From 911d1ae03efec2d54c3b1b605589d790d1745488 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Mon, 28 Nov 2016 16:44:40 -0800 Subject: [PATCH] Apply clang-format to the rest of the tree find * | grep "\.[ch]" | xargs clang-format --style=file -i Test: mma -j32 Change-Id: I6fcc9862bb7bc07c2a367ca58fef2b3cd27a6f05 --- audio_a2dp_hw/audio_a2dp_hw.cc | 1988 +++-- audio_a2dp_hw/audio_a2dp_hw.h | 28 +- audio_a2dp_hw/audio_a2dp_hw_utils.cc | 31 +- bta/av/bta_av_aact.cc | 24 +- bta/av/bta_av_main.cc | 10 +- bta/include/bta_ag_api.h | 16 +- btcore/include/bdaddr.h | 16 +- btcore/include/device_class.h | 61 +- btcore/include/device_features.h | 4 +- btcore/include/event_mask.h | 4 +- btcore/include/hal_util.h | 2 +- btcore/include/iac.h | 2 +- btcore/include/module.h | 27 +- btcore/include/property.h | 61 +- btcore/include/uuid.h | 22 +- btcore/src/bdaddr.cc | 42 +- btcore/src/device_class.cc | 54 +- btcore/src/hal_util.cc | 30 +- btcore/src/module.cc | 100 +- btcore/src/osi_module.cc | 20 +- btcore/src/property.cc | 120 +- btcore/src/uuid.cc | 83 +- btcore/test/bdaddr_test.cc | 1 - btcore/test/device_class_test.cc | 70 +- btcore/test/property_test.cc | 103 +- btcore/test/uuid_test.cc | 32 +- btif/src/btif_ble_advertiser.cc | 19 +- btif/src/btif_hf_client.cc | 81 +- btif/src/btif_hl.cc | 7 +- btif/src/btif_pan.cc | 2 +- btif/src/btif_rc.cc | 23 +- btif/src/btif_sock_l2cap.cc | 21 +- btif/src/btif_sock_rfc.cc | 3 +- conf/bt_did.conf | 93 +- conf/bt_stack.conf | 71 +- embdrv/sbc/decoder/include/oi_assert.h | 30 +- embdrv/sbc/decoder/include/oi_bitstream.h | 85 +- embdrv/sbc/decoder/include/oi_bt_spec.h | 103 +- embdrv/sbc/decoder/include/oi_codec_sbc.h | 262 +- embdrv/sbc/decoder/include/oi_codec_sbc_private.h | 174 +- embdrv/sbc/decoder/include/oi_common.h | 5 +- embdrv/sbc/decoder/include/oi_cpu_dep.h | 148 +- embdrv/sbc/decoder/include/oi_modules.h | 203 +- embdrv/sbc/decoder/include/oi_osinterface.h | 55 +- embdrv/sbc/decoder/include/oi_status.h | 1333 +-- embdrv/sbc/decoder/include/oi_stddefs.h | 262 +- embdrv/sbc/decoder/include/oi_string.h | 56 +- embdrv/sbc/decoder/include/oi_time.h | 49 +- embdrv/sbc/decoder/include/oi_utils.h | 69 +- embdrv/sbc/decoder/srce/alloc.c | 89 +- embdrv/sbc/decoder/srce/bitalloc-sbc.c | 199 +- embdrv/sbc/decoder/srce/bitalloc.c | 426 +- embdrv/sbc/decoder/srce/bitstream-decode.c | 74 +- embdrv/sbc/decoder/srce/decoder-oina.c | 131 +- embdrv/sbc/decoder/srce/decoder-private.c | 305 +- embdrv/sbc/decoder/srce/decoder-sbc.c | 722 +- embdrv/sbc/decoder/srce/dequant.c | 126 +- embdrv/sbc/decoder/srce/framing-sbc.c | 35 +- embdrv/sbc/decoder/srce/framing.c | 324 +- embdrv/sbc/decoder/srce/oi_codec_version.c | 13 +- embdrv/sbc/decoder/srce/synthesis-8-generated.c | 212 +- embdrv/sbc/decoder/srce/synthesis-dct8.c | 364 +- embdrv/sbc/decoder/srce/synthesis-sbc.c | 512 +- embdrv/sbc/encoder/include/sbc_dct.h | 95 +- embdrv/sbc/encoder/include/sbc_enc_func_declare.h | 21 +- embdrv/sbc/encoder/include/sbc_encoder.h | 73 +- embdrv/sbc/encoder/include/sbc_if.h | 4 +- embdrv/sbc/encoder/include/sbc_types.h | 2 +- embdrv/sbc/encoder/srce/sbc_analysis.c | 2017 +++-- embdrv/sbc/encoder/srce/sbc_dct.c | 329 +- embdrv/sbc/encoder/srce/sbc_dct_coeffs.c | 248 +- embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c | 284 +- embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c | 295 +- embdrv/sbc/encoder/srce/sbc_enc_coeffs.c | 483 +- embdrv/sbc/encoder/srce/sbc_encoder.c | 428 +- embdrv/sbc/encoder/srce/sbc_packing.c | 405 +- include/bt_trace.h | 1 - main/bte_conf.cc | 100 +- main/bte_init.cc | 39 +- main/bte_init_cpp_logging.cc | 8 +- main/bte_logmsg.cc | 182 +- main/bte_main.cc | 120 +- main/main_int.h | 4 +- main/stack_config.cc | 101 +- service/adapter.cc | 67 +- service/adapter.h | 3 +- service/bluetooth_instance.h | 6 +- service/client/main.cc | 52 +- .../common/android/bluetooth/advertise_settings.h | 3 +- .../bluetooth/bluetooth_gatt_characteristic.h | 6 +- .../android/bluetooth/bluetooth_gatt_descriptor.h | 6 +- .../bluetooth/bluetooth_gatt_included_service.cc | 2 +- .../bluetooth/bluetooth_gatt_included_service.h | 10 +- .../android/bluetooth/bluetooth_gatt_service.cc | 6 +- .../android/bluetooth/bluetooth_gatt_service.h | 13 +- service/common/android/bluetooth/scan_filter.cc | 2 +- service/common/android/bluetooth/scan_filter.h | 2 +- service/common/android/bluetooth/scan_settings.h | 2 +- service/common/bluetooth/adapter_state.cc | 36 +- service/common/bluetooth/advertise_settings.cc | 26 +- service/common/bluetooth/advertise_settings.h | 6 +- service/common/bluetooth/characteristic.cc | 3 +- service/common/bluetooth/characteristic.h | 12 +- service/common/bluetooth/descriptor.h | 2 +- service/common/bluetooth/low_energy_constants.h | 6 +- service/common/bluetooth/scan_filter.cc | 18 +- service/common/bluetooth/scan_result.cc | 17 +- service/common/bluetooth/scan_result.h | 3 +- service/common/bluetooth/scan_settings.cc | 36 +- service/common/bluetooth/scan_settings.h | 9 +- service/common/bluetooth/service.cc | 6 +- service/common/bluetooth/service.h | 10 +- service/common/bluetooth/util/address_helper.cc | 12 +- service/common/bluetooth/util/atomic_string.cc | 4 +- service/common/bluetooth/uuid.cc | 59 +- service/common/bluetooth/uuid.h | 8 +- service/daemon.cc | 23 +- service/daemon.h | 2 +- service/example/heart_rate/heart_rate_server.cc | 55 +- service/example/heart_rate/heart_rate_server.h | 32 +- service/gatt_client.cc | 31 +- service/gatt_client.h | 7 +- service/gatt_server.cc | 260 +- service/gatt_server.h | 125 +- service/gatt_server_old.cc | 196 +- service/gatt_server_old.h | 11 +- service/hal/bluetooth_gatt_interface.cc | 356 +- service/hal/bluetooth_gatt_interface.h | 196 +- service/hal/bluetooth_interface.cc | 162 +- service/hal/bluetooth_interface.h | 14 +- service/hal/fake_bluetooth_gatt_interface.cc | 195 +- service/hal/fake_bluetooth_gatt_interface.h | 56 +- service/hal/fake_bluetooth_interface.cc | 95 +- service/hal/fake_bluetooth_interface.h | 7 +- service/ipc/binder/bluetooth_binder_server.cc | 8 +- service/ipc/binder/bluetooth_binder_server.h | 2 +- .../binder/bluetooth_gatt_server_binder_server.cc | 7 +- .../binder/bluetooth_gatt_server_binder_server.h | 45 +- .../bluetooth_le_advertiser_binder_server.cc | 12 +- .../binder/bluetooth_le_advertiser_binder_server.h | 11 +- .../binder/bluetooth_le_scanner_binder_server.cc | 4 +- .../binder/bluetooth_le_scanner_binder_server.h | 1 + service/ipc/binder/ipc_handler_binder.cc | 20 +- service/ipc/binder/remote_callback_list.h | 22 +- service/ipc/binder/remote_callback_map.h | 56 +- service/ipc/ipc_handler.cc | 6 +- service/ipc/ipc_handler_linux.cc | 26 +- service/ipc/ipc_handler_linux.h | 5 +- service/ipc/ipc_manager.cc | 65 +- service/ipc/linux_ipc_host.cc | 69 +- service/ipc/linux_ipc_host.h | 2 +- service/logging_helpers.cc | 24 +- service/logging_helpers.h | 22 +- service/low_energy_advertiser.cc | 87 +- service/low_energy_advertiser.h | 20 +- service/low_energy_client.cc | 75 +- service/low_energy_client.h | 36 +- service/low_energy_scanner.cc | 51 +- service/low_energy_scanner.h | 15 +- service/main.cc | 2 +- service/settings.cc | 10 +- service/settings.h | 2 +- service/test/adapter_unittest.cc | 30 +- service/test/advertise_data_unittest.cc | 40 +- service/test/fake_hal_util.cc | 4 +- service/test/gatt_client_unittest.cc | 30 +- service/test/gatt_server_unittest.cc | 324 +- service/test/ipc_linux_unittest.cc | 15 +- service/test/low_energy_advertiser_unittest.cc | 199 +- service/test/low_energy_client_unittest.cc | 82 +- service/test/low_energy_scanner_unittest.cc | 91 +- service/test/main.cc | 2 +- service/test/parcelable_unittest.cc | 64 +- service/test/settings_unittest.cc | 32 +- service/test/stub_ipc_handler_binder.cc | 5 +- service/test/stub_ipc_handler_linux.cc | 5 +- service/test/util_unittest.cc | 4 +- service/test/uuid_unittest.cc | 20 +- stack/a2dp/a2dp_vendor.cc | 10 +- stack/avct/avct_api.cc | 480 +- stack/avct/avct_bcb_act.cc | 779 +- stack/avct/avct_ccb.cc | 114 +- stack/avct/avct_defs.h | 18 +- stack/avct/avct_int.h | 241 +- stack/avct/avct_l2c.cc | 516 +- stack/avct/avct_l2c_br.cc | 468 +- stack/avct/avct_lcb.cc | 482 +- stack/avct/avct_lcb_act.cc | 830 +- stack/avdt/avdt_ad.cc | 679 +- stack/avdt/avdt_api.cc | 1240 ++- stack/avdt/avdt_ccb.cc | 793 +- stack/avdt/avdt_ccb_act.cc | 1013 ++- stack/avdt/avdt_defs.h | 276 +- stack/avdt/avdt_int.h | 965 +-- stack/avdt/avdt_l2c.cc | 706 +- stack/avdt/avdt_msg.cc | 2252 +++-- stack/avdt/avdt_scb.cc | 1684 ++-- stack/avdt/avdt_scb_act.cc | 1352 ++- stack/avrc/avrc_api.cc | 1923 +++-- stack/avrc/avrc_bld_ct.cc | 732 +- stack/avrc/avrc_bld_tg.cc | 2096 +++-- stack/avrc/avrc_int.h | 145 +- stack/avrc/avrc_opt.cc | 144 +- stack/avrc/avrc_pars_ct.cc | 1106 ++- stack/avrc/avrc_pars_tg.cc | 876 +- stack/avrc/avrc_sdp.cc | 303 +- stack/avrc/avrc_utils.cc | 240 +- stack/bnep/bnep_api.cc | 864 +- stack/bnep/bnep_int.h | 310 +- stack/bnep/bnep_main.cc | 1033 ++- stack/bnep/bnep_utils.cc | 1724 ++-- stack/btm/ble_advertiser_hci_interface.cc | 63 +- stack/btm/ble_advertiser_hci_interface.h | 12 +- stack/btm/btm_acl.cc | 3176 ++++--- stack/btm/btm_ble.cc | 3057 ++++--- stack/btm/btm_ble_addr.cc | 638 +- stack/btm/btm_ble_adv_filter.cc | 1744 ++-- stack/btm/btm_ble_batchscan.cc | 1124 ++- stack/btm/btm_ble_bgconn.cc | 769 +- stack/btm/btm_ble_cont_energy.cc | 78 +- stack/btm/btm_ble_gap.cc | 3690 ++++----- stack/btm/btm_ble_int.h | 173 +- stack/btm/btm_ble_int_types.h | 440 +- stack/btm/btm_ble_multi_adv.cc | 58 +- stack/btm/btm_ble_privacy.cc | 1083 ++- stack/btm/btm_dev.cc | 642 +- stack/btm/btm_devctl.cc | 858 +- stack/btm/btm_inq.cc | 3445 ++++---- stack/btm/btm_int.h | 353 +- stack/btm/btm_int_types.h | 1300 +-- stack/btm/btm_main.cc | 50 +- stack/btm/btm_pm.cc | 1130 ++- stack/btm/btm_sco.cc | 1996 +++-- stack/btm/btm_sec.cc | 8637 ++++++++++---------- stack/btu/btu_hcif.cc | 1952 +++-- stack/btu/btu_init.cc | 79 +- stack/btu/btu_task.cc | 142 +- stack/gap/gap_api.cc | 24 +- stack/gap/gap_ble.cc | 962 ++- stack/gap/gap_conn.cc | 1397 ++-- stack/gap/gap_int.h | 196 +- stack/gap/gap_utils.cc | 93 +- stack/gatt/att_protocol.cc | 671 +- stack/gatt/gatt_api.cc | 1788 ++-- stack/gatt/gatt_attr.cc | 514 +- stack/gatt/gatt_auth.cc | 686 +- stack/gatt/gatt_cl.cc | 1728 ++-- stack/gatt/gatt_db.cc | 1463 ++-- stack/gatt/gatt_int.h | 945 +-- stack/gatt/gatt_main.cc | 1502 ++-- stack/gatt/gatt_sr.cc | 2031 +++-- stack/gatt/gatt_utils.cc | 2813 +++---- stack/hcic/hciblecmds.cc | 911 +-- stack/hcic/hcicmds.cc | 1666 ++-- stack/hid/hid_conn.h | 55 +- stack/hid/hidh_api.cc | 766 +- stack/hid/hidh_conn.cc | 1477 ++-- stack/hid/hidh_int.h | 68 +- stack/include/avct_api.h | 111 +- stack/include/avdt_api.h | 465 +- stack/include/avdtc_api.h | 60 +- stack/include/avrc_api.h | 220 +- stack/include/avrc_defs.h | 2194 ++--- stack/include/ble_advertiser.h | 20 +- stack/include/bnep_api.h | 226 +- stack/include/bt_types.h | 1179 +-- stack/include/btm_api.h | 431 +- stack/include/btm_api_types.h | 2248 +++-- stack/include/btm_ble_api.h | 217 +- stack/include/btm_ble_api_types.h | 826 +- stack/include/btu.h | 33 +- stack/include/gap_api.h | 178 +- stack/include/gatt_api.h | 882 +- stack/include/gattdefs.h | 122 +- stack/include/hcidefs.h | 4556 ++++++----- stack/include/hcimsgs.h | 1022 +-- stack/include/hiddefs.h | 181 +- stack/include/hidh_api.h | 92 +- stack/include/l2c_api.h | 471 +- stack/include/l2cap_client.h | 27 +- stack/include/l2cdefs.h | 384 +- stack/include/mca_api.h | 252 +- stack/include/mca_defs.h | 94 +- stack/include/pan_api.h | 206 +- stack/include/port_api.h | 389 +- stack/include/port_ext.h | 4 +- stack/include/profiles_api.h | 43 +- stack/include/rfcdefs.h | 327 +- stack/include/sdp_api.h | 348 +- stack/include/sdpdefs.h | 517 +- stack/include/smp_api.h | 32 +- stack/include/smp_api_types.h | 338 +- stack/include/srvc_api.h | 162 +- stack/l2cap/l2c_api.cc | 2679 +++--- stack/l2cap/l2c_ble.cc | 2036 +++-- stack/l2cap/l2c_csm.cc | 2313 +++--- stack/l2cap/l2c_fcr.cc | 3741 +++++---- stack/l2cap/l2c_int.h | 1074 +-- stack/l2cap/l2c_link.cc | 2077 +++-- stack/l2cap/l2c_main.cc | 1448 ++-- stack/l2cap/l2c_ucd.cc | 1420 ++-- stack/l2cap/l2c_utils.cc | 4697 +++++------ stack/l2cap/l2cap_client.cc | 207 +- stack/mcap/mca_api.cc | 1018 ++- stack/mcap/mca_cact.cc | 736 +- stack/mcap/mca_csm.cc | 368 +- stack/mcap/mca_dact.cc | 94 +- stack/mcap/mca_dsm.cc | 332 +- stack/mcap/mca_int.h | 406 +- stack/mcap/mca_l2c.cc | 753 +- stack/mcap/mca_main.cc | 673 +- stack/pan/pan_api.cc | 917 +-- stack/pan/pan_int.h | 165 +- stack/pan/pan_main.cc | 948 +-- stack/pan/pan_utils.cc | 402 +- stack/rfcomm/port_api.cc | 2028 +++-- stack/rfcomm/port_int.h | 274 +- stack/rfcomm/port_rfc.cc | 1351 ++- stack/rfcomm/port_utils.cc | 735 +- stack/rfcomm/rfc_int.h | 479 +- stack/rfcomm/rfc_l2cap_if.cc | 518 +- stack/rfcomm/rfc_mx_fsm.cc | 756 +- stack/rfcomm/rfc_port_fsm.cc | 1015 ++- stack/rfcomm/rfc_port_if.cc | 341 +- stack/rfcomm/rfc_ts_frames.cc | 1131 ++- stack/rfcomm/rfc_utils.cc | 461 +- stack/sdp/sdp_api.cc | 1530 ++-- stack/sdp/sdp_db.cc | 1216 ++- stack/sdp/sdp_discovery.cc | 1369 ++-- stack/sdp/sdp_main.cc | 887 +- stack/sdp/sdp_server.cc | 1225 ++- stack/sdp/sdp_utils.cc | 1202 ++- stack/sdp/sdpint.h | 366 +- stack/smp/aes.cc | 1374 ++-- stack/smp/aes.h | 102 +- stack/smp/p_256_curvepara.cc | 87 +- stack/smp/p_256_ecc_pp.cc | 402 +- stack/smp/p_256_ecc_pp.h | 38 +- stack/smp/p_256_multprecision.cc | 1154 ++- stack/smp/p_256_multprecision.h | 61 +- stack/smp/smp_act.cc | 2788 +++---- stack/smp/smp_api.cc | 634 +- stack/smp/smp_br_main.cc | 592 +- stack/smp/smp_cmac.cc | 344 +- stack/smp/smp_int.h | 841 +- stack/smp/smp_keys.cc | 2582 +++--- stack/smp/smp_l2c.cc | 435 +- stack/smp/smp_main.cc | 1592 ++-- stack/smp/smp_utils.cc | 1671 ++-- stack/srvc/srvc_battery.cc | 528 +- stack/srvc/srvc_battery_int.h | 55 +- stack/srvc/srvc_dis.cc | 655 +- stack/srvc/srvc_dis_int.h | 50 +- stack/srvc/srvc_eng.cc | 514 +- stack/srvc/srvc_eng_int.h | 60 +- stack/test/ble_advertiser_test.cc | 46 +- stack/test/stack_a2dp_test.cc | 162 +- test/suite/adapter/adapter_unittest.cc | 61 +- test/suite/adapter/bluetooth_test.cc | 49 +- test/suite/adapter/bluetooth_test.h | 19 +- test/suite/gatt/gatt_test.cc | 20 +- test/suite/gatt/gatt_test.h | 29 +- test/suite/gatt/gatt_unittest.cc | 21 +- test/suite/rfcomm/rfcomm_test.cc | 32 +- test/suite/rfcomm/rfcomm_test.h | 7 +- test/suite/rfcomm/rfcomm_unittest.cc | 114 +- tools/bdtool/adapter.c | 225 +- tools/bdtool/bdtool.c | 135 +- tools/hci/main.c | 106 +- udrv/include/uipc.h | 45 +- udrv/ulinux/uipc.cc | 1039 ++- udrv/ulinux/uipc_linux.h | 10 +- utils/include/bt_utils.h | 6 +- utils/src/bt_utils.cc | 123 +- vendor_libs/test_vendor_lib/include/bt_address.h | 2 +- .../test_vendor_lib/test/hci_transport_unittest.cc | 2 +- vnd/ble/vendor_hcidefs.h | 16 +- vnd/include/vendor_api.h | 8 +- 378 files changed, 89941 insertions(+), 96783 deletions(-) mode change 100755 => 100644 stack/l2cap/l2cap_client.cc diff --git a/audio_a2dp_hw/audio_a2dp_hw.cc b/audio_a2dp_hw/audio_a2dp_hw.cc index 753120974..30b2876c4 100644 --- a/audio_a2dp_hw/audio_a2dp_hw.cc +++ b/audio_a2dp_hw/audio_a2dp_hw.cc @@ -55,70 +55,76 @@ #define CTRL_CHAN_RETRY_COUNT 3 #define USEC_PER_SEC 1000000L -#define SOCK_SEND_TIMEOUT_MS 2000 /* Timeout for sending */ -#define SOCK_RECV_TIMEOUT_MS 5000 /* Timeout for receiving */ +#define SOCK_SEND_TIMEOUT_MS 2000 /* Timeout for sending */ +#define SOCK_RECV_TIMEOUT_MS 5000 /* Timeout for receiving */ -// set WRITE_POLL_MS to 0 for blocking sockets, nonzero for polled non-blocking sockets +// set WRITE_POLL_MS to 0 for blocking sockets, nonzero for polled non-blocking +// sockets #define WRITE_POLL_MS 20 -#define FNLOG() LOG_VERBOSE(LOG_TAG, "%s", __func__); -#define DEBUG(fmt, ...) LOG_VERBOSE(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) -#define INFO(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) -#define WARN(fmt, ...) LOG_WARN(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) -#define ERROR(fmt, ...) LOG_ERROR(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) +#define FNLOG() LOG_VERBOSE(LOG_TAG, "%s", __func__); +#define DEBUG(fmt, ...) \ + LOG_VERBOSE(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) +#define INFO(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) +#define WARN(fmt, ...) LOG_WARN(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) +#define ERROR(fmt, ...) LOG_ERROR(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) -#define ASSERTC(cond, msg, val) if (!(cond)) {ERROR("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} +#define ASSERTC(cond, msg, val) \ + if (!(cond)) { \ + ERROR("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, \ + val); \ + } /***************************************************************************** * Local type definitions *****************************************************************************/ typedef enum { - AUDIO_A2DP_STATE_STARTING, - AUDIO_A2DP_STATE_STARTED, - AUDIO_A2DP_STATE_STOPPING, - AUDIO_A2DP_STATE_STOPPED, - /* need explicit set param call to resume (suspend=false) */ - AUDIO_A2DP_STATE_SUSPENDED, - AUDIO_A2DP_STATE_STANDBY /* allows write to autoresume */ + AUDIO_A2DP_STATE_STARTING, + AUDIO_A2DP_STATE_STARTED, + AUDIO_A2DP_STATE_STOPPING, + AUDIO_A2DP_STATE_STOPPED, + /* need explicit set param call to resume (suspend=false) */ + AUDIO_A2DP_STATE_SUSPENDED, + AUDIO_A2DP_STATE_STANDBY /* allows write to autoresume */ } a2dp_state_t; struct a2dp_stream_in; struct a2dp_stream_out; struct a2dp_audio_device { - struct audio_hw_device device; - struct a2dp_stream_in *input; - struct a2dp_stream_out *output; + struct audio_hw_device device; + struct a2dp_stream_in* input; + struct a2dp_stream_out* output; }; struct a2dp_config { - uint32_t rate; - uint32_t channel_mask; - int format; + uint32_t rate; + uint32_t channel_mask; + int format; }; /* move ctrl_fd outside output stream and keep open until HAL unloaded ? */ struct a2dp_stream_common { - pthread_mutex_t lock; - int ctrl_fd; - int audio_fd; - size_t buffer_sz; - struct a2dp_config cfg; - a2dp_state_t state; + pthread_mutex_t lock; + int ctrl_fd; + int audio_fd; + size_t buffer_sz; + struct a2dp_config cfg; + a2dp_state_t state; }; struct a2dp_stream_out { - struct audio_stream_out stream; - struct a2dp_stream_common common; - uint64_t frames_presented; // frames written, never reset - uint64_t frames_rendered; // frames written, reset on standby + struct audio_stream_out stream; + struct a2dp_stream_common common; + uint64_t frames_presented; // frames written, never reset + uint64_t frames_rendered; // frames written, reset on standby }; struct a2dp_stream_in { - struct audio_stream_in stream; - struct a2dp_stream_common common; + struct audio_stream_in stream; + struct a2dp_stream_common common; }; /***************************************************************************** @@ -129,7 +135,7 @@ struct a2dp_stream_in { * Static functions *****************************************************************************/ -static size_t out_get_buffer_size(const struct audio_stream *stream); +static size_t out_get_buffer_size(const struct audio_stream* stream); /***************************************************************************** * Externs @@ -138,7 +144,7 @@ static size_t out_get_buffer_size(const struct audio_stream *stream); /***************************************************************************** * Functions *****************************************************************************/ -static void a2dp_open_ctrl_path(struct a2dp_stream_common *common); +static void a2dp_open_ctrl_path(struct a2dp_stream_common* common); /***************************************************************************** * Miscellaneous helper functions @@ -146,37 +152,35 @@ static void a2dp_open_ctrl_path(struct a2dp_stream_common *common); /* logs timestamp with microsec precision pprev is optional in case a dedicated diff is required */ -static void ts_log(UNUSED_ATTR const char *tag, UNUSED_ATTR int val, struct timespec *pprev_opt) -{ - struct timespec now; - static struct timespec prev = {0,0}; - unsigned long long now_us; - unsigned long long diff_us; - - clock_gettime(CLOCK_MONOTONIC, &now); - - now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000; - - if (pprev_opt) - { - diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000; - *pprev_opt = now; - DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val); - } - else - { - diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000; - prev = now; - DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val); - } -} - -static int calc_audiotime_usec(struct a2dp_config cfg, int bytes) -{ - int chan_count = audio_channel_count_from_out_mask(cfg.channel_mask); - int bytes_per_sample; - - switch (cfg.format) { +static void ts_log(UNUSED_ATTR const char* tag, UNUSED_ATTR int val, + struct timespec* pprev_opt) { + struct timespec now; + static struct timespec prev = {0, 0}; + unsigned long long now_us; + unsigned long long diff_us; + + clock_gettime(CLOCK_MONOTONIC, &now); + + now_us = now.tv_sec * USEC_PER_SEC + now.tv_nsec / 1000; + + if (pprev_opt) { + diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + + (now.tv_nsec - prev.tv_nsec) / 1000; + *pprev_opt = now; + DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val); + } else { + diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + + (now.tv_nsec - prev.tv_nsec) / 1000; + prev = now; + DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val); + } +} + +static int calc_audiotime_usec(struct a2dp_config cfg, int bytes) { + int chan_count = audio_channel_count_from_out_mask(cfg.channel_mask); + int bytes_per_sample; + + switch (cfg.format) { case AUDIO_FORMAT_PCM_8_BIT: bytes_per_sample = 1; break; @@ -196,11 +200,11 @@ static int calc_audiotime_usec(struct a2dp_config cfg, int bytes) ASSERTC(false, "unsupported sample format", cfg.format); bytes_per_sample = 2; break; - } + } - return (int)(((int64_t)bytes * - (USEC_PER_SEC / (chan_count * bytes_per_sample))) / - cfg.rate); + return ( + int)(((int64_t)bytes * (USEC_PER_SEC / (chan_count * bytes_per_sample))) / + cfg.rate); } /***************************************************************************** @@ -209,235 +213,215 @@ static int calc_audiotime_usec(struct a2dp_config cfg, int bytes) * ****************************************************************************/ -static int skt_connect(const char *path, size_t buffer_sz) -{ - int ret; - int skt_fd; - int len; +static int skt_connect(const char* path, size_t buffer_sz) { + int ret; + int skt_fd; + int len; - INFO("connect to %s (sz %zu)", path, buffer_sz); + INFO("connect to %s (sz %zu)", path, buffer_sz); - skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0); + skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if(osi_socket_local_client_connect(skt_fd, path, - ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) - { - ERROR("failed to connect (%s)", strerror(errno)); - close(skt_fd); - return -1; - } + if (osi_socket_local_client_connect( + skt_fd, path, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) { + ERROR("failed to connect (%s)", strerror(errno)); + close(skt_fd); + return -1; + } - len = buffer_sz; - ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len)); - if (ret < 0) - ERROR("setsockopt failed (%s)", strerror(errno)); + len = buffer_sz; + ret = + setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len)); + if (ret < 0) ERROR("setsockopt failed (%s)", strerror(errno)); - ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len)); - if (ret < 0) - ERROR("setsockopt failed (%s)", strerror(errno)); + ret = + setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len)); + if (ret < 0) ERROR("setsockopt failed (%s)", strerror(errno)); - /* Socket send/receive timeout value */ - struct timeval tv; - tv.tv_sec = SOCK_SEND_TIMEOUT_MS / 1000; - tv.tv_usec = (SOCK_SEND_TIMEOUT_MS % 1000) * 1000; + /* Socket send/receive timeout value */ + struct timeval tv; + tv.tv_sec = SOCK_SEND_TIMEOUT_MS / 1000; + tv.tv_usec = (SOCK_SEND_TIMEOUT_MS % 1000) * 1000; - ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); - if (ret < 0) - ERROR("setsockopt failed (%s)", strerror(errno)); + ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + if (ret < 0) ERROR("setsockopt failed (%s)", strerror(errno)); - tv.tv_sec = SOCK_RECV_TIMEOUT_MS / 1000; - tv.tv_usec = (SOCK_RECV_TIMEOUT_MS % 1000) * 1000; + tv.tv_sec = SOCK_RECV_TIMEOUT_MS / 1000; + tv.tv_usec = (SOCK_RECV_TIMEOUT_MS % 1000) * 1000; - ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) - ERROR("setsockopt failed (%s)", strerror(errno)); + ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + if (ret < 0) ERROR("setsockopt failed (%s)", strerror(errno)); - INFO("connected to stack fd = %d", skt_fd); + INFO("connected to stack fd = %d", skt_fd); - return skt_fd; + return skt_fd; } -static int skt_read(int fd, void *p, size_t len) -{ - ssize_t read; +static int skt_read(int fd, void* p, size_t len) { + ssize_t read; - FNLOG(); + FNLOG(); - ts_log("skt_read recv", len, NULL); + ts_log("skt_read recv", len, NULL); - OSI_NO_INTR(read = recv(fd, p, len, MSG_NOSIGNAL)); - if (read == -1) - ERROR("read failed with errno=%d\n", errno); + OSI_NO_INTR(read = recv(fd, p, len, MSG_NOSIGNAL)); + if (read == -1) ERROR("read failed with errno=%d\n", errno); - return (int)read; + return (int)read; } -static int skt_write(int fd, const void *p, size_t len) -{ - ssize_t sent; - FNLOG(); +static int skt_write(int fd, const void* p, size_t len) { + ssize_t sent; + FNLOG(); - ts_log("skt_write", len, NULL); + ts_log("skt_write", len, NULL); - if (WRITE_POLL_MS == 0) { - // do not poll, use blocking send - OSI_NO_INTR(sent = send(fd, p, len, MSG_NOSIGNAL)); - if (sent == -1) - ERROR("write failed with error(%s)", strerror(errno)); + if (WRITE_POLL_MS == 0) { + // do not poll, use blocking send + OSI_NO_INTR(sent = send(fd, p, len, MSG_NOSIGNAL)); + if (sent == -1) ERROR("write failed with error(%s)", strerror(errno)); - return (int)sent; - } + return (int)sent; + } - // use non-blocking send, poll - int ms_timeout = SOCK_SEND_TIMEOUT_MS; - size_t count = 0; - while (count < len) { - OSI_NO_INTR(sent = send(fd, p, len - count, MSG_NOSIGNAL | MSG_DONTWAIT)); - if (sent == -1) { - if (errno != EAGAIN && errno != EWOULDBLOCK) { - ERROR("write failed with error(%s)", strerror(errno)); - return -1; - } - if (ms_timeout >= WRITE_POLL_MS) { - usleep(WRITE_POLL_MS * 1000); - ms_timeout -= WRITE_POLL_MS; - continue; - } - WARN("write timeout exceeded, sent %zu bytes", count); - return -1; - } - count += sent; - p = (const uint8_t *)p + sent; + // use non-blocking send, poll + int ms_timeout = SOCK_SEND_TIMEOUT_MS; + size_t count = 0; + while (count < len) { + OSI_NO_INTR(sent = send(fd, p, len - count, MSG_NOSIGNAL | MSG_DONTWAIT)); + if (sent == -1) { + if (errno != EAGAIN && errno != EWOULDBLOCK) { + ERROR("write failed with error(%s)", strerror(errno)); + return -1; + } + if (ms_timeout >= WRITE_POLL_MS) { + usleep(WRITE_POLL_MS * 1000); + ms_timeout -= WRITE_POLL_MS; + continue; + } + WARN("write timeout exceeded, sent %zu bytes", count); + return -1; } - return (int)count; + count += sent; + p = (const uint8_t*)p + sent; + } + return (int)count; } -static int skt_disconnect(int fd) -{ - INFO("fd %d", fd); +static int skt_disconnect(int fd) { + INFO("fd %d", fd); - if (fd != AUDIO_SKT_DISCONNECTED) - { - shutdown(fd, SHUT_RDWR); - close(fd); - } - return 0; + if (fd != AUDIO_SKT_DISCONNECTED) { + shutdown(fd, SHUT_RDWR); + close(fd); + } + return 0; } - - /***************************************************************************** * * AUDIO CONTROL PATH * ****************************************************************************/ -static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void* buffer, int length) -{ - ssize_t ret; - int i; - - for (i = 0;; i++) { - OSI_NO_INTR(ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL)); - if (ret > 0) { - break; - } - if (ret == 0) { - ERROR("ack failed: peer closed"); - break; - } - if (errno != EWOULDBLOCK && errno != EAGAIN) { - ERROR("ack failed: error(%s)", strerror(errno)); - break; - } - if (i == (CTRL_CHAN_RETRY_COUNT - 1)) { - ERROR("ack failed: max retry count"); - break; - } - INFO("ack failed (%s), retrying", strerror(errno)); +static int a2dp_ctrl_receive(struct a2dp_stream_common* common, void* buffer, + int length) { + ssize_t ret; + int i; + + for (i = 0;; i++) { + OSI_NO_INTR(ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL)); + if (ret > 0) { + break; } - if (ret <= 0) { - skt_disconnect(common->ctrl_fd); - common->ctrl_fd = AUDIO_SKT_DISCONNECTED; + if (ret == 0) { + ERROR("ack failed: peer closed"); + break; } - return ret; + if (errno != EWOULDBLOCK && errno != EAGAIN) { + ERROR("ack failed: error(%s)", strerror(errno)); + break; + } + if (i == (CTRL_CHAN_RETRY_COUNT - 1)) { + ERROR("ack failed: max retry count"); + break; + } + INFO("ack failed (%s), retrying", strerror(errno)); + } + if (ret <= 0) { + skt_disconnect(common->ctrl_fd); + common->ctrl_fd = AUDIO_SKT_DISCONNECTED; + } + return ret; } -static int a2dp_command(struct a2dp_stream_common *common, tA2DP_CTRL_CMD cmd) -{ - char ack; +static int a2dp_command(struct a2dp_stream_common* common, tA2DP_CTRL_CMD cmd) { + char ack; - DEBUG("A2DP COMMAND %s", audio_a2dp_hw_dump_ctrl_event(cmd)); + DEBUG("A2DP COMMAND %s", audio_a2dp_hw_dump_ctrl_event(cmd)); + if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) { + INFO("recovering from previous error"); + a2dp_open_ctrl_path(common); if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) { - INFO("recovering from previous error"); - a2dp_open_ctrl_path(common); - if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) { - ERROR("failure to open ctrl path"); - return -1; - } - } - - /* send command */ - ssize_t sent; - OSI_NO_INTR(sent = send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL)); - if (sent == -1) - { - ERROR("cmd failed (%s)", strerror(errno)); - skt_disconnect(common->ctrl_fd); - common->ctrl_fd = AUDIO_SKT_DISCONNECTED; - return -1; + ERROR("failure to open ctrl path"); + return -1; } + } + + /* send command */ + ssize_t sent; + OSI_NO_INTR(sent = send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL)); + if (sent == -1) { + ERROR("cmd failed (%s)", strerror(errno)); + skt_disconnect(common->ctrl_fd); + common->ctrl_fd = AUDIO_SKT_DISCONNECTED; + return -1; + } - /* wait for ack byte */ - if (a2dp_ctrl_receive(common, &ack, 1) < 0) { - ERROR("A2DP COMMAND %s: no ACK", audio_a2dp_hw_dump_ctrl_event(cmd)); - return -1; - } + /* wait for ack byte */ + if (a2dp_ctrl_receive(common, &ack, 1) < 0) { + ERROR("A2DP COMMAND %s: no ACK", audio_a2dp_hw_dump_ctrl_event(cmd)); + return -1; + } - DEBUG("A2DP COMMAND %s DONE STATUS %d", audio_a2dp_hw_dump_ctrl_event(cmd), - ack); + DEBUG("A2DP COMMAND %s DONE STATUS %d", audio_a2dp_hw_dump_ctrl_event(cmd), + ack); - if (ack == A2DP_CTRL_ACK_INCALL_FAILURE) - return ack; - if (ack != A2DP_CTRL_ACK_SUCCESS) { - ERROR("A2DP COMMAND %s error %d", audio_a2dp_hw_dump_ctrl_event(cmd), - ack); - return -1; - } + if (ack == A2DP_CTRL_ACK_INCALL_FAILURE) return ack; + if (ack != A2DP_CTRL_ACK_SUCCESS) { + ERROR("A2DP COMMAND %s error %d", audio_a2dp_hw_dump_ctrl_event(cmd), ack); + return -1; + } - return 0; + return 0; } -static int check_a2dp_ready(struct a2dp_stream_common *common) -{ - if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) - { - ERROR("check a2dp ready failed"); - return -1; - } - return 0; +static int check_a2dp_ready(struct a2dp_stream_common* common) { + if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) { + ERROR("check a2dp ready failed"); + return -1; + } + return 0; } -static int a2dp_read_input_audio_config(struct a2dp_stream_common *common) -{ - tA2DP_SAMPLE_RATE sample_rate; - tA2DP_CHANNEL_COUNT channel_count; +static int a2dp_read_input_audio_config(struct a2dp_stream_common* common) { + tA2DP_SAMPLE_RATE sample_rate; + tA2DP_CHANNEL_COUNT channel_count; - if (a2dp_command(common, A2DP_CTRL_GET_INPUT_AUDIO_CONFIG) < 0) - { - ERROR("get a2dp input audio config failed"); - return -1; - } + if (a2dp_command(common, A2DP_CTRL_GET_INPUT_AUDIO_CONFIG) < 0) { + ERROR("get a2dp input audio config failed"); + return -1; + } - if (a2dp_ctrl_receive(common, &sample_rate, sizeof(tA2DP_SAMPLE_RATE)) < 0) - return -1; - if (a2dp_ctrl_receive(common, &channel_count, - sizeof(tA2DP_CHANNEL_COUNT)) < 0) { - return -1; - } + if (a2dp_ctrl_receive(common, &sample_rate, sizeof(tA2DP_SAMPLE_RATE)) < 0) + return -1; + if (a2dp_ctrl_receive(common, &channel_count, sizeof(tA2DP_CHANNEL_COUNT)) < + 0) { + return -1; + } - switch (sample_rate) { + switch (sample_rate) { case 44100: case 48000: common->cfg.rate = sample_rate; @@ -445,9 +429,9 @@ static int a2dp_read_input_audio_config(struct a2dp_stream_common *common) default: ERROR("Invalid sample rate: %" PRIu32, sample_rate); return -1; - } + } - switch (channel_count) { + switch (channel_count) { case 1: common->cfg.channel_mask = AUDIO_CHANNEL_IN_MONO; break; @@ -457,41 +441,39 @@ static int a2dp_read_input_audio_config(struct a2dp_stream_common *common) default: ERROR("Invalid channel count: %" PRIu32, channel_count); return -1; - } + } - // TODO: For now input audio format is always hard-coded as PCM 16-bit - common->cfg.format = AUDIO_FORMAT_PCM_16_BIT; + // TODO: For now input audio format is always hard-coded as PCM 16-bit + common->cfg.format = AUDIO_FORMAT_PCM_16_BIT; - INFO("got input audio config %d %d", common->cfg.format, common->cfg.rate); + INFO("got input audio config %d %d", common->cfg.format, common->cfg.rate); - return 0; + return 0; } -static int a2dp_read_output_audio_config(struct a2dp_stream_common *common) -{ - tA2DP_SAMPLE_RATE sample_rate; - tA2DP_CHANNEL_COUNT channel_count; - tA2DP_BITS_PER_SAMPLE bits_per_sample; +static int a2dp_read_output_audio_config(struct a2dp_stream_common* common) { + tA2DP_SAMPLE_RATE sample_rate; + tA2DP_CHANNEL_COUNT channel_count; + tA2DP_BITS_PER_SAMPLE bits_per_sample; - if (a2dp_command(common, A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG) < 0) - { - ERROR("get a2dp output audio config failed"); - return -1; - } + if (a2dp_command(common, A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG) < 0) { + ERROR("get a2dp output audio config failed"); + return -1; + } - if (a2dp_ctrl_receive(common, &sample_rate, sizeof(tA2DP_SAMPLE_RATE)) < 0) - return -1; - if (a2dp_ctrl_receive(common, &channel_count, - sizeof(tA2DP_CHANNEL_COUNT)) < 0) { - return -1; - } - if (a2dp_ctrl_receive(common, &bits_per_sample, - sizeof(tA2DP_BITS_PER_SAMPLE)) < 0) { - return -1; - } + if (a2dp_ctrl_receive(common, &sample_rate, sizeof(tA2DP_SAMPLE_RATE)) < 0) + return -1; + if (a2dp_ctrl_receive(common, &channel_count, sizeof(tA2DP_CHANNEL_COUNT)) < + 0) { + return -1; + } + if (a2dp_ctrl_receive(common, &bits_per_sample, + sizeof(tA2DP_BITS_PER_SAMPLE)) < 0) { + return -1; + } - // Check the sample rate - switch (sample_rate) { + // Check the sample rate + switch (sample_rate) { case 44100: case 48000: case 88200: @@ -501,10 +483,10 @@ static int a2dp_read_output_audio_config(struct a2dp_stream_common *common) default: ERROR("Invalid sample rate: %" PRIu32, sample_rate); return -1; - } + } - // Check the channel count - switch (channel_count) { + // Check the channel count + switch (channel_count) { case 1: common->cfg.channel_mask = AUDIO_CHANNEL_OUT_MONO; break; @@ -514,10 +496,10 @@ static int a2dp_read_output_audio_config(struct a2dp_stream_common *common) default: ERROR("Invalid channel count: %" PRIu8, channel_count); return -1; - } + } - // Check the bits per sample - switch (bits_per_sample) { + // Check the bits per sample + switch (bits_per_sample) { case 16: common->cfg.format = AUDIO_FORMAT_PCM_16_BIT; break; @@ -530,37 +512,36 @@ static int a2dp_read_output_audio_config(struct a2dp_stream_common *common) default: ERROR("Invalid bits per sample: %" PRIu8, bits_per_sample); return -1; - } + } - INFO("got output audio config: sample_rate=%u channel_count=%u " - "bits_per_sample=%u", sample_rate, channel_count, bits_per_sample); + INFO( + "got output audio config: sample_rate=%u channel_count=%u " + "bits_per_sample=%u", + sample_rate, channel_count, bits_per_sample); - return 0; + return 0; } -static void a2dp_open_ctrl_path(struct a2dp_stream_common *common) -{ - int i; +static void a2dp_open_ctrl_path(struct a2dp_stream_common* common) { + int i; - /* retry logic to catch any timing variations on control channel */ - for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) - { - /* connect control channel if not already connected */ - if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0) - { - /* success, now check if stack is ready */ - if (check_a2dp_ready(common) == 0) - break; - - ERROR("error : a2dp not ready, wait 250 ms and retry"); - usleep(250000); - skt_disconnect(common->ctrl_fd); - common->ctrl_fd = AUDIO_SKT_DISCONNECTED; - } - - /* ctrl channel not ready, wait a bit */ - usleep(250000); + /* retry logic to catch any timing variations on control channel */ + for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) { + /* connect control channel if not already connected */ + if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > + 0) { + /* success, now check if stack is ready */ + if (check_a2dp_ready(common) == 0) break; + + ERROR("error : a2dp not ready, wait 250 ms and retry"); + usleep(250000); + skt_disconnect(common->ctrl_fd); + common->ctrl_fd = AUDIO_SKT_DISCONNECTED; } + + /* ctrl channel not ready, wait a bit */ + usleep(250000); + } } /***************************************************************************** @@ -569,329 +550,300 @@ static void a2dp_open_ctrl_path(struct a2dp_stream_common *common) * ****************************************************************************/ -static void a2dp_stream_common_init(struct a2dp_stream_common *common) -{ - pthread_mutexattr_t lock_attr; +static void a2dp_stream_common_init(struct a2dp_stream_common* common) { + pthread_mutexattr_t lock_attr; - FNLOG(); + FNLOG(); - pthread_mutexattr_init(&lock_attr); - pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&common->lock, &lock_attr); + pthread_mutexattr_init(&lock_attr); + pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&common->lock, &lock_attr); - common->ctrl_fd = AUDIO_SKT_DISCONNECTED; - common->audio_fd = AUDIO_SKT_DISCONNECTED; - common->state = AUDIO_A2DP_STATE_STOPPED; + common->ctrl_fd = AUDIO_SKT_DISCONNECTED; + common->audio_fd = AUDIO_SKT_DISCONNECTED; + common->state = AUDIO_A2DP_STATE_STOPPED; - /* manages max capacity of socket pipe */ - common->buffer_sz = AUDIO_STREAM_OUTPUT_BUFFER_SZ; + /* manages max capacity of socket pipe */ + common->buffer_sz = AUDIO_STREAM_OUTPUT_BUFFER_SZ; } -static int start_audio_datapath(struct a2dp_stream_common *common) -{ - INFO("state %d", common->state); +static int start_audio_datapath(struct a2dp_stream_common* common) { + INFO("state %d", common->state); - int oldstate = common->state; - common->state = AUDIO_A2DP_STATE_STARTING; + int oldstate = common->state; + common->state = AUDIO_A2DP_STATE_STARTING; - int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START); - if (a2dp_status < 0) - { - ERROR("Audiopath start failed (status %d)", a2dp_status); - goto error; - } - else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) - { - ERROR("Audiopath start failed - in call, move to suspended"); - goto error; - } + int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START); + if (a2dp_status < 0) { + ERROR("Audiopath start failed (status %d)", a2dp_status); + goto error; + } else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) { + ERROR("Audiopath start failed - in call, move to suspended"); + goto error; + } - /* connect socket if not yet connected */ - if (common->audio_fd == AUDIO_SKT_DISCONNECTED) - { - common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz); - if (common->audio_fd < 0) - { - ERROR("Audiopath start failed - error opening data socket"); - goto error; - } + /* connect socket if not yet connected */ + if (common->audio_fd == AUDIO_SKT_DISCONNECTED) { + common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz); + if (common->audio_fd < 0) { + ERROR("Audiopath start failed - error opening data socket"); + goto error; } - common->state = (a2dp_state_t)AUDIO_A2DP_STATE_STARTED; - return 0; + } + common->state = (a2dp_state_t)AUDIO_A2DP_STATE_STARTED; + return 0; error: - common->state = (a2dp_state_t)oldstate; - return -1; + common->state = (a2dp_state_t)oldstate; + return -1; } -static int stop_audio_datapath(struct a2dp_stream_common *common) -{ - int oldstate = common->state; +static int stop_audio_datapath(struct a2dp_stream_common* common) { + int oldstate = common->state; - INFO("state %d", common->state); + INFO("state %d", common->state); - /* prevent any stray output writes from autostarting the stream - while stopping audiopath */ - common->state = AUDIO_A2DP_STATE_STOPPING; + /* prevent any stray output writes from autostarting the stream + while stopping audiopath */ + common->state = AUDIO_A2DP_STATE_STOPPING; - if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) - { - ERROR("audiopath stop failed"); - common->state = (a2dp_state_t)oldstate; - return -1; - } + if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) { + ERROR("audiopath stop failed"); + common->state = (a2dp_state_t)oldstate; + return -1; + } - common->state = (a2dp_state_t)AUDIO_A2DP_STATE_STOPPED; + common->state = (a2dp_state_t)AUDIO_A2DP_STATE_STOPPED; - /* disconnect audio path */ - skt_disconnect(common->audio_fd); - common->audio_fd = AUDIO_SKT_DISCONNECTED; + /* disconnect audio path */ + skt_disconnect(common->audio_fd); + common->audio_fd = AUDIO_SKT_DISCONNECTED; - return 0; + return 0; } -static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standby) -{ - INFO("state %d", common->state); +static int suspend_audio_datapath(struct a2dp_stream_common* common, + bool standby) { + INFO("state %d", common->state); - if (common->state == AUDIO_A2DP_STATE_STOPPING) - return -1; + if (common->state == AUDIO_A2DP_STATE_STOPPING) return -1; - if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) - return -1; + if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) return -1; - if (standby) - common->state = AUDIO_A2DP_STATE_STANDBY; - else - common->state = AUDIO_A2DP_STATE_SUSPENDED; + if (standby) + common->state = AUDIO_A2DP_STATE_STANDBY; + else + common->state = AUDIO_A2DP_STATE_SUSPENDED; - /* disconnect audio path */ - skt_disconnect(common->audio_fd); + /* disconnect audio path */ + skt_disconnect(common->audio_fd); - common->audio_fd = AUDIO_SKT_DISCONNECTED; + common->audio_fd = AUDIO_SKT_DISCONNECTED; - return 0; + return 0; } - /***************************************************************************** * * audio output callbacks * ****************************************************************************/ -static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, - size_t bytes) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - int sent = -1; - - DEBUG("write %zu bytes (fd %d)", bytes, out->common.audio_fd); - - pthread_mutex_lock(&out->common.lock); - if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED || - out->common.state == AUDIO_A2DP_STATE_STOPPING) { - DEBUG("stream suspended or closing"); - goto finish; - } - - /* only allow autostarting if we are in stopped or standby */ - if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) || - (out->common.state == AUDIO_A2DP_STATE_STANDBY)) - { - if (start_audio_datapath(&out->common) < 0) - { - goto finish; - } - } - else if (out->common.state != AUDIO_A2DP_STATE_STARTED) - { - ERROR("stream not in stopped or standby"); - goto finish; +static ssize_t out_write(struct audio_stream_out* stream, const void* buffer, + size_t bytes) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; + int sent = -1; + + DEBUG("write %zu bytes (fd %d)", bytes, out->common.audio_fd); + + pthread_mutex_lock(&out->common.lock); + if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED || + out->common.state == AUDIO_A2DP_STATE_STOPPING) { + DEBUG("stream suspended or closing"); + goto finish; + } + + /* only allow autostarting if we are in stopped or standby */ + if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) || + (out->common.state == AUDIO_A2DP_STATE_STANDBY)) { + if (start_audio_datapath(&out->common) < 0) { + goto finish; } - - pthread_mutex_unlock(&out->common.lock); - sent = skt_write(out->common.audio_fd, buffer, bytes); - pthread_mutex_lock(&out->common.lock); - - if (sent == -1) { - skt_disconnect(out->common.audio_fd); - out->common.audio_fd = AUDIO_SKT_DISCONNECTED; - if ((out->common.state != AUDIO_A2DP_STATE_SUSPENDED) && - (out->common.state != AUDIO_A2DP_STATE_STOPPING)) { - out->common.state = AUDIO_A2DP_STATE_STOPPED; - } else { - ERROR("write failed : stream suspended, avoid resetting state"); - } - goto finish; - } - -finish: ; - const size_t frames = bytes / audio_stream_out_frame_size(stream); - out->frames_rendered += frames; - out->frames_presented += frames; - pthread_mutex_unlock(&out->common.lock); - - // If send didn't work out, sleep to emulate write delay. - if (sent == -1) { - const int us_delay = calc_audiotime_usec(out->common.cfg, bytes); - DEBUG("emulate a2dp write delay (%d us)", us_delay); - usleep(us_delay); + } else if (out->common.state != AUDIO_A2DP_STATE_STARTED) { + ERROR("stream not in stopped or standby"); + goto finish; + } + + pthread_mutex_unlock(&out->common.lock); + sent = skt_write(out->common.audio_fd, buffer, bytes); + pthread_mutex_lock(&out->common.lock); + + if (sent == -1) { + skt_disconnect(out->common.audio_fd); + out->common.audio_fd = AUDIO_SKT_DISCONNECTED; + if ((out->common.state != AUDIO_A2DP_STATE_SUSPENDED) && + (out->common.state != AUDIO_A2DP_STATE_STOPPING)) { + out->common.state = AUDIO_A2DP_STATE_STOPPED; + } else { + ERROR("write failed : stream suspended, avoid resetting state"); } - return bytes; + goto finish; + } + +finish:; + const size_t frames = bytes / audio_stream_out_frame_size(stream); + out->frames_rendered += frames; + out->frames_presented += frames; + pthread_mutex_unlock(&out->common.lock); + + // If send didn't work out, sleep to emulate write delay. + if (sent == -1) { + const int us_delay = calc_audiotime_usec(out->common.cfg, bytes); + DEBUG("emulate a2dp write delay (%d us)", us_delay); + usleep(us_delay); + } + return bytes; } -static uint32_t out_get_sample_rate(const struct audio_stream *stream) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static uint32_t out_get_sample_rate(const struct audio_stream* stream) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - DEBUG("rate %" PRIu32,out->common.cfg.rate); + DEBUG("rate %" PRIu32, out->common.cfg.rate); - return out->common.cfg.rate; + return out->common.cfg.rate; } -static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static int out_set_sample_rate(struct audio_stream* stream, uint32_t rate) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - DEBUG("out_set_sample_rate : %" PRIu32, rate); + DEBUG("out_set_sample_rate : %" PRIu32, rate); - out->common.cfg.rate = rate; + out->common.cfg.rate = rate; - return 0; + return 0; } -static size_t out_get_buffer_size(const struct audio_stream *stream) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - // period_size is the AudioFlinger mixer buffer size. - const size_t period_size = out->common.buffer_sz / AUDIO_STREAM_OUTPUT_BUFFER_PERIODS; - const size_t mixer_unit_size = 16 /* frames */ * 4 /* framesize */; - - DEBUG("socket buffer size: %zu period size: %zu", out->common.buffer_sz, period_size); - if (period_size % mixer_unit_size != 0) { - ERROR("period size %zu not a multiple of %zu", period_size, mixer_unit_size); - } +static size_t out_get_buffer_size(const struct audio_stream* stream) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; + // period_size is the AudioFlinger mixer buffer size. + const size_t period_size = + out->common.buffer_sz / AUDIO_STREAM_OUTPUT_BUFFER_PERIODS; + const size_t mixer_unit_size = 16 /* frames */ * 4 /* framesize */; + + DEBUG("socket buffer size: %zu period size: %zu", out->common.buffer_sz, + period_size); + if (period_size % mixer_unit_size != 0) { + ERROR("period size %zu not a multiple of %zu", period_size, + mixer_unit_size); + } - return period_size; + return period_size; } -static uint32_t out_get_channels(const struct audio_stream *stream) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static uint32_t out_get_channels(const struct audio_stream* stream) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - DEBUG("channels 0x%" PRIx32, out->common.cfg.channel_mask); + DEBUG("channels 0x%" PRIx32, out->common.cfg.channel_mask); - return out->common.cfg.channel_mask; + return out->common.cfg.channel_mask; } -static audio_format_t out_get_format(const struct audio_stream *stream) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - DEBUG("format 0x%x", out->common.cfg.format); - return (audio_format_t)out->common.cfg.format; +static audio_format_t out_get_format(const struct audio_stream* stream) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; + DEBUG("format 0x%x", out->common.cfg.format); + return (audio_format_t)out->common.cfg.format; } -static int out_set_format(UNUSED_ATTR struct audio_stream *stream, - UNUSED_ATTR audio_format_t format) -{ - DEBUG("setting format not yet supported (0x%x)", format); - return -ENOSYS; +static int out_set_format(UNUSED_ATTR struct audio_stream* stream, + UNUSED_ATTR audio_format_t format) { + DEBUG("setting format not yet supported (0x%x)", format); + return -ENOSYS; } -static int out_standby(struct audio_stream *stream) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - int retVal = 0; +static int out_standby(struct audio_stream* stream) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; + int retVal = 0; - FNLOG(); + FNLOG(); - pthread_mutex_lock(&out->common.lock); - // Do nothing in SUSPENDED state. - if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) - retVal = suspend_audio_datapath(&out->common, true); - out->frames_rendered = 0; // rendered is reset, presented is not - pthread_mutex_unlock (&out->common.lock); + pthread_mutex_lock(&out->common.lock); + // Do nothing in SUSPENDED state. + if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) + retVal = suspend_audio_datapath(&out->common, true); + out->frames_rendered = 0; // rendered is reset, presented is not + pthread_mutex_unlock(&out->common.lock); - return retVal; + return retVal; } -static int out_dump(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR int fd) -{ - FNLOG(); - return 0; +static int out_dump(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR int fd) { + FNLOG(); + return 0; } -static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static int out_set_parameters(struct audio_stream* stream, + const char* kvpairs) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - INFO("state %d kvpairs %s", out->common.state, kvpairs); + INFO("state %d kvpairs %s", out->common.state, kvpairs); - std::unordered_map params = - hash_map_utils_new_from_string_params(kvpairs); - int status = 0; + std::unordered_map params = + hash_map_utils_new_from_string_params(kvpairs); + int status = 0; - if (params.empty()) - return status; + if (params.empty()) return status; - pthread_mutex_lock(&out->common.lock); + pthread_mutex_lock(&out->common.lock); - /* dump params */ - hash_map_utils_dump_string_keys_string_values(params); + /* dump params */ + hash_map_utils_dump_string_keys_string_values(params); - if (params["closing"].compare("true") == 0) - { - DEBUG("stream closing, disallow any writes"); - out->common.state = AUDIO_A2DP_STATE_STOPPING; - } + if (params["closing"].compare("true") == 0) { + DEBUG("stream closing, disallow any writes"); + out->common.state = AUDIO_A2DP_STATE_STOPPING; + } - if (params["A2dpSuspended"].compare("true") == 0) - { - if (out->common.state == AUDIO_A2DP_STATE_STARTED) - status = suspend_audio_datapath(&out->common, false); - } - else - { - /* Do not start the streaming automatically. If the phone was streaming - * prior to being suspended, the next out_write shall trigger the - * AVDTP start procedure */ - if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) - out->common.state = AUDIO_A2DP_STATE_STANDBY; - /* Irrespective of the state, return 0 */ - } + if (params["A2dpSuspended"].compare("true") == 0) { + if (out->common.state == AUDIO_A2DP_STATE_STARTED) + status = suspend_audio_datapath(&out->common, false); + } else { + /* Do not start the streaming automatically. If the phone was streaming + * prior to being suspended, the next out_write shall trigger the + * AVDTP start procedure */ + if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) + out->common.state = AUDIO_A2DP_STATE_STANDBY; + /* Irrespective of the state, return 0 */ + } - pthread_mutex_unlock(&out->common.lock); + pthread_mutex_unlock(&out->common.lock); - return status; + return status; } -static char * out_get_parameters(const struct audio_stream *stream, - const char *keys) -{ - FNLOG(); +static char* out_get_parameters(const struct audio_stream* stream, + const char* keys) { + FNLOG(); - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - std::unordered_map params = - hash_map_utils_new_from_string_params(keys); - std::unordered_map return_params; + std::unordered_map params = + hash_map_utils_new_from_string_params(keys); + std::unordered_map return_params; - if (params.empty()) - return strdup(""); + if (params.empty()) return strdup(""); - pthread_mutex_lock(&out->common.lock); + pthread_mutex_lock(&out->common.lock); - if (a2dp_read_output_audio_config(&out->common) < 0) { - ERROR("a2dp_read_output_audio_config failed"); - goto done; - } + if (a2dp_read_output_audio_config(&out->common) < 0) { + ERROR("a2dp_read_output_audio_config failed"); + goto done; + } - // Add the format - if (params.find(AUDIO_PARAMETER_STREAM_SUP_FORMATS) != params.end()) { - std::string param; - switch (out->common.cfg.format) { + // Add the format + if (params.find(AUDIO_PARAMETER_STREAM_SUP_FORMATS) != params.end()) { + std::string param; + switch (out->common.cfg.format) { case AUDIO_FORMAT_PCM_16_BIT: param = "AUDIO_FORMAT_PCM_16_BIT"; break; @@ -907,16 +859,16 @@ static char * out_get_parameters(const struct audio_stream *stream, default: ERROR("Invalid audio format: 0x%x", out->common.cfg.format); break; - } - if (!param.empty()) { - return_params[AUDIO_PARAMETER_STREAM_SUP_FORMATS] = param; - } } + if (!param.empty()) { + return_params[AUDIO_PARAMETER_STREAM_SUP_FORMATS] = param; + } + } - // Add the channel mask - if (params.find(AUDIO_PARAMETER_STREAM_SUP_CHANNELS) != params.end()) { - std::string param; - switch (out->common.cfg.channel_mask) { + // Add the channel mask + if (params.find(AUDIO_PARAMETER_STREAM_SUP_CHANNELS) != params.end()) { + std::string param; + switch (out->common.cfg.channel_mask) { case AUDIO_CHANNEL_OUT_MONO: param = "AUDIO_CHANNEL_OUT_MONO"; break; @@ -926,16 +878,16 @@ static char * out_get_parameters(const struct audio_stream *stream, default: ERROR("Invalid channel mask: 0x%x", out->common.cfg.channel_mask); break; - } - if (!param.empty()) { - return_params[AUDIO_PARAMETER_STREAM_SUP_CHANNELS] = param; - } } + if (!param.empty()) { + return_params[AUDIO_PARAMETER_STREAM_SUP_CHANNELS] = param; + } + } - // Add the sample rate - if (params.find(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES) != params.end()) { - std::string param; - switch (out->common.cfg.rate) { + // Add the sample rate + if (params.find(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES) != params.end()) { + std::string param; + switch (out->common.cfg.rate) { case 44100: case 48000: case 88200: @@ -945,639 +897,591 @@ static char * out_get_parameters(const struct audio_stream *stream, default: ERROR("Invalid sample rate: %d", out->common.cfg.rate); break; - } - if (!param.empty()) { - return_params[AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES] = param; - } } + if (!param.empty()) { + return_params[AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES] = param; + } + } done: - pthread_mutex_unlock(&out->common.lock); + pthread_mutex_unlock(&out->common.lock); - std::string result; - for (const auto& ptr : return_params) { - result += ptr.first + "=" + ptr.second + ";"; - } + std::string result; + for (const auto& ptr : return_params) { + result += ptr.first + "=" + ptr.second + ";"; + } - INFO("get parameters result = %s", result.c_str()); + INFO("get parameters result = %s", result.c_str()); - return strdup(result.c_str()); + return strdup(result.c_str()); } -static uint32_t out_get_latency(const struct audio_stream_out *stream) -{ - int latency_us; - - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static uint32_t out_get_latency(const struct audio_stream_out* stream) { + int latency_us; - FNLOG(); + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - latency_us = ((out->common.buffer_sz * 1000 ) / - audio_stream_out_frame_size(&out->stream) / - out->common.cfg.rate) * 1000; + FNLOG(); + latency_us = + ((out->common.buffer_sz * 1000) / + audio_stream_out_frame_size(&out->stream) / out->common.cfg.rate) * + 1000; - return (latency_us / 1000) + 200; + return (latency_us / 1000) + 200; } -static int out_set_volume(UNUSED_ATTR struct audio_stream_out *stream, UNUSED_ATTR float left, - UNUSED_ATTR float right) -{ - - FNLOG(); +static int out_set_volume(UNUSED_ATTR struct audio_stream_out* stream, + UNUSED_ATTR float left, UNUSED_ATTR float right) { + FNLOG(); - /* volume controlled in audioflinger mixer (digital) */ + /* volume controlled in audioflinger mixer (digital) */ - return -ENOSYS; + return -ENOSYS; } -static int out_get_presentation_position(const struct audio_stream_out *stream, - uint64_t *frames, struct timespec *timestamp) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; - - FNLOG(); - if (stream == NULL || frames == NULL || timestamp == NULL) - return -EINVAL; - - int ret = -EWOULDBLOCK; - pthread_mutex_lock(&out->common.lock); - uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; - if (out->frames_presented >= latency_frames) { - *frames = out->frames_presented - latency_frames; - clock_gettime(CLOCK_MONOTONIC, timestamp); // could also be associated with out_write(). - ret = 0; - } - pthread_mutex_unlock(&out->common.lock); - return ret; +static int out_get_presentation_position(const struct audio_stream_out* stream, + uint64_t* frames, + struct timespec* timestamp) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; + + FNLOG(); + if (stream == NULL || frames == NULL || timestamp == NULL) return -EINVAL; + + int ret = -EWOULDBLOCK; + pthread_mutex_lock(&out->common.lock); + uint64_t latency_frames = + (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; + if (out->frames_presented >= latency_frames) { + *frames = out->frames_presented - latency_frames; + clock_gettime(CLOCK_MONOTONIC, + timestamp); // could also be associated with out_write(). + ret = 0; + } + pthread_mutex_unlock(&out->common.lock); + return ret; } -static int out_get_render_position(const struct audio_stream_out *stream, - uint32_t *dsp_frames) -{ - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static int out_get_render_position(const struct audio_stream_out* stream, + uint32_t* dsp_frames) { + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - FNLOG(); - if (stream == NULL || dsp_frames == NULL) - return -EINVAL; + FNLOG(); + if (stream == NULL || dsp_frames == NULL) return -EINVAL; - pthread_mutex_lock(&out->common.lock); - uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; - if (out->frames_rendered >= latency_frames) { - *dsp_frames = (uint32_t)(out->frames_rendered - latency_frames); - } else { - *dsp_frames = 0; - } - pthread_mutex_unlock(&out->common.lock); - return 0; + pthread_mutex_lock(&out->common.lock); + uint64_t latency_frames = + (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; + if (out->frames_rendered >= latency_frames) { + *dsp_frames = (uint32_t)(out->frames_rendered - latency_frames); + } else { + *dsp_frames = 0; + } + pthread_mutex_unlock(&out->common.lock); + return 0; } -static int out_add_audio_effect(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR effect_handle_t effect) -{ - FNLOG(); - return 0; +static int out_add_audio_effect(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR effect_handle_t effect) { + FNLOG(); + return 0; } -static int out_remove_audio_effect(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR effect_handle_t effect) -{ - FNLOG(); - return 0; +static int out_remove_audio_effect( + UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR effect_handle_t effect) { + FNLOG(); + return 0; } /* * AUDIO INPUT STREAM */ -static uint32_t in_get_sample_rate(const struct audio_stream *stream) -{ - struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream; +static uint32_t in_get_sample_rate(const struct audio_stream* stream) { + struct a2dp_stream_in* in = (struct a2dp_stream_in*)stream; - FNLOG(); - return in->common.cfg.rate; + FNLOG(); + return in->common.cfg.rate; } -static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) -{ - struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream; +static int in_set_sample_rate(struct audio_stream* stream, uint32_t rate) { + struct a2dp_stream_in* in = (struct a2dp_stream_in*)stream; - FNLOG(); + FNLOG(); - if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) - return 0; - else - return -1; + if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) + return 0; + else + return -1; } -static size_t in_get_buffer_size(UNUSED_ATTR const struct audio_stream *stream) -{ - - FNLOG(); - return 320; +static size_t in_get_buffer_size( + UNUSED_ATTR const struct audio_stream* stream) { + FNLOG(); + return 320; } -static uint32_t in_get_channels(const struct audio_stream *stream) -{ - struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream; +static uint32_t in_get_channels(const struct audio_stream* stream) { + struct a2dp_stream_in* in = (struct a2dp_stream_in*)stream; - FNLOG(); - return in->common.cfg.channel_mask; + FNLOG(); + return in->common.cfg.channel_mask; } -static audio_format_t in_get_format(UNUSED_ATTR const struct audio_stream *stream) -{ - - FNLOG(); - return AUDIO_FORMAT_PCM_16_BIT; +static audio_format_t in_get_format( + UNUSED_ATTR const struct audio_stream* stream) { + FNLOG(); + return AUDIO_FORMAT_PCM_16_BIT; } -static int in_set_format(UNUSED_ATTR struct audio_stream *stream, - UNUSED_ATTR audio_format_t format) -{ - - FNLOG(); - if (format == AUDIO_FORMAT_PCM_16_BIT) - return 0; - else - return -1; +static int in_set_format(UNUSED_ATTR struct audio_stream* stream, + UNUSED_ATTR audio_format_t format) { + FNLOG(); + if (format == AUDIO_FORMAT_PCM_16_BIT) + return 0; + else + return -1; } -static int in_standby(UNUSED_ATTR struct audio_stream *stream) -{ - - FNLOG(); - return 0; +static int in_standby(UNUSED_ATTR struct audio_stream* stream) { + FNLOG(); + return 0; } -static int in_dump(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR int fd) -{ - FNLOG(); - return 0; +static int in_dump(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR int fd) { + FNLOG(); + return 0; } -static int in_set_parameters(UNUSED_ATTR struct audio_stream *stream, - UNUSED_ATTR const char *kvpairs) -{ +static int in_set_parameters(UNUSED_ATTR struct audio_stream* stream, + UNUSED_ATTR const char* kvpairs) { + FNLOG(); + return 0; +} - FNLOG(); - return 0; +static char* in_get_parameters(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR const char* keys) { + FNLOG(); + return strdup(""); } -static char * in_get_parameters(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR const char *keys) -{ - FNLOG(); - return strdup(""); +static int in_set_gain(UNUSED_ATTR struct audio_stream_in* stream, + UNUSED_ATTR float gain) { + FNLOG(); + return 0; } -static int in_set_gain(UNUSED_ATTR struct audio_stream_in *stream, - UNUSED_ATTR float gain) -{ +static ssize_t in_read(struct audio_stream_in* stream, void* buffer, + size_t bytes) { + struct a2dp_stream_in* in = (struct a2dp_stream_in*)stream; + int read; + int us_delay; - FNLOG(); - return 0; -} + DEBUG("read %zu bytes, state: %d", bytes, in->common.state); -static ssize_t in_read(struct audio_stream_in *stream, void* buffer, - size_t bytes) -{ - struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream; - int read; - int us_delay; - - DEBUG("read %zu bytes, state: %d", bytes, in->common.state); - - pthread_mutex_lock(&in->common.lock); - if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED || - in->common.state == AUDIO_A2DP_STATE_STOPPING) - { - DEBUG("stream suspended"); - goto error; - } + pthread_mutex_lock(&in->common.lock); + if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED || + in->common.state == AUDIO_A2DP_STATE_STOPPING) { + DEBUG("stream suspended"); + goto error; + } - /* only allow autostarting if we are in stopped or standby */ - if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) || - (in->common.state == AUDIO_A2DP_STATE_STANDBY)) - { - if (start_audio_datapath(&in->common) < 0) - { - goto error; - } + /* only allow autostarting if we are in stopped or standby */ + if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) || + (in->common.state == AUDIO_A2DP_STATE_STANDBY)) { + if (start_audio_datapath(&in->common) < 0) { + goto error; } - else if (in->common.state != AUDIO_A2DP_STATE_STARTED) - { - ERROR("stream not in stopped or standby"); - goto error; - } - - pthread_mutex_unlock(&in->common.lock); - read = skt_read(in->common.audio_fd, buffer, bytes); - pthread_mutex_lock(&in->common.lock); - if (read == -1) - { - skt_disconnect(in->common.audio_fd); - in->common.audio_fd = AUDIO_SKT_DISCONNECTED; - if ((in->common.state != AUDIO_A2DP_STATE_SUSPENDED) && - (in->common.state != AUDIO_A2DP_STATE_STOPPING)) { - in->common.state = AUDIO_A2DP_STATE_STOPPED; - } else { - ERROR("read failed : stream suspended, avoid resetting state"); - } - goto error; - } else if (read == 0) { - DEBUG("read time out - return zeros"); - memset(buffer, 0, bytes); - read = bytes; + } else if (in->common.state != AUDIO_A2DP_STATE_STARTED) { + ERROR("stream not in stopped or standby"); + goto error; + } + + pthread_mutex_unlock(&in->common.lock); + read = skt_read(in->common.audio_fd, buffer, bytes); + pthread_mutex_lock(&in->common.lock); + if (read == -1) { + skt_disconnect(in->common.audio_fd); + in->common.audio_fd = AUDIO_SKT_DISCONNECTED; + if ((in->common.state != AUDIO_A2DP_STATE_SUSPENDED) && + (in->common.state != AUDIO_A2DP_STATE_STOPPING)) { + in->common.state = AUDIO_A2DP_STATE_STOPPED; + } else { + ERROR("read failed : stream suspended, avoid resetting state"); } - pthread_mutex_unlock(&in->common.lock); + goto error; + } else if (read == 0) { + DEBUG("read time out - return zeros"); + memset(buffer, 0, bytes); + read = bytes; + } + pthread_mutex_unlock(&in->common.lock); - DEBUG("read %d bytes out of %zu bytes", read, bytes); - return read; + DEBUG("read %d bytes out of %zu bytes", read, bytes); + return read; error: - pthread_mutex_unlock(&in->common.lock); - memset(buffer, 0, bytes); - us_delay = calc_audiotime_usec(in->common.cfg, bytes); - DEBUG("emulate a2dp read delay (%d us)", us_delay); + pthread_mutex_unlock(&in->common.lock); + memset(buffer, 0, bytes); + us_delay = calc_audiotime_usec(in->common.cfg, bytes); + DEBUG("emulate a2dp read delay (%d us)", us_delay); - usleep(us_delay); - return bytes; + usleep(us_delay); + return bytes; } -static uint32_t in_get_input_frames_lost(UNUSED_ATTR struct audio_stream_in *stream) -{ - - FNLOG(); - return 0; +static uint32_t in_get_input_frames_lost( + UNUSED_ATTR struct audio_stream_in* stream) { + FNLOG(); + return 0; } -static int in_add_audio_effect(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR effect_handle_t effect) -{ - FNLOG(); - return 0; +static int in_add_audio_effect(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR effect_handle_t effect) { + FNLOG(); + return 0; } -static int in_remove_audio_effect(UNUSED_ATTR const struct audio_stream *stream, - UNUSED_ATTR effect_handle_t effect) -{ - FNLOG(); +static int in_remove_audio_effect(UNUSED_ATTR const struct audio_stream* stream, + UNUSED_ATTR effect_handle_t effect) { + FNLOG(); - return 0; + return 0; } -static int adev_open_output_stream(struct audio_hw_device *dev, +static int adev_open_output_stream(struct audio_hw_device* dev, UNUSED_ATTR audio_io_handle_t handle, UNUSED_ATTR audio_devices_t devices, UNUSED_ATTR audio_output_flags_t flags, - struct audio_config *config, - struct audio_stream_out **stream_out, - UNUSED_ATTR const char *address) - -{ - struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_out *out; - int ret = 0; - - INFO("opening output"); - - out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out)); - - if (!out) - return -ENOMEM; - - out->stream.common.get_sample_rate = out_get_sample_rate; - out->stream.common.set_sample_rate = out_set_sample_rate; - out->stream.common.get_buffer_size = out_get_buffer_size; - out->stream.common.get_channels = out_get_channels; - out->stream.common.get_format = out_get_format; - out->stream.common.set_format = out_set_format; - out->stream.common.standby = out_standby; - out->stream.common.dump = out_dump; - out->stream.common.set_parameters = out_set_parameters; - out->stream.common.get_parameters = out_get_parameters; - out->stream.common.add_audio_effect = out_add_audio_effect; - out->stream.common.remove_audio_effect = out_remove_audio_effect; - out->stream.get_latency = out_get_latency; - out->stream.set_volume = out_set_volume; - out->stream.write = out_write; - out->stream.get_render_position = out_get_render_position; - out->stream.get_presentation_position = out_get_presentation_position; - - - /* initialize a2dp specifics */ - a2dp_stream_common_init(&out->common); - - if (a2dp_read_output_audio_config(&out->common) < 0) { - ERROR("a2dp_read_output_audio_config failed"); - ret = -1; - goto err_open; - } - - /* set output config values */ - if (config) - { - config->format = out_get_format((const struct audio_stream *)&out->stream); - config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream); - config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream); - } - *stream_out = &out->stream; - a2dp_dev->output = out; - - a2dp_open_ctrl_path(&out->common); - if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) - { - ERROR("ctrl socket failed to connect (%s)", strerror(errno)); - ret = -1; - goto err_open; - } - - DEBUG("success"); - /* Delay to ensure Headset is in proper state when START is initiated from - * DUT immediately after the connection due to ongoing music playback. */ - usleep(250000); - return 0; + struct audio_config* config, + struct audio_stream_out** stream_out, + UNUSED_ATTR const char* address) + +{ + struct a2dp_audio_device* a2dp_dev = (struct a2dp_audio_device*)dev; + struct a2dp_stream_out* out; + int ret = 0; + + INFO("opening output"); + + out = (struct a2dp_stream_out*)calloc(1, sizeof(struct a2dp_stream_out)); + + if (!out) return -ENOMEM; + + out->stream.common.get_sample_rate = out_get_sample_rate; + out->stream.common.set_sample_rate = out_set_sample_rate; + out->stream.common.get_buffer_size = out_get_buffer_size; + out->stream.common.get_channels = out_get_channels; + out->stream.common.get_format = out_get_format; + out->stream.common.set_format = out_set_format; + out->stream.common.standby = out_standby; + out->stream.common.dump = out_dump; + out->stream.common.set_parameters = out_set_parameters; + out->stream.common.get_parameters = out_get_parameters; + out->stream.common.add_audio_effect = out_add_audio_effect; + out->stream.common.remove_audio_effect = out_remove_audio_effect; + out->stream.get_latency = out_get_latency; + out->stream.set_volume = out_set_volume; + out->stream.write = out_write; + out->stream.get_render_position = out_get_render_position; + out->stream.get_presentation_position = out_get_presentation_position; + + /* initialize a2dp specifics */ + a2dp_stream_common_init(&out->common); + + if (a2dp_read_output_audio_config(&out->common) < 0) { + ERROR("a2dp_read_output_audio_config failed"); + ret = -1; + goto err_open; + } + + /* set output config values */ + if (config) { + config->format = out_get_format((const struct audio_stream*)&out->stream); + config->sample_rate = + out_get_sample_rate((const struct audio_stream*)&out->stream); + config->channel_mask = + out_get_channels((const struct audio_stream*)&out->stream); + } + *stream_out = &out->stream; + a2dp_dev->output = out; + + a2dp_open_ctrl_path(&out->common); + if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) { + ERROR("ctrl socket failed to connect (%s)", strerror(errno)); + ret = -1; + goto err_open; + } + + DEBUG("success"); + /* Delay to ensure Headset is in proper state when START is initiated from + * DUT immediately after the connection due to ongoing music playback. */ + usleep(250000); + return 0; err_open: - free(out); - *stream_out = NULL; - a2dp_dev->output = NULL; - ERROR("failed"); - return ret; + free(out); + *stream_out = NULL; + a2dp_dev->output = NULL; + ERROR("failed"); + return ret; } -static void adev_close_output_stream(struct audio_hw_device *dev, - struct audio_stream_out *stream) -{ - struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; +static void adev_close_output_stream(struct audio_hw_device* dev, + struct audio_stream_out* stream) { + struct a2dp_audio_device* a2dp_dev = (struct a2dp_audio_device*)dev; + struct a2dp_stream_out* out = (struct a2dp_stream_out*)stream; - INFO("closing output (state %d)", out->common.state); + INFO("closing output (state %d)", out->common.state); - pthread_mutex_lock(&out->common.lock); - if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || - (out->common.state == AUDIO_A2DP_STATE_STOPPING)) { - stop_audio_datapath(&out->common); - } + pthread_mutex_lock(&out->common.lock); + if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || + (out->common.state == AUDIO_A2DP_STATE_STOPPING)) { + stop_audio_datapath(&out->common); + } - skt_disconnect(out->common.ctrl_fd); - out->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; - free(stream); - a2dp_dev->output = NULL; - pthread_mutex_unlock(&out->common.lock); + skt_disconnect(out->common.ctrl_fd); + out->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; + free(stream); + a2dp_dev->output = NULL; + pthread_mutex_unlock(&out->common.lock); - DEBUG("done"); + DEBUG("done"); } -static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) -{ - struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_out *out = a2dp_dev->output; - int retval = 0; +static int adev_set_parameters(struct audio_hw_device* dev, + const char* kvpairs) { + struct a2dp_audio_device* a2dp_dev = (struct a2dp_audio_device*)dev; + struct a2dp_stream_out* out = a2dp_dev->output; + int retval = 0; - if (out == NULL) - return retval; + if (out == NULL) return retval; - INFO("state %d", out->common.state); + INFO("state %d", out->common.state); - retval = out->stream.common.set_parameters((struct audio_stream *)out, kvpairs); + retval = + out->stream.common.set_parameters((struct audio_stream*)out, kvpairs); - return retval; + return retval; } -static char * adev_get_parameters(UNUSED_ATTR const struct audio_hw_device *dev, - const char *keys) -{ - FNLOG(); +static char* adev_get_parameters(UNUSED_ATTR const struct audio_hw_device* dev, + const char* keys) { + FNLOG(); - std::unordered_map params = - hash_map_utils_new_from_string_params(keys); - hash_map_utils_dump_string_keys_string_values(params); + std::unordered_map params = + hash_map_utils_new_from_string_params(keys); + hash_map_utils_dump_string_keys_string_values(params); - return strdup(""); + return strdup(""); } -static int adev_init_check(UNUSED_ATTR const struct audio_hw_device *dev) -{ - - FNLOG(); +static int adev_init_check(UNUSED_ATTR const struct audio_hw_device* dev) { + FNLOG(); - return 0; + return 0; } -static int adev_set_voice_volume(UNUSED_ATTR struct audio_hw_device *dev, - UNUSED_ATTR float volume) -{ - FNLOG(); +static int adev_set_voice_volume(UNUSED_ATTR struct audio_hw_device* dev, + UNUSED_ATTR float volume) { + FNLOG(); - return -ENOSYS; + return -ENOSYS; } -static int adev_set_master_volume(UNUSED_ATTR struct audio_hw_device *dev, - UNUSED_ATTR float volume) -{ - FNLOG(); +static int adev_set_master_volume(UNUSED_ATTR struct audio_hw_device* dev, + UNUSED_ATTR float volume) { + FNLOG(); - return -ENOSYS; + return -ENOSYS; } -static int adev_set_mode(UNUSED_ATTR struct audio_hw_device *dev, - UNUSED_ATTR audio_mode_t mode) -{ - FNLOG(); +static int adev_set_mode(UNUSED_ATTR struct audio_hw_device* dev, + UNUSED_ATTR audio_mode_t mode) { + FNLOG(); - return 0; + return 0; } -static int adev_set_mic_mute(UNUSED_ATTR struct audio_hw_device *dev, - UNUSED_ATTR bool state) -{ - FNLOG(); +static int adev_set_mic_mute(UNUSED_ATTR struct audio_hw_device* dev, + UNUSED_ATTR bool state) { + FNLOG(); - return -ENOSYS; + return -ENOSYS; } -static int adev_get_mic_mute(UNUSED_ATTR const struct audio_hw_device *dev, - UNUSED_ATTR bool *state) -{ - FNLOG(); +static int adev_get_mic_mute(UNUSED_ATTR const struct audio_hw_device* dev, + UNUSED_ATTR bool* state) { + FNLOG(); - return -ENOSYS; + return -ENOSYS; } -static size_t adev_get_input_buffer_size(UNUSED_ATTR const struct audio_hw_device *dev, - UNUSED_ATTR const struct audio_config *config) -{ - FNLOG(); +static size_t adev_get_input_buffer_size( + UNUSED_ATTR const struct audio_hw_device* dev, + UNUSED_ATTR const struct audio_config* config) { + FNLOG(); - return 320; + return 320; } -static int adev_open_input_stream(struct audio_hw_device *dev, +static int adev_open_input_stream(struct audio_hw_device* dev, UNUSED_ATTR audio_io_handle_t handle, UNUSED_ATTR audio_devices_t devices, - UNUSED_ATTR struct audio_config *config, - struct audio_stream_in **stream_in, + UNUSED_ATTR struct audio_config* config, + struct audio_stream_in** stream_in, UNUSED_ATTR audio_input_flags_t flags, - UNUSED_ATTR const char *address, - UNUSED_ATTR audio_source_t source) -{ - struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_in *in; - int ret; - - FNLOG(); - - in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in)); - - if (!in) - return -ENOMEM; - - in->stream.common.get_sample_rate = in_get_sample_rate; - in->stream.common.set_sample_rate = in_set_sample_rate; - in->stream.common.get_buffer_size = in_get_buffer_size; - in->stream.common.get_channels = in_get_channels; - in->stream.common.get_format = in_get_format; - in->stream.common.set_format = in_set_format; - in->stream.common.standby = in_standby; - in->stream.common.dump = in_dump; - in->stream.common.set_parameters = in_set_parameters; - in->stream.common.get_parameters = in_get_parameters; - in->stream.common.add_audio_effect = in_add_audio_effect; - in->stream.common.remove_audio_effect = in_remove_audio_effect; - in->stream.set_gain = in_set_gain; - in->stream.read = in_read; - in->stream.get_input_frames_lost = in_get_input_frames_lost; - - /* initialize a2dp specifics */ - a2dp_stream_common_init(&in->common); - - *stream_in = &in->stream; - a2dp_dev->input = in; - - a2dp_open_ctrl_path(&in->common); - if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) - { - ERROR("ctrl socket failed to connect (%s)", strerror(errno)); - ret = -1; - goto err_open; - } - - if (a2dp_read_input_audio_config(&in->common) < 0) { - ERROR("a2dp_read_input_audio_config failed (%s)", strerror(errno)); - ret = -1; - goto err_open; - } - - DEBUG("success"); - return 0; + UNUSED_ATTR const char* address, + UNUSED_ATTR audio_source_t source) { + struct a2dp_audio_device* a2dp_dev = (struct a2dp_audio_device*)dev; + struct a2dp_stream_in* in; + int ret; + + FNLOG(); + + in = (struct a2dp_stream_in*)calloc(1, sizeof(struct a2dp_stream_in)); + + if (!in) return -ENOMEM; + + in->stream.common.get_sample_rate = in_get_sample_rate; + in->stream.common.set_sample_rate = in_set_sample_rate; + in->stream.common.get_buffer_size = in_get_buffer_size; + in->stream.common.get_channels = in_get_channels; + in->stream.common.get_format = in_get_format; + in->stream.common.set_format = in_set_format; + in->stream.common.standby = in_standby; + in->stream.common.dump = in_dump; + in->stream.common.set_parameters = in_set_parameters; + in->stream.common.get_parameters = in_get_parameters; + in->stream.common.add_audio_effect = in_add_audio_effect; + in->stream.common.remove_audio_effect = in_remove_audio_effect; + in->stream.set_gain = in_set_gain; + in->stream.read = in_read; + in->stream.get_input_frames_lost = in_get_input_frames_lost; + + /* initialize a2dp specifics */ + a2dp_stream_common_init(&in->common); + + *stream_in = &in->stream; + a2dp_dev->input = in; + + a2dp_open_ctrl_path(&in->common); + if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) { + ERROR("ctrl socket failed to connect (%s)", strerror(errno)); + ret = -1; + goto err_open; + } + + if (a2dp_read_input_audio_config(&in->common) < 0) { + ERROR("a2dp_read_input_audio_config failed (%s)", strerror(errno)); + ret = -1; + goto err_open; + } + + DEBUG("success"); + return 0; err_open: - free(in); - *stream_in = NULL; - a2dp_dev->input = NULL; - ERROR("failed"); - return ret; + free(in); + *stream_in = NULL; + a2dp_dev->input = NULL; + ERROR("failed"); + return ret; } -static void adev_close_input_stream(struct audio_hw_device *dev, - struct audio_stream_in *stream) -{ - struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; - struct a2dp_stream_in* in = (struct a2dp_stream_in *)stream; - a2dp_state_t state = in->common.state; +static void adev_close_input_stream(struct audio_hw_device* dev, + struct audio_stream_in* stream) { + struct a2dp_audio_device* a2dp_dev = (struct a2dp_audio_device*)dev; + struct a2dp_stream_in* in = (struct a2dp_stream_in*)stream; + a2dp_state_t state = in->common.state; - INFO("closing input (state %d)", state); + INFO("closing input (state %d)", state); - if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING)) - stop_audio_datapath(&in->common); + if ((state == AUDIO_A2DP_STATE_STARTED) || + (state == AUDIO_A2DP_STATE_STOPPING)) + stop_audio_datapath(&in->common); - skt_disconnect(in->common.ctrl_fd); - in->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; - free(stream); - a2dp_dev->input = NULL; + skt_disconnect(in->common.ctrl_fd); + in->common.ctrl_fd = AUDIO_SKT_DISCONNECTED; + free(stream); + a2dp_dev->input = NULL; - DEBUG("done"); + DEBUG("done"); } -static int adev_dump(UNUSED_ATTR const audio_hw_device_t *device, - UNUSED_ATTR int fd) -{ - FNLOG(); +static int adev_dump(UNUSED_ATTR const audio_hw_device_t* device, + UNUSED_ATTR int fd) { + FNLOG(); - return 0; + return 0; } -static int adev_close(hw_device_t *device) -{ - FNLOG(); +static int adev_close(hw_device_t* device) { + FNLOG(); - free(device); - return 0; + free(device); + return 0; } static int adev_open(const hw_module_t* module, const char* name, - hw_device_t** device) -{ - struct a2dp_audio_device *adev; + hw_device_t** device) { + struct a2dp_audio_device* adev; - INFO(" adev_open in A2dp_hw module"); - FNLOG(); + INFO(" adev_open in A2dp_hw module"); + FNLOG(); - if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) - { - ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE); - return -EINVAL; - } + if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) { + ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE); + return -EINVAL; + } - adev = (struct a2dp_audio_device *)calloc(1, sizeof(struct a2dp_audio_device)); + adev = (struct a2dp_audio_device*)calloc(1, sizeof(struct a2dp_audio_device)); - if (!adev) - return -ENOMEM; + if (!adev) return -ENOMEM; - adev->device.common.tag = HARDWARE_DEVICE_TAG; - adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; - adev->device.common.module = (struct hw_module_t *) module; - adev->device.common.close = adev_close; + adev->device.common.tag = HARDWARE_DEVICE_TAG; + adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; + adev->device.common.module = (struct hw_module_t*)module; + adev->device.common.close = adev_close; - adev->device.init_check = adev_init_check; - adev->device.set_voice_volume = adev_set_voice_volume; - adev->device.set_master_volume = adev_set_master_volume; - adev->device.set_mode = adev_set_mode; - adev->device.set_mic_mute = adev_set_mic_mute; - adev->device.get_mic_mute = adev_get_mic_mute; - adev->device.set_parameters = adev_set_parameters; - adev->device.get_parameters = adev_get_parameters; - adev->device.get_input_buffer_size = adev_get_input_buffer_size; - adev->device.open_output_stream = adev_open_output_stream; - adev->device.close_output_stream = adev_close_output_stream; - adev->device.open_input_stream = adev_open_input_stream; - adev->device.close_input_stream = adev_close_input_stream; - adev->device.dump = adev_dump; + adev->device.init_check = adev_init_check; + adev->device.set_voice_volume = adev_set_voice_volume; + adev->device.set_master_volume = adev_set_master_volume; + adev->device.set_mode = adev_set_mode; + adev->device.set_mic_mute = adev_set_mic_mute; + adev->device.get_mic_mute = adev_get_mic_mute; + adev->device.set_parameters = adev_set_parameters; + adev->device.get_parameters = adev_get_parameters; + adev->device.get_input_buffer_size = adev_get_input_buffer_size; + adev->device.open_output_stream = adev_open_output_stream; + adev->device.close_output_stream = adev_close_output_stream; + adev->device.open_input_stream = adev_open_input_stream; + adev->device.close_input_stream = adev_close_input_stream; + adev->device.dump = adev_dump; - adev->output = NULL; + adev->output = NULL; + *device = &adev->device.common; - *device = &adev->device.common; - - return 0; + return 0; } static struct hw_module_methods_t hal_module_methods = { .open = adev_open, }; -__attribute__ ((visibility ("default"))) -struct audio_module HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = AUDIO_HARDWARE_MODULE_ID, - .name = "A2DP Audio HW HAL", - .author = "The Android Open Source Project", - .methods = &hal_module_methods, - }, +__attribute__(( + visibility("default"))) struct audio_module HAL_MODULE_INFO_SYM = { + .common = + { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = AUDIO_HARDWARE_MODULE_ID, + .name = "A2DP Audio HW HAL", + .author = "The Android Open Source Project", + .methods = &hal_module_methods, + }, }; diff --git a/audio_a2dp_hw/audio_a2dp_hw.h b/audio_a2dp_hw/audio_a2dp_hw.h index e6e7dde7a..df66d87ec 100644 --- a/audio_a2dp_hw/audio_a2dp_hw.h +++ b/audio_a2dp_hw/audio_a2dp_hw.h @@ -53,7 +53,7 @@ // 20 * 512 is not sufficient to smooth the variability for some BT devices, // resulting in mixer sleep and throttling. We increase this to 28 * 512 to help // reduce the effect of variable data consumption. -#define AUDIO_STREAM_OUTPUT_BUFFER_SZ (28*512) +#define AUDIO_STREAM_OUTPUT_BUFFER_SZ (28 * 512) // AUDIO_STREAM_OUTPUT_BUFFER_PERIODS controls how the socket buffer is divided // for AudioFlinger data delivery. The AudioFlinger mixer delivers data in @@ -73,24 +73,24 @@ // results in unnecessary latency and CPU overhead for Bluetooth. #define AUDIO_STREAM_OUTPUT_BUFFER_PERIODS 4 -#define AUDIO_SKT_DISCONNECTED (-1) +#define AUDIO_SKT_DISCONNECTED (-1) typedef enum { - A2DP_CTRL_CMD_NONE, - A2DP_CTRL_CMD_CHECK_READY, - A2DP_CTRL_CMD_START, - A2DP_CTRL_CMD_STOP, - A2DP_CTRL_CMD_SUSPEND, - A2DP_CTRL_GET_INPUT_AUDIO_CONFIG, - A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG, - A2DP_CTRL_CMD_OFFLOAD_START, + A2DP_CTRL_CMD_NONE, + A2DP_CTRL_CMD_CHECK_READY, + A2DP_CTRL_CMD_START, + A2DP_CTRL_CMD_STOP, + A2DP_CTRL_CMD_SUSPEND, + A2DP_CTRL_GET_INPUT_AUDIO_CONFIG, + A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG, + A2DP_CTRL_CMD_OFFLOAD_START, } tA2DP_CTRL_CMD; typedef enum { - A2DP_CTRL_ACK_SUCCESS, - A2DP_CTRL_ACK_FAILURE, - A2DP_CTRL_ACK_INCALL_FAILURE, /* Failure when in Call*/ - A2DP_CTRL_ACK_UNSUPPORTED + A2DP_CTRL_ACK_SUCCESS, + A2DP_CTRL_ACK_FAILURE, + A2DP_CTRL_ACK_INCALL_FAILURE, /* Failure when in Call*/ + A2DP_CTRL_ACK_UNSUPPORTED } tA2DP_CTRL_ACK; typedef uint32_t tA2DP_SAMPLE_RATE; diff --git a/audio_a2dp_hw/audio_a2dp_hw_utils.cc b/audio_a2dp_hw/audio_a2dp_hw_utils.cc index 93524d48e..5aedd27b9 100644 --- a/audio_a2dp_hw/audio_a2dp_hw_utils.cc +++ b/audio_a2dp_hw/audio_a2dp_hw_utils.cc @@ -18,22 +18,23 @@ #include "audio_a2dp_hw.h" -#define CASE_RETURN_STR(const) case const: return #const; +#define CASE_RETURN_STR(const) \ + case const: \ + return #const; -const char* audio_a2dp_hw_dump_ctrl_event(tA2DP_CTRL_CMD event) -{ - switch (event) { - CASE_RETURN_STR(A2DP_CTRL_CMD_NONE) - CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY) - CASE_RETURN_STR(A2DP_CTRL_CMD_START) - CASE_RETURN_STR(A2DP_CTRL_CMD_STOP) - CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND) - CASE_RETURN_STR(A2DP_CTRL_GET_INPUT_AUDIO_CONFIG) - CASE_RETURN_STR(A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG) - CASE_RETURN_STR(A2DP_CTRL_CMD_OFFLOAD_START) +const char* audio_a2dp_hw_dump_ctrl_event(tA2DP_CTRL_CMD event) { + switch (event) { + CASE_RETURN_STR(A2DP_CTRL_CMD_NONE) + CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY) + CASE_RETURN_STR(A2DP_CTRL_CMD_START) + CASE_RETURN_STR(A2DP_CTRL_CMD_STOP) + CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND) + CASE_RETURN_STR(A2DP_CTRL_GET_INPUT_AUDIO_CONFIG) + CASE_RETURN_STR(A2DP_CTRL_GET_OUTPUT_AUDIO_CONFIG) + CASE_RETURN_STR(A2DP_CTRL_CMD_OFFLOAD_START) default: - break; - } + break; + } - return "UNKNOWN A2DP_CTRL_CMD"; + return "UNKNOWN A2DP_CTRL_CMD"; } diff --git a/bta/av/bta_av_aact.cc b/bta/av/bta_av_aact.cc index ac74a8b5d..467968505 100644 --- a/bta/av/bta_av_aact.cc +++ b/bta/av/bta_av_aact.cc @@ -451,18 +451,18 @@ static void bta_av_proc_stream_evt(uint8_t handle, BD_ADDR bd_addr, case AVDT_RECONFIG_CFM_EVT: if (p_msg->msg.hdr.err_code == 0) { APPL_TRACE_DEBUG( - "%s: reconfig cfm event codec info = 0x%06x-%06x-%06x-%02x", - __func__, - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[0] << 16) + - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[1] << 8) + - p_msg->msg.reconfig_cfm.p_cfg->codec_info[2], - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[3] << 16) + - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[4] << 8) + - p_msg->msg.reconfig_cfm.p_cfg->codec_info[5], - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[6] << 16) + - (p_msg->msg.reconfig_cfm.p_cfg->codec_info[7] << 8) + - p_msg->msg.reconfig_cfm.p_cfg->codec_info[8], - p_msg->msg.reconfig_cfm.p_cfg->codec_info[9]); + "%s: reconfig cfm event codec info = 0x%06x-%06x-%06x-%02x", + __func__, + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[0] << 16) + + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[1] << 8) + + p_msg->msg.reconfig_cfm.p_cfg->codec_info[2], + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[3] << 16) + + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[4] << 8) + + p_msg->msg.reconfig_cfm.p_cfg->codec_info[5], + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[6] << 16) + + (p_msg->msg.reconfig_cfm.p_cfg->codec_info[7] << 8) + + p_msg->msg.reconfig_cfm.p_cfg->codec_info[8], + p_msg->msg.reconfig_cfm.p_cfg->codec_info[9]); } break; diff --git a/bta/av/bta_av_main.cc b/bta/av/bta_av_main.cc index ed0adea74..0d8c0fe64 100644 --- a/bta/av/bta_av_main.cc +++ b/bta/av/bta_av_main.cc @@ -1138,18 +1138,18 @@ bool bta_av_hdl_event(BT_HDR* p_msg) { bta_av_evt_code(p_msg->event)); /* non state machine events */ (*bta_av_nsm_act[p_msg->event - BTA_AV_FIRST_NSM_EVT])( - (tBTA_AV_DATA*) p_msg); - } else if (p_msg->event >= BTA_AV_FIRST_SM_EVT - && p_msg->event <= BTA_AV_LAST_SM_EVT) { + (tBTA_AV_DATA*)p_msg); + } else if (p_msg->event >= BTA_AV_FIRST_SM_EVT && + p_msg->event <= BTA_AV_LAST_SM_EVT) { APPL_TRACE_VERBOSE("%s: AV sm event=0x%x(%s)", __func__, p_msg->event, bta_av_evt_code(p_msg->event)); /* state machine events */ - bta_av_sm_execute(&bta_av_cb, p_msg->event, (tBTA_AV_DATA*) p_msg); + bta_av_sm_execute(&bta_av_cb, p_msg->event, (tBTA_AV_DATA*)p_msg); } else { APPL_TRACE_VERBOSE("handle=0x%x", p_msg->layer_specific); /* stream state machine events */ bta_av_ssm_execute(bta_av_hndl_to_scb(p_msg->layer_specific), p_msg->event, - (tBTA_AV_DATA*) p_msg); + (tBTA_AV_DATA*)p_msg); } return true; } diff --git a/bta/include/bta_ag_api.h b/bta/include/bta_ag_api.h index 11dfae70d..39eba001b 100644 --- a/bta/include/bta_ag_api.h +++ b/bta/include/bta_ag_api.h @@ -50,8 +50,8 @@ extern "C" { #endif /* AG feature masks */ -#define BTA_AG_FEAT_3WAY 0x00000001 /* Three-way calling */ -#define BTA_AG_FEAT_ECNR 0x00000002 /* Echo cancellation/noise reduction */ +#define BTA_AG_FEAT_3WAY 0x00000001 /* Three-way calling */ +#define BTA_AG_FEAT_ECNR 0x00000002 /* Echo cancellation/noise reduction */ #define BTA_AG_FEAT_VREC 0x00000004 /* Voice recognition */ #define BTA_AG_FEAT_INBAND 0x00000008 /* In-band ring tone */ #define BTA_AG_FEAT_VTAG 0x00000010 /* Attach a phone number to a voice tag */ @@ -69,8 +69,8 @@ extern "C" { #define BTA_AG_FEAT_ESCO 0x00000800 /* eSCO S4 (and T2) setting supported */ /* Proprietary features: using 31 ~ 16 bits */ -#define BTA_AG_FEAT_BTRH 0x00010000 /* CCAP incoming call hold */ -#define BTA_AG_FEAT_UNAT 0x00020000 /* Pass unknown AT commands to app */ +#define BTA_AG_FEAT_BTRH 0x00010000 /* CCAP incoming call hold */ +#define BTA_AG_FEAT_UNAT 0x00020000 /* Pass unknown AT commands to app */ #define BTA_AG_FEAT_NOSCO 0x00040000 /* No SCO control performed by BTA AG */ #define BTA_AG_FEAT_NO_ESCO 0x00080000 /* Do not allow or use eSCO */ #define BTA_AG_FEAT_VOIP 0x00100000 /* VoIP call */ @@ -148,7 +148,7 @@ typedef uint8_t tBTA_AG_STATUS; typedef uint8_t tBTA_AG_RES; /* HFP peer features */ -#define BTA_AG_PEER_FEAT_ECNR 0x0001 /* Echo cancellation/noise reduction */ +#define BTA_AG_PEER_FEAT_ECNR 0x0001 /* Echo cancellation/noise reduction */ #define BTA_AG_PEER_FEAT_3WAY 0x0002 /* Call waiting and three-way calling */ #define BTA_AG_PEER_FEAT_CLI 0x0004 /* Caller ID presentation capability */ #define BTA_AG_PEER_FEAT_VREC 0x0008 /* Voice recognition activation */ @@ -405,9 +405,9 @@ typedef void(tBTA_AG_CBACK)(tBTA_AG_EVT event, tBTA_AG* p_data); #define BTA_AG_CALLSETUP_ALERTING 3 /* service indicator values */ -#define BTA_AG_SERVICE_NONE 0 /* Neither CS nor VoIP service is available */ -#define BTA_AG_SERVICE_CS 1 /* Only CS service is available */ -#define BTA_AG_SERVICE_VOIP 2 /* Only VoIP service is available */ +#define BTA_AG_SERVICE_NONE 0 /* Neither CS nor VoIP service is available */ +#define BTA_AG_SERVICE_CS 1 /* Only CS service is available */ +#define BTA_AG_SERVICE_VOIP 2 /* Only VoIP service is available */ #define BTA_AG_SERVICE_CS_VOIP 3 /* Both CS and VoIP services available */ /* callheld indicator values */ diff --git a/btcore/include/bdaddr.h b/btcore/include/bdaddr.h index 7bc88a524..6992c1cf6 100644 --- a/btcore/include/bdaddr.h +++ b/btcore/include/bdaddr.h @@ -36,30 +36,32 @@ typedef char bdstr_t[sizeof("xx:xx:xx:xx:xx:xx")]; // Returns true if |addr| is the empty address (00:00:00:00:00:00). // |addr| may not be NULL. -bool bdaddr_is_empty(const bt_bdaddr_t *addr); +bool bdaddr_is_empty(const bt_bdaddr_t* addr); // Returns true if |first| and |second| refer to the same address. Neither // may be NULL. -bool bdaddr_equals(const bt_bdaddr_t *first, const bt_bdaddr_t *second); +bool bdaddr_equals(const bt_bdaddr_t* first, const bt_bdaddr_t* second); // Returns destination bdaddr |dest| after copying |src| to |dest|. // |dest| and |src| must not be NULL. -bt_bdaddr_t *bdaddr_copy(bt_bdaddr_t *dest, const bt_bdaddr_t *src); +bt_bdaddr_t* bdaddr_copy(bt_bdaddr_t* dest, const bt_bdaddr_t* src); // Makes a string representation of |addr| and places it into |string|. |size| // refers to the size of |string|'s buffer and must be >= 18. On success, this // function returns |string|, otherwise it returns NULL. Neither |addr| nor // |string| may be NULL. -const char *bdaddr_to_string(const bt_bdaddr_t *addr, char *string, size_t size); +const char* bdaddr_to_string(const bt_bdaddr_t* addr, char* string, + size_t size); -// Returns true if |string| represents a Bluetooth address. |string| may not be NULL. -bool string_is_bdaddr(const char *string); +// Returns true if |string| represents a Bluetooth address. |string| may not be +// NULL. +bool string_is_bdaddr(const char* string); // Converts |string| to bt_bdaddr_t and places it in |addr|. If |string| does // not represent a Bluetooth address, |addr| is not modified and this function // returns false. Otherwise, it returns true. Neither |string| nor |addr| may be // NULL. -bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr); +bool string_to_bdaddr(const char* string, bt_bdaddr_t* addr); #ifdef __cplusplus } diff --git a/btcore/include/device_class.h b/btcore/include/device_class.h index fa2b1a722..7a5f0092a 100644 --- a/btcore/include/device_class.h +++ b/btcore/include/device_class.h @@ -37,64 +37,67 @@ typedef struct bt_device_class_t { // Copies the |data| class of device stream into device class |dc|. |dc| // and |data| must not be NULL. -void device_class_from_stream(bt_device_class_t *dc, const uint8_t *data); +void device_class_from_stream(bt_device_class_t* dc, const uint8_t* data); // Serializes the device class |dc| to pointer argument |data| in big endian // format. |len| must contain the buffer size of |data|. Returns the actual // number of bytes copied into |data|. |dc| and |data| must not be NULL. -int device_class_to_stream(const bt_device_class_t *dc, uint8_t *data, size_t len); +int device_class_to_stream(const bt_device_class_t* dc, uint8_t* data, + size_t len); // Copies the |data| class of device integer into device class |dc|. |dc| // must not be NULL. -void device_class_from_int(bt_device_class_t *dc, int data); +void device_class_from_int(bt_device_class_t* dc, int data); // Returns the device class |dc| in integer format. |dc| must not be NULL. -int device_class_to_int(const bt_device_class_t *dc); +int device_class_to_int(const bt_device_class_t* dc); // Compares and returns |true| if two device classes |p1| and |p2| are equal. // False otherwise. -bool device_class_equals(const bt_device_class_t *p1, const bt_device_class_t *p2); +bool device_class_equals(const bt_device_class_t* p1, + const bt_device_class_t* p2); // Copies and returns |true| if the device class was successfully copied from // |p2| into |p1|. False otherwise. -bool device_class_copy(bt_device_class_t *dest, const bt_device_class_t *src); +bool device_class_copy(bt_device_class_t* dest, const bt_device_class_t* src); -// Query, getters and setters for the major device class. |dc| must not be NULL. -int device_class_get_major_device(const bt_device_class_t *dc); -void device_class_set_major_device(bt_device_class_t *dc, int val); +// Query, getters and setters for the major device class. |dc| must not be +// NULL. +int device_class_get_major_device(const bt_device_class_t* dc); +void device_class_set_major_device(bt_device_class_t* dc, int val); // Query, getters and setters for the minor device class. |dc| must not be NULL. -int device_class_get_minor_device(const bt_device_class_t *dc); -void device_class_set_minor_device(bt_device_class_t *dc, int val); +int device_class_get_minor_device(const bt_device_class_t* dc); +void device_class_set_minor_device(bt_device_class_t* dc, int val); // Query, getters and setters for the various major service class features. // |dc| must not be NULL. -bool device_class_get_limited(const bt_device_class_t *dc); -void device_class_set_limited(bt_device_class_t *dc, bool set); +bool device_class_get_limited(const bt_device_class_t* dc); +void device_class_set_limited(bt_device_class_t* dc, bool set); -bool device_class_get_positioning(const bt_device_class_t *dc); -void device_class_set_positioning(bt_device_class_t *dc, bool set); +bool device_class_get_positioning(const bt_device_class_t* dc); +void device_class_set_positioning(bt_device_class_t* dc, bool set); -bool device_class_get_networking(const bt_device_class_t *dc); -void device_class_set_networking(bt_device_class_t *dc, bool set); +bool device_class_get_networking(const bt_device_class_t* dc); +void device_class_set_networking(bt_device_class_t* dc, bool set); -bool device_class_get_rendering(const bt_device_class_t *dc); -void device_class_set_rendering(bt_device_class_t *dc, bool set); +bool device_class_get_rendering(const bt_device_class_t* dc); +void device_class_set_rendering(bt_device_class_t* dc, bool set); -bool device_class_get_capturing(const bt_device_class_t *dc); -void device_class_set_capturing(bt_device_class_t *dc, bool set); +bool device_class_get_capturing(const bt_device_class_t* dc); +void device_class_set_capturing(bt_device_class_t* dc, bool set); -bool device_class_get_object_transfer(const bt_device_class_t *dc); -void device_class_set_object_transfer(bt_device_class_t *dc, bool set); +bool device_class_get_object_transfer(const bt_device_class_t* dc); +void device_class_set_object_transfer(bt_device_class_t* dc, bool set); -bool device_class_get_audio(const bt_device_class_t *dc); -void device_class_set_audio(bt_device_class_t *dc, bool set); +bool device_class_get_audio(const bt_device_class_t* dc); +void device_class_set_audio(bt_device_class_t* dc, bool set); -bool device_class_get_telephony(const bt_device_class_t *dc); -void device_class_set_telephony(bt_device_class_t *dc, bool set); +bool device_class_get_telephony(const bt_device_class_t* dc); +void device_class_set_telephony(bt_device_class_t* dc, bool set); -bool device_class_get_information(const bt_device_class_t *dc); -void device_class_set_information(bt_device_class_t *dc, bool set); +bool device_class_get_information(const bt_device_class_t* dc); +void device_class_set_information(bt_device_class_t* dc, bool set); #ifdef __cplusplus } diff --git a/btcore/include/device_features.h b/btcore/include/device_features.h index 64ef866d9..2b667afaa 100644 --- a/btcore/include/device_features.h +++ b/btcore/include/device_features.h @@ -26,9 +26,7 @@ extern "C" { // Represents a page of device feature enabled/disabled bits returned // by the local controller. See the bluetooth spec for bit indexes. -typedef struct { - uint8_t as_array[8]; -} bt_device_features_t; +typedef struct { uint8_t as_array[8]; } bt_device_features_t; #ifdef __cplusplus } diff --git a/btcore/include/event_mask.h b/btcore/include/event_mask.h index 8dd92a7b1..c7eb7bca3 100644 --- a/btcore/include/event_mask.h +++ b/btcore/include/event_mask.h @@ -27,9 +27,7 @@ extern "C" { // Represents a mask which can be used to tell the controller which // HCI events the stack wishes to be informed about. See the bluetooth // spec for more information on what each bit means. -typedef struct { - const uint8_t as_array[8]; -} bt_event_mask_t; +typedef struct { const uint8_t as_array[8]; } bt_event_mask_t; #ifdef __cplusplus } diff --git a/btcore/include/hal_util.h b/btcore/include/hal_util.h index c49546811..7afa5cff6 100644 --- a/btcore/include/hal_util.h +++ b/btcore/include/hal_util.h @@ -25,7 +25,7 @@ struct hw_module_t; // Loads the Bluetooth library. If OS_GENERIC is defined, this function looks // explicitly for libbluetooth.default.so and loads it. On Android, this calls // the hw_get_module routine with the Bluetooth stack module id. -int hal_util_load_bt_library(const struct hw_module_t **module); +int hal_util_load_bt_library(const struct hw_module_t** module); #ifdef __cplusplus } diff --git a/btcore/include/iac.h b/btcore/include/iac.h index 2179b745c..d5a2a3d08 100644 --- a/btcore/include/iac.h +++ b/btcore/include/iac.h @@ -29,7 +29,7 @@ extern "C" { // (https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband) typedef struct { uint8_t iac[3]; -} __attribute__((packed))bt_inquiry_access_code_t; +} __attribute__((packed)) bt_inquiry_access_code_t; #ifdef __cplusplus } diff --git a/btcore/include/module.h b/btcore/include/module.h index 8d06b5192..a6305c8b2 100644 --- a/btcore/include/module.h +++ b/btcore/include/module.h @@ -27,38 +27,39 @@ extern "C" { #endif -typedef future_t *(*module_lifecycle_fn)(void); +typedef future_t* (*module_lifecycle_fn)(void); #define BTCORE_MAX_MODULE_DEPENDENCIES 10 typedef struct { - const char *name; + const char* name; module_lifecycle_fn init; module_lifecycle_fn start_up; module_lifecycle_fn shut_down; module_lifecycle_fn clean_up; - const char *dependencies[BTCORE_MAX_MODULE_DEPENDENCIES]; + const char* dependencies[BTCORE_MAX_MODULE_DEPENDENCIES]; } module_t; -// Prepares module management. Must be called before doing anything with modules. +// Prepares module management. Must be called before doing anything with +// modules. void module_management_start(void); // Cleans up all module management resources. void module_management_stop(void); -const module_t *get_module(const char *name); +const module_t* get_module(const char* name); // Initialize the provided module. |module| may not be NULL // and must not be initialized. -bool module_init(const module_t *module); +bool module_init(const module_t* module); // Start up the provided module. |module| may not be NULL // and must be initialized or have no init function. -bool module_start_up(const module_t *module); +bool module_start_up(const module_t* module); // Shut down the provided module. |module| may not be NULL. // If not started, does nothing. -void module_shut_down(const module_t *module); +void module_shut_down(const module_t* module); // Clean up the provided module. |module| may not be NULL. // If not initialized, does nothing. -void module_clean_up(const module_t *module); +void module_clean_up(const module_t* module); // Temporary callbacked wrapper for module start up, so real modules can be // spliced into the current janky startup sequence. Runs on a separate thread, @@ -66,11 +67,9 @@ void module_clean_up(const module_t *module); // has finished, |callback| is called within the context of |callback_thread| // with |FUTURE_SUCCESS| or |FUTURE_FAIL| depending on whether startup succeeded // or not. -void module_start_up_callbacked_wrapper( - const module_t *module, - thread_t *callback_thread, - thread_fn callback -); +void module_start_up_callbacked_wrapper(const module_t* module, + thread_t* callback_thread, + thread_fn callback); #ifdef __cplusplus } diff --git a/btcore/include/property.h b/btcore/include/property.h index 038ef908f..943947565 100644 --- a/btcore/include/property.h +++ b/btcore/include/property.h @@ -30,55 +30,58 @@ extern "C" { // Copies an array of consecutive properties of |count| to a newly // allocated array. |properties| must not be NULL. -bt_property_t *property_copy_array(const bt_property_t *properties, size_t count); +bt_property_t* property_copy_array(const bt_property_t* properties, + size_t count); // Copies |src| to |dest|. Returns the value of |dest|. // |src| and |dest| must not be NULL. -bt_property_t *property_copy(bt_property_t *dest, const bt_property_t *src); +bt_property_t* property_copy(bt_property_t* dest, const bt_property_t* src); // Returns true if the value of the two properties |p1| and |p2| are equal. // |p1| and |p2| must not be NULL. -bool property_equals(const bt_property_t *p1, const bt_property_t *p2); +bool property_equals(const bt_property_t* p1, const bt_property_t* p2); // Property resource allocations. Caller is expected to free |property| // using |property_free| or |property_free_array|. // Parameter must not be NULL. A copy of the parameter is made and // stored in the property. -bt_property_t *property_new_addr(const bt_bdaddr_t *addr); -bt_property_t *property_new_device_class(const bt_device_class_t *dc); -bt_property_t *property_new_device_type(bt_device_type_t device_type); -bt_property_t *property_new_discovery_timeout(const uint32_t timeout); -bt_property_t *property_new_name(const char *name); -bt_property_t *property_new_rssi(const int8_t rssi); -bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode); -bt_property_t *property_new_uuids(const bt_uuid_t *uuid, size_t count); +bt_property_t* property_new_addr(const bt_bdaddr_t* addr); +bt_property_t* property_new_device_class(const bt_device_class_t* dc); +bt_property_t* property_new_device_type(bt_device_type_t device_type); +bt_property_t* property_new_discovery_timeout(const uint32_t timeout); +bt_property_t* property_new_name(const char* name); +bt_property_t* property_new_rssi(const int8_t rssi); +bt_property_t* property_new_scan_mode(bt_scan_mode_t scan_mode); +bt_property_t* property_new_uuids(const bt_uuid_t* uuid, size_t count); // Property resource frees both property and value. -void property_free(bt_property_t *property); -void property_free_array(bt_property_t *properties, size_t count); +void property_free(bt_property_t* property); +void property_free_array(bt_property_t* properties, size_t count); // Value check convenience methods. The contents of the property are // checked for the respective validity and returns true, false otherwise. // |property| must not be NULL. -bool property_is_addr(const bt_property_t *property); -bool property_is_device_class(const bt_property_t *property); -bool property_is_device_type(const bt_property_t *property); -bool property_is_discovery_timeout(const bt_property_t *property); -bool property_is_name(const bt_property_t *property); -bool property_is_rssi(const bt_property_t *property); -bool property_is_scan_mode(const bt_property_t *property); -bool property_is_uuids(const bt_property_t *property); +bool property_is_addr(const bt_property_t* property); +bool property_is_device_class(const bt_property_t* property); +bool property_is_device_type(const bt_property_t* property); +bool property_is_discovery_timeout(const bt_property_t* property); +bool property_is_name(const bt_property_t* property); +bool property_is_rssi(const bt_property_t* property); +bool property_is_scan_mode(const bt_property_t* property); +bool property_is_uuids(const bt_property_t* property); // Value conversion convenience methods. The contents of the property are // properly typed and returned to the caller. |property| must not be NULL. -const bt_bdaddr_t *property_as_addr(const bt_property_t *property); -const bt_device_class_t *property_as_device_class(const bt_property_t *property); -bt_device_type_t property_as_device_type(const bt_property_t *property); -uint32_t property_as_discovery_timeout(const bt_property_t *property); -const bt_bdname_t *property_as_name(const bt_property_t *property); -int8_t property_as_rssi(const bt_property_t *property); -bt_scan_mode_t property_as_scan_mode(const bt_property_t *property); -const bt_uuid_t *property_as_uuids(const bt_property_t *property, size_t *count); +const bt_bdaddr_t* property_as_addr(const bt_property_t* property); +const bt_device_class_t* property_as_device_class( + const bt_property_t* property); +bt_device_type_t property_as_device_type(const bt_property_t* property); +uint32_t property_as_discovery_timeout(const bt_property_t* property); +const bt_bdname_t* property_as_name(const bt_property_t* property); +int8_t property_as_rssi(const bt_property_t* property); +bt_scan_mode_t property_as_scan_mode(const bt_property_t* property); +const bt_uuid_t* property_as_uuids(const bt_property_t* property, + size_t* count); #ifdef __cplusplus } diff --git a/btcore/include/uuid.h b/btcore/include/uuid.h index f0ae266c6..1348a63f4 100644 --- a/btcore/include/uuid.h +++ b/btcore/include/uuid.h @@ -30,15 +30,15 @@ typedef struct uuid_string_t uuid_string_t; // Creates uuid string structure to hold a well formed UUID // string. Must release resources with |uuid_string_free|. // Returns NULL if no memory. -uuid_string_t *uuid_string_new(void); +uuid_string_t* uuid_string_new(void); // Frees a uuid string structure created from |uuid_string_new|. // |uuid_string| may be NULL. -void uuid_string_free(uuid_string_t *uuid_string); +void uuid_string_free(uuid_string_t* uuid_string); // Returns a string pointer to the well formed UUID string // entry. |uuid_string| must not be NULL. -const char *uuid_string_data(const uuid_string_t *uuid_string); +const char* uuid_string_data(const uuid_string_t* uuid_string); // Creates uuid structure from a well formed UUID string // |uuid_string|. The caller takes ownership of the uuid @@ -49,34 +49,34 @@ const char *uuid_string_data(const uuid_string_t *uuid_string); // // A well formed UUID string is structured like this: // "00112233-4455-6677-8899-aabbccddeeff" -bt_uuid_t *uuid_new(const char *uuid_string); +bt_uuid_t* uuid_new(const char* uuid_string); // Frees a uuid structure created from |uuid_new| and friends. // |uuid| may be NULL. -void uuid_free(bt_uuid_t *uuid); +void uuid_free(bt_uuid_t* uuid); // Returns true if the UUID is all zeros, false otherwise. // |uuid| may not be NULL. -bool uuid_is_empty(const bt_uuid_t *uuid); +bool uuid_is_empty(const bt_uuid_t* uuid); // Returns true if the two UUIDs are equal, false otherwise. // |first| and |second| may not be NULL. -bool uuid_is_equal(const bt_uuid_t *first, const bt_uuid_t *second); +bool uuid_is_equal(const bt_uuid_t* first, const bt_uuid_t* second); // Copies uuid |src| into |dest| and returns a pointer to |dest|. // |src| and |dest| must not be NULL. -bt_uuid_t *uuid_copy(bt_uuid_t *dest, const bt_uuid_t *src); +bt_uuid_t* uuid_copy(bt_uuid_t* dest, const bt_uuid_t* src); // Converts contents of |uuid| to a well formed UUID string // |uuid_string| using numbers and lower case letter. |uuid| // and |uuid_string| must not be NULL. -void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string); +void uuid_to_string(const bt_uuid_t* uuid, uuid_string_t* uuid_string); // Converts contents of |uuid| to a short uuid if possible. Returns // true if conversion is possible, false otherwise. // |uuid|, |uuid16| and |uuid32| must not be NULL. -bool uuid_128_to_16(const bt_uuid_t *uuid, uint16_t *uuid16); -bool uuid_128_to_32(const bt_uuid_t *uuid, uint32_t *uuid32); +bool uuid_128_to_16(const bt_uuid_t* uuid, uint16_t* uuid16); +bool uuid_128_to_32(const bt_uuid_t* uuid, uint32_t* uuid32); #ifdef __cplusplus } diff --git a/btcore/src/bdaddr.cc b/btcore/src/bdaddr.cc index 80ad11eee..9447c33c7 100644 --- a/btcore/src/bdaddr.cc +++ b/btcore/src/bdaddr.cc @@ -23,70 +23,66 @@ #include "btcore/include/bdaddr.h" -bool bdaddr_is_empty(const bt_bdaddr_t *addr) { +bool bdaddr_is_empty(const bt_bdaddr_t* addr) { assert(addr != NULL); - uint8_t zero[sizeof(bt_bdaddr_t)] = { 0 }; + uint8_t zero[sizeof(bt_bdaddr_t)] = {0}; return memcmp(addr, &zero, sizeof(bt_bdaddr_t)) == 0; } -bool bdaddr_equals(const bt_bdaddr_t *first, const bt_bdaddr_t *second) { +bool bdaddr_equals(const bt_bdaddr_t* first, const bt_bdaddr_t* second) { assert(first != NULL); assert(second != NULL); return memcmp(first, second, sizeof(bt_bdaddr_t)) == 0; } -bt_bdaddr_t *bdaddr_copy(bt_bdaddr_t *dest, const bt_bdaddr_t *src) { +bt_bdaddr_t* bdaddr_copy(bt_bdaddr_t* dest, const bt_bdaddr_t* src) { assert(dest != NULL); assert(src != NULL); - return (bt_bdaddr_t *)memcpy(dest, src, sizeof(bt_bdaddr_t)); + return (bt_bdaddr_t*)memcpy(dest, src, sizeof(bt_bdaddr_t)); } -const char *bdaddr_to_string(const bt_bdaddr_t *addr, char *string, size_t size) { +const char* bdaddr_to_string(const bt_bdaddr_t* addr, char* string, + size_t size) { assert(addr != NULL); assert(string != NULL); - if (size < 18) - return NULL; + if (size < 18) return NULL; - const uint8_t *ptr = addr->address; - snprintf(string, size, "%02x:%02x:%02x:%02x:%02x:%02x", - ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); + const uint8_t* ptr = addr->address; + snprintf(string, size, "%02x:%02x:%02x:%02x:%02x:%02x", ptr[0], ptr[1], + ptr[2], ptr[3], ptr[4], ptr[5]); return string; } -bool string_is_bdaddr(const char *string) { +bool string_is_bdaddr(const char* string) { assert(string != NULL); size_t len = strlen(string); - if (len != 17) - return false; + if (len != 17) return false; for (size_t i = 0; i < len; ++i) { // Every 3rd char must be ':'. - if (((i + 1) % 3) == 0 && string[i] != ':') - return false; + if (((i + 1) % 3) == 0 && string[i] != ':') return false; // All other chars must be a hex digit. - if (((i + 1) % 3) != 0 && !isxdigit(string[i])) - return false; + if (((i + 1) % 3) != 0 && !isxdigit(string[i])) return false; } return true; } -bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr) { +bool string_to_bdaddr(const char* string, bt_bdaddr_t* addr) { assert(string != NULL); assert(addr != NULL); bt_bdaddr_t new_addr; - uint8_t *ptr = new_addr.address; + uint8_t* ptr = new_addr.address; bool ret = sscanf(string, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - &ptr[0], &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5]) == 6; + &ptr[0], &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5]) == 6; - if (ret) - memcpy(addr, &new_addr, sizeof(bt_bdaddr_t)); + if (ret) memcpy(addr, &new_addr, sizeof(bt_bdaddr_t)); return ret; } diff --git a/btcore/src/device_class.cc b/btcore/src/device_class.cc index b4493efd3..a0a9a23cc 100644 --- a/btcore/src/device_class.cc +++ b/btcore/src/device_class.cc @@ -24,14 +24,14 @@ #include "osi/include/osi.h" typedef struct _bt_device_class_t { - uint32_t unused : 2; // LSBs + uint32_t unused : 2; // LSBs uint32_t minor_device : 6; uint32_t major_device : 5; uint32_t major_service : 11; // MSBs -} __attribute__ ((__packed__)) _bt_device_class_t; +} __attribute__((__packed__)) _bt_device_class_t; // Convenience to interpret raw device class bytes. -#define DC(x) ((_bt_device_class_t *)(x)) +#define DC(x) ((_bt_device_class_t*)(x)) // Ensure the internal device class implementation and public one // have equal size. @@ -53,17 +53,19 @@ enum { DC_INFORMATION = 0x0400, }; -static bool device_class_get_major_service_(const bt_device_class_t *dc, int bitmask); -static void device_class_clr_major_service_(bt_device_class_t *dc, int bitmask); -static void device_class_set_major_service_(bt_device_class_t *dc, int bitmask); +static bool device_class_get_major_service_(const bt_device_class_t* dc, + int bitmask); +static void device_class_clr_major_service_(bt_device_class_t* dc, int bitmask); +static void device_class_set_major_service_(bt_device_class_t* dc, int bitmask); -void device_class_from_stream(bt_device_class_t *dc, const uint8_t *data) { +void device_class_from_stream(bt_device_class_t* dc, const uint8_t* data) { assert(dc != NULL); assert(data != NULL); - *dc = *(bt_device_class_t *)data; + *dc = *(bt_device_class_t*)data; } -int device_class_to_stream(const bt_device_class_t *dc, uint8_t *data, size_t len) { +int device_class_to_stream(const bt_device_class_t* dc, uint8_t* data, + size_t len) { assert(dc != NULL); assert(data != NULL); assert(len >= sizeof(bt_device_class_t)); @@ -73,7 +75,7 @@ int device_class_to_stream(const bt_device_class_t *dc, uint8_t *data, size_t le return sizeof(bt_device_class_t); } -void device_class_from_int(bt_device_class_t *dc, int data) { +void device_class_from_int(bt_device_class_t* dc, int data) { assert(dc != NULL); assert(data != 0); // Careful with endianess. @@ -82,50 +84,51 @@ void device_class_from_int(bt_device_class_t *dc, int data) { dc->_[2] = (data >> 16) & 0xff; } -int device_class_to_int(const bt_device_class_t *dc) { +int device_class_to_int(const bt_device_class_t* dc) { assert(dc != NULL); // Careful with endianess. return (int)(le32toh(*(int*)dc) & 0xffffff); } -bool device_class_equals(const bt_device_class_t *p1, const bt_device_class_t *p2) { +bool device_class_equals(const bt_device_class_t* p1, + const bt_device_class_t* p2) { assert(p1 != NULL); assert(p2 != NULL); return (memcmp(p1, p2, sizeof(bt_device_class_t)) == 0); } -bool device_class_copy(bt_device_class_t *dest, const bt_device_class_t *src) { +bool device_class_copy(bt_device_class_t* dest, const bt_device_class_t* src) { assert(dest != NULL); assert(src != NULL); return (memcpy(dest, src, sizeof(bt_device_class_t)) == dest); } -int device_class_get_major_device(const bt_device_class_t *dc) { +int device_class_get_major_device(const bt_device_class_t* dc) { assert(dc != NULL); return DC(dc)->major_device; } -void device_class_set_major_device(bt_device_class_t *dc, int val) { +void device_class_set_major_device(bt_device_class_t* dc, int val) { assert(dc != NULL); DC(dc)->major_device = val; } -int device_class_get_minor_device(const bt_device_class_t *dc) { +int device_class_get_minor_device(const bt_device_class_t* dc) { assert(dc != NULL); return DC(dc)->minor_device; } -void device_class_set_minor_device(bt_device_class_t *dc, int val) { +void device_class_set_minor_device(bt_device_class_t* dc, int val) { assert(dc != NULL); DC(dc)->minor_device = val; } -bool device_class_get_information(const bt_device_class_t *dc) { +bool device_class_get_information(const bt_device_class_t* dc) { assert(dc != NULL); return device_class_get_major_service_(dc, DC_INFORMATION); } -void device_class_set_information(bt_device_class_t *dc, bool set) { +void device_class_set_information(bt_device_class_t* dc, bool set) { assert(dc != NULL); if (set) device_class_set_major_service_(dc, DC_INFORMATION); @@ -133,12 +136,12 @@ void device_class_set_information(bt_device_class_t *dc, bool set) { device_class_clr_major_service_(dc, DC_INFORMATION); } -bool device_class_get_limited(const bt_device_class_t *dc) { +bool device_class_get_limited(const bt_device_class_t* dc) { assert(dc != NULL); return device_class_get_major_service_(dc, DC_LIMITED_DISCOVERABLE_MODE); } -void device_class_set_limited(bt_device_class_t *dc, bool set) { +void device_class_set_limited(bt_device_class_t* dc, bool set) { assert(dc != NULL); if (set) device_class_set_major_service_(dc, DC_LIMITED_DISCOVERABLE_MODE); @@ -146,14 +149,17 @@ void device_class_set_limited(bt_device_class_t *dc, bool set) { device_class_clr_major_service_(dc, DC_LIMITED_DISCOVERABLE_MODE); } -static bool device_class_get_major_service_(const bt_device_class_t *dc, int bitmask) { +static bool device_class_get_major_service_(const bt_device_class_t* dc, + int bitmask) { return (DC(dc)->major_service & bitmask); } -static void device_class_clr_major_service_(bt_device_class_t *dc, int bitmask) { +static void device_class_clr_major_service_(bt_device_class_t* dc, + int bitmask) { DC(dc)->major_service &= ~bitmask; } -static void device_class_set_major_service_(bt_device_class_t *dc, int bitmask) { +static void device_class_set_major_service_(bt_device_class_t* dc, + int bitmask) { DC(dc)->major_service |= bitmask; } diff --git a/btcore/src/hal_util.cc b/btcore/src/hal_util.cc index 0480be572..21be6131b 100644 --- a/btcore/src/hal_util.cc +++ b/btcore/src/hal_util.cc @@ -30,29 +30,29 @@ // TODO(armansito): All logging macros should include __func__ by default (see // Bug: 22671731) -#define HULOGERR(fmt, args...) \ - LOG_ERROR(LOG_TAG, "[%s] failed to load the Bluetooth library: " fmt, \ - __func__, ## args) +#define HULOGERR(fmt, args...) \ + LOG_ERROR(LOG_TAG, "[%s] failed to load the Bluetooth library: " fmt, \ + __func__, ##args) // TODO(armansito): It might be better to pass the library name in a more // generic manner as opposed to hard-coding it here. static const char kBluetoothLibraryName[] = "libbluetooth.default.so"; -static int load_bt_library(const struct hw_module_t **module) { - const char *id = BT_STACK_MODULE_ID; - const char *sym = HAL_MODULE_INFO_SYM_AS_STR; - struct hw_module_t *hmi = nullptr; +static int load_bt_library(const struct hw_module_t** module) { + const char* id = BT_STACK_MODULE_ID; + const char* sym = HAL_MODULE_INFO_SYM_AS_STR; + struct hw_module_t* hmi = nullptr; // Always try to load the default Bluetooth stack on GN builds. - void *handle = dlopen(kBluetoothLibraryName, RTLD_NOW); + void* handle = dlopen(kBluetoothLibraryName, RTLD_NOW); if (!handle) { - char const *err_str = dlerror(); + char const* err_str = dlerror(); HULOGERR("%s", err_str ? err_str : "error unknown"); goto error; } // Get the address of the struct hal_module_info. - hmi = (struct hw_module_t *)dlsym(handle, sym); + hmi = (struct hw_module_t*)dlsym(handle, sym); if (!hmi) { HULOGERR("%s", sym); goto error; @@ -67,24 +67,22 @@ static int load_bt_library(const struct hw_module_t **module) { hmi->dso = handle; // Success. - LOG_INFO( - LOG_TAG, "[%s] loaded HAL id=%s path=%s hmi=%p handle=%p", - __func__, id, kBluetoothLibraryName, hmi, handle); + LOG_INFO(LOG_TAG, "[%s] loaded HAL id=%s path=%s hmi=%p handle=%p", __func__, + id, kBluetoothLibraryName, hmi, handle); *module = hmi; return 0; error: *module = NULL; - if (handle) - dlclose(handle); + if (handle) dlclose(handle); return -EINVAL; } #endif // defined(OS_GENERIC) -int hal_util_load_bt_library(const struct hw_module_t **module) { +int hal_util_load_bt_library(const struct hw_module_t** module) { #if defined(OS_GENERIC) return load_bt_library(module); #else // !defined(OS_GENERIC) diff --git a/btcore/src/module.cc b/btcore/src/module.cc index 6a78a990f..d3e5c93bc 100644 --- a/btcore/src/module.cc +++ b/btcore/src/module.cc @@ -37,17 +37,15 @@ typedef enum { static std::unordered_map metadata; -// Include this lock for now for correctness, while the startup sequence is being refactored +// Include this lock for now for correctness, while the startup sequence is +// being refactored static pthread_mutex_t metadata_lock; static bool call_lifecycle_function(module_lifecycle_fn function); -static module_state_t get_module_state(const module_t *module); -static void set_module_state(const module_t *module, module_state_t state); +static module_state_t get_module_state(const module_t* module); +static void set_module_state(const module_t* module, module_state_t state); - -void module_management_start(void) { - pthread_mutex_init(&metadata_lock, NULL); -} +void module_management_start(void) { pthread_mutex_init(&metadata_lock, NULL); } void module_management_stop(void) { metadata.clear(); @@ -55,20 +53,20 @@ void module_management_stop(void) { pthread_mutex_destroy(&metadata_lock); } -const module_t *get_module(const char *name) { - module_t* module = (module_t *)dlsym(RTLD_DEFAULT, name); +const module_t* get_module(const char* name) { + module_t* module = (module_t*)dlsym(RTLD_DEFAULT, name); assert(module); return module; } -bool module_init(const module_t *module) { +bool module_init(const module_t* module) { assert(module != NULL); assert(get_module_state(module) == MODULE_STATE_NONE); LOG_INFO(LOG_TAG, "%s Initializing module \"%s\"", __func__, module->name); if (!call_lifecycle_function(module->init)) { - LOG_ERROR(LOG_TAG, "%s Failed to initialize module \"%s\"", - __func__, module->name); + LOG_ERROR(LOG_TAG, "%s Failed to initialize module \"%s\"", __func__, + module->name); return false; } LOG_INFO(LOG_TAG, "%s Initialized module \"%s\"", __func__, module->name); @@ -77,17 +75,20 @@ bool module_init(const module_t *module) { return true; } -bool module_start_up(const module_t *module) { +bool module_start_up(const module_t* module) { assert(module != NULL); - // TODO(zachoverflow): remove module->init check once automagic order/call is in place. - // This hack is here so modules which don't require init don't have to have useless calls + // TODO(zachoverflow): remove module->init check once automagic order/call is + // in place. + // This hack is here so modules which don't require init don't have to have + // useless calls // as we're converting the startup sequence. - assert(get_module_state(module) == MODULE_STATE_INITIALIZED || module->init == NULL); + assert(get_module_state(module) == MODULE_STATE_INITIALIZED || + module->init == NULL); LOG_INFO(LOG_TAG, "%s Starting module \"%s\"", __func__, module->name); if (!call_lifecycle_function(module->start_up)) { - LOG_ERROR(LOG_TAG, "%s Failed to start up module \"%s\"", - __func__, module->name); + LOG_ERROR(LOG_TAG, "%s Failed to start up module \"%s\"", __func__, + module->name); return false; } LOG_INFO(LOG_TAG, "%s Started module \"%s\"", __func__, module->name); @@ -96,62 +97,59 @@ bool module_start_up(const module_t *module) { return true; } -void module_shut_down(const module_t *module) { +void module_shut_down(const module_t* module) { assert(module != NULL); module_state_t state = get_module_state(module); assert(state <= MODULE_STATE_STARTED); // Only something to do if the module was actually started - if (state < MODULE_STATE_STARTED) - return; + if (state < MODULE_STATE_STARTED) return; LOG_INFO(LOG_TAG, "%s Shutting down module \"%s\"", __func__, module->name); if (!call_lifecycle_function(module->shut_down)) { - LOG_ERROR(LOG_TAG, "%s Failed to shutdown module \"%s\". Continuing anyway.", + LOG_ERROR(LOG_TAG, + "%s Failed to shutdown module \"%s\". Continuing anyway.", __func__, module->name); } - LOG_INFO(LOG_TAG, "%s Shutdown of module \"%s\" completed", - __func__, module->name); + LOG_INFO(LOG_TAG, "%s Shutdown of module \"%s\" completed", __func__, + module->name); set_module_state(module, MODULE_STATE_INITIALIZED); } -void module_clean_up(const module_t *module) { +void module_clean_up(const module_t* module) { assert(module != NULL); module_state_t state = get_module_state(module); assert(state <= MODULE_STATE_INITIALIZED); // Only something to do if the module was actually initialized - if (state < MODULE_STATE_INITIALIZED) - return; + if (state < MODULE_STATE_INITIALIZED) return; LOG_INFO(LOG_TAG, "%s Cleaning up module \"%s\"", __func__, module->name); if (!call_lifecycle_function(module->clean_up)) { LOG_ERROR(LOG_TAG, "%s Failed to cleanup module \"%s\". Continuing anyway.", __func__, module->name); } - LOG_INFO(LOG_TAG, "%s Cleanup of module \"%s\" completed", - __func__, module->name); + LOG_INFO(LOG_TAG, "%s Cleanup of module \"%s\" completed", __func__, + module->name); set_module_state(module, MODULE_STATE_NONE); } static bool call_lifecycle_function(module_lifecycle_fn function) { // A NULL lifecycle function means it isn't needed, so assume success - if (!function) - return true; + if (!function) return true; - future_t *future = function(); + future_t* future = function(); // A NULL future means synchronous success - if (!future) - return true; + if (!future) return true; // Otherwise fall back to the future return future_await(future); } -static module_state_t get_module_state(const module_t *module) { +static module_state_t get_module_state(const module_t* module) { pthread_mutex_lock(&metadata_lock); auto map_ptr = metadata.find(module); pthread_mutex_unlock(&metadata_lock); @@ -159,7 +157,7 @@ static module_state_t get_module_state(const module_t *module) { return (map_ptr != metadata.end()) ? map_ptr->second : MODULE_STATE_NONE; } -static void set_module_state(const module_t *module, module_state_t state) { +static void set_module_state(const module_t* module, module_state_t state) { pthread_mutex_lock(&metadata_lock); metadata[module] = state; pthread_mutex_unlock(&metadata_lock); @@ -169,21 +167,21 @@ static void set_module_state(const module_t *module, module_state_t state) { // Temporary callback-wrapper-related code typedef struct { - const module_t *module; - thread_t *lifecycle_thread; - thread_t *callback_thread; // we don't own this thread + const module_t* module; + thread_t* lifecycle_thread; + thread_t* callback_thread; // we don't own this thread thread_fn callback; bool success; } callbacked_wrapper_t; -static void run_wrapped_start_up(void *context); -static void post_result_to_callback(void *context); +static void run_wrapped_start_up(void* context); +static void post_result_to_callback(void* context); -void module_start_up_callbacked_wrapper( - const module_t *module, - thread_t *callback_thread, - thread_fn callback) { - callbacked_wrapper_t *wrapper = (callbacked_wrapper_t*)osi_calloc(sizeof(callbacked_wrapper_t)); +void module_start_up_callbacked_wrapper(const module_t* module, + thread_t* callback_thread, + thread_fn callback) { + callbacked_wrapper_t* wrapper = + (callbacked_wrapper_t*)osi_calloc(sizeof(callbacked_wrapper_t)); wrapper->module = module; wrapper->lifecycle_thread = thread_new("module_wrapper"); @@ -194,23 +192,23 @@ void module_start_up_callbacked_wrapper( thread_post(wrapper->lifecycle_thread, run_wrapped_start_up, wrapper); } -static void run_wrapped_start_up(void *context) { +static void run_wrapped_start_up(void* context) { assert(context); - callbacked_wrapper_t *wrapper = (callbacked_wrapper_t*)context; + callbacked_wrapper_t* wrapper = (callbacked_wrapper_t*)context; wrapper->success = module_start_up(wrapper->module); // Post the result back to the callback thread_post(wrapper->callback_thread, post_result_to_callback, wrapper); } -static void post_result_to_callback(void *context) { +static void post_result_to_callback(void* context) { assert(context); - callbacked_wrapper_t *wrapper = (callbacked_wrapper_t*)context; + callbacked_wrapper_t* wrapper = (callbacked_wrapper_t*)context; // Save the values we need for callback - void *result = wrapper->success ? FUTURE_SUCCESS : FUTURE_FAIL; + void* result = wrapper->success ? FUTURE_SUCCESS : FUTURE_FAIL; thread_fn callback = wrapper->callback; // Clean up the resources we used diff --git a/btcore/src/osi_module.cc b/btcore/src/osi_module.cc index ff7144634..3bcf03939 100644 --- a/btcore/src/osi_module.cc +++ b/btcore/src/osi_module.cc @@ -18,8 +18,8 @@ #define LOG_TAG "bt_osi_module" -#include "btcore/include/module.h" #include "btcore/include/osi_module.h" +#include "btcore/include/module.h" #include "osi/include/alarm.h" #include "osi/include/future.h" #include "osi/include/log.h" @@ -27,23 +27,21 @@ #include "osi/include/osi.h" #include "osi/include/wakelock.h" -future_t *osi_init(void) { +future_t* osi_init(void) { mutex_init(); return future_new_immediate(FUTURE_SUCCESS); } -future_t *osi_clean_up(void) { +future_t* osi_clean_up(void) { alarm_cleanup(); wakelock_cleanup(); mutex_cleanup(); return future_new_immediate(FUTURE_SUCCESS); } -EXPORT_SYMBOL extern const module_t osi_module = { - .name = OSI_MODULE, - .init = osi_init, - .start_up = NULL, - .shut_down = NULL, - .clean_up = osi_clean_up, - .dependencies = {NULL} -}; +EXPORT_SYMBOL extern const module_t osi_module = {.name = OSI_MODULE, + .init = osi_init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = osi_clean_up, + .dependencies = {NULL}}; diff --git a/btcore/src/property.cc b/btcore/src/property.cc index 9d49daa7f..e31617337 100644 --- a/btcore/src/property.cc +++ b/btcore/src/property.cc @@ -16,19 +16,22 @@ * ******************************************************************************/ +#include "btcore/include/property.h" #include #include #include "btcore/include/bdaddr.h" #include "btcore/include/device_class.h" -#include "btcore/include/property.h" #include "btcore/include/uuid.h" #include "osi/include/allocator.h" -static bt_property_t *property_new_(void *val, size_t len, bt_property_type_t type); +static bt_property_t* property_new_(void* val, size_t len, + bt_property_type_t type); -bt_property_t *property_copy_array(const bt_property_t *properties, size_t count) { +bt_property_t* property_copy_array(const bt_property_t* properties, + size_t count) { assert(properties != NULL); - bt_property_t *clone = static_cast(osi_calloc(sizeof(bt_property_t) * count)); + bt_property_t* clone = + static_cast(osi_calloc(sizeof(bt_property_t) * count)); memcpy(&clone[0], &properties[0], sizeof(bt_property_t) * count); for (size_t i = 0; i < count; ++i) { @@ -39,13 +42,13 @@ bt_property_t *property_copy_array(const bt_property_t *properties, size_t count return clone; } -bt_property_t *property_copy(bt_property_t *dest, const bt_property_t *src) { +bt_property_t* property_copy(bt_property_t* dest, const bt_property_t* src) { assert(dest != NULL); assert(src != NULL); - return (bt_property_t *)memcpy(dest, src, sizeof(bt_property_t)); + return (bt_property_t*)memcpy(dest, src, sizeof(bt_property_t)); } -bool property_equals(const bt_property_t *p1, const bt_property_t *p2) { +bool property_equals(const bt_property_t* p1, const bt_property_t* p2) { // Two null properties are not the same. May need to revisit that // decision when we have a test case that exercises that condition. if (!p1 || !p2 || p1->type != p2->type) { @@ -66,55 +69,60 @@ bool property_equals(const bt_property_t *p1, const bt_property_t *p2) { shorter = p2; longer = p1; } - return strlen((const char *)longer->val) == (size_t)shorter->len && !memcmp(longer->val, shorter->val, shorter->len); + return strlen((const char*)longer->val) == (size_t)shorter->len && + !memcmp(longer->val, shorter->val, shorter->len); } return p1->len == p2->len && !memcmp(p1->val, p2->val, p1->len); } -bt_property_t *property_new_addr(const bt_bdaddr_t *addr) { +bt_property_t* property_new_addr(const bt_bdaddr_t* addr) { assert(addr != NULL); - return property_new_((void *)addr, sizeof(bt_bdaddr_t), BT_PROPERTY_BDADDR); + return property_new_((void*)addr, sizeof(bt_bdaddr_t), BT_PROPERTY_BDADDR); } -bt_property_t *property_new_device_class(const bt_device_class_t *dc) { +bt_property_t* property_new_device_class(const bt_device_class_t* dc) { assert(dc != NULL); - return property_new_((void *)dc, sizeof(bt_device_class_t), BT_PROPERTY_CLASS_OF_DEVICE); + return property_new_((void*)dc, sizeof(bt_device_class_t), + BT_PROPERTY_CLASS_OF_DEVICE); } -bt_property_t *property_new_device_type(bt_device_type_t type) { - return property_new_((void *)&type, sizeof(bt_device_type_t), BT_PROPERTY_TYPE_OF_DEVICE); +bt_property_t* property_new_device_type(bt_device_type_t type) { + return property_new_((void*)&type, sizeof(bt_device_type_t), + BT_PROPERTY_TYPE_OF_DEVICE); } -bt_property_t *property_new_discovery_timeout(const uint32_t timeout) { - return property_new_((void *)&timeout, sizeof(uint32_t), BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT); +bt_property_t* property_new_discovery_timeout(const uint32_t timeout) { + return property_new_((void*)&timeout, sizeof(uint32_t), + BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT); } -bt_property_t *property_new_name(const char *name) { +bt_property_t* property_new_name(const char* name) { assert(name != NULL); - return property_new_((void *)name, sizeof(bt_bdname_t), BT_PROPERTY_BDNAME); + return property_new_((void*)name, sizeof(bt_bdname_t), BT_PROPERTY_BDNAME); } -bt_property_t *property_new_rssi(int8_t rssi) { - return property_new_((void *)&rssi, sizeof(int8_t), BT_PROPERTY_REMOTE_RSSI); +bt_property_t* property_new_rssi(int8_t rssi) { + return property_new_((void*)&rssi, sizeof(int8_t), BT_PROPERTY_REMOTE_RSSI); } -bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode) { - return property_new_((void *)&scan_mode, sizeof(bt_scan_mode_t), BT_PROPERTY_ADAPTER_SCAN_MODE); +bt_property_t* property_new_scan_mode(bt_scan_mode_t scan_mode) { + return property_new_((void*)&scan_mode, sizeof(bt_scan_mode_t), + BT_PROPERTY_ADAPTER_SCAN_MODE); } -bt_property_t *property_new_uuids(const bt_uuid_t *uuid, size_t count) { +bt_property_t* property_new_uuids(const bt_uuid_t* uuid, size_t count) { assert(uuid != NULL); - return property_new_((void *)uuid, sizeof(bt_uuid_t) * count, BT_PROPERTY_UUIDS); + return property_new_((void*)uuid, sizeof(bt_uuid_t) * count, + BT_PROPERTY_UUIDS); } -void property_free(bt_property_t *property) { +void property_free(bt_property_t* property) { property_free_array(property, 1); } -void property_free_array(bt_property_t *properties, size_t count) { - if (properties == NULL) - return; +void property_free_array(bt_property_t* properties, size_t count) { + if (properties == NULL) return; for (size_t i = 0; i < count; ++i) { osi_free(properties[i].val); @@ -123,90 +131,94 @@ void property_free_array(bt_property_t *properties, size_t count) { osi_free(properties); } -bool property_is_addr(const bt_property_t *property) { +bool property_is_addr(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_BDADDR; } -bool property_is_device_class(const bt_property_t *property) { +bool property_is_device_class(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_CLASS_OF_DEVICE; } -bool property_is_device_type(const bt_property_t *property) { +bool property_is_device_type(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_TYPE_OF_DEVICE; } -bool property_is_discovery_timeout(const bt_property_t *property) { +bool property_is_discovery_timeout(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT; } -bool property_is_name(const bt_property_t *property) { +bool property_is_name(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_BDNAME; } -bool property_is_rssi(const bt_property_t *property) { +bool property_is_rssi(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_REMOTE_RSSI; } -bool property_is_scan_mode(const bt_property_t *property) { +bool property_is_scan_mode(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_ADAPTER_SCAN_MODE; } -bool property_is_uuids(const bt_property_t *property) { +bool property_is_uuids(const bt_property_t* property) { assert(property != NULL); return property->type == BT_PROPERTY_UUIDS; } // Convenience conversion methods to property values -const bt_bdaddr_t *property_as_addr(const bt_property_t *property) { +const bt_bdaddr_t* property_as_addr(const bt_property_t* property) { assert(property_is_addr(property)); - return (const bt_bdaddr_t *)property->val; + return (const bt_bdaddr_t*)property->val; } -const bt_device_class_t *property_as_device_class(const bt_property_t *property) { +const bt_device_class_t* property_as_device_class( + const bt_property_t* property) { assert(property_is_device_class(property)); - return (const bt_device_class_t *)property->val; + return (const bt_device_class_t*)property->val; } -bt_device_type_t property_as_device_type(const bt_property_t *property) { +bt_device_type_t property_as_device_type(const bt_property_t* property) { assert(property_is_device_type(property)); - return *(const bt_device_type_t *)property->val; + return *(const bt_device_type_t*)property->val; } -uint32_t property_as_discovery_timeout(const bt_property_t *property) { +uint32_t property_as_discovery_timeout(const bt_property_t* property) { assert(property_is_discovery_timeout(property)); - return *(const uint32_t *)property->val; + return *(const uint32_t*)property->val; } -const bt_bdname_t *property_as_name(const bt_property_t *property) { +const bt_bdname_t* property_as_name(const bt_property_t* property) { assert(property_is_name(property)); - return (const bt_bdname_t *)property->val; + return (const bt_bdname_t*)property->val; } -int8_t property_as_rssi(const bt_property_t *property) { +int8_t property_as_rssi(const bt_property_t* property) { assert(property_is_rssi(property)); - return *(const int8_t *)property->val; + return *(const int8_t*)property->val; } -bt_scan_mode_t property_as_scan_mode(const bt_property_t *property) { +bt_scan_mode_t property_as_scan_mode(const bt_property_t* property) { assert(property_is_scan_mode(property)); - return *(const bt_scan_mode_t *)property->val; + return *(const bt_scan_mode_t*)property->val; } -const bt_uuid_t *property_as_uuids(const bt_property_t *property, size_t *count) { +const bt_uuid_t* property_as_uuids(const bt_property_t* property, + size_t* count) { assert(property_is_uuids(property)); *count = sizeof(bt_uuid_t) / property->len; - return (const bt_uuid_t *)property->val; + return (const bt_uuid_t*)property->val; } -static bt_property_t *property_new_(void *val, size_t len, bt_property_type_t type) { - bt_property_t *property = static_cast(osi_calloc(sizeof(bt_property_t))); +static bt_property_t* property_new_(void* val, size_t len, + bt_property_type_t type) { + bt_property_t* property = + static_cast(osi_calloc(sizeof(bt_property_t))); property->val = osi_malloc(len); memcpy(property->val, val, len); diff --git a/btcore/src/uuid.cc b/btcore/src/uuid.cc index 78a29048f..3795ee769 100644 --- a/btcore/src/uuid.cc +++ b/btcore/src/uuid.cc @@ -27,51 +27,49 @@ static const size_t UUID_WELL_FORMED_STRING_LEN = 36; static const size_t UUID_WELL_FORMED_STRING_LEN_WITH_NULL = 36 + 1; -typedef struct uuid_string_t { - char string[0]; -} uuid_string_t; +typedef struct uuid_string_t { char string[0]; } uuid_string_t; -static const bt_uuid_t empty_uuid = {{ 0 }}; +static const bt_uuid_t empty_uuid = {{0}}; // The base UUID is used for calculating 128-bit UUIDs from 16 and // 32 bit UUIDs as described in the SDP specification. -static const bt_uuid_t base_uuid = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }}; +static const bt_uuid_t base_uuid = {{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, + 0x5f, 0x9b, 0x34, 0xfb, +}}; -static bool uuid_is_base(const bt_uuid_t *uuid); +static bool uuid_is_base(const bt_uuid_t* uuid); -uuid_string_t *uuid_string_new(void) { - return static_cast(osi_calloc(UUID_WELL_FORMED_STRING_LEN_WITH_NULL)); +uuid_string_t* uuid_string_new(void) { + return static_cast( + osi_calloc(UUID_WELL_FORMED_STRING_LEN_WITH_NULL)); } -void uuid_string_free(uuid_string_t *uuid_string) { - osi_free(uuid_string); -} +void uuid_string_free(uuid_string_t* uuid_string) { osi_free(uuid_string); } -const char *uuid_string_data(const uuid_string_t *uuid_string) { +const char* uuid_string_data(const uuid_string_t* uuid_string) { assert(uuid_string != NULL); - return (const char *)uuid_string->string; + return (const char*)uuid_string->string; } -bt_uuid_t *uuid_new(const char *uuid_string) { +bt_uuid_t* uuid_new(const char* uuid_string) { assert(uuid_string != NULL); - if (strlen(uuid_string) < UUID_WELL_FORMED_STRING_LEN) - return NULL; - if (uuid_string[8] != '-' || uuid_string[13] != '-' || uuid_string[18] != '-' || uuid_string[23] != '-') + if (strlen(uuid_string) < UUID_WELL_FORMED_STRING_LEN) return NULL; + if (uuid_string[8] != '-' || uuid_string[13] != '-' || + uuid_string[18] != '-' || uuid_string[23] != '-') return NULL; - bt_uuid_t *uuid = static_cast(osi_calloc(sizeof(bt_uuid_t))); + bt_uuid_t* uuid = static_cast(osi_calloc(sizeof(bt_uuid_t))); - const char *s = uuid_string; - for (size_t i = 0; i < sizeof(bt_uuid_t); ++i, s+=2) { + const char* s = uuid_string; + for (size_t i = 0; i < sizeof(bt_uuid_t); ++i, s += 2) { char buf[3] = {0}; buf[0] = s[0]; buf[1] = s[1]; uuid->uu[i] = strtoul(buf, NULL, 16); // Adjust by skipping the dashes - switch(i) { + switch (i) { case 3: case 5: case 7: @@ -83,54 +81,51 @@ bt_uuid_t *uuid_new(const char *uuid_string) { return uuid; } -void uuid_free(bt_uuid_t *uuid) { - osi_free(uuid); -} +void uuid_free(bt_uuid_t* uuid) { osi_free(uuid); } -bool uuid_is_empty(const bt_uuid_t *uuid) { +bool uuid_is_empty(const bt_uuid_t* uuid) { return !uuid || !memcmp(uuid, &empty_uuid, sizeof(bt_uuid_t)); } -bool uuid_is_equal(const bt_uuid_t *first, const bt_uuid_t *second) { +bool uuid_is_equal(const bt_uuid_t* first, const bt_uuid_t* second) { assert(first != NULL); assert(second != NULL); return !memcmp(first, second, sizeof(bt_uuid_t)); } -bt_uuid_t *uuid_copy(bt_uuid_t *dest, const bt_uuid_t *src) { +bt_uuid_t* uuid_copy(bt_uuid_t* dest, const bt_uuid_t* src) { assert(dest != NULL); assert(src != NULL); - return (bt_uuid_t *)memcpy(dest, src, sizeof(bt_uuid_t)); + return (bt_uuid_t*)memcpy(dest, src, sizeof(bt_uuid_t)); } -bool uuid_128_to_16(const bt_uuid_t *uuid, uint16_t *uuid16) { +bool uuid_128_to_16(const bt_uuid_t* uuid, uint16_t* uuid16) { assert(uuid != NULL); assert(uuid16 != NULL); - if (!uuid_is_base(uuid)) - return false; + if (!uuid_is_base(uuid)) return false; *uuid16 = (uuid->uu[2] << 8) + uuid->uu[3]; return true; } -bool uuid_128_to_32(const bt_uuid_t *uuid, uint32_t *uuid32) { +bool uuid_128_to_32(const bt_uuid_t* uuid, uint32_t* uuid32) { assert(uuid != NULL); assert(uuid32 != NULL); - if (!uuid_is_base(uuid)) - return false; + if (!uuid_is_base(uuid)) return false; - *uuid32 = (uuid->uu[0] << 24) + (uuid->uu[1] << 16) + (uuid->uu[2] << 8) + uuid->uu[3]; + *uuid32 = (uuid->uu[0] << 24) + (uuid->uu[1] << 16) + (uuid->uu[2] << 8) + + uuid->uu[3]; return true; } -void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string) { +void uuid_to_string(const bt_uuid_t* uuid, uuid_string_t* uuid_string) { assert(uuid != NULL); assert(uuid_string != NULL); - char *string = uuid_string->string; - char *end = string + UUID_WELL_FORMED_STRING_LEN_WITH_NULL; + char* string = uuid_string->string; + char* end = string + UUID_WELL_FORMED_STRING_LEN_WITH_NULL; // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX for (int i = 0; i < 4; i++) { @@ -158,13 +153,11 @@ void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string) { } } -static bool uuid_is_base(const bt_uuid_t *uuid) { - if (!uuid) - return false; +static bool uuid_is_base(const bt_uuid_t* uuid) { + if (!uuid) return false; for (int i = 4; i < 16; i++) { - if (uuid->uu[i] != base_uuid.uu[i]) - return false; + if (uuid->uu[i] != base_uuid.uu[i]) return false; } return true; } diff --git a/btcore/test/bdaddr_test.cc b/btcore/test/bdaddr_test.cc index 0439c79bf..573a09b8e 100644 --- a/btcore/test/bdaddr_test.cc +++ b/btcore/test/bdaddr_test.cc @@ -23,7 +23,6 @@ static const char* test_addr = "12:34:56:78:9a:bc"; static const char* test_addr2 = "cb:a9:87:65:43:21"; - TEST(BdaddrTest, test_empty) { bt_bdaddr_t empty; string_to_bdaddr("00:00:00:00:00:00", &empty); diff --git a/btcore/test/device_class_test.cc b/btcore/test/device_class_test.cc index af9ed79b0..434f9ca4c 100644 --- a/btcore/test/device_class_test.cc +++ b/btcore/test/device_class_test.cc @@ -25,10 +25,9 @@ // Device Class is 3 bytes. static const int DC_MASK = 0xffffff; -::testing::AssertionResult check_bitfield(const char *m_expr, - const char *n_expr, int m, int n) { - if (m == n) - return ::testing::AssertionSuccess(); +::testing::AssertionResult check_bitfield(const char* m_expr, + const char* n_expr, int m, int n) { + if (m == n) return ::testing::AssertionSuccess(); std::stringstream ss; @@ -40,14 +39,15 @@ static const int DC_MASK = 0xffffff; ss << std::showbase << std::hex << std::setw(8) << std::setfill('0') << n; std::string actual_str = ss.str(); - return ::testing::AssertionFailure() << m_expr << " and " << n_expr - << " ( " << expected_str << " vs " << actual_str << " )"; + return ::testing::AssertionFailure() << m_expr << " and " << n_expr << " ( " + << expected_str << " vs " << actual_str + << " )"; } class DeviceClassTest : public AllocationTestHarness {}; TEST_F(DeviceClassTest, cod_sizeof) { - uint8_t dc_stream[] = { 0x00, 0x00, 0x00, 0x00}; + uint8_t dc_stream[] = {0x00, 0x00, 0x00, 0x00}; bt_device_class_t dc0; device_class_from_stream(&dc0, dc_stream); EXPECT_EQ((size_t)3, sizeof(dc0)); @@ -55,21 +55,21 @@ TEST_F(DeviceClassTest, cod_sizeof) { TEST_F(DeviceClassTest, simple) { uint8_t dc_stream[][sizeof(bt_device_class_t)] = { - { 0x00, 0x00, 0x00 }, - { 0xff, 0xff, 0xff }, - { 0xaa, 0x55, 0xaa }, - { 0x01, 0x23, 0x45 }, - { 0x20, 0x07, 0x14 }, + {0x00, 0x00, 0x00}, {0xff, 0xff, 0xff}, {0xaa, 0x55, 0xaa}, + {0x01, 0x23, 0x45}, {0x20, 0x07, 0x14}, }; - for (size_t i = 0; i < sizeof(dc_stream)/sizeof(bt_device_class_t); i++) { + for (size_t i = 0; i < sizeof(dc_stream) / sizeof(bt_device_class_t); i++) { bt_device_class_t dc; device_class_from_stream(&dc, (uint8_t*)&dc_stream[i]); - uint8_t *to_stream = (uint8_t *)&dc; - EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][0], to_stream[0]); - EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][1], to_stream[1]); - EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][2], to_stream[2]); + uint8_t* to_stream = (uint8_t*)&dc; + EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][0], + to_stream[0]); + EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][1], + to_stream[1]); + EXPECT_PRED_FORMAT2(check_bitfield, (unsigned)dc_stream[i][2], + to_stream[2]); } } @@ -77,14 +77,14 @@ TEST_F(DeviceClassTest, to_stream) { { bt_device_class_t dc; - uint8_t dc_stream0[] = { 0x00, 0x00, 0x00, 0xaa }; + uint8_t dc_stream0[] = {0x00, 0x00, 0x00, 0xaa}; device_class_from_stream(&dc, dc_stream0); - uint8_t dc_stream1[] = { 0x00, 0x00, 0x00, 0x00 }; + uint8_t dc_stream1[] = {0x00, 0x00, 0x00, 0x00}; int rc = device_class_to_stream(&dc, dc_stream1, sizeof(dc_stream1)); EXPECT_EQ(3, rc); - uint32_t *val = (uint32_t *)&dc; + uint32_t* val = (uint32_t*)&dc; EXPECT_PRED_FORMAT2(check_bitfield, 0x00000000, *val & 0xffffff); EXPECT_PRED_FORMAT2(check_bitfield, 0x00, dc_stream1[0]); @@ -93,15 +93,15 @@ TEST_F(DeviceClassTest, to_stream) { } { - uint8_t dc_stream0[] = { 0xaa, 0x55, 0xaa, 0x55 }; - uint8_t dc_stream1[] = { 0x00, 0x00, 0x00, 0x00 }; + uint8_t dc_stream0[] = {0xaa, 0x55, 0xaa, 0x55}; + uint8_t dc_stream1[] = {0x00, 0x00, 0x00, 0x00}; bt_device_class_t dc; device_class_from_stream(&dc, dc_stream0); int rc = device_class_to_stream(&dc, dc_stream1, sizeof(dc_stream1)); EXPECT_EQ(3, rc); - uint32_t *val = (uint32_t *)&dc; + uint32_t* val = (uint32_t*)&dc; EXPECT_PRED_FORMAT2(check_bitfield, 0x00aa55aa, *val & 0xffffff); EXPECT_PRED_FORMAT2(check_bitfield, 0xaa, dc_stream1[0]); @@ -110,15 +110,15 @@ TEST_F(DeviceClassTest, to_stream) { } { - uint8_t dc_stream0[] = { 0x01, 0x23, 0x45, 0x67 }; - uint8_t dc_stream1[] = { 0x00, 0x00, 0x00, 0x00 }; + uint8_t dc_stream0[] = {0x01, 0x23, 0x45, 0x67}; + uint8_t dc_stream1[] = {0x00, 0x00, 0x00, 0x00}; bt_device_class_t dc; device_class_from_stream(&dc, dc_stream0); int rc = device_class_to_stream(&dc, dc_stream1, sizeof(dc_stream1)); EXPECT_EQ(3, rc); - uint32_t *val = (uint32_t *)&dc; + uint32_t* val = (uint32_t*)&dc; EXPECT_PRED_FORMAT2(check_bitfield, 0x452301, *val & 0xffffff); EXPECT_PRED_FORMAT2(check_bitfield, 0x01, dc_stream1[0]); @@ -128,10 +128,10 @@ TEST_F(DeviceClassTest, to_stream) { } TEST_F(DeviceClassTest, limited_discoverable_mode) { - uint8_t dc_stream[] = { 0x00, 0x00, 0x00 }; + uint8_t dc_stream[] = {0x00, 0x00, 0x00}; bt_device_class_t dc; device_class_from_stream(&dc, dc_stream); - uint32_t *test = (uint32_t *)&dc; + uint32_t* test = (uint32_t*)&dc; EXPECT_FALSE(device_class_get_limited(&dc)); EXPECT_EQ((unsigned)0x00000000, *test & DC_MASK); @@ -152,8 +152,8 @@ TEST_F(DeviceClassTest, limited_discoverable_mode) { } TEST_F(DeviceClassTest, equals) { - uint8_t dc_stream0[] = { 0x00, 0x01, 0x02 }; - uint8_t dc_stream1[] = { 0x00, 0x02, 0x03 }; + uint8_t dc_stream0[] = {0x00, 0x01, 0x02}; + uint8_t dc_stream1[] = {0x00, 0x02, 0x03}; bt_device_class_t dc0; device_class_from_stream(&dc0, dc_stream0); @@ -163,7 +163,7 @@ TEST_F(DeviceClassTest, equals) { } TEST_F(DeviceClassTest, copy) { - uint8_t dc_stream0[] = { 0xaa, 0x55, 0x33 }; + uint8_t dc_stream0[] = {0xaa, 0x55, 0x33}; bt_device_class_t dc0; device_class_from_stream(&dc0, dc_stream0); bt_device_class_t dc1; @@ -176,14 +176,14 @@ TEST_F(DeviceClassTest, from_int) { int cod1 = 0x5a020c; // 5898764 device_class_from_int(&dc1, cod1); - uint8_t dc_stream[] = { 0x0c, 0x02, 0x5a }; + uint8_t dc_stream[] = {0x0c, 0x02, 0x5a}; bt_device_class_t dc2; device_class_from_stream(&dc2, dc_stream); EXPECT_TRUE(device_class_equals(&dc1, &dc2)); } TEST_F(DeviceClassTest, to_int) { - bt_device_class_t dc1 = {{ 0x0c, 0x02, 0x5a }}; + bt_device_class_t dc1 = {{0x0c, 0x02, 0x5a}}; int cod1 = device_class_to_int(&dc1); EXPECT_EQ(dc1._[0], 0x0c); @@ -191,7 +191,7 @@ TEST_F(DeviceClassTest, to_int) { EXPECT_EQ(dc1._[2], 0x5a); bt_device_class_t dc2; - uint8_t dc_stream[] = { 0x0c, 0x02, 0x5a }; + uint8_t dc_stream[] = {0x0c, 0x02, 0x5a}; device_class_from_stream(&dc2, dc_stream); EXPECT_EQ(dc2._[0], 0x0c); @@ -214,5 +214,5 @@ TEST_F(DeviceClassTest, endian) { int cod2 = device_class_to_int(&dc); EXPECT_EQ(cod1, cod2); - EXPECT_EQ(cod2, 0x200714); // 2098964 + EXPECT_EQ(cod2, 0x200714); // 2098964 } diff --git a/btcore/test/property_test.cc b/btcore/test/property_test.cc index 649be3583..fbf5f9a9d 100644 --- a/btcore/test/property_test.cc +++ b/btcore/test/property_test.cc @@ -26,7 +26,7 @@ class PropertyTest : public AllocationTestHarness {}; TEST_F(PropertyTest, addr) { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; - bt_property_t *property = property_new_addr(&addr0); + bt_property_t* property = property_new_addr(&addr0); EXPECT_EQ(addr0.address[0], ((uint8_t*)property->val)[0]); EXPECT_EQ(addr0.address[1], ((uint8_t*)property->val)[1]); @@ -37,15 +37,15 @@ TEST_F(PropertyTest, addr) { EXPECT_EQ(BT_PROPERTY_BDADDR, property->type); EXPECT_EQ((int)sizeof(bt_bdaddr_t), property->len); - const bt_bdaddr_t *addr1 = property_as_addr(property); + const bt_bdaddr_t* addr1 = property_as_addr(property); EXPECT_EQ(addr0.address[0], addr1->address[0]); property_free(property); } TEST_F(PropertyTest, device_class) { - bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }}; - bt_property_t *property = property_new_device_class(&dc0); + bt_device_class_t dc0 = {{0x01, 0x23, 0x45}}; + bt_property_t* property = property_new_device_class(&dc0); EXPECT_EQ(dc0._[0], ((uint8_t*)property->val)[0]); EXPECT_EQ(dc0._[1], ((uint8_t*)property->val)[1]); @@ -53,7 +53,7 @@ TEST_F(PropertyTest, device_class) { EXPECT_EQ(BT_PROPERTY_CLASS_OF_DEVICE, property->type); EXPECT_EQ((int)sizeof(bt_device_class_t), property->len); - const bt_device_class_t *dc1 = property_as_device_class(property); + const bt_device_class_t* dc1 = property_as_device_class(property); int dc_int = device_class_to_int(dc1); EXPECT_EQ(0x452301, dc_int); @@ -62,7 +62,7 @@ TEST_F(PropertyTest, device_class) { TEST_F(PropertyTest, device_type) { bt_device_type_t dt0 = (bt_device_type_t)1; - bt_property_t *property = property_new_device_type(dt0); + bt_property_t* property = property_new_device_type(dt0); EXPECT_EQ((int)dt0, *(int*)property->val); EXPECT_EQ(BT_PROPERTY_TYPE_OF_DEVICE, property->type); @@ -76,9 +76,9 @@ TEST_F(PropertyTest, device_type) { TEST_F(PropertyTest, discovery_timeout) { uint32_t timeout0 = 12345; - bt_property_t *property = property_new_discovery_timeout(timeout0); + bt_property_t* property = property_new_discovery_timeout(timeout0); - EXPECT_EQ(timeout0, *(uint32_t *)property->val); + EXPECT_EQ(timeout0, *(uint32_t*)property->val); EXPECT_EQ(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, property->type); EXPECT_EQ((int)sizeof(uint32_t), property->len); @@ -89,24 +89,24 @@ TEST_F(PropertyTest, discovery_timeout) { } TEST_F(PropertyTest, name) { - const char *name0 = "My btcore name"; - bt_property_t *property = property_new_name(name0); + const char* name0 = "My btcore name"; + bt_property_t* property = property_new_name(name0); - EXPECT_EQ(0, strcmp((char *)name0, (char *)property->val)); + EXPECT_EQ(0, strcmp((char*)name0, (char*)property->val)); EXPECT_EQ(BT_PROPERTY_BDNAME, property->type); EXPECT_EQ((int)sizeof(bt_bdname_t), property->len); - const bt_bdname_t *name1 = property_as_name(property); - EXPECT_EQ(0, strcmp((char *)name0, (char *)name1->name)); + const bt_bdname_t* name1 = property_as_name(property); + EXPECT_EQ(0, strcmp((char*)name0, (char*)name1->name)); property_free(property); } TEST_F(PropertyTest, rssi) { int8_t rssi0 = -56; - bt_property_t *property = property_new_rssi(rssi0); + bt_property_t* property = property_new_rssi(rssi0); - EXPECT_EQ(*(int8_t *)property->val, rssi0); + EXPECT_EQ(*(int8_t*)property->val, rssi0); EXPECT_EQ(BT_PROPERTY_REMOTE_RSSI, property->type); EXPECT_EQ((int)sizeof(int8_t), property->len); @@ -118,9 +118,9 @@ TEST_F(PropertyTest, rssi) { TEST_F(PropertyTest, scan_mode) { bt_scan_mode_t mode0 = (bt_scan_mode_t)3; - bt_property_t *property = property_new_scan_mode(mode0); + bt_property_t* property = property_new_scan_mode(mode0); - EXPECT_EQ(*(int *)property->val, mode0); + EXPECT_EQ(*(int*)property->val, mode0); EXPECT_EQ(BT_PROPERTY_ADAPTER_SCAN_MODE, property->type); EXPECT_EQ((int)sizeof(int), property->len); @@ -131,22 +131,18 @@ TEST_F(PropertyTest, scan_mode) { } TEST_F(PropertyTest, uuids) { - bt_uuid_t uuid0 = { - { - 0x00, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, + bt_uuid_t uuid0 = {{ + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, - } - }; - bt_property_t *property = property_new_uuids(&uuid0, 1); + }}; + bt_property_t* property = property_new_uuids(&uuid0, 1); - EXPECT_EQ(0, strcmp((const char *)uuid0.uu, (char *)property->val)); + EXPECT_EQ(0, strcmp((const char*)uuid0.uu, (char*)property->val)); EXPECT_EQ(BT_PROPERTY_UUIDS, property->type); EXPECT_EQ((int)sizeof(bt_uuid_t), property->len); size_t uuid_cnt1; - const bt_uuid_t *uuid1 = property_as_uuids(property, &uuid_cnt1); + const bt_uuid_t* uuid1 = property_as_uuids(property, &uuid_cnt1); EXPECT_EQ(0, memcmp(uuid1->uu, uuid1->uu, sizeof(bt_uuid_t))); property_free(property); @@ -155,21 +151,18 @@ TEST_F(PropertyTest, uuids) { TEST_F(PropertyTest, copy) { { bt_uuid_t uuids[] = { - {{ - 0x00, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, - 0xcc, 0xdd, 0xee, 0xff, - }}, - {{ - 0xf0, 0xe1, 0xd2, 0xc3, - 0xf4, 0xe5, 0xd6, 0xc7, - 0xf8, 0xe9, 0xda, 0xcb, - 0xfc, 0xed, 0xde, 0xcf, - }}, + {{ + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, + 0xbb, 0xcc, 0xdd, 0xee, 0xff, + }}, + {{ + 0xf0, 0xe1, 0xd2, 0xc3, 0xf4, 0xe5, 0xd6, 0xc7, 0xf8, 0xe9, 0xda, + 0xcb, 0xfc, 0xed, 0xde, 0xcf, + }}, }; - bt_property_t *property0 = property_new_uuids(uuids, sizeof(bt_uuid_t)/sizeof(uuids)); + bt_property_t* property0 = + property_new_uuids(uuids, sizeof(bt_uuid_t) / sizeof(uuids)); bt_property_t property1; property_copy(&property1, property0); @@ -182,10 +175,10 @@ TEST_F(PropertyTest, copy) { TEST_F(PropertyTest, equals) { { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; - bt_property_t *property0 = property_new_addr(&addr0); + bt_property_t* property0 = property_new_addr(&addr0); - bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }}; - bt_property_t *property1 = property_new_device_class(&dc0); + bt_device_class_t dc0 = {{0x01, 0x23, 0x45}}; + bt_property_t* property1 = property_new_device_class(&dc0); EXPECT_FALSE(property_equals(property0, property1)); @@ -195,8 +188,8 @@ TEST_F(PropertyTest, equals) { { bt_bdaddr_t addr = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; - bt_property_t *property0 = property_new_addr(&addr); - bt_property_t *property1 = property_new_addr(&addr); + bt_property_t* property0 = property_new_addr(&addr); + bt_property_t* property1 = property_new_addr(&addr); EXPECT_TRUE(property_equals(property0, property1)); @@ -206,10 +199,10 @@ TEST_F(PropertyTest, equals) { { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; - bt_property_t *property0 = property_new_addr(&addr0); + bt_property_t* property0 = property_new_addr(&addr0); bt_bdaddr_t addr1 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0xff}}; - bt_property_t *property1 = property_new_addr(&addr1); + bt_property_t* property1 = property_new_addr(&addr1); EXPECT_FALSE(property_equals(property0, property1)); @@ -218,11 +211,11 @@ TEST_F(PropertyTest, equals) { } { - const char *name0 = "My btcore name"; - bt_property_t *property0 = property_new_name(name0); + const char* name0 = "My btcore name"; + bt_property_t* property0 = property_new_name(name0); - const char *name1 = "My btcore name"; - bt_property_t *property1 = property_new_name(name1); + const char* name1 = "My btcore name"; + bt_property_t* property1 = property_new_name(name1); EXPECT_TRUE(property_equals(property0, property1)); @@ -231,11 +224,11 @@ TEST_F(PropertyTest, equals) { } { - const char *name0 = "My btcore name"; - bt_property_t *property0 = property_new_name(name0); + const char* name0 = "My btcore name"; + bt_property_t* property0 = property_new_name(name0); - const char *name1 = "My btcore name "; - bt_property_t *property1 = property_new_name(name1); + const char* name1 = "My btcore name "; + bt_property_t* property1 = property_new_name(name1); EXPECT_FALSE(property_equals(property0, property1)); diff --git a/btcore/test/uuid_test.cc b/btcore/test/uuid_test.cc index a20cc1cee..e9a40edc8 100644 --- a/btcore/test/uuid_test.cc +++ b/btcore/test/uuid_test.cc @@ -21,22 +21,20 @@ #include "btcore/include/uuid.h" -static const char *UUID_EMPTY = "00000000-0000-0000-0000-000000000000"; -static const char *UUID_ONES = "11111111-1111-1111-1111-111111111111"; -static const char *UUID_SEQUENTIAL = "01234567-89ab-cdef-ABCD-EF0123456789"; -static const char *UUID_BASE = "00000000-0000-1000-8000-00805f9b34fb"; +static const char* UUID_EMPTY = "00000000-0000-0000-0000-000000000000"; +static const char* UUID_ONES = "11111111-1111-1111-1111-111111111111"; +static const char* UUID_SEQUENTIAL = "01234567-89ab-cdef-ABCD-EF0123456789"; +static const char* UUID_BASE = "00000000-0000-1000-8000-00805f9b34fb"; class UuidTest : public AllocationTestHarness { - protected: - virtual void SetUp() { - } + protected: + virtual void SetUp() {} - virtual void TearDown() { - } + virtual void TearDown() {} }; TEST_F(UuidTest, new_from_string) { - bt_uuid_t *uuid; + bt_uuid_t* uuid; uuid = uuid_new("incorrect length"); EXPECT_EQ(NULL, uuid); @@ -91,7 +89,7 @@ TEST_F(UuidTest, new_from_string) { } TEST_F(UuidTest, uuid_is_empty) { - bt_uuid_t *uuid = NULL; + bt_uuid_t* uuid = NULL; uuid = uuid_new(UUID_EMPTY); ASSERT_TRUE(uuid != NULL); @@ -105,7 +103,7 @@ TEST_F(UuidTest, uuid_is_empty) { } TEST_F(UuidTest, uuid_128_to_16) { - bt_uuid_t *uuid = NULL; + bt_uuid_t* uuid = NULL; uint16_t uuid16 = 0xffff; uuid = uuid_new(UUID_ONES); @@ -121,7 +119,7 @@ TEST_F(UuidTest, uuid_128_to_16) { } TEST_F(UuidTest, uuid_128_to_32) { - bt_uuid_t *uuid = NULL; + bt_uuid_t* uuid = NULL; uint32_t uuid32 = 0xffffffff; uuid = uuid_new(UUID_ONES); @@ -137,9 +135,9 @@ TEST_F(UuidTest, uuid_128_to_32) { } TEST_F(UuidTest, uuid_to_string) { - bt_uuid_t *uuid = NULL; + bt_uuid_t* uuid = NULL; - uuid_string_t *uuid_string = uuid_string_new(); + uuid_string_t* uuid_string = uuid_string_new(); EXPECT_TRUE(uuid_string != NULL); uuid = uuid_new(UUID_BASE); @@ -155,8 +153,8 @@ TEST_F(UuidTest, uuid_to_string) { uuid_to_string(uuid, uuid_string); uuid_free(uuid); - char lower_case_buf[36+1]; - for (int i = 0; i < 36+1; i++) { + char lower_case_buf[36 + 1]; + for (int i = 0; i < 36 + 1; i++) { lower_case_buf[i] = tolower(UUID_SEQUENTIAL[i]); } EXPECT_TRUE(!strcmp(lower_case_buf, uuid_string_data(uuid_string))); diff --git a/btif/src/btif_ble_advertiser.cc b/btif/src/btif_ble_advertiser.cc index efe0f7998..1fe66df17 100644 --- a/btif/src/btif_ble_advertiser.cc +++ b/btif/src/btif_ble_advertiser.cc @@ -174,16 +174,15 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface { p_params->tx_power = ble_map_adv_tx_power(params.tx_power); do_in_bta_thread( - FROM_HERE, - Bind(&BleAdvertisingManager::StartAdvertising, - base::Unretained(BleAdvertisingManager::Get()), advertiser_id, - base::Bind( - [](Callback cb, uint8_t status) { - do_in_jni_thread(Bind(cb, status)); - }, - cb), - base::Owned(p_params), std::move(advertise_data), - std::move(scan_response_data), timeout_s, timeout_cb)); + FROM_HERE, Bind(&BleAdvertisingManager::StartAdvertising, + base::Unretained(BleAdvertisingManager::Get()), + advertiser_id, base::Bind( + [](Callback cb, uint8_t status) { + do_in_jni_thread(Bind(cb, status)); + }, + cb), + base::Owned(p_params), std::move(advertise_data), + std::move(scan_response_data), timeout_s, timeout_cb)); } }; diff --git a/btif/src/btif_hf_client.cc b/btif/src/btif_hf_client.cc index 8be06b4f3..3bb78330b 100644 --- a/btif/src/btif_hf_client.cc +++ b/btif/src/btif_hf_client.cc @@ -351,8 +351,7 @@ static bt_status_t stop_voice_recognition( * ******************************************************************************/ static bt_status_t volume_control(UNUSED_ATTR const bt_bdaddr_t* bd_addr, - bthf_client_volume_type_t type, - int volume) { + bthf_client_volume_type_t type, int volume) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); switch (type) { @@ -380,8 +379,8 @@ static bt_status_t volume_control(UNUSED_ATTR const bt_bdaddr_t* bd_addr, * Returns bt_status_t * ******************************************************************************/ -static bt_status_t dial( - UNUSED_ATTR const bt_bdaddr_t* bd_addr, const char* number) { +static bt_status_t dial(UNUSED_ATTR const bt_bdaddr_t* bd_addr, + const char* number) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); if (number) { @@ -404,8 +403,8 @@ static bt_status_t dial( * Returns bt_status_t * ******************************************************************************/ -static bt_status_t dial_memory( - UNUSED_ATTR const bt_bdaddr_t* bd_addr, int location) { +static bt_status_t dial_memory(UNUSED_ATTR const bt_bdaddr_t* bd_addr, + int location) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); BTA_HfClientSendAT(btif_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATD, @@ -522,8 +521,7 @@ static bt_status_t handle_call_action(UNUSED_ATTR const bt_bdaddr_t* bd_addr, * Returns bt_status_t * ******************************************************************************/ -static bt_status_t query_current_calls( - UNUSED_ATTR const bt_bdaddr_t* bd_addr) { +static bt_status_t query_current_calls(UNUSED_ATTR const bt_bdaddr_t* bd_addr) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); if (btif_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_ECS) { @@ -583,8 +581,8 @@ static bt_status_t retrieve_subscriber_info( * Returns bt_status_t * ******************************************************************************/ -static bt_status_t send_dtmf( - UNUSED_ATTR const bt_bdaddr_t *bd_addr, char code) { +static bt_status_t send_dtmf(UNUSED_ATTR const bt_bdaddr_t* bd_addr, + char code) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); BTA_HfClientSendAT(btif_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_VTS, code, @@ -603,7 +601,7 @@ static bt_status_t send_dtmf( * ******************************************************************************/ static bt_status_t request_last_voice_tag_number( - UNUSED_ATTR const bt_bdaddr_t *bd_addr) { + UNUSED_ATTR const bt_bdaddr_t* bd_addr) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); if (btif_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_VTAG) { @@ -643,8 +641,8 @@ static void cleanup(void) { * Returns bt_status_t * ******************************************************************************/ -static bt_status_t send_at_cmd(UNUSED_ATTR const bt_bdaddr_t *bd_addr, - int cmd, int val1, int val2, const char* arg) { +static bt_status_t send_at_cmd(UNUSED_ATTR const bt_bdaddr_t* bd_addr, int cmd, + int val1, int val2, const char* arg) { CHECK_BTHF_CLIENT_SLC_CONNECTED(); BTIF_TRACE_EVENT("%s Cmd %d val1 %d val2 %d arg %s", __func__, cmd, val1, val2, (arg != NULL) ? arg : ""); @@ -702,8 +700,7 @@ static void process_ind_evt(tBTA_HF_CLIENT_IND* ind) { case BTA_HF_CLIENT_IND_SIGNAL: HAL_CBACK(bt_hf_client_callbacks, network_signal_cb, - &btif_hf_client_cb.connected_bda, - ind->value); + &btif_hf_client_cb.connected_bda, ind->value); break; case BTA_HF_CLIENT_IND_ROAM: @@ -714,8 +711,7 @@ static void process_ind_evt(tBTA_HF_CLIENT_IND* ind) { case BTA_HF_CLIENT_IND_BATTCH: HAL_CBACK(bt_hf_client_callbacks, battery_level_cb, - &btif_hf_client_cb.connected_bda, - ind->value); + &btif_hf_client_cb.connected_bda, ind->value); break; default: @@ -769,9 +765,9 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { } HAL_CBACK(bt_hf_client_callbacks, connection_state_cb, - &btif_hf_client_cb.connected_bda, - btif_hf_client_cb.state, 0, /* peer feat */ - 0 /* AT+CHLD feat */); + &btif_hf_client_cb.connected_bda, btif_hf_client_cb.state, + 0, /* peer feat */ + 0 /* AT+CHLD feat */); if (btif_hf_client_cb.state == BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED) bdsetany(btif_hf_client_cb.connected_bda.address); @@ -785,10 +781,8 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { btif_hf_client_cb.state = BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED; HAL_CBACK(bt_hf_client_callbacks, connection_state_cb, - &btif_hf_client_cb.connected_bda, - btif_hf_client_cb.state, - btif_hf_client_cb.peer_feat, - btif_hf_client_cb.chld_feat); + &btif_hf_client_cb.connected_bda, btif_hf_client_cb.state, + btif_hf_client_cb.peer_feat, btif_hf_client_cb.chld_feat); /* Inform the application about in-band ringtone */ if (btif_hf_client_cb.peer_feat & BTA_HF_CLIENT_PEER_INBAND) { @@ -803,8 +797,8 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { case BTA_HF_CLIENT_CLOSE_EVT: btif_hf_client_cb.state = BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED; HAL_CBACK(bt_hf_client_callbacks, connection_state_cb, - &btif_hf_client_cb.connected_bda, - btif_hf_client_cb.state, 0, 0); + &btif_hf_client_cb.connected_bda, btif_hf_client_cb.state, 0, + 0); bdsetany(btif_hf_client_cb.connected_bda.address); btif_hf_client_cb.peer_feat = 0; btif_hf_client_cb.chld_feat = 0; @@ -817,14 +811,14 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { case BTA_HF_CLIENT_MIC_EVT: HAL_CBACK(bt_hf_client_callbacks, volume_change_cb, - &btif_hf_client_cb.connected_bda, - BTHF_CLIENT_VOLUME_TYPE_MIC, p_data->val.value); + &btif_hf_client_cb.connected_bda, BTHF_CLIENT_VOLUME_TYPE_MIC, + p_data->val.value); break; case BTA_HF_CLIENT_SPK_EVT: HAL_CBACK(bt_hf_client_callbacks, volume_change_cb, - &btif_hf_client_cb.connected_bda, - BTHF_CLIENT_VOLUME_TYPE_SPK, p_data->val.value); + &btif_hf_client_cb.connected_bda, BTHF_CLIENT_VOLUME_TYPE_SPK, + p_data->val.value); break; case BTA_HF_CLIENT_VOICE_REC_EVT: @@ -835,26 +829,22 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { case BTA_HF_CLIENT_OPERATOR_NAME_EVT: HAL_CBACK(bt_hf_client_callbacks, current_operator_cb, - &btif_hf_client_cb.connected_bda, - p_data->operator_name.name); + &btif_hf_client_cb.connected_bda, p_data->operator_name.name); break; case BTA_HF_CLIENT_CLIP_EVT: HAL_CBACK(bt_hf_client_callbacks, clip_cb, - &btif_hf_client_cb.connected_bda, - p_data->number.number); + &btif_hf_client_cb.connected_bda, p_data->number.number); break; case BTA_HF_CLIENT_BINP_EVT: HAL_CBACK(bt_hf_client_callbacks, last_voice_tag_number_callback, - &btif_hf_client_cb.connected_bda, - p_data->number.number); + &btif_hf_client_cb.connected_bda, p_data->number.number); break; case BTA_HF_CLIENT_CCWA_EVT: HAL_CBACK(bt_hf_client_callbacks, call_waiting_cb, - &btif_hf_client_cb.connected_bda, - p_data->number.number); + &btif_hf_client_cb.connected_bda, p_data->number.number); break; case BTA_HF_CLIENT_AT_RESULT_EVT: @@ -866,8 +856,7 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { case BTA_HF_CLIENT_CLCC_EVT: HAL_CBACK(bt_hf_client_callbacks, current_calls_cb, - &btif_hf_client_cb.connected_bda, - p_data->clcc.idx, + &btif_hf_client_cb.connected_bda, p_data->clcc.idx, p_data->clcc.inc ? BTHF_CLIENT_CALL_DIRECTION_INCOMING : BTHF_CLIENT_CALL_DIRECTION_OUTGOING, (bthf_client_call_state_t)p_data->clcc.status, @@ -879,16 +868,16 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) { case BTA_HF_CLIENT_CNUM_EVT: if (p_data->cnum.service == 4) { HAL_CBACK(bt_hf_client_callbacks, subscriber_info_cb, - &btif_hf_client_cb.connected_bda, - p_data->cnum.number, BTHF_CLIENT_SERVICE_VOICE); + &btif_hf_client_cb.connected_bda, p_data->cnum.number, + BTHF_CLIENT_SERVICE_VOICE); } else if (p_data->cnum.service == 5) { HAL_CBACK(bt_hf_client_callbacks, subscriber_info_cb, - &btif_hf_client_cb.connected_bda, - p_data->cnum.number, BTHF_CLIENT_SERVICE_FAX); + &btif_hf_client_cb.connected_bda, p_data->cnum.number, + BTHF_CLIENT_SERVICE_FAX); } else { HAL_CBACK(bt_hf_client_callbacks, subscriber_info_cb, - &btif_hf_client_cb.connected_bda, - p_data->cnum.number, BTHF_CLIENT_SERVICE_UNKNOWN); + &btif_hf_client_cb.connected_bda, p_data->cnum.number, + BTHF_CLIENT_SERVICE_UNKNOWN); } break; diff --git a/btif/src/btif_hl.cc b/btif/src/btif_hl.cc index 02c9ea0cb..0a85db44e 100644 --- a/btif/src/btif_hl.cc +++ b/btif/src/btif_hl.cc @@ -3986,7 +3986,9 @@ bool btif_hl_save_mdl_cfg(uint8_t mdep_id, uint8_t item_idx, evt_param.update_mdl.app_idx = app_idx; len = sizeof(btif_hl_update_mdl_t); BTIF_TRACE_DEBUG("send BTIF_HL_UPDATE_MDL event app_idx=%d ", app_idx); - bt_status = btif_transfer_context(btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, (char *)&evt_param, len, NULL); + bt_status = + btif_transfer_context(btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, + (char*)&evt_param, len, NULL); if (bt_status == BT_STATUS_SUCCESS) { success = true; } @@ -4023,7 +4025,8 @@ bool btif_hl_delete_mdl_cfg(uint8_t mdep_id, uint8_t item_idx) { evt_param.update_mdl.app_idx = app_idx; len = sizeof(btif_hl_update_mdl_t); BTIF_TRACE_DEBUG("send BTIF_HL_UPDATE_MDL event app_idx=%d ", app_idx); - bt_status = btif_transfer_context(btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, (char *)&evt_param, len, NULL); + bt_status = btif_transfer_context(btif_hl_proc_cb_evt, BTIF_HL_UPDATE_MDL, + (char*)&evt_param, len, NULL); if (bt_status == BT_STATUS_SUCCESS) { success = true; } diff --git a/btif/src/btif_pan.cc b/btif/src/btif_pan.cc index 6fdc3f66a..bff883d30 100644 --- a/btif/src/btif_pan.cc +++ b/btif/src/btif_pan.cc @@ -392,7 +392,7 @@ int btpan_tap_open() { strncpy(ifr.ifr_name, TAP_IF_NAME, IFNAMSIZ); /* try to create the device */ - err = ioctl(fd, TUNSETIFF, (void *)&ifr); + err = ioctl(fd, TUNSETIFF, (void*)&ifr); if (err < 0) { BTIF_TRACE_DEBUG("ioctl error:%d, errno:%s", err, strerror(errno)); close(fd); diff --git a/btif/src/btif_rc.cc b/btif/src/btif_rc.cc index ac4202e5b..f0e1ae611 100644 --- a/btif/src/btif_rc.cc +++ b/btif/src/btif_rc.cc @@ -1413,32 +1413,33 @@ static uint8_t fill_attribute_id_array( uint8_t out_attribute_number = 0; if (cmd_attribute_number == 0) { /* All attributes */ - out_attribute_number = - out_array_size < AVRC_MAX_NUM_MEDIA_ATTR_ID ? - out_array_size : AVRC_MAX_NUM_MEDIA_ATTR_ID; + out_attribute_number = out_array_size < AVRC_MAX_NUM_MEDIA_ATTR_ID + ? out_array_size + : AVRC_MAX_NUM_MEDIA_ATTR_ID; for (int i = 0; i < out_attribute_number; i++) { - out_attribute_id_array[i] = (btrc_media_attr_t) (i + 1); + out_attribute_id_array[i] = (btrc_media_attr_t)(i + 1); } } else if (cmd_attribute_number != 0xFF) { /* Attribute List */ out_attribute_number = 0; int filled_id_count = 0; - for (int i = 0; (i < cmd_attribute_number) - && (out_attribute_number < out_array_size) - && (out_attribute_number < AVRC_MAX_NUM_MEDIA_ATTR_ID); i++) { + for (int i = 0; (i < cmd_attribute_number) && + (out_attribute_number < out_array_size) && + (out_attribute_number < AVRC_MAX_NUM_MEDIA_ATTR_ID); + i++) { /* Fill only valid entries */ if (AVRC_IS_VALID_MEDIA_ATTRIBUTE(cmd_attribute_id_array[i])) { /* Skip the duplicate entries */ for (filled_id_count = 0; filled_id_count < out_attribute_number; - filled_id_count++) { - if (out_attribute_id_array[filled_id_count] - == cmd_attribute_id_array[i]) + filled_id_count++) { + if (out_attribute_id_array[filled_id_count] == + cmd_attribute_id_array[i]) break; } /* New ID */ if (filled_id_count == out_attribute_number) { out_attribute_id_array[out_attribute_number] = - (btrc_media_attr_t) cmd_attribute_id_array[i]; + (btrc_media_attr_t)cmd_attribute_id_array[i]; out_attribute_number++; } } diff --git a/btif/src/btif_sock_l2cap.cc b/btif/src/btif_sock_l2cap.cc index 82d0d7cb0..d7f48c755 100644 --- a/btif/src/btif_sock_l2cap.cc +++ b/btif/src/btif_sock_l2cap.cc @@ -773,8 +773,8 @@ static void btsock_l2cap_cbk(tBTA_JV_EVT event, tBTA_JV* p_data, case BTA_JV_L2CAP_WRITE_EVT: APPL_TRACE_DEBUG("BTA_JV_L2CAP_WRITE_EVT: id: %u", l2cap_socket_id); - on_l2cap_write_done(p_data->l2c_write.p_data, - p_data->l2c_write.len, l2cap_socket_id); + on_l2cap_write_done(p_data->l2c_write.p_data, p_data->l2c_write.len, + l2cap_socket_id); break; case BTA_JV_L2CAP_WRITE_FIXED_EVT: @@ -788,7 +788,8 @@ static void btsock_l2cap_cbk(tBTA_JV_EVT event, tBTA_JV* p_data, break; default: - APPL_TRACE_ERROR("unhandled event %d, slot id: %u", event, l2cap_socket_id); + APPL_TRACE_ERROR("unhandled event %d, slot id: %u", event, + l2cap_socket_id); break; } } @@ -853,12 +854,12 @@ static bt_status_t btSock_start_l2cap_server_l(l2cap_socket* sock) { * else we request a PSM and start the server after we receive a PSM. */ if (sock->channel < 0) { if (sock->is_le_coc) { - if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP_LE, sock->id, - 0) != BTA_JV_SUCCESS) + if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP_LE, sock->id, 0) != + BTA_JV_SUCCESS) stat = BT_STATUS_FAIL; } else { - if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP, sock->id, - 0) != BTA_JV_SUCCESS) + if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP, sock->id, 0) != + BTA_JV_SUCCESS) stat = BT_STATUS_FAIL; } } else { @@ -933,8 +934,7 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name, if (fixed_chan) { if (BTA_JvL2capConnectLE(sock->security, 0, NULL, channel, L2CAP_DEFAULT_MTU, NULL, sock->addr.address, - btsock_l2cap_cbk, - sock->id) != BTA_JV_SUCCESS) + btsock_l2cap_cbk, sock->id) != BTA_JV_SUCCESS) stat = BT_STATUS_FAIL; } else { @@ -1059,8 +1059,7 @@ void btsock_l2cap_signaled(int fd, int flags, uint32_t user_id) { if (sock->fixed_chan) { if (BTA_JvL2capWriteFixed(sock->channel, (BD_ADDR*)&sock->addr, PTR_TO_UINT(buffer), btsock_l2cap_cbk, - buffer, count, - user_id) != BTA_JV_SUCCESS) { + buffer, count, user_id) != BTA_JV_SUCCESS) { // On fail, free the buffer on_l2cap_write_fixed_done(buffer, count, user_id); } diff --git a/btif/src/btif_sock_rfc.cc b/btif/src/btif_sock_rfc.cc index 458b3b924..348f277fb 100644 --- a/btif/src/btif_sock_rfc.cc +++ b/btif/src/btif_sock_rfc.cc @@ -372,8 +372,7 @@ bt_status_t btsock_rfc_connect(const bt_bdaddr_t* bd_addr, memcpy(sdp_uuid.uu.uuid128, service_uuid, sizeof(sdp_uuid.uu.uuid128)); if (!is_requesting_sdp()) { - BTA_JvStartDiscovery((uint8_t*)bd_addr->address, 1, &sdp_uuid, - slot->id); + BTA_JvStartDiscovery((uint8_t*)bd_addr->address, 1, &sdp_uuid, slot->id); slot->f.pending_sdp_request = false; slot->f.doing_sdp_request = true; } else { diff --git a/conf/bt_did.conf b/conf/bt_did.conf index 631cc6df3..2027c6546 100644 --- a/conf/bt_did.conf +++ b/conf/bt_did.conf @@ -1,85 +1,92 @@ -# Device ID (DID) configuration +#Device ID(DID) configuration [DID1] -# Primary Record - true or false (default) -# There can be only one primary record -primaryRecord = true +#Primary Record - true or false(default) +#There can be only one primary record + primaryRecord = true -# Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the device -# 0x000F = Broadcom Corporation (default) +#Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the \ + device +# 0x000F = Broadcom Corporation(default) #vendorId = 0x000F -# Vendor ID Source -# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value (default) +#Vendor ID Source +# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value(default) # 0x0002 = USB Implementer's Forum assigned Device ID Vendor ID value #vendorIdSource = 0x0001 -# Product ID & Product Version -# Per spec DID v1.3 0xJJMN for version is interpreted as JJ.M.N -# JJ: major version number, M: minor version number, N: sub-minor version number -# For example: 1200, v14.3.6 -productId = 0x1200 -version = 0x1436 +#Product ID& Product Version +#Per spec DID v1 .3 0xJJMN for version is interpreted as JJ.M.N +#JJ : major version number, M : minor version number, \ + N : sub - minor version number +#For example : 1200, v14 .3.6 + productId = 0x1200 version = 0x1436 -# Optional attributes +#Optional attributes #clientExecutableURL = #serviceDescription = #documentationURL = -#=================================================================================================# -# Device ID (DID) configuration -[DID2] +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == == == == == == == == == == = # +#Device ID(DID) configuration + [DID2] -# Primary Record - true or false (default) -# There can be only one primary record +#Primary Record - true or false(default) +#There can be only one primary record #primaryRecord = false -# Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the device -# 0x000F = Broadcom Corporation (default) +#Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the \ + device +# 0x000F = Broadcom Corporation(default) #vendorId = 0x000F -# Vendor ID Source -# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value (default) +#Vendor ID Source +# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value(default) # 0x0002 = USB Implementer's Forum assigned Device ID Vendor ID value #vendorIdSource = 0x0001 -# Product ID & Product Version -# Per spec DID v1.3 0xJJMN for version is interpreted as JJ.M.N -# JJ: major version number, M: minor version number, N: sub-minor version number -# Default: 0x0000, v00.0.0 +#Product ID& Product Version +#Per spec DID v1 .3 0xJJMN for version is interpreted as JJ.M.N +#JJ : major version number, M : minor version number, \ + N : sub - minor version number +#Default : 0x0000, v00 .0.0 #productId = 0x0000 #version = 0x0000 -# Optional attributes +#Optional attributes #clientExecutableURL = #serviceDescription = #documentationURL = -#=================================================================================================# -# Device ID (DID) configuration -[DID3] +#== == == == == == == == == == == == == == == == == == == == == == == == == == \ + == == == == == == == == == == == == == == == == == == == == == == = # +#Device ID(DID) configuration + [DID3] -# Primary Record - true or false (default) -# There can be only one primary record +#Primary Record - true or false(default) +#There can be only one primary record #primaryRecord = false -# Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the device -# 0x000F = Broadcom Corporation (default) +#Vendor ID '0xFFFF' indicates no Device ID Service Record is present in the \ + device +# 0x000F = Broadcom Corporation(default) #vendorId = 0x000F -# Vendor ID Source -# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value (default) +#Vendor ID Source +# 0x0001 = Bluetooth SIG assigned Device ID Vendor ID value(default) # 0x0002 = USB Implementer's Forum assigned Device ID Vendor ID value #vendorIdSource = 0x0001 -# Product ID & Product Version -# Per spec DID v1.3 0xJJMN for version is interpreted as JJ.M.N -# JJ: major version number, M: minor version number, N: sub-minor version number -# Default: 0x0000, v00.0.0 +#Product ID& Product Version +#Per spec DID v1 .3 0xJJMN for version is interpreted as JJ.M.N +#JJ : major version number, M : minor version number, \ + N : sub - minor version number +#Default : 0x0000, v00 .0.0 #productId = 0x0000 #version = 0x0000 -# Optional attributes +#Optional attributes #clientExecutableURL = #serviceDescription = #documentationURL = diff --git a/conf/bt_stack.conf b/conf/bt_stack.conf index 6654943c2..a8e3ce4e1 100644 --- a/conf/bt_stack.conf +++ b/conf/bt_stack.conf @@ -1,50 +1,37 @@ -# Enable BtSnoop logging function -# valid value : true, false -BtSnoopLogOutput=false +#Enable BtSnoop logging function +#valid value : true, false +BtSnoopLogOutput = false -# BtSnoop log output file -BtSnoopFileName=/data/misc/bluetooth/logs/btsnoop_hci.log +#BtSnoop log output file + BtSnoopFileName = / data / misc / bluetooth / logs / + btsnoop_hci.log -# Preserve existing BtSnoop log before overwriting -BtSnoopSaveLog=false +#Preserve existing BtSnoop log before overwriting + BtSnoopSaveLog = false -# Enable trace level reconfiguration function -# Must be present before any TRC_ trace level settings -TraceConf=true +#Enable trace level reconfiguration function +#Must be present before any TRC_ trace level settings + TraceConf = true -# Trace level configuration -# BT_TRACE_LEVEL_NONE 0 ( No trace messages to be generated ) -# BT_TRACE_LEVEL_ERROR 1 ( Error condition trace messages ) -# BT_TRACE_LEVEL_WARNING 2 ( Warning condition trace messages ) -# BT_TRACE_LEVEL_API 3 ( API traces ) -# BT_TRACE_LEVEL_EVENT 4 ( Debug messages for events ) -# BT_TRACE_LEVEL_DEBUG 5 ( Full debug messages ) -# BT_TRACE_LEVEL_VERBOSE 6 ( Verbose messages ) - Currently supported for TRC_BTAPP only. -TRC_BTM=2 -TRC_HCI=2 -TRC_L2CAP=2 -TRC_RFCOMM=2 -TRC_OBEX=2 -TRC_AVCT=2 -TRC_AVDT=2 -TRC_AVRC=2 -TRC_AVDT_SCB=2 -TRC_AVDT_CCB=2 -TRC_A2D=2 -TRC_SDP=2 -TRC_GATT=2 -TRC_SMP=2 -TRC_BTAPP=2 -TRC_BTIF=2 -TRC_GAP=2 -TRC_BNEP=2 -TRC_PAN=2 +#Trace level configuration +#BT_TRACE_LEVEL_NONE 0(No trace messages to be generated) +#BT_TRACE_LEVEL_ERROR 1(Error condition trace messages) +#BT_TRACE_LEVEL_WARNING 2(Warning condition trace messages) +#BT_TRACE_LEVEL_API 3(API traces) +#BT_TRACE_LEVEL_EVENT 4(Debug messages for events) +#BT_TRACE_LEVEL_DEBUG 5(Full debug messages) +#BT_TRACE_LEVEL_VERBOSE 6(Verbose messages) - \ + Currently supported for TRC_BTAPP only. + TRC_BTM = 2 TRC_HCI = 2 TRC_L2CAP = 2 TRC_RFCOMM = 2 TRC_OBEX = 2 TRC_AVCT = + 2 TRC_AVDT = 2 TRC_AVRC = 2 TRC_AVDT_SCB = 2 TRC_AVDT_CCB = 2 TRC_A2D = + 2 TRC_SDP = 2 TRC_GATT = 2 TRC_SMP = 2 TRC_BTAPP = 2 TRC_BTIF = + 2 TRC_GAP = 2 TRC_BNEP = 2 TRC_PAN = 2 -# This is Log configuration for new C++ code using LOG() macros. -# See libchrome/base/logging.h for description on how to configure your logs. -# sample configuration: -#LoggingV=--v=0 -#LoggingVModule=--vmodule=*/btm/*=1,btm_ble_multi*=2,btif_*=1 +#This is Log configuration for new C++ code using LOG() macros. +#See libchrome / base / logging.h for description on how to configure your logs. +#sample configuration: +#LoggingV = --v = 0 +#LoggingVModule = --vmodule = * / btm/*=1,btm_ble_multi*=2,btif_*=1 # PTS testing helpers diff --git a/embdrv/sbc/decoder/include/oi_assert.h b/embdrv/sbc/decoder/include/oi_assert.h index c25ba85cf..1d18f1205 100644 --- a/embdrv/sbc/decoder/include/oi_assert.h +++ b/embdrv/sbc/decoder/include/oi_assert.h @@ -20,9 +20,11 @@ #ifndef _OI_ASSERT_H #define _OI_ASSERT_H /** @file - This file provides macros and functions for compile-time and run-time assertions. + This file provides macros and functions for compile-time and run-time + assertions. - When the OI_DEBUG preprocessor value is defined, the macro OI_ASSERT is compiled into + When the OI_DEBUG preprocessor value is defined, the macro OI_ASSERT is + compiled into the program, providing for a runtime assertion failure check. C_ASSERT is a macro that can be used to perform compile time checks. */ @@ -30,7 +32,6 @@ $Revision: #1 $ ******************************************************************************/ - /** \addtogroup Debugging Debugging APIs */ /**@{*/ @@ -38,35 +39,36 @@ extern "C" { #endif - #ifdef OI_DEBUG /** The macro OI_ASSERT takes a condition argument. If the asserted condition - does not evaluate to true, the OI_ASSERT macro calls the host-dependent function, + does not evaluate to true, the OI_ASSERT macro calls the host-dependent + function, OI_AssertFail(), which reports the failure and generates a runtime error. */ void OI_AssertFail(char* file, int line, char* reason); - -#define OI_ASSERT(condition) \ - { if (!(condition)) OI_AssertFail(__FILE__, __LINE__, #condition); } +#define OI_ASSERT(condition) \ + { \ + if (!(condition)) OI_AssertFail(__FILE__, __LINE__, #condition); \ + } #define OI_ASSERT_FAIL(msg) \ - { OI_AssertFail(__FILE__, __LINE__, msg); } + { OI_AssertFail(__FILE__, __LINE__, msg); } #else - #define OI_ASSERT(condition) #define OI_ASSERT_FAIL(msg) #endif - /** - C_ASSERT() can be used to perform many compile-time assertions: type sizes, field offsets, etc. + C_ASSERT() can be used to perform many compile-time assertions: type sizes, + field offsets, etc. An assertion failure results in compile time error C2118: negative subscript. - Unfortunately, this elegant macro doesn't work with GCC, so it's all commented out + Unfortunately, this elegant macro doesn't work with GCC, so it's all + commented out for now. Perhaps later..... */ @@ -75,7 +77,6 @@ void OI_AssertFail(char* file, int line, char* reason); // #define C_ASSERT(e) #endif - /*****************************************************************************/ #ifdef __cplusplus } @@ -84,4 +85,3 @@ void OI_AssertFail(char* file, int line, char* reason); /**@}*/ #endif /* _OI_ASSERT_H */ - diff --git a/embdrv/sbc/decoder/include/oi_bitstream.h b/embdrv/sbc/decoder/include/oi_bitstream.h index 346e67cd3..1fb075e5c 100644 --- a/embdrv/sbc/decoder/include/oi_bitstream.h +++ b/embdrv/sbc/decoder/include/oi_bitstream.h @@ -24,7 +24,6 @@ $Revision: #1 $ ******************************************************************************/ - /** @file Function prototypes and macro definitions for manipulating input and output @@ -41,32 +40,29 @@ bitstreams. #include "oi_codec_sbc_private.h" #include "oi_stddefs.h" -INLINE void OI_BITSTREAM_ReadInit(OI_BITSTREAM *bs, const OI_BYTE *buffer); +INLINE void OI_BITSTREAM_ReadInit(OI_BITSTREAM* bs, const OI_BYTE* buffer); -INLINE void OI_BITSTREAM_WriteInit(OI_BITSTREAM *bs, OI_BYTE *buffer); +INLINE void OI_BITSTREAM_WriteInit(OI_BITSTREAM* bs, OI_BYTE* buffer); -INLINE uint32_t OI_BITSTREAM_ReadUINT(OI_BITSTREAM *bs, OI_UINT bits); +INLINE uint32_t OI_BITSTREAM_ReadUINT(OI_BITSTREAM* bs, OI_UINT bits); -INLINE uint8_t OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs); +INLINE uint8_t OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM* bs); -INLINE uint8_t OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM *bs); +INLINE uint8_t OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM* bs); -INLINE void OI_BITSTREAM_WriteUINT(OI_BITSTREAM *bs, - uint16_t value, +INLINE void OI_BITSTREAM_WriteUINT(OI_BITSTREAM* bs, uint16_t value, OI_UINT bits); /* * Use knowledge that the bitstream is aligned to optimize the write of a byte */ -PRIVATE void OI_BITSTREAM_WriteUINT8Aligned(OI_BITSTREAM *bs, - uint8_t datum); +PRIVATE void OI_BITSTREAM_WriteUINT8Aligned(OI_BITSTREAM* bs, uint8_t datum); /* * Use knowledge that the bitstream is aligned to optimize the writing of a * pair of nibbles. */ -PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM *bs, - uint8_t datum1, +PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM* bs, uint8_t datum1, uint8_t datum2); /** Internally the bitstream looks ahead in the stream. When @@ -80,43 +76,42 @@ PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM *bs, * encapsulation for efficiency reasons. */ #define OI_BITSTREAM_READUINT(result, bits, ptr, value, bitPtr) \ -do { \ - OI_ASSERT((bits) <= 16); \ - OI_ASSERT((bitPtr) < 16); \ - OI_ASSERT((bitPtr) >= 8); \ - \ - (result) = (value) << (bitPtr); \ - (result) >>= 32 - (bits); \ - \ - (bitPtr) += (bits); \ - while ((bitPtr) >= 16) { \ - (value) = ((value) << 8) | *(ptr)++; \ - (bitPtr) -= 8; \ - } \ - OI_ASSERT(((bits) == 0) || ((result) < (1u << (bits)))); \ -} while (0) - + do { \ + OI_ASSERT((bits) <= 16); \ + OI_ASSERT((bitPtr) < 16); \ + OI_ASSERT((bitPtr) >= 8); \ + \ + (result) = (value) << (bitPtr); \ + (result) >>= 32 - (bits); \ + \ + (bitPtr) += (bits); \ + while ((bitPtr) >= 16) { \ + (value) = ((value) << 8) | *(ptr)++; \ + (bitPtr) -= 8; \ + } \ + OI_ASSERT(((bits) == 0) || ((result) < (1u << (bits)))); \ + } while (0) #define OI_BITSTREAM_WRITEUINT(ptr, value, bitPtr, datum, bits) \ -do {\ - (bitPtr) -= (bits);\ - (value) |= (datum) << (bitPtr);\ - \ - while ((bitPtr) <= 16) {\ - (bitPtr) += 8;\ - *(ptr)++ = (uint8_t)((value) >> 24);\ - (value) <<= 8;\ - }\ -} while (0) + do { \ + (bitPtr) -= (bits); \ + (value) |= (datum) << (bitPtr); \ + \ + while ((bitPtr) <= 16) { \ + (bitPtr) += 8; \ + *(ptr)++ = (uint8_t)((value) >> 24); \ + (value) <<= 8; \ + } \ + } while (0) #define OI_BITSTREAM_WRITEFLUSH(ptr, value, bitPtr) \ -do {\ - while ((bitPtr) < 32) {\ - (bitPtr) += 8;\ - *(ptr)++ = (uint8_t)((value) >> 24);\ - (value) <<= 8;\ - }\ -} while (0) + do { \ + while ((bitPtr) < 32) { \ + (bitPtr) += 8; \ + *(ptr)++ = (uint8_t)((value) >> 24); \ + (value) <<= 8; \ + } \ + } while (0) /** @} diff --git a/embdrv/sbc/decoder/include/oi_bt_spec.h b/embdrv/sbc/decoder/include/oi_bt_spec.h index 435a55b7a..f9bb13eb1 100644 --- a/embdrv/sbc/decoder/include/oi_bt_spec.h +++ b/embdrv/sbc/decoder/include/oi_bt_spec.h @@ -43,7 +43,7 @@ extern "C" { #define OI_BT_MAX_ACTIVE_SLAVES 7 /** the number of bytes in a Bluetooth device address (BD_ADDR) */ -#define OI_BD_ADDR_BYTE_SIZE 6 +#define OI_BD_ADDR_BYTE_SIZE 6 /** * 48-bit Bluetooth device address @@ -58,10 +58,10 @@ extern "C" { * - array[4] contains bits 15-8, and * - array[5] contains bits 7-0. */ -typedef struct { - /* Bluetooth device address represented as an array of 8-bit values */ - uint8_t addr[OI_BD_ADDR_BYTE_SIZE] ; -} OI_BD_ADDR ; +typedef struct { + /* Bluetooth device address represented as an array of 8-bit values */ + uint8_t addr[OI_BD_ADDR_BYTE_SIZE]; +} OI_BD_ADDR; /** * @name Data types for working with UUIDs @@ -87,12 +87,12 @@ typedef uint32_t OI_UUID32; /** * number of bytes in a 128 bit UUID */ -#define OI_BT_UUID128_SIZE 16 +#define OI_BT_UUID128_SIZE 16 /** * number of bytes in IPv6 style addresses */ -#define OI_BT_IPV6ADDR_SIZE 16 +#define OI_BT_IPV6ADDR_SIZE 16 /** * type definition for a 128-bit UUID @@ -103,16 +103,16 @@ typedef uint32_t OI_UUID32; * stored as bytes in big-endian order. */ typedef struct { - /* most significant 32 bits of 128-bit UUID */ - uint32_t ms32bits; - /* remainder of 128-bit UUID, array of 8-bit values */ - uint8_t base[OI_BT_UUID128_SIZE - sizeof(uint32_t)]; + /* most significant 32 bits of 128-bit UUID */ + uint32_t ms32bits; + /* remainder of 128-bit UUID, array of 8-bit values */ + uint8_t base[OI_BT_UUID128_SIZE - sizeof(uint32_t)]; } OI_UUID128; /** @} */ /** number of bytes in a link key */ -#define OI_BT_LINK_KEY_SIZE 16 +#define OI_BT_LINK_KEY_SIZE 16 /** * type definition for a baseband link key @@ -138,59 +138,56 @@ typedef struct { * - array[15] contains bits 120- 127. */ typedef struct { - /* link key represented as an array of 8-bit values */ - uint8_t key[OI_BT_LINK_KEY_SIZE] ; -} OI_LINK_KEY ; - + /* link key represented as an array of 8-bit values */ + uint8_t key[OI_BT_LINK_KEY_SIZE]; +} OI_LINK_KEY; /** Out-of-band data size - C and R values are 16-bytes each */ -#define OI_BT_OOB_NUM_BYTES 16 +#define OI_BT_OOB_NUM_BYTES 16 typedef struct { - /* same struct used for C and R values */ - uint8_t value[OI_BT_OOB_NUM_BYTES] ; -} OI_OOB_DATA ; - + /* same struct used for C and R values */ + uint8_t value[OI_BT_OOB_NUM_BYTES]; +} OI_OOB_DATA; /** * link key types */ -typedef enum { - OI_LINK_KEY_TYPE_COMBO = 0, /* combination key */ - OI_LINK_KEY_TYPE_LOCAL_UNIT = 1, /* local unit key */ - OI_LINK_KEY_TYPE_REMOTE_UNIT = 2, /* remote unit key */ - OI_LINK_KEY_TYPE_DEBUG_COMBO = 3, /* debug combination key */ - OI_LINK_KEY_TYPE_UNAUTHENTICATED = 4, /* Unauthenticated */ - OI_LINK_KEY_TYPE_AUTHENTICATED = 5, /* Authenticated */ - OI_LINK_KEY_TYPE_CHANGED_COMBO = 6 /* Changed */ - -} OI_BT_LINK_KEY_TYPE ; +typedef enum { + OI_LINK_KEY_TYPE_COMBO = 0, /* combination key */ + OI_LINK_KEY_TYPE_LOCAL_UNIT = 1, /* local unit key */ + OI_LINK_KEY_TYPE_REMOTE_UNIT = 2, /* remote unit key */ + OI_LINK_KEY_TYPE_DEBUG_COMBO = 3, /* debug combination key */ + OI_LINK_KEY_TYPE_UNAUTHENTICATED = 4, /* Unauthenticated */ + OI_LINK_KEY_TYPE_AUTHENTICATED = 5, /* Authenticated */ + OI_LINK_KEY_TYPE_CHANGED_COMBO = 6 /* Changed */ +} OI_BT_LINK_KEY_TYPE; /* Number of bytes allocated for a PIN (personal indentification number) */ -#define OI_BT_PIN_CODE_SIZE 16 +#define OI_BT_PIN_CODE_SIZE 16 /* data type for a PIN (PINs are treated as strings.) */ -typedef struct { - /* PIN represented as an array of 8-bit values */ - uint8_t pin[OI_BT_PIN_CODE_SIZE] ; -} OI_PIN_CODE ; +typedef struct { + /* PIN represented as an array of 8-bit values */ + uint8_t pin[OI_BT_PIN_CODE_SIZE]; +} OI_PIN_CODE; /* maximum number of SCO connections per device: 3 as of version 2.0+EDR of the Bluetooth specification (see sec 4.3 of vol 2 part B) */ -#define OI_BT_MAX_SCO_CONNECTIONS 3 +#define OI_BT_MAX_SCO_CONNECTIONS 3 /** data type for clock offset */ -typedef uint16_t OI_BT_CLOCK_OFFSET ; +typedef uint16_t OI_BT_CLOCK_OFFSET; /** data type for a LM handle */ typedef uint16_t OI_HCI_LM_HANDLE; /** opaque data type for a SCO or ACL connection handle */ -typedef struct _OI_HCI_CONNECTION *OI_HCI_CONNECTION_HANDLE; +typedef struct _OI_HCI_CONNECTION* OI_HCI_CONNECTION_HANDLE; /** data type for HCI Error Code, as defined in oi_hcispec.h */ -typedef uint8_t OI_HCI_ERROR_CODE ; +typedef uint8_t OI_HCI_ERROR_CODE; /** * The Bluetooth device type is indicated by a 24-bit bitfield, represented as a @@ -198,39 +195,39 @@ typedef uint8_t OI_HCI_ERROR_CODE ; * specified in the file oi_bt_assigned_nos.h and in the Bluetooth "Assigned * Numbers" specification at http://www.bluetooth.org/assigned-numbers/. */ -typedef uint32_t OI_BT_DEVICE_CLASS ; +typedef uint32_t OI_BT_DEVICE_CLASS; /* Bits 0-1 contain format type. */ -#define OI_BT_DEV_CLASS_FORMAT_MASK 0x000003 +#define OI_BT_DEV_CLASS_FORMAT_MASK 0x000003 /* Bits 2-7 contain minor device class value. */ -#define OI_BT_DEV_CLASS_MINOR_DEVICE_MASK 0x0000FC +#define OI_BT_DEV_CLASS_MINOR_DEVICE_MASK 0x0000FC /* Bits 8-12 contain major device class value. */ -#define OI_BT_DEV_CLASS_MAJOR_DEVICE_MASK 0x001F00 +#define OI_BT_DEV_CLASS_MAJOR_DEVICE_MASK 0x001F00 /* Bits 13-23 contain major service class value. */ #define OI_BT_DEV_CLASS_MAJOR_SERVICE_MASK 0xFFE000 /** There is currently only one device class format defined, type 00. */ -#define OI_BT_DEV_CLASS_FORMAT_TYPE 00 +#define OI_BT_DEV_CLASS_FORMAT_TYPE 00 /* Bit 13 in device class indicates limited discoverability mode (GAP v2.0+EDR, * section 4.1.2.2) */ -#define OI_BT_DEV_CLASS_LIMITED_DISCO_BIT BIT13 +#define OI_BT_DEV_CLASS_LIMITED_DISCO_BIT BIT13 /** macro to test validity of the Device Class Format */ -#define OI_BT_VALID_DEVICE_CLASS_FORMAT(class) (OI_BT_DEV_CLASS_FORMAT_TYPE == ((class) & OI_BT_DEV_CLASS_FORMAT_MASK)) +#define OI_BT_VALID_DEVICE_CLASS_FORMAT(class) \ + (OI_BT_DEV_CLASS_FORMAT_TYPE == ((class) & OI_BT_DEV_CLASS_FORMAT_MASK)) /* the time between baseband clock ticks, currently 625 microseconds (one slot) */ #define OI_BT_TICK 625 /* some macros to convert to/from baseband clock ticks - no floating point! */ -#define OI_SECONDS_TO_BT_TICKS(secs) ((secs)*1600) -#define OI_BT_TICKS_TO_SECONDS(ticks) ((ticks)/1600) -#define OI_MSECS_TO_BT_TICKS(msecs) (((msecs)*8)/5) -#define OI_BT_TICKS_TO_MSECS(ticks) (((ticks)*5)/8) +#define OI_SECONDS_TO_BT_TICKS(secs) ((secs)*1600) +#define OI_BT_TICKS_TO_SECONDS(ticks) ((ticks) / 1600) +#define OI_MSECS_TO_BT_TICKS(msecs) (((msecs)*8) / 5) +#define OI_BT_TICKS_TO_MSECS(ticks) (((ticks)*5) / 8) /** EIR byte order */ -#define OI_EIR_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER - +#define OI_EIR_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #ifdef __cplusplus } diff --git a/embdrv/sbc/decoder/include/oi_codec_sbc.h b/embdrv/sbc/decoder/include/oi_codec_sbc.h index 31ecb2c58..61fe5109e 100644 --- a/embdrv/sbc/decoder/include/oi_codec_sbc.h +++ b/embdrv/sbc/decoder/include/oi_codec_sbc.h @@ -45,8 +45,8 @@ Declarations of codec functions, data types, and macros. * including this file, or else these includes will fail because the BM3 SDK is * not in the include path */ #ifndef _OI_CODEC_SBC_BM3DEFS_H -#include "oi_stddefs.h" #include "oi_status.h" +#include "oi_stddefs.h" #endif #include @@ -61,74 +61,90 @@ Declarations of codec functions, data types, and macros. #define SBC_MAX_ONE_CHANNEL_BPS 320000 #define SBC_MAX_TWO_CHANNEL_BPS 512000 - #define SBC_WBS_BITRATE 62000 #define SBC_WBS_BITPOOL 27 #define SBC_WBS_NROF_BLOCKS 16 #define SBC_WBS_FRAME_LEN 62 #define SBC_WBS_SAMPLES_PER_FRAME 128 - #define SBC_HEADER_LEN 4 -#define SBC_MAX_FRAME_LEN (SBC_HEADER_LEN + \ - ((SBC_MAX_BANDS * SBC_MAX_CHANNELS / 2) + \ - (SBC_MAX_BANDS + SBC_MAX_BLOCKS * SBC_MAX_BITPOOL + 7)/8)) -#define SBC_MAX_SAMPLES_PER_FRAME (SBC_MAX_BANDS * SBC_MAX_BLOCKS) +#define SBC_MAX_FRAME_LEN \ + (SBC_HEADER_LEN + \ + ((SBC_MAX_BANDS * SBC_MAX_CHANNELS / 2) + \ + (SBC_MAX_BANDS + SBC_MAX_BLOCKS * SBC_MAX_BITPOOL + 7) / 8)) +#define SBC_MAX_SAMPLES_PER_FRAME (SBC_MAX_BANDS * SBC_MAX_BLOCKS) -#define SBC_MAX_SCALEFACTOR_BYTES ((4*(SBC_MAX_CHANNELS * SBC_MAX_BANDS) + 7)/8) +#define SBC_MAX_SCALEFACTOR_BYTES \ + ((4 * (SBC_MAX_CHANNELS * SBC_MAX_BANDS) + 7) / 8) #define OI_SBC_SYNCWORD 0x9c #define OI_SBC_ENHANCED_SYNCWORD 0x9d /**@name Sampling frequencies */ /**@{*/ -/**< The sampling frequency is 16 kHz. One possible value for the @a frequency parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The sampling frequency is 16 kHz. One possible value for the @a frequency + * parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_FREQ_16000 0 -/**< The sampling frequency is 32 kHz. One possible value for the @a frequency parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The sampling frequency is 32 kHz. One possible value for the @a frequency + * parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_FREQ_32000 1 -/**< The sampling frequency is 44.1 kHz. One possible value for the @a frequency parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The sampling frequency is 44.1 kHz. One possible value for the @a frequency + * parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_FREQ_44100 2 -/**< The sampling frequency is 48 kHz. One possible value for the @a frequency parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The sampling frequency is 48 kHz. One possible value for the @a frequency + * parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_FREQ_48000 3 /**@}*/ /**@name Channel modes */ /**@{*/ -/**< The mode of the encoded channel is mono. One possible value for the @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The mode of the encoded channel is mono. One possible value for the @a mode + * parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_MONO 0 -/**< The mode of the encoded channel is dual-channel. One possible value for the @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The mode of the encoded channel is dual-channel. One possible value for the + * @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_DUAL_CHANNEL 1 -/**< The mode of the encoded channel is stereo. One possible value for the @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The mode of the encoded channel is stereo. One possible value for the @a + * mode parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_STEREO 2 -/**< The mode of the encoded channel is joint stereo. One possible value for the @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The mode of the encoded channel is joint stereo. One possible value for the + * @a mode parameter of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_JOINT_STEREO 3 /**@}*/ /**@name Subbands */ /**@{*/ -/**< The encoded stream has 4 subbands. One possible value for the @a subbands parameter of OI_CODEC_SBC_EncoderConfigure()*/ -#define SBC_SUBBANDS_4 0 -/**< The encoded stream has 8 subbands. One possible value for the @a subbands parameter of OI_CODEC_SBC_EncoderConfigure() */ -#define SBC_SUBBANDS_8 1 +/**< The encoded stream has 4 subbands. One possible value for the @a subbands + * parameter of OI_CODEC_SBC_EncoderConfigure()*/ +#define SBC_SUBBANDS_4 0 +/**< The encoded stream has 8 subbands. One possible value for the @a subbands + * parameter of OI_CODEC_SBC_EncoderConfigure() */ +#define SBC_SUBBANDS_8 1 /**@}*/ /**@name Block lengths */ /**@{*/ -/**< A block size of 4 blocks was used to encode the stream. One possible value for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ -#define SBC_BLOCKS_4 0 -/**< A block size of 8 blocks was used to encode the stream is. One possible value for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ -#define SBC_BLOCKS_8 1 -/**< A block size of 12 blocks was used to encode the stream. One possible value for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ -#define SBC_BLOCKS_12 2 -/**< A block size of 16 blocks was used to encode the stream. One possible value for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ -#define SBC_BLOCKS_16 3 +/**< A block size of 4 blocks was used to encode the stream. One possible value + * for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ +#define SBC_BLOCKS_4 0 +/**< A block size of 8 blocks was used to encode the stream is. One possible + * value for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ +#define SBC_BLOCKS_8 1 +/**< A block size of 12 blocks was used to encode the stream. One possible value + * for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ +#define SBC_BLOCKS_12 2 +/**< A block size of 16 blocks was used to encode the stream. One possible value + * for the @a blocks parameter of OI_CODEC_SBC_EncoderConfigure() */ +#define SBC_BLOCKS_16 3 /**@}*/ /**@name Bit allocation methods */ /**@{*/ -/**< The bit allocation method. One possible value for the @a loudness parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The bit allocation method. One possible value for the @a loudness parameter + * of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_LOUDNESS 0 -/**< The bit allocation method. One possible value for the @a loudness parameter of OI_CODEC_SBC_EncoderConfigure() */ +/**< The bit allocation method. One possible value for the @a loudness parameter + * of OI_CODEC_SBC_EncoderConfigure() */ #define SBC_SNR 1 /**@}*/ @@ -141,57 +157,59 @@ Declarations of codec functions, data types, and macros. typedef int16_t SBC_BUFFER_T; - /** Used internally. */ typedef struct { - uint16_t frequency; /**< The sampling frequency. Input parameter. */ - uint8_t freqIndex; - - uint8_t nrof_blocks; /**< The block size used to encode the stream. Input parameter. */ - uint8_t blocks; - - - uint8_t nrof_subbands; /**< The number of subbands of the encoded stream. Input parameter. */ - uint8_t subbands; - - uint8_t mode; /**< The mode of the encoded channel. Input parameter. */ - uint8_t nrof_channels; /**< The number of channels of the encoded stream. */ - - uint8_t alloc; /**< The bit allocation method. Input parameter. */ - uint8_t bitpool; /**< Size of the bit allocation pool used to encode the stream. Input parameter. */ - uint8_t crc; /**< Parity check byte used for error detection. */ - uint8_t join; /**< Whether joint stereo has been used. */ - uint8_t enhanced; - uint8_t min_bitpool; /**< This value is only used when encoding. SBC_MAX_BITPOOL if variable - bitpools are disallowed, otherwise the minimum bitpool size that will - be used by the bit allocator. */ - - uint8_t cachedInfo; /**< Information about the previous frame */ + uint16_t frequency; /**< The sampling frequency. Input parameter. */ + uint8_t freqIndex; + + uint8_t nrof_blocks; /**< The block size used to encode the stream. Input + parameter. */ + uint8_t blocks; + + uint8_t nrof_subbands; /**< The number of subbands of the encoded stream. + Input parameter. */ + uint8_t subbands; + + uint8_t mode; /**< The mode of the encoded channel. Input parameter. */ + uint8_t nrof_channels; /**< The number of channels of the encoded stream. */ + + uint8_t alloc; /**< The bit allocation method. Input parameter. */ + uint8_t bitpool; /**< Size of the bit allocation pool used to encode the + stream. Input parameter. */ + uint8_t crc; /**< Parity check byte used for error detection. */ + uint8_t join; /**< Whether joint stereo has been used. */ + uint8_t enhanced; + uint8_t min_bitpool; /**< This value is only used when encoding. + SBC_MAX_BITPOOL if variable + bitpools are disallowed, otherwise the minimum + bitpool size that will + be used by the bit allocator. */ + + uint8_t cachedInfo; /**< Information about the previous frame */ } OI_CODEC_SBC_FRAME_INFO; /** Used internally. */ typedef struct { - const OI_CHAR *codecInfo; - OI_CODEC_SBC_FRAME_INFO frameInfo; - int8_t scale_factor[SBC_MAX_CHANNELS*SBC_MAX_BANDS]; - uint32_t frameCount; - int32_t *subdata; - - SBC_BUFFER_T *filterBuffer[SBC_MAX_CHANNELS]; - int32_t filterBufferLen; - OI_UINT filterBufferOffset; - - union { - uint8_t uint8[SBC_MAX_CHANNELS*SBC_MAX_BANDS]; - uint32_t uint32[SBC_MAX_CHANNELS*SBC_MAX_BANDS/4]; - } bits; - uint8_t maxBitneed; /**< Running maximum bitneed */ - OI_BYTE formatByte; - uint8_t pcmStride; - uint8_t maxChannels; + const OI_CHAR* codecInfo; + OI_CODEC_SBC_FRAME_INFO frameInfo; + int8_t scale_factor[SBC_MAX_CHANNELS * SBC_MAX_BANDS]; + uint32_t frameCount; + int32_t* subdata; + + SBC_BUFFER_T* filterBuffer[SBC_MAX_CHANNELS]; + int32_t filterBufferLen; + OI_UINT filterBufferOffset; + + union { + uint8_t uint8[SBC_MAX_CHANNELS * SBC_MAX_BANDS]; + uint32_t uint32[SBC_MAX_CHANNELS * SBC_MAX_BANDS / 4]; + } bits; + uint8_t maxBitneed; /**< Running maximum bitneed */ + OI_BYTE formatByte; + uint8_t pcmStride; + uint8_t maxChannels; } OI_CODEC_SBC_COMMON_CONTEXT; - /* * A smaller value reduces RAM usage at the expense of increased CPU usage. * Values in the range 27..50 are recommended. Beyond 50 there is a diminishing @@ -206,29 +224,28 @@ typedef struct { * uint32_t decoderData[CODEC_DATA_WORDS(SBC_MAX_CHANNELS, * SBC_DECODER_FAST_SYNTHESIS_BUFFERS)]; * */ -#define CODEC_DATA_WORDS(numChannels, numBuffers) \ - ((\ - (sizeof(int32_t) * SBC_MAX_BLOCKS * (numChannels) * SBC_MAX_BANDS) \ - + (sizeof(SBC_BUFFER_T) * SBC_MAX_CHANNELS * SBC_MAX_BANDS * (numBuffers)) \ - + (sizeof (uint32_t) - 1) \ - ) / sizeof(uint32_t)) +#define CODEC_DATA_WORDS(numChannels, numBuffers) \ + (((sizeof(int32_t) * SBC_MAX_BLOCKS * (numChannels)*SBC_MAX_BANDS) + \ + (sizeof(SBC_BUFFER_T) * SBC_MAX_CHANNELS * SBC_MAX_BANDS * (numBuffers)) + \ + (sizeof(uint32_t) - 1)) / \ + sizeof(uint32_t)) /** Opaque parameter to decoding functions; maintains decoder context. */ typedef struct { - OI_CODEC_SBC_COMMON_CONTEXT common; - /* Boolean, set by OI_CODEC_SBC_DecoderLimit() */ - uint8_t limitFrameFormat; - uint8_t restrictSubbands; - uint8_t enhancedEnabled; - uint8_t bufferedBlocks; + OI_CODEC_SBC_COMMON_CONTEXT common; + /* Boolean, set by OI_CODEC_SBC_DecoderLimit() */ + uint8_t limitFrameFormat; + uint8_t restrictSubbands; + uint8_t enhancedEnabled; + uint8_t bufferedBlocks; } OI_CODEC_SBC_DECODER_CONTEXT; typedef struct { - uint32_t data[CODEC_DATA_WORDS(1, SBC_CODEC_FAST_FILTER_BUFFERS)]; + uint32_t data[CODEC_DATA_WORDS(1, SBC_CODEC_FAST_FILTER_BUFFERS)]; } OI_CODEC_SBC_CODEC_DATA_MONO; typedef struct { - uint32_t data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; + uint32_t data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; } OI_CODEC_SBC_CODEC_DATA_STEREO; /** @@ -252,11 +269,10 @@ typedef struct { * by an enhanced encoder, or there is a small possibility * for decoding glitches if synchronization were to be lost. */ -OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint32_t *decoderData, +OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint32_t* decoderData, uint32_t decoderDataBytes, - uint8_t maxChannels, - uint8_t pcmStride, + uint8_t maxChannels, uint8_t pcmStride, OI_BOOL enhanced); /** @@ -278,9 +294,8 @@ OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, * the requested number of subbands. * */ -OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context, - OI_BOOL enhanced, - uint8_t subbands); +OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BOOL enhanced, uint8_t subbands); /** * This function sets the decoder parameters for a raw decode where the decoder @@ -308,14 +323,10 @@ OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context, * * @param maxBitpool The maximum bitpool size for this context */ -OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - OI_BOOL enhanced, - uint8_t frequency, - uint8_t mode, - uint8_t subbands, - uint8_t blocks, - uint8_t alloc, - uint8_t maxBitpool); +OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw( + OI_CODEC_SBC_DECODER_CONTEXT* context, OI_BOOL enhanced, uint8_t frequency, + uint8_t mode, uint8_t subbands, uint8_t blocks, uint8_t alloc, + uint8_t maxBitpool); /** * Decode one SBC frame. The frame has no header bytes. The context must have @@ -348,12 +359,10 @@ OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context * written. Note that this differs from the semantics of * frameBytes. */ -OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint8_t bitpool, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes); +OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint8_t bitpool, const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes); /** * Decode one SBC frame. @@ -381,11 +390,10 @@ OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, * written. Note that this differs from the semantics of * frameBytes. */ -OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes); +OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes); /** * Calculate the number of SBC frames but don't decode. CRC's are not checked, @@ -396,8 +404,7 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, * @param frameBytes Number of bytes avaiable in the frameData buffer * */ -uint8_t OI_CODEC_SBC_FrameCount(OI_BYTE *frameData, - uint32_t frameBytes); +uint8_t OI_CODEC_SBC_FrameCount(OI_BYTE* frameData, uint32_t frameBytes); /** * Analyze an SBC frame but don't do the decode. @@ -416,9 +423,9 @@ uint8_t OI_CODEC_SBC_FrameCount(OI_BYTE *frameData, * operation. * */ -OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE **frameData, - uint32_t *frameBytes); +OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE** frameData, + uint32_t* frameBytes); /* Common functions */ @@ -430,8 +437,7 @@ OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, @return the length of an individual encoded frame in bytes */ -uint16_t OI_CODEC_SBC_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame); - +uint16_t OI_CODEC_SBC_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO* frame); /** * Calculate the maximum bitpool size that fits within a given frame length. @@ -441,8 +447,8 @@ uint16_t OI_CODEC_SBC_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame); * * @return the maximum bitpool that will fit in the specified frame length */ -uint16_t OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame, - uint16_t frameLen); +uint16_t OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO* frame, + uint16_t frameLen); /** Calculate the bit rate. @@ -452,7 +458,7 @@ uint16_t OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame, @return the approximate bit rate in bits per second, assuming that stream parameters are constant */ -uint32_t OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame); +uint32_t OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO* frame); /** Calculate decoded audio data length for one frame. @@ -462,7 +468,7 @@ uint32_t OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame); @return length of decoded audio data for a single frame, in bytes */ -uint16_t OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT *common); +uint16_t OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT* common); /** * Get the codec version text. @@ -470,8 +476,7 @@ uint16_t OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT *common); * @return pointer to text string containing codec version text * */ -OI_CHAR *OI_CODEC_Version(void); - +OI_CHAR* OI_CODEC_Version(void); /** @} @@ -494,7 +499,7 @@ extern const OI_CHAR* const OI_CODEC_SBC_AllocText[]; */ #ifdef OI_DEBUG -void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo); +void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO* frameInfo); #else #define OI_CODEC_SBC_DumpConfig(f) #endif @@ -507,7 +512,4 @@ void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo); } #endif - #endif /* _OI_CODEC_SBC_CORE_H */ - - diff --git a/embdrv/sbc/decoder/include/oi_codec_sbc_private.h b/embdrv/sbc/decoder/include/oi_codec_sbc_private.h index c497ad0ce..91d80f104 100644 --- a/embdrv/sbc/decoder/include/oi_codec_sbc_private.h +++ b/embdrv/sbc/decoder/include/oi_codec_sbc_private.h @@ -44,13 +44,21 @@ Function prototypes and macro definitions used internally by the codec. #ifdef CODEC_DEBUG #include -#define ERROR(x) do { printf x; printf("\n"); } while (0) +#define ERROR(x) \ + do { \ + printf x; \ + printf("\n"); \ + } while (0) #else #define ERROR(x) #endif #ifdef TRACE_EXECUTION -#define TRACE(x) do { printf x; printf("\n"); } while (0) +#define TRACE(x) \ + do { \ + printf x; \ + printf("\n"); \ + } while (0) #else #define TRACE(x) #endif @@ -75,40 +83,38 @@ Function prototypes and macro definitions used internally by the codec. #endif typedef union { - uint8_t uint8[SBC_MAX_BANDS]; - uint32_t uint32[SBC_MAX_BANDS / 4]; + uint8_t uint8[SBC_MAX_BANDS]; + uint32_t uint32[SBC_MAX_BANDS / 4]; } BITNEED_UNION1; typedef union { - uint8_t uint8[2 * SBC_MAX_BANDS]; - uint32_t uint32[2 * SBC_MAX_BANDS / 4]; + uint8_t uint8[2 * SBC_MAX_BANDS]; + uint32_t uint32[2 * SBC_MAX_BANDS / 4]; } BITNEED_UNION2; -static const uint16_t freq_values[] = { 16000, 32000, 44100, 48000 }; -static const uint8_t block_values[] = { 4, 8, 12, 16 }; -static const uint8_t channel_values[] = { 1, 2, 2, 2 }; -static const uint8_t band_values[] = { 4, 8 }; - +static const uint16_t freq_values[] = {16000, 32000, 44100, 48000}; +static const uint8_t block_values[] = {4, 8, 12, 16}; +static const uint8_t channel_values[] = {1, 2, 2, 2}; +static const uint8_t band_values[] = {4, 8}; #define TEST_MODE_SENTINEL "OINA" #define TEST_MODE_SENTINEL_LENGTH 4 /** Used internally. */ typedef struct { - union { - const uint8_t *r; - uint8_t *w; - } ptr; - uint32_t value; - OI_UINT bitPtr; + union { + const uint8_t* r; + uint8_t* w; + } ptr; + uint32_t value; + OI_UINT bitPtr; } OI_BITSTREAM; - #define VALID_INT16(x) (((x) >= OI_INT16_MIN) && ((x) <= OI_INT16_MAX)) #define VALID_INT32(x) (((x) >= OI_INT32_MIN) && ((x) <= OI_INT32_MAX)) #define DCTII_8_SHIFT_IN 0 -#define DCTII_8_SHIFT_OUT (16-DCTII_8_SHIFT_IN) +#define DCTII_8_SHIFT_OUT (16 - DCTII_8_SHIFT_IN) #define DCTII_8_SHIFT_0 (DCTII_8_SHIFT_OUT) #define DCTII_8_SHIFT_1 (DCTII_8_SHIFT_OUT) @@ -116,8 +122,8 @@ typedef struct { #define DCTII_8_SHIFT_3 (DCTII_8_SHIFT_OUT) #define DCTII_8_SHIFT_4 (DCTII_8_SHIFT_OUT) #define DCTII_8_SHIFT_5 (DCTII_8_SHIFT_OUT) -#define DCTII_8_SHIFT_6 (DCTII_8_SHIFT_OUT-1) -#define DCTII_8_SHIFT_7 (DCTII_8_SHIFT_OUT-2) +#define DCTII_8_SHIFT_6 (DCTII_8_SHIFT_OUT - 1) +#define DCTII_8_SHIFT_7 (DCTII_8_SHIFT_OUT - 2) #define DCT_SHIFT 15 @@ -127,104 +133,100 @@ typedef struct { #define DCTIII_8_SHIFT_IN 3 #define DCTIII_8_SHIFT_OUT 14 -OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common, - uint8_t *bitneeds, - OI_UINT ch, - OI_UINT *preferredBitpool); - -void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common, - BITNEED_UNION1 *bitneeds, - OI_UINT ch, - OI_UINT bitcount); +OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT* common, uint8_t* bitneeds, + OI_UINT ch, OI_UINT* preferredBitpool); +void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common, + BITNEED_UNION1* bitneeds, OI_UINT ch, + OI_UINT bitcount); -OI_INT adjustToFitBitpool(const OI_UINT bitpool, - uint32_t *bitneeds, - const OI_UINT subbands, - OI_UINT bitcount, - OI_UINT *excess); +OI_INT adjustToFitBitpool(const OI_UINT bitpool, uint32_t* bitneeds, + const OI_UINT subbands, OI_UINT bitcount, + OI_UINT* excess); -INLINE OI_INT allocAdjustedBits(uint8_t *dest, - OI_INT bits, - OI_INT excess); +INLINE OI_INT allocAdjustedBits(uint8_t* dest, OI_INT bits, OI_INT excess); -INLINE OI_INT allocExcessBits(uint8_t *dest, - OI_INT excess); +INLINE OI_INT allocExcessBits(uint8_t* dest, OI_INT excess); -PRIVATE uint32_t internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame); +PRIVATE uint32_t internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO* frame); -PRIVATE uint16_t internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame); +PRIVATE uint16_t internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO* frame); -void monoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common); +void monoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common); -typedef void (*BIT_ALLOC)(OI_CODEC_SBC_COMMON_CONTEXT *common); +typedef void (*BIT_ALLOC)(OI_CODEC_SBC_COMMON_CONTEXT* common); -PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint8_t bitpool, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes); +PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint8_t bitpool, const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes); -INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint32_t *decoderData, +INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint32_t* decoderData, uint32_t decoderDataBytes, - OI_BYTE maxChannels, - OI_BYTE pcmStride, + OI_BYTE maxChannels, OI_BYTE pcmStride, OI_BOOL enhanced); -INLINE uint16_t OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_); +INLINE uint16_t OI_SBC_CalculateFrameAndHeaderlen( + OI_CODEC_SBC_FRAME_INFO* frame, OI_UINT* headerLen_); -PRIVATE uint32_t OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame); +PRIVATE uint32_t OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO* frame); -PRIVATE void OI_SBC_ComputeBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *frame); -PRIVATE uint8_t OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYTE const *data); +PRIVATE void OI_SBC_ComputeBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* frame); +PRIVATE uint8_t OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO* frame, + OI_BYTE const* data); /* Transform functions */ -PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount); -PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, int32_t const * RESTRICT in); -PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(int16_t *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift); - -INLINE void dct3_4(int32_t * RESTRICT out, int32_t const * RESTRICT in); +PRIVATE void shift_buffer(SBC_BUFFER_T* dest, SBC_BUFFER_T* src, + OI_UINT wordCount); +PRIVATE void cosineModulateSynth4(SBC_BUFFER_T* RESTRICT out, + int32_t const* RESTRICT in); +PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum( + int16_t* pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift); + +INLINE void dct3_4(int32_t* RESTRICT out, int32_t const* RESTRICT in); PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40], - int16_t *pcm, - OI_UINT strideShift, + int16_t* pcm, OI_UINT strideShift, int32_t subband[4]); -INLINE void dct3_8(int32_t * RESTRICT out, int32_t const * RESTRICT in); +INLINE void dct3_8(int32_t* RESTRICT out, int32_t const* RESTRICT in); PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80], - int16_t *pcm, - OI_UINT strideShift, + int16_t* pcm, OI_UINT strideShift, int32_t subband[8]); #ifdef SBC_ENHANCED -PRIVATE void analyze8_enhanced_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 112], - int16_t *pcm, - OI_UINT strideShift, - int32_t subband[8]); +PRIVATE void analyze8_enhanced_generated( + SBC_BUFFER_T analysisBuffer[RESTRICT 112], int16_t* pcm, + OI_UINT strideShift, int32_t subband[8]); #endif /* Decoder functions */ -INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *data); -PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *b, OI_BITSTREAM *bs); -PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *common, OI_BITSTREAM *ob); -PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT *common, OI_BITSTREAM *global_bs); -PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT start_block, OI_UINT nrof_blocks); +INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT* common, + const OI_BYTE* data); +PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT* common, + const OI_BYTE* b, OI_BITSTREAM* bs); +PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT* common, + OI_BITSTREAM* ob); +PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT* common, + OI_BITSTREAM* global_bs); +PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + int16_t* pcm, OI_UINT start_block, + OI_UINT nrof_blocks); INLINE int32_t OI_SBC_Dequant(uint32_t raw, OI_UINT scale_factor, OI_UINT bits); -PRIVATE OI_BOOL OI_SBC_ExamineCommandPacket(OI_CODEC_SBC_DECODER_CONTEXT *context, const OI_BYTE *data, uint32_t len); -PRIVATE void OI_SBC_GenerateTestSignal(int16_t pcmData[][2], uint32_t sampleCount); - -PRIVATE void OI_SBC_ExpandFrameFields(OI_CODEC_SBC_FRAME_INFO *frame); -PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common, - uint32_t *codecDataAligned, +PRIVATE OI_BOOL OI_SBC_ExamineCommandPacket( + OI_CODEC_SBC_DECODER_CONTEXT* context, const OI_BYTE* data, uint32_t len); +PRIVATE void OI_SBC_GenerateTestSignal(int16_t pcmData[][2], + uint32_t sampleCount); + +PRIVATE void OI_SBC_ExpandFrameFields(OI_CODEC_SBC_FRAME_INFO* frame); +PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT* common, + uint32_t* codecDataAligned, uint32_t codecDataBytes, - uint8_t maxChannels, - uint8_t pcmStride); + uint8_t maxChannels, uint8_t pcmStride); /** @} */ #endif /* _OI_CODEC_SBC_PRIVATE_H */ - diff --git a/embdrv/sbc/decoder/include/oi_common.h b/embdrv/sbc/decoder/include/oi_common.h index 0864ad252..a4cf20bf7 100644 --- a/embdrv/sbc/decoder/include/oi_common.h +++ b/embdrv/sbc/decoder/include/oi_common.h @@ -34,11 +34,10 @@ ******************************************************************************/ #include "oi_bt_spec.h" -#include "oi_stddefs.h" +#include "oi_osinterface.h" #include "oi_status.h" +#include "oi_stddefs.h" #include "oi_time.h" -#include "oi_osinterface.h" - /*****************************************************************************/ #endif /* _OI_COMMON_H */ diff --git a/embdrv/sbc/decoder/include/oi_cpu_dep.h b/embdrv/sbc/decoder/include/oi_cpu_dep.h index 2fc81273e..21faf5e97 100644 --- a/embdrv/sbc/decoder/include/oi_cpu_dep.h +++ b/embdrv/sbc/decoder/include/oi_cpu_dep.h @@ -54,75 +54,86 @@ extern "C" { * @{ */ -#define OI_CPU_X86 1 /**< x86 processor family */ -#define OI_CPU_ARM 2 /**< ARM processor family. - @deprecated Use #OI_CPU_ARM7_LEND or - #OI_CPU_ARM7_BEND. */ -#define OI_CPU_ARC 3 /**< ARC processor family. - @deprecated Use #OI_CPU_ARC_LEND or - #OI_CPU_ARC_BEND. */ -#define OI_CPU_SH3 4 /**< Hitachi SH-3 processor family */ -#define OI_CPU_H8 5 /**< Hitachi H8 processor family */ -#define OI_CPU_MIPS 6 /**< MIPS processor family */ -#define OI_CPU_SPARC 7 /**< SPARC processor family */ -#define OI_CPU_M68000 8 /**< Motorola M68000 processor family */ -#define OI_CPU_PPC 9 /**< PowerPC (PPC) processor family */ -#define OI_CPU_SH4_7750 10 /**< Hitachi SH7750 series in SH-4 processor family */ -#define OI_CPU_SH2 11 /**< Hitachi SH-2 processor family */ -#define OI_CPU_ARM7_LEND 12 /**< ARM7, little-endian */ -#define OI_CPU_ARM7_BEND 13 /**< ARM7, big-endian */ -#define OI_CPU_GDM1202 14 /**< GCT GDM1202 */ -#define OI_CPU_ARC_LEND 15 /**< ARC processor family, little-endian */ -#define OI_CPU_ARC_BEND 16 /**< ARC processor family, big-endian */ -#define OI_CPU_M30833F 17 /**< Mitsubishi M308 processor family */ -#define OI_CPU_CR16C 18 /**< National Semiconductor 16 bit processor family */ -#define OI_CPU_M64111 19 /**< Renesas M64111 processor (M32R family) */ -#define OI_CPU_ARMV5_LEND 20 //*< ARM5, little-endian */ +#define OI_CPU_X86 1 /**< x86 processor family */ +#define OI_CPU_ARM \ + 2 /**< ARM processor family. \ + @deprecated Use #OI_CPU_ARM7_LEND or \ + #OI_CPU_ARM7_BEND. */ +#define OI_CPU_ARC \ + 3 /**< ARC processor family. \ + @deprecated Use #OI_CPU_ARC_LEND or \ + #OI_CPU_ARC_BEND. */ +#define OI_CPU_SH3 4 /**< Hitachi SH-3 processor family */ +#define OI_CPU_H8 5 /**< Hitachi H8 processor family */ +#define OI_CPU_MIPS 6 /**< MIPS processor family */ +#define OI_CPU_SPARC 7 /**< SPARC processor family */ +#define OI_CPU_M68000 8 /**< Motorola M68000 processor family */ +#define OI_CPU_PPC 9 /**< PowerPC (PPC) processor family */ +#define OI_CPU_SH4_7750 \ + 10 /**< Hitachi SH7750 series in SH-4 processor family */ +#define OI_CPU_SH2 11 /**< Hitachi SH-2 processor family */ +#define OI_CPU_ARM7_LEND 12 /**< ARM7, little-endian */ +#define OI_CPU_ARM7_BEND 13 /**< ARM7, big-endian */ +#define OI_CPU_GDM1202 14 /**< GCT GDM1202 */ +#define OI_CPU_ARC_LEND 15 /**< ARC processor family, little-endian */ +#define OI_CPU_ARC_BEND 16 /**< ARC processor family, big-endian */ +#define OI_CPU_M30833F 17 /**< Mitsubishi M308 processor family */ +#define OI_CPU_CR16C 18 /**< National Semiconductor 16 bit processor family */ +#define OI_CPU_M64111 19 /**< Renesas M64111 processor (M32R family) */ +#define OI_CPU_ARMV5_LEND 20 //*< ARM5, little-endian */ #define OI_CPU_TYPE 12 #ifndef OI_CPU_TYPE - #error "OI_CPU_TYPE type not defined" +#error "OI_CPU_TYPE type not defined" #endif /**@}*/ - /** @name Definitions indicating byte-wise endianness of target CPU * @{ */ -#define OI_BIG_ENDIAN_BYTE_ORDER 0 /**< Multiple-byte values are stored in memory beginning with the most significant byte at the lowest address. */ -#define OI_LITTLE_ENDIAN_BYTE_ORDER 1 /**< Multiple-byte values are stored in memory beginning with the least significant byte at the lowest address. */ +#define OI_BIG_ENDIAN_BYTE_ORDER \ + 0 /**< Multiple-byte values are stored in memory beginning with the most \ + significant byte at the lowest address. */ +#define OI_LITTLE_ENDIAN_BYTE_ORDER \ + 1 /**< Multiple-byte values are stored in memory beginning with the least \ + significant byte at the lowest address. */ /**@}*/ - /** @name CPU/compiler-independent primitive data type definitions * @{ */ -typedef int OI_BOOL; /**< Boolean values use native integer data type for target CPU. */ -typedef int OI_INT; /**< Integer values use native integer data type for target CPU. */ -typedef unsigned int OI_UINT; /**< Unsigned integer values use native unsigned integer data type for target CPU. */ -typedef unsigned char OI_BYTE; /**< Raw bytes type uses native character data type for target CPU. */ -typedef uint32_t OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */ +typedef int + OI_BOOL; /**< Boolean values use native integer data type for target CPU. */ +typedef int + OI_INT; /**< Integer values use native integer data type for target CPU. */ +typedef unsigned int OI_UINT; /**< Unsigned integer values use native unsigned + integer data type for target CPU. */ +typedef unsigned char OI_BYTE; /**< Raw bytes type uses native character data + type for target CPU. */ +typedef uint32_t OI_ELEMENT_UNION; /**< Type for first element of a union to + support all data types up to pointer + width. */ /**@}*/ - - /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_X86 +#if OI_CPU_TYPE == OI_CPU_X86 -#define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< x86 platform byte ordering is little-endian */ +#define OI_CPU_BYTE_ORDER \ + OI_LITTLE_ENDIAN_BYTE_ORDER /**< x86 platform byte ordering is little-endian \ + */ #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARM +#if OI_CPU_TYPE == OI_CPU_ARM /* This CPU type is deprecated (removed from use). Instead, use OI_CPU_ARM7_LEND * or OI_CPU_ARM7_BEND for little-endian or big-endian configurations of the * ARM7, respectively. */ @@ -140,126 +151,133 @@ typedef uint32_t OI_ELEMENT_UNION; /**< Type for first element of a union to sup /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_SH3 +#if OI_CPU_TYPE == OI_CPU_SH3 /* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness specified to the compiler on the command line. */ #if defined(_LIT) - #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte ordering is little-endian. */ +#define OI_CPU_BYTE_ORDER \ + OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte \ + ordering is little-endian. */ #elif defined(_BIG) - #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte ordering is big-endian. */ +#define OI_CPU_BYTE_ORDER \ + OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte \ + ordering is big-endian. */ #else - #error SH compiler endianness undefined +#error SH compiler endianness undefined #endif #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_SH2 +#if OI_CPU_TYPE == OI_CPU_SH2 -#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< SH-2 platform byte ordering is big-endian. */ +#define OI_CPU_BYTE_ORDER \ + OI_BIG_ENDIAN_BYTE_ORDER /**< SH-2 platform byte ordering is big-endian. */ #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_H8 +#if OI_CPU_TYPE == OI_CPU_H8 #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #error basic types not defined #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_MIPS +#if OI_CPU_TYPE == OI_CPU_MIPS #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_SPARC +#if OI_CPU_TYPE == OI_CPU_SPARC #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #error basic types not defined #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_M68000 -#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< M68000 platform byte ordering is big-endian. */ +#if OI_CPU_TYPE == OI_CPU_M68000 +#define OI_CPU_BYTE_ORDER \ + OI_BIG_ENDIAN_BYTE_ORDER /**< M68000 platform byte ordering is big-endian. \ + */ #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_PPC +#if OI_CPU_TYPE == OI_CPU_PPC #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_SH4_7750 -#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< SH7750 platform byte ordering is big-endian. */ +#if OI_CPU_TYPE == OI_CPU_SH4_7750 +#define OI_CPU_BYTE_ORDER \ + OI_BIG_ENDIAN_BYTE_ORDER /**< SH7750 platform byte ordering is big-endian. \ + */ #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARM7_LEND +#if OI_CPU_TYPE == OI_CPU_ARM7_LEND #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARM7_BEND +#if OI_CPU_TYPE == OI_CPU_ARM7_BEND #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_GDM1202 +#if OI_CPU_TYPE == OI_CPU_GDM1202 #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARC_LEND +#if OI_CPU_TYPE == OI_CPU_ARC_LEND #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARC_BEND +#if OI_CPU_TYPE == OI_CPU_ARC_BEND #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_M30833F +#if OI_CPU_TYPE == OI_CPU_M30833F #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_CR16C +#if OI_CPU_TYPE == OI_CPU_CR16C #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_M64111 +#if OI_CPU_TYPE == OI_CPU_M64111 #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ -#if OI_CPU_TYPE==OI_CPU_ARMV5_LEND +#if OI_CPU_TYPE == OI_CPU_ARMV5_LEND #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER #endif /******************************************************************************/ - #ifndef OI_CPU_BYTE_ORDER - #error "Byte order (endian-ness) not defined" +#error "Byte order (endian-ness) not defined" #endif - /**@}*/ #ifdef __cplusplus diff --git a/embdrv/sbc/decoder/include/oi_modules.h b/embdrv/sbc/decoder/include/oi_modules.h index f0c5b664c..3c2028500 100644 --- a/embdrv/sbc/decoder/include/oi_modules.h +++ b/embdrv/sbc/decoder/include/oi_modules.h @@ -30,7 +30,6 @@ $Revision: #1 $ ******************************************************************************/ - /** \addtogroup Misc Miscellaneous APIs */ /**@{*/ @@ -38,7 +37,6 @@ extern "C" { #endif - /** * This enumeration lists constants for referencing the components of * the BLUEmagic 3.0 protocol stack, profiles, and other functionalities. @@ -53,98 +51,108 @@ extern "C" { */ typedef enum { - /* profiles and protocols --> Updates to oi_debug.c and oi_config_table.c */ - - /* XX --> Keep Enum values up-to-date! */ - OI_MODULE_AT, /**< 00 AT command processing */ - OI_MODULE_A2DP, /**< 01 Advanced Audio Distribution Profile */ - OI_MODULE_AVCTP, /**< 02 Audio-Visual Control Transport Profile */ - OI_MODULE_AVDTP, /**< 03 Audio-Visual Distribution Protocol */ - OI_MODULE_AVRCP, /**< 04 Audio-Visual Remote Control Profile */ - OI_MODULE_BIP_CLI, /**< 05 Basic Imaging Profile protocol client */ - OI_MODULE_BIP_SRV, /**< 06 Basic Imaging Profile protocol server */ - OI_MODULE_BNEP, /**< 07 Bluetooth Network Encapsulation Protocol */ - OI_MODULE_BPP_SENDER, /**< 08 Basic Printing Profile */ - OI_MODULE_BPP_PRINTER, /**< 09 Basic Printing Profile */ - OI_MODULE_CTP, /**< 10 Cordless Telephony Profile */ - OI_MODULE_DUN, /**< 11 Dial-Up Networking Profile */ - OI_MODULE_FAX, /**< 12 Fax Profile */ - OI_MODULE_FTP_CLI, /**< 13 File Transfer Profile protocol client */ - OI_MODULE_FTP_SRV, /**< 14 File Transfer Profile protocol server */ - OI_MODULE_HANDSFREE, /**< 15 Hands-Free Profile */ - OI_MODULE_HANDSFREE_AG, /**< 16 Hands-Free Profile */ - OI_MODULE_HCRP_CLI, /**< 17 Hardcopy Cable Replacement Profile */ - OI_MODULE_HCRP_SRV, /**< 18 Hardcopy Cable Replacement Profile */ - OI_MODULE_HEADSET, /**< 19 Headset Profile */ - OI_MODULE_HEADSET_AG, /**< 20 Headset Profile */ - OI_MODULE_HID, /**< 21 Human Interface Device profile */ - OI_MODULE_INTERCOM, /**< 22 Intercom Profile */ - OI_MODULE_OBEX_CLI, /**< 23 OBEX protocol client, Generic Object Exchange Profile */ - OI_MODULE_OBEX_SRV, /**< 24 OBEX protocol server, Generic Object Exchange Profile */ - OI_MODULE_OPP_CLI, /**< 25 Object Push Profile protocol client */ - OI_MODULE_OPP_SRV, /**< 26 Object Push Profile protocol server */ - OI_MODULE_PAN, /**< 27 PAN profile */ - OI_MODULE_PBAP_CLI, /**< 28 Phonebook Access Profile client */ - OI_MODULE_PBAP_SRV, /**< 29 Phonebook Access Profile server */ - OI_MODULE_SAP_CLI, /**< 30 SIM Access Profile */ - OI_MODULE_SAP_SRV, /**< 31 SIM Access Profile */ - OI_MODULE_SPP, /**< 32 Serial Port Profile */ - OI_MODULE_SYNC_CLI, /**< 33 Synchronization Profile */ - OI_MODULE_SYNC_SRV, /**< 34 Synchronization Profile */ - OI_MODULE_SYNC_CMD_CLI, /**< 35 Synchronization Profile */ - OI_MODULE_SYNC_CMD_SRV, /**< 36 Synchronization Profile */ - OI_MODULE_SYNCML, /**< 37 SyncML Profile */ - OI_MODULE_TCS, /**< 38 TCS Binary */ - OI_MODULE_VDP, /**< 39 Video Distribution Profile */ - - /* corestack components --> Updates to oi_debug.c and oi_config_table.c */ - - OI_MODULE_COMMON_CONFIG, /**< 40 Common configuration, module has no meaning other than for config struct */ - OI_MODULE_CMDCHAIN, /**< 41 Command chaining utility */ - OI_MODULE_DISPATCH, /**< 42 Dispatcher */ - OI_MODULE_DATAELEM, /**< 43 Data Elements, marshaller */ - OI_MODULE_DEVMGR, /**< 44 Device Manager */ - OI_MODULE_DEVMGR_MODES, /**< 45 Device Manager connectability/discoverability modes */ - OI_MODULE_HCI, /**< 46 Host Controller Interface command layer */ - OI_MODULE_L2CAP, /**< 47 L2CAP */ - OI_MODULE_MEMMGR, /**< 48 modules that do memory management */ - OI_MODULE_POLICYMGR, /**< 49 Policy Manager */ - OI_MODULE_RFCOMM, /**< 50 RFCOMM */ - OI_MODULE_RFCOMM_SD, /**< 51 RFCOMM Service discovery */ - OI_MODULE_SDP_CLI, /**< 52 Service Discovery Protocol client */ - OI_MODULE_SDP_SRV, /**< 53 Service Discovery Protocol server */ - OI_MODULE_SDPDB, /**< 54 Service Discovery Protocol database */ - OI_MODULE_SECMGR, /**< 55 Security Manager */ - OI_MODULE_SNIFFLOG, /**< 56 sniff log */ - OI_MODULE_SUPPORT, /**< 57 support functions, including CThru Dispatcher, time functions, and stack initialization */ - OI_MODULE_TRANSPORT, /**< 58 transport layer between HCI command layer and driver */ - OI_MODULE_TEST, /**< 59 used to debug output from internal test programs */ - OI_MODULE_XML, /**< 60 XML/CSS parser */ - - OI_MODULE_DI, /**< 61 Device Identification Profile */ - - // bhapi components --> Updates to oi_debug.c - - OI_MODULE_BHAPI, /**< 62 BLUEmagic Host API generic */ - OI_MODULE_BHCLI, /**< 63 BLUEmagic Host API client side */ - OI_MODULE_BHSRV, /**< 64 BLUEmagic Host API server side */ - OI_MODULE_MSGQ, /**< 65 module that handles message queuing */ - OI_MODULE_BHAPI_TRANSPORT, /**< 66 module that handles message queuing */ - OI_MODULE_BLST_SRV, /**< 67 module that provides server side BHAPI Lightweight Serial Transport */ - OI_MODULE_BLST_CLI, /**< 68 module that provides client side BHAPI Lightweight Serial Transport */ - - // OEM files --> Updates to oi_debug.c - OI_MODULE_OEM, /**< 69 Application Memory allocation */ - - // Application glue --> Updates to oi_debug.c - OI_MODULE_APP, /**< 70 Application Memory allocation */ - - /* various pieces of code depend on these last 2 elements occuring in a specific order: - OI_MODULE_ALL must be the 2nd to last element - OI_MODULE_UNKNOWN must be the last element - */ - OI_MODULE_ALL, /**< 71 special value identifying all modules - used for control of debug print statements */ - OI_MODULE_UNKNOWN /**< 72 special value - used for debug print statements */ + /* profiles and protocols --> Updates to oi_debug.c and oi_config_table.c */ + + /* XX --> Keep Enum values up-to-date! */ + OI_MODULE_AT, /**< 00 AT command processing */ + OI_MODULE_A2DP, /**< 01 Advanced Audio Distribution Profile */ + OI_MODULE_AVCTP, /**< 02 Audio-Visual Control Transport Profile */ + OI_MODULE_AVDTP, /**< 03 Audio-Visual Distribution Protocol */ + OI_MODULE_AVRCP, /**< 04 Audio-Visual Remote Control Profile */ + OI_MODULE_BIP_CLI, /**< 05 Basic Imaging Profile protocol client */ + OI_MODULE_BIP_SRV, /**< 06 Basic Imaging Profile protocol server */ + OI_MODULE_BNEP, /**< 07 Bluetooth Network Encapsulation Protocol */ + OI_MODULE_BPP_SENDER, /**< 08 Basic Printing Profile */ + OI_MODULE_BPP_PRINTER, /**< 09 Basic Printing Profile */ + OI_MODULE_CTP, /**< 10 Cordless Telephony Profile */ + OI_MODULE_DUN, /**< 11 Dial-Up Networking Profile */ + OI_MODULE_FAX, /**< 12 Fax Profile */ + OI_MODULE_FTP_CLI, /**< 13 File Transfer Profile protocol client */ + OI_MODULE_FTP_SRV, /**< 14 File Transfer Profile protocol server */ + OI_MODULE_HANDSFREE, /**< 15 Hands-Free Profile */ + OI_MODULE_HANDSFREE_AG, /**< 16 Hands-Free Profile */ + OI_MODULE_HCRP_CLI, /**< 17 Hardcopy Cable Replacement Profile */ + OI_MODULE_HCRP_SRV, /**< 18 Hardcopy Cable Replacement Profile */ + OI_MODULE_HEADSET, /**< 19 Headset Profile */ + OI_MODULE_HEADSET_AG, /**< 20 Headset Profile */ + OI_MODULE_HID, /**< 21 Human Interface Device profile */ + OI_MODULE_INTERCOM, /**< 22 Intercom Profile */ + OI_MODULE_OBEX_CLI, /**< 23 OBEX protocol client, Generic Object Exchange + Profile */ + OI_MODULE_OBEX_SRV, /**< 24 OBEX protocol server, Generic Object Exchange + Profile */ + OI_MODULE_OPP_CLI, /**< 25 Object Push Profile protocol client */ + OI_MODULE_OPP_SRV, /**< 26 Object Push Profile protocol server */ + OI_MODULE_PAN, /**< 27 PAN profile */ + OI_MODULE_PBAP_CLI, /**< 28 Phonebook Access Profile client */ + OI_MODULE_PBAP_SRV, /**< 29 Phonebook Access Profile server */ + OI_MODULE_SAP_CLI, /**< 30 SIM Access Profile */ + OI_MODULE_SAP_SRV, /**< 31 SIM Access Profile */ + OI_MODULE_SPP, /**< 32 Serial Port Profile */ + OI_MODULE_SYNC_CLI, /**< 33 Synchronization Profile */ + OI_MODULE_SYNC_SRV, /**< 34 Synchronization Profile */ + OI_MODULE_SYNC_CMD_CLI, /**< 35 Synchronization Profile */ + OI_MODULE_SYNC_CMD_SRV, /**< 36 Synchronization Profile */ + OI_MODULE_SYNCML, /**< 37 SyncML Profile */ + OI_MODULE_TCS, /**< 38 TCS Binary */ + OI_MODULE_VDP, /**< 39 Video Distribution Profile */ + + /* corestack components --> Updates to oi_debug.c and oi_config_table.c */ + + OI_MODULE_COMMON_CONFIG, /**< 40 Common configuration, module has no meaning + other than for config struct */ + OI_MODULE_CMDCHAIN, /**< 41 Command chaining utility */ + OI_MODULE_DISPATCH, /**< 42 Dispatcher */ + OI_MODULE_DATAELEM, /**< 43 Data Elements, marshaller */ + OI_MODULE_DEVMGR, /**< 44 Device Manager */ + OI_MODULE_DEVMGR_MODES, /**< 45 Device Manager connectability/discoverability + modes */ + OI_MODULE_HCI, /**< 46 Host Controller Interface command layer */ + OI_MODULE_L2CAP, /**< 47 L2CAP */ + OI_MODULE_MEMMGR, /**< 48 modules that do memory management */ + OI_MODULE_POLICYMGR, /**< 49 Policy Manager */ + OI_MODULE_RFCOMM, /**< 50 RFCOMM */ + OI_MODULE_RFCOMM_SD, /**< 51 RFCOMM Service discovery */ + OI_MODULE_SDP_CLI, /**< 52 Service Discovery Protocol client */ + OI_MODULE_SDP_SRV, /**< 53 Service Discovery Protocol server */ + OI_MODULE_SDPDB, /**< 54 Service Discovery Protocol database */ + OI_MODULE_SECMGR, /**< 55 Security Manager */ + OI_MODULE_SNIFFLOG, /**< 56 sniff log */ + OI_MODULE_SUPPORT, /**< 57 support functions, including CThru Dispatcher, time + functions, and stack initialization */ + OI_MODULE_TRANSPORT, /**< 58 transport layer between HCI command layer and + driver */ + OI_MODULE_TEST, /**< 59 used to debug output from internal test programs */ + OI_MODULE_XML, /**< 60 XML/CSS parser */ + + OI_MODULE_DI, /**< 61 Device Identification Profile */ + + // bhapi components --> Updates to oi_debug.c + + OI_MODULE_BHAPI, /**< 62 BLUEmagic Host API generic */ + OI_MODULE_BHCLI, /**< 63 BLUEmagic Host API client side */ + OI_MODULE_BHSRV, /**< 64 BLUEmagic Host API server side */ + OI_MODULE_MSGQ, /**< 65 module that handles message queuing */ + OI_MODULE_BHAPI_TRANSPORT, /**< 66 module that handles message queuing */ + OI_MODULE_BLST_SRV, /**< 67 module that provides server side BHAPI Lightweight + Serial Transport */ + OI_MODULE_BLST_CLI, /**< 68 module that provides client side BHAPI Lightweight + Serial Transport */ + + // OEM files --> Updates to oi_debug.c + OI_MODULE_OEM, /**< 69 Application Memory allocation */ + + // Application glue --> Updates to oi_debug.c + OI_MODULE_APP, /**< 70 Application Memory allocation */ + + /* various pieces of code depend on these last 2 elements occuring in a + specific order: + OI_MODULE_ALL must be the 2nd to last element + OI_MODULE_UNKNOWN must be the last element + */ + OI_MODULE_ALL, /**< 71 special value identifying all modules - used for + control of debug print statements */ + OI_MODULE_UNKNOWN /**< 72 special value - used for debug print statements */ } OI_MODULE; /** @@ -152,15 +160,13 @@ typedef enum { * are special values that are not actually modules. * Used for debug print and memmgr profiling */ -#define OI_NUM_MODULES OI_MODULE_ALL - +#define OI_NUM_MODULES OI_MODULE_ALL /** * This constant is the number of profile and core components. It is used to * size the initialization and configuration tables. */ -#define OI_NUM_STACK_MODULES OI_MODULE_BHAPI - +#define OI_NUM_STACK_MODULES OI_MODULE_BHAPI #ifdef __cplusplus } @@ -169,4 +175,3 @@ typedef enum { /**@}*/ #endif /* _OI_MODULES_H */ - diff --git a/embdrv/sbc/decoder/include/oi_osinterface.h b/embdrv/sbc/decoder/include/oi_osinterface.h index 2f716e549..c0a3ff15a 100644 --- a/embdrv/sbc/decoder/include/oi_osinterface.h +++ b/embdrv/sbc/decoder/include/oi_osinterface.h @@ -34,10 +34,10 @@ $Revision: #1 $ ******************************************************************************/ +#include "oi_modules.h" +#include "oi_status.h" #include "oi_stddefs.h" #include "oi_time.h" -#include "oi_status.h" -#include "oi_modules.h" /** \addtogroup Misc Miscellaneous APIs */ /**@{*/ @@ -46,7 +46,6 @@ extern "C" { #endif - /** * Terminates execution. * @@ -77,7 +76,6 @@ void OI_LogError(OI_MODULE module, OI_INT lineno, OI_STATUS status); */ void OI_InitDebugCodeHandler(void); - /** * This function reads the time from the real time clock. * @@ -87,7 +85,7 @@ void OI_InitDebugCodeHandler(void); * @param[out] now Pointer to the buffer to which the current * time will be returned */ -void OI_Time_Now(OI_TIME *now); +void OI_Time_Now(OI_TIME* now); /** * This function causes the current thread to sleep for the @@ -105,17 +103,16 @@ void OI_Time_Now(OI_TIME *now); */ void OI_Sleep(uint32_t milliseconds); - /** * Defines for message type codes. */ -#define OI_MSG_CODE_APPLICATION 0 /**< Application output */ -#define OI_MSG_CODE_ERROR 1 /**< Error message output */ -#define OI_MSG_CODE_WARNING 2 /**< Warning message output */ -#define OI_MSG_CODE_TRACE 3 /**< User API function trace output */ -#define OI_MSG_CODE_PRINT1 4 /**< Catagory 1 debug print output */ -#define OI_MSG_CODE_PRINT2 5 /**< Catagory 2 debug print output */ -#define OI_MSG_CODE_HEADER 6 /**< Error/Debug output header */ +#define OI_MSG_CODE_APPLICATION 0 /**< Application output */ +#define OI_MSG_CODE_ERROR 1 /**< Error message output */ +#define OI_MSG_CODE_WARNING 2 /**< Warning message output */ +#define OI_MSG_CODE_TRACE 3 /**< User API function trace output */ +#define OI_MSG_CODE_PRINT1 4 /**< Catagory 1 debug print output */ +#define OI_MSG_CODE_PRINT2 5 /**< Catagory 2 debug print output */ +#define OI_MSG_CODE_HEADER 6 /**< Error/Debug output header */ /** * This function is used to indicate the type of text being output with @@ -135,7 +132,7 @@ void OI_SetMsgCode(uint8_t code); * * @param str String to print */ -void OI_Print(OI_CHAR const *str); +void OI_Print(OI_CHAR const* str); /** * In cases where OI_Print() is sending output to a logfile in addition to @@ -150,12 +147,12 @@ void OI_Print(OI_CHAR const *str); * @param str Console input string */ -void OI_Print_ConsoleInput(OI_CHAR const *str); +void OI_Print_ConsoleInput(OI_CHAR const* str); /** * This function computes the CRC16 of the program image. */ -uint16_t OI_ProgramImageCRC16(void); +uint16_t OI_ProgramImageCRC16(void); /** * Writes an integer to stdout in hex. This macro is intended @@ -166,16 +163,19 @@ uint16_t OI_ProgramImageCRC16(void); * @param n the integer to print */ -#define OI_Print_Int(n) \ -{ \ +#define OI_Print_Int(n) \ + { \ static const OI_CHAR _digits[] = "0123456789ABCDEF"; \ - OI_CHAR _buf[9]; \ - OI_CHAR *_str = &_buf[8]; \ - uint32_t _i = n; \ - *_str = 0; \ - do { *(--_str) = _digits[(_i & 0xF)]; _i >>= 4; } while (_i); \ - OI_Print(_str); \ -} + OI_CHAR _buf[9]; \ + OI_CHAR* _str = &_buf[8]; \ + uint32_t _i = n; \ + *_str = 0; \ + do { \ + *(--_str) = _digits[(_i & 0xF)]; \ + _i >>= 4; \ + } while (_i); \ + OI_Print(_str); \ + } /** * Application Dynamic Memory allocation. @@ -185,8 +185,8 @@ uint16_t OI_ProgramImageCRC16(void); * allocated from the pool-based heap managed by the stack's * internal memory manager. */ -void *OI_APP_Malloc(int32_t size); -void OI_APP_Free(void *ptr); +void* OI_APP_Malloc(int32_t size); +void OI_APP_Free(void* ptr); /*****************************************************************************/ #ifdef __cplusplus @@ -196,4 +196,3 @@ void OI_APP_Free(void *ptr); /**@}*/ #endif /* _OI_OSINTERFACE_H */ - diff --git a/embdrv/sbc/decoder/include/oi_status.h b/embdrv/sbc/decoder/include/oi_status.h index 4593dfb58..13a5815af 100644 --- a/embdrv/sbc/decoder/include/oi_status.h +++ b/embdrv/sbc/decoder/include/oi_status.h @@ -33,541 +33,835 @@ extern "C" { #endif - - /** test it **/ +/** test it **/ /** * OI_STATUS is 16 bits, so status codes can range from 0 to 66535, inclusive. */ typedef enum { - OI_STATUS_SUCCESS = 0, /**< function call succeeded alias for #OI_OK */ - OI_OK = 0, /**< function call succeeded alias for #OI_STATUS_SUCCESS */ - OI_STATUS_INVALID_PARAMETERS = 101, /**< invalid function input parameters */ - OI_STATUS_NOT_IMPLEMENTED = 102, /**< attempt to use an unimplemented function */ - OI_STATUS_NOT_INITIALIZED = 103, /**< data not initialized */ - OI_STATUS_NO_RESOURCES = 104, /**< generic resource allocation failure status */ - OI_STATUS_INTERNAL_ERROR = 105, /**< internal inconsistency */ - OI_STATUS_OUT_OF_MEMORY = 106, /**< generally, OI_Malloc failed */ - OI_ILLEGAL_REENTRANT_CALL = 107, /**< violation of non-reentrant module policy */ - OI_STATUS_INITIALIZATION_FAILED = 108, /**< module initialization failed */ - OI_STATUS_INITIALIZATION_PENDING = 109, /**< inititialization not yet complete */ - OI_STATUS_NO_SCO_SUPPORT = 110, /**< SCO operation rejected; system not configured for SCO */ - OI_STATUS_OUT_OF_STATIC_MEMORY = 111, /**< static malloc failed */ - OI_TIMEOUT = 112, /**< generic timeout */ - OI_OS_ERROR = 113, /**< some operating system error */ - OI_FAIL = 114, /**< generic failure */ - OI_STRING_FORMAT_ERROR = 115, /**< error in VarString formatting string */ - OI_STATUS_PENDING = 116, /**< The operation is pending. */ - OI_STATUS_INVALID_COMMAND = 117, /**< The command was invalid. */ - OI_BUSY_FAIL = 118, /**< command rejected due to busy */ - OI_STATUS_ALREADY_REGISTERED = 119, /**< The registration has already been performed. */ - OI_STATUS_NOT_FOUND = 120, /**< The referenced resource was not found. */ - OI_STATUS_NOT_REGISTERED = 121, /**< not registered */ - OI_STATUS_NOT_CONNECTED = 122, /**< not connected */ - OI_CALLBACK_FUNCTION_REQUIRED = 123, /**< A callback function parameter was required. */ - OI_STATUS_MBUF_OVERFLOW = 124, /**< There is no room to add another buffer to an mbuf. */ - OI_STATUS_MBUF_UNDERFLOW = 125, /**< There was an attempt to pull too many bytes from an mbuf. */ - OI_STATUS_CONNECTION_EXISTS = 126, /**< connection exists */ - OI_STATUS_NOT_CONFIGURED = 127, /**< module not configured */ - OI_LOWER_STACK_ERROR = 128, /**< An error was reported by lower stack API. This is used for embedded platforms. */ - OI_STATUS_RESET_IN_PROGRESS = 129, /**< Request failed/rejected because we're busy resetting. */ - OI_STATUS_ACCESS_DENIED = 130, /**< Generic access denied error. */ - OI_STATUS_DATA_ERROR = 131, /**< Generic data error. */ - OI_STATUS_INVALID_ROLE = 132, /**< The requested role was invalid. */ - OI_STATUS_ALREADY_CONNECTED = 133, /**< The requested connection is already established. */ - OI_STATUS_PARSE_ERROR = 134, /**< Parse error */ - OI_STATUS_END_OF_FILE = 135, /**< End of file */ - OI_STATUS_READ_ERROR = 136, /**< Generic read error */ - OI_STATUS_WRITE_ERROR = 137, /**< Generic write error */ - OI_STATUS_NEGOTIATION_FAILURE = 138, /**< Error in negotiation */ - OI_STATUS_READ_IN_PROGRESS = 139, /**< A read is already in progress */ - OI_STATUS_ALREADY_INITIALIZED = 140, /**< Initialization has already been done */ - OI_STATUS_STILL_CONNECTED = 141, /**< The service cannot be shutdown because there are still active connections. */ - OI_STATUS_MTU_EXCEEDED = 142, /**< The packet is too big */ - OI_STATUS_LINK_TERMINATED = 143, /**< The link was terminated */ - OI_STATUS_PIN_CODE_TOO_LONG = 144, /**< Application gave us a pin code that is too long */ - OI_STATUS_STILL_REGISTERED = 145, /**< The service cannot be shutdown because there are still active registrations. */ - OI_STATUS_SPEC_VIOLATION = 146, /**< Some application behavior contrary to BT specifications */ - - - OI_STATUS_PSM_ALREADY_REGISTERED = 402, /**< L2CAP: The specified PSM has already been registered. */ - OI_STATUS_INVALID_CID = 403, /**< L2CAP: CID is invalid or no longer valid (connection terminated) */ - OI_STATUS_CID_NOT_FOUND = 404, /**< L2CAP: CID does not represent a current connection */ - OI_STATUS_CHANNEL_NOT_FOUND = 406, /**< L2CAP: CID does not represent a current connection */ - OI_STATUS_PSM_NOT_FOUND = 407, /**< L2CAP: PSM not found */ - OI_STATUS_INVALID_STATE = 408, /**< L2CAP: invalid state */ - OI_STATUS_WRITE_IN_PROGRESS = 410, /**< L2CAP: write in progress */ - OI_STATUS_INVALID_PACKET = 411, /**< L2CAP: invalid packet */ - OI_STATUS_SEND_COMPLETE = 412, /**< L2CAP: send is complete */ - OI_STATUS_INVALID_HANDLE = 414, /**< L2CAP: handle is invalid */ - OI_STATUS_GROUP_FULL = 418, /**< L2CAP: No more members can be added to the specified group. */ - OI_STATUS_DEVICE_ALREADY_IN_GROUP = 423, /**< L2CAP: The device already exists in the group. */ - OI_STATUS_DUPLICATE_GROUP = 425, /**< L2CAP: attempt to add more than one group */ - OI_STATUS_EMPTY_GROUP = 426, /**< L2CAP: group is empty */ - OI_STATUS_PACKET_NOT_FOUND = 427, /**< L2CAP: packet not found */ - OI_STATUS_BUFFER_TOO_SMALL = 428, /**< L2CAP: The buffer size is too small. */ - OI_STATUS_IDENTIFIER_NOT_FOUND = 429, /**< L2CAP: identifier not found */ - - OI_L2CAP_DISCONNECT_LOWER_LAYER = 430, /**< L2CAP: The lower level forced a disconnect. */ - OI_L2CAP_DISCONNECT_REMOTE_REQUEST = 431, /**< L2CAP: The remote device requested a disconnect. */ - OI_L2CAP_GROUP_ADD_CONNECT_FAIL = 433, /**< L2CAP: Group add connect faiL */ - OI_L2CAP_GROUP_REMOVE_FAILURE = 434, /**< L2CAP: Group remove failure */ - OI_L2CAP_DATA_WRITE_ERROR_LINK_TERM = 435, /**< L2CAP: Data write error LINK_TERM */ - OI_L2CAP_DISCONNECT_LOCAL_REQUEST = 436, /**< L2CAP: Disconnect local request */ - - OI_L2CAP_CONNECT_TIMEOUT = 437, /**< L2CAP: Connect timeout */ - OI_L2CAP_DISCONNECT_TIMEOUT = 439, /**< L2CAP: Disconnect timeout */ - OI_L2CAP_PING_TIMEOUT = 440, /**< L2CAP: Ping timeout */ - OI_L2CAP_GET_INFO_TIMEOUT = 441, /**< L2CAP: Get info timeout */ - OI_L2CAP_INVALID_ADDRESS = 444, /**< L2CAP: Invalid address */ - OI_L2CAP_CMD_REJECT_RCVD = 445, /**< L2CAP: remote sent us 'command reject' response */ - - OI_L2CAP_CONNECT_BASE = 450, /**< L2CAP: Connect base */ - OI_L2CAP_CONNECT_PENDING = 451, /**< L2CAP: Connect pending */ - OI_L2CAP_CONNECT_REFUSED_INVALID_PSM = 452, /**< L2CAP: Connect refused invalid PSM */ - OI_L2CAP_CONNECT_REFUSED_SECURITY = 453, /**< L2CAP: Connect refused security */ - OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */ - - OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */ - OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS= 461, /**< L2CAP: Config fail invalid parameters */ - OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */ - OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */ - - OI_L2CAP_GET_INFO_BASE = 470, /**< L2CAP: Get info base */ - OI_L2CAP_GET_INFO_NOT_SUPPORTED = 471, /**< L2CAP: Get info not supported */ - OI_L2CAP_MTU_EXCEEDED = 472, /**< L2CAP: The MTU of the channel was exceeded */ - OI_L2CAP_INVALID_PSM = 482, /**< L2CAP: Invalid PSM */ - OI_L2CAP_INVALID_MTU = 483, /**< L2CAP: Invalid MTU */ - OI_L2CAP_INVALID_FLUSHTO = 484, /**< L2CAP: Invalid flush timeout */ - - OI_HCI_NO_SUCH_CONNECTION = 601, /**< HCI: caller specified a non-existent connection handle */ - OI_HCI_CB_LIST_FULL = 603, /**< HCI: callback list is full, cannot attempt to send command */ - OI_HCI_EVENT_UNDERRUN = 605, /**< HCI: parsing event packet, premature end-of-parameters */ - OI_HCI_UNKNOWN_EVENT_CODE = 607, /**< HCI: event received - event code is unknown */ - OI_HCI_BAD_EVENT_PARM_LEN = 608, /**< HCI: event - parameter length is incorrect */ - OI_HCI_CMD_QUEUE_FULL = 611, /**< HCI: command queue is full */ - OI_HCI_SHORT_EVENT = 612, /**< HCI: event received, missing event code and/or parm len */ - OI_HCI_TRANSMIT_NOT_READY = 613, /**< HCI: ACL/SCO transmit request failed - busy or no buffers available */ - OI_HCI_ORPHAN_SENT_EVENT = 614, /**< HCI: got spurious 'sent' event from transport layer */ - OI_HCI_CMD_TABLE_ERROR = 615, /**< HCI: inconsistency in the internal command table */ - OI_HCI_UNKNOWN_CMD_ID = 616, /**< HCI: HciApi Command - unknown command id */ - OI_HCI_UNEXPECTED_EVENT = 619, /**< HCI: event received which only occurs in response to our cmd */ - OI_HCI_EVENT_TABLE_ERROR = 620, /**< HCI: inconsistency in the internal event table */ - OI_HCI_EXPECTED_EVENT_TIMOUT = 621, /**< HCI: timed out waiting for an expected event */ - OI_HCI_NO_CMD_DESC_FOR_OPCODE = 622, /**< HCI: event opcode is not known */ - OI_HCI_INVALID_OPCODE_ERROR = 623, /**< HCI: command opcode is invalid */ - OI_HCI_FLOW_CONTROL_DISABLED = 624, /**< HCI: can not use host flow control APIs if disabled in configuration */ - OI_HCI_TX_COMPLETE = 625, /**< HCI: packet delivery to Host Controler complete */ - OI_HCI_TX_ERROR = 626, /**< HCI: failed to deliver packet to Host Controler */ - OI_HCI_DEVICE_NOT_INITIALIZED = 627, /**< HCI: commands from upper layers disallowed until device is up and running */ - OI_HCI_UNSUPPORTED_COMMAND = 628, /**< HCI: command requested is not supported by local device */ - OI_HCI_PASSTHROUGH_ERROR = 629, /**< HCI: Error processing passthrough command */ - OI_HCI_PASSTHROUGH_ALREADY_SET = 630, /**< HCI: Passthrough mode already enabled */ - OI_HCI_RESET_FAILURE = 631, /**< HCI: failed to reset the device/baseband */ - OI_HCI_TRANSPORT_RESET = 632, /**< HCI: some operation failed because of a reset in the transport */ - OI_HCIERR_HCIIFC_INIT_FAILURE = 633, /**< HCI: failed to initialize transport layer interface */ - - OI_HCIERR_FIRST_ERROR_VALUE = 701, /**< marker for first HCI protocol error */ - OI_HCIERR_UNKNOWN_HCI_COMMAND = 701, /**< HCI: protocol error 0x01 */ - OI_HCIERR_NO_CONNECTION = 702, /**< HCI: protocol error 0x02 */ - OI_HCIERR_HARDWARE_FAILURE = 703, /**< HCI: protocol error 0x03 */ - OI_HCIERR_PAGE_TIMEOUT = 704, /**< HCI: protocol error 0x04 */ - OI_HCIERR_AUTHENTICATION_FAILURE = 705, /**< HCI: protocol error 0x05 */ - OI_HCIERR_KEY_MISSING = 706, /**< HCI: protocol error 0x06 */ - OI_HCIERR_MEMORY_FULL = 707, /**< HCI: protocol error 0x07 */ - OI_HCIERR_CONNECTION_TIMEOUT = 708, /**< HCI: protocol error 0x08 */ - OI_HCIERR_MAX_NUM_OF_CONNECTIONS = 709, /**< HCI: protocol error 0x09 */ - OI_HCIERR_MAX_NUM_OF_SCO_CONNECTIONS = 710, /**< HCI: protocol error 0x0A */ - OI_HCIERR_ACL_CONNECTION_ALREADY_EXISTS = 711, /**< HCI: protocol error 0x0B */ - OI_HCIERR_COMMAND_DISALLOWED = 712, /**< HCI: protocol error 0x0C */ - OI_HCIERR_HOST_REJECTED_RESOURCES = 713, /**< HCI: protocol error 0x0D */ - OI_HCIERR_HOST_REJECTED_SECURITY = 714, /**< HCI: protocol error 0x0E */ - OI_HCIERR_HOST_REJECTED_PERSONAL_DEVICE = 715, /**< HCI: protocol error 0x0F */ - OI_HCIERR_HOST_TIMEOUT = 716, /**< HCI: protocol error 0x10 */ - OI_HCIERR_UNSUPPORTED = 717, /**< HCI: protocol error 0x11 */ - OI_HCIERR_INVALID_PARAMETERS = 718, /**< HCI: protocol error 0x12 */ - OI_HCIERR_OTHER_END_USER_DISCONNECT = 719, /**< HCI: protocol error 0x13 */ - OI_HCIERR_OTHER_END_LOW_RESOURCES = 720, /**< HCI: protocol error 0x14 */ - OI_HCIERR_OTHER_END_POWERING_OFF = 721, /**< HCI: protocol error 0x15 */ - OI_HCIERR_CONNECTION_TERMINATED_LOCALLY = 722, /**< HCI: protocol error 0x16 */ - OI_HCIERR_REPEATED_ATTEMPTS = 723, /**< HCI: protocol error 0x17 */ - OI_HCIERR_PAIRING_NOT_ALLOWED = 724, /**< HCI: protocol error 0x18 */ - OI_HCIERR_UNKNOWN_LMP_PDU = 725, /**< HCI: protocol error 0x19 */ - OI_HCIERR_UNSUPPORTED_REMOTE_FEATURE = 726, /**< HCI: protocol error 0x1A */ - OI_HCIERR_SCO_OFFSET_REJECTED = 727, /**< HCI: protocol error 0x1B */ - OI_HCIERR_SCO_INTERVAL_REJECTED = 728, /**< HCI: protocol error 0x1C */ - OI_HCIERR_SCO_AIR_MODE_REJECTED = 729, /**< HCI: protocol error 0x1D */ - OI_HCIERR_INVALID_LMP_PARMS = 730, /**< HCI: protocol error 0x1E */ - OI_HCIERR_UNSPECIFIED_ERROR = 731, /**< HCI: protocol error 0x1F */ - OI_HCIERR_UNSUPPORTED_LMP_PARAMETERS = 732, /**< HCI: protocol error 0x20 */ - OI_HCIERR_ROLE_CHANGE_NOT_ALLOWED = 733, /**< HCI: protocol error 0x21 */ - OI_HCIERR_LMP_RESPONSE_TIMEOUT = 734, /**< HCI: protocol error 0x22 */ - OI_HCIERR_LMP_ERROR_TRANS_COLLISION = 735, /**< HCI: protocol error 0x23 */ - OI_HCIERR_LMP_PDU_NOT_ALLOWED = 736, /**< HCI: protocol error 0x24 */ - OI_HCIERR_ENCRYPTION_MODE_NOT_ACCEPTABLE = 737, /**< HCI: protocol error 0x25 */ - OI_HCIERR_UNIT_KEY_USED = 738, /**< HCI: protocol error 0x26 */ - OI_HCIERR_QOS_NOT_SUPPORTED = 739, /**< HCI: protocol error 0x27 */ - OI_HCIERR_INSTANT_PASSED = 740, /**< HCI: protocol error 0x28 */ - OI_HCIERR_UNIT_KEY_PAIRING_UNSUPPORTED = 741, /**< HCI: protocol error 0x29 */ - OI_HCIERR_DIFFERENT_TRANS_COLLISION = 742, /**< HCI: protocol error 0x2A */ - OI_HCIERR_RESERVED_2B = 743, /**< HCI: protocol error 0x2B */ - OI_HCIERR_QOS_UNACCEPTABLE_PARAMETER = 744, /**< HCI: protocol error 0x2C */ - OI_HCIERR_QOS_REJECTED = 745, /**< HCI: protocol error 0x2D */ - OI_HCIERR_CHANNEL_CLASSIFICATION_NS = 746, /**< HCI: protocol error 0x2E */ - OI_HCIERR_INSUFFICIENT_SECURITY = 747, /**< HCI: protocol error 0x2F */ - OI_HCIERR_PARM_OUT_OF_MANDATORY_RANGE = 748, /**< HCI: protocol error 0x30 */ - OI_HCIERR_RESERVED_31 = 749, /**< HCI: protocol error 0x31 */ - OI_HCIERR_ROLE_SWITCH_PENDING = 750, /**< HCI: protocol error 0x32 */ - OI_HCIERR_RESERVED_33 = 751, /**< HCI: protocol error 0x33 */ - OI_HCIERR_RESERVED_SLOT_VIOLATION = 752, /**< HCI: protocol error 0x34 */ - OI_HCIERR_ROLE_SWITCH_FAILED = 753, /**< HCI: protocol error 0x35 */ - OI_HCIERR_EIR_TOO_LARGE = 754, /**< HCI: protocol error 0x36 */ - OI_HCIERR_SSP_NOT_SUPPORTED_BY_HOST = 755, /**< HCI: protocol error 0x37 */ - OI_HCIERR_HOST_BUSY_PAIRING = 756, /**< HCI: protocol error 0x38 */ - - OI_HCIERR_UNKNOWN_ERROR = 757, /**< HCI: unknown error code */ - OI_HCIERR_LAST_ERROR_VALUE = 757, /**< marker for last HCI protocol error */ - - OI_SDP_SPEC_ERROR = 800, /**< SDP: Base error status for mapping OI_STATUS codes to SDP errors */ - OI_SDP_INVALID_SERVICE_RECORD_HANDLE = (OI_SDP_SPEC_ERROR + 2), /**< SDP: protocol error Invalid Service Record Handle */ - OI_SDP_INVALID_REQUEST_SYNTAX = (OI_SDP_SPEC_ERROR + 3), /**< SDP: protocol error Invalid Request Syntax */ - OI_SDP_INVALID_PDU_SIZE = (OI_SDP_SPEC_ERROR + 4), /**< SDP: protocol error Invalid PDU Size */ - OI_SDP_INVALID_CONTINUATION_STATE = (OI_SDP_SPEC_ERROR + 5), /**< SDP: protocol error Invalid Continuation State */ - OI_SDP_INSUFFICIENT_RESOURCES = (OI_SDP_SPEC_ERROR + 6), /**< SDP: protocol error Insufficient Resources */ - OI_SDP_ERROR = 807, /**< SDP: server returned an error code */ - OI_SDP_CORRUPT_DATA_ELEMENT = 808, /**< SDP: Invalid or corrupt data element representation */ - OI_SDP_SERVER_NOT_CONNECTED = 810, /**< SDP: Attempt to disconnect from an unconnected server */ - OI_SDP_ACCESS_DENIED = 811, /**< SDP: Server denied access to server */ - OI_SDP_ATTRIBUTES_OUT_OF_ORDER = 812, /**< SDP: Attributes in attribute list not in ascending order */ - OI_SDP_DEVICE_DOES_NOT_SUPPORT_SDP = 813, /**< SDP: Tried to connect to a device that does not support SDP */ - OI_SDP_NO_MORE_DATA = 815, /**< SDP: Server does not have more continuation data */ - OI_SDP_REQUEST_PARAMS_TOO_LONG = 816, /**< SDP: Parameters for a request exceed the L2CAP buffer size */ - OI_SDP_REQUEST_PENDING = 817, /**< SDP: Cannot make a request when another request is being processed */ - OI_SDP_SERVER_CONNECT_FAILED = 819, /**< SDP: Failed attempt to connect to an SDP server */ - OI_SDP_SERVER_TOO_MANY_CONNECTIONS = 821, /**< SDP: Exceeded maximum number of simultaneous server connections */ - OI_SDP_NO_MATCHING_SERVICE_RECORD = 823, /**< SDP: No service record matched the UUID list */ - OI_SDP_PARTIAL_RESPONSE = 824, /**< SDP: Internal use only */ - OI_SDP_ILLEGAL_ARGUMENT = 825, /**< SDP: Illegal argument passed to an SDP function */ - OI_SDP_ATTRIBUTE_NOT_FOUND = 826, /**< SDP: A requested attribute was not found in a service record */ - OI_SDP_DATABASE_OUT_OF_RESOURCES = 827, /**< SDP: server database is out of memory */ - OI_SDP_SHORT_PDU = 829, /**< SDP: Not enough bytes in the packet */ - OI_SDP_TRANSACTION_ID_MISMATCH = 830, /**< SDP: Transaction Id was not as expected */ - OI_SDP_UNEXPECTED_RESPONSE_PDU_ID = 831, /**< SDP: Did not expect this response PDU */ - OI_SDP_REQUEST_TIMEOUT = 832, /**< SDP: Did not get a response within the timeout period */ - OI_SDP_INVALID_RESPONSE_SYNTAX = 833, /**< SDP: Response is not correctly formatted */ - OI_SDP_CONNECTION_TIMEOUT = 834, /**< SDP: Connection attempt timed out at a lower layer */ - OI_SDP_RESPONSE_DATA_ERROR = 835, /**< SDP: Response to a service request appears to be corrupt */ - OI_SDP_TOO_MANY_ATTRIBUTE_BYTES = 836, /**< SDP: Response contained more bytes than requested. */ - OI_SDP_TOO_MANY_SERVICE_RECORDS = 837, /**< SDP: Response contained more service records than requested. */ - OI_SDP_INVALID_CONNECTION_ID = 838, /**< SDP: Invalid connection ID in an SDP request */ - OI_SDP_CANNOT_SET_ATTRIBUTE = 839, /**< SDP: Attempt to set a dynamic attribute value failed */ - OI_SDP_BADLY_FORMED_ATTRIBUTE_VALUE = 840, /**< SDP: An attribute value has the wrong type or structure */ - OI_SDP_NO_ATTRIBUTE_LIST_TO_REMOVE = 841, /**< SDP: Attempt to remove a non-existent attribute list from a service record */ - OI_SDP_ATTRIBUTE_LIST_ALREADY_ADDED = 842, /**< SDP: An attribute list has already been added to the service record */ - OI_SDP_DATA_ELEMENT_TRUNCATED = 843, /**< SDP: Data element truncated (too few bytes) */ - - OI_RFCOMM_WRITE_IN_PROGRESS = 901, /**< RFCOMM: Write in progress */ - OI_RFCOMM_INVALID_BAUDRATE = 903, /**< RFCOMM: Invalid baudrate */ - OI_RFCOMM_INVALID_DATABIT = 904, /**< RFCOMM: Invalid databit */ - OI_RFCOMM_INVALID_STOPBIT = 905, /**< RFCOMM: Invalid stopbit */ - OI_RFCOMM_INVALID_PARITY = 906, /**< RFCOMM: Invalid parity */ - OI_RFCOMM_INVALID_PARITYTYPE = 907, /**< RFCOMM: Invalid paritytype */ - OI_RFCOMM_INVALID_FLOWCONTROL = 908, /**< RFCOMM: Invalid flowcontrol */ - OI_RFCOMM_SESSION_EXISTS = 909, /**< RFCOMM: Session exists */ - OI_RFCOMM_INVALID_CHANNEL = 910, /**< RFCOMM: Invalid channel */ - OI_RFCOMM_DLCI_EXISTS = 911, /**< RFCOMM: DLCI exists */ - OI_RFCOMM_LINK_NOT_FOUND = 912, /**< RFCOMM: Link not found */ - OI_RFCOMM_REMOTE_REJECT = 913, /**< RFCOMM: Remote reject */ - OI_RFCOMM_TEST_IN_PROGRESS = 915, /**< RFCOMM: Test in progress */ - OI_RFCOMM_SESSION_NOT_FOUND = 916, /**< RFCOMM: Session not found */ - OI_RFCOMM_INVALID_PACKET = 917, /**< RFCOMM: Invalid packet */ - OI_RFCOMM_FRAMESIZE_EXCEEDED = 918, /**< RFCOMM: Framesize exceeded */ - OI_RFCOMM_INVALID_DLCI = 920, /**< RFCOMM: Invalid dlci */ - OI_RFCOMM_SERVER_NOT_REGISTERED = 921, /**< RFCOMM: Server not registered */ - OI_RFCOMM_CREDIT_ERROR = 922, /**< RFCOMM: Credit error */ - OI_RFCOMM_NO_CHANNEL_NUMBER = 923, /**< RFCOMM: No channel number */ - OI_RFCOMM_QUERY_IN_PROGRESS = 924, /**< RFCOMM: Query in progress */ - OI_RFCOMM_SESSION_SHUTDOWN = 925, /**< RFCOMM: Session shutdown */ - OI_RFCOMM_LOCAL_DEVICE_DISCONNECTED = 926, /**< RFCOMM: Local device disconnected */ - OI_RFCOMM_REMOTE_DEVICE_DISCONNECTED = 927, /**< RFCOMM: Remote device disconnected */ - OI_RFCOMM_OUT_OF_SERVER_CHANNELS = 928, /**< RFCOMM: Out of server channels */ - - OI_DISPATCH_INVALID_CB_HANDLE = 1001, /**< Dispatcher was handed an invalid callback handle */ - OI_DISPATCH_TABLE_OVERFLOW = 1002, /**< Dispatcher table is full */ - - OI_TEST_UNKNOWN_TEST = 1101, /**< TEST: Unknown test */ - OI_TEST_FAIL = 1102, /**< TEST: Fail */ - - OI_HCITRANS_CANNOT_CONNECT_TO_DEVICE = 1201, /**< TRANSPORT: Cannot connect to device */ - OI_HCITRANS_BUFFER_TOO_SMALL = 1203, /**< TRANSPORT: Buffer too small */ - OI_HCITRANS_NULL_DEVICE_HANDLE = 1204, /**< TRANSPORT: Null device handle */ - OI_HCITRANS_IO_ERROR = 1205, /**< TRANSPORT: IO error */ - OI_HCITRANS_DEVICE_NOT_READY = 1206, /**< TRANSPORT: Device not ready */ - OI_HCITRANS_FUNCTION_NOT_SUPPORTED = 1207, /**< TRANSPORT: Function not supporteD */ - OI_HCITRANS_ACCESS_DENIED = 1209, /**< TRANSPORT: win32 */ - OI_HCITRANS_ACL_DATA_ERROR = 1210, /**< TRANSPORT: ACL data error */ - OI_HCITRANS_SCO_DATA_ERROR = 1211, /**< TRANSPORT: SCO data error */ - OI_HCITRANS_EVENT_DATA_ERROR = 1212, /**< TRANSPORT: HCI event data error */ - OI_HCITRANS_INTERNAL_ERROR = 1214, /**< TRANSPORT: Internal error in the transport */ - OI_HCITRANS_LINK_NOT_ACTIVE = 1215, /**< TRANSPORT: Link to the device is not currently active */ - OI_HCITRANS_INITIALIZING = 1216, /**< TRANSPORT: Transport is initializing */ - - OI_DEVMGR_NO_CONNECTION = 1301, /**< DEVMGR: No connection */ - OI_DEVMGR_HARDWARE_ERROR = 1305, /**< DEVMGR: error reported by HCI */ - OI_DEVMGR_PENDING_CONNECT_LIST_FULL = 1307, /**< DEVMGR: Pending connect list full */ - OI_DEVMGR_CONNECTION_LIST_FULL = 1309, /**< DEVMGR: Connection list full */ - OI_DEVMGR_NO_SUCH_CONNECTION = 1310, /**< DEVMGR: No such connection */ - OI_DEVMGR_INQUIRY_IN_PROGRESS = 1311, /**< DEVMGR: Inquiry in progress */ - OI_DEVMGR_PERIODIC_INQUIRY_ACTIVE = 1312, /**< DEVMGR: Periodic inquiry active */ - OI_DEVMGR_NO_INQUIRIES_ACTIVE = 1313, /**< DEVMGR: can not cancel/exit if not active */ - OI_DEVMGR_DUPLICATE_CONNECTION = 1314, /**< DEVMGR: internal error */ - OI_DEVMGR_DUPLICATE_EVENT_CALLBACK = 1316, /**< DEVMGR: attempt to register same callback twice */ - OI_DEVMGR_EVENT_CALLBACK_LIST_FULL = 1317, /**< DEVMGR: can not register event callback, list is full */ - OI_DEVMGR_EVENT_CALLBACK_NOT_FOUND = 1318, /**< DEVMGR: attempt to unregister callback failed */ - OI_DEVMGR_BUSY = 1319, /**< DEVMGR: some operations can only execute one at a time */ - OI_DEVMGR_ENUM_UNEXPECTED_INQ_COMPLETE = 1320, /**< DEVMGR: inquiry complete event in inappropriate enumeration state */ - OI_DEVMGR_ENUM_UNEXPECTED_INQ_RESULT = 1321, /**< DEVMGR: inquiry result event in inappropriate enumeration state */ - OI_DEVMGR_ENUM_DATABASE_FULL = 1322, /**< DEVMGR: device enumeration, database is full, couldn't add a new device */ - OI_DEVMGR_ENUM_INQUIRIES_OVERLAP = 1323, /**< DEVMGR: device enumeration, periodic inquiries occurring too close together */ - OI_DEVMGR_UNKNOWN_LINK_TYPE = 1324, /**< DEVMGR: HCI connect request with unkown link type */ - OI_DEVMGR_PARAM_IO_ACTIVE = 1325, /**< DEVMGR: request for parameter read/write while param read/write active */ - OI_DEVMGR_UNKNOWN_IAC_LAP = 1326, /**< DEVMGR: unrecognized IAC LAP */ - OI_DEVMGR_SCO_ALREADY_REGISTERED = 1327, /**< DEVMGR: only one application can use SCO */ - OI_DEVMGR_SCO_NOT_REGISTERED = 1328, /**< DEVMGR: SCO applications must register before using the API */ - OI_DEVMGR_SCO_WITHOUT_ACL = 1329, /**< DEVMGR: Got SCO connection but there is no underlying ACL connection */ - OI_DEVMGR_NO_SUPPORT = 1330, /**< DEVMGR: Request is not supported by the device */ - OI_DEVMGR_WRITE_POLICY_FAILED = 1331, /**< DEVMGR: connection attempt failed - unable to write link policy */ - OI_DEVMGR_NOT_IN_MASTER_MODE = 1332, /**< DEVMGR: OI_DEVMGR EndMasterMode without prior OI_DEVMGR_BeginMasterMode */ - OI_DEVMGR_POLICY_VIOLATION = 1333, /**< DEVMGR: low-power request is rejected - link policy does not allow it */ - OI_DEVMGR_BUSY_TIMEOUT = 1334, /**< DEVMGR: queued operation timed out while in the queue; \n - timeout configurable via @ref OI_CONFIG_DEVMGR::connectQueueTimeoutSecs "connectQueueTimeoutSecs" */ - OI_DEVMGR_REENCRYPT_FAILED = 1335, /**< DEVMGR: failed to re-encrypt link after role switch */ - OI_DEVMGR_ROLE_POLICY_CONFLICT = 1336, /**< DEVMGR: requested role conflicts with current policy */ - OI_DEVMGR_BAD_INTERVAL = 1337, /**< DEVMGR: current linkTO outside range of requested min/max interval */ - OI_DEVMGR_INVALID_SCO_HANDLE = 1338, /**< DEVMGR: HCI SCO event, invalid handle */ - OI_DEVMGR_CONNECTION_OVERLAP = 1339, /**< DEVMGR: Connection failed due to race condition with remote side */ - OI_DEVMGR_ORPHAN_SUBRATE_COMPLETE = 1340, /**< DEVMGR: sniff subrate complete, but no callback */ - OI_DEVMGR_EIR_RESPONSE_2_LARGE = 1341, /**< DEVMGR: eir builder, response length would exceed spec max */ - - OI_SECMGR_NO_POLICY = 1401, /**< SECMGR: no security policy has been established */ - OI_SECMGR_INTERNAL_ERROR = 1402, /**< SECMGR: internal inconsistency */ - OI_SECMGR_ORPHANED_CALLBACK = 1403, /**< SECMGR: we've been called back, but CB context is gone */ - OI_SECMGR_BUSY = 1404, /**< SECMGR: configure and access request cannot be concurrent */ - OI_SECMGR_DEVICE_NOT_TRUSTED = 1405, /**< SECMGR: l2cap access denied - device is not trusted */ - OI_SECMGR_DEVICE_ENCRYPT_FAIL = 1407, /**< SECMGR: l2cap access denied - failed to start encryption */ - OI_SECMGR_DISCONNECTED_FAIL = 1408, /**< SECMGR: l2cap access denied - disconnected */ - OI_SECMGR_ACCESS_PENDING = 1409, /**< SECMGR: l2cap access request is still pending */ - OI_SECMGR_PIN_CODE_TOO_SHORT = 1410, /**< SECMGR: Higher-layer process gave us a pin code that is too short */ - OI_SECMGR_UNKNOWN_ENCRYPT_VALUE = 1411, /**< SECMGR: got EncryptionChange event, unknown encryption enable value */ - OI_SECMGR_INVALID_POLICY = 1412, /**< SECMGR: the specified security policy is not valid for security mode */ - OI_SECMGR_AUTHORIZATION_FAILED = 1413, /**< SECMGR: device authorization failed */ - OI_SECMGR_ENCRYPTION_FAILED = 1414, /**< SECMGR: device encryption failed */ - OI_SECMGR_UNIT_KEY_UNSUPPORTED = 1415, /**< SECMGR: authentication failed due to non-support of unit keys */ - OI_SECMGR_NOT_REGISTERED = 1416, /**< SECMGR: required registrations have not yet occurred */ - OI_SECMGR_ILLEGAL_WRITE_SSP_MODE = 1417, /**< SECMGR: 2.1 HCI spec does not allow SSP mode to be disabled */ - OI_SECMGR_INVALID_SEC_LEVEL = 1418, /**< SECMGR: security level for a service is not a valid value */ - OI_SECMGR_INSUFFICIENT_LINK_KEY = 1419, /**< SECMGR: link key type is not sufficient to meet service requirements */ - OI_SECMGR_INVALID_KEY_TYPE = 1420, /**< SECMGR: link key type is not a valid value */ - OI_SECMGR_SSP_NOT_ENCRYPTED = 1421, /**< SECMGR: ssp required encryption on incoming link */ - OI_SECMGR_ORPHAN_EVENT = 1422, /**< SECMGR: some HCI security event unrelated to current processes */ - OI_SECMGR_NOT_BONDABLE = 1423, /**< SECMGR: not in bondable mode */ - - OI_TCS_INVALID_ELEMENT_TYPE = 1602, /**< TCS: element type is invalid */ - OI_TCS_INVALID_PACKET = 1603, /**< TCS: packet is invalide */ - OI_TCS_CALL_IN_PROGRESS = 1604, /**< TCS: call is in progress */ - OI_TCS_NO_CALL_IN_PROGRESS = 1605, /**< TCS: no call in progress */ - - OI_OBEX_CONTINUE = 1701, /**< OBEX: Continue processing OBEX request */ - OI_OBEX_COMMAND_ERROR = 1702, /**< OBEX: An unrecognized OBEX command opcode */ - OI_OBEX_CONNECTION_TIMEOUT = 1703, /**< OBEX: Timeout waiting for a response to a request */ - OI_OBEX_CONNECT_FAILED = 1704, /**< OBEX: An OBEX connection request did not succeed */ - OI_OBEX_DISCONNECT_FAILED = 1705, /**< OBEX: A disconnect failed probably because the connection did not exist */ - OI_OBEX_ERROR = 1706, /**< OBEX: Unspecified OBEX error */ - OI_OBEX_INCOMPLETE_PACKET = 1707, /**< OBEX: Packet too short or corrupt */ - OI_OBEX_LENGTH_REQUIRED = 1708, /**< OBEX: Length header required in OBEX command */ - OI_OBEX_NOT_CONNECTED = 1709, /**< OBEX: No connection to OBEX server */ - OI_OBEX_NO_MORE_CONNECTIONS = 1710, /**< OBEX: Reached max connections limit */ - OI_OBEX_OPERATION_IN_PROGRESS = 1711, /**< OBEX: Another operation is still in progress on a connection */ - OI_OBEX_PUT_RESPONSE_ERROR = 1712, /**< OBEX: An error in the response to a PUT command */ - OI_OBEX_GET_RESPONSE_ERROR = 1713, /**< OBEX: An error in the response to a GET command */ - OI_OBEX_REQUIRED_HEADER_NOT_FOUND = 1714, /**< OBEX: packet was missing a required header */ - OI_OBEX_SERVICE_UNAVAILABLE = 1715, /**< OBEX: Unown OBEX target or required service */ - OI_OBEX_TOO_MANY_HEADER_BYTES = 1716, /**< OBEX: Headers will not fit in single OBEX packet */ - OI_OBEX_UNKNOWN_COMMAND = 1717, /**< OBEX: Unrecognized OBEX command */ - OI_OBEX_UNSUPPORTED_VERSION = 1718, /**< OBEX: Version mismatch */ - OI_OBEX_CLIENT_ABORTED_COMMAND = 1719, /**< OBEX: server received abort command */ - OI_OBEX_BAD_PACKET = 1720, /**< OBEX: Any malformed OBEX packet */ - OI_OBEX_BAD_REQUEST = 1721, /**< OBEX: Maps to OBEX response of the same name */ - OI_OBEX_OBJECT_OVERFLOW = 1723, /**< OBEX: Too many bytes received. */ - OI_OBEX_NOT_FOUND = 1724, /**< OBEX: Maps to obex response of same name */ - OI_OBEX_ACCESS_DENIED = 1735, /**< OBEX: Object could not be read or written. */ - OI_OBEX_VALUE_NOT_ACCEPTABLE = 1736, /**< OBEX: Value in a command was not in the acceptable range. */ - OI_OBEX_PACKET_OVERFLOW = 1737, /**< OBEX: Buffer will not fit in a single OBEX packet. */ - OI_OBEX_NO_SUCH_FOLDER = 1738, /**< OBEX: Error returned by a setpath operation. */ - OI_OBEX_NAME_REQUIRED = 1739, /**< OBEX: Name must be non-null and non-empty. */ - OI_OBEX_PASSWORD_TOO_LONG = 1740, /**< OBEX: Password exceeds implementation imposed length limit. */ - OI_OBEX_PRECONDITION_FAILED = 1741, /**< OBEX: response Precondition Failed */ - OI_OBEX_UNAUTHORIZED = 1742, /**< OBEX: authentication was not successful. */ - OI_OBEX_NOT_IMPLEMENTED = 1743, /**< OBEX: Unimplemented feature. */ - OI_OBEX_INVALID_AUTH_DIGEST = 1744, /**< OBEX: An authentication digest was bad. */ - OI_OBEX_INVALID_OPERATION = 1745, /**< OBEX: Operation not allowed at this time. */ - OI_OBEX_DATABASE_FULL = 1746, /**< OBEX: Sync database full. */ - OI_OBEX_DATABASE_LOCKED = 1747, /**< OBEX: Sync database locked. */ - OI_OBEX_INTERNAL_SERVER_ERROR = 1748, /**< OBEX: response Internal Server Error */ - OI_OBEX_UNSUPPORTED_MEDIA_TYPE = 1749, /**< OBEX: response Unsupported Media Type */ - OI_OBEX_PARTIAL_CONTENT = 1750, /**< OBEX: response Partial Content */ - OI_OBEX_METHOD_NOT_ALLOWED = 1751, /**< OBEX: response Method Not Allowed */ - OI_OBEXSRV_INCOMPLETE_GET = 1752, /**< OBEX: Indicates to a GET handler that the request phase is still in progress */ - OI_OBEX_FOLDER_BROWSING_NOT_ALLOWED = 1753, /**< OBEX: Indicates that an FTP server does not allow folder browsing */ - OI_OBEX_SERVER_FORCED_DISCONNECT = 1754, /**< OBEX: connection was forcibly terminated by the server */ - OI_OBEX_OFS_ERROR = 1755, /**< OBEX: OPP object file system error occurred */ - OI_OBEX_FILEOP_ERROR = 1756, /**< OBEX: FTP/PBAP file operation system error occurred */ - OI_OBEX_USERID_TOO_LONG = 1757, /**< OBEX: User Id exceeds spec limited length limit. */ - - OI_HANDSFREE_EVENT_REPORTING_DISABLED = 1801, /**< HANDSFREE: Event reporting disabled */ - OI_HANDSFREE_NOT_CONNECTED = 1802, /**< HANDSFREE: Not connected */ - OI_HANDSFREE_SERVICE_NOT_STARTED = 1803, /**< HANDSFREE: Cannot connect to handsfree AG if handsfree service not started */ - OI_HANDSFREE_AG_SERVICE_NOT_STARTED = 1804, /**< HANDSFREE: Cannot connect to handsfree device if handsfree AG service not started */ - OI_HANDSFREE_COMMAND_IN_PROGRESS = 1805, /**< HANDSFREE: Cannot accept a command at this time */ - OI_HANDSFREE_AUDIO_ALREADY_CONNECTED = 1806, /**< HANDSFREE: Audio is already connected */ - OI_HANDSFREE_AUDIO_NOT_CONNECTED = 1807, /**< HANDSFREE: Audio is not connected */ - OI_HANDSFREE_FEATURE_NOT_SUPPORTED = 1808, /**< HANDSFREE: Local or remote feature not supported for requested command */ - - OI_HEADSET_SERVICE_NOT_STARTED = 1901, /**< HEADSET: Cannot connect to headset AG if headset service not started */ - OI_HEADSET_AG_SERVICE_NOT_STARTED = 1902, /**< HEADSET: Cannot connect to headset device if headset AG service not started */ - OI_HEADSET_COMMAND_IN_PROGRESS = 1903, /**< HEADSET: Cannot accept a command at this time */ - - OI_BNEP_INVALID_MTU = 2001, /**< BNEP: The remote device cannot support the minimum BNEP MTU */ - OI_BNEP_SETUP_TIMEOUT = 2002, /**< BNEP: The setup request timed out. */ - OI_BNEP_SERVICE_NOT_REGISTERED = 2003, /**< BNEP: The requested service was not found. */ - OI_BNEP_INVALID_HANDLE = 2004, /**< BNEP: The specified connection handle is not valid. */ - OI_BNEP_RESPONSE_TIMEOUT = 2005, /**< BNEP: The timer for receiving a response has expired. */ - OI_BNEP_INVALID_CONNECTION = 2006, /**< BNEP: Invalid connection */ - OI_BNEP_INVALID_FILTER = 2007, /**< BNEP: The supplied filter was invalid. */ - OI_BNEP_CONNECTION_EXISTS = 2008, /**< BNEP: An attempt was made to create a duplicate connection. */ - OI_BNEP_NOT_INITIALIZED = 2009, /**< BNEP: Init has not been called */ - OI_BNEP_CONNECT_BASE = 2010, /**< BNEP: connection response codes */ - OI_BNEP_CONNECT_FAILED_INVALID_DEST_UUID = 2011, /**< BNEP: connect response code Invalid Dest UUID */ - OI_BNEP_CONNECT_FAILED_INVALID_SOURCE_UUID = 2012, /**< BNEP: connect response code Invalid Source UUID */ - OI_BNEP_CONNECT_FAILED_INVALID_UUID_SIZE = 2013, /**< BNEP: connect response code Invalid UUID Size */ - OI_BNEP_CONNECT_FAILED_NOT_ALLOWED = 2014, /**< BNEP: connect response code Not Allowed */ - OI_BNEP_FILTER_NET_BASE = 2020, /**< BNEP: filter response codes */ - OI_BNEP_FILTER_NET_UNSUPPORTED_REQUEST = 2021, /**< BNEP: filter response code Unsupported Request */ - OI_BNEP_FILTER_NET_FAILED_INVALID_PROTOCOL_TYPE = 2022, /**< BNEP: filter response code Invalid Protocol Type */ - OI_BNEP_FILTER_NET_FAILED_MAX_LIMIT_REACHED = 2023, /**< BNEP: filter response code Max Limit Reached */ - OI_BNEP_FILTER_NET_FAILED_SECURITY = 2024, /**< BNEP: filter response code Security */ - OI_BNEP_FILTER_MULTI_BASE = 2030, /**< BNEP: multicast response codes */ - OI_BNEP_FILTER_MULTI_UNSUPPORTED_REQUEST = 2031, /**< BNEP: multicast response code Unsupported Request */ - OI_BNEP_FILTER_MULTI_FAILED_INVALID_ADDRESS = 2032, /**< BNEP: multicast response code Invalid Address */ - OI_BNEP_FILTER_MULTI_FAILED_MAX_LIMIT_REACHED = 2033, /**< BNEP: multicast response code Max Limit Reached */ - OI_BNEP_FILTER_MULTI_FAILED_SECURITY = 2034, /**< BNEP: multicast response code Security */ - OI_BNEP_LOCAL_DEVICE_MUST_BE_MASTER = 2040, /**< BNEP: Device must be master of the piconet for this function */ - OI_BNEP_PACKET_FILTERED_OUT = 2041, /**< BNEP: Packet did not pass current filters */ - - OI_NETIFC_UP_FAILED = 2101, /**< NETIFC: Could not bring up network interface */ - OI_NETIFC_COULD_NOT_CREATE_THREAD = 2102, /**< NETIFC: Network interface could not create a read thread */ - OI_NETIFC_INITIALIZATION_FAILED = 2103, /**< NETIFC: Error in network interface initialization */ - OI_NETIFC_INTERFACE_ALREADY_UP = 2104, /**< NETIFC: Network interface is already up */ - OI_NETIFC_INTERFACE_NOT_UP = 2105, /**< NETIFC: Network interface is not up */ - OI_NETIFC_PACKET_TOO_BIG = 2106, /**< NETIFC: The packet is too big */ - - OI_PAN_ROLE_ALREADY_REGISTERED = 2201, /**< PAN: This PAN role was already registered */ - OI_PAN_ROLE_NOT_ALLOWED = 2202, /**< PAN: The PAN role is not currently allowed */ - OI_PAN_INCOMPATIBLE_ROLES = 2203, /**< PAN: Only certain local and remote role combinations are permitted */ - OI_PAN_INVALID_ROLE = 2204, /**< PAN: Role specified is not one the defined PAN roles */ - OI_PAN_CONNECTION_IN_PROGRESS = 2205, /**< PAN: A PAN connection is currently being established */ - OI_PAN_USER_ALREADY_CONNECTED = 2206, /**< PAN: PAN user role only allows a single connection */ - OI_PAN_DEVICE_CONNECTED = 2207, /**< PAN: A PAN connection already exists to specified device */ - - OI_CODEC_SBC_NO_SYNCWORD = 2301, /**< CODEC: Couldn't find an SBC SYNCWORD */ - OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA = 2302, /**< CODEC: Not enough data provided to decode an SBC header */ - OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA = 2303, /**< CODEC: Decoded the header, but not enough data to contain the rest of the frame */ - OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA = 2304, /**< CODEC: Not enough audio data for this frame */ - OI_CODEC_SBC_CHECKSUM_MISMATCH = 2305, /**< CODEC: The frame header didn't match the checksum */ - OI_CODEC_SBC_PARTIAL_DECODE = 2306, /**< CODEC: Decoding was successful, but frame data still remains. Next call will provide audio without consuming input data. */ - - OI_FIFOQ_QUEUE_NOT_ALIGNED = 2401, /**< FIFOQ: queue must be 32-bit aligned */ - OI_FIFOQ_INVALID_Q = 2402, /**< FIFOQ: queue parameter is not a valid queue */ - OI_FIFOQ_BUF_TOO_LARGE = 2403, /**< FIFOQ: attempt to queue a buffer which is too large */ - OI_FIFOQ_FULL = 2404, /**< FIFOQ: enqueue() failed, queue is full */ - OI_FIFOQ_NOT_ALLOCATED = 2405, /**< FIFOQ: Enqueue QBuf() failed, buffer not allocated */ - OI_FIFOQ_INVALID_DATA_PTR = 2406, /**< FIFOQ: Enqueue QBuf() failed, data pointer does not match */ - - OI_HID_HOST_SERVICE_NOT_STARTED = 2601, /**< HID: Cannot connect to a HID device unless HID host is started */ - OI_HID_DEVICE_SERVICE_NOT_STARTED = 2602, /**< HID: Cannot connect to a HID host unless HID device is started */ - - OI_AT_ERROR = 2701, /**< AT: ERROR response */ - OI_AT_NO_CARRIER = 2702, /**< AT: NO CARRIER response */ - OI_AT_BUSY = 2703, /**< AT: BUSY response */ - OI_AT_NO_ANSWER = 2704, /**< AT: NO ANSWER response */ - OI_AT_DELAYED = 2705, /**< AT: DELAYED response */ - OI_AT_BLACKLISTED = 2706, /**< AT: BLACKLISTED response */ - OI_AT_CME_ERROR = 2707, /**< AT: +CME ERROR response */ - OI_AT_CMS_ERROR = 2708, /**< AT: +CMS ERROR response */ - - OI_BLST_CHARACTER_TIMEOUT = 2801, /**< BLST: Timeout expired while waiting for a character from the client. */ - OI_BLST_ACKNOWLDGE_TIMEOUT = 2802, /**< BLST: Timeout expired while waiting for event acknowledgment from the client */ - OI_BLST_TX_NOT_READY = 2803, /**< BLST: BLST is not ready to send a BHAPI message to the client. */ - OI_BLST_TX_BUSY = 2804, /**< BLST: BLST transmit buffer is in use. */ - - OI_AVDTP_CONNECTION_SEQ_ERROR = 2901, /**< AVDTP: sequencing of signalling/media channel connections broken. */ - OI_AVDTP_OUT_OF_RESOURCES = 2902, /**< AVDTP: Tried to allocate too many endpoints or signalling channels. */ - - OI_PBAP_REPOSITORY_NOT_SET = 3001, /**< PBAP: Phonebook repository must be set for operation to complete. */ - OI_PBAP_PHONEBOOK_NOT_SET = 3002, /**< PBAP: Phonebook be set for operation to complete. */ - - OI_AADP_BAD_ENDPOINT = 3101, /**< AADP: Invalid local endpoint specified */ - OI_AADP_BAD_STATE = 3102, /**< AADP: AADP State is not correct for this operation. */ - - OI_UNICODE_INVALID_SOURCE = 3200, /**< Unicode Conversion: Source string has invalid character encoding. */ - OI_UNICODE_SOURCE_EXHAUSTED = 3201, /**< Unicode Conversion: Incomplete Unicode character at end of source buffer. */ - OI_UNICODE_DESTINATION_EXHAUSTED = 3202, /**< Unicode Conversion: Destination buffer not large enough to hold resulting Unicode string. */ - - OI_AVRCP_TOO_MANY_CONNECTIONS = 3300, /**< AVRCP: Exceeded maximum number of simultaneous AVCTP connections. */ - OI_AVRCP_NOT_IMPLEMENTED = 3301, /**< AVRCP: The target does not implement the command specified by the opcode and operand. */ - OI_AVRCP_REJECTED = 3302, /**< AVRCP: The target cannot respond because of invalid operands in command packet. */ - OI_AVRCP_INVALID_RESPONSE = 3303, /**< AVRCP: The controller received the response with invalid parameters */ - OI_AVRCP_RESPONSE_PACKET_OVERFLOW = 3304, /**< AVRCP: The response message does not fir in one AVRCP packet (512 bytes), has to be fragmented. */ - OI_AVRCP_RESPONSE_INVALID_PDU = 3305, /**< AVRCP: Command rejected: target received a PDU that it did not understand. */ - OI_AVRCP_RESPONSE_INVALID_PARAMETER = 3306, /**< AVRCP: Command rejected: target received a PDU with a parameter ID that it did not understand. */ - OI_AVRCP_RESPONSE_PARAMETER_NOT_FOUND = 3307, /**< AVRCP: Command rejected: specified parameter not found, sent if the parameter ID is understood, but content is wrong or corrupted.*/ - OI_AVRCP_RESPONSE_INTERNAL_ERROR = 3308, /**< AVRCP: Command rejected: target detected other error conditions. */ - OI_MAX_BM3_STATUS_VAL, /* Maximum BM3 status code */ - - /* Status code values reserved for BM3 SDK platform-specific implementations */ - OI_STATUS_RESERVED_FOR_BCOT = 9000, - - /* Status code values reserved for BHAPI products */ - OI_STATUS_RESERVED_FOR_BHAPI = 9200, - - /* Status code values reserved for Soundabout products */ - OI_STATUS_RESERVED_FOR_SOUNDABOUT= 9400, - - /* - * Status code values greater than or equal to this value are reserved for use by applications. - * However, because of differences between compilers, and differences between 16-bit and 32-bit - * platforms custom status codes should be in the 16-bit range, so status codes can range from 0 - * to 65534, inclusive (65535 is reserved) + OI_STATUS_SUCCESS = 0, /**< function call succeeded alias for #OI_OK */ + OI_OK = 0, /**< function call succeeded alias for #OI_STATUS_SUCCESS */ + OI_STATUS_INVALID_PARAMETERS = 101, /**< invalid function input parameters */ + OI_STATUS_NOT_IMPLEMENTED = + 102, /**< attempt to use an unimplemented function */ + OI_STATUS_NOT_INITIALIZED = 103, /**< data not initialized */ + OI_STATUS_NO_RESOURCES = + 104, /**< generic resource allocation failure status */ + OI_STATUS_INTERNAL_ERROR = 105, /**< internal inconsistency */ + OI_STATUS_OUT_OF_MEMORY = 106, /**< generally, OI_Malloc failed */ + OI_ILLEGAL_REENTRANT_CALL = + 107, /**< violation of non-reentrant module policy */ + OI_STATUS_INITIALIZATION_FAILED = 108, /**< module initialization failed */ + OI_STATUS_INITIALIZATION_PENDING = + 109, /**< inititialization not yet complete */ + OI_STATUS_NO_SCO_SUPPORT = + 110, /**< SCO operation rejected; system not configured for SCO */ + OI_STATUS_OUT_OF_STATIC_MEMORY = 111, /**< static malloc failed */ + OI_TIMEOUT = 112, /**< generic timeout */ + OI_OS_ERROR = 113, /**< some operating system error */ + OI_FAIL = 114, /**< generic failure */ + OI_STRING_FORMAT_ERROR = 115, /**< error in VarString formatting string */ + OI_STATUS_PENDING = 116, /**< The operation is pending. */ + OI_STATUS_INVALID_COMMAND = 117, /**< The command was invalid. */ + OI_BUSY_FAIL = 118, /**< command rejected due to busy */ + OI_STATUS_ALREADY_REGISTERED = + 119, /**< The registration has already been performed. */ + OI_STATUS_NOT_FOUND = 120, /**< The referenced resource was not found. */ + OI_STATUS_NOT_REGISTERED = 121, /**< not registered */ + OI_STATUS_NOT_CONNECTED = 122, /**< not connected */ + OI_CALLBACK_FUNCTION_REQUIRED = + 123, /**< A callback function parameter was required. */ + OI_STATUS_MBUF_OVERFLOW = + 124, /**< There is no room to add another buffer to an mbuf. */ + OI_STATUS_MBUF_UNDERFLOW = + 125, /**< There was an attempt to pull too many bytes from an mbuf. */ + OI_STATUS_CONNECTION_EXISTS = 126, /**< connection exists */ + OI_STATUS_NOT_CONFIGURED = 127, /**< module not configured */ + OI_LOWER_STACK_ERROR = 128, /**< An error was reported by lower stack API. + This is used for embedded platforms. */ + OI_STATUS_RESET_IN_PROGRESS = + 129, /**< Request failed/rejected because we're busy resetting. */ + OI_STATUS_ACCESS_DENIED = 130, /**< Generic access denied error. */ + OI_STATUS_DATA_ERROR = 131, /**< Generic data error. */ + OI_STATUS_INVALID_ROLE = 132, /**< The requested role was invalid. */ + OI_STATUS_ALREADY_CONNECTED = + 133, /**< The requested connection is already established. */ + OI_STATUS_PARSE_ERROR = 134, /**< Parse error */ + OI_STATUS_END_OF_FILE = 135, /**< End of file */ + OI_STATUS_READ_ERROR = 136, /**< Generic read error */ + OI_STATUS_WRITE_ERROR = 137, /**< Generic write error */ + OI_STATUS_NEGOTIATION_FAILURE = 138, /**< Error in negotiation */ + OI_STATUS_READ_IN_PROGRESS = 139, /**< A read is already in progress */ + OI_STATUS_ALREADY_INITIALIZED = + 140, /**< Initialization has already been done */ + OI_STATUS_STILL_CONNECTED = 141, /**< The service cannot be shutdown because + there are still active connections. */ + OI_STATUS_MTU_EXCEEDED = 142, /**< The packet is too big */ + OI_STATUS_LINK_TERMINATED = 143, /**< The link was terminated */ + OI_STATUS_PIN_CODE_TOO_LONG = + 144, /**< Application gave us a pin code that is too long */ + OI_STATUS_STILL_REGISTERED = + 145, /**< The service cannot be shutdown because there are still active + registrations. */ + OI_STATUS_SPEC_VIOLATION = + 146, /**< Some application behavior contrary to BT specifications */ + + OI_STATUS_PSM_ALREADY_REGISTERED = + 402, /**< L2CAP: The specified PSM has already been registered. */ + OI_STATUS_INVALID_CID = 403, /**< L2CAP: CID is invalid or no longer valid + (connection terminated) */ + OI_STATUS_CID_NOT_FOUND = + 404, /**< L2CAP: CID does not represent a current connection */ + OI_STATUS_CHANNEL_NOT_FOUND = + 406, /**< L2CAP: CID does not represent a current connection */ + OI_STATUS_PSM_NOT_FOUND = 407, /**< L2CAP: PSM not found */ + OI_STATUS_INVALID_STATE = 408, /**< L2CAP: invalid state */ + OI_STATUS_WRITE_IN_PROGRESS = 410, /**< L2CAP: write in progress */ + OI_STATUS_INVALID_PACKET = 411, /**< L2CAP: invalid packet */ + OI_STATUS_SEND_COMPLETE = 412, /**< L2CAP: send is complete */ + OI_STATUS_INVALID_HANDLE = 414, /**< L2CAP: handle is invalid */ + OI_STATUS_GROUP_FULL = + 418, /**< L2CAP: No more members can be added to the specified group. */ + OI_STATUS_DEVICE_ALREADY_IN_GROUP = + 423, /**< L2CAP: The device already exists in the group. */ + OI_STATUS_DUPLICATE_GROUP = + 425, /**< L2CAP: attempt to add more than one group */ + OI_STATUS_EMPTY_GROUP = 426, /**< L2CAP: group is empty */ + OI_STATUS_PACKET_NOT_FOUND = 427, /**< L2CAP: packet not found */ + OI_STATUS_BUFFER_TOO_SMALL = 428, /**< L2CAP: The buffer size is too small. */ + OI_STATUS_IDENTIFIER_NOT_FOUND = 429, /**< L2CAP: identifier not found */ + + OI_L2CAP_DISCONNECT_LOWER_LAYER = + 430, /**< L2CAP: The lower level forced a disconnect. */ + OI_L2CAP_DISCONNECT_REMOTE_REQUEST = + 431, /**< L2CAP: The remote device requested a disconnect. */ + OI_L2CAP_GROUP_ADD_CONNECT_FAIL = 433, /**< L2CAP: Group add connect faiL */ + OI_L2CAP_GROUP_REMOVE_FAILURE = 434, /**< L2CAP: Group remove failure */ + OI_L2CAP_DATA_WRITE_ERROR_LINK_TERM = + 435, /**< L2CAP: Data write error LINK_TERM */ + OI_L2CAP_DISCONNECT_LOCAL_REQUEST = + 436, /**< L2CAP: Disconnect local request */ + + OI_L2CAP_CONNECT_TIMEOUT = 437, /**< L2CAP: Connect timeout */ + OI_L2CAP_DISCONNECT_TIMEOUT = 439, /**< L2CAP: Disconnect timeout */ + OI_L2CAP_PING_TIMEOUT = 440, /**< L2CAP: Ping timeout */ + OI_L2CAP_GET_INFO_TIMEOUT = 441, /**< L2CAP: Get info timeout */ + OI_L2CAP_INVALID_ADDRESS = 444, /**< L2CAP: Invalid address */ + OI_L2CAP_CMD_REJECT_RCVD = + 445, /**< L2CAP: remote sent us 'command reject' response */ + + OI_L2CAP_CONNECT_BASE = 450, /**< L2CAP: Connect base */ + OI_L2CAP_CONNECT_PENDING = 451, /**< L2CAP: Connect pending */ + OI_L2CAP_CONNECT_REFUSED_INVALID_PSM = + 452, /**< L2CAP: Connect refused invalid PSM */ + OI_L2CAP_CONNECT_REFUSED_SECURITY = + 453, /**< L2CAP: Connect refused security */ + OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = + 454, /**< L2CAP: Connect refused no resources */ + + OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */ + OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS = + 461, /**< L2CAP: Config fail invalid parameters */ + OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */ + OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = + 463, /**< L2CAP: Config fail unknown options */ + + OI_L2CAP_GET_INFO_BASE = 470, /**< L2CAP: Get info base */ + OI_L2CAP_GET_INFO_NOT_SUPPORTED = 471, /**< L2CAP: Get info not supported */ + OI_L2CAP_MTU_EXCEEDED = + 472, /**< L2CAP: The MTU of the channel was exceeded */ + OI_L2CAP_INVALID_PSM = 482, /**< L2CAP: Invalid PSM */ + OI_L2CAP_INVALID_MTU = 483, /**< L2CAP: Invalid MTU */ + OI_L2CAP_INVALID_FLUSHTO = 484, /**< L2CAP: Invalid flush timeout */ + + OI_HCI_NO_SUCH_CONNECTION = + 601, /**< HCI: caller specified a non-existent connection handle */ + OI_HCI_CB_LIST_FULL = + 603, /**< HCI: callback list is full, cannot attempt to send command */ + OI_HCI_EVENT_UNDERRUN = + 605, /**< HCI: parsing event packet, premature end-of-parameters */ + OI_HCI_UNKNOWN_EVENT_CODE = + 607, /**< HCI: event received - event code is unknown */ + OI_HCI_BAD_EVENT_PARM_LEN = + 608, /**< HCI: event - parameter length is incorrect */ + OI_HCI_CMD_QUEUE_FULL = 611, /**< HCI: command queue is full */ + OI_HCI_SHORT_EVENT = + 612, /**< HCI: event received, missing event code and/or parm len */ + OI_HCI_TRANSMIT_NOT_READY = 613, /**< HCI: ACL/SCO transmit request failed - + busy or no buffers available */ + OI_HCI_ORPHAN_SENT_EVENT = + 614, /**< HCI: got spurious 'sent' event from transport layer */ + OI_HCI_CMD_TABLE_ERROR = + 615, /**< HCI: inconsistency in the internal command table */ + OI_HCI_UNKNOWN_CMD_ID = 616, /**< HCI: HciApi Command - unknown command id */ + OI_HCI_UNEXPECTED_EVENT = + 619, /**< HCI: event received which only occurs in response to our cmd */ + OI_HCI_EVENT_TABLE_ERROR = + 620, /**< HCI: inconsistency in the internal event table */ + OI_HCI_EXPECTED_EVENT_TIMOUT = + 621, /**< HCI: timed out waiting for an expected event */ + OI_HCI_NO_CMD_DESC_FOR_OPCODE = 622, /**< HCI: event opcode is not known */ + OI_HCI_INVALID_OPCODE_ERROR = 623, /**< HCI: command opcode is invalid */ + OI_HCI_FLOW_CONTROL_DISABLED = 624, /**< HCI: can not use host flow control + APIs if disabled in configuration */ + OI_HCI_TX_COMPLETE = + 625, /**< HCI: packet delivery to Host Controler complete */ + OI_HCI_TX_ERROR = 626, /**< HCI: failed to deliver packet to Host Controler */ + OI_HCI_DEVICE_NOT_INITIALIZED = 627, /**< HCI: commands from upper layers + disallowed until device is up and + running */ + OI_HCI_UNSUPPORTED_COMMAND = + 628, /**< HCI: command requested is not supported by local device */ + OI_HCI_PASSTHROUGH_ERROR = + 629, /**< HCI: Error processing passthrough command */ + OI_HCI_PASSTHROUGH_ALREADY_SET = + 630, /**< HCI: Passthrough mode already enabled */ + OI_HCI_RESET_FAILURE = 631, /**< HCI: failed to reset the device/baseband */ + OI_HCI_TRANSPORT_RESET = 632, /**< HCI: some operation failed because of a + reset in the transport */ + OI_HCIERR_HCIIFC_INIT_FAILURE = + 633, /**< HCI: failed to initialize transport layer interface */ + + OI_HCIERR_FIRST_ERROR_VALUE = 701, /**< marker for first HCI protocol error */ + OI_HCIERR_UNKNOWN_HCI_COMMAND = 701, /**< HCI: protocol error 0x01 */ + OI_HCIERR_NO_CONNECTION = 702, /**< HCI: protocol error 0x02 */ + OI_HCIERR_HARDWARE_FAILURE = 703, /**< HCI: protocol error 0x03 */ + OI_HCIERR_PAGE_TIMEOUT = 704, /**< HCI: protocol error 0x04 */ + OI_HCIERR_AUTHENTICATION_FAILURE = 705, /**< HCI: protocol error 0x05 */ + OI_HCIERR_KEY_MISSING = 706, /**< HCI: protocol error 0x06 */ + OI_HCIERR_MEMORY_FULL = 707, /**< HCI: protocol error 0x07 */ + OI_HCIERR_CONNECTION_TIMEOUT = 708, /**< HCI: protocol error 0x08 */ + OI_HCIERR_MAX_NUM_OF_CONNECTIONS = 709, /**< HCI: protocol error 0x09 */ + OI_HCIERR_MAX_NUM_OF_SCO_CONNECTIONS = 710, /**< HCI: protocol error 0x0A */ + OI_HCIERR_ACL_CONNECTION_ALREADY_EXISTS = + 711, /**< HCI: protocol error 0x0B */ + OI_HCIERR_COMMAND_DISALLOWED = 712, /**< HCI: protocol error 0x0C */ + OI_HCIERR_HOST_REJECTED_RESOURCES = 713, /**< HCI: protocol error 0x0D */ + OI_HCIERR_HOST_REJECTED_SECURITY = 714, /**< HCI: protocol error 0x0E */ + OI_HCIERR_HOST_REJECTED_PERSONAL_DEVICE = + 715, /**< HCI: protocol error 0x0F */ + OI_HCIERR_HOST_TIMEOUT = 716, /**< HCI: protocol error 0x10 */ + OI_HCIERR_UNSUPPORTED = 717, /**< HCI: protocol error 0x11 */ + OI_HCIERR_INVALID_PARAMETERS = 718, /**< HCI: protocol error 0x12 */ + OI_HCIERR_OTHER_END_USER_DISCONNECT = 719, /**< HCI: protocol error 0x13 */ + OI_HCIERR_OTHER_END_LOW_RESOURCES = 720, /**< HCI: protocol error 0x14 */ + OI_HCIERR_OTHER_END_POWERING_OFF = 721, /**< HCI: protocol error 0x15 */ + OI_HCIERR_CONNECTION_TERMINATED_LOCALLY = + 722, /**< HCI: protocol error 0x16 */ + OI_HCIERR_REPEATED_ATTEMPTS = 723, /**< HCI: protocol error 0x17 */ + OI_HCIERR_PAIRING_NOT_ALLOWED = 724, /**< HCI: protocol error 0x18 */ + OI_HCIERR_UNKNOWN_LMP_PDU = 725, /**< HCI: protocol error 0x19 */ + OI_HCIERR_UNSUPPORTED_REMOTE_FEATURE = 726, /**< HCI: protocol error 0x1A */ + OI_HCIERR_SCO_OFFSET_REJECTED = 727, /**< HCI: protocol error 0x1B */ + OI_HCIERR_SCO_INTERVAL_REJECTED = 728, /**< HCI: protocol error 0x1C */ + OI_HCIERR_SCO_AIR_MODE_REJECTED = 729, /**< HCI: protocol error 0x1D */ + OI_HCIERR_INVALID_LMP_PARMS = 730, /**< HCI: protocol error 0x1E */ + OI_HCIERR_UNSPECIFIED_ERROR = 731, /**< HCI: protocol error 0x1F */ + OI_HCIERR_UNSUPPORTED_LMP_PARAMETERS = 732, /**< HCI: protocol error 0x20 */ + OI_HCIERR_ROLE_CHANGE_NOT_ALLOWED = 733, /**< HCI: protocol error 0x21 */ + OI_HCIERR_LMP_RESPONSE_TIMEOUT = 734, /**< HCI: protocol error 0x22 */ + OI_HCIERR_LMP_ERROR_TRANS_COLLISION = 735, /**< HCI: protocol error 0x23 */ + OI_HCIERR_LMP_PDU_NOT_ALLOWED = 736, /**< HCI: protocol error 0x24 */ + OI_HCIERR_ENCRYPTION_MODE_NOT_ACCEPTABLE = + 737, /**< HCI: protocol error 0x25 */ + OI_HCIERR_UNIT_KEY_USED = 738, /**< HCI: protocol error 0x26 */ + OI_HCIERR_QOS_NOT_SUPPORTED = 739, /**< HCI: protocol error 0x27 */ + OI_HCIERR_INSTANT_PASSED = 740, /**< HCI: protocol error 0x28 */ + OI_HCIERR_UNIT_KEY_PAIRING_UNSUPPORTED = 741, /**< HCI: protocol error 0x29 */ + OI_HCIERR_DIFFERENT_TRANS_COLLISION = 742, /**< HCI: protocol error 0x2A */ + OI_HCIERR_RESERVED_2B = 743, /**< HCI: protocol error 0x2B */ + OI_HCIERR_QOS_UNACCEPTABLE_PARAMETER = 744, /**< HCI: protocol error 0x2C */ + OI_HCIERR_QOS_REJECTED = 745, /**< HCI: protocol error 0x2D */ + OI_HCIERR_CHANNEL_CLASSIFICATION_NS = 746, /**< HCI: protocol error 0x2E */ + OI_HCIERR_INSUFFICIENT_SECURITY = 747, /**< HCI: protocol error 0x2F */ + OI_HCIERR_PARM_OUT_OF_MANDATORY_RANGE = 748, /**< HCI: protocol error 0x30 */ + OI_HCIERR_RESERVED_31 = 749, /**< HCI: protocol error 0x31 */ + OI_HCIERR_ROLE_SWITCH_PENDING = 750, /**< HCI: protocol error 0x32 */ + OI_HCIERR_RESERVED_33 = 751, /**< HCI: protocol error 0x33 */ + OI_HCIERR_RESERVED_SLOT_VIOLATION = 752, /**< HCI: protocol error 0x34 */ + OI_HCIERR_ROLE_SWITCH_FAILED = 753, /**< HCI: protocol error 0x35 */ + OI_HCIERR_EIR_TOO_LARGE = 754, /**< HCI: protocol error 0x36 */ + OI_HCIERR_SSP_NOT_SUPPORTED_BY_HOST = 755, /**< HCI: protocol error 0x37 */ + OI_HCIERR_HOST_BUSY_PAIRING = 756, /**< HCI: protocol error 0x38 */ + + OI_HCIERR_UNKNOWN_ERROR = 757, /**< HCI: unknown error code */ + OI_HCIERR_LAST_ERROR_VALUE = 757, /**< marker for last HCI protocol error */ + + OI_SDP_SPEC_ERROR = 800, /**< SDP: Base error status for mapping OI_STATUS + codes to SDP errors */ + OI_SDP_INVALID_SERVICE_RECORD_HANDLE = + (OI_SDP_SPEC_ERROR + + 2), /**< SDP: protocol error Invalid Service Record Handle */ + OI_SDP_INVALID_REQUEST_SYNTAX = + (OI_SDP_SPEC_ERROR + + 3), /**< SDP: protocol error Invalid Request Syntax */ + OI_SDP_INVALID_PDU_SIZE = + (OI_SDP_SPEC_ERROR + 4), /**< SDP: protocol error Invalid PDU Size */ + OI_SDP_INVALID_CONTINUATION_STATE = + (OI_SDP_SPEC_ERROR + + 5), /**< SDP: protocol error Invalid Continuation State */ + OI_SDP_INSUFFICIENT_RESOURCES = + (OI_SDP_SPEC_ERROR + + 6), /**< SDP: protocol error Insufficient Resources */ + OI_SDP_ERROR = 807, /**< SDP: server returned an error code */ + OI_SDP_CORRUPT_DATA_ELEMENT = + 808, /**< SDP: Invalid or corrupt data element representation */ + OI_SDP_SERVER_NOT_CONNECTED = + 810, /**< SDP: Attempt to disconnect from an unconnected server */ + OI_SDP_ACCESS_DENIED = 811, /**< SDP: Server denied access to server */ + OI_SDP_ATTRIBUTES_OUT_OF_ORDER = + 812, /**< SDP: Attributes in attribute list not in ascending order */ + OI_SDP_DEVICE_DOES_NOT_SUPPORT_SDP = + 813, /**< SDP: Tried to connect to a device that does not support SDP */ + OI_SDP_NO_MORE_DATA = + 815, /**< SDP: Server does not have more continuation data */ + OI_SDP_REQUEST_PARAMS_TOO_LONG = + 816, /**< SDP: Parameters for a request exceed the L2CAP buffer size */ + OI_SDP_REQUEST_PENDING = 817, /**< SDP: Cannot make a request when another + request is being processed */ + OI_SDP_SERVER_CONNECT_FAILED = + 819, /**< SDP: Failed attempt to connect to an SDP server */ + OI_SDP_SERVER_TOO_MANY_CONNECTIONS = + 821, /**< SDP: Exceeded maximum number of simultaneous server connections + */ + OI_SDP_NO_MATCHING_SERVICE_RECORD = + 823, /**< SDP: No service record matched the UUID list */ + OI_SDP_PARTIAL_RESPONSE = 824, /**< SDP: Internal use only */ + OI_SDP_ILLEGAL_ARGUMENT = + 825, /**< SDP: Illegal argument passed to an SDP function */ + OI_SDP_ATTRIBUTE_NOT_FOUND = + 826, /**< SDP: A requested attribute was not found in a service record */ + OI_SDP_DATABASE_OUT_OF_RESOURCES = + 827, /**< SDP: server database is out of memory */ + OI_SDP_SHORT_PDU = 829, /**< SDP: Not enough bytes in the packet */ + OI_SDP_TRANSACTION_ID_MISMATCH = + 830, /**< SDP: Transaction Id was not as expected */ + OI_SDP_UNEXPECTED_RESPONSE_PDU_ID = + 831, /**< SDP: Did not expect this response PDU */ + OI_SDP_REQUEST_TIMEOUT = + 832, /**< SDP: Did not get a response within the timeout period */ + OI_SDP_INVALID_RESPONSE_SYNTAX = + 833, /**< SDP: Response is not correctly formatted */ + OI_SDP_CONNECTION_TIMEOUT = + 834, /**< SDP: Connection attempt timed out at a lower layer */ + OI_SDP_RESPONSE_DATA_ERROR = + 835, /**< SDP: Response to a service request appears to be corrupt */ + OI_SDP_TOO_MANY_ATTRIBUTE_BYTES = + 836, /**< SDP: Response contained more bytes than requested. */ + OI_SDP_TOO_MANY_SERVICE_RECORDS = + 837, /**< SDP: Response contained more service records than requested. */ + OI_SDP_INVALID_CONNECTION_ID = + 838, /**< SDP: Invalid connection ID in an SDP request */ + OI_SDP_CANNOT_SET_ATTRIBUTE = + 839, /**< SDP: Attempt to set a dynamic attribute value failed */ + OI_SDP_BADLY_FORMED_ATTRIBUTE_VALUE = + 840, /**< SDP: An attribute value has the wrong type or structure */ + OI_SDP_NO_ATTRIBUTE_LIST_TO_REMOVE = + 841, /**< SDP: Attempt to remove a non-existent attribute list from a + service record */ + OI_SDP_ATTRIBUTE_LIST_ALREADY_ADDED = 842, /**< SDP: An attribute list has + already been added to the + service record */ + OI_SDP_DATA_ELEMENT_TRUNCATED = + 843, /**< SDP: Data element truncated (too few bytes) */ + + OI_RFCOMM_WRITE_IN_PROGRESS = 901, /**< RFCOMM: Write in progress */ + OI_RFCOMM_INVALID_BAUDRATE = 903, /**< RFCOMM: Invalid baudrate */ + OI_RFCOMM_INVALID_DATABIT = 904, /**< RFCOMM: Invalid databit */ + OI_RFCOMM_INVALID_STOPBIT = 905, /**< RFCOMM: Invalid stopbit */ + OI_RFCOMM_INVALID_PARITY = 906, /**< RFCOMM: Invalid parity */ + OI_RFCOMM_INVALID_PARITYTYPE = 907, /**< RFCOMM: Invalid paritytype */ + OI_RFCOMM_INVALID_FLOWCONTROL = 908, /**< RFCOMM: Invalid flowcontrol */ + OI_RFCOMM_SESSION_EXISTS = 909, /**< RFCOMM: Session exists */ + OI_RFCOMM_INVALID_CHANNEL = 910, /**< RFCOMM: Invalid channel */ + OI_RFCOMM_DLCI_EXISTS = 911, /**< RFCOMM: DLCI exists */ + OI_RFCOMM_LINK_NOT_FOUND = 912, /**< RFCOMM: Link not found */ + OI_RFCOMM_REMOTE_REJECT = 913, /**< RFCOMM: Remote reject */ + OI_RFCOMM_TEST_IN_PROGRESS = 915, /**< RFCOMM: Test in progress */ + OI_RFCOMM_SESSION_NOT_FOUND = 916, /**< RFCOMM: Session not found */ + OI_RFCOMM_INVALID_PACKET = 917, /**< RFCOMM: Invalid packet */ + OI_RFCOMM_FRAMESIZE_EXCEEDED = 918, /**< RFCOMM: Framesize exceeded */ + OI_RFCOMM_INVALID_DLCI = 920, /**< RFCOMM: Invalid dlci */ + OI_RFCOMM_SERVER_NOT_REGISTERED = 921, /**< RFCOMM: Server not registered */ + OI_RFCOMM_CREDIT_ERROR = 922, /**< RFCOMM: Credit error */ + OI_RFCOMM_NO_CHANNEL_NUMBER = 923, /**< RFCOMM: No channel number */ + OI_RFCOMM_QUERY_IN_PROGRESS = 924, /**< RFCOMM: Query in progress */ + OI_RFCOMM_SESSION_SHUTDOWN = 925, /**< RFCOMM: Session shutdown */ + OI_RFCOMM_LOCAL_DEVICE_DISCONNECTED = + 926, /**< RFCOMM: Local device disconnected */ + OI_RFCOMM_REMOTE_DEVICE_DISCONNECTED = + 927, /**< RFCOMM: Remote device disconnected */ + OI_RFCOMM_OUT_OF_SERVER_CHANNELS = 928, /**< RFCOMM: Out of server channels */ + + OI_DISPATCH_INVALID_CB_HANDLE = + 1001, /**< Dispatcher was handed an invalid callback handle */ + OI_DISPATCH_TABLE_OVERFLOW = 1002, /**< Dispatcher table is full */ + + OI_TEST_UNKNOWN_TEST = 1101, /**< TEST: Unknown test */ + OI_TEST_FAIL = 1102, /**< TEST: Fail */ + + OI_HCITRANS_CANNOT_CONNECT_TO_DEVICE = + 1201, /**< TRANSPORT: Cannot connect to device */ + OI_HCITRANS_BUFFER_TOO_SMALL = 1203, /**< TRANSPORT: Buffer too small */ + OI_HCITRANS_NULL_DEVICE_HANDLE = 1204, /**< TRANSPORT: Null device handle */ + OI_HCITRANS_IO_ERROR = 1205, /**< TRANSPORT: IO error */ + OI_HCITRANS_DEVICE_NOT_READY = 1206, /**< TRANSPORT: Device not ready */ + OI_HCITRANS_FUNCTION_NOT_SUPPORTED = + 1207, /**< TRANSPORT: Function not supporteD */ + OI_HCITRANS_ACCESS_DENIED = 1209, /**< TRANSPORT: win32 */ + OI_HCITRANS_ACL_DATA_ERROR = 1210, /**< TRANSPORT: ACL data error */ + OI_HCITRANS_SCO_DATA_ERROR = 1211, /**< TRANSPORT: SCO data error */ + OI_HCITRANS_EVENT_DATA_ERROR = 1212, /**< TRANSPORT: HCI event data error */ + OI_HCITRANS_INTERNAL_ERROR = + 1214, /**< TRANSPORT: Internal error in the transport */ + OI_HCITRANS_LINK_NOT_ACTIVE = + 1215, /**< TRANSPORT: Link to the device is not currently active */ + OI_HCITRANS_INITIALIZING = 1216, /**< TRANSPORT: Transport is initializing */ + + OI_DEVMGR_NO_CONNECTION = 1301, /**< DEVMGR: No connection */ + OI_DEVMGR_HARDWARE_ERROR = 1305, /**< DEVMGR: error reported by HCI */ + OI_DEVMGR_PENDING_CONNECT_LIST_FULL = + 1307, /**< DEVMGR: Pending connect list full */ + OI_DEVMGR_CONNECTION_LIST_FULL = 1309, /**< DEVMGR: Connection list full */ + OI_DEVMGR_NO_SUCH_CONNECTION = 1310, /**< DEVMGR: No such connection */ + OI_DEVMGR_INQUIRY_IN_PROGRESS = 1311, /**< DEVMGR: Inquiry in progress */ + OI_DEVMGR_PERIODIC_INQUIRY_ACTIVE = + 1312, /**< DEVMGR: Periodic inquiry active */ + OI_DEVMGR_NO_INQUIRIES_ACTIVE = + 1313, /**< DEVMGR: can not cancel/exit if not active */ + OI_DEVMGR_DUPLICATE_CONNECTION = 1314, /**< DEVMGR: internal error */ + OI_DEVMGR_DUPLICATE_EVENT_CALLBACK = + 1316, /**< DEVMGR: attempt to register same callback twice */ + OI_DEVMGR_EVENT_CALLBACK_LIST_FULL = + 1317, /**< DEVMGR: can not register event callback, list is full */ + OI_DEVMGR_EVENT_CALLBACK_NOT_FOUND = + 1318, /**< DEVMGR: attempt to unregister callback failed */ + OI_DEVMGR_BUSY = + 1319, /**< DEVMGR: some operations can only execute one at a time */ + OI_DEVMGR_ENUM_UNEXPECTED_INQ_COMPLETE = 1320, /**< DEVMGR: inquiry complete + event in inappropriate + enumeration state */ + OI_DEVMGR_ENUM_UNEXPECTED_INQ_RESULT = 1321, /**< DEVMGR: inquiry result event + in inappropriate enumeration + state */ + OI_DEVMGR_ENUM_DATABASE_FULL = + 1322, /**< DEVMGR: device enumeration, database is full, couldn't add a + new device */ + OI_DEVMGR_ENUM_INQUIRIES_OVERLAP = 1323, /**< DEVMGR: device enumeration, + periodic inquiries occurring too + close together */ + OI_DEVMGR_UNKNOWN_LINK_TYPE = + 1324, /**< DEVMGR: HCI connect request with unkown link type */ + OI_DEVMGR_PARAM_IO_ACTIVE = 1325, /**< DEVMGR: request for parameter + read/write while param read/write active + */ + OI_DEVMGR_UNKNOWN_IAC_LAP = 1326, /**< DEVMGR: unrecognized IAC LAP */ + OI_DEVMGR_SCO_ALREADY_REGISTERED = + 1327, /**< DEVMGR: only one application can use SCO */ + OI_DEVMGR_SCO_NOT_REGISTERED = + 1328, /**< DEVMGR: SCO applications must register before using the API */ + OI_DEVMGR_SCO_WITHOUT_ACL = + 1329, /**< DEVMGR: Got SCO connection but there is no underlying ACL + connection */ + OI_DEVMGR_NO_SUPPORT = + 1330, /**< DEVMGR: Request is not supported by the device */ + OI_DEVMGR_WRITE_POLICY_FAILED = 1331, /**< DEVMGR: connection attempt failed - + unable to write link policy */ + OI_DEVMGR_NOT_IN_MASTER_MODE = 1332, /**< DEVMGR: OI_DEVMGR EndMasterMode + without prior + OI_DEVMGR_BeginMasterMode */ + OI_DEVMGR_POLICY_VIOLATION = + 1333, /**< DEVMGR: low-power request is rejected - link policy does not + allow it */ + OI_DEVMGR_BUSY_TIMEOUT = 1334, /**< DEVMGR: queued operation timed out while +in the queue; \n +timeout configurable via @ref OI_CONFIG_DEVMGR::connectQueueTimeoutSecs +"connectQueueTimeoutSecs" */ + OI_DEVMGR_REENCRYPT_FAILED = + 1335, /**< DEVMGR: failed to re-encrypt link after role switch */ + OI_DEVMGR_ROLE_POLICY_CONFLICT = + 1336, /**< DEVMGR: requested role conflicts with current policy */ + OI_DEVMGR_BAD_INTERVAL = 1337, /**< DEVMGR: current linkTO outside range of + requested min/max interval */ + OI_DEVMGR_INVALID_SCO_HANDLE = + 1338, /**< DEVMGR: HCI SCO event, invalid handle */ + OI_DEVMGR_CONNECTION_OVERLAP = 1339, /**< DEVMGR: Connection failed due to + race condition with remote side */ + OI_DEVMGR_ORPHAN_SUBRATE_COMPLETE = + 1340, /**< DEVMGR: sniff subrate complete, but no callback */ + OI_DEVMGR_EIR_RESPONSE_2_LARGE = + 1341, /**< DEVMGR: eir builder, response length would exceed spec max */ + + OI_SECMGR_NO_POLICY = + 1401, /**< SECMGR: no security policy has been established */ + OI_SECMGR_INTERNAL_ERROR = 1402, /**< SECMGR: internal inconsistency */ + OI_SECMGR_ORPHANED_CALLBACK = + 1403, /**< SECMGR: we've been called back, but CB context is gone */ + OI_SECMGR_BUSY = + 1404, /**< SECMGR: configure and access request cannot be concurrent */ + OI_SECMGR_DEVICE_NOT_TRUSTED = + 1405, /**< SECMGR: l2cap access denied - device is not trusted */ + OI_SECMGR_DEVICE_ENCRYPT_FAIL = + 1407, /**< SECMGR: l2cap access denied - failed to start encryption */ + OI_SECMGR_DISCONNECTED_FAIL = + 1408, /**< SECMGR: l2cap access denied - disconnected */ + OI_SECMGR_ACCESS_PENDING = + 1409, /**< SECMGR: l2cap access request is still pending */ + OI_SECMGR_PIN_CODE_TOO_SHORT = + 1410, /**< SECMGR: Higher-layer process gave us a pin code that is too + short */ + OI_SECMGR_UNKNOWN_ENCRYPT_VALUE = 1411, /**< SECMGR: got EncryptionChange + event, unknown encryption enable + value */ + OI_SECMGR_INVALID_POLICY = 1412, /**< SECMGR: the specified security policy is + not valid for security mode */ + OI_SECMGR_AUTHORIZATION_FAILED = + 1413, /**< SECMGR: device authorization failed */ + OI_SECMGR_ENCRYPTION_FAILED = 1414, /**< SECMGR: device encryption failed */ + OI_SECMGR_UNIT_KEY_UNSUPPORTED = + 1415, /**< SECMGR: authentication failed due to non-support of unit keys + */ + OI_SECMGR_NOT_REGISTERED = + 1416, /**< SECMGR: required registrations have not yet occurred */ + OI_SECMGR_ILLEGAL_WRITE_SSP_MODE = + 1417, /**< SECMGR: 2.1 HCI spec does not allow SSP mode to be disabled */ + OI_SECMGR_INVALID_SEC_LEVEL = + 1418, /**< SECMGR: security level for a service is not a valid value */ + OI_SECMGR_INSUFFICIENT_LINK_KEY = 1419, /**< SECMGR: link key type is not + sufficient to meet service + requirements */ + OI_SECMGR_INVALID_KEY_TYPE = + 1420, /**< SECMGR: link key type is not a valid value */ + OI_SECMGR_SSP_NOT_ENCRYPTED = + 1421, /**< SECMGR: ssp required encryption on incoming link */ + OI_SECMGR_ORPHAN_EVENT = 1422, /**< SECMGR: some HCI security event unrelated + to current processes */ + OI_SECMGR_NOT_BONDABLE = 1423, /**< SECMGR: not in bondable mode */ + + OI_TCS_INVALID_ELEMENT_TYPE = 1602, /**< TCS: element type is invalid */ + OI_TCS_INVALID_PACKET = 1603, /**< TCS: packet is invalide */ + OI_TCS_CALL_IN_PROGRESS = 1604, /**< TCS: call is in progress */ + OI_TCS_NO_CALL_IN_PROGRESS = 1605, /**< TCS: no call in progress */ + + OI_OBEX_CONTINUE = 1701, /**< OBEX: Continue processing OBEX request */ + OI_OBEX_COMMAND_ERROR = + 1702, /**< OBEX: An unrecognized OBEX command opcode */ + OI_OBEX_CONNECTION_TIMEOUT = + 1703, /**< OBEX: Timeout waiting for a response to a request */ + OI_OBEX_CONNECT_FAILED = + 1704, /**< OBEX: An OBEX connection request did not succeed */ + OI_OBEX_DISCONNECT_FAILED = 1705, /**< OBEX: A disconnect failed probably + because the connection did not exist */ + OI_OBEX_ERROR = 1706, /**< OBEX: Unspecified OBEX error */ + OI_OBEX_INCOMPLETE_PACKET = 1707, /**< OBEX: Packet too short or corrupt */ + OI_OBEX_LENGTH_REQUIRED = + 1708, /**< OBEX: Length header required in OBEX command */ + OI_OBEX_NOT_CONNECTED = 1709, /**< OBEX: No connection to OBEX server */ + OI_OBEX_NO_MORE_CONNECTIONS = + 1710, /**< OBEX: Reached max connections limit */ + OI_OBEX_OPERATION_IN_PROGRESS = + 1711, /**< OBEX: Another operation is still in progress on a connection */ + OI_OBEX_PUT_RESPONSE_ERROR = + 1712, /**< OBEX: An error in the response to a PUT command */ + OI_OBEX_GET_RESPONSE_ERROR = + 1713, /**< OBEX: An error in the response to a GET command */ + OI_OBEX_REQUIRED_HEADER_NOT_FOUND = + 1714, /**< OBEX: packet was missing a required header */ + OI_OBEX_SERVICE_UNAVAILABLE = + 1715, /**< OBEX: Unown OBEX target or required service */ + OI_OBEX_TOO_MANY_HEADER_BYTES = + 1716, /**< OBEX: Headers will not fit in single OBEX packet */ + OI_OBEX_UNKNOWN_COMMAND = 1717, /**< OBEX: Unrecognized OBEX command */ + OI_OBEX_UNSUPPORTED_VERSION = 1718, /**< OBEX: Version mismatch */ + OI_OBEX_CLIENT_ABORTED_COMMAND = + 1719, /**< OBEX: server received abort command */ + OI_OBEX_BAD_PACKET = 1720, /**< OBEX: Any malformed OBEX packet */ + OI_OBEX_BAD_REQUEST = + 1721, /**< OBEX: Maps to OBEX response of the same name */ + OI_OBEX_OBJECT_OVERFLOW = 1723, /**< OBEX: Too many bytes received. */ + OI_OBEX_NOT_FOUND = 1724, /**< OBEX: Maps to obex response of same name */ + OI_OBEX_ACCESS_DENIED = + 1735, /**< OBEX: Object could not be read or written. */ + OI_OBEX_VALUE_NOT_ACCEPTABLE = + 1736, /**< OBEX: Value in a command was not in the acceptable range. */ + OI_OBEX_PACKET_OVERFLOW = + 1737, /**< OBEX: Buffer will not fit in a single OBEX packet. */ + OI_OBEX_NO_SUCH_FOLDER = + 1738, /**< OBEX: Error returned by a setpath operation. */ + OI_OBEX_NAME_REQUIRED = + 1739, /**< OBEX: Name must be non-null and non-empty. */ + OI_OBEX_PASSWORD_TOO_LONG = + 1740, /**< OBEX: Password exceeds implementation imposed length limit. */ + OI_OBEX_PRECONDITION_FAILED = 1741, /**< OBEX: response Precondition Failed */ + OI_OBEX_UNAUTHORIZED = 1742, /**< OBEX: authentication was not successful. */ + OI_OBEX_NOT_IMPLEMENTED = 1743, /**< OBEX: Unimplemented feature. */ + OI_OBEX_INVALID_AUTH_DIGEST = + 1744, /**< OBEX: An authentication digest was bad. */ + OI_OBEX_INVALID_OPERATION = + 1745, /**< OBEX: Operation not allowed at this time. */ + OI_OBEX_DATABASE_FULL = 1746, /**< OBEX: Sync database full. */ + OI_OBEX_DATABASE_LOCKED = 1747, /**< OBEX: Sync database locked. */ + OI_OBEX_INTERNAL_SERVER_ERROR = + 1748, /**< OBEX: response Internal Server Error */ + OI_OBEX_UNSUPPORTED_MEDIA_TYPE = + 1749, /**< OBEX: response Unsupported Media Type */ + OI_OBEX_PARTIAL_CONTENT = 1750, /**< OBEX: response Partial Content */ + OI_OBEX_METHOD_NOT_ALLOWED = 1751, /**< OBEX: response Method Not Allowed */ + OI_OBEXSRV_INCOMPLETE_GET = 1752, /**< OBEX: Indicates to a GET handler that + the request phase is still in progress */ + OI_OBEX_FOLDER_BROWSING_NOT_ALLOWED = 1753, /**< OBEX: Indicates that an FTP + server does not allow folder + browsing */ + OI_OBEX_SERVER_FORCED_DISCONNECT = + 1754, /**< OBEX: connection was forcibly terminated by the server */ + OI_OBEX_OFS_ERROR = 1755, /**< OBEX: OPP object file system error occurred */ + OI_OBEX_FILEOP_ERROR = + 1756, /**< OBEX: FTP/PBAP file operation system error occurred */ + OI_OBEX_USERID_TOO_LONG = + 1757, /**< OBEX: User Id exceeds spec limited length limit. */ + + OI_HANDSFREE_EVENT_REPORTING_DISABLED = + 1801, /**< HANDSFREE: Event reporting disabled */ + OI_HANDSFREE_NOT_CONNECTED = 1802, /**< HANDSFREE: Not connected */ + OI_HANDSFREE_SERVICE_NOT_STARTED = 1803, /**< HANDSFREE: Cannot connect to + handsfree AG if handsfree service + not started */ + OI_HANDSFREE_AG_SERVICE_NOT_STARTED = + 1804, /**< HANDSFREE: Cannot connect to handsfree device if handsfree AG + service not started */ + OI_HANDSFREE_COMMAND_IN_PROGRESS = + 1805, /**< HANDSFREE: Cannot accept a command at this time */ + OI_HANDSFREE_AUDIO_ALREADY_CONNECTED = + 1806, /**< HANDSFREE: Audio is already connected */ + OI_HANDSFREE_AUDIO_NOT_CONNECTED = + 1807, /**< HANDSFREE: Audio is not connected */ + OI_HANDSFREE_FEATURE_NOT_SUPPORTED = 1808, /**< HANDSFREE: Local or remote + feature not supported for + requested command */ + + OI_HEADSET_SERVICE_NOT_STARTED = + 1901, /**< HEADSET: Cannot connect to headset AG if headset service not + started */ + OI_HEADSET_AG_SERVICE_NOT_STARTED = 1902, /**< HEADSET: Cannot connect to + headset device if headset AG + service not started */ + OI_HEADSET_COMMAND_IN_PROGRESS = + 1903, /**< HEADSET: Cannot accept a command at this time */ + + OI_BNEP_INVALID_MTU = + 2001, /**< BNEP: The remote device cannot support the minimum BNEP MTU */ + OI_BNEP_SETUP_TIMEOUT = 2002, /**< BNEP: The setup request timed out. */ + OI_BNEP_SERVICE_NOT_REGISTERED = + 2003, /**< BNEP: The requested service was not found. */ + OI_BNEP_INVALID_HANDLE = + 2004, /**< BNEP: The specified connection handle is not valid. */ + OI_BNEP_RESPONSE_TIMEOUT = + 2005, /**< BNEP: The timer for receiving a response has expired. */ + OI_BNEP_INVALID_CONNECTION = 2006, /**< BNEP: Invalid connection */ + OI_BNEP_INVALID_FILTER = 2007, /**< BNEP: The supplied filter was invalid. */ + OI_BNEP_CONNECTION_EXISTS = + 2008, /**< BNEP: An attempt was made to create a duplicate connection. */ + OI_BNEP_NOT_INITIALIZED = 2009, /**< BNEP: Init has not been called */ + OI_BNEP_CONNECT_BASE = 2010, /**< BNEP: connection response codes */ + OI_BNEP_CONNECT_FAILED_INVALID_DEST_UUID = + 2011, /**< BNEP: connect response code Invalid Dest UUID */ + OI_BNEP_CONNECT_FAILED_INVALID_SOURCE_UUID = + 2012, /**< BNEP: connect response code Invalid Source UUID */ + OI_BNEP_CONNECT_FAILED_INVALID_UUID_SIZE = + 2013, /**< BNEP: connect response code Invalid UUID Size */ + OI_BNEP_CONNECT_FAILED_NOT_ALLOWED = + 2014, /**< BNEP: connect response code Not Allowed */ + OI_BNEP_FILTER_NET_BASE = 2020, /**< BNEP: filter response codes */ + OI_BNEP_FILTER_NET_UNSUPPORTED_REQUEST = + 2021, /**< BNEP: filter response code Unsupported Request */ + OI_BNEP_FILTER_NET_FAILED_INVALID_PROTOCOL_TYPE = + 2022, /**< BNEP: filter response code Invalid Protocol Type */ + OI_BNEP_FILTER_NET_FAILED_MAX_LIMIT_REACHED = + 2023, /**< BNEP: filter response code Max Limit Reached */ + OI_BNEP_FILTER_NET_FAILED_SECURITY = + 2024, /**< BNEP: filter response code Security */ + OI_BNEP_FILTER_MULTI_BASE = 2030, /**< BNEP: multicast response codes */ + OI_BNEP_FILTER_MULTI_UNSUPPORTED_REQUEST = + 2031, /**< BNEP: multicast response code Unsupported Request */ + OI_BNEP_FILTER_MULTI_FAILED_INVALID_ADDRESS = + 2032, /**< BNEP: multicast response code Invalid Address */ + OI_BNEP_FILTER_MULTI_FAILED_MAX_LIMIT_REACHED = + 2033, /**< BNEP: multicast response code Max Limit Reached */ + OI_BNEP_FILTER_MULTI_FAILED_SECURITY = + 2034, /**< BNEP: multicast response code Security */ + OI_BNEP_LOCAL_DEVICE_MUST_BE_MASTER = + 2040, /**< BNEP: Device must be master of the piconet for this function */ + OI_BNEP_PACKET_FILTERED_OUT = + 2041, /**< BNEP: Packet did not pass current filters */ + + OI_NETIFC_UP_FAILED = + 2101, /**< NETIFC: Could not bring up network interface */ + OI_NETIFC_COULD_NOT_CREATE_THREAD = + 2102, /**< NETIFC: Network interface could not create a read thread */ + OI_NETIFC_INITIALIZATION_FAILED = + 2103, /**< NETIFC: Error in network interface initialization */ + OI_NETIFC_INTERFACE_ALREADY_UP = + 2104, /**< NETIFC: Network interface is already up */ + OI_NETIFC_INTERFACE_NOT_UP = 2105, /**< NETIFC: Network interface is not up */ + OI_NETIFC_PACKET_TOO_BIG = 2106, /**< NETIFC: The packet is too big */ + + OI_PAN_ROLE_ALREADY_REGISTERED = + 2201, /**< PAN: This PAN role was already registered */ + OI_PAN_ROLE_NOT_ALLOWED = + 2202, /**< PAN: The PAN role is not currently allowed */ + OI_PAN_INCOMPATIBLE_ROLES = + 2203, /**< PAN: Only certain local and remote role combinations are + permitted */ + OI_PAN_INVALID_ROLE = + 2204, /**< PAN: Role specified is not one the defined PAN roles */ + OI_PAN_CONNECTION_IN_PROGRESS = + 2205, /**< PAN: A PAN connection is currently being established */ + OI_PAN_USER_ALREADY_CONNECTED = + 2206, /**< PAN: PAN user role only allows a single connection */ + OI_PAN_DEVICE_CONNECTED = + 2207, /**< PAN: A PAN connection already exists to specified device */ + + OI_CODEC_SBC_NO_SYNCWORD = 2301, /**< CODEC: Couldn't find an SBC SYNCWORD */ + OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA = + 2302, /**< CODEC: Not enough data provided to decode an SBC header */ + OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA = + 2303, /**< CODEC: Decoded the header, but not enough data to contain the + rest of the frame */ + OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA = + 2304, /**< CODEC: Not enough audio data for this frame */ + OI_CODEC_SBC_CHECKSUM_MISMATCH = + 2305, /**< CODEC: The frame header didn't match the checksum */ + OI_CODEC_SBC_PARTIAL_DECODE = + 2306, /**< CODEC: Decoding was successful, but frame data still remains. + Next call will provide audio without consuming input data. */ + + OI_FIFOQ_QUEUE_NOT_ALIGNED = 2401, /**< FIFOQ: queue must be 32-bit aligned */ + OI_FIFOQ_INVALID_Q = 2402, /**< FIFOQ: queue parameter is not a valid queue */ + OI_FIFOQ_BUF_TOO_LARGE = + 2403, /**< FIFOQ: attempt to queue a buffer which is too large */ + OI_FIFOQ_FULL = 2404, /**< FIFOQ: enqueue() failed, queue is full */ + OI_FIFOQ_NOT_ALLOCATED = + 2405, /**< FIFOQ: Enqueue QBuf() failed, buffer not allocated */ + OI_FIFOQ_INVALID_DATA_PTR = + 2406, /**< FIFOQ: Enqueue QBuf() failed, data pointer does not match */ + + OI_HID_HOST_SERVICE_NOT_STARTED = 2601, /**< HID: Cannot connect to a HID + device unless HID host is started + */ + OI_HID_DEVICE_SERVICE_NOT_STARTED = + 2602, /**< HID: Cannot connect to a HID host unless HID device is started + */ + + OI_AT_ERROR = 2701, /**< AT: ERROR response */ + OI_AT_NO_CARRIER = 2702, /**< AT: NO CARRIER response */ + OI_AT_BUSY = 2703, /**< AT: BUSY response */ + OI_AT_NO_ANSWER = 2704, /**< AT: NO ANSWER response */ + OI_AT_DELAYED = 2705, /**< AT: DELAYED response */ + OI_AT_BLACKLISTED = 2706, /**< AT: BLACKLISTED response */ + OI_AT_CME_ERROR = 2707, /**< AT: +CME ERROR response */ + OI_AT_CMS_ERROR = 2708, /**< AT: +CMS ERROR response */ + + OI_BLST_CHARACTER_TIMEOUT = + 2801, /**< BLST: Timeout expired while waiting for a character from the + client. */ + OI_BLST_ACKNOWLDGE_TIMEOUT = + 2802, /**< BLST: Timeout expired while waiting for event acknowledgment + from the client */ + OI_BLST_TX_NOT_READY = 2803, /**< BLST: BLST is not ready to send a BHAPI + message to the client. */ + OI_BLST_TX_BUSY = 2804, /**< BLST: BLST transmit buffer is in use. */ + + OI_AVDTP_CONNECTION_SEQ_ERROR = + 2901, /**< AVDTP: sequencing of signalling/media channel connections + broken. */ + OI_AVDTP_OUT_OF_RESOURCES = 2902, /**< AVDTP: Tried to allocate too many + endpoints or signalling channels. */ + + OI_PBAP_REPOSITORY_NOT_SET = + 3001, /**< PBAP: Phonebook repository must be set for operation to + complete. */ + OI_PBAP_PHONEBOOK_NOT_SET = + 3002, /**< PBAP: Phonebook be set for operation to complete. */ + + OI_AADP_BAD_ENDPOINT = 3101, /**< AADP: Invalid local endpoint specified */ + OI_AADP_BAD_STATE = + 3102, /**< AADP: AADP State is not correct for this operation. */ + + OI_UNICODE_INVALID_SOURCE = 3200, /**< Unicode Conversion: Source string has + invalid character encoding. */ + OI_UNICODE_SOURCE_EXHAUSTED = 3201, /**< Unicode Conversion: Incomplete + Unicode character at end of source + buffer. */ + OI_UNICODE_DESTINATION_EXHAUSTED = 3202, /**< Unicode Conversion: Destination + buffer not large enough to hold + resulting Unicode string. */ + + OI_AVRCP_TOO_MANY_CONNECTIONS = 3300, /**< AVRCP: Exceeded maximum number of + simultaneous AVCTP connections. */ + OI_AVRCP_NOT_IMPLEMENTED = + 3301, /**< AVRCP: The target does not implement the command specified by + the opcode and operand. */ + OI_AVRCP_REJECTED = 3302, /**< AVRCP: The target cannot respond because of + invalid operands in command packet. */ + OI_AVRCP_INVALID_RESPONSE = 3303, /**< AVRCP: The controller received the + response with invalid parameters */ + OI_AVRCP_RESPONSE_PACKET_OVERFLOW = + 3304, /**< AVRCP: The response message does not fir in one AVRCP packet + (512 bytes), has to be fragmented. */ + OI_AVRCP_RESPONSE_INVALID_PDU = 3305, /**< AVRCP: Command rejected: target + received a PDU that it did not + understand. */ + OI_AVRCP_RESPONSE_INVALID_PARAMETER = 3306, /**< AVRCP: Command rejected: + target received a PDU with a + parameter ID that it did not + understand. */ + OI_AVRCP_RESPONSE_PARAMETER_NOT_FOUND = + 3307, /**< AVRCP: Command rejected: specified parameter not found, sent if + the parameter ID is understood, but content is wrong or + corrupted.*/ + OI_AVRCP_RESPONSE_INTERNAL_ERROR = + 3308, /**< AVRCP: Command rejected: target detected other error + conditions. */ + OI_MAX_BM3_STATUS_VAL, /* Maximum BM3 status code */ + + /* Status code values reserved for BM3 SDK platform-specific implementations */ - OI_STATUS_RESERVED_FOR_APPS = 10000, - - - - OI_STATUS_NONE = 0xffff /**< Special status code to indicate that there is no status. (Only to be used for special cases involving OI_SLOG_ERROR() and OI_SLOG_WARNING().) */ + OI_STATUS_RESERVED_FOR_BCOT = 9000, + + /* Status code values reserved for BHAPI products */ + OI_STATUS_RESERVED_FOR_BHAPI = 9200, + + /* Status code values reserved for Soundabout products */ + OI_STATUS_RESERVED_FOR_SOUNDABOUT = 9400, + + /* + * Status code values greater than or equal to this value are reserved for use + * by applications. + * However, because of differences between compilers, and differences between + * 16-bit and 32-bit + * platforms custom status codes should be in the 16-bit range, so status + * codes can range from 0 + * to 65534, inclusive (65535 is reserved) + */ + OI_STATUS_RESERVED_FOR_APPS = 10000, + + OI_STATUS_NONE = 0xffff /**< Special status code to indicate that there is no + status. (Only to be used for special cases + involving OI_SLOG_ERROR() and OI_SLOG_WARNING().) + */ } OI_STATUS; - /* Remeber to update the #define below when new reserved blocks are added to * the list above. */ -#define OI_NUM_RESERVED_STATUS_BLOCKS 4 /**< Number of status code blocks reserved, including user apps */ - +#define OI_NUM_RESERVED_STATUS_BLOCKS \ + 4 /**< Number of status code blocks reserved, including user apps */ /** * Test for success */ -#define OI_SUCCESS(x) ((x) == OI_OK) +#define OI_SUCCESS(x) ((x) == OI_OK) /*****************************************************************************/ #ifdef __cplusplus @@ -577,4 +871,3 @@ typedef enum { /**@}*/ #endif /* _OI_STATUS_H */ - diff --git a/embdrv/sbc/decoder/include/oi_stddefs.h b/embdrv/sbc/decoder/include/oi_stddefs.h index f2522bcf8..ade040ddd 100644 --- a/embdrv/sbc/decoder/include/oi_stddefs.h +++ b/embdrv/sbc/decoder/include/oi_stddefs.h @@ -39,40 +39,52 @@ extern "C" { #endif #ifndef FALSE -#define FALSE 0 /**< This define statement sets FALSE as a preprocessor alias for 0. */ +#define FALSE \ + 0 /**< This define statement sets FALSE as a preprocessor alias for 0. */ #endif #ifndef TRUE -#define TRUE (!FALSE) /**< This define statement sets TRUE as a preprocessor alias for !FALSE. */ +#define TRUE \ + (!FALSE) /**< This define statement sets TRUE as a preprocessor alias for \ + !FALSE. */ #endif #ifdef HEW_TOOLCHAIN - #ifdef NULL - #undef NULL /**< Override HEW toolchain NULL definition */ - #endif - #define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */ +#ifdef NULL +#undef NULL /**< Override HEW toolchain NULL definition */ +#endif +#define NULL \ + 0 /**< HEW toolchain does not allow us to compare (void*) type to function \ + pointer */ #else - #ifndef NULL - #define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */ - #endif +#ifndef NULL +#define NULL \ + ((void*)0) /**< This define statement sets NULL as a preprocessor alias \ + for (void*)0 */ +#endif #endif /** * @name Maximum and minimum values for basic types * @{ */ -#define OI_INT8_MIN ((int8_t)0x80) /**< decimal value: -128 */ -#define OI_INT8_MAX ((int8_t)0x7F) /**< decimal value: 127 */ -#define OI_INT16_MIN ((int16_t)0x8000) /**< decimal value: -32768 */ -#define OI_INT16_MAX ((int16_t)0x7FFF) /**< decimal value: 32767 */ -#define OI_INT32_MIN ((int32_t)0x80000000) /**< decimal value: -2,147,483,648 */ -#define OI_INT32_MAX ((int32_t)0x7FFFFFFF) /**< decimal value: 2,147,483,647 */ -#define OI_UINT8_MIN ((uint8_t)0) /**< decimal value: 0 */ -#define OI_UINT8_MAX ((uint8_t)0xFF) /**< decimal value: 255 */ -#define OI_UINT16_MIN ((uint16_t)0) /**< decimal value: 0 */ -#define OI_UINT16_MAX ((uint16_t)0xFFFF) /**< decimal value: 65535 */ -#define OI_UINT32_MIN ((uint32_t)0) /**< decimal value: 0 */ -#define OI_UINT32_MAX ((uint32_t)0xFFFFFFFF) /**< decimal value: 4,294,967,295 */ +#define OI_INT8_MIN ((int8_t)0x80) /**< decimal value: -128 */ +#define OI_INT8_MAX ((int8_t)0x7F) /**< decimal value: 127 */ +#define OI_INT16_MIN ((int16_t)0x8000) /**< decimal value: -32768 */ +#define OI_INT16_MAX ((int16_t)0x7FFF) /**< decimal value: 32767 */ +#define OI_INT32_MIN \ + ((int32_t)0x80000000) /**< decimal value: -2,147,483,648 \ + */ +#define OI_INT32_MAX \ + ((int32_t)0x7FFFFFFF) /**< decimal value: 2,147,483,647 \ + */ +#define OI_UINT8_MIN ((uint8_t)0) /**< decimal value: 0 */ +#define OI_UINT8_MAX ((uint8_t)0xFF) /**< decimal value: 255 */ +#define OI_UINT16_MIN ((uint16_t)0) /**< decimal value: 0 */ +#define OI_UINT16_MAX ((uint16_t)0xFFFF) /**< decimal value: 65535 */ +#define OI_UINT32_MIN ((uint32_t)0) /**< decimal value: 0 */ +#define OI_UINT32_MAX \ + ((uint32_t)0xFFFFFFFF) /**< decimal value: 4,294,967,295 */ /** * @} @@ -85,52 +97,71 @@ extern "C" { /** unsigned 64-bit integer as a structure of two unsigned 32-bit integers */ typedef struct { - uint32_t I1; /**< most significant 32 bits */ - uint32_t I2; /**< least significant 32 bits */ + uint32_t I1; /**< most significant 32 bits */ + uint32_t I2; /**< least significant 32 bits */ } OI_UINT64; -#define OI_UINT64_MIN { (uint32_t)0x00000000, (uint32_t)0x00000000 } -#define OI_UINT64_MAX { (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF } +#define OI_UINT64_MIN \ + { (uint32_t)0x00000000, (uint32_t)0x00000000 } +#define OI_UINT64_MAX \ + { (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF } /* signed 64-bit integer as a structure of one unsigned 32-bit integer and one * signed 32-bit integer */ typedef struct { - int32_t I1; /**< most significant 32 bits as a signed integer */ - uint32_t I2; /**< least significant 32 bits as an unsigned integer */ + int32_t I1; /**< most significant 32 bits as a signed integer */ + uint32_t I2; /**< least significant 32 bits as an unsigned integer */ } OI_INT64; -#define OI_INT64_MIN { (int32_t)0x80000000, (uint32_t)0x00000000 } -#define OI_INT64_MAX { (int32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF } +#define OI_INT64_MIN \ + { (int32_t)0x80000000, (uint32_t)0x00000000 } +#define OI_INT64_MAX \ + { (int32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF } /** unsigned 128-bit integer as a structure of four unsigned 32-bit integers */ typedef struct { - uint32_t I1; /**< most significant 32 bits */ - uint32_t I2; /**< second-most significant 32 bits */ - uint32_t I3; /**< third-most significant 32 bits */ - uint32_t I4; /**< least significant 32 bits */ + uint32_t I1; /**< most significant 32 bits */ + uint32_t I2; /**< second-most significant 32 bits */ + uint32_t I3; /**< third-most significant 32 bits */ + uint32_t I4; /**< least significant 32 bits */ } OI_UINT128; -#define OI_UINT128_MIN { (uint32_t)0x00000000, (uint32_t)0x00000000, (uint32_t)0x00000000, (uint32_t)0x00000000 } -#define OI_UINT128_MAX { (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF } +#define OI_UINT128_MIN \ + { \ + (uint32_t)0x00000000, (uint32_t)0x00000000, (uint32_t)0x00000000, \ + (uint32_t)0x00000000 \ + } +#define OI_UINT128_MAX \ + { \ + (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, \ + (uint32_t)0XFFFFFFFF \ + } /* signed 128-bit integer as a structure of three unsigned 32-bit integers and * one signed 32-bit integer */ typedef struct { - int32_t I1; /**< most significant 32 bits as a signed integer */ - uint32_t I2; /**< second-most significant 32 bits as an unsigned integer */ - uint32_t I3; /**< third-most significant 32 bits as an unsigned integer */ - uint32_t I4; /**< least significant 32 bits as an unsigned integer */ + int32_t I1; /**< most significant 32 bits as a signed integer */ + uint32_t I2; /**< second-most significant 32 bits as an unsigned integer */ + uint32_t I3; /**< third-most significant 32 bits as an unsigned integer */ + uint32_t I4; /**< least significant 32 bits as an unsigned integer */ } OI_INT128; -#define OI_INT128_MIN { (uint32_t)0x80000000, (uint32_t)0x00000000, (uint32_t)0x00000000, (uint32_t)0x00000000 } -#define OI_INT128_MAX { (uint32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF } +#define OI_INT128_MIN \ + { \ + (uint32_t)0x80000000, (uint32_t)0x00000000, (uint32_t)0x00000000, \ + (uint32_t)0x00000000 \ + } +#define OI_INT128_MAX \ + { \ + (uint32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, \ + (uint32_t)0XFFFFFFFF \ + } /** * @} */ - /** * type for ASCII character data items */ @@ -144,11 +175,10 @@ typedef uint16_t OI_CHAR16; /** * types for UTF encoded strings. */ -typedef uint8_t OI_UTF8; +typedef uint8_t OI_UTF8; typedef uint16_t OI_UTF16; typedef uint32_t OI_UTF32; - /** * @name Single-bit operation macros * @{ @@ -158,18 +188,18 @@ typedef uint32_t OI_UTF32; /* This macro's value is true if the bit specified by y is set in data item x. */ -#define OI_BIT_TEST(x,y) ((x) & (y)) +#define OI_BIT_TEST(x, y) ((x) & (y)) /* This macro's value is true if the bit specified by y is not set in data item * x. */ -#define OI_BIT_CLEAR_TEST(x,y) (((x) & (y)) == 0) +#define OI_BIT_CLEAR_TEST(x, y) (((x) & (y)) == 0) /** This macro sets the bit specified by y in data item x. */ -#define OI_BIT_SET(x,y) ((x) |= (y)) +#define OI_BIT_SET(x, y) ((x) |= (y)) /** This macro clears the bit specified by y in data item x. */ -#define OI_BIT_CLEAR(x,y) ((x) &= ~(y)) +#define OI_BIT_CLEAR(x, y) ((x) &= ~(y)) /** @} */ @@ -179,7 +209,7 @@ typedef uint32_t OI_UTF32; */ #ifndef OI_ARRAYSIZE -#define OI_ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0])) +#define OI_ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0])) #endif /** @@ -190,45 +220,107 @@ typedef uint32_t OI_UTF32; #ifndef BIT0 -#define BIT0 0x00000001 /**< preprocessor alias for 32-bit value with bit 0 set, used to specify this single bit */ -#define BIT1 0x00000002 /**< preprocessor alias for 32-bit value with bit 1 set, used to specify this single bit */ -#define BIT2 0x00000004 /**< preprocessor alias for 32-bit value with bit 2 set, used to specify this single bit */ -#define BIT3 0x00000008 /**< preprocessor alias for 32-bit value with bit 3 set, used to specify this single bit */ -#define BIT4 0x00000010 /**< preprocessor alias for 32-bit value with bit 4 set, used to specify this single bit */ -#define BIT5 0x00000020 /**< preprocessor alias for 32-bit value with bit 5 set, used to specify this single bit */ -#define BIT6 0x00000040 /**< preprocessor alias for 32-bit value with bit 6 set, used to specify this single bit */ -#define BIT7 0x00000080 /**< preprocessor alias for 32-bit value with bit 7 set, used to specify this single bit */ -#define BIT8 0x00000100 /**< preprocessor alias for 32-bit value with bit 8 set, used to specify this single bit */ -#define BIT9 0x00000200 /**< preprocessor alias for 32-bit value with bit 9 set, used to specify this single bit */ -#define BIT10 0x00000400 /**< preprocessor alias for 32-bit value with bit 10 set, used to specify this single bit */ -#define BIT11 0x00000800 /**< preprocessor alias for 32-bit value with bit 11 set, used to specify this single bit */ -#define BIT12 0x00001000 /**< preprocessor alias for 32-bit value with bit 12 set, used to specify this single bit */ -#define BIT13 0x00002000 /**< preprocessor alias for 32-bit value with bit 13 set, used to specify this single bit */ -#define BIT14 0x00004000 /**< preprocessor alias for 32-bit value with bit 14 set, used to specify this single bit */ -#define BIT15 0x00008000 /**< preprocessor alias for 32-bit value with bit 15 set, used to specify this single bit */ -#define BIT16 0x00010000 /**< preprocessor alias for 32-bit value with bit 16 set, used to specify this single bit */ -#define BIT17 0x00020000 /**< preprocessor alias for 32-bit value with bit 17 set, used to specify this single bit */ -#define BIT18 0x00040000 /**< preprocessor alias for 32-bit value with bit 18 set, used to specify this single bit */ -#define BIT19 0x00080000 /**< preprocessor alias for 32-bit value with bit 19 set, used to specify this single bit */ -#define BIT20 0x00100000 /**< preprocessor alias for 32-bit value with bit 20 set, used to specify this single bit */ -#define BIT21 0x00200000 /**< preprocessor alias for 32-bit value with bit 21 set, used to specify this single bit */ -#define BIT22 0x00400000 /**< preprocessor alias for 32-bit value with bit 22 set, used to specify this single bit */ -#define BIT23 0x00800000 /**< preprocessor alias for 32-bit value with bit 23 set, used to specify this single bit */ -#define BIT24 0x01000000 /**< preprocessor alias for 32-bit value with bit 24 set, used to specify this single bit */ -#define BIT25 0x02000000 /**< preprocessor alias for 32-bit value with bit 25 set, used to specify this single bit */ -#define BIT26 0x04000000 /**< preprocessor alias for 32-bit value with bit 26 set, used to specify this single bit */ -#define BIT27 0x08000000 /**< preprocessor alias for 32-bit value with bit 27 set, used to specify this single bit */ -#define BIT28 0x10000000 /**< preprocessor alias for 32-bit value with bit 28 set, used to specify this single bit */ -#define BIT29 0x20000000 /**< preprocessor alias for 32-bit value with bit 29 set, used to specify this single bit */ -#define BIT30 0x40000000 /**< preprocessor alias for 32-bit value with bit 30 set, used to specify this single bit */ -#define BIT31 0x80000000 /**< preprocessor alias for 32-bit value with bit 31 set, used to specify this single bit */ - -#endif /* BIT0 et al */ - +#define BIT0 \ + 0x00000001 /**< preprocessor alias for 32-bit value with bit 0 set, used to \ + specify this single bit */ +#define BIT1 \ + 0x00000002 /**< preprocessor alias for 32-bit value with bit 1 set, used to \ + specify this single bit */ +#define BIT2 \ + 0x00000004 /**< preprocessor alias for 32-bit value with bit 2 set, used to \ + specify this single bit */ +#define BIT3 \ + 0x00000008 /**< preprocessor alias for 32-bit value with bit 3 set, used to \ + specify this single bit */ +#define BIT4 \ + 0x00000010 /**< preprocessor alias for 32-bit value with bit 4 set, used to \ + specify this single bit */ +#define BIT5 \ + 0x00000020 /**< preprocessor alias for 32-bit value with bit 5 set, used to \ + specify this single bit */ +#define BIT6 \ + 0x00000040 /**< preprocessor alias for 32-bit value with bit 6 set, used to \ + specify this single bit */ +#define BIT7 \ + 0x00000080 /**< preprocessor alias for 32-bit value with bit 7 set, used to \ + specify this single bit */ +#define BIT8 \ + 0x00000100 /**< preprocessor alias for 32-bit value with bit 8 set, used to \ + specify this single bit */ +#define BIT9 \ + 0x00000200 /**< preprocessor alias for 32-bit value with bit 9 set, used to \ + specify this single bit */ +#define BIT10 \ + 0x00000400 /**< preprocessor alias for 32-bit value with bit 10 set, used to \ + specify this single bit */ +#define BIT11 \ + 0x00000800 /**< preprocessor alias for 32-bit value with bit 11 set, used to \ + specify this single bit */ +#define BIT12 \ + 0x00001000 /**< preprocessor alias for 32-bit value with bit 12 set, used to \ + specify this single bit */ +#define BIT13 \ + 0x00002000 /**< preprocessor alias for 32-bit value with bit 13 set, used to \ + specify this single bit */ +#define BIT14 \ + 0x00004000 /**< preprocessor alias for 32-bit value with bit 14 set, used to \ + specify this single bit */ +#define BIT15 \ + 0x00008000 /**< preprocessor alias for 32-bit value with bit 15 set, used to \ + specify this single bit */ +#define BIT16 \ + 0x00010000 /**< preprocessor alias for 32-bit value with bit 16 set, used to \ + specify this single bit */ +#define BIT17 \ + 0x00020000 /**< preprocessor alias for 32-bit value with bit 17 set, used to \ + specify this single bit */ +#define BIT18 \ + 0x00040000 /**< preprocessor alias for 32-bit value with bit 18 set, used to \ + specify this single bit */ +#define BIT19 \ + 0x00080000 /**< preprocessor alias for 32-bit value with bit 19 set, used to \ + specify this single bit */ +#define BIT20 \ + 0x00100000 /**< preprocessor alias for 32-bit value with bit 20 set, used to \ + specify this single bit */ +#define BIT21 \ + 0x00200000 /**< preprocessor alias for 32-bit value with bit 21 set, used to \ + specify this single bit */ +#define BIT22 \ + 0x00400000 /**< preprocessor alias for 32-bit value with bit 22 set, used to \ + specify this single bit */ +#define BIT23 \ + 0x00800000 /**< preprocessor alias for 32-bit value with bit 23 set, used to \ + specify this single bit */ +#define BIT24 \ + 0x01000000 /**< preprocessor alias for 32-bit value with bit 24 set, used to \ + specify this single bit */ +#define BIT25 \ + 0x02000000 /**< preprocessor alias for 32-bit value with bit 25 set, used to \ + specify this single bit */ +#define BIT26 \ + 0x04000000 /**< preprocessor alias for 32-bit value with bit 26 set, used to \ + specify this single bit */ +#define BIT27 \ + 0x08000000 /**< preprocessor alias for 32-bit value with bit 27 set, used to \ + specify this single bit */ +#define BIT28 \ + 0x10000000 /**< preprocessor alias for 32-bit value with bit 28 set, used to \ + specify this single bit */ +#define BIT29 \ + 0x20000000 /**< preprocessor alias for 32-bit value with bit 29 set, used to \ + specify this single bit */ +#define BIT30 \ + 0x40000000 /**< preprocessor alias for 32-bit value with bit 30 set, used to \ + specify this single bit */ +#define BIT31 \ + 0x80000000 /**< preprocessor alias for 32-bit value with bit 31 set, used to \ + specify this single bit */ + +#endif /* BIT0 et al */ /** @} */ - #ifdef __cplusplus } #endif diff --git a/embdrv/sbc/decoder/include/oi_string.h b/embdrv/sbc/decoder/include/oi_string.h index a876ac9fc..fe1e4c12d 100644 --- a/embdrv/sbc/decoder/include/oi_string.h +++ b/embdrv/sbc/decoder/include/oi_string.h @@ -43,7 +43,6 @@ extern "C" { #endif - /* * If we are using Native malloc(), we must also use * native Ansi string.h functions for memory manipulation. @@ -56,15 +55,15 @@ extern "C" { #ifdef USE_NATIVE_MEMCPY -#define OI_MemCopy(to, from, size) memcpy((to), (from), (size)) -#define OI_MemSet(block, val, size) memset((block), (val), (size)) -#define OI_MemZero(block, size) memset((block), 0, (size)) -#define OI_MemCmp(s1, s2, n) memcmp((s1), (s2), (n)) -#define OI_Strcpy(dest, src) strcpy((dest),(src)) -#define OI_Strcat(dest, src) strcat((dest),(src)) -#define OI_StrLen(str) strlen((str)) -#define OI_Strcmp(s1, s2) strcmp((s1), (s2)) -#define OI_Strncmp(s1, s2, n) strncmp((s1), (s2), (n)) +#define OI_MemCopy(to, from, size) memcpy((to), (from), (size)) +#define OI_MemSet(block, val, size) memset((block), (val), (size)) +#define OI_MemZero(block, size) memset((block), 0, (size)) +#define OI_MemCmp(s1, s2, n) memcmp((s1), (s2), (n)) +#define OI_Strcpy(dest, src) strcpy((dest), (src)) +#define OI_Strcat(dest, src) strcat((dest), (src)) +#define OI_StrLen(str) strlen((str)) +#define OI_Strcmp(s1, s2) strcmp((s1), (s2)) +#define OI_Strncmp(s1, s2, n) strncmp((s1), (s2), (n)) #else @@ -75,24 +74,21 @@ extern "C" { * The underlying implementation is the ANSI memmove() or equivalant, so * overlapping memory copies will work correctly. */ -void OI_MemCopy(void *To, void const *From, uint32_t Size); - +void OI_MemCopy(void* To, void const* From, uint32_t Size); /* * OI_MemSet * * Sets all bytes in a block of memory to the same value */ -void OI_MemSet(void *Block, uint8_t Val, uint32_t Size); - +void OI_MemSet(void* Block, uint8_t Val, uint32_t Size); /* * OI_MemZero * * Sets all bytes in a block of memory to zero */ -void OI_MemZero(void *Block, uint32_t Size); - +void OI_MemZero(void* Block, uint32_t Size); /* * OI_MemCmp @@ -104,7 +100,7 @@ void OI_MemZero(void *Block, uint32_t Size); * < 0, if s1 < s2 * > 0, if s2 > s2 */ -OI_INT OI_MemCmp(void const *s1, void const *s2, uint32_t n); +OI_INT OI_MemCmp(void const* s1, void const* s2, uint32_t n); /* * OI_Strcpy @@ -113,8 +109,7 @@ OI_INT OI_MemCmp(void const *s1, void const *s2, uint32_t n); * returns pDest. */ -OI_CHAR* OI_Strcpy(OI_CHAR *pDest, - OI_CHAR const *pStr); +OI_CHAR* OI_Strcpy(OI_CHAR* pDest, OI_CHAR const* pStr); /* * OI_Strcat @@ -123,8 +118,7 @@ OI_CHAR* OI_Strcpy(OI_CHAR *pDest, * returns pDest. */ -OI_CHAR* OI_Strcat(OI_CHAR *pDest, - OI_CHAR const *pStr) ; +OI_CHAR* OI_Strcat(OI_CHAR* pDest, OI_CHAR const* pStr); /* * OI_StrLen @@ -132,7 +126,7 @@ OI_CHAR* OI_Strcat(OI_CHAR *pDest, * Calculates the number of OI_CHARs in pStr (not including * the Null terminator) and returns the value. */ -OI_UINT OI_StrLen(OI_CHAR const *pStr) ; +OI_UINT OI_StrLen(OI_CHAR const* pStr); /* * OI_Strcmp @@ -144,8 +138,7 @@ OI_UINT OI_StrLen(OI_CHAR const *pStr) ; * < 0, if s1 < s2 * > 0, if s2 > s2 */ -OI_INT OI_Strcmp(OI_CHAR const *s1, - OI_CHAR const *s2); +OI_INT OI_Strcmp(OI_CHAR const* s1, OI_CHAR const* s2); /* * OI_Strncmp @@ -157,10 +150,7 @@ OI_INT OI_Strcmp(OI_CHAR const *s1, * < 0, if s1 < s2 * > 0, if s2 > s2 */ -OI_INT OI_Strncmp(OI_CHAR const *s1, - OI_CHAR const *s2, - uint32_t len); - +OI_INT OI_Strncmp(OI_CHAR const* s1, OI_CHAR const* s2, uint32_t len); #endif /* USE_NATIVE_MEMCPY */ @@ -176,8 +166,7 @@ OI_INT OI_Strncmp(OI_CHAR const *s1, * < 0, if s1 < s2 * > 0, if s2 > s2 */ -OI_INT OI_StrcmpInsensitive(OI_CHAR const *s1, - OI_CHAR const *s2); +OI_INT OI_StrcmpInsensitive(OI_CHAR const* s1, OI_CHAR const* s2); /* * OI_StrncmpInsensitive @@ -192,11 +181,7 @@ OI_INT OI_StrcmpInsensitive(OI_CHAR const *s1, * < 0, if s1 < s2 * > 0, if s2 > s2 */ -OI_INT OI_StrncmpInsensitive(OI_CHAR const *s1, - OI_CHAR const *s2, - OI_UINT len); - - +OI_INT OI_StrncmpInsensitive(OI_CHAR const* s1, OI_CHAR const* s2, OI_UINT len); #ifdef __cplusplus } @@ -206,4 +191,3 @@ OI_INT OI_StrncmpInsensitive(OI_CHAR const *s1, /*****************************************************************************/ #endif /* OI_STRING_H */ - diff --git a/embdrv/sbc/decoder/include/oi_time.h b/embdrv/sbc/decoder/include/oi_time.h index 4c4996e1a..9b189af79 100644 --- a/embdrv/sbc/decoder/include/oi_time.h +++ b/embdrv/sbc/decoder/include/oi_time.h @@ -41,7 +41,6 @@ #include "oi_stddefs.h" - /** \addtogroup Misc Miscellaneous APIs */ /**@{*/ @@ -49,41 +48,39 @@ extern "C" { #endif - - /** * Within the core stack, timeouts are specified in intervals of tenths of * seconds. */ typedef uint16_t OI_INTERVAL; -#define OI_INTERVALS_PER_SECOND 10 -#define MSECS_PER_OI_INTERVAL (1000 / OI_INTERVALS_PER_SECOND) +#define OI_INTERVALS_PER_SECOND 10 +#define MSECS_PER_OI_INTERVAL (1000 / OI_INTERVALS_PER_SECOND) /** maximum interval (54 min 36.7 sec) */ -#define OI_MAX_INTERVAL 0x7fff - +#define OI_MAX_INTERVAL 0x7fff /** * Macro to convert seconds to OI_INTERVAL time units */ -#define OI_SECONDS(n) ((OI_INTERVAL) ((n) * OI_INTERVALS_PER_SECOND)) +#define OI_SECONDS(n) ((OI_INTERVAL)((n)*OI_INTERVALS_PER_SECOND)) /** * Macro to convert milliseconds to OI_INTERVAL time units (Rounded Up) */ -#define OI_MSECONDS(n) ((OI_INTERVAL) (((n) + MSECS_PER_OI_INTERVAL - 1) / MSECS_PER_OI_INTERVAL)) +#define OI_MSECONDS(n) \ + ((OI_INTERVAL)(((n) + MSECS_PER_OI_INTERVAL - 1) / MSECS_PER_OI_INTERVAL)) /** * Macro to convert minutes to OI_INTERVAL time units */ -#define OI_MINUTES(n) ((OI_INTERVAL) ((n) * OI_SECONDS(60))) +#define OI_MINUTES(n) ((OI_INTERVAL)((n)*OI_SECONDS(60))) /** Convert an OI_INTERVAL to milliseconds. */ -#define OI_INTERVAL_TO_MILLISECONDS(i) ((i) * MSECS_PER_OI_INTERVAL) +#define OI_INTERVAL_TO_MILLISECONDS(i) ((i)*MSECS_PER_OI_INTERVAL) /** * The stack depends on relative not absolute time. Any mapping between the @@ -92,8 +89,8 @@ typedef uint16_t OI_INTERVAL; */ typedef struct { - int32_t seconds; - int16_t mseconds; + int32_t seconds; + int16_t mseconds; } OI_TIME; /** @@ -103,8 +100,7 @@ typedef struct { * * @return the time in milliseconds */ -uint32_t OI_Time_ToMS(OI_TIME *t); - +uint32_t OI_Time_ToMS(OI_TIME* t); /** * This function compares two time values. @@ -121,9 +117,7 @@ uint32_t OI_Time_ToMS(OI_TIME *t); @endverbatim */ -int16_t OI_Time_Compare(OI_TIME *T1, - OI_TIME *T2); - +int16_t OI_Time_Compare(OI_TIME* T1, OI_TIME* T2); /** * This function returns the interval between two times to a granularity of 0.1 @@ -139,10 +133,7 @@ int16_t OI_Time_Compare(OI_TIME *T1, * @return the time interval between the two times = (Later - Sooner) */ -OI_INTERVAL OI_Time_Interval(OI_TIME *Sooner, - OI_TIME *Later); - - +OI_INTERVAL OI_Time_Interval(OI_TIME* Sooner, OI_TIME* Later); /** * This function returns the interval between two times to a granularity of @@ -158,10 +149,7 @@ OI_INTERVAL OI_Time_Interval(OI_TIME *Sooner, * @return the time interval between the two times = (Later - Sooner) */ -uint32_t OI_Time_IntervalMsecs(OI_TIME *Sooner, - OI_TIME *Later); - - +uint32_t OI_Time_IntervalMsecs(OI_TIME* Sooner, OI_TIME* Later); /** * This function answers this question: @@ -173,22 +161,22 @@ uint32_t OI_Time_IntervalMsecs(OI_TIME *Sooner, * false means target time is still some time in the future */ -OI_BOOL OI_Time_NowReachedTime(OI_TIME *pTargetTime); +OI_BOOL OI_Time_NowReachedTime(OI_TIME* pTargetTime); /** * Convert seconds to the Link Manager 1.28-second units * Approximate by using 1.25 conversion factor. */ -#define OI_SECONDS_TO_LM_TIME_UNITS(lmUnits) ((lmUnits)<4?(lmUnits):(lmUnits)-((lmUnits)>>2)) - +#define OI_SECONDS_TO_LM_TIME_UNITS(lmUnits) \ + ((lmUnits) < 4 ? (lmUnits) : (lmUnits) - ((lmUnits) >> 2)) /** * Convert Link Manager 1.28-second units to seconds. * Approximate by using 1.25 conversion factor. */ -#define OI_LM_TIME_UNITS_TO_SECONDS(lmUnits) ((lmUnits) + ((lmUnits)>>2)) +#define OI_LM_TIME_UNITS_TO_SECONDS(lmUnits) ((lmUnits) + ((lmUnits) >> 2)) #ifdef __cplusplus } @@ -203,4 +191,3 @@ OI_BOOL OI_Time_NowReachedTime(OI_TIME *pTargetTime); /*****************************************************************************/ #endif /* _OI_TIME_H */ - diff --git a/embdrv/sbc/decoder/include/oi_utils.h b/embdrv/sbc/decoder/include/oi_utils.h index 19f8b916a..d91780ff4 100644 --- a/embdrv/sbc/decoder/include/oi_utils.h +++ b/embdrv/sbc/decoder/include/oi_utils.h @@ -33,9 +33,9 @@ ******************************************************************************/ #include +#include "oi_bt_spec.h" #include "oi_common.h" #include "oi_string.h" -#include "oi_bt_spec.h" /** \addtogroup Misc Miscellaneous APIs */ /**@{*/ @@ -49,15 +49,13 @@ extern "C" { */ typedef uint32_t OI_CALLBACK_HANDLE; - /** * Function prototype for a timed procedure callback. * * @param arg Value that was passed into the OI_ScheduleCallback() function * */ -typedef void (*OI_SCHEDULED_CALLBACK)(void *arg); - +typedef void (*OI_SCHEDULED_CALLBACK)(void* arg); /** * Registers a function to be called when a timeout expires. This API uses @@ -83,10 +81,8 @@ typedef void (*OI_SCHEDULED_CALLBACK)(void *arg); * status. */ OI_STATUS OI_ScheduleCallbackFunction(OI_SCHEDULED_CALLBACK callbackFunction, - void *arg, - OI_INTERVAL timeout, - OI_CALLBACK_HANDLE *handle); - + void* arg, OI_INTERVAL timeout, + OI_CALLBACK_HANDLE* handle); /** * Cancels a function registered with OI_ScheduleCallbackFunction() before its @@ -99,7 +95,6 @@ OI_STATUS OI_ScheduleCallbackFunction(OI_SCHEDULED_CALLBACK callbackFunction, */ OI_STATUS OI_CancelCallbackFunction(OI_CALLBACK_HANDLE handle); - /** * Registers a function to be called when a timeout expires. This version does * not return a handle so can only be canceled by calling OI_CancelCallback(). @@ -118,8 +113,7 @@ OI_STATUS OI_CancelCallbackFunction(OI_CALLBACK_HANDLE handle); * @return OI_OK if the function was reqistered, or an error * status. */ -#define OI_ScheduleCallback(f, a, t) OI_ScheduleCallbackFunction(f, a, t, NULL); - +#define OI_ScheduleCallback(f, a, t) OI_ScheduleCallbackFunction(f, a, t, NULL); /** * Cancels a function registered with OI_ScheduleCallback() before its timer @@ -133,7 +127,6 @@ OI_STATUS OI_CancelCallbackFunction(OI_CALLBACK_HANDLE handle); */ OI_STATUS OI_CancelCallback(OI_SCHEDULED_CALLBACK callbackFunction); - /** * Parse a Bluetooth device address from the specified string. * @@ -143,8 +136,7 @@ OI_STATUS OI_CancelCallback(OI_SCHEDULED_CALLBACK callbackFunction); * @return true if an address was successfully parsed, false otherwise */ -OI_BOOL OI_ParseBdAddr(const OI_CHAR *str, - OI_BD_ADDR *addr) ; +OI_BOOL OI_ParseBdAddr(const OI_CHAR* str, OI_BD_ADDR* addr); /** * Printf function for platforms which have no stdio or printf available. @@ -222,8 +214,7 @@ OI_BOOL OI_ParseBdAddr(const OI_CHAR *str, * @param format The format string * */ -void OI_Printf(const OI_CHAR *format, ...); - +void OI_Printf(const OI_CHAR* format, ...); /** * Var-args version OI_Printf @@ -232,8 +223,7 @@ void OI_Printf(const OI_CHAR *format, ...); * * @param argp Var-args list. */ -void OI_VPrintf(const OI_CHAR *format, va_list argp); - +void OI_VPrintf(const OI_CHAR* format, va_list argp); /** * Writes a formatted string to a buffer. This function supports the same format @@ -247,10 +237,8 @@ void OI_VPrintf(const OI_CHAR *format, va_list argp); * * @return Number of characters written or -1 in the case of an error. */ -int32_t OI_SNPrintf(OI_CHAR *buffer, - uint16_t bufLen, - const OI_CHAR* format, ...); - +int32_t OI_SNPrintf(OI_CHAR* buffer, uint16_t bufLen, const OI_CHAR* format, + ...); /** * Var-args version OI_SNPrintf @@ -265,10 +253,8 @@ int32_t OI_SNPrintf(OI_CHAR *buffer, * * @return Number of characters written or -1 in the case of an error. */ -int32_t OI_VSNPrintf(OI_CHAR *buffer, - uint16_t bufLen, - const OI_CHAR *format, va_list argp); - +int32_t OI_VSNPrintf(OI_CHAR* buffer, uint16_t bufLen, const OI_CHAR* format, + va_list argp); /** * Convert a string to an integer. @@ -278,8 +264,7 @@ int32_t OI_VSNPrintf(OI_CHAR *buffer, * @return the integer value of the string or 0 if the string could not be * parsed */ -OI_INT OI_atoi(const OI_CHAR *str); - +OI_INT OI_atoi(const OI_CHAR* str); /** * Parse a signed integer in a string. @@ -296,9 +281,7 @@ OI_INT OI_atoi(const OI_CHAR *str); * @return A pointer to the first character following the integer or the * pointer passed in. */ -const OI_CHAR* OI_ScanInt(const OI_CHAR *str, - int32_t *val); - +const OI_CHAR* OI_ScanInt(const OI_CHAR* str, int32_t* val); /** * Parse an unsigned integer in a string. @@ -315,8 +298,7 @@ const OI_CHAR* OI_ScanInt(const OI_CHAR *str, * @return A pointer to the first character following the unsigned * integer or the pointer passed in. */ -const OI_CHAR* OI_ScanUInt(const OI_CHAR *str, - uint32_t *val); +const OI_CHAR* OI_ScanUInt(const OI_CHAR* str, uint32_t* val); /** * Parse a whitespace delimited substring out of a string. @@ -329,10 +311,7 @@ const OI_CHAR* OI_ScanUInt(const OI_CHAR *str, * @return A pointer to the first character following the substring or * the pointer passed in. */ -const OI_CHAR* OI_ScanStr(const OI_CHAR *str, - OI_CHAR *outStr, - uint16_t len); - +const OI_CHAR* OI_ScanStr(const OI_CHAR* str, OI_CHAR* outStr, uint16_t len); /** * Parse a string for one of a set of alternative value. Skips leading @@ -350,9 +329,8 @@ const OI_CHAR* OI_ScanStr(const OI_CHAR *str, * @return A pointer to the first character following the matched value or * the pointer passed in if there was no matching text. */ -const OI_CHAR* OI_ScanAlt(const OI_CHAR *str, - const OI_CHAR *alts, - OI_INT *index); +const OI_CHAR* OI_ScanAlt(const OI_CHAR* str, const OI_CHAR* alts, + OI_INT* index); /** * Parse a string for a BD Addr. Skips leading whitespace (space and tabs only) @@ -366,9 +344,7 @@ const OI_CHAR* OI_ScanAlt(const OI_CHAR *str, * @return A pointer to the first character following the BD Addr or the * pointer passed in. */ -const OI_CHAR* OI_ScanBdAddr(const OI_CHAR *str, - OI_BD_ADDR *addr); - +const OI_CHAR* OI_ScanBdAddr(const OI_CHAR* str, OI_BD_ADDR* addr); /** Get a character from a digit integer value (0 - 9). */ #define OI_DigitToChar(d) ((d) + '0') @@ -381,15 +357,15 @@ const OI_CHAR* OI_ScanBdAddr(const OI_CHAR *str, * * @return the max or min value between a & b */ -#define OI_MAX(a, b) (((a) < (b)) ? (b) : (a) ) -#define OI_MIN(a, b) (((a) > (b)) ? (b) : (a) ) +#define OI_MAX(a, b) (((a) < (b)) ? (b) : (a)) +#define OI_MIN(a, b) (((a) > (b)) ? (b) : (a)) /** * Compare two BD_ADDRs * SAME_BD_ADDR - Boolean: true if they are the same address */ -#define SAME_BD_ADDR(x, y) (0 == OI_MemCmp((x),(y),OI_BD_ADDR_BYTE_SIZE) ) +#define SAME_BD_ADDR(x, y) (0 == OI_MemCmp((x), (y), OI_BD_ADDR_BYTE_SIZE)) #ifdef __cplusplus } @@ -398,4 +374,3 @@ const OI_CHAR* OI_ScanBdAddr(const OI_CHAR *str, /**@}*/ #endif /* _OI_UTILS_H */ - diff --git a/embdrv/sbc/decoder/srce/alloc.c b/embdrv/sbc/decoder/srce/alloc.c index aef79b1d8..db0d7f06c 100644 --- a/embdrv/sbc/decoder/srce/alloc.c +++ b/embdrv/sbc/decoder/srce/alloc.c @@ -19,61 +19,64 @@ ******************************************************************************/ #include -#include + +#include "oi_codec_sbc_private.h" /******************************************************************************* $Revision: #1 $ ******************************************************************************/ -PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common, - uint32_t *codecDataAligned, +PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT* common, + uint32_t* codecDataAligned, uint32_t codecDataBytes, - uint8_t maxChannels, - uint8_t pcmStride) -{ - int i; - size_t filterBufferCount; - size_t subdataSize; - OI_BYTE *codecData = (OI_BYTE*)codecDataAligned; + uint8_t maxChannels, uint8_t pcmStride) { + int i; + size_t filterBufferCount; + size_t subdataSize; + OI_BYTE* codecData = (OI_BYTE*)codecDataAligned; - if (maxChannels < 1 || maxChannels > 2) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (maxChannels < 1 || maxChannels > 2) { + return OI_STATUS_INVALID_PARAMETERS; + } - if (pcmStride < 1 || pcmStride > maxChannels) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (pcmStride < 1 || pcmStride > maxChannels) { + return OI_STATUS_INVALID_PARAMETERS; + } - common->maxChannels = maxChannels; - common->pcmStride = pcmStride; + common->maxChannels = maxChannels; + common->pcmStride = pcmStride; - /* Compute sizes needed for the memory regions, and bail if we don't have - * enough memory for them. */ - subdataSize = maxChannels * sizeof(common->subdata[0]) * SBC_MAX_BANDS * SBC_MAX_BLOCKS; - if (subdataSize > codecDataBytes) { - return OI_STATUS_OUT_OF_MEMORY; - } + /* Compute sizes needed for the memory regions, and bail if we don't have + * enough memory for them. */ + subdataSize = + maxChannels * sizeof(common->subdata[0]) * SBC_MAX_BANDS * SBC_MAX_BLOCKS; + if (subdataSize > codecDataBytes) { + return OI_STATUS_OUT_OF_MEMORY; + } - filterBufferCount = (codecDataBytes - subdataSize) / (sizeof(common->filterBuffer[0][0]) * SBC_MAX_BANDS * maxChannels); - if (filterBufferCount < SBC_CODEC_MIN_FILTER_BUFFERS) { - return OI_STATUS_OUT_OF_MEMORY; - } - common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS; + filterBufferCount = + (codecDataBytes - subdataSize) / + (sizeof(common->filterBuffer[0][0]) * SBC_MAX_BANDS * maxChannels); + if (filterBufferCount < SBC_CODEC_MIN_FILTER_BUFFERS) { + return OI_STATUS_OUT_OF_MEMORY; + } + common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS; - /* Allocate memory for the subband data */ - common->subdata = (int32_t*)codecData; - codecData += subdataSize; - OI_ASSERT(codecDataBytes >= subdataSize); - codecDataBytes -= subdataSize; + /* Allocate memory for the subband data */ + common->subdata = (int32_t*)codecData; + codecData += subdataSize; + OI_ASSERT(codecDataBytes >= subdataSize); + codecDataBytes -= subdataSize; - /* Allocate memory for the synthesis buffers */ - for (i = 0; i < maxChannels; ++i) { - size_t allocSize = common->filterBufferLen * sizeof(common->filterBuffer[0][0]); - common->filterBuffer[i] = (SBC_BUFFER_T*)codecData; - OI_ASSERT(codecDataBytes >= allocSize); - codecData += allocSize; - codecDataBytes -= allocSize; - } + /* Allocate memory for the synthesis buffers */ + for (i = 0; i < maxChannels; ++i) { + size_t allocSize = + common->filterBufferLen * sizeof(common->filterBuffer[0][0]); + common->filterBuffer[i] = (SBC_BUFFER_T*)codecData; + OI_ASSERT(codecDataBytes >= allocSize); + codecData += allocSize; + codecDataBytes -= allocSize; + } - return OI_OK; + return OI_OK; } diff --git a/embdrv/sbc/decoder/srce/bitalloc-sbc.c b/embdrv/sbc/decoder/srce/bitalloc-sbc.c index ed381cd97..3e7e6f49c 100644 --- a/embdrv/sbc/decoder/srce/bitalloc-sbc.c +++ b/embdrv/sbc/decoder/srce/bitalloc-sbc.c @@ -31,136 +31,131 @@ #include -static void dualBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - OI_UINT bitcountL; - OI_UINT bitcountR; - OI_UINT bitpoolPreferenceL = 0; - OI_UINT bitpoolPreferenceR = 0; - BITNEED_UNION1 bitneedsL; - BITNEED_UNION1 bitneedsR; - - bitcountL = computeBitneed(common, bitneedsL.uint8, 0, &bitpoolPreferenceL); - bitcountR = computeBitneed(common, bitneedsR.uint8, 1, &bitpoolPreferenceR); - - oneChannelBitAllocation(common, &bitneedsL, 0, bitcountL); - oneChannelBitAllocation(common, &bitneedsR, 1, bitcountR); +static void dualBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common) { + OI_UINT bitcountL; + OI_UINT bitcountR; + OI_UINT bitpoolPreferenceL = 0; + OI_UINT bitpoolPreferenceR = 0; + BITNEED_UNION1 bitneedsL; + BITNEED_UNION1 bitneedsR; + + bitcountL = computeBitneed(common, bitneedsL.uint8, 0, &bitpoolPreferenceL); + bitcountR = computeBitneed(common, bitneedsR.uint8, 1, &bitpoolPreferenceR); + + oneChannelBitAllocation(common, &bitneedsL, 0, bitcountL); + oneChannelBitAllocation(common, &bitneedsR, 1, bitcountR); } -static void stereoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - const OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; - BITNEED_UNION2 bitneeds; - OI_UINT excess; - OI_INT bitadjust; - OI_UINT bitcount; - OI_UINT sbL; - OI_UINT sbR; - OI_UINT bitpoolPreference = 0; - - bitcount = computeBitneed(common, &bitneeds.uint8[0], 0, &bitpoolPreference); - bitcount += computeBitneed(common, &bitneeds.uint8[nrof_subbands], 1, &bitpoolPreference); - - { - OI_UINT ex; - bitadjust = adjustToFitBitpool(common->frameInfo.bitpool, bitneeds.uint32, 2 * nrof_subbands, bitcount, &ex); - /* We want the compiler to put excess into a register */ - excess = ex; +static void stereoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common) { + const OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; + BITNEED_UNION2 bitneeds; + OI_UINT excess; + OI_INT bitadjust; + OI_UINT bitcount; + OI_UINT sbL; + OI_UINT sbR; + OI_UINT bitpoolPreference = 0; + + bitcount = computeBitneed(common, &bitneeds.uint8[0], 0, &bitpoolPreference); + bitcount += computeBitneed(common, &bitneeds.uint8[nrof_subbands], 1, + &bitpoolPreference); + + { + OI_UINT ex; + bitadjust = adjustToFitBitpool(common->frameInfo.bitpool, bitneeds.uint32, + 2 * nrof_subbands, bitcount, &ex); + /* We want the compiler to put excess into a register */ + excess = ex; + } + sbL = 0; + sbR = nrof_subbands; + while (sbL < nrof_subbands) { + excess = allocAdjustedBits(&common->bits.uint8[sbL], + bitneeds.uint8[sbL] + bitadjust, excess); + ++sbL; + excess = allocAdjustedBits(&common->bits.uint8[sbR], + bitneeds.uint8[sbR] + bitadjust, excess); + ++sbR; + } + sbL = 0; + sbR = nrof_subbands; + while (excess) { + excess = allocExcessBits(&common->bits.uint8[sbL], excess); + ++sbL; + if (!excess) { + break; } - sbL = 0; - sbR = nrof_subbands; - while (sbL < nrof_subbands) { - excess = allocAdjustedBits(&common->bits.uint8[sbL], bitneeds.uint8[sbL] + bitadjust, excess); - ++sbL; - excess = allocAdjustedBits(&common->bits.uint8[sbR], bitneeds.uint8[sbR] + bitadjust, excess); - ++sbR; - } - sbL = 0; - sbR = nrof_subbands; - while (excess) { - excess = allocExcessBits(&common->bits.uint8[sbL], excess); - ++sbL; - if (!excess) { - break; - } - excess = allocExcessBits(&common->bits.uint8[sbR], excess); - ++sbR; - } - + excess = allocExcessBits(&common->bits.uint8[sbR], excess); + ++sbR; + } } static const BIT_ALLOC balloc[] = { - monoBitAllocation, /* SBC_MONO */ - dualBitAllocation, /* SBC_DUAL_CHANNEL */ - stereoBitAllocation, /* SBC_STEREO */ - stereoBitAllocation /* SBC_JOINT_STEREO */ + monoBitAllocation, /* SBC_MONO */ + dualBitAllocation, /* SBC_DUAL_CHANNEL */ + stereoBitAllocation, /* SBC_STEREO */ + stereoBitAllocation /* SBC_JOINT_STEREO */ }; +PRIVATE void OI_SBC_ComputeBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common) { + OI_ASSERT(common->frameInfo.bitpool <= OI_SBC_MaxBitpool(&common->frameInfo)); + OI_ASSERT(common->frameInfo.mode < OI_ARRAYSIZE(balloc)); -PRIVATE void OI_SBC_ComputeBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - OI_ASSERT(common->frameInfo.bitpool <= OI_SBC_MaxBitpool(&common->frameInfo)); - OI_ASSERT(common->frameInfo.mode < OI_ARRAYSIZE(balloc)); - - /* - * Using an array of function pointers prevents the compiler from creating a suboptimal - * monolithic inlined bit allocation function. - */ - balloc[common->frameInfo.mode](common); + /* + * Using an array of function pointers prevents the compiler from creating a + * suboptimal + * monolithic inlined bit allocation function. + */ + balloc[common->frameInfo.mode](common); } -uint32_t OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame) -{ - return internal_CalculateBitrate(frame); +uint32_t OI_CODEC_SBC_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO* frame) { + return internal_CalculateBitrate(frame); } /* * Return the current maximum bitneed and clear it. */ -uint8_t OI_CODEC_SBC_GetMaxBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - uint8_t max = common->maxBitneed; +uint8_t OI_CODEC_SBC_GetMaxBitneed(OI_CODEC_SBC_COMMON_CONTEXT* common) { + uint8_t max = common->maxBitneed; - common->maxBitneed = 0; - return max; + common->maxBitneed = 0; + return max; } /* * Calculates the bitpool size for a given frame length */ -uint16_t OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame, - uint16_t frameLen) -{ - uint16_t nrof_subbands = frame->nrof_subbands; - uint16_t nrof_blocks = frame->nrof_blocks; - uint16_t hdr; - uint16_t bits; - - if (frame->mode == SBC_JOINT_STEREO) { - hdr = 9 * nrof_subbands; +uint16_t OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO* frame, + uint16_t frameLen) { + uint16_t nrof_subbands = frame->nrof_subbands; + uint16_t nrof_blocks = frame->nrof_blocks; + uint16_t hdr; + uint16_t bits; + + if (frame->mode == SBC_JOINT_STEREO) { + hdr = 9 * nrof_subbands; + } else { + if (frame->mode == SBC_MONO) { + hdr = 4 * nrof_subbands; } else { - if (frame->mode == SBC_MONO) { - hdr = 4 * nrof_subbands; - } else { - hdr = 8 * nrof_subbands; - } - if (frame->mode == SBC_DUAL_CHANNEL) { - nrof_blocks *= 2; - } + hdr = 8 * nrof_subbands; + } + if (frame->mode == SBC_DUAL_CHANNEL) { + nrof_blocks *= 2; } - bits = 8 * (frameLen - SBC_HEADER_LEN) - hdr; - return DIVIDE(bits, nrof_blocks); + } + bits = 8 * (frameLen - SBC_HEADER_LEN) - hdr; + return DIVIDE(bits, nrof_blocks); } -uint16_t OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - return sizeof(int16_t) * common->pcmStride * common->frameInfo.nrof_subbands * common->frameInfo.nrof_blocks; +uint16_t OI_CODEC_SBC_CalculatePcmBytes(OI_CODEC_SBC_COMMON_CONTEXT* common) { + return sizeof(int16_t) * common->pcmStride * common->frameInfo.nrof_subbands * + common->frameInfo.nrof_blocks; } - -uint16_t OI_CODEC_SBC_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame) -{ - return internal_CalculateFramelen(frame); +uint16_t OI_CODEC_SBC_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO* frame) { + return internal_CalculateFramelen(frame); } /**@}*/ diff --git a/embdrv/sbc/decoder/srce/bitalloc.c b/embdrv/sbc/decoder/srce/bitalloc.c index 4719cd8ad..6cb83eea3 100644 --- a/embdrv/sbc/decoder/srce/bitalloc.c +++ b/embdrv/sbc/decoder/srce/bitalloc.c @@ -37,64 +37,66 @@ frame length and bitrate. @{ */ -#include "oi_utils.h" #include +#include "oi_utils.h" -uint32_t OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame) -{ - switch (frame->mode) { - case SBC_MONO: - case SBC_DUAL_CHANNEL: - return 16 * frame->nrof_subbands; - case SBC_STEREO: - case SBC_JOINT_STEREO: - return 32 * frame->nrof_subbands; - } - - ERROR(("Invalid frame mode %d", frame->mode)); - OI_ASSERT(false); - return 0; /* Should never be reached */ +uint32_t OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO* frame) { + switch (frame->mode) { + case SBC_MONO: + case SBC_DUAL_CHANNEL: + return 16 * frame->nrof_subbands; + case SBC_STEREO: + case SBC_JOINT_STEREO: + return 32 * frame->nrof_subbands; + } + + ERROR(("Invalid frame mode %d", frame->mode)); + OI_ASSERT(false); + return 0; /* Should never be reached */ } +PRIVATE uint16_t internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO* frame) { + uint16_t nbits = frame->nrof_blocks * frame->bitpool; + uint16_t nrof_subbands = frame->nrof_subbands; + uint16_t result = nbits; -PRIVATE uint16_t internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame) -{ - uint16_t nbits = frame->nrof_blocks * frame->bitpool; - uint16_t nrof_subbands = frame->nrof_subbands; - uint16_t result = nbits; - - if (frame->mode == SBC_JOINT_STEREO) { - result += nrof_subbands + (8 * nrof_subbands); + if (frame->mode == SBC_JOINT_STEREO) { + result += nrof_subbands + (8 * nrof_subbands); + } else { + if (frame->mode == SBC_DUAL_CHANNEL) { + result += nbits; + } + if (frame->mode == SBC_MONO) { + result += 4 * nrof_subbands; } else { - if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; } - if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; } + result += 8 * nrof_subbands; } - return SBC_HEADER_LEN + (result + 7) / 8; + } + return SBC_HEADER_LEN + (result + 7) / 8; } +PRIVATE uint32_t internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO* frame) { + OI_UINT blocksbands; + blocksbands = frame->nrof_subbands * frame->nrof_blocks; -PRIVATE uint32_t internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame) -{ - OI_UINT blocksbands; - blocksbands = frame->nrof_subbands * frame->nrof_blocks; - - return DIVIDE(8 * internal_CalculateFramelen(frame) * frame->frequency, blocksbands); + return DIVIDE(8 * internal_CalculateFramelen(frame) * frame->frequency, + blocksbands); } +INLINE uint16_t OI_SBC_CalculateFrameAndHeaderlen( + OI_CODEC_SBC_FRAME_INFO* frame, OI_UINT* headerLen_) { + OI_UINT headerLen = + SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels / 2; -INLINE uint16_t OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_) -{ - OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels/2; + if (frame->mode == SBC_JOINT_STEREO) { + headerLen++; + } - if (frame->mode == SBC_JOINT_STEREO) { headerLen++; } - - *headerLen_ = headerLen; - return internal_CalculateFramelen(frame); + *headerLen_ = headerLen; + return internal_CalculateFramelen(frame); } - -#define MIN(x, y) ((x) < (y) ? (x) : (y)) - +#define MIN(x, y) ((x) < (y) ? (x) : (y)) /* * Computes the bit need for each sample and as also returns a counts of bit @@ -119,74 +121,64 @@ INLINE uint16_t OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame * @return The SBC bit need * */ -OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common, - uint8_t *bitneeds, - OI_UINT ch, - OI_UINT *preferredBitpool) -{ - static const int8_t offset4[4][4] = { - { -1, 0, 0, 0 }, - { -2, 0, 0, 1 }, - { -2, 0, 0, 1 }, - { -2, 0, 0, 1 } - }; - - static const int8_t offset8[4][8] = { - { -2, 0, 0, 0, 0, 0, 0, 1 }, - { -3, 0, 0, 0, 0, 0, 1, 2 }, - { -4, 0, 0, 0, 0, 0, 1, 2 }, - { -4, 0, 0, 0, 0, 0, 1, 2 } - }; - - const OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; - OI_UINT sb; - int8_t *scale_factor = &common->scale_factor[ch ? nrof_subbands : 0]; - OI_UINT bitcount = 0; - uint8_t maxBits = 0; - uint8_t prefBits = 0; - - if (common->frameInfo.alloc == SBC_SNR) { - for (sb = 0; sb < nrof_subbands; sb++) { - OI_INT bits = scale_factor[sb]; - if (bits > maxBits) { - maxBits = bits; - } - if ((bitneeds[sb] = bits) > 1) { - bitcount += bits; - } - prefBits += 2 + bits; - } +OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT* common, uint8_t* bitneeds, + OI_UINT ch, OI_UINT* preferredBitpool) { + static const int8_t offset4[4][4] = { + {-1, 0, 0, 0}, {-2, 0, 0, 1}, {-2, 0, 0, 1}, {-2, 0, 0, 1}}; + + static const int8_t offset8[4][8] = {{-2, 0, 0, 0, 0, 0, 0, 1}, + {-3, 0, 0, 0, 0, 0, 1, 2}, + {-4, 0, 0, 0, 0, 0, 1, 2}, + {-4, 0, 0, 0, 0, 0, 1, 2}}; + + const OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; + OI_UINT sb; + int8_t* scale_factor = &common->scale_factor[ch ? nrof_subbands : 0]; + OI_UINT bitcount = 0; + uint8_t maxBits = 0; + uint8_t prefBits = 0; + + if (common->frameInfo.alloc == SBC_SNR) { + for (sb = 0; sb < nrof_subbands; sb++) { + OI_INT bits = scale_factor[sb]; + if (bits > maxBits) { + maxBits = bits; + } + if ((bitneeds[sb] = bits) > 1) { + bitcount += bits; + } + prefBits += 2 + bits; + } + } else { + const int8_t* offset; + if (nrof_subbands == 4) { + offset = offset4[common->frameInfo.freqIndex]; } else { - const int8_t *offset; - if (nrof_subbands == 4) { - offset = offset4[common->frameInfo.freqIndex]; - } else { - offset = offset8[common->frameInfo.freqIndex]; - } - for (sb = 0; sb < nrof_subbands; sb++) { - OI_INT bits = scale_factor[sb]; - if (bits > maxBits) { - maxBits = bits; - } - prefBits += 2 + bits; - if (bits) { - bits -= offset[sb]; - if (bits > 0) { - bits /= 2; - } - bits += 5; - } - if ((bitneeds[sb] = bits) > 1) { - bitcount += bits; - } + offset = offset8[common->frameInfo.freqIndex]; + } + for (sb = 0; sb < nrof_subbands; sb++) { + OI_INT bits = scale_factor[sb]; + if (bits > maxBits) { + maxBits = bits; + } + prefBits += 2 + bits; + if (bits) { + bits -= offset[sb]; + if (bits > 0) { + bits /= 2; } + bits += 5; + } + if ((bitneeds[sb] = bits) > 1) { + bitcount += bits; + } } - common->maxBitneed = OI_MAX(maxBits, common->maxBitneed); - *preferredBitpool += prefBits; - return bitcount; + } + common->maxBitneed = OI_MAX(maxBits, common->maxBitneed); + *preferredBitpool += prefBits; + return bitcount; } - /* * Explanation of the adjustToFitBitpool inner loop. * @@ -226,7 +218,6 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common, * operate on 4 values at once. */ - /* * Encoder/Decoder * @@ -249,149 +240,136 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common, * * @return The adjustment. */ -OI_INT adjustToFitBitpool(const OI_UINT bitpool, - uint32_t *bitneeds, - const OI_UINT subbands, - OI_UINT bitcount, - OI_UINT *excess) -{ - OI_INT maxBitadjust = 0; - OI_INT bitadjust = (bitcount > bitpool) ? -8 : 8; - OI_INT chop = 8; - - /* - * This is essentially a binary search for the optimal adjustment value. - */ - while ((bitcount != bitpool) && chop) { - uint32_t total = 0; - OI_UINT count; - uint32_t adjust4; - OI_INT i; - - adjust4 = bitadjust & 0x7F; - adjust4 |= (adjust4 << 8); - adjust4 |= (adjust4 << 16); - - for (i = (subbands / 4 - 1); i >= 0; --i) { - uint32_t mask; - uint32_t n = bitneeds[i] + adjust4; - mask = 0x7F7F7F7F + ((n & 0x40404040) >> 6); - n &= mask; - mask = 0x0F0F0F0F + ((n & 0x10101010) >> 4); - n &= mask; - mask = (((n + 0x0E0E0E0E) >> 4) | 0x1E1E1E1E); - n &= mask; - total += n; - } +OI_INT adjustToFitBitpool(const OI_UINT bitpool, uint32_t* bitneeds, + const OI_UINT subbands, OI_UINT bitcount, + OI_UINT* excess) { + OI_INT maxBitadjust = 0; + OI_INT bitadjust = (bitcount > bitpool) ? -8 : 8; + OI_INT chop = 8; + + /* + * This is essentially a binary search for the optimal adjustment value. + */ + while ((bitcount != bitpool) && chop) { + uint32_t total = 0; + OI_UINT count; + uint32_t adjust4; + OI_INT i; + + adjust4 = bitadjust & 0x7F; + adjust4 |= (adjust4 << 8); + adjust4 |= (adjust4 << 16); + + for (i = (subbands / 4 - 1); i >= 0; --i) { + uint32_t mask; + uint32_t n = bitneeds[i] + adjust4; + mask = 0x7F7F7F7F + ((n & 0x40404040) >> 6); + n &= mask; + mask = 0x0F0F0F0F + ((n & 0x10101010) >> 4); + n &= mask; + mask = (((n + 0x0E0E0E0E) >> 4) | 0x1E1E1E1E); + n &= mask; + total += n; + } - count = (total & 0xFFFF) + (total >> 16); - count = (count & 0xFF) + (count >> 8); + count = (total & 0xFFFF) + (total >> 16); + count = (count & 0xFF) + (count >> 8); - chop >>= 1; - if (count > bitpool) { - bitadjust -= chop; - } else { - maxBitadjust = bitadjust; - bitcount = count; - bitadjust += chop; - } + chop >>= 1; + if (count > bitpool) { + bitadjust -= chop; + } else { + maxBitadjust = bitadjust; + bitcount = count; + bitadjust += chop; } + } - *excess = bitpool - bitcount; + *excess = bitpool - bitcount; - return maxBitadjust; + return maxBitadjust; } - /* * The bit allocator trys to avoid single bit allocations except as a last * resort. So in the case where a bitneed of 1 was passed over during the * adsjustment phase 2 bits are now allocated. */ -INLINE OI_INT allocAdjustedBits(uint8_t *dest, - OI_INT bits, - OI_INT excess) -{ - if (bits < 16) { - if (bits > 1) { - if (excess) { - ++bits; - --excess; - } - } else if ((bits == 1) && (excess > 1)) { - bits = 2; - excess -= 2; - } else { - bits = 0; - } +INLINE OI_INT allocAdjustedBits(uint8_t* dest, OI_INT bits, OI_INT excess) { + if (bits < 16) { + if (bits > 1) { + if (excess) { + ++bits; + --excess; + } + } else if ((bits == 1) && (excess > 1)) { + bits = 2; + excess -= 2; } else { - bits = 16; + bits = 0; } - *dest = (uint8_t)bits; - return excess; + } else { + bits = 16; + } + *dest = (uint8_t)bits; + return excess; } - /* * Excess bits not allocated by allocaAdjustedBits are allocated round-robin. */ -INLINE OI_INT allocExcessBits(uint8_t *dest, - OI_INT excess) -{ - if (*dest < 16) { - *dest += 1; - return excess - 1; - } else { - return excess; - } +INLINE OI_INT allocExcessBits(uint8_t* dest, OI_INT excess) { + if (*dest < 16) { + *dest += 1; + return excess - 1; + } else { + return excess; + } } -void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common, - BITNEED_UNION1 *bitneeds, - OI_UINT ch, - OI_UINT bitcount) -{ - const uint8_t nrof_subbands = common->frameInfo.nrof_subbands; - OI_UINT excess; - OI_UINT sb; - OI_INT bitadjust; - uint8_t RESTRICT *allocBits; - - - { - OI_UINT ex; - bitadjust = adjustToFitBitpool(common->frameInfo.bitpool, bitneeds->uint32, nrof_subbands, bitcount, &ex); - /* We want the compiler to put excess into a register */ - excess = ex; - } - - /* - * Allocate adjusted bits - */ - allocBits = &common->bits.uint8[ch ? nrof_subbands : 0]; - - sb = 0; - while (sb < nrof_subbands) { - excess = allocAdjustedBits(&allocBits[sb], bitneeds->uint8[sb] + bitadjust, excess); - ++sb; - } - sb = 0; - while (excess) { - excess = allocExcessBits(&allocBits[sb], excess); - ++sb; - } +void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common, + BITNEED_UNION1* bitneeds, OI_UINT ch, + OI_UINT bitcount) { + const uint8_t nrof_subbands = common->frameInfo.nrof_subbands; + OI_UINT excess; + OI_UINT sb; + OI_INT bitadjust; + uint8_t RESTRICT* allocBits; + + { + OI_UINT ex; + bitadjust = adjustToFitBitpool(common->frameInfo.bitpool, bitneeds->uint32, + nrof_subbands, bitcount, &ex); + /* We want the compiler to put excess into a register */ + excess = ex; + } + + /* + * Allocate adjusted bits + */ + allocBits = &common->bits.uint8[ch ? nrof_subbands : 0]; + + sb = 0; + while (sb < nrof_subbands) { + excess = allocAdjustedBits(&allocBits[sb], bitneeds->uint8[sb] + bitadjust, + excess); + ++sb; + } + sb = 0; + while (excess) { + excess = allocExcessBits(&allocBits[sb], excess); + ++sb; + } } +void monoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT* common) { + BITNEED_UNION1 bitneeds; + OI_UINT bitcount; + OI_UINT bitpoolPreference = 0; -void monoBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common) -{ - BITNEED_UNION1 bitneeds; - OI_UINT bitcount; - OI_UINT bitpoolPreference = 0; - - bitcount = computeBitneed(common, bitneeds.uint8, 0, &bitpoolPreference); + bitcount = computeBitneed(common, bitneeds.uint8, 0, &bitpoolPreference); - oneChannelBitAllocation(common, &bitneeds, 0, bitcount); + oneChannelBitAllocation(common, &bitneeds, 0, bitcount); } /** diff --git a/embdrv/sbc/decoder/srce/bitstream-decode.c b/embdrv/sbc/decoder/srce/bitstream-decode.c index be0050bd1..5c8b664e3 100644 --- a/embdrv/sbc/decoder/srce/bitstream-decode.c +++ b/embdrv/sbc/decoder/srce/bitstream-decode.c @@ -34,60 +34,54 @@ Functions for manipulating input bitstreams. @{ */ -#include "oi_stddefs.h" -#include "oi_bitstream.h" #include "oi_assert.h" +#include "oi_bitstream.h" +#include "oi_stddefs.h" -PRIVATE void OI_BITSTREAM_ReadInit(OI_BITSTREAM *bs, - const OI_BYTE *buffer) -{ - bs->value = ((int32_t)buffer[0] << 16) | ((int32_t)buffer[1] << 8) | (buffer[2]); - bs->ptr.r = buffer + 3; - bs->bitPtr = 8; +PRIVATE void OI_BITSTREAM_ReadInit(OI_BITSTREAM* bs, const OI_BYTE* buffer) { + bs->value = + ((int32_t)buffer[0] << 16) | ((int32_t)buffer[1] << 8) | (buffer[2]); + bs->ptr.r = buffer + 3; + bs->bitPtr = 8; } -PRIVATE uint32_t OI_BITSTREAM_ReadUINT(OI_BITSTREAM *bs, OI_UINT bits) -{ - uint32_t result; +PRIVATE uint32_t OI_BITSTREAM_ReadUINT(OI_BITSTREAM* bs, OI_UINT bits) { + uint32_t result; - OI_BITSTREAM_READUINT(result, bits, bs->ptr.r, bs->value, bs->bitPtr); + OI_BITSTREAM_READUINT(result, bits, bs->ptr.r, bs->value, bs->bitPtr); - return result; + return result; } -PRIVATE uint8_t OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs) -{ - uint32_t result; - - OI_ASSERT(bs->bitPtr < 16); - OI_ASSERT(bs->bitPtr % 4 == 0); - - if (bs->bitPtr == 8) { - result = bs->value << 8; - bs->bitPtr = 12; - } else { - result = bs->value << 12; - bs->value = (bs->value << 8) | *bs->ptr.r++; - bs->bitPtr = 8; - } - result >>= 28; - OI_ASSERT(result < (1u << 4)); - return (uint8_t)result; -} +PRIVATE uint8_t OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM* bs) { + uint32_t result; -PRIVATE uint8_t OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM *bs) -{ - uint32_t result; - OI_ASSERT(bs->bitPtr == 8); + OI_ASSERT(bs->bitPtr < 16); + OI_ASSERT(bs->bitPtr % 4 == 0); - result = bs->value >> 16; + if (bs->bitPtr == 8) { + result = bs->value << 8; + bs->bitPtr = 12; + } else { + result = bs->value << 12; bs->value = (bs->value << 8) | *bs->ptr.r++; + bs->bitPtr = 8; + } + result >>= 28; + OI_ASSERT(result < (1u << 4)); + return (uint8_t)result; +} + +PRIVATE uint8_t OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM* bs) { + uint32_t result; + OI_ASSERT(bs->bitPtr == 8); - return (uint8_t)result; + result = bs->value >> 16; + bs->value = (bs->value << 8) | *bs->ptr.r++; + + return (uint8_t)result; } /** @} */ - - diff --git a/embdrv/sbc/decoder/srce/decoder-oina.c b/embdrv/sbc/decoder/srce/decoder-oina.c index 9e1e0c0ec..5811584d8 100644 --- a/embdrv/sbc/decoder/srce/decoder-oina.c +++ b/embdrv/sbc/decoder/srce/decoder-oina.c @@ -33,108 +33,87 @@ This file exposes OINA-specific interfaces to decoder functions. @{ */ - #include -OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - OI_BOOL enhanced, - uint8_t frequency, - uint8_t mode, - uint8_t subbands, - uint8_t blocks, - uint8_t alloc, - uint8_t maxBitpool) -{ - if (frequency > SBC_FREQ_48000) { - return OI_STATUS_INVALID_PARAMETERS; - } +OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw( + OI_CODEC_SBC_DECODER_CONTEXT* context, OI_BOOL enhanced, uint8_t frequency, + uint8_t mode, uint8_t subbands, uint8_t blocks, uint8_t alloc, + uint8_t maxBitpool) { + if (frequency > SBC_FREQ_48000) { + return OI_STATUS_INVALID_PARAMETERS; + } - if (enhanced) { + if (enhanced) { #ifdef SBC_ENHANCED - if (subbands != SBC_SUBBANDS_8) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (subbands != SBC_SUBBANDS_8) { + return OI_STATUS_INVALID_PARAMETERS; + } #else - return OI_STATUS_INVALID_PARAMETERS; + return OI_STATUS_INVALID_PARAMETERS; #endif - } + } - if (mode > SBC_JOINT_STEREO) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (mode > SBC_JOINT_STEREO) { + return OI_STATUS_INVALID_PARAMETERS; + } - if (subbands > SBC_SUBBANDS_8) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (subbands > SBC_SUBBANDS_8) { + return OI_STATUS_INVALID_PARAMETERS; + } - if (blocks > SBC_BLOCKS_16) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (blocks > SBC_BLOCKS_16) { + return OI_STATUS_INVALID_PARAMETERS; + } - if (alloc > SBC_SNR) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (alloc > SBC_SNR) { + return OI_STATUS_INVALID_PARAMETERS; + } #ifdef SBC_ENHANCED - context->common.frameInfo.enhanced = enhanced; + context->common.frameInfo.enhanced = enhanced; #else - context->common.frameInfo.enhanced = FALSE; + context->common.frameInfo.enhanced = FALSE; #endif - context->common.frameInfo.freqIndex = frequency; - context->common.frameInfo.mode = mode; - context->common.frameInfo.subbands = subbands; - context->common.frameInfo.blocks = blocks; - context->common.frameInfo.alloc = alloc; - context->common.frameInfo.bitpool = maxBitpool; + context->common.frameInfo.freqIndex = frequency; + context->common.frameInfo.mode = mode; + context->common.frameInfo.subbands = subbands; + context->common.frameInfo.blocks = blocks; + context->common.frameInfo.alloc = alloc; + context->common.frameInfo.bitpool = maxBitpool; - OI_SBC_ExpandFrameFields(&context->common.frameInfo); + OI_SBC_ExpandFrameFields(&context->common.frameInfo); - if (context->common.frameInfo.nrof_channels >= context->common.pcmStride) { - return OI_STATUS_INVALID_PARAMETERS; - } + if (context->common.frameInfo.nrof_channels >= context->common.pcmStride) { + return OI_STATUS_INVALID_PARAMETERS; + } - return OI_OK; + return OI_OK; } - - -OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint8_t bitpool, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes) -{ - return internal_DecodeRaw(context, - bitpool, - frameData, - frameBytes, - pcmData, - pcmBytes); +OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint8_t bitpool, const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes) { + return internal_DecodeRaw(context, bitpool, frameData, frameBytes, pcmData, + pcmBytes); } -OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context, - OI_BOOL enhanced, - uint8_t subbands) -{ - if (enhanced) - { +OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BOOL enhanced, uint8_t subbands) { + if (enhanced) { #ifdef SBC_ENHANCED - context->enhancedEnabled = TRUE; + context->enhancedEnabled = TRUE; #else - context->enhancedEnabled = FALSE; + context->enhancedEnabled = FALSE; #endif - } - else - { - context->enhancedEnabled = FALSE; - } - context->restrictSubbands = subbands; - context->limitFrameFormat = TRUE; - return OI_OK; + } else { + context->enhancedEnabled = FALSE; + } + context->restrictSubbands = subbands; + context->limitFrameFormat = TRUE; + return OI_OK; } - /** @} */ diff --git a/embdrv/sbc/decoder/srce/decoder-private.c b/embdrv/sbc/decoder/srce/decoder-private.c index 9a874e698..686dd6aff 100644 --- a/embdrv/sbc/decoder/srce/decoder-private.c +++ b/embdrv/sbc/decoder/srce/decoder-private.c @@ -34,196 +34,193 @@ This file drives SBC decoding. @{ */ -#include "oi_codec_sbc_private.h" -#include "oi_bitstream.h" #include +#include "oi_bitstream.h" +#include "oi_codec_sbc_private.h" -OI_CHAR * const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved"; +OI_CHAR* const OI_Codec_Copyright = + "Copyright 2002-2007 Open Interface North America, Inc. All rights " + "reserved"; -INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint32_t *decoderData, +INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint32_t* decoderData, uint32_t decoderDataBytes, - OI_BYTE maxChannels, - OI_BYTE pcmStride, - OI_BOOL enhanced) -{ - OI_UINT i; - OI_STATUS status; + OI_BYTE maxChannels, OI_BYTE pcmStride, + OI_BOOL enhanced) { + OI_UINT i; + OI_STATUS status; - for (i = 0; i < sizeof(*context); i++) { - ((char *)context)[i] = 0; - } + for (i = 0; i < sizeof(*context); i++) { + ((char*)context)[i] = 0; + } #ifdef SBC_ENHANCED - context->enhancedEnabled = enhanced ? TRUE : FALSE; + context->enhancedEnabled = enhanced ? TRUE : FALSE; #else - context->enhancedEnabled = FALSE; - if (enhanced){ - return OI_STATUS_INVALID_PARAMETERS; - } + context->enhancedEnabled = FALSE; + if (enhanced) { + return OI_STATUS_INVALID_PARAMETERS; + } #endif - status = OI_CODEC_SBC_Alloc(&context->common, decoderData, decoderDataBytes, maxChannels, pcmStride); + status = OI_CODEC_SBC_Alloc(&context->common, decoderData, decoderDataBytes, + maxChannels, pcmStride); - if (!OI_SUCCESS(status)) { - return status; - } + if (!OI_SUCCESS(status)) { + return status; + } - context->common.codecInfo = OI_Codec_Copyright; - context->common.maxBitneed = 0; - context->limitFrameFormat = FALSE; - OI_SBC_ExpandFrameFields(&context->common.frameInfo); + context->common.codecInfo = OI_Codec_Copyright; + context->common.maxBitneed = 0; + context->limitFrameFormat = FALSE; + OI_SBC_ExpandFrameFields(&context->common.frameInfo); - /*PLATFORM_DECODER_RESET(context);*/ + /*PLATFORM_DECODER_RESET(context);*/ - return OI_OK; + return OI_OK; } - - - /** * Read the SBC header up to but not including the joint stereo mask. The * syncword has already been examined, and the enhanced mode flag set, by * FindSyncword. */ -INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE *data) -{ - OI_CODEC_SBC_FRAME_INFO *frame = &common->frameInfo; - uint8_t d1; - - - OI_ASSERT(data[0] == OI_SBC_SYNCWORD || data[0] == OI_SBC_ENHANCED_SYNCWORD); - - /* Avoid filling out all these strucutures if we already remember the values - * from last time. Just in case we get a stream corresponding to data[1] == - * 0, DecoderReset is responsible for ensuring the lookup table entries have - * already been populated - */ - d1 = data[1]; - if (d1 != frame->cachedInfo) { - - frame->freqIndex = (d1 & (BIT7 | BIT6)) >> 6; - frame->frequency = freq_values[frame->freqIndex]; - - frame->blocks = (d1 & (BIT5 | BIT4)) >> 4; - frame->nrof_blocks = block_values[frame->blocks]; - - frame->mode = (d1 & (BIT3 | BIT2)) >> 2; - frame->nrof_channels = channel_values[frame->mode]; - - frame->alloc = (d1 & BIT1) >> 1; - - frame->subbands = (d1 & BIT0); - frame->nrof_subbands = band_values[frame->subbands]; - - frame->cachedInfo = d1; - } - /* - * For decode, the bit allocator needs to know the bitpool value - */ - frame->bitpool = data[2]; - frame->crc = data[3]; +INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT* common, + const OI_BYTE* data) { + OI_CODEC_SBC_FRAME_INFO* frame = &common->frameInfo; + uint8_t d1; + + OI_ASSERT(data[0] == OI_SBC_SYNCWORD || data[0] == OI_SBC_ENHANCED_SYNCWORD); + + /* Avoid filling out all these strucutures if we already remember the values + * from last time. Just in case we get a stream corresponding to data[1] == + * 0, DecoderReset is responsible for ensuring the lookup table entries have + * already been populated + */ + d1 = data[1]; + if (d1 != frame->cachedInfo) { + frame->freqIndex = (d1 & (BIT7 | BIT6)) >> 6; + frame->frequency = freq_values[frame->freqIndex]; + + frame->blocks = (d1 & (BIT5 | BIT4)) >> 4; + frame->nrof_blocks = block_values[frame->blocks]; + + frame->mode = (d1 & (BIT3 | BIT2)) >> 2; + frame->nrof_channels = channel_values[frame->mode]; + + frame->alloc = (d1 & BIT1) >> 1; + + frame->subbands = (d1 & BIT0); + frame->nrof_subbands = band_values[frame->subbands]; + + frame->cachedInfo = d1; + } + /* + * For decode, the bit allocator needs to know the bitpool value + */ + frame->bitpool = data[2]; + frame->crc = data[3]; } - -#define LOW(x) ((x)& 0xf) +#define LOW(x) ((x)&0xf) #define HIGH(x) ((x) >> 4) /* * Read scalefactor values and prepare the bitstream for OI_SBC_ReadSamples */ -PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common, - const OI_BYTE *b, - OI_BITSTREAM *bs) -{ - OI_UINT i = common->frameInfo.nrof_subbands * common->frameInfo.nrof_channels; - int8_t *scale_factor = common->scale_factor; - OI_UINT f; - - if (common->frameInfo.nrof_subbands == 8 || common->frameInfo.mode != SBC_JOINT_STEREO) { - if (common->frameInfo.mode == SBC_JOINT_STEREO) { - common->frameInfo.join = *b++; - } else { - common->frameInfo.join = 0; - } - i /= 2; - do { - *scale_factor++ = HIGH(f = *b++); - *scale_factor++ = LOW(f); - } while (--i); - /* - * In this case we know that the scale factors end on a byte boundary so all we need to do - * is initialize the bitstream. - */ - OI_BITSTREAM_ReadInit(bs, b); +PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT* common, + const OI_BYTE* b, OI_BITSTREAM* bs) { + OI_UINT i = common->frameInfo.nrof_subbands * common->frameInfo.nrof_channels; + int8_t* scale_factor = common->scale_factor; + OI_UINT f; + + if (common->frameInfo.nrof_subbands == 8 || + common->frameInfo.mode != SBC_JOINT_STEREO) { + if (common->frameInfo.mode == SBC_JOINT_STEREO) { + common->frameInfo.join = *b++; } else { - OI_ASSERT(common->frameInfo.nrof_subbands == 4 && common->frameInfo.mode == SBC_JOINT_STEREO); - common->frameInfo.join = HIGH(f = *b++); - i = (i - 1) / 2; - do { - *scale_factor++ = LOW(f); - *scale_factor++ = HIGH(f = *b++); - } while (--i); - *scale_factor++ = LOW(f); - /* - * In 4-subband joint stereo mode, the joint stereo information ends on a half-byte - * boundary, so it's necessary to use the bitstream abstraction to read it, since - * OI_SBC_ReadSamples will need to pick up in mid-byte. - */ - OI_BITSTREAM_ReadInit(bs, b); - *scale_factor++ = OI_BITSTREAM_ReadUINT4Aligned(bs); + common->frameInfo.join = 0; } + i /= 2; + do { + *scale_factor++ = HIGH(f = *b++); + *scale_factor++ = LOW(f); + } while (--i); + /* + * In this case we know that the scale factors end on a byte boundary so all + * we need to do + * is initialize the bitstream. + */ + OI_BITSTREAM_ReadInit(bs, b); + } else { + OI_ASSERT(common->frameInfo.nrof_subbands == 4 && + common->frameInfo.mode == SBC_JOINT_STEREO); + common->frameInfo.join = HIGH(f = *b++); + i = (i - 1) / 2; + do { + *scale_factor++ = LOW(f); + *scale_factor++ = HIGH(f = *b++); + } while (--i); + *scale_factor++ = LOW(f); + /* + * In 4-subband joint stereo mode, the joint stereo information ends on a + * half-byte + * boundary, so it's necessary to use the bitstream abstraction to read it, + * since + * OI_SBC_ReadSamples will need to pick up in mid-byte. + */ + OI_BITSTREAM_ReadInit(bs, b); + *scale_factor++ = OI_BITSTREAM_ReadUINT4Aligned(bs); + } } /** Read quantized subband samples from the input bitstream and expand them. */ -PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTREAM *global_bs) -{ - OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common; - OI_UINT nrof_blocks = common->frameInfo.nrof_blocks; - int32_t * RESTRICT s = common->subdata; - uint8_t *ptr = global_bs->ptr.w; - uint32_t value = global_bs->value; - OI_UINT bitPtr = global_bs->bitPtr; - - const OI_UINT iter_count = common->frameInfo.nrof_channels * common->frameInfo.nrof_subbands / 4; - do { - OI_UINT i; - for (i = 0; i < iter_count; ++i) { - uint32_t sf_by4 = ((uint32_t*)common->scale_factor)[i]; - uint32_t bits_by4 = common->bits.uint32[i]; - OI_UINT n; - for (n = 0; n < 4; ++n) { - int32_t dequant; - OI_UINT bits; - OI_INT sf; - - if (OI_CPU_BYTE_ORDER == OI_LITTLE_ENDIAN_BYTE_ORDER) { - bits = bits_by4 & 0xFF; - bits_by4 >>= 8; - sf = sf_by4 & 0xFF; - sf_by4 >>= 8; - } else { - bits = (bits_by4 >> 24) & 0xFF; - bits_by4 <<= 8; - sf = (sf_by4 >> 24) & 0xFF; - sf_by4 <<= 8; - } - if (bits) { - uint32_t raw; - OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr); - dequant = OI_SBC_Dequant(raw, sf, bits); - } else { - dequant = 0; - } - *s++ = dequant; - } +PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BITSTREAM* global_bs) { + OI_CODEC_SBC_COMMON_CONTEXT* common = &context->common; + OI_UINT nrof_blocks = common->frameInfo.nrof_blocks; + int32_t* RESTRICT s = common->subdata; + uint8_t* ptr = global_bs->ptr.w; + uint32_t value = global_bs->value; + OI_UINT bitPtr = global_bs->bitPtr; + + const OI_UINT iter_count = + common->frameInfo.nrof_channels * common->frameInfo.nrof_subbands / 4; + do { + OI_UINT i; + for (i = 0; i < iter_count; ++i) { + uint32_t sf_by4 = ((uint32_t*)common->scale_factor)[i]; + uint32_t bits_by4 = common->bits.uint32[i]; + OI_UINT n; + for (n = 0; n < 4; ++n) { + int32_t dequant; + OI_UINT bits; + OI_INT sf; + + if (OI_CPU_BYTE_ORDER == OI_LITTLE_ENDIAN_BYTE_ORDER) { + bits = bits_by4 & 0xFF; + bits_by4 >>= 8; + sf = sf_by4 & 0xFF; + sf_by4 >>= 8; + } else { + bits = (bits_by4 >> 24) & 0xFF; + bits_by4 <<= 8; + sf = (sf_by4 >> 24) & 0xFF; + sf_by4 <<= 8; } - } while (--nrof_blocks); + if (bits) { + uint32_t raw; + OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr); + dequant = OI_SBC_Dequant(raw, sf, bits); + } else { + dequant = 0; + } + *s++ = dequant; + } + } + } while (--nrof_blocks); } - - /** @} */ diff --git a/embdrv/sbc/decoder/srce/decoder-sbc.c b/embdrv/sbc/decoder/srce/decoder-sbc.c index 2fbebc76e..85c37d6ea 100644 --- a/embdrv/sbc/decoder/srce/decoder-sbc.c +++ b/embdrv/sbc/decoder/srce/decoder-sbc.c @@ -28,8 +28,8 @@ /**@addtogroup codec_internal */ /**@{*/ -#include "oi_codec_sbc_private.h" #include "oi_bitstream.h" +#include "oi_codec_sbc_private.h" #define SPECIALIZE_READ_SAMPLES_JOINT @@ -38,421 +38,436 @@ * set for enhanced operation using OI_CODEC_SBC_DecoderReset(), it will search * for both a standard and an enhanced syncword. */ -PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE **frameData, - uint32_t *frameBytes) -{ +PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE** frameData, + uint32_t* frameBytes) { #ifdef SBC_ENHANCED - OI_BYTE search1 = OI_SBC_SYNCWORD; - OI_BYTE search2 = OI_SBC_ENHANCED_SYNCWORD; -#endif // SBC_ENHANCED + OI_BYTE search1 = OI_SBC_SYNCWORD; + OI_BYTE search2 = OI_SBC_ENHANCED_SYNCWORD; +#endif // SBC_ENHANCED - if (*frameBytes == 0) { - return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; - } + if (*frameBytes == 0) { + return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; + } #ifdef SBC_ENHANCED - if (context->limitFrameFormat && context->enhancedEnabled){ - /* If the context is restricted, only search for specified SYNCWORD */ - search1 = search2; - } else if (context->enhancedEnabled == FALSE) { - /* If enhanced is not enabled, only search for classic SBC SYNCWORD*/ - search2 = search1; - } - while (*frameBytes && (**frameData != search1) && (**frameData != search2)) { - (*frameBytes)--; - (*frameData)++; - } - if (*frameBytes) { - /* Syncword found, *frameData points to it, and *frameBytes correctly - * reflects the number of bytes available to read, including the - * syncword. */ - context->common.frameInfo.enhanced = (**frameData == OI_SBC_ENHANCED_SYNCWORD); - return OI_OK; - } else { - /* No syncword was found anywhere in the provided input data. - * *frameData points past the end of the original input, and - * *frameBytes is 0. */ - return OI_CODEC_SBC_NO_SYNCWORD; - } -#else // SBC_ENHANCED - while (*frameBytes && (**frameData != OI_SBC_SYNCWORD)) { - (*frameBytes)--; - (*frameData)++; - } - if (*frameBytes) { - /* Syncword found, *frameData points to it, and *frameBytes correctly - * reflects the number of bytes available to read, including the - * syncword. */ - context->common.frameInfo.enhanced = FALSE; - return OI_OK; - } else { - /* No syncword was found anywhere in the provided input data. - * *frameData points past the end of the original input, and - * *frameBytes is 0. */ - return OI_CODEC_SBC_NO_SYNCWORD; - } -#endif // SBC_ENHANCED + if (context->limitFrameFormat && context->enhancedEnabled) { + /* If the context is restricted, only search for specified SYNCWORD */ + search1 = search2; + } else if (context->enhancedEnabled == FALSE) { + /* If enhanced is not enabled, only search for classic SBC SYNCWORD*/ + search2 = search1; + } + while (*frameBytes && (**frameData != search1) && (**frameData != search2)) { + (*frameBytes)--; + (*frameData)++; + } + if (*frameBytes) { + /* Syncword found, *frameData points to it, and *frameBytes correctly + * reflects the number of bytes available to read, including the + * syncword. */ + context->common.frameInfo.enhanced = + (**frameData == OI_SBC_ENHANCED_SYNCWORD); + return OI_OK; + } else { + /* No syncword was found anywhere in the provided input data. + * *frameData points past the end of the original input, and + * *frameBytes is 0. */ + return OI_CODEC_SBC_NO_SYNCWORD; + } +#else // SBC_ENHANCED + while (*frameBytes && (**frameData != OI_SBC_SYNCWORD)) { + (*frameBytes)--; + (*frameData)++; + } + if (*frameBytes) { + /* Syncword found, *frameData points to it, and *frameBytes correctly + * reflects the number of bytes available to read, including the + * syncword. */ + context->common.frameInfo.enhanced = FALSE; + return OI_OK; + } else { + /* No syncword was found anywhere in the provided input data. + * *frameData points past the end of the original input, and + * *frameBytes is 0. */ + return OI_CODEC_SBC_NO_SYNCWORD; + } +#endif // SBC_ENHANCED } -static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE *bodyData, - int16_t *pcmData, - uint32_t *pcmBytes, - OI_BOOL allowPartial) -{ - OI_BITSTREAM bs; - OI_UINT frameSamples = context->common.frameInfo.nrof_blocks * context->common.frameInfo.nrof_subbands; - OI_UINT decode_block_count; - - /* - * Based on the header data, make sure that there is enough room to write the output samples. - */ - if (*pcmBytes < (sizeof(int16_t) * frameSamples * context->common.pcmStride) && !allowPartial) { - /* If we're not allowing partial decodes, we need room for the entire - * codec frame */ - TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA")); - return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA; - } else if (*pcmBytes < sizeof (int16_t) * context->common.frameInfo.nrof_subbands * context->common.pcmStride) { - /* Even if we're allowing partials, we can still only decode on a frame - * boundary */ - return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA; +static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE* bodyData, int16_t* pcmData, + uint32_t* pcmBytes, OI_BOOL allowPartial) { + OI_BITSTREAM bs; + OI_UINT frameSamples = context->common.frameInfo.nrof_blocks * + context->common.frameInfo.nrof_subbands; + OI_UINT decode_block_count; + + /* + * Based on the header data, make sure that there is enough room to write the + * output samples. + */ + if (*pcmBytes < + (sizeof(int16_t) * frameSamples * context->common.pcmStride) && + !allowPartial) { + /* If we're not allowing partial decodes, we need room for the entire + * codec frame */ + TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA")); + return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA; + } else if (*pcmBytes < sizeof(int16_t) * + context->common.frameInfo.nrof_subbands * + context->common.pcmStride) { + /* Even if we're allowing partials, we can still only decode on a frame + * boundary */ + return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA; + } + + if (context->bufferedBlocks == 0) { + TRACE(("Reading scalefactors")); + OI_SBC_ReadScalefactors(&context->common, bodyData, &bs); + + TRACE(("Computing bit allocation")); + OI_SBC_ComputeBitAllocation(&context->common); + + TRACE(("Reading samples")); + if (context->common.frameInfo.mode == SBC_JOINT_STEREO) { + OI_SBC_ReadSamplesJoint(context, &bs); + } else { + OI_SBC_ReadSamples(context, &bs); } - if (context->bufferedBlocks == 0) { - TRACE(("Reading scalefactors")); - OI_SBC_ReadScalefactors(&context->common, bodyData, &bs); + context->bufferedBlocks = context->common.frameInfo.nrof_blocks; + } - TRACE(("Computing bit allocation")); - OI_SBC_ComputeBitAllocation(&context->common); + if (allowPartial) { + decode_block_count = *pcmBytes / sizeof(int16_t) / + context->common.pcmStride / + context->common.frameInfo.nrof_subbands; - TRACE(("Reading samples")); - if (context->common.frameInfo.mode == SBC_JOINT_STEREO) { - OI_SBC_ReadSamplesJoint(context, &bs); - } else { - OI_SBC_ReadSamples(context, &bs); - } - - context->bufferedBlocks = context->common.frameInfo.nrof_blocks; + if (decode_block_count > context->bufferedBlocks) { + decode_block_count = context->bufferedBlocks; } - if (allowPartial) { - decode_block_count = *pcmBytes / sizeof(int16_t) / context->common.pcmStride / context->common.frameInfo.nrof_subbands; - - if (decode_block_count > context->bufferedBlocks) { - decode_block_count = context->bufferedBlocks; - } - - } else { - decode_block_count = context->common.frameInfo.nrof_blocks; - } - - TRACE(("Synthesizing frame")); - { - OI_UINT start_block = context->common.frameInfo.nrof_blocks - context->bufferedBlocks; - OI_SBC_SynthFrame(context, pcmData, start_block, decode_block_count); + } else { + decode_block_count = context->common.frameInfo.nrof_blocks; + } + + TRACE(("Synthesizing frame")); + { + OI_UINT start_block = + context->common.frameInfo.nrof_blocks - context->bufferedBlocks; + OI_SBC_SynthFrame(context, pcmData, start_block, decode_block_count); + } + + OI_ASSERT(context->bufferedBlocks >= decode_block_count); + context->bufferedBlocks -= decode_block_count; + + frameSamples = decode_block_count * context->common.frameInfo.nrof_subbands; + + /* + * When decoding mono into a stride-2 array, copy pcm data to second channel + */ + if (context->common.frameInfo.nrof_channels == 1 && + context->common.pcmStride == 2) { + OI_UINT i; + for (i = 0; i < frameSamples; ++i) { + pcmData[2 * i + 1] = pcmData[2 * i]; } + } + + /* + * Return number of pcm bytes generated by the decode operation. + */ + *pcmBytes = frameSamples * sizeof(int16_t) * context->common.pcmStride; + if (context->bufferedBlocks > 0) { + return OI_CODEC_SBC_PARTIAL_DECODE; + } else { + return OI_OK; + } +} - OI_ASSERT(context->bufferedBlocks >= decode_block_count); - context->bufferedBlocks -= decode_block_count; +PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint8_t bitpool, const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes) { + OI_STATUS status; + OI_UINT bodyLen; - frameSamples = decode_block_count * context->common.frameInfo.nrof_subbands; + TRACE(("+OI_CODEC_SBC_DecodeRaw")); + if (context->bufferedBlocks == 0) { /* - * When decoding mono into a stride-2 array, copy pcm data to second channel + * The bitallocator needs to know the bitpool value. */ - if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) { - OI_UINT i; - for (i = 0; i < frameSamples; ++i) { - pcmData[2*i+1] = pcmData[2*i]; - } - } - - /* - * Return number of pcm bytes generated by the decode operation. - */ - *pcmBytes = frameSamples * sizeof(int16_t) * context->common.pcmStride; - if (context->bufferedBlocks > 0) { - return OI_CODEC_SBC_PARTIAL_DECODE; - } else { - return OI_OK; - } -} - -PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint8_t bitpool, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes) -{ - OI_STATUS status; - OI_UINT bodyLen; - - TRACE(("+OI_CODEC_SBC_DecodeRaw")); - - if (context->bufferedBlocks == 0) { - /* - * The bitallocator needs to know the bitpool value. - */ - context->common.frameInfo.bitpool = bitpool; - /* - * Compute the frame length and check we have enough frame data to proceed - */ - bodyLen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo) - SBC_HEADER_LEN; - if (*frameBytes < bodyLen) { - TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA")); - return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; - } - } else { - bodyLen = 0; - } + context->common.frameInfo.bitpool = bitpool; /* - * Decode the SBC data. Pass TRUE to DecodeBody to allow partial decoding of - * tones. + * Compute the frame length and check we have enough frame data to proceed */ - status = DecodeBody(context, *frameData, pcmData, pcmBytes, TRUE); - if (OI_SUCCESS(status) || status == OI_CODEC_SBC_PARTIAL_DECODE) { - *frameData += bodyLen; - *frameBytes -= bodyLen; + bodyLen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo) - + SBC_HEADER_LEN; + if (*frameBytes < bodyLen) { + TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA")); + return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; } - TRACE(("-OI_CODEC_SBC_DecodeRaw: %d", status)); - return status; + } else { + bodyLen = 0; + } + /* + * Decode the SBC data. Pass TRUE to DecodeBody to allow partial decoding of + * tones. + */ + status = DecodeBody(context, *frameData, pcmData, pcmBytes, TRUE); + if (OI_SUCCESS(status) || status == OI_CODEC_SBC_PARTIAL_DECODE) { + *frameData += bodyLen; + *frameBytes -= bodyLen; + } + TRACE(("-OI_CODEC_SBC_DecodeRaw: %d", status)); + return status; } -OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, - uint32_t *decoderData, +OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT* context, + uint32_t* decoderData, uint32_t decoderDataBytes, - uint8_t maxChannels, - uint8_t pcmStride, - OI_BOOL enhanced) -{ - return internal_DecoderReset(context, decoderData, decoderDataBytes, maxChannels, pcmStride, enhanced); + uint8_t maxChannels, uint8_t pcmStride, + OI_BOOL enhanced) { + return internal_DecoderReset(context, decoderData, decoderDataBytes, + maxChannels, pcmStride, enhanced); } -OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE **frameData, - uint32_t *frameBytes, - int16_t *pcmData, - uint32_t *pcmBytes) -{ - OI_STATUS status; - OI_UINT framelen; - uint8_t crc; - - TRACE(("+OI_CODEC_SBC_DecodeFrame")); - - TRACE(("Finding syncword")); - status = FindSyncword(context, frameData, frameBytes); - if (!OI_SUCCESS(status)) { - return status; - } - - /* Make sure enough data remains to read the header. */ - if (*frameBytes < SBC_HEADER_LEN) { - TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA")); - return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; - } +OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE** frameData, + uint32_t* frameBytes, int16_t* pcmData, + uint32_t* pcmBytes) { + OI_STATUS status; + OI_UINT framelen; + uint8_t crc; - TRACE(("Reading Header")); - OI_SBC_ReadHeader(&context->common, *frameData); + TRACE(("+OI_CODEC_SBC_DecodeFrame")); - /* - * Some implementations load the decoder into RAM and use overlays for 4 vs 8 subbands. We need - * to ensure that the SBC parameters for this frame are compatible with the restrictions imposed - * by the loaded overlays. - */ - if (context->limitFrameFormat && (context->common.frameInfo.subbands != context->restrictSubbands)) { - ERROR(("SBC parameters incompatible with loaded overlay")); - return OI_STATUS_INVALID_PARAMETERS; - } - - if (context->common.frameInfo.nrof_channels > context->common.maxChannels) { - ERROR(("SBC parameters incompatible with number of channels specified during reset")); - return OI_STATUS_INVALID_PARAMETERS; - } - - if (context->common.pcmStride < 1 || context->common.pcmStride > 2) { - ERROR(("PCM stride not set correctly during reset")); - return OI_STATUS_INVALID_PARAMETERS; - } - - /* - * At this point a header has been read. However, it's possible that we found a false syncword, - * so the header data might be invalid. Make sure we have enough bytes to read in the - * CRC-protected header, but don't require we have the whole frame. That way, if it turns out - * that we're acting on bogus header data, we don't stall the decoding process by waiting for - * data that we don't actually need. - */ - framelen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo); - if (*frameBytes < framelen) { - TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA")); - return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; - } - - TRACE(("Calculating checksum")); - - crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData); - if (crc != context->common.frameInfo.crc) { - TRACE(("CRC Mismatch: calc=%02x read=%02x\n", crc, context->common.frameInfo.crc)); - TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_CHECKSUM_MISMATCH")); - return OI_CODEC_SBC_CHECKSUM_MISMATCH; - } + TRACE(("Finding syncword")); + status = FindSyncword(context, frameData, frameBytes); + if (!OI_SUCCESS(status)) { + return status; + } + + /* Make sure enough data remains to read the header. */ + if (*frameBytes < SBC_HEADER_LEN) { + TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA")); + return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; + } + + TRACE(("Reading Header")); + OI_SBC_ReadHeader(&context->common, *frameData); + + /* + * Some implementations load the decoder into RAM and use overlays for 4 vs 8 + * subbands. We need + * to ensure that the SBC parameters for this frame are compatible with the + * restrictions imposed + * by the loaded overlays. + */ + if (context->limitFrameFormat && + (context->common.frameInfo.subbands != context->restrictSubbands)) { + ERROR(("SBC parameters incompatible with loaded overlay")); + return OI_STATUS_INVALID_PARAMETERS; + } + + if (context->common.frameInfo.nrof_channels > context->common.maxChannels) { + ERROR( + ("SBC parameters incompatible with number of channels specified during " + "reset")); + return OI_STATUS_INVALID_PARAMETERS; + } + + if (context->common.pcmStride < 1 || context->common.pcmStride > 2) { + ERROR(("PCM stride not set correctly during reset")); + return OI_STATUS_INVALID_PARAMETERS; + } + + /* + * At this point a header has been read. However, it's possible that we found + * a false syncword, + * so the header data might be invalid. Make sure we have enough bytes to read + * in the + * CRC-protected header, but don't require we have the whole frame. That way, + * if it turns out + * that we're acting on bogus header data, we don't stall the decoding process + * by waiting for + * data that we don't actually need. + */ + framelen = OI_CODEC_SBC_CalculateFramelen(&context->common.frameInfo); + if (*frameBytes < framelen) { + TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA")); + return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; + } + + TRACE(("Calculating checksum")); + + crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData); + if (crc != context->common.frameInfo.crc) { + TRACE(("CRC Mismatch: calc=%02x read=%02x\n", crc, + context->common.frameInfo.crc)); + TRACE(("-OI_CODEC_SBC_DecodeFrame: OI_CODEC_SBC_CHECKSUM_MISMATCH")); + return OI_CODEC_SBC_CHECKSUM_MISMATCH; + } #ifdef OI_DEBUG - /* - * Make sure the bitpool values are sane. - */ - if ((context->common.frameInfo.bitpool < SBC_MIN_BITPOOL) && !context->common.frameInfo.enhanced) { - ERROR(("Bitpool too small: %d (must be >= 2)", context->common.frameInfo.bitpool)); - return OI_STATUS_INVALID_PARAMETERS; - } - if (context->common.frameInfo.bitpool > OI_SBC_MaxBitpool(&context->common.frameInfo)) { - ERROR(("Bitpool too large: %d (must be <= %ld)", context->common.frameInfo.bitpool, OI_SBC_MaxBitpool(&context->common.frameInfo))); - return OI_STATUS_INVALID_PARAMETERS; - } + /* + * Make sure the bitpool values are sane. + */ + if ((context->common.frameInfo.bitpool < SBC_MIN_BITPOOL) && + !context->common.frameInfo.enhanced) { + ERROR(("Bitpool too small: %d (must be >= 2)", + context->common.frameInfo.bitpool)); + return OI_STATUS_INVALID_PARAMETERS; + } + if (context->common.frameInfo.bitpool > + OI_SBC_MaxBitpool(&context->common.frameInfo)) { + ERROR(("Bitpool too large: %d (must be <= %ld)", + context->common.frameInfo.bitpool, + OI_SBC_MaxBitpool(&context->common.frameInfo))); + return OI_STATUS_INVALID_PARAMETERS; + } #endif - /* - * Now decode the SBC data. Partial decode is not yet implemented for an SBC - * stream, so pass FALSE to decode body to have it enforce the old rule that - * you have to decode a whole packet at a time. - */ - status = DecodeBody(context, *frameData + SBC_HEADER_LEN, pcmData, pcmBytes, FALSE); - if (OI_SUCCESS(status)) { - *frameData += framelen; - *frameBytes -= framelen; - } - TRACE(("-OI_CODEC_SBC_DecodeFrame: %d", status)); - - return status; -} - -OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, - const OI_BYTE **frameData, - uint32_t *frameBytes) -{ - OI_STATUS status; - OI_UINT framelen; - OI_UINT headerlen; - uint8_t crc; - - status = FindSyncword(context, frameData, frameBytes); - if (!OI_SUCCESS(status)) { - return status; - } - if (*frameBytes < SBC_HEADER_LEN) { - return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; - } - OI_SBC_ReadHeader(&context->common, *frameData); - framelen = OI_SBC_CalculateFrameAndHeaderlen(&context->common.frameInfo, &headerlen); - if (*frameBytes < headerlen) { - return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; - } - crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData); - if (crc != context->common.frameInfo.crc) { - return OI_CODEC_SBC_CHECKSUM_MISMATCH; - } - if (*frameBytes < framelen) { - return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; - } - context->bufferedBlocks = 0; + /* + * Now decode the SBC data. Partial decode is not yet implemented for an SBC + * stream, so pass FALSE to decode body to have it enforce the old rule that + * you have to decode a whole packet at a time. + */ + status = DecodeBody(context, *frameData + SBC_HEADER_LEN, pcmData, pcmBytes, + FALSE); + if (OI_SUCCESS(status)) { *frameData += framelen; *frameBytes -= framelen; - return OI_OK; + } + TRACE(("-OI_CODEC_SBC_DecodeFrame: %d", status)); + + return status; } -uint8_t OI_CODEC_SBC_FrameCount(OI_BYTE *frameData, - uint32_t frameBytes) -{ - uint8_t mode; - uint8_t blocks; - uint8_t subbands; - uint8_t frameCount = 0; - OI_UINT frameLen; - - while (frameBytes){ - while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)){ - frameData++; - frameBytes--; - } +OI_STATUS OI_CODEC_SBC_SkipFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + const OI_BYTE** frameData, + uint32_t* frameBytes) { + OI_STATUS status; + OI_UINT framelen; + OI_UINT headerlen; + uint8_t crc; - if (frameBytes < SBC_HEADER_LEN) { - return frameCount; - } + status = FindSyncword(context, frameData, frameBytes); + if (!OI_SUCCESS(status)) { + return status; + } + if (*frameBytes < SBC_HEADER_LEN) { + return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; + } + OI_SBC_ReadHeader(&context->common, *frameData); + framelen = + OI_SBC_CalculateFrameAndHeaderlen(&context->common.frameInfo, &headerlen); + if (*frameBytes < headerlen) { + return OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA; + } + crc = OI_SBC_CalculateChecksum(&context->common.frameInfo, *frameData); + if (crc != context->common.frameInfo.crc) { + return OI_CODEC_SBC_CHECKSUM_MISMATCH; + } + if (*frameBytes < framelen) { + return OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA; + } + context->bufferedBlocks = 0; + *frameData += framelen; + *frameBytes -= framelen; + return OI_OK; +} - /* Extract and translate required fields from Header */ - subbands = mode = blocks = frameData[1];; - mode = (mode & (BIT3 | BIT2)) >> 2; - blocks = block_values[(blocks & (BIT5 | BIT4)) >> 4]; - subbands = band_values[(subbands & BIT0)]; - - /* Inline logic to avoid corrupting context */ - frameLen = blocks * frameData[2]; - switch (mode){ - case SBC_JOINT_STEREO: - frameLen += subbands + (8 * subbands); - break; - - case SBC_DUAL_CHANNEL: - frameLen *= 2; - /* fall through */ - - default: - if (mode == SBC_MONO){ - frameLen += 4*subbands; - } else { - frameLen += 8*subbands; - } - } +uint8_t OI_CODEC_SBC_FrameCount(OI_BYTE* frameData, uint32_t frameBytes) { + uint8_t mode; + uint8_t blocks; + uint8_t subbands; + uint8_t frameCount = 0; + OI_UINT frameLen; + + while (frameBytes) { + while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)) { + frameData++; + frameBytes--; + } + + if (frameBytes < SBC_HEADER_LEN) { + return frameCount; + } - frameCount++; - frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8; - if (frameBytes > frameLen){ - frameBytes -= frameLen; - frameData += frameLen; + /* Extract and translate required fields from Header */ + subbands = mode = blocks = frameData[1]; + ; + mode = (mode & (BIT3 | BIT2)) >> 2; + blocks = block_values[(blocks & (BIT5 | BIT4)) >> 4]; + subbands = band_values[(subbands & BIT0)]; + + /* Inline logic to avoid corrupting context */ + frameLen = blocks * frameData[2]; + switch (mode) { + case SBC_JOINT_STEREO: + frameLen += subbands + (8 * subbands); + break; + + case SBC_DUAL_CHANNEL: + frameLen *= 2; + /* fall through */ + + default: + if (mode == SBC_MONO) { + frameLen += 4 * subbands; } else { - frameBytes = 0; + frameLen += 8 * subbands; } } - return frameCount; + + frameCount++; + frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8; + if (frameBytes > frameLen) { + frameBytes -= frameLen; + frameData += frameLen; + } else { + frameBytes = 0; + } + } + return frameCount; } /** Read quantized subband samples from the input bitstream and expand them. */ #ifdef SPECIALIZE_READ_SAMPLES_JOINT -PRIVATE void OI_SBC_ReadSamplesJoint4(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTREAM *global_bs) -{ +PRIVATE void OI_SBC_ReadSamplesJoint4(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BITSTREAM* global_bs) { #define NROF_SUBBANDS 4 #include "readsamplesjoint.inc" #undef NROF_SUBBANDS } -PRIVATE void OI_SBC_ReadSamplesJoint8(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTREAM *global_bs) -{ +PRIVATE void OI_SBC_ReadSamplesJoint8(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BITSTREAM* global_bs) { #define NROF_SUBBANDS 8 #include "readsamplesjoint.inc" #undef NROF_SUBBANDS } -typedef void (*READ_SAMPLES)(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTREAM *global_bs); +typedef void (*READ_SAMPLES)(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BITSTREAM* global_bs); -static const READ_SAMPLES SpecializedReadSamples[] = { - OI_SBC_ReadSamplesJoint4, - OI_SBC_ReadSamplesJoint8 -}; +static const READ_SAMPLES SpecializedReadSamples[] = {OI_SBC_ReadSamplesJoint4, + OI_SBC_ReadSamplesJoint8}; #endif /* SPECIALIZE_READ_SAMPLES_JOINT */ - -PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTREAM *global_bs) -{ - OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common; - OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; +PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT* context, + OI_BITSTREAM* global_bs) { + OI_CODEC_SBC_COMMON_CONTEXT* common = &context->common; + OI_UINT nrof_subbands = common->frameInfo.nrof_subbands; #ifdef SPECIALIZE_READ_SAMPLES_JOINT - OI_ASSERT((nrof_subbands >> 3u) <= 1u); - SpecializedReadSamples[nrof_subbands >> 3](context, global_bs); + OI_ASSERT((nrof_subbands >> 3u) <= 1u); + SpecializedReadSamples[nrof_subbands >> 3](context, global_bs); #else #define NROF_SUBBANDS nrof_subbands @@ -462,4 +477,3 @@ PRIVATE void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_B } /**@}*/ - diff --git a/embdrv/sbc/decoder/srce/dequant.c b/embdrv/sbc/decoder/srce/dequant.c index 664797899..5243477a4 100644 --- a/embdrv/sbc/decoder/srce/dequant.c +++ b/embdrv/sbc/decoder/srce/dequant.c @@ -25,7 +25,8 @@ /** @file - Dequantizer for SBC decoder; reconstructs quantized representation of subband samples. + Dequantizer for SBC decoder; reconstructs quantized representation of subband + samples. @ingroup codec_internal */ @@ -43,7 +44,8 @@ dequant = 2^(scale_factor+1) * ((raw * 2.0 + 1.0) / ((2^bits) - 1) - 1) 2 <= bits <= 16 - 0 <= raw < (2^bits)-1 (the -1 is because quantized values with all 1's are forbidden) + 0 <= raw < (2^bits)-1 (the -1 is because quantized values with all 1's are + forbidden) -65535 < dequant < 65535 @endcode @@ -58,7 +60,8 @@ The helper array dequant_long is defined as follows: @code - dequant_long_long[bits] = round(2^31 * 1/((2^bits - 1) / 1.38...) for 2 <= bits <= 16 + dequant_long_long[bits] = round(2^31 * 1/((2^bits - 1) / 1.38...) for 2 <= + bits <= 16 @endcode @@ -75,8 +78,10 @@ d' = d * dequant_long[bits] - d * dequant_long_scaled[bits] <= (2^bits - 2) * (2^31 / (2^bits - 1)) - d * dequant_long_scaled[bits] <= 2^31 * (2^bits - 2)/(2^bits - 1) < 2^31 + d * dequant_long_scaled[bits] <= (2^bits - 2) * (2^31 / + (2^bits - 1)) + d * dequant_long_scaled[bits] <= 2^31 * (2^bits - 2)/(2^bits - + 1) < 2^31 @endcode Therefore, d' doesn't overflow a signed 32-bit value. @@ -85,13 +90,15 @@ d' =~ 2^31 * (raw * 2.0 + 1.0) / (2^bits - 1) / 1.38... - result = d' - 2^31/1.38... =~ 2^31 * ((raw * 2.0 + 1.0) / (2^bits - 1) - 1) / 1.38... + result = d' - 2^31/1.38... =~ 2^31 * ((raw * 2.0 + 1.0) / (2^bits - 1) - 1) / + 1.38... result is therefore a scaled approximation to dequant. It remains only to turn 2^31 into 2^(scale_factor+1). Since we're aiming for Q16.15 format, this is achieved by shifting right by (15-scale_factor): - (2^31 * x) >> (15-scale_factor) =~ 2^(31-15+scale_factor) * x = 2^15 * 2^(1+scale_factor) * x + (2^31 * x) >> (15-scale_factor) =~ 2^(31-15+scale_factor) * x = 2^15 * + 2^(1+scale_factor) * x @endcode */ @@ -116,62 +123,61 @@ const uint32_t dequant_long_unscaled[17]; /** Scales x by y bits to the right, adding a rounding factor. */ #ifndef SCALE -#define SCALE(x, y) (((x) + (1 <<((y)-1))) >> (y)) +#define SCALE(x, y) (((x) + (1 << ((y)-1))) >> (y)) #endif #ifdef DEBUG_DEQUANTIZATION #include -INLINE float dequant_float(uint32_t raw, OI_UINT scale_factor, OI_UINT bits) -{ - float result = (1 << (scale_factor+1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f); +INLINE float dequant_float(uint32_t raw, OI_UINT scale_factor, OI_UINT bits) { + float result = (1 << (scale_factor + 1)) * + ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f); - result /= SBC_DEQUANT_SCALING_FACTOR; + result /= SBC_DEQUANT_SCALING_FACTOR; - /* Unless the encoder screwed up, all correct dequantized values should - * satisfy this inequality. Non-compliant encoders which generate quantized - * values with all 1-bits set can, theoretically, trigger this assert. This - * is unlikely, however, and only an issue in debug mode. - */ - OI_ASSERT(fabs(result) < 32768 * 1.6); + /* Unless the encoder screwed up, all correct dequantized values should + * satisfy this inequality. Non-compliant encoders which generate quantized + * values with all 1-bits set can, theoretically, trigger this assert. This + * is unlikely, however, and only an issue in debug mode. + */ + OI_ASSERT(fabs(result) < 32768 * 1.6); - return result; + return result; } #endif +INLINE int32_t OI_SBC_Dequant(uint32_t raw, OI_UINT scale_factor, + OI_UINT bits) { + uint32_t d; + int32_t result; -INLINE int32_t OI_SBC_Dequant(uint32_t raw, OI_UINT scale_factor, OI_UINT bits) -{ - uint32_t d; - int32_t result; + OI_ASSERT(scale_factor <= 15); + OI_ASSERT(bits <= 16); - OI_ASSERT(scale_factor <= 15); - OI_ASSERT(bits <= 16); + if (bits <= 1) { + return 0; + } - if (bits <= 1) { - return 0; - } - - d = (raw * 2) + 1; - d *= dequant_long_scaled[bits]; - result = d - SBC_DEQUANT_LONG_SCALED_OFFSET; + d = (raw * 2) + 1; + d *= dequant_long_scaled[bits]; + result = d - SBC_DEQUANT_LONG_SCALED_OFFSET; #ifdef DEBUG_DEQUANTIZATION - { - int32_t integerized_float_result; - float float_result; + { + int32_t integerized_float_result; + float float_result; - float_result = dequant_float(raw, scale_factor, bits); - integerized_float_result = (int32_t)floor(0.5f+float_result * (1 << 15)); + float_result = dequant_float(raw, scale_factor, bits); + integerized_float_result = (int32_t)floor(0.5f + float_result * (1 << 15)); - /* This detects overflow */ - OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) || - ((result <= 0) && (integerized_float_result <= 0))); - } + /* This detects overflow */ + OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) || + ((result <= 0) && (integerized_float_result <= 0))); + } #endif - return result >> (15 - scale_factor); + return result >> (15 - scale_factor); } /* This version of Dequant does not incorporate the scaling factor of 1.38. It @@ -181,29 +187,27 @@ INLINE int32_t OI_SBC_Dequant(uint32_t raw, OI_UINT scale_factor, OI_UINT bits) * the encoder is conformant) the result will fit a 24 bit fixed point signed * value.*/ -INLINE int32_t OI_SBC_Dequant_Unscaled(uint32_t raw, OI_UINT scale_factor, OI_UINT bits) -{ - uint32_t d; - int32_t result; - - OI_ASSERT(scale_factor <= 15); - OI_ASSERT(bits <= 16); - +INLINE int32_t OI_SBC_Dequant_Unscaled(uint32_t raw, OI_UINT scale_factor, + OI_UINT bits) { + uint32_t d; + int32_t result; - if (bits <= 1) { - return 0; - } - if (bits == 16) { - result = (raw << 16) + raw - 0x7fff7fff; - return SCALE(result, 24 - scale_factor); - } + OI_ASSERT(scale_factor <= 15); + OI_ASSERT(bits <= 16); + if (bits <= 1) { + return 0; + } + if (bits == 16) { + result = (raw << 16) + raw - 0x7fff7fff; + return SCALE(result, 24 - scale_factor); + } - d = (raw * 2) + 1; - d *= dequant_long_unscaled[bits]; - result = d - 0x80000000; + d = (raw * 2) + 1; + d *= dequant_long_unscaled[bits]; + result = d - 0x80000000; - return SCALE(result, 24 - scale_factor); + return SCALE(result, 24 - scale_factor); } /** diff --git a/embdrv/sbc/decoder/srce/framing-sbc.c b/embdrv/sbc/decoder/srce/framing-sbc.c index ca6f1a624..e3b1000ca 100644 --- a/embdrv/sbc/decoder/srce/framing-sbc.c +++ b/embdrv/sbc/decoder/srce/framing-sbc.c @@ -31,24 +31,27 @@ #include "oi_codec_sbc_private.h" -const OI_CHAR* const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" }; -const OI_CHAR* const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" }; -const OI_CHAR* const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" }; -const OI_CHAR* const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" }; -const OI_CHAR* const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" }; +const OI_CHAR* const OI_CODEC_SBC_FreqText[] = { + "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000"}; +const OI_CHAR* const OI_CODEC_SBC_ModeText[] = { + "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO"}; +const OI_CHAR* const OI_CODEC_SBC_SubbandsText[] = {"SBC_SUBBANDS_4", + "SBC_SUBBANDS_8"}; +const OI_CHAR* const OI_CODEC_SBC_BlocksText[] = { + "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16"}; +const OI_CHAR* const OI_CODEC_SBC_AllocText[] = {"SBC_LOUDNESS", "SBC_SNR"}; #ifdef OI_DEBUG -void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo) -{ - printf("SBC configuration\n"); - printf(" enhanced: %s\n", frameInfo->enhanced ? "true" : "false"); - printf(" frequency: %d\n", frameInfo->frequency); - printf(" subbands: %d\n", frameInfo->nrof_subbands); - printf(" blocks: %d\n", frameInfo->nrof_blocks); - printf(" channels: %d\n", frameInfo->nrof_channels); - printf(" mode: %s\n", OI_CODEC_SBC_ModeText[frameInfo->mode]); - printf(" alloc: %s\n", OI_CODEC_SBC_AllocText[frameInfo->alloc]); - printf(" bitpool: %d\n", frameInfo->bitpool); +void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO* frameInfo) { + printf("SBC configuration\n"); + printf(" enhanced: %s\n", frameInfo->enhanced ? "true" : "false"); + printf(" frequency: %d\n", frameInfo->frequency); + printf(" subbands: %d\n", frameInfo->nrof_subbands); + printf(" blocks: %d\n", frameInfo->nrof_blocks); + printf(" channels: %d\n", frameInfo->nrof_channels); + printf(" mode: %s\n", OI_CODEC_SBC_ModeText[frameInfo->mode]); + printf(" alloc: %s\n", OI_CODEC_SBC_AllocText[frameInfo->alloc]); + printf(" bitpool: %d\n", frameInfo->bitpool); } #endif /* OI_DEBUG */ diff --git a/embdrv/sbc/decoder/srce/framing.c b/embdrv/sbc/decoder/srce/framing.c index cc2fe165d..f6f762c08 100644 --- a/embdrv/sbc/decoder/srce/framing.c +++ b/embdrv/sbc/decoder/srce/framing.c @@ -34,9 +34,8 @@ Checksum and header-related functions. @{ */ -#include "oi_codec_sbc_private.h" #include "oi_assert.h" - +#include "oi_codec_sbc_private.h" /* asdasd */ @@ -52,56 +51,101 @@ Checksum and header-related functions. #ifdef USE_WIDE_CRC /* Save space if a char is 16 bits, such as on the C54x */ const OI_BYTE crc8_wide[128] = { - 0x001d, 0x3a27, 0x7469, 0x4e53, 0xe8f5, 0xd2cf, 0x9c81, 0xa6bb, 0xcdd0, 0xf7ea, 0xb9a4, 0x839e, 0x2538, 0x1f02, 0x514c, 0x6b76, 0x879a, 0xbda0, 0xf3ee, 0xc9d4, 0x6f72, 0x5548, 0x1b06, 0x213c, 0x4a57, 0x706d, 0x3e23, 0x0419, 0xa2bf, 0x9885, 0xd6cb, 0xecf1, 0x130e, 0x2934, 0x677a, 0x5d40, 0xfbe6, 0xc1dc, 0x8f92, 0xb5a8, 0xdec3, 0xe4f9, 0xaab7, 0x908d, 0x362b, 0x0c11, 0x425f, 0x7865, 0x9489, 0xaeb3, 0xe0fd, 0xdac7, 0x7c61, 0x465b, 0x0815, 0x322f, 0x5944, 0x637e, 0x2d30, 0x170a, 0xb1ac, 0x8b96, 0xc5d8, 0xffe2, 0x263b, 0x1c01, 0x524f, 0x6875, 0xced3, 0xf4e9, 0xbaa7, 0x809d, 0xebf6, 0xd1cc, 0x9f82, 0xa5b8, 0x031e, 0x3924, 0x776a, 0x4d50, 0xa1bc, 0x9b86, 0xd5c8, 0xeff2, 0x4954, 0x736e, 0x3d20, 0x071a, 0x6c71, 0x564b, 0x1805, 0x223f, 0x8499, 0xbea3, 0xf0ed, 0xcad7, 0x3528, 0x0f12, 0x415c, 0x7b66, 0xddc0, 0xe7fa, 0xa9b4, 0x938e, 0xf8e5, 0xc2df, 0x8c91, 0xb6ab, 0x100d, 0x2a37, 0x6479, 0x5e43, 0xb2af, 0x8895, 0xc6db, 0xfce1, 0x5a47, 0x607d, 0x2e33, 0x1409, 0x7f62, 0x4558, 0x0b16, 0x312c, 0x978a, 0xadb0, 0xe3fe, 0xd9c4, + 0x001d, 0x3a27, 0x7469, 0x4e53, 0xe8f5, 0xd2cf, 0x9c81, 0xa6bb, 0xcdd0, + 0xf7ea, 0xb9a4, 0x839e, 0x2538, 0x1f02, 0x514c, 0x6b76, 0x879a, 0xbda0, + 0xf3ee, 0xc9d4, 0x6f72, 0x5548, 0x1b06, 0x213c, 0x4a57, 0x706d, 0x3e23, + 0x0419, 0xa2bf, 0x9885, 0xd6cb, 0xecf1, 0x130e, 0x2934, 0x677a, 0x5d40, + 0xfbe6, 0xc1dc, 0x8f92, 0xb5a8, 0xdec3, 0xe4f9, 0xaab7, 0x908d, 0x362b, + 0x0c11, 0x425f, 0x7865, 0x9489, 0xaeb3, 0xe0fd, 0xdac7, 0x7c61, 0x465b, + 0x0815, 0x322f, 0x5944, 0x637e, 0x2d30, 0x170a, 0xb1ac, 0x8b96, 0xc5d8, + 0xffe2, 0x263b, 0x1c01, 0x524f, 0x6875, 0xced3, 0xf4e9, 0xbaa7, 0x809d, + 0xebf6, 0xd1cc, 0x9f82, 0xa5b8, 0x031e, 0x3924, 0x776a, 0x4d50, 0xa1bc, + 0x9b86, 0xd5c8, 0xeff2, 0x4954, 0x736e, 0x3d20, 0x071a, 0x6c71, 0x564b, + 0x1805, 0x223f, 0x8499, 0xbea3, 0xf0ed, 0xcad7, 0x3528, 0x0f12, 0x415c, + 0x7b66, 0xddc0, 0xe7fa, 0xa9b4, 0x938e, 0xf8e5, 0xc2df, 0x8c91, 0xb6ab, + 0x100d, 0x2a37, 0x6479, 0x5e43, 0xb2af, 0x8895, 0xc6db, 0xfce1, 0x5a47, + 0x607d, 0x2e33, 0x1409, 0x7f62, 0x4558, 0x0b16, 0x312c, 0x978a, 0xadb0, + 0xe3fe, 0xd9c4, }; #elif defined(USE_NIBBLEWISE_CRC) -const OI_BYTE crc8_narrow[16] = { - 0x00, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53, 0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb -}; +const OI_BYTE crc8_narrow[16] = {0x00, 0x1d, 0x3a, 0x27, 0x74, 0x69, + 0x4e, 0x53, 0xe8, 0xf5, 0xd2, 0xcf, + 0x9c, 0x81, 0xa6, 0xbb}; #else const OI_BYTE crc8_narrow[256] = { - 0x00, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53, 0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb, 0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e, 0x25, 0x38, 0x1f, 0x02, 0x51, 0x4c, 0x6b, 0x76, 0x87, 0x9a, 0xbd, 0xa0, 0xf3, 0xee, 0xc9, 0xd4, 0x6f, 0x72, 0x55, 0x48, 0x1b, 0x06, 0x21, 0x3c, 0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x04, 0x19, 0xa2, 0xbf, 0x98, 0x85, 0xd6, 0xcb, 0xec, 0xf1, 0x13, 0x0e, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40, 0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8, 0xde, 0xc3, 0xe4, 0xf9, 0xaa, 0xb7, 0x90, 0x8d, 0x36, 0x2b, 0x0c, 0x11, 0x42, 0x5f, 0x78, 0x65, 0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7, 0x7c, 0x61, 0x46, 0x5b, 0x08, 0x15, 0x32, 0x2f, 0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0x0a, 0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2, 0x26, 0x3b, 0x1c, 0x01, 0x52, 0x4f, 0x68, 0x75, 0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d, 0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8, 0x03, 0x1e, 0x39, 0x24, 0x77, 0x6a, 0x4d, 0x50, 0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2, 0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x07, 0x1a, 0x6c, 0x71, 0x56, 0x4b, 0x18, 0x05, 0x22, 0x3f, 0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7, 0x35, 0x28, 0x0f, 0x12, 0x41, 0x5c, 0x7b, 0x66, 0xdd, 0xc0, 0xe7, 0xfa, 0xa9, 0xb4, 0x93, 0x8e, 0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab, 0x10, 0x0d, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43, 0xb2, 0xaf, 0x88, 0x95, 0xc6, 0xdb, 0xfc, 0xe1, 0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x09, 0x7f, 0x62, 0x45, 0x58, 0x0b, 0x16, 0x31, 0x2c, 0x97, 0x8a, 0xad, 0xb0, 0xe3, 0xfe, 0xd9, 0xc4 -}; + 0x00, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53, 0xe8, 0xf5, 0xd2, 0xcf, + 0x9c, 0x81, 0xa6, 0xbb, 0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e, + 0x25, 0x38, 0x1f, 0x02, 0x51, 0x4c, 0x6b, 0x76, 0x87, 0x9a, 0xbd, 0xa0, + 0xf3, 0xee, 0xc9, 0xd4, 0x6f, 0x72, 0x55, 0x48, 0x1b, 0x06, 0x21, 0x3c, + 0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x04, 0x19, 0xa2, 0xbf, 0x98, 0x85, + 0xd6, 0xcb, 0xec, 0xf1, 0x13, 0x0e, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40, + 0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8, 0xde, 0xc3, 0xe4, 0xf9, + 0xaa, 0xb7, 0x90, 0x8d, 0x36, 0x2b, 0x0c, 0x11, 0x42, 0x5f, 0x78, 0x65, + 0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7, 0x7c, 0x61, 0x46, 0x5b, + 0x08, 0x15, 0x32, 0x2f, 0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0x0a, + 0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2, 0x26, 0x3b, 0x1c, 0x01, + 0x52, 0x4f, 0x68, 0x75, 0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d, + 0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8, 0x03, 0x1e, 0x39, 0x24, + 0x77, 0x6a, 0x4d, 0x50, 0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2, + 0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x07, 0x1a, 0x6c, 0x71, 0x56, 0x4b, + 0x18, 0x05, 0x22, 0x3f, 0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7, + 0x35, 0x28, 0x0f, 0x12, 0x41, 0x5c, 0x7b, 0x66, 0xdd, 0xc0, 0xe7, 0xfa, + 0xa9, 0xb4, 0x93, 0x8e, 0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab, + 0x10, 0x0d, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43, 0xb2, 0xaf, 0x88, 0x95, + 0xc6, 0xdb, 0xfc, 0xe1, 0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x09, + 0x7f, 0x62, 0x45, 0x58, 0x0b, 0x16, 0x31, 0x2c, 0x97, 0x8a, 0xad, 0xb0, + 0xe3, 0xfe, 0xd9, 0xc4}; #endif const uint32_t dequant_long_scaled[17] = { - 0, - 0, - 0x1ee9e116, /* bits=2 0.24151243 1/3 * (1/1.38019122262781) (0x00000008)*/ - 0x0d3fa99c, /* bits=3 0.10350533 1/7 * (1/1.38019122262781) (0x00000013)*/ - 0x062ec69e, /* bits=4 0.04830249 1/15 * (1/1.38019122262781) (0x00000029)*/ - 0x02fddbfa, /* bits=5 0.02337217 1/31 * (1/1.38019122262781) (0x00000055)*/ - 0x0178d9f5, /* bits=6 0.01150059 1/63 * (1/1.38019122262781) (0x000000ad)*/ - 0x00baf129, /* bits=7 0.00570502 1/127 * (1/1.38019122262781) (0x0000015e)*/ - 0x005d1abe, /* bits=8 0.00284132 1/255 * (1/1.38019122262781) (0x000002bf)*/ - 0x002e760d, /* bits=9 0.00141788 1/511 * (1/1.38019122262781) (0x00000582)*/ - 0x00173536, /* bits=10 0.00070825 1/1023 * (1/1.38019122262781) (0x00000b07)*/ - 0x000b9928, /* bits=11 0.00035395 1/2047 * (1/1.38019122262781) (0x00001612)*/ - 0x0005cc37, /* bits=12 0.00017693 1/4095 * (1/1.38019122262781) (0x00002c27)*/ - 0x0002e604, /* bits=13 0.00008846 1/8191 * (1/1.38019122262781) (0x00005852)*/ - 0x000172fc, /* bits=14 0.00004422 1/16383 * (1/1.38019122262781) (0x0000b0a7)*/ - 0x0000b97d, /* bits=15 0.00002211 1/32767 * (1/1.38019122262781) (0x00016150)*/ - 0x00005cbe, /* bits=16 0.00001106 1/65535 * (1/1.38019122262781) (0x0002c2a5)*/ + 0, 0, + 0x1ee9e116, /* bits=2 0.24151243 1/3 * (1/1.38019122262781) + (0x00000008)*/ + 0x0d3fa99c, /* bits=3 0.10350533 1/7 * (1/1.38019122262781) + (0x00000013)*/ + 0x062ec69e, /* bits=4 0.04830249 1/15 * (1/1.38019122262781) + (0x00000029)*/ + 0x02fddbfa, /* bits=5 0.02337217 1/31 * (1/1.38019122262781) + (0x00000055)*/ + 0x0178d9f5, /* bits=6 0.01150059 1/63 * (1/1.38019122262781) + (0x000000ad)*/ + 0x00baf129, /* bits=7 0.00570502 1/127 * (1/1.38019122262781) + (0x0000015e)*/ + 0x005d1abe, /* bits=8 0.00284132 1/255 * (1/1.38019122262781) + (0x000002bf)*/ + 0x002e760d, /* bits=9 0.00141788 1/511 * (1/1.38019122262781) + (0x00000582)*/ + 0x00173536, /* bits=10 0.00070825 1/1023 * (1/1.38019122262781) + (0x00000b07)*/ + 0x000b9928, /* bits=11 0.00035395 1/2047 * (1/1.38019122262781) + (0x00001612)*/ + 0x0005cc37, /* bits=12 0.00017693 1/4095 * (1/1.38019122262781) + (0x00002c27)*/ + 0x0002e604, /* bits=13 0.00008846 1/8191 * (1/1.38019122262781) + (0x00005852)*/ + 0x000172fc, /* bits=14 0.00004422 1/16383 * (1/1.38019122262781) + (0x0000b0a7)*/ + 0x0000b97d, /* bits=15 0.00002211 1/32767 * (1/1.38019122262781) + (0x00016150)*/ + 0x00005cbe, /* bits=16 0.00001106 1/65535 * (1/1.38019122262781) + (0x0002c2a5)*/ }; - const uint32_t dequant_long_unscaled[17] = { - 0, - 0, - 0x2aaaaaab, /* bits=2 0.33333333 1/3 (0x00000005)*/ - 0x12492492, /* bits=3 0.14285714 1/7 (0x0000000e)*/ - 0x08888889, /* bits=4 0.06666667 1/15 (0x0000001d)*/ - 0x04210842, /* bits=5 0.03225806 1/31 (0x0000003e)*/ - 0x02082082, /* bits=6 0.01587302 1/63 (0x0000007e)*/ - 0x01020408, /* bits=7 0.00787402 1/127 (0x000000fe)*/ - 0x00808081, /* bits=8 0.00392157 1/255 (0x000001fd)*/ - 0x00402010, /* bits=9 0.00195695 1/511 (0x000003fe)*/ - 0x00200802, /* bits=10 0.00097752 1/1023 (0x000007fe)*/ - 0x00100200, /* bits=11 0.00048852 1/2047 (0x00000ffe)*/ - 0x00080080, /* bits=12 0.00024420 1/4095 (0x00001ffe)*/ - 0x00040020, /* bits=13 0.00012209 1/8191 (0x00003ffe)*/ - 0x00020008, /* bits=14 0.00006104 1/16383 (0x00007ffe)*/ - 0x00010002, /* bits=15 0.00003052 1/32767 (0x0000fffe)*/ - 0x00008001, /* bits=16 0.00001526 1/65535 (0x0001fffc)*/ + 0, 0, 0x2aaaaaab, /* bits=2 0.33333333 1/3 (0x00000005)*/ + 0x12492492, /* bits=3 0.14285714 1/7 (0x0000000e)*/ + 0x08888889, /* bits=4 0.06666667 1/15 (0x0000001d)*/ + 0x04210842, /* bits=5 0.03225806 1/31 (0x0000003e)*/ + 0x02082082, /* bits=6 0.01587302 1/63 (0x0000007e)*/ + 0x01020408, /* bits=7 0.00787402 1/127 (0x000000fe)*/ + 0x00808081, /* bits=8 0.00392157 1/255 (0x000001fd)*/ + 0x00402010, /* bits=9 0.00195695 1/511 (0x000003fe)*/ + 0x00200802, /* bits=10 0.00097752 1/1023 (0x000007fe)*/ + 0x00100200, /* bits=11 0.00048852 1/2047 (0x00000ffe)*/ + 0x00080080, /* bits=12 0.00024420 1/4095 (0x00001ffe)*/ + 0x00040020, /* bits=13 0.00012209 1/8191 (0x00003ffe)*/ + 0x00020008, /* bits=14 0.00006104 1/16383 (0x00007ffe)*/ + 0x00010002, /* bits=15 0.00003052 1/32767 (0x0000fffe)*/ + 0x00008001, /* bits=16 0.00001526 1/65535 (0x0001fffc)*/ }; #if defined(OI_DEBUG) || defined(PRINT_SAMPLES) || defined(PRINT_SCALEFACTORS) @@ -109,140 +153,132 @@ const uint32_t dequant_long_unscaled[17] = { #endif #ifdef USE_WIDE_CRC -INLINE OI_CHAR crc_iterate(uint8_t oldcrc, uint8_t next) -{ - OI_UINT crc; - OI_UINT idx; - idx = oldcrc^next; - crc = crc8_wide[idx >> 1]; - if (idx%2) { - crc &= 0xff; - } else { - crc >>= 8; - } - - return crc; +INLINE OI_CHAR crc_iterate(uint8_t oldcrc, uint8_t next) { + OI_UINT crc; + OI_UINT idx; + idx = oldcrc ^ next; + crc = crc8_wide[idx >> 1]; + if (idx % 2) { + crc &= 0xff; + } else { + crc >>= 8; + } + + return crc; } -INLINE OI_CHAR crc_iterate_top4(uint8_t oldcrc, uint8_t next) -{ - OI_UINT crc; - OI_UINT idx; - idx = (oldcrc ^ next) >> 4; - crc = crc8_wide[idx>>1]; - if (idx%2) { - crc &= 0xff; - } else { - crc >>= 8; - } - - return (oldcrc << 4) ^ crc; +INLINE OI_CHAR crc_iterate_top4(uint8_t oldcrc, uint8_t next) { + OI_UINT crc; + OI_UINT idx; + idx = (oldcrc ^ next) >> 4; + crc = crc8_wide[idx >> 1]; + if (idx % 2) { + crc &= 0xff; + } else { + crc >>= 8; + } + + return (oldcrc << 4) ^ crc; } -#else // USE_WIDE_CRC +#else // USE_WIDE_CRC -INLINE uint8_t crc_iterate_top4(uint8_t oldcrc, uint8_t next) -{ - return (oldcrc << 4) ^ crc8_narrow[(oldcrc^next) >> 4]; +INLINE uint8_t crc_iterate_top4(uint8_t oldcrc, uint8_t next) { + return (oldcrc << 4) ^ crc8_narrow[(oldcrc ^ next) >> 4]; } #ifdef USE_NIBBLEWISE_CRC -INLINE uint8_t crc_iterate(uint8_t crc, uint8_t next) -{ - crc = (crc << 4) ^ crc8_narrow[(crc^next) >> 4]; - crc = (crc << 4) ^ crc8_narrow[((crc>>4)^next)&0xf]; +INLINE uint8_t crc_iterate(uint8_t crc, uint8_t next) { + crc = (crc << 4) ^ crc8_narrow[(crc ^ next) >> 4]; + crc = (crc << 4) ^ crc8_narrow[((crc >> 4) ^ next) & 0xf]; - return crc; + return crc; } -#else // USE_NIBBLEWISE_CRC -INLINE uint8_t crc_iterate(uint8_t crc, uint8_t next) -{ - return crc8_narrow[crc^next]; +#else // USE_NIBBLEWISE_CRC +INLINE uint8_t crc_iterate(uint8_t crc, uint8_t next) { + return crc8_narrow[crc ^ next]; } #endif // USE_NIBBLEWISE_CRC -#endif // USE_WIDE_CRC - - -PRIVATE uint8_t OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYTE const *data) -{ - OI_UINT i; - uint8_t crc = 0x0f; - /* Count is the number of whole bytes subject to CRC. Actually, it's one - * more than this number, because data[3] is the CRC field itself, which is - * explicitly skipped. Since crc_iterate (should be) inlined, it's cheaper - * spacewise to include the check in the loop. This shouldn't be much of a - * bottleneck routine in the first place. */ - OI_UINT count = (frame->nrof_subbands * frame->nrof_channels / 2u) + 4; - - if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 8) { - count++; +#endif // USE_WIDE_CRC + +PRIVATE uint8_t OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO* frame, + OI_BYTE const* data) { + OI_UINT i; + uint8_t crc = 0x0f; + /* Count is the number of whole bytes subject to CRC. Actually, it's one + * more than this number, because data[3] is the CRC field itself, which is + * explicitly skipped. Since crc_iterate (should be) inlined, it's cheaper + * spacewise to include the check in the loop. This shouldn't be much of a + * bottleneck routine in the first place. */ + OI_UINT count = (frame->nrof_subbands * frame->nrof_channels / 2u) + 4; + + if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 8) { + count++; + } + + for (i = 1; i < count; i++) { + if (i != 3) { + crc = crc_iterate(crc, data[i]); } + } - for (i = 1; i < count; i++) { - if (i != 3) { - crc = crc_iterate(crc,data[i]); - } - } - - if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 4) { - crc = crc_iterate_top4(crc, data[i]); - } + if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 4) { + crc = crc_iterate_top4(crc, data[i]); + } - return crc; + return crc; } -void OI_SBC_ExpandFrameFields(OI_CODEC_SBC_FRAME_INFO *frame) -{ - frame->nrof_blocks = block_values[frame->blocks]; - frame->nrof_subbands = band_values[frame->subbands]; +void OI_SBC_ExpandFrameFields(OI_CODEC_SBC_FRAME_INFO* frame) { + frame->nrof_blocks = block_values[frame->blocks]; + frame->nrof_subbands = band_values[frame->subbands]; - frame->frequency = freq_values[frame->freqIndex]; - frame->nrof_channels = channel_values[frame->mode]; + frame->frequency = freq_values[frame->freqIndex]; + frame->nrof_channels = channel_values[frame->mode]; } /** * Unrolled macro to copy 4 32-bit aligned 32-bit values backward in memory */ -#define COPY4WORDS_BACK(_dest, _src) \ - do { \ - int32_t _a, _b, _c, _d; \ - _a = *--(_src); \ - _b = *--(_src); \ - _c = *--(_src); \ - _d = *--(_src); \ - *--(_dest) = _a; \ - *--(_dest) = _b; \ - *--(_dest) = _c; \ - *--(_dest) = _d; \ - } while (0) - +#define COPY4WORDS_BACK(_dest, _src) \ + do { \ + int32_t _a, _b, _c, _d; \ + _a = *--(_src); \ + _b = *--(_src); \ + _c = *--(_src); \ + _d = *--(_src); \ + *--(_dest) = _a; \ + *--(_dest) = _b; \ + *--(_dest) = _c; \ + *--(_dest) = _d; \ + } while (0) #if defined(USE_PLATFORM_MEMMOVE) || defined(USE_PLATFORM_MEMCPY) #include #endif -PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount) -{ +PRIVATE void shift_buffer(SBC_BUFFER_T* dest, SBC_BUFFER_T* src, + OI_UINT wordCount) { #ifdef USE_PLATFORM_MEMMOVE - memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T)); + memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T)); #elif defined(USE_PLATFORM_MEMCPY) - OI_ASSERT(((OI_CHAR *)(dest) - (OI_CHAR *)(src)) >= wordCount*sizeof(*dest)); - memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T)); + OI_ASSERT(((OI_CHAR*)(dest) - (OI_CHAR*)(src)) >= wordCount * sizeof(*dest)); + memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T)); #else - OI_UINT n; - int32_t *d; - int32_t *s; - n = wordCount / 4 / (sizeof(int32_t)/sizeof(*dest)); - OI_ASSERT((n * 4 * (sizeof(int32_t)/sizeof(*dest))) == wordCount); - - d = (void*)(dest + wordCount); - s = (void*)(src + wordCount); - - do { - COPY4WORDS_BACK(d, s); - } while (--n); + OI_UINT n; + int32_t* d; + int32_t* s; + n = wordCount / 4 / (sizeof(int32_t) / sizeof(*dest)); + OI_ASSERT((n * 4 * (sizeof(int32_t) / sizeof(*dest))) == wordCount); + + d = (void*)(dest + wordCount); + s = (void*)(src + wordCount); + + do { + COPY4WORDS_BACK(d, s); + } while (--n); #endif } /** diff --git a/embdrv/sbc/decoder/srce/oi_codec_version.c b/embdrv/sbc/decoder/srce/oi_codec_version.c index b45d41801..4b6918396 100644 --- a/embdrv/sbc/decoder/srce/oi_codec_version.c +++ b/embdrv/sbc/decoder/srce/oi_codec_version.c @@ -35,21 +35,20 @@ version number of the eSBC codec $Revision: #1 $ ******************************************************************************/ -#include "oi_stddefs.h" #include "oi_codec_sbc_private.h" +#include "oi_stddefs.h" /** Version string for the BLUEmagic 3.0 protocol stack and profiles */ -PRIVATE OI_CHAR * const codecVersion = "v1.5" +PRIVATE OI_CHAR* const codecVersion = + "v1.5" #ifdef OI_SBC_EVAL -" (Evaluation version)" + " (Evaluation version)" #endif -; + ; /* This function returns the version string for the BLUEmagic 3.0 protocol stack and profiles */ -OI_CHAR *OI_CODEC_Version(void) { - return codecVersion; -} +OI_CHAR* OI_CODEC_Version(void) { return codecVersion; } /******************************************************************************/ diff --git a/embdrv/sbc/decoder/srce/synthesis-8-generated.c b/embdrv/sbc/decoder/srce/synthesis-8-generated.c index 91fff6115..d852c7455 100644 --- a/embdrv/sbc/decoder/srce/synthesis-8-generated.c +++ b/embdrv/sbc/decoder/srce/synthesis-8-generated.c @@ -35,102 +35,126 @@ #include #ifndef CLIP_INT16 -#define CLIP_INT16(x) do { if ((x) > OI_INT16_MAX) { (x) = OI_INT16_MAX; } else if ((x) < OI_INT16_MIN) { (x) = OI_INT16_MIN; } } while (0) +#define CLIP_INT16(x) \ + do { \ + if ((x) > OI_INT16_MAX) { \ + (x) = OI_INT16_MAX; \ + } else if ((x) < OI_INT16_MIN) { \ + (x) = OI_INT16_MIN; \ + } \ + } while (0) #endif #define MUL_16S_16S(_x, _y) ((_x) * (_y)) -PRIVATE void SynthWindow80_generated(int16_t *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift) -{ - int32_t pcm_a, pcm_b; - /* 1 - stage 0 */ pcm_b = 0; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 12]))>> 3; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-23167, buffer[ 20]))>> 3; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 28]))>> 2; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-17397, buffer[ 36]))<< 1; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(9399, buffer[ 44]))<< 3; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(17397, buffer[ 52]))<< 1; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 60]))>> 2; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(23167, buffer[ 68]))>> 3; - /* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 76]))>> 3; - /* 1 - stage 0 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[0<> 5; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(9293, buffer[ 5]))>> 3; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(29293, buffer[ 11]))>> 5; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-6087, buffer[ 11]))>> 2; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-5229, buffer[ 21])); - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1247, buffer[ 21]))<< 3; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(30835, buffer[ 27]))>> 3; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-2893, buffer[ 27]))<< 3; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-27021, buffer[ 37]))<< 1; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(23671, buffer[ 37]))<< 2; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(31633, buffer[ 43]))<< 1; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(18055, buffer[ 43]))<< 1; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(17319, buffer[ 53]))<< 1; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(11537, buffer[ 53]))>> 1; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(26663, buffer[ 59]))>> 2; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1747, buffer[ 59]))<< 1; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(4555, buffer[ 69]))>> 1; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(685, buffer[ 69]))<< 1; - /* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(12419, buffer[ 75]))>> 4; - /* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(8721, buffer[ 75]))>> 7; - /* 1 - stage 1 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[1<> 6; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(11167, buffer[ 6]))>> 4; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(24995, buffer[ 10]))>> 5; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-10337, buffer[ 10]))>> 4; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-309, buffer[ 22]))<< 4; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(1917, buffer[ 22]))<< 2; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9161, buffer[ 26]))>> 3; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-30605, buffer[ 26]))>> 1; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-23063, buffer[ 38]))<< 1; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8317, buffer[ 38]))<< 3; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(27561, buffer[ 42]))<< 1; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(9553, buffer[ 42]))<< 2; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(2309, buffer[ 54]))<< 3; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(22117, buffer[ 54]))>> 4; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(12705, buffer[ 58]))>> 1; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(16383, buffer[ 58]))>> 2; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(6239, buffer[ 70]))>> 3; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(7543, buffer[ 70]))>> 3; - /* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9251, buffer[ 74]))>> 4; - /* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8603, buffer[ 74]))>> 6; - /* 1 - stage 2 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[2<> 6; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(16913, buffer[ 7]))>> 5; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(19083, buffer[ 9]))>> 5; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-8443, buffer[ 9]))>> 7; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-23641, buffer[ 23]))>> 2; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(3687, buffer[ 23]))<< 1; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-29015, buffer[ 25]))>> 4; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-301, buffer[ 25]))<< 5; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-12889, buffer[ 39]))<< 2; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(15447, buffer[ 39]))<< 2; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(6145, buffer[ 41]))<< 3; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(10255, buffer[ 41]))<< 2; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(24211, buffer[ 55]))>> 1; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-18233, buffer[ 55]))>> 3; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(23469, buffer[ 57]))>> 2; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(9405, buffer[ 57]))>> 1; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(21223, buffer[ 71]))>> 8; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(1499, buffer[ 71]))>> 1; - /* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(26913, buffer[ 73]))>> 6; - /* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(26189, buffer[ 73]))>> 7; - /* 1 - stage 3 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[3<> 4; - /* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(-5297, buffer[ 24]))<< 1; - /* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(22299, buffer[ 40]))<< 2; - /* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(10603, buffer[ 56])); - /* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(9539, buffer[ 72]))>> 4; - /* 1 - stage 4 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[4<> 3; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-23167, buffer[20])) >> 3; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[28])) >> 2; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-17397, buffer[36])) << 1; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(9399, buffer[44])) << 3; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(17397, buffer[52])) << 1; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[60])) >> 2; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(23167, buffer[68])) >> 3; + /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(8235, buffer[76])) >> 3; + /* 1 - stage 0 */ pcm_b /= 32768; + CLIP_INT16(pcm_b); + pcm[0 << strideShift] = (int16_t)pcm_b; + /* 1 - stage 1 */ pcm_a = 0; + /* 1 - stage 1 */ pcm_b = 0; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-3263, buffer[5])) >> 5; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(9293, buffer[5])) >> 3; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(29293, buffer[11])) >> 5; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-6087, buffer[11])) >> 2; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-5229, buffer[21])); + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1247, buffer[21])) << 3; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(30835, buffer[27])) >> 3; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-2893, buffer[27])) << 3; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-27021, buffer[37])) << 1; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(23671, buffer[37])) << 2; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(31633, buffer[43])) << 1; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(18055, buffer[43])) << 1; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(17319, buffer[53])) << 1; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(11537, buffer[53])) >> 1; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(26663, buffer[59])) >> 2; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1747, buffer[59])) << 1; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(4555, buffer[69])) >> 1; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(685, buffer[69])) << 1; + /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(12419, buffer[75])) >> 4; + /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(8721, buffer[75])) >> 7; + /* 1 - stage 1 */ pcm_a /= 32768; + CLIP_INT16(pcm_a); + pcm[1 << strideShift] = (int16_t)pcm_a; + /* 1 - stage 1 */ pcm_b /= 32768; + CLIP_INT16(pcm_b); + pcm[7 << strideShift] = (int16_t)pcm_b; + /* 1 - stage 2 */ pcm_a = 0; + /* 1 - stage 2 */ pcm_b = 0; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-10385, buffer[6])) >> 6; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(11167, buffer[6])) >> 4; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(24995, buffer[10])) >> 5; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-10337, buffer[10])) >> 4; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-309, buffer[22])) << 4; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(1917, buffer[22])) << 2; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9161, buffer[26])) >> 3; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-30605, buffer[26])) >> 1; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-23063, buffer[38])) << 1; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8317, buffer[38])) << 3; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(27561, buffer[42])) << 1; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(9553, buffer[42])) << 2; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(2309, buffer[54])) << 3; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(22117, buffer[54])) >> 4; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(12705, buffer[58])) >> 1; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(16383, buffer[58])) >> 2; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(6239, buffer[70])) >> 3; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(7543, buffer[70])) >> 3; + /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9251, buffer[74])) >> 4; + /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8603, buffer[74])) >> 6; + /* 1 - stage 2 */ pcm_a /= 32768; + CLIP_INT16(pcm_a); + pcm[2 << strideShift] = (int16_t)pcm_a; + /* 1 - stage 2 */ pcm_b /= 32768; + CLIP_INT16(pcm_b); + pcm[6 << strideShift] = (int16_t)pcm_b; + /* 1 - stage 3 */ pcm_a = 0; + /* 1 - stage 3 */ pcm_b = 0; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-16457, buffer[7])) >> 6; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(16913, buffer[7])) >> 5; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(19083, buffer[9])) >> 5; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-8443, buffer[9])) >> 7; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-23641, buffer[23])) >> 2; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(3687, buffer[23])) << 1; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-29015, buffer[25])) >> 4; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-301, buffer[25])) << 5; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-12889, buffer[39])) << 2; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(15447, buffer[39])) << 2; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(6145, buffer[41])) << 3; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(10255, buffer[41])) << 2; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(24211, buffer[55])) >> 1; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-18233, buffer[55])) >> 3; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(23469, buffer[57])) >> 2; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(9405, buffer[57])) >> 1; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(21223, buffer[71])) >> 8; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(1499, buffer[71])) >> 1; + /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(26913, buffer[73])) >> 6; + /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(26189, buffer[73])) >> 7; + /* 1 - stage 3 */ pcm_a /= 32768; + CLIP_INT16(pcm_a); + pcm[3 << strideShift] = (int16_t)pcm_a; + /* 1 - stage 3 */ pcm_b /= 32768; + CLIP_INT16(pcm_b); + pcm[5 << strideShift] = (int16_t)pcm_b; + /* 1 - stage 4 */ pcm_a = 0; + /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10445, buffer[8])) >> 4; + /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(-5297, buffer[24])) << 1; + /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(22299, buffer[40])) << 2; + /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10603, buffer[56])); + /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(9539, buffer[72])) >> 4; + /* 1 - stage 4 */ pcm_a /= 32768; + CLIP_INT16(pcm_a); + pcm[4 << strideShift] = (int16_t)pcm_a; } diff --git a/embdrv/sbc/decoder/srce/synthesis-dct8.c b/embdrv/sbc/decoder/srce/synthesis-dct8.c index 8a17c54da..514c9000a 100644 --- a/embdrv/sbc/decoder/srce/synthesis-dct8.c +++ b/embdrv/sbc/decoder/srce/synthesis-dct8.c @@ -37,18 +37,18 @@ #include "oi_codec_sbc_private.h" -#define AAN_C4_FIX (759250125)/* S1.30 759250125 0.707107*/ +#define AAN_C4_FIX (759250125) /* S1.30 759250125 0.707107*/ -#define AAN_C6_FIX (410903207)/* S1.30 410903207 0.382683*/ +#define AAN_C6_FIX (410903207) /* S1.30 410903207 0.382683*/ -#define AAN_Q0_FIX (581104888)/* S1.30 581104888 0.541196*/ +#define AAN_Q0_FIX (581104888) /* S1.30 581104888 0.541196*/ -#define AAN_Q1_FIX (1402911301)/* S1.30 1402911301 1.306563*/ +#define AAN_Q1_FIX (1402911301) /* S1.30 1402911301 1.306563*/ /** Scales x by y bits to the right, adding a rounding factor. */ #ifndef SCALE -#define SCALE(x, y) (((x) + (1 <<((y)-1))) >> (y)) +#define SCALE(x, y) (((x) + (1 << ((y)-1))) >> (y)) #endif /** @@ -61,107 +61,146 @@ * @return A signed 32-bit value corresponding to the 32 most significant bits * of the 64-bit product of u and v. */ -INLINE int32_t default_mul_32s_32s_hi(int32_t u, int32_t v) -{ - uint32_t u0, v0; - int32_t u1, v1, w1, w2, t; - - u0 = u & 0xFFFF; u1 = u >> 16; - v0 = v & 0xFFFF; v1 = v >> 16; - t = u0*v0; - t = u1*v0 + ((uint32_t)t >> 16); - w1 = t & 0xFFFF; - w2 = t >> 16; - w1 = u0*v1 + w1; - return u1*v1 + w2 + (w1 >> 16); +INLINE int32_t default_mul_32s_32s_hi(int32_t u, int32_t v) { + uint32_t u0, v0; + int32_t u1, v1, w1, w2, t; + + u0 = u & 0xFFFF; + u1 = u >> 16; + v0 = v & 0xFFFF; + v1 = v >> 16; + t = u0 * v0; + t = u1 * v0 + ((uint32_t)t >> 16); + w1 = t & 0xFFFF; + w2 = t >> 16; + w1 = u0 * v1 + w1; + return u1 * v1 + w2 + (w1 >> 16); } #define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y) - #ifdef DEBUG_DCT -PRIVATE void float_dct2_8(float * RESTRICT out, int32_t const *RESTRICT in) -{ -#define FIX(x,bits) (((int)floor(0.5f+((x)*((float)(1<= 8 ? 16 : 0) - and VSIGN(i) maps i%16 into {1, 1, 1, 1, 0, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1 } + W[i] = D[i]*VSIGN(i)*V[remap_V(i)] where remap_V(i) = 32*(int(i/16)) + +(i % 16) + (i % 16 >= 8 ? 16 : 0) + and VSIGN(i) maps i%16 into {1, 1, +1, 1, 0, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1 } These values correspond to the signs of the redundant values as shown in the explanation three @@ -143,7 +145,8 @@ D can be premultiplied with the DCT scaling factors to yield @code for i=0 to 79 do - W[i] = DSCALED[i]*AAN_DCT[remap_DCT(i)] where DSCALED[i] = D[i]*SCALE[i%8] + W[i] = DSCALED[i]*AAN_DCT[remap_DCT(i)] where DSCALED[i] = +D[i]*SCALE[i%8] @endcode The output samples X[0..7] are defined as sums of W: @@ -163,45 +166,52 @@ The output samples X[0..7] are defined as sums of W: #include "oi_codec_sbc_private.h" const int32_t dec_window_4[21] = { - 0, /* +0.00000000E+00 */ - 97, /* +5.36548976E-04 */ - 270, /* +1.49188357E-03 */ - 495, /* +2.73370904E-03 */ - 694, /* +3.83720193E-03 */ - 704, /* +3.89205149E-03 */ - 338, /* +1.86581691E-03 */ - -554, /* -3.06012286E-03 */ - 1974, /* +1.09137620E-02 */ - 3697, /* +2.04385087E-02 */ - 5224, /* +2.88757392E-02 */ - 5824, /* +3.21939290E-02 */ - 4681, /* +2.58767811E-02 */ - 1109, /* +6.13245186E-03 */ - -5214, /* -2.88217274E-02 */ - -14047, /* -7.76463494E-02 */ - 24529, /* +1.35593274E-01 */ - 35274, /* +1.94987841E-01 */ - 44618, /* +2.46636662E-01 */ - 50984, /* +2.81828203E-01 */ - 53243, /* +2.94315332E-01 */ + 0, /* +0.00000000E+00 */ + 97, /* +5.36548976E-04 */ + 270, /* +1.49188357E-03 */ + 495, /* +2.73370904E-03 */ + 694, /* +3.83720193E-03 */ + 704, /* +3.89205149E-03 */ + 338, /* +1.86581691E-03 */ + -554, /* -3.06012286E-03 */ + 1974, /* +1.09137620E-02 */ + 3697, /* +2.04385087E-02 */ + 5224, /* +2.88757392E-02 */ + 5824, /* +3.21939290E-02 */ + 4681, /* +2.58767811E-02 */ + 1109, /* +6.13245186E-03 */ + -5214, /* -2.88217274E-02 */ + -14047, /* -7.76463494E-02 */ + 24529, /* +1.35593274E-01 */ + 35274, /* +1.94987841E-01 */ + 44618, /* +2.46636662E-01 */ + 50984, /* +2.81828203E-01 */ + 53243, /* +2.94315332E-01 */ }; -#define DCTII_4_K06_FIX ( 11585)/* S1.14 11585 0.707107*/ +#define DCTII_4_K06_FIX (11585) /* S1.14 11585 0.707107*/ -#define DCTII_4_K08_FIX ( 21407)/* S1.14 21407 1.306563*/ +#define DCTII_4_K08_FIX (21407) /* S1.14 21407 1.306563*/ -#define DCTII_4_K09_FIX (-15137)/* S1.14 -15137 -0.923880*/ +#define DCTII_4_K09_FIX (-15137) /* S1.14 -15137 -0.923880*/ -#define DCTII_4_K10_FIX ( -8867)/* S1.14 -8867 -0.541196*/ +#define DCTII_4_K10_FIX (-8867) /* S1.14 -8867 -0.541196*/ /** Scales x by y bits to the right, adding a rounding factor. */ #ifndef SCALE -#define SCALE(x, y) (((x) + (1 <<((y)-1))) >> (y)) +#define SCALE(x, y) (((x) + (1 << ((y)-1))) >> (y)) #endif #ifndef CLIP_INT16 -#define CLIP_INT16(x) do { if ((x) > OI_INT16_MAX) { (x) = OI_INT16_MAX; } else if ((x) < OI_INT16_MIN) { (x) = OI_INT16_MIN; } } while (0) +#define CLIP_INT16(x) \ + do { \ + if ((x) > OI_INT16_MAX) { \ + (x) = OI_INT16_MAX; \ + } else if ((x) < OI_INT16_MIN) { \ + (x) = OI_INT16_MIN; \ + } \ + } while (0) #endif /** @@ -214,34 +224,41 @@ const int32_t dec_window_4[21] = { * @return A signed 32-bit value corresponding to the 32 most significant bits * of the 48-bit product of u and v. */ -INLINE int32_t default_mul_16s_32s_hi(int16_t u, int32_t v) -{ - uint16_t v0; - int16_t v1; +INLINE int32_t default_mul_16s_32s_hi(int16_t u, int32_t v) { + uint16_t v0; + int16_t v1; - int32_t w,x; + int32_t w, x; - v0 = (uint16_t)(v & 0xffff); - v1 = (int16_t) (v >> 16); + v0 = (uint16_t)(v & 0xffff); + v1 = (int16_t)(v >> 16); - w = v1 * u; - x = u * v0; + w = v1 * u; + x = u * v0; - return w + (x >> 16); + return w + (x >> 16); } #define MUL_16S_32S_HI(_x, _y) default_mul_16s_32s_hi(_x, _y) -#define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample)<<2) +#define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample) << 2) -PRIVATE void SynthWindow80_generated(int16_t *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift); -PRIVATE void SynthWindow112_generated(int16_t *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift); -PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, int32_t const * RESTRICT x); +PRIVATE void SynthWindow80_generated(int16_t* pcm, + SBC_BUFFER_T const* RESTRICT buffer, + OI_UINT strideShift); +PRIVATE void SynthWindow112_generated(int16_t* pcm, + SBC_BUFFER_T const* RESTRICT buffer, + OI_UINT strideShift); +PRIVATE void dct2_8(SBC_BUFFER_T* RESTRICT out, int32_t const* RESTRICT x); -typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT blkstart, OI_UINT blkcount); +typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT* context, int16_t* pcm, + OI_UINT blkstart, OI_UINT blkcount); #ifndef COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS -#define COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(dest, src) do { shift_buffer(dest, src, 72); } while (0) +#define COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(dest, src) \ + do { \ + shift_buffer(dest, src, 72); \ + } while (0) #endif #ifndef DCT2_8 @@ -256,99 +273,121 @@ typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, #define SYNTH112 SynthWindow112_generated #endif -PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT blkstart, OI_UINT blkcount) -{ - OI_UINT blk; - OI_UINT ch; - OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; - OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; - OI_UINT offset = context->common.filterBufferOffset; - int32_t *s = context->common.subdata + 8 * nrof_channels * blkstart; - OI_UINT blkstop = blkstart + blkcount; - - for (blk = blkstart; blk < blkstop; blk++) { - if (offset == 0) { - COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72, context->common.filterBuffer[0]); - if (nrof_channels == 2) { - COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72, context->common.filterBuffer[1]); - } - offset = context->common.filterBufferLen - 80; - } else { - offset -= 1*8; - } - - for (ch = 0; ch < nrof_channels; ch++) { - DCT2_8(context->common.filterBuffer[ch] + offset, s); - SYNTH80(pcm + ch, context->common.filterBuffer[ch] + offset, pcmStrideShift); - s += 8; - } - pcm += (8 << pcmStrideShift); +PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT* context, + int16_t* pcm, OI_UINT blkstart, + OI_UINT blkcount) { + OI_UINT blk; + OI_UINT ch; + OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; + OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; + OI_UINT offset = context->common.filterBufferOffset; + int32_t* s = context->common.subdata + 8 * nrof_channels * blkstart; + OI_UINT blkstop = blkstart + blkcount; + + for (blk = blkstart; blk < blkstop; blk++) { + if (offset == 0) { + COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS( + context->common.filterBuffer[0] + context->common.filterBufferLen - + 72, + context->common.filterBuffer[0]); + if (nrof_channels == 2) { + COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS( + context->common.filterBuffer[1] + context->common.filterBufferLen - + 72, + context->common.filterBuffer[1]); + } + offset = context->common.filterBufferLen - 80; + } else { + offset -= 1 * 8; } - context->common.filterBufferOffset = offset; + + for (ch = 0; ch < nrof_channels; ch++) { + DCT2_8(context->common.filterBuffer[ch] + offset, s); + SYNTH80(pcm + ch, context->common.filterBuffer[ch] + offset, + pcmStrideShift); + s += 8; + } + pcm += (8 << pcmStrideShift); + } + context->common.filterBufferOffset = offset; } -PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT blkstart, OI_UINT blkcount) -{ - OI_UINT blk; - OI_UINT ch; - OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; - OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; - OI_UINT offset = context->common.filterBufferOffset; - int32_t *s = context->common.subdata + 8 * nrof_channels * blkstart; - OI_UINT blkstop = blkstart + blkcount; - - for (blk = blkstart; blk < blkstop; blk++) { - if (offset == 0) { - COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72,context->common.filterBuffer[0]); - if (nrof_channels == 2) { - COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72,context->common.filterBuffer[1]); - } - offset =context->common.filterBufferLen - 80; - } else { - offset -= 8; - } - for (ch = 0; ch < nrof_channels; ch++) { - cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s); - SynthWindow40_int32_int32_symmetry_with_sum(pcm + ch, - context->common.filterBuffer[ch] + offset, - pcmStrideShift); - s += 4; - } - pcm += (4 << pcmStrideShift); +PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT* context, + int16_t* pcm, OI_UINT blkstart, + OI_UINT blkcount) { + OI_UINT blk; + OI_UINT ch; + OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; + OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; + OI_UINT offset = context->common.filterBufferOffset; + int32_t* s = context->common.subdata + 8 * nrof_channels * blkstart; + OI_UINT blkstop = blkstart + blkcount; + + for (blk = blkstart; blk < blkstop; blk++) { + if (offset == 0) { + COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS( + context->common.filterBuffer[0] + context->common.filterBufferLen - + 72, + context->common.filterBuffer[0]); + if (nrof_channels == 2) { + COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS( + context->common.filterBuffer[1] + context->common.filterBufferLen - + 72, + context->common.filterBuffer[1]); + } + offset = context->common.filterBufferLen - 80; + } else { + offset -= 8; + } + for (ch = 0; ch < nrof_channels; ch++) { + cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s); + SynthWindow40_int32_int32_symmetry_with_sum( + pcm + ch, context->common.filterBuffer[ch] + offset, pcmStrideShift); + s += 4; } - context->common.filterBufferOffset = offset; + pcm += (4 << pcmStrideShift); + } + context->common.filterBufferOffset = offset; } #ifdef SBC_ENHANCED -PRIVATE void OI_SBC_SynthFrame_Enhanced(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT blkstart, OI_UINT blkcount) -{ - OI_UINT blk; - OI_UINT ch; - OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; - OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; - OI_UINT offset = context->common.filterBufferOffset; - int32_t *s = context->common.subdata + 8 * nrof_channels * blkstart; - OI_UINT blkstop = blkstart + blkcount; - - for (blk = blkstart; blk < blkstop; blk++) { - if (offset == 0) { - COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] +context->common.filterBufferLen - 104, context->common.filterBuffer[0]); - if (nrof_channels == 2) { - COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]); - } - offset = context->common.filterBufferLen - 112; - } else { - offset -= 8; - } - for (ch = 0; ch < nrof_channels; ++ch) { - DCT2_8(context->common.filterBuffer[ch] + offset, s); - SYNTH112(pcm + ch, context->common.filterBuffer[ch] + offset, pcmStrideShift); - s += 8; - } - pcm += (8 << pcmStrideShift); +PRIVATE void OI_SBC_SynthFrame_Enhanced(OI_CODEC_SBC_DECODER_CONTEXT* context, + int16_t* pcm, OI_UINT blkstart, + OI_UINT blkcount) { + OI_UINT blk; + OI_UINT ch; + OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; + OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1; + OI_UINT offset = context->common.filterBufferOffset; + int32_t* s = context->common.subdata + 8 * nrof_channels * blkstart; + OI_UINT blkstop = blkstart + blkcount; + + for (blk = blkstart; blk < blkstop; blk++) { + if (offset == 0) { + COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS( + context->common.filterBuffer[0] + context->common.filterBufferLen - + 104, + context->common.filterBuffer[0]); + if (nrof_channels == 2) { + COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS( + context->common.filterBuffer[1] + context->common.filterBufferLen - + 104, + context->common.filterBuffer[1]); + } + offset = context->common.filterBufferLen - 112; + } else { + offset -= 8; } - context->common.filterBufferOffset = offset; + for (ch = 0; ch < nrof_channels; ++ch) { + DCT2_8(context->common.filterBuffer[ch] + offset, s); + SYNTH112(pcm + ch, context->common.filterBuffer[ch] + offset, + pcmStrideShift); + s += 8; + } + pcm += (8 << pcmStrideShift); + } + context->common.filterBufferOffset = offset; } static const SYNTH_FRAME SynthFrameEnhanced[] = { @@ -360,94 +399,105 @@ static const SYNTH_FRAME SynthFrameEnhanced[] = { #endif static const SYNTH_FRAME SynthFrame8SB[] = { - NULL, /* invalid */ + NULL, /* invalid */ OI_SBC_SynthFrame_80, /* mono */ OI_SBC_SynthFrame_80 /* stereo */ }; - static const SYNTH_FRAME SynthFrame4SB[] = { NULL, /* invalid */ OI_SBC_SynthFrame_4SB, /* mono */ OI_SBC_SynthFrame_4SB /* stereo */ }; -PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, int16_t *pcm, OI_UINT start_block, OI_UINT nrof_blocks) -{ - OI_UINT nrof_subbands = context->common.frameInfo.nrof_subbands; - OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; +PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT* context, + int16_t* pcm, OI_UINT start_block, + OI_UINT nrof_blocks) { + OI_UINT nrof_subbands = context->common.frameInfo.nrof_subbands; + OI_UINT nrof_channels = context->common.frameInfo.nrof_channels; - OI_ASSERT(nrof_subbands == 4 || nrof_subbands == 8); - if (nrof_subbands == 4) { - SynthFrame4SB[nrof_channels](context, pcm, start_block, nrof_blocks); + OI_ASSERT(nrof_subbands == 4 || nrof_subbands == 8); + if (nrof_subbands == 4) { + SynthFrame4SB[nrof_channels](context, pcm, start_block, nrof_blocks); #ifdef SBC_ENHANCED - } else if (context->common.frameInfo.enhanced) { - SynthFrameEnhanced[nrof_channels](context, pcm, start_block, nrof_blocks); + } else if (context->common.frameInfo.enhanced) { + SynthFrameEnhanced[nrof_channels](context, pcm, start_block, nrof_blocks); #endif /* SBC_ENHANCED */ - } else { - SynthFrame8SB[nrof_channels](context, pcm, start_block, nrof_blocks); - } + } else { + SynthFrame8SB[nrof_channels](context, pcm, start_block, nrof_blocks); + } } - -void SynthWindow40_int32_int32_symmetry_with_sum(int16_t *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift) -{ - int32_t pa; - int32_t pb; - - /* These values should be zero, since out[2] of the 4-band cosine modulation - * is always zero. */ - OI_ASSERT(buffer[ 2] == 0); - OI_ASSERT(buffer[10] == 0); - OI_ASSERT(buffer[18] == 0); - OI_ASSERT(buffer[26] == 0); - OI_ASSERT(buffer[34] == 0); - OI_ASSERT(buffer[42] == 0); - OI_ASSERT(buffer[50] == 0); - OI_ASSERT(buffer[58] == 0); - OI_ASSERT(buffer[66] == 0); - OI_ASSERT(buffer[74] == 0); - - - pa = dec_window_4[ 4] * (buffer[12] + buffer[76]); - pa += dec_window_4[ 8] * (buffer[16] - buffer[64]); - pa += dec_window_4[12] * (buffer[28] + buffer[60]); - pa += dec_window_4[16] * (buffer[32] - buffer[48]); - pa += dec_window_4[20] * buffer[44]; - pa = SCALE(-pa, 15); - CLIP_INT16(pa); - pcm[0 << strideShift] = (int16_t)pa; - - - pa = dec_window_4[ 1] * buffer[ 1]; pb = dec_window_4[ 1] * buffer[79]; - pb += dec_window_4[ 3] * buffer[ 3]; pa += dec_window_4[ 3] * buffer[77]; - pa += dec_window_4[ 5] * buffer[13]; pb += dec_window_4[ 5] * buffer[67]; - pb += dec_window_4[ 7] * buffer[15]; pa += dec_window_4[ 7] * buffer[65]; - pa += dec_window_4[ 9] * buffer[17]; pb += dec_window_4[ 9] * buffer[63]; - pb += dec_window_4[11] * buffer[19]; pa += dec_window_4[11] * buffer[61]; - pa += dec_window_4[13] * buffer[29]; pb += dec_window_4[13] * buffer[51]; - pb += dec_window_4[15] * buffer[31]; pa += dec_window_4[15] * buffer[49]; - pa += dec_window_4[17] * buffer[33]; pb += dec_window_4[17] * buffer[47]; - pb += dec_window_4[19] * buffer[35]; pa += dec_window_4[19] * buffer[45]; - pa = SCALE(-pa, 15); - CLIP_INT16(pa); - pcm[1 << strideShift] = (int16_t)(pa); - pb = SCALE(-pb, 15); - CLIP_INT16(pb); - pcm[3 << strideShift] = (int16_t)(pb); - - - pa = dec_window_4[2] * (/*buffer[ 2] + */ buffer[78]); /* buffer[ 2] is always zero */ - pa += dec_window_4[6] * (buffer[14] /* + buffer[66]*/); /* buffer[66] is always zero */ - pa += dec_window_4[10] * (/*buffer[18] + */ buffer[62]); /* buffer[18] is always zero */ - pa += dec_window_4[14] * (buffer[30] /* + buffer[50]*/); /* buffer[50] is always zero */ - pa += dec_window_4[18] * (/*buffer[34] + */ buffer[46]); /* buffer[34] is always zero */ - pa = SCALE(-pa, 15); - CLIP_INT16(pa); - pcm[2 << strideShift] = (int16_t)(pa); +void SynthWindow40_int32_int32_symmetry_with_sum(int16_t* pcm, + SBC_BUFFER_T buffer[80], + OI_UINT strideShift) { + int32_t pa; + int32_t pb; + + /* These values should be zero, since out[2] of the 4-band cosine modulation + * is always zero. */ + OI_ASSERT(buffer[2] == 0); + OI_ASSERT(buffer[10] == 0); + OI_ASSERT(buffer[18] == 0); + OI_ASSERT(buffer[26] == 0); + OI_ASSERT(buffer[34] == 0); + OI_ASSERT(buffer[42] == 0); + OI_ASSERT(buffer[50] == 0); + OI_ASSERT(buffer[58] == 0); + OI_ASSERT(buffer[66] == 0); + OI_ASSERT(buffer[74] == 0); + + pa = dec_window_4[4] * (buffer[12] + buffer[76]); + pa += dec_window_4[8] * (buffer[16] - buffer[64]); + pa += dec_window_4[12] * (buffer[28] + buffer[60]); + pa += dec_window_4[16] * (buffer[32] - buffer[48]); + pa += dec_window_4[20] * buffer[44]; + pa = SCALE(-pa, 15); + CLIP_INT16(pa); + pcm[0 << strideShift] = (int16_t)pa; + + pa = dec_window_4[1] * buffer[1]; + pb = dec_window_4[1] * buffer[79]; + pb += dec_window_4[3] * buffer[3]; + pa += dec_window_4[3] * buffer[77]; + pa += dec_window_4[5] * buffer[13]; + pb += dec_window_4[5] * buffer[67]; + pb += dec_window_4[7] * buffer[15]; + pa += dec_window_4[7] * buffer[65]; + pa += dec_window_4[9] * buffer[17]; + pb += dec_window_4[9] * buffer[63]; + pb += dec_window_4[11] * buffer[19]; + pa += dec_window_4[11] * buffer[61]; + pa += dec_window_4[13] * buffer[29]; + pb += dec_window_4[13] * buffer[51]; + pb += dec_window_4[15] * buffer[31]; + pa += dec_window_4[15] * buffer[49]; + pa += dec_window_4[17] * buffer[33]; + pb += dec_window_4[17] * buffer[47]; + pb += dec_window_4[19] * buffer[35]; + pa += dec_window_4[19] * buffer[45]; + pa = SCALE(-pa, 15); + CLIP_INT16(pa); + pcm[1 << strideShift] = (int16_t)(pa); + pb = SCALE(-pb, 15); + CLIP_INT16(pb); + pcm[3 << strideShift] = (int16_t)(pb); + + pa = dec_window_4[2] * + (/*buffer[ 2] + */ buffer[78]); /* buffer[ 2] is always zero */ + pa += dec_window_4[6] * + (buffer[14] /* + buffer[66]*/); /* buffer[66] is always zero */ + pa += dec_window_4[10] * + (/*buffer[18] + */ buffer[62]); /* buffer[18] is always zero */ + pa += dec_window_4[14] * + (buffer[30] /* + buffer[50]*/); /* buffer[50] is always zero */ + pa += dec_window_4[18] * + (/*buffer[34] + */ buffer[46]); /* buffer[34] is always zero */ + pa = SCALE(-pa, 15); + CLIP_INT16(pa); + pcm[2 << strideShift] = (int16_t)(pa); } - /** This routine implements the cosine modulation matrix for 4-subband synthesis. This is called "matrixing" in the SBC specification. This @@ -473,39 +523,37 @@ void SynthWindow40_int32_int32_symmetry_with_sum(int16_t *pcm, SBC_BUFFER_T buff algebra system, manually converted to fixed-point arithmetic. S4 can be implemented using only assignment and negation. */ -PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, int32_t const * RESTRICT in) -{ - int32_t f0, f1, f2, f3, f4, f7, f8, f9, f10; - int32_t y0, y1, y2, y3; - - f0 = (in[0] - in[3]); - f1 = (in[0] + in[3]); - f2 = (in[1] - in[2]); - f3 = (in[1] + in[2]); - - f4 = f1 - f3; - - y0 = -SCALE(f1 + f3, DCT_SHIFT); - y2 = -SCALE(LONG_MULT_DCT(DCTII_4_K06_FIX, f4), DCT_SHIFT); - f7 = f0 + f2; - f8 = LONG_MULT_DCT(DCTII_4_K08_FIX, f0); - f9 = LONG_MULT_DCT(DCTII_4_K09_FIX, f7); - f10 = LONG_MULT_DCT(DCTII_4_K10_FIX, f2); - y3 = -SCALE(f8 + f9, DCT_SHIFT); - y1 = -SCALE(f10 - f9, DCT_SHIFT); - - out[0] = (int16_t)-y2; - out[1] = (int16_t)-y3; - out[2] = (int16_t)0; - out[3] = (int16_t)y3; - out[4] = (int16_t)y2; - out[5] = (int16_t)y1; - out[6] = (int16_t)y0; - out[7] = (int16_t)y1; +PRIVATE void cosineModulateSynth4(SBC_BUFFER_T* RESTRICT out, + int32_t const* RESTRICT in) { + int32_t f0, f1, f2, f3, f4, f7, f8, f9, f10; + int32_t y0, y1, y2, y3; + + f0 = (in[0] - in[3]); + f1 = (in[0] + in[3]); + f2 = (in[1] - in[2]); + f3 = (in[1] + in[2]); + + f4 = f1 - f3; + + y0 = -SCALE(f1 + f3, DCT_SHIFT); + y2 = -SCALE(LONG_MULT_DCT(DCTII_4_K06_FIX, f4), DCT_SHIFT); + f7 = f0 + f2; + f8 = LONG_MULT_DCT(DCTII_4_K08_FIX, f0); + f9 = LONG_MULT_DCT(DCTII_4_K09_FIX, f7); + f10 = LONG_MULT_DCT(DCTII_4_K10_FIX, f2); + y3 = -SCALE(f8 + f9, DCT_SHIFT); + y1 = -SCALE(f10 - f9, DCT_SHIFT); + + out[0] = (int16_t)-y2; + out[1] = (int16_t)-y3; + out[2] = (int16_t)0; + out[3] = (int16_t)y3; + out[4] = (int16_t)y2; + out[5] = (int16_t)y1; + out[6] = (int16_t)y0; + out[7] = (int16_t)y1; } - - /** @} */ diff --git a/embdrv/sbc/encoder/include/sbc_dct.h b/embdrv/sbc/encoder/include/sbc_dct.h index 84c8d42d9..10123e530 100644 --- a/embdrv/sbc/encoder/include/sbc_dct.h +++ b/embdrv/sbc/encoder/include/sbc_dct.h @@ -28,64 +28,63 @@ #include "sbc_enc_func_declare.h" #if (SBC_ARM_ASM_OPT == TRUE) -#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \ -{ \ - __asm \ -{ \ - MUL s32OutLow,(int32_t)s16In2, (s32In1>>15) \ -} \ -} +#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \ + { \ + __asm { \ + MUL s32OutLow,(int32_t)s16In2, (s32In1>>15) } \ + } #else #if (SBC_DSP_OPT == TRUE) -#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow = SBC_Multiply_32_16_Simplified((int32_t)s16In2,s32In1); +#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \ + s32OutLow = SBC_Multiply_32_16_Simplified((int32_t)s16In2, s32In1); #else #if (SBC_IPAQ_OPT == TRUE) /* -#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow=(int32_t)((int32_t)(s16In2)*(int32_t)(s32In1>>15)); +#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) +s32OutLow=(int32_t)((int32_t)(s16In2)*(int32_t)(s32In1>>15)); */ -#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow=(int32_t)(((int64_t)(s16In2)*(int64_t)(s32In1))>>15); +#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \ + s32OutLow = (int32_t)(((int64_t)(s16In2) * (int64_t)(s32In1)) >> 15); #if (SBC_IS_64_MULT_IN_IDCT == TRUE) -#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \ -{ \ - s64Temp = ((int64_t) s32In2) * ((int64_t) s32In1)>>31; \ - s32OutLow = (int32_t) s64Temp; \ -} +#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \ + { \ + s64Temp = ((int64_t)s32In2) * ((int64_t)s32In1) >> 31; \ + s32OutLow = (int32_t)s64Temp; \ + } #endif #else -#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) \ -{ \ - s32In1Temp = s32In1; \ - s32In2Temp = (int32_t)s16In2; \ - \ - /* Multiply one +ve and the other -ve number */ \ - if (s32In1Temp < 0) \ - { \ - s32In1Temp ^= 0xFFFFFFFF; \ - s32In1Temp++; \ - s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \ - s32OutLow += (( s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \ - s32OutLow ^= 0xFFFFFFFF; \ - s32OutLow++; \ - } \ - else \ - { \ - s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \ - s32OutLow += (( s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \ - } \ - s32OutLow <<= 1; \ -} +#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \ + { \ + s32In1Temp = s32In1; \ + s32In2Temp = (int32_t)s16In2; \ + \ + /* Multiply one +ve and the other -ve number */ \ + if (s32In1Temp < 0) { \ + s32In1Temp ^= 0xFFFFFFFF; \ + s32In1Temp++; \ + s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \ + s32OutLow += ((s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \ + s32OutLow ^= 0xFFFFFFFF; \ + s32OutLow++; \ + } else { \ + s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \ + s32OutLow += ((s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \ + } \ + s32OutLow <<= 1; \ + } #if (SBC_IS_64_MULT_IN_IDCT == TRUE) -#define SBC_MULT_64(s32In1, s32In2, s32OutLow, s32OutHi) \ -{\ - s32OutLow=(int32_t)(((int64_t)s32In1*(int64_t)s32In2)& 0x00000000FFFFFFFF);\ - s32OutHi=(int32_t)(((int64_t)s32In1*(int64_t)s32In2)>>32);\ -} -#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \ -{ \ - s32HiTemp = 0; \ - SBC_MULT_64(s32In2,s32In1 , s32OutLow, s32HiTemp); \ - s32OutLow = (((s32OutLow>>15)&0x1FFFF) | (s32HiTemp << 17)); \ -} +#define SBC_MULT_64(s32In1, s32In2, s32OutLow, s32OutHi) \ + { \ + s32OutLow = \ + (int32_t)(((int64_t)s32In1 * (int64_t)s32In2) & 0x00000000FFFFFFFF); \ + s32OutHi = (int32_t)(((int64_t)s32In1 * (int64_t)s32In2) >> 32); \ + } +#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \ + { \ + s32HiTemp = 0; \ + SBC_MULT_64(s32In2, s32In1, s32OutLow, s32HiTemp); \ + s32OutLow = (((s32OutLow >> 15) & 0x1FFFF) | (s32HiTemp << 17)); \ + } #endif #endif diff --git a/embdrv/sbc/encoder/include/sbc_enc_func_declare.h b/embdrv/sbc/encoder/include/sbc_enc_func_declare.h index a7039acbc..3fbe06a5e 100644 --- a/embdrv/sbc/encoder/include/sbc_enc_func_declare.h +++ b/embdrv/sbc/encoder/include/sbc_enc_func_declare.h @@ -37,21 +37,20 @@ extern const int32_t gas32CoeffFor8SBs[]; /* Global functions*/ -extern void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *CodecParams); -extern void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *CodecParams); +extern void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS* CodecParams); +extern void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS* CodecParams); -extern void SbcAnalysisInit (void); +extern void SbcAnalysisInit(void); -extern void SbcAnalysisFilter4(SBC_ENC_PARAMS *strEncParams, int16_t *input); -extern void SbcAnalysisFilter8(SBC_ENC_PARAMS *strEncParams, int16_t *input); +extern void SbcAnalysisFilter4(SBC_ENC_PARAMS* strEncParams, int16_t* input); +extern void SbcAnalysisFilter8(SBC_ENC_PARAMS* strEncParams, int16_t* input); -extern void SBC_FastIDCT8 (int32_t *pInVect, int32_t *pOutVect); -extern void SBC_FastIDCT4 (int32_t *x0, int32_t *pOutVect); +extern void SBC_FastIDCT8(int32_t* pInVect, int32_t* pOutVect); +extern void SBC_FastIDCT4(int32_t* x0, int32_t* pOutVect); -extern uint32_t EncPacking(SBC_ENC_PARAMS *strEncParams, uint8_t *output); -extern void EncQuantizer(SBC_ENC_PARAMS *); +extern uint32_t EncPacking(SBC_ENC_PARAMS* strEncParams, uint8_t* output); +extern void EncQuantizer(SBC_ENC_PARAMS*); #if (SBC_DSP_OPT == TRUE) - int32_t SBC_Multiply_32_16_Simplified(int32_t s32In2Temp,int32_t s32In1Temp); +int32_t SBC_Multiply_32_16_Simplified(int32_t s32In2Temp, int32_t s32In1Temp); #endif #endif - diff --git a/embdrv/sbc/encoder/include/sbc_encoder.h b/embdrv/sbc/encoder/include/sbc_encoder.h index 6f038ad48..11b7bc799 100644 --- a/embdrv/sbc/encoder/include/sbc_encoder.h +++ b/embdrv/sbc/encoder/include/sbc_encoder.h @@ -28,7 +28,7 @@ #define ENCODER_VERSION "0025" #ifdef BUILDCFG - #include "bt_target.h" +#include "bt_target.h" #endif /*DEFINES*/ @@ -42,9 +42,9 @@ #define SBC_MAX_NUM_OF_SUBBANDS 8 #define SBC_MAX_NUM_OF_CHANNELS 2 -#define SBC_MAX_NUM_OF_BLOCKS 16 +#define SBC_MAX_NUM_OF_BLOCKS 16 -#define SBC_LOUDNESS 0 +#define SBC_LOUDNESS 0 #define SBC_SNR 1 #define SUB_BANDS_8 8 @@ -55,17 +55,17 @@ #define SBC_sf44100 2 #define SBC_sf48000 3 -#define SBC_MONO 0 -#define SBC_DUAL 1 -#define SBC_STEREO 2 -#define SBC_JOINT_STEREO 3 +#define SBC_MONO 0 +#define SBC_DUAL 1 +#define SBC_STEREO 2 +#define SBC_JOINT_STEREO 3 #define SBC_BLOCK_0 4 #define SBC_BLOCK_1 8 #define SBC_BLOCK_2 12 #define SBC_BLOCK_3 16 -#define SBC_NULL 0 +#define SBC_NULL 0 #ifndef SBC_MAX_NUM_FRAME #define SBC_MAX_NUM_FRAME 1 @@ -112,7 +112,7 @@ */ /* -> not recomended, more MIPS for the same restitution. */ #ifndef SBC_IS_64_MULT_IN_WINDOW_ACCU -#define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE +#define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE #endif /*SBC_IS_64_MULT_IN_WINDOW_ACCU */ /* Set SBC_IS_64_MULT_IN_IDCT to TRUE to use 64 bits multiplication in the DCT @@ -123,7 +123,7 @@ */ /* CAUTION: It only apply in the if SBC_FAST_DCT is set to TRUE */ #ifndef SBC_IS_64_MULT_IN_IDCT -#define SBC_IS_64_MULT_IN_IDCT FALSE +#define SBC_IS_64_MULT_IN_IDCT FALSE #endif /*SBC_IS_64_MULT_IN_IDCT */ /* set SBC_IS_64_MULT_IN_QUANTIZER to TRUE to use 64 bits multiplication in the @@ -132,12 +132,12 @@ /* setting this flag to FALSE adds a whistling noise at 5.5 and 11 KHz usualy * not perceptible by human's hears. */ #ifndef SBC_IS_64_MULT_IN_QUANTIZER -#define SBC_IS_64_MULT_IN_QUANTIZER TRUE +#define SBC_IS_64_MULT_IN_QUANTIZER TRUE #endif /*SBC_IS_64_MULT_IN_IDCT */ /* Debug only: set this flag to FALSE to disable fast DCT algorithm */ #ifndef SBC_FAST_DCT -#define SBC_FAST_DCT TRUE +#define SBC_FAST_DCT TRUE #endif /*SBC_FAST_DCT */ /* In case we do not use joint stereo mode the flag save some RAM and ROM in @@ -146,7 +146,7 @@ #define SBC_JOINT_STE_INCLUDED TRUE #endif -#define MINIMUM_ENC_VX_BUFFER_SIZE (8*10*2) +#define MINIMUM_ENC_VX_BUFFER_SIZE (8 * 10 * 2) #ifndef ENC_VX_BUFFER_SIZE #define ENC_VX_BUFFER_SIZE (MINIMUM_ENC_VX_BUFFER_SIZE + 64) /*#define ENC_VX_BUFFER_SIZE MINIMUM_ENC_VX_BUFFER_SIZE + 1024*/ @@ -159,37 +159,39 @@ /*constants used for index calculation*/ #define SBC_BLK (SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS) -#define SBC_MAX_PCM_BUFFER_SIZE (SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS) +#define SBC_MAX_PCM_BUFFER_SIZE \ + (SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * \ + SBC_MAX_NUM_OF_SUBBANDS) #include "sbc_types.h" -typedef struct SBC_ENC_PARAMS_TAG -{ - int16_t s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/ - int16_t s16ChannelMode; /* mono, dual, streo or joint streo*/ - int16_t s16NumOfSubBands; /* 4 or 8 */ - int16_t s16NumOfChannels; - int16_t s16NumOfBlocks; /* 4, 8, 12 or 16*/ - int16_t s16AllocationMethod; /* loudness or SNR*/ - int16_t s16BitPool; /* 16*numOfSb for mono & dual; - 32*numOfSb for stereo & joint stereo */ - uint16_t u16BitRate; +typedef struct SBC_ENC_PARAMS_TAG { + int16_t s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/ + int16_t s16ChannelMode; /* mono, dual, streo or joint streo*/ + int16_t s16NumOfSubBands; /* 4 or 8 */ + int16_t s16NumOfChannels; + int16_t s16NumOfBlocks; /* 4, 8, 12 or 16*/ + int16_t s16AllocationMethod; /* loudness or SNR*/ + int16_t s16BitPool; /* 16*numOfSb for mono & dual; + 32*numOfSb for stereo & joint stereo */ + uint16_t u16BitRate; #if (SBC_JOINT_STE_INCLUDED == TRUE) - int16_t as16Join[SBC_MAX_NUM_OF_SUBBANDS]; /*1 if JS, 0 otherwise*/ + int16_t as16Join[SBC_MAX_NUM_OF_SUBBANDS]; /*1 if JS, 0 otherwise*/ #endif - int16_t s16MaxBitNeed; - int16_t as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS]; + int16_t s16MaxBitNeed; + int16_t as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS]; - int16_t s16ScartchMemForBitAlloc[16]; + int16_t s16ScartchMemForBitAlloc[16]; - int32_t s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS]; + int32_t s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * + SBC_MAX_NUM_OF_BLOCKS]; - int16_t as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS]; + int16_t as16Bits[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS]; - uint16_t FrameHeader; + uint16_t FrameHeader; -}SBC_ENC_PARAMS; +} SBC_ENC_PARAMS; #ifdef __cplusplus extern "C" { @@ -197,8 +199,9 @@ extern "C" { /* Encode the frame using SBC. The output is written into |output|. Return * number of bytes written. */ -extern uint32_t SBC_Encode(SBC_ENC_PARAMS *strEncParams, int16_t *input, uint8_t *output); -extern void SBC_Encoder_Init(SBC_ENC_PARAMS *strEncParams); +extern uint32_t SBC_Encode(SBC_ENC_PARAMS* strEncParams, int16_t* input, + uint8_t* output); +extern void SBC_Encoder_Init(SBC_ENC_PARAMS* strEncParams); #ifdef __cplusplus } diff --git a/embdrv/sbc/encoder/include/sbc_if.h b/embdrv/sbc/encoder/include/sbc_if.h index de8dd4829..19706d2b4 100644 --- a/embdrv/sbc/encoder/include/sbc_if.h +++ b/embdrv/sbc/encoder/include/sbc_if.h @@ -34,7 +34,7 @@ int SBC_init(int pcm_sample_freq, int channels, int bits_per_sample); /* SBC_write - called repeatedly with pcm_in pointer - increasing by length until track is finished. + increasing by length until track is finished. pcm_in - pointer to PCM buffer length - any @@ -42,6 +42,6 @@ int SBC_init(int pcm_sample_freq, int channels, int bits_per_sample); return - number of bytes written to sbc_out */ -int SBC_write(unsigned char *pcm_in, int length, unsigned char *sbc_out); +int SBC_write(unsigned char* pcm_in, int length, unsigned char* sbc_out); #endif diff --git a/embdrv/sbc/encoder/include/sbc_types.h b/embdrv/sbc/encoder/include/sbc_types.h index f16a22b2e..ffa3f3217 100644 --- a/embdrv/sbc/encoder/include/sbc_types.h +++ b/embdrv/sbc/encoder/include/sbc_types.h @@ -33,6 +33,6 @@ #include "bt_types.h" -#define abs32(x) ( ((x) >= 0) ? (x) : (-(x)) ) +#define abs32(x) (((x) >= 0) ? (x) : (-(x))) #endif diff --git a/embdrv/sbc/encoder/srce/sbc_analysis.c b/embdrv/sbc/encoder/srce/sbc_analysis.c index 9541bf899..ddc997867 100644 --- a/embdrv/sbc/encoder/srce/sbc_analysis.c +++ b/embdrv/sbc/encoder/srce/sbc_analysis.c @@ -23,206 +23,269 @@ * ******************************************************************************/ #include -#include "sbc_encoder.h" #include "sbc_enc_func_declare.h" +#include "sbc_encoder.h" /*#include */ #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) -#define WIND_4_SUBBANDS_0_1 (int32_t)0x01659F45 /* gas32CoeffFor4SBs[8] = -gas32CoeffFor4SBs[32] = 0x01659F45 */ -#define WIND_4_SUBBANDS_0_2 (int32_t)0x115B1ED2 /* gas32CoeffFor4SBs[16] = -gas32CoeffFor4SBs[24] = 0x115B1ED2 */ -#define WIND_4_SUBBANDS_1_0 (int32_t)0x001194E6 /* gas32CoeffFor4SBs[1 et 39] = 0x001194E6 */ -#define WIND_4_SUBBANDS_1_1 (int32_t)0x029DBAA3 /* gas32CoeffFor4SBs[9 et 31] = 0x029DBAA3 */ -#define WIND_4_SUBBANDS_1_2 (int32_t)0x18F55C90 /* gas32CoeffFor4SBs[17 et 23] = 0x18F55C90 */ -#define WIND_4_SUBBANDS_1_3 (int32_t)0xF60FAF37 /* gas32CoeffFor4SBs[15 et 25] = 0xF60FAF37 */ -#define WIND_4_SUBBANDS_1_4 (int32_t)0xFF9BB9D5 /* gas32CoeffFor4SBs[7 et 33] = 0xFF9BB9D5 */ -#define WIND_4_SUBBANDS_2_0 (int32_t)0x0030E2D3 /* gas32CoeffFor4SBs[2 et 38] = 0x0030E2D3 */ -#define WIND_4_SUBBANDS_2_1 (int32_t)0x03B23341 /* gas32CoeffFor4SBs[10 et 30] = 0x03B23341 */ -#define WIND_4_SUBBANDS_2_2 (int32_t)0x1F91CA46 /* gas32CoeffFor4SBs[18 et 22] = 0x1F91CA46 */ -#define WIND_4_SUBBANDS_2_3 (int32_t)0xFC4F91D4 /* gas32CoeffFor4SBs[14 et 26] = 0xFC4F91D4 */ -#define WIND_4_SUBBANDS_2_4 (int32_t)0x003D239B /* gas32CoeffFor4SBs[6 et 34] = 0x003D239B */ -#define WIND_4_SUBBANDS_3_0 (int32_t)0x00599403 /* gas32CoeffFor4SBs[3 et 37] = 0x00599403 */ -#define WIND_4_SUBBANDS_3_1 (int32_t)0x041EEE40 /* gas32CoeffFor4SBs[11 et 29] = 0x041EEE40 */ -#define WIND_4_SUBBANDS_3_2 (int32_t)0x2412F251 /* gas32CoeffFor4SBs[19 et 21] = 0x2412F251 */ -#define WIND_4_SUBBANDS_3_3 (int32_t)0x00C8F2BC /* gas32CoeffFor4SBs[13 et 27] = 0x00C8F2BC */ -#define WIND_4_SUBBANDS_3_4 (int32_t)0x007F88E4 /* gas32CoeffFor4SBs[5 et 35] = 0x007F88E4 */ -#define WIND_4_SUBBANDS_4_0 (int32_t)0x007DBCC8 /* gas32CoeffFor4SBs[4 et 36] = 0x007DBCC8 */ -#define WIND_4_SUBBANDS_4_1 (int32_t)0x034FEE2C /* gas32CoeffFor4SBs[12 et 28] = 0x034FEE2C */ -#define WIND_4_SUBBANDS_4_2 (int32_t)0x25AC1FF2 /* gas32CoeffFor4SBs[20] = 0x25AC1FF2 */ +#define WIND_4_SUBBANDS_0_1 \ + (int32_t)0x01659F45 /* gas32CoeffFor4SBs[8] = -gas32CoeffFor4SBs[32] = \ + 0x01659F45 */ +#define WIND_4_SUBBANDS_0_2 \ + (int32_t)0x115B1ED2 /* gas32CoeffFor4SBs[16] = -gas32CoeffFor4SBs[24] = \ + 0x115B1ED2 */ +#define WIND_4_SUBBANDS_1_0 \ + (int32_t)0x001194E6 /* gas32CoeffFor4SBs[1 et 39] = 0x001194E6 */ +#define WIND_4_SUBBANDS_1_1 \ + (int32_t)0x029DBAA3 /* gas32CoeffFor4SBs[9 et 31] = 0x029DBAA3 */ +#define WIND_4_SUBBANDS_1_2 \ + (int32_t)0x18F55C90 /* gas32CoeffFor4SBs[17 et 23] = 0x18F55C90 */ +#define WIND_4_SUBBANDS_1_3 \ + (int32_t)0xF60FAF37 /* gas32CoeffFor4SBs[15 et 25] = 0xF60FAF37 */ +#define WIND_4_SUBBANDS_1_4 \ + (int32_t)0xFF9BB9D5 /* gas32CoeffFor4SBs[7 et 33] = 0xFF9BB9D5 */ +#define WIND_4_SUBBANDS_2_0 \ + (int32_t)0x0030E2D3 /* gas32CoeffFor4SBs[2 et 38] = 0x0030E2D3 */ +#define WIND_4_SUBBANDS_2_1 \ + (int32_t)0x03B23341 /* gas32CoeffFor4SBs[10 et 30] = 0x03B23341 */ +#define WIND_4_SUBBANDS_2_2 \ + (int32_t)0x1F91CA46 /* gas32CoeffFor4SBs[18 et 22] = 0x1F91CA46 */ +#define WIND_4_SUBBANDS_2_3 \ + (int32_t)0xFC4F91D4 /* gas32CoeffFor4SBs[14 et 26] = 0xFC4F91D4 */ +#define WIND_4_SUBBANDS_2_4 \ + (int32_t)0x003D239B /* gas32CoeffFor4SBs[6 et 34] = 0x003D239B */ +#define WIND_4_SUBBANDS_3_0 \ + (int32_t)0x00599403 /* gas32CoeffFor4SBs[3 et 37] = 0x00599403 */ +#define WIND_4_SUBBANDS_3_1 \ + (int32_t)0x041EEE40 /* gas32CoeffFor4SBs[11 et 29] = 0x041EEE40 */ +#define WIND_4_SUBBANDS_3_2 \ + (int32_t)0x2412F251 /* gas32CoeffFor4SBs[19 et 21] = 0x2412F251 */ +#define WIND_4_SUBBANDS_3_3 \ + (int32_t)0x00C8F2BC /* gas32CoeffFor4SBs[13 et 27] = 0x00C8F2BC */ +#define WIND_4_SUBBANDS_3_4 \ + (int32_t)0x007F88E4 /* gas32CoeffFor4SBs[5 et 35] = 0x007F88E4 */ +#define WIND_4_SUBBANDS_4_0 \ + (int32_t)0x007DBCC8 /* gas32CoeffFor4SBs[4 et 36] = 0x007DBCC8 */ +#define WIND_4_SUBBANDS_4_1 \ + (int32_t)0x034FEE2C /* gas32CoeffFor4SBs[12 et 28] = 0x034FEE2C */ +#define WIND_4_SUBBANDS_4_2 \ + (int32_t)0x25AC1FF2 /* gas32CoeffFor4SBs[20] = 0x25AC1FF2 */ -#define WIND_8_SUBBANDS_0_1 (int32_t)0x00B97348 /* 16 0x00B97348 */ -#define WIND_8_SUBBANDS_0_2 (int32_t)0x08B4307A /* 32 0x08B4307A */ -#define WIND_8_SUBBANDS_1_0 (int32_t)0x00052173 /* 1 et 79 = 0x00052173 */ -#define WIND_8_SUBBANDS_1_1 (int32_t)0x01071B96 /* 17 et 63 = 0x01071B96 */ -#define WIND_8_SUBBANDS_1_2 (int32_t)0x0A9F3E9A /* 33 et 47 = 0x0A9F3E9A*/ -#define WIND_8_SUBBANDS_1_3 (int32_t)0xF9312891 /* 31 et 49 = 0xF9312891 */ -#define WIND_8_SUBBANDS_1_4 (int32_t)0xFF8D6793 /* 15 et 65 = 0xFF8D6793 */ -#define WIND_8_SUBBANDS_2_0 (int32_t)0x000B3F71 /* 2 et 78 = 0x000B3F71 */ -#define WIND_8_SUBBANDS_2_1 (int32_t)0x0156B3CA /* 18 et 62 = 0x0156B3CA */ -#define WIND_8_SUBBANDS_2_2 (int32_t)0x0C7D59B6 /* 34 et 46 = 0x0C7D59B6 */ -#define WIND_8_SUBBANDS_2_3 (int32_t)0xFAFF95FC /* 30 et 50 = 0xFAFF95FC */ -#define WIND_8_SUBBANDS_2_4 (int32_t)0xFFC9F10E /* 14 et 66 = 0xFFC9F10E */ -#define WIND_8_SUBBANDS_3_0 (int32_t)0x00122C7D /* 3 et 77 = 0x00122C7D*/ -#define WIND_8_SUBBANDS_3_1 (int32_t)0x01A1B38B /* 19 et 61 = 0x01A1B38B */ -#define WIND_8_SUBBANDS_3_2 (int32_t)0x0E3BB16F /* 35 et 45 = 0x0E3BB16F */ -#define WIND_8_SUBBANDS_3_3 (int32_t)0xFCA86E7E /* 29 et 51 = 0xFCA86E7E */ -#define WIND_8_SUBBANDS_3_4 (int32_t)0xFFFA2413 /* 13 et 67 = 0xFFFA2413 */ -#define WIND_8_SUBBANDS_4_0 (int32_t)0x001AFF89 /* 4 et 66 = 0x001AFF89 */ -#define WIND_8_SUBBANDS_4_1 (int32_t)0x01E0224C /* 20 et 60 = 0x01E0224C */ -#define WIND_8_SUBBANDS_4_2 (int32_t)0x0FC721F9 /* 36 et 44 = 0x0FC721F9 */ -#define WIND_8_SUBBANDS_4_3 (int32_t)0xFE20435D /* 28 et 52 = 0xFE20435D */ -#define WIND_8_SUBBANDS_4_4 (int32_t)0x001D8FD2 /* 12 et 68 = 0x001D8FD2 */ -#define WIND_8_SUBBANDS_5_0 (int32_t)0x00255A62 /* 5 et 75 = 0x00255A62 */ -#define WIND_8_SUBBANDS_5_1 (int32_t)0x0209291F /* 21 et 59 = 0x0209291F */ -#define WIND_8_SUBBANDS_5_2 (int32_t)0x110ECEF0 /* 37 et 43 = 0x110ECEF0 */ -#define WIND_8_SUBBANDS_5_3 (int32_t)0xFF5EEB73 /* 27 et 53 = 0xFF5EEB73 */ -#define WIND_8_SUBBANDS_5_4 (int32_t)0x0034F8B6 /* 11 et 69 = 0x0034F8B6 */ -#define WIND_8_SUBBANDS_6_0 (int32_t)0x003060F4 /* 6 et 74 = 0x003060F4 */ -#define WIND_8_SUBBANDS_6_1 (int32_t)0x02138653 /* 22 et 58 = 0x02138653 */ -#define WIND_8_SUBBANDS_6_2 (int32_t)0x120435FA /* 38 et 42 = 0x120435FA */ -#define WIND_8_SUBBANDS_6_3 (int32_t)0x005FD0FF /* 26 et 54 = 0x005FD0FF */ -#define WIND_8_SUBBANDS_6_4 (int32_t)0x00415B75 /* 10 et 70 = 0x00415B75 */ -#define WIND_8_SUBBANDS_7_0 (int32_t)0x003A72E7 /* 7 et 73 = 0x003A72E7 */ -#define WIND_8_SUBBANDS_7_1 (int32_t)0x01F5F424 /* 23 et 57 = 0x01F5F424 */ -#define WIND_8_SUBBANDS_7_2 (int32_t)0x129C226F /* 39 et 41 = 0x129C226F */ -#define WIND_8_SUBBANDS_7_3 (int32_t)0x01223EBA /* 25 et 55 = 0x01223EBA */ -#define WIND_8_SUBBANDS_7_4 (int32_t)0x0044EF48 /* 9 et 71 = 0x0044EF48 */ -#define WIND_8_SUBBANDS_8_0 (int32_t)0x0041EC6A /* 8 et 72 = 0x0041EC6A */ -#define WIND_8_SUBBANDS_8_1 (int32_t)0x01A7ECEF /* 24 et 56 = 0x01A7ECEF */ -#define WIND_8_SUBBANDS_8_2 (int32_t)0x12CF6C75 /* 40 = 0x12CF6C75 */ +#define WIND_8_SUBBANDS_0_1 (int32_t)0x00B97348 /* 16 0x00B97348 */ +#define WIND_8_SUBBANDS_0_2 (int32_t)0x08B4307A /* 32 0x08B4307A */ +#define WIND_8_SUBBANDS_1_0 (int32_t)0x00052173 /* 1 et 79 = 0x00052173 */ +#define WIND_8_SUBBANDS_1_1 (int32_t)0x01071B96 /* 17 et 63 = 0x01071B96 */ +#define WIND_8_SUBBANDS_1_2 (int32_t)0x0A9F3E9A /* 33 et 47 = 0x0A9F3E9A*/ +#define WIND_8_SUBBANDS_1_3 (int32_t)0xF9312891 /* 31 et 49 = 0xF9312891 */ +#define WIND_8_SUBBANDS_1_4 (int32_t)0xFF8D6793 /* 15 et 65 = 0xFF8D6793 */ +#define WIND_8_SUBBANDS_2_0 (int32_t)0x000B3F71 /* 2 et 78 = 0x000B3F71 */ +#define WIND_8_SUBBANDS_2_1 (int32_t)0x0156B3CA /* 18 et 62 = 0x0156B3CA */ +#define WIND_8_SUBBANDS_2_2 (int32_t)0x0C7D59B6 /* 34 et 46 = 0x0C7D59B6 */ +#define WIND_8_SUBBANDS_2_3 (int32_t)0xFAFF95FC /* 30 et 50 = 0xFAFF95FC */ +#define WIND_8_SUBBANDS_2_4 (int32_t)0xFFC9F10E /* 14 et 66 = 0xFFC9F10E */ +#define WIND_8_SUBBANDS_3_0 (int32_t)0x00122C7D /* 3 et 77 = 0x00122C7D*/ +#define WIND_8_SUBBANDS_3_1 (int32_t)0x01A1B38B /* 19 et 61 = 0x01A1B38B */ +#define WIND_8_SUBBANDS_3_2 (int32_t)0x0E3BB16F /* 35 et 45 = 0x0E3BB16F */ +#define WIND_8_SUBBANDS_3_3 (int32_t)0xFCA86E7E /* 29 et 51 = 0xFCA86E7E */ +#define WIND_8_SUBBANDS_3_4 (int32_t)0xFFFA2413 /* 13 et 67 = 0xFFFA2413 */ +#define WIND_8_SUBBANDS_4_0 (int32_t)0x001AFF89 /* 4 et 66 = 0x001AFF89 */ +#define WIND_8_SUBBANDS_4_1 (int32_t)0x01E0224C /* 20 et 60 = 0x01E0224C */ +#define WIND_8_SUBBANDS_4_2 (int32_t)0x0FC721F9 /* 36 et 44 = 0x0FC721F9 */ +#define WIND_8_SUBBANDS_4_3 (int32_t)0xFE20435D /* 28 et 52 = 0xFE20435D */ +#define WIND_8_SUBBANDS_4_4 (int32_t)0x001D8FD2 /* 12 et 68 = 0x001D8FD2 */ +#define WIND_8_SUBBANDS_5_0 (int32_t)0x00255A62 /* 5 et 75 = 0x00255A62 */ +#define WIND_8_SUBBANDS_5_1 (int32_t)0x0209291F /* 21 et 59 = 0x0209291F */ +#define WIND_8_SUBBANDS_5_2 (int32_t)0x110ECEF0 /* 37 et 43 = 0x110ECEF0 */ +#define WIND_8_SUBBANDS_5_3 (int32_t)0xFF5EEB73 /* 27 et 53 = 0xFF5EEB73 */ +#define WIND_8_SUBBANDS_5_4 (int32_t)0x0034F8B6 /* 11 et 69 = 0x0034F8B6 */ +#define WIND_8_SUBBANDS_6_0 (int32_t)0x003060F4 /* 6 et 74 = 0x003060F4 */ +#define WIND_8_SUBBANDS_6_1 (int32_t)0x02138653 /* 22 et 58 = 0x02138653 */ +#define WIND_8_SUBBANDS_6_2 (int32_t)0x120435FA /* 38 et 42 = 0x120435FA */ +#define WIND_8_SUBBANDS_6_3 (int32_t)0x005FD0FF /* 26 et 54 = 0x005FD0FF */ +#define WIND_8_SUBBANDS_6_4 (int32_t)0x00415B75 /* 10 et 70 = 0x00415B75 */ +#define WIND_8_SUBBANDS_7_0 (int32_t)0x003A72E7 /* 7 et 73 = 0x003A72E7 */ +#define WIND_8_SUBBANDS_7_1 (int32_t)0x01F5F424 /* 23 et 57 = 0x01F5F424 */ +#define WIND_8_SUBBANDS_7_2 (int32_t)0x129C226F /* 39 et 41 = 0x129C226F */ +#define WIND_8_SUBBANDS_7_3 (int32_t)0x01223EBA /* 25 et 55 = 0x01223EBA */ +#define WIND_8_SUBBANDS_7_4 (int32_t)0x0044EF48 /* 9 et 71 = 0x0044EF48 */ +#define WIND_8_SUBBANDS_8_0 (int32_t)0x0041EC6A /* 8 et 72 = 0x0041EC6A */ +#define WIND_8_SUBBANDS_8_1 (int32_t)0x01A7ECEF /* 24 et 56 = 0x01A7ECEF */ +#define WIND_8_SUBBANDS_8_2 (int32_t)0x12CF6C75 /* 40 = 0x12CF6C75 */ #else -#define WIND_4_SUBBANDS_0_1 (int16_t)0x0166 /* gas32CoeffFor4SBs[8] = -gas32CoeffFor4SBs[32] = 0x01659F45 */ -#define WIND_4_SUBBANDS_0_2 (int16_t)0x115B /* gas32CoeffFor4SBs[16] = -gas32CoeffFor4SBs[24] = 0x115B1ED2 */ -#define WIND_4_SUBBANDS_1_0 (int16_t)0x0012 /* gas32CoeffFor4SBs[1 et 39] = 0x001194E6 */ -#define WIND_4_SUBBANDS_1_1 (int16_t)0x029E /* gas32CoeffFor4SBs[9 et 31] = 0x029DBAA3 */ -#define WIND_4_SUBBANDS_1_2 (int16_t)0x18F5 /* gas32CoeffFor4SBs[17 et 23] = 0x18F55C90 */ -#define WIND_4_SUBBANDS_1_3 (int16_t)0xF610 /* gas32CoeffFor4SBs[15 et 25] = 0xF60FAF37 */ -#define WIND_4_SUBBANDS_1_4 (int16_t)0xFF9C /* gas32CoeffFor4SBs[7 et 33] = 0xFF9BB9D5 */ -#define WIND_4_SUBBANDS_2_0 (int16_t)0x0031 /* gas32CoeffFor4SBs[2 et 38] = 0x0030E2D3 */ -#define WIND_4_SUBBANDS_2_1 (int16_t)0x03B2 /* gas32CoeffFor4SBs[10 et 30] = 0x03B23341 */ -#define WIND_4_SUBBANDS_2_2 (int16_t)0x1F91 /* gas32CoeffFor4SBs[18 et 22] = 0x1F91CA46 */ -#define WIND_4_SUBBANDS_2_3 (int16_t)0xFC50 /* gas32CoeffFor4SBs[14 et 26] = 0xFC4F91D4 */ -#define WIND_4_SUBBANDS_2_4 (int16_t)0x003D /* gas32CoeffFor4SBs[6 et 34] = 0x003D239B */ -#define WIND_4_SUBBANDS_3_0 (int16_t)0x005A /* gas32CoeffFor4SBs[3 et 37] = 0x00599403 */ -#define WIND_4_SUBBANDS_3_1 (int16_t)0x041F /* gas32CoeffFor4SBs[11 et 29] = 0x041EEE40 */ -#define WIND_4_SUBBANDS_3_2 (int16_t)0x2413 /* gas32CoeffFor4SBs[19 et 21] = 0x2412F251 */ -#define WIND_4_SUBBANDS_3_3 (int16_t)0x00C9 /* gas32CoeffFor4SBs[13 et 27] = 0x00C8F2BC */ -#define WIND_4_SUBBANDS_3_4 (int16_t)0x0080 /* gas32CoeffFor4SBs[5 et 35] = 0x007F88E4 */ -#define WIND_4_SUBBANDS_4_0 (int16_t)0x007E /* gas32CoeffFor4SBs[4 et 36] = 0x007DBCC8 */ -#define WIND_4_SUBBANDS_4_1 (int16_t)0x0350 /* gas32CoeffFor4SBs[12 et 28] = 0x034FEE2C */ -#define WIND_4_SUBBANDS_4_2 (int16_t)0x25AC /* gas32CoeffFor4SBs[20] = 25AC1FF2 */ +#define WIND_4_SUBBANDS_0_1 \ + (int16_t)0x0166 /* gas32CoeffFor4SBs[8] = -gas32CoeffFor4SBs[32] = \ + 0x01659F45 */ +#define WIND_4_SUBBANDS_0_2 \ + (int16_t)0x115B /* gas32CoeffFor4SBs[16] = -gas32CoeffFor4SBs[24] = \ + 0x115B1ED2 */ +#define WIND_4_SUBBANDS_1_0 \ + (int16_t)0x0012 /* gas32CoeffFor4SBs[1 et 39] = 0x001194E6 */ +#define WIND_4_SUBBANDS_1_1 \ + (int16_t)0x029E /* gas32CoeffFor4SBs[9 et 31] = 0x029DBAA3 */ +#define WIND_4_SUBBANDS_1_2 \ + (int16_t)0x18F5 /* gas32CoeffFor4SBs[17 et 23] = 0x18F55C90 */ +#define WIND_4_SUBBANDS_1_3 \ + (int16_t)0xF610 /* gas32CoeffFor4SBs[15 et 25] = 0xF60FAF37 */ +#define WIND_4_SUBBANDS_1_4 \ + (int16_t)0xFF9C /* gas32CoeffFor4SBs[7 et 33] = 0xFF9BB9D5 */ +#define WIND_4_SUBBANDS_2_0 \ + (int16_t)0x0031 /* gas32CoeffFor4SBs[2 et 38] = 0x0030E2D3 */ +#define WIND_4_SUBBANDS_2_1 \ + (int16_t)0x03B2 /* gas32CoeffFor4SBs[10 et 30] = 0x03B23341 */ +#define WIND_4_SUBBANDS_2_2 \ + (int16_t)0x1F91 /* gas32CoeffFor4SBs[18 et 22] = 0x1F91CA46 */ +#define WIND_4_SUBBANDS_2_3 \ + (int16_t)0xFC50 /* gas32CoeffFor4SBs[14 et 26] = 0xFC4F91D4 */ +#define WIND_4_SUBBANDS_2_4 \ + (int16_t)0x003D /* gas32CoeffFor4SBs[6 et 34] = 0x003D239B */ +#define WIND_4_SUBBANDS_3_0 \ + (int16_t)0x005A /* gas32CoeffFor4SBs[3 et 37] = 0x00599403 */ +#define WIND_4_SUBBANDS_3_1 \ + (int16_t)0x041F /* gas32CoeffFor4SBs[11 et 29] = 0x041EEE40 */ +#define WIND_4_SUBBANDS_3_2 \ + (int16_t)0x2413 /* gas32CoeffFor4SBs[19 et 21] = 0x2412F251 */ +#define WIND_4_SUBBANDS_3_3 \ + (int16_t)0x00C9 /* gas32CoeffFor4SBs[13 et 27] = 0x00C8F2BC */ +#define WIND_4_SUBBANDS_3_4 \ + (int16_t)0x0080 /* gas32CoeffFor4SBs[5 et 35] = 0x007F88E4 */ +#define WIND_4_SUBBANDS_4_0 \ + (int16_t)0x007E /* gas32CoeffFor4SBs[4 et 36] = 0x007DBCC8 */ +#define WIND_4_SUBBANDS_4_1 \ + (int16_t)0x0350 /* gas32CoeffFor4SBs[12 et 28] = 0x034FEE2C */ +#define WIND_4_SUBBANDS_4_2 \ + (int16_t)0x25AC /* gas32CoeffFor4SBs[20] = 25AC1FF2 */ -#define WIND_8_SUBBANDS_0_1 (int16_t)0x00B9 /* 16 0x12CF6C75 */ -#define WIND_8_SUBBANDS_0_2 (int16_t)0x08B4 /* 32 0x08B4307A */ -#define WIND_8_SUBBANDS_1_0 (int16_t)0x0005 /* 1 et 79 = 0x00052173 */ -#define WIND_8_SUBBANDS_1_1 (int16_t)0x0107 /* 17 et 63 = 0x01071B96 */ -#define WIND_8_SUBBANDS_1_2 (int16_t)0x0A9F /* 33 et 47 = 0x0A9F3E9A*/ -#define WIND_8_SUBBANDS_1_3 (int16_t)0xF931 /* 31 et 49 = 0xF9312891 */ -#define WIND_8_SUBBANDS_1_4 (int16_t)0xFF8D /* 15 et 65 = 0xFF8D6793 */ -#define WIND_8_SUBBANDS_2_0 (int16_t)0x000B /* 2 et 78 = 0x000B3F71 */ -#define WIND_8_SUBBANDS_2_1 (int16_t)0x0157 /* 18 et 62 = 0x0156B3CA */ -#define WIND_8_SUBBANDS_2_2 (int16_t)0x0C7D /* 34 et 46 = 0x0C7D59B6 */ -#define WIND_8_SUBBANDS_2_3 (int16_t)0xFB00 /* 30 et 50 = 0xFAFF95FC */ -#define WIND_8_SUBBANDS_2_4 (int16_t)0xFFCA /* 14 et 66 = 0xFFC9F10E */ -#define WIND_8_SUBBANDS_3_0 (int16_t)0x0012 /* 3 et 77 = 0x00122C7D*/ -#define WIND_8_SUBBANDS_3_1 (int16_t)0x01A2 /* 19 et 61 = 0x01A1B38B */ -#define WIND_8_SUBBANDS_3_2 (int16_t)0x0E3C /* 35 et 45 = 0x0E3BB16F */ -#define WIND_8_SUBBANDS_3_3 (int16_t)0xFCA8 /* 29 et 51 = 0xFCA86E7E */ -#define WIND_8_SUBBANDS_3_4 (int16_t)0xFFFA /* 13 et 67 = 0xFFFA2413 */ -#define WIND_8_SUBBANDS_4_0 (int16_t)0x001B /* 4 et 66 = 0x001AFF89 */ -#define WIND_8_SUBBANDS_4_1 (int16_t)0x01E0 /* 20 et 60 = 0x01E0224C */ -#define WIND_8_SUBBANDS_4_2 (int16_t)0x0FC7 /* 36 et 44 = 0x0FC721F9 */ -#define WIND_8_SUBBANDS_4_3 (int16_t)0xFE20 /* 28 et 52 = 0xFE20435D */ -#define WIND_8_SUBBANDS_4_4 (int16_t)0x001E /* 12 et 68 = 0x001D8FD2 */ -#define WIND_8_SUBBANDS_5_0 (int16_t)0x0025 /* 5 et 75 = 0x00255A62 */ -#define WIND_8_SUBBANDS_5_1 (int16_t)0x0209 /* 21 et 59 = 0x0209291F */ -#define WIND_8_SUBBANDS_5_2 (int16_t)0x110F /* 37 et 43 = 0x110ECEF0 */ -#define WIND_8_SUBBANDS_5_3 (int16_t)0xFF5F /* 27 et 53 = 0xFF5EEB73 */ -#define WIND_8_SUBBANDS_5_4 (int16_t)0x0035 /* 11 et 69 = 0x0034F8B6 */ -#define WIND_8_SUBBANDS_6_0 (int16_t)0x0030 /* 6 et 74 = 0x003060F4 */ -#define WIND_8_SUBBANDS_6_1 (int16_t)0x0214 /* 22 et 58 = 0x02138653 */ -#define WIND_8_SUBBANDS_6_2 (int16_t)0x1204 /* 38 et 42 = 0x120435FA */ -#define WIND_8_SUBBANDS_6_3 (int16_t)0x0060 /* 26 et 54 = 0x005FD0FF */ -#define WIND_8_SUBBANDS_6_4 (int16_t)0x0041 /* 10 et 70 = 0x00415B75 */ -#define WIND_8_SUBBANDS_7_0 (int16_t)0x003A /* 7 et 73 = 0x003A72E7 */ -#define WIND_8_SUBBANDS_7_1 (int16_t)0x01F6 /* 23 et 57 = 0x01F5F424 */ -#define WIND_8_SUBBANDS_7_2 (int16_t)0x129C /* 39 et 41 = 0x129C226F */ -#define WIND_8_SUBBANDS_7_3 (int16_t)0x0122 /* 25 et 55 = 0x01223EBA */ -#define WIND_8_SUBBANDS_7_4 (int16_t)0x0045 /* 9 et 71 = 0x0044EF48 */ -#define WIND_8_SUBBANDS_8_0 (int16_t)0x0042 /* 8 et 72 = 0x0041EC6A */ -#define WIND_8_SUBBANDS_8_1 (int16_t)0x01A8 /* 24 et 56 = 0x01A7ECEF */ -#define WIND_8_SUBBANDS_8_2 (int16_t)0x12CF /* 40 = 0x12CF6C75 */ +#define WIND_8_SUBBANDS_0_1 (int16_t)0x00B9 /* 16 0x12CF6C75 */ +#define WIND_8_SUBBANDS_0_2 (int16_t)0x08B4 /* 32 0x08B4307A */ +#define WIND_8_SUBBANDS_1_0 (int16_t)0x0005 /* 1 et 79 = 0x00052173 */ +#define WIND_8_SUBBANDS_1_1 (int16_t)0x0107 /* 17 et 63 = 0x01071B96 */ +#define WIND_8_SUBBANDS_1_2 (int16_t)0x0A9F /* 33 et 47 = 0x0A9F3E9A*/ +#define WIND_8_SUBBANDS_1_3 (int16_t)0xF931 /* 31 et 49 = 0xF9312891 */ +#define WIND_8_SUBBANDS_1_4 (int16_t)0xFF8D /* 15 et 65 = 0xFF8D6793 */ +#define WIND_8_SUBBANDS_2_0 (int16_t)0x000B /* 2 et 78 = 0x000B3F71 */ +#define WIND_8_SUBBANDS_2_1 (int16_t)0x0157 /* 18 et 62 = 0x0156B3CA */ +#define WIND_8_SUBBANDS_2_2 (int16_t)0x0C7D /* 34 et 46 = 0x0C7D59B6 */ +#define WIND_8_SUBBANDS_2_3 (int16_t)0xFB00 /* 30 et 50 = 0xFAFF95FC */ +#define WIND_8_SUBBANDS_2_4 (int16_t)0xFFCA /* 14 et 66 = 0xFFC9F10E */ +#define WIND_8_SUBBANDS_3_0 (int16_t)0x0012 /* 3 et 77 = 0x00122C7D*/ +#define WIND_8_SUBBANDS_3_1 (int16_t)0x01A2 /* 19 et 61 = 0x01A1B38B */ +#define WIND_8_SUBBANDS_3_2 (int16_t)0x0E3C /* 35 et 45 = 0x0E3BB16F */ +#define WIND_8_SUBBANDS_3_3 (int16_t)0xFCA8 /* 29 et 51 = 0xFCA86E7E */ +#define WIND_8_SUBBANDS_3_4 (int16_t)0xFFFA /* 13 et 67 = 0xFFFA2413 */ +#define WIND_8_SUBBANDS_4_0 (int16_t)0x001B /* 4 et 66 = 0x001AFF89 */ +#define WIND_8_SUBBANDS_4_1 (int16_t)0x01E0 /* 20 et 60 = 0x01E0224C */ +#define WIND_8_SUBBANDS_4_2 (int16_t)0x0FC7 /* 36 et 44 = 0x0FC721F9 */ +#define WIND_8_SUBBANDS_4_3 (int16_t)0xFE20 /* 28 et 52 = 0xFE20435D */ +#define WIND_8_SUBBANDS_4_4 (int16_t)0x001E /* 12 et 68 = 0x001D8FD2 */ +#define WIND_8_SUBBANDS_5_0 (int16_t)0x0025 /* 5 et 75 = 0x00255A62 */ +#define WIND_8_SUBBANDS_5_1 (int16_t)0x0209 /* 21 et 59 = 0x0209291F */ +#define WIND_8_SUBBANDS_5_2 (int16_t)0x110F /* 37 et 43 = 0x110ECEF0 */ +#define WIND_8_SUBBANDS_5_3 (int16_t)0xFF5F /* 27 et 53 = 0xFF5EEB73 */ +#define WIND_8_SUBBANDS_5_4 (int16_t)0x0035 /* 11 et 69 = 0x0034F8B6 */ +#define WIND_8_SUBBANDS_6_0 (int16_t)0x0030 /* 6 et 74 = 0x003060F4 */ +#define WIND_8_SUBBANDS_6_1 (int16_t)0x0214 /* 22 et 58 = 0x02138653 */ +#define WIND_8_SUBBANDS_6_2 (int16_t)0x1204 /* 38 et 42 = 0x120435FA */ +#define WIND_8_SUBBANDS_6_3 (int16_t)0x0060 /* 26 et 54 = 0x005FD0FF */ +#define WIND_8_SUBBANDS_6_4 (int16_t)0x0041 /* 10 et 70 = 0x00415B75 */ +#define WIND_8_SUBBANDS_7_0 (int16_t)0x003A /* 7 et 73 = 0x003A72E7 */ +#define WIND_8_SUBBANDS_7_1 (int16_t)0x01F6 /* 23 et 57 = 0x01F5F424 */ +#define WIND_8_SUBBANDS_7_2 (int16_t)0x129C /* 39 et 41 = 0x129C226F */ +#define WIND_8_SUBBANDS_7_3 (int16_t)0x0122 /* 25 et 55 = 0x01223EBA */ +#define WIND_8_SUBBANDS_7_4 (int16_t)0x0045 /* 9 et 71 = 0x0044EF48 */ +#define WIND_8_SUBBANDS_8_0 (int16_t)0x0042 /* 8 et 72 = 0x0041EC6A */ +#define WIND_8_SUBBANDS_8_1 (int16_t)0x01A8 /* 24 et 56 = 0x01A7ECEF */ +#define WIND_8_SUBBANDS_8_2 (int16_t)0x12CF /* 40 = 0x12CF6C75 */ #endif #if (SBC_USE_ARM_PRAGMA == TRUE) #pragma arm section zidata = "sbc_s32_analysis_section" #endif -static int32_t s32DCTY[16] = {0}; -static int32_t s32X[ENC_VX_BUFFER_SIZE/2]; -static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/ +static int32_t s32DCTY[16] = {0}; +static int32_t s32X[ENC_VX_BUFFER_SIZE / 2]; +static int16_t* s16X = + (int16_t*)s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/ #if (SBC_USE_ARM_PRAGMA == TRUE) #pragma arm section zidata #endif /* This macro is for 4 subbands */ -#define SHIFTUP_X4 \ -{ \ - ps32X=(int32_t *)(s16X+EncMaxShiftCounter+38); \ - for (i=0;i<9;i++) \ - { \ - *ps32X=*(ps32X-2-(ShiftCounter>>1)); ps32X--; \ - *ps32X=*(ps32X-2-(ShiftCounter>>1)); ps32X--; \ - } \ -} -#define SHIFTUP_X4_2 \ -{ \ - ps32X=(int32_t *)(s16X+EncMaxShiftCounter+38); \ - ps32X2=(int32_t *)(s16X+(EncMaxShiftCounter<<1)+78); \ - for (i=0;i<9;i++) \ - { \ - *ps32X=*(ps32X-2-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-2-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - *ps32X=*(ps32X-2-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-2-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - } \ -} +#define SHIFTUP_X4 \ + { \ + ps32X = (int32_t*)(s16X + EncMaxShiftCounter + 38); \ + for (i = 0; i < 9; i++) { \ + *ps32X = *(ps32X - 2 - (ShiftCounter >> 1)); \ + ps32X--; \ + *ps32X = *(ps32X - 2 - (ShiftCounter >> 1)); \ + ps32X--; \ + } \ + } +#define SHIFTUP_X4_2 \ + { \ + ps32X = (int32_t*)(s16X + EncMaxShiftCounter + 38); \ + ps32X2 = (int32_t*)(s16X + (EncMaxShiftCounter << 1) + 78); \ + for (i = 0; i < 9; i++) { \ + *ps32X = *(ps32X - 2 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 2 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + *ps32X = *(ps32X - 2 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 2 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + } \ + } /* This macro is for 8 subbands */ -#define SHIFTUP_X8 \ -{ \ - ps32X=(int32_t *)(s16X+EncMaxShiftCounter+78); \ - for (i=0;i<9;i++) \ - { \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); ps32X--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); ps32X--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); ps32X--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); ps32X--; \ - } \ -} -#define SHIFTUP_X8_2 \ -{ \ - ps32X=(int32_t *)(s16X+EncMaxShiftCounter+78); \ - ps32X2=(int32_t *)(s16X+(EncMaxShiftCounter<<1)+158); \ - for (i=0;i<9;i++) \ - { \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-4-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-4-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-4-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - *ps32X=*(ps32X-4-(ShiftCounter>>1)); *(ps32X2)=*(ps32X2-4-(ShiftCounter>>1)); ps32X--; ps32X2--; \ - } \ -} +#define SHIFTUP_X8 \ + { \ + ps32X = (int32_t*)(s16X + EncMaxShiftCounter + 78); \ + for (i = 0; i < 9; i++) { \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + } \ + } +#define SHIFTUP_X8_2 \ + { \ + ps32X = (int32_t*)(s16X + EncMaxShiftCounter + 78); \ + ps32X2 = (int32_t*)(s16X + (EncMaxShiftCounter << 1) + 158); \ + for (i = 0; i < 9; i++) { \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + *ps32X = *(ps32X - 4 - (ShiftCounter >> 1)); \ + *(ps32X2) = *(ps32X2 - 4 - (ShiftCounter >> 1)); \ + ps32X--; \ + ps32X2--; \ + } \ + } #if (SBC_ARM_ASM_OPT == TRUE) -#define WINDOW_ACCU_8_0 \ -{\ - __asm\ - {\ +#define WINDOW_ACCU_8_0 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_0_1,(s16X[ChOffset+16]-s16X[ChOffset+64]);\ MLA s32Hi,WIND_8_SUBBANDS_0_2,(s16X[ChOffset+32]-s16X[ChOffset+48]),s32Hi;\ - MOV s32DCTY[0],s32Hi;\ - }\ -} -#define WINDOW_ACCU_8_1_15 \ -{\ - __asm\ - {\ + MOV s32DCTY[0],s32Hi; \ + } \ + } +#define WINDOW_ACCU_8_1_15 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_1_0,s16X[ChOffset+1];\ MUL s32Hi2,WIND_8_SUBBANDS_1_0,s16X[ChOffset+64+15];\ MLA s32Hi,WIND_8_SUBBANDS_1_1,s16X[ChOffset+16+1],s32Hi;\ @@ -234,13 +297,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_1_4,s16X[ChOffset+64+1],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_1_4,s16X[ChOffset+15],s32Hi2;\ MOV s32DCTY[1],s32Hi;\ - MOV s32DCTY[15],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_2_14 \ -{\ - __asm\ - {\ + MOV s32DCTY[15],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_2_14 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_2_0,s16X[ChOffset+2];\ MUL s32Hi2,WIND_8_SUBBANDS_2_0,s16X[ChOffset+64+14];\ MLA s32Hi,WIND_8_SUBBANDS_2_1,s16X[ChOffset+16+2],s32Hi;\ @@ -252,13 +314,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_2_4,s16X[ChOffset+64+2],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_2_4,s16X[ChOffset+14],s32Hi2;\ MOV s32DCTY[2],s32Hi;\ - MOV s32DCTY[14],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_3_13 \ -{\ - __asm\ - {\ + MOV s32DCTY[14],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_3_13 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_3_0,s16X[ChOffset+3];\ MUL s32Hi2,WIND_8_SUBBANDS_3_0,s16X[ChOffset+64+13];\ MLA s32Hi,WIND_8_SUBBANDS_3_1,s16X[ChOffset+16+3],s32Hi;\ @@ -270,13 +331,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_3_4,s16X[ChOffset+64+3],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_3_4,s16X[ChOffset+13],s32Hi2;\ MOV s32DCTY[3],s32Hi;\ - MOV s32DCTY[13],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_4_12 \ -{\ - __asm\ - {\ + MOV s32DCTY[13],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_4_12 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_4_0,s16X[ChOffset+4];\ MUL s32Hi2,WIND_8_SUBBANDS_4_0,s16X[ChOffset+64+12];\ MLA s32Hi,WIND_8_SUBBANDS_4_1,s16X[ChOffset+16+4],s32Hi;\ @@ -288,13 +348,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_4_4,s16X[ChOffset+64+4],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_4_4,s16X[ChOffset+12],s32Hi2;\ MOV s32DCTY[4],s32Hi;\ - MOV s32DCTY[12],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_5_11 \ -{\ - __asm\ - {\ + MOV s32DCTY[12],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_5_11 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_5_0,s16X[ChOffset+5];\ MUL s32Hi2,WIND_8_SUBBANDS_5_0,s16X[ChOffset+64+11];\ MLA s32Hi,WIND_8_SUBBANDS_5_1,s16X[ChOffset+16+5],s32Hi;\ @@ -306,13 +365,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_5_4,s16X[ChOffset+64+5],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_5_4,s16X[ChOffset+11],s32Hi2;\ MOV s32DCTY[5],s32Hi;\ - MOV s32DCTY[11],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_6_10 \ -{\ - __asm\ - {\ + MOV s32DCTY[11],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_6_10 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_6_0,s16X[ChOffset+6];\ MUL s32Hi2,WIND_8_SUBBANDS_6_0,s16X[ChOffset+64+10];\ MLA s32Hi,WIND_8_SUBBANDS_6_1,s16X[ChOffset+16+6],s32Hi;\ @@ -324,13 +382,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_6_4,s16X[ChOffset+64+6],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_6_4,s16X[ChOffset+10],s32Hi2;\ MOV s32DCTY[6],s32Hi;\ - MOV s32DCTY[10],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_7_9 \ -{\ - __asm\ - {\ + MOV s32DCTY[10],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_7_9 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_7_0,s16X[ChOffset+7];\ MUL s32Hi2,WIND_8_SUBBANDS_7_0,s16X[ChOffset+64+9];\ MLA s32Hi,WIND_8_SUBBANDS_7_1,s16X[ChOffset+16+7],s32Hi;\ @@ -342,32 +399,29 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_8_SUBBANDS_7_4,s16X[ChOffset+64+7],s32Hi;\ MLA s32Hi2,WIND_8_SUBBANDS_7_4,s16X[ChOffset+9],s32Hi2;\ MOV s32DCTY[7],s32Hi;\ - MOV s32DCTY[9],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_8_8 \ -{\ - __asm\ - {\ + MOV s32DCTY[9],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_8_8 \ + { \ + __asm {\ MUL s32Hi,WIND_8_SUBBANDS_8_0,(s16X[ChOffset+8]+s16X[ChOffset+8+64]);\ MLA s32Hi,WIND_8_SUBBANDS_8_1,(s16X[ChOffset+8+16]+s16X[ChOffset+8+64]),s32Hi;\ MLA s32Hi,WIND_8_SUBBANDS_8_2,s16X[ChOffset+8+32],s32Hi;\ - MOV s32DCTY[8],s32Hi;\ - }\ -} -#define WINDOW_ACCU_4_0 \ -{\ - __asm\ - {\ + MOV s32DCTY[8],s32Hi; \ + } \ + } +#define WINDOW_ACCU_4_0 \ + { \ + __asm {\ MUL s32Hi,WIND_4_SUBBANDS_0_1,(s16X[ChOffset+8]-s16X[ChOffset+32]);\ MLA s32Hi,WIND_4_SUBBANDS_0_2,(s16X[ChOffset+16]-s16X[ChOffset+24]),s32Hi;\ - MOV s32DCTY[0],s32Hi;\ - }\ -} -#define WINDOW_ACCU_4_1_7 \ -{\ - __asm\ - {\ + MOV s32DCTY[0],s32Hi; \ + } \ + } +#define WINDOW_ACCU_4_1_7 \ + { \ + __asm {\ MUL s32Hi,WIND_4_SUBBANDS_1_0,s16X[ChOffset+1];\ MUL s32Hi2,WIND_4_SUBBANDS_1_0,s16X[ChOffset+32+7];\ MLA s32Hi,WIND_4_SUBBANDS_1_1,s16X[ChOffset+8+1],s32Hi;\ @@ -379,13 +433,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_4_SUBBANDS_1_4,s16X[ChOffset+32+1],s32Hi;\ MLA s32Hi2,WIND_4_SUBBANDS_1_4,s16X[ChOffset+7],s32Hi2;\ MOV s32DCTY[1],s32Hi;\ - MOV s32DCTY[7],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_4_2_6 \ -{\ - __asm\ - {\ + MOV s32DCTY[7],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_4_2_6 \ + { \ + __asm {\ MUL s32Hi,WIND_4_SUBBANDS_2_0,s16X[ChOffset+2];\ MUL s32Hi2,WIND_4_SUBBANDS_2_0,s16X[ChOffset+32+6];\ MLA s32Hi,WIND_4_SUBBANDS_2_1,s16X[ChOffset+8+2],s32Hi;\ @@ -397,13 +450,12 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_4_SUBBANDS_2_4,s16X[ChOffset+32+2],s32Hi;\ MLA s32Hi2,WIND_4_SUBBANDS_2_4,s16X[ChOffset+6],s32Hi2;\ MOV s32DCTY[2],s32Hi;\ - MOV s32DCTY[6],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_4_3_5 \ -{\ - __asm\ - {\ + MOV s32DCTY[6],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_4_3_5 \ + { \ + __asm {\ MUL s32Hi,WIND_4_SUBBANDS_3_0,s16X[ChOffset+3];\ MUL s32Hi2,WIND_4_SUBBANDS_3_0,s16X[ChOffset+32+5];\ MLA s32Hi,WIND_4_SUBBANDS_3_1,s16X[ChOffset+8+3],s32Hi;\ @@ -415,693 +467,934 @@ static int16_t *s16X=(int16_t*) s32X; /* s16X must be 32 bits aligned cf MLA s32Hi,WIND_4_SUBBANDS_3_4,s16X[ChOffset+32+3],s32Hi;\ MLA s32Hi2,WIND_4_SUBBANDS_3_4,s16X[ChOffset+5],s32Hi2;\ MOV s32DCTY[3],s32Hi;\ - MOV s32DCTY[5],s32Hi2;\ - }\ -} -#define WINDOW_ACCU_4_4 \ -{\ - __asm\ - {\ + MOV s32DCTY[5],s32Hi2; \ + } \ + } +#define WINDOW_ACCU_4_4 \ + { \ + __asm {\ MUL s32Hi,WIND_4_SUBBANDS_4_0,(s16X[ChOffset+4]+s16X[ChOffset+4+32]);\ MLA s32Hi,WIND_4_SUBBANDS_4_1,(s16X[ChOffset+4+8]+s16X[ChOffset+4+24]),s32Hi;\ MLA s32Hi,WIND_4_SUBBANDS_4_2,s16X[ChOffset+4+16],s32Hi;\ - MOV s32DCTY[4],s32Hi;\ - }\ -} + MOV s32DCTY[4],s32Hi; \ + } \ + } #define WINDOW_PARTIAL_4 \ -{\ - WINDOW_ACCU_4_0; WINDOW_ACCU_4_1_7;\ - WINDOW_ACCU_4_2_6; WINDOW_ACCU_4_3_5;\ - WINDOW_ACCU_4_4;\ -} + { \ + WINDOW_ACCU_4_0; \ + WINDOW_ACCU_4_1_7; \ + WINDOW_ACCU_4_2_6; \ + WINDOW_ACCU_4_3_5; \ + WINDOW_ACCU_4_4; \ + } #define WINDOW_PARTIAL_8 \ -{\ - WINDOW_ACCU_8_0; WINDOW_ACCU_8_1_15;\ - WINDOW_ACCU_8_2_14; WINDOW_ACCU_8_3_13;\ - WINDOW_ACCU_8_4_12; WINDOW_ACCU_8_5_11;\ - WINDOW_ACCU_8_6_10; WINDOW_ACCU_8_7_9;\ - WINDOW_ACCU_8_8;\ -} + { \ + WINDOW_ACCU_8_0; \ + WINDOW_ACCU_8_1_15; \ + WINDOW_ACCU_8_2_14; \ + WINDOW_ACCU_8_3_13; \ + WINDOW_ACCU_8_4_12; \ + WINDOW_ACCU_8_5_11; \ + WINDOW_ACCU_8_6_10; \ + WINDOW_ACCU_8_7_9; \ + WINDOW_ACCU_8_8; \ + } #else #if (SBC_IPAQ_OPT == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) -#define WINDOW_ACCU_8_0 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_0_1*(int64_t)(s16X[ChOffset+16]-s16X[ChOffset+64]);\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_0_2*(int64_t)(s16X[ChOffset+32]-s16X[ChOffset+48]);\ - s32DCTY[0]=(int32_t)(s64Temp>>16);\ -} -#define WINDOW_ACCU_8_1_15 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_1_0*(int64_t)s16X[ChOffset+1];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_1_0*(int64_t)s16X[ChOffset+64+15];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_1_1*(int64_t)s16X[ChOffset+16+1];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_1_1*(int64_t)s16X[ChOffset+48+15];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_1_2*(int64_t)s16X[ChOffset+32+1];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_1_2*(int64_t)s16X[ChOffset+32+15];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_1_3*(int64_t)s16X[ChOffset+48+1];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_1_3*(int64_t)s16X[ChOffset+16+15];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_1_4*(int64_t)s16X[ChOffset+64+1];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_1_4*(int64_t)s16X[ChOffset+15];\ - s32DCTY[1]=(int32_t)(s64Temp>>16);\ - s32DCTY[15]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_2_14 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_2_0*(int64_t)s16X[ChOffset+2];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_2_0*(int64_t)s16X[ChOffset+64+14];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_2_1*(int64_t)s16X[ChOffset+16+2];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_2_1*(int64_t)s16X[ChOffset+48+14];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_2_2*(int64_t)s16X[ChOffset+32+2];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_2_2*(int64_t)s16X[ChOffset+32+14];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_2_3*(int64_t)s16X[ChOffset+48+2];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_2_3*(int64_t)s16X[ChOffset+16+14];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_2_4*(int64_t)s16X[ChOffset+64+2];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_2_4*(int64_t)s16X[ChOffset+14];\ - s32DCTY[2]=(int32_t)(s64Temp>>16);\ - s32DCTY[14]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_3_13 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_3_0*(int64_t)s16X[ChOffset+3];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_3_0*(int64_t)s16X[ChOffset+64+13];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_3_1*(int64_t)s16X[ChOffset+16+3];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_3_1*(int64_t)s16X[ChOffset+48+13];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_3_2*(int64_t)s16X[ChOffset+32+3];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_3_2*(int64_t)s16X[ChOffset+32+13];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_3_3*(int64_t)s16X[ChOffset+48+3];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_3_3*(int64_t)s16X[ChOffset+16+13];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_3_4*(int64_t)s16X[ChOffset+64+3];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_3_4*(int64_t)s16X[ChOffset+13];\ - s32DCTY[3]=(int32_t)(s64Temp>>16);\ - s32DCTY[13]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_4_12 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_4_0*(int64_t)s16X[ChOffset+4];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_4_0*(int64_t)s16X[ChOffset+64+12];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_4_1*(int64_t)s16X[ChOffset+16+4];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_4_1*(int64_t)s16X[ChOffset+48+12];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_4_2*(int64_t)s16X[ChOffset+32+4];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_4_2*(int64_t)s16X[ChOffset+32+12];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_4_3*(int64_t)s16X[ChOffset+48+4];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_4_3*(int64_t)s16X[ChOffset+16+12];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_4_4*(int64_t)s16X[ChOffset+64+4];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_4_4*(int64_t)s16X[ChOffset+12];\ - s32DCTY[4]=(int32_t)(s64Temp>>16);\ - s32DCTY[12]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_5_11 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_5_0*(int64_t)s16X[ChOffset+5];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_5_0*(int64_t)s16X[ChOffset+64+11];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_5_1*(int64_t)s16X[ChOffset+16+5];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_5_1*(int64_t)s16X[ChOffset+48+11];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_5_2*(int64_t)s16X[ChOffset+32+5];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_5_2*(int64_t)s16X[ChOffset+32+11];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_5_3*(int64_t)s16X[ChOffset+48+5];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_5_3*(int64_t)s16X[ChOffset+16+11];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_5_4*(int64_t)s16X[ChOffset+64+5];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_5_4*(int64_t)s16X[ChOffset+11];\ - s32DCTY[5]=(int32_t)(s64Temp>>16);\ - s32DCTY[11]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_6_10 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_6_0*(int64_t)s16X[ChOffset+6];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_6_0*(int64_t)s16X[ChOffset+64+10];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_6_1*(int64_t)s16X[ChOffset+16+6];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_6_1*(int64_t)s16X[ChOffset+48+10];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_6_2*(int64_t)s16X[ChOffset+32+6];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_6_2*(int64_t)s16X[ChOffset+32+10];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_6_3*(int64_t)s16X[ChOffset+48+6];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_6_3*(int64_t)s16X[ChOffset+16+10];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_6_4*(int64_t)s16X[ChOffset+64+6];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_6_4*(int64_t)s16X[ChOffset+10];\ - s32DCTY[6]=(int32_t)(s64Temp>>16);\ - s32DCTY[10]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_7_9 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_7_0*(int64_t)s16X[ChOffset+7];\ - s64Temp2=(int64_t)WIND_8_SUBBANDS_7_0*(int64_t)s16X[ChOffset+64+9];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_7_1*(int64_t)s16X[ChOffset+16+7];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_7_1*(int64_t)s16X[ChOffset+48+9];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_7_2*(int64_t)s16X[ChOffset+32+7];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_7_2*(int64_t)s16X[ChOffset+32+9];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_7_3*(int64_t)s16X[ChOffset+48+7];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_7_3*(int64_t)s16X[ChOffset+16+9];\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_7_4*(int64_t)s16X[ChOffset+64+7];\ - s64Temp2+=(int64_t)WIND_8_SUBBANDS_7_4*(int64_t)s16X[ChOffset+9];\ - s32DCTY[7]=(int32_t)(s64Temp>>16);\ - s32DCTY[9]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_8_8 \ -{\ - s64Temp=(int64_t)WIND_8_SUBBANDS_8_0*(int64_t)(s16X[ChOffset+8]+s16X[ChOffset+64+8]);\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_8_1*(int64_t)(s16X[ChOffset+16+8]+s16X[ChOffset+48+8]);\ - s64Temp+=(int64_t)WIND_8_SUBBANDS_8_2*(int64_t)s16X[ChOffset+32+8];\ - s32DCTY[8]=(int32_t)(s64Temp>>16);\ -} -#define WINDOW_ACCU_4_0 \ -{\ - s64Temp=(int64_t)WIND_4_SUBBANDS_0_1*(int64_t)(s16X[ChOffset+8]-s16X[ChOffset+32]);\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_0_2*(int64_t)(s16X[ChOffset+16]-s16X[ChOffset+24]);\ - s32DCTY[0]=(int32_t)(s64Temp>>16);\ -} -#define WINDOW_ACCU_4_1_7 \ -{\ - s64Temp=(int64_t)WIND_4_SUBBANDS_1_0*(int64_t)s16X[ChOffset+1];\ - s64Temp2=(int64_t)WIND_4_SUBBANDS_1_0*(int64_t)s16X[ChOffset+32+7];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_1_1*(int64_t)s16X[ChOffset+8+1];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_1_1*(int64_t)s16X[ChOffset+24+7];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_1_2*(int64_t)s16X[ChOffset+16+1];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_1_2*(int64_t)s16X[ChOffset+16+7];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_1_3*(int64_t)s16X[ChOffset+24+1];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_1_3*(int64_t)s16X[ChOffset+8+7];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_1_4*(int64_t)s16X[ChOffset+32+1];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_1_4*(int64_t)s16X[ChOffset+7];\ - s32DCTY[1]=(int32_t)(s64Temp>>16);\ - s32DCTY[7]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_4_2_6 \ -{\ - s64Temp=(int64_t)WIND_4_SUBBANDS_2_0*(int64_t)s16X[ChOffset+2];\ - s64Temp2=(int64_t)WIND_4_SUBBANDS_2_0*(int64_t)s16X[ChOffset+32+6];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_2_1*(int64_t)s16X[ChOffset+8+2];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_2_1*(int64_t)s16X[ChOffset+24+6];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_2_2*(int64_t)s16X[ChOffset+16+2];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_2_2*(int64_t)s16X[ChOffset+16+6];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_2_3*(int64_t)s16X[ChOffset+24+2];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_2_3*(int64_t)s16X[ChOffset+8+6];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_2_4*(int64_t)s16X[ChOffset+32+2];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_2_4*(int64_t)s16X[ChOffset+6];\ - s32DCTY[2]=(int32_t)(s64Temp>>16);\ - s32DCTY[6]=(int32_t)(s64Temp2>>16);\ -} -#define WINDOW_ACCU_4_3_5 \ -{\ - s64Temp=(int64_t)WIND_4_SUBBANDS_3_0*(int64_t)s16X[ChOffset+3];\ - s64Temp2=(int64_t)WIND_4_SUBBANDS_3_0*(int64_t)s16X[ChOffset+32+5];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_3_1*(int64_t)s16X[ChOffset+8+3];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_3_1*(int64_t)s16X[ChOffset+24+5];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_3_2*(int64_t)s16X[ChOffset+16+3];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_3_2*(int64_t)s16X[ChOffset+16+5];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_3_3*(int64_t)s16X[ChOffset+24+3];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_3_3*(int64_t)s16X[ChOffset+8+5];\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_3_4*(int64_t)s16X[ChOffset+32+3];\ - s64Temp2+=(int64_t)WIND_4_SUBBANDS_3_4*(int64_t)s16X[ChOffset+5];\ - s32DCTY[3]=(int32_t)(s64Temp>>16);\ - s32DCTY[5]=(int32_t)(s64Temp2>>16);\ -} +#define WINDOW_ACCU_8_0 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_0_1 * \ + (int64_t)(s16X[ChOffset + 16] - s16X[ChOffset + 64]); \ + s64Temp += (int64_t)WIND_8_SUBBANDS_0_2 * \ + (int64_t)(s16X[ChOffset + 32] - s16X[ChOffset + 48]); \ + s32DCTY[0] = (int32_t)(s64Temp >> 16); \ + } +#define WINDOW_ACCU_8_1_15 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_1_0 * (int64_t)s16X[ChOffset + 1]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_1_0 * (int64_t)s16X[ChOffset + 64 + 15]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_1_1 * (int64_t)s16X[ChOffset + 16 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_1_1 * (int64_t)s16X[ChOffset + 48 + 15]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_1_2 * (int64_t)s16X[ChOffset + 32 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_1_2 * (int64_t)s16X[ChOffset + 32 + 15]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_1_3 * (int64_t)s16X[ChOffset + 48 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_1_3 * (int64_t)s16X[ChOffset + 16 + 15]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_1_4 * (int64_t)s16X[ChOffset + 64 + 1]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_1_4 * (int64_t)s16X[ChOffset + 15]; \ + s32DCTY[1] = (int32_t)(s64Temp >> 16); \ + s32DCTY[15] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_2_14 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_2_0 * (int64_t)s16X[ChOffset + 2]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_2_0 * (int64_t)s16X[ChOffset + 64 + 14]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_2_1 * (int64_t)s16X[ChOffset + 16 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_2_1 * (int64_t)s16X[ChOffset + 48 + 14]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_2_2 * (int64_t)s16X[ChOffset + 32 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_2_2 * (int64_t)s16X[ChOffset + 32 + 14]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_2_3 * (int64_t)s16X[ChOffset + 48 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_2_3 * (int64_t)s16X[ChOffset + 16 + 14]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_2_4 * (int64_t)s16X[ChOffset + 64 + 2]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_2_4 * (int64_t)s16X[ChOffset + 14]; \ + s32DCTY[2] = (int32_t)(s64Temp >> 16); \ + s32DCTY[14] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_3_13 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_3_0 * (int64_t)s16X[ChOffset + 3]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_3_0 * (int64_t)s16X[ChOffset + 64 + 13]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_3_1 * (int64_t)s16X[ChOffset + 16 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_3_1 * (int64_t)s16X[ChOffset + 48 + 13]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_3_2 * (int64_t)s16X[ChOffset + 32 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_3_2 * (int64_t)s16X[ChOffset + 32 + 13]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_3_3 * (int64_t)s16X[ChOffset + 48 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_3_3 * (int64_t)s16X[ChOffset + 16 + 13]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_3_4 * (int64_t)s16X[ChOffset + 64 + 3]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_3_4 * (int64_t)s16X[ChOffset + 13]; \ + s32DCTY[3] = (int32_t)(s64Temp >> 16); \ + s32DCTY[13] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_4_12 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_4_0 * (int64_t)s16X[ChOffset + 4]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_4_0 * (int64_t)s16X[ChOffset + 64 + 12]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_4_1 * (int64_t)s16X[ChOffset + 16 + 4]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_4_1 * (int64_t)s16X[ChOffset + 48 + 12]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_4_2 * (int64_t)s16X[ChOffset + 32 + 4]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_4_2 * (int64_t)s16X[ChOffset + 32 + 12]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_4_3 * (int64_t)s16X[ChOffset + 48 + 4]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_4_3 * (int64_t)s16X[ChOffset + 16 + 12]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_4_4 * (int64_t)s16X[ChOffset + 64 + 4]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_4_4 * (int64_t)s16X[ChOffset + 12]; \ + s32DCTY[4] = (int32_t)(s64Temp >> 16); \ + s32DCTY[12] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_5_11 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_5_0 * (int64_t)s16X[ChOffset + 5]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_5_0 * (int64_t)s16X[ChOffset + 64 + 11]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_5_1 * (int64_t)s16X[ChOffset + 16 + 5]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_5_1 * (int64_t)s16X[ChOffset + 48 + 11]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_5_2 * (int64_t)s16X[ChOffset + 32 + 5]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_5_2 * (int64_t)s16X[ChOffset + 32 + 11]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_5_3 * (int64_t)s16X[ChOffset + 48 + 5]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_5_3 * (int64_t)s16X[ChOffset + 16 + 11]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_5_4 * (int64_t)s16X[ChOffset + 64 + 5]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_5_4 * (int64_t)s16X[ChOffset + 11]; \ + s32DCTY[5] = (int32_t)(s64Temp >> 16); \ + s32DCTY[11] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_6_10 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_6_0 * (int64_t)s16X[ChOffset + 6]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_6_0 * (int64_t)s16X[ChOffset + 64 + 10]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_6_1 * (int64_t)s16X[ChOffset + 16 + 6]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_6_1 * (int64_t)s16X[ChOffset + 48 + 10]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_6_2 * (int64_t)s16X[ChOffset + 32 + 6]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_6_2 * (int64_t)s16X[ChOffset + 32 + 10]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_6_3 * (int64_t)s16X[ChOffset + 48 + 6]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_6_3 * (int64_t)s16X[ChOffset + 16 + 10]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_6_4 * (int64_t)s16X[ChOffset + 64 + 6]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_6_4 * (int64_t)s16X[ChOffset + 10]; \ + s32DCTY[6] = (int32_t)(s64Temp >> 16); \ + s32DCTY[10] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_7_9 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_7_0 * (int64_t)s16X[ChOffset + 7]; \ + s64Temp2 = \ + (int64_t)WIND_8_SUBBANDS_7_0 * (int64_t)s16X[ChOffset + 64 + 9]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_7_1 * (int64_t)s16X[ChOffset + 16 + 7]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_7_1 * (int64_t)s16X[ChOffset + 48 + 9]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_7_2 * (int64_t)s16X[ChOffset + 32 + 7]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_7_2 * (int64_t)s16X[ChOffset + 32 + 9]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_7_3 * (int64_t)s16X[ChOffset + 48 + 7]; \ + s64Temp2 += \ + (int64_t)WIND_8_SUBBANDS_7_3 * (int64_t)s16X[ChOffset + 16 + 9]; \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_7_4 * (int64_t)s16X[ChOffset + 64 + 7]; \ + s64Temp2 += (int64_t)WIND_8_SUBBANDS_7_4 * (int64_t)s16X[ChOffset + 9]; \ + s32DCTY[7] = (int32_t)(s64Temp >> 16); \ + s32DCTY[9] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_8_8 \ + { \ + s64Temp = (int64_t)WIND_8_SUBBANDS_8_0 * \ + (int64_t)(s16X[ChOffset + 8] + s16X[ChOffset + 64 + 8]); \ + s64Temp += (int64_t)WIND_8_SUBBANDS_8_1 * \ + (int64_t)(s16X[ChOffset + 16 + 8] + s16X[ChOffset + 48 + 8]); \ + s64Temp += \ + (int64_t)WIND_8_SUBBANDS_8_2 * (int64_t)s16X[ChOffset + 32 + 8]; \ + s32DCTY[8] = (int32_t)(s64Temp >> 16); \ + } +#define WINDOW_ACCU_4_0 \ + { \ + s64Temp = (int64_t)WIND_4_SUBBANDS_0_1 * \ + (int64_t)(s16X[ChOffset + 8] - s16X[ChOffset + 32]); \ + s64Temp += (int64_t)WIND_4_SUBBANDS_0_2 * \ + (int64_t)(s16X[ChOffset + 16] - s16X[ChOffset + 24]); \ + s32DCTY[0] = (int32_t)(s64Temp >> 16); \ + } +#define WINDOW_ACCU_4_1_7 \ + { \ + s64Temp = (int64_t)WIND_4_SUBBANDS_1_0 * (int64_t)s16X[ChOffset + 1]; \ + s64Temp2 = \ + (int64_t)WIND_4_SUBBANDS_1_0 * (int64_t)s16X[ChOffset + 32 + 7]; \ + s64Temp += (int64_t)WIND_4_SUBBANDS_1_1 * (int64_t)s16X[ChOffset + 8 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_1_1 * (int64_t)s16X[ChOffset + 24 + 7]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_1_2 * (int64_t)s16X[ChOffset + 16 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_1_2 * (int64_t)s16X[ChOffset + 16 + 7]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_1_3 * (int64_t)s16X[ChOffset + 24 + 1]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_1_3 * (int64_t)s16X[ChOffset + 8 + 7]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_1_4 * (int64_t)s16X[ChOffset + 32 + 1]; \ + s64Temp2 += (int64_t)WIND_4_SUBBANDS_1_4 * (int64_t)s16X[ChOffset + 7]; \ + s32DCTY[1] = (int32_t)(s64Temp >> 16); \ + s32DCTY[7] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_4_2_6 \ + { \ + s64Temp = (int64_t)WIND_4_SUBBANDS_2_0 * (int64_t)s16X[ChOffset + 2]; \ + s64Temp2 = \ + (int64_t)WIND_4_SUBBANDS_2_0 * (int64_t)s16X[ChOffset + 32 + 6]; \ + s64Temp += (int64_t)WIND_4_SUBBANDS_2_1 * (int64_t)s16X[ChOffset + 8 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_2_1 * (int64_t)s16X[ChOffset + 24 + 6]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_2_2 * (int64_t)s16X[ChOffset + 16 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_2_2 * (int64_t)s16X[ChOffset + 16 + 6]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_2_3 * (int64_t)s16X[ChOffset + 24 + 2]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_2_3 * (int64_t)s16X[ChOffset + 8 + 6]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_2_4 * (int64_t)s16X[ChOffset + 32 + 2]; \ + s64Temp2 += (int64_t)WIND_4_SUBBANDS_2_4 * (int64_t)s16X[ChOffset + 6]; \ + s32DCTY[2] = (int32_t)(s64Temp >> 16); \ + s32DCTY[6] = (int32_t)(s64Temp2 >> 16); \ + } +#define WINDOW_ACCU_4_3_5 \ + { \ + s64Temp = (int64_t)WIND_4_SUBBANDS_3_0 * (int64_t)s16X[ChOffset + 3]; \ + s64Temp2 = \ + (int64_t)WIND_4_SUBBANDS_3_0 * (int64_t)s16X[ChOffset + 32 + 5]; \ + s64Temp += (int64_t)WIND_4_SUBBANDS_3_1 * (int64_t)s16X[ChOffset + 8 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_3_1 * (int64_t)s16X[ChOffset + 24 + 5]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_3_2 * (int64_t)s16X[ChOffset + 16 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_3_2 * (int64_t)s16X[ChOffset + 16 + 5]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_3_3 * (int64_t)s16X[ChOffset + 24 + 3]; \ + s64Temp2 += \ + (int64_t)WIND_4_SUBBANDS_3_3 * (int64_t)s16X[ChOffset + 8 + 5]; \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_3_4 * (int64_t)s16X[ChOffset + 32 + 3]; \ + s64Temp2 += (int64_t)WIND_4_SUBBANDS_3_4 * (int64_t)s16X[ChOffset + 5]; \ + s32DCTY[3] = (int32_t)(s64Temp >> 16); \ + s32DCTY[5] = (int32_t)(s64Temp2 >> 16); \ + } -#define WINDOW_ACCU_4_4 \ -{\ - s64Temp=(int64_t)WIND_4_SUBBANDS_4_0*(int64_t)(s16X[ChOffset+4]+s16X[ChOffset+4+32]);\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_4_1*(int64_t)(s16X[ChOffset+4+8]+s16X[ChOffset+4+24]);\ - s64Temp+=(int64_t)WIND_4_SUBBANDS_4_2*(int64_t)s16X[ChOffset+4+16];\ - s32DCTY[4]=(int32_t)(s64Temp>>16);\ -} +#define WINDOW_ACCU_4_4 \ + { \ + s64Temp = (int64_t)WIND_4_SUBBANDS_4_0 * \ + (int64_t)(s16X[ChOffset + 4] + s16X[ChOffset + 4 + 32]); \ + s64Temp += (int64_t)WIND_4_SUBBANDS_4_1 * \ + (int64_t)(s16X[ChOffset + 4 + 8] + s16X[ChOffset + 4 + 24]); \ + s64Temp += \ + (int64_t)WIND_4_SUBBANDS_4_2 * (int64_t)s16X[ChOffset + 4 + 16]; \ + s32DCTY[4] = (int32_t)(s64Temp >> 16); \ + } #else /* SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE */ -#define WINDOW_ACCU_8_0 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_0_1*(int32_t)(s16X[ChOffset+16]-s16X[ChOffset+64]);\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_0_2*(int32_t)(s16X[ChOffset+32]-s16X[ChOffset+48]);\ - s32DCTY[0]=(int32_t)s32Temp;\ -} -#define WINDOW_ACCU_8_1_15 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_1_0*(int32_t)s16X[ChOffset+1];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_1_0*(int32_t)s16X[ChOffset+64+15];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_1_1*(int32_t)s16X[ChOffset+16+1];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_1_1*(int32_t)s16X[ChOffset+48+15];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_1_2*(int32_t)s16X[ChOffset+32+1];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_1_2*(int32_t)s16X[ChOffset+32+15];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_1_3*(int32_t)s16X[ChOffset+48+1];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_1_3*(int32_t)s16X[ChOffset+16+15];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_1_4*(int32_t)s16X[ChOffset+64+1];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_1_4*(int32_t)s16X[ChOffset+15];\ - s32DCTY[1]=(int32_t)s32Temp;\ - s32DCTY[15]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_2_14 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_2_0*(int32_t)s16X[ChOffset+2];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_2_0*(int32_t)s16X[ChOffset+64+14];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_2_1*(int32_t)s16X[ChOffset+16+2];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_2_1*(int32_t)s16X[ChOffset+48+14];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_2_2*(int32_t)s16X[ChOffset+32+2];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_2_2*(int32_t)s16X[ChOffset+32+14];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_2_3*(int32_t)s16X[ChOffset+48+2];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_2_3*(int32_t)s16X[ChOffset+16+14];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_2_4*(int32_t)s16X[ChOffset+64+2];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_2_4*(int32_t)s16X[ChOffset+14];\ - s32DCTY[2]=(int32_t)s32Temp;\ - s32DCTY[14]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_3_13 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_3_0*(int32_t)s16X[ChOffset+3];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_3_0*(int32_t)s16X[ChOffset+64+13];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_3_1*(int32_t)s16X[ChOffset+16+3];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_3_1*(int32_t)s16X[ChOffset+48+13];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_3_2*(int32_t)s16X[ChOffset+32+3];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_3_2*(int32_t)s16X[ChOffset+32+13];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_3_3*(int32_t)s16X[ChOffset+48+3];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_3_3*(int32_t)s16X[ChOffset+16+13];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_3_4*(int32_t)s16X[ChOffset+64+3];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_3_4*(int32_t)s16X[ChOffset+13];\ - s32DCTY[3]=(int32_t)s32Temp;\ - s32DCTY[13]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_4_12 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_4_0*(int32_t)s16X[ChOffset+4];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_4_0*(int32_t)s16X[ChOffset+64+12];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_4_1*(int32_t)s16X[ChOffset+16+4];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_4_1*(int32_t)s16X[ChOffset+48+12];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_4_2*(int32_t)s16X[ChOffset+32+4];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_4_2*(int32_t)s16X[ChOffset+32+12];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_4_3*(int32_t)s16X[ChOffset+48+4];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_4_3*(int32_t)s16X[ChOffset+16+12];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_4_4*(int32_t)s16X[ChOffset+64+4];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_4_4*(int32_t)s16X[ChOffset+12];\ - s32DCTY[4]=(int32_t)s32Temp;\ - s32DCTY[12]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_5_11 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_5_0*(int32_t)s16X[ChOffset+5];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_5_0*(int32_t)s16X[ChOffset+64+11];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_5_1*(int32_t)s16X[ChOffset+16+5];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_5_1*(int32_t)s16X[ChOffset+48+11];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_5_2*(int32_t)s16X[ChOffset+32+5];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_5_2*(int32_t)s16X[ChOffset+32+11];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_5_3*(int32_t)s16X[ChOffset+48+5];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_5_3*(int32_t)s16X[ChOffset+16+11];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_5_4*(int32_t)s16X[ChOffset+64+5];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_5_4*(int32_t)s16X[ChOffset+11];\ - s32DCTY[5]=(int32_t)s32Temp;\ - s32DCTY[11]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_6_10 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_6_0*(int32_t)s16X[ChOffset+6];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_6_0*(int32_t)s16X[ChOffset+64+10];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_6_1*(int32_t)s16X[ChOffset+16+6];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_6_1*(int32_t)s16X[ChOffset+48+10];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_6_2*(int32_t)s16X[ChOffset+32+6];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_6_2*(int32_t)s16X[ChOffset+32+10];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_6_3*(int32_t)s16X[ChOffset+48+6];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_6_3*(int32_t)s16X[ChOffset+16+10];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_6_4*(int32_t)s16X[ChOffset+64+6];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_6_4*(int32_t)s16X[ChOffset+10];\ - s32DCTY[6]=(int32_t)s32Temp;\ - s32DCTY[10]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_7_9 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_7_0*(int32_t)s16X[ChOffset+7];\ - s32Temp2=(int32_t)WIND_8_SUBBANDS_7_0*(int32_t)s16X[ChOffset+64+9];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_7_1*(int32_t)s16X[ChOffset+16+7];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_7_1*(int32_t)s16X[ChOffset+48+9];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_7_2*(int32_t)s16X[ChOffset+32+7];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_7_2*(int32_t)s16X[ChOffset+32+9];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_7_3*(int32_t)s16X[ChOffset+48+7];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_7_3*(int32_t)s16X[ChOffset+16+9];\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_7_4*(int32_t)s16X[ChOffset+64+7];\ - s32Temp2+=(int32_t)WIND_8_SUBBANDS_7_4*(int32_t)s16X[ChOffset+9];\ - s32DCTY[7]=(int32_t)s32Temp;\ - s32DCTY[9]=(int32_t)s32Temp2;\ -} -#define WINDOW_ACCU_8_8 \ -{\ - s32Temp=(int32_t)WIND_8_SUBBANDS_8_0*(int32_t)(s16X[ChOffset+8]+s16X[ChOffset+64+8]);\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_8_1*(int32_t)(s16X[ChOffset+16+8]+s16X[ChOffset+48+8]);\ - s32Temp+=(int32_t)WIND_8_SUBBANDS_8_2*(int32_t)s16X[ChOffset+32+8];\ - s32DCTY[8]=(int32_t)s32Temp;\ -} -#define WINDOW_ACCU_4_0 \ -{\ - s32Temp=(int32_t)WIND_4_SUBBANDS_0_1*(int32_t)(s16X[ChOffset+8]-s16X[ChOffset+32]);\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_0_2*(int32_t)(s16X[ChOffset+16]-s16X[ChOffset+24]);\ - s32DCTY[0]=(int32_t)(s32Temp);\ -} -#define WINDOW_ACCU_4_1_7 \ -{\ - s32Temp=(int32_t)WIND_4_SUBBANDS_1_0*(int32_t)s16X[ChOffset+1];\ - s32Temp2=(int32_t)WIND_4_SUBBANDS_1_0*(int32_t)s16X[ChOffset+32+7];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_1_1*(int32_t)s16X[ChOffset+8+1];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_1_1*(int32_t)s16X[ChOffset+24+7];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_1_2*(int32_t)s16X[ChOffset+16+1];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_1_2*(int32_t)s16X[ChOffset+16+7];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_1_3*(int32_t)s16X[ChOffset+24+1];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_1_3*(int32_t)s16X[ChOffset+8+7];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_1_4*(int32_t)s16X[ChOffset+32+1];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_1_4*(int32_t)s16X[ChOffset+7];\ - s32DCTY[1]=(int32_t)(s32Temp);\ - s32DCTY[7]=(int32_t)(s32Temp2);\ -} -#define WINDOW_ACCU_4_2_6 \ -{\ - s32Temp=(int32_t)WIND_4_SUBBANDS_2_0*(int32_t)s16X[ChOffset+2];\ - s32Temp2=(int32_t)WIND_4_SUBBANDS_2_0*(int32_t)s16X[ChOffset+32+6];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_2_1*(int32_t)s16X[ChOffset+8+2];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_2_1*(int32_t)s16X[ChOffset+24+6];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_2_2*(int32_t)s16X[ChOffset+16+2];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_2_2*(int32_t)s16X[ChOffset+16+6];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_2_3*(int32_t)s16X[ChOffset+24+2];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_2_3*(int32_t)s16X[ChOffset+8+6];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_2_4*(int32_t)s16X[ChOffset+32+2];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_2_4*(int32_t)s16X[ChOffset+6];\ - s32DCTY[2]=(int32_t)(s32Temp);\ - s32DCTY[6]=(int32_t)(s32Temp2);\ -} -#define WINDOW_ACCU_4_3_5 \ -{\ - s32Temp=(int32_t)WIND_4_SUBBANDS_3_0*(int32_t)s16X[ChOffset+3];\ - s32Temp2=(int32_t)WIND_4_SUBBANDS_3_0*(int32_t)s16X[ChOffset+32+5];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_3_1*(int32_t)s16X[ChOffset+8+3];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_3_1*(int32_t)s16X[ChOffset+24+5];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_3_2*(int32_t)s16X[ChOffset+16+3];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_3_2*(int32_t)s16X[ChOffset+16+5];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_3_3*(int32_t)s16X[ChOffset+24+3];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_3_3*(int32_t)s16X[ChOffset+8+5];\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_3_4*(int32_t)s16X[ChOffset+32+3];\ - s32Temp2+=(int32_t)WIND_4_SUBBANDS_3_4*(int32_t)s16X[ChOffset+5];\ - s32DCTY[3]=(int32_t)(s32Temp);\ - s32DCTY[5]=(int32_t)(s32Temp2);\ -} +#define WINDOW_ACCU_8_0 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_0_1 * \ + (int32_t)(s16X[ChOffset + 16] - s16X[ChOffset + 64]); \ + s32Temp += (int32_t)WIND_8_SUBBANDS_0_2 * \ + (int32_t)(s16X[ChOffset + 32] - s16X[ChOffset + 48]); \ + s32DCTY[0] = (int32_t)s32Temp; \ + } +#define WINDOW_ACCU_8_1_15 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_1_0 * (int32_t)s16X[ChOffset + 1]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_1_0 * (int32_t)s16X[ChOffset + 64 + 15]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_1_1 * (int32_t)s16X[ChOffset + 16 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_1_1 * (int32_t)s16X[ChOffset + 48 + 15]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_1_2 * (int32_t)s16X[ChOffset + 32 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_1_2 * (int32_t)s16X[ChOffset + 32 + 15]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_1_3 * (int32_t)s16X[ChOffset + 48 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_1_3 * (int32_t)s16X[ChOffset + 16 + 15]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_1_4 * (int32_t)s16X[ChOffset + 64 + 1]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_1_4 * (int32_t)s16X[ChOffset + 15]; \ + s32DCTY[1] = (int32_t)s32Temp; \ + s32DCTY[15] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_2_14 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_2_0 * (int32_t)s16X[ChOffset + 2]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_2_0 * (int32_t)s16X[ChOffset + 64 + 14]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_2_1 * (int32_t)s16X[ChOffset + 16 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_2_1 * (int32_t)s16X[ChOffset + 48 + 14]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_2_2 * (int32_t)s16X[ChOffset + 32 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_2_2 * (int32_t)s16X[ChOffset + 32 + 14]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_2_3 * (int32_t)s16X[ChOffset + 48 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_2_3 * (int32_t)s16X[ChOffset + 16 + 14]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_2_4 * (int32_t)s16X[ChOffset + 64 + 2]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_2_4 * (int32_t)s16X[ChOffset + 14]; \ + s32DCTY[2] = (int32_t)s32Temp; \ + s32DCTY[14] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_3_13 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_3_0 * (int32_t)s16X[ChOffset + 3]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_3_0 * (int32_t)s16X[ChOffset + 64 + 13]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_3_1 * (int32_t)s16X[ChOffset + 16 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_3_1 * (int32_t)s16X[ChOffset + 48 + 13]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_3_2 * (int32_t)s16X[ChOffset + 32 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_3_2 * (int32_t)s16X[ChOffset + 32 + 13]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_3_3 * (int32_t)s16X[ChOffset + 48 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_3_3 * (int32_t)s16X[ChOffset + 16 + 13]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_3_4 * (int32_t)s16X[ChOffset + 64 + 3]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_3_4 * (int32_t)s16X[ChOffset + 13]; \ + s32DCTY[3] = (int32_t)s32Temp; \ + s32DCTY[13] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_4_12 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_4_0 * (int32_t)s16X[ChOffset + 4]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_4_0 * (int32_t)s16X[ChOffset + 64 + 12]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_4_1 * (int32_t)s16X[ChOffset + 16 + 4]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_4_1 * (int32_t)s16X[ChOffset + 48 + 12]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_4_2 * (int32_t)s16X[ChOffset + 32 + 4]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_4_2 * (int32_t)s16X[ChOffset + 32 + 12]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_4_3 * (int32_t)s16X[ChOffset + 48 + 4]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_4_3 * (int32_t)s16X[ChOffset + 16 + 12]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_4_4 * (int32_t)s16X[ChOffset + 64 + 4]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_4_4 * (int32_t)s16X[ChOffset + 12]; \ + s32DCTY[4] = (int32_t)s32Temp; \ + s32DCTY[12] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_5_11 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_5_0 * (int32_t)s16X[ChOffset + 5]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_5_0 * (int32_t)s16X[ChOffset + 64 + 11]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_5_1 * (int32_t)s16X[ChOffset + 16 + 5]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_5_1 * (int32_t)s16X[ChOffset + 48 + 11]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_5_2 * (int32_t)s16X[ChOffset + 32 + 5]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_5_2 * (int32_t)s16X[ChOffset + 32 + 11]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_5_3 * (int32_t)s16X[ChOffset + 48 + 5]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_5_3 * (int32_t)s16X[ChOffset + 16 + 11]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_5_4 * (int32_t)s16X[ChOffset + 64 + 5]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_5_4 * (int32_t)s16X[ChOffset + 11]; \ + s32DCTY[5] = (int32_t)s32Temp; \ + s32DCTY[11] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_6_10 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_6_0 * (int32_t)s16X[ChOffset + 6]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_6_0 * (int32_t)s16X[ChOffset + 64 + 10]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_6_1 * (int32_t)s16X[ChOffset + 16 + 6]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_6_1 * (int32_t)s16X[ChOffset + 48 + 10]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_6_2 * (int32_t)s16X[ChOffset + 32 + 6]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_6_2 * (int32_t)s16X[ChOffset + 32 + 10]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_6_3 * (int32_t)s16X[ChOffset + 48 + 6]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_6_3 * (int32_t)s16X[ChOffset + 16 + 10]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_6_4 * (int32_t)s16X[ChOffset + 64 + 6]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_6_4 * (int32_t)s16X[ChOffset + 10]; \ + s32DCTY[6] = (int32_t)s32Temp; \ + s32DCTY[10] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_7_9 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_7_0 * (int32_t)s16X[ChOffset + 7]; \ + s32Temp2 = \ + (int32_t)WIND_8_SUBBANDS_7_0 * (int32_t)s16X[ChOffset + 64 + 9]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_7_1 * (int32_t)s16X[ChOffset + 16 + 7]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_7_1 * (int32_t)s16X[ChOffset + 48 + 9]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_7_2 * (int32_t)s16X[ChOffset + 32 + 7]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_7_2 * (int32_t)s16X[ChOffset + 32 + 9]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_7_3 * (int32_t)s16X[ChOffset + 48 + 7]; \ + s32Temp2 += \ + (int32_t)WIND_8_SUBBANDS_7_3 * (int32_t)s16X[ChOffset + 16 + 9]; \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_7_4 * (int32_t)s16X[ChOffset + 64 + 7]; \ + s32Temp2 += (int32_t)WIND_8_SUBBANDS_7_4 * (int32_t)s16X[ChOffset + 9]; \ + s32DCTY[7] = (int32_t)s32Temp; \ + s32DCTY[9] = (int32_t)s32Temp2; \ + } +#define WINDOW_ACCU_8_8 \ + { \ + s32Temp = (int32_t)WIND_8_SUBBANDS_8_0 * \ + (int32_t)(s16X[ChOffset + 8] + s16X[ChOffset + 64 + 8]); \ + s32Temp += (int32_t)WIND_8_SUBBANDS_8_1 * \ + (int32_t)(s16X[ChOffset + 16 + 8] + s16X[ChOffset + 48 + 8]); \ + s32Temp += \ + (int32_t)WIND_8_SUBBANDS_8_2 * (int32_t)s16X[ChOffset + 32 + 8]; \ + s32DCTY[8] = (int32_t)s32Temp; \ + } +#define WINDOW_ACCU_4_0 \ + { \ + s32Temp = (int32_t)WIND_4_SUBBANDS_0_1 * \ + (int32_t)(s16X[ChOffset + 8] - s16X[ChOffset + 32]); \ + s32Temp += (int32_t)WIND_4_SUBBANDS_0_2 * \ + (int32_t)(s16X[ChOffset + 16] - s16X[ChOffset + 24]); \ + s32DCTY[0] = (int32_t)(s32Temp); \ + } +#define WINDOW_ACCU_4_1_7 \ + { \ + s32Temp = (int32_t)WIND_4_SUBBANDS_1_0 * (int32_t)s16X[ChOffset + 1]; \ + s32Temp2 = \ + (int32_t)WIND_4_SUBBANDS_1_0 * (int32_t)s16X[ChOffset + 32 + 7]; \ + s32Temp += (int32_t)WIND_4_SUBBANDS_1_1 * (int32_t)s16X[ChOffset + 8 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_1_1 * (int32_t)s16X[ChOffset + 24 + 7]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_1_2 * (int32_t)s16X[ChOffset + 16 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_1_2 * (int32_t)s16X[ChOffset + 16 + 7]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_1_3 * (int32_t)s16X[ChOffset + 24 + 1]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_1_3 * (int32_t)s16X[ChOffset + 8 + 7]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_1_4 * (int32_t)s16X[ChOffset + 32 + 1]; \ + s32Temp2 += (int32_t)WIND_4_SUBBANDS_1_4 * (int32_t)s16X[ChOffset + 7]; \ + s32DCTY[1] = (int32_t)(s32Temp); \ + s32DCTY[7] = (int32_t)(s32Temp2); \ + } +#define WINDOW_ACCU_4_2_6 \ + { \ + s32Temp = (int32_t)WIND_4_SUBBANDS_2_0 * (int32_t)s16X[ChOffset + 2]; \ + s32Temp2 = \ + (int32_t)WIND_4_SUBBANDS_2_0 * (int32_t)s16X[ChOffset + 32 + 6]; \ + s32Temp += (int32_t)WIND_4_SUBBANDS_2_1 * (int32_t)s16X[ChOffset + 8 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_2_1 * (int32_t)s16X[ChOffset + 24 + 6]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_2_2 * (int32_t)s16X[ChOffset + 16 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_2_2 * (int32_t)s16X[ChOffset + 16 + 6]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_2_3 * (int32_t)s16X[ChOffset + 24 + 2]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_2_3 * (int32_t)s16X[ChOffset + 8 + 6]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_2_4 * (int32_t)s16X[ChOffset + 32 + 2]; \ + s32Temp2 += (int32_t)WIND_4_SUBBANDS_2_4 * (int32_t)s16X[ChOffset + 6]; \ + s32DCTY[2] = (int32_t)(s32Temp); \ + s32DCTY[6] = (int32_t)(s32Temp2); \ + } +#define WINDOW_ACCU_4_3_5 \ + { \ + s32Temp = (int32_t)WIND_4_SUBBANDS_3_0 * (int32_t)s16X[ChOffset + 3]; \ + s32Temp2 = \ + (int32_t)WIND_4_SUBBANDS_3_0 * (int32_t)s16X[ChOffset + 32 + 5]; \ + s32Temp += (int32_t)WIND_4_SUBBANDS_3_1 * (int32_t)s16X[ChOffset + 8 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_3_1 * (int32_t)s16X[ChOffset + 24 + 5]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_3_2 * (int32_t)s16X[ChOffset + 16 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_3_2 * (int32_t)s16X[ChOffset + 16 + 5]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_3_3 * (int32_t)s16X[ChOffset + 24 + 3]; \ + s32Temp2 += \ + (int32_t)WIND_4_SUBBANDS_3_3 * (int32_t)s16X[ChOffset + 8 + 5]; \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_3_4 * (int32_t)s16X[ChOffset + 32 + 3]; \ + s32Temp2 += (int32_t)WIND_4_SUBBANDS_3_4 * (int32_t)s16X[ChOffset + 5]; \ + s32DCTY[3] = (int32_t)(s32Temp); \ + s32DCTY[5] = (int32_t)(s32Temp2); \ + } -#define WINDOW_ACCU_4_4 \ -{\ - s32Temp=(int32_t)WIND_4_SUBBANDS_4_0*(int32_t)(s16X[ChOffset+4]+s16X[ChOffset+4+32]);\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_4_1*(int32_t)(s16X[ChOffset+4+8]+s16X[ChOffset+4+24]);\ - s32Temp+=(int32_t)WIND_4_SUBBANDS_4_2*(int32_t)s16X[ChOffset+4+16];\ - s32DCTY[4]=(int32_t)(s32Temp);\ -} +#define WINDOW_ACCU_4_4 \ + { \ + s32Temp = (int32_t)WIND_4_SUBBANDS_4_0 * \ + (int32_t)(s16X[ChOffset + 4] + s16X[ChOffset + 4 + 32]); \ + s32Temp += (int32_t)WIND_4_SUBBANDS_4_1 * \ + (int32_t)(s16X[ChOffset + 4 + 8] + s16X[ChOffset + 4 + 24]); \ + s32Temp += \ + (int32_t)WIND_4_SUBBANDS_4_2 * (int32_t)s16X[ChOffset + 4 + 16]; \ + s32DCTY[4] = (int32_t)(s32Temp); \ + } #endif #define WINDOW_PARTIAL_4 \ -{\ - WINDOW_ACCU_4_0; WINDOW_ACCU_4_1_7;\ - WINDOW_ACCU_4_2_6; WINDOW_ACCU_4_3_5;\ - WINDOW_ACCU_4_4;\ -} + { \ + WINDOW_ACCU_4_0; \ + WINDOW_ACCU_4_1_7; \ + WINDOW_ACCU_4_2_6; \ + WINDOW_ACCU_4_3_5; \ + WINDOW_ACCU_4_4; \ + } #define WINDOW_PARTIAL_8 \ -{\ - WINDOW_ACCU_8_0; WINDOW_ACCU_8_1_15;\ - WINDOW_ACCU_8_2_14; WINDOW_ACCU_8_3_13;\ - WINDOW_ACCU_8_4_12; WINDOW_ACCU_8_5_11;\ - WINDOW_ACCU_8_6_10; WINDOW_ACCU_8_7_9;\ - WINDOW_ACCU_8_8;\ -} + { \ + WINDOW_ACCU_8_0; \ + WINDOW_ACCU_8_1_15; \ + WINDOW_ACCU_8_2_14; \ + WINDOW_ACCU_8_3_13; \ + WINDOW_ACCU_8_4_12; \ + WINDOW_ACCU_8_5_11; \ + WINDOW_ACCU_8_6_10; \ + WINDOW_ACCU_8_7_9; \ + WINDOW_ACCU_8_8; \ + } #else #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) -#define WINDOW_ACCU_4(i) \ -{\ - s64Temp=((int64_t)gas32CoeffFor4SBs[i] * (int64_t)s16X[ChOffset+i]); \ - s64Temp+=((int64_t)gas32CoeffFor4SBs[(i+8)] * (int64_t)s16X[ChOffset+i+8]); \ - s64Temp+=((int64_t)gas32CoeffFor4SBs[(i+16)] * (int64_t)s16X[ChOffset+i+16]); \ - s64Temp+=((int64_t)gas32CoeffFor4SBs[(i+24)] * (int64_t)s16X[ChOffset+i+24]); \ - s64Temp+=((int64_t)gas32CoeffFor4SBs[(i+32)] * (int64_t)s16X[ChOffset+i+32]); \ - s32DCTY[i]=(int32_t)(s64Temp>>16);\ - /*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/\ -} +#define WINDOW_ACCU_4(i) \ + { \ + s64Temp = ((int64_t)gas32CoeffFor4SBs[i] * (int64_t)s16X[ChOffset + i]); \ + s64Temp += ((int64_t)gas32CoeffFor4SBs[(i + 8)] * \ + (int64_t)s16X[ChOffset + i + 8]); \ + s64Temp += ((int64_t)gas32CoeffFor4SBs[(i + 16)] * \ + (int64_t)s16X[ChOffset + i + 16]); \ + s64Temp += ((int64_t)gas32CoeffFor4SBs[(i + 24)] * \ + (int64_t)s16X[ChOffset + i + 24]); \ + s64Temp += ((int64_t)gas32CoeffFor4SBs[(i + 32)] * \ + (int64_t)s16X[ChOffset + i + 32]); \ + s32DCTY[i] = (int32_t)(s64Temp >> 16); \ + /*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/ \ + } #else -#define WINDOW_ACCU_4(i) \ -{\ - s32DCTY[i]=(gas32CoeffFor4SBs[i * 2] * s16X[ChOffset+i]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[(i * 2) + 1]) * s16X[ChOffset+i]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor4SBs[(i+8) * 2] * s16X[ChOffset+i+8]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i+8) * 2) + 1]) * s16X[ChOffset+i+8]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor4SBs[(i+16) * 2] * s16X[ChOffset+i+16]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i+16) * 2) + 1]) * s16X[ChOffset+i+16]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor4SBs[(i+24) * 2] * s16X[ChOffset+i+24]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i+24) * 2) + 1]) * s16X[ChOffset+i+24]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor4SBs[(i+32) * 2] * s16X[ChOffset+i+32]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i+32) * 2) + 1]) * s16X[ChOffset+i+32]) >> 16); \ -} +#define WINDOW_ACCU_4(i) \ + { \ + s32DCTY[i] = (gas32CoeffFor4SBs[i * 2] * s16X[ChOffset + i]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[(i * 2) + 1]) * \ + s16X[ChOffset + i]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor4SBs[(i + 8) * 2] * s16X[ChOffset + i + 8]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i + 8) * 2) + 1]) * \ + s16X[ChOffset + i + 8]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor4SBs[(i + 16) * 2] * s16X[ChOffset + i + 16]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i + 16) * 2) + 1]) * \ + s16X[ChOffset + i + 16]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor4SBs[(i + 24) * 2] * s16X[ChOffset + i + 24]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i + 24) * 2) + 1]) * \ + s16X[ChOffset + i + 24]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor4SBs[(i + 32) * 2] * s16X[ChOffset + i + 32]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor4SBs[((i + 32) * 2) + 1]) * \ + s16X[ChOffset + i + 32]) >> \ + 16); \ + } #endif #define WINDOW_PARTIAL_4 \ -{\ - WINDOW_ACCU_4(0); WINDOW_ACCU_4(1);\ - WINDOW_ACCU_4(2); WINDOW_ACCU_4(3);\ - WINDOW_ACCU_4(4); WINDOW_ACCU_4(5);\ - WINDOW_ACCU_4(6); WINDOW_ACCU_4(7);\ -} + { \ + WINDOW_ACCU_4(0); \ + WINDOW_ACCU_4(1); \ + WINDOW_ACCU_4(2); \ + WINDOW_ACCU_4(3); \ + WINDOW_ACCU_4(4); \ + WINDOW_ACCU_4(5); \ + WINDOW_ACCU_4(6); \ + WINDOW_ACCU_4(7); \ + } #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) -#define WINDOW_ACCU_8(i) \ -{\ - s64Temp = ((((int64_t)gas32CoeffFor8SBs[i] * (int64_t)s16X[ChOffset+i] ))); \ - s64Temp+= ((((int64_t)gas32CoeffFor8SBs[(i+16)] * (int64_t)s16X[ChOffset+i+16]))); \ - s64Temp+= ((((int64_t)gas32CoeffFor8SBs[(i+32)] * (int64_t)s16X[ChOffset+i+32]))); \ - s64Temp+= ((((int64_t)gas32CoeffFor8SBs[(i+48)] * (int64_t)s16X[ChOffset+i+48]))); \ - s64Temp+= ((((int64_t)gas32CoeffFor8SBs[(i+64)] * (int64_t)s16X[ChOffset+i+64]))); \ - /*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], s16X[ChOffset+i]);*/ \ - s32DCTY[i]=(int32_t)(s64Temp>>16);\ -} +#define WINDOW_ACCU_8(i) \ + { \ + s64Temp = \ + ((((int64_t)gas32CoeffFor8SBs[i] * (int64_t)s16X[ChOffset + i]))); \ + s64Temp += ((((int64_t)gas32CoeffFor8SBs[(i + 16)] * \ + (int64_t)s16X[ChOffset + i + 16]))); \ + s64Temp += ((((int64_t)gas32CoeffFor8SBs[(i + 32)] * \ + (int64_t)s16X[ChOffset + i + 32]))); \ + s64Temp += ((((int64_t)gas32CoeffFor8SBs[(i + 48)] * \ + (int64_t)s16X[ChOffset + i + 48]))); \ + s64Temp += ((((int64_t)gas32CoeffFor8SBs[(i + 64)] * \ + (int64_t)s16X[ChOffset + i + 64]))); \ + /*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], \ + * s16X[ChOffset+i]);*/ \ + s32DCTY[i] = (int32_t)(s64Temp >> 16); \ + } #else -#define WINDOW_ACCU_8(i) \ -{\ - s32DCTY[i]=(gas32CoeffFor8SBs[i * 2] * s16X[ChOffset+i]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[(i * 2) + 1]) * s16X[ChOffset+i]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor8SBs[(i+16) * 2] * s16X[ChOffset+i+16]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i+16) * 2) + 1]) * s16X[ChOffset+i+16]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor8SBs[(i+32) * 2] * s16X[ChOffset+i+32]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i+32) * 2) + 1]) * s16X[ChOffset+i+32]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor8SBs[(i+48) * 2] * s16X[ChOffset+i+48]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i+48) * 2) + 1]) * s16X[ChOffset+i+48]) >> 16); \ - s32DCTY[i]+=(gas32CoeffFor8SBs[(i+64) * 2] * s16X[ChOffset+i+64]) \ - + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i+64) * 2) + 1]) * s16X[ChOffset+i+64]) >> 16); \ - /*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/\ - /*s32DCTY[i]=(int32_t)(s64Temp>>16);*/\ -} +#define WINDOW_ACCU_8(i) \ + { \ + s32DCTY[i] = (gas32CoeffFor8SBs[i * 2] * s16X[ChOffset + i]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[(i * 2) + 1]) * \ + s16X[ChOffset + i]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor8SBs[(i + 16) * 2] * s16X[ChOffset + i + 16]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i + 16) * 2) + 1]) * \ + s16X[ChOffset + i + 16]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor8SBs[(i + 32) * 2] * s16X[ChOffset + i + 32]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i + 32) * 2) + 1]) * \ + s16X[ChOffset + i + 32]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor8SBs[(i + 48) * 2] * s16X[ChOffset + i + 48]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i + 48) * 2) + 1]) * \ + s16X[ChOffset + i + 48]) >> \ + 16); \ + s32DCTY[i] += \ + (gas32CoeffFor8SBs[(i + 64) * 2] * s16X[ChOffset + i + 64]) + \ + (((int32_t)(uint16_t)(gas32CoeffFor8SBs[((i + 64) * 2) + 1]) * \ + s16X[ChOffset + i + 64]) >> \ + 16); \ + /*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i \ + * * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/ \ + /*s32DCTY[i]=(int32_t)(s64Temp>>16);*/ \ + } #endif #define WINDOW_PARTIAL_8 \ -{\ - WINDOW_ACCU_8(0); WINDOW_ACCU_8(1);\ - WINDOW_ACCU_8(2); WINDOW_ACCU_8(3);\ - WINDOW_ACCU_8(4); WINDOW_ACCU_8(5);\ - WINDOW_ACCU_8(6); WINDOW_ACCU_8(7);\ - WINDOW_ACCU_8(8); WINDOW_ACCU_8(9);\ - WINDOW_ACCU_8(10); WINDOW_ACCU_8(11);\ - WINDOW_ACCU_8(12); WINDOW_ACCU_8(13);\ - WINDOW_ACCU_8(14); WINDOW_ACCU_8(15);\ -} + { \ + WINDOW_ACCU_8(0); \ + WINDOW_ACCU_8(1); \ + WINDOW_ACCU_8(2); \ + WINDOW_ACCU_8(3); \ + WINDOW_ACCU_8(4); \ + WINDOW_ACCU_8(5); \ + WINDOW_ACCU_8(6); \ + WINDOW_ACCU_8(7); \ + WINDOW_ACCU_8(8); \ + WINDOW_ACCU_8(9); \ + WINDOW_ACCU_8(10); \ + WINDOW_ACCU_8(11); \ + WINDOW_ACCU_8(12); \ + WINDOW_ACCU_8(13); \ + WINDOW_ACCU_8(14); \ + WINDOW_ACCU_8(15); \ + } #endif #endif -static int16_t ShiftCounter=0; +static int16_t ShiftCounter = 0; extern int16_t EncMaxShiftCounter; /**************************************************************************** * SbcAnalysisFilter - performs Analysis of the input audio stream * * RETURNS : N/A */ -void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams, int16_t *input) -{ - int16_t *ps16PcmBuf; - int32_t *ps32SbBuf; - int32_t s32Blk,s32Ch; - int32_t s32NumOfChannels, s32NumOfBlocks; - int32_t i,*ps32X,*ps32X2; - int32_t Offset,Offset2,ChOffset; +void SbcAnalysisFilter4(SBC_ENC_PARAMS* pstrEncParams, int16_t* input) { + int16_t* ps16PcmBuf; + int32_t* ps32SbBuf; + int32_t s32Blk, s32Ch; + int32_t s32NumOfChannels, s32NumOfBlocks; + int32_t i, *ps32X, *ps32X2; + int32_t Offset, Offset2, ChOffset; #if (SBC_ARM_ASM_OPT == TRUE) - register int32_t s32Hi,s32Hi2; + register int32_t s32Hi, s32Hi2; #else #if (SBC_IPAQ_OPT == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) - register int64_t s64Temp,s64Temp2; + register int64_t s64Temp, s64Temp2; #else - register int32_t s32Temp,s32Temp2; + register int32_t s32Temp, s32Temp2; #endif #else #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) - int64_t s64Temp; + int64_t s64Temp; #endif #endif #endif - s32NumOfChannels = pstrEncParams->s16NumOfChannels; - s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; + s32NumOfChannels = pstrEncParams->s16NumOfChannels; + s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; - ps16PcmBuf = input; + ps16PcmBuf = input; - ps32SbBuf = pstrEncParams->s32SbBuffer; - Offset2=(int32_t)(EncMaxShiftCounter+40); - for (s32Blk=0; s32Blk s32SbBuffer; + Offset2 = (int32_t)(EncMaxShiftCounter + 40); + for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) { + Offset = (int32_t)(EncMaxShiftCounter - ShiftCounter); + /* Store new samples */ + if (s32NumOfChannels == 1) { + s16X[3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + } else { + s16X[3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + } + for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) { + ChOffset = s32Ch * Offset2 + Offset; - WINDOW_PARTIAL_4 + WINDOW_PARTIAL_4 - SBC_FastIDCT4(s32DCTY, ps32SbBuf); + SBC_FastIDCT4(s32DCTY, ps32SbBuf); - ps32SbBuf +=SUB_BANDS_4; - } - if (s32NumOfChannels==1) - { - if (ShiftCounter>=EncMaxShiftCounter) - { - SHIFTUP_X4; - ShiftCounter=0; - } - else - { - ShiftCounter+=SUB_BANDS_4; - } - } - else - { - if (ShiftCounter>=EncMaxShiftCounter) - { - SHIFTUP_X4_2; - ShiftCounter=0; - } - else - { - ShiftCounter+=SUB_BANDS_4; - } - } + ps32SbBuf += SUB_BANDS_4; } + if (s32NumOfChannels == 1) { + if (ShiftCounter >= EncMaxShiftCounter) { + SHIFTUP_X4; + ShiftCounter = 0; + } else { + ShiftCounter += SUB_BANDS_4; + } + } else { + if (ShiftCounter >= EncMaxShiftCounter) { + SHIFTUP_X4_2; + ShiftCounter = 0; + } else { + ShiftCounter += SUB_BANDS_4; + } + } + } } /* ////////////////////////////////////////////////////////////////////////// */ -void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams, int16_t *input) -{ - int16_t *ps16PcmBuf; - int32_t *ps32SbBuf; - int32_t s32Blk,s32Ch; /* counter for block*/ - int32_t Offset,Offset2; - int32_t s32NumOfChannels, s32NumOfBlocks; - int32_t i,*ps32X,*ps32X2; - int32_t ChOffset; +void SbcAnalysisFilter8(SBC_ENC_PARAMS* pstrEncParams, int16_t* input) { + int16_t* ps16PcmBuf; + int32_t* ps32SbBuf; + int32_t s32Blk, s32Ch; /* counter for block*/ + int32_t Offset, Offset2; + int32_t s32NumOfChannels, s32NumOfBlocks; + int32_t i, *ps32X, *ps32X2; + int32_t ChOffset; #if (SBC_ARM_ASM_OPT == TRUE) - register int32_t s32Hi,s32Hi2; + register int32_t s32Hi, s32Hi2; #else #if (SBC_IPAQ_OPT == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) - register int64_t s64Temp,s64Temp2; + register int64_t s64Temp, s64Temp2; #else - register int32_t s32Temp,s32Temp2; + register int32_t s32Temp, s32Temp2; #endif #else #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) - int64_t s64Temp; + int64_t s64Temp; #endif #endif #endif - s32NumOfChannels = pstrEncParams->s16NumOfChannels; - s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; + s32NumOfChannels = pstrEncParams->s16NumOfChannels; + s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; - ps16PcmBuf = input; + ps16PcmBuf = input; - ps32SbBuf = pstrEncParams->s32SbBuffer; - Offset2=(int32_t)(EncMaxShiftCounter+80); - for (s32Blk=0; s32Blk s32SbBuffer; + Offset2 = (int32_t)(EncMaxShiftCounter + 80); + for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) { + Offset = (int32_t)(EncMaxShiftCounter - ShiftCounter); + /* Store new samples */ + if (s32NumOfChannels == 1) { + s16X[7 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[6 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[5 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[4 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + } else { + s16X[7 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 7 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[6 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 6 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[5 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 5 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[4 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 4 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; + ps16PcmBuf++; + } + for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) { + ChOffset = s32Ch * Offset2 + Offset; - WINDOW_PARTIAL_8 + WINDOW_PARTIAL_8 - SBC_FastIDCT8 (s32DCTY, ps32SbBuf); + SBC_FastIDCT8(s32DCTY, ps32SbBuf); - ps32SbBuf +=SUB_BANDS_8; - } - if (s32NumOfChannels==1) - { - if (ShiftCounter>=EncMaxShiftCounter) - { - SHIFTUP_X8; - ShiftCounter=0; - } - else - { - ShiftCounter+=SUB_BANDS_8; - } - } - else - { - if (ShiftCounter>=EncMaxShiftCounter) - { - SHIFTUP_X8_2; - ShiftCounter=0; - } - else - { - ShiftCounter+=SUB_BANDS_8; - } - } + ps32SbBuf += SUB_BANDS_8; + } + if (s32NumOfChannels == 1) { + if (ShiftCounter >= EncMaxShiftCounter) { + SHIFTUP_X8; + ShiftCounter = 0; + } else { + ShiftCounter += SUB_BANDS_8; + } + } else { + if (ShiftCounter >= EncMaxShiftCounter) { + SHIFTUP_X8_2; + ShiftCounter = 0; + } else { + ShiftCounter += SUB_BANDS_8; + } } + } } -void SbcAnalysisInit (void) -{ - memset(s16X,0,ENC_VX_BUFFER_SIZE*sizeof(int16_t)); - ShiftCounter=0; +void SbcAnalysisInit(void) { + memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(int16_t)); + ShiftCounter = 0; } diff --git a/embdrv/sbc/encoder/srce/sbc_dct.c b/embdrv/sbc/encoder/srce/sbc_dct.c index 87879bdc1..4ef5572e3 100644 --- a/embdrv/sbc/encoder/srce/sbc_dct.c +++ b/embdrv/sbc/encoder/srce/sbc_dct.c @@ -22,11 +22,9 @@ * ******************************************************************************/ -#include "sbc_encoder.h" -#include "sbc_enc_func_declare.h" #include "sbc_dct.h" - - +#include "sbc_enc_func_declare.h" +#include "sbc_encoder.h" /******************************************************************************* * @@ -41,23 +39,38 @@ ******************************************************************************/ #if (SBC_IS_64_MULT_IN_IDCT == FALSE) -#define SBC_COS_PI_SUR_4 (0x00005a82) /* ((0x8000) * 0.7071) = cos(pi/4) */ -#define SBC_COS_PI_SUR_8 (0x00007641) /* ((0x8000) * 0.9239) = (cos(pi/8)) */ -#define SBC_COS_3PI_SUR_8 (0x000030fb) /* ((0x8000) * 0.3827) = (cos(3*pi/8)) */ -#define SBC_COS_PI_SUR_16 (0x00007d8a) /* ((0x8000) * 0.9808)) = (cos(pi/16)) */ -#define SBC_COS_3PI_SUR_16 (0x00006a6d) /* ((0x8000) * 0.8315)) = (cos(3*pi/16)) */ -#define SBC_COS_5PI_SUR_16 (0x0000471c) /* ((0x8000) * 0.5556)) = (cos(5*pi/16)) */ -#define SBC_COS_7PI_SUR_16 (0x000018f8) /* ((0x8000) * 0.1951)) = (cos(7*pi/16)) */ -#define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_16_SIMPLIFIED(a,b,c) +#define SBC_COS_PI_SUR_4 \ + (0x00005a82) /* ((0x8000) * 0.7071) = cos(pi/4) \ + */ +#define SBC_COS_PI_SUR_8 \ + (0x00007641) /* ((0x8000) * 0.9239) = (cos(pi/8)) */ +#define SBC_COS_3PI_SUR_8 \ + (0x000030fb) /* ((0x8000) * 0.3827) = (cos(3*pi/8)) */ +#define SBC_COS_PI_SUR_16 \ + (0x00007d8a) /* ((0x8000) * 0.9808)) = (cos(pi/16)) */ +#define SBC_COS_3PI_SUR_16 \ + (0x00006a6d) /* ((0x8000) * 0.8315)) = (cos(3*pi/16)) */ +#define SBC_COS_5PI_SUR_16 \ + (0x0000471c) /* ((0x8000) * 0.5556)) = (cos(5*pi/16)) */ +#define SBC_COS_7PI_SUR_16 \ + (0x000018f8) /* ((0x8000) * 0.1951)) = (cos(7*pi/16)) */ +#define SBC_IDCT_MULT(a, b, c) SBC_MULT_32_16_SIMPLIFIED(a, b, c) #else -#define SBC_COS_PI_SUR_4 (0x5A827999) /* ((0x80000000) * 0.707106781) = (cos(pi/4) ) */ -#define SBC_COS_PI_SUR_8 (0x7641AF3C) /* ((0x80000000) * 0.923879533) = (cos(pi/8) ) */ -#define SBC_COS_3PI_SUR_8 (0x30FBC54D) /* ((0x80000000) * 0.382683432) = (cos(3*pi/8) ) */ -#define SBC_COS_PI_SUR_16 (0x7D8A5F3F) /* ((0x80000000) * 0.98078528 )) = (cos(pi/16) ) */ -#define SBC_COS_3PI_SUR_16 (0x6A6D98A4) /* ((0x80000000) * 0.831469612)) = (cos(3*pi/16)) */ -#define SBC_COS_5PI_SUR_16 (0x471CECE6) /* ((0x80000000) * 0.555570233)) = (cos(5*pi/16)) */ -#define SBC_COS_7PI_SUR_16 (0x18F8B83C) /* ((0x80000000) * 0.195090322)) = (cos(7*pi/16)) */ -#define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_32(a,b,c) +#define SBC_COS_PI_SUR_4 \ + (0x5A827999) /* ((0x80000000) * 0.707106781) = (cos(pi/4) ) */ +#define SBC_COS_PI_SUR_8 \ + (0x7641AF3C) /* ((0x80000000) * 0.923879533) = (cos(pi/8) ) */ +#define SBC_COS_3PI_SUR_8 \ + (0x30FBC54D) /* ((0x80000000) * 0.382683432) = (cos(3*pi/8) ) */ +#define SBC_COS_PI_SUR_16 \ + (0x7D8A5F3F) /* ((0x80000000) * 0.98078528 )) = (cos(pi/16) ) */ +#define SBC_COS_3PI_SUR_16 \ + (0x6A6D98A4) /* ((0x80000000) * 0.831469612)) = (cos(3*pi/16)) */ +#define SBC_COS_5PI_SUR_16 \ + (0x471CECE6) /* ((0x80000000) * 0.555570233)) = (cos(5*pi/16)) */ +#define SBC_COS_7PI_SUR_16 \ + (0x18F8B83C) /* ((0x80000000) * 0.195090322)) = (cos(7*pi/16)) */ +#define SBC_IDCT_MULT(a, b, c) SBC_MULT_32_32(a, b, c) #endif /* SBC_IS_64_MULT_IN_IDCT */ #if (SBC_FAST_DCT == FALSE) @@ -65,116 +78,126 @@ extern const int16_t gas16AnalDCTcoeff8[]; extern const int16_t gas16AnalDCTcoeff4[]; #endif -void SBC_FastIDCT8(int32_t *pInVect, int32_t *pOutVect) -{ +void SBC_FastIDCT8(int32_t* pInVect, int32_t* pOutVect) { #if (SBC_FAST_DCT == TRUE) #if (SBC_ARM_ASM_OPT == TRUE) #else #if (SBC_IPAQ_OPT == TRUE) #if (SBC_IS_64_MULT_IN_IDCT == TRUE) - int64_t s64Temp; + int64_t s64Temp; #endif #else #if (SBC_IS_64_MULT_IN_IDCT == TRUE) - int32_t s32HiTemp; + int32_t s32HiTemp; #else - int32_t s32In2Temp; - register int32_t s32In1Temp; + int32_t s32In2Temp; + register int32_t s32In1Temp; #endif #endif #endif - register int32_t x0, x1, x2, x3, x4, x5, x6, x7,temp; - int32_t res_even[4], res_odd[4]; - /*x0= (pInVect[4])/2 ;*/ - SBC_IDCT_MULT(SBC_COS_PI_SUR_4,pInVect[4], x0); - /*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/ - - x1 = (pInVect[3] + pInVect[5]) >>1; - x2 = (pInVect[2] + pInVect[6]) >>1; - x3 = (pInVect[1] + pInVect[7]) >>1; - x4 = (pInVect[0] + pInVect[8]) >>1; - x5 = (pInVect[9] - pInVect[15]) >>1; - x6 = (pInVect[10] - pInVect[14])>>1; - x7 = (pInVect[11] - pInVect[13])>>1; - - /* 2-point IDCT of x0 and x4 as in (11) */ - temp = x0 ; - SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( x0 + x4 ), x0); /*x0 = ( x0 + x4 ) * cos(1*pi/4) ; */ - SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */ - - /* rearrangement of x2 and x6 as in (15) */ - x2 -=x6; - x6 <<= 1 ; - - /* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */ - SBC_IDCT_MULT(SBC_COS_PI_SUR_4,x6, x6); /*x6 = x6 * cos(1*pi/4) ; */ - temp = x2 ; - SBC_IDCT_MULT(SBC_COS_PI_SUR_8,( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */ - SBC_IDCT_MULT(SBC_COS_3PI_SUR_8,( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/ - - /* 4-point IDCT of x0,x2,x4 and x6 as in (11) */ - res_even[ 0 ] = x0 + x2 ; - res_even[ 1 ] = x4 + x6 ; - res_even[ 2 ] = x4 - x6 ; - res_even[ 3 ] = x0 - x2 ; - - - /* rearrangement of x1,x3,x5,x7 as in (15) */ - x7 <<= 1 ; - x5 = ( x5 <<1 ) - x7 ; - x3 = ( x3 <<1 ) - x5 ; - x1 -= x3 >>1 ; - - /* two-dimensional IDCT of x1 and x5 */ - SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */ - temp = x1 ; - x1 = x1 + x5 ; - x5 = temp - x5 ; - - /* rearrangement of x3 and x7 as in (15) */ - x3 -= x7; - x7 <<= 1 ; - SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x7, x7); /*x7 = x7 * cos(1*pi/4) ; */ - - /* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */ - temp = x3 ; - SBC_IDCT_MULT( SBC_COS_PI_SUR_8,( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */ - SBC_IDCT_MULT( SBC_COS_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/ - - /* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */ - SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */ - SBC_IDCT_MULT((SBC_COS_3PI_SUR_16), ( x5 + x7 ) , res_odd[1]); /*res_odd[ 1 ] = ( x5 + x7 ) * cos(3*pi/16) ; */ - SBC_IDCT_MULT((SBC_COS_5PI_SUR_16), ( x5 - x7 ) , res_odd[2]); /*res_odd[ 2 ] = ( x5 - x7 ) * cos(5*pi/16) ; */ - SBC_IDCT_MULT((SBC_COS_7PI_SUR_16), ( x1 - x3 ) , res_odd[3]); /*res_odd[ 3 ] = ( x1 - x3 ) * cos(7*pi/16) ; */ - - /* additions and subtractions as in (9) */ - pOutVect[0] = (res_even[ 0 ] + res_odd[ 0 ]) ; - pOutVect[1] = (res_even[ 1 ] + res_odd[ 1 ]) ; - pOutVect[2] = (res_even[ 2 ] + res_odd[ 2 ]) ; - pOutVect[3] = (res_even[ 3 ] + res_odd[ 3 ]) ; - pOutVect[7] = (res_even[ 0 ] - res_odd[ 0 ]) ; - pOutVect[6] = (res_even[ 1 ] - res_odd[ 1 ]) ; - pOutVect[5] = (res_even[ 2 ] - res_odd[ 2 ]) ; - pOutVect[4] = (res_even[ 3 ] - res_odd[ 3 ]) ; + register int32_t x0, x1, x2, x3, x4, x5, x6, x7, temp; + int32_t res_even[4], res_odd[4]; + /*x0= (pInVect[4])/2 ;*/ + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, pInVect[4], x0); + /*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/ + + x1 = (pInVect[3] + pInVect[5]) >> 1; + x2 = (pInVect[2] + pInVect[6]) >> 1; + x3 = (pInVect[1] + pInVect[7]) >> 1; + x4 = (pInVect[0] + pInVect[8]) >> 1; + x5 = (pInVect[9] - pInVect[15]) >> 1; + x6 = (pInVect[10] - pInVect[14]) >> 1; + x7 = (pInVect[11] - pInVect[13]) >> 1; + + /* 2-point IDCT of x0 and x4 as in (11) */ + temp = x0; + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, (x0 + x4), + x0); /*x0 = ( x0 + x4 ) * cos(1*pi/4) ; */ + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, (temp - x4), + x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */ + + /* rearrangement of x2 and x6 as in (15) */ + x2 -= x6; + x6 <<= 1; + + /* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */ + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x6, x6); /*x6 = x6 * cos(1*pi/4) ; */ + temp = x2; + SBC_IDCT_MULT(SBC_COS_PI_SUR_8, (x2 + x6), + x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */ + SBC_IDCT_MULT(SBC_COS_3PI_SUR_8, (temp - x6), + x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/ + + /* 4-point IDCT of x0,x2,x4 and x6 as in (11) */ + res_even[0] = x0 + x2; + res_even[1] = x4 + x6; + res_even[2] = x4 - x6; + res_even[3] = x0 - x2; + + /* rearrangement of x1,x3,x5,x7 as in (15) */ + x7 <<= 1; + x5 = (x5 << 1) - x7; + x3 = (x3 << 1) - x5; + x1 -= x3 >> 1; + + /* two-dimensional IDCT of x1 and x5 */ + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */ + temp = x1; + x1 = x1 + x5; + x5 = temp - x5; + + /* rearrangement of x3 and x7 as in (15) */ + x3 -= x7; + x7 <<= 1; + SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x7, x7); /*x7 = x7 * cos(1*pi/4) ; */ + + /* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */ + temp = x3; + SBC_IDCT_MULT(SBC_COS_PI_SUR_8, (x3 + x7), + x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */ + SBC_IDCT_MULT(SBC_COS_3PI_SUR_8, (temp - x7), + x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/ + + /* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix + * as in (14) */ + SBC_IDCT_MULT((SBC_COS_PI_SUR_16), (x1 + x3), + res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */ + SBC_IDCT_MULT((SBC_COS_3PI_SUR_16), (x5 + x7), + res_odd[1]); /*res_odd[ 1 ] = ( x5 + x7 ) * cos(3*pi/16) ; */ + SBC_IDCT_MULT((SBC_COS_5PI_SUR_16), (x5 - x7), + res_odd[2]); /*res_odd[ 2 ] = ( x5 - x7 ) * cos(5*pi/16) ; */ + SBC_IDCT_MULT((SBC_COS_7PI_SUR_16), (x1 - x3), + res_odd[3]); /*res_odd[ 3 ] = ( x1 - x3 ) * cos(7*pi/16) ; */ + + /* additions and subtractions as in (9) */ + pOutVect[0] = (res_even[0] + res_odd[0]); + pOutVect[1] = (res_even[1] + res_odd[1]); + pOutVect[2] = (res_even[2] + res_odd[2]); + pOutVect[3] = (res_even[3] + res_odd[3]); + pOutVect[7] = (res_even[0] - res_odd[0]); + pOutVect[6] = (res_even[1] - res_odd[1]); + pOutVect[5] = (res_even[2] - res_odd[2]); + pOutVect[4] = (res_even[3] - res_odd[3]); #else - uint8_t Index, k; - int32_t temp; - /*Calculate 4 subband samples by matrixing*/ - for(Index=0; Index<8; Index++) - { - temp = 0; - for(k=0; k<16; k++) - { - /*temp += (int32_t)(((int64_t)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/ - temp += (gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] >> 16)); - temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16); - } - pOutVect[Index] = temp; + uint8_t Index, k; + int32_t temp; + /*Calculate 4 subband samples by matrixing*/ + for (Index = 0; Index < 8; Index++) { + temp = 0; + for (k = 0; k < 16; k++) { + /*temp += (int32_t)(((int64_t)M[(Index*strEncParams->numOfSubBands*2)+k] * + * Y[k]) >> 16 );*/ + temp += (gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] >> 16)); + temp += + ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> + 16); } + pOutVect[Index] = temp; + } #endif -/* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\ - pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/ + /* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\ + pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/ } /******************************************************************************* @@ -188,58 +211,58 @@ void SBC_FastIDCT8(int32_t *pInVect, int32_t *pOutVect) * * ******************************************************************************/ -void SBC_FastIDCT4(int32_t *pInVect, int32_t *pOutVect) -{ +void SBC_FastIDCT4(int32_t* pInVect, int32_t* pOutVect) { #if (SBC_FAST_DCT == TRUE) #if (SBC_ARM_ASM_OPT == TRUE) #else #if (SBC_IPAQ_OPT == TRUE) #if (SBC_IS_64_MULT_IN_IDCT == TRUE) - int64_t s64Temp; + int64_t s64Temp; #endif #else #if (SBC_IS_64_MULT_IN_IDCT == TRUE) - int32_t s32HiTemp; + int32_t s32HiTemp; #else - uint16_t s32In2Temp; - int32_t s32In1Temp; + uint16_t s32In2Temp; + int32_t s32In1Temp; #endif #endif #endif - int32_t temp,x2; - int32_t tmp[8]; - - x2=pInVect[2]>>1; - temp=(pInVect[0]+pInVect[4]); - SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]); - tmp[1]=x2-tmp[0]; - tmp[0]+=x2; - temp=(pInVect[1]+pInVect[3]); - SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[3]); - SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[2]); - temp=(pInVect[5]-pInVect[7]); - SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]); - SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]); - tmp[6]=tmp[2]+tmp[5]; - tmp[7]=tmp[3]-tmp[4]; - pOutVect[0] = (tmp[0]+tmp[6]); - pOutVect[1] = (tmp[1]+tmp[7]); - pOutVect[2] = (tmp[1]-tmp[7]); - pOutVect[3] = (tmp[0]-tmp[6]); + int32_t temp, x2; + int32_t tmp[8]; + + x2 = pInVect[2] >> 1; + temp = (pInVect[0] + pInVect[4]); + SBC_IDCT_MULT((SBC_COS_PI_SUR_4 >> 1), temp, tmp[0]); + tmp[1] = x2 - tmp[0]; + tmp[0] += x2; + temp = (pInVect[1] + pInVect[3]); + SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp, tmp[3]); + SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp, tmp[2]); + temp = (pInVect[5] - pInVect[7]); + SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp, tmp[5]); + SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp, tmp[4]); + tmp[6] = tmp[2] + tmp[5]; + tmp[7] = tmp[3] - tmp[4]; + pOutVect[0] = (tmp[0] + tmp[6]); + pOutVect[1] = (tmp[1] + tmp[7]); + pOutVect[2] = (tmp[1] - tmp[7]); + pOutVect[3] = (tmp[0] - tmp[6]); #else - uint8_t Index, k; - int32_t temp; - /*Calculate 4 subband samples by matrixing*/ - for(Index=0; Index<4; Index++) - { - temp = 0; - for(k=0; k<8; k++) - { - /*temp += (int32_t)(((int64_t)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */ - temp += (gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] >> 16)); - temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16); - } - pOutVect[Index] = temp; + uint8_t Index, k; + int32_t temp; + /*Calculate 4 subband samples by matrixing*/ + for (Index = 0; Index < 4; Index++) { + temp = 0; + for (k = 0; k < 8; k++) { + /*temp += (int32_t)(((int64_t)M[(Index*strEncParams->numOfSubBands*2)+k] * + * Y[k]) >> 16 ); */ + temp += (gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] >> 16)); + temp += + ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> + 16); } + pOutVect[Index] = temp; + } #endif } diff --git a/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c b/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c index 1ac7d0c2c..287ad4ce3 100644 --- a/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c +++ b/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c @@ -26,175 +26,91 @@ #include "sbc_encoder.h" /*DCT coeff for 4 sub-band case.*/ #if (SBC_FAST_DCT == FALSE) -const int16_t gas16AnalDCTcoeff4[] = -{ - (int16_t)(0.7071*32768), - (int16_t)(0.9239*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.9239*32768), - (int16_t)(0.7071*32768), - (int16_t)(0.3827*32768), - (int16_t)(0.0000*32768), - (int16_t)(-0.3827*32768), +const int16_t gas16AnalDCTcoeff4[] = { + (int16_t)(0.7071 * 32768), (int16_t)(0.9239 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.9239 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(0.3827 * 32768), + (int16_t)(0.0000 * 32768), (int16_t)(-0.3827 * 32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.3827*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.3827*32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.9239*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.9239*32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.3827 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.3827 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.9239 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.9239 * 32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.3827*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.3827*32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.9239*32768), - (int16_t)(0.0000*32768), - (int16_t)(-0.9239*32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.3827 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.3827 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.9239 * 32768), + (int16_t)(0.0000 * 32768), (int16_t)(-0.9239 * 32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.9239*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.9239*32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.3827*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.3827*32768) -}; + (int16_t)(0.7071 * 32768), (int16_t)(-0.9239 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.9239 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(-0.3827 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.3827 * 32768)}; /*DCT coeff for 8 sub-band case.*/ -const int16_t gas16AnalDCTcoeff8[] = -{ - (int16_t)(0.7071*32768), - (int16_t)(0.8315*32768), - (int16_t)(0.9239*32768), - (int16_t)(0.9808*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.9808*32768), - (int16_t)(0.9239*32768), - (int16_t)(0.8315*32768), - (int16_t)(0.7071*32768), - (int16_t)(0.5556*32768), - (int16_t)(0.3827*32768), - (int16_t)(0.1951*32768), - (int16_t)(0.0000*32768), - (int16_t)(-0.1951*32768), - (int16_t)(-0.3827*32768), - (int16_t)(-0.5556*32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.1951*32768), - (int16_t)(0.3827*32768), - (int16_t)(0.8315*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.8315*32768), - (int16_t)(0.3827*32768), - (int16_t)(-0.1951*32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.9808*32768), - (int16_t)(-0.9239*32768), - (int16_t)(-0.5556*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.5556*32768), - (int16_t)(0.9239*32768), - (int16_t)(0.9808*32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.9808*32768), - (int16_t)(-0.3827*32768), - (int16_t)(0.5556*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.5556*32768), - (int16_t)(-0.3827*32768), - (int16_t)(-0.9808*32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.1951*32768), - (int16_t)(0.9239*32768), - (int16_t)(0.8315*32768), - (int16_t)(0.0000*32768), - (int16_t)(-0.8315*32768), - (int16_t)(-0.9239*32768), - (int16_t)(-0.1951*32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.5556*32768), - (int16_t)(-0.9239*32768), - (int16_t)(0.1951*32768), - (int16_t)(1.0000*32767), - (int16_t)(0.1951*32768), - (int16_t)(-0.9239*32768), - (int16_t)(-0.5556*32768), - (int16_t)(0.7071*32768), - (int16_t)(0.8315*32768), - (int16_t)(-0.3827*32768), - (int16_t)(-0.9808*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.9808*32768), - (int16_t)(0.3827*32768), - (int16_t)(-0.8315*32768), - (int16_t)(0.7071*32768), - (int16_t)(0.5556*32768), - (int16_t)(-0.9239*32768), - (int16_t)(-0.1951*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.1951*32768), - (int16_t)(-0.9239*32768), - (int16_t)(0.5556*32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.8315*32768), - (int16_t)(-0.3827*32768), - (int16_t)(0.9808*32768), - (int16_t)(0.0000*32768), - (int16_t)(-0.9808*32768), - (int16_t)(0.3827*32768), - (int16_t)(0.8315*32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.9808*32768), - (int16_t)(-0.3827*32768), - (int16_t)(-0.5556*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.5556*32768), - (int16_t)(-0.3827*32768), - (int16_t)(0.9808*32768), - (int16_t)(-0.7071*32768), - (int16_t)(-0.1951*32768), - (int16_t)(0.9239*32768), - (int16_t)(-0.8315*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.8315*32768), - (int16_t)(-0.9239*32768), - (int16_t)(0.1951*32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.1951*32768), - (int16_t)(0.3827*32768), - (int16_t)(-0.8315*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.8315*32768), - (int16_t)(0.3827*32768), - (int16_t)(0.1951*32768), - (int16_t)(-0.7071*32768), - (int16_t)(0.9808*32768), - (int16_t)(-0.9239*32768), - (int16_t)(0.5556*32768), - (int16_t)(-0.0000*32768), - (int16_t)(-0.5556*32768), - (int16_t)(0.9239*32768), - (int16_t)(-0.9808*32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.8315*32768), - (int16_t)(0.9239*32768), - (int16_t)(-0.9808*32768), - (int16_t)(1.0000*32767), - (int16_t)(-0.9808*32768), - (int16_t)(0.9239*32768), - (int16_t)(-0.8315*32768), - (int16_t)(0.7071*32768), - (int16_t)(-0.5556*32768), - (int16_t)(0.3827*32768), - (int16_t)(-0.1951*32768), - (int16_t)(-0.0000*32768), - (int16_t)(0.1951*32768), - (int16_t)(-0.3827*32768), - (int16_t)(0.5556*32768) -}; +const int16_t gas16AnalDCTcoeff8[] = { + (int16_t)(0.7071 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.9808 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(0.0000 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.8315 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.5556 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(0.0000 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(0.1951 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.1951 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(0.0000 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.5556 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.8315 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.8315 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(-0.7071 * 32768), (int16_t)(0.9808 * 32768), + (int16_t)(-0.9239 * 32768), (int16_t)(0.5556 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(-0.9808 * 32768), + (int16_t)(1.0000 * 32767), (int16_t)(-0.9808 * 32768), + (int16_t)(0.9239 * 32768), (int16_t)(-0.8315 * 32768), + (int16_t)(0.7071 * 32768), (int16_t)(-0.5556 * 32768), + (int16_t)(0.3827 * 32768), (int16_t)(-0.1951 * 32768), + (int16_t)(-0.0000 * 32768), (int16_t)(0.1951 * 32768), + (int16_t)(-0.3827 * 32768), (int16_t)(0.5556 * 32768)}; #endif diff --git a/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c b/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c index f5d439ebc..f8493405c 100644 --- a/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c +++ b/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c @@ -24,16 +24,16 @@ ******************************************************************************/ /*Includes*/ -#include "sbc_encoder.h" #include "sbc_enc_func_declare.h" +#include "sbc_encoder.h" /*global arrays*/ -const int16_t sbc_enc_as16Offset4[4][4] = { {-1, 0, 0, 0}, {-2, 0, 0, 1}, - {-2, 0, 0, 1}, {-2, 0, 0, 1} }; -const int16_t sbc_enc_as16Offset8[4][8] = { {-2, 0, 0, 0, 0, 0, 0, 1}, - {-3, 0, 0, 0, 0, 0, 1, 2}, - {-4, 0, 0, 0, 0, 0, 1, 2}, - {-4, 0, 0, 0, 0, 0, 1, 2} }; +const int16_t sbc_enc_as16Offset4[4][4] = { + {-1, 0, 0, 0}, {-2, 0, 0, 1}, {-2, 0, 0, 1}, {-2, 0, 0, 1}}; +const int16_t sbc_enc_as16Offset8[4][8] = {{-2, 0, 0, 0, 0, 0, 0, 1}, + {-3, 0, 0, 0, 0, 0, 1, 2}, + {-4, 0, 0, 0, 0, 0, 1, 2}, + {-4, 0, 0, 0, 0, 0, 1, 2}}; /**************************************************************************** * BitAlloc - Calculates the required number of bits for the given scale factor @@ -42,158 +42,136 @@ const int16_t sbc_enc_as16Offset8[4][8] = { {-2, 0, 0, 0, 0, 0, 0, 1}, * RETURNS : N/A */ -void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams) -{ - int32_t s32MaxBitNeed; /*to store the max bits needed per sb*/ - int32_t s32BitCount; /*the used number of bits*/ - int32_t s32SliceCount; /*to store hwo many slices can be put in bitpool*/ - int32_t s32BitSlice; /*number of bitslices in bitpool*/ - int32_t s32Sb; /*counter for sub-band*/ - int32_t s32Ch; /*counter for channel*/ - int16_t *ps16BitNeed; /*temp memory to store required number of bits*/ - int32_t s32Loudness; /*used in Loudness calculation*/ - int16_t *ps16GenBufPtr; - int16_t *ps16GenArrPtr; - int16_t *ps16GenTabPtr; - int32_t s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands; - - ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc; - - for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) - { - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS; - - /* bitneed values are derived from scale factor */ - if (pstrCodecParams->s16AllocationMethod == SBC_SNR) - { - ps16BitNeed = pstrCodecParams->as16ScaleFactor; - ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; +void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS* pstrCodecParams) { + int32_t s32MaxBitNeed; /*to store the max bits needed per sb*/ + int32_t s32BitCount; /*the used number of bits*/ + int32_t s32SliceCount; /*to store hwo many slices can be put in bitpool*/ + int32_t s32BitSlice; /*number of bitslices in bitpool*/ + int32_t s32Sb; /*counter for sub-band*/ + int32_t s32Ch; /*counter for channel*/ + int16_t* ps16BitNeed; /*temp memory to store required number of bits*/ + int32_t s32Loudness; /*used in Loudness calculation*/ + int16_t* ps16GenBufPtr; + int16_t* ps16GenArrPtr; + int16_t* ps16GenTabPtr; + int32_t s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands; + + ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc; + + for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) { + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * SBC_MAX_NUM_OF_SUBBANDS; + + /* bitneed values are derived from scale factor */ + if (pstrCodecParams->s16AllocationMethod == SBC_SNR) { + ps16BitNeed = pstrCodecParams->as16ScaleFactor; + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + } else { + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + if (s32NumOfSubBands == 4) { + ps16GenTabPtr = + (int16_t*)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; + } else { + ps16GenTabPtr = + (int16_t*)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; + } + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if (pstrCodecParams + ->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) + *(ps16GenBufPtr) = -5; + else { + s32Loudness = (int32_t)( + pstrCodecParams + ->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] - + *ps16GenTabPtr); + if (s32Loudness > 0) + *(ps16GenBufPtr) = (int16_t)(s32Loudness >> 1); + else + *(ps16GenBufPtr) = (int16_t)s32Loudness; } - else - { - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - if(s32NumOfSubBands == 4) - { - ps16GenTabPtr = (int16_t *) - sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; - } - else - { - ps16GenTabPtr = (int16_t *) - sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; - } - for(s32Sb=0; s32Sbas16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0) - *(ps16GenBufPtr) = -5; - else - { - s32Loudness = - (int32_t)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] - - *ps16GenTabPtr); - if(s32Loudness > 0) - *(ps16GenBufPtr) = (int16_t)(s32Loudness >>1); - else - *(ps16GenBufPtr) = (int16_t)s32Loudness; - } - ps16GenBufPtr++; - ps16GenTabPtr++; - } + ps16GenBufPtr++; + ps16GenTabPtr++; + } + } + + /* max bitneed index is searched*/ + s32MaxBitNeed = 0; + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if (*(ps16GenBufPtr) > s32MaxBitNeed) s32MaxBitNeed = *(ps16GenBufPtr); + ps16GenBufPtr++; + } + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + /*iterative process to find hwo many bitslices fit into the bitpool*/ + s32BitSlice = s32MaxBitNeed + 1; + s32BitCount = pstrCodecParams->s16BitPool; + s32SliceCount = 0; + do { + s32BitSlice--; + s32BitCount -= s32SliceCount; + s32SliceCount = 0; + + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if ((((*ps16GenBufPtr - s32BitSlice) < 16) && + (*ps16GenBufPtr - s32BitSlice) >= 1)) { + if ((*ps16GenBufPtr - s32BitSlice) == 1) + s32SliceCount += 2; + else + s32SliceCount++; } + ps16GenBufPtr++; - /* max bitneed index is searched*/ - s32MaxBitNeed = 0; - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - for(s32Sb=0; s32Sb s32MaxBitNeed) - s32MaxBitNeed = *(ps16GenBufPtr); + } /*end of for*/ + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + } while (s32BitCount - s32SliceCount > 0); - ps16GenBufPtr++; - } - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - /*iterative process to find hwo many bitslices fit into the bitpool*/ - s32BitSlice = s32MaxBitNeed + 1; - s32BitCount = pstrCodecParams->s16BitPool; - s32SliceCount = 0; - do - { - s32BitSlice --; - s32BitCount -= s32SliceCount; - s32SliceCount = 0; - - for(s32Sb=0; s32Sb= 1)) - { - if((*ps16GenBufPtr-s32BitSlice) == 1) - s32SliceCount+=2; - else - s32SliceCount++; - } - ps16GenBufPtr++; - - }/*end of for*/ - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - }while(s32BitCount-s32SliceCount>0); - - if(s32BitCount == 0) - { - s32BitCount -= s32SliceCount; - s32BitSlice --; - } + if (s32BitCount == 0) { + s32BitCount -= s32SliceCount; + s32BitSlice--; + } - /*Bits are distributed until the last bitslice is reached*/ - ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands; - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - for(s32Sb=0; s32Sbas16Bits+s32Ch*s32NumOfSubBands; - ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; - /*the remaining bits are allocated starting at subband 0*/ - s32Sb=0; - while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) - { - if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) - { - (*(ps16GenArrPtr))++; - s32BitCount--; - } - else if( (*(ps16GenBufPtr) == s32BitSlice+1) && - (s32BitCount > 1) ) - { - *(ps16GenArrPtr) = 2; - s32BitCount -= 2; - } - s32Sb++; - ps16GenArrPtr++; - ps16GenBufPtr++; - } - ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands; - - - s32Sb=0; - while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) - { - if( *(ps16GenArrPtr) < 16) - { - (*(ps16GenArrPtr))++; - s32BitCount--; - } - s32Sb++; - ps16GenArrPtr++; - } + /*Bits are distributed until the last bitslice is reached*/ + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands; + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if (*(ps16GenBufPtr) < s32BitSlice + 2) + *(ps16GenArrPtr) = 0; + else + *(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice) < 16) + ? (int16_t)(*(ps16GenBufPtr)-s32BitSlice) + : 16; + + ps16GenBufPtr++; + ps16GenArrPtr++; + } + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands; + ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; + /*the remaining bits are allocated starting at subband 0*/ + s32Sb = 0; + while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) { + if ((*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16)) { + (*(ps16GenArrPtr))++; + s32BitCount--; + } else if ((*(ps16GenBufPtr) == s32BitSlice + 1) && (s32BitCount > 1)) { + *(ps16GenArrPtr) = 2; + s32BitCount -= 2; + } + s32Sb++; + ps16GenArrPtr++; + ps16GenBufPtr++; + } + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands; + + s32Sb = 0; + while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) { + if (*(ps16GenArrPtr) < 16) { + (*(ps16GenArrPtr))++; + s32BitCount--; + } + s32Sb++; + ps16GenArrPtr++; } + } } /*End of BitAlloc() function*/ diff --git a/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c b/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c index 410c8d684..4e205e2e8 100644 --- a/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c +++ b/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c @@ -24,8 +24,8 @@ ******************************************************************************/ /*Includes*/ -#include "sbc_encoder.h" #include "sbc_enc_func_declare.h" +#include "sbc_encoder.h" /*global arrays*/ extern const int16_t sbc_enc_as16Offset4[4][4]; @@ -38,175 +38,150 @@ extern const int16_t sbc_enc_as16Offset8[4][8]; * RETURNS : N/A */ -void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams) -{ - /* CAUTIOM -> mips optim for arm 32 require to use int32_t instead of int16_t */ - /* Do not change variable type or name */ - int32_t s32MaxBitNeed; /*to store the max bits needed per sb*/ - int32_t s32BitCount; /*the used number of bits*/ - int32_t s32SliceCount; /*to store hwo many slices can be put in bitpool*/ - int32_t s32BitSlice; /*number of bitslices in bitpool*/ - int32_t s32Sb; /*counter for sub-band*/ - int32_t s32Ch; /*counter for channel*/ - int16_t *ps16BitNeed; /*temp memory to store required number of bits*/ - int32_t s32Loudness; /*used in Loudness calculation*/ - int16_t *ps16GenBufPtr,*pas16ScaleFactor; - int16_t *ps16GenArrPtr; - int16_t *ps16GenTabPtr; - int32_t s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands; - int32_t s32BitPool = pstrCodecParams->s16BitPool; - - /* bitneed values are derived from scale factor */ - if (pstrCodecParams->s16AllocationMethod == SBC_SNR) - { - ps16BitNeed = pstrCodecParams->as16ScaleFactor; - s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed; - } - else - { - ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc; - pas16ScaleFactor=pstrCodecParams->as16ScaleFactor; - s32MaxBitNeed = 0; - ps16GenBufPtr = ps16BitNeed; - for (s32Ch = 0; s32Ch < 2; s32Ch++) - { - if (s32NumOfSubBands == 4) - { - ps16GenTabPtr = (int16_t *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; - } - else - { - ps16GenTabPtr = (int16_t *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; - } - - for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) - { - if (*pas16ScaleFactor == 0) - *ps16GenBufPtr = -5; - else - { - s32Loudness = (int32_t)(*pas16ScaleFactor - *ps16GenTabPtr); - - if (s32Loudness > 0) - *ps16GenBufPtr = (int16_t)(s32Loudness >> 1); - else - *ps16GenBufPtr = (int16_t)s32Loudness; - } - - if (*ps16GenBufPtr > s32MaxBitNeed) - s32MaxBitNeed = *ps16GenBufPtr; - pas16ScaleFactor++; - ps16GenBufPtr++; - ps16GenTabPtr++; - } - } - } - - /* iterative process to find out hwo many bitslices fit into the bitpool */ - s32BitSlice = s32MaxBitNeed + 1; - s32BitCount = s32BitPool; - s32SliceCount = 0; - do - { - s32BitSlice --; - s32BitCount -= s32SliceCount; - s32SliceCount = 0; - ps16GenBufPtr = ps16BitNeed; - - for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++) - { - if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) - { - if (*(ps16GenBufPtr) == s32BitSlice+1) - s32SliceCount += 2; - else - s32SliceCount++; - } - ps16GenBufPtr++; +void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS* pstrCodecParams) { + /* CAUTIOM -> mips optim for arm 32 require to use int32_t instead of int16_t + */ + /* Do not change variable type or name */ + int32_t s32MaxBitNeed; /*to store the max bits needed per sb*/ + int32_t s32BitCount; /*the used number of bits*/ + int32_t s32SliceCount; /*to store hwo many slices can be put in bitpool*/ + int32_t s32BitSlice; /*number of bitslices in bitpool*/ + int32_t s32Sb; /*counter for sub-band*/ + int32_t s32Ch; /*counter for channel*/ + int16_t* ps16BitNeed; /*temp memory to store required number of bits*/ + int32_t s32Loudness; /*used in Loudness calculation*/ + int16_t *ps16GenBufPtr, *pas16ScaleFactor; + int16_t* ps16GenArrPtr; + int16_t* ps16GenTabPtr; + int32_t s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands; + int32_t s32BitPool = pstrCodecParams->s16BitPool; + + /* bitneed values are derived from scale factor */ + if (pstrCodecParams->s16AllocationMethod == SBC_SNR) { + ps16BitNeed = pstrCodecParams->as16ScaleFactor; + s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed; + } else { + ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc; + pas16ScaleFactor = pstrCodecParams->as16ScaleFactor; + s32MaxBitNeed = 0; + ps16GenBufPtr = ps16BitNeed; + for (s32Ch = 0; s32Ch < 2; s32Ch++) { + if (s32NumOfSubBands == 4) { + ps16GenTabPtr = + (int16_t*)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; + } else { + ps16GenTabPtr = + (int16_t*)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; + } + + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if (*pas16ScaleFactor == 0) + *ps16GenBufPtr = -5; + else { + s32Loudness = (int32_t)(*pas16ScaleFactor - *ps16GenTabPtr); + + if (s32Loudness > 0) + *ps16GenBufPtr = (int16_t)(s32Loudness >> 1); + else + *ps16GenBufPtr = (int16_t)s32Loudness; } - } while (s32BitCount-s32SliceCount>0); - if (s32BitCount-s32SliceCount == 0) - { - s32BitCount -= s32SliceCount; - s32BitSlice --; + if (*ps16GenBufPtr > s32MaxBitNeed) s32MaxBitNeed = *ps16GenBufPtr; + pas16ScaleFactor++; + ps16GenBufPtr++; + ps16GenTabPtr++; + } } - - /* Bits are distributed until the last bitslice is reached */ + } + + /* iterative process to find out hwo many bitslices fit into the bitpool */ + s32BitSlice = s32MaxBitNeed + 1; + s32BitCount = s32BitPool; + s32SliceCount = 0; + do { + s32BitSlice--; + s32BitCount -= s32SliceCount; + s32SliceCount = 0; ps16GenBufPtr = ps16BitNeed; - ps16GenArrPtr = pstrCodecParams->as16Bits; - for (s32Ch = 0; s32Ch < 2; s32Ch++) - { - for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) - { - if (*ps16GenBufPtr < s32BitSlice+2) - *ps16GenArrPtr = 0; - else - *ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ? - (int16_t)(*(ps16GenBufPtr)-s32BitSlice):16; - ps16GenBufPtr++; - ps16GenArrPtr++; - } - } - /* the remaining bits are allocated starting at subband 0 */ - s32Ch=0; - s32Sb=0; - ps16GenBufPtr = ps16BitNeed; - ps16GenArrPtr -= 2*s32NumOfSubBands; - - while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) - { - if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) - { - (*(ps16GenArrPtr))++; - s32BitCount--; - } - else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1)) - { - *(ps16GenArrPtr) = 2; - s32BitCount -= 2; - } - if(s32Ch == 1) - { - s32Ch = 0; - s32Sb++; - ps16GenBufPtr = ps16BitNeed+s32Sb; - ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb; - - } + for (s32Sb = 0; s32Sb < 2 * s32NumOfSubBands; s32Sb++) { + if ((*ps16GenBufPtr >= s32BitSlice + 1) && + (*ps16GenBufPtr < s32BitSlice + 16)) { + if (*(ps16GenBufPtr) == s32BitSlice + 1) + s32SliceCount += 2; else - { - s32Ch =1; - ps16GenBufPtr = ps16BitNeed+s32NumOfSubBands+s32Sb; - ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb; - } + s32SliceCount++; + } + ps16GenBufPtr++; + } + } while (s32BitCount - s32SliceCount > 0); + + if (s32BitCount - s32SliceCount == 0) { + s32BitCount -= s32SliceCount; + s32BitSlice--; + } + + /* Bits are distributed until the last bitslice is reached */ + ps16GenBufPtr = ps16BitNeed; + ps16GenArrPtr = pstrCodecParams->as16Bits; + for (s32Ch = 0; s32Ch < 2; s32Ch++) { + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + if (*ps16GenBufPtr < s32BitSlice + 2) + *ps16GenArrPtr = 0; + else + *ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) + ? (int16_t)(*(ps16GenBufPtr)-s32BitSlice) + : 16; + ps16GenBufPtr++; + ps16GenArrPtr++; + } + } + + /* the remaining bits are allocated starting at subband 0 */ + s32Ch = 0; + s32Sb = 0; + ps16GenBufPtr = ps16BitNeed; + ps16GenArrPtr -= 2 * s32NumOfSubBands; + + while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) { + if ((*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16)) { + (*(ps16GenArrPtr))++; + s32BitCount--; + } else if ((*ps16GenBufPtr == s32BitSlice + 1) && (s32BitCount > 1)) { + *(ps16GenArrPtr) = 2; + s32BitCount -= 2; + } + if (s32Ch == 1) { + s32Ch = 0; + s32Sb++; + ps16GenBufPtr = ps16BitNeed + s32Sb; + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb; + + } else { + s32Ch = 1; + ps16GenBufPtr = ps16BitNeed + s32NumOfSubBands + s32Sb; + ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb; } + } - s32Ch=0; - s32Sb=0; - ps16GenArrPtr = pstrCodecParams->as16Bits; + s32Ch = 0; + s32Sb = 0; + ps16GenArrPtr = pstrCodecParams->as16Bits; - while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands)) - { - if(*(ps16GenArrPtr) < 16) - { - (*(ps16GenArrPtr))++; - s32BitCount--; - } - if (s32Ch == 1) - { - s32Ch = 0; - s32Sb++; - ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb; - } - else - { - s32Ch = 1; - ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb; - } + while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) { + if (*(ps16GenArrPtr) < 16) { + (*(ps16GenArrPtr))++; + s32BitCount--; + } + if (s32Ch == 1) { + s32Ch = 0; + s32Sb++; + ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb; + } else { + s32Ch = 1; + ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb; } + } } /*End of BitAlloc() function*/ - diff --git a/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c b/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c index 95d1fd912..2129fba04 100644 --- a/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c +++ b/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c @@ -27,293 +27,218 @@ #if (SBC_ARM_ASM_OPT == FALSE && SBC_IPAQ_OPT == FALSE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE) /*Window coeff for 4 sub band case*/ -const int16_t gas32CoeffFor4SBs[] = -{ - (int16_t)((int32_t)0x00000000 >> 16), (int16_t)0x00000000, - (int16_t)((int32_t)0x001194E6 >> 16), (int16_t)0x001194E6, - (int16_t)((int32_t)0x0030E2D3 >> 16), (int16_t)0x0030E2D3, - (int16_t)((int32_t)0x00599403 >> 16), (int16_t)0x00599403, - (int16_t)((int32_t)0x007DBCC8 >> 16), (int16_t)0x007DBCC8, - (int16_t)((int32_t)0x007F88E4 >> 16), (int16_t)0x007F88E4, - (int16_t)((int32_t)0x003D239B >> 16), (int16_t)0x003D239B, - (int16_t)((int32_t)0xFF9BB9D5 >> 16), (int16_t)0xFF9BB9D5, - - (int16_t)((int32_t)0x01659F45 >> 16), (int16_t)0x01659F45, - (int16_t)((int32_t)0x029DBAA3 >> 16), (int16_t)0x029DBAA3, - (int16_t)((int32_t)0x03B23341 >> 16), (int16_t)0x03B23341, - (int16_t)((int32_t)0x041EEE40 >> 16), (int16_t)0x041EEE40, - (int16_t)((int32_t)0x034FEE2C >> 16), (int16_t)0x034FEE2C, - (int16_t)((int32_t)0x00C8F2BC >> 16), (int16_t)0x00C8F2BC, - (int16_t)((int32_t)0xFC4F91D4 >> 16), (int16_t)0xFC4F91D4, - (int16_t)((int32_t)0xF60FAF37 >> 16), (int16_t)0xF60FAF37, - - (int16_t)((int32_t)0x115B1ED2 >> 16), (int16_t)0x115B1ED2, - (int16_t)((int32_t)0x18F55C90 >> 16), (int16_t)0x18F55C90, - (int16_t)((int32_t)0x1F91CA46 >> 16), (int16_t)0x1F91CA46, - (int16_t)((int32_t)0x2412F251 >> 16), (int16_t)0x2412F251, - (int16_t)((int32_t)0x25AC1FF2 >> 16), (int16_t)0x25AC1FF2, - (int16_t)((int32_t)0x2412F251 >> 16), (int16_t)0x2412F251, - (int16_t)((int32_t)0x1F91CA46 >> 16), (int16_t)0x1F91CA46, - (int16_t)((int32_t)0x18F55C90 >> 16), (int16_t)0x18F55C90, - - (int16_t)((int32_t)0xEEA4E12E >> 16), (int16_t)0xEEA4E12E, - (int16_t)((int32_t)0xF60FAF37 >> 16), (int16_t)0xF60FAF37, - (int16_t)((int32_t)0xFC4F91D4 >> 16), (int16_t)0xFC4F91D4, - (int16_t)((int32_t)0x00C8F2BC >> 16), (int16_t)0x00C8F2BC, - (int16_t)((int32_t)0x034FEE2C >> 16), (int16_t)0x034FEE2C, - (int16_t)((int32_t)0x041EEE40 >> 16), (int16_t)0x041EEE40, - (int16_t)((int32_t)0x03B23341 >> 16), (int16_t)0x03B23341, - (int16_t)((int32_t)0x029DBAA3 >> 16), (int16_t)0x029DBAA3, - - (int16_t)((int32_t)0xFE9A60BB >> 16), (int16_t)0xFE9A60BB, - (int16_t)((int32_t)0xFF9BB9D5 >> 16), (int16_t)0xFF9BB9D5, - (int16_t)((int32_t)0x003D239B >> 16), (int16_t)0x003D239B, - (int16_t)((int32_t)0x007F88E4 >> 16), (int16_t)0x007F88E4, - (int16_t)((int32_t)0x007DBCC8 >> 16), (int16_t)0x007DBCC8, - (int16_t)((int32_t)0x00599403 >> 16), (int16_t)0x00599403, - (int16_t)((int32_t)0x0030E2D3 >> 16), (int16_t)0x0030E2D3, - (int16_t)((int32_t)0x001194E6 >> 16), (int16_t)0x001194E6 -}; +const int16_t gas32CoeffFor4SBs[] = { + (int16_t)((int32_t)0x00000000 >> 16), (int16_t)0x00000000, + (int16_t)((int32_t)0x001194E6 >> 16), (int16_t)0x001194E6, + (int16_t)((int32_t)0x0030E2D3 >> 16), (int16_t)0x0030E2D3, + (int16_t)((int32_t)0x00599403 >> 16), (int16_t)0x00599403, + (int16_t)((int32_t)0x007DBCC8 >> 16), (int16_t)0x007DBCC8, + (int16_t)((int32_t)0x007F88E4 >> 16), (int16_t)0x007F88E4, + (int16_t)((int32_t)0x003D239B >> 16), (int16_t)0x003D239B, + (int16_t)((int32_t)0xFF9BB9D5 >> 16), (int16_t)0xFF9BB9D5, + + (int16_t)((int32_t)0x01659F45 >> 16), (int16_t)0x01659F45, + (int16_t)((int32_t)0x029DBAA3 >> 16), (int16_t)0x029DBAA3, + (int16_t)((int32_t)0x03B23341 >> 16), (int16_t)0x03B23341, + (int16_t)((int32_t)0x041EEE40 >> 16), (int16_t)0x041EEE40, + (int16_t)((int32_t)0x034FEE2C >> 16), (int16_t)0x034FEE2C, + (int16_t)((int32_t)0x00C8F2BC >> 16), (int16_t)0x00C8F2BC, + (int16_t)((int32_t)0xFC4F91D4 >> 16), (int16_t)0xFC4F91D4, + (int16_t)((int32_t)0xF60FAF37 >> 16), (int16_t)0xF60FAF37, + + (int16_t)((int32_t)0x115B1ED2 >> 16), (int16_t)0x115B1ED2, + (int16_t)((int32_t)0x18F55C90 >> 16), (int16_t)0x18F55C90, + (int16_t)((int32_t)0x1F91CA46 >> 16), (int16_t)0x1F91CA46, + (int16_t)((int32_t)0x2412F251 >> 16), (int16_t)0x2412F251, + (int16_t)((int32_t)0x25AC1FF2 >> 16), (int16_t)0x25AC1FF2, + (int16_t)((int32_t)0x2412F251 >> 16), (int16_t)0x2412F251, + (int16_t)((int32_t)0x1F91CA46 >> 16), (int16_t)0x1F91CA46, + (int16_t)((int32_t)0x18F55C90 >> 16), (int16_t)0x18F55C90, + + (int16_t)((int32_t)0xEEA4E12E >> 16), (int16_t)0xEEA4E12E, + (int16_t)((int32_t)0xF60FAF37 >> 16), (int16_t)0xF60FAF37, + (int16_t)((int32_t)0xFC4F91D4 >> 16), (int16_t)0xFC4F91D4, + (int16_t)((int32_t)0x00C8F2BC >> 16), (int16_t)0x00C8F2BC, + (int16_t)((int32_t)0x034FEE2C >> 16), (int16_t)0x034FEE2C, + (int16_t)((int32_t)0x041EEE40 >> 16), (int16_t)0x041EEE40, + (int16_t)((int32_t)0x03B23341 >> 16), (int16_t)0x03B23341, + (int16_t)((int32_t)0x029DBAA3 >> 16), (int16_t)0x029DBAA3, + + (int16_t)((int32_t)0xFE9A60BB >> 16), (int16_t)0xFE9A60BB, + (int16_t)((int32_t)0xFF9BB9D5 >> 16), (int16_t)0xFF9BB9D5, + (int16_t)((int32_t)0x003D239B >> 16), (int16_t)0x003D239B, + (int16_t)((int32_t)0x007F88E4 >> 16), (int16_t)0x007F88E4, + (int16_t)((int32_t)0x007DBCC8 >> 16), (int16_t)0x007DBCC8, + (int16_t)((int32_t)0x00599403 >> 16), (int16_t)0x00599403, + (int16_t)((int32_t)0x0030E2D3 >> 16), (int16_t)0x0030E2D3, + (int16_t)((int32_t)0x001194E6 >> 16), (int16_t)0x001194E6}; /*Window coeff for 8 sub band case*/ -const int16_t gas32CoeffFor8SBs[] = -{ - (int16_t)((int32_t)0x00000000 >>16), (int16_t)0x00000000, - (int16_t)((int32_t)0x00052173 >>16), (int16_t)0x00052173, - (int16_t)((int32_t)0x000B3F71 >>16), (int16_t)0x000B3F71, - (int16_t)((int32_t)0x00122C7D >>16), (int16_t)0x00122C7D, - (int16_t)((int32_t)0x001AFF89 >>16), (int16_t)0x001AFF89, - (int16_t)((int32_t)0x00255A62 >>16), (int16_t)0x00255A62, - (int16_t)((int32_t)0x003060F4 >>16), (int16_t)0x003060F4, - (int16_t)((int32_t)0x003A72E7 >>16), (int16_t)0x003A72E7, - - (int16_t)((int32_t)0x0041EC6A >>16), (int16_t)0x0041EC6A, /* 8 */ - (int16_t)((int32_t)0x0044EF48 >>16), (int16_t)0x0044EF48, - (int16_t)((int32_t)0x00415B75 >>16), (int16_t)0x00415B75, - (int16_t)((int32_t)0x0034F8B6 >>16), (int16_t)0x0034F8B6, - (int16_t)((int32_t)0x001D8FD2 >>16), (int16_t)0x001D8FD2, - (int16_t)((int32_t)0xFFFA2413 >>16), (int16_t)0xFFFA2413, - (int16_t)((int32_t)0xFFC9F10E >>16), (int16_t)0xFFC9F10E, - (int16_t)((int32_t)0xFF8D6793 >>16), (int16_t)0xFF8D6793, - - (int16_t)((int32_t)0x00B97348 >>16), (int16_t)0x00B97348, /* 16 */ - (int16_t)((int32_t)0x01071B96 >>16), (int16_t)0x01071B96, - (int16_t)((int32_t)0x0156B3CA >>16), (int16_t)0x0156B3CA, - (int16_t)((int32_t)0x01A1B38B >>16), (int16_t)0x01A1B38B, - (int16_t)((int32_t)0x01E0224C >>16), (int16_t)0x01E0224C, - (int16_t)((int32_t)0x0209291F >>16), (int16_t)0x0209291F, - (int16_t)((int32_t)0x02138653 >>16), (int16_t)0x02138653, - (int16_t)((int32_t)0x01F5F424 >>16), (int16_t)0x01F5F424, - - (int16_t)((int32_t)0x01A7ECEF >>16), (int16_t)0x01A7ECEF, /* 24 */ - (int16_t)((int32_t)0x01223EBA >>16), (int16_t)0x01223EBA, - (int16_t)((int32_t)0x005FD0FF >>16), (int16_t)0x005FD0FF, - (int16_t)((int32_t)0xFF5EEB73 >>16), (int16_t)0xFF5EEB73, - (int16_t)((int32_t)0xFE20435D >>16), (int16_t)0xFE20435D, - (int16_t)((int32_t)0xFCA86E7E >>16), (int16_t)0xFCA86E7E, - (int16_t)((int32_t)0xFAFF95FC >>16), (int16_t)0xFAFF95FC, - (int16_t)((int32_t)0xF9312891 >>16), (int16_t)0xF9312891, - - (int16_t)((int32_t)0x08B4307A >>16), (int16_t)0x08B4307A, /* 32 */ - (int16_t)((int32_t)0x0A9F3E9A >>16), (int16_t)0x0A9F3E9A, - (int16_t)((int32_t)0x0C7D59B6 >>16), (int16_t)0x0C7D59B6, - (int16_t)((int32_t)0x0E3BB16F >>16), (int16_t)0x0E3BB16F, - (int16_t)((int32_t)0x0FC721F9 >>16), (int16_t)0x0FC721F9, - (int16_t)((int32_t)0x110ECEF0 >>16), (int16_t)0x110ECEF0, - (int16_t)((int32_t)0x120435FA >>16), (int16_t)0x120435FA, - (int16_t)((int32_t)0x129C226F >>16), (int16_t)0x129C226F, - - (int16_t)((int32_t)0x12CF6C75 >>16), (int16_t)0x12CF6C75, /* 40 */ - (int16_t)((int32_t)0x129C226F >>16), (int16_t)0x129C226F, - (int16_t)((int32_t)0x120435FA >>16), (int16_t)0x120435FA, - (int16_t)((int32_t)0x110ECEF0 >>16), (int16_t)0x110ECEF0, - (int16_t)((int32_t)0x0FC721F9 >>16), (int16_t)0x0FC721F9, - (int16_t)((int32_t)0x0E3BB16F >>16), (int16_t)0x0E3BB16F, - (int16_t)((int32_t)0x0C7D59B6 >>16), (int16_t)0x0C7D59B6, - (int16_t)((int32_t)0x0A9F3E9A >>16), (int16_t)0x0A9F3E9A, - - (int16_t)((int32_t)0xF74BCF86 >>16), (int16_t)0xF74BCF86, /* 48 */ - (int16_t)((int32_t)0xF9312891 >>16), (int16_t)0xF9312891, - (int16_t)((int32_t)0xFAFF95FC >>16), (int16_t)0xFAFF95FC, - (int16_t)((int32_t)0xFCA86E7E >>16), (int16_t)0xFCA86E7E, - (int16_t)((int32_t)0xFE20435D >>16), (int16_t)0xFE20435D, - (int16_t)((int32_t)0xFF5EEB73 >>16), (int16_t)0xFF5EEB73, - (int16_t)((int32_t)0x005FD0FF >>16), (int16_t)0x005FD0FF, - (int16_t)((int32_t)0x01223EBA >>16), (int16_t)0x01223EBA, - - (int16_t)((int32_t)0x01A7ECEF >>16), (int16_t)0x01A7ECEF, /* 56 */ - (int16_t)((int32_t)0x01F5F424 >>16), (int16_t)0x01F5F424, - (int16_t)((int32_t)0x02138653 >>16), (int16_t)0x02138653, - (int16_t)((int32_t)0x0209291F >>16), (int16_t)0x0209291F, - (int16_t)((int32_t)0x01E0224C >>16), (int16_t)0x01E0224C, - (int16_t)((int32_t)0x01A1B38B >>16), (int16_t)0x01A1B38B, - (int16_t)((int32_t)0x0156B3CA >>16), (int16_t)0x0156B3CA, - (int16_t)((int32_t)0x01071B96 >>16), (int16_t)0x01071B96, - - (int16_t)((int32_t)0xFF468CB8 >>16), (int16_t)0xFF468CB8, /* 64 */ - (int16_t)((int32_t)0xFF8D6793 >>16), (int16_t)0xFF8D6793, - (int16_t)((int32_t)0xFFC9F10E >>16), (int16_t)0xFFC9F10E, - (int16_t)((int32_t)0xFFFA2413 >>16), (int16_t)0xFFFA2413, - (int16_t)((int32_t)0x001D8FD2 >>16), (int16_t)0x001D8FD2, - (int16_t)((int32_t)0x0034F8B6 >>16), (int16_t)0x0034F8B6, - (int16_t)((int32_t)0x00415B75 >>16), (int16_t)0x00415B75, - (int16_t)((int32_t)0x0044EF48 >>16), (int16_t)0x0044EF48, - - (int16_t)((int32_t)0x0041EC6A >>16), (int16_t)0x0041EC6A, /* 72 */ - (int16_t)((int32_t)0x003A72E7 >>16), (int16_t)0x003A72E7, - (int16_t)((int32_t)0x003060F4 >>16), (int16_t)0x003060F4, - (int16_t)((int32_t)0x00255A62 >>16), (int16_t)0x00255A62, - (int16_t)((int32_t)0x001AFF89 >>16), (int16_t)0x001AFF89, - (int16_t)((int32_t)0x00122C7D >>16), (int16_t)0x00122C7D, - (int16_t)((int32_t)0x000B3F71 >>16), (int16_t)0x000B3F71, - (int16_t)((int32_t)0x00052173 >>16), (int16_t)0x00052173 -}; +const int16_t gas32CoeffFor8SBs[] = { + (int16_t)((int32_t)0x00000000 >> 16), (int16_t)0x00000000, + (int16_t)((int32_t)0x00052173 >> 16), (int16_t)0x00052173, + (int16_t)((int32_t)0x000B3F71 >> 16), (int16_t)0x000B3F71, + (int16_t)((int32_t)0x00122C7D >> 16), (int16_t)0x00122C7D, + (int16_t)((int32_t)0x001AFF89 >> 16), (int16_t)0x001AFF89, + (int16_t)((int32_t)0x00255A62 >> 16), (int16_t)0x00255A62, + (int16_t)((int32_t)0x003060F4 >> 16), (int16_t)0x003060F4, + (int16_t)((int32_t)0x003A72E7 >> 16), (int16_t)0x003A72E7, + + (int16_t)((int32_t)0x0041EC6A >> 16), (int16_t)0x0041EC6A, /* 8 */ + (int16_t)((int32_t)0x0044EF48 >> 16), (int16_t)0x0044EF48, + (int16_t)((int32_t)0x00415B75 >> 16), (int16_t)0x00415B75, + (int16_t)((int32_t)0x0034F8B6 >> 16), (int16_t)0x0034F8B6, + (int16_t)((int32_t)0x001D8FD2 >> 16), (int16_t)0x001D8FD2, + (int16_t)((int32_t)0xFFFA2413 >> 16), (int16_t)0xFFFA2413, + (int16_t)((int32_t)0xFFC9F10E >> 16), (int16_t)0xFFC9F10E, + (int16_t)((int32_t)0xFF8D6793 >> 16), (int16_t)0xFF8D6793, + + (int16_t)((int32_t)0x00B97348 >> 16), (int16_t)0x00B97348, /* 16 */ + (int16_t)((int32_t)0x01071B96 >> 16), (int16_t)0x01071B96, + (int16_t)((int32_t)0x0156B3CA >> 16), (int16_t)0x0156B3CA, + (int16_t)((int32_t)0x01A1B38B >> 16), (int16_t)0x01A1B38B, + (int16_t)((int32_t)0x01E0224C >> 16), (int16_t)0x01E0224C, + (int16_t)((int32_t)0x0209291F >> 16), (int16_t)0x0209291F, + (int16_t)((int32_t)0x02138653 >> 16), (int16_t)0x02138653, + (int16_t)((int32_t)0x01F5F424 >> 16), (int16_t)0x01F5F424, + + (int16_t)((int32_t)0x01A7ECEF >> 16), (int16_t)0x01A7ECEF, /* 24 */ + (int16_t)((int32_t)0x01223EBA >> 16), (int16_t)0x01223EBA, + (int16_t)((int32_t)0x005FD0FF >> 16), (int16_t)0x005FD0FF, + (int16_t)((int32_t)0xFF5EEB73 >> 16), (int16_t)0xFF5EEB73, + (int16_t)((int32_t)0xFE20435D >> 16), (int16_t)0xFE20435D, + (int16_t)((int32_t)0xFCA86E7E >> 16), (int16_t)0xFCA86E7E, + (int16_t)((int32_t)0xFAFF95FC >> 16), (int16_t)0xFAFF95FC, + (int16_t)((int32_t)0xF9312891 >> 16), (int16_t)0xF9312891, + + (int16_t)((int32_t)0x08B4307A >> 16), (int16_t)0x08B4307A, /* 32 */ + (int16_t)((int32_t)0x0A9F3E9A >> 16), (int16_t)0x0A9F3E9A, + (int16_t)((int32_t)0x0C7D59B6 >> 16), (int16_t)0x0C7D59B6, + (int16_t)((int32_t)0x0E3BB16F >> 16), (int16_t)0x0E3BB16F, + (int16_t)((int32_t)0x0FC721F9 >> 16), (int16_t)0x0FC721F9, + (int16_t)((int32_t)0x110ECEF0 >> 16), (int16_t)0x110ECEF0, + (int16_t)((int32_t)0x120435FA >> 16), (int16_t)0x120435FA, + (int16_t)((int32_t)0x129C226F >> 16), (int16_t)0x129C226F, + + (int16_t)((int32_t)0x12CF6C75 >> 16), (int16_t)0x12CF6C75, /* 40 */ + (int16_t)((int32_t)0x129C226F >> 16), (int16_t)0x129C226F, + (int16_t)((int32_t)0x120435FA >> 16), (int16_t)0x120435FA, + (int16_t)((int32_t)0x110ECEF0 >> 16), (int16_t)0x110ECEF0, + (int16_t)((int32_t)0x0FC721F9 >> 16), (int16_t)0x0FC721F9, + (int16_t)((int32_t)0x0E3BB16F >> 16), (int16_t)0x0E3BB16F, + (int16_t)((int32_t)0x0C7D59B6 >> 16), (int16_t)0x0C7D59B6, + (int16_t)((int32_t)0x0A9F3E9A >> 16), (int16_t)0x0A9F3E9A, + + (int16_t)((int32_t)0xF74BCF86 >> 16), (int16_t)0xF74BCF86, /* 48 */ + (int16_t)((int32_t)0xF9312891 >> 16), (int16_t)0xF9312891, + (int16_t)((int32_t)0xFAFF95FC >> 16), (int16_t)0xFAFF95FC, + (int16_t)((int32_t)0xFCA86E7E >> 16), (int16_t)0xFCA86E7E, + (int16_t)((int32_t)0xFE20435D >> 16), (int16_t)0xFE20435D, + (int16_t)((int32_t)0xFF5EEB73 >> 16), (int16_t)0xFF5EEB73, + (int16_t)((int32_t)0x005FD0FF >> 16), (int16_t)0x005FD0FF, + (int16_t)((int32_t)0x01223EBA >> 16), (int16_t)0x01223EBA, + + (int16_t)((int32_t)0x01A7ECEF >> 16), (int16_t)0x01A7ECEF, /* 56 */ + (int16_t)((int32_t)0x01F5F424 >> 16), (int16_t)0x01F5F424, + (int16_t)((int32_t)0x02138653 >> 16), (int16_t)0x02138653, + (int16_t)((int32_t)0x0209291F >> 16), (int16_t)0x0209291F, + (int16_t)((int32_t)0x01E0224C >> 16), (int16_t)0x01E0224C, + (int16_t)((int32_t)0x01A1B38B >> 16), (int16_t)0x01A1B38B, + (int16_t)((int32_t)0x0156B3CA >> 16), (int16_t)0x0156B3CA, + (int16_t)((int32_t)0x01071B96 >> 16), (int16_t)0x01071B96, + + (int16_t)((int32_t)0xFF468CB8 >> 16), (int16_t)0xFF468CB8, /* 64 */ + (int16_t)((int32_t)0xFF8D6793 >> 16), (int16_t)0xFF8D6793, + (int16_t)((int32_t)0xFFC9F10E >> 16), (int16_t)0xFFC9F10E, + (int16_t)((int32_t)0xFFFA2413 >> 16), (int16_t)0xFFFA2413, + (int16_t)((int32_t)0x001D8FD2 >> 16), (int16_t)0x001D8FD2, + (int16_t)((int32_t)0x0034F8B6 >> 16), (int16_t)0x0034F8B6, + (int16_t)((int32_t)0x00415B75 >> 16), (int16_t)0x00415B75, + (int16_t)((int32_t)0x0044EF48 >> 16), (int16_t)0x0044EF48, + + (int16_t)((int32_t)0x0041EC6A >> 16), (int16_t)0x0041EC6A, /* 72 */ + (int16_t)((int32_t)0x003A72E7 >> 16), (int16_t)0x003A72E7, + (int16_t)((int32_t)0x003060F4 >> 16), (int16_t)0x003060F4, + (int16_t)((int32_t)0x00255A62 >> 16), (int16_t)0x00255A62, + (int16_t)((int32_t)0x001AFF89 >> 16), (int16_t)0x001AFF89, + (int16_t)((int32_t)0x00122C7D >> 16), (int16_t)0x00122C7D, + (int16_t)((int32_t)0x000B3F71 >> 16), (int16_t)0x000B3F71, + (int16_t)((int32_t)0x00052173 >> 16), (int16_t)0x00052173}; #else /*Window coeff for 4 sub band case*/ -const int32_t gas32CoeffFor4SBs[] = -{ - (int32_t)0x00000000, - (int32_t)0x001194E6, - (int32_t)0x0030E2D3, - (int32_t)0x00599403, - (int32_t)0x007DBCC8, - (int32_t)0x007F88E4, - (int32_t)0x003D239B, - (int32_t)0xFF9BB9D5, - - (int32_t)0x01659F45, - (int32_t)0x029DBAA3, - (int32_t)0x03B23341, - (int32_t)0x041EEE40, - (int32_t)0x034FEE2C, - (int32_t)0x00C8F2BC, - (int32_t)0xFC4F91D4, - (int32_t)0xF60FAF37, - - (int32_t)0x115B1ED2, - (int32_t)0x18F55C90, - (int32_t)0x1F91CA46, - (int32_t)0x2412F251, - (int32_t)0x25AC1FF2, - (int32_t)0x2412F251, - (int32_t)0x1F91CA46, - (int32_t)0x18F55C90, - - (int32_t)0xEEA4E12E, - (int32_t)0xF60FAF37, - (int32_t)0xFC4F91D4, - (int32_t)0x00C8F2BC, - (int32_t)0x034FEE2C, - (int32_t)0x041EEE40, - (int32_t)0x03B23341, - (int32_t)0x029DBAA3, - - (int32_t)0xFE9A60BB, - (int32_t)0xFF9BB9D5, - (int32_t)0x003D239B, - (int32_t)0x007F88E4, - (int32_t)0x007DBCC8, - (int32_t)0x00599403, - (int32_t)0x0030E2D3, - (int32_t)0x001194E6 -}; +const int32_t gas32CoeffFor4SBs[] = { + (int32_t)0x00000000, (int32_t)0x001194E6, (int32_t)0x0030E2D3, + (int32_t)0x00599403, (int32_t)0x007DBCC8, (int32_t)0x007F88E4, + (int32_t)0x003D239B, (int32_t)0xFF9BB9D5, + + (int32_t)0x01659F45, (int32_t)0x029DBAA3, (int32_t)0x03B23341, + (int32_t)0x041EEE40, (int32_t)0x034FEE2C, (int32_t)0x00C8F2BC, + (int32_t)0xFC4F91D4, (int32_t)0xF60FAF37, + + (int32_t)0x115B1ED2, (int32_t)0x18F55C90, (int32_t)0x1F91CA46, + (int32_t)0x2412F251, (int32_t)0x25AC1FF2, (int32_t)0x2412F251, + (int32_t)0x1F91CA46, (int32_t)0x18F55C90, + + (int32_t)0xEEA4E12E, (int32_t)0xF60FAF37, (int32_t)0xFC4F91D4, + (int32_t)0x00C8F2BC, (int32_t)0x034FEE2C, (int32_t)0x041EEE40, + (int32_t)0x03B23341, (int32_t)0x029DBAA3, + + (int32_t)0xFE9A60BB, (int32_t)0xFF9BB9D5, (int32_t)0x003D239B, + (int32_t)0x007F88E4, (int32_t)0x007DBCC8, (int32_t)0x00599403, + (int32_t)0x0030E2D3, (int32_t)0x001194E6}; /*Window coeff for 8 sub band case*/ -const int32_t gas32CoeffFor8SBs[] = -{ - (int32_t)0x00000000, - (int32_t)0x00052173, - (int32_t)0x000B3F71, - (int32_t)0x00122C7D, - (int32_t)0x001AFF89, - (int32_t)0x00255A62, - (int32_t)0x003060F4, - (int32_t)0x003A72E7, - - (int32_t)0x0041EC6A, /* 8 */ - (int32_t)0x0044EF48, - (int32_t)0x00415B75, - (int32_t)0x0034F8B6, - (int32_t)0x001D8FD2, - (int32_t)0xFFFA2413, - (int32_t)0xFFC9F10E, - (int32_t)0xFF8D6793, - - (int32_t)0x00B97348, /* 16 */ - (int32_t)0x01071B96, - (int32_t)0x0156B3CA, - (int32_t)0x01A1B38B, - (int32_t)0x01E0224C, - (int32_t)0x0209291F, - (int32_t)0x02138653, - (int32_t)0x01F5F424, - - (int32_t)0x01A7ECEF, /* 24 */ - (int32_t)0x01223EBA, - (int32_t)0x005FD0FF, - (int32_t)0xFF5EEB73, - (int32_t)0xFE20435D, - (int32_t)0xFCA86E7E, - (int32_t)0xFAFF95FC, - (int32_t)0xF9312891, - - (int32_t)0x08B4307A, /* 32 */ - (int32_t)0x0A9F3E9A, - (int32_t)0x0C7D59B6, - (int32_t)0x0E3BB16F, - (int32_t)0x0FC721F9, - (int32_t)0x110ECEF0, - (int32_t)0x120435FA, - (int32_t)0x129C226F, - - (int32_t)0x12CF6C75, /* 40 */ - (int32_t)0x129C226F, - (int32_t)0x120435FA, - (int32_t)0x110ECEF0, - (int32_t)0x0FC721F9, - (int32_t)0x0E3BB16F, - (int32_t)0x0C7D59B6, - (int32_t)0x0A9F3E9A, - - (int32_t)0xF74BCF86, /* 48 */ - (int32_t)0xF9312891, - (int32_t)0xFAFF95FC, - (int32_t)0xFCA86E7E, - (int32_t)0xFE20435D, - (int32_t)0xFF5EEB73, - (int32_t)0x005FD0FF, - (int32_t)0x01223EBA, - - (int32_t)0x01A7ECEF, /* 56 */ - (int32_t)0x01F5F424, - (int32_t)0x02138653, - (int32_t)0x0209291F, - (int32_t)0x01E0224C, - (int32_t)0x01A1B38B, - (int32_t)0x0156B3CA, - (int32_t)0x01071B96, - - (int32_t)0xFF468CB8, /* 64 */ - (int32_t)0xFF8D6793, - (int32_t)0xFFC9F10E, - (int32_t)0xFFFA2413, - (int32_t)0x001D8FD2, - (int32_t)0x0034F8B6, - (int32_t)0x00415B75, - (int32_t)0x0044EF48, - - (int32_t)0x0041EC6A, /* 72 */ - (int32_t)0x003A72E7, - (int32_t)0x003060F4, - (int32_t)0x00255A62, - (int32_t)0x001AFF89, - (int32_t)0x00122C7D, - (int32_t)0x000B3F71, - (int32_t)0x00052173 -}; +const int32_t gas32CoeffFor8SBs[] = { + (int32_t)0x00000000, (int32_t)0x00052173, (int32_t)0x000B3F71, + (int32_t)0x00122C7D, (int32_t)0x001AFF89, (int32_t)0x00255A62, + (int32_t)0x003060F4, (int32_t)0x003A72E7, + + (int32_t)0x0041EC6A, /* 8 */ + (int32_t)0x0044EF48, (int32_t)0x00415B75, (int32_t)0x0034F8B6, + (int32_t)0x001D8FD2, (int32_t)0xFFFA2413, (int32_t)0xFFC9F10E, + (int32_t)0xFF8D6793, + + (int32_t)0x00B97348, /* 16 */ + (int32_t)0x01071B96, (int32_t)0x0156B3CA, (int32_t)0x01A1B38B, + (int32_t)0x01E0224C, (int32_t)0x0209291F, (int32_t)0x02138653, + (int32_t)0x01F5F424, + + (int32_t)0x01A7ECEF, /* 24 */ + (int32_t)0x01223EBA, (int32_t)0x005FD0FF, (int32_t)0xFF5EEB73, + (int32_t)0xFE20435D, (int32_t)0xFCA86E7E, (int32_t)0xFAFF95FC, + (int32_t)0xF9312891, + + (int32_t)0x08B4307A, /* 32 */ + (int32_t)0x0A9F3E9A, (int32_t)0x0C7D59B6, (int32_t)0x0E3BB16F, + (int32_t)0x0FC721F9, (int32_t)0x110ECEF0, (int32_t)0x120435FA, + (int32_t)0x129C226F, + + (int32_t)0x12CF6C75, /* 40 */ + (int32_t)0x129C226F, (int32_t)0x120435FA, (int32_t)0x110ECEF0, + (int32_t)0x0FC721F9, (int32_t)0x0E3BB16F, (int32_t)0x0C7D59B6, + (int32_t)0x0A9F3E9A, + + (int32_t)0xF74BCF86, /* 48 */ + (int32_t)0xF9312891, (int32_t)0xFAFF95FC, (int32_t)0xFCA86E7E, + (int32_t)0xFE20435D, (int32_t)0xFF5EEB73, (int32_t)0x005FD0FF, + (int32_t)0x01223EBA, + + (int32_t)0x01A7ECEF, /* 56 */ + (int32_t)0x01F5F424, (int32_t)0x02138653, (int32_t)0x0209291F, + (int32_t)0x01E0224C, (int32_t)0x01A1B38B, (int32_t)0x0156B3CA, + (int32_t)0x01071B96, + + (int32_t)0xFF468CB8, /* 64 */ + (int32_t)0xFF8D6793, (int32_t)0xFFC9F10E, (int32_t)0xFFFA2413, + (int32_t)0x001D8FD2, (int32_t)0x0034F8B6, (int32_t)0x00415B75, + (int32_t)0x0044EF48, + + (int32_t)0x0041EC6A, /* 72 */ + (int32_t)0x003A72E7, (int32_t)0x003060F4, (int32_t)0x00255A62, + (int32_t)0x001AFF89, (int32_t)0x00122C7D, (int32_t)0x000B3F71, + (int32_t)0x00052173}; #endif #endif - diff --git a/embdrv/sbc/encoder/srce/sbc_encoder.c b/embdrv/sbc/encoder/srce/sbc_encoder.c index 11ca62c4b..6d334b93e 100644 --- a/embdrv/sbc/encoder/srce/sbc_encoder.c +++ b/embdrv/sbc/encoder/srce/sbc_encoder.c @@ -22,157 +22,137 @@ * ******************************************************************************/ +#include "sbc_encoder.h" #include #include "bt_target.h" -#include "sbc_encoder.h" #include "sbc_enc_func_declare.h" int16_t EncMaxShiftCounter; #if (SBC_JOINT_STE_INCLUDED == TRUE) -int32_t s32LRDiff[SBC_MAX_NUM_OF_BLOCKS] = {0}; -int32_t s32LRSum[SBC_MAX_NUM_OF_BLOCKS] = {0}; +int32_t s32LRDiff[SBC_MAX_NUM_OF_BLOCKS] = {0}; +int32_t s32LRSum[SBC_MAX_NUM_OF_BLOCKS] = {0}; #endif -uint32_t SBC_Encode(SBC_ENC_PARAMS *pstrEncParams, int16_t *input, uint8_t *output) -{ - int32_t s32Ch; /* counter for ch*/ - int32_t s32Sb; /* counter for sub-band*/ - uint32_t u32Count, maxBit = 0; /* loop count*/ - int32_t s32MaxValue; /* temp variable to store max value */ - - int16_t *ps16ScfL; - int32_t *SbBuffer; - int32_t s32Blk; /* counter for block*/ - int32_t s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; +uint32_t SBC_Encode(SBC_ENC_PARAMS* pstrEncParams, int16_t* input, + uint8_t* output) { + int32_t s32Ch; /* counter for ch*/ + int32_t s32Sb; /* counter for sub-band*/ + uint32_t u32Count, maxBit = 0; /* loop count*/ + int32_t s32MaxValue; /* temp variable to store max value */ + + int16_t* ps16ScfL; + int32_t* SbBuffer; + int32_t s32Blk; /* counter for block*/ + int32_t s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; #if (SBC_JOINT_STE_INCLUDED == TRUE) - int32_t s32MaxValue2; - uint32_t u32CountSum,u32CountDiff; - int32_t *pSum, *pDiff; + int32_t s32MaxValue2; + uint32_t u32CountSum, u32CountDiff; + int32_t *pSum, *pDiff; #endif - register int32_t s32NumOfSubBands = pstrEncParams->s16NumOfSubBands; - - /* SBC ananlysis filter*/ - if (s32NumOfSubBands == 4) - SbcAnalysisFilter4(pstrEncParams, input); - else - SbcAnalysisFilter8(pstrEncParams, input); - - /* compute the scale factor, and save the max */ - ps16ScfL = pstrEncParams->as16ScaleFactor; - s32Ch=pstrEncParams->s16NumOfChannels*s32NumOfSubBands; - - for (s32Sb=0; s32Sbs32SbBuffer+s32Sb; - s32MaxValue=0; - for (s32Blk=s32NumOfBlocks;s32Blk>0;s32Blk--) - { - if (s32MaxValue 0x800000) ? 9 : 0; + register int32_t s32NumOfSubBands = pstrEncParams->s16NumOfSubBands; + + /* SBC ananlysis filter*/ + if (s32NumOfSubBands == 4) + SbcAnalysisFilter4(pstrEncParams, input); + else + SbcAnalysisFilter8(pstrEncParams, input); + + /* compute the scale factor, and save the max */ + ps16ScfL = pstrEncParams->as16ScaleFactor; + s32Ch = pstrEncParams->s16NumOfChannels * s32NumOfSubBands; + + for (s32Sb = 0; s32Sb < s32Ch; s32Sb++) { + SbBuffer = pstrEncParams->s32SbBuffer + s32Sb; + s32MaxValue = 0; + for (s32Blk = s32NumOfBlocks; s32Blk > 0; s32Blk--) { + if (s32MaxValue < abs32(*SbBuffer)) s32MaxValue = abs32(*SbBuffer); + SbBuffer += s32Ch; + } - for ( ; u32Count < 15; u32Count++) - { - if (s32MaxValue <= (int32_t)(0x8000 << u32Count)) - break; - } - *ps16ScfL++ = (int16_t)u32Count; + u32Count = (s32MaxValue > 0x800000) ? 9 : 0; - if (u32Count > maxBit) - maxBit = u32Count; + for (; u32Count < 15; u32Count++) { + if (s32MaxValue <= (int32_t)(0x8000 << u32Count)) break; } - /* In case of JS processing,check whether to use JS */ + *ps16ScfL++ = (int16_t)u32Count; + + if (u32Count > maxBit) maxBit = u32Count; + } +/* In case of JS processing,check whether to use JS */ #if (SBC_JOINT_STE_INCLUDED == TRUE) - if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) - { - /* Calculate sum and differance scale factors for making JS decision */ - ps16ScfL = pstrEncParams->as16ScaleFactor ; - /* calculate the scale factor of Joint stereo max sum and diff */ - for (s32Sb = 0; s32Sb < s32NumOfSubBands-1; s32Sb++) - { - SbBuffer=pstrEncParams->s32SbBuffer+s32Sb; - s32MaxValue2=0; - s32MaxValue=0; - pSum = s32LRSum; - pDiff = s32LRDiff; - for (s32Blk=0;s32Blk>1; - if (abs32(*pSum)>s32MaxValue) - s32MaxValue=abs32(*pSum); - pSum++; - *pDiff=(*SbBuffer-*(SbBuffer+s32NumOfSubBands))>>1; - if (abs32(*pDiff)>s32MaxValue2) - s32MaxValue2=abs32(*pDiff); - pDiff++; - SbBuffer+=s32Ch; - } - u32Count = (s32MaxValue > 0x800000) ? 9 : 0; - for ( ; u32Count < 15; u32Count++) - { - if (s32MaxValue <= (int32_t)(0x8000 << u32Count)) - break; - } - u32CountSum=u32Count; - u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0; - for ( ; u32Count < 15; u32Count++) - { - if (s32MaxValue2 <= (int32_t)(0x8000 << u32Count)) - break; - } - u32CountDiff=u32Count; - if ( (*ps16ScfL + *(ps16ScfL+s32NumOfSubBands)) > (int16_t)(u32CountSum + u32CountDiff) ) - { - - if (u32CountSum > maxBit) - maxBit = u32CountSum; - - if (u32CountDiff > maxBit) - maxBit = u32CountDiff; - - *ps16ScfL = (int16_t)u32CountSum; - *(ps16ScfL+s32NumOfSubBands) = (int16_t)u32CountDiff; - - SbBuffer=pstrEncParams->s32SbBuffer+s32Sb; - pSum = s32LRSum; - pDiff = s32LRDiff; - - for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) - { - *SbBuffer = *pSum; - *(SbBuffer+s32NumOfSubBands) = *pDiff; - - SbBuffer += s32NumOfSubBands<<1; - pSum++; - pDiff++; - } - - pstrEncParams->as16Join[s32Sb] = 1; - } - else - { - pstrEncParams->as16Join[s32Sb] = 0; - } - ps16ScfL++; + if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) { + /* Calculate sum and differance scale factors for making JS decision */ + ps16ScfL = pstrEncParams->as16ScaleFactor; + /* calculate the scale factor of Joint stereo max sum and diff */ + for (s32Sb = 0; s32Sb < s32NumOfSubBands - 1; s32Sb++) { + SbBuffer = pstrEncParams->s32SbBuffer + s32Sb; + s32MaxValue2 = 0; + s32MaxValue = 0; + pSum = s32LRSum; + pDiff = s32LRDiff; + for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) { + *pSum = (*SbBuffer + *(SbBuffer + s32NumOfSubBands)) >> 1; + if (abs32(*pSum) > s32MaxValue) s32MaxValue = abs32(*pSum); + pSum++; + *pDiff = (*SbBuffer - *(SbBuffer + s32NumOfSubBands)) >> 1; + if (abs32(*pDiff) > s32MaxValue2) s32MaxValue2 = abs32(*pDiff); + pDiff++; + SbBuffer += s32Ch; + } + u32Count = (s32MaxValue > 0x800000) ? 9 : 0; + for (; u32Count < 15; u32Count++) { + if (s32MaxValue <= (int32_t)(0x8000 << u32Count)) break; + } + u32CountSum = u32Count; + u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0; + for (; u32Count < 15; u32Count++) { + if (s32MaxValue2 <= (int32_t)(0x8000 << u32Count)) break; + } + u32CountDiff = u32Count; + if ((*ps16ScfL + *(ps16ScfL + s32NumOfSubBands)) > + (int16_t)(u32CountSum + u32CountDiff)) { + if (u32CountSum > maxBit) maxBit = u32CountSum; + + if (u32CountDiff > maxBit) maxBit = u32CountDiff; + + *ps16ScfL = (int16_t)u32CountSum; + *(ps16ScfL + s32NumOfSubBands) = (int16_t)u32CountDiff; + + SbBuffer = pstrEncParams->s32SbBuffer + s32Sb; + pSum = s32LRSum; + pDiff = s32LRDiff; + + for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) { + *SbBuffer = *pSum; + *(SbBuffer + s32NumOfSubBands) = *pDiff; + + SbBuffer += s32NumOfSubBands << 1; + pSum++; + pDiff++; } + + pstrEncParams->as16Join[s32Sb] = 1; + } else { pstrEncParams->as16Join[s32Sb] = 0; + } + ps16ScfL++; } + pstrEncParams->as16Join[s32Sb] = 0; + } #endif - pstrEncParams->s16MaxBitNeed = (int16_t)maxBit; + pstrEncParams->s16MaxBitNeed = (int16_t)maxBit; - /* bit allocation */ - if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)) - sbc_enc_bit_alloc_ste(pstrEncParams); - else - sbc_enc_bit_alloc_mono(pstrEncParams); + /* bit allocation */ + if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || + (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)) + sbc_enc_bit_alloc_ste(pstrEncParams); + else + sbc_enc_bit_alloc_mono(pstrEncParams); - /* Quantize the encoded audio */ - return EncPacking(pstrEncParams, output); + /* Quantize the encoded audio */ + return EncPacking(pstrEncParams, output); } /**************************************************************************** @@ -180,106 +160,102 @@ uint32_t SBC_Encode(SBC_ENC_PARAMS *pstrEncParams, int16_t *input, uint8_t *outp * * RETURNS : N/A */ -void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams) -{ - uint16_t s16SamplingFreq; /*temp variable to store smpling freq*/ - int16_t s16Bitpool; /*to store bit pool value*/ - int16_t s16BitRate; /*to store bitrate*/ - int16_t s16FrameLen; /*to store frame length*/ - uint16_t HeaderParams; - - /* Required number of channels */ - if (pstrEncParams->s16ChannelMode == SBC_MONO) - pstrEncParams->s16NumOfChannels = 1; - else - pstrEncParams->s16NumOfChannels = 2; - - /* Bit pool calculation */ - if (pstrEncParams->s16SamplingFreq == SBC_sf16000) - s16SamplingFreq = 16000; - else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) - s16SamplingFreq = 32000; - else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) - s16SamplingFreq = 44100; +void SBC_Encoder_Init(SBC_ENC_PARAMS* pstrEncParams) { + uint16_t s16SamplingFreq; /*temp variable to store smpling freq*/ + int16_t s16Bitpool; /*to store bit pool value*/ + int16_t s16BitRate; /*to store bitrate*/ + int16_t s16FrameLen; /*to store frame length*/ + uint16_t HeaderParams; + + /* Required number of channels */ + if (pstrEncParams->s16ChannelMode == SBC_MONO) + pstrEncParams->s16NumOfChannels = 1; + else + pstrEncParams->s16NumOfChannels = 2; + + /* Bit pool calculation */ + if (pstrEncParams->s16SamplingFreq == SBC_sf16000) + s16SamplingFreq = 16000; + else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) + s16SamplingFreq = 32000; + else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) + s16SamplingFreq = 44100; + else + s16SamplingFreq = 48000; + + if ((pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) || + (pstrEncParams->s16ChannelMode == SBC_STEREO)) { + s16Bitpool = + (int16_t)((pstrEncParams->u16BitRate * pstrEncParams->s16NumOfSubBands * + 1000 / s16SamplingFreq) - + ((32 + (4 * pstrEncParams->s16NumOfSubBands * + pstrEncParams->s16NumOfChannels) + + ((pstrEncParams->s16ChannelMode - 2) * + pstrEncParams->s16NumOfSubBands)) / + pstrEncParams->s16NumOfBlocks)); + + s16FrameLen = 4 + + (4 * pstrEncParams->s16NumOfSubBands * + pstrEncParams->s16NumOfChannels) / + 8 + + (((pstrEncParams->s16ChannelMode - 2) * + pstrEncParams->s16NumOfSubBands) + + (pstrEncParams->s16NumOfBlocks * s16Bitpool)) / + 8; + + s16BitRate = (8 * s16FrameLen * s16SamplingFreq) / + (pstrEncParams->s16NumOfSubBands * + pstrEncParams->s16NumOfBlocks * 1000); + + if (s16BitRate > pstrEncParams->u16BitRate) s16Bitpool--; + + if (pstrEncParams->s16NumOfSubBands == 8) + pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool; else - s16SamplingFreq = 48000; - - if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) - || (pstrEncParams->s16ChannelMode == SBC_STEREO) ) - { - s16Bitpool = (int16_t)( (pstrEncParams->u16BitRate * - pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq) - -( (32 + (4 * pstrEncParams->s16NumOfSubBands * - pstrEncParams->s16NumOfChannels) - + ( (pstrEncParams->s16ChannelMode - 2) * - pstrEncParams->s16NumOfSubBands ) ) - / pstrEncParams->s16NumOfBlocks) ); - - s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands* - pstrEncParams->s16NumOfChannels)/8 - + ( ((pstrEncParams->s16ChannelMode - 2) * - pstrEncParams->s16NumOfSubBands) - + (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8; - - s16BitRate = (8 * s16FrameLen * s16SamplingFreq) - / (pstrEncParams->s16NumOfSubBands * - pstrEncParams->s16NumOfBlocks * 1000); - - if (s16BitRate > pstrEncParams->u16BitRate) - s16Bitpool--; - - if(pstrEncParams->s16NumOfSubBands == 8) - pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool; - else - pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool; - } + pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool; + } else { + s16Bitpool = (int16_t)( + ((pstrEncParams->s16NumOfSubBands * pstrEncParams->u16BitRate * 1000) / + (s16SamplingFreq * pstrEncParams->s16NumOfChannels)) - + (((32 / pstrEncParams->s16NumOfChannels) + + (4 * pstrEncParams->s16NumOfSubBands)) / + pstrEncParams->s16NumOfBlocks)); + + pstrEncParams->s16BitPool = + (s16Bitpool > (16 * pstrEncParams->s16NumOfSubBands)) + ? (16 * pstrEncParams->s16NumOfSubBands) + : s16Bitpool; + } + + if (pstrEncParams->s16BitPool < 0) pstrEncParams->s16BitPool = 0; + /* sampling freq */ + HeaderParams = ((pstrEncParams->s16SamplingFreq & 3) << 6); + + /* number of blocks*/ + HeaderParams |= (((pstrEncParams->s16NumOfBlocks - 4) & 12) << 2); + + /* channel mode: mono, dual...*/ + HeaderParams |= ((pstrEncParams->s16ChannelMode & 3) << 2); + + /* Loudness or SNR */ + HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1) << 1); + HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/ + pstrEncParams->FrameHeader = HeaderParams; + + if (pstrEncParams->s16NumOfSubBands == 4) { + if (pstrEncParams->s16NumOfChannels == 1) + EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10) >> 2) << 2; else - { - s16Bitpool = (int16_t)( ((pstrEncParams->s16NumOfSubBands * - pstrEncParams->u16BitRate * 1000) - / (s16SamplingFreq * pstrEncParams->s16NumOfChannels)) - -( ( (32 / pstrEncParams->s16NumOfChannels) + - (4 * pstrEncParams->s16NumOfSubBands) ) - / pstrEncParams->s16NumOfBlocks ) ); - - pstrEncParams->s16BitPool = (s16Bitpool > - (16 * pstrEncParams->s16NumOfSubBands)) - ? (16*pstrEncParams->s16NumOfSubBands) : s16Bitpool; - } - - if (pstrEncParams->s16BitPool < 0) - pstrEncParams->s16BitPool = 0; - /* sampling freq */ - HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6); - - /* number of blocks*/ - HeaderParams |= (((pstrEncParams->s16NumOfBlocks -4) & 12) << 2); - - /* channel mode: mono, dual...*/ - HeaderParams |= ((pstrEncParams->s16ChannelMode & 3)<< 2); - - /* Loudness or SNR */ - HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1)<< 1); - HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/ - pstrEncParams->FrameHeader=HeaderParams; - - if (pstrEncParams->s16NumOfSubBands==4) - { - if (pstrEncParams->s16NumOfChannels==1) - EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10)>>2)<<2; - else - EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10*2)>>3)<<2; - } + EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10 * 2) >> 3) << 2; + } else { + if (pstrEncParams->s16NumOfChannels == 1) + EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10) >> 3) << 3; else - { - if (pstrEncParams->s16NumOfChannels==1) - EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10)>>3)<<3; - else - EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10*2)>>4)<<3; - } + EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10 * 2) >> 4) << 3; + } - APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d", - pstrEncParams->u16BitRate, pstrEncParams->s16BitPool); + APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d", + pstrEncParams->u16BitRate, pstrEncParams->s16BitPool); - SbcAnalysisInit(); + SbcAnalysisInit(); } diff --git a/embdrv/sbc/encoder/srce/sbc_packing.c b/embdrv/sbc/encoder/srce/sbc_packing.c index 277eda822..5f36ab84f 100644 --- a/embdrv/sbc/encoder/srce/sbc_packing.c +++ b/embdrv/sbc/encoder/srce/sbc_packing.c @@ -22,252 +22,229 @@ * ******************************************************************************/ -#include "sbc_encoder.h" #include "sbc_enc_func_declare.h" +#include "sbc_encoder.h" #if (SBC_ARM_ASM_OPT == TRUE) -#define Mult32(s32In1,s32In2,s32OutLow) \ -{ \ - __asm \ - { \ - MUL s32OutLow,s32In1,s32In2; \ - } \ -} -#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \ -{ \ - __asm \ - { \ - SMULL s32OutLow,s32OutHi,s32In1,s32In2 \ - } \ -} +#define Mult32(s32In1, s32In2, s32OutLow) \ + { \ + __asm { \ + MUL s32OutLow,s32In1,s32In2; } \ + } +#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \ + { \ + __asm { \ + SMULL s32OutLow,s32OutHi,s32In1,s32In2 } \ + } #else -#define Mult32(s32In1,s32In2,s32OutLow) s32OutLow=(int32_t)(s32In1)*(int32_t)(s32In2); -#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \ -{ \ - (s32OutLow) = ((int32_t)(uint16_t)(s32In1) * (uint16_t)(s32In2)); \ - s32TempVal2 = (int32_t)(((s32In1) >> 16) * (uint16_t)(s32In2)); \ - s32Carry = ((((uint32_t)(s32OutLow)>>16)&0xFFFF) + \ - + (s32TempVal2 & 0xFFFF) ) >> 16; \ - (s32OutLow) += (s32TempVal2 << 16); \ - (s32OutHi) = (s32TempVal2 >> 16) + s32Carry; \ -} +#define Mult32(s32In1, s32In2, s32OutLow) \ + s32OutLow = (int32_t)(s32In1) * (int32_t)(s32In2); +#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \ + { \ + (s32OutLow) = ((int32_t)(uint16_t)(s32In1) * (uint16_t)(s32In2)); \ + s32TempVal2 = (int32_t)(((s32In1) >> 16) * (uint16_t)(s32In2)); \ + s32Carry = ((((uint32_t)(s32OutLow) >> 16) & 0xFFFF) + \ + +(s32TempVal2 & 0xFFFF)) >> \ + 16; \ + (s32OutLow) += (s32TempVal2 << 16); \ + (s32OutHi) = (s32TempVal2 >> 16) + s32Carry; \ + } #endif /* return number of bytes written to output */ -uint32_t EncPacking(SBC_ENC_PARAMS *pstrEncParams, uint8_t *output) -{ - uint8_t *pu8PacketPtr; /* packet ptr*/ - uint8_t Temp; - int32_t s32Blk; /* counter for block*/ - int32_t s32Ch; /* counter for channel*/ - int32_t s32Sb; /* counter for sub-band*/ - int32_t s32PresentBit; /* represents bit to be stored*/ - /*int32_t s32LoopCountI; loop counter*/ - int32_t s32LoopCountJ; /* loop counter*/ - uint32_t u32QuantizedSbValue,u32QuantizedSbValue0; /* temp variable to store quantized sb val*/ - int32_t s32LoopCount; /* loop counter*/ - uint8_t u8XoredVal; /* to store XORed value in CRC calculation*/ - uint8_t u8CRC; /* to store CRC value*/ - int16_t *ps16GenPtr; - int32_t s32NumOfBlocks; - int32_t s32NumOfSubBands = pstrEncParams->s16NumOfSubBands; - int32_t s32NumOfChannels = pstrEncParams->s16NumOfChannels; - uint32_t u32SfRaisedToPow2; /*scale factor raised to power 2*/ - int16_t *ps16ScfPtr; - int32_t *ps32SbPtr; - uint16_t u16Levels; /*to store levels*/ - int32_t s32Temp1; /*used in 64-bit multiplication*/ - int32_t s32Low; /*used in 64-bit multiplication*/ +uint32_t EncPacking(SBC_ENC_PARAMS* pstrEncParams, uint8_t* output) { + uint8_t* pu8PacketPtr; /* packet ptr*/ + uint8_t Temp; + int32_t s32Blk; /* counter for block*/ + int32_t s32Ch; /* counter for channel*/ + int32_t s32Sb; /* counter for sub-band*/ + int32_t s32PresentBit; /* represents bit to be stored*/ + /*int32_t s32LoopCountI; loop counter*/ + int32_t s32LoopCountJ; /* loop counter*/ + uint32_t u32QuantizedSbValue, + u32QuantizedSbValue0; /* temp variable to store quantized sb val*/ + int32_t s32LoopCount; /* loop counter*/ + uint8_t u8XoredVal; /* to store XORed value in CRC calculation*/ + uint8_t u8CRC; /* to store CRC value*/ + int16_t* ps16GenPtr; + int32_t s32NumOfBlocks; + int32_t s32NumOfSubBands = pstrEncParams->s16NumOfSubBands; + int32_t s32NumOfChannels = pstrEncParams->s16NumOfChannels; + uint32_t u32SfRaisedToPow2; /*scale factor raised to power 2*/ + int16_t* ps16ScfPtr; + int32_t* ps32SbPtr; + uint16_t u16Levels; /*to store levels*/ + int32_t s32Temp1; /*used in 64-bit multiplication*/ + int32_t s32Low; /*used in 64-bit multiplication*/ #if (SBC_IS_64_MULT_IN_QUANTIZER == TRUE) - int32_t s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2; + int32_t s32Hi1, s32Low1, s32Carry, s32TempVal2, s32Hi, s32Temp2; #endif - pu8PacketPtr = output; /*Initialize the ptr*/ - *pu8PacketPtr++ = (uint8_t)0x9C; /*Sync word*/ - *pu8PacketPtr++=(uint8_t)(pstrEncParams->FrameHeader); + pu8PacketPtr = output; /*Initialize the ptr*/ + *pu8PacketPtr++ = (uint8_t)0x9C; /*Sync word*/ + *pu8PacketPtr++ = (uint8_t)(pstrEncParams->FrameHeader); - *pu8PacketPtr = (uint8_t)(pstrEncParams->s16BitPool & 0x00FF); - pu8PacketPtr += 2; /*skip for CRC*/ + *pu8PacketPtr = (uint8_t)(pstrEncParams->s16BitPool & 0x00FF); + pu8PacketPtr += 2; /*skip for CRC*/ - /*here it indicate if it is byte boundary or nibble boundary*/ - s32PresentBit = 8; - Temp=0; + /*here it indicate if it is byte boundary or nibble boundary*/ + s32PresentBit = 8; + Temp = 0; #if (SBC_JOINT_STE_INCLUDED == TRUE) - if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) - { - /* pack join stero parameters */ - for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) - { - Temp <<= 1; - Temp |= pstrEncParams->as16Join[s32Sb]; - } + if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) { + /* pack join stero parameters */ + for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) { + Temp <<= 1; + Temp |= pstrEncParams->as16Join[s32Sb]; + } - /* pack RFA */ - if (s32NumOfSubBands == SUB_BANDS_4) - { - s32PresentBit = 4; - } - else - { - *(pu8PacketPtr++)=Temp; - Temp = 0; - } + /* pack RFA */ + if (s32NumOfSubBands == SUB_BANDS_4) { + s32PresentBit = 4; + } else { + *(pu8PacketPtr++) = Temp; + Temp = 0; } + } #endif - /* Pack Scale factor */ - ps16GenPtr = pstrEncParams->as16ScaleFactor; - s32Sb=s32NumOfChannels*s32NumOfSubBands; - /*Temp=*pu8PacketPtr;*/ - for (s32Ch = s32Sb; s32Ch >0; s32Ch--) - { - Temp<<= 4; - Temp |= *ps16GenPtr++; - - if(s32PresentBit == 4) - { - s32PresentBit = 8; - *(pu8PacketPtr++)=Temp; - Temp = 0; - } - else - { - s32PresentBit = 4; - } + /* Pack Scale factor */ + ps16GenPtr = pstrEncParams->as16ScaleFactor; + s32Sb = s32NumOfChannels * s32NumOfSubBands; + /*Temp=*pu8PacketPtr;*/ + for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) { + Temp <<= 4; + Temp |= *ps16GenPtr++; + + if (s32PresentBit == 4) { + s32PresentBit = 8; + *(pu8PacketPtr++) = Temp; + Temp = 0; + } else { + s32PresentBit = 4; } - - /* Pack samples */ - ps32SbPtr = pstrEncParams->s32SbBuffer; - /*Temp=*pu8PacketPtr;*/ - s32NumOfBlocks= pstrEncParams->s16NumOfBlocks; - for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--) - { - ps16GenPtr = pstrEncParams->as16Bits; - ps16ScfPtr = pstrEncParams->as16ScaleFactor; - for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--) - { - s32LoopCount = *ps16GenPtr++; - if (s32LoopCount != 0) - { + } + + /* Pack samples */ + ps32SbPtr = pstrEncParams->s32SbBuffer; + /*Temp=*pu8PacketPtr;*/ + s32NumOfBlocks = pstrEncParams->s16NumOfBlocks; + for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) { + ps16GenPtr = pstrEncParams->as16Bits; + ps16ScfPtr = pstrEncParams->as16ScaleFactor; + for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) { + s32LoopCount = *ps16GenPtr++; + if (s32LoopCount != 0) { #if (SBC_IS_64_MULT_IN_QUANTIZER == TRUE) - /* finding level from reconstruction part of decoder */ - u32SfRaisedToPow2 = ((uint32_t)1 << ((*ps16ScfPtr)+1)); - u16Levels = (uint16_t)(((uint32_t)1 << s32LoopCount) - 1); + /* finding level from reconstruction part of decoder */ + u32SfRaisedToPow2 = ((uint32_t)1 << ((*ps16ScfPtr) + 1)); + u16Levels = (uint16_t)(((uint32_t)1 << s32LoopCount) - 1); - /* quantizer */ - s32Temp1 = (*ps32SbPtr >> 2) + (u32SfRaisedToPow2 << 12); - s32Temp2 = u16Levels; + /* quantizer */ + s32Temp1 = (*ps32SbPtr >> 2) + (u32SfRaisedToPow2 << 12); + s32Temp2 = u16Levels; - Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi); + Mult64(s32Temp1, s32Temp2, s32Low, s32Hi); - s32Low1 = s32Low >> ((*ps16ScfPtr)+2); - s32Low1 &= ((uint32_t)1 << (32 - ((*ps16ScfPtr)+2))) - 1; - s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) +2)); + s32Low1 = s32Low >> ((*ps16ScfPtr) + 2); + s32Low1 &= ((uint32_t)1 << (32 - ((*ps16ScfPtr) + 2))) - 1; + s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) + 2)); - u32QuantizedSbValue0 = (uint16_t)((s32Low1 | s32Hi1) >> 12); + u32QuantizedSbValue0 = (uint16_t)((s32Low1 | s32Hi1) >> 12); #else - /* finding level from reconstruction part of decoder */ - u32SfRaisedToPow2 = ((uint32_t)1 << *ps16ScfPtr); - u16Levels = (uint16_t)(((uint32_t)1 << s32LoopCount)-1); - - /* quantizer */ - s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2; - Mult32(s32Temp1,u16Levels,s32Low); - s32Low>>= (*ps16ScfPtr+1); - u32QuantizedSbValue0 = (uint16_t)s32Low; + /* finding level from reconstruction part of decoder */ + u32SfRaisedToPow2 = ((uint32_t)1 << *ps16ScfPtr); + u16Levels = (uint16_t)(((uint32_t)1 << s32LoopCount) - 1); + + /* quantizer */ + s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2; + Mult32(s32Temp1, u16Levels, s32Low); + s32Low >>= (*ps16ScfPtr + 1); + u32QuantizedSbValue0 = (uint16_t)s32Low; #endif - /*store the number of bits required and the quantized s32Sb - sample to ease the coding*/ - u32QuantizedSbValue = u32QuantizedSbValue0; - - if(s32PresentBit >= s32LoopCount) - { - Temp <<= s32LoopCount; - Temp |= u32QuantizedSbValue; - s32PresentBit -= s32LoopCount; - } - else - { - while (s32PresentBit < s32LoopCount) - { - s32LoopCount -= s32PresentBit; - u32QuantizedSbValue >>= s32LoopCount; - - /*remove the unwanted msbs*/ - /*u32QuantizedSbValue <<= 16 - s32PresentBit; - u32QuantizedSbValue >>= 16 - s32PresentBit;*/ - - Temp <<= s32PresentBit; - - Temp |= u32QuantizedSbValue ; - /*restore the original*/ - u32QuantizedSbValue=u32QuantizedSbValue0; - - *(pu8PacketPtr++)=Temp; - Temp = 0; - s32PresentBit = 8; - } - Temp <<= s32LoopCount; + /*store the number of bits required and the quantized s32Sb + sample to ease the coding*/ + u32QuantizedSbValue = u32QuantizedSbValue0; + + if (s32PresentBit >= s32LoopCount) { + Temp <<= s32LoopCount; + Temp |= u32QuantizedSbValue; + s32PresentBit -= s32LoopCount; + } else { + while (s32PresentBit < s32LoopCount) { + s32LoopCount -= s32PresentBit; + u32QuantizedSbValue >>= s32LoopCount; + + /*remove the unwanted msbs*/ + /*u32QuantizedSbValue <<= 16 - s32PresentBit; + u32QuantizedSbValue >>= 16 - s32PresentBit;*/ + + Temp <<= s32PresentBit; + + Temp |= u32QuantizedSbValue; + /*restore the original*/ + u32QuantizedSbValue = u32QuantizedSbValue0; + + *(pu8PacketPtr++) = Temp; + Temp = 0; + s32PresentBit = 8; + } + Temp <<= s32LoopCount; - /* remove the unwanted msbs */ - /*u32QuantizedSbValue <<= 16 - s32LoopCount; - u32QuantizedSbValue >>= 16 - s32LoopCount;*/ + /* remove the unwanted msbs */ + /*u32QuantizedSbValue <<= 16 - s32LoopCount; + u32QuantizedSbValue >>= 16 - s32LoopCount;*/ - Temp |= u32QuantizedSbValue; + Temp |= u32QuantizedSbValue; - s32PresentBit -= s32LoopCount; - } - } - ps16ScfPtr++; - ps32SbPtr++; + s32PresentBit -= s32LoopCount; } + } + ps16ScfPtr++; + ps32SbPtr++; } - - Temp <<= s32PresentBit; - *pu8PacketPtr=Temp; - uint32_t u16PacketLength=pu8PacketPtr-output+1; - /*find CRC*/ - pu8PacketPtr = output+1; /*Initialize the ptr*/ - u8CRC = 0x0F; - s32LoopCount = s32Sb >> 1; - - /* - The loops is run from the start of the packet till the scale factor - parameters. In case of JS, 'join' parameter is included in the packet - so that many more bytes are included in CRC calculation. - */ - Temp=*pu8PacketPtr; - for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++) - { - /* skip sync word and CRC bytes */ - if (s32Ch != 3) - { - for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--) - { - u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01); - u8CRC <<= 1; - u8CRC ^= (u8XoredVal * 0x1D); - u8CRC &= 0xFF; - } - } - Temp=*(++pu8PacketPtr); + } + + Temp <<= s32PresentBit; + *pu8PacketPtr = Temp; + uint32_t u16PacketLength = pu8PacketPtr - output + 1; + /*find CRC*/ + pu8PacketPtr = output + 1; /*Initialize the ptr*/ + u8CRC = 0x0F; + s32LoopCount = s32Sb >> 1; + + /* + The loops is run from the start of the packet till the scale factor + parameters. In case of JS, 'join' parameter is included in the packet + so that many more bytes are included in CRC calculation. + */ + Temp = *pu8PacketPtr; + for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) { + /* skip sync word and CRC bytes */ + if (s32Ch != 3) { + for (s32LoopCountJ = 7; s32LoopCountJ >= 0; s32LoopCountJ--) { + u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01); + u8CRC <<= 1; + u8CRC ^= (u8XoredVal * 0x1D); + u8CRC &= 0xFF; + } } - - if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) - { - for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) - { - u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01); - u8CRC <<= 1; - u8CRC ^= (u8XoredVal * 0x1D); - u8CRC &= 0xFF; - } + Temp = *(++pu8PacketPtr); + } + + if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) { + for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); + s32LoopCountJ--) { + u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01); + u8CRC <<= 1; + u8CRC ^= (u8XoredVal * 0x1D); + u8CRC &= 0xFF; } + } - /* CRC calculation ends here */ + /* CRC calculation ends here */ - /* store CRC in packet */ - output[3] = u8CRC; - return u16PacketLength; + /* store CRC in packet */ + output[3] = u8CRC; + return u16PacketLength; } - diff --git a/include/bt_trace.h b/include/bt_trace.h index 84a0a8aa3..0b538a787 100644 --- a/include/bt_trace.h +++ b/include/bt_trace.h @@ -124,7 +124,6 @@ static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module"; #define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL #define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */ - /****************************************************************************** * * Trace Levels diff --git a/main/bte_conf.cc b/main/bte_conf.cc index 655094a1e..74ba571c2 100644 --- a/main/bte_conf.cc +++ b/main/bte_conf.cc @@ -30,56 +30,70 @@ // Parses the specified Device ID configuration file and registers the // Device ID records with SDP. -void bte_load_did_conf(const char *p_path) { - assert(p_path != NULL); +void bte_load_did_conf(const char* p_path) { + assert(p_path != NULL); - config_t *config = config_new(p_path); - if (!config) { - LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path); - return; - } + config_t* config = config_new(p_path); + if (!config) { + LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path); + return; + } - for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) { - char section_name[16] = { 0 }; - snprintf(section_name, sizeof(section_name), "DID%d", i); + for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) { + char section_name[16] = {0}; + snprintf(section_name, sizeof(section_name), "DID%d", i); - if (!config_has_section(config, section_name)) { - LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name); - break; - } + if (!config_has_section(config, section_name)) { + LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name); + break; + } - tBTA_DI_RECORD record; - record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM); - record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG); - record.product = config_get_int(config, section_name, "productId", 0); - record.version = config_get_int(config, section_name, "version", 0); - record.primary_record = config_get_bool(config, section_name, "primaryRecord", false); - strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url)); - strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description)); - strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url)); + tBTA_DI_RECORD record; + record.vendor = + config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM); + record.vendor_id_source = config_get_int( + config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG); + record.product = config_get_int(config, section_name, "productId", 0); + record.version = config_get_int(config, section_name, "version", 0); + record.primary_record = + config_get_bool(config, section_name, "primaryRecord", false); + strlcpy(record.client_executable_url, + config_get_string(config, section_name, "clientExecutableURL", ""), + sizeof(record.client_executable_url)); + strlcpy(record.service_description, + config_get_string(config, section_name, "serviceDescription", ""), + sizeof(record.service_description)); + strlcpy(record.documentation_url, + config_get_string(config, section_name, "documentationURL", ""), + sizeof(record.documentation_url)); - if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && - record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { - LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); - continue; - } + if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && + record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { + LOG_ERROR(LOG_TAG, + "%s invalid vendor id source %d; ignoring DID record %d.", + __func__, record.vendor_id_source, i); + continue; + } - LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); - LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor); - LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source); - LOG_DEBUG(LOG_TAG, " product = %04x", record.product); - LOG_DEBUG(LOG_TAG, " version = %04x", record.version); - LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", record.client_executable_url); - LOG_DEBUG(LOG_TAG, " serviceDescription = %s", record.service_description); - LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url); + LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, + (record.primary_record ? "primary" : "not primary")); + LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor); + LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source); + LOG_DEBUG(LOG_TAG, " product = %04x", record.product); + LOG_DEBUG(LOG_TAG, " version = %04x", record.version); + LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", + record.client_executable_url); + LOG_DEBUG(LOG_TAG, " serviceDescription = %s", + record.service_description); + LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url); - uint32_t record_handle; - tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); - if (status != BTA_SUCCESS) { - LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status); - } + uint32_t record_handle; + tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); + if (status != BTA_SUCCESS) { + LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", + __func__, i, status); } + } - config_free(config); + config_free(config); } - diff --git a/main/bte_init.cc b/main/bte_init.cc index 6c03c98a6..2aa8a9744 100644 --- a/main/bte_init.cc +++ b/main/bte_init.cc @@ -23,8 +23,8 @@ * ******************************************************************************/ -#include "bt_target.h" #include +#include "bt_target.h" #ifndef BTA_INCLUDED #define BTA_INCLUDED FALSE @@ -81,45 +81,40 @@ * Returns void * *****************************************************************************/ -void BTE_InitStack(void) -{ -/* Initialize the optional stack components */ - RFCOMM_Init(); +void BTE_InitStack(void) { + /* Initialize the optional stack components */ + RFCOMM_Init(); /************************** * BNEP and its profiles ** **************************/ #if (BNEP_INCLUDED == TRUE) - BNEP_Init(); + BNEP_Init(); #if (PAN_INCLUDED == TRUE) - PAN_Init(); -#endif /* PAN */ -#endif /* BNEP Included */ - + PAN_Init(); +#endif /* PAN */ +#endif /* BNEP Included */ /************************** * AVDT and its profiles ** **************************/ #if (A2D_INCLUDED == TRUE) - A2DP_Init(); -#endif /* AADP */ + A2DP_Init(); +#endif /* AADP */ + AVRC_Init(); - AVRC_Init(); - - -/*********** - * Others ** - ***********/ - GAP_Init(); + /*********** + * Others ** + ***********/ + GAP_Init(); #if (HID_HOST_INCLUDED == TRUE) - HID_HostInit(); + HID_HostInit(); #endif #if (MCA_INCLUDED == TRUE) - MCA_Init(); + MCA_Init(); #endif - } diff --git a/main/bte_init_cpp_logging.cc b/main/bte_init_cpp_logging.cc index cd531bb15..c31a1f7d0 100644 --- a/main/bte_init_cpp_logging.cc +++ b/main/bte_init_cpp_logging.cc @@ -23,19 +23,19 @@ #include #include "main_int.h" -void init_cpp_logging(config_t *config) { +void init_cpp_logging(config_t* config) { // Command line and log level might be also configured in service/main.cpp // when running the bluetoothtbd daemon. If it's already configured, skip // configuring. if (base::CommandLine::InitializedForCurrentProcess()) return; - const char *loggingV = + const char* loggingV = config_get_string(config, CONFIG_DEFAULT_SECTION, "LoggingV", NULL); - const char *loggingVModule = + const char* loggingVModule = config_get_string(config, CONFIG_DEFAULT_SECTION, "LoggingVModule", NULL); int argc = 1; - const char *argv[] = {"bt_stack", NULL, NULL}; + const char* argv[] = {"bt_stack", NULL, NULL}; if (loggingV != NULL) { argv[argc] = loggingV; diff --git a/main/bte_logmsg.cc b/main/bte_logmsg.cc index e8d1bd6de..2ad5df0e3 100644 --- a/main/bte_logmsg.cc +++ b/main/bte_logmsg.cc @@ -19,28 +19,28 @@ #define LOG_TAG "bt_bte" #include +#include #include #include #include -#include #include #include #include "avrc_api.h" +#include "bt_common.h" #include "bta_api.h" #include "bte.h" #include "btm_api.h" #include "btu.h" #include "gap_api.h" -#include "bt_common.h" #include "l2c_api.h" +#include "main_int.h" #include "osi/include/config.h" #include "osi/include/log.h" #include "osi/include/log.h" #include "port_api.h" #include "sdp_api.h" #include "stack_config.h" -#include "main_int.h" #if (AVDT_INCLUDED == TRUE) #include "avdt_api.h" @@ -62,64 +62,24 @@ #endif #ifndef BTE_LOG_BUF_SIZE -#define BTE_LOG_BUF_SIZE 1024 +#define BTE_LOG_BUF_SIZE 1024 #endif -#define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12) +#define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12) #define MSG_BUFFER_OFFSET 0 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */ -static const char * const bt_layer_tags[] = { - "bt_btif", - "bt_usb", - "bt_serial", - "bt_socket", - "bt_rs232", - "bt_lc", - "bt_lm", - "bt_hci", - "bt_l2cap", - "bt_rfcomm", - "bt_sdp", - "bt_tcs", - "bt_obex", - "bt_btm", - "bt_gap", - "UNUSED", - "UNUSED", - "bt_icp", - "bt_hsp2", - "bt_spp", - "bt_ctp", - "bt_bpp", - "bt_hcrp", - "bt_ftp", - "bt_opp", - "bt_btu", - "bt_gki", /* OBSOLETED */ - "bt_bnep", - "bt_pan", - "bt_hfp", - "bt_hid", - "bt_bip", - "bt_avp", - "bt_a2d", - "bt_sap", - "bt_amp", - "bt_mca", - "bt_att", - "bt_smp", - "bt_nfc", - "bt_nci", - "bt_idep", - "bt_ndep", - "bt_llcp", - "bt_rw", - "bt_ce", - "bt_snep", - "bt_ndef", - "bt_nfa", +static const char* const bt_layer_tags[] = { + "bt_btif", "bt_usb", "bt_serial", "bt_socket", "bt_rs232", "bt_lc", + "bt_lm", "bt_hci", "bt_l2cap", "bt_rfcomm", "bt_sdp", "bt_tcs", + "bt_obex", "bt_btm", "bt_gap", "UNUSED", "UNUSED", "bt_icp", + "bt_hsp2", "bt_spp", "bt_ctp", "bt_bpp", "bt_hcrp", "bt_ftp", + "bt_opp", "bt_btu", "bt_gki", /* OBSOLETED */ + "bt_bnep", "bt_pan", "bt_hfp", "bt_hid", "bt_bip", "bt_avp", + "bt_a2d", "bt_sap", "bt_amp", "bt_mca", "bt_att", "bt_smp", + "bt_nfc", "bt_nci", "bt_idep", "bt_ndep", "bt_llcp", "bt_rw", + "bt_ce", "bt_snep", "bt_ndef", "bt_nfa", }; static uint8_t BTAPP_SetTraceLevel(uint8_t new_level); static uint8_t BTIF_SetTraceLevel(uint8_t new_level); @@ -127,51 +87,65 @@ static uint8_t BTU_SetTraceLevel(uint8_t new_level); /* make sure list is order by increasing layer id!!! */ static tBTTRC_FUNC_MAP bttrc_set_level_map[] = { - {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, + "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL}, #if (AVDT_INCLUDED == TRUE) - {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", + DEFAULT_CONF_TRACE_LEVEL}, #endif - {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", + DEFAULT_CONF_TRACE_LEVEL}, #if (AVDT_INCLUDED == TRUE) - //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL}, +//{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", +// DEFAULT_CONF_TRACE_LEVEL}, #endif #if (A2D_INCLUDED == TRUE) - {BTTRC_ID_STK_A2DP, BTTRC_ID_STK_A2DP, A2DP_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_A2DP, BTTRC_ID_STK_A2DP, A2DP_SetTraceLevel, "TRC_A2D", + DEFAULT_CONF_TRACE_LEVEL}, #endif #if (BNEP_INCLUDED == TRUE) - {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", + DEFAULT_CONF_TRACE_LEVEL}, #endif - {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", + DEFAULT_CONF_TRACE_LEVEL}, #if (PAN_INCLUDED == TRUE) - {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", + DEFAULT_CONF_TRACE_LEVEL}, #endif - {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL}, - - /* LayerIDs for BTA, currently everything maps onto appl_trace_level. - */ - {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, "TRC_BTAPP", DEFAULT_CONF_TRACE_LEVEL}, - {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL}, - - {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL} -}; - -void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) { + {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", + DEFAULT_CONF_TRACE_LEVEL}, + + /* LayerIDs for BTA, currently everything maps onto appl_trace_level. + */ + {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, "TRC_BTAPP", + DEFAULT_CONF_TRACE_LEVEL}, + {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", + DEFAULT_CONF_TRACE_LEVEL}, + + {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}}; + +void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) { static char buffer[BTE_LOG_BUF_SIZE]; int trace_layer = TRACE_GET_LAYER(trace_set_mask); - if (trace_layer >= TRACE_LAYER_MAX_NUM) - trace_layer = 0; + if (trace_layer >= TRACE_LAYER_MAX_NUM) trace_layer = 0; va_list ap; va_start(ap, fmt_str); vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap); va_end(ap); - switch ( TRACE_GET_TYPE(trace_set_mask) ) { + switch (TRACE_GET_TYPE(trace_set_mask)) { case TRACE_TYPE_ERROR: LOG_ERROR(bt_layer_tags[trace_layer], "%s", buffer); break; @@ -194,43 +168,39 @@ void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) { /* this function should go into BTAPP_DM for example */ static uint8_t BTAPP_SetTraceLevel(uint8_t new_level) { - if (new_level != 0xFF) - appl_trace_level = new_level; + if (new_level != 0xFF) appl_trace_level = new_level; return appl_trace_level; } static uint8_t BTIF_SetTraceLevel(uint8_t new_level) { - if (new_level != 0xFF) - btif_trace_level = new_level; + if (new_level != 0xFF) btif_trace_level = new_level; return btif_trace_level; } static uint8_t BTU_SetTraceLevel(uint8_t new_level) { - if (new_level != 0xFF) - btu_trace_level = new_level; + if (new_level != 0xFF) btu_trace_level = new_level; return btu_trace_level; } -static void load_levels_from_config(const config_t *config) { +static void load_levels_from_config(const config_t* config) { assert(config != NULL); - for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) { + for (tBTTRC_FUNC_MAP* functions = &bttrc_set_level_map[0]; + functions->trc_name; ++functions) { LOG_INFO(LOG_TAG, "BTE_InitTraceLevels -- %s", functions->trc_name); - int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1); - if (value != -1) - functions->trace_level = value; + int value = + config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1); + if (value != -1) functions->trace_level = value; - if (functions->p_f) - functions->p_f(functions->trace_level); + if (functions->p_f) functions->p_f(functions->trace_level); } } -static future_t *init(void) { - - const stack_config_t *stack_config = stack_config_get_interface(); +static future_t* init(void) { + const stack_config_t* stack_config = stack_config_get_interface(); if (!stack_config->get_trace_config_enabled()) { LOG_INFO(LOG_TAG, "using compile default trace settings"); return NULL; @@ -243,13 +213,9 @@ static future_t *init(void) { } EXPORT_SYMBOL extern const module_t bte_logmsg_module = { - .name = BTE_LOGMSG_MODULE, - .init = init, - .start_up = NULL, - .shut_down = NULL, - .clean_up = NULL, - .dependencies = { - STACK_CONFIG_MODULE, - NULL - } -}; + .name = BTE_LOGMSG_MODULE, + .init = init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = NULL, + .dependencies = {STACK_CONFIG_MODULE, NULL}}; diff --git a/main/bte_main.cc b/main/bte_main.cc index d31387458..86a0637dc 100644 --- a/main/bte_main.cc +++ b/main/bte_main.cc @@ -35,6 +35,7 @@ #include +#include "bt_common.h" #include "bt_hci_bdroid.h" #include "bt_utils.h" #include "bta_api.h" @@ -43,7 +44,6 @@ #include "btif_common.h" #include "btsnoop.h" #include "btu.h" -#include "bt_common.h" #include "device/include/interop.h" #include "hci_layer.h" #include "hcimsgs.h" @@ -76,7 +76,7 @@ /******************************************************************************* * Static variables ******************************************************************************/ -static const hci_t *hci; +static const hci_t* hci; /******************************************************************************* * Static functions @@ -85,7 +85,7 @@ static const hci_t *hci; /******************************************************************************* * Externs ******************************************************************************/ -fixed_queue_t *btu_hci_msg_queue; +fixed_queue_t* btu_hci_msg_queue; /****************************************************************************** * @@ -96,24 +96,23 @@ fixed_queue_t *btu_hci_msg_queue; * Returns None * *****************************************************************************/ -void bte_main_boot_entry(void) -{ - module_init(get_module(INTEROP_MODULE)); +void bte_main_boot_entry(void) { + module_init(get_module(INTEROP_MODULE)); - hci = hci_layer_get_interface(); - if (!hci) - LOG_ERROR(LOG_TAG, "%s could not get hci layer interface.", __func__); + hci = hci_layer_get_interface(); + if (!hci) + LOG_ERROR(LOG_TAG, "%s could not get hci layer interface.", __func__); - btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); - if (btu_hci_msg_queue == NULL) { - LOG_ERROR(LOG_TAG, "%s unable to allocate hci message queue.", __func__); - return; - } + btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); + if (btu_hci_msg_queue == NULL) { + LOG_ERROR(LOG_TAG, "%s unable to allocate hci message queue.", __func__); + return; + } - data_dispatcher_register_default(hci->event_dispatcher, btu_hci_msg_queue); - hci->set_data_queue(btu_hci_msg_queue); + data_dispatcher_register_default(hci->event_dispatcher, btu_hci_msg_queue); + hci->set_data_queue(btu_hci_msg_queue); - module_init(get_module(STACK_CONFIG_MODULE)); + module_init(get_module(STACK_CONFIG_MODULE)); } /****************************************************************************** @@ -125,17 +124,17 @@ void bte_main_boot_entry(void) * Returns None * *****************************************************************************/ -void bte_main_cleanup() -{ - data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL); - hci->set_data_queue(NULL); - fixed_queue_free(btu_hci_msg_queue, NULL); +void bte_main_cleanup() { + data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, + NULL); + hci->set_data_queue(NULL); + fixed_queue_free(btu_hci_msg_queue, NULL); - btu_hci_msg_queue = NULL; + btu_hci_msg_queue = NULL; - module_clean_up(get_module(STACK_CONFIG_MODULE)); + module_clean_up(get_module(STACK_CONFIG_MODULE)); - module_clean_up(get_module(INTEROP_MODULE)); + module_clean_up(get_module(INTEROP_MODULE)); } /****************************************************************************** @@ -148,14 +147,13 @@ void bte_main_cleanup() * Returns None * *****************************************************************************/ -void bte_main_enable() -{ - APPL_TRACE_DEBUG("%s", __func__); +void bte_main_enable() { + APPL_TRACE_DEBUG("%s", __func__); - module_start_up(get_module(BTSNOOP_MODULE)); - module_start_up(get_module(HCI_MODULE)); + module_start_up(get_module(BTSNOOP_MODULE)); + module_start_up(get_module(HCI_MODULE)); - BTU_StartUp(); + BTU_StartUp(); } /****************************************************************************** @@ -168,14 +166,13 @@ void bte_main_enable() * Returns None * *****************************************************************************/ -void bte_main_disable(void) -{ - APPL_TRACE_DEBUG("%s", __func__); +void bte_main_disable(void) { + APPL_TRACE_DEBUG("%s", __func__); - module_shut_down(get_module(HCI_MODULE)); - module_shut_down(get_module(BTSNOOP_MODULE)); + module_shut_down(get_module(HCI_MODULE)); + module_shut_down(get_module(BTSNOOP_MODULE)); - BTU_ShutDown(); + BTU_ShutDown(); } /****************************************************************************** @@ -187,10 +184,7 @@ void bte_main_disable(void) * Returns None * *****************************************************************************/ -void bte_main_postload_cfg(void) -{ - hci->do_postload(); -} +void bte_main_postload_cfg(void) { hci->do_postload(); } #if (HCILP_INCLUDED == TRUE) /****************************************************************************** @@ -202,9 +196,8 @@ void bte_main_postload_cfg(void) * Returns None * *****************************************************************************/ -void bte_main_enable_lpm(bool enable) -{ - hci->send_low_power_command(enable ? LPM_ENABLE : LPM_DISABLE); +void bte_main_enable_lpm(bool enable) { + hci->send_low_power_command(enable ? LPM_ENABLE : LPM_DISABLE); } /****************************************************************************** @@ -216,9 +209,8 @@ void bte_main_enable_lpm(bool enable) * Returns None * *****************************************************************************/ -void bte_main_lpm_allow_bt_device_sleep() -{ - hci->send_low_power_command(LPM_WAKE_DEASSERT); +void bte_main_lpm_allow_bt_device_sleep() { + hci->send_low_power_command(LPM_WAKE_DEASSERT); } /****************************************************************************** @@ -230,9 +222,8 @@ void bte_main_lpm_allow_bt_device_sleep() * Returns None * *****************************************************************************/ -void bte_main_lpm_wake_bt_device() -{ - hci->send_low_power_command(LPM_WAKE_ASSERT); +void bte_main_lpm_wake_bt_device() { + hci->send_low_power_command(LPM_WAKE_ASSERT); } #endif // HCILP_INCLUDED @@ -248,21 +239,16 @@ void bte_main_lpm_wake_bt_device() * Returns None * *****************************************************************************/ -void bte_main_hci_send (BT_HDR *p_msg, uint16_t event) -{ - uint16_t sub_event = event & BT_SUB_EVT_MASK; /* local controller ID */ - - p_msg->event = event; - - - if((sub_event == LOCAL_BR_EDR_CONTROLLER_ID) || \ - (sub_event == LOCAL_BLE_CONTROLLER_ID)) - { - hci->transmit_downward(event, p_msg); - } - else - { - APPL_TRACE_ERROR("Invalid Controller ID. Discarding message."); - osi_free(p_msg); - } +void bte_main_hci_send(BT_HDR* p_msg, uint16_t event) { + uint16_t sub_event = event & BT_SUB_EVT_MASK; /* local controller ID */ + + p_msg->event = event; + + if ((sub_event == LOCAL_BR_EDR_CONTROLLER_ID) || + (sub_event == LOCAL_BLE_CONTROLLER_ID)) { + hci->transmit_downward(event, p_msg); + } else { + APPL_TRACE_ERROR("Invalid Controller ID. Discarding message."); + osi_free(p_msg); + } } diff --git a/main/main_int.h b/main/main_int.h index dc821bc51..8e07236d9 100644 --- a/main/main_int.h +++ b/main/main_int.h @@ -26,10 +26,10 @@ extern "C" { #endif /* Initiates the logging for C++ */ -void init_cpp_logging(config_t *config); +void init_cpp_logging(config_t* config); #ifdef __cplusplus } #endif -#endif // MAIN_INT_H \ No newline at end of file +#endif // MAIN_INT_H \ No newline at end of file diff --git a/main/stack_config.cc b/main/stack_config.cc index 72044df8f..fefeead14 100644 --- a/main/stack_config.cc +++ b/main/stack_config.cc @@ -25,26 +25,26 @@ #include "osi/include/future.h" #include "osi/include/log.h" -const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName"; -const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput"; -const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog"; -const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf"; -const char *PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly"; -const char *PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates"; -const char *PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair"; -const char *PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions"; -const char *PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase"; - -static config_t *config; +const char* BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName"; +const char* BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput"; +const char* BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog"; +const char* TRACE_CONFIG_ENABLED_KEY = "TraceConf"; +const char* PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly"; +const char* PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates"; +const char* PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair"; +const char* PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions"; +const char* PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase"; + +static config_t* config; // Module lifecycle functions -static future_t *init() { +static future_t* init() { // TODO(armansito): Find a better way than searching by a hardcoded path. #if defined(OS_GENERIC) - const char *path = "bt_stack.conf"; + const char* path = "bt_stack.conf"; #else // !defined(OS_GENERIC) - const char *path = "/etc/bluetooth/bt_stack.conf"; + const char* path = "/etc/bluetooth/bt_stack.conf"; #endif // defined(OS_GENERIC) assert(path != NULL); @@ -59,79 +59,74 @@ static future_t *init() { return future_new_immediate(FUTURE_SUCCESS); } -static future_t *clean_up() { +static future_t* clean_up() { config_free(config); config = NULL; return future_new_immediate(FUTURE_SUCCESS); } EXPORT_SYMBOL extern const module_t stack_config_module = { - .name = STACK_CONFIG_MODULE, - .init = init, - .start_up = NULL, - .shut_down = NULL, - .clean_up = clean_up, - .dependencies = { - NULL - } -}; + .name = STACK_CONFIG_MODULE, + .init = init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = clean_up, + .dependencies = {NULL}}; // Interface functions -static const char *get_btsnoop_log_path(void) { +static const char* get_btsnoop_log_path(void) { return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, - "/data/misc/bluetooth/logs/btsnoop_hci.log"); + "/data/misc/bluetooth/logs/btsnoop_hci.log"); } static bool get_btsnoop_turned_on(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, + false); } static bool get_btsnoop_should_save_last(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, + BTSNOOP_SHOULD_SAVE_LAST_KEY, false); } static bool get_trace_config_enabled(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, + TRACE_CONFIG_ENABLED_KEY, false); } static bool get_pts_secure_only_mode(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, + false); } static bool get_pts_conn_updates_disabled(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_LE_CONN_UPDATED_DISABLED, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, + PTS_LE_CONN_UPDATED_DISABLED, false); } static bool get_pts_crosskey_sdp_disable(void) { - return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_DISABLE_SDP_LE_PAIR, false); + return config_get_bool(config, CONFIG_DEFAULT_SECTION, + PTS_DISABLE_SDP_LE_PAIR, false); } -static const char *get_pts_smp_options(void) { - return config_get_string(config, CONFIG_DEFAULT_SECTION, PTS_SMP_PAIRING_OPTIONS_KEY, NULL); +static const char* get_pts_smp_options(void) { + return config_get_string(config, CONFIG_DEFAULT_SECTION, + PTS_SMP_PAIRING_OPTIONS_KEY, NULL); } static int get_pts_smp_failure_case(void) { - return config_get_int(config, CONFIG_DEFAULT_SECTION, PTS_SMP_FAILURE_CASE_KEY, 0); + return config_get_int(config, CONFIG_DEFAULT_SECTION, + PTS_SMP_FAILURE_CASE_KEY, 0); } -static config_t *get_all(void) { - return config; -} +static config_t* get_all(void) { return config; } const stack_config_t interface = { - get_btsnoop_log_path, - get_btsnoop_turned_on, - get_btsnoop_should_save_last, - get_trace_config_enabled, - get_pts_secure_only_mode, - get_pts_conn_updates_disabled, - get_pts_crosskey_sdp_disable, - get_pts_smp_options, - get_pts_smp_failure_case, - get_all -}; - -const stack_config_t *stack_config_get_interface(void) { - return &interface; -} + get_btsnoop_log_path, get_btsnoop_turned_on, + get_btsnoop_should_save_last, get_trace_config_enabled, + get_pts_secure_only_mode, get_pts_conn_updates_disabled, + get_pts_crosskey_sdp_disable, get_pts_smp_options, + get_pts_smp_failure_case, get_all}; + +const stack_config_t* stack_config_get_interface(void) { return &interface; } diff --git a/service/adapter.cc b/service/adapter.cc index e97b595f0..3ef30054d 100644 --- a/service/adapter.cc +++ b/service/adapter.cc @@ -30,8 +30,8 @@ #include "service/hal/bluetooth_interface.h" #include "service/logging_helpers.h" #include "service/low_energy_advertiser.h" -#include "service/low_energy_scanner.h" #include "service/low_energy_client.h" +#include "service/low_energy_scanner.h" using std::lock_guard; using std::mutex; @@ -70,13 +70,12 @@ void Adapter::Observer::OnDeviceConnectionStateChanged( } // The real Adapter implementation used in production. -class AdapterImpl : public Adapter, - public hal::BluetoothInterface::Observer { +class AdapterImpl : public Adapter, public hal::BluetoothInterface::Observer { public: AdapterImpl() - : state_(ADAPTER_STATE_OFF), - address_(kDefaultAddress), - name_(kDefaultName) { + : state_(ADAPTER_STATE_OFF), + address_(kDefaultAddress), + name_(kDefaultName) { memset(&local_le_features_, 0, sizeof(local_le_features_)); hal::BluetoothInterface::Get()->AddObserver(this); ble_client_factory_.reset(new LowEnergyClientFactory(*this)); @@ -101,13 +100,9 @@ class AdapterImpl : public Adapter, observers_.RemoveObserver(observer); } - AdapterState GetState() const override { - return state_.load(); - } + AdapterState GetState() const override { return state_.load(); } - bool IsEnabled() const override { - return state_.load() == ADAPTER_STATE_ON; - } + bool IsEnabled() const override { return state_.load() == ADAPTER_STATE_ON; } bool Enable(bool start_restricted) override { AdapterState current_state = GetState(); @@ -122,7 +117,8 @@ class AdapterImpl : public Adapter, state_ = ADAPTER_STATE_TURNING_ON; NotifyAdapterStateChanged(current_state, state_); - int status = hal::BluetoothInterface::Get()->GetHALInterface()->enable(start_restricted); + int status = hal::BluetoothInterface::Get()->GetHALInterface()->enable( + start_restricted); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to enable Bluetooth - status: " << BtStatusText((const bt_status_t)status); @@ -159,9 +155,7 @@ class AdapterImpl : public Adapter, return true; } - std::string GetName() const override { - return name_.Get(); - } + std::string GetName() const override { return name_.Get(); } bool SetName(const std::string& name) override { bt_bdname_t hal_name; @@ -187,9 +181,7 @@ class AdapterImpl : public Adapter, return true; } - std::string GetAddress() const override { - return address_.Get(); - } + std::string GetAddress() const override { return address_.Get(); } bool IsMultiAdvertisementSupported() override { lock_guard lock(local_le_features_lock_); @@ -214,7 +206,7 @@ class AdapterImpl : public Adapter, bool IsOffloadedScanBatchingSupported() override { lock_guard lock(local_le_features_lock_); return local_le_features_.scan_result_storage_size >= - kMinOffloadedScanStorageBytes; + kMinOffloadedScanStorageBytes; } LowEnergyClientFactory* GetLowEnergyClientFactory() const override { @@ -244,23 +236,22 @@ class AdapterImpl : public Adapter, AdapterState prev_state = GetState(); switch (state) { - case BT_STATE_OFF: - state_ = ADAPTER_STATE_OFF; - break; + case BT_STATE_OFF: + state_ = ADAPTER_STATE_OFF; + break; - case BT_STATE_ON: - state_ = ADAPTER_STATE_ON; - break; + case BT_STATE_ON: + state_ = ADAPTER_STATE_ON; + break; - default: - NOTREACHED(); + default: + NOTREACHED(); } NotifyAdapterStateChanged(prev_state, GetState()); } - void AdapterPropertiesCallback(bt_status_t status, - int num_properties, + void AdapterPropertiesCallback(bt_status_t status, int num_properties, bt_property_t* properties) override { LOG(INFO) << "Adapter properties changed"; @@ -273,8 +264,8 @@ class AdapterImpl : public Adapter, bt_property_t* property = properties + i; switch (property->type) { case BT_PROPERTY_BDADDR: { - std::string address = BtAddrString(reinterpret_cast( - property->val)); + std::string address = + BtAddrString(reinterpret_cast(property->val)); LOG(INFO) << "Adapter address changed: " << address; address_.Set(address); break; @@ -314,8 +305,8 @@ class AdapterImpl : public Adapter, bt_acl_state_t state) override { std::string device_address = BtAddrString(&remote_bdaddr); bool connected = (state == BT_ACL_STATE_CONNECTED); - LOG(INFO) << "ACL state changed: " << device_address << " - connected: " - << (connected ? "true" : "false"); + LOG(INFO) << "ACL state changed: " << device_address + << " - connected: " << (connected ? "true" : "false"); // If this is reported with an error status, I suppose the best thing we can // do is to log it and ignore the event. @@ -349,8 +340,9 @@ class AdapterImpl : public Adapter, property.val = value; property.type = type; - int status = hal::BluetoothInterface::Get()->GetHALInterface()-> - set_adapter_property(&property); + int status = + hal::BluetoothInterface::Get()->GetHALInterface()->set_adapter_property( + &property); if (status != BT_STATUS_SUCCESS) { VLOG(1) << "Failed to set property"; return false; @@ -362,8 +354,7 @@ class AdapterImpl : public Adapter, // Helper for invoking the AdapterStateChanged observer method. void NotifyAdapterStateChanged(AdapterState prev_state, AdapterState new_state) { - if (prev_state == new_state) - return; + if (prev_state == new_state) return; lock_guard lock(observers_lock_); FOR_EACH_OBSERVER(Adapter::Observer, observers_, diff --git a/service/adapter.h b/service/adapter.h index 75a5491fd..37275db1e 100644 --- a/service/adapter.h +++ b/service/adapter.h @@ -132,7 +132,8 @@ class Adapter { virtual LowEnergyScannerFactory* GetLeScannerFactory() const = 0; // Returns a pointer to the LowEnergyAdvertiserFactory. This can be used to - // register per-application LowEnergyAdvertiser instances to perform advertising. + // register per-application LowEnergyAdvertiser instances to perform + // advertising. virtual LowEnergyAdvertiserFactory* GetLeAdvertiserFactory() const = 0; // Returns a pointer to the GattClientFactory. This can be used to register diff --git a/service/bluetooth_instance.h b/service/bluetooth_instance.h index c2e06f3a5..868f425e2 100644 --- a/service/bluetooth_instance.h +++ b/service/bluetooth_instance.h @@ -57,9 +57,9 @@ class BluetoothInstanceFactory { virtual ~BluetoothInstanceFactory() = default; // Callback invoked as a result of a call to RegisterInstance. - using RegisterCallback = std::function instance)>; + using RegisterCallback = + std::function instance)>; // Registers an instance for the given unique identifier |app_uuid|. // On success, this asynchronously invokes |callback| with a unique pointer diff --git a/service/client/main.cc b/service/client/main.cc index 9f9947d58..255d3f0de 100644 --- a/service/client/main.cc +++ b/service/client/main.cc @@ -32,17 +32,17 @@ #include #include -#include #include #include -#include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -435,7 +435,8 @@ void HandleSupportsMultiAdv(IBluetooth* bt_iface, const vector& args) { PrintFieldAndBoolValue("Multi-advertisement support", multi_adv); } -void HandleRegisterBLEAdvertiser(IBluetooth* bt_iface, const vector& args) { +void HandleRegisterBLEAdvertiser(IBluetooth* bt_iface, + const vector& args) { CHECK_NO_ARGS(args); if (ble_advertiser_registering.load()) { @@ -456,12 +457,14 @@ void HandleRegisterBLEAdvertiser(IBluetooth* bt_iface, const vector& arg } bool status; - ble_advertiser_iface->RegisterAdvertiser(new CLIBluetoothLeAdvertiserCallback(), &status); + ble_advertiser_iface->RegisterAdvertiser( + new CLIBluetoothLeAdvertiserCallback(), &status); ble_advertiser_registering = status; PrintCommandStatus(status); } -void HandleUnregisterBLEAdvertiser(IBluetooth* bt_iface, const vector& args) { +void HandleUnregisterBLEAdvertiser(IBluetooth* bt_iface, + const vector& args) { CHECK_NO_ARGS(args); if (!ble_advertiser_id.load()) { @@ -705,8 +708,8 @@ void HandleStartAdv(IBluetooth* bt_iface, const vector& args) { bluetooth::AdvertiseData scan_rsp; bool status; - ble_advertiser_iface->StartMultiAdvertising(ble_advertiser_id.load(), adv_data, scan_rsp, - settings, &status); + ble_advertiser_iface->StartMultiAdvertising( + ble_advertiser_id.load(), adv_data, scan_rsp, settings, &status); PrintCommandStatus(status); } @@ -821,8 +824,8 @@ void HandleSetMtu(IBluetooth* bt_iface, const vector& args) { PrintCommandStatus(status); } - -void HandleRegisterBLEScanner(IBluetooth* bt_iface, const vector& args) { +void HandleRegisterBLEScanner(IBluetooth* bt_iface, + const vector& args) { CHECK_NO_ARGS(args); if (ble_scanner_registering.load()) { @@ -843,12 +846,14 @@ void HandleRegisterBLEScanner(IBluetooth* bt_iface, const vector& args) } bool status; - ble_scanner_iface->RegisterScanner(new CLIBluetoothLeScannerCallback(), &status); + ble_scanner_iface->RegisterScanner(new CLIBluetoothLeScannerCallback(), + &status); ble_scanner_registering = status; PrintCommandStatus(status); } -void HandleUnregisterBLEScanner(IBluetooth* bt_iface, const vector& args) { +void HandleUnregisterBLEScanner(IBluetooth* bt_iface, + const vector& args) { CHECK_NO_ARGS(args); if (!ble_scanner_id.load()) { @@ -900,7 +905,8 @@ void HandleStartLeScan(IBluetooth* bt_iface, const vector& args) { std::vector filters; bool status; - ble_scanner_iface->StartScan(ble_scanner_id.load(), settings, filters, &status); + ble_scanner_iface->StartScan(ble_scanner_id.load(), settings, filters, + &status); PrintCommandStatus(status); } @@ -981,13 +987,11 @@ void HandleHelp(IBluetooth* /* bt_iface */, const vector& /* args */) { const char kExecuteLong[] = "exec"; const char kExecuteShort[] = "e"; -bool ExecuteCommand(const sp& bt_iface, std::string &command) { - vector args = - base::SplitString(command, " ", base::TRIM_WHITESPACE, - base::SPLIT_WANT_ALL); +bool ExecuteCommand(const sp& bt_iface, std::string& command) { + vector args = base::SplitString(command, " ", base::TRIM_WHITESPACE, + base::SPLIT_WANT_ALL); - if (args.empty()) - return true; + if (args.empty()) return true; // The first argument is the command while the remaining are what we pass to // the handler functions. @@ -1027,7 +1031,6 @@ class BluetoothDeathRecipient : public android::IBinder::DeathRecipient { DISALLOW_COPY_AND_ASSIGN(BluetoothDeathRecipient); }; - int main(int argc, char* argv[]) { base::AtExitManager exit_manager; base::CommandLine::Init(argc, argv); @@ -1076,18 +1079,15 @@ int main(int argc, char* argv[]) { } if (command_line->HasSwitch(kExecuteShort)) { - if (!command.empty()) - command += " ; "; + if (!command.empty()) command += " ; "; command += command_line->GetSwitchValueASCII(kExecuteShort); } while (true) { - vector commands = base::SplitString(command, ";", - base::TRIM_WHITESPACE, - base::SPLIT_WANT_ALL); + vector commands = base::SplitString( + command, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); for (string command : commands) { - if (!ExecuteCommand(bt_iface, command)) - break; + if (!ExecuteCommand(bt_iface, command)) break; } commands.clear(); diff --git a/service/common/android/bluetooth/advertise_settings.h b/service/common/android/bluetooth/advertise_settings.h index 19eeda537..afca23376 100644 --- a/service/common/android/bluetooth/advertise_settings.h +++ b/service/common/android/bluetooth/advertise_settings.h @@ -32,7 +32,8 @@ class AdvertiseSettings : public Parcelable, public ::bluetooth::AdvertiseSettings { public: // NOLINT, implicit converter - AdvertiseSettings(const ::bluetooth::AdvertiseSettings& advertise_settings) // NOLINT + AdvertiseSettings( + const ::bluetooth::AdvertiseSettings& advertise_settings) // NOLINT : ::bluetooth::AdvertiseSettings(advertise_settings){}; AdvertiseSettings() = default; ~AdvertiseSettings() = default; diff --git a/service/common/android/bluetooth/bluetooth_gatt_characteristic.h b/service/common/android/bluetooth/bluetooth_gatt_characteristic.h index 2286068ee..9884d996e 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_characteristic.h +++ b/service/common/android/bluetooth/bluetooth_gatt_characteristic.h @@ -28,10 +28,12 @@ using android::status_t; namespace android { namespace bluetooth { -class BluetoothGattCharacteristic : public Parcelable, public ::bluetooth::Characteristic { +class BluetoothGattCharacteristic : public Parcelable, + public ::bluetooth::Characteristic { public: BluetoothGattCharacteristic() = default; - BluetoothGattCharacteristic(const ::bluetooth::Characteristic& characteristic) // NOLINT(implicit) + BluetoothGattCharacteristic( + const ::bluetooth::Characteristic& characteristic) // NOLINT(implicit) : ::bluetooth::Characteristic(characteristic){}; ~BluetoothGattCharacteristic() = default; diff --git a/service/common/android/bluetooth/bluetooth_gatt_descriptor.h b/service/common/android/bluetooth/bluetooth_gatt_descriptor.h index c791c242f..955c645c3 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_descriptor.h +++ b/service/common/android/bluetooth/bluetooth_gatt_descriptor.h @@ -28,10 +28,12 @@ using android::status_t; namespace android { namespace bluetooth { -class BluetoothGattDescriptor : public Parcelable, public ::bluetooth::Descriptor { +class BluetoothGattDescriptor : public Parcelable, + public ::bluetooth::Descriptor { public: BluetoothGattDescriptor() = default; - BluetoothGattDescriptor(const ::bluetooth::Descriptor& characteristic) // NOLINT(implicit) + BluetoothGattDescriptor( + const ::bluetooth::Descriptor& characteristic) // NOLINT(implicit) : ::bluetooth::Descriptor(characteristic){}; ~BluetoothGattDescriptor() = default; diff --git a/service/common/android/bluetooth/bluetooth_gatt_included_service.cc b/service/common/android/bluetooth/bluetooth_gatt_included_service.cc index 9b4090efe..02dc54683 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_included_service.cc +++ b/service/common/android/bluetooth/bluetooth_gatt_included_service.cc @@ -14,8 +14,8 @@ // limitations under the License. // -#include "service/common/android/bluetooth/bluetooth_gatt_service.h" #include "service/common/android/bluetooth/bluetooth_gatt_characteristic.h" +#include "service/common/android/bluetooth/bluetooth_gatt_service.h" #include "service/common/android/bluetooth/uuid.h" #include diff --git a/service/common/android/bluetooth/bluetooth_gatt_included_service.h b/service/common/android/bluetooth/bluetooth_gatt_included_service.h index 7ff344f5d..3a00a19cd 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_included_service.h +++ b/service/common/android/bluetooth/bluetooth_gatt_included_service.h @@ -33,9 +33,11 @@ namespace bluetooth { class BluetoothGattIncludedService : public Parcelable { public: BluetoothGattIncludedService() = default; - BluetoothGattIncludedService(const ::bluetooth::Service& service) // NOLINT(implicit) - : handle_(service.handle()), uuid_(service.uuid()), - primary_(service.primary()) {}; + BluetoothGattIncludedService( + const ::bluetooth::Service& service) // NOLINT(implicit) + : handle_(service.handle()), + uuid_(service.uuid()), + primary_(service.primary()){}; ~BluetoothGattIncludedService() = default; // Write |this| parcelable to the given |parcel|. Keep in mind that @@ -56,7 +58,7 @@ class BluetoothGattIncludedService : public Parcelable { bool primary() const { return primary_; } UUID uuid() const { return uuid_; } -protected: + protected: uint16_t handle_; UUID uuid_; bool primary_; diff --git a/service/common/android/bluetooth/bluetooth_gatt_service.cc b/service/common/android/bluetooth/bluetooth_gatt_service.cc index cdbd73f9a..f4915cb05 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_service.cc +++ b/service/common/android/bluetooth/bluetooth_gatt_service.cc @@ -39,8 +39,7 @@ status_t BluetoothGattService::writeToParcel(Parcel* parcel) const { if (status != OK) return status; std::vector characteristics; - for (const auto& chrc : characteristics_) - characteristics.push_back(chrc); + for (const auto& chrc : characteristics_) characteristics.push_back(chrc); status = parcel->writeParcelableVector(characteristics); @@ -71,8 +70,7 @@ status_t BluetoothGattService::readFromParcel(const Parcel* parcel) { status = parcel->readParcelableVector(&characteristics); if (status != OK) return status; - for (const auto& chrc : characteristics) - characteristics_.push_back(chrc); + for (const auto& chrc : characteristics) characteristics_.push_back(chrc); std::vector includedServices; status = parcel->readParcelableVector(&includedServices); diff --git a/service/common/android/bluetooth/bluetooth_gatt_service.h b/service/common/android/bluetooth/bluetooth_gatt_service.h index eb6a30e58..932d4fb59 100644 --- a/service/common/android/bluetooth/bluetooth_gatt_service.h +++ b/service/common/android/bluetooth/bluetooth_gatt_service.h @@ -16,8 +16,8 @@ #pragma once -#include "bluetooth/service.h" #include "android/bluetooth/bluetooth_gatt_included_service.h" +#include "bluetooth/service.h" #include #include @@ -32,10 +32,13 @@ namespace bluetooth { class BluetoothGattService : public Parcelable, public ::bluetooth::Service { public: BluetoothGattService() = default; - BluetoothGattService(const ::bluetooth::Service& service) : ::bluetooth::Service(service){}; // NOLINT(implicit) - BluetoothGattService(const BluetoothGattIncludedService& includedService) // NOLINT(implicit) - : ::bluetooth::Service(includedService.handle(), includedService.primary(), - includedService.uuid(), {}, {}) {}; + BluetoothGattService(const ::bluetooth::Service& service) + : ::bluetooth::Service(service){}; // NOLINT(implicit) + BluetoothGattService( + const BluetoothGattIncludedService& includedService) // NOLINT(implicit) + : ::bluetooth::Service(includedService.handle(), + includedService.primary(), includedService.uuid(), + {}, {}){}; ~BluetoothGattService() = default; // Write |this| parcelable to the given |parcel|. Keep in mind that diff --git a/service/common/android/bluetooth/scan_filter.cc b/service/common/android/bluetooth/scan_filter.cc index 514b93281..bf9eaf2db 100644 --- a/service/common/android/bluetooth/scan_filter.cc +++ b/service/common/android/bluetooth/scan_filter.cc @@ -39,7 +39,7 @@ status_t ScanFilter::writeToParcel(Parcel* parcel) const { status = parcel->writeString16(String16(String8(device_address_.c_str()))); if (status != OK) return status; - //TODO(jpawlowski) make type casting nicer + // TODO(jpawlowski) make type casting nicer // uuid won't really keep ownership, it's just for type casting std::unique_ptr uuid; UUID tmp; diff --git a/service/common/android/bluetooth/scan_filter.h b/service/common/android/bluetooth/scan_filter.h index 90dcbd924..c14f39243 100644 --- a/service/common/android/bluetooth/scan_filter.h +++ b/service/common/android/bluetooth/scan_filter.h @@ -32,7 +32,7 @@ class ScanFilter : public Parcelable, public ::bluetooth::ScanFilter { public: ScanFilter() = default; // NOLINT, implicit converter - ScanFilter(const ::bluetooth::ScanFilter& scan_filter) // NOLINT + ScanFilter(const ::bluetooth::ScanFilter& scan_filter) // NOLINT : ::bluetooth::ScanFilter(scan_filter){}; ~ScanFilter() = default; diff --git a/service/common/android/bluetooth/scan_settings.h b/service/common/android/bluetooth/scan_settings.h index bae0125bf..14b8bd56b 100644 --- a/service/common/android/bluetooth/scan_settings.h +++ b/service/common/android/bluetooth/scan_settings.h @@ -32,7 +32,7 @@ class ScanSettings : public Parcelable, public ::bluetooth::ScanSettings { public: ScanSettings() = default; // NOLINT, implicit converter - ScanSettings(const ::bluetooth::ScanSettings& scan_settings) // NOLINT + ScanSettings(const ::bluetooth::ScanSettings& scan_settings) // NOLINT : ::bluetooth::ScanSettings(scan_settings){}; ~ScanSettings() = default; diff --git a/service/common/bluetooth/adapter_state.cc b/service/common/bluetooth/adapter_state.cc index 87d23b1d2..9ca599873 100644 --- a/service/common/bluetooth/adapter_state.cc +++ b/service/common/bluetooth/adapter_state.cc @@ -20,24 +20,24 @@ namespace bluetooth { std::string AdapterStateToString(AdapterState state) { switch (state) { - case ADAPTER_STATE_DISCONNECTED: - return "ADAPTER_STATE_DISCONNECTED"; - case ADAPTER_STATE_CONNECTING: - return "ADAPTER_STATE_CONNECTING"; - case ADAPTER_STATE_CONNECTED: - return "ADAPTER_STATE_CONNECTED"; - case ADAPTER_STATE_DISCONNECTING: - return "ADAPTER_STATE_DISCONNECTING"; - case ADAPTER_STATE_OFF: - return "ADAPTER_STATE_OFF"; - case ADAPTER_STATE_TURNING_ON: - return "ADAPTER_STATE_TURNING_ON"; - case ADAPTER_STATE_ON: - return "ADAPTER_STATE_ON"; - case ADAPTER_STATE_TURNING_OFF: - return "ADAPTER_STATE_TURNING_OFF"; - default: - return "unknown state"; + case ADAPTER_STATE_DISCONNECTED: + return "ADAPTER_STATE_DISCONNECTED"; + case ADAPTER_STATE_CONNECTING: + return "ADAPTER_STATE_CONNECTING"; + case ADAPTER_STATE_CONNECTED: + return "ADAPTER_STATE_CONNECTED"; + case ADAPTER_STATE_DISCONNECTING: + return "ADAPTER_STATE_DISCONNECTING"; + case ADAPTER_STATE_OFF: + return "ADAPTER_STATE_OFF"; + case ADAPTER_STATE_TURNING_ON: + return "ADAPTER_STATE_TURNING_ON"; + case ADAPTER_STATE_ON: + return "ADAPTER_STATE_ON"; + case ADAPTER_STATE_TURNING_OFF: + return "ADAPTER_STATE_TURNING_OFF"; + default: + return "unknown state"; } } diff --git a/service/common/bluetooth/advertise_settings.cc b/service/common/bluetooth/advertise_settings.cc index ffe65ea11..ca3428cc2 100644 --- a/service/common/bluetooth/advertise_settings.cc +++ b/service/common/bluetooth/advertise_settings.cc @@ -18,36 +18,28 @@ namespace bluetooth { -AdvertiseSettings::AdvertiseSettings( - Mode mode, - base::TimeDelta timeout, - TxPowerLevel tx_power_level, - bool connectable) +AdvertiseSettings::AdvertiseSettings(Mode mode, base::TimeDelta timeout, + TxPowerLevel tx_power_level, + bool connectable) : mode_(mode), timeout_(timeout), tx_power_level_(tx_power_level), - connectable_(connectable) { -} + connectable_(connectable) {} // Default values are taken from the AdvertiseSettings.java AdvertiseSettings::AdvertiseSettings() : mode_(MODE_LOW_POWER), tx_power_level_(TX_POWER_LEVEL_MEDIUM), - connectable_(true) { -} + connectable_(true) {} bool AdvertiseSettings::operator==(const AdvertiseSettings& rhs) const { - if (mode_ != rhs.mode_) - return false; + if (mode_ != rhs.mode_) return false; - if (timeout_ != rhs.timeout_) - return false; + if (timeout_ != rhs.timeout_) return false; - if (tx_power_level_ != rhs.tx_power_level_) - return false; + if (tx_power_level_ != rhs.tx_power_level_) return false; - if (connectable_ != rhs.connectable_) - return false; + if (connectable_ != rhs.connectable_) return false; return true; } diff --git a/service/common/bluetooth/advertise_settings.h b/service/common/bluetooth/advertise_settings.h index 6e787c157..bd3764dbe 100644 --- a/service/common/bluetooth/advertise_settings.h +++ b/service/common/bluetooth/advertise_settings.h @@ -61,10 +61,8 @@ class AdvertiseSettings { TX_POWER_LEVEL_HIGH = 0x03, }; - AdvertiseSettings(Mode mode, - base::TimeDelta timeout, - TxPowerLevel tx_power_level, - bool connectable); + AdvertiseSettings(Mode mode, base::TimeDelta timeout, + TxPowerLevel tx_power_level, bool connectable); // The default constructor sets all fields to defaults: // mode: MODE_LOW_POWER diff --git a/service/common/bluetooth/characteristic.cc b/service/common/bluetooth/characteristic.cc index 4968d331a..492a63a89 100644 --- a/service/common/bluetooth/characteristic.cc +++ b/service/common/bluetooth/characteristic.cc @@ -39,7 +39,8 @@ Characteristic& Characteristic::operator=(const Characteristic& other) { bool Characteristic::Equals(const Characteristic& other) const { return handle_ == other.handle_ && uuid_ == other.uuid_ && - properties_ == other.properties_ && permissions_ == other.permissions_ && + properties_ == other.properties_ && + permissions_ == other.permissions_ && descriptors_ == other.descriptors_; } diff --git a/service/common/bluetooth/characteristic.h b/service/common/bluetooth/characteristic.h index b0a4aa05f..a68270a84 100644 --- a/service/common/bluetooth/characteristic.h +++ b/service/common/bluetooth/characteristic.h @@ -26,12 +26,14 @@ class Characteristic { public: Characteristic() = default; Characteristic(const Characteristic& other); - Characteristic(uint16_t handle, const UUID& uuid, - uint8_t properties, uint16_t permissions, + Characteristic(uint16_t handle, const UUID& uuid, uint8_t properties, + uint16_t permissions, const std::vector& descriptors) - : handle_(handle), uuid_(uuid), - properties_(properties), permissions_(permissions), - descriptors_(descriptors) {}; + : handle_(handle), + uuid_(uuid), + properties_(properties), + permissions_(permissions), + descriptors_(descriptors){}; Characteristic& operator=(const Characteristic& other); ~Characteristic() = default; diff --git a/service/common/bluetooth/descriptor.h b/service/common/bluetooth/descriptor.h index a1cd8b9be..90c021d60 100644 --- a/service/common/bluetooth/descriptor.h +++ b/service/common/bluetooth/descriptor.h @@ -25,7 +25,7 @@ class Descriptor { Descriptor(const Descriptor& other); Descriptor& operator=(const Descriptor& other); Descriptor(uint16_t handle, const UUID& uuid, uint16_t permissions) - : handle_(handle), uuid_(uuid), permissions_(permissions) {}; + : handle_(handle), uuid_(uuid), permissions_(permissions){}; ~Descriptor() = default; // Comparison function and operator. diff --git a/service/common/bluetooth/low_energy_constants.h b/service/common/bluetooth/low_energy_constants.h index 1f8d3ebf3..81cf0dda9 100644 --- a/service/common/bluetooth/low_energy_constants.h +++ b/service/common/bluetooth/low_energy_constants.h @@ -55,11 +55,7 @@ enum GATTError { GATT_ERROR_OUT_OF_RANGE = 0xFF }; -enum Transport { - TRANSPORT_AUTO = 0, - TRANSPORT_BREDR = 1, - TRANSPORT_LE = 2 -}; +enum Transport { TRANSPORT_AUTO = 0, TRANSPORT_BREDR = 1, TRANSPORT_LE = 2 }; // Android attribute permission values const uint16_t kAttributePermissionNone = 0x0; diff --git a/service/common/bluetooth/scan_filter.cc b/service/common/bluetooth/scan_filter.cc index beeeedcf2..c0b737514 100644 --- a/service/common/bluetooth/scan_filter.cc +++ b/service/common/bluetooth/scan_filter.cc @@ -24,8 +24,7 @@ ScanFilter::ScanFilter(const ScanFilter& other) { device_name_ = other.device_name_; device_address_ = other.device_address_; - if (other.service_uuid_) - service_uuid_.reset(new UUID(*other.service_uuid_)); + if (other.service_uuid_) service_uuid_.reset(new UUID(*other.service_uuid_)); if (other.service_uuid_mask_) service_uuid_mask_.reset(new UUID(*other.service_uuid_mask_)); @@ -49,8 +48,7 @@ ScanFilter& ScanFilter::operator=(const ScanFilter& other) { } bool ScanFilter::SetDeviceAddress(const std::string& device_address) { - if (!util::IsAddressValid(device_address)) - return false; + if (!util::IsAddressValid(device_address)) return false; device_address_ = device_address; return true; @@ -68,16 +66,13 @@ void ScanFilter::SetServiceUuidWithMask(const UUID& service_uuid, } bool ScanFilter::operator==(const ScanFilter& rhs) const { - if (device_name_ != rhs.device_name_) - return false; + if (device_name_ != rhs.device_name_) return false; - if (device_address_ != rhs.device_address_) - return false; + if (device_address_ != rhs.device_address_) return false; // Both must be either NULL or non-NULL. If only one of them is NULL, then // return false. - if (!!service_uuid_ != !!rhs.service_uuid_) - return false; + if (!!service_uuid_ != !!rhs.service_uuid_) return false; if (service_uuid_ && rhs.service_uuid_ && *service_uuid_ != *rhs.service_uuid_) @@ -85,8 +80,7 @@ bool ScanFilter::operator==(const ScanFilter& rhs) const { // Both must be either NULL or non-NULL. If only one of them is NULL, then // return false. - if (!!service_uuid_mask_ != !!rhs.service_uuid_mask_) - return false; + if (!!service_uuid_mask_ != !!rhs.service_uuid_mask_) return false; if (service_uuid_mask_ && rhs.service_uuid_mask_ && *service_uuid_mask_ != *rhs.service_uuid_mask_) diff --git a/service/common/bluetooth/scan_result.cc b/service/common/bluetooth/scan_result.cc index 9e28e416d..099cac7ea 100644 --- a/service/common/bluetooth/scan_result.cc +++ b/service/common/bluetooth/scan_result.cc @@ -20,28 +20,21 @@ #include "service/common/bluetooth/util/address_helper.h" - namespace bluetooth { ScanResult::ScanResult(const std::string& device_address, - const std::vector& scan_record, - int rssi) - : device_address_(device_address), - scan_record_(scan_record), - rssi_(rssi) { + const std::vector& scan_record, int rssi) + : device_address_(device_address), scan_record_(scan_record), rssi_(rssi) { CHECK(util::IsAddressValid(device_address)) << "Invalid BD_ADDR given: " << device_address; } bool ScanResult::operator==(const ScanResult& rhs) const { - if (device_address_ != rhs.device_address_) - return false; + if (device_address_ != rhs.device_address_) return false; - if (scan_record_ != rhs.scan_record_) - return false; + if (scan_record_ != rhs.scan_record_) return false; - if (rssi_ != rhs.rssi_) - return false; + if (rssi_ != rhs.rssi_) return false; return true; } diff --git a/service/common/bluetooth/scan_result.h b/service/common/bluetooth/scan_result.h index 9be25b530..67240c28d 100644 --- a/service/common/bluetooth/scan_result.h +++ b/service/common/bluetooth/scan_result.h @@ -28,8 +28,7 @@ namespace bluetooth { class ScanResult { public: ScanResult(const std::string& device_address, - const std::vector& scan_record, - int rssi); + const std::vector& scan_record, int rssi); ScanResult() = default; ~ScanResult() = default; diff --git a/service/common/bluetooth/scan_settings.cc b/service/common/bluetooth/scan_settings.cc index 2c807c00b..a405a285a 100644 --- a/service/common/bluetooth/scan_settings.cc +++ b/service/common/bluetooth/scan_settings.cc @@ -22,42 +22,32 @@ ScanSettings::ScanSettings() : mode_(MODE_LOW_POWER), callback_type_(CALLBACK_TYPE_ALL_MATCHES), result_type_(RESULT_TYPE_FULL), - match_count_per_filter_(MATCH_COUNT_MAX_ADVERTISEMENTS) { -} + match_count_per_filter_(MATCH_COUNT_MAX_ADVERTISEMENTS) {} -ScanSettings::ScanSettings( - Mode mode, - CallbackTypeBitField callback_type, - ResultType result_type, - base::TimeDelta report_delay_ms, - MatchMode match_mode, - MatchCount match_count_per_filter) +ScanSettings::ScanSettings(Mode mode, CallbackTypeBitField callback_type, + ResultType result_type, + base::TimeDelta report_delay_ms, + MatchMode match_mode, + MatchCount match_count_per_filter) : mode_(mode), callback_type_(callback_type), result_type_(result_type), report_delay_ms_(report_delay_ms), match_mode_(match_mode), - match_count_per_filter_(match_count_per_filter) { -} + match_count_per_filter_(match_count_per_filter) {} bool ScanSettings::operator==(const ScanSettings& rhs) const { - if (mode_ != rhs.mode_) - return false; + if (mode_ != rhs.mode_) return false; - if (callback_type_ != rhs.callback_type_) - return false; + if (callback_type_ != rhs.callback_type_) return false; - if (result_type_ != rhs.result_type_) - return false; + if (result_type_ != rhs.result_type_) return false; - if (report_delay_ms_ != rhs.report_delay_ms_) - return false; + if (report_delay_ms_ != rhs.report_delay_ms_) return false; - if (match_mode_ != rhs.match_mode_) - return false; + if (match_mode_ != rhs.match_mode_) return false; - if (match_count_per_filter_ != rhs.match_count_per_filter_) - return false; + if (match_count_per_filter_ != rhs.match_count_per_filter_) return false; return true; } diff --git a/service/common/bluetooth/scan_settings.h b/service/common/bluetooth/scan_settings.h index 7771ac92e..02d7eb819 100644 --- a/service/common/bluetooth/scan_settings.h +++ b/service/common/bluetooth/scan_settings.h @@ -113,12 +113,9 @@ class ScanSettings { // match_mode: MATCH_MODE_AGGRESSIVE // match_count_per_filter: MATCH_COUNT_MAX_ADVERTISEMENTS ScanSettings(); - ScanSettings(Mode mode, - CallbackTypeBitField callback_type, - ResultType result_type, - base::TimeDelta report_delay_ms, - MatchMode match_mode, - MatchCount match_count_per_filter); + ScanSettings(Mode mode, CallbackTypeBitField callback_type, + ResultType result_type, base::TimeDelta report_delay_ms, + MatchMode match_mode, MatchCount match_count_per_filter); ~ScanSettings() = default; // Returns the scan mode. diff --git a/service/common/bluetooth/service.cc b/service/common/bluetooth/service.cc index b5f9a75ab..6a8a0c335 100644 --- a/service/common/bluetooth/service.cc +++ b/service/common/bluetooth/service.cc @@ -37,10 +37,8 @@ Service& Service::operator=(const Service& other) { } bool Service::Equals(const Service& other) const { - return handle_ == other.handle_ && - primary_ == other.primary_ && - uuid_ == other.uuid_ && - characteristics_ == other.characteristics_ && + return handle_ == other.handle_ && primary_ == other.primary_ && + uuid_ == other.uuid_ && characteristics_ == other.characteristics_ && included_services_ == other.included_services_; } diff --git a/service/common/bluetooth/service.h b/service/common/bluetooth/service.h index 19fbadc6b..194954656 100644 --- a/service/common/bluetooth/service.h +++ b/service/common/bluetooth/service.h @@ -29,9 +29,11 @@ class Service { Service(uint16_t handle, bool primary, const UUID& uuid, const std::vector& characteristics, const std::vector& included_services) - : handle_(handle), primary_(primary), uuid_(uuid), + : handle_(handle), + primary_(primary), + uuid_(uuid), characteristics_(characteristics), - included_services_(included_services) {}; + included_services_(included_services){}; Service& operator=(const Service& other); ~Service() = default; @@ -46,9 +48,7 @@ class Service { const std::vector& characteristics() const { return characteristics_; } - std::vector& characteristics() { - return characteristics_; - } + std::vector& characteristics() { return characteristics_; } const std::vector& included_services() const { return included_services_; } diff --git a/service/common/bluetooth/util/address_helper.cc b/service/common/bluetooth/util/address_helper.cc index 51f896273..17aeccec5 100644 --- a/service/common/bluetooth/util/address_helper.cc +++ b/service/common/bluetooth/util/address_helper.cc @@ -31,25 +31,21 @@ bool IsAddressValid(const std::string& address) { bool BdAddrFromString(const std::string& address, bt_bdaddr_t* out_addr) { CHECK(out_addr); - if (address.length() != 17) - return false; + if (address.length() != 17) return false; std::vector byte_tokens = base::SplitString( address, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (byte_tokens.size() != 6) - return false; + if (byte_tokens.size() != 6) return false; for (int i = 0; i < 6; i++) { const auto& token = byte_tokens[i]; - if (token.length() != 2) - return false; + if (token.length() != 2) return false; char* temp = nullptr; out_addr->address[i] = strtol(token.c_str(), &temp, 16); - if (*temp != '\0') - return false; + if (*temp != '\0') return false; } return true; diff --git a/service/common/bluetooth/util/atomic_string.cc b/service/common/bluetooth/util/atomic_string.cc index 008470091..fd71a5b17 100644 --- a/service/common/bluetooth/util/atomic_string.cc +++ b/service/common/bluetooth/util/atomic_string.cc @@ -18,9 +18,7 @@ namespace util { -AtomicString::AtomicString(const std::string& str) - : str_(str) { -} +AtomicString::AtomicString(const std::string& str) : str_(str) {} std::string AtomicString::Get() const { std::mutex* mutex = const_cast(&lock_); diff --git a/service/common/bluetooth/uuid.cc b/service/common/bluetooth/uuid.cc index 575b055c0..b7ae9e50e 100644 --- a/service/common/bluetooth/uuid.cc +++ b/service/common/bluetooth/uuid.cc @@ -22,18 +22,17 @@ #include #include -#include #include #include +#include namespace bluetooth { namespace { -const UUID::UUID128Bit kSigBaseUUID = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } -}; +const UUID::UUID128Bit kSigBaseUUID = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, + 0x5f, 0x9b, 0x34, 0xfb}}; } // namespace @@ -64,38 +63,28 @@ void UUID::InitializeDefault() { is_valid_ = true; } -UUID::UUID() { - InitializeDefault(); -} +UUID::UUID() { InitializeDefault(); } UUID::UUID(std::string uuid) { InitializeDefault(); is_valid_ = false; - if (uuid.empty()) - return; + if (uuid.empty()) return; - if (uuid.size() < 11 && uuid.find("0x") == 0) - uuid = uuid.substr(2); + if (uuid.size() < 11 && uuid.find("0x") == 0) uuid = uuid.substr(2); - if (uuid.size() != 4 && uuid.size() != 8 && uuid.size() != 36) - return; + if (uuid.size() != 4 && uuid.size() != 8 && uuid.size() != 36) return; if (uuid.size() == 36) { - if (uuid[8] != '-') - return; - if (uuid[13] != '-') - return; - if (uuid[18] != '-') - return; - if (uuid[23] != '-') - return; + if (uuid[8] != '-') return; + if (uuid[13] != '-') return; + if (uuid[18] != '-') return; + if (uuid[23] != '-') return; std::vector tokens = base::SplitString( uuid, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); - if (tokens.size() != 5) - return; + if (tokens.size() != 5) return; uuid = base::JoinString(tokens, ""); } @@ -103,11 +92,10 @@ UUID::UUID(std::string uuid) { const int start_index = uuid.size() == 4 ? 2 : 0; const size_t copy_size = std::min(id_.size(), uuid.size() / 2); for (size_t i = 0; i < copy_size; ++i) { - std::string octet_text(uuid, i * 2, 2); - char* temp = nullptr; - id_[start_index + i] = strtol(octet_text.c_str(), &temp, 16); - if (*temp != '\0') - return; + std::string octet_text(uuid, i * 2, 2); + char* temp = nullptr; + id_[start_index + i] = strtol(octet_text.c_str(), &temp, 16); + if (*temp != '\0') return; } is_valid_ = true; @@ -130,9 +118,7 @@ UUID::UUID(const UUID32Bit& uuid) { UUID::UUID(const UUID128Bit& uuid) : id_(uuid), is_valid_(true) {} -UUID::UUID128Bit UUID::GetFullBigEndian() const { - return id_; -} +UUID::UUID128Bit UUID::GetFullBigEndian() const { return id_; } UUID::UUID128Bit UUID::GetFullLittleEndian() const { UUID::UUID128Bit ret; @@ -149,18 +135,15 @@ bt_uuid_t UUID::GetBlueDroid() const { std::string UUID::ToString() const { return base::StringPrintf( "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - id_[0], id_[1], id_[2], id_[3], - id_[4], id_[5], id_[6], id_[7], - id_[8], id_[9], id_[10], id_[11], - id_[12], id_[13], id_[14], id_[15]); + id_[0], id_[1], id_[2], id_[3], id_[4], id_[5], id_[6], id_[7], id_[8], + id_[9], id_[10], id_[11], id_[12], id_[13], id_[14], id_[15]); } size_t UUID::GetShortestRepresentationSize() const { if (memcmp(id_.data() + 4, kSigBaseUUID.data() + 4, id_.size() - 4) != 0) return kNumBytes128; - if (id_[0] == 0 && id_[1] == 0) - return kNumBytes16; + if (id_[0] == 0 && id_[1] == 0) return kNumBytes16; return kNumBytes32; } diff --git a/service/common/bluetooth/uuid.h b/service/common/bluetooth/uuid.h index d3028c8e0..57dec0a3c 100644 --- a/service/common/bluetooth/uuid.h +++ b/service/common/bluetooth/uuid.h @@ -78,9 +78,7 @@ class UUID { bool operator<(const UUID& rhs) const; bool operator==(const UUID& rhs) const; - inline bool operator!=(const UUID& rhs) const { - return !(*this == rhs); - } + inline bool operator!=(const UUID& rhs) const { return !(*this == rhs); } protected: void InitializeDefault(); @@ -98,12 +96,12 @@ class UUID { // in std::unordered_map. namespace std { -template<> +template <> struct hash { std::size_t operator()(const bluetooth::UUID& key) const { const auto& uuid_bytes = key.GetFullBigEndian(); std::hash hash_fn; - return hash_fn(std::string((char *)uuid_bytes.data(), uuid_bytes.size())); + return hash_fn(std::string((char*)uuid_bytes.data(), uuid_bytes.size())); } }; diff --git a/service/daemon.cc b/service/daemon.cc index 0439c3666..bc022d219 100644 --- a/service/daemon.cc +++ b/service/daemon.cc @@ -35,23 +35,17 @@ Daemon* g_daemon = nullptr; class DaemonImpl : public Daemon { public: - DaemonImpl() : initialized_(false) { - } + DaemonImpl() : initialized_(false) {} ~DaemonImpl() override { - if (!initialized_) - return; + if (!initialized_) return; CleanUpBluetoothStack(); } - void StartMainLoop() override { - message_loop_->Run(); - } + void StartMainLoop() override { message_loop_->Run(); } - Settings* GetSettings() const override { - return settings_.get(); - } + Settings* GetSettings() const override { return settings_.get(); } base::MessageLoop* GetMessageLoop() const override { return message_loop_.get(); @@ -59,11 +53,9 @@ class DaemonImpl : public Daemon { private: bool StartUpBluetoothInterfaces() { - if (!hal::BluetoothInterface::Initialize()) - goto failed; + if (!hal::BluetoothInterface::Initialize()) goto failed; - if (!hal::BluetoothGattInterface::Initialize()) - goto failed; + if (!hal::BluetoothGattInterface::Initialize()) goto failed; return true; @@ -147,8 +139,7 @@ bool Daemon::Initialize() { CHECK(!g_daemon); g_daemon = new DaemonImpl(); - if (g_daemon->Init()) - return true; + if (g_daemon->Init()) return true; LOG(ERROR) << "Failed to initialize the Daemon object"; diff --git a/service/daemon.h b/service/daemon.h index c792dfc79..0afefa9c5 100644 --- a/service/daemon.h +++ b/service/daemon.h @@ -51,7 +51,7 @@ class Daemon { // The global Settings object. All classes have direct access to this through // the Daemon object. - virtual Settings* GetSettings() const = 0; + virtual Settings* GetSettings() const = 0; // The main event loop. This should be used for any events and delayed tasks // that should be executed on the daemon's main thread. diff --git a/service/example/heart_rate/heart_rate_server.cc b/service/example/heart_rate/heart_rate_server.cc index e1ae7f64c..01aeb9959 100644 --- a/service/example/heart_rate/heart_rate_server.cc +++ b/service/example/heart_rate/heart_rate_server.cc @@ -39,13 +39,15 @@ namespace heart_rate { class CLIBluetoothLeAdvertiserCallback : public android::bluetooth::BnBluetoothLeAdvertiserCallback { public: - explicit CLIBluetoothLeAdvertiserCallback(android::sp bt) + explicit CLIBluetoothLeAdvertiserCallback( + android::sp bt) : bt_(bt) {} // IBluetoothLeAdvertiserCallback overrides: Status OnAdvertiserRegistered(int status, int advertiser_id) { if (status != bluetooth::BLE_STATUS_SUCCESS) { - LOG(ERROR) << "Failed to register BLE advertiser, will not start advertising"; + LOG(ERROR) + << "Failed to register BLE advertiser, will not start advertising"; return Status::ok(); } @@ -56,9 +58,10 @@ class CLIBluetoothLeAdvertiserCallback std::string name(String8(name_param).string()); /* Advertising data: 16-bit Service UUID: Heart Rate Service, Tx power*/ - std::vector data{ - 0x03, bluetooth::kEIRTypeComplete16BitUUIDs, 0x0D, 0x18, - 0x02, bluetooth::kEIRTypeTxPower, 0x00}; + std::vector data{0x03, bluetooth::kEIRTypeComplete16BitUUIDs, + 0x0D, 0x18, + 0x02, bluetooth::kEIRTypeTxPower, + 0x00}; data.push_back(name.length() + 1); data.push_back(bluetooth::kEIRTypeCompleteLocalName); data.insert(data.begin(), name.c_str(), name.c_str() + name.length()); @@ -92,7 +95,6 @@ class CLIBluetoothLeAdvertiserCallback DISALLOW_COPY_AND_ASSIGN(CLIBluetoothLeAdvertiserCallback); }; - HeartRateServer::HeartRateServer( android::sp bluetooth, scoped_refptr main_task_runner, @@ -239,16 +241,30 @@ Status HeartRateServer::OnServerRegistered(int status, int server_if) { LOG(INFO) << "Heart Rate server registered - server_if: " << server_if_; - bluetooth::Service hrService(0, true, kHRServiceUUID, { - {0, kHRMeasurementUUID, bluetooth::kCharacteristicPropertyNotify, 0, - { {0, kCCCDescriptorUUID, (bluetooth::kAttributePermissionRead | bluetooth::kAttributePermissionWrite)}} }, - {0, kBodySensorLocationUUID, bluetooth::kCharacteristicPropertyRead, bluetooth::kAttributePermissionRead, {}}, - {0, kHRControlPointUUID, bluetooth::kCharacteristicPropertyWrite, bluetooth::kAttributePermissionWrite, {}} - }, {}); + bluetooth::Service hrService( + 0, true, kHRServiceUUID, + {{0, + kHRMeasurementUUID, + bluetooth::kCharacteristicPropertyNotify, + 0, + {{0, kCCCDescriptorUUID, (bluetooth::kAttributePermissionRead | + bluetooth::kAttributePermissionWrite)}}}, + {0, + kBodySensorLocationUUID, + bluetooth::kCharacteristicPropertyRead, + bluetooth::kAttributePermissionRead, + {}}, + {0, + kHRControlPointUUID, + bluetooth::kCharacteristicPropertyWrite, + bluetooth::kAttributePermissionWrite, + {}}}, + {}); bool op_status = true; - Status stat = gatt_->AddService(server_if_, (BluetoothGattService)hrService, &op_status); + Status stat = gatt_->AddService(server_if_, (BluetoothGattService)hrService, + &op_status); if (!stat.isOk()) { LOG(ERROR) << "Failed to add service, status is: " /*<< stat*/; pending_run_cb_(false); @@ -289,7 +305,8 @@ Status HeartRateServer::OnServiceAdded( android::sp ble; bluetooth_->GetLeAdvertiserInterface(&ble); bool status; - ble->RegisterAdvertiser(new CLIBluetoothLeAdvertiserCallback(bluetooth_), &status); + ble->RegisterAdvertiser(new CLIBluetoothLeAdvertiserCallback(bluetooth_), + &status); } return Status::ok(); @@ -298,7 +315,6 @@ Status HeartRateServer::OnServiceAdded( Status HeartRateServer::OnCharacteristicReadRequest( const String16& device_address, int request_id, int offset, bool /* is_long */, int handle) { - std::lock_guard lock(mutex_); // This is where we handle an incoming characteristic read. Only the body @@ -318,9 +334,10 @@ Status HeartRateServer::OnCharacteristicReadRequest( return Status::ok(); } -Status HeartRateServer::OnDescriptorReadRequest( - const String16& device_address, int request_id, int offset, - bool /* is_long */, int handle) { +Status HeartRateServer::OnDescriptorReadRequest(const String16& device_address, + int request_id, int offset, + bool /* is_long */, + int handle) { std::lock_guard lock(mutex_); // This is where we handle an incoming characteristic descriptor read. There @@ -472,7 +489,7 @@ Status HeartRateServer::OnNotificationSent(const String16& device_address, Status HeartRateServer::OnConnectionStateChanged(const String16& device_address, bool connected) { LOG(INFO) << "Connection state changed - device: " << device_address - << " connected: " << (connected? "true" : "false"); + << " connected: " << (connected ? "true" : "false"); return Status::ok(); } } // namespace heart_rate diff --git a/service/example/heart_rate/heart_rate_server.h b/service/example/heart_rate/heart_rate_server.h index b2476533b..c7df8a11c 100644 --- a/service/example/heart_rate/heart_rate_server.h +++ b/service/example/heart_rate/heart_rate_server.h @@ -56,21 +56,23 @@ class HeartRateServer // ipc::binder::IBluetoothGattServerCallback override: Status OnServerRegistered(int status, int server_id) override; Status OnServiceAdded( - int status, const android::bluetooth::BluetoothGattService& service) override; - Status OnCharacteristicReadRequest( - const String16& device_address, int request_id, int offset, bool is_long, - int handle) override; - Status OnDescriptorReadRequest( - const String16& device_address, int request_id, int offset, bool is_long, - int handle) override; - Status OnCharacteristicWriteRequest( - const String16& device_address, int request_id, int offset, - bool is_prepare_write, bool need_response, - const std::vector& value, int handle) override; - Status OnDescriptorWriteRequest( - const String16& device_address, int request_id, int offset, - bool is_prepare_write, bool need_response, - const std::vector& value, int handle) override; + int status, + const android::bluetooth::BluetoothGattService& service) override; + Status OnCharacteristicReadRequest(const String16& device_address, + int request_id, int offset, bool is_long, + int handle) override; + Status OnDescriptorReadRequest(const String16& device_address, int request_id, + int offset, bool is_long, int handle) override; + Status OnCharacteristicWriteRequest(const String16& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + int handle) override; + Status OnDescriptorWriteRequest(const String16& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + int handle) override; Status OnExecuteWriteRequest(const String16& device_address, int request_id, bool is_execute) override; Status OnNotificationSent(const String16& device_address, diff --git a/service/gatt_client.cc b/service/gatt_client.cc index a8f48c86c..0567dd7f6 100644 --- a/service/gatt_client.cc +++ b/service/gatt_client.cc @@ -27,25 +27,20 @@ namespace bluetooth { // ======================================================== GattClient::GattClient(const UUID& uuid, int client_id) - : app_identifier_(uuid), - client_id_(client_id) { -} + : app_identifier_(uuid), client_id_(client_id) {} GattClient::~GattClient() { // Automatically unregister the client. VLOG(1) << "GattClient unregistering client: " << client_id_; - hal::BluetoothGattInterface::Get()->GetClientHALInterface()-> - unregister_client(client_id_); + hal::BluetoothGattInterface::Get() + ->GetClientHALInterface() + ->unregister_client(client_id_); } -const UUID& GattClient::GetAppIdentifier() const { - return app_identifier_; -} +const UUID& GattClient::GetAppIdentifier() const { return app_identifier_; } -int GattClient::GetInstanceId() const { - return client_id_; -} +int GattClient::GetInstanceId() const { return client_id_; } // GattClientFactory implementation // ======================================================== @@ -58,9 +53,8 @@ GattClientFactory::~GattClientFactory() { hal::BluetoothGattInterface::Get()->RemoveClientObserver(this); } -bool GattClientFactory::RegisterInstance( - const UUID& uuid, - const RegisterCallback& callback) { +bool GattClientFactory::RegisterInstance(const UUID& uuid, + const RegisterCallback& callback) { VLOG(1) << __func__ << " - UUID: " << uuid.ToString(); lock_guard lock(pending_calls_lock_); @@ -74,8 +68,7 @@ bool GattClientFactory::RegisterInstance( hal::BluetoothGattInterface::Get()->GetClientHALInterface(); bt_uuid_t app_uuid = uuid.GetBlueDroid(); - if (hal_iface->register_client(&app_uuid) != BT_STATUS_SUCCESS) - return false; + if (hal_iface->register_client(&app_uuid) != BT_STATUS_SUCCESS) return false; pending_calls_[uuid] = callback; @@ -83,8 +76,7 @@ bool GattClientFactory::RegisterInstance( } void GattClientFactory::RegisterClientCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int status, int client_id, + hal::BluetoothGattInterface* /* gatt_iface */, int status, int client_id, const bt_uuid_t& app_uuid) { UUID uuid(app_uuid); @@ -99,8 +91,7 @@ void GattClientFactory::RegisterClientCallback( // No need to construct a client if the call wasn't successful. std::unique_ptr client; - if (success) - client.reset(new GattClient(uuid, client_id)); + if (success) client.reset(new GattClient(uuid, client_id)); // Notify the result via the result callback. iter->second(result, uuid, std::move(client)); diff --git a/service/gatt_client.h b/service/gatt_client.h index eb9440532..fd83ffe9f 100644 --- a/service/gatt_client.h +++ b/service/gatt_client.h @@ -69,10 +69,9 @@ class GattClientFactory : public BluetoothInstanceFactory, private: // hal::BluetoothGattInterface::ClientObserver override: - void RegisterClientCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int client_id, - const bt_uuid_t& app_uuid) override; + void RegisterClientCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int client_id, + const bt_uuid_t& app_uuid) override; // Map of pending calls to register. std::mutex pending_calls_lock_; diff --git a/service/gatt_server.cc b/service/gatt_server.cc index 57ac6bad4..1d5977349 100644 --- a/service/gatt_server.cc +++ b/service/gatt_server.cc @@ -40,10 +40,7 @@ bool operator!=(const bt_bdaddr_t& lhs, const bt_bdaddr_t& rhs) { // ======================================================== GattServer::GattServer(const UUID& uuid, int server_id) - : app_identifier_(uuid), - server_id_(server_id), - delegate_(nullptr) { -} + : app_identifier_(uuid), server_id_(server_id), delegate_(nullptr) {} GattServer::~GattServer() { // Automatically unregister the server. @@ -55,8 +52,9 @@ GattServer::~GattServer() { // Unregister this server, stop all services, and ignore the result. // TODO(armansito): stop and remove all services here? unregister_server // should really take care of that. - hal::BluetoothGattInterface::Get()-> - GetServerHALInterface()->unregister_server(server_id_); + hal::BluetoothGattInterface::Get() + ->GetServerHALInterface() + ->unregister_server(server_id_); } void GattServer::SetDelegate(Delegate* delegate) { @@ -64,16 +62,12 @@ void GattServer::SetDelegate(Delegate* delegate) { delegate_ = delegate; } -const UUID& GattServer::GetAppIdentifier() const { - return app_identifier_; -} +const UUID& GattServer::GetAppIdentifier() const { return app_identifier_; } -int GattServer::GetInstanceId() const { - return server_id_; -} +int GattServer::GetInstanceId() const { return server_id_; } -bool GattServer::AddService( - const bluetooth::Service& service, const ResultCallback& callback) { +bool GattServer::AddService(const bluetooth::Service& service, + const ResultCallback& callback) { VLOG(1) << __func__ << " server_id: " << server_id_; lock_guard lock(mutex_); @@ -84,30 +78,30 @@ bool GattServer::AddService( std::vector svc; - svc.push_back({.type = (service.primary() ? BTGATT_DB_PRIMARY_SERVICE : BTGATT_DB_SECONDARY_SERVICE), - .uuid = service.uuid().GetBlueDroid()}); + svc.push_back({.type = (service.primary() ? BTGATT_DB_PRIMARY_SERVICE + : BTGATT_DB_SECONDARY_SERVICE), + .uuid = service.uuid().GetBlueDroid()}); - for (const auto & characteristic : service.characteristics()) { + for (const auto& characteristic : service.characteristics()) { svc.push_back({.type = BTGATT_DB_CHARACTERISTIC, - .uuid = characteristic.uuid().GetBlueDroid(), - .properties = characteristic.properties(), - .permissions = characteristic.permissions() - }); - for (const auto & descriptor : characteristic.descriptors()) + .uuid = characteristic.uuid().GetBlueDroid(), + .properties = characteristic.properties(), + .permissions = characteristic.permissions()}); + for (const auto& descriptor : characteristic.descriptors()) svc.push_back({.type = BTGATT_DB_DESCRIPTOR, - .uuid = descriptor.uuid().GetBlueDroid(), - .permissions = descriptor.permissions() - }); + .uuid = descriptor.uuid().GetBlueDroid(), + .permissions = descriptor.permissions()}); } - for (const auto & incl_svc : service.included_services()) + for (const auto& incl_svc : service.included_services()) svc.push_back({.type = BTGATT_DB_INCLUDED_SERVICE, - .attribute_handle = incl_svc.handle() }); + .attribute_handle = incl_svc.handle()}); pending_end_decl_cb_ = callback; - bt_status_t status = hal::BluetoothGattInterface::Get()-> - GetServerHALInterface()->add_service(server_id_, svc); + bt_status_t status = + hal::BluetoothGattInterface::Get()->GetServerHALInterface()->add_service( + server_id_, svc); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to initiate call to populate GATT service"; CleanUpPendingData(); @@ -117,14 +111,12 @@ bool GattServer::AddService( return true; } -bool GattServer::SendResponse( - const std::string& device_address, int request_id, - GATTError error, int offset, - const std::vector& value) { +bool GattServer::SendResponse(const std::string& device_address, int request_id, + GATTError error, int offset, + const std::vector& value) { VLOG(1) << __func__ << " - server_id: " << server_id_ << " device_address: " << device_address - << " request_id: " << request_id - << " error: " << error + << " request_id: " << request_id << " error: " << error << " offset: " << offset; lock_guard lock(mutex_); @@ -175,9 +167,10 @@ bool GattServer::SendResponse( response.attr_value.len = value.size(); } - bt_status_t result = hal::BluetoothGattInterface::Get()-> - GetServerHALInterface()->send_response( - connection->conn_id, request_id, error, &response); + bt_status_t result = + hal::BluetoothGattInterface::Get() + ->GetServerHALInterface() + ->send_response(connection->conn_id, request_id, error, &response); if (result != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to initiate call to send GATT response"; return false; @@ -188,15 +181,12 @@ bool GattServer::SendResponse( return true; } -bool GattServer::SendNotification( - const std::string& device_address, - const uint16_t handle, - bool confirm, - const std::vector& value, - const GattCallback& callback) { +bool GattServer::SendNotification(const std::string& device_address, + const uint16_t handle, bool confirm, + const std::vector& value, + const GattCallback& callback) { VLOG(1) << " - server_id: " << server_id_ - << " device_address: " << device_address - << " confirm: " << confirm; + << " device_address: " << device_address << " confirm: " << confirm; lock_guard lock(mutex_); bt_bdaddr_t addr; @@ -230,21 +220,17 @@ bool GattServer::SendNotification( // The HAL API takes char* rather const char* for |value|, so we have to // cast away the const. // TODO(armansito): Make HAL accept const char*. - bt_status_t status = hal::BluetoothGattInterface::Get()-> - GetServerHALInterface()->send_indication( - server_id_, - handle, - conn->conn_id, - confirm, - value); + bt_status_t status = hal::BluetoothGattInterface::Get() + ->GetServerHALInterface() + ->send_indication(server_id_, handle, + conn->conn_id, confirm, value); // Increment the send count if this was successful. We don't immediately // fail if the HAL returned an error. It's better to report success as long // as we sent out at least one notification to this device as // multi-transport GATT connections from the same BD_ADDR will be rare // enough already. - if (status != BT_STATUS_SUCCESS) - continue; + if (status != BT_STATUS_SUCCESS) continue; send_count++; pending_indications_[conn->conn_id] = pending_ind; @@ -260,14 +246,11 @@ bool GattServer::SendNotification( } void GattServer::ConnectionCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int server_id, - int connected, - const bt_bdaddr_t& bda) { + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int server_id, + int connected, const bt_bdaddr_t& bda) { lock_guard lock(mutex_); - if (server_id != server_id_) - return; + if (server_id != server_id_) return; std::string device_address = BtAddrString(&bda); @@ -279,14 +262,12 @@ void GattServer::ConnectionCallback( VLOG(1) << "No longer connected: " << device_address; conn_id_map_.erase(conn_id); auto iter = conn_addr_map_.find(device_address); - if (iter == conn_addr_map_.end()) - return; + if (iter == conn_addr_map_.end()) return; // Remove the appropriate connection objects in the address. for (auto conn_iter = iter->second.begin(); conn_iter != iter->second.end(); ++conn_iter) { - if ((*conn_iter)->conn_id != conn_id) - continue; + if ((*conn_iter)->conn_id != conn_id) continue; iter->second.erase(conn_iter); break; @@ -314,30 +295,33 @@ void GattServer::ConnectionCallback( delegate_->OnConnectionStateChanged(this, device_address, true); } -void GattServer::ServiceAddedCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int server_id, - vector svc) { +void GattServer::ServiceAddedCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int server_id, + vector svc) { lock_guard lock(mutex_); - if (server_id != server_id_) - return; + if (server_id != server_id_) return; - VLOG(1) << __func__ << " - status: " << status - << " server_id: " << server_id + VLOG(1) << __func__ << " - status: " << status << " server_id: " << server_id << " first handle: " << svc[0].attribute_handle << " service UUID: " << UUID(svc[0].uuid).ToString() << " count: " << svc.size(); Service service(svc[0].attribute_handle, true, UUID(svc[0].uuid), {}, {}); - for (size_t i=1; i lock(mutex_); // Check to see if we know about this connection. Otherwise ignore the // request. auto conn = GetConnection(conn_id, bda, trans_id); - if (!conn) - return; + if (!conn) return; std::string device_address = BtAddrString(&bda); @@ -390,22 +367,18 @@ void GattServer::RequestReadCharacteristicCallback( return; } - delegate_->OnCharacteristicReadRequest( - this, device_address, trans_id, offset, is_long, attribute_handle); + delegate_->OnCharacteristicReadRequest(this, device_address, trans_id, offset, + is_long, attribute_handle); } void GattServer::RequestReadDescriptorCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attribute_handle, int offset, - bool is_long) { + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attribute_handle, int offset, bool is_long) { lock_guard lock(mutex_); // Check to see if we know about this connection. Otherwise ignore the // request. auto conn = GetConnection(conn_id, bda, trans_id); - if (!conn) - return; + if (!conn) return; std::string device_address = BtAddrString(&bda); @@ -427,38 +400,32 @@ void GattServer::RequestReadDescriptorCallback( return; } - delegate_->OnDescriptorReadRequest( - this, device_address, trans_id, offset, is_long, attribute_handle); + delegate_->OnDescriptorReadRequest(this, device_address, trans_id, offset, + is_long, attribute_handle); } void GattServer::RequestWriteCharacteristicCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) { + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, + bool is_prep, vector value) { lock_guard lock(mutex_); // Check to see if we know about this connection. Otherwise ignore the // request. auto conn = GetConnection(conn_id, bda, trans_id); - if (!conn) - return; + if (!conn) return; std::string device_address = BtAddrString(&bda); VLOG(1) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id - << " BD_ADDR: " << device_address - << " attr_handle: " << attr_handle << " offset: " << offset - << " length: " << value.size() << " need_rsp: " << need_rsp - << " is_prep: " << is_prep; + << " BD_ADDR: " << device_address << " attr_handle: " << attr_handle + << " offset: " << offset << " length: " << value.size() + << " need_rsp: " << need_rsp << " is_prep: " << is_prep; // Store the request ID only if this is not a write-without-response. If // another request occurs after this with the same request ID, then we'll // simply process it normally, though that shouldn't ever happen. - if (need_rsp) - conn->request_id_to_handle[trans_id] = attr_handle; + if (need_rsp) conn->request_id_to_handle[trans_id] = attr_handle; // If there is no delegate then there is nobody to handle request. The request // will eventually timeout and we should get a connection update that @@ -471,39 +438,33 @@ void GattServer::RequestWriteCharacteristicCallback( return; } - delegate_->OnCharacteristicWriteRequest( - this, device_address, trans_id, offset, is_prep, need_rsp, - std::move(value), attr_handle); + delegate_->OnCharacteristicWriteRequest(this, device_address, trans_id, + offset, is_prep, need_rsp, + std::move(value), attr_handle); } void GattServer::RequestWriteDescriptorCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) { + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, + bool is_prep, vector value) { lock_guard lock(mutex_); // Check to see if we know about this connection. Otherwise ignore the // request. auto conn = GetConnection(conn_id, bda, trans_id); - if (!conn) - return; + if (!conn) return; std::string device_address = BtAddrString(&bda); VLOG(1) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id - << " BD_ADDR: " << device_address - << " attr_handle: " << attr_handle << " offset: " << offset - << " length: " << value.size() << " need_rsp: " << need_rsp - << " is_prep: " << is_prep; + << " BD_ADDR: " << device_address << " attr_handle: " << attr_handle + << " offset: " << offset << " length: " << value.size() + << " need_rsp: " << need_rsp << " is_prep: " << is_prep; // Store the request ID only if this is not a write-without-response. If // another request occurs after this with the same request ID, then we'll // simply process it normally, though that shouldn't ever happen. - if (need_rsp) - conn->request_id_to_handle[trans_id] = attr_handle; + if (need_rsp) conn->request_id_to_handle[trans_id] = attr_handle; // If there is no delegate then there is nobody to handle request. The request // will eventually timeout and we should get a connection update that @@ -516,22 +477,20 @@ void GattServer::RequestWriteDescriptorCallback( return; } - delegate_->OnDescriptorWriteRequest( - this, device_address, trans_id, offset, is_prep, need_rsp, - std::move(value), attr_handle); + delegate_->OnDescriptorWriteRequest(this, device_address, trans_id, offset, + is_prep, need_rsp, std::move(value), + attr_handle); } void GattServer::RequestExecWriteCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int trans_id, + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int trans_id, const bt_bdaddr_t& bda, int exec_write) { lock_guard lock(mutex_); // Check to see if we know about this connection. Otherwise ignore the // request. auto conn = GetConnection(conn_id, bda, trans_id); - if (!conn) - return; + if (!conn) return; std::string device_address = BtAddrString(&bda); @@ -557,8 +516,7 @@ void GattServer::RequestExecWriteCallback( } void GattServer::IndicationSentCallback( - hal::BluetoothGattInterface* /* gatt_iface */, - int conn_id, int status) { + hal::BluetoothGattInterface* /* gatt_iface */, int conn_id, int status) { VLOG(1) << __func__ << " conn_id: " << conn_id << " status: " << status; lock_guard lock(mutex_); @@ -571,14 +529,13 @@ void GattServer::IndicationSentCallback( std::shared_ptr pending_ind = pending_ind_iter->second; pending_indications_.erase(pending_ind_iter); - if (status == BT_STATUS_SUCCESS) - pending_ind->has_success = true; + if (status == BT_STATUS_SUCCESS) pending_ind->has_success = true; // Invoke it if this was the last reference to the confirmation callback. if (pending_ind.unique() && pending_ind->callback) { - pending_ind->callback( - pending_ind->has_success ? - GATT_ERROR_NONE : static_cast(status)); + pending_ind->callback(pending_ind->has_success + ? GATT_ERROR_NONE + : static_cast(status)); } } @@ -622,9 +579,8 @@ GattServerFactory::~GattServerFactory() { hal::BluetoothGattInterface::Get()->RemoveServerObserver(this); } -bool GattServerFactory::RegisterInstance( - const UUID& uuid, - const RegisterCallback& callback) { +bool GattServerFactory::RegisterInstance(const UUID& uuid, + const RegisterCallback& callback) { VLOG(1) << __func__ << " - UUID: " << uuid.ToString(); lock_guard lock(pending_calls_lock_); @@ -638,8 +594,7 @@ bool GattServerFactory::RegisterInstance( hal::BluetoothGattInterface::Get()->GetServerHALInterface(); bt_uuid_t app_uuid = uuid.GetBlueDroid(); - if (hal_iface->register_server(&app_uuid) != BT_STATUS_SUCCESS) - return false; + if (hal_iface->register_server(&app_uuid) != BT_STATUS_SUCCESS) return false; pending_calls_[uuid] = callback; @@ -647,8 +602,7 @@ bool GattServerFactory::RegisterInstance( } void GattServerFactory::RegisterServerCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int server_id, + hal::BluetoothGattInterface* gatt_iface, int status, int server_id, const bt_uuid_t& app_uuid) { UUID uuid(app_uuid); diff --git a/service/gatt_server.h b/service/gatt_server.h index aa0be81e8..86dd0dbcc 100644 --- a/service/gatt_server.h +++ b/service/gatt_server.h @@ -49,19 +49,19 @@ class GattServer : public BluetoothInstance, // ID |characteristic_id| from a remote device with address // |device_address|. |request_id| can be used to respond to this request by // calling SendResponse below. - virtual void OnCharacteristicReadRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) = 0; + virtual void OnCharacteristicReadRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_long, uint16_t handle) = 0; // Called when there is an incoming read request for the descriptor with // ID |descriptor_id| from a remote device with address |device_address|. // |request_id| can be used to respond to this request by // calling SendResponse below. - virtual void OnDescriptorReadRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) = 0; + virtual void OnDescriptorReadRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_long, uint16_t handle) = 0; // Called when there is an incoming write request for the characteristic // with ID |characteristic_id| from a remote device with address @@ -73,8 +73,7 @@ class GattServer : public BluetoothInstance, // should hold on to the value and either discard it or complete the write // when it receives the OnExecuteWriteRequest event. virtual void OnCharacteristicWriteRequest( - GattServer* gatt_server, - const std::string& device_address, + GattServer* gatt_server, const std::string& device_address, int request_id, int offset, bool is_prepare_write, bool need_response, const std::vector& value, uint16_t handle) = 0; @@ -88,8 +87,7 @@ class GattServer : public BluetoothInstance, // should hold on to the value and either discard it or complete the write // when it receives the OnExecuteWriteRequest event. virtual void OnDescriptorWriteRequest( - GattServer* gatt_server, - const std::string& device_address, + GattServer* gatt_server, const std::string& device_address, int request_id, int offset, bool is_prepare_write, bool need_response, const std::vector& value, uint16_t handle) = 0; @@ -97,15 +95,13 @@ class GattServer : public BluetoothInstance, // is true, then the Delegate should commit all previously prepared writes. // Otherwise, all prepared writes should be aborted. The Delegate should // call "SendResponse" to complete the procedure. - virtual void OnExecuteWriteRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, bool is_execute) = 0; + virtual void OnExecuteWriteRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, bool is_execute) = 0; - virtual void OnConnectionStateChanged( - GattServer* gatt_server, - const std::string& device_addres, - bool connected) = 0; + virtual void OnConnectionStateChanged(GattServer* gatt_server, + const std::string& device_addres, + bool connected) = 0; private: DISALLOW_COPY_AND_ASSIGN(Delegate); @@ -139,7 +135,6 @@ class GattServer : public BluetoothInstance, // we in a stuck-state where the service declaration hasn't ended? bool AddService(const bluetooth::Service&, const ResultCallback& callback); - // Sends a response for a pending notification. |request_id| and // |device_address| should match those that were received through one of the // Delegate callbacks. |value| and |offset| are used for read requests and @@ -162,8 +157,8 @@ class GattServer : public BluetoothInstance, // sends a ATT Handle-Value Confirmation packet. Otherwise, it will be run as // soon as the notification has been sent out. bool SendNotification(const std::string& device_address, - const uint16_t handle, - bool confirm, const std::vector& value, + const uint16_t handle, bool confirm, + const std::vector& value, const GattCallback& callback); private: @@ -175,9 +170,7 @@ class GattServer : public BluetoothInstance, struct Connection { Connection(int conn_id, const bt_bdaddr_t& bdaddr) : conn_id(conn_id), bdaddr(bdaddr) {} - Connection() : conn_id(-1) { - memset(&bdaddr, 0, sizeof(bdaddr)); - } + Connection() : conn_id(-1) { memset(&bdaddr, 0, sizeof(bdaddr)); } int conn_id; std::unordered_map request_id_to_handle; @@ -198,52 +191,39 @@ class GattServer : public BluetoothInstance, GattServer(const UUID& uuid, int server_id); // hal::BluetoothGattInterface::ServerObserver overrides: - void ConnectionCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int server_id, - int connected, - const bt_bdaddr_t& bda) override; - void ServiceAddedCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int server_if, - vector) override; - void ServiceStoppedCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int server_id, - int service_handle) override; + void ConnectionCallback(hal::BluetoothGattInterface* gatt_iface, int conn_id, + int server_id, int connected, + const bt_bdaddr_t& bda) override; + void ServiceAddedCallback(hal::BluetoothGattInterface* gatt_iface, int status, + int server_if, + vector) override; + void ServiceStoppedCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int server_id, + int service_handle) override; void RequestReadCharacteristicCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attribute_handle, int offset, - bool is_long) override; - void RequestReadDescriptorCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attribute_handle, int offset, + hal::BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attribute_handle, int offset, bool is_long) override; + void RequestReadDescriptorCallback(hal::BluetoothGattInterface* gatt_iface, + int conn_id, int trans_id, + const bt_bdaddr_t& bda, + int attribute_handle, int offset, + bool is_long) override; void RequestWriteCharacteristicCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) override; - void RequestWriteDescriptorCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) override; - void RequestExecWriteCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, int exec_write) override; - void IndicationSentCallback( - hal::BluetoothGattInterface* gatt_iface, - int conn_id, int status) override; + hal::BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, + bool is_prep, vector value) override; + void RequestWriteDescriptorCallback(hal::BluetoothGattInterface* gatt_iface, + int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, + int offset, bool need_rsp, bool is_prep, + vector value) override; + void RequestExecWriteCallback(hal::BluetoothGattInterface* gatt_iface, + int conn_id, int trans_id, + const bt_bdaddr_t& bda, + int exec_write) override; + void IndicationSentCallback(hal::BluetoothGattInterface* gatt_iface, + int conn_id, int status) override; // Helper function that notifies and clears the pending callback. void CleanUpPendingData(); @@ -302,10 +282,9 @@ class GattServerFactory : public BluetoothInstanceFactory, private: // hal::BluetoothGattInterface::ServerObserver override: - void RegisterServerCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int server_id, - const bt_uuid_t& app_uuid) override; + void RegisterServerCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int server_id, + const bt_uuid_t& app_uuid) override; // Map of pending calls to register. std::mutex pending_calls_lock_; diff --git a/service/gatt_server_old.cc b/service/gatt_server_old.cc index 3e195adf9..ec5f8ff84 100644 --- a/service/gatt_server_old.cc +++ b/service/gatt_server_old.cc @@ -71,7 +71,7 @@ std::unordered_set blob_index; // all operations can timeout or fail and this is best reported in an // asynchronous base::Callback. // -static bluetooth::gatt::ServerInternals *g_internal = nullptr; +static bluetooth::gatt::ServerInternals* g_internal = nullptr; enum { kPipeReadEnd = 0, kPipeWriteEnd = 1, kPipeNumEnds = 2 }; @@ -97,10 +97,8 @@ struct ServerInternals { ServerInternals(); ~ServerInternals(); int Initialize(); - bt_status_t AddCharacteristic( - const UUID& uuid, - uint8_t properties, - uint16_t permissions); + bt_status_t AddCharacteristic(const UUID& uuid, uint8_t properties, + uint16_t permissions); // This maps API attribute UUIDs to BlueDroid handles. std::map uuid_to_attribute; @@ -114,7 +112,7 @@ struct ServerInternals { ScanResults scan_results; UUID last_write; - const btgatt_interface_t *gatt; + const btgatt_interface_t* gatt; int server_if; int client_if; int service_handle; @@ -131,17 +129,20 @@ struct ServerInternals { namespace { /** Callback invoked in response to register_server */ -void RegisterServerCallback(int status, int server_if, bt_uuid_t *app_uuid) { +void RegisterServerCallback(int status, int server_if, bt_uuid_t* app_uuid) { LOG_INFO(LOG_TAG, "%s: status:%d server_if:%d app_uuid:%p", __func__, status, server_if, app_uuid); g_internal->server_if = server_if; - pending_svc_decl.push_back({.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = *app_uuid}); + pending_svc_decl.push_back( + {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = *app_uuid}); } -void ServiceAddedCallback(int status, int server_if, vector service) { +void ServiceAddedCallback(int status, int server_if, + vector service) { LOG_INFO(LOG_TAG, "%s: status:%d server_if:%d count:%zu svc_handle:%d", - __func__, status, server_if, service.size(), service[0].attribute_handle); + __func__, status, server_if, service.size(), + service[0].attribute_handle); std::lock_guard lock(g_internal->lock); g_internal->server_if = server_if; @@ -150,8 +151,8 @@ void ServiceAddedCallback(int status, int server_if, vector uint16_t prev_char_handle = 0; uint16_t prev_char_properties = 0; - for (size_t i = 1; i g_internal->characteristics[blob_attribute].notify = prev_char_properties & bluetooth::gatt::kPropertyNotify; - bluetooth::gatt::Characteristic &ctrl = + bluetooth::gatt::Characteristic& ctrl = g_internal->characteristics[control_attribute]; ctrl.next_blob.clear(); ctrl.next_blob.push_back(0); @@ -202,12 +203,13 @@ void ServiceAddedCallback(int status, int server_if, vector } } -void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, +void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, int attr_handle, int attribute_offset_octets, bool is_long) { std::lock_guard lock(g_internal->lock); - bluetooth::gatt::Characteristic &ch = g_internal->characteristics[attr_handle]; + bluetooth::gatt::Characteristic& ch = + g_internal->characteristics[attr_handle]; // Latch next_blob to blob on a 'fresh' read. if (ch.next_blob_pending && attribute_offset_octets == 0 && @@ -223,10 +225,10 @@ void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, - "%s: connection:%d (%s) reading attr:%d attribute_offset_octets:%d " - "blob_section:%u (is_long:%u)", - __func__, conn_id, addr.c_str(), attr_handle, attribute_offset_octets, - ch.blob_section, is_long); + "%s: connection:%d (%s) reading attr:%d attribute_offset_octets:%d " + "blob_section:%u (is_long:%u)", + __func__, conn_id, addr.c_str(), attr_handle, + attribute_offset_octets, ch.blob_section, is_long); btgatt_response_t response; response.attr_value.len = 0; @@ -244,21 +246,20 @@ void RequestReadCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, g_internal->gatt->server->send_response(conn_id, trans_id, 0, &response); } -void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, - int attr_handle, int attribute_offset, - bool need_rsp, bool is_prep, - vector value) { +void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, + int attr_handle, int attribute_offset, bool need_rsp, + bool is_prep, vector value) { std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, - "%s: connection:%d (%s:trans:%d) write attr:%d attribute_offset:%d " - "length:%zu " - "need_resp:%u is_prep:%u", - __func__, conn_id, addr.c_str(), trans_id, attr_handle, attribute_offset, - value.size(), need_rsp, is_prep); + "%s: connection:%d (%s:trans:%d) write attr:%d attribute_offset:%d " + "length:%zu " + "need_resp:%u is_prep:%u", + __func__, conn_id, addr.c_str(), trans_id, attr_handle, + attribute_offset, value.size(), need_rsp, is_prep); std::lock_guard lock(g_internal->lock); - bluetooth::gatt::Characteristic &ch = + bluetooth::gatt::Characteristic& ch = g_internal->characteristics[attr_handle]; ch.blob.resize(attribute_offset + value.size()); @@ -271,11 +272,11 @@ void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, ch.blob.size() == 1u) { g_internal->characteristics[target_blob->second].blob_section = ch.blob[0]; LOG_INFO(LOG_TAG, "%s: updating attribute %d blob_section to %u", __func__, - target_blob->second, ch.blob[0]); + target_blob->second, ch.blob[0]); } else if (!is_prep) { // This is a single frame characteristic write. // Notify upwards because we're done now. - const bluetooth::UUID::UUID128Bit &attr_uuid = ch.uuid.GetFullBigEndian(); + const bluetooth::UUID::UUID128Bit& attr_uuid = ch.uuid.GetFullBigEndian(); ssize_t status; OSI_NO_INTR(status = write(g_internal->pipefd[kPipeWriteEnd], attr_uuid.data(), attr_uuid.size())); @@ -301,19 +302,18 @@ void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, g_internal->gatt->server->send_response(conn_id, trans_id, 0, &response); } -void RequestExecWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, +void RequestExecWriteCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, int exec_write) { std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, "%s: connection:%d (%s:trans:%d) exec_write:%d", __func__, - conn_id, addr.c_str(), trans_id, exec_write); + conn_id, addr.c_str(), trans_id, exec_write); // This 'response' data is unused for ExecWriteResponses. // It is only used to pass BlueDroid argument validation. btgatt_response_t response = {}; g_internal->gatt->server->send_response(conn_id, trans_id, 0, &response); - if (!exec_write) - return; + if (!exec_write) return; std::lock_guard lock(g_internal->lock); // Communicate the attribute UUID as notification of a write update. @@ -327,10 +327,10 @@ void RequestExecWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, } void ConnectionCallback(int conn_id, int server_if, int connected, - bt_bdaddr_t *bda) { + bt_bdaddr_t* bda) { std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, "%s: connection:%d server_if:%d connected:%d addr:%s", - __func__, conn_id, server_if, connected, addr.c_str()); + __func__, conn_id, server_if, connected, addr.c_str()); if (connected == 1) { g_internal->connections.insert(conn_id); } else if (connected == 0) { @@ -345,9 +345,9 @@ void EnableAdvertisingCallback(uint8_t status) { g_internal->api_synchronize.notify_one(); } -void RegisterClientCallback(int status, int client_if, bt_uuid_t *app_uuid) { +void RegisterClientCallback(int status, int client_if, bt_uuid_t* app_uuid) { LOG_INFO(LOG_TAG, "%s: status:%d client_if:%d uuid[0]:%u", __func__, status, - client_if, app_uuid->uu[0]); + client_if, app_uuid->uu[0]); g_internal->client_if = client_if; // Setup our advertisement. This has no callback. @@ -360,21 +360,21 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t *app_uuid) { 0 /* no timeout */, base::Bind(&DoNothing)); } -void RegisterScannerCallback(int status, int scanner_id, bt_uuid_t *app_uuid) { +void RegisterScannerCallback(int status, int scanner_id, bt_uuid_t* app_uuid) { LOG_INFO(LOG_TAG, "%s: status:%d scanner_id:%d uuid[0]:%u", __func__, status, - scanner_id, app_uuid->uu[0]); + scanner_id, app_uuid->uu[0]); } void ServiceStoppedCallback(int status, int server_if, int srvc_handle) { LOG_INFO(LOG_TAG, "%s: status:%d server_if:%d srvc_handle:%d", __func__, - status, server_if, srvc_handle); + status, server_if, srvc_handle); // This terminates a Stop call. // TODO(icoolidge): make this symmetric with start std::lock_guard lock(g_internal->lock); g_internal->api_synchronize.notify_one(); } -void ScanResultCallback(bt_bdaddr_t *bda, int rssi, vector adv_data) { +void ScanResultCallback(bt_bdaddr_t* bda, int rssi, vector adv_data) { std::string addr(BtAddrString(bda)); (void)adv_data; std::lock_guard lock(g_internal->lock); @@ -382,21 +382,20 @@ void ScanResultCallback(bt_bdaddr_t *bda, int rssi, vector adv_data) { } void ClientConnectCallback(int conn_id, int status, int client_if, - bt_bdaddr_t *bda) { + bt_bdaddr_t* bda) { std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, "%s: conn_id:%d status:%d client_if:%d %s", __func__, - conn_id, status, client_if, addr.c_str()); + conn_id, status, client_if, addr.c_str()); } void ClientDisconnectCallback(int conn_id, int status, int client_if, - bt_bdaddr_t *bda) { + bt_bdaddr_t* bda) { std::string addr(BtAddrString(bda)); LOG_INFO(LOG_TAG, "%s: conn_id:%d status:%d client_if:%d %s", __func__, - conn_id, status, client_if, addr.c_str()); + conn_id, status, client_if, addr.c_str()); } -void IndicationSentCallback(UNUSED_ATTR int conn_id, - UNUSED_ATTR int status) { +void IndicationSentCallback(UNUSED_ATTR int conn_id, UNUSED_ATTR int status) { // TODO(icoolidge): what to do } @@ -482,7 +481,7 @@ int ServerInternals::Initialize() { // Get the interface to the GATT profile. const bt_interface_t* bt_iface = hal::BluetoothInterface::Get()->GetHALInterface(); - gatt = reinterpret_cast( + gatt = reinterpret_cast( bt_iface->get_profile_interface(BT_PROFILE_GATT_ID)); if (!gatt) { LOG_ERROR(LOG_TAG, "Error getting GATT interface"); @@ -504,14 +503,15 @@ int ServerInternals::Initialize() { return 0; } -bt_status_t ServerInternals::AddCharacteristic( - const UUID& uuid, - uint8_t properties, - uint16_t permissions) { +bt_status_t ServerInternals::AddCharacteristic(const UUID& uuid, + uint8_t properties, + uint16_t permissions) { bt_uuid_t c_uuid = uuid.GetBlueDroid(); - pending_svc_decl.push_back({.type = BTGATT_DB_CHARACTERISTIC, .uuid = c_uuid, - .properties = properties, .permissions = permissions}); + pending_svc_decl.push_back({.type = BTGATT_DB_CHARACTERISTIC, + .uuid = c_uuid, + .properties = properties, + .permissions = permissions}); return BT_STATUS_SUCCESS; } @@ -523,10 +523,8 @@ ServerInternals::ServerInternals() pipefd{INVALID_FD, INVALID_FD} {} ServerInternals::~ServerInternals() { - if (pipefd[0] != INVALID_FD) - close(pipefd[0]); - if (pipefd[1] != INVALID_FD) - close(pipefd[1]); + if (pipefd[0] != INVALID_FD) close(pipefd[0]); + if (pipefd[1] != INVALID_FD) close(pipefd[1]); gatt->server->delete_service(server_if, service_handle); gatt->server->unregister_server(server_if); @@ -588,14 +586,13 @@ bool Server::SetAdvertisement(const std::vector& ids, std::lock_guard lock(internal_->lock); // Setup our advertisement. This has no callback. - internal_->gatt->advertiser->SetData(0, - false, /* beacon, not scan response */ - {}, base::Bind(&DoNothing)); - // transmit_name, /* name */ - // 2, 2, interval - // mutable_manufacturer_data, - // mutable_service_data, - // id_data); + internal_->gatt->advertiser->SetData(0, false, /* beacon, not scan response */ + {}, base::Bind(&DoNothing)); + // transmit_name, /* name */ + // 2, 2, interval + // mutable_manufacturer_data, + // mutable_service_data, + // id_data); return true; } @@ -615,24 +612,23 @@ bool Server::SetScanResponse(const std::vector& ids, std::lock_guard lock(internal_->lock); // Setup our advertisement. This has no callback. - internal_->gatt->advertiser->SetData(0, - true, /* scan response */ - {}, base::Bind(&DoNothing)); - // transmit_name, /* name */ - // false, /* no txpower */ - // 2, 2, interval - // 0, /* appearance */ - // mutable_manufacturer_data, - // mutable_service_data, - // id_data); + internal_->gatt->advertiser->SetData(0, true, /* scan response */ + {}, base::Bind(&DoNothing)); + // transmit_name, /* name */ + // false, /* no txpower */ + // 2, 2, interval + // 0, /* appearance */ + // mutable_manufacturer_data, + // mutable_service_data, + // id_data); return true; } -bool Server::AddCharacteristic( - const UUID &id, int properties, int permissions) { +bool Server::AddCharacteristic(const UUID& id, int properties, + int permissions) { std::unique_lock lock(internal_->lock); - bt_status_t btstat = internal_->AddCharacteristic( - id, properties, permissions); + bt_status_t btstat = + internal_->AddCharacteristic(id, properties, permissions); if (btstat != BT_STATUS_SUCCESS) { LOG_ERROR(LOG_TAG, "Failed to add characteristic to service: 0x%04x", internal_->service_handle); @@ -644,13 +640,13 @@ bool Server::AddCharacteristic( return true; } -bool Server::AddBlob(const UUID &id, const UUID &control_id, int properties, - int permissions) { +bool Server::AddBlob(const UUID& id, const UUID& control_id, int properties, + int permissions) { std::unique_lock lock(internal_->lock); // First, add the primary attribute (characteristic value) - bt_status_t btstat = internal_->AddCharacteristic( - id, properties, permissions); + bt_status_t btstat = + internal_->AddCharacteristic(id, properties, permissions); if (btstat != BT_STATUS_SUCCESS) { LOG_ERROR(LOG_TAG, "Failed to set scan response data"); return false; @@ -660,10 +656,9 @@ bool Server::AddBlob(const UUID &id, const UUID &control_id, int properties, // Control attributes have fixed permissions/properties. // Remember position at which blob was added. blob_index.insert(pending_svc_decl.size()); - btstat = internal_->AddCharacteristic( - control_id, - kPropertyRead | kPropertyWrite, - kPermissionRead | kPermissionWrite); + btstat = + internal_->AddCharacteristic(control_id, kPropertyRead | kPropertyWrite, + kPermissionRead | kPermissionWrite); return true; } @@ -712,34 +707,31 @@ bool Server::ScanDisable() { return true; } -bool Server::GetScanResults(ScanResults *results) { +bool Server::GetScanResults(ScanResults* results) { std::lock_guard lock(internal_->lock); *results = internal_->scan_results; return true; } -bool Server::SetCharacteristicValue(const UUID &id, - const std::vector &value) { +bool Server::SetCharacteristicValue(const UUID& id, + const std::vector& value) { std::lock_guard lock(internal_->lock); const int attribute_id = internal_->uuid_to_attribute[id]; - Characteristic &ch = internal_->characteristics[attribute_id]; + Characteristic& ch = internal_->characteristics[attribute_id]; ch.next_blob = value; ch.next_blob_pending = true; - if (!ch.notify) - return true; + if (!ch.notify) return true; for (auto connection : internal_->connections) { - internal_->gatt->server->send_indication(internal_->server_if, - attribute_id, - connection, - true, - {0}); + internal_->gatt->server->send_indication(internal_->server_if, attribute_id, + connection, true, {0}); } return true; } -bool Server::GetCharacteristicValue(const UUID &id, std::vector *value) { +bool Server::GetCharacteristicValue(const UUID& id, + std::vector* value) { std::lock_guard lock(internal_->lock); const int attribute_id = internal_->uuid_to_attribute[id]; *value = internal_->characteristics[attribute_id].blob; diff --git a/service/gatt_server_old.h b/service/gatt_server_old.h index 84ceb26b3..a16bdfc7a 100644 --- a/service/gatt_server_old.h +++ b/service/gatt_server_old.h @@ -86,19 +86,20 @@ class Server { bool transmit_name); // Add an ordinary characteristic for reading and/or writing. - bool AddCharacteristic(const UUID &id, int properties, int permissions); + bool AddCharacteristic(const UUID& id, int properties, int permissions); // Add a special 'blob' characteristic with a corresponding control // attribute to manipulate which part of the blob the attribute represents. - bool AddBlob(const UUID &id, const UUID &control_id, int properties, + bool AddBlob(const UUID& id, const UUID& control_id, int properties, int permissions); // Put a new value into a characeteristic. // It will be read from a client starting at the next 0-offset read. - bool SetCharacteristicValue(const UUID &id, const std::vector &value); + bool SetCharacteristicValue(const UUID& id, + const std::vector& value); // Get the current value of a characteristic. - bool GetCharacteristicValue(const UUID &id, std::vector *value); + bool GetCharacteristicValue(const UUID& id, std::vector* value); // Start this service. Activate advertisements, allow connections. // Characteristics should all be created before this. @@ -114,7 +115,7 @@ class Server { bool ScanDisable(); // Copy out the cached scan results. - bool GetScanResults(ScanResults *results); + bool GetScanResults(ScanResults* results); private: // Internal data. diff --git a/service/hal/bluetooth_gatt_interface.cc b/service/hal/bluetooth_gatt_interface.cc index be8c08446..ecabc57a6 100644 --- a/service/hal/bluetooth_gatt_interface.cc +++ b/service/hal/bluetooth_gatt_interface.cc @@ -45,37 +45,37 @@ BluetoothGattInterface* g_interface = nullptr; // Mutex used by callbacks to access |g_interface|. If we initialize or clean it // use unique_lock. If only accessing |g_interface| use shared lock. -//TODO(jpawlowski): this should be just shared_mutex, as we currently don't use +// TODO(jpawlowski): this should be just shared_mutex, as we currently don't use // timed methods. Change to shared_mutex when we upgrade to C++14 shared_mutex_impl g_instance_lock; // Helper for obtaining the observer lists. This is forward declared here // and defined below since it depends on BluetoothInterfaceImpl. base::ObserverList* - GetScannerObservers(); +GetScannerObservers(); base::ObserverList* - GetClientObservers(); +GetClientObservers(); base::ObserverList* - GetServerObservers(); +GetServerObservers(); -#define FOR_EACH_SCANNER_OBSERVER(func) \ +#define FOR_EACH_SCANNER_OBSERVER(func) \ FOR_EACH_OBSERVER(BluetoothGattInterface::ScannerObserver, \ *GetScannerObservers(), func) -#define FOR_EACH_CLIENT_OBSERVER(func) \ +#define FOR_EACH_CLIENT_OBSERVER(func) \ FOR_EACH_OBSERVER(BluetoothGattInterface::ClientObserver, \ *GetClientObservers(), func) -#define FOR_EACH_SERVER_OBSERVER(func) \ +#define FOR_EACH_SERVER_OBSERVER(func) \ FOR_EACH_OBSERVER(BluetoothGattInterface::ServerObserver, \ *GetServerObservers(), func) -#define VERIFY_INTERFACE_OR_RETURN() \ - do { \ - if (!g_interface) { \ +#define VERIFY_INTERFACE_OR_RETURN() \ + do { \ + if (!g_interface) { \ LOG(WARNING) << "Callback received while |g_interface| is NULL"; \ - return; \ - } \ + return; \ + } \ } while (0) void RegisterClientCallback(int status, int client_if, bt_uuid_t* app_uuid) { @@ -90,7 +90,8 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t* app_uuid) { void RegisterScannerCallback(int status, int scanner_id, bt_uuid_t* app_uuid) { shared_lock lock(g_instance_lock); - VLOG(2) << __func__ << " - status: " << status << " scanner_id: " << scanner_id; + VLOG(2) << __func__ << " - status: " << status + << " scanner_id: " << scanner_id; VERIFY_INTERFACE_OR_RETURN(); CHECK(app_uuid); @@ -98,7 +99,8 @@ void RegisterScannerCallback(int status, int scanner_id, bt_uuid_t* app_uuid) { RegisterScannerCallback(g_interface, status, scanner_id, *app_uuid)); } -void ScanResultCallback(bt_bdaddr_t* bda, int rssi, vector adv_data) { // NOLINT(pass-by-value) +void ScanResultCallback(bt_bdaddr_t* bda, int rssi, + vector adv_data) { // NOLINT(pass-by-value) shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); CHECK(bda); @@ -106,7 +108,7 @@ void ScanResultCallback(bt_bdaddr_t* bda, int rssi, vector adv_data) { VLOG(2) << __func__ << " - BD_ADDR: " << BtAddrString(bda) << " RSSI: " << rssi; FOR_EACH_SCANNER_OBSERVER( - ScanResultCallback(g_interface, *bda, rssi, adv_data)); + ScanResultCallback(g_interface, *bda, rssi, adv_data)); } void ConnectCallback(int conn_id, int status, int client_if, bt_bdaddr_t* bda) { @@ -114,13 +116,11 @@ void ConnectCallback(int conn_id, int status, int client_if, bt_bdaddr_t* bda) { VERIFY_INTERFACE_OR_RETURN(); CHECK(bda); - VLOG(2) << __func__ << " - status: " << status - << " client_if: " << client_if - << " - BD_ADDR: " << BtAddrString(bda) - << " - conn_id: " << conn_id; + VLOG(2) << __func__ << " - status: " << status << " client_if: " << client_if + << " - BD_ADDR: " << BtAddrString(bda) << " - conn_id: " << conn_id; FOR_EACH_CLIENT_OBSERVER( - ConnectCallback(g_interface, conn_id, status, client_if, *bda)); + ConnectCallback(g_interface, conn_id, status, client_if, *bda)); } void DisconnectCallback(int conn_id, int status, int client_if, @@ -129,105 +129,96 @@ void DisconnectCallback(int conn_id, int status, int client_if, VERIFY_INTERFACE_OR_RETURN(); CHECK(bda); - VLOG(2) << __func__ << " - conn_id: " << conn_id - << " - status: " << status - << " client_if: " << client_if - << " - BD_ADDR: " << BtAddrString(bda); + VLOG(2) << __func__ << " - conn_id: " << conn_id << " - status: " << status + << " client_if: " << client_if << " - BD_ADDR: " << BtAddrString(bda); FOR_EACH_CLIENT_OBSERVER( - DisconnectCallback(g_interface, conn_id, status, client_if, *bda)); + DisconnectCallback(g_interface, conn_id, status, client_if, *bda)); } void SearchCompleteCallback(int conn_id, int status) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ << " - conn_id: " << conn_id - << " - status: " << status; + VLOG(2) << __func__ << " - conn_id: " << conn_id << " - status: " << status; FOR_EACH_CLIENT_OBSERVER( - SearchCompleteCallback(g_interface, conn_id, status)); + SearchCompleteCallback(g_interface, conn_id, status)); } -void RegisterForNotificationCallback(int conn_id, int registered, int status, uint16_t handle) { +void RegisterForNotificationCallback(int conn_id, int registered, int status, + uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - LOG(INFO) << __func__ << " - conn_id: " << conn_id - << " - status: " << status - << " - registered: " << registered - << " - handle: " << handle; - FOR_EACH_CLIENT_OBSERVER( - RegisterForNotificationCallback(g_interface, conn_id, status, registered, handle)); + LOG(INFO) << __func__ << " - conn_id: " << conn_id << " - status: " << status + << " - registered: " << registered << " - handle: " << handle; + FOR_EACH_CLIENT_OBSERVER(RegisterForNotificationCallback( + g_interface, conn_id, status, registered, handle)); } -void NotifyCallback(int conn_id, btgatt_notify_params_t *p_data) { +void NotifyCallback(int conn_id, btgatt_notify_params_t* p_data) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); VLOG(2) << __func__ << " - conn_id: " << conn_id << " - address: " << BtAddrString(&p_data->bda) - << " - handle: " << p_data->handle - << " - len: " << p_data->len + << " - handle: " << p_data->handle << " - len: " << p_data->len << " - is_notify: " << p_data->is_notify; - FOR_EACH_CLIENT_OBSERVER( - NotifyCallback(g_interface, conn_id, p_data)); + FOR_EACH_CLIENT_OBSERVER(NotifyCallback(g_interface, conn_id, p_data)); } void WriteCharacteristicCallback(int conn_id, int status, uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ << " - conn_id: " << conn_id - << " - status: " << status; + VLOG(2) << __func__ << " - conn_id: " << conn_id << " - status: " << status; FOR_EACH_CLIENT_OBSERVER( - WriteCharacteristicCallback(g_interface, conn_id, status, handle)); + WriteCharacteristicCallback(g_interface, conn_id, status, handle)); } -void WriteDescriptorCallback(int conn_id, int status, - uint16_t handle) { +void WriteDescriptorCallback(int conn_id, int status, uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ << " - conn_id: " << conn_id - << " - status: " << status; + VLOG(2) << __func__ << " - conn_id: " << conn_id << " - status: " << status; FOR_EACH_CLIENT_OBSERVER( - WriteDescriptorCallback(g_interface, conn_id, status, handle)); + WriteDescriptorCallback(g_interface, conn_id, status, handle)); } void MtuChangedCallback(int conn_id, int status, int mtu) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ << " - conn_id: " << conn_id - << " status: " << status + VLOG(2) << __func__ << " - conn_id: " << conn_id << " status: " << status << " mtu: " << mtu; - FOR_EACH_CLIENT_OBSERVER(MtuChangedCallback(g_interface, conn_id, status, mtu)); + FOR_EACH_CLIENT_OBSERVER( + MtuChangedCallback(g_interface, conn_id, status, mtu)); } -void GetGattDbCallback(int conn_id, btgatt_db_element_t *db, int size) { +void GetGattDbCallback(int conn_id, btgatt_db_element_t* db, int size) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " size: " << size; VERIFY_INTERFACE_OR_RETURN(); - FOR_EACH_CLIENT_OBSERVER( - GetGattDbCallback(g_interface, conn_id, db, size)); + FOR_EACH_CLIENT_OBSERVER(GetGattDbCallback(g_interface, conn_id, db, size)); } -void ServicesRemovedCallback(int conn_id, uint16_t start_handle, uint16_t end_handle) { +void ServicesRemovedCallback(int conn_id, uint16_t start_handle, + uint16_t end_handle) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id - << " start_handle: " << start_handle - << " end_handle: " << end_handle; + << " start_handle: " << start_handle << " end_handle: " << end_handle; VERIFY_INTERFACE_OR_RETURN(); FOR_EACH_CLIENT_OBSERVER( ServicesRemovedCallback(g_interface, conn_id, start_handle, end_handle)); } -void ServicesAddedCallback(int conn_id, btgatt_db_element_t *added, int added_count) { +void ServicesAddedCallback(int conn_id, btgatt_db_element_t* added, + int added_count) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " added_count: " << added_count; @@ -260,8 +251,7 @@ void ConnectionCallback(int conn_id, int server_if, int connected, } void ServiceAddedCallback( - int status, - int server_if, + int status, int server_if, vector service) { // NOLINT(pass-by-value) shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - status: " << status << " server_if: " << server_if @@ -269,8 +259,8 @@ void ServiceAddedCallback( VERIFY_INTERFACE_OR_RETURN(); CHECK(service.size()); - FOR_EACH_SERVER_OBSERVER(ServiceAddedCallback( - g_interface, status, server_if, service)); + FOR_EACH_SERVER_OBSERVER( + ServiceAddedCallback(g_interface, status, server_if, service)); } void ServiceStoppedCallback(int status, int server_if, int srvc_handle) { @@ -279,8 +269,8 @@ void ServiceStoppedCallback(int status, int server_if, int srvc_handle) { << " handle: " << srvc_handle; VERIFY_INTERFACE_OR_RETURN(); - FOR_EACH_SERVER_OBSERVER(ServiceStoppedCallback( - g_interface, status, server_if, srvc_handle)); + FOR_EACH_SERVER_OBSERVER( + ServiceStoppedCallback(g_interface, status, server_if, srvc_handle)); } void ServiceDeletedCallback(int status, int server_if, int srvc_handle) { @@ -289,12 +279,13 @@ void ServiceDeletedCallback(int status, int server_if, int srvc_handle) { << " handle: " << srvc_handle; VERIFY_INTERFACE_OR_RETURN(); - FOR_EACH_SERVER_OBSERVER(ServiceDeletedCallback( - g_interface, status, server_if, srvc_handle)); + FOR_EACH_SERVER_OBSERVER( + ServiceDeletedCallback(g_interface, status, server_if, srvc_handle)); } -void RequestReadCharacteristicCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, - int attr_handle, int offset, bool is_long) { +void RequestReadCharacteristicCallback(int conn_id, int trans_id, + bt_bdaddr_t* bda, int attr_handle, + int offset, bool is_long) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id << " attr_handle: " << attr_handle << " offset: " << offset @@ -307,7 +298,7 @@ void RequestReadCharacteristicCallback(int conn_id, int trans_id, bt_bdaddr_t* b } void RequestReadDescriptorCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, - int attr_handle, int offset, bool is_long) { + int attr_handle, int offset, bool is_long) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id << " attr_handle: " << attr_handle << " offset: " << offset @@ -320,10 +311,9 @@ void RequestReadDescriptorCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, } void RequestWriteCharacteristicCallback(int conn_id, int trans_id, - bt_bdaddr_t* bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) { + bt_bdaddr_t* bda, int attr_handle, + int offset, bool need_rsp, bool is_prep, + vector value) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id << " attr_handle: " << attr_handle << " offset: " << offset @@ -333,15 +323,14 @@ void RequestWriteCharacteristicCallback(int conn_id, int trans_id, CHECK(bda); FOR_EACH_SERVER_OBSERVER(RequestWriteCharacteristicCallback( - g_interface, conn_id, trans_id, *bda, attr_handle, offset, - need_rsp, is_prep, value)); + g_interface, conn_id, trans_id, *bda, attr_handle, offset, need_rsp, + is_prep, value)); } -void RequestWriteDescriptorCallback(int conn_id, int trans_id, - bt_bdaddr_t* bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, - vector value) { // NOLINT(pass-by-value) +void RequestWriteDescriptorCallback( + int conn_id, int trans_id, bt_bdaddr_t* bda, int attr_handle, int offset, + bool need_rsp, bool is_prep, + vector value) { // NOLINT(pass-by-value) shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id << " attr_handle: " << attr_handle << " offset: " << offset @@ -351,12 +340,12 @@ void RequestWriteDescriptorCallback(int conn_id, int trans_id, CHECK(bda); FOR_EACH_SERVER_OBSERVER(RequestWriteDescriptorCallback( - g_interface, conn_id, trans_id, *bda, attr_handle, offset, - need_rsp, is_prep, value)); + g_interface, conn_id, trans_id, *bda, attr_handle, offset, need_rsp, + is_prep, value)); } -void RequestExecWriteCallback(int conn_id, int trans_id, - bt_bdaddr_t* bda, int exec_write) { +void RequestExecWriteCallback(int conn_id, int trans_id, bt_bdaddr_t* bda, + int exec_write) { shared_lock lock(g_instance_lock); VLOG(2) << __func__ << " - conn_id: " << conn_id << " trans_id: " << trans_id << " exec_write: " << exec_write; @@ -372,8 +361,8 @@ void ResponseConfirmationCallback(int status, int handle) { VLOG(2) << __func__ << " - status: " << status << " handle: " << handle; VERIFY_INTERFACE_OR_RETURN(); - FOR_EACH_SERVER_OBSERVER(ResponseConfirmationCallback( - g_interface, status, handle)); + FOR_EACH_SERVER_OBSERVER( + ResponseConfirmationCallback(g_interface, status, handle)); } void IndicationSentCallback(int conn_id, int status) { @@ -381,8 +370,8 @@ void IndicationSentCallback(int conn_id, int status) { VLOG(2) << __func__ << " - conn_id: " << conn_id << " status: " << status; VERIFY_INTERFACE_OR_RETURN(); - FOR_EACH_SERVER_OBSERVER(IndicationSentCallback( - g_interface, conn_id, status)); + FOR_EACH_SERVER_OBSERVER( + IndicationSentCallback(g_interface, conn_id, status)); } void MtuChangedCallback(int conn_id, int mtu) { @@ -448,10 +437,8 @@ const btgatt_server_callbacks_t gatt_server_callbacks = { }; const btgatt_callbacks_t gatt_callbacks = { - sizeof(btgatt_callbacks_t), - &gatt_client_callbacks, - &gatt_server_callbacks, - &gatt_scanner_callbacks, + sizeof(btgatt_callbacks_t), &gatt_client_callbacks, &gatt_server_callbacks, + &gatt_scanner_callbacks, }; } // namespace @@ -459,12 +446,10 @@ const btgatt_callbacks_t gatt_callbacks = { // BluetoothGattInterface implementation for production. class BluetoothGattInterfaceImpl : public BluetoothGattInterface { public: - BluetoothGattInterfaceImpl() : hal_iface_(nullptr) { - } + BluetoothGattInterfaceImpl() : hal_iface_(nullptr) {} ~BluetoothGattInterfaceImpl() override { - if (hal_iface_) - hal_iface_->cleanup(); + if (hal_iface_) hal_iface_->cleanup(); } void AddScannerObserver(ScannerObserver* observer) override { @@ -565,22 +550,22 @@ namespace { base::ObserverList* GetScannerObservers() { CHECK(g_interface); - return static_cast( - g_interface)->scanner_observers(); + return static_cast(g_interface) + ->scanner_observers(); } base::ObserverList* GetClientObservers() { CHECK(g_interface); - return static_cast( - g_interface)->client_observers(); + return static_cast(g_interface) + ->client_observers(); } base::ObserverList* GetServerObservers() { CHECK(g_interface); - return static_cast( - g_interface)->server_observers(); + return static_cast(g_interface) + ->server_observers(); } } // namespace @@ -589,233 +574,170 @@ GetServerObservers() { // themselves are optional. void BluetoothGattInterface::ScannerObserver::RegisterScannerCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, - int /* scanner_id */, - const bt_uuid_t& /* app_uuid */) { + BluetoothGattInterface* /* gatt_iface */, int /* status */, + int /* scanner_id */, const bt_uuid_t& /* app_uuid */) { // Do nothing. } void BluetoothGattInterface::ScannerObserver::ScanResultCallback( - BluetoothGattInterface* /* gatt_iface */, - const bt_bdaddr_t& /* bda */, - int /* rssi */, - vector /* adv_data */) { // NOLINT(pass-by-value) + BluetoothGattInterface* /* gatt_iface */, const bt_bdaddr_t& /* bda */, + int /* rssi */, vector /* adv_data */) { // NOLINT(pass-by-value) // Do Nothing. } void BluetoothGattInterface::ClientObserver::RegisterClientCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, - int /* client_if */, - const bt_uuid_t& /* app_uuid */) { + BluetoothGattInterface* /* gatt_iface */, int /* status */, + int /* client_if */, const bt_uuid_t& /* app_uuid */) { // Do nothing. } void BluetoothGattInterface::ClientObserver::ConnectCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* status */, - int /* client_if */, - const bt_bdaddr_t& /* bda */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* status */, int /* client_if */, const bt_bdaddr_t& /* bda */) { // Do nothing } void BluetoothGattInterface::ClientObserver::DisconnectCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* status */, - int /* client_if */, - const bt_bdaddr_t& /* bda */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* status */, int /* client_if */, const bt_bdaddr_t& /* bda */) { // Do nothing } void BluetoothGattInterface::ClientObserver::SearchCompleteCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, int /* status */) { // Do nothing } void BluetoothGattInterface::ClientObserver::RegisterForNotificationCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* status */, - int /* registered */, - uint16_t /* handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* status */, int /* registered */, uint16_t /* handle */) { // Do nothing } void BluetoothGattInterface::ClientObserver::NotifyCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, btgatt_notify_params_t* /* p_data */) { // Do nothing } void BluetoothGattInterface::ClientObserver::WriteCharacteristicCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* status */, - uint16_t /* handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* status */, uint16_t /* handle */) { // Do nothing } void BluetoothGattInterface::ClientObserver::WriteDescriptorCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* status */, - uint16_t /* handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* status */, uint16_t /* handle */) { // Do nothing } void BluetoothGattInterface::ClientObserver::MtuChangedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* statis*/, - int /* mtu */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* statis*/, int /* mtu */) { // Do nothing. } void BluetoothGattInterface::ClientObserver::GetGattDbCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - btgatt_db_element_t* /* gatt_db */, - int /* size */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + btgatt_db_element_t* /* gatt_db */, int /* size */) { // Do nothing. } void BluetoothGattInterface::ClientObserver::ServicesRemovedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - uint16_t /* start_handle */, - uint16_t /* end_handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + uint16_t /* start_handle */, uint16_t /* end_handle */) { // Do nothing. } void BluetoothGattInterface::ClientObserver::ServicesAddedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - btgatt_db_element_t* /* added */, - int /* added_count */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + btgatt_db_element_t* /* added */, int /* added_count */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::RegisterServerCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, - int /* server_if */, - const bt_uuid_t& /* app_uuid */) { + BluetoothGattInterface* /* gatt_iface */, int /* status */, + int /* server_if */, const bt_uuid_t& /* app_uuid */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::ConnectionCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* server_if */, - int /* connected */, - const bt_bdaddr_t& /* bda */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* server_if */, int /* connected */, const bt_bdaddr_t& /* bda */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::ServiceAddedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, + BluetoothGattInterface* /* gatt_iface */, int /* status */, int /* server_if */, vector /* service */) { // NOLINT(pass-by-value) // Do nothing. } void BluetoothGattInterface::ServerObserver::ServiceStoppedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, - int /* server_if */, - int /* srvc_handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* status */, + int /* server_if */, int /* srvc_handle */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::ServiceDeletedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, - int /* server_if */, - int /* srvc_handle */) { + BluetoothGattInterface* /* gatt_iface */, int /* status */, + int /* server_if */, int /* srvc_handle */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::RequestReadCharacteristicCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* trans_id */, - const bt_bdaddr_t& /* bda */, - int /* attr_handle */, - int /* offset */, - bool /* is_long */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* trans_id */, const bt_bdaddr_t& /* bda */, int /* attr_handle */, + int /* offset */, bool /* is_long */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::RequestReadDescriptorCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* trans_id */, - const bt_bdaddr_t& /* bda */, - int /* attr_handle */, - int /* offset */, - bool /* is_long */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* trans_id */, const bt_bdaddr_t& /* bda */, int /* attr_handle */, + int /* offset */, bool /* is_long */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::RequestWriteCharacteristicCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* trans_id */, - const bt_bdaddr_t& /* bda */, - int /* attr_handle */, - int /* offset */, - bool /* need_rsp */, - bool /* is_prep */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* trans_id */, const bt_bdaddr_t& /* bda */, int /* attr_handle */, + int /* offset */, bool /* need_rsp */, bool /* is_prep */, vector /* value */) { // NOLINT(pass-by-value) // Do nothing. } void BluetoothGattInterface::ServerObserver::RequestWriteDescriptorCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* trans_id */, - const bt_bdaddr_t& /* bda */, - int /* attr_handle */, - int /* offset */, - bool /* need_rsp */, - bool /* is_prep */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* trans_id */, const bt_bdaddr_t& /* bda */, int /* attr_handle */, + int /* offset */, bool /* need_rsp */, bool /* is_prep */, vector /* value */) { // NOLINT(pass-by-value) // Do nothing. } void BluetoothGattInterface::ServerObserver::RequestExecWriteCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, - int /* trans_id */, - const bt_bdaddr_t& /* bda */, - int /* exec_write */) { + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, + int /* trans_id */, const bt_bdaddr_t& /* bda */, int /* exec_write */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::ResponseConfirmationCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* status */, + BluetoothGattInterface* /* gatt_iface */, int /* status */, int /* handle */) { // Do nothing } void BluetoothGattInterface::ServerObserver::IndicationSentCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, int /* status */) { // Do nothing. } void BluetoothGattInterface::ServerObserver::MtuChangedCallback( - BluetoothGattInterface* /* gatt_iface */, - int /* conn_id */, + BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, int /* mtu */) { // Do nothing. } diff --git a/service/hal/bluetooth_gatt_interface.h b/service/hal/bluetooth_gatt_interface.h index 3b7c297e1..a4ad084b1 100644 --- a/service/hal/bluetooth_gatt_interface.h +++ b/service/hal/bluetooth_gatt_interface.h @@ -39,7 +39,6 @@ namespace hal { // be injected for testing the upper layer. class BluetoothGattInterface { public: - // The HAL interface doesn't allow registering "user data" that carries // context beyond the callback parameters, forcing implementations to deal // with global variables. The *Observer interface is to redirect these events @@ -48,93 +47,72 @@ class BluetoothGattInterface { // The standard LE scanner callback interface. class ScannerObserver { public: - virtual ~ScannerObserver() = default; // All of the events below correspond to callbacks defined in // "btgatt_scanner_callbacks_t" in the HAL API definitions. - virtual void RegisterScannerCallback( - BluetoothGattInterface* gatt_iface, - int status, int scanner_id, - const bt_uuid_t& app_uuid); + virtual void RegisterScannerCallback(BluetoothGattInterface* gatt_iface, + int status, int scanner_id, + const bt_uuid_t& app_uuid); virtual void ScanResultCallback( - BluetoothGattInterface* gatt_iface, - const bt_bdaddr_t& bda, int rssi, + BluetoothGattInterface* gatt_iface, const bt_bdaddr_t& bda, int rssi, vector adv_data); // NOLINT(pass-by-value) }; // The standard BT-GATT client callback interface. class ClientObserver { public: - virtual ~ClientObserver() = default; // All of the events below correspond to callbacks defined in // "bt_gatt_client_callbacks_t" in the HAL API definitions. - virtual void RegisterClientCallback( - BluetoothGattInterface* gatt_iface, - int status, int client_if, - const bt_uuid_t& app_uuid); - - virtual void ConnectCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - int status, - int client_if, - const bt_bdaddr_t& bda); - - virtual void DisconnectCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - int status, - int client_if, - const bt_bdaddr_t& bda); - - virtual void SearchCompleteCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - int status); + virtual void RegisterClientCallback(BluetoothGattInterface* gatt_iface, + int status, int client_if, + const bt_uuid_t& app_uuid); + + virtual void ConnectCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status, int client_if, + const bt_bdaddr_t& bda); + + virtual void DisconnectCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status, int client_if, + const bt_bdaddr_t& bda); + + virtual void SearchCompleteCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status); virtual void RegisterForNotificationCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int status, int registered, uint16_t handle); - - virtual void NotifyCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, btgatt_notify_params_t* p_data); - - virtual void WriteCharacteristicCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int status, uint16_t handle); - - virtual void WriteDescriptorCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int status, uint16_t handle); - - virtual void MtuChangedCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int status, int mtu); - - virtual void GetGattDbCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - btgatt_db_element_t* gatt_db, - int size); - - virtual void ServicesRemovedCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - uint16_t start_handle, - uint16_t end_handle); - - virtual void ServicesAddedCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, - btgatt_db_element_t *added, - int added_count); + BluetoothGattInterface* gatt_iface, int conn_id, int status, + int registered, uint16_t handle); + + virtual void NotifyCallback(BluetoothGattInterface* gatt_iface, int conn_id, + btgatt_notify_params_t* p_data); + + virtual void WriteCharacteristicCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status, + uint16_t handle); + + virtual void WriteDescriptorCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status, + uint16_t handle); + + virtual void MtuChangedCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status, int mtu); + + virtual void GetGattDbCallback(BluetoothGattInterface* gatt_iface, + int conn_id, btgatt_db_element_t* gatt_db, + int size); + + virtual void ServicesRemovedCallback(BluetoothGattInterface* gatt_iface, + int conn_id, uint16_t start_handle, + uint16_t end_handle); + + virtual void ServicesAddedCallback(BluetoothGattInterface* gatt_iface, + int conn_id, btgatt_db_element_t* added, + int added_count); }; // The standard BT-GATT server callback interface. @@ -142,77 +120,59 @@ class BluetoothGattInterface { public: virtual ~ServerObserver() = default; - virtual void RegisterServerCallback( - BluetoothGattInterface* gatt_iface, - int status, int server_if, - const bt_uuid_t& app_uuid); + virtual void RegisterServerCallback(BluetoothGattInterface* gatt_iface, + int status, int server_if, + const bt_uuid_t& app_uuid); - virtual void ConnectionCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int server_if, - int connected, - const bt_bdaddr_t& bda); + virtual void ConnectionCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int server_if, int connected, + const bt_bdaddr_t& bda); virtual void ServiceAddedCallback( - BluetoothGattInterface* gatt_iface, - int status, int server_if, + BluetoothGattInterface* gatt_iface, int status, int server_if, vector service); // NOLINT(pass-by-value) - virtual void ServiceStoppedCallback( - BluetoothGattInterface* gatt_iface, - int status, int server_if, - int srvc_handle); + virtual void ServiceStoppedCallback(BluetoothGattInterface* gatt_iface, + int status, int server_if, + int srvc_handle); - virtual void ServiceDeletedCallback( - BluetoothGattInterface* gatt_iface, - int status, int server_if, - int srvc_handle); + virtual void ServiceDeletedCallback(BluetoothGattInterface* gatt_iface, + int status, int server_if, + int srvc_handle); virtual void RequestReadCharacteristicCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool is_long); + BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool is_long); virtual void RequestReadDescriptorCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool is_long); + BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool is_long); virtual void RequestWriteCharacteristicCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, + BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, + bool is_prep, vector value); // NOLINT(pass-by-value) virtual void RequestWriteDescriptorCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, - int attr_handle, int offset, - bool need_rsp, bool is_prep, + BluetoothGattInterface* gatt_iface, int conn_id, int trans_id, + const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, + bool is_prep, vector value); // NOLINT(pass-by-alue) - virtual void RequestExecWriteCallback( - BluetoothGattInterface* gatt_iface, - int conn_id, int trans_id, - const bt_bdaddr_t& bda, int exec_write); + virtual void RequestExecWriteCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int trans_id, + const bt_bdaddr_t& bda, + int exec_write); virtual void ResponseConfirmationCallback( - BluetoothGattInterface* gatt_iface, - int status, - int handle); + BluetoothGattInterface* gatt_iface, int status, int handle); - virtual void IndicationSentCallback( - BluetoothGattInterface* gatt_iface, int conn_id, int status); + virtual void IndicationSentCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int status); - virtual void MtuChangedCallback( - BluetoothGattInterface* gatt_iface, int conn_id, int mtu); + virtual void MtuChangedCallback(BluetoothGattInterface* gatt_iface, + int conn_id, int mtu); }; // Initialize and clean up the BluetoothInterface singleton. Returns false if diff --git a/service/hal/bluetooth_interface.cc b/service/hal/bluetooth_interface.cc index fc751b583..4e73c65af 100644 --- a/service/hal/bluetooth_interface.cc +++ b/service/hal/bluetooth_interface.cc @@ -46,7 +46,7 @@ BluetoothInterface* g_bluetooth_interface = nullptr; // Mutex used by callbacks to access |g_interface|. If we initialize or clean it // use unique_lock. If only accessing |g_interface| use shared lock. -//TODO(jpawlowski): this should be just shared_mutex, as we currently don't use +// TODO(jpawlowski): this should be just shared_mutex, as we currently don't use // timed methods. Change to shared_mutex when we upgrade to C++14 shared_mutex_impl g_instance_lock; @@ -57,12 +57,12 @@ base::ObserverList* GetObservers(); #define FOR_EACH_BLUETOOTH_OBSERVER(func) \ FOR_EACH_OBSERVER(BluetoothInterface::Observer, *GetObservers(), func) -#define VERIFY_INTERFACE_OR_RETURN() \ - do { \ - if (!g_bluetooth_interface) { \ +#define VERIFY_INTERFACE_OR_RETURN() \ + do { \ + if (!g_bluetooth_interface) { \ LOG(WARNING) << "Callback received while |g_interface| is NULL"; \ - return; \ - } \ + return; \ + } \ } while (0) void AdapterStateChangedCallback(bt_state_t state) { @@ -72,8 +72,7 @@ void AdapterStateChangedCallback(bt_state_t state) { FOR_EACH_BLUETOOTH_OBSERVER(AdapterStateChangedCallback(state)); } -void AdapterPropertiesCallback(bt_status_t status, - int num_properties, +void AdapterPropertiesCallback(bt_status_t status, int num_properties, bt_property_t* properties) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); @@ -84,17 +83,17 @@ void AdapterPropertiesCallback(bt_status_t status, } void RemoteDevicePropertiesCallback(bt_status_t status, - bt_bdaddr_t *remote_bd_addr, - int num_properties, - bt_property_t* properties) { + bt_bdaddr_t* remote_bd_addr, + int num_properties, + bt_property_t* properties) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(1) << " Remote device properties changed - status: " << BtStatusText(status) + VLOG(1) << " Remote device properties changed - status: " + << BtStatusText(status) << " - BD_ADDR: " << BtAddrString(remote_bd_addr) << ", num_properties: " << num_properties; - FOR_EACH_BLUETOOTH_OBSERVER( - RemoteDevicePropertiesCallback(status, remote_bd_addr, num_properties, - properties)); + FOR_EACH_BLUETOOTH_OBSERVER(RemoteDevicePropertiesCallback( + status, remote_bd_addr, num_properties, properties)); } void DiscoveryStateChangedCallback(bt_discovery_state_t state) { @@ -104,54 +103,47 @@ void DiscoveryStateChangedCallback(bt_discovery_state_t state) { FOR_EACH_BLUETOOTH_OBSERVER(DiscoveryStateChangedCallback(state)); } -void PinRequestCallback(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, - uint32_t cod, bool min_16_digit) { +void PinRequestCallback(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, + uint32_t cod, bool min_16_digit) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ - << " - remote_bd_addr: " << remote_bd_addr - << " - bd_name: " << bd_name - << " - cod: " << cod + VLOG(2) << __func__ << " - remote_bd_addr: " << remote_bd_addr + << " - bd_name: " << bd_name << " - cod: " << cod << " - min_16_digit: " << min_16_digit; - FOR_EACH_BLUETOOTH_OBSERVER(PinRequestCallback(remote_bd_addr, bd_name, cod, min_16_digit)); + FOR_EACH_BLUETOOTH_OBSERVER( + PinRequestCallback(remote_bd_addr, bd_name, cod, min_16_digit)); } -void SSPRequestCallback(bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { +void SSPRequestCallback(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, + uint32_t cod, bt_ssp_variant_t pairing_variant, + uint32_t pass_key) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ - << " - remote_bd_addr: " << remote_bd_addr - << " - bd_name: " << bd_name - << " - cod: " << cod + VLOG(2) << __func__ << " - remote_bd_addr: " << remote_bd_addr + << " - bd_name: " << bd_name << " - cod: " << cod << " - pairing_variant: " << pairing_variant; FOR_EACH_BLUETOOTH_OBSERVER(SSPRequestCallback(remote_bd_addr, bd_name, cod, - pairing_variant, pass_key)); + pairing_variant, pass_key)); } -void BondStateChangedCallback( - bt_status_t status, - bt_bdaddr_t *remote_bd_addr, - bt_bond_state_t state) { +void BondStateChangedCallback(bt_status_t status, bt_bdaddr_t* remote_bd_addr, + bt_bond_state_t state) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); - VLOG(2) << __func__ - << " - remote_bd_addr: " << BtAddrString(remote_bd_addr) - << " - status: " << status - << " - state: " << state; - FOR_EACH_BLUETOOTH_OBSERVER(BondStateChangedCallback(status, remote_bd_addr, state)); + VLOG(2) << __func__ << " - remote_bd_addr: " << BtAddrString(remote_bd_addr) + << " - status: " << status << " - state: " << state; + FOR_EACH_BLUETOOTH_OBSERVER( + BondStateChangedCallback(status, remote_bd_addr, state)); } -void AclStateChangedCallback(bt_status_t status, - bt_bdaddr_t *remote_bd_addr, +void AclStateChangedCallback(bt_status_t status, bt_bdaddr_t* remote_bd_addr, bt_acl_state_t state) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); CHECK(remote_bd_addr); VLOG(1) << "Remote device ACL state changed - status: " << BtStatusText(status) - << " - BD_ADDR: " << BtAddrString(remote_bd_addr) - << " - state: " + << " - BD_ADDR: " << BtAddrString(remote_bd_addr) << " - state: " << ((state == BT_ACL_STATE_CONNECTED) ? "CONNECTED" : "DISCONNECTED"); FOR_EACH_BLUETOOTH_OBSERVER( AclStateChangedCallback(status, *remote_bd_addr, state)); @@ -164,10 +156,8 @@ void ThreadEventCallback(bt_cb_thread_evt evt) { // out if this is not set. Consider making this optional. } -bool SetWakeAlarmCallout(uint64_t /* delay_millis */, - bool /* should_wake */, - alarm_cb /* cb */, - void* /* data */) { +bool SetWakeAlarmCallout(uint64_t /* delay_millis */, bool /* should_wake */, + alarm_cb /* cb */, void* /* data */) { // TODO(armansito): According to sharvil@, this interface doesn't even need to // exist and can be done entirely from within osi by interfacing directly with // the kernel. Remove these stubs once that's fixed. (See http://b/23390297) @@ -194,42 +184,35 @@ int ReleaseWakeLockCallout(const char* /* lock_name */) { // The HAL Bluetooth DM callbacks. bt_callbacks_t bt_callbacks = { - sizeof(bt_callbacks_t), - AdapterStateChangedCallback, - AdapterPropertiesCallback, - RemoteDevicePropertiesCallback, - nullptr, /* device_found_cb */ - DiscoveryStateChangedCallback, - PinRequestCallback, - SSPRequestCallback, - BondStateChangedCallback, - AclStateChangedCallback, - ThreadEventCallback, - nullptr, /* dut_mode_recv_cb */ - nullptr, /* le_test_mode_cb */ - nullptr /* energy_info_cb */ + sizeof(bt_callbacks_t), + AdapterStateChangedCallback, + AdapterPropertiesCallback, + RemoteDevicePropertiesCallback, + nullptr, /* device_found_cb */ + DiscoveryStateChangedCallback, + PinRequestCallback, + SSPRequestCallback, + BondStateChangedCallback, + AclStateChangedCallback, + ThreadEventCallback, + nullptr, /* dut_mode_recv_cb */ + nullptr, /* le_test_mode_cb */ + nullptr /* energy_info_cb */ }; -bt_os_callouts_t bt_os_callouts = { - sizeof(bt_os_callouts_t), - SetWakeAlarmCallout, - AcquireWakeLockCallout, - ReleaseWakeLockCallout -}; +bt_os_callouts_t bt_os_callouts = {sizeof(bt_os_callouts_t), + SetWakeAlarmCallout, AcquireWakeLockCallout, + ReleaseWakeLockCallout}; } // namespace // BluetoothInterface implementation for production. class BluetoothInterfaceImpl : public BluetoothInterface { public: - BluetoothInterfaceImpl() - : hal_iface_(nullptr), - hal_adapter_(nullptr) { - } + BluetoothInterfaceImpl() : hal_iface_(nullptr), hal_adapter_(nullptr) {} ~BluetoothInterfaceImpl() override { - if (hal_iface_) - hal_iface_->cleanup(); + if (hal_iface_) hal_iface_->cleanup(); } // BluetoothInterface overrides. @@ -243,9 +226,7 @@ class BluetoothInterfaceImpl : public BluetoothInterface { observers_.RemoveObserver(observer); } - const bt_interface_t* GetHALInterface() const override { - return hal_iface_; - } + const bt_interface_t* GetHALInterface() const override { return hal_iface_; } const bluetooth_device_t* GetHALAdapter() const override { return hal_adapter_; @@ -317,8 +298,8 @@ namespace { // function is NOT thread safe. base::ObserverList* GetObservers() { CHECK(g_bluetooth_interface); - return static_cast( - g_bluetooth_interface)->observers(); + return static_cast(g_bluetooth_interface) + ->observers(); } } // namespace @@ -331,17 +312,14 @@ void BluetoothInterface::Observer::AdapterStateChangedCallback( } void BluetoothInterface::Observer::AdapterPropertiesCallback( - bt_status_t /* status */, - int /* num_properties */, + bt_status_t /* status */, int /* num_properties */, bt_property_t* /* properties */) { // Do nothing. } void BluetoothInterface::Observer::RemoteDevicePropertiesCallback( - bt_status_t /* status */, - bt_bdaddr_t* /* remote_bd_addr */, - int /* num_properties */, - bt_property_t* /* properties */) { + bt_status_t /* status */, bt_bdaddr_t* /* remote_bd_addr */, + int /* num_properties */, bt_property_t* /* properties */) { // Do nothing. } @@ -351,32 +329,24 @@ void BluetoothInterface::Observer::DiscoveryStateChangedCallback( } void BluetoothInterface::Observer::PinRequestCallback( - bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, - uint32_t cod, + bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod, bool min_16_digit) { // Do nothing. } void BluetoothInterface::Observer::SSPRequestCallback( - bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, - uint32_t cod, - bt_ssp_variant_t pairing_variant, - uint32_t pass_key) { + bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod, + bt_ssp_variant_t pairing_variant, uint32_t pass_key) { // Do nothing. } void BluetoothInterface::Observer::BondStateChangedCallback( - bt_status_t status, - bt_bdaddr_t *remote_bd_addr, - bt_bond_state_t state) { + bt_status_t status, bt_bdaddr_t* remote_bd_addr, bt_bond_state_t state) { // Do nothing. } void BluetoothInterface::Observer::AclStateChangedCallback( - bt_status_t /* status */, - const bt_bdaddr_t& /* remote_bdaddr */, + bt_status_t /* status */, const bt_bdaddr_t& /* remote_bdaddr */, bt_acl_state_t /* state */) { // Do nothing. } diff --git a/service/hal/bluetooth_interface.h b/service/hal/bluetooth_interface.h index 34e189761..3828fdd99 100644 --- a/service/hal/bluetooth_interface.h +++ b/service/hal/bluetooth_interface.h @@ -54,21 +54,19 @@ class BluetoothInterface { int num_properties, bt_property_t* properties); virtual void RemoteDevicePropertiesCallback(bt_status_t status, - bt_bdaddr_t *remote_bd_addr, + bt_bdaddr_t* remote_bd_addr, int num_properties, bt_property_t* properties); virtual void DiscoveryStateChangedCallback(bt_discovery_state_t state); - virtual void PinRequestCallback(bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, - uint32_t cod, + virtual void PinRequestCallback(bt_bdaddr_t* remote_bd_addr, + bt_bdname_t* bd_name, uint32_t cod, bool min_16_digit); - virtual void SSPRequestCallback(bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, - uint32_t cod, + virtual void SSPRequestCallback(bt_bdaddr_t* remote_bd_addr, + bt_bdname_t* bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key); virtual void BondStateChangedCallback(bt_status_t status, - bt_bdaddr_t *remote_bd_addr, + bt_bdaddr_t* remote_bd_addr, bt_bond_state_t state); virtual void AclStateChangedCallback(bt_status_t status, const bt_bdaddr_t& remote_bdaddr, diff --git a/service/hal/fake_bluetooth_gatt_interface.cc b/service/hal/fake_bluetooth_gatt_interface.cc index dbbd53303..911de2eec 100644 --- a/service/hal/fake_bluetooth_gatt_interface.cc +++ b/service/hal/fake_bluetooth_gatt_interface.cc @@ -24,46 +24,42 @@ namespace { // interface methods all have to be global and their signatures don't allow us // to pass in user_data. std::shared_ptr g_advertiser_handler; -std::shared_ptr g_scanner_handler; +std::shared_ptr + g_scanner_handler; std::shared_ptr g_client_handler; std::shared_ptr g_server_handler; bt_status_t FakeRegisterClient(bt_uuid_t* app_uuid) { - if (g_client_handler) - return g_client_handler->RegisterClient(app_uuid); + if (g_client_handler) return g_client_handler->RegisterClient(app_uuid); return BT_STATUS_FAIL; } bt_status_t FakeUnregisterClient(int client_if) { - if (g_client_handler) - return g_client_handler->UnregisterClient(client_if); + if (g_client_handler) return g_client_handler->UnregisterClient(client_if); return BT_STATUS_FAIL; } bt_status_t FakeRegisterScanner(bt_uuid_t* app_uuid) { - if (g_scanner_handler) - return g_scanner_handler->RegisterScanner(app_uuid); + if (g_scanner_handler) return g_scanner_handler->RegisterScanner(app_uuid); return BT_STATUS_FAIL; } bt_status_t FakeUnregisterScanner(int client_if) { - if (g_scanner_handler) - return g_scanner_handler->UnregisterScanner(client_if); + if (g_scanner_handler) return g_scanner_handler->UnregisterScanner(client_if); return BT_STATUS_FAIL; } bt_status_t FakeScan(bool start) { - if (g_scanner_handler) - return g_scanner_handler->Scan(start); + if (g_scanner_handler) return g_scanner_handler->Scan(start); return BT_STATUS_FAIL; } -bt_status_t FakeConnect(int client_if, const bt_bdaddr_t *bd_addr, +bt_status_t FakeConnect(int client_if, const bt_bdaddr_t* bd_addr, bool is_direct, int transport) { if (g_client_handler) return g_client_handler->Connect(client_if, bd_addr, is_direct, transport); @@ -71,7 +67,7 @@ bt_status_t FakeConnect(int client_if, const bt_bdaddr_t *bd_addr, return BT_STATUS_FAIL; } -bt_status_t FakeDisconnect(int client_if, const bt_bdaddr_t *bd_addr, +bt_status_t FakeDisconnect(int client_if, const bt_bdaddr_t* bd_addr, int conn_id) { if (g_client_handler) return g_client_handler->Disconnect(client_if, bd_addr, conn_id); @@ -80,21 +76,18 @@ bt_status_t FakeDisconnect(int client_if, const bt_bdaddr_t *bd_addr, } bt_status_t FakeRegisterServer(bt_uuid_t* app_uuid) { - if (g_server_handler) - return g_server_handler->RegisterServer(app_uuid); + if (g_server_handler) return g_server_handler->RegisterServer(app_uuid); return BT_STATUS_FAIL; } bt_status_t FakeUnregisterServer(int server_if) { - if (g_server_handler) - return g_server_handler->UnregisterServer(server_if); + if (g_server_handler) return g_server_handler->UnregisterServer(server_if); return BT_STATUS_FAIL; } -bt_status_t FakeAddService( - int server_if, vector service) { +bt_status_t FakeAddService(int server_if, vector service) { if (g_server_handler) return g_server_handler->AddService(server_if, std::move(service)); @@ -108,9 +101,8 @@ bt_status_t FakeDeleteService(int server_if, int srvc_handle) { return BT_STATUS_FAIL; } -bt_status_t FakeSendIndication(int server_if, int attribute_handle, - int conn_id, int confirm, - vector value) { +bt_status_t FakeSendIndication(int server_if, int attribute_handle, int conn_id, + int confirm, vector value) { if (g_server_handler) return g_server_handler->SendIndication(server_if, attribute_handle, conn_id, confirm, std::move(value)); @@ -127,52 +119,52 @@ bt_status_t FakeSendResponse(int conn_id, int trans_id, int status, } btgatt_scanner_interface_t fake_scanner_iface = { - FakeRegisterScanner, - FakeUnregisterScanner, - FakeScan, - nullptr, // scan_filter_param_setup - nullptr, // scan_filter_add_remove - nullptr, // scan_filter_clear - nullptr, // scan_filter_enable - nullptr, // set_scan_parameters - nullptr, // batchscan_cfg_storate - nullptr, // batchscan_enb_batch_scan - nullptr, // batchscan_dis_batch_scan - nullptr, // batchscan_read_reports + FakeRegisterScanner, + FakeUnregisterScanner, + FakeScan, + nullptr, // scan_filter_param_setup + nullptr, // scan_filter_add_remove + nullptr, // scan_filter_clear + nullptr, // scan_filter_enable + nullptr, // set_scan_parameters + nullptr, // batchscan_cfg_storate + nullptr, // batchscan_enb_batch_scan + nullptr, // batchscan_dis_batch_scan + nullptr, // batchscan_read_reports }; btgatt_client_interface_t fake_btgattc_iface = { - FakeRegisterClient, - FakeUnregisterClient, - FakeConnect, - FakeDisconnect, - nullptr, // refresh - nullptr, // search_service - nullptr, // read_characteristic - nullptr, // write_characteristic - nullptr, // read_descriptor - nullptr, // write_descriptor - nullptr, // execute_write - nullptr, // register_for_notification - nullptr, // deregister_for_notification - nullptr, // read_remote_rssi - nullptr, // get_device_type - nullptr, // configure_mtu - nullptr, // conn_parameter_update - nullptr, // test_command - nullptr, // get_gatt_db + FakeRegisterClient, + FakeUnregisterClient, + FakeConnect, + FakeDisconnect, + nullptr, // refresh + nullptr, // search_service + nullptr, // read_characteristic + nullptr, // write_characteristic + nullptr, // read_descriptor + nullptr, // write_descriptor + nullptr, // execute_write + nullptr, // register_for_notification + nullptr, // deregister_for_notification + nullptr, // read_remote_rssi + nullptr, // get_device_type + nullptr, // configure_mtu + nullptr, // conn_parameter_update + nullptr, // test_command + nullptr, // get_gatt_db }; btgatt_server_interface_t fake_btgatts_iface = { - FakeRegisterServer, - FakeUnregisterServer, - nullptr, // connect - nullptr, // disconnect - FakeAddService, - nullptr, // stop_service - FakeDeleteService, - FakeSendIndication, - FakeSendResponse, + FakeRegisterServer, + FakeUnregisterServer, + nullptr, // connect + nullptr, // disconnect + FakeAddService, + nullptr, // stop_service + FakeDeleteService, + FakeSendIndication, + FakeSendResponse, }; } // namespace @@ -189,38 +181,29 @@ FakeBluetoothGattInterface::FakeBluetoothGattInterface( CHECK(!g_server_handler); // We allow passing NULL. In this case all calls we fail by default. - if (advertiser_handler) - g_advertiser_handler = advertiser_handler; + if (advertiser_handler) g_advertiser_handler = advertiser_handler; - if (scanner_handler) - g_scanner_handler = scanner_handler; + if (scanner_handler) g_scanner_handler = scanner_handler; - if (client_handler) - g_client_handler = client_handler; + if (client_handler) g_client_handler = client_handler; - if (server_handler) - g_server_handler = server_handler; + if (server_handler) g_server_handler = server_handler; } FakeBluetoothGattInterface::~FakeBluetoothGattInterface() { - if (g_advertiser_handler) - g_advertiser_handler = nullptr; + if (g_advertiser_handler) g_advertiser_handler = nullptr; - if (g_scanner_handler) - g_scanner_handler = nullptr; + if (g_scanner_handler) g_scanner_handler = nullptr; - if (g_client_handler) - g_client_handler = nullptr; + if (g_client_handler) g_client_handler = nullptr; - if (g_server_handler) - g_server_handler = nullptr; + if (g_server_handler) g_server_handler = nullptr; } // The methods below can be used to notify observers with certain events and // given parameters. void FakeBluetoothGattInterface::NotifyRegisterScannerCallback( - int status, int client_if, - const bt_uuid_t& app_uuid) { + int status, int client_if, const bt_uuid_t& app_uuid) { FOR_EACH_OBSERVER(ScannerObserver, scanner_observers_, RegisterScannerCallback(this, status, client_if, app_uuid)); } @@ -232,14 +215,14 @@ void FakeBluetoothGattInterface::NotifyScanResultCallback( } void FakeBluetoothGattInterface::NotifyRegisterClientCallback( - int status, int client_if, - const bt_uuid_t& app_uuid) { + int status, int client_if, const bt_uuid_t& app_uuid) { FOR_EACH_OBSERVER(ClientObserver, client_observers_, RegisterClientCallback(this, status, client_if, app_uuid)); } -void FakeBluetoothGattInterface::NotifyConnectCallback( - int conn_id, int status, int client_if, const bt_bdaddr_t& bda) { +void FakeBluetoothGattInterface::NotifyConnectCallback(int conn_id, int status, + int client_if, + const bt_bdaddr_t& bda) { FOR_EACH_OBSERVER(ClientObserver, client_observers_, ConnectCallback(this, conn_id, status, client_if, bda)); } @@ -251,8 +234,7 @@ void FakeBluetoothGattInterface::NotifyDisconnectCallback( } void FakeBluetoothGattInterface::NotifyRegisterServerCallback( - int status, int server_if, - const bt_uuid_t& app_uuid) { + int status, int server_if, const bt_uuid_t& app_uuid) { FOR_EACH_OBSERVER(ServerObserver, server_observers_, RegisterServerCallback(this, status, server_if, app_uuid)); } @@ -265,11 +247,9 @@ void FakeBluetoothGattInterface::NotifyServerConnectionCallback( } void FakeBluetoothGattInterface::NotifyServiceAddedCallback( - int status, int server_if, - vector service) { - FOR_EACH_OBSERVER( - ServerObserver, server_observers_, - ServiceAddedCallback(this, status, server_if, service)); + int status, int server_if, vector service) { + FOR_EACH_OBSERVER(ServerObserver, server_observers_, + ServiceAddedCallback(this, status, server_if, service)); } void FakeBluetoothGattInterface::NotifyRequestReadCharacteristicCallback( @@ -277,8 +257,8 @@ void FakeBluetoothGattInterface::NotifyRequestReadCharacteristicCallback( int offset, bool is_long) { FOR_EACH_OBSERVER( ServerObserver, server_observers_, - RequestReadCharacteristicCallback( - this, conn_id, trans_id, bda, attr_handle, offset, is_long)); + RequestReadCharacteristicCallback(this, conn_id, trans_id, bda, + attr_handle, offset, is_long)); } void FakeBluetoothGattInterface::NotifyRequestReadDescriptorCallback( @@ -286,30 +266,26 @@ void FakeBluetoothGattInterface::NotifyRequestReadDescriptorCallback( int offset, bool is_long) { FOR_EACH_OBSERVER( ServerObserver, server_observers_, - RequestReadDescriptorCallback( - this, conn_id, trans_id, bda, attr_handle, offset, is_long)); + RequestReadDescriptorCallback(this, conn_id, trans_id, bda, attr_handle, + offset, is_long)); } void FakeBluetoothGattInterface::NotifyRequestWriteCharacteristicCallback( int conn_id, int trans_id, const bt_bdaddr_t& bda, int attr_handle, int offset, bool need_rsp, bool is_prep, vector value) { - FOR_EACH_OBSERVER( - ServerObserver, server_observers_, - RequestWriteCharacteristicCallback( - this, conn_id, trans_id, bda, attr_handle, offset, need_rsp, - is_prep, value)); + FOR_EACH_OBSERVER(ServerObserver, server_observers_, + RequestWriteCharacteristicCallback( + this, conn_id, trans_id, bda, attr_handle, offset, + need_rsp, is_prep, value)); } void FakeBluetoothGattInterface::NotifyRequestWriteDescriptorCallback( - int conn_id, int trans_id, - const bt_bdaddr_t& bda, int attr_handle, - int offset, bool need_rsp, bool is_prep, - vector value) { + int conn_id, int trans_id, const bt_bdaddr_t& bda, int attr_handle, + int offset, bool need_rsp, bool is_prep, vector value) { FOR_EACH_OBSERVER( ServerObserver, server_observers_, - RequestWriteDescriptorCallback( - this, conn_id, trans_id, bda, attr_handle, offset, need_rsp, - is_prep, value)); + RequestWriteDescriptorCallback(this, conn_id, trans_id, bda, attr_handle, + offset, need_rsp, is_prep, value)); } void FakeBluetoothGattInterface::NotifyRequestExecWriteCallback( @@ -319,8 +295,8 @@ void FakeBluetoothGattInterface::NotifyRequestExecWriteCallback( RequestExecWriteCallback(this, conn_id, trans_id, bda, exec_write)); } -void FakeBluetoothGattInterface::NotifyIndicationSentCallback( - int conn_id, int status) { +void FakeBluetoothGattInterface::NotifyIndicationSentCallback(int conn_id, + int status) { FOR_EACH_OBSERVER(ServerObserver, server_observers_, IndicationSentCallback(this, conn_id, status)); } @@ -368,7 +344,6 @@ FakeBluetoothGattInterface::GetScannerHALInterface() const { return &fake_scanner_iface; } - const btgatt_client_interface_t* FakeBluetoothGattInterface::GetClientHALInterface() const { return &fake_btgattc_iface; diff --git a/service/hal/fake_bluetooth_gatt_interface.h b/service/hal/fake_bluetooth_gatt_interface.h index 363e0530f..5d4005b2b 100644 --- a/service/hal/fake_bluetooth_gatt_interface.h +++ b/service/hal/fake_bluetooth_gatt_interface.h @@ -26,7 +26,6 @@ namespace hal { class FakeBluetoothGattInterface : public BluetoothGattInterface { public: - // Handles HAL LE scanner API calls for testing. Test code can // provide a fake or mock implementation of this and all calls will be routed // to it. @@ -50,9 +49,9 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { virtual bt_status_t RegisterClient(bt_uuid_t* app_uuid) = 0; virtual bt_status_t UnregisterClient(int client_if) = 0; - virtual bt_status_t Connect(int client_if, const bt_bdaddr_t *bd_addr, + virtual bt_status_t Connect(int client_if, const bt_bdaddr_t* bd_addr, bool is_direct, int transport) = 0; - virtual bt_status_t Disconnect(int client_if, const bt_bdaddr_t *bd_addr, + virtual bt_status_t Disconnect(int client_if, const bt_bdaddr_t* bd_addr, int conn_id) = 0; }; @@ -65,8 +64,8 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { virtual bt_status_t RegisterServer(bt_uuid_t* app_uuid) = 0; virtual bt_status_t UnregisterServer(int server_if) = 0; - virtual bt_status_t AddService( - int server_if, vector service) = 0; + virtual bt_status_t AddService(int server_if, + vector service) = 0; virtual bt_status_t DeleteService(int server_if, int srvc_handle) = 0; virtual bt_status_t SendIndication(int server_if, int attribute_handle, int conn_id, int confirm, @@ -78,17 +77,18 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { // Constructs the fake with the given handlers. Implementations can // provide their own handlers or simply pass "nullptr" for the default // behavior in which BT_STATUS_FAIL will be returned from all calls. - FakeBluetoothGattInterface(std::shared_ptr advertiser_handler, - std::shared_ptr scanner_handler, - std::shared_ptr client_handler, - std::shared_ptr server_handler); + FakeBluetoothGattInterface( + std::shared_ptr advertiser_handler, + std::shared_ptr scanner_handler, + std::shared_ptr client_handler, + std::shared_ptr server_handler); ~FakeBluetoothGattInterface(); // The methods below can be used to notify observers with certain events and // given parameters. void NotifyRegisterScannerCallback(int status, int client_if, - const bt_uuid_t& app_uuid); + const bt_uuid_t& app_uuid); void NotifyScanResultCallback(const bt_bdaddr_t& bda, int rssi, vector adv_data); @@ -103,32 +103,35 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { // Server callbacks: void NotifyRegisterServerCallback(int status, int server_if, const bt_uuid_t& app_uuid); - void NotifyServerConnectionCallback(int conn_id, int server_if, - int connected, + void NotifyServerConnectionCallback(int conn_id, int server_if, int connected, const bt_bdaddr_t& bda); void NotifyServiceAddedCallback(int status, int server_if, vector srvc); void NotifyCharacteristicAddedCallback(int status, int server_if, - const bt_uuid_t& uuid, - int srvc_handle, int char_handle); + const bt_uuid_t& uuid, int srvc_handle, + int char_handle); void NotifyDescriptorAddedCallback(int status, int server_if, - const bt_uuid_t& uuid, - int srvc_handle, int desc_handle); + const bt_uuid_t& uuid, int srvc_handle, + int desc_handle); void NotifyServiceStartedCallback(int status, int server_if, int srvc_handle); void NotifyRequestReadCharacteristicCallback(int conn_id, int trans_id, - const bt_bdaddr_t& bda, int attr_handle, - int offset, bool is_long); + const bt_bdaddr_t& bda, + int attr_handle, int offset, + bool is_long); void NotifyRequestReadDescriptorCallback(int conn_id, int trans_id, - const bt_bdaddr_t& bda, int attr_handle, - int offset, bool is_long); + const bt_bdaddr_t& bda, + int attr_handle, int offset, + bool is_long); void NotifyRequestWriteCharacteristicCallback(int conn_id, int trans_id, - const bt_bdaddr_t& bda, int attr_handle, - int offset, bool need_rsp, bool is_prep, - vector value); + const bt_bdaddr_t& bda, + int attr_handle, int offset, + bool need_rsp, bool is_prep, + vector value); void NotifyRequestWriteDescriptorCallback(int conn_id, int trans_id, - const bt_bdaddr_t& bda, int attr_handle, - int offset, bool need_rsp, bool is_prep, - vector value); + const bt_bdaddr_t& bda, + int attr_handle, int offset, + bool need_rsp, bool is_prep, + vector value); void NotifyRequestExecWriteCallback(int conn_id, int trans_id, const bt_bdaddr_t& bda, int exec_write); void NotifyIndicationSentCallback(int conn_id, int status); @@ -153,7 +156,6 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { std::shared_ptr client_handler_; std::shared_ptr server_handler_; - DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattInterface); }; diff --git a/service/hal/fake_bluetooth_interface.cc b/service/hal/fake_bluetooth_interface.cc index 5036c63c5..fce0e1040 100644 --- a/service/hal/fake_bluetooth_interface.cc +++ b/service/hal/fake_bluetooth_interface.cc @@ -31,50 +31,48 @@ int FakeHALDisable() { return g_hal_manager.disable_succeed ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; } -int FakeHALGetAdapterProperties() { - return BT_STATUS_SUCCESS; -} +int FakeHALGetAdapterProperties() { return BT_STATUS_SUCCESS; } int FakeHALSetAdapterProperty(const bt_property_t* /* property */) { LOG(INFO) << __func__; - return (g_hal_manager.set_property_succeed ? BT_STATUS_SUCCESS : - BT_STATUS_FAIL); + return (g_hal_manager.set_property_succeed ? BT_STATUS_SUCCESS + : BT_STATUS_FAIL); } bt_interface_t fake_bt_iface = { - sizeof(bt_interface_t), - nullptr, /* init */ - FakeHALEnable, - FakeHALDisable, - nullptr, /* cleanup */ - FakeHALGetAdapterProperties, - nullptr, /* get_adapter_property */ - FakeHALSetAdapterProperty, - nullptr, /* get_remote_device_properties */ - nullptr, /* get_remote_device_property */ - nullptr, /* set_remote_device_property */ - nullptr, /* get_remote_service_record */ - nullptr, /* get_remote_services */ - nullptr, /* start_discovery */ - nullptr, /* cancel_discovery */ - nullptr, /* create_bond */ - nullptr, /* create_bond_out_of_band */ - nullptr, /* remove_bond */ - nullptr, /* cancel_bond */ - nullptr, /* get_connection_state */ - nullptr, /* pin_reply */ - nullptr, /* ssp_reply */ - nullptr, /* get_profile_interface */ - nullptr, /* dut_mode_configure */ - nullptr, /* dut_more_send */ - nullptr, /* le_test_mode */ - nullptr, /* config_hci_snoop_log */ - nullptr, /* set_os_callouts */ - nullptr, /* read_energy_info */ - nullptr, /* dump */ - nullptr, /* config clear */ - nullptr, /* interop_database_clear */ - nullptr /* interop_database_add */ + sizeof(bt_interface_t), + nullptr, /* init */ + FakeHALEnable, + FakeHALDisable, + nullptr, /* cleanup */ + FakeHALGetAdapterProperties, + nullptr, /* get_adapter_property */ + FakeHALSetAdapterProperty, + nullptr, /* get_remote_device_properties */ + nullptr, /* get_remote_device_property */ + nullptr, /* set_remote_device_property */ + nullptr, /* get_remote_service_record */ + nullptr, /* get_remote_services */ + nullptr, /* start_discovery */ + nullptr, /* cancel_discovery */ + nullptr, /* create_bond */ + nullptr, /* create_bond_out_of_band */ + nullptr, /* remove_bond */ + nullptr, /* cancel_bond */ + nullptr, /* get_connection_state */ + nullptr, /* pin_reply */ + nullptr, /* ssp_reply */ + nullptr, /* get_profile_interface */ + nullptr, /* dut_mode_configure */ + nullptr, /* dut_more_send */ + nullptr, /* le_test_mode */ + nullptr, /* config_hci_snoop_log */ + nullptr, /* set_os_callouts */ + nullptr, /* read_energy_info */ + nullptr, /* dump */ + nullptr, /* config clear */ + nullptr, /* interop_database_clear */ + nullptr /* interop_database_add */ }; } // namespace @@ -87,16 +85,14 @@ FakeBluetoothInterface::Manager* FakeBluetoothInterface::GetManager() { FakeBluetoothInterface::Manager::Manager() : enable_succeed(false), disable_succeed(false), - set_property_succeed(false) { -} + set_property_succeed(false) {} void FakeBluetoothInterface::NotifyAdapterStateChanged(bt_state_t state) { FOR_EACH_OBSERVER(Observer, observers_, AdapterStateChangedCallback(state)); } void FakeBluetoothInterface::NotifyAdapterPropertiesChanged( - int num_properties, - bt_property_t* properties) { + int num_properties, bt_property_t* properties) { FOR_EACH_OBSERVER( Observer, observers_, AdapterPropertiesCallback(BT_STATUS_SUCCESS, num_properties, properties)); @@ -105,9 +101,8 @@ void FakeBluetoothInterface::NotifyAdapterPropertiesChanged( void FakeBluetoothInterface::NotifyAdapterNamePropertyChanged( const std::string& name) { bt_bdname_t hal_name; - strncpy(reinterpret_cast(hal_name.name), - name.c_str(), - std::min(sizeof(hal_name)-1, name.length())); + strncpy(reinterpret_cast(hal_name.name), name.c_str(), + std::min(sizeof(hal_name) - 1, name.length())); reinterpret_cast(hal_name.name)[name.length()] = '\0'; bt_property_t property; @@ -129,7 +124,7 @@ void FakeBluetoothInterface::NotifyAdapterAddressPropertyChanged( } void FakeBluetoothInterface::NotifyAdapterLocalLeFeaturesPropertyChanged( - const bt_local_le_features_t* features) { + const bt_local_le_features_t* features) { bt_property_t property; property.len = sizeof(*features); property.val = (void*)features; @@ -139,12 +134,10 @@ void FakeBluetoothInterface::NotifyAdapterLocalLeFeaturesPropertyChanged( } void FakeBluetoothInterface::NotifyAclStateChangedCallback( - bt_status_t status, - const bt_bdaddr_t& remote_bdaddr, + bt_status_t status, const bt_bdaddr_t& remote_bdaddr, bt_acl_state_t state) { - FOR_EACH_OBSERVER( - Observer, observers_, - AclStateChangedCallback(status, remote_bdaddr, state)); + FOR_EACH_OBSERVER(Observer, observers_, + AclStateChangedCallback(status, remote_bdaddr, state)); } void FakeBluetoothInterface::AddObserver(Observer* observer) { diff --git a/service/hal/fake_bluetooth_interface.h b/service/hal/fake_bluetooth_interface.h index 553d4e01e..1bc7b5a53 100644 --- a/service/hal/fake_bluetooth_interface.h +++ b/service/hal/fake_bluetooth_interface.h @@ -54,10 +54,9 @@ class FakeBluetoothInterface : public BluetoothInterface { void NotifyAdapterAddressPropertyChanged(const bt_bdaddr_t* address); void NotifyAdapterLocalLeFeaturesPropertyChanged( const bt_local_le_features_t* features); - void NotifyAclStateChangedCallback( - bt_status_t status, - const bt_bdaddr_t& remote_bdaddr, - bt_acl_state_t state); + void NotifyAclStateChangedCallback(bt_status_t status, + const bt_bdaddr_t& remote_bdaddr, + bt_acl_state_t state); // hal::BluetoothInterface overrides: void AddObserver(Observer* observer) override; diff --git a/service/ipc/binder/bluetooth_binder_server.cc b/service/ipc/binder/bluetooth_binder_server.cc index 953f97464..ea2d2c281 100644 --- a/service/ipc/binder/bluetooth_binder_server.cc +++ b/service/ipc/binder/bluetooth_binder_server.cc @@ -20,9 +20,9 @@ #include "service/ipc/binder/bluetooth_gatt_client_binder_server.h" #include "service/ipc/binder/bluetooth_gatt_server_binder_server.h" -#include "service/ipc/binder/bluetooth_low_energy_binder_server.h" #include "service/ipc/binder/bluetooth_le_advertiser_binder_server.h" #include "service/ipc/binder/bluetooth_le_scanner_binder_server.h" +#include "service/ipc/binder/bluetooth_low_energy_binder_server.h" #include "service/hal/bluetooth_interface.h" @@ -60,7 +60,8 @@ Status BluetoothBinderServer::GetState(int32_t* _aidl_return) { return Status::ok(); } -Status BluetoothBinderServer::Enable(bool start_restricted, bool* _aidl_return) { +Status BluetoothBinderServer::Enable(bool start_restricted, + bool* _aidl_return) { VLOG(2) << __func__; *_aidl_return = adapter_->Enable(start_restricted); return Status::ok(); @@ -157,7 +158,8 @@ Status BluetoothBinderServer::GetLeAdvertiserInterface( VLOG(2) << __func__; if (!adapter_->IsEnabled()) { - LOG(ERROR) << "Cannot obtain IBluetoothLeAdvertiser interface while disabled"; + LOG(ERROR) + << "Cannot obtain IBluetoothLeAdvertiser interface while disabled"; *_aidl_return = NULL; return Status::ok(); } diff --git a/service/ipc/binder/bluetooth_binder_server.h b/service/ipc/binder/bluetooth_binder_server.h index 45cb01828..55a330046 100644 --- a/service/ipc/binder/bluetooth_binder_server.h +++ b/service/ipc/binder/bluetooth_binder_server.h @@ -27,9 +27,9 @@ #include #include #include -#include #include #include +#include #include "service/adapter.h" #include "service/common/bluetooth/uuid.h" diff --git a/service/ipc/binder/bluetooth_gatt_server_binder_server.cc b/service/ipc/binder/bluetooth_gatt_server_binder_server.cc index 228e9cbbe..f0f071735 100644 --- a/service/ipc/binder/bluetooth_gatt_server_binder_server.cc +++ b/service/ipc/binder/bluetooth_gatt_server_binder_server.cc @@ -162,8 +162,8 @@ Status BluetoothGattServerBinderServer::SendNotification( }; if (!gatt_server->SendNotification( - std::string(String8(device_address).string()), handle, - confirm, value, callback)) { + std::string(String8(device_address).string()), handle, confirm, value, + callback)) { LOG(ERROR) << "Failed to send notification"; *_aidl_return = false; return Status::ok(); @@ -290,7 +290,8 @@ void BluetoothGattServerBinderServer::OnExecuteWriteRequest( } void BluetoothGattServerBinderServer::OnConnectionStateChanged( - bluetooth::GattServer* gatt_server, const std::string& device_address, bool connected) { + bluetooth::GattServer* gatt_server, const std::string& device_address, + bool connected) { VLOG(2) << __func__; std::lock_guard lock(*maps_lock()); diff --git a/service/ipc/binder/bluetooth_gatt_server_binder_server.h b/service/ipc/binder/bluetooth_gatt_server_binder_server.h index 0d8f1d924..8a6dc02ec 100644 --- a/service/ipc/binder/bluetooth_gatt_server_binder_server.h +++ b/service/ipc/binder/bluetooth_gatt_server_binder_server.h @@ -51,33 +51,40 @@ class BluetoothGattServerBinderServer : public BnBluetoothGattServer, bool* _aidl_return) override; Status UnregisterServer(int32_t server_id) override; Status UnregisterAll() override; - Status AddService(int32_t server_id, const ::android::bluetooth::BluetoothGattService& service, + Status AddService(int32_t server_id, + const ::android::bluetooth::BluetoothGattService& service, bool* _aidl_return) override; Status SendResponse(int32_t server_id, const ::android::String16& device_address, int32_t request_id, int32_t status, int32_t offset, const ::std::vector& value, bool* _aidl_return) override; - Status SendNotification( - int32_t server_id, const ::android::String16& device_address, - int handle, bool confirm, const ::std::vector& value, - bool* _aidl_return) override; + Status SendNotification(int32_t server_id, + const ::android::String16& device_address, int handle, + bool confirm, const ::std::vector& value, + bool* _aidl_return) override; // bluetooth::GattServer::Delegate overrides: - void OnCharacteristicReadRequest( - bluetooth::GattServer* gatt_server, const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) override; - void OnDescriptorReadRequest( - bluetooth::GattServer* gatt_server, const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) override; - void OnCharacteristicWriteRequest( - bluetooth::GattServer* gatt_server, const std::string& device_address, - int request_id, int offset, bool is_prepare_write, bool need_response, - const std::vector& value, uint16_t handle) override; - void OnDescriptorWriteRequest( - bluetooth::GattServer* gatt_server, const std::string& device_address, - int request_id, int offset, bool is_prepare_write, bool need_response, - const std::vector& value, uint16_t handle) override; + void OnCharacteristicReadRequest(bluetooth::GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, bool is_long, + uint16_t handle) override; + void OnDescriptorReadRequest(bluetooth::GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, bool is_long, + uint16_t handle) override; + void OnCharacteristicWriteRequest(bluetooth::GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + uint16_t handle) override; + void OnDescriptorWriteRequest(bluetooth::GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + uint16_t handle) override; void OnExecuteWriteRequest(bluetooth::GattServer* gatt_server, const std::string& device_address, int request_id, bool is_execute) override; diff --git a/service/ipc/binder/bluetooth_le_advertiser_binder_server.cc b/service/ipc/binder/bluetooth_le_advertiser_binder_server.cc index a992c32d3..170e94c5c 100644 --- a/service/ipc/binder/bluetooth_le_advertiser_binder_server.cc +++ b/service/ipc/binder/bluetooth_le_advertiser_binder_server.cc @@ -50,7 +50,8 @@ Status BluetoothLeAdvertiserBinderServer::RegisterAdvertiser( return Status::ok(); } -Status BluetoothLeAdvertiserBinderServer::UnregisterAdvertiser(int advertiser_id) { +Status BluetoothLeAdvertiserBinderServer::UnregisterAdvertiser( + int advertiser_id) { VLOG(2) << __func__; UnregisterInstanceBase(advertiser_id); return Status::ok(); @@ -99,7 +100,7 @@ Status BluetoothLeAdvertiserBinderServer::StartMultiAdvertising( }; if (!advertiser->StartAdvertising(settings, advertise_data, scan_response, - callback)) { + callback)) { LOG(ERROR) << "Failed to initiate call to start advertising"; *_aidl_return = false; return Status::ok(); @@ -134,7 +135,8 @@ Status BluetoothLeAdvertiserBinderServer::StopMultiAdvertising( auto cb = GetLECallback(advertiser_id); if (!cb.get()) { - VLOG(2) << "Advertiser was unregistered - advertiser_id: " << advertiser_id; + VLOG(2) << "Advertiser was unregistered - advertiser_id: " + << advertiser_id; return; } @@ -174,8 +176,8 @@ void BluetoothLeAdvertiserBinderServer::OnRegisterInstanceImpl( android::sp cb( static_cast(callback.get())); cb->OnAdvertiserRegistered(status, (status == bluetooth::BLE_STATUS_SUCCESS) - ? instance->GetInstanceId() - : kInvalidInstanceId); + ? instance->GetInstanceId() + : kInvalidInstanceId); } } // namespace binder diff --git a/service/ipc/binder/bluetooth_le_advertiser_binder_server.h b/service/ipc/binder/bluetooth_le_advertiser_binder_server.h index 5a9f84dbd..fc00db57d 100644 --- a/service/ipc/binder/bluetooth_le_advertiser_binder_server.h +++ b/service/ipc/binder/bluetooth_le_advertiser_binder_server.h @@ -41,9 +41,8 @@ namespace ipc { namespace binder { // Implements the server side of the IBluetoothLowEnergy interface. -class BluetoothLeAdvertiserBinderServer - : public BnBluetoothLeAdvertiser, - public InterfaceWithInstancesBase { +class BluetoothLeAdvertiserBinderServer : public BnBluetoothLeAdvertiser, + public InterfaceWithInstancesBase { public: explicit BluetoothLeAdvertiserBinderServer(bluetooth::Adapter* adapter); ~BluetoothLeAdvertiserBinderServer() override; @@ -55,7 +54,8 @@ class BluetoothLeAdvertiserBinderServer Status UnregisterAdvertiser(int advertiser_id) override; Status UnregisterAll() override; Status StartMultiAdvertising( - int advertiser_id, const android::bluetooth::AdvertiseData& advertise_data, + int advertiser_id, + const android::bluetooth::AdvertiseData& advertise_data, const android::bluetooth::AdvertiseData& scan_response, const android::bluetooth::AdvertiseSettings& settings, bool* _aidl_return) override; @@ -68,7 +68,8 @@ class BluetoothLeAdvertiserBinderServer // Returns a pointer to the LowEnergyAdvertiser instance associated with // |advertiser_id|. Returns NULL if such a advertiser cannot be found. - std::shared_ptr GetLEAdvertiser(int advertiser_id); + std::shared_ptr GetLEAdvertiser( + int advertiser_id); // InterfaceWithInstancesBase override: void OnRegisterInstanceImpl(bluetooth::BLEStatus status, diff --git a/service/ipc/binder/bluetooth_le_scanner_binder_server.cc b/service/ipc/binder/bluetooth_le_scanner_binder_server.cc index e65ed067e..0c20a4600 100644 --- a/service/ipc/binder/bluetooth_le_scanner_binder_server.cc +++ b/service/ipc/binder/bluetooth_le_scanner_binder_server.cc @@ -140,8 +140,8 @@ void BluetoothLeScannerBinderServer::OnRegisterInstanceImpl( android::sp cb( static_cast(callback.get())); cb->OnScannerRegistered(status, (status == bluetooth::BLE_STATUS_SUCCESS) - ? instance->GetInstanceId() - : kInvalidInstanceId); + ? instance->GetInstanceId() + : kInvalidInstanceId); } } // namespace binder diff --git a/service/ipc/binder/bluetooth_le_scanner_binder_server.h b/service/ipc/binder/bluetooth_le_scanner_binder_server.h index 655c91b48..ef9a90086 100644 --- a/service/ipc/binder/bluetooth_le_scanner_binder_server.h +++ b/service/ipc/binder/bluetooth_le_scanner_binder_server.h @@ -63,6 +63,7 @@ class BluetoothLeScannerBinderServer void OnScanResult(bluetooth::LowEnergyScanner* scanner, const bluetooth::ScanResult& result) override; + private: // Returns a pointer to the IBluetoothLowEnergyCallback instance associated // with |scanner_id|. Returns NULL if such a callback cannot be found. diff --git a/service/ipc/binder/ipc_handler_binder.cc b/service/ipc/binder/ipc_handler_binder.cc index c1757d034..5b9212050 100644 --- a/service/ipc/binder/ipc_handler_binder.cc +++ b/service/ipc/binder/ipc_handler_binder.cc @@ -35,14 +35,11 @@ namespace ipc { std::string kServiceName = "bluetooth-service"; -IPCHandlerBinder::IPCHandlerBinder( - bluetooth::Adapter* adapter, - IPCManager::Delegate* delegate) - : IPCHandler(adapter, delegate) { -} +IPCHandlerBinder::IPCHandlerBinder(bluetooth::Adapter* adapter, + IPCManager::Delegate* delegate) + : IPCHandler(adapter, delegate) {} -IPCHandlerBinder::~IPCHandlerBinder() { -} +IPCHandlerBinder::~IPCHandlerBinder() {} bool IPCHandlerBinder::Run() { CHECK(adapter()); @@ -51,8 +48,7 @@ bool IPCHandlerBinder::Run() { android::sp bt_server = new binder::BluetoothBinderServer(adapter()); status_t status = defaultServiceManager()->addService( - String16(String8(kServiceName.c_str())), - bt_server); + String16(String8(kServiceName.c_str())), bt_server); if (status != android::NO_ERROR) { LOG(ERROR) << "Failed to register Bluetooth service with ServiceManager"; return false; @@ -61,8 +57,7 @@ bool IPCHandlerBinder::Run() { // Notify the delegate. We do this in the message loop to avoid reentrancy. if (delegate()) { base::MessageLoop::current()->task_runner()->PostTask( - FROM_HERE, - base::Bind(&IPCHandlerBinder::NotifyStarted, this)); + FROM_HERE, base::Bind(&IPCHandlerBinder::NotifyStarted, this)); } android::ProcessState::self()->startThreadPool(); @@ -78,8 +73,7 @@ void IPCHandlerBinder::Stop() { } void IPCHandlerBinder::NotifyStarted() { - if (delegate()) - delegate()->OnIPCHandlerStarted(IPCManager::TYPE_BINDER); + if (delegate()) delegate()->OnIPCHandlerStarted(IPCManager::TYPE_BINDER); } } // namespace ipc diff --git a/service/ipc/binder/remote_callback_list.h b/service/ipc/binder/remote_callback_list.h index aa612fa2e..e62b7efe9 100644 --- a/service/ipc/binder/remote_callback_list.h +++ b/service/ipc/binder/remote_callback_list.h @@ -49,7 +49,7 @@ namespace binder { // against a mock version of this class. // // TODO(armansito): Consider submitting this class to frameworks/native/binder. -template +template class RemoteCallbackList final { public: RemoteCallbackList() = default; @@ -103,14 +103,14 @@ using android::IInterface; using android::sp; using android::wp; -template +template RemoteCallbackList::~RemoteCallbackList() { std::lock_guard lock(map_lock_); for (auto iter = callbacks_.begin(); iter != callbacks_.end(); ++iter) UnregisterInternal(iter); } -template +template bool RemoteCallbackList::Register(const sp& callback) { std::lock_guard lock(map_lock_); @@ -134,7 +134,7 @@ bool RemoteCallbackList::Register(const sp& callback) { return true; } -template +template bool RemoteCallbackList::Unregister(const sp& callback) { std::lock_guard lock(map_lock_); @@ -148,14 +148,14 @@ bool RemoteCallbackList::Unregister(const sp& callback) { return UnregisterInternal(iter); } -template +template void RemoteCallbackList::ForEach(const std::function& callback) { std::lock_guard lock(map_lock_); for (const auto& iter : callbacks_) callback(iter.second->get_callback().get()); } -template +template bool RemoteCallbackList::UnregisterInternal( typename CallbackMap::iterator iter) { sp dr = iter->second; @@ -176,17 +176,15 @@ bool RemoteCallbackList::UnregisterInternal( return true; } -template +template RemoteCallbackList::CallbackDeathRecipient::CallbackDeathRecipient( - const sp& callback, - RemoteCallbackList* owner) - : callback_(callback), - owner_(owner) { + const sp& callback, RemoteCallbackList* owner) + : callback_(callback), owner_(owner) { CHECK(callback_.get()); CHECK(owner_); } -template +template void RemoteCallbackList::CallbackDeathRecipient::binderDied( const wp& who) { VLOG(1) << "Received binderDied"; diff --git a/service/ipc/binder/remote_callback_map.h b/service/ipc/binder/remote_callback_map.h index f6aaf05a9..b3422ac1e 100644 --- a/service/ipc/binder/remote_callback_map.h +++ b/service/ipc/binder/remote_callback_map.h @@ -34,7 +34,7 @@ namespace binder { // TODO(armansito): We should make this class non-final and the template // interface abstract, so that code that depends on this can be unit tested // against a mock version of this class. -template +template class RemoteCallbackMap final { public: RemoteCallbackMap() = default; @@ -60,8 +60,7 @@ class RemoteCallbackMap final { // // An optional |delegate| can be passed which will be assocated with the given // key/value pair. |delegate| must outlive this map. - bool Register(const K& key, - const android::sp& callback, + bool Register(const K& key, const android::sp& callback, Delegate* delegate = nullptr); // Unregisters a previously registered callback with the given key. Returns @@ -82,11 +81,8 @@ class RemoteCallbackMap final { private: class CallbackDeathRecipient : public android::IBinder::DeathRecipient { public: - CallbackDeathRecipient( - const K& key, - const android::sp& callback, - RemoteCallbackMap* owner, - Delegate* delegate); + CallbackDeathRecipient(const K& key, const android::sp& callback, + RemoteCallbackMap* owner, Delegate* delegate); android::sp get_callback() const { return callback_; } @@ -97,7 +93,7 @@ class RemoteCallbackMap final { K key_; android::sp callback_; RemoteCallbackMap* owner_; // weak - Delegate* delegate_; // weak + Delegate* delegate_; // weak }; // Typedef for internal map container. @@ -122,16 +118,14 @@ using android::wp; using std::lock_guard; using std::mutex; -template +template RemoteCallbackMap::~RemoteCallbackMap() { Clear(); } -template -bool RemoteCallbackMap::Register( - const K& key, - const sp& callback, - Delegate* delegate) { +template +bool RemoteCallbackMap::Register(const K& key, const sp& callback, + Delegate* delegate) { lock_guard lock(map_lock_); if (map_.find(key) != map_.end()) { @@ -154,7 +148,7 @@ bool RemoteCallbackMap::Register( return true; } -template +template bool RemoteCallbackMap::Unregister(const K& key) { lock_guard lock(map_lock_); @@ -167,31 +161,29 @@ bool RemoteCallbackMap::Unregister(const K& key) { return UnregisterInternal(iter); } -template +template sp RemoteCallbackMap::Get(const K& key) { lock_guard lock(map_lock_); auto iter = map_.find(key); - if (iter == map_.end()) - return nullptr; + if (iter == map_.end()) return nullptr; return iter->second->get_callback(); } -template +template sp RemoteCallbackMap::Remove(const K& key) { lock_guard lock(map_lock_); auto iter = map_.find(key); - if (iter == map_.end()) - return nullptr; + if (iter == map_.end()) return nullptr; sp val = iter->second->get_callback(); UnregisterInternal(iter); return val; } -template +template void RemoteCallbackMap::Clear() { lock_guard lock(map_lock_); @@ -199,7 +191,7 @@ void RemoteCallbackMap::Clear() { UnregisterInternal(iter++); } -template +template bool RemoteCallbackMap::UnregisterInternal( typename CallbackMap::iterator iter) { sp dr = iter->second; @@ -220,20 +212,15 @@ bool RemoteCallbackMap::UnregisterInternal( return true; } -template +template RemoteCallbackMap::CallbackDeathRecipient::CallbackDeathRecipient( - const K& key, - const sp& callback, - RemoteCallbackMap* owner, + const K& key, const sp& callback, RemoteCallbackMap* owner, Delegate* delegate) - : key_(key), - callback_(callback), - owner_(owner), - delegate_(delegate) { + : key_(key), callback_(callback), owner_(owner), delegate_(delegate) { CHECK(callback_.get()); } -template +template void RemoteCallbackMap::CallbackDeathRecipient::binderDied( const wp& who) { VLOG(1) << "Received binderDied"; @@ -252,8 +239,7 @@ void RemoteCallbackMap::CallbackDeathRecipient::binderDied( VLOG(1) << "Callback from dead process unregistered; notifying delegate"; // Notify delegate. - if (delegate_) - delegate_->OnRemoteCallbackRemoved(key_); + if (delegate_) delegate_->OnRemoteCallbackRemoved(key_); } } // namespace binder diff --git a/service/ipc/ipc_handler.cc b/service/ipc/ipc_handler.cc index ffea0ee04..66d9c03d2 100644 --- a/service/ipc/ipc_handler.cc +++ b/service/ipc/ipc_handler.cc @@ -22,12 +22,10 @@ namespace ipc { IPCHandler::IPCHandler(bluetooth::Adapter* adapter, IPCManager::Delegate* delegate) - : adapter_(adapter), - delegate_(delegate) { + : adapter_(adapter), delegate_(delegate) { CHECK(adapter_); } -IPCHandler::~IPCHandler() { -} +IPCHandler::~IPCHandler() {} } // namespace ipc diff --git a/service/ipc/ipc_handler_linux.cc b/service/ipc/ipc_handler_linux.cc index b9f181e74..bcd21aa7e 100644 --- a/service/ipc/ipc_handler_linux.cc +++ b/service/ipc/ipc_handler_linux.cc @@ -29,18 +29,16 @@ namespace ipc { IPCHandlerLinux::IPCHandlerLinux(bluetooth::Adapter* adapter, - IPCManager::Delegate* delegate) + IPCManager::Delegate* delegate) : IPCHandler(adapter, delegate), running_(false), thread_("IPCHandlerLinux"), - keep_running_(true) { -} + keep_running_(true) {} IPCHandlerLinux::~IPCHandlerLinux() { // This will only be set if the Settings::create_ipc_socket_path() was // originally provided. - if (!socket_path_.empty()) - unlink(socket_path_.value().c_str()); + if (!socket_path_.empty()) unlink(socket_path_.value().c_str()); } bool IPCHandlerLinux::Run() { @@ -112,8 +110,7 @@ bool IPCHandlerLinux::Run() { } thread_.task_runner()->PostTask( - FROM_HERE, - base::Bind(&IPCHandlerLinux::StartListeningOnThread, this)); + FROM_HERE, base::Bind(&IPCHandlerLinux::StartListeningOnThread, this)); return true; } @@ -146,8 +143,7 @@ void IPCHandlerLinux::StartListeningOnThread() { if (status < 0) { LOG(ERROR) << "Failed to listen on domain socket: " << strerror(errno); origin_task_runner_->PostTask( - FROM_HERE, - base::Bind(&IPCHandlerLinux::ShutDownOnOriginThread, this)); + FROM_HERE, base::Bind(&IPCHandlerLinux::ShutDownOnOriginThread, this)); return; } @@ -185,8 +181,7 @@ void IPCHandlerLinux::ShutDownOnOriginThread() { } void IPCHandlerLinux::NotifyStartedOnOriginThread() { - if (!delegate()) - return; + if (!delegate()) return; origin_task_runner_->PostTask( FROM_HERE, @@ -194,13 +189,11 @@ void IPCHandlerLinux::NotifyStartedOnOriginThread() { } void IPCHandlerLinux::NotifyStartedOnCurrentThread() { - if (delegate()) - delegate()->OnIPCHandlerStarted(IPCManager::TYPE_LINUX); + if (delegate()) delegate()->OnIPCHandlerStarted(IPCManager::TYPE_LINUX); } void IPCHandlerLinux::NotifyStoppedOnOriginThread() { - if (!delegate()) - return; + if (!delegate()) return; origin_task_runner_->PostTask( FROM_HERE, @@ -208,8 +201,7 @@ void IPCHandlerLinux::NotifyStoppedOnOriginThread() { } void IPCHandlerLinux::NotifyStoppedOnCurrentThread() { - if (delegate()) - delegate()->OnIPCHandlerStopped(IPCManager::TYPE_LINUX); + if (delegate()) delegate()->OnIPCHandlerStopped(IPCManager::TYPE_LINUX); } } // namespace ipc diff --git a/service/ipc/ipc_handler_linux.h b/service/ipc/ipc_handler_linux.h index 82e31428a..b00eb2715 100644 --- a/service/ipc/ipc_handler_linux.h +++ b/service/ipc/ipc_handler_linux.h @@ -35,8 +35,7 @@ namespace ipc { // Implements a Linux sequential packet domain-socket based IPCHandler class IPCHandlerLinux : public IPCHandler { public: - IPCHandlerLinux(bluetooth::Adapter* adapter, - IPCManager::Delegate* delegate); + IPCHandlerLinux(bluetooth::Adapter* adapter, IPCManager::Delegate* delegate); ~IPCHandlerLinux() override; // IPCHandler overrides: @@ -60,7 +59,7 @@ class IPCHandlerLinux : public IPCHandler { void NotifyStoppedOnOriginThread(); void NotifyStoppedOnCurrentThread(); - // True, if the IPC mechanism is running. +// True, if the IPC mechanism is running. #if defined(__APPLE__) bool running_ ATTRIBUTE_UNUSED; #else diff --git a/service/ipc/ipc_manager.cc b/service/ipc/ipc_manager.cc index b0e82c87e..74c53bc06 100644 --- a/service/ipc/ipc_manager.cc +++ b/service/ipc/ipc_manager.cc @@ -23,61 +23,54 @@ namespace ipc { -IPCManager::IPCManager(bluetooth::Adapter* adapter) - : adapter_(adapter) { +IPCManager::IPCManager(bluetooth::Adapter* adapter) : adapter_(adapter) { CHECK(adapter_); } IPCManager::~IPCManager() { // Don't rely on the handlers getting destroyed since another thread might be // holding a reference to them. Instead, explicitly stop them here. - if (BinderStarted()) - binder_handler_->Stop(); - if (LinuxStarted()) - linux_handler_->Stop(); + if (BinderStarted()) binder_handler_->Stop(); + if (LinuxStarted()) linux_handler_->Stop(); } bool IPCManager::Start(Type type, Delegate* delegate) { switch (type) { - case TYPE_LINUX: - if (LinuxStarted()) { - LOG(ERROR) << "IPCManagerLinux already started."; - return false; - } + case TYPE_LINUX: + if (LinuxStarted()) { + LOG(ERROR) << "IPCManagerLinux already started."; + return false; + } - linux_handler_ = new IPCHandlerLinux(adapter_, delegate); - if (!linux_handler_->Run()) { - linux_handler_ = nullptr; - return false; - } - return true; + linux_handler_ = new IPCHandlerLinux(adapter_, delegate); + if (!linux_handler_->Run()) { + linux_handler_ = nullptr; + return false; + } + return true; #if !defined(OS_GENERIC) - case TYPE_BINDER: - if (BinderStarted()) { - LOG(ERROR) << "IPCManagerBinder already started."; - return false; - } + case TYPE_BINDER: + if (BinderStarted()) { + LOG(ERROR) << "IPCManagerBinder already started."; + return false; + } - binder_handler_ = new IPCHandlerBinder(adapter_, delegate); - if (!binder_handler_->Run()) { - binder_handler_ = nullptr; - return false; - } - return true; + binder_handler_ = new IPCHandlerBinder(adapter_, delegate); + if (!binder_handler_->Run()) { + binder_handler_ = nullptr; + return false; + } + return true; #endif // !defined(OS_GENERIC) - default: - LOG(ERROR) << "Unsupported IPC type given: " << type; + default: + LOG(ERROR) << "Unsupported IPC type given: " << type; } return false; } -bool IPCManager::BinderStarted() const { - return binder_handler_.get(); -} +bool IPCManager::BinderStarted() const { return binder_handler_.get(); } -bool IPCManager::LinuxStarted() const { - return linux_handler_.get(); -} +bool IPCManager::LinuxStarted() const { return linux_handler_.get(); } } // namespace ipc diff --git a/service/ipc/linux_ipc_host.cc b/service/ipc/linux_ipc_host.cc index a3176a97b..7b328cf53 100644 --- a/service/ipc/linux_ipc_host.cc +++ b/service/ipc/linux_ipc_host.cc @@ -33,8 +33,8 @@ #include #include -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "service/adapter.h" using bluetooth::Adapter; @@ -66,9 +66,7 @@ enum { kPossibleFds = 2, }; -bool TokenBool(const std::string& text) { - return text == "true"; -} +bool TokenBool(const std::string& text) { return text == "true"; } } // namespace @@ -77,9 +75,7 @@ namespace ipc { LinuxIPCHost::LinuxIPCHost(int sockfd, Adapter* adapter) : adapter_(adapter), pfds_(1, {sockfd, POLLIN, 0}) {} -LinuxIPCHost::~LinuxIPCHost() { - close(pfds_[0].fd); -} +LinuxIPCHost::~LinuxIPCHost() { close(pfds_[0].fd); } bool LinuxIPCHost::EventLoop() { while (true) { @@ -94,8 +90,7 @@ bool LinuxIPCHost::EventLoop() { return false; } - if (pfds_.size() == kPossibleFds && - pfds_[kFdGatt].revents && + if (pfds_.size() == kPossibleFds && pfds_[kFdGatt].revents && !OnGattWrite()) { return false; } @@ -113,8 +108,8 @@ bool LinuxIPCHost::OnCreateService(const std::string& service_uuid) { gatt_servers_[service_uuid] = std::unique_ptr(new Server); int gattfd; - bool status = gatt_servers_[service_uuid]->Initialize( - UUID(service_uuid), &gattfd); + bool status = + gatt_servers_[service_uuid]->Initialize(UUID(service_uuid), &gattfd); if (!status) { LOG_ERROR(LOG_TAG, "Failed to initialize bluetooth"); return false; @@ -132,9 +127,9 @@ bool LinuxIPCHost::OnDestroyService(const std::string& service_uuid) { } bool LinuxIPCHost::OnAddCharacteristic(const std::string& service_uuid, - const std::string& characteristic_uuid, - const std::string& control_uuid, - const std::string& options) { + const std::string& characteristic_uuid, + const std::string& control_uuid, + const std::string& options) { std::vector option_tokens = base::SplitString( options, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); @@ -169,9 +164,9 @@ bool LinuxIPCHost::OnAddCharacteristic(const std::string& service_uuid, return true; } -bool LinuxIPCHost::OnSetCharacteristicValue(const std::string& service_uuid, - const std::string& characteristic_uuid, - const std::string& value) { +bool LinuxIPCHost::OnSetCharacteristicValue( + const std::string& service_uuid, const std::string& characteristic_uuid, + const std::string& value) { std::string decoded_data; base::Base64Decode(value, &decoded_data); std::vector blob_data(decoded_data.begin(), decoded_data.end()); @@ -181,12 +176,13 @@ bool LinuxIPCHost::OnSetCharacteristicValue(const std::string& service_uuid, } bool LinuxIPCHost::OnSetAdvertisement(const std::string& service_uuid, - const std::string& advertise_uuids, - const std::string& advertise_data, - const std::string& manufacturer_data, - const std::string& transmit_name) { - LOG_INFO(LOG_TAG, "%s: service:%s uuids:%s data:%s", __func__, service_uuid.c_str(), - advertise_uuids.c_str(), advertise_data.c_str()); + const std::string& advertise_uuids, + const std::string& advertise_data, + const std::string& manufacturer_data, + const std::string& transmit_name) { + LOG_INFO(LOG_TAG, "%s: service:%s uuids:%s data:%s", __func__, + service_uuid.c_str(), advertise_uuids.c_str(), + advertise_data.c_str()); std::vector advertise_uuid_tokens = base::SplitString( advertise_uuids, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); @@ -212,10 +208,10 @@ bool LinuxIPCHost::OnSetAdvertisement(const std::string& service_uuid, } bool LinuxIPCHost::OnSetScanResponse(const std::string& service_uuid, - const std::string& scan_response_uuids, - const std::string& scan_response_data, - const std::string& manufacturer_data, - const std::string& transmit_name) { + const std::string& scan_response_uuids, + const std::string& scan_response_data, + const std::string& manufacturer_data, + const std::string& transmit_name) { std::vector scan_response_uuid_tokens = base::SplitString( scan_response_uuids, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); @@ -251,8 +247,8 @@ bool LinuxIPCHost::OnMessage() { std::string ipc_msg; ssize_t size; - OSI_NO_INTR(size = recv(pfds_[kFdIpc].fd, &ipc_msg[0], 0, - MSG_PEEK | MSG_TRUNC)); + OSI_NO_INTR(size = + recv(pfds_[kFdIpc].fd, &ipc_msg[0], 0, MSG_PEEK | MSG_TRUNC)); if (-1 == size) { LOG_ERROR(LOG_TAG, "Error reading datagram size: %s", strerror(errno)); return false; @@ -277,14 +273,11 @@ bool LinuxIPCHost::OnMessage() { case 2: if (tokens[0] == kSetAdapterNameCommand) return OnSetAdapterName(tokens[1]); - if (tokens[0] == kCreateServiceCommand) - return OnCreateService(tokens[1]); + if (tokens[0] == kCreateServiceCommand) return OnCreateService(tokens[1]); if (tokens[0] == kDestroyServiceCommand) return OnDestroyService(tokens[1]); - if (tokens[0] == kStartServiceCommand) - return OnStartService(tokens[1]); - if (tokens[0] == kStopServiceCommand) - return OnStopService(tokens[1]); + if (tokens[0] == kStartServiceCommand) return OnStartService(tokens[1]); + if (tokens[0] == kStopServiceCommand) return OnStopService(tokens[1]); break; case 4: if (tokens[0] == kSetCharacteristicValueCommand) @@ -296,9 +289,11 @@ bool LinuxIPCHost::OnMessage() { break; case 6: if (tokens[0] == kSetAdvertisementCommand) - return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]); + return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4], + tokens[5]); if (tokens[0] == kSetScanResponseCommand) - return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]); + return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4], + tokens[5]); break; default: break; diff --git a/service/ipc/linux_ipc_host.h b/service/ipc/linux_ipc_host.h index 48d25cb5f..a51a96602 100644 --- a/service/ipc/linux_ipc_host.h +++ b/service/ipc/linux_ipc_host.h @@ -93,7 +93,7 @@ class LinuxIPCHost { bool OnStopService(const std::string& service_uuid); // weak reference. - bluetooth::Adapter *adapter_; + bluetooth::Adapter* adapter_; // File descripters that we will block against. std::vector pfds_; diff --git a/service/logging_helpers.cc b/service/logging_helpers.cc index 287a7631c..34e70e49d 100644 --- a/service/logging_helpers.cc +++ b/service/logging_helpers.cc @@ -23,7 +23,7 @@ case code: \ return #code -const char *BtAvConnectionStateText(const btav_connection_state_t state) { +const char* BtAvConnectionStateText(const btav_connection_state_t state) { switch (state) { CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTED); CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTING); @@ -34,7 +34,7 @@ const char *BtAvConnectionStateText(const btav_connection_state_t state) { } } -const char *BtAvAudioStateText(const btav_audio_state_t state) { +const char* BtAvAudioStateText(const btav_audio_state_t state) { switch (state) { CASE_RETURN_TEXT(BTAV_AUDIO_STATE_REMOTE_SUSPEND); CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STOPPED); @@ -44,8 +44,8 @@ const char *BtAvAudioStateText(const btav_audio_state_t state) { } } -const char *BtTransportText(const btgatt_transport_t t) { - switch(t) { +const char* BtTransportText(const btgatt_transport_t t) { + switch (t) { CASE_RETURN_TEXT(GATT_TRANSPORT_AUTO); CASE_RETURN_TEXT(GATT_TRANSPORT_BREDR); CASE_RETURN_TEXT(GATT_TRANSPORT_LE); @@ -54,7 +54,7 @@ const char *BtTransportText(const btgatt_transport_t t) { } } -const char *BtStateText(const bt_state_t state) { +const char* BtStateText(const bt_state_t state) { switch (state) { CASE_RETURN_TEXT(BT_STATE_OFF); CASE_RETURN_TEXT(BT_STATE_ON); @@ -63,7 +63,7 @@ const char *BtStateText(const bt_state_t state) { } } -const char *BtDiscoveryStateText(const bt_discovery_state_t state) { +const char* BtDiscoveryStateText(const bt_discovery_state_t state) { switch (state) { CASE_RETURN_TEXT(BT_DISCOVERY_STOPPED); CASE_RETURN_TEXT(BT_DISCOVERY_STARTED); @@ -72,7 +72,7 @@ const char *BtDiscoveryStateText(const bt_discovery_state_t state) { } } -const char *BtScanModeText(const bt_scan_mode_t mode) { +const char* BtScanModeText(const bt_scan_mode_t mode) { switch (mode) { CASE_RETURN_TEXT(BT_SCAN_MODE_NONE); CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE); @@ -82,7 +82,7 @@ const char *BtScanModeText(const bt_scan_mode_t mode) { } } -const char *BtStatusText(const bt_status_t status) { +const char* BtStatusText(const bt_status_t status) { switch (status) { CASE_RETURN_TEXT(BT_STATUS_SUCCESS); CASE_RETURN_TEXT(BT_STATUS_FAIL); @@ -101,7 +101,7 @@ const char *BtStatusText(const bt_status_t status) { } } -const char *BtPropertyText(const bt_property_type_t prop) { +const char* BtPropertyText(const bt_property_type_t prop) { switch (prop) { CASE_RETURN_TEXT(BT_PROPERTY_BDNAME); CASE_RETURN_TEXT(BT_PROPERTY_BDADDR); @@ -122,7 +122,7 @@ const char *BtPropertyText(const bt_property_type_t prop) { } } -const char *BtEventText(const bt_cb_thread_evt evt) { +const char* BtEventText(const bt_cb_thread_evt evt) { switch (evt) { CASE_RETURN_TEXT(ASSOCIATE_JVM); CASE_RETURN_TEXT(DISASSOCIATE_JVM); @@ -131,7 +131,7 @@ const char *BtEventText(const bt_cb_thread_evt evt) { } } -const char *BtAclText(const bt_acl_state_t code) { +const char* BtAclText(const bt_acl_state_t code) { switch (code) { CASE_RETURN_TEXT(BT_ACL_STATE_CONNECTED); CASE_RETURN_TEXT(BT_ACL_STATE_DISCONNECTED); @@ -140,7 +140,7 @@ const char *BtAclText(const bt_acl_state_t code) { } } -std::string BtAddrString(const bt_bdaddr_t *addr) { +std::string BtAddrString(const bt_bdaddr_t* addr) { char buffer[20]; snprintf(buffer, sizeof(buffer), "%02X:%02X:%02X:%02X:%02X:%02X", addr->address[0], addr->address[1], addr->address[2], diff --git a/service/logging_helpers.h b/service/logging_helpers.h index 6eb1cb10b..4462f3e26 100644 --- a/service/logging_helpers.h +++ b/service/logging_helpers.h @@ -23,25 +23,25 @@ #include "hardware/bt_av.h" #include "hardware/bt_gatt_types.h" -const char *BtAvConnectionStateText(const btav_connection_state_t state); +const char* BtAvConnectionStateText(const btav_connection_state_t state); -const char *BtAvAudioStateText(const btav_audio_state_t state); +const char* BtAvAudioStateText(const btav_audio_state_t state); -const char *BtTransportText(const btgatt_transport_t t); +const char* BtTransportText(const btgatt_transport_t t); -const char *BtStateText(const bt_state_t state); +const char* BtStateText(const bt_state_t state); -const char *BtDiscoveryStateText(const bt_discovery_state_t); +const char* BtDiscoveryStateText(const bt_discovery_state_t); -const char *BtScanModeText(const bt_scan_mode_t mode); +const char* BtScanModeText(const bt_scan_mode_t mode); -const char *BtStatusText(const bt_status_t status); +const char* BtStatusText(const bt_status_t status); -const char *BtPropertyText(const bt_property_type_t prop); +const char* BtPropertyText(const bt_property_type_t prop); -const char *BtEventText(const bt_cb_thread_evt evt); +const char* BtEventText(const bt_cb_thread_evt evt); -const char *BtAclText(const bt_acl_state_t state); +const char* BtAclText(const bt_acl_state_t state); // TODO(icoolidge): Address object. -std::string BtAddrString(const bt_bdaddr_t *addr); +std::string BtAddrString(const bt_bdaddr_t* addr); diff --git a/service/low_energy_advertiser.cc b/service/low_energy_advertiser.cc index 06c0b808f..1077999f4 100644 --- a/service/low_energy_advertiser.cc +++ b/service/low_energy_advertiser.cc @@ -33,8 +33,7 @@ namespace bluetooth { namespace { BLEStatus GetBLEStatus(int status) { - if (status == BT_STATUS_FAIL) - return BLE_STATUS_FAILURE; + if (status == BT_STATUS_FAIL) return BLE_STATUS_FAILURE; return static_cast(status); } @@ -48,17 +47,17 @@ int GetAdvertisingIntervalUnit(AdvertiseSettings::Mode mode) { int ms; switch (mode) { - case AdvertiseSettings::MODE_BALANCED: - ms = kAdvertisingIntervalMediumMs; - break; - case AdvertiseSettings::MODE_LOW_LATENCY: - ms = kAdvertisingIntervalLowMs; - break; - case AdvertiseSettings::MODE_LOW_POWER: + case AdvertiseSettings::MODE_BALANCED: + ms = kAdvertisingIntervalMediumMs; + break; + case AdvertiseSettings::MODE_LOW_LATENCY: + ms = kAdvertisingIntervalLowMs; + break; + case AdvertiseSettings::MODE_LOW_POWER: // Fall through - default: - ms = kAdvertisingIntervalHighMs; - break; + default: + ms = kAdvertisingIntervalHighMs; + break; } // Convert milliseconds to Bluetooth units. @@ -90,29 +89,28 @@ void DoNothing(uint8_t status) {} // LowEnergyAdvertiser implementation // ======================================================== -LowEnergyAdvertiser::LowEnergyAdvertiser(const UUID& uuid, int advertiser_id) : - app_identifier_(uuid), +LowEnergyAdvertiser::LowEnergyAdvertiser(const UUID& uuid, int advertiser_id) + : app_identifier_(uuid), advertiser_id_(advertiser_id), adv_started_(false), adv_start_callback_(nullptr), - adv_stop_callback_(nullptr) { -} + adv_stop_callback_(nullptr) {} LowEnergyAdvertiser::~LowEnergyAdvertiser() { // Automatically unregister the advertiser. VLOG(1) << "LowEnergyAdvertiser unregistering advertiser: " << advertiser_id_; // Stop advertising and ignore the result. - hal::BluetoothGattInterface::Get()-> - GetAdvertiserHALInterface()->Enable(advertiser_id_, false, base::Bind(&DoNothing), 0, base::Bind(&DoNothing)); - hal::BluetoothGattInterface::Get()-> - GetAdvertiserHALInterface()->Unregister(advertiser_id_); + hal::BluetoothGattInterface::Get()->GetAdvertiserHALInterface()->Enable( + advertiser_id_, false, base::Bind(&DoNothing), 0, base::Bind(&DoNothing)); + hal::BluetoothGattInterface::Get()->GetAdvertiserHALInterface()->Unregister( + advertiser_id_); } bool LowEnergyAdvertiser::StartAdvertising(const AdvertiseSettings& settings, - const AdvertiseData& advertise_data, - const AdvertiseData& scan_response, - const StatusCallback& callback) { + const AdvertiseData& advertise_data, + const AdvertiseData& scan_response, + const StatusCallback& callback) { VLOG(2) << __func__; lock_guard lock(adv_fields_lock_); @@ -171,14 +169,12 @@ bool LowEnergyAdvertiser::StopAdvertising(const StatusCallback& callback) { return false; } - hal::BluetoothGattInterface::Get() - ->GetAdvertiserHALInterface() - ->Enable( - advertiser_id_, false, - base::Bind(&LowEnergyAdvertiser::EnableCallback, - base::Unretained(this), false, advertiser_id_), - 0, base::Bind(&LowEnergyAdvertiser::EnableCallback, - base::Unretained(this), false, advertiser_id_)); + hal::BluetoothGattInterface::Get()->GetAdvertiserHALInterface()->Enable( + advertiser_id_, false, + base::Bind(&LowEnergyAdvertiser::EnableCallback, base::Unretained(this), + false, advertiser_id_), + 0, base::Bind(&LowEnergyAdvertiser::EnableCallback, + base::Unretained(this), false, advertiser_id_)); // OK to set this at the end since we're still holding |adv_fields_lock_|. adv_stop_callback_.reset(new StatusCallback(callback)); @@ -202,20 +198,16 @@ const UUID& LowEnergyAdvertiser::GetAppIdentifier() const { return app_identifier_; } -int LowEnergyAdvertiser::GetInstanceId() const { - return advertiser_id_; -} +int LowEnergyAdvertiser::GetInstanceId() const { return advertiser_id_; } -void LowEnergyAdvertiser::EnableCallback( - bool enable, uint8_t advertiser_id, uint8_t status) { - if (advertiser_id != advertiser_id_) - return; +void LowEnergyAdvertiser::EnableCallback(bool enable, uint8_t advertiser_id, + uint8_t status) { + if (advertiser_id != advertiser_id_) return; lock_guard lock(adv_fields_lock_); VLOG(1) << __func__ << "advertiser_id: " << advertiser_id - << " status: " << status - << " enable: " << enable; + << " status: " << status << " enable: " << enable; if (enable) { CHECK(adv_start_callback_); @@ -237,7 +229,8 @@ void LowEnergyAdvertiser::EnableCallback( CHECK(adv_stop_callback_); if (status == BT_STATUS_SUCCESS) { - VLOG(1) << "Multi-advertising stopped for advertiser_id: " << advertiser_id; + VLOG(1) << "Multi-advertising stopped for advertiser_id: " + << advertiser_id; adv_started_ = false; } else { LOG(ERROR) << "Failed to stop multi-advertising"; @@ -249,16 +242,14 @@ void LowEnergyAdvertiser::EnableCallback( void LowEnergyAdvertiser::InvokeAndClearStartCallback(BLEStatus status) { // We allow NULL callbacks. - if (*adv_start_callback_) - (*adv_start_callback_)(status); + if (*adv_start_callback_) (*adv_start_callback_)(status); adv_start_callback_ = nullptr; } void LowEnergyAdvertiser::InvokeAndClearStopCallback(BLEStatus status) { // We allow NULL callbacks. - if (*adv_stop_callback_) - (*adv_stop_callback_)(status); + if (*adv_stop_callback_) (*adv_stop_callback_)(status); adv_stop_callback_ = nullptr; } @@ -266,11 +257,9 @@ void LowEnergyAdvertiser::InvokeAndClearStopCallback(BLEStatus status) { // LowEnergyAdvertiserFactory implementation // ======================================================== -LowEnergyAdvertiserFactory::LowEnergyAdvertiserFactory() { -} +LowEnergyAdvertiserFactory::LowEnergyAdvertiserFactory() {} -LowEnergyAdvertiserFactory::~LowEnergyAdvertiserFactory() { -} +LowEnergyAdvertiserFactory::~LowEnergyAdvertiserFactory() {} bool LowEnergyAdvertiserFactory::RegisterInstance( const UUID& app_uuid, const RegisterCallback& callback) { diff --git a/service/low_energy_advertiser.h b/service/low_energy_advertiser.h index f45a14c8c..a014ae132 100644 --- a/service/low_energy_advertiser.h +++ b/service/low_energy_advertiser.h @@ -42,7 +42,6 @@ class Adapter; // should be obtained through the factory. class LowEnergyAdvertiser : public BluetoothInstance { public: - // The destructor automatically unregisters this client instance from the // stack. ~LowEnergyAdvertiser() override; @@ -87,12 +86,9 @@ class LowEnergyAdvertiser : public BluetoothInstance { LowEnergyAdvertiser(const UUID& uuid, int advertiser_id); // BluetoothGattInterface::AdvertiserObserver overrides: - void SetDataCallback( - uint8_t advertiser_id, uint8_t status); - void SetParamsCallback( - uint8_t advertiser_id, uint8_t status); - void EnableCallback( - bool enable, uint8_t advertiser_id, uint8_t status); + void SetDataCallback(uint8_t advertiser_id, uint8_t status); + void SetParamsCallback(uint8_t advertiser_id, uint8_t status); + void EnableCallback(bool enable, uint8_t advertiser_id, uint8_t status); // Calls and clears the pending callbacks. void InvokeAndClearStartCallback(BLEStatus status); @@ -108,7 +104,6 @@ class LowEnergyAdvertiser : public BluetoothInstance { // Latest advertising settings. AdvertiseSettings advertise_settings_; - std::atomic_bool adv_started_; std::unique_ptr adv_start_callback_; std::unique_ptr adv_stop_callback_; @@ -117,11 +112,11 @@ class LowEnergyAdvertiser : public BluetoothInstance { }; // LowEnergyAdvertiserFactory is used to register and obtain a per-application -// LowEnergyAdvertiser instance. Users should call RegisterInstance to obtain their +// LowEnergyAdvertiser instance. Users should call RegisterInstance to obtain +// their // own unique LowEnergyAdvertiser instance that has been registered with the // Bluetooth stack. -class LowEnergyAdvertiserFactory - : public BluetoothInstanceFactory { +class LowEnergyAdvertiserFactory : public BluetoothInstanceFactory { public: // Don't construct/destruct directly except in tests. Instead, obtain a handle // from an Adapter instance. @@ -129,7 +124,8 @@ class LowEnergyAdvertiserFactory ~LowEnergyAdvertiserFactory() override; // BluetoothInstanceFactory override: - bool RegisterInstance(const UUID& app_uuid, const RegisterCallback& callback) override; + bool RegisterInstance(const UUID& app_uuid, + const RegisterCallback& callback) override; private: friend class LowEnergyAdvertiser; diff --git a/service/low_energy_client.cc b/service/low_energy_client.cc index 3fce0356f..dc99b6c69 100644 --- a/service/low_energy_client.cc +++ b/service/low_energy_client.cc @@ -32,13 +32,12 @@ namespace bluetooth { // LowEnergyClient implementation // ======================================================== -LowEnergyClient::LowEnergyClient( - Adapter& adapter, const UUID& uuid, int client_id) +LowEnergyClient::LowEnergyClient(Adapter& adapter, const UUID& uuid, + int client_id) : adapter_(adapter), app_identifier_(uuid), client_id_(client_id), - delegate_(nullptr) { -} + delegate_(nullptr) {} LowEnergyClient::~LowEnergyClient() { // Automatically unregister the client. @@ -47,8 +46,9 @@ LowEnergyClient::~LowEnergyClient() { // Unregister as observer so we no longer receive any callbacks. hal::BluetoothGattInterface::Get()->RemoveClientObserver(this); - hal::BluetoothGattInterface::Get()-> - GetClientHALInterface()->unregister_client(client_id_); + hal::BluetoothGattInterface::Get() + ->GetClientHALInterface() + ->unregister_client(client_id_); } bool LowEnergyClient::Connect(const std::string& address, bool is_direct) { @@ -57,9 +57,9 @@ bool LowEnergyClient::Connect(const std::string& address, bool is_direct) { bt_bdaddr_t bda; util::BdAddrFromString(address, &bda); - bt_status_t status = hal::BluetoothGattInterface::Get()-> - GetClientHALInterface()->connect(client_id_, &bda, is_direct, - BT_TRANSPORT_LE); + bt_status_t status = + hal::BluetoothGattInterface::Get()->GetClientHALInterface()->connect( + client_id_, &bda, is_direct, BT_TRANSPORT_LE); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "HAL call to connect failed"; return false; @@ -84,8 +84,9 @@ bool LowEnergyClient::Disconnect(const std::string& address) { } } - bt_status_t status = hal::BluetoothGattInterface::Get()-> - GetClientHALInterface()->disconnect(client_id_, &bda, conn_id->second); + bt_status_t status = + hal::BluetoothGattInterface::Get()->GetClientHALInterface()->disconnect( + client_id_, &bda, conn_id->second); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "HAL call to disconnect failed"; return false; @@ -95,8 +96,7 @@ bool LowEnergyClient::Disconnect(const std::string& address) { } bool LowEnergyClient::SetMtu(const std::string& address, int mtu) { - VLOG(2) << __func__ << "Address: " << address - << " MTU: " << mtu; + VLOG(2) << __func__ << "Address: " << address << " MTU: " << mtu; bt_bdaddr_t bda; util::BdAddrFromString(address, &bda); @@ -111,8 +111,9 @@ bool LowEnergyClient::SetMtu(const std::string& address, int mtu) { } } - bt_status_t status = hal::BluetoothGattInterface::Get()-> - GetClientHALInterface()->configure_mtu(conn_id->second, mtu); + bt_status_t status = hal::BluetoothGattInterface::Get() + ->GetClientHALInterface() + ->configure_mtu(conn_id->second, mtu); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "HAL call to set MTU failed"; return false; @@ -130,15 +131,12 @@ const UUID& LowEnergyClient::GetAppIdentifier() const { return app_identifier_; } -int LowEnergyClient::GetInstanceId() const { - return client_id_; -} +int LowEnergyClient::GetInstanceId() const { return client_id_; } -void LowEnergyClient::ConnectCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int client_id, const bt_bdaddr_t& bda) { - if (client_id != client_id_) - return; +void LowEnergyClient::ConnectCallback(hal::BluetoothGattInterface* gatt_iface, + int conn_id, int status, int client_id, + const bt_bdaddr_t& bda) { + if (client_id != client_id_) return; VLOG(1) << __func__ << "client_id: " << client_id << " status: " << status; @@ -156,10 +154,9 @@ void LowEnergyClient::ConnectCallback( } void LowEnergyClient::DisconnectCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int client_id, const bt_bdaddr_t& bda) { - if (client_id != client_id_) - return; + hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, + int client_id, const bt_bdaddr_t& bda) { + if (client_id != client_id_) return; VLOG(1) << __func__ << " client_id: " << client_id << " status: " << status; { @@ -175,15 +172,14 @@ void LowEnergyClient::DisconnectCallback( } void LowEnergyClient::MtuChangedCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int mtu) { + hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, int mtu) { VLOG(1) << __func__ << " conn_id: " << conn_id << " status: " << status << " mtu: " << mtu; - const bt_bdaddr_t *bda = nullptr; + const bt_bdaddr_t* bda = nullptr; { lock_guard lock(connection_fields_lock_); - for (auto& connection: connection_ids_) { + for (auto& connection : connection_ids_) { if (connection.second == conn_id) { bda = &connection.first; break; @@ -191,12 +187,10 @@ void LowEnergyClient::MtuChangedCallback( } } - if (!bda) - return; + if (!bda) return; - const char *addr = BtAddrString(bda).c_str(); - if (delegate_) - delegate_->OnMtuChanged(this, status, addr, mtu); + const char* addr = BtAddrString(bda).c_str(); + if (delegate_) delegate_->OnMtuChanged(this, status, addr, mtu); } // LowEnergyClientFactory implementation @@ -212,8 +206,7 @@ LowEnergyClientFactory::~LowEnergyClientFactory() { } bool LowEnergyClientFactory::RegisterInstance( - const UUID& uuid, - const RegisterCallback& callback) { + const UUID& uuid, const RegisterCallback& callback) { VLOG(1) << __func__ << " - UUID: " << uuid.ToString(); lock_guard lock(pending_calls_lock_); @@ -227,8 +220,7 @@ bool LowEnergyClientFactory::RegisterInstance( hal::BluetoothGattInterface::Get()->GetClientHALInterface(); bt_uuid_t app_uuid = uuid.GetBlueDroid(); - if (hal_iface->register_client(&app_uuid) != BT_STATUS_SUCCESS) - return false; + if (hal_iface->register_client(&app_uuid) != BT_STATUS_SUCCESS) return false; pending_calls_[uuid] = callback; @@ -236,8 +228,7 @@ bool LowEnergyClientFactory::RegisterInstance( } void LowEnergyClientFactory::RegisterClientCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int client_id, + hal::BluetoothGattInterface* gatt_iface, int status, int client_id, const bt_uuid_t& app_uuid) { UUID uuid(app_uuid); diff --git a/service/low_energy_client.h b/service/low_energy_client.h index b8e4fec1f..d9b1d37d0 100644 --- a/service/low_energy_client.h +++ b/service/low_energy_client.h @@ -34,9 +34,9 @@ namespace bluetooth { struct ConnComparator { - bool operator()(const bt_bdaddr_t& a, const bt_bdaddr_t& b) const { - return memcmp(&a, &b, sizeof(bt_bdaddr_t)) < 0; - } + bool operator()(const bt_bdaddr_t& a, const bt_bdaddr_t& b) const { + return memcmp(&a, &b, sizeof(bt_bdaddr_t)) < 0; + } }; class Adapter; @@ -59,8 +59,8 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, const char* address, bool connected) = 0; // Called asynchronously to notify the delegate of mtu change - virtual void OnMtuChanged(LowEnergyClient* client, int status, const char* address, - int mtu) = 0; + virtual void OnMtuChanged(LowEnergyClient* client, int status, + const char* address, int mtu) = 0; private: DISALLOW_COPY_AND_ASSIGN(Delegate); @@ -102,15 +102,14 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, LowEnergyClient(Adapter& adapter, const UUID& uuid, int client_id); // BluetoothGattInterface::ClientObserver overrides: - void ConnectCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int client_id, const bt_bdaddr_t& bda) override; - void DisconnectCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int client_id, const bt_bdaddr_t& bda) override; - void MtuChangedCallback( - hal::BluetoothGattInterface* gatt_iface, int conn_id, int status, - int mtu) override; + void ConnectCallback(hal::BluetoothGattInterface* gatt_iface, int conn_id, + int status, int client_id, + const bt_bdaddr_t& bda) override; + void DisconnectCallback(hal::BluetoothGattInterface* gatt_iface, int conn_id, + int status, int client_id, + const bt_bdaddr_t& bda) override; + void MtuChangedCallback(hal::BluetoothGattInterface* gatt_iface, int conn_id, + int status, int mtu) override; // Calls and clears the pending callbacks. void InvokeAndClearStartCallback(BLEStatus status); @@ -132,7 +131,7 @@ class LowEnergyClient : private hal::BluetoothGattInterface::ClientObserver, std::mutex connection_fields_lock_; // Maps bluetooth address to connection id - //TODO(jpawlowski): change type to bimap + // TODO(jpawlowski): change type to bimap std::map connection_ids_; DISALLOW_COPY_AND_ASSIGN(LowEnergyClient); @@ -159,10 +158,9 @@ class LowEnergyClientFactory friend class LowEnergyClient; // BluetoothGattInterface::ClientObserver overrides: - void RegisterClientCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int client_id, - const bt_uuid_t& app_uuid) override; + void RegisterClientCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int client_id, + const bt_uuid_t& app_uuid) override; // Map of pending calls to register. std::mutex pending_calls_lock_; diff --git a/service/low_energy_scanner.cc b/service/low_energy_scanner.cc index c865e9bc4..b1d937a4b 100644 --- a/service/low_energy_scanner.cc +++ b/service/low_energy_scanner.cc @@ -54,8 +54,7 @@ size_t GetScanRecordLength(vector bytes) { // If the field length is zero and we haven't reached the maximum length, // then we have found the length, as the stack will pad the data with zeros // accordingly. - if (field_len == 0) - return i; + if (field_len == 0) return i; } // We have reached the end. @@ -82,12 +81,12 @@ LowEnergyScanner::~LowEnergyScanner() { // Unregister as observer so we no longer receive any callbacks. hal::BluetoothGattInterface::Get()->RemoveScannerObserver(this); - hal::BluetoothGattInterface::Get()-> - GetScannerHALInterface()->unregister_scanner(scanner_id_); + hal::BluetoothGattInterface::Get() + ->GetScannerHALInterface() + ->unregister_scanner(scanner_id_); // Stop any scans started by this client. - if (scan_started_.load()) - StopScan(); + if (scan_started_.load()) StopScan(); } void LowEnergyScanner::SetDelegate(Delegate* delegate) { @@ -96,7 +95,7 @@ void LowEnergyScanner::SetDelegate(Delegate* delegate) { } bool LowEnergyScanner::StartScan(const ScanSettings& settings, - const std::vector& filters) { + const std::vector& filters) { VLOG(2) << __func__; // Cannot start a scan if the adapter is not enabled. @@ -106,8 +105,8 @@ bool LowEnergyScanner::StartScan(const ScanSettings& settings, } // TODO(jpawlowski): Push settings and filtering logic below the HAL. - bt_status_t status = hal::BluetoothGattInterface::Get()-> - StartScan(scanner_id_); + bt_status_t status = + hal::BluetoothGattInterface::Get()->StartScan(scanner_id_); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to initiate scanning for client: " << scanner_id_; return false; @@ -123,8 +122,8 @@ bool LowEnergyScanner::StopScan() { // TODO(armansito): We don't support batch scanning yet so call // StopRegularScanForClient directly. In the future we will need to // conditionally call a batch scan API here. - bt_status_t status = hal::BluetoothGattInterface::Get()-> - StopScan(scanner_id_); + bt_status_t status = + hal::BluetoothGattInterface::Get()->StopScan(scanner_id_); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Failed to stop scan for client: " << scanner_id_; return false; @@ -138,25 +137,22 @@ const UUID& LowEnergyScanner::GetAppIdentifier() const { return app_identifier_; } -int LowEnergyScanner::GetInstanceId() const { - return scanner_id_; -} +int LowEnergyScanner::GetInstanceId() const { return scanner_id_; } void LowEnergyScanner::ScanResultCallback( - hal::BluetoothGattInterface* gatt_iface, - const bt_bdaddr_t& bda, int rssi, vector adv_data) { + hal::BluetoothGattInterface* gatt_iface, const bt_bdaddr_t& bda, int rssi, + vector adv_data) { // Ignore scan results if this client didn't start a scan. - if (!scan_started_.load()) - return; + if (!scan_started_.load()) return; lock_guard lock(delegate_mutex_); - if (!delegate_) - return; + if (!delegate_) return; // TODO(armansito): Apply software filters here. size_t record_len = GetScanRecordLength(adv_data); - std::vector scan_record(adv_data.begin(), adv_data.begin() + record_len); + std::vector scan_record(adv_data.begin(), + adv_data.begin() + record_len); ScanResult result(BtAddrString(&bda), scan_record, rssi); @@ -166,7 +162,8 @@ void LowEnergyScanner::ScanResultCallback( // LowEnergyScannerFactory implementation // ======================================================== -LowEnergyScannerFactory::LowEnergyScannerFactory(Adapter& adapter) : adapter_(adapter) { +LowEnergyScannerFactory::LowEnergyScannerFactory(Adapter& adapter) + : adapter_(adapter) { hal::BluetoothGattInterface::Get()->AddScannerObserver(this); } @@ -175,8 +172,7 @@ LowEnergyScannerFactory::~LowEnergyScannerFactory() { } bool LowEnergyScannerFactory::RegisterInstance( - const UUID& uuid, - const RegisterCallback& callback) { + const UUID& uuid, const RegisterCallback& callback) { VLOG(1) << __func__ << " - UUID: " << uuid.ToString(); lock_guard lock(pending_calls_lock_); @@ -190,8 +186,7 @@ bool LowEnergyScannerFactory::RegisterInstance( hal::BluetoothGattInterface::Get()->GetScannerHALInterface(); bt_uuid_t app_uuid = uuid.GetBlueDroid(); - if (hal_iface->register_scanner(&app_uuid) != BT_STATUS_SUCCESS) - return false; + if (hal_iface->register_scanner(&app_uuid) != BT_STATUS_SUCCESS) return false; pending_calls_[uuid] = callback; @@ -199,8 +194,7 @@ bool LowEnergyScannerFactory::RegisterInstance( } void LowEnergyScannerFactory::RegisterScannerCallback( - hal::BluetoothGattInterface* gatt_iface, - int status, int scanner_id, + hal::BluetoothGattInterface* gatt_iface, int status, int scanner_id, const bt_uuid_t& app_uuid) { UUID uuid(app_uuid); @@ -230,5 +224,4 @@ void LowEnergyScannerFactory::RegisterScannerCallback( pending_calls_.erase(iter); } - } // namespace bluetooth diff --git a/service/low_energy_scanner.h b/service/low_energy_scanner.h index cae1f58e7..3d5cf131f 100644 --- a/service/low_energy_scanner.h +++ b/service/low_energy_scanner.h @@ -84,10 +84,9 @@ class LowEnergyScanner : private hal::BluetoothGattInterface::ScannerObserver, const UUID& GetAppIdentifier() const override; int GetInstanceId() const override; - void ScanResultCallback( - hal::BluetoothGattInterface* gatt_iface, - const bt_bdaddr_t& bda, int rssi, - vector adv_data) override; + void ScanResultCallback(hal::BluetoothGattInterface* gatt_iface, + const bt_bdaddr_t& bda, int rssi, + vector adv_data) override; private: friend class LowEnergyScannerFactory; @@ -138,14 +137,16 @@ class LowEnergyScannerFactory ~LowEnergyScannerFactory() override; // BluetoothInstanceFactory override: - bool RegisterInstance(const UUID& app_uuid, const RegisterCallback& callback) override; + bool RegisterInstance(const UUID& app_uuid, + const RegisterCallback& callback) override; private: friend class LowEnergyScanner; // BluetoothGattInterface::ScannerObserver overrides: - void RegisterScannerCallback(hal::BluetoothGattInterface* gatt_iface, int status, - int scanner_id, const bt_uuid_t& app_uuid); + void RegisterScannerCallback(hal::BluetoothGattInterface* gatt_iface, + int status, int scanner_id, + const bt_uuid_t& app_uuid); // Map of pending calls to register. std::mutex pending_calls_lock_; diff --git a/service/main.cc b/service/main.cc index fc5eec66c..cc5c9efb0 100644 --- a/service/main.cc +++ b/service/main.cc @@ -35,7 +35,7 @@ const char kDisableProperty[] = "persist.bluetooth.disable"; } // namespace -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { base::AtExitManager exit_manager; base::CommandLine::Init(argc, argv); diff --git a/service/settings.cc b/service/settings.cc index dee0e69cb..d4728d7b4 100644 --- a/service/settings.cc +++ b/service/settings.cc @@ -24,12 +24,9 @@ namespace bluetooth { -Settings::Settings() - : initialized_(false) { -} +Settings::Settings() : initialized_(false) {} -Settings::~Settings() { -} +Settings::~Settings() {} bool Settings::Init() { CHECK(!initialized_); @@ -67,8 +64,7 @@ bool Settings::Init() { } // Two IPC methods/paths were provided. - if (!android_ipc_socket_suffix_.empty() && - !create_ipc_socket_path_.empty()) { + if (!android_ipc_socket_suffix_.empty() && !create_ipc_socket_path_.empty()) { LOG(ERROR) << "Too many IPC methods provided"; return false; } diff --git a/service/settings.h b/service/settings.h index 4c4ea4fb7..d68bda173 100644 --- a/service/settings.h +++ b/service/settings.h @@ -57,7 +57,7 @@ class Settings { // Binder IPC must be used. inline bool UseSocketIPC() const { return !android_ipc_socket_suffix().empty() || - !create_ipc_socket_path().empty(); + !create_ipc_socket_path().empty(); } private: diff --git a/service/test/adapter_unittest.cc b/service/test/adapter_unittest.cc index ca646185e..f7ee10985 100644 --- a/service/test/adapter_unittest.cc +++ b/service/test/adapter_unittest.cc @@ -37,7 +37,8 @@ class AdapterTest : public ::testing::Test { // Initialize GATT interface with default handlers. hal::BluetoothGattInterface::InitializeForTesting( - new hal::FakeBluetoothGattInterface(nullptr, nullptr, nullptr, nullptr)); + new hal::FakeBluetoothGattInterface(nullptr, nullptr, nullptr, + nullptr)); adapter_ = Adapter::Create(); } @@ -68,9 +69,7 @@ class TestObserver final : public bluetooth::Adapter::Observer { adapter_->AddObserver(this); } - ~TestObserver() override { - adapter_->RemoveObserver(this); - } + ~TestObserver() override { adapter_->RemoveObserver(this); } bluetooth::AdapterState prev_state() const { return prev_state_; } bluetooth::AdapterState cur_state() const { return cur_state_; } @@ -92,10 +91,9 @@ class TestObserver final : public bluetooth::Adapter::Observer { cur_state_ = new_state; } - void OnDeviceConnectionStateChanged( - Adapter* adapter, - const std::string& device_address, - bool connected) override { + void OnDeviceConnectionStateChanged(Adapter* adapter, + const std::string& device_address, + bool connected) override { ASSERT_EQ(adapter_, adapter); last_connection_state_address_ = device_address; last_device_connected_state_ = connected; @@ -229,9 +227,7 @@ TEST_F(AdapterTest, SetName) { TEST_F(AdapterTest, GetAddress) { EXPECT_EQ(bluetooth::Adapter::kDefaultAddress, adapter_->GetAddress()); - const bt_bdaddr_t kTestAdapterInput = { - { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc } - }; + const bt_bdaddr_t kTestAdapterInput = {{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}}; const char kTestAdapterAddressOutput[] = "12:34:56:78:9A:BC"; fake_hal_iface_->NotifyAdapterAddressPropertyChanged(&kTestAdapterInput); @@ -263,22 +259,22 @@ TEST_F(AdapterTest, IsDeviceConnected) { ASSERT_TRUE(util::BdAddrFromString(kDeviceAddr, &hal_addr)); // status != BT_STATUS_SUCCESS should be ignored - fake_hal_iface_->NotifyAclStateChangedCallback( - BT_STATUS_FAIL, hal_addr, BT_ACL_STATE_CONNECTED); + fake_hal_iface_->NotifyAclStateChangedCallback(BT_STATUS_FAIL, hal_addr, + BT_ACL_STATE_CONNECTED); EXPECT_FALSE(adapter_->IsDeviceConnected(kDeviceAddr)); EXPECT_TRUE(observer.last_connection_state_address().empty()); EXPECT_FALSE(observer.last_device_connected_state()); // Connected - fake_hal_iface_->NotifyAclStateChangedCallback( - BT_STATUS_SUCCESS, hal_addr, BT_ACL_STATE_CONNECTED); + fake_hal_iface_->NotifyAclStateChangedCallback(BT_STATUS_SUCCESS, hal_addr, + BT_ACL_STATE_CONNECTED); EXPECT_TRUE(adapter_->IsDeviceConnected(kDeviceAddr)); EXPECT_EQ(kDeviceAddr, observer.last_connection_state_address()); EXPECT_TRUE(observer.last_device_connected_state()); // Disconnected - fake_hal_iface_->NotifyAclStateChangedCallback( - BT_STATUS_SUCCESS, hal_addr, BT_ACL_STATE_DISCONNECTED); + fake_hal_iface_->NotifyAclStateChangedCallback(BT_STATUS_SUCCESS, hal_addr, + BT_ACL_STATE_DISCONNECTED); EXPECT_FALSE(adapter_->IsDeviceConnected(kDeviceAddr)); EXPECT_EQ(kDeviceAddr, observer.last_connection_state_address()); EXPECT_FALSE(observer.last_device_connected_state()); diff --git a/service/test/advertise_data_unittest.cc b/service/test/advertise_data_unittest.cc index c052608ef..bd0787e86 100644 --- a/service/test/advertise_data_unittest.cc +++ b/service/test/advertise_data_unittest.cc @@ -28,85 +28,77 @@ TEST(AdvertiseDataTest, EmptyData) { EXPECT_TRUE(adv0.IsValid()); // Single empty field not allowed. - const std::vector data1{ 0x00 }; + const std::vector data1{0x00}; AdvertiseData adv1(data1); EXPECT_FALSE(adv1.IsValid()); } TEST(AdvertiseDataTest, BadTLV) { // Single field, field empty. - const std::vector data0{ 0x01 }; + const std::vector data0{0x01}; AdvertiseData adv0(data0); EXPECT_FALSE(adv0.IsValid()); // Single field, first field length too long. - const std::vector data1{ 0x05, 0x02, 0x00, 0x00, 0x00 }; + const std::vector data1{0x05, 0x02, 0x00, 0x00, 0x00}; AdvertiseData adv1(data1); EXPECT_FALSE(adv1.IsValid()); // Two fields, second field length too long. - const std::vector data2{ 0x02, 0x02, 0x00, 0x02, 0x00 }; + const std::vector data2{0x02, 0x02, 0x00, 0x02, 0x00}; AdvertiseData adv2(data2); EXPECT_FALSE(adv2.IsValid()); // Two fields, second field empty. - const std::vector data3{ 0x02, 0x02, 0x00, 0x01 }; + const std::vector data3{0x02, 0x02, 0x00, 0x01}; AdvertiseData adv3(data3); EXPECT_FALSE(adv3.IsValid()); } TEST(AdvertiseDataTest, GoodTLV) { // Singe field. - const std::vector data0{ 0x03, 0x02, 0x01, 0x02 }; + const std::vector data0{0x03, 0x02, 0x01, 0x02}; AdvertiseData adv0(data0); EXPECT_TRUE(adv0.IsValid()); // Twi fields. - const std::vector data1{ 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01 }; + const std::vector data1{0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01}; AdvertiseData adv1(data1); EXPECT_TRUE(adv0.IsValid()); } TEST(AdvertiseDataTest, DisallowedFields) { // Singe field. - const std::vector data0{ 0x02, HCI_EIR_FLAGS_TYPE, 0x00 }; + const std::vector data0{0x02, HCI_EIR_FLAGS_TYPE, 0x00}; AdvertiseData adv0(data0); EXPECT_FALSE(adv0.IsValid()); // Two fields, first invalid. const std::vector data1{ - 0x02, HCI_EIR_FLAGS_TYPE, 0x00, - 0x03, 0x02, 0x01, 0x02 - }; + 0x02, HCI_EIR_FLAGS_TYPE, 0x00, 0x03, 0x02, 0x01, 0x02}; AdvertiseData adv1(data1); EXPECT_FALSE(adv1.IsValid()); // Two fields, second invalid. const std::vector data2{ - 0x03, 0x02, 0x01, 0x02, - 0x02, HCI_EIR_FLAGS_TYPE, 0x00 - }; + 0x03, 0x02, 0x01, 0x02, 0x02, HCI_EIR_FLAGS_TYPE, 0x00}; AdvertiseData adv2(data2); EXPECT_FALSE(adv2.IsValid()); // Check all blacklisted fields - uint8_t blacklist[] = { - HCI_EIR_FLAGS_TYPE, - HCI_EIR_OOB_BD_ADDR_TYPE, - HCI_EIR_OOB_COD_TYPE, - HCI_EIR_OOB_SSP_HASH_C_TYPE, - HCI_EIR_OOB_SSP_RAND_R_TYPE - }; + uint8_t blacklist[] = {HCI_EIR_FLAGS_TYPE, HCI_EIR_OOB_BD_ADDR_TYPE, + HCI_EIR_OOB_COD_TYPE, HCI_EIR_OOB_SSP_HASH_C_TYPE, + HCI_EIR_OOB_SSP_RAND_R_TYPE}; for (size_t i = 0; i < sizeof(blacklist); i++) { - const std::vector data{ 0x02, blacklist[i], 0x00 }; + const std::vector data{0x02, blacklist[i], 0x00}; AdvertiseData adv(data); EXPECT_FALSE(adv.IsValid()); } } TEST(AdvertiseDataTest, EqualsData) { - const std::vector data0{ 0x02, 0x02, 0x00 }; - const std::vector data1{ 0x02, 0x03, 0x00 }; + const std::vector data0{0x02, 0x02, 0x00}; + const std::vector data1{0x02, 0x03, 0x00}; AdvertiseData adv0(data0); AdvertiseData adv1(data1); diff --git a/service/test/fake_hal_util.cc b/service/test/fake_hal_util.cc index 46acf73fe..0fdc19ba5 100644 --- a/service/test/fake_hal_util.cc +++ b/service/test/fake_hal_util.cc @@ -22,6 +22,4 @@ // tests. Instead of doing it this way, however, we should instead provide a C++ // class abstraction for this (and all other btif interfaces) that we can mock // for testing. -int hal_util_load_bt_library(const struct hw_module_t** module) { - return -1; -} +int hal_util_load_bt_library(const struct hw_module_t** module) { return -1; } diff --git a/service/test/gatt_client_unittest.cc b/service/test/gatt_client_unittest.cc index 1628a7b64..7527e8beb 100644 --- a/service/test/gatt_client_unittest.cc +++ b/service/test/gatt_client_unittest.cc @@ -36,8 +36,8 @@ class MockGattHandler MOCK_METHOD1(RegisterClient, bt_status_t(bt_uuid_t*)); MOCK_METHOD1(UnregisterClient, bt_status_t(int)); MOCK_METHOD1(Scan, bt_status_t(bool)); - MOCK_METHOD4(Connect, bt_status_t(int , const bt_bdaddr_t *, bool, int)); - MOCK_METHOD3(Disconnect, bt_status_t(int , const bt_bdaddr_t *, int)); + MOCK_METHOD4(Connect, bt_status_t(int, const bt_bdaddr_t*, bool, int)); + MOCK_METHOD3(Disconnect, bt_status_t(int, const bt_bdaddr_t*, int)); private: DISALLOW_COPY_AND_ASSIGN(MockGattHandler); @@ -50,12 +50,10 @@ class GattClientTest : public ::testing::Test { void SetUp() override { // Only set |mock_handler_| if a previous test case hasn't set it. - if (!mock_handler_) - mock_handler_.reset(new MockGattHandler()); + if (!mock_handler_) mock_handler_.reset(new MockGattHandler()); fake_hal_gatt_iface_ = new hal::FakeBluetoothGattInterface( - nullptr, - nullptr, + nullptr, nullptr, std::static_pointer_cast< hal::FakeBluetoothGattInterface::TestClientHandler>(mock_handler_), nullptr); @@ -93,12 +91,12 @@ TEST_F(GattClientTest, RegisterInstance) { auto callback = [&](BLEStatus in_status, const UUID& uuid, std::unique_ptr in_client) { - status = in_status; - cb_uuid = uuid; - client = std::unique_ptr( - static_cast(in_client.release())); - callback_count++; - }; + status = in_status; + cb_uuid = uuid; + client = std::unique_ptr( + static_cast(in_client.release())); + callback_count++; + }; UUID uuid0 = UUID::GetRandom(); @@ -132,8 +130,8 @@ TEST_F(GattClientTest, RegisterInstance) { // |uuid0| succeeds. int client_id0 = 2; // Pick something that's not 0. hal_uuid = uuid0.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterClientCallback( - BT_STATUS_SUCCESS, client_id0, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterClientCallback(BT_STATUS_SUCCESS, + client_id0, hal_uuid); EXPECT_EQ(1, callback_count); ASSERT_TRUE(client.get() != nullptr); // Assert to terminate in case of error @@ -152,8 +150,8 @@ TEST_F(GattClientTest, RegisterInstance) { // |uuid1| fails. int client_id1 = 3; hal_uuid = uuid1.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterClientCallback( - BT_STATUS_FAIL, client_id1, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterClientCallback(BT_STATUS_FAIL, client_id1, + hal_uuid); EXPECT_EQ(2, callback_count); ASSERT_TRUE(client.get() == nullptr); // Assert to terminate in case of error diff --git a/service/test/gatt_server_unittest.cc b/service/test/gatt_server_unittest.cc index ca4c2fe15..3a3fbaf45 100644 --- a/service/test/gatt_server_unittest.cc +++ b/service/test/gatt_server_unittest.cc @@ -40,7 +40,8 @@ class MockGattHandler MOCK_METHOD4(AddDescriptor, bt_status_t(int, int, bt_uuid_t*, int)); MOCK_METHOD3(StartService, bt_status_t(int, int, int)); MOCK_METHOD2(DeleteService, bt_status_t(int, int)); - MOCK_METHOD5(SendIndication, bt_status_t(int, int, int, int, vector)); + MOCK_METHOD5(SendIndication, + bt_status_t(int, int, int, int, vector)); MOCK_METHOD4(SendResponse, bt_status_t(int, int, int, btgatt_response_t*)); private: @@ -53,9 +54,15 @@ class TestDelegate : public GattServer::Delegate { ~TestDelegate() override = default; struct RequestData { - RequestData() : id(-1), offset(-1), is_long(false), is_prep(false), - need_rsp(false), is_exec(false), count(0), - connected(false) {} + RequestData() + : id(-1), + offset(-1), + is_long(false), + is_prep(false), + need_rsp(false), + is_exec(false), + count(0), + connected(false) {} ~RequestData() = default; std::string device_address; @@ -71,10 +78,10 @@ class TestDelegate : public GattServer::Delegate { bool connected; }; - void OnCharacteristicReadRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) override { + void OnCharacteristicReadRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, bool is_long, + uint16_t handle) override { ASSERT_TRUE(gatt_server); char_read_req_.device_address = device_address; char_read_req_.id = request_id; @@ -84,10 +91,10 @@ class TestDelegate : public GattServer::Delegate { char_read_req_.count++; } - void OnDescriptorReadRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_long, uint16_t handle) override { + void OnDescriptorReadRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, bool is_long, + uint16_t handle) override { ASSERT_TRUE(gatt_server); desc_read_req_.device_address = device_address; desc_read_req_.id = request_id; @@ -97,11 +104,12 @@ class TestDelegate : public GattServer::Delegate { desc_read_req_.count++; } - void OnCharacteristicWriteRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_prepare_write, bool need_response, - const std::vector& value, uint16_t handle) override { + void OnCharacteristicWriteRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + uint16_t handle) override { ASSERT_TRUE(gatt_server); char_write_req_.device_address = device_address; char_write_req_.id = request_id; @@ -113,11 +121,12 @@ class TestDelegate : public GattServer::Delegate { char_write_req_.write_value = value; } - void OnDescriptorWriteRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, int offset, bool is_prepare_write, bool need_response, - const std::vector& value, uint16_t handle) override { + void OnDescriptorWriteRequest(GattServer* gatt_server, + const std::string& device_address, + int request_id, int offset, + bool is_prepare_write, bool need_response, + const std::vector& value, + uint16_t handle) override { ASSERT_TRUE(gatt_server); desc_write_req_.device_address = device_address; desc_write_req_.id = request_id; @@ -129,10 +138,9 @@ class TestDelegate : public GattServer::Delegate { desc_write_req_.write_value = value; } - void OnExecuteWriteRequest( - GattServer* gatt_server, - const std::string& device_address, - int request_id, bool is_execute) override { + void OnExecuteWriteRequest(GattServer* gatt_server, + const std::string& device_address, int request_id, + bool is_execute) override { ASSERT_TRUE(gatt_server); exec_req_.device_address = device_address; exec_req_.id = request_id; @@ -140,10 +148,9 @@ class TestDelegate : public GattServer::Delegate { exec_req_.count++; } - void OnConnectionStateChanged( - GattServer* gatt_server, - const std::string& device_address, - bool connected) override { + void OnConnectionStateChanged(GattServer* gatt_server, + const std::string& device_address, + bool connected) override { ASSERT_TRUE(gatt_server); conn_state_changed_.device_address = device_address; conn_state_changed_.connected = connected; @@ -173,9 +180,7 @@ class GattServerTest : public ::testing::Test { void SetUp() override { mock_handler_.reset(new MockGattHandler()); fake_hal_gatt_iface_ = new hal::FakeBluetoothGattInterface( - nullptr, - nullptr, - nullptr, + nullptr, nullptr, nullptr, std::static_pointer_cast< hal::FakeBluetoothGattInterface::TestServerHandler>(mock_handler_)); @@ -225,9 +230,7 @@ class GattServerPostRegisterTest : public GattServerTest { bt_uuid_t hal_uuid = uuid.GetBlueDroid(); fake_hal_gatt_iface_->NotifyRegisterServerCallback( - BT_STATUS_SUCCESS, - kDefaultServerId, - hal_uuid); + BT_STATUS_SUCCESS, kDefaultServerId, hal_uuid); } void TearDown() override { @@ -249,24 +252,30 @@ class GattServerPostRegisterTest : public GattServerTest { bool register_success = false; - Service service(0, true, uuid0, {}, {} ); + Service service(0, true, uuid0, {}, {}); - ASSERT_TRUE(gatt_server_->AddService(service, [&]( - BLEStatus status, const Service& added_service) { - ASSERT_EQ(BLE_STATUS_SUCCESS, status); - ASSERT_TRUE(UUID(added_service.uuid()) == UUID(service.uuid())); - ASSERT_TRUE(added_service.handle() == 0x0001); - register_success = true; - })); + ASSERT_TRUE(gatt_server_->AddService( + service, [&](BLEStatus status, const Service& added_service) { + ASSERT_EQ(BLE_STATUS_SUCCESS, status); + ASSERT_TRUE(UUID(added_service.uuid()) == UUID(service.uuid())); + ASSERT_TRUE(added_service.handle() == 0x0001); + register_success = true; + })); srvc_handle_ = 0x0001; char_handle_ = 0x0002; desc_handle_ = 0x0004; vector service_with_handles = { - {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = uuid0.GetBlueDroid(), .attribute_handle = srvc_handle_}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid = uuid1.GetBlueDroid(), .attribute_handle = char_handle_}, - {.type = BTGATT_DB_DESCRIPTOR, .uuid = uuid2.GetBlueDroid(), .attribute_handle = desc_handle_}, + {.type = BTGATT_DB_PRIMARY_SERVICE, + .uuid = uuid0.GetBlueDroid(), + .attribute_handle = srvc_handle_}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = uuid1.GetBlueDroid(), + .attribute_handle = char_handle_}, + {.type = BTGATT_DB_DESCRIPTOR, + .uuid = uuid2.GetBlueDroid(), + .attribute_handle = desc_handle_}, }; fake_hal_gatt_iface_->NotifyServiceAddedCallback( @@ -342,8 +351,8 @@ TEST_F(GattServerTest, RegisterServer) { // |uuid0| succeeds. int server_if0 = 2; // Pick something that's not 0. hal_uuid = uuid0.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterServerCallback( - BT_STATUS_SUCCESS, server_if0, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterServerCallback(BT_STATUS_SUCCESS, + server_if0, hal_uuid); EXPECT_EQ(1, callback_count); ASSERT_TRUE(server.get() != nullptr); // Assert to terminate in case of error @@ -363,8 +372,8 @@ TEST_F(GattServerTest, RegisterServer) { // |uuid1| fails. int server_if1 = 3; hal_uuid = uuid1.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterServerCallback( - BT_STATUS_FAIL, server_if1, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterServerCallback(BT_STATUS_FAIL, server_if1, + hal_uuid); EXPECT_EQ(2, callback_count); ASSERT_TRUE(server.get() == nullptr); // Assert to terminate in case of error @@ -378,7 +387,7 @@ TEST_F(GattServerPostRegisterTest, RequestRead) { TestDelegate test_delegate; gatt_server_->SetDelegate(&test_delegate); - const std::vector kTestValue = { 0x01, 0x02, 0x03 }; + const std::vector kTestValue = {0x01, 0x02, 0x03}; const std::vector kTestValueTooLarge(BTGATT_MAX_ATTR_LEN + 1, 0); const std::string kTestAddress0 = "01:23:45:67:89:AB"; const std::string kTestAddress1 = "CD:EF:01:23:45:67"; @@ -387,9 +396,8 @@ TEST_F(GattServerPostRegisterTest, RequestRead) { const int kConnId0 = 1; // No pending request. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); bt_bdaddr_t hal_addr0, hal_addr1; ASSERT_TRUE(util::BdAddrFromString(kTestAddress0, &hal_addr0)); @@ -443,50 +451,43 @@ TEST_F(GattServerPostRegisterTest, RequestRead) { EXPECT_EQ(1, test_delegate.desc_read_req().count); // Send response for wrong device address. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress1, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress1, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); // Send response for a value that's too large. EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValueTooLarge)); + kTestAddress0, kReqId0, GATT_ERROR_NONE, 0, kTestValueTooLarge)); - EXPECT_CALL(*mock_handler_, SendResponse(kConnId0, kReqId0, - BT_STATUS_SUCCESS, _)) + EXPECT_CALL(*mock_handler_, + SendResponse(kConnId0, kReqId0, BT_STATUS_SUCCESS, _)) .Times(2) .WillOnce(Return(BT_STATUS_FAIL)) .WillOnce(Return(BT_STATUS_SUCCESS)); // Stack call fails. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); // Successful send response for characteristic. - EXPECT_TRUE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_TRUE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); // Characteristic request ID no longer pending. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); - EXPECT_CALL(*mock_handler_, SendResponse(kConnId0, kReqId1, - BT_STATUS_SUCCESS, _)) + EXPECT_CALL(*mock_handler_, + SendResponse(kConnId0, kReqId1, BT_STATUS_SUCCESS, _)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); // Successful send response for descriptor. - EXPECT_TRUE(gatt_server_->SendResponse( - kTestAddress0, kReqId1, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_TRUE(gatt_server_->SendResponse(kTestAddress0, kReqId1, + GATT_ERROR_NONE, 0, kTestValue)); // Descriptor request ID no longer pending. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId1, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId1, + GATT_ERROR_NONE, 0, kTestValue)); gatt_server_->SetDelegate(nullptr); } @@ -497,7 +498,7 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) { TestDelegate test_delegate; gatt_server_->SetDelegate(&test_delegate); - const std::vector kTestValue = { 0x01, 0x02, 0x03 }; + const std::vector kTestValue = {0x01, 0x02, 0x03}; const std::string kTestAddress0 = "01:23:45:67:89:AB"; const std::string kTestAddress1 = "CD:EF:01:23:45:67"; const int kReqId0 = 0; @@ -505,9 +506,8 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) { const int kConnId0 = 1; // No pending request. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); bt_bdaddr_t hal_addr0, hal_addr1; ASSERT_TRUE(util::BdAddrFromString(kTestAddress0, &hal_addr0)); @@ -521,22 +521,20 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) { // Unknown connection ID shouldn't trigger anything. fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0 + 1, kReqId0, hal_addr0, char_handle_, 0, - true, false, kTestValue); + kConnId0 + 1, kReqId0, hal_addr0, char_handle_, 0, true, false, + kTestValue); EXPECT_EQ(0, test_delegate.char_write_req().count); EXPECT_EQ(0, test_delegate.desc_write_req().count); // Unknown device address shouldn't trigger anything. fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0, kReqId0, hal_addr1, char_handle_, 0, - true, false, kTestValue); + kConnId0, kReqId0, hal_addr1, char_handle_, 0, true, false, kTestValue); EXPECT_EQ(0, test_delegate.char_write_req().count); EXPECT_EQ(0, test_delegate.desc_write_req().count); // Characteristic and descriptor handles should trigger correct callbacks. fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0, kReqId0, hal_addr0, char_handle_, 0, - true, false, kTestValue); + kConnId0, kReqId0, hal_addr0, char_handle_, 0, true, false, kTestValue); EXPECT_EQ(1, test_delegate.char_write_req().count); EXPECT_EQ(kTestAddress0, test_delegate.char_write_req().device_address); EXPECT_EQ(kReqId0, test_delegate.char_write_req().id); @@ -548,8 +546,7 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) { EXPECT_EQ(0, test_delegate.desc_write_req().count); fake_hal_gatt_iface_->NotifyRequestWriteDescriptorCallback( - kConnId0, kReqId1, hal_addr0, desc_handle_, 2, - true, false, kTestValue); + kConnId0, kReqId1, hal_addr0, desc_handle_, 2, true, false, kTestValue); EXPECT_EQ(1, test_delegate.char_write_req().count); EXPECT_EQ(1, test_delegate.desc_write_req().count); EXPECT_EQ(kTestAddress0, test_delegate.desc_write_req().device_address); @@ -562,63 +559,53 @@ TEST_F(GattServerPostRegisterTest, RequestWrite) { // Callback with a pending request ID will be ignored. fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0, kReqId0, hal_addr0, char_handle_, 0, - true, false, kTestValue); + kConnId0, kReqId0, hal_addr0, char_handle_, 0, true, false, kTestValue); fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0, kReqId1, hal_addr0, char_handle_, 0, - true, false, kTestValue); + kConnId0, kReqId1, hal_addr0, char_handle_, 0, true, false, kTestValue); EXPECT_EQ(1, test_delegate.char_write_req().count); EXPECT_EQ(1, test_delegate.desc_write_req().count); // Send response for wrong device address. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress1, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress1, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); - EXPECT_CALL(*mock_handler_, SendResponse(kConnId0, kReqId0, - BT_STATUS_SUCCESS, _)) + EXPECT_CALL(*mock_handler_, + SendResponse(kConnId0, kReqId0, BT_STATUS_SUCCESS, _)) .Times(2) .WillOnce(Return(BT_STATUS_FAIL)) .WillOnce(Return(BT_STATUS_SUCCESS)); // Stack call fails. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); // Successful send response for characteristic. - EXPECT_TRUE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_TRUE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); // Characteristic request ID no longer pending. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); - EXPECT_CALL(*mock_handler_, SendResponse(kConnId0, kReqId1, - BT_STATUS_SUCCESS, _)) + EXPECT_CALL(*mock_handler_, + SendResponse(kConnId0, kReqId1, BT_STATUS_SUCCESS, _)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); // Successful send response for descriptor. - EXPECT_TRUE(gatt_server_->SendResponse( - kTestAddress0, kReqId1, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_TRUE(gatt_server_->SendResponse(kTestAddress0, kReqId1, + GATT_ERROR_NONE, 0, kTestValue)); // Descriptor request ID no longer pending. - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId1, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId1, + GATT_ERROR_NONE, 0, kTestValue)); // SendResponse should fail for a "Write Without Response". fake_hal_gatt_iface_->NotifyRequestWriteCharacteristicCallback( - kConnId0, kReqId0, hal_addr0, char_handle_, 0, - false, false, kTestValue); + kConnId0, kReqId0, hal_addr0, char_handle_, 0, false, false, kTestValue); EXPECT_EQ(false, test_delegate.char_write_req().need_rsp); - EXPECT_FALSE(gatt_server_->SendResponse( - kTestAddress0, kReqId0, - GATT_ERROR_NONE, 0, kTestValue)); + EXPECT_FALSE(gatt_server_->SendResponse(kTestAddress0, kReqId0, + GATT_ERROR_NONE, 0, kTestValue)); gatt_server_->SetDelegate(nullptr); } @@ -650,104 +637,91 @@ TEST_F(GattServerPostRegisterTest, SendNotification) { }; // Bad device address. - EXPECT_FALSE(gatt_server_->SendNotification( - kInvalidAddress, - char_handle_, false, value, callback)); + EXPECT_FALSE(gatt_server_->SendNotification(kInvalidAddress, char_handle_, + false, value, callback)); // Bad connection. - EXPECT_FALSE(gatt_server_->SendNotification( - kTestAddress1, - char_handle_, false, value, callback)); + EXPECT_FALSE(gatt_server_->SendNotification(kTestAddress1, char_handle_, + false, value, callback)); // We should get a HAL call for each connection for this address. The calls // fail. - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId0, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId0, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_FAIL)); - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId1, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId1, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_FAIL)); - EXPECT_FALSE(gatt_server_->SendNotification( - kTestAddress0, - char_handle_, false, value, callback)); + EXPECT_FALSE(gatt_server_->SendNotification(kTestAddress0, char_handle_, + false, value, callback)); // One of the calls succeeds. - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId0, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId0, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId1, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId1, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_FAIL)); - EXPECT_TRUE(gatt_server_->SendNotification( - kTestAddress0, - char_handle_, false, value, callback)); + EXPECT_TRUE(gatt_server_->SendNotification(kTestAddress0, char_handle_, false, + value, callback)); // One of the connections is already pending so there should be only one call. // This one we send with confirm=true. - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId1, - 1, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId1, 1, value)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); - EXPECT_TRUE(gatt_server_->SendNotification( - kTestAddress0, - char_handle_, true, value, callback)); + EXPECT_TRUE(gatt_server_->SendNotification(kTestAddress0, char_handle_, true, + value, callback)); // Calls are already pending. - EXPECT_FALSE(gatt_server_->SendNotification( - kTestAddress0, char_handle_, true, value, callback)); + EXPECT_FALSE(gatt_server_->SendNotification(kTestAddress0, char_handle_, true, + value, callback)); // Trigger one confirmation callback. We should get calls for two callbacks // since we have two separate calls pending. - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId0, BT_STATUS_SUCCESS); - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId1, BT_STATUS_SUCCESS); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId0, + BT_STATUS_SUCCESS); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId1, + BT_STATUS_SUCCESS); EXPECT_EQ(2, callback_count); EXPECT_EQ(GATT_ERROR_NONE, gatt_error); callback_count = 0; // Restart. Both calls succeed now. - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId0, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId0, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); - EXPECT_CALL(*mock_handler_, - SendIndication(kDefaultServerId, char_handle_, kConnId1, - 0, value)) + EXPECT_CALL(*mock_handler_, SendIndication(kDefaultServerId, char_handle_, + kConnId1, 0, value)) .Times(1) .WillOnce(Return(BT_STATUS_SUCCESS)); - EXPECT_TRUE(gatt_server_->SendNotification( - kTestAddress0, - char_handle_, false, value, callback)); + EXPECT_TRUE(gatt_server_->SendNotification(kTestAddress0, char_handle_, false, + value, callback)); // Trigger one confirmation callback. The callback we passed should still be // pending. The first callback is for the wrong connection ID. - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId0 + 50, BT_STATUS_FAIL); - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId0, BT_STATUS_SUCCESS); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId0 + 50, + BT_STATUS_FAIL); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId0, + BT_STATUS_SUCCESS); EXPECT_EQ(0, callback_count); // This should be ignored since |kConnId0| was already processed. - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId0, BT_STATUS_SUCCESS); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId0, + BT_STATUS_SUCCESS); EXPECT_EQ(0, callback_count); // Run the callback with failure. Since the previous callback reported // success, we should report success. - fake_hal_gatt_iface_->NotifyIndicationSentCallback( - kConnId1, BT_STATUS_SUCCESS); + fake_hal_gatt_iface_->NotifyIndicationSentCallback(kConnId1, + BT_STATUS_SUCCESS); EXPECT_EQ(1, callback_count); EXPECT_EQ(GATT_ERROR_NONE, gatt_error); } diff --git a/service/test/ipc_linux_unittest.cc b/service/test/ipc_linux_unittest.cc index efd50aca4..39cc741e3 100644 --- a/service/test/ipc_linux_unittest.cc +++ b/service/test/ipc_linux_unittest.cc @@ -33,7 +33,6 @@ #include "service/settings.h" #include "service/test/mock_daemon.h" - namespace { using testing::Return; @@ -59,7 +58,8 @@ class IPCLinuxTest : public ::testing::Test { bluetooth::hal::BluetoothInterface::InitializeForTesting( new bluetooth::hal::FakeBluetoothInterface()); bluetooth::hal::BluetoothGattInterface::InitializeForTesting( - new bluetooth::hal::FakeBluetoothGattInterface(nullptr, nullptr, nullptr, nullptr)); + new bluetooth::hal::FakeBluetoothGattInterface(nullptr, nullptr, + nullptr, nullptr)); adapter_ = bluetooth::Adapter::Create(); ipc_manager_.reset(new ipc::IPCManager(adapter_.get())); @@ -79,7 +79,7 @@ class IPCLinuxTest : public ::testing::Test { std::string ipc_socket_arg = base::StringPrintf("--create-ipc-socket=%s", kTestSocketPath); const base::CommandLine::CharType* argv[] = { - "program", ipc_socket_arg.c_str(), + "program", ipc_socket_arg.c_str(), }; base::CommandLine::Init(arraysize(argv), argv); } @@ -93,8 +93,8 @@ class IPCLinuxTest : public ::testing::Test { address.sun_family = AF_UNIX; strncpy(address.sun_path, kTestSocketPath, sizeof(address.sun_path) - 1); - int status = connect(client_fd_.get(), (struct sockaddr *)&address, - sizeof(address)); + int status = + connect(client_fd_.get(), (struct sockaddr*)&address, sizeof(address)); EXPECT_EQ(0, status); } @@ -117,7 +117,7 @@ class IPCLinuxTestDisabled : public IPCLinuxTest { void SetUpCommandLine() override { // Set up with no --ipc-socket-path - const base::CommandLine::CharType* argv[] = { "program" }; + const base::CommandLine::CharType* argv[] = {"program"}; base::CommandLine::Init(arraysize(argv), argv); } @@ -128,8 +128,7 @@ class IPCLinuxTestDisabled : public IPCLinuxTest { class TestDelegate : public ipc::IPCManager::Delegate, public base::SupportsWeakPtr { public: - TestDelegate() : started_count_(0), stopped_count_(0) { - } + TestDelegate() : started_count_(0), stopped_count_(0) {} void OnIPCHandlerStarted(ipc::IPCManager::Type type) override { ASSERT_EQ(ipc::IPCManager::TYPE_LINUX, type); diff --git a/service/test/low_energy_advertiser_unittest.cc b/service/test/low_energy_advertiser_unittest.cc index 006a234cb..9175755da 100644 --- a/service/test/low_energy_advertiser_unittest.cc +++ b/service/test/low_energy_advertiser_unittest.cc @@ -56,9 +56,9 @@ class MockAdvertiserHandler : public BleAdvertiserInterface { vector data, Callback cb)); MOCK_METHOD5(Enable, void(uint8_t advertiser_id, bool enable, Callback cb, int timeout_s, Callback timeout_cb)); - MOCK_METHOD7(StartAdvertising, void(uint8_t advertiser_id, Callback cb, - AdvertiseParameters, std::vector, - std::vector, int, Callback)); + MOCK_METHOD7(StartAdvertising, + void(uint8_t advertiser_id, Callback cb, AdvertiseParameters, + std::vector, std::vector, int, Callback)); private: DISALLOW_COPY_AND_ASSIGN(MockAdvertiserHandler); @@ -118,7 +118,7 @@ class LowEnergyAdvertiserPostRegisterTest : public LowEnergyAdvertiserTest { callback) { UUID uuid = UUID::GetRandom(); auto api_callback = [&](BLEStatus status, const UUID& in_uuid, - std::unique_ptr in_client) { + std::unique_ptr in_client) { CHECK(in_uuid == uuid); CHECK(in_client.get()); CHECK(status == BLE_STATUS_SUCCESS); @@ -162,13 +162,15 @@ class LowEnergyAdvertiserPostRegisterTest : public LowEnergyAdvertiserTest { ASSERT_FALSE(le_advertiser_->IsStoppingAdvertising()); } - void AdvertiseDataTestHelper(AdvertiseData data, std::function callback, status_cb *set_data_cb) { + void AdvertiseDataTestHelper(AdvertiseData data, + std::function callback, + status_cb* set_data_cb) { AdvertiseSettings settings; LOG_ASSERT(set_data_cb) << "set_data_cb must be set"; - EXPECT_TRUE(le_advertiser_->StartAdvertising( - settings, data, AdvertiseData(), callback)); + EXPECT_TRUE(le_advertiser_->StartAdvertising(settings, data, + AdvertiseData(), callback)); set_data_cb->Run(BT_STATUS_SUCCESS); @@ -177,7 +179,8 @@ class LowEnergyAdvertiserPostRegisterTest : public LowEnergyAdvertiserTest { .Times(1) .WillOnce(SaveArg<2>(&disable_cb)); - EXPECT_TRUE(le_advertiser_->StopAdvertising(LowEnergyAdvertiser::StatusCallback())); + EXPECT_TRUE( + le_advertiser_->StopAdvertising(LowEnergyAdvertiser::StatusCallback())); disable_cb.Run(BT_STATUS_SUCCESS); } @@ -200,12 +203,12 @@ TEST_F(LowEnergyAdvertiserTest, RegisterInstance) { auto callback = [&](BLEStatus in_status, const UUID& uuid, std::unique_ptr in_client) { - status = in_status; - cb_uuid = uuid; - advertiser = std::unique_ptr( - static_cast(in_client.release())); - callback_count++; - }; + status = in_status; + cb_uuid = uuid; + advertiser = std::unique_ptr( + static_cast(in_client.release())); + callback_count++; + }; UUID uuid0 = UUID::GetRandom(); @@ -237,17 +240,16 @@ TEST_F(LowEnergyAdvertiserTest, RegisterInstance) { reg_adv1_cb.Run(client_if0, BT_STATUS_SUCCESS); EXPECT_EQ(1, callback_count); - ASSERT_TRUE(advertiser.get() != nullptr); // Assert to terminate in case of error + ASSERT_TRUE(advertiser.get() != + nullptr); // Assert to terminate in case of error EXPECT_EQ(BLE_STATUS_SUCCESS, status); EXPECT_EQ(client_if0, advertiser->GetInstanceId()); EXPECT_EQ(uuid0, advertiser->GetAppIdentifier()); EXPECT_EQ(uuid0, cb_uuid); // The advertiser should unregister itself when deleted. - EXPECT_CALL(*mock_handler_, Enable(client_if0, false, _, _, _)) - .Times(1); - EXPECT_CALL(*mock_handler_, Unregister(client_if0)) - .Times(1); + EXPECT_CALL(*mock_handler_, Enable(client_if0, false, _, _, _)).Times(1); + EXPECT_CALL(*mock_handler_, Unregister(client_if0)).Times(1); advertiser.reset(); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); @@ -256,7 +258,8 @@ TEST_F(LowEnergyAdvertiserTest, RegisterInstance) { reg_adv2_cb.Run(client_if1, BT_STATUS_FAIL); EXPECT_EQ(2, callback_count); - ASSERT_TRUE(advertiser.get() == nullptr); // Assert to terminate in case of error + ASSERT_TRUE(advertiser.get() == + nullptr); // Assert to terminate in case of error EXPECT_EQ(BLE_STATUS_FAILURE, status); EXPECT_EQ(uuid1, cb_uuid); } @@ -282,8 +285,8 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StartAdvertisingBasic) { .WillRepeatedly(SaveArg<1>(&start_advertising_cb)); // Stack call returns success. - EXPECT_TRUE(le_advertiser_->StartAdvertising( - settings, adv_data, scan_rsp, callback)); + EXPECT_TRUE( + le_advertiser_->StartAdvertising(settings, adv_data, scan_rsp, callback)); EXPECT_FALSE(le_advertiser_->IsAdvertisingStarted()); EXPECT_TRUE(le_advertiser_->IsStartingAdvertising()); @@ -291,8 +294,8 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StartAdvertisingBasic) { EXPECT_EQ(0, callback_count); // Already starting. - EXPECT_FALSE(le_advertiser_->StartAdvertising( - settings, adv_data, scan_rsp, callback)); + EXPECT_FALSE( + le_advertiser_->StartAdvertising(settings, adv_data, scan_rsp, callback)); // Notify failure. start_advertising_cb.Run(BT_STATUS_FAIL); @@ -304,8 +307,8 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StartAdvertisingBasic) { EXPECT_EQ(BLE_STATUS_FAILURE, last_status); // Try again. - EXPECT_TRUE(le_advertiser_->StartAdvertising( - settings, adv_data, scan_rsp, callback)); + EXPECT_TRUE( + le_advertiser_->StartAdvertising(settings, adv_data, scan_rsp, callback)); EXPECT_FALSE(le_advertiser_->IsAdvertisingStarted()); EXPECT_TRUE(le_advertiser_->IsStartingAdvertising()); EXPECT_FALSE(le_advertiser_->IsStoppingAdvertising()); @@ -320,8 +323,8 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StartAdvertisingBasic) { EXPECT_EQ(BLE_STATUS_SUCCESS, last_status); // Already started. - EXPECT_FALSE(le_advertiser_->StartAdvertising( - settings, adv_data, scan_rsp, callback)); + EXPECT_FALSE( + le_advertiser_->StartAdvertising(settings, adv_data, scan_rsp, callback)); } TEST_F(LowEnergyAdvertiserPostRegisterTest, StopAdvertisingBasic) { @@ -329,7 +332,8 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StopAdvertisingBasic) { // Not enabled. EXPECT_FALSE(le_advertiser_->IsAdvertisingStarted()); - EXPECT_FALSE(le_advertiser_->StopAdvertising(LowEnergyAdvertiser::StatusCallback())); + EXPECT_FALSE( + le_advertiser_->StopAdvertising(LowEnergyAdvertiser::StatusCallback())); // Start advertising for testing. StartAdvertising(); @@ -388,10 +392,9 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, StopAdvertisingBasic) { } TEST_F(LowEnergyAdvertiserPostRegisterTest, InvalidAdvertiseData) { - const std::vector data0{ 0x02, HCI_EIR_FLAGS_TYPE, 0x00 }; - const std::vector data1{ - 0x04, HCI_EIR_MANUFACTURER_SPECIFIC_TYPE, 0x01, 0x02, 0x00 - }; + const std::vector data0{0x02, HCI_EIR_FLAGS_TYPE, 0x00}; + const std::vector data1{0x04, HCI_EIR_MANUFACTURER_SPECIFIC_TYPE, + 0x01, 0x02, 0x00}; AdvertiseData invalid_adv(data0); AdvertiseData valid_adv(data1); @@ -404,67 +407,98 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, InvalidAdvertiseData) { // Manufacturer data not correctly formatted according to spec. We let the // stack handle this case. - const std::vector data2{ 0x01, HCI_EIR_MANUFACTURER_SPECIFIC_TYPE }; + const std::vector data2{0x01, HCI_EIR_MANUFACTURER_SPECIFIC_TYPE}; AdvertiseData invalid_mfc(data2); - EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1); + EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)).Times(1); EXPECT_TRUE(le_advertiser_->StartAdvertising( settings, invalid_mfc, valid_adv, LowEnergyAdvertiser::StatusCallback())); } TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { const std::vector kUUID16BitData{ - 0x03, HCI_EIR_COMPLETE_16BITS_UUID_TYPE, 0xDE, 0xAD, + 0x03, HCI_EIR_COMPLETE_16BITS_UUID_TYPE, 0xDE, 0xAD, }; const std::vector kUUID32BitData{ - 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02 - }; + 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02}; const std::vector kUUID128BitData{ - 0x11, HCI_EIR_COMPLETE_128BITS_UUID_TYPE, - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E - }; + 0x11, HCI_EIR_COMPLETE_128BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0x03, 0x04, + 0x05, 0x06, + 0x07, 0x08, + 0x09, 0x0A, + 0x0B, 0x0C, + 0x0D, 0x0E}; const std::vector kMultiUUIDData{ - 0x11, HCI_EIR_COMPLETE_128BITS_UUID_TYPE, - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, - 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, 0xDE, 0xAD, 0xBE, 0xEF - }; + 0x11, HCI_EIR_COMPLETE_128BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0x03, 0x04, + 0x05, 0x06, + 0x07, 0x08, + 0x09, 0x0A, + 0x0B, 0x0C, + 0x0D, 0x0E, + 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, + 0xDE, 0xAD, + 0xBE, 0xEF}; const std::vector kServiceData16Bit{ - 0x05, HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE, 0xDE, 0xAD, 0xBE, 0xEF - }; + 0x05, HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE, 0xDE, 0xAD, 0xBE, 0xEF}; const std::vector kServiceData32Bit{ - 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02, 0xBE, 0xEF - }; + 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02, 0xBE, + 0xEF}; const std::vector kServiceData128Bit{ - 0x13, HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE, - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0xBE, 0xEF - }; + 0x13, HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0x03, 0x04, + 0x05, 0x06, + 0x07, 0x08, + 0x09, 0x0A, + 0x0B, 0x0C, + 0x0D, 0x0E, + 0xBE, 0xEF}; const std::vector kMultiServiceData{ - 0x13, HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE, - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xBE, 0xEF, - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x05, HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE, 0xDE, 0xAD, 0xBE, 0xEF - }; + 0x13, HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0x03, 0x04, + 0x05, 0x06, + 0xBE, 0xEF, + 0xDE, 0xAD, + 0x01, 0x02, + 0x03, 0x04, + 0x05, 0x06, + 0x05, HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE, + 0xDE, 0xAD, + 0xBE, 0xEF}; const std::vector kServiceUUIDMatch{ - 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02, - 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02, 0xBE, 0xEF - }; + 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0xBE, 0xEF}; const std::vector kServiceUUIDMismatch{ - 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x01, - 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, 0xDE, 0xAD, 0x01, 0x02, 0xBE, 0xEF - }; + 0x05, HCI_EIR_COMPLETE_32BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x01, + 0x07, HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE, + 0xDE, 0xAD, + 0x01, 0x02, + 0xBE, 0xEF}; AdvertiseData uuid_16bit_adv(kUUID16BitData); AdvertiseData uuid_32bit_adv(kUUID32BitData); @@ -491,7 +525,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { status_cb start_advertising_cb; // Multiple UUID test EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(multi_uuid_adv, callback, &start_advertising_cb); EXPECT_EQ(1, callback_count); @@ -499,7 +533,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // Multiple Service Data test EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(multi_service_adv, callback, &start_advertising_cb); EXPECT_EQ(2, callback_count); @@ -511,7 +545,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { 0xFB, 0x34, 0x9b, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xDE, 0xAD, 0x00, 0x00}; EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(uuid_16bit_adv, callback, &start_advertising_cb); EXPECT_EQ(3, callback_count); @@ -519,23 +553,21 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // 32bit uuid test, should succeed with correctly parsed uuid const std::vector uuid_32bit_canonical{ - 0xFB, 0x34, 0x9b, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, - 0xDE, 0xAD, 0x01, 0x02 - }; + 0xFB, 0x34, 0x9b, 0x5F, 0x80, 0x00, 0x00, 0x80, + 0x00, 0x10, 0x00, 0x00, 0xDE, 0xAD, 0x01, 0x02}; EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(uuid_32bit_adv, callback, &start_advertising_cb); EXPECT_EQ(4, callback_count); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); // 128bit uuid test, should succeed with correctly parsed uuid - const std::vector uuid_128bit{ - 0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E - }; + const std::vector uuid_128bit{0xDE, 0xAD, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E}; EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(uuid_128bit_adv, callback, &start_advertising_cb); EXPECT_EQ(5, callback_count); @@ -546,7 +578,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // Service data with 16bit uuid included, should succeed with // uuid and service data parsed out EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(service_16bit_adv, callback, &start_advertising_cb); EXPECT_EQ(6, callback_count); @@ -555,7 +587,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // Service data with 32bit uuid included, should succeed with // uuid and service data parsed out EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(service_32bit_adv, callback, &start_advertising_cb); EXPECT_EQ(7, callback_count); @@ -564,7 +596,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // Service data with 128bit uuid included, should succeed with // uuid and service data parsed out EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(service_128bit_adv, callback, &start_advertising_cb); EXPECT_EQ(8, callback_count); @@ -572,7 +604,7 @@ TEST_F(LowEnergyAdvertiserPostRegisterTest, AdvertiseDataParsing) { // Service data and UUID where the UUID for both match, should succeed. EXPECT_CALL(*mock_handler_, StartAdvertising(_, _, _, _, _, _, _)) - .Times(1) + .Times(1) .WillOnce(SaveArg<1>(&start_advertising_cb)); AdvertiseDataTestHelper(service_uuid_match, callback, &start_advertising_cb); EXPECT_EQ(9, callback_count); @@ -593,6 +625,5 @@ MATCHER_P(BitEq, x, std::string(negation ? "isn't" : "is") + return std::memcmp(&arg, &x, sizeof(x)) == 0; } - } // namespace } // namespace bluetooth diff --git a/service/test/low_energy_client_unittest.cc b/service/test/low_energy_client_unittest.cc index 1fc2393ff..99eb93436 100644 --- a/service/test/low_energy_client_unittest.cc +++ b/service/test/low_energy_client_unittest.cc @@ -37,13 +37,13 @@ namespace { class MockGattHandler : public hal::FakeBluetoothGattInterface::TestClientHandler { public: - MockGattHandler() {}; + MockGattHandler(){}; ~MockGattHandler() override = default; MOCK_METHOD1(RegisterClient, bt_status_t(bt_uuid_t*)); MOCK_METHOD1(UnregisterClient, bt_status_t(int)); - MOCK_METHOD4(Connect, bt_status_t(int , const bt_bdaddr_t *, bool, int)); - MOCK_METHOD3(Disconnect, bt_status_t(int , const bt_bdaddr_t *, int)); + MOCK_METHOD4(Connect, bt_status_t(int, const bt_bdaddr_t*, bool, int)); + MOCK_METHOD3(Disconnect, bt_status_t(int, const bt_bdaddr_t*, int)); private: DISALLOW_COPY_AND_ASSIGN(MockGattHandler); @@ -51,15 +51,14 @@ class MockGattHandler class TestDelegate : public LowEnergyClient::Delegate { public: - TestDelegate() : connection_state_count_(0), last_mtu_(0) { - } + TestDelegate() : connection_state_count_(0), last_mtu_(0) {} ~TestDelegate() override = default; int connection_state_count() const { return connection_state_count_; } void OnConnectionState(LowEnergyClient* client, int status, - const char* address, bool connected) { + const char* address, bool connected) { ASSERT_TRUE(client); connection_state_count_++; } @@ -85,11 +84,9 @@ class LowEnergyClientTest : public ::testing::Test { void SetUp() override { // Only set |mock_handler_| if a test hasn't set it. - if (!mock_handler_) - mock_handler_.reset(new MockGattHandler()); + if (!mock_handler_) mock_handler_.reset(new MockGattHandler()); fake_hal_gatt_iface_ = new hal::FakeBluetoothGattInterface( - nullptr, - nullptr, + nullptr, nullptr, std::static_pointer_cast< hal::FakeBluetoothGattInterface::TestClientHandler>(mock_handler_), nullptr); @@ -115,8 +112,7 @@ class LowEnergyClientTest : public ::testing::Test { // Used for tests that operate on a pre-registered client. class LowEnergyClientPostRegisterTest : public LowEnergyClientTest { public: - LowEnergyClientPostRegisterTest() : next_client_id_(0) { - } + LowEnergyClientPostRegisterTest() : next_client_id_(0) {} ~LowEnergyClientPostRegisterTest() override = default; void SetUp() override { @@ -140,7 +136,7 @@ class LowEnergyClientPostRegisterTest : public LowEnergyClientTest { callback) { UUID uuid = UUID::GetRandom(); auto api_callback = [&](BLEStatus status, const UUID& in_uuid, - std::unique_ptr in_client) { + std::unique_ptr in_client) { CHECK(in_uuid == uuid); CHECK(in_client.get()); CHECK(status == BLE_STATUS_SUCCESS); @@ -156,8 +152,8 @@ class LowEnergyClientPostRegisterTest : public LowEnergyClientTest { ble_factory_->RegisterInstance(uuid, api_callback); bt_uuid_t hal_uuid = uuid.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterClientCallback( - 0, next_client_id_++, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterClientCallback(0, next_client_id_++, + hal_uuid); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); } @@ -185,12 +181,12 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { auto callback = [&](BLEStatus in_status, const UUID& uuid, std::unique_ptr in_client) { - status = in_status; - cb_uuid = uuid; - client = std::unique_ptr( - static_cast(in_client.release())); - callback_count++; - }; + status = in_status; + cb_uuid = uuid; + client = std::unique_ptr( + static_cast(in_client.release())); + callback_count++; + }; UUID uuid0 = UUID::GetRandom(); @@ -224,8 +220,8 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { // |uuid0| succeeds. int client_if0 = 2; // Pick something that's not 0. hal_uuid = uuid0.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterClientCallback( - BT_STATUS_SUCCESS, client_if0, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterClientCallback(BT_STATUS_SUCCESS, + client_if0, hal_uuid); EXPECT_EQ(1, callback_count); ASSERT_TRUE(client.get() != nullptr); // Assert to terminate in case of error @@ -244,8 +240,8 @@ TEST_F(LowEnergyClientTest, RegisterInstance) { // |uuid1| fails. int client_if1 = 3; hal_uuid = uuid1.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterClientCallback( - BT_STATUS_FAIL, client_if1, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterClientCallback(BT_STATUS_FAIL, client_if1, + hal_uuid); EXPECT_EQ(2, callback_count); ASSERT_TRUE(client.get() == nullptr); // Assert to terminate in case of error @@ -260,9 +256,7 @@ MATCHER_P(BitEq, x, std::string(negation ? "isn't" : "is") + } TEST_F(LowEnergyClientPostRegisterTest, Connect) { - const bt_bdaddr_t kTestAddress = { - { 0x01, 0x02, 0x03, 0x0A, 0x0B, 0x0C } - }; + const bt_bdaddr_t kTestAddress = {{0x01, 0x02, 0x03, 0x0A, 0x0B, 0x0C}}; const char kTestAddressStr[] = "01:02:03:0A:0B:0C"; const bool kTestDirect = false; const int connId = 12; @@ -273,16 +267,16 @@ TEST_F(LowEnergyClientPostRegisterTest, Connect) { // TODO(jpawlowski): NotifyConnectCallback should be called after returning // success, fix it when it becomes important. // These should succeed and result in a HAL call - EXPECT_CALL(*mock_handler_, Connect(le_client_->GetInstanceId(), - Pointee(BitEq(kTestAddress)), kTestDirect, BT_TRANSPORT_LE)) + EXPECT_CALL(*mock_handler_, + Connect(le_client_->GetInstanceId(), Pointee(BitEq(kTestAddress)), + kTestDirect, BT_TRANSPORT_LE)) .Times(1) - .WillOnce(DoAll( - Invoke([&](int client_id, const bt_bdaddr_t *bd_addr, bool is_direct, - int transport){ - fake_hal_gatt_iface_->NotifyConnectCallback(connId, BT_STATUS_SUCCESS, - client_id, *bd_addr); - }), - Return(BT_STATUS_SUCCESS))); + .WillOnce(DoAll(Invoke([&](int client_id, const bt_bdaddr_t* bd_addr, + bool is_direct, int transport) { + fake_hal_gatt_iface_->NotifyConnectCallback( + connId, BT_STATUS_SUCCESS, client_id, *bd_addr); + }), + Return(BT_STATUS_SUCCESS))); EXPECT_TRUE(le_client_->Connect(kTestAddressStr, kTestDirect)); EXPECT_EQ(1, delegate.connection_state_count()); @@ -290,15 +284,14 @@ TEST_F(LowEnergyClientPostRegisterTest, Connect) { // TODO(jpawlowski): same as above // These should succeed and result in a HAL call EXPECT_CALL(*mock_handler_, Disconnect(le_client_->GetInstanceId(), - Pointee(BitEq(kTestAddress)), connId)) + Pointee(BitEq(kTestAddress)), connId)) .Times(1) .WillOnce(DoAll( - Invoke([&](int client_id, const bt_bdaddr_t *bd_addr, int connId){ - fake_hal_gatt_iface_->NotifyDisconnectCallback(connId, - BT_STATUS_SUCCESS, - client_id, *bd_addr); - }), - Return(BT_STATUS_SUCCESS))); + Invoke([&](int client_id, const bt_bdaddr_t* bd_addr, int connId) { + fake_hal_gatt_iface_->NotifyDisconnectCallback( + connId, BT_STATUS_SUCCESS, client_id, *bd_addr); + }), + Return(BT_STATUS_SUCCESS))); EXPECT_TRUE(le_client_->Disconnect(kTestAddressStr)); EXPECT_EQ(2, delegate.connection_state_count()); @@ -307,6 +300,5 @@ TEST_F(LowEnergyClientPostRegisterTest, Connect) { ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); } - } // namespace } // namespace bluetooth diff --git a/service/test/low_energy_scanner_unittest.cc b/service/test/low_energy_scanner_unittest.cc index f966a14b3..a56cf3f49 100644 --- a/service/test/low_energy_scanner_unittest.cc +++ b/service/test/low_energy_scanner_unittest.cc @@ -38,8 +38,7 @@ class MockGattHandler : public hal::FakeBluetoothGattInterface::TestScannerHandler { public: MockGattHandler() { - ON_CALL(*this, Scan(false)) - .WillByDefault(Return(BT_STATUS_SUCCESS)); + ON_CALL(*this, Scan(false)).WillByDefault(Return(BT_STATUS_SUCCESS)); } ~MockGattHandler() override = default; @@ -53,8 +52,7 @@ class MockGattHandler class TestDelegate : public LowEnergyScanner::Delegate { public: - TestDelegate() : scan_result_count_(0) { - } + TestDelegate() : scan_result_count_(0) {} ~TestDelegate() override = default; @@ -81,14 +79,12 @@ class LowEnergyScannerTest : public ::testing::Test { void SetUp() override { // Only set |mock_handler_| if a test hasn't set it. - if (!mock_handler_) - mock_handler_.reset(new MockGattHandler()); + if (!mock_handler_) mock_handler_.reset(new MockGattHandler()); fake_hal_gatt_iface_ = new hal::FakeBluetoothGattInterface( nullptr, std::static_pointer_cast< hal::FakeBluetoothGattInterface::TestScannerHandler>(mock_handler_), - nullptr, - nullptr); + nullptr, nullptr); hal::BluetoothGattInterface::InitializeForTesting(fake_hal_gatt_iface_); ble_factory_.reset(new LowEnergyScannerFactory(mock_adapter_)); } @@ -111,8 +107,7 @@ class LowEnergyScannerTest : public ::testing::Test { // Used for tests that operate on a pre-registered scanner. class LowEnergyScannerPostRegisterTest : public LowEnergyScannerTest { public: - LowEnergyScannerPostRegisterTest() : next_scanner_id_(0) { - } + LowEnergyScannerPostRegisterTest() : next_scanner_id_(0) {} ~LowEnergyScannerPostRegisterTest() override = default; void SetUp() override { @@ -136,7 +131,7 @@ class LowEnergyScannerPostRegisterTest : public LowEnergyScannerTest { callback) { UUID uuid = UUID::GetRandom(); auto api_callback = [&](BLEStatus status, const UUID& in_uuid, - std::unique_ptr in_scanner) { + std::unique_ptr in_scanner) { CHECK(in_uuid == uuid); CHECK(in_scanner.get()); CHECK(status == BLE_STATUS_SUCCESS); @@ -152,8 +147,8 @@ class LowEnergyScannerPostRegisterTest : public LowEnergyScannerTest { ble_factory_->RegisterInstance(uuid, api_callback); bt_uuid_t hal_uuid = uuid.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterScannerCallback( - 0, next_scanner_id_++, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterScannerCallback(0, next_scanner_id_++, + hal_uuid); ::testing::Mock::VerifyAndClearExpectations(mock_handler_.get()); } @@ -181,12 +176,12 @@ TEST_F(LowEnergyScannerTest, RegisterInstance) { auto callback = [&](BLEStatus in_status, const UUID& uuid, std::unique_ptr in_scanner) { - status = in_status; - cb_uuid = uuid; - scanner = std::unique_ptr( - static_cast(in_scanner.release())); - callback_count++; - }; + status = in_status; + cb_uuid = uuid; + scanner = std::unique_ptr( + static_cast(in_scanner.release())); + callback_count++; + }; UUID uuid0 = UUID::GetRandom(); @@ -220,11 +215,12 @@ TEST_F(LowEnergyScannerTest, RegisterInstance) { // |uuid0| succeeds. int scanner_if0 = 2; // Pick something that's not 0. hal_uuid = uuid0.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterScannerCallback( - BT_STATUS_SUCCESS, scanner_if0, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterScannerCallback(BT_STATUS_SUCCESS, + scanner_if0, hal_uuid); EXPECT_EQ(1, callback_count); - ASSERT_TRUE(scanner.get() != nullptr); // Assert to terminate in case of error + ASSERT_TRUE(scanner.get() != + nullptr); // Assert to terminate in case of error EXPECT_EQ(BLE_STATUS_SUCCESS, status); EXPECT_EQ(scanner_if0, scanner->GetInstanceId()); EXPECT_EQ(uuid0, scanner->GetAppIdentifier()); @@ -240,11 +236,12 @@ TEST_F(LowEnergyScannerTest, RegisterInstance) { // |uuid1| fails. int scanner_if1 = 3; hal_uuid = uuid1.GetBlueDroid(); - fake_hal_gatt_iface_->NotifyRegisterScannerCallback( - BT_STATUS_FAIL, scanner_if1, hal_uuid); + fake_hal_gatt_iface_->NotifyRegisterScannerCallback(BT_STATUS_FAIL, + scanner_if1, hal_uuid); EXPECT_EQ(2, callback_count); - ASSERT_TRUE(scanner.get() == nullptr); // Assert to terminate in case of error + ASSERT_TRUE(scanner.get() == + nullptr); // Assert to terminate in case of error EXPECT_EQ(BLE_STATUS_FAILURE, status); EXPECT_EQ(uuid1, cb_uuid); } @@ -284,31 +281,26 @@ TEST_F(LowEnergyScannerPostRegisterTest, ScanRecord) { EXPECT_EQ(0, delegate.scan_result_count()); - vector kTestRecord0({ 0x02, 0x01, 0x00, 0x00 }); - vector kTestRecord1({ 0x00 }); - vector kTestRecord2({ - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, - 0x01, 0x00 - }); - const bt_bdaddr_t kTestAddress = { - { 0x01, 0x02, 0x03, 0x0A, 0x0B, 0x0C } - }; + vector kTestRecord0({0x02, 0x01, 0x00, 0x00}); + vector kTestRecord1({0x00}); + vector kTestRecord2( + {0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00}); + const bt_bdaddr_t kTestAddress = {{0x01, 0x02, 0x03, 0x0A, 0x0B, 0x0C}}; const char kTestAddressStr[] = "01:02:03:0A:0B:0C"; const int kTestRssi = 64; // Scan wasn't started. Result should be ignored. - fake_hal_gatt_iface_->NotifyScanResultCallback( - kTestAddress, kTestRssi, kTestRecord0); + fake_hal_gatt_iface_->NotifyScanResultCallback(kTestAddress, kTestRssi, + kTestRecord0); EXPECT_EQ(0, delegate.scan_result_count()); // Start a scan session for |le_scanner_|. - EXPECT_CALL(mock_adapter_, IsEnabled()) - .Times(1) - .WillOnce(Return(true)); + EXPECT_CALL(mock_adapter_, IsEnabled()).Times(1).WillOnce(Return(true)); EXPECT_CALL(*mock_handler_, Scan(_)) .Times(2) .WillOnce(Return(BT_STATUS_SUCCESS)) @@ -317,22 +309,22 @@ TEST_F(LowEnergyScannerPostRegisterTest, ScanRecord) { std::vector filters; ASSERT_TRUE(le_scanner_->StartScan(settings, filters)); - fake_hal_gatt_iface_->NotifyScanResultCallback( - kTestAddress, kTestRssi, kTestRecord0); + fake_hal_gatt_iface_->NotifyScanResultCallback(kTestAddress, kTestRssi, + kTestRecord0); EXPECT_EQ(1, delegate.scan_result_count()); EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address()); EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi()); EXPECT_EQ(3U, delegate.last_scan_result().scan_record().size()); - fake_hal_gatt_iface_->NotifyScanResultCallback( - kTestAddress, kTestRssi, kTestRecord1); + fake_hal_gatt_iface_->NotifyScanResultCallback(kTestAddress, kTestRssi, + kTestRecord1); EXPECT_EQ(2, delegate.scan_result_count()); EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address()); EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi()); EXPECT_TRUE(delegate.last_scan_result().scan_record().empty()); - fake_hal_gatt_iface_->NotifyScanResultCallback( - kTestAddress, kTestRssi, kTestRecord2); + fake_hal_gatt_iface_->NotifyScanResultCallback(kTestAddress, kTestRssi, + kTestRecord2); EXPECT_EQ(3, delegate.scan_result_count()); EXPECT_EQ(kTestAddressStr, delegate.last_scan_result().device_address()); EXPECT_EQ(kTestRssi, delegate.last_scan_result().rssi()); @@ -341,6 +333,5 @@ TEST_F(LowEnergyScannerPostRegisterTest, ScanRecord) { le_scanner_->SetDelegate(nullptr); } - } // namespace } // namespace bluetooth diff --git a/service/test/main.cc b/service/test/main.cc index 458a83bc2..039714818 100644 --- a/service/test/main.cc +++ b/service/test/main.cc @@ -24,7 +24,7 @@ #include -GTEST_API_ int main(int argc, char **argv) { +GTEST_API_ int main(int argc, char** argv) { base::AtExitManager exit_manager; base::CommandLine::Init(argc, argv); logging::LoggingSettings log_settings; diff --git a/service/test/parcelable_unittest.cc b/service/test/parcelable_unittest.cc index 5b5344854..dcfb8fbb0 100644 --- a/service/test/parcelable_unittest.cc +++ b/service/test/parcelable_unittest.cc @@ -50,7 +50,7 @@ bool TestData(IN& in) { parcel.setDataPosition(0); OUT out; parcel.readParcelable(&out); - //in case of error this display nice log message + // in case of error this display nice log message EXPECT_EQ(out, in); return in == out; } @@ -58,7 +58,8 @@ bool TestData(IN& in) { TEST(ParcelableTest, NonEmptyAdvertiseData) { std::vector data{0x02, 0x02, 0x00}; AdvertiseData adv0(data); - bool result = TestData(adv0); + bool result = + TestData(adv0); EXPECT_TRUE(result); } @@ -145,46 +146,57 @@ TEST(ParcelableTest, ScanResult) { } TEST(ParcelableTest, GattDescriptor) { - Descriptor s = Descriptor(0x0000, UUID::GetRandom(), bluetooth::kAttributePermissionRead); - Descriptor s2 = Descriptor(0xFFFE, UUID::GetRandom(), bluetooth::kAttributePermissionWrite); + Descriptor s = Descriptor(0x0000, UUID::GetRandom(), + bluetooth::kAttributePermissionRead); + Descriptor s2 = Descriptor(0xFFFE, UUID::GetRandom(), + bluetooth::kAttributePermissionWrite); Descriptor s3 = Descriptor(0x003D, UUID::GetRandom(), - bluetooth::kAttributePermissionReadEncryptedMITM | bluetooth::kAttributePermissionRead); + bluetooth::kAttributePermissionReadEncryptedMITM | + bluetooth::kAttributePermissionRead); - bool result = TestData(s); + bool result = + TestData(s); EXPECT_TRUE(result); - result = TestData(s2); + result = + TestData(s2); EXPECT_TRUE(result); - result = TestData(s3); + result = + TestData(s3); EXPECT_TRUE(result); } TEST(ParcelableTest, GattCharacteristic) { Characteristic c = Characteristic(0x0004, UUID::GetRandom(), 0, 0, - {Descriptor(0x0005, UUID::GetRandom(), 0), - Descriptor(0x0007, UUID::GetRandom(), 0), - Descriptor(0x00A1, UUID::GetRandom(), 0)}); + {Descriptor(0x0005, UUID::GetRandom(), 0), + Descriptor(0x0007, UUID::GetRandom(), 0), + Descriptor(0x00A1, UUID::GetRandom(), 0)}); - bool result = TestData(c); + bool result = + TestData( + c); EXPECT_TRUE(result); } TEST(ParcelableTest, GattService) { - Service s = Service(0x0001, true, UUID("CAFE"), - {Characteristic(0x0004, UUID::GetRandom(),bluetooth::kCharacteristicPropertyNotify, - bluetooth::kAttributePermissionRead, - {Descriptor(0x0005, UUID::GetRandom(), 0), - Descriptor(0x0007, UUID::GetRandom(), 0), - Descriptor(0x0009, UUID::GetRandom(), 0)}), - Characteristic(0x000D, UUID::GetRandom(), bluetooth::kCharacteristicPropertyWrite, - bluetooth::kAttributePermissionWrite, - {Descriptor(0x0010, UUID::GetRandom(), 0), - Descriptor(0x0012, UUID::GetRandom(), 0)}), - Characteristic(0x0015, UUID::GetRandom(), 0, 0, {}) - }, {}); - - Parcel parcel; + Service s = + Service(0x0001, true, UUID("CAFE"), + {Characteristic(0x0004, UUID::GetRandom(), + bluetooth::kCharacteristicPropertyNotify, + bluetooth::kAttributePermissionRead, + {Descriptor(0x0005, UUID::GetRandom(), 0), + Descriptor(0x0007, UUID::GetRandom(), 0), + Descriptor(0x0009, UUID::GetRandom(), 0)}), + Characteristic(0x000D, UUID::GetRandom(), + bluetooth::kCharacteristicPropertyWrite, + bluetooth::kAttributePermissionWrite, + {Descriptor(0x0010, UUID::GetRandom(), 0), + Descriptor(0x0012, UUID::GetRandom(), 0)}), + Characteristic(0x0015, UUID::GetRandom(), 0, 0, {})}, + {}); + + Parcel parcel; parcel.writeParcelable((android::bluetooth::BluetoothGattService)s); parcel.setDataPosition(0); diff --git a/service/test/settings_unittest.cc b/service/test/settings_unittest.cc index 52145a89d..62b6db581 100644 --- a/service/test/settings_unittest.cc +++ b/service/test/settings_unittest.cc @@ -31,13 +31,9 @@ class SettingsTest : public ::testing::Test { public: SettingsTest() = default; - void SetUp() override { - base::CommandLine::Reset(); - } + void SetUp() override { base::CommandLine::Reset(); } - void TearDown() override { - base::CommandLine::Reset(); - } + void TearDown() override { base::CommandLine::Reset(); } protected: base::AtExitManager exit_manager_; @@ -48,39 +44,33 @@ class SettingsTest : public ::testing::Test { }; TEST_F(SettingsTest, EmptyCommandLine) { - const base::CommandLine::CharType* argv[] = { "program" }; + const base::CommandLine::CharType* argv[] = {"program"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_TRUE(settings_.Init()); } TEST_F(SettingsTest, UnexpectedSwitches1) { const base::CommandLine::CharType* argv[] = { - "program", "--create-ipc-socket=foobar", "--foobarbaz" - }; + "program", "--create-ipc-socket=foobar", "--foobarbaz"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_FALSE(settings_.Init()); } TEST_F(SettingsTest, UnexpectedSwitches2) { - const base::CommandLine::CharType* argv[] = { - "program", "--foobarbaz" - }; + const base::CommandLine::CharType* argv[] = {"program", "--foobarbaz"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_FALSE(settings_.Init()); } TEST_F(SettingsTest, UnexpectedArguments1) { - const base::CommandLine::CharType* argv[] = { - "program", "foobarbaz" - }; + const base::CommandLine::CharType* argv[] = {"program", "foobarbaz"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_FALSE(settings_.Init()); } TEST_F(SettingsTest, UnexpectedArguments2) { const base::CommandLine::CharType* argv[] = { - "program", "--create-ipc-socket=foobar", "foobarbaz" - }; + "program", "--create-ipc-socket=foobar", "foobarbaz"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_FALSE(settings_.Init()); } @@ -94,17 +84,15 @@ TEST_F(SettingsTest, TooManyIpcOptions) { } TEST_F(SettingsTest, GoodArgumentsCreateIpc) { - const base::CommandLine::CharType* argv[] = { - "program", "--create-ipc-socket=foobar" - }; + const base::CommandLine::CharType* argv[] = {"program", + "--create-ipc-socket=foobar"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_TRUE(settings_.Init()); } TEST_F(SettingsTest, GoodArgumentsAndroidIpc) { const base::CommandLine::CharType* argv[] = { - "program", "--android-ipc-socket-suffix=foobar" - }; + "program", "--android-ipc-socket-suffix=foobar"}; EXPECT_TRUE(base::CommandLine::Init(arraysize(argv), argv)); EXPECT_TRUE(settings_.Init()); } diff --git a/service/test/stub_ipc_handler_binder.cc b/service/test/stub_ipc_handler_binder.cc index 6f5a13dfe..8ce064b16 100644 --- a/service/test/stub_ipc_handler_binder.cc +++ b/service/test/stub_ipc_handler_binder.cc @@ -22,9 +22,8 @@ namespace ipc { -IPCHandlerBinder::IPCHandlerBinder( - bluetooth::Adapter* adapter, - IPCManager::Delegate* delegate) +IPCHandlerBinder::IPCHandlerBinder(bluetooth::Adapter* adapter, + IPCManager::Delegate* delegate) : IPCHandler(adapter, delegate) { // Stub } diff --git a/service/test/stub_ipc_handler_linux.cc b/service/test/stub_ipc_handler_linux.cc index a36717e68..011b9652c 100644 --- a/service/test/stub_ipc_handler_linux.cc +++ b/service/test/stub_ipc_handler_linux.cc @@ -22,9 +22,8 @@ namespace ipc { -IPCHandlerLinux::IPCHandlerLinux( - bluetooth::Adapter* adapter, - IPCManager::Delegate* delegate) +IPCHandlerLinux::IPCHandlerLinux(bluetooth::Adapter* adapter, + IPCManager::Delegate* delegate) : IPCHandler(adapter, delegate), running_(false), thread_("IPCHandlerLinux"), diff --git a/service/test/util_unittest.cc b/service/test/util_unittest.cc index 78960d99f..83e7fb7f1 100644 --- a/service/test/util_unittest.cc +++ b/service/test/util_unittest.cc @@ -35,11 +35,11 @@ TEST(UtilTest, BdAddrFromString) { memset(&addr, 0, sizeof(addr)); EXPECT_TRUE(BdAddrFromString("00:00:00:00:00:00", &addr)); - const bt_bdaddr_t result0 = {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}; + const bt_bdaddr_t result0 = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; EXPECT_EQ(0, memcmp(&addr, &result0, sizeof(addr))); EXPECT_TRUE(BdAddrFromString("ab:01:4C:d5:21:9f", &addr)); - const bt_bdaddr_t result1 = {{ 0xab, 0x01, 0x4c, 0xd5, 0x21, 0x9f }}; + const bt_bdaddr_t result1 = {{0xab, 0x01, 0x4c, 0xd5, 0x21, 0x9f}}; EXPECT_EQ(0, memcmp(&addr, &result1, sizeof(addr))); } diff --git a/service/test/uuid_unittest.cc b/service/test/uuid_unittest.cc index 207be4ab0..3a8103a37 100644 --- a/service/test/uuid_unittest.cc +++ b/service/test/uuid_unittest.cc @@ -14,9 +14,9 @@ // limitations under the License. // +#include #include #include -#include #include @@ -26,10 +26,10 @@ using namespace bluetooth; namespace { -const std::array kBtSigBaseUUID = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, } -}; +const std::array kBtSigBaseUUID = {{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, + 0x5f, 0x9b, 0x34, 0xfb, +}}; } // namespace @@ -47,7 +47,7 @@ TEST(UUIDTest, Init16Bit) { auto my_uuid_16 = kBtSigBaseUUID; my_uuid_16[2] = 0xde; my_uuid_16[3] = 0xad; - UUID uuid(UUID::UUID16Bit({{ 0xde, 0xad }})); + UUID uuid(UUID::UUID16Bit({{0xde, 0xad}})); ASSERT_TRUE(uuid.is_valid()); ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_16); ASSERT_TRUE(UUID::kNumBytes16 == uuid.GetShortestRepresentationSize()); @@ -70,7 +70,6 @@ TEST(UUIDTest, Init16BitString) { ASSERT_TRUE(UUID::kNumBytes16 == uuid.GetShortestRepresentationSize()); } - // Verify that we initialize a 32-bit UUID in a // way consistent with how we read it. TEST(UUIDTest, Init32Bit) { @@ -79,7 +78,7 @@ TEST(UUIDTest, Init32Bit) { my_uuid_32[1] = 0xad; my_uuid_32[2] = 0xbe; my_uuid_32[3] = 0xef; - UUID uuid(UUID::UUID32Bit({{ 0xde, 0xad, 0xbe, 0xef }})); + UUID uuid(UUID::UUID32Bit({{0xde, 0xad, 0xbe, 0xef}})); ASSERT_TRUE(uuid.is_valid()); ASSERT_TRUE(uuid.GetFullBigEndian() == my_uuid_32); ASSERT_TRUE(UUID::kNumBytes32 == uuid.GetShortestRepresentationSize()); @@ -130,8 +129,7 @@ TEST(UUIDTest, Init128BitLittleEndian) { // way consistent with how we read it. TEST(UUIDTest, Init128BitString) { UUID::UUID128Bit my_uuid{ - { 7, 1, 6, 8, 14, 255, 16, 2, 3, 4, 5, 6, 7, 8, 9, 10 } - }; + {7, 1, 6, 8, 14, 255, 16, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; std::string my_uuid_string("07010608-0eff-1002-0304-05060708090a"); UUID uuid0(my_uuid); @@ -155,7 +153,7 @@ TEST(UUIDTest, InitInvalid) { } TEST(UUIDTest, ToString) { - const UUID::UUID16Bit data{{ 0x18, 0x0d }}; + const UUID::UUID16Bit data{{0x18, 0x0d}}; UUID uuid(data); std::string uuid_string = uuid.ToString(); EXPECT_EQ("0000180d-0000-1000-8000-00805f9b34fb", uuid_string); diff --git a/stack/a2dp/a2dp_vendor.cc b/stack/a2dp/a2dp_vendor.cc index 6e9161b2d..2e8bec993 100644 --- a/stack/a2dp/a2dp_vendor.cc +++ b/stack/a2dp/a2dp_vendor.cc @@ -35,13 +35,12 @@ tA2DP_CODEC_SEP_INDEX A2DP_VendorSourceCodecSepIndex( return A2DP_CODEC_SEP_INDEX_MAX; } -const char* A2DP_VendorCodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index) -{ +const char* A2DP_VendorCodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index) { // Add checks based on codec_sep_index switch (codec_sep_index) { case A2DP_CODEC_SEP_INDEX_SOURCE_SBC: case A2DP_CODEC_SEP_INDEX_SINK_SBC: - break; // This is not a vendor-specific codec + break; // This is not a vendor-specific codec case A2DP_CODEC_SEP_INDEX_MAX: break; } @@ -50,13 +49,12 @@ const char* A2DP_VendorCodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index) } bool A2DP_VendorInitCodecConfig(tA2DP_CODEC_SEP_INDEX codec_sep_index, - UNUSED_ATTR tAVDT_CFG* p_cfg) -{ + UNUSED_ATTR tAVDT_CFG* p_cfg) { // Add checks based on codec_sep_index switch (codec_sep_index) { case A2DP_CODEC_SEP_INDEX_SOURCE_SBC: case A2DP_CODEC_SEP_INDEX_SINK_SBC: - break; // This is not a vendor-specific codec + break; // This is not a vendor-specific codec case A2DP_CODEC_SEP_INDEX_MAX: break; } diff --git a/stack/avct/avct_api.cc b/stack/avct/avct_api.cc index d33bee4a3..2910461e4 100644 --- a/stack/avct/avct_api.cc +++ b/stack/avct/avct_api.cc @@ -22,16 +22,16 @@ * ******************************************************************************/ +#include "avct_api.h" #include -#include "bt_types.h" +#include "avct_int.h" +#include "bt_common.h" #include "bt_target.h" +#include "bt_types.h" #include "bt_utils.h" -#include "bt_common.h" +#include "btm_api.h" #include "l2c_api.h" #include "l2cdefs.h" -#include "btm_api.h" -#include "avct_api.h" -#include "avct_int.h" #include "osi/include/osi.h" /* Control block for AVCT */ @@ -51,42 +51,44 @@ tAVCT_CB avct_cb; * Returns void * ******************************************************************************/ -void AVCT_Register(uint16_t mtu, - UNUSED_ATTR uint16_t mtu_br, uint8_t sec_mask) -{ - AVCT_TRACE_API("AVCT_Register"); +void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br, + uint8_t sec_mask) { + AVCT_TRACE_API("AVCT_Register"); - /* register PSM with L2CAP */ - L2CA_Register(AVCT_PSM, (tL2CAP_APPL_INFO *) &avct_l2c_appl); + /* register PSM with L2CAP */ + L2CA_Register(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl); - /* set security level */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_PSM, 0, 0); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_PSM, 0, 0); + /* set security level */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_PSM, 0, + 0); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_PSM, 0, + 0); - /* initialize AVCTP data structures */ - memset(&avct_cb, 0, sizeof(tAVCT_CB)); + /* initialize AVCTP data structures */ + memset(&avct_cb, 0, sizeof(tAVCT_CB)); - /* Include the browsing channel which uses eFCR */ - L2CA_Register(AVCT_BR_PSM, (tL2CAP_APPL_INFO *) &avct_l2c_br_appl); + /* Include the browsing channel which uses eFCR */ + L2CA_Register(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl); - /* AVCTP browsing channel uses the same security service as AVCTP control channel */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_BR_PSM, 0, 0); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_BR_PSM, 0, 0); + /* AVCTP browsing channel uses the same security service as AVCTP control + * channel */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_BR_PSM, + 0, 0); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVCTP, sec_mask, AVCT_BR_PSM, + 0, 0); - if (mtu_br < AVCT_MIN_BROWSE_MTU) - mtu_br = AVCT_MIN_BROWSE_MTU; - avct_cb.mtu_br = mtu_br; + if (mtu_br < AVCT_MIN_BROWSE_MTU) mtu_br = AVCT_MIN_BROWSE_MTU; + avct_cb.mtu_br = mtu_br; #if defined(AVCT_INITIAL_TRACE_LEVEL) - avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL; + avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL; #else - avct_cb.trace_level = BT_TRACE_LEVEL_NONE; + avct_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif - if (mtu < AVCT_MIN_CONTROL_MTU) - mtu = AVCT_MIN_CONTROL_MTU; - /* store mtu */ - avct_cb.mtu = mtu; + if (mtu < AVCT_MIN_CONTROL_MTU) mtu = AVCT_MIN_CONTROL_MTU; + /* store mtu */ + avct_cb.mtu = mtu; } /******************************************************************************* @@ -103,12 +105,11 @@ void AVCT_Register(uint16_t mtu, * Returns void * ******************************************************************************/ -void AVCT_Deregister(void) -{ - AVCT_TRACE_API("AVCT_Deregister"); +void AVCT_Deregister(void) { + AVCT_TRACE_API("AVCT_Deregister"); - /* deregister PSM with L2CAP */ - L2CA_Deregister(AVCT_PSM); + /* deregister PSM with L2CAP */ + L2CA_Deregister(AVCT_PSM); } /******************************************************************************* @@ -128,57 +129,48 @@ void AVCT_Deregister(void) * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVCT_CreateConn(uint8_t *p_handle, tAVCT_CC *p_cc, BD_ADDR peer_addr) -{ - uint16_t result = AVCT_SUCCESS; - tAVCT_CCB *p_ccb; - tAVCT_LCB *p_lcb; - - AVCT_TRACE_API("AVCT_CreateConn: %d, control:%d", p_cc->role, p_cc->control); - - /* Allocate ccb; if no ccbs, return failure */ - p_ccb = avct_ccb_alloc(p_cc); - if (p_ccb == NULL) - { - result = AVCT_NO_RESOURCES; - } - else - { - /* get handle */ - *p_handle = avct_ccb_to_idx(p_ccb); - - /* if initiator connection */ - if (p_cc->role == AVCT_INT) - { - /* find link; if none allocate a new one */ - p_lcb = avct_lcb_by_bd(peer_addr); - if (p_lcb == NULL) - { - p_lcb = avct_lcb_alloc(peer_addr); - if (p_lcb == NULL) - { - /* no link resources; free ccb as well */ - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - result = AVCT_NO_RESOURCES; - } - } - /* check if PID already in use */ - else if (avct_lcb_has_pid(p_lcb, p_cc->pid)) - { - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - result = AVCT_PID_IN_USE; - } - - if (result == AVCT_SUCCESS) - { - /* bind lcb to ccb */ - p_ccb->p_lcb = p_lcb; - AVCT_TRACE_DEBUG("ch_state: %d", p_lcb->ch_state); - avct_lcb_event(p_lcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); - } +uint16_t AVCT_CreateConn(uint8_t* p_handle, tAVCT_CC* p_cc, BD_ADDR peer_addr) { + uint16_t result = AVCT_SUCCESS; + tAVCT_CCB* p_ccb; + tAVCT_LCB* p_lcb; + + AVCT_TRACE_API("AVCT_CreateConn: %d, control:%d", p_cc->role, p_cc->control); + + /* Allocate ccb; if no ccbs, return failure */ + p_ccb = avct_ccb_alloc(p_cc); + if (p_ccb == NULL) { + result = AVCT_NO_RESOURCES; + } else { + /* get handle */ + *p_handle = avct_ccb_to_idx(p_ccb); + + /* if initiator connection */ + if (p_cc->role == AVCT_INT) { + /* find link; if none allocate a new one */ + p_lcb = avct_lcb_by_bd(peer_addr); + if (p_lcb == NULL) { + p_lcb = avct_lcb_alloc(peer_addr); + if (p_lcb == NULL) { + /* no link resources; free ccb as well */ + avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); + result = AVCT_NO_RESOURCES; } + } + /* check if PID already in use */ + else if (avct_lcb_has_pid(p_lcb, p_cc->pid)) { + avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); + result = AVCT_PID_IN_USE; + } + + if (result == AVCT_SUCCESS) { + /* bind lcb to ccb */ + p_ccb->p_lcb = p_lcb; + AVCT_TRACE_DEBUG("ch_state: %d", p_lcb->ch_state); + avct_lcb_event(p_lcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT*)&p_ccb); + } } - return result; + } + return result; } /******************************************************************************* @@ -194,30 +186,27 @@ uint16_t AVCT_CreateConn(uint8_t *p_handle, tAVCT_CC *p_cc, BD_ADDR peer_addr) * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVCT_RemoveConn(uint8_t handle) -{ - uint16_t result = AVCT_SUCCESS; - tAVCT_CCB *p_ccb; - - AVCT_TRACE_API("AVCT_RemoveConn"); - - /* map handle to ccb */ - p_ccb = avct_ccb_by_idx(handle); - if (p_ccb == NULL) - { - result = AVCT_BAD_HANDLE; - } - /* if connection not bound to lcb, dealloc */ - else if (p_ccb->p_lcb == NULL) - { - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - } - /* send unbind event to lcb */ - else - { - avct_lcb_event(p_ccb->p_lcb, AVCT_LCB_UL_UNBIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); - } - return result; +uint16_t AVCT_RemoveConn(uint8_t handle) { + uint16_t result = AVCT_SUCCESS; + tAVCT_CCB* p_ccb; + + AVCT_TRACE_API("AVCT_RemoveConn"); + + /* map handle to ccb */ + p_ccb = avct_ccb_by_idx(handle); + if (p_ccb == NULL) { + result = AVCT_BAD_HANDLE; + } + /* if connection not bound to lcb, dealloc */ + else if (p_ccb->p_lcb == NULL) { + avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); + } + /* send unbind event to lcb */ + else { + avct_lcb_event(p_ccb->p_lcb, AVCT_LCB_UL_UNBIND_EVT, + (tAVCT_LCB_EVT*)&p_ccb); + } + return result; } /******************************************************************************* @@ -237,64 +226,52 @@ uint16_t AVCT_RemoveConn(uint8_t handle) * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVCT_CreateBrowse (uint8_t handle, uint8_t role) -{ - uint16_t result = AVCT_SUCCESS; - tAVCT_CCB *p_ccb; - tAVCT_BCB *p_bcb; - int index; - - AVCT_TRACE_API("AVCT_CreateBrowse: %d", role); - - /* map handle to ccb */ - p_ccb = avct_ccb_by_idx(handle); - if (p_ccb == NULL) - { - return AVCT_BAD_HANDLE; +uint16_t AVCT_CreateBrowse(uint8_t handle, uint8_t role) { + uint16_t result = AVCT_SUCCESS; + tAVCT_CCB* p_ccb; + tAVCT_BCB* p_bcb; + int index; + + AVCT_TRACE_API("AVCT_CreateBrowse: %d", role); + + /* map handle to ccb */ + p_ccb = avct_ccb_by_idx(handle); + if (p_ccb == NULL) { + return AVCT_BAD_HANDLE; + } else { + /* mark this CCB as supporting browsing channel */ + if ((p_ccb->allocated & AVCT_ALOC_BCB) == 0) { + p_ccb->allocated |= AVCT_ALOC_BCB; } - else - { - /* mark this CCB as supporting browsing channel */ - if ((p_ccb->allocated & AVCT_ALOC_BCB) == 0) - { - p_ccb->allocated |= AVCT_ALOC_BCB; - } + } + + /* if initiator connection */ + if (role == AVCT_INT) { + /* the link control block must exist before this function is called as INT. + */ + if ((p_ccb->p_lcb == NULL) || (p_ccb->p_lcb->allocated == 0)) { + result = AVCT_NOT_OPEN; + } else { + /* find link; if none allocate a new one */ + index = p_ccb->p_lcb->allocated; + if (index > AVCT_NUM_LINKS) { + result = AVCT_BAD_HANDLE; + } else { + p_bcb = &avct_cb.bcb[index - 1]; + p_bcb->allocated = index; + } } - /* if initiator connection */ - if (role == AVCT_INT) - { - /* the link control block must exist before this function is called as INT. */ - if ((p_ccb->p_lcb == NULL) || (p_ccb->p_lcb->allocated == 0)) - { - result = AVCT_NOT_OPEN; - } - else - { - /* find link; if none allocate a new one */ - index = p_ccb->p_lcb->allocated; - if (index > AVCT_NUM_LINKS) - { - result = AVCT_BAD_HANDLE; - } - else - { - p_bcb = &avct_cb.bcb[index - 1]; - p_bcb->allocated = index; - } - } - - if (result == AVCT_SUCCESS) - { - /* bind bcb to ccb */ - p_ccb->p_bcb = p_bcb; - memcpy(p_bcb->peer_addr, p_ccb->p_lcb->peer_addr, BD_ADDR_LEN); - AVCT_TRACE_DEBUG("ch_state: %d", p_bcb->ch_state); - avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); - } + if (result == AVCT_SUCCESS) { + /* bind bcb to ccb */ + p_ccb->p_bcb = p_bcb; + memcpy(p_bcb->peer_addr, p_ccb->p_lcb->peer_addr, BD_ADDR_LEN); + AVCT_TRACE_DEBUG("ch_state: %d", p_bcb->ch_state); + avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT*)&p_ccb); } + } - return result; + return result; } /******************************************************************************* @@ -310,26 +287,24 @@ uint16_t AVCT_CreateBrowse (uint8_t handle, uint8_t role) * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVCT_RemoveBrowse (uint8_t handle) -{ - uint16_t result = AVCT_SUCCESS; - tAVCT_CCB *p_ccb; - - AVCT_TRACE_API("AVCT_RemoveBrowse"); - - /* map handle to ccb */ - p_ccb = avct_ccb_by_idx(handle); - if (p_ccb == NULL) - { - result = AVCT_BAD_HANDLE; - } - else if (p_ccb->p_bcb != NULL) - /* send unbind event to bcb */ - { - avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); - } - - return result; +uint16_t AVCT_RemoveBrowse(uint8_t handle) { + uint16_t result = AVCT_SUCCESS; + tAVCT_CCB* p_ccb; + + AVCT_TRACE_API("AVCT_RemoveBrowse"); + + /* map handle to ccb */ + p_ccb = avct_ccb_by_idx(handle); + if (p_ccb == NULL) { + result = AVCT_BAD_HANDLE; + } else if (p_ccb->p_bcb != NULL) + /* send unbind event to bcb */ + { + avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, + (tAVCT_LCB_EVT*)&p_ccb); + } + + return result; } /******************************************************************************* @@ -342,18 +317,16 @@ uint16_t AVCT_RemoveBrowse (uint8_t handle) * Returns the peer browsing channel MTU. * ******************************************************************************/ -uint16_t AVCT_GetBrowseMtu (uint8_t handle) -{ - uint16_t peer_mtu = AVCT_MIN_BROWSE_MTU; +uint16_t AVCT_GetBrowseMtu(uint8_t handle) { + uint16_t peer_mtu = AVCT_MIN_BROWSE_MTU; - tAVCT_CCB *p_ccb; + tAVCT_CCB* p_ccb; - if ((p_ccb = avct_ccb_by_idx(handle)) != NULL && p_ccb->p_bcb != NULL) - { - peer_mtu = p_ccb->p_bcb->peer_mtu; - } + if ((p_ccb = avct_ccb_by_idx(handle)) != NULL && p_ccb->p_bcb != NULL) { + peer_mtu = p_ccb->p_bcb->peer_mtu; + } - return peer_mtu; + return peer_mtu; } /******************************************************************************* @@ -366,22 +339,19 @@ uint16_t AVCT_GetBrowseMtu (uint8_t handle) * Returns the peer MTU size. * ******************************************************************************/ -uint16_t AVCT_GetPeerMtu (uint8_t handle) -{ - uint16_t peer_mtu = L2CAP_DEFAULT_MTU; - tAVCT_CCB *p_ccb; - - /* map handle to ccb */ - p_ccb = avct_ccb_by_idx(handle); - if (p_ccb != NULL) - { - if (p_ccb->p_lcb) - { - peer_mtu = p_ccb->p_lcb->peer_mtu; - } +uint16_t AVCT_GetPeerMtu(uint8_t handle) { + uint16_t peer_mtu = L2CAP_DEFAULT_MTU; + tAVCT_CCB* p_ccb; + + /* map handle to ccb */ + p_ccb = avct_ccb_by_idx(handle); + if (p_ccb != NULL) { + if (p_ccb->p_lcb) { + peer_mtu = p_ccb->p_lcb->peer_mtu; } + } - return peer_mtu; + return peer_mtu; } /******************************************************************************* @@ -406,63 +376,55 @@ uint16_t AVCT_GetPeerMtu (uint8_t handle) * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVCT_MsgReq(uint8_t handle, uint8_t label, uint8_t cr, BT_HDR *p_msg) -{ - uint16_t result = AVCT_SUCCESS; - tAVCT_CCB *p_ccb; - tAVCT_UL_MSG ul_msg; - - AVCT_TRACE_API("%s", __func__); - - /* verify p_msg parameter */ - if (p_msg == NULL) - { - return AVCT_NO_RESOURCES; - } - AVCT_TRACE_API("%s len: %d layer_specific: %d", __func__, p_msg->len, p_msg->layer_specific); - - /* map handle to ccb */ - p_ccb = avct_ccb_by_idx(handle); - if (p_ccb == NULL) - { +uint16_t AVCT_MsgReq(uint8_t handle, uint8_t label, uint8_t cr, BT_HDR* p_msg) { + uint16_t result = AVCT_SUCCESS; + tAVCT_CCB* p_ccb; + tAVCT_UL_MSG ul_msg; + + AVCT_TRACE_API("%s", __func__); + + /* verify p_msg parameter */ + if (p_msg == NULL) { + return AVCT_NO_RESOURCES; + } + AVCT_TRACE_API("%s len: %d layer_specific: %d", __func__, p_msg->len, + p_msg->layer_specific); + + /* map handle to ccb */ + p_ccb = avct_ccb_by_idx(handle); + if (p_ccb == NULL) { + result = AVCT_BAD_HANDLE; + osi_free(p_msg); + } + /* verify channel is bound to link */ + else if (p_ccb->p_lcb == NULL) { + result = AVCT_NOT_OPEN; + osi_free(p_msg); + } + + if (result == AVCT_SUCCESS) { + ul_msg.p_buf = p_msg; + ul_msg.p_ccb = p_ccb; + ul_msg.label = label; + ul_msg.cr = cr; + + /* send msg event to bcb */ + if (p_msg->layer_specific == AVCT_DATA_BROWSE) { + if (p_ccb->p_bcb == NULL && (p_ccb->allocated & AVCT_ALOC_BCB) == 0) { + /* BCB channel is not open and not allocated */ result = AVCT_BAD_HANDLE; osi_free(p_msg); + } else { + p_ccb->p_bcb = avct_bcb_by_lcb(p_ccb->p_lcb); + avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_MSG_EVT, + (tAVCT_LCB_EVT*)&ul_msg); + } } - /* verify channel is bound to link */ - else if (p_ccb->p_lcb == NULL) - { - result = AVCT_NOT_OPEN; - osi_free(p_msg); + /* send msg event to lcb */ + else { + avct_lcb_event(p_ccb->p_lcb, AVCT_LCB_UL_MSG_EVT, + (tAVCT_LCB_EVT*)&ul_msg); } - - if (result == AVCT_SUCCESS) - { - ul_msg.p_buf = p_msg; - ul_msg.p_ccb = p_ccb; - ul_msg.label = label; - ul_msg.cr = cr; - - /* send msg event to bcb */ - if (p_msg->layer_specific == AVCT_DATA_BROWSE) - { - if (p_ccb->p_bcb == NULL && (p_ccb->allocated & AVCT_ALOC_BCB) == 0) - { - /* BCB channel is not open and not allocated */ - result = AVCT_BAD_HANDLE; - osi_free(p_msg); - } - else - { - p_ccb->p_bcb = avct_bcb_by_lcb(p_ccb->p_lcb); - avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg); - } - } - /* send msg event to lcb */ - else - { - avct_lcb_event(p_ccb->p_lcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg); - } - } - return result; + } + return result; } - diff --git a/stack/avct/avct_bcb_act.cc b/stack/avct/avct_bcb_act.cc index 7e78402fc..abf58fc31 100644 --- a/stack/avct/avct_bcb_act.cc +++ b/stack/avct/avct_bcb_act.cc @@ -25,36 +25,34 @@ * *****************************************************************************/ - #include -#include "bt_target.h" -#include "bt_utils.h" #include "avct_api.h" #include "avct_int.h" +#include "bt_target.h" +#include "bt_utils.h" #include "btm_api.h" #include "osi/include/osi.h" /* action function list */ const tAVCT_BCB_ACTION avct_bcb_action[] = { - avct_bcb_chnl_open, /* AVCT_LCB_CHNL_OPEN */ - avct_bcb_chnl_disc, /* AVCT_LCB_CHNL_DISC */ - avct_bcb_send_msg, /* AVCT_LCB_SEND_MSG */ - avct_bcb_open_ind, /* AVCT_LCB_OPEN_IND */ - avct_bcb_open_fail, /* AVCT_LCB_OPEN_FAIL */ - avct_bcb_close_ind, /* AVCT_LCB_CLOSE_IND */ - avct_bcb_close_cfm, /* AVCT_LCB_CLOSE_CFM */ - avct_bcb_msg_ind, /* AVCT_LCB_MSG_IND */ - avct_bcb_cong_ind, /* AVCT_LCB_CONG_IND */ - avct_bcb_bind_conn, /* AVCT_LCB_BIND_CONN */ - avct_bcb_bind_fail, /* AVCT_LCB_BIND_FAIL */ - avct_bcb_unbind_disc, /* AVCT_LCB_UNBIND_DISC */ - avct_bcb_chk_disc, /* AVCT_LCB_CHK_DISC */ - avct_bcb_discard_msg, /* AVCT_LCB_DISCARD_MSG */ - avct_bcb_dealloc, /* AVCT_LCB_DEALLOC */ - avct_bcb_free_msg_ind /* AVCT_LCB_FREE_MSG_IND */ + avct_bcb_chnl_open, /* AVCT_LCB_CHNL_OPEN */ + avct_bcb_chnl_disc, /* AVCT_LCB_CHNL_DISC */ + avct_bcb_send_msg, /* AVCT_LCB_SEND_MSG */ + avct_bcb_open_ind, /* AVCT_LCB_OPEN_IND */ + avct_bcb_open_fail, /* AVCT_LCB_OPEN_FAIL */ + avct_bcb_close_ind, /* AVCT_LCB_CLOSE_IND */ + avct_bcb_close_cfm, /* AVCT_LCB_CLOSE_CFM */ + avct_bcb_msg_ind, /* AVCT_LCB_MSG_IND */ + avct_bcb_cong_ind, /* AVCT_LCB_CONG_IND */ + avct_bcb_bind_conn, /* AVCT_LCB_BIND_CONN */ + avct_bcb_bind_fail, /* AVCT_LCB_BIND_FAIL */ + avct_bcb_unbind_disc, /* AVCT_LCB_UNBIND_DISC */ + avct_bcb_chk_disc, /* AVCT_LCB_CHK_DISC */ + avct_bcb_discard_msg, /* AVCT_LCB_DISCARD_MSG */ + avct_bcb_dealloc, /* AVCT_LCB_DEALLOC */ + avct_bcb_free_msg_ind /* AVCT_LCB_FREE_MSG_IND */ }; - /******************************************************************************* * * Function avct_bcb_msg_asmbl @@ -66,25 +64,23 @@ const tAVCT_BCB_ACTION avct_bcb_action[] = { * available. * ******************************************************************************/ -static BT_HDR *avct_bcb_msg_asmbl(UNUSED_ATTR tAVCT_BCB *p_bcb, BT_HDR *p_buf) -{ - uint8_t *p; - uint8_t pkt_type; - - /* parse the message header */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - pkt_type = AVCT_PKT_TYPE(p); - - /* must be single packet - can not fragment */ - if (pkt_type != AVCT_PKT_TYPE_SINGLE) - { - osi_free_and_reset((void **)&p_buf); - AVCT_TRACE_WARNING("Pkt type=%d - fragmentation not allowed. drop it", pkt_type); - } - return p_buf; +static BT_HDR* avct_bcb_msg_asmbl(UNUSED_ATTR tAVCT_BCB* p_bcb, BT_HDR* p_buf) { + uint8_t* p; + uint8_t pkt_type; + + /* parse the message header */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + pkt_type = AVCT_PKT_TYPE(p); + + /* must be single packet - can not fragment */ + if (pkt_type != AVCT_PKT_TYPE_SINGLE) { + osi_free_and_reset((void**)&p_buf); + AVCT_TRACE_WARNING("Pkt type=%d - fragmentation not allowed. drop it", + pkt_type); + } + return p_buf; } - /******************************************************************************* * * Function avct_bcb_chnl_open @@ -95,31 +91,29 @@ static BT_HDR *avct_bcb_msg_asmbl(UNUSED_ATTR tAVCT_BCB *p_bcb, BT_HDR *p_buf) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_chnl_open(tAVCT_BCB *p_bcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - uint16_t result = AVCT_RESULT_FAIL; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - tL2CAP_ERTM_INFO ertm_info; - - BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP_BROWSE, 0); - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = avct_l2c_br_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; - - /* call l2cap connect req */ - p_bcb->ch_state = AVCT_CH_CONN; - p_bcb->ch_lcid = L2CA_ErtmConnectReq(AVCT_BR_PSM, p_lcb->peer_addr, &ertm_info); - if (p_bcb->ch_lcid == 0) - { - /* if connect req failed, send ourselves close event */ - avct_bcb_event(p_bcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } +void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + uint16_t result = AVCT_RESULT_FAIL; + tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb); + tL2CAP_ERTM_INFO ertm_info; + + BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP_BROWSE, 0); + + /* Set the FCR options: Browsing channel mandates ERTM */ + ertm_info.preferred_mode = avct_l2c_br_fcr_opts_def.mode; + ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; + ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; + + /* call l2cap connect req */ + p_bcb->ch_state = AVCT_CH_CONN; + p_bcb->ch_lcid = + L2CA_ErtmConnectReq(AVCT_BR_PSM, p_lcb->peer_addr, &ertm_info); + if (p_bcb->ch_lcid == 0) { + /* if connect req failed, send ourselves close event */ + avct_bcb_event(p_bcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); + } } /******************************************************************************* @@ -132,11 +126,10 @@ void avct_bcb_chnl_open(tAVCT_BCB *p_bcb, * Returns Nothing. * ******************************************************************************/ -void avct_bcb_unbind_disc(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_BROWSE_DISCONN_CFM_EVT, 0, NULL); +void avct_bcb_unbind_disc(UNUSED_ATTR tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + p_data->p_ccb->p_bcb = NULL; + (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), + AVCT_BROWSE_DISCONN_CFM_EVT, 0, NULL); } /******************************************************************************* @@ -153,62 +146,57 @@ void avct_bcb_unbind_disc(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_open_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_CCB *p_ccb_bind = NULL; - bool bind = false; - tAVCT_UL_MSG ul_msg; - - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - /* if bound to this bcb send connect confirm event */ - if (p_ccb->p_bcb == p_bcb) - { - bind = true; - p_ccb_bind = p_ccb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_CFM_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - /* if unbound acceptor and lcb allocated and bd_addr are the same for bcb and lcb */ - else if ((p_ccb->p_bcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && - (p_ccb->p_lcb != NULL) && - (!memcmp(p_bcb->peer_addr, p_ccb->p_lcb->peer_addr, BD_ADDR_LEN))) - { - /* bind bcb to ccb and send connect ind event */ - bind = true; - p_ccb_bind = p_ccb; - p_ccb->p_bcb = p_bcb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_IND_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - } - } - - /* if no ccbs bound to this lcb, disconnect */ - if (bind == false) - { - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - return; - } - - if (!p_bcb->p_tx_msg || !p_ccb_bind) - { - return; +void avct_bcb_open_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + tAVCT_CCB* p_ccb_bind = NULL; + bool bind = false; + tAVCT_UL_MSG ul_msg; + + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + /* if ccb allocated and */ + if (p_ccb->allocated) { + /* if bound to this bcb send connect confirm event */ + if (p_ccb->p_bcb == p_bcb) { + bind = true; + p_ccb_bind = p_ccb; + p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_CFM_EVT, + 0, p_ccb->p_lcb->peer_addr); + } + /* if unbound acceptor and lcb allocated and bd_addr are the same for bcb + and lcb */ + else if ((p_ccb->p_bcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && + (p_ccb->p_lcb != NULL) && + (!memcmp(p_bcb->peer_addr, p_ccb->p_lcb->peer_addr, + BD_ADDR_LEN))) { + /* bind bcb to ccb and send connect ind event */ + bind = true; + p_ccb_bind = p_ccb; + p_ccb->p_bcb = p_bcb; + p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_IND_EVT, + 0, p_ccb->p_lcb->peer_addr); + } } - - ul_msg.p_buf = p_bcb->p_tx_msg; - ul_msg.p_ccb = p_ccb_bind; - ul_msg.label = (uint8_t)(p_bcb->p_tx_msg->layer_specific & 0xFF); - ul_msg.cr = (uint8_t)((p_bcb->p_tx_msg->layer_specific & 0xFF00) >> 8); - p_bcb->p_tx_msg->layer_specific = AVCT_DATA_BROWSE; - p_bcb->p_tx_msg = NULL; - - /* send msg event to bcb */ - avct_bcb_event(p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg); + } + + /* if no ccbs bound to this lcb, disconnect */ + if (bind == false) { + avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); + return; + } + + if (!p_bcb->p_tx_msg || !p_ccb_bind) { + return; + } + + ul_msg.p_buf = p_bcb->p_tx_msg; + ul_msg.p_ccb = p_ccb_bind; + ul_msg.label = (uint8_t)(p_bcb->p_tx_msg->layer_specific & 0xFF); + ul_msg.cr = (uint8_t)((p_bcb->p_tx_msg->layer_specific & 0xFF00) >> 8); + p_bcb->p_tx_msg->layer_specific = AVCT_DATA_BROWSE; + p_bcb->p_tx_msg = NULL; + + /* send msg event to bcb */ + avct_bcb_event(p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT*)&ul_msg); } /******************************************************************************* @@ -222,18 +210,14 @@ void avct_bcb_open_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_open_fail(tAVCT_BCB *p_bcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - p_ccb->p_bcb = NULL; - } +void avct_bcb_open_fail(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) { + p_ccb->p_bcb = NULL; } + } } /******************************************************************************* @@ -247,29 +231,23 @@ void avct_bcb_open_fail(tAVCT_BCB *p_bcb, * Returns Nothing. * ******************************************************************************/ -void avct_bcb_close_ind(tAVCT_BCB *p_bcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb->cc.role == AVCT_INT) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_CFM_EVT, - 0, p_lcb->peer_addr); - } - else - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_IND_EVT, - 0, NULL); - } - p_ccb->p_bcb = NULL; - } +void avct_bcb_close_ind(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb); + + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) { + if (p_ccb->cc.role == AVCT_INT) { + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), + AVCT_BROWSE_DISCONN_CFM_EVT, 0, + p_lcb->peer_addr); + } else { + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), + AVCT_BROWSE_DISCONN_IND_EVT, 0, NULL); + } + p_ccb->p_bcb = NULL; } + } } /******************************************************************************* @@ -283,38 +261,31 @@ void avct_bcb_close_ind(tAVCT_BCB *p_bcb, * Returns Nothing. * ******************************************************************************/ -void avct_bcb_close_cfm(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - uint8_t event = 0; - /* Whether BCB initiated channel close */ - bool ch_close = p_bcb->ch_close; - tAVCT_CTRL_CBACK *p_cback; - - p_bcb->ch_close = false; - p_bcb->allocated = 0; - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - /* if this ccb initiated close send disconnect cfm otherwise ind */ - if (ch_close) - { - event = AVCT_BROWSE_DISCONN_CFM_EVT; - } - else - { - event = AVCT_BROWSE_DISCONN_IND_EVT; - } - - p_cback = p_ccb->cc.p_ctrl_cback; - p_ccb->p_bcb = NULL; - if (p_ccb->p_lcb == NULL) - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - (*p_cback)(avct_ccb_to_idx(p_ccb), event, - p_data->result, p_bcb->peer_addr); - } +void avct_bcb_close_cfm(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + uint8_t event = 0; + /* Whether BCB initiated channel close */ + bool ch_close = p_bcb->ch_close; + tAVCT_CTRL_CBACK* p_cback; + + p_bcb->ch_close = false; + p_bcb->allocated = 0; + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) { + /* if this ccb initiated close send disconnect cfm otherwise ind */ + if (ch_close) { + event = AVCT_BROWSE_DISCONN_CFM_EVT; + } else { + event = AVCT_BROWSE_DISCONN_IND_EVT; + } + + p_cback = p_ccb->cc.p_ctrl_cback; + p_ccb->p_bcb = NULL; + if (p_ccb->p_lcb == NULL) avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); + (*p_cback)(avct_ccb_to_idx(p_ccb), event, p_data->result, + p_bcb->peer_addr); } + } } /******************************************************************************* @@ -327,12 +298,12 @@ void avct_bcb_close_cfm(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_bind_conn(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - p_data->p_ccb->p_bcb = p_bcb; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_BROWSE_CONN_CFM_EVT, 0, p_lcb->peer_addr); +void avct_bcb_bind_conn(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb); + p_data->p_ccb->p_bcb = p_bcb; + (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), + AVCT_BROWSE_CONN_CFM_EVT, 0, + p_lcb->peer_addr); } /******************************************************************************* @@ -347,16 +318,14 @@ void avct_bcb_bind_conn(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_chk_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_bcb->ch_close = avct_bcb_get_last_ccb_index(p_bcb, p_data->p_ccb); - if (p_bcb->ch_close) - { - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - return; - } - - avct_bcb_unbind_disc(p_bcb, p_data); +void avct_bcb_chk_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + p_bcb->ch_close = avct_bcb_get_last_ccb_index(p_bcb, p_data->p_ccb); + if (p_bcb->ch_close) { + avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); + return; + } + + avct_bcb_unbind_disc(p_bcb, p_data); } /******************************************************************************* @@ -369,10 +338,8 @@ void avct_bcb_chk_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_chnl_disc(tAVCT_BCB *p_bcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - L2CA_DisconnectReq(p_bcb->ch_lcid); +void avct_bcb_chnl_disc(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + L2CA_DisconnectReq(p_bcb->ch_lcid); } /******************************************************************************* @@ -386,11 +353,11 @@ void avct_bcb_chnl_disc(tAVCT_BCB *p_bcb, * Returns Nothing. * ******************************************************************************/ -void avct_bcb_bind_fail(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_BROWSE_CONN_CFM_EVT, AVCT_RESULT_FAIL, NULL); +void avct_bcb_bind_fail(UNUSED_ATTR tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + p_data->p_ccb->p_bcb = NULL; + (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), + AVCT_BROWSE_CONN_CFM_EVT, AVCT_RESULT_FAIL, + NULL); } /******************************************************************************* @@ -403,24 +370,22 @@ void avct_bcb_bind_fail(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_cong_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - uint8_t event; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - /* set event */ - event = (p_data->cong) ? AVCT_BROWSE_CONG_IND_EVT : AVCT_BROWSE_UNCONG_IND_EVT; - - /* send event to all ccbs on this lcb */ - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, p_lcb->peer_addr); - } +void avct_bcb_cong_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + uint8_t event; + tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb); + + /* set event */ + event = + (p_data->cong) ? AVCT_BROWSE_CONG_IND_EVT : AVCT_BROWSE_UNCONG_IND_EVT; + + /* send event to all ccbs on this lcb */ + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) { + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, + p_lcb->peer_addr); } - + } } /******************************************************************************* @@ -433,28 +398,27 @@ void avct_bcb_cong_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_discard_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - osi_free_and_reset((void **)&p_bcb->p_tx_msg); - - /* if control channel is up, save the message and open the browsing channel */ - if (p_data->ul_msg.p_ccb->p_lcb == NULL) - { - osi_free_and_reset((void **)&p_data->ul_msg.p_buf); - return; - } - p_bcb->p_tx_msg = p_data->ul_msg.p_buf; - - if (p_bcb->p_tx_msg) - { - p_bcb->p_tx_msg->layer_specific = (p_data->ul_msg.cr << 8) + p_data->ul_msg.label; - - /* the channel is closed, opening or closing - open it again */ - AVCT_TRACE_DEBUG("ch_state: %d, allocated:%d->%d", p_bcb->ch_state, p_bcb->allocated, - p_data->ul_msg.p_ccb->p_lcb->allocated); - p_bcb->allocated = p_data->ul_msg.p_ccb->p_lcb->allocated; - avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT *) p_data->ul_msg.p_ccb); - } +void avct_bcb_discard_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + osi_free_and_reset((void**)&p_bcb->p_tx_msg); + + /* if control channel is up, save the message and open the browsing channel */ + if (p_data->ul_msg.p_ccb->p_lcb == NULL) { + osi_free_and_reset((void**)&p_data->ul_msg.p_buf); + return; + } + p_bcb->p_tx_msg = p_data->ul_msg.p_buf; + + if (p_bcb->p_tx_msg) { + p_bcb->p_tx_msg->layer_specific = + (p_data->ul_msg.cr << 8) + p_data->ul_msg.label; + + /* the channel is closed, opening or closing - open it again */ + AVCT_TRACE_DEBUG("ch_state: %d, allocated:%d->%d", p_bcb->ch_state, + p_bcb->allocated, p_data->ul_msg.p_ccb->p_lcb->allocated); + p_bcb->allocated = p_data->ul_msg.p_ccb->p_lcb->allocated; + avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, + (tAVCT_LCB_EVT*)p_data->ul_msg.p_ccb); + } } /******************************************************************************* @@ -467,43 +431,41 @@ void avct_bcb_discard_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_send_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - uint16_t curr_msg_len; - uint8_t pkt_type = AVCT_PKT_TYPE_SINGLE; - uint8_t hdr_len; - BT_HDR *p_buf; - uint8_t *p; - - /* store msg len */ - curr_msg_len = p_data->ul_msg.p_buf->len; - - /* initialize packet type and other stuff */ - if (curr_msg_len > (p_bcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) - { - AVCT_TRACE_ERROR ("%s msg len (%d) exceeds peer mtu(%d-%d)!!", __func__, - curr_msg_len, p_bcb->peer_mtu, AVCT_HDR_LEN_SINGLE); - osi_free_and_reset((void **)&p_data->ul_msg.p_buf); - return; - } - - /* set header len */ - hdr_len = avct_lcb_pkt_type_len[pkt_type]; - p_buf = p_data->ul_msg.p_buf; - - /* set up to build header */ - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* build header */ - AVCT_BUILD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); - UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); - - p_buf->layer_specific = AVCT_DATA_BROWSE; - - /* send message to L2CAP */ - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); +void avct_bcb_send_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + uint16_t curr_msg_len; + uint8_t pkt_type = AVCT_PKT_TYPE_SINGLE; + uint8_t hdr_len; + BT_HDR* p_buf; + uint8_t* p; + + /* store msg len */ + curr_msg_len = p_data->ul_msg.p_buf->len; + + /* initialize packet type and other stuff */ + if (curr_msg_len > (p_bcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) { + AVCT_TRACE_ERROR("%s msg len (%d) exceeds peer mtu(%d-%d)!!", __func__, + curr_msg_len, p_bcb->peer_mtu, AVCT_HDR_LEN_SINGLE); + osi_free_and_reset((void**)&p_data->ul_msg.p_buf); + return; + } + + /* set header len */ + hdr_len = avct_lcb_pkt_type_len[pkt_type]; + p_buf = p_data->ul_msg.p_buf; + + /* set up to build header */ + p_buf->len += hdr_len; + p_buf->offset -= hdr_len; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* build header */ + AVCT_BUILD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); + UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); + + p_buf->layer_specific = AVCT_DATA_BROWSE; + + /* send message to L2CAP */ + L2CA_DataWrite(p_bcb->ch_lcid, p_buf); } /******************************************************************************* @@ -516,10 +478,9 @@ void avct_bcb_send_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_free_msg_ind(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - if (p_data) - osi_free_and_reset((void **)&p_data->p_buf); +void avct_bcb_free_msg_ind(UNUSED_ATTR tAVCT_BCB* p_bcb, + tAVCT_LCB_EVT* p_data) { + if (p_data) osi_free_and_reset((void**)&p_data->p_buf); } /******************************************************************************* @@ -532,73 +493,69 @@ void avct_bcb_free_msg_ind(UNUSED_ATTR tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - uint8_t *p; - uint8_t label, type, cr_ipid; - uint16_t pid; - tAVCT_CCB *p_ccb; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - if ((p_data == NULL) || (p_data->p_buf == NULL)) - { - AVCT_TRACE_WARNING("%s p_data is NULL, returning!", __func__); - return; - } - - /* this p_buf is to be reported through p_msg_cback. The layer_specific - * needs to be set properly to indicate that it is received through - * browsing channel */ - p_data->p_buf->layer_specific = AVCT_DATA_BROWSE; - - /* reassemble message; if no message available (we received a fragment) return */ - p_data->p_buf = avct_bcb_msg_asmbl(p_bcb, p_data->p_buf); - if (p_data->p_buf == NULL) - { - return; - } - - p = (uint8_t *)(p_data->p_buf + 1) + p_data->p_buf->offset; - - /* parse header byte */ - AVCT_PARSE_HDR(p, label, type, cr_ipid); - - /* check for invalid cr_ipid */ - if (cr_ipid == AVCT_CR_IPID_INVALID) - { - AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid); - osi_free_and_reset((void **)&p_data->p_buf); - return; - } - - /* parse and lookup PID */ - BE_STREAM_TO_UINT16(pid, p); - p_ccb = avct_lcb_has_pid(p_lcb, pid); - if (p_ccb) - { - /* PID found; send msg up, adjust bt hdr and call msg callback */ - p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; - p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; - (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, p_data->p_buf); - return; - } - - /* PID not found; drop message */ - AVCT_TRACE_WARNING("No ccb for PID=%x", pid); - osi_free_and_reset((void **)&p_data->p_buf); - - /* if command send reject */ - if (cr_ipid == AVCT_CMD) - { - BT_HDR *p_buf = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE); - p_buf->len = AVCT_HDR_LEN_SINGLE; - p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - AVCT_BUILD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); - UINT16_TO_BE_STREAM(p, pid); - p_buf->layer_specific = AVCT_DATA_BROWSE; - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); - } +void avct_bcb_msg_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data) { + uint8_t* p; + uint8_t label, type, cr_ipid; + uint16_t pid; + tAVCT_CCB* p_ccb; + tAVCT_LCB* p_lcb = avct_lcb_by_bcb(p_bcb); + + if ((p_data == NULL) || (p_data->p_buf == NULL)) { + AVCT_TRACE_WARNING("%s p_data is NULL, returning!", __func__); + return; + } + + /* this p_buf is to be reported through p_msg_cback. The layer_specific + * needs to be set properly to indicate that it is received through + * browsing channel */ + p_data->p_buf->layer_specific = AVCT_DATA_BROWSE; + + /* reassemble message; if no message available (we received a fragment) return + */ + p_data->p_buf = avct_bcb_msg_asmbl(p_bcb, p_data->p_buf); + if (p_data->p_buf == NULL) { + return; + } + + p = (uint8_t*)(p_data->p_buf + 1) + p_data->p_buf->offset; + + /* parse header byte */ + AVCT_PARSE_HDR(p, label, type, cr_ipid); + + /* check for invalid cr_ipid */ + if (cr_ipid == AVCT_CR_IPID_INVALID) { + AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid); + osi_free_and_reset((void**)&p_data->p_buf); + return; + } + + /* parse and lookup PID */ + BE_STREAM_TO_UINT16(pid, p); + p_ccb = avct_lcb_has_pid(p_lcb, pid); + if (p_ccb) { + /* PID found; send msg up, adjust bt hdr and call msg callback */ + p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; + p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; + (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, + p_data->p_buf); + return; + } + + /* PID not found; drop message */ + AVCT_TRACE_WARNING("No ccb for PID=%x", pid); + osi_free_and_reset((void**)&p_data->p_buf); + + /* if command send reject */ + if (cr_ipid == AVCT_CMD) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVRC_CMD_BUF_SIZE); + p_buf->len = AVCT_HDR_LEN_SINGLE; + p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + AVCT_BUILD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); + UINT16_TO_BE_STREAM(p, pid); + p_buf->layer_specific = AVCT_DATA_BROWSE; + L2CA_DataWrite(p_bcb->ch_lcid, p_buf); + } } /******************************************************************************* @@ -611,27 +568,23 @@ void avct_bcb_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avct_bcb_dealloc(tAVCT_BCB *p_bcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - - AVCT_TRACE_DEBUG("%s %d", __func__, p_bcb->allocated); - - for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) - { - /* if ccb allocated and */ - if ((p_ccb->allocated) && (p_ccb->p_bcb == p_bcb)) - { - p_ccb->p_bcb = NULL; - AVCT_TRACE_DEBUG("%s used by ccb: %d", __func__, idx); - break; - } +void avct_bcb_dealloc(tAVCT_BCB* p_bcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + + AVCT_TRACE_DEBUG("%s %d", __func__, p_bcb->allocated); + + for (int idx = 0; idx < AVCT_NUM_CONN; idx++, p_ccb++) { + /* if ccb allocated and */ + if ((p_ccb->allocated) && (p_ccb->p_bcb == p_bcb)) { + p_ccb->p_bcb = NULL; + AVCT_TRACE_DEBUG("%s used by ccb: %d", __func__, idx); + break; } + } - /* the browsing channel is down. Check if we have pending messages */ - osi_free_and_reset((void **)&p_bcb->p_tx_msg); - memset(p_bcb, 0, sizeof(tAVCT_BCB)); + /* the browsing channel is down. Check if we have pending messages */ + osi_free_and_reset((void**)&p_bcb->p_tx_msg); + memset(p_bcb, 0, sizeof(tAVCT_BCB)); } /******************************************************************************* @@ -644,16 +597,13 @@ void avct_bcb_dealloc(tAVCT_BCB *p_bcb, * Returns Nothing. * ******************************************************************************/ -void avct_close_bcb(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_BCB *p_bcb = avct_bcb_by_lcb(p_lcb); - if (p_bcb->allocated) - { - avct_bcb_event(p_bcb, AVCT_LCB_UL_UNBIND_EVT, p_data); - } +void avct_close_bcb(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + tAVCT_BCB* p_bcb = avct_bcb_by_lcb(p_lcb); + if (p_bcb->allocated) { + avct_bcb_event(p_bcb, AVCT_LCB_UL_UNBIND_EVT, p_data); + } } - /******************************************************************************* * * Function avct_lcb_by_bcb @@ -663,9 +613,8 @@ void avct_close_bcb(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns pointer to the lcb. * ******************************************************************************/ -tAVCT_LCB *avct_lcb_by_bcb(tAVCT_BCB *p_bcb) -{ - return &avct_cb.lcb[p_bcb->allocated - 1]; +tAVCT_LCB* avct_lcb_by_bcb(tAVCT_BCB* p_bcb) { + return &avct_cb.lcb[p_bcb->allocated - 1]; } /******************************************************************************* @@ -677,9 +626,8 @@ tAVCT_LCB *avct_lcb_by_bcb(tAVCT_BCB *p_bcb) * Returns pointer to the lcb. * ******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcb(tAVCT_LCB *p_lcb) -{ - return &avct_cb.bcb[p_lcb->allocated - 1]; +tAVCT_BCB* avct_bcb_by_lcb(tAVCT_LCB* p_lcb) { + return &avct_cb.bcb[p_lcb->allocated - 1]; } /******************************************************************************* @@ -692,21 +640,17 @@ tAVCT_BCB *avct_bcb_by_lcb(tAVCT_LCB *p_lcb) * Returns 0, if ccb is last, (ccb index + 1) otherwise. * ******************************************************************************/ -uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB *p_bcb, tAVCT_CCB *p_ccb_last) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - uint8_t idx = 0; - - for (int i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb != p_ccb_last) - return 0; - idx = (uint8_t)(i + 1); - } +uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB* p_bcb, tAVCT_CCB* p_ccb_last) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + uint8_t idx = 0; + + for (int i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) { + if (p_ccb != p_ccb_last) return 0; + idx = (uint8_t)(i + 1); } - return idx; + } + return idx; } /******************************************************************************* @@ -719,20 +663,17 @@ uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB *p_bcb, tAVCT_CCB *p_ccb_last) * Returns pointer to the lcb, or NULL if none found. * ******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcid(uint16_t lcid) -{ - tAVCT_BCB *p_bcb = &avct_cb.bcb[0]; - int idx; - - for (idx = 0; idx < AVCT_NUM_LINKS; idx++, p_bcb++) - { - if (p_bcb->allocated && (p_bcb->ch_lcid == lcid)) - { - return p_bcb; - } +tAVCT_BCB* avct_bcb_by_lcid(uint16_t lcid) { + tAVCT_BCB* p_bcb = &avct_cb.bcb[0]; + int idx; + + for (idx = 0; idx < AVCT_NUM_LINKS; idx++, p_bcb++) { + if (p_bcb->allocated && (p_bcb->ch_lcid == lcid)) { + return p_bcb; } + } - /* out of lcbs */ - AVCT_TRACE_WARNING("No bcb for lcid %x", lcid); - return NULL; + /* out of lcbs */ + AVCT_TRACE_WARNING("No bcb for lcid %x", lcid); + return NULL; } diff --git a/stack/avct/avct_ccb.cc b/stack/avct/avct_ccb.cc index e3362136e..2cdd85be0 100644 --- a/stack/avct/avct_ccb.cc +++ b/stack/avct/avct_ccb.cc @@ -24,10 +24,10 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" #include "avct_api.h" #include "avct_int.h" +#include "bt_target.h" +#include "bt_types.h" /******************************************************************************* * @@ -39,29 +39,25 @@ * Returns pointer to the ccb, or NULL if none could be allocated. * ******************************************************************************/ -tAVCT_CCB *avct_ccb_alloc(tAVCT_CC *p_cc) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; +tAVCT_CCB* avct_ccb_alloc(tAVCT_CC* p_cc) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (!p_ccb->allocated) - { - p_ccb->allocated = AVCT_ALOC_LCB; - memcpy(&p_ccb->cc, p_cc, sizeof(tAVCT_CC)); - AVCT_TRACE_DEBUG("avct_ccb_alloc %d", i); - break; - } + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (!p_ccb->allocated) { + p_ccb->allocated = AVCT_ALOC_LCB; + memcpy(&p_ccb->cc, p_cc, sizeof(tAVCT_CC)); + AVCT_TRACE_DEBUG("avct_ccb_alloc %d", i); + break; } + } - if (i == AVCT_NUM_CONN) - { - /* out of ccbs */ - p_ccb = NULL; - AVCT_TRACE_WARNING("Out of ccbs"); - } - return p_ccb; + if (i == AVCT_NUM_CONN) { + /* out of ccbs */ + p_ccb = NULL; + AVCT_TRACE_WARNING("Out of ccbs"); + } + return p_ccb; } /******************************************************************************* @@ -75,27 +71,25 @@ tAVCT_CCB *avct_ccb_alloc(tAVCT_CC *p_cc) * Returns void. * ******************************************************************************/ -void avct_ccb_dealloc(tAVCT_CCB *p_ccb, uint8_t event, uint16_t result, BD_ADDR bd_addr) -{ - tAVCT_CTRL_CBACK *p_cback = p_ccb->cc.p_ctrl_cback; +void avct_ccb_dealloc(tAVCT_CCB* p_ccb, uint8_t event, uint16_t result, + BD_ADDR bd_addr) { + tAVCT_CTRL_CBACK* p_cback = p_ccb->cc.p_ctrl_cback; - AVCT_TRACE_DEBUG("avct_ccb_dealloc %d", avct_ccb_to_idx(p_ccb)); + AVCT_TRACE_DEBUG("avct_ccb_dealloc %d", avct_ccb_to_idx(p_ccb)); - if(p_ccb->p_bcb == NULL) - { - memset(p_ccb, 0, sizeof(tAVCT_CCB)); - } - else - { - /* control channel is down, but the browsing channel is still connected 0 disconnect it now */ - avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); - p_ccb->p_lcb = NULL; - } + if (p_ccb->p_bcb == NULL) { + memset(p_ccb, 0, sizeof(tAVCT_CCB)); + } else { + /* control channel is down, but the browsing channel is still connected 0 + * disconnect it now */ + avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, + (tAVCT_LCB_EVT*)&p_ccb); + p_ccb->p_lcb = NULL; + } - if (event != AVCT_NO_EVT) - { - (*p_cback)(avct_ccb_to_idx(p_ccb), event, result, bd_addr); - } + if (event != AVCT_NO_EVT) { + (*p_cback)(avct_ccb_to_idx(p_ccb), event, result, bd_addr); + } } /******************************************************************************* @@ -108,10 +102,9 @@ void avct_ccb_dealloc(tAVCT_CCB *p_ccb, uint8_t event, uint16_t result, BD_ADDR * Returns Index of ccb. * ******************************************************************************/ -uint8_t avct_ccb_to_idx(tAVCT_CCB *p_ccb) -{ - /* use array arithmetic to determine index */ - return (uint8_t) (p_ccb - avct_cb.ccb); +uint8_t avct_ccb_to_idx(tAVCT_CCB* p_ccb) { + /* use array arithmetic to determine index */ + return (uint8_t)(p_ccb - avct_cb.ccb); } /******************************************************************************* @@ -124,26 +117,21 @@ uint8_t avct_ccb_to_idx(tAVCT_CCB *p_ccb) * Returns pointer to the ccb, or NULL if none found. * ******************************************************************************/ -tAVCT_CCB *avct_ccb_by_idx(uint8_t idx) -{ - tAVCT_CCB *p_ccb; +tAVCT_CCB* avct_ccb_by_idx(uint8_t idx) { + tAVCT_CCB* p_ccb; - /* verify index */ - if (idx < AVCT_NUM_CONN) - { - p_ccb = &avct_cb.ccb[idx]; + /* verify index */ + if (idx < AVCT_NUM_CONN) { + p_ccb = &avct_cb.ccb[idx]; - /* verify ccb is allocated */ - if (!p_ccb->allocated) - { - p_ccb = NULL; - AVCT_TRACE_WARNING("ccb %d not allocated", idx); - } - } - else - { - p_ccb = NULL; - AVCT_TRACE_WARNING("No ccb for idx %d", idx); + /* verify ccb is allocated */ + if (!p_ccb->allocated) { + p_ccb = NULL; + AVCT_TRACE_WARNING("ccb %d not allocated", idx); } - return p_ccb; + } else { + p_ccb = NULL; + AVCT_TRACE_WARNING("No ccb for idx %d", idx); + } + return p_ccb; } diff --git a/stack/avct/avct_defs.h b/stack/avct/avct_defs.h index 37846721a..73d4fcfbf 100644 --- a/stack/avct/avct_defs.h +++ b/stack/avct/avct_defs.h @@ -30,19 +30,19 @@ ****************************************************************************/ /* packet type */ -#define AVCT_PKT_TYPE_SINGLE 0 /* single packet */ -#define AVCT_PKT_TYPE_START 1 /* start packet */ -#define AVCT_PKT_TYPE_CONT 2 /* continue packet */ -#define AVCT_PKT_TYPE_END 3 /* end packet */ +#define AVCT_PKT_TYPE_SINGLE 0 /* single packet */ +#define AVCT_PKT_TYPE_START 1 /* start packet */ +#define AVCT_PKT_TYPE_CONT 2 /* continue packet */ +#define AVCT_PKT_TYPE_END 3 /* end packet */ /* header lengths for different packet types */ -#define AVCT_HDR_LEN_SINGLE 3 -#define AVCT_HDR_LEN_START 4 -#define AVCT_HDR_LEN_CONT 1 -#define AVCT_HDR_LEN_END 1 +#define AVCT_HDR_LEN_SINGLE 3 +#define AVCT_HDR_LEN_START 4 +#define AVCT_HDR_LEN_CONT 1 +#define AVCT_HDR_LEN_END 1 /* invalid cr+ipid value */ -#define AVCT_CR_IPID_INVALID 1 +#define AVCT_CR_IPID_INVALID 1 /***************************************************************************** * message parsing and building macros diff --git a/stack/avct/avct_int.h b/stack/avct/avct_int.h index 21f6aa0a3..5a738664b 100644 --- a/stack/avct/avct_int.h +++ b/stack/avct/avct_int.h @@ -24,11 +24,11 @@ #ifndef AVCT_INT_H #define AVCT_INT_H -#include "osi/include/fixed_queue.h" -#include "bt_common.h" #include "avct_api.h" #include "avct_defs.h" +#include "bt_common.h" #include "l2c_api.h" +#include "osi/include/fixed_queue.h" #ifdef __cplusplus extern "C" { @@ -40,107 +40,107 @@ extern "C" { /* lcb state machine events */ enum { - AVCT_LCB_UL_BIND_EVT, - AVCT_LCB_UL_UNBIND_EVT, - AVCT_LCB_UL_MSG_EVT, - AVCT_LCB_INT_CLOSE_EVT, - AVCT_LCB_LL_OPEN_EVT, - AVCT_LCB_LL_CLOSE_EVT, - AVCT_LCB_LL_MSG_EVT, - AVCT_LCB_LL_CONG_EVT + AVCT_LCB_UL_BIND_EVT, + AVCT_LCB_UL_UNBIND_EVT, + AVCT_LCB_UL_MSG_EVT, + AVCT_LCB_INT_CLOSE_EVT, + AVCT_LCB_LL_OPEN_EVT, + AVCT_LCB_LL_CLOSE_EVT, + AVCT_LCB_LL_MSG_EVT, + AVCT_LCB_LL_CONG_EVT }; - /* "states" used for L2CAP channel */ -#define AVCT_CH_IDLE 0 /* No connection */ -#define AVCT_CH_CONN 1 /* Waiting for connection confirm */ -#define AVCT_CH_CFG 2 /* Waiting for configuration complete */ -#define AVCT_CH_OPEN 3 /* Channel opened */ +#define AVCT_CH_IDLE 0 /* No connection */ +#define AVCT_CH_CONN 1 /* Waiting for connection confirm */ +#define AVCT_CH_CFG 2 /* Waiting for configuration complete */ +#define AVCT_CH_OPEN 3 /* Channel opened */ /* "no event" indicator used by ccb dealloc */ -#define AVCT_NO_EVT 0xFF +#define AVCT_NO_EVT 0xFF /***************************************************************************** * data types ****************************************************************************/ /* sub control block type - common data members for tAVCT_LCB and tAVCT_BCB */ typedef struct { - uint16_t peer_mtu; /* peer l2c mtu */ - uint16_t ch_result; /* L2CAP connection result value */ - uint16_t ch_lcid; /* L2CAP channel LCID */ - uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ - uint8_t state; /* The state machine state */ - uint8_t ch_state; /* L2CAP channel state */ - uint8_t ch_flags; /* L2CAP configuration flags */ + uint16_t peer_mtu; /* peer l2c mtu */ + uint16_t ch_result; /* L2CAP connection result value */ + uint16_t ch_lcid; /* L2CAP channel LCID */ + uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ + uint8_t state; /* The state machine state */ + uint8_t ch_state; /* L2CAP channel state */ + uint8_t ch_flags; /* L2CAP configuration flags */ } tAVCT_SCB; /* link control block type */ typedef struct { - uint16_t peer_mtu; /* peer l2c mtu */ - uint16_t ch_result; /* L2CAP connection result value */ - uint16_t ch_lcid; /* L2CAP channel LCID */ - uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ - uint8_t state; /* The state machine state */ - uint8_t ch_state; /* L2CAP channel state */ - uint8_t ch_flags; /* L2CAP configuration flags */ - BT_HDR *p_rx_msg; /* Message being reassembled */ - uint16_t conflict_lcid; /* L2CAP channel LCID */ - BD_ADDR peer_addr; /* BD address of peer */ - fixed_queue_t *tx_q; /* Transmit data buffer queue */ - bool cong; /* true, if congested */ + uint16_t peer_mtu; /* peer l2c mtu */ + uint16_t ch_result; /* L2CAP connection result value */ + uint16_t ch_lcid; /* L2CAP channel LCID */ + uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ + uint8_t state; /* The state machine state */ + uint8_t ch_state; /* L2CAP channel state */ + uint8_t ch_flags; /* L2CAP configuration flags */ + BT_HDR* p_rx_msg; /* Message being reassembled */ + uint16_t conflict_lcid; /* L2CAP channel LCID */ + BD_ADDR peer_addr; /* BD address of peer */ + fixed_queue_t* tx_q; /* Transmit data buffer queue */ + bool cong; /* true, if congested */ } tAVCT_LCB; /* browse control block type */ typedef struct { - uint16_t peer_mtu; /* peer l2c mtu */ - uint16_t ch_result; /* L2CAP connection result value */ - uint16_t ch_lcid; /* L2CAP channel LCID */ - uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ - uint8_t state; /* The state machine state */ - uint8_t ch_state; /* L2CAP channel state */ - uint8_t ch_flags; /* L2CAP configuration flags */ - BT_HDR *p_tx_msg; /* Message to be sent - in case the browsing channel is not open when MsgReg is called */ - uint8_t ch_close; /* CCB index+1, if CCB initiated channel close */ - BD_ADDR peer_addr; /* BD address of peer */ + uint16_t peer_mtu; /* peer l2c mtu */ + uint16_t ch_result; /* L2CAP connection result value */ + uint16_t ch_lcid; /* L2CAP channel LCID */ + uint8_t allocated; /* 0, not allocated. index+1, otherwise. */ + uint8_t state; /* The state machine state */ + uint8_t ch_state; /* L2CAP channel state */ + uint8_t ch_flags; /* L2CAP configuration flags */ + BT_HDR* p_tx_msg; /* Message to be sent - in case the browsing channel is not + open when MsgReg is called */ + uint8_t ch_close; /* CCB index+1, if CCB initiated channel close */ + BD_ADDR peer_addr; /* BD address of peer */ } tAVCT_BCB; -#define AVCT_ALOC_LCB 0x01 -#define AVCT_ALOC_BCB 0x02 +#define AVCT_ALOC_LCB 0x01 +#define AVCT_ALOC_BCB 0x02 /* connection control block */ typedef struct { - tAVCT_CC cc; /* parameters from connection creation */ - tAVCT_LCB *p_lcb; /* Associated LCB */ - tAVCT_BCB *p_bcb; /* associated BCB */ - bool ch_close; /* Whether CCB initiated channel close */ - uint8_t allocated; /* Whether LCB/BCB is allocated */ + tAVCT_CC cc; /* parameters from connection creation */ + tAVCT_LCB* p_lcb; /* Associated LCB */ + tAVCT_BCB* p_bcb; /* associated BCB */ + bool ch_close; /* Whether CCB initiated channel close */ + uint8_t allocated; /* Whether LCB/BCB is allocated */ } tAVCT_CCB; /* data type associated with UL_MSG_EVT */ typedef struct { - BT_HDR *p_buf; - tAVCT_CCB *p_ccb; - uint8_t label; - uint8_t cr; + BT_HDR* p_buf; + tAVCT_CCB* p_ccb; + uint8_t label; + uint8_t cr; } tAVCT_UL_MSG; /* union associated with lcb state machine events */ typedef union { - tAVCT_UL_MSG ul_msg; - BT_HDR *p_buf; - tAVCT_CCB *p_ccb; - uint16_t result; - bool cong; - uint8_t err_code; + tAVCT_UL_MSG ul_msg; + BT_HDR* p_buf; + tAVCT_CCB* p_ccb; + uint16_t result; + bool cong; + uint8_t err_code; } tAVCT_LCB_EVT; /* Control block for AVCT */ typedef struct { - tAVCT_LCB lcb[AVCT_NUM_LINKS]; /* link control blocks */ - tAVCT_BCB bcb[AVCT_NUM_LINKS]; /* browse control blocks */ - tAVCT_CCB ccb[AVCT_NUM_CONN]; /* connection control blocks */ - uint16_t mtu; /* our L2CAP MTU */ - uint16_t mtu_br; /* our L2CAP MTU for the Browsing channel */ - uint8_t trace_level; /* trace level */ + tAVCT_LCB lcb[AVCT_NUM_LINKS]; /* link control blocks */ + tAVCT_BCB bcb[AVCT_NUM_LINKS]; /* browse control blocks */ + tAVCT_CCB ccb[AVCT_NUM_CONN]; /* connection control blocks */ + uint16_t mtu; /* our L2CAP MTU */ + uint16_t mtu_br; /* our L2CAP MTU for the Browsing channel */ + uint8_t trace_level; /* trace level */ } tAVCT_CB; /***************************************************************************** @@ -148,67 +148,70 @@ typedef struct { ****************************************************************************/ /* LCB function declarations */ -extern void avct_lcb_event(tAVCT_LCB *p_lcb, uint8_t event, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_event(tAVCT_BCB *p_bcb, uint8_t event, tAVCT_LCB_EVT *p_data); -extern void avct_close_bcb(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern tAVCT_LCB *avct_lcb_by_bcb(tAVCT_BCB *p_bcb); -extern tAVCT_BCB *avct_bcb_by_lcb(tAVCT_LCB *p_lcb); -extern uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB *p_bcb, tAVCT_CCB *p_ccb_last); -extern tAVCT_BCB *avct_bcb_by_lcid(uint16_t lcid); -extern tAVCT_LCB *avct_lcb_by_bd(BD_ADDR bd_addr); -extern tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr); -extern void avct_lcb_dealloc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern tAVCT_LCB *avct_lcb_by_lcid(uint16_t lcid); -extern tAVCT_CCB *avct_lcb_has_pid(tAVCT_LCB *p_lcb, uint16_t pid); -extern bool avct_lcb_last_ccb(tAVCT_LCB *p_lcb, tAVCT_CCB *p_ccb_last); +extern void avct_lcb_event(tAVCT_LCB* p_lcb, uint8_t event, + tAVCT_LCB_EVT* p_data); +extern void avct_bcb_event(tAVCT_BCB* p_bcb, uint8_t event, + tAVCT_LCB_EVT* p_data); +extern void avct_close_bcb(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern tAVCT_LCB* avct_lcb_by_bcb(tAVCT_BCB* p_bcb); +extern tAVCT_BCB* avct_bcb_by_lcb(tAVCT_LCB* p_lcb); +extern uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB* p_bcb, + tAVCT_CCB* p_ccb_last); +extern tAVCT_BCB* avct_bcb_by_lcid(uint16_t lcid); +extern tAVCT_LCB* avct_lcb_by_bd(BD_ADDR bd_addr); +extern tAVCT_LCB* avct_lcb_alloc(BD_ADDR bd_addr); +extern void avct_lcb_dealloc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern tAVCT_LCB* avct_lcb_by_lcid(uint16_t lcid); +extern tAVCT_CCB* avct_lcb_has_pid(tAVCT_LCB* p_lcb, uint16_t pid); +extern bool avct_lcb_last_ccb(tAVCT_LCB* p_lcb, tAVCT_CCB* p_ccb_last); /* LCB action functions */ -extern void avct_lcb_chnl_open(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_unbind_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_open_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_open_fail(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_close_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_close_cfm(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_bind_conn(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_chk_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_chnl_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_bind_fail(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_cong_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_discard_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); -extern void avct_lcb_free_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data); +extern void avct_lcb_chnl_open(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_unbind_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_open_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_open_fail(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_close_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_close_cfm(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_bind_conn(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_chk_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_chnl_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_bind_fail(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_cong_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_discard_msg(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_send_msg(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_msg_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); +extern void avct_lcb_free_msg_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data); /* BCB action functions */ -typedef void (*tAVCT_BCB_ACTION)(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_chnl_open(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_unbind_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_open_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_open_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_close_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_close_cfm(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_bind_conn(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_chk_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_chnl_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_bind_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_cong_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_discard_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_send_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); -extern void avct_bcb_free_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); - -extern void avct_bcb_dealloc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data); +typedef void (*tAVCT_BCB_ACTION)(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_unbind_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_open_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_open_fail(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_close_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_close_cfm(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_bind_conn(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_chk_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_chnl_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_bind_fail(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_cong_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_discard_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_send_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_msg_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); +extern void avct_bcb_free_msg_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); + +extern void avct_bcb_dealloc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data); extern const tAVCT_BCB_ACTION avct_bcb_action[]; extern const uint8_t avct_lcb_pkt_type_len[]; extern const tL2CAP_FCR_OPTS avct_l2c_br_fcr_opts_def; /* CCB function declarations */ -extern tAVCT_CCB *avct_ccb_alloc(tAVCT_CC *p_cc); -extern void avct_ccb_dealloc(tAVCT_CCB *p_ccb, uint8_t event, uint16_t result, BD_ADDR bd_addr); -extern uint8_t avct_ccb_to_idx(tAVCT_CCB *p_ccb); -extern tAVCT_CCB *avct_ccb_by_idx(uint8_t idx); - +extern tAVCT_CCB* avct_ccb_alloc(tAVCT_CC* p_cc); +extern void avct_ccb_dealloc(tAVCT_CCB* p_ccb, uint8_t event, uint16_t result, + BD_ADDR bd_addr); +extern uint8_t avct_ccb_to_idx(tAVCT_CCB* p_ccb); +extern tAVCT_CCB* avct_ccb_by_idx(uint8_t idx); /***************************************************************************** * global data diff --git a/stack/avct/avct_l2c.cc b/stack/avct/avct_l2c.cc index cac13abe9..2ed077bb2 100644 --- a/stack/avct/avct_l2c.cc +++ b/stack/avct/avct_l2c.cc @@ -23,28 +23,29 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avct_api.h" #include "avct_int.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "l2c_api.h" #include "l2cdefs.h" #include "osi/include/osi.h" /* Configuration flags. */ -#define AVCT_L2C_CFG_IND_DONE (1<<0) -#define AVCT_L2C_CFG_CFM_DONE (1<<1) +#define AVCT_L2C_CFG_IND_DONE (1 << 0) +#define AVCT_L2C_CFG_CFM_DONE (1 << 1) /* callback function declarations */ -void avct_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); +void avct_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id); void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result); -void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); +void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result); void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); -void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf); +void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); /* L2CAP callback function structure */ const tL2CAP_APPL_INFO avct_l2c_appl = { @@ -58,7 +59,7 @@ const tL2CAP_APPL_INFO avct_l2c_appl = { NULL, avct_l2c_data_ind_cback, avct_l2c_congestion_ind_cback, - NULL /* tL2CA_TX_COMPLETE_CB */ + NULL /* tL2CA_TX_COMPLETE_CB */ }; /******************************************************************************* @@ -71,25 +72,21 @@ const tL2CAP_APPL_INFO avct_l2c_appl = { * Returns true, if the given LCB is created as AVCT_PASSIVE * ******************************************************************************/ -static bool avct_l2c_is_passive (tAVCT_LCB *p_lcb) -{ - bool is_passive = false; - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) - { - AVCT_TRACE_DEBUG("avct_l2c_is_ct control:x%x", p_ccb->cc.control); - if (p_ccb->cc.control & AVCT_PASSIVE) - { - is_passive = true; - break; - } - } +static bool avct_l2c_is_passive(tAVCT_LCB* p_lcb) { + bool is_passive = false; + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) { + AVCT_TRACE_DEBUG("avct_l2c_is_ct control:x%x", p_ccb->cc.control); + if (p_ccb->cc.control & AVCT_PASSIVE) { + is_passive = true; + break; + } } - return is_passive; + } + return is_passive; } /******************************************************************************* @@ -103,67 +100,59 @@ static bool avct_l2c_is_passive (tAVCT_LCB *p_lcb) * ******************************************************************************/ void avct_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, - UNUSED_ATTR uint16_t psm, uint8_t id) -{ - tAVCT_LCB *p_lcb; - uint16_t result = L2CAP_CONN_OK; - tL2CAP_CFG_INFO cfg; - - /* do we already have a channel for this peer? */ - p_lcb = avct_lcb_by_bd(bd_addr); - if (p_lcb == NULL) - { - /* no, allocate lcb */ - p_lcb = avct_lcb_alloc(bd_addr); - if (p_lcb == NULL) - { - /* no ccb available, reject L2CAP connection */ - result = L2CAP_CONN_NO_RESOURCES; - } - } - /* else we already have a channel for this peer */ - else - { - if (!avct_l2c_is_passive (p_lcb) || (p_lcb->ch_state == AVCT_CH_OPEN)) - { - /* this LCB included CT role - reject */ - result = L2CAP_CONN_NO_RESOURCES; - } - else - { - /* TG role only - accept the connection from CT. move the channel ID to the conflict list */ - p_lcb->conflict_lcid = p_lcb->ch_lcid; - AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback conflict_lcid:0x%x", p_lcb->conflict_lcid); - } + UNUSED_ATTR uint16_t psm, uint8_t id) { + tAVCT_LCB* p_lcb; + uint16_t result = L2CAP_CONN_OK; + tL2CAP_CFG_INFO cfg; + + /* do we already have a channel for this peer? */ + p_lcb = avct_lcb_by_bd(bd_addr); + if (p_lcb == NULL) { + /* no, allocate lcb */ + p_lcb = avct_lcb_alloc(bd_addr); + if (p_lcb == NULL) { + /* no ccb available, reject L2CAP connection */ + result = L2CAP_CONN_NO_RESOURCES; } - - if(p_lcb) - { - AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback: 0x%x, res: %d, ch_state: %d", - lcid, result, p_lcb->ch_state); + } + /* else we already have a channel for this peer */ + else { + if (!avct_l2c_is_passive(p_lcb) || (p_lcb->ch_state == AVCT_CH_OPEN)) { + /* this LCB included CT role - reject */ + result = L2CAP_CONN_NO_RESOURCES; + } else { + /* TG role only - accept the connection from CT. move the channel ID to + * the conflict list */ + p_lcb->conflict_lcid = p_lcb->ch_lcid; + AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback conflict_lcid:0x%x", + p_lcb->conflict_lcid); } - /* Send L2CAP connect rsp */ - L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store LCID */ - p_lcb->ch_lcid = lcid; - - /* transition to configuration state */ - p_lcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = avct_cb.mtu; - L2CA_ConfigReq(lcid, &cfg); - AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); - } - - if (p_lcb) - AVCT_TRACE_DEBUG("ch_state cni: %d ", p_lcb->ch_state); + } + + if (p_lcb) { + AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback: 0x%x, res: %d, ch_state: %d", + lcid, result, p_lcb->ch_state); + } + /* Send L2CAP connect rsp */ + L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); + + /* if result ok, proceed with connection */ + if (result == L2CAP_CONN_OK) { + /* store LCID */ + p_lcb->ch_lcid = lcid; + + /* transition to configuration state */ + p_lcb->ch_state = AVCT_CH_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = avct_cb.mtu; + L2CA_ConfigReq(lcid, &cfg); + AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); + } + + if (p_lcb) AVCT_TRACE_DEBUG("ch_state cni: %d ", p_lcb->ch_state); } /******************************************************************************* @@ -176,56 +165,54 @@ void avct_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, * Returns void * ******************************************************************************/ -void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVCT_LCB *p_lcb; - tL2CAP_CFG_INFO cfg; - - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback lcid:0x%x result: %d ch_state: %d, conflict_lcid:0x%x", - lcid, result, p_lcb->ch_state, p_lcb->conflict_lcid); - /* if in correct state */ - if (p_lcb->ch_state == AVCT_CH_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - /* set channel state */ - p_lcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = avct_cb.mtu; - L2CA_ConfigReq(lcid, &cfg); - AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); - } - /* else failure */ - else - { - AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback conflict_lcid:0x%x", p_lcb->conflict_lcid); - if (p_lcb->conflict_lcid == lcid) - p_lcb->conflict_lcid = 0; - else - avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } - } - else if (p_lcb->conflict_lcid == lcid) - { - /* we must be in AVCT_CH_CFG state for the ch_lcid channel */ - AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback ch_state: %d, conflict_lcid:0x%x", p_lcb->ch_state, p_lcb->conflict_lcid); - if (result == L2CAP_CONN_OK) - { - /* just in case the peer also accepts our connection - Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } - p_lcb->conflict_lcid = 0; - } - AVCT_TRACE_DEBUG("ch_state cnc: %d ", p_lcb->ch_state); +void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVCT_LCB* p_lcb; + tL2CAP_CFG_INFO cfg; + + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + AVCT_TRACE_DEBUG( + "avct_l2c_connect_cfm_cback lcid:0x%x result: %d ch_state: %d, " + "conflict_lcid:0x%x", + lcid, result, p_lcb->ch_state, p_lcb->conflict_lcid); + /* if in correct state */ + if (p_lcb->ch_state == AVCT_CH_CONN) { + /* if result successful */ + if (result == L2CAP_CONN_OK) { + /* set channel state */ + p_lcb->ch_state = AVCT_CH_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = avct_cb.mtu; + L2CA_ConfigReq(lcid, &cfg); + AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); + } + /* else failure */ + else { + AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback conflict_lcid:0x%x", + p_lcb->conflict_lcid); + if (p_lcb->conflict_lcid == lcid) + p_lcb->conflict_lcid = 0; + else + avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); + } + } else if (p_lcb->conflict_lcid == lcid) { + /* we must be in AVCT_CH_CFG state for the ch_lcid channel */ + AVCT_TRACE_DEBUG( + "avct_l2c_connect_cfm_cback ch_state: %d, conflict_lcid:0x%x", + p_lcb->ch_state, p_lcb->conflict_lcid); + if (result == L2CAP_CONN_OK) { + /* just in case the peer also accepts our connection - Send L2CAP + * disconnect req */ + L2CA_DisconnectReq(lcid); + } + p_lcb->conflict_lcid = 0; } + AVCT_TRACE_DEBUG("ch_state cnc: %d ", p_lcb->ch_state); + } } /******************************************************************************* @@ -238,45 +225,41 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_LCB *p_lcb; - - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - AVCT_TRACE_DEBUG("avct_l2c_config_cfm_cback: 0x%x, ch_state: %d, res: %d", - lcid, p_lcb->ch_state, p_cfg->result); - /* if in correct state */ - if (p_lcb->ch_state == AVCT_CH_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - /* else failure */ - else - { - AVCT_TRACE_DEBUG("ERROR avct_l2c_config_cfm_cback L2CA_DisconnectReq %d ", p_lcb->ch_state); - /* store result value */ - p_lcb->ch_result = p_cfg->result; - - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } +void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVCT_LCB* p_lcb; + + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + AVCT_TRACE_DEBUG("avct_l2c_config_cfm_cback: 0x%x, ch_state: %d, res: %d", + lcid, p_lcb->ch_state, p_cfg->result); + /* if in correct state */ + if (p_lcb->ch_state == AVCT_CH_CFG) { + /* if result successful */ + if (p_cfg->result == L2CAP_CFG_OK) { + /* update flags */ + p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; + + /* if configuration complete */ + if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) { + p_lcb->ch_state = AVCT_CH_OPEN; + avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); } - AVCT_TRACE_DEBUG("ch_state cfc: %d ", p_lcb->ch_state); + } + /* else failure */ + else { + AVCT_TRACE_DEBUG( + "ERROR avct_l2c_config_cfm_cback L2CA_DisconnectReq %d ", + p_lcb->ch_state); + /* store result value */ + p_lcb->ch_result = p_cfg->result; + + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } } + AVCT_TRACE_DEBUG("ch_state cfc: %d ", p_lcb->ch_state); + } } /******************************************************************************* @@ -289,45 +272,39 @@ void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_LCB *p_lcb; - - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - AVCT_TRACE_DEBUG("avct_l2c_config_ind_cback: 0x%x, ch_state: %d", lcid, p_lcb->ch_state); - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_lcb->peer_mtu = p_cfg->mtu; - } - else - { - p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; - } +void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVCT_LCB* p_lcb; + + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + AVCT_TRACE_DEBUG("avct_l2c_config_ind_cback: 0x%x, ch_state: %d", lcid, + p_lcb->ch_state); + /* store the mtu in tbl */ + if (p_cfg->mtu_present) { + p_lcb->peer_mtu = p_cfg->mtu; + } else { + p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; + } - /* send L2CAP configure response */ - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->result = L2CAP_CFG_OK; - L2CA_ConfigRsp(lcid, p_cfg); - - /* if first config ind */ - if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - AVCT_TRACE_DEBUG("ch_state cfi: %d ", p_lcb->ch_state); + /* send L2CAP configure response */ + memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + p_cfg->result = L2CAP_CFG_OK; + L2CA_ConfigRsp(lcid, p_cfg); + + /* if first config ind */ + if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) { + /* update flags */ + p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; + + /* if configuration complete */ + if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) { + p_lcb->ch_state = AVCT_CH_OPEN; + avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); + } } + AVCT_TRACE_DEBUG("ch_state cfi: %d ", p_lcb->ch_state); + } } /******************************************************************************* @@ -340,25 +317,23 @@ void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) -{ - tAVCT_LCB *p_lcb; - uint16_t result = AVCT_RESULT_FAIL; - - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - AVCT_TRACE_DEBUG("avct_l2c_disconnect_ind_cback: 0x%x, ch_state: %d", lcid, p_lcb->ch_state); - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - - avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - AVCT_TRACE_DEBUG("ch_state di: %d ", p_lcb->ch_state); +void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { + tAVCT_LCB* p_lcb; + uint16_t result = AVCT_RESULT_FAIL; + + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + AVCT_TRACE_DEBUG("avct_l2c_disconnect_ind_cback: 0x%x, ch_state: %d", lcid, + p_lcb->ch_state); + if (ack_needed) { + /* send L2CAP disconnect response */ + L2CA_DisconnectRsp(lcid); } + + avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); + AVCT_TRACE_DEBUG("ch_state di: %d ", p_lcb->ch_state); + } } /******************************************************************************* @@ -371,24 +346,23 @@ void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) * Returns void * ******************************************************************************/ -void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVCT_LCB *p_lcb; - uint16_t res; - - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - AVCT_TRACE_DEBUG("avct_l2c_disconnect_cfm_cback: 0x%x, ch_state: %d, res: %d", - lcid, p_lcb->ch_state, result); - /* result value may be previously stored */ - res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; - p_lcb->ch_result = 0; - - avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &res); - AVCT_TRACE_DEBUG("ch_state dc: %d ", p_lcb->ch_state); - } +void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVCT_LCB* p_lcb; + uint16_t res; + + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + AVCT_TRACE_DEBUG( + "avct_l2c_disconnect_cfm_cback: 0x%x, ch_state: %d, res: %d", lcid, + p_lcb->ch_state, result); + /* result value may be previously stored */ + res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; + p_lcb->ch_result = 0; + + avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&res); + AVCT_TRACE_DEBUG("ch_state dc: %d ", p_lcb->ch_state); + } } /******************************************************************************* @@ -401,17 +375,15 @@ void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) -{ - tAVCT_LCB *p_lcb; - - AVCT_TRACE_DEBUG("avct_l2c_congestion_ind_cback: 0x%x", lcid); - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - avct_lcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT *) &is_congested); - } +void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) { + tAVCT_LCB* p_lcb; + + AVCT_TRACE_DEBUG("avct_l2c_congestion_ind_cback: 0x%x", lcid); + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + avct_lcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT*)&is_congested); + } } /******************************************************************************* @@ -424,21 +396,17 @@ void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) * Returns void * ******************************************************************************/ -void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) -{ - tAVCT_LCB *p_lcb; - - AVCT_TRACE_DEBUG("avct_l2c_data_ind_cback: 0x%x", lcid); - /* look up lcb for this channel */ - p_lcb = avct_lcb_by_lcid(lcid); - if (p_lcb != NULL) - { - avct_lcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, (tAVCT_LCB_EVT *) &p_buf); - } - else /* prevent buffer leak */ - { - AVCT_TRACE_WARNING("ERROR -> avct_l2c_data_ind_cback drop buffer"); - osi_free(p_buf); - } +void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) { + tAVCT_LCB* p_lcb; + + AVCT_TRACE_DEBUG("avct_l2c_data_ind_cback: 0x%x", lcid); + /* look up lcb for this channel */ + p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb != NULL) { + avct_lcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, (tAVCT_LCB_EVT*)&p_buf); + } else /* prevent buffer leak */ + { + AVCT_TRACE_WARNING("ERROR -> avct_l2c_data_ind_cback drop buffer"); + osi_free(p_buf); + } } - diff --git a/stack/avct/avct_l2c_br.cc b/stack/avct/avct_l2c_br.cc index a6c326c06..45386504e 100644 --- a/stack/avct/avct_l2c_br.cc +++ b/stack/avct/avct_l2c_br.cc @@ -25,23 +25,23 @@ *****************************************************************************/ #include -#include "bt_target.h" -#include "bt_utils.h" #include "avct_api.h" #include "avct_int.h" +#include "bt_target.h" +#include "bt_utils.h" #include "l2c_api.h" #include "l2cdefs.h" #include "osi/include/osi.h" /* Configuration flags. */ -#define AVCT_L2C_CFG_IND_DONE (1<<0) -#define AVCT_L2C_CFG_CFM_DONE (1<<1) +#define AVCT_L2C_CFG_IND_DONE (1 << 0) +#define AVCT_L2C_CFG_CFM_DONE (1 << 1) /* AVCTP Browsing channel FCR Option: * Size of the transmission window when using enhanced retransmission mode. Not * used in basic and streaming modes. Range: 1 - 63 */ -#define AVCT_BR_FCR_OPT_TX_WINDOW_SIZE 10 +#define AVCT_BR_FCR_OPT_TX_WINDOW_SIZE 10 /* AVCTP Browsing channel FCR Option: * Number of transmission attempts for a single I-Frame before taking @@ -51,7 +51,7 @@ * 0 - infinite retransmissions * 1 - single transmission */ -#define AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT 20 +#define AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT 20 /* AVCTP Browsing channel FCR Option: Retransmission Timeout * The AVRCP specification set a value in the range of 300 - 2000 ms @@ -59,7 +59,7 @@ * retransmission mode. * Range: Minimum 2000 (2 secs) when supporting PBF. */ -#define AVCT_BR_FCR_OPT_RETX_TOUT 2000 +#define AVCT_BR_FCR_OPT_RETX_TOUT 2000 /* AVCTP Browsing channel FCR Option: Monitor Timeout * The AVRCP specification set a value in the range of 300 - 2000 ms @@ -67,17 +67,18 @@ * retransmission mode. * Range: Minimum 12000 (12 secs) when supporting PBF. */ -#define AVCT_BR_FCR_OPT_MONITOR_TOUT 12000 +#define AVCT_BR_FCR_OPT_MONITOR_TOUT 12000 /* callback function declarations */ -void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); +void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id); void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result); -void avct_l2c_br_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); +void avct_l2c_br_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avct_l2c_br_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avct_l2c_br_disconnect_cfm_cback(uint16_t lcid, uint16_t result); void avct_l2c_br_congestion_ind_cback(uint16_t lcid, bool is_congested); -void avct_l2c_br_data_ind_cback(uint16_t lcid, BT_HDR *p_buf); +void avct_l2c_br_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); /* L2CAP callback function structure */ const tL2CAP_APPL_INFO avct_l2c_br_appl = { @@ -91,17 +92,18 @@ const tL2CAP_APPL_INFO avct_l2c_br_appl = { NULL, avct_l2c_br_data_ind_cback, avct_l2c_br_congestion_ind_cback, - NULL /* tL2CA_TX_COMPLETE_CB */ + NULL /* tL2CA_TX_COMPLETE_CB */ }; /* Browsing channel eL2CAP default options */ const tL2CAP_FCR_OPTS avct_l2c_br_fcr_opts_def = { - L2CAP_FCR_ERTM_MODE, /* Mandatory for Browsing channel */ - AVCT_BR_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ - AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ - AVCT_BR_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ - AVCT_BR_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ - L2CAP_DEFAULT_ERM_MPS /* MPS segment size */ + L2CAP_FCR_ERTM_MODE, /* Mandatory for Browsing channel */ + AVCT_BR_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ + AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before + disconnecting */ + AVCT_BR_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ + AVCT_BR_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ + L2CAP_DEFAULT_ERM_MPS /* MPS segment size */ }; /******************************************************************************* @@ -115,62 +117,59 @@ const tL2CAP_FCR_OPTS avct_l2c_br_fcr_opts_def = { * ******************************************************************************/ void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, - UNUSED_ATTR uint16_t psm, uint8_t id) -{ - tAVCT_LCB *p_lcb; - uint16_t result = L2CAP_CONN_NO_RESOURCES; - tL2CAP_CFG_INFO cfg; - tAVCT_BCB *p_bcb; - tL2CAP_ERTM_INFO ertm_info; - - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - - p_lcb = avct_lcb_by_bd(bd_addr); - if (p_lcb != NULL) - { - /* control channel exists */ - p_bcb = avct_bcb_by_lcb(p_lcb); - memcpy(p_bcb->peer_addr, bd_addr, BD_ADDR_LEN); - - if (p_bcb->allocated == 0) - { - /* browsing channel does not exist yet and the browsing channel is registered - * - accept connection */ - p_bcb->allocated = p_lcb->allocated; /* copy the index from lcb */ - - result = L2CAP_CONN_OK; - cfg.mtu = avct_cb.mtu_br; - - cfg.fcr_present = true; - cfg.fcr = avct_l2c_br_fcr_opts_def; - } - } - /* else no control channel yet, reject */ - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = cfg.fcr.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; - ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; - - /* Send L2CAP connect rsp */ - L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, 0, &ertm_info); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store LCID */ - p_bcb->ch_lcid = lcid; - - /* transition to configuration state */ - p_bcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - L2CA_ConfigReq(lcid, &cfg); + UNUSED_ATTR uint16_t psm, uint8_t id) { + tAVCT_LCB* p_lcb; + uint16_t result = L2CAP_CONN_NO_RESOURCES; + tL2CAP_CFG_INFO cfg; + tAVCT_BCB* p_bcb; + tL2CAP_ERTM_INFO ertm_info; + + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + + p_lcb = avct_lcb_by_bd(bd_addr); + if (p_lcb != NULL) { + /* control channel exists */ + p_bcb = avct_bcb_by_lcb(p_lcb); + memcpy(p_bcb->peer_addr, bd_addr, BD_ADDR_LEN); + + if (p_bcb->allocated == 0) { + /* browsing channel does not exist yet and the browsing channel is + * registered + * - accept connection */ + p_bcb->allocated = p_lcb->allocated; /* copy the index from lcb */ + + result = L2CAP_CONN_OK; + cfg.mtu = avct_cb.mtu_br; + + cfg.fcr_present = true; + cfg.fcr = avct_l2c_br_fcr_opts_def; } + } + /* else no control channel yet, reject */ + + /* Set the FCR options: Browsing channel mandates ERTM */ + ertm_info.preferred_mode = cfg.fcr.mode; + ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; + ertm_info.user_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.user_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.fcr_rx_buf_size = BT_DEFAULT_BUFFER_SIZE; + ertm_info.fcr_tx_buf_size = BT_DEFAULT_BUFFER_SIZE; + + /* Send L2CAP connect rsp */ + L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, 0, &ertm_info); + + /* if result ok, proceed with connection */ + if (result == L2CAP_CONN_OK) { + /* store LCID */ + p_bcb->ch_lcid = lcid; + + /* transition to configuration state */ + p_bcb->ch_state = AVCT_CH_CFG; + + /* Send L2CAP config req */ + L2CA_ConfigReq(lcid, &cfg); + } } /******************************************************************************* @@ -183,37 +182,34 @@ void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, * Returns void * ******************************************************************************/ -void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVCT_BCB *p_lcb; - tL2CAP_CFG_INFO cfg; - - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if ((p_lcb == NULL) || (p_lcb->ch_state != AVCT_CH_CONN)) - return; - - if (result != L2CAP_CONN_OK) - { - /* failure */ - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - return; - } +void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVCT_BCB* p_lcb; + tL2CAP_CFG_INFO cfg; - /* result is successful */ - /* set channel state */ - p_lcb->ch_state = AVCT_CH_CFG; + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if ((p_lcb == NULL) || (p_lcb->ch_state != AVCT_CH_CONN)) return; - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + if (result != L2CAP_CONN_OK) { + /* failure */ + avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); + return; + } - cfg.mtu_present = true; - cfg.mtu = avct_cb.mtu_br; + /* result is successful */ + /* set channel state */ + p_lcb->ch_state = AVCT_CH_CFG; - cfg.fcr_present = true; - cfg.fcr = avct_l2c_br_fcr_opts_def; + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - L2CA_ConfigReq(lcid, &cfg); + cfg.mtu_present = true; + cfg.mtu = avct_cb.mtu_br; + + cfg.fcr_present = true; + cfg.fcr = avct_l2c_br_fcr_opts_def; + + L2CA_ConfigReq(lcid, &cfg); } /******************************************************************************* @@ -226,37 +222,32 @@ void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avct_l2c_br_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if ((p_lcb == NULL) || (p_lcb->ch_state != AVCT_CH_CFG)) - return; - - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - /* else failure */ - else - { - /* store result value */ - p_lcb->ch_result = p_cfg->result; - - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); +void avct_l2c_br_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVCT_BCB* p_lcb; + + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if ((p_lcb == NULL) || (p_lcb->ch_state != AVCT_CH_CFG)) return; + + /* if result successful */ + if (p_cfg->result == L2CAP_CFG_OK) { + /* update flags */ + p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; + + /* if configuration complete */ + if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) { + p_lcb->ch_state = AVCT_CH_OPEN; + avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); } + } + /* else failure */ + else { + /* store result value */ + p_lcb->ch_result = p_cfg->result; + + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } } /******************************************************************************* @@ -269,73 +260,63 @@ void avct_l2c_br_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - uint16_t max_mtu = BT_DEFAULT_BUFFER_SIZE - L2CAP_MIN_OFFSET - BT_HDR_SIZE; - - /* Don't include QoS nor flush timeout in the response since we - currently always accept these values. Note: fcr_present is left - untouched since l2cap negotiates this internally - */ - p_cfg->flush_to_present = false; - p_cfg->qos_present = false; - - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if (p_lcb == NULL) - return; - - /* store the mtu in tbl */ - p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; - if (p_cfg->mtu_present) - { - p_lcb->peer_mtu = p_cfg->mtu; - } - - if (p_lcb->peer_mtu > max_mtu) - { - p_lcb->peer_mtu = p_cfg->mtu = max_mtu; - - /* Must tell the peer what the adjusted value is */ - p_cfg->mtu_present = true; - } - else /* Don't include in the response */ - p_cfg->mtu_present = false; - - AVCT_TRACE_DEBUG ("%s peer_mtu:%d use:%d", __func__, - p_lcb->peer_mtu, max_mtu); - - if (p_lcb->peer_mtu >= AVCT_MIN_BROWSE_MTU) - p_cfg->result = L2CAP_CFG_OK; - else - { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - p_cfg->mtu_present = true; - p_cfg->mtu = AVCT_MIN_BROWSE_MTU; - } - - /* send L2CAP configure response */ - L2CA_ConfigRsp(lcid, p_cfg); - - if (p_cfg->result != L2CAP_CFG_OK) - { - return; - } - - /* if first config ind */ - if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) - { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) - { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } +void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVCT_BCB* p_lcb; + uint16_t max_mtu = BT_DEFAULT_BUFFER_SIZE - L2CAP_MIN_OFFSET - BT_HDR_SIZE; + + /* Don't include QoS nor flush timeout in the response since we + currently always accept these values. Note: fcr_present is left + untouched since l2cap negotiates this internally + */ + p_cfg->flush_to_present = false; + p_cfg->qos_present = false; + + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if (p_lcb == NULL) return; + + /* store the mtu in tbl */ + p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; + if (p_cfg->mtu_present) { + p_lcb->peer_mtu = p_cfg->mtu; + } + + if (p_lcb->peer_mtu > max_mtu) { + p_lcb->peer_mtu = p_cfg->mtu = max_mtu; + + /* Must tell the peer what the adjusted value is */ + p_cfg->mtu_present = true; + } else /* Don't include in the response */ + p_cfg->mtu_present = false; + + AVCT_TRACE_DEBUG("%s peer_mtu:%d use:%d", __func__, p_lcb->peer_mtu, max_mtu); + + if (p_lcb->peer_mtu >= AVCT_MIN_BROWSE_MTU) + p_cfg->result = L2CAP_CFG_OK; + else { + p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + p_cfg->mtu_present = true; + p_cfg->mtu = AVCT_MIN_BROWSE_MTU; + } + + /* send L2CAP configure response */ + L2CA_ConfigRsp(lcid, p_cfg); + + if (p_cfg->result != L2CAP_CFG_OK) { + return; + } + + /* if first config ind */ + if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) { + /* update flags */ + p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; + + /* if configuration complete */ + if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) { + p_lcb->ch_state = AVCT_CH_OPEN; + avct_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); } + } } /******************************************************************************* @@ -348,23 +329,20 @@ void avct_l2c_br_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avct_l2c_br_disconnect_ind_cback(uint16_t lcid, bool ack_needed) -{ - tAVCT_BCB *p_lcb; - uint16_t result = AVCT_RESULT_FAIL; - - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if (p_lcb == NULL) - return; - - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } +void avct_l2c_br_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { + tAVCT_BCB* p_lcb; + uint16_t result = AVCT_RESULT_FAIL; - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if (p_lcb == NULL) return; + + if (ack_needed) { + /* send L2CAP disconnect response */ + L2CA_DisconnectRsp(lcid); + } + + avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); } /******************************************************************************* @@ -377,21 +355,19 @@ void avct_l2c_br_disconnect_ind_cback(uint16_t lcid, bool ack_needed) * Returns void * ******************************************************************************/ -void avct_l2c_br_disconnect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVCT_BCB *p_lcb; - uint16_t res; +void avct_l2c_br_disconnect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVCT_BCB* p_lcb; + uint16_t res; - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if (p_lcb == NULL) - return; + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if (p_lcb == NULL) return; - /* result value may be previously stored */ - res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; - p_lcb->ch_result = 0; + /* result value may be previously stored */ + res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; + p_lcb->ch_result = 0; - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &res); + avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&res); } /******************************************************************************* @@ -404,16 +380,14 @@ void avct_l2c_br_disconnect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avct_l2c_br_congestion_ind_cback(uint16_t lcid, bool is_congested) -{ - tAVCT_BCB *p_lcb; +void avct_l2c_br_congestion_ind_cback(uint16_t lcid, bool is_congested) { + tAVCT_BCB* p_lcb; - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if (p_lcb == NULL) - return; + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if (p_lcb == NULL) return; - avct_bcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT *) &is_congested); + avct_bcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT*)&is_congested); } /******************************************************************************* @@ -426,20 +400,18 @@ void avct_l2c_br_congestion_ind_cback(uint16_t lcid, bool is_congested) * Returns void * ******************************************************************************/ -void avct_l2c_br_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) -{ - tAVCT_BCB *p_lcb; - tAVCT_LCB_EVT evt_data; - - /* look up lcb for this channel */ - p_lcb = avct_bcb_by_lcid(lcid); - if (p_lcb == NULL) - { - /* prevent buffer leak */ - osi_free(p_buf); - return; - } - - evt_data.p_buf = p_buf; - avct_bcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, &evt_data); +void avct_l2c_br_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) { + tAVCT_BCB* p_lcb; + tAVCT_LCB_EVT evt_data; + + /* look up lcb for this channel */ + p_lcb = avct_bcb_by_lcid(lcid); + if (p_lcb == NULL) { + /* prevent buffer leak */ + osi_free(p_buf); + return; + } + + evt_data.p_buf = p_buf; + avct_bcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, &evt_data); } diff --git a/stack/avct/avct_lcb.cc b/stack/avct/avct_lcb.cc index 2efe2bb7f..f13dc73dc 100644 --- a/stack/avct/avct_lcb.cc +++ b/stack/avct/avct_lcb.cc @@ -24,12 +24,12 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avct_api.h" #include "avct_int.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "osi/include/osi.h" /***************************************************************************** @@ -37,146 +37,118 @@ ****************************************************************************/ /* verbose state strings for trace */ -const char * const avct_lcb_st_str[] = { - "LCB_IDLE_ST", - "LCB_OPENING_ST", - "LCB_OPEN_ST", - "LCB_CLOSING_ST" -}; +const char* const avct_lcb_st_str[] = {"LCB_IDLE_ST", "LCB_OPENING_ST", + "LCB_OPEN_ST", "LCB_CLOSING_ST"}; /* verbose event strings for trace */ -const char * const avct_lcb_evt_str[] = { - "UL_BIND_EVT", - "UL_UNBIND_EVT", - "UL_MSG_EVT", - "INT_CLOSE_EVT", - "LL_OPEN_EVT", - "LL_CLOSE_EVT", - "LL_MSG_EVT", - "LL_CONG_EVT" -}; +const char* const avct_lcb_evt_str[] = { + "UL_BIND_EVT", "UL_UNBIND_EVT", "UL_MSG_EVT", "INT_CLOSE_EVT", + "LL_OPEN_EVT", "LL_CLOSE_EVT", "LL_MSG_EVT", "LL_CONG_EVT"}; /* lcb state machine states */ enum { - AVCT_LCB_IDLE_ST, - AVCT_LCB_OPENING_ST, - AVCT_LCB_OPEN_ST, - AVCT_LCB_CLOSING_ST + AVCT_LCB_IDLE_ST, + AVCT_LCB_OPENING_ST, + AVCT_LCB_OPEN_ST, + AVCT_LCB_CLOSING_ST }; /* state machine action enumeration list */ enum { - AVCT_LCB_CHNL_OPEN, - AVCT_LCB_CHNL_DISC, - AVCT_LCB_SEND_MSG, - AVCT_LCB_OPEN_IND, - AVCT_LCB_OPEN_FAIL, - AVCT_LCB_CLOSE_IND, - AVCT_LCB_CLOSE_CFM, - AVCT_LCB_MSG_IND, - AVCT_LCB_CONG_IND, - AVCT_LCB_BIND_CONN, - AVCT_LCB_BIND_FAIL, - AVCT_LCB_UNBIND_DISC, - AVCT_LCB_CHK_DISC, - AVCT_LCB_DISCARD_MSG, - AVCT_LCB_DEALLOC, - AVCT_LCB_FREE_MSG_IND, - AVCT_LCB_NUM_ACTIONS + AVCT_LCB_CHNL_OPEN, + AVCT_LCB_CHNL_DISC, + AVCT_LCB_SEND_MSG, + AVCT_LCB_OPEN_IND, + AVCT_LCB_OPEN_FAIL, + AVCT_LCB_CLOSE_IND, + AVCT_LCB_CLOSE_CFM, + AVCT_LCB_MSG_IND, + AVCT_LCB_CONG_IND, + AVCT_LCB_BIND_CONN, + AVCT_LCB_BIND_FAIL, + AVCT_LCB_UNBIND_DISC, + AVCT_LCB_CHK_DISC, + AVCT_LCB_DISCARD_MSG, + AVCT_LCB_DEALLOC, + AVCT_LCB_FREE_MSG_IND, + AVCT_LCB_NUM_ACTIONS }; -#define AVCT_LCB_IGNORE AVCT_LCB_NUM_ACTIONS +#define AVCT_LCB_IGNORE AVCT_LCB_NUM_ACTIONS /* type for action functions */ -typedef void (*tAVCT_LCB_ACTION)(tAVCT_LCB *p_ccb, tAVCT_LCB_EVT *p_data); +typedef void (*tAVCT_LCB_ACTION)(tAVCT_LCB* p_ccb, tAVCT_LCB_EVT* p_data); /* action function list */ const tAVCT_LCB_ACTION avct_lcb_action[] = { - avct_lcb_chnl_open, - avct_lcb_chnl_disc, - avct_lcb_send_msg, - avct_lcb_open_ind, - avct_lcb_open_fail, - avct_lcb_close_ind, - avct_lcb_close_cfm, - avct_lcb_msg_ind, - avct_lcb_cong_ind, - avct_lcb_bind_conn, - avct_lcb_bind_fail, - avct_lcb_unbind_disc, - avct_lcb_chk_disc, - avct_lcb_discard_msg, - avct_lcb_dealloc, - avct_lcb_free_msg_ind -}; + avct_lcb_chnl_open, avct_lcb_chnl_disc, avct_lcb_send_msg, + avct_lcb_open_ind, avct_lcb_open_fail, avct_lcb_close_ind, + avct_lcb_close_cfm, avct_lcb_msg_ind, avct_lcb_cong_ind, + avct_lcb_bind_conn, avct_lcb_bind_fail, avct_lcb_unbind_disc, + avct_lcb_chk_disc, avct_lcb_discard_msg, avct_lcb_dealloc, + avct_lcb_free_msg_ind}; /* state table information */ -#define AVCT_LCB_ACTIONS 2 /* number of actions */ -#define AVCT_LCB_NEXT_STATE 2 /* position of next state */ -#define AVCT_LCB_NUM_COLS 3 /* number of columns in state tables */ +#define AVCT_LCB_ACTIONS 2 /* number of actions */ +#define AVCT_LCB_NEXT_STATE 2 /* position of next state */ +#define AVCT_LCB_NUM_COLS 3 /* number of columns in state tables */ /* state table for idle state */ const uint8_t avct_lcb_st_idle[][AVCT_LCB_NUM_COLS] = { -/* Event Action 1 Action 2 Next state */ -/* UL_BIND */ {AVCT_LCB_CHNL_OPEN, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, -/* UL_UNBIND */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, -/* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, -/* INT_CLOSE */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, -/* LL_OPEN */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* LL_CLOSE */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, -/* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, -/* LL_CONG */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST} -}; + /* Event Action 1 Action 2 Next state */ + /* UL_BIND */ {AVCT_LCB_CHNL_OPEN, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, + /* UL_UNBIND */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, + /* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, + /* INT_CLOSE */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, + /* LL_OPEN */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* LL_CLOSE */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, + /* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, + /* LL_CONG */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}}; /* state table for opening state */ const uint8_t avct_lcb_st_opening[][AVCT_LCB_NUM_COLS] = { -/* Event Action 1 Action 2 Next state */ -/* UL_BIND */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, -/* UL_UNBIND */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, -/* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, -/* INT_CLOSE */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* LL_OPEN */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* LL_CLOSE */ {AVCT_LCB_OPEN_FAIL, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, -/* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, -/* LL_CONG */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST} -}; + /* Event Action 1 Action 2 Next state */ + /* UL_BIND */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, + /* UL_UNBIND */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, + AVCT_LCB_OPENING_ST}, + /* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, + /* INT_CLOSE */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* LL_OPEN */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* LL_CLOSE */ {AVCT_LCB_OPEN_FAIL, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, + /* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, + /* LL_CONG */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}}; /* state table for open state */ const uint8_t avct_lcb_st_open[][AVCT_LCB_NUM_COLS] = { -/* Event Action 1 Action 2 Next state */ -/* UL_BIND */ {AVCT_LCB_BIND_CONN, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* UL_UNBIND */ {AVCT_LCB_CHK_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* UL_MSG */ {AVCT_LCB_SEND_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* INT_CLOSE */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* LL_OPEN */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* LL_CLOSE */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, -/* LL_MSG */ {AVCT_LCB_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, -/* LL_CONG */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST} -}; + /* Event Action 1 Action 2 Next state */ + /* UL_BIND */ {AVCT_LCB_BIND_CONN, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* UL_UNBIND */ {AVCT_LCB_CHK_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* UL_MSG */ {AVCT_LCB_SEND_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* INT_CLOSE */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* LL_OPEN */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* LL_CLOSE */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, + /* LL_MSG */ {AVCT_LCB_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, + /* LL_CONG */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}}; /* state table for closing state */ const uint8_t avct_lcb_st_closing[][AVCT_LCB_NUM_COLS] = { -/* Event Action 1 Action 2 Next state */ -/* UL_BIND */ {AVCT_LCB_BIND_FAIL, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* UL_UNBIND */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* INT_CLOSE */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* LL_OPEN */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* LL_CLOSE */ {AVCT_LCB_CLOSE_CFM, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, -/* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, -/* LL_CONG */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST} -}; + /* Event Action 1 Action 2 Next state */ + /* UL_BIND */ {AVCT_LCB_BIND_FAIL, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* UL_UNBIND */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* UL_MSG */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* INT_CLOSE */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* LL_OPEN */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* LL_CLOSE */ {AVCT_LCB_CLOSE_CFM, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, + /* LL_MSG */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, + /* LL_CONG */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}}; /* type for state table */ typedef const uint8_t (*tAVCT_LCB_ST_TBL)[AVCT_LCB_NUM_COLS]; /* state table */ const tAVCT_LCB_ST_TBL avct_lcb_st_tbl[] = { - avct_lcb_st_idle, - avct_lcb_st_opening, - avct_lcb_st_open, - avct_lcb_st_closing -}; + avct_lcb_st_idle, avct_lcb_st_opening, avct_lcb_st_open, + avct_lcb_st_closing}; /******************************************************************************* * @@ -188,33 +160,29 @@ const tAVCT_LCB_ST_TBL avct_lcb_st_tbl[] = { * Returns Nothing. * ******************************************************************************/ -void avct_lcb_event(tAVCT_LCB *p_lcb, uint8_t event, tAVCT_LCB_EVT *p_data) -{ - tAVCT_LCB_ST_TBL state_table; - uint8_t action; - int i; - - AVCT_TRACE_EVENT("LCB lcb=%d event=%s state=%s", p_lcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_lcb->state]); - - /* look up the state table for the current state */ - state_table = avct_lcb_st_tbl[p_lcb->state]; - - /* set next state */ - p_lcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; - - /* execute action functions */ - for (i = 0; i < AVCT_LCB_ACTIONS; i++) - { - action = state_table[event][i]; - if (action != AVCT_LCB_IGNORE) - { - (*avct_lcb_action[action])(p_lcb, p_data); - } - else - { - break; - } +void avct_lcb_event(tAVCT_LCB* p_lcb, uint8_t event, tAVCT_LCB_EVT* p_data) { + tAVCT_LCB_ST_TBL state_table; + uint8_t action; + int i; + + AVCT_TRACE_EVENT("LCB lcb=%d event=%s state=%s", p_lcb->allocated, + avct_lcb_evt_str[event], avct_lcb_st_str[p_lcb->state]); + + /* look up the state table for the current state */ + state_table = avct_lcb_st_tbl[p_lcb->state]; + + /* set next state */ + p_lcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; + + /* execute action functions */ + for (i = 0; i < AVCT_LCB_ACTIONS; i++) { + action = state_table[event][i]; + if (action != AVCT_LCB_IGNORE) { + (*avct_lcb_action[action])(p_lcb, p_data); + } else { + break; } + } } /******************************************************************************* @@ -227,33 +195,29 @@ void avct_lcb_event(tAVCT_LCB *p_lcb, uint8_t event, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_bcb_event(tAVCT_BCB *p_bcb, uint8_t event, tAVCT_LCB_EVT *p_data) -{ - tAVCT_LCB_ST_TBL state_table; - uint8_t action; - int i; - - AVCT_TRACE_EVENT("BCB lcb=%d event=%s state=%s", p_bcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_bcb->state]); - - /* look up the state table for the current state */ - state_table = avct_lcb_st_tbl[p_bcb->state]; - - /* set next state */ - p_bcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; - - /* execute action functions */ - for (i = 0; i < AVCT_LCB_ACTIONS; i++) - { - action = state_table[event][i]; - if (action != AVCT_LCB_IGNORE) - { - (*avct_bcb_action[action])(p_bcb, p_data); - } - else - { - break; - } +void avct_bcb_event(tAVCT_BCB* p_bcb, uint8_t event, tAVCT_LCB_EVT* p_data) { + tAVCT_LCB_ST_TBL state_table; + uint8_t action; + int i; + + AVCT_TRACE_EVENT("BCB lcb=%d event=%s state=%s", p_bcb->allocated, + avct_lcb_evt_str[event], avct_lcb_st_str[p_bcb->state]); + + /* look up the state table for the current state */ + state_table = avct_lcb_st_tbl[p_bcb->state]; + + /* set next state */ + p_bcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; + + /* execute action functions */ + for (i = 0; i < AVCT_LCB_ACTIONS; i++) { + action = state_table[event][i]; + if (action != AVCT_LCB_IGNORE) { + (*avct_bcb_action[action])(p_bcb, p_data); + } else { + break; } + } } /******************************************************************************* @@ -266,29 +230,26 @@ void avct_bcb_event(tAVCT_BCB *p_bcb, uint8_t event, tAVCT_LCB_EVT *p_data) * Returns pointer to the lcb, or NULL if none found. * ******************************************************************************/ -tAVCT_LCB *avct_lcb_by_bd(BD_ADDR bd_addr) -{ - tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; - int i; - - for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) - { - /* if allocated lcb has matching lcb */ - if (p_lcb->allocated && (!memcmp(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN))) - { - break; - } +tAVCT_LCB* avct_lcb_by_bd(BD_ADDR bd_addr) { + tAVCT_LCB* p_lcb = &avct_cb.lcb[0]; + int i; + + for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) { + /* if allocated lcb has matching lcb */ + if (p_lcb->allocated && (!memcmp(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN))) { + break; } + } - if (i == AVCT_NUM_LINKS) - { - /* if no lcb found */ - p_lcb = NULL; + if (i == AVCT_NUM_LINKS) { + /* if no lcb found */ + p_lcb = NULL; - AVCT_TRACE_DEBUG("No lcb for addr %02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - } - return p_lcb; + AVCT_TRACE_DEBUG("No lcb for addr %02x-%02x-%02x-%02x-%02x-%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + } + return p_lcb; } /******************************************************************************* @@ -301,30 +262,26 @@ tAVCT_LCB *avct_lcb_by_bd(BD_ADDR bd_addr) * Returns pointer to the lcb, or NULL if none could be allocated. * ******************************************************************************/ -tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr) -{ - tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; - int i; - - for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) - { - if (!p_lcb->allocated) - { - p_lcb->allocated = (uint8_t)(i + 1); - memcpy(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN); - AVCT_TRACE_DEBUG("avct_lcb_alloc %d", p_lcb->allocated); - p_lcb->tx_q = fixed_queue_new(SIZE_MAX); - break; - } +tAVCT_LCB* avct_lcb_alloc(BD_ADDR bd_addr) { + tAVCT_LCB* p_lcb = &avct_cb.lcb[0]; + int i; + + for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) { + if (!p_lcb->allocated) { + p_lcb->allocated = (uint8_t)(i + 1); + memcpy(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN); + AVCT_TRACE_DEBUG("avct_lcb_alloc %d", p_lcb->allocated); + p_lcb->tx_q = fixed_queue_new(SIZE_MAX); + break; } - - if (i == AVCT_NUM_LINKS) - { - /* out of lcbs */ - p_lcb = NULL; - AVCT_TRACE_WARNING("Out of lcbs"); - } - return p_lcb; + } + + if (i == AVCT_NUM_LINKS) { + /* out of lcbs */ + p_lcb = NULL; + AVCT_TRACE_WARNING("Out of lcbs"); + } + return p_lcb; } /******************************************************************************* @@ -337,29 +294,25 @@ tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr) * Returns void. * ******************************************************************************/ -void avct_lcb_dealloc(tAVCT_LCB *p_lcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_DEBUG("%s allocated: %d", __func__, p_lcb->allocated); - - // Check if the LCB is still referenced - - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - for (size_t i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && p_ccb->p_lcb == p_lcb) - { - AVCT_TRACE_DEBUG("%s LCB in use; lcb index: %d", __func__, i); - return; - } +void avct_lcb_dealloc(tAVCT_LCB* p_lcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + AVCT_TRACE_DEBUG("%s allocated: %d", __func__, p_lcb->allocated); + + // Check if the LCB is still referenced + + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + for (size_t i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && p_ccb->p_lcb == p_lcb) { + AVCT_TRACE_DEBUG("%s LCB in use; lcb index: %d", __func__, i); + return; } + } - // If not, de-allocate now... + // If not, de-allocate now... - AVCT_TRACE_DEBUG("%s Freeing LCB", __func__); - osi_free(p_lcb->p_rx_msg); - fixed_queue_free(p_lcb->tx_q, NULL); - memset(p_lcb, 0, sizeof(tAVCT_LCB)); + AVCT_TRACE_DEBUG("%s Freeing LCB", __func__); + osi_free(p_lcb->p_rx_msg); + fixed_queue_free(p_lcb->tx_q, NULL); + memset(p_lcb, 0, sizeof(tAVCT_LCB)); } /******************************************************************************* @@ -372,27 +325,24 @@ void avct_lcb_dealloc(tAVCT_LCB *p_lcb, * Returns pointer to the lcb, or NULL if none found. * ******************************************************************************/ -tAVCT_LCB *avct_lcb_by_lcid(uint16_t lcid) -{ - tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; - int i; - - for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) - { - if (p_lcb->allocated && ((p_lcb->ch_lcid == lcid) || (p_lcb->conflict_lcid == lcid))) - { - break; - } +tAVCT_LCB* avct_lcb_by_lcid(uint16_t lcid) { + tAVCT_LCB* p_lcb = &avct_cb.lcb[0]; + int i; + + for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) { + if (p_lcb->allocated && + ((p_lcb->ch_lcid == lcid) || (p_lcb->conflict_lcid == lcid))) { + break; } + } - if (i == AVCT_NUM_LINKS) - { - /* out of lcbs */ - p_lcb = NULL; - AVCT_TRACE_WARNING("No lcb for lcid %x", lcid); - } + if (i == AVCT_NUM_LINKS) { + /* out of lcbs */ + p_lcb = NULL; + AVCT_TRACE_WARNING("No lcb for lcid %x", lcid); + } - return p_lcb; + return p_lcb; } /******************************************************************************* @@ -405,19 +355,16 @@ tAVCT_LCB *avct_lcb_by_lcid(uint16_t lcid) * Returns Pointer to CCB if PID found, NULL otherwise. * ******************************************************************************/ -tAVCT_CCB *avct_lcb_has_pid(tAVCT_LCB *p_lcb, uint16_t pid) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb->cc.pid == pid)) - { - return p_ccb; - } +tAVCT_CCB* avct_lcb_has_pid(tAVCT_LCB* p_lcb, uint16_t pid) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb->cc.pid == pid)) { + return p_ccb; } - return NULL; + } + return NULL; } /******************************************************************************* @@ -430,23 +377,18 @@ tAVCT_CCB *avct_lcb_has_pid(tAVCT_LCB *p_lcb, uint16_t pid) * Returns true if ccb is last, false otherwise. * ******************************************************************************/ -bool avct_lcb_last_ccb(tAVCT_LCB *p_lcb, tAVCT_CCB *p_ccb_last) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - AVCT_TRACE_WARNING("avct_lcb_last_ccb"); - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - AVCT_TRACE_WARNING("%x: aloc:%d, lcb:0x%x/0x%x, ccb:0x%x/0x%x", - i, p_ccb->allocated, p_ccb->p_lcb, p_lcb, p_ccb, p_ccb_last); - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb != p_ccb_last)) - { - return false; - } +bool avct_lcb_last_ccb(tAVCT_LCB* p_lcb, tAVCT_CCB* p_ccb_last) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + + AVCT_TRACE_WARNING("avct_lcb_last_ccb"); + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + AVCT_TRACE_WARNING("%x: aloc:%d, lcb:0x%x/0x%x, ccb:0x%x/0x%x", i, + p_ccb->allocated, p_ccb->p_lcb, p_lcb, p_ccb, + p_ccb_last); + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb != p_ccb_last)) { + return false; } - return true; + } + return true; } - - - diff --git a/stack/avct/avct_lcb_act.cc b/stack/avct/avct_lcb_act.cc index afb53f658..9731780b6 100644 --- a/stack/avct/avct_lcb_act.cc +++ b/stack/avct/avct_lcb_act.cc @@ -23,22 +23,19 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avct_api.h" #include "avct_int.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btm_api.h" #include "osi/include/osi.h" /* packet header length lookup table */ -const uint8_t avct_lcb_pkt_type_len[] = { - AVCT_HDR_LEN_SINGLE, - AVCT_HDR_LEN_START, - AVCT_HDR_LEN_CONT, - AVCT_HDR_LEN_END -}; +const uint8_t avct_lcb_pkt_type_len[] = {AVCT_HDR_LEN_SINGLE, + AVCT_HDR_LEN_START, AVCT_HDR_LEN_CONT, + AVCT_HDR_LEN_END}; /******************************************************************************* * @@ -51,125 +48,112 @@ const uint8_t avct_lcb_pkt_type_len[] = { * available. * ******************************************************************************/ -static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf) -{ - uint8_t *p; - uint8_t pkt_type; - BT_HDR *p_ret; - - /* parse the message header */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - pkt_type = AVCT_PKT_TYPE(p); - - /* quick sanity check on length */ - if (p_buf->len < avct_lcb_pkt_type_len[pkt_type]) - { +static BT_HDR* avct_lcb_msg_asmbl(tAVCT_LCB* p_lcb, BT_HDR* p_buf) { + uint8_t* p; + uint8_t pkt_type; + BT_HDR* p_ret; + + /* parse the message header */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + pkt_type = AVCT_PKT_TYPE(p); + + /* quick sanity check on length */ + if (p_buf->len < avct_lcb_pkt_type_len[pkt_type]) { + osi_free(p_buf); + AVCT_TRACE_WARNING("Bad length during reassembly"); + p_ret = NULL; + } + /* single packet */ + else if (pkt_type == AVCT_PKT_TYPE_SINGLE) { + /* if reassembly in progress drop message and process new single */ + if (p_lcb->p_rx_msg != NULL) + AVCT_TRACE_WARNING("Got single during reassembly"); + + osi_free_and_reset((void**)&p_lcb->p_rx_msg); + + p_ret = p_buf; + } + /* start packet */ + else if (pkt_type == AVCT_PKT_TYPE_START) { + /* if reassembly in progress drop message and process new start */ + if (p_lcb->p_rx_msg != NULL) + AVCT_TRACE_WARNING("Got start during reassembly"); + + osi_free(p_lcb->p_rx_msg); + + /* + * Allocate bigger buffer for reassembly. As lower layers are + * not aware of possible packet size after reassembly, they + * would have allocated smaller buffer. + */ + p_lcb->p_rx_msg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE); + memcpy(p_lcb->p_rx_msg, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len); + + /* Free original buffer */ + osi_free(p_buf); + + /* update p to point to new buffer */ + p = (uint8_t*)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset; + + /* copy first header byte over nosp */ + *(p + 1) = *p; + + /* set offset to point to where to copy next */ + p_lcb->p_rx_msg->offset += p_lcb->p_rx_msg->len; + + /* adjust length for packet header */ + p_lcb->p_rx_msg->len -= 1; + + p_ret = NULL; + } + /* continue or end */ + else { + /* if no reassembly in progress drop message */ + if (p_lcb->p_rx_msg == NULL) { + osi_free(p_buf); + AVCT_TRACE_WARNING("Pkt type=%d out of order", pkt_type); + p_ret = NULL; + } else { + /* get size of buffer holding assembled message */ + /* + * NOTE: The buffer is allocated above at the beginning of the + * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. + */ + uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); + + /* adjust offset and len of fragment for header byte */ + p_buf->offset += AVCT_HDR_LEN_CONT; + p_buf->len -= AVCT_HDR_LEN_CONT; + + /* verify length */ + if ((p_lcb->p_rx_msg->offset + p_buf->len) > buf_len) { + /* won't fit; free everything */ + AVCT_TRACE_WARNING("%s: Fragmented message too big!", __func__); + osi_free_and_reset((void**)&p_lcb->p_rx_msg); osi_free(p_buf); - AVCT_TRACE_WARNING("Bad length during reassembly"); - p_ret = NULL; - } - /* single packet */ - else if (pkt_type == AVCT_PKT_TYPE_SINGLE) - { - /* if reassembly in progress drop message and process new single */ - if (p_lcb->p_rx_msg != NULL) - AVCT_TRACE_WARNING("Got single during reassembly"); - - osi_free_and_reset((void **)&p_lcb->p_rx_msg); - - p_ret = p_buf; - } - /* start packet */ - else if (pkt_type == AVCT_PKT_TYPE_START) - { - /* if reassembly in progress drop message and process new start */ - if (p_lcb->p_rx_msg != NULL) - AVCT_TRACE_WARNING("Got start during reassembly"); - - osi_free(p_lcb->p_rx_msg); - - /* - * Allocate bigger buffer for reassembly. As lower layers are - * not aware of possible packet size after reassembly, they - * would have allocated smaller buffer. - */ - p_lcb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE); - memcpy(p_lcb->p_rx_msg, p_buf, - sizeof(BT_HDR) + p_buf->offset + p_buf->len); - - /* Free original buffer */ - osi_free(p_buf); - - /* update p to point to new buffer */ - p = (uint8_t *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset; - - /* copy first header byte over nosp */ - *(p + 1) = *p; - - /* set offset to point to where to copy next */ - p_lcb->p_rx_msg->offset += p_lcb->p_rx_msg->len; - - /* adjust length for packet header */ - p_lcb->p_rx_msg->len -= 1; - p_ret = NULL; - } - /* continue or end */ - else - { - /* if no reassembly in progress drop message */ - if (p_lcb->p_rx_msg == NULL) - { - osi_free(p_buf); - AVCT_TRACE_WARNING("Pkt type=%d out of order", pkt_type); - p_ret = NULL; - } - else - { - /* get size of buffer holding assembled message */ - /* - * NOTE: The buffer is allocated above at the beginning of the - * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. - */ - uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); - - /* adjust offset and len of fragment for header byte */ - p_buf->offset += AVCT_HDR_LEN_CONT; - p_buf->len -= AVCT_HDR_LEN_CONT; - - /* verify length */ - if ((p_lcb->p_rx_msg->offset + p_buf->len) > buf_len) { - /* won't fit; free everything */ - AVCT_TRACE_WARNING("%s: Fragmented message too big!", __func__); - osi_free_and_reset((void **)&p_lcb->p_rx_msg); - osi_free(p_buf); - p_ret = NULL; - } else { - /* copy contents of p_buf to p_rx_msg */ - memcpy((uint8_t *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset, - (uint8_t *)(p_buf + 1) + p_buf->offset, p_buf->len); - - if (pkt_type == AVCT_PKT_TYPE_END) - { - p_lcb->p_rx_msg->offset -= p_lcb->p_rx_msg->len; - p_lcb->p_rx_msg->len += p_buf->len; - p_ret = p_lcb->p_rx_msg; - p_lcb->p_rx_msg = NULL; - } - else - { - p_lcb->p_rx_msg->offset += p_buf->len; - p_lcb->p_rx_msg->len += p_buf->len; - p_ret = NULL; - } - osi_free(p_buf); - } + } else { + /* copy contents of p_buf to p_rx_msg */ + memcpy((uint8_t*)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset, + (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len); + + if (pkt_type == AVCT_PKT_TYPE_END) { + p_lcb->p_rx_msg->offset -= p_lcb->p_rx_msg->len; + p_lcb->p_rx_msg->len += p_buf->len; + p_ret = p_lcb->p_rx_msg; + p_lcb->p_rx_msg = NULL; + } else { + p_lcb->p_rx_msg->offset += p_buf->len; + p_lcb->p_rx_msg->len += p_buf->len; + p_ret = NULL; } + osi_free(p_buf); + } } - return p_ret; + } + return p_ret; } - /******************************************************************************* * * Function avct_lcb_chnl_open @@ -180,20 +164,17 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_chnl_open(tAVCT_LCB *p_lcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - uint16_t result = AVCT_RESULT_FAIL; - - BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP, 0); - /* call l2cap connect req */ - p_lcb->ch_state = AVCT_CH_CONN; - p_lcb->ch_lcid = L2CA_ConnectReq(AVCT_PSM, p_lcb->peer_addr); - if (p_lcb->ch_lcid == 0) - { - /* if connect req failed, send ourselves close event */ - avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } +void avct_lcb_chnl_open(tAVCT_LCB* p_lcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + uint16_t result = AVCT_RESULT_FAIL; + + BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP, 0); + /* call l2cap connect req */ + p_lcb->ch_state = AVCT_CH_CONN; + p_lcb->ch_lcid = L2CA_ConnectReq(AVCT_PSM, p_lcb->peer_addr); + if (p_lcb->ch_lcid == 0) { + /* if connect req failed, send ourselves close event */ + avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT*)&result); + } } /******************************************************************************* @@ -206,9 +187,8 @@ void avct_lcb_chnl_open(tAVCT_LCB *p_lcb, * Returns Nothing. * ******************************************************************************/ -void avct_lcb_unbind_disc(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - avct_ccb_dealloc(p_data->p_ccb, AVCT_DISCONNECT_CFM_EVT, 0, NULL); +void avct_lcb_unbind_disc(UNUSED_ATTR tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + avct_ccb_dealloc(p_data->p_ccb, AVCT_DISCONNECT_CFM_EVT, 0, NULL); } /******************************************************************************* @@ -224,44 +204,38 @@ void avct_lcb_unbind_disc(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_open_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - bool bind = false; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - /* if bound to this lcb send connect confirm event */ - if (p_ccb->p_lcb == p_lcb) - { - bind = true; - L2CA_SetTxPriority(p_lcb->ch_lcid, L2CAP_CHNL_PRIORITY_HIGH); - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_CONNECT_CFM_EVT, - 0, p_lcb->peer_addr); - } - /* if unbound acceptor and lcb doesn't already have a ccb for this PID */ - else if ((p_ccb->p_lcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && - (avct_lcb_has_pid(p_lcb, p_ccb->cc.pid) == NULL)) - { - /* bind ccb to lcb and send connect ind event */ - bind = true; - p_ccb->p_lcb = p_lcb; - L2CA_SetTxPriority(p_lcb->ch_lcid, L2CAP_CHNL_PRIORITY_HIGH); - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_CONNECT_IND_EVT, - 0, p_lcb->peer_addr); - } - } +void avct_lcb_open_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + bool bind = false; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + /* if ccb allocated and */ + if (p_ccb->allocated) { + /* if bound to this lcb send connect confirm event */ + if (p_ccb->p_lcb == p_lcb) { + bind = true; + L2CA_SetTxPriority(p_lcb->ch_lcid, L2CAP_CHNL_PRIORITY_HIGH); + p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_CONNECT_CFM_EVT, 0, + p_lcb->peer_addr); + } + /* if unbound acceptor and lcb doesn't already have a ccb for this PID */ + else if ((p_ccb->p_lcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && + (avct_lcb_has_pid(p_lcb, p_ccb->cc.pid) == NULL)) { + /* bind ccb to lcb and send connect ind event */ + bind = true; + p_ccb->p_lcb = p_lcb; + L2CA_SetTxPriority(p_lcb->ch_lcid, L2CAP_CHNL_PRIORITY_HIGH); + p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_CONNECT_IND_EVT, 0, + p_lcb->peer_addr); + } } + } - /* if no ccbs bound to this lcb, disconnect */ - if (bind == false) - { - avct_lcb_event(p_lcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } + /* if no ccbs bound to this lcb, disconnect */ + if (bind == false) { + avct_lcb_event(p_lcb, AVCT_LCB_INT_CLOSE_EVT, p_data); + } } /******************************************************************************* @@ -275,19 +249,16 @@ void avct_lcb_open_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_open_fail(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) - { - avct_ccb_dealloc(p_ccb, AVCT_CONNECT_CFM_EVT, - p_data->result, p_lcb->peer_addr); - } +void avct_lcb_open_fail(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) { + avct_ccb_dealloc(p_ccb, AVCT_CONNECT_CFM_EVT, p_data->result, + p_lcb->peer_addr); } + } } /******************************************************************************* @@ -301,29 +272,21 @@ void avct_lcb_open_fail(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_close_ind(tAVCT_LCB *p_lcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) - { - if (p_ccb->cc.role == AVCT_INT) - { - avct_ccb_dealloc(p_ccb, AVCT_DISCONNECT_IND_EVT, - 0, p_lcb->peer_addr); - } - else - { - p_ccb->p_lcb = NULL; - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_DISCONNECT_IND_EVT, - 0, p_lcb->peer_addr); - } - } +void avct_lcb_close_ind(tAVCT_LCB* p_lcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) { + if (p_ccb->cc.role == AVCT_INT) { + avct_ccb_dealloc(p_ccb, AVCT_DISCONNECT_IND_EVT, 0, p_lcb->peer_addr); + } else { + p_ccb->p_lcb = NULL; + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), + AVCT_DISCONNECT_IND_EVT, 0, p_lcb->peer_addr); + } } + } } /******************************************************************************* @@ -337,39 +300,30 @@ void avct_lcb_close_ind(tAVCT_LCB *p_lcb, * Returns Nothing. * ******************************************************************************/ -void avct_lcb_close_cfm(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - uint8_t event; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) - { - /* if this ccb initiated close send disconnect cfm otherwise ind */ - if (p_ccb->ch_close) - { - p_ccb->ch_close = false; - event = AVCT_DISCONNECT_CFM_EVT; - } - else - { - event = AVCT_DISCONNECT_IND_EVT; - } - - if (p_ccb->cc.role == AVCT_INT) - { - avct_ccb_dealloc(p_ccb, event, p_data->result, p_lcb->peer_addr); - } - else - { - p_ccb->p_lcb = NULL; - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, - p_data->result, p_lcb->peer_addr); - } - } +void avct_lcb_close_cfm(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + uint8_t event; + + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) { + /* if this ccb initiated close send disconnect cfm otherwise ind */ + if (p_ccb->ch_close) { + p_ccb->ch_close = false; + event = AVCT_DISCONNECT_CFM_EVT; + } else { + event = AVCT_DISCONNECT_IND_EVT; + } + + if (p_ccb->cc.role == AVCT_INT) { + avct_ccb_dealloc(p_ccb, event, p_data->result, p_lcb->peer_addr); + } else { + p_ccb->p_lcb = NULL; + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, p_data->result, + p_lcb->peer_addr); + } } + } } /******************************************************************************* @@ -382,11 +336,10 @@ void avct_lcb_close_cfm(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_bind_conn(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_lcb = p_lcb; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_CONNECT_CFM_EVT, 0, p_lcb->peer_addr); +void avct_lcb_bind_conn(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + p_data->p_ccb->p_lcb = p_lcb; + (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), + AVCT_CONNECT_CFM_EVT, 0, p_lcb->peer_addr); } /******************************************************************************* @@ -401,22 +354,18 @@ void avct_lcb_bind_conn(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_chk_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING("%s", __func__); - - avct_close_bcb(p_lcb, p_data); - if (avct_lcb_last_ccb(p_lcb, p_data->p_ccb)) - { - AVCT_TRACE_WARNING("%s: closing", __func__); - p_data->p_ccb->ch_close = true; - avct_lcb_event(p_lcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } - else - { - AVCT_TRACE_WARNING("%s: dealloc ccb", __func__); - avct_lcb_unbind_disc(p_lcb, p_data); - } +void avct_lcb_chk_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + AVCT_TRACE_WARNING("%s", __func__); + + avct_close_bcb(p_lcb, p_data); + if (avct_lcb_last_ccb(p_lcb, p_data->p_ccb)) { + AVCT_TRACE_WARNING("%s: closing", __func__); + p_data->p_ccb->ch_close = true; + avct_lcb_event(p_lcb, AVCT_LCB_INT_CLOSE_EVT, p_data); + } else { + AVCT_TRACE_WARNING("%s: dealloc ccb", __func__); + avct_lcb_unbind_disc(p_lcb, p_data); + } } /******************************************************************************* @@ -429,10 +378,8 @@ void avct_lcb_chk_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_chnl_disc(tAVCT_LCB *p_lcb, - UNUSED_ATTR tAVCT_LCB_EVT *p_data) -{ - L2CA_DisconnectReq(p_lcb->ch_lcid); +void avct_lcb_chnl_disc(tAVCT_LCB* p_lcb, UNUSED_ATTR tAVCT_LCB_EVT* p_data) { + L2CA_DisconnectReq(p_lcb->ch_lcid); } /******************************************************************************* @@ -446,9 +393,8 @@ void avct_lcb_chnl_disc(tAVCT_LCB *p_lcb, * Returns Nothing. * ******************************************************************************/ -void avct_lcb_bind_fail(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - avct_ccb_dealloc(p_data->p_ccb, AVCT_CONNECT_CFM_EVT, AVCT_RESULT_FAIL, NULL); +void avct_lcb_bind_fail(UNUSED_ATTR tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + avct_ccb_dealloc(p_data->p_ccb, AVCT_CONNECT_CFM_EVT, AVCT_RESULT_FAIL, NULL); } /******************************************************************************* @@ -461,36 +407,31 @@ void avct_lcb_bind_fail(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_cong_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - uint8_t event; - BT_HDR *p_buf; - - /* set event */ - event = (p_data->cong) ? AVCT_CONG_IND_EVT : AVCT_UNCONG_IND_EVT; - p_lcb->cong = p_data->cong; - if (p_lcb->cong == false && !fixed_queue_is_empty(p_lcb->tx_q)) - { - while (!p_lcb->cong && - (p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_lcb->tx_q)) != NULL) - { - if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) - { - p_lcb->cong = true; - } - } +void avct_lcb_cong_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + tAVCT_CCB* p_ccb = &avct_cb.ccb[0]; + int i; + uint8_t event; + BT_HDR* p_buf; + + /* set event */ + event = (p_data->cong) ? AVCT_CONG_IND_EVT : AVCT_UNCONG_IND_EVT; + p_lcb->cong = p_data->cong; + if (p_lcb->cong == false && !fixed_queue_is_empty(p_lcb->tx_q)) { + while (!p_lcb->cong && + (p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_lcb->tx_q)) != NULL) { + if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) { + p_lcb->cong = true; + } } + } - /* send event to all ccbs on this lcb */ - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, p_lcb->peer_addr); - } + /* send event to all ccbs on this lcb */ + for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) { + if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb)) { + (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, + p_lcb->peer_addr); } + } } /******************************************************************************* @@ -503,10 +444,9 @@ void avct_lcb_cong_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_discard_msg(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING("%s Dropping message", __func__); - osi_free_and_reset((void **)&p_data->ul_msg.p_buf); +void avct_lcb_discard_msg(UNUSED_ATTR tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + AVCT_TRACE_WARNING("%s Dropping message", __func__); + osi_free_and_reset((void**)&p_data->ul_msg.p_buf); } /******************************************************************************* @@ -519,107 +459,93 @@ void avct_lcb_discard_msg(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - uint16_t curr_msg_len; - uint8_t pkt_type; - uint8_t hdr_len; - uint8_t *p; - uint8_t nosp = 0; /* number of subsequent packets */ - uint16_t temp; - uint16_t buf_size = p_lcb->peer_mtu + L2CAP_MIN_OFFSET + BT_HDR_SIZE; - - - /* store msg len */ - curr_msg_len = p_data->ul_msg.p_buf->len; - - /* initialize packet type and other stuff */ - if (curr_msg_len <= (p_lcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) - { - pkt_type = AVCT_PKT_TYPE_SINGLE; - } - else - { - pkt_type = AVCT_PKT_TYPE_START; - temp = (curr_msg_len + AVCT_HDR_LEN_START - p_lcb->peer_mtu); - nosp = temp / (p_lcb->peer_mtu - 1) + 1; - if ( (temp % (p_lcb->peer_mtu - 1)) != 0) - nosp++; +void avct_lcb_send_msg(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + uint16_t curr_msg_len; + uint8_t pkt_type; + uint8_t hdr_len; + uint8_t* p; + uint8_t nosp = 0; /* number of subsequent packets */ + uint16_t temp; + uint16_t buf_size = p_lcb->peer_mtu + L2CAP_MIN_OFFSET + BT_HDR_SIZE; + + /* store msg len */ + curr_msg_len = p_data->ul_msg.p_buf->len; + + /* initialize packet type and other stuff */ + if (curr_msg_len <= (p_lcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) { + pkt_type = AVCT_PKT_TYPE_SINGLE; + } else { + pkt_type = AVCT_PKT_TYPE_START; + temp = (curr_msg_len + AVCT_HDR_LEN_START - p_lcb->peer_mtu); + nosp = temp / (p_lcb->peer_mtu - 1) + 1; + if ((temp % (p_lcb->peer_mtu - 1)) != 0) nosp++; + } + + /* while we haven't sent all packets */ + while (curr_msg_len != 0) { + BT_HDR* p_buf; + + /* set header len */ + hdr_len = avct_lcb_pkt_type_len[pkt_type]; + + /* if remaining msg must be fragmented */ + if (p_data->ul_msg.p_buf->len > (p_lcb->peer_mtu - hdr_len)) { + /* get a new buffer for fragment we are sending */ + p_buf = (BT_HDR*)osi_malloc(buf_size); + + /* copy portion of data from current message to new buffer */ + p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; + p_buf->len = p_lcb->peer_mtu - hdr_len; + + memcpy( + (uint8_t*)(p_buf + 1) + p_buf->offset, + (uint8_t*)(p_data->ul_msg.p_buf + 1) + p_data->ul_msg.p_buf->offset, + p_buf->len); + + p_data->ul_msg.p_buf->offset += p_buf->len; + p_data->ul_msg.p_buf->len -= p_buf->len; + } else { + p_buf = p_data->ul_msg.p_buf; } - /* while we haven't sent all packets */ - while (curr_msg_len != 0) { - BT_HDR *p_buf; - - /* set header len */ - hdr_len = avct_lcb_pkt_type_len[pkt_type]; - - /* if remaining msg must be fragmented */ - if (p_data->ul_msg.p_buf->len > (p_lcb->peer_mtu - hdr_len)) - { - /* get a new buffer for fragment we are sending */ - p_buf = (BT_HDR *)osi_malloc(buf_size); + curr_msg_len -= p_buf->len; - /* copy portion of data from current message to new buffer */ - p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; - p_buf->len = p_lcb->peer_mtu - hdr_len; - - memcpy((uint8_t *)(p_buf + 1) + p_buf->offset, - (uint8_t *)(p_data->ul_msg.p_buf + 1) + p_data->ul_msg.p_buf->offset, p_buf->len); - - p_data->ul_msg.p_buf->offset += p_buf->len; - p_data->ul_msg.p_buf->len -= p_buf->len; - } - else - { - p_buf = p_data->ul_msg.p_buf; - } + /* set up to build header */ + p_buf->len += hdr_len; + p_buf->offset -= hdr_len; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; - curr_msg_len -= p_buf->len; - - /* set up to build header */ - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* build header */ - AVCT_BUILD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); - if (pkt_type == AVCT_PKT_TYPE_START) - { - UINT8_TO_STREAM(p, nosp); - } - if ((pkt_type == AVCT_PKT_TYPE_START) || (pkt_type == AVCT_PKT_TYPE_SINGLE)) - { - UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); - } + /* build header */ + AVCT_BUILD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); + if (pkt_type == AVCT_PKT_TYPE_START) { + UINT8_TO_STREAM(p, nosp); + } + if ((pkt_type == AVCT_PKT_TYPE_START) || + (pkt_type == AVCT_PKT_TYPE_SINGLE)) { + UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); + } - if (p_lcb->cong == true) - { - fixed_queue_enqueue(p_lcb->tx_q, p_buf); - } + if (p_lcb->cong == true) { + fixed_queue_enqueue(p_lcb->tx_q, p_buf); + } - /* send message to L2CAP */ - else - { - if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) - { - p_lcb->cong = true; - } - } + /* send message to L2CAP */ + else { + if (L2CA_DataWrite(p_lcb->ch_lcid, p_buf) == L2CAP_DW_CONGESTED) { + p_lcb->cong = true; + } + } - /* update pkt type for next packet */ - if (curr_msg_len > (p_lcb->peer_mtu - AVCT_HDR_LEN_END)) - { - pkt_type = AVCT_PKT_TYPE_CONT; - } - else - { - pkt_type = AVCT_PKT_TYPE_END; - } + /* update pkt type for next packet */ + if (curr_msg_len > (p_lcb->peer_mtu - AVCT_HDR_LEN_END)) { + pkt_type = AVCT_PKT_TYPE_CONT; + } else { + pkt_type = AVCT_PKT_TYPE_END; } - AVCT_TRACE_DEBUG ("%s tx_q_count:%d", __func__, - fixed_queue_length(p_lcb->tx_q)); - return; + } + AVCT_TRACE_DEBUG("%s tx_q_count:%d", __func__, + fixed_queue_length(p_lcb->tx_q)); + return; } /******************************************************************************* @@ -632,12 +558,11 @@ void avct_lcb_send_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_free_msg_ind(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - if (p_data == NULL) - return; +void avct_lcb_free_msg_ind(UNUSED_ATTR tAVCT_LCB* p_lcb, + tAVCT_LCB_EVT* p_data) { + if (p_data == NULL) return; - osi_free_and_reset((void **)&p_data->p_buf); + osi_free_and_reset((void**)&p_data->p_buf); } /******************************************************************************* @@ -650,63 +575,60 @@ void avct_lcb_free_msg_ind(UNUSED_ATTR tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - uint8_t *p; - uint8_t label, type, cr_ipid; - uint16_t pid; - tAVCT_CCB *p_ccb; - - /* this p_buf is to be reported through p_msg_cback. The layer_specific - * needs to be set properly to indicate that it is received through - * control channel */ - p_data->p_buf->layer_specific = AVCT_DATA_CTRL; - - /* reassemble message; if no message available (we received a fragment) return */ - p_data->p_buf = avct_lcb_msg_asmbl(p_lcb, p_data->p_buf); - if (p_data->p_buf == NULL) - { - return; - } - - p = (uint8_t *)(p_data->p_buf + 1) + p_data->p_buf->offset; - - /* parse header byte */ - AVCT_PARSE_HDR(p, label, type, cr_ipid); +void avct_lcb_msg_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data) { + uint8_t* p; + uint8_t label, type, cr_ipid; + uint16_t pid; + tAVCT_CCB* p_ccb; + + /* this p_buf is to be reported through p_msg_cback. The layer_specific + * needs to be set properly to indicate that it is received through + * control channel */ + p_data->p_buf->layer_specific = AVCT_DATA_CTRL; + + /* reassemble message; if no message available (we received a fragment) return + */ + p_data->p_buf = avct_lcb_msg_asmbl(p_lcb, p_data->p_buf); + if (p_data->p_buf == NULL) { + return; + } - /* check for invalid cr_ipid */ - if (cr_ipid == AVCT_CR_IPID_INVALID) - { - AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid); - osi_free_and_reset((void **)&p_data->p_buf); - return; - } + p = (uint8_t*)(p_data->p_buf + 1) + p_data->p_buf->offset; - /* parse and lookup PID */ - BE_STREAM_TO_UINT16(pid, p); - p_ccb = avct_lcb_has_pid(p_lcb, pid); - if (p_ccb) - { - /* PID found; send msg up, adjust bt hdr and call msg callback */ - p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; - p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; - (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, p_data->p_buf); - return; - } + /* parse header byte */ + AVCT_PARSE_HDR(p, label, type, cr_ipid); - /* PID not found; drop message */ - AVCT_TRACE_WARNING("No ccb for PID=%x", pid); - osi_free_and_reset((void **)&p_data->p_buf); - - /* if command send reject */ - if (cr_ipid == AVCT_CMD) - { - BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVCT_CMD_BUF_SIZE); - p_buf->len = AVCT_HDR_LEN_SINGLE; - p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - AVCT_BUILD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); - UINT16_TO_BE_STREAM(p, pid); - L2CA_DataWrite(p_lcb->ch_lcid, p_buf); - } + /* check for invalid cr_ipid */ + if (cr_ipid == AVCT_CR_IPID_INVALID) { + AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid); + osi_free_and_reset((void**)&p_data->p_buf); + return; + } + + /* parse and lookup PID */ + BE_STREAM_TO_UINT16(pid, p); + p_ccb = avct_lcb_has_pid(p_lcb, pid); + if (p_ccb) { + /* PID found; send msg up, adjust bt hdr and call msg callback */ + p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; + p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; + (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, + p_data->p_buf); + return; + } + + /* PID not found; drop message */ + AVCT_TRACE_WARNING("No ccb for PID=%x", pid); + osi_free_and_reset((void**)&p_data->p_buf); + + /* if command send reject */ + if (cr_ipid == AVCT_CMD) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVCT_CMD_BUF_SIZE); + p_buf->len = AVCT_HDR_LEN_SINGLE; + p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + AVCT_BUILD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); + UINT16_TO_BE_STREAM(p, pid); + L2CA_DataWrite(p_lcb->ch_lcid, p_buf); + } } diff --git a/stack/avdt/avdt_ad.cc b/stack/avdt/avdt_ad.cc index cebc5e92e..5abf69543 100644 --- a/stack/avdt/avdt_ad.cc +++ b/stack/avdt/avdt_ad.cc @@ -25,17 +25,16 @@ #include #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "l2c_api.h" #include "l2cdefs.h" #include "osi/include/osi.h" - /******************************************************************************* * * Function avdt_ad_type_to_tcid @@ -46,22 +45,19 @@ * Returns TCID value. * ******************************************************************************/ -uint8_t avdt_ad_type_to_tcid(uint8_t type, tAVDT_SCB *p_scb) -{ - uint8_t scb_idx; - - if (type == AVDT_CHAN_SIG) - { - return 0; - } - else - { - scb_idx = avdt_scb_to_hdl(p_scb) - 1; - /* - AVDT_TRACE_DEBUG("type: %d, tcid: %d", type, ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type)); - */ - return ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type); - } +uint8_t avdt_ad_type_to_tcid(uint8_t type, tAVDT_SCB* p_scb) { + uint8_t scb_idx; + + if (type == AVDT_CHAN_SIG) { + return 0; + } else { + scb_idx = avdt_scb_to_hdl(p_scb) - 1; + /* + AVDT_TRACE_DEBUG("type: %d, tcid: %d", type, ((scb_idx * + (AVDT_CHAN_NUM_TYPES - 1)) + type)); + */ + return ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type); + } } /******************************************************************************* @@ -74,28 +70,23 @@ uint8_t avdt_ad_type_to_tcid(uint8_t type, tAVDT_SCB *p_scb) * Returns Channel type value. * ******************************************************************************/ -static uint8_t avdt_ad_tcid_to_type(uint8_t tcid) -{ - uint8_t type; - - if (tcid == 0) - { - type = AVDT_CHAN_SIG; - } - else - { - /* tcid translates to type based on number of channels, as follows: - ** only media channel : tcid=1,2,3,4,5,6... type=1,1,1,1,1,1... - ** media and report : tcid=1,2,3,4,5,6... type=1,2,1,2,1,2... - ** media, report, recov : tcid=1,2,3,4,5,6... type=1,2,3,1,2,3... - */ - type = ((tcid + AVDT_CHAN_NUM_TYPES - 2) % (AVDT_CHAN_NUM_TYPES - 1)) + 1; - } - AVDT_TRACE_DEBUG("tcid: %d, type: %d", tcid, type); - return type; +static uint8_t avdt_ad_tcid_to_type(uint8_t tcid) { + uint8_t type; + + if (tcid == 0) { + type = AVDT_CHAN_SIG; + } else { + /* tcid translates to type based on number of channels, as follows: + ** only media channel : tcid=1,2,3,4,5,6... type=1,1,1,1,1,1... + ** media and report : tcid=1,2,3,4,5,6... type=1,2,1,2,1,2... + ** media, report, recov : tcid=1,2,3,4,5,6... type=1,2,3,1,2,3... + */ + type = ((tcid + AVDT_CHAN_NUM_TYPES - 2) % (AVDT_CHAN_NUM_TYPES - 1)) + 1; + } + AVDT_TRACE_DEBUG("tcid: %d, type: %d", tcid, type); + return type; } - /******************************************************************************* * * Function avdt_ad_init @@ -106,19 +97,16 @@ static uint8_t avdt_ad_tcid_to_type(uint8_t tcid) * Returns Nothing. * ******************************************************************************/ -void avdt_ad_init(void) -{ - int i; - tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; - memset(&avdt_cb.ad, 0, sizeof(tAVDT_AD)); - - /* make sure the peer_mtu is a valid value */ - for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) - { - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - } -} +void avdt_ad_init(void) { + int i; + tAVDT_TC_TBL* p_tbl = avdt_cb.ad.tc_tbl; + memset(&avdt_cb.ad, 0, sizeof(tAVDT_AD)); + /* make sure the peer_mtu is a valid value */ + for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) { + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + } +} /******************************************************************************* * @@ -133,64 +121,48 @@ void avdt_ad_init(void) * first matching entry (there could be more than one). * ******************************************************************************/ -tAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(uint8_t type, tAVDT_CCB *p_ccb, uint8_t state) -{ - int i; - tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; - uint8_t ccb_idx; - - if (p_ccb == NULL) - { - /* resending security req */ - for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) - { - /* must be AVDT_CHAN_SIG - tcid always zero */ - if ((p_tbl->tcid == 0) && - (p_tbl->state == state)) - { - break; - } - } +tAVDT_TC_TBL* avdt_ad_tc_tbl_by_st(uint8_t type, tAVDT_CCB* p_ccb, + uint8_t state) { + int i; + tAVDT_TC_TBL* p_tbl = avdt_cb.ad.tc_tbl; + uint8_t ccb_idx; + + if (p_ccb == NULL) { + /* resending security req */ + for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) { + /* must be AVDT_CHAN_SIG - tcid always zero */ + if ((p_tbl->tcid == 0) && (p_tbl->state == state)) { + break; + } } - else - { - ccb_idx = avdt_ccb_to_idx(p_ccb); - - for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) - { - if (type == AVDT_CHAN_SIG) - { - /* if control channel, tcid always zero */ - if ((p_tbl->tcid == 0) && - (p_tbl->ccb_idx == ccb_idx) && - (p_tbl->state == state)) - { - break; - } - } - else - { - /* if other channel, tcid is always > zero */ - if ((p_tbl->tcid > 0) && - (p_tbl->ccb_idx == ccb_idx) && - (p_tbl->state == state)) - { - break; - } - } + } else { + ccb_idx = avdt_ccb_to_idx(p_ccb); + + for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) { + if (type == AVDT_CHAN_SIG) { + /* if control channel, tcid always zero */ + if ((p_tbl->tcid == 0) && (p_tbl->ccb_idx == ccb_idx) && + (p_tbl->state == state)) { + break; + } + } else { + /* if other channel, tcid is always > zero */ + if ((p_tbl->tcid > 0) && (p_tbl->ccb_idx == ccb_idx) && + (p_tbl->state == state)) { + break; } + } } + } - /* if nothing found return null */ - if (i == AVDT_NUM_TC_TBL) - { - p_tbl = NULL; - } + /* if nothing found return null */ + if (i == AVDT_NUM_TC_TBL) { + p_tbl = NULL; + } - return p_tbl; + return p_tbl; } - /******************************************************************************* * * Function avdt_ad_tc_tbl_by_lcid @@ -201,23 +173,18 @@ tAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(uint8_t type, tAVDT_CCB *p_ccb, uint8_t state * Returns Pointer to entry. * ******************************************************************************/ -tAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(uint16_t lcid) -{ - uint8_t idx; +tAVDT_TC_TBL* avdt_ad_tc_tbl_by_lcid(uint16_t lcid) { + uint8_t idx; - idx = avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; + idx = avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; - if (idx < AVDT_NUM_TC_TBL) - { - return &avdt_cb.ad.tc_tbl[idx]; - } - else - { - return NULL; - } + if (idx < AVDT_NUM_TC_TBL) { + return &avdt_cb.ad.tc_tbl[idx]; + } else { + return NULL; + } } - /******************************************************************************* * * Function avdt_ad_tc_tbl_by_type @@ -229,30 +196,27 @@ tAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(uint16_t lcid) * Returns Pointer to transport channel table entry. * ******************************************************************************/ -tAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb) -{ - uint8_t tcid; - int i; - tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; - uint8_t ccb_idx = avdt_ccb_to_idx(p_ccb); - - /* get tcid from type, scb */ - tcid = avdt_ad_type_to_tcid(type, p_scb); - - for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) - { - if ((p_tbl->tcid == tcid) && (p_tbl->ccb_idx == ccb_idx)) - { - break; - } +tAVDT_TC_TBL* avdt_ad_tc_tbl_by_type(uint8_t type, tAVDT_CCB* p_ccb, + tAVDT_SCB* p_scb) { + uint8_t tcid; + int i; + tAVDT_TC_TBL* p_tbl = avdt_cb.ad.tc_tbl; + uint8_t ccb_idx = avdt_ccb_to_idx(p_ccb); + + /* get tcid from type, scb */ + tcid = avdt_ad_type_to_tcid(type, p_scb); + + for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) { + if ((p_tbl->tcid == tcid) && (p_tbl->ccb_idx == ccb_idx)) { + break; } + } - assert(i != AVDT_NUM_TC_TBL); + assert(i != AVDT_NUM_TC_TBL); - return p_tbl; + return p_tbl; } - /******************************************************************************* * * Function avdt_ad_tc_tbl_alloc @@ -263,31 +227,26 @@ tAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB * * Returns Pointer to entry. * ******************************************************************************/ -tAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb) -{ - int i; - tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; - - /* find next free entry in tc table */ - for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) - { - if (p_tbl->state == AVDT_AD_ST_UNUSED) - { - break; - } +tAVDT_TC_TBL* avdt_ad_tc_tbl_alloc(tAVDT_CCB* p_ccb) { + int i; + tAVDT_TC_TBL* p_tbl = avdt_cb.ad.tc_tbl; + + /* find next free entry in tc table */ + for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) { + if (p_tbl->state == AVDT_AD_ST_UNUSED) { + break; } + } - /* sanity check */ - assert(i != AVDT_NUM_TC_TBL); - - - /* initialize entry */ - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - p_tbl->cfg_flags = 0; - p_tbl->ccb_idx = avdt_ccb_to_idx(p_ccb); - p_tbl->state = AVDT_AD_ST_IDLE; - return p_tbl; + /* sanity check */ + assert(i != AVDT_NUM_TC_TBL); + /* initialize entry */ + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + p_tbl->cfg_flags = 0; + p_tbl->ccb_idx = avdt_ccb_to_idx(p_ccb); + p_tbl->state = AVDT_AD_ST_IDLE; + return p_tbl; } /******************************************************************************* @@ -300,11 +259,10 @@ tAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb) * Returns Index value. * ******************************************************************************/ -uint8_t avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl) -{ - AVDT_TRACE_DEBUG("avdt_ad_tc_tbl_to_idx: %d", (p_tbl - avdt_cb.ad.tc_tbl)); - /* use array arithmetic to determine index */ - return (uint8_t) (p_tbl - avdt_cb.ad.tc_tbl); +uint8_t avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL* p_tbl) { + AVDT_TRACE_DEBUG("avdt_ad_tc_tbl_to_idx: %d", (p_tbl - avdt_cb.ad.tc_tbl)); + /* use array arithmetic to determine index */ + return (uint8_t)(p_tbl - avdt_cb.ad.tc_tbl); } /******************************************************************************* @@ -321,39 +279,35 @@ uint8_t avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl) * Returns Nothing. * ******************************************************************************/ -void avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, - UNUSED_ATTR uint16_t reason) -{ - tAVDT_CCB *p_ccb; - tAVDT_SCB *p_scb; - tAVDT_SCB_TC_CLOSE close; - - close.old_tc_state = p_tbl->state; - /* clear avdt_ad_tc_tbl entry */ - p_tbl->state = AVDT_AD_ST_UNUSED; - p_tbl->cfg_flags = 0; - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - - AVDT_TRACE_DEBUG("avdt_ad_tc_close_ind tcid: %d, old: %d", - p_tbl->tcid, close.old_tc_state); - /* if signaling channel, notify ccb that channel open */ - if (p_tbl->tcid == 0) - { - p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); - avdt_ccb_event(p_ccb, AVDT_CCB_LL_CLOSE_EVT, NULL); - } - /* if media or other channel, notify scb that channel close */ - else - { - /* look up scb in stream routing table by ccb, tcid */ - p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); - if (p_scb != NULL) - { - close.tcid = p_tbl->tcid; - close.type = avdt_ad_tcid_to_type(p_tbl->tcid); - avdt_scb_event(p_scb, AVDT_SCB_TC_CLOSE_EVT, (tAVDT_SCB_EVT *)&close); - } +void avdt_ad_tc_close_ind(tAVDT_TC_TBL* p_tbl, UNUSED_ATTR uint16_t reason) { + tAVDT_CCB* p_ccb; + tAVDT_SCB* p_scb; + tAVDT_SCB_TC_CLOSE close; + + close.old_tc_state = p_tbl->state; + /* clear avdt_ad_tc_tbl entry */ + p_tbl->state = AVDT_AD_ST_UNUSED; + p_tbl->cfg_flags = 0; + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + + AVDT_TRACE_DEBUG("avdt_ad_tc_close_ind tcid: %d, old: %d", p_tbl->tcid, + close.old_tc_state); + /* if signaling channel, notify ccb that channel open */ + if (p_tbl->tcid == 0) { + p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); + avdt_ccb_event(p_ccb, AVDT_CCB_LL_CLOSE_EVT, NULL); + } + /* if media or other channel, notify scb that channel close */ + else { + /* look up scb in stream routing table by ccb, tcid */ + p_scb = + avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); + if (p_scb != NULL) { + close.tcid = p_tbl->tcid; + close.type = avdt_ad_tcid_to_type(p_tbl->tcid); + avdt_scb_event(p_scb, AVDT_SCB_TC_CLOSE_EVT, (tAVDT_SCB_EVT*)&close); } + } } /******************************************************************************* @@ -368,49 +322,45 @@ void avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, * Returns Nothing. * ******************************************************************************/ -void avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl) -{ - tAVDT_CCB *p_ccb; - tAVDT_SCB *p_scb; - tAVDT_OPEN open; - tAVDT_EVT_HDR evt; - - p_tbl->state = AVDT_AD_ST_OPEN; - - /* if signaling channel, notify ccb that channel open */ - if (p_tbl->tcid == 0) - { - /* set the signal channel to use high priority within the ACL link */ - L2CA_SetTxPriority(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][AVDT_CHAN_SIG].lcid, L2CAP_CHNL_PRIORITY_HIGH); - - p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); - /* use err_param to indicate the role of connection. - * AVDT_ACP, if ACP */ - evt.err_param = AVDT_INT; - if(p_tbl->cfg_flags & AVDT_L2C_CFG_CONN_ACP) - { - evt.err_param = AVDT_ACP; - } - avdt_ccb_event(p_ccb, AVDT_CCB_LL_OPEN_EVT, (tAVDT_CCB_EVT *)&evt); +void avdt_ad_tc_open_ind(tAVDT_TC_TBL* p_tbl) { + tAVDT_CCB* p_ccb; + tAVDT_SCB* p_scb; + tAVDT_OPEN open; + tAVDT_EVT_HDR evt; + + p_tbl->state = AVDT_AD_ST_OPEN; + + /* if signaling channel, notify ccb that channel open */ + if (p_tbl->tcid == 0) { + /* set the signal channel to use high priority within the ACL link */ + L2CA_SetTxPriority(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][AVDT_CHAN_SIG].lcid, + L2CAP_CHNL_PRIORITY_HIGH); + + p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); + /* use err_param to indicate the role of connection. + * AVDT_ACP, if ACP */ + evt.err_param = AVDT_INT; + if (p_tbl->cfg_flags & AVDT_L2C_CFG_CONN_ACP) { + evt.err_param = AVDT_ACP; } - /* if media or other channel, notify scb that channel open */ - else - { - /* look up scb in stream routing table by ccb, tcid */ - p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); - - /* put lcid in event data */ - if (p_scb != NULL) - { - open.peer_mtu = p_tbl->peer_mtu; - open.lcid = avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].lcid; - open.hdr.err_code = avdt_ad_tcid_to_type(p_tbl->tcid); - avdt_scb_event(p_scb, AVDT_SCB_TC_OPEN_EVT, (tAVDT_SCB_EVT *) &open); - } + avdt_ccb_event(p_ccb, AVDT_CCB_LL_OPEN_EVT, (tAVDT_CCB_EVT*)&evt); + } + /* if media or other channel, notify scb that channel open */ + else { + /* look up scb in stream routing table by ccb, tcid */ + p_scb = + avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); + + /* put lcid in event data */ + if (p_scb != NULL) { + open.peer_mtu = p_tbl->peer_mtu; + open.lcid = avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].lcid; + open.hdr.err_code = avdt_ad_tcid_to_type(p_tbl->tcid); + avdt_scb_event(p_scb, AVDT_SCB_TC_OPEN_EVT, (tAVDT_SCB_EVT*)&open); } + } } - /******************************************************************************* * * Function avdt_ad_tc_cong_ind @@ -425,30 +375,27 @@ void avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl) * Returns Nothing. * ******************************************************************************/ -void avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, bool is_congested) -{ - tAVDT_CCB *p_ccb; - tAVDT_SCB *p_scb; - - /* if signaling channel, notify ccb of congestion */ - if (p_tbl->tcid == 0) - { - p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); - avdt_ccb_event(p_ccb, AVDT_CCB_LL_CONG_EVT, (tAVDT_CCB_EVT *) &is_congested); - } - /* if media or other channel, notify scb that channel open */ - else - { - /* look up scb in stream routing table by ccb, tcid */ - p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_TC_CONG_EVT, (tAVDT_SCB_EVT *) &is_congested); - } +void avdt_ad_tc_cong_ind(tAVDT_TC_TBL* p_tbl, bool is_congested) { + tAVDT_CCB* p_ccb; + tAVDT_SCB* p_scb; + + /* if signaling channel, notify ccb of congestion */ + if (p_tbl->tcid == 0) { + p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); + avdt_ccb_event(p_ccb, AVDT_CCB_LL_CONG_EVT, (tAVDT_CCB_EVT*)&is_congested); + } + /* if media or other channel, notify scb that channel open */ + else { + /* look up scb in stream routing table by ccb, tcid */ + p_scb = + avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_TC_CONG_EVT, + (tAVDT_SCB_EVT*)&is_congested); } + } } - /******************************************************************************* * * Function avdt_ad_tc_data_ind @@ -461,35 +408,29 @@ void avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, bool is_congested) * Returns Nothing. * ******************************************************************************/ -void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf) -{ - tAVDT_CCB *p_ccb; - tAVDT_SCB *p_scb; - - /* store type (media, recovery, reporting) */ - p_buf->layer_specific = avdt_ad_tcid_to_type(p_tbl->tcid); - - - /* if signaling channel, handle control message */ - if (p_tbl->tcid == 0) - { - p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); - avdt_msg_ind(p_ccb, p_buf); - } - /* if media or other channel, send event to scb */ - else - { - p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT *) &p_buf); - } - else - { - osi_free(p_buf); - AVDT_TRACE_ERROR(" avdt_ad_tc_data_ind buffer freed"); - } +void avdt_ad_tc_data_ind(tAVDT_TC_TBL* p_tbl, BT_HDR* p_buf) { + tAVDT_CCB* p_ccb; + tAVDT_SCB* p_scb; + + /* store type (media, recovery, reporting) */ + p_buf->layer_specific = avdt_ad_tcid_to_type(p_tbl->tcid); + + /* if signaling channel, handle control message */ + if (p_tbl->tcid == 0) { + p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); + avdt_msg_ind(p_ccb, p_buf); + } + /* if media or other channel, send event to scb */ + else { + p_scb = + avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT*)&p_buf); + } else { + osi_free(p_buf); + AVDT_TRACE_ERROR(" avdt_ad_tc_data_ind buffer freed"); } + } } /******************************************************************************* @@ -508,18 +449,17 @@ void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf) * AVDT_AD_FAILED, if error * ******************************************************************************/ -uint8_t avdt_ad_write_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_HDR *p_buf) -{ - uint8_t tcid; +uint8_t avdt_ad_write_req(uint8_t type, tAVDT_CCB* p_ccb, tAVDT_SCB* p_scb, + BT_HDR* p_buf) { + uint8_t tcid; - /* get tcid from type, scb */ - tcid = avdt_ad_type_to_tcid(type, p_scb); + /* get tcid from type, scb */ + tcid = avdt_ad_type_to_tcid(type, p_scb); - - return L2CA_DataWrite(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid, p_buf); + return L2CA_DataWrite(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid, + p_buf); } - /******************************************************************************* * * Function avdt_ad_open_req @@ -536,72 +476,64 @@ uint8_t avdt_ad_write_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_H * Returns Nothing. * ******************************************************************************/ -void avdt_ad_open_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, uint8_t role) -{ - tAVDT_TC_TBL *p_tbl; - uint16_t lcid; - - p_tbl = avdt_ad_tc_tbl_alloc(p_ccb); - if(p_tbl == NULL) - { - AVDT_TRACE_ERROR("avdt_ad_open_req: Cannot allocate p_tbl"); - return; - } - - - p_tbl->tcid = avdt_ad_type_to_tcid(type, p_scb); - AVDT_TRACE_DEBUG("avdt_ad_open_req: type: %d, role: %d, tcid:%d", - type, role, p_tbl->tcid); - - if (type == AVDT_CHAN_SIG) - { - /* if signaling, get mtu from registration control block */ - p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu; - p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO; - } - else - { - /* otherwise get mtu from scb */ - p_tbl->my_mtu = p_scb->cs.mtu; - p_tbl->my_flush_to = p_scb->cs.flush_to; - - /* also set scb_hdl in rt_tbl */ - avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].scb_hdl = avdt_scb_to_hdl(p_scb); - AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].scb_hdl = %d", - avdt_ccb_to_idx(p_ccb), p_tbl->tcid, - avdt_scb_to_hdl(p_scb)); - } - - /* if we're acceptor, we're done; just sit back and listen */ - if (role == AVDT_ACP) - { - p_tbl->state = AVDT_AD_ST_ACP; - } - /* else we're inititator, start the L2CAP connection */ - else - { - p_tbl->state = AVDT_AD_ST_CONN; - - /* call l2cap connect req */ - lcid = L2CA_ConnectReq(AVDT_PSM, p_ccb->peer_addr); - if (lcid != 0) - { - /* if connect req ok, store tcid in lcid table */ - avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = avdt_ad_tc_tbl_to_idx(p_tbl); - AVDT_TRACE_DEBUG("avdt_cb.ad.lcid_tbl[%d] = %d", - (lcid - L2CAP_BASE_APPL_CID), avdt_ad_tc_tbl_to_idx(p_tbl)); - - avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid; - AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].lcid = 0x%x", - avdt_ccb_to_idx(p_ccb), p_tbl->tcid, - lcid); - } - else - { - /* if connect req failed, call avdt_ad_tc_close_ind() */ - avdt_ad_tc_close_ind(p_tbl, 0); - } +void avdt_ad_open_req(uint8_t type, tAVDT_CCB* p_ccb, tAVDT_SCB* p_scb, + uint8_t role) { + tAVDT_TC_TBL* p_tbl; + uint16_t lcid; + + p_tbl = avdt_ad_tc_tbl_alloc(p_ccb); + if (p_tbl == NULL) { + AVDT_TRACE_ERROR("avdt_ad_open_req: Cannot allocate p_tbl"); + return; + } + + p_tbl->tcid = avdt_ad_type_to_tcid(type, p_scb); + AVDT_TRACE_DEBUG("avdt_ad_open_req: type: %d, role: %d, tcid:%d", type, role, + p_tbl->tcid); + + if (type == AVDT_CHAN_SIG) { + /* if signaling, get mtu from registration control block */ + p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu; + p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO; + } else { + /* otherwise get mtu from scb */ + p_tbl->my_mtu = p_scb->cs.mtu; + p_tbl->my_flush_to = p_scb->cs.flush_to; + + /* also set scb_hdl in rt_tbl */ + avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].scb_hdl = + avdt_scb_to_hdl(p_scb); + AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].scb_hdl = %d", + avdt_ccb_to_idx(p_ccb), p_tbl->tcid, + avdt_scb_to_hdl(p_scb)); + } + + /* if we're acceptor, we're done; just sit back and listen */ + if (role == AVDT_ACP) { + p_tbl->state = AVDT_AD_ST_ACP; + } + /* else we're inititator, start the L2CAP connection */ + else { + p_tbl->state = AVDT_AD_ST_CONN; + + /* call l2cap connect req */ + lcid = L2CA_ConnectReq(AVDT_PSM, p_ccb->peer_addr); + if (lcid != 0) { + /* if connect req ok, store tcid in lcid table */ + avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = + avdt_ad_tc_tbl_to_idx(p_tbl); + AVDT_TRACE_DEBUG("avdt_cb.ad.lcid_tbl[%d] = %d", + (lcid - L2CAP_BASE_APPL_CID), + avdt_ad_tc_tbl_to_idx(p_tbl)); + + avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid; + AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].lcid = 0x%x", + avdt_ccb_to_idx(p_ccb), p_tbl->tcid, lcid); + } else { + /* if connect req failed, call avdt_ad_tc_close_ind() */ + avdt_ad_tc_close_ind(p_tbl, 0); } + } } /******************************************************************************* @@ -616,29 +548,26 @@ void avdt_ad_open_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, uint8_t * Returns Nothing. * ******************************************************************************/ -void avdt_ad_close_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb) -{ - uint8_t tcid; - tAVDT_TC_TBL *p_tbl; +void avdt_ad_close_req(uint8_t type, tAVDT_CCB* p_ccb, tAVDT_SCB* p_scb) { + uint8_t tcid; + tAVDT_TC_TBL* p_tbl; - p_tbl = avdt_ad_tc_tbl_by_type(type, p_ccb, p_scb); - AVDT_TRACE_DEBUG("avdt_ad_close_req state: %d", p_tbl->state); + p_tbl = avdt_ad_tc_tbl_by_type(type, p_ccb, p_scb); + AVDT_TRACE_DEBUG("avdt_ad_close_req state: %d", p_tbl->state); - switch(p_tbl->state) - { + switch (p_tbl->state) { case AVDT_AD_ST_UNUSED: - /* probably for reporting */ - break; + /* probably for reporting */ + break; case AVDT_AD_ST_ACP: - /* if we're listening on this channel, send ourselves a close ind */ - avdt_ad_tc_close_ind(p_tbl, 0); - break; + /* if we're listening on this channel, send ourselves a close ind */ + avdt_ad_tc_close_ind(p_tbl, 0); + break; default: - /* get tcid from type, scb */ - tcid = avdt_ad_type_to_tcid(type, p_scb); + /* get tcid from type, scb */ + tcid = avdt_ad_type_to_tcid(type, p_scb); - /* call l2cap disconnect req */ - L2CA_DisconnectReq(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid); - } + /* call l2cap disconnect req */ + L2CA_DisconnectReq(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid); + } } - diff --git a/stack/avdt/avdt_api.cc b/stack/avdt/avdt_api.cc index 28b8b7e42..8e6ba929f 100644 --- a/stack/avdt/avdt_api.cc +++ b/stack/avdt/avdt_api.cc @@ -23,53 +23,48 @@ * ******************************************************************************/ -#include -#include "bt_types.h" -#include "bt_target.h" #include "avdt_api.h" -#include "avdtc_api.h" +#include #include "avdt_int.h" -#include "l2c_api.h" +#include "avdtc_api.h" +#include "bt_target.h" +#include "bt_types.h" #include "btm_api.h" #include "btu.h" - +#include "l2c_api.h" /* Control block for AVDT */ tAVDT_CB avdt_cb; -void avdt_ccb_idle_ccb_timer_timeout(void *data) -{ - tAVDT_CCB *p_ccb = (tAVDT_CCB *)data; - uint8_t avdt_event = AVDT_CCB_IDLE_TOUT_EVT; - uint8_t err_code = AVDT_ERR_TIMEOUT; +void avdt_ccb_idle_ccb_timer_timeout(void* data) { + tAVDT_CCB* p_ccb = (tAVDT_CCB*)data; + uint8_t avdt_event = AVDT_CCB_IDLE_TOUT_EVT; + uint8_t err_code = AVDT_ERR_TIMEOUT; - avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code); + avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT*)&err_code); } -void avdt_ccb_ret_ccb_timer_timeout(void *data) -{ - tAVDT_CCB *p_ccb = (tAVDT_CCB *)data; - uint8_t avdt_event = AVDT_CCB_RET_TOUT_EVT; - uint8_t err_code = AVDT_ERR_TIMEOUT; +void avdt_ccb_ret_ccb_timer_timeout(void* data) { + tAVDT_CCB* p_ccb = (tAVDT_CCB*)data; + uint8_t avdt_event = AVDT_CCB_RET_TOUT_EVT; + uint8_t err_code = AVDT_ERR_TIMEOUT; - avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code); + avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT*)&err_code); } -void avdt_ccb_rsp_ccb_timer_timeout(void *data) -{ - tAVDT_CCB *p_ccb = (tAVDT_CCB *)data; - uint8_t avdt_event = AVDT_CCB_RSP_TOUT_EVT; - uint8_t err_code = AVDT_ERR_TIMEOUT; +void avdt_ccb_rsp_ccb_timer_timeout(void* data) { + tAVDT_CCB* p_ccb = (tAVDT_CCB*)data; + uint8_t avdt_event = AVDT_CCB_RSP_TOUT_EVT; + uint8_t err_code = AVDT_ERR_TIMEOUT; - avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code); + avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT*)&err_code); } -void avdt_scb_transport_channel_timer_timeout(void *data) -{ - tAVDT_SCB *p_scb = (tAVDT_SCB *)data; - uint8_t avdt_event = AVDT_SCB_TC_TOUT_EVT; +void avdt_scb_transport_channel_timer_timeout(void* data) { + tAVDT_SCB* p_scb = (tAVDT_SCB*)data; + uint8_t avdt_event = AVDT_SCB_TC_TOUT_EVT; - avdt_scb_event(p_scb, avdt_event, NULL); + avdt_scb_event(p_scb, avdt_event, NULL); } /******************************************************************************* @@ -86,39 +81,38 @@ void avdt_scb_transport_channel_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void AVDT_Register(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback) -{ - /* register PSM with L2CAP */ - L2CA_Register(AVDT_PSM, (tL2CAP_APPL_INFO *) &avdt_l2c_appl); - - /* set security level */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG); - - /* do not use security on the media channel */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA); +void AVDT_Register(tAVDT_REG* p_reg, tAVDT_CTRL_CBACK* p_cback) { + /* register PSM with L2CAP */ + L2CA_Register(AVDT_PSM, (tL2CAP_APPL_INFO*)&avdt_l2c_appl); + + /* set security level */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP, p_reg->sec_mask, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG); + + /* do not use security on the media channel */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_MEDIA); #if (AVDT_REPORTING == TRUE) - /* do not use security on the reporting channel */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT); + /* do not use security on the reporting channel */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_AVDTP_NOSEC, BTM_SEC_NONE, + AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_REPORT); #endif - /* initialize AVDTP data structures */ - avdt_scb_init(); - avdt_ccb_init(); - avdt_ad_init(); + /* initialize AVDTP data structures */ + avdt_scb_init(); + avdt_ccb_init(); + avdt_ad_init(); - /* copy registration struct */ - memcpy(&avdt_cb.rcb, p_reg, sizeof(tAVDT_REG)); - avdt_cb.p_conn_cback = p_cback; + /* copy registration struct */ + memcpy(&avdt_cb.rcb, p_reg, sizeof(tAVDT_REG)); + avdt_cb.p_conn_cback = p_cback; } /******************************************************************************* @@ -135,23 +129,20 @@ void AVDT_Register(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback) * Returns void * ******************************************************************************/ -void AVDT_Deregister(void) -{ - /* deregister PSM with L2CAP */ - L2CA_Deregister(AVDT_PSM); +void AVDT_Deregister(void) { + /* deregister PSM with L2CAP */ + L2CA_Deregister(AVDT_PSM); } -void AVDT_AbortReq(uint8_t handle) -{ - AVDT_TRACE_ERROR("%s", __func__); +void AVDT_AbortReq(uint8_t handle) { + AVDT_TRACE_ERROR("%s", __func__); - tAVDT_SCB *p_scb = avdt_scb_by_hdl(handle); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_REQ_EVT, NULL); - } else { - AVDT_TRACE_ERROR("%s Improper SCB, can not abort the stream", __func__); - } + tAVDT_SCB* p_scb = avdt_scb_by_hdl(handle); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_REQ_EVT, NULL); + } else { + AVDT_TRACE_ERROR("%s Improper SCB, can not abort the stream", __func__); + } } /******************************************************************************* @@ -168,29 +159,25 @@ void AVDT_AbortReq(uint8_t handle) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_CreateStream(uint8_t *p_handle, tAVDT_CS *p_cs) -{ - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB *p_scb; - - /* Verify parameters; if invalid, return failure */ - if (((p_cs->cfg.psc_mask & (~AVDT_PSC)) != 0) || (p_cs->p_ctrl_cback == NULL)) - { - result = AVDT_BAD_PARAMS; - } - /* Allocate scb; if no scbs, return failure */ - else { - p_scb = avdt_scb_alloc(p_cs); - if (p_scb == NULL) - { - result = AVDT_NO_RESOURCES; - } - else - { - *p_handle = avdt_scb_to_hdl(p_scb); - } +uint16_t AVDT_CreateStream(uint8_t* p_handle, tAVDT_CS* p_cs) { + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB* p_scb; + + /* Verify parameters; if invalid, return failure */ + if (((p_cs->cfg.psc_mask & (~AVDT_PSC)) != 0) || + (p_cs->p_ctrl_cback == NULL)) { + result = AVDT_BAD_PARAMS; + } + /* Allocate scb; if no scbs, return failure */ + else { + p_scb = avdt_scb_alloc(p_cs); + if (p_scb == NULL) { + result = AVDT_NO_RESOURCES; + } else { + *p_handle = avdt_scb_to_hdl(p_scb); } - return result; + } + return result; } /******************************************************************************* @@ -207,23 +194,19 @@ uint16_t AVDT_CreateStream(uint8_t *p_handle, tAVDT_CS *p_cs) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_RemoveStream(uint8_t handle) -{ - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB *p_scb; - - /* look up scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - { - /* send remove event to scb */ - avdt_scb_event(p_scb, AVDT_SCB_API_REMOVE_EVT, NULL); - } - return result; +uint16_t AVDT_RemoveStream(uint8_t handle) { + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB* p_scb; + + /* look up scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } else { + /* send remove event to scb */ + avdt_scb_event(p_scb, AVDT_SCB_API_REMOVE_EVT, NULL); + } + return result; } /******************************************************************************* @@ -252,42 +235,36 @@ uint16_t AVDT_RemoveStream(uint8_t handle) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info, - uint8_t max_seps, tAVDT_CTRL_CBACK *p_cback) -{ - tAVDT_CCB *p_ccb; - uint16_t result = AVDT_SUCCESS; - tAVDT_CCB_EVT evt; - - /* find channel control block for this bd addr; if none, allocate one */ - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - p_ccb = avdt_ccb_alloc(bd_addr); - if (p_ccb == NULL) - { - /* could not allocate channel control block */ - result = AVDT_NO_RESOURCES; - } +uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO* p_sep_info, + uint8_t max_seps, tAVDT_CTRL_CBACK* p_cback) { + tAVDT_CCB* p_ccb; + uint16_t result = AVDT_SUCCESS; + tAVDT_CCB_EVT evt; + + /* find channel control block for this bd addr; if none, allocate one */ + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + p_ccb = avdt_ccb_alloc(bd_addr); + if (p_ccb == NULL) { + /* could not allocate channel control block */ + result = AVDT_NO_RESOURCES; } + } - if (result == AVDT_SUCCESS) - { - /* make sure no discovery or get capabilities req already in progress */ - if (p_ccb->proc_busy) - { - result = AVDT_BUSY; - } - /* send event to ccb */ - else - { - evt.discover.p_sep_info = p_sep_info; - evt.discover.num_seps = max_seps; - evt.discover.p_cback = p_cback; - avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_REQ_EVT, &evt); - } + if (result == AVDT_SUCCESS) { + /* make sure no discovery or get capabilities req already in progress */ + if (p_ccb->proc_busy) { + result = AVDT_BUSY; + } + /* send event to ccb */ + else { + evt.discover.p_sep_info = p_sep_info; + evt.discover.num_seps = max_seps; + evt.discover.p_cback = p_cback; + avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_REQ_EVT, &evt); } - return result; + } + return result; } /******************************************************************************* @@ -300,45 +277,39 @@ uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -static uint16_t avdt_get_cap_req(BD_ADDR bd_addr, tAVDT_CCB_API_GETCAP *p_evt) -{ - tAVDT_CCB *p_ccb = NULL; - uint16_t result = AVDT_SUCCESS; - - /* verify SEID */ - if ((p_evt->single.seid < AVDT_SEID_MIN) || (p_evt->single.seid > AVDT_SEID_MAX)) - { - AVDT_TRACE_ERROR("seid: %d", p_evt->single.seid); - result = AVDT_BAD_PARAMS; - } - /* find channel control block for this bd addr; if none, allocate one */ - else { - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - p_ccb = avdt_ccb_alloc(bd_addr); - if (p_ccb == NULL) - { - /* could not allocate channel control block */ - result = AVDT_NO_RESOURCES; - } - } +static uint16_t avdt_get_cap_req(BD_ADDR bd_addr, tAVDT_CCB_API_GETCAP* p_evt) { + tAVDT_CCB* p_ccb = NULL; + uint16_t result = AVDT_SUCCESS; + + /* verify SEID */ + if ((p_evt->single.seid < AVDT_SEID_MIN) || + (p_evt->single.seid > AVDT_SEID_MAX)) { + AVDT_TRACE_ERROR("seid: %d", p_evt->single.seid); + result = AVDT_BAD_PARAMS; + } + /* find channel control block for this bd addr; if none, allocate one */ + else { + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + p_ccb = avdt_ccb_alloc(bd_addr); + if (p_ccb == NULL) { + /* could not allocate channel control block */ + result = AVDT_NO_RESOURCES; + } } + } - if (result == AVDT_SUCCESS) - { - /* make sure no discovery or get capabilities req already in progress */ - if (p_ccb->proc_busy) - { - result = AVDT_BUSY; - } - /* send event to ccb */ - else - { - avdt_ccb_event(p_ccb, AVDT_CCB_API_GETCAP_REQ_EVT, (tAVDT_CCB_EVT *)p_evt); - } + if (result == AVDT_SUCCESS) { + /* make sure no discovery or get capabilities req already in progress */ + if (p_ccb->proc_busy) { + result = AVDT_BUSY; + } + /* send event to ccb */ + else { + avdt_ccb_event(p_ccb, AVDT_CCB_API_GETCAP_REQ_EVT, (tAVDT_CCB_EVT*)p_evt); } - return result; + } + return result; } /******************************************************************************* @@ -365,15 +336,15 @@ static uint16_t avdt_get_cap_req(BD_ADDR bd_addr, tAVDT_CCB_API_GETCAP *p_evt) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback) -{ - tAVDT_CCB_API_GETCAP getcap; - - getcap.single.seid = seid; - getcap.single.sig_id = AVDT_SIG_GETCAP; - getcap.p_cfg = p_cfg; - getcap.p_cback = p_cback; - return avdt_get_cap_req (bd_addr, &getcap); +uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG* p_cfg, + tAVDT_CTRL_CBACK* p_cback) { + tAVDT_CCB_API_GETCAP getcap; + + getcap.single.seid = seid; + getcap.single.sig_id = AVDT_SIG_GETCAP; + getcap.p_cfg = p_cfg; + getcap.p_cback = p_cback; + return avdt_get_cap_req(bd_addr, &getcap); } /******************************************************************************* @@ -400,15 +371,15 @@ uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, tAVDT_C * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback) -{ - tAVDT_CCB_API_GETCAP getcap; - - getcap.single.seid = seid; - getcap.single.sig_id = AVDT_SIG_GET_ALLCAP; - getcap.p_cfg = p_cfg; - getcap.p_cback = p_cback; - return avdt_get_cap_req (bd_addr, &getcap); +uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG* p_cfg, + tAVDT_CTRL_CBACK* p_cback) { + tAVDT_CCB_API_GETCAP getcap; + + getcap.single.seid = seid; + getcap.single.sig_id = AVDT_SIG_GET_ALLCAP; + getcap.p_cfg = p_cfg; + getcap.p_cback = p_cback; + return avdt_get_cap_req(bd_addr, &getcap); } /******************************************************************************* @@ -422,27 +393,24 @@ uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, tAVD * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB_EVT evt; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - /* send event to scb */ - { - evt.apidelay.hdr.seid = seid; - evt.apidelay.delay = delay; - avdt_scb_event(p_scb, AVDT_SCB_API_DELAY_RPT_REQ_EVT, &evt); - } - - return result; +uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB_EVT evt; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } else + /* send event to scb */ + { + evt.apidelay.hdr.seid = seid; + evt.apidelay.delay = delay; + avdt_scb_event(p_scb, AVDT_SCB_API_DELAY_RPT_REQ_EVT, &evt); + } + + return result; } /******************************************************************************* @@ -459,50 +427,45 @@ uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg) -{ - tAVDT_CCB *p_ccb = NULL; - tAVDT_SCB *p_scb = NULL; - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB_EVT evt; - - /* verify SEID */ - if ((seid < AVDT_SEID_MIN) || (seid > AVDT_SEID_MAX)) - { - result = AVDT_BAD_PARAMS; +uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid, + tAVDT_CFG* p_cfg) { + tAVDT_CCB* p_ccb = NULL; + tAVDT_SCB* p_scb = NULL; + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB_EVT evt; + + /* verify SEID */ + if ((seid < AVDT_SEID_MIN) || (seid > AVDT_SEID_MAX)) { + result = AVDT_BAD_PARAMS; + } + /* map handle to scb */ + else { + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; } - /* map handle to scb */ - else { - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } /* find channel control block for this bd addr; if none, allocate one */ - else { - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - p_ccb = avdt_ccb_alloc(bd_addr); - if (p_ccb == NULL) - { - /* could not allocate channel control block */ - result = AVDT_NO_RESOURCES; - } - } + else { + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + p_ccb = avdt_ccb_alloc(bd_addr); + if (p_ccb == NULL) { + /* could not allocate channel control block */ + result = AVDT_NO_RESOURCES; } + } } - - /* send event to scb */ - if (result == AVDT_SUCCESS) - { - evt.msg.config_cmd.hdr.seid = seid; - evt.msg.config_cmd.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); - evt.msg.config_cmd.int_seid = handle; - evt.msg.config_cmd.p_cfg = p_cfg; - avdt_scb_event(p_scb, AVDT_SCB_API_SETCONFIG_REQ_EVT, &evt); - } - return result; + } + + /* send event to scb */ + if (result == AVDT_SUCCESS) { + evt.msg.config_cmd.hdr.seid = seid; + evt.msg.config_cmd.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); + evt.msg.config_cmd.int_seid = handle; + evt.msg.config_cmd.p_cfg = p_cfg; + avdt_scb_event(p_scb, AVDT_SCB_API_SETCONFIG_REQ_EVT, &evt); + } + return result; } /******************************************************************************* @@ -517,44 +480,38 @@ uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG * * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, uint8_t category) -{ - tAVDT_SCB *p_scb; - tAVDT_SCB_EVT evt; - uint16_t result = AVDT_SUCCESS; - uint8_t event_code; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - /* handle special case when this function is called but peer has not send - ** a configuration cmd; ignore and return error result - */ - else if (!p_scb->in_use) - { - result = AVDT_BAD_HANDLE; - } - /* send event to scb */ - else - { - evt.msg.hdr.err_code = error_code; - evt.msg.hdr.err_param = category; - evt.msg.hdr.label = label; - if (error_code == 0) - { - event_code = AVDT_SCB_API_SETCONFIG_RSP_EVT; - } - else - { - event_code = AVDT_SCB_API_SETCONFIG_REJ_EVT; - } - avdt_scb_event(p_scb, event_code, &evt); +uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, + uint8_t category) { + tAVDT_SCB* p_scb; + tAVDT_SCB_EVT evt; + uint16_t result = AVDT_SUCCESS; + uint8_t event_code; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } + /* handle special case when this function is called but peer has not send + ** a configuration cmd; ignore and return error result + */ + else if (!p_scb->in_use) { + result = AVDT_BAD_HANDLE; + } + /* send event to scb */ + else { + evt.msg.hdr.err_code = error_code; + evt.msg.hdr.err_param = category; + evt.msg.hdr.label = label; + if (error_code == 0) { + event_code = AVDT_SCB_API_SETCONFIG_RSP_EVT; + } else { + event_code = AVDT_SCB_API_SETCONFIG_REJ_EVT; } + avdt_scb_event(p_scb, event_code, &evt); + } - return result; + return result; } /******************************************************************************* @@ -572,46 +529,36 @@ uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, uint8 * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_StartReq(uint8_t *p_handles, uint8_t num_handles) -{ - tAVDT_SCB *p_scb = NULL; - tAVDT_CCB_EVT evt; - uint16_t result = AVDT_SUCCESS; - int i; - - if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) - { - result = AVDT_BAD_PARAMS; - } - else - { - /* verify handles */ - for (i = 0; i < num_handles; i++) - { - p_scb = avdt_scb_by_hdl(p_handles[i]); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - break; - } - } +uint16_t AVDT_StartReq(uint8_t* p_handles, uint8_t num_handles) { + tAVDT_SCB* p_scb = NULL; + tAVDT_CCB_EVT evt; + uint16_t result = AVDT_SUCCESS; + int i; + + if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) { + result = AVDT_BAD_PARAMS; + } else { + /* verify handles */ + for (i = 0; i < num_handles; i++) { + p_scb = avdt_scb_by_hdl(p_handles[i]); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + break; + } } + } - if (result == AVDT_SUCCESS) - { - if (p_scb->p_ccb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - { - /* send event to ccb */ - memcpy(evt.msg.multi.seid_list, p_handles, num_handles); - evt.msg.multi.num_seps = num_handles; - avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_START_REQ_EVT, &evt); - } + if (result == AVDT_SUCCESS) { + if (p_scb->p_ccb == NULL) { + result = AVDT_BAD_HANDLE; + } else { + /* send event to ccb */ + memcpy(evt.msg.multi.seid_list, p_handles, num_handles); + evt.msg.multi.num_seps = num_handles; + avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_START_REQ_EVT, &evt); } - return result; + } + return result; } /******************************************************************************* @@ -629,47 +576,37 @@ uint16_t AVDT_StartReq(uint8_t *p_handles, uint8_t num_handles) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_SuspendReq(uint8_t *p_handles, uint8_t num_handles) -{ - tAVDT_SCB *p_scb = NULL; - tAVDT_CCB_EVT evt; - uint16_t result = AVDT_SUCCESS; - int i; - - if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) - { - result = AVDT_BAD_PARAMS; - } - else - { - /* verify handles */ - for (i = 0; i < num_handles; i++) - { - p_scb = avdt_scb_by_hdl(p_handles[i]); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - break; - } - } +uint16_t AVDT_SuspendReq(uint8_t* p_handles, uint8_t num_handles) { + tAVDT_SCB* p_scb = NULL; + tAVDT_CCB_EVT evt; + uint16_t result = AVDT_SUCCESS; + int i; + + if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) { + result = AVDT_BAD_PARAMS; + } else { + /* verify handles */ + for (i = 0; i < num_handles; i++) { + p_scb = avdt_scb_by_hdl(p_handles[i]); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + break; + } } + } - if (result == AVDT_SUCCESS) - { - if (p_scb->p_ccb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - { - /* send event to ccb */ - memcpy(evt.msg.multi.seid_list, p_handles, num_handles); - evt.msg.multi.num_seps = num_handles; - avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_SUSPEND_REQ_EVT, &evt); - } + if (result == AVDT_SUCCESS) { + if (p_scb->p_ccb == NULL) { + result = AVDT_BAD_HANDLE; + } else { + /* send event to ccb */ + memcpy(evt.msg.multi.seid_list, p_handles, num_handles); + evt.msg.multi.num_seps = num_handles; + avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_API_SUSPEND_REQ_EVT, &evt); } + } - return result; + return result; } /******************************************************************************* @@ -686,24 +623,21 @@ uint16_t AVDT_SuspendReq(uint8_t *p_handles, uint8_t num_handles) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_CloseReq(uint8_t handle) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_SUCCESS; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - /* send event to scb */ - { - avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_REQ_EVT, NULL); - } - - return result; +uint16_t AVDT_CloseReq(uint8_t handle) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_SUCCESS; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } else + /* send event to scb */ + { + avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_REQ_EVT, NULL); + } + + return result; } /******************************************************************************* @@ -723,28 +657,25 @@ uint16_t AVDT_CloseReq(uint8_t handle) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG *p_cfg) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB_EVT evt; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - /* send event to scb */ - else - { - /* force psc_mask to zero */ - p_cfg->psc_mask = 0; - - evt.msg.reconfig_cmd.p_cfg = p_cfg; - avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_REQ_EVT, &evt); - } - return result; +uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG* p_cfg) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB_EVT evt; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } + /* send event to scb */ + else { + /* force psc_mask to zero */ + p_cfg->psc_mask = 0; + + evt.msg.reconfig_cmd.p_cfg = p_cfg; + avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_REQ_EVT, &evt); + } + return result; } /******************************************************************************* @@ -759,28 +690,26 @@ uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG *p_cfg) * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, uint8_t category) -{ - tAVDT_SCB *p_scb; - tAVDT_SCB_EVT evt; - uint16_t result = AVDT_SUCCESS; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - /* send event to scb */ - else - { - evt.msg.hdr.err_code = error_code; - evt.msg.hdr.err_param = category; - evt.msg.hdr.label = label; - avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, &evt); - } - - return result; +uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, + uint8_t category) { + tAVDT_SCB* p_scb; + tAVDT_SCB_EVT evt; + uint16_t result = AVDT_SUCCESS; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } + /* send event to scb */ + else { + evt.msg.hdr.err_code = error_code; + evt.msg.hdr.err_param = category; + evt.msg.hdr.label = label; + avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, &evt); + } + + return result; } /******************************************************************************* @@ -797,26 +726,23 @@ uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, uin * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t *p_data, uint16_t len) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB_EVT evt; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - /* send event to scb */ - else - { - evt.msg.security_rsp.p_data = p_data; - evt.msg.security_rsp.len = len; - avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_REQ_EVT, &evt); - } - return result; +uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t* p_data, uint16_t len) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB_EVT evt; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } + /* send event to scb */ + else { + evt.msg.security_rsp.p_data = p_data; + evt.msg.security_rsp.len = len; + avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_REQ_EVT, &evt); + } + return result; } /******************************************************************************* @@ -834,28 +760,25 @@ uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t *p_data, uint16_t len) * ******************************************************************************/ uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_code, - uint8_t *p_data, uint16_t len) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_SUCCESS; - tAVDT_SCB_EVT evt; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - /* send event to scb */ - else - { - evt.msg.security_rsp.hdr.err_code = error_code; - evt.msg.security_rsp.hdr.label = label; - evt.msg.security_rsp.p_data = p_data; - evt.msg.security_rsp.len = len; - avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, &evt); - } - return result; + uint8_t* p_data, uint16_t len) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_SUCCESS; + tAVDT_SCB_EVT evt; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } + /* send event to scb */ + else { + evt.msg.security_rsp.hdr.err_code = error_code; + evt.msg.security_rsp.hdr.label = label; + evt.msg.security_rsp.p_data = p_data; + evt.msg.security_rsp.len = len; + avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, &evt); + } + return result; } /******************************************************************************* @@ -895,28 +818,25 @@ uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_code, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, uint8_t m_pt, tAVDT_DATA_OPT_MASK opt) -{ - tAVDT_SCB *p_scb; - tAVDT_SCB_EVT evt; - uint16_t result = AVDT_SUCCESS; - - /* map handle to scb */ - p_scb = avdt_scb_by_hdl(handle); - if (p_scb == NULL) - { - result = AVDT_BAD_HANDLE; - } - else - { - evt.apiwrite.p_buf = p_pkt; - evt.apiwrite.time_stamp = time_stamp; - evt.apiwrite.m_pt = m_pt; - evt.apiwrite.opt = opt; - avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt); - } - - return result; +uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp, + uint8_t m_pt, tAVDT_DATA_OPT_MASK opt) { + tAVDT_SCB* p_scb; + tAVDT_SCB_EVT evt; + uint16_t result = AVDT_SUCCESS; + + /* map handle to scb */ + p_scb = avdt_scb_by_hdl(handle); + if (p_scb == NULL) { + result = AVDT_BAD_HANDLE; + } else { + evt.apiwrite.p_buf = p_pkt; + evt.apiwrite.time_stamp = time_stamp; + evt.apiwrite.m_pt = m_pt; + evt.apiwrite.opt = opt; + avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt); + } + + return result; } /******************************************************************************* @@ -953,9 +873,9 @@ uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, ui * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, uint8_t m_pt) -{ - return AVDT_WriteReqOpt(handle, p_pkt, time_stamp, m_pt, AVDT_DATA_OPT_NONE); +uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp, + uint8_t m_pt) { + return AVDT_WriteReqOpt(handle, p_pkt, time_stamp, m_pt, AVDT_DATA_OPT_NONE); } /******************************************************************************* @@ -973,39 +893,34 @@ uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, uint8 * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask, tAVDT_CTRL_CBACK *p_cback) -{ - tAVDT_CCB *p_ccb = NULL; - uint16_t result = AVDT_SUCCESS; - tAVDT_CCB_EVT evt; - - /* find channel control block for this bd addr; if none, allocate one */ - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - p_ccb = avdt_ccb_alloc(bd_addr); - if (p_ccb == NULL) - { - /* could not allocate channel control block */ - result = AVDT_NO_RESOURCES; - } - } - else if (p_ccb->ll_opened == false) - { - AVDT_TRACE_WARNING("AVDT_ConnectReq: CCB LL is in the middle of opening"); - - /* ccb was already allocated for the incoming signalling. */ - result = AVDT_BUSY; +uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask, + tAVDT_CTRL_CBACK* p_cback) { + tAVDT_CCB* p_ccb = NULL; + uint16_t result = AVDT_SUCCESS; + tAVDT_CCB_EVT evt; + + /* find channel control block for this bd addr; if none, allocate one */ + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + p_ccb = avdt_ccb_alloc(bd_addr); + if (p_ccb == NULL) { + /* could not allocate channel control block */ + result = AVDT_NO_RESOURCES; } - - if (result == AVDT_SUCCESS) - { - /* send event to ccb */ - evt.connect.p_cback = p_cback; - evt.connect.sec_mask = sec_mask; - avdt_ccb_event(p_ccb, AVDT_CCB_API_CONNECT_REQ_EVT, &evt); - } - return result; + } else if (p_ccb->ll_opened == false) { + AVDT_TRACE_WARNING("AVDT_ConnectReq: CCB LL is in the middle of opening"); + + /* ccb was already allocated for the incoming signalling. */ + result = AVDT_BUSY; + } + + if (result == AVDT_SUCCESS) { + /* send event to ccb */ + evt.connect.p_cback = p_cback; + evt.connect.sec_mask = sec_mask; + avdt_ccb_event(p_ccb, AVDT_CCB_API_CONNECT_REQ_EVT, &evt); + } + return result; } /******************************************************************************* @@ -1020,26 +935,23 @@ uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask, tAVDT_CTRL_CBACK *p_ * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK *p_cback) -{ - tAVDT_CCB *p_ccb = NULL; - uint16_t result = AVDT_SUCCESS; - tAVDT_CCB_EVT evt; - - /* find channel control block for this bd addr; if none, error */ - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - result = AVDT_BAD_PARAMS; - } - - if (result == AVDT_SUCCESS) - { - /* send event to ccb */ - evt.disconnect.p_cback = p_cback; - avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCONNECT_REQ_EVT, &evt); - } - return result; +uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK* p_cback) { + tAVDT_CCB* p_ccb = NULL; + uint16_t result = AVDT_SUCCESS; + tAVDT_CCB_EVT evt; + + /* find channel control block for this bd addr; if none, error */ + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + result = AVDT_BAD_PARAMS; + } + + if (result == AVDT_SUCCESS) { + /* send event to ccb */ + evt.disconnect.p_cback = p_cback; + avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCONNECT_REQ_EVT, &evt); + } + return result; } /******************************************************************************* @@ -1051,24 +963,22 @@ uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK *p_cback) * Returns CID if successful, otherwise 0. * ******************************************************************************/ -uint16_t AVDT_GetL2CapChannel(uint8_t handle) -{ - tAVDT_SCB *p_scb; - tAVDT_CCB *p_ccb; - uint8_t tcid; - uint16_t lcid = 0; - - /* map handle to scb */ - if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) - && ((p_ccb = p_scb->p_ccb) != NULL)) - { - /* get tcid from type, scb */ - tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb); - - lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; - } - - return (lcid); +uint16_t AVDT_GetL2CapChannel(uint8_t handle) { + tAVDT_SCB* p_scb; + tAVDT_CCB* p_ccb; + uint8_t tcid; + uint16_t lcid = 0; + + /* map handle to scb */ + if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) && + ((p_ccb = p_scb->p_ccb) != NULL)) { + /* get tcid from type, scb */ + tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb); + + lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; + } + + return (lcid); } /******************************************************************************* @@ -1081,28 +991,24 @@ uint16_t AVDT_GetL2CapChannel(uint8_t handle) * Returns CID if successful, otherwise 0. * ******************************************************************************/ -uint16_t AVDT_GetSignalChannel(uint8_t handle, BD_ADDR bd_addr) -{ - tAVDT_SCB *p_scb; - tAVDT_CCB *p_ccb; - uint8_t tcid = 0; /* tcid is always 0 for signal channel */ - uint16_t lcid = 0; - - /* map handle to scb */ - if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) - && ((p_ccb = p_scb->p_ccb) != NULL)) - { - lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; - } - else { - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb != NULL) - { - lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; - } +uint16_t AVDT_GetSignalChannel(uint8_t handle, BD_ADDR bd_addr) { + tAVDT_SCB* p_scb; + tAVDT_CCB* p_ccb; + uint8_t tcid = 0; /* tcid is always 0 for signal channel */ + uint16_t lcid = 0; + + /* map handle to scb */ + if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) && + ((p_ccb = p_scb->p_ccb) != NULL)) { + lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; + } else { + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb != NULL) { + lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; } + } - return (lcid); + return (lcid); } #if (AVDT_REPORTING == TRUE) @@ -1118,86 +1024,82 @@ uint16_t AVDT_GetSignalChannel(uint8_t handle, BD_ADDR bd_addr) * ******************************************************************************/ uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type, - tAVDT_REPORT_DATA *p_data) -{ - tAVDT_SCB *p_scb; - uint16_t result = AVDT_BAD_PARAMS; - tAVDT_TC_TBL *p_tbl; - uint8_t *p, *plen, *pm1, *p_end; - uint32_t ssrc; - uint16_t len; - - /* map handle to scb && verify parameters */ - if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) - && (p_scb->p_ccb != NULL) - && (((type == AVDT_RTCP_PT_SR) && (p_scb->cs.tsep == AVDT_TSEP_SRC)) || - ((type == AVDT_RTCP_PT_RR) && (p_scb->cs.tsep == AVDT_TSEP_SNK)) || - (type == AVDT_RTCP_PT_SDES)) ) - { - result = AVDT_NO_RESOURCES; - - /* build SR - assume fit in one packet */ - p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb); - if (p_tbl->state == AVDT_AD_ST_OPEN) { - BT_HDR *p_pkt = (BT_HDR *)osi_malloc(p_tbl->peer_mtu); - - p_pkt->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - pm1 = p; - *p++ = AVDT_MEDIA_OCTET1 | 1; - *p++ = type; - /* save the location for length */ - plen = p; - p+= 2; - ssrc = avdt_scb_gen_ssrc(p_scb); - UINT32_TO_BE_STREAM(p, ssrc); - - switch(type) - { - case AVDT_RTCP_PT_SR: /* Sender Report */ - *pm1 = AVDT_MEDIA_OCTET1; - UINT32_TO_BE_STREAM(p, p_data->sr.ntp_sec); - UINT32_TO_BE_STREAM(p, p_data->sr.ntp_frac); - UINT32_TO_BE_STREAM(p, p_data->sr.rtp_time); - UINT32_TO_BE_STREAM(p, p_data->sr.pkt_count); - UINT32_TO_BE_STREAM(p, p_data->sr.octet_count); - break; - - case AVDT_RTCP_PT_RR: /* Receiver Report */ - *p++ = p_data->rr.frag_lost; - AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost); - p_data->rr.packet_lost &= 0xFFFFFF; - AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost); - UINT24_TO_BE_STREAM(p, p_data->rr.packet_lost); - UINT32_TO_BE_STREAM(p, p_data->rr.seq_num_rcvd); - UINT32_TO_BE_STREAM(p, p_data->rr.jitter); - UINT32_TO_BE_STREAM(p, p_data->rr.lsr); - UINT32_TO_BE_STREAM(p, p_data->rr.dlsr); - break; - - case AVDT_RTCP_PT_SDES: /* Source Description */ - *p++ = AVDT_RTCP_SDES_CNAME; - len = strlen((char *)p_data->cname); - if(len > AVDT_MAX_CNAME_SIZE) - len = AVDT_MAX_CNAME_SIZE; - *p++ = (uint8_t)len; - strlcpy((char *)p, (char *)p_data->cname, len+1); - p += len; - break; - } - p_end = p; - len = p - pm1 - 1; - UINT16_TO_BE_STREAM(plen, len); - - /* set the actual payload length */ - p_pkt->len = p_end - p; - /* send the packet */ - if(L2CAP_DW_FAILED != avdt_ad_write_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, p_pkt)) - result = AVDT_SUCCESS; - } + tAVDT_REPORT_DATA* p_data) { + tAVDT_SCB* p_scb; + uint16_t result = AVDT_BAD_PARAMS; + tAVDT_TC_TBL* p_tbl; + uint8_t *p, *plen, *pm1, *p_end; + uint32_t ssrc; + uint16_t len; + + /* map handle to scb && verify parameters */ + if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) && (p_scb->p_ccb != NULL) && + (((type == AVDT_RTCP_PT_SR) && (p_scb->cs.tsep == AVDT_TSEP_SRC)) || + ((type == AVDT_RTCP_PT_RR) && (p_scb->cs.tsep == AVDT_TSEP_SNK)) || + (type == AVDT_RTCP_PT_SDES))) { + result = AVDT_NO_RESOURCES; + + /* build SR - assume fit in one packet */ + p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb); + if (p_tbl->state == AVDT_AD_ST_OPEN) { + BT_HDR* p_pkt = (BT_HDR*)osi_malloc(p_tbl->peer_mtu); + + p_pkt->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + pm1 = p; + *p++ = AVDT_MEDIA_OCTET1 | 1; + *p++ = type; + /* save the location for length */ + plen = p; + p += 2; + ssrc = avdt_scb_gen_ssrc(p_scb); + UINT32_TO_BE_STREAM(p, ssrc); + + switch (type) { + case AVDT_RTCP_PT_SR: /* Sender Report */ + *pm1 = AVDT_MEDIA_OCTET1; + UINT32_TO_BE_STREAM(p, p_data->sr.ntp_sec); + UINT32_TO_BE_STREAM(p, p_data->sr.ntp_frac); + UINT32_TO_BE_STREAM(p, p_data->sr.rtp_time); + UINT32_TO_BE_STREAM(p, p_data->sr.pkt_count); + UINT32_TO_BE_STREAM(p, p_data->sr.octet_count); + break; + + case AVDT_RTCP_PT_RR: /* Receiver Report */ + *p++ = p_data->rr.frag_lost; + AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost); + p_data->rr.packet_lost &= 0xFFFFFF; + AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost); + UINT24_TO_BE_STREAM(p, p_data->rr.packet_lost); + UINT32_TO_BE_STREAM(p, p_data->rr.seq_num_rcvd); + UINT32_TO_BE_STREAM(p, p_data->rr.jitter); + UINT32_TO_BE_STREAM(p, p_data->rr.lsr); + UINT32_TO_BE_STREAM(p, p_data->rr.dlsr); + break; + + case AVDT_RTCP_PT_SDES: /* Source Description */ + *p++ = AVDT_RTCP_SDES_CNAME; + len = strlen((char*)p_data->cname); + if (len > AVDT_MAX_CNAME_SIZE) len = AVDT_MAX_CNAME_SIZE; + *p++ = (uint8_t)len; + strlcpy((char*)p, (char*)p_data->cname, len + 1); + p += len; + break; + } + p_end = p; + len = p - pm1 - 1; + UINT16_TO_BE_STREAM(plen, len); + + /* set the actual payload length */ + p_pkt->len = p_end - p; + /* send the packet */ + if (L2CAP_DW_FAILED != + avdt_ad_write_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, p_pkt)) + result = AVDT_SUCCESS; } + } - return result; + return result; } #endif @@ -1222,10 +1124,8 @@ uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type, * the input parameter is 0xff. * *****************************************************************************/ -uint8_t AVDT_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - avdt_cb.trace_level = new_level; +uint8_t AVDT_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) avdt_cb.trace_level = new_level; - return (avdt_cb.trace_level); + return (avdt_cb.trace_level); } diff --git a/stack/avdt/avdt_ccb.cc b/stack/avdt/avdt_ccb.cc index 5fc06daf7..9c09ab54a 100644 --- a/stack/avdt/avdt_ccb.cc +++ b/stack/avdt/avdt_ccb.cc @@ -24,13 +24,13 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btu.h" #include "osi/include/osi.h" @@ -40,351 +40,305 @@ #if (AVDT_DEBUG == TRUE) /* verbose state strings for trace */ -const char * const avdt_ccb_st_str[] = { - "CCB_IDLE_ST", - "CCB_OPENING_ST", - "CCB_OPEN_ST", - "CCB_CLOSING_ST" -}; +const char* const avdt_ccb_st_str[] = {"CCB_IDLE_ST", "CCB_OPENING_ST", + "CCB_OPEN_ST", "CCB_CLOSING_ST"}; /* verbose event strings for trace */ -const char * const avdt_ccb_evt_str[] = { - "API_DISCOVER_REQ_EVT", - "API_GETCAP_REQ_EVT", - "API_START_REQ_EVT", - "API_SUSPEND_REQ_EVT", - "API_DISCOVER_RSP_EVT", - "API_GETCAP_RSP_EVT", - "API_START_RSP_EVT", - "API_SUSPEND_RSP_EVT", - "API_CONNECT_REQ_EVT", - "API_DISCONNECT_REQ_EVT", - "MSG_DISCOVER_CMD_EVT", - "MSG_GETCAP_CMD_EVT", - "MSG_START_CMD_EVT", - "MSG_SUSPEND_CMD_EVT", - "MSG_DISCOVER_RSP_EVT", - "MSG_GETCAP_RSP_EVT", - "MSG_START_RSP_EVT", - "MSG_SUSPEND_RSP_EVT", - "RCVRSP_EVT", - "SENDMSG_EVT", - "RET_TOUT_EVT", - "RSP_TOUT_EVT", - "IDLE_TOUT_EVT", - "UL_OPEN_EVT", - "UL_CLOSE_EVT", - "LL_OPEN_EVT", - "LL_CLOSE_EVT", - "LL_CONG_EVT" -}; +const char* const avdt_ccb_evt_str[] = { + "API_DISCOVER_REQ_EVT", "API_GETCAP_REQ_EVT", + "API_START_REQ_EVT", "API_SUSPEND_REQ_EVT", + "API_DISCOVER_RSP_EVT", "API_GETCAP_RSP_EVT", + "API_START_RSP_EVT", "API_SUSPEND_RSP_EVT", + "API_CONNECT_REQ_EVT", "API_DISCONNECT_REQ_EVT", + "MSG_DISCOVER_CMD_EVT", "MSG_GETCAP_CMD_EVT", + "MSG_START_CMD_EVT", "MSG_SUSPEND_CMD_EVT", + "MSG_DISCOVER_RSP_EVT", "MSG_GETCAP_RSP_EVT", + "MSG_START_RSP_EVT", "MSG_SUSPEND_RSP_EVT", + "RCVRSP_EVT", "SENDMSG_EVT", + "RET_TOUT_EVT", "RSP_TOUT_EVT", + "IDLE_TOUT_EVT", "UL_OPEN_EVT", + "UL_CLOSE_EVT", "LL_OPEN_EVT", + "LL_CLOSE_EVT", "LL_CONG_EVT"}; #endif - /* action function list */ const tAVDT_CCB_ACTION avdt_ccb_action[] = { - avdt_ccb_chan_open, - avdt_ccb_chan_close, - avdt_ccb_chk_close, - avdt_ccb_hdl_discover_cmd, - avdt_ccb_hdl_discover_rsp, - avdt_ccb_hdl_getcap_cmd, - avdt_ccb_hdl_getcap_rsp, - avdt_ccb_hdl_start_cmd, - avdt_ccb_hdl_start_rsp, - avdt_ccb_hdl_suspend_cmd, - avdt_ccb_hdl_suspend_rsp, - avdt_ccb_snd_discover_cmd, - avdt_ccb_snd_discover_rsp, - avdt_ccb_snd_getcap_cmd, - avdt_ccb_snd_getcap_rsp, - avdt_ccb_snd_start_cmd, - avdt_ccb_snd_start_rsp, - avdt_ccb_snd_suspend_cmd, - avdt_ccb_snd_suspend_rsp, - avdt_ccb_clear_cmds, - avdt_ccb_cmd_fail, - avdt_ccb_free_cmd, - avdt_ccb_cong_state, - avdt_ccb_ret_cmd, - avdt_ccb_snd_cmd, - avdt_ccb_snd_msg, - avdt_ccb_set_reconn, - avdt_ccb_clr_reconn, - avdt_ccb_chk_reconn, - avdt_ccb_chk_timer, - avdt_ccb_set_conn, - avdt_ccb_set_disconn, - avdt_ccb_do_disconn, - avdt_ccb_ll_closed, - avdt_ccb_ll_opened, - avdt_ccb_dealloc -}; + avdt_ccb_chan_open, avdt_ccb_chan_close, + avdt_ccb_chk_close, avdt_ccb_hdl_discover_cmd, + avdt_ccb_hdl_discover_rsp, avdt_ccb_hdl_getcap_cmd, + avdt_ccb_hdl_getcap_rsp, avdt_ccb_hdl_start_cmd, + avdt_ccb_hdl_start_rsp, avdt_ccb_hdl_suspend_cmd, + avdt_ccb_hdl_suspend_rsp, avdt_ccb_snd_discover_cmd, + avdt_ccb_snd_discover_rsp, avdt_ccb_snd_getcap_cmd, + avdt_ccb_snd_getcap_rsp, avdt_ccb_snd_start_cmd, + avdt_ccb_snd_start_rsp, avdt_ccb_snd_suspend_cmd, + avdt_ccb_snd_suspend_rsp, avdt_ccb_clear_cmds, + avdt_ccb_cmd_fail, avdt_ccb_free_cmd, + avdt_ccb_cong_state, avdt_ccb_ret_cmd, + avdt_ccb_snd_cmd, avdt_ccb_snd_msg, + avdt_ccb_set_reconn, avdt_ccb_clr_reconn, + avdt_ccb_chk_reconn, avdt_ccb_chk_timer, + avdt_ccb_set_conn, avdt_ccb_set_disconn, + avdt_ccb_do_disconn, avdt_ccb_ll_closed, + avdt_ccb_ll_opened, avdt_ccb_dealloc}; /* state table information */ -#define AVDT_CCB_ACTIONS 2 /* number of actions */ -#define AVDT_CCB_NEXT_STATE 2 /* position of next state */ -#define AVDT_CCB_NUM_COLS 3 /* number of columns in state tables */ +#define AVDT_CCB_ACTIONS 2 /* number of actions */ +#define AVDT_CCB_NEXT_STATE 2 /* position of next state */ +#define AVDT_CCB_NUM_COLS 3 /* number of columns in state tables */ /* state table for idle state */ const uint8_t avdt_ccb_st_idle[][AVDT_CCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_DISCOVER_REQ_EVT */ -{AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, -/* API_GETCAP_REQ_EVT */ -{AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, -/* API_START_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_SUSPEND_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_DISCOVER_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_GETCAP_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_START_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_SUSPEND_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* API_CONNECT_REQ_EVT */ -{AVDT_CCB_SET_CONN, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, -/* API_DISCONNECT_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_DISCOVER_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_GETCAP_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_DISCOVER_RSP_EVT */ -{AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_GETCAP_RSP_EVT */ -{AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* RCVRSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* SENDMSG_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* RET_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* RSP_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* IDLE_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* UL_OPEN_EVT */ -{AVDT_CCB_CHAN_OPEN, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* UL_CLOSE_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* LL_OPEN_EVT */ -{AVDT_CCB_LL_OPENED, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* LL_CLOSE_EVT */ -{AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* LL_CONG_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_DISCOVER_REQ_EVT */ + {AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, + /* API_GETCAP_REQ_EVT */ + {AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, + /* API_START_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_SUSPEND_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_DISCOVER_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_GETCAP_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_START_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_SUSPEND_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* API_CONNECT_REQ_EVT */ + {AVDT_CCB_SET_CONN, AVDT_CCB_CHAN_OPEN, AVDT_CCB_OPENING_ST}, + /* API_DISCONNECT_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_DISCOVER_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_GETCAP_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_DISCOVER_RSP_EVT */ + {AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_GETCAP_RSP_EVT */ + {AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* RCVRSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* SENDMSG_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* RET_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* RSP_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* IDLE_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* UL_OPEN_EVT */ + {AVDT_CCB_CHAN_OPEN, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* UL_CLOSE_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* LL_OPEN_EVT */ + {AVDT_CCB_LL_OPENED, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* LL_CLOSE_EVT */ + {AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* LL_CONG_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}}; /* state table for opening state */ const uint8_t avdt_ccb_st_opening[][AVDT_CCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_DISCOVER_REQ_EVT */ -{AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_GETCAP_REQ_EVT */ -{AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_START_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_SUSPEND_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_DISCOVER_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_GETCAP_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_START_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_SUSPEND_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_CONNECT_REQ_EVT */ -{AVDT_CCB_SET_CONN, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* API_DISCONNECT_REQ_EVT */ -{AVDT_CCB_SET_DISCONN, AVDT_CCB_DO_DISCONN, AVDT_CCB_CLOSING_ST}, -/* MSG_DISCOVER_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_GETCAP_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_DISCOVER_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_GETCAP_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* RCVRSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* SENDMSG_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* RET_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* RSP_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* IDLE_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* UL_OPEN_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, -/* UL_CLOSE_EVT */ -{AVDT_CCB_CLEAR_CMDS, AVDT_CCB_CHAN_CLOSE, AVDT_CCB_CLOSING_ST}, -/* LL_OPEN_EVT */ -{AVDT_CCB_SND_CMD, AVDT_CCB_LL_OPENED, AVDT_CCB_OPEN_ST}, -/* LL_CLOSE_EVT */ -{AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* LL_CONG_EVT */ -{AVDT_CCB_CONG_STATE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_DISCOVER_REQ_EVT */ + {AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_GETCAP_REQ_EVT */ + {AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_START_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_SUSPEND_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_DISCOVER_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_GETCAP_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_START_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_SUSPEND_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_CONNECT_REQ_EVT */ + {AVDT_CCB_SET_CONN, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* API_DISCONNECT_REQ_EVT */ + {AVDT_CCB_SET_DISCONN, AVDT_CCB_DO_DISCONN, AVDT_CCB_CLOSING_ST}, + /* MSG_DISCOVER_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_GETCAP_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_DISCOVER_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_GETCAP_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* RCVRSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* SENDMSG_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* RET_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* RSP_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* IDLE_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* UL_OPEN_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}, + /* UL_CLOSE_EVT */ + {AVDT_CCB_CLEAR_CMDS, AVDT_CCB_CHAN_CLOSE, AVDT_CCB_CLOSING_ST}, + /* LL_OPEN_EVT */ + {AVDT_CCB_SND_CMD, AVDT_CCB_LL_OPENED, AVDT_CCB_OPEN_ST}, + /* LL_CLOSE_EVT */ + {AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* LL_CONG_EVT */ + {AVDT_CCB_CONG_STATE, AVDT_CCB_IGNORE, AVDT_CCB_OPENING_ST}}; /* state table for open state */ const uint8_t avdt_ccb_st_open[][AVDT_CCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_DISCOVER_REQ_EVT */ -{AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_GETCAP_REQ_EVT */ -{AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_START_REQ_EVT */ -{AVDT_CCB_SND_START_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_SUSPEND_REQ_EVT */ -{AVDT_CCB_SND_SUSPEND_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_DISCOVER_RSP_EVT */ -{AVDT_CCB_SND_DISCOVER_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_GETCAP_RSP_EVT */ -{AVDT_CCB_SND_GETCAP_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_START_RSP_EVT */ -{AVDT_CCB_SND_START_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_SUSPEND_RSP_EVT */ -{AVDT_CCB_SND_SUSPEND_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* API_CONNECT_REQ_EVT */ -{AVDT_CCB_SET_CONN, AVDT_CCB_LL_OPENED, AVDT_CCB_OPEN_ST}, -/* API_DISCONNECT_REQ_EVT */ -{AVDT_CCB_SET_DISCONN, AVDT_CCB_DO_DISCONN, AVDT_CCB_CLOSING_ST}, -/* MSG_DISCOVER_CMD_EVT */ -{AVDT_CCB_HDL_DISCOVER_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* MSG_GETCAP_CMD_EVT */ -{AVDT_CCB_HDL_GETCAP_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_CCB_HDL_START_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_CCB_HDL_SUSPEND_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* MSG_DISCOVER_RSP_EVT */ -{AVDT_CCB_CHK_CLOSE, AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_OPEN_ST}, -/* MSG_GETCAP_RSP_EVT */ -{AVDT_CCB_CHK_CLOSE, AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_OPEN_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* RCVRSP_EVT */ -{AVDT_CCB_FREE_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* SENDMSG_EVT */ -{AVDT_CCB_SND_MSG, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* RET_TOUT_EVT */ -{AVDT_CCB_RET_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* RSP_TOUT_EVT */ -{AVDT_CCB_CMD_FAIL, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, -/* IDLE_TOUT_EVT */ -{AVDT_CCB_CLEAR_CMDS, AVDT_CCB_CHAN_CLOSE, AVDT_CCB_CLOSING_ST}, -/* UL_OPEN_EVT */ -{AVDT_CCB_CHK_TIMER, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* UL_CLOSE_EVT */ -{AVDT_CCB_CHK_CLOSE, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* LL_OPEN_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, -/* LL_CLOSE_EVT */ -{AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* LL_CONG_EVT */ -{AVDT_CCB_CONG_STATE, AVDT_CCB_SND_MSG, AVDT_CCB_OPEN_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_DISCOVER_REQ_EVT */ + {AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_GETCAP_REQ_EVT */ + {AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_START_REQ_EVT */ + {AVDT_CCB_SND_START_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_SUSPEND_REQ_EVT */ + {AVDT_CCB_SND_SUSPEND_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_DISCOVER_RSP_EVT */ + {AVDT_CCB_SND_DISCOVER_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_GETCAP_RSP_EVT */ + {AVDT_CCB_SND_GETCAP_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_START_RSP_EVT */ + {AVDT_CCB_SND_START_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_SUSPEND_RSP_EVT */ + {AVDT_CCB_SND_SUSPEND_RSP, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* API_CONNECT_REQ_EVT */ + {AVDT_CCB_SET_CONN, AVDT_CCB_LL_OPENED, AVDT_CCB_OPEN_ST}, + /* API_DISCONNECT_REQ_EVT */ + {AVDT_CCB_SET_DISCONN, AVDT_CCB_DO_DISCONN, AVDT_CCB_CLOSING_ST}, + /* MSG_DISCOVER_CMD_EVT */ + {AVDT_CCB_HDL_DISCOVER_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* MSG_GETCAP_CMD_EVT */ + {AVDT_CCB_HDL_GETCAP_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_CCB_HDL_START_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_CCB_HDL_SUSPEND_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* MSG_DISCOVER_RSP_EVT */ + {AVDT_CCB_CHK_CLOSE, AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_OPEN_ST}, + /* MSG_GETCAP_RSP_EVT */ + {AVDT_CCB_CHK_CLOSE, AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_OPEN_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* RCVRSP_EVT */ + {AVDT_CCB_FREE_CMD, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* SENDMSG_EVT */ + {AVDT_CCB_SND_MSG, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* RET_TOUT_EVT */ + {AVDT_CCB_RET_CMD, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* RSP_TOUT_EVT */ + {AVDT_CCB_CMD_FAIL, AVDT_CCB_SND_CMD, AVDT_CCB_OPEN_ST}, + /* IDLE_TOUT_EVT */ + {AVDT_CCB_CLEAR_CMDS, AVDT_CCB_CHAN_CLOSE, AVDT_CCB_CLOSING_ST}, + /* UL_OPEN_EVT */ + {AVDT_CCB_CHK_TIMER, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* UL_CLOSE_EVT */ + {AVDT_CCB_CHK_CLOSE, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* LL_OPEN_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_OPEN_ST}, + /* LL_CLOSE_EVT */ + {AVDT_CCB_LL_CLOSED, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* LL_CONG_EVT */ + {AVDT_CCB_CONG_STATE, AVDT_CCB_SND_MSG, AVDT_CCB_OPEN_ST}}; /* state table for closing state */ const uint8_t avdt_ccb_st_closing[][AVDT_CCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_DISCOVER_REQ_EVT */ -{AVDT_CCB_SET_RECONN, AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_CLOSING_ST}, -/* API_GETCAP_REQ_EVT */ -{AVDT_CCB_SET_RECONN, AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_CLOSING_ST}, -/* API_START_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_SUSPEND_REQ_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_DISCOVER_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_GETCAP_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_START_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_SUSPEND_RSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* API_CONNECT_REQ_EVT */ -{AVDT_CCB_SET_RECONN, AVDT_CCB_SET_CONN, AVDT_CCB_CLOSING_ST}, -/* API_DISCONNECT_REQ_EVT */ -{AVDT_CCB_CLR_RECONN, AVDT_CCB_SET_DISCONN, AVDT_CCB_CLOSING_ST}, -/* MSG_DISCOVER_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_GETCAP_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_DISCOVER_RSP_EVT */ -{AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_GETCAP_RSP_EVT */ -{AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* RCVRSP_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* SENDMSG_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* RET_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* RSP_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* IDLE_TOUT_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* UL_OPEN_EVT */ -{AVDT_CCB_SET_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* UL_CLOSE_EVT */ -{AVDT_CCB_CLR_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* LL_OPEN_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, -/* LL_CLOSE_EVT */ -{AVDT_CCB_CHK_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, -/* LL_CONG_EVT */ -{AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_DISCOVER_REQ_EVT */ + {AVDT_CCB_SET_RECONN, AVDT_CCB_SND_DISCOVER_CMD, AVDT_CCB_CLOSING_ST}, + /* API_GETCAP_REQ_EVT */ + {AVDT_CCB_SET_RECONN, AVDT_CCB_SND_GETCAP_CMD, AVDT_CCB_CLOSING_ST}, + /* API_START_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_SUSPEND_REQ_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_DISCOVER_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_GETCAP_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_START_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_SUSPEND_RSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* API_CONNECT_REQ_EVT */ + {AVDT_CCB_SET_RECONN, AVDT_CCB_SET_CONN, AVDT_CCB_CLOSING_ST}, + /* API_DISCONNECT_REQ_EVT */ + {AVDT_CCB_CLR_RECONN, AVDT_CCB_SET_DISCONN, AVDT_CCB_CLOSING_ST}, + /* MSG_DISCOVER_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_GETCAP_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_DISCOVER_RSP_EVT */ + {AVDT_CCB_HDL_DISCOVER_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_GETCAP_RSP_EVT */ + {AVDT_CCB_HDL_GETCAP_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_CCB_HDL_START_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_CCB_HDL_SUSPEND_RSP, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* RCVRSP_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* SENDMSG_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* RET_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* RSP_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* IDLE_TOUT_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* UL_OPEN_EVT */ + {AVDT_CCB_SET_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* UL_CLOSE_EVT */ + {AVDT_CCB_CLR_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* LL_OPEN_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}, + /* LL_CLOSE_EVT */ + {AVDT_CCB_CHK_RECONN, AVDT_CCB_IGNORE, AVDT_CCB_IDLE_ST}, + /* LL_CONG_EVT */ + {AVDT_CCB_IGNORE, AVDT_CCB_IGNORE, AVDT_CCB_CLOSING_ST}}; /* type for state table */ typedef const uint8_t (*tAVDT_CCB_ST_TBL)[AVDT_CCB_NUM_COLS]; /* state table */ const tAVDT_CCB_ST_TBL avdt_ccb_st_tbl[] = { - avdt_ccb_st_idle, - avdt_ccb_st_opening, - avdt_ccb_st_open, - avdt_ccb_st_closing -}; + avdt_ccb_st_idle, avdt_ccb_st_opening, avdt_ccb_st_open, + avdt_ccb_st_closing}; /******************************************************************************* * @@ -396,10 +350,9 @@ const tAVDT_CCB_ST_TBL avdt_ccb_st_tbl[] = { * Returns Nothing. * ******************************************************************************/ -void avdt_ccb_init(void) -{ - memset(&avdt_cb.ccb[0], 0, sizeof(tAVDT_CCB) * AVDT_NUM_LINKS); - avdt_cb.p_ccb_act = (tAVDT_CCB_ACTION *) avdt_ccb_action; +void avdt_ccb_init(void) { + memset(&avdt_cb.ccb[0], 0, sizeof(tAVDT_CCB) * AVDT_NUM_LINKS); + avdt_cb.p_ccb_act = (tAVDT_CCB_ACTION*)avdt_ccb_action; } /******************************************************************************* @@ -412,40 +365,35 @@ void avdt_ccb_init(void) * Returns Nothing. * ******************************************************************************/ -void avdt_ccb_event(tAVDT_CCB *p_ccb, uint8_t event, tAVDT_CCB_EVT *p_data) -{ - tAVDT_CCB_ST_TBL state_table; - uint8_t action; - int i; +void avdt_ccb_event(tAVDT_CCB* p_ccb, uint8_t event, tAVDT_CCB_EVT* p_data) { + tAVDT_CCB_ST_TBL state_table; + uint8_t action; + int i; #if (AVDT_DEBUG == TRUE) - AVDT_TRACE_EVENT("CCB ccb=%d event=%s state=%s", avdt_ccb_to_idx(p_ccb), avdt_ccb_evt_str[event], avdt_ccb_st_str[p_ccb->state]); + AVDT_TRACE_EVENT("CCB ccb=%d event=%s state=%s", avdt_ccb_to_idx(p_ccb), + avdt_ccb_evt_str[event], avdt_ccb_st_str[p_ccb->state]); #endif - /* look up the state table for the current state */ - state_table = avdt_ccb_st_tbl[p_ccb->state]; - - /* set next state */ - if (p_ccb->state != state_table[event][AVDT_CCB_NEXT_STATE]) { - p_ccb->state = state_table[event][AVDT_CCB_NEXT_STATE]; - } - - /* execute action functions */ - for (i = 0; i < AVDT_CCB_ACTIONS; i++) - { - action = state_table[event][i]; - if (action != AVDT_CCB_IGNORE) - { - (*avdt_cb.p_ccb_act[action])(p_ccb, p_data); - } - else - { - break; - } + /* look up the state table for the current state */ + state_table = avdt_ccb_st_tbl[p_ccb->state]; + + /* set next state */ + if (p_ccb->state != state_table[event][AVDT_CCB_NEXT_STATE]) { + p_ccb->state = state_table[event][AVDT_CCB_NEXT_STATE]; + } + + /* execute action functions */ + for (i = 0; i < AVDT_CCB_ACTIONS; i++) { + action = state_table[event][i]; + if (action != AVDT_CCB_IGNORE) { + (*avdt_cb.p_ccb_act[action])(p_ccb, p_data); + } else { + break; } + } } - /******************************************************************************* * * Function avdt_ccb_by_bd @@ -456,29 +404,26 @@ void avdt_ccb_event(tAVDT_CCB *p_ccb, uint8_t event, tAVDT_CCB_EVT *p_data) * Returns pointer to the ccb, or NULL if none found. * ******************************************************************************/ -tAVDT_CCB *avdt_ccb_by_bd(BD_ADDR bd_addr) -{ - tAVDT_CCB *p_ccb = &avdt_cb.ccb[0]; - int i; - - for (i = 0; i < AVDT_NUM_LINKS; i++, p_ccb++) - { - /* if allocated ccb has matching ccb */ - if (p_ccb->allocated && (!memcmp(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN))) - { - break; - } +tAVDT_CCB* avdt_ccb_by_bd(BD_ADDR bd_addr) { + tAVDT_CCB* p_ccb = &avdt_cb.ccb[0]; + int i; + + for (i = 0; i < AVDT_NUM_LINKS; i++, p_ccb++) { + /* if allocated ccb has matching ccb */ + if (p_ccb->allocated && (!memcmp(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN))) { + break; } + } - if (i == AVDT_NUM_LINKS) - { - /* if no ccb found */ - p_ccb = NULL; + if (i == AVDT_NUM_LINKS) { + /* if no ccb found */ + p_ccb = NULL; - AVDT_TRACE_DEBUG("No ccb for addr %02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - } - return p_ccb; + AVDT_TRACE_DEBUG("No ccb for addr %02x-%02x-%02x-%02x-%02x-%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + } + return p_ccb; } /******************************************************************************* @@ -491,34 +436,30 @@ tAVDT_CCB *avdt_ccb_by_bd(BD_ADDR bd_addr) * Returns pointer to the ccb, or NULL if none could be allocated. * ******************************************************************************/ -tAVDT_CCB *avdt_ccb_alloc(BD_ADDR bd_addr) -{ - tAVDT_CCB *p_ccb = &avdt_cb.ccb[0]; - int i; - - for (i = 0; i < AVDT_NUM_LINKS; i++, p_ccb++) - { - if (!p_ccb->allocated) - { - p_ccb->allocated = true; - memcpy(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN); - p_ccb->cmd_q = fixed_queue_new(SIZE_MAX); - p_ccb->rsp_q = fixed_queue_new(SIZE_MAX); - p_ccb->idle_ccb_timer = alarm_new("avdt_ccb.idle_ccb_timer"); - p_ccb->ret_ccb_timer = alarm_new("avdt_ccb.ret_ccb_timer"); - p_ccb->rsp_ccb_timer = alarm_new("avdt_ccb.rsp_ccb_timer"); - AVDT_TRACE_DEBUG("avdt_ccb_alloc %d", i); - break; - } +tAVDT_CCB* avdt_ccb_alloc(BD_ADDR bd_addr) { + tAVDT_CCB* p_ccb = &avdt_cb.ccb[0]; + int i; + + for (i = 0; i < AVDT_NUM_LINKS; i++, p_ccb++) { + if (!p_ccb->allocated) { + p_ccb->allocated = true; + memcpy(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN); + p_ccb->cmd_q = fixed_queue_new(SIZE_MAX); + p_ccb->rsp_q = fixed_queue_new(SIZE_MAX); + p_ccb->idle_ccb_timer = alarm_new("avdt_ccb.idle_ccb_timer"); + p_ccb->ret_ccb_timer = alarm_new("avdt_ccb.ret_ccb_timer"); + p_ccb->rsp_ccb_timer = alarm_new("avdt_ccb.rsp_ccb_timer"); + AVDT_TRACE_DEBUG("avdt_ccb_alloc %d", i); + break; } - - if (i == AVDT_NUM_LINKS) - { - /* out of ccbs */ - p_ccb = NULL; - AVDT_TRACE_WARNING("Out of ccbs"); - } - return p_ccb; + } + + if (i == AVDT_NUM_LINKS) { + /* out of ccbs */ + p_ccb = NULL; + AVDT_TRACE_WARNING("Out of ccbs"); + } + return p_ccb; } /******************************************************************************* @@ -531,16 +472,14 @@ tAVDT_CCB *avdt_ccb_alloc(BD_ADDR bd_addr) * Returns void. * ******************************************************************************/ -void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - AVDT_TRACE_DEBUG("avdt_ccb_dealloc %d", avdt_ccb_to_idx(p_ccb)); - alarm_free(p_ccb->idle_ccb_timer); - alarm_free(p_ccb->ret_ccb_timer); - alarm_free(p_ccb->rsp_ccb_timer); - fixed_queue_free(p_ccb->cmd_q, NULL); - fixed_queue_free(p_ccb->rsp_q, NULL); - memset(p_ccb, 0, sizeof(tAVDT_CCB)); +void avdt_ccb_dealloc(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + AVDT_TRACE_DEBUG("avdt_ccb_dealloc %d", avdt_ccb_to_idx(p_ccb)); + alarm_free(p_ccb->idle_ccb_timer); + alarm_free(p_ccb->ret_ccb_timer); + alarm_free(p_ccb->rsp_ccb_timer); + fixed_queue_free(p_ccb->cmd_q, NULL); + fixed_queue_free(p_ccb->rsp_q, NULL); + memset(p_ccb, 0, sizeof(tAVDT_CCB)); } /******************************************************************************* @@ -553,10 +492,9 @@ void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, * Returns Index of ccb. * ******************************************************************************/ -uint8_t avdt_ccb_to_idx(tAVDT_CCB *p_ccb) -{ - /* use array arithmetic to determine index */ - return (uint8_t) (p_ccb - avdt_cb.ccb); +uint8_t avdt_ccb_to_idx(tAVDT_CCB* p_ccb) { + /* use array arithmetic to determine index */ + return (uint8_t)(p_ccb - avdt_cb.ccb); } /******************************************************************************* @@ -569,20 +507,15 @@ uint8_t avdt_ccb_to_idx(tAVDT_CCB *p_ccb) * Returns pointer to the ccb, or NULL if none found. * ******************************************************************************/ -tAVDT_CCB *avdt_ccb_by_idx(uint8_t idx) -{ - tAVDT_CCB *p_ccb; - - /* verify index */ - if (idx < AVDT_NUM_LINKS) - { - p_ccb = &avdt_cb.ccb[idx]; - } - else - { - p_ccb = NULL; - AVDT_TRACE_WARNING("No ccb for idx %d", idx); - } - return p_ccb; +tAVDT_CCB* avdt_ccb_by_idx(uint8_t idx) { + tAVDT_CCB* p_ccb; + + /* verify index */ + if (idx < AVDT_NUM_LINKS) { + p_ccb = &avdt_cb.ccb[idx]; + } else { + p_ccb = NULL; + AVDT_TRACE_WARNING("No ccb for idx %d", idx); + } + return p_ccb; } - diff --git a/stack/avdt/avdt_ccb_act.cc b/stack/avdt/avdt_ccb_act.cc index 4384aba2d..943855f75 100644 --- a/stack/avdt/avdt_ccb_act.cc +++ b/stack/avdt/avdt_ccb_act.cc @@ -24,18 +24,18 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" #include "bt_common.h" -#include "btu.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btm_api.h" +#include "btu.h" #include "osi/include/osi.h" -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -48,23 +48,22 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns void. * ******************************************************************************/ -static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb) -{ - BT_HDR *p_buf; +static void avdt_ccb_clear_ccb(tAVDT_CCB* p_ccb) { + BT_HDR* p_buf; - /* clear certain ccb variables */ - p_ccb->cong = false; - p_ccb->ret_count = 0; + /* clear certain ccb variables */ + p_ccb->cong = false; + p_ccb->ret_count = 0; - /* free message being fragmented */ - osi_free_and_reset((void **)&p_ccb->p_curr_msg); + /* free message being fragmented */ + osi_free_and_reset((void**)&p_ccb->p_curr_msg); - /* free message being reassembled */ - osi_free_and_reset((void **)&p_ccb->p_rx_msg); + /* free message being reassembled */ + osi_free_and_reset((void**)&p_ccb->p_rx_msg); - /* clear out response queue */ - while ((p_buf = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) - osi_free(p_buf); + /* clear out response queue */ + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) + osi_free(p_buf); } /******************************************************************************* @@ -78,11 +77,9 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb) * Returns void. * ******************************************************************************/ -void avdt_ccb_chan_open(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - BTM_SetOutService(p_ccb->peer_addr, BTM_SEC_SERVICE_AVDTP, AVDT_CHAN_SIG); - avdt_ad_open_req(AVDT_CHAN_SIG, p_ccb, NULL, AVDT_INT); +void avdt_ccb_chan_open(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + BTM_SetOutService(p_ccb->peer_addr, BTM_SEC_SERVICE_AVDTP, AVDT_CHAN_SIG); + avdt_ad_open_req(AVDT_CHAN_SIG, p_ccb, NULL, AVDT_INT); } /******************************************************************************* @@ -96,11 +93,9 @@ void avdt_ccb_chan_open(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_chan_close(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - /* close the transport channel used by this CCB */ - avdt_ad_close_req(AVDT_CHAN_SIG, p_ccb, NULL); +void avdt_ccb_chan_close(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + /* close the transport channel used by this CCB */ + avdt_ad_close_req(AVDT_CHAN_SIG, p_ccb, NULL); } /******************************************************************************* @@ -114,31 +109,26 @@ void avdt_ccb_chan_close(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_chk_close(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - int i; - tAVDT_SCB *p_scb = &avdt_cb.scb[0]; - - /* see if there are any active scbs associated with this ccb */ - for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) - { - if ((p_scb->allocated) && (p_scb->p_ccb == p_ccb)) - { - break; - } - } - - /* if no active scbs start idle timer */ - if (i == AVDT_NUM_SEPS) - { - alarm_cancel(p_ccb->ret_ccb_timer); - alarm_cancel(p_ccb->rsp_ccb_timer); - period_ms_t interval_ms = avdt_cb.rcb.idle_tout * 1000; - alarm_set_on_queue(p_ccb->idle_ccb_timer, interval_ms, - avdt_ccb_idle_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); +void avdt_ccb_chk_close(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + int i; + tAVDT_SCB* p_scb = &avdt_cb.scb[0]; + + /* see if there are any active scbs associated with this ccb */ + for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) { + if ((p_scb->allocated) && (p_scb->p_ccb == p_ccb)) { + break; } + } + + /* if no active scbs start idle timer */ + if (i == AVDT_NUM_SEPS) { + alarm_cancel(p_ccb->ret_ccb_timer); + alarm_cancel(p_ccb->rsp_ccb_timer); + period_ms_t interval_ms = avdt_cb.rcb.idle_tout * 1000; + alarm_set_on_queue(p_ccb->idle_ccb_timer, interval_ms, + avdt_ccb_idle_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + } } /******************************************************************************* @@ -154,32 +144,30 @@ void avdt_ccb_chk_close(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_SEP_INFO sep_info[AVDT_NUM_SEPS]; - tAVDT_SCB *p_scb = &avdt_cb.scb[0]; - int i; - - p_data->msg.discover_rsp.p_sep_info = sep_info; - p_data->msg.discover_rsp.num_seps = 0; - - /* for all allocated scbs */ - for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) - { - if (p_scb->allocated) - { - /* copy sep info */ - sep_info[p_data->msg.discover_rsp.num_seps].in_use = p_scb->in_use; - sep_info[p_data->msg.discover_rsp.num_seps].seid = i + 1; - sep_info[p_data->msg.discover_rsp.num_seps].media_type = p_scb->cs.media_type; - sep_info[p_data->msg.discover_rsp.num_seps].tsep = p_scb->cs.tsep; - - p_data->msg.discover_rsp.num_seps++; - } +void avdt_ccb_hdl_discover_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_SEP_INFO sep_info[AVDT_NUM_SEPS]; + tAVDT_SCB* p_scb = &avdt_cb.scb[0]; + int i; + + p_data->msg.discover_rsp.p_sep_info = sep_info; + p_data->msg.discover_rsp.num_seps = 0; + + /* for all allocated scbs */ + for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) { + if (p_scb->allocated) { + /* copy sep info */ + sep_info[p_data->msg.discover_rsp.num_seps].in_use = p_scb->in_use; + sep_info[p_data->msg.discover_rsp.num_seps].seid = i + 1; + sep_info[p_data->msg.discover_rsp.num_seps].media_type = + p_scb->cs.media_type; + sep_info[p_data->msg.discover_rsp.num_seps].tsep = p_scb->cs.tsep; + + p_data->msg.discover_rsp.num_seps++; } + } - /* send response */ - avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_RSP_EVT, p_data); + /* send response */ + avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_RSP_EVT, p_data); } /******************************************************************************* @@ -194,14 +182,13 @@ void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* we're done with procedure */ - p_ccb->proc_busy = false; - - /* call app callback with results */ - (*p_ccb->proc_cback)(0, p_ccb->peer_addr, AVDT_DISCOVER_CFM_EVT, - (tAVDT_CTRL *)(&p_data->msg.discover_rsp)); +void avdt_ccb_hdl_discover_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* we're done with procedure */ + p_ccb->proc_busy = false; + + /* call app callback with results */ + (*p_ccb->proc_cback)(0, p_ccb->peer_addr, AVDT_DISCOVER_CFM_EVT, + (tAVDT_CTRL*)(&p_data->msg.discover_rsp)); } /******************************************************************************* @@ -217,16 +204,15 @@ void avdt_ccb_hdl_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_SCB *p_scb; +void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_SCB* p_scb; - /* look up scb for seid sent to us */ - p_scb = avdt_scb_by_hdl(p_data->msg.single.seid); + /* look up scb for seid sent to us */ + p_scb = avdt_scb_by_hdl(p_data->msg.single.seid); - p_data->msg.svccap.p_cfg = &p_scb->cs.cfg; + p_data->msg.svccap.p_cfg = &p_scb->cs.cfg; - avdt_ccb_event(p_ccb, AVDT_CCB_API_GETCAP_RSP_EVT, p_data); + avdt_ccb_event(p_ccb, AVDT_CCB_API_GETCAP_RSP_EVT, p_data); } /******************************************************************************* @@ -241,14 +227,13 @@ void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* we're done with procedure */ - p_ccb->proc_busy = false; - - /* call app callback with results */ - (*p_ccb->proc_cback)(0, p_ccb->peer_addr, AVDT_GETCAP_CFM_EVT, - (tAVDT_CTRL *)(&p_data->msg.svccap)); +void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* we're done with procedure */ + p_ccb->proc_busy = false; + + /* call app callback with results */ + (*p_ccb->proc_cback)(0, p_ccb->peer_addr, AVDT_GETCAP_CFM_EVT, + (tAVDT_CTRL*)(&p_data->msg.svccap)); } /******************************************************************************* @@ -264,23 +249,22 @@ void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t err_code = 0; - - /* verify all streams in the right state */ - uint8_t seid = avdt_scb_verify(p_ccb, AVDT_VERIFY_START, p_data->msg.multi.seid_list, - p_data->msg.multi.num_seps, &err_code); - if (seid == 0 && err_code == 0) - { - /* we're ok, send response */ - avdt_ccb_event(p_ccb, AVDT_CCB_API_START_RSP_EVT, p_data); - } else { - /* not ok, send reject */ - p_data->msg.hdr.err_code = err_code; - p_data->msg.hdr.err_param = seid; - avdt_msg_send_rej(p_ccb, AVDT_SIG_START, &p_data->msg); - } +void avdt_ccb_hdl_start_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t err_code = 0; + + /* verify all streams in the right state */ + uint8_t seid = + avdt_scb_verify(p_ccb, AVDT_VERIFY_START, p_data->msg.multi.seid_list, + p_data->msg.multi.num_seps, &err_code); + if (seid == 0 && err_code == 0) { + /* we're ok, send response */ + avdt_ccb_event(p_ccb, AVDT_CCB_API_START_RSP_EVT, p_data); + } else { + /* not ok, send reject */ + p_data->msg.hdr.err_code = err_code; + p_data->msg.hdr.err_param = seid; + avdt_msg_send_rej(p_ccb, AVDT_SIG_START, &p_data->msg); + } } /******************************************************************************* @@ -296,29 +280,26 @@ void avdt_ccb_hdl_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t event; - int i; - uint8_t *p; - tAVDT_SCB *p_scb; - - /* determine rsp or rej event */ - event = (p_data->msg.hdr.err_code == 0) ? - AVDT_SCB_MSG_START_RSP_EVT : AVDT_SCB_MSG_START_REJ_EVT; - - /* get to where seid's are stashed in current cmd */ - p = (uint8_t *)(p_ccb->p_curr_cmd + 1); - - /* little trick here; length of current command equals number of streams */ - for (i = 0; i < p_ccb->p_curr_cmd->len; i++) - { - p_scb = avdt_scb_by_hdl(p[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, event, (tAVDT_SCB_EVT *) &p_data->msg); - } +void avdt_ccb_hdl_start_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t event; + int i; + uint8_t* p; + tAVDT_SCB* p_scb; + + /* determine rsp or rej event */ + event = (p_data->msg.hdr.err_code == 0) ? AVDT_SCB_MSG_START_RSP_EVT + : AVDT_SCB_MSG_START_REJ_EVT; + + /* get to where seid's are stashed in current cmd */ + p = (uint8_t*)(p_ccb->p_curr_cmd + 1); + + /* little trick here; length of current command equals number of streams */ + for (i = 0; i < p_ccb->p_curr_cmd->len; i++) { + p_scb = avdt_scb_by_hdl(p[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, event, (tAVDT_SCB_EVT*)&p_data->msg); } + } } /******************************************************************************* @@ -335,26 +316,23 @@ void avdt_ccb_hdl_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t seid; - uint8_t err_code = 0; - - /* verify all streams in the right state */ - if ((seid = avdt_scb_verify(p_ccb, AVDT_VERIFY_SUSPEND, p_data->msg.multi.seid_list, - p_data->msg.multi.num_seps, &err_code)) == 0 && - err_code == 0) - { - /* we're ok, send response */ - avdt_ccb_event(p_ccb, AVDT_CCB_API_SUSPEND_RSP_EVT, p_data); - } - else - { - /* not ok, send reject */ - p_data->msg.hdr.err_code = err_code; - p_data->msg.hdr.err_param = seid; - avdt_msg_send_rej(p_ccb, AVDT_SIG_SUSPEND, &p_data->msg); - } +void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t seid; + uint8_t err_code = 0; + + /* verify all streams in the right state */ + if ((seid = avdt_scb_verify(p_ccb, AVDT_VERIFY_SUSPEND, + p_data->msg.multi.seid_list, + p_data->msg.multi.num_seps, &err_code)) == 0 && + err_code == 0) { + /* we're ok, send response */ + avdt_ccb_event(p_ccb, AVDT_CCB_API_SUSPEND_RSP_EVT, p_data); + } else { + /* not ok, send reject */ + p_data->msg.hdr.err_code = err_code; + p_data->msg.hdr.err_param = seid; + avdt_msg_send_rej(p_ccb, AVDT_SIG_SUSPEND, &p_data->msg); + } } /******************************************************************************* @@ -372,29 +350,26 @@ void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t event; - int i; - uint8_t *p; - tAVDT_SCB *p_scb; - - /* determine rsp or rej event */ - event = (p_data->msg.hdr.err_code == 0) ? - AVDT_SCB_MSG_SUSPEND_RSP_EVT : AVDT_SCB_MSG_SUSPEND_REJ_EVT; - - /* get to where seid's are stashed in current cmd */ - p = (uint8_t *)(p_ccb->p_curr_cmd + 1); - - /* little trick here; length of current command equals number of streams */ - for (i = 0; i < p_ccb->p_curr_cmd->len; i++) - { - p_scb = avdt_scb_by_hdl(p[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, event, (tAVDT_SCB_EVT *) &p_data->msg); - } +void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t event; + int i; + uint8_t* p; + tAVDT_SCB* p_scb; + + /* determine rsp or rej event */ + event = (p_data->msg.hdr.err_code == 0) ? AVDT_SCB_MSG_SUSPEND_RSP_EVT + : AVDT_SCB_MSG_SUSPEND_REJ_EVT; + + /* get to where seid's are stashed in current cmd */ + p = (uint8_t*)(p_ccb->p_curr_cmd + 1); + + /* little trick here; length of current command equals number of streams */ + for (i = 0; i < p_ccb->p_curr_cmd->len; i++) { + p_scb = avdt_scb_by_hdl(p[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, event, (tAVDT_SCB_EVT*)&p_data->msg); } + } } /******************************************************************************* @@ -410,18 +385,17 @@ void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* store info in ccb struct */ - p_ccb->p_proc_data = p_data->discover.p_sep_info; - p_ccb->proc_cback = p_data->discover.p_cback; - p_ccb->proc_param = p_data->discover.num_seps; - - /* we're busy */ - p_ccb->proc_busy = true; - - /* build and queue discover req */ - avdt_msg_send_cmd(p_ccb, NULL, AVDT_SIG_DISCOVER, NULL); +void avdt_ccb_snd_discover_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* store info in ccb struct */ + p_ccb->p_proc_data = p_data->discover.p_sep_info; + p_ccb->proc_cback = p_data->discover.p_cback; + p_ccb->proc_param = p_data->discover.num_seps; + + /* we're busy */ + p_ccb->proc_busy = true; + + /* build and queue discover req */ + avdt_msg_send_cmd(p_ccb, NULL, AVDT_SIG_DISCOVER, NULL); } /******************************************************************************* @@ -436,10 +410,9 @@ void avdt_ccb_snd_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* send response */ - avdt_msg_send_rsp(p_ccb, AVDT_SIG_DISCOVER, &p_data->msg); +void avdt_ccb_snd_discover_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* send response */ + avdt_msg_send_rsp(p_ccb, AVDT_SIG_DISCOVER, &p_data->msg); } /******************************************************************************* @@ -455,22 +428,21 @@ void avdt_ccb_snd_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t sig_id = AVDT_SIG_GETCAP; +void avdt_ccb_snd_getcap_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t sig_id = AVDT_SIG_GETCAP; - /* store info in ccb struct */ - p_ccb->p_proc_data = p_data->getcap.p_cfg; - p_ccb->proc_cback = p_data->getcap.p_cback; + /* store info in ccb struct */ + p_ccb->p_proc_data = p_data->getcap.p_cfg; + p_ccb->proc_cback = p_data->getcap.p_cback; - /* we're busy */ - p_ccb->proc_busy = true; + /* we're busy */ + p_ccb->proc_busy = true; - /* build and queue discover req */ - if (p_data->msg.hdr.sig_id == AVDT_SIG_GET_ALLCAP) - sig_id = AVDT_SIG_GET_ALLCAP; + /* build and queue discover req */ + if (p_data->msg.hdr.sig_id == AVDT_SIG_GET_ALLCAP) + sig_id = AVDT_SIG_GET_ALLCAP; - avdt_msg_send_cmd(p_ccb, NULL, sig_id, (tAVDT_MSG *) &p_data->getcap.single); + avdt_msg_send_cmd(p_ccb, NULL, sig_id, (tAVDT_MSG*)&p_data->getcap.single); } /******************************************************************************* @@ -485,15 +457,14 @@ void avdt_ccb_snd_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t sig_id = AVDT_SIG_GETCAP; +void avdt_ccb_snd_getcap_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t sig_id = AVDT_SIG_GETCAP; - if (p_data->msg.hdr.sig_id == AVDT_SIG_GET_ALLCAP) - sig_id = AVDT_SIG_GET_ALLCAP; + if (p_data->msg.hdr.sig_id == AVDT_SIG_GET_ALLCAP) + sig_id = AVDT_SIG_GET_ALLCAP; - /* send response */ - avdt_msg_send_rsp(p_ccb, sig_id, &p_data->msg); + /* send response */ + avdt_msg_send_rsp(p_ccb, sig_id, &p_data->msg); } /******************************************************************************* @@ -509,38 +480,35 @@ void avdt_ccb_snd_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - int i; - tAVDT_SCB *p_scb; - tAVDT_MSG avdt_msg; - uint8_t seid_list[AVDT_NUM_SEPS]; - - /* make copy of our seid list */ - memcpy(seid_list, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps); - - /* verify all streams in the right state */ - avdt_msg.hdr.err_param = avdt_scb_verify(p_ccb, AVDT_VERIFY_OPEN, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps, &avdt_msg.hdr.err_code); - if (avdt_msg.hdr.err_param == 0) - { - /* set peer seid list in messsage */ - avdt_scb_peer_seid_list(&p_data->msg.multi); - - /* send command */ - avdt_msg_send_cmd(p_ccb, seid_list, AVDT_SIG_START, &p_data->msg); - } - else - { - /* failed; send ourselves a reject for each stream */ - for (i = 0; i < p_data->msg.multi.num_seps; i++) - { - p_scb = avdt_scb_by_hdl(seid_list[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_MSG_START_REJ_EVT, (tAVDT_SCB_EVT *) &avdt_msg.hdr); - } - } +void avdt_ccb_snd_start_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + int i; + tAVDT_SCB* p_scb; + tAVDT_MSG avdt_msg; + uint8_t seid_list[AVDT_NUM_SEPS]; + + /* make copy of our seid list */ + memcpy(seid_list, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps); + + /* verify all streams in the right state */ + avdt_msg.hdr.err_param = + avdt_scb_verify(p_ccb, AVDT_VERIFY_OPEN, p_data->msg.multi.seid_list, + p_data->msg.multi.num_seps, &avdt_msg.hdr.err_code); + if (avdt_msg.hdr.err_param == 0) { + /* set peer seid list in messsage */ + avdt_scb_peer_seid_list(&p_data->msg.multi); + + /* send command */ + avdt_msg_send_cmd(p_ccb, seid_list, AVDT_SIG_START, &p_data->msg); + } else { + /* failed; send ourselves a reject for each stream */ + for (i = 0; i < p_data->msg.multi.num_seps; i++) { + p_scb = avdt_scb_by_hdl(seid_list[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_MSG_START_REJ_EVT, + (tAVDT_SCB_EVT*)&avdt_msg.hdr); + } } + } } /******************************************************************************* @@ -556,23 +524,20 @@ void avdt_ccb_snd_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_SCB *p_scb; - int i; - - /* send response message */ - avdt_msg_send_rsp(p_ccb, AVDT_SIG_START, &p_data->msg); - - /* send start event to each scb */ - for (i = 0; i < p_data->msg.multi.num_seps; i++) - { - p_scb = avdt_scb_by_hdl(p_data->msg.multi.seid_list[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_MSG_START_CMD_EVT, NULL); - } +void avdt_ccb_snd_start_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_SCB* p_scb; + int i; + + /* send response message */ + avdt_msg_send_rsp(p_ccb, AVDT_SIG_START, &p_data->msg); + + /* send start event to each scb */ + for (i = 0; i < p_data->msg.multi.num_seps; i++) { + p_scb = avdt_scb_by_hdl(p_data->msg.multi.seid_list[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_MSG_START_CMD_EVT, NULL); } + } } /******************************************************************************* @@ -589,38 +554,35 @@ void avdt_ccb_snd_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - int i; - tAVDT_SCB *p_scb; - tAVDT_MSG avdt_msg; - uint8_t seid_list[AVDT_NUM_SEPS]; - - /* make copy of our seid list */ - memcpy(seid_list, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps); - - /* verify all streams in the right state */ - avdt_msg.hdr.err_param = avdt_scb_verify(p_ccb, AVDT_VERIFY_STREAMING, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps, &avdt_msg.hdr.err_code); - if (avdt_msg.hdr.err_param == 0) - { - /* set peer seid list in messsage */ - avdt_scb_peer_seid_list(&p_data->msg.multi); - - /* send command */ - avdt_msg_send_cmd(p_ccb, seid_list, AVDT_SIG_SUSPEND, &p_data->msg); - } - else - { - /* failed; send ourselves a reject for each stream */ - for (i = 0; i < p_data->msg.multi.num_seps; i++) - { - p_scb = avdt_scb_by_hdl(seid_list[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_MSG_SUSPEND_REJ_EVT, (tAVDT_SCB_EVT *) &avdt_msg.hdr); - } - } +void avdt_ccb_snd_suspend_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + int i; + tAVDT_SCB* p_scb; + tAVDT_MSG avdt_msg; + uint8_t seid_list[AVDT_NUM_SEPS]; + + /* make copy of our seid list */ + memcpy(seid_list, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps); + + /* verify all streams in the right state */ + avdt_msg.hdr.err_param = + avdt_scb_verify(p_ccb, AVDT_VERIFY_STREAMING, p_data->msg.multi.seid_list, + p_data->msg.multi.num_seps, &avdt_msg.hdr.err_code); + if (avdt_msg.hdr.err_param == 0) { + /* set peer seid list in messsage */ + avdt_scb_peer_seid_list(&p_data->msg.multi); + + /* send command */ + avdt_msg_send_cmd(p_ccb, seid_list, AVDT_SIG_SUSPEND, &p_data->msg); + } else { + /* failed; send ourselves a reject for each stream */ + for (i = 0; i < p_data->msg.multi.num_seps; i++) { + p_scb = avdt_scb_by_hdl(seid_list[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_MSG_SUSPEND_REJ_EVT, + (tAVDT_SCB_EVT*)&avdt_msg.hdr); + } } + } } /******************************************************************************* @@ -636,23 +598,20 @@ void avdt_ccb_snd_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_SCB *p_scb; - int i; - - /* send response message */ - avdt_msg_send_rsp(p_ccb, AVDT_SIG_SUSPEND, &p_data->msg); - - /* send start event to each scb */ - for (i = 0; i < p_data->msg.multi.num_seps; i++) - { - p_scb = avdt_scb_by_hdl(p_data->msg.multi.seid_list[i]); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, AVDT_SCB_MSG_SUSPEND_CMD_EVT, NULL); - } +void avdt_ccb_snd_suspend_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_SCB* p_scb; + int i; + + /* send response message */ + avdt_msg_send_rsp(p_ccb, AVDT_SIG_SUSPEND, &p_data->msg); + + /* send start event to each scb */ + for (i = 0; i < p_data->msg.multi.num_seps; i++) { + p_scb = avdt_scb_by_hdl(p_data->msg.multi.seid_list[i]); + if (p_scb != NULL) { + avdt_scb_event(p_scb, AVDT_SCB_MSG_SUSPEND_CMD_EVT, NULL); } + } } /******************************************************************************* @@ -669,38 +628,33 @@ void avdt_ccb_snd_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - int i; - tAVDT_SCB *p_scb = &avdt_cb.scb[0]; - uint8_t err_code = AVDT_ERR_CONNECT; - - /* clear the ccb */ - avdt_ccb_clear_ccb(p_ccb); - - /* clear out command queue; this is a little tricky here; we need - ** to handle the case where there is a command on deck in p_curr_cmd, - ** plus we need to clear out the queue - */ - do - { - /* we know p_curr_cmd = NULL after this */ - avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code); - - /* set up next message */ - p_ccb->p_curr_cmd = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q); - - } while (p_ccb->p_curr_cmd != NULL); - - /* send a CC_CLOSE_EVT any active scbs associated with this ccb */ - for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) - { - if ((p_scb->allocated) && (p_scb->p_ccb == p_ccb)) - { - avdt_scb_event(p_scb, AVDT_SCB_CC_CLOSE_EVT, NULL); - } +void avdt_ccb_clear_cmds(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + int i; + tAVDT_SCB* p_scb = &avdt_cb.scb[0]; + uint8_t err_code = AVDT_ERR_CONNECT; + + /* clear the ccb */ + avdt_ccb_clear_ccb(p_ccb); + + /* clear out command queue; this is a little tricky here; we need + ** to handle the case where there is a command on deck in p_curr_cmd, + ** plus we need to clear out the queue + */ + do { + /* we know p_curr_cmd = NULL after this */ + avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT*)&err_code); + + /* set up next message */ + p_ccb->p_curr_cmd = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->cmd_q); + + } while (p_ccb->p_curr_cmd != NULL); + + /* send a CC_CLOSE_EVT any active scbs associated with this ccb */ + for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) { + if ((p_scb->allocated) && (p_scb->p_ccb == p_ccb)) { + avdt_scb_event(p_scb, AVDT_SCB_CC_CLOSE_EVT, NULL); } + } } /******************************************************************************* @@ -715,38 +669,33 @@ void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_MSG msg; - uint8_t evt; - tAVDT_SCB *p_scb; - - if (p_ccb->p_curr_cmd != NULL) - { - /* set up data */ - msg.hdr.err_code = p_data->err_code; - msg.hdr.err_param = 0; - msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); - - /* pretend that we received a rej message */ - evt = avdt_msg_rej_2_evt[p_ccb->p_curr_cmd->event - 1]; - - if (evt & AVDT_CCB_MKR) - { - avdt_ccb_event(p_ccb, (uint8_t) (evt & ~AVDT_CCB_MKR), (tAVDT_CCB_EVT *) &msg); - } - else - { - /* we get the scb out of the current cmd */ - p_scb = avdt_scb_by_hdl(*((uint8_t *)(p_ccb->p_curr_cmd + 1))); - if (p_scb != NULL) - { - avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT *) &msg); - } - } - - osi_free_and_reset((void **)&p_ccb->p_curr_cmd); +void avdt_ccb_cmd_fail(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_MSG msg; + uint8_t evt; + tAVDT_SCB* p_scb; + + if (p_ccb->p_curr_cmd != NULL) { + /* set up data */ + msg.hdr.err_code = p_data->err_code; + msg.hdr.err_param = 0; + msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); + + /* pretend that we received a rej message */ + evt = avdt_msg_rej_2_evt[p_ccb->p_curr_cmd->event - 1]; + + if (evt & AVDT_CCB_MKR) { + avdt_ccb_event(p_ccb, (uint8_t)(evt & ~AVDT_CCB_MKR), + (tAVDT_CCB_EVT*)&msg); + } else { + /* we get the scb out of the current cmd */ + p_scb = avdt_scb_by_hdl(*((uint8_t*)(p_ccb->p_curr_cmd + 1))); + if (p_scb != NULL) { + avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT*)&msg); + } } + + osi_free_and_reset((void**)&p_ccb->p_curr_cmd); + } } /******************************************************************************* @@ -760,10 +709,8 @@ void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - osi_free_and_reset((void **)&p_ccb->p_curr_cmd); +void avdt_ccb_free_cmd(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + osi_free_and_reset((void**)&p_ccb->p_curr_cmd); } /******************************************************************************* @@ -777,9 +724,8 @@ void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_cong_state(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - p_ccb->cong = p_data->llcong; +void avdt_ccb_cong_state(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + p_ccb->cong = p_data->llcong; } /******************************************************************************* @@ -795,40 +741,37 @@ void avdt_ccb_cong_state(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - uint8_t err_code = AVDT_ERR_TIMEOUT; - - p_ccb->ret_count++; - if (p_ccb->ret_count == AVDT_RET_MAX) - { - /* command failed */ - p_ccb->ret_count = 0; - avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code); - - /* go to next queued command */ - avdt_ccb_snd_cmd(p_ccb, p_data); - } - else - { - /* if command pending and we're not congested and not sending a fragment */ - if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd != NULL)) - { - /* make copy of message in p_curr_cmd and send it */ - BT_HDR *p_msg = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - memcpy(p_msg, p_ccb->p_curr_cmd, - (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + p_ccb->p_curr_cmd->len)); - avdt_msg_send(p_ccb, p_msg); - } +void avdt_ccb_ret_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + uint8_t err_code = AVDT_ERR_TIMEOUT; - /* restart ret timer */ - alarm_cancel(p_ccb->idle_ccb_timer); - alarm_cancel(p_ccb->rsp_ccb_timer); - period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000; - alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms, - avdt_ccb_ret_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); + p_ccb->ret_count++; + if (p_ccb->ret_count == AVDT_RET_MAX) { + /* command failed */ + p_ccb->ret_count = 0; + avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT*)&err_code); + + /* go to next queued command */ + avdt_ccb_snd_cmd(p_ccb, p_data); + } else { + /* if command pending and we're not congested and not sending a fragment */ + if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && + (p_ccb->p_curr_cmd != NULL)) { + /* make copy of message in p_curr_cmd and send it */ + BT_HDR* p_msg = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + memcpy(p_msg, p_ccb->p_curr_cmd, + (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + + p_ccb->p_curr_cmd->len)); + avdt_msg_send(p_ccb, p_msg); } + + /* restart ret timer */ + alarm_cancel(p_ccb->idle_ccb_timer); + alarm_cancel(p_ccb->rsp_ccb_timer); + period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000; + alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms, + avdt_ccb_ret_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + } } /******************************************************************************* @@ -842,26 +785,23 @@ void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - BT_HDR *p_msg; - - /* do we have commands to send? send next command; make sure we're clear; - ** not congested, not sending fragment, not waiting for response - */ - if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd == NULL)) - { - p_msg = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->cmd_q); - if (p_msg != NULL) - { - /* make a copy of buffer in p_curr_cmd */ - p_ccb->p_curr_cmd = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - memcpy(p_ccb->p_curr_cmd, p_msg, - (sizeof(BT_HDR) + p_msg->offset + p_msg->len)); - avdt_msg_send(p_ccb, p_msg); - } +void avdt_ccb_snd_cmd(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + BT_HDR* p_msg; + + /* do we have commands to send? send next command; make sure we're clear; + ** not congested, not sending fragment, not waiting for response + */ + if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && + (p_ccb->p_curr_cmd == NULL)) { + p_msg = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->cmd_q); + if (p_msg != NULL) { + /* make a copy of buffer in p_curr_cmd */ + p_ccb->p_curr_cmd = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + memcpy(p_ccb->p_curr_cmd, p_msg, + (sizeof(BT_HDR) + p_msg->offset + p_msg->len)); + avdt_msg_send(p_ccb, p_msg); } + } } /******************************************************************************* @@ -874,35 +814,28 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - BT_HDR *p_msg; - - /* if not congested */ - if (!p_ccb->cong) - { - /* are we sending a fragmented message? continue sending fragment */ - if (p_ccb->p_curr_msg != NULL) - { - avdt_msg_send(p_ccb, NULL); - } - /* do we have responses to send? send them */ - else if (!fixed_queue_is_empty(p_ccb->rsp_q)) - { - while ((p_msg = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) - { - if (avdt_msg_send(p_ccb, p_msg) == true) - { - /* break out if congested */ - break; - } - } +void avdt_ccb_snd_msg(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + BT_HDR* p_msg; + + /* if not congested */ + if (!p_ccb->cong) { + /* are we sending a fragmented message? continue sending fragment */ + if (p_ccb->p_curr_msg != NULL) { + avdt_msg_send(p_ccb, NULL); + } + /* do we have responses to send? send them */ + else if (!fixed_queue_is_empty(p_ccb->rsp_q)) { + while ((p_msg = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL) { + if (avdt_msg_send(p_ccb, p_msg) == true) { + /* break out if congested */ + break; } - - /* do we have commands to send? send next command */ - avdt_ccb_snd_cmd(p_ccb, NULL); + } } + + /* do we have commands to send? send next command */ + avdt_ccb_snd_cmd(p_ccb, NULL); + } } /******************************************************************************* @@ -917,10 +850,8 @@ void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_set_reconn(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - p_ccb->reconn = true; +void avdt_ccb_set_reconn(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + p_ccb->reconn = true; } /******************************************************************************* @@ -933,10 +864,8 @@ void avdt_ccb_set_reconn(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_clr_reconn(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - p_ccb->reconn = false; +void avdt_ccb_clr_reconn(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + p_ccb->reconn = false; } /******************************************************************************* @@ -951,28 +880,23 @@ void avdt_ccb_clr_reconn(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_chk_reconn(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - uint8_t err_code = AVDT_ERR_CONNECT; +void avdt_ccb_chk_reconn(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + uint8_t err_code = AVDT_ERR_CONNECT; - if (p_ccb->reconn) - { - p_ccb->reconn = false; + if (p_ccb->reconn) { + p_ccb->reconn = false; - /* clear out ccb */ - avdt_ccb_clear_ccb(p_ccb); + /* clear out ccb */ + avdt_ccb_clear_ccb(p_ccb); - /* clear out current command, if any */ - avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT *) &err_code); + /* clear out current command, if any */ + avdt_ccb_cmd_fail(p_ccb, (tAVDT_CCB_EVT*)&err_code); - /* reopen the signaling channel */ - avdt_ccb_event(p_ccb, AVDT_CCB_UL_OPEN_EVT, NULL); - } - else - { - avdt_ccb_ll_closed(p_ccb, NULL); - } + /* reopen the signaling channel */ + avdt_ccb_event(p_ccb, AVDT_CCB_UL_OPEN_EVT, NULL); + } else { + avdt_ccb_ll_closed(p_ccb, NULL); + } } /******************************************************************************* @@ -986,10 +910,8 @@ void avdt_ccb_chk_reconn(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - alarm_cancel(p_ccb->idle_ccb_timer); +void avdt_ccb_chk_timer(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + alarm_cancel(p_ccb->idle_ccb_timer); } /******************************************************************************* @@ -1002,14 +924,14 @@ void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_set_conn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* save callback */ - p_ccb->p_conn_cback = p_data->connect.p_cback; - - /* set security level */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP, p_data->connect.sec_mask, - AVDT_PSM, BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG); +void avdt_ccb_set_conn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* save callback */ + p_ccb->p_conn_cback = p_data->connect.p_cback; + + /* set security level */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_AVDTP, + p_data->connect.sec_mask, AVDT_PSM, BTM_SEC_PROTO_AVDT, + AVDT_CHAN_SIG); } /******************************************************************************* @@ -1022,15 +944,14 @@ void avdt_ccb_set_conn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_set_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - /* - AVDT_TRACE_EVENT("avdt_ccb_set_disconn:conn:x%x, api:x%x", - p_ccb->p_conn_cback, p_data->disconnect.p_cback); - */ - /* save callback */ - if (p_data->disconnect.p_cback) - p_ccb->p_conn_cback = p_data->disconnect.p_cback; +void avdt_ccb_set_disconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + /* + AVDT_TRACE_EVENT("avdt_ccb_set_disconn:conn:x%x, api:x%x", + p_ccb->p_conn_cback, p_data->disconnect.p_cback); + */ + /* save callback */ + if (p_data->disconnect.p_cback) + p_ccb->p_conn_cback = p_data->disconnect.p_cback; } /******************************************************************************* @@ -1043,14 +964,12 @@ void avdt_ccb_set_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void avdt_ccb_do_disconn(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - /* clear any pending commands */ - avdt_ccb_clear_cmds(p_ccb, NULL); - - /* close channel */ - avdt_ccb_chan_close(p_ccb, NULL); +void avdt_ccb_do_disconn(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + /* clear any pending commands */ + avdt_ccb_clear_cmds(p_ccb, NULL); + + /* close channel */ + avdt_ccb_chan_close(p_ccb, NULL); } /******************************************************************************* @@ -1063,31 +982,27 @@ void avdt_ccb_do_disconn(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_ll_closed(tAVDT_CCB *p_ccb, - UNUSED_ATTR tAVDT_CCB_EVT *p_data) -{ - tAVDT_CTRL_CBACK *p_cback; - BD_ADDR bd_addr; - tAVDT_CTRL avdt_ctrl; - - /* clear any pending commands */ - avdt_ccb_clear_cmds(p_ccb, NULL); - - /* save callback pointer, bd addr */ - p_cback = p_ccb->p_conn_cback; - if (!p_cback) - p_cback = avdt_cb.p_conn_cback; - memcpy(bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); - - /* dealloc ccb */ - avdt_ccb_dealloc(p_ccb, NULL); - - /* call callback */ - if (p_cback) - { - avdt_ctrl.hdr.err_code = 0; - (*p_cback)(0, bd_addr, AVDT_DISCONNECT_IND_EVT, &avdt_ctrl); - } +void avdt_ccb_ll_closed(tAVDT_CCB* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) { + tAVDT_CTRL_CBACK* p_cback; + BD_ADDR bd_addr; + tAVDT_CTRL avdt_ctrl; + + /* clear any pending commands */ + avdt_ccb_clear_cmds(p_ccb, NULL); + + /* save callback pointer, bd addr */ + p_cback = p_ccb->p_conn_cback; + if (!p_cback) p_cback = avdt_cb.p_conn_cback; + memcpy(bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); + + /* dealloc ccb */ + avdt_ccb_dealloc(p_ccb, NULL); + + /* call callback */ + if (p_cback) { + avdt_ctrl.hdr.err_code = 0; + (*p_cback)(0, bd_addr, AVDT_DISCONNECT_IND_EVT, &avdt_ctrl); + } } /******************************************************************************* @@ -1100,20 +1015,18 @@ void avdt_ccb_ll_closed(tAVDT_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void avdt_ccb_ll_opened(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; +void avdt_ccb_ll_opened(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; - p_ccb->ll_opened = true; + p_ccb->ll_opened = true; - if (!p_ccb->p_conn_cback) - p_ccb->p_conn_cback = avdt_cb.p_conn_cback; + if (!p_ccb->p_conn_cback) p_ccb->p_conn_cback = avdt_cb.p_conn_cback; - /* call callback */ - if (p_ccb->p_conn_cback) - { - avdt_ctrl.hdr.err_code = 0; - avdt_ctrl.hdr.err_param = p_data->msg.hdr.err_param; - (*p_ccb->p_conn_cback)(0, p_ccb->peer_addr, AVDT_CONNECT_IND_EVT, &avdt_ctrl); - } + /* call callback */ + if (p_ccb->p_conn_cback) { + avdt_ctrl.hdr.err_code = 0; + avdt_ctrl.hdr.err_param = p_data->msg.hdr.err_param; + (*p_ccb->p_conn_cback)(0, p_ccb->peer_addr, AVDT_CONNECT_IND_EVT, + &avdt_ctrl); + } } diff --git a/stack/avdt/avdt_defs.h b/stack/avdt/avdt_defs.h index 898c8f24c..02e924169 100644 --- a/stack/avdt/avdt_defs.h +++ b/stack/avdt/avdt_defs.h @@ -30,213 +30,213 @@ ****************************************************************************/ /* signalling packet type */ -#define AVDT_PKT_TYPE_SINGLE 0 /* single packet */ -#define AVDT_PKT_TYPE_START 1 /* start packet */ -#define AVDT_PKT_TYPE_CONT 2 /* continue packet */ -#define AVDT_PKT_TYPE_END 3 /* end packet */ +#define AVDT_PKT_TYPE_SINGLE 0 /* single packet */ +#define AVDT_PKT_TYPE_START 1 /* start packet */ +#define AVDT_PKT_TYPE_CONT 2 /* continue packet */ +#define AVDT_PKT_TYPE_END 3 /* end packet */ /* signalling message type */ -#define AVDT_MSG_TYPE_CMD 0 /* command */ -#define AVDT_MSG_TYPE_GRJ 1 /* general reject */ -#define AVDT_MSG_TYPE_RSP 2 /* response accept */ -#define AVDT_MSG_TYPE_REJ 3 /* response reject */ +#define AVDT_MSG_TYPE_CMD 0 /* command */ +#define AVDT_MSG_TYPE_GRJ 1 /* general reject */ +#define AVDT_MSG_TYPE_RSP 2 /* response accept */ +#define AVDT_MSG_TYPE_REJ 3 /* response reject */ /* signalling messages */ -#define AVDT_SIG_DISCOVER 1 /* discover */ -#define AVDT_SIG_GETCAP 2 /* get capabilities */ -#define AVDT_SIG_SETCONFIG 3 /* set configuration */ -#define AVDT_SIG_GETCONFIG 4 /* get configuration */ -#define AVDT_SIG_RECONFIG 5 /* reconfigure */ -#define AVDT_SIG_OPEN 6 /* open */ -#define AVDT_SIG_START 7 /* start */ -#define AVDT_SIG_CLOSE 8 /* close */ -#define AVDT_SIG_SUSPEND 9 /* suspend */ -#define AVDT_SIG_ABORT 10 /* abort */ -#define AVDT_SIG_SECURITY 11 /* security control */ -#define AVDT_SIG_GET_ALLCAP 12 /* get all capabilities */ -#define AVDT_SIG_DELAY_RPT 13 /* delay report */ +#define AVDT_SIG_DISCOVER 1 /* discover */ +#define AVDT_SIG_GETCAP 2 /* get capabilities */ +#define AVDT_SIG_SETCONFIG 3 /* set configuration */ +#define AVDT_SIG_GETCONFIG 4 /* get configuration */ +#define AVDT_SIG_RECONFIG 5 /* reconfigure */ +#define AVDT_SIG_OPEN 6 /* open */ +#define AVDT_SIG_START 7 /* start */ +#define AVDT_SIG_CLOSE 8 /* close */ +#define AVDT_SIG_SUSPEND 9 /* suspend */ +#define AVDT_SIG_ABORT 10 /* abort */ +#define AVDT_SIG_SECURITY 11 /* security control */ +#define AVDT_SIG_GET_ALLCAP 12 /* get all capabilities */ +#define AVDT_SIG_DELAY_RPT 13 /* delay report */ /* maximum signal value */ -#define AVDT_SIG_MAX AVDT_SIG_DELAY_RPT +#define AVDT_SIG_MAX AVDT_SIG_DELAY_RPT /* used for general reject */ -#define AVDT_SIG_NONE 0 +#define AVDT_SIG_NONE 0 /* some maximum and minimum sizes of signalling messages */ -#define AVDT_DISCOVER_REQ_MIN 1 -#define AVDT_DISCOVER_REQ_MAX 124 +#define AVDT_DISCOVER_REQ_MIN 1 +#define AVDT_DISCOVER_REQ_MAX 124 /* service category information element field values */ -#define AVDT_CAT_TRANS 1 /* Media Transport */ -#define AVDT_CAT_REPORT 2 /* Reporting */ -#define AVDT_CAT_RECOV 3 /* Recovery */ -#define AVDT_CAT_PROTECT 4 /* Content Protection */ -#define AVDT_CAT_HDRCMP 5 /* Header Compression */ -#define AVDT_CAT_MUX 6 /* Multiplexing */ -#define AVDT_CAT_CODEC 7 /* Media Codec */ -#define AVDT_CAT_DELAY_RPT 8 /* Delay Reporting */ -#define AVDT_CAT_MAX_CUR AVDT_CAT_DELAY_RPT +#define AVDT_CAT_TRANS 1 /* Media Transport */ +#define AVDT_CAT_REPORT 2 /* Reporting */ +#define AVDT_CAT_RECOV 3 /* Recovery */ +#define AVDT_CAT_PROTECT 4 /* Content Protection */ +#define AVDT_CAT_HDRCMP 5 /* Header Compression */ +#define AVDT_CAT_MUX 6 /* Multiplexing */ +#define AVDT_CAT_CODEC 7 /* Media Codec */ +#define AVDT_CAT_DELAY_RPT 8 /* Delay Reporting */ +#define AVDT_CAT_MAX_CUR AVDT_CAT_DELAY_RPT /* min/max lengths of service category information elements */ -#define AVDT_LEN_TRANS_MIN 0 -#define AVDT_LEN_REPORT_MIN 0 -#define AVDT_LEN_RECOV_MIN 3 -#define AVDT_LEN_PROTECT_MIN 2 -#define AVDT_LEN_HDRCMP_MIN 1 -#define AVDT_LEN_MUX_MIN 3 -#define AVDT_LEN_CODEC_MIN 2 -#define AVDT_LEN_DELAY_RPT_MIN 0 - -#define AVDT_LEN_TRANS_MAX 0 -#define AVDT_LEN_REPORT_MAX 0 -#define AVDT_LEN_RECOV_MAX 3 -#define AVDT_LEN_PROTECT_MAX 255 -#define AVDT_LEN_HDRCMP_MAX 1 -#define AVDT_LEN_MUX_MAX 7 -#define AVDT_LEN_CODEC_MAX 255 -#define AVDT_LEN_DELAY_RPT_MAX 0 +#define AVDT_LEN_TRANS_MIN 0 +#define AVDT_LEN_REPORT_MIN 0 +#define AVDT_LEN_RECOV_MIN 3 +#define AVDT_LEN_PROTECT_MIN 2 +#define AVDT_LEN_HDRCMP_MIN 1 +#define AVDT_LEN_MUX_MIN 3 +#define AVDT_LEN_CODEC_MIN 2 +#define AVDT_LEN_DELAY_RPT_MIN 0 + +#define AVDT_LEN_TRANS_MAX 0 +#define AVDT_LEN_REPORT_MAX 0 +#define AVDT_LEN_RECOV_MAX 3 +#define AVDT_LEN_PROTECT_MAX 255 +#define AVDT_LEN_HDRCMP_MAX 1 +#define AVDT_LEN_MUX_MAX 7 +#define AVDT_LEN_CODEC_MAX 255 +#define AVDT_LEN_DELAY_RPT_MAX 0 /* minimum possible size of configuration or capabilities data */ -#define AVDT_LEN_CFG_MIN 2 +#define AVDT_LEN_CFG_MIN 2 /* minimum and maximum lengths for different message types */ -#define AVDT_LEN_SINGLE 1 -#define AVDT_LEN_SETCONFIG_MIN 2 -#define AVDT_LEN_RECONFIG_MIN 1 -#define AVDT_LEN_MULTI_MIN 1 -#define AVDT_LEN_SECURITY_MIN 1 -#define AVDT_LEN_DELAY_RPT 3 +#define AVDT_LEN_SINGLE 1 +#define AVDT_LEN_SETCONFIG_MIN 2 +#define AVDT_LEN_RECONFIG_MIN 1 +#define AVDT_LEN_MULTI_MIN 1 +#define AVDT_LEN_SECURITY_MIN 1 +#define AVDT_LEN_DELAY_RPT 3 /* header lengths for different packet types */ -#define AVDT_LEN_TYPE_SINGLE 2 /* single packet */ -#define AVDT_LEN_TYPE_START 3 /* start packet */ -#define AVDT_LEN_TYPE_CONT 1 /* continue packet */ -#define AVDT_LEN_TYPE_END 1 /* end packet */ +#define AVDT_LEN_TYPE_SINGLE 2 /* single packet */ +#define AVDT_LEN_TYPE_START 3 /* start packet */ +#define AVDT_LEN_TYPE_CONT 1 /* continue packet */ +#define AVDT_LEN_TYPE_END 1 /* end packet */ /* length of general reject message */ -#define AVDT_LEN_GEN_REJ 2 +#define AVDT_LEN_GEN_REJ 2 /* recovery service capabilities information elements */ /* min value for maximum recovery window */ -#define AVDT_RECOV_MRWS_MIN 0x01 +#define AVDT_RECOV_MRWS_MIN 0x01 /* max value for maximum recovery window */ -#define AVDT_RECOV_MRWS_MAX 0x18 +#define AVDT_RECOV_MRWS_MAX 0x18 /* min value for maximum number of media packets */ -#define AVDT_RECOV_MNMP_MIN 0x01 +#define AVDT_RECOV_MNMP_MIN 0x01 /* max value for maximum number of media packets */ -#define AVDT_RECOV_MNMP_MAX 0x18 +#define AVDT_RECOV_MNMP_MAX 0x18 /* SEID value range */ -#define AVDT_SEID_MIN 0x01 -#define AVDT_SEID_MAX 0x3E +#define AVDT_SEID_MIN 0x01 +#define AVDT_SEID_MAX 0x3E /* first byte of media packet header */ -#define AVDT_MEDIA_OCTET1 0x80 +#define AVDT_MEDIA_OCTET1 0x80 /* for adaptation layer header */ /* coding of length field */ -#define AVDT_ALH_LCODE_MASK 0x03 +#define AVDT_ALH_LCODE_MASK 0x03 /* No length field present. Take length from l2cap */ -#define AVDT_ALH_LCODE_NONE 0x00 +#define AVDT_ALH_LCODE_NONE 0x00 /* 16bit length field */ -#define AVDT_ALH_LCODE_16BIT 0x01 +#define AVDT_ALH_LCODE_16BIT 0x01 /* 9 bit length field, MSB = 0, 8 LSBs in 1 octet following */ -#define AVDT_ALH_LCODE_9BITM0 0x02 +#define AVDT_ALH_LCODE_9BITM0 0x02 /* 9 bit length field, MSB = 1, 8 LSBs in 1 octet following */ -#define AVDT_ALH_LCODE_9BITM1 0x03 +#define AVDT_ALH_LCODE_9BITM1 0x03 /* set this for continuation packet */ -#define AVDT_ALH_FRAG_MASK 0x04 +#define AVDT_ALH_FRAG_MASK 0x04 /***************************************************************************** * message parsing and building macros ****************************************************************************/ #define AVDT_MSG_PRS_HDR(p, lbl, pkt, msg) \ -do { \ - (lbl) = (*(p) >> 4) & 0x0F; \ - (pkt) = (*(p) >> 2) & 0x03; \ - (msg) = *(p)++ & 0x03; \ -} while (0) + do { \ + (lbl) = (*(p) >> 4) & 0x0F; \ + (pkt) = (*(p) >> 2) & 0x03; \ + (msg) = *(p)++ & 0x03; \ + } while (0) #define AVDT_MSG_PRS_DISC(p, seid, in_use, type, tsep) \ -do { \ - (seid) = *(p) >> 2; \ - (in_use) = (*(p)++ >> 1) & 0x01; \ - (type) = (*(p) >> 4) & 0x0F; \ - (tsep) = (*(p)++ >> 3) & 0x01; \ -} while (0) + do { \ + (seid) = *(p) >> 2; \ + (in_use) = (*(p)++ >> 1) & 0x01; \ + (type) = (*(p) >> 4) & 0x0F; \ + (tsep) = (*(p)++ >> 3) & 0x01; \ + } while (0) #define AVDT_MSG_PRS_SIG(p, sig) \ -do { \ - (sig) = (*(p)++) & 0x3F; \ -} while (0) + do { \ + (sig) = (*(p)++) & 0x3F; \ + } while (0) -#define AVDT_MSG_PRS_SEID(p, seid) \ -do { \ +#define AVDT_MSG_PRS_SEID(p, seid) \ + do { \ (seid) = ((*(p)++) >> 2) & 0x3F; \ -} while (0) + } while (0) #define AVDT_MSG_PRS_PKT_TYPE(p, pkt) \ -do { \ - (pkt) = (*(p) >> 2) & 0x03; \ -} while (0) + do { \ + (pkt) = (*(p) >> 2) & 0x03; \ + } while (0) #define AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc) \ -do { \ - (o_v) = (*(p) >> 6) & 0x02; \ - (o_p) = (*(p) >> 5) & 0x01; \ - (o_x) = (*(p) >> 4) & 0x01; \ - (o_cc) = (*(p)++) & 0x0F; \ -} while (0) + do { \ + (o_v) = (*(p) >> 6) & 0x02; \ + (o_p) = (*(p) >> 5) & 0x01; \ + (o_x) = (*(p) >> 4) & 0x01; \ + (o_cc) = (*(p)++) & 0x0F; \ + } while (0) #define AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc) \ -do { \ - (o_v) = (*(p) >> 6) & 0x02; \ - (o_p) = (*(p) >> 5) & 0x01; \ - (o_cc) = (*(p)++) & 0x1F; \ -} while (0) + do { \ + (o_v) = (*(p) >> 6) & 0x02; \ + (o_p) = (*(p) >> 5) & 0x01; \ + (o_cc) = (*(p)++) & 0x1F; \ + } while (0) #define AVDT_MSG_PRS_M_PT(p, m_pt, marker) \ -do { \ - (marker) = (*(p) >> 7) & 0x01; \ - (m_pt) = (*(p)++) & 0x7F; \ -} while (0) - -#define AVDT_MSG_BLD_HDR(p, lbl, pkt, msg) \ -do { \ - *(p)++ = (uint8_t) ((lbl) << 4) | ((pkt) << 2) | (msg); \ -} while (0) - -#define AVDT_MSG_BLD_DISC(p, seid, in_use, type, tsep) \ -do { \ - *(p)++ = (uint8_t) (((seid) << 2) | ((in_use) << 1)); \ - *(p)++ = (uint8_t) (((type) << 4) | ((tsep) << 3)); \ -} while (0) + do { \ + (marker) = (*(p) >> 7) & 0x01; \ + (m_pt) = (*(p)++) & 0x7F; \ + } while (0) + +#define AVDT_MSG_BLD_HDR(p, lbl, pkt, msg) \ + do { \ + *(p)++ = (uint8_t)((lbl) << 4) | ((pkt) << 2) | (msg); \ + } while (0) + +#define AVDT_MSG_BLD_DISC(p, seid, in_use, type, tsep) \ + do { \ + *(p)++ = (uint8_t)(((seid) << 2) | ((in_use) << 1)); \ + *(p)++ = (uint8_t)(((type) << 4) | ((tsep) << 3)); \ + } while (0) #define AVDT_MSG_BLD_SIG(p, sig) \ -do { \ - *(p)++ = (uint8_t) (sig); \ -} while (0) + do { \ + *(p)++ = (uint8_t)(sig); \ + } while (0) -#define AVDT_MSG_BLD_SEID(p, seid) \ -do { \ - *(p)++ = (uint8_t) ((seid) << 2); \ -} while (0) +#define AVDT_MSG_BLD_SEID(p, seid) \ + do { \ + *(p)++ = (uint8_t)((seid) << 2); \ + } while (0) #define AVDT_MSG_BLD_ERR(p, err) \ -do { \ - *(p)++ = (uint8_t) (err); \ -} while (0) + do { \ + *(p)++ = (uint8_t)(err); \ + } while (0) #define AVDT_MSG_BLD_PARAM(p, param) \ -do { \ - *(p)++ = (uint8_t) (param); \ -} while (0) + do { \ + *(p)++ = (uint8_t)(param); \ + } while (0) #define AVDT_MSG_BLD_NOSP(p, nosp) \ -do { \ - *(p)++ = (uint8_t) (nosp); \ -} while (0) + do { \ + *(p)++ = (uint8_t)(nosp); \ + } while (0) #endif /* AVDT_DEFS_H */ diff --git a/stack/avdt/avdt_int.h b/stack/avdt/avdt_int.h index 2deb04ff0..fb6ead204 100644 --- a/stack/avdt/avdt_int.h +++ b/stack/avdt/avdt_int.h @@ -24,21 +24,21 @@ #ifndef AVDT_INT_H #define AVDT_INT_H -#include "osi/include/alarm.h" -#include "osi/include/fixed_queue.h" -#include "bt_common.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_defs.h" -#include "l2c_api.h" +#include "avdtc_api.h" +#include "bt_common.h" #include "btm_api.h" +#include "l2c_api.h" +#include "osi/include/alarm.h" +#include "osi/include/fixed_queue.h" #ifdef __cplusplus extern "C" { #endif #ifndef AVDT_DEBUG -#define AVDT_DEBUG false +#define AVDT_DEBUG false #endif /***************************************************************************** @@ -47,37 +47,37 @@ extern "C" { /* channel types */ enum { - AVDT_CHAN_SIG, /* signaling channel */ - AVDT_CHAN_MEDIA, /* media channel */ + AVDT_CHAN_SIG, /* signaling channel */ + AVDT_CHAN_MEDIA, /* media channel */ #if (AVDT_REPORTING == TRUE) - AVDT_CHAN_REPORT, /* reporting channel */ + AVDT_CHAN_REPORT, /* reporting channel */ #endif - AVDT_CHAN_NUM_TYPES + AVDT_CHAN_NUM_TYPES }; /* protocol service capabilities of this AVDTP implementation */ #if (AVDT_REPORTING == TRUE) -#define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT) -#define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT) +#define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT) +#define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT) #else /* AVDT_REPORTING */ -#define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_DELAY_RPT) -#define AVDT_LEG_PSC (AVDT_PSC_TRANS) +#define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_DELAY_RPT) +#define AVDT_LEG_PSC (AVDT_PSC_TRANS) #endif /* AVDT_REPORTING */ /* initiator/acceptor signaling roles */ -#define AVDT_CLOSE_ACP 0 -#define AVDT_CLOSE_INT 1 -#define AVDT_OPEN_ACP 2 -#define AVDT_OPEN_INT 3 +#define AVDT_CLOSE_ACP 0 +#define AVDT_CLOSE_INT 1 +#define AVDT_OPEN_ACP 2 +#define AVDT_OPEN_INT 3 /* states for avdt_scb_verify */ -#define AVDT_VERIFY_OPEN 0 -#define AVDT_VERIFY_STREAMING 1 -#define AVDT_VERIFY_SUSPEND 2 -#define AVDT_VERIFY_START 3 +#define AVDT_VERIFY_OPEN 0 +#define AVDT_VERIFY_STREAMING 1 +#define AVDT_VERIFY_SUSPEND 2 +#define AVDT_VERIFY_START 3 /* to distinguish CCB events from SCB events */ -#define AVDT_CCB_MKR 0x80 +#define AVDT_CCB_MKR 0x80 /* offset where AVDTP signaling message content starts; * use the size of a start header since it's the largest possible @@ -87,271 +87,268 @@ enum { * * Note that we "hide" the scb handles at the top of the message buffer. */ -#define AVDT_MSG_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS + AVDT_LEN_TYPE_START) +#define AVDT_MSG_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS + AVDT_LEN_TYPE_START) /* scb transport channel connect timeout value (in milliseconds) */ -#define AVDT_SCB_TC_CONN_TIMEOUT_MS (10 * 1000) +#define AVDT_SCB_TC_CONN_TIMEOUT_MS (10 * 1000) /* scb transport channel disconnect timeout value (in milliseconds) */ -#define AVDT_SCB_TC_DISC_TIMEOUT_MS (10 * 1000) +#define AVDT_SCB_TC_DISC_TIMEOUT_MS (10 * 1000) /* maximum number of command retransmissions */ #ifndef AVDT_RET_MAX -#define AVDT_RET_MAX 1 +#define AVDT_RET_MAX 1 #endif - /* ccb state machine states */ enum { - AVDT_CCB_IDLE_ST, - AVDT_CCB_OPENING_ST, - AVDT_CCB_OPEN_ST, - AVDT_CCB_CLOSING_ST + AVDT_CCB_IDLE_ST, + AVDT_CCB_OPENING_ST, + AVDT_CCB_OPEN_ST, + AVDT_CCB_CLOSING_ST }; /* state machine action enumeration list */ enum { - AVDT_CCB_CHAN_OPEN, - AVDT_CCB_CHAN_CLOSE, - AVDT_CCB_CHK_CLOSE, - AVDT_CCB_HDL_DISCOVER_CMD, - AVDT_CCB_HDL_DISCOVER_RSP, - AVDT_CCB_HDL_GETCAP_CMD, - AVDT_CCB_HDL_GETCAP_RSP, - AVDT_CCB_HDL_START_CMD, - AVDT_CCB_HDL_START_RSP, - AVDT_CCB_HDL_SUSPEND_CMD, - AVDT_CCB_HDL_SUSPEND_RSP, - AVDT_CCB_SND_DISCOVER_CMD, - AVDT_CCB_SND_DISCOVER_RSP, - AVDT_CCB_SND_GETCAP_CMD, - AVDT_CCB_SND_GETCAP_RSP, - AVDT_CCB_SND_START_CMD, - AVDT_CCB_SND_START_RSP, - AVDT_CCB_SND_SUSPEND_CMD, - AVDT_CCB_SND_SUSPEND_RSP, - AVDT_CCB_CLEAR_CMDS, - AVDT_CCB_CMD_FAIL, - AVDT_CCB_FREE_CMD, - AVDT_CCB_CONG_STATE, - AVDT_CCB_RET_CMD, - AVDT_CCB_SND_CMD, - AVDT_CCB_SND_MSG, - AVDT_CCB_SET_RECONN, - AVDT_CCB_CLR_RECONN, - AVDT_CCB_CHK_RECONN, - AVDT_CCB_CHK_TIMER, - AVDT_CCB_SET_CONN, - AVDT_CCB_SET_DISCONN, - AVDT_CCB_DO_DISCONN, - AVDT_CCB_LL_CLOSED, - AVDT_CCB_LL_OPENED, - AVDT_CCB_DEALLOC, - AVDT_CCB_NUM_ACTIONS + AVDT_CCB_CHAN_OPEN, + AVDT_CCB_CHAN_CLOSE, + AVDT_CCB_CHK_CLOSE, + AVDT_CCB_HDL_DISCOVER_CMD, + AVDT_CCB_HDL_DISCOVER_RSP, + AVDT_CCB_HDL_GETCAP_CMD, + AVDT_CCB_HDL_GETCAP_RSP, + AVDT_CCB_HDL_START_CMD, + AVDT_CCB_HDL_START_RSP, + AVDT_CCB_HDL_SUSPEND_CMD, + AVDT_CCB_HDL_SUSPEND_RSP, + AVDT_CCB_SND_DISCOVER_CMD, + AVDT_CCB_SND_DISCOVER_RSP, + AVDT_CCB_SND_GETCAP_CMD, + AVDT_CCB_SND_GETCAP_RSP, + AVDT_CCB_SND_START_CMD, + AVDT_CCB_SND_START_RSP, + AVDT_CCB_SND_SUSPEND_CMD, + AVDT_CCB_SND_SUSPEND_RSP, + AVDT_CCB_CLEAR_CMDS, + AVDT_CCB_CMD_FAIL, + AVDT_CCB_FREE_CMD, + AVDT_CCB_CONG_STATE, + AVDT_CCB_RET_CMD, + AVDT_CCB_SND_CMD, + AVDT_CCB_SND_MSG, + AVDT_CCB_SET_RECONN, + AVDT_CCB_CLR_RECONN, + AVDT_CCB_CHK_RECONN, + AVDT_CCB_CHK_TIMER, + AVDT_CCB_SET_CONN, + AVDT_CCB_SET_DISCONN, + AVDT_CCB_DO_DISCONN, + AVDT_CCB_LL_CLOSED, + AVDT_CCB_LL_OPENED, + AVDT_CCB_DEALLOC, + AVDT_CCB_NUM_ACTIONS }; -#define AVDT_CCB_IGNORE AVDT_CCB_NUM_ACTIONS +#define AVDT_CCB_IGNORE AVDT_CCB_NUM_ACTIONS /* ccb state machine events */ enum { - AVDT_CCB_API_DISCOVER_REQ_EVT, - AVDT_CCB_API_GETCAP_REQ_EVT, - AVDT_CCB_API_START_REQ_EVT, - AVDT_CCB_API_SUSPEND_REQ_EVT, - AVDT_CCB_API_DISCOVER_RSP_EVT, - AVDT_CCB_API_GETCAP_RSP_EVT, - AVDT_CCB_API_START_RSP_EVT, - AVDT_CCB_API_SUSPEND_RSP_EVT, - AVDT_CCB_API_CONNECT_REQ_EVT, - AVDT_CCB_API_DISCONNECT_REQ_EVT, - AVDT_CCB_MSG_DISCOVER_CMD_EVT, - AVDT_CCB_MSG_GETCAP_CMD_EVT, - AVDT_CCB_MSG_START_CMD_EVT, - AVDT_CCB_MSG_SUSPEND_CMD_EVT, - AVDT_CCB_MSG_DISCOVER_RSP_EVT, - AVDT_CCB_MSG_GETCAP_RSP_EVT, - AVDT_CCB_MSG_START_RSP_EVT, - AVDT_CCB_MSG_SUSPEND_RSP_EVT, - AVDT_CCB_RCVRSP_EVT, - AVDT_CCB_SENDMSG_EVT, - AVDT_CCB_RET_TOUT_EVT, - AVDT_CCB_RSP_TOUT_EVT, - AVDT_CCB_IDLE_TOUT_EVT, - AVDT_CCB_UL_OPEN_EVT, - AVDT_CCB_UL_CLOSE_EVT, - AVDT_CCB_LL_OPEN_EVT, - AVDT_CCB_LL_CLOSE_EVT, - AVDT_CCB_LL_CONG_EVT + AVDT_CCB_API_DISCOVER_REQ_EVT, + AVDT_CCB_API_GETCAP_REQ_EVT, + AVDT_CCB_API_START_REQ_EVT, + AVDT_CCB_API_SUSPEND_REQ_EVT, + AVDT_CCB_API_DISCOVER_RSP_EVT, + AVDT_CCB_API_GETCAP_RSP_EVT, + AVDT_CCB_API_START_RSP_EVT, + AVDT_CCB_API_SUSPEND_RSP_EVT, + AVDT_CCB_API_CONNECT_REQ_EVT, + AVDT_CCB_API_DISCONNECT_REQ_EVT, + AVDT_CCB_MSG_DISCOVER_CMD_EVT, + AVDT_CCB_MSG_GETCAP_CMD_EVT, + AVDT_CCB_MSG_START_CMD_EVT, + AVDT_CCB_MSG_SUSPEND_CMD_EVT, + AVDT_CCB_MSG_DISCOVER_RSP_EVT, + AVDT_CCB_MSG_GETCAP_RSP_EVT, + AVDT_CCB_MSG_START_RSP_EVT, + AVDT_CCB_MSG_SUSPEND_RSP_EVT, + AVDT_CCB_RCVRSP_EVT, + AVDT_CCB_SENDMSG_EVT, + AVDT_CCB_RET_TOUT_EVT, + AVDT_CCB_RSP_TOUT_EVT, + AVDT_CCB_IDLE_TOUT_EVT, + AVDT_CCB_UL_OPEN_EVT, + AVDT_CCB_UL_CLOSE_EVT, + AVDT_CCB_LL_OPEN_EVT, + AVDT_CCB_LL_CLOSE_EVT, + AVDT_CCB_LL_CONG_EVT }; - /* scb state machine states; these state values are private to this module so * the scb state cannot be read or set by actions functions */ enum { - AVDT_SCB_IDLE_ST, - AVDT_SCB_CONF_ST, - AVDT_SCB_OPENING_ST, - AVDT_SCB_OPEN_ST, - AVDT_SCB_STREAM_ST, - AVDT_SCB_CLOSING_ST + AVDT_SCB_IDLE_ST, + AVDT_SCB_CONF_ST, + AVDT_SCB_OPENING_ST, + AVDT_SCB_OPEN_ST, + AVDT_SCB_STREAM_ST, + AVDT_SCB_CLOSING_ST }; /* state machine action enumeration list */ enum { - AVDT_SCB_HDL_ABORT_CMD, - AVDT_SCB_HDL_ABORT_RSP, - AVDT_SCB_HDL_CLOSE_CMD, - AVDT_SCB_HDL_CLOSE_RSP, - AVDT_SCB_HDL_GETCONFIG_CMD, - AVDT_SCB_HDL_GETCONFIG_RSP, - AVDT_SCB_HDL_OPEN_CMD, - AVDT_SCB_HDL_OPEN_REJ, - AVDT_SCB_HDL_OPEN_RSP, - AVDT_SCB_HDL_PKT, - AVDT_SCB_DROP_PKT, - AVDT_SCB_HDL_RECONFIG_CMD, - AVDT_SCB_HDL_RECONFIG_RSP, - AVDT_SCB_HDL_SECURITY_CMD, - AVDT_SCB_HDL_SECURITY_RSP, - AVDT_SCB_HDL_SETCONFIG_CMD, - AVDT_SCB_HDL_SETCONFIG_REJ, - AVDT_SCB_HDL_SETCONFIG_RSP, - AVDT_SCB_HDL_START_CMD, - AVDT_SCB_HDL_START_RSP, - AVDT_SCB_HDL_SUSPEND_CMD, - AVDT_SCB_HDL_SUSPEND_RSP, - AVDT_SCB_HDL_TC_CLOSE, + AVDT_SCB_HDL_ABORT_CMD, + AVDT_SCB_HDL_ABORT_RSP, + AVDT_SCB_HDL_CLOSE_CMD, + AVDT_SCB_HDL_CLOSE_RSP, + AVDT_SCB_HDL_GETCONFIG_CMD, + AVDT_SCB_HDL_GETCONFIG_RSP, + AVDT_SCB_HDL_OPEN_CMD, + AVDT_SCB_HDL_OPEN_REJ, + AVDT_SCB_HDL_OPEN_RSP, + AVDT_SCB_HDL_PKT, + AVDT_SCB_DROP_PKT, + AVDT_SCB_HDL_RECONFIG_CMD, + AVDT_SCB_HDL_RECONFIG_RSP, + AVDT_SCB_HDL_SECURITY_CMD, + AVDT_SCB_HDL_SECURITY_RSP, + AVDT_SCB_HDL_SETCONFIG_CMD, + AVDT_SCB_HDL_SETCONFIG_REJ, + AVDT_SCB_HDL_SETCONFIG_RSP, + AVDT_SCB_HDL_START_CMD, + AVDT_SCB_HDL_START_RSP, + AVDT_SCB_HDL_SUSPEND_CMD, + AVDT_SCB_HDL_SUSPEND_RSP, + AVDT_SCB_HDL_TC_CLOSE, #if (AVDT_REPORTING == TRUE) - AVDT_SCB_HDL_TC_CLOSE_STO, + AVDT_SCB_HDL_TC_CLOSE_STO, #endif - AVDT_SCB_HDL_TC_OPEN, + AVDT_SCB_HDL_TC_OPEN, #if (AVDT_REPORTING == TRUE) - AVDT_SCB_HDL_TC_OPEN_STO, + AVDT_SCB_HDL_TC_OPEN_STO, #endif - AVDT_SCB_SND_DELAY_RPT_REQ, - AVDT_SCB_HDL_DELAY_RPT_CMD, - AVDT_SCB_HDL_DELAY_RPT_RSP, - AVDT_SCB_HDL_WRITE_REQ, - AVDT_SCB_SND_ABORT_REQ, - AVDT_SCB_SND_ABORT_RSP, - AVDT_SCB_SND_CLOSE_REQ, - AVDT_SCB_SND_STREAM_CLOSE, - AVDT_SCB_SND_CLOSE_RSP, - AVDT_SCB_SND_GETCONFIG_REQ, - AVDT_SCB_SND_GETCONFIG_RSP, - AVDT_SCB_SND_OPEN_REQ, - AVDT_SCB_SND_OPEN_RSP, - AVDT_SCB_SND_RECONFIG_REQ, - AVDT_SCB_SND_RECONFIG_RSP, - AVDT_SCB_SND_SECURITY_REQ, - AVDT_SCB_SND_SECURITY_RSP, - AVDT_SCB_SND_SETCONFIG_REQ, - AVDT_SCB_SND_SETCONFIG_REJ, - AVDT_SCB_SND_SETCONFIG_RSP, - AVDT_SCB_SND_TC_CLOSE, - AVDT_SCB_CB_ERR, - AVDT_SCB_CONG_STATE, - AVDT_SCB_REJ_STATE, - AVDT_SCB_REJ_IN_USE, - AVDT_SCB_REJ_NOT_IN_USE, - AVDT_SCB_SET_REMOVE, - AVDT_SCB_FREE_PKT, - AVDT_SCB_CLR_PKT, - AVDT_SCB_CHK_SND_PKT, - AVDT_SCB_TC_TIMER, - AVDT_SCB_CLR_VARS, - AVDT_SCB_DEALLOC, - AVDT_SCB_NUM_ACTIONS + AVDT_SCB_SND_DELAY_RPT_REQ, + AVDT_SCB_HDL_DELAY_RPT_CMD, + AVDT_SCB_HDL_DELAY_RPT_RSP, + AVDT_SCB_HDL_WRITE_REQ, + AVDT_SCB_SND_ABORT_REQ, + AVDT_SCB_SND_ABORT_RSP, + AVDT_SCB_SND_CLOSE_REQ, + AVDT_SCB_SND_STREAM_CLOSE, + AVDT_SCB_SND_CLOSE_RSP, + AVDT_SCB_SND_GETCONFIG_REQ, + AVDT_SCB_SND_GETCONFIG_RSP, + AVDT_SCB_SND_OPEN_REQ, + AVDT_SCB_SND_OPEN_RSP, + AVDT_SCB_SND_RECONFIG_REQ, + AVDT_SCB_SND_RECONFIG_RSP, + AVDT_SCB_SND_SECURITY_REQ, + AVDT_SCB_SND_SECURITY_RSP, + AVDT_SCB_SND_SETCONFIG_REQ, + AVDT_SCB_SND_SETCONFIG_REJ, + AVDT_SCB_SND_SETCONFIG_RSP, + AVDT_SCB_SND_TC_CLOSE, + AVDT_SCB_CB_ERR, + AVDT_SCB_CONG_STATE, + AVDT_SCB_REJ_STATE, + AVDT_SCB_REJ_IN_USE, + AVDT_SCB_REJ_NOT_IN_USE, + AVDT_SCB_SET_REMOVE, + AVDT_SCB_FREE_PKT, + AVDT_SCB_CLR_PKT, + AVDT_SCB_CHK_SND_PKT, + AVDT_SCB_TC_TIMER, + AVDT_SCB_CLR_VARS, + AVDT_SCB_DEALLOC, + AVDT_SCB_NUM_ACTIONS }; -#define AVDT_SCB_IGNORE AVDT_SCB_NUM_ACTIONS +#define AVDT_SCB_IGNORE AVDT_SCB_NUM_ACTIONS /* scb state machine events */ enum { - AVDT_SCB_API_REMOVE_EVT, - AVDT_SCB_API_WRITE_REQ_EVT, - AVDT_SCB_API_GETCONFIG_REQ_EVT, - AVDT_SCB_API_DELAY_RPT_REQ_EVT, - AVDT_SCB_API_SETCONFIG_REQ_EVT, - AVDT_SCB_API_OPEN_REQ_EVT, - AVDT_SCB_API_CLOSE_REQ_EVT, - AVDT_SCB_API_RECONFIG_REQ_EVT, - AVDT_SCB_API_SECURITY_REQ_EVT, - AVDT_SCB_API_ABORT_REQ_EVT, - AVDT_SCB_API_GETCONFIG_RSP_EVT, - AVDT_SCB_API_SETCONFIG_RSP_EVT, - AVDT_SCB_API_SETCONFIG_REJ_EVT, - AVDT_SCB_API_OPEN_RSP_EVT, - AVDT_SCB_API_CLOSE_RSP_EVT, - AVDT_SCB_API_RECONFIG_RSP_EVT, - AVDT_SCB_API_SECURITY_RSP_EVT, - AVDT_SCB_API_ABORT_RSP_EVT, - AVDT_SCB_MSG_SETCONFIG_CMD_EVT, - AVDT_SCB_MSG_GETCONFIG_CMD_EVT, - AVDT_SCB_MSG_OPEN_CMD_EVT, - AVDT_SCB_MSG_START_CMD_EVT, - AVDT_SCB_MSG_SUSPEND_CMD_EVT, - AVDT_SCB_MSG_CLOSE_CMD_EVT, - AVDT_SCB_MSG_ABORT_CMD_EVT, - AVDT_SCB_MSG_RECONFIG_CMD_EVT, - AVDT_SCB_MSG_SECURITY_CMD_EVT, - AVDT_SCB_MSG_DELAY_RPT_CMD_EVT, - AVDT_SCB_MSG_DELAY_RPT_RSP_EVT, - AVDT_SCB_MSG_SETCONFIG_RSP_EVT, - AVDT_SCB_MSG_GETCONFIG_RSP_EVT, - AVDT_SCB_MSG_OPEN_RSP_EVT, - AVDT_SCB_MSG_START_RSP_EVT, - AVDT_SCB_MSG_SUSPEND_RSP_EVT, - AVDT_SCB_MSG_CLOSE_RSP_EVT, - AVDT_SCB_MSG_ABORT_RSP_EVT, - AVDT_SCB_MSG_RECONFIG_RSP_EVT, - AVDT_SCB_MSG_SECURITY_RSP_EVT, - AVDT_SCB_MSG_SETCONFIG_REJ_EVT, - AVDT_SCB_MSG_OPEN_REJ_EVT, - AVDT_SCB_MSG_START_REJ_EVT, - AVDT_SCB_MSG_SUSPEND_REJ_EVT, - AVDT_SCB_TC_TOUT_EVT, - AVDT_SCB_TC_OPEN_EVT, - AVDT_SCB_TC_CLOSE_EVT, - AVDT_SCB_TC_CONG_EVT, - AVDT_SCB_TC_DATA_EVT, - AVDT_SCB_CC_CLOSE_EVT + AVDT_SCB_API_REMOVE_EVT, + AVDT_SCB_API_WRITE_REQ_EVT, + AVDT_SCB_API_GETCONFIG_REQ_EVT, + AVDT_SCB_API_DELAY_RPT_REQ_EVT, + AVDT_SCB_API_SETCONFIG_REQ_EVT, + AVDT_SCB_API_OPEN_REQ_EVT, + AVDT_SCB_API_CLOSE_REQ_EVT, + AVDT_SCB_API_RECONFIG_REQ_EVT, + AVDT_SCB_API_SECURITY_REQ_EVT, + AVDT_SCB_API_ABORT_REQ_EVT, + AVDT_SCB_API_GETCONFIG_RSP_EVT, + AVDT_SCB_API_SETCONFIG_RSP_EVT, + AVDT_SCB_API_SETCONFIG_REJ_EVT, + AVDT_SCB_API_OPEN_RSP_EVT, + AVDT_SCB_API_CLOSE_RSP_EVT, + AVDT_SCB_API_RECONFIG_RSP_EVT, + AVDT_SCB_API_SECURITY_RSP_EVT, + AVDT_SCB_API_ABORT_RSP_EVT, + AVDT_SCB_MSG_SETCONFIG_CMD_EVT, + AVDT_SCB_MSG_GETCONFIG_CMD_EVT, + AVDT_SCB_MSG_OPEN_CMD_EVT, + AVDT_SCB_MSG_START_CMD_EVT, + AVDT_SCB_MSG_SUSPEND_CMD_EVT, + AVDT_SCB_MSG_CLOSE_CMD_EVT, + AVDT_SCB_MSG_ABORT_CMD_EVT, + AVDT_SCB_MSG_RECONFIG_CMD_EVT, + AVDT_SCB_MSG_SECURITY_CMD_EVT, + AVDT_SCB_MSG_DELAY_RPT_CMD_EVT, + AVDT_SCB_MSG_DELAY_RPT_RSP_EVT, + AVDT_SCB_MSG_SETCONFIG_RSP_EVT, + AVDT_SCB_MSG_GETCONFIG_RSP_EVT, + AVDT_SCB_MSG_OPEN_RSP_EVT, + AVDT_SCB_MSG_START_RSP_EVT, + AVDT_SCB_MSG_SUSPEND_RSP_EVT, + AVDT_SCB_MSG_CLOSE_RSP_EVT, + AVDT_SCB_MSG_ABORT_RSP_EVT, + AVDT_SCB_MSG_RECONFIG_RSP_EVT, + AVDT_SCB_MSG_SECURITY_RSP_EVT, + AVDT_SCB_MSG_SETCONFIG_REJ_EVT, + AVDT_SCB_MSG_OPEN_REJ_EVT, + AVDT_SCB_MSG_START_REJ_EVT, + AVDT_SCB_MSG_SUSPEND_REJ_EVT, + AVDT_SCB_TC_TOUT_EVT, + AVDT_SCB_TC_OPEN_EVT, + AVDT_SCB_TC_CLOSE_EVT, + AVDT_SCB_TC_CONG_EVT, + AVDT_SCB_TC_DATA_EVT, + AVDT_SCB_CC_CLOSE_EVT }; /* adaption layer number of stream routing table entries */ #if (AVDT_REPORTING == TRUE) /* 2 channels(1 media, 1 report) for each SEP and one for signalling */ -#define AVDT_NUM_RT_TBL ((AVDT_NUM_SEPS<<1) + 1) +#define AVDT_NUM_RT_TBL ((AVDT_NUM_SEPS << 1) + 1) #else -#define AVDT_NUM_RT_TBL (AVDT_NUM_SEPS + 1) +#define AVDT_NUM_RT_TBL (AVDT_NUM_SEPS + 1) #endif /* adaption layer number of transport channel table entries - moved to target.h #define AVDT_NUM_TC_TBL (AVDT_NUM_SEPS + AVDT_NUM_LINKS) */ /* "states" used in transport channel table */ -#define AVDT_AD_ST_UNUSED 0 /* Unused - unallocated */ -#define AVDT_AD_ST_IDLE 1 /* No connection */ -#define AVDT_AD_ST_ACP 2 /* Waiting to accept a connection */ -#define AVDT_AD_ST_INT 3 /* Initiating a connection */ -#define AVDT_AD_ST_CONN 4 /* Waiting for connection confirm */ -#define AVDT_AD_ST_CFG 5 /* Waiting for configuration complete */ -#define AVDT_AD_ST_OPEN 6 /* Channel opened */ -#define AVDT_AD_ST_SEC_INT 7 /* Security process as INT */ -#define AVDT_AD_ST_SEC_ACP 8 /* Security process as ACP */ +#define AVDT_AD_ST_UNUSED 0 /* Unused - unallocated */ +#define AVDT_AD_ST_IDLE 1 /* No connection */ +#define AVDT_AD_ST_ACP 2 /* Waiting to accept a connection */ +#define AVDT_AD_ST_INT 3 /* Initiating a connection */ +#define AVDT_AD_ST_CONN 4 /* Waiting for connection confirm */ +#define AVDT_AD_ST_CFG 5 /* Waiting for configuration complete */ +#define AVDT_AD_ST_OPEN 6 /* Channel opened */ +#define AVDT_AD_ST_SEC_INT 7 /* Security process as INT */ +#define AVDT_AD_ST_SEC_ACP 8 /* Security process as ACP */ /* Configuration flags. tAVDT_TC_TBL.cfg_flags */ -#define AVDT_L2C_CFG_IND_DONE (1<<0) -#define AVDT_L2C_CFG_CFM_DONE (1<<1) -#define AVDT_L2C_CFG_CONN_INT (1<<2) -#define AVDT_L2C_CFG_CONN_ACP (1<<3) - +#define AVDT_L2C_CFG_IND_DONE (1 << 0) +#define AVDT_L2C_CFG_CFM_DONE (1 << 1) +#define AVDT_L2C_CFG_CONN_INT (1 << 2) +#define AVDT_L2C_CFG_CONN_ACP (1 << 3) /* result code for avdt_ad_write_req() (L2CA_DataWrite()) */ -#define AVDT_AD_FAILED L2CAP_DW_FAILED /* FALSE */ -#define AVDT_AD_SUCCESS L2CAP_DW_SUCCESS /* TRUE */ -#define AVDT_AD_CONGESTED L2CAP_DW_CONGESTED /* 2 */ +#define AVDT_AD_FAILED L2CAP_DW_FAILED /* FALSE */ +#define AVDT_AD_SUCCESS L2CAP_DW_SUCCESS /* TRUE */ +#define AVDT_AD_CONGESTED L2CAP_DW_CONGESTED /* 2 */ /***************************************************************************** * data types @@ -359,326 +356,337 @@ enum { /* msg union of all message parameter types */ typedef union { - tAVDT_EVT_HDR hdr; - tAVDT_EVT_HDR single; - tAVDT_SETCONFIG config_cmd; - tAVDT_CONFIG reconfig_cmd; - tAVDT_MULTI multi; - tAVDT_SECURITY security_cmd; - tAVDT_DISCOVER discover_rsp; - tAVDT_CONFIG svccap; - tAVDT_SECURITY security_rsp; - tAVDT_DELAY_RPT delay_rpt_cmd; + tAVDT_EVT_HDR hdr; + tAVDT_EVT_HDR single; + tAVDT_SETCONFIG config_cmd; + tAVDT_CONFIG reconfig_cmd; + tAVDT_MULTI multi; + tAVDT_SECURITY security_cmd; + tAVDT_DISCOVER discover_rsp; + tAVDT_CONFIG svccap; + tAVDT_SECURITY security_rsp; + tAVDT_DELAY_RPT delay_rpt_cmd; } tAVDT_MSG; /* data type for AVDT_CCB_API_DISCOVER_REQ_EVT */ typedef struct { - tAVDT_CTRL_CBACK *p_cback; - tAVDT_SEP_INFO *p_sep_info; - uint8_t num_seps; + tAVDT_CTRL_CBACK* p_cback; + tAVDT_SEP_INFO* p_sep_info; + uint8_t num_seps; } tAVDT_CCB_API_DISCOVER; /* data type for AVDT_CCB_API_GETCAP_REQ_EVT */ typedef struct { - tAVDT_EVT_HDR single; - tAVDT_CTRL_CBACK *p_cback; - tAVDT_CFG *p_cfg; + tAVDT_EVT_HDR single; + tAVDT_CTRL_CBACK* p_cback; + tAVDT_CFG* p_cfg; } tAVDT_CCB_API_GETCAP; /* data type for AVDT_CCB_API_CONNECT_REQ_EVT */ typedef struct { - tAVDT_CTRL_CBACK *p_cback; - uint8_t sec_mask; + tAVDT_CTRL_CBACK* p_cback; + uint8_t sec_mask; } tAVDT_CCB_API_CONNECT; /* data type for AVDT_CCB_API_DISCONNECT_REQ_EVT */ -typedef struct { - tAVDT_CTRL_CBACK *p_cback; -} tAVDT_CCB_API_DISCONNECT; +typedef struct { tAVDT_CTRL_CBACK* p_cback; } tAVDT_CCB_API_DISCONNECT; /* union associated with ccb state machine events */ typedef union { - tAVDT_CCB_API_DISCOVER discover; - tAVDT_CCB_API_GETCAP getcap; - tAVDT_CCB_API_CONNECT connect; - tAVDT_CCB_API_DISCONNECT disconnect; - tAVDT_MSG msg; - bool llcong; - uint8_t err_code; + tAVDT_CCB_API_DISCOVER discover; + tAVDT_CCB_API_GETCAP getcap; + tAVDT_CCB_API_CONNECT connect; + tAVDT_CCB_API_DISCONNECT disconnect; + tAVDT_MSG msg; + bool llcong; + uint8_t err_code; } tAVDT_CCB_EVT; /* channel control block type */ typedef struct { - BD_ADDR peer_addr; /* BD address of peer */ - /* - * NOTE: idle_ccb_timer, ret_ccb_timer and rsp_ccb_timer are mutually - * exclusive - no more than one timer should be running at the same time. - */ - alarm_t *idle_ccb_timer; /* Idle CCB timer entry */ - alarm_t *ret_ccb_timer; /* Ret CCB timer entry */ - alarm_t *rsp_ccb_timer; /* Rsp CCB timer entry */ - fixed_queue_t *cmd_q; /* Queue for outgoing command messages */ - fixed_queue_t *rsp_q; /* Queue for outgoing response and reject messages */ - tAVDT_CTRL_CBACK *proc_cback; /* Procedure callback function */ - tAVDT_CTRL_CBACK *p_conn_cback; /* Connection/disconnection callback function */ - void *p_proc_data; /* Pointer to data storage for procedure */ - BT_HDR *p_curr_cmd; /* Current command being sent awaiting response */ - BT_HDR *p_curr_msg; /* Current message being sent */ - BT_HDR *p_rx_msg; /* Current message being received */ - bool allocated; /* Whether ccb is allocated */ - uint8_t state; /* The CCB state machine state */ - bool ll_opened; /* true if LL is opened */ - bool proc_busy; /* true when a discover or get capabilities procedure in progress */ - uint8_t proc_param; /* Procedure parameter; either SEID for get capabilities or number of SEPS for discover */ - bool cong; /* Whether signaling channel is congested */ - uint8_t label; /* Message header "label" (sequence number) */ - bool reconn; /* If true, reinitiate connection after transitioning from CLOSING to IDLE state */ - uint8_t ret_count; /* Command retransmission count */ + BD_ADDR peer_addr; /* BD address of peer */ + /* + * NOTE: idle_ccb_timer, ret_ccb_timer and rsp_ccb_timer are mutually + * exclusive - no more than one timer should be running at the same time. + */ + alarm_t* idle_ccb_timer; /* Idle CCB timer entry */ + alarm_t* ret_ccb_timer; /* Ret CCB timer entry */ + alarm_t* rsp_ccb_timer; /* Rsp CCB timer entry */ + fixed_queue_t* cmd_q; /* Queue for outgoing command messages */ + fixed_queue_t* rsp_q; /* Queue for outgoing response and reject messages */ + tAVDT_CTRL_CBACK* proc_cback; /* Procedure callback function */ + tAVDT_CTRL_CBACK* + p_conn_cback; /* Connection/disconnection callback function */ + void* p_proc_data; /* Pointer to data storage for procedure */ + BT_HDR* p_curr_cmd; /* Current command being sent awaiting response */ + BT_HDR* p_curr_msg; /* Current message being sent */ + BT_HDR* p_rx_msg; /* Current message being received */ + bool allocated; /* Whether ccb is allocated */ + uint8_t state; /* The CCB state machine state */ + bool ll_opened; /* true if LL is opened */ + bool proc_busy; /* true when a discover or get capabilities procedure in + progress */ + uint8_t proc_param; /* Procedure parameter; either SEID for get capabilities + or number of SEPS for discover */ + bool cong; /* Whether signaling channel is congested */ + uint8_t label; /* Message header "label" (sequence number) */ + bool reconn; /* If true, reinitiate connection after transitioning from + CLOSING to IDLE state */ + uint8_t ret_count; /* Command retransmission count */ } tAVDT_CCB; /* type for action functions */ -typedef void (*tAVDT_CCB_ACTION)(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); +typedef void (*tAVDT_CCB_ACTION)(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); /* type for AVDT_SCB_API_WRITE_REQ_EVT */ typedef struct { - BT_HDR *p_buf; - uint32_t time_stamp; - uint8_t m_pt; - tAVDT_DATA_OPT_MASK opt; + BT_HDR* p_buf; + uint32_t time_stamp; + uint8_t m_pt; + tAVDT_DATA_OPT_MASK opt; } tAVDT_SCB_APIWRITE; /* type for AVDT_SCB_TC_CLOSE_EVT */ typedef struct { - uint8_t old_tc_state; /* channel state before closed */ - uint8_t tcid; /* TCID */ - uint8_t type; /* channel type */ + uint8_t old_tc_state; /* channel state before closed */ + uint8_t tcid; /* TCID */ + uint8_t type; /* channel type */ } tAVDT_SCB_TC_CLOSE; /* type for scb event data */ typedef union { - tAVDT_MSG msg; - tAVDT_SCB_APIWRITE apiwrite; - tAVDT_DELAY_RPT apidelay; - tAVDT_OPEN open; - tAVDT_SCB_TC_CLOSE close; - bool llcong; - BT_HDR *p_pkt; + tAVDT_MSG msg; + tAVDT_SCB_APIWRITE apiwrite; + tAVDT_DELAY_RPT apidelay; + tAVDT_OPEN open; + tAVDT_SCB_TC_CLOSE close; + bool llcong; + BT_HDR* p_pkt; } tAVDT_SCB_EVT; /* stream control block type */ typedef struct { - tAVDT_CS cs; /* stream creation struct */ - tAVDT_CFG curr_cfg; /* current configuration */ - tAVDT_CFG req_cfg; /* requested configuration */ - alarm_t *transport_channel_timer; /* transport channel connect timer */ - BT_HDR *p_pkt; /* packet waiting to be sent */ - tAVDT_CCB *p_ccb; /* ccb associated with this scb */ - uint16_t media_seq; /* media packet sequence number */ - bool allocated; /* whether scb is allocated or unused */ - bool in_use; /* whether stream being used by peer */ - uint8_t role; /* initiator/acceptor role in current procedure */ - bool remove; /* whether CB is marked for removal */ - uint8_t state; /* state machine state */ - uint8_t peer_seid; /* SEID of peer stream */ - uint8_t curr_evt; /* current event; set only by state machine */ - bool cong; /* Whether media transport channel is congested */ - uint8_t close_code; /* Error code received in close response */ + tAVDT_CS cs; /* stream creation struct */ + tAVDT_CFG curr_cfg; /* current configuration */ + tAVDT_CFG req_cfg; /* requested configuration */ + alarm_t* transport_channel_timer; /* transport channel connect timer */ + BT_HDR* p_pkt; /* packet waiting to be sent */ + tAVDT_CCB* p_ccb; /* ccb associated with this scb */ + uint16_t media_seq; /* media packet sequence number */ + bool allocated; /* whether scb is allocated or unused */ + bool in_use; /* whether stream being used by peer */ + uint8_t role; /* initiator/acceptor role in current procedure */ + bool remove; /* whether CB is marked for removal */ + uint8_t state; /* state machine state */ + uint8_t peer_seid; /* SEID of peer stream */ + uint8_t curr_evt; /* current event; set only by state machine */ + bool cong; /* Whether media transport channel is congested */ + uint8_t close_code; /* Error code received in close response */ } tAVDT_SCB; /* type for action functions */ -typedef void (*tAVDT_SCB_ACTION)(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); +typedef void (*tAVDT_SCB_ACTION)(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); /* adaption layer type for transport channel table */ typedef struct { - uint16_t peer_mtu; /* L2CAP mtu of the peer device */ - uint16_t my_mtu; /* Our MTU for this channel */ - uint16_t my_flush_to; /* Our flush timeout for this channel */ - uint16_t lcid; - uint8_t tcid; /* transport channel id */ - uint8_t ccb_idx; /* channel control block associated with this tc */ - uint8_t state; /* transport channel state */ - uint8_t cfg_flags; /* L2CAP configuration flags */ - uint8_t id; + uint16_t peer_mtu; /* L2CAP mtu of the peer device */ + uint16_t my_mtu; /* Our MTU for this channel */ + uint16_t my_flush_to; /* Our flush timeout for this channel */ + uint16_t lcid; + uint8_t tcid; /* transport channel id */ + uint8_t ccb_idx; /* channel control block associated with this tc */ + uint8_t state; /* transport channel state */ + uint8_t cfg_flags; /* L2CAP configuration flags */ + uint8_t id; } tAVDT_TC_TBL; /* adaption layer type for stream routing table */ typedef struct { - uint16_t lcid; /* L2CAP LCID of the associated transport channel */ - uint8_t scb_hdl; /* stream control block associated with this tc */ + uint16_t lcid; /* L2CAP LCID of the associated transport channel */ + uint8_t scb_hdl; /* stream control block associated with this tc */ } tAVDT_RT_TBL; - /* adaption layer control block */ typedef struct { - tAVDT_RT_TBL rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL]; - tAVDT_TC_TBL tc_tbl[AVDT_NUM_TC_TBL]; - uint8_t lcid_tbl[MAX_L2CAP_CHANNELS]; /* map LCID to tc_tbl index */ + tAVDT_RT_TBL rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL]; + tAVDT_TC_TBL tc_tbl[AVDT_NUM_TC_TBL]; + uint8_t lcid_tbl[MAX_L2CAP_CHANNELS]; /* map LCID to tc_tbl index */ } tAVDT_AD; /* Control block for AVDT */ typedef struct { - tAVDT_REG rcb; /* registration control block */ - tAVDT_CCB ccb[AVDT_NUM_LINKS]; /* channel control blocks */ - tAVDT_SCB scb[AVDT_NUM_SEPS]; /* stream control blocks */ - tAVDT_AD ad; /* adaption layer control block */ - tAVDTC_CTRL_CBACK *p_conf_cback; /* conformance callback function */ - tAVDT_CCB_ACTION *p_ccb_act; /* pointer to CCB action functions */ - tAVDT_SCB_ACTION *p_scb_act; /* pointer to SCB action functions */ - tAVDT_CTRL_CBACK *p_conn_cback; /* connection callback function */ - uint8_t trace_level; /* trace level */ + tAVDT_REG rcb; /* registration control block */ + tAVDT_CCB ccb[AVDT_NUM_LINKS]; /* channel control blocks */ + tAVDT_SCB scb[AVDT_NUM_SEPS]; /* stream control blocks */ + tAVDT_AD ad; /* adaption layer control block */ + tAVDTC_CTRL_CBACK* p_conf_cback; /* conformance callback function */ + tAVDT_CCB_ACTION* p_ccb_act; /* pointer to CCB action functions */ + tAVDT_SCB_ACTION* p_scb_act; /* pointer to SCB action functions */ + tAVDT_CTRL_CBACK* p_conn_cback; /* connection callback function */ + uint8_t trace_level; /* trace level */ } tAVDT_CB; - /***************************************************************************** * function declarations ****************************************************************************/ /* CCB function declarations */ extern void avdt_ccb_init(void); -extern void avdt_ccb_event(tAVDT_CCB *p_ccb, uint8_t event, tAVDT_CCB_EVT *p_data); -extern tAVDT_CCB *avdt_ccb_by_bd(BD_ADDR bd_addr); -extern tAVDT_CCB *avdt_ccb_alloc(BD_ADDR bd_addr); -extern void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern uint8_t avdt_ccb_to_idx(tAVDT_CCB *p_ccb); -extern tAVDT_CCB *avdt_ccb_by_idx(uint8_t idx); +extern void avdt_ccb_event(tAVDT_CCB* p_ccb, uint8_t event, + tAVDT_CCB_EVT* p_data); +extern tAVDT_CCB* avdt_ccb_by_bd(BD_ADDR bd_addr); +extern tAVDT_CCB* avdt_ccb_alloc(BD_ADDR bd_addr); +extern void avdt_ccb_dealloc(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern uint8_t avdt_ccb_to_idx(tAVDT_CCB* p_ccb); +extern tAVDT_CCB* avdt_ccb_by_idx(uint8_t idx); /* CCB action functions */ -extern void avdt_ccb_chan_open(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_chan_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_chk_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_cong_state(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_set_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_clr_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_chk_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_set_conn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_set_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_do_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_ll_closed(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); -extern void avdt_ccb_ll_opened(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); +extern void avdt_ccb_chan_open(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_chan_close(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_chk_close(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_discover_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_discover_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_start_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_start_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_discover_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_discover_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_getcap_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_getcap_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_start_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_start_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_suspend_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_suspend_rsp(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_clear_cmds(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_cmd_fail(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_free_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_cong_state(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_ret_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_cmd(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_snd_msg(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_set_reconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_clr_reconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_chk_reconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_chk_timer(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_set_conn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_set_disconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_do_disconn(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_ll_closed(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); +extern void avdt_ccb_ll_opened(tAVDT_CCB* p_ccb, tAVDT_CCB_EVT* p_data); /* SCB function prototypes */ -extern void avdt_scb_event(tAVDT_SCB *p_scb, uint8_t event, tAVDT_SCB_EVT *p_data); +extern void avdt_scb_event(tAVDT_SCB* p_scb, uint8_t event, + tAVDT_SCB_EVT* p_data); extern void avdt_scb_init(void); -extern tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs); -extern void avdt_scb_dealloc(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern uint8_t avdt_scb_to_hdl(tAVDT_SCB *p_scb); -extern tAVDT_SCB *avdt_scb_by_hdl(uint8_t hdl); -extern uint8_t avdt_scb_verify(tAVDT_CCB *p_ccb, uint8_t state, uint8_t *p_seid, uint16_t num_seid, uint8_t *p_err_code); -extern void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi); -extern uint32_t avdt_scb_gen_ssrc(tAVDT_SCB *p_scb); +extern tAVDT_SCB* avdt_scb_alloc(tAVDT_CS* p_cs); +extern void avdt_scb_dealloc(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern uint8_t avdt_scb_to_hdl(tAVDT_SCB* p_scb); +extern tAVDT_SCB* avdt_scb_by_hdl(uint8_t hdl); +extern uint8_t avdt_scb_verify(tAVDT_CCB* p_ccb, uint8_t state, uint8_t* p_seid, + uint16_t num_seid, uint8_t* p_err_code); +extern void avdt_scb_peer_seid_list(tAVDT_MULTI* p_multi); +extern uint32_t avdt_scb_gen_ssrc(tAVDT_SCB* p_scb); /* SCB action functions */ -extern void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_close_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_open_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_open_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_drop_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_security_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_start_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_start_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_suspend_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_suspend_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_delay_rpt_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_delay_rpt_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_delay_rpt_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_tc_open(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_tc_close_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_tc_open_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_hdl_write_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_abort_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_getconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_open_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_reconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_security_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_setconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_snd_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_cb_err(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_cong_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_rej_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_rej_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_rej_not_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_set_remove(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); -extern void avdt_scb_transport_channel_timer(tAVDT_SCB *p_scb, - tAVDT_SCB_EVT *p_data); -extern void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); +extern void avdt_scb_hdl_abort_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_abort_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_close_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_close_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_getconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_open_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_open_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_open_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_drop_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_security_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_security_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_setconfig_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_start_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_start_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_suspend_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_suspend_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_delay_rpt_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_delay_rpt_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_delay_rpt_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_tc_close(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_tc_open(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_tc_close_sto(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_tc_open_sto(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_hdl_write_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_abort_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_abort_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_close_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_stream_close(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_close_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_getconfig_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_getconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_open_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_open_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_reconfig_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_reconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_security_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_security_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_setconfig_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_setconfig_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_setconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_snd_tc_close(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_cb_err(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_cong_state(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_rej_state(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_rej_in_use(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_rej_not_in_use(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_set_remove(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_free_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_chk_snd_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_clr_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); +extern void avdt_scb_transport_channel_timer(tAVDT_SCB* p_scb, + tAVDT_SCB_EVT* p_data); +extern void avdt_scb_clr_vars(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data); /* msg function declarations */ -extern bool avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg); -extern void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, uint8_t sig_id, tAVDT_MSG *p_params); -extern void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params); -extern void avdt_msg_send_rej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params); -extern void avdt_msg_send_grej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params); -extern void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf); +extern bool avdt_msg_send(tAVDT_CCB* p_ccb, BT_HDR* p_msg); +extern void avdt_msg_send_cmd(tAVDT_CCB* p_ccb, void* p_scb, uint8_t sig_id, + tAVDT_MSG* p_params); +extern void avdt_msg_send_rsp(tAVDT_CCB* p_ccb, uint8_t sig_id, + tAVDT_MSG* p_params); +extern void avdt_msg_send_rej(tAVDT_CCB* p_ccb, uint8_t sig_id, + tAVDT_MSG* p_params); +extern void avdt_msg_send_grej(tAVDT_CCB* p_ccb, uint8_t sig_id, + tAVDT_MSG* p_params); +extern void avdt_msg_ind(tAVDT_CCB* p_ccb, BT_HDR* p_buf); /* adaption layer function declarations */ extern void avdt_ad_init(void); -extern uint8_t avdt_ad_type_to_tcid(uint8_t type, tAVDT_SCB *p_scb); -extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(uint8_t type, tAVDT_CCB *p_ccb, uint8_t state); -extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(uint16_t lcid); -extern tAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb); -extern uint8_t avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl); -extern void avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, uint16_t reason); -extern void avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl); -extern void avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, bool is_congested); -extern void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf); -extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb); -extern uint8_t avdt_ad_write_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_HDR *p_buf); -extern void avdt_ad_open_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, uint8_t role); -extern void avdt_ad_close_req(uint8_t type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb); - -extern void avdt_ccb_idle_ccb_timer_timeout(void *data); -extern void avdt_ccb_ret_ccb_timer_timeout(void *data); -extern void avdt_ccb_rsp_ccb_timer_timeout(void *data); -extern void avdt_scb_transport_channel_timer_timeout(void *data); +extern uint8_t avdt_ad_type_to_tcid(uint8_t type, tAVDT_SCB* p_scb); +extern tAVDT_TC_TBL* avdt_ad_tc_tbl_by_st(uint8_t type, tAVDT_CCB* p_ccb, + uint8_t state); +extern tAVDT_TC_TBL* avdt_ad_tc_tbl_by_lcid(uint16_t lcid); +extern tAVDT_TC_TBL* avdt_ad_tc_tbl_alloc(tAVDT_CCB* p_ccb); +extern uint8_t avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL* p_tbl); +extern void avdt_ad_tc_close_ind(tAVDT_TC_TBL* p_tbl, uint16_t reason); +extern void avdt_ad_tc_open_ind(tAVDT_TC_TBL* p_tbl); +extern void avdt_ad_tc_cong_ind(tAVDT_TC_TBL* p_tbl, bool is_congested); +extern void avdt_ad_tc_data_ind(tAVDT_TC_TBL* p_tbl, BT_HDR* p_buf); +extern tAVDT_TC_TBL* avdt_ad_tc_tbl_by_type(uint8_t type, tAVDT_CCB* p_ccb, + tAVDT_SCB* p_scb); +extern uint8_t avdt_ad_write_req(uint8_t type, tAVDT_CCB* p_ccb, + tAVDT_SCB* p_scb, BT_HDR* p_buf); +extern void avdt_ad_open_req(uint8_t type, tAVDT_CCB* p_ccb, tAVDT_SCB* p_scb, + uint8_t role); +extern void avdt_ad_close_req(uint8_t type, tAVDT_CCB* p_ccb, tAVDT_SCB* p_scb); + +extern void avdt_ccb_idle_ccb_timer_timeout(void* data); +extern void avdt_ccb_ret_ccb_timer_timeout(void* data); +extern void avdt_ccb_rsp_ccb_timer_timeout(void* data); +extern void avdt_scb_transport_channel_timer_timeout(void* data); /***************************************************************************** * macros @@ -687,12 +695,11 @@ extern void avdt_scb_transport_channel_timer_timeout(void *data); /* we store the scb and the label in the layer_specific field of the * current cmd */ -#define AVDT_BLD_LAYERSPEC(ls, msg, label) \ - ls = (((label) << 4) | (msg)) +#define AVDT_BLD_LAYERSPEC(ls, msg, label) ls = (((label) << 4) | (msg)) -#define AVDT_LAYERSPEC_LABEL(ls) ((uint8_t)((ls) >> 4)) +#define AVDT_LAYERSPEC_LABEL(ls) ((uint8_t)((ls) >> 4)) -#define AVDT_LAYERSPEC_MSG(ls) ((uint8_t)((ls) & 0x000F)) +#define AVDT_LAYERSPEC_MSG(ls) ((uint8_t)((ls)&0x000F)) /***************************************************************************** * global data diff --git a/stack/avdt/avdt_l2c.cc b/stack/avdt/avdt_l2c.cc index ec3ea6b36..35502f82c 100644 --- a/stack/avdt/avdt_l2c.cc +++ b/stack/avdt/avdt_l2c.cc @@ -23,29 +23,29 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" -#include "l2c_api.h" -#include "l2cdefs.h" +#include "avdtc_api.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" #include "device/include/interop.h" +#include "l2c_api.h" +#include "l2cdefs.h" #include "osi/include/osi.h" /* callback function declarations */ -void avdt_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, - uint16_t psm, uint8_t id); +void avdt_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id); void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result); -void avdt_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); +void avdt_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); void avdt_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result); void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); -void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf); +void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); /* L2CAP callback function structure */ const tL2CAP_APPL_INFO avdt_l2c_appl = { @@ -59,7 +59,7 @@ const tL2CAP_APPL_INFO avdt_l2c_appl = { NULL, avdt_l2c_data_ind_cback, avdt_l2c_congestion_ind_cback, - NULL /* tL2CA_TX_COMPLETE_CB */ + NULL /* tL2CA_TX_COMPLETE_CB */ }; /******************************************************************************* @@ -72,51 +72,49 @@ const tL2CAP_APPL_INFO avdt_l2c_appl = { * Returns void * ******************************************************************************/ -static void avdt_sec_check_complete_term (BD_ADDR bd_addr, tBT_TRANSPORT transport, - UNUSED_ATTR void *p_ref_data, uint8_t res) -{ - tAVDT_CCB *p_ccb = NULL; - tL2CAP_CFG_INFO cfg; - tAVDT_TC_TBL *p_tbl; - - AVDT_TRACE_DEBUG("avdt_sec_check_complete_term res: %d", res); - if (!bd_addr) - { - AVDT_TRACE_WARNING("avdt_sec_check_complete_term: NULL BD_ADDR"); - return; - - } - p_ccb = avdt_ccb_by_bd(bd_addr); - - p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_ACP); - if (p_tbl == NULL) - return; - - if (res == BTM_SUCCESS) - { - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK, L2CAP_CONN_OK); - - /* store idx in LCID table, store LCID in routing table */ - avdt_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] = avdt_ad_tc_tbl_to_idx(p_tbl); - avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = p_tbl->lcid; - - /* transition to configuration state */ - p_tbl->state = AVDT_AD_ST_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = p_tbl->my_mtu; - cfg.flush_to_present = true; - cfg.flush_to = p_tbl->my_flush_to; - L2CA_ConfigReq(p_tbl->lcid, &cfg); - } - else - { - L2CA_ConnectRsp (bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK); - avdt_ad_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); - } +static void avdt_sec_check_complete_term(BD_ADDR bd_addr, + tBT_TRANSPORT transport, + UNUSED_ATTR void* p_ref_data, + uint8_t res) { + tAVDT_CCB* p_ccb = NULL; + tL2CAP_CFG_INFO cfg; + tAVDT_TC_TBL* p_tbl; + + AVDT_TRACE_DEBUG("avdt_sec_check_complete_term res: %d", res); + if (!bd_addr) { + AVDT_TRACE_WARNING("avdt_sec_check_complete_term: NULL BD_ADDR"); + return; + } + p_ccb = avdt_ccb_by_bd(bd_addr); + + p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_ACP); + if (p_tbl == NULL) return; + + if (res == BTM_SUCCESS) { + /* Send response to the L2CAP layer. */ + L2CA_ConnectRsp(bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK, + L2CAP_CONN_OK); + + /* store idx in LCID table, store LCID in routing table */ + avdt_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] = + avdt_ad_tc_tbl_to_idx(p_tbl); + avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = p_tbl->lcid; + + /* transition to configuration state */ + p_tbl->state = AVDT_AD_ST_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = p_tbl->my_mtu; + cfg.flush_to_present = true; + cfg.flush_to = p_tbl->my_flush_to; + L2CA_ConfigReq(p_tbl->lcid, &cfg); + } else { + L2CA_ConnectRsp(bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_SECURITY_BLOCK, + L2CAP_CONN_OK); + avdt_ad_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); + } } /******************************************************************************* @@ -129,38 +127,34 @@ static void avdt_sec_check_complete_term (BD_ADDR bd_addr, tBT_TRANSPORT transpo * Returns void * ******************************************************************************/ -static void avdt_sec_check_complete_orig (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, - UNUSED_ATTR void *p_ref_data, uint8_t res) -{ - tAVDT_CCB *p_ccb = NULL; - tL2CAP_CFG_INFO cfg; - tAVDT_TC_TBL *p_tbl; - - AVDT_TRACE_DEBUG("avdt_sec_check_complete_orig res: %d", res); - if (bd_addr) - p_ccb = avdt_ccb_by_bd(bd_addr); - p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_INT); - if(p_tbl == NULL) - return; - - if( res == BTM_SUCCESS ) - { - /* set channel state */ - p_tbl->state = AVDT_AD_ST_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = p_tbl->my_mtu; - cfg.flush_to_present = true; - cfg.flush_to = p_tbl->my_flush_to; - L2CA_ConfigReq(p_tbl->lcid, &cfg); - } - else - { - L2CA_DisconnectReq (p_tbl->lcid); - avdt_ad_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); - } +static void avdt_sec_check_complete_orig(BD_ADDR bd_addr, + tBT_TRANSPORT trasnport, + UNUSED_ATTR void* p_ref_data, + uint8_t res) { + tAVDT_CCB* p_ccb = NULL; + tL2CAP_CFG_INFO cfg; + tAVDT_TC_TBL* p_tbl; + + AVDT_TRACE_DEBUG("avdt_sec_check_complete_orig res: %d", res); + if (bd_addr) p_ccb = avdt_ccb_by_bd(bd_addr); + p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_INT); + if (p_tbl == NULL) return; + + if (res == BTM_SUCCESS) { + /* set channel state */ + p_tbl->state = AVDT_AD_ST_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = p_tbl->my_mtu; + cfg.flush_to_present = true; + cfg.flush_to = p_tbl->my_flush_to; + L2CA_ConfigReq(p_tbl->lcid, &cfg); + } else { + L2CA_DisconnectReq(p_tbl->lcid); + avdt_ad_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); + } } /******************************************************************************* * @@ -173,114 +167,109 @@ static void avdt_sec_check_complete_orig (BD_ADDR bd_addr, tBT_TRANSPORT trasnpo * ******************************************************************************/ void avdt_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, - UNUSED_ATTR uint16_t psm, uint8_t id) -{ - tAVDT_CCB *p_ccb; - tAVDT_TC_TBL *p_tbl = NULL; - uint16_t result; - tL2CAP_CFG_INFO cfg; - tBTM_STATUS rc; - - /* do we already have a control channel for this peer? */ - p_ccb = avdt_ccb_by_bd(bd_addr); - if (p_ccb == NULL) - { - /* no, allocate ccb */ - p_ccb = avdt_ccb_alloc(bd_addr); - if (p_ccb == NULL) - { - /* no ccb available, reject L2CAP connection */ - result = L2CAP_CONN_NO_RESOURCES; - } - else - { - /* allocate and set up entry; first channel is always signaling */ - p_tbl = avdt_ad_tc_tbl_alloc(p_ccb); - p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu; - p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO; - p_tbl->tcid = AVDT_CHAN_SIG; - p_tbl->lcid = lcid; - p_tbl->id = id; - p_tbl->state = AVDT_AD_ST_SEC_ACP; - p_tbl->cfg_flags = AVDT_L2C_CFG_CONN_ACP; - - if (interop_match_addr(INTEROP_2MBPS_LINK_ONLY, (const bt_bdaddr_t *)&bd_addr)) { - // Disable 3DH packets for AVDT ACL to improve sensitivity on HS - tACL_CONN *p_acl_cb = btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR); - btm_set_packet_types(p_acl_cb, (btm_cb.btm_acl_pkt_types_supported | - HCI_PKT_TYPES_MASK_NO_3_DH1 | - HCI_PKT_TYPES_MASK_NO_3_DH3 | - HCI_PKT_TYPES_MASK_NO_3_DH5)); - } - - /* Check the security */ - rc = btm_sec_mx_access_request (bd_addr, AVDT_PSM, - false, BTM_SEC_PROTO_AVDT, - AVDT_CHAN_SIG, - &avdt_sec_check_complete_term, NULL); - if(rc == BTM_CMD_STARTED) - { - L2CA_ConnectRsp (p_ccb->peer_addr, p_tbl->id, lcid, L2CAP_CONN_PENDING, L2CAP_CONN_OK); - } - return; - } + UNUSED_ATTR uint16_t psm, uint8_t id) { + tAVDT_CCB* p_ccb; + tAVDT_TC_TBL* p_tbl = NULL; + uint16_t result; + tL2CAP_CFG_INFO cfg; + tBTM_STATUS rc; + + /* do we already have a control channel for this peer? */ + p_ccb = avdt_ccb_by_bd(bd_addr); + if (p_ccb == NULL) { + /* no, allocate ccb */ + p_ccb = avdt_ccb_alloc(bd_addr); + if (p_ccb == NULL) { + /* no ccb available, reject L2CAP connection */ + result = L2CAP_CONN_NO_RESOURCES; + } else { + /* allocate and set up entry; first channel is always signaling */ + p_tbl = avdt_ad_tc_tbl_alloc(p_ccb); + p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu; + p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO; + p_tbl->tcid = AVDT_CHAN_SIG; + p_tbl->lcid = lcid; + p_tbl->id = id; + p_tbl->state = AVDT_AD_ST_SEC_ACP; + p_tbl->cfg_flags = AVDT_L2C_CFG_CONN_ACP; + + if (interop_match_addr(INTEROP_2MBPS_LINK_ONLY, + (const bt_bdaddr_t*)&bd_addr)) { + // Disable 3DH packets for AVDT ACL to improve sensitivity on HS + tACL_CONN* p_acl_cb = btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR); + btm_set_packet_types( + p_acl_cb, + (btm_cb.btm_acl_pkt_types_supported | HCI_PKT_TYPES_MASK_NO_3_DH1 | + HCI_PKT_TYPES_MASK_NO_3_DH3 | HCI_PKT_TYPES_MASK_NO_3_DH5)); + } + + /* Check the security */ + rc = btm_sec_mx_access_request(bd_addr, AVDT_PSM, false, + BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG, + &avdt_sec_check_complete_term, NULL); + if (rc == BTM_CMD_STARTED) { + L2CA_ConnectRsp(p_ccb->peer_addr, p_tbl->id, lcid, L2CAP_CONN_PENDING, + L2CAP_CONN_OK); + } + return; + } + } + /* deal with simultaneous control channel connect case */ + else { + p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_CONN); + if (p_tbl != NULL) { + /* reject their connection */ + result = L2CAP_CONN_NO_RESOURCES; } - /* deal with simultaneous control channel connect case */ + /* this must be a traffic channel; are we accepting a traffic channel + ** for this ccb? + */ else { - p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_CONN); + p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_MEDIA, p_ccb, AVDT_AD_ST_ACP); + if (p_tbl != NULL) { + /* yes; proceed with connection */ + result = L2CAP_CONN_OK; + } +#if (AVDT_REPORTING == TRUE) + /* this must be a reporting channel; are we accepting a reporting channel + ** for this ccb? + */ + else { + p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_REPORT, p_ccb, AVDT_AD_ST_ACP); if (p_tbl != NULL) { - /* reject their connection */ - result = L2CAP_CONN_NO_RESOURCES; + /* yes; proceed with connection */ + result = L2CAP_CONN_OK; } - /* this must be a traffic channel; are we accepting a traffic channel - ** for this ccb? - */ - else { - p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_MEDIA, p_ccb, AVDT_AD_ST_ACP); - if (p_tbl != NULL) { - /* yes; proceed with connection */ - result = L2CAP_CONN_OK; - } -#if (AVDT_REPORTING == TRUE) - /* this must be a reporting channel; are we accepting a reporting channel - ** for this ccb? - */ - else { - p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_REPORT, p_ccb, AVDT_AD_ST_ACP); - if (p_tbl != NULL) { - /* yes; proceed with connection */ - result = L2CAP_CONN_OK; - } #endif - /* else we're not listening for traffic channel; reject */ - else { - result = L2CAP_CONN_NO_PSM; - } - } + /* else we're not listening for traffic channel; reject */ + else { + result = L2CAP_CONN_NO_PSM; } + } } - - /* Send L2CAP connect rsp */ - L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store idx in LCID table, store LCID in routing table */ - avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = avdt_ad_tc_tbl_to_idx(p_tbl); - avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid; - - /* transition to configuration state */ - p_tbl->state = AVDT_AD_ST_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = p_tbl->my_mtu; - cfg.flush_to_present = true; - cfg.flush_to = p_tbl->my_flush_to; - L2CA_ConfigReq(lcid, &cfg); - } + } + + /* Send L2CAP connect rsp */ + L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); + + /* if result ok, proceed with connection */ + if (result == L2CAP_CONN_OK) { + /* store idx in LCID table, store LCID in routing table */ + avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = + avdt_ad_tc_tbl_to_idx(p_tbl); + avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid; + + /* transition to configuration state */ + p_tbl->state = AVDT_AD_ST_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = p_tbl->my_mtu; + cfg.flush_to_present = true; + cfg.flush_to = p_tbl->my_flush_to; + L2CA_ConfigReq(lcid, &cfg); + } } /******************************************************************************* @@ -293,76 +282,67 @@ void avdt_l2c_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, * Returns void * ******************************************************************************/ -void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVDT_TC_TBL *p_tbl; - tL2CAP_CFG_INFO cfg; - tAVDT_CCB *p_ccb; - - AVDT_TRACE_DEBUG("avdt_l2c_connect_cfm_cback lcid: %d, result: %d", - lcid, result); - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - /* if in correct state */ - if (p_tbl->state == AVDT_AD_ST_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - if(p_tbl->tcid != AVDT_CHAN_SIG) - { - /* set channel state */ - p_tbl->state = AVDT_AD_ST_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = p_tbl->my_mtu; - cfg.flush_to_present = true; - cfg.flush_to = p_tbl->my_flush_to; - L2CA_ConfigReq(lcid, &cfg); - } - else - { - p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); - if(p_ccb == NULL) - { - result = L2CAP_CONN_NO_RESOURCES; - } - else - { - /* set channel state */ - p_tbl->state = AVDT_AD_ST_SEC_INT; - p_tbl->lcid = lcid; - p_tbl->cfg_flags = AVDT_L2C_CFG_CONN_INT; - - if (interop_match_addr(INTEROP_2MBPS_LINK_ONLY, (const bt_bdaddr_t *) &p_ccb->peer_addr)) { - // Disable 3DH packets for AVDT ACL to improve sensitivity on HS - tACL_CONN *p_acl_cb = btm_bda_to_acl(p_ccb->peer_addr, BT_TRANSPORT_BR_EDR); - btm_set_packet_types(p_acl_cb, (btm_cb.btm_acl_pkt_types_supported | - HCI_PKT_TYPES_MASK_NO_3_DH1 | - HCI_PKT_TYPES_MASK_NO_3_DH3 | - HCI_PKT_TYPES_MASK_NO_3_DH5)); - } - - /* Check the security */ - btm_sec_mx_access_request (p_ccb->peer_addr, AVDT_PSM, - true, BTM_SEC_PROTO_AVDT, - AVDT_CHAN_SIG, - &avdt_sec_check_complete_orig, NULL); - } - } +void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVDT_TC_TBL* p_tbl; + tL2CAP_CFG_INFO cfg; + tAVDT_CCB* p_ccb; + + AVDT_TRACE_DEBUG("avdt_l2c_connect_cfm_cback lcid: %d, result: %d", lcid, + result); + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + /* if in correct state */ + if (p_tbl->state == AVDT_AD_ST_CONN) { + /* if result successful */ + if (result == L2CAP_CONN_OK) { + if (p_tbl->tcid != AVDT_CHAN_SIG) { + /* set channel state */ + p_tbl->state = AVDT_AD_ST_CFG; + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = p_tbl->my_mtu; + cfg.flush_to_present = true; + cfg.flush_to = p_tbl->my_flush_to; + L2CA_ConfigReq(lcid, &cfg); + } else { + p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); + if (p_ccb == NULL) { + result = L2CAP_CONN_NO_RESOURCES; + } else { + /* set channel state */ + p_tbl->state = AVDT_AD_ST_SEC_INT; + p_tbl->lcid = lcid; + p_tbl->cfg_flags = AVDT_L2C_CFG_CONN_INT; + + if (interop_match_addr(INTEROP_2MBPS_LINK_ONLY, + (const bt_bdaddr_t*)&p_ccb->peer_addr)) { + // Disable 3DH packets for AVDT ACL to improve sensitivity on HS + tACL_CONN* p_acl_cb = + btm_bda_to_acl(p_ccb->peer_addr, BT_TRANSPORT_BR_EDR); + btm_set_packet_types( + p_acl_cb, + (btm_cb.btm_acl_pkt_types_supported | + HCI_PKT_TYPES_MASK_NO_3_DH1 | HCI_PKT_TYPES_MASK_NO_3_DH3 | + HCI_PKT_TYPES_MASK_NO_3_DH5)); } - /* failure; notify adaption that channel closed */ - if (result != L2CAP_CONN_OK) - { - avdt_ad_tc_close_ind(p_tbl, result); - } + /* Check the security */ + btm_sec_mx_access_request(p_ccb->peer_addr, AVDT_PSM, true, + BTM_SEC_PROTO_AVDT, AVDT_CHAN_SIG, + &avdt_sec_check_complete_orig, NULL); + } } + } + + /* failure; notify adaption that channel closed */ + if (result != L2CAP_CONN_OK) { + avdt_ad_tc_close_ind(p_tbl, result); + } } + } } /******************************************************************************* @@ -375,39 +355,33 @@ void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avdt_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVDT_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - p_tbl->lcid = lcid; - - /* if in correct state */ - if (p_tbl->state == AVDT_AD_ST_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CONN_OK) - { - /* update cfg_flags */ - p_tbl->cfg_flags |= AVDT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_tbl->cfg_flags & AVDT_L2C_CFG_IND_DONE) - { - avdt_ad_tc_open_ind(p_tbl); - } - } - /* else failure */ - else - { - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } +void avdt_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVDT_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + p_tbl->lcid = lcid; + + /* if in correct state */ + if (p_tbl->state == AVDT_AD_ST_CFG) { + /* if result successful */ + if (p_cfg->result == L2CAP_CONN_OK) { + /* update cfg_flags */ + p_tbl->cfg_flags |= AVDT_L2C_CFG_CFM_DONE; + + /* if configuration complete */ + if (p_tbl->cfg_flags & AVDT_L2C_CFG_IND_DONE) { + avdt_ad_tc_open_ind(p_tbl); } + } + /* else failure */ + else { + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } } + } } /******************************************************************************* @@ -420,43 +394,36 @@ void avdt_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVDT_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_tbl->peer_mtu = p_cfg->mtu; - } - else - { - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - } - AVDT_TRACE_DEBUG("peer_mtu: %d, lcid: x%x",p_tbl->peer_mtu, lcid); - - /* send L2CAP configure response */ - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->result = L2CAP_CFG_OK; - L2CA_ConfigRsp(lcid, p_cfg); - - /* if first config ind */ - if ((p_tbl->cfg_flags & AVDT_L2C_CFG_IND_DONE) == 0) - { - /* update cfg_flags */ - p_tbl->cfg_flags |= AVDT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_tbl->cfg_flags & AVDT_L2C_CFG_CFM_DONE) - { - avdt_ad_tc_open_ind(p_tbl); - } - } +void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tAVDT_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + /* store the mtu in tbl */ + if (p_cfg->mtu_present) { + p_tbl->peer_mtu = p_cfg->mtu; + } else { + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + } + AVDT_TRACE_DEBUG("peer_mtu: %d, lcid: x%x", p_tbl->peer_mtu, lcid); + + /* send L2CAP configure response */ + memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + p_cfg->result = L2CAP_CFG_OK; + L2CA_ConfigRsp(lcid, p_cfg); + + /* if first config ind */ + if ((p_tbl->cfg_flags & AVDT_L2C_CFG_IND_DONE) == 0) { + /* update cfg_flags */ + p_tbl->cfg_flags |= AVDT_L2C_CFG_IND_DONE; + + /* if configuration complete */ + if (p_tbl->cfg_flags & AVDT_L2C_CFG_CFM_DONE) { + avdt_ad_tc_open_ind(p_tbl); + } } + } } /******************************************************************************* @@ -469,24 +436,21 @@ void avdt_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) -{ - tAVDT_TC_TBL *p_tbl; - - AVDT_TRACE_DEBUG("avdt_l2c_disconnect_ind_cback lcid: %d, ack_needed: %d", - lcid, ack_needed); - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - - avdt_ad_tc_close_ind(p_tbl, 0); +void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { + tAVDT_TC_TBL* p_tbl; + + AVDT_TRACE_DEBUG("avdt_l2c_disconnect_ind_cback lcid: %d, ack_needed: %d", + lcid, ack_needed); + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + if (ack_needed) { + /* send L2CAP disconnect response */ + L2CA_DisconnectRsp(lcid); } + + avdt_ad_tc_close_ind(p_tbl, 0); + } } /******************************************************************************* @@ -499,18 +463,16 @@ void avdt_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) * Returns void * ******************************************************************************/ -void avdt_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tAVDT_TC_TBL *p_tbl; - - AVDT_TRACE_DEBUG("avdt_l2c_disconnect_cfm_cback lcid: %d, result: %d", - lcid, result); - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - avdt_ad_tc_close_ind(p_tbl, result); - } +void avdt_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) { + tAVDT_TC_TBL* p_tbl; + + AVDT_TRACE_DEBUG("avdt_l2c_disconnect_cfm_cback lcid: %d, result: %d", lcid, + result); + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + avdt_ad_tc_close_ind(p_tbl, result); + } } /******************************************************************************* @@ -523,16 +485,14 @@ void avdt_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) -{ - tAVDT_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - avdt_ad_tc_cong_ind(p_tbl, is_congested); - } +void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) { + tAVDT_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + avdt_ad_tc_cong_ind(p_tbl, is_congested); + } } /******************************************************************************* @@ -545,17 +505,13 @@ void avdt_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) * Returns void * ******************************************************************************/ -void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) -{ - tAVDT_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - avdt_ad_tc_data_ind(p_tbl, p_buf); - } - else /* prevent buffer leak */ - osi_free(p_buf); +void avdt_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) { + tAVDT_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = avdt_ad_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + avdt_ad_tc_data_ind(p_tbl, p_buf); + } else /* prevent buffer leak */ + osi_free(p_buf); } - diff --git a/stack/avdt/avdt_msg.cc b/stack/avdt/avdt_msg.cc index 0d18e487f..8d62a20ab 100644 --- a/stack/avdt/avdt_msg.cc +++ b/stack/avdt/avdt_msg.cc @@ -27,67 +27,73 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btu.h" #include "osi/include/osi.h" -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /***************************************************************************** * constants ****************************************************************************/ /* mask of all psc values */ -#define AVDT_MSG_PSC_MASK (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT | \ - AVDT_PSC_RECOV | AVDT_PSC_HDRCMP | AVDT_PSC_MUX) -#define AVDT_PSC_PROTECT (1<<4) /* Content Protection */ -#define AVDT_PSC_CODEC (1<<7) /* codec */ - +#define AVDT_MSG_PSC_MASK \ + (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT | AVDT_PSC_RECOV | \ + AVDT_PSC_HDRCMP | AVDT_PSC_MUX) +#define AVDT_PSC_PROTECT (1 << 4) /* Content Protection */ +#define AVDT_PSC_CODEC (1 << 7) /* codec */ /***************************************************************************** * type definitions ****************************************************************************/ /* type for message building functions */ -typedef void (*tAVDT_MSG_BLD)(uint8_t **p, tAVDT_MSG *p_msg); +typedef void (*tAVDT_MSG_BLD)(uint8_t** p, tAVDT_MSG* p_msg); /* type for message parsing functions */ -typedef uint8_t (*tAVDT_MSG_PRS)(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); - +typedef uint8_t (*tAVDT_MSG_PRS)(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len); /***************************************************************************** * local function declarations ****************************************************************************/ -static void avdt_msg_bld_none(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_single(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_setconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_reconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_multi(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_security_cmd(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_discover_rsp(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_svccap(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_security_rsp(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_all_svccap(uint8_t **p, tAVDT_MSG *p_msg); -static void avdt_msg_bld_delay_rpt(uint8_t **p, tAVDT_MSG *p_msg); - -static uint8_t avdt_msg_prs_none(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_single(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_multi(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); -static uint8_t avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, uint8_t *p, uint16_t len); +static void avdt_msg_bld_none(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_single(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_setconfig_cmd(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_reconfig_cmd(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_multi(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_security_cmd(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_discover_rsp(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_svccap(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_security_rsp(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_all_svccap(uint8_t** p, tAVDT_MSG* p_msg); +static void avdt_msg_bld_delay_rpt(uint8_t** p, tAVDT_MSG* p_msg); + +static uint8_t avdt_msg_prs_none(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len); +static uint8_t avdt_msg_prs_single(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len); +static uint8_t avdt_msg_prs_setconfig_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_reconfig_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_multi(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len); +static uint8_t avdt_msg_prs_security_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_discover_rsp(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_svccap(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len); +static uint8_t avdt_msg_prs_all_svccap(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_security_rsp(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); +static uint8_t avdt_msg_prs_delay_rpt(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len); /***************************************************************************** * constants @@ -95,168 +101,165 @@ static uint8_t avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, uint8_t *p, uint16_t le /* table of information element minimum lengths used for parsing */ const uint8_t avdt_msg_ie_len_min[] = { - 0, /* unused */ - AVDT_LEN_TRANS_MIN, /* media transport */ - AVDT_LEN_REPORT_MIN, /* reporting */ - AVDT_LEN_RECOV_MIN, /* recovery */ - AVDT_LEN_PROTECT_MIN, /* content protection */ - AVDT_LEN_HDRCMP_MIN, /* header compression */ - AVDT_LEN_MUX_MIN, /* multiplexing */ - AVDT_LEN_CODEC_MIN, /* codec */ - AVDT_LEN_DELAY_RPT_MIN /* delay report */ + 0, /* unused */ + AVDT_LEN_TRANS_MIN, /* media transport */ + AVDT_LEN_REPORT_MIN, /* reporting */ + AVDT_LEN_RECOV_MIN, /* recovery */ + AVDT_LEN_PROTECT_MIN, /* content protection */ + AVDT_LEN_HDRCMP_MIN, /* header compression */ + AVDT_LEN_MUX_MIN, /* multiplexing */ + AVDT_LEN_CODEC_MIN, /* codec */ + AVDT_LEN_DELAY_RPT_MIN /* delay report */ }; /* table of information element minimum lengths used for parsing */ const uint8_t avdt_msg_ie_len_max[] = { - 0, /* unused */ - AVDT_LEN_TRANS_MAX, /* media transport */ - AVDT_LEN_REPORT_MAX, /* reporting */ - AVDT_LEN_RECOV_MAX, /* recovery */ - AVDT_LEN_PROTECT_MAX, /* content protection */ - AVDT_LEN_HDRCMP_MAX, /* header compression */ - AVDT_LEN_MUX_MAX, /* multiplexing */ - AVDT_LEN_CODEC_MAX, /* codec */ - AVDT_LEN_DELAY_RPT_MAX /* delay report */ + 0, /* unused */ + AVDT_LEN_TRANS_MAX, /* media transport */ + AVDT_LEN_REPORT_MAX, /* reporting */ + AVDT_LEN_RECOV_MAX, /* recovery */ + AVDT_LEN_PROTECT_MAX, /* content protection */ + AVDT_LEN_HDRCMP_MAX, /* header compression */ + AVDT_LEN_MUX_MAX, /* multiplexing */ + AVDT_LEN_CODEC_MAX, /* codec */ + AVDT_LEN_DELAY_RPT_MAX /* delay report */ }; /* table of error codes used when decoding information elements */ const uint8_t avdt_msg_ie_err[] = { - 0, /* unused */ - AVDT_ERR_MEDIA_TRANS, /* media transport */ - AVDT_ERR_LENGTH, /* reporting */ - AVDT_ERR_RECOV_FMT, /* recovery */ - AVDT_ERR_CP_FMT, /* content protection */ - AVDT_ERR_ROHC_FMT, /* header compression */ - AVDT_ERR_MUX_FMT, /* multiplexing */ - AVDT_ERR_SERVICE, /* codec */ - AVDT_ERR_SERVICE /* delay report ?? */ + 0, /* unused */ + AVDT_ERR_MEDIA_TRANS, /* media transport */ + AVDT_ERR_LENGTH, /* reporting */ + AVDT_ERR_RECOV_FMT, /* recovery */ + AVDT_ERR_CP_FMT, /* content protection */ + AVDT_ERR_ROHC_FMT, /* header compression */ + AVDT_ERR_MUX_FMT, /* multiplexing */ + AVDT_ERR_SERVICE, /* codec */ + AVDT_ERR_SERVICE /* delay report ?? */ }; /* table of packet type minimum lengths */ static const uint8_t avdt_msg_pkt_type_len[] = { - AVDT_LEN_TYPE_SINGLE, - AVDT_LEN_TYPE_START, - AVDT_LEN_TYPE_CONT, - AVDT_LEN_TYPE_END -}; + AVDT_LEN_TYPE_SINGLE, AVDT_LEN_TYPE_START, AVDT_LEN_TYPE_CONT, + AVDT_LEN_TYPE_END}; /* function table for building command messages */ const tAVDT_MSG_BLD avdt_msg_bld_cmd[] = { - avdt_msg_bld_none, /* discover */ - avdt_msg_bld_single, /* get capabilities */ - avdt_msg_bld_setconfig_cmd, /* set configuration */ - avdt_msg_bld_single, /* get configuration */ - avdt_msg_bld_reconfig_cmd, /* reconfigure */ - avdt_msg_bld_single, /* open */ - avdt_msg_bld_multi, /* start */ - avdt_msg_bld_single, /* close */ - avdt_msg_bld_multi, /* suspend */ - avdt_msg_bld_single, /* abort */ - avdt_msg_bld_security_cmd, /* security control */ - avdt_msg_bld_single, /* get all capabilities */ - avdt_msg_bld_delay_rpt /* delay report */ + avdt_msg_bld_none, /* discover */ + avdt_msg_bld_single, /* get capabilities */ + avdt_msg_bld_setconfig_cmd, /* set configuration */ + avdt_msg_bld_single, /* get configuration */ + avdt_msg_bld_reconfig_cmd, /* reconfigure */ + avdt_msg_bld_single, /* open */ + avdt_msg_bld_multi, /* start */ + avdt_msg_bld_single, /* close */ + avdt_msg_bld_multi, /* suspend */ + avdt_msg_bld_single, /* abort */ + avdt_msg_bld_security_cmd, /* security control */ + avdt_msg_bld_single, /* get all capabilities */ + avdt_msg_bld_delay_rpt /* delay report */ }; /* function table for building response messages */ const tAVDT_MSG_BLD avdt_msg_bld_rsp[] = { - avdt_msg_bld_discover_rsp, /* discover */ - avdt_msg_bld_svccap, /* get capabilities */ - avdt_msg_bld_none, /* set configuration */ - avdt_msg_bld_all_svccap, /* get configuration */ - avdt_msg_bld_none, /* reconfigure */ - avdt_msg_bld_none, /* open */ - avdt_msg_bld_none, /* start */ - avdt_msg_bld_none, /* close */ - avdt_msg_bld_none, /* suspend */ - avdt_msg_bld_none, /* abort */ - avdt_msg_bld_security_rsp, /* security control */ - avdt_msg_bld_all_svccap, /* get all capabilities */ - avdt_msg_bld_none /* delay report */ + avdt_msg_bld_discover_rsp, /* discover */ + avdt_msg_bld_svccap, /* get capabilities */ + avdt_msg_bld_none, /* set configuration */ + avdt_msg_bld_all_svccap, /* get configuration */ + avdt_msg_bld_none, /* reconfigure */ + avdt_msg_bld_none, /* open */ + avdt_msg_bld_none, /* start */ + avdt_msg_bld_none, /* close */ + avdt_msg_bld_none, /* suspend */ + avdt_msg_bld_none, /* abort */ + avdt_msg_bld_security_rsp, /* security control */ + avdt_msg_bld_all_svccap, /* get all capabilities */ + avdt_msg_bld_none /* delay report */ }; /* function table for parsing command messages */ const tAVDT_MSG_PRS avdt_msg_prs_cmd[] = { - avdt_msg_prs_none, /* discover */ - avdt_msg_prs_single, /* get capabilities */ - avdt_msg_prs_setconfig_cmd, /* set configuration */ - avdt_msg_prs_single, /* get configuration */ - avdt_msg_prs_reconfig_cmd, /* reconfigure */ - avdt_msg_prs_single, /* open */ - avdt_msg_prs_multi, /* start */ - avdt_msg_prs_single, /* close */ - avdt_msg_prs_multi, /* suspend */ - avdt_msg_prs_single, /* abort */ - avdt_msg_prs_security_cmd, /* security control */ - avdt_msg_prs_single, /* get all capabilities */ - avdt_msg_prs_delay_rpt /* delay report */ + avdt_msg_prs_none, /* discover */ + avdt_msg_prs_single, /* get capabilities */ + avdt_msg_prs_setconfig_cmd, /* set configuration */ + avdt_msg_prs_single, /* get configuration */ + avdt_msg_prs_reconfig_cmd, /* reconfigure */ + avdt_msg_prs_single, /* open */ + avdt_msg_prs_multi, /* start */ + avdt_msg_prs_single, /* close */ + avdt_msg_prs_multi, /* suspend */ + avdt_msg_prs_single, /* abort */ + avdt_msg_prs_security_cmd, /* security control */ + avdt_msg_prs_single, /* get all capabilities */ + avdt_msg_prs_delay_rpt /* delay report */ }; /* function table for parsing response messages */ const tAVDT_MSG_PRS avdt_msg_prs_rsp[] = { - avdt_msg_prs_discover_rsp, /* discover */ - avdt_msg_prs_svccap, /* get capabilities */ - avdt_msg_prs_none, /* set configuration */ - avdt_msg_prs_all_svccap, /* get configuration */ - avdt_msg_prs_none, /* reconfigure */ - avdt_msg_prs_none, /* open */ - avdt_msg_prs_none, /* start */ - avdt_msg_prs_none, /* close */ - avdt_msg_prs_none, /* suspend */ - avdt_msg_prs_none, /* abort */ - avdt_msg_prs_security_rsp, /* security control */ - avdt_msg_prs_all_svccap, /* get all capabilities */ - avdt_msg_prs_none /* delay report */ + avdt_msg_prs_discover_rsp, /* discover */ + avdt_msg_prs_svccap, /* get capabilities */ + avdt_msg_prs_none, /* set configuration */ + avdt_msg_prs_all_svccap, /* get configuration */ + avdt_msg_prs_none, /* reconfigure */ + avdt_msg_prs_none, /* open */ + avdt_msg_prs_none, /* start */ + avdt_msg_prs_none, /* close */ + avdt_msg_prs_none, /* suspend */ + avdt_msg_prs_none, /* abort */ + avdt_msg_prs_security_rsp, /* security control */ + avdt_msg_prs_all_svccap, /* get all capabilities */ + avdt_msg_prs_none /* delay report */ }; /* command message-to-event lookup table */ const uint8_t avdt_msg_cmd_2_evt[] = { - AVDT_CCB_MSG_DISCOVER_CMD_EVT + AVDT_CCB_MKR, /* discover */ - AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get capabilities */ - AVDT_SCB_MSG_SETCONFIG_CMD_EVT, /* set configuration */ - AVDT_SCB_MSG_GETCONFIG_CMD_EVT, /* get configuration */ - AVDT_SCB_MSG_RECONFIG_CMD_EVT, /* reconfigure */ - AVDT_SCB_MSG_OPEN_CMD_EVT, /* open */ - AVDT_CCB_MSG_START_CMD_EVT + AVDT_CCB_MKR, /* start */ - AVDT_SCB_MSG_CLOSE_CMD_EVT, /* close */ - AVDT_CCB_MSG_SUSPEND_CMD_EVT + AVDT_CCB_MKR, /* suspend */ - AVDT_SCB_MSG_ABORT_CMD_EVT, /* abort */ - AVDT_SCB_MSG_SECURITY_CMD_EVT, /* security control */ - AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get all capabilities */ - AVDT_SCB_MSG_DELAY_RPT_CMD_EVT /* delay report */ + AVDT_CCB_MSG_DISCOVER_CMD_EVT + AVDT_CCB_MKR, /* discover */ + AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get capabilities */ + AVDT_SCB_MSG_SETCONFIG_CMD_EVT, /* set configuration */ + AVDT_SCB_MSG_GETCONFIG_CMD_EVT, /* get configuration */ + AVDT_SCB_MSG_RECONFIG_CMD_EVT, /* reconfigure */ + AVDT_SCB_MSG_OPEN_CMD_EVT, /* open */ + AVDT_CCB_MSG_START_CMD_EVT + AVDT_CCB_MKR, /* start */ + AVDT_SCB_MSG_CLOSE_CMD_EVT, /* close */ + AVDT_CCB_MSG_SUSPEND_CMD_EVT + AVDT_CCB_MKR, /* suspend */ + AVDT_SCB_MSG_ABORT_CMD_EVT, /* abort */ + AVDT_SCB_MSG_SECURITY_CMD_EVT, /* security control */ + AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get all capabilities */ + AVDT_SCB_MSG_DELAY_RPT_CMD_EVT /* delay report */ }; /* response message-to-event lookup table */ const uint8_t avdt_msg_rsp_2_evt[] = { - AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */ - AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */ - AVDT_SCB_MSG_SETCONFIG_RSP_EVT, /* set configuration */ - AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */ - AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */ - AVDT_SCB_MSG_OPEN_RSP_EVT, /* open */ - AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */ - AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */ - AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */ - AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */ - AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */ - AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */ - AVDT_SCB_MSG_DELAY_RPT_RSP_EVT /* delay report */ + AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */ + AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */ + AVDT_SCB_MSG_SETCONFIG_RSP_EVT, /* set configuration */ + AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */ + AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */ + AVDT_SCB_MSG_OPEN_RSP_EVT, /* open */ + AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */ + AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */ + AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */ + AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */ + AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */ + AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */ + AVDT_SCB_MSG_DELAY_RPT_RSP_EVT /* delay report */ }; /* reject message-to-event lookup table */ const uint8_t avdt_msg_rej_2_evt[] = { - AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */ - AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */ - AVDT_SCB_MSG_SETCONFIG_REJ_EVT, /* set configuration */ - AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */ - AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */ - AVDT_SCB_MSG_OPEN_REJ_EVT, /* open */ - AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */ - AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */ - AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */ - AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */ - AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */ - AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */ - 0 /* delay report */ + AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */ + AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */ + AVDT_SCB_MSG_SETCONFIG_REJ_EVT, /* set configuration */ + AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */ + AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */ + AVDT_SCB_MSG_OPEN_REJ_EVT, /* open */ + AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */ + AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */ + AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */ + AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */ + AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */ + AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */ + 0 /* delay report */ }; /******************************************************************************* @@ -270,58 +273,51 @@ const uint8_t avdt_msg_rej_2_evt[] = { * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_cfg(uint8_t **p, tAVDT_CFG *p_cfg) -{ - uint8_t len; +static void avdt_msg_bld_cfg(uint8_t** p, tAVDT_CFG* p_cfg) { + uint8_t len; - /* for now, just build media transport, codec, and content protection, and multiplexing */ + /* for now, just build media transport, codec, and content protection, and + * multiplexing */ - /* media transport */ - if (p_cfg->psc_mask & AVDT_PSC_TRANS) - { - *(*p)++ = AVDT_CAT_TRANS; - *(*p)++ = 0; /* length */ - } + /* media transport */ + if (p_cfg->psc_mask & AVDT_PSC_TRANS) { + *(*p)++ = AVDT_CAT_TRANS; + *(*p)++ = 0; /* length */ + } #if (AVDT_REPORTING == TRUE) - /* reporting transport */ - if (p_cfg->psc_mask & AVDT_PSC_REPORT) - { - *(*p)++ = AVDT_CAT_REPORT; - *(*p)++ = 0; /* length */ - } + /* reporting transport */ + if (p_cfg->psc_mask & AVDT_PSC_REPORT) { + *(*p)++ = AVDT_CAT_REPORT; + *(*p)++ = 0; /* length */ + } #endif - /* codec */ - if (p_cfg->num_codec != 0) - { - *(*p)++ = AVDT_CAT_CODEC; - len = p_cfg->codec_info[0] + 1; - if( len > AVDT_CODEC_SIZE ) - len = AVDT_CODEC_SIZE; - - memcpy(*p, p_cfg->codec_info, len); - *p += len; - } - - /* content protection */ - if (p_cfg->num_protect != 0) - { - *(*p)++ = AVDT_CAT_PROTECT; - len = p_cfg->protect_info[0] + 1; - if( len > AVDT_PROTECT_SIZE ) - len = AVDT_PROTECT_SIZE; - - memcpy(*p, p_cfg->protect_info, len); - *p += len; - } - - /* delay report */ - if (p_cfg->psc_mask & AVDT_PSC_DELAY_RPT) - { - *(*p)++ = AVDT_CAT_DELAY_RPT; - *(*p)++ = 0; /* length */ - } + /* codec */ + if (p_cfg->num_codec != 0) { + *(*p)++ = AVDT_CAT_CODEC; + len = p_cfg->codec_info[0] + 1; + if (len > AVDT_CODEC_SIZE) len = AVDT_CODEC_SIZE; + + memcpy(*p, p_cfg->codec_info, len); + *p += len; + } + + /* content protection */ + if (p_cfg->num_protect != 0) { + *(*p)++ = AVDT_CAT_PROTECT; + len = p_cfg->protect_info[0] + 1; + if (len > AVDT_PROTECT_SIZE) len = AVDT_PROTECT_SIZE; + + memcpy(*p, p_cfg->protect_info, len); + *p += len; + } + + /* delay report */ + if (p_cfg->psc_mask & AVDT_PSC_DELAY_RPT) { + *(*p)++ = AVDT_CAT_DELAY_RPT; + *(*p)++ = 0; /* length */ + } } /******************************************************************************* @@ -334,10 +330,9 @@ static void avdt_msg_bld_cfg(uint8_t **p, tAVDT_CFG *p_cfg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_none(UNUSED_ATTR uint8_t **p, - UNUSED_ATTR tAVDT_MSG *p_msg) -{ - return; +static void avdt_msg_bld_none(UNUSED_ATTR uint8_t** p, + UNUSED_ATTR tAVDT_MSG* p_msg) { + return; } /******************************************************************************* @@ -351,9 +346,8 @@ static void avdt_msg_bld_none(UNUSED_ATTR uint8_t **p, * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_single(uint8_t **p, tAVDT_MSG *p_msg) -{ - AVDT_MSG_BLD_SEID(*p, p_msg->single.seid); +static void avdt_msg_bld_single(uint8_t** p, tAVDT_MSG* p_msg) { + AVDT_MSG_BLD_SEID(*p, p_msg->single.seid); } /******************************************************************************* @@ -367,11 +361,10 @@ static void avdt_msg_bld_single(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_setconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg) -{ - AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.hdr.seid); - AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.int_seid); - avdt_msg_bld_cfg(p, p_msg->config_cmd.p_cfg); +static void avdt_msg_bld_setconfig_cmd(uint8_t** p, tAVDT_MSG* p_msg) { + AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.hdr.seid); + AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.int_seid); + avdt_msg_bld_cfg(p, p_msg->config_cmd.p_cfg); } /******************************************************************************* @@ -385,13 +378,12 @@ static void avdt_msg_bld_setconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_reconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg) -{ - AVDT_MSG_BLD_SEID(*p, p_msg->reconfig_cmd.hdr.seid); +static void avdt_msg_bld_reconfig_cmd(uint8_t** p, tAVDT_MSG* p_msg) { + AVDT_MSG_BLD_SEID(*p, p_msg->reconfig_cmd.hdr.seid); - /* force psc mask zero to build only codec and security */ - p_msg->reconfig_cmd.p_cfg->psc_mask = 0; - avdt_msg_bld_cfg(p, p_msg->reconfig_cmd.p_cfg); + /* force psc mask zero to build only codec and security */ + p_msg->reconfig_cmd.p_cfg->psc_mask = 0; + avdt_msg_bld_cfg(p, p_msg->reconfig_cmd.p_cfg); } /******************************************************************************* @@ -405,14 +397,12 @@ static void avdt_msg_bld_reconfig_cmd(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_multi(uint8_t **p, tAVDT_MSG *p_msg) -{ - int i; +static void avdt_msg_bld_multi(uint8_t** p, tAVDT_MSG* p_msg) { + int i; - for (i = 0; i < p_msg->multi.num_seps; i++) - { - AVDT_MSG_BLD_SEID(*p, p_msg->multi.seid_list[i]); - } + for (i = 0; i < p_msg->multi.num_seps; i++) { + AVDT_MSG_BLD_SEID(*p, p_msg->multi.seid_list[i]); + } } /******************************************************************************* @@ -425,11 +415,10 @@ static void avdt_msg_bld_multi(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_security_cmd(uint8_t **p, tAVDT_MSG *p_msg) -{ - AVDT_MSG_BLD_SEID(*p, p_msg->security_cmd.hdr.seid); - memcpy(*p, p_msg->security_cmd.p_data, p_msg->security_cmd.len); - *p += p_msg->security_cmd.len; +static void avdt_msg_bld_security_cmd(uint8_t** p, tAVDT_MSG* p_msg) { + AVDT_MSG_BLD_SEID(*p, p_msg->security_cmd.hdr.seid); + memcpy(*p, p_msg->security_cmd.p_data, p_msg->security_cmd.len); + *p += p_msg->security_cmd.len; } /******************************************************************************* @@ -442,10 +431,9 @@ static void avdt_msg_bld_security_cmd(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_delay_rpt(uint8_t **p, tAVDT_MSG *p_msg) -{ - AVDT_MSG_BLD_SEID(*p, p_msg->delay_rpt_cmd.hdr.seid); - UINT16_TO_BE_STREAM(*p, p_msg->delay_rpt_cmd.delay); +static void avdt_msg_bld_delay_rpt(uint8_t** p, tAVDT_MSG* p_msg) { + AVDT_MSG_BLD_SEID(*p, p_msg->delay_rpt_cmd.hdr.seid); + UINT16_TO_BE_STREAM(*p, p_msg->delay_rpt_cmd.delay); } /******************************************************************************* @@ -459,18 +447,16 @@ static void avdt_msg_bld_delay_rpt(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_discover_rsp(uint8_t **p, tAVDT_MSG *p_msg) -{ - int i; - - for (i = 0; i < p_msg->discover_rsp.num_seps; i++) - { - /* build discover rsp info */ - AVDT_MSG_BLD_DISC(*p, p_msg->discover_rsp.p_sep_info[i].seid, - p_msg->discover_rsp.p_sep_info[i].in_use, - p_msg->discover_rsp.p_sep_info[i].media_type, - p_msg->discover_rsp.p_sep_info[i].tsep); - } +static void avdt_msg_bld_discover_rsp(uint8_t** p, tAVDT_MSG* p_msg) { + int i; + + for (i = 0; i < p_msg->discover_rsp.num_seps; i++) { + /* build discover rsp info */ + AVDT_MSG_BLD_DISC(*p, p_msg->discover_rsp.p_sep_info[i].seid, + p_msg->discover_rsp.p_sep_info[i].in_use, + p_msg->discover_rsp.p_sep_info[i].media_type, + p_msg->discover_rsp.p_sep_info[i].tsep); + } } /******************************************************************************* @@ -484,14 +470,13 @@ static void avdt_msg_bld_discover_rsp(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_svccap(uint8_t **p, tAVDT_MSG *p_msg) -{ - tAVDT_CFG cfg; - - /* make sure the delay report category is not reported */ - memcpy (&cfg, p_msg->svccap.p_cfg, sizeof(tAVDT_CFG)); - cfg.psc_mask &= ~AVDT_PSC_DELAY_RPT; - avdt_msg_bld_cfg(p, &cfg); +static void avdt_msg_bld_svccap(uint8_t** p, tAVDT_MSG* p_msg) { + tAVDT_CFG cfg; + + /* make sure the delay report category is not reported */ + memcpy(&cfg, p_msg->svccap.p_cfg, sizeof(tAVDT_CFG)); + cfg.psc_mask &= ~AVDT_PSC_DELAY_RPT; + avdt_msg_bld_cfg(p, &cfg); } /******************************************************************************* @@ -505,9 +490,8 @@ static void avdt_msg_bld_svccap(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_all_svccap(uint8_t **p, tAVDT_MSG *p_msg) -{ - avdt_msg_bld_cfg(p, p_msg->svccap.p_cfg); +static void avdt_msg_bld_all_svccap(uint8_t** p, tAVDT_MSG* p_msg) { + avdt_msg_bld_cfg(p, p_msg->svccap.p_cfg); } /******************************************************************************* @@ -521,10 +505,9 @@ static void avdt_msg_bld_all_svccap(uint8_t **p, tAVDT_MSG *p_msg) * Returns void. * ******************************************************************************/ -static void avdt_msg_bld_security_rsp(uint8_t **p, tAVDT_MSG *p_msg) -{ - memcpy(*p, p_msg->security_rsp.p_data, p_msg->security_rsp.len); - *p += p_msg->security_rsp.len; +static void avdt_msg_bld_security_rsp(uint8_t** p, tAVDT_MSG* p_msg) { + memcpy(*p, p_msg->security_rsp.p_data, p_msg->security_rsp.len); + *p += p_msg->security_rsp.len; } /******************************************************************************* @@ -539,136 +522,127 @@ static void avdt_msg_bld_security_rsp(uint8_t **p, tAVDT_MSG *p_msg) * in p_elem. * ******************************************************************************/ -static uint8_t avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, uint8_t *p, uint16_t len, uint8_t* p_elem, uint8_t sig_id) -{ - uint8_t *p_end; - uint8_t elem = 0; - uint8_t elem_len; - uint8_t tmp; - uint8_t err = 0; - uint8_t protect_offset = 0; - - if (!p_cfg) - { - AVDT_TRACE_ERROR ("not expecting this cfg"); - return AVDT_ERR_BAD_STATE; +static uint8_t avdt_msg_prs_cfg(tAVDT_CFG* p_cfg, uint8_t* p, uint16_t len, + uint8_t* p_elem, uint8_t sig_id) { + uint8_t* p_end; + uint8_t elem = 0; + uint8_t elem_len; + uint8_t tmp; + uint8_t err = 0; + uint8_t protect_offset = 0; + + if (!p_cfg) { + AVDT_TRACE_ERROR("not expecting this cfg"); + return AVDT_ERR_BAD_STATE; + } + + p_cfg->psc_mask = 0; + p_cfg->num_codec = 0; + p_cfg->num_protect = 0; + + /* while there is still data to parse */ + p_end = p + len; + while ((p < p_end) && (err == 0)) { + /* verify overall length */ + if ((p_end - p) < AVDT_LEN_CFG_MIN) { + err = AVDT_ERR_PAYLOAD; + break; } - p_cfg->psc_mask = 0; - p_cfg->num_codec = 0; - p_cfg->num_protect = 0; + /* get and verify info elem id, length */ + elem = *p++; + elem_len = *p++; + + if ((elem == 0) || (elem > AVDT_CAT_MAX_CUR)) { + /* this may not be really bad. + * It may be a service category that is too new for us. + * allow these to be parsed without reporting an error. + * If this is a "capability" (as in GetCapRsp & GetConfigRsp), this is + * filtered out. + * If this is a Configuration (as in SetConfigCmd & ReconfigCmd), + * this will be marked as an error in the caller of this function */ + if ((sig_id == AVDT_SIG_SETCONFIG) || (sig_id == AVDT_SIG_RECONFIG)) { + /* Cannot accept unknown category. */ + err = AVDT_ERR_CATEGORY; + break; + } else /* GETCAP or GET_ALLCAP */ + { + /* Skip unknown categories. */ + p += elem_len; + AVDT_TRACE_DEBUG("skipping unknown service category=%d len: %d", elem, + elem_len); + continue; + } + } - /* while there is still data to parse */ - p_end = p + len; - while ((p < p_end) && (err == 0)) - { - /* verify overall length */ - if ((p_end - p) < AVDT_LEN_CFG_MIN) - { - err = AVDT_ERR_PAYLOAD; - break; - } + if ((elem_len > avdt_msg_ie_len_max[elem]) || + (elem_len < avdt_msg_ie_len_min[elem])) { + err = avdt_msg_ie_err[elem]; + break; + } - /* get and verify info elem id, length */ - elem = *p++; - elem_len = *p++; - - if ((elem == 0) || (elem > AVDT_CAT_MAX_CUR)) - { - /* this may not be really bad. - * It may be a service category that is too new for us. - * allow these to be parsed without reporting an error. - * If this is a "capability" (as in GetCapRsp & GetConfigRsp), this is filtered out. - * If this is a Configuration (as in SetConfigCmd & ReconfigCmd), - * this will be marked as an error in the caller of this function */ - if ((sig_id == AVDT_SIG_SETCONFIG) || (sig_id == AVDT_SIG_RECONFIG)) - { - /* Cannot accept unknown category. */ - err = AVDT_ERR_CATEGORY; - break; - } - else /* GETCAP or GET_ALLCAP */ - { - /* Skip unknown categories. */ - p += elem_len; - AVDT_TRACE_DEBUG("skipping unknown service category=%d len: %d", elem, elem_len); - continue; - } + /* add element to psc mask, but mask out codec or protect */ + p_cfg->psc_mask |= (1 << elem); + AVDT_TRACE_DEBUG("elem=%d elem_len: %d psc_mask=0x%x", elem, elem_len, + p_cfg->psc_mask); + + /* parse individual information elements with additional parameters */ + switch (elem) { + case AVDT_CAT_RECOV: + p_cfg->recov_type = *p++; + p_cfg->recov_mrws = *p++; + p_cfg->recov_mnmp = *p++; + if (p_cfg->recov_type != AVDT_RECOV_RFC2733) { + err = AVDT_ERR_RECOV_TYPE; + } else if ((p_cfg->recov_mrws < AVDT_RECOV_MRWS_MIN) || + (p_cfg->recov_mrws > AVDT_RECOV_MRWS_MAX) || + (p_cfg->recov_mnmp < AVDT_RECOV_MNMP_MIN) || + (p_cfg->recov_mnmp > AVDT_RECOV_MNMP_MAX)) { + err = AVDT_ERR_RECOV_FMT; } - - if ((elem_len > avdt_msg_ie_len_max[elem]) || - (elem_len < avdt_msg_ie_len_min[elem])) - { - err = avdt_msg_ie_err[elem]; - break; + break; + + case AVDT_CAT_PROTECT: + p_cfg->psc_mask &= ~AVDT_PSC_PROTECT; + if ((elem_len + protect_offset) < AVDT_PROTECT_SIZE) { + p_cfg->num_protect++; + p_cfg->protect_info[protect_offset] = elem_len; + protect_offset++; + memcpy(&p_cfg->protect_info[protect_offset], p, elem_len); + protect_offset += elem_len; } - - /* add element to psc mask, but mask out codec or protect */ - p_cfg->psc_mask |= (1 << elem); - AVDT_TRACE_DEBUG("elem=%d elem_len: %d psc_mask=0x%x", elem, elem_len, p_cfg->psc_mask); - - /* parse individual information elements with additional parameters */ - switch (elem) - { - case AVDT_CAT_RECOV: - p_cfg->recov_type = *p++; - p_cfg->recov_mrws = *p++; - p_cfg->recov_mnmp = *p++; - if (p_cfg->recov_type != AVDT_RECOV_RFC2733) - { - err = AVDT_ERR_RECOV_TYPE; - } - else if ((p_cfg->recov_mrws < AVDT_RECOV_MRWS_MIN) || - (p_cfg->recov_mrws > AVDT_RECOV_MRWS_MAX) || - (p_cfg->recov_mnmp < AVDT_RECOV_MNMP_MIN) || - (p_cfg->recov_mnmp > AVDT_RECOV_MNMP_MAX)) - { - err = AVDT_ERR_RECOV_FMT; - } - break; - - case AVDT_CAT_PROTECT: - p_cfg->psc_mask &= ~AVDT_PSC_PROTECT; - if ((elem_len + protect_offset) < AVDT_PROTECT_SIZE) - { - p_cfg->num_protect++; - p_cfg->protect_info[protect_offset] = elem_len; - protect_offset++; - memcpy(&p_cfg->protect_info[protect_offset], p, elem_len); - protect_offset += elem_len; - } - p += elem_len; - break; - - case AVDT_CAT_HDRCMP: - p_cfg->hdrcmp_mask = *p++; - break; - - case AVDT_CAT_CODEC: - p_cfg->psc_mask &= ~AVDT_PSC_CODEC; - tmp = elem_len; - if (elem_len >= AVDT_CODEC_SIZE) - { - tmp = AVDT_CODEC_SIZE - 1; - } - p_cfg->num_codec++; - p_cfg->codec_info[0] = elem_len; - memcpy(&p_cfg->codec_info[1], p, tmp); - p += elem_len; - break; - - case AVDT_CAT_DELAY_RPT: - break; - - default: - p += elem_len; - break; - } /* switch */ - } /* while ! err, !end*/ - *p_elem = elem; - AVDT_TRACE_DEBUG("err=0x%x, elem:0x%x psc_mask=0x%x", err, elem, p_cfg->psc_mask); - - return err; + p += elem_len; + break; + + case AVDT_CAT_HDRCMP: + p_cfg->hdrcmp_mask = *p++; + break; + + case AVDT_CAT_CODEC: + p_cfg->psc_mask &= ~AVDT_PSC_CODEC; + tmp = elem_len; + if (elem_len >= AVDT_CODEC_SIZE) { + tmp = AVDT_CODEC_SIZE - 1; + } + p_cfg->num_codec++; + p_cfg->codec_info[0] = elem_len; + memcpy(&p_cfg->codec_info[1], p, tmp); + p += elem_len; + break; + + case AVDT_CAT_DELAY_RPT: + break; + + default: + p += elem_len; + break; + } /* switch */ + } /* while ! err, !end*/ + *p_elem = elem; + AVDT_TRACE_DEBUG("err=0x%x, elem:0x%x psc_mask=0x%x", err, elem, + p_cfg->psc_mask); + + return err; } /******************************************************************************* @@ -682,10 +656,10 @@ static uint8_t avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, uint8_t *p, uint16_t len, uint * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_none(UNUSED_ATTR tAVDT_MSG *p_msg, UNUSED_ATTR uint8_t *p, - UNUSED_ATTR uint16_t len) -{ - return 0; +static uint8_t avdt_msg_prs_none(UNUSED_ATTR tAVDT_MSG* p_msg, + UNUSED_ATTR uint8_t* p, + UNUSED_ATTR uint16_t len) { + return 0; } /******************************************************************************* @@ -699,25 +673,20 @@ static uint8_t avdt_msg_prs_none(UNUSED_ATTR tAVDT_MSG *p_msg, UNUSED_ATTR uint8 * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_single(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = 0; +static uint8_t avdt_msg_prs_single(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len) { + uint8_t err = 0; - /* verify len */ - if (len != AVDT_LEN_SINGLE) - { - err = AVDT_ERR_LENGTH; - } - else - { - AVDT_MSG_PRS_SEID(p, p_msg->single.seid); + /* verify len */ + if (len != AVDT_LEN_SINGLE) { + err = AVDT_ERR_LENGTH; + } else { + AVDT_MSG_PRS_SEID(p, p_msg->single.seid); - if (avdt_scb_by_hdl(p_msg->single.seid) == NULL) - { - err = AVDT_ERR_SEID; - } + if (avdt_scb_by_hdl(p_msg->single.seid) == NULL) { + err = AVDT_ERR_SEID; } - return err; + } + return err; } /******************************************************************************* @@ -731,52 +700,45 @@ static uint8_t avdt_msg_prs_single(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = 0; - - p_msg->hdr.err_param = 0; - - /* verify len */ - if (len < AVDT_LEN_SETCONFIG_MIN) - { - err = AVDT_ERR_LENGTH; +static uint8_t avdt_msg_prs_setconfig_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + uint8_t err = 0; + + p_msg->hdr.err_param = 0; + + /* verify len */ + if (len < AVDT_LEN_SETCONFIG_MIN) { + err = AVDT_ERR_LENGTH; + } else { + /* get seids */ + AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.hdr.seid); + if (avdt_scb_by_hdl(p_msg->config_cmd.hdr.seid) == NULL) { + err = AVDT_ERR_SEID; } - else - { - /* get seids */ - AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.hdr.seid); - if (avdt_scb_by_hdl(p_msg->config_cmd.hdr.seid) == NULL) - { - err = AVDT_ERR_SEID; - } - AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.int_seid); - if ((p_msg->config_cmd.int_seid < AVDT_SEID_MIN) || - (p_msg->config_cmd.int_seid > AVDT_SEID_MAX)) - { - err = AVDT_ERR_SEID; - } + AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.int_seid); + if ((p_msg->config_cmd.int_seid < AVDT_SEID_MIN) || + (p_msg->config_cmd.int_seid > AVDT_SEID_MAX)) { + err = AVDT_ERR_SEID; } - - if (!err) - { - /* parse configuration parameters */ - len -= 2; - err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_SETCONFIG); - - if (!err) - { - /* verify protocol service capabilities are supported */ - if (((p_msg->config_cmd.p_cfg->psc_mask & (~AVDT_PSC)) != 0) || - (p_msg->config_cmd.p_cfg->num_codec == 0)) - { - err = AVDT_ERR_INVALID_CAP; - } - } + } + + if (!err) { + /* parse configuration parameters */ + len -= 2; + err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, + &p_msg->hdr.err_param, AVDT_SIG_SETCONFIG); + + if (!err) { + /* verify protocol service capabilities are supported */ + if (((p_msg->config_cmd.p_cfg->psc_mask & (~AVDT_PSC)) != 0) || + (p_msg->config_cmd.p_cfg->num_codec == 0)) { + err = AVDT_ERR_INVALID_CAP; + } } + } - return err; + return err; } /******************************************************************************* @@ -790,44 +752,39 @@ static uint8_t avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = 0; - - p_msg->hdr.err_param = 0; - - /* verify len */ - if (len < AVDT_LEN_RECONFIG_MIN) - { - err = AVDT_ERR_LENGTH; - } - else - { - /* get seid */ - AVDT_MSG_PRS_SEID(p, p_msg->reconfig_cmd.hdr.seid); - if (avdt_scb_by_hdl(p_msg->reconfig_cmd.hdr.seid) == NULL) - { - err = AVDT_ERR_SEID; - } - else - { - /* parse config parameters */ - len--; - err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_RECONFIG); - - /* verify no protocol service capabilities in parameters */ - if (!err) - { - AVDT_TRACE_DEBUG("avdt_msg_prs_reconfig_cmd psc_mask=0x%x/0x%x", p_msg->config_cmd.p_cfg->psc_mask, AVDT_MSG_PSC_MASK); - if ((p_msg->config_cmd.p_cfg->psc_mask != 0) || - (p_msg->config_cmd.p_cfg->num_codec == 0 && p_msg->config_cmd.p_cfg->num_protect == 0)) - { - err = AVDT_ERR_INVALID_CAP; - } - } +static uint8_t avdt_msg_prs_reconfig_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + uint8_t err = 0; + + p_msg->hdr.err_param = 0; + + /* verify len */ + if (len < AVDT_LEN_RECONFIG_MIN) { + err = AVDT_ERR_LENGTH; + } else { + /* get seid */ + AVDT_MSG_PRS_SEID(p, p_msg->reconfig_cmd.hdr.seid); + if (avdt_scb_by_hdl(p_msg->reconfig_cmd.hdr.seid) == NULL) { + err = AVDT_ERR_SEID; + } else { + /* parse config parameters */ + len--; + err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, + &p_msg->hdr.err_param, AVDT_SIG_RECONFIG); + + /* verify no protocol service capabilities in parameters */ + if (!err) { + AVDT_TRACE_DEBUG("avdt_msg_prs_reconfig_cmd psc_mask=0x%x/0x%x", + p_msg->config_cmd.p_cfg->psc_mask, AVDT_MSG_PSC_MASK); + if ((p_msg->config_cmd.p_cfg->psc_mask != 0) || + (p_msg->config_cmd.p_cfg->num_codec == 0 && + p_msg->config_cmd.p_cfg->num_protect == 0)) { + err = AVDT_ERR_INVALID_CAP; } + } } - return err; + } + return err; } /******************************************************************************* @@ -841,35 +798,29 @@ static uint8_t avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_multi(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - int i; - uint8_t err = 0; - - p_msg->hdr.err_param = 0; - - /* verify len */ - if (len < AVDT_LEN_MULTI_MIN || (len > AVDT_NUM_SEPS)) - { - err = AVDT_ERR_LENGTH; - } - else - { - /* get and verify all seps */ - for (i = 0; i < len; i++) - { - AVDT_MSG_PRS_SEID(p, p_msg->multi.seid_list[i]); - if (avdt_scb_by_hdl(p_msg->multi.seid_list[i]) == NULL) - { - err = AVDT_ERR_SEID; - p_msg->hdr.err_param = p_msg->multi.seid_list[i]; - break; - } - } - p_msg->multi.num_seps = (uint8_t)i; +static uint8_t avdt_msg_prs_multi(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len) { + int i; + uint8_t err = 0; + + p_msg->hdr.err_param = 0; + + /* verify len */ + if (len < AVDT_LEN_MULTI_MIN || (len > AVDT_NUM_SEPS)) { + err = AVDT_ERR_LENGTH; + } else { + /* get and verify all seps */ + for (i = 0; i < len; i++) { + AVDT_MSG_PRS_SEID(p, p_msg->multi.seid_list[i]); + if (avdt_scb_by_hdl(p_msg->multi.seid_list[i]) == NULL) { + err = AVDT_ERR_SEID; + p_msg->hdr.err_param = p_msg->multi.seid_list[i]; + break; + } } + p_msg->multi.num_seps = (uint8_t)i; + } - return err; + return err; } /******************************************************************************* @@ -883,30 +834,24 @@ static uint8_t avdt_msg_prs_multi(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = 0; - - /* verify len */ - if (len < AVDT_LEN_SECURITY_MIN) - { - err = AVDT_ERR_LENGTH; - } - else - { - /* get seid */ - AVDT_MSG_PRS_SEID(p, p_msg->security_cmd.hdr.seid); - if (avdt_scb_by_hdl(p_msg->security_cmd.hdr.seid) == NULL) - { - err = AVDT_ERR_SEID; - } - else - { - p_msg->security_cmd.p_data = p; - p_msg->security_cmd.len = len - 1; - } +static uint8_t avdt_msg_prs_security_cmd(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + uint8_t err = 0; + + /* verify len */ + if (len < AVDT_LEN_SECURITY_MIN) { + err = AVDT_ERR_LENGTH; + } else { + /* get seid */ + AVDT_MSG_PRS_SEID(p, p_msg->security_cmd.hdr.seid); + if (avdt_scb_by_hdl(p_msg->security_cmd.hdr.seid) == NULL) { + err = AVDT_ERR_SEID; + } else { + p_msg->security_cmd.p_data = p; + p_msg->security_cmd.len = len - 1; } - return err; + } + return err; } /******************************************************************************* @@ -920,38 +865,35 @@ static uint8_t avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, uint8_t *p, uint16_t * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - int i; - uint8_t err = 0; - - /* determine number of seps; seps in msg is len/2, but set to minimum - ** of seps app has supplied memory for and seps in msg - */ - if (p_msg->discover_rsp.num_seps > (len / 2)) - { - p_msg->discover_rsp.num_seps = (len / 2); - } - - /* parse out sep info */ - for (i = 0; i < p_msg->discover_rsp.num_seps; i++) - { - /* parse discover rsp info */ - AVDT_MSG_PRS_DISC(p, p_msg->discover_rsp.p_sep_info[i].seid, - p_msg->discover_rsp.p_sep_info[i].in_use, - p_msg->discover_rsp.p_sep_info[i].media_type, - p_msg->discover_rsp.p_sep_info[i].tsep); - - /* verify that seid is valid */ - if ((p_msg->discover_rsp.p_sep_info[i].seid < AVDT_SEID_MIN) || - (p_msg->discover_rsp.p_sep_info[i].seid > AVDT_SEID_MAX)) - { - err = AVDT_ERR_SEID; - break; - } +static uint8_t avdt_msg_prs_discover_rsp(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + int i; + uint8_t err = 0; + + /* determine number of seps; seps in msg is len/2, but set to minimum + ** of seps app has supplied memory for and seps in msg + */ + if (p_msg->discover_rsp.num_seps > (len / 2)) { + p_msg->discover_rsp.num_seps = (len / 2); + } + + /* parse out sep info */ + for (i = 0; i < p_msg->discover_rsp.num_seps; i++) { + /* parse discover rsp info */ + AVDT_MSG_PRS_DISC(p, p_msg->discover_rsp.p_sep_info[i].seid, + p_msg->discover_rsp.p_sep_info[i].in_use, + p_msg->discover_rsp.p_sep_info[i].media_type, + p_msg->discover_rsp.p_sep_info[i].tsep); + + /* verify that seid is valid */ + if ((p_msg->discover_rsp.p_sep_info[i].seid < AVDT_SEID_MIN) || + (p_msg->discover_rsp.p_sep_info[i].seid > AVDT_SEID_MAX)) { + err = AVDT_ERR_SEID; + break; } + } - return err; + return err; } /******************************************************************************* @@ -965,16 +907,15 @@ static uint8_t avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - /* parse parameters */ - uint8_t err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GETCAP); - if (p_msg->svccap.p_cfg) - { - p_msg->svccap.p_cfg->psc_mask &= AVDT_LEG_PSC; - } - - return (err); +static uint8_t avdt_msg_prs_svccap(tAVDT_MSG* p_msg, uint8_t* p, uint16_t len) { + /* parse parameters */ + uint8_t err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, + &p_msg->hdr.err_param, AVDT_SIG_GETCAP); + if (p_msg->svccap.p_cfg) { + p_msg->svccap.p_cfg->psc_mask &= AVDT_LEG_PSC; + } + + return (err); } /******************************************************************************* @@ -988,14 +929,14 @@ static uint8_t avdt_msg_prs_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GET_ALLCAP); - if (p_msg->svccap.p_cfg) - { - p_msg->svccap.p_cfg->psc_mask &= AVDT_MSG_PSC_MASK; - } - return (err); +static uint8_t avdt_msg_prs_all_svccap(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + uint8_t err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, + &p_msg->hdr.err_param, AVDT_SIG_GET_ALLCAP); + if (p_msg->svccap.p_cfg) { + p_msg->svccap.p_cfg->psc_mask &= AVDT_MSG_PSC_MASK; + } + return (err); } /******************************************************************************* @@ -1009,12 +950,12 @@ static uint8_t avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, uint8_t *p, uint16_t le * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - p_msg->security_rsp.p_data = p; - p_msg->security_rsp.len = len; +static uint8_t avdt_msg_prs_security_rsp(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + p_msg->security_rsp.p_data = p; + p_msg->security_rsp.len = len; - return 0; + return 0; } /******************************************************************************* @@ -1027,24 +968,18 @@ static uint8_t avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, uint8_t *p, uint16_t * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_rej(tAVDT_MSG *p_msg, uint8_t *p, uint8_t sig) -{ - if ((sig == AVDT_SIG_SETCONFIG) || (sig == AVDT_SIG_RECONFIG)) - { - p_msg->hdr.err_param = *p++; - p_msg->hdr.err_code = *p; - } - else if ((sig == AVDT_SIG_START) || (sig == AVDT_SIG_SUSPEND)) - { - AVDT_MSG_PRS_SEID(p, p_msg->hdr.err_param); - p_msg->hdr.err_code = *p; - } - else - { - p_msg->hdr.err_code = *p; - } - - return 0; +static uint8_t avdt_msg_prs_rej(tAVDT_MSG* p_msg, uint8_t* p, uint8_t sig) { + if ((sig == AVDT_SIG_SETCONFIG) || (sig == AVDT_SIG_RECONFIG)) { + p_msg->hdr.err_param = *p++; + p_msg->hdr.err_code = *p; + } else if ((sig == AVDT_SIG_START) || (sig == AVDT_SIG_SUSPEND)) { + AVDT_MSG_PRS_SEID(p, p_msg->hdr.err_param); + p_msg->hdr.err_code = *p; + } else { + p_msg->hdr.err_code = *p; + } + + return 0; } /******************************************************************************* @@ -1058,35 +993,30 @@ static uint8_t avdt_msg_prs_rej(tAVDT_MSG *p_msg, uint8_t *p, uint8_t sig) * Returns Error code or zero if no error. * ******************************************************************************/ -static uint8_t avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, uint8_t *p, uint16_t len) -{ - uint8_t err = 0; - - /* verify len */ - if (len != AVDT_LEN_DELAY_RPT) - { - AVDT_TRACE_WARNING("avdt_msg_prs_delay_rpt expected len: %u got: %u", AVDT_LEN_DELAY_RPT, len); - err = AVDT_ERR_LENGTH; +static uint8_t avdt_msg_prs_delay_rpt(tAVDT_MSG* p_msg, uint8_t* p, + uint16_t len) { + uint8_t err = 0; + + /* verify len */ + if (len != AVDT_LEN_DELAY_RPT) { + AVDT_TRACE_WARNING("avdt_msg_prs_delay_rpt expected len: %u got: %u", + AVDT_LEN_DELAY_RPT, len); + err = AVDT_ERR_LENGTH; + } else { + /* get seid */ + AVDT_MSG_PRS_SEID(p, p_msg->delay_rpt_cmd.hdr.seid); + + if (avdt_scb_by_hdl(p_msg->delay_rpt_cmd.hdr.seid) == NULL) { + err = AVDT_ERR_SEID; + } else { + BE_STREAM_TO_UINT16(p_msg->delay_rpt_cmd.delay, p); + AVDT_TRACE_DEBUG("avdt_msg_prs_delay_rpt delay: %u", + p_msg->delay_rpt_cmd.delay); } - else - { - /* get seid */ - AVDT_MSG_PRS_SEID (p, p_msg->delay_rpt_cmd.hdr.seid); - - if (avdt_scb_by_hdl(p_msg->delay_rpt_cmd.hdr.seid) == NULL) - { - err = AVDT_ERR_SEID; - } - else - { - BE_STREAM_TO_UINT16 (p_msg->delay_rpt_cmd.delay, p); - AVDT_TRACE_DEBUG("avdt_msg_prs_delay_rpt delay: %u", p_msg->delay_rpt_cmd.delay); - } - } - return err; + } + return err; } - /******************************************************************************* * * Function avdt_msg_send @@ -1097,153 +1027,143 @@ static uint8_t avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, uint8_t *p, uint16_t le * Returns Congested state; true if CCB congested, false if not. * ******************************************************************************/ -bool avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg) -{ - uint16_t curr_msg_len; - uint8_t pkt_type; - uint8_t hdr_len; - tAVDT_TC_TBL *p_tbl; - BT_HDR *p_buf; - uint8_t *p; - uint8_t label; - uint8_t msg; - uint8_t sig; - uint8_t nosp = 0; /* number of subsequent packets */ - - /* look up transport channel table entry to get peer mtu */ - p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_SIG, p_ccb, NULL); - - /* set the current message if there is a message passed in */ - if (p_msg != NULL) - { - p_ccb->p_curr_msg = p_msg; - } - - /* store copy of curr_msg->len */ - curr_msg_len = p_ccb->p_curr_msg->len; +bool avdt_msg_send(tAVDT_CCB* p_ccb, BT_HDR* p_msg) { + uint16_t curr_msg_len; + uint8_t pkt_type; + uint8_t hdr_len; + tAVDT_TC_TBL* p_tbl; + BT_HDR* p_buf; + uint8_t* p; + uint8_t label; + uint8_t msg; + uint8_t sig; + uint8_t nosp = 0; /* number of subsequent packets */ + + /* look up transport channel table entry to get peer mtu */ + p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_SIG, p_ccb, NULL); + + /* set the current message if there is a message passed in */ + if (p_msg != NULL) { + p_ccb->p_curr_msg = p_msg; + } + + /* store copy of curr_msg->len */ + curr_msg_len = p_ccb->p_curr_msg->len; + + /* while not congested and we haven't sent it all */ + while ((!p_ccb->cong) && (p_ccb->p_curr_msg != NULL)) { + /* check what kind of message we've got here; we are using the offset + ** to indicate that a message is being fragmented + */ - /* while not congested and we haven't sent it all */ - while ((!p_ccb->cong) && (p_ccb->p_curr_msg != NULL)) - { - /* check what kind of message we've got here; we are using the offset - ** to indicate that a message is being fragmented - */ - - /* if message isn't being fragmented and it fits in mtu */ - if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) && - (p_ccb->p_curr_msg->len <= p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) - { - pkt_type = AVDT_PKT_TYPE_SINGLE; - hdr_len = AVDT_LEN_TYPE_SINGLE; - p_buf = p_ccb->p_curr_msg; - } - /* if message isn't being fragmented and it doesn't fit in mtu */ - else if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) && - (p_ccb->p_curr_msg->len > p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) - { - pkt_type = AVDT_PKT_TYPE_START; - hdr_len = AVDT_LEN_TYPE_START; - nosp = (p_ccb->p_curr_msg->len + AVDT_LEN_TYPE_START - p_tbl->peer_mtu) / - (p_tbl->peer_mtu - 1) + 2; - - /* get a new buffer for fragment we are sending */ - p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - - /* copy portion of data from current message to new buffer */ - p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; - p_buf->len = p_tbl->peer_mtu - hdr_len; - memcpy((uint8_t *)(p_buf + 1) + p_buf->offset, - (uint8_t *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len); - } - /* if message is being fragmented and remaining bytes don't fit in mtu */ - else if ((p_ccb->p_curr_msg->offset > AVDT_MSG_OFFSET) && - (p_ccb->p_curr_msg->len > (p_tbl->peer_mtu - AVDT_LEN_TYPE_CONT))) - { - pkt_type = AVDT_PKT_TYPE_CONT; - hdr_len = AVDT_LEN_TYPE_CONT; - - /* get a new buffer for fragment we are sending */ - p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - - /* copy portion of data from current message to new buffer */ - p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; - p_buf->len = p_tbl->peer_mtu - hdr_len; - memcpy((uint8_t *)(p_buf + 1) + p_buf->offset, - (uint8_t *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len); - } - /* if message is being fragmented and remaining bytes do fit in mtu */ - else - { - pkt_type = AVDT_PKT_TYPE_END; - hdr_len = AVDT_LEN_TYPE_END; - p_buf = p_ccb->p_curr_msg; - } + /* if message isn't being fragmented and it fits in mtu */ + if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) && + (p_ccb->p_curr_msg->len <= p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) { + pkt_type = AVDT_PKT_TYPE_SINGLE; + hdr_len = AVDT_LEN_TYPE_SINGLE; + p_buf = p_ccb->p_curr_msg; + } + /* if message isn't being fragmented and it doesn't fit in mtu */ + else if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) && + (p_ccb->p_curr_msg->len > + p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE)) { + pkt_type = AVDT_PKT_TYPE_START; + hdr_len = AVDT_LEN_TYPE_START; + nosp = (p_ccb->p_curr_msg->len + AVDT_LEN_TYPE_START - p_tbl->peer_mtu) / + (p_tbl->peer_mtu - 1) + + 2; + + /* get a new buffer for fragment we are sending */ + p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + + /* copy portion of data from current message to new buffer */ + p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; + p_buf->len = p_tbl->peer_mtu - hdr_len; + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, + (uint8_t*)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, + p_buf->len); + } + /* if message is being fragmented and remaining bytes don't fit in mtu */ + else if ((p_ccb->p_curr_msg->offset > AVDT_MSG_OFFSET) && + (p_ccb->p_curr_msg->len > + (p_tbl->peer_mtu - AVDT_LEN_TYPE_CONT))) { + pkt_type = AVDT_PKT_TYPE_CONT; + hdr_len = AVDT_LEN_TYPE_CONT; + + /* get a new buffer for fragment we are sending */ + p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + + /* copy portion of data from current message to new buffer */ + p_buf->offset = L2CAP_MIN_OFFSET + hdr_len; + p_buf->len = p_tbl->peer_mtu - hdr_len; + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, + (uint8_t*)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, + p_buf->len); + } + /* if message is being fragmented and remaining bytes do fit in mtu */ + else { + pkt_type = AVDT_PKT_TYPE_END; + hdr_len = AVDT_LEN_TYPE_END; + p_buf = p_ccb->p_curr_msg; + } - /* label, sig id, msg type are in hdr of p_curr_msg */ - label = AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_msg->layer_specific); - msg = AVDT_LAYERSPEC_MSG(p_ccb->p_curr_msg->layer_specific); - sig = (uint8_t) p_ccb->p_curr_msg->event; - AVDT_TRACE_DEBUG("avdt_msg_send label:%d, msg:%d, sig:%d", label, msg, sig); - - /* keep track of how much of msg we've sent */ - curr_msg_len -= p_buf->len; - if (curr_msg_len == 0) - { - /* entire message sent; mark as finished */ - p_ccb->p_curr_msg = NULL; - - /* start timer here for commands */ - if (msg == AVDT_MSG_TYPE_CMD) - { - /* if retransmit timeout set to zero, sig doesn't use retransmit */ - if ((sig == AVDT_SIG_DISCOVER) || (sig == AVDT_SIG_GETCAP) || - (sig == AVDT_SIG_SECURITY) || (avdt_cb.rcb.ret_tout == 0)) - { - alarm_cancel(p_ccb->idle_ccb_timer); - alarm_cancel(p_ccb->ret_ccb_timer); - period_ms_t interval_ms = avdt_cb.rcb.sig_tout * 1000; - alarm_set_on_queue(p_ccb->rsp_ccb_timer, interval_ms, - avdt_ccb_rsp_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else if (sig != AVDT_SIG_DELAY_RPT) - { - alarm_cancel(p_ccb->idle_ccb_timer); - alarm_cancel(p_ccb->rsp_ccb_timer); - period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000; - alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms, - avdt_ccb_ret_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - } + /* label, sig id, msg type are in hdr of p_curr_msg */ + label = AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_msg->layer_specific); + msg = AVDT_LAYERSPEC_MSG(p_ccb->p_curr_msg->layer_specific); + sig = (uint8_t)p_ccb->p_curr_msg->event; + AVDT_TRACE_DEBUG("avdt_msg_send label:%d, msg:%d, sig:%d", label, msg, sig); + + /* keep track of how much of msg we've sent */ + curr_msg_len -= p_buf->len; + if (curr_msg_len == 0) { + /* entire message sent; mark as finished */ + p_ccb->p_curr_msg = NULL; + + /* start timer here for commands */ + if (msg == AVDT_MSG_TYPE_CMD) { + /* if retransmit timeout set to zero, sig doesn't use retransmit */ + if ((sig == AVDT_SIG_DISCOVER) || (sig == AVDT_SIG_GETCAP) || + (sig == AVDT_SIG_SECURITY) || (avdt_cb.rcb.ret_tout == 0)) { + alarm_cancel(p_ccb->idle_ccb_timer); + alarm_cancel(p_ccb->ret_ccb_timer); + period_ms_t interval_ms = avdt_cb.rcb.sig_tout * 1000; + alarm_set_on_queue(p_ccb->rsp_ccb_timer, interval_ms, + avdt_ccb_rsp_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + } else if (sig != AVDT_SIG_DELAY_RPT) { + alarm_cancel(p_ccb->idle_ccb_timer); + alarm_cancel(p_ccb->rsp_ccb_timer); + period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000; + alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms, + avdt_ccb_ret_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); } - else - { - /* message being fragmented and not completely sent */ - p_ccb->p_curr_msg->len -= p_buf->len; - p_ccb->p_curr_msg->offset += p_buf->len; - } - - /* set up to build header */ - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; + } + } else { + /* message being fragmented and not completely sent */ + p_ccb->p_curr_msg->len -= p_buf->len; + p_ccb->p_curr_msg->offset += p_buf->len; + } - /* build header */ - AVDT_MSG_BLD_HDR(p, label, pkt_type, msg); - if (pkt_type == AVDT_PKT_TYPE_START) - { - AVDT_MSG_BLD_NOSP(p, nosp); - } - if ((pkt_type == AVDT_PKT_TYPE_START) || (pkt_type == AVDT_PKT_TYPE_SINGLE)) - { - AVDT_MSG_BLD_SIG(p, sig); - } + /* set up to build header */ + p_buf->len += hdr_len; + p_buf->offset -= hdr_len; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; - /* send msg buffer down */ - avdt_ad_write_req(AVDT_CHAN_SIG, p_ccb, NULL, p_buf); + /* build header */ + AVDT_MSG_BLD_HDR(p, label, pkt_type, msg); + if (pkt_type == AVDT_PKT_TYPE_START) { + AVDT_MSG_BLD_NOSP(p, nosp); } - return (p_ccb->cong); + if ((pkt_type == AVDT_PKT_TYPE_START) || + (pkt_type == AVDT_PKT_TYPE_SINGLE)) { + AVDT_MSG_BLD_SIG(p, sig); + } + + /* send msg buffer down */ + avdt_ad_write_req(AVDT_CHAN_SIG, p_ccb, NULL, p_buf); + } + return (p_ccb->cong); } /******************************************************************************* @@ -1257,122 +1177,110 @@ bool avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg) * available. * ******************************************************************************/ -BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf) -{ - uint8_t *p; - uint8_t pkt_type; - BT_HDR *p_ret; - - /* parse the message header */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - AVDT_MSG_PRS_PKT_TYPE(p, pkt_type); - - /* quick sanity check on length */ - if (p_buf->len < avdt_msg_pkt_type_len[pkt_type]) - { - osi_free(p_buf); - AVDT_TRACE_WARNING("Bad length during reassembly"); - p_ret = NULL; - } - /* single packet */ - else if (pkt_type == AVDT_PKT_TYPE_SINGLE) - { - /* if reassembly in progress drop message and process new single */ - if (p_ccb->p_rx_msg != NULL) - AVDT_TRACE_WARNING("Got single during reassembly"); - - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - - p_ret = p_buf; - } - /* start packet */ - else if (pkt_type == AVDT_PKT_TYPE_START) - { - /* if reassembly in progress drop message and process new single */ - if (p_ccb->p_rx_msg != NULL) - AVDT_TRACE_WARNING("Got start during reassembly"); - - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - - /* - * Allocate bigger buffer for reassembly. As lower layers are - * not aware of possible packet size after reassembly, they - * would have allocated smaller buffer. - */ - p_ccb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE); - memcpy(p_ccb->p_rx_msg, p_buf, - sizeof(BT_HDR) + p_buf->offset + p_buf->len); - - /* Free original buffer */ - osi_free(p_buf); +BT_HDR* avdt_msg_asmbl(tAVDT_CCB* p_ccb, BT_HDR* p_buf) { + uint8_t* p; + uint8_t pkt_type; + BT_HDR* p_ret; - /* update p to point to new buffer */ - p = (uint8_t *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset; + /* parse the message header */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + AVDT_MSG_PRS_PKT_TYPE(p, pkt_type); - /* copy first header byte over nosp */ - *(p + 1) = *p; - - /* set offset to point to where to copy next */ - p_ccb->p_rx_msg->offset += p_ccb->p_rx_msg->len; - - /* adjust length for packet header */ - p_ccb->p_rx_msg->len -= 1; + /* quick sanity check on length */ + if (p_buf->len < avdt_msg_pkt_type_len[pkt_type]) { + osi_free(p_buf); + AVDT_TRACE_WARNING("Bad length during reassembly"); + p_ret = NULL; + } + /* single packet */ + else if (pkt_type == AVDT_PKT_TYPE_SINGLE) { + /* if reassembly in progress drop message and process new single */ + if (p_ccb->p_rx_msg != NULL) + AVDT_TRACE_WARNING("Got single during reassembly"); + + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + + p_ret = p_buf; + } + /* start packet */ + else if (pkt_type == AVDT_PKT_TYPE_START) { + /* if reassembly in progress drop message and process new single */ + if (p_ccb->p_rx_msg != NULL) + AVDT_TRACE_WARNING("Got start during reassembly"); + + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + + /* + * Allocate bigger buffer for reassembly. As lower layers are + * not aware of possible packet size after reassembly, they + * would have allocated smaller buffer. + */ + p_ccb->p_rx_msg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE); + memcpy(p_ccb->p_rx_msg, p_buf, sizeof(BT_HDR) + p_buf->offset + p_buf->len); + + /* Free original buffer */ + osi_free(p_buf); + /* update p to point to new buffer */ + p = (uint8_t*)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset; + + /* copy first header byte over nosp */ + *(p + 1) = *p; + + /* set offset to point to where to copy next */ + p_ccb->p_rx_msg->offset += p_ccb->p_rx_msg->len; + + /* adjust length for packet header */ + p_ccb->p_rx_msg->len -= 1; + + p_ret = NULL; + } + /* continue or end */ + else { + /* if no reassembly in progress drop message */ + if (p_ccb->p_rx_msg == NULL) { + osi_free(p_buf); + AVDT_TRACE_WARNING("Pkt type=%d out of order", pkt_type); + p_ret = NULL; + } else { + /* get size of buffer holding assembled message */ + /* + * NOTE: The buffer is allocated above at the beginning of the + * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. + */ + uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); + + /* adjust offset and len of fragment for header byte */ + p_buf->offset += AVDT_LEN_TYPE_CONT; + p_buf->len -= AVDT_LEN_TYPE_CONT; + + /* verify length */ + if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) { + /* won't fit; free everything */ + AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__); + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + osi_free(p_buf); p_ret = NULL; - } - /* continue or end */ - else - { - /* if no reassembly in progress drop message */ - if (p_ccb->p_rx_msg == NULL) - { - osi_free(p_buf); - AVDT_TRACE_WARNING("Pkt type=%d out of order", pkt_type); - p_ret = NULL; - } - else - { - /* get size of buffer holding assembled message */ - /* - * NOTE: The buffer is allocated above at the beginning of the - * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. - */ - uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); - - /* adjust offset and len of fragment for header byte */ - p_buf->offset += AVDT_LEN_TYPE_CONT; - p_buf->len -= AVDT_LEN_TYPE_CONT; - - /* verify length */ - if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) { - /* won't fit; free everything */ - AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__); - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - osi_free(p_buf); - p_ret = NULL; - } else { - /* copy contents of p_buf to p_rx_msg */ - memcpy((uint8_t *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset, - (uint8_t *)(p_buf + 1) + p_buf->offset, p_buf->len); - - if (pkt_type == AVDT_PKT_TYPE_END) - { - p_ccb->p_rx_msg->offset -= p_ccb->p_rx_msg->len; - p_ccb->p_rx_msg->len += p_buf->len; - p_ret = p_ccb->p_rx_msg; - p_ccb->p_rx_msg = NULL; - } - else - { - p_ccb->p_rx_msg->offset += p_buf->len; - p_ccb->p_rx_msg->len += p_buf->len; - p_ret = NULL; - } - osi_free(p_buf); - } + } else { + /* copy contents of p_buf to p_rx_msg */ + memcpy((uint8_t*)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset, + (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len); + + if (pkt_type == AVDT_PKT_TYPE_END) { + p_ccb->p_rx_msg->offset -= p_ccb->p_rx_msg->len; + p_ccb->p_rx_msg->len += p_buf->len; + p_ret = p_ccb->p_rx_msg; + p_ccb->p_rx_msg = NULL; + } else { + p_ccb->p_rx_msg->offset += p_buf->len; + p_ccb->p_rx_msg->len += p_buf->len; + p_ret = NULL; } + osi_free(p_buf); + } } - return p_ret; + } + return p_ret; } /******************************************************************************* @@ -1390,52 +1298,48 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf) * Returns Nothing. * ******************************************************************************/ -void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, uint8_t sig_id, tAVDT_MSG *p_params) -{ - uint8_t *p; - uint8_t *p_start; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); +void avdt_msg_send_cmd(tAVDT_CCB* p_ccb, void* p_scb, uint8_t sig_id, + tAVDT_MSG* p_params) { + uint8_t* p; + uint8_t* p_start; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); - /* set up buf pointer and offset */ - p_buf->offset = AVDT_MSG_OFFSET; - p_start = p = (uint8_t *)(p_buf + 1) + p_buf->offset; + /* set up buf pointer and offset */ + p_buf->offset = AVDT_MSG_OFFSET; + p_start = p = (uint8_t*)(p_buf + 1) + p_buf->offset; - /* execute parameter building function to build message */ - (*avdt_msg_bld_cmd[sig_id - 1])(&p, p_params); + /* execute parameter building function to build message */ + (*avdt_msg_bld_cmd[sig_id - 1])(&p, p_params); - /* set len */ - p_buf->len = (uint16_t) (p - p_start); + /* set len */ + p_buf->len = (uint16_t)(p - p_start); - /* now store scb hdls, if any, in buf */ - if (p_scb != NULL) - { - p = (uint8_t *)(p_buf + 1); + /* now store scb hdls, if any, in buf */ + if (p_scb != NULL) { + p = (uint8_t*)(p_buf + 1); - /* for start and suspend, p_scb points to array of handles */ - if ((sig_id == AVDT_SIG_START) || (sig_id == AVDT_SIG_SUSPEND)) - { - memcpy(p, (uint8_t *) p_scb, p_buf->len); - } - /* for all others, p_scb points to scb as usual */ - else - { - *p = avdt_scb_to_hdl((tAVDT_SCB *) p_scb); - } + /* for start and suspend, p_scb points to array of handles */ + if ((sig_id == AVDT_SIG_START) || (sig_id == AVDT_SIG_SUSPEND)) { + memcpy(p, (uint8_t*)p_scb, p_buf->len); + } + /* for all others, p_scb points to scb as usual */ + else { + *p = avdt_scb_to_hdl((tAVDT_SCB*)p_scb); } + } - /* stash sig, label, and message type in buf */ - p_buf->event = sig_id; - AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_CMD, p_ccb->label); + /* stash sig, label, and message type in buf */ + p_buf->event = sig_id; + AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_CMD, p_ccb->label); - /* increment label */ - p_ccb->label = (p_ccb->label + 1) % 16; + /* increment label */ + p_ccb->label = (p_ccb->label + 1) % 16; - /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->cmd_q, p_buf); - avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); + /* queue message and trigger ccb to send it */ + fixed_queue_enqueue(p_ccb->cmd_q, p_buf); + avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } - /******************************************************************************* * * Function avdt_msg_send_rsp @@ -1451,32 +1355,31 @@ void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, uint8_t sig_id, tAVDT_MSG * Returns Nothing. * ******************************************************************************/ -void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) -{ - uint8_t *p; - uint8_t *p_start; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); +void avdt_msg_send_rsp(tAVDT_CCB* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) { + uint8_t* p; + uint8_t* p_start; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); - /* set up buf pointer and offset */ - p_buf->offset = AVDT_MSG_OFFSET; - p_start = p = (uint8_t *)(p_buf + 1) + p_buf->offset; + /* set up buf pointer and offset */ + p_buf->offset = AVDT_MSG_OFFSET; + p_start = p = (uint8_t*)(p_buf + 1) + p_buf->offset; - /* execute parameter building function to build message */ - (*avdt_msg_bld_rsp[sig_id - 1])(&p, p_params); + /* execute parameter building function to build message */ + (*avdt_msg_bld_rsp[sig_id - 1])(&p, p_params); - /* set length */ - p_buf->len = (uint16_t) (p - p_start); + /* set length */ + p_buf->len = (uint16_t)(p - p_start); - /* stash sig, label, and message type in buf */ - p_buf->event = sig_id; - AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label); + /* stash sig, label, and message type in buf */ + p_buf->event = sig_id; + AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, + p_params->hdr.label); - /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); - avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); + /* queue message and trigger ccb to send it */ + fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } - /******************************************************************************* * * Function avdt_msg_send_rej @@ -1492,46 +1395,40 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) * Returns Nothing. * ******************************************************************************/ -void avdt_msg_send_rej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) -{ - uint8_t *p; - uint8_t *p_start; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - - /* set up buf pointer and offset */ - p_buf->offset = AVDT_MSG_OFFSET; - p_start = p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* if sig id included, build into message */ - if (sig_id != AVDT_SIG_NONE) - { - /* if this sig has a parameter, add the parameter */ - if ((sig_id == AVDT_SIG_SETCONFIG) || - (sig_id == AVDT_SIG_RECONFIG)) - { - AVDT_MSG_BLD_PARAM(p, p_params->hdr.err_param); - } - else if ((sig_id == AVDT_SIG_START) || - (sig_id == AVDT_SIG_SUSPEND)) - { - AVDT_MSG_BLD_SEID(p, p_params->hdr.err_param); - } - - /* add the error code */ - AVDT_MSG_BLD_ERR(p, p_params->hdr.err_code); +void avdt_msg_send_rej(tAVDT_CCB* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) { + uint8_t* p; + uint8_t* p_start; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + + /* set up buf pointer and offset */ + p_buf->offset = AVDT_MSG_OFFSET; + p_start = p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* if sig id included, build into message */ + if (sig_id != AVDT_SIG_NONE) { + /* if this sig has a parameter, add the parameter */ + if ((sig_id == AVDT_SIG_SETCONFIG) || (sig_id == AVDT_SIG_RECONFIG)) { + AVDT_MSG_BLD_PARAM(p, p_params->hdr.err_param); + } else if ((sig_id == AVDT_SIG_START) || (sig_id == AVDT_SIG_SUSPEND)) { + AVDT_MSG_BLD_SEID(p, p_params->hdr.err_param); } - AVDT_TRACE_DEBUG("avdt_msg_send_rej"); - /* calculate length */ - p_buf->len = (uint16_t) (p - p_start); + /* add the error code */ + AVDT_MSG_BLD_ERR(p, p_params->hdr.err_code); + } + AVDT_TRACE_DEBUG("avdt_msg_send_rej"); + + /* calculate length */ + p_buf->len = (uint16_t)(p - p_start); - /* stash sig, label, and message type in buf */ - p_buf->event = sig_id; - AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label); + /* stash sig, label, and message type in buf */ + p_buf->event = sig_id; + AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, + p_params->hdr.label); - /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); - avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); + /* queue message and trigger ccb to send it */ + fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } /******************************************************************************* @@ -1549,27 +1446,27 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) * Returns Nothing. * ******************************************************************************/ -void avdt_msg_send_grej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) -{ - uint8_t *p; - uint8_t *p_start; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE); - - /* set up buf pointer and offset */ - p_buf->offset = AVDT_MSG_OFFSET; - p_start = p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* calculate length */ - p_buf->len = (uint16_t) (p - p_start); - - /* stash sig, label, and message type in buf */ - p_buf->event = sig_id; - AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_GRJ, p_params->hdr.label); - AVDT_TRACE_DEBUG(__func__); - - /* queue message and trigger ccb to send it */ - fixed_queue_enqueue(p_ccb->rsp_q, p_buf); - avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); +void avdt_msg_send_grej(tAVDT_CCB* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) { + uint8_t* p; + uint8_t* p_start; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(AVDT_CMD_BUF_SIZE); + + /* set up buf pointer and offset */ + p_buf->offset = AVDT_MSG_OFFSET; + p_start = p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* calculate length */ + p_buf->len = (uint16_t)(p - p_start); + + /* stash sig, label, and message type in buf */ + p_buf->event = sig_id; + AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_GRJ, + p_params->hdr.label); + AVDT_TRACE_DEBUG(__func__); + + /* queue message and trigger ccb to send it */ + fixed_queue_enqueue(p_ccb->rsp_q, p_buf); + avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL); } /******************************************************************************* @@ -1585,214 +1482,181 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, uint8_t sig_id, tAVDT_MSG *p_params) * Returns Nothing. * ******************************************************************************/ -void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf) -{ - tAVDT_SCB *p_scb; - uint8_t *p; - bool ok = true; - bool handle_rsp = false; - bool gen_rej = false; - uint8_t label; - uint8_t pkt_type; - uint8_t msg_type; - uint8_t sig = 0; - tAVDT_MSG msg; - tAVDT_CFG cfg; - uint8_t err; - uint8_t evt = 0; - uint8_t scb_hdl; - - /* reassemble message; if no message available (we received a fragment) return */ - p_buf = avdt_msg_asmbl(p_ccb, p_buf); - if (p_buf == NULL) - { - return; - } - - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* parse the message header */ - AVDT_MSG_PRS_HDR(p, label, pkt_type, msg_type); - - AVDT_TRACE_DEBUG("msg_type=%d, sig=%d", msg_type, sig); - /* set up label and ccb_idx in message hdr */ - msg.hdr.label = label; - msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); - - /* verify msg type */ - if (msg_type == AVDT_MSG_TYPE_GRJ) - { - AVDT_TRACE_WARNING("Dropping msg msg_type=%d", msg_type); - ok = false; +void avdt_msg_ind(tAVDT_CCB* p_ccb, BT_HDR* p_buf) { + tAVDT_SCB* p_scb; + uint8_t* p; + bool ok = true; + bool handle_rsp = false; + bool gen_rej = false; + uint8_t label; + uint8_t pkt_type; + uint8_t msg_type; + uint8_t sig = 0; + tAVDT_MSG msg; + tAVDT_CFG cfg; + uint8_t err; + uint8_t evt = 0; + uint8_t scb_hdl; + + /* reassemble message; if no message available (we received a fragment) return + */ + p_buf = avdt_msg_asmbl(p_ccb, p_buf); + if (p_buf == NULL) { + return; + } + + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* parse the message header */ + AVDT_MSG_PRS_HDR(p, label, pkt_type, msg_type); + + AVDT_TRACE_DEBUG("msg_type=%d, sig=%d", msg_type, sig); + /* set up label and ccb_idx in message hdr */ + msg.hdr.label = label; + msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb); + + /* verify msg type */ + if (msg_type == AVDT_MSG_TYPE_GRJ) { + AVDT_TRACE_WARNING("Dropping msg msg_type=%d", msg_type); + ok = false; + } + /* check for general reject */ + else if ((msg_type == AVDT_MSG_TYPE_REJ) && + (p_buf->len == AVDT_LEN_GEN_REJ)) { + gen_rej = true; + if (p_ccb->p_curr_cmd != NULL) { + msg.hdr.sig_id = sig = (uint8_t)p_ccb->p_curr_cmd->event; + evt = avdt_msg_rej_2_evt[sig - 1]; + msg.hdr.err_code = AVDT_ERR_NSC; + msg.hdr.err_param = 0; } - /* check for general reject */ - else if ((msg_type == AVDT_MSG_TYPE_REJ) && (p_buf->len == AVDT_LEN_GEN_REJ)) - { - gen_rej = true; - if (p_ccb->p_curr_cmd != NULL) - { - msg.hdr.sig_id = sig = (uint8_t) p_ccb->p_curr_cmd->event; - evt = avdt_msg_rej_2_evt[sig - 1]; - msg.hdr.err_code = AVDT_ERR_NSC; - msg.hdr.err_param = 0; - } + } else /* not a general reject */ + { + /* get and verify signal */ + AVDT_MSG_PRS_SIG(p, sig); + msg.hdr.sig_id = sig; + if ((sig == 0) || (sig > AVDT_SIG_MAX)) { + AVDT_TRACE_WARNING("Dropping msg sig=%d msg_type:%d", sig, msg_type); + ok = false; + + /* send a general reject */ + if (msg_type == AVDT_MSG_TYPE_CMD) { + avdt_msg_send_grej(p_ccb, sig, &msg); + } } - else /* not a general reject */ - { - /* get and verify signal */ - AVDT_MSG_PRS_SIG(p, sig); - msg.hdr.sig_id = sig; - if ((sig == 0) || (sig > AVDT_SIG_MAX)) - { - AVDT_TRACE_WARNING("Dropping msg sig=%d msg_type:%d", sig, msg_type); - ok = false; - - /* send a general reject */ - if (msg_type == AVDT_MSG_TYPE_CMD) - { - avdt_msg_send_grej(p_ccb, sig, &msg); - } - } + } + + if (ok && !gen_rej) { + /* skip over header (msg length already verified during reassembly) */ + p_buf->len -= AVDT_LEN_TYPE_SINGLE; + + /* set up to parse message */ + if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_DISCOVER)) { + /* parse discover rsp message to struct supplied by app */ + msg.discover_rsp.p_sep_info = (tAVDT_SEP_INFO*)p_ccb->p_proc_data; + msg.discover_rsp.num_seps = p_ccb->proc_param; + } else if ((msg_type == AVDT_MSG_TYPE_RSP) && + ((sig == AVDT_SIG_GETCAP) || (sig == AVDT_SIG_GET_ALLCAP))) { + /* parse discover rsp message to struct supplied by app */ + msg.svccap.p_cfg = (tAVDT_CFG*)p_ccb->p_proc_data; + } else if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_GETCONFIG)) { + /* parse get config rsp message to struct allocated locally */ + msg.svccap.p_cfg = &cfg; + } else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_SETCONFIG)) { + /* parse config cmd message to struct allocated locally */ + msg.config_cmd.p_cfg = &cfg; + } else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_RECONFIG)) { + /* parse reconfig cmd message to struct allocated locally */ + msg.reconfig_cmd.p_cfg = &cfg; } - if (ok && !gen_rej) + /* parse message; while we're at it map message sig to event */ + if (msg_type == AVDT_MSG_TYPE_CMD) { + msg.hdr.err_code = err = + (*avdt_msg_prs_cmd[sig - 1])(&msg, p, p_buf->len); + evt = avdt_msg_cmd_2_evt[sig - 1]; + } else if (msg_type == AVDT_MSG_TYPE_RSP) { + msg.hdr.err_code = err = + (*avdt_msg_prs_rsp[sig - 1])(&msg, p, p_buf->len); + evt = avdt_msg_rsp_2_evt[sig - 1]; + } else /* msg_type == AVDT_MSG_TYPE_REJ */ { - /* skip over header (msg length already verified during reassembly) */ - p_buf->len -= AVDT_LEN_TYPE_SINGLE; - - /* set up to parse message */ - if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_DISCOVER)) - { - /* parse discover rsp message to struct supplied by app */ - msg.discover_rsp.p_sep_info = (tAVDT_SEP_INFO *) p_ccb->p_proc_data; - msg.discover_rsp.num_seps = p_ccb->proc_param; - } - else if ((msg_type == AVDT_MSG_TYPE_RSP) && - ((sig == AVDT_SIG_GETCAP) || (sig == AVDT_SIG_GET_ALLCAP))) - { - /* parse discover rsp message to struct supplied by app */ - msg.svccap.p_cfg = (tAVDT_CFG *) p_ccb->p_proc_data; - } - else if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_GETCONFIG)) - { - /* parse get config rsp message to struct allocated locally */ - msg.svccap.p_cfg = &cfg; - } - else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_SETCONFIG)) - { - /* parse config cmd message to struct allocated locally */ - msg.config_cmd.p_cfg = &cfg; - } - else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_RECONFIG)) - { - /* parse reconfig cmd message to struct allocated locally */ - msg.reconfig_cmd.p_cfg = &cfg; - } - - /* parse message; while we're at it map message sig to event */ - if (msg_type == AVDT_MSG_TYPE_CMD) - { - msg.hdr.err_code = err = (*avdt_msg_prs_cmd[sig - 1])(&msg, p, p_buf->len); - evt = avdt_msg_cmd_2_evt[sig - 1]; - } - else if (msg_type == AVDT_MSG_TYPE_RSP) - { - msg.hdr.err_code = err = (*avdt_msg_prs_rsp[sig - 1])(&msg, p, p_buf->len); - evt = avdt_msg_rsp_2_evt[sig - 1]; - } - else /* msg_type == AVDT_MSG_TYPE_REJ */ - { - err = avdt_msg_prs_rej(&msg, p, sig); - evt = avdt_msg_rej_2_evt[sig - 1]; - } - - /* if parsing failed */ - if (err != 0) - { - AVDT_TRACE_WARNING("Parsing failed sig=%d err=0x%x", sig, err); - - /* if its a rsp or rej, drop it; if its a cmd, send a rej; - ** note special case for abort; never send abort reject - */ - ok = false; - if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig != AVDT_SIG_ABORT)) - { - avdt_msg_send_rej(p_ccb, sig, &msg); - } - } + err = avdt_msg_prs_rej(&msg, p, sig); + evt = avdt_msg_rej_2_evt[sig - 1]; } - /* if its a rsp or rej, check sent cmd to see if we're waiting for - ** the rsp or rej. If we didn't send a cmd for it, drop it. If - ** it does match a cmd, stop timer for the cmd. - */ - if (ok) - { - if ((msg_type == AVDT_MSG_TYPE_RSP) || (msg_type == AVDT_MSG_TYPE_REJ)) - { - if ((p_ccb->p_curr_cmd != NULL) && - (p_ccb->p_curr_cmd->event == sig) && - (AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_cmd->layer_specific) == label)) - { - /* stop timer */ - alarm_cancel(p_ccb->idle_ccb_timer); - alarm_cancel(p_ccb->ret_ccb_timer); - alarm_cancel(p_ccb->rsp_ccb_timer); - - /* clear retransmission count */ - p_ccb->ret_count = 0; - - /* later in this function handle ccb event */ - handle_rsp = true; - } - else - { - ok = false; - AVDT_TRACE_WARNING("Cmd not found for rsp sig=%d label=%d", sig, label); - } - } + /* if parsing failed */ + if (err != 0) { + AVDT_TRACE_WARNING("Parsing failed sig=%d err=0x%x", sig, err); + + /* if its a rsp or rej, drop it; if its a cmd, send a rej; + ** note special case for abort; never send abort reject + */ + ok = false; + if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig != AVDT_SIG_ABORT)) { + avdt_msg_send_rej(p_ccb, sig, &msg); + } + } + } + + /* if its a rsp or rej, check sent cmd to see if we're waiting for + ** the rsp or rej. If we didn't send a cmd for it, drop it. If + ** it does match a cmd, stop timer for the cmd. + */ + if (ok) { + if ((msg_type == AVDT_MSG_TYPE_RSP) || (msg_type == AVDT_MSG_TYPE_REJ)) { + if ((p_ccb->p_curr_cmd != NULL) && (p_ccb->p_curr_cmd->event == sig) && + (AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_cmd->layer_specific) == label)) { + /* stop timer */ + alarm_cancel(p_ccb->idle_ccb_timer); + alarm_cancel(p_ccb->ret_ccb_timer); + alarm_cancel(p_ccb->rsp_ccb_timer); + + /* clear retransmission count */ + p_ccb->ret_count = 0; + + /* later in this function handle ccb event */ + handle_rsp = true; + } else { + ok = false; + AVDT_TRACE_WARNING("Cmd not found for rsp sig=%d label=%d", sig, label); + } } + } - if (ok) - { - /* if it's a ccb event send to ccb */ - if (evt & AVDT_CCB_MKR) - { - avdt_ccb_event(p_ccb, (uint8_t)(evt & ~AVDT_CCB_MKR), (tAVDT_CCB_EVT *) &msg); - } - /* if it's a scb event */ - else - { - /* Scb events always have a single seid. For cmd, get seid from - ** message. For rej and rsp, get seid from p_curr_cmd. - */ - if (msg_type == AVDT_MSG_TYPE_CMD) - { - scb_hdl = msg.single.seid; - } - else - { - scb_hdl = *((uint8_t *)(p_ccb->p_curr_cmd + 1)); - } - - /* Map seid to the scb and send it the event. For cmd, seid has - ** already been verified by parsing function. - */ - if (evt && (p_scb = avdt_scb_by_hdl(scb_hdl)) != NULL) - { - avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT *) &msg); - } - } + if (ok) { + /* if it's a ccb event send to ccb */ + if (evt & AVDT_CCB_MKR) { + avdt_ccb_event(p_ccb, (uint8_t)(evt & ~AVDT_CCB_MKR), + (tAVDT_CCB_EVT*)&msg); } + /* if it's a scb event */ + else { + /* Scb events always have a single seid. For cmd, get seid from + ** message. For rej and rsp, get seid from p_curr_cmd. + */ + if (msg_type == AVDT_MSG_TYPE_CMD) { + scb_hdl = msg.single.seid; + } else { + scb_hdl = *((uint8_t*)(p_ccb->p_curr_cmd + 1)); + } + + /* Map seid to the scb and send it the event. For cmd, seid has + ** already been verified by parsing function. + */ + if (evt && (p_scb = avdt_scb_by_hdl(scb_hdl)) != NULL) { + avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT*)&msg); + } + } + } - /* free message buffer */ - osi_free(p_buf); + /* free message buffer */ + osi_free(p_buf); - /* if its a rsp or rej, send event to ccb to free associated - ** cmd msg buffer and handle cmd queue - */ - if (handle_rsp) - { - avdt_ccb_event(p_ccb, AVDT_CCB_RCVRSP_EVT, NULL); - } + /* if its a rsp or rej, send event to ccb to free associated + ** cmd msg buffer and handle cmd queue + */ + if (handle_rsp) { + avdt_ccb_event(p_ccb, AVDT_CCB_RCVRSP_EVT, NULL); + } } diff --git a/stack/avdt/avdt_scb.cc b/stack/avdt/avdt_scb.cc index b18f3904b..4cb456c0c 100644 --- a/stack/avdt/avdt_scb.cc +++ b/stack/avdt/avdt_scb.cc @@ -24,13 +24,13 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btu.h" #include "osi/include/osi.h" @@ -40,774 +40,721 @@ #if (AVDT_DEBUG == TRUE) /* verbose state strings for trace */ -const char * const avdt_scb_st_str[] = { - "SCB_IDLE_ST", - "SCB_CONF_ST", - "SCB_OPENING_ST", - "SCB_OPEN_ST", - "SCB_STREAM_ST", - "SCB_CLOSING_ST" -}; +const char* const avdt_scb_st_str[] = {"SCB_IDLE_ST", "SCB_CONF_ST", + "SCB_OPENING_ST", "SCB_OPEN_ST", + "SCB_STREAM_ST", "SCB_CLOSING_ST"}; /* verbose event strings for trace */ -const char * const avdt_scb_evt_str[] = { - "API_REMOVE_EVT", - "API_WRITE_REQ_EVT", - "API_GETCONFIG_REQ_EVT", - "API_DELAY_RPT_REQ", - "API_SETCONFIG_REQ_EVT", - "API_OPEN_REQ_EVT", - "API_CLOSE_REQ_EVT", - "API_RECONFIG_REQ_EVT", - "API_SECURITY_REQ_EVT", - "API_ABORT_REQ_EVT", - "API_GETCONFIG_RSP_EVT", - "API_SETCONFIG_RSP_EVT", - "API_SETCONFIG_REJ_EVT", - "API_OPEN_RSP_EVT", - "API_CLOSE_RSP_EVT", - "API_RECONFIG_RSP_EVT", - "API_SECURITY_RSP_EVT", - "API_ABORT_RSP_EVT", - "MSG_SETCONFIG_CMD_EVT", - "MSG_GETCONFIG_CMD_EVT", - "MSG_OPEN_CMD_EVT", - "MSG_START_CMD_EVT", - "MSG_SUSPEND_CMD_EVT", - "MSG_CLOSE_CMD_EVT", - "MSG_ABORT_CMD_EVT", - "MSG_RECONFIG_CMD_EVT", - "MSG_SECURITY_CMD_EVT", - "MSG_DELAY_RPT_CMD_EVT", - "MSG_DELAY_RPT_RSP_EVT", - "MSG_SETCONFIG_RSP_EVT", - "MSG_GETCONFIG_RSP_EVT", - "MSG_OPEN_RSP_EVT", - "MSG_START_RSP_EVT", - "MSG_SUSPEND_RSP_EVT", - "MSG_CLOSE_RSP_EVT", - "MSG_ABORT_RSP_EVT", - "MSG_RECONFIG_RSP_EVT", - "MSG_SECURITY_RSP_EVT", - "MSG_SETCONFIG_REJ_EVT", - "MSG_OPEN_REJ_EVT", - "MSG_START_REJ_EVT", - "MSG_SUSPEND_REJ_EVT", - "TC_TOUT_EVT", - "TC_OPEN_EVT", - "TC_CLOSE_EVT", - "TC_CONG_EVT", - "TC_DATA_EVT", - "CC_CLOSE_EVT" -}; +const char* const avdt_scb_evt_str[] = { + "API_REMOVE_EVT", "API_WRITE_REQ_EVT", "API_GETCONFIG_REQ_EVT", + "API_DELAY_RPT_REQ", "API_SETCONFIG_REQ_EVT", "API_OPEN_REQ_EVT", + "API_CLOSE_REQ_EVT", "API_RECONFIG_REQ_EVT", "API_SECURITY_REQ_EVT", + "API_ABORT_REQ_EVT", "API_GETCONFIG_RSP_EVT", "API_SETCONFIG_RSP_EVT", + "API_SETCONFIG_REJ_EVT", "API_OPEN_RSP_EVT", "API_CLOSE_RSP_EVT", + "API_RECONFIG_RSP_EVT", "API_SECURITY_RSP_EVT", "API_ABORT_RSP_EVT", + "MSG_SETCONFIG_CMD_EVT", "MSG_GETCONFIG_CMD_EVT", "MSG_OPEN_CMD_EVT", + "MSG_START_CMD_EVT", "MSG_SUSPEND_CMD_EVT", "MSG_CLOSE_CMD_EVT", + "MSG_ABORT_CMD_EVT", "MSG_RECONFIG_CMD_EVT", "MSG_SECURITY_CMD_EVT", + "MSG_DELAY_RPT_CMD_EVT", "MSG_DELAY_RPT_RSP_EVT", "MSG_SETCONFIG_RSP_EVT", + "MSG_GETCONFIG_RSP_EVT", "MSG_OPEN_RSP_EVT", "MSG_START_RSP_EVT", + "MSG_SUSPEND_RSP_EVT", "MSG_CLOSE_RSP_EVT", "MSG_ABORT_RSP_EVT", + "MSG_RECONFIG_RSP_EVT", "MSG_SECURITY_RSP_EVT", "MSG_SETCONFIG_REJ_EVT", + "MSG_OPEN_REJ_EVT", "MSG_START_REJ_EVT", "MSG_SUSPEND_REJ_EVT", + "TC_TOUT_EVT", "TC_OPEN_EVT", "TC_CLOSE_EVT", + "TC_CONG_EVT", "TC_DATA_EVT", "CC_CLOSE_EVT"}; #endif - /* action function list */ -const tAVDT_SCB_ACTION avdt_scb_action[] = { - avdt_scb_hdl_abort_cmd, - avdt_scb_hdl_abort_rsp, - avdt_scb_hdl_close_cmd, - avdt_scb_hdl_close_rsp, - avdt_scb_hdl_getconfig_cmd, - avdt_scb_hdl_getconfig_rsp, - avdt_scb_hdl_open_cmd, - avdt_scb_hdl_open_rej, - avdt_scb_hdl_open_rsp, - avdt_scb_hdl_pkt, - avdt_scb_drop_pkt, - avdt_scb_hdl_reconfig_cmd, - avdt_scb_hdl_reconfig_rsp, - avdt_scb_hdl_security_cmd, - avdt_scb_hdl_security_rsp, - avdt_scb_hdl_setconfig_cmd, - avdt_scb_hdl_setconfig_rej, - avdt_scb_hdl_setconfig_rsp, - avdt_scb_hdl_start_cmd, - avdt_scb_hdl_start_rsp, - avdt_scb_hdl_suspend_cmd, - avdt_scb_hdl_suspend_rsp, - avdt_scb_hdl_tc_close, +const tAVDT_SCB_ACTION avdt_scb_action[] = {avdt_scb_hdl_abort_cmd, + avdt_scb_hdl_abort_rsp, + avdt_scb_hdl_close_cmd, + avdt_scb_hdl_close_rsp, + avdt_scb_hdl_getconfig_cmd, + avdt_scb_hdl_getconfig_rsp, + avdt_scb_hdl_open_cmd, + avdt_scb_hdl_open_rej, + avdt_scb_hdl_open_rsp, + avdt_scb_hdl_pkt, + avdt_scb_drop_pkt, + avdt_scb_hdl_reconfig_cmd, + avdt_scb_hdl_reconfig_rsp, + avdt_scb_hdl_security_cmd, + avdt_scb_hdl_security_rsp, + avdt_scb_hdl_setconfig_cmd, + avdt_scb_hdl_setconfig_rej, + avdt_scb_hdl_setconfig_rsp, + avdt_scb_hdl_start_cmd, + avdt_scb_hdl_start_rsp, + avdt_scb_hdl_suspend_cmd, + avdt_scb_hdl_suspend_rsp, + avdt_scb_hdl_tc_close, #if (AVDT_REPORTING == TRUE) - avdt_scb_hdl_tc_close_sto, + avdt_scb_hdl_tc_close_sto, #endif - avdt_scb_hdl_tc_open, + avdt_scb_hdl_tc_open, #if (AVDT_REPORTING == TRUE) - avdt_scb_hdl_tc_open_sto, + avdt_scb_hdl_tc_open_sto, #endif - avdt_scb_snd_delay_rpt_req, - avdt_scb_hdl_delay_rpt_cmd, - avdt_scb_hdl_delay_rpt_rsp, - avdt_scb_hdl_write_req, - avdt_scb_snd_abort_req, - avdt_scb_snd_abort_rsp, - avdt_scb_snd_close_req, - avdt_scb_snd_stream_close, - avdt_scb_snd_close_rsp, - avdt_scb_snd_getconfig_req, - avdt_scb_snd_getconfig_rsp, - avdt_scb_snd_open_req, - avdt_scb_snd_open_rsp, - avdt_scb_snd_reconfig_req, - avdt_scb_snd_reconfig_rsp, - avdt_scb_snd_security_req, - avdt_scb_snd_security_rsp, - avdt_scb_snd_setconfig_req, - avdt_scb_snd_setconfig_rej, - avdt_scb_snd_setconfig_rsp, - avdt_scb_snd_tc_close, - avdt_scb_cb_err, - avdt_scb_cong_state, - avdt_scb_rej_state, - avdt_scb_rej_in_use, - avdt_scb_rej_not_in_use, - avdt_scb_set_remove, - avdt_scb_free_pkt, - avdt_scb_clr_pkt, - avdt_scb_chk_snd_pkt, - avdt_scb_transport_channel_timer, - avdt_scb_clr_vars, - avdt_scb_dealloc -}; + avdt_scb_snd_delay_rpt_req, + avdt_scb_hdl_delay_rpt_cmd, + avdt_scb_hdl_delay_rpt_rsp, + avdt_scb_hdl_write_req, + avdt_scb_snd_abort_req, + avdt_scb_snd_abort_rsp, + avdt_scb_snd_close_req, + avdt_scb_snd_stream_close, + avdt_scb_snd_close_rsp, + avdt_scb_snd_getconfig_req, + avdt_scb_snd_getconfig_rsp, + avdt_scb_snd_open_req, + avdt_scb_snd_open_rsp, + avdt_scb_snd_reconfig_req, + avdt_scb_snd_reconfig_rsp, + avdt_scb_snd_security_req, + avdt_scb_snd_security_rsp, + avdt_scb_snd_setconfig_req, + avdt_scb_snd_setconfig_rej, + avdt_scb_snd_setconfig_rsp, + avdt_scb_snd_tc_close, + avdt_scb_cb_err, + avdt_scb_cong_state, + avdt_scb_rej_state, + avdt_scb_rej_in_use, + avdt_scb_rej_not_in_use, + avdt_scb_set_remove, + avdt_scb_free_pkt, + avdt_scb_clr_pkt, + avdt_scb_chk_snd_pkt, + avdt_scb_transport_channel_timer, + avdt_scb_clr_vars, + avdt_scb_dealloc}; /* state table information */ -#define AVDT_SCB_ACTIONS 2 /* number of actions */ -#define AVDT_SCB_NEXT_STATE 2 /* position of next state */ -#define AVDT_SCB_NUM_COLS 3 /* number of columns in state tables */ +#define AVDT_SCB_ACTIONS 2 /* number of actions */ +#define AVDT_SCB_NEXT_STATE 2 /* position of next state */ +#define AVDT_SCB_NUM_COLS 3 /* number of columns in state tables */ /* state table for idle state */ const uint8_t avdt_scb_st_idle[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_DEALLOC, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_SND_SETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_SND_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_SND_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_HDL_SETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_REJ_NOT_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_HDL_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_HDL_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_OPEN_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_CONG_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_CLR_VARS, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_DEALLOC, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_SND_SETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_SND_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_SND_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_HDL_SETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_REJ_NOT_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_HDL_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_HDL_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_CONG_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_CLR_VARS, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}}; /* state table for configured state */ const uint8_t avdt_scb_st_conf[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CONF_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_SND_OPEN_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_SND_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_HDL_OPEN_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_HDL_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_HDL_OPEN_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* TC_OPEN_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* TC_CONG_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CONF_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_SND_OPEN_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_SND_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_HDL_OPEN_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_HDL_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_HDL_OPEN_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* TC_CONG_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}}; /* state table for opening state */ const uint8_t avdt_scb_st_opening[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* TC_OPEN_EVT */ -{AVDT_SCB_HDL_TC_OPEN, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_CONG_EVT */ -{AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_HDL_TC_OPEN, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_CONG_EVT */ + {AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}}; /* state table for open state */ const uint8_t avdt_scb_st_open[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_SND_RECONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_SND_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_HDL_START_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_HDL_RECONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_SND_RECONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_SND_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_HDL_START_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_HDL_RECONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, #if (AVDT_REPORTING == TRUE) -/* TC_OPEN_EVT */ -{AVDT_SCB_HDL_TC_OPEN_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_HDL_TC_OPEN_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, #else -/* TC_OPEN_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, #endif -/* TC_CONG_EVT */ -{AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST} -}; + /* TC_CONG_EVT */ + {AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}}; /* state table for streaming state */ const uint8_t avdt_scb_st_stream[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_HDL_WRITE_REQ, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_CLR_PKT, AVDT_SCB_CLOSING_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_HDL_SUSPEND_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_STREAM_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* TC_OPEN_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_CONG_EVT */ -{AVDT_SCB_CONG_STATE, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_HDL_PKT, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_HDL_WRITE_REQ, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_CLR_PKT, AVDT_SCB_CLOSING_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_HDL_SUSPEND_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_STREAM_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_CONG_EVT */ + {AVDT_SCB_CONG_STATE, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_HDL_PKT, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}}; /* state table for closing state */ const uint8_t avdt_scb_st_closing[][AVDT_SCB_NUM_COLS] = { -/* Event */ -/* Action 1 Action 2 Next state */ -/* API_REMOVE_EVT */ -{AVDT_SCB_SET_REMOVE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_WRITE_REQ_EVT */ -{AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_GETCONFIG_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_DELAY_RPT_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_SETCONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_OPEN_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_CLOSE_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_SECURITY_REQ_EVT */ -{AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_ABORT_REQ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_GETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_CLOSE_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_SECURITY_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* API_ABORT_RSP_EVT */ -{AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_GETCONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_OPEN_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_START_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SUSPEND_CMD_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_CLOSE_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_ABORT_CMD_EVT */ -{AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_RECONFIG_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SECURITY_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_DELAY_RPT_CMD_EVT */ -{AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_DELAY_RPT_RSP_EVT */ -{AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_GETCONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_OPEN_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_START_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SUSPEND_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_CLOSE_RSP_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_CLOSE_RSP, AVDT_SCB_CLOSING_ST}, -/* MSG_ABORT_RSP_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST}, -/* MSG_RECONFIG_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SECURITY_RSP_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SETCONFIG_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_OPEN_REJ_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_START_REJ_EVT */ -{AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* MSG_SUSPEND_REJ_EVT */ -{AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* TC_TOUT_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* TC_OPEN_EVT */ -{AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* TC_CLOSE_EVT */ -{AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, -/* TC_CONG_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* TC_DATA_EVT */ -{AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, -/* CC_CLOSE_EVT */ -{AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST} -}; + /* Event */ + /* Action 1 Action 2 Next state */ + /* API_REMOVE_EVT */ + {AVDT_SCB_SET_REMOVE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_WRITE_REQ_EVT */ + {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_GETCONFIG_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_DELAY_RPT_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_SETCONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_OPEN_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_CLOSE_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_SECURITY_REQ_EVT */ + {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_ABORT_REQ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_GETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_CLOSE_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_SECURITY_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* API_ABORT_RSP_EVT */ + {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_GETCONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_OPEN_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_START_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SUSPEND_CMD_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_CLOSE_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_ABORT_CMD_EVT */ + {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_RECONFIG_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SECURITY_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_DELAY_RPT_CMD_EVT */ + {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_DELAY_RPT_RSP_EVT */ + {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_GETCONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_OPEN_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_START_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SUSPEND_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_CLOSE_RSP_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_CLOSE_RSP, AVDT_SCB_CLOSING_ST}, + /* MSG_ABORT_RSP_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST}, + /* MSG_RECONFIG_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SECURITY_RSP_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SETCONFIG_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_OPEN_REJ_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_START_REJ_EVT */ + {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* MSG_SUSPEND_REJ_EVT */ + {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* TC_TOUT_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* TC_OPEN_EVT */ + {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* TC_CLOSE_EVT */ + {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}, + /* TC_CONG_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* TC_DATA_EVT */ + {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}, + /* CC_CLOSE_EVT */ + {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}}; /* type for state table */ typedef const uint8_t (*tAVDT_SCB_ST_TBL)[AVDT_SCB_NUM_COLS]; /* state table */ const tAVDT_SCB_ST_TBL avdt_scb_st_tbl[] = { - avdt_scb_st_idle, - avdt_scb_st_conf, - avdt_scb_st_opening, - avdt_scb_st_open, - avdt_scb_st_stream, - avdt_scb_st_closing -}; - + avdt_scb_st_idle, avdt_scb_st_conf, avdt_scb_st_opening, + avdt_scb_st_open, avdt_scb_st_stream, avdt_scb_st_closing}; /******************************************************************************* * @@ -819,42 +766,38 @@ const tAVDT_SCB_ST_TBL avdt_scb_st_tbl[] = { * Returns Nothing. * ******************************************************************************/ -void avdt_scb_event(tAVDT_SCB *p_scb, uint8_t event, tAVDT_SCB_EVT *p_data) -{ - tAVDT_SCB_ST_TBL state_table; - uint8_t action; - int i; +void avdt_scb_event(tAVDT_SCB* p_scb, uint8_t event, tAVDT_SCB_EVT* p_data) { + tAVDT_SCB_ST_TBL state_table; + uint8_t action; + int i; #if (AVDT_DEBUG == TRUE) - AVDT_TRACE_EVENT("SCB hdl=%d event=%d/%s state=%s", avdt_scb_to_hdl(p_scb), event, avdt_scb_evt_str[event], avdt_scb_st_str[p_scb->state]); + AVDT_TRACE_EVENT("SCB hdl=%d event=%d/%s state=%s", avdt_scb_to_hdl(p_scb), + event, avdt_scb_evt_str[event], + avdt_scb_st_str[p_scb->state]); #endif - /* set current event */ - p_scb->curr_evt = event; - - /* look up the state table for the current state */ - state_table = avdt_scb_st_tbl[p_scb->state]; - - /* set next state */ - if (p_scb->state != state_table[event][AVDT_SCB_NEXT_STATE]) { - p_scb->state = state_table[event][AVDT_SCB_NEXT_STATE]; - } - - /* execute action functions */ - for (i = 0; i < AVDT_SCB_ACTIONS; i++) - { - action = state_table[event][i]; - if (action != AVDT_SCB_IGNORE) - { - (*avdt_cb.p_scb_act[action])(p_scb, p_data); - } - else - { - break; - } + /* set current event */ + p_scb->curr_evt = event; + + /* look up the state table for the current state */ + state_table = avdt_scb_st_tbl[p_scb->state]; + + /* set next state */ + if (p_scb->state != state_table[event][AVDT_SCB_NEXT_STATE]) { + p_scb->state = state_table[event][AVDT_SCB_NEXT_STATE]; + } + + /* execute action functions */ + for (i = 0; i < AVDT_SCB_ACTIONS; i++) { + action = state_table[event][i]; + if (action != AVDT_SCB_IGNORE) { + (*avdt_cb.p_scb_act[action])(p_scb, p_data); + } else { + break; } + } } - /******************************************************************************* * * Function avdt_scb_init @@ -865,13 +808,11 @@ void avdt_scb_event(tAVDT_SCB *p_scb, uint8_t event, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_init(void) -{ - memset(&avdt_cb.scb[0], 0, sizeof(tAVDT_SCB) * AVDT_NUM_SEPS); - avdt_cb.p_scb_act = (tAVDT_SCB_ACTION *) avdt_scb_action; +void avdt_scb_init(void) { + memset(&avdt_cb.scb[0], 0, sizeof(tAVDT_SCB) * AVDT_NUM_SEPS); + avdt_cb.p_scb_act = (tAVDT_SCB_ACTION*)avdt_scb_action; } - /******************************************************************************* * * Function avdt_scb_alloc @@ -882,37 +823,33 @@ void avdt_scb_init(void) * Returns pointer to the scb, or NULL if none could be allocated. * ******************************************************************************/ -tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs) -{ - tAVDT_SCB *p_scb = &avdt_cb.scb[0]; - int i; - - /* find available scb */ - for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) - { - if (!p_scb->allocated) - { - memset(p_scb,0,sizeof(tAVDT_SCB)); - p_scb->allocated = true; - p_scb->p_ccb = NULL; - - memcpy(&p_scb->cs, p_cs, sizeof(tAVDT_CS)); - p_scb->transport_channel_timer = - alarm_new("avdt_scb.transport_channel_timer"); - AVDT_TRACE_DEBUG("%s: hdl=%d, psc_mask:0x%x", - __func__, i + 1, p_cs->cfg.psc_mask); - break; - } +tAVDT_SCB* avdt_scb_alloc(tAVDT_CS* p_cs) { + tAVDT_SCB* p_scb = &avdt_cb.scb[0]; + int i; + + /* find available scb */ + for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) { + if (!p_scb->allocated) { + memset(p_scb, 0, sizeof(tAVDT_SCB)); + p_scb->allocated = true; + p_scb->p_ccb = NULL; + + memcpy(&p_scb->cs, p_cs, sizeof(tAVDT_CS)); + p_scb->transport_channel_timer = + alarm_new("avdt_scb.transport_channel_timer"); + AVDT_TRACE_DEBUG("%s: hdl=%d, psc_mask:0x%x", __func__, i + 1, + p_cs->cfg.psc_mask); + break; } + } - if (i == AVDT_NUM_SEPS) - { - /* out of ccbs */ - p_scb = NULL; - AVDT_TRACE_WARNING("Out of scbs"); - } + if (i == AVDT_NUM_SEPS) { + /* out of ccbs */ + p_scb = NULL; + AVDT_TRACE_WARNING("Out of scbs"); + } - return p_scb; + return p_scb; } /******************************************************************************* @@ -925,12 +862,10 @@ tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs) * Returns void. * ******************************************************************************/ -void avdt_scb_dealloc(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - AVDT_TRACE_DEBUG("%s: hdl=%d", __func__, avdt_scb_to_hdl(p_scb)); - alarm_free(p_scb->transport_channel_timer); - memset(p_scb, 0, sizeof(tAVDT_SCB)); +void avdt_scb_dealloc(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + AVDT_TRACE_DEBUG("%s: hdl=%d", __func__, avdt_scb_to_hdl(p_scb)); + alarm_free(p_scb->transport_channel_timer); + memset(p_scb, 0, sizeof(tAVDT_SCB)); } /******************************************************************************* @@ -943,9 +878,8 @@ void avdt_scb_dealloc(tAVDT_SCB *p_scb, * Returns Index of scb. * ******************************************************************************/ -uint8_t avdt_scb_to_hdl(tAVDT_SCB *p_scb) -{ - return (uint8_t) (p_scb - avdt_cb.scb + 1); +uint8_t avdt_scb_to_hdl(tAVDT_SCB* p_scb) { + return (uint8_t)(p_scb - avdt_cb.scb + 1); } /******************************************************************************* @@ -959,28 +893,23 @@ uint8_t avdt_scb_to_hdl(tAVDT_SCB *p_scb) * is not allocated. * ******************************************************************************/ -tAVDT_SCB *avdt_scb_by_hdl(uint8_t hdl) -{ - tAVDT_SCB *p_scb; +tAVDT_SCB* avdt_scb_by_hdl(uint8_t hdl) { + tAVDT_SCB* p_scb; - /* verify index */ - if ((hdl > 0) && (hdl <= AVDT_NUM_SEPS)) - { - p_scb = &avdt_cb.scb[hdl - 1]; + /* verify index */ + if ((hdl > 0) && (hdl <= AVDT_NUM_SEPS)) { + p_scb = &avdt_cb.scb[hdl - 1]; - /* verify scb is allocated */ - if (!p_scb->allocated) - { - p_scb = NULL; - AVDT_TRACE_WARNING("scb hdl %d not allocated", hdl); - } - } - else - { - p_scb = NULL; - AVDT_TRACE_WARNING("scb hdl %d out of range", hdl); + /* verify scb is allocated */ + if (!p_scb->allocated) { + p_scb = NULL; + AVDT_TRACE_WARNING("scb hdl %d not allocated", hdl); } - return p_scb; + } else { + p_scb = NULL; + AVDT_TRACE_WARNING("scb hdl %d out of range", hdl); + } + return p_scb; } /******************************************************************************* @@ -993,52 +922,51 @@ tAVDT_SCB *avdt_scb_by_hdl(uint8_t hdl) * Returns SEID that failed, or 0 if success. * ******************************************************************************/ -uint8_t avdt_scb_verify(tAVDT_CCB *p_ccb, uint8_t state, uint8_t *p_seid, uint16_t num_seid, uint8_t *p_err_code) -{ - int i; - tAVDT_SCB *p_scb; - uint8_t nsc_mask; - uint8_t ret = 0; - - AVDT_TRACE_DEBUG("avdt_scb_verify state %d", state); - /* set nonsupported command mask */ - /* translate public state into private state */ - nsc_mask = 0; - if (state == AVDT_VERIFY_SUSPEND) - nsc_mask = AVDT_NSC_SUSPEND; - - /* verify every scb */ - for (i = 0, *p_err_code = 0; (i < num_seid) && (*p_err_code == 0) && (i < AVDT_NUM_SEPS); i++) - { - p_scb = avdt_scb_by_hdl(p_seid[i]); - if (p_scb == NULL) - *p_err_code = AVDT_ERR_BAD_STATE; - else if (p_scb->p_ccb != p_ccb) - *p_err_code = AVDT_ERR_BAD_STATE; - else if (p_scb->cs.nsc_mask & nsc_mask) - *p_err_code = AVDT_ERR_NSC; - - switch (state) { - case AVDT_VERIFY_OPEN: - case AVDT_VERIFY_START: - if (p_scb->state != AVDT_SCB_OPEN_ST && p_scb->state != AVDT_SCB_STREAM_ST) - *p_err_code = AVDT_ERR_BAD_STATE; - break; - - case AVDT_VERIFY_SUSPEND: - case AVDT_VERIFY_STREAMING: - if (p_scb->state != AVDT_SCB_STREAM_ST) - *p_err_code = AVDT_ERR_BAD_STATE; - break; - } +uint8_t avdt_scb_verify(tAVDT_CCB* p_ccb, uint8_t state, uint8_t* p_seid, + uint16_t num_seid, uint8_t* p_err_code) { + int i; + tAVDT_SCB* p_scb; + uint8_t nsc_mask; + uint8_t ret = 0; + + AVDT_TRACE_DEBUG("avdt_scb_verify state %d", state); + /* set nonsupported command mask */ + /* translate public state into private state */ + nsc_mask = 0; + if (state == AVDT_VERIFY_SUSPEND) nsc_mask = AVDT_NSC_SUSPEND; + + /* verify every scb */ + for (i = 0, *p_err_code = 0; + (i < num_seid) && (*p_err_code == 0) && (i < AVDT_NUM_SEPS); i++) { + p_scb = avdt_scb_by_hdl(p_seid[i]); + if (p_scb == NULL) + *p_err_code = AVDT_ERR_BAD_STATE; + else if (p_scb->p_ccb != p_ccb) + *p_err_code = AVDT_ERR_BAD_STATE; + else if (p_scb->cs.nsc_mask & nsc_mask) + *p_err_code = AVDT_ERR_NSC; + + switch (state) { + case AVDT_VERIFY_OPEN: + case AVDT_VERIFY_START: + if (p_scb->state != AVDT_SCB_OPEN_ST && + p_scb->state != AVDT_SCB_STREAM_ST) + *p_err_code = AVDT_ERR_BAD_STATE; + break; + + case AVDT_VERIFY_SUSPEND: + case AVDT_VERIFY_STREAMING: + if (p_scb->state != AVDT_SCB_STREAM_ST) + *p_err_code = AVDT_ERR_BAD_STATE; + break; } + } - if ((i != num_seid) && (i < AVDT_NUM_SEPS)) - { - ret = p_seid[i]; - } + if ((i != num_seid) && (i < AVDT_NUM_SEPS)) { + ret = p_seid[i]; + } - return ret; + return ret; } /******************************************************************************* @@ -1052,18 +980,14 @@ uint8_t avdt_scb_verify(tAVDT_CCB *p_ccb, uint8_t state, uint8_t *p_seid, uint16 * Returns Nothing. * ******************************************************************************/ -void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi) -{ - int i; - tAVDT_SCB *p_scb; - - for (i = 0; i < p_multi->num_seps; i++) - { - p_scb = avdt_scb_by_hdl(p_multi->seid_list[i]); - if (p_scb != NULL) - { - p_multi->seid_list[i] = p_scb->peer_seid; - } +void avdt_scb_peer_seid_list(tAVDT_MULTI* p_multi) { + int i; + tAVDT_SCB* p_scb; + + for (i = 0; i < p_multi->num_seps; i++) { + p_scb = avdt_scb_by_hdl(p_multi->seid_list[i]); + if (p_scb != NULL) { + p_multi->seid_list[i] = p_scb->peer_seid; } + } } - diff --git a/stack/avdt/avdt_scb_act.cc b/stack/avdt/avdt_scb_act.cc index 94323469f..ebe058256 100644 --- a/stack/avdt/avdt_scb_act.cc +++ b/stack/avdt/avdt_scb_act.cc @@ -24,19 +24,18 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" -#include "bt_utils.h" #include "a2dp_api.h" #include "avdt_api.h" -#include "avdtc_api.h" #include "avdt_int.h" +#include "avdtc_api.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btu.h" #include "osi/include/osi.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /* This table is used to lookup the callback event that matches a particular * state machine API request event. Note that state machine API request @@ -44,16 +43,16 @@ extern fixed_queue_t *btu_general_alarm_queue; * allowing for this table. */ const uint8_t avdt_scb_cback_evt[] = { - 0, /* API_REMOVE_EVT (no event) */ - AVDT_WRITE_CFM_EVT, /* API_WRITE_REQ_EVT */ - 0, /* API_GETCONFIG_REQ_EVT (no event) */ - 0, /* API_DELAY_RPT_REQ_EVT (no event) */ - AVDT_OPEN_CFM_EVT, /* API_SETCONFIG_REQ_EVT */ - AVDT_OPEN_CFM_EVT, /* API_OPEN_REQ_EVT */ - AVDT_CLOSE_CFM_EVT, /* API_CLOSE_REQ_EVT */ - AVDT_RECONFIG_CFM_EVT, /* API_RECONFIG_REQ_EVT */ - AVDT_SECURITY_CFM_EVT, /* API_SECURITY_REQ_EVT */ - 0 /* API_ABORT_REQ_EVT (no event) */ + 0, /* API_REMOVE_EVT (no event) */ + AVDT_WRITE_CFM_EVT, /* API_WRITE_REQ_EVT */ + 0, /* API_GETCONFIG_REQ_EVT (no event) */ + 0, /* API_DELAY_RPT_REQ_EVT (no event) */ + AVDT_OPEN_CFM_EVT, /* API_SETCONFIG_REQ_EVT */ + AVDT_OPEN_CFM_EVT, /* API_OPEN_REQ_EVT */ + AVDT_CLOSE_CFM_EVT, /* API_CLOSE_REQ_EVT */ + AVDT_RECONFIG_CFM_EVT, /* API_RECONFIG_REQ_EVT */ + AVDT_SECURITY_CFM_EVT, /* API_SECURITY_REQ_EVT */ + 0 /* API_ABORT_REQ_EVT (no event) */ }; /******************************************************************************* @@ -65,10 +64,10 @@ const uint8_t avdt_scb_cback_evt[] = { * Returns SSRC value. * ******************************************************************************/ -uint32_t avdt_scb_gen_ssrc(tAVDT_SCB *p_scb) -{ - /* combine the value of the media type and codec type of the SCB */ - return ((uint32_t)(p_scb->cs.cfg.codec_info[1] | p_scb->cs.cfg.codec_info[2])); +uint32_t avdt_scb_gen_ssrc(tAVDT_SCB* p_scb) { + /* combine the value of the media type and codec type of the SCB */ + return ( + (uint32_t)(p_scb->cs.cfg.codec_info[1] | p_scb->cs.cfg.codec_info[2])); } /******************************************************************************* @@ -81,10 +80,9 @@ uint32_t avdt_scb_gen_ssrc(tAVDT_SCB *p_scb) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_scb->role = AVDT_CLOSE_ACP; - avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_RSP_EVT, p_data); +void avdt_scb_hdl_abort_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_scb->role = AVDT_CLOSE_ACP; + avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_RSP_EVT, p_data); } /******************************************************************************* @@ -97,10 +95,9 @@ void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_abort_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - return; +void avdt_scb_hdl_abort_rsp(UNUSED_ATTR tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + return; } /******************************************************************************* @@ -113,10 +110,9 @@ void avdt_scb_hdl_abort_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_close_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_scb->role = AVDT_CLOSE_ACP; - avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_RSP_EVT, p_data); +void avdt_scb_hdl_close_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_scb->role = AVDT_CLOSE_ACP; + avdt_scb_event(p_scb, AVDT_SCB_API_CLOSE_RSP_EVT, p_data); } /******************************************************************************* @@ -129,9 +125,8 @@ void avdt_scb_hdl_close_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_scb->close_code = p_data->msg.hdr.err_code; +void avdt_scb_hdl_close_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_scb->close_code = p_data->msg.hdr.err_code; } /******************************************************************************* @@ -145,11 +140,10 @@ void avdt_scb_hdl_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB *p_scb,tAVDT_SCB_EVT *p_data) -{ - p_data->msg.svccap.p_cfg = &p_scb->curr_cfg; +void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_data->msg.svccap.p_cfg = &p_scb->curr_cfg; - avdt_scb_event(p_scb, AVDT_SCB_API_GETCONFIG_RSP_EVT, p_data); + avdt_scb_event(p_scb, AVDT_SCB_API_GETCONFIG_RSP_EVT, p_data); } /******************************************************************************* @@ -162,10 +156,9 @@ void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB *p_scb,tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_getconfig_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - return; +void avdt_scb_hdl_getconfig_rsp(UNUSED_ATTR tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + return; } /******************************************************************************* @@ -178,9 +171,8 @@ void avdt_scb_hdl_getconfig_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_open_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_RSP_EVT, p_data); +void avdt_scb_hdl_open_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_RSP_EVT, p_data); } /******************************************************************************* @@ -195,10 +187,9 @@ void avdt_scb_hdl_open_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_open_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* do exactly same as setconfig reject */ - avdt_scb_hdl_setconfig_rej(p_scb, p_data); +void avdt_scb_hdl_open_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* do exactly same as setconfig reject */ + avdt_scb_hdl_setconfig_rej(p_scb, p_data); } /******************************************************************************* @@ -211,17 +202,16 @@ void avdt_scb_hdl_open_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_open_rsp(tAVDT_SCB *p_scb, UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - /* initiate opening of trans channels for this SEID */ - p_scb->role = AVDT_OPEN_INT; - avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_INT); - - /* start tc connect timer */ - alarm_set_on_queue(p_scb->transport_channel_timer, - AVDT_SCB_TC_CONN_TIMEOUT_MS, - avdt_scb_transport_channel_timer_timeout, p_scb, - btu_general_alarm_queue); +void avdt_scb_hdl_open_rsp(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + /* initiate opening of trans channels for this SEID */ + p_scb->role = AVDT_OPEN_INT; + avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_INT); + + /* start tc connect timer */ + alarm_set_on_queue( + p_scb->transport_channel_timer, AVDT_SCB_TC_CONN_TIMEOUT_MS, + avdt_scb_transport_channel_timer_timeout, p_scb, btu_general_alarm_queue); } /******************************************************************************* @@ -233,72 +223,66 @@ void avdt_scb_hdl_open_rsp(tAVDT_SCB *p_scb, UNUSED_ATTR tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - uint8_t *p, *p_start; - uint8_t o_v, o_p, o_x, o_cc; - uint8_t m_pt; - uint8_t marker; - uint16_t seq; - uint32_t time_stamp; - uint16_t offset; - uint16_t ex_len; - uint8_t pad_len = 0; - - p = p_start = (uint8_t *)(p_data->p_pkt + 1) + p_data->p_pkt->offset; - - /* parse media packet header */ - AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc); - AVDT_MSG_PRS_M_PT(p, m_pt, marker); - BE_STREAM_TO_UINT16(seq, p); - BE_STREAM_TO_UINT32(time_stamp, p); - p += 4; - - /* skip over any csrc's in packet */ - p += o_cc * 4; - - /* check for and skip over extension header */ - if (o_x) - { - p += 2; - BE_STREAM_TO_UINT16(ex_len, p); - p += ex_len * 4; - } - - /* save our new offset */ - offset = (uint16_t) (p - p_start); - - /* adjust length for any padding at end of packet */ - if (o_p) - { - /* padding length in last byte of packet */ - pad_len = *(p_start + p_data->p_pkt->len); - } - - /* do sanity check */ - if ((offset > p_data->p_pkt->len) || ((pad_len + offset) > p_data->p_pkt->len)) - { - AVDT_TRACE_WARNING("Got bad media packet"); - osi_free_and_reset((void **)&p_data->p_pkt); - } - /* adjust offset and length and send it up */ - else - { - p_data->p_pkt->len -= (offset + pad_len); - p_data->p_pkt->offset += offset; - - if (p_scb->cs.p_sink_data_cback != NULL) - { - /* report sequence number */ - p_data->p_pkt->layer_specific = seq; - (*p_scb->cs.p_sink_data_cback)(avdt_scb_to_hdl(p_scb), - p_data->p_pkt, time_stamp, (uint8_t)(m_pt | (marker << 7))); - } - else - { - osi_free_and_reset((void **)&p_data->p_pkt); - } +void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + uint8_t *p, *p_start; + uint8_t o_v, o_p, o_x, o_cc; + uint8_t m_pt; + uint8_t marker; + uint16_t seq; + uint32_t time_stamp; + uint16_t offset; + uint16_t ex_len; + uint8_t pad_len = 0; + + p = p_start = (uint8_t*)(p_data->p_pkt + 1) + p_data->p_pkt->offset; + + /* parse media packet header */ + AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc); + AVDT_MSG_PRS_M_PT(p, m_pt, marker); + BE_STREAM_TO_UINT16(seq, p); + BE_STREAM_TO_UINT32(time_stamp, p); + p += 4; + + /* skip over any csrc's in packet */ + p += o_cc * 4; + + /* check for and skip over extension header */ + if (o_x) { + p += 2; + BE_STREAM_TO_UINT16(ex_len, p); + p += ex_len * 4; + } + + /* save our new offset */ + offset = (uint16_t)(p - p_start); + + /* adjust length for any padding at end of packet */ + if (o_p) { + /* padding length in last byte of packet */ + pad_len = *(p_start + p_data->p_pkt->len); + } + + /* do sanity check */ + if ((offset > p_data->p_pkt->len) || + ((pad_len + offset) > p_data->p_pkt->len)) { + AVDT_TRACE_WARNING("Got bad media packet"); + osi_free_and_reset((void**)&p_data->p_pkt); + } + /* adjust offset and length and send it up */ + else { + p_data->p_pkt->len -= (offset + pad_len); + p_data->p_pkt->offset += offset; + + if (p_scb->cs.p_sink_data_cback != NULL) { + /* report sequence number */ + p_data->p_pkt->layer_specific = seq; + (*p_scb->cs.p_sink_data_cback)(avdt_scb_to_hdl(p_scb), p_data->p_pkt, + time_stamp, + (uint8_t)(m_pt | (marker << 7))); + } else { + osi_free_and_reset((void**)&p_data->p_pkt); } + } } #if (AVDT_REPORTING == TRUE) @@ -311,69 +295,62 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -uint8_t * avdt_scb_hdl_report(tAVDT_SCB *p_scb, uint8_t *p, uint16_t len) -{ - uint16_t result = AVDT_SUCCESS; - uint8_t *p_start = p; - uint32_t ssrc; - uint8_t o_v, o_p, o_cc; - AVDT_REPORT_TYPE pt; - tAVDT_REPORT_DATA report, *p_rpt; - - AVDT_TRACE_DEBUG("%s", __func__); - if(p_scb->cs.p_report_cback) - { - p_rpt = &report; - /* parse report packet header */ - AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc); - pt = *p++; - p += 2; - BE_STREAM_TO_UINT32(ssrc, p); - - switch(pt) - { - case AVDT_RTCP_PT_SR: /* the packet type - SR (Sender Report) */ - BE_STREAM_TO_UINT32(report.sr.ntp_sec, p); - BE_STREAM_TO_UINT32(report.sr.ntp_frac, p); - BE_STREAM_TO_UINT32(report.sr.rtp_time, p); - BE_STREAM_TO_UINT32(report.sr.pkt_count, p); - BE_STREAM_TO_UINT32(report.sr.octet_count, p); - break; - - case AVDT_RTCP_PT_RR: /* the packet type - RR (Receiver Report) */ - report.rr.frag_lost = *p; - BE_STREAM_TO_UINT32(report.rr.packet_lost, p); - report.rr.packet_lost &= 0xFFFFFF; - BE_STREAM_TO_UINT32(report.rr.seq_num_rcvd, p); - BE_STREAM_TO_UINT32(report.rr.jitter, p); - BE_STREAM_TO_UINT32(report.rr.lsr, p); - BE_STREAM_TO_UINT32(report.rr.dlsr, p); - break; - - case AVDT_RTCP_PT_SDES: /* the packet type - SDES (Source Description) */ - if(*p == AVDT_RTCP_SDES_CNAME) - { - p_rpt = (tAVDT_REPORT_DATA *)(p+2); - } - else - { - AVDT_TRACE_WARNING( " - SDES SSRC=0x%08x sc=%d %d len=%d %s", - ssrc, o_cc, *p, *(p+1), p+2); - result = AVDT_BUSY; - } - break; - - default: - AVDT_TRACE_ERROR( "Bad Report pkt - packet type: %d", pt); - result = AVDT_BAD_PARAMS; +uint8_t* avdt_scb_hdl_report(tAVDT_SCB* p_scb, uint8_t* p, uint16_t len) { + uint16_t result = AVDT_SUCCESS; + uint8_t* p_start = p; + uint32_t ssrc; + uint8_t o_v, o_p, o_cc; + AVDT_REPORT_TYPE pt; + tAVDT_REPORT_DATA report, *p_rpt; + + AVDT_TRACE_DEBUG("%s", __func__); + if (p_scb->cs.p_report_cback) { + p_rpt = &report; + /* parse report packet header */ + AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc); + pt = *p++; + p += 2; + BE_STREAM_TO_UINT32(ssrc, p); + + switch (pt) { + case AVDT_RTCP_PT_SR: /* the packet type - SR (Sender Report) */ + BE_STREAM_TO_UINT32(report.sr.ntp_sec, p); + BE_STREAM_TO_UINT32(report.sr.ntp_frac, p); + BE_STREAM_TO_UINT32(report.sr.rtp_time, p); + BE_STREAM_TO_UINT32(report.sr.pkt_count, p); + BE_STREAM_TO_UINT32(report.sr.octet_count, p); + break; + + case AVDT_RTCP_PT_RR: /* the packet type - RR (Receiver Report) */ + report.rr.frag_lost = *p; + BE_STREAM_TO_UINT32(report.rr.packet_lost, p); + report.rr.packet_lost &= 0xFFFFFF; + BE_STREAM_TO_UINT32(report.rr.seq_num_rcvd, p); + BE_STREAM_TO_UINT32(report.rr.jitter, p); + BE_STREAM_TO_UINT32(report.rr.lsr, p); + BE_STREAM_TO_UINT32(report.rr.dlsr, p); + break; + + case AVDT_RTCP_PT_SDES: /* the packet type - SDES (Source Description) */ + if (*p == AVDT_RTCP_SDES_CNAME) { + p_rpt = (tAVDT_REPORT_DATA*)(p + 2); + } else { + AVDT_TRACE_WARNING(" - SDES SSRC=0x%08x sc=%d %d len=%d %s", ssrc, + o_cc, *p, *(p + 1), p + 2); + result = AVDT_BUSY; } + break; - if(result == AVDT_SUCCESS) - (*p_scb->cs.p_report_cback)(avdt_scb_to_hdl(p_scb), pt, p_rpt); - + default: + AVDT_TRACE_ERROR("Bad Report pkt - packet type: %d", pt); + result = AVDT_BAD_PARAMS; } - p_start += len; - return p_start; + + if (result == AVDT_SUCCESS) + (*p_scb->cs.p_report_cback)(avdt_scb_to_hdl(p_scb), pt, p_rpt); + } + p_start += len; + return p_start; } #endif @@ -386,18 +363,15 @@ uint8_t * avdt_scb_hdl_report(tAVDT_SCB *p_scb, uint8_t *p, uint16_t len) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ +void avdt_scb_hdl_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { #if (AVDT_REPORTING == TRUE) - if(p_data->p_pkt->layer_specific == AVDT_CHAN_REPORT) - { - uint8_t *p = (uint8_t *)(p_data->p_pkt + 1) + p_data->p_pkt->offset; - avdt_scb_hdl_report(p_scb, p, p_data->p_pkt->len); - osi_free_and_reset((void **)&p_data->p_pkt); - } - else + if (p_data->p_pkt->layer_specific == AVDT_CHAN_REPORT) { + uint8_t* p = (uint8_t*)(p_data->p_pkt + 1) + p_data->p_pkt->offset; + avdt_scb_hdl_report(p_scb, p, p_data->p_pkt->len); + osi_free_and_reset((void**)&p_data->p_pkt); + } else #endif - avdt_scb_hdl_pkt_no_frag(p_scb, p_data); + avdt_scb_hdl_pkt_no_frag(p_scb, p_data); } /******************************************************************************* @@ -410,10 +384,9 @@ void avdt_scb_hdl_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_drop_pkt(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - AVDT_TRACE_ERROR("%s dropped incoming media packet", __func__); - osi_free_and_reset((void **)&p_data->p_pkt); +void avdt_scb_drop_pkt(UNUSED_ATTR tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + AVDT_TRACE_ERROR("%s dropped incoming media packet", __func__); + osi_free_and_reset((void**)&p_data->p_pkt); } /******************************************************************************* @@ -426,27 +399,22 @@ void avdt_scb_drop_pkt(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* if command not supported */ - if (p_scb->cs.nsc_mask & AVDT_NSC_RECONFIG) - { - /* send reject */ - p_data->msg.hdr.err_code = AVDT_ERR_NSC; - p_data->msg.hdr.err_param = 0; - avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, p_data); - } - else - { - /* store requested configuration */ - memcpy(&p_scb->req_cfg, p_data->msg.reconfig_cmd.p_cfg, sizeof(tAVDT_CFG)); - - /* call application callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - AVDT_RECONFIG_IND_EVT, - (tAVDT_CTRL *) &p_data->msg.reconfig_cmd); - } +void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* if command not supported */ + if (p_scb->cs.nsc_mask & AVDT_NSC_RECONFIG) { + /* send reject */ + p_data->msg.hdr.err_code = AVDT_ERR_NSC; + p_data->msg.hdr.err_param = 0; + avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, p_data); + } else { + /* store requested configuration */ + memcpy(&p_scb->req_cfg, p_data->msg.reconfig_cmd.p_cfg, sizeof(tAVDT_CFG)); + + /* call application callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, + AVDT_RECONFIG_IND_EVT, + (tAVDT_CTRL*)&p_data->msg.reconfig_cmd); + } } /******************************************************************************* @@ -459,30 +427,26 @@ void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - if (p_data->msg.hdr.err_code == 0) - { - /* store new configuration */ - if (p_scb->req_cfg.num_codec > 0) - { - p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec; - memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info, AVDT_CODEC_SIZE); - } - if (p_scb->req_cfg.num_protect > 0) - { - p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect; - memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info, AVDT_PROTECT_SIZE); - } +void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + if (p_data->msg.hdr.err_code == 0) { + /* store new configuration */ + if (p_scb->req_cfg.num_codec > 0) { + p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec; + memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info, + AVDT_CODEC_SIZE); + } + if (p_scb->req_cfg.num_protect > 0) { + p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect; + memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info, + AVDT_PROTECT_SIZE); } + } - p_data->msg.svccap.p_cfg = &p_scb->curr_cfg; + p_data->msg.svccap.p_cfg = &p_scb->curr_cfg; - /* call application callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - AVDT_RECONFIG_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.svccap); + /* call application callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_RECONFIG_CFM_EVT, + (tAVDT_CTRL*)&p_data->msg.svccap); } /******************************************************************************* @@ -495,23 +459,18 @@ void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_security_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* if command not supported */ - if (p_scb->cs.nsc_mask & AVDT_NSC_SECURITY) - { - /* send reject */ - p_data->msg.hdr.err_code = AVDT_ERR_NSC; - avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, p_data); - } - else - { - /* call application callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - AVDT_SECURITY_IND_EVT, - (tAVDT_CTRL *) &p_data->msg.security_cmd); - } +void avdt_scb_hdl_security_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* if command not supported */ + if (p_scb->cs.nsc_mask & AVDT_NSC_SECURITY) { + /* send reject */ + p_data->msg.hdr.err_code = AVDT_ERR_NSC; + avdt_scb_event(p_scb, AVDT_SCB_API_SECURITY_RSP_EVT, p_data); + } else { + /* call application callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, + AVDT_SECURITY_IND_EVT, + (tAVDT_CTRL*)&p_data->msg.security_cmd); + } } /******************************************************************************* @@ -524,13 +483,10 @@ void avdt_scb_hdl_security_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* call application callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - AVDT_SECURITY_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.security_cmd); +void avdt_scb_hdl_security_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* call application callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_SECURITY_CFM_EVT, + (tAVDT_CTRL*)&p_data->msg.security_cmd); } /******************************************************************************* @@ -544,42 +500,34 @@ void avdt_scb_hdl_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - tAVDT_CFG *p_cfg; - - if (!p_scb->in_use) - { - p_cfg = p_data->msg.config_cmd.p_cfg; - if (A2DP_GetCodecType(p_scb->cs.cfg.codec_info) == - A2DP_GetCodecType(p_cfg->codec_info)) - { - /* set sep as in use */ - p_scb->in_use = true; - - /* copy info to scb */ - p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx); - p_scb->peer_seid = p_data->msg.config_cmd.int_seid; - memcpy(&p_scb->req_cfg, p_cfg, sizeof(tAVDT_CFG)); - /* call app callback */ - /* handle of scb- which is same as sep handle of bta_av_cb.p_scb*/ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_CONFIG_IND_EVT, - (tAVDT_CTRL *) &p_data->msg.config_cmd); - } - else - { - p_data->msg.hdr.err_code = AVDT_ERR_UNSUP_CFG; - p_data->msg.hdr.err_param = 0; - avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), - p_data->msg.hdr.sig_id, &p_data->msg); - } - } - else - { - avdt_scb_rej_in_use(p_scb, p_data); +void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + tAVDT_CFG* p_cfg; + + if (!p_scb->in_use) { + p_cfg = p_data->msg.config_cmd.p_cfg; + if (A2DP_GetCodecType(p_scb->cs.cfg.codec_info) == + A2DP_GetCodecType(p_cfg->codec_info)) { + /* set sep as in use */ + p_scb->in_use = true; + + /* copy info to scb */ + p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx); + p_scb->peer_seid = p_data->msg.config_cmd.int_seid; + memcpy(&p_scb->req_cfg, p_cfg, sizeof(tAVDT_CFG)); + /* call app callback */ + /* handle of scb- which is same as sep handle of bta_av_cb.p_scb*/ + (*p_scb->cs.p_ctrl_cback)( + avdt_scb_to_hdl(p_scb), p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_CONFIG_IND_EVT, (tAVDT_CTRL*)&p_data->msg.config_cmd); + } else { + p_data->msg.hdr.err_code = AVDT_ERR_UNSUP_CFG; + p_data->msg.hdr.err_param = 0; + avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), + p_data->msg.hdr.sig_id, &p_data->msg); } + } else { + avdt_scb_rej_in_use(p_scb, p_data); + } } /******************************************************************************* @@ -593,19 +541,17 @@ void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* clear scb variables */ - avdt_scb_clr_vars(p_scb, p_data); +void avdt_scb_hdl_setconfig_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* clear scb variables */ + avdt_scb_clr_vars(p_scb, p_data); - /* tell ccb we're done with signaling channel */ - avdt_ccb_event(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), AVDT_CCB_UL_CLOSE_EVT, NULL); + /* tell ccb we're done with signaling channel */ + avdt_ccb_event(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), + AVDT_CCB_UL_CLOSE_EVT, NULL); - /* call application callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - AVDT_OPEN_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.hdr); + /* call application callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_OPEN_CFM_EVT, + (tAVDT_CTRL*)&p_data->msg.hdr); } /******************************************************************************* @@ -618,20 +564,18 @@ void avdt_scb_hdl_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_EVT_HDR single; - - if (p_scb->p_ccb != NULL) - { - /* save configuration */ - memcpy(&p_scb->curr_cfg, &p_scb->req_cfg, sizeof(tAVDT_CFG)); - - /* initiate open */ - single.seid = p_scb->peer_seid; - avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_REQ_EVT, (tAVDT_SCB_EVT *) &single); - } +void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_EVT_HDR single; + + if (p_scb->p_ccb != NULL) { + /* save configuration */ + memcpy(&p_scb->curr_cfg, &p_scb->req_cfg, sizeof(tAVDT_CFG)); + + /* initiate open */ + single.seid = p_scb->peer_seid; + avdt_scb_event(p_scb, AVDT_SCB_API_OPEN_REQ_EVT, (tAVDT_SCB_EVT*)&single); + } } /******************************************************************************* @@ -644,13 +588,11 @@ void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_start_cmd(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_START_IND_EVT, - NULL); +void avdt_scb_hdl_start_cmd(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), + p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_START_IND_EVT, NULL); } /******************************************************************************* @@ -663,12 +605,10 @@ void avdt_scb_hdl_start_cmd(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_start_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_START_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.hdr); +void avdt_scb_hdl_start_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), + p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_START_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr); } /******************************************************************************* @@ -681,13 +621,11 @@ void avdt_scb_hdl_start_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_suspend_cmd(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_SUSPEND_IND_EVT, - NULL); +void avdt_scb_hdl_suspend_cmd(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), + p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_SUSPEND_IND_EVT, NULL); } /******************************************************************************* @@ -700,12 +638,10 @@ void avdt_scb_hdl_suspend_cmd(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_suspend_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_SUSPEND_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.hdr); +void avdt_scb_hdl_suspend_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)( + avdt_scb_to_hdl(p_scb), p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_SUSPEND_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr); } /******************************************************************************* @@ -724,46 +660,43 @@ void avdt_scb_hdl_suspend_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - uint8_t hdl = avdt_scb_to_hdl(p_scb); - tAVDT_CTRL_CBACK *p_ctrl_cback = p_scb->cs.p_ctrl_cback; - tAVDT_CTRL avdt_ctrl; - uint8_t event; - tAVDT_CCB *p_ccb = p_scb->p_ccb; - BD_ADDR remote_addr; +void avdt_scb_hdl_tc_close(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + uint8_t hdl = avdt_scb_to_hdl(p_scb); + tAVDT_CTRL_CBACK* p_ctrl_cback = p_scb->cs.p_ctrl_cback; + tAVDT_CTRL avdt_ctrl; + uint8_t event; + tAVDT_CCB* p_ccb = p_scb->p_ccb; + BD_ADDR remote_addr; + memcpy(remote_addr, p_ccb->peer_addr, BD_ADDR_LEN); - memcpy (remote_addr, p_ccb->peer_addr, BD_ADDR_LEN); + /* set up hdr */ + avdt_ctrl.hdr.err_code = p_scb->close_code; - /* set up hdr */ - avdt_ctrl.hdr.err_code = p_scb->close_code; + /* clear sep variables */ + avdt_scb_clr_vars(p_scb, p_data); + p_scb->media_seq = 0; + p_scb->cong = false; - /* clear sep variables */ - avdt_scb_clr_vars(p_scb, p_data); - p_scb->media_seq = 0; - p_scb->cong = false; - - /* free pkt we're holding, if any */ - osi_free_and_reset((void **)&p_scb->p_pkt); + /* free pkt we're holding, if any */ + osi_free_and_reset((void**)&p_scb->p_pkt); - alarm_cancel(p_scb->transport_channel_timer); - - if ((p_scb->role == AVDT_CLOSE_INT) || (p_scb->role == AVDT_OPEN_INT)) - { - /* tell ccb we're done with signaling channel */ - avdt_ccb_event(p_ccb, AVDT_CCB_UL_CLOSE_EVT, NULL); - } - event = (p_scb->role == AVDT_CLOSE_INT) ? AVDT_CLOSE_CFM_EVT : AVDT_CLOSE_IND_EVT; - p_scb->role = AVDT_CLOSE_ACP; + alarm_cancel(p_scb->transport_channel_timer); - if (p_scb->remove) - { - avdt_scb_dealloc(p_scb, NULL); - } - - /* call app callback */ - (*p_ctrl_cback)(hdl, remote_addr, event, &avdt_ctrl); + if ((p_scb->role == AVDT_CLOSE_INT) || (p_scb->role == AVDT_OPEN_INT)) { + /* tell ccb we're done with signaling channel */ + avdt_ccb_event(p_ccb, AVDT_CCB_UL_CLOSE_EVT, NULL); + } + event = + (p_scb->role == AVDT_CLOSE_INT) ? AVDT_CLOSE_CFM_EVT : AVDT_CLOSE_IND_EVT; + p_scb->role = AVDT_CLOSE_ACP; + + if (p_scb->remove) { + avdt_scb_dealloc(p_scb, NULL); + } + + /* call app callback */ + (*p_ctrl_cback)(hdl, remote_addr, event, &avdt_ctrl); } /******************************************************************************* @@ -776,9 +709,9 @@ void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_delay_rpt_req (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_DELAY_RPT, (tAVDT_MSG *) &p_data->apidelay); +void avdt_scb_snd_delay_rpt_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_DELAY_RPT, + (tAVDT_MSG*)&p_data->apidelay); } /******************************************************************************* @@ -791,17 +724,15 @@ void avdt_scb_snd_delay_rpt_req (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_delay_rpt_cmd (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_DELAY_REPORT_EVT, - (tAVDT_CTRL *) &p_data->msg.hdr); - - if (p_scb->p_ccb) - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_DELAY_RPT, &p_data->msg); - else - avdt_scb_rej_not_in_use(p_scb, p_data); +void avdt_scb_hdl_delay_rpt_cmd(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)( + avdt_scb_to_hdl(p_scb), p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_DELAY_REPORT_EVT, (tAVDT_CTRL*)&p_data->msg.hdr); + + if (p_scb->p_ccb) + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_DELAY_RPT, &p_data->msg); + else + avdt_scb_rej_not_in_use(p_scb, p_data); } /******************************************************************************* @@ -814,12 +745,10 @@ void avdt_scb_hdl_delay_rpt_cmd (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_delay_rpt_rsp (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_DELAY_REPORT_CFM_EVT, - (tAVDT_CTRL *) &p_data->msg.hdr); +void avdt_scb_hdl_delay_rpt_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + (*p_scb->cs.p_ctrl_cback)( + avdt_scb_to_hdl(p_scb), p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_DELAY_REPORT_CFM_EVT, (tAVDT_CTRL*)&p_data->msg.hdr); } #if (AVDT_REPORTING == TRUE) @@ -833,30 +762,25 @@ void avdt_scb_hdl_delay_rpt_rsp (tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_tc_close_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; - /* AVDT_CHAN_SIG does not visit this action */ - if(p_data && p_data->close.type != AVDT_CHAN_MEDIA) - { - /* it's reporting or recovery channel, - * the channel close in open state means the peer does not support it */ - if(p_data->close.old_tc_state == AVDT_AD_ST_OPEN) - { - avdt_ctrl.hdr.err_code = 0; - avdt_ctrl.hdr.err_param = 0; - /* call app callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - AVDT_REPORT_DISCONN_EVT, &avdt_ctrl); - } - } - else - { - /* must be in OPEN state. need to go back to idle */ - avdt_scb_event(p_scb, AVDT_SCB_MSG_ABORT_RSP_EVT, NULL); - avdt_scb_hdl_tc_close(p_scb, p_data); +void avdt_scb_hdl_tc_close_sto(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; + /* AVDT_CHAN_SIG does not visit this action */ + if (p_data && p_data->close.type != AVDT_CHAN_MEDIA) { + /* it's reporting or recovery channel, + * the channel close in open state means the peer does not support it */ + if (p_data->close.old_tc_state == AVDT_AD_ST_OPEN) { + avdt_ctrl.hdr.err_code = 0; + avdt_ctrl.hdr.err_param = 0; + /* call app callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), + p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + AVDT_REPORT_DISCONN_EVT, &avdt_ctrl); } + } else { + /* must be in OPEN state. need to go back to idle */ + avdt_scb_event(p_scb, AVDT_SCB_MSG_ABORT_RSP_EVT, NULL); + avdt_scb_hdl_tc_close(p_scb, p_data); + } } #endif @@ -872,34 +796,33 @@ void avdt_scb_hdl_tc_close_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_tc_open(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - uint8_t event; +void avdt_scb_hdl_tc_open(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + uint8_t event; #if (AVDT_REPORTING == TRUE) - uint8_t role; + uint8_t role; #endif - alarm_cancel(p_scb->transport_channel_timer); + alarm_cancel(p_scb->transport_channel_timer); - event = (p_scb->role == AVDT_OPEN_INT) ? AVDT_OPEN_CFM_EVT : AVDT_OPEN_IND_EVT; - p_data->open.hdr.err_code = 0; + event = + (p_scb->role == AVDT_OPEN_INT) ? AVDT_OPEN_CFM_EVT : AVDT_OPEN_IND_EVT; + p_data->open.hdr.err_code = 0; - AVDT_TRACE_DEBUG("psc_mask: cfg: 0x%x, req:0x%x, cur: 0x%x", - p_scb->cs.cfg.psc_mask, p_scb->req_cfg.psc_mask, p_scb->curr_cfg.psc_mask); + AVDT_TRACE_DEBUG("psc_mask: cfg: 0x%x, req:0x%x, cur: 0x%x", + p_scb->cs.cfg.psc_mask, p_scb->req_cfg.psc_mask, + p_scb->curr_cfg.psc_mask); #if (AVDT_REPORTING == TRUE) - if(p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT) - { - /* open the reporting channel, if both devices support it */ - role = (p_scb->role == AVDT_OPEN_INT) ? AVDT_INT : AVDT_ACP; - avdt_ad_open_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, role); - } + if (p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT) { + /* open the reporting channel, if both devices support it */ + role = (p_scb->role == AVDT_OPEN_INT) ? AVDT_INT : AVDT_ACP; + avdt_ad_open_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, role); + } #endif - /* call app callback */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, - event, - (tAVDT_CTRL *) &p_data->open); + /* call app callback */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), + p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, + event, (tAVDT_CTRL*)&p_data->open); } #if (AVDT_REPORTING == TRUE) @@ -915,20 +838,18 @@ void avdt_scb_hdl_tc_open(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_tc_open_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; - /* open reporting channel here, when it is implemented */ - - /* call app callback */ - if(p_data->open.hdr.err_code == AVDT_CHAN_REPORT) - { - avdt_ctrl.hdr.err_code = 0; - avdt_ctrl.hdr.err_param = 1; - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), +void avdt_scb_hdl_tc_open_sto(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; + /* open reporting channel here, when it is implemented */ + + /* call app callback */ + if (p_data->open.hdr.err_code == AVDT_CHAN_REPORT) { + avdt_ctrl.hdr.err_code = 0; + avdt_ctrl.hdr.err_param = 1; + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL, AVDT_REPORT_CONN_EVT, &avdt_ctrl); - } + } } #endif @@ -943,44 +864,43 @@ void avdt_scb_hdl_tc_open_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_hdl_write_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - uint8_t *p; - uint32_t ssrc; - bool add_rtp_header = !(p_data->apiwrite.opt & AVDT_DATA_OPT_NO_RTP); - - /* free packet we're holding, if any; to be replaced with new */ - if (p_scb->p_pkt != NULL) { - /* this shouldn't be happening */ - AVDT_TRACE_WARNING("Dropped media packet; congested"); - } - osi_free_and_reset((void **)&p_scb->p_pkt); - - /* Recompute only if the RTP header wasn't disabled by the API */ - if (add_rtp_header) { - bool is_content_protection = (p_scb->curr_cfg.num_protect > 0); - add_rtp_header = A2DP_UsesRtpHeader(is_content_protection, - p_scb->curr_cfg.codec_info); - } - - /* Build a media packet, and add an RTP header if required. */ - if (add_rtp_header) { - ssrc = avdt_scb_gen_ssrc(p_scb); - - p_data->apiwrite.p_buf->len += AVDT_MEDIA_HDR_SIZE; - p_data->apiwrite.p_buf->offset -= AVDT_MEDIA_HDR_SIZE; - p_scb->media_seq++; - p = (uint8_t *)(p_data->apiwrite.p_buf + 1) + p_data->apiwrite.p_buf->offset; - - UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1); - UINT8_TO_BE_STREAM(p, p_data->apiwrite.m_pt); - UINT16_TO_BE_STREAM(p, p_scb->media_seq); - UINT32_TO_BE_STREAM(p, p_data->apiwrite.time_stamp); - UINT32_TO_BE_STREAM(p, ssrc); - } - - /* store it */ - p_scb->p_pkt = p_data->apiwrite.p_buf; +void avdt_scb_hdl_write_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + uint8_t* p; + uint32_t ssrc; + bool add_rtp_header = !(p_data->apiwrite.opt & AVDT_DATA_OPT_NO_RTP); + + /* free packet we're holding, if any; to be replaced with new */ + if (p_scb->p_pkt != NULL) { + /* this shouldn't be happening */ + AVDT_TRACE_WARNING("Dropped media packet; congested"); + } + osi_free_and_reset((void**)&p_scb->p_pkt); + + /* Recompute only if the RTP header wasn't disabled by the API */ + if (add_rtp_header) { + bool is_content_protection = (p_scb->curr_cfg.num_protect > 0); + add_rtp_header = + A2DP_UsesRtpHeader(is_content_protection, p_scb->curr_cfg.codec_info); + } + + /* Build a media packet, and add an RTP header if required. */ + if (add_rtp_header) { + ssrc = avdt_scb_gen_ssrc(p_scb); + + p_data->apiwrite.p_buf->len += AVDT_MEDIA_HDR_SIZE; + p_data->apiwrite.p_buf->offset -= AVDT_MEDIA_HDR_SIZE; + p_scb->media_seq++; + p = (uint8_t*)(p_data->apiwrite.p_buf + 1) + p_data->apiwrite.p_buf->offset; + + UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1); + UINT8_TO_BE_STREAM(p, p_data->apiwrite.m_pt); + UINT16_TO_BE_STREAM(p, p_scb->media_seq); + UINT32_TO_BE_STREAM(p, p_data->apiwrite.time_stamp); + UINT32_TO_BE_STREAM(p, ssrc); + } + + /* store it */ + p_scb->p_pkt = p_data->apiwrite.p_buf; } /******************************************************************************* @@ -992,19 +912,17 @@ void avdt_scb_hdl_write_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_abort_req(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_EVT_HDR hdr; +void avdt_scb_snd_abort_req(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_EVT_HDR hdr; - if (p_scb->p_ccb != NULL) - { - p_scb->role = AVDT_CLOSE_INT; + if (p_scb->p_ccb != NULL) { + p_scb->role = AVDT_CLOSE_INT; - hdr.seid = p_scb->peer_seid; + hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_ABORT, (tAVDT_MSG *) &hdr); - } + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_ABORT, (tAVDT_MSG*)&hdr); + } } /******************************************************************************* @@ -1016,10 +934,10 @@ void avdt_scb_snd_abort_req(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_abort_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - avdt_msg_send_rsp(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), AVDT_SIG_ABORT, - &p_data->msg); +void avdt_scb_snd_abort_rsp(UNUSED_ATTR tAVDT_SCB* p_scb, + tAVDT_SCB_EVT* p_data) { + avdt_msg_send_rsp(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), AVDT_SIG_ABORT, + &p_data->msg); } /******************************************************************************* @@ -1031,16 +949,15 @@ void avdt_scb_snd_abort_rsp(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_EVT_HDR hdr; +void avdt_scb_snd_close_req(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_EVT_HDR hdr; - p_scb->role = AVDT_CLOSE_INT; + p_scb->role = AVDT_CLOSE_INT; - hdr.seid = p_scb->peer_seid; + hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_CLOSE, (tAVDT_MSG *) &hdr); + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_CLOSE, (tAVDT_MSG*)&hdr); } /******************************************************************************* @@ -1052,10 +969,9 @@ void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - osi_free_and_reset((void **)&p_scb->p_pkt); - avdt_scb_snd_close_req(p_scb, p_data); +void avdt_scb_snd_stream_close(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + osi_free_and_reset((void**)&p_scb->p_pkt); + avdt_scb_snd_close_req(p_scb, p_data); } /******************************************************************************* @@ -1067,9 +983,8 @@ void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_CLOSE, &p_data->msg); +void avdt_scb_snd_close_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_CLOSE, &p_data->msg); } /******************************************************************************* @@ -1081,14 +996,13 @@ void avdt_scb_snd_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_getconfig_req(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_EVT_HDR hdr; +void avdt_scb_snd_getconfig_req(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_EVT_HDR hdr; - hdr.seid = p_scb->peer_seid; + hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_GETCONFIG, (tAVDT_MSG *) &hdr); + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_GETCONFIG, (tAVDT_MSG*)&hdr); } /******************************************************************************* @@ -1100,9 +1014,8 @@ void avdt_scb_snd_getconfig_req(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_GETCONFIG, &p_data->msg); +void avdt_scb_snd_getconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_GETCONFIG, &p_data->msg); } /******************************************************************************* @@ -1114,14 +1027,13 @@ void avdt_scb_snd_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_open_req(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_EVT_HDR hdr; +void avdt_scb_snd_open_req(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_EVT_HDR hdr; - hdr.seid = p_scb->peer_seid; + hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_OPEN, (tAVDT_MSG *) &hdr); + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_OPEN, (tAVDT_MSG*)&hdr); } /******************************************************************************* @@ -1135,19 +1047,17 @@ void avdt_scb_snd_open_req(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - /* notify adaption that we're waiting for transport channel open */ - p_scb->role = AVDT_OPEN_ACP; - avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_ACP); +void avdt_scb_snd_open_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + /* notify adaption that we're waiting for transport channel open */ + p_scb->role = AVDT_OPEN_ACP; + avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_ACP); - /* send response */ - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_OPEN, &p_data->msg); + /* send response */ + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_OPEN, &p_data->msg); - alarm_set_on_queue(p_scb->transport_channel_timer, - AVDT_SCB_TC_CONN_TIMEOUT_MS, - avdt_scb_transport_channel_timer_timeout, p_scb, - btu_general_alarm_queue); + alarm_set_on_queue( + p_scb->transport_channel_timer, AVDT_SCB_TC_CONN_TIMEOUT_MS, + avdt_scb_transport_channel_timer_timeout, p_scb, btu_general_alarm_queue); } /******************************************************************************* @@ -1160,11 +1070,10 @@ void avdt_scb_snd_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_reconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - memcpy(&p_scb->req_cfg, p_data->msg.config_cmd.p_cfg, sizeof(tAVDT_CFG)); - p_data->msg.hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_RECONFIG, &p_data->msg); +void avdt_scb_snd_reconfig_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + memcpy(&p_scb->req_cfg, p_data->msg.config_cmd.p_cfg, sizeof(tAVDT_CFG)); + p_data->msg.hdr.seid = p_scb->peer_seid; + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_RECONFIG, &p_data->msg); } /******************************************************************************* @@ -1177,30 +1086,26 @@ void avdt_scb_snd_reconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - if (p_data->msg.hdr.err_code == 0) - { - /* store new configuration */ - if (p_scb->req_cfg.num_codec > 0) - { - p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec; - memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info, AVDT_CODEC_SIZE); - } - if (p_scb->req_cfg.num_protect > 0) - { - p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect; - memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info, AVDT_PROTECT_SIZE); - } - - /* send response */ - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg); +void avdt_scb_snd_reconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + if (p_data->msg.hdr.err_code == 0) { + /* store new configuration */ + if (p_scb->req_cfg.num_codec > 0) { + p_scb->curr_cfg.num_codec = p_scb->req_cfg.num_codec; + memcpy(p_scb->curr_cfg.codec_info, p_scb->req_cfg.codec_info, + AVDT_CODEC_SIZE); } - else - { - /* send reject */ - avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg); + if (p_scb->req_cfg.num_protect > 0) { + p_scb->curr_cfg.num_protect = p_scb->req_cfg.num_protect; + memcpy(p_scb->curr_cfg.protect_info, p_scb->req_cfg.protect_info, + AVDT_PROTECT_SIZE); } + + /* send response */ + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg); + } else { + /* send reject */ + avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_RECONFIG, &p_data->msg); + } } /******************************************************************************* @@ -1212,10 +1117,9 @@ void avdt_scb_snd_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_security_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_data->msg.hdr.seid = p_scb->peer_seid; - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SECURITY, &p_data->msg); +void avdt_scb_snd_security_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_data->msg.hdr.seid = p_scb->peer_seid; + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SECURITY, &p_data->msg); } /******************************************************************************* @@ -1227,16 +1131,12 @@ void avdt_scb_snd_security_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - if (p_data->msg.hdr.err_code == 0) - { - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg); - } - else - { - avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg); - } +void avdt_scb_snd_security_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + if (p_data->msg.hdr.err_code == 0) { + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg); + } else { + avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SECURITY, &p_data->msg); + } } /******************************************************************************* @@ -1249,15 +1149,13 @@ void avdt_scb_snd_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - if (p_scb->p_ccb != NULL) - { - avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg); - - /* clear scb variables */ - avdt_scb_clr_vars(p_scb, p_data); - } +void avdt_scb_snd_setconfig_rej(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + if (p_scb->p_ccb != NULL) { + avdt_msg_send_rej(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg); + + /* clear scb variables */ + avdt_scb_clr_vars(p_scb, p_data); + } } /******************************************************************************* @@ -1272,22 +1170,21 @@ void avdt_scb_snd_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_setconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - tAVDT_CFG *p_req, *p_cfg; - - /* copy API parameters to scb, set scb as in use */ - p_scb->in_use = true; - p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx); - p_scb->peer_seid = p_data->msg.config_cmd.hdr.seid; - p_req = p_data->msg.config_cmd.p_cfg; - p_cfg = &p_scb->cs.cfg; - memcpy(&p_scb->req_cfg, p_data->msg.config_cmd.p_cfg, sizeof(tAVDT_CFG)); - - avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SETCONFIG, &p_data->msg); - - /* tell ccb to open channel */ - avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_UL_OPEN_EVT, NULL); +void avdt_scb_snd_setconfig_req(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + tAVDT_CFG *p_req, *p_cfg; + + /* copy API parameters to scb, set scb as in use */ + p_scb->in_use = true; + p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx); + p_scb->peer_seid = p_data->msg.config_cmd.hdr.seid; + p_req = p_data->msg.config_cmd.p_cfg; + p_cfg = &p_scb->cs.cfg; + memcpy(&p_scb->req_cfg, p_data->msg.config_cmd.p_cfg, sizeof(tAVDT_CFG)); + + avdt_msg_send_cmd(p_scb->p_ccb, p_scb, AVDT_SIG_SETCONFIG, &p_data->msg); + + /* tell ccb to open channel */ + avdt_ccb_event(p_scb->p_ccb, AVDT_CCB_UL_OPEN_EVT, NULL); } /******************************************************************************* @@ -1301,14 +1198,12 @@ void avdt_scb_snd_setconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - if (p_scb->p_ccb != NULL) - { - memcpy(&p_scb->curr_cfg, &p_scb->req_cfg, sizeof(tAVDT_CFG)); +void avdt_scb_snd_setconfig_rsp(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + if (p_scb->p_ccb != NULL) { + memcpy(&p_scb->curr_cfg, &p_scb->req_cfg, sizeof(tAVDT_CFG)); - avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg); - } + avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_SETCONFIG, &p_data->msg); + } } /******************************************************************************* @@ -1321,14 +1216,13 @@ void avdt_scb_snd_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_snd_tc_close(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ +void avdt_scb_snd_tc_close(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { #if (AVDT_REPORTING == TRUE) - if(p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT) - avdt_ad_close_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb); + if (p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT) + avdt_ad_close_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb); #endif - avdt_ad_close_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb); + avdt_ad_close_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb); } /******************************************************************************* @@ -1341,20 +1235,16 @@ void avdt_scb_snd_tc_close(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_cb_err(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; +void avdt_scb_cb_err(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; - /* set error code and parameter */ - avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; - avdt_ctrl.hdr.err_param = 0; + /* set error code and parameter */ + avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; + avdt_ctrl.hdr.err_param = 0; - /* call callback, using lookup table to get callback event */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), - NULL, - avdt_scb_cback_evt[p_scb->curr_evt], - &avdt_ctrl); + /* call callback, using lookup table to get callback event */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, + avdt_scb_cback_evt[p_scb->curr_evt], &avdt_ctrl); } /******************************************************************************* @@ -1367,9 +1257,8 @@ void avdt_scb_cb_err(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_cong_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_scb->cong = p_data->llcong; +void avdt_scb_cong_state(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_scb->cong = p_data->llcong; } /******************************************************************************* @@ -1382,12 +1271,11 @@ void avdt_scb_cong_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_rej_state(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_data->msg.hdr.err_code = AVDT_ERR_BAD_STATE; - p_data->msg.hdr.err_param = 0; - avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), - p_data->msg.hdr.sig_id, &p_data->msg); +void avdt_scb_rej_state(UNUSED_ATTR tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_data->msg.hdr.err_code = AVDT_ERR_BAD_STATE; + p_data->msg.hdr.err_param = 0; + avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), + p_data->msg.hdr.sig_id, &p_data->msg); } /******************************************************************************* @@ -1400,12 +1288,11 @@ void avdt_scb_rej_state(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_rej_in_use(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_data->msg.hdr.err_code = AVDT_ERR_IN_USE; - p_data->msg.hdr.err_param = 0; - avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), - p_data->msg.hdr.sig_id, &p_data->msg); +void avdt_scb_rej_in_use(UNUSED_ATTR tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + p_data->msg.hdr.err_code = AVDT_ERR_IN_USE; + p_data->msg.hdr.err_param = 0; + avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), + p_data->msg.hdr.sig_id, &p_data->msg); } /******************************************************************************* @@ -1418,12 +1305,12 @@ void avdt_scb_rej_in_use(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_rej_not_in_use(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - p_data->msg.hdr.err_code = AVDT_ERR_NOT_IN_USE; - p_data->msg.hdr.err_param = 0; - avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), - p_data->msg.hdr.sig_id, &p_data->msg); +void avdt_scb_rej_not_in_use(UNUSED_ATTR tAVDT_SCB* p_scb, + tAVDT_SCB_EVT* p_data) { + p_data->msg.hdr.err_code = AVDT_ERR_NOT_IN_USE; + p_data->msg.hdr.err_param = 0; + avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), + p_data->msg.hdr.sig_id, &p_data->msg); } /******************************************************************************* @@ -1435,10 +1322,8 @@ void avdt_scb_rej_not_in_use(UNUSED_ATTR tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data * Returns Nothing. * ******************************************************************************/ -void avdt_scb_set_remove(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - p_scb->remove = true; +void avdt_scb_set_remove(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + p_scb->remove = true; } /******************************************************************************* @@ -1450,21 +1335,20 @@ void avdt_scb_set_remove(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; +void avdt_scb_free_pkt(tAVDT_SCB* p_scb, tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; - /* set error code and parameter */ - avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; - avdt_ctrl.hdr.err_param = 0; + /* set error code and parameter */ + avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; + avdt_ctrl.hdr.err_param = 0; - osi_free_and_reset((void **)&p_data->apiwrite.p_buf); + osi_free_and_reset((void**)&p_data->apiwrite.p_buf); - AVDT_TRACE_WARNING("Dropped media packet"); + AVDT_TRACE_WARNING("Dropped media packet"); - /* we need to call callback to keep data flow going */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, - &avdt_ctrl); + /* we need to call callback to keep data flow going */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, + &avdt_ctrl); } /******************************************************************************* @@ -1476,41 +1360,36 @@ void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data) * Returns Nothing. * ******************************************************************************/ -void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; - tAVDT_CCB *p_ccb; - uint8_t tcid; - uint16_t lcid; - - /* set error code and parameter */ - avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; - avdt_ctrl.hdr.err_param = 0; - /* flush the media data queued at L2CAP */ - p_ccb = p_scb->p_ccb; - if(p_ccb != NULL) - { - /* get tcid from type, scb */ - tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb); - - lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; - L2CA_FlushChannel (lcid, L2CAP_FLUSH_CHANS_ALL); - } - - if (p_scb->p_pkt != NULL) - { - osi_free_and_reset((void **)&p_scb->p_pkt); +void avdt_scb_clr_pkt(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; + tAVDT_CCB* p_ccb; + uint8_t tcid; + uint16_t lcid; + + /* set error code and parameter */ + avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE; + avdt_ctrl.hdr.err_param = 0; + /* flush the media data queued at L2CAP */ + p_ccb = p_scb->p_ccb; + if (p_ccb != NULL) { + /* get tcid from type, scb */ + tcid = avdt_ad_type_to_tcid(AVDT_CHAN_MEDIA, p_scb); + + lcid = avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid; + L2CA_FlushChannel(lcid, L2CAP_FLUSH_CHANS_ALL); + } + + if (p_scb->p_pkt != NULL) { + osi_free_and_reset((void**)&p_scb->p_pkt); + + AVDT_TRACE_DEBUG("Dropped stored media packet"); - AVDT_TRACE_DEBUG("Dropped stored media packet"); - - /* we need to call callback to keep data flow going */ - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, - &avdt_ctrl); - } + /* we need to call callback to keep data flow going */ + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, + &avdt_ctrl); + } } - /******************************************************************************* * * Function avdt_scb_chk_snd_pkt @@ -1523,25 +1402,22 @@ void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - tAVDT_CTRL avdt_ctrl; - BT_HDR *p_pkt; +void avdt_scb_chk_snd_pkt(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + tAVDT_CTRL avdt_ctrl; + BT_HDR* p_pkt; - avdt_ctrl.hdr.err_code = 0; + avdt_ctrl.hdr.err_code = 0; - if (!p_scb->cong) - { - if (p_scb->p_pkt != NULL) - { - p_pkt = p_scb->p_pkt; - p_scb->p_pkt = NULL; - avdt_ad_write_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, p_pkt); + if (!p_scb->cong) { + if (p_scb->p_pkt != NULL) { + p_pkt = p_scb->p_pkt; + p_scb->p_pkt = NULL; + avdt_ad_write_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, p_pkt); - (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, AVDT_WRITE_CFM_EVT, &avdt_ctrl); - } + (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), NULL, + AVDT_WRITE_CFM_EVT, &avdt_ctrl); } + } } /******************************************************************************* @@ -1555,13 +1431,11 @@ void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_transport_channel_timer(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - alarm_set_on_queue(p_scb->transport_channel_timer, - AVDT_SCB_TC_DISC_TIMEOUT_MS, - avdt_scb_transport_channel_timer_timeout, p_scb, - btu_general_alarm_queue); +void avdt_scb_transport_channel_timer(tAVDT_SCB* p_scb, + UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + alarm_set_on_queue( + p_scb->transport_channel_timer, AVDT_SCB_TC_DISC_TIMEOUT_MS, + avdt_scb_transport_channel_timer_timeout, p_scb, btu_general_alarm_queue); } /******************************************************************************* @@ -1573,10 +1447,8 @@ void avdt_scb_transport_channel_timer(tAVDT_SCB *p_scb, * Returns Nothing. * ******************************************************************************/ -void avdt_scb_clr_vars(tAVDT_SCB *p_scb, - UNUSED_ATTR tAVDT_SCB_EVT *p_data) -{ - p_scb->in_use = false; - p_scb->p_ccb = NULL; - p_scb->peer_seid = 0; +void avdt_scb_clr_vars(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) { + p_scb->in_use = false; + p_scb->p_ccb = NULL; + p_scb->peer_seid = 0; } diff --git a/stack/avrc/avrc_api.cc b/stack/avrc/avrc_api.cc index d69f1d991..8fbd994ca 100644 --- a/stack/avrc/avrc_api.cc +++ b/stack/avrc/avrc_api.cc @@ -24,33 +24,31 @@ #include #include -#include "bt_common.h" -#include "btu.h" #include "avrc_api.h" #include "avrc_int.h" +#include "bt_common.h" +#include "btu.h" #include "osi/include/fixed_queue.h" #include "osi/include/osi.h" /***************************************************************************** * Global data ****************************************************************************/ -extern fixed_queue_t *btu_general_alarm_queue; - +extern fixed_queue_t* btu_general_alarm_queue; -#define AVRC_MAX_RCV_CTRL_EVT AVCT_BROWSE_UNCONG_IND_EVT +#define AVRC_MAX_RCV_CTRL_EVT AVCT_BROWSE_UNCONG_IND_EVT #ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif -static const uint8_t avrc_ctrl_event_map[] = -{ - AVRC_OPEN_IND_EVT, /* AVCT_CONNECT_CFM_EVT */ - AVRC_OPEN_IND_EVT, /* AVCT_CONNECT_IND_EVT */ - AVRC_CLOSE_IND_EVT, /* AVCT_DISCONNECT_CFM_EVT */ - AVRC_CLOSE_IND_EVT, /* AVCT_DISCONNECT_IND_EVT */ - AVRC_CONG_IND_EVT, /* AVCT_CONG_IND_EVT */ - AVRC_UNCONG_IND_EVT,/* AVCT_UNCONG_IND_EVT */ +static const uint8_t avrc_ctrl_event_map[] = { + AVRC_OPEN_IND_EVT, /* AVCT_CONNECT_CFM_EVT */ + AVRC_OPEN_IND_EVT, /* AVCT_CONNECT_IND_EVT */ + AVRC_CLOSE_IND_EVT, /* AVCT_DISCONNECT_CFM_EVT */ + AVRC_CLOSE_IND_EVT, /* AVCT_DISCONNECT_IND_EVT */ + AVRC_CONG_IND_EVT, /* AVCT_CONG_IND_EVT */ + AVRC_UNCONG_IND_EVT, /* AVCT_UNCONG_IND_EVT */ AVRC_BROWSE_OPEN_IND_EVT, /* AVCT_BROWSE_CONN_CFM_EVT */ AVRC_BROWSE_OPEN_IND_EVT, /* AVCT_BROWSE_CONN_IND_EVT */ AVRC_BROWSE_CLOSE_IND_EVT, /* AVCT_BROWSE_DISCONN_CFM_EVT */ @@ -60,17 +58,18 @@ static const uint8_t avrc_ctrl_event_map[] = }; /* use this unused opcode to indication no need to call the callback function */ -#define AVRC_OP_DROP 0xFE -/* use this unused opcode to indication no need to call the callback function & free buffer */ +#define AVRC_OP_DROP 0xFE +/* use this unused opcode to indication no need to call the callback function & + * free buffer */ #define AVRC_OP_DROP_N_FREE 0xFD -#define AVRC_OP_UNIT_INFO_RSP_LEN 8 -#define AVRC_OP_SUB_UNIT_INFO_RSP_LEN 8 -#define AVRC_OP_REJ_MSG_LEN 11 +#define AVRC_OP_UNIT_INFO_RSP_LEN 8 +#define AVRC_OP_SUB_UNIT_INFO_RSP_LEN 8 +#define AVRC_OP_REJ_MSG_LEN 11 /* Flags definitions for AVRC_MsgReq */ -#define AVRC_MSG_MASK_IS_VENDOR_CMD 0x01 -#define AVRC_MSG_MASK_IS_CONTINUATION_RSP 0x02 +#define AVRC_MSG_MASK_IS_VENDOR_CMD 0x01 +#define AVRC_MSG_MASK_IS_CONTINUATION_RSP 0x02 /****************************************************************************** * @@ -83,26 +82,23 @@ static const uint8_t avrc_ctrl_event_map[] = * *****************************************************************************/ static void avrc_ctrl_cback(uint8_t handle, uint8_t event, uint16_t result, - BD_ADDR peer_addr) -{ - uint8_t avrc_event; - - if (event <= AVRC_MAX_RCV_CTRL_EVT && avrc_cb.ccb[handle].p_ctrl_cback) - { - avrc_event = avrc_ctrl_event_map[event]; - if (event == AVCT_CONNECT_CFM_EVT) - { - if (result != 0) /* failed */ - avrc_event = AVRC_CLOSE_IND_EVT; - } - (*avrc_cb.ccb[handle].p_ctrl_cback)(handle, avrc_event, result, peer_addr); - } - - if ((event == AVCT_DISCONNECT_CFM_EVT) || (event == AVCT_DISCONNECT_IND_EVT)) - { - avrc_flush_cmd_q(handle); - alarm_free(avrc_cb.ccb_int[handle].tle); + BD_ADDR peer_addr) { + uint8_t avrc_event; + + if (event <= AVRC_MAX_RCV_CTRL_EVT && avrc_cb.ccb[handle].p_ctrl_cback) { + avrc_event = avrc_ctrl_event_map[event]; + if (event == AVCT_CONNECT_CFM_EVT) { + if (result != 0) /* failed */ + avrc_event = AVRC_CLOSE_IND_EVT; } + (*avrc_cb.ccb[handle].p_ctrl_cback)(handle, avrc_event, result, peer_addr); + } + + if ((event == AVCT_DISCONNECT_CFM_EVT) || + (event == AVCT_DISCONNECT_IND_EVT)) { + avrc_flush_cmd_q(handle); + alarm_free(avrc_cb.ccb_int[handle].tle); + } } /****************************************************************************** @@ -114,13 +110,12 @@ static void avrc_ctrl_cback(uint8_t handle, uint8_t event, uint16_t result, * Returns Nothing. * *****************************************************************************/ -void avrc_flush_cmd_q(uint8_t handle) -{ - AVRC_TRACE_DEBUG("AVRC: Flushing command queue for handle=0x%02x", handle); - avrc_cb.ccb_int[handle].flags &= ~AVRC_CB_FLAGS_RSP_PENDING; +void avrc_flush_cmd_q(uint8_t handle) { + AVRC_TRACE_DEBUG("AVRC: Flushing command queue for handle=0x%02x", handle); + avrc_cb.ccb_int[handle].flags &= ~AVRC_CB_FLAGS_RSP_PENDING; - alarm_cancel(avrc_cb.ccb_int[handle].tle); - fixed_queue_free(avrc_cb.ccb_int[handle].cmd_q, osi_free); + alarm_cancel(avrc_cb.ccb_int[handle].tle); + fixed_queue_free(avrc_cb.ccb_int[handle].cmd_q, osi_free); } /****************************************************************************** @@ -132,26 +127,23 @@ void avrc_flush_cmd_q(uint8_t handle) * Returns Nothing. * *****************************************************************************/ -void avrc_process_timeout(void *data) -{ - tAVRC_PARAM *param = (tAVRC_PARAM *)data; - - AVRC_TRACE_DEBUG("AVRC: command timeout (handle=0x%02x, label=0x%02x)", param->handle, - param->label); - - /* Notify app */ - if (avrc_cb.ccb[param->handle].p_ctrl_cback) - { - (*avrc_cb.ccb[param->handle].p_ctrl_cback)(param->handle, AVRC_CMD_TIMEOUT_EVT, - param->label, NULL); - } - - /* If vendor command timed-out, then send next command in the queue */ - if (param->msg_mask & AVRC_MSG_MASK_IS_VENDOR_CMD) - { - avrc_send_next_vendor_cmd(param->handle); - } - osi_free(param); +void avrc_process_timeout(void* data) { + tAVRC_PARAM* param = (tAVRC_PARAM*)data; + + AVRC_TRACE_DEBUG("AVRC: command timeout (handle=0x%02x, label=0x%02x)", + param->handle, param->label); + + /* Notify app */ + if (avrc_cb.ccb[param->handle].p_ctrl_cback) { + (*avrc_cb.ccb[param->handle].p_ctrl_cback)( + param->handle, AVRC_CMD_TIMEOUT_EVT, param->label, NULL); + } + + /* If vendor command timed-out, then send next command in the queue */ + if (param->msg_mask & AVRC_MSG_MASK_IS_VENDOR_CMD) { + avrc_send_next_vendor_cmd(param->handle); + } + osi_free(param); } /****************************************************************************** @@ -163,34 +155,33 @@ void avrc_process_timeout(void *data) * Returns Nothing. * *****************************************************************************/ -void avrc_send_next_vendor_cmd(uint8_t handle) -{ - BT_HDR *p_next_cmd; - uint8_t next_label; - - while ((p_next_cmd = (BT_HDR *)fixed_queue_try_dequeue(avrc_cb.ccb_int[handle].cmd_q)) != NULL) - { - p_next_cmd->event &= 0xFF; /* opcode */ - next_label = (p_next_cmd->layer_specific) >> 8; /* extract label */ - p_next_cmd->layer_specific &= 0xFF; /* AVCT_DATA_CTRL or AVCT_DATA_BROWSE */ - - AVRC_TRACE_DEBUG("AVRC: Dequeuing command 0x%08x (handle=0x%02x, label=0x%02x)", - p_next_cmd, handle, next_label); - - /* Send the message */ - if ((AVCT_MsgReq(handle, next_label, AVCT_CMD, p_next_cmd)) == AVCT_SUCCESS) - { - /* Start command timer to wait for response */ - avrc_start_cmd_timer(handle, next_label, AVRC_MSG_MASK_IS_VENDOR_CMD); - return; - } - } +void avrc_send_next_vendor_cmd(uint8_t handle) { + BT_HDR* p_next_cmd; + uint8_t next_label; - if (p_next_cmd == NULL) - { - /* cmd queue empty */ - avrc_cb.ccb_int[handle].flags &= ~AVRC_CB_FLAGS_RSP_PENDING; + while ((p_next_cmd = (BT_HDR*)fixed_queue_try_dequeue( + avrc_cb.ccb_int[handle].cmd_q)) != NULL) { + p_next_cmd->event &= 0xFF; /* opcode */ + next_label = (p_next_cmd->layer_specific) >> 8; /* extract label */ + p_next_cmd->layer_specific &= 0xFF; /* AVCT_DATA_CTRL or AVCT_DATA_BROWSE */ + + AVRC_TRACE_DEBUG( + "AVRC: Dequeuing command 0x%08x (handle=0x%02x, label=0x%02x)", + p_next_cmd, handle, next_label); + + /* Send the message */ + if ((AVCT_MsgReq(handle, next_label, AVCT_CMD, p_next_cmd)) == + AVCT_SUCCESS) { + /* Start command timer to wait for response */ + avrc_start_cmd_timer(handle, next_label, AVRC_MSG_MASK_IS_VENDOR_CMD); + return; } + } + + if (p_next_cmd == NULL) { + /* cmd queue empty */ + avrc_cb.ccb_int[handle].flags &= ~AVRC_CB_FLAGS_RSP_PENDING; + } } /****************************************************************************** @@ -202,19 +193,18 @@ void avrc_send_next_vendor_cmd(uint8_t handle) * Returns Nothing. * *****************************************************************************/ -void avrc_start_cmd_timer(uint8_t handle, uint8_t label, uint8_t msg_mask) -{ - tAVRC_PARAM *param = static_cast(osi_malloc(sizeof(tAVRC_PARAM))); - param->handle = handle; - param->label = label; - param->msg_mask = msg_mask; - - AVRC_TRACE_DEBUG("AVRC: starting timer (handle=0x%02x, label=0x%02x)", handle, label); - - alarm_set_on_queue(avrc_cb.ccb_int[handle].tle, - AVRC_CMD_TOUT_MS, - avrc_process_timeout, param, - btu_general_alarm_queue); +void avrc_start_cmd_timer(uint8_t handle, uint8_t label, uint8_t msg_mask) { + tAVRC_PARAM* param = + static_cast(osi_malloc(sizeof(tAVRC_PARAM))); + param->handle = handle; + param->label = label; + param->msg_mask = msg_mask; + + AVRC_TRACE_DEBUG("AVRC: starting timer (handle=0x%02x, label=0x%02x)", handle, + label); + + alarm_set_on_queue(avrc_cb.ccb_int[handle].tle, AVRC_CMD_TOUT_MS, + avrc_process_timeout, param, btu_general_alarm_queue); } /****************************************************************************** @@ -226,9 +216,8 @@ void avrc_start_cmd_timer(uint8_t handle, uint8_t label, uint8_t msg_mask) * Returns A pointer to the data payload. * *****************************************************************************/ -static uint8_t * avrc_get_data_ptr(BT_HDR *p_pkt) -{ - return (uint8_t *)(p_pkt + 1) + p_pkt->offset; +static uint8_t* avrc_get_data_ptr(BT_HDR* p_pkt) { + return (uint8_t*)(p_pkt + 1) + p_pkt->offset; } /****************************************************************************** @@ -241,20 +230,19 @@ static uint8_t * avrc_get_data_ptr(BT_HDR *p_pkt) * Returns The buffer with the copied data. * *****************************************************************************/ -static BT_HDR * avrc_copy_packet(BT_HDR *p_pkt, int rsp_pkt_len) -{ - const int offset = MAX(AVCT_MSG_OFFSET, p_pkt->offset); - const int pkt_len = MAX(rsp_pkt_len, p_pkt->len); - BT_HDR *p_pkt_copy = (BT_HDR *)osi_malloc(BT_HDR_SIZE + offset + pkt_len); - - /* Copy the packet header, set the new offset, and copy the payload */ - memcpy(p_pkt_copy, p_pkt, BT_HDR_SIZE); - p_pkt_copy->offset = offset; - uint8_t *p_data = avrc_get_data_ptr(p_pkt); - uint8_t *p_data_copy = avrc_get_data_ptr(p_pkt_copy); - memcpy(p_data_copy, p_data, p_pkt->len); - - return p_pkt_copy; +static BT_HDR* avrc_copy_packet(BT_HDR* p_pkt, int rsp_pkt_len) { + const int offset = MAX(AVCT_MSG_OFFSET, p_pkt->offset); + const int pkt_len = MAX(rsp_pkt_len, p_pkt->len); + BT_HDR* p_pkt_copy = (BT_HDR*)osi_malloc(BT_HDR_SIZE + offset + pkt_len); + + /* Copy the packet header, set the new offset, and copy the payload */ + memcpy(p_pkt_copy, p_pkt, BT_HDR_SIZE); + p_pkt_copy->offset = offset; + uint8_t* p_data = avrc_get_data_ptr(p_pkt); + uint8_t* p_data_copy = avrc_get_data_ptr(p_pkt_copy); + memcpy(p_data_copy, p_data, p_pkt->len); + + return p_pkt_copy; } #if (AVRC_METADATA_INCLUDED == TRUE) @@ -267,35 +255,39 @@ static BT_HDR * avrc_copy_packet(BT_HDR *p_pkt, int rsp_pkt_len) * Returns Nothing. * *****************************************************************************/ -static void avrc_prep_end_frag(uint8_t handle) -{ - tAVRC_FRAG_CB *p_fcb; - BT_HDR *p_pkt_new; - uint8_t *p_data, *p_orig_data; - uint8_t rsp_type; - - AVRC_TRACE_DEBUG ("%s", __func__ ); - p_fcb = &avrc_cb.fcb[handle]; - - /* The response type of the end fragment should be the same as the the PDU of "End Fragment - ** Response" Errata: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=4383 - */ - p_orig_data = ((uint8_t *)(p_fcb->p_fmsg + 1) + p_fcb->p_fmsg->offset); - rsp_type = ((*p_orig_data) & AVRC_CTYPE_MASK); - - p_pkt_new = p_fcb->p_fmsg; - p_pkt_new->len -= (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); - p_pkt_new->offset += (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); - p_data = (uint8_t *)(p_pkt_new+1) + p_pkt_new->offset; - *p_data++ = rsp_type; - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_VENDOR; - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - *p_data++ = p_fcb->frag_pdu; - *p_data++ = AVRC_PKT_END; - - /* 4=pdu, pkt_type & len */ - UINT16_TO_BE_STREAM(p_data, (p_pkt_new->len - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE)); +static void avrc_prep_end_frag(uint8_t handle) { + tAVRC_FRAG_CB* p_fcb; + BT_HDR* p_pkt_new; + uint8_t *p_data, *p_orig_data; + uint8_t rsp_type; + + AVRC_TRACE_DEBUG("%s", __func__); + p_fcb = &avrc_cb.fcb[handle]; + + /* The response type of the end fragment should be the same as the the PDU of + *"End Fragment + ** Response" Errata: + *https://www.bluetooth.org/errata/errata_view.cfm?errata_id=4383 + */ + p_orig_data = ((uint8_t*)(p_fcb->p_fmsg + 1) + p_fcb->p_fmsg->offset); + rsp_type = ((*p_orig_data) & AVRC_CTYPE_MASK); + + p_pkt_new = p_fcb->p_fmsg; + p_pkt_new->len -= + (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_pkt_new->offset += + (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_data = (uint8_t*)(p_pkt_new + 1) + p_pkt_new->offset; + *p_data++ = rsp_type; + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + *p_data++ = p_fcb->frag_pdu; + *p_data++ = AVRC_PKT_END; + + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM( + p_data, (p_pkt_new->len - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE)); } /****************************************************************************** @@ -308,44 +300,44 @@ static void avrc_prep_end_frag(uint8_t handle) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -static uint16_t avrc_send_continue_frag(uint8_t handle, uint8_t label) -{ - tAVRC_FRAG_CB *p_fcb; - BT_HDR *p_pkt_old, *p_pkt; - uint8_t *p_old, *p_data; - uint8_t cr = AVCT_RSP; - - p_fcb = &avrc_cb.fcb[handle]; - p_pkt = p_fcb->p_fmsg; - - AVRC_TRACE_DEBUG("%s handle = %u label = %u len = %d", - __func__, handle, label, p_pkt->len); - if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) { - int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset); - p_pkt_old = p_fcb->p_fmsg; - p_pkt = (BT_HDR *)osi_malloc(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE); - p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; - p_pkt->offset = AVCT_MSG_OFFSET; - p_pkt->layer_specific = p_pkt_old->layer_specific; - p_pkt->event = p_pkt_old->event; - p_old = (uint8_t *)(p_pkt_old + 1) + p_pkt_old->offset; - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - memcpy (p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); - /* use AVRC continue packet type */ - p_data += AVRC_VENDOR_HDR_SIZE; - p_data++; /* pdu */ - *p_data++ = AVRC_PKT_CONTINUE; - /* 4=pdu, pkt_type & len */ - UINT16_TO_BE_STREAM(p_data, (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); - - /* prepare the left over for as an end fragment */ - avrc_prep_end_frag (handle); - } else { - /* end fragment. clean the control block */ - p_fcb->frag_enabled = false; - p_fcb->p_fmsg = NULL; - } - return AVCT_MsgReq( handle, label, cr, p_pkt); +static uint16_t avrc_send_continue_frag(uint8_t handle, uint8_t label) { + tAVRC_FRAG_CB* p_fcb; + BT_HDR *p_pkt_old, *p_pkt; + uint8_t *p_old, *p_data; + uint8_t cr = AVCT_RSP; + + p_fcb = &avrc_cb.fcb[handle]; + p_pkt = p_fcb->p_fmsg; + + AVRC_TRACE_DEBUG("%s handle = %u label = %u len = %d", __func__, handle, + label, p_pkt->len); + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) { + int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset); + p_pkt_old = p_fcb->p_fmsg; + p_pkt = (BT_HDR*)osi_malloc(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE); + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = AVCT_MSG_OFFSET; + p_pkt->layer_specific = p_pkt_old->layer_specific; + p_pkt->event = p_pkt_old->event; + p_old = (uint8_t*)(p_pkt_old + 1) + p_pkt_old->offset; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + memcpy(p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC continue packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_CONTINUE; + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM(p_data, + (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); + + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag(handle); + } else { + /* end fragment. clean the control block */ + p_fcb->frag_enabled = false; + p_fcb->p_fmsg = NULL; + } + return AVCT_MsgReq(handle, label, cr, p_pkt); } /****************************************************************************** @@ -357,104 +349,93 @@ static uint16_t avrc_send_continue_frag(uint8_t handle, uint8_t label) * Returns if not NULL, the response to send right away. * *****************************************************************************/ -static BT_HDR * avrc_proc_vendor_command(uint8_t handle, uint8_t label, - BT_HDR *p_pkt, tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_rsp = NULL; - uint8_t *p_data; - uint8_t *p_begin; - uint8_t pkt_type; - bool abort_frag = false; - tAVRC_STS status = AVRC_STS_NO_ERROR; - tAVRC_FRAG_CB *p_fcb; - - p_begin = (uint8_t *)(p_pkt+1) + p_pkt->offset; - p_data = p_begin + AVRC_VENDOR_HDR_SIZE; - pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; - - if (pkt_type != AVRC_PKT_SINGLE) - { - /* reject - commands can only be in single packets at AVRCP level */ - AVRC_TRACE_ERROR ("commands must be in single packet pdu:0x%x", *p_data ); - /* use the current GKI buffer to send the reject */ - status = AVRC_STS_BAD_CMD; - } - /* check if there are fragments waiting to be sent */ - else if (avrc_cb.fcb[handle].frag_enabled) - { - p_fcb = &avrc_cb.fcb[handle]; - if (p_msg->company_id == AVRC_CO_METADATA) - { - switch (*p_data) - { - case AVRC_PDU_ABORT_CONTINUATION_RSP: - /* aborted by CT - send accept response */ - abort_frag = true; - p_begin = (uint8_t *)(p_pkt+1) + p_pkt->offset; - *p_begin = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); - if (*(p_data + 4) != p_fcb->frag_pdu) - { - *p_begin = (AVRC_RSP_REJ & AVRC_CTYPE_MASK); - *(p_data + 4) = AVRC_STS_BAD_PARAM; - } - else - { - p_data = (p_begin + AVRC_VENDOR_HDR_SIZE + 2); - UINT16_TO_BE_STREAM(p_data, 0); - p_pkt->len = (p_data - p_begin); - } - AVCT_MsgReq( handle, label, AVCT_RSP, p_pkt); - p_msg->hdr.opcode = AVRC_OP_DROP; /* used the p_pkt to send response */ - break; - - case AVRC_PDU_REQUEST_CONTINUATION_RSP: - if (*(p_data + 4) == p_fcb->frag_pdu) - { - avrc_send_continue_frag(handle, label); - p_msg->hdr.opcode = AVRC_OP_DROP_N_FREE; - } - else - { - /* the pdu id does not match - reject the command using the current GKI buffer */ - AVRC_TRACE_ERROR("%s continue pdu: 0x%x does not match the current pdu: 0x%x", - __func__, *(p_data + 4), p_fcb->frag_pdu); - status = AVRC_STS_BAD_PARAM; - abort_frag = true; - } - break; - - default: - /* implicit abort */ - abort_frag = true; - } - } - else - { +static BT_HDR* avrc_proc_vendor_command(uint8_t handle, uint8_t label, + BT_HDR* p_pkt, + tAVRC_MSG_VENDOR* p_msg) { + BT_HDR* p_rsp = NULL; + uint8_t* p_data; + uint8_t* p_begin; + uint8_t pkt_type; + bool abort_frag = false; + tAVRC_STS status = AVRC_STS_NO_ERROR; + tAVRC_FRAG_CB* p_fcb; + + p_begin = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_begin + AVRC_VENDOR_HDR_SIZE; + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + + if (pkt_type != AVRC_PKT_SINGLE) { + /* reject - commands can only be in single packets at AVRCP level */ + AVRC_TRACE_ERROR("commands must be in single packet pdu:0x%x", *p_data); + /* use the current GKI buffer to send the reject */ + status = AVRC_STS_BAD_CMD; + } + /* check if there are fragments waiting to be sent */ + else if (avrc_cb.fcb[handle].frag_enabled) { + p_fcb = &avrc_cb.fcb[handle]; + if (p_msg->company_id == AVRC_CO_METADATA) { + switch (*p_data) { + case AVRC_PDU_ABORT_CONTINUATION_RSP: + /* aborted by CT - send accept response */ + abort_frag = true; + p_begin = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + *p_begin = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); + if (*(p_data + 4) != p_fcb->frag_pdu) { + *p_begin = (AVRC_RSP_REJ & AVRC_CTYPE_MASK); + *(p_data + 4) = AVRC_STS_BAD_PARAM; + } else { + p_data = (p_begin + AVRC_VENDOR_HDR_SIZE + 2); + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = (p_data - p_begin); + } + AVCT_MsgReq(handle, label, AVCT_RSP, p_pkt); + p_msg->hdr.opcode = + AVRC_OP_DROP; /* used the p_pkt to send response */ + break; + + case AVRC_PDU_REQUEST_CONTINUATION_RSP: + if (*(p_data + 4) == p_fcb->frag_pdu) { + avrc_send_continue_frag(handle, label); + p_msg->hdr.opcode = AVRC_OP_DROP_N_FREE; + } else { + /* the pdu id does not match - reject the command using the current + * GKI buffer */ + AVRC_TRACE_ERROR( + "%s continue pdu: 0x%x does not match the current pdu: 0x%x", + __func__, *(p_data + 4), p_fcb->frag_pdu); + status = AVRC_STS_BAD_PARAM; abort_frag = true; - /* implicit abort */ - } + } + break; - if (abort_frag) - { - osi_free_and_reset((void **)&p_fcb->p_fmsg); - p_fcb->frag_enabled = false; - } + default: + /* implicit abort */ + abort_frag = true; + } + } else { + abort_frag = true; + /* implicit abort */ } - if (status != AVRC_STS_NO_ERROR) - { - /* use the current GKI buffer to build/send the reject message */ - p_data = (uint8_t *)(p_pkt+1) + p_pkt->offset; - *p_data++ = AVRC_RSP_REJ; - p_data += AVRC_VENDOR_HDR_SIZE; /* pdu */ - *p_data++ = 0; /* pkt_type */ - UINT16_TO_BE_STREAM(p_data, 1); /* len */ - *p_data++ = status; /* error code */ - p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; - p_rsp = p_pkt; + if (abort_frag) { + osi_free_and_reset((void**)&p_fcb->p_fmsg); + p_fcb->frag_enabled = false; } + } + + if (status != AVRC_STS_NO_ERROR) { + /* use the current GKI buffer to build/send the reject message */ + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + *p_data++ = AVRC_RSP_REJ; + p_data += AVRC_VENDOR_HDR_SIZE; /* pdu */ + *p_data++ = 0; /* pkt_type */ + UINT16_TO_BE_STREAM(p_data, 1); /* len */ + *p_data++ = status; /* error code */ + p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; + p_rsp = p_pkt; + } - return p_rsp; + return p_rsp; } /****************************************************************************** @@ -467,175 +448,158 @@ static BT_HDR * avrc_proc_vendor_command(uint8_t handle, uint8_t label, * Returns 0, to report the message with msg_cback . * *****************************************************************************/ -static uint8_t avrc_proc_far_msg(uint8_t handle, uint8_t label, uint8_t cr, BT_HDR **pp_pkt, - tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_pkt = *pp_pkt; - uint8_t *p_data; - uint8_t drop_code = 0; - bool buf_overflow = false; - BT_HDR *p_rsp = NULL; - BT_HDR *p_cmd = NULL; - bool req_continue = false; - BT_HDR *p_pkt_new = NULL; - uint8_t pkt_type; - tAVRC_RASM_CB *p_rcb; - tAVRC_NEXT_CMD avrc_cmd; - tAVRC_STS status; - - p_data = (uint8_t *)(p_pkt+1) + p_pkt->offset; - - /* Skip over vendor header (ctype, subunit*, opcode, CO_ID) */ - p_data += AVRC_VENDOR_HDR_SIZE; - - pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; - AVRC_TRACE_DEBUG ("pkt_type %d", pkt_type ); - p_rcb = &avrc_cb.rcb[handle]; - - /* check if the message needs to be re-assembled */ - if (pkt_type == AVRC_PKT_SINGLE || pkt_type == AVRC_PKT_START) - { - /* previous fragments need to be dropped, when received another new message */ - p_rcb->rasm_offset = 0; - osi_free_and_reset((void **)&p_rcb->p_rmsg); - } - - if (pkt_type != AVRC_PKT_SINGLE && cr == AVCT_RSP) - { - /* not a single response packet - need to re-assemble metadata messages */ - if (pkt_type == AVRC_PKT_START) { - /* Allocate buffer for re-assembly */ - p_rcb->rasm_pdu = *p_data; - p_rcb->p_rmsg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE); - /* Copy START packet to buffer for re-assembling fragments */ - memcpy(p_rcb->p_rmsg, p_pkt, sizeof(BT_HDR)); /* Copy bt hdr */ - - /* Copy metadata message */ - memcpy((uint8_t *)(p_rcb->p_rmsg + 1), - (uint8_t *)(p_pkt+1) + p_pkt->offset, p_pkt->len); - - /* offset of start of metadata response in reassembly buffer */ - p_rcb->p_rmsg->offset = p_rcb->rasm_offset = 0; - - /* - * Free original START packet, replace with pointer to - * reassembly buffer. - */ - osi_free(p_pkt); - *pp_pkt = p_rcb->p_rmsg; - - /* - * Set offset to point to where to copy next - use the same - * reassembly logic as AVCT. - */ - p_rcb->p_rmsg->offset += p_rcb->p_rmsg->len; - req_continue = true; - } else if (p_rcb->p_rmsg == NULL) { - /* Received a CONTINUE/END, but no corresponding START - (or previous fragmented response was dropped) */ - AVRC_TRACE_DEBUG ("Received a CONTINUE/END without no corresponding START \ +static uint8_t avrc_proc_far_msg(uint8_t handle, uint8_t label, uint8_t cr, + BT_HDR** pp_pkt, tAVRC_MSG_VENDOR* p_msg) { + BT_HDR* p_pkt = *pp_pkt; + uint8_t* p_data; + uint8_t drop_code = 0; + bool buf_overflow = false; + BT_HDR* p_rsp = NULL; + BT_HDR* p_cmd = NULL; + bool req_continue = false; + BT_HDR* p_pkt_new = NULL; + uint8_t pkt_type; + tAVRC_RASM_CB* p_rcb; + tAVRC_NEXT_CMD avrc_cmd; + tAVRC_STS status; + + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + + /* Skip over vendor header (ctype, subunit*, opcode, CO_ID) */ + p_data += AVRC_VENDOR_HDR_SIZE; + + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + AVRC_TRACE_DEBUG("pkt_type %d", pkt_type); + p_rcb = &avrc_cb.rcb[handle]; + + /* check if the message needs to be re-assembled */ + if (pkt_type == AVRC_PKT_SINGLE || pkt_type == AVRC_PKT_START) { + /* previous fragments need to be dropped, when received another new message + */ + p_rcb->rasm_offset = 0; + osi_free_and_reset((void**)&p_rcb->p_rmsg); + } + + if (pkt_type != AVRC_PKT_SINGLE && cr == AVCT_RSP) { + /* not a single response packet - need to re-assemble metadata messages */ + if (pkt_type == AVRC_PKT_START) { + /* Allocate buffer for re-assembly */ + p_rcb->rasm_pdu = *p_data; + p_rcb->p_rmsg = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE); + /* Copy START packet to buffer for re-assembling fragments */ + memcpy(p_rcb->p_rmsg, p_pkt, sizeof(BT_HDR)); /* Copy bt hdr */ + + /* Copy metadata message */ + memcpy((uint8_t*)(p_rcb->p_rmsg + 1), + (uint8_t*)(p_pkt + 1) + p_pkt->offset, p_pkt->len); + + /* offset of start of metadata response in reassembly buffer */ + p_rcb->p_rmsg->offset = p_rcb->rasm_offset = 0; + + /* + * Free original START packet, replace with pointer to + * reassembly buffer. + */ + osi_free(p_pkt); + *pp_pkt = p_rcb->p_rmsg; + + /* + * Set offset to point to where to copy next - use the same + * reassembly logic as AVCT. + */ + p_rcb->p_rmsg->offset += p_rcb->p_rmsg->len; + req_continue = true; + } else if (p_rcb->p_rmsg == NULL) { + /* Received a CONTINUE/END, but no corresponding START + (or previous fragmented response was dropped) */ + AVRC_TRACE_DEBUG( + "Received a CONTINUE/END without no corresponding START \ (or previous fragmented response was dropped)"); - drop_code = 5; - osi_free(p_pkt); - *pp_pkt = NULL; - } - else - { - /* get size of buffer holding assembled message */ - /* - * NOTE: The buffer is allocated above at the beginning of the - * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. - */ - uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); - /* adjust offset and len of fragment for header byte */ - p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); - p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); - /* verify length */ - if ((p_rcb->p_rmsg->offset + p_pkt->len) > buf_len) - { - AVRC_TRACE_WARNING("Fragmented message too big! - report the partial message"); - p_pkt->len = buf_len - p_rcb->p_rmsg->offset; - pkt_type = AVRC_PKT_END; - buf_overflow = true; - } - - /* copy contents of p_pkt to p_rx_msg */ - memcpy((uint8_t *)(p_rcb->p_rmsg + 1) + p_rcb->p_rmsg->offset, - (uint8_t *)(p_pkt + 1) + p_pkt->offset, p_pkt->len); - - if (pkt_type == AVRC_PKT_END) - { - p_rcb->p_rmsg->offset = p_rcb->rasm_offset; - p_rcb->p_rmsg->len += p_pkt->len; - p_pkt_new = p_rcb->p_rmsg; - p_rcb->rasm_offset = 0; - p_rcb->p_rmsg = NULL; - p_msg->p_vendor_data = (uint8_t *)(p_pkt_new+1) + p_pkt_new->offset; - p_msg->hdr.ctype = p_msg->p_vendor_data[0] & AVRC_CTYPE_MASK; - /* 6 = ctype, subunit*, opcode & CO_ID */ - p_msg->p_vendor_data += AVRC_VENDOR_HDR_SIZE; - p_msg->vendor_len = p_pkt_new->len - AVRC_VENDOR_HDR_SIZE; - p_data = p_msg->p_vendor_data + 1; /* skip pdu */ - *p_data++ = AVRC_PKT_SINGLE; - UINT16_TO_BE_STREAM(p_data, (p_msg->vendor_len - AVRC_MIN_META_HDR_SIZE)); - AVRC_TRACE_DEBUG("end frag:%d, total len:%d, offset:%d", p_pkt->len, - p_pkt_new->len, p_pkt_new->offset); - } - else - { - p_rcb->p_rmsg->offset += p_pkt->len; - p_rcb->p_rmsg->len += p_pkt->len; - p_pkt_new = NULL; - req_continue = true; - } - osi_free(p_pkt); - *pp_pkt = p_pkt_new; - } + drop_code = 5; + osi_free(p_pkt); + *pp_pkt = NULL; + } else { + /* get size of buffer holding assembled message */ + /* + * NOTE: The buffer is allocated above at the beginning of the + * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE. + */ + uint16_t buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR); + /* adjust offset and len of fragment for header byte */ + p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + /* verify length */ + if ((p_rcb->p_rmsg->offset + p_pkt->len) > buf_len) { + AVRC_TRACE_WARNING( + "Fragmented message too big! - report the partial message"); + p_pkt->len = buf_len - p_rcb->p_rmsg->offset; + pkt_type = AVRC_PKT_END; + buf_overflow = true; + } + + /* copy contents of p_pkt to p_rx_msg */ + memcpy((uint8_t*)(p_rcb->p_rmsg + 1) + p_rcb->p_rmsg->offset, + (uint8_t*)(p_pkt + 1) + p_pkt->offset, p_pkt->len); + + if (pkt_type == AVRC_PKT_END) { + p_rcb->p_rmsg->offset = p_rcb->rasm_offset; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = p_rcb->p_rmsg; + p_rcb->rasm_offset = 0; + p_rcb->p_rmsg = NULL; + p_msg->p_vendor_data = (uint8_t*)(p_pkt_new + 1) + p_pkt_new->offset; + p_msg->hdr.ctype = p_msg->p_vendor_data[0] & AVRC_CTYPE_MASK; + /* 6 = ctype, subunit*, opcode & CO_ID */ + p_msg->p_vendor_data += AVRC_VENDOR_HDR_SIZE; + p_msg->vendor_len = p_pkt_new->len - AVRC_VENDOR_HDR_SIZE; + p_data = p_msg->p_vendor_data + 1; /* skip pdu */ + *p_data++ = AVRC_PKT_SINGLE; + UINT16_TO_BE_STREAM(p_data, + (p_msg->vendor_len - AVRC_MIN_META_HDR_SIZE)); + AVRC_TRACE_DEBUG("end frag:%d, total len:%d, offset:%d", p_pkt->len, + p_pkt_new->len, p_pkt_new->offset); + } else { + p_rcb->p_rmsg->offset += p_pkt->len; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = NULL; + req_continue = true; + } + osi_free(p_pkt); + *pp_pkt = p_pkt_new; } - - if (cr == AVCT_CMD) - { - p_rsp = avrc_proc_vendor_command(handle, label, *pp_pkt, p_msg); - if (p_rsp) - { - AVCT_MsgReq( handle, label, AVCT_RSP, p_rsp); - drop_code = 3; - } - else if (p_msg->hdr.opcode == AVRC_OP_DROP) - { - drop_code = 1; - } - else if (p_msg->hdr.opcode == AVRC_OP_DROP_N_FREE) - drop_code = 4; - + } + + if (cr == AVCT_CMD) { + p_rsp = avrc_proc_vendor_command(handle, label, *pp_pkt, p_msg); + if (p_rsp) { + AVCT_MsgReq(handle, label, AVCT_RSP, p_rsp); + drop_code = 3; + } else if (p_msg->hdr.opcode == AVRC_OP_DROP) { + drop_code = 1; + } else if (p_msg->hdr.opcode == AVRC_OP_DROP_N_FREE) + drop_code = 4; + + } else if (cr == AVCT_RSP) { + if (req_continue == true) { + avrc_cmd.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; + drop_code = 2; + } else if (buf_overflow == true) { + /* Incoming message too big to fit in BT_DEFAULT_BUFFER_SIZE. Send abort + * to peer */ + avrc_cmd.pdu = AVRC_PDU_ABORT_CONTINUATION_RSP; + drop_code = 4; + } else { + return drop_code; } - else if (cr == AVCT_RSP) - { - if (req_continue == true) - { - avrc_cmd.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; - drop_code = 2; - } - else if (buf_overflow == true) - { - /* Incoming message too big to fit in BT_DEFAULT_BUFFER_SIZE. Send abort to peer */ - avrc_cmd.pdu = AVRC_PDU_ABORT_CONTINUATION_RSP; - drop_code = 4; - } - else - { - return drop_code; - } - avrc_cmd.status = AVRC_STS_NO_ERROR; - avrc_cmd.target_pdu = p_rcb->rasm_pdu; - status = AVRC_BldCommand ((tAVRC_COMMAND *)&avrc_cmd, &p_cmd); - if (status == AVRC_STS_NO_ERROR) - { - AVRC_MsgReq (handle, (uint8_t)(label), AVRC_CMD_CTRL, p_cmd); - } + avrc_cmd.status = AVRC_STS_NO_ERROR; + avrc_cmd.target_pdu = p_rcb->rasm_pdu; + status = AVRC_BldCommand((tAVRC_COMMAND*)&avrc_cmd, &p_cmd); + if (status == AVRC_STS_NO_ERROR) { + AVRC_MsgReq(handle, (uint8_t)(label), AVRC_CMD_CTRL, p_cmd); } + } - return drop_code; + return drop_code; } #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ @@ -650,347 +614,322 @@ static uint8_t avrc_proc_far_msg(uint8_t handle, uint8_t label, uint8_t cr, BT_H * *****************************************************************************/ static void avrc_msg_cback(uint8_t handle, uint8_t label, uint8_t cr, - BT_HDR *p_pkt) -{ - uint8_t opcode; - tAVRC_MSG msg; - uint8_t *p_data; - uint8_t *p_begin; - bool drop = false; - bool do_free = true; - BT_HDR *p_rsp = NULL; - uint8_t *p_rsp_data; - int xx; - bool reject = false; - const char *p_drop_msg = "dropped"; - tAVRC_MSG_VENDOR *p_msg = &msg.vendor; - - if (cr == AVCT_CMD && - (p_pkt->layer_specific & AVCT_DATA_CTRL && AVRC_PACKET_LEN < sizeof(p_pkt->len))) - { - /* Ignore the invalid AV/C command frame */ - p_drop_msg = "dropped - too long AV/C cmd frame size"; - osi_free(p_pkt); - return; - } - - if (cr == AVCT_REJ) - { - /* The peer thinks that this PID is no longer open - remove this handle */ - /* */ - osi_free(p_pkt); - AVCT_RemoveConn(handle); - return; - } - else if (cr == AVCT_RSP) - { - /* Received response. Stop command timeout timer */ - AVRC_TRACE_DEBUG("AVRC: stopping timer (handle=0x%02x)", handle); - alarm_cancel(avrc_cb.ccb_int[handle].tle); - } - - p_data = (uint8_t *)(p_pkt+1) + p_pkt->offset; - memset(&msg, 0, sizeof(tAVRC_MSG) ); - - if (p_pkt->layer_specific == AVCT_DATA_BROWSE) - { - opcode = AVRC_OP_BROWSE; - msg.browse.hdr.ctype= cr; - msg.browse.p_browse_data = p_data; - msg.browse.browse_len = p_pkt->len; - msg.browse.p_browse_pkt = p_pkt; - } - else - { - msg.hdr.ctype = p_data[0] & AVRC_CTYPE_MASK; - AVRC_TRACE_DEBUG("%s handle:%d, ctype:%d, offset:%d, len: %d", __func__, - handle, msg.hdr.ctype, p_pkt->offset, p_pkt->len); - msg.hdr.subunit_type = (p_data[1] & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT; - msg.hdr.subunit_id = p_data[1] & AVRC_SUBID_MASK; - opcode = p_data[2]; - } + BT_HDR* p_pkt) { + uint8_t opcode; + tAVRC_MSG msg; + uint8_t* p_data; + uint8_t* p_begin; + bool drop = false; + bool do_free = true; + BT_HDR* p_rsp = NULL; + uint8_t* p_rsp_data; + int xx; + bool reject = false; + const char* p_drop_msg = "dropped"; + tAVRC_MSG_VENDOR* p_msg = &msg.vendor; + + if (cr == AVCT_CMD && (p_pkt->layer_specific & AVCT_DATA_CTRL && + AVRC_PACKET_LEN < sizeof(p_pkt->len))) { + /* Ignore the invalid AV/C command frame */ + p_drop_msg = "dropped - too long AV/C cmd frame size"; + osi_free(p_pkt); + return; + } + + if (cr == AVCT_REJ) { + /* The peer thinks that this PID is no longer open - remove this handle */ + /* */ + osi_free(p_pkt); + AVCT_RemoveConn(handle); + return; + } else if (cr == AVCT_RSP) { + /* Received response. Stop command timeout timer */ + AVRC_TRACE_DEBUG("AVRC: stopping timer (handle=0x%02x)", handle); + alarm_cancel(avrc_cb.ccb_int[handle].tle); + } + + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + memset(&msg, 0, sizeof(tAVRC_MSG)); + + if (p_pkt->layer_specific == AVCT_DATA_BROWSE) { + opcode = AVRC_OP_BROWSE; + msg.browse.hdr.ctype = cr; + msg.browse.p_browse_data = p_data; + msg.browse.browse_len = p_pkt->len; + msg.browse.p_browse_pkt = p_pkt; + } else { + msg.hdr.ctype = p_data[0] & AVRC_CTYPE_MASK; + AVRC_TRACE_DEBUG("%s handle:%d, ctype:%d, offset:%d, len: %d", __func__, + handle, msg.hdr.ctype, p_pkt->offset, p_pkt->len); + msg.hdr.subunit_type = + (p_data[1] & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT; + msg.hdr.subunit_id = p_data[1] & AVRC_SUBID_MASK; + opcode = p_data[2]; + } + + if (((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD)) || + ((avrc_cb.ccb[handle].control & AVRC_CT_CONTROL) && (cr == AVCT_RSP))) { + switch (opcode) { + case AVRC_OP_UNIT_INFO: + if (cr == AVCT_CMD) { + /* send the response to the peer */ + p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_UNIT_INFO_RSP_LEN); + p_rsp_data = avrc_get_data_ptr(p_rsp); + *p_rsp_data = AVRC_RSP_IMPL_STBL; + /* check & set the offset. set response code, set subunit_type & + subunit_id, + set AVRC_OP_UNIT_INFO */ + /* 3 bytes: ctype, subunit*, opcode */ + p_rsp_data += AVRC_AVC_HDR_SIZE; + *p_rsp_data++ = 7; + /* Panel subunit & id=0 */ + *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + AVRC_CO_ID_TO_BE_STREAM(p_rsp_data, avrc_cb.ccb[handle].company_id); + p_rsp->len = + (uint16_t)(p_rsp_data - (uint8_t*)(p_rsp + 1) - p_rsp->offset); + cr = AVCT_RSP; + p_drop_msg = "auto respond"; + } else { + /* parse response */ + p_data += 4; /* 3 bytes: ctype, subunit*, opcode + octet 3 (is 7)*/ + msg.unit.unit_type = + (*p_data & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT; + msg.unit.unit = *p_data & AVRC_SUBID_MASK; + p_data++; + AVRC_BE_STREAM_TO_CO_ID(msg.unit.company_id, p_data); + } + break; - if ( ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD)) || - ((avrc_cb.ccb[handle].control & AVRC_CT_CONTROL) && (cr == AVCT_RSP)) ) - { + case AVRC_OP_SUB_INFO: + if (cr == AVCT_CMD) { + /* send the response to the peer */ + p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_SUB_UNIT_INFO_RSP_LEN); + p_rsp_data = avrc_get_data_ptr(p_rsp); + *p_rsp_data = AVRC_RSP_IMPL_STBL; + /* check & set the offset. set response code, set (subunit_type & + subunit_id), + set AVRC_OP_SUB_INFO, set (page & extention code) */ + p_rsp_data += 4; + /* Panel subunit & id=0 */ + *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + memset(p_rsp_data, AVRC_CMD_OPRND_PAD, AVRC_SUBRSP_OPRND_BYTES); + p_rsp_data += AVRC_SUBRSP_OPRND_BYTES; + p_rsp->len = + (uint16_t)(p_rsp_data - (uint8_t*)(p_rsp + 1) - p_rsp->offset); + cr = AVCT_RSP; + p_drop_msg = "auto responded"; + } else { + /* parse response */ + p_data += AVRC_AVC_HDR_SIZE; /* 3 bytes: ctype, subunit*, opcode */ + msg.sub.page = + (*p_data++ >> AVRC_SUB_PAGE_SHIFT) & AVRC_SUB_PAGE_MASK; + xx = 0; + while (*p_data != AVRC_CMD_OPRND_PAD && xx < AVRC_SUB_TYPE_LEN) { + msg.sub.subunit_type[xx] = *p_data++ >> AVRC_SUBTYPE_SHIFT; + if (msg.sub.subunit_type[xx] == AVRC_SUB_PANEL) + msg.sub.panel = true; + xx++; + } + } + break; - switch(opcode) + case AVRC_OP_VENDOR: { + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_begin = p_data; + if (p_pkt->len < + AVRC_VENDOR_HDR_SIZE) /* 6 = ctype, subunit*, opcode & CO_ID */ { - case AVRC_OP_UNIT_INFO: - if (cr == AVCT_CMD) - { - /* send the response to the peer */ - p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_UNIT_INFO_RSP_LEN); - p_rsp_data = avrc_get_data_ptr(p_rsp); - *p_rsp_data = AVRC_RSP_IMPL_STBL; - /* check & set the offset. set response code, set subunit_type & subunit_id, - set AVRC_OP_UNIT_INFO */ - /* 3 bytes: ctype, subunit*, opcode */ - p_rsp_data += AVRC_AVC_HDR_SIZE; - *p_rsp_data++ = 7; - /* Panel subunit & id=0 */ - *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - AVRC_CO_ID_TO_BE_STREAM(p_rsp_data, avrc_cb.ccb[handle].company_id); - p_rsp->len = (uint16_t) (p_rsp_data - (uint8_t *)(p_rsp + 1) - p_rsp->offset); - cr = AVCT_RSP; - p_drop_msg = "auto respond"; - } - else - { - /* parse response */ - p_data += 4; /* 3 bytes: ctype, subunit*, opcode + octet 3 (is 7)*/ - msg.unit.unit_type = (*p_data & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT; - msg.unit.unit = *p_data & AVRC_SUBID_MASK; - p_data++; - AVRC_BE_STREAM_TO_CO_ID(msg.unit.company_id, p_data); - } - break; + if (cr == AVCT_CMD) + reject = true; + else + drop = true; + break; + } + p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, + opcode */ + AVRC_BE_STREAM_TO_CO_ID(p_msg->company_id, p_data); + p_msg->p_vendor_data = p_data; + p_msg->vendor_len = p_pkt->len - (p_data - p_begin); - case AVRC_OP_SUB_INFO: +#if (AVRC_METADATA_INCLUDED == TRUE) + uint8_t drop_code = 0; + if (p_msg->company_id == AVRC_CO_METADATA) { + /* Validate length for metadata message */ + if (p_pkt->len < (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE)) { if (cr == AVCT_CMD) - { - /* send the response to the peer */ - p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_SUB_UNIT_INFO_RSP_LEN); - p_rsp_data = avrc_get_data_ptr(p_rsp); - *p_rsp_data = AVRC_RSP_IMPL_STBL; - /* check & set the offset. set response code, set (subunit_type & subunit_id), - set AVRC_OP_SUB_INFO, set (page & extention code) */ - p_rsp_data += 4; - /* Panel subunit & id=0 */ - *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - memset(p_rsp_data, AVRC_CMD_OPRND_PAD, AVRC_SUBRSP_OPRND_BYTES); - p_rsp_data += AVRC_SUBRSP_OPRND_BYTES; - p_rsp->len = (uint16_t) (p_rsp_data - (uint8_t *)(p_rsp + 1) - p_rsp->offset); - cr = AVCT_RSP; - p_drop_msg = "auto responded"; - } + reject = true; else - { - /* parse response */ - p_data += AVRC_AVC_HDR_SIZE; /* 3 bytes: ctype, subunit*, opcode */ - msg.sub.page = (*p_data++ >> AVRC_SUB_PAGE_SHIFT) & AVRC_SUB_PAGE_MASK; - xx = 0; - while (*p_data != AVRC_CMD_OPRND_PAD && xx> AVRC_SUBTYPE_SHIFT; - if (msg.sub.subunit_type[xx] == AVRC_SUB_PANEL) - msg.sub.panel = true; - xx++; - } - } + drop = true; break; + } - case AVRC_OP_VENDOR: - { - p_data = (uint8_t *)(p_pkt+1) + p_pkt->offset; - p_begin = p_data; - if (p_pkt->len < AVRC_VENDOR_HDR_SIZE) /* 6 = ctype, subunit*, opcode & CO_ID */ - { - if (cr == AVCT_CMD) - reject = true; - else - drop = true; - break; - } - p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, opcode */ - AVRC_BE_STREAM_TO_CO_ID(p_msg->company_id, p_data); - p_msg->p_vendor_data = p_data; - p_msg->vendor_len = p_pkt->len - (p_data - p_begin); - -#if (AVRC_METADATA_INCLUDED == TRUE) - uint8_t drop_code = 0; - if (p_msg->company_id == AVRC_CO_METADATA) - { - /* Validate length for metadata message */ - if (p_pkt->len < (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE)) - { - if (cr == AVCT_CMD) - reject = true; - else - drop = true; - break; - } - - /* Check+handle fragmented messages */ - drop_code = avrc_proc_far_msg(handle, label, cr, &p_pkt, p_msg); - if (drop_code > 0) - drop = true; - } - if (drop_code > 0) - { - if (drop_code != 4) - do_free = false; - switch (drop_code) - { - case 1: - p_drop_msg = "sent_frag"; - break; - case 2: - p_drop_msg = "req_cont"; - break; - case 3: - p_drop_msg = "sent_frag3"; - break; - case 4: - p_drop_msg = "sent_frag_free"; - break; - default: - p_drop_msg = "sent_fragd"; - } - } + /* Check+handle fragmented messages */ + drop_code = avrc_proc_far_msg(handle, label, cr, &p_pkt, p_msg); + if (drop_code > 0) drop = true; + } + if (drop_code > 0) { + if (drop_code != 4) do_free = false; + switch (drop_code) { + case 1: + p_drop_msg = "sent_frag"; + break; + case 2: + p_drop_msg = "req_cont"; + break; + case 3: + p_drop_msg = "sent_frag3"; + break; + case 4: + p_drop_msg = "sent_frag_free"; + break; + default: + p_drop_msg = "sent_fragd"; + } + } #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ - /* If vendor response received, and did not ask for continuation */ - /* then check queue for addition commands to send */ - if ((cr == AVCT_RSP) && (drop_code != 2)) - { - avrc_send_next_vendor_cmd(handle); - } + /* If vendor response received, and did not ask for continuation */ + /* then check queue for addition commands to send */ + if ((cr == AVCT_RSP) && (drop_code != 2)) { + avrc_send_next_vendor_cmd(handle); } - break; - - case AVRC_OP_PASS_THRU: - if (p_pkt->len < 5) /* 3 bytes: ctype, subunit*, opcode & op_id & len */ - { - if (cr == AVCT_CMD) - reject = true; - else - drop = true; - break; - } - p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, opcode */ - msg.pass.op_id = (AVRC_PASS_OP_ID_MASK & *p_data); - if (AVRC_PASS_STATE_MASK & *p_data) - msg.pass.state = true; - else - msg.pass.state = false; - p_data++; - msg.pass.pass_len = *p_data++; - if (msg.pass.pass_len != p_pkt->len - 5) - msg.pass.pass_len = p_pkt->len - 5; - if (msg.pass.pass_len) - msg.pass.p_pass_data = p_data; - else - msg.pass.p_pass_data = NULL; - break; - - case AVRC_OP_BROWSE: - /* If browse response received, then check queue for addition commands to send */ - if (cr == AVCT_RSP) - { - avrc_send_next_vendor_cmd(handle); - } - break; + } break; - default: - if ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD)) - { - /* reject unsupported opcode */ - reject = true; - } - drop = true; - break; + case AVRC_OP_PASS_THRU: + if (p_pkt->len < 5) /* 3 bytes: ctype, subunit*, opcode & op_id & len */ + { + if (cr == AVCT_CMD) + reject = true; + else + drop = true; + break; } - } - else /* drop the event */ - { - if (opcode != AVRC_OP_BROWSE) - drop = true; - } + p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, + opcode */ + msg.pass.op_id = (AVRC_PASS_OP_ID_MASK & *p_data); + if (AVRC_PASS_STATE_MASK & *p_data) + msg.pass.state = true; + else + msg.pass.state = false; + p_data++; + msg.pass.pass_len = *p_data++; + if (msg.pass.pass_len != p_pkt->len - 5) + msg.pass.pass_len = p_pkt->len - 5; + if (msg.pass.pass_len) + msg.pass.p_pass_data = p_data; + else + msg.pass.p_pass_data = NULL; + break; - if (reject) - { - /* reject unsupported opcode */ - p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_REJ_MSG_LEN); - p_rsp_data = avrc_get_data_ptr(p_rsp); - *p_rsp_data = AVRC_RSP_REJ; - p_drop_msg = "rejected"; - cr = AVCT_RSP; - drop = true; - } + case AVRC_OP_BROWSE: + /* If browse response received, then check queue for addition commands + * to send */ + if (cr == AVCT_RSP) { + avrc_send_next_vendor_cmd(handle); + } + break; - if (p_rsp) - { - /* set to send response right away */ - AVCT_MsgReq( handle, label, cr, p_rsp); + default: + if ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && + (cr == AVCT_CMD)) { + /* reject unsupported opcode */ + reject = true; + } drop = true; + break; } - - if (drop == false) - { - msg.hdr.opcode = opcode; - (*avrc_cb.ccb[handle].p_msg_cback)(handle, label, opcode, &msg); - } else { - AVRC_TRACE_WARNING("%s %s msg handle:%d, control:%d, cr:%d, opcode:x%x", - __func__, p_drop_msg, - handle, avrc_cb.ccb[handle].control, cr, opcode); - } - - if (opcode == AVRC_OP_BROWSE && msg.browse.p_browse_pkt == NULL) - { - do_free = false; - } - - if (do_free) - osi_free(p_pkt); + } else /* drop the event */ + { + if (opcode != AVRC_OP_BROWSE) drop = true; + } + + if (reject) { + /* reject unsupported opcode */ + p_rsp = avrc_copy_packet(p_pkt, AVRC_OP_REJ_MSG_LEN); + p_rsp_data = avrc_get_data_ptr(p_rsp); + *p_rsp_data = AVRC_RSP_REJ; + p_drop_msg = "rejected"; + cr = AVCT_RSP; + drop = true; + } + + if (p_rsp) { + /* set to send response right away */ + AVCT_MsgReq(handle, label, cr, p_rsp); + drop = true; + } + + if (drop == false) { + msg.hdr.opcode = opcode; + (*avrc_cb.ccb[handle].p_msg_cback)(handle, label, opcode, &msg); + } else { + AVRC_TRACE_WARNING("%s %s msg handle:%d, control:%d, cr:%d, opcode:x%x", + __func__, p_drop_msg, handle, + avrc_cb.ccb[handle].control, cr, opcode); + } + + if (opcode == AVRC_OP_BROWSE && msg.browse.p_browse_pkt == NULL) { + do_free = false; + } + + if (do_free) osi_free(p_pkt); } -static void AVRC_build_empty_packet(BT_HDR *p_pkt) { - uint8_t *p_start = ((uint8_t *)(p_pkt + 1) + p_pkt->offset); - *p_start = AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK; - p_start += AVRC_VENDOR_HDR_SIZE; - UINT8_TO_BE_STREAM(p_start, 0); - UINT8_TO_BE_STREAM(p_start, AVRC_PKT_SINGLE); - UINT16_TO_BE_STREAM(p_start, 0); - p_pkt->len = AVRC_VENDOR_HDR_SIZE + 4; +static void AVRC_build_empty_packet(BT_HDR* p_pkt) { + uint8_t* p_start = ((uint8_t*)(p_pkt + 1) + p_pkt->offset); + *p_start = AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK; + p_start += AVRC_VENDOR_HDR_SIZE; + UINT8_TO_BE_STREAM(p_start, 0); + UINT8_TO_BE_STREAM(p_start, AVRC_PKT_SINGLE); + UINT16_TO_BE_STREAM(p_start, 0); + p_pkt->len = AVRC_VENDOR_HDR_SIZE + 4; } -static void AVRC_build_error_packet(BT_HDR *p_pkt) { - uint8_t *p_start = ((uint8_t *)(p_pkt + 1) + p_pkt->offset); - *p_start = AVRC_RSP_REJ & AVRC_CTYPE_MASK; - p_start += AVRC_VENDOR_HDR_SIZE; - UINT8_TO_BE_STREAM(p_start, 0); - UINT8_TO_BE_STREAM(p_start, AVRC_PKT_SINGLE); - UINT16_TO_BE_STREAM(p_start, 1); - UINT8_TO_BE_STREAM(p_start, AVRC_STS_BAD_PARAM); - p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; +static void AVRC_build_error_packet(BT_HDR* p_pkt) { + uint8_t* p_start = ((uint8_t*)(p_pkt + 1) + p_pkt->offset); + *p_start = AVRC_RSP_REJ & AVRC_CTYPE_MASK; + p_start += AVRC_VENDOR_HDR_SIZE; + UINT8_TO_BE_STREAM(p_start, 0); + UINT8_TO_BE_STREAM(p_start, AVRC_PKT_SINGLE); + UINT16_TO_BE_STREAM(p_start, 1); + UINT8_TO_BE_STREAM(p_start, AVRC_STS_BAD_PARAM); + p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; } -static uint16_t AVRC_HandleContinueRsp(uint8_t handle, uint8_t label, BT_HDR *p_pkt) -{ - AVRC_TRACE_DEBUG("%s()", __func__); +static uint16_t AVRC_HandleContinueRsp(uint8_t handle, uint8_t label, + BT_HDR* p_pkt) { + AVRC_TRACE_DEBUG("%s()", __func__); - uint8_t *p_data = ((uint8_t *)(p_pkt + 1) + p_pkt->offset + AVRC_VENDOR_HDR_SIZE); - tAVRC_FRAG_CB *p_fcb = &avrc_cb.fcb[handle]; + uint8_t* p_data = + ((uint8_t*)(p_pkt + 1) + p_pkt->offset + AVRC_VENDOR_HDR_SIZE); + tAVRC_FRAG_CB* p_fcb = &avrc_cb.fcb[handle]; - uint8_t pdu, pkt_type, target_pdu; - uint16_t len; + uint8_t pdu, pkt_type, target_pdu; + uint16_t len; - BE_STREAM_TO_UINT8(pdu, p_data); - BE_STREAM_TO_UINT8(pkt_type, p_data); - BE_STREAM_TO_UINT16(len, p_data); - BE_STREAM_TO_UINT8(target_pdu, p_data); + BE_STREAM_TO_UINT8(pdu, p_data); + BE_STREAM_TO_UINT8(pkt_type, p_data); + BE_STREAM_TO_UINT16(len, p_data); + BE_STREAM_TO_UINT8(target_pdu, p_data); - if (pdu == AVRC_PDU_REQUEST_CONTINUATION_RSP && - target_pdu == p_fcb->frag_pdu) { - return avrc_send_continue_frag(handle, label); - } + if (pdu == AVRC_PDU_REQUEST_CONTINUATION_RSP && + target_pdu == p_fcb->frag_pdu) { + return avrc_send_continue_frag(handle, label); + } - if (pdu == AVRC_PDU_ABORT_CONTINUATION_RSP && - target_pdu == p_fcb->frag_pdu) { - AVRC_build_empty_packet(p_pkt); - } else { - AVRC_TRACE_ERROR("%s() error: target_pdu: 0x%02x, frag_pdu: 0x%02x", - __func__, *(p_data+4), p_fcb->frag_pdu); - AVRC_build_error_packet(p_pkt); - } + if (pdu == AVRC_PDU_ABORT_CONTINUATION_RSP && target_pdu == p_fcb->frag_pdu) { + AVRC_build_empty_packet(p_pkt); + } else { + AVRC_TRACE_ERROR("%s() error: target_pdu: 0x%02x, frag_pdu: 0x%02x", + __func__, *(p_data + 4), p_fcb->frag_pdu); + AVRC_build_error_packet(p_pkt); + } - p_fcb->frag_enabled = FALSE; - osi_free_and_reset((void **)&p_fcb->p_fmsg); + p_fcb->frag_enabled = FALSE; + osi_free_and_reset((void**)&p_fcb->p_fmsg); - return AVCT_MsgReq(handle, label, AVCT_RSP, p_pkt); + return AVCT_MsgReq(handle, label, AVCT_RSP, p_pkt); } - /****************************************************************************** * * Function avrc_pass_msg @@ -1007,37 +946,35 @@ static uint16_t AVRC_HandleContinueRsp(uint8_t handle, uint8_t label, BT_HDR *p_ * NULL if p_msg is NULL. * *****************************************************************************/ -static BT_HDR * avrc_pass_msg(tAVRC_MSG_PASS *p_msg) -{ - assert(p_msg != NULL); - assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN+p_msg->pass_len)); - - BT_HDR *p_cmd = (BT_HDR *)osi_malloc(AVRC_CMD_BUF_SIZE); - p_cmd->offset = AVCT_MSG_OFFSET; - p_cmd->layer_specific = AVCT_DATA_CTRL; - - uint8_t *p_data = (uint8_t *)(p_cmd + 1) + p_cmd->offset; - *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); /* Panel subunit & id=0 */ - *p_data++ = AVRC_OP_PASS_THRU; - *p_data = (AVRC_PASS_OP_ID_MASK&p_msg->op_id); - if (p_msg->state) - *p_data |= AVRC_PASS_STATE_MASK; - p_data++; - - if (p_msg->op_id == AVRC_ID_VENDOR) { - *p_data++ = p_msg->pass_len; - if (p_msg->pass_len && p_msg->p_pass_data) { - memcpy(p_data, p_msg->p_pass_data, p_msg->pass_len); - p_data += p_msg->pass_len; - } - } else { - /* set msg len to 0 for other op_id */ - *p_data++ = 0; +static BT_HDR* avrc_pass_msg(tAVRC_MSG_PASS* p_msg) { + assert(p_msg != NULL); + assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->pass_len)); + + BT_HDR* p_cmd = (BT_HDR*)osi_malloc(AVRC_CMD_BUF_SIZE); + p_cmd->offset = AVCT_MSG_OFFSET; + p_cmd->layer_specific = AVCT_DATA_CTRL; + + uint8_t* p_data = (uint8_t*)(p_cmd + 1) + p_cmd->offset; + *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); /* Panel subunit & id=0 */ + *p_data++ = AVRC_OP_PASS_THRU; + *p_data = (AVRC_PASS_OP_ID_MASK & p_msg->op_id); + if (p_msg->state) *p_data |= AVRC_PASS_STATE_MASK; + p_data++; + + if (p_msg->op_id == AVRC_ID_VENDOR) { + *p_data++ = p_msg->pass_len; + if (p_msg->pass_len && p_msg->p_pass_data) { + memcpy(p_data, p_msg->p_pass_data, p_msg->pass_len); + p_data += p_msg->pass_len; } - p_cmd->len = (uint16_t) (p_data - (uint8_t *)(p_cmd + 1) - p_cmd->offset); + } else { + /* set msg len to 0 for other op_id */ + *p_data++ = 0; + } + p_cmd->len = (uint16_t)(p_data - (uint8_t*)(p_cmd + 1) - p_cmd->offset); - return p_cmd; + return p_cmd; } /****************************************************************************** @@ -1088,33 +1025,32 @@ static BT_HDR * avrc_pass_msg(tAVRC_MSG_PASS *p_msg) * the connection. * *****************************************************************************/ -uint16_t AVRC_Open(uint8_t *p_handle, tAVRC_CONN_CB *p_ccb, BD_ADDR_PTR peer_addr) -{ - uint16_t status; - tAVCT_CC cc; - - cc.p_ctrl_cback = avrc_ctrl_cback; /* Control callback */ - cc.p_msg_cback = avrc_msg_cback; /* Message callback */ - cc.pid = UUID_SERVCLASS_AV_REMOTE_CONTROL; /* Profile ID */ - cc.role = p_ccb->conn; /* Initiator/acceptor role */ - cc.control = p_ccb->control; /* Control role (Control/Target) */ - - status = AVCT_CreateConn(p_handle, &cc, peer_addr); - if (status == AVCT_SUCCESS) - { - memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB)); - memset(&avrc_cb.ccb_int[*p_handle], 0, sizeof(tAVRC_CONN_INT_CB)); +uint16_t AVRC_Open(uint8_t* p_handle, tAVRC_CONN_CB* p_ccb, + BD_ADDR_PTR peer_addr) { + uint16_t status; + tAVCT_CC cc; + + cc.p_ctrl_cback = avrc_ctrl_cback; /* Control callback */ + cc.p_msg_cback = avrc_msg_cback; /* Message callback */ + cc.pid = UUID_SERVCLASS_AV_REMOTE_CONTROL; /* Profile ID */ + cc.role = p_ccb->conn; /* Initiator/acceptor role */ + cc.control = p_ccb->control; /* Control role (Control/Target) */ + + status = AVCT_CreateConn(p_handle, &cc, peer_addr); + if (status == AVCT_SUCCESS) { + memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB)); + memset(&avrc_cb.ccb_int[*p_handle], 0, sizeof(tAVRC_CONN_INT_CB)); #if (AVRC_METADATA_INCLUDED == TRUE) - memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB)); - memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB)); + memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB)); + memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB)); #endif - avrc_cb.ccb_int[*p_handle].tle = alarm_new("avrcp.commandTimer"); - avrc_cb.ccb_int[*p_handle].cmd_q = fixed_queue_new(SIZE_MAX); - } - AVRC_TRACE_DEBUG("%s role: %d, control:%d status:%d, handle:%d", __func__, - cc.role, cc.control, status, *p_handle); + avrc_cb.ccb_int[*p_handle].tle = alarm_new("avrcp.commandTimer"); + avrc_cb.ccb_int[*p_handle].cmd_q = fixed_queue_new(SIZE_MAX); + } + AVRC_TRACE_DEBUG("%s role: %d, control:%d status:%d, handle:%d", __func__, + cc.role, cc.control, status, *p_handle); - return status; + return status; } /****************************************************************************** @@ -1135,10 +1071,9 @@ uint16_t AVRC_Open(uint8_t *p_handle, tAVRC_CONN_CB *p_ccb, BD_ADDR_PTR peer_add * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_Close(uint8_t handle) -{ - AVRC_TRACE_DEBUG("%s handle:%d", __func__, handle); - return AVCT_RemoveConn(handle); +uint16_t AVRC_Close(uint8_t handle) { + AVRC_TRACE_DEBUG("%s handle:%d", __func__, handle); + return AVCT_RemoveConn(handle); } /****************************************************************************** @@ -1155,9 +1090,8 @@ uint16_t AVRC_Close(uint8_t handle) * the connection. * *****************************************************************************/ -uint16_t AVRC_OpenBrowse(uint8_t handle, uint8_t conn_role) -{ - return AVCT_CreateBrowse(handle, conn_role); +uint16_t AVRC_OpenBrowse(uint8_t handle, uint8_t conn_role) { + return AVCT_CreateBrowse(handle, conn_role); } /****************************************************************************** @@ -1172,10 +1106,7 @@ uint16_t AVRC_OpenBrowse(uint8_t handle, uint8_t conn_role) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_CloseBrowse(uint8_t handle) -{ - return AVCT_RemoveBrowse(handle); -} +uint16_t AVRC_CloseBrowse(uint8_t handle) { return AVCT_RemoveBrowse(handle); } /****************************************************************************** * @@ -1196,181 +1127,169 @@ uint16_t AVRC_CloseBrowse(uint8_t handle) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_MsgReq (uint8_t handle, uint8_t label, uint8_t ctype, BT_HDR *p_pkt) -{ +uint16_t AVRC_MsgReq(uint8_t handle, uint8_t label, uint8_t ctype, + BT_HDR* p_pkt) { #if (AVRC_METADATA_INCLUDED == TRUE) - uint8_t *p_data; - uint8_t cr = AVCT_CMD; - bool chk_frag = true; - uint8_t *p_start = NULL; - tAVRC_FRAG_CB *p_fcb; - uint16_t len; - uint16_t status; - uint8_t msg_mask = 0; - uint16_t peer_mtu; - - if (!p_pkt) - return AVRC_BAD_PARAM; - - AVRC_TRACE_DEBUG("%s handle = %u label = %u ctype = %u len = %d", - __func__, handle, label, ctype, p_pkt->len); - - if (ctype >= AVRC_RSP_NOT_IMPL) - cr = AVCT_RSP; - - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - if (*p_data == AVRC_PDU_REQUEST_CONTINUATION_RSP || - *p_data == AVRC_PDU_ABORT_CONTINUATION_RSP) { - return AVRC_HandleContinueRsp(handle, label, p_pkt); - } + uint8_t* p_data; + uint8_t cr = AVCT_CMD; + bool chk_frag = true; + uint8_t* p_start = NULL; + tAVRC_FRAG_CB* p_fcb; + uint16_t len; + uint16_t status; + uint8_t msg_mask = 0; + uint16_t peer_mtu; + + if (!p_pkt) return AVRC_BAD_PARAM; + + AVRC_TRACE_DEBUG("%s handle = %u label = %u ctype = %u len = %d", __func__, + handle, label, ctype, p_pkt->len); + + if (ctype >= AVRC_RSP_NOT_IMPL) cr = AVCT_RSP; + + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + if (*p_data == AVRC_PDU_REQUEST_CONTINUATION_RSP || + *p_data == AVRC_PDU_ABORT_CONTINUATION_RSP) { + return AVRC_HandleContinueRsp(handle, label, p_pkt); + } + + if (p_pkt->event == AVRC_OP_VENDOR) { + /* add AVRCP Vendor Dependent headers */ + p_start = ((uint8_t*)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_VENDOR_HDR_SIZE; + p_pkt->len += AVRC_VENDOR_HDR_SIZE; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - if (p_pkt->event == AVRC_OP_VENDOR) - { - /* add AVRCP Vendor Dependent headers */ - p_start = ((uint8_t *)(p_pkt + 1) + p_pkt->offset); - p_pkt->offset -= AVRC_VENDOR_HDR_SIZE; - p_pkt->len += AVRC_VENDOR_HDR_SIZE; - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - *p_data++ = (ctype & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_VENDOR; - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); - - /* Check if this is a AVRC_PDU_REQUEST_CONTINUATION_RSP */ - if (cr == AVCT_CMD) - { - msg_mask |= AVRC_MSG_MASK_IS_VENDOR_CMD; + /* Check if this is a AVRC_PDU_REQUEST_CONTINUATION_RSP */ + if (cr == AVCT_CMD) { + msg_mask |= AVRC_MSG_MASK_IS_VENDOR_CMD; - if ((*p_start == AVRC_PDU_REQUEST_CONTINUATION_RSP) - || (*p_start == AVRC_PDU_ABORT_CONTINUATION_RSP)) - { - msg_mask |= AVRC_MSG_MASK_IS_CONTINUATION_RSP; - } - } - } - else if (p_pkt->event == AVRC_OP_PASS_THRU) - { - /* add AVRCP Pass Through headers */ - p_start = ((uint8_t *)(p_pkt + 1) + p_pkt->offset); - p_pkt->offset -= AVRC_PASS_THRU_SIZE; - p_pkt->len += AVRC_PASS_THRU_SIZE; - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - *p_data++ = (ctype & AVRC_CTYPE_MASK); - *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); - *p_data++ = AVRC_OP_PASS_THRU;/* opcode */ - *p_data++ = AVRC_ID_VENDOR; /* operation id */ - *p_data++ = 5; /* operation data len */ - AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + if ((*p_start == AVRC_PDU_REQUEST_CONTINUATION_RSP) || + (*p_start == AVRC_PDU_ABORT_CONTINUATION_RSP)) { + msg_mask |= AVRC_MSG_MASK_IS_CONTINUATION_RSP; + } } - else - { - chk_frag = false; - peer_mtu = AVCT_GetBrowseMtu (handle); - if (p_pkt->len > (peer_mtu-AVCT_HDR_LEN_SINGLE)) - { - AVRC_TRACE_ERROR ("%s bigger than peer mtu (p_pkt->len(%d) > peer_mtu(%d-%d))", - __func__, p_pkt->len, peer_mtu, AVCT_HDR_LEN_SINGLE ); - osi_free(p_pkt); - return AVRC_MSG_TOO_BIG; - } + } else if (p_pkt->event == AVRC_OP_PASS_THRU) { + /* add AVRCP Pass Through headers */ + p_start = ((uint8_t*)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_PASS_THRU_SIZE; + p_pkt->len += AVRC_PASS_THRU_SIZE; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_PASS_THRU; /* opcode */ + *p_data++ = AVRC_ID_VENDOR; /* operation id */ + *p_data++ = 5; /* operation data len */ + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + } else { + chk_frag = false; + peer_mtu = AVCT_GetBrowseMtu(handle); + if (p_pkt->len > (peer_mtu - AVCT_HDR_LEN_SINGLE)) { + AVRC_TRACE_ERROR( + "%s bigger than peer mtu (p_pkt->len(%d) > peer_mtu(%d-%d))", + __func__, p_pkt->len, peer_mtu, AVCT_HDR_LEN_SINGLE); + osi_free(p_pkt); + return AVRC_MSG_TOO_BIG; } + } - /* abandon previous fragments */ - p_fcb = &avrc_cb.fcb[handle]; + /* abandon previous fragments */ + p_fcb = &avrc_cb.fcb[handle]; - if(p_fcb == NULL) - { - AVRC_TRACE_ERROR ("%s p_fcb is NULL", __func__ ); - osi_free(p_pkt); - return AVRC_NOT_OPEN; - } + if (p_fcb == NULL) { + AVRC_TRACE_ERROR("%s p_fcb is NULL", __func__); + osi_free(p_pkt); + return AVRC_NOT_OPEN; + } - if (p_fcb->frag_enabled) - p_fcb->frag_enabled = false; + if (p_fcb->frag_enabled) p_fcb->frag_enabled = false; - osi_free_and_reset((void **)&p_fcb->p_fmsg); + osi_free_and_reset((void**)&p_fcb->p_fmsg); - /* AVRCP spec has not defined any control channel commands that needs fragmentation at this level - * check for fragmentation only on the response */ - if ((cr == AVCT_RSP) && (chk_frag == true)) - { - if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) - { - int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset); - BT_HDR *p_pkt_new = - (BT_HDR *)osi_malloc(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE); - if (p_start != NULL) { - p_fcb->frag_enabled = true; - p_fcb->p_fmsg = p_pkt; - p_fcb->frag_pdu = *p_start; - p_pkt = p_pkt_new; - p_pkt_new = p_fcb->p_fmsg; - p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; - p_pkt->offset = p_pkt_new->offset; - p_pkt->layer_specific = p_pkt_new->layer_specific; - p_pkt->event = p_pkt_new->event; - p_data = (uint8_t *)(p_pkt+1) + p_pkt->offset; - p_start -= AVRC_VENDOR_HDR_SIZE; - memcpy (p_data, p_start, AVRC_MAX_CTRL_DATA_LEN); - /* use AVRC start packet type */ - p_data += AVRC_VENDOR_HDR_SIZE; - p_data++; /* pdu */ - *p_data++ = AVRC_PKT_START; - - /* 4 pdu, pkt_type & len */ - len = (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); - UINT16_TO_BE_STREAM(p_data, len); - - /* prepare the left over for as an end fragment */ - avrc_prep_end_frag (handle); - AVRC_TRACE_DEBUG ("%s p_pkt len:%d/%d, next len:%d", __func__, - p_pkt->len, len, p_fcb->p_fmsg->len ); - } else { - /* TODO: Is this "else" block valid? Remove it? */ - AVRC_TRACE_ERROR ("%s no buffers for fragmentation", __func__ ); - osi_free(p_pkt); - return AVRC_NO_RESOURCES; - } - } - } - else if ((p_pkt->event == AVRC_OP_VENDOR) && (cr == AVCT_CMD) && - (avrc_cb.ccb_int[handle].flags & AVRC_CB_FLAGS_RSP_PENDING) && - !(msg_mask & AVRC_MSG_MASK_IS_CONTINUATION_RSP)) - { - /* If we are sending a vendor specific command, and a response is pending, - * then enqueue the command until the response has been received. - * This is to interop with TGs that abort sending responses whenever a new command - * is received (exception is continuation request command - * must sent that to get additional response frags) */ - AVRC_TRACE_DEBUG("AVRC: Enqueuing command 0x%08x (handle=0x%02x, label=0x%02x)", - p_pkt, handle, label); - - /* label in BT_HDR (will need this later when the command is dequeued) */ - p_pkt->layer_specific = (label << 8) | (p_pkt->layer_specific & 0xFF); - - /* Enqueue the command */ - fixed_queue_enqueue(avrc_cb.ccb_int[handle].cmd_q, p_pkt); - return AVRC_SUCCESS; - } + /* AVRCP spec has not defined any control channel commands that needs + * fragmentation at this level + * check for fragmentation only on the response */ + if ((cr == AVCT_RSP) && (chk_frag == true)) { + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) { + int offset_len = MAX(AVCT_MSG_OFFSET, p_pkt->offset); + BT_HDR* p_pkt_new = + (BT_HDR*)osi_malloc(AVRC_PACKET_LEN + offset_len + BT_HDR_SIZE); + if (p_start != NULL) { + p_fcb->frag_enabled = true; + p_fcb->p_fmsg = p_pkt; + p_fcb->frag_pdu = *p_start; + p_pkt = p_pkt_new; + p_pkt_new = p_fcb->p_fmsg; + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = p_pkt_new->offset; + p_pkt->layer_specific = p_pkt_new->layer_specific; + p_pkt->event = p_pkt_new->event; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_start -= AVRC_VENDOR_HDR_SIZE; + memcpy(p_data, p_start, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC start packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_START; - /* Send the message */ - status = AVCT_MsgReq( handle, label, cr, p_pkt); - if ((status == AVCT_SUCCESS) && (cr == AVCT_CMD)) - { - /* If a command was successfully sent, indicate that a response is pending */ - avrc_cb.ccb_int[handle].flags |= AVRC_CB_FLAGS_RSP_PENDING; - - /* Start command timer to wait for response */ - avrc_start_cmd_timer(handle, label, msg_mask); - } + /* 4 pdu, pkt_type & len */ + len = (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - + AVRC_MIN_META_HDR_SIZE); + UINT16_TO_BE_STREAM(p_data, len); - return status; + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag(handle); + AVRC_TRACE_DEBUG("%s p_pkt len:%d/%d, next len:%d", __func__, + p_pkt->len, len, p_fcb->p_fmsg->len); + } else { + /* TODO: Is this "else" block valid? Remove it? */ + AVRC_TRACE_ERROR("%s no buffers for fragmentation", __func__); + osi_free(p_pkt); + return AVRC_NO_RESOURCES; + } + } + } else if ((p_pkt->event == AVRC_OP_VENDOR) && (cr == AVCT_CMD) && + (avrc_cb.ccb_int[handle].flags & AVRC_CB_FLAGS_RSP_PENDING) && + !(msg_mask & AVRC_MSG_MASK_IS_CONTINUATION_RSP)) { + /* If we are sending a vendor specific command, and a response is pending, + * then enqueue the command until the response has been received. + * This is to interop with TGs that abort sending responses whenever a new + * command + * is received (exception is continuation request command + * must sent that to get additional response frags) */ + AVRC_TRACE_DEBUG( + "AVRC: Enqueuing command 0x%08x (handle=0x%02x, label=0x%02x)", p_pkt, + handle, label); + + /* label in BT_HDR (will need this later when the command is dequeued) */ + p_pkt->layer_specific = (label << 8) | (p_pkt->layer_specific & 0xFF); + + /* Enqueue the command */ + fixed_queue_enqueue(avrc_cb.ccb_int[handle].cmd_q, p_pkt); + return AVRC_SUCCESS; + } + + /* Send the message */ + status = AVCT_MsgReq(handle, label, cr, p_pkt); + if ((status == AVCT_SUCCESS) && (cr == AVCT_CMD)) { + /* If a command was successfully sent, indicate that a response is pending + */ + avrc_cb.ccb_int[handle].flags |= AVRC_CB_FLAGS_RSP_PENDING; + + /* Start command timer to wait for response */ + avrc_start_cmd_timer(handle, label, msg_mask); + } + + return status; #else - return AVRC_NO_RESOURCES; + return AVRC_NO_RESOURCES; #endif } - /****************************************************************************** * * Function AVRC_PassCmd @@ -1394,25 +1313,21 @@ uint16_t AVRC_MsgReq (uint8_t handle, uint8_t label, uint8_t ctype, BT_HDR *p_pk * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_msg) -{ - BT_HDR *p_buf; - uint16_t status = AVRC_NO_RESOURCES; - if (!p_msg) - return AVRC_BAD_PARAM; - - p_msg->hdr.ctype = AVRC_CMD_CTRL; - p_buf = avrc_pass_msg(p_msg); - if (p_buf) - { - status = AVCT_MsgReq( handle, label, AVCT_CMD, p_buf); - if (status == AVCT_SUCCESS) - { - /* Start command timer to wait for response */ - avrc_start_cmd_timer(handle, label, 0); - } +uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, tAVRC_MSG_PASS* p_msg) { + BT_HDR* p_buf; + uint16_t status = AVRC_NO_RESOURCES; + if (!p_msg) return AVRC_BAD_PARAM; + + p_msg->hdr.ctype = AVRC_CMD_CTRL; + p_buf = avrc_pass_msg(p_msg); + if (p_buf) { + status = AVCT_MsgReq(handle, label, AVCT_CMD, p_buf); + if (status == AVCT_SUCCESS) { + /* Start command timer to wait for response */ + avrc_start_cmd_timer(handle, label, 0); } - return (status); + } + return (status); } /****************************************************************************** @@ -1441,15 +1356,11 @@ uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_msg) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_PassRsp(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_msg) -{ - BT_HDR *p_buf; - if (!p_msg) - return AVRC_BAD_PARAM; - - p_buf = avrc_pass_msg(p_msg); - if (p_buf) - return AVCT_MsgReq( handle, label, AVCT_RSP, p_buf); - return AVRC_NO_RESOURCES; -} +uint16_t AVRC_PassRsp(uint8_t handle, uint8_t label, tAVRC_MSG_PASS* p_msg) { + BT_HDR* p_buf; + if (!p_msg) return AVRC_BAD_PARAM; + p_buf = avrc_pass_msg(p_msg); + if (p_buf) return AVCT_MsgReq(handle, label, AVCT_RSP, p_buf); + return AVRC_NO_RESOURCES; +} diff --git a/stack/avrc/avrc_bld_ct.cc b/stack/avrc/avrc_bld_ct.cc index 916b770af..6e3642105 100644 --- a/stack/avrc/avrc_bld_ct.cc +++ b/stack/avrc/avrc_bld_ct.cc @@ -17,16 +17,15 @@ ******************************************************************************/ #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_defs.h" #include "avrc_int.h" +#include "bt_common.h" /***************************************************************************** * Global data ****************************************************************************/ - #if (AVRC_METADATA_INCLUDED == TRUE) /******************************************************************************* * @@ -38,22 +37,21 @@ * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_next_cmd (tAVRC_NEXT_CMD *p_cmd, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; +static tAVRC_STS avrc_bld_next_cmd(tAVRC_NEXT_CMD* p_cmd, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; - AVRC_TRACE_API("avrc_bld_next_cmd"); + AVRC_TRACE_API("avrc_bld_next_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed lenth 1 - pdu_id (1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_cmd->target_pdu); - p_pkt->len = (p_data - p_start); + /* add fixed lenth 1 - pdu_id (1) */ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, p_cmd->target_pdu); + p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; + return AVRC_STS_NO_ERROR; } /***************************************************************************** @@ -71,19 +69,19 @@ static tAVRC_STS avrc_bld_next_cmd (tAVRC_NEXT_CMD *p_cmd, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_abs_volume_cmd (tAVRC_SET_VOLUME_CMD *p_cmd, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - - AVRC_TRACE_API("avrc_bld_set_abs_volume_cmd"); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed lenth 1 - volume (1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_cmd->volume)); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_abs_volume_cmd(tAVRC_SET_VOLUME_CMD* p_cmd, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + + AVRC_TRACE_API("avrc_bld_set_abs_volume_cmd"); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed lenth 1 - volume (1) */ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_cmd->volume)); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -96,21 +94,21 @@ static tAVRC_STS avrc_bld_set_abs_volume_cmd (tAVRC_SET_VOLUME_CMD *p_cmd, BT_HD * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_register_notifn(BT_HDR * p_pkt, uint8_t event_id, uint32_t event_param) -{ - uint8_t *p_data, *p_start; - - AVRC_TRACE_API("avrc_bld_register_notifn"); - /* get the existing length, if any, and also the num attributes */ - // Set the notify value - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 5 -*/ - UINT16_TO_BE_STREAM(p_data, 5); - UINT8_TO_BE_STREAM(p_data,event_id); - UINT32_TO_BE_STREAM(p_data, event_param); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_register_notifn(BT_HDR* p_pkt, uint8_t event_id, + uint32_t event_param) { + uint8_t *p_data, *p_start; + + AVRC_TRACE_API("avrc_bld_register_notifn"); + /* get the existing length, if any, and also the num attributes */ + // Set the notify value + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 5 -*/ + UINT16_TO_BE_STREAM(p_data, 5); + UINT8_TO_BE_STREAM(p_data, event_id); + UINT32_TO_BE_STREAM(p_data, event_param); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } #endif @@ -124,16 +122,15 @@ static tAVRC_STS avrc_bld_register_notifn(BT_HDR * p_pkt, uint8_t event_id, uint * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_capability_cmd(BT_HDR * p_pkt, uint8_t cap_id) -{ - AVRC_TRACE_API("avrc_bld_get_capability_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 1 -*/ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data,cap_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_capability_cmd(BT_HDR* p_pkt, uint8_t cap_id) { + AVRC_TRACE_API("avrc_bld_get_capability_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 1 -*/ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, cap_id); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -146,15 +143,14 @@ static tAVRC_STS avrc_bld_get_capability_cmd(BT_HDR * p_pkt, uint8_t cap_id) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_list_player_app_attr_cmd(BT_HDR * p_pkt) -{ - AVRC_TRACE_API("avrc_bld_list_player_app_attr_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 1 -*/ - UINT16_TO_BE_STREAM(p_data, 0); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_list_player_app_attr_cmd(BT_HDR* p_pkt) { + AVRC_TRACE_API("avrc_bld_list_player_app_attr_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 1 -*/ + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -167,16 +163,16 @@ static tAVRC_STS avrc_bld_list_player_app_attr_cmd(BT_HDR * p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_list_player_app_values_cmd(BT_HDR * p_pkt, uint8_t attrib_id) -{ - AVRC_TRACE_API("avrc_bld_list_player_app_values_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 1 -*/ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data,attrib_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_list_player_app_values_cmd(BT_HDR* p_pkt, + uint8_t attrib_id) { + AVRC_TRACE_API("avrc_bld_list_player_app_values_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 1 -*/ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, attrib_id); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -191,21 +187,20 @@ static tAVRC_STS avrc_bld_list_player_app_values_cmd(BT_HDR * p_pkt, uint8_t att * ******************************************************************************/ static tAVRC_STS avrc_bld_get_current_player_app_values_cmd( - BT_HDR * p_pkt, uint8_t num_attrib_id, uint8_t* attrib_ids) -{ - AVRC_TRACE_API("avrc_bld_get_current_player_app_values_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - uint8_t param_len = num_attrib_id + 1; // 1 additional to hold num attributes feild - /* add length -*/ - UINT16_TO_BE_STREAM(p_data, param_len); - UINT8_TO_BE_STREAM(p_data,num_attrib_id); - for(int count = 0; count < num_attrib_id; count ++) - { - UINT8_TO_BE_STREAM(p_data,attrib_ids[count]); - } - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; + BT_HDR* p_pkt, uint8_t num_attrib_id, uint8_t* attrib_ids) { + AVRC_TRACE_API("avrc_bld_get_current_player_app_values_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + uint8_t param_len = + num_attrib_id + 1; // 1 additional to hold num attributes feild + /* add length -*/ + UINT16_TO_BE_STREAM(p_data, param_len); + UINT8_TO_BE_STREAM(p_data, num_attrib_id); + for (int count = 0; count < num_attrib_id; count++) { + UINT8_TO_BE_STREAM(p_data, attrib_ids[count]); + } + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -219,25 +214,24 @@ static tAVRC_STS avrc_bld_get_current_player_app_values_cmd( * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_current_player_app_values_cmd(BT_HDR * p_pkt, uint8_t num_attrib_id, tAVRC_APP_SETTING* p_val) -{ - AVRC_TRACE_API("avrc_bld_set_current_player_app_values_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* we have to store attrib- value pair - * 1 additional to store num elements - */ - uint8_t param_len = (2*num_attrib_id) + 1; - /* add length */ - UINT16_TO_BE_STREAM(p_data, param_len); - UINT8_TO_BE_STREAM(p_data,num_attrib_id); - for(int count = 0; count < num_attrib_id; count ++) - { - UINT8_TO_BE_STREAM(p_data,p_val[count].attr_id); - UINT8_TO_BE_STREAM(p_data,p_val[count].attr_val); - } - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_current_player_app_values_cmd( + BT_HDR* p_pkt, uint8_t num_attrib_id, tAVRC_APP_SETTING* p_val) { + AVRC_TRACE_API("avrc_bld_set_current_player_app_values_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* we have to store attrib- value pair + * 1 additional to store num elements + */ + uint8_t param_len = (2 * num_attrib_id) + 1; + /* add length */ + UINT16_TO_BE_STREAM(p_data, param_len); + UINT8_TO_BE_STREAM(p_data, num_attrib_id); + for (int count = 0; count < num_attrib_id; count++) { + UINT8_TO_BE_STREAM(p_data, p_val[count].attr_id); + UINT8_TO_BE_STREAM(p_data, p_val[count].attr_val); + } + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -251,23 +245,22 @@ static tAVRC_STS avrc_bld_set_current_player_app_values_cmd(BT_HDR * p_pkt, uint * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_player_app_setting_attr_text_cmd (BT_HDR * p_pkt, tAVRC_GET_APP_ATTR_TXT_CMD *p_cmd) -{ - AVRC_TRACE_API("%s", __func__); - - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - - uint8_t param_len = p_cmd->num_attr + 1; - /* add length */ - UINT16_TO_BE_STREAM(p_data, param_len); - UINT8_TO_BE_STREAM(p_data, p_cmd->num_attr); - for(int count = 0; count < p_cmd->num_attr; count++) - { - UINT8_TO_BE_STREAM(p_data, p_cmd->attrs[count]); - } - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_player_app_setting_attr_text_cmd( + BT_HDR* p_pkt, tAVRC_GET_APP_ATTR_TXT_CMD* p_cmd) { + AVRC_TRACE_API("%s", __func__); + + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + + uint8_t param_len = p_cmd->num_attr + 1; + /* add length */ + UINT16_TO_BE_STREAM(p_data, param_len); + UINT8_TO_BE_STREAM(p_data, p_cmd->num_attr); + for (int count = 0; count < p_cmd->num_attr; count++) { + UINT8_TO_BE_STREAM(p_data, p_cmd->attrs[count]); + } + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -281,23 +274,22 @@ static tAVRC_STS avrc_bld_get_player_app_setting_attr_text_cmd (BT_HDR * p_pkt, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_player_app_setting_value_text_cmd (BT_HDR * p_pkt, tAVRC_GET_APP_VAL_TXT_CMD *p_cmd) -{ - AVRC_TRACE_API("%s", __func__); - - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - - uint8_t param_len = p_cmd->num_val + 1; - /* add length */ - UINT16_TO_BE_STREAM(p_data, param_len); - UINT8_TO_BE_STREAM(p_data, p_cmd->num_val); - for(int count = 0; count < p_cmd->num_val; count++) - { - UINT8_TO_BE_STREAM(p_data, p_cmd->vals[count]); - } - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_player_app_setting_value_text_cmd( + BT_HDR* p_pkt, tAVRC_GET_APP_VAL_TXT_CMD* p_cmd) { + AVRC_TRACE_API("%s", __func__); + + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + + uint8_t param_len = p_cmd->num_val + 1; + /* add length */ + UINT16_TO_BE_STREAM(p_data, param_len); + UINT8_TO_BE_STREAM(p_data, p_cmd->num_val); + for (int count = 0; count < p_cmd->num_val; count++) { + UINT8_TO_BE_STREAM(p_data, p_cmd->vals[count]); + } + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -310,27 +302,27 @@ static tAVRC_STS avrc_bld_get_player_app_setting_value_text_cmd (BT_HDR * p_pkt, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_element_attr_cmd(BT_HDR * p_pkt, uint8_t num_attrib, uint32_t* attrib_ids) -{ - AVRC_TRACE_API("avrc_bld_get_element_attr_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* we have to store attrib- value pair - * 1 additional to store num elements - */ - uint8_t param_len = (4*num_attrib) + 9; - /* add length */ - UINT16_TO_BE_STREAM(p_data, param_len); - /* 8 bytes of identifier as 0 (playing)*/ - UINT32_TO_BE_STREAM(p_data,0); - UINT32_TO_BE_STREAM(p_data,0); - UINT8_TO_BE_STREAM(p_data,num_attrib); - for(int count = 0; count < num_attrib; count ++) - { - UINT32_TO_BE_STREAM(p_data,attrib_ids[count]); - } - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_element_attr_cmd(BT_HDR* p_pkt, + uint8_t num_attrib, + uint32_t* attrib_ids) { + AVRC_TRACE_API("avrc_bld_get_element_attr_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* we have to store attrib- value pair + * 1 additional to store num elements + */ + uint8_t param_len = (4 * num_attrib) + 9; + /* add length */ + UINT16_TO_BE_STREAM(p_data, param_len); + /* 8 bytes of identifier as 0 (playing)*/ + UINT32_TO_BE_STREAM(p_data, 0); + UINT32_TO_BE_STREAM(p_data, 0); + UINT8_TO_BE_STREAM(p_data, num_attrib); + for (int count = 0; count < num_attrib; count++) { + UINT32_TO_BE_STREAM(p_data, attrib_ids[count]); + } + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -343,22 +335,21 @@ static tAVRC_STS avrc_bld_get_element_attr_cmd(BT_HDR * p_pkt, uint8_t num_attri * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_play_item_cmd( - BT_HDR * p_pkt, uint8_t scope, uint8_t *uid, uint16_t uid_counter) -{ - AVRC_TRACE_API("avrc_bld_get_element_attr_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 11 */ - UINT16_TO_BE_STREAM(p_data, 0xb); - /* Add scope */ - UINT8_TO_BE_STREAM(p_data, scope); - /* Add UID */ - ARRAY_TO_BE_STREAM(p_data, uid, AVRC_UID_SIZE); - /* Add UID Counter */ - UINT16_TO_BE_STREAM(p_data, uid_counter); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_play_item_cmd(BT_HDR* p_pkt, uint8_t scope, + uint8_t* uid, uint16_t uid_counter) { + AVRC_TRACE_API("avrc_bld_get_element_attr_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 11 */ + UINT16_TO_BE_STREAM(p_data, 0xb); + /* Add scope */ + UINT8_TO_BE_STREAM(p_data, scope); + /* Add UID */ + ARRAY_TO_BE_STREAM(p_data, uid, AVRC_UID_SIZE); + /* Add UID Counter */ + UINT16_TO_BE_STREAM(p_data, uid_counter); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -371,15 +362,14 @@ static tAVRC_STS avrc_bld_play_item_cmd( * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_play_status_cmd(BT_HDR * p_pkt) -{ - AVRC_TRACE_API("avrc_bld_list_player_app_attr_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - /* add fixed length 0 -*/ - UINT16_TO_BE_STREAM(p_data, 0); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_play_status_cmd(BT_HDR* p_pkt) { + AVRC_TRACE_API("avrc_bld_list_player_app_attr_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + /* add fixed length 0 -*/ + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -392,25 +382,26 @@ static tAVRC_STS avrc_bld_get_play_status_cmd(BT_HDR * p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_folder_items_cmd(BT_HDR *p_pkt, const tAVRC_GET_ITEMS_CMD *cmd) -{ - AVRC_TRACE_API("avrc_bld_get_folder_items_cmd scope %d, start_item %d, end_item %d", - cmd->scope, cmd->start_item, cmd->end_item); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* This is where the PDU specific for AVRC starts - * AVRCP Spec 1.4 section 22.19 */ - uint8_t *p_data = p_start + 1; /* pdu */ - - /* To get the list of all media players we simply need to use the predefined - * PDU mentioned in above spec. */ - /* scope (1) + st item (4) + end item (4) + attr (1) */ - UINT16_TO_BE_STREAM(p_data, 10); - UINT8_TO_BE_STREAM(p_data, cmd->scope); /* scope (1bytes) */ - UINT32_TO_BE_STREAM(p_data, cmd->start_item); /* start item (4bytes) */ - UINT32_TO_BE_STREAM(p_data, cmd->end_item); /* end item (4bytes) */ - UINT8_TO_BE_STREAM(p_data, 0); /* attribute count = 0 (1bytes) */ - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_folder_items_cmd(BT_HDR* p_pkt, + const tAVRC_GET_ITEMS_CMD* cmd) { + AVRC_TRACE_API( + "avrc_bld_get_folder_items_cmd scope %d, start_item %d, end_item %d", + cmd->scope, cmd->start_item, cmd->end_item); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* This is where the PDU specific for AVRC starts + * AVRCP Spec 1.4 section 22.19 */ + uint8_t* p_data = p_start + 1; /* pdu */ + + /* To get the list of all media players we simply need to use the predefined + * PDU mentioned in above spec. */ + /* scope (1) + st item (4) + end item (4) + attr (1) */ + UINT16_TO_BE_STREAM(p_data, 10); + UINT8_TO_BE_STREAM(p_data, cmd->scope); /* scope (1bytes) */ + UINT32_TO_BE_STREAM(p_data, cmd->start_item); /* start item (4bytes) */ + UINT32_TO_BE_STREAM(p_data, cmd->end_item); /* end item (4bytes) */ + UINT8_TO_BE_STREAM(p_data, 0); /* attribute count = 0 (1bytes) */ + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -423,23 +414,23 @@ static tAVRC_STS avrc_bld_get_folder_items_cmd(BT_HDR *p_pkt, const tAVRC_GET_IT * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_change_folder_cmd(BT_HDR *p_pkt, const tAVRC_CHG_PATH_CMD *cmd) -{ - AVRC_TRACE_API("avrc_bld_change_folder_cmd"); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* This is where the PDU specific for AVRC starts - * AVRCP Spec 1.4 section 22.19 */ - uint8_t *p_data = p_start + 1; /* pdu */ - - /* To change folder we need to provide the following: - * UID Counter (2) + Direction (1) + UID (8) = 11bytes - */ - UINT16_TO_BE_STREAM(p_data, 11); - UINT16_TO_BE_STREAM(p_data, cmd->uid_counter); - UINT8_TO_BE_STREAM(p_data, cmd->direction); - ARRAY_TO_BE_STREAM(p_data, cmd->folder_uid, AVRC_UID_SIZE); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_change_folder_cmd(BT_HDR* p_pkt, + const tAVRC_CHG_PATH_CMD* cmd) { + AVRC_TRACE_API("avrc_bld_change_folder_cmd"); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* This is where the PDU specific for AVRC starts + * AVRCP Spec 1.4 section 22.19 */ + uint8_t* p_data = p_start + 1; /* pdu */ + + /* To change folder we need to provide the following: + * UID Counter (2) + Direction (1) + UID (8) = 11bytes + */ + UINT16_TO_BE_STREAM(p_data, 11); + UINT16_TO_BE_STREAM(p_data, cmd->uid_counter); + UINT8_TO_BE_STREAM(p_data, cmd->direction); + ARRAY_TO_BE_STREAM(p_data, cmd->folder_uid, AVRC_UID_SIZE); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -452,21 +443,21 @@ static tAVRC_STS avrc_bld_change_folder_cmd(BT_HDR *p_pkt, const tAVRC_CHG_PATH_ * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_browsed_player_cmd(BT_HDR *p_pkt, const tAVRC_SET_BR_PLAYER_CMD *cmd) -{ - AVRC_TRACE_API("%s", __func__); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* This is where the PDU specific for AVRC starts - * AVRCP Spec 1.4 section 22.19 */ - uint8_t *p_data = p_start + 1; /* pdu */ - - /* To change browsed player the following is the total length: - * Player ID (2) - */ - UINT16_TO_BE_STREAM(p_data, 2); /* fixed length */ - UINT16_TO_BE_STREAM(p_data, cmd->player_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_browsed_player_cmd( + BT_HDR* p_pkt, const tAVRC_SET_BR_PLAYER_CMD* cmd) { + AVRC_TRACE_API("%s", __func__); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* This is where the PDU specific for AVRC starts + * AVRCP Spec 1.4 section 22.19 */ + uint8_t* p_data = p_start + 1; /* pdu */ + + /* To change browsed player the following is the total length: + * Player ID (2) + */ + UINT16_TO_BE_STREAM(p_data, 2); /* fixed length */ + UINT16_TO_BE_STREAM(p_data, cmd->player_id); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -480,20 +471,19 @@ static tAVRC_STS avrc_bld_set_browsed_player_cmd(BT_HDR *p_pkt, const tAVRC_SET_ * ******************************************************************************/ static tAVRC_STS avrc_bld_set_addressed_player_cmd( - BT_HDR *p_pkt, const tAVRC_SET_ADDR_PLAYER_CMD *cmd) -{ - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = p_data = p_start + 2; /* pdu + rsvd */ - - /* To change addressed player the following is the total length: - * Player ID (2) - */ - UINT16_TO_BE_STREAM(p_data, 2); /* fixed length */ - UINT16_TO_BE_STREAM(p_data, cmd->player_id); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; + BT_HDR* p_pkt, const tAVRC_SET_ADDR_PLAYER_CMD* cmd) { + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = p_data = p_start + 2; /* pdu + rsvd */ + + /* To change addressed player the following is the total length: + * Player ID (2) + */ + UINT16_TO_BE_STREAM(p_data, 2); /* fixed length */ + UINT16_TO_BE_STREAM(p_data, cmd->player_id); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -507,57 +497,55 @@ static tAVRC_STS avrc_bld_set_addressed_player_cmd( * message. * ******************************************************************************/ -static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd) -{ - uint16_t chnl = AVCT_DATA_CTRL; - uint8_t opcode = avrc_opcode_from_pdu(p_cmd->pdu); - AVRC_TRACE_API("avrc_bld_init_cmd_buffer: pdu=%x, opcode=%x", p_cmd->pdu, opcode); - - uint16_t offset = 0; - switch (opcode) - { +static BT_HDR* avrc_bld_init_cmd_buffer(tAVRC_COMMAND* p_cmd) { + uint16_t chnl = AVCT_DATA_CTRL; + uint8_t opcode = avrc_opcode_from_pdu(p_cmd->pdu); + AVRC_TRACE_API("avrc_bld_init_cmd_buffer: pdu=%x, opcode=%x", p_cmd->pdu, + opcode); + + uint16_t offset = 0; + switch (opcode) { case AVRC_OP_BROWSE: - chnl = AVCT_DATA_BROWSE; - offset = AVCT_BROWSE_OFFSET; - break; + chnl = AVCT_DATA_BROWSE; + offset = AVCT_BROWSE_OFFSET; + break; case AVRC_OP_PASS_THRU: - offset = AVRC_MSG_PASS_THRU_OFFSET; - break; + offset = AVRC_MSG_PASS_THRU_OFFSET; + break; case AVRC_OP_VENDOR: - offset = AVRC_MSG_VENDOR_OFFSET; - break; - } + offset = AVRC_MSG_VENDOR_OFFSET; + break; + } - /* allocate and initialize the buffer */ - BT_HDR *p_pkt = (BT_HDR *)osi_malloc(AVRC_META_CMD_BUF_SIZE); - uint8_t *p_data, *p_start; + /* allocate and initialize the buffer */ + BT_HDR* p_pkt = (BT_HDR*)osi_malloc(AVRC_META_CMD_BUF_SIZE); + uint8_t *p_data, *p_start; - p_pkt->layer_specific = chnl; - p_pkt->event = opcode; - p_pkt->offset = offset; - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_start = p_data; + p_pkt->layer_specific = chnl; + p_pkt->event = opcode; + p_pkt->offset = offset; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_start = p_data; - /* pass thru - group navigation - has a two byte op_id, so dont do it here */ - if (opcode != AVRC_OP_PASS_THRU) - *p_data++ = p_cmd->pdu; + /* pass thru - group navigation - has a two byte op_id, so dont do it here */ + if (opcode != AVRC_OP_PASS_THRU) *p_data++ = p_cmd->pdu; - switch (opcode) { + switch (opcode) { case AVRC_OP_VENDOR: - /* reserved 0, packet_type 0 */ - UINT8_TO_BE_STREAM(p_data, 0); - /* continue to the next "case to add length */ - /* add fixed lenth - 0 */ - UINT16_TO_BE_STREAM(p_data, 0); - break; - } - - p_pkt->len = (p_data - p_start); - p_cmd->cmd.opcode = opcode; - - return p_pkt; + /* reserved 0, packet_type 0 */ + UINT8_TO_BE_STREAM(p_data, 0); + /* continue to the next "case to add length */ + /* add fixed lenth - 0 */ + UINT16_TO_BE_STREAM(p_data, 0); + break; + } + + p_pkt->len = (p_data - p_start); + p_cmd->cmd.opcode = opcode; + + return p_pkt; } /******************************************************************************* @@ -571,104 +559,106 @@ static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd) * Otherwise, the error code. * ******************************************************************************/ -tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt) -{ - tAVRC_STS status = AVRC_STS_BAD_PARAM; - bool alloc = false; - AVRC_TRACE_API("AVRC_BldCommand: pdu=%x status=%x", p_cmd->cmd.pdu, p_cmd->cmd.status); - if (!p_cmd || !pp_pkt) - { - AVRC_TRACE_API("AVRC_BldCommand. Invalid parameters passed. p_cmd=%p, pp_pkt=%p", - p_cmd, pp_pkt); - return AVRC_STS_BAD_PARAM; - } - - if (*pp_pkt == NULL) - { - *pp_pkt = avrc_bld_init_cmd_buffer(p_cmd); - if (*pp_pkt == NULL) - { - AVRC_TRACE_API("AVRC_BldCommand: Failed to initialize command buffer"); - return AVRC_STS_INTERNAL_ERR; - } - alloc = true; +tAVRC_STS AVRC_BldCommand(tAVRC_COMMAND* p_cmd, BT_HDR** pp_pkt) { + tAVRC_STS status = AVRC_STS_BAD_PARAM; + bool alloc = false; + AVRC_TRACE_API("AVRC_BldCommand: pdu=%x status=%x", p_cmd->cmd.pdu, + p_cmd->cmd.status); + if (!p_cmd || !pp_pkt) { + AVRC_TRACE_API( + "AVRC_BldCommand. Invalid parameters passed. p_cmd=%p, pp_pkt=%p", + p_cmd, pp_pkt); + return AVRC_STS_BAD_PARAM; + } + + if (*pp_pkt == NULL) { + *pp_pkt = avrc_bld_init_cmd_buffer(p_cmd); + if (*pp_pkt == NULL) { + AVRC_TRACE_API("AVRC_BldCommand: Failed to initialize command buffer"); + return AVRC_STS_INTERNAL_ERR; } - status = AVRC_STS_NO_ERROR; - BT_HDR* p_pkt = *pp_pkt; - - switch (p_cmd->pdu) - { - case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - status = avrc_bld_next_cmd(&p_cmd->continu, p_pkt); - break; - - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - status = avrc_bld_next_cmd(&p_cmd->abort, p_pkt); - break; + alloc = true; + } + status = AVRC_STS_NO_ERROR; + BT_HDR* p_pkt = *pp_pkt; + + switch (p_cmd->pdu) { + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + status = avrc_bld_next_cmd(&p_cmd->continu, p_pkt); + break; + + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + status = avrc_bld_next_cmd(&p_cmd->abort, p_pkt); + break; #if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - status = avrc_bld_set_abs_volume_cmd(&p_cmd->volume, p_pkt); - break; + case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ + status = avrc_bld_set_abs_volume_cmd(&p_cmd->volume, p_pkt); + break; #endif - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ #if (AVRC_ADV_CTRL_INCLUDED == TRUE) - status=avrc_bld_register_notifn(p_pkt,p_cmd->reg_notif.event_id,p_cmd->reg_notif.param); + status = avrc_bld_register_notifn(p_pkt, p_cmd->reg_notif.event_id, + p_cmd->reg_notif.param); #endif - break; + break; case AVRC_PDU_GET_CAPABILITIES: - status = avrc_bld_get_capability_cmd(p_pkt, p_cmd->get_caps.capability_id); - break; + status = + avrc_bld_get_capability_cmd(p_pkt, p_cmd->get_caps.capability_id); + break; case AVRC_PDU_LIST_PLAYER_APP_ATTR: - status = avrc_bld_list_player_app_attr_cmd(p_pkt); - break; + status = avrc_bld_list_player_app_attr_cmd(p_pkt); + break; case AVRC_PDU_LIST_PLAYER_APP_VALUES: - status = avrc_bld_list_player_app_values_cmd(p_pkt,p_cmd->list_app_values.attr_id); - break; + status = avrc_bld_list_player_app_values_cmd( + p_pkt, p_cmd->list_app_values.attr_id); + break; case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: - status = avrc_bld_get_current_player_app_values_cmd(p_pkt, - p_cmd->get_cur_app_val.num_attr,p_cmd->get_cur_app_val.attrs); - break; + status = avrc_bld_get_current_player_app_values_cmd( + p_pkt, p_cmd->get_cur_app_val.num_attr, p_cmd->get_cur_app_val.attrs); + break; case AVRC_PDU_SET_PLAYER_APP_VALUE: - status = avrc_bld_set_current_player_app_values_cmd(p_pkt, - p_cmd->set_app_val.num_val,p_cmd->set_app_val.p_vals); - break; + status = avrc_bld_set_current_player_app_values_cmd( + p_pkt, p_cmd->set_app_val.num_val, p_cmd->set_app_val.p_vals); + break; case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: - avrc_bld_get_player_app_setting_attr_text_cmd(p_pkt, &p_cmd->get_app_attr_txt); - break; + avrc_bld_get_player_app_setting_attr_text_cmd(p_pkt, + &p_cmd->get_app_attr_txt); + break; case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: - avrc_bld_get_player_app_setting_value_text_cmd(p_pkt, &p_cmd->get_app_val_txt); - break; + avrc_bld_get_player_app_setting_value_text_cmd(p_pkt, + &p_cmd->get_app_val_txt); + break; case AVRC_PDU_GET_ELEMENT_ATTR: - status = avrc_bld_get_element_attr_cmd(p_pkt, - p_cmd->get_elem_attrs.num_attr,p_cmd->get_elem_attrs.attrs); - break; + status = avrc_bld_get_element_attr_cmd( + p_pkt, p_cmd->get_elem_attrs.num_attr, p_cmd->get_elem_attrs.attrs); + break; case AVRC_PDU_PLAY_ITEM: - status = avrc_bld_play_item_cmd( - p_pkt, p_cmd->play_item.scope, p_cmd->play_item.uid, p_cmd->play_item.uid_counter); - break; + status = avrc_bld_play_item_cmd(p_pkt, p_cmd->play_item.scope, + p_cmd->play_item.uid, + p_cmd->play_item.uid_counter); + break; case AVRC_PDU_GET_PLAY_STATUS: - status = avrc_bld_get_play_status_cmd(p_pkt); - break; + status = avrc_bld_get_play_status_cmd(p_pkt); + break; case AVRC_PDU_GET_FOLDER_ITEMS: - status = avrc_bld_get_folder_items_cmd(p_pkt, &(p_cmd->get_items)); - break; + status = avrc_bld_get_folder_items_cmd(p_pkt, &(p_cmd->get_items)); + break; case AVRC_PDU_CHANGE_PATH: - status = avrc_bld_change_folder_cmd(p_pkt, &(p_cmd->chg_path)); - break; + status = avrc_bld_change_folder_cmd(p_pkt, &(p_cmd->chg_path)); + break; case AVRC_PDU_SET_BROWSED_PLAYER: - status = avrc_bld_set_browsed_player_cmd(p_pkt, &(p_cmd->br_player)); - break; + status = avrc_bld_set_browsed_player_cmd(p_pkt, &(p_cmd->br_player)); + break; case AVRC_PDU_SET_ADDRESSED_PLAYER: - status = avrc_bld_set_addressed_player_cmd(p_pkt, &(p_cmd->addr_player)); - break; - } - - if (alloc && (status != AVRC_STS_NO_ERROR) ) - { - osi_free(p_pkt); - *pp_pkt = NULL; - } - AVRC_TRACE_API("AVRC_BldCommand: returning %d", status); - return status; + status = avrc_bld_set_addressed_player_cmd(p_pkt, &(p_cmd->addr_player)); + break; + } + + if (alloc && (status != AVRC_STS_NO_ERROR)) { + osi_free(p_pkt); + *pp_pkt = NULL; + } + AVRC_TRACE_API("AVRC_BldCommand: returning %d", status); + return status; } #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ diff --git a/stack/avrc/avrc_bld_tg.cc b/stack/avrc/avrc_bld_tg.cc index fa0d17515..746a954cd 100644 --- a/stack/avrc/avrc_bld_tg.cc +++ b/stack/avrc/avrc_bld_tg.cc @@ -18,10 +18,10 @@ #include #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_defs.h" #include "avrc_int.h" +#include "bt_common.h" #include "bt_utils.h" #include "osi/include/osi.h" @@ -29,14 +29,15 @@ * Global data ****************************************************************************/ #if (AVRC_METADATA_INCLUDED == TRUE) -#define AVRC_ITEM_PLAYER_IS_VALID(_p_player) ((_p_player)->name.p_str && \ - ((_p_player)->major_type & AVRC_MJ_TYPE_INVALID) == 0 && \ - ((_p_player)->sub_type & AVRC_SUB_TYPE_INVALID) == 0 && \ - (((_p_player)->play_status <= AVRC_PLAYSTATE_REV_SEEK) || \ - ((_p_player)->play_status == AVRC_PLAYSTATE_ERROR)) ) +#define AVRC_ITEM_PLAYER_IS_VALID(_p_player) \ + ((_p_player)->name.p_str && \ + ((_p_player)->major_type & AVRC_MJ_TYPE_INVALID) == 0 && \ + ((_p_player)->sub_type & AVRC_SUB_TYPE_INVALID) == 0 && \ + (((_p_player)->play_status <= AVRC_PLAYSTATE_REV_SEEK) || \ + ((_p_player)->play_status == AVRC_PLAYSTATE_ERROR))) - /* 17 = item_type(1) + item len(2) + min item (14) */ -#define AVRC_MIN_LEN_GET_FOLDER_ITEMS_RSP 17 +/* 17 = item_type(1) + item len(2) + min item (14) */ +#define AVRC_MIN_LEN_GET_FOLDER_ITEMS_RSP 17 /******************************************************************************* * @@ -48,71 +49,61 @@ * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len, *p_count; - uint16_t len = 0; - uint8_t xx; - uint32_t *p_company_id; - uint8_t *p_event_id; - tAVRC_STS status = AVRC_STS_NO_ERROR; - - if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id))) - { - AVRC_TRACE_ERROR("%s bad parameter. p_rsp: %x", __func__, p_rsp); - status = AVRC_STS_BAD_PARAM; - return status; - } - - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - UINT8_TO_BE_STREAM(p_data, p_rsp->capability_id); - p_count = p_data; - - if (len == 0) - { - *p_count = p_rsp->count; - p_data++; - len = 2; /* move past the capability_id and count */ - } - else - { - p_data = p_start + p_pkt->len; - *p_count += p_rsp->count; - } - - if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) - { - p_company_id = p_rsp->param.company_id; - for (xx=0; xx< p_rsp->count; xx++) - { - UINT24_TO_BE_STREAM(p_data, p_company_id[xx]); - } - len += p_rsp->count * 3; +static tAVRC_STS avrc_bld_get_capability_rsp(tAVRC_GET_CAPS_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len, *p_count; + uint16_t len = 0; + uint8_t xx; + uint32_t* p_company_id; + uint8_t* p_event_id; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id))) { + AVRC_TRACE_ERROR("%s bad parameter. p_rsp: %x", __func__, p_rsp); + status = AVRC_STS_BAD_PARAM; + return status; + } + + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + UINT8_TO_BE_STREAM(p_data, p_rsp->capability_id); + p_count = p_data; + + if (len == 0) { + *p_count = p_rsp->count; + p_data++; + len = 2; /* move past the capability_id and count */ + } else { + p_data = p_start + p_pkt->len; + *p_count += p_rsp->count; + } + + if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) { + p_company_id = p_rsp->param.company_id; + for (xx = 0; xx < p_rsp->count; xx++) { + UINT24_TO_BE_STREAM(p_data, p_company_id[xx]); } - else - { - p_event_id = p_rsp->param.event_id; - *p_count = 0; - for (xx=0; xx< p_rsp->count; xx++) - { - if (AVRC_IS_VALID_EVENT_ID(p_event_id[xx])) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_event_id[xx]); - } - } - len += (*p_count); + len += p_rsp->count * 3; + } else { + p_event_id = p_rsp->param.event_id; + *p_count = 0; + for (xx = 0; xx < p_rsp->count; xx++) { + if (AVRC_IS_VALID_EVENT_ID(p_event_id[xx])) { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_event_id[xx]); + } } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - status = AVRC_STS_NO_ERROR; + len += (*p_count); + } + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + status = AVRC_STS_NO_ERROR; - return status; + return status; } /******************************************************************************* @@ -126,45 +117,39 @@ static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_attr_rsp (tAVRC_LIST_APP_ATTR_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len, *p_num; - uint16_t len = 0; - uint8_t xx; - - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_num = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; +static tAVRC_STS avrc_bld_list_app_settings_attr_rsp( + tAVRC_LIST_APP_ATTR_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len, *p_num; + uint16_t len = 0; + uint8_t xx; + + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + if (len == 0) { + /* first time initialize the attribute count */ + *p_num = 0; + p_data++; + } else { + p_data = p_start + p_pkt->len; + } + + for (xx = 0; xx < p_rsp->num_attr; xx++) { + if (AVRC_IsValidPlayerAttr(p_rsp->attrs[xx])) { + (*p_num)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->attrs[xx]); } + } - for (xx=0; xxnum_attr; xx++) - { - if(AVRC_IsValidPlayerAttr(p_rsp->attrs[xx])) - { - (*p_num)++; - UINT8_TO_BE_STREAM(p_data, p_rsp->attrs[xx]); - } - } + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); - len = *p_num + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -178,43 +163,37 @@ static tAVRC_STS avrc_bld_list_app_settings_attr_rsp (tAVRC_LIST_APP_ATTR_RSP *p * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_list_app_settings_values_rsp (tAVRC_LIST_APP_VALUES_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len, *p_num; - uint8_t xx; - uint16_t len; - - AVRC_TRACE_API("%s", __func__); - - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - /* get the existing length, if any, and also the num attributes */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data; - /* first time initialize the attribute count */ - if (len == 0) - { - *p_num = p_rsp->num_val; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; - *p_num += p_rsp->num_val; - } - - - for (xx=0; xxnum_val; xx++) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->vals[xx]); - } - - len = *p_num + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_list_app_settings_values_rsp( + tAVRC_LIST_APP_VALUES_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len, *p_num; + uint8_t xx; + uint16_t len; + + AVRC_TRACE_API("%s", __func__); + + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + /* get the existing length, if any, and also the num attributes */ + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + /* first time initialize the attribute count */ + if (len == 0) { + *p_num = p_rsp->num_val; + p_data++; + } else { + p_data = p_start + p_pkt->len; + *p_num += p_rsp->num_val; + } + + for (xx = 0; xx < p_rsp->num_val; xx++) { + UINT8_TO_BE_STREAM(p_data, p_rsp->vals[xx]); + } + + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -228,52 +207,45 @@ static tAVRC_STS avrc_bld_list_app_settings_values_rsp (tAVRC_LIST_APP_VALUES_RS * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp (tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len, *p_count; - uint16_t len; - uint8_t xx; - - if (!p_rsp->p_vals) - { - AVRC_TRACE_ERROR("%s NULL parameter", __func__); - return AVRC_STS_BAD_PARAM; - } - - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - if (len == 0) - { - /* first time initialize the attribute count */ - *p_count = 0; - p_data++; - } - else - { - p_data = p_start + p_pkt->len; +static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp( + tAVRC_GET_CUR_APP_VALUE_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len, *p_count; + uint16_t len; + uint8_t xx; + + if (!p_rsp->p_vals) { + AVRC_TRACE_ERROR("%s NULL parameter", __func__); + return AVRC_STS_BAD_PARAM; + } + + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + if (len == 0) { + /* first time initialize the attribute count */ + *p_count = 0; + p_data++; + } else { + p_data = p_start + p_pkt->len; + } + + for (xx = 0; xx < p_rsp->num_val; xx++) { + if (avrc_is_valid_player_attrib_value(p_rsp->p_vals[xx].attr_id, + p_rsp->p_vals[xx].attr_val)) { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_val); } + } + len = ((*p_count) << 1) + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); - for (xx=0; xxnum_val; xx++) - { - if (avrc_is_valid_player_attrib_value(p_rsp->p_vals[xx].attr_id, - p_rsp->p_vals[xx].attr_val)) - { - (*p_count)++; - UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_id); - UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_val); - } - } - len = ((*p_count) << 1) + 1; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -287,12 +259,11 @@ static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp (tAVRC_GET_CUR_APP_VALUE * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_app_setting_value_rsp (UNUSED_ATTR tAVRC_RSP *p_rsp, - UNUSED_ATTR BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API("%s", __func__); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_app_setting_value_rsp( + UNUSED_ATTR tAVRC_RSP* p_rsp, UNUSED_ATTR BT_HDR* p_pkt) { + /* nothing to be added. */ + AVRC_TRACE_API("%s", __func__); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -306,70 +277,63 @@ static tAVRC_STS avrc_bld_set_app_setting_value_rsp (UNUSED_ATTR tAVRC_RSP *p_rs * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len, *p_count; - uint16_t len, len_left; - uint8_t xx; - tAVRC_STS sts = AVRC_STS_NO_ERROR; - uint8_t num_added = 0; - - if (!p_rsp->p_attrs) - { - AVRC_TRACE_ERROR("%s NULL parameter", __func__); - return AVRC_STS_BAD_PARAM; - } - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - - /* - * NOTE: The buffer is allocated within avrc_bld_init_rsp_buffer(), and is - * always of size BT_DEFAULT_BUFFER_SIZE. - */ - len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; - - BE_STREAM_TO_UINT16(len, p_data); - p_count = p_data; - - if (len == 0) - { - *p_count = 0; - p_data++; +static tAVRC_STS avrc_bld_app_setting_text_rsp( + tAVRC_GET_APP_ATTR_TXT_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len, *p_count; + uint16_t len, len_left; + uint8_t xx; + tAVRC_STS sts = AVRC_STS_NO_ERROR; + uint8_t num_added = 0; + + if (!p_rsp->p_attrs) { + AVRC_TRACE_ERROR("%s NULL parameter", __func__); + return AVRC_STS_BAD_PARAM; + } + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + /* + * NOTE: The buffer is allocated within avrc_bld_init_rsp_buffer(), and is + * always of size BT_DEFAULT_BUFFER_SIZE. + */ + len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + + if (len == 0) { + *p_count = 0; + p_data++; + } else { + p_data = p_start + p_pkt->len; + } + + for (xx = 0; xx < p_rsp->num_attr; xx++) { + if (len_left < (p_rsp->p_attrs[xx].str_len + 4)) { + AVRC_TRACE_ERROR("%s out of room (str_len:%d, left:%d)", __func__, xx, + p_rsp->p_attrs[xx].str_len, len_left); + p_rsp->num_attr = num_added; + sts = AVRC_STS_INTERNAL_ERR; + break; } - else - { - p_data = p_start + p_pkt->len; + if (!p_rsp->p_attrs[xx].str_len || !p_rsp->p_attrs[xx].p_str) { + AVRC_TRACE_ERROR("%s NULL attr text[%d]", __func__, xx); + continue; } - - for (xx=0; xxnum_attr; xx++) - { - if (len_left < (p_rsp->p_attrs[xx].str_len + 4)) - { - AVRC_TRACE_ERROR("%s out of room (str_len:%d, left:%d)", - __func__, xx, p_rsp->p_attrs[xx].str_len, len_left); - p_rsp->num_attr = num_added; - sts = AVRC_STS_INTERNAL_ERR; - break; - } - if ( !p_rsp->p_attrs[xx].str_len || !p_rsp->p_attrs[xx].p_str ) - { - AVRC_TRACE_ERROR("%s NULL attr text[%d]", __func__, xx); - continue; - } - UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].charset_id); - UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].str_len); - ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].p_str, p_rsp->p_attrs[xx].str_len); - (*p_count)++; - num_added++; - } - len = p_data - p_count; - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - - return sts; + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].charset_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].str_len); + ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].p_str, + p_rsp->p_attrs[xx].str_len); + (*p_count)++; + num_added++; + } + len = p_data - p_count; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return sts; } /******************************************************************************* @@ -383,11 +347,10 @@ static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rs * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, - BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp( + tAVRC_GET_APP_ATTR_TXT_RSP* p_rsp, BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); } /******************************************************************************* @@ -401,11 +364,10 @@ static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp (tAVRC_GET_APP_ATTR_TXT_ * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, - BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp( + tAVRC_GET_APP_ATTR_TXT_RSP* p_rsp, BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); } /******************************************************************************* @@ -419,12 +381,11 @@ static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp (tAVRC_GET_APP_ATTR_TXT * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_inform_charset_rsp (UNUSED_ATTR tAVRC_RSP *p_rsp, - UNUSED_ATTR BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API("%s", __func__); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_inform_charset_rsp(UNUSED_ATTR tAVRC_RSP* p_rsp, + UNUSED_ATTR BT_HDR* p_pkt) { + /* nothing to be added. */ + AVRC_TRACE_API("%s", __func__); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -438,12 +399,11 @@ static tAVRC_STS avrc_bld_inform_charset_rsp (UNUSED_ATTR tAVRC_RSP *p_rsp, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_inform_battery_status_rsp (UNUSED_ATTR tAVRC_RSP *p_rsp, - UNUSED_ATTR BT_HDR *p_pkt) -{ - /* nothing to be added. */ - AVRC_TRACE_API("%s", __func__); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_inform_battery_status_rsp( + UNUSED_ATTR tAVRC_RSP* p_rsp, UNUSED_ATTR BT_HDR* p_pkt) { + /* nothing to be added. */ + AVRC_TRACE_API("%s", __func__); + return AVRC_STS_NO_ERROR; } static void avrc_build_attribute_entries(int num_attrs, @@ -451,44 +411,45 @@ static void avrc_build_attribute_entries(int num_attrs, int remaining_buffer_capacity, uint8_t** pp_data, uint8_t* p_attribute_count) { - AVRC_TRACE_DEBUG("%s num_attrs: %d, remaining_buffer_capacity: %d", - __func__, num_attrs, remaining_buffer_capacity); - uint8_t* p_data = *pp_data; - /* Fill in the Attribute ID, Character Set, Length and Values */ - for (int index = 0; index < num_attrs; index++) { - AVRC_TRACE_DEBUG("%s attr id[%d]: %d", - __func__, index, p_attrs[index].attr_id); - assert(AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_attrs[index].attr_id)); - if (!p_attrs[index].name.p_str) { - p_attrs[index].name.str_len = 0; - } - /* 8 is the size of attr_id, char set and str_len */ - remaining_buffer_capacity -= 8; - if (remaining_buffer_capacity < 0) { - AVRC_TRACE_WARNING( - "%s not enough buffer space for attr_id[%d]: %d," - " skipping %d attributes", - __func__, index, p_attrs[index].attr_id, num_attrs - index); - break; - } - if (remaining_buffer_capacity < p_attrs[index].name.str_len) { - AVRC_TRACE_WARNING("%s not enough buffer space for attr_id[%d]: %d," - " truncating attribute", - __func__, index, p_attrs[index].attr_id); - p_attrs[index].name.str_len = remaining_buffer_capacity; - remaining_buffer_capacity = 0; - } - remaining_buffer_capacity -= p_attrs[index].name.str_len; - UINT32_TO_BE_STREAM(p_data, p_attrs[index].attr_id); - UINT16_TO_BE_STREAM(p_data, p_attrs[index].name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_attrs[index].name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_attrs[index].name.p_str, - p_attrs[index].name.str_len); - (*p_attribute_count)++; + AVRC_TRACE_DEBUG("%s num_attrs: %d, remaining_buffer_capacity: %d", __func__, + num_attrs, remaining_buffer_capacity); + uint8_t* p_data = *pp_data; + /* Fill in the Attribute ID, Character Set, Length and Values */ + for (int index = 0; index < num_attrs; index++) { + AVRC_TRACE_DEBUG("%s attr id[%d]: %d", __func__, index, + p_attrs[index].attr_id); + assert(AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_attrs[index].attr_id)); + if (!p_attrs[index].name.p_str) { + p_attrs[index].name.str_len = 0; + } + /* 8 is the size of attr_id, char set and str_len */ + remaining_buffer_capacity -= 8; + if (remaining_buffer_capacity < 0) { + AVRC_TRACE_WARNING( + "%s not enough buffer space for attr_id[%d]: %d," + " skipping %d attributes", + __func__, index, p_attrs[index].attr_id, num_attrs - index); + break; } - *pp_data = p_data; - AVRC_TRACE_DEBUG("%s filled attributes, remaining_buffer_capacity: %d", - __func__, num_attrs, remaining_buffer_capacity); + if (remaining_buffer_capacity < p_attrs[index].name.str_len) { + AVRC_TRACE_WARNING( + "%s not enough buffer space for attr_id[%d]: %d," + " truncating attribute", + __func__, index, p_attrs[index].attr_id); + p_attrs[index].name.str_len = remaining_buffer_capacity; + remaining_buffer_capacity = 0; + } + remaining_buffer_capacity -= p_attrs[index].name.str_len; + UINT32_TO_BE_STREAM(p_data, p_attrs[index].attr_id); + UINT16_TO_BE_STREAM(p_data, p_attrs[index].name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_attrs[index].name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_attrs[index].name.p_str, + p_attrs[index].name.str_len); + (*p_attribute_count)++; + } + *pp_data = p_data; + AVRC_TRACE_DEBUG("%s filled attributes, remaining_buffer_capacity: %d", + __func__, num_attrs, remaining_buffer_capacity); } /******************************************************************************* @@ -502,53 +463,53 @@ static void avrc_build_attribute_entries(int num_attrs, ** Otherwise, the error code. ** *******************************************************************************/ -static tAVRC_STS avrc_bld_get_elem_attrs_rsp (tAVRC_GET_ATTRS_RSP *p_rsp, - BT_HDR *p_pkt) { - AVRC_TRACE_API("%s", __func__); - if (!p_rsp->p_attrs) { - AVRC_TRACE_ERROR("%s NULL p_attrs", __func__); - return AVRC_STS_BAD_PARAM; - } - /* Figure out how much we have left in current buffer */ - int remaining_buffer_capacity = BT_DEFAULT_BUFFER_SIZE - - BT_HDR_SIZE - p_pkt->offset; - if (remaining_buffer_capacity < 5) { - AVRC_TRACE_ERROR("%s not enough buffer for packet header", - remaining_buffer_capacity); - return AVRC_STS_INTERNAL_ERR; - } - /* Get to the beginning of PDU */ - uint8_t *p_pdu_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* Skip PDU ID and Reserved byte to get pointer to Parameter Length */ - uint8_t *p_data, *p_parameter_len; - p_data = p_parameter_len = p_pdu_start + 2; - /* Parse parameter length */ - uint16_t parameter_len; - BE_STREAM_TO_UINT16(parameter_len, p_data); - /* Get pointer to Attribute Count */ - uint8_t *p_attribute_count = p_data; - /* Initialize field values when Parameter Length is 0 */ - if (parameter_len == 0) { - *p_attribute_count = 0; - p_data++; - } else { - // TODO: Why do we need this case? - p_data = p_pdu_start + p_pkt->len; - } - remaining_buffer_capacity -= p_data - p_pdu_start;; - if (remaining_buffer_capacity < 0) { - AVRC_TRACE_ERROR("%s not enough buffer capacity for response"); - return AVRC_STS_BAD_PARAM; - } - /* Fill in the Attribute ID, Character Set, Length and Values */ - avrc_build_attribute_entries(p_rsp->num_attrs, - p_rsp->p_attrs, - remaining_buffer_capacity, - &p_data, p_attribute_count); - parameter_len = p_data - p_attribute_count; - UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); - p_pkt->len = (p_data - p_pdu_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_elem_attrs_rsp(tAVRC_GET_ATTRS_RSP* p_rsp, + BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + if (!p_rsp->p_attrs) { + AVRC_TRACE_ERROR("%s NULL p_attrs", __func__); + return AVRC_STS_BAD_PARAM; + } + /* Figure out how much we have left in current buffer */ + int remaining_buffer_capacity = + BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - p_pkt->offset; + if (remaining_buffer_capacity < 5) { + AVRC_TRACE_ERROR("%s not enough buffer for packet header", + remaining_buffer_capacity); + return AVRC_STS_INTERNAL_ERR; + } + /* Get to the beginning of PDU */ + uint8_t* p_pdu_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* Skip PDU ID and Reserved byte to get pointer to Parameter Length */ + uint8_t *p_data, *p_parameter_len; + p_data = p_parameter_len = p_pdu_start + 2; + /* Parse parameter length */ + uint16_t parameter_len; + BE_STREAM_TO_UINT16(parameter_len, p_data); + /* Get pointer to Attribute Count */ + uint8_t* p_attribute_count = p_data; + /* Initialize field values when Parameter Length is 0 */ + if (parameter_len == 0) { + *p_attribute_count = 0; + p_data++; + } else { + // TODO: Why do we need this case? + p_data = p_pdu_start + p_pkt->len; + } + remaining_buffer_capacity -= p_data - p_pdu_start; + ; + if (remaining_buffer_capacity < 0) { + AVRC_TRACE_ERROR("%s not enough buffer capacity for response"); + return AVRC_STS_BAD_PARAM; + } + /* Fill in the Attribute ID, Character Set, Length and Values */ + avrc_build_attribute_entries(p_rsp->num_attrs, p_rsp->p_attrs, + remaining_buffer_capacity, &p_data, + p_attribute_count); + parameter_len = p_data - p_attribute_count; + UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); + p_pkt->len = (p_data - p_pdu_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -562,23 +523,22 @@ static tAVRC_STS avrc_bld_get_elem_attrs_rsp (tAVRC_GET_ATTRS_RSP *p_rsp, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_play_status_rsp (tAVRC_GET_PLAY_STATUS_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - - AVRC_TRACE_API("%s", __func__); - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 2; - - /* add fixed lenth - song len(4) + song position(4) + status(1) */ - UINT16_TO_BE_STREAM(p_data, 9); - UINT32_TO_BE_STREAM(p_data, p_rsp->song_len); - UINT32_TO_BE_STREAM(p_data, p_rsp->song_pos); - UINT8_TO_BE_STREAM(p_data, p_rsp->play_status); - p_pkt->len = (p_data - p_start); - - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_get_play_status_rsp(tAVRC_GET_PLAY_STATUS_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + + AVRC_TRACE_API("%s", __func__); + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; + + /* add fixed lenth - song len(4) + song position(4) + status(1) */ + UINT16_TO_BE_STREAM(p_data, 9); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_len); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_pos); + UINT8_TO_BE_STREAM(p_data, p_rsp->play_status); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -591,135 +551,122 @@ static tAVRC_STS avrc_bld_get_play_status_rsp (tAVRC_GET_PLAY_STATUS_RSP *p_rsp, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_notify_rsp (tAVRC_REG_NOTIF_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - uint8_t *p_len; - uint16_t len = 0; - uint8_t xx; - tAVRC_STS status = AVRC_STS_NO_ERROR; - - AVRC_TRACE_API("%s event_id %d", __func__, p_rsp->event_id); - - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 2; /* pdu + rsvd */ - p_data += 2; - - UINT8_TO_BE_STREAM(p_data, p_rsp->event_id); - switch (p_rsp->event_id) - { - case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ - /* p_rsp->param.play_status >= AVRC_PLAYSTATE_STOPPED is always true */ - if ((p_rsp->param.play_status <= AVRC_PLAYSTATE_REV_SEEK) || - (p_rsp->param.play_status == AVRC_PLAYSTATE_ERROR) ) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.play_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR("%s bad play state", __func__); - status = AVRC_STS_BAD_PARAM; - } - break; - - case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ - ARRAY_TO_BE_STREAM(p_data, p_rsp->param.track, AVRC_UID_SIZE); - len = (uint8_t)(AVRC_UID_SIZE + 1); - break; +static tAVRC_STS avrc_bld_notify_rsp(tAVRC_REG_NOTIF_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + uint8_t* p_len; + uint16_t len = 0; + uint8_t xx; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + AVRC_TRACE_API("%s event_id %d", __func__, p_rsp->event_id); + + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + p_data += 2; + + UINT8_TO_BE_STREAM(p_data, p_rsp->event_id); + switch (p_rsp->event_id) { + case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ + /* p_rsp->param.play_status >= AVRC_PLAYSTATE_STOPPED is always true */ + if ((p_rsp->param.play_status <= AVRC_PLAYSTATE_REV_SEEK) || + (p_rsp->param.play_status == AVRC_PLAYSTATE_ERROR)) { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.play_status); + len = 2; + } else { + AVRC_TRACE_ERROR("%s bad play state", __func__); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ + ARRAY_TO_BE_STREAM(p_data, p_rsp->param.track, AVRC_UID_SIZE); + len = (uint8_t)(AVRC_UID_SIZE + 1); + break; + + case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ + case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ + case AVRC_EVT_NOW_PLAYING_CHANGE: /* 0x09 */ + case AVRC_EVT_AVAL_PLAYERS_CHANGE: /* 0x0a */ + len = 1; + break; + + case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ + UINT32_TO_BE_STREAM(p_data, p_rsp->param.play_pos); + len = 5; + break; + + case AVRC_EVT_BATTERY_STATUS_CHANGE: /* 0x06 */ + if (AVRC_IS_VALID_BATTERY_STATUS(p_rsp->param.battery_status)) { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.battery_status); + len = 2; + } else { + AVRC_TRACE_ERROR("%s bad battery status", __func__); + status = AVRC_STS_BAD_PARAM; + } + break; - case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ - case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ - case AVRC_EVT_NOW_PLAYING_CHANGE: /* 0x09 */ - case AVRC_EVT_AVAL_PLAYERS_CHANGE: /* 0x0a */ - len = 1; - break; + case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ + if (AVRC_IS_VALID_SYSTEM_STATUS(p_rsp->param.system_status)) { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.system_status); + len = 2; + } else { + AVRC_TRACE_ERROR("%s bad system status", __func__); + status = AVRC_STS_BAD_PARAM; + } + break; - case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ - UINT32_TO_BE_STREAM(p_data, p_rsp->param.play_pos); - len = 5; - break; + case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ + if (p_rsp->param.player_setting.num_attr > AVRC_MAX_APP_SETTINGS) + p_rsp->param.player_setting.num_attr = AVRC_MAX_APP_SETTINGS; - case AVRC_EVT_BATTERY_STATUS_CHANGE: /* 0x06 */ - if (AVRC_IS_VALID_BATTERY_STATUS(p_rsp->param.battery_status)) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.battery_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR("%s bad battery status", __func__); + if (p_rsp->param.player_setting.num_attr > 0) { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.num_attr); + len = 2; + for (xx = 0; xx < p_rsp->param.player_setting.num_attr; xx++) { + if (avrc_is_valid_player_attrib_value( + p_rsp->param.player_setting.attr_id[xx], + p_rsp->param.player_setting.attr_value[xx])) { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_id[xx]); + UINT8_TO_BE_STREAM(p_data, + p_rsp->param.player_setting.attr_value[xx]); + } else { + AVRC_TRACE_ERROR("%s bad player app seeting attribute or value", + __func__); status = AVRC_STS_BAD_PARAM; + break; + } + len += 2; } - break; + } else + status = AVRC_STS_BAD_PARAM; + break; - case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ - if (AVRC_IS_VALID_SYSTEM_STATUS(p_rsp->param.system_status)) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.system_status); - len = 2; - } - else - { - AVRC_TRACE_ERROR("%s bad system status", __func__); - status = AVRC_STS_BAD_PARAM; - } - break; + case AVRC_EVT_VOLUME_CHANGE: /* 0x0d */ + len = 2; + UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_rsp->param.volume)); + break; - case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ - if (p_rsp->param.player_setting.num_attr > AVRC_MAX_APP_SETTINGS) - p_rsp->param.player_setting.num_attr = AVRC_MAX_APP_SETTINGS; - - if (p_rsp->param.player_setting.num_attr > 0) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.num_attr); - len = 2; - for (xx=0; xxparam.player_setting.num_attr; xx++) - { - if (avrc_is_valid_player_attrib_value(p_rsp->param.player_setting.attr_id[xx], - p_rsp->param.player_setting.attr_value[xx])) - { - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_id[xx]); - UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_value[xx]); - } - else - { - AVRC_TRACE_ERROR("%s bad player app seeting attribute or value", __func__); - status = AVRC_STS_BAD_PARAM; - break; - } - len += 2; - } - } - else - status = AVRC_STS_BAD_PARAM; - break; + case AVRC_EVT_ADDR_PLAYER_CHANGE: /* 0x0b */ + UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.player_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.uid_counter); + len = 5; + break; - case AVRC_EVT_VOLUME_CHANGE: /* 0x0d */ - len = 2; - UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_rsp->param.volume)); - break; - - case AVRC_EVT_ADDR_PLAYER_CHANGE: /* 0x0b */ - UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.player_id); - UINT16_TO_BE_STREAM(p_data, p_rsp->param.addr_player.uid_counter); - len = 5; - break; - - case AVRC_EVT_UIDS_CHANGE: /* 0x0c */ - UINT16_TO_BE_STREAM(p_data, p_rsp->param.uid_counter); /* uid counter */ - len = 3; - break; + case AVRC_EVT_UIDS_CHANGE: /* 0x0c */ + UINT16_TO_BE_STREAM(p_data, p_rsp->param.uid_counter); /* uid counter */ + len = 3; + break; default: - status = AVRC_STS_BAD_PARAM; - AVRC_TRACE_ERROR("%s unknown event_id", __func__); - } + status = AVRC_STS_BAD_PARAM; + AVRC_TRACE_ERROR("%s unknown event_id", __func__); + } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); - return status; + return status; } /******************************************************************************* @@ -733,16 +680,15 @@ static tAVRC_STS avrc_bld_notify_rsp (tAVRC_REG_NOTIF_RSP *p_rsp, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_next_rsp (tAVRC_NEXT_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data = (p_start + 2); /* Skip the pdu and reserved bits */ +static tAVRC_STS avrc_bld_next_rsp(tAVRC_NEXT_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data = (p_start + 2); /* Skip the pdu and reserved bits */ - UINT16_TO_BE_STREAM(p_data, 0x0001); /* only one attribute to be sent */ - UINT8_TO_BE_STREAM(p_data, p_rsp->target_pdu); + UINT16_TO_BE_STREAM(p_data, 0x0001); /* only one attribute to be sent */ + UINT8_TO_BE_STREAM(p_data, p_rsp->target_pdu); - AVRC_TRACE_API("%s: target_pdu: 0x%02x", __func__, p_rsp->target_pdu); - return AVRC_STS_NO_ERROR; + AVRC_TRACE_API("%s: target_pdu: 0x%02x", __func__, p_rsp->target_pdu); + return AVRC_STS_NO_ERROR; } /***************************************************************************** @@ -754,17 +700,17 @@ static tAVRC_STS avrc_bld_next_rsp (tAVRC_NEXT_RSP *p_rsp, BT_HDR *p_pkt) * Returns AVRC_STS_NO_ERROR, if the response is build successfully * *****************************************************************************/ -static tAVRC_STS avrc_bld_set_absolute_volume_rsp(uint8_t abs_vol, BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* To calculate length */ - uint8_t *p_data = p_start + 2; - /* add fixed lenth status(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, abs_vol); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_absolute_volume_rsp(uint8_t abs_vol, + BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* To calculate length */ + uint8_t* p_data = p_start + 2; + /* add fixed lenth status(1) */ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, abs_vol); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -778,18 +724,16 @@ static tAVRC_STS avrc_bld_set_absolute_volume_rsp(uint8_t abs_vol, BT_HDR *p_pkt * Otherwise, the error code. * ******************************************************************************/ -tAVRC_STS avrc_bld_group_navigation_rsp (uint16_t navi_id, BT_HDR *p_pkt) -{ - if (!AVRC_IS_VALID_GROUP(navi_id)) - { - AVRC_TRACE_ERROR("%s bad navigation op id: %d", __func__, navi_id); - return AVRC_STS_BAD_PARAM; - } - AVRC_TRACE_API("%s", __func__); - uint8_t *p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - UINT16_TO_BE_STREAM(p_data, navi_id); - p_pkt->len = 2; - return AVRC_STS_NO_ERROR; +tAVRC_STS avrc_bld_group_navigation_rsp(uint16_t navi_id, BT_HDR* p_pkt) { + if (!AVRC_IS_VALID_GROUP(navi_id)) { + AVRC_TRACE_ERROR("%s bad navigation op id: %d", __func__, navi_id); + return AVRC_STS_BAD_PARAM; + } + AVRC_TRACE_API("%s", __func__); + uint8_t* p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + UINT16_TO_BE_STREAM(p_data, navi_id); + p_pkt->len = 2; + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -801,34 +745,31 @@ tAVRC_STS avrc_bld_group_navigation_rsp (uint16_t navi_id, BT_HDR *p_pkt) * Returns AVRC_STS_NO_ERROR, if the response is built successfully * ******************************************************************************/ -static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt ) -{ - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - uint8_t *p_data; - uint8_t opcode = p_rsp->opcode; - - AVRC_TRACE_API("%s: status=%d, pdu:x%x, opcode=%x", __func__, p_rsp->status, - p_rsp->pdu, opcode); - - if (opcode == AVRC_OP_BROWSE) - { - p_data = p_start + 1; - if ((AVRC_PDU_INVALID == *p_start) || (avrc_opcode_from_pdu(*p_start) != AVRC_OP_BROWSE)) - { - /* if invalid or the given opcode is not recognized as a browsing command opcode, */ - /* use general reject command */ - *p_start = AVRC_PDU_GENERAL_REJECT; - } - } - else - { - p_data = p_start + 2; +static tAVRC_STS avrc_bld_rejected_rsp(tAVRC_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + uint8_t* p_data; + uint8_t opcode = p_rsp->opcode; + + AVRC_TRACE_API("%s: status=%d, pdu:x%x, opcode=%x", __func__, p_rsp->status, + p_rsp->pdu, opcode); + + if (opcode == AVRC_OP_BROWSE) { + p_data = p_start + 1; + if ((AVRC_PDU_INVALID == *p_start) || + (avrc_opcode_from_pdu(*p_start) != AVRC_OP_BROWSE)) { + /* if invalid or the given opcode is not recognized as a browsing command + * opcode, */ + /* use general reject command */ + *p_start = AVRC_PDU_GENERAL_REJECT; } - AVRC_TRACE_DEBUG("%s pdu:x%x, Opcode:%x", __func__, *p_start,opcode); - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - p_pkt->len = p_data - p_start; - return AVRC_STS_NO_ERROR; + } else { + p_data = p_start + 2; + } + AVRC_TRACE_DEBUG("%s pdu:x%x, Opcode:%x", __func__, *p_start, opcode); + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + p_pkt->len = p_data - p_start; + return AVRC_STS_NO_ERROR; } /***************************************************************************** @@ -845,19 +786,18 @@ static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt ) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_ctrl_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - AVRC_TRACE_DEBUG("pdu:x%x", *p_start); - - /* To calculate length */ - uint8_t *p_data = p_start + 2; /* pdu + rsvd */ - - /* add fixed lenth - status(1) */ - UINT16_TO_BE_STREAM(p_data, 1); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_ctrl_status_rsp(tAVRC_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t* p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + AVRC_TRACE_DEBUG("pdu:x%x", *p_start); + + /* To calculate length */ + uint8_t* p_data = p_start + 2; /* pdu + rsvd */ + + /* add fixed lenth - status(1) */ + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -870,10 +810,9 @@ static tAVRC_STS avrc_bld_ctrl_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_addr_player_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); +static tAVRC_STS avrc_bld_set_addr_player_rsp(tAVRC_RSP* p_rsp, BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); } /******************************************************************************* @@ -888,65 +827,62 @@ static tAVRC_STS avrc_bld_set_addr_player_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_set_browsed_player_rsp (tAVRC_SET_BR_PLAYER_RSP *p_rsp, - BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - uint8_t *p_len; - uint16_t len; - tAVRC_NAME *p_folders = p_rsp->p_folders; - uint16_t len_left; - uint8_t *p_folder_depth; - uint16_t mtu; - - /* make sure the given buffer can accomodate this response */ - len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE; - p_data = (uint8_t *)(p_pkt + 1); - BE_STREAM_TO_UINT16 (mtu, p_data); - if (len_left > mtu) - { - len_left = mtu; - } - len_left = len_left - p_pkt->offset - p_pkt->len; - AVRC_TRACE_DEBUG("len_left:%d, mtu:%d ", len_left, mtu); - - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* the existing len */ - BE_STREAM_TO_UINT16(len, p_data); - /* find the position to add the folder depth. - * 9 is sizeof (status + uid_counter + num_items + charset_id) */ - p_folder_depth = p_data + 9; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - UINT16_TO_BE_STREAM(p_data, p_rsp->charset_id); - *p_folder_depth = 0; - p_data++; - len = 10; - /* assuming that we would never use a buffer that is too small for headers */ - len_left -= 12; - } - else - { - p_data = p_start + p_pkt->len; - } - - for (uint8_t xx = 0; (xx < p_rsp->folder_depth) && (len_left > (p_folders[xx].str_len + 2)); xx++) - { - (*p_folder_depth)++; - UINT16_TO_BE_STREAM(p_data, p_folders[xx].str_len); - ARRAY_TO_BE_STREAM(p_data, p_folders[xx].p_str, p_folders[xx].str_len); - len += (p_folders[xx].str_len + 2); - } - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_set_browsed_player_rsp(tAVRC_SET_BR_PLAYER_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + uint8_t* p_len; + uint16_t len; + tAVRC_NAME* p_folders = p_rsp->p_folders; + uint16_t len_left; + uint8_t* p_folder_depth; + uint16_t mtu; + + /* make sure the given buffer can accomodate this response */ + len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE; + p_data = (uint8_t*)(p_pkt + 1); + BE_STREAM_TO_UINT16(mtu, p_data); + if (len_left > mtu) { + len_left = mtu; + } + len_left = len_left - p_pkt->offset - p_pkt->len; + AVRC_TRACE_DEBUG("len_left:%d, mtu:%d ", len_left, mtu); + + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 1; /* pdu */ + + /* the existing len */ + BE_STREAM_TO_UINT16(len, p_data); + /* find the position to add the folder depth. + * 9 is sizeof (status + uid_counter + num_items + charset_id) */ + p_folder_depth = p_data + 9; + if (len == 0) { + /* first time initialize the attribute count */ + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); + UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); + UINT16_TO_BE_STREAM(p_data, p_rsp->charset_id); + *p_folder_depth = 0; + p_data++; + len = 10; + /* assuming that we would never use a buffer that is too small for headers + */ + len_left -= 12; + } else { + p_data = p_start + p_pkt->len; + } + + for (uint8_t xx = 0; + (xx < p_rsp->folder_depth) && (len_left > (p_folders[xx].str_len + 2)); + xx++) { + (*p_folder_depth)++; + UINT16_TO_BE_STREAM(p_data, p_folders[xx].str_len); + ARRAY_TO_BE_STREAM(p_data, p_folders[xx].p_str, p_folders[xx].str_len); + len += (p_folders[xx].str_len + 2); + } + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -966,209 +902,189 @@ static tAVRC_STS avrc_bld_set_browsed_player_rsp (tAVRC_SET_BR_PLAYER_RSP *p_rsp * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_folder_items_rsp (tAVRC_GET_ITEMS_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - uint8_t *p_len, xx; - uint16_t len; - uint16_t item_len; - uint8_t *p_item_len, yy; - tAVRC_ITEM_PLAYER *p_player; - tAVRC_ITEM_FOLDER *p_folder; - tAVRC_ITEM_MEDIA *p_media; - tAVRC_ATTR_ENTRY *p_attr; - tAVRC_ITEM *p_item_list = p_rsp->p_item_list; - tAVRC_STS status = AVRC_STS_NO_ERROR; - uint16_t len_left; - uint8_t *p_num, *p; - uint8_t *p_item_start, *p_attr_count; - uint16_t item_count; - uint16_t mtu; - bool multi_items_add_fail = FALSE; - AVRC_TRACE_API("%s", __func__); - - /* make sure the given buffer can accomodate this response */ - len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE; - p = (uint8_t *)(p_pkt + 1); - BE_STREAM_TO_UINT16 (mtu, p); - if (len_left > mtu) - len_left = mtu; - len_left = len_left - p_pkt->offset - p_pkt->len; - - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* the existing len */ - BE_STREAM_TO_UINT16(len, p_data); - p_num = p_data + 3; - if (len == 0) - { - /* first time initialize the attribute count */ - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - item_count = 0; - p_data += 2; - len = 5; - len_left -= 5; - } - else - { - p_data = p_start + p_pkt->len; - p = p_num; - BE_STREAM_TO_UINT16 (item_count, p); - } - AVRC_TRACE_DEBUG("len:%d, len_left:%d, num:%d", len, len_left, item_count); - - /* min len required = item_type(1) + item len(2) + min item (14) = 17 */ - for (xx = 0; xx < p_rsp->item_count && len_left > AVRC_MIN_LEN_GET_FOLDER_ITEMS_RSP && multi_items_add_fail == FALSE; xx++) - { - p_item_start = p_data; - UINT8_TO_BE_STREAM(p_data, p_item_list[xx].item_type); - /* variable item lenth - save the location to add length */ - p_item_len = p_data; - p_data += 2; - item_len = 0; - len_left -= 3; /* item_type(1) + item len(2) */ - switch (p_item_list[xx].item_type) - { - case AVRC_ITEM_PLAYER: - /* min len required: 2 + 1 + 4 + 1 + 16 + 2 + 2 = 30 + str_len */ - p_player = &p_item_list[xx].u.player; - item_len = AVRC_FEATURE_MASK_SIZE + p_player->name.str_len + 12; - - if ((len_left <= item_len) || AVRC_ITEM_PLAYER_IS_VALID(p_player) == false) - { - p_data = p_item_start; - } - else - { - UINT16_TO_BE_STREAM(p_data, p_player->player_id); - UINT8_TO_BE_STREAM(p_data, p_player->major_type); - UINT32_TO_BE_STREAM(p_data, p_player->sub_type); - UINT8_TO_BE_STREAM(p_data, p_player->play_status); - ARRAY_TO_BE_STREAM(p_data, p_player->features, AVRC_FEATURE_MASK_SIZE); - UINT16_TO_BE_STREAM(p_data, p_player->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_player->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_player->name.p_str, p_player->name.str_len); - } - break; +static tAVRC_STS avrc_bld_get_folder_items_rsp(tAVRC_GET_ITEMS_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + uint8_t *p_len, xx; + uint16_t len; + uint16_t item_len; + uint8_t *p_item_len, yy; + tAVRC_ITEM_PLAYER* p_player; + tAVRC_ITEM_FOLDER* p_folder; + tAVRC_ITEM_MEDIA* p_media; + tAVRC_ATTR_ENTRY* p_attr; + tAVRC_ITEM* p_item_list = p_rsp->p_item_list; + tAVRC_STS status = AVRC_STS_NO_ERROR; + uint16_t len_left; + uint8_t *p_num, *p; + uint8_t *p_item_start, *p_attr_count; + uint16_t item_count; + uint16_t mtu; + bool multi_items_add_fail = FALSE; + AVRC_TRACE_API("%s", __func__); + + /* make sure the given buffer can accomodate this response */ + len_left = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE; + p = (uint8_t*)(p_pkt + 1); + BE_STREAM_TO_UINT16(mtu, p); + if (len_left > mtu) len_left = mtu; + len_left = len_left - p_pkt->offset - p_pkt->len; + + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 1; /* pdu */ + + /* the existing len */ + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data + 3; + if (len == 0) { + /* first time initialize the attribute count */ + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); + item_count = 0; + p_data += 2; + len = 5; + len_left -= 5; + } else { + p_data = p_start + p_pkt->len; + p = p_num; + BE_STREAM_TO_UINT16(item_count, p); + } + AVRC_TRACE_DEBUG("len:%d, len_left:%d, num:%d", len, len_left, item_count); + + /* min len required = item_type(1) + item len(2) + min item (14) = 17 */ + for (xx = 0; + xx < p_rsp->item_count && len_left > AVRC_MIN_LEN_GET_FOLDER_ITEMS_RSP && + multi_items_add_fail == FALSE; + xx++) { + p_item_start = p_data; + UINT8_TO_BE_STREAM(p_data, p_item_list[xx].item_type); + /* variable item lenth - save the location to add length */ + p_item_len = p_data; + p_data += 2; + item_len = 0; + len_left -= 3; /* item_type(1) + item len(2) */ + switch (p_item_list[xx].item_type) { + case AVRC_ITEM_PLAYER: + /* min len required: 2 + 1 + 4 + 1 + 16 + 2 + 2 = 30 + str_len */ + p_player = &p_item_list[xx].u.player; + item_len = AVRC_FEATURE_MASK_SIZE + p_player->name.str_len + 12; + + if ((len_left <= item_len) || + AVRC_ITEM_PLAYER_IS_VALID(p_player) == false) { + p_data = p_item_start; + } else { + UINT16_TO_BE_STREAM(p_data, p_player->player_id); + UINT8_TO_BE_STREAM(p_data, p_player->major_type); + UINT32_TO_BE_STREAM(p_data, p_player->sub_type); + UINT8_TO_BE_STREAM(p_data, p_player->play_status); + ARRAY_TO_BE_STREAM(p_data, p_player->features, + AVRC_FEATURE_MASK_SIZE); + UINT16_TO_BE_STREAM(p_data, p_player->name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_player->name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_player->name.p_str, + p_player->name.str_len); + } + break; - case AVRC_ITEM_FOLDER: - /* min len required: 8 + 1 + 1 + 2 + 2 = 14 + str_len */ - p_folder = &p_item_list[xx].u.folder; - item_len = AVRC_UID_SIZE + p_folder->name.str_len + 6; - - if ((len_left > item_len) && - p_folder->name.p_str && - p_folder->type <= AVRC_FOLDER_TYPE_YEARS) - { - ARRAY_TO_BE_STREAM(p_data, p_folder->uid, AVRC_UID_SIZE); - UINT8_TO_BE_STREAM(p_data, p_folder->type); - UINT8_TO_BE_STREAM(p_data, p_folder->playable); - UINT16_TO_BE_STREAM(p_data, p_folder->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_folder->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_folder->name.p_str, p_folder->name.str_len); - } - else - { - p_data = p_item_start; - } - break; + case AVRC_ITEM_FOLDER: + /* min len required: 8 + 1 + 1 + 2 + 2 = 14 + str_len */ + p_folder = &p_item_list[xx].u.folder; + item_len = AVRC_UID_SIZE + p_folder->name.str_len + 6; + + if ((len_left > item_len) && p_folder->name.p_str && + p_folder->type <= AVRC_FOLDER_TYPE_YEARS) { + ARRAY_TO_BE_STREAM(p_data, p_folder->uid, AVRC_UID_SIZE); + UINT8_TO_BE_STREAM(p_data, p_folder->type); + UINT8_TO_BE_STREAM(p_data, p_folder->playable); + UINT16_TO_BE_STREAM(p_data, p_folder->name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_folder->name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_folder->name.p_str, + p_folder->name.str_len); + } else { + p_data = p_item_start; + } + break; - case AVRC_ITEM_MEDIA: - /* min len required: 8 + 1 + 2 + 2 + 1 = 14 + str_len */ - p_media = &p_item_list[xx].u.media; - item_len = AVRC_UID_SIZE + p_media->name.str_len + 6; - - if ((len_left >= item_len) && - p_media->name.p_str && - p_media->type <= AVRC_MEDIA_TYPE_VIDEO) - { - ARRAY_TO_BE_STREAM(p_data, p_media->uid, AVRC_UID_SIZE); - UINT8_TO_BE_STREAM(p_data, p_media->type); - UINT16_TO_BE_STREAM(p_data, p_media->name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_media->name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_media->name.p_str, p_media->name.str_len); - p_attr_count = p_data++; - *p_attr_count = 0; - len_left -= item_len; - if (p_media->attr_count > 0) - { - p_attr = p_media->p_attr_list; - for (yy = 0; yy < p_media->attr_count; yy++) - { - if (p_attr[yy].name.p_str && - AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_attr[yy].attr_id) && - (len_left >= (p_attr[yy].name.str_len + 8)) ) - { - (*p_attr_count) ++; - UINT32_TO_BE_STREAM(p_data, p_attr[yy].attr_id); - UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.charset_id); - UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.str_len); - ARRAY_TO_BE_STREAM(p_data, p_attr[yy].name.p_str, - p_attr[yy].name.str_len); - item_len += (p_attr[yy].name.str_len + 8); - len_left -= (p_attr[yy].name.str_len + 8); - } - else if ((len_left < (p_attr[yy].name.str_len + 8)) && item_count > 0) - { - p_data = p_item_start; - multi_items_add_fail = TRUE; - break; - } - } - } - } - else - { - if (len_left < item_len && item_count > 0) - multi_items_add_fail = TRUE; + case AVRC_ITEM_MEDIA: + /* min len required: 8 + 1 + 2 + 2 + 1 = 14 + str_len */ + p_media = &p_item_list[xx].u.media; + item_len = AVRC_UID_SIZE + p_media->name.str_len + 6; + + if ((len_left >= item_len) && p_media->name.p_str && + p_media->type <= AVRC_MEDIA_TYPE_VIDEO) { + ARRAY_TO_BE_STREAM(p_data, p_media->uid, AVRC_UID_SIZE); + UINT8_TO_BE_STREAM(p_data, p_media->type); + UINT16_TO_BE_STREAM(p_data, p_media->name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_media->name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_media->name.p_str, + p_media->name.str_len); + p_attr_count = p_data++; + *p_attr_count = 0; + len_left -= item_len; + if (p_media->attr_count > 0) { + p_attr = p_media->p_attr_list; + for (yy = 0; yy < p_media->attr_count; yy++) { + if (p_attr[yy].name.p_str && + AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_attr[yy].attr_id) && + (len_left >= (p_attr[yy].name.str_len + 8))) { + (*p_attr_count)++; + UINT32_TO_BE_STREAM(p_data, p_attr[yy].attr_id); + UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_attr[yy].name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_attr[yy].name.p_str, + p_attr[yy].name.str_len); + item_len += (p_attr[yy].name.str_len + 8); + len_left -= (p_attr[yy].name.str_len + 8); + } else if ((len_left < (p_attr[yy].name.str_len + 8)) && + item_count > 0) { p_data = p_item_start; + multi_items_add_fail = TRUE; + break; + } } - break; - } /* switch item_type */ - - if (p_item_start != p_data) - { - /* successfully added the item */ - item_count++; - /* fill in variable item lenth */ - UINT16_TO_BE_STREAM(p_item_len, item_len); + } + } else { + if (len_left < item_len && item_count > 0) + multi_items_add_fail = TRUE; + p_data = p_item_start; } + break; + } /* switch item_type */ + + if (p_item_start != p_data) { + /* successfully added the item */ + item_count++; + /* fill in variable item lenth */ + UINT16_TO_BE_STREAM(p_item_len, item_len); + } else { + if (multi_items_add_fail == FALSE) { + /* some item is not added properly - set an error status */ + if (len_left < item_len) + status = AVRC_STS_INTERNAL_ERR; else - { - if (multi_items_add_fail == FALSE) - { - /* some item is not added properly - set an error status */ - if (len_left < item_len) - status = AVRC_STS_INTERNAL_ERR; - else - status = AVRC_STS_BAD_PARAM; - } - } - if (multi_items_add_fail == FALSE) - { - len += item_len; - len += 3; /* the item_type(1) and item_len(2) */ - } - AVRC_TRACE_DEBUG("len:%d, len_left:%d, num:%d, item_len:%d", - len, len_left, item_count, item_len); - } /* for item_count */ + status = AVRC_STS_BAD_PARAM; + } + } + if (multi_items_add_fail == FALSE) { + len += item_len; + len += 3; /* the item_type(1) and item_len(2) */ + } + AVRC_TRACE_DEBUG("len:%d, len_left:%d, num:%d, item_len:%d", len, len_left, + item_count, item_len); + } /* for item_count */ - UINT16_TO_BE_STREAM(p_num, item_count); - UINT16_TO_BE_STREAM(p_len, len); - p_pkt->len = (p_data - p_start); + UINT16_TO_BE_STREAM(p_num, item_count); + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); - if (p_rsp->item_count != xx) - { - p_rsp->item_count = xx; - AVRC_TRACE_DEBUG("xx value = 0x%02X", xx); - if (status == AVRC_STS_NO_ERROR) - status = AVRC_STS_INTERNAL_ERR; - } + if (p_rsp->item_count != xx) { + p_rsp->item_count = xx; + AVRC_TRACE_DEBUG("xx value = 0x%02X", xx); + if (status == AVRC_STS_NO_ERROR) status = AVRC_STS_INTERNAL_ERR; + } - return status; + return status; } /******************************************************************************* @@ -1183,19 +1099,19 @@ static tAVRC_STS avrc_bld_get_folder_items_rsp (tAVRC_GET_ITEMS_RSP *p_rsp, BT_H * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_change_path_rsp (tAVRC_CHG_PATH_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start; - - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_start + 1; /* pdu */ - /* add fixed length - status(1) + num_items(4) */ - UINT16_TO_BE_STREAM(p_data, 5); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_change_path_rsp(tAVRC_CHG_PATH_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start; + + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 1; /* pdu */ + /* add fixed length - status(1) + num_items(4) */ + UINT16_TO_BE_STREAM(p_data, 5); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -1213,67 +1129,66 @@ static tAVRC_STS avrc_bld_change_path_rsp (tAVRC_CHG_PATH_RSP *p_rsp, BT_HDR *p_ * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_item_attrs_rsp (tAVRC_GET_ATTRS_RSP *p_rsp, - BT_HDR *p_pkt) { - AVRC_TRACE_API("%s", __func__); - if (!p_rsp->p_attrs) { - AVRC_TRACE_ERROR("%s NULL p_attrs", __func__); - return AVRC_STS_BAD_PARAM; - } - /* Figure out how much we have left in current buffer */ - int remaining_buffer_capacity = BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - - p_pkt->offset; - /* Get to the beginning of data section in buffer */ - uint8_t *p_data = (uint8_t *)(p_pkt + 1); - /* Get the MTU size that is filled in earlier */ - uint16_t mtu; - BE_STREAM_TO_UINT16(mtu, p_data); - if (remaining_buffer_capacity > mtu) { - remaining_buffer_capacity = mtu; - } - AVRC_TRACE_DEBUG("%s remaining_buffer_capacity:%d, mtu:%d", - remaining_buffer_capacity, mtu); - if (remaining_buffer_capacity < 5) { - AVRC_TRACE_ERROR("%s not enough buffer for packet header", - remaining_buffer_capacity); - return AVRC_STS_INTERNAL_ERR; - } - /* Get to the beginning of PDU */ - uint8_t *p_pdu_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - /* Skip PDU ID to get pointer to Parameter length */ - uint8_t *p_parameter_len; - p_data = p_parameter_len = p_pdu_start + 1; - /* Parse existing parameter length */ - uint16_t parameter_len; - BE_STREAM_TO_UINT16(parameter_len, p_data); - /* Skip one byte to Number of Attributes */ - uint8_t *p_status = p_data++; - uint8_t *p_attribute_count = p_data++; - if (parameter_len == 0) { - /* First time, initialize the status byte */ - *p_status = p_rsp->status; - if (p_rsp->status != AVRC_STS_NO_ERROR) { - // TODO(siyuanh): This is a hack - parameter_len = 1; - UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); - p_pkt->len = p_status - p_pdu_start; - return AVRC_STS_NO_ERROR; - } - *p_attribute_count = 0; - } else { - // TODO(siyuanh): Why do wee need this case? - p_data = p_pdu_start + p_pkt->len; +static tAVRC_STS avrc_bld_get_item_attrs_rsp(tAVRC_GET_ATTRS_RSP* p_rsp, + BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + if (!p_rsp->p_attrs) { + AVRC_TRACE_ERROR("%s NULL p_attrs", __func__); + return AVRC_STS_BAD_PARAM; + } + /* Figure out how much we have left in current buffer */ + int remaining_buffer_capacity = + BT_DEFAULT_BUFFER_SIZE - BT_HDR_SIZE - p_pkt->offset; + /* Get to the beginning of data section in buffer */ + uint8_t* p_data = (uint8_t*)(p_pkt + 1); + /* Get the MTU size that is filled in earlier */ + uint16_t mtu; + BE_STREAM_TO_UINT16(mtu, p_data); + if (remaining_buffer_capacity > mtu) { + remaining_buffer_capacity = mtu; + } + AVRC_TRACE_DEBUG("%s remaining_buffer_capacity:%d, mtu:%d", + remaining_buffer_capacity, mtu); + if (remaining_buffer_capacity < 5) { + AVRC_TRACE_ERROR("%s not enough buffer for packet header", + remaining_buffer_capacity); + return AVRC_STS_INTERNAL_ERR; + } + /* Get to the beginning of PDU */ + uint8_t* p_pdu_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + /* Skip PDU ID to get pointer to Parameter length */ + uint8_t* p_parameter_len; + p_data = p_parameter_len = p_pdu_start + 1; + /* Parse existing parameter length */ + uint16_t parameter_len; + BE_STREAM_TO_UINT16(parameter_len, p_data); + /* Skip one byte to Number of Attributes */ + uint8_t* p_status = p_data++; + uint8_t* p_attribute_count = p_data++; + if (parameter_len == 0) { + /* First time, initialize the status byte */ + *p_status = p_rsp->status; + if (p_rsp->status != AVRC_STS_NO_ERROR) { + // TODO(siyuanh): This is a hack + parameter_len = 1; + UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); + p_pkt->len = p_status - p_pdu_start; + return AVRC_STS_NO_ERROR; } - remaining_buffer_capacity -= p_data - p_pdu_start; - /* Fill in the Attribute ID, Character Set, Length and Values */ - avrc_build_attribute_entries(p_rsp->num_attrs, - p_rsp->p_attrs, - remaining_buffer_capacity, - &p_data, p_attribute_count); - parameter_len = p_data - p_status; - UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); - p_pkt->len = p_data - p_pdu_start; - return AVRC_STS_NO_ERROR; + *p_attribute_count = 0; + } else { + // TODO(siyuanh): Why do wee need this case? + p_data = p_pdu_start + p_pkt->len; + } + remaining_buffer_capacity -= p_data - p_pdu_start; + /* Fill in the Attribute ID, Character Set, Length and Values */ + avrc_build_attribute_entries(p_rsp->num_attrs, p_rsp->p_attrs, + remaining_buffer_capacity, &p_data, + p_attribute_count); + parameter_len = p_data - p_status; + UINT16_TO_BE_STREAM(p_parameter_len, parameter_len); + p_pkt->len = p_data - p_pdu_start; + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -1290,33 +1205,30 @@ static tAVRC_STS avrc_bld_get_item_attrs_rsp (tAVRC_GET_ATTRS_RSP *p_rsp, * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_get_num_of_item_rsp (tAVRC_GET_NUM_OF_ITEMS_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len; - - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - if (p_rsp->status == AVRC_STS_NO_ERROR) - { - /* add fixed lenth - status(1) + uid_counter(2) + num_items(4) */ - UINT16_TO_BE_STREAM(p_data, 7); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; - } - else - { - /* add fixed lenth - status(1) */ - UINT16_TO_BE_STREAM(p_data, 7); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - p_pkt->len = (p_data - p_start); - return p_rsp->status; - } +static tAVRC_STS avrc_bld_get_num_of_item_rsp(tAVRC_GET_NUM_OF_ITEMS_RSP* p_rsp, + BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len; + + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 1; /* pdu */ + + if (p_rsp->status == AVRC_STS_NO_ERROR) { + /* add fixed lenth - status(1) + uid_counter(2) + num_items(4) */ + UINT16_TO_BE_STREAM(p_data, 7); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); + UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; + } else { + /* add fixed lenth - status(1) */ + UINT16_TO_BE_STREAM(p_data, 7); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + p_pkt->len = (p_data - p_start); + return p_rsp->status; + } } /******************************************************************************* @@ -1331,22 +1243,21 @@ static tAVRC_STS avrc_bld_get_num_of_item_rsp (tAVRC_GET_NUM_OF_ITEMS_RSP *p_rsp * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_search_rsp (tAVRC_SEARCH_RSP *p_rsp, BT_HDR *p_pkt) -{ - uint8_t *p_data, *p_start, *p_len; - - AVRC_TRACE_API("%s", __func__); - /* get the existing length, if any, and also the num attributes */ - p_start = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_data = p_len = p_start + 1; /* pdu */ - - /* add fixed lenth - status(1) + uid_counter(2) + num_items(4) */ - UINT16_TO_BE_STREAM(p_data, 7); - UINT8_TO_BE_STREAM(p_data, p_rsp->status); - UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); - UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); - p_pkt->len = (p_data - p_start); - return AVRC_STS_NO_ERROR; +static tAVRC_STS avrc_bld_search_rsp(tAVRC_SEARCH_RSP* p_rsp, BT_HDR* p_pkt) { + uint8_t *p_data, *p_start, *p_len; + + AVRC_TRACE_API("%s", __func__); + /* get the existing length, if any, and also the num attributes */ + p_start = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 1; /* pdu */ + + /* add fixed lenth - status(1) + uid_counter(2) + num_items(4) */ + UINT16_TO_BE_STREAM(p_data, 7); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + UINT16_TO_BE_STREAM(p_data, p_rsp->uid_counter); + UINT32_TO_BE_STREAM(p_data, p_rsp->num_items); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -1359,10 +1270,9 @@ static tAVRC_STS avrc_bld_search_rsp (tAVRC_SEARCH_RSP *p_rsp, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_play_item_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); +static tAVRC_STS avrc_bld_play_item_rsp(tAVRC_RSP* p_rsp, BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); } /******************************************************************************* @@ -1375,10 +1285,10 @@ static tAVRC_STS avrc_bld_play_item_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) * Otherwise, the error code. * ******************************************************************************/ -static tAVRC_STS avrc_bld_add_to_now_playing_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) -{ - AVRC_TRACE_API("%s", __func__); - return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); +static tAVRC_STS avrc_bld_add_to_now_playing_rsp(tAVRC_RSP* p_rsp, + BT_HDR* p_pkt) { + AVRC_TRACE_API("%s", __func__); + return avrc_bld_ctrl_status_rsp(p_rsp, p_pkt); } /******************************************************************************* @@ -1391,66 +1301,63 @@ static tAVRC_STS avrc_bld_add_to_now_playing_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pk * Otherwise, the buffer that contains the initialized message. * ******************************************************************************/ -static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp) -{ - uint16_t offset = 0; - uint16_t chnl = AVCT_DATA_CTRL; - uint8_t opcode = avrc_opcode_from_pdu(p_rsp->pdu); - - AVRC_TRACE_API("%s: pdu=%x, opcode=%x/%x", __func__, p_rsp->pdu, opcode, p_rsp->rsp.opcode); - if (opcode != p_rsp->rsp.opcode && p_rsp->rsp.status != AVRC_STS_NO_ERROR && - avrc_is_valid_opcode(p_rsp->rsp.opcode)) - { - opcode = p_rsp->rsp.opcode; - AVRC_TRACE_API("%s opcode=%x", __func__, opcode); - } - - switch (opcode) - { - case AVRC_OP_BROWSE: - chnl = AVCT_DATA_BROWSE; - offset = AVCT_BROWSE_OFFSET; - break; +static BT_HDR* avrc_bld_init_rsp_buffer(tAVRC_RESPONSE* p_rsp) { + uint16_t offset = 0; + uint16_t chnl = AVCT_DATA_CTRL; + uint8_t opcode = avrc_opcode_from_pdu(p_rsp->pdu); + + AVRC_TRACE_API("%s: pdu=%x, opcode=%x/%x", __func__, p_rsp->pdu, opcode, + p_rsp->rsp.opcode); + if (opcode != p_rsp->rsp.opcode && p_rsp->rsp.status != AVRC_STS_NO_ERROR && + avrc_is_valid_opcode(p_rsp->rsp.opcode)) { + opcode = p_rsp->rsp.opcode; + AVRC_TRACE_API("%s opcode=%x", __func__, opcode); + } + + switch (opcode) { + case AVRC_OP_BROWSE: + chnl = AVCT_DATA_BROWSE; + offset = AVCT_BROWSE_OFFSET; + break; - case AVRC_OP_PASS_THRU: - offset = AVRC_MSG_PASS_THRU_OFFSET; - break; + case AVRC_OP_PASS_THRU: + offset = AVRC_MSG_PASS_THRU_OFFSET; + break; - case AVRC_OP_VENDOR: - offset = AVRC_MSG_VENDOR_OFFSET; - break; - } + case AVRC_OP_VENDOR: + offset = AVRC_MSG_VENDOR_OFFSET; + break; + } - /* allocate and initialize the buffer */ - BT_HDR *p_pkt = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE); - uint8_t *p_data, *p_start; + /* allocate and initialize the buffer */ + BT_HDR* p_pkt = (BT_HDR*)osi_malloc(BT_DEFAULT_BUFFER_SIZE); + uint8_t *p_data, *p_start; - p_pkt->layer_specific = chnl; - p_pkt->event = opcode; - p_pkt->offset = offset; - p_data = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - p_start = p_data; + p_pkt->layer_specific = chnl; + p_pkt->event = opcode; + p_pkt->offset = offset; + p_data = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + p_start = p_data; - /* pass thru - group navigation - has a two byte op_id, so dont do it here */ - if (opcode != AVRC_OP_PASS_THRU) - *p_data++ = p_rsp->pdu; + /* pass thru - group navigation - has a two byte op_id, so dont do it here */ + if (opcode != AVRC_OP_PASS_THRU) *p_data++ = p_rsp->pdu; - switch (opcode) { + switch (opcode) { case AVRC_OP_VENDOR: - /* reserved 0, packet_type 0 */ - UINT8_TO_BE_STREAM(p_data, 0); - /* continue to the next "case to add length */ + /* reserved 0, packet_type 0 */ + UINT8_TO_BE_STREAM(p_data, 0); + /* continue to the next "case to add length */ case AVRC_OP_BROWSE: - /* add fixed lenth - 0 */ - UINT16_TO_BE_STREAM(p_data, 0); - break; - } + /* add fixed lenth - 0 */ + UINT16_TO_BE_STREAM(p_data, 0); + break; + } - p_pkt->len = (p_data - p_start); - p_rsp->rsp.opcode = opcode; + p_pkt->len = (p_data - p_start); + p_rsp->rsp.opcode = opcode; - return p_pkt; + return p_pkt; } /******************************************************************************* @@ -1464,160 +1371,159 @@ static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp) * Otherwise, the error code. * ******************************************************************************/ -tAVRC_STS AVRC_BldResponse( uint8_t handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt) -{ - tAVRC_STS status = AVRC_STS_BAD_PARAM; - BT_HDR *p_pkt; - bool alloc = false; - uint8_t *p; - uint16_t peer_mtu; - - if (!p_rsp || !pp_pkt) - { - AVRC_TRACE_API("%s Invalid parameters passed. p_rsp=%p, pp_pkt=%p", - __func__, p_rsp, pp_pkt); - return AVRC_STS_BAD_PARAM; +tAVRC_STS AVRC_BldResponse(uint8_t handle, tAVRC_RESPONSE* p_rsp, + BT_HDR** pp_pkt) { + tAVRC_STS status = AVRC_STS_BAD_PARAM; + BT_HDR* p_pkt; + bool alloc = false; + uint8_t* p; + uint16_t peer_mtu; + + if (!p_rsp || !pp_pkt) { + AVRC_TRACE_API("%s Invalid parameters passed. p_rsp=%p, pp_pkt=%p", + __func__, p_rsp, pp_pkt); + return AVRC_STS_BAD_PARAM; + } + + if (*pp_pkt == NULL) { + *pp_pkt = avrc_bld_init_rsp_buffer(p_rsp); + if (*pp_pkt == NULL) { + AVRC_TRACE_API("%s Failed to initialize response buffer", __func__); + return AVRC_STS_INTERNAL_ERR; } - if (*pp_pkt == NULL) - { - *pp_pkt = avrc_bld_init_rsp_buffer(p_rsp); - if (*pp_pkt == NULL) - { - AVRC_TRACE_API("%s Failed to initialize response buffer", __func__); - return AVRC_STS_INTERNAL_ERR; - } - - if ((*pp_pkt)->layer_specific == AVCT_DATA_BROWSE) - { - p = (uint8_t *)((*pp_pkt) + 1); - peer_mtu = AVCT_GetBrowseMtu(handle) - AVCT_HDR_LEN_SINGLE; - UINT16_TO_BE_STREAM(p, peer_mtu); - } - - alloc = true; + if ((*pp_pkt)->layer_specific == AVCT_DATA_BROWSE) { + p = (uint8_t*)((*pp_pkt) + 1); + peer_mtu = AVCT_GetBrowseMtu(handle) - AVCT_HDR_LEN_SINGLE; + UINT16_TO_BE_STREAM(p, peer_mtu); } - status = AVRC_STS_NO_ERROR; - p_pkt = *pp_pkt; - AVRC_TRACE_API("%s pdu=%x status=%x", __func__, p_rsp->rsp.pdu, p_rsp->rsp.status); - if (p_rsp->rsp.status != AVRC_STS_NO_ERROR) - { - return( avrc_bld_rejected_rsp(&p_rsp->rsp, p_pkt) ); - } + alloc = true; + } + status = AVRC_STS_NO_ERROR; + p_pkt = *pp_pkt; - switch (p_rsp->pdu) - { + AVRC_TRACE_API("%s pdu=%x status=%x", __func__, p_rsp->rsp.pdu, + p_rsp->rsp.status); + if (p_rsp->rsp.status != AVRC_STS_NO_ERROR) { + return (avrc_bld_rejected_rsp(&p_rsp->rsp, p_pkt)); + } + + switch (p_rsp->pdu) { case AVRC_PDU_NEXT_GROUP: case AVRC_PDU_PREV_GROUP: - status = avrc_bld_group_navigation_rsp(p_rsp->pdu, p_pkt); - break; + status = avrc_bld_group_navigation_rsp(p_rsp->pdu, p_pkt); + break; case AVRC_PDU_GET_CAPABILITIES: - status = avrc_bld_get_capability_rsp(&p_rsp->get_caps, p_pkt); - break; + status = avrc_bld_get_capability_rsp(&p_rsp->get_caps, p_pkt); + break; case AVRC_PDU_LIST_PLAYER_APP_ATTR: - status = avrc_bld_list_app_settings_attr_rsp(&p_rsp->list_app_attr, p_pkt); - break; + status = + avrc_bld_list_app_settings_attr_rsp(&p_rsp->list_app_attr, p_pkt); + break; case AVRC_PDU_LIST_PLAYER_APP_VALUES: - status = avrc_bld_list_app_settings_values_rsp(&p_rsp->list_app_values, p_pkt); - break; + status = + avrc_bld_list_app_settings_values_rsp(&p_rsp->list_app_values, p_pkt); + break; case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: - status = avrc_bld_get_cur_app_setting_value_rsp(&p_rsp->get_cur_app_val, p_pkt); - break; + status = avrc_bld_get_cur_app_setting_value_rsp(&p_rsp->get_cur_app_val, + p_pkt); + break; case AVRC_PDU_SET_PLAYER_APP_VALUE: - status = avrc_bld_set_app_setting_value_rsp(&p_rsp->set_app_val, p_pkt); - break; + status = avrc_bld_set_app_setting_value_rsp(&p_rsp->set_app_val, p_pkt); + break; case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: - status = avrc_bld_get_app_setting_attr_text_rsp(&p_rsp->get_app_attr_txt, p_pkt); - break; + status = avrc_bld_get_app_setting_attr_text_rsp(&p_rsp->get_app_attr_txt, + p_pkt); + break; case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: - status = avrc_bld_get_app_setting_value_text_rsp(&p_rsp->get_app_val_txt, p_pkt); - break; + status = avrc_bld_get_app_setting_value_text_rsp(&p_rsp->get_app_val_txt, + p_pkt); + break; case AVRC_PDU_INFORM_DISPLAY_CHARSET: - status = avrc_bld_inform_charset_rsp(&p_rsp->inform_charset, p_pkt); - break; + status = avrc_bld_inform_charset_rsp(&p_rsp->inform_charset, p_pkt); + break; case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: - status = avrc_bld_inform_battery_status_rsp(&p_rsp->inform_battery_status, p_pkt); - break; + status = avrc_bld_inform_battery_status_rsp(&p_rsp->inform_battery_status, + p_pkt); + break; case AVRC_PDU_GET_ELEMENT_ATTR: - status = avrc_bld_get_elem_attrs_rsp(&p_rsp->get_attrs, p_pkt); - break; + status = avrc_bld_get_elem_attrs_rsp(&p_rsp->get_attrs, p_pkt); + break; case AVRC_PDU_GET_PLAY_STATUS: - status = avrc_bld_get_play_status_rsp(&p_rsp->get_play_status, p_pkt); - break; + status = avrc_bld_get_play_status_rsp(&p_rsp->get_play_status, p_pkt); + break; case AVRC_PDU_REGISTER_NOTIFICATION: - status = avrc_bld_notify_rsp(&p_rsp->reg_notif, p_pkt); - break; + status = avrc_bld_notify_rsp(&p_rsp->reg_notif, p_pkt); + break; case AVRC_PDU_REQUEST_CONTINUATION_RSP: - status = avrc_bld_next_rsp(&p_rsp->continu, p_pkt); - break; + status = avrc_bld_next_rsp(&p_rsp->continu, p_pkt); + break; case AVRC_PDU_ABORT_CONTINUATION_RSP: - status = avrc_bld_next_rsp(&p_rsp->abort, p_pkt); - break; + status = avrc_bld_next_rsp(&p_rsp->abort, p_pkt); + break; case AVRC_PDU_SET_ADDRESSED_PLAYER: - status = avrc_bld_set_addr_player_rsp(&p_rsp->addr_player, p_pkt); - break; + status = avrc_bld_set_addr_player_rsp(&p_rsp->addr_player, p_pkt); + break; case AVRC_PDU_PLAY_ITEM: - status = avrc_bld_play_item_rsp(&p_rsp->play_item, p_pkt); - break; + status = avrc_bld_play_item_rsp(&p_rsp->play_item, p_pkt); + break; case AVRC_PDU_SET_ABSOLUTE_VOLUME: - status = avrc_bld_set_absolute_volume_rsp(p_rsp->volume.volume, p_pkt); - break; + status = avrc_bld_set_absolute_volume_rsp(p_rsp->volume.volume, p_pkt); + break; case AVRC_PDU_ADD_TO_NOW_PLAYING: - status = avrc_bld_add_to_now_playing_rsp(&p_rsp->add_to_play, p_pkt); - break; + status = avrc_bld_add_to_now_playing_rsp(&p_rsp->add_to_play, p_pkt); + break; case AVRC_PDU_SET_BROWSED_PLAYER: - status = avrc_bld_set_browsed_player_rsp(&p_rsp->br_player, p_pkt); - break; + status = avrc_bld_set_browsed_player_rsp(&p_rsp->br_player, p_pkt); + break; case AVRC_PDU_GET_FOLDER_ITEMS: - status = avrc_bld_get_folder_items_rsp(&p_rsp->get_items, p_pkt); - break; + status = avrc_bld_get_folder_items_rsp(&p_rsp->get_items, p_pkt); + break; case AVRC_PDU_CHANGE_PATH: - status = avrc_bld_change_path_rsp(&p_rsp->chg_path, p_pkt); - break; + status = avrc_bld_change_path_rsp(&p_rsp->chg_path, p_pkt); + break; case AVRC_PDU_GET_ITEM_ATTRIBUTES: - status = avrc_bld_get_item_attrs_rsp(&p_rsp->get_attrs, p_pkt); - break; + status = avrc_bld_get_item_attrs_rsp(&p_rsp->get_attrs, p_pkt); + break; case AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS: - status = avrc_bld_get_num_of_item_rsp(&p_rsp->get_num_of_items, p_pkt); - break; + status = avrc_bld_get_num_of_item_rsp(&p_rsp->get_num_of_items, p_pkt); + break; case AVRC_PDU_SEARCH: - status = avrc_bld_search_rsp(&p_rsp->search, p_pkt); - break; - } - - if (alloc && (status != AVRC_STS_NO_ERROR) ) - { - osi_free(p_pkt); - *pp_pkt = NULL; - } - AVRC_TRACE_API("%s returning %d", __func__, status); - return status; + status = avrc_bld_search_rsp(&p_rsp->search, p_pkt); + break; + } + + if (alloc && (status != AVRC_STS_NO_ERROR)) { + osi_free(p_pkt); + *pp_pkt = NULL; + } + AVRC_TRACE_API("%s returning %d", __func__, status); + return status; } #endif /* (AVRC_METADATA_INCLUDED == true)*/ - diff --git a/stack/avrc/avrc_int.h b/stack/avrc/avrc_int.h index 5fb27060f..de305958b 100644 --- a/stack/avrc/avrc_int.h +++ b/stack/avrc/avrc_int.h @@ -22,7 +22,6 @@ * ******************************************************************************/ - #ifndef AVRC_INT_H #define AVRC_INT_H @@ -44,67 +43,80 @@ extern "C" { ****************************************************************************/ /* Number of attributes in AVRC SDP record. */ -#define AVRC_NUM_ATTR 6 +#define AVRC_NUM_ATTR 6 /* Number of protocol elements in protocol element list. */ -#define AVRC_NUM_PROTO_ELEMS 2 +#define AVRC_NUM_PROTO_ELEMS 2 #ifndef AVRC_MIN_CMD_LEN -#define AVRC_MIN_CMD_LEN 20 +#define AVRC_MIN_CMD_LEN 20 #endif -#define AVRC_UNIT_OPRND_BYTES 5 -#define AVRC_SUB_OPRND_BYTES 4 +#define AVRC_UNIT_OPRND_BYTES 5 +#define AVRC_SUB_OPRND_BYTES 4 #define AVRC_SUBRSP_OPRND_BYTES 3 -#define AVRC_SUB_PAGE_MASK 7 -#define AVRC_SUB_PAGE_SHIFT 4 -#define AVRC_SUB_EXT_CODE 7 -#define AVRC_PASS_OP_ID_MASK 0x7F -#define AVRC_PASS_STATE_MASK 0x80 -#define AVRC_CMD_OPRND_PAD 0xFF - -#define AVRC_CTYPE_MASK 0x0F -#define AVRC_SUBTYPE_MASK 0xF8 -#define AVRC_SUBTYPE_SHIFT 3 -#define AVRC_SUBID_MASK 0x07 -#define AVRC_SUBID_IGNORE 0x07 - -#define AVRC_SINGLE_PARAM_SIZE 1 +#define AVRC_SUB_PAGE_MASK 7 +#define AVRC_SUB_PAGE_SHIFT 4 +#define AVRC_SUB_EXT_CODE 7 +#define AVRC_PASS_OP_ID_MASK 0x7F +#define AVRC_PASS_STATE_MASK 0x80 +#define AVRC_CMD_OPRND_PAD 0xFF + +#define AVRC_CTYPE_MASK 0x0F +#define AVRC_SUBTYPE_MASK 0xF8 +#define AVRC_SUBTYPE_SHIFT 3 +#define AVRC_SUBID_MASK 0x07 +#define AVRC_SUBID_IGNORE 0x07 + +#define AVRC_SINGLE_PARAM_SIZE 1 #define AVRC_METADATA_PKT_TYPE_MASK 0x03 -#define AVRC_PASS_THOUGH_MSG_MASK 0x80 /* MSB of msg_type indicates the PAS THROUGH msg */ -#define AVRC_VENDOR_UNIQUE_MASK 0x70 /* vendor unique id */ - +#define AVRC_PASS_THOUGH_MSG_MASK \ + 0x80 /* MSB of msg_type indicates the PAS THROUGH msg */ +#define AVRC_VENDOR_UNIQUE_MASK 0x70 /* vendor unique id */ /* Company ID is 24-bit integer We can not use the macros in bt_types.h */ -#define AVRC_CO_ID_TO_BE_STREAM(p, u32) {*(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)(u32); } -#define AVRC_BE_STREAM_TO_CO_ID(u32, p) {(u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + (((uint32_t)(*(p))) << 16)); (p) += 3;} +#define AVRC_CO_ID_TO_BE_STREAM(p, u32) \ + { \ + *(p)++ = (uint8_t)((u32) >> 16); \ + *(p)++ = (uint8_t)((u32) >> 8); \ + *(p)++ = (uint8_t)(u32); \ + } +#define AVRC_BE_STREAM_TO_CO_ID(u32, p) \ + { \ + (u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + \ + (((uint32_t)(*(p))) << 16)); \ + (p) += 3; \ + } -#define AVRC_AVC_HDR_SIZE 3 /* ctype, subunit*, opcode */ +#define AVRC_AVC_HDR_SIZE 3 /* ctype, subunit*, opcode */ -#define AVRC_MIN_META_HDR_SIZE 4 /* pdu id(1), packet type(1), param len(2) */ -#define AVRC_MIN_BROWSE_HDR_SIZE 3 /* pdu id(1), param len(2) */ +#define AVRC_MIN_META_HDR_SIZE 4 /* pdu id(1), packet type(1), param len(2) */ +#define AVRC_MIN_BROWSE_HDR_SIZE 3 /* pdu id(1), param len(2) */ -#define AVRC_VENDOR_HDR_SIZE 6 /* ctype, subunit*, opcode, CO_ID */ -#define AVRC_MSG_VENDOR_OFFSET 23 -#define AVRC_MIN_VENDOR_SIZE (AVRC_MSG_VENDOR_OFFSET + BT_HDR_SIZE + AVRC_MIN_META_HDR_SIZE) +#define AVRC_VENDOR_HDR_SIZE 6 /* ctype, subunit*, opcode, CO_ID */ +#define AVRC_MSG_VENDOR_OFFSET 23 +#define AVRC_MIN_VENDOR_SIZE \ + (AVRC_MSG_VENDOR_OFFSET + BT_HDR_SIZE + AVRC_MIN_META_HDR_SIZE) -#define AVRC_PASS_THRU_SIZE 8 -#define AVRC_MSG_PASS_THRU_OFFSET 25 -#define AVRC_MIN_PASS_THRU_SIZE (AVRC_MSG_PASS_THRU_OFFSET + BT_HDR_SIZE + 4) +#define AVRC_PASS_THRU_SIZE 8 +#define AVRC_MSG_PASS_THRU_OFFSET 25 +#define AVRC_MIN_PASS_THRU_SIZE (AVRC_MSG_PASS_THRU_OFFSET + BT_HDR_SIZE + 4) -#define AVRC_MIN_BROWSE_SIZE (AVCT_BROWSE_OFFSET + BT_HDR_SIZE + AVRC_MIN_BROWSE_HDR_SIZE) +#define AVRC_MIN_BROWSE_SIZE \ + (AVCT_BROWSE_OFFSET + BT_HDR_SIZE + AVRC_MIN_BROWSE_HDR_SIZE) -#define AVRC_CTRL_PKT_LEN(pf, pk) {(pf) = (uint8_t *)((pk) + 1) + (pk)->offset + 2;} +#define AVRC_CTRL_PKT_LEN(pf, pk) \ + { (pf) = (uint8_t*)((pk) + 1) + (pk)->offset + 2; } -#define AVRC_MAX_CTRL_DATA_LEN (AVRC_PACKET_LEN) +#define AVRC_MAX_CTRL_DATA_LEN (AVRC_PACKET_LEN) /* Timeout for waiting for avrc command responses (in milliseconds) */ #ifndef AVRC_CMD_TOUT_MS -#define AVRC_CMD_TOUT_MS (2*1000) +#define AVRC_CMD_TOUT_MS (2 * 1000) #endif /* Flags for avrc_cb.ccb_int[].flags */ -#define AVRC_CB_FLAGS_RSP_PENDING 0x01 /* Waiting for AVRC response */ +#define AVRC_CB_FLAGS_RSP_PENDING 0x01 /* Waiting for AVRC response */ /***************************************************************************** * Type definitions @@ -112,57 +124,58 @@ extern "C" { #if (AVRC_METADATA_INCLUDED == TRUE) /* type for Metadata fragmentation control block */ -typedef struct -{ - BT_HDR *p_fmsg; /* the fragmented message */ - uint8_t frag_pdu; /* the PDU ID for fragmentation */ - bool frag_enabled; /* fragmentation flag */ +typedef struct { + BT_HDR* p_fmsg; /* the fragmented message */ + uint8_t frag_pdu; /* the PDU ID for fragmentation */ + bool frag_enabled; /* fragmentation flag */ } tAVRC_FRAG_CB; /* type for Metadata re-assembly control block */ -typedef struct -{ - BT_HDR *p_rmsg; /* the received message */ - uint16_t rasm_offset; /* re-assembly flag, the offset of the start fragment */ - uint8_t rasm_pdu; /* the PDU ID for re-assembly */ +typedef struct { + BT_HDR* p_rmsg; /* the received message */ + uint16_t rasm_offset; /* re-assembly flag, the offset of the start fragment */ + uint8_t rasm_pdu; /* the PDU ID for re-assembly */ } tAVRC_RASM_CB; #endif /* AVRC internal connection control block */ -typedef struct -{ - fixed_queue_t *cmd_q; /* Command queue for serializing vendor specific commands */ - uint8_t flags; /* See AVRC_CB_FLAGS_* definitions */ - alarm_t * tle; /* Command timeout timer */ +typedef struct { + fixed_queue_t* + cmd_q; /* Command queue for serializing vendor specific commands */ + uint8_t flags; /* See AVRC_CB_FLAGS_* definitions */ + alarm_t* tle; /* Command timeout timer */ } tAVRC_CONN_INT_CB; typedef struct { - tAVRC_CONN_CB ccb[AVCT_NUM_CONN]; /* Connection control block from AVRC_Open API */ - tAVRC_CONN_INT_CB ccb_int[AVCT_NUM_CONN]; /* Internal connection control block */ + tAVRC_CONN_CB + ccb[AVCT_NUM_CONN]; /* Connection control block from AVRC_Open API */ + tAVRC_CONN_INT_CB + ccb_int[AVCT_NUM_CONN]; /* Internal connection control block */ #if (AVRC_METADATA_INCLUDED == TRUE) - tAVRC_FRAG_CB fcb[AVCT_NUM_CONN]; - tAVRC_RASM_CB rcb[AVCT_NUM_CONN]; + tAVRC_FRAG_CB fcb[AVCT_NUM_CONN]; + tAVRC_RASM_CB rcb[AVCT_NUM_CONN]; #endif - tAVRC_FIND_CBACK *p_cback; /* pointer to application callback */ - tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ - uint16_t service_uuid; /* service UUID to search */ - uint8_t trace_level; + tAVRC_FIND_CBACK* p_cback; /* pointer to application callback */ + tSDP_DISCOVERY_DB* p_db; /* pointer to discovery database */ + uint16_t service_uuid; /* service UUID to search */ + uint8_t trace_level; } tAVRC_CB; /****************************************************************************** * Main Control Block ******************************************************************************/ -extern tAVRC_CB avrc_cb; +extern tAVRC_CB avrc_cb; extern bool avrc_is_valid_pdu_id(uint8_t pdu_id); extern bool avrc_is_valid_player_attrib_value(uint8_t attrib, uint8_t value); -extern BT_HDR * avrc_alloc_ctrl_pkt (uint8_t pdu); -extern tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, uint16_t *p_vendor_unique_id); +extern BT_HDR* avrc_alloc_ctrl_pkt(uint8_t pdu); +extern tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS* p_msg, + uint16_t* p_vendor_unique_id); extern uint8_t avrc_opcode_from_pdu(uint8_t pdu); extern bool avrc_is_valid_opcode(uint8_t opcode); extern void avrc_flush_cmd_q(uint8_t handle); void avrc_start_cmd_timer(uint8_t handle, uint8_t label, uint8_t msg_mask); -void avrc_send_next_vendor_cmd (uint8_t handle); +void avrc_send_next_vendor_cmd(uint8_t handle); #ifdef __cplusplus } diff --git a/stack/avrc/avrc_opt.cc b/stack/avrc/avrc_opt.cc index fb3348f3e..c0d1be769 100644 --- a/stack/avrc/avrc_opt.cc +++ b/stack/avrc/avrc_opt.cc @@ -24,9 +24,9 @@ #include #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_int.h" +#include "bt_common.h" /****************************************************************************** * @@ -44,33 +44,34 @@ * NULL if p_msg is NULL. * *****************************************************************************/ -static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_cmd; - uint8_t *p_data; +static BT_HDR* avrc_vendor_msg(tAVRC_MSG_VENDOR* p_msg) { + BT_HDR* p_cmd; + uint8_t* p_data; - assert(p_msg != NULL); + assert(p_msg != NULL); #if (AVRC_METADATA_INCLUDED == TRUE) - assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); - p_cmd = (BT_HDR *)osi_malloc(AVRC_META_CMD_BUF_SIZE); + assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); + p_cmd = (BT_HDR*)osi_malloc(AVRC_META_CMD_BUF_SIZE); #else - assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); - p_cmd = (BT_HDR *)osi_malloc(AVRC_CMD_BUF_SIZE); + assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); + p_cmd = (BT_HDR*)osi_malloc(AVRC_CMD_BUF_SIZE); #endif - p_cmd->offset = AVCT_MSG_OFFSET; - p_data = (uint8_t *)(p_cmd + 1) + p_cmd->offset; - *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); - *p_data++ = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id; - *p_data++ = AVRC_OP_VENDOR; - AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id); - if (p_msg->vendor_len && p_msg->p_vendor_data) - memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len); - p_cmd->len = (uint16_t)(p_data + p_msg->vendor_len - (uint8_t *)(p_cmd + 1) - p_cmd->offset); - p_cmd->layer_specific = AVCT_DATA_CTRL; - - return p_cmd; + p_cmd->offset = AVCT_MSG_OFFSET; + p_data = (uint8_t*)(p_cmd + 1) + p_cmd->offset; + *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); + *p_data++ = + (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id; + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id); + if (p_msg->vendor_len && p_msg->p_vendor_data) + memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len); + p_cmd->len = (uint16_t)(p_data + p_msg->vendor_len - (uint8_t*)(p_cmd + 1) - + p_cmd->offset); + p_cmd->layer_specific = AVCT_DATA_CTRL; + + return p_cmd; } /****************************************************************************** @@ -94,22 +95,22 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_UnitCmd(uint8_t handle, uint8_t label) -{ - BT_HDR *p_cmd = (BT_HDR *)osi_malloc(AVRC_CMD_BUF_SIZE); - uint8_t *p_data; - - p_cmd->offset = AVCT_MSG_OFFSET; - p_data = (uint8_t *)(p_cmd + 1) + p_cmd->offset; - *p_data++ = AVRC_CMD_STATUS; - /* unit & id ignore */ - *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE; - *p_data++ = AVRC_OP_UNIT_INFO; - memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_UNIT_OPRND_BYTES); - p_cmd->len = p_data + AVRC_UNIT_OPRND_BYTES - (uint8_t *)(p_cmd + 1) - p_cmd->offset; - p_cmd->layer_specific = AVCT_DATA_CTRL; - - return AVCT_MsgReq(handle, label, AVCT_CMD, p_cmd); +uint16_t AVRC_UnitCmd(uint8_t handle, uint8_t label) { + BT_HDR* p_cmd = (BT_HDR*)osi_malloc(AVRC_CMD_BUF_SIZE); + uint8_t* p_data; + + p_cmd->offset = AVCT_MSG_OFFSET; + p_data = (uint8_t*)(p_cmd + 1) + p_cmd->offset; + *p_data++ = AVRC_CMD_STATUS; + /* unit & id ignore */ + *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE; + *p_data++ = AVRC_OP_UNIT_INFO; + memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_UNIT_OPRND_BYTES); + p_cmd->len = + p_data + AVRC_UNIT_OPRND_BYTES - (uint8_t*)(p_cmd + 1) - p_cmd->offset; + p_cmd->layer_specific = AVCT_DATA_CTRL; + + return AVCT_MsgReq(handle, label, AVCT_CMD, p_cmd); } /****************************************************************************** @@ -137,23 +138,24 @@ uint16_t AVRC_UnitCmd(uint8_t handle, uint8_t label) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_SubCmd(uint8_t handle, uint8_t label, uint8_t page) -{ - BT_HDR *p_cmd = (BT_HDR *)osi_malloc(AVRC_CMD_BUF_SIZE); - uint8_t *p_data; - - p_cmd->offset = AVCT_MSG_OFFSET; - p_data = (uint8_t *)(p_cmd + 1) + p_cmd->offset; - *p_data++ = AVRC_CMD_STATUS; - /* unit & id ignore */ - *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE; - *p_data++ = AVRC_OP_SUB_INFO; - *p_data++ = ((page&AVRC_SUB_PAGE_MASK) << AVRC_SUB_PAGE_SHIFT) | AVRC_SUB_EXT_CODE; - memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_SUB_OPRND_BYTES); - p_cmd->len = p_data + AVRC_SUB_OPRND_BYTES - (uint8_t *)(p_cmd + 1) - p_cmd->offset; - p_cmd->layer_specific = AVCT_DATA_CTRL; - - return AVCT_MsgReq(handle, label, AVCT_CMD, p_cmd); +uint16_t AVRC_SubCmd(uint8_t handle, uint8_t label, uint8_t page) { + BT_HDR* p_cmd = (BT_HDR*)osi_malloc(AVRC_CMD_BUF_SIZE); + uint8_t* p_data; + + p_cmd->offset = AVCT_MSG_OFFSET; + p_data = (uint8_t*)(p_cmd + 1) + p_cmd->offset; + *p_data++ = AVRC_CMD_STATUS; + /* unit & id ignore */ + *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE; + *p_data++ = AVRC_OP_SUB_INFO; + *p_data++ = + ((page & AVRC_SUB_PAGE_MASK) << AVRC_SUB_PAGE_SHIFT) | AVRC_SUB_EXT_CODE; + memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_SUB_OPRND_BYTES); + p_cmd->len = + p_data + AVRC_SUB_OPRND_BYTES - (uint8_t*)(p_cmd + 1) - p_cmd->offset; + p_cmd->layer_specific = AVCT_DATA_CTRL; + + return AVCT_MsgReq(handle, label, AVCT_CMD, p_cmd); } /****************************************************************************** @@ -179,16 +181,15 @@ uint16_t AVRC_SubCmd(uint8_t handle, uint8_t label, uint8_t page) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_buf = avrc_vendor_msg(p_msg); - if (p_buf) - return AVCT_MsgReq( handle, label, AVCT_CMD, p_buf); - else - return AVCT_NO_RESOURCES; +uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, + tAVRC_MSG_VENDOR* p_msg) { + BT_HDR* p_buf = avrc_vendor_msg(p_msg); + if (p_buf) + return AVCT_MsgReq(handle, label, AVCT_CMD, p_buf); + else + return AVCT_NO_RESOURCES; } - /****************************************************************************** * * Function AVRC_VendorRsp @@ -215,14 +216,11 @@ uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR *p_msg) * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -uint16_t AVRC_VendorRsp(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR *p_msg) -{ - BT_HDR *p_buf = avrc_vendor_msg(p_msg); - if (p_buf) - return AVCT_MsgReq( handle, label, AVCT_RSP, p_buf); - else - return AVCT_NO_RESOURCES; +uint16_t AVRC_VendorRsp(uint8_t handle, uint8_t label, + tAVRC_MSG_VENDOR* p_msg) { + BT_HDR* p_buf = avrc_vendor_msg(p_msg); + if (p_buf) + return AVCT_MsgReq(handle, label, AVCT_RSP, p_buf); + else + return AVCT_NO_RESOURCES; } - - - diff --git a/stack/avrc/avrc_pars_ct.cc b/stack/avrc/avrc_pars_ct.cc index dc68688b2..7c1f62267 100644 --- a/stack/avrc/avrc_pars_ct.cc +++ b/stack/avrc/avrc_pars_ct.cc @@ -17,10 +17,10 @@ ******************************************************************************/ #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_defs.h" #include "avrc_int.h" +#include "bt_common.h" #include "bt_utils.h" #include "osi/include/osi.h" @@ -42,361 +42,348 @@ * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - uint8_t *p; - uint16_t len; +static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg, + tAVRC_RESPONSE* p_result) { + tAVRC_STS status = AVRC_STS_NO_ERROR; + uint8_t* p; + uint16_t len; #if (AVRC_ADV_CTRL_INCLUDED == TRUE) - uint8_t eventid=0; + uint8_t eventid = 0; #endif - /* Check the vendor data */ - if (p_msg->vendor_len == 0) - return AVRC_STS_NO_ERROR; - if (p_msg->p_vendor_data == NULL) - return AVRC_STS_INTERNAL_ERR; - - p = p_msg->p_vendor_data; - BE_STREAM_TO_UINT8 (p_result->pdu, p); - p++; /* skip the reserved/packe_type byte */ - BE_STREAM_TO_UINT16 (len, p); - AVRC_TRACE_DEBUG("%s ctype:0x%x pdu:0x%x, len:%d/0x%x", - __func__, p_msg->hdr.ctype, p_result->pdu, len, len); - if (p_msg->hdr.ctype == AVRC_RSP_REJ) - { - p_result->rsp.status = *p; - return p_result->rsp.status; - } - - switch (p_result->pdu) - { - /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ - /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ + /* Check the vendor data */ + if (p_msg->vendor_len == 0) return AVRC_STS_NO_ERROR; + if (p_msg->p_vendor_data == NULL) return AVRC_STS_INTERNAL_ERR; + + p = p_msg->p_vendor_data; + BE_STREAM_TO_UINT8(p_result->pdu, p); + p++; /* skip the reserved/packe_type byte */ + BE_STREAM_TO_UINT16(len, p); + AVRC_TRACE_DEBUG("%s ctype:0x%x pdu:0x%x, len:%d/0x%x", __func__, + p_msg->hdr.ctype, p_result->pdu, len, len); + if (p_msg->hdr.ctype == AVRC_RSP_REJ) { + p_result->rsp.status = *p; + return p_result->rsp.status; + } + + switch (p_result->pdu) { +/* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ +/* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ #if (AVRC_ADV_CTRL_INCLUDED == TRUE) - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->volume.volume, p); - } - break; + case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ + if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT8(p_result->volume.volume, p); + } + break; #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ #if (AVRC_ADV_CTRL_INCLUDED == TRUE) - BE_STREAM_TO_UINT8 (eventid, p); - if(AVRC_EVT_VOLUME_CHANGE==eventid - && (AVRC_RSP_CHANGED==p_msg->hdr.ctype || AVRC_RSP_INTERIM==p_msg->hdr.ctype - || AVRC_RSP_REJ==p_msg->hdr.ctype || AVRC_RSP_NOT_IMPL==p_msg->hdr.ctype)) - { - p_result->reg_notif.status=p_msg->hdr.ctype; - p_result->reg_notif.event_id=eventid; - BE_STREAM_TO_UINT8 (p_result->reg_notif.param.volume, p); - } - AVRC_TRACE_DEBUG("%s PDU reg notif response:event %x, volume %x", - __func__, eventid, p_result->reg_notif.param.volume); + BE_STREAM_TO_UINT8(eventid, p); + if (AVRC_EVT_VOLUME_CHANGE == eventid && + (AVRC_RSP_CHANGED == p_msg->hdr.ctype || + AVRC_RSP_INTERIM == p_msg->hdr.ctype || + AVRC_RSP_REJ == p_msg->hdr.ctype || + AVRC_RSP_NOT_IMPL == p_msg->hdr.ctype)) { + p_result->reg_notif.status = p_msg->hdr.ctype; + p_result->reg_notif.event_id = eventid; + BE_STREAM_TO_UINT8(p_result->reg_notif.param.volume, p); + } + AVRC_TRACE_DEBUG("%s PDU reg notif response:event %x, volume %x", + __func__, eventid, p_result->reg_notif.param.volume); #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */ - break; + break; default: - status = AVRC_STS_BAD_CMD; - break; - } + status = AVRC_STS_BAD_CMD; + break; + } - return status; + return status; } -void avrc_parse_notification_rsp (uint8_t *p_stream, tAVRC_REG_NOTIF_RSP *p_rsp) -{ - BE_STREAM_TO_UINT8(p_rsp->event_id, p_stream); - switch (p_rsp->event_id) - { - case AVRC_EVT_PLAY_STATUS_CHANGE: - BE_STREAM_TO_UINT8(p_rsp->param.play_status, p_stream); - break; - - case AVRC_EVT_TRACK_CHANGE: - BE_STREAM_TO_ARRAY(p_stream, p_rsp->param.track, 8); - break; - - case AVRC_EVT_APP_SETTING_CHANGE: - BE_STREAM_TO_UINT8(p_rsp->param.player_setting.num_attr, p_stream); - for (int index = 0; index < p_rsp->param.player_setting.num_attr; index++) - { - BE_STREAM_TO_UINT8(p_rsp->param.player_setting.attr_id[index], p_stream); - BE_STREAM_TO_UINT8(p_rsp->param.player_setting.attr_value[index], p_stream); - } - break; - - case AVRC_EVT_NOW_PLAYING_CHANGE: - break; - - case AVRC_EVT_AVAL_PLAYERS_CHANGE: - break; - - case AVRC_EVT_ADDR_PLAYER_CHANGE: - break; - - case AVRC_EVT_UIDS_CHANGE: - break; - - case AVRC_EVT_TRACK_REACHED_END: - case AVRC_EVT_TRACK_REACHED_START: - case AVRC_EVT_PLAY_POS_CHANGED: - case AVRC_EVT_BATTERY_STATUS_CHANGE: - case AVRC_EVT_SYSTEM_STATUS_CHANGE: - default: - break; - } +void avrc_parse_notification_rsp(uint8_t* p_stream, + tAVRC_REG_NOTIF_RSP* p_rsp) { + BE_STREAM_TO_UINT8(p_rsp->event_id, p_stream); + switch (p_rsp->event_id) { + case AVRC_EVT_PLAY_STATUS_CHANGE: + BE_STREAM_TO_UINT8(p_rsp->param.play_status, p_stream); + break; + + case AVRC_EVT_TRACK_CHANGE: + BE_STREAM_TO_ARRAY(p_stream, p_rsp->param.track, 8); + break; + + case AVRC_EVT_APP_SETTING_CHANGE: + BE_STREAM_TO_UINT8(p_rsp->param.player_setting.num_attr, p_stream); + for (int index = 0; index < p_rsp->param.player_setting.num_attr; + index++) { + BE_STREAM_TO_UINT8(p_rsp->param.player_setting.attr_id[index], + p_stream); + BE_STREAM_TO_UINT8(p_rsp->param.player_setting.attr_value[index], + p_stream); + } + break; + + case AVRC_EVT_NOW_PLAYING_CHANGE: + break; + + case AVRC_EVT_AVAL_PLAYERS_CHANGE: + break; + + case AVRC_EVT_ADDR_PLAYER_CHANGE: + break; + + case AVRC_EVT_UIDS_CHANGE: + break; + + case AVRC_EVT_TRACK_REACHED_END: + case AVRC_EVT_TRACK_REACHED_START: + case AVRC_EVT_PLAY_POS_CHANGED: + case AVRC_EVT_BATTERY_STATUS_CHANGE: + case AVRC_EVT_SYSTEM_STATUS_CHANGE: + default: + break; + } } -static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE *p_msg, tAVRC_RESPONSE *p_rsp) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - uint8_t pdu; - - if (p_msg->browse_len == 0) - { - AVRC_TRACE_ERROR("%s length ", p_msg->browse_len); - return AVRC_STS_BAD_PARAM; - } - - uint8_t *p = p_msg->p_browse_data; - - /* read the pdu */ - BE_STREAM_TO_UINT8(pdu, p); - uint8_t pkt_len; - /* read the entire packet len */ - BE_STREAM_TO_UINT16(pkt_len, p); - - AVRC_TRACE_DEBUG("%s pdu %d", __func__, pdu); - - /* used to track how much we have read, if we cannot read anymore but the - * packet says so then we have a malformed packet. Also vice versa. */ - uint16_t pkt_len_read = 0; - - - switch (pdu) - { - case AVRC_PDU_GET_FOLDER_ITEMS: - { - tAVRC_GET_ITEMS_RSP *get_item_rsp = &(p_rsp->get_items); - /* Copy back the PDU */ - get_item_rsp->pdu = pdu; - /* read the status */ - BE_STREAM_TO_UINT8(get_item_rsp->status, p); - /* read the UID counter */ - BE_STREAM_TO_UINT16(get_item_rsp->uid_counter, p); - /* read the number of items */ - BE_STREAM_TO_UINT16(get_item_rsp->item_count, p); - pkt_len_read += 5; - - AVRC_TRACE_DEBUG("%s pdu %d status %d pkt_len %d uid counter %d item count %d", - __func__, get_item_rsp->pdu, get_item_rsp->status, pkt_len, - get_item_rsp->uid_counter, get_item_rsp->item_count); - - if (get_item_rsp->status != AVRC_STS_NO_ERROR) { - AVRC_TRACE_WARNING("%s returning error %d", __func__, get_item_rsp->status); - return get_item_rsp->status; - } - - /* get each of the items */ - get_item_rsp->p_item_list = - (tAVRC_ITEM *) osi_malloc (get_item_rsp->item_count * (sizeof(tAVRC_ITEM))); - tAVRC_ITEM *curr_item = get_item_rsp->p_item_list; - for (int i = 0; i < get_item_rsp->item_count; i++) - { - BE_STREAM_TO_UINT8(curr_item->item_type, p); - pkt_len_read += 1; - AVRC_TRACE_DEBUG("%s item type %d", __func__, curr_item->item_type); - switch (curr_item->item_type) - { - case AVRC_ITEM_PLAYER: - { - /* Handle player */ - tAVRC_ITEM_PLAYER *player = &(curr_item->u.player); - uint8_t player_len; - BE_STREAM_TO_UINT16(player_len, p); - BE_STREAM_TO_UINT16(player->player_id, p); - BE_STREAM_TO_UINT8(player->major_type, p); - BE_STREAM_TO_UINT32(player->sub_type, p); - BE_STREAM_TO_UINT8(player->play_status, p); - BE_STREAM_TO_ARRAY(p, player->features, AVRC_FEATURE_MASK_SIZE); - pkt_len_read += (10 + AVRC_FEATURE_MASK_SIZE); - - /* read str */ - BE_STREAM_TO_UINT16(player->name.charset_id, p); - BE_STREAM_TO_UINT16(player->name.str_len, p); - player->name.p_str = (uint8_t *) osi_malloc ( - (player->name.str_len + 1) * sizeof (uint8_t)); - BE_STREAM_TO_ARRAY(p, player->name.p_str, player->name.str_len); - pkt_len_read += (4 + player->name.str_len); - AVRC_TRACE_DEBUG( - "%s type %d id %d mtype %d stype %d ps %d cs %d name len %d", - __func__, curr_item->item_type, player->player_id, - player->major_type, player->sub_type, player->play_status, - player->name.charset_id, player->name.str_len); - } break; - - case AVRC_ITEM_FOLDER: - { - tAVRC_ITEM_FOLDER *folder = &(curr_item->u.folder); - uint16_t folder_len; - BE_STREAM_TO_UINT16(folder_len, p); - - BE_STREAM_TO_ARRAY(p, folder->uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT8(folder->type, p); - BE_STREAM_TO_UINT8(folder->playable, p); - pkt_len_read += (4 + AVRC_UID_SIZE); - - /* read str, encoding to be handled by upper layers */ - BE_STREAM_TO_UINT16(folder->name.charset_id, p); - BE_STREAM_TO_UINT16(folder->name.str_len, p); - folder->name.p_str = (uint8_t *) osi_malloc ( - (folder->name.str_len + 1) * sizeof (uint8_t)); - BE_STREAM_TO_ARRAY(p, folder->name.p_str, folder->name.str_len); - pkt_len_read += (4 + folder->name.str_len); - AVRC_TRACE_DEBUG( - "%s type %d playable %d cs %d name len %d", - __func__, folder->type, folder->playable, folder->name.charset_id, - folder->name.str_len); - } break; - - case AVRC_ITEM_MEDIA: - { - tAVRC_ITEM_MEDIA *media = &(curr_item->u.media); - uint8_t media_len; - BE_STREAM_TO_UINT16(media_len, p); - BE_STREAM_TO_ARRAY(p, media->uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT8(media->type, p); - pkt_len_read += (3 + AVRC_UID_SIZE); - - /* read str, encoding to be handled by upper layers */ - BE_STREAM_TO_UINT16(media->name.charset_id, p); - BE_STREAM_TO_UINT16(media->name.str_len, p); - media->name.p_str = (uint8_t *) osi_malloc ( - (media->name.str_len) * sizeof (uint8_t)); - BE_STREAM_TO_ARRAY(p, media->name.p_str, media->name.str_len); - - BE_STREAM_TO_UINT8(media->attr_count, p); - AVRC_TRACE_DEBUG("%s media type %d charset id %d len %d attr ct %d", - __func__, media->type, media->name.charset_id, - media->name.str_len, media->attr_count); - pkt_len_read += (5 + media->name.str_len); - - media->p_attr_list = (tAVRC_ATTR_ENTRY *) osi_malloc ( - media->attr_count * sizeof (tAVRC_ATTR_ENTRY)); - for (int jk = 0; jk < media->attr_count; jk++) - { - tAVRC_ATTR_ENTRY *attr_entry = &(media->p_attr_list[jk]); - BE_STREAM_TO_UINT32(attr_entry->attr_id, p); - - /* Parse the name now */ - BE_STREAM_TO_UINT16(attr_entry->name.charset_id, p); - BE_STREAM_TO_UINT16(attr_entry->name.str_len, p); - attr_entry->name.p_str = (uint8_t *) osi_malloc ( - attr_entry->name.str_len * sizeof (uint8_t)); - BE_STREAM_TO_ARRAY(p, attr_entry->name.p_str, attr_entry->name.str_len); - pkt_len_read += (8 + attr_entry->name.str_len); - AVRC_TRACE_DEBUG("%s media attr id %d cs %d name len %d", - __func__, attr_entry->attr_id, - attr_entry->name.charset_id, attr_entry->name.str_len); - } - } break; - - default: - AVRC_TRACE_ERROR("%s item type not handled %d", __func__, curr_item->item_type); - return AVRC_STS_INTERNAL_ERR; +static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE* p_msg, + tAVRC_RESPONSE* p_rsp) { + tAVRC_STS status = AVRC_STS_NO_ERROR; + uint8_t pdu; + + if (p_msg->browse_len == 0) { + AVRC_TRACE_ERROR("%s length ", p_msg->browse_len); + return AVRC_STS_BAD_PARAM; + } + + uint8_t* p = p_msg->p_browse_data; + + /* read the pdu */ + BE_STREAM_TO_UINT8(pdu, p); + uint8_t pkt_len; + /* read the entire packet len */ + BE_STREAM_TO_UINT16(pkt_len, p); + + AVRC_TRACE_DEBUG("%s pdu %d", __func__, pdu); + + /* used to track how much we have read, if we cannot read anymore but the + * packet says so then we have a malformed packet. Also vice versa. */ + uint16_t pkt_len_read = 0; + + switch (pdu) { + case AVRC_PDU_GET_FOLDER_ITEMS: { + tAVRC_GET_ITEMS_RSP* get_item_rsp = &(p_rsp->get_items); + /* Copy back the PDU */ + get_item_rsp->pdu = pdu; + /* read the status */ + BE_STREAM_TO_UINT8(get_item_rsp->status, p); + /* read the UID counter */ + BE_STREAM_TO_UINT16(get_item_rsp->uid_counter, p); + /* read the number of items */ + BE_STREAM_TO_UINT16(get_item_rsp->item_count, p); + pkt_len_read += 5; + + AVRC_TRACE_DEBUG( + "%s pdu %d status %d pkt_len %d uid counter %d item count %d", + __func__, get_item_rsp->pdu, get_item_rsp->status, pkt_len, + get_item_rsp->uid_counter, get_item_rsp->item_count); + + if (get_item_rsp->status != AVRC_STS_NO_ERROR) { + AVRC_TRACE_WARNING("%s returning error %d", __func__, + get_item_rsp->status); + return get_item_rsp->status; + } + + /* get each of the items */ + get_item_rsp->p_item_list = (tAVRC_ITEM*)osi_malloc( + get_item_rsp->item_count * (sizeof(tAVRC_ITEM))); + tAVRC_ITEM* curr_item = get_item_rsp->p_item_list; + for (int i = 0; i < get_item_rsp->item_count; i++) { + BE_STREAM_TO_UINT8(curr_item->item_type, p); + pkt_len_read += 1; + AVRC_TRACE_DEBUG("%s item type %d", __func__, curr_item->item_type); + switch (curr_item->item_type) { + case AVRC_ITEM_PLAYER: { + /* Handle player */ + tAVRC_ITEM_PLAYER* player = &(curr_item->u.player); + uint8_t player_len; + BE_STREAM_TO_UINT16(player_len, p); + BE_STREAM_TO_UINT16(player->player_id, p); + BE_STREAM_TO_UINT8(player->major_type, p); + BE_STREAM_TO_UINT32(player->sub_type, p); + BE_STREAM_TO_UINT8(player->play_status, p); + BE_STREAM_TO_ARRAY(p, player->features, AVRC_FEATURE_MASK_SIZE); + pkt_len_read += (10 + AVRC_FEATURE_MASK_SIZE); + + /* read str */ + BE_STREAM_TO_UINT16(player->name.charset_id, p); + BE_STREAM_TO_UINT16(player->name.str_len, p); + player->name.p_str = (uint8_t*)osi_malloc( + (player->name.str_len + 1) * sizeof(uint8_t)); + BE_STREAM_TO_ARRAY(p, player->name.p_str, player->name.str_len); + pkt_len_read += (4 + player->name.str_len); + AVRC_TRACE_DEBUG( + "%s type %d id %d mtype %d stype %d ps %d cs %d name len %d", + __func__, curr_item->item_type, player->player_id, + player->major_type, player->sub_type, player->play_status, + player->name.charset_id, player->name.str_len); + } break; + + case AVRC_ITEM_FOLDER: { + tAVRC_ITEM_FOLDER* folder = &(curr_item->u.folder); + uint16_t folder_len; + BE_STREAM_TO_UINT16(folder_len, p); + + BE_STREAM_TO_ARRAY(p, folder->uid, AVRC_UID_SIZE); + BE_STREAM_TO_UINT8(folder->type, p); + BE_STREAM_TO_UINT8(folder->playable, p); + pkt_len_read += (4 + AVRC_UID_SIZE); + + /* read str, encoding to be handled by upper layers */ + BE_STREAM_TO_UINT16(folder->name.charset_id, p); + BE_STREAM_TO_UINT16(folder->name.str_len, p); + folder->name.p_str = (uint8_t*)osi_malloc( + (folder->name.str_len + 1) * sizeof(uint8_t)); + BE_STREAM_TO_ARRAY(p, folder->name.p_str, folder->name.str_len); + pkt_len_read += (4 + folder->name.str_len); + AVRC_TRACE_DEBUG("%s type %d playable %d cs %d name len %d", + __func__, folder->type, folder->playable, + folder->name.charset_id, folder->name.str_len); + } break; + + case AVRC_ITEM_MEDIA: { + tAVRC_ITEM_MEDIA* media = &(curr_item->u.media); + uint8_t media_len; + BE_STREAM_TO_UINT16(media_len, p); + BE_STREAM_TO_ARRAY(p, media->uid, AVRC_UID_SIZE); + BE_STREAM_TO_UINT8(media->type, p); + pkt_len_read += (3 + AVRC_UID_SIZE); + + /* read str, encoding to be handled by upper layers */ + BE_STREAM_TO_UINT16(media->name.charset_id, p); + BE_STREAM_TO_UINT16(media->name.str_len, p); + media->name.p_str = + (uint8_t*)osi_malloc((media->name.str_len) * sizeof(uint8_t)); + BE_STREAM_TO_ARRAY(p, media->name.p_str, media->name.str_len); + + BE_STREAM_TO_UINT8(media->attr_count, p); + AVRC_TRACE_DEBUG("%s media type %d charset id %d len %d attr ct %d", + __func__, media->type, media->name.charset_id, + media->name.str_len, media->attr_count); + pkt_len_read += (5 + media->name.str_len); + + media->p_attr_list = (tAVRC_ATTR_ENTRY*)osi_malloc( + media->attr_count * sizeof(tAVRC_ATTR_ENTRY)); + for (int jk = 0; jk < media->attr_count; jk++) { + tAVRC_ATTR_ENTRY* attr_entry = &(media->p_attr_list[jk]); + BE_STREAM_TO_UINT32(attr_entry->attr_id, p); + + /* Parse the name now */ + BE_STREAM_TO_UINT16(attr_entry->name.charset_id, p); + BE_STREAM_TO_UINT16(attr_entry->name.str_len, p); + attr_entry->name.p_str = (uint8_t*)osi_malloc( + attr_entry->name.str_len * sizeof(uint8_t)); + BE_STREAM_TO_ARRAY(p, attr_entry->name.p_str, + attr_entry->name.str_len); + pkt_len_read += (8 + attr_entry->name.str_len); + AVRC_TRACE_DEBUG("%s media attr id %d cs %d name len %d", + __func__, attr_entry->attr_id, + attr_entry->name.charset_id, + attr_entry->name.str_len); } + } break; - /* we check if we have overrun */ - if (pkt_len_read > pkt_len) - { - AVRC_TRACE_ERROR("%s overflow in read pkt_len %d pkt_len_read %d", - __func__, pkt_len, pkt_len_read); - return AVRC_STS_BAD_CMD; - } - AVRC_TRACE_DEBUG("%s pkt_len %d pkt_len_read %d", __func__, pkt_len, pkt_len_read); + default: + AVRC_TRACE_ERROR("%s item type not handled %d", __func__, + curr_item->item_type); + return AVRC_STS_INTERNAL_ERR; + } - /* advance to populate the next item */ - curr_item++; + /* we check if we have overrun */ + if (pkt_len_read > pkt_len) { + AVRC_TRACE_ERROR("%s overflow in read pkt_len %d pkt_len_read %d", + __func__, pkt_len, pkt_len_read); + return AVRC_STS_BAD_CMD; } - break; + AVRC_TRACE_DEBUG("%s pkt_len %d pkt_len_read %d", __func__, pkt_len, + pkt_len_read); + + /* advance to populate the next item */ + curr_item++; + } + break; } - case AVRC_PDU_CHANGE_PATH: - { - tAVRC_CHG_PATH_RSP *change_path_rsp = &(p_rsp->chg_path); - /* Copyback the PDU */ - change_path_rsp->pdu = pdu; - /* Read the status */ - BE_STREAM_TO_UINT8(change_path_rsp->status, p); - /* Read the number of items in folder */ - BE_STREAM_TO_UINT32(change_path_rsp->num_items, p); - pkt_len_read += 5; - - AVRC_TRACE_DEBUG("%s pdu %d status %d item count %d", - __func__, change_path_rsp->pdu, change_path_rsp->status, - change_path_rsp->num_items); - break; + case AVRC_PDU_CHANGE_PATH: { + tAVRC_CHG_PATH_RSP* change_path_rsp = &(p_rsp->chg_path); + /* Copyback the PDU */ + change_path_rsp->pdu = pdu; + /* Read the status */ + BE_STREAM_TO_UINT8(change_path_rsp->status, p); + /* Read the number of items in folder */ + BE_STREAM_TO_UINT32(change_path_rsp->num_items, p); + pkt_len_read += 5; + + AVRC_TRACE_DEBUG("%s pdu %d status %d item count %d", __func__, + change_path_rsp->pdu, change_path_rsp->status, + change_path_rsp->num_items); + break; } - case AVRC_PDU_SET_BROWSED_PLAYER: - { - tAVRC_SET_BR_PLAYER_RSP *set_br_pl_rsp = &(p_rsp->br_player); - /* Copyback the PDU */ - set_br_pl_rsp->pdu = pdu; + case AVRC_PDU_SET_BROWSED_PLAYER: { + tAVRC_SET_BR_PLAYER_RSP* set_br_pl_rsp = &(p_rsp->br_player); + /* Copyback the PDU */ + set_br_pl_rsp->pdu = pdu; - /* Read the status */ - BE_STREAM_TO_UINT8(set_br_pl_rsp->status, p); + /* Read the status */ + BE_STREAM_TO_UINT8(set_br_pl_rsp->status, p); - if (set_br_pl_rsp->status != AVRC_STS_NO_ERROR) { - AVRC_TRACE_ERROR( - "%s Stopping further parsing because player not browsable sts %d", - __func__, set_br_pl_rsp->status); - break; - } - BE_STREAM_TO_UINT16(set_br_pl_rsp->uid_counter, p); - BE_STREAM_TO_UINT32(set_br_pl_rsp->num_items, p); - BE_STREAM_TO_UINT16(set_br_pl_rsp->charset_id, p); - BE_STREAM_TO_UINT8(set_br_pl_rsp->folder_depth, p); - AVRC_TRACE_DEBUG("%s AVRC_PDU_SET_BROWSED_PLAYER status %d items %d cs %d depth %d", - __func__, - set_br_pl_rsp->status, - set_br_pl_rsp->num_items, - set_br_pl_rsp->charset_id, - set_br_pl_rsp->folder_depth); - pkt_len_read += 10; - - set_br_pl_rsp->p_folders = (tAVRC_NAME *) osi_malloc ( - set_br_pl_rsp->num_items * sizeof (tAVRC_NAME)); - - /* Read each of the folder in the depth */ - for (uint32_t i = 0; i < set_br_pl_rsp->folder_depth; i++) { - tAVRC_NAME *folder_name = &(set_br_pl_rsp->p_folders[i]); - BE_STREAM_TO_UINT16(folder_name->str_len, p); - AVRC_TRACE_DEBUG("%s AVRC_PDU_SET_BROWSED_PLAYER item: %d len: %d", - __func__, i, folder_name->str_len); - folder_name->p_str = (uint8_t *) osi_malloc ( - (folder_name->str_len + 1) * sizeof (uint8_t)); - BE_STREAM_TO_ARRAY(p, folder_name->p_str, folder_name->str_len); - pkt_len_read += (2 + folder_name->str_len); - } + if (set_br_pl_rsp->status != AVRC_STS_NO_ERROR) { + AVRC_TRACE_ERROR( + "%s Stopping further parsing because player not browsable sts %d", + __func__, set_br_pl_rsp->status); break; + } + BE_STREAM_TO_UINT16(set_br_pl_rsp->uid_counter, p); + BE_STREAM_TO_UINT32(set_br_pl_rsp->num_items, p); + BE_STREAM_TO_UINT16(set_br_pl_rsp->charset_id, p); + BE_STREAM_TO_UINT8(set_br_pl_rsp->folder_depth, p); + AVRC_TRACE_DEBUG( + "%s AVRC_PDU_SET_BROWSED_PLAYER status %d items %d cs %d depth %d", + __func__, set_br_pl_rsp->status, set_br_pl_rsp->num_items, + set_br_pl_rsp->charset_id, set_br_pl_rsp->folder_depth); + pkt_len_read += 10; + + set_br_pl_rsp->p_folders = (tAVRC_NAME*)osi_malloc( + set_br_pl_rsp->num_items * sizeof(tAVRC_NAME)); + + /* Read each of the folder in the depth */ + for (uint32_t i = 0; i < set_br_pl_rsp->folder_depth; i++) { + tAVRC_NAME* folder_name = &(set_br_pl_rsp->p_folders[i]); + BE_STREAM_TO_UINT16(folder_name->str_len, p); + AVRC_TRACE_DEBUG("%s AVRC_PDU_SET_BROWSED_PLAYER item: %d len: %d", + __func__, i, folder_name->str_len); + folder_name->p_str = + (uint8_t*)osi_malloc((folder_name->str_len + 1) * sizeof(uint8_t)); + BE_STREAM_TO_ARRAY(p, folder_name->p_str, folder_name->str_len); + pkt_len_read += (2 + folder_name->str_len); + } + break; } default: - AVRC_TRACE_ERROR("%s pdu %d not handled", __func__, pdu); - } - - if (pkt_len != pkt_len_read) - { - AVRC_TRACE_ERROR("%s finished pkt_len %d pkt_len_read %d", __func__, pkt_len, pkt_len_read); - return AVRC_STS_BAD_CMD; - } - return status; + AVRC_TRACE_ERROR("%s pdu %d not handled", __func__, pdu); + } + + if (pkt_len != pkt_len_read) { + AVRC_TRACE_ERROR("%s finished pkt_len %d pkt_len_read %d", __func__, + pkt_len, pkt_len_read); + return AVRC_STS_BAD_CMD; + } + return status; } /******************************************************************************* @@ -411,228 +398,216 @@ static tAVRC_STS avrc_pars_browse_rsp(tAVRC_MSG_BROWSE *p_msg, tAVRC_RESPONSE *p * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -static tAVRC_STS avrc_ctrl_pars_vendor_rsp( - tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result, uint8_t* p_buf, uint16_t* buf_len) -{ - uint8_t *p = p_msg->p_vendor_data; - BE_STREAM_TO_UINT8 (p_result->pdu, p); - p++; /* skip the reserved/packe_type byte */ - - uint16_t len; - BE_STREAM_TO_UINT16 (len, p); - AVRC_TRACE_DEBUG("%s ctype:0x%x pdu:0x%x, len:%d", - __func__, p_msg->hdr.ctype, p_result->pdu, len); - /* Todo: Issue in handling reject, check */ - if (p_msg->hdr.ctype == AVRC_RSP_REJ) - { - p_result->rsp.status = *p; - return p_result->rsp.status; - } - - /* TODO: Break the big switch into functions. */ - switch (p_result->pdu) - { +static tAVRC_STS avrc_ctrl_pars_vendor_rsp(tAVRC_MSG_VENDOR* p_msg, + tAVRC_RESPONSE* p_result, + uint8_t* p_buf, uint16_t* buf_len) { + uint8_t* p = p_msg->p_vendor_data; + BE_STREAM_TO_UINT8(p_result->pdu, p); + p++; /* skip the reserved/packe_type byte */ + + uint16_t len; + BE_STREAM_TO_UINT16(len, p); + AVRC_TRACE_DEBUG("%s ctype:0x%x pdu:0x%x, len:%d", __func__, p_msg->hdr.ctype, + p_result->pdu, len); + /* Todo: Issue in handling reject, check */ + if (p_msg->hdr.ctype == AVRC_RSP_REJ) { + p_result->rsp.status = *p; + return p_result->rsp.status; + } + + /* TODO: Break the big switch into functions. */ + switch (p_result->pdu) { /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ case AVRC_PDU_REGISTER_NOTIFICATION: - avrc_parse_notification_rsp(p, &p_result->reg_notif); - break; + avrc_parse_notification_rsp(p, &p_result->reg_notif); + break; case AVRC_PDU_GET_CAPABILITIES: - if (len == 0) - { - p_result->get_caps.count = 0; - p_result->get_caps.capability_id = 0; - break; + if (len == 0) { + p_result->get_caps.count = 0; + p_result->get_caps.capability_id = 0; + break; + } + BE_STREAM_TO_UINT8(p_result->get_caps.capability_id, p); + BE_STREAM_TO_UINT8(p_result->get_caps.count, p); + AVRC_TRACE_DEBUG("%s cap id = %d, cap_count = %d ", __func__, + p_result->get_caps.capability_id, + p_result->get_caps.count); + if (p_result->get_caps.capability_id == AVRC_CAP_COMPANY_ID) { + for (int xx = 0; ((xx < p_result->get_caps.count) && + (xx < AVRC_CAP_MAX_NUM_COMP_ID)); + xx++) { + BE_STREAM_TO_UINT24(p_result->get_caps.param.company_id[xx], p); } - BE_STREAM_TO_UINT8(p_result->get_caps.capability_id, p); - BE_STREAM_TO_UINT8(p_result->get_caps.count, p); - AVRC_TRACE_DEBUG("%s cap id = %d, cap_count = %d ", - __func__, p_result->get_caps.capability_id, p_result->get_caps.count); - if (p_result->get_caps.capability_id == AVRC_CAP_COMPANY_ID) - { - for(int xx = 0; ((xx < p_result->get_caps.count) && (xx < AVRC_CAP_MAX_NUM_COMP_ID)); - xx++) - { - BE_STREAM_TO_UINT24(p_result->get_caps.param.company_id[xx], p); - } + } else if (p_result->get_caps.capability_id == + AVRC_CAP_EVENTS_SUPPORTED) { + for (int xx = 0; ((xx < p_result->get_caps.count) && + (xx < AVRC_CAP_MAX_NUM_EVT_ID)); + xx++) { + BE_STREAM_TO_UINT8(p_result->get_caps.param.event_id[xx], p); } - else if (p_result->get_caps.capability_id == AVRC_CAP_EVENTS_SUPPORTED) - { - for(int xx = 0; ((xx < p_result->get_caps.count) && (xx < AVRC_CAP_MAX_NUM_EVT_ID)); - xx++) - { - BE_STREAM_TO_UINT8(p_result->get_caps.param.event_id[xx], p); - } - } - break; + } + break; case AVRC_PDU_LIST_PLAYER_APP_ATTR: - if (len == 0) - { - p_result->list_app_attr.num_attr = 0; - break; - } - BE_STREAM_TO_UINT8(p_result->list_app_attr.num_attr, p); - AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, p_result->list_app_attr.num_attr); - for(int xx = 0; xx < p_result->list_app_attr.num_attr; xx++) - { - BE_STREAM_TO_UINT8(p_result->list_app_attr.attrs[xx], p); - } + if (len == 0) { + p_result->list_app_attr.num_attr = 0; break; + } + BE_STREAM_TO_UINT8(p_result->list_app_attr.num_attr, p); + AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, + p_result->list_app_attr.num_attr); + for (int xx = 0; xx < p_result->list_app_attr.num_attr; xx++) { + BE_STREAM_TO_UINT8(p_result->list_app_attr.attrs[xx], p); + } + break; case AVRC_PDU_LIST_PLAYER_APP_VALUES: - if (len == 0) - { - p_result->list_app_values.num_val = 0; - break; - } - BE_STREAM_TO_UINT8(p_result->list_app_values.num_val, p); - AVRC_TRACE_DEBUG("%s value count = %d ", __func__, p_result->list_app_values.num_val); - for(int xx = 0; xx < p_result->list_app_values.num_val; xx++) - { - BE_STREAM_TO_UINT8(p_result->list_app_values.vals[xx], p); - } + if (len == 0) { + p_result->list_app_values.num_val = 0; break; - - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: - { - if (len == 0) - { - p_result->get_cur_app_val.num_val = 0; - break; - } - BE_STREAM_TO_UINT8(p_result->get_cur_app_val.num_val, p); - tAVRC_APP_SETTING *app_sett = - (tAVRC_APP_SETTING*)osi_malloc(p_result->get_cur_app_val.num_val*sizeof(tAVRC_APP_SETTING)); - AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, p_result->get_cur_app_val.num_val); - for (int xx = 0; xx < p_result->get_cur_app_val.num_val; xx++) - { - BE_STREAM_TO_UINT8(app_sett[xx].attr_id, p); - BE_STREAM_TO_UINT8(app_sett[xx].attr_val, p); - } - p_result->get_cur_app_val.p_vals = app_sett; - } + } + BE_STREAM_TO_UINT8(p_result->list_app_values.num_val, p); + AVRC_TRACE_DEBUG("%s value count = %d ", __func__, + p_result->list_app_values.num_val); + for (int xx = 0; xx < p_result->list_app_values.num_val; xx++) { + BE_STREAM_TO_UINT8(p_result->list_app_values.vals[xx], p); + } + break; + + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: { + if (len == 0) { + p_result->get_cur_app_val.num_val = 0; break; - - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: - { - tAVRC_APP_SETTING_TEXT *p_setting_text; - uint8_t num_attrs; - - if (len == 0) - { - p_result->get_app_attr_txt.num_attr = 0; - break; - } - BE_STREAM_TO_UINT8(num_attrs, p); - AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, p_result->get_app_attr_txt.num_attr); - p_result->get_app_attr_txt.num_attr = num_attrs; - p_setting_text = (tAVRC_APP_SETTING_TEXT*)osi_malloc(num_attrs * sizeof(tAVRC_APP_SETTING_TEXT)); - for (int xx = 0; xx < num_attrs; xx++) - { - BE_STREAM_TO_UINT8(p_result->get_app_attr_txt.p_attrs[xx].attr_id, p); - BE_STREAM_TO_UINT16(p_result->get_app_attr_txt.p_attrs[xx].charset_id, p); - BE_STREAM_TO_UINT8(p_result->get_app_attr_txt.p_attrs[xx].str_len, p); - if (p_result->get_app_attr_txt.p_attrs[xx].str_len != 0) - { - uint8_t *p_str = (uint8_t *)osi_malloc(p_result->get_app_attr_txt.p_attrs[xx].str_len); - BE_STREAM_TO_ARRAY(p, p_str, p_result->get_app_attr_txt.p_attrs[xx].str_len); - p_result->get_app_attr_txt.p_attrs[xx].p_str = p_str; - } else { - p_result->get_app_attr_txt.p_attrs[xx].p_str = NULL; - } - } - } + } + BE_STREAM_TO_UINT8(p_result->get_cur_app_val.num_val, p); + tAVRC_APP_SETTING* app_sett = (tAVRC_APP_SETTING*)osi_malloc( + p_result->get_cur_app_val.num_val * sizeof(tAVRC_APP_SETTING)); + AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, + p_result->get_cur_app_val.num_val); + for (int xx = 0; xx < p_result->get_cur_app_val.num_val; xx++) { + BE_STREAM_TO_UINT8(app_sett[xx].attr_id, p); + BE_STREAM_TO_UINT8(app_sett[xx].attr_val, p); + } + p_result->get_cur_app_val.p_vals = app_sett; + } break; + + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: { + tAVRC_APP_SETTING_TEXT* p_setting_text; + uint8_t num_attrs; + + if (len == 0) { + p_result->get_app_attr_txt.num_attr = 0; break; + } + BE_STREAM_TO_UINT8(num_attrs, p); + AVRC_TRACE_DEBUG("%s attr count = %d ", __func__, + p_result->get_app_attr_txt.num_attr); + p_result->get_app_attr_txt.num_attr = num_attrs; + p_setting_text = (tAVRC_APP_SETTING_TEXT*)osi_malloc( + num_attrs * sizeof(tAVRC_APP_SETTING_TEXT)); + for (int xx = 0; xx < num_attrs; xx++) { + BE_STREAM_TO_UINT8(p_result->get_app_attr_txt.p_attrs[xx].attr_id, p); + BE_STREAM_TO_UINT16(p_result->get_app_attr_txt.p_attrs[xx].charset_id, + p); + BE_STREAM_TO_UINT8(p_result->get_app_attr_txt.p_attrs[xx].str_len, p); + if (p_result->get_app_attr_txt.p_attrs[xx].str_len != 0) { + uint8_t* p_str = (uint8_t*)osi_malloc( + p_result->get_app_attr_txt.p_attrs[xx].str_len); + BE_STREAM_TO_ARRAY(p, p_str, + p_result->get_app_attr_txt.p_attrs[xx].str_len); + p_result->get_app_attr_txt.p_attrs[xx].p_str = p_str; + } else { + p_result->get_app_attr_txt.p_attrs[xx].p_str = NULL; + } + } + } break; - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: - { - tAVRC_APP_SETTING_TEXT *p_setting_text; - uint8_t num_vals; + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: { + tAVRC_APP_SETTING_TEXT* p_setting_text; + uint8_t num_vals; - if (len == 0) - { - p_result->get_app_val_txt.num_attr = 0; - break; - } - BE_STREAM_TO_UINT8(num_vals, p); - p_result->get_app_val_txt.num_attr = num_vals; - AVRC_TRACE_DEBUG("%s value count = %d ", __func__, p_result->get_app_val_txt.num_attr); - - p_setting_text = (tAVRC_APP_SETTING_TEXT *)osi_malloc(num_vals * sizeof(tAVRC_APP_SETTING_TEXT)); - for (int i = 0; i < num_vals; i++) { - BE_STREAM_TO_UINT8(p_result->get_app_val_txt.p_attrs[i].attr_id, p); - BE_STREAM_TO_UINT16(p_result->get_app_val_txt.p_attrs[i].charset_id, p); - BE_STREAM_TO_UINT8(p_result->get_app_val_txt.p_attrs[i].str_len, p); - if (p_result->get_app_val_txt.p_attrs[i].str_len != 0) { - uint8_t *p_str = (uint8_t *)osi_malloc(p_result->get_app_val_txt.p_attrs[i].str_len); - BE_STREAM_TO_ARRAY(p, p_str, p_result->get_app_val_txt.p_attrs[i].str_len); - p_result->get_app_val_txt.p_attrs[i].p_str = p_str; - } else { - p_result->get_app_val_txt.p_attrs[i].p_str = NULL; - } - } - } + if (len == 0) { + p_result->get_app_val_txt.num_attr = 0; break; + } + BE_STREAM_TO_UINT8(num_vals, p); + p_result->get_app_val_txt.num_attr = num_vals; + AVRC_TRACE_DEBUG("%s value count = %d ", __func__, + p_result->get_app_val_txt.num_attr); + + p_setting_text = (tAVRC_APP_SETTING_TEXT*)osi_malloc( + num_vals * sizeof(tAVRC_APP_SETTING_TEXT)); + for (int i = 0; i < num_vals; i++) { + BE_STREAM_TO_UINT8(p_result->get_app_val_txt.p_attrs[i].attr_id, p); + BE_STREAM_TO_UINT16(p_result->get_app_val_txt.p_attrs[i].charset_id, p); + BE_STREAM_TO_UINT8(p_result->get_app_val_txt.p_attrs[i].str_len, p); + if (p_result->get_app_val_txt.p_attrs[i].str_len != 0) { + uint8_t* p_str = (uint8_t*)osi_malloc( + p_result->get_app_val_txt.p_attrs[i].str_len); + BE_STREAM_TO_ARRAY(p, p_str, + p_result->get_app_val_txt.p_attrs[i].str_len); + p_result->get_app_val_txt.p_attrs[i].p_str = p_str; + } else { + p_result->get_app_val_txt.p_attrs[i].p_str = NULL; + } + } + } break; case AVRC_PDU_SET_PLAYER_APP_VALUE: - /* nothing comes as part of this rsp */ - break; + /* nothing comes as part of this rsp */ + break; - case AVRC_PDU_GET_ELEMENT_ATTR: - { - uint8_t num_attrs; + case AVRC_PDU_GET_ELEMENT_ATTR: { + uint8_t num_attrs; - if (len <= 0) - { - p_result->get_attrs.num_attrs = 0; - break; - } - BE_STREAM_TO_UINT8(num_attrs, p); - p_result->get_attrs.num_attrs = num_attrs; - if (num_attrs) - { - tAVRC_ATTR_ENTRY *p_attrs = - (tAVRC_ATTR_ENTRY*)osi_malloc(num_attrs * sizeof(tAVRC_ATTR_ENTRY)); - for (int i = 0; i < num_attrs; i++) { - BE_STREAM_TO_UINT32(p_attrs[i].attr_id, p); - BE_STREAM_TO_UINT16(p_attrs[i].name.charset_id, p); - BE_STREAM_TO_UINT16(p_attrs[i].name.str_len, p); - if (p_attrs[i].name.str_len > 0) { - p_attrs[i].name.p_str = (uint8_t *)osi_malloc(p_attrs[i].name.str_len); - BE_STREAM_TO_ARRAY(p, p_attrs[i].name.p_str, p_attrs[i].name.str_len); - } - } - p_result->get_attrs.p_attrs = p_attrs; - } - } + if (len <= 0) { + p_result->get_attrs.num_attrs = 0; break; + } + BE_STREAM_TO_UINT8(num_attrs, p); + p_result->get_attrs.num_attrs = num_attrs; + if (num_attrs) { + tAVRC_ATTR_ENTRY* p_attrs = + (tAVRC_ATTR_ENTRY*)osi_malloc(num_attrs * sizeof(tAVRC_ATTR_ENTRY)); + for (int i = 0; i < num_attrs; i++) { + BE_STREAM_TO_UINT32(p_attrs[i].attr_id, p); + BE_STREAM_TO_UINT16(p_attrs[i].name.charset_id, p); + BE_STREAM_TO_UINT16(p_attrs[i].name.str_len, p); + if (p_attrs[i].name.str_len > 0) { + p_attrs[i].name.p_str = + (uint8_t*)osi_malloc(p_attrs[i].name.str_len); + BE_STREAM_TO_ARRAY(p, p_attrs[i].name.p_str, + p_attrs[i].name.str_len); + } + } + p_result->get_attrs.p_attrs = p_attrs; + } + } break; case AVRC_PDU_GET_PLAY_STATUS: - if (len == 0) - { - break; - } - BE_STREAM_TO_UINT32(p_result->get_play_status.song_len, p); - BE_STREAM_TO_UINT32(p_result->get_play_status.song_pos, p); - BE_STREAM_TO_UINT8(p_result->get_play_status.status, p); + if (len == 0) { break; + } + BE_STREAM_TO_UINT32(p_result->get_play_status.song_len, p); + BE_STREAM_TO_UINT32(p_result->get_play_status.song_pos, p); + BE_STREAM_TO_UINT8(p_result->get_play_status.status, p); + break; case AVRC_PDU_SET_ADDRESSED_PLAYER: - if (len != 1) - { - AVRC_TRACE_ERROR("%s pdu: %d len %d", __func__, p_result->pdu, len); - return AVRC_STS_BAD_CMD; - } - BE_STREAM_TO_UINT8(p_result->rsp.status, p); - break; + if (len != 1) { + AVRC_TRACE_ERROR("%s pdu: %d len %d", __func__, p_result->pdu, len); + return AVRC_STS_BAD_CMD; + } + BE_STREAM_TO_UINT8(p_result->rsp.status, p); + break; default: - return AVRC_STS_BAD_CMD; - } - return AVRC_STS_NO_ERROR; + return AVRC_STS_BAD_CMD; + } + return AVRC_STS_NO_ERROR; } /******************************************************************************* @@ -646,29 +621,28 @@ static tAVRC_STS avrc_ctrl_pars_vendor_rsp( * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -tAVRC_STS AVRC_Ctrl_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, uint8_t *p_buf, uint16_t* buf_len) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_ctrl_pars_vendor_rsp(&p_msg->vendor, p_result, p_buf,buf_len); - break; - - case AVRC_OP_BROWSE: /* 0xff Browse commands */ - status = avrc_pars_browse_rsp(&p_msg->browse, p_result); - break; - - default: - AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); - break; - } - p_result->rsp.opcode = p_msg->hdr.opcode; - p_result->rsp.status = status; +tAVRC_STS AVRC_Ctrl_ParsResponse(tAVRC_MSG* p_msg, tAVRC_RESPONSE* p_result, + uint8_t* p_buf, uint16_t* buf_len) { + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + if (p_msg && p_result) { + switch (p_msg->hdr.opcode) { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = + avrc_ctrl_pars_vendor_rsp(&p_msg->vendor, p_result, p_buf, buf_len); + break; + + case AVRC_OP_BROWSE: /* 0xff Browse commands */ + status = avrc_pars_browse_rsp(&p_msg->browse, p_result); + break; + + default: + AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); + break; } - return status; + p_result->rsp.opcode = p_msg->hdr.opcode; + p_result->rsp.status = status; + } + return status; } /******************************************************************************* @@ -683,36 +657,32 @@ tAVRC_STS AVRC_Ctrl_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, ui * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, - UNUSED_ATTR uint8_t *p_buf, - UNUSED_ATTR uint16_t buf_len) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - uint16_t id; - - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result); - break; - - case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ - status = avrc_pars_pass_thru(&p_msg->pass, &id); - if (status == AVRC_STS_NO_ERROR) - { - p_result->pdu = (uint8_t)id; - } - break; +tAVRC_STS AVRC_ParsResponse(tAVRC_MSG* p_msg, tAVRC_RESPONSE* p_result, + UNUSED_ATTR uint8_t* p_buf, + UNUSED_ATTR uint16_t buf_len) { + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + uint16_t id; + + if (p_msg && p_result) { + switch (p_msg->hdr.opcode) { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result); + break; - default: - AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); - break; + case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ + status = avrc_pars_pass_thru(&p_msg->pass, &id); + if (status == AVRC_STS_NO_ERROR) { + p_result->pdu = (uint8_t)id; } - p_result->rsp.opcode = p_msg->hdr.opcode; - p_result->rsp.status = status; + break; + + default: + AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); + break; } - return status; + p_result->rsp.opcode = p_msg->hdr.opcode; + p_result->rsp.status = status; + } + return status; } #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ diff --git a/stack/avrc/avrc_pars_tg.cc b/stack/avrc/avrc_pars_tg.cc index c4dde79a2..cc5ec1de0 100644 --- a/stack/avrc/avrc_pars_tg.cc +++ b/stack/avrc/avrc_pars_tg.cc @@ -17,10 +17,10 @@ ******************************************************************************/ #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_defs.h" #include "avrc_int.h" +#include "bt_common.h" /***************************************************************************** * Global data @@ -39,52 +39,46 @@ * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -static tAVRC_STS avrc_ctrl_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - - uint8_t *p = p_msg->p_vendor_data; - p_result->pdu = *p++; - AVRC_TRACE_DEBUG("%s pdu:0x%x", __func__, p_result->pdu); - if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype)) - { - AVRC_TRACE_DEBUG("%s detects wrong AV/C type!", __func__); - status = AVRC_STS_BAD_CMD; - } - - p++; /* skip the reserved byte */ - uint16_t len; - BE_STREAM_TO_UINT16 (len, p); - if ((len+4) != (p_msg->vendor_len)) - { +static tAVRC_STS avrc_ctrl_pars_vendor_cmd(tAVRC_MSG_VENDOR* p_msg, + tAVRC_COMMAND* p_result) { + tAVRC_STS status = AVRC_STS_NO_ERROR; + + uint8_t* p = p_msg->p_vendor_data; + p_result->pdu = *p++; + AVRC_TRACE_DEBUG("%s pdu:0x%x", __func__, p_result->pdu); + if (!AVRC_IsValidAvcType(p_result->pdu, p_msg->hdr.ctype)) { + AVRC_TRACE_DEBUG("%s detects wrong AV/C type!", __func__); + status = AVRC_STS_BAD_CMD; + } + + p++; /* skip the reserved byte */ + uint16_t len; + BE_STREAM_TO_UINT16(len, p); + if ((len + 4) != (p_msg->vendor_len)) { + status = AVRC_STS_INTERNAL_ERR; + } + + if (status != AVRC_STS_NO_ERROR) return status; + + switch (p_result->pdu) { + case AVRC_PDU_SET_ABSOLUTE_VOLUME: { + if (len != 1) status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT8(p_result->volume.volume, p); + p_result->volume.volume = AVRC_MAX_VOLUME & p_result->volume.volume; + } + break; } - - if (status != AVRC_STS_NO_ERROR) - return status; - - switch (p_result->pdu) - { - case AVRC_PDU_SET_ABSOLUTE_VOLUME: - { - if(len!=1) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->volume.volume, p); - p_result->volume.volume = AVRC_MAX_VOLUME & p_result->volume.volume; - } - break; - } - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); - BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p); - break; - default: - status = AVRC_STS_BAD_CMD; - break; - } - return status; + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + BE_STREAM_TO_UINT8(p_result->reg_notif.event_id, p); + BE_STREAM_TO_UINT32(p_result->reg_notif.param, p); + break; + default: + status = AVRC_STS_BAD_CMD; + break; + } + return status; } /******************************************************************************* @@ -99,280 +93,254 @@ static tAVRC_STS avrc_ctrl_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAN * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result, - uint8_t *p_buf, uint16_t buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - uint8_t *p; - uint16_t len; - uint8_t xx, yy; - uint8_t *p_u8; - uint16_t *p_u16; - uint32_t u32, u32_2, *p_u32; - tAVRC_APP_SETTING *p_app_set; - uint16_t size_needed; - - /* Check the vendor data */ - if (p_msg->vendor_len == 0) - return AVRC_STS_NO_ERROR; - if (p_msg->p_vendor_data == NULL) - return AVRC_STS_INTERNAL_ERR; - - p = p_msg->p_vendor_data; - p_result->pdu = *p++; - AVRC_TRACE_DEBUG("%s pdu:0x%x", __func__, p_result->pdu); - if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype)) - { - AVRC_TRACE_DEBUG("%s detects wrong AV/C type(0x%x)!", __func__, - p_msg->hdr.ctype); - status = AVRC_STS_BAD_CMD; - } - - p++; /* skip the reserved byte */ - BE_STREAM_TO_UINT16 (len, p); - if ((len+4) != (p_msg->vendor_len)) - { - AVRC_TRACE_ERROR("%s incorrect length :%d, %d", __func__, len, p_msg->vendor_len); +static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR* p_msg, + tAVRC_COMMAND* p_result, uint8_t* p_buf, + uint16_t buf_len) { + tAVRC_STS status = AVRC_STS_NO_ERROR; + uint8_t* p; + uint16_t len; + uint8_t xx, yy; + uint8_t* p_u8; + uint16_t* p_u16; + uint32_t u32, u32_2, *p_u32; + tAVRC_APP_SETTING* p_app_set; + uint16_t size_needed; + + /* Check the vendor data */ + if (p_msg->vendor_len == 0) return AVRC_STS_NO_ERROR; + if (p_msg->p_vendor_data == NULL) return AVRC_STS_INTERNAL_ERR; + + p = p_msg->p_vendor_data; + p_result->pdu = *p++; + AVRC_TRACE_DEBUG("%s pdu:0x%x", __func__, p_result->pdu); + if (!AVRC_IsValidAvcType(p_result->pdu, p_msg->hdr.ctype)) { + AVRC_TRACE_DEBUG("%s detects wrong AV/C type(0x%x)!", __func__, + p_msg->hdr.ctype); + status = AVRC_STS_BAD_CMD; + } + + p++; /* skip the reserved byte */ + BE_STREAM_TO_UINT16(len, p); + if ((len + 4) != (p_msg->vendor_len)) { + AVRC_TRACE_ERROR("%s incorrect length :%d, %d", __func__, len, + p_msg->vendor_len); + status = AVRC_STS_INTERNAL_ERR; + } + + if (status != AVRC_STS_NO_ERROR) return status; + + switch (p_result->pdu) { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + p_result->get_caps.capability_id = *p++; + if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) status = AVRC_STS_INTERNAL_ERR; - } - - if (status != AVRC_STS_NO_ERROR) - return status; - - switch (p_result->pdu) - { - case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ - p_result->get_caps.capability_id = *p++; - if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) - status = AVRC_STS_BAD_PARAM; - else if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ - /* no additional parameters */ - if (len != 0) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ - p_result->list_app_values.attr_id = *p++; - if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id)) - status = AVRC_STS_BAD_PARAM; - else if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - break; + break; + + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + /* no additional parameters */ + if (len != 0) status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + p_result->list_app_values.attr_id = *p++; + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + break; case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ - BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_attr, p); - if (len != (p_result->get_cur_app_val.num_attr+1)) - { - status = AVRC_STS_INTERNAL_ERR; - break; - } - p_u8 = p_result->get_cur_app_val.attrs; - for (xx=0, yy=0; xx< p_result->get_cur_app_val.num_attr; xx++) - { - /* only report the valid player app attributes */ - if (AVRC_IsValidPlayerAttr(*p)) - p_u8[yy++] = *p; - p++; - } - p_result->get_cur_app_val.num_attr = yy; - if (yy == 0) - { - status = AVRC_STS_BAD_PARAM; - } + BE_STREAM_TO_UINT8(p_result->get_cur_app_val.num_attr, p); + if (len != (p_result->get_cur_app_val.num_attr + 1)) { + status = AVRC_STS_INTERNAL_ERR; break; - - case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ - BE_STREAM_TO_UINT8 (p_result->set_app_val.num_val, p); - size_needed = sizeof(tAVRC_APP_SETTING); - if (p_buf && (len == ((p_result->set_app_val.num_val<<1) + 1))) - { - p_result->set_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf; - p_app_set = p_result->set_app_val.p_vals; - for (xx=0; ((xx< p_result->set_app_val.num_val) && (buf_len > size_needed)); xx++) - { - p_app_set[xx].attr_id = *p++; - p_app_set[xx].attr_val = *p++; - if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, - p_app_set[xx].attr_val)) - status = AVRC_STS_BAD_PARAM; - } - if (xx != p_result->set_app_val.num_val) - { - AVRC_TRACE_ERROR( - "%s AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig num_val:%d", - __func__, xx, p_result->set_app_val.num_val); - p_result->set_app_val.num_val = xx; - } + } + p_u8 = p_result->get_cur_app_val.attrs; + for (xx = 0, yy = 0; xx < p_result->get_cur_app_val.num_attr; xx++) { + /* only report the valid player app attributes */ + if (AVRC_IsValidPlayerAttr(*p)) p_u8[yy++] = *p; + p++; + } + p_result->get_cur_app_val.num_attr = yy; + if (yy == 0) { + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + BE_STREAM_TO_UINT8(p_result->set_app_val.num_val, p); + size_needed = sizeof(tAVRC_APP_SETTING); + if (p_buf && (len == ((p_result->set_app_val.num_val << 1) + 1))) { + p_result->set_app_val.p_vals = (tAVRC_APP_SETTING*)p_buf; + p_app_set = p_result->set_app_val.p_vals; + for (xx = 0; + ((xx < p_result->set_app_val.num_val) && (buf_len > size_needed)); + xx++) { + p_app_set[xx].attr_id = *p++; + p_app_set[xx].attr_val = *p++; + if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, + p_app_set[xx].attr_val)) + status = AVRC_STS_BAD_PARAM; } - else - { - AVRC_TRACE_ERROR("%s AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len", - __func__); - status = AVRC_STS_INTERNAL_ERR; + if (xx != p_result->set_app_val.num_val) { + AVRC_TRACE_ERROR( + "%s AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig " + "num_val:%d", + __func__, xx, p_result->set_app_val.num_val); + p_result->set_app_val.num_val = xx; } - break; + } else { + AVRC_TRACE_ERROR( + "%s AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len", + __func__); + status = AVRC_STS_INTERNAL_ERR; + } + break; - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */ - if (len < 3) + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT8(p_result->get_app_val_txt.attr_id, p); + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id)) + status = AVRC_STS_BAD_PARAM; + else { + BE_STREAM_TO_UINT8(p_result->get_app_val_txt.num_val, p); + if ((len - 2 /* attr_id & num_val */) != + p_result->get_app_val_txt.num_val) status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.attr_id, p); - if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id)) + else { + p_u8 = p_result->get_app_val_txt.vals; + for (xx = 0; xx < p_result->get_app_val_txt.num_val; xx++) { + p_u8[xx] = *p++; + if (!avrc_is_valid_player_attrib_value( + p_result->get_app_val_txt.attr_id, p_u8[xx])) { status = AVRC_STS_BAD_PARAM; - else - { - BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.num_val, p); - if ( (len - 2/* attr_id & num_val */) != p_result->get_app_val_txt.num_val) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u8 = p_result->get_app_val_txt.vals; - for (xx=0; xx< p_result->get_app_val_txt.num_val; xx++) - { - p_u8[xx] = *p++; - if (!avrc_is_valid_player_attrib_value(p_result->get_app_val_txt.attr_id, - p_u8[xx])) - { - status = AVRC_STS_BAD_PARAM; - break; - } - } - } + break; + } } + } } - break; - - case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ - if (len < 3) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->inform_charset.num_id, p); - if ( (len - 1/* num_id */) != p_result->inform_charset.num_id * 2) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u16 = p_result->inform_charset.charsets; - if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE) - p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE; - for (xx=0; xx< p_result->inform_charset.num_id; xx++) - { - BE_STREAM_TO_UINT16 (p_u16[xx], p); - } - } - } - break; + } + break; - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */ - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_result->inform_battery_status.battery_status = *p++; - if (!AVRC_IS_VALID_BATTERY_STATUS(p_result->inform_battery_status.battery_status)) - status = AVRC_STS_BAD_PARAM; + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT8(p_result->inform_charset.num_id, p); + if ((len - 1 /* num_id */) != p_result->inform_charset.num_id * 2) + status = AVRC_STS_INTERNAL_ERR; + else { + p_u16 = p_result->inform_charset.charsets; + if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE) + p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE; + for (xx = 0; xx < p_result->inform_charset.num_id; xx++) { + BE_STREAM_TO_UINT16(p_u16[xx], p); + } } - break; + } + break; - case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ - if (len < 9) /* UID/8 and num_attr/1 */ + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ + if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + else { + p_result->inform_battery_status.battery_status = *p++; + if (!AVRC_IS_VALID_BATTERY_STATUS( + p_result->inform_battery_status.battery_status)) + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + if (len < 9) /* UID/8 and num_attr/1 */ + status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT32(u32, p); + BE_STREAM_TO_UINT32(u32_2, p); + if (u32 == 0 && u32_2 == 0) { + BE_STREAM_TO_UINT8(p_result->get_elem_attrs.num_attr, p); + if ((len - 9 /* UID/8 and num_attr/1 */) != + (p_result->get_elem_attrs.num_attr * 4)) status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT32 (u32, p); - BE_STREAM_TO_UINT32 (u32_2, p); - if (u32== 0 && u32_2 == 0) - { - BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p); - if ( (len - 9/* UID/8 and num_attr/1 */) != (p_result->get_elem_attrs.num_attr * 4)) - status = AVRC_STS_INTERNAL_ERR; - else - { - p_u32 = p_result->get_elem_attrs.attrs; - if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE) - p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE; - for (xx=0; xx< p_result->get_elem_attrs.num_attr; xx++) - { - BE_STREAM_TO_UINT32 (p_u32[xx], p); - } - } + else { + p_u32 = p_result->get_elem_attrs.attrs; + if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE) + p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE; + for (xx = 0; xx < p_result->get_elem_attrs.num_attr; xx++) { + BE_STREAM_TO_UINT32(p_u32[xx], p); } - else - status = AVRC_STS_NOT_FOUND; - } - break; - - case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ - /* no additional parameters */ - if (len != 0) - status = AVRC_STS_INTERNAL_ERR; - break; - - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - if (len != 5) - status = AVRC_STS_INTERNAL_ERR; - else - { - BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); - BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p); - } - break; - - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - if (len != 1) - status = AVRC_STS_INTERNAL_ERR; - else - p_result->volume.volume = *p++; - break; + } + } else + status = AVRC_STS_NOT_FOUND; + } + break; + + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + /* no additional parameters */ + if (len != 0) status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (len != 5) + status = AVRC_STS_INTERNAL_ERR; + else { + BE_STREAM_TO_UINT8(p_result->reg_notif.event_id, p); + BE_STREAM_TO_UINT32(p_result->reg_notif.param, p); + } + break; + + case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ + if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + else + p_result->volume.volume = *p++; + break; case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - if (len != 1) { - status = AVRC_STS_INTERNAL_ERR; - } - BE_STREAM_TO_UINT8(p_result->continu.target_pdu, p); - break; - - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - if (len != 1){ - status = AVRC_STS_INTERNAL_ERR; - } - BE_STREAM_TO_UINT8(p_result->abort.target_pdu, p); - break; - - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - if (len != 2) - { - AVRC_TRACE_ERROR("AVRC_PDU_SET_ADDRESSED_PLAYER length is incorrect:%d",len); - status = AVRC_STS_INTERNAL_ERR; - } - BE_STREAM_TO_UINT16 (p_result->addr_player.player_id, p); - break; + if (len != 1) { + status = AVRC_STS_INTERNAL_ERR; + } + BE_STREAM_TO_UINT8(p_result->continu.target_pdu, p); + break; - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - if (len != (AVRC_UID_SIZE + 3)) - status = AVRC_STS_INTERNAL_ERR; - BE_STREAM_TO_UINT8 (p_result->play_item.scope, p); - if (p_result->play_item.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - } - BE_STREAM_TO_ARRAY (p, p_result->play_item.uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT16 (p_result->play_item.uid_counter, p); - break; + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + if (len != 1) { + status = AVRC_STS_INTERNAL_ERR; + } + BE_STREAM_TO_UINT8(p_result->abort.target_pdu, p); + break; + + case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ + if (len != 2) { + AVRC_TRACE_ERROR("AVRC_PDU_SET_ADDRESSED_PLAYER length is incorrect:%d", + len); + status = AVRC_STS_INTERNAL_ERR; + } + BE_STREAM_TO_UINT16(p_result->addr_player.player_id, p); + break; + + case AVRC_PDU_PLAY_ITEM: /* 0x74 */ + case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ + if (len != (AVRC_UID_SIZE + 3)) status = AVRC_STS_INTERNAL_ERR; + BE_STREAM_TO_UINT8(p_result->play_item.scope, p); + if (p_result->play_item.scope > AVRC_SCOPE_NOW_PLAYING) { + status = AVRC_STS_BAD_SCOPE; + } + BE_STREAM_TO_ARRAY(p, p_result->play_item.uid, AVRC_UID_SIZE); + BE_STREAM_TO_UINT16(p_result->play_item.uid_counter, p); + break; default: - status = AVRC_STS_BAD_CMD; - break; - } + status = AVRC_STS_BAD_CMD; + break; + } - return status; + return status; } /******************************************************************************* @@ -388,27 +356,24 @@ static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_ * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -tAVRC_STS AVRC_Ctrl_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_ctrl_pars_vendor_cmd(&p_msg->vendor, p_result); - break; - - default: - AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); - break; - } - p_result->cmd.opcode = p_msg->hdr.opcode; - p_result->cmd.status = status; +tAVRC_STS AVRC_Ctrl_ParsCommand(tAVRC_MSG* p_msg, tAVRC_COMMAND* p_result) { + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + + if (p_msg && p_result) { + switch (p_msg->hdr.opcode) { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = avrc_ctrl_pars_vendor_cmd(&p_msg->vendor, p_result); + break; + + default: + AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); + break; } - AVRC_TRACE_DEBUG("%s return status:0x%x", __func__, status); - return status; + p_result->cmd.opcode = p_msg->hdr.opcode; + p_result->cmd.status = status; + } + AVRC_TRACE_DEBUG("%s return status:0x%x", __func__, status); + return status; } /******************************************************************************* @@ -423,127 +388,116 @@ tAVRC_STS AVRC_Ctrl_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result) * Otherwise, the error code defined by AVRCP+1 * ******************************************************************************/ -static tAVRC_STS avrc_pars_browsing_cmd(tAVRC_MSG_BROWSE *p_msg, tAVRC_COMMAND *p_result, - uint8_t *p_buf, uint16_t buf_len) -{ - tAVRC_STS status = AVRC_STS_NO_ERROR; - uint8_t *p = p_msg->p_browse_data; - int count; - - p_result->pdu = *p++; - AVRC_TRACE_DEBUG("avrc_pars_browsing_cmd() pdu:0x%x", p_result->pdu); - /* skip over len */ - p += 2; - - switch (p_result->pdu) - { - case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ - // For current implementation all players are browsable. - BE_STREAM_TO_UINT16 (p_result->br_player.player_id, p); - break; - - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - STREAM_TO_UINT8 (p_result->get_items.scope, p); - // To be modified later here (Scope) when all browsing commands are supported - if (p_result->get_items.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - } - BE_STREAM_TO_UINT32 (p_result->get_items.start_item, p); - BE_STREAM_TO_UINT32 (p_result->get_items.end_item, p); - if (p_result->get_items.start_item > p_result->get_items.end_item) - { - status = AVRC_STS_BAD_RANGE; - } - STREAM_TO_UINT8 (p_result->get_items.attr_count, p); - p_result->get_items.p_attr_list = NULL; - if (p_result->get_items.attr_count && p_buf && - (p_result->get_items.attr_count != AVRC_FOLDER_ITEM_COUNT_NONE)) - { - p_result->get_items.p_attr_list = (uint32_t *)p_buf; - count = p_result->get_items.attr_count; - if (buf_len < (count << 2)) - p_result->get_items.attr_count = count = (buf_len >> 2); - for (int idx = 0; idx < count; idx++) - { - BE_STREAM_TO_UINT32 (p_result->get_items.p_attr_list[idx], p); - } - } - break; - - case AVRC_PDU_CHANGE_PATH: /* 0x72 */ - BE_STREAM_TO_UINT16 (p_result->chg_path.uid_counter, p); - BE_STREAM_TO_UINT8 (p_result->chg_path.direction, p); - if (p_result->chg_path.direction != AVRC_DIR_UP - && p_result->chg_path.direction != AVRC_DIR_DOWN) - { - status = AVRC_STS_BAD_DIR; - } - BE_STREAM_TO_ARRAY (p, p_result->chg_path.folder_uid, AVRC_UID_SIZE); - break; - - case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ - BE_STREAM_TO_UINT8 (p_result->get_attrs.scope, p); - if (p_result->get_attrs.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; - break; - } - BE_STREAM_TO_ARRAY (p, p_result->get_attrs.uid, AVRC_UID_SIZE); - BE_STREAM_TO_UINT16 (p_result->get_attrs.uid_counter, p); - BE_STREAM_TO_UINT8 (p_result->get_attrs.attr_count, p); - p_result->get_attrs.p_attr_list = NULL; - if (p_result->get_attrs.attr_count && p_buf) - { - p_result->get_attrs.p_attr_list = (uint32_t *)p_buf; - count = p_result->get_attrs.attr_count; - if (buf_len < (count << 2)) - p_result->get_attrs.attr_count = count = (buf_len >> 2); - for (int idx = 0, count = 0; idx < p_result->get_attrs.attr_count; idx++) - { - BE_STREAM_TO_UINT32 (p_result->get_attrs.p_attr_list[count], p); - if (AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_result->get_attrs.p_attr_list[count])) - { - count++; - } - } - - if (p_result->get_attrs.attr_count != count && count == 0) - status = AVRC_STS_BAD_PARAM; - else - p_result->get_attrs.attr_count = count; +static tAVRC_STS avrc_pars_browsing_cmd(tAVRC_MSG_BROWSE* p_msg, + tAVRC_COMMAND* p_result, uint8_t* p_buf, + uint16_t buf_len) { + tAVRC_STS status = AVRC_STS_NO_ERROR; + uint8_t* p = p_msg->p_browse_data; + int count; + + p_result->pdu = *p++; + AVRC_TRACE_DEBUG("avrc_pars_browsing_cmd() pdu:0x%x", p_result->pdu); + /* skip over len */ + p += 2; + + switch (p_result->pdu) { + case AVRC_PDU_SET_BROWSED_PLAYER: /* 0x70 */ + // For current implementation all players are browsable. + BE_STREAM_TO_UINT16(p_result->br_player.player_id, p); + break; + + case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ + STREAM_TO_UINT8(p_result->get_items.scope, p); + // To be modified later here (Scope) when all browsing commands are + // supported + if (p_result->get_items.scope > AVRC_SCOPE_NOW_PLAYING) { + status = AVRC_STS_BAD_SCOPE; + } + BE_STREAM_TO_UINT32(p_result->get_items.start_item, p); + BE_STREAM_TO_UINT32(p_result->get_items.end_item, p); + if (p_result->get_items.start_item > p_result->get_items.end_item) { + status = AVRC_STS_BAD_RANGE; + } + STREAM_TO_UINT8(p_result->get_items.attr_count, p); + p_result->get_items.p_attr_list = NULL; + if (p_result->get_items.attr_count && p_buf && + (p_result->get_items.attr_count != AVRC_FOLDER_ITEM_COUNT_NONE)) { + p_result->get_items.p_attr_list = (uint32_t*)p_buf; + count = p_result->get_items.attr_count; + if (buf_len < (count << 2)) + p_result->get_items.attr_count = count = (buf_len >> 2); + for (int idx = 0; idx < count; idx++) { + BE_STREAM_TO_UINT32(p_result->get_items.p_attr_list[idx], p); } + } + break; + + case AVRC_PDU_CHANGE_PATH: /* 0x72 */ + BE_STREAM_TO_UINT16(p_result->chg_path.uid_counter, p); + BE_STREAM_TO_UINT8(p_result->chg_path.direction, p); + if (p_result->chg_path.direction != AVRC_DIR_UP && + p_result->chg_path.direction != AVRC_DIR_DOWN) { + status = AVRC_STS_BAD_DIR; + } + BE_STREAM_TO_ARRAY(p, p_result->chg_path.folder_uid, AVRC_UID_SIZE); + break; + + case AVRC_PDU_GET_ITEM_ATTRIBUTES: /* 0x73 */ + BE_STREAM_TO_UINT8(p_result->get_attrs.scope, p); + if (p_result->get_attrs.scope > AVRC_SCOPE_NOW_PLAYING) { + status = AVRC_STS_BAD_SCOPE; break; - - case AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS: /* 0x75 */ - BE_STREAM_TO_UINT8 (p_result->get_num_of_items.scope, p); - if (p_result->get_num_of_items.scope > AVRC_SCOPE_NOW_PLAYING) - { - status = AVRC_STS_BAD_SCOPE; + } + BE_STREAM_TO_ARRAY(p, p_result->get_attrs.uid, AVRC_UID_SIZE); + BE_STREAM_TO_UINT16(p_result->get_attrs.uid_counter, p); + BE_STREAM_TO_UINT8(p_result->get_attrs.attr_count, p); + p_result->get_attrs.p_attr_list = NULL; + if (p_result->get_attrs.attr_count && p_buf) { + p_result->get_attrs.p_attr_list = (uint32_t*)p_buf; + count = p_result->get_attrs.attr_count; + if (buf_len < (count << 2)) + p_result->get_attrs.attr_count = count = (buf_len >> 2); + for (int idx = 0, count = 0; idx < p_result->get_attrs.attr_count; + idx++) { + BE_STREAM_TO_UINT32(p_result->get_attrs.p_attr_list[count], p); + if (AVRC_IS_VALID_MEDIA_ATTRIBUTE( + p_result->get_attrs.p_attr_list[count])) { + count++; + } } - break; - case AVRC_PDU_SEARCH: /* 0x80 */ - BE_STREAM_TO_UINT16 (p_result->search.string.charset_id, p); - BE_STREAM_TO_UINT16 (p_result->search.string.str_len, p); - p_result->search.string.p_str = p_buf; - if (p_buf) - { - if (buf_len > p_result->search.string.str_len) - buf_len = p_result->search.string.str_len; - BE_STREAM_TO_ARRAY (p, p_buf, p_result->search.string.str_len); - } + if (p_result->get_attrs.attr_count != count && count == 0) + status = AVRC_STS_BAD_PARAM; else - { - status = AVRC_STS_INTERNAL_ERR; - } - break; + p_result->get_attrs.attr_count = count; + } + break; + + case AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS: /* 0x75 */ + BE_STREAM_TO_UINT8(p_result->get_num_of_items.scope, p); + if (p_result->get_num_of_items.scope > AVRC_SCOPE_NOW_PLAYING) { + status = AVRC_STS_BAD_SCOPE; + } + break; + + case AVRC_PDU_SEARCH: /* 0x80 */ + BE_STREAM_TO_UINT16(p_result->search.string.charset_id, p); + BE_STREAM_TO_UINT16(p_result->search.string.str_len, p); + p_result->search.string.p_str = p_buf; + if (p_buf) { + if (buf_len > p_result->search.string.str_len) + buf_len = p_result->search.string.str_len; + BE_STREAM_TO_ARRAY(p, p_buf, p_result->search.string.str_len); + } else { + status = AVRC_STS_INTERNAL_ERR; + } + break; default: - status = AVRC_STS_BAD_CMD; - break; - } - return status; + status = AVRC_STS_BAD_CMD; + break; + } + return status; } /******************************************************************************* @@ -558,42 +512,38 @@ static tAVRC_STS avrc_pars_browsing_cmd(tAVRC_MSG_BROWSE *p_msg, tAVRC_COMMAND * * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, - uint8_t *p_buf, uint16_t buf_len) -{ - tAVRC_STS status = AVRC_STS_INTERNAL_ERR; - uint16_t id; - - if (p_msg && p_result) - { - switch (p_msg->hdr.opcode) - { - case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ - status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len); - break; - - case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ - status = avrc_pars_pass_thru(&p_msg->pass, &id); - if (status == AVRC_STS_NO_ERROR) - { - p_result->pdu = (uint8_t)id; - } - break; - - case AVRC_OP_BROWSE: - status = avrc_pars_browsing_cmd(&p_msg->browse, p_result, p_buf, buf_len); - break; +tAVRC_STS AVRC_ParsCommand(tAVRC_MSG* p_msg, tAVRC_COMMAND* p_result, + uint8_t* p_buf, uint16_t buf_len) { + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + uint16_t id; + + if (p_msg && p_result) { + switch (p_msg->hdr.opcode) { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len); + break; - default: - AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); - break; + case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ + status = avrc_pars_pass_thru(&p_msg->pass, &id); + if (status == AVRC_STS_NO_ERROR) { + p_result->pdu = (uint8_t)id; } - p_result->cmd.opcode = p_msg->hdr.opcode; - p_result->cmd.status = status; + break; + + case AVRC_OP_BROWSE: + status = + avrc_pars_browsing_cmd(&p_msg->browse, p_result, p_buf, buf_len); + break; + + default: + AVRC_TRACE_ERROR("%s unknown opcode:0x%x", __func__, p_msg->hdr.opcode); + break; } - AVRC_TRACE_DEBUG("%s return status:0x%x", __func__, status); - return status; + p_result->cmd.opcode = p_msg->hdr.opcode; + p_result->cmd.status = status; + } + AVRC_TRACE_DEBUG("%s return status:0x%x", __func__, status); + return status; } #endif /* (AVRC_METADATA_INCLUDED == true) */ - diff --git a/stack/avrc/avrc_sdp.cc b/stack/avrc/avrc_sdp.cc index 3a63798cb..dbb71faa4 100644 --- a/stack/avrc/avrc_sdp.cc +++ b/stack/avrc/avrc_sdp.cc @@ -23,9 +23,9 @@ ******************************************************************************/ #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_int.h" +#include "bt_common.h" /***************************************************************************** * Global data @@ -47,17 +47,16 @@ tAVRC_CB avrc_cb; * Returns Nothing. * *****************************************************************************/ -static void avrc_sdp_cback(uint16_t status) -{ - AVRC_TRACE_API("%s status: %d", __func__, status); +static void avrc_sdp_cback(uint16_t status) { + AVRC_TRACE_API("%s status: %d", __func__, status); - /* reset service_uuid, so can start another find service */ - avrc_cb.service_uuid = 0; + /* reset service_uuid, so can start another find service */ + avrc_cb.service_uuid = 0; - /* return info from sdp record in app callback function */ - (*avrc_cb.p_cback) (status); + /* return info from sdp record in app callback function */ + (*avrc_cb.p_cback)(status); - return; + return; } /****************************************************************************** @@ -100,52 +99,51 @@ static void avrc_sdp_cback(uint16_t status) * *****************************************************************************/ uint16_t AVRC_FindService(uint16_t service_uuid, BD_ADDR bd_addr, - tAVRC_SDP_DB_PARAMS *p_db, tAVRC_FIND_CBACK *p_cback) -{ - tSDP_UUID uuid_list; - bool result = true; - uint16_t a2dp_attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, /* update AVRC_NUM_ATTR, if changed */ - ATTR_ID_PROTOCOL_DESC_LIST, - ATTR_ID_BT_PROFILE_DESC_LIST, - ATTR_ID_SERVICE_NAME, - ATTR_ID_SUPPORTED_FEATURES, - ATTR_ID_PROVIDER_NAME}; - - AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid); - if( (service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL) || - p_db == NULL || p_db->p_db == NULL || p_cback == NULL) - return AVRC_BAD_PARAM; - - /* check if it is busy */ - if( avrc_cb.service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET || - avrc_cb.service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) - return AVRC_NO_RESOURCES; - - /* set up discovery database */ - uuid_list.len = LEN_UUID_16; - uuid_list.uu.uuid16 = service_uuid; - - if(p_db->p_attrs == NULL || p_db->num_attr == 0) - { - p_db->p_attrs = a2dp_attr_list; - p_db->num_attr = AVRC_NUM_ATTR; - } - - result = SDP_InitDiscoveryDb(p_db->p_db, p_db->db_len, 1, &uuid_list, p_db->num_attr, - p_db->p_attrs); - - if (result == true) - { - /* store service_uuid and discovery db pointer */ - avrc_cb.p_db = p_db->p_db; - avrc_cb.service_uuid = service_uuid; - avrc_cb.p_cback = p_cback; - - /* perform service search */ - result = SDP_ServiceSearchAttributeRequest(bd_addr, p_db->p_db, avrc_sdp_cback); - } - - return (result ? AVRC_SUCCESS : AVRC_FAIL); + tAVRC_SDP_DB_PARAMS* p_db, + tAVRC_FIND_CBACK* p_cback) { + tSDP_UUID uuid_list; + bool result = true; + uint16_t a2dp_attr_list[] = { + ATTR_ID_SERVICE_CLASS_ID_LIST, /* update AVRC_NUM_ATTR, if changed */ + ATTR_ID_PROTOCOL_DESC_LIST, ATTR_ID_BT_PROFILE_DESC_LIST, + ATTR_ID_SERVICE_NAME, ATTR_ID_SUPPORTED_FEATURES, + ATTR_ID_PROVIDER_NAME}; + + AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid); + if ((service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && + service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL) || + p_db == NULL || p_db->p_db == NULL || p_cback == NULL) + return AVRC_BAD_PARAM; + + /* check if it is busy */ + if (avrc_cb.service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET || + avrc_cb.service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) + return AVRC_NO_RESOURCES; + + /* set up discovery database */ + uuid_list.len = LEN_UUID_16; + uuid_list.uu.uuid16 = service_uuid; + + if (p_db->p_attrs == NULL || p_db->num_attr == 0) { + p_db->p_attrs = a2dp_attr_list; + p_db->num_attr = AVRC_NUM_ATTR; + } + + result = SDP_InitDiscoveryDb(p_db->p_db, p_db->db_len, 1, &uuid_list, + p_db->num_attr, p_db->p_attrs); + + if (result == true) { + /* store service_uuid and discovery db pointer */ + avrc_cb.p_db = p_db->p_db; + avrc_cb.service_uuid = service_uuid; + avrc_cb.p_cback = p_cback; + + /* perform service search */ + result = + SDP_ServiceSearchAttributeRequest(bd_addr, p_db->p_db, avrc_sdp_cback); + } + + return (result ? AVRC_SUCCESS : AVRC_FAIL); } /****************************************************************************** @@ -185,99 +183,96 @@ uint16_t AVRC_FindService(uint16_t service_uuid, BD_ADDR bd_addr, * record. * *****************************************************************************/ -uint16_t AVRC_AddRecord(uint16_t service_uuid, const char *p_service_name, - const char *p_provider_name, uint16_t categories, +uint16_t AVRC_AddRecord(uint16_t service_uuid, const char* p_service_name, + const char* p_provider_name, uint16_t categories, uint32_t sdp_handle, bool browse_supported, - uint16_t profile_version) -{ - uint16_t browse_list[1]; - bool result = true; - uint8_t temp[8]; - uint8_t *p; - uint16_t count = 1; - uint8_t index = 0; - uint16_t class_list[2]; - - - AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid); - - if( service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL ) - return AVRC_BAD_PARAM; - - /* add service class id list */ - class_list[0] = service_uuid; - if((service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL ) && (profile_version > AVRC_REV_1_3)) - { - class_list[1] = UUID_SERVCLASS_AV_REM_CTRL_CONTROL; - count = 2; - } - result &= SDP_AddServiceClassIdList(sdp_handle, count, class_list); - - /* add protocol descriptor list */ - tSDP_PROTOCOL_ELEM avrc_proto_desc_list [AVRC_NUM_PROTO_ELEMS]; - avrc_proto_desc_list[0].num_params = 1; - avrc_proto_desc_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - avrc_proto_desc_list[0].params[0] = AVCT_PSM; - avrc_proto_desc_list[0].params[1] = 0; - for (index = 1; index < AVRC_NUM_PROTO_ELEMS; index++) - { - avrc_proto_desc_list[index].num_params = 1; - avrc_proto_desc_list[index].protocol_uuid = UUID_PROTOCOL_AVCTP; - avrc_proto_desc_list[index].params[0] = AVCT_REV_1_4; - avrc_proto_desc_list[index].params[1] = 0; - } - result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS, - (tSDP_PROTOCOL_ELEM *)avrc_proto_desc_list); - - /* additional protocal descriptor, required only for version > 1.3 */ - if ((profile_version > AVRC_REV_1_3) && (browse_supported)) - { - tSDP_PROTO_LIST_ELEM avrc_add_proto_desc_list; - avrc_add_proto_desc_list.num_elems = 2; - avrc_add_proto_desc_list.list_elem[0].num_params = 1; - avrc_add_proto_desc_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - avrc_add_proto_desc_list.list_elem[0].params[0] = AVCT_BR_PSM; - avrc_add_proto_desc_list.list_elem[0].params[1] = 0; - avrc_add_proto_desc_list.list_elem[1].num_params = 1; - avrc_add_proto_desc_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_AVCTP; - avrc_add_proto_desc_list.list_elem[1].params[0] = AVCT_REV_1_4; - avrc_add_proto_desc_list.list_elem[1].params[1] = 0; - - result &= SDP_AddAdditionProtoLists( sdp_handle, 1, (tSDP_PROTO_LIST_ELEM *)&avrc_add_proto_desc_list); - } - /* add profile descriptor list */ - result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, profile_version); - - /* add supported categories */ - p = temp; - UINT16_TO_BE_STREAM(p, categories); - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE, - (uint32_t)2, (uint8_t*)temp); - - /* add provider name */ - if (p_provider_name != NULL) - { - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE, - (uint32_t)(strlen(p_provider_name)+1), (uint8_t *) p_provider_name); - } - - /* add service name */ - if (p_service_name != NULL) - { - result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, - (uint32_t)(strlen(p_service_name)+1), (uint8_t *) p_service_name); - } - - /* add browse group list */ - browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list); - - - return (result ? AVRC_SUCCESS : AVRC_FAIL); + uint16_t profile_version) { + uint16_t browse_list[1]; + bool result = true; + uint8_t temp[8]; + uint8_t* p; + uint16_t count = 1; + uint8_t index = 0; + uint16_t class_list[2]; + + AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid); + + if (service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && + service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL) + return AVRC_BAD_PARAM; + + /* add service class id list */ + class_list[0] = service_uuid; + if ((service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) && + (profile_version > AVRC_REV_1_3)) { + class_list[1] = UUID_SERVCLASS_AV_REM_CTRL_CONTROL; + count = 2; + } + result &= SDP_AddServiceClassIdList(sdp_handle, count, class_list); + + /* add protocol descriptor list */ + tSDP_PROTOCOL_ELEM avrc_proto_desc_list[AVRC_NUM_PROTO_ELEMS]; + avrc_proto_desc_list[0].num_params = 1; + avrc_proto_desc_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; + avrc_proto_desc_list[0].params[0] = AVCT_PSM; + avrc_proto_desc_list[0].params[1] = 0; + for (index = 1; index < AVRC_NUM_PROTO_ELEMS; index++) { + avrc_proto_desc_list[index].num_params = 1; + avrc_proto_desc_list[index].protocol_uuid = UUID_PROTOCOL_AVCTP; + avrc_proto_desc_list[index].params[0] = AVCT_REV_1_4; + avrc_proto_desc_list[index].params[1] = 0; + } + result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS, + (tSDP_PROTOCOL_ELEM*)avrc_proto_desc_list); + + /* additional protocal descriptor, required only for version > 1.3 */ + if ((profile_version > AVRC_REV_1_3) && (browse_supported)) { + tSDP_PROTO_LIST_ELEM avrc_add_proto_desc_list; + avrc_add_proto_desc_list.num_elems = 2; + avrc_add_proto_desc_list.list_elem[0].num_params = 1; + avrc_add_proto_desc_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP; + avrc_add_proto_desc_list.list_elem[0].params[0] = AVCT_BR_PSM; + avrc_add_proto_desc_list.list_elem[0].params[1] = 0; + avrc_add_proto_desc_list.list_elem[1].num_params = 1; + avrc_add_proto_desc_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_AVCTP; + avrc_add_proto_desc_list.list_elem[1].params[0] = AVCT_REV_1_4; + avrc_add_proto_desc_list.list_elem[1].params[1] = 0; + + result &= SDP_AddAdditionProtoLists( + sdp_handle, 1, (tSDP_PROTO_LIST_ELEM*)&avrc_add_proto_desc_list); + } + /* add profile descriptor list */ + result &= SDP_AddProfileDescriptorList( + sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, profile_version); + + /* add supported categories */ + p = temp; + UINT16_TO_BE_STREAM(p, categories); + result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES, + UINT_DESC_TYPE, (uint32_t)2, (uint8_t*)temp); + + /* add provider name */ + if (p_provider_name != NULL) { + result &= SDP_AddAttribute( + sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE, + (uint32_t)(strlen(p_provider_name) + 1), (uint8_t*)p_provider_name); + } + + /* add service name */ + if (p_service_name != NULL) { + result &= SDP_AddAttribute( + sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, + (uint32_t)(strlen(p_service_name) + 1), (uint8_t*)p_service_name); + } + + /* add browse group list */ + browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; + result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, + browse_list); + + return (result ? AVRC_SUCCESS : AVRC_FAIL); } - - /****************************************************************************** * * Function AVRC_SetTraceLevel @@ -299,12 +294,10 @@ uint16_t AVRC_AddRecord(uint16_t service_uuid, const char *p_service_name, * the input parameter is 0xff. * *****************************************************************************/ -uint8_t AVRC_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - avrc_cb.trace_level = new_level; +uint8_t AVRC_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) avrc_cb.trace_level = new_level; - return (avrc_cb.trace_level); + return (avrc_cb.trace_level); } /******************************************************************************* @@ -318,14 +311,12 @@ uint8_t AVRC_SetTraceLevel (uint8_t new_level) * Returns void * ******************************************************************************/ -void AVRC_Init(void) -{ - memset(&avrc_cb, 0, sizeof(tAVRC_CB)); +void AVRC_Init(void) { + memset(&avrc_cb, 0, sizeof(tAVRC_CB)); #if defined(AVRC_INITIAL_TRACE_LEVEL) - avrc_cb.trace_level = AVRC_INITIAL_TRACE_LEVEL; + avrc_cb.trace_level = AVRC_INITIAL_TRACE_LEVEL; #else - avrc_cb.trace_level = BT_TRACE_LEVEL_NONE; + avrc_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif } - diff --git a/stack/avrc/avrc_utils.cc b/stack/avrc/avrc_utils.cc index fe65ead23..3d86b6765 100644 --- a/stack/avrc/avrc_utils.cc +++ b/stack/avrc/avrc_utils.cc @@ -17,10 +17,9 @@ ******************************************************************************/ #include -#include "bt_common.h" #include "avrc_api.h" #include "avrc_int.h" - +#include "bt_common.h" #if (AVRC_METADATA_INCLUDED == TRUE) @@ -34,61 +33,53 @@ * * ******************************************************************************/ -bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type) -{ - bool result=false; - - if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */ - { - switch (pdu_id) - { - case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ - case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ - case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ - case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ - case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ - case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ - case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ - case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ - if (avc_type == AVRC_CMD_STATUS) - result=true; - break; +bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type) { + bool result = false; + + if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */ + { + switch (pdu_id) { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + if (avc_type == AVRC_CMD_STATUS) result = true; + break; - case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ - case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ - case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ - case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ - case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ - if (avc_type == AVRC_CMD_CTRL) - result=true; - break; + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + if (avc_type == AVRC_CMD_CTRL) result = true; + break; - case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ - result = true; - break; + case AVRC_PDU_GET_FOLDER_ITEMS: /* 0x71 */ + result = true; + break; - case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ - case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ - case AVRC_PDU_PLAY_ITEM: /* 0x74 */ - case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ - if (avc_type == AVRC_CMD_CTRL) - result=true; - break; + case AVRC_PDU_SET_ABSOLUTE_VOLUME: /* 0x50 */ + case AVRC_PDU_SET_ADDRESSED_PLAYER: /* 0x60 */ + case AVRC_PDU_PLAY_ITEM: /* 0x74 */ + case AVRC_PDU_ADD_TO_NOW_PLAYING: /* 0x90 */ + if (avc_type == AVRC_CMD_CTRL) result = true; + break; - case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ - if (avc_type == AVRC_CMD_NOTIF) - result=true; - break; - } - } - else /* response msg */ - { - if (avc_type >= AVRC_RSP_NOT_IMPL && - avc_type <= AVRC_RSP_INTERIM ) - result=true; + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (avc_type == AVRC_CMD_NOTIF) result = true; + break; } + } else /* response msg */ + { + if (avc_type >= AVRC_RSP_NOT_IMPL && avc_type <= AVRC_RSP_INTERIM) + result = true; + } - return result; + return result; } /******************************************************************************* @@ -100,41 +91,32 @@ bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type) * Returns returns true if it is valid * ******************************************************************************/ -bool avrc_is_valid_player_attrib_value(uint8_t attrib, uint8_t value) -{ - bool result=false; +bool avrc_is_valid_player_attrib_value(uint8_t attrib, uint8_t value) { + bool result = false; - switch(attrib) - { + switch (attrib) { case AVRC_PLAYER_SETTING_EQUALIZER: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_ON)) - result=true; - break; + if ((value > 0) && (value <= AVRC_PLAYER_VAL_ON)) result = true; + break; case AVRC_PLAYER_SETTING_REPEAT: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) - result=true; - break; + if ((value > 0) && (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) result = true; + break; case AVRC_PLAYER_SETTING_SHUFFLE: case AVRC_PLAYER_SETTING_SCAN: - if ((value > 0) && - (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) - result=true; - break; - } - - if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) - result = true; - - if (!result) - { - AVRC_TRACE_ERROR(" %s found not matching attrib(x%x)-value(x%x) pair!", - __FUNCTION__, attrib, value); - } - return result; + if ((value > 0) && (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) + result = true; + break; + } + + if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) result = true; + + if (!result) { + AVRC_TRACE_ERROR(" %s found not matching attrib(x%x)-value(x%x) pair!", + __FUNCTION__, attrib, value); + } + return result; } /******************************************************************************* @@ -146,21 +128,18 @@ bool avrc_is_valid_player_attrib_value(uint8_t attrib, uint8_t value) * Returns returns true if it is valid * ******************************************************************************/ -bool AVRC_IsValidPlayerAttr(uint8_t attr) -{ - bool result=false; +bool AVRC_IsValidPlayerAttr(uint8_t attr) { + bool result = false; - if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) || - (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) ) - { - result = true; - } + if ((attr >= AVRC_PLAYER_SETTING_EQUALIZER && + attr <= AVRC_PLAYER_SETTING_SCAN) || + (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)) { + result = true; + } - return result; + return result; } - - /******************************************************************************* * * Function avrc_pars_pass_thru @@ -173,28 +152,26 @@ bool AVRC_IsValidPlayerAttr(uint8_t attr) * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, uint16_t *p_vendor_unique_id) -{ - uint8_t *p_data; - uint32_t co_id; - uint16_t id; - tAVRC_STS status = AVRC_STS_BAD_CMD; - - if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) - { - p_data = p_msg->p_pass_data; - AVRC_BE_STREAM_TO_CO_ID (co_id, p_data); - if (co_id == AVRC_CO_METADATA) - { - BE_STREAM_TO_UINT16 (id, p_data); - if (AVRC_IS_VALID_GROUP(id)) - { - *p_vendor_unique_id = id; - status = AVRC_STS_NO_ERROR; - } - } +tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS* p_msg, + uint16_t* p_vendor_unique_id) { + uint8_t* p_data; + uint32_t co_id; + uint16_t id; + tAVRC_STS status = AVRC_STS_BAD_CMD; + + if (p_msg->op_id == AVRC_ID_VENDOR && + p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) { + p_data = p_msg->p_pass_data; + AVRC_BE_STREAM_TO_CO_ID(co_id, p_data); + if (co_id == AVRC_CO_METADATA) { + BE_STREAM_TO_UINT16(id, p_data); + if (AVRC_IS_VALID_GROUP(id)) { + *p_vendor_unique_id = id; + status = AVRC_STS_NO_ERROR; + } } - return status; + } + return status; } /******************************************************************************* @@ -206,12 +183,10 @@ tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, uint16_t *p_vendor_unique_i * Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE * ******************************************************************************/ -uint8_t avrc_opcode_from_pdu(uint8_t pdu) -{ - uint8_t opcode = 0; +uint8_t avrc_opcode_from_pdu(uint8_t pdu) { + uint8_t opcode = 0; - switch (pdu) - { + switch (pdu) { case AVRC_PDU_SET_BROWSED_PLAYER: case AVRC_PDU_GET_FOLDER_ITEMS: case AVRC_PDU_CHANGE_PATH: @@ -219,20 +194,20 @@ uint8_t avrc_opcode_from_pdu(uint8_t pdu) case AVRC_PDU_SEARCH: case AVRC_PDU_GENERAL_REJECT: case AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS: - opcode = AVRC_OP_BROWSE; - break; + opcode = AVRC_OP_BROWSE; + break; case AVRC_PDU_NEXT_GROUP: case AVRC_PDU_PREV_GROUP: /* pass thru */ - opcode = AVRC_OP_PASS_THRU; - break; + opcode = AVRC_OP_PASS_THRU; + break; default: /* vendor */ - opcode = AVRC_OP_VENDOR; - break; - } + opcode = AVRC_OP_VENDOR; + break; + } - return opcode; + return opcode; } /******************************************************************************* @@ -244,19 +219,16 @@ uint8_t avrc_opcode_from_pdu(uint8_t pdu) * Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE * ******************************************************************************/ -bool avrc_is_valid_opcode(uint8_t opcode) -{ - bool is_valid = false; - switch (opcode) - { +bool avrc_is_valid_opcode(uint8_t opcode) { + bool is_valid = false; + switch (opcode) { case AVRC_OP_BROWSE: case AVRC_OP_PASS_THRU: case AVRC_OP_VENDOR: - is_valid = true; - break; - } - return is_valid; + is_valid = true; + break; + } + return is_valid; } #endif /* (AVRC_METADATA_INCLUDED == TRUE) */ - diff --git a/stack/bnep/bnep_api.cc b/stack/bnep/bnep_api.cc index 6c5b86775..557e7f493 100644 --- a/stack/bnep/bnep_api.cc +++ b/stack/bnep/bnep_api.cc @@ -22,12 +22,11 @@ * ******************************************************************************/ -#include #include "bnep_api.h" +#include #include "bnep_int.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -40,18 +39,16 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns void * ******************************************************************************/ -void BNEP_Init (void) -{ - memset (&bnep_cb, 0, sizeof (tBNEP_CB)); +void BNEP_Init(void) { + memset(&bnep_cb, 0, sizeof(tBNEP_CB)); #if defined(BNEP_INITIAL_TRACE_LEVEL) - bnep_cb.trace_level = BNEP_INITIAL_TRACE_LEVEL; + bnep_cb.trace_level = BNEP_INITIAL_TRACE_LEVEL; #else - bnep_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + bnep_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif } - /******************************************************************************* * * Function BNEP_Register @@ -66,28 +63,25 @@ void BNEP_Init (void) * BNEP_FAILURE if connection state callback is missing * ******************************************************************************/ -tBNEP_RESULT BNEP_Register (tBNEP_REGISTER *p_reg_info) -{ - /* There should be connection state call back registered */ - if ((!p_reg_info) || (!(p_reg_info->p_conn_state_cb))) - return BNEP_SECURITY_FAIL; - - bnep_cb.p_conn_ind_cb = p_reg_info->p_conn_ind_cb; - bnep_cb.p_conn_state_cb = p_reg_info->p_conn_state_cb; - bnep_cb.p_data_ind_cb = p_reg_info->p_data_ind_cb; - bnep_cb.p_data_buf_cb = p_reg_info->p_data_buf_cb; - bnep_cb.p_filter_ind_cb = p_reg_info->p_filter_ind_cb; - bnep_cb.p_mfilter_ind_cb = p_reg_info->p_mfilter_ind_cb; - bnep_cb.p_tx_data_flow_cb = p_reg_info->p_tx_data_flow_cb; - - if (bnep_register_with_l2cap ()) - return BNEP_SECURITY_FAIL; - - bnep_cb.profile_registered = true; - return BNEP_SUCCESS; +tBNEP_RESULT BNEP_Register(tBNEP_REGISTER* p_reg_info) { + /* There should be connection state call back registered */ + if ((!p_reg_info) || (!(p_reg_info->p_conn_state_cb))) + return BNEP_SECURITY_FAIL; + + bnep_cb.p_conn_ind_cb = p_reg_info->p_conn_ind_cb; + bnep_cb.p_conn_state_cb = p_reg_info->p_conn_state_cb; + bnep_cb.p_data_ind_cb = p_reg_info->p_data_ind_cb; + bnep_cb.p_data_buf_cb = p_reg_info->p_data_buf_cb; + bnep_cb.p_filter_ind_cb = p_reg_info->p_filter_ind_cb; + bnep_cb.p_mfilter_ind_cb = p_reg_info->p_mfilter_ind_cb; + bnep_cb.p_tx_data_flow_cb = p_reg_info->p_tx_data_flow_cb; + + if (bnep_register_with_l2cap()) return BNEP_SECURITY_FAIL; + + bnep_cb.profile_registered = true; + return BNEP_SUCCESS; } - /******************************************************************************* * * Function BNEP_Deregister @@ -101,21 +95,19 @@ tBNEP_RESULT BNEP_Register (tBNEP_REGISTER *p_reg_info) * Returns void * ******************************************************************************/ -void BNEP_Deregister (void) -{ - /* Clear all the call backs registered */ - bnep_cb.p_conn_ind_cb = NULL; - bnep_cb.p_conn_state_cb = NULL; - bnep_cb.p_data_ind_cb = NULL; - bnep_cb.p_data_buf_cb = NULL; - bnep_cb.p_filter_ind_cb = NULL; - bnep_cb.p_mfilter_ind_cb = NULL; - - bnep_cb.profile_registered = false; - L2CA_Deregister (BT_PSM_BNEP); +void BNEP_Deregister(void) { + /* Clear all the call backs registered */ + bnep_cb.p_conn_ind_cb = NULL; + bnep_cb.p_conn_state_cb = NULL; + bnep_cb.p_data_ind_cb = NULL; + bnep_cb.p_data_buf_cb = NULL; + bnep_cb.p_filter_ind_cb = NULL; + bnep_cb.p_mfilter_ind_cb = NULL; + + bnep_cb.profile_registered = false; + L2CA_Deregister(BT_PSM_BNEP); } - /******************************************************************************* * * Function BNEP_Connect @@ -133,95 +125,82 @@ void BNEP_Deregister (void) * BNEP_NO_RESOURCES if no resources * ******************************************************************************/ -tBNEP_RESULT BNEP_Connect (BD_ADDR p_rem_bda, - tBT_UUID *src_uuid, - tBT_UUID *dst_uuid, - uint16_t *p_handle) -{ - uint16_t cid; - tBNEP_CONN *p_bcb = bnepu_find_bcb_by_bd_addr (p_rem_bda); - - BNEP_TRACE_API ("BNEP_Connect() BDA: %02x-%02x-%02x-%02x-%02x-%02x", - p_rem_bda[0], p_rem_bda[1], p_rem_bda[2], - p_rem_bda[3], p_rem_bda[4], p_rem_bda[5]); - - if (!bnep_cb.profile_registered) - return BNEP_WRONG_STATE; - - /* Both source and destination UUID lengths should be same */ - if (src_uuid->len != dst_uuid->len) - return BNEP_CONN_FAILED_UUID_SIZE; - - if (!p_bcb) - { - p_bcb = bnepu_allocate_bcb(p_rem_bda); - if (p_bcb == NULL) - return (BNEP_NO_RESOURCES); - } - else if (p_bcb->con_state != BNEP_STATE_CONNECTED) - return BNEP_WRONG_STATE; - else - { - /* Backup current UUID values to restore if role change fails */ - memcpy ((uint8_t *)&(p_bcb->prv_src_uuid), (uint8_t *)&(p_bcb->src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->prv_dst_uuid), (uint8_t *)&(p_bcb->dst_uuid), sizeof (tBT_UUID)); - } - - /* We are the originator of this connection */ - p_bcb->con_flags |= BNEP_FLAGS_IS_ORIG; - - memcpy ((uint8_t *)&(p_bcb->src_uuid), (uint8_t *)src_uuid, sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->dst_uuid), (uint8_t *)dst_uuid, sizeof (tBT_UUID)); - - if (p_bcb->con_state == BNEP_STATE_CONNECTED) - { - /* Transition to the next appropriate state, waiting for connection confirm. */ - p_bcb->con_state = BNEP_STATE_SEC_CHECKING; - - BNEP_TRACE_API ("BNEP initiating security procedures for src uuid 0x%x", - p_bcb->src_uuid.uu.uuid16); +tBNEP_RESULT BNEP_Connect(BD_ADDR p_rem_bda, tBT_UUID* src_uuid, + tBT_UUID* dst_uuid, uint16_t* p_handle) { + uint16_t cid; + tBNEP_CONN* p_bcb = bnepu_find_bcb_by_bd_addr(p_rem_bda); + + BNEP_TRACE_API("BNEP_Connect() BDA: %02x-%02x-%02x-%02x-%02x-%02x", + p_rem_bda[0], p_rem_bda[1], p_rem_bda[2], p_rem_bda[3], + p_rem_bda[4], p_rem_bda[5]); + + if (!bnep_cb.profile_registered) return BNEP_WRONG_STATE; + + /* Both source and destination UUID lengths should be same */ + if (src_uuid->len != dst_uuid->len) return BNEP_CONN_FAILED_UUID_SIZE; + + if (!p_bcb) { + p_bcb = bnepu_allocate_bcb(p_rem_bda); + if (p_bcb == NULL) return (BNEP_NO_RESOURCES); + } else if (p_bcb->con_state != BNEP_STATE_CONNECTED) + return BNEP_WRONG_STATE; + else { + /* Backup current UUID values to restore if role change fails */ + memcpy((uint8_t*)&(p_bcb->prv_src_uuid), (uint8_t*)&(p_bcb->src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->prv_dst_uuid), (uint8_t*)&(p_bcb->dst_uuid), + sizeof(tBT_UUID)); + } + + /* We are the originator of this connection */ + p_bcb->con_flags |= BNEP_FLAGS_IS_ORIG; + + memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)src_uuid, sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)dst_uuid, sizeof(tBT_UUID)); + + if (p_bcb->con_state == BNEP_STATE_CONNECTED) { + /* Transition to the next appropriate state, waiting for connection confirm. + */ + p_bcb->con_state = BNEP_STATE_SEC_CHECKING; + + BNEP_TRACE_API("BNEP initiating security procedures for src uuid 0x%x", + p_bcb->src_uuid.uu.uuid16); #if (BNEP_DO_AUTH_FOR_ROLE_SWITCH == TRUE) - btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, true, - BTM_SEC_PROTO_BNEP, - bnep_get_uuid32(src_uuid), - &bnep_sec_check_complete, p_bcb); + btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, true, + BTM_SEC_PROTO_BNEP, bnep_get_uuid32(src_uuid), + &bnep_sec_check_complete, p_bcb); #else - bnep_sec_check_complete (p_bcb->rem_bda, p_bcb, BTM_SUCCESS); + bnep_sec_check_complete(p_bcb->rem_bda, p_bcb, BTM_SUCCESS); #endif + } else { + /* Transition to the next appropriate state, waiting for connection confirm. + */ + p_bcb->con_state = BNEP_STATE_CONN_START; + + cid = L2CA_ConnectReq(BT_PSM_BNEP, p_bcb->rem_bda); + if (cid != 0) { + p_bcb->l2cap_cid = cid; + + } else { + BNEP_TRACE_ERROR("BNEP - Originate failed"); + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED, false); + bnepu_release_bcb(p_bcb); + return BNEP_CONN_FAILED; } - else - { - /* Transition to the next appropriate state, waiting for connection confirm. */ - p_bcb->con_state = BNEP_STATE_CONN_START; - - cid = L2CA_ConnectReq(BT_PSM_BNEP, p_bcb->rem_bda); - if (cid != 0) - { - p_bcb->l2cap_cid = cid; - } - else - { - BNEP_TRACE_ERROR ("BNEP - Originate failed"); - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false); - bnepu_release_bcb (p_bcb); - return BNEP_CONN_FAILED; - } - - /* Start timer waiting for connect */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - } + /* Start timer waiting for connect */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); + } - *p_handle = p_bcb->handle; - return (BNEP_SUCCESS); + *p_handle = p_bcb->handle; + return (BNEP_SUCCESS); } - /******************************************************************************* * * Function BNEP_ConnectResp @@ -237,71 +216,72 @@ tBNEP_RESULT BNEP_Connect (BD_ADDR p_rem_bda, * BNEP_WRONG_STATE if the responce is not expected * ******************************************************************************/ -tBNEP_RESULT BNEP_ConnectResp (uint16_t handle, tBNEP_RESULT resp) -{ - tBNEP_CONN *p_bcb; - uint16_t resp_code = BNEP_SETUP_CONN_OK; - - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); - - p_bcb = &(bnep_cb.bcb[handle - 1]); +tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp) { + tBNEP_CONN* p_bcb; + uint16_t resp_code = BNEP_SETUP_CONN_OK; + + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); + + p_bcb = &(bnep_cb.bcb[handle - 1]); + + if (p_bcb->con_state != BNEP_STATE_CONN_SETUP || + (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD))) + return (BNEP_WRONG_STATE); + + BNEP_TRACE_API("BNEP_ConnectResp() for handle %d, responce %d", handle, + resp); + + /* Form appropriate responce based on profile responce */ + if (resp == BNEP_CONN_FAILED_SRC_UUID) + resp_code = BNEP_SETUP_INVALID_SRC_UUID; + else if (resp == BNEP_CONN_FAILED_DST_UUID) + resp_code = BNEP_SETUP_INVALID_DEST_UUID; + else if (resp == BNEP_CONN_FAILED_UUID_SIZE) + resp_code = BNEP_SETUP_INVALID_UUID_SIZE; + else if (resp == BNEP_SUCCESS) + resp_code = BNEP_SETUP_CONN_OK; + else + resp_code = BNEP_SETUP_CONN_NOT_ALLOWED; + + bnep_send_conn_responce(p_bcb, resp_code); + p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); + + if (resp == BNEP_SUCCESS) + bnep_connected(p_bcb); + else if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) { + /* Restore the original parameters */ + p_bcb->con_state = BNEP_STATE_CONNECTED; + p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); - if (p_bcb->con_state != BNEP_STATE_CONN_SETUP || - (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD))) - return (BNEP_WRONG_STATE); + memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid), + sizeof(tBT_UUID)); + } - BNEP_TRACE_API ("BNEP_ConnectResp() for handle %d, responce %d", handle, resp); + /* Process remaining part of the setup message (extension headers) */ + if (p_bcb->p_pending_data) { + uint8_t extension_present = true, *p, ext_type; + uint16_t rem_len; - /* Form appropriate responce based on profile responce */ - if (resp == BNEP_CONN_FAILED_SRC_UUID) resp_code = BNEP_SETUP_INVALID_SRC_UUID; - else if (resp == BNEP_CONN_FAILED_DST_UUID) resp_code = BNEP_SETUP_INVALID_DEST_UUID; - else if (resp == BNEP_CONN_FAILED_UUID_SIZE) resp_code = BNEP_SETUP_INVALID_UUID_SIZE; - else if (resp == BNEP_SUCCESS) resp_code = BNEP_SETUP_CONN_OK; - else resp_code = BNEP_SETUP_CONN_NOT_ALLOWED; + rem_len = p_bcb->p_pending_data->len; + p = (uint8_t*)(p_bcb->p_pending_data + 1) + p_bcb->p_pending_data->offset; + while (extension_present && p && rem_len) { + ext_type = *p++; + extension_present = ext_type >> 7; + ext_type &= 0x7F; - bnep_send_conn_responce (p_bcb, resp_code); - p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); + /* if unknown extension present stop processing */ + if (ext_type) break; - if (resp == BNEP_SUCCESS) - bnep_connected (p_bcb); - else if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - { - /* Restore the original parameters */ - p_bcb->con_state = BNEP_STATE_CONNECTED; - p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); - - memcpy ((uint8_t *)&(p_bcb->src_uuid), (uint8_t *)&(p_bcb->prv_src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->dst_uuid), (uint8_t *)&(p_bcb->prv_dst_uuid), sizeof (tBT_UUID)); + p = bnep_process_control_packet(p_bcb, p, &rem_len, true); } - /* Process remaining part of the setup message (extension headers) */ - if (p_bcb->p_pending_data) - { - uint8_t extension_present = true, *p, ext_type; - uint16_t rem_len; - - rem_len = p_bcb->p_pending_data->len; - p = (uint8_t *)(p_bcb->p_pending_data + 1) + p_bcb->p_pending_data->offset; - while (extension_present && p && rem_len) - { - ext_type = *p++; - extension_present = ext_type >> 7; - ext_type &= 0x7F; - - /* if unknown extension present stop processing */ - if (ext_type) - break; - - p = bnep_process_control_packet (p_bcb, p, &rem_len, true); - } - - osi_free_and_reset((void **)&p_bcb->p_pending_data); - } - return (BNEP_SUCCESS); + osi_free_and_reset((void**)&p_bcb->p_pending_data); + } + return (BNEP_SUCCESS); } - /******************************************************************************* * * Function BNEP_Disconnect @@ -314,28 +294,24 @@ tBNEP_RESULT BNEP_ConnectResp (uint16_t handle, tBNEP_RESULT resp) * BNEP_WRONG_HANDLE if no connection is not found * ******************************************************************************/ -tBNEP_RESULT BNEP_Disconnect (uint16_t handle) -{ - tBNEP_CONN *p_bcb; +tBNEP_RESULT BNEP_Disconnect(uint16_t handle) { + tBNEP_CONN* p_bcb; - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); - p_bcb = &(bnep_cb.bcb[handle - 1]); + p_bcb = &(bnep_cb.bcb[handle - 1]); - if (p_bcb->con_state == BNEP_STATE_IDLE) - return (BNEP_WRONG_HANDLE); + if (p_bcb->con_state == BNEP_STATE_IDLE) return (BNEP_WRONG_HANDLE); - BNEP_TRACE_API ("BNEP_Disconnect() for handle %d", handle); + BNEP_TRACE_API("BNEP_Disconnect() for handle %d", handle); - L2CA_DisconnectReq (p_bcb->l2cap_cid); + L2CA_DisconnectReq(p_bcb->l2cap_cid); - bnepu_release_bcb (p_bcb); + bnepu_release_bcb(p_bcb); - return (BNEP_SUCCESS); + return (BNEP_SUCCESS); } - /******************************************************************************* * * Function BNEP_WriteBuf @@ -359,95 +335,83 @@ tBNEP_RESULT BNEP_Disconnect (uint16_t handle) * BNEP_SUCCESS - If written successfully * ******************************************************************************/ -tBNEP_RESULT BNEP_WriteBuf (uint16_t handle, - uint8_t *p_dest_addr, - BT_HDR *p_buf, - uint16_t protocol, - uint8_t *p_src_addr, - bool fw_ext_present) -{ - tBNEP_CONN *p_bcb; - uint8_t *p_data; - - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - { - osi_free(p_buf); - return (BNEP_WRONG_HANDLE); - } - - p_bcb = &(bnep_cb.bcb[handle - 1]); - /* Check MTU size */ - if (p_buf->len > BNEP_MTU_SIZE) - { - BNEP_TRACE_ERROR ("BNEP_Write() length %d exceeded MTU %d", p_buf->len, BNEP_MTU_SIZE); - osi_free(p_buf); - return (BNEP_MTU_EXCEDED); - } - - /* Check if the packet should be filtered out */ - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - if (bnep_is_packet_allowed (p_bcb, p_dest_addr, protocol, fw_ext_present, p_data) != BNEP_SUCCESS) - { - /* - ** If packet is filtered and ext headers are present - ** drop the data and forward the ext headers - */ - if (fw_ext_present) - { - uint8_t ext, length; - uint16_t org_len, new_len; - /* parse the extension headers and findout the new packet len */ - org_len = p_buf->len; - new_len = 0; - do { - - ext = *p_data++; - length = *p_data++; - p_data += length; - - new_len += (length + 2); - - if (new_len > org_len) - { - osi_free(p_buf); - return BNEP_IGNORE_CMD; - } - - } while (ext & 0x80); - - if (protocol != BNEP_802_1_P_PROTOCOL) - protocol = 0; - else - { - new_len += 4; - p_data[2] = 0; - p_data[3] = 0; - } - p_buf->len = new_len; +tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, uint8_t* p_dest_addr, BT_HDR* p_buf, + uint16_t protocol, uint8_t* p_src_addr, + bool fw_ext_present) { + tBNEP_CONN* p_bcb; + uint8_t* p_data; + + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) { + osi_free(p_buf); + return (BNEP_WRONG_HANDLE); + } + + p_bcb = &(bnep_cb.bcb[handle - 1]); + /* Check MTU size */ + if (p_buf->len > BNEP_MTU_SIZE) { + BNEP_TRACE_ERROR("BNEP_Write() length %d exceeded MTU %d", p_buf->len, + BNEP_MTU_SIZE); + osi_free(p_buf); + return (BNEP_MTU_EXCEDED); + } + + /* Check if the packet should be filtered out */ + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + if (bnep_is_packet_allowed(p_bcb, p_dest_addr, protocol, fw_ext_present, + p_data) != BNEP_SUCCESS) { + /* + ** If packet is filtered and ext headers are present + ** drop the data and forward the ext headers + */ + if (fw_ext_present) { + uint8_t ext, length; + uint16_t org_len, new_len; + /* parse the extension headers and findout the new packet len */ + org_len = p_buf->len; + new_len = 0; + do { + ext = *p_data++; + length = *p_data++; + p_data += length; + + new_len += (length + 2); + + if (new_len > org_len) { + osi_free(p_buf); + return BNEP_IGNORE_CMD; } - else - { - osi_free(p_buf); - return BNEP_IGNORE_CMD; - } - } - /* Check transmit queue */ - if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) - { - osi_free(p_buf); - return (BNEP_Q_SIZE_EXCEEDED); + } while (ext & 0x80); + + if (protocol != BNEP_802_1_P_PROTOCOL) + protocol = 0; + else { + new_len += 4; + p_data[2] = 0; + p_data[3] = 0; + } + p_buf->len = new_len; + } else { + osi_free(p_buf); + return BNEP_IGNORE_CMD; } + } - /* Build the BNEP header */ - bnepu_build_bnep_hdr (p_bcb, p_buf, protocol, p_src_addr, p_dest_addr, fw_ext_present); + /* Check transmit queue */ + if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) { + osi_free(p_buf); + return (BNEP_Q_SIZE_EXCEEDED); + } - /* Send the data or queue it up */ - bnepu_check_send_packet (p_bcb, p_buf); + /* Build the BNEP header */ + bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, p_src_addr, p_dest_addr, + fw_ext_present); - return (BNEP_SUCCESS); -} + /* Send the data or queue it up */ + bnepu_check_send_packet(p_bcb, p_buf); + return (BNEP_SUCCESS); +} /******************************************************************************* * @@ -473,95 +437,84 @@ tBNEP_RESULT BNEP_WriteBuf (uint16_t handle, * BNEP_SUCCESS - If written successfully * ******************************************************************************/ -tBNEP_RESULT BNEP_Write (uint16_t handle, - uint8_t *p_dest_addr, - uint8_t *p_data, - uint16_t len, - uint16_t protocol, - uint8_t *p_src_addr, - bool fw_ext_present) -{ - tBNEP_CONN *p_bcb; - uint8_t *p; - - /* Check MTU size. Consider the possibility of having extension headers */ - if (len > BNEP_MTU_SIZE) - { - BNEP_TRACE_ERROR ("BNEP_Write() length %d exceeded MTU %d", len, BNEP_MTU_SIZE); - return (BNEP_MTU_EXCEDED); - } - - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); - - p_bcb = &(bnep_cb.bcb[handle - 1]); - - /* Check if the packet should be filtered out */ - if (bnep_is_packet_allowed (p_bcb, p_dest_addr, protocol, fw_ext_present, p_data) != BNEP_SUCCESS) - { - /* - ** If packet is filtered and ext headers are present - ** drop the data and forward the ext headers - */ - if (fw_ext_present) - { - uint8_t ext, length; - uint16_t org_len, new_len; - /* parse the extension headers and findout the new packet len */ - org_len = len; - new_len = 0; - p = p_data; - do { - - ext = *p_data++; - length = *p_data++; - p_data += length; - - new_len += (length + 2); - - if (new_len > org_len) - return BNEP_IGNORE_CMD; - - } while (ext & 0x80); - - if (protocol != BNEP_802_1_P_PROTOCOL) - protocol = 0; - else - { - new_len += 4; - p_data[2] = 0; - p_data[3] = 0; - } - len = new_len; - p_data = p; - } - else - return BNEP_IGNORE_CMD; - } - - /* Check transmit queue */ - if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) - return (BNEP_Q_SIZE_EXCEEDED); - - /* Get a buffer to copy the data into */ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - - p_buf->len = len; - p_buf->offset = BNEP_MINIMUM_OFFSET; - p = (uint8_t *)(p_buf + 1) + BNEP_MINIMUM_OFFSET; - - memcpy (p, p_data, len); - - /* Build the BNEP header */ - bnepu_build_bnep_hdr (p_bcb, p_buf, protocol, p_src_addr, p_dest_addr, fw_ext_present); - - /* Send the data or queue it up */ - bnepu_check_send_packet (p_bcb, p_buf); - - return (BNEP_SUCCESS); +tBNEP_RESULT BNEP_Write(uint16_t handle, uint8_t* p_dest_addr, uint8_t* p_data, + uint16_t len, uint16_t protocol, uint8_t* p_src_addr, + bool fw_ext_present) { + tBNEP_CONN* p_bcb; + uint8_t* p; + + /* Check MTU size. Consider the possibility of having extension headers */ + if (len > BNEP_MTU_SIZE) { + BNEP_TRACE_ERROR("BNEP_Write() length %d exceeded MTU %d", len, + BNEP_MTU_SIZE); + return (BNEP_MTU_EXCEDED); + } + + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); + + p_bcb = &(bnep_cb.bcb[handle - 1]); + + /* Check if the packet should be filtered out */ + if (bnep_is_packet_allowed(p_bcb, p_dest_addr, protocol, fw_ext_present, + p_data) != BNEP_SUCCESS) { + /* + ** If packet is filtered and ext headers are present + ** drop the data and forward the ext headers + */ + if (fw_ext_present) { + uint8_t ext, length; + uint16_t org_len, new_len; + /* parse the extension headers and findout the new packet len */ + org_len = len; + new_len = 0; + p = p_data; + do { + ext = *p_data++; + length = *p_data++; + p_data += length; + + new_len += (length + 2); + + if (new_len > org_len) return BNEP_IGNORE_CMD; + + } while (ext & 0x80); + + if (protocol != BNEP_802_1_P_PROTOCOL) + protocol = 0; + else { + new_len += 4; + p_data[2] = 0; + p_data[3] = 0; + } + len = new_len; + p_data = p; + } else + return BNEP_IGNORE_CMD; + } + + /* Check transmit queue */ + if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) + return (BNEP_Q_SIZE_EXCEEDED); + + /* Get a buffer to copy the data into */ + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + + p_buf->len = len; + p_buf->offset = BNEP_MINIMUM_OFFSET; + p = (uint8_t*)(p_buf + 1) + BNEP_MINIMUM_OFFSET; + + memcpy(p, p_data, len); + + /* Build the BNEP header */ + bnepu_build_bnep_hdr(p_bcb, p_buf, protocol, p_src_addr, p_dest_addr, + fw_ext_present); + + /* Send the data or queue it up */ + bnepu_check_send_packet(p_bcb, p_buf); + + return (BNEP_SUCCESS); } - /******************************************************************************* * * Function BNEP_SetProtocolFilters @@ -581,45 +534,39 @@ tBNEP_RESULT BNEP_Write (uint16_t handle, * BNEP_SUCCESS - if request sent successfully * ******************************************************************************/ -tBNEP_RESULT BNEP_SetProtocolFilters (uint16_t handle, - uint16_t num_filters, - uint16_t *p_start_array, - uint16_t *p_end_array) -{ - uint16_t xx; - tBNEP_CONN *p_bcb; - - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); - - p_bcb = &(bnep_cb.bcb[handle - 1]); - - /* Check the connection state */ - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - return (BNEP_WRONG_STATE); - - /* Validate the parameters */ - if (num_filters && (!p_start_array || !p_end_array)) - return (BNEP_SET_FILTER_FAIL); - - if (num_filters > BNEP_MAX_PROT_FILTERS) - return (BNEP_TOO_MANY_FILTERS); - - /* Fill the filter values in connnection block */ - for (xx = 0; xx < num_filters; xx++) - { - p_bcb->sent_prot_filter_start[xx] = *p_start_array++; - p_bcb->sent_prot_filter_end[xx] = *p_end_array++; - } +tBNEP_RESULT BNEP_SetProtocolFilters(uint16_t handle, uint16_t num_filters, + uint16_t* p_start_array, + uint16_t* p_end_array) { + uint16_t xx; + tBNEP_CONN* p_bcb; - p_bcb->sent_num_filters = num_filters; + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); - bnepu_send_peer_our_filters (p_bcb); + p_bcb = &(bnep_cb.bcb[handle - 1]); - return (BNEP_SUCCESS); -} + /* Check the connection state */ + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) + return (BNEP_WRONG_STATE); + + /* Validate the parameters */ + if (num_filters && (!p_start_array || !p_end_array)) + return (BNEP_SET_FILTER_FAIL); + if (num_filters > BNEP_MAX_PROT_FILTERS) return (BNEP_TOO_MANY_FILTERS); + + /* Fill the filter values in connnection block */ + for (xx = 0; xx < num_filters; xx++) { + p_bcb->sent_prot_filter_start[xx] = *p_start_array++; + p_bcb->sent_prot_filter_end[xx] = *p_end_array++; + } + + p_bcb->sent_num_filters = num_filters; + + bnepu_send_peer_our_filters(p_bcb); + + return (BNEP_SUCCESS); +} /******************************************************************************* * @@ -643,46 +590,41 @@ tBNEP_RESULT BNEP_SetProtocolFilters (uint16_t handle, * BNEP_SUCCESS - if request sent successfully * ******************************************************************************/ -tBNEP_RESULT BNEP_SetMulticastFilters (uint16_t handle, - uint16_t num_filters, - uint8_t *p_start_array, - uint8_t *p_end_array) -{ - uint16_t xx; - tBNEP_CONN *p_bcb; - - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); - - p_bcb = &(bnep_cb.bcb[handle - 1]); - - /* Check the connection state */ - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - return (BNEP_WRONG_STATE); - - /* Validate the parameters */ - if (num_filters && (!p_start_array || !p_end_array)) - return (BNEP_SET_FILTER_FAIL); - - if (num_filters > BNEP_MAX_MULTI_FILTERS) - return (BNEP_TOO_MANY_FILTERS); - - /* Fill the multicast filter values in connnection block */ - for (xx = 0; xx < num_filters; xx++) - { - memcpy (p_bcb->sent_mcast_filter_start[xx], p_start_array, BD_ADDR_LEN); - memcpy (p_bcb->sent_mcast_filter_end[xx], p_end_array, BD_ADDR_LEN); - - p_start_array += BD_ADDR_LEN; - p_end_array += BD_ADDR_LEN; - } +tBNEP_RESULT BNEP_SetMulticastFilters(uint16_t handle, uint16_t num_filters, + uint8_t* p_start_array, + uint8_t* p_end_array) { + uint16_t xx; + tBNEP_CONN* p_bcb; + + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); + + p_bcb = &(bnep_cb.bcb[handle - 1]); - p_bcb->sent_mcast_filters = num_filters; + /* Check the connection state */ + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) + return (BNEP_WRONG_STATE); - bnepu_send_peer_our_multi_filters (p_bcb); + /* Validate the parameters */ + if (num_filters && (!p_start_array || !p_end_array)) + return (BNEP_SET_FILTER_FAIL); - return (BNEP_SUCCESS); + if (num_filters > BNEP_MAX_MULTI_FILTERS) return (BNEP_TOO_MANY_FILTERS); + + /* Fill the multicast filter values in connnection block */ + for (xx = 0; xx < num_filters; xx++) { + memcpy(p_bcb->sent_mcast_filter_start[xx], p_start_array, BD_ADDR_LEN); + memcpy(p_bcb->sent_mcast_filter_end[xx], p_end_array, BD_ADDR_LEN); + + p_start_array += BD_ADDR_LEN; + p_end_array += BD_ADDR_LEN; + } + + p_bcb->sent_mcast_filters = num_filters; + + bnepu_send_peer_our_multi_filters(p_bcb); + + return (BNEP_SUCCESS); } /******************************************************************************* @@ -695,15 +637,12 @@ tBNEP_RESULT BNEP_SetMulticastFilters (uint16_t handle, * Returns the new (current) trace level * ******************************************************************************/ -uint8_t BNEP_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - bnep_cb.trace_level = new_level; +uint8_t BNEP_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) bnep_cb.trace_level = new_level; - return (bnep_cb.trace_level); + return (bnep_cb.trace_level); } - /******************************************************************************* * * Function BNEP_GetStatus @@ -718,42 +657,37 @@ uint8_t BNEP_SetTraceLevel (uint8_t new_level) * BNEP_WRONG_STATE - if not in connected state * ******************************************************************************/ -tBNEP_RESULT BNEP_GetStatus (uint16_t handle, tBNEP_STATUS *p_status) -{ +tBNEP_RESULT BNEP_GetStatus(uint16_t handle, tBNEP_STATUS* p_status) { #if (BNEP_SUPPORTS_STATUS_API == TRUE) - tBNEP_CONN *p_bcb; + tBNEP_CONN* p_bcb; - if (!p_status) - return BNEP_NO_RESOURCES; + if (!p_status) return BNEP_NO_RESOURCES; - if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) - return (BNEP_WRONG_HANDLE); + if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE); - p_bcb = &(bnep_cb.bcb[handle - 1]); + p_bcb = &(bnep_cb.bcb[handle - 1]); - memset (p_status, 0, sizeof (tBNEP_STATUS)); - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - return BNEP_WRONG_STATE; + memset(p_status, 0, sizeof(tBNEP_STATUS)); + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) + return BNEP_WRONG_STATE; - /* Read the status parameters from the connection control block */ - p_status->con_status = BNEP_STATUS_CONNECTED; - p_status->l2cap_cid = p_bcb->l2cap_cid; - p_status->rem_mtu_size = p_bcb->rem_mtu_size; - p_status->xmit_q_depth = fixed_queue_length(p_bcb->xmit_q); - p_status->sent_num_filters = p_bcb->sent_num_filters; - p_status->sent_mcast_filters = p_bcb->sent_mcast_filters; - p_status->rcvd_num_filters = p_bcb->rcvd_num_filters; - p_status->rcvd_mcast_filters = p_bcb->rcvd_mcast_filters; + /* Read the status parameters from the connection control block */ + p_status->con_status = BNEP_STATUS_CONNECTED; + p_status->l2cap_cid = p_bcb->l2cap_cid; + p_status->rem_mtu_size = p_bcb->rem_mtu_size; + p_status->xmit_q_depth = fixed_queue_length(p_bcb->xmit_q); + p_status->sent_num_filters = p_bcb->sent_num_filters; + p_status->sent_mcast_filters = p_bcb->sent_mcast_filters; + p_status->rcvd_num_filters = p_bcb->rcvd_num_filters; + p_status->rcvd_mcast_filters = p_bcb->rcvd_mcast_filters; - memcpy (p_status->rem_bda, p_bcb->rem_bda, BD_ADDR_LEN); - memcpy (&(p_status->src_uuid), &(p_bcb->src_uuid), sizeof (tBT_UUID)); - memcpy (&(p_status->dst_uuid), &(p_bcb->dst_uuid), sizeof (tBT_UUID)); + memcpy(p_status->rem_bda, p_bcb->rem_bda, BD_ADDR_LEN); + memcpy(&(p_status->src_uuid), &(p_bcb->src_uuid), sizeof(tBT_UUID)); + memcpy(&(p_status->dst_uuid), &(p_bcb->dst_uuid), sizeof(tBT_UUID)); - return BNEP_SUCCESS; + return BNEP_SUCCESS; #else - return (BNEP_IGNORE_CMD); + return (BNEP_IGNORE_CMD); #endif } - - diff --git a/stack/bnep/bnep_int.h b/stack/bnep/bnep_int.h index 438b35731..60a3113af 100644 --- a/stack/bnep/bnep_int.h +++ b/stack/bnep/bnep_int.h @@ -22,12 +22,12 @@ * ******************************************************************************/ -#ifndef BNEP_INT_H -#define BNEP_INT_H +#ifndef BNEP_INT_H +#define BNEP_INT_H -#include "bt_target.h" -#include "bt_common.h" #include "bnep_api.h" +#include "bt_common.h" +#include "bt_target.h" #include "btm_int.h" #include "btu.h" @@ -37,155 +37,147 @@ extern "C" { /* BNEP frame types */ -#define BNEP_FRAME_GENERAL_ETHERNET 0x00 -#define BNEP_FRAME_CONTROL 0x01 -#define BNEP_FRAME_COMPRESSED_ETHERNET 0x02 -#define BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY 0x03 -#define BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY 0x04 - +#define BNEP_FRAME_GENERAL_ETHERNET 0x00 +#define BNEP_FRAME_CONTROL 0x01 +#define BNEP_FRAME_COMPRESSED_ETHERNET 0x02 +#define BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY 0x03 +#define BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY 0x04 /* BNEP filter control message types */ -#define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00 -#define BNEP_SETUP_CONNECTION_REQUEST_MSG 0x01 -#define BNEP_SETUP_CONNECTION_RESPONSE_MSG 0x02 -#define BNEP_FILTER_NET_TYPE_SET_MSG 0x03 -#define BNEP_FILTER_NET_TYPE_RESPONSE_MSG 0x04 -#define BNEP_FILTER_MULTI_ADDR_SET_MSG 0x05 -#define BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG 0x06 - +#define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00 +#define BNEP_SETUP_CONNECTION_REQUEST_MSG 0x01 +#define BNEP_SETUP_CONNECTION_RESPONSE_MSG 0x02 +#define BNEP_FILTER_NET_TYPE_SET_MSG 0x03 +#define BNEP_FILTER_NET_TYPE_RESPONSE_MSG 0x04 +#define BNEP_FILTER_MULTI_ADDR_SET_MSG 0x05 +#define BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG 0x06 /* BNEP header extension types */ -#define BNEP_EXTENSION_FILTER_CONTROL 0x00 - +#define BNEP_EXTENSION_FILTER_CONTROL 0x00 /* BNEP Setup Connection response codes */ -#define BNEP_SETUP_CONN_OK 0x0000 -#define BNEP_SETUP_INVALID_DEST_UUID 0x0001 -#define BNEP_SETUP_INVALID_SRC_UUID 0x0002 -#define BNEP_SETUP_INVALID_UUID_SIZE 0x0003 -#define BNEP_SETUP_CONN_NOT_ALLOWED 0x0004 - +#define BNEP_SETUP_CONN_OK 0x0000 +#define BNEP_SETUP_INVALID_DEST_UUID 0x0001 +#define BNEP_SETUP_INVALID_SRC_UUID 0x0002 +#define BNEP_SETUP_INVALID_UUID_SIZE 0x0003 +#define BNEP_SETUP_CONN_NOT_ALLOWED 0x0004 /* BNEP filter control response codes */ -#define BNEP_FILTER_CRL_OK 0x0000 -#define BNEP_FILTER_CRL_UNSUPPORTED 0x0001 -#define BNEP_FILTER_CRL_BAD_RANGE 0x0002 -#define BNEP_FILTER_CRL_MAX_REACHED 0x0003 -#define BNEP_FILTER_CRL_SECURITY_ERR 0x0004 - +#define BNEP_FILTER_CRL_OK 0x0000 +#define BNEP_FILTER_CRL_UNSUPPORTED 0x0001 +#define BNEP_FILTER_CRL_BAD_RANGE 0x0002 +#define BNEP_FILTER_CRL_MAX_REACHED 0x0003 +#define BNEP_FILTER_CRL_SECURITY_ERR 0x0004 /* 802.1p protocol packet will have actual protocol field in side the payload */ -#define BNEP_802_1_P_PROTOCOL 0x8100 +#define BNEP_802_1_P_PROTOCOL 0x8100 /* Timeout definitions. */ /* Connection related timeout */ -#define BNEP_CONN_TIMEOUT_MS (20 * 1000) +#define BNEP_CONN_TIMEOUT_MS (20 * 1000) /* host response timeout */ -#define BNEP_HOST_TIMEOUT_MS (200 * 1000) -#define BNEP_FILTER_SET_TIMEOUT_MS (10 * 1000) +#define BNEP_HOST_TIMEOUT_MS (200 * 1000) +#define BNEP_FILTER_SET_TIMEOUT_MS (10 * 1000) /* Define the Out-Flow default values. */ -#define BNEP_OFLOW_QOS_FLAG 0 -#define BNEP_OFLOW_SERV_TYPE 0 -#define BNEP_OFLOW_TOKEN_RATE 0 -#define BNEP_OFLOW_TOKEN_BUCKET_SIZE 0 -#define BNEP_OFLOW_PEAK_BANDWIDTH 0 -#define BNEP_OFLOW_LATENCY 0 -#define BNEP_OFLOW_DELAY_VARIATION 0 +#define BNEP_OFLOW_QOS_FLAG 0 +#define BNEP_OFLOW_SERV_TYPE 0 +#define BNEP_OFLOW_TOKEN_RATE 0 +#define BNEP_OFLOW_TOKEN_BUCKET_SIZE 0 +#define BNEP_OFLOW_PEAK_BANDWIDTH 0 +#define BNEP_OFLOW_LATENCY 0 +#define BNEP_OFLOW_DELAY_VARIATION 0 /* Define the In-Flow default values. */ -#define BNEP_IFLOW_QOS_FLAG 0 -#define BNEP_IFLOW_SERV_TYPE 0 -#define BNEP_IFLOW_TOKEN_RATE 0 -#define BNEP_IFLOW_TOKEN_BUCKET_SIZE 0 -#define BNEP_IFLOW_PEAK_BANDWIDTH 0 -#define BNEP_IFLOW_LATENCY 0 -#define BNEP_IFLOW_DELAY_VARIATION 0 +#define BNEP_IFLOW_QOS_FLAG 0 +#define BNEP_IFLOW_SERV_TYPE 0 +#define BNEP_IFLOW_TOKEN_RATE 0 +#define BNEP_IFLOW_TOKEN_BUCKET_SIZE 0 +#define BNEP_IFLOW_PEAK_BANDWIDTH 0 +#define BNEP_IFLOW_LATENCY 0 +#define BNEP_IFLOW_DELAY_VARIATION 0 -#define BNEP_FLUSH_TO 0xFFFF +#define BNEP_FLUSH_TO 0xFFFF -#define BNEP_MAX_RETRANSMITS 3 +#define BNEP_MAX_RETRANSMITS 3 /* Define the BNEP Connection Control Block */ -typedef struct -{ -#define BNEP_STATE_IDLE 0 -#define BNEP_STATE_CONN_START 1 -#define BNEP_STATE_CFG_SETUP 2 -#define BNEP_STATE_CONN_SETUP 3 -#define BNEP_STATE_SEC_CHECKING 4 -#define BNEP_STATE_SETUP_RCVD 5 -#define BNEP_STATE_CONNECTED 6 - uint8_t con_state; - -#define BNEP_FLAGS_IS_ORIG 0x01 -#define BNEP_FLAGS_HIS_CFG_DONE 0x02 -#define BNEP_FLAGS_MY_CFG_DONE 0x04 -#define BNEP_FLAGS_L2CAP_CONGESTED 0x08 -#define BNEP_FLAGS_FILTER_RESP_PEND 0x10 -#define BNEP_FLAGS_MULTI_RESP_PEND 0x20 -#define BNEP_FLAGS_SETUP_RCVD 0x40 -#define BNEP_FLAGS_CONN_COMPLETED 0x80 - uint8_t con_flags; - BT_HDR *p_pending_data; - - uint16_t l2cap_cid; - BD_ADDR rem_bda; - uint16_t rem_mtu_size; - alarm_t *conn_timer; - fixed_queue_t *xmit_q; - - uint16_t sent_num_filters; - uint16_t sent_prot_filter_start[BNEP_MAX_PROT_FILTERS]; - uint16_t sent_prot_filter_end[BNEP_MAX_PROT_FILTERS]; - - uint16_t sent_mcast_filters; - BD_ADDR sent_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; - BD_ADDR sent_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; - - uint16_t rcvd_num_filters; - uint16_t rcvd_prot_filter_start[BNEP_MAX_PROT_FILTERS]; - uint16_t rcvd_prot_filter_end[BNEP_MAX_PROT_FILTERS]; - - uint16_t rcvd_mcast_filters; - BD_ADDR rcvd_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; - BD_ADDR rcvd_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; - - uint16_t bad_pkts_rcvd; - uint8_t re_transmits; - uint16_t handle; - tBT_UUID prv_src_uuid; - tBT_UUID prv_dst_uuid; - tBT_UUID src_uuid; - tBT_UUID dst_uuid; +typedef struct { +#define BNEP_STATE_IDLE 0 +#define BNEP_STATE_CONN_START 1 +#define BNEP_STATE_CFG_SETUP 2 +#define BNEP_STATE_CONN_SETUP 3 +#define BNEP_STATE_SEC_CHECKING 4 +#define BNEP_STATE_SETUP_RCVD 5 +#define BNEP_STATE_CONNECTED 6 + uint8_t con_state; + +#define BNEP_FLAGS_IS_ORIG 0x01 +#define BNEP_FLAGS_HIS_CFG_DONE 0x02 +#define BNEP_FLAGS_MY_CFG_DONE 0x04 +#define BNEP_FLAGS_L2CAP_CONGESTED 0x08 +#define BNEP_FLAGS_FILTER_RESP_PEND 0x10 +#define BNEP_FLAGS_MULTI_RESP_PEND 0x20 +#define BNEP_FLAGS_SETUP_RCVD 0x40 +#define BNEP_FLAGS_CONN_COMPLETED 0x80 + uint8_t con_flags; + BT_HDR* p_pending_data; + + uint16_t l2cap_cid; + BD_ADDR rem_bda; + uint16_t rem_mtu_size; + alarm_t* conn_timer; + fixed_queue_t* xmit_q; + + uint16_t sent_num_filters; + uint16_t sent_prot_filter_start[BNEP_MAX_PROT_FILTERS]; + uint16_t sent_prot_filter_end[BNEP_MAX_PROT_FILTERS]; + + uint16_t sent_mcast_filters; + BD_ADDR sent_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; + BD_ADDR sent_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; + + uint16_t rcvd_num_filters; + uint16_t rcvd_prot_filter_start[BNEP_MAX_PROT_FILTERS]; + uint16_t rcvd_prot_filter_end[BNEP_MAX_PROT_FILTERS]; + + uint16_t rcvd_mcast_filters; + BD_ADDR rcvd_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; + BD_ADDR rcvd_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; + + uint16_t bad_pkts_rcvd; + uint8_t re_transmits; + uint16_t handle; + tBT_UUID prv_src_uuid; + tBT_UUID prv_dst_uuid; + tBT_UUID src_uuid; + tBT_UUID dst_uuid; } tBNEP_CONN; - /* The main BNEP control block */ -typedef struct -{ - tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ - tBNEP_CONN bcb[BNEP_MAX_CONNECTIONS]; +typedef struct { + tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ + tBNEP_CONN bcb[BNEP_MAX_CONNECTIONS]; - tBNEP_CONNECT_IND_CB *p_conn_ind_cb; - tBNEP_CONN_STATE_CB *p_conn_state_cb; - tBNEP_DATA_IND_CB *p_data_ind_cb; - tBNEP_DATA_BUF_CB *p_data_buf_cb; - tBNEP_FILTER_IND_CB *p_filter_ind_cb; - tBNEP_MFILTER_IND_CB *p_mfilter_ind_cb; - tBNEP_TX_DATA_FLOW_CB *p_tx_data_flow_cb; + tBNEP_CONNECT_IND_CB* p_conn_ind_cb; + tBNEP_CONN_STATE_CB* p_conn_state_cb; + tBNEP_DATA_IND_CB* p_data_ind_cb; + tBNEP_DATA_BUF_CB* p_data_buf_cb; + tBNEP_FILTER_IND_CB* p_filter_ind_cb; + tBNEP_MFILTER_IND_CB* p_mfilter_ind_cb; + tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; - tL2CAP_APPL_INFO reg_info; + tL2CAP_APPL_INFO reg_info; - bool profile_registered; /* true when we got our BD addr */ - uint8_t trace_level; + bool profile_registered; /* true when we got our BD addr */ + uint8_t trace_level; } tBNEP_CB; @@ -195,50 +187,56 @@ extern tBNEP_CB bnep_cb; /* Functions provided by bnep_main.cc */ -extern tBNEP_RESULT bnep_register_with_l2cap (void); -extern void bnep_disconnect (tBNEP_CONN *p_bcb, uint16_t reason); -extern tBNEP_CONN *bnep_conn_originate (uint8_t *p_bd_addr); -extern void bnep_conn_timer_timeout(void *data); -extern void bnep_connected (tBNEP_CONN *p_bcb); - +extern tBNEP_RESULT bnep_register_with_l2cap(void); +extern void bnep_disconnect(tBNEP_CONN* p_bcb, uint16_t reason); +extern tBNEP_CONN* bnep_conn_originate(uint8_t* p_bd_addr); +extern void bnep_conn_timer_timeout(void* data); +extern void bnep_connected(tBNEP_CONN* p_bcb); /* Functions provided by bnep_utils.cc */ -extern tBNEP_CONN *bnepu_find_bcb_by_cid (uint16_t cid); -extern tBNEP_CONN *bnepu_find_bcb_by_bd_addr (uint8_t *p_bda); -extern tBNEP_CONN *bnepu_allocate_bcb (BD_ADDR p_rem_bda); -extern void bnepu_release_bcb (tBNEP_CONN *p_bcb); -extern void bnepu_send_peer_our_filters (tBNEP_CONN *p_bcb); -extern void bnepu_send_peer_our_multi_filters (tBNEP_CONN *p_bcb); -extern bool bnepu_does_dest_support_prot (tBNEP_CONN *p_bcb, uint16_t protocol); -extern void bnepu_build_bnep_hdr (tBNEP_CONN *p_bcb, BT_HDR *p_buf, uint16_t protocol, - uint8_t *p_src_addr, uint8_t *p_dest_addr, bool ext_bit); -extern void test_bnepu_build_bnep_hdr (tBNEP_CONN *p_bcb, BT_HDR *p_buf, uint16_t protocol, - uint8_t *p_src_addr, uint8_t *p_dest_addr, uint8_t type); - -extern tBNEP_CONN *bnepu_get_route_to_dest (uint8_t *p_bda); -extern void bnepu_check_send_packet (tBNEP_CONN *p_bcb, BT_HDR *p_buf); -extern void bnep_send_command_not_understood (tBNEP_CONN *p_bcb, uint8_t cmd_code); -extern void bnepu_process_peer_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filters, uint16_t len); -extern void bnepu_process_peer_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data); -extern void bnepu_process_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data); -extern void bnep_send_conn_req (tBNEP_CONN *p_bcb); -extern void bnep_send_conn_responce (tBNEP_CONN *p_bcb, uint16_t resp_code); -extern void bnep_process_setup_conn_req (tBNEP_CONN *p_bcb, uint8_t *p_setup, uint8_t len); -extern void bnep_process_setup_conn_responce (tBNEP_CONN *p_bcb, uint8_t *p_setup); -extern uint8_t *bnep_process_control_packet (tBNEP_CONN *p_bcb, uint8_t *p, uint16_t *len, - bool is_ext); -extern void bnep_sec_check_complete (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, - void *p_ref_data, uint8_t result); -extern tBNEP_RESULT bnep_is_packet_allowed (tBNEP_CONN *p_bcb, BD_ADDR p_dest_addr, uint16_t protocol, - bool fw_ext_present, uint8_t *p_data); -extern uint32_t bnep_get_uuid32 (tBT_UUID *src_uuid); - - +extern tBNEP_CONN* bnepu_find_bcb_by_cid(uint16_t cid); +extern tBNEP_CONN* bnepu_find_bcb_by_bd_addr(uint8_t* p_bda); +extern tBNEP_CONN* bnepu_allocate_bcb(BD_ADDR p_rem_bda); +extern void bnepu_release_bcb(tBNEP_CONN* p_bcb); +extern void bnepu_send_peer_our_filters(tBNEP_CONN* p_bcb); +extern void bnepu_send_peer_our_multi_filters(tBNEP_CONN* p_bcb); +extern bool bnepu_does_dest_support_prot(tBNEP_CONN* p_bcb, uint16_t protocol); +extern void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, + uint16_t protocol, uint8_t* p_src_addr, + uint8_t* p_dest_addr, bool ext_bit); +extern void test_bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, + uint16_t protocol, uint8_t* p_src_addr, + uint8_t* p_dest_addr, uint8_t type); + +extern tBNEP_CONN* bnepu_get_route_to_dest(uint8_t* p_bda); +extern void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf); +extern void bnep_send_command_not_understood(tBNEP_CONN* p_bcb, + uint8_t cmd_code); +extern void bnepu_process_peer_filter_set(tBNEP_CONN* p_bcb, uint8_t* p_filters, + uint16_t len); +extern void bnepu_process_peer_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data); +extern void bnepu_process_multicast_filter_rsp(tBNEP_CONN* p_bcb, + uint8_t* p_data); +extern void bnep_send_conn_req(tBNEP_CONN* p_bcb); +extern void bnep_send_conn_responce(tBNEP_CONN* p_bcb, uint16_t resp_code); +extern void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup, + uint8_t len); +extern void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, + uint8_t* p_setup); +extern uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p, + uint16_t* len, bool is_ext); +extern void bnep_sec_check_complete(BD_ADDR bd_addr, tBT_TRANSPORT trasnport, + void* p_ref_data, uint8_t result); +extern tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb, + BD_ADDR p_dest_addr, + uint16_t protocol, + bool fw_ext_present, + uint8_t* p_data); +extern uint32_t bnep_get_uuid32(tBT_UUID* src_uuid); #ifdef __cplusplus } #endif - #endif diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index caad4142c..c6d145678 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -22,22 +22,22 @@ * ******************************************************************************/ -#include "bt_target.h" +#include #include #include -#include +#include "bt_target.h" #include "bt_common.h" #include "bt_types.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "l2c_api.h" #include "l2cdefs.h" -#include "btu.h" #include "btm_api.h" +#include "btu.h" #include "bnep_api.h" #include "bnep_int.h" @@ -46,8 +46,7 @@ #include "device/include/controller.h" #include "osi/include/osi.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* G L O B A L B N E P D A T A */ @@ -59,15 +58,15 @@ const uint16_t bnep_frame_hdr_sizes[] = {14, 1, 2, 8, 8}; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void bnep_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, uint8_t l2cap_id); -static void bnep_connect_cfm (uint16_t l2cap_cid, uint16_t result); -static void bnep_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void bnep_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void bnep_disconnect_ind (uint16_t l2cap_cid, bool ack_needed); -static void bnep_disconnect_cfm (uint16_t l2cap_cid, uint16_t result); -static void bnep_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg); -static void bnep_congestion_ind (uint16_t lcid, bool is_congested); - +static void bnep_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, + uint8_t l2cap_id); +static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result); +static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void bnep_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void bnep_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); +static void bnep_disconnect_cfm(uint16_t l2cap_cid, uint16_t result); +static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); +static void bnep_congestion_ind(uint16_t lcid, bool is_congested); /******************************************************************************* * @@ -78,36 +77,33 @@ static void bnep_congestion_ind (uint16_t lcid, bool is_congested); * Returns void * ******************************************************************************/ -tBNEP_RESULT bnep_register_with_l2cap (void) -{ - /* Initialize the L2CAP configuration. We only care about MTU and flush */ - memset(&bnep_cb.l2cap_my_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - - bnep_cb.l2cap_my_cfg.mtu_present = true; - bnep_cb.l2cap_my_cfg.mtu = BNEP_MTU_SIZE; - bnep_cb.l2cap_my_cfg.flush_to_present = true; - bnep_cb.l2cap_my_cfg.flush_to = BNEP_FLUSH_TO; - - bnep_cb.reg_info.pL2CA_ConnectInd_Cb = bnep_connect_ind; - bnep_cb.reg_info.pL2CA_ConnectCfm_Cb = bnep_connect_cfm; - bnep_cb.reg_info.pL2CA_ConfigInd_Cb = bnep_config_ind; - bnep_cb.reg_info.pL2CA_ConfigCfm_Cb = bnep_config_cfm; - bnep_cb.reg_info.pL2CA_DisconnectInd_Cb = bnep_disconnect_ind; - bnep_cb.reg_info.pL2CA_DisconnectCfm_Cb = bnep_disconnect_cfm; - bnep_cb.reg_info.pL2CA_DataInd_Cb = bnep_data_ind; - bnep_cb.reg_info.pL2CA_CongestionStatus_Cb = bnep_congestion_ind; - - /* Now, register with L2CAP */ - if (!L2CA_Register (BT_PSM_BNEP, &bnep_cb.reg_info)) - { - BNEP_TRACE_ERROR ("BNEP - Registration failed"); - return BNEP_SECURITY_FAIL; - } - - return BNEP_SUCCESS; +tBNEP_RESULT bnep_register_with_l2cap(void) { + /* Initialize the L2CAP configuration. We only care about MTU and flush */ + memset(&bnep_cb.l2cap_my_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + + bnep_cb.l2cap_my_cfg.mtu_present = true; + bnep_cb.l2cap_my_cfg.mtu = BNEP_MTU_SIZE; + bnep_cb.l2cap_my_cfg.flush_to_present = true; + bnep_cb.l2cap_my_cfg.flush_to = BNEP_FLUSH_TO; + + bnep_cb.reg_info.pL2CA_ConnectInd_Cb = bnep_connect_ind; + bnep_cb.reg_info.pL2CA_ConnectCfm_Cb = bnep_connect_cfm; + bnep_cb.reg_info.pL2CA_ConfigInd_Cb = bnep_config_ind; + bnep_cb.reg_info.pL2CA_ConfigCfm_Cb = bnep_config_cfm; + bnep_cb.reg_info.pL2CA_DisconnectInd_Cb = bnep_disconnect_ind; + bnep_cb.reg_info.pL2CA_DisconnectCfm_Cb = bnep_disconnect_cfm; + bnep_cb.reg_info.pL2CA_DataInd_Cb = bnep_data_ind; + bnep_cb.reg_info.pL2CA_CongestionStatus_Cb = bnep_congestion_ind; + + /* Now, register with L2CAP */ + if (!L2CA_Register(BT_PSM_BNEP, &bnep_cb.reg_info)) { + BNEP_TRACE_ERROR("BNEP - Registration failed"); + return BNEP_SECURITY_FAIL; + } + + return BNEP_SUCCESS; } - /******************************************************************************* * * Function bnep_connect_ind @@ -119,42 +115,37 @@ tBNEP_RESULT bnep_register_with_l2cap (void) * Returns void * ******************************************************************************/ -static void bnep_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, - UNUSED_ATTR uint16_t psm, uint8_t l2cap_id) -{ - tBNEP_CONN *p_bcb = bnepu_find_bcb_by_bd_addr (bd_addr); - - /* If we are not acting as server, or already have a connection, or have */ - /* no more resources to handle the connection, reject the connection. */ - if (!(bnep_cb.profile_registered) || (p_bcb) - || ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL)) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0); - return; - } +static void bnep_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, + UNUSED_ATTR uint16_t psm, uint8_t l2cap_id) { + tBNEP_CONN* p_bcb = bnepu_find_bcb_by_bd_addr(bd_addr); - /* Transition to the next appropriate state, waiting for config setup. */ - p_bcb->con_state = BNEP_STATE_CFG_SETUP; + /* If we are not acting as server, or already have a connection, or have */ + /* no more resources to handle the connection, reject the connection. */ + if (!(bnep_cb.profile_registered) || (p_bcb) || + ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL)) { + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0); + return; + } - /* Save the L2CAP Channel ID. */ - p_bcb->l2cap_cid = l2cap_cid; + /* Transition to the next appropriate state, waiting for config setup. */ + p_bcb->con_state = BNEP_STATE_CFG_SETUP; - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); + /* Save the L2CAP Channel ID. */ + p_bcb->l2cap_cid = l2cap_cid; - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg); + /* Send response to the L2CAP layer. */ + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); - /* Start timer waiting for config setup */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); + /* Send a Configuration Request. */ + L2CA_ConfigReq(l2cap_cid, &bnep_cb.l2cap_my_cfg); - BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid); + /* Start timer waiting for config setup */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); + BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid); } - /******************************************************************************* * * Function bnep_connect_cfm @@ -166,47 +157,43 @@ static void bnep_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, * Returns void * ******************************************************************************/ -static void bnep_connect_cfm (uint16_t l2cap_cid, uint16_t result) -{ - tBNEP_CONN *p_bcb; - - /* Find CCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid); - return; - } +static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result) { + tBNEP_CONN* p_bcb; + + /* Find CCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid); + return; + } + + /* If the connection response contains success status, then */ + /* Transition to the next state and startup the timer. */ + if ((result == L2CAP_CONN_OK) && + (p_bcb->con_state == BNEP_STATE_CONN_START)) { + p_bcb->con_state = BNEP_STATE_CFG_SETUP; - /* If the connection response contains success status, then */ - /* Transition to the next state and startup the timer. */ - if ((result == L2CAP_CONN_OK) && (p_bcb->con_state == BNEP_STATE_CONN_START)) - { - p_bcb->con_state = BNEP_STATE_CFG_SETUP; + /* Send a Configuration Request. */ + L2CA_ConfigReq(l2cap_cid, &bnep_cb.l2cap_my_cfg); - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg); + /* Start timer waiting for config results */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); - /* Start timer waiting for config results */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); + BNEP_TRACE_EVENT("BNEP - got conn cnf, sent cfg req, CID: 0x%x", + p_bcb->l2cap_cid); + } else { + BNEP_TRACE_WARNING("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", + result, p_bcb->l2cap_cid); - BNEP_TRACE_EVENT ("BNEP - got conn cnf, sent cfg req, CID: 0x%x", p_bcb->l2cap_cid); + /* Tell the upper layer, if he has a callback */ + if (bnep_cb.p_conn_state_cb && p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) { + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED, false); } - else - { - BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, p_bcb->l2cap_cid); - - /* Tell the upper layer, if he has a callback */ - if (bnep_cb.p_conn_state_cb && - p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) - { - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false); - } - bnepu_release_bcb (p_bcb); - } + bnepu_release_bcb(p_bcb); + } } /******************************************************************************* @@ -219,73 +206,64 @@ static void bnep_connect_cfm (uint16_t l2cap_cid, uint16_t result) * Returns void * ******************************************************************************/ -static void bnep_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tBNEP_CONN *p_bcb; - uint16_t result, mtu = 0; - - /* Find CCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; - } - - BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind, CID: 0x%x", l2cap_cid); - - /* Remember the remote MTU size */ - if ((!p_cfg->mtu_present) || (p_cfg->mtu < BNEP_MIN_MTU_SIZE)) - { - mtu = p_cfg->mtu; - p_cfg->flush_to_present = false; - p_cfg->mtu_present = true; - p_cfg->mtu = BNEP_MIN_MTU_SIZE; - p_cfg->result = result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - } +static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tBNEP_CONN* p_bcb; + uint16_t result, mtu = 0; + + /* Find CCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", + l2cap_cid); + return; + } + + BNEP_TRACE_EVENT("BNEP - Rcvd cfg ind, CID: 0x%x", l2cap_cid); + + /* Remember the remote MTU size */ + if ((!p_cfg->mtu_present) || (p_cfg->mtu < BNEP_MIN_MTU_SIZE)) { + mtu = p_cfg->mtu; + p_cfg->flush_to_present = false; + p_cfg->mtu_present = true; + p_cfg->mtu = BNEP_MIN_MTU_SIZE; + p_cfg->result = result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + } else { + if (p_cfg->mtu > BNEP_MTU_SIZE) + p_bcb->rem_mtu_size = BNEP_MTU_SIZE; else - { - if (p_cfg->mtu > BNEP_MTU_SIZE) - p_bcb->rem_mtu_size = BNEP_MTU_SIZE; - else - p_bcb->rem_mtu_size = p_cfg->mtu; - - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = false; - p_cfg->mtu_present = false; - p_cfg->result = result = L2CAP_CFG_OK; - } + p_bcb->rem_mtu_size = p_cfg->mtu; - L2CA_ConfigRsp (l2cap_cid, p_cfg); + /* For now, always accept configuration from the other side */ + p_cfg->flush_to_present = false; + p_cfg->mtu_present = false; + p_cfg->result = result = L2CAP_CFG_OK; + } - if (result != L2CAP_CFG_OK) - { - BNEP_TRACE_EVENT ("BNEP - Rcvd cfg ind with bad MTU %d, CID: 0x%x", mtu, l2cap_cid); - return; - } + L2CA_ConfigRsp(l2cap_cid, p_cfg); - p_bcb->con_flags |= BNEP_FLAGS_HIS_CFG_DONE; + if (result != L2CAP_CFG_OK) { + BNEP_TRACE_EVENT("BNEP - Rcvd cfg ind with bad MTU %d, CID: 0x%x", mtu, + l2cap_cid); + return; + } - if (p_bcb->con_flags & BNEP_FLAGS_MY_CFG_DONE) - { - p_bcb->con_state = BNEP_STATE_SEC_CHECKING; + p_bcb->con_flags |= BNEP_FLAGS_HIS_CFG_DONE; - /* Start timer waiting for setup or response */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); + if (p_bcb->con_flags & BNEP_FLAGS_MY_CFG_DONE) { + p_bcb->con_state = BNEP_STATE_SEC_CHECKING; - if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) - { - btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, true, - BTM_SEC_PROTO_BNEP, - bnep_get_uuid32(&(p_bcb->src_uuid)), - &bnep_sec_check_complete, p_bcb); - } + /* Start timer waiting for setup or response */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); + + if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) { + btm_sec_mx_access_request( + p_bcb->rem_bda, BT_PSM_BNEP, true, BTM_SEC_PROTO_BNEP, + bnep_get_uuid32(&(p_bcb->src_uuid)), &bnep_sec_check_complete, p_bcb); } + } } - /******************************************************************************* * * Function bnep_config_cfm @@ -296,58 +274,52 @@ static void bnep_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void bnep_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tBNEP_CONN *p_bcb; - - BNEP_TRACE_EVENT ("BNEP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result); - - /* Find CCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; +static void bnep_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tBNEP_CONN* p_bcb; + + BNEP_TRACE_EVENT("BNEP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, + p_cfg->result); + + /* Find CCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", + l2cap_cid); + return; + } + + /* For now, always accept configuration from the other side */ + if (p_cfg->result == L2CAP_CFG_OK) { + p_bcb->con_flags |= BNEP_FLAGS_MY_CFG_DONE; + + if (p_bcb->con_flags & BNEP_FLAGS_HIS_CFG_DONE) { + p_bcb->con_state = BNEP_STATE_SEC_CHECKING; + + /* Start timer waiting for setup or response */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, + btu_general_alarm_queue); + + if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) { + btm_sec_mx_access_request(p_bcb->rem_bda, BT_PSM_BNEP, true, + BTM_SEC_PROTO_BNEP, + bnep_get_uuid32(&(p_bcb->src_uuid)), + &bnep_sec_check_complete, p_bcb); + } } - - /* For now, always accept configuration from the other side */ - if (p_cfg->result == L2CAP_CFG_OK) - { - p_bcb->con_flags |= BNEP_FLAGS_MY_CFG_DONE; - - if (p_bcb->con_flags & BNEP_FLAGS_HIS_CFG_DONE) - { - p_bcb->con_state = BNEP_STATE_SEC_CHECKING; - - /* Start timer waiting for setup or response */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - - if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) - { - btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, true, - BTM_SEC_PROTO_BNEP, - bnep_get_uuid32(&(p_bcb->src_uuid)), - &bnep_sec_check_complete, p_bcb); - } - } + } else { + /* Tell the upper layer, if he has a callback */ + if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) { + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED_CFG, false); } - else - { - /* Tell the upper layer, if he has a callback */ - if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) - { - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED_CFG, false); - } - L2CA_DisconnectReq (p_bcb->l2cap_cid); + L2CA_DisconnectReq(p_bcb->l2cap_cid); - bnepu_release_bcb (p_bcb); - } + bnepu_release_bcb(p_bcb); + } } - /******************************************************************************* * * Function bnep_disconnect_ind @@ -358,40 +330,35 @@ static void bnep_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void bnep_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) -{ - tBNEP_CONN *p_bcb; - - if (ack_needed) - L2CA_DisconnectRsp (l2cap_cid); - - /* Find CCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); - return; - } +static void bnep_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) { + tBNEP_CONN* p_bcb; - BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); + if (ack_needed) L2CA_DisconnectRsp(l2cap_cid); - /* Tell the user if he has a callback */ - if (p_bcb->con_state == BNEP_STATE_CONNECTED) - { - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_DISCONNECTED, false); - } - else - { - if ((bnep_cb.p_conn_state_cb) && ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) || - (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false); - } - - bnepu_release_bcb (p_bcb); -} + /* Find CCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); + return; + } + BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); + /* Tell the user if he has a callback */ + if (p_bcb->con_state == BNEP_STATE_CONNECTED) { + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_DISCONNECTED, false); + } else { + if ((bnep_cb.p_conn_state_cb) && + ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) || + (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED, false); + } + + bnepu_release_bcb(p_bcb); +} /******************************************************************************* * @@ -402,13 +369,11 @@ static void bnep_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) * Returns void * ******************************************************************************/ -static void bnep_disconnect_cfm (uint16_t l2cap_cid, uint16_t result) -{ - BNEP_TRACE_EVENT ("BNEP - Rcvd L2CAP disc cfm, CID: 0x%x, Result 0x%x", l2cap_cid, result); +static void bnep_disconnect_cfm(uint16_t l2cap_cid, uint16_t result) { + BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP disc cfm, CID: 0x%x, Result 0x%x", + l2cap_cid, result); } - - /******************************************************************************* * * Function bnep_congestion_ind @@ -417,50 +382,39 @@ static void bnep_disconnect_cfm (uint16_t l2cap_cid, uint16_t result) * congestion status changes * ******************************************************************************/ -static void bnep_congestion_ind (uint16_t l2cap_cid, bool is_congested) -{ - tBNEP_CONN *p_bcb; - - /* Find BCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP cong, unknown CID: 0x%x", l2cap_cid); - return; +static void bnep_congestion_ind(uint16_t l2cap_cid, bool is_congested) { + tBNEP_CONN* p_bcb; + + /* Find BCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd L2CAP cong, unknown CID: 0x%x", l2cap_cid); + return; + } + + if (is_congested) { + p_bcb->con_flags |= BNEP_FLAGS_L2CAP_CONGESTED; + if (bnep_cb.p_tx_data_flow_cb) { + bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_OFF); } + } else { + p_bcb->con_flags &= ~BNEP_FLAGS_L2CAP_CONGESTED; - if (is_congested) - { - p_bcb->con_flags |= BNEP_FLAGS_L2CAP_CONGESTED; - if(bnep_cb.p_tx_data_flow_cb) - { - bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_OFF); - } - } - else - { - p_bcb->con_flags &= ~BNEP_FLAGS_L2CAP_CONGESTED; - - if(bnep_cb.p_tx_data_flow_cb) - { - bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_ON); - } + if (bnep_cb.p_tx_data_flow_cb) { + bnep_cb.p_tx_data_flow_cb(p_bcb->handle, BNEP_TX_FLOW_ON); + } - /* While not congested, send as many buffers as we can */ - while (!(p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED)) - { - BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_bcb->xmit_q); + /* While not congested, send as many buffers as we can */ + while (!(p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED)) { + BT_HDR* p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_bcb->xmit_q); - if (!p_buf) - break; + if (!p_buf) break; - L2CA_DataWrite (l2cap_cid, p_buf); - } + L2CA_DataWrite(l2cap_cid, p_buf); } + } } - - /******************************************************************************* * * Function bnep_data_ind @@ -476,201 +430,183 @@ static void bnep_congestion_ind (uint16_t l2cap_cid, bool is_congested) * Returns void * ******************************************************************************/ -static void bnep_data_ind (uint16_t l2cap_cid, BT_HDR *p_buf) -{ - tBNEP_CONN *p_bcb; - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint16_t rem_len = p_buf->len; - uint8_t type, ctrl_type, ext_type = 0; - bool extension_present, fw_ext_present; - uint16_t protocol = 0; - uint8_t *p_src_addr, *p_dst_addr; - - - /* Find CCB based on CID */ - p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); - if (p_bcb == NULL) - { - BNEP_TRACE_WARNING ("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); - osi_free(p_buf); - return; - } - - /* Get the type and extension bits */ - type = *p++; - extension_present = type >> 7; - type &= 0x7f; - if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE)) - { - BNEP_TRACE_EVENT ("BNEP - rcvd frame, bad len: %d type: 0x%02x", p_buf->len, type); - osi_free(p_buf); - return; +static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) { + tBNEP_CONN* p_bcb; + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint16_t rem_len = p_buf->len; + uint8_t type, ctrl_type, ext_type = 0; + bool extension_present, fw_ext_present; + uint16_t protocol = 0; + uint8_t *p_src_addr, *p_dst_addr; + + /* Find CCB based on CID */ + p_bcb = bnepu_find_bcb_by_cid(l2cap_cid); + if (p_bcb == NULL) { + BNEP_TRACE_WARNING("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); + osi_free(p_buf); + return; + } + + /* Get the type and extension bits */ + type = *p++; + extension_present = type >> 7; + type &= 0x7f; + if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE)) { + BNEP_TRACE_EVENT("BNEP - rcvd frame, bad len: %d type: 0x%02x", p_buf->len, + type); + osi_free(p_buf); + return; + } + + rem_len--; + + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) && + (type != BNEP_FRAME_CONTROL)) { + BNEP_TRACE_WARNING( + "BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x", + p_bcb->con_state, l2cap_cid); + + if (extension_present) { + /* + ** When there is no connection if a data packet is received + ** with unknown control extension headers then those should be processed + ** according to complain/ignore law + */ + uint8_t ext, length; + uint16_t org_len, new_len; + /* parse the extension headers and process unknown control headers */ + org_len = rem_len; + new_len = 0; + do { + ext = *p++; + length = *p++; + p += length; + + if ((!(ext & 0x7F)) && (*p > BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG)) + bnep_send_command_not_understood(p_bcb, *p); + + new_len += (length + 2); + + if (new_len > org_len) break; + + } while (ext & 0x80); } - rem_len--; - - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) && - (type != BNEP_FRAME_CONTROL)) - { - BNEP_TRACE_WARNING ("BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x", - p_bcb->con_state, l2cap_cid); - - if (extension_present) - { - /* - ** When there is no connection if a data packet is received - ** with unknown control extension headers then those should be processed - ** according to complain/ignore law - */ - uint8_t ext, length; - uint16_t org_len, new_len; - /* parse the extension headers and process unknown control headers */ - org_len = rem_len; - new_len = 0; - do { - - ext = *p++; - length = *p++; - p += length; - - if ((!(ext & 0x7F)) && (*p > BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG)) - bnep_send_command_not_understood (p_bcb, *p); - - new_len += (length + 2); - - if (new_len > org_len) - break; - - } while (ext & 0x80); - } - - osi_free(p_buf); - return; - } + osi_free(p_buf); + return; + } - if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY) - { - BNEP_TRACE_EVENT ("BNEP - rcvd frame, unknown type: 0x%02x", type); - osi_free(p_buf); - return; - } + if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY) { + BNEP_TRACE_EVENT("BNEP - rcvd frame, unknown type: 0x%02x", type); + osi_free(p_buf); + return; + } - BNEP_TRACE_DEBUG ("BNEP - rcv frame, type: %d len: %d Ext: %d", type, p_buf->len, extension_present); + BNEP_TRACE_DEBUG("BNEP - rcv frame, type: %d len: %d Ext: %d", type, + p_buf->len, extension_present); - /* Initialize addresses to 'not supplied' */ - p_src_addr = p_dst_addr = NULL; + /* Initialize addresses to 'not supplied' */ + p_src_addr = p_dst_addr = NULL; - switch (type) - { + switch (type) { case BNEP_FRAME_GENERAL_ETHERNET: - p_dst_addr = p; - p += BD_ADDR_LEN; - p_src_addr = p; - p += BD_ADDR_LEN; - BE_STREAM_TO_UINT16 (protocol, p); - rem_len -= 14; - break; + p_dst_addr = p; + p += BD_ADDR_LEN; + p_src_addr = p; + p += BD_ADDR_LEN; + BE_STREAM_TO_UINT16(protocol, p); + rem_len -= 14; + break; case BNEP_FRAME_CONTROL: - ctrl_type = *p; - p = bnep_process_control_packet (p_bcb, p, &rem_len, false); - - if (ctrl_type == BNEP_SETUP_CONNECTION_REQUEST_MSG && - p_bcb->con_state != BNEP_STATE_CONNECTED && - extension_present && p && rem_len) - { - p_bcb->p_pending_data = (BT_HDR *)osi_malloc(rem_len); - memcpy((uint8_t *)(p_bcb->p_pending_data + 1), p, rem_len); - p_bcb->p_pending_data->len = rem_len; - p_bcb->p_pending_data->offset = 0; - } - else - { - while (extension_present && p && rem_len) - { - ext_type = *p++; - extension_present = ext_type >> 7; - ext_type &= 0x7F; - - /* if unknown extension present stop processing */ - if (ext_type) - break; - - p = bnep_process_control_packet (p_bcb, p, &rem_len, true); - } + ctrl_type = *p; + p = bnep_process_control_packet(p_bcb, p, &rem_len, false); + + if (ctrl_type == BNEP_SETUP_CONNECTION_REQUEST_MSG && + p_bcb->con_state != BNEP_STATE_CONNECTED && extension_present && p && + rem_len) { + p_bcb->p_pending_data = (BT_HDR*)osi_malloc(rem_len); + memcpy((uint8_t*)(p_bcb->p_pending_data + 1), p, rem_len); + p_bcb->p_pending_data->len = rem_len; + p_bcb->p_pending_data->offset = 0; + } else { + while (extension_present && p && rem_len) { + ext_type = *p++; + extension_present = ext_type >> 7; + ext_type &= 0x7F; + + /* if unknown extension present stop processing */ + if (ext_type) break; + + p = bnep_process_control_packet(p_bcb, p, &rem_len, true); } - osi_free(p_buf); - return; + } + osi_free(p_buf); + return; case BNEP_FRAME_COMPRESSED_ETHERNET: - BE_STREAM_TO_UINT16 (protocol, p); - rem_len -= 2; - break; + BE_STREAM_TO_UINT16(protocol, p); + rem_len -= 2; + break; case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY: - p_src_addr = p; - p += BD_ADDR_LEN; - BE_STREAM_TO_UINT16 (protocol, p); - rem_len -= 8; - break; + p_src_addr = p; + p += BD_ADDR_LEN; + BE_STREAM_TO_UINT16(protocol, p); + rem_len -= 8; + break; case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY: - p_dst_addr = p; - p += BD_ADDR_LEN; - BE_STREAM_TO_UINT16 (protocol, p); - rem_len -= 8; - break; + p_dst_addr = p; + p += BD_ADDR_LEN; + BE_STREAM_TO_UINT16(protocol, p); + rem_len -= 8; + break; + } + + /* Process the header extension if there is one */ + while (extension_present && p && rem_len) { + ext_type = *p; + extension_present = ext_type >> 7; + ext_type &= 0x7F; + + /* if unknown extension present stop processing */ + if (ext_type) { + BNEP_TRACE_EVENT("Data extension type 0x%x found", ext_type); + break; } - /* Process the header extension if there is one */ - while (extension_present && p && rem_len) - { - ext_type = *p; - extension_present = ext_type >> 7; - ext_type &= 0x7F; - - /* if unknown extension present stop processing */ - if (ext_type) - { - BNEP_TRACE_EVENT ("Data extension type 0x%x found", ext_type); - break; - } - - p++; - rem_len--; - p = bnep_process_control_packet (p_bcb, p, &rem_len, true); - } - - p_buf->offset += p_buf->len - rem_len; - p_buf->len = rem_len; - - /* Always give the upper layer MAC addresses */ - if (!p_src_addr) - p_src_addr = (uint8_t *) p_bcb->rem_bda; - - if (!p_dst_addr) - p_dst_addr = (uint8_t *) controller_get_interface()->get_address(); - - /* check whether there are any extensions to be forwarded */ - if (ext_type) - fw_ext_present = true; - else - fw_ext_present = false; - - if (bnep_cb.p_data_buf_cb) - { - (*bnep_cb.p_data_buf_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p_buf, fw_ext_present); - } - else if (bnep_cb.p_data_ind_cb) - { - (*bnep_cb.p_data_ind_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p, rem_len, fw_ext_present); - osi_free(p_buf); - } + p++; + rem_len--; + p = bnep_process_control_packet(p_bcb, p, &rem_len, true); + } + + p_buf->offset += p_buf->len - rem_len; + p_buf->len = rem_len; + + /* Always give the upper layer MAC addresses */ + if (!p_src_addr) p_src_addr = (uint8_t*)p_bcb->rem_bda; + + if (!p_dst_addr) + p_dst_addr = (uint8_t*)controller_get_interface()->get_address(); + + /* check whether there are any extensions to be forwarded */ + if (ext_type) + fw_ext_present = true; + else + fw_ext_present = false; + + if (bnep_cb.p_data_buf_cb) { + (*bnep_cb.p_data_buf_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, + p_buf, fw_ext_present); + } else if (bnep_cb.p_data_ind_cb) { + (*bnep_cb.p_data_ind_cb)(p_bcb->handle, p_src_addr, p_dst_addr, protocol, p, + rem_len, fw_ext_present); + osi_free(p_buf); + } } - - /******************************************************************************* * * Function bnep_conn_timer_timeout @@ -682,102 +618,89 @@ static void bnep_data_ind (uint16_t l2cap_cid, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -void bnep_conn_timer_timeout(void *data) -{ - tBNEP_CONN *p_bcb = (tBNEP_CONN *)data; - - BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d", - p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, p_bcb->re_transmits); +void bnep_conn_timer_timeout(void* data) { + tBNEP_CONN* p_bcb = (tBNEP_CONN*)data; - if (p_bcb->con_state == BNEP_STATE_CONN_SETUP) - { - BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x", - p_bcb->con_state, p_bcb->l2cap_cid); + BNEP_TRACE_EVENT( + "BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d", + p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, + p_bcb->re_transmits); - if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) - { - L2CA_DisconnectReq (p_bcb->l2cap_cid); + if (p_bcb->con_state == BNEP_STATE_CONN_SETUP) { + BNEP_TRACE_EVENT("BNEP - CCB timeout in state: %d CID: 0x%x", + p_bcb->con_state, p_bcb->l2cap_cid); - bnepu_release_bcb (p_bcb); - return; - } + if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) { + L2CA_DisconnectReq(p_bcb->l2cap_cid); - if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) - { - bnep_send_conn_req (p_bcb); - alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - } - else - { - L2CA_DisconnectReq (p_bcb->l2cap_cid); - - if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false); - - bnepu_release_bcb (p_bcb); - return; - } + bnepu_release_bcb(p_bcb); + return; } - else if (p_bcb->con_state != BNEP_STATE_CONNECTED) - { - BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x", - p_bcb->con_state, p_bcb->l2cap_cid); - L2CA_DisconnectReq (p_bcb->l2cap_cid); + if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) { + bnep_send_conn_req(p_bcb); + alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, + btu_general_alarm_queue); + } else { + L2CA_DisconnectReq(p_bcb->l2cap_cid); - /* Tell the user if he has a callback */ - if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false); + if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED, false); - bnepu_release_bcb (p_bcb); + bnepu_release_bcb(p_bcb); + return; } - else if (p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND) - { - if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) - { - bnepu_send_peer_our_filters (p_bcb); - alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - } - else - { - L2CA_DisconnectReq (p_bcb->l2cap_cid); + } else if (p_bcb->con_state != BNEP_STATE_CONNECTED) { + BNEP_TRACE_EVENT("BNEP - CCB timeout in state: %d CID: 0x%x", + p_bcb->con_state, p_bcb->l2cap_cid); - /* Tell the user if he has a callback */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, false); + L2CA_DisconnectReq(p_bcb->l2cap_cid); - bnepu_release_bcb (p_bcb); - return; - } + /* Tell the user if he has a callback */ + if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_CONN_FAILED, false); + + bnepu_release_bcb(p_bcb); + } else if (p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND) { + if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) { + bnepu_send_peer_our_filters(p_bcb); + alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, + btu_general_alarm_queue); + } else { + L2CA_DisconnectReq(p_bcb->l2cap_cid); + + /* Tell the user if he has a callback */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_SET_FILTER_FAIL, false); + + bnepu_release_bcb(p_bcb); + return; } - else if (p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND) - { - if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) - { - bnepu_send_peer_our_multi_filters (p_bcb); - alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - } - else - { - L2CA_DisconnectReq (p_bcb->l2cap_cid); - - /* Tell the user if he has a callback */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SET_FILTER_FAIL, false); - - bnepu_release_bcb (p_bcb); - return; - } + } else if (p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND) { + if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS) { + bnepu_send_peer_our_multi_filters(p_bcb); + alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, + btu_general_alarm_queue); + } else { + L2CA_DisconnectReq(p_bcb->l2cap_cid); + + /* Tell the user if he has a callback */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_SET_FILTER_FAIL, false); + + bnepu_release_bcb(p_bcb); + return; } + } } - /******************************************************************************* * * Function bnep_connected @@ -788,24 +711,24 @@ void bnep_conn_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void bnep_connected (tBNEP_CONN *p_bcb) -{ - bool is_role_change; - - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - is_role_change = true; - else - is_role_change = false; - - p_bcb->con_state = BNEP_STATE_CONNECTED; - p_bcb->con_flags |= BNEP_FLAGS_CONN_COMPLETED; - p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); - - /* Ensure timer is stopped */ - alarm_cancel(p_bcb->conn_timer); - p_bcb->re_transmits = 0; - - /* Tell the upper layer, if he has a callback */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SUCCESS, is_role_change); +void bnep_connected(tBNEP_CONN* p_bcb) { + bool is_role_change; + + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) + is_role_change = true; + else + is_role_change = false; + + p_bcb->con_state = BNEP_STATE_CONNECTED; + p_bcb->con_flags |= BNEP_FLAGS_CONN_COMPLETED; + p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); + + /* Ensure timer is stopped */ + alarm_cancel(p_bcb->conn_timer); + p_bcb->re_transmits = 0; + + /* Tell the upper layer, if he has a callback */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, BNEP_SUCCESS, + is_role_change); } diff --git a/stack/bnep/bnep_utils.cc b/stack/bnep/bnep_utils.cc index ecae262dc..06a5115c4 100644 --- a/stack/bnep/bnep_utils.cc +++ b/stack/bnep/bnep_utils.cc @@ -24,26 +24,27 @@ #include #include +#include "bnep_int.h" #include "bt_common.h" #include "bt_types.h" -#include "bnep_int.h" -#include "btu.h" -#include "btm_int.h" #include "bt_utils.h" +#include "btm_int.h" +#include "btu.h" #include "device/include/controller.h" #include "osi/include/osi.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static uint8_t *bnepu_init_hdr (BT_HDR *p_buf, uint16_t hdr_len, uint8_t pkt_type); - -void bnepu_process_peer_multicast_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filters, uint16_t len); -void bnepu_send_peer_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_code); +static uint8_t* bnepu_init_hdr(BT_HDR* p_buf, uint16_t hdr_len, + uint8_t pkt_type); +void bnepu_process_peer_multicast_filter_set(tBNEP_CONN* p_bcb, + uint8_t* p_filters, uint16_t len); +void bnepu_send_peer_multicast_filter_rsp(tBNEP_CONN* p_bcb, + uint16_t response_code); /******************************************************************************* * @@ -55,23 +56,20 @@ void bnepu_send_peer_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_ * Returns the BCB address, or NULL if not found. * ******************************************************************************/ -tBNEP_CONN *bnepu_find_bcb_by_cid (uint16_t cid) -{ - uint16_t xx; - tBNEP_CONN *p_bcb; - - /* Look through each connection control block */ - for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) - { - if ((p_bcb->con_state != BNEP_STATE_IDLE) && (p_bcb->l2cap_cid == cid)) - return (p_bcb); - } - - /* If here, not found */ - return (NULL); +tBNEP_CONN* bnepu_find_bcb_by_cid(uint16_t cid) { + uint16_t xx; + tBNEP_CONN* p_bcb; + + /* Look through each connection control block */ + for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) { + if ((p_bcb->con_state != BNEP_STATE_IDLE) && (p_bcb->l2cap_cid == cid)) + return (p_bcb); + } + + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function bnepu_find_bcb_by_bd_addr @@ -82,26 +80,22 @@ tBNEP_CONN *bnepu_find_bcb_by_cid (uint16_t cid) * Returns the BCB address, or NULL if not found. * ******************************************************************************/ -tBNEP_CONN *bnepu_find_bcb_by_bd_addr (uint8_t *p_bda) -{ - uint16_t xx; - tBNEP_CONN *p_bcb; - - /* Look through each connection control block */ - for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) - { - if (p_bcb->con_state != BNEP_STATE_IDLE) - { - if (!memcmp ((uint8_t *)(p_bcb->rem_bda), p_bda, BD_ADDR_LEN)) - return (p_bcb); - } +tBNEP_CONN* bnepu_find_bcb_by_bd_addr(uint8_t* p_bda) { + uint16_t xx; + tBNEP_CONN* p_bcb; + + /* Look through each connection control block */ + for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) { + if (p_bcb->con_state != BNEP_STATE_IDLE) { + if (!memcmp((uint8_t*)(p_bcb->rem_bda), p_bda, BD_ADDR_LEN)) + return (p_bcb); } + } - /* If here, not found */ - return (NULL); + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function bnepu_allocate_bcb @@ -111,33 +105,29 @@ tBNEP_CONN *bnepu_find_bcb_by_bd_addr (uint8_t *p_bda) * Returns BCB address, or NULL if none available. * ******************************************************************************/ -tBNEP_CONN *bnepu_allocate_bcb (BD_ADDR p_rem_bda) -{ - uint16_t xx; - tBNEP_CONN *p_bcb; - - /* Look through each connection control block for a free one */ - for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) - { - if (p_bcb->con_state == BNEP_STATE_IDLE) - { - alarm_free(p_bcb->conn_timer); - memset ((uint8_t *)p_bcb, 0, sizeof (tBNEP_CONN)); - p_bcb->conn_timer = alarm_new("bnep.conn_timer"); - - memcpy ((uint8_t *)(p_bcb->rem_bda), (uint8_t *)p_rem_bda, BD_ADDR_LEN); - p_bcb->handle = xx + 1; - p_bcb->xmit_q = fixed_queue_new(SIZE_MAX); - - return (p_bcb); - } +tBNEP_CONN* bnepu_allocate_bcb(BD_ADDR p_rem_bda) { + uint16_t xx; + tBNEP_CONN* p_bcb; + + /* Look through each connection control block for a free one */ + for (xx = 0, p_bcb = bnep_cb.bcb; xx < BNEP_MAX_CONNECTIONS; xx++, p_bcb++) { + if (p_bcb->con_state == BNEP_STATE_IDLE) { + alarm_free(p_bcb->conn_timer); + memset((uint8_t*)p_bcb, 0, sizeof(tBNEP_CONN)); + p_bcb->conn_timer = alarm_new("bnep.conn_timer"); + + memcpy((uint8_t*)(p_bcb->rem_bda), (uint8_t*)p_rem_bda, BD_ADDR_LEN); + p_bcb->handle = xx + 1; + p_bcb->xmit_q = fixed_queue_new(SIZE_MAX); + + return (p_bcb); } + } - /* If here, no free BCB found */ - return (NULL); + /* If here, no free BCB found */ + return (NULL); } - /******************************************************************************* * * Function bnepu_release_bcb @@ -147,26 +137,23 @@ tBNEP_CONN *bnepu_allocate_bcb (BD_ADDR p_rem_bda) * Returns void * ******************************************************************************/ -void bnepu_release_bcb (tBNEP_CONN *p_bcb) -{ - /* Ensure timer is stopped */ - alarm_free(p_bcb->conn_timer); - p_bcb->conn_timer = NULL; - - /* Drop any response pointer we may be holding */ - p_bcb->con_state = BNEP_STATE_IDLE; - p_bcb->p_pending_data = NULL; - - /* Free transmit queue */ - while (!fixed_queue_is_empty(p_bcb->xmit_q)) - { - osi_free(fixed_queue_try_dequeue(p_bcb->xmit_q)); - } - fixed_queue_free(p_bcb->xmit_q, NULL); - p_bcb->xmit_q = NULL; +void bnepu_release_bcb(tBNEP_CONN* p_bcb) { + /* Ensure timer is stopped */ + alarm_free(p_bcb->conn_timer); + p_bcb->conn_timer = NULL; + + /* Drop any response pointer we may be holding */ + p_bcb->con_state = BNEP_STATE_IDLE; + p_bcb->p_pending_data = NULL; + + /* Free transmit queue */ + while (!fixed_queue_is_empty(p_bcb->xmit_q)) { + osi_free(fixed_queue_try_dequeue(p_bcb->xmit_q)); + } + fixed_queue_free(p_bcb->xmit_q, NULL); + p_bcb->xmit_q = NULL; } - /******************************************************************************* * * Function bnep_send_conn_req @@ -176,54 +163,45 @@ void bnepu_release_bcb (tBNEP_CONN *p_bcb) * Returns void * ******************************************************************************/ -void bnep_send_conn_req (tBNEP_CONN *p_bcb) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p, *p_start; - - BNEP_TRACE_DEBUG ("%s: sending setup req with dst uuid %x", - __func__, p_bcb->dst_uuid.uu.uuid16); - - p_buf->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); - - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_SETUP_CONNECTION_REQUEST_MSG); - - UINT8_TO_BE_STREAM (p, p_bcb->dst_uuid.len); - - if (p_bcb->dst_uuid.len == 2) - { - UINT16_TO_BE_STREAM (p, p_bcb->dst_uuid.uu.uuid16); - UINT16_TO_BE_STREAM (p, p_bcb->src_uuid.uu.uuid16); - } - else if (p_bcb->dst_uuid.len == 4) - { - UINT32_TO_BE_STREAM (p, p_bcb->dst_uuid.uu.uuid32); - UINT32_TO_BE_STREAM (p, p_bcb->src_uuid.uu.uuid32); - } - else if (p_bcb->dst_uuid.len == 16) - { - memcpy (p, p_bcb->dst_uuid.uu.uuid128, p_bcb->dst_uuid.len); - p += p_bcb->dst_uuid.len; - memcpy (p, p_bcb->src_uuid.uu.uuid128, p_bcb->dst_uuid.len); - p += p_bcb->dst_uuid.len; - } - else - { - BNEP_TRACE_ERROR ("%s: uuid: %x, invalid length: %x", - __func__, p_bcb->dst_uuid.uu.uuid16, p_bcb->dst_uuid.len); - } - - p_buf->len = (uint16_t)(p - p_start); - - bnepu_check_send_packet (p_bcb, p_buf); +void bnep_send_conn_req(tBNEP_CONN* p_bcb) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t *p, *p_start; + + BNEP_TRACE_DEBUG("%s: sending setup req with dst uuid %x", __func__, + p_bcb->dst_uuid.uu.uuid16); + + p_buf->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); + + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_SETUP_CONNECTION_REQUEST_MSG); + + UINT8_TO_BE_STREAM(p, p_bcb->dst_uuid.len); + + if (p_bcb->dst_uuid.len == 2) { + UINT16_TO_BE_STREAM(p, p_bcb->dst_uuid.uu.uuid16); + UINT16_TO_BE_STREAM(p, p_bcb->src_uuid.uu.uuid16); + } else if (p_bcb->dst_uuid.len == 4) { + UINT32_TO_BE_STREAM(p, p_bcb->dst_uuid.uu.uuid32); + UINT32_TO_BE_STREAM(p, p_bcb->src_uuid.uu.uuid32); + } else if (p_bcb->dst_uuid.len == 16) { + memcpy(p, p_bcb->dst_uuid.uu.uuid128, p_bcb->dst_uuid.len); + p += p_bcb->dst_uuid.len; + memcpy(p, p_bcb->src_uuid.uu.uuid128, p_bcb->dst_uuid.len); + p += p_bcb->dst_uuid.len; + } else { + BNEP_TRACE_ERROR("%s: uuid: %x, invalid length: %x", __func__, + p_bcb->dst_uuid.uu.uuid16, p_bcb->dst_uuid.len); + } + + p_buf->len = (uint16_t)(p - p_start); + + bnepu_check_send_packet(p_bcb, p_buf); } - /******************************************************************************* * * Function bnep_send_conn_responce @@ -233,31 +211,29 @@ void bnep_send_conn_req (tBNEP_CONN *p_bcb) * Returns void * ******************************************************************************/ -void bnep_send_conn_responce (tBNEP_CONN *p_bcb, uint16_t resp_code) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; +void bnep_send_conn_responce(tBNEP_CONN* p_bcb, uint16_t resp_code) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; - BNEP_TRACE_EVENT ("BNEP - bnep_send_conn_responce for CID: 0x%x", p_bcb->l2cap_cid); + BNEP_TRACE_EVENT("BNEP - bnep_send_conn_responce for CID: 0x%x", + p_bcb->l2cap_cid); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_SETUP_CONNECTION_RESPONSE_MSG); + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_SETUP_CONNECTION_RESPONSE_MSG); - UINT16_TO_BE_STREAM (p, resp_code); + UINT16_TO_BE_STREAM(p, resp_code); - p_buf->len = 4; - - bnepu_check_send_packet (p_bcb, p_buf); + p_buf->len = 4; + bnepu_check_send_packet(p_bcb, p_buf); } - /******************************************************************************* * * Function bnepu_send_peer_our_filters @@ -267,43 +243,39 @@ void bnep_send_conn_responce (tBNEP_CONN *p_bcb, uint16_t resp_code) * Returns void * ******************************************************************************/ -void bnepu_send_peer_our_filters (tBNEP_CONN *p_bcb) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; - uint16_t xx; +void bnepu_send_peer_our_filters(tBNEP_CONN* p_bcb) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; + uint16_t xx; - BNEP_TRACE_DEBUG ("BNEP sending peer our filters"); + BNEP_TRACE_DEBUG("BNEP sending peer our filters"); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_FILTER_NET_TYPE_SET_MSG); + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_FILTER_NET_TYPE_SET_MSG); - UINT16_TO_BE_STREAM (p, (4 * p_bcb->sent_num_filters)); - for (xx = 0; xx < p_bcb->sent_num_filters; xx++) - { - UINT16_TO_BE_STREAM (p, p_bcb->sent_prot_filter_start[xx]); - UINT16_TO_BE_STREAM (p, p_bcb->sent_prot_filter_end[xx]); - } + UINT16_TO_BE_STREAM(p, (4 * p_bcb->sent_num_filters)); + for (xx = 0; xx < p_bcb->sent_num_filters; xx++) { + UINT16_TO_BE_STREAM(p, p_bcb->sent_prot_filter_start[xx]); + UINT16_TO_BE_STREAM(p, p_bcb->sent_prot_filter_end[xx]); + } - p_buf->len = 4 + (4 * p_bcb->sent_num_filters); + p_buf->len = 4 + (4 * p_bcb->sent_num_filters); - bnepu_check_send_packet (p_bcb, p_buf); + bnepu_check_send_packet(p_bcb, p_buf); - p_bcb->con_flags |= BNEP_FLAGS_FILTER_RESP_PEND; + p_bcb->con_flags |= BNEP_FLAGS_FILTER_RESP_PEND; - /* Start timer waiting for setup response */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); + /* Start timer waiting for setup response */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); } - /******************************************************************************* * * Function bnepu_send_peer_our_multi_filters @@ -313,44 +285,40 @@ void bnepu_send_peer_our_filters (tBNEP_CONN *p_bcb) * Returns void * ******************************************************************************/ -void bnepu_send_peer_our_multi_filters (tBNEP_CONN *p_bcb) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; - uint16_t xx; - - BNEP_TRACE_DEBUG ("BNEP sending peer our multicast filters"); - - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); - - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_FILTER_MULTI_ADDR_SET_MSG); - - UINT16_TO_BE_STREAM (p, (2 * BD_ADDR_LEN * p_bcb->sent_mcast_filters)); - for (xx = 0; xx < p_bcb->sent_mcast_filters; xx++) - { - memcpy (p, p_bcb->sent_mcast_filter_start[xx], BD_ADDR_LEN); - p += BD_ADDR_LEN; - memcpy (p, p_bcb->sent_mcast_filter_end[xx], BD_ADDR_LEN); - p += BD_ADDR_LEN; - } +void bnepu_send_peer_our_multi_filters(tBNEP_CONN* p_bcb) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; + uint16_t xx; - p_buf->len = 4 + (2 * BD_ADDR_LEN * p_bcb->sent_mcast_filters); + BNEP_TRACE_DEBUG("BNEP sending peer our multicast filters"); - bnepu_check_send_packet (p_bcb, p_buf); + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_bcb->con_flags |= BNEP_FLAGS_MULTI_RESP_PEND; + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Start timer waiting for setup response */ - alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); -} + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_FILTER_MULTI_ADDR_SET_MSG); + + UINT16_TO_BE_STREAM(p, (2 * BD_ADDR_LEN * p_bcb->sent_mcast_filters)); + for (xx = 0; xx < p_bcb->sent_mcast_filters; xx++) { + memcpy(p, p_bcb->sent_mcast_filter_start[xx], BD_ADDR_LEN); + p += BD_ADDR_LEN; + memcpy(p, p_bcb->sent_mcast_filter_end[xx], BD_ADDR_LEN); + p += BD_ADDR_LEN; + } + p_buf->len = 4 + (2 * BD_ADDR_LEN * p_bcb->sent_mcast_filters); + + bnepu_check_send_packet(p_bcb, p_buf); + + p_bcb->con_flags |= BNEP_FLAGS_MULTI_RESP_PEND; + + /* Start timer waiting for setup response */ + alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); +} /******************************************************************************* * @@ -361,30 +329,28 @@ void bnepu_send_peer_our_multi_filters (tBNEP_CONN *p_bcb) * Returns void * ******************************************************************************/ -void bnepu_send_peer_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_code) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; +void bnepu_send_peer_filter_rsp(tBNEP_CONN* p_bcb, uint16_t response_code) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; - BNEP_TRACE_DEBUG ("BNEP sending filter response"); + BNEP_TRACE_DEBUG("BNEP sending filter response"); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_FILTER_NET_TYPE_RESPONSE_MSG); + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_FILTER_NET_TYPE_RESPONSE_MSG); - UINT16_TO_BE_STREAM (p, response_code); + UINT16_TO_BE_STREAM(p, response_code); - p_buf->len = 4; + p_buf->len = 4; - bnepu_check_send_packet (p_bcb, p_buf); + bnepu_check_send_packet(p_bcb, p_buf); } - /******************************************************************************* * * Function bnep_send_command_not_understood @@ -394,31 +360,30 @@ void bnepu_send_peer_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_code) * Returns void * ******************************************************************************/ -void bnep_send_command_not_understood (tBNEP_CONN *p_bcb, uint8_t cmd_code) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; +void bnep_send_command_not_understood(tBNEP_CONN* p_bcb, uint8_t cmd_code) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; - BNEP_TRACE_EVENT ("BNEP - bnep_send_command_not_understood for CID: 0x%x, cmd 0x%x", p_bcb->l2cap_cid, cmd_code); + BNEP_TRACE_EVENT( + "BNEP - bnep_send_command_not_understood for CID: 0x%x, cmd 0x%x", + p_bcb->l2cap_cid, cmd_code); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD); + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD); - UINT8_TO_BE_STREAM (p, cmd_code); + UINT8_TO_BE_STREAM(p, cmd_code); - p_buf->len = 3; - - bnepu_check_send_packet (p_bcb, p_buf); + p_buf->len = 3; + bnepu_check_send_packet(p_bcb, p_buf); } - /******************************************************************************* * * Function bnepu_check_send_packet @@ -430,29 +395,23 @@ void bnep_send_command_not_understood (tBNEP_CONN *p_bcb, uint8_t cmd_code) * Returns void * ******************************************************************************/ -void bnepu_check_send_packet (tBNEP_CONN *p_bcb, BT_HDR *p_buf) -{ - BNEP_TRACE_EVENT ("BNEP - bnepu_check_send_packet for CID: 0x%x", p_bcb->l2cap_cid); - if (p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED) - { - if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) - { - BNEP_TRACE_EVENT ("BNEP - congested, dropping buf, CID: 0x%x", p_bcb->l2cap_cid); - - osi_free(p_buf); - } - else - { - fixed_queue_enqueue(p_bcb->xmit_q, p_buf); - } - } - else - { - L2CA_DataWrite (p_bcb->l2cap_cid, p_buf); +void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf) { + BNEP_TRACE_EVENT("BNEP - bnepu_check_send_packet for CID: 0x%x", + p_bcb->l2cap_cid); + if (p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED) { + if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) { + BNEP_TRACE_EVENT("BNEP - congested, dropping buf, CID: 0x%x", + p_bcb->l2cap_cid); + + osi_free(p_buf); + } else { + fixed_queue_enqueue(p_bcb->xmit_q, p_buf); } + } else { + L2CA_DataWrite(p_bcb->l2cap_cid, p_buf); + } } - /******************************************************************************* * * Function bnepu_build_bnep_hdr @@ -464,59 +423,65 @@ void bnepu_check_send_packet (tBNEP_CONN *p_bcb, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -void bnepu_build_bnep_hdr (tBNEP_CONN *p_bcb, BT_HDR *p_buf, uint16_t protocol, - uint8_t *p_src_addr, uint8_t *p_dest_addr, bool fw_ext_present) -{ - const controller_t *controller = controller_get_interface(); - uint8_t ext_bit, *p = (uint8_t *)NULL; - uint8_t type = BNEP_FRAME_COMPRESSED_ETHERNET; +void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, uint16_t protocol, + uint8_t* p_src_addr, uint8_t* p_dest_addr, + bool fw_ext_present) { + const controller_t* controller = controller_get_interface(); + uint8_t ext_bit, *p = (uint8_t *)NULL; + uint8_t type = BNEP_FRAME_COMPRESSED_ETHERNET; - ext_bit = fw_ext_present ? 0x80 : 0x00; + ext_bit = fw_ext_present ? 0x80 : 0x00; - if ((p_src_addr) && (memcmp (p_src_addr, &controller->get_address()->address, BD_ADDR_LEN))) - type = BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY; + if ((p_src_addr) && + (memcmp(p_src_addr, &controller->get_address()->address, BD_ADDR_LEN))) + type = BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY; - if (memcmp (p_dest_addr, p_bcb->rem_bda, BD_ADDR_LEN)) - type = (type == BNEP_FRAME_COMPRESSED_ETHERNET) ? BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY : BNEP_FRAME_GENERAL_ETHERNET; + if (memcmp(p_dest_addr, p_bcb->rem_bda, BD_ADDR_LEN)) + type = (type == BNEP_FRAME_COMPRESSED_ETHERNET) + ? BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY + : BNEP_FRAME_GENERAL_ETHERNET; - if (!p_src_addr) - p_src_addr = (uint8_t *)controller->get_address(); + if (!p_src_addr) p_src_addr = (uint8_t*)controller->get_address(); - switch (type) - { + switch (type) { case BNEP_FRAME_GENERAL_ETHERNET: - p = bnepu_init_hdr (p_buf, 15, (uint8_t)(ext_bit | BNEP_FRAME_GENERAL_ETHERNET)); + p = bnepu_init_hdr(p_buf, 15, + (uint8_t)(ext_bit | BNEP_FRAME_GENERAL_ETHERNET)); - memcpy (p, p_dest_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; + memcpy(p, p_dest_addr, BD_ADDR_LEN); + p += BD_ADDR_LEN; - memcpy (p, p_src_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; - break; + memcpy(p, p_src_addr, BD_ADDR_LEN); + p += BD_ADDR_LEN; + break; case BNEP_FRAME_COMPRESSED_ETHERNET: - p = bnepu_init_hdr (p_buf, 3, (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET)); - break; + p = bnepu_init_hdr(p_buf, 3, + (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET)); + break; case BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY: - p = bnepu_init_hdr (p_buf, 9, (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY)); + p = bnepu_init_hdr( + p_buf, 9, + (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY)); - memcpy (p, p_src_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; - break; + memcpy(p, p_src_addr, BD_ADDR_LEN); + p += BD_ADDR_LEN; + break; case BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY: - p = bnepu_init_hdr (p_buf, 9, (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY)); + p = bnepu_init_hdr( + p_buf, 9, + (uint8_t)(ext_bit | BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY)); - memcpy (p, p_dest_addr, BD_ADDR_LEN); - p += BD_ADDR_LEN; - break; - } + memcpy(p, p_dest_addr, BD_ADDR_LEN); + p += BD_ADDR_LEN; + break; + } - UINT16_TO_BE_STREAM (p, protocol); + UINT16_TO_BE_STREAM(p, protocol); } - /******************************************************************************* * * Function bnepu_init_hdr @@ -526,31 +491,28 @@ void bnepu_build_bnep_hdr (tBNEP_CONN *p_bcb, BT_HDR *p_buf, uint16_t protocol, * Returns pointer to header in buffer * ******************************************************************************/ -static uint8_t *bnepu_init_hdr (BT_HDR *p_buf, uint16_t hdr_len, uint8_t pkt_type) -{ - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* See if we need to make space in the buffer */ - if (p_buf->offset < (hdr_len + L2CAP_MIN_OFFSET)) - { - uint16_t xx, diff = BNEP_MINIMUM_OFFSET - p_buf->offset; - p = p + p_buf->len - 1; - for (xx = 0; xx < p_buf->len; xx++, p--) - p[diff] = *p; - - p_buf->offset = BNEP_MINIMUM_OFFSET; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - } +static uint8_t* bnepu_init_hdr(BT_HDR* p_buf, uint16_t hdr_len, + uint8_t pkt_type) { + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p -= hdr_len; + /* See if we need to make space in the buffer */ + if (p_buf->offset < (hdr_len + L2CAP_MIN_OFFSET)) { + uint16_t xx, diff = BNEP_MINIMUM_OFFSET - p_buf->offset; + p = p + p_buf->len - 1; + for (xx = 0; xx < p_buf->len; xx++, p--) p[diff] = *p; - *p++ = pkt_type; + p_buf->offset = BNEP_MINIMUM_OFFSET; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + } - return (p); -} + p_buf->len += hdr_len; + p_buf->offset -= hdr_len; + p -= hdr_len; + *p++ = pkt_type; + + return (p); +} /******************************************************************************* * @@ -563,95 +525,90 @@ static uint8_t *bnepu_init_hdr (BT_HDR *p_buf, uint16_t hdr_len, uint8_t pkt_typ * Returns void * ******************************************************************************/ -void bnep_process_setup_conn_req (tBNEP_CONN *p_bcb, uint8_t *p_setup, uint8_t len) -{ - BNEP_TRACE_EVENT ("BNEP - bnep_process_setup_conn_req for CID: 0x%x", p_bcb->l2cap_cid); - - if (p_bcb->con_state != BNEP_STATE_CONN_SETUP && - p_bcb->con_state != BNEP_STATE_SEC_CHECKING && - p_bcb->con_state != BNEP_STATE_CONNECTED) - { - BNEP_TRACE_ERROR ("BNEP - setup request in bad state %d", p_bcb->con_state); - bnep_send_conn_responce (p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); - return; - } - - /* Check if we already initiated security check or if waiting for user responce */ - if (p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD) - { - BNEP_TRACE_EVENT ("BNEP - Duplicate Setup message received while doing security check"); - return; - } - - /* Check if peer is the originator */ - if (p_bcb->con_state != BNEP_STATE_CONNECTED && - (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) && - (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) - { - BNEP_TRACE_ERROR ("BNEP - setup request when we are originator", p_bcb->con_state); - bnep_send_conn_responce (p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); - return; - } - - if (p_bcb->con_state == BNEP_STATE_CONNECTED) - { - memcpy ((uint8_t *)&(p_bcb->prv_src_uuid), (uint8_t *)&(p_bcb->src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->prv_dst_uuid), (uint8_t *)&(p_bcb->dst_uuid), sizeof (tBT_UUID)); - } +void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup, + uint8_t len) { + BNEP_TRACE_EVENT("BNEP - bnep_process_setup_conn_req for CID: 0x%x", + p_bcb->l2cap_cid); + + if (p_bcb->con_state != BNEP_STATE_CONN_SETUP && + p_bcb->con_state != BNEP_STATE_SEC_CHECKING && + p_bcb->con_state != BNEP_STATE_CONNECTED) { + BNEP_TRACE_ERROR("BNEP - setup request in bad state %d", p_bcb->con_state); + bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); + return; + } - p_bcb->dst_uuid.len = p_bcb->src_uuid.len = len; - - if (p_bcb->dst_uuid.len == 2) - { - /* because peer initiated connection keep src uuid as dst uuid */ - BE_STREAM_TO_UINT16 (p_bcb->src_uuid.uu.uuid16, p_setup); - BE_STREAM_TO_UINT16 (p_bcb->dst_uuid.uu.uuid16, p_setup); - - /* If nothing has changed don't bother the profile */ - if (p_bcb->con_state == BNEP_STATE_CONNECTED && - p_bcb->src_uuid.uu.uuid16 == p_bcb->prv_src_uuid.uu.uuid16 && - p_bcb->dst_uuid.uu.uuid16 == p_bcb->prv_dst_uuid.uu.uuid16) - { - bnep_send_conn_responce (p_bcb, BNEP_SETUP_CONN_OK); - return; - } - } - else if (p_bcb->dst_uuid.len == 4) - { - BE_STREAM_TO_UINT32 (p_bcb->src_uuid.uu.uuid32, p_setup); - BE_STREAM_TO_UINT32 (p_bcb->dst_uuid.uu.uuid32, p_setup); - } - else if (p_bcb->dst_uuid.len == 16) - { - memcpy (p_bcb->src_uuid.uu.uuid128, p_setup, p_bcb->src_uuid.len); - p_setup += p_bcb->src_uuid.len; - memcpy (p_bcb->dst_uuid.uu.uuid128, p_setup, p_bcb->dst_uuid.len); - p_setup += p_bcb->dst_uuid.len; - } - else - { - BNEP_TRACE_ERROR ("BNEP - Bad UID len %d in ConnReq", p_bcb->dst_uuid.len); - bnep_send_conn_responce (p_bcb, BNEP_SETUP_INVALID_UUID_SIZE); - return; + /* Check if we already initiated security check or if waiting for user + * responce */ + if (p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD) { + BNEP_TRACE_EVENT( + "BNEP - Duplicate Setup message received while doing security check"); + return; + } + + /* Check if peer is the originator */ + if (p_bcb->con_state != BNEP_STATE_CONNECTED && + (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) && + (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) { + BNEP_TRACE_ERROR("BNEP - setup request when we are originator", + p_bcb->con_state); + bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); + return; + } + + if (p_bcb->con_state == BNEP_STATE_CONNECTED) { + memcpy((uint8_t*)&(p_bcb->prv_src_uuid), (uint8_t*)&(p_bcb->src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->prv_dst_uuid), (uint8_t*)&(p_bcb->dst_uuid), + sizeof(tBT_UUID)); + } + + p_bcb->dst_uuid.len = p_bcb->src_uuid.len = len; + + if (p_bcb->dst_uuid.len == 2) { + /* because peer initiated connection keep src uuid as dst uuid */ + BE_STREAM_TO_UINT16(p_bcb->src_uuid.uu.uuid16, p_setup); + BE_STREAM_TO_UINT16(p_bcb->dst_uuid.uu.uuid16, p_setup); + + /* If nothing has changed don't bother the profile */ + if (p_bcb->con_state == BNEP_STATE_CONNECTED && + p_bcb->src_uuid.uu.uuid16 == p_bcb->prv_src_uuid.uu.uuid16 && + p_bcb->dst_uuid.uu.uuid16 == p_bcb->prv_dst_uuid.uu.uuid16) { + bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_OK); + return; } + } else if (p_bcb->dst_uuid.len == 4) { + BE_STREAM_TO_UINT32(p_bcb->src_uuid.uu.uuid32, p_setup); + BE_STREAM_TO_UINT32(p_bcb->dst_uuid.uu.uuid32, p_setup); + } else if (p_bcb->dst_uuid.len == 16) { + memcpy(p_bcb->src_uuid.uu.uuid128, p_setup, p_bcb->src_uuid.len); + p_setup += p_bcb->src_uuid.len; + memcpy(p_bcb->dst_uuid.uu.uuid128, p_setup, p_bcb->dst_uuid.len); + p_setup += p_bcb->dst_uuid.len; + } else { + BNEP_TRACE_ERROR("BNEP - Bad UID len %d in ConnReq", p_bcb->dst_uuid.len); + bnep_send_conn_responce(p_bcb, BNEP_SETUP_INVALID_UUID_SIZE); + return; + } - p_bcb->con_state = BNEP_STATE_SEC_CHECKING; - p_bcb->con_flags |= BNEP_FLAGS_SETUP_RCVD; + p_bcb->con_state = BNEP_STATE_SEC_CHECKING; + p_bcb->con_flags |= BNEP_FLAGS_SETUP_RCVD; - BNEP_TRACE_EVENT ("BNEP initiating security check for incoming call for uuid 0x%x", p_bcb->src_uuid.uu.uuid16); + BNEP_TRACE_EVENT( + "BNEP initiating security check for incoming call for uuid 0x%x", + p_bcb->src_uuid.uu.uuid16); #if (BNEP_DO_AUTH_FOR_ROLE_SWITCH == FALSE) - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - bnep_sec_check_complete (p_bcb->rem_bda, p_bcb, BTM_SUCCESS); - else + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) + bnep_sec_check_complete(p_bcb->rem_bda, p_bcb, BTM_SUCCESS); + else #endif - btm_sec_mx_access_request (p_bcb->rem_bda, BT_PSM_BNEP, false, - BTM_SEC_PROTO_BNEP, bnep_get_uuid32(&(p_bcb->src_uuid)), - &bnep_sec_check_complete, p_bcb); + btm_sec_mx_access_request( + p_bcb->rem_bda, BT_PSM_BNEP, false, BTM_SEC_PROTO_BNEP, + bnep_get_uuid32(&(p_bcb->src_uuid)), &bnep_sec_check_complete, p_bcb); - return; + return; } - /******************************************************************************* * * Function bnep_process_setup_conn_responce @@ -663,92 +620,86 @@ void bnep_process_setup_conn_req (tBNEP_CONN *p_bcb, uint8_t *p_setup, uint8_t l * Returns void * ******************************************************************************/ -void bnep_process_setup_conn_responce (tBNEP_CONN *p_bcb, uint8_t *p_setup) -{ - tBNEP_RESULT resp; - uint16_t resp_code; - - BNEP_TRACE_DEBUG ("BNEP received setup responce"); - /* The state should be either SETUP or CONNECTED */ - if (p_bcb->con_state != BNEP_STATE_CONN_SETUP) - { - /* Should we disconnect ? */ - BNEP_TRACE_ERROR ("BNEP - setup response in bad state %d", p_bcb->con_state); - return; - } +void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, uint8_t* p_setup) { + tBNEP_RESULT resp; + uint16_t resp_code; + + BNEP_TRACE_DEBUG("BNEP received setup responce"); + /* The state should be either SETUP or CONNECTED */ + if (p_bcb->con_state != BNEP_STATE_CONN_SETUP) { + /* Should we disconnect ? */ + BNEP_TRACE_ERROR("BNEP - setup response in bad state %d", p_bcb->con_state); + return; + } - /* Check if we are the originator */ - if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) - { - BNEP_TRACE_ERROR ("BNEP - setup response when we are not originator", p_bcb->con_state); - return; - } + /* Check if we are the originator */ + if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) { + BNEP_TRACE_ERROR("BNEP - setup response when we are not originator", + p_bcb->con_state); + return; + } - BE_STREAM_TO_UINT16 (resp_code, p_setup); + BE_STREAM_TO_UINT16(resp_code, p_setup); - switch (resp_code) - { + switch (resp_code) { case BNEP_SETUP_INVALID_SRC_UUID: - resp = BNEP_CONN_FAILED_SRC_UUID; - break; + resp = BNEP_CONN_FAILED_SRC_UUID; + break; case BNEP_SETUP_INVALID_DEST_UUID: - resp = BNEP_CONN_FAILED_DST_UUID; - break; + resp = BNEP_CONN_FAILED_DST_UUID; + break; case BNEP_SETUP_INVALID_UUID_SIZE: - resp = BNEP_CONN_FAILED_UUID_SIZE; - break; + resp = BNEP_CONN_FAILED_UUID_SIZE; + break; case BNEP_SETUP_CONN_NOT_ALLOWED: default: - resp = BNEP_CONN_FAILED; - break; + resp = BNEP_CONN_FAILED; + break; + } + + /* Check the responce code */ + if (resp_code != BNEP_SETUP_CONN_OK) { + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) { + BNEP_TRACE_EVENT("BNEP - role change response is %d", resp_code); + + /* Restore the earlier BNEP status */ + p_bcb->con_state = BNEP_STATE_CONNECTED; + p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); + memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid), + sizeof(tBT_UUID)); + + /* Ensure timer is stopped */ + alarm_cancel(p_bcb->conn_timer); + p_bcb->re_transmits = 0; + + /* Tell the user if he has a callback */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, resp, true); + + return; + } else { + BNEP_TRACE_ERROR("BNEP - setup response %d is not OK", resp_code); + + L2CA_DisconnectReq(p_bcb->l2cap_cid); + + /* Tell the user if he has a callback */ + if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, resp, false); + + bnepu_release_bcb(p_bcb); + return; } + } - /* Check the responce code */ - if (resp_code != BNEP_SETUP_CONN_OK) - { - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - { - BNEP_TRACE_EVENT ("BNEP - role change response is %d", resp_code); - - /* Restore the earlier BNEP status */ - p_bcb->con_state = BNEP_STATE_CONNECTED; - p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); - memcpy ((uint8_t *)&(p_bcb->src_uuid), (uint8_t *)&(p_bcb->prv_src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->dst_uuid), (uint8_t *)&(p_bcb->prv_dst_uuid), sizeof (tBT_UUID)); - - /* Ensure timer is stopped */ - alarm_cancel(p_bcb->conn_timer); - p_bcb->re_transmits = 0; - - /* Tell the user if he has a callback */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, resp, true); - - return; - } - else - { - BNEP_TRACE_ERROR ("BNEP - setup response %d is not OK", resp_code); - - L2CA_DisconnectReq (p_bcb->l2cap_cid); - - /* Tell the user if he has a callback */ - if ((p_bcb->con_flags & BNEP_FLAGS_IS_ORIG) && (bnep_cb.p_conn_state_cb)) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, resp, false); - - bnepu_release_bcb (p_bcb); - return; - } - } - - /* Received successful responce */ - bnep_connected (p_bcb); + /* Received successful responce */ + bnep_connected(p_bcb); } - /******************************************************************************* * * Function bnep_process_control_packet @@ -760,112 +711,106 @@ void bnep_process_setup_conn_responce (tBNEP_CONN *p_bcb, uint8_t *p_setup) * Returns void * ******************************************************************************/ -uint8_t *bnep_process_control_packet (tBNEP_CONN *p_bcb, uint8_t *p, uint16_t *rem_len, bool is_ext) -{ - uint8_t control_type; - bool bad_pkt = false; - uint16_t len, ext_len = 0; - - if (is_ext) - { - ext_len = *p++; - *rem_len = *rem_len - 1; - } - - control_type = *p++; +uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p, + uint16_t* rem_len, bool is_ext) { + uint8_t control_type; + bool bad_pkt = false; + uint16_t len, ext_len = 0; + + if (is_ext) { + ext_len = *p++; *rem_len = *rem_len - 1; + } - BNEP_TRACE_EVENT ("BNEP processing control packet rem_len %d, is_ext %d, ctrl_type %d", *rem_len, is_ext, control_type); + control_type = *p++; + *rem_len = *rem_len - 1; - switch (control_type) - { + BNEP_TRACE_EVENT( + "BNEP processing control packet rem_len %d, is_ext %d, ctrl_type %d", + *rem_len, is_ext, control_type); + + switch (control_type) { case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD: - BNEP_TRACE_ERROR ("BNEP Received Cmd not understood for ctl pkt type: %d", *p); - p++; - *rem_len = *rem_len - 1; - break; + BNEP_TRACE_ERROR("BNEP Received Cmd not understood for ctl pkt type: %d", + *p); + p++; + *rem_len = *rem_len - 1; + break; case BNEP_SETUP_CONNECTION_REQUEST_MSG: - len = *p++; - if (*rem_len < ((2 * len) + 1)) - { - bad_pkt = true; - BNEP_TRACE_ERROR ("BNEP Received Setup message with bad length"); - break; - } - if (!is_ext) - bnep_process_setup_conn_req (p_bcb, p, (uint8_t)len); - p += (2 * len); - *rem_len = *rem_len - (2 * len) - 1; + len = *p++; + if (*rem_len < ((2 * len) + 1)) { + bad_pkt = true; + BNEP_TRACE_ERROR("BNEP Received Setup message with bad length"); break; + } + if (!is_ext) bnep_process_setup_conn_req(p_bcb, p, (uint8_t)len); + p += (2 * len); + *rem_len = *rem_len - (2 * len) - 1; + break; case BNEP_SETUP_CONNECTION_RESPONSE_MSG: - if (!is_ext) - bnep_process_setup_conn_responce (p_bcb, p); - p += 2; - *rem_len = *rem_len - 2; - break; + if (!is_ext) bnep_process_setup_conn_responce(p_bcb, p); + p += 2; + *rem_len = *rem_len - 2; + break; case BNEP_FILTER_NET_TYPE_SET_MSG: - BE_STREAM_TO_UINT16 (len, p); - if (*rem_len < (len + 2)) - { - bad_pkt = true; - BNEP_TRACE_ERROR ("BNEP Received Filter set message with bad length"); - break; - } - bnepu_process_peer_filter_set (p_bcb, p, len); - p += len; - *rem_len = *rem_len - len - 2; + BE_STREAM_TO_UINT16(len, p); + if (*rem_len < (len + 2)) { + bad_pkt = true; + BNEP_TRACE_ERROR("BNEP Received Filter set message with bad length"); break; + } + bnepu_process_peer_filter_set(p_bcb, p, len); + p += len; + *rem_len = *rem_len - len - 2; + break; case BNEP_FILTER_NET_TYPE_RESPONSE_MSG: - bnepu_process_peer_filter_rsp (p_bcb, p); - p += 2; - *rem_len = *rem_len - 2; - break; + bnepu_process_peer_filter_rsp(p_bcb, p); + p += 2; + *rem_len = *rem_len - 2; + break; case BNEP_FILTER_MULTI_ADDR_SET_MSG: - BE_STREAM_TO_UINT16 (len, p); - if (*rem_len < (len + 2)) - { - bad_pkt = true; - BNEP_TRACE_ERROR ("BNEP Received Multicast Filter Set message with bad length"); - break; - } - bnepu_process_peer_multicast_filter_set (p_bcb, p, len); - p += len; - *rem_len = *rem_len - len - 2; + BE_STREAM_TO_UINT16(len, p); + if (*rem_len < (len + 2)) { + bad_pkt = true; + BNEP_TRACE_ERROR( + "BNEP Received Multicast Filter Set message with bad length"); break; + } + bnepu_process_peer_multicast_filter_set(p_bcb, p, len); + p += len; + *rem_len = *rem_len - len - 2; + break; case BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG: - bnepu_process_multicast_filter_rsp (p_bcb, p); - p += 2; - *rem_len = *rem_len - 2; - break; - - default : - BNEP_TRACE_ERROR ("BNEP - bad ctl pkt type: %d", control_type); - bnep_send_command_not_understood (p_bcb, control_type); - if (is_ext) - { - p += (ext_len - 1); - *rem_len -= (ext_len - 1); - } - break; - } - - if (bad_pkt) - { - BNEP_TRACE_ERROR ("BNEP - bad ctl pkt length: %d", *rem_len); - *rem_len = 0; - return NULL; - } + bnepu_process_multicast_filter_rsp(p_bcb, p); + p += 2; + *rem_len = *rem_len - 2; + break; - return p; + default: + BNEP_TRACE_ERROR("BNEP - bad ctl pkt type: %d", control_type); + bnep_send_command_not_understood(p_bcb, control_type); + if (is_ext) { + p += (ext_len - 1); + *rem_len -= (ext_len - 1); + } + break; + } + + if (bad_pkt) { + BNEP_TRACE_ERROR("BNEP - bad ctl pkt length: %d", *rem_len); + *rem_len = 0; + return NULL; + } + + return p; } - /******************************************************************************* * * Function bnepu_process_peer_filter_set @@ -877,73 +822,64 @@ uint8_t *bnep_process_control_packet (tBNEP_CONN *p_bcb, uint8_t *p, uint16_t *r * Returns void * ******************************************************************************/ -void bnepu_process_peer_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filters, uint16_t len) -{ - uint16_t num_filters = 0; - uint16_t xx, resp_code = BNEP_FILTER_CRL_OK; - uint16_t start, end; - uint8_t *p_temp_filters; - - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - { - BNEP_TRACE_DEBUG ("BNEP received filter set from peer when there is no connection"); - return; - } +void bnepu_process_peer_filter_set(tBNEP_CONN* p_bcb, uint8_t* p_filters, + uint16_t len) { + uint16_t num_filters = 0; + uint16_t xx, resp_code = BNEP_FILTER_CRL_OK; + uint16_t start, end; + uint8_t* p_temp_filters; + + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) { + BNEP_TRACE_DEBUG( + "BNEP received filter set from peer when there is no connection"); + return; + } - BNEP_TRACE_DEBUG ("BNEP received filter set from peer"); - /* Check for length not a multiple of 4 */ - if (len & 3) - { - BNEP_TRACE_EVENT ("BNEP - bad filter len: %d", len); - bnepu_send_peer_filter_rsp (p_bcb, BNEP_FILTER_CRL_BAD_RANGE); - return; - } + BNEP_TRACE_DEBUG("BNEP received filter set from peer"); + /* Check for length not a multiple of 4 */ + if (len & 3) { + BNEP_TRACE_EVENT("BNEP - bad filter len: %d", len); + bnepu_send_peer_filter_rsp(p_bcb, BNEP_FILTER_CRL_BAD_RANGE); + return; + } - if (len) - num_filters = (uint16_t) (len >> 2); - - /* Validate filter values */ - if (num_filters <= BNEP_MAX_PROT_FILTERS) - { - p_temp_filters = p_filters; - for (xx = 0; xx < num_filters; xx++) - { - BE_STREAM_TO_UINT16 (start, p_temp_filters); - BE_STREAM_TO_UINT16 (end, p_temp_filters); - - if (start > end) - { - resp_code = BNEP_FILTER_CRL_BAD_RANGE; - break; - } - } - } - else - resp_code = BNEP_FILTER_CRL_MAX_REACHED; + if (len) num_filters = (uint16_t)(len >> 2); - if (resp_code != BNEP_FILTER_CRL_OK) - { - bnepu_send_peer_filter_rsp (p_bcb, resp_code); - return; + /* Validate filter values */ + if (num_filters <= BNEP_MAX_PROT_FILTERS) { + p_temp_filters = p_filters; + for (xx = 0; xx < num_filters; xx++) { + BE_STREAM_TO_UINT16(start, p_temp_filters); + BE_STREAM_TO_UINT16(end, p_temp_filters); + + if (start > end) { + resp_code = BNEP_FILTER_CRL_BAD_RANGE; + break; + } } + } else + resp_code = BNEP_FILTER_CRL_MAX_REACHED; - if (bnep_cb.p_filter_ind_cb) - (*bnep_cb.p_filter_ind_cb) (p_bcb->handle, true, 0, len, p_filters); + if (resp_code != BNEP_FILTER_CRL_OK) { + bnepu_send_peer_filter_rsp(p_bcb, resp_code); + return; + } - p_bcb->rcvd_num_filters = num_filters; - for (xx = 0; xx < num_filters; xx++) - { - BE_STREAM_TO_UINT16 (start, p_filters); - BE_STREAM_TO_UINT16 (end, p_filters); + if (bnep_cb.p_filter_ind_cb) + (*bnep_cb.p_filter_ind_cb)(p_bcb->handle, true, 0, len, p_filters); - p_bcb->rcvd_prot_filter_start[xx] = start; - p_bcb->rcvd_prot_filter_end[xx] = end; - } + p_bcb->rcvd_num_filters = num_filters; + for (xx = 0; xx < num_filters; xx++) { + BE_STREAM_TO_UINT16(start, p_filters); + BE_STREAM_TO_UINT16(end, p_filters); - bnepu_send_peer_filter_rsp (p_bcb, resp_code); -} + p_bcb->rcvd_prot_filter_start[xx] = start; + p_bcb->rcvd_prot_filter_end[xx] = end; + } + bnepu_send_peer_filter_rsp(p_bcb, resp_code); +} /******************************************************************************* * @@ -955,40 +891,37 @@ void bnepu_process_peer_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filters, uint1 * Returns void * ******************************************************************************/ -void bnepu_process_peer_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data) -{ - uint16_t resp_code; - tBNEP_RESULT result; - - BNEP_TRACE_DEBUG ("BNEP received filter responce"); - /* The state should be CONNECTED */ - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - { - BNEP_TRACE_ERROR ("BNEP - filter response in bad state %d", p_bcb->con_state); - return; - } +void bnepu_process_peer_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data) { + uint16_t resp_code; + tBNEP_RESULT result; + + BNEP_TRACE_DEBUG("BNEP received filter responce"); + /* The state should be CONNECTED */ + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) { + BNEP_TRACE_ERROR("BNEP - filter response in bad state %d", + p_bcb->con_state); + return; + } - /* Check if we are the originator */ - if (!(p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)) - { - BNEP_TRACE_ERROR ("BNEP - filter response when not expecting"); - return; - } + /* Check if we are the originator */ + if (!(p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)) { + BNEP_TRACE_ERROR("BNEP - filter response when not expecting"); + return; + } - /* Ensure timer is stopped */ - alarm_cancel(p_bcb->conn_timer); - p_bcb->con_flags &= ~BNEP_FLAGS_FILTER_RESP_PEND; - p_bcb->re_transmits = 0; + /* Ensure timer is stopped */ + alarm_cancel(p_bcb->conn_timer); + p_bcb->con_flags &= ~BNEP_FLAGS_FILTER_RESP_PEND; + p_bcb->re_transmits = 0; - BE_STREAM_TO_UINT16 (resp_code, p_data); + BE_STREAM_TO_UINT16(resp_code, p_data); - result = BNEP_SUCCESS; - if (resp_code != BNEP_FILTER_CRL_OK) - result = BNEP_SET_FILTER_FAIL; + result = BNEP_SUCCESS; + if (resp_code != BNEP_FILTER_CRL_OK) result = BNEP_SET_FILTER_FAIL; - if (bnep_cb.p_filter_ind_cb) - (*bnep_cb.p_filter_ind_cb) (p_bcb->handle, false, result, 0, NULL); + if (bnep_cb.p_filter_ind_cb) + (*bnep_cb.p_filter_ind_cb)(p_bcb->handle, false, result, 0, NULL); } /******************************************************************************* @@ -1001,40 +934,37 @@ void bnepu_process_peer_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data) * Returns void * ******************************************************************************/ -void bnepu_process_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data) -{ - uint16_t resp_code; - tBNEP_RESULT result; - - BNEP_TRACE_DEBUG ("BNEP received multicast filter responce"); - /* The state should be CONNECTED */ - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - { - BNEP_TRACE_ERROR ("BNEP - multicast filter response in bad state %d", p_bcb->con_state); - return; - } +void bnepu_process_multicast_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data) { + uint16_t resp_code; + tBNEP_RESULT result; + + BNEP_TRACE_DEBUG("BNEP received multicast filter responce"); + /* The state should be CONNECTED */ + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) { + BNEP_TRACE_ERROR("BNEP - multicast filter response in bad state %d", + p_bcb->con_state); + return; + } - /* Check if we are the originator */ - if (!(p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)) - { - BNEP_TRACE_ERROR ("BNEP - multicast filter response when not expecting"); - return; - } + /* Check if we are the originator */ + if (!(p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)) { + BNEP_TRACE_ERROR("BNEP - multicast filter response when not expecting"); + return; + } - /* Ensure timer is stopped */ - alarm_cancel(p_bcb->conn_timer); - p_bcb->con_flags &= ~BNEP_FLAGS_MULTI_RESP_PEND; - p_bcb->re_transmits = 0; + /* Ensure timer is stopped */ + alarm_cancel(p_bcb->conn_timer); + p_bcb->con_flags &= ~BNEP_FLAGS_MULTI_RESP_PEND; + p_bcb->re_transmits = 0; - BE_STREAM_TO_UINT16 (resp_code, p_data); + BE_STREAM_TO_UINT16(resp_code, p_data); - result = BNEP_SUCCESS; - if (resp_code != BNEP_FILTER_CRL_OK) - result = BNEP_SET_FILTER_FAIL; + result = BNEP_SUCCESS; + if (resp_code != BNEP_FILTER_CRL_OK) result = BNEP_SET_FILTER_FAIL; - if (bnep_cb.p_mfilter_ind_cb) - (*bnep_cb.p_mfilter_ind_cb) (p_bcb->handle, false, result, 0, NULL); + if (bnep_cb.p_mfilter_ind_cb) + (*bnep_cb.p_mfilter_ind_cb)(p_bcb->handle, false, result, 0, NULL); } /******************************************************************************* @@ -1048,77 +978,74 @@ void bnepu_process_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint8_t *p_data) * Returns void * ******************************************************************************/ -void bnepu_process_peer_multicast_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filters, uint16_t len) -{ - uint16_t resp_code = BNEP_FILTER_CRL_OK; - uint16_t num_filters, xx; - uint8_t *p_temp_filters, null_bda[BD_ADDR_LEN] = {0,0,0,0,0,0}; - - if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && - (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) - { - BNEP_TRACE_DEBUG ("BNEP received multicast filter set from peer when there is no connection"); - return; - } +void bnepu_process_peer_multicast_filter_set(tBNEP_CONN* p_bcb, + uint8_t* p_filters, uint16_t len) { + uint16_t resp_code = BNEP_FILTER_CRL_OK; + uint16_t num_filters, xx; + uint8_t *p_temp_filters, null_bda[BD_ADDR_LEN] = {0, 0, 0, 0, 0, 0}; + + if ((p_bcb->con_state != BNEP_STATE_CONNECTED) && + (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) { + BNEP_TRACE_DEBUG( + "BNEP received multicast filter set from peer when there is no " + "connection"); + return; + } - if (len % 12) - { - BNEP_TRACE_EVENT ("BNEP - bad filter len: %d", len); - bnepu_send_peer_multicast_filter_rsp (p_bcb, BNEP_FILTER_CRL_BAD_RANGE); - return; - } + if (len % 12) { + BNEP_TRACE_EVENT("BNEP - bad filter len: %d", len); + bnepu_send_peer_multicast_filter_rsp(p_bcb, BNEP_FILTER_CRL_BAD_RANGE); + return; + } - if (len > (BNEP_MAX_MULTI_FILTERS * 2 * BD_ADDR_LEN)) - { - BNEP_TRACE_EVENT ("BNEP - Too many filters"); - bnepu_send_peer_multicast_filter_rsp (p_bcb, BNEP_FILTER_CRL_MAX_REACHED); + if (len > (BNEP_MAX_MULTI_FILTERS * 2 * BD_ADDR_LEN)) { + BNEP_TRACE_EVENT("BNEP - Too many filters"); + bnepu_send_peer_multicast_filter_rsp(p_bcb, BNEP_FILTER_CRL_MAX_REACHED); + return; + } + + num_filters = 0; + if (len) num_filters = (uint16_t)(len / 12); + + /* Validate filter values */ + if (num_filters <= BNEP_MAX_MULTI_FILTERS) { + p_temp_filters = p_filters; + for (xx = 0; xx < num_filters; xx++) { + if (memcmp(p_temp_filters, p_temp_filters + BD_ADDR_LEN, BD_ADDR_LEN) > + 0) { + bnepu_send_peer_multicast_filter_rsp(p_bcb, BNEP_FILTER_CRL_BAD_RANGE); return; - } + } - num_filters = 0; - if (len) - num_filters = (uint16_t) (len / 12); - - /* Validate filter values */ - if (num_filters <= BNEP_MAX_MULTI_FILTERS) - { - p_temp_filters = p_filters; - for (xx = 0; xx < num_filters; xx++) - { - if (memcmp (p_temp_filters, p_temp_filters + BD_ADDR_LEN, BD_ADDR_LEN) > 0) - { - bnepu_send_peer_multicast_filter_rsp (p_bcb, BNEP_FILTER_CRL_BAD_RANGE); - return; - } - - p_temp_filters += (BD_ADDR_LEN * 2); - } + p_temp_filters += (BD_ADDR_LEN * 2); } - - p_bcb->rcvd_mcast_filters = num_filters; - for (xx = 0; xx < num_filters; xx++) - { - memcpy (p_bcb->rcvd_mcast_filter_start[xx], p_filters, BD_ADDR_LEN); - memcpy (p_bcb->rcvd_mcast_filter_end[xx], p_filters + BD_ADDR_LEN, BD_ADDR_LEN); - p_filters += (BD_ADDR_LEN * 2); - - /* Check if any of the ranges have all zeros as both starting and ending addresses */ - if ((memcmp (null_bda, p_bcb->rcvd_mcast_filter_start[xx], BD_ADDR_LEN) == 0) && - (memcmp (null_bda, p_bcb->rcvd_mcast_filter_end[xx], BD_ADDR_LEN) == 0)) - { - p_bcb->rcvd_mcast_filters = 0xFFFF; - break; - } + } + + p_bcb->rcvd_mcast_filters = num_filters; + for (xx = 0; xx < num_filters; xx++) { + memcpy(p_bcb->rcvd_mcast_filter_start[xx], p_filters, BD_ADDR_LEN); + memcpy(p_bcb->rcvd_mcast_filter_end[xx], p_filters + BD_ADDR_LEN, + BD_ADDR_LEN); + p_filters += (BD_ADDR_LEN * 2); + + /* Check if any of the ranges have all zeros as both starting and ending + * addresses */ + if ((memcmp(null_bda, p_bcb->rcvd_mcast_filter_start[xx], BD_ADDR_LEN) == + 0) && + (memcmp(null_bda, p_bcb->rcvd_mcast_filter_end[xx], BD_ADDR_LEN) == + 0)) { + p_bcb->rcvd_mcast_filters = 0xFFFF; + break; } + } - BNEP_TRACE_EVENT ("BNEP multicast filters %d", p_bcb->rcvd_mcast_filters); - bnepu_send_peer_multicast_filter_rsp (p_bcb, resp_code); + BNEP_TRACE_EVENT("BNEP multicast filters %d", p_bcb->rcvd_mcast_filters); + bnepu_send_peer_multicast_filter_rsp(p_bcb, resp_code); - if (bnep_cb.p_mfilter_ind_cb) - (*bnep_cb.p_mfilter_ind_cb) (p_bcb->handle, true, 0, len, p_filters); + if (bnep_cb.p_mfilter_ind_cb) + (*bnep_cb.p_mfilter_ind_cb)(p_bcb->handle, true, 0, len, p_filters); } - /******************************************************************************* * * Function bnepu_send_peer_multicast_filter_rsp @@ -1128,31 +1055,29 @@ void bnepu_process_peer_multicast_filter_set (tBNEP_CONN *p_bcb, uint8_t *p_filt * Returns void * ******************************************************************************/ -void bnepu_send_peer_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_code) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(BNEP_BUF_SIZE); - uint8_t *p; +void bnepu_send_peer_multicast_filter_rsp(tBNEP_CONN* p_bcb, + uint16_t response_code) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE); + uint8_t* p; - BNEP_TRACE_DEBUG ("BNEP sending multicast filter response %d", response_code); + BNEP_TRACE_DEBUG("BNEP sending multicast filter response %d", response_code); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Put in BNEP frame type - filter control */ - UINT8_TO_BE_STREAM (p, BNEP_FRAME_CONTROL); + /* Put in BNEP frame type - filter control */ + UINT8_TO_BE_STREAM(p, BNEP_FRAME_CONTROL); - /* Put in filter message type - set filters */ - UINT8_TO_BE_STREAM (p, BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG); + /* Put in filter message type - set filters */ + UINT8_TO_BE_STREAM(p, BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG); - UINT16_TO_BE_STREAM (p, response_code); + UINT16_TO_BE_STREAM(p, response_code); - p_buf->len = 4; + p_buf->len = 4; - bnepu_check_send_packet (p_bcb, p_buf); + bnepu_check_send_packet(p_bcb, p_buf); } - - /******************************************************************************* * * Function bnep_sec_check_complete @@ -1163,99 +1088,99 @@ void bnepu_send_peer_multicast_filter_rsp (tBNEP_CONN *p_bcb, uint16_t response_ * Returns void * ******************************************************************************/ -void bnep_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT trasnport, - void *p_ref_data, uint8_t result) -{ - tBNEP_CONN *p_bcb = (tBNEP_CONN *)p_ref_data; - uint16_t resp_code = BNEP_SETUP_CONN_OK; - bool is_role_change; - - BNEP_TRACE_EVENT ("BNEP security callback returned result %d", result); - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - is_role_change = true; - else - is_role_change = false; - - /* check if the port is still waiting for security to complete */ - if (p_bcb->con_state != BNEP_STATE_SEC_CHECKING) - { - BNEP_TRACE_ERROR ("BNEP Connection in wrong state %d when security is completed", p_bcb->con_state); +void bnep_sec_check_complete(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT trasnport, + void* p_ref_data, uint8_t result) { + tBNEP_CONN* p_bcb = (tBNEP_CONN*)p_ref_data; + uint16_t resp_code = BNEP_SETUP_CONN_OK; + bool is_role_change; + + BNEP_TRACE_EVENT("BNEP security callback returned result %d", result); + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) + is_role_change = true; + else + is_role_change = false; + + /* check if the port is still waiting for security to complete */ + if (p_bcb->con_state != BNEP_STATE_SEC_CHECKING) { + BNEP_TRACE_ERROR( + "BNEP Connection in wrong state %d when security is completed", + p_bcb->con_state); + return; + } + + /* if it is outgoing call and result is FAILURE return security fail error */ + if (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) { + if (result != BTM_SUCCESS) { + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) { + /* Tell the user that role change is failed because of security */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_SECURITY_FAIL, is_role_change); + + p_bcb->con_state = BNEP_STATE_CONNECTED; + memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid), + sizeof(tBT_UUID)); return; - } + } - /* if it is outgoing call and result is FAILURE return security fail error */ - if (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) - { - if (result != BTM_SUCCESS) - { - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - { - /* Tell the user that role change is failed because of security */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SECURITY_FAIL, is_role_change); - - p_bcb->con_state = BNEP_STATE_CONNECTED; - memcpy ((uint8_t *)&(p_bcb->src_uuid), (uint8_t *)&(p_bcb->prv_src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->dst_uuid), (uint8_t *)&(p_bcb->prv_dst_uuid), sizeof (tBT_UUID)); - return; - } - - L2CA_DisconnectReq (p_bcb->l2cap_cid); - - /* Tell the user if he has a callback */ - if (bnep_cb.p_conn_state_cb) - (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_SECURITY_FAIL, is_role_change); - - bnepu_release_bcb (p_bcb); - return; - } - - /* Transition to the next appropriate state, waiting for connection confirm. */ - p_bcb->con_state = BNEP_STATE_CONN_SETUP; - - bnep_send_conn_req (p_bcb); - alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, - bnep_conn_timer_timeout, p_bcb, - btu_general_alarm_queue); - return; - } + L2CA_DisconnectReq(p_bcb->l2cap_cid); - /* it is an incoming call respond appropriately */ - if (result != BTM_SUCCESS) - { - bnep_send_conn_responce (p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); - if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) - { - /* Role change is failed because of security. Revert back to connected state */ - p_bcb->con_state = BNEP_STATE_CONNECTED; - p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); - memcpy ((uint8_t *)&(p_bcb->src_uuid), (uint8_t *)&(p_bcb->prv_src_uuid), sizeof (tBT_UUID)); - memcpy ((uint8_t *)&(p_bcb->dst_uuid), (uint8_t *)&(p_bcb->prv_dst_uuid), sizeof (tBT_UUID)); - return; - } - - L2CA_DisconnectReq (p_bcb->l2cap_cid); - - bnepu_release_bcb (p_bcb); - return; - } + /* Tell the user if he has a callback */ + if (bnep_cb.p_conn_state_cb) + (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, + BNEP_SECURITY_FAIL, is_role_change); - if (bnep_cb.p_conn_ind_cb) - { - p_bcb->con_state = BNEP_STATE_CONN_SETUP; - (*bnep_cb.p_conn_ind_cb) (p_bcb->handle, p_bcb->rem_bda, &p_bcb->dst_uuid, &p_bcb->src_uuid, is_role_change); + bnepu_release_bcb(p_bcb); + return; } - else - { - /* Profile didn't register connection indication call back */ - bnep_send_conn_responce (p_bcb, resp_code); - bnep_connected (p_bcb); + + /* Transition to the next appropriate state, waiting for connection confirm. + */ + p_bcb->con_state = BNEP_STATE_CONN_SETUP; + + bnep_send_conn_req(p_bcb); + alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, + bnep_conn_timer_timeout, p_bcb, btu_general_alarm_queue); + return; + } + + /* it is an incoming call respond appropriately */ + if (result != BTM_SUCCESS) { + bnep_send_conn_responce(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED); + if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) { + /* Role change is failed because of security. Revert back to connected + * state */ + p_bcb->con_state = BNEP_STATE_CONNECTED; + p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD); + memcpy((uint8_t*)&(p_bcb->src_uuid), (uint8_t*)&(p_bcb->prv_src_uuid), + sizeof(tBT_UUID)); + memcpy((uint8_t*)&(p_bcb->dst_uuid), (uint8_t*)&(p_bcb->prv_dst_uuid), + sizeof(tBT_UUID)); + return; } + L2CA_DisconnectReq(p_bcb->l2cap_cid); + + bnepu_release_bcb(p_bcb); return; + } + + if (bnep_cb.p_conn_ind_cb) { + p_bcb->con_state = BNEP_STATE_CONN_SETUP; + (*bnep_cb.p_conn_ind_cb)(p_bcb->handle, p_bcb->rem_bda, &p_bcb->dst_uuid, + &p_bcb->src_uuid, is_role_change); + } else { + /* Profile didn't register connection indication call back */ + bnep_send_conn_responce(p_bcb, resp_code); + bnep_connected(p_bcb); + } + + return; } - /******************************************************************************* * * Function bnep_is_packet_allowed @@ -1267,82 +1192,73 @@ void bnep_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANS * BNEP_IGNORE_CMD - if the protocol is filtered out * ******************************************************************************/ -tBNEP_RESULT bnep_is_packet_allowed (tBNEP_CONN *p_bcb, - BD_ADDR p_dest_addr, - uint16_t protocol, - bool fw_ext_present, - uint8_t *p_data) -{ - if (p_bcb->rcvd_num_filters) - { - uint16_t i, proto; - - /* Findout the actual protocol to check for the filtering */ - proto = protocol; - if (proto == BNEP_802_1_P_PROTOCOL) - { - if (fw_ext_present) - { - uint8_t len, ext; - /* parse the extension headers and findout actual protocol */ - do { - - ext = *p_data++; - len = *p_data++; - p_data += len; - - } while (ext & 0x80); - } - p_data += 2; - BE_STREAM_TO_UINT16 (proto, p_data); - } - - for (i=0; ircvd_num_filters; i++) - { - if ((p_bcb->rcvd_prot_filter_start[i] <= proto) && - (proto <= p_bcb->rcvd_prot_filter_end[i])) - break; - } - - if (i == p_bcb->rcvd_num_filters) - { - BNEP_TRACE_DEBUG ("Ignoring protocol 0x%x in BNEP data write", proto); - return BNEP_IGNORE_CMD; - } +tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb, BD_ADDR p_dest_addr, + uint16_t protocol, bool fw_ext_present, + uint8_t* p_data) { + if (p_bcb->rcvd_num_filters) { + uint16_t i, proto; + + /* Findout the actual protocol to check for the filtering */ + proto = protocol; + if (proto == BNEP_802_1_P_PROTOCOL) { + if (fw_ext_present) { + uint8_t len, ext; + /* parse the extension headers and findout actual protocol */ + do { + ext = *p_data++; + len = *p_data++; + p_data += len; + + } while (ext & 0x80); + } + p_data += 2; + BE_STREAM_TO_UINT16(proto, p_data); } - /* Ckeck for multicast address filtering */ - if ((p_dest_addr[0] & 0x01) && - p_bcb->rcvd_mcast_filters) - { - uint16_t i; - - /* Check if every multicast should be filtered */ - if (p_bcb->rcvd_mcast_filters != 0xFFFF) - { - /* Check if the address is mentioned in the filter range */ - for (i = 0; i < p_bcb->rcvd_mcast_filters; i++) - { - if ((memcmp (p_bcb->rcvd_mcast_filter_start[i], p_dest_addr, BD_ADDR_LEN) <= 0) && - (memcmp (p_bcb->rcvd_mcast_filter_end[i], p_dest_addr, BD_ADDR_LEN) >= 0)) - break; - } - } - - /* - ** If every multicast should be filtered or the address is not in the filter range - ** drop the packet - */ - if ((p_bcb->rcvd_mcast_filters == 0xFFFF) || (i == p_bcb->rcvd_mcast_filters)) - { - BNEP_TRACE_DEBUG ("Ignoring multicast address %x.%x.%x.%x.%x.%x in BNEP data write", - p_dest_addr[0], p_dest_addr[1], p_dest_addr[2], - p_dest_addr[3], p_dest_addr[4], p_dest_addr[5]); - return BNEP_IGNORE_CMD; - } + for (i = 0; i < p_bcb->rcvd_num_filters; i++) { + if ((p_bcb->rcvd_prot_filter_start[i] <= proto) && + (proto <= p_bcb->rcvd_prot_filter_end[i])) + break; } - return BNEP_SUCCESS; + if (i == p_bcb->rcvd_num_filters) { + BNEP_TRACE_DEBUG("Ignoring protocol 0x%x in BNEP data write", proto); + return BNEP_IGNORE_CMD; + } + } + + /* Ckeck for multicast address filtering */ + if ((p_dest_addr[0] & 0x01) && p_bcb->rcvd_mcast_filters) { + uint16_t i; + + /* Check if every multicast should be filtered */ + if (p_bcb->rcvd_mcast_filters != 0xFFFF) { + /* Check if the address is mentioned in the filter range */ + for (i = 0; i < p_bcb->rcvd_mcast_filters; i++) { + if ((memcmp(p_bcb->rcvd_mcast_filter_start[i], p_dest_addr, + BD_ADDR_LEN) <= 0) && + (memcmp(p_bcb->rcvd_mcast_filter_end[i], p_dest_addr, + BD_ADDR_LEN) >= 0)) + break; + } + } + + /* + ** If every multicast should be filtered or the address is not in the filter + *range + ** drop the packet + */ + if ((p_bcb->rcvd_mcast_filters == 0xFFFF) || + (i == p_bcb->rcvd_mcast_filters)) { + BNEP_TRACE_DEBUG( + "Ignoring multicast address %x.%x.%x.%x.%x.%x in BNEP data write", + p_dest_addr[0], p_dest_addr[1], p_dest_addr[2], p_dest_addr[3], + p_dest_addr[4], p_dest_addr[5]); + return BNEP_IGNORE_CMD; + } + } + + return BNEP_SUCCESS; } /******************************************************************************* @@ -1354,18 +1270,16 @@ tBNEP_RESULT bnep_is_packet_allowed (tBNEP_CONN *p_bcb, * Returns uint32_t - 32-bit equivalent of the UUID * ******************************************************************************/ -uint32_t bnep_get_uuid32 (tBT_UUID *src_uuid) -{ - uint32_t result; - - if (src_uuid->len == 2) - return ((uint32_t)src_uuid->uu.uuid16); - else if (src_uuid->len == 4) - return (src_uuid->uu.uuid32 & 0x0000FFFF); - else - { - result = src_uuid->uu.uuid128[2]; - result = (result << 8) | (src_uuid->uu.uuid128[3]); - return result; - } +uint32_t bnep_get_uuid32(tBT_UUID* src_uuid) { + uint32_t result; + + if (src_uuid->len == 2) + return ((uint32_t)src_uuid->uu.uuid16); + else if (src_uuid->len == 4) + return (src_uuid->uu.uuid32 & 0x0000FFFF); + else { + result = src_uuid->uu.uuid128[2]; + result = (result << 8) | (src_uuid->uu.uuid128[3]); + return result; + } } diff --git a/stack/btm/ble_advertiser_hci_interface.cc b/stack/btm/ble_advertiser_hci_interface.cc index eff5ea3d8..92423b110 100644 --- a/stack/btm/ble_advertiser_hci_interface.cc +++ b/stack/btm/ble_advertiser_hci_interface.cc @@ -38,19 +38,19 @@ using status_cb = BleAdvertiserHciInterface::status_cb; -typedef void (*hci_cmd_complete_cb)(uint16_t opcode, uint8_t *return_parameters, +typedef void (*hci_cmd_complete_cb)(uint16_t opcode, uint8_t* return_parameters, uint16_t return_parameters_length); -extern void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t *params, +extern void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t* params, uint8_t params_len, hci_cmd_complete_cb cb); namespace { -BleAdvertiserHciInterface *instance = nullptr; -std::queue> *pending_ops = nullptr; +BleAdvertiserHciInterface* instance = nullptr; +std::queue>* pending_ops = nullptr; -void btm_ble_multi_adv_vsc_cmpl_cback(tBTM_VSC_CMPL *p_params) { +void btm_ble_multi_adv_vsc_cmpl_cback(tBTM_VSC_CMPL* p_params) { uint8_t status, subcode; - uint8_t *p = p_params->p_param_buf; + uint8_t* p = p_params->p_param_buf; uint16_t len = p_params->param_len; // All multi-adv commands respond with status and inst_id. @@ -75,7 +75,7 @@ void btm_ble_multi_adv_vsc_cmpl_cback(tBTM_VSC_CMPL *p_params) { } class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { - void SendVscMultiAdvCmd(uint8_t param_len, uint8_t *param_buf, + void SendVscMultiAdvCmd(uint8_t param_len, uint8_t* param_buf, status_cb command_complete) { BTM_VendorSpecificCommand(HCI_BLE_MULTI_ADV_OCF, param_len, param_buf, btm_ble_multi_adv_vsc_cmpl_cback); @@ -88,7 +88,7 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { } void SetAdvertisingEventObserver( - AdvertisingEventObserver *observer) override { + AdvertisingEventObserver* observer) override { this->advertising_event_observer = observer; } @@ -102,7 +102,7 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { uint8_t param[BTM_BLE_MULTI_ADV_SET_PARAM_LEN]; memset(param, 0, BTM_BLE_MULTI_ADV_SET_PARAM_LEN); - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, BTM_BLE_MULTI_ADV_SET_PARAM); UINT16_TO_STREAM(pp, adv_int_min); UINT16_TO_STREAM(pp, adv_int_max); @@ -120,13 +120,13 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { command_complete); } - void SetAdvertisingData(uint8_t data_length, uint8_t *data, uint8_t inst_id, + void SetAdvertisingData(uint8_t data_length, uint8_t* data, uint8_t inst_id, status_cb command_complete) override { VLOG(1) << __func__; uint8_t param[BTM_BLE_MULTI_ADV_WRITE_DATA_LEN]; memset(param, 0, BTM_BLE_MULTI_ADV_WRITE_DATA_LEN); - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, BTM_BLE_MULTI_ADV_WRITE_ADV_DATA); UINT8_TO_STREAM(pp, data_length); ARRAY_TO_STREAM(pp, data, data_length); @@ -137,13 +137,13 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { } void SetScanResponseData(uint8_t scan_response_data_length, - uint8_t *scan_response_data, uint8_t inst_id, + uint8_t* scan_response_data, uint8_t inst_id, status_cb command_complete) override { VLOG(1) << __func__; uint8_t param[BTM_BLE_MULTI_ADV_WRITE_DATA_LEN]; memset(param, 0, BTM_BLE_MULTI_ADV_WRITE_DATA_LEN); - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, BTM_BLE_MULTI_ADV_WRITE_SCAN_RSP_DATA); UINT8_TO_STREAM(pp, scan_response_data_length); ARRAY_TO_STREAM(pp, scan_response_data, scan_response_data_length); @@ -159,7 +159,7 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { uint8_t param[BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR_LEN]; memset(param, 0, BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR_LEN); - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR); BDADDR_TO_STREAM(pp, random_address); UINT8_TO_STREAM(pp, inst_id); @@ -174,7 +174,7 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { uint8_t param[BTM_BLE_MULTI_ADV_ENB_LEN]; memset(param, 0, BTM_BLE_MULTI_ADV_ENB_LEN); - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, BTM_BLE_MULTI_ADV_ENB); UINT8_TO_STREAM(pp, advertising_enable); UINT8_TO_STREAM(pp, inst_id); @@ -184,7 +184,7 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { } public: - static void VendorSpecificEventCback(uint8_t length, uint8_t *p) { + static void VendorSpecificEventCback(uint8_t length, uint8_t* p) { VLOG(1) << __func__; LOG_ASSERT(p); @@ -202,18 +202,19 @@ class BleAdvertiserVscHciInterfaceImpl : public BleAdvertiserHciInterface { STREAM_TO_UINT8(change_reason, p); STREAM_TO_UINT16(conn_handle, p); - AdvertisingEventObserver *observer = - ((BleAdvertiserVscHciInterfaceImpl *)BleAdvertiserHciInterface::Get())->advertising_event_observer; + AdvertisingEventObserver* observer = + ((BleAdvertiserVscHciInterfaceImpl*)BleAdvertiserHciInterface::Get()) + ->advertising_event_observer; if (observer) observer->OnAdvertisingStateChanged(adv_inst, change_reason, conn_handle); } private: - AdvertisingEventObserver *advertising_event_observer = nullptr; + AdvertisingEventObserver* advertising_event_observer = nullptr; }; -std::queue> *legacy_pending_ops = nullptr; -void adv_cmd_cmpl_cback(uint16_t opcode, uint8_t *return_parameters, +std::queue>* legacy_pending_ops = nullptr; +void adv_cmd_cmpl_cback(uint16_t opcode, uint8_t* return_parameters, uint16_t return_parameters_length) { uint8_t status = *return_parameters; @@ -233,7 +234,7 @@ void adv_cmd_cmpl_cback(uint16_t opcode, uint8_t *return_parameters, } class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { - void SendAdvCmd(uint16_t opcode, uint8_t *param_buf, uint8_t param_buf_len, + void SendAdvCmd(uint16_t opcode, uint8_t* param_buf, uint8_t param_buf_len, status_cb command_complete) { btu_hcif_send_cmd_with_cb(opcode, param_buf, param_buf_len, adv_cmd_cmpl_cback); @@ -247,7 +248,7 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { } void SetAdvertisingEventObserver( - AdvertisingEventObserver *observer) override {} + AdvertisingEventObserver* observer) override {} void SetParameters(uint8_t adv_int_min, uint8_t adv_int_max, uint8_t advertising_type, uint8_t own_address_type, @@ -259,7 +260,7 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { uint8_t param[HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS]; - uint8_t *pp = param; + uint8_t* pp = param; UINT16_TO_STREAM(pp, adv_int_min); UINT16_TO_STREAM(pp, adv_int_max); UINT8_TO_STREAM(pp, advertising_type); @@ -273,13 +274,13 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS, command_complete); } - void SetAdvertisingData(uint8_t data_length, uint8_t *data, uint8_t inst_id, + void SetAdvertisingData(uint8_t data_length, uint8_t* data, uint8_t inst_id, status_cb command_complete) override { VLOG(1) << __func__; uint8_t param[HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1]; - uint8_t *pp = param; + uint8_t* pp = param; memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1); UINT8_TO_STREAM(pp, data_length); ARRAY_TO_STREAM(pp, data, data_length); @@ -289,12 +290,12 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { } void SetScanResponseData(uint8_t scan_response_data_length, - uint8_t *scan_response_data, uint8_t inst_id, + uint8_t* scan_response_data, uint8_t inst_id, status_cb command_complete) override { VLOG(1) << __func__; uint8_t param[HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1]; - uint8_t *pp = param; + uint8_t* pp = param; memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1); UINT8_TO_STREAM(pp, scan_response_data_length); ARRAY_TO_STREAM(pp, scan_response_data, scan_response_data_length); @@ -309,7 +310,7 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { uint8_t param[HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD]; - uint8_t *pp = param; + uint8_t* pp = param; BDADDR_TO_STREAM(pp, random_address); SendAdvCmd(HCI_BLE_WRITE_RANDOM_ADDR, param, @@ -321,7 +322,7 @@ class BleAdvertiserLegacyHciInterfaceImpl : public BleAdvertiserHciInterface { VLOG(1) << __func__; uint8_t param[HCIC_PARAM_SIZE_WRITE_ADV_ENABLE]; - uint8_t *pp = param; + uint8_t* pp = param; UINT8_TO_STREAM(pp, advertising_enable); SendAdvCmd(HCI_BLE_WRITE_ADV_ENABLE, param, @@ -346,7 +347,7 @@ void BleAdvertiserHciInterface::Initialize() { } } -BleAdvertiserHciInterface *BleAdvertiserHciInterface::Get() { return instance; } +BleAdvertiserHciInterface* BleAdvertiserHciInterface::Get() { return instance; } void BleAdvertiserHciInterface::CleanUp() { VLOG(1) << __func__; diff --git a/stack/btm/ble_advertiser_hci_interface.h b/stack/btm/ble_advertiser_hci_interface.h index 8b5357330..2d88cd0cd 100644 --- a/stack/btm/ble_advertiser_hci_interface.h +++ b/stack/btm/ble_advertiser_hci_interface.h @@ -31,7 +31,7 @@ class BleAdvertiserHciInterface { using status_cb = base::Callback; static void Initialize(); - static BleAdvertiserHciInterface *Get(); + static BleAdvertiserHciInterface* Get(); static void CleanUp(); virtual ~BleAdvertiserHciInterface() = default; @@ -44,19 +44,21 @@ class BleAdvertiserHciInterface { uint16_t connection_handle) = 0; }; - virtual void SetAdvertisingEventObserver(AdvertisingEventObserver *observer) = 0; - virtual void ReadInstanceCount(base::Callback cb) = 0; + virtual void SetAdvertisingEventObserver( + AdvertisingEventObserver* observer) = 0; + virtual void ReadInstanceCount( + base::Callback cb) = 0; virtual void SetParameters(uint8_t adv_int_min, uint8_t adv_int_max, uint8_t advertising_type, uint8_t own_address_type, BD_ADDR own_address, uint8_t direct_address_type, BD_ADDR direct_address, uint8_t channel_map, uint8_t filter_policy, uint8_t inst_id, uint8_t tx_power, status_cb command_complete) = 0; - virtual void SetAdvertisingData(uint8_t data_length, uint8_t *data, + virtual void SetAdvertisingData(uint8_t data_length, uint8_t* data, uint8_t inst_id, status_cb command_complete) = 0; virtual void SetScanResponseData(uint8_t scan_response_data_length, - uint8_t *scan_response_data, uint8_t inst_id, + uint8_t* scan_response_data, uint8_t inst_id, status_cb command_complete) = 0; virtual void SetRandomAddress(BD_ADDR random_address, uint8_t inst_id, status_cb command_complete) = 0; diff --git a/stack/btm/btm_acl.cc b/stack/btm/btm_acl.cc index cfe333b2b..f1e9d3c52 100644 --- a/stack/btm/btm_acl.cc +++ b/stack/btm/btm_acl.cc @@ -31,30 +31,30 @@ * *****************************************************************************/ +#include +#include #include #include -#include -#include -#include "bt_types.h" -#include "bt_target.h" -#include "device/include/controller.h" #include "bt_common.h" -#include "hcimsgs.h" -#include "btu.h" +#include "bt_target.h" +#include "bt_types.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" -#include "l2c_int.h" +#include "btu.h" +#include "device/include/controller.h" #include "hcidefs.h" -#include "bt_utils.h" +#include "hcimsgs.h" +#include "l2c_int.h" #include "osi/include/osi.h" +extern fixed_queue_t* btu_general_alarm_queue; -extern fixed_queue_t *btu_general_alarm_queue; - -static void btm_read_remote_features (uint16_t handle); -static void btm_read_remote_ext_features (uint16_t handle, uint8_t page_number); -static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_read_pages); +static void btm_read_remote_features(uint16_t handle); +static void btm_read_remote_ext_features(uint16_t handle, uint8_t page_number); +static void btm_process_remote_ext_features(tACL_CONN* p_acl_cb, + uint8_t num_read_pages); /* 3 seconds timeout waiting for responses */ #define BTM_DEV_REPLY_TIMEOUT_MS (3 * 1000) @@ -68,12 +68,11 @@ static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_re * Returns void * ******************************************************************************/ -void btm_acl_init (void) -{ - BTM_TRACE_DEBUG ("btm_acl_init"); - /* Initialize nonzero defaults */ - btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT; - btm_cb.acl_disc_reason = 0xff ; +void btm_acl_init(void) { + BTM_TRACE_DEBUG("btm_acl_init"); + /* Initialize nonzero defaults */ + btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT; + btm_cb.acl_disc_reason = 0xff; } /******************************************************************************* @@ -91,25 +90,21 @@ void btm_acl_init (void) * NULL if not found. * ******************************************************************************/ -tACL_CONN *btm_bda_to_acl (const BD_ADDR bda, tBT_TRANSPORT transport) -{ - tACL_CONN *p = &btm_cb.acl_db[0]; - uint16_t xx; - if (bda) - { - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) - { - if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN)) && - p->transport == transport) - { - BTM_TRACE_DEBUG ("btm_bda_to_acl found"); - return(p); - } - } +tACL_CONN* btm_bda_to_acl(const BD_ADDR bda, tBT_TRANSPORT transport) { + tACL_CONN* p = &btm_cb.acl_db[0]; + uint16_t xx; + if (bda) { + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { + if ((p->in_use) && (!memcmp(p->remote_addr, bda, BD_ADDR_LEN)) && + p->transport == transport) { + BTM_TRACE_DEBUG("btm_bda_to_acl found"); + return (p); + } } + } - /* If here, no BD Addr found */ - return((tACL_CONN *)NULL); + /* If here, no BD Addr found */ + return ((tACL_CONN*)NULL); } /******************************************************************************* @@ -122,21 +117,18 @@ tACL_CONN *btm_bda_to_acl (const BD_ADDR bda, tBT_TRANSPORT transport) * Returns index to the acl_db or MAX_L2CAP_LINKS. * ******************************************************************************/ -uint8_t btm_handle_to_acl_index (uint16_t hci_handle) -{ - tACL_CONN *p = &btm_cb.acl_db[0]; - uint8_t xx; - BTM_TRACE_DEBUG ("btm_handle_to_acl_index"); - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) - { - if ((p->in_use) && (p->hci_handle == hci_handle)) - { - break; - } +uint8_t btm_handle_to_acl_index(uint16_t hci_handle) { + tACL_CONN* p = &btm_cb.acl_db[0]; + uint8_t xx; + BTM_TRACE_DEBUG("btm_handle_to_acl_index"); + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { + if ((p->in_use) && (p->hci_handle == hci_handle)) { + break; } + } - /* If here, no BD Addr found */ - return(xx); + /* If here, no BD Addr found */ + return (xx); } #if (BLE_PRIVACY_SPT == TRUE) @@ -150,41 +142,41 @@ uint8_t btm_handle_to_acl_index (uint16_t hci_handle) * Returns success return true, otherwise false. * ******************************************************************************/ -bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr, - tBLE_ADDR_TYPE *p_addr_type) -{ - bool st = true; - - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address"); - return false; - } - - switch (p_dev_rec->ble.active_addr_type) - { +bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC* p_dev_rec, BD_ADDR conn_addr, + tBLE_ADDR_TYPE* p_addr_type) { + bool st = true; + + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR( + "btm_ble_get_acl_remote_addr can not find device with matching " + "address"); + return false; + } + + switch (p_dev_rec->ble.active_addr_type) { case BTM_BLE_ADDR_PSEUDO: - memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - * p_addr_type = p_dev_rec->ble.ble_addr_type; - break; + memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + *p_addr_type = p_dev_rec->ble.ble_addr_type; + break; case BTM_BLE_ADDR_RRA: - memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); - * p_addr_type = BLE_ADDR_RANDOM; - break; + memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); + *p_addr_type = BLE_ADDR_RANDOM; + break; case BTM_BLE_ADDR_STATIC: - memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); - * p_addr_type = p_dev_rec->ble.static_addr_type; - break; + memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); + *p_addr_type = p_dev_rec->ble.static_addr_type; + break; default: - BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type); - st = false; - break; - } + BTM_TRACE_ERROR("Unknown active address: %d", + p_dev_rec->ble.active_addr_type); + st = false; + break; + } - return st; + return st; } #endif /******************************************************************************* @@ -197,133 +189,120 @@ bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_ad * Returns void * ******************************************************************************/ -void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, - uint16_t hci_handle, uint8_t link_role, tBT_TRANSPORT transport) -{ - tBTM_SEC_DEV_REC *p_dev_rec = NULL; - tACL_CONN *p; - uint8_t xx; - - BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d", - hci_handle,link_role, transport); - /* Ensure we don't have duplicates */ - p = btm_bda_to_acl(bda, transport); - if (p != (tACL_CONN *)NULL) - { - p->hci_handle = hci_handle; - p->link_role = link_role; - p->transport = transport; - BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); - BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy); - return; - } - - /* Allocate acl_db entry */ - for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++) - { - if (!p->in_use) - { - p->in_use = true; - p->hci_handle = hci_handle; - p->link_role = link_role; - p->link_up_issued = false; - memcpy (p->remote_addr, bda, BD_ADDR_LEN); - - p->transport = transport; +void btm_acl_created(BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, + uint16_t hci_handle, uint8_t link_role, + tBT_TRANSPORT transport) { + tBTM_SEC_DEV_REC* p_dev_rec = NULL; + tACL_CONN* p; + uint8_t xx; + + BTM_TRACE_DEBUG("btm_acl_created hci_handle=%d link_role=%d transport=%d", + hci_handle, link_role, transport); + /* Ensure we don't have duplicates */ + p = btm_bda_to_acl(bda, transport); + if (p != (tACL_CONN*)NULL) { + p->hci_handle = hci_handle; + p->link_role = link_role; + p->transport = transport; + BTM_TRACE_DEBUG( + "Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy); + return; + } + + /* Allocate acl_db entry */ + for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++) { + if (!p->in_use) { + p->in_use = true; + p->hci_handle = hci_handle; + p->link_role = link_role; + p->link_up_issued = false; + memcpy(p->remote_addr, bda, BD_ADDR_LEN); + + p->transport = transport; #if (BLE_PRIVACY_SPT == TRUE) - if (transport == BT_TRANSPORT_LE) - btm_ble_refresh_local_resolvable_private_addr(bda, - btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr); + if (transport == BT_TRANSPORT_LE) + btm_ble_refresh_local_resolvable_private_addr( + bda, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr); #else - p->conn_addr_type = BLE_ADDR_PUBLIC; - memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN); + p->conn_addr_type = BLE_ADDR_PUBLIC; + memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, + BD_ADDR_LEN); #endif - p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; - - btm_pm_sm_alloc(xx); - - - if (dc) - memcpy (p->remote_dc, dc, DEV_CLASS_LEN); - - if (bdn) - memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN); - - /* if BR/EDR do something more */ - if (transport == BT_TRANSPORT_BR_EDR) - { - btsnd_hcic_read_rmt_clk_offset (p->hci_handle); - btsnd_hcic_rmt_ver_req (p->hci_handle); - } - p_dev_rec = btm_find_dev_by_handle (hci_handle); - - if (p_dev_rec ) - { - BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type); - } - - if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) - { - /* If remote features already known, copy them and continue connection setup */ - if ((p_dev_rec->num_read_pages) && - (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1))) - { - memcpy (p->peer_lmp_features, p_dev_rec->features, - (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages)); - p->num_read_pages = p_dev_rec->num_read_pages; - - const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); - - /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ - btm_sec_set_peer_sec_caps(p, p_dev_rec); - - BTM_TRACE_API("%s: pend:%d", __func__, req_pend); - if (req_pend) - { - /* Request for remaining Security Features (if any) */ - l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); - } - btm_establish_continue (p); - return; - } - } - - /* If here, features are not known yet */ - if (p_dev_rec && transport == BT_TRANSPORT_LE) - { + p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; + + btm_pm_sm_alloc(xx); + + if (dc) memcpy(p->remote_dc, dc, DEV_CLASS_LEN); + + if (bdn) memcpy(p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN); + + /* if BR/EDR do something more */ + if (transport == BT_TRANSPORT_BR_EDR) { + btsnd_hcic_read_rmt_clk_offset(p->hci_handle); + btsnd_hcic_rmt_ver_req(p->hci_handle); + } + p_dev_rec = btm_find_dev_by_handle(hci_handle); + + if (p_dev_rec) { + BTM_TRACE_DEBUG("device_type=0x%x", p_dev_rec->device_type); + } + + if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) { + /* If remote features already known, copy them and continue connection + * setup */ + if ((p_dev_rec->num_read_pages) && + (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1))) { + memcpy(p->peer_lmp_features, p_dev_rec->features, + (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages)); + p->num_read_pages = p_dev_rec->num_read_pages; + + const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); + + /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ + btm_sec_set_peer_sec_caps(p, p_dev_rec); + + BTM_TRACE_API("%s: pend:%d", __func__, req_pend); + if (req_pend) { + /* Request for remaining Security Features (if any) */ + l2cu_resubmit_pending_sec_req(p_dev_rec->bd_addr); + } + btm_establish_continue(p); + return; + } + } + + /* If here, features are not known yet */ + if (p_dev_rec && transport == BT_TRANSPORT_LE) { #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr, - &p->active_remote_addr_type); + btm_ble_get_acl_remote_addr(p_dev_rec, p->active_remote_addr, + &p->active_remote_addr_type); #endif - if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) - || link_role == HCI_ROLE_MASTER) - { - btsnd_hcic_ble_read_remote_feat(p->hci_handle); - } - else - { - btm_establish_continue(p); - } - } - else - { - btm_read_remote_features (p->hci_handle); - } - - /* read page 1 - on rmt feature event for buffer reasons */ - return; + if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED( + controller_get_interface()->get_features_ble()->as_array) || + link_role == HCI_ROLE_MASTER) { + btsnd_hcic_ble_read_remote_feat(p->hci_handle); + } else { + btm_establish_continue(p); } + } else { + btm_read_remote_features(p->hci_handle); + } + + /* read page 1 - on rmt feature event for buffer reasons */ + return; } + } } void btm_acl_update_conn_addr(uint8_t conn_handle, BD_ADDR address) { - uint8_t idx = btm_handle_to_acl_index(conn_handle); - if (idx != MAX_L2CAP_LINKS) { - memcpy(btm_cb.acl_db[idx].conn_addr, address, BD_ADDR_LEN); - } + uint8_t idx = btm_handle_to_acl_index(conn_handle); + if (idx != MAX_L2CAP_LINKS) { + memcpy(btm_cb.acl_db[idx].conn_addr, address, BD_ADDR_LEN); + } } /******************************************************************************* @@ -336,19 +315,20 @@ void btm_acl_update_conn_addr(uint8_t conn_handle, BD_ADDR address) { * Returns void * ******************************************************************************/ -void btm_acl_report_role_change (uint8_t hci_status, BD_ADDR bda) -{ - tBTM_ROLE_SWITCH_CMPL ref_data; - BTM_TRACE_DEBUG ("btm_acl_report_role_change"); - if (btm_cb.devcb.p_switch_role_cb - && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN)))) - { - memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL)); - ref_data.hci_status = hci_status; - (*btm_cb.devcb.p_switch_role_cb)(&ref_data); - memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL)); - btm_cb.devcb.p_switch_role_cb = NULL; - } +void btm_acl_report_role_change(uint8_t hci_status, BD_ADDR bda) { + tBTM_ROLE_SWITCH_CMPL ref_data; + BTM_TRACE_DEBUG("btm_acl_report_role_change"); + if (btm_cb.devcb.p_switch_role_cb && + (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, + bda, BD_ADDR_LEN)))) { + memcpy(&ref_data, &btm_cb.devcb.switch_role_ref_data, + sizeof(tBTM_ROLE_SWITCH_CMPL)); + ref_data.hci_status = hci_status; + (*btm_cb.devcb.p_switch_role_cb)(&ref_data); + memset(&btm_cb.devcb.switch_role_ref_data, 0, + sizeof(tBTM_ROLE_SWITCH_CMPL)); + btm_cb.devcb.p_switch_role_cb = NULL; + } } /******************************************************************************* @@ -362,81 +342,68 @@ void btm_acl_report_role_change (uint8_t hci_status, BD_ADDR bda) * Returns void * ******************************************************************************/ -void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport) -{ - tACL_CONN *p; - tBTM_BL_EVENT_DATA evt_data; - tBTM_SEC_DEV_REC *p_dev_rec=NULL; - BTM_TRACE_DEBUG ("btm_acl_removed"); - p = btm_bda_to_acl(bda, transport); - if (p != (tACL_CONN *)NULL) - { - p->in_use = false; - - /* if the disconnected channel has a pending role switch, clear it now */ - btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda); - - /* Only notify if link up has had a chance to be issued */ - if (p->link_up_issued) - { - p->link_up_issued = false; - - /* If anyone cares, tell him database changed */ - if (btm_cb.p_bl_changed_cb) - { - evt_data.event = BTM_BL_DISCN_EVT; - evt_data.discn.p_bda = bda; - evt_data.discn.handle = p->hci_handle; - evt_data.discn.transport = p->transport; - (*btm_cb.p_bl_changed_cb)(&evt_data); - } - - btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT); - } - - BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d", - p->hci_handle, - p->transport, - btm_cb.ble_ctr_cb.inq_var.connectable_mode, - p->link_role); - - p_dev_rec = btm_find_dev(bda); - if ( p_dev_rec) - { - BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); - if (p->transport == BT_TRANSPORT_LE) - { - BTM_TRACE_DEBUG("LE link down"); - p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); - if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) - { - BTM_TRACE_DEBUG("Not Bonded"); - p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED); - } - else - { - BTM_TRACE_DEBUG("Bonded"); - } - } - else - { - BTM_TRACE_DEBUG("Bletooth link down"); - p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED - | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); - } - BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); - } - else - { - BTM_TRACE_ERROR("Device not found"); - +void btm_acl_removed(BD_ADDR bda, tBT_TRANSPORT transport) { + tACL_CONN* p; + tBTM_BL_EVENT_DATA evt_data; + tBTM_SEC_DEV_REC* p_dev_rec = NULL; + BTM_TRACE_DEBUG("btm_acl_removed"); + p = btm_bda_to_acl(bda, transport); + if (p != (tACL_CONN*)NULL) { + p->in_use = false; + + /* if the disconnected channel has a pending role switch, clear it now */ + btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda); + + /* Only notify if link up has had a chance to be issued */ + if (p->link_up_issued) { + p->link_up_issued = false; + + /* If anyone cares, tell him database changed */ + if (btm_cb.p_bl_changed_cb) { + evt_data.event = BTM_BL_DISCN_EVT; + evt_data.discn.p_bda = bda; + evt_data.discn.handle = p->hci_handle; + evt_data.discn.transport = p->transport; + (*btm_cb.p_bl_changed_cb)(&evt_data); + } + + btm_acl_update_busy_level(BTM_BLI_ACL_DOWN_EVT); + } + + BTM_TRACE_DEBUG( + "acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d", + p->hci_handle, p->transport, btm_cb.ble_ctr_cb.inq_var.connectable_mode, + p->link_role); + + p_dev_rec = btm_find_dev(bda); + if (p_dev_rec) { + BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", + p_dev_rec->sec_flags); + if (p->transport == BT_TRANSPORT_LE) { + BTM_TRACE_DEBUG("LE link down"); + p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); + if ((p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) { + BTM_TRACE_DEBUG("Not Bonded"); + p_dev_rec->sec_flags &= + ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED); + } else { + BTM_TRACE_DEBUG("Bonded"); } - - /* Clear the ACL connection data */ - memset(p, 0, sizeof(tACL_CONN)); + } else { + BTM_TRACE_DEBUG("Bletooth link down"); + p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | + BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); + } + BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", + p_dev_rec->sec_flags); + } else { + BTM_TRACE_ERROR("Device not found"); } -} + /* Clear the ACL connection data */ + memset(p, 0, sizeof(tACL_CONN)); + } +} /******************************************************************************* * @@ -448,19 +415,16 @@ void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport) * Returns void * ******************************************************************************/ -void btm_acl_device_down (void) -{ - tACL_CONN *p = &btm_cb.acl_db[0]; - uint16_t xx; - BTM_TRACE_DEBUG ("btm_acl_device_down"); - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) - { - if (p->in_use) - { - BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle ); - l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE); - } +void btm_acl_device_down(void) { + tACL_CONN* p = &btm_cb.acl_db[0]; + uint16_t xx; + BTM_TRACE_DEBUG("btm_acl_device_down"); + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { + if (p->in_use) { + BTM_TRACE_DEBUG("hci_handle=%d HCI_ERR_HW_FAILURE ", p->hci_handle); + l2c_link_hci_disc_comp(p->hci_handle, HCI_ERR_HW_FAILURE); } + } } /******************************************************************************* @@ -473,62 +437,59 @@ void btm_acl_device_down (void) * Returns void * ******************************************************************************/ -void btm_acl_update_busy_level (tBTM_BLI_EVENT event) -{ - bool old_inquiry_state = btm_cb.is_inquiry; - tBTM_BL_UPDATE_DATA evt; - evt.busy_level_flags = 0; - switch (event) - { - case BTM_BLI_ACL_UP_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT"); - break; - case BTM_BLI_ACL_DOWN_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT"); - break; - case BTM_BLI_PAGE_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT"); - btm_cb.is_paging = true; - evt.busy_level_flags= BTM_BL_PAGING_STARTED; - break; - case BTM_BLI_PAGE_DONE_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT"); - btm_cb.is_paging = false; - evt.busy_level_flags = BTM_BL_PAGING_COMPLETE; - break; - case BTM_BLI_INQ_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT"); - btm_cb.is_inquiry = true; - evt.busy_level_flags = BTM_BL_INQUIRY_STARTED; - break; - case BTM_BLI_INQ_CANCEL_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT"); - btm_cb.is_inquiry = false; - evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED; - break; - case BTM_BLI_INQ_DONE_EVT: - BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT"); - btm_cb.is_inquiry = false; - evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE; - break; - } - - uint8_t busy_level; - if (btm_cb.is_paging || btm_cb.is_inquiry) - busy_level = 10; - else - busy_level = BTM_GetNumAclLinks(); - - if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry)) - { - evt.event = BTM_BL_UPDATE_EVT; - evt.busy_level = busy_level; - btm_cb.busy_level = busy_level; - if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) - { - (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); - } - } +void btm_acl_update_busy_level(tBTM_BLI_EVENT event) { + bool old_inquiry_state = btm_cb.is_inquiry; + tBTM_BL_UPDATE_DATA evt; + evt.busy_level_flags = 0; + switch (event) { + case BTM_BLI_ACL_UP_EVT: + BTM_TRACE_DEBUG("BTM_BLI_ACL_UP_EVT"); + break; + case BTM_BLI_ACL_DOWN_EVT: + BTM_TRACE_DEBUG("BTM_BLI_ACL_DOWN_EVT"); + break; + case BTM_BLI_PAGE_EVT: + BTM_TRACE_DEBUG("BTM_BLI_PAGE_EVT"); + btm_cb.is_paging = true; + evt.busy_level_flags = BTM_BL_PAGING_STARTED; + break; + case BTM_BLI_PAGE_DONE_EVT: + BTM_TRACE_DEBUG("BTM_BLI_PAGE_DONE_EVT"); + btm_cb.is_paging = false; + evt.busy_level_flags = BTM_BL_PAGING_COMPLETE; + break; + case BTM_BLI_INQ_EVT: + BTM_TRACE_DEBUG("BTM_BLI_INQ_EVT"); + btm_cb.is_inquiry = true; + evt.busy_level_flags = BTM_BL_INQUIRY_STARTED; + break; + case BTM_BLI_INQ_CANCEL_EVT: + BTM_TRACE_DEBUG("BTM_BLI_INQ_CANCEL_EVT"); + btm_cb.is_inquiry = false; + evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED; + break; + case BTM_BLI_INQ_DONE_EVT: + BTM_TRACE_DEBUG("BTM_BLI_INQ_DONE_EVT"); + btm_cb.is_inquiry = false; + evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE; + break; + } + + uint8_t busy_level; + if (btm_cb.is_paging || btm_cb.is_inquiry) + busy_level = 10; + else + busy_level = BTM_GetNumAclLinks(); + + if ((busy_level != btm_cb.busy_level) || + (old_inquiry_state != btm_cb.is_inquiry)) { + evt.event = BTM_BL_UPDATE_EVT; + evt.busy_level = busy_level; + btm_cb.busy_level = busy_level; + if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) { + (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA*)&evt); + } + } } /******************************************************************************* @@ -542,23 +503,20 @@ void btm_acl_update_busy_level (tBTM_BLI_EVENT event) * BTM_UNKNOWN_ADDR if no active link with bd addr specified * ******************************************************************************/ -tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, uint8_t *p_role) -{ - tACL_CONN *p; - BTM_TRACE_DEBUG ("BTM_GetRole"); - p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR); - if (p == NULL) - { - *p_role = BTM_ROLE_UNDEFINED; - return(BTM_UNKNOWN_ADDR); - } +tBTM_STATUS BTM_GetRole(BD_ADDR remote_bd_addr, uint8_t* p_role) { + tACL_CONN* p; + BTM_TRACE_DEBUG("BTM_GetRole"); + p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR); + if (p == NULL) { + *p_role = BTM_ROLE_UNDEFINED; + return (BTM_UNKNOWN_ADDR); + } - /* Get the current role */ - *p_role = p->link_role; - return(BTM_SUCCESS); + /* Get the current role */ + *p_role = p->link_role; + return (BTM_SUCCESS); } - /******************************************************************************* * * Function BTM_SwitchRole @@ -578,113 +536,97 @@ tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, uint8_t *p_role) * BTM_BUSY if the previous command is not completed * ******************************************************************************/ -tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, uint8_t new_role, tBTM_CMPL_CB *p_cb) -{ - tACL_CONN *p; - tBTM_SEC_DEV_REC *p_dev_rec = NULL; +tBTM_STATUS BTM_SwitchRole(BD_ADDR remote_bd_addr, uint8_t new_role, + tBTM_CMPL_CB* p_cb) { + tACL_CONN* p; + tBTM_SEC_DEV_REC* p_dev_rec = NULL; #if (BTM_SCO_INCLUDED == TRUE) - bool is_sco_active; + bool is_sco_active; #endif - tBTM_STATUS status; - tBTM_PM_MODE pwr_mode; - tBTM_PM_PWR_MD settings; - BD_ADDR_PTR p_bda; - BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x", - remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2], - remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]); - - /* Make sure the local device supports switching */ - if (!controller_get_interface()->supports_master_slave_role_switch()) - return(BTM_MODE_UNSUPPORTED); - - if (btm_cb.devcb.p_switch_role_cb && p_cb) - { - p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; - BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x", - p_bda[0], p_bda[1], p_bda[2], - p_bda[3], p_bda[4], p_bda[5]); - return(BTM_BUSY); - } - - p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR); - if (p == NULL) - return(BTM_UNKNOWN_ADDR); - - /* Finished if already in desired role */ - if (p->link_role == new_role) - return(BTM_SUCCESS); + tBTM_STATUS status; + tBTM_PM_MODE pwr_mode; + tBTM_PM_PWR_MD settings; + BD_ADDR_PTR p_bda; + BTM_TRACE_API("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x", + remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2], + remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]); + + /* Make sure the local device supports switching */ + if (!controller_get_interface()->supports_master_slave_role_switch()) + return (BTM_MODE_UNSUPPORTED); + + if (btm_cb.devcb.p_switch_role_cb && p_cb) { + p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; + BTM_TRACE_DEBUG( + "Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x", + p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); + return (BTM_BUSY); + } + + p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR); + if (p == NULL) return (BTM_UNKNOWN_ADDR); + + /* Finished if already in desired role */ + if (p->link_role == new_role) return (BTM_SUCCESS); #if (BTM_SCO_INCLUDED == TRUE) - /* Check if there is any SCO Active on this BD Address */ - is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr); + /* Check if there is any SCO Active on this BD Address */ + is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr); - if (is_sco_active == true) - return(BTM_NO_RESOURCES); + if (is_sco_active == true) return (BTM_NO_RESOURCES); #endif - /* Ignore role switch request if the previous request was not completed */ - if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) - { - BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d", - p->switch_role_state); - return(BTM_BUSY); - } - - status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode); - if (status != BTM_SUCCESS) - return(status); - - /* Wake up the link if in sniff or park before attempting switch */ - if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) - { - memset( (void*)&settings, 0, sizeof(settings)); - settings.mode = BTM_PM_MD_ACTIVE; - status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings); - if (status != BTM_CMD_STARTED) - return(BTM_WRONG_MODE); - - p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; - } - /* some devices do not support switch while encryption is on */ - else - { - p_dev_rec = btm_find_dev (remote_bd_addr); - if ((p_dev_rec != NULL) - && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) - && !BTM_EPR_AVAILABLE(p)) - { - /* bypass turning off encryption if change link key is already doing it */ - if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) - { - btsnd_hcic_set_conn_encrypt (p->hci_handle, false); - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; - } - - p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; - } - else - { - btsnd_hcic_switch_role (remote_bd_addr, new_role); - p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; + /* Ignore role switch request if the previous request was not completed */ + if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) { + BTM_TRACE_DEBUG("BTM_SwitchRole busy: %d", p->switch_role_state); + return (BTM_BUSY); + } + + status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode); + if (status != BTM_SUCCESS) return (status); + + /* Wake up the link if in sniff or park before attempting switch */ + if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) { + memset((void*)&settings, 0, sizeof(settings)); + settings.mode = BTM_PM_MD_ACTIVE; + status = BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p->remote_addr, &settings); + if (status != BTM_CMD_STARTED) return (BTM_WRONG_MODE); + + p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; + } + /* some devices do not support switch while encryption is on */ + else { + p_dev_rec = btm_find_dev(remote_bd_addr); + if ((p_dev_rec != NULL) && + ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) && + !BTM_EPR_AVAILABLE(p)) { + /* bypass turning off encryption if change link key is already doing it */ + if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) { + btsnd_hcic_set_conn_encrypt(p->hci_handle, false); + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; + } + + p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; + } else { + btsnd_hcic_switch_role(remote_bd_addr, new_role); + p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; #if (BTM_DISC_DURING_RS == TRUE) - if (p_dev_rec) - p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; + if (p_dev_rec) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; #endif - } } + } - /* Initialize return structure in case request fails */ - if (p_cb) - { - memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr, - BD_ADDR_LEN); - btm_cb.devcb.switch_role_ref_data.role = new_role; - /* initialized to an error code */ - btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE; - btm_cb.devcb.p_switch_role_cb = p_cb; - } - return(BTM_CMD_STARTED); + /* Initialize return structure in case request fails */ + if (p_cb) { + memcpy(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr, + BD_ADDR_LEN); + btm_cb.devcb.switch_role_ref_data.role = new_role; + /* initialized to an error code */ + btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE; + btm_cb.devcb.p_switch_role_cb = p_cb; + } + return (BTM_CMD_STARTED); } /******************************************************************************* @@ -699,80 +641,77 @@ tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, uint8_t new_role, tBTM_CMPL_ * Returns void * ******************************************************************************/ -void btm_acl_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enable) -{ - tACL_CONN *p; - uint8_t xx; - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_BL_ROLE_CHG_DATA evt; - - BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d", - handle, status, encr_enable); - xx = btm_handle_to_acl_index(handle); - /* don't assume that we can never get a bad hci_handle */ - if (xx < MAX_L2CAP_LINKS) - p = &btm_cb.acl_db[xx]; - else - return; - - /* Process Role Switch if active */ - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) - { - /* if encryption turn off failed we still will try to switch role */ - if (encr_enable) - { - p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; - } - else - { - p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING; - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC; - } - - btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role); +void btm_acl_encrypt_change(uint16_t handle, uint8_t status, + uint8_t encr_enable) { + tACL_CONN* p; + uint8_t xx; + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_BL_ROLE_CHG_DATA evt; + + BTM_TRACE_DEBUG("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d", + handle, status, encr_enable); + xx = btm_handle_to_acl_index(handle); + /* don't assume that we can never get a bad hci_handle */ + if (xx < MAX_L2CAP_LINKS) + p = &btm_cb.acl_db[xx]; + else + return; + + /* Process Role Switch if active */ + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) { + /* if encryption turn off failed we still will try to switch role */ + if (encr_enable) { + p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; + } else { + p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING; + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC; + } + + btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role); #if (BTM_DISC_DURING_RS == TRUE) - p_dev_rec = btm_find_dev(p->remote_addr); - if (p_dev_rec != NULL) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; + p_dev_rec = btm_find_dev(p->remote_addr); + if (p_dev_rec != NULL) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; #endif + } + /* Finished enabling Encryption after role switch */ + else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) { + p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; + btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, + p->remote_addr); + + /* if role change event is registered, report it now */ + if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) { + evt.event = BTM_BL_ROLE_CHG_EVT; + evt.new_role = btm_cb.devcb.switch_role_ref_data.role; + evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; + evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status; + (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA*)&evt); + + BTM_TRACE_DEBUG( + "Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", + evt.new_role, evt.hci_status, p->switch_role_state); } - /* Finished enabling Encryption after role switch */ - else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) - { - p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; - btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr); - - /* if role change event is registered, report it now */ - if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) - { - evt.event = BTM_BL_ROLE_CHG_EVT; - evt.new_role = btm_cb.devcb.switch_role_ref_data.role; - evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; - evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status; - (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); - - BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", - evt.new_role, evt.hci_status, p->switch_role_state); - } #if (BTM_DISC_DURING_RS == TRUE) - /* If a disconnect is pending, issue it now that role switch has completed */ - p_dev_rec = btm_find_dev(p->remote_addr); - if (p_dev_rec != NULL) - { - if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) - { - BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!"); - btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); - } - BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d", - PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ - } -#endif + /* If a disconnect is pending, issue it now that role switch has completed + */ + p_dev_rec = btm_find_dev(p->remote_addr); + if (p_dev_rec != NULL) { + if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) { + BTM_TRACE_WARNING( + "btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!"); + btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); + } + BTM_TRACE_ERROR( + "btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d", + PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ } +#endif + } } /******************************************************************************* * @@ -783,46 +722,48 @@ void btm_acl_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enabl * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, uint16_t *settings) -{ - tACL_CONN *p; - uint8_t *localFeatures = BTM_ReadLocalFeatures(); - BTM_TRACE_DEBUG ("%s", __func__); -/* BTM_TRACE_API ("%s: requested settings: 0x%04x", __func__, *settings ); */ - - /* First, check if hold mode is supported */ - if (*settings != HCI_DISABLE_ALL_LM_MODES) - { - if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) ) - { - *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH); - BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings ); - } - if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) ) - { - *settings &= (~HCI_ENABLE_HOLD_MODE); - BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings ); - } - if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) ) - { - *settings &= (~HCI_ENABLE_SNIFF_MODE); - BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings ); - } - if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) ) - { - *settings &= (~HCI_ENABLE_PARK_MODE); - BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings ); - } - } - - p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); - if (p != NULL) { - btsnd_hcic_write_policy_set(p->hci_handle, *settings); - return BTM_CMD_STARTED; - } - - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); +tBTM_STATUS BTM_SetLinkPolicy(BD_ADDR remote_bda, uint16_t* settings) { + tACL_CONN* p; + uint8_t* localFeatures = BTM_ReadLocalFeatures(); + BTM_TRACE_DEBUG("%s", __func__); + /* BTM_TRACE_API ("%s: requested settings: 0x%04x", __func__, *settings ); */ + + /* First, check if hold mode is supported */ + if (*settings != HCI_DISABLE_ALL_LM_MODES) { + if ((*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && + (!HCI_SWITCH_SUPPORTED(localFeatures))) { + *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH); + BTM_TRACE_API("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", + *settings); + } + if ((*settings & HCI_ENABLE_HOLD_MODE) && + (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) { + *settings &= (~HCI_ENABLE_HOLD_MODE); + BTM_TRACE_API("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", + *settings); + } + if ((*settings & HCI_ENABLE_SNIFF_MODE) && + (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) { + *settings &= (~HCI_ENABLE_SNIFF_MODE); + BTM_TRACE_API("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", + *settings); + } + if ((*settings & HCI_ENABLE_PARK_MODE) && + (!HCI_PARK_MODE_SUPPORTED(localFeatures))) { + *settings &= (~HCI_ENABLE_PARK_MODE); + BTM_TRACE_API("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", + *settings); + } + } + + p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); + if (p != NULL) { + btsnd_hcic_write_policy_set(p->hci_handle, *settings); + return BTM_CMD_STARTED; + } + + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -835,75 +776,83 @@ tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, uint16_t *settings) * Returns void * ******************************************************************************/ -void BTM_SetDefaultLinkPolicy (uint16_t settings) -{ - uint8_t *localFeatures = BTM_ReadLocalFeatures(); - - BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings); - - if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures))) - { - settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; - BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings); - } - if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) - { - settings &= ~HCI_ENABLE_HOLD_MODE; - BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings); - } - if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) - { - settings &= ~HCI_ENABLE_SNIFF_MODE; - BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings); - } - if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures))) - { - settings &= ~HCI_ENABLE_PARK_MODE; - BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings); - } - BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings); - - btm_cb.btm_def_link_policy = settings; - - /* Set the default Link Policy of the controller */ - btsnd_hcic_write_def_policy_set(settings); +void BTM_SetDefaultLinkPolicy(uint16_t settings) { + uint8_t* localFeatures = BTM_ReadLocalFeatures(); + + BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings); + + if ((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && + (!HCI_SWITCH_SUPPORTED(localFeatures))) { + settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; + BTM_TRACE_DEBUG( + "BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", + settings); + } + if ((settings & HCI_ENABLE_HOLD_MODE) && + (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) { + settings &= ~HCI_ENABLE_HOLD_MODE; + BTM_TRACE_DEBUG( + "BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", + settings); + } + if ((settings & HCI_ENABLE_SNIFF_MODE) && + (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) { + settings &= ~HCI_ENABLE_SNIFF_MODE; + BTM_TRACE_DEBUG( + "BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", + settings); + } + if ((settings & HCI_ENABLE_PARK_MODE) && + (!HCI_PARK_MODE_SUPPORTED(localFeatures))) { + settings &= ~HCI_ENABLE_PARK_MODE; + BTM_TRACE_DEBUG( + "BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", + settings); + } + BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings); + + btm_cb.btm_def_link_policy = settings; + + /* Set the default Link Policy of the controller */ + btsnd_hcic_write_def_policy_set(settings); } - void btm_use_preferred_conn_params(BD_ADDR bda) { - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda); - - /* If there are any preferred connection parameters, set them now */ - if ( (p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN ) && - (p_dev_rec->conn_params.min_conn_int <= BTM_BLE_CONN_INT_MAX ) && - (p_dev_rec->conn_params.max_conn_int >= BTM_BLE_CONN_INT_MIN ) && - (p_dev_rec->conn_params.max_conn_int <= BTM_BLE_CONN_INT_MAX ) && - (p_dev_rec->conn_params.slave_latency <= BTM_BLE_CONN_LATENCY_MAX ) && - (p_dev_rec->conn_params.supervision_tout >= BTM_BLE_CONN_SUP_TOUT_MIN) && - (p_dev_rec->conn_params.supervision_tout <= BTM_BLE_CONN_SUP_TOUT_MAX) && - ((p_lcb->min_interval < p_dev_rec->conn_params.min_conn_int && - p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) || - (p_lcb->min_interval > p_dev_rec->conn_params.max_conn_int) || - (p_lcb->latency > p_dev_rec->conn_params.slave_latency) || - (p_lcb->timeout > p_dev_rec->conn_params.supervision_tout))) - { - BTM_TRACE_DEBUG ("%s: HANDLE=%d min_conn_int=%d max_conn_int=%d slave_latency=%d supervision_tout=%d", __func__, - p_lcb->handle, p_dev_rec->conn_params.min_conn_int, p_dev_rec->conn_params.max_conn_int, - p_dev_rec->conn_params.slave_latency, p_dev_rec->conn_params.supervision_tout); - - p_lcb->min_interval = p_dev_rec->conn_params.min_conn_int; - p_lcb->max_interval = p_dev_rec->conn_params.max_conn_int; - p_lcb->timeout = p_dev_rec->conn_params.supervision_tout; - p_lcb->latency = p_dev_rec->conn_params.slave_latency; - - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, - p_dev_rec->conn_params.min_conn_int, - p_dev_rec->conn_params.max_conn_int, - p_dev_rec->conn_params.slave_latency, - p_dev_rec->conn_params.supervision_tout, - 0, 0); - } + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda); + + /* If there are any preferred connection parameters, set them now */ + if ((p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN) && + (p_dev_rec->conn_params.min_conn_int <= BTM_BLE_CONN_INT_MAX) && + (p_dev_rec->conn_params.max_conn_int >= BTM_BLE_CONN_INT_MIN) && + (p_dev_rec->conn_params.max_conn_int <= BTM_BLE_CONN_INT_MAX) && + (p_dev_rec->conn_params.slave_latency <= BTM_BLE_CONN_LATENCY_MAX) && + (p_dev_rec->conn_params.supervision_tout >= BTM_BLE_CONN_SUP_TOUT_MIN) && + (p_dev_rec->conn_params.supervision_tout <= BTM_BLE_CONN_SUP_TOUT_MAX) && + ((p_lcb->min_interval < p_dev_rec->conn_params.min_conn_int && + p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) || + (p_lcb->min_interval > p_dev_rec->conn_params.max_conn_int) || + (p_lcb->latency > p_dev_rec->conn_params.slave_latency) || + (p_lcb->timeout > p_dev_rec->conn_params.supervision_tout))) { + BTM_TRACE_DEBUG( + "%s: HANDLE=%d min_conn_int=%d max_conn_int=%d slave_latency=%d " + "supervision_tout=%d", + __func__, p_lcb->handle, p_dev_rec->conn_params.min_conn_int, + p_dev_rec->conn_params.max_conn_int, + p_dev_rec->conn_params.slave_latency, + p_dev_rec->conn_params.supervision_tout); + + p_lcb->min_interval = p_dev_rec->conn_params.min_conn_int; + p_lcb->max_interval = p_dev_rec->conn_params.max_conn_int; + p_lcb->timeout = p_dev_rec->conn_params.supervision_tout; + p_lcb->latency = p_dev_rec->conn_params.slave_latency; + + btsnd_hcic_ble_upd_ll_conn_params( + p_lcb->handle, p_dev_rec->conn_params.min_conn_int, + p_dev_rec->conn_params.max_conn_int, + p_dev_rec->conn_params.slave_latency, + p_dev_rec->conn_params.supervision_tout, 0, 0); + } } /******************************************************************************* @@ -916,39 +865,34 @@ void btm_use_preferred_conn_params(BD_ADDR bda) { * Returns void * ******************************************************************************/ -void btm_read_remote_version_complete (uint8_t *p) -{ - tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; - uint8_t status; - uint16_t handle; - int xx; - BTM_TRACE_DEBUG ("btm_read_remote_version_complete"); - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - - /* Look up the connection by handle and copy features */ - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) - { - if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) - { - if (status == HCI_SUCCESS) - { - STREAM_TO_UINT8 (p_acl_cb->lmp_version, p); - STREAM_TO_UINT16 (p_acl_cb->manufacturer, p); - STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p); - } - - if (p_acl_cb->transport == BT_TRANSPORT_LE) { - l2cble_notify_le_connection (p_acl_cb->remote_addr); - btm_use_preferred_conn_params(p_acl_cb->remote_addr); - } - break; - } - } +void btm_read_remote_version_complete(uint8_t* p) { + tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; + uint8_t status; + uint16_t handle; + int xx; + BTM_TRACE_DEBUG("btm_read_remote_version_complete"); + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + + /* Look up the connection by handle and copy features */ + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) { + if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) { + if (status == HCI_SUCCESS) { + STREAM_TO_UINT8(p_acl_cb->lmp_version, p); + STREAM_TO_UINT16(p_acl_cb->manufacturer, p); + STREAM_TO_UINT16(p_acl_cb->lmp_subversion, p); + } + + if (p_acl_cb->transport == BT_TRANSPORT_LE) { + l2cble_notify_le_connection(p_acl_cb->remote_addr); + btm_use_preferred_conn_params(p_acl_cb->remote_addr); + } + break; + } + } } - /******************************************************************************* * * Function btm_process_remote_ext_features @@ -959,50 +903,45 @@ void btm_read_remote_version_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_read_pages) -{ - uint16_t handle = p_acl_cb->hci_handle; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - uint8_t page_idx; +void btm_process_remote_ext_features(tACL_CONN* p_acl_cb, + uint8_t num_read_pages) { + uint16_t handle = p_acl_cb->hci_handle; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + uint8_t page_idx; - BTM_TRACE_DEBUG ("btm_process_remote_ext_features"); + BTM_TRACE_DEBUG("btm_process_remote_ext_features"); - /* Make sure we have the record to save remote features information */ - if (p_dev_rec == NULL) - { - /* Get a new device; might be doing dedicated bonding */ - p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr); - } + /* Make sure we have the record to save remote features information */ + if (p_dev_rec == NULL) { + /* Get a new device; might be doing dedicated bonding */ + p_dev_rec = btm_find_or_alloc_dev(p_acl_cb->remote_addr); + } - p_acl_cb->num_read_pages = num_read_pages; - p_dev_rec->num_read_pages = num_read_pages; + p_acl_cb->num_read_pages = num_read_pages; + p_dev_rec->num_read_pages = num_read_pages; - /* Move the pages to placeholder */ - for (page_idx = 0; page_idx < num_read_pages; page_idx++) - { - if (page_idx > HCI_EXT_FEATURES_PAGE_MAX) - { - BTM_TRACE_ERROR("%s: page=%d unexpected", __func__, page_idx); - break; - } - memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx], - HCI_FEATURE_BYTES_PER_PAGE); + /* Move the pages to placeholder */ + for (page_idx = 0; page_idx < num_read_pages; page_idx++) { + if (page_idx > HCI_EXT_FEATURES_PAGE_MAX) { + BTM_TRACE_ERROR("%s: page=%d unexpected", __func__, page_idx); + break; } + memcpy(p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx], + HCI_FEATURE_BYTES_PER_PAGE); + } - const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); + const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); - /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ - btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec); + /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ + btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec); - BTM_TRACE_API("%s: pend:%d", __func__, req_pend); - if (req_pend) - { - /* Request for remaining Security Features (if any) */ - l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); - } + BTM_TRACE_API("%s: pend:%d", __func__, req_pend); + if (req_pend) { + /* Request for remaining Security Features (if any) */ + l2cu_resubmit_pending_sec_req(p_dev_rec->bd_addr); + } } - /******************************************************************************* * * Function btm_read_remote_features @@ -1013,30 +952,28 @@ void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_read_page * Returns void * ******************************************************************************/ -void btm_read_remote_features (uint16_t handle) -{ - uint8_t acl_idx; - tACL_CONN *p_acl_cb; +void btm_read_remote_features(uint16_t handle) { + uint8_t acl_idx; + tACL_CONN* p_acl_cb; - BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle); + BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle); - acl_idx = btm_handle_to_acl_index(handle); - if (acl_idx >= MAX_L2CAP_LINKS) - { - BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle); - return; - } + acl_idx = btm_handle_to_acl_index(handle); + if (acl_idx >= MAX_L2CAP_LINKS) { + BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle); + return; + } - p_acl_cb = &btm_cb.acl_db[acl_idx]; - p_acl_cb->num_read_pages = 0; - memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features)); + p_acl_cb = &btm_cb.acl_db[acl_idx]; + p_acl_cb->num_read_pages = 0; + memset(p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features)); - /* first send read remote supported features HCI command */ - /* because we don't know whether the remote support extended feature command */ - btsnd_hcic_rmt_features_req (handle); + /* first send read remote supported features HCI command */ + /* because we don't know whether the remote support extended feature command + */ + btsnd_hcic_rmt_features_req(handle); } - /******************************************************************************* * * Function btm_read_remote_ext_features @@ -1047,14 +984,13 @@ void btm_read_remote_features (uint16_t handle) * Returns void * ******************************************************************************/ -void btm_read_remote_ext_features (uint16_t handle, uint8_t page_number) -{ - BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number); +void btm_read_remote_ext_features(uint16_t handle, uint8_t page_number) { + BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, + page_number); - btsnd_hcic_rmt_ext_features(handle, page_number); + btsnd_hcic_rmt_ext_features(handle, page_number); } - /******************************************************************************* * * Function btm_read_remote_features_complete @@ -1065,54 +1001,57 @@ void btm_read_remote_ext_features (uint16_t handle, uint8_t page_number) * Returns void * ******************************************************************************/ -void btm_read_remote_features_complete (uint8_t *p) -{ - tACL_CONN *p_acl_cb; - uint8_t status; - uint16_t handle; - uint8_t acl_idx; - - BTM_TRACE_DEBUG ("btm_read_remote_features_complete"); - STREAM_TO_UINT8 (status, p); - - if (status != HCI_SUCCESS) - { - BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status); - return; - } - - STREAM_TO_UINT16 (handle, p); - - acl_idx = btm_handle_to_acl_index(handle); - if (acl_idx >= MAX_L2CAP_LINKS) - { - BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle); - return; - } - - p_acl_cb = &btm_cb.acl_db[acl_idx]; - - /* Copy the received features page */ - STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p, - HCI_FEATURE_BYTES_PER_PAGE); - - if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && - (controller_get_interface()->supports_reading_remote_extended_features())) - { - /* if the remote controller has extended features and local controller supports - ** HCI_Read_Remote_Extended_Features command then start reading these feature starting - ** with extended features page 1 */ - BTM_TRACE_DEBUG ("Start reading remote extended features"); - btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1); - return; - } - - /* Remote controller has no extended features. Process remote controller supported features - (features page HCI_EXT_FEATURES_PAGE_0). */ - btm_process_remote_ext_features (p_acl_cb, 1); - - /* Continue with HCI connection establishment */ - btm_establish_continue (p_acl_cb); +void btm_read_remote_features_complete(uint8_t* p) { + tACL_CONN* p_acl_cb; + uint8_t status; + uint16_t handle; + uint8_t acl_idx; + + BTM_TRACE_DEBUG("btm_read_remote_features_complete"); + STREAM_TO_UINT8(status, p); + + if (status != HCI_SUCCESS) { + BTM_TRACE_ERROR("btm_read_remote_features_complete failed (status 0x%02x)", + status); + return; + } + + STREAM_TO_UINT16(handle, p); + + acl_idx = btm_handle_to_acl_index(handle); + if (acl_idx >= MAX_L2CAP_LINKS) { + BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", + handle); + return; + } + + p_acl_cb = &btm_cb.acl_db[acl_idx]; + + /* Copy the received features page */ + STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p, + HCI_FEATURE_BYTES_PER_PAGE); + + if ((HCI_LMP_EXTENDED_SUPPORTED( + p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && + (controller_get_interface() + ->supports_reading_remote_extended_features())) { + /* if the remote controller has extended features and local controller + *supports + ** HCI_Read_Remote_Extended_Features command then start reading these + *feature starting + ** with extended features page 1 */ + BTM_TRACE_DEBUG("Start reading remote extended features"); + btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1); + return; + } + + /* Remote controller has no extended features. Process remote controller + supported features + (features page HCI_EXT_FEATURES_PAGE_0). */ + btm_process_remote_ext_features(p_acl_cb, 1); + + /* Continue with HCI connection establishment */ + btm_establish_continue(p_acl_cb); } /******************************************************************************* @@ -1125,57 +1064,58 @@ void btm_read_remote_features_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_read_remote_ext_features_complete (uint8_t *p) -{ - tACL_CONN *p_acl_cb; - uint8_t page_num, max_page; - uint16_t handle; - uint8_t acl_idx; - - BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete"); - - ++p; - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (page_num, p); - STREAM_TO_UINT8 (max_page, p); - - /* Validate parameters */ - acl_idx = btm_handle_to_acl_index(handle); - if (acl_idx >= MAX_L2CAP_LINKS) - { - BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle); - return; - } - - if (max_page > HCI_EXT_FEATURES_PAGE_MAX) - { - BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page); - return; - } - - p_acl_cb = &btm_cb.acl_db[acl_idx]; - - /* Copy the received features page */ - STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE); - - /* If there is the next remote features page and - * we have space to keep this page data - read this page */ - if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) - { - page_num++; - BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num); - btm_read_remote_ext_features (handle, page_num); - return; - } - - /* Reading of remote feature pages is complete */ - BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num); - - /* Process the pages */ - btm_process_remote_ext_features (p_acl_cb, (uint8_t) (page_num + 1)); - - /* Continue with HCI connection establishment */ - btm_establish_continue (p_acl_cb); +void btm_read_remote_ext_features_complete(uint8_t* p) { + tACL_CONN* p_acl_cb; + uint8_t page_num, max_page; + uint16_t handle; + uint8_t acl_idx; + + BTM_TRACE_DEBUG("btm_read_remote_ext_features_complete"); + + ++p; + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(page_num, p); + STREAM_TO_UINT8(max_page, p); + + /* Validate parameters */ + acl_idx = btm_handle_to_acl_index(handle); + if (acl_idx >= MAX_L2CAP_LINKS) { + BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", + handle); + return; + } + + if (max_page > HCI_EXT_FEATURES_PAGE_MAX) { + BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", + max_page); + return; + } + + p_acl_cb = &btm_cb.acl_db[acl_idx]; + + /* Copy the received features page */ + STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, + HCI_FEATURE_BYTES_PER_PAGE); + + /* If there is the next remote features page and + * we have space to keep this page data - read this page */ + if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) { + page_num++; + BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", + page_num); + btm_read_remote_ext_features(handle, page_num); + return; + } + + /* Reading of remote feature pages is complete */ + BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", + page_num); + + /* Process the pages */ + btm_process_remote_ext_features(p_acl_cb, (uint8_t)(page_num + 1)); + + /* Continue with HCI connection establishment */ + btm_establish_continue(p_acl_cb); } /******************************************************************************* @@ -1188,28 +1128,28 @@ void btm_read_remote_ext_features_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_read_remote_ext_features_failed (uint8_t status, uint16_t handle) -{ - tACL_CONN *p_acl_cb; - uint8_t acl_idx; +void btm_read_remote_ext_features_failed(uint8_t status, uint16_t handle) { + tACL_CONN* p_acl_cb; + uint8_t acl_idx; - BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d", - status, handle); + BTM_TRACE_WARNING( + "btm_read_remote_ext_features_failed (status 0x%02x) for handle %d", + status, handle); - acl_idx = btm_handle_to_acl_index(handle); - if (acl_idx >= MAX_L2CAP_LINKS) - { - BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle); - return; - } + acl_idx = btm_handle_to_acl_index(handle); + if (acl_idx >= MAX_L2CAP_LINKS) { + BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", + handle); + return; + } - p_acl_cb = &btm_cb.acl_db[acl_idx]; + p_acl_cb = &btm_cb.acl_db[acl_idx]; - /* Process supported features only */ - btm_process_remote_ext_features (p_acl_cb, 1); + /* Process supported features only */ + btm_process_remote_ext_features(p_acl_cb, 1); - /* Continue HCI connection establishment */ - btm_establish_continue (p_acl_cb); + /* Continue HCI connection establishment */ + btm_establish_continue(p_acl_cb); } /******************************************************************************* @@ -1223,40 +1163,37 @@ void btm_read_remote_ext_features_failed (uint8_t status, uint16_t handle) * Returns void * ******************************************************************************/ -void btm_establish_continue (tACL_CONN *p_acl_cb) -{ - tBTM_BL_EVENT_DATA evt_data; - BTM_TRACE_DEBUG ("btm_establish_continue"); +void btm_establish_continue(tACL_CONN* p_acl_cb) { + tBTM_BL_EVENT_DATA evt_data; + BTM_TRACE_DEBUG("btm_establish_continue"); #if (BTM_BYPASS_EXTRA_ACL_SETUP == FALSE) - if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR) - { - /* For now there are a some devices that do not like sending */ - /* commands events and data at the same time. */ - /* Set the packet types to the default allowed by the device */ - btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported); - - if (btm_cb.btm_def_link_policy) - BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); - } + if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR) { + /* For now there are a some devices that do not like sending */ + /* commands events and data at the same time. */ + /* Set the packet types to the default allowed by the device */ + btm_set_packet_types(p_acl_cb, btm_cb.btm_acl_pkt_types_supported); + + if (btm_cb.btm_def_link_policy) + BTM_SetLinkPolicy(p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); + } #endif - p_acl_cb->link_up_issued = true; - - /* If anyone cares, tell him database changed */ - if (btm_cb.p_bl_changed_cb) - { - evt_data.event = BTM_BL_CONN_EVT; - evt_data.conn.p_bda = p_acl_cb->remote_addr; - evt_data.conn.p_bdn = p_acl_cb->remote_name; - evt_data.conn.p_dc = p_acl_cb->remote_dc; - evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]; - evt_data.conn.handle = p_acl_cb->hci_handle; - evt_data.conn.transport = p_acl_cb->transport; - - (*btm_cb.p_bl_changed_cb)(&evt_data); - } - btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT); -} + p_acl_cb->link_up_issued = true; + /* If anyone cares, tell him database changed */ + if (btm_cb.p_bl_changed_cb) { + evt_data.event = BTM_BL_CONN_EVT; + evt_data.conn.p_bda = p_acl_cb->remote_addr; + evt_data.conn.p_bdn = p_acl_cb->remote_name; + evt_data.conn.p_dc = p_acl_cb->remote_dc; + evt_data.conn.p_features = + p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]; + evt_data.conn.handle = p_acl_cb->hci_handle; + evt_data.conn.transport = p_acl_cb->transport; + + (*btm_cb.p_bl_changed_cb)(&evt_data); + } + btm_acl_update_busy_level(BTM_BLI_ACL_UP_EVT); +} /******************************************************************************* * @@ -1269,10 +1206,9 @@ void btm_establish_continue (tACL_CONN *p_acl_cb) * Returns void * ******************************************************************************/ -void BTM_SetDefaultLinkSuperTout (uint16_t timeout) -{ - BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout"); - btm_cb.btm_def_link_super_tout = timeout; +void BTM_SetDefaultLinkSuperTout(uint16_t timeout) { + BTM_TRACE_DEBUG("BTM_SetDefaultLinkSuperTout"); + btm_cb.btm_def_link_super_tout = timeout; } /******************************************************************************* @@ -1284,21 +1220,18 @@ void BTM_SetDefaultLinkSuperTout (uint16_t timeout) * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, uint16_t *p_timeout) -{ - tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); +tBTM_STATUS BTM_GetLinkSuperTout(BD_ADDR remote_bda, uint16_t* p_timeout) { + tACL_CONN* p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout"); - if (p != (tACL_CONN *)NULL) - { - *p_timeout = p->link_super_tout; - return(BTM_SUCCESS); - } - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); + BTM_TRACE_DEBUG("BTM_GetLinkSuperTout"); + if (p != (tACL_CONN*)NULL) { + *p_timeout = p->link_super_tout; + return (BTM_SUCCESS); + } + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } - /******************************************************************************* * * Function BTM_SetLinkSuperTout @@ -1308,28 +1241,24 @@ tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, uint16_t *p_timeout) * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, uint16_t timeout) -{ - tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); +tBTM_STATUS BTM_SetLinkSuperTout(BD_ADDR remote_bda, uint16_t timeout) { + tACL_CONN* p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout"); - if (p != (tACL_CONN *)NULL) - { - p->link_super_tout = timeout; - - /* Only send if current role is Master; 2.0 spec requires this */ - if (p->link_role == BTM_ROLE_MASTER) - { - btsnd_hcic_write_link_super_tout(LOCAL_BR_EDR_CONTROLLER_ID, - p->hci_handle, timeout); - return(BTM_CMD_STARTED); - } - else - return(BTM_SUCCESS); - } + BTM_TRACE_DEBUG("BTM_SetLinkSuperTout"); + if (p != (tACL_CONN*)NULL) { + p->link_super_tout = timeout; - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); + /* Only send if current role is Master; 2.0 spec requires this */ + if (p->link_role == BTM_ROLE_MASTER) { + btsnd_hcic_write_link_super_tout(LOCAL_BR_EDR_CONTROLLER_ID, + p->hci_handle, timeout); + return (BTM_CMD_STARTED); + } else + return (BTM_SUCCESS); + } + + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -1342,22 +1271,20 @@ tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, uint16_t timeout) * Returns true if connection is up, else false. * ******************************************************************************/ -bool BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport) -{ - tACL_CONN *p; +bool BTM_IsAclConnectionUp(BD_ADDR remote_bda, tBT_TRANSPORT transport) { + tACL_CONN* p; - BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x", - remote_bda[0], remote_bda[1], remote_bda[2], - remote_bda[3], remote_bda[4], remote_bda[5]); + BTM_TRACE_API("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x", + remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], + remote_bda[4], remote_bda[5]); - p = btm_bda_to_acl(remote_bda, transport); - if (p != (tACL_CONN *)NULL) - { - return(true); - } + p = btm_bda_to_acl(remote_bda, transport); + if (p != (tACL_CONN*)NULL) { + return (true); + } - /* If here, no BD Addr found */ - return(false); + /* If here, no BD Addr found */ + return (false); } /******************************************************************************* @@ -1370,17 +1297,14 @@ bool BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport) * Returns uint16_t Number of active ACL links * ******************************************************************************/ -uint16_t BTM_GetNumAclLinks (void) -{ - uint16_t num_acl = 0; +uint16_t BTM_GetNumAclLinks(void) { + uint16_t num_acl = 0; - for (uint16_t i = 0; i < MAX_L2CAP_LINKS; ++i) - { - if (btm_cb.acl_db[i].in_use) - ++num_acl; - } + for (uint16_t i = 0; i < MAX_L2CAP_LINKS; ++i) { + if (btm_cb.acl_db[i].in_use) ++num_acl; + } - return num_acl; + return num_acl; } /******************************************************************************* @@ -1393,14 +1317,12 @@ uint16_t BTM_GetNumAclLinks (void) * Returns true if connection is up, else false. * ******************************************************************************/ -uint16_t btm_get_acl_disc_reason_code (void) -{ - uint8_t res = btm_cb.acl_disc_reason; - BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code"); - return(res); +uint16_t btm_get_acl_disc_reason_code(void) { + uint8_t res = btm_cb.acl_disc_reason; + BTM_TRACE_DEBUG("btm_get_acl_disc_reason_code"); + return (res); } - /******************************************************************************* * * Function BTM_GetHCIConnHandle @@ -1411,18 +1333,17 @@ uint16_t btm_get_acl_disc_reason_code (void) * Returns the handle of the connection, or 0xFFFF if none. * ******************************************************************************/ -uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT transport) -{ - tACL_CONN *p; - BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle"); - p = btm_bda_to_acl(remote_bda, transport); - if (p != (tACL_CONN *)NULL) - { - return(p->hci_handle); - } +uint16_t BTM_GetHCIConnHandle(const BD_ADDR remote_bda, + tBT_TRANSPORT transport) { + tACL_CONN* p; + BTM_TRACE_DEBUG("BTM_GetHCIConnHandle"); + p = btm_bda_to_acl(remote_bda, transport); + if (p != (tACL_CONN*)NULL) { + return (p->hci_handle); + } - /* If here, no BD Addr found */ - return(0xFFFF); + /* If here, no BD Addr found */ + return (0xFFFF); } /******************************************************************************* @@ -1437,14 +1358,12 @@ uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT transport * Returns void * ******************************************************************************/ -void btm_process_clk_off_comp_evt (uint16_t hci_handle, uint16_t clock_offset) -{ - uint8_t xx; - BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt"); - /* Look up the connection by handle and set the current mode */ - xx = btm_handle_to_acl_index(hci_handle); - if (xx < MAX_L2CAP_LINKS) - btm_cb.acl_db[xx].clock_offset = clock_offset; +void btm_process_clk_off_comp_evt(uint16_t hci_handle, uint16_t clock_offset) { + uint8_t xx; + BTM_TRACE_DEBUG("btm_process_clk_off_comp_evt"); + /* Look up the connection by handle and set the current mode */ + xx = btm_handle_to_acl_index(hci_handle); + if (xx < MAX_L2CAP_LINKS) btm_cb.acl_db[xx].clock_offset = clock_offset; } /******************************************************************************* @@ -1459,101 +1378,93 @@ void btm_process_clk_off_comp_evt (uint16_t hci_handle, uint16_t clock_offset) * Returns void * ******************************************************************************/ -void btm_acl_role_changed (uint8_t hci_status, BD_ADDR bd_addr, uint8_t new_role) -{ - uint8_t *p_bda = (bd_addr) ? bd_addr : - btm_cb.devcb.switch_role_ref_data.remote_bd_addr; - tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR); - tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data; - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_BL_ROLE_CHG_DATA evt; - - BTM_TRACE_DEBUG ("btm_acl_role_changed"); - /* Ignore any stray events */ - if (p == NULL) - { - /* it could be a failure */ - if (hci_status != HCI_SUCCESS) - btm_acl_report_role_change(hci_status, bd_addr); - return; - } - - p_data->hci_status = hci_status; - - if (hci_status == HCI_SUCCESS) - { - p_data->role = new_role; - memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN); - - /* Update cached value */ - p->link_role = new_role; - - /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */ - if (new_role == BTM_ROLE_MASTER) - { - BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout); - } - } - else - { - /* so the BTM_BL_ROLE_CHG_EVT uses the old role */ - new_role = p->link_role; - } - - /* Check if any SCO req is pending for role change */ - btm_sco_chk_pend_rolechange (p->hci_handle); - - /* if switching state is switching we need to turn encryption on */ - /* if idle, we did not change encryption */ - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) - { - btsnd_hcic_set_conn_encrypt (p->hci_handle, true); - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON; - p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; - return; - } - - /* Set the switch_role_state to IDLE since the reply received from HCI */ - /* regardless of its result either success or failed. */ - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) - { - p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; - } - - /* if role switch complete is needed, report it now */ - btm_acl_report_role_change(hci_status, bd_addr); - - /* if role change event is registered, report it now */ - if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) - { - evt.event = BTM_BL_ROLE_CHG_EVT; - evt.new_role = new_role; - evt.p_bda = p_bda; - evt.hci_status = hci_status; - (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); - } - - BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", - p_data->role, p_data->hci_status, p->switch_role_state); +void btm_acl_role_changed(uint8_t hci_status, BD_ADDR bd_addr, + uint8_t new_role) { + uint8_t* p_bda = + (bd_addr) ? bd_addr : btm_cb.devcb.switch_role_ref_data.remote_bd_addr; + tACL_CONN* p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR); + tBTM_ROLE_SWITCH_CMPL* p_data = &btm_cb.devcb.switch_role_ref_data; + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_BL_ROLE_CHG_DATA evt; + + BTM_TRACE_DEBUG("btm_acl_role_changed"); + /* Ignore any stray events */ + if (p == NULL) { + /* it could be a failure */ + if (hci_status != HCI_SUCCESS) + btm_acl_report_role_change(hci_status, bd_addr); + return; + } + + p_data->hci_status = hci_status; + + if (hci_status == HCI_SUCCESS) { + p_data->role = new_role; + memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN); + + /* Update cached value */ + p->link_role = new_role; + + /* Reload LSTO: link supervision timeout is reset in the LM after a role + * switch */ + if (new_role == BTM_ROLE_MASTER) { + BTM_SetLinkSuperTout(p->remote_addr, p->link_super_tout); + } + } else { + /* so the BTM_BL_ROLE_CHG_EVT uses the old role */ + new_role = p->link_role; + } + + /* Check if any SCO req is pending for role change */ + btm_sco_chk_pend_rolechange(p->hci_handle); + + /* if switching state is switching we need to turn encryption on */ + /* if idle, we did not change encryption */ + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) { + btsnd_hcic_set_conn_encrypt(p->hci_handle, true); + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON; + p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; + return; + } + + /* Set the switch_role_state to IDLE since the reply received from HCI */ + /* regardless of its result either success or failed. */ + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) { + p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; + } + + /* if role switch complete is needed, report it now */ + btm_acl_report_role_change(hci_status, bd_addr); + + /* if role change event is registered, report it now */ + if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) { + evt.event = BTM_BL_ROLE_CHG_EVT; + evt.new_role = new_role; + evt.p_bda = p_bda; + evt.hci_status = hci_status; + (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA*)&evt); + } + + BTM_TRACE_DEBUG( + "Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", + p_data->role, p_data->hci_status, p->switch_role_state); #if (BTM_DISC_DURING_RS == TRUE) - /* If a disconnect is pending, issue it now that role switch has completed */ - p_dev_rec = btm_find_dev(p_bda); - if (p_dev_rec != NULL) - { - if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) - { - BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!"); - btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); - } - BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d", - PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ - } + /* If a disconnect is pending, issue it now that role switch has completed */ + p_dev_rec = btm_find_dev(p_bda); + if (p_dev_rec != NULL) { + if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) { + BTM_TRACE_WARNING( + "btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!"); + btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); + } + BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d", + PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ + } #endif - } /******************************************************************************* @@ -1566,22 +1477,19 @@ void btm_acl_role_changed (uint8_t hci_status, BD_ADDR bd_addr, uint8_t new_role * ******************************************************************************/ -uint8_t BTM_AllocateSCN(void) -{ - uint8_t x; - BTM_TRACE_DEBUG ("BTM_AllocateSCN"); +uint8_t BTM_AllocateSCN(void) { + uint8_t x; + BTM_TRACE_DEBUG("BTM_AllocateSCN"); - // stack reserves scn 1 for HFP, HSP we still do the correct way - for (x = 1; x < BTM_MAX_SCN; x++) - { - if (!btm_cb.btm_scn[x]) - { - btm_cb.btm_scn[x] = true; - return(x+1); - } + // stack reserves scn 1 for HFP, HSP we still do the correct way + for (x = 1; x < BTM_MAX_SCN; x++) { + if (!btm_cb.btm_scn[x]) { + btm_cb.btm_scn[x] = true; + return (x + 1); } + } - return(0); /* No free ports */ + return (0); /* No free ports */ } /******************************************************************************* @@ -1594,22 +1502,19 @@ uint8_t BTM_AllocateSCN(void) * ******************************************************************************/ -bool BTM_TryAllocateSCN(uint8_t scn) -{ - /* Make sure we don't exceed max port range. - * Stack reserves scn 1 for HFP, HSP we still do the correct way. - */ - if ( (scn>=BTM_MAX_SCN) || (scn == 1) ) - return false; +bool BTM_TryAllocateSCN(uint8_t scn) { + /* Make sure we don't exceed max port range. + * Stack reserves scn 1 for HFP, HSP we still do the correct way. + */ + if ((scn >= BTM_MAX_SCN) || (scn == 1)) return false; - /* check if this port is available */ - if (!btm_cb.btm_scn[scn-1]) - { - btm_cb.btm_scn[scn-1] = true; - return true; - } + /* check if this port is available */ + if (!btm_cb.btm_scn[scn - 1]) { + btm_cb.btm_scn[scn - 1] = true; + return true; + } - return (false); /* Port was busy */ + return (false); /* Port was busy */ } /******************************************************************************* @@ -1621,16 +1526,13 @@ bool BTM_TryAllocateSCN(uint8_t scn) * Returns true or false * ******************************************************************************/ -bool BTM_FreeSCN(uint8_t scn) -{ - BTM_TRACE_DEBUG ("BTM_FreeSCN "); - if (scn <= BTM_MAX_SCN) - { - btm_cb.btm_scn[scn-1] = false; - return(true); - } - else - return(false); /* Illegal SCN passed in */ +bool BTM_FreeSCN(uint8_t scn) { + BTM_TRACE_DEBUG("BTM_FreeSCN "); + if (scn <= BTM_MAX_SCN) { + btm_cb.btm_scn[scn - 1] = false; + return (true); + } else + return (false); /* Illegal SCN passed in */ } /******************************************************************************* @@ -1644,27 +1546,27 @@ bool BTM_FreeSCN(uint8_t scn) * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS btm_set_packet_types (tACL_CONN *p, uint16_t pkt_types) -{ - uint16_t temp_pkt_types; - BTM_TRACE_DEBUG ("btm_set_packet_types"); - /* Save in the ACL control blocks, types that we support */ - temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK & - btm_cb.btm_acl_pkt_types_supported); +tBTM_STATUS btm_set_packet_types(tACL_CONN* p, uint16_t pkt_types) { + uint16_t temp_pkt_types; + BTM_TRACE_DEBUG("btm_set_packet_types"); + /* Save in the ACL control blocks, types that we support */ + temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK & + btm_cb.btm_acl_pkt_types_supported); - /* OR in any exception packet types if at least 2.0 version of spec */ - temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) | - (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK)); + /* OR in any exception packet types if at least 2.0 version of spec */ + temp_pkt_types |= + ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) | + (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK)); - /* Exclude packet types not supported by the peer */ - btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types); + /* Exclude packet types not supported by the peer */ + btm_acl_chk_peer_pkt_type_support(p, &temp_pkt_types); - BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types); + BTM_TRACE_DEBUG("SetPacketType Mask -> 0x%04x", temp_pkt_types); - btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types); - p->pkt_types_mask = temp_pkt_types; + btsnd_hcic_change_conn_type(p->hci_handle, temp_pkt_types); + p->pkt_types_mask = temp_pkt_types; - return(BTM_CMD_STARTED); + return (BTM_CMD_STARTED); } /******************************************************************************* @@ -1675,54 +1577,49 @@ tBTM_STATUS btm_set_packet_types (tACL_CONN *p, uint16_t pkt_types) * connection, 0 if connection is not established * ******************************************************************************/ -uint16_t btm_get_max_packet_size (BD_ADDR addr) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - uint16_t pkt_types = 0; - uint16_t pkt_size = 0; - BTM_TRACE_DEBUG ("btm_get_max_packet_size"); - if (p != NULL) - { - pkt_types = p->pkt_types_mask; - } - else - { - /* Special case for when info for the local device is requested */ - if (memcmp (controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == 0) - { - pkt_types = btm_cb.btm_acl_pkt_types_supported; - } - } - - if (pkt_types) - { - if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) - pkt_size = HCI_EDR3_DH5_PACKET_SIZE; - else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) - pkt_size = HCI_EDR2_DH5_PACKET_SIZE; - else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) - pkt_size = HCI_EDR3_DH3_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) - pkt_size = HCI_DH5_PACKET_SIZE; - else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) - pkt_size = HCI_EDR2_DH3_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) - pkt_size = HCI_DM5_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) - pkt_size = HCI_DH3_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) - pkt_size = HCI_DM3_PACKET_SIZE; - else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) - pkt_size = HCI_EDR3_DH1_PACKET_SIZE; - else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) - pkt_size = HCI_EDR2_DH1_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) - pkt_size = HCI_DH1_PACKET_SIZE; - else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) - pkt_size = HCI_DM1_PACKET_SIZE; - } - - return(pkt_size); +uint16_t btm_get_max_packet_size(BD_ADDR addr) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + uint16_t pkt_types = 0; + uint16_t pkt_size = 0; + BTM_TRACE_DEBUG("btm_get_max_packet_size"); + if (p != NULL) { + pkt_types = p->pkt_types_mask; + } else { + /* Special case for when info for the local device is requested */ + if (memcmp(controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == + 0) { + pkt_types = btm_cb.btm_acl_pkt_types_supported; + } + } + + if (pkt_types) { + if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) + pkt_size = HCI_EDR3_DH5_PACKET_SIZE; + else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) + pkt_size = HCI_EDR2_DH5_PACKET_SIZE; + else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) + pkt_size = HCI_EDR3_DH3_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) + pkt_size = HCI_DH5_PACKET_SIZE; + else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) + pkt_size = HCI_EDR2_DH3_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) + pkt_size = HCI_DM5_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) + pkt_size = HCI_DH3_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) + pkt_size = HCI_DM3_PACKET_SIZE; + else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) + pkt_size = HCI_EDR3_DH1_PACKET_SIZE; + else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) + pkt_size = HCI_EDR2_DH1_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) + pkt_size = HCI_DH1_PACKET_SIZE; + else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) + pkt_size = HCI_DM1_PACKET_SIZE; + } + + return (pkt_size); } /******************************************************************************* @@ -1732,24 +1629,20 @@ uint16_t btm_get_max_packet_size (BD_ADDR addr) * Returns If connected report peer device info * ******************************************************************************/ -tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, uint8_t *lmp_version, - uint16_t *manufacturer, uint16_t *lmp_sub_version) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion"); - if (p == NULL) - return(BTM_UNKNOWN_ADDR); +tBTM_STATUS BTM_ReadRemoteVersion(BD_ADDR addr, uint8_t* lmp_version, + uint16_t* manufacturer, + uint16_t* lmp_sub_version) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + BTM_TRACE_DEBUG("BTM_ReadRemoteVersion"); + if (p == NULL) return (BTM_UNKNOWN_ADDR); - if (lmp_version) - *lmp_version = p->lmp_version; + if (lmp_version) *lmp_version = p->lmp_version; - if (manufacturer) - *manufacturer = p->manufacturer; + if (manufacturer) *manufacturer = p->manufacturer; - if (lmp_sub_version) - *lmp_sub_version = p->lmp_subversion; + if (lmp_sub_version) *lmp_sub_version = p->lmp_subversion; - return(BTM_SUCCESS); + return (BTM_SUCCESS); } /******************************************************************************* @@ -1759,16 +1652,14 @@ tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, uint8_t *lmp_version, * Returns pointer to the remote supported features mask (8 bytes) * ******************************************************************************/ -uint8_t *BTM_ReadRemoteFeatures (BD_ADDR addr) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures"); - if (p == NULL) - { - return(NULL); - } +uint8_t* BTM_ReadRemoteFeatures(BD_ADDR addr) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + BTM_TRACE_DEBUG("BTM_ReadRemoteFeatures"); + if (p == NULL) { + return (NULL); + } - return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); + return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); } /******************************************************************************* @@ -1779,22 +1670,20 @@ uint8_t *BTM_ReadRemoteFeatures (BD_ADDR addr) * or NULL if bad page * ******************************************************************************/ -uint8_t *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, uint8_t page_number) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures"); - if (p == NULL) - { - return(NULL); - } +uint8_t* BTM_ReadRemoteExtendedFeatures(BD_ADDR addr, uint8_t page_number) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + BTM_TRACE_DEBUG("BTM_ReadRemoteExtendedFeatures"); + if (p == NULL) { + return (NULL); + } - if (page_number > HCI_EXT_FEATURES_PAGE_MAX) - { - BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number); - return NULL; - } + if (page_number > HCI_EXT_FEATURES_PAGE_MAX) { + BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", + page_number); + return NULL; + } - return(p->peer_lmp_features[page_number]); + return (p->peer_lmp_features[page_number]); } /******************************************************************************* @@ -1804,16 +1693,14 @@ uint8_t *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, uint8_t page_number) * Returns number of features pages read from the remote device. * ******************************************************************************/ -uint8_t BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages"); - if (p == NULL) - { - return(0); - } +uint8_t BTM_ReadNumberRemoteFeaturesPages(BD_ADDR addr) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + BTM_TRACE_DEBUG("BTM_ReadNumberRemoteFeaturesPages"); + if (p == NULL) { + return (0); + } - return(p->num_read_pages); + return (p->num_read_pages); } /******************************************************************************* @@ -1823,16 +1710,14 @@ uint8_t BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr) * Returns pointer to all features of the remote (24 bytes). * ******************************************************************************/ -uint8_t *BTM_ReadAllRemoteFeatures (BD_ADDR addr) -{ - tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); - BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures"); - if (p == NULL) - { - return(NULL); - } +uint8_t* BTM_ReadAllRemoteFeatures(BD_ADDR addr) { + tACL_CONN* p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); + BTM_TRACE_DEBUG("BTM_ReadAllRemoteFeatures"); + if (p == NULL) { + return (NULL); + } - return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); + return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); } /******************************************************************************* @@ -1845,23 +1730,21 @@ uint8_t *BTM_ReadAllRemoteFeatures (BD_ADDR addr) * Returns BTM_SUCCESS if successfully registered, otherwise error * ******************************************************************************/ -tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, uint8_t *p_level, - tBTM_BL_EVENT_MASK evt_mask) -{ - BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif"); - if (p_level) - *p_level = btm_cb.busy_level; +tBTM_STATUS BTM_RegBusyLevelNotif(tBTM_BL_CHANGE_CB* p_cb, uint8_t* p_level, + tBTM_BL_EVENT_MASK evt_mask) { + BTM_TRACE_DEBUG("BTM_RegBusyLevelNotif"); + if (p_level) *p_level = btm_cb.busy_level; - btm_cb.bl_evt_mask = evt_mask; + btm_cb.bl_evt_mask = evt_mask; - if (!p_cb) - btm_cb.p_bl_changed_cb = NULL; - else if (btm_cb.p_bl_changed_cb) - return(BTM_BUSY); - else - btm_cb.p_bl_changed_cb = p_cb; + if (!p_cb) + btm_cb.p_bl_changed_cb = NULL; + else if (btm_cb.p_bl_changed_cb) + return (BTM_BUSY); + else + btm_cb.p_bl_changed_cb = p_cb; - return(BTM_SUCCESS); + return (BTM_SUCCESS); } /******************************************************************************* @@ -1873,35 +1756,29 @@ tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, uint8_t *p_level, * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb) -{ - tACL_CONN *p = &btm_cb.acl_db[0]; +tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC* p_flow, tBTM_CMPL_CB* p_cb) { + tACL_CONN* p = &btm_cb.acl_db[0]; - BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x", - bd[0], bd[1], bd[2], - bd[3], bd[4], bd[5]); + BTM_TRACE_API("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x", bd[0], bd[1], + bd[2], bd[3], bd[4], bd[5]); - /* If someone already waiting on the version, do not allow another */ - if (btm_cb.devcb.p_qos_setup_cmpl_cb) - return(BTM_BUSY); + /* If someone already waiting on the version, do not allow another */ + if (btm_cb.devcb.p_qos_setup_cmpl_cb) return (BTM_BUSY); - p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR); - if (p != NULL) - { - btm_cb.devcb.p_qos_setup_cmpl_cb = p_cb; - alarm_set_on_queue(btm_cb.devcb.qos_setup_timer, - BTM_DEV_REPLY_TIMEOUT_MS, - btm_qos_setup_timeout, NULL, - btu_general_alarm_queue); - - btsnd_hcic_qos_setup(p->hci_handle, p_flow->qos_flags, p_flow->service_type, - p_flow->token_rate, p_flow->peak_bandwidth, - p_flow->latency,p_flow->delay_variation); - return(BTM_CMD_STARTED); - } + p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR); + if (p != NULL) { + btm_cb.devcb.p_qos_setup_cmpl_cb = p_cb; + alarm_set_on_queue(btm_cb.devcb.qos_setup_timer, BTM_DEV_REPLY_TIMEOUT_MS, + btm_qos_setup_timeout, NULL, btu_general_alarm_queue); - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); + btsnd_hcic_qos_setup(p->hci_handle, p_flow->qos_flags, p_flow->service_type, + p_flow->token_rate, p_flow->peak_bandwidth, + p_flow->latency, p_flow->delay_variation); + return (BTM_CMD_STARTED); + } + + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -1913,12 +1790,10 @@ tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb) * Returns void * ******************************************************************************/ -void btm_qos_setup_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; - btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_qos_setup_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; + btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -1931,34 +1806,32 @@ void btm_qos_setup_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_qos_setup_complete(uint8_t status, uint16_t handle, FLOW_SPEC *p_flow) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; - tBTM_QOS_SETUP_CMPL qossu; - - BTM_TRACE_DEBUG("%s", __func__); - alarm_cancel(btm_cb.devcb.qos_setup_timer); - btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; - - /* If there was a registered callback, call it */ - if (p_cb) - { - memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL)); - qossu.status = status; - qossu.handle = handle; - if (p_flow != NULL) - { - qossu.flow.qos_flags = p_flow->qos_flags; - qossu.flow.service_type = p_flow->service_type; - qossu.flow.token_rate = p_flow->token_rate; - qossu.flow.peak_bandwidth = p_flow->peak_bandwidth; - qossu.flow.latency = p_flow->latency; - qossu.flow.delay_variation = p_flow->delay_variation; - } - BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x", - qossu.flow.delay_variation); - (*p_cb)(&qossu); - } +void btm_qos_setup_complete(uint8_t status, uint16_t handle, + FLOW_SPEC* p_flow) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; + tBTM_QOS_SETUP_CMPL qossu; + + BTM_TRACE_DEBUG("%s", __func__); + alarm_cancel(btm_cb.devcb.qos_setup_timer); + btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; + + /* If there was a registered callback, call it */ + if (p_cb) { + memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL)); + qossu.status = status; + qossu.handle = handle; + if (p_flow != NULL) { + qossu.flow.qos_flags = p_flow->qos_flags; + qossu.flow.service_type = p_flow->service_type; + qossu.flow.token_rate = p_flow->token_rate; + qossu.flow.peak_bandwidth = p_flow->peak_bandwidth; + qossu.flow.latency = p_flow->latency; + qossu.flow.delay_variation = p_flow->delay_variation; + } + BTM_TRACE_DEBUG("BTM: p_flow->delay_variation: 0x%02x", + qossu.flow.delay_variation); + (*p_cb)(&qossu); + } } /******************************************************************************* @@ -1973,38 +1846,33 @@ void btm_qos_setup_complete(uint8_t status, uint16_t handle, FLOW_SPEC *p_flow) * Returns BTM_CMD_STARTED if successfully initiated or error code * ******************************************************************************/ -tBTM_STATUS BTM_ReadRSSI (const BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) -{ - tACL_CONN *p; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - tBT_DEVICE_TYPE dev_type; - tBLE_ADDR_TYPE addr_type; - BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x", - remote_bda[0], remote_bda[1], remote_bda[2], - remote_bda[3], remote_bda[4], remote_bda[5]); - - /* If someone already waiting on the version, do not allow another */ - if (btm_cb.devcb.p_rssi_cmpl_cb) - return(BTM_BUSY); - - BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type); - if (dev_type == BT_DEVICE_TYPE_BLE) - transport = BT_TRANSPORT_LE; - - p = btm_bda_to_acl(remote_bda, transport); - if (p != (tACL_CONN *)NULL) - { - btm_cb.devcb.p_rssi_cmpl_cb = p_cb; - alarm_set_on_queue(btm_cb.devcb.read_rssi_timer, - BTM_DEV_REPLY_TIMEOUT_MS, btm_read_rssi_timeout, - NULL, btu_general_alarm_queue); +tBTM_STATUS BTM_ReadRSSI(const BD_ADDR remote_bda, tBTM_CMPL_CB* p_cb) { + tACL_CONN* p; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + tBT_DEVICE_TYPE dev_type; + tBLE_ADDR_TYPE addr_type; + BTM_TRACE_API("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x", + remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], + remote_bda[4], remote_bda[5]); - btsnd_hcic_read_rssi (p->hci_handle); - return(BTM_CMD_STARTED); - } + /* If someone already waiting on the version, do not allow another */ + if (btm_cb.devcb.p_rssi_cmpl_cb) return (BTM_BUSY); + + BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type); + if (dev_type == BT_DEVICE_TYPE_BLE) transport = BT_TRANSPORT_LE; - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); + p = btm_bda_to_acl(remote_bda, transport); + if (p != (tACL_CONN*)NULL) { + btm_cb.devcb.p_rssi_cmpl_cb = p_cb; + alarm_set_on_queue(btm_cb.devcb.read_rssi_timer, BTM_DEV_REPLY_TIMEOUT_MS, + btm_read_rssi_timeout, NULL, btu_general_alarm_queue); + + btsnd_hcic_read_rssi(p->hci_handle); + return (BTM_CMD_STARTED); + } + + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -2018,33 +1886,29 @@ tBTM_STATUS BTM_ReadRSSI (const BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) * Returns BTM_CMD_STARTED if successfully initiated or error code * ******************************************************************************/ -tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) -{ - tACL_CONN *p; +tBTM_STATUS BTM_ReadLinkQuality(BD_ADDR remote_bda, tBTM_CMPL_CB* p_cb) { + tACL_CONN* p; - BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x", - remote_bda[0], remote_bda[1], remote_bda[2], - remote_bda[3], remote_bda[4], remote_bda[5]); + BTM_TRACE_API("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x", + remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], + remote_bda[4], remote_bda[5]); - /* If someone already waiting on the version, do not allow another */ - if (btm_cb.devcb.p_link_qual_cmpl_cb) - return(BTM_BUSY); + /* If someone already waiting on the version, do not allow another */ + if (btm_cb.devcb.p_link_qual_cmpl_cb) return (BTM_BUSY); - p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); - if (p != (tACL_CONN *)NULL) - { - btm_cb.devcb.p_link_qual_cmpl_cb = p_cb; - alarm_set_on_queue(btm_cb.devcb.read_link_quality_timer, - BTM_DEV_REPLY_TIMEOUT_MS, - btm_read_link_quality_timeout, NULL, - btu_general_alarm_queue); - - btsnd_hcic_get_link_quality(p->hci_handle); - return(BTM_CMD_STARTED); - } + p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); + if (p != (tACL_CONN*)NULL) { + btm_cb.devcb.p_link_qual_cmpl_cb = p_cb; + alarm_set_on_queue(btm_cb.devcb.read_link_quality_timer, + BTM_DEV_REPLY_TIMEOUT_MS, btm_read_link_quality_timeout, + NULL, btu_general_alarm_queue); + + btsnd_hcic_get_link_quality(p->hci_handle); + return (BTM_CMD_STARTED); + } - /* If here, no BD Addr found */ - return(BTM_UNKNOWN_ADDR); + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -2059,44 +1923,38 @@ tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) * Returns BTM_CMD_STARTED if successfully initiated or error code * ******************************************************************************/ -tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb) -{ - tACL_CONN *p; -#define BTM_READ_RSSI_TYPE_CUR 0x00 -#define BTM_READ_RSSI_TYPE_MAX 0X01 - - BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x", - remote_bda[0], remote_bda[1], remote_bda[2], - remote_bda[3], remote_bda[4], remote_bda[5]); - - /* If someone already waiting on the version, do not allow another */ - if (btm_cb.devcb.p_tx_power_cmpl_cb) - return(BTM_BUSY); - - p = btm_bda_to_acl(remote_bda, transport); - if (p != (tACL_CONN *)NULL) - { - btm_cb.devcb.p_tx_power_cmpl_cb = p_cb; - alarm_set_on_queue(btm_cb.devcb.read_tx_power_timer, - BTM_DEV_REPLY_TIMEOUT_MS, - btm_read_tx_power_timeout, NULL, - btu_general_alarm_queue); - - if (p->transport == BT_TRANSPORT_LE) - { - memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN); - btsnd_hcic_ble_read_adv_chnl_tx_power(); - } - else - { - btsnd_hcic_read_tx_power(p->hci_handle, BTM_READ_RSSI_TYPE_CUR); - } +tBTM_STATUS BTM_ReadTxPower(BD_ADDR remote_bda, tBT_TRANSPORT transport, + tBTM_CMPL_CB* p_cb) { + tACL_CONN* p; +#define BTM_READ_RSSI_TYPE_CUR 0x00 +#define BTM_READ_RSSI_TYPE_MAX 0X01 + + BTM_TRACE_API("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x", + remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], + remote_bda[4], remote_bda[5]); + + /* If someone already waiting on the version, do not allow another */ + if (btm_cb.devcb.p_tx_power_cmpl_cb) return (BTM_BUSY); - return(BTM_CMD_STARTED); + p = btm_bda_to_acl(remote_bda, transport); + if (p != (tACL_CONN*)NULL) { + btm_cb.devcb.p_tx_power_cmpl_cb = p_cb; + alarm_set_on_queue(btm_cb.devcb.read_tx_power_timer, + BTM_DEV_REPLY_TIMEOUT_MS, btm_read_tx_power_timeout, + NULL, btu_general_alarm_queue); + + if (p->transport == BT_TRANSPORT_LE) { + memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN); + btsnd_hcic_ble_read_adv_chnl_tx_power(); + } else { + btsnd_hcic_read_tx_power(p->hci_handle, BTM_READ_RSSI_TYPE_CUR); } - /* If here, no BD Addr found */ - return (BTM_UNKNOWN_ADDR); + return (BTM_CMD_STARTED); + } + + /* If here, no BD Addr found */ + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -2108,12 +1966,10 @@ tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_C * Returns void * ******************************************************************************/ -void btm_read_tx_power_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; - btm_cb.devcb.p_tx_power_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_read_tx_power_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; + btm_cb.devcb.p_tx_power_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -2126,55 +1982,46 @@ void btm_read_tx_power_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_read_tx_power_complete(uint8_t *p, bool is_ble) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; - tBTM_TX_POWER_RESULTS results; - uint16_t handle; - tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; - - BTM_TRACE_DEBUG("%s", __func__); - alarm_cancel(btm_cb.devcb.read_tx_power_timer); - btm_cb.devcb.p_tx_power_cmpl_cb = NULL; - - /* If there was a registered callback, call it */ - if (p_cb) - { - STREAM_TO_UINT8 (results.hci_status, p); - - if (results.hci_status == HCI_SUCCESS) - { - results.status = BTM_SUCCESS; - - if (!is_ble) - { - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (results.tx_power, p); - - /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) - { - if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) - { - memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); - break; - } - } - } - else - { - STREAM_TO_UINT8 (results.tx_power, p); - memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN); - } - BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x", - results.tx_power, results.hci_status); +void btm_read_tx_power_complete(uint8_t* p, bool is_ble) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; + tBTM_TX_POWER_RESULTS results; + uint16_t handle; + tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; + uint16_t index; + + BTM_TRACE_DEBUG("%s", __func__); + alarm_cancel(btm_cb.devcb.read_tx_power_timer); + btm_cb.devcb.p_tx_power_cmpl_cb = NULL; + + /* If there was a registered callback, call it */ + if (p_cb) { + STREAM_TO_UINT8(results.hci_status, p); + + if (results.hci_status == HCI_SUCCESS) { + results.status = BTM_SUCCESS; + + if (!is_ble) { + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(results.tx_power, p); + + /* Search through the list of active channels for the correct BD Addr */ + for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { + memcpy(results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); + break; + } } - else - results.status = BTM_ERR_PROCESSING; + } else { + STREAM_TO_UINT8(results.tx_power, p); + memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN); + } + BTM_TRACE_DEBUG("BTM TX power Complete: tx_power %d, hci status 0x%02x", + results.tx_power, results.hci_status); + } else + results.status = BTM_ERR_PROCESSING; - (*p_cb)(&results); - } + (*p_cb)(&results); + } } /******************************************************************************* @@ -2186,12 +2033,10 @@ void btm_read_tx_power_complete(uint8_t *p, bool is_ble) * Returns void * ******************************************************************************/ -void btm_read_rssi_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb; - btm_cb.devcb.p_rssi_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_read_rssi_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb; + btm_cb.devcb.p_rssi_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -2204,48 +2049,42 @@ void btm_read_rssi_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_read_rssi_complete (uint8_t *p) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb; - tBTM_RSSI_RESULTS results; - uint16_t handle; - tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; - - BTM_TRACE_DEBUG("%s", __func__); - alarm_cancel(btm_cb.devcb.read_rssi_timer); - btm_cb.devcb.p_rssi_cmpl_cb = NULL; - - /* If there was a registered callback, call it */ - if (p_cb) - { - STREAM_TO_UINT8 (results.hci_status, p); - - if (results.hci_status == HCI_SUCCESS) - { - results.status = BTM_SUCCESS; - - STREAM_TO_UINT16 (handle, p); - - STREAM_TO_UINT8 (results.rssi, p); - BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x", - results.rssi, results.hci_status); - - /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) - { - if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) - { - memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); - break; - } - } +void btm_read_rssi_complete(uint8_t* p) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb; + tBTM_RSSI_RESULTS results; + uint16_t handle; + tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; + uint16_t index; + + BTM_TRACE_DEBUG("%s", __func__); + alarm_cancel(btm_cb.devcb.read_rssi_timer); + btm_cb.devcb.p_rssi_cmpl_cb = NULL; + + /* If there was a registered callback, call it */ + if (p_cb) { + STREAM_TO_UINT8(results.hci_status, p); + + if (results.hci_status == HCI_SUCCESS) { + results.status = BTM_SUCCESS; + + STREAM_TO_UINT16(handle, p); + + STREAM_TO_UINT8(results.rssi, p); + BTM_TRACE_DEBUG("BTM RSSI Complete: rssi %d, hci status 0x%02x", + results.rssi, results.hci_status); + + /* Search through the list of active channels for the correct BD Addr */ + for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { + memcpy(results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); + break; } - else - results.status = BTM_ERR_PROCESSING; + } + } else + results.status = BTM_ERR_PROCESSING; - (*p_cb)(&results); - } + (*p_cb)(&results); + } } /******************************************************************************* @@ -2257,12 +2096,10 @@ void btm_read_rssi_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_read_link_quality_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; - btm_cb.devcb.p_link_qual_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_read_link_quality_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; + btm_cb.devcb.p_link_qual_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -2275,48 +2112,43 @@ void btm_read_link_quality_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_read_link_quality_complete(uint8_t *p) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; - tBTM_LINK_QUALITY_RESULTS results; - uint16_t handle; - tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; - - BTM_TRACE_DEBUG("%s", __func__); - alarm_cancel(btm_cb.devcb.read_link_quality_timer); - btm_cb.devcb.p_link_qual_cmpl_cb = NULL; - - /* If there was a registered callback, call it */ - if (p_cb) - { - STREAM_TO_UINT8 (results.hci_status, p); - - if (results.hci_status == HCI_SUCCESS) - { - results.status = BTM_SUCCESS; - - STREAM_TO_UINT16 (handle, p); - - STREAM_TO_UINT8 (results.link_quality, p); - BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x", - results.link_quality, results.hci_status); - - /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) - { - if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) - { - memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); - break; - } - } +void btm_read_link_quality_complete(uint8_t* p) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; + tBTM_LINK_QUALITY_RESULTS results; + uint16_t handle; + tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; + uint16_t index; + + BTM_TRACE_DEBUG("%s", __func__); + alarm_cancel(btm_cb.devcb.read_link_quality_timer); + btm_cb.devcb.p_link_qual_cmpl_cb = NULL; + + /* If there was a registered callback, call it */ + if (p_cb) { + STREAM_TO_UINT8(results.hci_status, p); + + if (results.hci_status == HCI_SUCCESS) { + results.status = BTM_SUCCESS; + + STREAM_TO_UINT16(handle, p); + + STREAM_TO_UINT8(results.link_quality, p); + BTM_TRACE_DEBUG( + "BTM Link Quality Complete: Link Quality %d, hci status 0x%02x", + results.link_quality, results.hci_status); + + /* Search through the list of active channels for the correct BD Addr */ + for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { + memcpy(results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); + break; } - else - results.status = BTM_ERR_PROCESSING; + } + } else + results.status = BTM_ERR_PROCESSING; - (*p_cb)(&results); - } + (*p_cb)(&results); + } } /******************************************************************************* @@ -2329,36 +2161,30 @@ void btm_read_link_quality_complete(uint8_t *p) * BTM_NO_RESOURCES. * ******************************************************************************/ -tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport) -{ - uint16_t hci_handle = BTM_GetHCIConnHandle(bd_addr, transport); - tBTM_STATUS status = BTM_SUCCESS; +tBTM_STATUS btm_remove_acl(BD_ADDR bd_addr, tBT_TRANSPORT transport) { + uint16_t hci_handle = BTM_GetHCIConnHandle(bd_addr, transport); + tBTM_STATUS status = BTM_SUCCESS; - BTM_TRACE_DEBUG ("btm_remove_acl"); + BTM_TRACE_DEBUG("btm_remove_acl"); #if (BTM_DISC_DURING_RS == TRUE) - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - /* Role Switch is pending, postpone until completed */ - if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) - { - p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; - } - else /* otherwise can disconnect right away */ + /* Role Switch is pending, postpone until completed */ + if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) { + p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; + } else /* otherwise can disconnect right away */ #endif - { - if (hci_handle != 0xFFFF && p_dev_rec && - p_dev_rec->sec_state!= BTM_SEC_STATE_DISCONNECTING) - { - btsnd_hcic_disconnect(hci_handle, HCI_ERR_PEER_USER); - } - else - status = BTM_UNKNOWN_ADDR; - } + { + if (hci_handle != 0xFFFF && p_dev_rec && + p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) { + btsnd_hcic_disconnect(hci_handle, HCI_ERR_PEER_USER); + } else + status = BTM_UNKNOWN_ADDR; + } - return status; + return status; } - /******************************************************************************* * * Function BTM_SetTraceLevel @@ -2369,13 +2195,11 @@ tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport) * Returns The new or current trace level * ******************************************************************************/ -uint8_t BTM_SetTraceLevel (uint8_t new_level) -{ - BTM_TRACE_DEBUG ("BTM_SetTraceLevel"); - if (new_level != 0xFF) - btm_cb.trace_level = new_level; +uint8_t BTM_SetTraceLevel(uint8_t new_level) { + BTM_TRACE_DEBUG("BTM_SetTraceLevel"); + if (new_level != 0xFF) btm_cb.trace_level = new_level; - return(btm_cb.trace_level); + return (btm_cb.trace_level); } /******************************************************************************* @@ -2389,38 +2213,34 @@ uint8_t BTM_SetTraceLevel (uint8_t new_level) * Returns void * ******************************************************************************/ -void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec, - uint8_t hci_status) -{ - BTM_TRACE_DEBUG ("btm_cont_rswitch"); - /* Check to see if encryption needs to be turned off if pending - change of link key or role switch */ - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) - { - /* Must turn off Encryption first if necessary */ - /* Some devices do not support switch or change of link key while encryption is on */ - if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) - && !BTM_EPR_AVAILABLE(p)) - { - btsnd_hcic_set_conn_encrypt(p->hci_handle, false); - p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) - p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; - } - else /* Encryption not used or EPR supported, continue with switch - and/or change of link key */ - { - if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) - { - p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; +void btm_cont_rswitch(tACL_CONN* p, tBTM_SEC_DEV_REC* p_dev_rec, + uint8_t hci_status) { + BTM_TRACE_DEBUG("btm_cont_rswitch"); + /* Check to see if encryption needs to be turned off if pending + change of link key or role switch */ + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) { + /* Must turn off Encryption first if necessary */ + /* Some devices do not support switch or change of link key while encryption + * is on */ + if (p_dev_rec != NULL && + ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) && + !BTM_EPR_AVAILABLE(p)) { + btsnd_hcic_set_conn_encrypt(p->hci_handle, false); + p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) + p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; + } else /* Encryption not used or EPR supported, continue with switch + and/or change of link key */ + { + if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) { + p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; #if (BTM_DISC_DURING_RS == TRUE) - if (p_dev_rec) - p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; + if (p_dev_rec) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; #endif - btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role); - } - } + btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role); + } } + } } /******************************************************************************* @@ -2430,32 +2250,29 @@ void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec, * Description send pending page request * ******************************************************************************/ -void btm_acl_resubmit_page (void) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - BT_HDR *p_buf; - uint8_t *pp; - BD_ADDR bda; - BTM_TRACE_DEBUG ("btm_acl_resubmit_page"); - /* If there were other page request schedule can start the next one */ - p_buf = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue); - if (p_buf != NULL) - { - /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr - * for both create_conn and rmt_name */ - pp = (uint8_t *)(p_buf + 1) + p_buf->offset + 3; - - STREAM_TO_BDADDR (bda, pp); - - p_dev_rec = btm_find_or_alloc_dev (bda); - - memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); - memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf); - } - else - btm_cb.paging = false; +void btm_acl_resubmit_page(void) { + tBTM_SEC_DEV_REC* p_dev_rec; + BT_HDR* p_buf; + uint8_t* pp; + BD_ADDR bda; + BTM_TRACE_DEBUG("btm_acl_resubmit_page"); + /* If there were other page request schedule can start the next one */ + p_buf = (BT_HDR*)fixed_queue_try_dequeue(btm_cb.page_queue); + if (p_buf != NULL) { + /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr + * for both create_conn and rmt_name */ + pp = (uint8_t*)(p_buf + 1) + p_buf->offset + 3; + + STREAM_TO_BDADDR(bda, pp); + + p_dev_rec = btm_find_or_alloc_dev(bda); + + memcpy(btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); + memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p_buf); + } else + btm_cb.paging = false; } /******************************************************************************* @@ -2466,15 +2283,14 @@ void btm_acl_resubmit_page (void) * hci_reset * ******************************************************************************/ -void btm_acl_reset_paging (void) -{ - BT_HDR *p; - BTM_TRACE_DEBUG ("btm_acl_reset_paging"); - /* If we sent reset we are definitely not paging any more */ - while ((p = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) - osi_free(p); +void btm_acl_reset_paging(void) { + BT_HDR* p; + BTM_TRACE_DEBUG("btm_acl_reset_paging"); + /* If we sent reset we are definitely not paging any more */ + while ((p = (BT_HDR*)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) + osi_free(p); - btm_cb.paging = false; + btm_cb.paging = false; } /******************************************************************************* @@ -2484,48 +2300,41 @@ void btm_acl_reset_paging (void) * Description send a paging command or queue it in btm_cb * ******************************************************************************/ -void btm_acl_paging (BT_HDR *p, BD_ADDR bda) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x", - btm_cb.discing, btm_cb.paging, - (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]); - if (btm_cb.discing) - { - btm_cb.paging = true; +void btm_acl_paging(BT_HDR* p, BD_ADDR bda) { + tBTM_SEC_DEV_REC* p_dev_rec; + + BTM_TRACE_DEBUG("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x", + btm_cb.discing, btm_cb.paging, + (bda[0] << 16) + (bda[1] << 8) + bda[2], + (bda[3] << 16) + (bda[4] << 8) + bda[5]); + if (btm_cb.discing) { + btm_cb.paging = true; + fixed_queue_enqueue(btm_cb.page_queue, p); + } else { + if (!BTM_ACL_IS_CONNECTED(bda)) { + BTM_TRACE_DEBUG( + "connecting_bda: %06x%06x", + (btm_cb.connecting_bda[0] << 16) + (btm_cb.connecting_bda[1] << 8) + + btm_cb.connecting_bda[2], + (btm_cb.connecting_bda[3] << 16) + (btm_cb.connecting_bda[4] << 8) + + btm_cb.connecting_bda[5]); + if (btm_cb.paging && + memcmp(bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) { fixed_queue_enqueue(btm_cb.page_queue, p); - } - else + } else { + p_dev_rec = btm_find_or_alloc_dev(bda); + memcpy(btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); + memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + } + + btm_cb.paging = true; + } else /* ACL is already up */ { - if (!BTM_ACL_IS_CONNECTED (bda)) - { - BTM_TRACE_DEBUG ("connecting_bda: %06x%06x", - (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) + - btm_cb.connecting_bda[2], - (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) + - btm_cb.connecting_bda[5]); - if (btm_cb.paging && - memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) - { - fixed_queue_enqueue(btm_cb.page_queue, p); - } - else - { - p_dev_rec = btm_find_or_alloc_dev (bda); - memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); - memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - } - - btm_cb.paging = true; - } - else /* ACL is already up */ - { - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - } + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } + } } /******************************************************************************* @@ -2538,28 +2347,25 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda) * false if no one needs the notification. * ******************************************************************************/ -bool btm_acl_notif_conn_collision (BD_ADDR bda) -{ - tBTM_BL_EVENT_DATA evt_data; +bool btm_acl_notif_conn_collision(BD_ADDR bda) { + tBTM_BL_EVENT_DATA evt_data; - /* Report possible collision to the upper layer. */ - if (btm_cb.p_bl_changed_cb) - { - BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + /* Report possible collision to the upper layer. */ + if (btm_cb.p_bl_changed_cb) { + BTM_TRACE_DEBUG( + "btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); - evt_data.event = BTM_BL_COLLISION_EVT; - evt_data.conn.p_bda = bda; - evt_data.conn.transport = BT_TRANSPORT_BR_EDR; - evt_data.conn.handle = BTM_INVALID_HCI_HANDLE; - (*btm_cb.p_bl_changed_cb)(&evt_data); - return true; - } - else - return false; + evt_data.event = BTM_BL_COLLISION_EVT; + evt_data.conn.p_bda = bda; + evt_data.conn.transport = BT_TRANSPORT_BR_EDR; + evt_data.conn.handle = BTM_INVALID_HCI_HANDLE; + (*btm_cb.p_bl_changed_cb)(&evt_data); + return true; + } else + return false; } - /******************************************************************************* * * Function btm_acl_chk_peer_pkt_type_support @@ -2567,36 +2373,48 @@ bool btm_acl_notif_conn_collision (BD_ADDR bda) * Description Check if peer supports requested packets * ******************************************************************************/ -void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, uint16_t *p_pkt_type) -{ - /* 3 and 5 slot packets? */ - if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3); - - if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5); - - /* 2 and 3 MPS support? */ - if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - /* Not supported. Add 'not_supported' mask for all 2MPS packet types */ - *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + - BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); - - if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - /* Not supported. Add 'not_supported' mask for all 3MPS packet types */ - *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + - BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); - - /* EDR 3 and 5 slot support? */ - if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) - || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - { - if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */ - *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); - - if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */ - *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); - } +void btm_acl_chk_peer_pkt_type_support(tACL_CONN* p, uint16_t* p_pkt_type) { + /* 3 and 5 slot packets? */ + if (!HCI_3_SLOT_PACKETS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3); + + if (!HCI_5_SLOT_PACKETS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5); + + /* 2 and 3 MPS support? */ + if (!HCI_EDR_ACL_2MPS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + /* Not supported. Add 'not_supported' mask for all 2MPS packet types */ + *p_pkt_type |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + + BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); + + if (!HCI_EDR_ACL_3MPS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + /* Not supported. Add 'not_supported' mask for all 3MPS packet types */ + *p_pkt_type |= + (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); + + /* EDR 3 and 5 slot support? */ + if (HCI_EDR_ACL_2MPS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) || + HCI_EDR_ACL_3MPS_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) { + if (!HCI_3_SLOT_EDR_ACL_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types + */ + *p_pkt_type |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); + + if (!HCI_5_SLOT_EDR_ACL_SUPPORTED( + p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) + /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types + */ + *p_pkt_type |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); + } } diff --git a/stack/btm/btm_ble.cc b/stack/btm/btm_ble.cc index 975361973..082116deb 100644 --- a/stack/btm/btm_ble.cc +++ b/stack/btm/btm_ble.cc @@ -43,8 +43,9 @@ #include "osi/include/osi.h" #include "smp_api.h" -extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t length, - uint16_t tlen, uint8_t *p_signature); +extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t* input, + uint16_t length, uint16_t tlen, + uint8_t* p_signature); /******************************************************************************/ /* External Function to be called by other modules */ @@ -65,52 +66,49 @@ extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t * Returns true if added OK, else false * ******************************************************************************/ -bool BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type, - tBLE_ADDR_TYPE addr_type) -{ - BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type); +bool BTM_SecAddBleDevice(const BD_ADDR bd_addr, BD_NAME bd_name, + tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type) { + BTM_TRACE_DEBUG("%s: dev_type=0x%x", __func__, dev_type); - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); - if (!p_dev_rec) - { - p_dev_rec = btm_sec_allocate_dev_rec(); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (!p_dev_rec) { + p_dev_rec = btm_sec_allocate_dev_rec(); - memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); - p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); - p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE); + memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); + p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); + p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE); - /* update conn params, use default value for background connection params */ - p_dev_rec->conn_params.min_conn_int = BTM_BLE_CONN_PARAM_UNDEF; - p_dev_rec->conn_params.max_conn_int = BTM_BLE_CONN_PARAM_UNDEF; - p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_PARAM_UNDEF; - p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; + /* update conn params, use default value for background connection params */ + p_dev_rec->conn_params.min_conn_int = BTM_BLE_CONN_PARAM_UNDEF; + p_dev_rec->conn_params.max_conn_int = BTM_BLE_CONN_PARAM_UNDEF; + p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_PARAM_UNDEF; + p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; - BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, p_dev_rec->ble_hci_handle); - } + BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, + p_dev_rec->ble_hci_handle); + } - memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); + memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); - if (bd_name && bd_name[0]) - { - p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; - strlcpy((char *)p_dev_rec->sec_bd_name, - (char *)bd_name, BTM_MAX_REM_BD_NAME_LEN); - } - p_dev_rec->device_type |= dev_type; - p_dev_rec->ble.ble_addr_type = addr_type; + if (bd_name && bd_name[0]) { + p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; + strlcpy((char*)p_dev_rec->sec_bd_name, (char*)bd_name, + BTM_MAX_REM_BD_NAME_LEN); + } + p_dev_rec->device_type |= dev_type; + p_dev_rec->ble.ble_addr_type = addr_type; - memcpy(p_dev_rec->ble.pseudo_addr, bd_addr, BD_ADDR_LEN); - /* sync up with the Inq Data base*/ - tBTM_INQ_INFO *p_info = BTM_InqDbRead(bd_addr); - if (p_info) - { - p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; - p_info->results.device_type = p_dev_rec->device_type; - BTM_TRACE_DEBUG("InqDb device_type =0x%x addr_type=0x%x", - p_info->results.device_type, p_info->results.ble_addr_type); - } + memcpy(p_dev_rec->ble.pseudo_addr, bd_addr, BD_ADDR_LEN); + /* sync up with the Inq Data base*/ + tBTM_INQ_INFO* p_info = BTM_InqDbRead(bd_addr); + if (p_info) { + p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type; + p_info->results.device_type = p_dev_rec->device_type; + BTM_TRACE_DEBUG("InqDb device_type =0x%x addr_type=0x%x", + p_info->results.device_type, p_info->results.ble_addr_type); + } - return true; + return true; } /******************************************************************************* @@ -128,35 +126,37 @@ bool BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_ * Returns true if added OK, else false * ******************************************************************************/ -bool BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_KEY_TYPE key_type) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - BTM_TRACE_DEBUG ("BTM_SecAddBleKey"); - p_dev_rec = btm_find_dev (bd_addr); - if (!p_dev_rec || !p_le_key || - (key_type != BTM_LE_KEY_PENC && key_type != BTM_LE_KEY_PID && - key_type != BTM_LE_KEY_PCSRK && key_type != BTM_LE_KEY_LENC && - key_type != BTM_LE_KEY_LCSRK && key_type != BTM_LE_KEY_LID)) - { - BTM_TRACE_WARNING ("BTM_SecAddBleKey() Wrong Type, or No Device record \ +bool BTM_SecAddBleKey(BD_ADDR bd_addr, tBTM_LE_KEY_VALUE* p_le_key, + tBTM_LE_KEY_TYPE key_type) { + tBTM_SEC_DEV_REC* p_dev_rec; + BTM_TRACE_DEBUG("BTM_SecAddBleKey"); + p_dev_rec = btm_find_dev(bd_addr); + if (!p_dev_rec || !p_le_key || + (key_type != BTM_LE_KEY_PENC && key_type != BTM_LE_KEY_PID && + key_type != BTM_LE_KEY_PCSRK && key_type != BTM_LE_KEY_LENC && + key_type != BTM_LE_KEY_LCSRK && key_type != BTM_LE_KEY_LID)) { + BTM_TRACE_WARNING( + "BTM_SecAddBleKey() Wrong Type, or No Device record \ for bdaddr: %08x%04x, Type: %d", - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], key_type); - return(false); - } + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], key_type); + return (false); + } - BTM_TRACE_DEBUG ("BTM_SecAddLeKey() BDA: %08x%04x, Type: 0x%02x", - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], key_type); + BTM_TRACE_DEBUG( + "BTM_SecAddLeKey() BDA: %08x%04x, Type: 0x%02x", + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], key_type); - btm_sec_save_le_key (bd_addr, key_type, p_le_key, false); + btm_sec_save_le_key(bd_addr, key_type, p_le_key, false); #if (BLE_PRIVACY_SPT == TRUE) - if (key_type == BTM_LE_KEY_PID || key_type == BTM_LE_KEY_LID) - btm_ble_resolving_list_load_dev (p_dev_rec); + if (key_type == BTM_LE_KEY_PID || key_type == BTM_LE_KEY_LID) + btm_ble_resolving_list_load_dev(p_dev_rec); #endif - return(true); + return (true); } /******************************************************************************* @@ -173,27 +173,26 @@ bool BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_ * Returns non2. * ******************************************************************************/ -void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS *p_key) -{ - tBTM_DEVCB *p_devcb = &btm_cb.devcb; - BTM_TRACE_DEBUG ("%s", __func__); - if (p_key != NULL) - { - switch (key_type) - { - case BTM_BLE_KEY_TYPE_ID: - memcpy(&p_devcb->id_keys, &p_key->id_keys, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); - break; - - case BTM_BLE_KEY_TYPE_ER: - memcpy(p_devcb->ble_encryption_key_value, p_key->er, sizeof(BT_OCTET16)); - break; - - default: - BTM_TRACE_ERROR("unknow local key type: %d", key_type); - break; - } +void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key) { + tBTM_DEVCB* p_devcb = &btm_cb.devcb; + BTM_TRACE_DEBUG("%s", __func__); + if (p_key != NULL) { + switch (key_type) { + case BTM_BLE_KEY_TYPE_ID: + memcpy(&p_devcb->id_keys, &p_key->id_keys, + sizeof(tBTM_BLE_LOCAL_ID_KEYS)); + break; + + case BTM_BLE_KEY_TYPE_ER: + memcpy(p_devcb->ble_encryption_key_value, p_key->er, + sizeof(BT_OCTET16)); + break; + + default: + BTM_TRACE_ERROR("unknow local key type: %d", key_type); + break; } + } } /******************************************************************************* @@ -207,10 +206,10 @@ void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS *p_key) * the local device ER is copied into ble_encr_key_value * ******************************************************************************/ -void BTM_GetDeviceEncRoot (BT_OCTET16 ble_encr_key_value) -{ - BTM_TRACE_DEBUG ("%s", __func__); - memcpy (ble_encr_key_value, btm_cb.devcb.ble_encryption_key_value, BT_OCTET16_LEN); +void BTM_GetDeviceEncRoot(BT_OCTET16 ble_encr_key_value) { + BTM_TRACE_DEBUG("%s", __func__); + memcpy(ble_encr_key_value, btm_cb.devcb.ble_encryption_key_value, + BT_OCTET16_LEN); } /******************************************************************************* @@ -224,11 +223,10 @@ void BTM_GetDeviceEncRoot (BT_OCTET16 ble_encr_key_value) * the local device IR is copied into irk * ******************************************************************************/ -void BTM_GetDeviceIDRoot (BT_OCTET16 irk) -{ - BTM_TRACE_DEBUG ("BTM_GetDeviceIDRoot "); +void BTM_GetDeviceIDRoot(BT_OCTET16 irk) { + BTM_TRACE_DEBUG("BTM_GetDeviceIDRoot "); - memcpy (irk, btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN); + memcpy(irk, btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN); } /******************************************************************************* @@ -241,10 +239,9 @@ void BTM_GetDeviceIDRoot (BT_OCTET16 irk) * the local device DHK is copied into dhk * ******************************************************************************/ -void BTM_GetDeviceDHK (BT_OCTET16 dhk) -{ - BTM_TRACE_DEBUG ("BTM_GetDeviceDHK"); - memcpy (dhk, btm_cb.devcb.id_keys.dhk, BT_OCTET16_LEN); +void BTM_GetDeviceDHK(BT_OCTET16 dhk) { + BTM_TRACE_DEBUG("BTM_GetDeviceDHK"); + memcpy(dhk, btm_cb.devcb.id_keys.dhk, BT_OCTET16_LEN); } /******************************************************************************* @@ -257,20 +254,19 @@ void BTM_GetDeviceDHK (BT_OCTET16 dhk) * Returns void * ******************************************************************************/ -void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, tBLE_ADDR_TYPE *p_addr_type) -{ - tACL_CONN *p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_LE); +void BTM_ReadConnectionAddr(BD_ADDR remote_bda, BD_ADDR local_conn_addr, + tBLE_ADDR_TYPE* p_addr_type) { + tACL_CONN* p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_LE); - if (p_acl == NULL) - { - BTM_TRACE_ERROR("No connection exist!"); - return; - } - memcpy(local_conn_addr, p_acl->conn_addr, BD_ADDR_LEN); - * p_addr_type = p_acl->conn_addr_type; + if (p_acl == NULL) { + BTM_TRACE_ERROR("No connection exist!"); + return; + } + memcpy(local_conn_addr, p_acl->conn_addr, BD_ADDR_LEN); + *p_addr_type = p_acl->conn_addr_type; - BTM_TRACE_DEBUG ("BTM_ReadConnectionAddr address type: %d addr: 0x%02x", - p_acl->conn_addr_type, p_acl->conn_addr[0]); + BTM_TRACE_DEBUG("BTM_ReadConnectionAddr address type: %d addr: 0x%02x", + p_acl->conn_addr_type, p_acl->conn_addr[0]); } /******************************************************************************* @@ -283,20 +279,18 @@ void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, tBLE_A * Returns true if connection is LE link, otherwise false. * ******************************************************************************/ -bool BTM_IsBleConnection (uint16_t conn_handle) -{ - uint8_t xx; - tACL_CONN *p; +bool BTM_IsBleConnection(uint16_t conn_handle) { + uint8_t xx; + tACL_CONN* p; - BTM_TRACE_API ("BTM_IsBleConnection: conn_handle: %d", conn_handle); + BTM_TRACE_API("BTM_IsBleConnection: conn_handle: %d", conn_handle); - xx = btm_handle_to_acl_index (conn_handle); - if (xx >= MAX_L2CAP_LINKS) - return false; + xx = btm_handle_to_acl_index(conn_handle); + if (xx >= MAX_L2CAP_LINKS) return false; - p = &btm_cb.acl_db[xx]; + p = &btm_cb.acl_db[xx]; - return (p->transport == BT_TRANSPORT_LE); + return (p->transport == BT_TRANSPORT_LE); } /******************************************************************************* @@ -313,33 +307,30 @@ bool BTM_IsBleConnection (uint16_t conn_handle) * Returns bool, true if connection to remote device exists, else false * ******************************************************************************/ -bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, - tBLE_ADDR_TYPE *p_addr_type) -{ - bool st = true; +bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, + tBLE_ADDR_TYPE* p_addr_type) { + bool st = true; #if (BLE_PRIVACY_SPT == TRUE) - tACL_CONN *p = btm_bda_to_acl (pseudo_addr, BT_TRANSPORT_LE); + tACL_CONN* p = btm_bda_to_acl(pseudo_addr, BT_TRANSPORT_LE); - if (p == NULL) - { - BTM_TRACE_ERROR("BTM_ReadRemoteConnectionAddr can not find connection" - " with matching address"); - return false; - } + if (p == NULL) { + BTM_TRACE_ERROR( + "BTM_ReadRemoteConnectionAddr can not find connection" + " with matching address"); + return false; + } - memcpy(conn_addr, p->active_remote_addr, BD_ADDR_LEN); - *p_addr_type = p->active_remote_addr_type; + memcpy(conn_addr, p->active_remote_addr, BD_ADDR_LEN); + *p_addr_type = p->active_remote_addr_type; #else - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(pseudo_addr); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(pseudo_addr); - memcpy(conn_addr, pseudo_addr, BD_ADDR_LEN); - if (p_dev_rec != NULL) - { - *p_addr_type = p_dev_rec->ble.ble_addr_type; - } + memcpy(conn_addr, pseudo_addr, BD_ADDR_LEN); + if (p_dev_rec != NULL) { + *p_addr_type = p_dev_rec->ble.ble_addr_type; + } #endif - return st; - + return st; } /******************************************************************************* * @@ -355,11 +346,11 @@ bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, * Returns None * ******************************************************************************/ -void BTM_SecurityGrant(BD_ADDR bd_addr, uint8_t res) -{ - tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_REPEATED_ATTEMPTS; - BTM_TRACE_DEBUG ("BTM_SecurityGrant"); - SMP_SecurityGrant(bd_addr, res_smp); +void BTM_SecurityGrant(BD_ADDR bd_addr, uint8_t res) { + tSMP_STATUS res_smp = + (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_REPEATED_ATTEMPTS; + BTM_TRACE_DEBUG("BTM_SecurityGrant"); + SMP_SecurityGrant(bd_addr, res_smp); } /******************************************************************************* @@ -378,20 +369,19 @@ void BTM_SecurityGrant(BD_ADDR bd_addr, uint8_t res) * uint32_t) * ******************************************************************************/ -void BTM_BlePasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL; +void BTM_BlePasskeyReply(BD_ADDR bd_addr, uint8_t res, uint32_t passkey) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + tSMP_STATUS res_smp = + (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL; - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR("Passkey reply to Unknown device"); - return; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("Passkey reply to Unknown device"); + return; + } - p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - BTM_TRACE_DEBUG ("BTM_BlePasskeyReply"); - SMP_PasskeyReply(bd_addr, res_smp, passkey); + p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; + BTM_TRACE_DEBUG("BTM_BlePasskeyReply"); + SMP_PasskeyReply(bd_addr, res_smp, passkey); } /******************************************************************************* @@ -406,20 +396,19 @@ void BTM_BlePasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey) * res - comparison result BTM_SUCCESS if success * ******************************************************************************/ -void BTM_BleConfirmReply (BD_ADDR bd_addr, uint8_t res) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL; +void BTM_BleConfirmReply(BD_ADDR bd_addr, uint8_t res) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + tSMP_STATUS res_smp = + (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL; - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR("Passkey reply to Unknown device"); - return; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("Passkey reply to Unknown device"); + return; + } - p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - BTM_TRACE_DEBUG ("%s", __func__); - SMP_ConfirmReply(bd_addr, res_smp); + p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; + BTM_TRACE_DEBUG("%s", __func__); + SMP_ConfirmReply(bd_addr, res_smp); } /******************************************************************************* @@ -437,20 +426,20 @@ void BTM_BleConfirmReply (BD_ADDR bd_addr, uint8_t res) * "Security Manager TK Value". * ******************************************************************************/ -void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, uint8_t *p_data) -{ - tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_OOB_FAIL; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, + uint8_t* p_data) { + tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_OOB_FAIL; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - BTM_TRACE_DEBUG ("%s:", __func__); + BTM_TRACE_DEBUG("%s:", __func__); - if (p_dev_rec == NULL) { - BTM_TRACE_ERROR("%s: Unknown device", __func__); - return; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("%s: Unknown device", __func__); + return; + } - p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - SMP_OobDataReply(bd_addr, res_smp, len, p_data); + p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; + SMP_OobDataReply(bd_addr, res_smp, len, p_data); } /******************************************************************************* @@ -466,30 +455,29 @@ void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, uint8_t *p_d * p_r - pointer to Randomizer * ******************************************************************************/ -void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, - uint8_t *p_c, uint8_t *p_r) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, uint8_t* p_c, + uint8_t* p_r) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - BTM_TRACE_DEBUG ("%s:", __func__); + BTM_TRACE_DEBUG("%s:", __func__); - if (p_dev_rec == NULL) { - BTM_TRACE_ERROR("%s: Unknown device", __func__); - return; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("%s: Unknown device", __func__); + return; + } - p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; + p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - tSMP_SC_OOB_DATA oob; - memset(&oob, 0, sizeof(tSMP_SC_OOB_DATA)); + tSMP_SC_OOB_DATA oob; + memset(&oob, 0, sizeof(tSMP_SC_OOB_DATA)); - oob.peer_oob_data.present = true; - memcpy(&oob.peer_oob_data.randomizer, p_r, BT_OCTET16_LEN); - memcpy(&oob.peer_oob_data.commitment, p_c, BT_OCTET16_LEN); - oob.peer_oob_data.addr_rcvd_from.type = p_dev_rec->ble.ble_addr_type; - memcpy(&oob.peer_oob_data.addr_rcvd_from.bda, bd_addr, sizeof(BD_ADDR)); + oob.peer_oob_data.present = true; + memcpy(&oob.peer_oob_data.randomizer, p_r, BT_OCTET16_LEN); + memcpy(&oob.peer_oob_data.commitment, p_c, BT_OCTET16_LEN); + oob.peer_oob_data.addr_rcvd_from.type = p_dev_rec->ble.ble_addr_type; + memcpy(&oob.peer_oob_data.addr_rcvd_from.bda, bd_addr, sizeof(BD_ADDR)); - SMP_SecureConnectionOobDataReply((uint8_t*)&oob); + SMP_SecureConnectionOobDataReply((uint8_t*)&oob); } /****************************************************************************** @@ -504,35 +492,30 @@ void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, * Returns void * ******************************************************************************/ -void BTM_BleSetConnScanParams (uint32_t scan_interval, uint32_t scan_window) -{ - tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; - bool new_param = false; - - if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && - BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX)) - { - if (p_ble_cb->scan_int != scan_interval) - { - p_ble_cb->scan_int = scan_interval; - new_param = true; - } +void BTM_BleSetConnScanParams(uint32_t scan_interval, uint32_t scan_window) { + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; + bool new_param = false; - if (p_ble_cb->scan_win != scan_window) - { - p_ble_cb->scan_win = scan_window; - new_param = true; - } + if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, + BTM_BLE_SCAN_INT_MAX) && + BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, + BTM_BLE_SCAN_WIN_MAX)) { + if (p_ble_cb->scan_int != scan_interval) { + p_ble_cb->scan_int = scan_interval; + new_param = true; + } - if (new_param && p_ble_cb->conn_state == BLE_BG_CONN) - { - btm_ble_suspend_bg_conn(); - } + if (p_ble_cb->scan_win != scan_window) { + p_ble_cb->scan_win = scan_window; + new_param = true; } - else - { - BTM_TRACE_ERROR("Illegal Connection Scan Parameters"); + + if (new_param && p_ble_cb->conn_state == BLE_BG_CONN) { + btm_ble_suspend_bg_conn(); } + } else { + BTM_TRACE_ERROR("Illegal Connection Scan Parameters"); + } } /******************************************************** @@ -552,58 +535,56 @@ void BTM_BleSetConnScanParams (uint32_t scan_interval, uint32_t scan_window) * Returns void * ******************************************************************************/ -void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, - uint16_t min_conn_int, uint16_t max_conn_int, - uint16_t slave_latency, uint16_t supervision_tout) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +void BTM_BleSetPrefConnParams(BD_ADDR bd_addr, uint16_t min_conn_int, + uint16_t max_conn_int, uint16_t slave_latency, + uint16_t supervision_tout) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - BTM_TRACE_API ("BTM_BleSetPrefConnParams min: %u max: %u latency: %u \ + BTM_TRACE_API( + "BTM_BleSetPrefConnParams min: %u max: %u latency: %u \ tout: %u", - min_conn_int, max_conn_int, slave_latency, supervision_tout); + min_conn_int, max_conn_int, slave_latency, supervision_tout); + + if (BTM_BLE_ISVALID_PARAM(min_conn_int, BTM_BLE_CONN_INT_MIN, + BTM_BLE_CONN_INT_MAX) && + BTM_BLE_ISVALID_PARAM(max_conn_int, BTM_BLE_CONN_INT_MIN, + BTM_BLE_CONN_INT_MAX) && + BTM_BLE_ISVALID_PARAM(supervision_tout, BTM_BLE_CONN_SUP_TOUT_MIN, + BTM_BLE_CONN_SUP_TOUT_MAX) && + (slave_latency <= BTM_BLE_CONN_LATENCY_MAX || + slave_latency == BTM_BLE_CONN_PARAM_UNDEF)) { + if (p_dev_rec) { + /* expect conn int and stout and slave latency to be updated all together + */ + if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF || + max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) { + if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) + p_dev_rec->conn_params.min_conn_int = min_conn_int; + else + p_dev_rec->conn_params.min_conn_int = max_conn_int; - if (BTM_BLE_ISVALID_PARAM(min_conn_int, BTM_BLE_CONN_INT_MIN, BTM_BLE_CONN_INT_MAX) && - BTM_BLE_ISVALID_PARAM(max_conn_int, BTM_BLE_CONN_INT_MIN, BTM_BLE_CONN_INT_MAX) && - BTM_BLE_ISVALID_PARAM(supervision_tout, BTM_BLE_CONN_SUP_TOUT_MIN, BTM_BLE_CONN_SUP_TOUT_MAX) && - (slave_latency <= BTM_BLE_CONN_LATENCY_MAX || slave_latency == BTM_BLE_CONN_PARAM_UNDEF)) - { - if (p_dev_rec) - { - /* expect conn int and stout and slave latency to be updated all together */ - if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF || max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) - { - if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) - p_dev_rec->conn_params.min_conn_int = min_conn_int; - else - p_dev_rec->conn_params.min_conn_int = max_conn_int; - - if (max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) - p_dev_rec->conn_params.max_conn_int = max_conn_int; - else - p_dev_rec->conn_params.max_conn_int = min_conn_int; - - if (slave_latency != BTM_BLE_CONN_PARAM_UNDEF) - p_dev_rec->conn_params.slave_latency = slave_latency; - else - p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; - - if (supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) - p_dev_rec->conn_params.supervision_tout = supervision_tout; - else - p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF; + if (max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) + p_dev_rec->conn_params.max_conn_int = max_conn_int; + else + p_dev_rec->conn_params.max_conn_int = min_conn_int; - } + if (slave_latency != BTM_BLE_CONN_PARAM_UNDEF) + p_dev_rec->conn_params.slave_latency = slave_latency; + else + p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; - } + if (supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) + p_dev_rec->conn_params.supervision_tout = supervision_tout; else - { - BTM_TRACE_ERROR("Unknown Device, setting rejected"); - } - } - else - { - BTM_TRACE_ERROR("Illegal Connection Parameters"); + p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF; + } + + } else { + BTM_TRACE_ERROR("Unknown Device, setting rejected"); } + } else { + BTM_TRACE_ERROR("Illegal Connection Parameters"); + } } /******************************************************************************* @@ -618,54 +599,47 @@ void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, * p_addr_type: output parameter to read the address type. * ******************************************************************************/ -void BTM_ReadDevInfo (const BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR_TYPE *p_addr_type) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (remote_bda); - tBTM_INQ_INFO *p_inq_info = BTM_InqDbRead(remote_bda); +void BTM_ReadDevInfo(const BD_ADDR remote_bda, tBT_DEVICE_TYPE* p_dev_type, + tBLE_ADDR_TYPE* p_addr_type) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(remote_bda); + tBTM_INQ_INFO* p_inq_info = BTM_InqDbRead(remote_bda); - *p_addr_type = BLE_ADDR_PUBLIC; + *p_addr_type = BLE_ADDR_PUBLIC; - if (!p_dev_rec) - { - *p_dev_type = BT_DEVICE_TYPE_BREDR; - /* Check with the BT manager if details about remote device are known */ - if (p_inq_info != NULL) - { - *p_dev_type = p_inq_info->results.device_type ; - *p_addr_type = p_inq_info->results.ble_addr_type; - } else { - /* unknown device, assume BR/EDR */ - BTM_TRACE_DEBUG ("btm_find_dev_type - unknown device, BR/EDR assumed"); - } + if (!p_dev_rec) { + *p_dev_type = BT_DEVICE_TYPE_BREDR; + /* Check with the BT manager if details about remote device are known */ + if (p_inq_info != NULL) { + *p_dev_type = p_inq_info->results.device_type; + *p_addr_type = p_inq_info->results.ble_addr_type; + } else { + /* unknown device, assume BR/EDR */ + BTM_TRACE_DEBUG("btm_find_dev_type - unknown device, BR/EDR assumed"); } - else /* there is a security device record exisitng */ + } else /* there is a security device record exisitng */ + { + /* new inquiry result, overwrite device type in security device record */ + if (p_inq_info) { + p_dev_rec->device_type = p_inq_info->results.device_type; + p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type; + } + if (memcmp(p_dev_rec->bd_addr, remote_bda, BD_ADDR_LEN) == 0 && + memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == 0) { + *p_dev_type = p_dev_rec->device_type; + *p_addr_type = p_dev_rec->ble.ble_addr_type; + } else if (memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == + 0) { + *p_dev_type = BT_DEVICE_TYPE_BLE; + *p_addr_type = p_dev_rec->ble.ble_addr_type; + } else /* matching static adddress only */ { - /* new inquiry result, overwrite device type in security device record */ - if (p_inq_info) - { - p_dev_rec->device_type = p_inq_info->results.device_type; - p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type; - } - if (memcmp(p_dev_rec->bd_addr, remote_bda, BD_ADDR_LEN) == 0 && - memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == 0) - { - *p_dev_type = p_dev_rec->device_type; - *p_addr_type = p_dev_rec->ble.ble_addr_type; - } - else if (memcmp(p_dev_rec->ble.pseudo_addr, remote_bda, BD_ADDR_LEN) == 0) - { - *p_dev_type = BT_DEVICE_TYPE_BLE; - *p_addr_type = p_dev_rec->ble.ble_addr_type; - } - else /* matching static adddress only */ - { - *p_dev_type = BT_DEVICE_TYPE_BREDR; - *p_addr_type = BLE_ADDR_PUBLIC; - } - + *p_dev_type = BT_DEVICE_TYPE_BREDR; + *p_addr_type = BLE_ADDR_PUBLIC; } + } - BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type); + BTM_TRACE_DEBUG("btm_find_dev_type - device_type = %d addr_type = %d", + *p_dev_type, *p_addr_type); } /******************************************************************************* @@ -682,40 +656,33 @@ void BTM_ReadDevInfo (const BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBL * Return true if an active link is identified; false otherwise * ******************************************************************************/ -bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT transport) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(remote_bda); +bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, + tBT_TRANSPORT transport) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(remote_bda); - /* if no device can be located, return */ - if (p_dev_rec == NULL) - return false; + /* if no device can be located, return */ + if (p_dev_rec == NULL) return false; - if (transport == BT_TRANSPORT_BR_EDR) - { - if (btm_bda_to_acl(p_dev_rec->bd_addr, transport) != NULL) - { - memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); - return true; - } - else if (p_dev_rec->device_type & BT_DEVICE_TYPE_BREDR) - { - memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); - } - else - memset(remote_bda, 0, BD_ADDR_LEN); - return false; - } + if (transport == BT_TRANSPORT_BR_EDR) { + if (btm_bda_to_acl(p_dev_rec->bd_addr, transport) != NULL) { + memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); + return true; + } else if (p_dev_rec->device_type & BT_DEVICE_TYPE_BREDR) { + memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); + } else + memset(remote_bda, 0, BD_ADDR_LEN); + return false; + } - if (transport == BT_TRANSPORT_LE) - { - memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); - if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL) - return true; - else - return false; - } + if (transport == BT_TRANSPORT_LE) { + memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); + if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL) + return true; + else + return false; + } - return false; + return false; } /******************************************************************************* @@ -728,11 +695,10 @@ bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT tran * p_cmd_cmpl_cback - Command Complete callback * ******************************************************************************/ -void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback) -{ - btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; +void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB* p_cmd_cmpl_cback) { + btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; - btsnd_hcic_ble_receiver_test(rx_freq); + btsnd_hcic_ble_receiver_test(rx_freq); } /******************************************************************************* @@ -749,10 +715,10 @@ void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback) * ******************************************************************************/ void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len, - uint8_t packet_payload, tBTM_CMPL_CB *p_cmd_cmpl_cback) -{ - btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; - btsnd_hcic_ble_transmitter_test(tx_freq, test_data_len, packet_payload); + uint8_t packet_payload, + tBTM_CMPL_CB* p_cmd_cmpl_cback) { + btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; + btsnd_hcic_ble_transmitter_test(tx_freq, test_data_len, packet_payload); } /******************************************************************************* @@ -765,26 +731,23 @@ void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len, * Parameter p_cmd_cmpl_cback - Command complete callback * ******************************************************************************/ -void BTM_BleTestEnd(tBTM_CMPL_CB *p_cmd_cmpl_cback) -{ - btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; +void BTM_BleTestEnd(tBTM_CMPL_CB* p_cmd_cmpl_cback) { + btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; - btsnd_hcic_ble_test_end(); + btsnd_hcic_ble_test_end(); } /******************************************************************************* * Internal Functions ******************************************************************************/ -void btm_ble_test_command_complete(uint8_t *p) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_le_test_cmd_cmpl_cb; +void btm_ble_test_command_complete(uint8_t* p) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_le_test_cmd_cmpl_cb; - btm_cb.devcb.p_le_test_cmd_cmpl_cb = NULL; + btm_cb.devcb.p_le_test_cmd_cmpl_cb = NULL; - if (p_cb) - { - (*p_cb)(p); - } + if (p_cb) { + (*p_cb)(p); + } } /******************************************************************************* @@ -797,26 +760,25 @@ void btm_ble_test_command_complete(uint8_t *p) * Returns true to use LE, false use BR/EDR. * ******************************************************************************/ -bool BTM_UseLeLink (BD_ADDR bd_addr) -{ - tACL_CONN *p; - tBT_DEVICE_TYPE dev_type; - tBLE_ADDR_TYPE addr_type; - bool use_le = false; +bool BTM_UseLeLink(BD_ADDR bd_addr) { + tACL_CONN* p; + tBT_DEVICE_TYPE dev_type; + tBLE_ADDR_TYPE addr_type; + bool use_le = false; - p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR); + p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR); + if (p != NULL) { + return use_le; + } else { + p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE); if (p != NULL) { - return use_le; + use_le = true; } else { - p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE); - if (p != NULL) { - use_le = true; - } else { - BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); - use_le = (dev_type == BT_DEVICE_TYPE_BLE); - } + BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); + use_le = (dev_type == BT_DEVICE_TYPE_BLE); } - return use_le; + } + return use_le; } /******************************************************************************* @@ -828,40 +790,37 @@ bool BTM_UseLeLink (BD_ADDR bd_addr) * Returns BTM_SUCCESS if success; otherwise failed. * ******************************************************************************/ -tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, uint16_t tx_pdu_length) -{ - tACL_CONN *p_acl = btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE); +tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, uint16_t tx_pdu_length) { + tACL_CONN* p_acl = btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE); - if(p_acl == NULL) - { - BTM_TRACE_ERROR("%s: Wrong mode: no LE link exist or LE not supported",__func__); - return BTM_WRONG_MODE; - } + if (p_acl == NULL) { + BTM_TRACE_ERROR("%s: Wrong mode: no LE link exist or LE not supported", + __func__); + return BTM_WRONG_MODE; + } - BTM_TRACE_DEBUG("%s: tx_pdu_length =%d", __func__, tx_pdu_length); + BTM_TRACE_DEBUG("%s: tx_pdu_length =%d", __func__, tx_pdu_length); - if (!controller_get_interface()->supports_ble_packet_extension()) - { - BTM_TRACE_ERROR("%s failed, request not supported", __func__); - return BTM_ILLEGAL_VALUE; - } + if (!controller_get_interface()->supports_ble_packet_extension()) { + BTM_TRACE_ERROR("%s failed, request not supported", __func__); + return BTM_ILLEGAL_VALUE; + } - if (!HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl->peer_le_features)) - { - BTM_TRACE_ERROR("%s failed, peer does not support request", __func__); - return BTM_ILLEGAL_VALUE; - } + if (!HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl->peer_le_features)) { + BTM_TRACE_ERROR("%s failed, peer does not support request", __func__); + return BTM_ILLEGAL_VALUE; + } - if (tx_pdu_length > BTM_BLE_DATA_SIZE_MAX) - tx_pdu_length = BTM_BLE_DATA_SIZE_MAX; - else if (tx_pdu_length < BTM_BLE_DATA_SIZE_MIN) - tx_pdu_length = BTM_BLE_DATA_SIZE_MIN; + if (tx_pdu_length > BTM_BLE_DATA_SIZE_MAX) + tx_pdu_length = BTM_BLE_DATA_SIZE_MAX; + else if (tx_pdu_length < BTM_BLE_DATA_SIZE_MIN) + tx_pdu_length = BTM_BLE_DATA_SIZE_MIN; - /* always set the TxTime to be max, as controller does not care for now */ - btsnd_hcic_ble_set_data_length(p_acl->hci_handle, tx_pdu_length, - BTM_BLE_DATA_TX_TIME_MAX); + /* always set the TxTime to be max, as controller does not care for now */ + btsnd_hcic_ble_set_data_length(p_acl->hci_handle, tx_pdu_length, + BTM_BLE_DATA_TX_TIME_MAX); - return BTM_SUCCESS; + return BTM_SUCCESS; } /******************************************************************************* @@ -879,78 +838,68 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, uint16_t tx_pdu_length) * Returns The appropriate security action required. * ******************************************************************************/ -tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator, BD_ADDR bdaddr, uint16_t security_required) -{ - tBTM_LE_AUTH_REQ auth_req = 0x00; - - if (is_originator) - { - if ((security_required & BTM_SEC_OUT_FLAGS) == 0 && - (security_required & BTM_SEC_OUT_MITM) == 0) - { - BTM_TRACE_DEBUG ("%s No security required for outgoing connection", __func__); - return BTM_SEC_OK; - } +tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator, + BD_ADDR bdaddr, + uint16_t security_required) { + tBTM_LE_AUTH_REQ auth_req = 0x00; - if (security_required & BTM_SEC_OUT_MITM) - auth_req |= BTM_LE_AUTH_REQ_MITM; + if (is_originator) { + if ((security_required & BTM_SEC_OUT_FLAGS) == 0 && + (security_required & BTM_SEC_OUT_MITM) == 0) { + BTM_TRACE_DEBUG("%s No security required for outgoing connection", + __func__); + return BTM_SEC_OK; } - else - { - if ((security_required & BTM_SEC_IN_FLAGS) == 0&& (security_required & BTM_SEC_IN_MITM) == 0) - { - BTM_TRACE_DEBUG ("%s No security required for incoming connection", __func__); - return BTM_SEC_OK; - } - if (security_required & BTM_SEC_IN_MITM) - auth_req |= BTM_LE_AUTH_REQ_MITM; + if (security_required & BTM_SEC_OUT_MITM) auth_req |= BTM_LE_AUTH_REQ_MITM; + } else { + if ((security_required & BTM_SEC_IN_FLAGS) == 0 && + (security_required & BTM_SEC_IN_MITM) == 0) { + BTM_TRACE_DEBUG("%s No security required for incoming connection", + __func__); + return BTM_SEC_OK; } - tBTM_BLE_SEC_REQ_ACT ble_sec_act; - btm_ble_link_sec_check(bdaddr, auth_req, &ble_sec_act); + if (security_required & BTM_SEC_IN_MITM) auth_req |= BTM_LE_AUTH_REQ_MITM; + } - BTM_TRACE_DEBUG ("%s ble_sec_act %d", __func__ , ble_sec_act); + tBTM_BLE_SEC_REQ_ACT ble_sec_act; + btm_ble_link_sec_check(bdaddr, auth_req, &ble_sec_act); - if (ble_sec_act == BTM_BLE_SEC_REQ_ACT_DISCARD) - return BTM_SEC_ENC_PENDING; + BTM_TRACE_DEBUG("%s ble_sec_act %d", __func__, ble_sec_act); - if (ble_sec_act == BTM_BLE_SEC_REQ_ACT_NONE) - return BTM_SEC_OK; + if (ble_sec_act == BTM_BLE_SEC_REQ_ACT_DISCARD) return BTM_SEC_ENC_PENDING; - uint8_t sec_flag = 0; - BTM_GetSecurityFlagsByTransport(bdaddr, &sec_flag, BT_TRANSPORT_LE); + if (ble_sec_act == BTM_BLE_SEC_REQ_ACT_NONE) return BTM_SEC_OK; - bool is_link_encrypted = false; - bool is_key_mitm = false; - if (sec_flag & (BTM_SEC_FLAG_ENCRYPTED| BTM_SEC_FLAG_LKEY_KNOWN)) - { - if (sec_flag & BTM_SEC_FLAG_ENCRYPTED) - is_link_encrypted = true; + uint8_t sec_flag = 0; + BTM_GetSecurityFlagsByTransport(bdaddr, &sec_flag, BT_TRANSPORT_LE); - if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) - is_key_mitm = true; - } + bool is_link_encrypted = false; + bool is_key_mitm = false; + if (sec_flag & (BTM_SEC_FLAG_ENCRYPTED | BTM_SEC_FLAG_LKEY_KNOWN)) { + if (sec_flag & BTM_SEC_FLAG_ENCRYPTED) is_link_encrypted = true; - if (auth_req & BTM_LE_AUTH_REQ_MITM) - { - if (!is_key_mitm) - { - return BTM_SEC_ENCRYPT_MITM; - } else { - if (is_link_encrypted) - return BTM_SEC_OK; - else - return BTM_SEC_ENCRYPT; - } + if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) is_key_mitm = true; + } + + if (auth_req & BTM_LE_AUTH_REQ_MITM) { + if (!is_key_mitm) { + return BTM_SEC_ENCRYPT_MITM; } else { - if (is_link_encrypted) - return BTM_SEC_OK; - else - return BTM_SEC_ENCRYPT_NO_MITM; + if (is_link_encrypted) + return BTM_SEC_OK; + else + return BTM_SEC_ENCRYPT; } + } else { + if (is_link_encrypted) + return BTM_SEC_OK; + else + return BTM_SEC_ENCRYPT_NO_MITM; + } - return BTM_SEC_OK; + return BTM_SEC_OK; } /******************************************************************************* @@ -970,62 +919,60 @@ tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator, BD_ADDR bd * false. * ******************************************************************************/ -bool btm_ble_start_sec_check(BD_ADDR bd_addr, uint16_t psm, bool is_originator, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data) -{ - /* Find the service record for the PSM */ - tBTM_SEC_SERV_REC *p_serv_rec = btm_sec_find_first_serv (is_originator, psm); +bool btm_ble_start_sec_check(BD_ADDR bd_addr, uint16_t psm, bool is_originator, + tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { + /* Find the service record for the PSM */ + tBTM_SEC_SERV_REC* p_serv_rec = btm_sec_find_first_serv(is_originator, psm); - /* If there is no application registered with this PSM do not allow connection */ - if (!p_serv_rec) - { - BTM_TRACE_WARNING ("%s PSM: %d no application registerd", __func__, psm); - (*p_callback) (bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_MODE_UNSUPPORTED); - return false; - } + /* If there is no application registered with this PSM do not allow connection + */ + if (!p_serv_rec) { + BTM_TRACE_WARNING("%s PSM: %d no application registerd", __func__, psm); + (*p_callback)(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_MODE_UNSUPPORTED); + return false; + } - tBTM_SEC_ACTION sec_act = btm_ble_determine_security_act(is_originator, - bd_addr, p_serv_rec->security_flags); + tBTM_SEC_ACTION sec_act = btm_ble_determine_security_act( + is_originator, bd_addr, p_serv_rec->security_flags); - tBTM_BLE_SEC_ACT ble_sec_act = BTM_BLE_SEC_NONE; - bool status = false; + tBTM_BLE_SEC_ACT ble_sec_act = BTM_BLE_SEC_NONE; + bool status = false; - switch (sec_act) - { - case BTM_SEC_OK: - BTM_TRACE_DEBUG ("%s Security met", __func__); - p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_SUCCESS); - status = true; - break; - - case BTM_SEC_ENCRYPT: - BTM_TRACE_DEBUG ("%s Encryption needs to be done", __func__); - ble_sec_act = BTM_BLE_SEC_ENCRYPT; - break; - - case BTM_SEC_ENCRYPT_MITM: - BTM_TRACE_DEBUG ("%s Pairing with MITM needs to be done", __func__); - ble_sec_act = BTM_BLE_SEC_ENCRYPT_MITM; - break; - - case BTM_SEC_ENCRYPT_NO_MITM: - BTM_TRACE_DEBUG ("%s Pairing with No MITM needs to be done", __func__); - ble_sec_act = BTM_BLE_SEC_ENCRYPT_NO_MITM; - break; - - case BTM_SEC_ENC_PENDING: - BTM_TRACE_DEBUG ("%s Ecryption pending", __func__); - break; - } + switch (sec_act) { + case BTM_SEC_OK: + BTM_TRACE_DEBUG("%s Security met", __func__); + p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_SUCCESS); + status = true; + break; - if (ble_sec_act == BTM_BLE_SEC_NONE) - return status; + case BTM_SEC_ENCRYPT: + BTM_TRACE_DEBUG("%s Encryption needs to be done", __func__); + ble_sec_act = BTM_BLE_SEC_ENCRYPT; + break; - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); - p_lcb->sec_act = sec_act; - BTM_SetEncryption(bd_addr, BT_TRANSPORT_LE, p_callback, p_ref_data, ble_sec_act); + case BTM_SEC_ENCRYPT_MITM: + BTM_TRACE_DEBUG("%s Pairing with MITM needs to be done", __func__); + ble_sec_act = BTM_BLE_SEC_ENCRYPT_MITM; + break; - return false; + case BTM_SEC_ENCRYPT_NO_MITM: + BTM_TRACE_DEBUG("%s Pairing with No MITM needs to be done", __func__); + ble_sec_act = BTM_BLE_SEC_ENCRYPT_NO_MITM; + break; + + case BTM_SEC_ENC_PENDING: + BTM_TRACE_DEBUG("%s Ecryption pending", __func__); + break; + } + + if (ble_sec_act == BTM_BLE_SEC_NONE) return status; + + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); + p_lcb->sec_act = sec_act; + BTM_SetEncryption(bd_addr, BT_TRANSPORT_LE, p_callback, p_ref_data, + ble_sec_act); + + return false; } /******************************************************************************* @@ -1039,37 +986,34 @@ bool btm_ble_start_sec_check(BD_ADDR bd_addr, uint16_t psm, bool is_origin * Returns void * ******************************************************************************/ -void btm_ble_rand_enc_complete (uint8_t *p, uint16_t op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback) -{ - tBTM_RAND_ENC params; - uint8_t *p_dest = params.param_buf; +void btm_ble_rand_enc_complete(uint8_t* p, uint16_t op_code, + tBTM_RAND_ENC_CB* p_enc_cplt_cback) { + tBTM_RAND_ENC params; + uint8_t* p_dest = params.param_buf; - BTM_TRACE_DEBUG ("btm_ble_rand_enc_complete"); + BTM_TRACE_DEBUG("btm_ble_rand_enc_complete"); - memset(¶ms, 0, sizeof(tBTM_RAND_ENC)); + memset(¶ms, 0, sizeof(tBTM_RAND_ENC)); - /* If there was a callback address for vcs complete, call it */ - if (p_enc_cplt_cback && p) - { - /* Pass paramters to the callback function */ - STREAM_TO_UINT8(params.status, p); /* command status */ + /* If there was a callback address for vcs complete, call it */ + if (p_enc_cplt_cback && p) { + /* Pass paramters to the callback function */ + STREAM_TO_UINT8(params.status, p); /* command status */ - if (params.status == HCI_SUCCESS) - { - params.opcode = op_code; + if (params.status == HCI_SUCCESS) { + params.opcode = op_code; - if (op_code == HCI_BLE_RAND) - params.param_len = BT_OCTET8_LEN; - else - params.param_len = BT_OCTET16_LEN; + if (op_code == HCI_BLE_RAND) + params.param_len = BT_OCTET8_LEN; + else + params.param_len = BT_OCTET16_LEN; - /* Fetch return info from HCI event message */ - memcpy(p_dest, p, params.param_len); - } - if (p_enc_cplt_cback) - /* Call the Encryption complete callback function */ - (*p_enc_cplt_cback)(¶ms); + /* Fetch return info from HCI event message */ + memcpy(p_dest, p, params.param_len); } + if (p_enc_cplt_cback) /* Call the Encryption complete callback function */ + (*p_enc_cplt_cback)(¶ms); + } } /******************************************************************************* @@ -1080,24 +1024,21 @@ void btm_ble_rand_enc_complete (uint8_t *p, uint16_t op_code, tBTM_RAND_ENC_CB * * Returns None * ******************************************************************************/ -void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, bool is_local ) -{ - tBTM_SEC_DEV_REC *p_dev_rec; +void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, bool is_local) { + tBTM_SEC_DEV_REC* p_dev_rec; - BTM_TRACE_DEBUG ("btm_ble_increment_sign_ctr is_local=%d", is_local); + BTM_TRACE_DEBUG("btm_ble_increment_sign_ctr is_local=%d", is_local); - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) - { - if (is_local) - p_dev_rec->ble.keys.local_counter++; - else - p_dev_rec->ble.keys.counter++; - BTM_TRACE_DEBUG ("is_local=%d local sign counter=%d peer sign counter=%d", - is_local, - p_dev_rec->ble.keys.local_counter, - p_dev_rec->ble.keys.counter); - } + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + if (is_local) + p_dev_rec->ble.keys.local_counter++; + else + p_dev_rec->ble.keys.counter++; + BTM_TRACE_DEBUG("is_local=%d local sign counter=%d peer sign counter=%d", + is_local, p_dev_rec->ble.keys.local_counter, + p_dev_rec->ble.keys.counter); + } } /******************************************************************************* @@ -1110,19 +1051,17 @@ void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, bool is_local ) * Returns p_key_type: output parameter to carry the key type value. * ******************************************************************************/ -bool btm_ble_get_enc_key_type(BD_ADDR bd_addr, uint8_t *p_key_types) -{ - tBTM_SEC_DEV_REC *p_dev_rec; +bool btm_ble_get_enc_key_type(BD_ADDR bd_addr, uint8_t* p_key_types) { + tBTM_SEC_DEV_REC* p_dev_rec; - BTM_TRACE_DEBUG ("btm_ble_get_enc_key_type"); + BTM_TRACE_DEBUG("btm_ble_get_enc_key_type"); - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) - { - *p_key_types = p_dev_rec->ble.key_type; - return true; - } - return false; + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + *p_key_types = p_dev_rec->ble.key_type; + return true; + } + return false; } /******************************************************************************* @@ -1133,27 +1072,24 @@ bool btm_ble_get_enc_key_type(BD_ADDR bd_addr, uint8_t *p_key_types) * * Returns TURE - if a valid DIV is availavle ******************************************************************************/ -bool btm_get_local_div (BD_ADDR bd_addr, uint16_t *p_div) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - bool status = false; - BTM_TRACE_DEBUG ("btm_get_local_div"); +bool btm_get_local_div(BD_ADDR bd_addr, uint16_t* p_div) { + tBTM_SEC_DEV_REC* p_dev_rec; + bool status = false; + BTM_TRACE_DEBUG("btm_get_local_div"); - BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0],bd_addr[1], - bd_addr[2],bd_addr[3], - bd_addr[4],bd_addr[5]); + BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", bd_addr[0], + bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - *p_div = 0; - p_dev_rec = btm_find_dev (bd_addr); + *p_div = 0; + p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec && p_dev_rec->ble.keys.div) - { - status = true; - *p_div = p_dev_rec->ble.keys.div; - } - BTM_TRACE_DEBUG ("btm_get_local_div status=%d (1-OK) DIV=0x%x", status, *p_div); - return status; + if (p_dev_rec && p_dev_rec->ble.keys.div) { + status = true; + *p_div = p_dev_rec->ble.keys.div; + } + BTM_TRACE_DEBUG("btm_get_local_div status=%d (1-OK) DIV=0x%x", status, + *p_div); + return status; } /******************************************************************************* @@ -1170,139 +1106,142 @@ bool btm_get_local_div (BD_ADDR bd_addr, uint16_t *p_div) * Returns void * ******************************************************************************/ -void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, - bool pass_to_application) -{ - tBTM_SEC_DEV_REC *p_rec; - tBTM_LE_EVT_DATA cb_data; - uint8_t i; - - BTM_TRACE_DEBUG ("btm_sec_save_le_key key_type=0x%x pass_to_application=%d",key_type, pass_to_application); - /* Store the updated key in the device database */ - - BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0],bd_addr[1], - bd_addr[2],bd_addr[3], - bd_addr[4],bd_addr[5]); - - if ((p_rec = btm_find_dev (bd_addr)) != NULL && (p_keys || key_type== BTM_LE_KEY_LID)) - { - btm_ble_init_pseudo_addr (p_rec, bd_addr); - - switch (key_type) - { - case BTM_LE_KEY_PENC: - memcpy(p_rec->ble.keys.pltk, p_keys->penc_key.ltk, BT_OCTET16_LEN); - memcpy(p_rec->ble.keys.rand, p_keys->penc_key.rand, BT_OCTET8_LEN); - p_rec->ble.keys.sec_level = p_keys->penc_key.sec_level; - p_rec->ble.keys.ediv = p_keys->penc_key.ediv; - p_rec->ble.keys.key_size = p_keys->penc_key.key_size; - p_rec->ble.key_type |= BTM_LE_KEY_PENC; - p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; - if (p_keys->penc_key.sec_level == SMP_SEC_AUTHENTICATED) - p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; - else - p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; - BTM_TRACE_DEBUG("BTM_LE_KEY_PENC key_type=0x%x sec_flags=0x%x sec_leve=0x%x", - p_rec->ble.key_type, - p_rec->sec_flags, - p_rec->ble.keys.sec_level); - break; - - case BTM_LE_KEY_PID: - for (i=0; ible.keys.irk[i] = p_keys->pid_key.irk[i]; - } - - //memcpy( p_rec->ble.keys.irk, p_keys->pid_key, BT_OCTET16_LEN); todo will crash the system - memcpy(p_rec->ble.static_addr, p_keys->pid_key.static_addr, BD_ADDR_LEN); - p_rec->ble.static_addr_type = p_keys->pid_key.addr_type; - p_rec->ble.key_type |= BTM_LE_KEY_PID; - BTM_TRACE_DEBUG("BTM_LE_KEY_PID key_type=0x%x save peer IRK", p_rec->ble.key_type); - /* update device record address as static address */ - memcpy(p_rec->bd_addr, p_keys->pid_key.static_addr, BD_ADDR_LEN); - /* combine DUMO device security record if needed */ - btm_consolidate_dev(p_rec); - break; - - case BTM_LE_KEY_PCSRK: - memcpy(p_rec->ble.keys.pcsrk, p_keys->pcsrk_key.csrk, BT_OCTET16_LEN); - p_rec->ble.keys.srk_sec_level = p_keys->pcsrk_key.sec_level; - p_rec->ble.keys.counter = p_keys->pcsrk_key.counter; - p_rec->ble.key_type |= BTM_LE_KEY_PCSRK; - p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; - if ( p_keys->pcsrk_key.sec_level== SMP_SEC_AUTHENTICATED) - p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; - else - p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; - - BTM_TRACE_DEBUG("BTM_LE_KEY_PCSRK key_type=0x%x sec_flags=0x%x sec_level=0x%x peer_counter=%d", - p_rec->ble.key_type, - p_rec->sec_flags, - p_rec->ble.keys.srk_sec_level, - p_rec->ble.keys.counter ); - break; - - case BTM_LE_KEY_LENC: - memcpy(p_rec->ble.keys.lltk, p_keys->lenc_key.ltk, BT_OCTET16_LEN); - p_rec->ble.keys.div = p_keys->lenc_key.div; /* update DIV */ - p_rec->ble.keys.sec_level = p_keys->lenc_key.sec_level; - p_rec->ble.keys.key_size = p_keys->lenc_key.key_size; - p_rec->ble.key_type |= BTM_LE_KEY_LENC; - - BTM_TRACE_DEBUG("BTM_LE_KEY_LENC key_type=0x%x DIV=0x%x key_size=0x%x sec_level=0x%x", - p_rec->ble.key_type, - p_rec->ble.keys.div, - p_rec->ble.keys.key_size, - p_rec->ble.keys.sec_level ); - break; - - case BTM_LE_KEY_LCSRK:/* local CSRK has been delivered */ - memcpy (p_rec->ble.keys.lcsrk, p_keys->lcsrk_key.csrk, BT_OCTET16_LEN); - p_rec->ble.keys.div = p_keys->lcsrk_key.div; /* update DIV */ - p_rec->ble.keys.local_csrk_sec_level = p_keys->lcsrk_key.sec_level; - p_rec->ble.keys.local_counter = p_keys->lcsrk_key.counter; - p_rec->ble.key_type |= BTM_LE_KEY_LCSRK; - BTM_TRACE_DEBUG("BTM_LE_KEY_LCSRK key_type=0x%x DIV=0x%x scrk_sec_level=0x%x local_counter=%d", - p_rec->ble.key_type, - p_rec->ble.keys.div, - p_rec->ble.keys.local_csrk_sec_level, - p_rec->ble.keys.local_counter ); - break; - - case BTM_LE_KEY_LID: - p_rec->ble.key_type |= BTM_LE_KEY_LID; - break; - default: - BTM_TRACE_WARNING("btm_sec_save_le_key (Bad key_type 0x%02x)", key_type); - return; +void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, + tBTM_LE_KEY_VALUE* p_keys, bool pass_to_application) { + tBTM_SEC_DEV_REC* p_rec; + tBTM_LE_EVT_DATA cb_data; + uint8_t i; + + BTM_TRACE_DEBUG("btm_sec_save_le_key key_type=0x%x pass_to_application=%d", + key_type, pass_to_application); + /* Store the updated key in the device database */ + + BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", bd_addr[0], + bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + + if ((p_rec = btm_find_dev(bd_addr)) != NULL && + (p_keys || key_type == BTM_LE_KEY_LID)) { + btm_ble_init_pseudo_addr(p_rec, bd_addr); + + switch (key_type) { + case BTM_LE_KEY_PENC: + memcpy(p_rec->ble.keys.pltk, p_keys->penc_key.ltk, BT_OCTET16_LEN); + memcpy(p_rec->ble.keys.rand, p_keys->penc_key.rand, BT_OCTET8_LEN); + p_rec->ble.keys.sec_level = p_keys->penc_key.sec_level; + p_rec->ble.keys.ediv = p_keys->penc_key.ediv; + p_rec->ble.keys.key_size = p_keys->penc_key.key_size; + p_rec->ble.key_type |= BTM_LE_KEY_PENC; + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; + if (p_keys->penc_key.sec_level == SMP_SEC_AUTHENTICATED) + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; + else + p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; + BTM_TRACE_DEBUG( + "BTM_LE_KEY_PENC key_type=0x%x sec_flags=0x%x sec_leve=0x%x", + p_rec->ble.key_type, p_rec->sec_flags, p_rec->ble.keys.sec_level); + break; + + case BTM_LE_KEY_PID: + for (i = 0; i < BT_OCTET16_LEN; i++) { + p_rec->ble.keys.irk[i] = p_keys->pid_key.irk[i]; } - BTM_TRACE_DEBUG ("BLE key type 0x%02x updated for BDA: %08x%04x (btm_sec_save_le_key)", key_type, - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5]); - - /* Notify the application that one of the BLE keys has been updated - If link key is in progress, it will get sent later.*/ - if (pass_to_application && btm_cb.api.p_le_callback) - { - cb_data.key.p_key_value = p_keys; - cb_data.key.key_type = key_type; - - (*btm_cb.api.p_le_callback) (BTM_LE_KEY_EVT, bd_addr, &cb_data); - } + // memcpy( p_rec->ble.keys.irk, p_keys->pid_key, BT_OCTET16_LEN); todo + // will crash the system + memcpy(p_rec->ble.static_addr, p_keys->pid_key.static_addr, + BD_ADDR_LEN); + p_rec->ble.static_addr_type = p_keys->pid_key.addr_type; + p_rec->ble.key_type |= BTM_LE_KEY_PID; + BTM_TRACE_DEBUG("BTM_LE_KEY_PID key_type=0x%x save peer IRK", + p_rec->ble.key_type); + /* update device record address as static address */ + memcpy(p_rec->bd_addr, p_keys->pid_key.static_addr, BD_ADDR_LEN); + /* combine DUMO device security record if needed */ + btm_consolidate_dev(p_rec); + break; + + case BTM_LE_KEY_PCSRK: + memcpy(p_rec->ble.keys.pcsrk, p_keys->pcsrk_key.csrk, BT_OCTET16_LEN); + p_rec->ble.keys.srk_sec_level = p_keys->pcsrk_key.sec_level; + p_rec->ble.keys.counter = p_keys->pcsrk_key.counter; + p_rec->ble.key_type |= BTM_LE_KEY_PCSRK; + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; + if (p_keys->pcsrk_key.sec_level == SMP_SEC_AUTHENTICATED) + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; + else + p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; + + BTM_TRACE_DEBUG( + "BTM_LE_KEY_PCSRK key_type=0x%x sec_flags=0x%x sec_level=0x%x " + "peer_counter=%d", + p_rec->ble.key_type, p_rec->sec_flags, + p_rec->ble.keys.srk_sec_level, p_rec->ble.keys.counter); + break; + + case BTM_LE_KEY_LENC: + memcpy(p_rec->ble.keys.lltk, p_keys->lenc_key.ltk, BT_OCTET16_LEN); + p_rec->ble.keys.div = p_keys->lenc_key.div; /* update DIV */ + p_rec->ble.keys.sec_level = p_keys->lenc_key.sec_level; + p_rec->ble.keys.key_size = p_keys->lenc_key.key_size; + p_rec->ble.key_type |= BTM_LE_KEY_LENC; + + BTM_TRACE_DEBUG( + "BTM_LE_KEY_LENC key_type=0x%x DIV=0x%x key_size=0x%x " + "sec_level=0x%x", + p_rec->ble.key_type, p_rec->ble.keys.div, p_rec->ble.keys.key_size, + p_rec->ble.keys.sec_level); + break; + + case BTM_LE_KEY_LCSRK: /* local CSRK has been delivered */ + memcpy(p_rec->ble.keys.lcsrk, p_keys->lcsrk_key.csrk, BT_OCTET16_LEN); + p_rec->ble.keys.div = p_keys->lcsrk_key.div; /* update DIV */ + p_rec->ble.keys.local_csrk_sec_level = p_keys->lcsrk_key.sec_level; + p_rec->ble.keys.local_counter = p_keys->lcsrk_key.counter; + p_rec->ble.key_type |= BTM_LE_KEY_LCSRK; + BTM_TRACE_DEBUG( + "BTM_LE_KEY_LCSRK key_type=0x%x DIV=0x%x scrk_sec_level=0x%x " + "local_counter=%d", + p_rec->ble.key_type, p_rec->ble.keys.div, + p_rec->ble.keys.local_csrk_sec_level, + p_rec->ble.keys.local_counter); + break; + + case BTM_LE_KEY_LID: + p_rec->ble.key_type |= BTM_LE_KEY_LID; + break; + default: + BTM_TRACE_WARNING("btm_sec_save_le_key (Bad key_type 0x%02x)", + key_type); return; } - BTM_TRACE_WARNING ("BLE key type 0x%02x called for Unknown BDA or type: %08x%04x !! (btm_sec_save_le_key)", key_type, - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5]); + BTM_TRACE_DEBUG( + "BLE key type 0x%02x updated for BDA: %08x%04x (btm_sec_save_le_key)", + key_type, (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); - if (p_rec) - { - BTM_TRACE_DEBUG ("sec_flags=0x%x", p_rec->sec_flags); + /* Notify the application that one of the BLE keys has been updated + If link key is in progress, it will get sent later.*/ + if (pass_to_application && btm_cb.api.p_le_callback) { + cb_data.key.p_key_value = p_keys; + cb_data.key.key_type = key_type; + + (*btm_cb.api.p_le_callback)(BTM_LE_KEY_EVT, bd_addr, &cb_data); } + return; + } + + BTM_TRACE_WARNING( + "BLE key type 0x%02x called for Unknown BDA or type: %08x%04x !! " + "(btm_sec_save_le_key)", + key_type, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + + if (p_rec) { + BTM_TRACE_DEBUG("sec_flags=0x%x", p_rec->sec_flags); + } } /******************************************************************************* @@ -1314,17 +1253,16 @@ void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY * Returns void * ******************************************************************************/ -void btm_ble_update_sec_key_size(BD_ADDR bd_addr, uint8_t enc_key_size) -{ - tBTM_SEC_DEV_REC *p_rec; +void btm_ble_update_sec_key_size(BD_ADDR bd_addr, uint8_t enc_key_size) { + tBTM_SEC_DEV_REC* p_rec; - BTM_TRACE_DEBUG("btm_ble_update_sec_key_size enc_key_size = %d", enc_key_size); + BTM_TRACE_DEBUG("btm_ble_update_sec_key_size enc_key_size = %d", + enc_key_size); - p_rec = btm_find_dev(bd_addr); - if (p_rec != NULL ) - { - p_rec->enc_key_size = enc_key_size; - } + p_rec = btm_find_dev(bd_addr); + if (p_rec != NULL) { + p_rec->enc_key_size = enc_key_size; + } } /******************************************************************************* @@ -1336,17 +1274,14 @@ void btm_ble_update_sec_key_size(BD_ADDR bd_addr, uint8_t enc_key_size) * Returns void * ******************************************************************************/ -uint8_t btm_ble_read_sec_key_size(BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_rec; +uint8_t btm_ble_read_sec_key_size(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_rec; - p_rec = btm_find_dev(bd_addr); - if (p_rec != NULL ) - { - return p_rec->enc_key_size; - } - else - return 0; + p_rec = btm_find_dev(bd_addr); + if (p_rec != NULL) { + return p_rec->enc_key_size; + } else + return 0; } /******************************************************************************* @@ -1358,69 +1293,58 @@ uint8_t btm_ble_read_sec_key_size(BD_ADDR bd_addr) * Returns true: check is OK and the *p_sec_req_act contain the action * ******************************************************************************/ -void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE_SEC_REQ_ACT *p_sec_req_act) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - uint8_t req_sec_level = BTM_LE_SEC_NONE, cur_sec_level = BTM_LE_SEC_NONE; - - BTM_TRACE_DEBUG ("btm_ble_link_sec_check auth_req =0x%x", auth_req); +void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, + tBTM_BLE_SEC_REQ_ACT* p_sec_req_act) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + uint8_t req_sec_level = BTM_LE_SEC_NONE, cur_sec_level = BTM_LE_SEC_NONE; - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR ("btm_ble_link_sec_check received for unknown device"); - return; - } + BTM_TRACE_DEBUG("btm_ble_link_sec_check auth_req =0x%x", auth_req); - if (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || - p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) - { - /* race condition: discard the security request while master is encrypting the link */ - *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; - } - else - { - req_sec_level = BTM_LE_SEC_UNAUTHENTICATE; - if (auth_req & BTM_LE_AUTH_REQ_MITM) - { - req_sec_level = BTM_LE_SEC_AUTHENTICATED; - } - - BTM_TRACE_DEBUG ("dev_rec sec_flags=0x%x", p_dev_rec->sec_flags); - - /* currently encrpted */ - if (p_dev_rec->sec_flags & BTM_SEC_LE_ENCRYPTED) - { - if (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED) - cur_sec_level = BTM_LE_SEC_AUTHENTICATED; - else - cur_sec_level = BTM_LE_SEC_UNAUTHENTICATE; - } - else /* unencrypted link */ - { - /* if bonded, get the key security level */ - if (p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) - cur_sec_level = p_dev_rec->ble.keys.sec_level; - else - cur_sec_level = BTM_LE_SEC_NONE; - } - - if (cur_sec_level >= req_sec_level) - { - /* To avoid re-encryption on an encrypted link for an equal condition encryption */ - *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_ENCRYPT; - } - else - { - /* start the pariring process to upgrade the keys*/ - *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_PAIR; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("btm_ble_link_sec_check received for unknown device"); + return; + } + + if (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || + p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) { + /* race condition: discard the security request while master is encrypting + * the link */ + *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; + } else { + req_sec_level = BTM_LE_SEC_UNAUTHENTICATE; + if (auth_req & BTM_LE_AUTH_REQ_MITM) { + req_sec_level = BTM_LE_SEC_AUTHENTICATED; + } + + BTM_TRACE_DEBUG("dev_rec sec_flags=0x%x", p_dev_rec->sec_flags); + + /* currently encrpted */ + if (p_dev_rec->sec_flags & BTM_SEC_LE_ENCRYPTED) { + if (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED) + cur_sec_level = BTM_LE_SEC_AUTHENTICATED; + else + cur_sec_level = BTM_LE_SEC_UNAUTHENTICATE; + } else /* unencrypted link */ + { + /* if bonded, get the key security level */ + if (p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) + cur_sec_level = p_dev_rec->ble.keys.sec_level; + else + cur_sec_level = BTM_LE_SEC_NONE; + } + + if (cur_sec_level >= req_sec_level) { + /* To avoid re-encryption on an encrypted link for an equal condition + * encryption */ + *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_ENCRYPT; + } else { + /* start the pariring process to upgrade the keys*/ + *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_PAIR; } + } - BTM_TRACE_DEBUG("cur_sec_level=%d req_sec_level=%d sec_req_act=%d", - cur_sec_level, - req_sec_level, - *p_sec_req_act); - + BTM_TRACE_DEBUG("cur_sec_level=%d req_sec_level=%d sec_req_act=%d", + cur_sec_level, req_sec_level, *p_sec_req_act); } /******************************************************************************* @@ -1436,70 +1360,65 @@ void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE * the local device ER is copied into er * ******************************************************************************/ -tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, tBTM_BLE_SEC_ACT sec_act, uint8_t link_role) -{ - tBTM_STATUS cmd = BTM_NO_RESOURCES; - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); - tBTM_BLE_SEC_REQ_ACT sec_req_act; - tBTM_LE_AUTH_REQ auth_req; - - if (p_rec == NULL) - { - BTM_TRACE_WARNING ("btm_ble_set_encryption (NULL device record!! sec_act=0x%x", sec_act); - return(BTM_WRONG_MODE); - } - - BTM_TRACE_DEBUG ("btm_ble_set_encryption sec_act=0x%x role_master=%d", sec_act, p_rec->role_master); - - if (sec_act == BTM_BLE_SEC_ENCRYPT_MITM) - { - p_rec->security_required |= BTM_SEC_IN_MITM; - } +tBTM_STATUS btm_ble_set_encryption(BD_ADDR bd_addr, tBTM_BLE_SEC_ACT sec_act, + uint8_t link_role) { + tBTM_STATUS cmd = BTM_NO_RESOURCES; + tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bd_addr); + tBTM_BLE_SEC_REQ_ACT sec_req_act; + tBTM_LE_AUTH_REQ auth_req; + + if (p_rec == NULL) { + BTM_TRACE_WARNING( + "btm_ble_set_encryption (NULL device record!! sec_act=0x%x", sec_act); + return (BTM_WRONG_MODE); + } + + BTM_TRACE_DEBUG("btm_ble_set_encryption sec_act=0x%x role_master=%d", sec_act, + p_rec->role_master); + + if (sec_act == BTM_BLE_SEC_ENCRYPT_MITM) { + p_rec->security_required |= BTM_SEC_IN_MITM; + } + + switch (sec_act) { + case BTM_BLE_SEC_ENCRYPT: + if (link_role == BTM_ROLE_MASTER) { + /* start link layer encryption using the security info stored */ + cmd = btm_ble_start_encrypt(bd_addr, false, NULL); + break; + } + /* if salve role then fall through to call SMP_Pair below which will send a + sec_request to request the master to encrypt the link */ + case BTM_BLE_SEC_ENCRYPT_NO_MITM: + case BTM_BLE_SEC_ENCRYPT_MITM: + auth_req = (sec_act == BTM_BLE_SEC_ENCRYPT_NO_MITM) + ? SMP_AUTH_GEN_BOND + : (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT); + btm_ble_link_sec_check(bd_addr, auth_req, &sec_req_act); + if (sec_req_act == BTM_BLE_SEC_REQ_ACT_NONE || + sec_req_act == BTM_BLE_SEC_REQ_ACT_DISCARD) { + BTM_TRACE_DEBUG("%s, no action needed. Ignore", __func__); + cmd = BTM_SUCCESS; + break; + } + if (link_role == BTM_ROLE_MASTER) { + if (sec_req_act == BTM_BLE_SEC_REQ_ACT_ENCRYPT) { + cmd = btm_ble_start_encrypt(bd_addr, false, NULL); + break; + } + } - switch (sec_act) - { - case BTM_BLE_SEC_ENCRYPT: - if (link_role == BTM_ROLE_MASTER) - { - /* start link layer encryption using the security info stored */ - cmd = btm_ble_start_encrypt(bd_addr, false, NULL); - break; - } - /* if salve role then fall through to call SMP_Pair below which will send a - sec_request to request the master to encrypt the link */ - case BTM_BLE_SEC_ENCRYPT_NO_MITM: - case BTM_BLE_SEC_ENCRYPT_MITM: - auth_req = (sec_act == BTM_BLE_SEC_ENCRYPT_NO_MITM) - ? SMP_AUTH_GEN_BOND : (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT); - btm_ble_link_sec_check (bd_addr, auth_req, &sec_req_act); - if(sec_req_act == BTM_BLE_SEC_REQ_ACT_NONE || sec_req_act == BTM_BLE_SEC_REQ_ACT_DISCARD) - { - BTM_TRACE_DEBUG("%s, no action needed. Ignore", __func__); - cmd = BTM_SUCCESS; - break; - } - if (link_role == BTM_ROLE_MASTER) - { - - if (sec_req_act == BTM_BLE_SEC_REQ_ACT_ENCRYPT) - { - cmd = btm_ble_start_encrypt(bd_addr, false, NULL); - break; - } - } + if (SMP_Pair(bd_addr) == SMP_STARTED) { + cmd = BTM_CMD_STARTED; + p_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; + } + break; - if (SMP_Pair(bd_addr) == SMP_STARTED) - { - cmd = BTM_CMD_STARTED; - p_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; - } - break; - - default: - cmd = BTM_WRONG_MODE; - break; - } - return cmd; + default: + cmd = BTM_WRONG_MODE; + break; + } + return cmd; } /******************************************************************************* @@ -1513,24 +1432,21 @@ tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, tBTM_BLE_SEC_ACT sec_act, u * Returns void * ******************************************************************************/ -void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], uint16_t ediv) -{ - tBTM_CB *p_cb = &btm_cb; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - BT_OCTET8 dummy_stk = {0}; - - BTM_TRACE_DEBUG ("btm_ble_ltk_request"); +void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], uint16_t ediv) { + tBTM_CB* p_cb = &btm_cb; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + BT_OCTET8 dummy_stk = {0}; - p_cb->ediv = ediv; + BTM_TRACE_DEBUG("btm_ble_ltk_request"); - memcpy(p_cb->enc_rand, rand, BT_OCTET8_LEN); + p_cb->ediv = ediv; - if (p_dev_rec != NULL) - { - if (!smp_proc_ltk_request(p_dev_rec->bd_addr)) - btm_ble_ltk_request_reply(p_dev_rec->bd_addr, false, dummy_stk); - } + memcpy(p_cb->enc_rand, rand, BT_OCTET8_LEN); + if (p_dev_rec != NULL) { + if (!smp_proc_ltk_request(p_dev_rec->bd_addr)) + btm_ble_ltk_request_reply(p_dev_rec->bd_addr, false, dummy_stk); + } } /******************************************************************************* @@ -1543,47 +1459,39 @@ void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], uint16_t ediv) * Returns BTM_SUCCESS if encryption was started successfully * ******************************************************************************/ -tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) -{ - tBTM_CB *p_cb = &btm_cb; - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bda); - BT_OCTET8 dummy_rand = {0}; +tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) { + tBTM_CB* p_cb = &btm_cb; + tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bda); + BT_OCTET8 dummy_rand = {0}; - BTM_TRACE_DEBUG ("btm_ble_start_encrypt"); + BTM_TRACE_DEBUG("btm_ble_start_encrypt"); - if (!p_rec ) - { - BTM_TRACE_ERROR("Link is not active, can not encrypt!"); - return BTM_WRONG_MODE; - } + if (!p_rec) { + BTM_TRACE_ERROR("Link is not active, can not encrypt!"); + return BTM_WRONG_MODE; + } - if (p_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) - { - BTM_TRACE_WARNING("Link Encryption is active, Busy!"); - return BTM_BUSY; - } + if (p_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) { + BTM_TRACE_WARNING("Link Encryption is active, Busy!"); + return BTM_BUSY; + } - p_cb->enc_handle = p_rec->ble_hci_handle; + p_cb->enc_handle = p_rec->ble_hci_handle; - if (use_stk) - { - btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, dummy_rand, 0, stk); - } - else if (p_rec->ble.key_type & BTM_LE_KEY_PENC) - { - btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, p_rec->ble.keys.rand, - p_rec->ble.keys.ediv, p_rec->ble.keys.pltk); - } - else - { - BTM_TRACE_ERROR("No key available to encrypt the link"); - return BTM_NO_RESOURCES; - } + if (use_stk) { + btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, dummy_rand, 0, stk); + } else if (p_rec->ble.key_type & BTM_LE_KEY_PENC) { + btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, p_rec->ble.keys.rand, + p_rec->ble.keys.ediv, p_rec->ble.keys.pltk); + } else { + BTM_TRACE_ERROR("No key available to encrypt the link"); + return BTM_NO_RESOURCES; + } - if (p_rec->sec_state == BTM_SEC_STATE_IDLE) - p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; + if (p_rec->sec_state == BTM_SEC_STATE_IDLE) + p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; - return BTM_CMD_STARTED; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -1596,39 +1504,37 @@ tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) * Returns void * ******************************************************************************/ -void btm_ble_link_encrypted(BD_ADDR bd_addr, uint8_t encr_enable) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - bool enc_cback; +void btm_ble_link_encrypted(BD_ADDR bd_addr, uint8_t encr_enable) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + bool enc_cback; - if (!p_dev_rec) - { - BTM_TRACE_WARNING ("btm_ble_link_encrypted (No Device Found!) encr_enable=%d", encr_enable); - return; - } - - BTM_TRACE_DEBUG ("btm_ble_link_encrypted encr_enable=%d", encr_enable); + if (!p_dev_rec) { + BTM_TRACE_WARNING( + "btm_ble_link_encrypted (No Device Found!) encr_enable=%d", + encr_enable); + return; + } - enc_cback = (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING); + BTM_TRACE_DEBUG("btm_ble_link_encrypted encr_enable=%d", encr_enable); - smp_link_encrypted(bd_addr, encr_enable); + enc_cback = (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING); - BTM_TRACE_DEBUG(" p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); + smp_link_encrypted(bd_addr, encr_enable); - if (encr_enable && p_dev_rec->enc_key_size == 0) - p_dev_rec->enc_key_size = p_dev_rec->ble.keys.key_size; + BTM_TRACE_DEBUG(" p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - if (p_dev_rec->p_callback && enc_cback) - { - if (encr_enable) - btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); - else if (p_dev_rec->role_master) - btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, true); + if (encr_enable && p_dev_rec->enc_key_size == 0) + p_dev_rec->enc_key_size = p_dev_rec->ble.keys.key_size; - } - /* to notify GATT to send data if any request is pending */ - gatt_notify_enc_cmpl(p_dev_rec->ble.pseudo_addr); + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + if (p_dev_rec->p_callback && enc_cback) { + if (encr_enable) + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); + else if (p_dev_rec->role_master) + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, true); + } + /* to notify GATT to send data if any request is pending */ + gatt_notify_enc_cmpl(p_dev_rec->ble.pseudo_addr); } /******************************************************************************* @@ -1642,33 +1548,29 @@ void btm_ble_link_encrypted(BD_ADDR bd_addr, uint8_t encr_enable) * Returns void * ******************************************************************************/ -void btm_ble_ltk_request_reply(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) -{ - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bda); - tBTM_CB *p_cb = &btm_cb; - - if (p_rec == NULL) - { - BTM_TRACE_ERROR("btm_ble_ltk_request_reply received for unknown device"); - return; - } - - BTM_TRACE_DEBUG ("btm_ble_ltk_request_reply"); - p_cb->enc_handle = p_rec->ble_hci_handle; - p_cb->key_size = p_rec->ble.keys.key_size; +void btm_ble_ltk_request_reply(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) { + tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bda); + tBTM_CB* p_cb = &btm_cb; - BTM_TRACE_ERROR("key size = %d", p_rec->ble.keys.key_size); - if (use_stk) - { - btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, stk); - } - else /* calculate LTK using peer device */ - { - if (p_rec->ble.key_type & BTM_LE_KEY_LENC) - btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, p_rec->ble.keys.lltk); - else - btsnd_hcic_ble_ltk_req_neg_reply(btm_cb.enc_handle); - } + if (p_rec == NULL) { + BTM_TRACE_ERROR("btm_ble_ltk_request_reply received for unknown device"); + return; + } + + BTM_TRACE_DEBUG("btm_ble_ltk_request_reply"); + p_cb->enc_handle = p_rec->ble_hci_handle; + p_cb->key_size = p_rec->ble.keys.key_size; + + BTM_TRACE_ERROR("key size = %d", p_rec->ble.keys.key_size); + if (use_stk) { + btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, stk); + } else /* calculate LTK using peer device */ + { + if (p_rec->ble.key_type & BTM_LE_KEY_LENC) + btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, p_rec->ble.keys.lltk); + else + btsnd_hcic_ble_ltk_req_neg_reply(btm_cb.enc_handle); + } } /******************************************************************************* @@ -1681,78 +1583,78 @@ void btm_ble_ltk_request_reply(BD_ADDR bda, bool use_stk, BT_OCTET16 stk) * Returns void * ******************************************************************************/ -uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p_data) -{ - uint8_t callback_rc = BTM_SUCCESS; - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req"); - if (btm_cb.api.p_le_callback) - { - /* the callback function implementation may change the IO capability... */ - callback_rc = (*btm_cb.api.p_le_callback) (BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, (tBTM_LE_EVT_DATA *)p_data); - } - if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != p_data->oob_data)) - { +uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec, + tBTM_LE_IO_REQ* p_data) { + uint8_t callback_rc = BTM_SUCCESS; + BTM_TRACE_DEBUG("btm_ble_io_capabilities_req"); + if (btm_cb.api.p_le_callback) { + /* the callback function implementation may change the IO capability... */ + callback_rc = (*btm_cb.api.p_le_callback)( + BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, (tBTM_LE_EVT_DATA*)p_data); + } + if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != p_data->oob_data)) { #if (BTM_BLE_CONFORMANCE_TESTING == TRUE) - if (btm_cb.devcb.keep_rfu_in_auth_req) - { - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req keep_rfu_in_auth_req = %u", - btm_cb.devcb.keep_rfu_in_auth_req); - p_data->auth_req &= BTM_LE_AUTH_REQ_MASK_KEEP_RFU; - btm_cb.devcb.keep_rfu_in_auth_req = false; - } - else - { /* default */ - p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; - } + if (btm_cb.devcb.keep_rfu_in_auth_req) { + BTM_TRACE_DEBUG("btm_ble_io_capabilities_req keep_rfu_in_auth_req = %u", + btm_cb.devcb.keep_rfu_in_auth_req); + p_data->auth_req &= BTM_LE_AUTH_REQ_MASK_KEEP_RFU; + btm_cb.devcb.keep_rfu_in_auth_req = false; + } else { /* default */ + p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; + } #else - p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; + p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; #endif - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 1: p_dev_rec->security_required = %d auth_req:%d", - p_dev_rec->security_required, p_data->auth_req); - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 2: i_keys=0x%x r_keys=0x%x (bit 0-LTK 1-IRK 2-CSRK)", - p_data->init_keys, - p_data->resp_keys); - - /* if authentication requires MITM protection, put on the mask */ - if (p_dev_rec->security_required & BTM_SEC_IN_MITM) - p_data->auth_req |= BTM_LE_AUTH_REQ_MITM; - - if (!(p_data->auth_req & SMP_AUTH_BOND)) - { - BTM_TRACE_DEBUG("Non bonding: No keys should be exchanged"); - p_data->init_keys = 0; - p_data->resp_keys = 0; - } - - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 3: auth_req:%d", p_data->auth_req); - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x", - p_data->init_keys, - p_data->resp_keys); - - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d", - p_data->io_cap, p_data->auth_req); - - /* remove MITM protection requirement if IO cap does not allow it */ - if ((p_data->io_cap == BTM_IO_CAP_NONE) && p_data->oob_data == SMP_OOB_NONE) - p_data->auth_req &= ~BTM_LE_AUTH_REQ_MITM; - - if (!(p_data->auth_req & SMP_SC_SUPPORT_BIT)) - { - /* if Secure Connections are not supported then remove LK derivation, - ** and keypress notifications. - */ - BTM_TRACE_DEBUG("%s-SC not supported -> No LK derivation, no keypress notifications", - __func__); - p_data->auth_req &= ~SMP_KP_SUPPORT_BIT; - p_data->init_keys &= ~SMP_SEC_KEY_TYPE_LK; - p_data->resp_keys &= ~SMP_SEC_KEY_TYPE_LK; - } - - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:0x%02x", - p_data->io_cap, p_data->oob_data, p_data->auth_req); - } - return callback_rc; + BTM_TRACE_DEBUG( + "btm_ble_io_capabilities_req 1: p_dev_rec->security_required = %d " + "auth_req:%d", + p_dev_rec->security_required, p_data->auth_req); + BTM_TRACE_DEBUG( + "btm_ble_io_capabilities_req 2: i_keys=0x%x r_keys=0x%x (bit 0-LTK " + "1-IRK 2-CSRK)", + p_data->init_keys, p_data->resp_keys); + + /* if authentication requires MITM protection, put on the mask */ + if (p_dev_rec->security_required & BTM_SEC_IN_MITM) + p_data->auth_req |= BTM_LE_AUTH_REQ_MITM; + + if (!(p_data->auth_req & SMP_AUTH_BOND)) { + BTM_TRACE_DEBUG("Non bonding: No keys should be exchanged"); + p_data->init_keys = 0; + p_data->resp_keys = 0; + } + + BTM_TRACE_DEBUG("btm_ble_io_capabilities_req 3: auth_req:%d", + p_data->auth_req); + BTM_TRACE_DEBUG("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x", + p_data->init_keys, p_data->resp_keys); + + BTM_TRACE_DEBUG( + "btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d", + p_data->io_cap, p_data->auth_req); + + /* remove MITM protection requirement if IO cap does not allow it */ + if ((p_data->io_cap == BTM_IO_CAP_NONE) && p_data->oob_data == SMP_OOB_NONE) + p_data->auth_req &= ~BTM_LE_AUTH_REQ_MITM; + + if (!(p_data->auth_req & SMP_SC_SUPPORT_BIT)) { + /* if Secure Connections are not supported then remove LK derivation, + ** and keypress notifications. + */ + BTM_TRACE_DEBUG( + "%s-SC not supported -> No LK derivation, no keypress notifications", + __func__); + p_data->auth_req &= ~SMP_KP_SUPPORT_BIT; + p_data->init_keys &= ~SMP_SEC_KEY_TYPE_LK; + p_data->resp_keys &= ~SMP_SEC_KEY_TYPE_LK; + } + + BTM_TRACE_DEBUG( + "btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:0x%02x", + p_data->io_cap, p_data->oob_data, p_data->auth_req); + } + return callback_rc; } /******************************************************************************* @@ -1765,18 +1667,17 @@ uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ * Returns void * ******************************************************************************/ -uint8_t btm_ble_br_keys_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p_data) -{ - uint8_t callback_rc = BTM_SUCCESS; - BTM_TRACE_DEBUG ("%s", __func__); - if (btm_cb.api.p_le_callback) - { - /* the callback function implementation may change the IO capability... */ - callback_rc = (*btm_cb.api.p_le_callback) (BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, - (tBTM_LE_EVT_DATA *)p_data); - } +uint8_t btm_ble_br_keys_req(tBTM_SEC_DEV_REC* p_dev_rec, + tBTM_LE_IO_REQ* p_data) { + uint8_t callback_rc = BTM_SUCCESS; + BTM_TRACE_DEBUG("%s", __func__); + if (btm_cb.api.p_le_callback) { + /* the callback function implementation may change the IO capability... */ + callback_rc = (*btm_cb.api.p_le_callback)( + BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, (tBTM_LE_EVT_DATA*)p_data); + } - return callback_rc; + return callback_rc; } #if (BLE_PRIVACY_SPT == TRUE) @@ -1790,56 +1691,52 @@ uint8_t btm_ble_br_keys_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p_data) * Returns void * ******************************************************************************/ -static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - tBTM_SEC_DEV_REC *match_rec = (tBTM_SEC_DEV_REC *) p_rec; - uint8_t role, bda_type; - uint16_t handle; - BD_ADDR bda; - uint16_t conn_interval, conn_latency, conn_timeout; - bool match = false; - - ++p; - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (role, p); - STREAM_TO_UINT8 (bda_type, p); - STREAM_TO_BDADDR (bda, p); - STREAM_TO_UINT16 (conn_interval, p); - STREAM_TO_UINT16 (conn_latency, p); - STREAM_TO_UINT16 (conn_timeout, p); - - handle = HCID_GET_HANDLE (handle); - - BTM_TRACE_EVENT ("%s", __func__); - - if (match_rec) - { - LOG_INFO(LOG_TAG, "%s matched and resolved random address", __func__); - match = true; - match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; - memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); - if (!btm_ble_init_pseudo_addr (match_rec, bda)) - { - /* assign the original address to be the current report address */ - memcpy(bda, match_rec->ble.pseudo_addr, BD_ADDR_LEN); - } - else - { - memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); - } - } - else - { - LOG_INFO(LOG_TAG, "%s unable to match and resolve random address", __func__); +static void btm_ble_resolve_random_addr_on_conn_cmpl(void* p_rec, + void* p_data) { + uint8_t* p = (uint8_t*)p_data; + tBTM_SEC_DEV_REC* match_rec = (tBTM_SEC_DEV_REC*)p_rec; + uint8_t role, bda_type; + uint16_t handle; + BD_ADDR bda; + uint16_t conn_interval, conn_latency, conn_timeout; + bool match = false; + + ++p; + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(role, p); + STREAM_TO_UINT8(bda_type, p); + STREAM_TO_BDADDR(bda, p); + STREAM_TO_UINT16(conn_interval, p); + STREAM_TO_UINT16(conn_latency, p); + STREAM_TO_UINT16(conn_timeout, p); + + handle = HCID_GET_HANDLE(handle); + + BTM_TRACE_EVENT("%s", __func__); + + if (match_rec) { + LOG_INFO(LOG_TAG, "%s matched and resolved random address", __func__); + match = true; + match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; + memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); + if (!btm_ble_init_pseudo_addr(match_rec, bda)) { + /* assign the original address to be the current report address */ + memcpy(bda, match_rec->ble.pseudo_addr, BD_ADDR_LEN); + } else { + memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); } + } else { + LOG_INFO(LOG_TAG, "%s unable to match and resolve random address", + __func__); + } - btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); + btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, + match); - l2cble_conn_comp (handle, role, bda, bda_type, conn_interval, - conn_latency, conn_timeout); + l2cble_conn_comp(handle, role, bda, bda_type, conn_interval, conn_latency, + conn_timeout); - return; + return; } #endif @@ -1853,67 +1750,62 @@ static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) * Returns void * ******************************************************************************/ -void btm_ble_connected (uint8_t *bda, uint16_t handle, uint8_t enc_mode, uint8_t role, - tBLE_ADDR_TYPE addr_type, - UNUSED_ATTR bool addr_matched) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - - BTM_TRACE_EVENT ("btm_ble_connected"); - - /* Commenting out trace due to obf/compilation problems. - */ - if (p_dev_rec) - { - BTM_TRACE_EVENT ("Security Manager: btm_ble_connected : handle:%d enc_mode:%d bda:%x RName:%s", - handle, enc_mode, - (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5], - p_dev_rec->sec_bd_name); - - BTM_TRACE_DEBUG ("btm_ble_connected sec_flags=0x%x",p_dev_rec->sec_flags); - } - else - { - BTM_TRACE_EVENT ("Security Manager: btm_ble_connected: handle:%d enc_mode:%d bda:%x ", - handle, enc_mode, - (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5]); - } - - if (!p_dev_rec) - { - /* There is no device record for new connection. Allocate one */ - p_dev_rec = btm_sec_alloc_dev(bda); - if (p_dev_rec == NULL) - return; - } - else /* Update the timestamp for this device */ - { - p_dev_rec->timestamp = btm_cb.dev_rec_count++; - } - - /* update device information */ - p_dev_rec->device_type |= BT_DEVICE_TYPE_BLE; - p_dev_rec->ble_hci_handle = handle; - p_dev_rec->ble.ble_addr_type = addr_type; - /* update pseudo address */ - memcpy(p_dev_rec->ble.pseudo_addr, bda, BD_ADDR_LEN); - - p_dev_rec->role_master = false; - if (role == HCI_ROLE_MASTER) - p_dev_rec->role_master = true; +void btm_ble_connected(uint8_t* bda, uint16_t handle, uint8_t enc_mode, + uint8_t role, tBLE_ADDR_TYPE addr_type, + UNUSED_ATTR bool addr_matched) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + + BTM_TRACE_EVENT("btm_ble_connected"); + + /* Commenting out trace due to obf/compilation problems. + */ + if (p_dev_rec) { + BTM_TRACE_EVENT( + "Security Manager: btm_ble_connected : handle:%d enc_mode:%d bda:%x " + "RName:%s", + handle, enc_mode, + (bda[2] << 24) + (bda[3] << 16) + (bda[4] << 8) + bda[5], + p_dev_rec->sec_bd_name); + + BTM_TRACE_DEBUG("btm_ble_connected sec_flags=0x%x", p_dev_rec->sec_flags); + } else { + BTM_TRACE_EVENT( + "Security Manager: btm_ble_connected: handle:%d enc_mode:%d " + "bda:%x ", + handle, enc_mode, + (bda[2] << 24) + (bda[3] << 16) + (bda[4] << 8) + bda[5]); + } + + if (!p_dev_rec) { + /* There is no device record for new connection. Allocate one */ + p_dev_rec = btm_sec_alloc_dev(bda); + if (p_dev_rec == NULL) return; + } else /* Update the timestamp for this device */ + { + p_dev_rec->timestamp = btm_cb.dev_rec_count++; + } + + /* update device information */ + p_dev_rec->device_type |= BT_DEVICE_TYPE_BLE; + p_dev_rec->ble_hci_handle = handle; + p_dev_rec->ble.ble_addr_type = addr_type; + /* update pseudo address */ + memcpy(p_dev_rec->ble.pseudo_addr, bda, BD_ADDR_LEN); + + p_dev_rec->role_master = false; + if (role == HCI_ROLE_MASTER) p_dev_rec->role_master = true; #if (BLE_PRIVACY_SPT == TRUE) - if (!addr_matched) - p_dev_rec->ble.active_addr_type = BTM_BLE_ADDR_PSEUDO; + if (!addr_matched) p_dev_rec->ble.active_addr_type = BTM_BLE_ADDR_PSEUDO; - if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM && !addr_matched) - memcpy(p_dev_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); + if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM && !addr_matched) + memcpy(p_dev_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); #endif - p_cb->inq_var.directed_conn = BTM_BLE_CONNECT_EVT; + p_cb->inq_var.directed_conn = BTM_BLE_CONNECT_EVT; - return; + return; } /***************************************************************************** @@ -1922,87 +1814,79 @@ void btm_ble_connected (uint8_t *bda, uint16_t handle, uint8_t enc_mode, uint8_t * Description LE connection complete. * *****************************************************************************/ -void btm_ble_conn_complete(uint8_t *p, - UNUSED_ATTR uint16_t evt_len, bool enhanced) -{ +void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len, + bool enhanced) { #if (BLE_PRIVACY_SPT == TRUE) - uint8_t *p_data = p, peer_addr_type; - BD_ADDR local_rpa, peer_rpa; + uint8_t *p_data = p, peer_addr_type; + BD_ADDR local_rpa, peer_rpa; #endif - uint8_t role, status, bda_type; - uint16_t handle; - BD_ADDR bda; - uint16_t conn_interval, conn_latency, conn_timeout; - bool match = false; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (role, p); - STREAM_TO_UINT8 (bda_type, p); - STREAM_TO_BDADDR (bda, p); - - if (status == 0) - { + uint8_t role, status, bda_type; + uint16_t handle; + BD_ADDR bda; + uint16_t conn_interval, conn_latency, conn_timeout; + bool match = false; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(role, p); + STREAM_TO_UINT8(bda_type, p); + STREAM_TO_BDADDR(bda, p); + + if (status == 0) { #if (BLE_PRIVACY_SPT == TRUE) - peer_addr_type = bda_type; - match = btm_identity_addr_to_random_pseudo (bda, &bda_type, true); + peer_addr_type = bda_type; + match = btm_identity_addr_to_random_pseudo(bda, &bda_type, true); - if (enhanced) - { - STREAM_TO_BDADDR (local_rpa, p); - STREAM_TO_BDADDR (peer_rpa, p); - } + if (enhanced) { + STREAM_TO_BDADDR(local_rpa, p); + STREAM_TO_BDADDR(peer_rpa, p); + } - /* possiblly receive connection complete with resolvable random while - the device has been paired */ - if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) - { - btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_conn_cmpl, p_data); - } - else + /* possiblly receive connection complete with resolvable random while + the device has been paired */ + if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) { + btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_conn_cmpl, + p_data); + } else #endif - { - STREAM_TO_UINT16 (conn_interval, p); - STREAM_TO_UINT16 (conn_latency, p); - STREAM_TO_UINT16 (conn_timeout, p); - handle = HCID_GET_HANDLE (handle); + { + STREAM_TO_UINT16(conn_interval, p); + STREAM_TO_UINT16(conn_latency, p); + STREAM_TO_UINT16(conn_timeout, p); + handle = HCID_GET_HANDLE(handle); - btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); + btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, + match); - l2cble_conn_comp (handle, role, bda, bda_type, conn_interval, - conn_latency, conn_timeout); + l2cble_conn_comp(handle, role, bda, bda_type, conn_interval, conn_latency, + conn_timeout); #if (BLE_PRIVACY_SPT == TRUE) - if (enhanced) - { - btm_ble_refresh_local_resolvable_private_addr(bda, local_rpa); + if (enhanced) { + btm_ble_refresh_local_resolvable_private_addr(bda, local_rpa); - if (peer_addr_type & BLE_ADDR_TYPE_ID_BIT) - btm_ble_refresh_peer_resolvable_private_addr(bda, peer_rpa, BLE_ADDR_RANDOM); - } + if (peer_addr_type & BLE_ADDR_TYPE_ID_BIT) + btm_ble_refresh_peer_resolvable_private_addr(bda, peer_rpa, + BLE_ADDR_RANDOM); + } #endif - } } - else - { - role = HCI_ROLE_UNKNOWN; - if (status != HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) - { - btm_ble_set_conn_st(BLE_CONN_IDLE); + } else { + role = HCI_ROLE_UNKNOWN; + if (status != HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) { + btm_ble_set_conn_st(BLE_CONN_IDLE); #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); + btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); #endif - } - else - { + } else { #if (BLE_PRIVACY_SPT == TRUE) - btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); + btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); #endif - } } + } - btm_ble_update_mode_operation(role, bda, status); + btm_ble_update_mode_operation(role, bda, status); } /***************************************************************************** @@ -2011,13 +1895,11 @@ void btm_ble_conn_complete(uint8_t *p, * Description LE connection complete. * *****************************************************************************/ -void btm_ble_create_ll_conn_complete (uint8_t status) -{ - if (status != HCI_SUCCESS) - { - btm_ble_set_conn_st(BLE_CONN_IDLE); - btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, NULL, status); - } +void btm_ble_create_ll_conn_complete(uint8_t status) { + if (status != HCI_SUCCESS) { + btm_ble_set_conn_st(BLE_CONN_IDLE); + btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, NULL, status); + } } /***************************************************************************** * Function btm_proc_smp_cback @@ -2025,129 +1907,125 @@ void btm_ble_create_ll_conn_complete (uint8_t status) * Description This function is the SMP callback handler. * *****************************************************************************/ -uint8_t btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - uint8_t res = 0; +uint8_t btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, + tSMP_EVT_DATA* p_data) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + uint8_t res = 0; + + BTM_TRACE_DEBUG("btm_proc_smp_cback event = %d", event); + + if (p_dev_rec != NULL) { + switch (event) { + case SMP_IO_CAP_REQ_EVT: + btm_ble_io_capabilities_req(p_dev_rec, + (tBTM_LE_IO_REQ*)&p_data->io_req); + break; + + case SMP_BR_KEYS_REQ_EVT: + btm_ble_br_keys_req(p_dev_rec, (tBTM_LE_IO_REQ*)&p_data->io_req); + break; + + case SMP_PASSKEY_REQ_EVT: + case SMP_PASSKEY_NOTIF_EVT: + case SMP_OOB_REQ_EVT: + case SMP_NC_REQ_EVT: + case SMP_SC_OOB_REQ_EVT: + /* fall through */ + p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; + + case SMP_SEC_REQUEST_EVT: + if (event == SMP_SEC_REQUEST_EVT && + btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) { + BTM_TRACE_DEBUG("%s: Ignoring SMP Security request", __func__); + break; + } + memcpy(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); + p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; + /* fall through */ + + case SMP_COMPLT_EVT: + if (btm_cb.api.p_le_callback) { + /* the callback function implementation may change the IO + * capability... */ + BTM_TRACE_DEBUG("btm_cb.api.p_le_callback=0x%x", + btm_cb.api.p_le_callback); + (*btm_cb.api.p_le_callback)(event, bd_addr, + (tBTM_LE_EVT_DATA*)p_data); + } - BTM_TRACE_DEBUG ("btm_proc_smp_cback event = %d", event); + if (event == SMP_COMPLT_EVT) { + BTM_TRACE_DEBUG( + "evt=SMP_COMPLT_EVT before update sec_level=0x%x sec_flags=0x%x", + p_data->cmplt.sec_level, p_dev_rec->sec_flags); - if (p_dev_rec != NULL) - { - switch (event) - { - case SMP_IO_CAP_REQ_EVT: - btm_ble_io_capabilities_req(p_dev_rec, (tBTM_LE_IO_REQ *)&p_data->io_req); - break; - - case SMP_BR_KEYS_REQ_EVT: - btm_ble_br_keys_req(p_dev_rec, (tBTM_LE_IO_REQ *)&p_data->io_req); - break; - - case SMP_PASSKEY_REQ_EVT: - case SMP_PASSKEY_NOTIF_EVT: - case SMP_OOB_REQ_EVT: - case SMP_NC_REQ_EVT: - case SMP_SC_OOB_REQ_EVT: - /* fall through */ - p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - - case SMP_SEC_REQUEST_EVT: - if (event == SMP_SEC_REQUEST_EVT && btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - { - BTM_TRACE_DEBUG("%s: Ignoring SMP Security request", __func__); - break; - } - memcpy (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); - p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; - /* fall through */ - - case SMP_COMPLT_EVT: - if (btm_cb.api.p_le_callback) - { - /* the callback function implementation may change the IO capability... */ - BTM_TRACE_DEBUG ("btm_cb.api.p_le_callback=0x%x", btm_cb.api.p_le_callback ); - (*btm_cb.api.p_le_callback) (event, bd_addr, (tBTM_LE_EVT_DATA *)p_data); - } - - if (event == SMP_COMPLT_EVT) - { - BTM_TRACE_DEBUG ("evt=SMP_COMPLT_EVT before update sec_level=0x%x sec_flags=0x%x", p_data->cmplt.sec_level , p_dev_rec->sec_flags ); - - res = (p_data->cmplt.reason == SMP_SUCCESS) ? BTM_SUCCESS : BTM_ERR_PROCESSING; - - BTM_TRACE_DEBUG ("after update result=%d sec_level=0x%x sec_flags=0x%x", - res, p_data->cmplt.sec_level , p_dev_rec->sec_flags ); - - if (p_data->cmplt.is_pair_cancel && btm_cb.api.p_bond_cancel_cmpl_callback ) - { - BTM_TRACE_DEBUG ("Pairing Cancel completed"); - (*btm_cb.api.p_bond_cancel_cmpl_callback)(BTM_SUCCESS); - } + res = (p_data->cmplt.reason == SMP_SUCCESS) ? BTM_SUCCESS + : BTM_ERR_PROCESSING; + + BTM_TRACE_DEBUG( + "after update result=%d sec_level=0x%x sec_flags=0x%x", res, + p_data->cmplt.sec_level, p_dev_rec->sec_flags); + + if (p_data->cmplt.is_pair_cancel && + btm_cb.api.p_bond_cancel_cmpl_callback) { + BTM_TRACE_DEBUG("Pairing Cancel completed"); + (*btm_cb.api.p_bond_cancel_cmpl_callback)(BTM_SUCCESS); + } #if (BTM_BLE_CONFORMANCE_TESTING == TRUE) - if (res != BTM_SUCCESS) - { - if (!btm_cb.devcb.no_disc_if_pair_fail && p_data->cmplt.reason != SMP_CONN_TOUT) - { - BTM_TRACE_DEBUG ("Pairing failed - prepare to remove ACL"); - l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle); - } - else - { - BTM_TRACE_DEBUG ("Pairing failed - Not Removing ACL"); - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - } - } + if (res != BTM_SUCCESS) { + if (!btm_cb.devcb.no_disc_if_pair_fail && + p_data->cmplt.reason != SMP_CONN_TOUT) { + BTM_TRACE_DEBUG("Pairing failed - prepare to remove ACL"); + l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle); + } else { + BTM_TRACE_DEBUG("Pairing failed - Not Removing ACL"); + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + } + } #else - if (res != BTM_SUCCESS && p_data->cmplt.reason != SMP_CONN_TOUT) - { - BTM_TRACE_DEBUG ("Pairing failed - prepare to remove ACL"); - l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle); - } + if (res != BTM_SUCCESS && p_data->cmplt.reason != SMP_CONN_TOUT) { + BTM_TRACE_DEBUG("Pairing failed - prepare to remove ACL"); + l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle); + } #endif - BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x pin_code_len=%x", - btm_cb.pairing_state, - btm_cb.pairing_flags, - btm_cb.pin_code_len ); - BTM_TRACE_DEBUG ("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x", - btm_cb.pairing_bda[0], btm_cb.pairing_bda[1], btm_cb.pairing_bda[2], - btm_cb.pairing_bda[3], btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]); - - /* Reset btm state only if the callback address matches pairing address*/ - if(memcmp(bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) - { - memset (btm_cb.pairing_bda, 0xff, BD_ADDR_LEN); - btm_cb.pairing_state = BTM_PAIR_STATE_IDLE; - btm_cb.pairing_flags = 0; - } - - if (res == BTM_SUCCESS) - { - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + BTM_TRACE_DEBUG( + "btm_cb pairing_state=%x pairing_flags=%x pin_code_len=%x", + btm_cb.pairing_state, btm_cb.pairing_flags, btm_cb.pin_code_len); + BTM_TRACE_DEBUG("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x", + btm_cb.pairing_bda[0], btm_cb.pairing_bda[1], + btm_cb.pairing_bda[2], btm_cb.pairing_bda[3], + btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]); + + /* Reset btm state only if the callback address matches pairing + * address*/ + if (memcmp(bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) { + memset(btm_cb.pairing_bda, 0xff, BD_ADDR_LEN); + btm_cb.pairing_state = BTM_PAIR_STATE_IDLE; + btm_cb.pairing_flags = 0; + } + + if (res == BTM_SUCCESS) { + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; #if (BLE_PRIVACY_SPT == TRUE) - /* add all bonded device into resolving list if IRK is available*/ - btm_ble_resolving_list_load_dev(p_dev_rec); + /* add all bonded device into resolving list if IRK is available*/ + btm_ble_resolving_list_load_dev(p_dev_rec); #endif - } - - btm_sec_dev_rec_cback_event(p_dev_rec, res, true); - } - break; - - default: - BTM_TRACE_DEBUG ("unknown event = %d", event); - break; + } + btm_sec_dev_rec_cback_event(p_dev_rec, res, true); } + break; + + default: + BTM_TRACE_DEBUG("unknown event = %d", event); + break; } - else - { - BTM_TRACE_ERROR("btm_proc_smp_cback received for unknown device"); - } + } else { + BTM_TRACE_ERROR("btm_proc_smp_cback received for unknown device"); + } - return 0; + return 0; } /******************************************************************************* @@ -2166,47 +2044,50 @@ uint8_t btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_dat * Returns true if signing sucessul, otherwise false. * ******************************************************************************/ -bool BTM_BleDataSignature (BD_ADDR bd_addr, uint8_t *p_text, uint16_t len, - BLE_SIGNATURE signature) -{ - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); - - BTM_TRACE_DEBUG ("%s", __func__); - bool ret = false; - if (p_rec == NULL) - { - BTM_TRACE_ERROR("%s-data signing can not be done from unknown device", __func__); - } - else - { - uint8_t *p_mac = (uint8_t *)signature; - uint8_t *pp; - uint8_t *p_buf = (uint8_t *)osi_malloc(len + 4); - - BTM_TRACE_DEBUG("%s-Start to generate Local CSRK", __func__); - pp = p_buf; - /* prepare plain text */ - if (p_text) { - memcpy(p_buf, p_text, len); - pp = (p_buf + len); - } - - UINT32_TO_STREAM(pp, p_rec->ble.keys.local_counter); - UINT32_TO_STREAM(p_mac, p_rec->ble.keys.local_counter); - - ret = aes_cipher_msg_auth_code(p_rec->ble.keys.lcsrk, p_buf, (uint16_t)(len + 4), BTM_CMAC_TLEN_SIZE, p_mac); - if (ret == true) { - btm_ble_increment_sign_ctr(bd_addr, true); - } - - BTM_TRACE_DEBUG("%s p_mac = %d", __func__, p_mac); - BTM_TRACE_DEBUG("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x", - *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3)); - BTM_TRACE_DEBUG("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x", - *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7)); - osi_free(p_buf); - } - return ret; +bool BTM_BleDataSignature(BD_ADDR bd_addr, uint8_t* p_text, uint16_t len, + BLE_SIGNATURE signature) { + tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bd_addr); + + BTM_TRACE_DEBUG("%s", __func__); + bool ret = false; + if (p_rec == NULL) { + BTM_TRACE_ERROR("%s-data signing can not be done from unknown device", + __func__); + } else { + uint8_t* p_mac = (uint8_t*)signature; + uint8_t* pp; + uint8_t* p_buf = (uint8_t*)osi_malloc(len + 4); + + BTM_TRACE_DEBUG("%s-Start to generate Local CSRK", __func__); + pp = p_buf; + /* prepare plain text */ + if (p_text) { + memcpy(p_buf, p_text, len); + pp = (p_buf + len); + } + + UINT32_TO_STREAM(pp, p_rec->ble.keys.local_counter); + UINT32_TO_STREAM(p_mac, p_rec->ble.keys.local_counter); + + ret = aes_cipher_msg_auth_code(p_rec->ble.keys.lcsrk, p_buf, + (uint16_t)(len + 4), BTM_CMAC_TLEN_SIZE, + p_mac); + if (ret == true) { + btm_ble_increment_sign_ctr(bd_addr, true); + } + + BTM_TRACE_DEBUG("%s p_mac = %d", __func__, p_mac); + BTM_TRACE_DEBUG( + "p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = " + "0x%02x", + *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3)); + BTM_TRACE_DEBUG( + "p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = " + "0x%02x", + *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7)); + osi_free(p_buf); + } + return ret; } /******************************************************************************* @@ -2224,40 +2105,31 @@ bool BTM_BleDataSignature (BD_ADDR bd_addr, uint8_t *p_text, uint16_t len, * Returns true if signature verified correctly; otherwise false. * ******************************************************************************/ -bool BTM_BleVerifySignature (BD_ADDR bd_addr, uint8_t *p_orig, uint16_t len, uint32_t counter, - uint8_t *p_comp) -{ - bool verified = false; - tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); - uint8_t p_mac[BTM_CMAC_TLEN_SIZE]; +bool BTM_BleVerifySignature(BD_ADDR bd_addr, uint8_t* p_orig, uint16_t len, + uint32_t counter, uint8_t* p_comp) { + bool verified = false; + tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bd_addr); + uint8_t p_mac[BTM_CMAC_TLEN_SIZE]; - if (p_rec == NULL || (p_rec && !(p_rec->ble.key_type & BTM_LE_KEY_PCSRK))) - { - BTM_TRACE_ERROR("can not verify signature for unknown device"); - } - else if (counter < p_rec->ble.keys.counter) - { - BTM_TRACE_ERROR("signature received with out dated sign counter"); - } - else if (p_orig == NULL) - { - BTM_TRACE_ERROR("No signature to verify"); - } - else - { - BTM_TRACE_DEBUG ("%s rcv_cnt=%d >= expected_cnt=%d", __func__, counter, - p_rec->ble.keys.counter); - - if (aes_cipher_msg_auth_code(p_rec->ble.keys.pcsrk, p_orig, len, BTM_CMAC_TLEN_SIZE, p_mac)) - { - if (memcmp(p_mac, p_comp, BTM_CMAC_TLEN_SIZE) == 0) - { - btm_ble_increment_sign_ctr(bd_addr, false); - verified = true; - } - } + if (p_rec == NULL || (p_rec && !(p_rec->ble.key_type & BTM_LE_KEY_PCSRK))) { + BTM_TRACE_ERROR("can not verify signature for unknown device"); + } else if (counter < p_rec->ble.keys.counter) { + BTM_TRACE_ERROR("signature received with out dated sign counter"); + } else if (p_orig == NULL) { + BTM_TRACE_ERROR("No signature to verify"); + } else { + BTM_TRACE_DEBUG("%s rcv_cnt=%d >= expected_cnt=%d", __func__, counter, + p_rec->ble.keys.counter); + + if (aes_cipher_msg_auth_code(p_rec->ble.keys.pcsrk, p_orig, len, + BTM_CMAC_TLEN_SIZE, p_mac)) { + if (memcmp(p_mac, p_comp, BTM_CMAC_TLEN_SIZE) == 0) { + btm_ble_increment_sign_ctr(bd_addr, false); + verified = true; + } } - return verified; + } + return verified; } /******************************************************************************* @@ -2270,52 +2142,50 @@ bool BTM_BleVerifySignature (BD_ADDR bd_addr, uint8_t *p_orig, uint16_t len, * Returns bool true if LE device is found, false otherwise. * ******************************************************************************/ -bool BTM_GetLeSecurityState (BD_ADDR bd_addr, uint8_t *p_le_dev_sec_flags, uint8_t *p_le_key_size) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - uint16_t dev_rec_sec_flags; +bool BTM_GetLeSecurityState(BD_ADDR bd_addr, uint8_t* p_le_dev_sec_flags, + uint8_t* p_le_key_size) { + tBTM_SEC_DEV_REC* p_dev_rec; + uint16_t dev_rec_sec_flags; - *p_le_dev_sec_flags = 0; - *p_le_key_size = 0; + *p_le_dev_sec_flags = 0; + *p_le_key_size = 0; - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR ("%s fails", __func__); - return (false); - } + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("%s fails", __func__); + return (false); + } - if (p_dev_rec->ble_hci_handle == BTM_SEC_INVALID_HANDLE) { - BTM_TRACE_ERROR ("%s-this is not LE device", __func__); - return (false); - } + if (p_dev_rec->ble_hci_handle == BTM_SEC_INVALID_HANDLE) { + BTM_TRACE_ERROR("%s-this is not LE device", __func__); + return (false); + } - dev_rec_sec_flags = p_dev_rec->sec_flags; + dev_rec_sec_flags = p_dev_rec->sec_flags; - if (dev_rec_sec_flags & BTM_SEC_LE_ENCRYPTED) - { - /* link is encrypted with LTK or STK */ - *p_le_key_size = p_dev_rec->enc_key_size; - *p_le_dev_sec_flags |= BTM_SEC_LE_LINK_ENCRYPTED; + if (dev_rec_sec_flags & BTM_SEC_LE_ENCRYPTED) { + /* link is encrypted with LTK or STK */ + *p_le_key_size = p_dev_rec->enc_key_size; + *p_le_dev_sec_flags |= BTM_SEC_LE_LINK_ENCRYPTED; - *p_le_dev_sec_flags |= (dev_rec_sec_flags & BTM_SEC_LE_AUTHENTICATED) - ? BTM_SEC_LE_LINK_PAIRED_WITH_MITM /* set auth LTK flag */ - : BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM; /* set unauth LTK flag */ - } - else if (p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) - { - /* link is unencrypted, still LTK is available */ - *p_le_key_size = p_dev_rec->ble.keys.key_size; + *p_le_dev_sec_flags |= + (dev_rec_sec_flags & BTM_SEC_LE_AUTHENTICATED) + ? BTM_SEC_LE_LINK_PAIRED_WITH_MITM /* set auth LTK flag */ + : BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM; /* set unauth LTK flag */ + } else if (p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) { + /* link is unencrypted, still LTK is available */ + *p_le_key_size = p_dev_rec->ble.keys.key_size; - *p_le_dev_sec_flags |= (dev_rec_sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) - ? BTM_SEC_LE_LINK_PAIRED_WITH_MITM /* set auth LTK flag */ - : BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM; /* set unauth LTK flag */ - } + *p_le_dev_sec_flags |= + (dev_rec_sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) + ? BTM_SEC_LE_LINK_PAIRED_WITH_MITM /* set auth LTK flag */ + : BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM; /* set unauth LTK flag */ + } - BTM_TRACE_DEBUG ("%s - le_dev_sec_flags: 0x%02x, le_key_size: %d", - __func__, *p_le_dev_sec_flags, *p_le_key_size); + BTM_TRACE_DEBUG("%s - le_dev_sec_flags: 0x%02x, le_key_size: %d", __func__, + *p_le_dev_sec_flags, *p_le_key_size); - return true; + return true; } /******************************************************************************* @@ -2329,20 +2199,19 @@ bool BTM_GetLeSecurityState (BD_ADDR bd_addr, uint8_t *p_le_dev_sec_flags, ui * otherwise. * ******************************************************************************/ -bool BTM_BleSecurityProcedureIsRunning(BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +bool BTM_BleSecurityProcedureIsRunning(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR ("%s device with BDA: %08x%04x is not found", - __func__, (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5]); - return false; - } + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("%s device with BDA: %08x%04x is not found", __func__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + return false; + } - return (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || - p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING); + return (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || + p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING); } /******************************************************************************* @@ -2356,40 +2225,38 @@ bool BTM_BleSecurityProcedureIsRunning(BD_ADDR bd_addr) * Returns the key size or 0 if the size can't be retrieved. * ******************************************************************************/ -extern uint8_t BTM_BleGetSupportedKeySize (BD_ADDR bd_addr) -{ +extern uint8_t BTM_BleGetSupportedKeySize(BD_ADDR bd_addr) { #if (L2CAP_LE_COC_INCLUDED == TRUE) - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - tBTM_LE_IO_REQ dev_io_cfg; - uint8_t callback_rc; - - if (!p_dev_rec) - { - BTM_TRACE_ERROR ("%s device with BDA: %08x%04x is not found", - __func__,(bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5]); - return 0; - } + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + tBTM_LE_IO_REQ dev_io_cfg; + uint8_t callback_rc; + + if (!p_dev_rec) { + BTM_TRACE_ERROR("%s device with BDA: %08x%04x is not found", __func__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + return 0; + } - if (btm_cb.api.p_le_callback == NULL) - { - BTM_TRACE_ERROR ("%s can't access supported key size",__func__); - return 0; - } + if (btm_cb.api.p_le_callback == NULL) { + BTM_TRACE_ERROR("%s can't access supported key size", __func__); + return 0; + } - callback_rc = (*btm_cb.api.p_le_callback) (BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, - (tBTM_LE_EVT_DATA *) &dev_io_cfg); + callback_rc = (*btm_cb.api.p_le_callback)( + BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, (tBTM_LE_EVT_DATA*)&dev_io_cfg); - if (callback_rc != BTM_SUCCESS) - { - BTM_TRACE_ERROR ("%s can't access supported key size",__func__); - return 0; - } + if (callback_rc != BTM_SUCCESS) { + BTM_TRACE_ERROR("%s can't access supported key size", __func__); + return 0; + } - BTM_TRACE_DEBUG ("%s device supports key size = %d", __func__, dev_io_cfg.max_key_size); - return (dev_io_cfg.max_key_size); + BTM_TRACE_DEBUG("%s device supports key size = %d", __func__, + dev_io_cfg.max_key_size); + return (dev_io_cfg.max_key_size); #else - return 0; + return 0; #endif } @@ -2406,33 +2273,31 @@ extern uint8_t BTM_BleGetSupportedKeySize (BD_ADDR bd_addr) * Returns void * ******************************************************************************/ -static void btm_notify_new_key(uint8_t key_type) -{ - tBTM_BLE_LOCAL_KEYS *p_locak_keys = NULL; +static void btm_notify_new_key(uint8_t key_type) { + tBTM_BLE_LOCAL_KEYS* p_locak_keys = NULL; - BTM_TRACE_DEBUG ("btm_notify_new_key key_type=%d", key_type); + BTM_TRACE_DEBUG("btm_notify_new_key key_type=%d", key_type); - if (btm_cb.api.p_le_key_callback) - { - switch (key_type) - { - case BTM_BLE_KEY_TYPE_ID: - BTM_TRACE_DEBUG ("BTM_BLE_KEY_TYPE_ID"); - p_locak_keys = (tBTM_BLE_LOCAL_KEYS *)&btm_cb.devcb.id_keys; - break; - - case BTM_BLE_KEY_TYPE_ER: - BTM_TRACE_DEBUG ("BTM_BLE_KEY_TYPE_ER"); - p_locak_keys = (tBTM_BLE_LOCAL_KEYS *)&btm_cb.devcb.ble_encryption_key_value; - break; - - default: - BTM_TRACE_ERROR("unknown key type: %d", key_type); - break; - } - if (p_locak_keys != NULL) - (*btm_cb.api.p_le_key_callback) (key_type, p_locak_keys); + if (btm_cb.api.p_le_key_callback) { + switch (key_type) { + case BTM_BLE_KEY_TYPE_ID: + BTM_TRACE_DEBUG("BTM_BLE_KEY_TYPE_ID"); + p_locak_keys = (tBTM_BLE_LOCAL_KEYS*)&btm_cb.devcb.id_keys; + break; + + case BTM_BLE_KEY_TYPE_ER: + BTM_TRACE_DEBUG("BTM_BLE_KEY_TYPE_ER"); + p_locak_keys = + (tBTM_BLE_LOCAL_KEYS*)&btm_cb.devcb.ble_encryption_key_value; + break; + + default: + BTM_TRACE_ERROR("unknown key type: %d", key_type); + break; } + if (p_locak_keys != NULL) + (*btm_cb.api.p_le_key_callback)(key_type, p_locak_keys); + } } /******************************************************************************* @@ -2445,20 +2310,17 @@ static void btm_notify_new_key(uint8_t key_type) * Returns void * ******************************************************************************/ -static void btm_ble_process_er2(tBTM_RAND_ENC *p) -{ - BTM_TRACE_DEBUG ("btm_ble_process_er2"); +static void btm_ble_process_er2(tBTM_RAND_ENC* p) { + BTM_TRACE_DEBUG("btm_ble_process_er2"); - if (p &&p->opcode == HCI_BLE_RAND) - { - memcpy(&btm_cb.devcb.ble_encryption_key_value[8], p->param_buf, BT_OCTET8_LEN); - btm_notify_new_key(BTM_BLE_KEY_TYPE_ER); - } - else - { - BTM_TRACE_ERROR("Generating ER2 exception."); - memset(&btm_cb.devcb.ble_encryption_key_value, 0, sizeof(BT_OCTET16)); - } + if (p && p->opcode == HCI_BLE_RAND) { + memcpy(&btm_cb.devcb.ble_encryption_key_value[8], p->param_buf, + BT_OCTET8_LEN); + btm_notify_new_key(BTM_BLE_KEY_TYPE_ER); + } else { + BTM_TRACE_ERROR("Generating ER2 exception."); + memset(&btm_cb.devcb.ble_encryption_key_value, 0, sizeof(BT_OCTET16)); + } } /******************************************************************************* @@ -2471,20 +2333,17 @@ static void btm_ble_process_er2(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -static void btm_ble_process_er(tBTM_RAND_ENC *p) -{ - BTM_TRACE_DEBUG ("btm_ble_process_er"); +static void btm_ble_process_er(tBTM_RAND_ENC* p) { + BTM_TRACE_DEBUG("btm_ble_process_er"); - if (p &&p->opcode == HCI_BLE_RAND) - { - memcpy(&btm_cb.devcb.ble_encryption_key_value[0], p->param_buf, BT_OCTET8_LEN); + if (p && p->opcode == HCI_BLE_RAND) { + memcpy(&btm_cb.devcb.ble_encryption_key_value[0], p->param_buf, + BT_OCTET8_LEN); - btsnd_hcic_ble_rand((void *)btm_ble_process_er2); - } - else - { - BTM_TRACE_ERROR("Generating ER1 exception."); - } + btsnd_hcic_ble_rand((void*)btm_ble_process_er2); + } else { + BTM_TRACE_ERROR("Generating ER1 exception."); + } } /******************************************************************************* @@ -2497,29 +2356,24 @@ static void btm_ble_process_er(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -static void btm_ble_process_irk(tSMP_ENC *p) -{ - BTM_TRACE_DEBUG ("btm_ble_process_irk"); - if (p &&p->opcode == HCI_BLE_ENCRYPT) - { - memcpy(btm_cb.devcb.id_keys.irk, p->param_buf, BT_OCTET16_LEN); - btm_notify_new_key(BTM_BLE_KEY_TYPE_ID); +static void btm_ble_process_irk(tSMP_ENC* p) { + BTM_TRACE_DEBUG("btm_ble_process_irk"); + if (p && p->opcode == HCI_BLE_ENCRYPT) { + memcpy(btm_cb.devcb.id_keys.irk, p->param_buf, BT_OCTET16_LEN); + btm_notify_new_key(BTM_BLE_KEY_TYPE_ID); #if (BLE_PRIVACY_SPT == TRUE) - /* if privacy is enabled, new RPA should be calculated */ - if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) - { - btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); - } -#endif - } - else - { - BTM_TRACE_ERROR("Generating IRK exception."); + /* if privacy is enabled, new RPA should be calculated */ + if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { + btm_gen_resolvable_private_addr((void*)btm_gen_resolve_paddr_low); } +#endif + } else { + BTM_TRACE_ERROR("Generating IRK exception."); + } - /* proceed generate ER */ - btsnd_hcic_ble_rand((void *)btm_ble_process_er); + /* proceed generate ER */ + btsnd_hcic_ble_rand((void*)btm_ble_process_er); } /******************************************************************************* @@ -2533,35 +2387,28 @@ static void btm_ble_process_irk(tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void btm_ble_process_dhk(tSMP_ENC *p) -{ - uint8_t btm_ble_irk_pt = 0x01; - tSMP_ENC output; +static void btm_ble_process_dhk(tSMP_ENC* p) { + uint8_t btm_ble_irk_pt = 0x01; + tSMP_ENC output; - BTM_TRACE_DEBUG ("btm_ble_process_dhk"); + BTM_TRACE_DEBUG("btm_ble_process_dhk"); - if (p && p->opcode == HCI_BLE_ENCRYPT) - { - memcpy(btm_cb.devcb.id_keys.dhk, p->param_buf, BT_OCTET16_LEN); - BTM_TRACE_DEBUG("BLE DHK generated."); - - /* IRK = D1(IR, 1) */ - if (!SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_irk_pt, - 1, &output)) - { - /* reset all identity root related key */ - memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); - } - else - { - btm_ble_process_irk(&output); - } - } - else - { - /* reset all identity root related key */ - memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); + if (p && p->opcode == HCI_BLE_ENCRYPT) { + memcpy(btm_cb.devcb.id_keys.dhk, p->param_buf, BT_OCTET16_LEN); + BTM_TRACE_DEBUG("BLE DHK generated."); + + /* IRK = D1(IR, 1) */ + if (!SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_irk_pt, + 1, &output)) { + /* reset all identity root related key */ + memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); + } else { + btm_ble_process_irk(&output); } + } else { + /* reset all identity root related key */ + memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); + } } /******************************************************************************* @@ -2576,29 +2423,25 @@ static void btm_ble_process_dhk(tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void btm_ble_process_ir2(tBTM_RAND_ENC *p) -{ - uint8_t btm_ble_dhk_pt = 0x03; - tSMP_ENC output; +static void btm_ble_process_ir2(tBTM_RAND_ENC* p) { + uint8_t btm_ble_dhk_pt = 0x03; + tSMP_ENC output; - BTM_TRACE_DEBUG ("btm_ble_process_ir2"); + BTM_TRACE_DEBUG("btm_ble_process_ir2"); - if (p && p->opcode == HCI_BLE_RAND) - { - /* remembering in control block */ - memcpy(&btm_cb.devcb.id_keys.ir[8], p->param_buf, BT_OCTET8_LEN); - /* generate DHK= Eir({0x03, 0x00, 0x00 ...}) */ + if (p && p->opcode == HCI_BLE_RAND) { + /* remembering in control block */ + memcpy(&btm_cb.devcb.id_keys.ir[8], p->param_buf, BT_OCTET8_LEN); + /* generate DHK= Eir({0x03, 0x00, 0x00 ...}) */ - SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_dhk_pt, - 1, &output); - btm_ble_process_dhk(&output); + SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_dhk_pt, 1, + &output); + btm_ble_process_dhk(&output); - BTM_TRACE_DEBUG("BLE IR generated."); - } - else - { - memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); - } + BTM_TRACE_DEBUG("BLE IR generated."); + } else { + memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); + } } /******************************************************************************* @@ -2613,17 +2456,15 @@ static void btm_ble_process_ir2(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -static void btm_ble_process_ir(tBTM_RAND_ENC *p) -{ - BTM_TRACE_DEBUG ("btm_ble_process_ir"); +static void btm_ble_process_ir(tBTM_RAND_ENC* p) { + BTM_TRACE_DEBUG("btm_ble_process_ir"); - if (p && p->opcode == HCI_BLE_RAND) - { - /* remembering in control block */ - memcpy(btm_cb.devcb.id_keys.ir, p->param_buf, BT_OCTET8_LEN); + if (p && p->opcode == HCI_BLE_RAND) { + /* remembering in control block */ + memcpy(btm_cb.devcb.id_keys.ir, p->param_buf, BT_OCTET8_LEN); - btsnd_hcic_ble_rand((void *)btm_ble_process_ir2); - } + btsnd_hcic_ble_rand((void*)btm_ble_process_ir2); + } } /******************************************************************************* @@ -2635,15 +2476,14 @@ static void btm_ble_process_ir(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -void btm_ble_reset_id( void ) -{ - BTM_TRACE_DEBUG ("btm_ble_reset_id"); +void btm_ble_reset_id(void) { + BTM_TRACE_DEBUG("btm_ble_reset_id"); - /* regenrate Identity Root*/ - btsnd_hcic_ble_rand((void *)btm_ble_process_ir); + /* regenrate Identity Root*/ + btsnd_hcic_ble_rand((void*)btm_ble_process_ir); } - #if BTM_BLE_CONFORMANCE_TESTING == true +#if BTM_BLE_CONFORMANCE_TESTING == true /******************************************************************************* * * Function btm_ble_set_no_disc_if_pair_fail @@ -2654,10 +2494,10 @@ void btm_ble_reset_id( void ) * Returns void * ******************************************************************************/ -void btm_ble_set_no_disc_if_pair_fail(bool disable_disc ) -{ - BTM_TRACE_DEBUG ("btm_ble_set_disc_enable_if_pair_fail disable_disc=%d", disable_disc); - btm_cb.devcb.no_disc_if_pair_fail = disable_disc; +void btm_ble_set_no_disc_if_pair_fail(bool disable_disc) { + BTM_TRACE_DEBUG("btm_ble_set_disc_enable_if_pair_fail disable_disc=%d", + disable_disc); + btm_cb.devcb.no_disc_if_pair_fail = disable_disc; } /******************************************************************************* @@ -2669,11 +2509,10 @@ void btm_ble_set_no_disc_if_pair_fail(bool disable_disc ) * Returns void * ******************************************************************************/ -void btm_ble_set_test_mac_value(bool enable, uint8_t *p_test_mac_val ) -{ - BTM_TRACE_DEBUG ("btm_ble_set_test_mac_value enable=%d", enable); - btm_cb.devcb.enable_test_mac_val = enable; - memcpy(btm_cb.devcb.test_mac, p_test_mac_val, BT_OCTET8_LEN); +void btm_ble_set_test_mac_value(bool enable, uint8_t* p_test_mac_val) { + BTM_TRACE_DEBUG("btm_ble_set_test_mac_value enable=%d", enable); + btm_cb.devcb.enable_test_mac_val = enable; + memcpy(btm_cb.devcb.test_mac, p_test_mac_val, BT_OCTET8_LEN); } /******************************************************************************* @@ -2685,12 +2524,13 @@ void btm_ble_set_test_mac_value(bool enable, uint8_t *p_test_mac_val ) * Returns void * ******************************************************************************/ -void btm_ble_set_test_local_sign_cntr_value(bool enable, uint32_t test_local_sign_cntr ) -{ - BTM_TRACE_DEBUG ("btm_ble_set_test_local_sign_cntr_value enable=%d local_sign_cntr=%d", - enable, test_local_sign_cntr); - btm_cb.devcb.enable_test_local_sign_cntr = enable; - btm_cb.devcb.test_local_sign_cntr = test_local_sign_cntr; +void btm_ble_set_test_local_sign_cntr_value(bool enable, + uint32_t test_local_sign_cntr) { + BTM_TRACE_DEBUG( + "btm_ble_set_test_local_sign_cntr_value enable=%d local_sign_cntr=%d", + enable, test_local_sign_cntr); + btm_cb.devcb.enable_test_local_sign_cntr = enable; + btm_cb.devcb.test_local_sign_cntr = test_local_sign_cntr; } /******************************************************************************* @@ -2702,22 +2542,20 @@ void btm_ble_set_test_local_sign_cntr_value(bool enable, uint32_t test_local_ * Returns void * ******************************************************************************/ -void btm_set_random_address(BD_ADDR random_bda) -{ - tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - bool adv_mode = btm_cb.ble_ctr_cb.inq_var.adv_mode ; - - BTM_TRACE_DEBUG ("btm_set_random_address"); +void btm_set_random_address(BD_ADDR random_bda) { + tBTM_LE_RANDOM_CB* p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + bool adv_mode = btm_cb.ble_ctr_cb.inq_var.adv_mode; - if (adv_mode == BTM_BLE_ADV_ENABLE) - btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE); + BTM_TRACE_DEBUG("btm_set_random_address"); - memcpy(p_cb->private_addr, random_bda, BD_ADDR_LEN); - btsnd_hcic_ble_set_random_addr(p_cb->private_addr); + if (adv_mode == BTM_BLE_ADV_ENABLE) + btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE); - if (adv_mode == BTM_BLE_ADV_ENABLE) - btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE); + memcpy(p_cb->private_addr, random_bda, BD_ADDR_LEN); + btsnd_hcic_ble_set_random_addr(p_cb->private_addr); + if (adv_mode == BTM_BLE_ADV_ENABLE) + btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_ENABLE); } /******************************************************************************* @@ -2730,10 +2568,9 @@ void btm_set_random_address(BD_ADDR random_bda) * Returns void * ******************************************************************************/ -void btm_ble_set_keep_rfu_in_auth_req(bool keep_rfu) -{ - BTM_TRACE_DEBUG ("btm_ble_set_keep_rfu_in_auth_req keep_rfus=%d", keep_rfu); - btm_cb.devcb.keep_rfu_in_auth_req = keep_rfu; +void btm_ble_set_keep_rfu_in_auth_req(bool keep_rfu) { + BTM_TRACE_DEBUG("btm_ble_set_keep_rfu_in_auth_req keep_rfus=%d", keep_rfu); + btm_cb.devcb.keep_rfu_in_auth_req = keep_rfu; } #endif /* BTM_BLE_CONFORMANCE_TESTING */ diff --git a/stack/btm/btm_ble_addr.cc b/stack/btm/btm_ble_addr.cc index e54fe6ffb..6d13205ec 100644 --- a/stack/btm/btm_ble_addr.cc +++ b/stack/btm/btm_ble_addr.cc @@ -25,17 +25,16 @@ #include #include "bt_types.h" -#include "hcimsgs.h" -#include "btu.h" #include "btm_int.h" -#include "gap_api.h" +#include "btu.h" #include "device/include/controller.h" +#include "gap_api.h" +#include "hcimsgs.h" #include "btm_ble_int.h" #include "smp_api.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -47,36 +46,32 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns void * ******************************************************************************/ -static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) -{ - tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - BTM_TRACE_EVENT ("btm_gen_resolve_paddr_cmpl"); - - if (p) - { - /* set hash to be LSB of rpAddress */ - p_cb->private_addr[5] = p->param_buf[0]; - p_cb->private_addr[4] = p->param_buf[1]; - p_cb->private_addr[3] = p->param_buf[2]; - /* set it to controller */ - btsnd_hcic_ble_set_random_addr(p_cb->private_addr); - - p_cb->own_addr_type = BLE_ADDR_RANDOM; - - /* start a periodical timer to refresh random addr */ - period_ms_t interval_ms = BTM_BLE_PRIVATE_ADDR_INT_MS; +static void btm_gen_resolve_paddr_cmpl(tSMP_ENC* p) { + tBTM_LE_RANDOM_CB* p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + BTM_TRACE_EVENT("btm_gen_resolve_paddr_cmpl"); + + if (p) { + /* set hash to be LSB of rpAddress */ + p_cb->private_addr[5] = p->param_buf[0]; + p_cb->private_addr[4] = p->param_buf[1]; + p_cb->private_addr[3] = p->param_buf[2]; + /* set it to controller */ + btsnd_hcic_ble_set_random_addr(p_cb->private_addr); + + p_cb->own_addr_type = BLE_ADDR_RANDOM; + + /* start a periodical timer to refresh random addr */ + period_ms_t interval_ms = BTM_BLE_PRIVATE_ADDR_INT_MS; #if (BTM_BLE_CONFORMANCE_TESTING == TRUE) - interval_ms = btm_cb.ble_ctr_cb.rpa_tout * 1000; + interval_ms = btm_cb.ble_ctr_cb.rpa_tout * 1000; #endif - alarm_set_on_queue(p_cb->refresh_raddr_timer, interval_ms, - btm_ble_refresh_raddr_timer_timeout, NULL, - btu_general_alarm_queue); - } - else - { - /* random address set failure */ - BTM_TRACE_DEBUG("set random address failed"); - } + alarm_set_on_queue(p_cb->refresh_raddr_timer, interval_ms, + btm_ble_refresh_raddr_timer_timeout, NULL, + btu_general_alarm_queue); + } else { + /* random address set failure */ + BTM_TRACE_DEBUG("set random address failed"); + } } /******************************************************************************* * @@ -88,31 +83,27 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) * Returns void * ******************************************************************************/ -void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p) -{ - tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tSMP_ENC output; - - BTM_TRACE_EVENT ("btm_gen_resolve_paddr_low"); - if (p) - { - p->param_buf[2] &= (~BLE_RESOLVE_ADDR_MASK); - p->param_buf[2] |= BLE_RESOLVE_ADDR_MSB; - - p_cb->private_addr[2] = p->param_buf[0]; - p_cb->private_addr[1] = p->param_buf[1]; - p_cb->private_addr[0] = p->param_buf[2]; - - /* encrypt with ur IRK */ - if (!SMP_Encrypt(btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN, p->param_buf, 3, &output)) - { - btm_gen_resolve_paddr_cmpl(NULL); - } - else - { - btm_gen_resolve_paddr_cmpl(&output); - } +void btm_gen_resolve_paddr_low(tBTM_RAND_ENC* p) { + tBTM_LE_RANDOM_CB* p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tSMP_ENC output; + + BTM_TRACE_EVENT("btm_gen_resolve_paddr_low"); + if (p) { + p->param_buf[2] &= (~BLE_RESOLVE_ADDR_MASK); + p->param_buf[2] |= BLE_RESOLVE_ADDR_MSB; + + p_cb->private_addr[2] = p->param_buf[0]; + p_cb->private_addr[1] = p->param_buf[1]; + p_cb->private_addr[0] = p->param_buf[2]; + + /* encrypt with ur IRK */ + if (!SMP_Encrypt(btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN, p->param_buf, 3, + &output)) { + btm_gen_resolve_paddr_cmpl(NULL); + } else { + btm_gen_resolve_paddr_cmpl(&output); } + } } /******************************************************************************* * @@ -123,11 +114,10 @@ void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -void btm_gen_resolvable_private_addr(void *p_cmd_cplt_cback) -{ - BTM_TRACE_EVENT ("%s", __func__); - /* generate 3B rand as BD LSB, SRK with it, get BD MSB */ - btsnd_hcic_ble_rand(p_cmd_cplt_cback); +void btm_gen_resolvable_private_addr(void* p_cmd_cplt_cback) { + BTM_TRACE_EVENT("%s", __func__); + /* generate 3B rand as BD LSB, SRK with it, get BD MSB */ + btsnd_hcic_ble_rand(p_cmd_cplt_cback); } /******************************************************************************* * @@ -139,35 +129,28 @@ void btm_gen_resolvable_private_addr(void *p_cmd_cplt_cback) * Returns void * ******************************************************************************/ -static void btm_gen_non_resolve_paddr_cmpl(tBTM_RAND_ENC *p) -{ - tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tBTM_BLE_ADDR_CBACK *p_cback = p_cb->p_generate_cback; - void *p_data = p_cb->p; - uint8_t *pp; - BD_ADDR static_random; - - BTM_TRACE_EVENT ("btm_gen_non_resolve_paddr_cmpl"); - - p_cb->p_generate_cback = NULL; - if (p) - { - - pp = p->param_buf; - STREAM_TO_BDADDR(static_random, pp); - /* mask off the 2 MSB */ - static_random[0] &= BLE_STATIC_PRIVATE_MSB_MASK; - - /* report complete */ - if (p_cback) - (* p_cback)(static_random, p_data); - } - else - { - BTM_TRACE_DEBUG("btm_gen_non_resolvable_private_addr failed"); - if (p_cback) - (* p_cback)(NULL, p_data); - } +static void btm_gen_non_resolve_paddr_cmpl(tBTM_RAND_ENC* p) { + tBTM_LE_RANDOM_CB* p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tBTM_BLE_ADDR_CBACK* p_cback = p_cb->p_generate_cback; + void* p_data = p_cb->p; + uint8_t* pp; + BD_ADDR static_random; + + BTM_TRACE_EVENT("btm_gen_non_resolve_paddr_cmpl"); + + p_cb->p_generate_cback = NULL; + if (p) { + pp = p->param_buf; + STREAM_TO_BDADDR(static_random, pp); + /* mask off the 2 MSB */ + static_random[0] &= BLE_STATIC_PRIVATE_MSB_MASK; + + /* report complete */ + if (p_cback) (*p_cback)(static_random, p_data); + } else { + BTM_TRACE_DEBUG("btm_gen_non_resolvable_private_addr failed"); + if (p_cback) (*p_cback)(NULL, p_data); + } } /******************************************************************************* * @@ -179,18 +162,17 @@ static void btm_gen_non_resolve_paddr_cmpl(tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p) -{ - tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; +void btm_gen_non_resolvable_private_addr(tBTM_BLE_ADDR_CBACK* p_cback, + void* p) { + tBTM_LE_RANDOM_CB* p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - BTM_TRACE_EVENT ("btm_gen_non_resolvable_private_addr"); + BTM_TRACE_EVENT("btm_gen_non_resolvable_private_addr"); - if (p_mgnt_cb->p_generate_cback != NULL) - return; + if (p_mgnt_cb->p_generate_cback != NULL) return; - p_mgnt_cb->p_generate_cback = p_cback; - p_mgnt_cb->p = p; - btsnd_hcic_ble_rand((void *)btm_gen_non_resolve_paddr_cmpl); + p_mgnt_cb->p_generate_cback = p_cback; + p_mgnt_cb->p = p; + btsnd_hcic_ble_rand((void*)btm_gen_non_resolve_paddr_cmpl); } /******************************************************************************* @@ -206,26 +188,23 @@ void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p) * Returns true on match, false otherwise * ******************************************************************************/ -static bool btm_ble_proc_resolve_x(tSMP_ENC *p) -{ - tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - uint8_t comp[3]; - BTM_TRACE_EVENT ("btm_ble_proc_resolve_x"); - /* compare the hash with 3 LSB of bd address */ - comp[0] = p_mgnt_cb->random_bda[5]; - comp[1] = p_mgnt_cb->random_bda[4]; - comp[2] = p_mgnt_cb->random_bda[3]; - - if (p) - { - if (!memcmp(p->param_buf, &comp[0], 3)) - { - /* match is found */ - BTM_TRACE_EVENT ("match is found"); - return true; - } +static bool btm_ble_proc_resolve_x(tSMP_ENC* p) { + tBTM_LE_RANDOM_CB* p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + uint8_t comp[3]; + BTM_TRACE_EVENT("btm_ble_proc_resolve_x"); + /* compare the hash with 3 LSB of bd address */ + comp[0] = p_mgnt_cb->random_bda[5]; + comp[1] = p_mgnt_cb->random_bda[4]; + comp[2] = p_mgnt_cb->random_bda[3]; + + if (p) { + if (!memcmp(p->param_buf, &comp[0], 3)) { + /* match is found */ + BTM_TRACE_EVENT("match is found"); + return true; } - return false; + } + return false; } /******************************************************************************* @@ -238,17 +217,16 @@ static bool btm_ble_proc_resolve_x(tSMP_ENC *p) * Returns true is updated; false otherwise. * ******************************************************************************/ -bool btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr) -{ - BD_ADDR dummy_bda = {0}; - - if (memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN) == 0) - { - memcpy(p_dev_rec->ble.pseudo_addr, new_pseudo_addr, BD_ADDR_LEN); - return true; - } +bool btm_ble_init_pseudo_addr(tBTM_SEC_DEV_REC* p_dev_rec, + BD_ADDR new_pseudo_addr) { + BD_ADDR dummy_bda = {0}; - return false; + if (memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN) == 0) { + memcpy(p_dev_rec->ble.pseudo_addr, new_pseudo_addr, BD_ADDR_LEN); + return true; + } + + return false; } /******************************************************************************* @@ -261,39 +239,34 @@ bool btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseud * Returns true is resolvable; false otherwise. * ******************************************************************************/ -bool btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) -{ - bool rt = false; - - if (!BTM_BLE_IS_RESOLVE_BDA(rpa)) - return rt; - - uint8_t rand[3]; - tSMP_ENC output; - if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && - (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) - { - BTM_TRACE_DEBUG("%s try to resolve", __func__); - /* use the 3 MSB of bd address as prand */ - rand[0] = rpa[2]; - rand[1] = rpa[1]; - rand[2] = rpa[0]; - - /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ - SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, - &rand[0], 3, &output); - - rand[0] = rpa[5]; - rand[1] = rpa[4]; - rand[2] = rpa[3]; - - if (!memcmp(output.param_buf, &rand[0], 3)) - { - btm_ble_init_pseudo_addr (p_dev_rec, rpa); - rt = true; - } +bool btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC* p_dev_rec) { + bool rt = false; + + if (!BTM_BLE_IS_RESOLVE_BDA(rpa)) return rt; + + uint8_t rand[3]; + tSMP_ENC output; + if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && + (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) { + BTM_TRACE_DEBUG("%s try to resolve", __func__); + /* use the 3 MSB of bd address as prand */ + rand[0] = rpa[2]; + rand[1] = rpa[1]; + rand[2] = rpa[0]; + + /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ + SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, &rand[0], 3, &output); + + rand[0] = rpa[5]; + rand[1] = rpa[4]; + rand[2] = rpa[3]; + + if (!memcmp(output.param_buf, &rand[0], 3)) { + btm_ble_init_pseudo_addr(p_dev_rec, rpa); + rt = true; } - return rt; + } + return rt; } /******************************************************************************* @@ -308,33 +281,31 @@ bool btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) * Returns None. * ******************************************************************************/ -static bool btm_ble_match_random_bda(void *data, void *context) -{ - /* use the 3 MSB of bd address as prand */ +static bool btm_ble_match_random_bda(void* data, void* context) { + /* use the 3 MSB of bd address as prand */ - tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - uint8_t rand[3]; - rand[0] = p_mgnt_cb->random_bda[2]; - rand[1] = p_mgnt_cb->random_bda[1]; - rand[2] = p_mgnt_cb->random_bda[0]; + tBTM_LE_RANDOM_CB* p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + uint8_t rand[3]; + rand[0] = p_mgnt_cb->random_bda[2]; + rand[1] = p_mgnt_cb->random_bda[1]; + rand[2] = p_mgnt_cb->random_bda[0]; - BTM_TRACE_EVENT("%s next iteration", __func__); + BTM_TRACE_EVENT("%s next iteration", __func__); - tSMP_ENC output; - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); + tSMP_ENC output; + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); - BTM_TRACE_DEBUG("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, - p_dev_rec->device_type); + BTM_TRACE_DEBUG("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, + p_dev_rec->device_type); - if (!(p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) || - !(p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) - return true; + if (!(p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) || + !(p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) + return true; - /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ - SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, - &rand[0], 3, &output); - // if it was match, finish iteration, otherwise continue - return !btm_ble_proc_resolve_x(&output); + /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ + SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, &rand[0], 3, &output); + // if it was match, finish iteration, otherwise continue + return !btm_ble_proc_resolve_x(&output); } /******************************************************************************* @@ -347,30 +318,31 @@ static bool btm_ble_match_random_bda(void *data, void *context) * address is matched to. * ******************************************************************************/ -void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_cback, void *p) -{ - tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - - BTM_TRACE_EVENT("%s", __func__); - if ( !p_mgnt_cb->busy) { - p_mgnt_cb->p = p; - p_mgnt_cb->busy = true; - memcpy(p_mgnt_cb->random_bda, random_bda, BD_ADDR_LEN); - /* start to resolve random address */ - /* check for next security record */ - - list_node_t * n = list_foreach(btm_cb.sec_dev_rec, btm_ble_match_random_bda, NULL); - tBTM_SEC_DEV_REC *p_dev_rec = NULL; - if (n != NULL) - p_dev_rec = static_cast(list_node(n)); - - BTM_TRACE_EVENT("%s: %sresolved", __func__, (p_dev_rec == NULL ? "not " : "")); - p_mgnt_cb->busy = false; - - (*p_cback)(p_dev_rec, p); - } else { - (*p_cback)(NULL, p); - } +void btm_ble_resolve_random_addr(BD_ADDR random_bda, + tBTM_BLE_RESOLVE_CBACK* p_cback, void* p) { + tBTM_LE_RANDOM_CB* p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + + BTM_TRACE_EVENT("%s", __func__); + if (!p_mgnt_cb->busy) { + p_mgnt_cb->p = p; + p_mgnt_cb->busy = true; + memcpy(p_mgnt_cb->random_bda, random_bda, BD_ADDR_LEN); + /* start to resolve random address */ + /* check for next security record */ + + list_node_t* n = + list_foreach(btm_cb.sec_dev_rec, btm_ble_match_random_bda, NULL); + tBTM_SEC_DEV_REC* p_dev_rec = NULL; + if (n != NULL) p_dev_rec = static_cast(list_node(n)); + + BTM_TRACE_EVENT("%s: %sresolved", __func__, + (p_dev_rec == NULL ? "not " : "")); + p_mgnt_cb->busy = false; + + (*p_cback)(p_dev_rec, p); + } else { + (*p_cback)(NULL, p); + } } /******************************************************************************* @@ -383,26 +355,28 @@ void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_ * Description find the security record whose LE static address is matching * ******************************************************************************/ -tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(BD_ADDR bd_addr, uint8_t addr_type) -{ +tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(BD_ADDR bd_addr, + uint8_t addr_type) { #if (BLE_PRIVACY_SPT == TRUE) - list_node_t *end = list_end(btm_cb.sec_dev_rec); - for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) { - tBTM_SEC_DEV_REC *p_dev_rec = - static_cast(list_node(node)); - if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { - if ((p_dev_rec->ble.static_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) != - (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) - BTM_TRACE_WARNING("%s find pseudo->random match with diff addr type: %d vs %d", - __func__, p_dev_rec->ble.static_addr_type, addr_type); - - /* found the match */ - return p_dev_rec; - } + list_node_t* end = list_end(btm_cb.sec_dev_rec); + for (list_node_t* node = list_begin(btm_cb.sec_dev_rec); node != end; + node = list_next(node)) { + tBTM_SEC_DEV_REC* p_dev_rec = + static_cast(list_node(node)); + if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { + if ((p_dev_rec->ble.static_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) != + (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) + BTM_TRACE_WARNING( + "%s find pseudo->random match with diff addr type: %d vs %d", + __func__, p_dev_rec->ble.static_addr_type, addr_type); + + /* found the match */ + return p_dev_rec; } + } #endif - return NULL; + return NULL; } /******************************************************************************* @@ -413,28 +387,29 @@ tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(BD_ADDR bd_addr, uint8_t addr_ty * address in security database. * ******************************************************************************/ -bool btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, uint8_t *p_addr_type, bool refresh) -{ +bool btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, uint8_t* p_addr_type, + bool refresh) { #if (BLE_PRIVACY_SPT == TRUE) - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_identity_addr(bd_addr, *p_addr_type); - - BTM_TRACE_EVENT ("%s", __func__); - /* evt reported on static address, map static address to random pseudo */ - if (p_dev_rec != NULL) - { - /* if RPA offloading is supported, or 4.2 controller, do RPA refresh */ - if (refresh && controller_get_interface()->get_ble_resolving_list_max_size() != 0) - btm_ble_read_resolving_list_entry(p_dev_rec); - - /* assign the original address to be the current report address */ - if (!btm_ble_init_pseudo_addr (p_dev_rec, bd_addr)) - memcpy(bd_addr, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); - - *p_addr_type = p_dev_rec->ble.ble_addr_type; - return true; - } + tBTM_SEC_DEV_REC* p_dev_rec = + btm_find_dev_by_identity_addr(bd_addr, *p_addr_type); + + BTM_TRACE_EVENT("%s", __func__); + /* evt reported on static address, map static address to random pseudo */ + if (p_dev_rec != NULL) { + /* if RPA offloading is supported, or 4.2 controller, do RPA refresh */ + if (refresh && + controller_get_interface()->get_ble_resolving_list_max_size() != 0) + btm_ble_read_resolving_list_entry(p_dev_rec); + + /* assign the original address to be the current report address */ + if (!btm_ble_init_pseudo_addr(p_dev_rec, bd_addr)) + memcpy(bd_addr, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN); + + *p_addr_type = p_dev_rec->ble.ble_addr_type; + return true; + } #endif - return false; + return false; } /******************************************************************************* @@ -445,24 +420,22 @@ bool btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, uint8_t *p_addr_type * address. random_pseudo is input and output parameter * ******************************************************************************/ -bool btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, uint8_t *p_static_addr_type) -{ +bool btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, + uint8_t* p_static_addr_type) { #if (BLE_PRIVACY_SPT == TRUE) - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (random_pseudo); - - if (p_dev_rec != NULL) - { - if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) - { - * p_static_addr_type = p_dev_rec->ble.static_addr_type; - memcpy(random_pseudo, p_dev_rec->ble.static_addr, BD_ADDR_LEN); - if (controller_get_interface()->supports_ble_privacy()) - *p_static_addr_type |= BLE_ADDR_TYPE_ID_BIT; - return true; - } + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(random_pseudo); + + if (p_dev_rec != NULL) { + if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { + *p_static_addr_type = p_dev_rec->ble.static_addr_type; + memcpy(random_pseudo, p_dev_rec->ble.static_addr, BD_ADDR_LEN); + if (controller_get_interface()->supports_ble_privacy()) + *p_static_addr_type |= BLE_ADDR_TYPE_ID_BIT; + return true; } + } #endif - return false; + return false; } /******************************************************************************* @@ -474,70 +447,62 @@ bool btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, uint8_t *p_sta * connection address. * ******************************************************************************/ -void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rpa, - uint8_t rra_type) -{ +void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, + BD_ADDR rpa, + uint8_t rra_type) { #if (BLE_PRIVACY_SPT == TRUE) - uint8_t rra_dummy = false; - BD_ADDR dummy_bda = {0}; - - if (memcmp(dummy_bda, rpa, BD_ADDR_LEN) == 0) - rra_dummy = true; - - /* update security record here, in adv event or connection complete process */ - tBTM_SEC_DEV_REC *p_sec_rec = btm_find_dev(pseudo_bda); - if (p_sec_rec != NULL) - { - memcpy(p_sec_rec->ble.cur_rand_addr, rpa, BD_ADDR_LEN); - - /* unknown, if dummy address, set to static */ - if (rra_type == BTM_BLE_ADDR_PSEUDO) - p_sec_rec->ble.active_addr_type = rra_dummy ? BTM_BLE_ADDR_STATIC: BTM_BLE_ADDR_RRA; - else - p_sec_rec->ble.active_addr_type = rra_type; - } + uint8_t rra_dummy = false; + BD_ADDR dummy_bda = {0}; + + if (memcmp(dummy_bda, rpa, BD_ADDR_LEN) == 0) rra_dummy = true; + + /* update security record here, in adv event or connection complete process */ + tBTM_SEC_DEV_REC* p_sec_rec = btm_find_dev(pseudo_bda); + if (p_sec_rec != NULL) { + memcpy(p_sec_rec->ble.cur_rand_addr, rpa, BD_ADDR_LEN); + + /* unknown, if dummy address, set to static */ + if (rra_type == BTM_BLE_ADDR_PSEUDO) + p_sec_rec->ble.active_addr_type = + rra_dummy ? BTM_BLE_ADDR_STATIC : BTM_BLE_ADDR_RRA; else - { - BTM_TRACE_ERROR("No matching known device in record"); - return; + p_sec_rec->ble.active_addr_type = rra_type; + } else { + BTM_TRACE_ERROR("No matching known device in record"); + return; + } + + BTM_TRACE_DEBUG("%s: active_addr_type: %d ", __func__, + p_sec_rec->ble.active_addr_type); + + /* connection refresh remote address */ + tACL_CONN* p_acl = btm_bda_to_acl(p_sec_rec->bd_addr, BT_TRANSPORT_LE); + if (p_acl == NULL) + p_acl = btm_bda_to_acl(p_sec_rec->ble.pseudo_addr, BT_TRANSPORT_LE); + + if (p_acl != NULL) { + if (rra_type == BTM_BLE_ADDR_PSEUDO) { + /* use static address, resolvable_private_addr is empty */ + if (rra_dummy) { + p_acl->active_remote_addr_type = p_sec_rec->ble.static_addr_type; + memcpy(p_acl->active_remote_addr, p_sec_rec->ble.static_addr, + BD_ADDR_LEN); + } else { + p_acl->active_remote_addr_type = BLE_ADDR_RANDOM; + memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN); + } + } else { + p_acl->active_remote_addr_type = rra_type; + memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN); } - BTM_TRACE_DEBUG("%s: active_addr_type: %d ", - __func__, p_sec_rec->ble.active_addr_type); - - /* connection refresh remote address */ - tACL_CONN *p_acl = btm_bda_to_acl(p_sec_rec->bd_addr, BT_TRANSPORT_LE); - if (p_acl == NULL) - p_acl = btm_bda_to_acl(p_sec_rec->ble.pseudo_addr, BT_TRANSPORT_LE); - - if (p_acl != NULL) - { - if (rra_type == BTM_BLE_ADDR_PSEUDO) - { - /* use static address, resolvable_private_addr is empty */ - if (rra_dummy) - { - p_acl->active_remote_addr_type = p_sec_rec->ble.static_addr_type; - memcpy(p_acl->active_remote_addr, p_sec_rec->ble.static_addr, BD_ADDR_LEN); - } - else - { - p_acl->active_remote_addr_type = BLE_ADDR_RANDOM; - memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN); - } - } - else - { - p_acl->active_remote_addr_type = rra_type; - memcpy(p_acl->active_remote_addr, rpa, BD_ADDR_LEN); - } - - BTM_TRACE_DEBUG("p_acl->active_remote_addr_type: %d ", p_acl->active_remote_addr_type); - BTM_TRACE_DEBUG("%s conn_addr: %02x:%02x:%02x:%02x:%02x:%02x", - __func__,p_acl->active_remote_addr[0], p_acl->active_remote_addr[1], - p_acl->active_remote_addr[2], p_acl->active_remote_addr[3], - p_acl->active_remote_addr[4], p_acl->active_remote_addr[5]); - } + BTM_TRACE_DEBUG("p_acl->active_remote_addr_type: %d ", + p_acl->active_remote_addr_type); + BTM_TRACE_DEBUG("%s conn_addr: %02x:%02x:%02x:%02x:%02x:%02x", __func__, + p_acl->active_remote_addr[0], p_acl->active_remote_addr[1], + p_acl->active_remote_addr[2], p_acl->active_remote_addr[3], + p_acl->active_remote_addr[4], p_acl->active_remote_addr[5]); + } #endif } @@ -550,29 +515,24 @@ void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rp * ******************************************************************************/ void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, - BD_ADDR local_rpa) -{ + BD_ADDR local_rpa) { #if (BLE_PRIVACY_SPT == TRUE) - tACL_CONN *p = btm_bda_to_acl(pseudo_addr, BT_TRANSPORT_LE); - BD_ADDR dummy_bda = {0}; - - if (p != NULL) - { - if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) - { - p->conn_addr_type = BLE_ADDR_RANDOM; - if (memcmp(local_rpa, dummy_bda, BD_ADDR_LEN)) - memcpy(p->conn_addr, local_rpa, BD_ADDR_LEN); - else - memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN); - } - else - { - p->conn_addr_type = BLE_ADDR_PUBLIC; - memcpy(p->conn_addr,&controller_get_interface()->get_address()->address, BD_ADDR_LEN); - } + tACL_CONN* p = btm_bda_to_acl(pseudo_addr, BT_TRANSPORT_LE); + BD_ADDR dummy_bda = {0}; + + if (p != NULL) { + if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { + p->conn_addr_type = BLE_ADDR_RANDOM; + if (memcmp(local_rpa, dummy_bda, BD_ADDR_LEN)) + memcpy(p->conn_addr, local_rpa, BD_ADDR_LEN); + else + memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, + BD_ADDR_LEN); + } else { + p->conn_addr_type = BLE_ADDR_PUBLIC; + memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, + BD_ADDR_LEN); } + } #endif } - - diff --git a/stack/btm/btm_ble_adv_filter.cc b/stack/btm/btm_ble_adv_filter.cc index 85e3f6845..f1c78a5ff 100644 --- a/stack/btm/btm_ble_adv_filter.cc +++ b/stack/btm/btm_ble_adv_filter.cc @@ -32,42 +32,44 @@ #include "hcimsgs.h" #define BTM_BLE_ADV_FILT_META_HDR_LENGTH 3 -#define BTM_BLE_ADV_FILT_FEAT_SELN_LEN 13 -#define BTM_BLE_ADV_FILT_TRACK_NUM 2 +#define BTM_BLE_ADV_FILT_FEAT_SELN_LEN 13 +#define BTM_BLE_ADV_FILT_TRACK_NUM 2 -#define BTM_BLE_PF_SELECT_NONE 0 +#define BTM_BLE_PF_SELECT_NONE 0 /* BLE meta vsc header: 1 bytes of sub_code, 1 byte of PCF action */ -#define BTM_BLE_META_HDR_LENGTH 3 -#define BTM_BLE_PF_FEAT_SEL_LEN 18 -#define BTM_BLE_PCF_ENABLE_LEN 2 +#define BTM_BLE_META_HDR_LENGTH 3 +#define BTM_BLE_PF_FEAT_SEL_LEN 18 +#define BTM_BLE_PCF_ENABLE_LEN 2 -#define BTM_BLE_META_ADDR_LEN 7 -#define BTM_BLE_META_UUID_LEN 40 +#define BTM_BLE_META_ADDR_LEN 7 +#define BTM_BLE_META_UUID_LEN 40 -#define BTM_BLE_PF_BIT_TO_MASK(x) (uint16_t)(1 << (x)) +#define BTM_BLE_PF_BIT_TO_MASK(x) (uint16_t)(1 << (x)) tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb; tBTM_BLE_VSC_CB cmn_ble_vsc_cb; -static const BD_ADDR na_bda= {0}; +static const BD_ADDR na_bda = {0}; static uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, - uint8_t cond_type, tBLE_BD_ADDR *p_bd_addr, uint8_t num_available); + uint8_t cond_type, + tBLE_BD_ADDR* p_bd_addr, + uint8_t num_available); -#define BTM_BLE_SET_SCAN_PF_OPCODE(x, y) (((x)<<4)|(y)) -#define BTM_BLE_GET_SCAN_PF_SUBCODE(x) ((x) >> 4) -#define BTM_BLE_GET_SCAN_PF_ACTION(x) ((x) & 0x0f) -#define BTM_BLE_INVALID_COUNTER 0xff +#define BTM_BLE_SET_SCAN_PF_OPCODE(x, y) (((x) << 4) | (y)) +#define BTM_BLE_GET_SCAN_PF_SUBCODE(x) ((x) >> 4) +#define BTM_BLE_GET_SCAN_PF_ACTION(x) ((x)&0x0f) +#define BTM_BLE_INVALID_COUNTER 0xff /* length of each multi adv sub command */ -#define BTM_BLE_ADV_FILTER_ENB_LEN 3 +#define BTM_BLE_ADV_FILTER_ENB_LEN 3 /* length of each batch scan command */ -#define BTM_BLE_ADV_FILTER_CLEAR_LEN 3 -#define BTM_BLE_ADV_FILTER_LEN 2 +#define BTM_BLE_ADV_FILTER_CLEAR_LEN 3 +#define BTM_BLE_ADV_FILTER_LEN 2 -#define BTM_BLE_ADV_FILT_CB_EVT_MASK 0xF0 -#define BTM_BLE_ADV_FILT_SUBCODE_MASK 0x0F +#define BTM_BLE_ADV_FILT_CB_EVT_MASK 0xF0 +#define BTM_BLE_ADV_FILT_SUBCODE_MASK 0x0F /******************************************************************************* * @@ -80,21 +82,19 @@ static uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, * Returns status * ******************************************************************************/ -tBTM_STATUS btm_ble_obtain_vsc_details() -{ - tBTM_STATUS st = BTM_SUCCESS; +tBTM_STATUS btm_ble_obtain_vsc_details() { + tBTM_STATUS st = BTM_SUCCESS; #if (BLE_VND_INCLUDED == TRUE) - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - if (0 == cmn_ble_vsc_cb.max_filter) - { - st = BTM_MODE_UNSUPPORTED; - return st; - } + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + if (0 == cmn_ble_vsc_cb.max_filter) { + st = BTM_MODE_UNSUPPORTED; + return st; + } #else - cmn_ble_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER; + cmn_ble_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER; #endif - return st; + return st; } /******************************************************************************* @@ -107,21 +107,27 @@ tBTM_STATUS btm_ble_obtain_vsc_details() * Returns void * ******************************************************************************/ -void btm_ble_advfilt_enq_op_q(uint8_t action, uint8_t ocf, tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref, tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback) -{ - btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx] = (action |(ocf << 4)); - btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.next_idx] = ref; - btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.next_idx] = cb_evt; - btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.next_idx] = p_cmpl_cback; - btm_ble_adv_filt_cb.op_q.p_filt_param_cback[btm_ble_adv_filt_cb.op_q.next_idx] - = p_filt_param_cback; - BTM_TRACE_DEBUG("btm_ble_advfilt_enq_op_q: act_ocf:%d, action:%d, ocf:%d,cb_evt;%d, cback:%x", - btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx], action, - ocf, cb_evt, p_cmpl_cback); - btm_ble_adv_filt_cb.op_q.next_idx = (btm_ble_adv_filt_cb.op_q.next_idx + 1) - % BTM_BLE_PF_TYPE_MAX; +void btm_ble_advfilt_enq_op_q(uint8_t action, uint8_t ocf, + tBTM_BLE_FILT_CB_EVT cb_evt, + tBTM_BLE_REF_VALUE ref, + tBTM_BLE_PF_CFG_CBACK* p_cmpl_cback, + tBTM_BLE_PF_PARAM_CBACK* p_filt_param_cback) { + btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx] = + (action | (ocf << 4)); + btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.next_idx] = ref; + btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.next_idx] = cb_evt; + btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.next_idx] = + p_cmpl_cback; + btm_ble_adv_filt_cb.op_q + .p_filt_param_cback[btm_ble_adv_filt_cb.op_q.next_idx] = + p_filt_param_cback; + BTM_TRACE_DEBUG( + "btm_ble_advfilt_enq_op_q: act_ocf:%d, action:%d, ocf:%d,cb_evt;%d, " + "cback:%x", + btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx], + action, ocf, cb_evt, p_cmpl_cback); + btm_ble_adv_filt_cb.op_q.next_idx = + (btm_ble_adv_filt_cb.op_q.next_idx + 1) % BTM_BLE_PF_TYPE_MAX; } /******************************************************************************* @@ -134,23 +140,32 @@ void btm_ble_advfilt_enq_op_q(uint8_t action, uint8_t ocf, tBTM_BLE_FILT_CB_EVT * Returns void * ******************************************************************************/ -void btm_ble_advfilt_deq_op_q(uint8_t *p_action,uint8_t *p_ocf, tBTM_BLE_FILT_CB_EVT *p_cb_evt, - tBTM_BLE_REF_VALUE *p_ref, tBTM_BLE_PF_CFG_CBACK ** p_cmpl_cback, - tBTM_BLE_PF_PARAM_CBACK **p_filt_param_cback) -{ - *p_ocf = (btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] >> 4); - *p_action = (btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] - & BTM_BLE_ADV_FILT_SUBCODE_MASK); - *p_ref = btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_cb_evt = btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_cmpl_cback = btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_filt_param_cback = - btm_ble_adv_filt_cb.op_q.p_filt_param_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; - - btm_ble_adv_filt_cb.op_q.pending_idx = (btm_ble_adv_filt_cb.op_q.pending_idx + 1) - % BTM_BLE_PF_TYPE_MAX; - BTM_TRACE_DEBUG("btm_ble_advfilt_deq_op_q: ocf:%d, action:%d, ref_value:%d, cb_evt:%x", - *p_ocf,*p_action, *p_ref, *p_cb_evt); +void btm_ble_advfilt_deq_op_q(uint8_t* p_action, uint8_t* p_ocf, + tBTM_BLE_FILT_CB_EVT* p_cb_evt, + tBTM_BLE_REF_VALUE* p_ref, + tBTM_BLE_PF_CFG_CBACK** p_cmpl_cback, + tBTM_BLE_PF_PARAM_CBACK** p_filt_param_cback) { + *p_ocf = (btm_ble_adv_filt_cb.op_q + .action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] >> + 4); + *p_action = (btm_ble_adv_filt_cb.op_q + .action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] & + BTM_BLE_ADV_FILT_SUBCODE_MASK); + *p_ref = + btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.pending_idx]; + *p_cb_evt = + btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.pending_idx]; + *p_cmpl_cback = btm_ble_adv_filt_cb.op_q + .p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; + *p_filt_param_cback = + btm_ble_adv_filt_cb.op_q + .p_filt_param_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; + + btm_ble_adv_filt_cb.op_q.pending_idx = + (btm_ble_adv_filt_cb.op_q.pending_idx + 1) % BTM_BLE_PF_TYPE_MAX; + BTM_TRACE_DEBUG( + "btm_ble_advfilt_deq_op_q: ocf:%d, action:%d, ref_value:%d, cb_evt:%x", + *p_ocf, *p_action, *p_ref, *p_cb_evt); } /******************************************************************************* @@ -162,38 +177,36 @@ void btm_ble_advfilt_deq_op_q(uint8_t *p_action,uint8_t *p_ocf, tBTM_BLE_FILT_CB * Returns Returns ocf value * ******************************************************************************/ -uint8_t btm_ble_condtype_to_ocf(uint8_t cond_type) -{ - uint8_t ocf = 0; - - switch(cond_type) - { - case BTM_BLE_PF_ADDR_FILTER: - ocf = BTM_BLE_META_PF_ADDR; - break; - case BTM_BLE_PF_SRVC_UUID: - ocf = BTM_BLE_META_PF_UUID; - break; - case BTM_BLE_PF_SRVC_SOL_UUID: - ocf = BTM_BLE_META_PF_SOL_UUID; - break; - case BTM_BLE_PF_LOCAL_NAME: - ocf = BTM_BLE_META_PF_LOCAL_NAME; - break; - case BTM_BLE_PF_MANU_DATA: - ocf = BTM_BLE_META_PF_MANU_DATA; - break; - case BTM_BLE_PF_SRVC_DATA_PATTERN: - ocf = BTM_BLE_META_PF_SRVC_DATA; - break; - case BTM_BLE_PF_TYPE_ALL: - ocf = BTM_BLE_META_PF_ALL; - break; - default: - ocf = BTM_BLE_PF_TYPE_MAX; - break; - } - return ocf; +uint8_t btm_ble_condtype_to_ocf(uint8_t cond_type) { + uint8_t ocf = 0; + + switch (cond_type) { + case BTM_BLE_PF_ADDR_FILTER: + ocf = BTM_BLE_META_PF_ADDR; + break; + case BTM_BLE_PF_SRVC_UUID: + ocf = BTM_BLE_META_PF_UUID; + break; + case BTM_BLE_PF_SRVC_SOL_UUID: + ocf = BTM_BLE_META_PF_SOL_UUID; + break; + case BTM_BLE_PF_LOCAL_NAME: + ocf = BTM_BLE_META_PF_LOCAL_NAME; + break; + case BTM_BLE_PF_MANU_DATA: + ocf = BTM_BLE_META_PF_MANU_DATA; + break; + case BTM_BLE_PF_SRVC_DATA_PATTERN: + ocf = BTM_BLE_META_PF_SRVC_DATA; + break; + case BTM_BLE_PF_TYPE_ALL: + ocf = BTM_BLE_META_PF_ALL; + break; + default: + ocf = BTM_BLE_PF_TYPE_MAX; + break; + } + return ocf; } /******************************************************************************* @@ -205,41 +218,39 @@ uint8_t btm_ble_condtype_to_ocf(uint8_t cond_type) * Returns Returns condtype value * ******************************************************************************/ -uint8_t btm_ble_ocf_to_condtype(uint8_t ocf) -{ - uint8_t cond_type = 0; - - switch(ocf) - { - case BTM_BLE_META_PF_FEAT_SEL: - cond_type = BTM_BLE_META_PF_FEAT_SEL; - break; - case BTM_BLE_META_PF_ADDR: - cond_type = BTM_BLE_PF_ADDR_FILTER; - break; - case BTM_BLE_META_PF_UUID: - cond_type = BTM_BLE_PF_SRVC_UUID; - break; - case BTM_BLE_META_PF_SOL_UUID: - cond_type = BTM_BLE_PF_SRVC_SOL_UUID; - break; - case BTM_BLE_META_PF_LOCAL_NAME: - cond_type = BTM_BLE_PF_LOCAL_NAME; - break; - case BTM_BLE_META_PF_MANU_DATA: - cond_type = BTM_BLE_PF_MANU_DATA; - break; - case BTM_BLE_META_PF_SRVC_DATA: - cond_type = BTM_BLE_PF_SRVC_DATA_PATTERN; - break; - case BTM_BLE_META_PF_ALL: - cond_type = BTM_BLE_PF_TYPE_ALL; - break; - default: - cond_type = BTM_BLE_PF_TYPE_MAX; - break; - } - return cond_type; +uint8_t btm_ble_ocf_to_condtype(uint8_t ocf) { + uint8_t cond_type = 0; + + switch (ocf) { + case BTM_BLE_META_PF_FEAT_SEL: + cond_type = BTM_BLE_META_PF_FEAT_SEL; + break; + case BTM_BLE_META_PF_ADDR: + cond_type = BTM_BLE_PF_ADDR_FILTER; + break; + case BTM_BLE_META_PF_UUID: + cond_type = BTM_BLE_PF_SRVC_UUID; + break; + case BTM_BLE_META_PF_SOL_UUID: + cond_type = BTM_BLE_PF_SRVC_SOL_UUID; + break; + case BTM_BLE_META_PF_LOCAL_NAME: + cond_type = BTM_BLE_PF_LOCAL_NAME; + break; + case BTM_BLE_META_PF_MANU_DATA: + cond_type = BTM_BLE_PF_MANU_DATA; + break; + case BTM_BLE_META_PF_SRVC_DATA: + cond_type = BTM_BLE_PF_SRVC_DATA_PATTERN; + break; + case BTM_BLE_META_PF_ALL: + cond_type = BTM_BLE_PF_TYPE_ALL; + break; + default: + cond_type = BTM_BLE_PF_TYPE_MAX; + break; + } + return cond_type; } /******************************************************************************* @@ -252,108 +263,108 @@ uint8_t btm_ble_ocf_to_condtype(uint8_t ocf) * Returns pointer to the counter if found; NULL otherwise. * ******************************************************************************/ -void btm_ble_scan_pf_cmpl_cback(tBTM_VSC_CMPL *p_params) -{ - uint8_t status = 0; - uint8_t *p = p_params->p_param_buf, op_subcode = 0, action = 0xff; - uint16_t evt_len = p_params->param_len; - uint8_t ocf = BTM_BLE_META_PF_ALL, cond_type = 0; - uint8_t num_avail = 0, cb_evt = 0; - tBTM_BLE_REF_VALUE ref_value = 0; - tBTM_BLE_PF_CFG_CBACK *p_scan_cfg_cback = NULL; - tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback = NULL; - - if (evt_len < 3 || evt_len > 4) - { - BTM_TRACE_ERROR("%s cannot interpret APCF callback status = %d, length = %d", - __func__, status, evt_len); - btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, &p_scan_cfg_cback, - &p_filt_param_cback); - return; +void btm_ble_scan_pf_cmpl_cback(tBTM_VSC_CMPL* p_params) { + uint8_t status = 0; + uint8_t *p = p_params->p_param_buf, op_subcode = 0, action = 0xff; + uint16_t evt_len = p_params->param_len; + uint8_t ocf = BTM_BLE_META_PF_ALL, cond_type = 0; + uint8_t num_avail = 0, cb_evt = 0; + tBTM_BLE_REF_VALUE ref_value = 0; + tBTM_BLE_PF_CFG_CBACK* p_scan_cfg_cback = NULL; + tBTM_BLE_PF_PARAM_CBACK* p_filt_param_cback = NULL; + + if (evt_len < 3 || evt_len > 4) { + BTM_TRACE_ERROR( + "%s cannot interpret APCF callback status = %d, length = %d", __func__, + status, evt_len); + btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, + &p_scan_cfg_cback, &p_filt_param_cback); + return; + } + + btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, + &p_scan_cfg_cback, &p_filt_param_cback); + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT8(op_subcode, p); + STREAM_TO_UINT8(action, p); + + /* Ignore the event, if it is not the same one expected */ + if (3 == evt_len) { + if (ocf != op_subcode) { + BTM_TRACE_ERROR( + "btm_ble_scan_pf_cmpl_cback:3-Incorrect opcode :%d, %d, %d, %d, %d, " + "%d", + ocf, op_subcode, action, evt_len, ref_value, status); + return; + } else { + if (NULL != btm_ble_adv_filt_cb.p_filt_stat_cback) + btm_ble_adv_filt_cb.p_filt_stat_cback(action, status, ref_value); + BTM_TRACE_DEBUG( + "btm_ble_scan_pf_cmpl_cback enabled/disabled, %d, %d, %d, %d", ocf, + action, status, ref_value); + return; } - - btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, &p_scan_cfg_cback, - &p_filt_param_cback); - - STREAM_TO_UINT8(status, p); - STREAM_TO_UINT8(op_subcode, p); - STREAM_TO_UINT8(action, p); - - /* Ignore the event, if it is not the same one expected */ - if (3 == evt_len) - { - if(ocf != op_subcode) - { - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback:3-Incorrect opcode :%d, %d, %d, %d, %d, %d", - ocf, op_subcode, action, evt_len, ref_value, status); - return; - } + } + + if (4 == evt_len && ocf != op_subcode) { + BTM_TRACE_ERROR( + "btm_ble_scan_pf_cmpl_cback:4-Incorrect opcode: %d, %d, %d, %d, %d", + ocf, op_subcode, action, status, ref_value); + return; + } + + STREAM_TO_UINT8(num_avail, p); + switch (op_subcode) { + case BTM_BLE_META_PF_ADDR: + case BTM_BLE_META_PF_UUID: + case BTM_BLE_META_PF_SOL_UUID: + case BTM_BLE_META_PF_LOCAL_NAME: + case BTM_BLE_META_PF_MANU_DATA: + case BTM_BLE_META_PF_SRVC_DATA: + cond_type = btm_ble_ocf_to_condtype(ocf); + BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback Recd: %d, %d, %d, %d, %d, %d", + op_subcode, ocf, action, status, ref_value, num_avail); + if (HCI_SUCCESS == status) { + if (memcmp(&btm_ble_adv_filt_cb.cur_filter_target.bda, &na_bda, + BD_ADDR_LEN) == 0) + btm_ble_cs_update_pf_counter(action, cond_type, NULL, num_avail); else - { - if(NULL != btm_ble_adv_filt_cb.p_filt_stat_cback) - btm_ble_adv_filt_cb.p_filt_stat_cback(action, status, ref_value); - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback enabled/disabled, %d, %d, %d, %d", - ocf, action, status, ref_value); - return; - } - } - - if (4 == evt_len && ocf != op_subcode) - { - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback:4-Incorrect opcode: %d, %d, %d, %d, %d", - ocf, op_subcode, action, status, ref_value); - return; - } - - STREAM_TO_UINT8(num_avail, p); - switch (op_subcode) - { - case BTM_BLE_META_PF_ADDR: - case BTM_BLE_META_PF_UUID: - case BTM_BLE_META_PF_SOL_UUID: - case BTM_BLE_META_PF_LOCAL_NAME: - case BTM_BLE_META_PF_MANU_DATA: - case BTM_BLE_META_PF_SRVC_DATA: - cond_type = btm_ble_ocf_to_condtype(ocf); - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback Recd: %d, %d, %d, %d, %d, %d", op_subcode, - ocf, action, status, ref_value, num_avail); - if (HCI_SUCCESS == status) - { - if (memcmp(&btm_ble_adv_filt_cb.cur_filter_target.bda, &na_bda, BD_ADDR_LEN) == 0) - btm_ble_cs_update_pf_counter(action, cond_type, NULL, num_avail); - else - btm_ble_cs_update_pf_counter(action, cond_type, - &btm_ble_adv_filt_cb.cur_filter_target, num_avail); - } - - /* send ADV PF operation complete */ - btm_ble_adv_filt_cb.op_type = 0; - break; - - case BTM_BLE_META_PF_FEAT_SEL: - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback-Feat sel event: %d, %d, %d, %d", - action, status, ref_value, num_avail); - break; - - default: - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback: unknown operation: %d", op_subcode); - break; - } - - switch(cb_evt) - { - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback: calling the cback: %d", cb_evt); - case BTM_BLE_FILT_CFG: - if(NULL != p_scan_cfg_cback) - p_scan_cfg_cback(action, cond_type, num_avail, status, ref_value); - break; - case BTM_BLE_FILT_ADV_PARAM: - if(NULL != p_filt_param_cback) - p_filt_param_cback(action, num_avail, ref_value, status); - break; - default: - break; - } + btm_ble_cs_update_pf_counter(action, cond_type, + &btm_ble_adv_filt_cb.cur_filter_target, + num_avail); + } + + /* send ADV PF operation complete */ + btm_ble_adv_filt_cb.op_type = 0; + break; + + case BTM_BLE_META_PF_FEAT_SEL: + BTM_TRACE_DEBUG( + "btm_ble_scan_pf_cmpl_cback-Feat sel event: %d, %d, %d, %d", action, + status, ref_value, num_avail); + break; + + default: + BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback: unknown operation: %d", + op_subcode); + break; + } + + switch (cb_evt) { + BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback: calling the cback: %d", + cb_evt); + case BTM_BLE_FILT_CFG: + if (NULL != p_scan_cfg_cback) + p_scan_cfg_cback(action, cond_type, num_avail, status, ref_value); + break; + case BTM_BLE_FILT_ADV_PARAM: + if (NULL != p_filt_param_cback) + p_filt_param_cback(action, num_avail, ref_value, status); + break; + default: + break; + } } /******************************************************************************* @@ -366,23 +377,20 @@ void btm_ble_scan_pf_cmpl_cback(tBTM_VSC_CMPL *p_params) * Returns pointer to the counter if found; NULL otherwise. * ******************************************************************************/ -tBTM_BLE_PF_COUNT* btm_ble_find_addr_filter_counter(tBLE_BD_ADDR *p_le_bda) -{ - uint8_t i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; +tBTM_BLE_PF_COUNT* btm_ble_find_addr_filter_counter(tBLE_BD_ADDR* p_le_bda) { + uint8_t i; + tBTM_BLE_PF_COUNT* p_addr_filter = + &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - if (p_le_bda == NULL) - return &btm_ble_adv_filt_cb.p_addr_filter_count[0]; + if (p_le_bda == NULL) return &btm_ble_adv_filt_cb.p_addr_filter_count[0]; - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) - { - if (p_addr_filter->in_use && - memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) - { - return p_addr_filter; - } + for (i = 0; i < cmn_ble_vsc_cb.max_filter; i++, p_addr_filter++) { + if (p_addr_filter->in_use && + memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { + return p_addr_filter; } - return NULL; + } + return NULL; } /******************************************************************************* @@ -395,21 +403,19 @@ tBTM_BLE_PF_COUNT* btm_ble_find_addr_filter_counter(tBLE_BD_ADDR *p_le_bda) * otherwise. * ******************************************************************************/ -tBTM_BLE_PF_COUNT * btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr) -{ - uint8_t i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) - { - if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) - { - memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN); - p_addr_filter->in_use = true; - return p_addr_filter; - } +tBTM_BLE_PF_COUNT* btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr) { + uint8_t i; + tBTM_BLE_PF_COUNT* p_addr_filter = + &btm_ble_adv_filt_cb.p_addr_filter_count[1]; + + for (i = 0; i < cmn_ble_vsc_cb.max_filter; i++, p_addr_filter++) { + if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { + memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN); + p_addr_filter->in_use = true; + return p_addr_filter; } - return NULL; + } + return NULL; } /******************************************************************************* * @@ -420,28 +426,29 @@ tBTM_BLE_PF_COUNT * btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr) * Returns true if deallocation succeed; false otherwise. * ******************************************************************************/ -bool btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, uint8_t filter_type) -{ - uint8_t i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - bool found = false; - - if (BTM_BLE_PF_TYPE_ALL == filter_type && NULL == p_bd_addr) - memset(&btm_ble_adv_filt_cb.p_addr_filter_count[0], 0, sizeof(tBTM_BLE_PF_COUNT)); - - for (i = 0; i < cmn_ble_vsc_cb.max_filter; i ++, p_addr_filter ++) - { - if ((p_addr_filter->in_use) && (NULL == p_bd_addr || - (NULL != p_bd_addr && - memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) - { - found = true; - memset(p_addr_filter, 0, sizeof(tBTM_BLE_PF_COUNT)); - - if (NULL != p_bd_addr) break; - } +bool btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR* p_bd_addr, + uint8_t filter_type) { + uint8_t i; + tBTM_BLE_PF_COUNT* p_addr_filter = + &btm_ble_adv_filt_cb.p_addr_filter_count[1]; + bool found = false; + + if (BTM_BLE_PF_TYPE_ALL == filter_type && NULL == p_bd_addr) + memset(&btm_ble_adv_filt_cb.p_addr_filter_count[0], 0, + sizeof(tBTM_BLE_PF_COUNT)); + + for (i = 0; i < cmn_ble_vsc_cb.max_filter; i++, p_addr_filter++) { + if ((p_addr_filter->in_use) && + (NULL == p_bd_addr || + (NULL != p_bd_addr && + memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) { + found = true; + memset(p_addr_filter, 0, sizeof(tBTM_BLE_PF_COUNT)); + + if (NULL != p_bd_addr) break; } - return found; + } + return found; } /******************************************************************************* @@ -458,40 +465,36 @@ bool btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, uint8_t fil ******************************************************************************/ tBTM_STATUS btm_ble_update_pf_local_name(tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - tBTM_BLE_PF_LOCAL_NAME_COND *p_local_name = (p_cond == NULL) ? NULL : &p_cond->local_name; - uint8_t param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - *p = param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; + tBTM_BLE_PF_COND_PARAM* p_cond) { + tBTM_BLE_PF_LOCAL_NAME_COND* p_local_name = + (p_cond == NULL) ? NULL : &p_cond->local_name; + uint8_t param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH], + *p = param, len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; + tBTM_STATUS st = BTM_ILLEGAL_VALUE; - memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH); + memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - UINT8_TO_STREAM(p, BTM_BLE_META_PF_LOCAL_NAME); - UINT8_TO_STREAM(p, action); + UINT8_TO_STREAM(p, BTM_BLE_META_PF_LOCAL_NAME); + UINT8_TO_STREAM(p, action); - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); - if (BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) - { - if (NULL == p_local_name) - return st; + if (BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) { + if (NULL == p_local_name) return st; - if (p_local_name->data_len > BTM_BLE_PF_STR_LEN_MAX) - p_local_name->data_len = BTM_BLE_PF_STR_LEN_MAX; + if (p_local_name->data_len > BTM_BLE_PF_STR_LEN_MAX) + p_local_name->data_len = BTM_BLE_PF_STR_LEN_MAX; - ARRAY_TO_STREAM(p, p_local_name->p_data, p_local_name->data_len); - len += p_local_name->data_len; - } + ARRAY_TO_STREAM(p, p_local_name->p_data, p_local_name->data_len); + len += p_local_name->data_len; + } - /* send local name filter */ - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, len, param, - btm_ble_scan_pf_cmpl_cback); - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - return BTM_CMD_STARTED; + /* send local name filter */ + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, len, param, + btm_ble_scan_pf_cmpl_cback); + memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -506,18 +509,17 @@ tBTM_STATUS btm_ble_update_pf_local_name(tBTM_BLE_SCAN_COND_OP action, * ******************************************************************************/ tBTM_STATUS btm_ble_update_srvc_data_change(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - tBLE_BD_ADDR *p_bd_addr = p_cond ? &p_cond->target_addr : NULL; - uint8_t num_avail = (action == BTM_BLE_SCAN_COND_ADD) ? 0 : 1; + tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_COND_PARAM* p_cond) { + tBTM_STATUS st = BTM_ILLEGAL_VALUE; + tBLE_BD_ADDR* p_bd_addr = p_cond ? &p_cond->target_addr : NULL; + uint8_t num_avail = (action == BTM_BLE_SCAN_COND_ADD) ? 0 : 1; - if (btm_ble_cs_update_pf_counter (action, BTM_BLE_PF_SRVC_DATA, p_bd_addr, num_avail) - != BTM_BLE_INVALID_COUNTER) - st = BTM_SUCCESS; + if (btm_ble_cs_update_pf_counter(action, BTM_BLE_PF_SRVC_DATA, p_bd_addr, + num_avail) != BTM_BLE_INVALID_COUNTER) + st = BTM_SUCCESS; - return st; + return st; } /******************************************************************************* @@ -534,105 +536,89 @@ tBTM_STATUS btm_ble_update_srvc_data_change(tBTM_BLE_SCAN_COND_OP action, ******************************************************************************/ tBTM_STATUS btm_ble_update_pf_manu_data(tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_data, + tBTM_BLE_PF_COND_PARAM* p_data, tBTM_BLE_PF_COND_TYPE cond_type, tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_PF_MANU_COND *p_manu_data = (p_data == NULL) ? NULL : &p_data->manu_data; - tBTM_BLE_PF_SRVC_PATTERN_COND *p_srvc_data = (p_data == NULL) ? NULL : &p_data->srvc_data; - - uint8_t param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - *p = param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - - if (NULL == p_data) + tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_PF_MANU_COND* p_manu_data = + (p_data == NULL) ? NULL : &p_data->manu_data; + tBTM_BLE_PF_SRVC_PATTERN_COND* p_srvc_data = + (p_data == NULL) ? NULL : &p_data->srvc_data; + + uint8_t param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX + + BTM_BLE_ADV_FILT_META_HDR_LENGTH], + *p = param, len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; + tBTM_STATUS st = BTM_ILLEGAL_VALUE; + + if (NULL == p_data) return st; + + memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX + + BTM_BLE_ADV_FILT_META_HDR_LENGTH); + + if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) { + UINT8_TO_STREAM(p, BTM_BLE_META_PF_SRVC_DATA); + } else { + UINT8_TO_STREAM(p, BTM_BLE_META_PF_MANU_DATA); + } + + UINT8_TO_STREAM(p, action); + + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + if (BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) { + if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) { + if (NULL == p_srvc_data) return st; + if (p_srvc_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) + p_srvc_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); + + if (p_srvc_data->data_len > 0) { + ARRAY_TO_STREAM(p, p_srvc_data->p_pattern, p_srvc_data->data_len); + len += (p_srvc_data->data_len); + ARRAY_TO_STREAM(p, p_srvc_data->p_pattern_mask, p_srvc_data->data_len); + } + + len += (p_srvc_data->data_len); + BTM_TRACE_DEBUG("Service data length: %d", len); + } else { + if (NULL == p_manu_data) { + BTM_TRACE_ERROR("btm_ble_update_pf_manu_data - No manuf data"); return st; - - memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX - + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) - { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_SRVC_DATA); - } - else - { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_MANU_DATA); - } - - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if (BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) - { - if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) - { - if (NULL == p_srvc_data) - return st; - if (p_srvc_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) - p_srvc_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); - - if (p_srvc_data->data_len > 0) - { - ARRAY_TO_STREAM(p, p_srvc_data->p_pattern, p_srvc_data->data_len); - len += (p_srvc_data->data_len); - ARRAY_TO_STREAM(p, p_srvc_data->p_pattern_mask, p_srvc_data->data_len); - } - - len += (p_srvc_data->data_len); - BTM_TRACE_DEBUG("Service data length: %d", len); - } - else - { - if (NULL == p_manu_data) - { - BTM_TRACE_ERROR("btm_ble_update_pf_manu_data - No manuf data"); - return st; - } - BTM_TRACE_EVENT("btm_ble_update_pf_manu_data length: %d", - p_manu_data->data_len); - if (p_manu_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) - p_manu_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); - - UINT16_TO_STREAM(p, p_manu_data->company_id); - if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) - { - ARRAY_TO_STREAM(p, p_manu_data->p_pattern, p_manu_data->data_len); - len += (p_manu_data->data_len + 2); - } - else - len += 2; - - if (p_manu_data->company_id_mask != 0) - { - UINT16_TO_STREAM (p, p_manu_data->company_id_mask); - } - else - { - memset(p, 0xff, 2); - p += 2; - } - len += 2; - - if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) - { - ARRAY_TO_STREAM(p, p_manu_data->p_pattern_mask, p_manu_data->data_len); - len += (p_manu_data->data_len); - } - - BTM_TRACE_DEBUG("Manuf data length: %d", len); - } + } + BTM_TRACE_EVENT("btm_ble_update_pf_manu_data length: %d", + p_manu_data->data_len); + if (p_manu_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) + p_manu_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); + + UINT16_TO_STREAM(p, p_manu_data->company_id); + if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) { + ARRAY_TO_STREAM(p, p_manu_data->p_pattern, p_manu_data->data_len); + len += (p_manu_data->data_len + 2); + } else + len += 2; + + if (p_manu_data->company_id_mask != 0) { + UINT16_TO_STREAM(p, p_manu_data->company_id_mask); + } else { + memset(p, 0xff, 2); + p += 2; + } + len += 2; + + if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) { + ARRAY_TO_STREAM(p, p_manu_data->p_pattern_mask, p_manu_data->data_len); + len += (p_manu_data->data_len); + } + + BTM_TRACE_DEBUG("Manuf data length: %d", len); } + } - /* send manufacturer*/ - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, len, param, - btm_ble_scan_pf_cmpl_cback); - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - return BTM_CMD_STARTED; + /* send manufacturer*/ + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, len, param, + btm_ble_scan_pf_cmpl_cback); + memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -647,61 +633,55 @@ tBTM_STATUS btm_ble_update_pf_manu_data(tBTM_BLE_SCAN_COND_OP action, * ******************************************************************************/ uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, - uint8_t cond_type, tBLE_BD_ADDR *p_bd_addr, - uint8_t num_available) -{ - tBTM_BLE_PF_COUNT *p_addr_filter = NULL; - uint8_t *p_counter = NULL; + uint8_t cond_type, tBLE_BD_ADDR* p_bd_addr, + uint8_t num_available) { + tBTM_BLE_PF_COUNT* p_addr_filter = NULL; + uint8_t* p_counter = NULL; - btm_ble_obtain_vsc_details(); + btm_ble_obtain_vsc_details(); - if (cond_type > BTM_BLE_PF_TYPE_ALL) - { - BTM_TRACE_ERROR("unknown PF filter condition type %d", cond_type); - return BTM_BLE_INVALID_COUNTER; - } - - /* for these three types of filter, always generic */ - if (BTM_BLE_PF_ADDR_FILTER == cond_type || - BTM_BLE_PF_MANU_DATA == cond_type || - BTM_BLE_PF_LOCAL_NAME == cond_type || - BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) - p_bd_addr = NULL; - - if ((p_addr_filter = btm_ble_find_addr_filter_counter(p_bd_addr)) == NULL && - BTM_BLE_SCAN_COND_ADD == action) - { - p_addr_filter = btm_ble_alloc_addr_filter_counter(p_bd_addr->bda); - } - - if (NULL != p_addr_filter) - { - /* all filter just cleared */ - if ((BTM_BLE_PF_TYPE_ALL == cond_type && BTM_BLE_SCAN_COND_CLEAR == action) || - /* or bd address filter been deleted */ - (BTM_BLE_PF_ADDR_FILTER == cond_type && - (BTM_BLE_SCAN_COND_DELETE == action || BTM_BLE_SCAN_COND_CLEAR == action))) - { - btm_ble_dealloc_addr_filter_counter(p_bd_addr, cond_type); - } - /* if not feature selection, update new addition/reduction of the filter counter */ - else if (cond_type != BTM_BLE_PF_TYPE_ALL) - { - p_counter = p_addr_filter->pf_counter; - if (num_available > 0) - p_counter[cond_type] += 1; - - BTM_TRACE_DEBUG("counter = %d, maxfilt = %d, num_avbl=%d", - p_counter[cond_type], cmn_ble_vsc_cb.max_filter, num_available); - return p_counter[cond_type]; - } + if (cond_type > BTM_BLE_PF_TYPE_ALL) { + BTM_TRACE_ERROR("unknown PF filter condition type %d", cond_type); + return BTM_BLE_INVALID_COUNTER; + } + + /* for these three types of filter, always generic */ + if (BTM_BLE_PF_ADDR_FILTER == cond_type || + BTM_BLE_PF_MANU_DATA == cond_type || BTM_BLE_PF_LOCAL_NAME == cond_type || + BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) + p_bd_addr = NULL; + + if ((p_addr_filter = btm_ble_find_addr_filter_counter(p_bd_addr)) == NULL && + BTM_BLE_SCAN_COND_ADD == action) { + p_addr_filter = btm_ble_alloc_addr_filter_counter(p_bd_addr->bda); + } + + if (NULL != p_addr_filter) { + /* all filter just cleared */ + if ((BTM_BLE_PF_TYPE_ALL == cond_type && + BTM_BLE_SCAN_COND_CLEAR == action) || + /* or bd address filter been deleted */ + (BTM_BLE_PF_ADDR_FILTER == cond_type && + (BTM_BLE_SCAN_COND_DELETE == action || + BTM_BLE_SCAN_COND_CLEAR == action))) { + btm_ble_dealloc_addr_filter_counter(p_bd_addr, cond_type); } - else - { - BTM_TRACE_ERROR("no matching filter counter found"); + /* if not feature selection, update new addition/reduction of the filter + counter */ + else if (cond_type != BTM_BLE_PF_TYPE_ALL) { + p_counter = p_addr_filter->pf_counter; + if (num_available > 0) p_counter[cond_type] += 1; + + BTM_TRACE_DEBUG("counter = %d, maxfilt = %d, num_avbl=%d", + p_counter[cond_type], cmn_ble_vsc_cb.max_filter, + num_available); + return p_counter[cond_type]; } - /* no matching filter located and updated */ - return BTM_BLE_INVALID_COUNTER; + } else { + BTM_TRACE_ERROR("no matching filter counter found"); + } + /* no matching filter located and updated */ + return BTM_BLE_INVALID_COUNTER; } /******************************************************************************* @@ -718,36 +698,32 @@ uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, ******************************************************************************/ tBTM_STATUS btm_ble_update_addr_filter(tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - uint8_t param[BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - * p= param; - tBLE_BD_ADDR *p_addr = (p_cond == NULL) ? NULL : &p_cond->target_addr; - - memset(param, 0, BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if (BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) - { - if (NULL == p_addr) - return BTM_ILLEGAL_VALUE; - - BDADDR_TO_STREAM(p, p_addr->bda); - UINT8_TO_STREAM(p, p_addr->type); - } - /* send address filter */ - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), - param, - btm_ble_scan_pf_cmpl_cback); - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - return BTM_CMD_STARTED; + tBTM_BLE_PF_COND_PARAM* p_cond) { + uint8_t param[BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], + *p = param; + tBLE_BD_ADDR* p_addr = (p_cond == NULL) ? NULL : &p_cond->target_addr; + + memset(param, 0, BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); + + UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); + UINT8_TO_STREAM(p, action); + + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + if (BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) { + if (NULL == p_addr) return BTM_ILLEGAL_VALUE; + + BDADDR_TO_STREAM(p, p_addr->bda); + UINT8_TO_STREAM(p, p_addr->type); + } + /* send address filter */ + BTM_VendorSpecificCommand( + HCI_BLE_ADV_FILTER_OCF, + (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), + param, btm_ble_scan_pf_cmpl_cback); + memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -765,129 +741,108 @@ tBTM_STATUS btm_ble_update_addr_filter(tBTM_BLE_SCAN_COND_OP action, tBTM_STATUS btm_ble_update_uuid_filter(tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_FILT_INDEX filt_index, tBTM_BLE_PF_COND_TYPE filter_type, - tBTM_BLE_PF_COND_PARAM *p_cond, + tBTM_BLE_PF_COND_PARAM* p_cond, tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - uint8_t param[BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - * p= param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_BLE_PF_UUID_COND *p_uuid_cond; - uint8_t evt_type; - - memset(param, 0, BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - if (BTM_BLE_PF_SRVC_UUID == filter_type) - { - evt_type = BTM_BLE_META_PF_UUID; - p_uuid_cond = p_cond ? &p_cond->srvc_uuid : NULL; - } - else - { - evt_type = BTM_BLE_META_PF_SOL_UUID; - p_uuid_cond = p_cond ? &p_cond->solicitate_uuid : NULL; - } - - if (NULL == p_uuid_cond && action != BTM_BLE_SCAN_COND_CLEAR) - { - BTM_TRACE_ERROR("Illegal param for add/delete UUID filter"); - return BTM_ILLEGAL_VALUE; - } - - /* need to add address filter first, if adding per bda UUID filter without address filter */ - if (BTM_BLE_SCAN_COND_ADD == action && NULL != p_uuid_cond && - p_uuid_cond->p_target_addr && - btm_ble_find_addr_filter_counter(p_uuid_cond->p_target_addr) == NULL) - { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - BDADDR_TO_STREAM(p, p_uuid_cond->p_target_addr->bda); - UINT8_TO_STREAM(p, p_uuid_cond->p_target_addr->type); - - /* send address filter */ - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), - param, - btm_ble_scan_pf_cmpl_cback); - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_ADDR, cb_evt, ref_value, NULL, NULL); - BTM_TRACE_DEBUG("Updated Address filter"); - } - - p = param; - UINT8_TO_STREAM(p, evt_type); + tBTM_BLE_REF_VALUE ref_value) { + uint8_t param[BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], + *p = param, len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; + tBTM_BLE_PF_UUID_COND* p_uuid_cond; + uint8_t evt_type; + + memset(param, 0, BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); + + if (BTM_BLE_PF_SRVC_UUID == filter_type) { + evt_type = BTM_BLE_META_PF_UUID; + p_uuid_cond = p_cond ? &p_cond->srvc_uuid : NULL; + } else { + evt_type = BTM_BLE_META_PF_SOL_UUID; + p_uuid_cond = p_cond ? &p_cond->solicitate_uuid : NULL; + } + + if (NULL == p_uuid_cond && action != BTM_BLE_SCAN_COND_CLEAR) { + BTM_TRACE_ERROR("Illegal param for add/delete UUID filter"); + return BTM_ILLEGAL_VALUE; + } + + /* need to add address filter first, if adding per bda UUID filter without + * address filter */ + if (BTM_BLE_SCAN_COND_ADD == action && NULL != p_uuid_cond && + p_uuid_cond->p_target_addr && + btm_ble_find_addr_filter_counter(p_uuid_cond->p_target_addr) == NULL) { + UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); UINT8_TO_STREAM(p, action); /* Filter index */ UINT8_TO_STREAM(p, filt_index); - if ((BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) && - NULL != p_uuid_cond) + BDADDR_TO_STREAM(p, p_uuid_cond->p_target_addr->bda); + UINT8_TO_STREAM(p, p_uuid_cond->p_target_addr->type); + + /* send address filter */ + BTM_VendorSpecificCommand( + HCI_BLE_ADV_FILTER_OCF, + (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), + param, btm_ble_scan_pf_cmpl_cback); + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_ADDR, cb_evt, ref_value, + NULL, NULL); + BTM_TRACE_DEBUG("Updated Address filter"); + } + + p = param; + UINT8_TO_STREAM(p, evt_type); + UINT8_TO_STREAM(p, action); + + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + if ((BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) && + NULL != p_uuid_cond) { + if (p_uuid_cond->uuid.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid16); + len += LEN_UUID_16; + } else if (p_uuid_cond->uuid.len == LEN_UUID_32) /*4 bytes */ { - if (p_uuid_cond->uuid.len == LEN_UUID_16) - { - UINT16_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid16); - len += LEN_UUID_16; - } - else if (p_uuid_cond->uuid.len == LEN_UUID_32)/*4 bytes */ - { - UINT32_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid32); - len += LEN_UUID_32; - } - else if (p_uuid_cond->uuid.len == LEN_UUID_128) - { - ARRAY_TO_STREAM (p, p_uuid_cond->uuid.uu.uuid128, LEN_UUID_128); - len += LEN_UUID_128; - } - else - { - BTM_TRACE_ERROR("illegal UUID length: %d", p_uuid_cond->uuid.len); - return BTM_ILLEGAL_VALUE; - } - - if (NULL != p_uuid_cond->p_uuid_mask) - { - if (p_uuid_cond->uuid.len == LEN_UUID_16) - { - UINT16_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid16_mask); - len += LEN_UUID_16; - } - else if (p_uuid_cond->uuid.len == LEN_UUID_32)/*4 bytes */ - { - UINT32_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid32_mask); - len += LEN_UUID_32; - } - else if (p_uuid_cond->uuid.len == LEN_UUID_128) - { - ARRAY_TO_STREAM (p, p_uuid_cond->p_uuid_mask->uuid128_mask, LEN_UUID_128); - len += LEN_UUID_128; - } - } - else - { - memset(p, 0xff, p_uuid_cond->uuid.len); - len += p_uuid_cond->uuid.len; - } - BTM_TRACE_DEBUG("btm_ble_update_uuid_filter : %d, %d, %d, %d", filter_type, evt_type, - p_uuid_cond->uuid.len, len); + UINT32_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid32); + len += LEN_UUID_32; + } else if (p_uuid_cond->uuid.len == LEN_UUID_128) { + ARRAY_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid128, LEN_UUID_128); + len += LEN_UUID_128; + } else { + BTM_TRACE_ERROR("illegal UUID length: %d", p_uuid_cond->uuid.len); + return BTM_ILLEGAL_VALUE; } - /* send UUID filter update */ - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - len, - param, - btm_ble_scan_pf_cmpl_cback); - if (p_uuid_cond && p_uuid_cond->p_target_addr) - memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_uuid_cond->p_target_addr, - sizeof(tBLE_BD_ADDR)); - else - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); + if (NULL != p_uuid_cond->p_uuid_mask) { + if (p_uuid_cond->uuid.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid16_mask); + len += LEN_UUID_16; + } else if (p_uuid_cond->uuid.len == LEN_UUID_32) /*4 bytes */ + { + UINT32_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid32_mask); + len += LEN_UUID_32; + } else if (p_uuid_cond->uuid.len == LEN_UUID_128) { + ARRAY_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid128_mask, + LEN_UUID_128); + len += LEN_UUID_128; + } + } else { + memset(p, 0xff, p_uuid_cond->uuid.len); + len += p_uuid_cond->uuid.len; + } + BTM_TRACE_DEBUG("btm_ble_update_uuid_filter : %d, %d, %d, %d", filter_type, + evt_type, p_uuid_cond->uuid.len, len); + } + + /* send UUID filter update */ + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, len, param, + btm_ble_scan_pf_cmpl_cback); + if (p_uuid_cond && p_uuid_cond->p_target_addr) + memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_uuid_cond->p_target_addr, + sizeof(tBLE_BD_ADDR)); + else + memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - return BTM_CMD_STARTED; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -903,96 +858,101 @@ tBTM_STATUS btm_ble_update_uuid_filter(tBTM_BLE_SCAN_COND_OP action, * ******************************************************************************/ tBTM_STATUS btm_ble_clear_scan_pf_filter(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - tBLE_BD_ADDR *p_target = (p_cond == NULL)? NULL : &p_cond->target_addr; - tBTM_BLE_PF_COUNT *p_bda_filter; - tBTM_STATUS st = BTM_WRONG_MODE; - uint8_t param[20], *p; - - if (BTM_BLE_SCAN_COND_CLEAR != action) - { - BTM_TRACE_ERROR("unable to perform action:%d for generic adv filter type", action); - return BTM_ILLEGAL_VALUE; - } - - p = param; - memset(param, 0, 20); - - p_bda_filter = btm_ble_find_addr_filter_counter(p_target); - - if (NULL == p_bda_filter || - /* not a generic filter */ - (p_target != NULL && p_bda_filter)) - { - BTM_TRACE_ERROR("Error: Can not clear filter, No PF filter has been configured!"); - return st; - } - - /* clear the general filter entry */ - if (NULL == p_target) - { - /* clear manufactuer data filter */ - st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, - BTM_BLE_PF_MANU_DATA, cb_evt, ref_value); - if(BTM_CMD_STARTED == st) - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_MANU_DATA, cb_evt, - ref_value, NULL, NULL); - - /* clear local name filter */ - st = btm_ble_update_pf_local_name(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL); - if(BTM_CMD_STARTED == st) - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_LOCAL_NAME, cb_evt, - ref_value, NULL, NULL); - - /* update the counter for service data */ - st = btm_ble_update_srvc_data_change(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL); - - /* clear UUID filter */ - st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, - BTM_BLE_PF_SRVC_UUID, NULL, cb_evt, ref_value); - if(BTM_CMD_STARTED == st) - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_UUID, cb_evt, ref_value, NULL, NULL); - - st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, - BTM_BLE_PF_SRVC_SOL_UUID, NULL, cb_evt, ref_value); - if(BTM_CMD_STARTED == st) - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SOL_UUID, cb_evt, - ref_value, NULL, NULL); - - /* clear service data filter */ - st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, - BTM_BLE_PF_SRVC_DATA_PATTERN, cb_evt, ref_value); - if(BTM_CMD_STARTED == st) - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SRVC_DATA, cb_evt, - ref_value, NULL, NULL); - } - - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - /* set PCF selection */ - UINT32_TO_STREAM(p, BTM_BLE_PF_SELECT_NONE); - /* set logic condition as OR as default */ - UINT8_TO_STREAM(p, BTM_BLE_PF_LOGIC_OR); - - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_PF_FEAT_SEL_LEN), - param, - btm_ble_scan_pf_cmpl_cback); - if (p_target) - memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_target, sizeof(tBLE_BD_ADDR)); - else - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - return BTM_CMD_STARTED; + tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_COND_PARAM* p_cond, + tBTM_BLE_PF_CFG_CBACK* p_cmpl_cback, + tBTM_BLE_FILT_CB_EVT cb_evt, + tBTM_BLE_REF_VALUE ref_value) { + tBLE_BD_ADDR* p_target = (p_cond == NULL) ? NULL : &p_cond->target_addr; + tBTM_BLE_PF_COUNT* p_bda_filter; + tBTM_STATUS st = BTM_WRONG_MODE; + uint8_t param[20], *p; + + if (BTM_BLE_SCAN_COND_CLEAR != action) { + BTM_TRACE_ERROR("unable to perform action:%d for generic adv filter type", + action); + return BTM_ILLEGAL_VALUE; + } + + p = param; + memset(param, 0, 20); + + p_bda_filter = btm_ble_find_addr_filter_counter(p_target); + + if (NULL == p_bda_filter || + /* not a generic filter */ + (p_target != NULL && p_bda_filter)) { + BTM_TRACE_ERROR( + "Error: Can not clear filter, No PF filter has been configured!"); + return st; + } + + /* clear the general filter entry */ + if (NULL == p_target) { + /* clear manufactuer data filter */ + st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, + BTM_BLE_PF_MANU_DATA, cb_evt, ref_value); + if (BTM_CMD_STARTED == st) + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_MANU_DATA, cb_evt, + ref_value, NULL, NULL); + + /* clear local name filter */ + st = + btm_ble_update_pf_local_name(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL); + if (BTM_CMD_STARTED == st) + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_LOCAL_NAME, cb_evt, + ref_value, NULL, NULL); + + /* update the counter for service data */ + st = btm_ble_update_srvc_data_change(BTM_BLE_SCAN_COND_CLEAR, filt_index, + NULL); + + /* clear UUID filter */ + st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, + BTM_BLE_PF_SRVC_UUID, NULL, cb_evt, + ref_value); + if (BTM_CMD_STARTED == st) + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_UUID, cb_evt, ref_value, + NULL, NULL); + + st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, + BTM_BLE_PF_SRVC_SOL_UUID, NULL, cb_evt, + ref_value); + if (BTM_CMD_STARTED == st) + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SOL_UUID, cb_evt, + ref_value, NULL, NULL); + + /* clear service data filter */ + st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, + BTM_BLE_PF_SRVC_DATA_PATTERN, cb_evt, + ref_value); + if (BTM_CMD_STARTED == st) + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SRVC_DATA, cb_evt, + ref_value, NULL, NULL); + } + + /* select feature based on control block settings */ + UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); + UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); + + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + /* set PCF selection */ + UINT32_TO_STREAM(p, BTM_BLE_PF_SELECT_NONE); + /* set logic condition as OR as default */ + UINT8_TO_STREAM(p, BTM_BLE_PF_LOGIC_OR); + + BTM_VendorSpecificCommand( + HCI_BLE_ADV_FILTER_OCF, + (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_PF_FEAT_SEL_LEN), + param, btm_ble_scan_pf_cmpl_cback); + if (p_target) + memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_target, + sizeof(tBLE_BD_ADDR)); + else + memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -1012,113 +972,104 @@ tBTM_STATUS btm_ble_clear_scan_pf_filter(tBTM_BLE_SCAN_COND_OP action, * Returns void * ******************************************************************************/ -tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_FILT_PARAMS *p_filt_params, - tBLE_BD_ADDR *p_target, tBTM_BLE_PF_PARAM_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_PF_COUNT *p_bda_filter = NULL; - uint8_t len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + - BTM_BLE_ADV_FILT_TRACK_NUM; - uint8_t param[len], *p; - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) - return BTM_WRONG_MODE; - - p = param; - memset(param, 0, len); - BTM_TRACE_EVENT (" BTM_BleAdvFilterParamSetup"); - - if (BTM_BLE_SCAN_COND_ADD == action) - { - p_bda_filter = btm_ble_find_addr_filter_counter(p_target); - if (NULL == p_bda_filter) - { - BTM_TRACE_ERROR("BD Address not found!"); - return BTM_WRONG_MODE; - } - - BTM_TRACE_DEBUG("BTM_BleAdvFilterParamSetup : Feat mask:%d", p_filt_params->feat_seln); - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_ADD); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - /* set PCF selection */ - UINT16_TO_STREAM(p, p_filt_params->feat_seln); - /* set logic type */ - UINT16_TO_STREAM(p, p_filt_params->logic_type); - /* set logic condition */ - UINT8_TO_STREAM(p, p_filt_params->filt_logic_type); - /* set RSSI high threshold */ - UINT8_TO_STREAM(p, p_filt_params->rssi_high_thres); - /* set delivery mode */ - UINT8_TO_STREAM(p, p_filt_params->dely_mode); - - if (0x01 == p_filt_params->dely_mode) - { - /* set onfound timeout */ - UINT16_TO_STREAM(p, p_filt_params->found_timeout); - /* set onfound timeout count*/ - UINT8_TO_STREAM(p, p_filt_params->found_timeout_cnt); - /* set RSSI low threshold */ - UINT8_TO_STREAM(p, p_filt_params->rssi_low_thres); - /* set onlost timeout */ - UINT16_TO_STREAM(p, p_filt_params->lost_timeout); - /* set num_of_track_entries for firmware greater than L-release version */ - if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) - UINT16_TO_STREAM(p, p_filt_params->num_of_tracking_entries); - } - - if (cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN; - else - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + - BTM_BLE_ADV_FILT_TRACK_NUM; - - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)len, - param, - btm_ble_scan_pf_cmpl_cback); - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); +tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, + tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_FILT_PARAMS* p_filt_params, + tBLE_BD_ADDR* p_target, + tBTM_BLE_PF_PARAM_CBACK* p_cmpl_cback, + tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_PF_COUNT* p_bda_filter = NULL; + uint8_t len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + BTM_BLE_ADV_FILT_TRACK_NUM; + uint8_t param[len], *p; + + if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) return BTM_WRONG_MODE; + + p = param; + memset(param, 0, len); + BTM_TRACE_EVENT(" BTM_BleAdvFilterParamSetup"); + + if (BTM_BLE_SCAN_COND_ADD == action) { + p_bda_filter = btm_ble_find_addr_filter_counter(p_target); + if (NULL == p_bda_filter) { + BTM_TRACE_ERROR("BD Address not found!"); + return BTM_WRONG_MODE; } - else - if (BTM_BLE_SCAN_COND_DELETE == action) - { - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_DELETE); - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH), - param, - btm_ble_scan_pf_cmpl_cback); - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); + + BTM_TRACE_DEBUG("BTM_BleAdvFilterParamSetup : Feat mask:%d", + p_filt_params->feat_seln); + /* select feature based on control block settings */ + UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); + UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_ADD); + + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + /* set PCF selection */ + UINT16_TO_STREAM(p, p_filt_params->feat_seln); + /* set logic type */ + UINT16_TO_STREAM(p, p_filt_params->logic_type); + /* set logic condition */ + UINT8_TO_STREAM(p, p_filt_params->filt_logic_type); + /* set RSSI high threshold */ + UINT8_TO_STREAM(p, p_filt_params->rssi_high_thres); + /* set delivery mode */ + UINT8_TO_STREAM(p, p_filt_params->dely_mode); + + if (0x01 == p_filt_params->dely_mode) { + /* set onfound timeout */ + UINT16_TO_STREAM(p, p_filt_params->found_timeout); + /* set onfound timeout count*/ + UINT8_TO_STREAM(p, p_filt_params->found_timeout_cnt); + /* set RSSI low threshold */ + UINT8_TO_STREAM(p, p_filt_params->rssi_low_thres); + /* set onlost timeout */ + UINT16_TO_STREAM(p, p_filt_params->lost_timeout); + /* set num_of_track_entries for firmware greater than L-release version */ + if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) + UINT16_TO_STREAM(p, p_filt_params->num_of_tracking_entries); } + + if (cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) + len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN; else - if (BTM_BLE_SCAN_COND_CLEAR == action) - { - /* Deallocate all filters here */ - btm_ble_dealloc_addr_filter_counter(NULL, BTM_BLE_PF_TYPE_ALL); - - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); - - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH-1), - param, - btm_ble_scan_pf_cmpl_cback); - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); - } - return BTM_CMD_STARTED; + len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + + BTM_BLE_ADV_FILT_TRACK_NUM; + + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, (uint8_t)len, param, + btm_ble_scan_pf_cmpl_cback); + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, + BTM_BLE_FILT_ADV_PARAM, ref_value, NULL, + p_cmpl_cback); + } else if (BTM_BLE_SCAN_COND_DELETE == action) { + /* select feature based on control block settings */ + UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); + UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_DELETE); + /* Filter index */ + UINT8_TO_STREAM(p, filt_index); + + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, + (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH), + param, btm_ble_scan_pf_cmpl_cback); + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, + BTM_BLE_FILT_ADV_PARAM, ref_value, NULL, + p_cmpl_cback); + } else if (BTM_BLE_SCAN_COND_CLEAR == action) { + /* Deallocate all filters here */ + btm_ble_dealloc_addr_filter_counter(NULL, BTM_BLE_PF_TYPE_ALL); + + /* select feature based on control block settings */ + UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); + UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); + + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, + (uint8_t)(BTM_BLE_ADV_FILT_META_HDR_LENGTH - 1), + param, btm_ble_scan_pf_cmpl_cback); + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, + BTM_BLE_FILT_ADV_PARAM, ref_value, NULL, + p_cmpl_cback); + } + return BTM_CMD_STARTED; } /******************************************************************************* @@ -1134,32 +1085,29 @@ tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_i * Returns void * ******************************************************************************/ -tBTM_STATUS BTM_BleEnableDisableFilterFeature(uint8_t enable, - tBTM_BLE_PF_STATUS_CBACK *p_stat_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - uint8_t param[20], *p; - tBTM_STATUS st = BTM_WRONG_MODE; - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) - return st; - - p = param; - memset(param, 0, 20); - - /* enable the content filter in controller */ - p = param; - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ENABLE); - /* enable adv data payload filtering */ - UINT8_TO_STREAM(p, enable); - - BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, - BTM_BLE_PCF_ENABLE_LEN, param, - btm_ble_scan_pf_cmpl_cback); - btm_ble_adv_filt_cb.p_filt_stat_cback = p_stat_cback; - btm_ble_advfilt_enq_op_q(enable, BTM_BLE_META_PF_ENABLE, BTM_BLE_FILT_ENABLE_DISABLE, - ref_value, NULL, NULL); - return BTM_CMD_STARTED; +tBTM_STATUS BTM_BleEnableDisableFilterFeature( + uint8_t enable, tBTM_BLE_PF_STATUS_CBACK* p_stat_cback, + tBTM_BLE_REF_VALUE ref_value) { + uint8_t param[20], *p; + tBTM_STATUS st = BTM_WRONG_MODE; + + if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) return st; + + p = param; + memset(param, 0, 20); + + /* enable the content filter in controller */ + p = param; + UINT8_TO_STREAM(p, BTM_BLE_META_PF_ENABLE); + /* enable adv data payload filtering */ + UINT8_TO_STREAM(p, enable); + + BTM_VendorSpecificCommand(HCI_BLE_ADV_FILTER_OCF, BTM_BLE_PCF_ENABLE_LEN, + param, btm_ble_scan_pf_cmpl_cback); + btm_ble_adv_filt_cb.p_filt_stat_cback = p_stat_cback; + btm_ble_advfilt_enq_op_q(enable, BTM_BLE_META_PF_ENABLE, + BTM_BLE_FILT_ENABLE_DISABLE, ref_value, NULL, NULL); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -1182,69 +1130,67 @@ tBTM_STATUS BTM_BleEnableDisableFilterFeature(uint8_t enable, tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_COND_TYPE cond_type, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - uint8_t ocf = 0; - BTM_TRACE_EVENT (" BTM_BleCfgFilterCondition action:%d, cond_type:%d, index:%d", action, - cond_type, filt_index); - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) - return st; - - switch (cond_type) - { - /* write service data filter */ - case BTM_BLE_PF_SRVC_DATA_PATTERN: - /* write manufacturer data filter */ - case BTM_BLE_PF_MANU_DATA: - st = btm_ble_update_pf_manu_data(action, filt_index, p_cond, cond_type, 0, ref_value); - break; - - /* write local name filter */ - case BTM_BLE_PF_LOCAL_NAME: - st = btm_ble_update_pf_local_name(action, filt_index, p_cond); - break; - - /* filter on advertiser address */ - case BTM_BLE_PF_ADDR_FILTER: - st = btm_ble_update_addr_filter(action, filt_index, p_cond); - break; - - /* filter on service/solicitated UUID */ - case BTM_BLE_PF_SRVC_UUID: - case BTM_BLE_PF_SRVC_SOL_UUID: - st = btm_ble_update_uuid_filter(action, filt_index, cond_type, p_cond, 0, ref_value); - break; - - case BTM_BLE_PF_SRVC_DATA: - st = btm_ble_update_srvc_data_change(action, filt_index, p_cond); - break; - - case BTM_BLE_PF_TYPE_ALL: /* only used to clear filter */ - st = btm_ble_clear_scan_pf_filter(action, filt_index, p_cond, p_cmpl_cback, - 0, ref_value); - break; - - default: - BTM_TRACE_WARNING("condition type [%d] not supported currently.", cond_type); - break; - } - - if(BTM_CMD_STARTED == st && cond_type != BTM_BLE_PF_TYPE_ALL) - { - ocf = btm_ble_condtype_to_ocf(cond_type); - btm_ble_advfilt_enq_op_q(action, ocf, BTM_BLE_FILT_CFG, ref_value, p_cmpl_cback, NULL); - } - else - if(BTM_CMD_STARTED == st && BTM_BLE_PF_TYPE_ALL == cond_type) - { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_CFG, - ref_value, p_cmpl_cback, NULL); - } - return st; + tBTM_BLE_PF_COND_PARAM* p_cond, + tBTM_BLE_PF_CFG_CBACK* p_cmpl_cback, + tBTM_BLE_REF_VALUE ref_value) { + tBTM_STATUS st = BTM_ILLEGAL_VALUE; + uint8_t ocf = 0; + BTM_TRACE_EVENT( + " BTM_BleCfgFilterCondition action:%d, cond_type:%d, index:%d", action, + cond_type, filt_index); + + if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) return st; + + switch (cond_type) { + /* write service data filter */ + case BTM_BLE_PF_SRVC_DATA_PATTERN: + /* write manufacturer data filter */ + case BTM_BLE_PF_MANU_DATA: + st = btm_ble_update_pf_manu_data(action, filt_index, p_cond, cond_type, 0, + ref_value); + break; + + /* write local name filter */ + case BTM_BLE_PF_LOCAL_NAME: + st = btm_ble_update_pf_local_name(action, filt_index, p_cond); + break; + + /* filter on advertiser address */ + case BTM_BLE_PF_ADDR_FILTER: + st = btm_ble_update_addr_filter(action, filt_index, p_cond); + break; + + /* filter on service/solicitated UUID */ + case BTM_BLE_PF_SRVC_UUID: + case BTM_BLE_PF_SRVC_SOL_UUID: + st = btm_ble_update_uuid_filter(action, filt_index, cond_type, p_cond, 0, + ref_value); + break; + + case BTM_BLE_PF_SRVC_DATA: + st = btm_ble_update_srvc_data_change(action, filt_index, p_cond); + break; + + case BTM_BLE_PF_TYPE_ALL: /* only used to clear filter */ + st = btm_ble_clear_scan_pf_filter(action, filt_index, p_cond, + p_cmpl_cback, 0, ref_value); + break; + + default: + BTM_TRACE_WARNING("condition type [%d] not supported currently.", + cond_type); + break; + } + + if (BTM_CMD_STARTED == st && cond_type != BTM_BLE_PF_TYPE_ALL) { + ocf = btm_ble_condtype_to_ocf(cond_type); + btm_ble_advfilt_enq_op_q(action, ocf, BTM_BLE_FILT_CFG, ref_value, + p_cmpl_cback, NULL); + } else if (BTM_CMD_STARTED == st && BTM_BLE_PF_TYPE_ALL == cond_type) { + btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_CFG, + ref_value, p_cmpl_cback, NULL); + } + return st; } /******************************************************************************* @@ -1258,17 +1204,14 @@ tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, * Returns status * ******************************************************************************/ -void btm_ble_adv_filter_init(void) -{ - memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) - return; - - if (cmn_ble_vsc_cb.max_filter > 0) - { - btm_ble_adv_filt_cb.p_addr_filter_count = - (tBTM_BLE_PF_COUNT*)osi_malloc(sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter); - } +void btm_ble_adv_filter_init(void) { + memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); + if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) return; + + if (cmn_ble_vsc_cb.max_filter > 0) { + btm_ble_adv_filt_cb.p_addr_filter_count = (tBTM_BLE_PF_COUNT*)osi_malloc( + sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_vsc_cb.max_filter); + } } /******************************************************************************* @@ -1282,7 +1225,6 @@ void btm_ble_adv_filter_init(void) * Returns status * ******************************************************************************/ -void btm_ble_adv_filter_cleanup(void) -{ - osi_free_and_reset((void **)&btm_ble_adv_filt_cb.p_addr_filter_count); +void btm_ble_adv_filter_cleanup(void) { + osi_free_and_reset((void**)&btm_ble_adv_filt_cb.p_addr_filter_count); } diff --git a/stack/btm/btm_ble_batchscan.cc b/stack/btm/btm_ble_batchscan.cc index e590b6137..43db5ef61 100644 --- a/stack/btm/btm_ble_batchscan.cc +++ b/stack/btm/btm_ble_batchscan.cc @@ -15,36 +15,35 @@ * limitations under the License. * ******************************************************************************/ -#include -#include #include +#include +#include #include "bt_target.h" -#include "btm_ble_api.h" #include "bt_types.h" #include "bt_utils.h" -#include "btu.h" +#include "btm_ble_api.h" #include "btm_int.h" +#include "btu.h" #include "device/include/controller.h" #include "hcimsgs.h" tBTM_BLE_BATCH_SCAN_CB ble_batchscan_cb; tBTM_BLE_ADV_TRACK_CB ble_advtrack_cb; - /* length of each batch scan command */ -#define BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN 4 -#define BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN 12 -#define BTM_BLE_BATCH_SCAN_ENB_DISB_LEN 2 -#define BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN 2 +#define BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN 4 +#define BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN 12 +#define BTM_BLE_BATCH_SCAN_ENB_DISB_LEN 2 +#define BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN 2 -#define BTM_BLE_BATCH_SCAN_CB_EVT_MASK 0xF0 -#define BTM_BLE_BATCH_SCAN_SUBCODE_MASK 0x0F +#define BTM_BLE_BATCH_SCAN_CB_EVT_MASK 0xF0 +#define BTM_BLE_BATCH_SCAN_SUBCODE_MASK 0x0F /******************************************************************************* * Local functions ******************************************************************************/ -void btm_ble_batchscan_vsc_cmpl_cback (tBTM_VSC_CMPL *p_params); +void btm_ble_batchscan_vsc_cmpl_cback(tBTM_VSC_CMPL* p_params); void btm_ble_batchscan_cleanup(void); /******************************************************************************* @@ -56,80 +55,75 @@ void btm_ble_batchscan_cleanup(void); * Returns None * ******************************************************************************/ -void btm_ble_batchscan_filter_track_adv_vse_cback(uint8_t len, uint8_t *p) -{ - tBTM_BLE_TRACK_ADV_DATA adv_data; - - uint8_t sub_event = 0; - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - STREAM_TO_UINT8(sub_event, p); - - BTM_TRACE_EVENT("btm_ble_batchscan_filter_track_adv_vse_cback called with event:%x", sub_event); - if (HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT == sub_event && - NULL != ble_batchscan_cb.p_thres_cback) - { - ble_batchscan_cb.p_thres_cback(ble_batchscan_cb.ref_value); - return; - } +void btm_ble_batchscan_filter_track_adv_vse_cback(uint8_t len, uint8_t* p) { + tBTM_BLE_TRACK_ADV_DATA adv_data; + + uint8_t sub_event = 0; + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + STREAM_TO_UINT8(sub_event, p); + + BTM_TRACE_EVENT( + "btm_ble_batchscan_filter_track_adv_vse_cback called with event:%x", + sub_event); + if (HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT == sub_event && + NULL != ble_batchscan_cb.p_thres_cback) { + ble_batchscan_cb.p_thres_cback(ble_batchscan_cb.ref_value); + return; + } + + if (HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT == sub_event && + NULL != ble_advtrack_cb.p_track_cback) { + if (len < 10) return; - if (HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT == sub_event && NULL != ble_advtrack_cb.p_track_cback) - { - if (len < 10) - return; - - memset(&adv_data, 0 , sizeof(tBTM_BLE_TRACK_ADV_DATA)); - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - adv_data.client_if = (uint8_t)ble_advtrack_cb.ref_value; - if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) - { - STREAM_TO_UINT8(adv_data.filt_index, p); - STREAM_TO_UINT8(adv_data.advertiser_state, p); - STREAM_TO_UINT8(adv_data.advertiser_info_present, p); - STREAM_TO_BDADDR(adv_data.bd_addr.address, p); - STREAM_TO_UINT8(adv_data.addr_type, p); - - /* Extract the adv info details */ - if (ADV_INFO_PRESENT == adv_data.advertiser_info_present) - { - STREAM_TO_UINT8(adv_data.tx_power, p); - STREAM_TO_UINT8(adv_data.rssi_value, p); - STREAM_TO_UINT16(adv_data.time_stamp, p); - - STREAM_TO_UINT8(adv_data.adv_pkt_len, p); - if (adv_data.adv_pkt_len > 0) - { - adv_data.p_adv_pkt_data = - static_cast(osi_malloc(adv_data.adv_pkt_len)); - memcpy(adv_data.p_adv_pkt_data, p, adv_data.adv_pkt_len); - } - - STREAM_TO_UINT8(adv_data.scan_rsp_len, p); - if (adv_data.scan_rsp_len > 0) - { - adv_data.p_scan_rsp_data = - static_cast(osi_malloc(adv_data.scan_rsp_len)); - memcpy(adv_data.p_scan_rsp_data, p, adv_data.scan_rsp_len); - } - } + memset(&adv_data, 0, sizeof(tBTM_BLE_TRACK_ADV_DATA)); + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + adv_data.client_if = (uint8_t)ble_advtrack_cb.ref_value; + if (cmn_ble_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) { + STREAM_TO_UINT8(adv_data.filt_index, p); + STREAM_TO_UINT8(adv_data.advertiser_state, p); + STREAM_TO_UINT8(adv_data.advertiser_info_present, p); + STREAM_TO_BDADDR(adv_data.bd_addr.address, p); + STREAM_TO_UINT8(adv_data.addr_type, p); + + /* Extract the adv info details */ + if (ADV_INFO_PRESENT == adv_data.advertiser_info_present) { + STREAM_TO_UINT8(adv_data.tx_power, p); + STREAM_TO_UINT8(adv_data.rssi_value, p); + STREAM_TO_UINT16(adv_data.time_stamp, p); + + STREAM_TO_UINT8(adv_data.adv_pkt_len, p); + if (adv_data.adv_pkt_len > 0) { + adv_data.p_adv_pkt_data = + static_cast(osi_malloc(adv_data.adv_pkt_len)); + memcpy(adv_data.p_adv_pkt_data, p, adv_data.adv_pkt_len); } - else - { - /* Based on L-release version */ - STREAM_TO_UINT8(adv_data.filt_index, p); - STREAM_TO_UINT8(adv_data.addr_type, p); - STREAM_TO_BDADDR(adv_data.bd_addr.address, p); - STREAM_TO_UINT8(adv_data.advertiser_state, p); + + STREAM_TO_UINT8(adv_data.scan_rsp_len, p); + if (adv_data.scan_rsp_len > 0) { + adv_data.p_scan_rsp_data = + static_cast(osi_malloc(adv_data.scan_rsp_len)); + memcpy(adv_data.p_scan_rsp_data, p, adv_data.scan_rsp_len); } + } + } else { + /* Based on L-release version */ + STREAM_TO_UINT8(adv_data.filt_index, p); + STREAM_TO_UINT8(adv_data.addr_type, p); + STREAM_TO_BDADDR(adv_data.bd_addr.address, p); + STREAM_TO_UINT8(adv_data.advertiser_state, p); + } - BTM_TRACE_EVENT("track_adv_vse_cback called: %d, %d, %d", adv_data.filt_index, - adv_data.addr_type, adv_data.advertiser_state); + BTM_TRACE_EVENT("track_adv_vse_cback called: %d, %d, %d", + adv_data.filt_index, adv_data.addr_type, + adv_data.advertiser_state); - // Make sure the device is known - BTM_SecAddBleDevice(adv_data.bd_addr.address, NULL, BT_DEVICE_TYPE_BLE, adv_data.addr_type); + // Make sure the device is known + BTM_SecAddBleDevice(adv_data.bd_addr.address, NULL, BT_DEVICE_TYPE_BLE, + adv_data.addr_type); - ble_advtrack_cb.p_track_cback(&adv_data); - return; - } + ble_advtrack_cb.p_track_cback(&adv_data); + return; + } } /******************************************************************************* @@ -142,18 +136,20 @@ void btm_ble_batchscan_filter_track_adv_vse_cback(uint8_t len, uint8_t *p) * Returns void * ******************************************************************************/ -void btm_ble_batchscan_enq_op_q(uint8_t opcode, tBTM_BLE_BATCH_SCAN_STATE cur_state, - uint8_t cb_evt, tBTM_BLE_REF_VALUE ref_value) -{ - ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.next_idx] = (opcode |(cb_evt << 4)); - ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.next_idx] = cur_state; - ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.next_idx] = ref_value; - BTM_TRACE_DEBUG("btm_ble_batchscan_enq_op_q: subcode:%d, Cur_state:%d, ref_value:%d", - ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.next_idx], - ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.next_idx], - ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.next_idx]); - ble_batchscan_cb.op_q.next_idx = (ble_batchscan_cb.op_q.next_idx + 1) - % BTM_BLE_BATCH_SCAN_MAX; +void btm_ble_batchscan_enq_op_q(uint8_t opcode, + tBTM_BLE_BATCH_SCAN_STATE cur_state, + uint8_t cb_evt, tBTM_BLE_REF_VALUE ref_value) { + ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.next_idx] = + (opcode | (cb_evt << 4)); + ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.next_idx] = cur_state; + ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.next_idx] = ref_value; + BTM_TRACE_DEBUG( + "btm_ble_batchscan_enq_op_q: subcode:%d, Cur_state:%d, ref_value:%d", + ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.next_idx], + ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.next_idx], + ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.next_idx]); + ble_batchscan_cb.op_q.next_idx = + (ble_batchscan_cb.op_q.next_idx + 1) % BTM_BLE_BATCH_SCAN_MAX; } /******************************************************************************* @@ -166,26 +162,32 @@ void btm_ble_batchscan_enq_op_q(uint8_t opcode, tBTM_BLE_BATCH_SCAN_STATE cur_st * Returns void * ******************************************************************************/ -tBTM_STATUS btm_ble_batchscan_enq_rep_q(uint8_t report_format, tBTM_BLE_REF_VALUE ref_value) -{ - int i = 0; - for (i = 0; i < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; i++) - { - if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[i]) - return BTM_ILLEGAL_VALUE; - } - - ble_batchscan_cb.main_rep_q.rep_mode[ble_batchscan_cb.main_rep_q.next_idx] = report_format; - ble_batchscan_cb.main_rep_q.ref_value[ble_batchscan_cb.main_rep_q.next_idx] = ref_value; - ble_batchscan_cb.main_rep_q.num_records[ble_batchscan_cb.main_rep_q.next_idx] = 0; - ble_batchscan_cb.main_rep_q.data_len[ble_batchscan_cb.main_rep_q.next_idx] = 0; - ble_batchscan_cb.main_rep_q.p_data[ble_batchscan_cb.main_rep_q.next_idx] = NULL; - BTM_TRACE_DEBUG("btm_ble_batchscan_enq_rep_q: index:%d, rep %d, ref %d", - ble_batchscan_cb.main_rep_q.next_idx, report_format, ref_value); - - ble_batchscan_cb.main_rep_q.next_idx = (ble_batchscan_cb.main_rep_q.next_idx + 1) - % BTM_BLE_BATCH_REP_MAIN_Q_SIZE; - return BTM_SUCCESS; +tBTM_STATUS btm_ble_batchscan_enq_rep_q(uint8_t report_format, + tBTM_BLE_REF_VALUE ref_value) { + int i = 0; + for (i = 0; i < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; i++) { + if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[i]) + return BTM_ILLEGAL_VALUE; + } + + ble_batchscan_cb.main_rep_q.rep_mode[ble_batchscan_cb.main_rep_q.next_idx] = + report_format; + ble_batchscan_cb.main_rep_q.ref_value[ble_batchscan_cb.main_rep_q.next_idx] = + ref_value; + ble_batchscan_cb.main_rep_q + .num_records[ble_batchscan_cb.main_rep_q.next_idx] = 0; + ble_batchscan_cb.main_rep_q.data_len[ble_batchscan_cb.main_rep_q.next_idx] = + 0; + ble_batchscan_cb.main_rep_q.p_data[ble_batchscan_cb.main_rep_q.next_idx] = + NULL; + BTM_TRACE_DEBUG("btm_ble_batchscan_enq_rep_q: index:%d, rep %d, ref %d", + ble_batchscan_cb.main_rep_q.next_idx, report_format, + ref_value); + + ble_batchscan_cb.main_rep_q.next_idx = + (ble_batchscan_cb.main_rep_q.next_idx + 1) % + BTM_BLE_BATCH_REP_MAIN_Q_SIZE; + return BTM_SUCCESS; } /******************************************************************************* @@ -197,45 +199,40 @@ tBTM_STATUS btm_ble_batchscan_enq_rep_q(uint8_t report_format, tBTM_BLE_REF_VALU * Returns void * ******************************************************************************/ -void btm_ble_batchscan_enq_rep_data(uint8_t report_format, uint8_t num_records, uint8_t *p_data, - uint8_t data_len) -{ - int index = 0; - - for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) - { - if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[index]) - break; - } - - BTM_TRACE_DEBUG("btm_ble_batchscan_enq_rep_data: index:%d, rep %d, num %d len : %d", - index, report_format, num_records, data_len); - - if (index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE && data_len > 0 && num_records > 0) - { - int len = ble_batchscan_cb.main_rep_q.data_len[index]; - uint8_t *p_orig_data = ble_batchscan_cb.main_rep_q.p_data[index]; - uint8_t *p_app_data; - - if (NULL != p_orig_data) - { - p_app_data = static_cast(osi_malloc(len + data_len)); - memcpy(p_app_data, p_orig_data, len); - memcpy(p_app_data+len, p_data, data_len); - osi_free(p_orig_data); - ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data; - ble_batchscan_cb.main_rep_q.num_records[index] += num_records; - ble_batchscan_cb.main_rep_q.data_len[index] += data_len; - } - else - { - p_app_data = static_cast(osi_malloc(data_len)); - memcpy(p_app_data, p_data, data_len); - ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data; - ble_batchscan_cb.main_rep_q.num_records[index] = num_records; - ble_batchscan_cb.main_rep_q.data_len[index] = data_len; - } +void btm_ble_batchscan_enq_rep_data(uint8_t report_format, uint8_t num_records, + uint8_t* p_data, uint8_t data_len) { + int index = 0; + + for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) { + if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[index]) break; + } + + BTM_TRACE_DEBUG( + "btm_ble_batchscan_enq_rep_data: index:%d, rep %d, num %d len : %d", + index, report_format, num_records, data_len); + + if (index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE && data_len > 0 && + num_records > 0) { + int len = ble_batchscan_cb.main_rep_q.data_len[index]; + uint8_t* p_orig_data = ble_batchscan_cb.main_rep_q.p_data[index]; + uint8_t* p_app_data; + + if (NULL != p_orig_data) { + p_app_data = static_cast(osi_malloc(len + data_len)); + memcpy(p_app_data, p_orig_data, len); + memcpy(p_app_data + len, p_data, data_len); + osi_free(p_orig_data); + ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data; + ble_batchscan_cb.main_rep_q.num_records[index] += num_records; + ble_batchscan_cb.main_rep_q.data_len[index] += data_len; + } else { + p_app_data = static_cast(osi_malloc(data_len)); + memcpy(p_app_data, p_data, data_len); + ble_batchscan_cb.main_rep_q.p_data[index] = p_app_data; + ble_batchscan_cb.main_rep_q.num_records[index] = num_records; + ble_batchscan_cb.main_rep_q.data_len[index] = data_len; } + } } /******************************************************************************* @@ -248,39 +245,39 @@ void btm_ble_batchscan_enq_rep_data(uint8_t report_format, uint8_t num_records, * Returns void * ******************************************************************************/ -void btm_ble_batchscan_deq_rep_data(uint8_t report_format, tBTM_BLE_REF_VALUE *p_ref_value, - uint8_t *p_num_records, uint8_t **p_data, uint16_t *p_data_len) -{ - int index = 0; - - for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) - { - if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[index]) - break; - } - - if (BTM_BLE_BATCH_REP_MAIN_Q_SIZE == index) - { - BTM_TRACE_ERROR("btm_ble_batchscan_deq_rep_data: rep_format:%d not found", report_format); - return; - } +void btm_ble_batchscan_deq_rep_data(uint8_t report_format, + tBTM_BLE_REF_VALUE* p_ref_value, + uint8_t* p_num_records, uint8_t** p_data, + uint16_t* p_data_len) { + int index = 0; + + for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) { + if (report_format == ble_batchscan_cb.main_rep_q.rep_mode[index]) break; + } + + if (BTM_BLE_BATCH_REP_MAIN_Q_SIZE == index) { + BTM_TRACE_ERROR("btm_ble_batchscan_deq_rep_data: rep_format:%d not found", + report_format); + return; + } - *p_num_records = ble_batchscan_cb.main_rep_q.num_records[index]; - *p_ref_value = ble_batchscan_cb.main_rep_q.ref_value[index]; - *p_data = ble_batchscan_cb.main_rep_q.p_data[index]; - *p_data_len = ble_batchscan_cb.main_rep_q.data_len[index]; + *p_num_records = ble_batchscan_cb.main_rep_q.num_records[index]; + *p_ref_value = ble_batchscan_cb.main_rep_q.ref_value[index]; + *p_data = ble_batchscan_cb.main_rep_q.p_data[index]; + *p_data_len = ble_batchscan_cb.main_rep_q.data_len[index]; - ble_batchscan_cb.main_rep_q.p_data[index] = NULL; - ble_batchscan_cb.main_rep_q.data_len[index] = 0; - ble_batchscan_cb.main_rep_q.rep_mode[index] = 0; - ble_batchscan_cb.main_rep_q.ref_value[index] = 0; - ble_batchscan_cb.main_rep_q.num_records[index] = 0; + ble_batchscan_cb.main_rep_q.p_data[index] = NULL; + ble_batchscan_cb.main_rep_q.data_len[index] = 0; + ble_batchscan_cb.main_rep_q.rep_mode[index] = 0; + ble_batchscan_cb.main_rep_q.ref_value[index] = 0; + ble_batchscan_cb.main_rep_q.num_records[index] = 0; - BTM_TRACE_DEBUG("btm_ble_batchscan_deq_rep_data: index:%d, rep %d, num %d, data_len %d", - index, report_format, *p_num_records, *p_data_len); + BTM_TRACE_DEBUG( + "btm_ble_batchscan_deq_rep_data: index:%d, rep %d, num %d, data_len %d", + index, report_format, *p_num_records, *p_data_len); - ble_batchscan_cb.main_rep_q.pending_idx = (ble_batchscan_cb.main_rep_q.pending_idx + 1) - % BTM_BLE_BATCH_SCAN_MAX; + ble_batchscan_cb.main_rep_q.pending_idx = + (ble_batchscan_cb.main_rep_q.pending_idx + 1) % BTM_BLE_BATCH_SCAN_MAX; } /******************************************************************************* @@ -293,16 +290,19 @@ void btm_ble_batchscan_deq_rep_data(uint8_t report_format, tBTM_BLE_REF_VALUE *p * Returns void * ******************************************************************************/ -void btm_ble_batchscan_deq_op_q(uint8_t *p_opcode,tBTM_BLE_BATCH_SCAN_STATE *cur_state, - uint8_t *p_cb_evt, tBTM_BLE_REF_VALUE *p_ref) -{ - *p_cb_evt = (ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.pending_idx] >> 4); - *p_opcode = (ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.pending_idx] - & BTM_BLE_BATCH_SCAN_SUBCODE_MASK); - *p_ref = ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.pending_idx]; - *cur_state = (ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.pending_idx]); - ble_batchscan_cb.op_q.pending_idx = (ble_batchscan_cb.op_q.pending_idx + 1) - % BTM_BLE_BATCH_SCAN_MAX; +void btm_ble_batchscan_deq_op_q(uint8_t* p_opcode, + tBTM_BLE_BATCH_SCAN_STATE* cur_state, + uint8_t* p_cb_evt, tBTM_BLE_REF_VALUE* p_ref) { + *p_cb_evt = + (ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.pending_idx] >> 4); + *p_opcode = + (ble_batchscan_cb.op_q.sub_code[ble_batchscan_cb.op_q.pending_idx] & + BTM_BLE_BATCH_SCAN_SUBCODE_MASK); + *p_ref = ble_batchscan_cb.op_q.ref_value[ble_batchscan_cb.op_q.pending_idx]; + *cur_state = + (ble_batchscan_cb.op_q.cur_state[ble_batchscan_cb.op_q.pending_idx]); + ble_batchscan_cb.op_q.pending_idx = + (ble_batchscan_cb.op_q.pending_idx + 1) % BTM_BLE_BATCH_SCAN_MAX; } /******************************************************************************* @@ -317,22 +317,23 @@ void btm_ble_batchscan_deq_op_q(uint8_t *p_opcode,tBTM_BLE_BATCH_SCAN_STATE *cur * ******************************************************************************/ void btm_ble_read_batchscan_reports(tBTM_BLE_BATCH_SCAN_MODE scan_mode, - tBTM_BLE_REF_VALUE ref_value) -{ - uint8_t param[BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN], *pp; - pp = param; + tBTM_BLE_REF_VALUE ref_value) { + uint8_t param[BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN], *pp; + pp = param; - memset(param, 0, BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN); + memset(param, 0, BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN); - UINT8_TO_STREAM (pp, BTM_BLE_BATCH_SCAN_READ_RESULTS); - UINT8_TO_STREAM (pp, scan_mode); + UINT8_TO_STREAM(pp, BTM_BLE_BATCH_SCAN_READ_RESULTS); + UINT8_TO_STREAM(pp, scan_mode); - BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, - BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN, param, btm_ble_batchscan_vsc_cmpl_cback); + BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, + BTM_BLE_BATCH_SCAN_READ_RESULTS_LEN, param, + btm_ble_batchscan_vsc_cmpl_cback); - /* The user needs to be provided scan read reports event */ - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_READ_RESULTS, ble_batchscan_cb.cur_state, - BTM_BLE_BATCH_SCAN_READ_REPTS_EVT, ref_value); + /* The user needs to be provided scan read reports event */ + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_READ_RESULTS, + ble_batchscan_cb.cur_state, + BTM_BLE_BATCH_SCAN_READ_REPTS_EVT, ref_value); } /******************************************************************************* @@ -346,127 +347,120 @@ void btm_ble_read_batchscan_reports(tBTM_BLE_BATCH_SCAN_MODE scan_mode, * Returns void * ******************************************************************************/ -void btm_ble_batchscan_vsc_cmpl_cback (tBTM_VSC_CMPL *p_params) -{ - uint8_t *p = p_params->p_param_buf; - uint16_t len = p_params->param_len; - tBTM_BLE_REF_VALUE ref_value = 0; - - uint8_t status = 0, subcode = 0, opcode = 0; - uint8_t report_format = 0, num_records = 0, cb_evt = 0; - uint16_t data_len = 0; - tBTM_BLE_BATCH_SCAN_STATE cur_state = BTM_BLE_SCAN_INVALID_STATE; - uint8_t *p_data = NULL; - - if (len < 2) - { - BTM_TRACE_ERROR("wrong length for btm_ble_batch_scan_vsc_cmpl_cback"); - btm_ble_batchscan_deq_op_q(&opcode, &cur_state, &cb_evt, &ref_value); - return; - } +void btm_ble_batchscan_vsc_cmpl_cback(tBTM_VSC_CMPL* p_params) { + uint8_t* p = p_params->p_param_buf; + uint16_t len = p_params->param_len; + tBTM_BLE_REF_VALUE ref_value = 0; + + uint8_t status = 0, subcode = 0, opcode = 0; + uint8_t report_format = 0, num_records = 0, cb_evt = 0; + uint16_t data_len = 0; + tBTM_BLE_BATCH_SCAN_STATE cur_state = BTM_BLE_SCAN_INVALID_STATE; + uint8_t* p_data = NULL; + + if (len < 2) { + BTM_TRACE_ERROR("wrong length for btm_ble_batch_scan_vsc_cmpl_cback"); + btm_ble_batchscan_deq_op_q(&opcode, &cur_state, &cb_evt, &ref_value); + return; + } - STREAM_TO_UINT8(status, p); - STREAM_TO_UINT8(subcode, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT8(subcode, p); - btm_ble_batchscan_deq_op_q(&opcode, &cur_state, &cb_evt, &ref_value); + btm_ble_batchscan_deq_op_q(&opcode, &cur_state, &cb_evt, &ref_value); - BTM_TRACE_DEBUG("btm_ble_batchscan op_code = %02x state = %02x cb_evt = %02x,ref_value=%d", - opcode, cur_state, cb_evt, ref_value); + BTM_TRACE_DEBUG( + "btm_ble_batchscan op_code = %02x state = %02x cb_evt = " + "%02x,ref_value=%d", + opcode, cur_state, cb_evt, ref_value); - if (opcode != subcode) - { - BTM_TRACE_ERROR("Got unexpected VSC cmpl, expected: %d got: %d",subcode,opcode); - return; + if (opcode != subcode) { + BTM_TRACE_ERROR("Got unexpected VSC cmpl, expected: %d got: %d", subcode, + opcode); + return; + } + + switch (subcode) { + case BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE: { + if (BTM_SUCCESS == status && BTM_BLE_SCAN_ENABLE_CALLED == cur_state) + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLED_STATE; + else if (BTM_BLE_SCAN_ENABLE_CALLED == cur_state) { + BTM_TRACE_ERROR( + "SCAN_ENB_DISAB_CUST_FEATURE - Invalid state after enb"); + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_INVALID_STATE; + } + + BTM_TRACE_DEBUG( + "BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEAT status = %d, state: " + "%d,evt=%d", + status, ble_batchscan_cb.cur_state, cb_evt); + + if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) + ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); + break; } - switch (subcode) - { - case BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE: - { - if (BTM_SUCCESS == status && BTM_BLE_SCAN_ENABLE_CALLED == cur_state) - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLED_STATE; - else - if (BTM_BLE_SCAN_ENABLE_CALLED == cur_state) - { - BTM_TRACE_ERROR("SCAN_ENB_DISAB_CUST_FEATURE - Invalid state after enb"); - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_INVALID_STATE; - } - - BTM_TRACE_DEBUG("BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEAT status = %d, state: %d,evt=%d", - status, ble_batchscan_cb.cur_state, cb_evt); - - if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) - ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); - break; - } + case BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM: { + BTM_TRACE_DEBUG( + "BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM status = %d, evt=%d", status, + cb_evt); + if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) + ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); + break; + } - case BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM: - { - BTM_TRACE_DEBUG("BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM status = %d, evt=%d", - status, cb_evt); - if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) - ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); - break; + case BTM_BLE_BATCH_SCAN_SET_PARAMS: { + BTM_TRACE_DEBUG("BTM_BLE_BATCH_SCAN_SET_PARAMS status = %d,evt=%d", + status, cb_evt); + + if (BTM_BLE_SCAN_DISABLE_CALLED == cur_state) { + if (BTM_SUCCESS == status) { + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_DISABLED_STATE; + } else { + BTM_TRACE_ERROR( + "BTM_BLE_BATCH_SCAN_SET_PARAMS - Invalid state after disabled"); + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_INVALID_STATE; } + } - case BTM_BLE_BATCH_SCAN_SET_PARAMS: - { - BTM_TRACE_DEBUG("BTM_BLE_BATCH_SCAN_SET_PARAMS status = %d,evt=%d", status, cb_evt); - - if (BTM_BLE_SCAN_DISABLE_CALLED == cur_state) - { - if (BTM_SUCCESS == status) - { - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_DISABLED_STATE; - } - else - { - BTM_TRACE_ERROR("BTM_BLE_BATCH_SCAN_SET_PARAMS - Invalid state after disabled"); - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_INVALID_STATE; - } - } - - if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) - ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); - break; - } + if (cb_evt != 0 && NULL != ble_batchscan_cb.p_setup_cback) + ble_batchscan_cb.p_setup_cback(cb_evt, ref_value, status); + break; + } - case BTM_BLE_BATCH_SCAN_READ_RESULTS: - { - if (cb_evt != 0 && NULL != ble_batchscan_cb.p_scan_rep_cback) - { - STREAM_TO_UINT8(report_format,p); - STREAM_TO_UINT8(num_records, p); - p = (uint8_t *)(p_params->p_param_buf + 4); - BTM_TRACE_DEBUG("BTM_BLE_BATCH_SCAN_READ_RESULTS status=%d,len=%d,rec=%d", - status, len-4, num_records); - - if (0 == num_records) - { - btm_ble_batchscan_deq_rep_data(report_format, &ref_value, &num_records, - &p_data, &data_len); - if (NULL != ble_batchscan_cb.p_scan_rep_cback) - ble_batchscan_cb.p_scan_rep_cback(ref_value,report_format, num_records, - data_len, p_data, status); - } - else - { - if ((len-4) > 0) - { - btm_ble_batchscan_enq_rep_data(report_format, num_records, p, len-4); - /* More records could be in the buffer and needs to be pulled out */ - btm_ble_read_batchscan_reports(report_format, ref_value); - } - } - } - break; + case BTM_BLE_BATCH_SCAN_READ_RESULTS: { + if (cb_evt != 0 && NULL != ble_batchscan_cb.p_scan_rep_cback) { + STREAM_TO_UINT8(report_format, p); + STREAM_TO_UINT8(num_records, p); + p = (uint8_t*)(p_params->p_param_buf + 4); + BTM_TRACE_DEBUG( + "BTM_BLE_BATCH_SCAN_READ_RESULTS status=%d,len=%d,rec=%d", status, + len - 4, num_records); + + if (0 == num_records) { + btm_ble_batchscan_deq_rep_data(report_format, &ref_value, + &num_records, &p_data, &data_len); + if (NULL != ble_batchscan_cb.p_scan_rep_cback) + ble_batchscan_cb.p_scan_rep_cback(ref_value, report_format, + num_records, data_len, p_data, + status); + } else { + if ((len - 4) > 0) { + btm_ble_batchscan_enq_rep_data(report_format, num_records, p, + len - 4); + /* More records could be in the buffer and needs to be pulled out */ + btm_ble_read_batchscan_reports(report_format, ref_value); + } } - - default: - break; + } + break; } - return; + default: + break; + } + + return; } /******************************************************************************* @@ -483,22 +477,22 @@ void btm_ble_batchscan_vsc_cmpl_cback (tBTM_VSC_CMPL *p_params) * based on total space * ******************************************************************************/ -void btm_ble_set_storage_config(uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, - uint8_t batch_scan_notify_threshold) -{ - uint8_t param[BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN], *pp; - - pp = param; - memset(param, 0, BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN); - - UINT8_TO_STREAM (pp, BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM); - UINT8_TO_STREAM (pp, batch_scan_full_max); - UINT8_TO_STREAM (pp, batch_scan_trunc_max); - UINT8_TO_STREAM (pp, batch_scan_notify_threshold); - - BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, - BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN, param, - btm_ble_batchscan_vsc_cmpl_cback); +void btm_ble_set_storage_config(uint8_t batch_scan_full_max, + uint8_t batch_scan_trunc_max, + uint8_t batch_scan_notify_threshold) { + uint8_t param[BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN], *pp; + + pp = param; + memset(param, 0, BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN); + + UINT8_TO_STREAM(pp, BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM); + UINT8_TO_STREAM(pp, batch_scan_full_max); + UINT8_TO_STREAM(pp, batch_scan_trunc_max); + UINT8_TO_STREAM(pp, batch_scan_notify_threshold); + + BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, + BTM_BLE_BATCH_SCAN_STORAGE_CFG_LEN, param, + btm_ble_batchscan_vsc_cmpl_cback); } /******************************************************************************* @@ -515,28 +509,28 @@ void btm_ble_set_storage_config(uint8_t batch_scan_full_max, uint8_t batch_scan_ * ******************************************************************************/ void btm_ble_set_batchscan_param(tBTM_BLE_BATCH_SCAN_MODE scan_mode, - uint32_t scan_interval, uint32_t scan_window, tBLE_ADDR_TYPE addr_type, - tBTM_BLE_DISCARD_RULE discard_rule) -{ - uint8_t scan_param[BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN], *pp_scan; - - pp_scan = scan_param; - memset(scan_param, 0, BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN); - - // Override param and decide addr_type based on own addr type - // TODO: Remove upper layer parameter? - addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type; - - UINT8_TO_STREAM (pp_scan, BTM_BLE_BATCH_SCAN_SET_PARAMS); - UINT8_TO_STREAM (pp_scan, scan_mode); - UINT32_TO_STREAM (pp_scan, scan_window); - UINT32_TO_STREAM (pp_scan, scan_interval); - UINT8_TO_STREAM (pp_scan, addr_type); - UINT8_TO_STREAM (pp_scan, discard_rule); - - BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, - BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN, - scan_param, btm_ble_batchscan_vsc_cmpl_cback); + uint32_t scan_interval, uint32_t scan_window, + tBLE_ADDR_TYPE addr_type, + tBTM_BLE_DISCARD_RULE discard_rule) { + uint8_t scan_param[BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN], *pp_scan; + + pp_scan = scan_param; + memset(scan_param, 0, BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN); + + // Override param and decide addr_type based on own addr type + // TODO: Remove upper layer parameter? + addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type; + + UINT8_TO_STREAM(pp_scan, BTM_BLE_BATCH_SCAN_SET_PARAMS); + UINT8_TO_STREAM(pp_scan, scan_mode); + UINT32_TO_STREAM(pp_scan, scan_window); + UINT32_TO_STREAM(pp_scan, scan_interval); + UINT8_TO_STREAM(pp_scan, addr_type); + UINT8_TO_STREAM(pp_scan, discard_rule); + + BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, + BTM_BLE_BATCH_SCAN_PARAM_CONFIG_LEN, scan_param, + btm_ble_batchscan_vsc_cmpl_cback); } /******************************************************************************* @@ -549,35 +543,32 @@ void btm_ble_set_batchscan_param(tBTM_BLE_BATCH_SCAN_MODE scan_mode, * Parameters enable_disable: true - enable, false - disable * ******************************************************************************/ -void btm_ble_enable_disable_batchscan(bool should_enable) -{ - uint8_t shld_enable = 0x01; - uint8_t enable_param[BTM_BLE_BATCH_SCAN_ENB_DISB_LEN], *pp_enable; +void btm_ble_enable_disable_batchscan(bool should_enable) { + uint8_t shld_enable = 0x01; + uint8_t enable_param[BTM_BLE_BATCH_SCAN_ENB_DISB_LEN], *pp_enable; - if (!should_enable) - shld_enable = 0x00; + if (!should_enable) shld_enable = 0x00; - if (should_enable) - { - pp_enable = enable_param; - memset(enable_param, 0, BTM_BLE_BATCH_SCAN_ENB_DISB_LEN); + if (should_enable) { + pp_enable = enable_param; + memset(enable_param, 0, BTM_BLE_BATCH_SCAN_ENB_DISB_LEN); - UINT8_TO_STREAM (pp_enable, BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE); - UINT8_TO_STREAM (pp_enable, shld_enable); + UINT8_TO_STREAM(pp_enable, BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE); + UINT8_TO_STREAM(pp_enable, shld_enable); - BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, - BTM_BLE_BATCH_SCAN_ENB_DISB_LEN, enable_param, - btm_ble_batchscan_vsc_cmpl_cback); - } - else - btm_ble_set_batchscan_param(BTM_BLE_BATCH_SCAN_MODE_DISABLE, - ble_batchscan_cb.scan_interval, ble_batchscan_cb.scan_window, - ble_batchscan_cb.addr_type, ble_batchscan_cb.discard_rule); - - if (should_enable) - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLE_CALLED; - else - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_DISABLE_CALLED; + BTM_VendorSpecificCommand(HCI_BLE_BATCH_SCAN_OCF, + BTM_BLE_BATCH_SCAN_ENB_DISB_LEN, enable_param, + btm_ble_batchscan_vsc_cmpl_cback); + } else + btm_ble_set_batchscan_param( + BTM_BLE_BATCH_SCAN_MODE_DISABLE, ble_batchscan_cb.scan_interval, + ble_batchscan_cb.scan_window, ble_batchscan_cb.addr_type, + ble_batchscan_cb.discard_rule); + + if (should_enable) + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLE_CALLED; + else + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_DISABLE_CALLED; } /******************************************************************************* @@ -600,63 +591,58 @@ void btm_ble_enable_disable_batchscan(bool should_enable) * Returns tBTM_STATUS * ******************************************************************************/ -tBTM_STATUS BTM_BleSetStorageConfig(uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, - uint8_t batch_scan_notify_threshold, - tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback, - tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback, - tBTM_BLE_SCAN_REP_CBACK* p_rep_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - - BTM_TRACE_EVENT (" BTM_BleSetStorageConfig: %d, %d, %d, %d, %d", - ble_batchscan_cb.cur_state, ref_value, batch_scan_full_max, batch_scan_trunc_max, - batch_scan_notify_threshold); - - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - - if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) - { - BTM_TRACE_ERROR("Controller does not support batch scan"); - return BTM_ERR_PROCESSING; - } - - ble_batchscan_cb.p_setup_cback = p_setup_cback; - ble_batchscan_cb.p_thres_cback = p_thres_cback; - ble_batchscan_cb.p_scan_rep_cback = p_rep_cback; - ble_batchscan_cb.ref_value = ref_value; - - if (batch_scan_full_max > BTM_BLE_ADV_SCAN_FULL_MAX || - batch_scan_trunc_max > BTM_BLE_ADV_SCAN_TRUNC_MAX || - batch_scan_notify_threshold > BTM_BLE_ADV_SCAN_THR_MAX) - { - BTM_TRACE_ERROR("Illegal set storage config params"); - return BTM_ILLEGAL_VALUE; - } - - if (BTM_BLE_SCAN_INVALID_STATE == ble_batchscan_cb.cur_state || - BTM_BLE_SCAN_DISABLED_STATE == ble_batchscan_cb.cur_state || - BTM_BLE_SCAN_DISABLE_CALLED == ble_batchscan_cb.cur_state) - { - btm_ble_enable_disable_batchscan(true); - ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLE_CALLED; - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE, - BTM_BLE_SCAN_ENABLE_CALLED, 0, ref_value); - } - - btm_ble_set_storage_config(batch_scan_full_max, batch_scan_trunc_max, - batch_scan_notify_threshold); - /* The user needs to be provided scan config storage event */ - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM, ble_batchscan_cb.cur_state, - BTM_BLE_BATCH_SCAN_CFG_STRG_EVT, ref_value); - - return BTM_CMD_STARTED; +tBTM_STATUS BTM_BleSetStorageConfig( + uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, + uint8_t batch_scan_notify_threshold, + tBTM_BLE_SCAN_SETUP_CBACK* p_setup_cback, + tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback, + tBTM_BLE_SCAN_REP_CBACK* p_rep_cback, tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + + BTM_TRACE_EVENT(" BTM_BleSetStorageConfig: %d, %d, %d, %d, %d", + ble_batchscan_cb.cur_state, ref_value, batch_scan_full_max, + batch_scan_trunc_max, batch_scan_notify_threshold); + + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; + + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + + if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) { + BTM_TRACE_ERROR("Controller does not support batch scan"); + return BTM_ERR_PROCESSING; + } + + ble_batchscan_cb.p_setup_cback = p_setup_cback; + ble_batchscan_cb.p_thres_cback = p_thres_cback; + ble_batchscan_cb.p_scan_rep_cback = p_rep_cback; + ble_batchscan_cb.ref_value = ref_value; + + if (batch_scan_full_max > BTM_BLE_ADV_SCAN_FULL_MAX || + batch_scan_trunc_max > BTM_BLE_ADV_SCAN_TRUNC_MAX || + batch_scan_notify_threshold > BTM_BLE_ADV_SCAN_THR_MAX) { + BTM_TRACE_ERROR("Illegal set storage config params"); + return BTM_ILLEGAL_VALUE; + } + + if (BTM_BLE_SCAN_INVALID_STATE == ble_batchscan_cb.cur_state || + BTM_BLE_SCAN_DISABLED_STATE == ble_batchscan_cb.cur_state || + BTM_BLE_SCAN_DISABLE_CALLED == ble_batchscan_cb.cur_state) { + btm_ble_enable_disable_batchscan(true); + ble_batchscan_cb.cur_state = BTM_BLE_SCAN_ENABLE_CALLED; + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE, + BTM_BLE_SCAN_ENABLE_CALLED, 0, ref_value); + } + + btm_ble_set_storage_config(batch_scan_full_max, batch_scan_trunc_max, + batch_scan_notify_threshold); + /* The user needs to be provided scan config storage event */ + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM, + ble_batchscan_cb.cur_state, + BTM_BLE_BATCH_SCAN_CFG_STRG_EVT, ref_value); + + return BTM_CMD_STARTED; } - /******************************************************************************* * * Function BTM_BleEnableBatchScan @@ -674,64 +660,66 @@ tBTM_STATUS BTM_BleSetStorageConfig(uint8_t batch_scan_full_max, uint8_t batch_s * ******************************************************************************/ tBTM_STATUS BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode, - uint32_t scan_interval, uint32_t scan_window, tBLE_ADDR_TYPE addr_type, - tBTM_BLE_DISCARD_RULE discard_rule, tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - BTM_TRACE_EVENT (" BTM_BleEnableBatchScan: %d, %d, %d, %d, %d, %d", - scan_mode, scan_interval, scan_window, addr_type, discard_rule, ref_value); - - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - - if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) - { - BTM_TRACE_ERROR("Controller does not support batch scan"); - return BTM_ERR_PROCESSING; + uint32_t scan_interval, uint32_t scan_window, + tBLE_ADDR_TYPE addr_type, + tBTM_BLE_DISCARD_RULE discard_rule, + tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + BTM_TRACE_EVENT(" BTM_BleEnableBatchScan: %d, %d, %d, %d, %d, %d", scan_mode, + scan_interval, scan_window, addr_type, discard_rule, + ref_value); + + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; + + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + + if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) { + BTM_TRACE_ERROR("Controller does not support batch scan"); + return BTM_ERR_PROCESSING; + } + + BTM_TRACE_DEBUG("BTM_BleEnableBatchScan: %d, %x, %x, %d, %d", scan_mode, + scan_interval, scan_window, discard_rule, + ble_batchscan_cb.cur_state); + + /* Only 16 bits will be used for scan interval and scan window as per + * agreement with Google */ + /* So the standard LE range would suffice for scan interval and scan window */ + if ((BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, + BTM_BLE_SCAN_INT_MAX) || + BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, + BTM_BLE_SCAN_WIN_MAX)) && + (BTM_BLE_BATCH_SCAN_MODE_PASS == scan_mode || + BTM_BLE_BATCH_SCAN_MODE_ACTI == scan_mode || + BTM_BLE_BATCH_SCAN_MODE_PASS_ACTI == scan_mode) && + (BTM_BLE_DISCARD_OLD_ITEMS == discard_rule || + BTM_BLE_DISCARD_LOWER_RSSI_ITEMS == discard_rule)) { + if (BTM_BLE_SCAN_INVALID_STATE == ble_batchscan_cb.cur_state || + BTM_BLE_SCAN_DISABLED_STATE == ble_batchscan_cb.cur_state || + BTM_BLE_SCAN_DISABLE_CALLED == ble_batchscan_cb.cur_state) { + btm_ble_enable_disable_batchscan(true); + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE, + BTM_BLE_SCAN_ENABLE_CALLED, 0, ref_value); } - BTM_TRACE_DEBUG("BTM_BleEnableBatchScan: %d, %x, %x, %d, %d", scan_mode, scan_interval, - scan_window, discard_rule, ble_batchscan_cb.cur_state); - - /* Only 16 bits will be used for scan interval and scan window as per agreement with Google */ - /* So the standard LE range would suffice for scan interval and scan window */ - if ((BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) || - BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX)) - && (BTM_BLE_BATCH_SCAN_MODE_PASS == scan_mode || BTM_BLE_BATCH_SCAN_MODE_ACTI == scan_mode - || BTM_BLE_BATCH_SCAN_MODE_PASS_ACTI == scan_mode) - && (BTM_BLE_DISCARD_OLD_ITEMS == discard_rule || - BTM_BLE_DISCARD_LOWER_RSSI_ITEMS == discard_rule)) - { - if (BTM_BLE_SCAN_INVALID_STATE == ble_batchscan_cb.cur_state || - BTM_BLE_SCAN_DISABLED_STATE == ble_batchscan_cb.cur_state || - BTM_BLE_SCAN_DISABLE_CALLED == ble_batchscan_cb.cur_state) - { - btm_ble_enable_disable_batchscan(true); - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE, - BTM_BLE_SCAN_ENABLE_CALLED, 0, ref_value); - } + ble_batchscan_cb.scan_mode = scan_mode; + ble_batchscan_cb.scan_interval = scan_interval; + ble_batchscan_cb.scan_window = scan_window; + ble_batchscan_cb.addr_type = addr_type; + ble_batchscan_cb.discard_rule = discard_rule; + /* This command starts batch scanning, if enabled */ + btm_ble_set_batchscan_param(scan_mode, scan_interval, scan_window, + addr_type, discard_rule); - ble_batchscan_cb.scan_mode = scan_mode; - ble_batchscan_cb.scan_interval = scan_interval; - ble_batchscan_cb.scan_window = scan_window; - ble_batchscan_cb.addr_type = addr_type; - ble_batchscan_cb.discard_rule = discard_rule; - /* This command starts batch scanning, if enabled */ - btm_ble_set_batchscan_param(scan_mode, scan_interval, scan_window, addr_type, - discard_rule); - - /* The user needs to be provided scan enable event */ - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_PARAMS, ble_batchscan_cb.cur_state, - BTM_BLE_BATCH_SCAN_ENABLE_EVT, ref_value); - } - else - { - BTM_TRACE_ERROR("Illegal enable scan params"); - return BTM_ILLEGAL_VALUE; - } - return BTM_CMD_STARTED; + /* The user needs to be provided scan enable event */ + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_PARAMS, + ble_batchscan_cb.cur_state, + BTM_BLE_BATCH_SCAN_ENABLE_EVT, ref_value); + } else { + BTM_TRACE_ERROR("Illegal enable scan params"); + return BTM_ILLEGAL_VALUE; + } + return BTM_CMD_STARTED; } /******************************************************************************* @@ -743,28 +731,25 @@ tBTM_STATUS BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode, * Parameters: ref_value - Reference value * ******************************************************************************/ -tBTM_STATUS BTM_BleDisableBatchScan(tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - BTM_TRACE_EVENT (" BTM_BleDisableBatchScan"); +tBTM_STATUS BTM_BleDisableBatchScan(tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + BTM_TRACE_EVENT(" BTM_BleDisableBatchScan"); - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) - { - BTM_TRACE_ERROR("Controller does not support batch scan"); - return BTM_ERR_PROCESSING; - } + if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) { + BTM_TRACE_ERROR("Controller does not support batch scan"); + return BTM_ERR_PROCESSING; + } - btm_ble_enable_disable_batchscan(false); - /* The user needs to be provided scan disable event */ - btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_PARAMS, - BTM_BLE_SCAN_DISABLE_CALLED, BTM_BLE_BATCH_SCAN_DISABLE_EVT, - ref_value); - return BTM_CMD_STARTED; + btm_ble_enable_disable_batchscan(false); + /* The user needs to be provided scan disable event */ + btm_ble_batchscan_enq_op_q(BTM_BLE_BATCH_SCAN_SET_PARAMS, + BTM_BLE_SCAN_DISABLE_CALLED, + BTM_BLE_BATCH_SCAN_DISABLE_EVT, ref_value); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -780,51 +765,44 @@ tBTM_STATUS BTM_BleDisableBatchScan(tBTM_BLE_REF_VALUE ref_value) * ******************************************************************************/ tBTM_STATUS BTM_BleReadScanReports(tBTM_BLE_BATCH_SCAN_MODE scan_mode, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_STATUS status = BTM_NO_RESOURCES; - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - uint8_t read_scan_mode = 0; - - BTM_TRACE_EVENT (" BTM_BleReadScanReports; %d, %d", scan_mode, ref_value); - - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - - if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) - { - BTM_TRACE_ERROR("Controller does not support batch scan"); - return BTM_ERR_PROCESSING; + tBTM_BLE_REF_VALUE ref_value) { + tBTM_STATUS status = BTM_NO_RESOURCES; + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + uint8_t read_scan_mode = 0; + + BTM_TRACE_EVENT(" BTM_BleReadScanReports; %d, %d", scan_mode, ref_value); + + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; + + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + + if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) { + BTM_TRACE_ERROR("Controller does not support batch scan"); + return BTM_ERR_PROCESSING; + } + + /* Check if the requested scan mode has already been setup by the user */ + read_scan_mode = ble_batchscan_cb.scan_mode & BTM_BLE_BATCH_SCAN_MODE_ACTI; + if (0 == read_scan_mode) + read_scan_mode = ble_batchscan_cb.scan_mode & BTM_BLE_BATCH_SCAN_MODE_PASS; + + /* Check only for modes, as scan reports can be called after disabling batch + * scan */ + if (read_scan_mode > 0 && (BTM_BLE_BATCH_SCAN_MODE_PASS == scan_mode || + BTM_BLE_BATCH_SCAN_MODE_ACTI == scan_mode)) { + status = btm_ble_batchscan_enq_rep_q(scan_mode, ref_value); + if (BTM_SUCCESS == status) { + btm_ble_read_batchscan_reports(scan_mode, ref_value); + status = BTM_CMD_STARTED; } - - /* Check if the requested scan mode has already been setup by the user */ - read_scan_mode = ble_batchscan_cb.scan_mode & BTM_BLE_BATCH_SCAN_MODE_ACTI; - if (0 == read_scan_mode) - read_scan_mode = ble_batchscan_cb.scan_mode & BTM_BLE_BATCH_SCAN_MODE_PASS; - - /* Check only for modes, as scan reports can be called after disabling batch scan */ - if (read_scan_mode > 0 && (BTM_BLE_BATCH_SCAN_MODE_PASS == scan_mode || - BTM_BLE_BATCH_SCAN_MODE_ACTI == scan_mode)) - { - status = btm_ble_batchscan_enq_rep_q(scan_mode, ref_value); - if (BTM_SUCCESS == status) - { - btm_ble_read_batchscan_reports(scan_mode, ref_value); - status = BTM_CMD_STARTED; - } - } - else - { - BTM_TRACE_ERROR("Illegal read scan params: %d, %d, %d", read_scan_mode, scan_mode, - ble_batchscan_cb.cur_state); - return BTM_ILLEGAL_VALUE; - } - return status; + } else { + BTM_TRACE_ERROR("Illegal read scan params: %d, %d, %d", read_scan_mode, + scan_mode, ble_batchscan_cb.cur_state); + return BTM_ILLEGAL_VALUE; + } + return status; } - /******************************************************************************* * * Function BTM_BleTrackAdvertiser @@ -838,25 +816,22 @@ tBTM_STATUS BTM_BleReadScanReports(tBTM_BLE_BATCH_SCAN_MODE scan_mode, * Returns tBTM_STATUS * ******************************************************************************/ -tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - BTM_TRACE_EVENT (" BTM_BleTrackAdvertiser"); - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - - if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) - { - BTM_TRACE_ERROR("Controller does not support scan storage"); - return BTM_ERR_PROCESSING; - } - - ble_advtrack_cb.p_track_cback = p_track_cback; - ble_advtrack_cb.ref_value = ref_value; - return BTM_CMD_STARTED; +tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK* p_track_cback, + tBTM_BLE_REF_VALUE ref_value) { + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + BTM_TRACE_EVENT(" BTM_BleTrackAdvertiser"); + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; + + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + + if (0 == cmn_ble_vsc_cb.tot_scan_results_strg) { + BTM_TRACE_ERROR("Controller does not support scan storage"); + return BTM_ERR_PROCESSING; + } + + ble_advtrack_cb.p_track_cback = p_track_cback; + ble_advtrack_cb.ref_value = ref_value; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -870,12 +845,11 @@ tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback, * Returns status * ******************************************************************************/ -void btm_ble_batchscan_init(void) -{ - BTM_TRACE_EVENT (" btm_ble_batchscan_init"); - memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); - memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); - BTM_RegisterForVSEvents(btm_ble_batchscan_filter_track_adv_vse_cback, true); +void btm_ble_batchscan_init(void) { + BTM_TRACE_EVENT(" btm_ble_batchscan_init"); + memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); + memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); + BTM_RegisterForVSEvents(btm_ble_batchscan_filter_track_adv_vse_cback, true); } /******************************************************************************* @@ -889,15 +863,13 @@ void btm_ble_batchscan_init(void) * Returns void * ******************************************************************************/ -void btm_ble_batchscan_cleanup(void) -{ - int index = 0; - BTM_TRACE_EVENT (" btm_ble_batchscan_cleanup"); +void btm_ble_batchscan_cleanup(void) { + int index = 0; + BTM_TRACE_EVENT(" btm_ble_batchscan_cleanup"); - for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) - osi_free_and_reset((void **)&ble_batchscan_cb.main_rep_q.p_data[index]); + for (index = 0; index < BTM_BLE_BATCH_REP_MAIN_Q_SIZE; index++) + osi_free_and_reset((void**)&ble_batchscan_cb.main_rep_q.p_data[index]); - memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); - memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); + memset(&ble_batchscan_cb, 0, sizeof(tBTM_BLE_BATCH_SCAN_CB)); + memset(&ble_advtrack_cb, 0, sizeof(tBTM_BLE_ADV_TRACK_CB)); } - diff --git a/stack/btm/btm_ble_bgconn.cc b/stack/btm/btm_ble_bgconn.cc index fcf66aac5..c81cb2304 100644 --- a/stack/btm/btm_ble_bgconn.cc +++ b/stack/btm/btm_ble_bgconn.cc @@ -26,18 +26,18 @@ #include #include -#include "device/include/controller.h" -#include "osi/include/allocator.h" -#include "osi/include/osi.h" #include "bt_types.h" -#include "btu.h" +#include "bt_utils.h" #include "btm_int.h" -#include "l2c_int.h" +#include "btu.h" +#include "device/include/controller.h" #include "hcimsgs.h" -#include "bt_utils.h" +#include "l2c_int.h" +#include "osi/include/allocator.h" +#include "osi/include/osi.h" #ifndef BTM_BLE_SCAN_PARAM_TOUT -#define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */ +#define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */ #endif static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state); @@ -53,40 +53,38 @@ typedef struct background_connection_t { } background_connection_t; struct KeyEqual { - bool operator()(const bt_bdaddr_t *x, const bt_bdaddr_t *y) const - { + bool operator()(const bt_bdaddr_t* x, const bt_bdaddr_t* y) const { return bdaddr_equals(x, y); } }; -static std::unordered_map, KeyEqual> +static std::unordered_map, KeyEqual> background_connections; -static void background_connection_add(bt_bdaddr_t *address) { +static void background_connection_add(bt_bdaddr_t* address) { assert(address); auto map_iter = background_connections.find(address); if (map_iter == background_connections.end()) { - background_connection_t *connection = - (background_connection_t *)osi_calloc(sizeof(background_connection_t)); + background_connection_t* connection = + (background_connection_t*)osi_calloc(sizeof(background_connection_t)); connection->address = *address; background_connections[&(connection->address)] = connection; } } -static void background_connection_remove(bt_bdaddr_t *address) { +static void background_connection_remove(bt_bdaddr_t* address) { background_connections.erase(address); } -static void background_connections_clear() { - background_connections.clear(); -} +static void background_connections_clear() { background_connections.clear(); } static bool background_connections_pending() { - for (const auto &map_el : background_connections) { - background_connection_t *connection = map_el.second; - const bool connected = BTM_IsAclConnectionUp(connection->address.address, BT_TRANSPORT_LE); + for (const auto& map_el : background_connections) { + background_connection_t* connection = map_el.second; + const bool connected = + BTM_IsAclConnectionUp(connection->address.address, BT_TRANSPORT_LE); if (!connected) { return true; } @@ -100,31 +98,30 @@ static bool background_connections_pending() { * * Description This function updates the filter policy of scanner ******************************************************************************/ -void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) -{ - tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; - - uint32_t scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; - uint32_t scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; - - BTM_TRACE_EVENT ("%s", __func__); - - p_inq->sfp = scan_policy; - p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE ? BTM_BLE_SCAN_MODE_ACTI : p_inq->scan_type; - - if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) - { - btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (uint16_t)scan_interval, - (uint16_t)scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - scan_policy); - } - else - { - btm_ble_send_extended_scan_params(p_inq->scan_type, scan_interval, scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - scan_policy); - } +void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) { + tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var; + + uint32_t scan_interval = + !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; + uint32_t scan_window = + !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; + + BTM_TRACE_EVENT("%s", __func__); + + p_inq->sfp = scan_policy; + p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE + ? BTM_BLE_SCAN_MODE_ACTI + : p_inq->scan_type; + + if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { + btsnd_hcic_ble_set_scan_params( + p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, scan_policy); + } else { + btm_ble_send_extended_scan_params( + p_inq->scan_type, scan_interval, scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, scan_policy); + } } /******************************************************************************* * @@ -132,50 +129,55 @@ void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) * * Description This function load the device into controller white list ******************************************************************************/ -bool btm_add_dev_to_controller (bool to_add, BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - bool started = false; - BD_ADDR dummy_bda = {0}; - - if (p_dev_rec != NULL && p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) { - if (to_add) { - if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) { - btsnd_hcic_ble_add_white_list(p_dev_rec->ble.ble_addr_type, bd_addr); - started = true; - p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT; - } else if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0 && - memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0) { - btsnd_hcic_ble_add_white_list(p_dev_rec->ble.static_addr_type, - p_dev_rec->ble.static_addr); - started = true; - p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT; - } - } else { - if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) { - btsnd_hcic_ble_remove_from_white_list(p_dev_rec->ble.ble_addr_type, bd_addr); - started = true; - } - - if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0 && - memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0) { - btsnd_hcic_ble_remove_from_white_list(p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr); - started = true; - } - - p_dev_rec->ble.in_controller_list &= ~BTM_WHITE_LIST_BIT; - } +bool btm_add_dev_to_controller(bool to_add, BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + bool started = false; + BD_ADDR dummy_bda = {0}; + + if (p_dev_rec != NULL && p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) { + if (to_add) { + if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || + !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) { + btsnd_hcic_ble_add_white_list(p_dev_rec->ble.ble_addr_type, bd_addr); + started = true; + p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT; + } else if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != + 0 && + memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != + 0) { + btsnd_hcic_ble_add_white_list(p_dev_rec->ble.static_addr_type, + p_dev_rec->ble.static_addr); + started = true; + p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT; + } } else { - /* not a known device, i.e. attempt to connect to device never seen before */ - uint8_t addr_type = BTM_IS_PUBLIC_BDA(bd_addr) ? BLE_ADDR_PUBLIC : BLE_ADDR_RANDOM; - btsnd_hcic_ble_remove_from_white_list(addr_type, bd_addr); + if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || + !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) { + btsnd_hcic_ble_remove_from_white_list(p_dev_rec->ble.ble_addr_type, + bd_addr); started = true; - if (to_add) - btsnd_hcic_ble_add_white_list(addr_type, bd_addr); - } + } - return started; + if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0 && + memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0) { + btsnd_hcic_ble_remove_from_white_list(p_dev_rec->ble.static_addr_type, + p_dev_rec->ble.static_addr); + started = true; + } + p_dev_rec->ble.in_controller_list &= ~BTM_WHITE_LIST_BIT; + } + } else { + /* not a known device, i.e. attempt to connect to device never seen before + */ + uint8_t addr_type = + BTM_IS_PUBLIC_BDA(bd_addr) ? BLE_ADDR_PUBLIC : BLE_ADDR_RANDOM; + btsnd_hcic_ble_remove_from_white_list(addr_type, bd_addr); + started = true; + if (to_add) btsnd_hcic_ble_add_white_list(addr_type, bd_addr); + } + + return started; } /******************************************************************************* * @@ -184,23 +186,19 @@ bool btm_add_dev_to_controller (bool to_add, BD_ADDR bd_addr) * Description execute the pending whitelist device operation (loading or * removing) ******************************************************************************/ -bool btm_execute_wl_dev_operation(void) -{ - tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; - uint8_t i = 0; - bool rt = true; - - for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i ++, p_dev_op ++) - { - if (p_dev_op->in_use) - { - rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr); - memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP)); - } - else - break; - } - return rt; +bool btm_execute_wl_dev_operation(void) { + tBTM_BLE_WL_OP* p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; + uint8_t i = 0; + bool rt = true; + + for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i++, p_dev_op++) { + if (p_dev_op->in_use) { + rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr); + memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP)); + } else + break; + } + return rt; } /******************************************************************************* * @@ -209,32 +207,25 @@ bool btm_execute_wl_dev_operation(void) * Description enqueue the pending whitelist device operation (loading or * removing). ******************************************************************************/ -void btm_enq_wl_dev_operation(bool to_add, BD_ADDR bd_addr) -{ - tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; - uint8_t i = 0; - - for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_dev_op ++) - { - if (p_dev_op->in_use && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) - { - p_dev_op->to_add = to_add; - return; - } - else if (!p_dev_op->in_use) - break; - } - if (i != BTM_BLE_MAX_BG_CONN_DEV_NUM) - { - p_dev_op->in_use = true; - p_dev_op->to_add = to_add; - memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN); - } - else - { - BTM_TRACE_ERROR("max pending WL operation reached, discard"); - } - return; +void btm_enq_wl_dev_operation(bool to_add, BD_ADDR bd_addr) { + tBTM_BLE_WL_OP* p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; + uint8_t i = 0; + + for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i++, p_dev_op++) { + if (p_dev_op->in_use && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) { + p_dev_op->to_add = to_add; + return; + } else if (!p_dev_op->in_use) + break; + } + if (i != BTM_BLE_MAX_BG_CONN_DEV_NUM) { + p_dev_op->in_use = true; + p_dev_op->to_add = to_add; + memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN); + } else { + BTM_TRACE_ERROR("max pending WL operation reached, discard"); + } + return; } /******************************************************************************* @@ -245,25 +236,23 @@ void btm_enq_wl_dev_operation(bool to_add, BD_ADDR bd_addr) * the white list. * ******************************************************************************/ -bool btm_update_dev_to_white_list(bool to_add, BD_ADDR bd_addr) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; +bool btm_update_dev_to_white_list(bool to_add, BD_ADDR bd_addr) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; - if (to_add && p_cb->white_list_avail_size == 0) - { - BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__); - return false; - } + if (to_add && p_cb->white_list_avail_size == 0) { + BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__); + return false; + } - if (to_add) - background_connection_add((bt_bdaddr_t*)bd_addr); - else - background_connection_remove((bt_bdaddr_t*)bd_addr); + if (to_add) + background_connection_add((bt_bdaddr_t*)bd_addr); + else + background_connection_remove((bt_bdaddr_t*)bd_addr); - btm_suspend_wl_activity(p_cb->wl_state); - btm_enq_wl_dev_operation(to_add, bd_addr); - btm_resume_wl_activity(p_cb->wl_state); - return true; + btm_suspend_wl_activity(p_cb->wl_state); + btm_enq_wl_dev_operation(to_add, bd_addr); + btm_resume_wl_activity(p_cb->wl_state); + return true; } /******************************************************************************* @@ -273,11 +262,10 @@ bool btm_update_dev_to_white_list(bool to_add, BD_ADDR bd_addr) * Description This function clears the white list. * ******************************************************************************/ -void btm_ble_clear_white_list (void) -{ - BTM_TRACE_EVENT ("btm_ble_clear_white_list"); - btsnd_hcic_ble_clear_white_list(); - background_connections_clear(); +void btm_ble_clear_white_list(void) { + BTM_TRACE_EVENT("btm_ble_clear_white_list"); + btsnd_hcic_ble_clear_white_list(); + background_connections_clear(); } /******************************************************************************* @@ -287,17 +275,17 @@ void btm_ble_clear_white_list (void) * Description Indicates white list cleared. * ******************************************************************************/ -void btm_ble_clear_white_list_complete(uint8_t *p_data, - UNUSED_ATTR uint16_t evt_len) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - uint8_t status; +void btm_ble_clear_white_list_complete(uint8_t* p_data, + UNUSED_ATTR uint16_t evt_len) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + uint8_t status; - BTM_TRACE_EVENT ("btm_ble_clear_white_list_complete"); - STREAM_TO_UINT8 (status, p_data); + BTM_TRACE_EVENT("btm_ble_clear_white_list_complete"); + STREAM_TO_UINT8(status, p_data); - if (status == HCI_SUCCESS) - p_cb->white_list_avail_size = controller_get_interface()->get_ble_white_list_size(); + if (status == HCI_SUCCESS) + p_cb->white_list_avail_size = + controller_get_interface()->get_ble_white_list_size(); } /******************************************************************************* @@ -307,10 +295,9 @@ void btm_ble_clear_white_list_complete(uint8_t *p_data, * Description Initialize white list size * ******************************************************************************/ -void btm_ble_white_list_init(uint8_t white_list_size) -{ - BTM_TRACE_DEBUG("%s white_list_size = %d", __func__, white_list_size); - btm_cb.ble_ctr_cb.white_list_avail_size = white_list_size; +void btm_ble_white_list_init(uint8_t white_list_size) { + BTM_TRACE_DEBUG("%s white_list_size = %d", __func__, white_list_size); + btm_cb.ble_ctr_cb.white_list_avail_size = white_list_size; } /******************************************************************************* @@ -320,11 +307,9 @@ void btm_ble_white_list_init(uint8_t white_list_size) * Description White list element added * ******************************************************************************/ -void btm_ble_add_2_white_list_complete(uint8_t status) -{ - BTM_TRACE_EVENT("%s status=%d", __func__, status); - if (status == HCI_SUCCESS) - --btm_cb.ble_ctr_cb.white_list_avail_size; +void btm_ble_add_2_white_list_complete(uint8_t status) { + BTM_TRACE_EVENT("%s status=%d", __func__, status); + if (status == HCI_SUCCESS) --btm_cb.ble_ctr_cb.white_list_avail_size; } /******************************************************************************* @@ -334,12 +319,10 @@ void btm_ble_add_2_white_list_complete(uint8_t status) * Description White list element removal complete * ******************************************************************************/ -void btm_ble_remove_from_white_list_complete(uint8_t *p, - UNUSED_ATTR uint16_t evt_len) -{ - BTM_TRACE_EVENT ("%s status=%d", __func__, *p); - if (*p == HCI_SUCCESS) - ++btm_cb.ble_ctr_cb.white_list_avail_size; +void btm_ble_remove_from_white_list_complete(uint8_t* p, + UNUSED_ATTR uint16_t evt_len) { + BTM_TRACE_EVENT("%s status=%d", __func__, *p); + if (*p == HCI_SUCCESS) ++btm_cb.ble_ctr_cb.white_list_avail_size; } /******************************************************************************* @@ -353,76 +336,69 @@ void btm_ble_remove_from_white_list_complete(uint8_t *p, * Returns void * ******************************************************************************/ -bool btm_ble_start_auto_conn(bool start) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - BD_ADDR dummy_bda = {0}; - bool exec = true; - uint16_t scan_int; - uint16_t scan_win; - uint8_t own_addr_type = p_cb->addr_mgnt_cb.own_addr_type; - uint8_t peer_addr_type = BLE_ADDR_PUBLIC; - - if (start) - { - if (p_cb->conn_state == BLE_CONN_IDLE && background_connections_pending() - && btm_ble_topology_check(BTM_BLE_STATE_INIT)) - { - p_cb->wl_state |= BTM_BLE_WL_INIT; - - btm_execute_wl_dev_operation(); +bool btm_ble_start_auto_conn(bool start) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + BD_ADDR dummy_bda = {0}; + bool exec = true; + uint16_t scan_int; + uint16_t scan_win; + uint8_t own_addr_type = p_cb->addr_mgnt_cb.own_addr_type; + uint8_t peer_addr_type = BLE_ADDR_PUBLIC; + + if (start) { + if (p_cb->conn_state == BLE_CONN_IDLE && background_connections_pending() && + btm_ble_topology_check(BTM_BLE_STATE_INIT)) { + p_cb->wl_state |= BTM_BLE_WL_INIT; + + btm_execute_wl_dev_operation(); #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT); + btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT); #endif - scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? - BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int; - scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? - BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win; + scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) + ? BTM_BLE_SCAN_SLOW_INT_1 + : p_cb->scan_int; + scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) + ? BTM_BLE_SCAN_SLOW_WIN_1 + : p_cb->scan_win; #if (BLE_PRIVACY_SPT == TRUE) - if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE - && controller_get_interface()->supports_ble_privacy()) - { - own_addr_type |= BLE_ADDR_TYPE_ID_BIT; - peer_addr_type |= BLE_ADDR_TYPE_ID_BIT; - } + if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE && + controller_get_interface()->supports_ble_privacy()) { + own_addr_type |= BLE_ADDR_TYPE_ID_BIT; + peer_addr_type |= BLE_ADDR_TYPE_ID_BIT; + } #endif - btsnd_hcic_ble_create_ll_conn(scan_int, /* uint16_t scan_int */ - scan_win, /* uint16_t scan_win */ - 0x01, /* uint8_t white_list */ - peer_addr_type, /* uint8_t addr_type_peer */ - dummy_bda, /* BD_ADDR bda_peer */ - own_addr_type, /* uint8_t addr_type_own */ - BTM_BLE_CONN_INT_MIN_DEF, /* uint16_t conn_int_min */ - BTM_BLE_CONN_INT_MAX_DEF, /* uint16_t conn_int_max */ - BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* uint16_t conn_latency */ - BTM_BLE_CONN_TIMEOUT_DEF, /* uint16_t conn_timeout */ - 0, /* uint16_t min_len */ - 0); /* uint16_t max_len */ - btm_ble_set_conn_st (BLE_BG_CONN); - } - else - { - exec = false; - } + btsnd_hcic_ble_create_ll_conn( + scan_int, /* uint16_t scan_int */ + scan_win, /* uint16_t scan_win */ + 0x01, /* uint8_t white_list */ + peer_addr_type, /* uint8_t addr_type_peer */ + dummy_bda, /* BD_ADDR bda_peer */ + own_addr_type, /* uint8_t addr_type_own */ + BTM_BLE_CONN_INT_MIN_DEF, /* uint16_t conn_int_min */ + BTM_BLE_CONN_INT_MAX_DEF, /* uint16_t conn_int_max */ + BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* uint16_t conn_latency */ + BTM_BLE_CONN_TIMEOUT_DEF, /* uint16_t conn_timeout */ + 0, /* uint16_t min_len */ + 0); /* uint16_t max_len */ + btm_ble_set_conn_st(BLE_BG_CONN); + } else { + exec = false; } - else - { - if (p_cb->conn_state == BLE_BG_CONN) - { - btsnd_hcic_ble_create_conn_cancel(); - btm_ble_set_conn_st (BLE_CONN_CANCEL); - p_cb->wl_state &= ~BTM_BLE_WL_INIT; - } - else - { - BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop", p_cb->conn_state); - exec = false; - } + } else { + if (p_cb->conn_state == BLE_BG_CONN) { + btsnd_hcic_ble_create_conn_cancel(); + btm_ble_set_conn_st(BLE_CONN_CANCEL); + p_cb->wl_state &= ~BTM_BLE_WL_INIT; + } else { + BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop", + p_cb->conn_state); + exec = false; } - return exec; + } + return exec; } /******************************************************************************* @@ -439,79 +415,71 @@ bool btm_ble_start_auto_conn(bool start) * Returns bool : selective connectino procedure is started. * ******************************************************************************/ -bool btm_ble_start_select_conn(bool start, tBTM_BLE_SEL_CBACK *p_select_cback) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - uint32_t scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; - uint32_t scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; - - BTM_TRACE_EVENT ("%s", __func__); - - if (start) - { - if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) - { - if (p_select_cback != NULL) - btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; - - btm_execute_wl_dev_operation(); - - btm_update_scanner_filter_policy(SP_ADV_WL); - btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS; - - /* Process advertising packets only from devices in the white list */ - if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) - { - /* use passive scan by default */ - btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, - scan_int, - scan_win, - p_cb->addr_mgnt_cb.own_addr_type, - SP_ADV_WL); - } - else - { - btm_ble_send_extended_scan_params(BTM_BLE_SCAN_MODE_PASS, - scan_int, - scan_win, - p_cb->addr_mgnt_cb.own_addr_type, - SP_ADV_WL); - } - - if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) - { - BTM_TRACE_ERROR("peripheral device cannot initiate passive scan for a selective connection"); - return false; - } - else if (background_connections_pending()) - { +bool btm_ble_start_select_conn(bool start, tBTM_BLE_SEL_CBACK* p_select_cback) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + uint32_t scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF + ? BTM_BLE_SCAN_FAST_INT + : p_cb->scan_int; + uint32_t scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF + ? BTM_BLE_SCAN_FAST_WIN + : p_cb->scan_win; + + BTM_TRACE_EVENT("%s", __func__); + + if (start) { + if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) { + if (p_select_cback != NULL) + btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; + + btm_execute_wl_dev_operation(); + + btm_update_scanner_filter_policy(SP_ADV_WL); + btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS; + + /* Process advertising packets only from devices in the white list */ + if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { + /* use passive scan by default */ + btsnd_hcic_ble_set_scan_params( + BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win, + p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL); + } else { + btm_ble_send_extended_scan_params( + BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win, + p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL); + } + + if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) { + BTM_TRACE_ERROR( + "peripheral device cannot initiate passive scan for a selective " + "connection"); + return false; + } else if (background_connections_pending()) { #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); + btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif - btsnd_hcic_ble_set_scan_enable(true, true); /* duplicate filtering enabled */ - - /* mark up inquiry status flag */ - p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE; - p_cb->wl_state |= BTM_BLE_WL_SCAN; - } - } - else - { - BTM_TRACE_ERROR("scan active, can not start selective connection procedure"); - return false; - } - } - else /* disable selective connection mode */ - { - p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE; - p_cb->p_select_cback = NULL; - p_cb->wl_state &= ~BTM_BLE_WL_SCAN; - - /* stop scanning */ - if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) - btm_ble_stop_scan(); /* duplicate filtering enabled */ + btsnd_hcic_ble_set_scan_enable(true, + true); /* duplicate filtering enabled */ + + /* mark up inquiry status flag */ + p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE; + p_cb->wl_state |= BTM_BLE_WL_SCAN; + } + } else { + BTM_TRACE_ERROR( + "scan active, can not start selective connection procedure"); + return false; } - return true; + } else /* disable selective connection mode */ + { + p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE; + p_cb->p_select_cback = NULL; + p_cb->wl_state &= ~BTM_BLE_WL_SCAN; + + /* stop scanning */ + if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) + btm_ble_stop_scan(); /* duplicate filtering enabled */ + } + return true; } /******************************************************************************* * @@ -527,15 +495,13 @@ bool btm_ble_start_select_conn(bool start, tBTM_BLE_SEL_CBACK *p_select_cb * Returns bool : selective connectino procedure is started. * ******************************************************************************/ -void btm_ble_initiate_select_conn(BD_ADDR bda) -{ - BTM_TRACE_EVENT ("btm_ble_initiate_select_conn"); - - /* use direct connection procedure to initiate connection */ - if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda)) - { - BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed"); - } +void btm_ble_initiate_select_conn(BD_ADDR bda) { + BTM_TRACE_EVENT("btm_ble_initiate_select_conn"); + + /* use direct connection procedure to initiate connection */ + if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda)) { + BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed"); + } } /******************************************************************************* * @@ -549,16 +515,15 @@ void btm_ble_initiate_select_conn(BD_ADDR bda) * Returns none. * ******************************************************************************/ -bool btm_ble_suspend_bg_conn(void) -{ - BTM_TRACE_EVENT ("%s", __func__); +bool btm_ble_suspend_bg_conn(void) { + BTM_TRACE_EVENT("%s", __func__); - if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) - return btm_ble_start_auto_conn(false); - else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) - return btm_ble_start_select_conn(false, NULL); + if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) + return btm_ble_start_auto_conn(false); + else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) + return btm_ble_start_select_conn(false, NULL); - return false; + return false; } /******************************************************************************* * @@ -569,21 +534,16 @@ bool btm_ble_suspend_bg_conn(void) * Returns none. * ******************************************************************************/ -static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state) -{ - if (wl_state & BTM_BLE_WL_INIT) - { - btm_ble_start_auto_conn(false); - } - if (wl_state & BTM_BLE_WL_SCAN) - { - btm_ble_start_select_conn(false, NULL); - } - if (wl_state & BTM_BLE_WL_ADV) - { - btm_ble_stop_adv(); - } - +static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state) { + if (wl_state & BTM_BLE_WL_INIT) { + btm_ble_start_auto_conn(false); + } + if (wl_state & BTM_BLE_WL_SCAN) { + btm_ble_start_select_conn(false, NULL); + } + if (wl_state & BTM_BLE_WL_ADV) { + btm_ble_stop_adv(); + } } /******************************************************************************* * @@ -594,15 +554,12 @@ static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state) * Returns none. * ******************************************************************************/ -static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state) -{ - btm_ble_resume_bg_conn(); - - if (wl_state & BTM_BLE_WL_ADV) - { - btm_ble_start_adv(); - } +static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state) { + btm_ble_resume_bg_conn(); + if (wl_state & BTM_BLE_WL_ADV) { + btm_ble_start_adv(); + } } /******************************************************************************* * @@ -616,21 +573,19 @@ static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state) * Returns none. * ******************************************************************************/ -bool btm_ble_resume_bg_conn(void) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - bool ret = false; - - if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE) - { - if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) - ret = btm_ble_start_auto_conn(true); - - if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE) - ret = btm_ble_start_select_conn(true, btm_cb.ble_ctr_cb.p_select_cback); - } +bool btm_ble_resume_bg_conn(void) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + bool ret = false; + + if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE) { + if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) + ret = btm_ble_start_auto_conn(true); - return ret; + if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE) + ret = btm_ble_start_select_conn(true, btm_cb.ble_ctr_cb.p_select_cback); + } + + return ret; } /******************************************************************************* * @@ -641,9 +596,8 @@ bool btm_ble_resume_bg_conn(void) * Returns connection state * ******************************************************************************/ -tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) -{ - return btm_cb.ble_ctr_cb.conn_state; +tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) { + return btm_cb.ble_ctr_cb.conn_state; } /******************************************************************************* * @@ -654,14 +608,13 @@ tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) * Returns None. * ******************************************************************************/ -void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st) -{ - btm_cb.ble_ctr_cb.conn_state = new_st; - - if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN) - btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT); - else - btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT); +void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st) { + btm_cb.ble_ctr_cb.conn_state = new_st; + + if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN) + btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT); + else + btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT); } /******************************************************************************* @@ -673,13 +626,13 @@ void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st) * Returns None. * ******************************************************************************/ -void btm_ble_enqueue_direct_conn_req(void *p_param) -{ - tBTM_BLE_CONN_REQ *p = (tBTM_BLE_CONN_REQ *)osi_malloc(sizeof(tBTM_BLE_CONN_REQ)); +void btm_ble_enqueue_direct_conn_req(void* p_param) { + tBTM_BLE_CONN_REQ* p = + (tBTM_BLE_CONN_REQ*)osi_malloc(sizeof(tBTM_BLE_CONN_REQ)); - p->p_param = p_param; + p->p_param = p_param; - fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p); + fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p); } /******************************************************************************* * @@ -690,27 +643,26 @@ void btm_ble_enqueue_direct_conn_req(void *p_param) * Returns None. * ******************************************************************************/ -void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda) -{ - if (fixed_queue_is_empty(btm_cb.ble_ctr_cb.conn_pending_q)) - return; - - list_t *list = fixed_queue_get_list(btm_cb.ble_ctr_cb.conn_pending_q); - for (const list_node_t *node = list_begin(list); node != list_end(list); - node = list_next(node)) { - tBTM_BLE_CONN_REQ *p_req = (tBTM_BLE_CONN_REQ *)list_node(node); - tL2C_LCB *p_lcb = (tL2C_LCB *)p_req->p_param; - if ((p_lcb == NULL) || (!p_lcb->in_use)) { - continue; - } - //If BD address matches - if (!memcmp (rem_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) { - fixed_queue_try_remove_from_queue(btm_cb.ble_ctr_cb.conn_pending_q, p_req); - l2cu_release_lcb((tL2C_LCB *)p_req->p_param); - osi_free((void *)p_req); - break; - } +void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda) { + if (fixed_queue_is_empty(btm_cb.ble_ctr_cb.conn_pending_q)) return; + + list_t* list = fixed_queue_get_list(btm_cb.ble_ctr_cb.conn_pending_q); + for (const list_node_t* node = list_begin(list); node != list_end(list); + node = list_next(node)) { + tBTM_BLE_CONN_REQ* p_req = (tBTM_BLE_CONN_REQ*)list_node(node); + tL2C_LCB* p_lcb = (tL2C_LCB*)p_req->p_param; + if ((p_lcb == NULL) || (!p_lcb->in_use)) { + continue; } + // If BD address matches + if (!memcmp(rem_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) { + fixed_queue_try_remove_from_queue(btm_cb.ble_ctr_cb.conn_pending_q, + p_req); + l2cu_release_lcb((tL2C_LCB*)p_req->p_param); + osi_free((void*)p_req); + break; + } + } } /******************************************************************************* * @@ -722,19 +674,18 @@ void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda) * Returns true if started, false otherwise * ******************************************************************************/ -bool btm_send_pending_direct_conn(void) -{ - tBTM_BLE_CONN_REQ *p_req; - bool rt = false; - - p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue(btm_cb.ble_ctr_cb.conn_pending_q); - if (p_req != NULL) { - tL2C_LCB *p_lcb = (tL2C_LCB *)(p_req->p_param); - /* Ignore entries that might have been released while queued. */ - if (p_lcb->in_use) - rt = l2cble_init_direct_conn(p_lcb); - osi_free(p_req); - } +bool btm_send_pending_direct_conn(void) { + tBTM_BLE_CONN_REQ* p_req; + bool rt = false; + + p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue( + btm_cb.ble_ctr_cb.conn_pending_q); + if (p_req != NULL) { + tL2C_LCB* p_lcb = (tL2C_LCB*)(p_req->p_param); + /* Ignore entries that might have been released while queued. */ + if (p_lcb->in_use) rt = l2cble_init_direct_conn(p_lcb); + osi_free(p_req); + } - return rt; + return rt; } diff --git a/stack/btm/btm_ble_cont_energy.cc b/stack/btm/btm_ble_cont_energy.cc index 476fcbd55..61c5327eb 100644 --- a/stack/btm/btm_ble_cont_energy.cc +++ b/stack/btm/btm_ble_cont_energy.cc @@ -20,12 +20,12 @@ #include "bt_target.h" #include "bt_types.h" -#include "hcimsgs.h" -#include "btu.h" -#include "btm_int.h" #include "bt_utils.h" -#include "hcidefs.h" #include "btm_ble_api.h" +#include "btm_int.h" +#include "btu.h" +#include "hcidefs.h" +#include "hcimsgs.h" tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb; @@ -40,33 +40,33 @@ tBTM_BLE_ENERGY_INFO_CB ble_energy_info_cb; * Returns void * ******************************************************************************/ -void btm_ble_cont_energy_cmpl_cback (tBTM_VSC_CMPL *p_params) -{ - uint8_t *p = p_params->p_param_buf; - uint16_t len = p_params->param_len; - uint8_t status = 0; - uint32_t total_tx_time = 0, total_rx_time = 0, total_idle_time = 0, total_energy_used = 0; +void btm_ble_cont_energy_cmpl_cback(tBTM_VSC_CMPL* p_params) { + uint8_t* p = p_params->p_param_buf; + uint16_t len = p_params->param_len; + uint8_t status = 0; + uint32_t total_tx_time = 0, total_rx_time = 0, total_idle_time = 0, + total_energy_used = 0; - if (len < 17) - { - BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback"); - return; - } + if (len < 17) { + BTM_TRACE_ERROR("wrong length for btm_ble_cont_energy_cmpl_cback"); + return; + } - STREAM_TO_UINT8(status, p); - STREAM_TO_UINT32(total_tx_time, p); - STREAM_TO_UINT32(total_rx_time, p); - STREAM_TO_UINT32(total_idle_time, p); - STREAM_TO_UINT32(total_energy_used, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT32(total_tx_time, p); + STREAM_TO_UINT32(total_rx_time, p); + STREAM_TO_UINT32(total_idle_time, p); + STREAM_TO_UINT32(total_energy_used, p); - BTM_TRACE_DEBUG("energy_info status=%d,tx_t=%ld, rx_t=%ld, ener_used=%ld, idle_t=%ld", - status, total_tx_time, total_rx_time, total_energy_used, total_idle_time); + BTM_TRACE_DEBUG( + "energy_info status=%d,tx_t=%ld, rx_t=%ld, ener_used=%ld, idle_t=%ld", + status, total_tx_time, total_rx_time, total_energy_used, total_idle_time); - if (NULL != ble_energy_info_cb.p_ener_cback) - ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time, total_idle_time, - total_energy_used, status); + if (NULL != ble_energy_info_cb.p_ener_cback) + ble_energy_info_cb.p_ener_cback(total_tx_time, total_rx_time, + total_idle_time, total_energy_used, status); - return; + return; } /******************************************************************************* @@ -80,22 +80,20 @@ void btm_ble_cont_energy_cmpl_cback (tBTM_VSC_CMPL *p_params) * Returns status * ******************************************************************************/ -tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback) -{ - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; +tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback) { + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); + BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb); - BTM_TRACE_EVENT("BTM_BleGetEnergyInfo"); + BTM_TRACE_EVENT("BTM_BleGetEnergyInfo"); - if (0 == cmn_ble_vsc_cb.energy_support) - { - BTM_TRACE_ERROR("Controller does not support get energy info"); - return BTM_ERR_PROCESSING; - } + if (0 == cmn_ble_vsc_cb.energy_support) { + BTM_TRACE_ERROR("Controller does not support get energy info"); + return BTM_ERR_PROCESSING; + } - ble_energy_info_cb.p_ener_cback = p_ener_cback; - BTM_VendorSpecificCommand(HCI_BLE_ENERGY_INFO_OCF, 0, NULL, - btm_ble_cont_energy_cmpl_cback); - return BTM_CMD_STARTED; + ble_energy_info_cb.p_ener_cback = p_ener_cback; + BTM_VendorSpecificCommand(HCI_BLE_ENERGY_INFO_OCF, 0, NULL, + btm_ble_cont_energy_cmpl_cback); + return BTM_CMD_STARTED; } diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc index e7d5cf331..d0bf44ea3 100644 --- a/stack/btm/btm_ble_gap.cc +++ b/stack/btm/btm_ble_gap.cc @@ -24,9 +24,9 @@ #define LOG_TAG "bt_btm_ble" -#include -#include #include +#include +#include #include "bt_types.h" #include "bt_utils.h" @@ -44,186 +44,280 @@ #include "l2c_int.h" #include "osi/include/log.h" -#define BTM_BLE_NAME_SHORT 0x01 -#define BTM_BLE_NAME_CMPL 0x02 +#define BTM_BLE_NAME_SHORT 0x01 +#define BTM_BLE_NAME_CMPL 0x02 -#define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff -#define BTM_BLE_POLICY_UNKNOWN 0xff +#define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff +#define BTM_BLE_POLICY_UNKNOWN 0xff -#define BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS (30 * 1000) -#define MIN_ADV_LENGTH 2 +#define BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS (30 * 1000) +#define MIN_ADV_LENGTH 2 #define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9 - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; #if (BLE_VND_INCLUDED == TRUE) -static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; +static tBTM_BLE_CTRL_FEATURES_CBACK* p_ctrl_le_feature_rd_cmpl_cback = NULL; #endif /******************************************************************************* * Local functions ******************************************************************************/ static void btm_ble_update_adv_flag(uint8_t flag); -static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, uint8_t evt_type, uint8_t *p); -static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, - BD_ADDR_PTR p_peer_addr_ptr, - tBLE_ADDR_TYPE *p_peer_addr_type, - tBLE_ADDR_TYPE *p_own_addr_type); +static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, + uint8_t evt_type, uint8_t* p); +static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB* p_cb, + BD_ADDR_PTR p_peer_addr_ptr, + tBLE_ADDR_TYPE* p_peer_addr_type, + tBLE_ADDR_TYPE* p_own_addr_type); static void btm_ble_stop_observe(void); -static void btm_ble_fast_adv_timer_timeout(void *data); +static void btm_ble_fast_adv_timer_timeout(void* data); static void btm_ble_start_slow_adv(void); -static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(void *data); -static void btm_ble_inquiry_timer_timeout(void *data); -static void btm_ble_observer_timer_timeout(void *data); +static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(void* data); +static void btm_ble_inquiry_timer_timeout(void* data); +static void btm_ble_observer_timer_timeout(void* data); - -#define BTM_BLE_INQ_RESULT 0x01 -#define BTM_BLE_OBS_RESULT 0x02 -#define BTM_BLE_SEL_CONN_RESULT 0x04 +#define BTM_BLE_INQ_RESULT 0x01 +#define BTM_BLE_OBS_RESULT 0x02 +#define BTM_BLE_SEL_CONN_RESULT 0x04 /* LE states combo bit to check */ const uint8_t btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = -{ - {/* single state support */ - {HCI_SUPP_LE_STATES_CONN_ADV_MASK, HCI_SUPP_LE_STATES_CONN_ADV_OFF}, /* conn_adv */ - {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* init */ - {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* master */ - {HCI_SUPP_LE_STATES_SLAVE_MASK, HCI_SUPP_LE_STATES_SLAVE_OFF}, /* slave */ - {0, 0}, /* todo: lo du dir adv, not covered ? */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF}, /* hi duty dir adv */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF}, /* active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_MASK, HCI_SUPP_LE_STATESSCAN_ADV_OFF} /* scanable adv */ - }, - { /* conn_adv =0 */ - {0, 0}, /* conn_adv */ - {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* init: 32 */ - {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* master: 35 */ - {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ - {0, 0}, /* lo du dir adv */ - {0, 0}, /* hi duty dir adv */ - {0, 0}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ - {0, 0} /* scanable adv */ - }, - { /* init */ - {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* conn_adv: 32 */ - {0, 0}, /* init */ - {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ - {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* slave 41 */ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* lo du dir adv 34 */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* hi duty dir adv 33 */ - {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF} /* scanable adv */ - - }, - { /* master */ - {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* conn_adv: 35 */ - {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* init 28 */ - {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ - {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* slave: 32 */ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* lo duty cycle adv 37 */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* hi duty cycle adv 36 */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF} /* scanable adv */ - - }, - { /* slave */ - {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* conn_adv: 38,*/ - {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* init 41 */ - {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* master 41 */ - {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* lo duty cycle adv 40 */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* hi duty cycle adv 39 */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF} /* scanable adv */ - - }, - { /* lo duty cycle adv */ - {0, 0}, /* conn_adv: 38,*/ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* init 34 */ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* master 37 */ - {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 40 */ - {0, 0}, /* lo duty cycle adv 40 */ - {0, 0}, /* hi duty cycle adv 39 */ - {0, 0}, /* non connectable adv */ - {0, 0}, /* TODO: passive scan, not covered? */ - {0, 0}, /* TODO: active scan, not covered? */ - {0, 0} /* scanable adv */ - }, - { /* hi duty cycle adv */ - {0, 0}, /* conn_adv: 38,*/ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* init 33 */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* master 36 */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 39*/ - {0, 0}, /* lo duty cycle adv 40 */ - {0, 0}, /* hi duty cycle adv 39 */ - {0, 0}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* active scan */ - {0, 0} /* scanable adv */ - }, - { /* non connectable adv */ - {0, 0}, /* conn_adv: */ - {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* init */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* master */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* slave: */ - {0, 0}, /* lo duty cycle adv */ - {0, 0}, /* hi duty cycle adv */ - {0, 0}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ - {0, 0} /* scanable adv */ - }, - { /* passive scan */ - {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* conn_adv: */ - {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* init */ - {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* master */ - {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* slave: */ - {0, 0}, /* lo duty cycle adv */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* hi duty cycle adv */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* non connectable adv */ - {0, 0}, /* passive scan */ - {0, 0}, /* active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF} /* scanable adv */ - }, - { /* active scan */ - {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* conn_adv: */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* init */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* master */ - {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* slave: */ - {0, 0}, /* lo duty cycle adv */ - {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* hi duty cycle adv */ - {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* non connectable adv */ - {0, 0}, /* TODO: passive scan */ - {0, 0}, /* TODO: active scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF} /* scanable adv */ - }, - { /* scanable adv */ - {0, 0}, /* conn_adv: */ - {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF}, /* init */ - {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF}, /* master */ - {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF}, /* slave: */ - {0, 0}, /* lo duty cycle adv */ - {0, 0}, /* hi duty cycle adv */ - {0, 0}, /* non connectable adv */ - {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF}, /* passive scan */ - {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ - {0, 0} /* scanable adv */ - } + {{ + /* single state support */ + {HCI_SUPP_LE_STATES_CONN_ADV_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_OFF}, /* conn_adv */ + {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* init */ + {HCI_SUPP_LE_STATES_INIT_MASK, + HCI_SUPP_LE_STATES_INIT_OFF}, /* master */ + {HCI_SUPP_LE_STATES_SLAVE_MASK, + HCI_SUPP_LE_STATES_SLAVE_OFF}, /* slave */ + {0, 0}, /* todo: lo du dir adv, not covered ? */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF}, /* hi duty dir adv */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF}, /* active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_MASK, + HCI_SUPP_LE_STATESSCAN_ADV_OFF} /* scanable adv */ + }, + { + /* conn_adv =0 */ + {0, 0}, /* conn_adv */ + {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* init: 32 */ + {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* master: 35 */ + {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ + {0, 0}, /* lo du dir adv */ + {0, 0}, /* hi duty dir adv */ + {0, 0}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ + {0, 0} /* scanable adv */ + }, + { + /* init */ + {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* conn_adv: 32 */ + {0, 0}, /* init */ + {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ + {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* slave 41 */ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF}, /* lo du dir adv 34 */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* hi duty dir adv 33 */ + {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, + HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF} /* scanable adv */ + + }, + { + /* master */ + {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* conn_adv: 35 */ + {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* init 28 */ + {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ + {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* slave: 32 */ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* lo duty cycle adv + 37 */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* hi duty cycle adv + 36 */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* non connectable adv + */ + {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF} /* scanable adv */ + + }, + { + /* slave */ + {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* conn_adv: 38,*/ + {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* init 41 */ + {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, + HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* master 41 */ + {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* lo duty cycle adv 40 + */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* hi duty cycle adv 39 + */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF} /* scanable adv */ + + }, + { + /* lo duty cycle adv */ + {0, 0}, /* conn_adv: 38,*/ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF}, /* init 34 */ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* master 37 */ + {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 40 */ + {0, 0}, /* lo duty cycle adv 40 */ + {0, 0}, /* hi duty cycle adv 39 */ + {0, 0}, /* non connectable adv */ + {0, 0}, /* TODO: passive scan, not covered? */ + {0, 0}, /* TODO: active scan, not covered? */ + {0, 0} /* scanable adv */ + }, + { + /* hi duty cycle adv */ + {0, 0}, /* conn_adv: 38,*/ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* init 33 */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* master 36 */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 39*/ + {0, 0}, /* lo duty cycle adv 40 */ + {0, 0}, /* hi duty cycle adv 39 */ + {0, 0}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* active scan */ + {0, 0} /* scanable adv */ + }, + { + /* non connectable adv */ + {0, 0}, /* conn_adv: */ + {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, + HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* init */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* master */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* slave: */ + {0, 0}, /* lo duty cycle adv */ + {0, 0}, /* hi duty cycle adv */ + {0, 0}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ + {0, 0} /* scanable adv */ + }, + { + /* passive scan */ + {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* conn_adv: */ + {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* init */ + {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* master */ + {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, + HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* slave: */ + {0, 0}, /* lo duty cycle adv */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* hi duty cycle + adv */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* non connectable + adv */ + {0, 0}, /* passive scan */ + {0, 0}, /* active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF} /* scanable adv */ + }, + { + /* active scan */ + {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* conn_adv: */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* init */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* master */ + {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, + HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* slave: */ + {0, 0}, /* lo duty cycle adv */ + {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* hi duty + cycle adv + */ + {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* non + connectable + adv */ + {0, 0}, /* TODO: passive scan */ + {0, 0}, /* TODO: active scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF} /* scanable adv */ + }, + { + /* scanable adv */ + {0, 0}, /* conn_adv: */ + {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF}, /* init */ + {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF}, /* master */ + {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF}, /* slave: */ + {0, 0}, /* lo duty cycle adv */ + {0, 0}, /* hi duty cycle adv */ + {0, 0}, /* non connectable adv */ + {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF}, /* passive scan */ + {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, + HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ + {0, 0} /* scanable adv */ + } }; /* check LE combo state supported */ -#define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y)) +#define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y)) /******************************************************************************* * @@ -235,44 +329,36 @@ const uint8_t btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = * * Return void ******************************************************************************/ -void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; - BD_ADDR p_addr_ptr= {0}; - uint8_t adv_mode = p_cb->adv_mode; - - BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy"); - - if (!controller_get_interface()->supports_ble()) - return; - - if (p_cb->afp != adv_policy) - { - p_cb->afp = adv_policy; - - /* if adv active, stop and restart */ - btm_ble_stop_adv (); - - if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) - p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, - &p_cb->adv_addr_type); - - btsnd_hcic_ble_write_adv_params((uint16_t)(p_cb->adv_interval_min ? p_cb->adv_interval_min : - BTM_BLE_GAP_ADV_SLOW_INT), - (uint16_t)(p_cb->adv_interval_max ? p_cb->adv_interval_max : - BTM_BLE_GAP_ADV_SLOW_INT), - p_cb->evt_type, - p_cb->adv_addr_type, - init_addr_type, - p_addr_ptr, - p_cb->adv_chnl_map, - p_cb->afp); - - if (adv_mode == BTM_BLE_ADV_ENABLE) - btm_ble_start_adv (); +void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; + BD_ADDR p_addr_ptr = {0}; + uint8_t adv_mode = p_cb->adv_mode; - } + BTM_TRACE_EVENT("BTM_BleUpdateAdvFilterPolicy"); + + if (!controller_get_interface()->supports_ble()) return; + + if (p_cb->afp != adv_policy) { + p_cb->afp = adv_policy; + + /* if adv active, stop and restart */ + btm_ble_stop_adv(); + + if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) + p_cb->evt_type = btm_set_conn_mode_adv_init_addr( + p_cb, p_addr_ptr, &init_addr_type, &p_cb->adv_addr_type); + + btsnd_hcic_ble_write_adv_params( + (uint16_t)(p_cb->adv_interval_min ? p_cb->adv_interval_min + : BTM_BLE_GAP_ADV_SLOW_INT), + (uint16_t)(p_cb->adv_interval_max ? p_cb->adv_interval_max + : BTM_BLE_GAP_ADV_SLOW_INT), + p_cb->evt_type, p_cb->adv_addr_type, init_addr_type, p_addr_ptr, + p_cb->adv_chnl_map, p_cb->afp); + + if (adv_mode == BTM_BLE_ADV_ENABLE) btm_ble_start_adv(); + } } /******************************************************************************* @@ -290,23 +376,23 @@ void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) * ******************************************************************************/ void btm_ble_send_extended_scan_params(uint8_t scan_type, uint32_t scan_int, - uint32_t scan_win, uint8_t addr_type_own, - uint8_t scan_filter_policy) -{ - uint8_t scan_param[HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM]; - uint8_t *pp_scan = scan_param; - - memset(scan_param, 0, HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM); - - UINT8_TO_STREAM(pp_scan, scan_type); - UINT32_TO_STREAM(pp_scan, scan_int); - UINT32_TO_STREAM(pp_scan, scan_win); - UINT8_TO_STREAM(pp_scan, addr_type_own); - UINT8_TO_STREAM(pp_scan, scan_filter_policy); - - BTM_TRACE_DEBUG("%s, %d, %d", __func__, scan_int, scan_win); - BTM_VendorSpecificCommand(HCI_BLE_EXTENDED_SCAN_PARAMS_OCF, - HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM, scan_param, NULL); + uint32_t scan_win, uint8_t addr_type_own, + uint8_t scan_filter_policy) { + uint8_t scan_param[HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM]; + uint8_t* pp_scan = scan_param; + + memset(scan_param, 0, HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM); + + UINT8_TO_STREAM(pp_scan, scan_type); + UINT32_TO_STREAM(pp_scan, scan_int); + UINT32_TO_STREAM(pp_scan, scan_win); + UINT8_TO_STREAM(pp_scan, addr_type_own); + UINT8_TO_STREAM(pp_scan, scan_filter_policy); + + BTM_TRACE_DEBUG("%s, %d, %d", __func__, scan_int, scan_win); + BTM_VendorSpecificCommand(HCI_BLE_EXTENDED_SCAN_PARAMS_OCF, + HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM, + scan_param, NULL); } /******************************************************************************* @@ -322,88 +408,78 @@ void btm_ble_send_extended_scan_params(uint8_t scan_type, uint32_t scan_int, * Returns void * ******************************************************************************/ -tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, - tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb) -{ - tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; - tBTM_STATUS status = BTM_WRONG_MODE; - - uint32_t scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; - uint32_t scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; - - BTM_TRACE_EVENT ("%s : scan_type:%d, %d, %d", __func__, btm_cb.btm_inq_vars.scan_type, - p_inq->scan_interval, p_inq->scan_window); - - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - if (start) - { - /* shared inquiry database, do not allow observe if any inquiry is active */ - if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - { - BTM_TRACE_ERROR("%s Observe Already Active", __func__); - return status; - } - - btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb; - btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb; - status = BTM_CMD_STARTED; - - /* scan is not started */ - if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - { - /* allow config of scan type */ - p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? - BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type; - /* assume observe always not using white list */ - #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == true) - /* enable resolving list */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); - #endif - - if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) - { - btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (uint16_t)scan_interval, - (uint16_t)scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - BTM_BLE_DEFAULT_SFP); - } - else - { - btm_ble_send_extended_scan_params(p_inq->scan_type, scan_interval, scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - BTM_BLE_DEFAULT_SFP); - } - - p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; - status = btm_ble_start_scan(); - } +tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, + tBTM_INQ_RESULTS_CB* p_results_cb, + tBTM_CMPL_CB* p_cmpl_cb) { + tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var; + tBTM_STATUS status = BTM_WRONG_MODE; + + uint32_t scan_interval = + !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; + uint32_t scan_window = + !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; + + BTM_TRACE_EVENT("%s : scan_type:%d, %d, %d", __func__, + btm_cb.btm_inq_vars.scan_type, p_inq->scan_interval, + p_inq->scan_window); + + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; + + if (start) { + /* shared inquiry database, do not allow observe if any inquiry is active */ + if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { + BTM_TRACE_ERROR("%s Observe Already Active", __func__); + return status; + } + + btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb; + btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb; + status = BTM_CMD_STARTED; + + /* scan is not started */ + if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { + /* allow config of scan type */ + p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) + ? BTM_BLE_SCAN_MODE_ACTI + : p_inq->scan_type; +/* assume observe always not using white list */ +#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == true) + /* enable resolving list */ + btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); +#endif - if (status == BTM_CMD_STARTED) - { - btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE; - if (duration != 0) { - /* start observer timer */ - period_ms_t duration_ms = duration * 1000; - alarm_set_on_queue(btm_cb.ble_ctr_cb.observer_timer, - duration_ms, btm_ble_observer_timer_timeout, - NULL, btu_general_alarm_queue); - } - } - } - else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - { - status = BTM_CMD_STARTED; - btm_ble_stop_observe(); - } - else - { - BTM_TRACE_ERROR("%s Observe not active", __func__); + if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { + btsnd_hcic_ble_set_scan_params( + p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, BTM_BLE_DEFAULT_SFP); + } else { + btm_ble_send_extended_scan_params( + p_inq->scan_type, scan_interval, scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, BTM_BLE_DEFAULT_SFP); + } + + p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; + status = btm_ble_start_scan(); + } + + if (status == BTM_CMD_STARTED) { + btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE; + if (duration != 0) { + /* start observer timer */ + period_ms_t duration_ms = duration * 1000; + alarm_set_on_queue(btm_cb.ble_ctr_cb.observer_timer, duration_ms, + btm_ble_observer_timer_timeout, NULL, + btu_general_alarm_queue); + } } + } else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { + status = BTM_CMD_STARTED; + btm_ble_stop_observe(); + } else { + BTM_TRACE_ERROR("%s Observe not active", __func__); + } - return status; - + return status; } #if (BLE_VND_INCLUDED == TRUE) @@ -416,74 +492,70 @@ tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, * Returns void * ******************************************************************************/ -static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_params) -{ - uint8_t status = 0xFF; - uint8_t *p; - - BTM_TRACE_DEBUG("%s", __func__); - - /* Check status of command complete event */ - if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) && - (p_vcs_cplt_params->param_len > 0)) - { - p = p_vcs_cplt_params->p_param_buf; - STREAM_TO_UINT8(status, p); - } +static void btm_ble_vendor_capability_vsc_cmpl_cback( + tBTM_VSC_CMPL* p_vcs_cplt_params) { + uint8_t status = 0xFF; + uint8_t* p; - if (status == HCI_SUCCESS) - { - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.adv_inst_max, p); - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.rpa_offloading, p); - STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg, p); - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, p); - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.filter_support, p); - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_filter, p); - STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.energy_support, p); - - if (p_vcs_cplt_params->param_len > BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE) - { - STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.version_supported, p); - } - else - { - btm_cb.cmn_ble_vsc_cb.version_supported = BTM_VSC_CHIP_CAPABILITY_L_VERSION; - } + BTM_TRACE_DEBUG("%s", __func__); - if (btm_cb.cmn_ble_vsc_cb.version_supported >= BTM_VSC_CHIP_CAPABILITY_M_VERSION) - { - STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p); - STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p); - STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p); - } - btm_cb.cmn_ble_vsc_cb.values_read = true; + /* Check status of command complete event */ + if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) && + (p_vcs_cplt_params->param_len > 0)) { + p = p_vcs_cplt_params->p_param_buf; + STREAM_TO_UINT8(status, p); + } + + if (status == HCI_SUCCESS) { + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.adv_inst_max, p); + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.rpa_offloading, p); + STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg, p); + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, p); + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.filter_support, p); + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_filter, p); + STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.energy_support, p); + + if (p_vcs_cplt_params->param_len > + BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE) { + STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.version_supported, p); + } else { + btm_cb.cmn_ble_vsc_cb.version_supported = + BTM_VSC_CHIP_CAPABILITY_L_VERSION; } - BTM_TRACE_DEBUG("%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d", - __func__, status, btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, - btm_cb.cmn_ble_vsc_cb.adv_inst_max, btm_cb.cmn_ble_vsc_cb.rpa_offloading, - btm_cb.cmn_ble_vsc_cb.energy_support, btm_cb.cmn_ble_vsc_cb.extended_scan_support); + if (btm_cb.cmn_ble_vsc_cb.version_supported >= + BTM_VSC_CHIP_CAPABILITY_M_VERSION) { + STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p); + STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p); + STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p); + } + btm_cb.cmn_ble_vsc_cb.values_read = true; + } - if (BTM_BleMaxMultiAdvInstanceCount() > 0) - btm_ble_multi_adv_init(); + BTM_TRACE_DEBUG( + "%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d", __func__, + status, btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, + btm_cb.cmn_ble_vsc_cb.adv_inst_max, btm_cb.cmn_ble_vsc_cb.rpa_offloading, + btm_cb.cmn_ble_vsc_cb.energy_support, + btm_cb.cmn_ble_vsc_cb.extended_scan_support); - if (btm_cb.cmn_ble_vsc_cb.max_filter > 0) - btm_ble_adv_filter_init(); + if (BTM_BleMaxMultiAdvInstanceCount() > 0) btm_ble_multi_adv_init(); + + if (btm_cb.cmn_ble_vsc_cb.max_filter > 0) btm_ble_adv_filter_init(); #if (BLE_PRIVACY_SPT == TRUE) - /* VS capability included and non-4.2 device */ - if (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz > 0 && - controller_get_interface()->get_ble_resolving_list_max_size() == 0) - btm_ble_resolving_list_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz); -#endif /* (BLE_PRIVACY_SPT == TRUE) */ + /* VS capability included and non-4.2 device */ + if (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz > 0 && + controller_get_interface()->get_ble_resolving_list_max_size() == 0) + btm_ble_resolving_list_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz); +#endif /* (BLE_PRIVACY_SPT == TRUE) */ - if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0) - btm_ble_batchscan_init(); + if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_init(); - if (p_ctrl_le_feature_rd_cmpl_cback != NULL) - p_ctrl_le_feature_rd_cmpl_cback(status); + if (p_ctrl_le_feature_rd_cmpl_cback != NULL) + p_ctrl_le_feature_rd_cmpl_cback(status); } -#endif /* (BLE_VND_INCLUDED == TRUE) */ +#endif /* (BLE_VND_INCLUDED == TRUE) */ /******************************************************************************* * @@ -496,14 +568,12 @@ static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_ * Returns void * ******************************************************************************/ -extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb) -{ - BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities"); +extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb) { + BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities"); - if (NULL != p_cmn_vsc_cb) - { - *p_cmn_vsc_cb = btm_cb.cmn_ble_vsc_cb; - } + if (NULL != p_cmn_vsc_cb) { + *p_cmn_vsc_cb = btm_cb.cmn_ble_vsc_cb; + } } /****************************************************************************** @@ -519,21 +589,19 @@ extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb) * ******************************************************************************/ #if (BLE_VND_INCLUDED == TRUE) -extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback) -{ - if (true == btm_cb.cmn_ble_vsc_cb.values_read) - return; +extern void BTM_BleReadControllerFeatures( + tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback) { + if (true == btm_cb.cmn_ble_vsc_cb.values_read) return; - BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures"); + BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures"); - p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback; - BTM_VendorSpecificCommand(HCI_BLE_VENDOR_CAP_OCF, 0, NULL, - btm_ble_vendor_capability_vsc_cmpl_cback); + p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback; + BTM_VendorSpecificCommand(HCI_BLE_VENDOR_CAP_OCF, 0, NULL, + btm_ble_vendor_capability_vsc_cmpl_cback); } #else -extern void BTM_BleReadControllerFeatures(UNUSED_ATTR tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback) -{ -} +extern void BTM_BleReadControllerFeatures( + UNUSED_ATTR tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback) {} #endif /******************************************************************************* @@ -548,13 +616,11 @@ extern void BTM_BleReadControllerFeatures(UNUSED_ATTR tBTM_BLE_CTRL_FEATURES_CBA * Returns void * ******************************************************************************/ -void BTM_BleEnableMixedPrivacyMode(bool mixed_on) -{ - +void BTM_BleEnableMixedPrivacyMode(bool mixed_on) { #if (BLE_PRIVACY_SPT == TRUE) - btm_cb.ble_ctr_cb.mixed_mode = mixed_on; + btm_cb.ble_ctr_cb.mixed_mode = mixed_on; - /* TODO: send VSC to enabled mixed mode */ +/* TODO: send VSC to enabled mixed mode */ #endif } @@ -570,45 +636,44 @@ void BTM_BleEnableMixedPrivacyMode(bool mixed_on) * Returns bool privacy mode set success; otherwise failed. * ******************************************************************************/ -bool BTM_BleConfigPrivacy(bool privacy_mode) -{ +bool BTM_BleConfigPrivacy(bool privacy_mode) { #if (BLE_PRIVACY_SPT == TRUE) - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - - BTM_TRACE_EVENT ("%s", __func__); - - /* if LE is not supported, return error */ - if (!controller_get_interface()->supports_ble()) - return false; - - uint8_t addr_resolution = 0; - if(!privacy_mode)/* if privacy disabled, always use public address */ - { - p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC; - p_cb->privacy_mode = BTM_PRIVACY_NONE; - } - else /* privacy is turned on*/ - { - /* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */ - p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; - btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); - - /* 4.2 controller only allow privacy 1.2 or mixed mode, resolvable private address in controller */ - if (controller_get_interface()->supports_ble_privacy()) - { - addr_resolution = 1; - /* check vendor specific capability */ - p_cb->privacy_mode = btm_cb.ble_ctr_cb.mixed_mode ? BTM_PRIVACY_MIXED : BTM_PRIVACY_1_2; - } - else /* 4.1/4.0 controller */ - p_cb->privacy_mode = BTM_PRIVACY_1_1; - } - - GAP_BleAttrDBUpdate (GATT_UUID_GAP_CENTRAL_ADDR_RESOL, (tGAP_BLE_ATTR_VALUE *)&addr_resolution); - - return true; + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + + BTM_TRACE_EVENT("%s", __func__); + + /* if LE is not supported, return error */ + if (!controller_get_interface()->supports_ble()) return false; + + uint8_t addr_resolution = 0; + if (!privacy_mode) /* if privacy disabled, always use public address */ + { + p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC; + p_cb->privacy_mode = BTM_PRIVACY_NONE; + } else /* privacy is turned on*/ + { + /* always set host random address, used when privacy 1.1 or priavcy 1.2 is + * disabled */ + p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; + btm_gen_resolvable_private_addr((void*)btm_gen_resolve_paddr_low); + + /* 4.2 controller only allow privacy 1.2 or mixed mode, resolvable private + * address in controller */ + if (controller_get_interface()->supports_ble_privacy()) { + addr_resolution = 1; + /* check vendor specific capability */ + p_cb->privacy_mode = + btm_cb.ble_ctr_cb.mixed_mode ? BTM_PRIVACY_MIXED : BTM_PRIVACY_1_2; + } else /* 4.1/4.0 controller */ + p_cb->privacy_mode = BTM_PRIVACY_1_1; + } + + GAP_BleAttrDBUpdate(GATT_UUID_GAP_CENTRAL_ADDR_RESOL, + (tGAP_BLE_ATTR_VALUE*)&addr_resolution); + + return true; #else - return false; + return false; #endif } @@ -622,10 +687,10 @@ bool BTM_BleConfigPrivacy(bool privacy_mode) * Returns Max multi adv instance count * ******************************************************************************/ -extern uint8_t BTM_BleMaxMultiAdvInstanceCount(void) -{ - return btm_cb.cmn_ble_vsc_cb.adv_inst_max < BTM_BLE_MULTI_ADV_MAX ? - btm_cb.cmn_ble_vsc_cb.adv_inst_max : BTM_BLE_MULTI_ADV_MAX; +extern uint8_t BTM_BleMaxMultiAdvInstanceCount(void) { + return btm_cb.cmn_ble_vsc_cb.adv_inst_max < BTM_BLE_MULTI_ADV_MAX + ? btm_cb.cmn_ble_vsc_cb.adv_inst_max + : BTM_BLE_MULTI_ADV_MAX; } #if (BLE_PRIVACY_SPT == TRUE) @@ -638,38 +703,35 @@ extern uint8_t BTM_BleMaxMultiAdvInstanceCount(void) * Returns void * ******************************************************************************/ -static void btm_ble_resolve_random_addr_on_adv(void * p_rec, void *p) -{ - tBTM_SEC_DEV_REC *match_rec = (tBTM_SEC_DEV_REC *) p_rec; - uint8_t addr_type = BLE_ADDR_RANDOM; - BD_ADDR bda; - uint8_t *pp = (uint8_t *)p + 1; - uint8_t evt_type; - - BTM_TRACE_EVENT ("btm_ble_resolve_random_addr_on_adv "); - - STREAM_TO_UINT8 (evt_type, pp); - STREAM_TO_UINT8 (addr_type, pp); - STREAM_TO_BDADDR (bda, pp); - - if (match_rec) - { - BTM_TRACE_DEBUG("Random match"); - match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; - memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); - - if (btm_ble_init_pseudo_addr(match_rec, bda)) - { - memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); - } else { - // Assign the original address to be the current report address - memcpy(bda, match_rec->ble.pseudo_addr, BD_ADDR_LEN); - } +static void btm_ble_resolve_random_addr_on_adv(void* p_rec, void* p) { + tBTM_SEC_DEV_REC* match_rec = (tBTM_SEC_DEV_REC*)p_rec; + uint8_t addr_type = BLE_ADDR_RANDOM; + BD_ADDR bda; + uint8_t* pp = (uint8_t*)p + 1; + uint8_t evt_type; + + BTM_TRACE_EVENT("btm_ble_resolve_random_addr_on_adv "); + + STREAM_TO_UINT8(evt_type, pp); + STREAM_TO_UINT8(addr_type, pp); + STREAM_TO_BDADDR(bda, pp); + + if (match_rec) { + BTM_TRACE_DEBUG("Random match"); + match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; + memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); + + if (btm_ble_init_pseudo_addr(match_rec, bda)) { + memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); + } else { + // Assign the original address to be the current report address + memcpy(bda, match_rec->ble.pseudo_addr, BD_ADDR_LEN); } + } - btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp); + btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp); - return; + return; } #endif @@ -682,12 +744,11 @@ static void btm_ble_resolve_random_addr_on_adv(void * p_rec, void *p) * Returns Return true if local privacy is enabled else false * ******************************************************************************/ -bool BTM_BleLocalPrivacyEnabled(void) -{ +bool BTM_BleLocalPrivacyEnabled(void) { #if (BLE_PRIVACY_SPT == TRUE) - return (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE); + return (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE); #else - return false; + return false; #endif } @@ -706,53 +767,44 @@ bool BTM_BleLocalPrivacyEnabled(void) * Returns void * ******************************************************************************/ -bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, - tBTM_BLE_SEL_CBACK *p_select_cback) -{ - bool started = true; - - BTM_TRACE_EVENT ("BTM_BleSetBgConnType "); - if (!controller_get_interface()->supports_ble()) - return false; - - if (btm_cb.ble_ctr_cb.bg_conn_type != bg_conn_type) - { - switch (bg_conn_type) - { - case BTM_BLE_CONN_AUTO: - btm_ble_start_auto_conn(true); - break; - - case BTM_BLE_CONN_SELECTIVE: - if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) - { - btm_ble_start_auto_conn(false); - } - btm_ble_start_select_conn(true, p_select_cback); - break; - - case BTM_BLE_CONN_NONE: - if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) - { - btm_ble_start_auto_conn(false); - } - else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) - { - btm_ble_start_select_conn(false, NULL); - } - started = true; - break; - - default: - BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type); - started = false; - break; +bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, + tBTM_BLE_SEL_CBACK* p_select_cback) { + bool started = true; + + BTM_TRACE_EVENT("BTM_BleSetBgConnType "); + if (!controller_get_interface()->supports_ble()) return false; + + if (btm_cb.ble_ctr_cb.bg_conn_type != bg_conn_type) { + switch (bg_conn_type) { + case BTM_BLE_CONN_AUTO: + btm_ble_start_auto_conn(true); + break; + + case BTM_BLE_CONN_SELECTIVE: + if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) { + btm_ble_start_auto_conn(false); + } + btm_ble_start_select_conn(true, p_select_cback); + break; + + case BTM_BLE_CONN_NONE: + if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) { + btm_ble_start_auto_conn(false); + } else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) { + btm_ble_start_select_conn(false, NULL); } + started = true; + break; - if (started) - btm_cb.ble_ctr_cb.bg_conn_type = bg_conn_type; + default: + BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type); + started = false; + break; } - return started; + + if (started) btm_cb.ble_ctr_cb.bg_conn_type = bg_conn_type; + } + return started; } /******************************************************************************* @@ -768,11 +820,10 @@ bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, * Returns void * ******************************************************************************/ -void BTM_BleClearBgConnDev(void) -{ - btm_ble_start_auto_conn(false); - btm_ble_clear_white_list(); - gatt_reset_bgdev_list(); +void BTM_BleClearBgConnDev(void) { + btm_ble_start_auto_conn(false); + btm_ble_clear_white_list(); + gatt_reset_bgdev_list(); } /******************************************************************************* @@ -781,7 +832,8 @@ void BTM_BleClearBgConnDev(void) * * Description This function is called to add or remove a device into/from * background connection procedure. The background connection -* procedure is decided by the background connection type, it can be +* procedure is decided by the background connection type, it +*can be * auto connection, or selective connection. * * Parameters add_remove: true to add; false to remove. @@ -790,10 +842,9 @@ void BTM_BleClearBgConnDev(void) * Returns void * ******************************************************************************/ -bool BTM_BleUpdateBgConnDev(bool add_remove, BD_ADDR remote_bda) -{ - BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove); - return btm_update_dev_to_white_list(add_remove, remote_bda); +bool BTM_BleUpdateBgConnDev(bool add_remove, BD_ADDR remote_bda) { + BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove); + return btm_update_dev_to_white_list(add_remove, remote_bda); } /******************************************************************************* @@ -812,27 +863,24 @@ bool BTM_BleUpdateBgConnDev(bool add_remove, BD_ADDR remote_bda) * BTM_SUCCESS is status set successfully; otherwise failure. * ******************************************************************************/ -tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; +tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; - BTM_TRACE_EVENT ("%s connectable_mode = %d ", __func__, connectable_mode); - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; + BTM_TRACE_EVENT("%s connectable_mode = %d ", __func__, connectable_mode); + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; - p_cb->directed_conn = connectable_mode; - return btm_ble_set_connectability( p_cb->connectable_mode); + p_cb->directed_conn = connectable_mode; + return btm_ble_set_connectability(p_cb->connectable_mode); } #if (BLE_PRIVACY_SPT == TRUE) -static bool is_resolving_list_bit_set(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); +static bool is_resolving_list_bit_set(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); - if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) - return false; + if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) + return false; - return true; + return true; } #endif @@ -845,88 +893,84 @@ static bool is_resolving_list_bit_set(void *data, void *context) * * ******************************************************************************/ -static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, - BD_ADDR_PTR p_peer_addr_ptr, - tBLE_ADDR_TYPE *p_peer_addr_type, - tBLE_ADDR_TYPE *p_own_addr_type) -{ - uint8_t evt_type; +static uint8_t btm_set_conn_mode_adv_init_addr( + tBTM_BLE_INQ_CB* p_cb, BD_ADDR_PTR p_peer_addr_ptr, + tBLE_ADDR_TYPE* p_peer_addr_type, tBLE_ADDR_TYPE* p_own_addr_type) { + uint8_t evt_type; #if (BLE_PRIVACY_SPT == TRUE) - tBTM_SEC_DEV_REC *p_dev_rec; + tBTM_SEC_DEV_REC* p_dev_rec; #endif - evt_type = (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE) ? \ - ((p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT )\ - : BTM_BLE_CONNECT_EVT; - - if (evt_type == BTM_BLE_CONNECT_EVT) - { - evt_type = p_cb->directed_conn; + evt_type = + (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE) + ? ((p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT) + : BTM_BLE_CONNECT_EVT; - if ( p_cb->directed_conn == BTM_BLE_CONNECT_DIR_EVT || - p_cb->directed_conn == BTM_BLE_CONNECT_LO_DUTY_DIR_EVT) - { + if (evt_type == BTM_BLE_CONNECT_EVT) { + evt_type = p_cb->directed_conn; + if (p_cb->directed_conn == BTM_BLE_CONNECT_DIR_EVT || + p_cb->directed_conn == BTM_BLE_CONNECT_LO_DUTY_DIR_EVT) { #if (BLE_PRIVACY_SPT == TRUE) - /* for privacy 1.2, convert peer address as static, own address set as ID addr */ - if (btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 || - btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) - { - /* only do so for bonded device */ - if ((p_dev_rec = btm_find_or_alloc_dev (p_cb->direct_bda.bda)) != NULL && - p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) - { - btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); - memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); - *p_peer_addr_type = p_dev_rec->ble.static_addr_type; - *p_own_addr_type = BLE_ADDR_RANDOM_ID; - return evt_type; - } - /* otherwise fall though as normal directed adv */ - else - { - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); - } - } -#endif - /* direct adv mode does not have privacy, if privacy is not enabled */ - *p_peer_addr_type = p_cb->direct_bda.type; - memcpy(p_peer_addr_ptr, p_cb->direct_bda.bda, BD_ADDR_LEN); - return evt_type; + /* for privacy 1.2, convert peer address as static, own address set as ID + * addr */ + if (btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 || + btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { + /* only do so for bonded device */ + if ((p_dev_rec = btm_find_or_alloc_dev(p_cb->direct_bda.bda)) != NULL && + p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { + btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); + memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); + *p_peer_addr_type = p_dev_rec->ble.static_addr_type; + *p_own_addr_type = BLE_ADDR_RANDOM_ID; + return evt_type; + } + /* otherwise fall though as normal directed adv */ + else { + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); } + } +#endif + /* direct adv mode does not have privacy, if privacy is not enabled */ + *p_peer_addr_type = p_cb->direct_bda.type; + memcpy(p_peer_addr_ptr, p_cb->direct_bda.bda, BD_ADDR_LEN); + return evt_type; } + } - /* undirect adv mode or non-connectable mode*/ +/* undirect adv mode or non-connectable mode*/ #if (BLE_PRIVACY_SPT == TRUE) - /* when privacy 1.2 privacy only mode is used, or mixed mode */ - if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && p_cb->afp != AP_SCAN_CONN_ALL) || - btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) - { - list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_resolving_list_bit_set, NULL); - if (n) { - /* if enhanced privacy is required, set Identity address and matching IRK peer */ - tBTM_SEC_DEV_REC *p_dev_rec = - static_cast(list_node(n)); - memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); - *p_peer_addr_type = p_dev_rec->ble.static_addr_type; - - *p_own_addr_type = BLE_ADDR_RANDOM_ID; - } else { - /* resolving list is empty, not enabled */ - *p_own_addr_type = BLE_ADDR_RANDOM; - } - } - /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable privacy in */ - /* controller fall back to host based privacy */ - else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) - { - *p_own_addr_type = BLE_ADDR_RANDOM; - } + /* when privacy 1.2 privacy only mode is used, or mixed mode */ + if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && + p_cb->afp != AP_SCAN_CONN_ALL) || + btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { + list_node_t* n = + list_foreach(btm_cb.sec_dev_rec, is_resolving_list_bit_set, NULL); + if (n) { + /* if enhanced privacy is required, set Identity address and matching IRK + * peer */ + tBTM_SEC_DEV_REC* p_dev_rec = + static_cast(list_node(n)); + memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); + *p_peer_addr_type = p_dev_rec->ble.static_addr_type; + + *p_own_addr_type = BLE_ADDR_RANDOM_ID; + } else { + /* resolving list is empty, not enabled */ + *p_own_addr_type = BLE_ADDR_RANDOM; + } + } + /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable + privacy in */ + /* controller fall back to host based privacy */ + else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { + *p_own_addr_type = BLE_ADDR_RANDOM; + } #endif - /* if no privacy,do not set any peer address,*/ - /* local address type go by global privacy setting */ - return evt_type; + /* if no privacy,do not set any peer address,*/ + /* local address type go by global privacy setting */ + return evt_type; } /******************************************************************************* @@ -944,58 +988,50 @@ static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, * ******************************************************************************/ tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, uint16_t adv_int_max, - tBLE_BD_ADDR *p_dir_bda, - tBTM_BLE_ADV_CHNL_MAP chnl_map) -{ - tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - tBTM_STATUS status = BTM_SUCCESS; - BD_ADDR p_addr_ptr = {0}; - tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; - tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; - uint8_t adv_mode = p_cb->adv_mode; - - BTM_TRACE_EVENT ("BTM_BleSetAdvParams"); - - if (!controller_get_interface()->supports_ble()) - return BTM_ILLEGAL_VALUE; - - if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || - !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) - { - return BTM_ILLEGAL_VALUE; - } + tBLE_BD_ADDR* p_dir_bda, + tBTM_BLE_ADV_CHNL_MAP chnl_map) { + tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + tBTM_STATUS status = BTM_SUCCESS; + BD_ADDR p_addr_ptr = {0}; + tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; + tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; + uint8_t adv_mode = p_cb->adv_mode; - p_cb->adv_interval_min = adv_int_min; - p_cb->adv_interval_max = adv_int_max; - p_cb->adv_chnl_map = chnl_map; + BTM_TRACE_EVENT("BTM_BleSetAdvParams"); - if (p_dir_bda) - { - memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); - } + if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; - BTM_TRACE_EVENT ("update params for an active adv"); + if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, + BTM_BLE_ADV_INT_MAX) || + !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, + BTM_BLE_ADV_INT_MAX)) { + return BTM_ILLEGAL_VALUE; + } - btm_ble_stop_adv(); + p_cb->adv_interval_min = adv_int_min; + p_cb->adv_interval_max = adv_int_max; + p_cb->adv_chnl_map = chnl_map; - p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, - &own_addr_type); + if (p_dir_bda) { + memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); + } - /* update adv params */ - btsnd_hcic_ble_write_adv_params (p_cb->adv_interval_min, - p_cb->adv_interval_max, - p_cb->evt_type, - own_addr_type, - init_addr_type, - p_addr_ptr, - p_cb->adv_chnl_map, - p_cb->afp); + BTM_TRACE_EVENT("update params for an active adv"); - if (adv_mode == BTM_BLE_ADV_ENABLE) - btm_ble_start_adv(); + btm_ble_stop_adv(); - return status; + p_cb->evt_type = btm_set_conn_mode_adv_init_addr( + p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); + + /* update adv params */ + btsnd_hcic_ble_write_adv_params( + p_cb->adv_interval_min, p_cb->adv_interval_max, p_cb->evt_type, + own_addr_type, init_addr_type, p_addr_ptr, p_cb->adv_chnl_map, p_cb->afp); + + if (adv_mode == BTM_BLE_ADV_ENABLE) btm_ble_start_adv(); + + return status; } /******************************************************************************* @@ -1013,51 +1049,47 @@ tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, uint16_t adv_int_max, * Returns void * ******************************************************************************/ -void BTM_BleSetScanParams(tGATT_IF client_if, uint32_t scan_interval, uint32_t scan_window, - tBLE_SCAN_MODE scan_mode, - tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - uint32_t max_scan_interval; - uint32_t max_scan_window; - - BTM_TRACE_EVENT ("%s", __func__); - if (!controller_get_interface()->supports_ble()) - return; - - /* If not supporting extended scan support, use the older range for checking */ - if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) - { - max_scan_interval = BTM_BLE_SCAN_INT_MAX; - max_scan_window = BTM_BLE_SCAN_WIN_MAX; - } - else - { - /* If supporting extended scan support, use the new extended range for checking */ - max_scan_interval = BTM_BLE_EXT_SCAN_INT_MAX; - max_scan_window = BTM_BLE_EXT_SCAN_WIN_MAX; - } - - if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, max_scan_interval) && - BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, max_scan_window) && - (scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS)) - { - p_cb->scan_type = scan_mode; - p_cb->scan_interval = scan_interval; - p_cb->scan_window = scan_window; - - if (scan_setup_status_cback != NULL) - scan_setup_status_cback(client_if, BTM_SUCCESS); - } - else - { - if (scan_setup_status_cback != NULL) - scan_setup_status_cback(client_if, BTM_ILLEGAL_VALUE); - - BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", - scan_interval, scan_window); - } - +void BTM_BleSetScanParams(tGATT_IF client_if, uint32_t scan_interval, + uint32_t scan_window, tBLE_SCAN_MODE scan_mode, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + uint32_t max_scan_interval; + uint32_t max_scan_window; + + BTM_TRACE_EVENT("%s", __func__); + if (!controller_get_interface()->supports_ble()) return; + + /* If not supporting extended scan support, use the older range for checking + */ + if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { + max_scan_interval = BTM_BLE_SCAN_INT_MAX; + max_scan_window = BTM_BLE_SCAN_WIN_MAX; + } else { + /* If supporting extended scan support, use the new extended range for + * checking */ + max_scan_interval = BTM_BLE_EXT_SCAN_INT_MAX; + max_scan_window = BTM_BLE_EXT_SCAN_WIN_MAX; + } + + if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, + max_scan_interval) && + BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, + max_scan_window) && + (scan_mode == BTM_BLE_SCAN_MODE_ACTI || + scan_mode == BTM_BLE_SCAN_MODE_PASS)) { + p_cb->scan_type = scan_mode; + p_cb->scan_interval = scan_interval; + p_cb->scan_window = scan_window; + + if (scan_setup_status_cback != NULL) + scan_setup_status_cback(client_if, BTM_SUCCESS); + } else { + if (scan_setup_status_cback != NULL) + scan_setup_status_cback(client_if, BTM_ILLEGAL_VALUE); + + BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", + scan_interval, scan_window); + } } /******************************************************************************* @@ -1072,22 +1104,21 @@ void BTM_BleSetScanParams(tGATT_IF client_if, uint32_t scan_interval, uint32_t s * ******************************************************************************/ void BTM_BleWriteScanRsp(uint8_t* data, uint8_t length, - tBTM_BLE_ADV_DATA_CMPL_CBACK *p_adv_data_cback) -{ - BTM_TRACE_EVENT ("%s: length: %d", __func__, length); - if (!controller_get_interface()->supports_ble()) { - p_adv_data_cback(BTM_ILLEGAL_VALUE); - return; - } + tBTM_BLE_ADV_DATA_CMPL_CBACK* p_adv_data_cback) { + BTM_TRACE_EVENT("%s: length: %d", __func__, length); + if (!controller_get_interface()->supports_ble()) { + p_adv_data_cback(BTM_ILLEGAL_VALUE); + return; + } - btsnd_hcic_ble_set_scan_rsp_data(length, data); + btsnd_hcic_ble_set_scan_rsp_data(length, data); - if (length != 0) - btm_cb.ble_ctr_cb.inq_var.scan_rsp = true; - else - btm_cb.ble_ctr_cb.inq_var.scan_rsp = false; + if (length != 0) + btm_cb.ble_ctr_cb.inq_var.scan_rsp = true; + else + btm_cb.ble_ctr_cb.inq_var.scan_rsp = false; - p_adv_data_cback(BTM_SUCCESS); + p_adv_data_cback(BTM_SUCCESS); } /******************************************************************************* @@ -1103,31 +1134,28 @@ void BTM_BleWriteScanRsp(uint8_t* data, uint8_t length, * Returns pointer of ADV data * ******************************************************************************/ -uint8_t *BTM_CheckAdvData( uint8_t *p_adv, uint8_t type, uint8_t *p_length) -{ - uint8_t *p = p_adv; - uint8_t length; - uint8_t adv_type; - BTM_TRACE_API("%s: type=0x%02x", __func__, type); +uint8_t* BTM_CheckAdvData(uint8_t* p_adv, uint8_t type, uint8_t* p_length) { + uint8_t* p = p_adv; + uint8_t length; + uint8_t adv_type; + BTM_TRACE_API("%s: type=0x%02x", __func__, type); - STREAM_TO_UINT8(length, p); + STREAM_TO_UINT8(length, p); - while ( length && (p - p_adv <= BTM_BLE_CACHE_ADV_DATA_MAX)) - { - STREAM_TO_UINT8(adv_type, p); + while (length && (p - p_adv <= BTM_BLE_CACHE_ADV_DATA_MAX)) { + STREAM_TO_UINT8(adv_type, p); - if ( adv_type == type ) - { - /* length doesn't include itself */ - *p_length = length - 1; /* minus the length of type */ - return p; - } - p += length - 1; /* skip the length of data */ - STREAM_TO_UINT8(length, p); + if (adv_type == type) { + /* length doesn't include itself */ + *p_length = length - 1; /* minus the length of type */ + return p; } + p += length - 1; /* skip the length of data */ + STREAM_TO_UINT8(length, p); + } - *p_length = 0; - return NULL; + *p_length = 0; + return NULL; } /******************************************************************************* @@ -1141,11 +1169,10 @@ uint8_t *BTM_CheckAdvData( uint8_t *p_adv, uint8_t type, uint8_t *p_length) * BTM_BLE_GENRAL_DISCOVERABLE * ******************************************************************************/ -uint16_t BTM_BleReadDiscoverability() -{ - BTM_TRACE_API("%s", __func__); +uint16_t BTM_BleReadDiscoverability() { + BTM_TRACE_API("%s", __func__); - return (btm_cb.ble_ctr_cb.inq_var.discoverable_mode); + return (btm_cb.ble_ctr_cb.inq_var.discoverable_mode); } /******************************************************************************* @@ -1158,11 +1185,10 @@ uint16_t BTM_BleReadDiscoverability() * Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE * ******************************************************************************/ -uint16_t BTM_BleReadConnectability() -{ - BTM_TRACE_API ("%s", __func__); +uint16_t BTM_BleReadConnectability() { + BTM_TRACE_API("%s", __func__); - return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); + return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); } /******************************************************************************* @@ -1174,39 +1200,36 @@ uint16_t BTM_BleReadConnectability() * Returns void * ******************************************************************************/ -void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB *p_cb, uint8_t evt_type, uint16_t *p_adv_int_min, uint16_t *p_adv_int_max) -{ - if (p_cb->adv_interval_min && p_cb->adv_interval_max) - { - *p_adv_int_min = p_cb->adv_interval_min; - *p_adv_int_max = p_cb->adv_interval_max; - } - else - { - switch (evt_type) - { - case BTM_BLE_CONNECT_EVT: - case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: - *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1; - break; +void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB* p_cb, uint8_t evt_type, + uint16_t* p_adv_int_min, + uint16_t* p_adv_int_max) { + if (p_cb->adv_interval_min && p_cb->adv_interval_max) { + *p_adv_int_min = p_cb->adv_interval_min; + *p_adv_int_max = p_cb->adv_interval_max; + } else { + switch (evt_type) { + case BTM_BLE_CONNECT_EVT: + case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: + *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1; + break; - case BTM_BLE_NON_CONNECT_EVT: - case BTM_BLE_DISCOVER_EVT: - *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_2; - break; + case BTM_BLE_NON_CONNECT_EVT: + case BTM_BLE_DISCOVER_EVT: + *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_2; + break; - /* connectable directed event */ - case BTM_BLE_CONNECT_DIR_EVT: - *p_adv_int_min = BTM_BLE_GAP_ADV_DIR_MIN_INT; - *p_adv_int_max = BTM_BLE_GAP_ADV_DIR_MAX_INT; - break; + /* connectable directed event */ + case BTM_BLE_CONNECT_DIR_EVT: + *p_adv_int_min = BTM_BLE_GAP_ADV_DIR_MIN_INT; + *p_adv_int_max = BTM_BLE_GAP_ADV_DIR_MAX_INT; + break; - default: - *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_SLOW_INT; - break; - } + default: + *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_SLOW_INT; + break; } - return; + } + return; } /******************************************************************************* @@ -1225,21 +1248,22 @@ void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB *p_cb, uint8_t evt_type, uint16 * Returns void * ******************************************************************************/ -void btm_ble_update_dmt_flag_bits(uint8_t *adv_flag_value, const uint16_t connect_mode, - const uint16_t disc_mode) -{ - /* BR/EDR non-discoverable , non-connectable */ - if ((disc_mode & BTM_DISCOVERABLE_MASK) == 0 && - (connect_mode & BTM_CONNECTABLE_MASK) == 0) - *adv_flag_value |= BTM_BLE_BREDR_NOT_SPT; - else - *adv_flag_value &= ~BTM_BLE_BREDR_NOT_SPT; - - /* if local controller support, mark both controller and host support in flag */ - if (controller_get_interface()->supports_simultaneous_le_bredr()) - *adv_flag_value |= (BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); - else - *adv_flag_value &= ~(BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); +void btm_ble_update_dmt_flag_bits(uint8_t* adv_flag_value, + const uint16_t connect_mode, + const uint16_t disc_mode) { + /* BR/EDR non-discoverable , non-connectable */ + if ((disc_mode & BTM_DISCOVERABLE_MASK) == 0 && + (connect_mode & BTM_CONNECTABLE_MASK) == 0) + *adv_flag_value |= BTM_BLE_BREDR_NOT_SPT; + else + *adv_flag_value &= ~BTM_BLE_BREDR_NOT_SPT; + + /* if local controller support, mark both controller and host support in flag + */ + if (controller_get_interface()->supports_simultaneous_le_bredr()) + *adv_flag_value |= (BTM_BLE_DMT_CONTROLLER_SPT | BTM_BLE_DMT_HOST_SPT); + else + *adv_flag_value &= ~(BTM_BLE_DMT_CONTROLLER_SPT | BTM_BLE_DMT_HOST_SPT); } /******************************************************************************* @@ -1254,37 +1278,30 @@ void btm_ble_update_dmt_flag_bits(uint8_t *adv_flag_value, const uint16_t connec * Returns void * ******************************************************************************/ -void btm_ble_set_adv_flag(uint16_t connect_mode, uint16_t disc_mode) -{ - uint8_t flag = 0, old_flag = 0; - tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; - - if (p_adv_data->p_flags != NULL) - flag = old_flag = *(p_adv_data->p_flags); - - btm_ble_update_dmt_flag_bits (&flag, connect_mode, disc_mode); - - LOG_DEBUG(LOG_TAG, "disc_mode %04x", disc_mode); - /* update discoverable flag */ - if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) - { - flag &= ~BTM_BLE_GEN_DISC_FLAG; - flag |= BTM_BLE_LIMIT_DISC_FLAG; - } - else if (disc_mode & BTM_BLE_GENERAL_DISCOVERABLE) - { - flag |= BTM_BLE_GEN_DISC_FLAG; - flag &= ~BTM_BLE_LIMIT_DISC_FLAG; - } - else /* remove all discoverable flags */ - { - flag &= ~(BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG); - } - - if (flag != old_flag) - { - btm_ble_update_adv_flag(flag); - } +void btm_ble_set_adv_flag(uint16_t connect_mode, uint16_t disc_mode) { + uint8_t flag = 0, old_flag = 0; + tBTM_BLE_LOCAL_ADV_DATA* p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; + + if (p_adv_data->p_flags != NULL) flag = old_flag = *(p_adv_data->p_flags); + + btm_ble_update_dmt_flag_bits(&flag, connect_mode, disc_mode); + + LOG_DEBUG(LOG_TAG, "disc_mode %04x", disc_mode); + /* update discoverable flag */ + if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) { + flag &= ~BTM_BLE_GEN_DISC_FLAG; + flag |= BTM_BLE_LIMIT_DISC_FLAG; + } else if (disc_mode & BTM_BLE_GENERAL_DISCOVERABLE) { + flag |= BTM_BLE_GEN_DISC_FLAG; + flag &= ~BTM_BLE_LIMIT_DISC_FLAG; + } else /* remove all discoverable flags */ + { + flag &= ~(BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_GEN_DISC_FLAG); + } + + if (flag != old_flag) { + btm_ble_update_adv_flag(flag); + } } /******************************************************************************* * @@ -1297,93 +1314,86 @@ void btm_ble_set_adv_flag(uint16_t connect_mode, uint16_t disc_mode) * Returns BTM_SUCCESS is status set successfully; otherwise failure. * ******************************************************************************/ -tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode) -{ - tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - uint16_t mode = (combined_mode & BTM_BLE_DISCOVERABLE_MASK); - uint8_t new_mode = BTM_BLE_ADV_ENABLE; - uint8_t evt_type; - tBTM_STATUS status = BTM_SUCCESS; - BD_ADDR p_addr_ptr= {0}; - tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, - own_addr_type = p_addr_cb->own_addr_type; - uint16_t adv_int_min, adv_int_max; +tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode) { + tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + uint16_t mode = (combined_mode & BTM_BLE_DISCOVERABLE_MASK); + uint8_t new_mode = BTM_BLE_ADV_ENABLE; + uint8_t evt_type; + tBTM_STATUS status = BTM_SUCCESS; + BD_ADDR p_addr_ptr = {0}; + tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, + own_addr_type = p_addr_cb->own_addr_type; + uint16_t adv_int_min, adv_int_max; - BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __func__, mode, combined_mode); + BTM_TRACE_EVENT("%s mode=0x%0x combined_mode=0x%x", __func__, mode, + combined_mode); - /*** Check mode parameter ***/ - if (mode > BTM_BLE_MAX_DISCOVERABLE) - return(BTM_ILLEGAL_VALUE); + /*** Check mode parameter ***/ + if (mode > BTM_BLE_MAX_DISCOVERABLE) return (BTM_ILLEGAL_VALUE); - p_cb->discoverable_mode = mode; + p_cb->discoverable_mode = mode; - evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); + evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, + &own_addr_type); - if (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE && mode == BTM_BLE_NON_DISCOVERABLE) - new_mode = BTM_BLE_ADV_DISABLE; + if (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE && + mode == BTM_BLE_NON_DISCOVERABLE) + new_mode = BTM_BLE_ADV_DISABLE; - btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); + btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); - alarm_cancel(p_cb->fast_adv_timer); + alarm_cancel(p_cb->fast_adv_timer); - /* update adv params if start advertising */ - BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type); + /* update adv params if start advertising */ + BTM_TRACE_EVENT("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, + p_cb->evt_type); - if (new_mode == BTM_BLE_ADV_ENABLE) - { - btm_ble_set_adv_flag (btm_cb.btm_inq_vars.connectable_mode, combined_mode); - - if (evt_type != p_cb->evt_type ||p_cb->adv_addr_type != own_addr_type - || !p_cb->fast_adv_on) - { - btm_ble_stop_adv(); - - /* update adv params */ - btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, - own_addr_type, init_addr_type, - p_addr_ptr, p_cb->adv_chnl_map, - p_cb->afp); - p_cb->evt_type = evt_type; - p_cb->adv_addr_type = own_addr_type; - } - } + if (new_mode == BTM_BLE_ADV_ENABLE) { + btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, combined_mode); - if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode) - { - if (new_mode == BTM_BLE_ADV_ENABLE) - status = btm_ble_start_adv(); - else - status = btm_ble_stop_adv(); - } + if (evt_type != p_cb->evt_type || p_cb->adv_addr_type != own_addr_type || + !p_cb->fast_adv_on) { + btm_ble_stop_adv(); - if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) - { - p_cb->fast_adv_on = true; - /* start initial GAP mode adv timer */ - alarm_set_on_queue(p_cb->fast_adv_timer, - BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, - btm_ble_fast_adv_timer_timeout, NULL, - btu_general_alarm_queue); + /* update adv params */ + btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, + own_addr_type, init_addr_type, p_addr_ptr, + p_cb->adv_chnl_map, p_cb->afp); + p_cb->evt_type = evt_type; + p_cb->adv_addr_type = own_addr_type; } + } + + if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode) { + if (new_mode == BTM_BLE_ADV_ENABLE) + status = btm_ble_start_adv(); else - { + status = btm_ble_stop_adv(); + } + + if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { + p_cb->fast_adv_on = true; + /* start initial GAP mode adv timer */ + alarm_set_on_queue(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, + btm_ble_fast_adv_timer_timeout, NULL, + btu_general_alarm_queue); + } else { #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); #endif - } + } - /* set up stop advertising timer */ - if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE) - { - BTM_TRACE_EVENT("start timer for limited disc mode duration=%d ms", - BTM_BLE_GAP_LIM_TIMEOUT_MS); - /* start Tgap(lim_timeout) */ - alarm_set_on_queue(p_cb->inquiry_timer, BTM_BLE_GAP_LIM_TIMEOUT_MS, - btm_ble_inquiry_timer_gap_limited_discovery_timeout, - NULL, btu_general_alarm_queue); - } - return status; + /* set up stop advertising timer */ + if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE) { + BTM_TRACE_EVENT("start timer for limited disc mode duration=%d ms", + BTM_BLE_GAP_LIM_TIMEOUT_MS); + /* start Tgap(lim_timeout) */ + alarm_set_on_queue(p_cb->inquiry_timer, BTM_BLE_GAP_LIM_TIMEOUT_MS, + btm_ble_inquiry_timer_gap_limited_discovery_timeout, + NULL, btu_general_alarm_queue); + } + return status; } /******************************************************************************* @@ -1397,78 +1407,71 @@ tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode) * Returns BTM_SUCCESS is status set successfully; otherwise failure. * ******************************************************************************/ -tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode) -{ - tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - uint16_t mode = (combined_mode & BTM_BLE_CONNECTABLE_MASK); - uint8_t new_mode = BTM_BLE_ADV_ENABLE; - uint8_t evt_type; - tBTM_STATUS status = BTM_SUCCESS; - BD_ADDR p_addr_ptr = {0}; - tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC, - own_addr_type = p_addr_cb->own_addr_type; - uint16_t adv_int_min, adv_int_max; - - BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __func__, mode, combined_mode); - - /*** Check mode parameter ***/ - if (mode > BTM_BLE_MAX_CONNECTABLE) - return(BTM_ILLEGAL_VALUE); - - p_cb->connectable_mode = mode; - - evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &peer_addr_type, &own_addr_type); - - if (mode == BTM_BLE_NON_CONNECTABLE && p_cb->discoverable_mode == BTM_BLE_NON_DISCOVERABLE) - new_mode = BTM_BLE_ADV_DISABLE; - - btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); - - alarm_cancel(p_cb->fast_adv_timer); - /* update adv params if needed */ +tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode) { + tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + uint16_t mode = (combined_mode & BTM_BLE_CONNECTABLE_MASK); + uint8_t new_mode = BTM_BLE_ADV_ENABLE; + uint8_t evt_type; + tBTM_STATUS status = BTM_SUCCESS; + BD_ADDR p_addr_ptr = {0}; + tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC, + own_addr_type = p_addr_cb->own_addr_type; + uint16_t adv_int_min, adv_int_max; + + BTM_TRACE_EVENT("%s mode=0x%0x combined_mode=0x%x", __func__, mode, + combined_mode); + + /*** Check mode parameter ***/ + if (mode > BTM_BLE_MAX_CONNECTABLE) return (BTM_ILLEGAL_VALUE); + + p_cb->connectable_mode = mode; + + evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &peer_addr_type, + &own_addr_type); + + if (mode == BTM_BLE_NON_CONNECTABLE && + p_cb->discoverable_mode == BTM_BLE_NON_DISCOVERABLE) + new_mode = BTM_BLE_ADV_DISABLE; + + btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); + + alarm_cancel(p_cb->fast_adv_timer); + /* update adv params if needed */ + if (new_mode == BTM_BLE_ADV_ENABLE) { + btm_ble_set_adv_flag(combined_mode, btm_cb.btm_inq_vars.discoverable_mode); + if (p_cb->evt_type != evt_type || + p_cb->adv_addr_type != p_addr_cb->own_addr_type || !p_cb->fast_adv_on) { + btm_ble_stop_adv(); + + btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, + own_addr_type, peer_addr_type, p_addr_ptr, + p_cb->adv_chnl_map, p_cb->afp); + p_cb->evt_type = evt_type; + p_cb->adv_addr_type = own_addr_type; + } + } + + /* update advertising mode */ + if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode) { if (new_mode == BTM_BLE_ADV_ENABLE) - { - btm_ble_set_adv_flag (combined_mode, btm_cb.btm_inq_vars.discoverable_mode); - if (p_cb->evt_type != evt_type || p_cb->adv_addr_type != p_addr_cb->own_addr_type - || !p_cb->fast_adv_on) - { - btm_ble_stop_adv(); - - btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, - own_addr_type, peer_addr_type, - p_addr_ptr, p_cb->adv_chnl_map, - p_cb->afp); - p_cb->evt_type = evt_type; - p_cb->adv_addr_type = own_addr_type; - } - } - - /* update advertising mode */ - if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode) - { - if (new_mode == BTM_BLE_ADV_ENABLE) - status = btm_ble_start_adv(); - else - status = btm_ble_stop_adv(); - } - - if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) - { - p_cb->fast_adv_on = true; - /* start initial GAP mode adv timer */ - alarm_set_on_queue(p_cb->fast_adv_timer, - BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, - btm_ble_fast_adv_timer_timeout, NULL, - btu_general_alarm_queue); - } + status = btm_ble_start_adv(); else - { + status = btm_ble_stop_adv(); + } + + if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { + p_cb->fast_adv_on = true; + /* start initial GAP mode adv timer */ + alarm_set_on_queue(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, + btm_ble_fast_adv_timer_timeout, NULL, + btu_general_alarm_queue); + } else { #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); #endif - } - return status; + } + return status; } /******************************************************************************* @@ -1492,66 +1495,65 @@ tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode) * BTM_BUSY - if an inquiry is already active * ******************************************************************************/ -tBTM_STATUS btm_ble_start_inquiry (uint8_t mode, uint8_t duration) -{ - tBTM_STATUS status = BTM_CMD_STARTED; - tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - BTM_TRACE_DEBUG("btm_ble_start_inquiry: mode = %02x inq_active = 0x%02x", mode, btm_cb.btm_inq_vars.inq_active); - - /* if selective connection is active, or inquiry is already active, reject it */ - if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity) || - BTM_BLE_IS_SEL_CONN_ACTIVE (p_ble_cb->scan_activity)) - { - BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry"); - return(BTM_BUSY); - } - - if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) - { - btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_ACTI, - BTM_BLE_LOW_LATENCY_SCAN_INT, - BTM_BLE_LOW_LATENCY_SCAN_WIN, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - SP_ADV_ALL); +tBTM_STATUS btm_ble_start_inquiry(uint8_t mode, uint8_t duration) { + tBTM_STATUS status = BTM_CMD_STARTED; + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + + BTM_TRACE_DEBUG("btm_ble_start_inquiry: mode = %02x inq_active = 0x%02x", + mode, btm_cb.btm_inq_vars.inq_active); + + /* if selective connection is active, or inquiry is already active, reject it + */ + if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity) || + BTM_BLE_IS_SEL_CONN_ACTIVE(p_ble_cb->scan_activity)) { + BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry"); + return (BTM_BUSY); + } + + if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) { + btsnd_hcic_ble_set_scan_params( + BTM_BLE_SCAN_MODE_ACTI, BTM_BLE_LOW_LATENCY_SCAN_INT, + BTM_BLE_LOW_LATENCY_SCAN_WIN, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, SP_ADV_ALL); #if (BLE_PRIVACY_SPT == TRUE) - /* enable IRK list */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); + /* enable IRK list */ + btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif - p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; - status = btm_ble_start_scan(); - } - else if ((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || - (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { - BTM_TRACE_DEBUG("%s, restart LE scan with low latency scan params", __func__); - btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); - btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_ACTI, - BTM_BLE_LOW_LATENCY_SCAN_INT, - BTM_BLE_LOW_LATENCY_SCAN_WIN, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - SP_ADV_ALL); - btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE); - } - - if (status == BTM_CMD_STARTED) - { - p_inq->inq_active |= mode; - p_ble_cb->scan_activity |= mode; - - BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", p_inq->inq_active); - - if (duration != 0) { - /* start inquiry timer */ - period_ms_t duration_ms = duration * 1000; - alarm_set_on_queue(p_ble_cb->inq_var.inquiry_timer, - duration_ms, btm_ble_inquiry_timer_timeout, - NULL, btu_general_alarm_queue); - } - } - - return status; - + p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; + status = btm_ble_start_scan(); + } else if ((p_ble_cb->inq_var.scan_interval != + BTM_BLE_LOW_LATENCY_SCAN_INT) || + (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { + BTM_TRACE_DEBUG("%s, restart LE scan with low latency scan params", + __func__); + btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_DISABLE, + BTM_BLE_DUPLICATE_ENABLE); + btsnd_hcic_ble_set_scan_params( + BTM_BLE_SCAN_MODE_ACTI, BTM_BLE_LOW_LATENCY_SCAN_INT, + BTM_BLE_LOW_LATENCY_SCAN_WIN, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, SP_ADV_ALL); + btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_ENABLE, + BTM_BLE_DUPLICATE_DISABLE); + } + + if (status == BTM_CMD_STARTED) { + p_inq->inq_active |= mode; + p_ble_cb->scan_activity |= mode; + + BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", + p_inq->inq_active); + + if (duration != 0) { + /* start inquiry timer */ + period_ms_t duration_ms = duration * 1000; + alarm_set_on_queue(p_ble_cb->inq_var.inquiry_timer, duration_ms, + btm_ble_inquiry_timer_timeout, NULL, + btu_general_alarm_queue); + } + } + + return status; } /******************************************************************************* @@ -1563,25 +1565,23 @@ tBTM_STATUS btm_ble_start_inquiry (uint8_t mode, uint8_t duration) * Returns void * ******************************************************************************/ -void btm_ble_read_remote_name_cmpl(bool status, BD_ADDR bda, uint16_t length, char *p_name) -{ - uint8_t hci_status = HCI_SUCCESS; - BD_NAME bd_name; - - memset(bd_name, 0, (BD_NAME_LEN + 1)); - if (length > BD_NAME_LEN) - { - length = BD_NAME_LEN; - } - memcpy((uint8_t*)bd_name, p_name, length); +void btm_ble_read_remote_name_cmpl(bool status, BD_ADDR bda, uint16_t length, + char* p_name) { + uint8_t hci_status = HCI_SUCCESS; + BD_NAME bd_name; - if ((!status) || (length==0)) - { - hci_status = HCI_ERR_HOST_TIMEOUT; - } + memset(bd_name, 0, (BD_NAME_LEN + 1)); + if (length > BD_NAME_LEN) { + length = BD_NAME_LEN; + } + memcpy((uint8_t*)bd_name, p_name, length); - btm_process_remote_name(bda, bd_name, length +1, hci_status); - btm_sec_rmt_name_request_complete (bda, (uint8_t *)p_name, hci_status); + if ((!status) || (length == 0)) { + hci_status = HCI_ERR_HOST_TIMEOUT; + } + + btm_process_remote_name(bda, bd_name, length + 1, hci_status); + btm_sec_rmt_name_request_complete(bda, (uint8_t*)p_name, hci_status); } /******************************************************************************* @@ -1596,39 +1596,34 @@ void btm_ble_read_remote_name_cmpl(bool status, BD_ADDR bda, uint16_t length, * Returns void * ******************************************************************************/ -tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - if (!controller_get_interface()->supports_ble()) - return BTM_ERR_PROCESSING; - - if (p_cur && - p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_ADV && - p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_DIR_ADV) - { - BTM_TRACE_DEBUG("name request to non-connectable device failed."); - return BTM_ERR_PROCESSING; - } +tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO* p_cur, + tBTM_CMPL_CB* p_cb) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; - /* read remote device name using GATT procedure */ - if (p_inq->remname_active) - return BTM_BUSY; + if (!controller_get_interface()->supports_ble()) return BTM_ERR_PROCESSING; - if (!GAP_BleReadPeerDevName(remote_bda, btm_ble_read_remote_name_cmpl)) - return BTM_BUSY; + if (p_cur && p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_ADV && + p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_DIR_ADV) { + BTM_TRACE_DEBUG("name request to non-connectable device failed."); + return BTM_ERR_PROCESSING; + } - p_inq->p_remname_cmpl_cb = p_cb; - p_inq->remname_active = true; + /* read remote device name using GATT procedure */ + if (p_inq->remname_active) return BTM_BUSY; - memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); + if (!GAP_BleReadPeerDevName(remote_bda, btm_ble_read_remote_name_cmpl)) + return BTM_BUSY; - alarm_set_on_queue(p_inq->remote_name_timer, - BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS, - btm_inq_remote_name_timer_timeout, NULL, - btu_general_alarm_queue); + p_inq->p_remname_cmpl_cb = p_cb; + p_inq->remname_active = true; + + memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); + + alarm_set_on_queue(p_inq->remote_name_timer, BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS, + btm_inq_remote_name_timer_timeout, NULL, + btu_general_alarm_queue); - return BTM_CMD_STARTED; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -1642,18 +1637,17 @@ tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, t * Returns void * ******************************************************************************/ -bool btm_ble_cancel_remote_name(BD_ADDR remote_bda) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - bool status; +bool btm_ble_cancel_remote_name(BD_ADDR remote_bda) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + bool status; - status = GAP_BleCancelReadPeerDevName(remote_bda); + status = GAP_BleCancelReadPeerDevName(remote_bda); - p_inq->remname_active = false; - memset(p_inq->remname_bda, 0, BD_ADDR_LEN); - alarm_cancel(p_inq->remote_name_timer); + p_inq->remname_active = false; + memset(p_inq->remname_bda, 0, BD_ADDR_LEN); + alarm_cancel(p_inq->remote_name_timer); - return status; + return status; } /******************************************************************************* @@ -1668,40 +1662,35 @@ bool btm_ble_cancel_remote_name(BD_ADDR remote_bda) * Returns void * ******************************************************************************/ -static void btm_ble_update_adv_flag(uint8_t flag) -{ - tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; - uint8_t *p; +static void btm_ble_update_adv_flag(uint8_t flag) { + tBTM_BLE_LOCAL_ADV_DATA* p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; + uint8_t* p; - BTM_TRACE_DEBUG ("btm_ble_update_adv_flag new=0x%x", flag); + BTM_TRACE_DEBUG("btm_ble_update_adv_flag new=0x%x", flag); - if (p_adv_data->p_flags != NULL) - { - BTM_TRACE_DEBUG ("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags); - *p_adv_data->p_flags = flag; - } - else /* no FLAGS in ADV data*/ - { - p = (p_adv_data->p_pad == NULL) ? p_adv_data->ad_data : p_adv_data->p_pad; - /* need 3 bytes space to stuff in the flags, if not */ - /* erase all written data, just for flags */ - if ((BTM_BLE_AD_DATA_LEN - (p - p_adv_data->ad_data)) < 3) - { - p = p_adv_data->p_pad = p_adv_data->ad_data; - memset(p_adv_data->ad_data, 0, BTM_BLE_AD_DATA_LEN); - } - - *p++ = 2; - *p++ = BTM_BLE_AD_TYPE_FLAG; - p_adv_data->p_flags = p; - *p++ = flag; - p_adv_data->p_pad = p; + if (p_adv_data->p_flags != NULL) { + BTM_TRACE_DEBUG("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags); + *p_adv_data->p_flags = flag; + } else /* no FLAGS in ADV data*/ + { + p = (p_adv_data->p_pad == NULL) ? p_adv_data->ad_data : p_adv_data->p_pad; + /* need 3 bytes space to stuff in the flags, if not */ + /* erase all written data, just for flags */ + if ((BTM_BLE_AD_DATA_LEN - (p - p_adv_data->ad_data)) < 3) { + p = p_adv_data->p_pad = p_adv_data->ad_data; + memset(p_adv_data->ad_data, 0, BTM_BLE_AD_DATA_LEN); } - btsnd_hcic_ble_set_adv_data((uint8_t)(p_adv_data->p_pad - p_adv_data->ad_data), - p_adv_data->ad_data); - p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; + *p++ = 2; + *p++ = BTM_BLE_AD_TYPE_FLAG; + p_adv_data->p_flags = p; + *p++ = flag; + p_adv_data->p_pad = p; + } + btsnd_hcic_ble_set_adv_data( + (uint8_t)(p_adv_data->p_pad - p_adv_data->ad_data), p_adv_data->ad_data); + p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; } /******************************************************************************* @@ -1713,40 +1702,37 @@ static void btm_ble_update_adv_flag(uint8_t flag) * Returns void * ******************************************************************************/ -void btm_ble_cache_adv_data(UNUSED_ATTR tBTM_INQ_RESULTS *p_cur, uint8_t data_len, - uint8_t *p, uint8_t evt_type) -{ - tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; - uint8_t *p_cache; - uint8_t length; - - /* cache adv report/scan response data */ - if (evt_type != BTM_BLE_SCAN_RSP_EVT) - { - p_le_inq_cb->adv_len = 0; - memset(p_le_inq_cb->adv_data_cache, 0, BTM_BLE_CACHE_ADV_DATA_MAX); - } - - if (data_len > 0) - { - p_cache = &p_le_inq_cb->adv_data_cache[p_le_inq_cb->adv_len]; - STREAM_TO_UINT8(length, p); - while ( length && ((p_le_inq_cb->adv_len + length + 1) <= BTM_BLE_CACHE_ADV_DATA_MAX)) - { - /* copy from the length byte & data into cache */ - memcpy(p_cache, p-1, length+1); - /* advance the cache pointer past data */ - p_cache += length+1; - /* increment cache length */ - p_le_inq_cb->adv_len += length+1; - /* skip the length of data */ - p += length; - STREAM_TO_UINT8(length, p); - } +void btm_ble_cache_adv_data(UNUSED_ATTR tBTM_INQ_RESULTS* p_cur, + uint8_t data_len, uint8_t* p, uint8_t evt_type) { + tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + uint8_t* p_cache; + uint8_t length; + + /* cache adv report/scan response data */ + if (evt_type != BTM_BLE_SCAN_RSP_EVT) { + p_le_inq_cb->adv_len = 0; + memset(p_le_inq_cb->adv_data_cache, 0, BTM_BLE_CACHE_ADV_DATA_MAX); + } + + if (data_len > 0) { + p_cache = &p_le_inq_cb->adv_data_cache[p_le_inq_cb->adv_len]; + STREAM_TO_UINT8(length, p); + while (length && ((p_le_inq_cb->adv_len + length + 1) <= + BTM_BLE_CACHE_ADV_DATA_MAX)) { + /* copy from the length byte & data into cache */ + memcpy(p_cache, p - 1, length + 1); + /* advance the cache pointer past data */ + p_cache += length + 1; + /* increment cache length */ + p_le_inq_cb->adv_len += length + 1; + /* skip the length of data */ + p += length; + STREAM_TO_UINT8(length, p); } + } - /* parse service UUID from adv packet and save it in inq db eir_uuid */ - /* TODO */ + /* parse service UUID from adv packet and save it in inq db eir_uuid */ + /* TODO */ } /******************************************************************************* @@ -1762,179 +1748,172 @@ void btm_ble_cache_adv_data(UNUSED_ATTR tBTM_INQ_RESULTS *p_cur, uint8_t data_le * ******************************************************************************/ uint8_t btm_ble_is_discoverable(BD_ADDR bda, uint8_t evt_type, - UNUSED_ATTR uint8_t *p) -{ - uint8_t *p_flag, flag = 0, rt = 0; - uint8_t data_len; - tBTM_INQ_PARMS *p_cond = &btm_cb.btm_inq_vars.inqparms; - tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; - - /* for observer, always "discoverable */ - if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - rt |= BTM_BLE_OBS_RESULT; - - if (BTM_BLE_IS_SEL_CONN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity) && - (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_CONNECT_DIR_EVT)) - rt |= BTM_BLE_SEL_CONN_RESULT; - - /* does not match filter condition */ - if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR && - memcmp(bda, p_cond->filter_cond.bdaddr_cond, BD_ADDR_LEN) != 0) - { - BTM_TRACE_DEBUG("BD ADDR does not meet filter condition"); - return rt; - } - - if (p_le_inq_cb->adv_len != 0) - { - p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, &data_len); - if (p_flag != NULL) - { - flag = * p_flag; - - if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) && - (flag & (BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG)) != 0) - { - BTM_TRACE_DEBUG("Find Generable Discoverable device"); - rt |= BTM_BLE_INQ_RESULT; - } - - else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY && - (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0) - { - BTM_TRACE_DEBUG("Find limited discoverable device"); - rt |= BTM_BLE_INQ_RESULT; - } - } - } + UNUSED_ATTR uint8_t* p) { + uint8_t *p_flag, flag = 0, rt = 0; + uint8_t data_len; + tBTM_INQ_PARMS* p_cond = &btm_cb.btm_inq_vars.inqparms; + tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + + /* for observer, always "discoverable */ + if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) + rt |= BTM_BLE_OBS_RESULT; + + if (BTM_BLE_IS_SEL_CONN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity) && + (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_CONNECT_DIR_EVT)) + rt |= BTM_BLE_SEL_CONN_RESULT; + + /* does not match filter condition */ + if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR && + memcmp(bda, p_cond->filter_cond.bdaddr_cond, BD_ADDR_LEN) != 0) { + BTM_TRACE_DEBUG("BD ADDR does not meet filter condition"); return rt; -} - -static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t *dev_class) -{ - dev_class[0] = 0; - - switch (appearance) - { - case BTM_BLE_APPEARANCE_GENERIC_PHONE: - dev_class[1] = BTM_COD_MAJOR_PHONE; - dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; - break; - case BTM_BLE_APPEARANCE_GENERIC_COMPUTER: - dev_class[1] = BTM_COD_MAJOR_COMPUTER; - dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; - break; - case BTM_BLE_APPEARANCE_GENERIC_REMOTE: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_REMOTE_CONTROL; - break; - case BTM_BLE_APPEARANCE_GENERIC_THERMOMETER: - case BTM_BLE_APPEARANCE_THERMOMETER_EAR: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_THERMOMETER; - break; - case BTM_BLE_APPEARANCE_GENERIC_HEART_RATE: - case BTM_BLE_APPEARANCE_HEART_RATE_BELT: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_HEART_PULSE_MONITOR; - break; - case BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE: - case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM: - case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_BLOOD_MONITOR; - break; - case BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER: - case BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP: - case BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_PULSE_OXIMETER; - break; - case BTM_BLE_APPEARANCE_GENERIC_GLUCOSE: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_GLUCOSE_METER; - break; - case BTM_BLE_APPEARANCE_GENERIC_WEIGHT: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_WEIGHING_SCALE; - break; - case BTM_BLE_APPEARANCE_GENERIC_WALKING: - case BTM_BLE_APPEARANCE_WALKING_IN_SHOE: - case BTM_BLE_APPEARANCE_WALKING_ON_SHOE: - case BTM_BLE_APPEARANCE_WALKING_ON_HIP: - dev_class[1] = BTM_COD_MAJOR_HEALTH; - dev_class[2] = BTM_COD_MINOR_STEP_COUNTER; - break; - case BTM_BLE_APPEARANCE_GENERIC_WATCH: - case BTM_BLE_APPEARANCE_SPORTS_WATCH: - dev_class[1] = BTM_COD_MAJOR_WEARABLE; - dev_class[2] = BTM_COD_MINOR_WRIST_WATCH; - break; - case BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES: - dev_class[1] = BTM_COD_MAJOR_WEARABLE; - dev_class[2] = BTM_COD_MINOR_GLASSES; - break; - case BTM_BLE_APPEARANCE_GENERIC_DISPLAY: - dev_class[1] = BTM_COD_MAJOR_IMAGING; - dev_class[2] = BTM_COD_MINOR_DISPLAY; - break; - case BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER: - dev_class[1] = BTM_COD_MAJOR_AUDIO; - dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; - break; - case BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER: - case BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER: - case BTM_BLE_APPEARANCE_GENERIC_HID: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; - break; - case BTM_BLE_APPEARANCE_HID_KEYBOARD: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_KEYBOARD; - break; - case BTM_BLE_APPEARANCE_HID_MOUSE: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_POINTING; - break; - case BTM_BLE_APPEARANCE_HID_JOYSTICK: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_JOYSTICK; - break; - case BTM_BLE_APPEARANCE_HID_GAMEPAD: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_GAMEPAD; - break; - case BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_DIGITIZING_TABLET; - break; - case BTM_BLE_APPEARANCE_HID_CARD_READER: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_CARD_READER; - break; - case BTM_BLE_APPEARANCE_HID_DIGITAL_PEN: - dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - dev_class[2] = BTM_COD_MINOR_DIGITAL_PAN; - break; - case BTM_BLE_APPEARANCE_UKNOWN: - case BTM_BLE_APPEARANCE_GENERIC_CLOCK: - case BTM_BLE_APPEARANCE_GENERIC_TAG: - case BTM_BLE_APPEARANCE_GENERIC_KEYRING: - case BTM_BLE_APPEARANCE_GENERIC_CYCLING: - case BTM_BLE_APPEARANCE_CYCLING_COMPUTER: - case BTM_BLE_APPEARANCE_CYCLING_SPEED: - case BTM_BLE_APPEARANCE_CYCLING_CADENCE: - case BTM_BLE_APPEARANCE_CYCLING_POWER: - case BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE: - case BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS: - case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION: - case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV: - case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD: - case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV: - default: - dev_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; - dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; - }; + } + + if (p_le_inq_cb->adv_len != 0) { + p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, + &data_len); + if (p_flag != NULL) { + flag = *p_flag; + + if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) && + (flag & (BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_GEN_DISC_FLAG)) != 0) { + BTM_TRACE_DEBUG("Find Generable Discoverable device"); + rt |= BTM_BLE_INQ_RESULT; + } + + else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY && + (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0) { + BTM_TRACE_DEBUG("Find limited discoverable device"); + rt |= BTM_BLE_INQ_RESULT; + } + } + } + return rt; +} + +static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t* dev_class) { + dev_class[0] = 0; + + switch (appearance) { + case BTM_BLE_APPEARANCE_GENERIC_PHONE: + dev_class[1] = BTM_COD_MAJOR_PHONE; + dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; + break; + case BTM_BLE_APPEARANCE_GENERIC_COMPUTER: + dev_class[1] = BTM_COD_MAJOR_COMPUTER; + dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; + break; + case BTM_BLE_APPEARANCE_GENERIC_REMOTE: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_REMOTE_CONTROL; + break; + case BTM_BLE_APPEARANCE_GENERIC_THERMOMETER: + case BTM_BLE_APPEARANCE_THERMOMETER_EAR: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_THERMOMETER; + break; + case BTM_BLE_APPEARANCE_GENERIC_HEART_RATE: + case BTM_BLE_APPEARANCE_HEART_RATE_BELT: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_HEART_PULSE_MONITOR; + break; + case BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE: + case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM: + case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_BLOOD_MONITOR; + break; + case BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER: + case BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP: + case BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_PULSE_OXIMETER; + break; + case BTM_BLE_APPEARANCE_GENERIC_GLUCOSE: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_GLUCOSE_METER; + break; + case BTM_BLE_APPEARANCE_GENERIC_WEIGHT: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_WEIGHING_SCALE; + break; + case BTM_BLE_APPEARANCE_GENERIC_WALKING: + case BTM_BLE_APPEARANCE_WALKING_IN_SHOE: + case BTM_BLE_APPEARANCE_WALKING_ON_SHOE: + case BTM_BLE_APPEARANCE_WALKING_ON_HIP: + dev_class[1] = BTM_COD_MAJOR_HEALTH; + dev_class[2] = BTM_COD_MINOR_STEP_COUNTER; + break; + case BTM_BLE_APPEARANCE_GENERIC_WATCH: + case BTM_BLE_APPEARANCE_SPORTS_WATCH: + dev_class[1] = BTM_COD_MAJOR_WEARABLE; + dev_class[2] = BTM_COD_MINOR_WRIST_WATCH; + break; + case BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES: + dev_class[1] = BTM_COD_MAJOR_WEARABLE; + dev_class[2] = BTM_COD_MINOR_GLASSES; + break; + case BTM_BLE_APPEARANCE_GENERIC_DISPLAY: + dev_class[1] = BTM_COD_MAJOR_IMAGING; + dev_class[2] = BTM_COD_MINOR_DISPLAY; + break; + case BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER: + dev_class[1] = BTM_COD_MAJOR_AUDIO; + dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; + break; + case BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER: + case BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER: + case BTM_BLE_APPEARANCE_GENERIC_HID: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; + break; + case BTM_BLE_APPEARANCE_HID_KEYBOARD: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_KEYBOARD; + break; + case BTM_BLE_APPEARANCE_HID_MOUSE: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_POINTING; + break; + case BTM_BLE_APPEARANCE_HID_JOYSTICK: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_JOYSTICK; + break; + case BTM_BLE_APPEARANCE_HID_GAMEPAD: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_GAMEPAD; + break; + case BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_DIGITIZING_TABLET; + break; + case BTM_BLE_APPEARANCE_HID_CARD_READER: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_CARD_READER; + break; + case BTM_BLE_APPEARANCE_HID_DIGITAL_PEN: + dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + dev_class[2] = BTM_COD_MINOR_DIGITAL_PAN; + break; + case BTM_BLE_APPEARANCE_UKNOWN: + case BTM_BLE_APPEARANCE_GENERIC_CLOCK: + case BTM_BLE_APPEARANCE_GENERIC_TAG: + case BTM_BLE_APPEARANCE_GENERIC_KEYRING: + case BTM_BLE_APPEARANCE_GENERIC_CYCLING: + case BTM_BLE_APPEARANCE_CYCLING_COMPUTER: + case BTM_BLE_APPEARANCE_CYCLING_SPEED: + case BTM_BLE_APPEARANCE_CYCLING_CADENCE: + case BTM_BLE_APPEARANCE_CYCLING_POWER: + case BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE: + case BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS: + case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION: + case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV: + case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD: + case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV: + default: + dev_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; + dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; + }; } /******************************************************************************* @@ -1948,115 +1927,107 @@ static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t *dev_class) * Returns void * ******************************************************************************/ -bool btm_ble_update_inq_result(tINQ_DB_ENT *p_i, uint8_t addr_type, uint8_t evt_type, uint8_t *p) -{ - bool to_report = true; - tBTM_INQ_RESULTS *p_cur = &p_i->inq_info.results; - uint8_t len; - uint8_t *p_flag; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - uint8_t data_len, rssi; - tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; - uint8_t *p1; - uint8_t *p_uuid16; - - STREAM_TO_UINT8 (data_len, p); - - if (data_len > BTM_BLE_ADV_DATA_LEN_MAX) - { - BTM_TRACE_WARNING("EIR data too long %d. discard", data_len); - return false; - } - btm_ble_cache_adv_data(p_cur, data_len, p, evt_type); - - p1 = (p + data_len); - STREAM_TO_UINT8 (rssi, p1); - - /* Save the info */ - p_cur->inq_result_type = BTM_INQ_RESULT_BLE; - p_cur->ble_addr_type = addr_type; - p_cur->rssi = rssi; - - /* active scan, always wait until get scan_rsp to report the result */ - if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && - (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT))) - { - BTM_TRACE_DEBUG("btm_ble_update_inq_result scan_rsp=false, to_report=false,\ - scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type); - p_i->scan_rsp = false; - to_report = false; - } - else - p_i->scan_rsp = true; - - if (p_i->inq_count != p_inq->inq_counter) - p_cur->device_type = BT_DEVICE_TYPE_BLE; - else - p_cur->device_type |= BT_DEVICE_TYPE_BLE; - - if (evt_type != BTM_BLE_SCAN_RSP_EVT) - p_cur->ble_evt_type = evt_type; - - p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ - - if (p_le_inq_cb->adv_len != 0) - { - p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, &len); - if (p_flag != NULL) - p_cur->flag = * p_flag; - } - - if (p_le_inq_cb->adv_len != 0) - { - /* Check to see the BLE device has the Appearance UUID in the advertising data. If it does - * then try to convert the appearance value to a class of device value Bluedroid can use. - * Otherwise fall back to trying to infer if it is a HID device based on the service class. - */ - p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_APPEARANCE, &len); - if (p_uuid16 && len == 2) - { - btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8), p_cur->dev_class); - } - else - { - p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_16SRV_CMPL, &len); - if (p_uuid16 != NULL) - { - uint8_t i; - for (i = 0; i + 2 <= len; i = i + 2) - { - /* if this BLE device support HID over LE, set HID Major in class of device */ - if ((p_uuid16[i] | (p_uuid16[i+1] << 8)) == UUID_SERVCLASS_LE_HID) - { - p_cur->dev_class[0] = 0; - p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; - p_cur->dev_class[2] = 0; - break; - } - } - } +bool btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type, + uint8_t evt_type, uint8_t* p) { + bool to_report = true; + tBTM_INQ_RESULTS* p_cur = &p_i->inq_info.results; + uint8_t len; + uint8_t* p_flag; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + uint8_t data_len, rssi; + tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + uint8_t* p1; + uint8_t* p_uuid16; + + STREAM_TO_UINT8(data_len, p); + + if (data_len > BTM_BLE_ADV_DATA_LEN_MAX) { + BTM_TRACE_WARNING("EIR data too long %d. discard", data_len); + return false; + } + btm_ble_cache_adv_data(p_cur, data_len, p, evt_type); + + p1 = (p + data_len); + STREAM_TO_UINT8(rssi, p1); + + /* Save the info */ + p_cur->inq_result_type = BTM_INQ_RESULT_BLE; + p_cur->ble_addr_type = addr_type; + p_cur->rssi = rssi; + + /* active scan, always wait until get scan_rsp to report the result */ + if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && + (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT))) { + BTM_TRACE_DEBUG( + "btm_ble_update_inq_result scan_rsp=false, to_report=false,\ + scan_type_active=%d", + btm_cb.ble_ctr_cb.inq_var.scan_type); + p_i->scan_rsp = false; + to_report = false; + } else + p_i->scan_rsp = true; + + if (p_i->inq_count != p_inq->inq_counter) + p_cur->device_type = BT_DEVICE_TYPE_BLE; + else + p_cur->device_type |= BT_DEVICE_TYPE_BLE; + + if (evt_type != BTM_BLE_SCAN_RSP_EVT) p_cur->ble_evt_type = evt_type; + + p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ + + if (p_le_inq_cb->adv_len != 0) { + p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, + &len); + if (p_flag != NULL) p_cur->flag = *p_flag; + } + + if (p_le_inq_cb->adv_len != 0) { + /* Check to see the BLE device has the Appearance UUID in the advertising + * data. If it does + * then try to convert the appearance value to a class of device value + * Bluedroid can use. + * Otherwise fall back to trying to infer if it is a HID device based on the + * service class. + */ + p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, + BTM_BLE_AD_TYPE_APPEARANCE, &len); + if (p_uuid16 && len == 2) { + btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8), + p_cur->dev_class); + } else { + p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, + BTM_BLE_AD_TYPE_16SRV_CMPL, &len); + if (p_uuid16 != NULL) { + uint8_t i; + for (i = 0; i + 2 <= len; i = i + 2) { + /* if this BLE device support HID over LE, set HID Major in class of + * device */ + if ((p_uuid16[i] | (p_uuid16[i + 1] << 8)) == UUID_SERVCLASS_LE_HID) { + p_cur->dev_class[0] = 0; + p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; + p_cur->dev_class[2] = 0; + break; + } } + } } + } - /* if BR/EDR not supported is not set, assume is a DUMO device */ - if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 && - evt_type != BTM_BLE_CONNECT_DIR_EVT) - { - if (p_cur->ble_addr_type != BLE_ADDR_RANDOM) - { - BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO"); - p_cur->device_type |= BT_DEVICE_TYPE_DUMO; - } else { - BTM_TRACE_DEBUG("Random address, treating device as LE only"); - } + /* if BR/EDR not supported is not set, assume is a DUMO device */ + if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 && + evt_type != BTM_BLE_CONNECT_DIR_EVT) { + if (p_cur->ble_addr_type != BLE_ADDR_RANDOM) { + BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO"); + p_cur->device_type |= BT_DEVICE_TYPE_DUMO; + } else { + BTM_TRACE_DEBUG("Random address, treating device as LE only"); } - else - { - BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device"); - } - - return to_report; + } else { + BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device"); + } + return to_report; } /******************************************************************************* @@ -2069,19 +2040,18 @@ bool btm_ble_update_inq_result(tINQ_DB_ENT *p_i, uint8_t addr_type, uint8_t e * Returns void * ******************************************************************************/ -void btm_clear_all_pending_le_entry(void) -{ - uint16_t xx; - tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; - - for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) - { - /* mark all pending LE entry as unused if an LE only device has scan response outstanding */ - if ((p_ent->in_use) && - (p_ent->inq_info.results.device_type == BT_DEVICE_TYPE_BLE) && - !p_ent->scan_rsp) - p_ent->in_use = false; - } +void btm_clear_all_pending_le_entry(void) { + uint16_t xx; + tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; + + for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { + /* mark all pending LE entry as unused if an LE only device has scan + * response outstanding */ + if ((p_ent->in_use) && + (p_ent->inq_info.results.device_type == BT_DEVICE_TYPE_BLE) && + !p_ent->scan_rsp) + p_ent->in_use = false; + } } /******************************************************************************* @@ -2095,36 +2065,34 @@ void btm_clear_all_pending_le_entry(void) * Returns void * ******************************************************************************/ -void btm_send_sel_conn_callback(BD_ADDR remote_bda, uint8_t evt_type, uint8_t *p_data, - UNUSED_ATTR uint8_t addr_type) -{ - uint8_t data_len, len; - uint8_t *p_dev_name, remname[31] = {0}; - - if (btm_cb.ble_ctr_cb.p_select_cback == NULL || - /* non-connectable device */ - (evt_type != BTM_BLE_EVT_CONN_ADV && evt_type != BTM_BLE_EVT_CONN_DIR_ADV)) - return; +void btm_send_sel_conn_callback(BD_ADDR remote_bda, uint8_t evt_type, + uint8_t* p_data, + UNUSED_ATTR uint8_t addr_type) { + uint8_t data_len, len; + uint8_t *p_dev_name, remname[31] = {0}; + + if (btm_cb.ble_ctr_cb.p_select_cback == NULL || + /* non-connectable device */ + (evt_type != BTM_BLE_EVT_CONN_ADV && + evt_type != BTM_BLE_EVT_CONN_DIR_ADV)) + return; - STREAM_TO_UINT8 (data_len, p_data); + STREAM_TO_UINT8(data_len, p_data); - /* get the device name if exist in ADV data */ - if (data_len != 0) - { - p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_CMPL, &len); + /* get the device name if exist in ADV data */ + if (data_len != 0) { + p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_CMPL, &len); - if (p_dev_name == NULL) - p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_SHORT, &len); + if (p_dev_name == NULL) + p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_SHORT, &len); - if (p_dev_name) - memcpy(remname, p_dev_name, len); - } - /* allow connection */ - if ((* btm_cb.ble_ctr_cb.p_select_cback)(remote_bda, remname)) - { - /* terminate selective connection, initiate connection */ - btm_ble_initiate_select_conn(remote_bda); - } + if (p_dev_name) memcpy(remname, p_dev_name, len); + } + /* allow connection */ + if ((*btm_cb.ble_ctr_cb.p_select_cback)(remote_bda, remname)) { + /* terminate selective connection, initiate connection */ + btm_ble_initiate_select_conn(remote_bda); + } } /******************************************************************************* @@ -2141,51 +2109,47 @@ void btm_send_sel_conn_callback(BD_ADDR remote_bda, uint8_t evt_type, uint8_t *p * Returns void * ******************************************************************************/ -void btm_ble_process_adv_pkt (uint8_t *p_data) -{ - BD_ADDR bda; - uint8_t evt_type = 0, *p = p_data; - uint8_t addr_type = 0; - uint8_t num_reports; - uint8_t data_len; +void btm_ble_process_adv_pkt(uint8_t* p_data) { + BD_ADDR bda; + uint8_t evt_type = 0, *p = p_data; + uint8_t addr_type = 0; + uint8_t num_reports; + uint8_t data_len; #if (BLE_PRIVACY_SPT == TRUE) - bool match = false; + bool match = false; #endif - /* Only process the results if the inquiry is still active */ - if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - return; + /* Only process the results if the inquiry is still active */ + if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) return; - /* Extract the number of reports in this event. */ - STREAM_TO_UINT8(num_reports, p); + /* Extract the number of reports in this event. */ + STREAM_TO_UINT8(num_reports, p); - while (num_reports--) - { - /* Extract inquiry results */ - STREAM_TO_UINT8 (evt_type, p); - STREAM_TO_UINT8 (addr_type, p); - STREAM_TO_BDADDR (bda, p); + while (num_reports--) { + /* Extract inquiry results */ + STREAM_TO_UINT8(evt_type, p); + STREAM_TO_UINT8(addr_type, p); + STREAM_TO_BDADDR(bda, p); #if (BLE_PRIVACY_SPT == TRUE) - /* map address to security record */ - match = btm_identity_addr_to_random_pseudo(bda, &addr_type, false); - - BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x", - bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); - /* always do RRA resolution on host */ - if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) - { - btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_adv, p_data); - } - else + /* map address to security record */ + match = btm_identity_addr_to_random_pseudo(bda, &addr_type, false); + + BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + /* always do RRA resolution on host */ + if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) { + btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_adv, + p_data); + } else #endif - btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p); + btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p); - STREAM_TO_UINT8(data_len, p); + STREAM_TO_UINT8(data_len, p); - /* Advance to the next event data_len + rssi byte */ - p += data_len + 1; - } + /* Advance to the next event data_len + rssi byte */ + p += data_len + 1; + } } /******************************************************************************* @@ -2200,111 +2164,97 @@ void btm_ble_process_adv_pkt (uint8_t *p_data) * Returns void * ******************************************************************************/ -static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, uint8_t evt_type, uint8_t *p) -{ - tINQ_DB_ENT *p_i; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb; - tBTM_INQ_RESULTS_CB *p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb; - tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; - bool update = true; - uint8_t result = 0; - - p_i = btm_inq_db_find (bda); - - /* Check if this address has already been processed for this inquiry */ - if (btm_inq_find_bdaddr(bda)) - { - /* never been report as an LE device */ - if (p_i && - (!(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) || - /* scan repsonse to be updated */ - (!p_i->scan_rsp))) - { - update = true; - } - else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) - { - update = false; - } - else - { - /* if yes, skip it */ - return; /* assumption: one result per event */ - } - } - /* If existing entry, use that, else get a new one (possibly reusing the oldest) */ - if (p_i == NULL) - { - p_i = btm_inq_db_new(bda); - if (p_i != NULL) - { - p_inq->inq_cmpl_info.num_resp++; - } - else - return; - } - else if (p_i->inq_count != p_inq->inq_counter) /* first time seen in this inquiry */ - { - p_inq->inq_cmpl_info.num_resp++; - } - /* update the LE device information in inquiry database */ - if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, p)) - return; - - result = btm_ble_is_discoverable(bda, evt_type, p); - if (result == 0) - { - LOG_WARN(LOG_TAG, "%s device is no longer discoverable so discarding advertising packet pkt", - __func__); - return; - } - if (!update) - result &= ~BTM_BLE_INQ_RESULT; - /* If the number of responses found and limited, issue a cancel inquiry */ - if (p_inq->inqparms.max_resps && - p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps) - { - /* new device */ - if (p_i == NULL || - /* assume a DUMO device, BR/EDR inquiry is always active */ - (p_i && - (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE && - p_i->scan_rsp)) - { - BTM_TRACE_WARNING("INQ RES: Extra Response Received...cancelling inquiry.."); - - /* if is non-periodic inquiry active, cancel now */ - if ((p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK) != 0 && - (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) == 0) - btsnd_hcic_inq_cancel(); - - btm_ble_stop_inquiry(); - - btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); - } - } - /* background connection in selective connection mode */ - if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) - { - if (result & BTM_BLE_SEL_CONN_RESULT) - btm_send_sel_conn_callback(bda, evt_type, p, addr_type); - else - { - BTM_TRACE_DEBUG("None LE device, can not initiate selective connection"); - } - } - else - { - if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) - { - (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); - } - if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) - { - (p_obs_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); - } - } +static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, + uint8_t evt_type, uint8_t* p) { + tINQ_DB_ENT* p_i; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_INQ_RESULTS_CB* p_inq_results_cb = p_inq->p_inq_results_cb; + tBTM_INQ_RESULTS_CB* p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb; + tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + bool update = true; + uint8_t result = 0; + + p_i = btm_inq_db_find(bda); + + /* Check if this address has already been processed for this inquiry */ + if (btm_inq_find_bdaddr(bda)) { + /* never been report as an LE device */ + if (p_i && (!(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) || + /* scan repsonse to be updated */ + (!p_i->scan_rsp))) { + update = true; + } else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { + update = false; + } else { + /* if yes, skip it */ + return; /* assumption: one result per event */ + } + } + /* If existing entry, use that, else get a new one (possibly reusing the + * oldest) */ + if (p_i == NULL) { + p_i = btm_inq_db_new(bda); + if (p_i != NULL) { + p_inq->inq_cmpl_info.num_resp++; + } else + return; + } else if (p_i->inq_count != + p_inq->inq_counter) /* first time seen in this inquiry */ + { + p_inq->inq_cmpl_info.num_resp++; + } + /* update the LE device information in inquiry database */ + if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, p)) return; + + result = btm_ble_is_discoverable(bda, evt_type, p); + if (result == 0) { + LOG_WARN(LOG_TAG, + "%s device is no longer discoverable so discarding advertising " + "packet pkt", + __func__); + return; + } + if (!update) result &= ~BTM_BLE_INQ_RESULT; + /* If the number of responses found and limited, issue a cancel inquiry */ + if (p_inq->inqparms.max_resps && + p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps) { + /* new device */ + if (p_i == NULL || + /* assume a DUMO device, BR/EDR inquiry is always active */ + (p_i && + (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == + BT_DEVICE_TYPE_BLE && + p_i->scan_rsp)) { + BTM_TRACE_WARNING( + "INQ RES: Extra Response Received...cancelling inquiry.."); + + /* if is non-periodic inquiry active, cancel now */ + if ((p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK) != 0 && + (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) == 0) + btsnd_hcic_inq_cancel(); + + btm_ble_stop_inquiry(); + + btm_acl_update_busy_level(BTM_BLI_INQ_DONE_EVT); + } + } + /* background connection in selective connection mode */ + if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) { + if (result & BTM_BLE_SEL_CONN_RESULT) + btm_send_sel_conn_callback(bda, evt_type, p, addr_type); + else { + BTM_TRACE_DEBUG("None LE device, can not initiate selective connection"); + } + } else { + if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) { + (p_inq_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results, + p_le_inq_cb->adv_data_cache); + } + if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) { + (p_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results, + p_le_inq_cb->adv_data_cache); + } + } } /******************************************************************************* @@ -2316,19 +2266,19 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, uint8_t * Returns void * ******************************************************************************/ -tBTM_STATUS btm_ble_start_scan(void) -{ - tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; +tBTM_STATUS btm_ble_start_scan(void) { + tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var; - /* start scan, disable duplicate filtering */ - btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter); + /* start scan, disable duplicate filtering */ + btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_ENABLE, + p_inq->scan_duplicate_filter); - if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) - btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); - else - btm_ble_set_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); + if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) + btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); + else + btm_ble_set_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); - return BTM_CMD_STARTED; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -2340,19 +2290,19 @@ tBTM_STATUS btm_ble_start_scan(void) * Returns void * ******************************************************************************/ -void btm_ble_stop_scan(void) -{ - BTM_TRACE_EVENT ("btm_ble_stop_scan "); +void btm_ble_stop_scan(void) { + BTM_TRACE_EVENT("btm_ble_stop_scan "); - /* Clear the inquiry callback if set */ - btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; + /* Clear the inquiry callback if set */ + btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; - /* stop discovery now */ - btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); + /* stop discovery now */ + btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_DISABLE, + BTM_BLE_DUPLICATE_ENABLE); - btm_update_scanner_filter_policy(SP_ADV_ALL); + btm_update_scanner_filter_policy(SP_ADV_ALL); - btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; + btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; } /******************************************************************************* * @@ -2363,31 +2313,30 @@ void btm_ble_stop_scan(void) * Returns void * ******************************************************************************/ -void btm_ble_stop_inquiry(void) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; - - alarm_cancel(p_ble_cb->inq_var.inquiry_timer); - - p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK; - - /* If no more scan activity, stop LE scan now */ - if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) - btm_ble_stop_scan(); - else if((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || - (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) - { - BTM_TRACE_DEBUG("%s: setting default params for ongoing observe", __func__); - btm_ble_stop_scan(); - btm_ble_start_scan(); - } +void btm_ble_stop_inquiry(void) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; - /* If we have a callback registered for inquiry complete, call it */ - BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d", - p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); + alarm_cancel(p_ble_cb->inq_var.inquiry_timer); - btm_process_inq_complete(HCI_SUCCESS, (uint8_t)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK)); + p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK; + + /* If no more scan activity, stop LE scan now */ + if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) + btm_ble_stop_scan(); + else if ((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || + (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { + BTM_TRACE_DEBUG("%s: setting default params for ongoing observe", __func__); + btm_ble_stop_scan(); + btm_ble_start_scan(); + } + + /* If we have a callback registered for inquiry complete, call it */ + BTM_TRACE_DEBUG("BTM Inq Compl Callback: status 0x%02x, num results %d", + p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); + + btm_process_inq_complete( + HCI_SUCCESS, (uint8_t)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK)); } /******************************************************************************* @@ -2399,23 +2348,21 @@ void btm_ble_stop_inquiry(void) * Returns void * ******************************************************************************/ -static void btm_ble_stop_observe(void) -{ - tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; - tBTM_CMPL_CB *p_obs_cb = p_ble_cb->p_obs_cmpl_cb; +static void btm_ble_stop_observe(void) { + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; + tBTM_CMPL_CB* p_obs_cb = p_ble_cb->p_obs_cmpl_cb; - alarm_cancel(p_ble_cb->observer_timer); + alarm_cancel(p_ble_cb->observer_timer); - p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE; + p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE; - p_ble_cb->p_obs_results_cb = NULL; - p_ble_cb->p_obs_cmpl_cb = NULL; + p_ble_cb->p_obs_results_cb = NULL; + p_ble_cb->p_obs_cmpl_cb = NULL; - if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) - btm_ble_stop_scan(); + if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) btm_ble_stop_scan(); - if (p_obs_cb) - (p_obs_cb)((tBTM_INQUIRY_CMPL *) &btm_cb.btm_inq_vars.inq_cmpl_info); + if (p_obs_cb) + (p_obs_cb)((tBTM_INQUIRY_CMPL*)&btm_cb.btm_inq_vars.inq_cmpl_info); } /******************************************************************************* * @@ -2426,38 +2373,37 @@ static void btm_ble_stop_observe(void) * Returns operation status. true if sucessful, false otherwise. * ******************************************************************************/ -typedef bool (BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK); -static bool btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR *p_handler, uint8_t adv_evt) -{ - bool rt = false; +typedef bool(BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK); +static bool btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR* p_handler, + uint8_t adv_evt) { + bool rt = false; - switch (adv_evt) - { + switch (adv_evt) { case BTM_BLE_CONNECT_EVT: - rt = (*p_handler)(BTM_BLE_STATE_CONN_ADV_BIT); - break; + rt = (*p_handler)(BTM_BLE_STATE_CONN_ADV_BIT); + break; - case BTM_BLE_NON_CONNECT_EVT: - rt = (*p_handler) (BTM_BLE_STATE_NON_CONN_ADV_BIT); - break; + case BTM_BLE_NON_CONNECT_EVT: + rt = (*p_handler)(BTM_BLE_STATE_NON_CONN_ADV_BIT); + break; case BTM_BLE_CONNECT_DIR_EVT: - rt = (*p_handler) (BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); - break; + rt = (*p_handler)(BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); + break; case BTM_BLE_DISCOVER_EVT: - rt = (*p_handler) (BTM_BLE_STATE_SCAN_ADV_BIT); - break; + rt = (*p_handler)(BTM_BLE_STATE_SCAN_ADV_BIT); + break; case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: - rt = (*p_handler) (BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT); - break; + rt = (*p_handler)(BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT); + break; default: - BTM_TRACE_ERROR("unknown adv event : %d", adv_evt); - break; - } + BTM_TRACE_ERROR("unknown adv event : %d", adv_evt); + break; + } - return rt; + return rt; } /******************************************************************************* @@ -2469,30 +2415,29 @@ static bool btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR *p_handler, ui * Returns void * ******************************************************************************/ -tBTM_STATUS btm_ble_start_adv(void) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; +tBTM_STATUS btm_ble_start_adv(void) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; - if (!btm_ble_adv_states_operation (btm_ble_topology_check, p_cb->evt_type)) - return BTM_WRONG_MODE; + if (!btm_ble_adv_states_operation(btm_ble_topology_check, p_cb->evt_type)) + return BTM_WRONG_MODE; #if (BLE_PRIVACY_SPT == TRUE) - /* To relax resolving list, always have resolving list enabled, unless directed adv */ - if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT && - p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT) - /* enable resolving list is desired */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV); + /* To relax resolving list, always have resolving list enabled, unless + * directed adv */ + if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT && + p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT) + /* enable resolving list is desired */ + btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV); #endif - if (p_cb->afp != AP_SCAN_CONN_ALL) - { - btm_execute_wl_dev_operation(); - btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; - } + if (p_cb->afp != AP_SCAN_CONN_ALL) { + btm_execute_wl_dev_operation(); + btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; + } - btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE); - p_cb->adv_mode = BTM_BLE_ADV_ENABLE; - btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); - return BTM_SUCCESS; + btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_ENABLE); + p_cb->adv_mode = BTM_BLE_ADV_ENABLE; + btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); + return BTM_SUCCESS; } /******************************************************************************* @@ -2504,28 +2449,25 @@ tBTM_STATUS btm_ble_start_adv(void) * Returns void * ******************************************************************************/ -tBTM_STATUS btm_ble_stop_adv(void) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; +tBTM_STATUS btm_ble_stop_adv(void) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; - if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) - { - btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE); + if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { + btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE); - p_cb->fast_adv_on = false; - p_cb->adv_mode = BTM_BLE_ADV_DISABLE; - btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; + p_cb->fast_adv_on = false; + p_cb->adv_mode = BTM_BLE_ADV_DISABLE; + btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; - /* clear all adv states */ - btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); - } - return BTM_SUCCESS; + /* clear all adv states */ + btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); + } + return BTM_SUCCESS; } -static void btm_ble_fast_adv_timer_timeout(UNUSED_ATTR void *data) -{ - /* fast adv is completed, fall back to slow adv interval */ - btm_ble_start_slow_adv(); +static void btm_ble_fast_adv_timer_timeout(UNUSED_ATTR void* data) { + /* fast adv is completed, fall back to slow adv interval */ + btm_ble_start_slow_adv(); } /******************************************************************************* @@ -2537,56 +2479,51 @@ static void btm_ble_fast_adv_timer_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -static void btm_ble_start_slow_adv(void) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; +static void btm_ble_start_slow_adv(void) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; - if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) - { - tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - BD_ADDR p_addr_ptr = {0}; - tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; - tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; + if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { + tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + BD_ADDR p_addr_ptr = {0}; + tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; + tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; - btm_ble_stop_adv(); + btm_ble_stop_adv(); - p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, - &own_addr_type); + p_cb->evt_type = btm_set_conn_mode_adv_init_addr( + p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); - /* slow adv mode never goes into directed adv */ - btsnd_hcic_ble_write_adv_params (BTM_BLE_GAP_ADV_SLOW_INT, BTM_BLE_GAP_ADV_SLOW_INT, - p_cb->evt_type, own_addr_type, - init_addr_type, p_addr_ptr, - p_cb->adv_chnl_map, p_cb->afp); + /* slow adv mode never goes into directed adv */ + btsnd_hcic_ble_write_adv_params(BTM_BLE_GAP_ADV_SLOW_INT, + BTM_BLE_GAP_ADV_SLOW_INT, p_cb->evt_type, + own_addr_type, init_addr_type, p_addr_ptr, + p_cb->adv_chnl_map, p_cb->afp); - btm_ble_start_adv(); - } + btm_ble_start_adv(); + } } -static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(UNUSED_ATTR void *data) -{ - /* lim_timeout expired, limited discovery should exit now */ - btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE; - btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, - btm_cb.btm_inq_vars.discoverable_mode); +static void btm_ble_inquiry_timer_gap_limited_discovery_timeout( + UNUSED_ATTR void* data) { + /* lim_timeout expired, limited discovery should exit now */ + btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE; + btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, + btm_cb.btm_inq_vars.discoverable_mode); } -static void btm_ble_inquiry_timer_timeout(UNUSED_ATTR void *data) -{ - btm_ble_stop_inquiry(); +static void btm_ble_inquiry_timer_timeout(UNUSED_ATTR void* data) { + btm_ble_stop_inquiry(); } -static void btm_ble_observer_timer_timeout(UNUSED_ATTR void *data) -{ - btm_ble_stop_observe(); +static void btm_ble_observer_timer_timeout(UNUSED_ATTR void* data) { + btm_ble_stop_observe(); } -void btm_ble_refresh_raddr_timer_timeout(UNUSED_ATTR void *data) -{ - if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) { - /* refresh the random addr */ - btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); - } +void btm_ble_refresh_raddr_timer_timeout(UNUSED_ATTR void* data) { + if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) { + /* refresh the random addr */ + btm_gen_resolvable_private_addr((void*)btm_gen_resolve_paddr_low); + } } /******************************************************************************* @@ -2600,35 +2537,30 @@ void btm_ble_refresh_raddr_timer_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_ble_read_remote_features_complete(uint8_t *p) -{ - tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; - uint16_t handle; - uint8_t status; - int xx; - - BTM_TRACE_EVENT ("btm_ble_read_remote_features_complete "); - - STREAM_TO_UINT8(status, p); - - // if LE read remote feature failed for HCI_ERR_CONN_FAILED_ESTABLISHMENT, - // expect disconnect complete to be received - if (status != HCI_ERR_CONN_FAILED_ESTABLISHMENT) - { - STREAM_TO_UINT16 (handle, p); - - /* Look up the connection by handle and copy features */ - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) - { - if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) - { - STREAM_TO_ARRAY(p_acl_cb->peer_le_features, p, BD_FEATURES_LEN); - btsnd_hcic_rmt_ver_req (p_acl_cb->hci_handle); - break; - } - } +void btm_ble_read_remote_features_complete(uint8_t* p) { + tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; + uint16_t handle; + uint8_t status; + int xx; + + BTM_TRACE_EVENT("btm_ble_read_remote_features_complete "); + + STREAM_TO_UINT8(status, p); + + // if LE read remote feature failed for HCI_ERR_CONN_FAILED_ESTABLISHMENT, + // expect disconnect complete to be received + if (status != HCI_ERR_CONN_FAILED_ESTABLISHMENT) { + STREAM_TO_UINT16(handle, p); + + /* Look up the connection by handle and copy features */ + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) { + if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) { + STREAM_TO_ARRAY(p_acl_cb->peer_le_features, p, BD_FEATURES_LEN); + btsnd_hcic_rmt_ver_req(p_acl_cb->hci_handle); + break; + } } - + } } /******************************************************************************* @@ -2640,16 +2572,14 @@ void btm_ble_read_remote_features_complete(uint8_t *p) * Returns void * ******************************************************************************/ -void btm_ble_write_adv_enable_complete(uint8_t * p) -{ - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - - /* if write adv enable/disbale not succeed */ - if (*p != HCI_SUCCESS) - { - /* toggle back the adv mode */ - p_cb->adv_mode = !p_cb->adv_mode; - } +void btm_ble_write_adv_enable_complete(uint8_t* p) { + tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; + + /* if write adv enable/disbale not succeed */ + if (*p != HCI_SUCCESS) { + /* toggle back the adv mode */ + p_cb->adv_mode = !p_cb->adv_mode; + } } /******************************************************************************* @@ -2661,12 +2591,11 @@ void btm_ble_write_adv_enable_complete(uint8_t * p) * Returns void * ******************************************************************************/ -void btm_ble_dir_adv_tout(void) -{ - btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; +void btm_ble_dir_adv_tout(void) { + btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - /* make device fall back into undirected adv mode by default */ - btm_cb.ble_ctr_cb.inq_var.directed_conn = false; + /* make device fall back into undirected adv mode by default */ + btm_cb.ble_ctr_cb.inq_var.directed_conn = false; } /******************************************************************************* @@ -2678,11 +2607,10 @@ void btm_ble_dir_adv_tout(void) * Returns true is request is allowed, false otherwise. * ******************************************************************************/ -bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) -{ - request_state_mask &= BTM_BLE_STATE_ALL_MASK; - btm_cb.ble_ctr_cb.cur_states |= (request_state_mask & BTM_BLE_STATE_ALL_MASK); - return true; +bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) { + request_state_mask &= BTM_BLE_STATE_ALL_MASK; + btm_cb.ble_ctr_cb.cur_states |= (request_state_mask & BTM_BLE_STATE_ALL_MASK); + return true; } /******************************************************************************* @@ -2694,11 +2622,10 @@ bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) * Returns true is request is allowed, false otherwise. * ******************************************************************************/ -bool btm_ble_clear_topology_mask (tBTM_BLE_STATE_MASK request_state_mask) -{ - request_state_mask &= BTM_BLE_STATE_ALL_MASK; - btm_cb.ble_ctr_cb.cur_states &= ~request_state_mask; - return true; +bool btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) { + request_state_mask &= BTM_BLE_STATE_ALL_MASK; + btm_cb.ble_ctr_cb.cur_states &= ~request_state_mask; + return true; } /******************************************************************************* @@ -2710,29 +2637,27 @@ bool btm_ble_clear_topology_mask (tBTM_BLE_STATE_MASK request_state_mask) * Returns void * ******************************************************************************/ -void btm_ble_update_link_topology_mask(uint8_t link_role, bool increase) -{ - btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_CONN_MASK); - - if (increase) - btm_cb.ble_ctr_cb.link_count[link_role]++; - else if (btm_cb.ble_ctr_cb.link_count[link_role] > 0) - btm_cb.ble_ctr_cb.link_count[link_role]--; - - if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_MASTER]) - btm_ble_set_topology_mask (BTM_BLE_STATE_MASTER_BIT); - - if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_SLAVE]) - btm_ble_set_topology_mask(BTM_BLE_STATE_SLAVE_BIT); - - if (link_role == HCI_ROLE_SLAVE && increase) - { - btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - /* make device fall back into undirected adv mode by default */ - btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; - /* clear all adv states */ - btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); - } +void btm_ble_update_link_topology_mask(uint8_t link_role, bool increase) { + btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_CONN_MASK); + + if (increase) + btm_cb.ble_ctr_cb.link_count[link_role]++; + else if (btm_cb.ble_ctr_cb.link_count[link_role] > 0) + btm_cb.ble_ctr_cb.link_count[link_role]--; + + if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_MASTER]) + btm_ble_set_topology_mask(BTM_BLE_STATE_MASTER_BIT); + + if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_SLAVE]) + btm_ble_set_topology_mask(BTM_BLE_STATE_SLAVE_BIT); + + if (link_role == HCI_ROLE_SLAVE && increase) { + btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; + /* make device fall back into undirected adv mode by default */ + btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; + /* clear all adv states */ + btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); + } } /******************************************************************************* @@ -2745,31 +2670,31 @@ void btm_ble_update_link_topology_mask(uint8_t link_role, bool increase) * Returns void * ******************************************************************************/ -void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bd_addr, uint8_t status) -{ - if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) - { - btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - /* make device fall back into undirected adv mode by default */ - btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; - /* clear all adv states */ - btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); - } - - if (btm_cb.ble_ctr_cb.inq_var.connectable_mode == BTM_BLE_CONNECTABLE) - { - btm_ble_set_connectability(btm_cb.btm_inq_vars.connectable_mode | - btm_cb.ble_ctr_cb.inq_var.connectable_mode); - } - - /* when no connection is attempted, and controller is not rejecting last request - due to resource limitation, start next direct connection or background connection - now in order */ - if (btm_ble_get_conn_st() == BLE_CONN_IDLE && status != HCI_ERR_HOST_REJECT_RESOURCES && - !btm_send_pending_direct_conn()) - { - btm_ble_resume_bg_conn(); - } +void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bd_addr, + uint8_t status) { + if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) { + btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; + /* make device fall back into undirected adv mode by default */ + btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; + /* clear all adv states */ + btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); + } + + if (btm_cb.ble_ctr_cb.inq_var.connectable_mode == BTM_BLE_CONNECTABLE) { + btm_ble_set_connectability(btm_cb.btm_inq_vars.connectable_mode | + btm_cb.ble_ctr_cb.inq_var.connectable_mode); + } + + /* when no connection is attempted, and controller is not rejecting last + request + due to resource limitation, start next direct connection or background + connection + now in order */ + if (btm_ble_get_conn_st() == BLE_CONN_IDLE && + status != HCI_ERR_HOST_REJECT_RESOURCES && + !btm_send_pending_direct_conn()) { + btm_ble_resume_bg_conn(); + } } /******************************************************************************* @@ -2781,42 +2706,41 @@ void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bd_addr, uint8_t s * Returns void * ******************************************************************************/ -void btm_ble_init(void) -{ - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; +void btm_ble_init(void) { + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; - BTM_TRACE_DEBUG("%s", __func__); + BTM_TRACE_DEBUG("%s", __func__); - alarm_free(p_cb->observer_timer); - alarm_free(p_cb->inq_var.fast_adv_timer); - memset(p_cb, 0, sizeof(tBTM_BLE_CB)); - memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB)); - btm_cb.cmn_ble_vsc_cb.values_read = false; + alarm_free(p_cb->observer_timer); + alarm_free(p_cb->inq_var.fast_adv_timer); + memset(p_cb, 0, sizeof(tBTM_BLE_CB)); + memset(&(btm_cb.cmn_ble_vsc_cb), 0, sizeof(tBTM_BLE_VSC_CB)); + btm_cb.cmn_ble_vsc_cb.values_read = false; - p_cb->observer_timer = alarm_new("btm_ble.observer_timer"); - p_cb->cur_states = 0; - p_cb->conn_pending_q = fixed_queue_new(SIZE_MAX); + p_cb->observer_timer = alarm_new("btm_ble.observer_timer"); + p_cb->cur_states = 0; + p_cb->conn_pending_q = fixed_queue_new(SIZE_MAX); - p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; - p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP; - p_cb->inq_var.afp = BTM_BLE_DEFAULT_AFP; - p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP; - p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE; - p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE; - p_cb->inq_var.fast_adv_timer = alarm_new("btm_ble_inq.fast_adv_timer"); - p_cb->inq_var.inquiry_timer = alarm_new("btm_ble_inq.inquiry_timer"); + p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; + p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; + p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP; + p_cb->inq_var.afp = BTM_BLE_DEFAULT_AFP; + p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP; + p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE; + p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE; + p_cb->inq_var.fast_adv_timer = alarm_new("btm_ble_inq.fast_adv_timer"); + p_cb->inq_var.inquiry_timer = alarm_new("btm_ble_inq.inquiry_timer"); - /* for background connection, reset connection params to be undefined */ - p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF; + /* for background connection, reset connection params to be undefined */ + p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF; - p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT; + p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT; - p_cb->addr_mgnt_cb.refresh_raddr_timer = - alarm_new("btm_ble_addr.refresh_raddr_timer"); + p_cb->addr_mgnt_cb.refresh_raddr_timer = + alarm_new("btm_ble_addr.refresh_raddr_timer"); #if (BLE_VND_INCLUDED == FALSE) - btm_ble_adv_filter_init(); + btm_ble_adv_filter_init(); #endif } @@ -2830,63 +2754,57 @@ void btm_ble_init(void) * Returns true is request is allowed, false otherwise. * ******************************************************************************/ -bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask) -{ - bool rt = false; - - uint8_t state_offset = 0; - uint16_t cur_states = btm_cb.ble_ctr_cb.cur_states; - uint8_t mask, offset; - uint8_t request_state = 0; - - /* check only one bit is set and within valid range */ - if (request_state_mask == BTM_BLE_STATE_INVALID || - request_state_mask > BTM_BLE_STATE_SCAN_ADV_BIT || - (request_state_mask & (request_state_mask -1 )) != 0) - { - BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask); - return rt; - } - - while (request_state_mask) - { - request_state_mask >>= 1; - request_state ++; - } +bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask) { + bool rt = false; + + uint8_t state_offset = 0; + uint16_t cur_states = btm_cb.ble_ctr_cb.cur_states; + uint8_t mask, offset; + uint8_t request_state = 0; + + /* check only one bit is set and within valid range */ + if (request_state_mask == BTM_BLE_STATE_INVALID || + request_state_mask > BTM_BLE_STATE_SCAN_ADV_BIT || + (request_state_mask & (request_state_mask - 1)) != 0) { + BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask); + return rt; + } - /* check if the requested state is supported or not */ - mask = btm_le_state_combo_tbl[0][request_state - 1][0]; - offset = btm_le_state_combo_tbl[0][request_state-1][1]; + while (request_state_mask) { + request_state_mask >>= 1; + request_state++; + } - const uint8_t *ble_supported_states = controller_get_interface()->get_ble_supported_states(); + /* check if the requested state is supported or not */ + mask = btm_le_state_combo_tbl[0][request_state - 1][0]; + offset = btm_le_state_combo_tbl[0][request_state - 1][1]; - if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) - { - BTM_TRACE_ERROR("state requested not supported: %d", request_state); - return rt; - } + const uint8_t* ble_supported_states = + controller_get_interface()->get_ble_supported_states(); - rt = true; - /* make sure currently active states are all supported in conjunction with the requested - state. If the bit in table is not set, the combination is not supported */ - while (cur_states != 0) - { - if (cur_states & 0x01) - { - mask = btm_le_state_combo_tbl[request_state][state_offset][0]; - offset = btm_le_state_combo_tbl[request_state][state_offset][1]; - - if (mask != 0 && offset != 0) - { - if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) - { - rt = false; - break; - } - } + if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) { + BTM_TRACE_ERROR("state requested not supported: %d", request_state); + return rt; + } + + rt = true; + /* make sure currently active states are all supported in conjunction with the + requested + state. If the bit in table is not set, the combination is not supported */ + while (cur_states != 0) { + if (cur_states & 0x01) { + mask = btm_le_state_combo_tbl[request_state][state_offset][0]; + offset = btm_le_state_combo_tbl[request_state][state_offset][1]; + + if (mask != 0 && offset != 0) { + if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) { + rt = false; + break; } - cur_states >>= 1; - state_offset ++; + } } - return rt; + cur_states >>= 1; + state_offset++; + } + return rt; } diff --git a/stack/btm/btm_ble_int.h b/stack/btm/btm_ble_int.h index 28b6ce139..a75fef8d9 100644 --- a/stack/btm/btm_ble_int.h +++ b/stack/btm/btm_ble_int.h @@ -26,121 +26,154 @@ #ifndef BTM_BLE_INT_H #define BTM_BLE_INT_H -#include "bt_target.h" #include "bt_common.h" -#include "hcidefs.h" +#include "bt_target.h" #include "btm_ble_api.h" +#include "btm_ble_int_types.h" #include "btm_int.h" +#include "hcidefs.h" #include "smp_api.h" -#include "btm_ble_int_types.h" #ifdef __cplusplus extern "C" { #endif -extern void btm_ble_refresh_raddr_timer_timeout(void *data); -extern void btm_ble_process_adv_pkt (uint8_t *p); -extern void btm_ble_proc_scan_rsp_rpt (uint8_t *p); -extern tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb); -extern bool btm_ble_cancel_remote_name(BD_ADDR remote_bda); +extern void btm_ble_refresh_raddr_timer_timeout(void* data); +extern void btm_ble_process_adv_pkt(uint8_t* p); +extern void btm_ble_proc_scan_rsp_rpt(uint8_t* p); +extern tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, + tBTM_INQ_INFO* p_cur, + tBTM_CMPL_CB* p_cb); +extern bool btm_ble_cancel_remote_name(BD_ADDR remote_bda); extern tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode); extern tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode); -extern tBTM_STATUS btm_ble_start_inquiry (uint8_t mode, uint8_t duration); +extern tBTM_STATUS btm_ble_start_inquiry(uint8_t mode, uint8_t duration); extern void btm_ble_stop_scan(void); extern void btm_clear_all_pending_le_entry(void); extern void btm_ble_stop_scan(); -extern void btm_ble_send_extended_scan_params(uint8_t scan_type, uint32_t scan_int, - uint32_t scan_win, uint8_t addr_type_own, - uint8_t scan_filter_policy); +extern void btm_ble_send_extended_scan_params(uint8_t scan_type, + uint32_t scan_int, + uint32_t scan_win, + uint8_t addr_type_own, + uint8_t scan_filter_policy); extern void btm_ble_stop_inquiry(void); -extern void btm_ble_init (void); -extern void btm_ble_connected (uint8_t *bda, uint16_t handle, uint8_t enc_mode, uint8_t role, tBLE_ADDR_TYPE addr_type, bool addr_matched); -extern void btm_ble_read_remote_features_complete(uint8_t *p); -extern void btm_ble_write_adv_enable_complete(uint8_t * p); -extern void btm_ble_conn_complete(uint8_t *p, uint16_t evt_len, bool enhanced); -extern void btm_read_ble_local_supported_states_complete(uint8_t *p, uint16_t evt_len); +extern void btm_ble_init(void); +extern void btm_ble_connected(uint8_t* bda, uint16_t handle, uint8_t enc_mode, + uint8_t role, tBLE_ADDR_TYPE addr_type, + bool addr_matched); +extern void btm_ble_read_remote_features_complete(uint8_t* p); +extern void btm_ble_write_adv_enable_complete(uint8_t* p); +extern void btm_ble_conn_complete(uint8_t* p, uint16_t evt_len, bool enhanced); +extern void btm_read_ble_local_supported_states_complete(uint8_t* p, + uint16_t evt_len); extern tBTM_BLE_CONN_ST btm_ble_get_conn_st(void); extern void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st); extern tBTM_STATUS btm_ble_start_adv(void); extern tBTM_STATUS btm_ble_stop_adv(void); extern tBTM_STATUS btm_ble_start_scan(void); -extern void btm_ble_create_ll_conn_complete (uint8_t status); +extern void btm_ble_create_ll_conn_complete(uint8_t status); /* LE security function from btm_sec.cc */ -extern void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE_SEC_REQ_ACT *p_sec_req_act); -extern void btm_ble_ltk_request_reply(BD_ADDR bda, bool use_stk, BT_OCTET16 stk); -extern uint8_t btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data); -extern tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, tBTM_BLE_SEC_ACT sec_act, uint8_t link_role); -extern void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], uint16_t ediv); -extern tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, bool use_stk, BT_OCTET16 stk); +extern void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, + tBTM_BLE_SEC_REQ_ACT* p_sec_req_act); +extern void btm_ble_ltk_request_reply(BD_ADDR bda, bool use_stk, + BT_OCTET16 stk); +extern uint8_t btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, + tSMP_EVT_DATA* p_data); +extern tBTM_STATUS btm_ble_set_encryption(BD_ADDR bd_addr, + tBTM_BLE_SEC_ACT sec_act, + uint8_t link_role); +extern void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], + uint16_t ediv); +extern tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, bool use_stk, + BT_OCTET16 stk); extern void btm_ble_link_encrypted(BD_ADDR bd_addr, uint8_t encr_enable); /* LE device management functions */ -extern void btm_ble_reset_id( void ); +extern void btm_ble_reset_id(void); /* security related functions */ -extern void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, bool is_local ); -extern bool btm_get_local_div (BD_ADDR bd_addr, uint16_t *p_div); -extern bool btm_ble_get_enc_key_type(BD_ADDR bd_addr, uint8_t *p_key_types); +extern void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, bool is_local); +extern bool btm_get_local_div(BD_ADDR bd_addr, uint16_t* p_div); +extern bool btm_ble_get_enc_key_type(BD_ADDR bd_addr, uint8_t* p_key_types); -extern void btm_ble_test_command_complete(uint8_t *p); -extern void btm_ble_rand_enc_complete (uint8_t *p, uint16_t op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback); +extern void btm_ble_test_command_complete(uint8_t* p); +extern void btm_ble_rand_enc_complete(uint8_t* p, uint16_t op_code, + tBTM_RAND_ENC_CB* p_enc_cplt_cback); -extern void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, bool pass_to_application); +extern void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, + tBTM_LE_KEY_VALUE* p_keys, + bool pass_to_application); extern void btm_ble_update_sec_key_size(BD_ADDR bd_addr, uint8_t enc_key_size); extern uint8_t btm_ble_read_sec_key_size(BD_ADDR bd_addr); /* white list function */ -extern bool btm_update_dev_to_white_list(bool to_add, BD_ADDR bd_addr); +extern bool btm_update_dev_to_white_list(bool to_add, BD_ADDR bd_addr); extern void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy); extern void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy); -extern void btm_ble_clear_white_list (void); -extern void btm_read_white_list_size_complete(uint8_t *p, uint16_t evt_len); +extern void btm_ble_clear_white_list(void); +extern void btm_read_white_list_size_complete(uint8_t* p, uint16_t evt_len); extern void btm_ble_add_2_white_list_complete(uint8_t status); -extern void btm_ble_remove_from_white_list_complete(uint8_t *p, uint16_t evt_len); -extern void btm_ble_clear_white_list_complete(uint8_t *p, uint16_t evt_len); +extern void btm_ble_remove_from_white_list_complete(uint8_t* p, + uint16_t evt_len); +extern void btm_ble_clear_white_list_complete(uint8_t* p, uint16_t evt_len); extern void btm_ble_white_list_init(uint8_t white_list_size); /* background connection function */ -extern bool btm_ble_suspend_bg_conn(void); -extern bool btm_ble_resume_bg_conn(void); +extern bool btm_ble_suspend_bg_conn(void); +extern bool btm_ble_resume_bg_conn(void); extern void btm_ble_initiate_select_conn(BD_ADDR bda); -extern bool btm_ble_start_auto_conn(bool start); -extern bool btm_ble_start_select_conn(bool start,tBTM_BLE_SEL_CBACK *p_select_cback); -extern bool btm_ble_renew_bg_conn_params(bool add, BD_ADDR bd_addr); +extern bool btm_ble_start_auto_conn(bool start); +extern bool btm_ble_start_select_conn(bool start, + tBTM_BLE_SEL_CBACK* p_select_cback); +extern bool btm_ble_renew_bg_conn_params(bool add, BD_ADDR bd_addr); extern void btm_write_dir_conn_wl(BD_ADDR target_addr); -extern void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bda, uint8_t status); -extern bool btm_execute_wl_dev_operation(void); -extern void btm_ble_update_link_topology_mask(uint8_t role, bool increase); +extern void btm_ble_update_mode_operation(uint8_t link_role, BD_ADDR bda, + uint8_t status); +extern bool btm_execute_wl_dev_operation(void); +extern void btm_ble_update_link_topology_mask(uint8_t role, bool increase); /* direct connection utility */ -extern bool btm_send_pending_direct_conn(void); -extern void btm_ble_enqueue_direct_conn_req(void *p_param); +extern bool btm_send_pending_direct_conn(void); +extern void btm_ble_enqueue_direct_conn_req(void* p_param); extern void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda); /* BLE address management */ -extern void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback); -extern void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p); -extern void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_cback, void *p); -extern void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p); +extern void btm_gen_resolvable_private_addr(void* p_cmd_cplt_cback); +extern void btm_gen_non_resolvable_private_addr(tBTM_BLE_ADDR_CBACK* p_cback, + void* p); +extern void btm_ble_resolve_random_addr(BD_ADDR random_bda, + tBTM_BLE_RESOLVE_CBACK* p_cback, + void* p); +extern void btm_gen_resolve_paddr_low(tBTM_RAND_ENC* p); /* privacy function */ #if (BLE_PRIVACY_SPT == TRUE) /* BLE address mapping with CS feature */ -extern bool btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, uint8_t *p_addr_type, bool refresh); -extern bool btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, uint8_t *p_static_addr_type); -extern void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rra, uint8_t rra_type); -extern void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, BD_ADDR local_rpa); -extern void btm_ble_read_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) ; -extern void btm_ble_remove_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len); -extern void btm_ble_add_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len); -extern void btm_ble_clear_resolving_list_complete(uint8_t *p, uint16_t evt_len); -extern void btm_read_ble_resolving_list_size_complete (uint8_t *p, uint16_t evt_len); +extern bool btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, + uint8_t* p_addr_type, + bool refresh); +extern bool btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, + uint8_t* p_static_addr_type); +extern void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, + BD_ADDR rra, + uint8_t rra_type); +extern void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, + BD_ADDR local_rpa); +extern void btm_ble_read_resolving_list_entry_complete(uint8_t* p, + uint16_t evt_len); +extern void btm_ble_remove_resolving_list_entry_complete(uint8_t* p, + uint16_t evt_len); +extern void btm_ble_add_resolving_list_entry_complete(uint8_t* p, + uint16_t evt_len); +extern void btm_ble_clear_resolving_list_complete(uint8_t* p, uint16_t evt_len); +extern void btm_read_ble_resolving_list_size_complete(uint8_t* p, + uint16_t evt_len); extern void btm_ble_enable_resolving_list(uint8_t); -extern bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume); -extern void btm_ble_enable_resolving_list_for_platform (uint8_t rl_mask); +extern bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume); +extern void btm_ble_enable_resolving_list_for_platform(uint8_t rl_mask); extern void btm_ble_resolving_list_init(uint8_t max_irk_list_sz); extern void btm_ble_resolving_list_cleanup(void); #endif @@ -152,19 +185,19 @@ extern void btm_ble_batchscan_init(void); extern void btm_ble_batchscan_cleanup(void); extern void btm_ble_adv_filter_init(void); extern void btm_ble_adv_filter_cleanup(void); -extern bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request); -extern bool btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state); -extern bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state); +extern bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request); +extern bool btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state); +extern bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state); #if (BTM_BLE_CONFORMANCE_TESTING == TRUE) -extern void btm_ble_set_no_disc_if_pair_fail (bool disble_disc); -extern void btm_ble_set_test_mac_value (bool enable, uint8_t *p_test_mac_val); -extern void btm_ble_set_test_local_sign_cntr_value(bool enable, uint32_t test_local_sign_cntr); +extern void btm_ble_set_no_disc_if_pair_fail(bool disble_disc); +extern void btm_ble_set_test_mac_value(bool enable, uint8_t* p_test_mac_val); +extern void btm_ble_set_test_local_sign_cntr_value( + bool enable, uint32_t test_local_sign_cntr); extern void btm_set_random_address(BD_ADDR random_bda); -extern void btm_ble_set_keep_rfu_in_auth_req(bool keep_rfu); +extern void btm_ble_set_keep_rfu_in_auth_req(bool keep_rfu); #endif - #ifdef __cplusplus } #endif diff --git a/stack/btm/btm_ble_int_types.h b/stack/btm/btm_ble_int_types.h index c282de6ea..8c311b5ba 100644 --- a/stack/btm/btm_ble_int_types.h +++ b/stack/btm/btm_ble_int_types.h @@ -26,84 +26,85 @@ extern "C" { #endif /* scanning enable status */ -#define BTM_BLE_SCAN_ENABLE 0x01 -#define BTM_BLE_SCAN_DISABLE 0x00 +#define BTM_BLE_SCAN_ENABLE 0x01 +#define BTM_BLE_SCAN_DISABLE 0x00 /* advertising enable status */ -#define BTM_BLE_ADV_ENABLE 0x01 -#define BTM_BLE_ADV_DISABLE 0x00 +#define BTM_BLE_ADV_ENABLE 0x01 +#define BTM_BLE_ADV_DISABLE 0x00 /* use the high 4 bits unused by inquiry mode */ -#define BTM_BLE_SELECT_SCAN 0x20 -#define BTM_BLE_NAME_REQUEST 0x40 -#define BTM_BLE_OBSERVE 0x80 +#define BTM_BLE_SELECT_SCAN 0x20 +#define BTM_BLE_NAME_REQUEST 0x40 +#define BTM_BLE_OBSERVE 0x80 -#define BTM_BLE_MAX_WL_ENTRY 1 -#define BTM_BLE_AD_DATA_LEN 31 +#define BTM_BLE_MAX_WL_ENTRY 1 +#define BTM_BLE_AD_DATA_LEN 31 -#define BTM_BLE_ENC_MASK 0x03 +#define BTM_BLE_ENC_MASK 0x03 -#define BTM_BLE_DUPLICATE_ENABLE 1 -#define BTM_BLE_DUPLICATE_DISABLE 0 +#define BTM_BLE_DUPLICATE_ENABLE 1 +#define BTM_BLE_DUPLICATE_DISABLE 0 /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms */ -#define BTM_BLE_GAP_DISC_SCAN_INT 18 +#define BTM_BLE_GAP_DISC_SCAN_INT 18 /* scan_window = 11.25 ms= 0x0010 * 0.625 ms */ -#define BTM_BLE_GAP_DISC_SCAN_WIN 18 +#define BTM_BLE_GAP_DISC_SCAN_WIN 18 /* Tgap(gen_disc) = 1.28 s= 512 * 0.625 ms */ -#define BTM_BLE_GAP_ADV_INT 512 +#define BTM_BLE_GAP_ADV_INT 512 /* Tgap(lim_timeout) = 180s max */ -#define BTM_BLE_GAP_LIM_TIMEOUT_MS (180 * 1000) +#define BTM_BLE_GAP_LIM_TIMEOUT_MS (180 * 1000) /* Interval(scan_int) = 5s= 8000 * 0.625 ms */ -#define BTM_BLE_LOW_LATENCY_SCAN_INT 8000 +#define BTM_BLE_LOW_LATENCY_SCAN_INT 8000 /* scan_window = 5s= 8000 * 0.625 ms */ -#define BTM_BLE_LOW_LATENCY_SCAN_WIN 8000 - +#define BTM_BLE_LOW_LATENCY_SCAN_WIN 8000 /* TGAP(adv_fast_interval1) = 30(used) ~ 60 ms = 48 *0.625 */ -#define BTM_BLE_GAP_ADV_FAST_INT_1 48 +#define BTM_BLE_GAP_ADV_FAST_INT_1 48 /* TGAP(adv_fast_interval2) = 100(used) ~ 150 ms = 160 * 0.625 ms */ -#define BTM_BLE_GAP_ADV_FAST_INT_2 160 +#define BTM_BLE_GAP_ADV_FAST_INT_2 160 /* Tgap(adv_slow_interval) = 1.28 s= 512 * 0.625 ms */ -#define BTM_BLE_GAP_ADV_SLOW_INT 2048 +#define BTM_BLE_GAP_ADV_SLOW_INT 2048 /* Tgap(dir_conn_adv_int_max) = 500 ms = 800 * 0.625 ms */ -#define BTM_BLE_GAP_ADV_DIR_MAX_INT 800 +#define BTM_BLE_GAP_ADV_DIR_MAX_INT 800 /* Tgap(dir_conn_adv_int_min) = 250 ms = 400 * 0.625 ms */ -#define BTM_BLE_GAP_ADV_DIR_MIN_INT 400 +#define BTM_BLE_GAP_ADV_DIR_MIN_INT 400 -#define BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS (30 * 1000) +#define BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS (30 * 1000) -#define BTM_BLE_SEC_REQ_ACT_NONE 0 +#define BTM_BLE_SEC_REQ_ACT_NONE 0 /* encrypt the link using current key or key refresh */ -#define BTM_BLE_SEC_REQ_ACT_ENCRYPT 1 -#define BTM_BLE_SEC_REQ_ACT_PAIR 2 +#define BTM_BLE_SEC_REQ_ACT_ENCRYPT 1 +#define BTM_BLE_SEC_REQ_ACT_PAIR 2 /* discard the sec request while encryption is started but not completed */ -#define BTM_BLE_SEC_REQ_ACT_DISCARD 3 +#define BTM_BLE_SEC_REQ_ACT_DISCARD 3 typedef uint8_t tBTM_BLE_SEC_REQ_ACT; -#define BLE_STATIC_PRIVATE_MSB_MASK 0x3f +#define BLE_STATIC_PRIVATE_MSB_MASK 0x3f /* most significant bit, bit7, bit6 is 01 to be resolvable random */ -#define BLE_RESOLVE_ADDR_MSB 0x40 +#define BLE_RESOLVE_ADDR_MSB 0x40 /* bit 6, and bit7 */ -#define BLE_RESOLVE_ADDR_MASK 0xc0 -#define BTM_BLE_IS_RESOLVE_BDA(x) (((x)[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB) +#define BLE_RESOLVE_ADDR_MASK 0xc0 +#define BTM_BLE_IS_RESOLVE_BDA(x) \ + (((x)[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB) -#define BLE_PUBLIC_ADDR_MSB_MASK 0xC0 +#define BLE_PUBLIC_ADDR_MSB_MASK 0xC0 /* most significant bit, bit7, bit6 is 10 to be public address*/ -#define BLE_PUBLIC_ADDR_MSB 0x80 -#define BTM_IS_PUBLIC_BDA(x) (((x)[0] & BLE_PUBLIC_ADDR_MSB_MASK) == BLE_PUBLIC_ADDR_MSB) +#define BLE_PUBLIC_ADDR_MSB 0x80 +#define BTM_IS_PUBLIC_BDA(x) \ + (((x)[0] & BLE_PUBLIC_ADDR_MSB_MASK) == BLE_PUBLIC_ADDR_MSB) /* LE scan activity bit mask, continue with LE inquiry bits */ /* selection connection is in progress */ -#define BTM_LE_SELECT_CONN_ACTIVE 0x40 +#define BTM_LE_SELECT_CONN_ACTIVE 0x40 /* observe is in progress */ -#define BTM_LE_OBSERVE_ACTIVE 0x80 +#define BTM_LE_OBSERVE_ACTIVE 0x80 /* BLE scan activity mask checking */ -#define BTM_BLE_IS_SCAN_ACTIVE(x) ((x) & BTM_BLE_SCAN_ACTIVE_MASK) -#define BTM_BLE_IS_INQ_ACTIVE(x) ((x) & BTM_BLE_INQUIRY_MASK) -#define BTM_BLE_IS_OBS_ACTIVE(x) ((x) & BTM_LE_OBSERVE_ACTIVE) -#define BTM_BLE_IS_SEL_CONN_ACTIVE(x) ((x) & BTM_LE_SELECT_CONN_ACTIVE) +#define BTM_BLE_IS_SCAN_ACTIVE(x) ((x)&BTM_BLE_SCAN_ACTIVE_MASK) +#define BTM_BLE_IS_INQ_ACTIVE(x) ((x)&BTM_BLE_INQUIRY_MASK) +#define BTM_BLE_IS_OBS_ACTIVE(x) ((x)&BTM_LE_OBSERVE_ACTIVE) +#define BTM_BLE_IS_SEL_CONN_ACTIVE(x) ((x)&BTM_LE_SELECT_CONN_ACTIVE) /* BLE ADDR type ID bit */ #define BLE_ADDR_TYPE_ID_BIT 0x02 @@ -111,247 +112,240 @@ typedef uint8_t tBTM_BLE_SEC_REQ_ACT; #define BTM_VSC_CHIP_CAPABILITY_L_VERSION 55 #define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95 -typedef struct -{ - uint16_t data_mask; - uint8_t *p_flags; - uint8_t ad_data[BTM_BLE_AD_DATA_LEN]; - uint8_t *p_pad; -}tBTM_BLE_LOCAL_ADV_DATA; - -typedef struct -{ - /* Used for determining if a response has already been received for the - * current inquiry operation. (We do not want to flood the caller with - * multiple responses from the same device. */ - uint32_t inq_count; - bool scan_rsp; - tBLE_BD_ADDR le_bda; +typedef struct { + uint16_t data_mask; + uint8_t* p_flags; + uint8_t ad_data[BTM_BLE_AD_DATA_LEN]; + uint8_t* p_pad; +} tBTM_BLE_LOCAL_ADV_DATA; + +typedef struct { + /* Used for determining if a response has already been received for the + * current inquiry operation. (We do not want to flood the caller with + * multiple responses from the same device. */ + uint32_t inq_count; + bool scan_rsp; + tBLE_BD_ADDR le_bda; } tINQ_LE_BDADDR; -#define BTM_BLE_ADV_DATA_LEN_MAX 31 -#define BTM_BLE_CACHE_ADV_DATA_MAX 62 +#define BTM_BLE_ADV_DATA_LEN_MAX 31 +#define BTM_BLE_CACHE_ADV_DATA_MAX 62 -#define BTM_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF)) +#define BTM_BLE_ISVALID_PARAM(x, min, max) \ + (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF)) /* 15 minutes minimum for random address refreshing */ -#define BTM_BLE_PRIVATE_ADDR_INT_MS (15 * 60 * 1000) - -typedef struct -{ - uint16_t discoverable_mode; - uint16_t connectable_mode; - uint32_t scan_window; - uint32_t scan_interval; - uint8_t scan_type; /* current scan type: active or passive */ - uint8_t scan_duplicate_filter; /* duplicate filter enabled for scan */ - uint16_t adv_interval_min; - uint16_t adv_interval_max; - tBTM_BLE_AFP afp; /* advertising filter policy */ - tBTM_BLE_SFP sfp; /* scanning filter policy */ - - tBLE_ADDR_TYPE adv_addr_type; - uint8_t evt_type; - uint8_t adv_mode; - tBLE_BD_ADDR direct_bda; - tBTM_BLE_EVT directed_conn; - bool fast_adv_on; - alarm_t *fast_adv_timer; - - uint8_t adv_len; - uint8_t adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX]; - - /* inquiry BD addr database */ - uint8_t num_bd_entries; - uint8_t max_bd_entries; - tBTM_BLE_LOCAL_ADV_DATA adv_data; - tBTM_BLE_ADV_CHNL_MAP adv_chnl_map; - - alarm_t *inquiry_timer; - bool scan_rsp; - uint8_t state; /* Current state that the inquiry process is in */ - int8_t tx_power; +#define BTM_BLE_PRIVATE_ADDR_INT_MS (15 * 60 * 1000) + +typedef struct { + uint16_t discoverable_mode; + uint16_t connectable_mode; + uint32_t scan_window; + uint32_t scan_interval; + uint8_t scan_type; /* current scan type: active or passive */ + uint8_t scan_duplicate_filter; /* duplicate filter enabled for scan */ + uint16_t adv_interval_min; + uint16_t adv_interval_max; + tBTM_BLE_AFP afp; /* advertising filter policy */ + tBTM_BLE_SFP sfp; /* scanning filter policy */ + + tBLE_ADDR_TYPE adv_addr_type; + uint8_t evt_type; + uint8_t adv_mode; + tBLE_BD_ADDR direct_bda; + tBTM_BLE_EVT directed_conn; + bool fast_adv_on; + alarm_t* fast_adv_timer; + + uint8_t adv_len; + uint8_t adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX]; + + /* inquiry BD addr database */ + uint8_t num_bd_entries; + uint8_t max_bd_entries; + tBTM_BLE_LOCAL_ADV_DATA adv_data; + tBTM_BLE_ADV_CHNL_MAP adv_chnl_map; + + alarm_t* inquiry_timer; + bool scan_rsp; + uint8_t state; /* Current state that the inquiry process is in */ + int8_t tx_power; } tBTM_BLE_INQ_CB; - /* random address resolving complete callback */ -typedef void (tBTM_BLE_RESOLVE_CBACK) (void * match_rec, void *p); +typedef void(tBTM_BLE_RESOLVE_CBACK)(void* match_rec, void* p); -typedef void (tBTM_BLE_ADDR_CBACK) (BD_ADDR_PTR static_random, void *p); +typedef void(tBTM_BLE_ADDR_CBACK)(BD_ADDR_PTR static_random, void* p); /* random address management control block */ -typedef struct -{ - tBLE_ADDR_TYPE own_addr_type; /* local device LE address type */ - BD_ADDR private_addr; - BD_ADDR random_bda; - bool busy; - tBTM_BLE_ADDR_CBACK *p_generate_cback; - void *p; - alarm_t *refresh_raddr_timer; +typedef struct { + tBLE_ADDR_TYPE own_addr_type; /* local device LE address type */ + BD_ADDR private_addr; + BD_ADDR random_bda; + bool busy; + tBTM_BLE_ADDR_CBACK* p_generate_cback; + void* p; + alarm_t* refresh_raddr_timer; } tBTM_LE_RANDOM_CB; -#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10 - -typedef struct -{ - uint16_t min_conn_int; - uint16_t max_conn_int; - uint16_t slave_latency; - uint16_t supervision_tout; +#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10 -}tBTM_LE_CONN_PRAMS; +typedef struct { + uint16_t min_conn_int; + uint16_t max_conn_int; + uint16_t slave_latency; + uint16_t supervision_tout; +} tBTM_LE_CONN_PRAMS; -typedef struct -{ - BD_ADDR bd_addr; - uint8_t attr; - bool is_connected; - bool in_use; -}tBTM_LE_BG_CONN_DEV; +typedef struct { + BD_ADDR bd_addr; + uint8_t attr; + bool is_connected; + bool in_use; +} tBTM_LE_BG_CONN_DEV; - /* white list using state as a bit mask */ -#define BTM_BLE_WL_IDLE 0 -#define BTM_BLE_WL_INIT 1 -#define BTM_BLE_WL_SCAN 2 -#define BTM_BLE_WL_ADV 4 +/* white list using state as a bit mask */ +#define BTM_BLE_WL_IDLE 0 +#define BTM_BLE_WL_INIT 1 +#define BTM_BLE_WL_SCAN 2 +#define BTM_BLE_WL_ADV 4 typedef uint8_t tBTM_BLE_WL_STATE; /* resolving list using state as a bit mask */ -#define BTM_BLE_RL_IDLE 0 -#define BTM_BLE_RL_INIT 1 -#define BTM_BLE_RL_SCAN 2 -#define BTM_BLE_RL_ADV 4 +#define BTM_BLE_RL_IDLE 0 +#define BTM_BLE_RL_INIT 1 +#define BTM_BLE_RL_SCAN 2 +#define BTM_BLE_RL_ADV 4 typedef uint8_t tBTM_BLE_RL_STATE; /* BLE connection state */ -#define BLE_CONN_IDLE 0 -#define BLE_DIR_CONN 1 -#define BLE_BG_CONN 2 -#define BLE_CONN_CANCEL 3 +#define BLE_CONN_IDLE 0 +#define BLE_DIR_CONN 1 +#define BLE_BG_CONN 2 +#define BLE_CONN_CANCEL 3 typedef uint8_t tBTM_BLE_CONN_ST; -typedef struct -{ - void *p_param; -}tBTM_BLE_CONN_REQ; +typedef struct { void* p_param; } tBTM_BLE_CONN_REQ; /* LE state request */ -#define BTM_BLE_STATE_INVALID 0 -#define BTM_BLE_STATE_CONN_ADV 1 -#define BTM_BLE_STATE_INIT 2 -#define BTM_BLE_STATE_MASTER 3 -#define BTM_BLE_STATE_SLAVE 4 -#define BTM_BLE_STATE_LO_DUTY_DIR_ADV 5 -#define BTM_BLE_STATE_HI_DUTY_DIR_ADV 6 -#define BTM_BLE_STATE_NON_CONN_ADV 7 -#define BTM_BLE_STATE_PASSIVE_SCAN 8 -#define BTM_BLE_STATE_ACTIVE_SCAN 9 -#define BTM_BLE_STATE_SCAN_ADV 10 -#define BTM_BLE_STATE_MAX 11 +#define BTM_BLE_STATE_INVALID 0 +#define BTM_BLE_STATE_CONN_ADV 1 +#define BTM_BLE_STATE_INIT 2 +#define BTM_BLE_STATE_MASTER 3 +#define BTM_BLE_STATE_SLAVE 4 +#define BTM_BLE_STATE_LO_DUTY_DIR_ADV 5 +#define BTM_BLE_STATE_HI_DUTY_DIR_ADV 6 +#define BTM_BLE_STATE_NON_CONN_ADV 7 +#define BTM_BLE_STATE_PASSIVE_SCAN 8 +#define BTM_BLE_STATE_ACTIVE_SCAN 9 +#define BTM_BLE_STATE_SCAN_ADV 10 +#define BTM_BLE_STATE_MAX 11 typedef uint8_t tBTM_BLE_STATE; -#define BTM_BLE_STATE_CONN_ADV_BIT 0x0001 -#define BTM_BLE_STATE_INIT_BIT 0x0002 -#define BTM_BLE_STATE_MASTER_BIT 0x0004 -#define BTM_BLE_STATE_SLAVE_BIT 0x0008 -#define BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT 0x0010 -#define BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT 0x0020 -#define BTM_BLE_STATE_NON_CONN_ADV_BIT 0x0040 -#define BTM_BLE_STATE_PASSIVE_SCAN_BIT 0x0080 -#define BTM_BLE_STATE_ACTIVE_SCAN_BIT 0x0100 -#define BTM_BLE_STATE_SCAN_ADV_BIT 0x0200 +#define BTM_BLE_STATE_CONN_ADV_BIT 0x0001 +#define BTM_BLE_STATE_INIT_BIT 0x0002 +#define BTM_BLE_STATE_MASTER_BIT 0x0004 +#define BTM_BLE_STATE_SLAVE_BIT 0x0008 +#define BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT 0x0010 +#define BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT 0x0020 +#define BTM_BLE_STATE_NON_CONN_ADV_BIT 0x0040 +#define BTM_BLE_STATE_PASSIVE_SCAN_BIT 0x0080 +#define BTM_BLE_STATE_ACTIVE_SCAN_BIT 0x0100 +#define BTM_BLE_STATE_SCAN_ADV_BIT 0x0200 typedef uint16_t tBTM_BLE_STATE_MASK; -#define BTM_BLE_STATE_ALL_MASK 0x03ff -#define BTM_BLE_STATE_ALL_ADV_MASK (BTM_BLE_STATE_CONN_ADV_BIT|BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_SCAN_ADV_BIT) -#define BTM_BLE_STATE_ALL_SCAN_MASK (BTM_BLE_STATE_PASSIVE_SCAN_BIT|BTM_BLE_STATE_ACTIVE_SCAN_BIT) -#define BTM_BLE_STATE_ALL_CONN_MASK (BTM_BLE_STATE_MASTER_BIT|BTM_BLE_STATE_SLAVE_BIT) +#define BTM_BLE_STATE_ALL_MASK 0x03ff +#define BTM_BLE_STATE_ALL_ADV_MASK \ + (BTM_BLE_STATE_CONN_ADV_BIT | BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT | \ + BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT | BTM_BLE_STATE_SCAN_ADV_BIT) +#define BTM_BLE_STATE_ALL_SCAN_MASK \ + (BTM_BLE_STATE_PASSIVE_SCAN_BIT | BTM_BLE_STATE_ACTIVE_SCAN_BIT) +#define BTM_BLE_STATE_ALL_CONN_MASK \ + (BTM_BLE_STATE_MASTER_BIT | BTM_BLE_STATE_SLAVE_BIT) #ifndef BTM_LE_RESOLVING_LIST_MAX -#define BTM_LE_RESOLVING_LIST_MAX 0x20 +#define BTM_LE_RESOLVING_LIST_MAX 0x20 #endif -typedef struct -{ - BD_ADDR *resolve_q_random_pseudo; - uint8_t *resolve_q_action; - uint8_t q_next; - uint8_t q_pending; +typedef struct { + BD_ADDR* resolve_q_random_pseudo; + uint8_t* resolve_q_action; + uint8_t q_next; + uint8_t q_pending; } tBTM_BLE_RESOLVE_Q; -typedef struct -{ - bool in_use; - bool to_add; - BD_ADDR bd_addr; - uint8_t attr; -}tBTM_BLE_WL_OP; +typedef struct { + bool in_use; + bool to_add; + BD_ADDR bd_addr; + uint8_t attr; +} tBTM_BLE_WL_OP; /* BLE privacy mode */ -#define BTM_PRIVACY_NONE 0 /* BLE no privacy */ -#define BTM_PRIVACY_1_1 1 /* BLE privacy 1.1, do not support privacy 1.0 */ -#define BTM_PRIVACY_1_2 2 /* BLE privacy 1.2 */ -#define BTM_PRIVACY_MIXED 3 /* BLE privacy mixed mode, broadcom propietary mode */ +#define BTM_PRIVACY_NONE 0 /* BLE no privacy */ +#define BTM_PRIVACY_1_1 1 /* BLE privacy 1.1, do not support privacy 1.0 */ +#define BTM_PRIVACY_1_2 2 /* BLE privacy 1.2 */ +#define BTM_PRIVACY_MIXED \ + 3 /* BLE privacy mixed mode, broadcom propietary mode */ typedef uint8_t tBTM_PRIVACY_MODE; /* data length change event callback */ -typedef void (tBTM_DATA_LENGTH_CHANGE_CBACK) (uint16_t max_tx_length, uint16_t max_rx_length); +typedef void(tBTM_DATA_LENGTH_CHANGE_CBACK)(uint16_t max_tx_length, + uint16_t max_rx_length); /* Define BLE Device Management control structure */ -typedef struct -{ - uint8_t scan_activity; /* LE scan activity mask */ +typedef struct { + uint8_t scan_activity; /* LE scan activity mask */ - /***************************************************** - ** BLE Inquiry - *****************************************************/ - tBTM_BLE_INQ_CB inq_var; + /***************************************************** + ** BLE Inquiry + *****************************************************/ + tBTM_BLE_INQ_CB inq_var; - /* observer callback and timer */ - tBTM_INQ_RESULTS_CB *p_obs_results_cb; - tBTM_CMPL_CB *p_obs_cmpl_cb; - alarm_t *observer_timer; + /* observer callback and timer */ + tBTM_INQ_RESULTS_CB* p_obs_results_cb; + tBTM_CMPL_CB* p_obs_cmpl_cb; + alarm_t* observer_timer; - /* background connection procedure cb value */ - tBTM_BLE_CONN_TYPE bg_conn_type; - uint32_t scan_int; - uint32_t scan_win; - tBTM_BLE_SEL_CBACK *p_select_cback; + /* background connection procedure cb value */ + tBTM_BLE_CONN_TYPE bg_conn_type; + uint32_t scan_int; + uint32_t scan_win; + tBTM_BLE_SEL_CBACK* p_select_cback; - /* white list information */ - uint8_t white_list_avail_size; - tBTM_BLE_WL_STATE wl_state; + /* white list information */ + uint8_t white_list_avail_size; + tBTM_BLE_WL_STATE wl_state; - fixed_queue_t *conn_pending_q; - tBTM_BLE_CONN_ST conn_state; + fixed_queue_t* conn_pending_q; + tBTM_BLE_CONN_ST conn_state; - /* random address management control block */ - tBTM_LE_RANDOM_CB addr_mgnt_cb; + /* random address management control block */ + tBTM_LE_RANDOM_CB addr_mgnt_cb; - bool enabled; + bool enabled; #if (BLE_PRIVACY_SPT == TRUE) - bool mixed_mode; /* privacy 1.2 mixed mode is on or not */ - tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */ - uint8_t resolving_list_avail_size; /* resolving list available size */ - tBTM_BLE_RESOLVE_Q resolving_list_pend_q; /* Resolving list queue */ - tBTM_BLE_RL_STATE suspended_rl_state; /* Suspended resolving list state */ - uint8_t *irk_list_mask; /* IRK list availability mask, up to max entry bits */ - tBTM_BLE_RL_STATE rl_state; /* Resolving list state */ + bool mixed_mode; /* privacy 1.2 mixed mode is on or not */ + tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */ + uint8_t resolving_list_avail_size; /* resolving list available size */ + tBTM_BLE_RESOLVE_Q resolving_list_pend_q; /* Resolving list queue */ + tBTM_BLE_RL_STATE suspended_rl_state; /* Suspended resolving list state */ + uint8_t* irk_list_mask; /* IRK list availability mask, up to max entry bits */ + tBTM_BLE_RL_STATE rl_state; /* Resolving list state */ #endif - tBTM_BLE_WL_OP wl_op_q[BTM_BLE_MAX_BG_CONN_DEV_NUM]; + tBTM_BLE_WL_OP wl_op_q[BTM_BLE_MAX_BG_CONN_DEV_NUM]; - /* current BLE link state */ - tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */ - uint8_t link_count[2]; /* total link count master and slave*/ + /* current BLE link state */ + tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */ + uint8_t link_count[2]; /* total link count master and slave*/ } tBTM_BLE_CB; #ifdef __cplusplus } #endif -#endif // BTM_BLE_INT_TYPES_H +#endif // BTM_BLE_INT_TYPES_H diff --git a/stack/btm/btm_ble_multi_adv.cc b/stack/btm/btm_ble_multi_adv.cc index 3767dd52d..407f1c74e 100644 --- a/stack/btm/btm_ble_multi_adv.cc +++ b/stack/btm/btm_ble_multi_adv.cc @@ -39,11 +39,11 @@ struct AdvertisingInstance { bool in_use; uint8_t adv_evt; BD_ADDR rpa; - alarm_t *adv_raddr_timer; + alarm_t* adv_raddr_timer; int8_t tx_power; int timeout_s; MultiAdvCb timeout_cb; - alarm_t *timeout_timer; + alarm_t* timeout_timer; AdvertisingInstance(int inst_id) : inst_id(inst_id), in_use(false), @@ -65,28 +65,28 @@ struct AdvertisingInstance { /******************************************************************************* * Externs ******************************************************************************/ -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; void DoNothing(uint8_t) {} -std::queue> *rand_gen_inst_id = nullptr; +std::queue>* rand_gen_inst_id = nullptr; /* RPA generation completion callback for each adv instance. Will continue write * the new RPA into controller. */ -void btm_ble_multi_adv_gen_rpa_cmpl(tBTM_RAND_ENC *p) { +void btm_ble_multi_adv_gen_rpa_cmpl(tBTM_RAND_ENC* p) { /* Retrieve the index of adv instance from stored Q */ base::Callback cb = rand_gen_inst_id->front(); rand_gen_inst_id->pop(); cb.Run(p); } -void btm_ble_adv_raddr_timer_timeout(void *data); +void btm_ble_adv_raddr_timer_timeout(void* data); class BleAdvertisingManagerImpl : public BleAdvertisingManager, public BleAdvertiserHciInterface::AdvertisingEventObserver { public: - BleAdvertisingManagerImpl(BleAdvertiserHciInterface *interface) { + BleAdvertisingManagerImpl(BleAdvertiserHciInterface* interface) { this->hci_interface = interface; hci_interface->ReadInstanceCount( base::Bind(&BleAdvertisingManagerImpl::ReadInstanceCountCb, @@ -104,10 +104,10 @@ class BleAdvertisingManagerImpl } } - void OnRpaGenerationComplete(uint8_t inst_id, tBTM_RAND_ENC *p) { + void OnRpaGenerationComplete(uint8_t inst_id, tBTM_RAND_ENC* p) { LOG(INFO) << "inst_id = " << +inst_id; - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; if (!p) return; p->param_buf[2] &= (~BLE_RESOLVE_ADDR_MASK); @@ -142,13 +142,13 @@ class BleAdvertisingManagerImpl rand_gen_inst_id->push( Bind(&BleAdvertisingManagerImpl::OnRpaGenerationComplete, base::Unretained(this), inst_id)); - btm_gen_resolvable_private_addr((void *)btm_ble_multi_adv_gen_rpa_cmpl); + btm_gen_resolvable_private_addr((void*)btm_ble_multi_adv_gen_rpa_cmpl); } void RegisterAdvertiser( base::Callback cb) override { - AdvertisingInstance *p_inst = &adv_inst[0]; + AdvertisingInstance* p_inst = &adv_inst[0]; for (uint8_t i = 0; i < inst_count; i++, p_inst++) { if (p_inst->in_use) continue; @@ -174,14 +174,14 @@ class BleAdvertisingManagerImpl } void StartAdvertising(uint8_t advertiser_id, MultiAdvCb cb, - tBTM_BLE_ADV_PARAMS *params, + tBTM_BLE_ADV_PARAMS* params, std::vector advertise_data, std::vector scan_response_data, int timeout_s, MultiAdvCb timeout_cb) override { /* a temporary type for holding all the data needed in callbacks below*/ struct CreatorParams { uint8_t inst_id; - BleAdvertisingManagerImpl *self; + BleAdvertisingManagerImpl* self; MultiAdvCb cb; tBTM_BLE_ADV_PARAMS params; std::vector advertise_data; @@ -241,7 +241,7 @@ class BleAdvertisingManagerImpl void EnableWithTimerCb(uint8_t inst_id, int timeout_s, MultiAdvCb timeout_cb, uint8_t status) { - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; p_inst->timeout_s = timeout_s; p_inst->timeout_cb = std::move(timeout_cb); @@ -258,7 +258,7 @@ class BleAdvertisingManagerImpl return; } - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; VLOG(1) << __func__ << "enable: " << enable; if (!p_inst->in_use) { LOG(ERROR) << "Invalid or no active instance"; @@ -282,7 +282,7 @@ class BleAdvertisingManagerImpl } } - void SetParameters(uint8_t inst_id, tBTM_BLE_ADV_PARAMS *p_params, + void SetParameters(uint8_t inst_id, tBTM_BLE_ADV_PARAMS* p_params, MultiAdvCb cb) override { VLOG(1) << __func__ << " inst_id: " << +inst_id; if (inst_id >= inst_count) { @@ -290,7 +290,7 @@ class BleAdvertisingManagerImpl return; } - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; if (!p_inst->in_use) { LOG(ERROR) << "adv instance not in use" << +inst_id; cb.Run(BTM_BLE_MULTI_ADV_FAILURE); @@ -340,7 +340,7 @@ class BleAdvertisingManagerImpl return; } - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; VLOG(1) << "is_scan_rsp = " << is_scan_rsp; if (!is_scan_rsp && p_inst->adv_evt != BTM_BLE_NON_CONNECT_EVT) { @@ -380,7 +380,7 @@ class BleAdvertisingManagerImpl } void Unregister(uint8_t inst_id) override { - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; VLOG(1) << __func__ << " inst_id: " << +inst_id; if (inst_id >= inst_count) { @@ -397,7 +397,7 @@ class BleAdvertisingManagerImpl void OnAdvertisingStateChanged(uint8_t inst_id, uint8_t reason, uint16_t conn_handle) override { - AdvertisingInstance *p_inst = &adv_inst[inst_id]; + AdvertisingInstance* p_inst = &adv_inst[inst_id]; VLOG(1) << __func__ << " inst_id: 0x" << std::hex << inst_id << ", reason: 0x" << std::hex << reason << ", conn_handle: 0x" << std::hex << conn_handle; @@ -423,22 +423,22 @@ class BleAdvertisingManagerImpl } private: - BleAdvertiserHciInterface *GetHciInterface() { return hci_interface; } + BleAdvertiserHciInterface* GetHciInterface() { return hci_interface; } - BleAdvertiserHciInterface *hci_interface = nullptr; + BleAdvertiserHciInterface* hci_interface = nullptr; std::vector adv_inst; uint8_t inst_count; }; namespace { -BleAdvertisingManager *instance; +BleAdvertisingManager* instance; } -void BleAdvertisingManager::Initialize(BleAdvertiserHciInterface *interface) { +void BleAdvertisingManager::Initialize(BleAdvertiserHciInterface* interface) { instance = new BleAdvertisingManagerImpl(interface); } -BleAdvertisingManager *BleAdvertisingManager::Get() { +BleAdvertisingManager* BleAdvertisingManager::Get() { CHECK(instance); return instance; }; @@ -448,9 +448,9 @@ void BleAdvertisingManager::CleanUp() { instance = nullptr; }; -void btm_ble_adv_raddr_timer_timeout(void *data) { - ((BleAdvertisingManagerImpl *)BleAdvertisingManager::Get()) - ->ConfigureRpa(((AdvertisingInstance *)data)->inst_id); +void btm_ble_adv_raddr_timer_timeout(void* data) { + ((BleAdvertisingManagerImpl*)BleAdvertisingManager::Get()) + ->ConfigureRpa(((AdvertisingInstance*)data)->inst_id); } /******************************************************************************* @@ -468,7 +468,7 @@ void btm_ble_multi_adv_init() { BleAdvertiserHciInterface::Initialize(); BleAdvertisingManager::Initialize(BleAdvertiserHciInterface::Get()); BleAdvertiserHciInterface::Get()->SetAdvertisingEventObserver( - (BleAdvertisingManagerImpl *)BleAdvertisingManager::Get()); + (BleAdvertisingManagerImpl*)BleAdvertisingManager::Get()); } /******************************************************************************* diff --git a/stack/btm/btm_ble_privacy.cc b/stack/btm/btm_ble_privacy.cc index 7ead70a76..1d735cd14 100644 --- a/stack/btm/btm_ble_privacy.cc +++ b/stack/btm/btm_ble_privacy.cc @@ -26,26 +26,26 @@ #if (BLE_PRIVACY_SPT == TRUE) #include "bt_types.h" -#include "hcimsgs.h" -#include "btu.h" -#include "vendor_hcidefs.h" #include "btm_int.h" +#include "btu.h" #include "device/include/controller.h" +#include "hcimsgs.h" +#include "vendor_hcidefs.h" /* RPA offload VSC specifics */ -#define BTM_BLE_META_IRK_ENABLE 0x01 -#define BTM_BLE_META_ADD_IRK_ENTRY 0x02 -#define BTM_BLE_META_REMOVE_IRK_ENTRY 0x03 -#define BTM_BLE_META_CLEAR_IRK_LIST 0x04 -#define BTM_BLE_META_READ_IRK_ENTRY 0x05 -#define BTM_BLE_META_CS_RESOLVE_ADDR 0x00000001 -#define BTM_BLE_IRK_ENABLE_LEN 2 - -#define BTM_BLE_META_ADD_IRK_LEN 24 -#define BTM_BLE_META_REMOVE_IRK_LEN 8 -#define BTM_BLE_META_CLEAR_IRK_LEN 1 -#define BTM_BLE_META_READ_IRK_LEN 2 -#define BTM_BLE_META_ADD_WL_ATTR_LEN 9 +#define BTM_BLE_META_IRK_ENABLE 0x01 +#define BTM_BLE_META_ADD_IRK_ENTRY 0x02 +#define BTM_BLE_META_REMOVE_IRK_ENTRY 0x03 +#define BTM_BLE_META_CLEAR_IRK_LIST 0x04 +#define BTM_BLE_META_READ_IRK_ENTRY 0x05 +#define BTM_BLE_META_CS_RESOLVE_ADDR 0x00000001 +#define BTM_BLE_IRK_ENABLE_LEN 2 + +#define BTM_BLE_META_ADD_IRK_LEN 24 +#define BTM_BLE_META_REMOVE_IRK_LEN 8 +#define BTM_BLE_META_CLEAR_IRK_LEN 1 +#define BTM_BLE_META_READ_IRK_LEN 2 +#define BTM_BLE_META_ADD_WL_ATTR_LEN 9 /******************************************************************************* * Functions implemented controller based privacy using Resolving List @@ -62,14 +62,13 @@ * Returns void * ******************************************************************************/ -void btm_ble_enq_resolving_list_pending(BD_ADDR pseudo_bda, uint8_t op_code) -{ - tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; - - memcpy(p_q->resolve_q_random_pseudo[p_q->q_next], pseudo_bda, BD_ADDR_LEN); - p_q->resolve_q_action[p_q->q_next] = op_code; - p_q->q_next ++; - p_q->q_next %= controller_get_interface()->get_ble_resolving_list_max_size(); +void btm_ble_enq_resolving_list_pending(BD_ADDR pseudo_bda, uint8_t op_code) { + tBTM_BLE_RESOLVE_Q* p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; + + memcpy(p_q->resolve_q_random_pseudo[p_q->q_next], pseudo_bda, BD_ADDR_LEN); + p_q->resolve_q_action[p_q->q_next] = op_code; + p_q->q_next++; + p_q->q_next %= controller_get_interface()->get_ble_resolving_list_max_size(); } /******************************************************************************* @@ -84,20 +83,20 @@ void btm_ble_enq_resolving_list_pending(BD_ADDR pseudo_bda, uint8_t op_code) * Returns void * ******************************************************************************/ -bool btm_ble_brcm_find_resolving_pending_entry(BD_ADDR pseudo_addr, uint8_t action) -{ - tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; - - for (uint8_t i = p_q->q_pending; i != p_q->q_next;) - { - if (memcmp(p_q->resolve_q_random_pseudo[i], pseudo_addr, BD_ADDR_LEN) == 0 && - action == p_q->resolve_q_action[i]) - return true; - - i ++; - i %= controller_get_interface()->get_ble_resolving_list_max_size(); - } - return false; +bool btm_ble_brcm_find_resolving_pending_entry(BD_ADDR pseudo_addr, + uint8_t action) { + tBTM_BLE_RESOLVE_Q* p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; + + for (uint8_t i = p_q->q_pending; i != p_q->q_next;) { + if (memcmp(p_q->resolve_q_random_pseudo[i], pseudo_addr, BD_ADDR_LEN) == + 0 && + action == p_q->resolve_q_action[i]) + return true; + + i++; + i %= controller_get_interface()->get_ble_resolving_list_max_size(); + } + return false; } /******************************************************************************* @@ -112,20 +111,20 @@ bool btm_ble_brcm_find_resolving_pending_entry(BD_ADDR pseudo_addr, uint8_t a * Returns void * ******************************************************************************/ -bool btm_ble_deq_resolving_pending(BD_ADDR pseudo_addr) -{ - tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; - - if (p_q->q_next != p_q->q_pending) - { - memcpy(pseudo_addr, p_q->resolve_q_random_pseudo[p_q->q_pending], BD_ADDR_LEN); - memset(p_q->resolve_q_random_pseudo[p_q->q_pending], 0, BD_ADDR_LEN); - p_q->q_pending ++; - p_q->q_pending %= controller_get_interface()->get_ble_resolving_list_max_size(); - return true; - } +bool btm_ble_deq_resolving_pending(BD_ADDR pseudo_addr) { + tBTM_BLE_RESOLVE_Q* p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; + + if (p_q->q_next != p_q->q_pending) { + memcpy(pseudo_addr, p_q->resolve_q_random_pseudo[p_q->q_pending], + BD_ADDR_LEN); + memset(p_q->resolve_q_random_pseudo[p_q->q_pending], 0, BD_ADDR_LEN); + p_q->q_pending++; + p_q->q_pending %= + controller_get_interface()->get_ble_resolving_list_max_size(); + return true; + } - return false; + return false; } /******************************************************************************* @@ -137,17 +136,15 @@ bool btm_ble_deq_resolving_pending(BD_ADDR pseudo_addr) * Returns none * ******************************************************************************/ -void btm_ble_clear_irk_index(uint8_t index) -{ - uint8_t byte; - uint8_t bit; - - if (index < controller_get_interface()->get_ble_resolving_list_max_size()) - { - byte = index / 8; - bit = index % 8; - btm_cb.ble_ctr_cb.irk_list_mask[byte] &= (~(1 << bit)); - } +void btm_ble_clear_irk_index(uint8_t index) { + uint8_t byte; + uint8_t bit; + + if (index < controller_get_interface()->get_ble_resolving_list_max_size()) { + byte = index / 8; + bit = index % 8; + btm_cb.ble_ctr_cb.irk_list_mask[byte] &= (~(1 << bit)); + } } /******************************************************************************* @@ -159,27 +156,24 @@ void btm_ble_clear_irk_index(uint8_t index) * Returns index from 0 ~ max (127 default) * ******************************************************************************/ -uint8_t btm_ble_find_irk_index(void) -{ - uint8_t i = 0; - uint8_t byte; - uint8_t bit; - - while (i < controller_get_interface()->get_ble_resolving_list_max_size()) - { - byte = i / 8; - bit = i % 8; - - if ((btm_cb.ble_ctr_cb.irk_list_mask[byte] & (1 << bit)) == 0) - { - btm_cb.ble_ctr_cb.irk_list_mask[byte] |= (1 << bit); - return i; - } - i++; +uint8_t btm_ble_find_irk_index(void) { + uint8_t i = 0; + uint8_t byte; + uint8_t bit; + + while (i < controller_get_interface()->get_ble_resolving_list_max_size()) { + byte = i / 8; + bit = i % 8; + + if ((btm_cb.ble_ctr_cb.irk_list_mask[byte] & (1 << bit)) == 0) { + btm_cb.ble_ctr_cb.irk_list_mask[byte] |= (1 << bit); + return i; } + i++; + } - BTM_TRACE_ERROR ("%s failed, list full", __func__); - return i; + BTM_TRACE_ERROR("%s failed, list full", __func__); + return i; } /******************************************************************************* @@ -191,35 +185,28 @@ uint8_t btm_ble_find_irk_index(void) * Returns void * ******************************************************************************/ -void btm_ble_update_resolving_list(BD_ADDR pseudo_bda, bool add) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(pseudo_bda); - if (p_dev_rec == NULL) - return; - - if (add) - { - p_dev_rec->ble.in_controller_list |= BTM_RESOLVING_LIST_BIT; - if (!controller_get_interface()->supports_ble_privacy()) - p_dev_rec->ble.resolving_list_index = btm_ble_find_irk_index(); - } - else - { - p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; - if (!controller_get_interface()->supports_ble_privacy()) - { - /* clear IRK list index mask */ - btm_ble_clear_irk_index(p_dev_rec->ble.resolving_list_index); - p_dev_rec->ble.resolving_list_index = 0; - } +void btm_ble_update_resolving_list(BD_ADDR pseudo_bda, bool add) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(pseudo_bda); + if (p_dev_rec == NULL) return; + + if (add) { + p_dev_rec->ble.in_controller_list |= BTM_RESOLVING_LIST_BIT; + if (!controller_get_interface()->supports_ble_privacy()) + p_dev_rec->ble.resolving_list_index = btm_ble_find_irk_index(); + } else { + p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; + if (!controller_get_interface()->supports_ble_privacy()) { + /* clear IRK list index mask */ + btm_ble_clear_irk_index(p_dev_rec->ble.resolving_list_index); + p_dev_rec->ble.resolving_list_index = 0; } + } } -bool clear_resolving_list_bit(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; - return true; +bool clear_resolving_list_bit(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; + return true; } /******************************************************************************* @@ -232,40 +219,38 @@ bool clear_resolving_list_bit(void *data, void *context) * Returns void * ******************************************************************************/ -void btm_ble_clear_resolving_list_complete(uint8_t *p, uint16_t evt_len) -{ - uint8_t status = 0; - STREAM_TO_UINT8(status, p); - - BTM_TRACE_DEBUG("%s status=%d", __func__, status); - - if (status == HCI_SUCCESS) - { - if (evt_len >= 3) - { - /* VSC complete has one extra byte for op code and list size, skip it here */ - p ++; - - /* updated the available list size, and current list size */ - uint8_t irk_list_sz_max = 0; - STREAM_TO_UINT8(irk_list_sz_max, p); - - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) - btm_ble_resolving_list_init(irk_list_sz_max); - - uint8_t irk_mask_size = (irk_list_sz_max % 8) ? - (irk_list_sz_max / 8 + 1) : (irk_list_sz_max / 8); - memset(btm_cb.ble_ctr_cb.irk_list_mask, 0, irk_mask_size); - } +void btm_ble_clear_resolving_list_complete(uint8_t* p, uint16_t evt_len) { + uint8_t status = 0; + STREAM_TO_UINT8(status, p); + + BTM_TRACE_DEBUG("%s status=%d", __func__, status); + + if (status == HCI_SUCCESS) { + if (evt_len >= 3) { + /* VSC complete has one extra byte for op code and list size, skip it here + */ + p++; - btm_cb.ble_ctr_cb.resolving_list_avail_size = - controller_get_interface()->get_ble_resolving_list_max_size(); + /* updated the available list size, and current list size */ + uint8_t irk_list_sz_max = 0; + STREAM_TO_UINT8(irk_list_sz_max, p); - BTM_TRACE_DEBUG("%s resolving_list_avail_size=%d", - __func__, btm_cb.ble_ctr_cb.resolving_list_avail_size); + if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) + btm_ble_resolving_list_init(irk_list_sz_max); - list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); + uint8_t irk_mask_size = (irk_list_sz_max % 8) ? (irk_list_sz_max / 8 + 1) + : (irk_list_sz_max / 8); + memset(btm_cb.ble_ctr_cb.irk_list_mask, 0, irk_mask_size); } + + btm_cb.ble_ctr_cb.resolving_list_avail_size = + controller_get_interface()->get_ble_resolving_list_max_size(); + + BTM_TRACE_DEBUG("%s resolving_list_avail_size=%d", __func__, + btm_cb.ble_ctr_cb.resolving_list_avail_size); + + list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); + } } /******************************************************************************* @@ -278,37 +263,32 @@ void btm_ble_clear_resolving_list_complete(uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -void btm_ble_add_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) -{ - uint8_t status; - STREAM_TO_UINT8(status, p); - - BTM_TRACE_DEBUG("%s status = %d", __func__, status); - - BD_ADDR pseudo_bda; - if (!btm_ble_deq_resolving_pending(pseudo_bda)) - { - BTM_TRACE_DEBUG("no pending resolving list operation"); - return; - } - - if (status == HCI_SUCCESS) - { - /* privacy 1.2 command complete does not have these extra byte */ - if (evt_len > 2) - { - /* VSC complete has one extra byte for op code, skip it here */ - p ++; - STREAM_TO_UINT8(btm_cb.ble_ctr_cb.resolving_list_avail_size, p); - } - else - btm_cb.ble_ctr_cb.resolving_list_avail_size --; - } - else if (status == HCI_ERR_MEMORY_FULL) /* BT_ERROR_CODE_MEMORY_CAPACITY_EXCEEDED */ - { - btm_cb.ble_ctr_cb.resolving_list_avail_size = 0; - BTM_TRACE_DEBUG("%s Resolving list Full ", __func__); - } +void btm_ble_add_resolving_list_entry_complete(uint8_t* p, uint16_t evt_len) { + uint8_t status; + STREAM_TO_UINT8(status, p); + + BTM_TRACE_DEBUG("%s status = %d", __func__, status); + + BD_ADDR pseudo_bda; + if (!btm_ble_deq_resolving_pending(pseudo_bda)) { + BTM_TRACE_DEBUG("no pending resolving list operation"); + return; + } + + if (status == HCI_SUCCESS) { + /* privacy 1.2 command complete does not have these extra byte */ + if (evt_len > 2) { + /* VSC complete has one extra byte for op code, skip it here */ + p++; + STREAM_TO_UINT8(btm_cb.ble_ctr_cb.resolving_list_avail_size, p); + } else + btm_cb.ble_ctr_cb.resolving_list_avail_size--; + } else if (status == + HCI_ERR_MEMORY_FULL) /* BT_ERROR_CODE_MEMORY_CAPACITY_EXCEEDED */ + { + btm_cb.ble_ctr_cb.resolving_list_avail_size = 0; + BTM_TRACE_DEBUG("%s Resolving list Full ", __func__); + } } /******************************************************************************* @@ -321,32 +301,28 @@ void btm_ble_add_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -void btm_ble_remove_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) -{ - BD_ADDR pseudo_bda; - uint8_t status; - - STREAM_TO_UINT8(status, p); - - BTM_TRACE_DEBUG("%s status = %d", __func__, status); - - if (!btm_ble_deq_resolving_pending(pseudo_bda)) - { - BTM_TRACE_ERROR("%s no pending resolving list operation", __func__); - return; - } - - if (status == HCI_SUCCESS) - { - /* proprietary: spec does not have these extra bytes */ - if (evt_len > 2) - { - p ++; /* skip opcode */ - STREAM_TO_UINT8(btm_cb.ble_ctr_cb.resolving_list_avail_size, p); - } - else - btm_cb.ble_ctr_cb.resolving_list_avail_size++; - } +void btm_ble_remove_resolving_list_entry_complete(uint8_t* p, + uint16_t evt_len) { + BD_ADDR pseudo_bda; + uint8_t status; + + STREAM_TO_UINT8(status, p); + + BTM_TRACE_DEBUG("%s status = %d", __func__, status); + + if (!btm_ble_deq_resolving_pending(pseudo_bda)) { + BTM_TRACE_ERROR("%s no pending resolving list operation", __func__); + return; + } + + if (status == HCI_SUCCESS) { + /* proprietary: spec does not have these extra bytes */ + if (evt_len > 2) { + p++; /* skip opcode */ + STREAM_TO_UINT8(btm_cb.ble_ctr_cb.resolving_list_avail_size, p); + } else + btm_cb.ble_ctr_cb.resolving_list_avail_size++; + } } /******************************************************************************* @@ -359,39 +335,33 @@ void btm_ble_remove_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -void btm_ble_read_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) -{ - uint8_t status, rra_type = BTM_BLE_ADDR_PSEUDO; - BD_ADDR rra, pseudo_bda; +void btm_ble_read_resolving_list_entry_complete(uint8_t* p, uint16_t evt_len) { + uint8_t status, rra_type = BTM_BLE_ADDR_PSEUDO; + BD_ADDR rra, pseudo_bda; - STREAM_TO_UINT8 (status, p); + STREAM_TO_UINT8(status, p); - BTM_TRACE_DEBUG("%s status = %d", __func__, status); + BTM_TRACE_DEBUG("%s status = %d", __func__, status); - if (!btm_ble_deq_resolving_pending(pseudo_bda)) - { - BTM_TRACE_ERROR("no pending resolving list operation"); - return; - } + if (!btm_ble_deq_resolving_pending(pseudo_bda)) { + BTM_TRACE_ERROR("no pending resolving list operation"); + return; + } - if (status == HCI_SUCCESS) - { - /* proprietary spec has extra bytes */ - if (evt_len > 8) - { - /* skip subcode, index, IRK value, address type, identity addr type */ - p += (2 + 16 + 1 + 6); - STREAM_TO_BDADDR(rra, p); - - BTM_TRACE_ERROR("%s peer_addr: %02x:%02x:%02x:%02x:%02x:%02x", - __func__, rra[0], rra[1], rra[2], rra[3], rra[4], rra[5]); - } - else - { - STREAM_TO_BDADDR(rra, p); - } - btm_ble_refresh_peer_resolvable_private_addr(pseudo_bda, rra, rra_type); - } + if (status == HCI_SUCCESS) { + /* proprietary spec has extra bytes */ + if (evt_len > 8) { + /* skip subcode, index, IRK value, address type, identity addr type */ + p += (2 + 16 + 1 + 6); + STREAM_TO_BDADDR(rra, p); + + BTM_TRACE_ERROR("%s peer_addr: %02x:%02x:%02x:%02x:%02x:%02x", __func__, + rra[0], rra[1], rra[2], rra[3], rra[4], rra[5]); + } else { + STREAM_TO_BDADDR(rra, p); + } + btm_ble_refresh_peer_resolvable_private_addr(pseudo_bda, rra, rra_type); + } } /******************************************************************************* VSC that implement controller based privacy @@ -407,35 +377,25 @@ void btm_ble_read_resolving_list_entry_complete(uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -void btm_ble_resolving_list_vsc_op_cmpl (tBTM_VSC_CMPL *p_params) -{ - uint8_t *p = p_params->p_param_buf, op_subcode; - uint16_t evt_len = p_params->param_len; - - op_subcode = *(p + 1); - - BTM_TRACE_DEBUG("%s op_subcode = %d", __func__, op_subcode); - - if (op_subcode == BTM_BLE_META_CLEAR_IRK_LIST) - { - btm_ble_clear_resolving_list_complete(p, evt_len); - } - else if (op_subcode == BTM_BLE_META_ADD_IRK_ENTRY) - { - btm_ble_add_resolving_list_entry_complete(p, evt_len); - } - else if (op_subcode == BTM_BLE_META_REMOVE_IRK_ENTRY) - { - btm_ble_remove_resolving_list_entry_complete(p, evt_len); - } - else if (op_subcode == BTM_BLE_META_READ_IRK_ENTRY) - { - btm_ble_read_resolving_list_entry_complete(p, evt_len); - } - else if (op_subcode == BTM_BLE_META_IRK_ENABLE) - { - /* RPA offloading enable/disabled */ - } +void btm_ble_resolving_list_vsc_op_cmpl(tBTM_VSC_CMPL* p_params) { + uint8_t *p = p_params->p_param_buf, op_subcode; + uint16_t evt_len = p_params->param_len; + + op_subcode = *(p + 1); + + BTM_TRACE_DEBUG("%s op_subcode = %d", __func__, op_subcode); + + if (op_subcode == BTM_BLE_META_CLEAR_IRK_LIST) { + btm_ble_clear_resolving_list_complete(p, evt_len); + } else if (op_subcode == BTM_BLE_META_ADD_IRK_ENTRY) { + btm_ble_add_resolving_list_entry_complete(p, evt_len); + } else if (op_subcode == BTM_BLE_META_REMOVE_IRK_ENTRY) { + btm_ble_remove_resolving_list_entry_complete(p, evt_len); + } else if (op_subcode == BTM_BLE_META_READ_IRK_ENTRY) { + btm_ble_read_resolving_list_entry_complete(p, evt_len); + } else if (op_subcode == BTM_BLE_META_IRK_ENABLE) { + /* RPA offloading enable/disabled */ + } } /******************************************************************************* @@ -450,34 +410,30 @@ void btm_ble_resolving_list_vsc_op_cmpl (tBTM_VSC_CMPL *p_params) * Returns status * ******************************************************************************/ -tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec) -{ - /* if controller does not support RPA offloading or privacy 1.2, skip */ - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) - return BTM_WRONG_MODE; - - if (controller_get_interface()->supports_ble_privacy()) - { - btsnd_hcic_ble_rm_device_resolving_list(p_dev_rec->ble.static_addr_type, - p_dev_rec->ble.static_addr); - } - else - { - uint8_t param[20]= {0}; - uint8_t *p = param; - - UINT8_TO_STREAM(p, BTM_BLE_META_REMOVE_IRK_ENTRY); - UINT8_TO_STREAM(p, p_dev_rec->ble.static_addr_type); - BDADDR_TO_STREAM(p, p_dev_rec->ble.static_addr); - - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, - BTM_BLE_META_REMOVE_IRK_LEN, - param, - btm_ble_resolving_list_vsc_op_cmpl); - } - - btm_ble_enq_resolving_list_pending( p_dev_rec->bd_addr, BTM_BLE_META_REMOVE_IRK_ENTRY); - return BTM_CMD_STARTED; +tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC* p_dev_rec) { + /* if controller does not support RPA offloading or privacy 1.2, skip */ + if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) + return BTM_WRONG_MODE; + + if (controller_get_interface()->supports_ble_privacy()) { + btsnd_hcic_ble_rm_device_resolving_list(p_dev_rec->ble.static_addr_type, + p_dev_rec->ble.static_addr); + } else { + uint8_t param[20] = {0}; + uint8_t* p = param; + + UINT8_TO_STREAM(p, BTM_BLE_META_REMOVE_IRK_ENTRY); + UINT8_TO_STREAM(p, p_dev_rec->ble.static_addr_type); + BDADDR_TO_STREAM(p, p_dev_rec->ble.static_addr); + + BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, + BTM_BLE_META_REMOVE_IRK_LEN, param, + btm_ble_resolving_list_vsc_op_cmpl); + } + + btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, + BTM_BLE_META_REMOVE_IRK_ENTRY); + return BTM_CMD_STARTED; } /******************************************************************************* @@ -489,24 +445,18 @@ tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec) * Parameters None. * ******************************************************************************/ -void btm_ble_clear_resolving_list(void) -{ - - if (controller_get_interface()->supports_ble_privacy()) - { - btsnd_hcic_ble_clear_resolving_list(); - } - else - { - uint8_t param[20] = {0}; - uint8_t *p = param; - - UINT8_TO_STREAM(p, BTM_BLE_META_CLEAR_IRK_LIST); - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, - BTM_BLE_META_CLEAR_IRK_LEN, - param, - btm_ble_resolving_list_vsc_op_cmpl); - } +void btm_ble_clear_resolving_list(void) { + if (controller_get_interface()->supports_ble_privacy()) { + btsnd_hcic_ble_clear_resolving_list(); + } else { + uint8_t param[20] = {0}; + uint8_t* p = param; + + UINT8_TO_STREAM(p, BTM_BLE_META_CLEAR_IRK_LIST); + BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, + BTM_BLE_META_CLEAR_IRK_LEN, param, + btm_ble_resolving_list_vsc_op_cmpl); + } } /******************************************************************************* @@ -520,36 +470,29 @@ void btm_ble_clear_resolving_list(void) * Returns status * ******************************************************************************/ -tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec) -{ - if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT)) - return BTM_WRONG_MODE; - - if (controller_get_interface()->supports_ble_privacy()) - { - btsnd_hcic_ble_read_resolvable_addr_peer(p_dev_rec->ble.static_addr_type, - p_dev_rec->ble.static_addr); - } - else - { - uint8_t param[20] = {0}; - uint8_t *p = param; +tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC* p_dev_rec) { + if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT)) + return BTM_WRONG_MODE; - UINT8_TO_STREAM(p, BTM_BLE_META_READ_IRK_ENTRY); - UINT8_TO_STREAM(p, p_dev_rec->ble.resolving_list_index); + if (controller_get_interface()->supports_ble_privacy()) { + btsnd_hcic_ble_read_resolvable_addr_peer(p_dev_rec->ble.static_addr_type, + p_dev_rec->ble.static_addr); + } else { + uint8_t param[20] = {0}; + uint8_t* p = param; - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, - BTM_BLE_META_READ_IRK_LEN, - param, - btm_ble_resolving_list_vsc_op_cmpl); - } + UINT8_TO_STREAM(p, BTM_BLE_META_READ_IRK_ENTRY); + UINT8_TO_STREAM(p, p_dev_rec->ble.resolving_list_index); - btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, - BTM_BLE_META_READ_IRK_ENTRY); + BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_META_READ_IRK_LEN, + param, btm_ble_resolving_list_vsc_op_cmpl); + } - return BTM_CMD_STARTED; -} + btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, + BTM_BLE_META_READ_IRK_ENTRY); + return BTM_CMD_STARTED; +} /******************************************************************************* * @@ -564,41 +507,36 @@ tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if suspended; false otherwise * ******************************************************************************/ -bool btm_ble_suspend_resolving_list_activity(void) -{ - tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; - - /* if resolving list is not enabled, do not need to terminate any activity */ - /* if asking for stop all activity */ - /* if already suspended */ - if (p_ble_cb->suspended_rl_state != BTM_BLE_RL_IDLE) - return true; - - /* direct connection active, wait until it completed */ - if (btm_ble_get_conn_st() == BLE_DIR_CONN) - { - BTM_TRACE_ERROR("resolving list can not be edited, EnQ now"); - return false; - } +bool btm_ble_suspend_resolving_list_activity(void) { + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; - p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE; + /* if resolving list is not enabled, do not need to terminate any activity */ + /* if asking for stop all activity */ + /* if already suspended */ + if (p_ble_cb->suspended_rl_state != BTM_BLE_RL_IDLE) return true; - if (p_ble_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE) - { - btm_ble_stop_adv(); - p_ble_cb->suspended_rl_state |= BTM_BLE_RL_ADV; - } + /* direct connection active, wait until it completed */ + if (btm_ble_get_conn_st() == BLE_DIR_CONN) { + BTM_TRACE_ERROR("resolving list can not be edited, EnQ now"); + return false; + } - if (BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) - { - btm_ble_stop_scan(); - p_ble_cb->suspended_rl_state |= BTM_BLE_RL_SCAN; - } + p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE; - if (btm_ble_suspend_bg_conn()) - p_ble_cb->suspended_rl_state |= BTM_BLE_RL_INIT; + if (p_ble_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE) { + btm_ble_stop_adv(); + p_ble_cb->suspended_rl_state |= BTM_BLE_RL_ADV; + } - return true; + if (BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) { + btm_ble_stop_scan(); + p_ble_cb->suspended_rl_state |= BTM_BLE_RL_SCAN; + } + + if (btm_ble_suspend_bg_conn()) + p_ble_cb->suspended_rl_state |= BTM_BLE_RL_INIT; + + return true; } /******************************************************************************* @@ -612,20 +550,16 @@ bool btm_ble_suspend_resolving_list_activity(void) * Returns none * ******************************************************************************/ -void btm_ble_resume_resolving_list_activity(void) -{ - tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; +void btm_ble_resume_resolving_list_activity(void) { + tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; - if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_ADV) - btm_ble_start_adv(); + if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_ADV) btm_ble_start_adv(); - if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_SCAN) - btm_ble_start_scan(); + if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_SCAN) btm_ble_start_scan(); - if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_INIT) - btm_ble_resume_bg_conn(); + if (p_ble_cb->suspended_rl_state & BTM_BLE_RL_INIT) btm_ble_resume_bg_conn(); - p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE; + p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE; } /******************************************************************************* @@ -638,19 +572,18 @@ void btm_ble_resume_resolving_list_activity(void) * Parameters enable: enable or disable the RRA offloading feature * ******************************************************************************/ -void btm_ble_vendor_enable_irk_feature(bool enable) -{ - uint8_t param[20], *p; +void btm_ble_vendor_enable_irk_feature(bool enable) { + uint8_t param[20], *p; - p = param; - memset(param, 0, 20); + p = param; + memset(param, 0, 20); - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_IRK_ENABLE); - UINT8_TO_STREAM(p, enable ? 0x01 : 0x00); + /* select feature based on control block settings */ + UINT8_TO_STREAM(p, BTM_BLE_META_IRK_ENABLE); + UINT8_TO_STREAM(p, enable ? 0x01 : 0x00); - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_IRK_ENABLE_LEN, - param, btm_ble_resolving_list_vsc_op_cmpl); + BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_IRK_ENABLE_LEN, + param, btm_ble_resolving_list_vsc_op_cmpl); } /******************************************************************************* @@ -662,17 +595,15 @@ void btm_ble_vendor_enable_irk_feature(bool enable) * Returns none * ******************************************************************************/ -bool btm_ble_exe_disable_resolving_list(void) -{ - if (!btm_ble_suspend_resolving_list_activity()) - return false; +bool btm_ble_exe_disable_resolving_list(void) { + if (!btm_ble_suspend_resolving_list_activity()) return false; - if (!controller_get_interface()->supports_ble_privacy()) - btm_ble_vendor_enable_irk_feature(false); - else - btsnd_hcic_ble_set_addr_resolution_enable(false); + if (!controller_get_interface()->supports_ble_privacy()) + btm_ble_vendor_enable_irk_feature(false); + else + btsnd_hcic_ble_set_addr_resolution_enable(false); - return true; + return true; } /******************************************************************************* @@ -684,15 +615,13 @@ bool btm_ble_exe_disable_resolving_list(void) * Returns none * ******************************************************************************/ -void btm_ble_exe_enable_resolving_list(void) -{ - if (!btm_ble_suspend_resolving_list_activity()) - return; +void btm_ble_exe_enable_resolving_list(void) { + if (!btm_ble_suspend_resolving_list_activity()) return; - if (!controller_get_interface()->supports_ble_privacy()) - btm_ble_vendor_enable_irk_feature(true); - else - btsnd_hcic_ble_set_addr_resolution_enable(true); + if (!controller_get_interface()->supports_ble_privacy()) + btm_ble_vendor_enable_irk_feature(true); + else + btsnd_hcic_ble_set_addr_resolution_enable(true); } /******************************************************************************* @@ -704,30 +633,26 @@ void btm_ble_exe_enable_resolving_list(void) * Returns none * ******************************************************************************/ -bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume ) -{ - uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state; +bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume) { + uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state; - /* if controller does not support RPA offloading or privacy 1.2, skip */ - if (controller_get_interface()->get_ble_resolving_list_max_size()== 0) - return false; + /* if controller does not support RPA offloading or privacy 1.2, skip */ + if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) + return false; - btm_cb.ble_ctr_cb.rl_state &= ~rl_mask; + btm_cb.ble_ctr_cb.rl_state &= ~rl_mask; - if (rl_state != BTM_BLE_RL_IDLE && btm_cb.ble_ctr_cb.rl_state == BTM_BLE_RL_IDLE) - { - if (btm_ble_exe_disable_resolving_list()) - { - if (to_resume) - btm_ble_resume_resolving_list_activity(); + if (rl_state != BTM_BLE_RL_IDLE && + btm_cb.ble_ctr_cb.rl_state == BTM_BLE_RL_IDLE) { + if (btm_ble_exe_disable_resolving_list()) { + if (to_resume) btm_ble_resume_resolving_list_activity(); - return true; - } - else - return false; - } + return true; + } else + return false; + } - return true; + return true; } /******************************************************************************* @@ -742,94 +667,81 @@ bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume ) * Returns true if device added, otherwise falase. * ******************************************************************************/ -bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) -{ - bool rt = false; - uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state; - - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, - btm_cb.ble_ctr_cb.privacy_mode); - - /* if controller does not support RPA offloading or privacy 1.2, skip */ - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) - return false; - - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", - __func__, btm_cb.ble_ctr_cb.privacy_mode); - - /* only add RPA enabled device into resolving list */ - if (p_dev_rec != NULL && /* RPA is being used and PID is known */ - ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 || - (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0)) - { - if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && - btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr, - BTM_BLE_META_ADD_IRK_ENTRY) == false) - { - if (btm_cb.ble_ctr_cb.resolving_list_avail_size > 0) - { - if (rl_mask) - { - if (!btm_ble_disable_resolving_list (rl_mask, false)) - return false; - } - - btm_ble_update_resolving_list(p_dev_rec->bd_addr, true); - if (controller_get_interface()->supports_ble_privacy()) - { - BD_ADDR dummy_bda = {0}; - uint8_t *peer_irk = p_dev_rec->ble.keys.irk; - uint8_t *local_irk = btm_cb.devcb.id_keys.irk; - - if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) == 0) - { - memcpy(p_dev_rec->ble.static_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type; - } - - BTM_TRACE_DEBUG("%s:adding device to controller resolving list", __func__); - // use identical IRK for now - btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type, - p_dev_rec->ble.static_addr, peer_irk, local_irk); - } - else - { - uint8_t param[40] = {0}; - uint8_t *p = param; - - UINT8_TO_STREAM(p, BTM_BLE_META_ADD_IRK_ENTRY); - ARRAY_TO_STREAM(p, p_dev_rec->ble.keys.irk, BT_OCTET16_LEN); - UINT8_TO_STREAM(p, p_dev_rec->ble.static_addr_type); - BDADDR_TO_STREAM(p,p_dev_rec->ble.static_addr); - - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, - BTM_BLE_META_ADD_IRK_LEN, - param, - btm_ble_resolving_list_vsc_op_cmpl); - } - - rt = true; - btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, - BTM_BLE_META_ADD_IRK_ENTRY); - - /* if resolving list has been turned on, re-enable it */ - if (rl_mask) - btm_ble_enable_resolving_list(rl_mask); - else - btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); - } +bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) { + bool rt = false; + uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state; + + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, + btm_cb.ble_ctr_cb.privacy_mode); + + /* if controller does not support RPA offloading or privacy 1.2, skip */ + if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) + return false; + + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, + btm_cb.ble_ctr_cb.privacy_mode); + + /* only add RPA enabled device into resolving list */ + if (p_dev_rec != NULL && /* RPA is being used and PID is known */ + ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 || + (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0)) { + if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && + btm_ble_brcm_find_resolving_pending_entry( + p_dev_rec->bd_addr, BTM_BLE_META_ADD_IRK_ENTRY) == false) { + if (btm_cb.ble_ctr_cb.resolving_list_avail_size > 0) { + if (rl_mask) { + if (!btm_ble_disable_resolving_list(rl_mask, false)) return false; } - else - { - BTM_TRACE_ERROR("Device already in Resolving list"); - rt = true; + + btm_ble_update_resolving_list(p_dev_rec->bd_addr, true); + if (controller_get_interface()->supports_ble_privacy()) { + BD_ADDR dummy_bda = {0}; + uint8_t* peer_irk = p_dev_rec->ble.keys.irk; + uint8_t* local_irk = btm_cb.devcb.id_keys.irk; + + if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) == 0) { + memcpy(p_dev_rec->ble.static_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type; + } + + BTM_TRACE_DEBUG("%s:adding device to controller resolving list", + __func__); + // use identical IRK for now + btsnd_hcic_ble_add_device_resolving_list( + p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr, + peer_irk, local_irk); + } else { + uint8_t param[40] = {0}; + uint8_t* p = param; + + UINT8_TO_STREAM(p, BTM_BLE_META_ADD_IRK_ENTRY); + ARRAY_TO_STREAM(p, p_dev_rec->ble.keys.irk, BT_OCTET16_LEN); + UINT8_TO_STREAM(p, p_dev_rec->ble.static_addr_type); + BDADDR_TO_STREAM(p, p_dev_rec->ble.static_addr); + + BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, + BTM_BLE_META_ADD_IRK_LEN, param, + btm_ble_resolving_list_vsc_op_cmpl); } - } - else - { - BTM_TRACE_DEBUG("Device not a RPA enabled device"); - } - return rt; + + rt = true; + btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, + BTM_BLE_META_ADD_IRK_ENTRY); + + /* if resolving list has been turned on, re-enable it */ + if (rl_mask) + btm_ble_enable_resolving_list(rl_mask); + else + btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); + } + } else { + BTM_TRACE_ERROR("Device already in Resolving list"); + rt = true; + } + } else { + BTM_TRACE_DEBUG("Device not a RPA enabled device"); + } + return rt; } /******************************************************************************* @@ -843,32 +755,25 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) * Returns status * ******************************************************************************/ -void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) -{ - uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state; - - BTM_TRACE_EVENT ("%s", __func__); - if (rl_mask) - { - if (!btm_ble_disable_resolving_list (rl_mask, false)) - return; - } - - if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && - btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr, - BTM_BLE_META_REMOVE_IRK_ENTRY) == false) - { - btm_ble_update_resolving_list( p_dev_rec->bd_addr, false); - btm_ble_remove_resolving_list_entry(p_dev_rec); - } - else - { - BTM_TRACE_DEBUG("Device not in resolving list"); - } - - /* if resolving list has been turned on, re-enable it */ - if (rl_mask) - btm_ble_enable_resolving_list(rl_mask); +void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC* p_dev_rec) { + uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state; + + BTM_TRACE_EVENT("%s", __func__); + if (rl_mask) { + if (!btm_ble_disable_resolving_list(rl_mask, false)) return; + } + + if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && + btm_ble_brcm_find_resolving_pending_entry( + p_dev_rec->bd_addr, BTM_BLE_META_REMOVE_IRK_ENTRY) == false) { + btm_ble_update_resolving_list(p_dev_rec->bd_addr, false); + btm_ble_remove_resolving_list_entry(p_dev_rec); + } else { + BTM_TRACE_DEBUG("Device not in resolving list"); + } + + /* if resolving list has been turned on, re-enable it */ + if (rl_mask) btm_ble_enable_resolving_list(rl_mask); } /******************************************************************************* @@ -880,18 +785,16 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) * Returns none * ******************************************************************************/ -void btm_ble_enable_resolving_list(uint8_t rl_mask) -{ - uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state; - - btm_cb.ble_ctr_cb.rl_state |= rl_mask; - if (rl_state == BTM_BLE_RL_IDLE && - btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE && - controller_get_interface()->get_ble_resolving_list_max_size() != 0) - { - btm_ble_exe_enable_resolving_list(); - btm_ble_resume_resolving_list_activity(); - } +void btm_ble_enable_resolving_list(uint8_t rl_mask) { + uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state; + + btm_cb.ble_ctr_cb.rl_state |= rl_mask; + if (rl_state == BTM_BLE_RL_IDLE && + btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE && + controller_get_interface()->get_ble_resolving_list_max_size() != 0) { + btm_ble_exe_enable_resolving_list(); + btm_ble_resume_resolving_list_activity(); + } } /******************************************************************************* @@ -903,24 +806,20 @@ void btm_ble_enable_resolving_list(uint8_t rl_mask) * Returns true: empty; false non-empty * ******************************************************************************/ -bool btm_ble_resolving_list_empty(void) -{ - return (controller_get_interface()->get_ble_resolving_list_max_size() == - btm_cb.ble_ctr_cb.resolving_list_avail_size); +bool btm_ble_resolving_list_empty(void) { + return (controller_get_interface()->get_ble_resolving_list_max_size() == + btm_cb.ble_ctr_cb.resolving_list_avail_size); } +bool is_on_resolving_list(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev = static_cast(data); + if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && + (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) + return false; -bool is_on_resolving_list(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev = static_cast(data); - if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && - (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) - return false; - - return true; + return true; } - /******************************************************************************* * * Function btm_ble_enable_resolving_list_for_platform @@ -932,27 +831,25 @@ bool is_on_resolving_list(void *data, void *context) * Returns none * ******************************************************************************/ -void btm_ble_enable_resolving_list_for_platform (uint8_t rl_mask) -{ - /* if controller does not support, skip */ - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) - return; - - if (btm_cb.ble_ctr_cb.wl_state == BTM_BLE_WL_IDLE) - { - if (controller_get_interface()->get_ble_resolving_list_max_size() > - btm_cb.ble_ctr_cb.resolving_list_avail_size) - btm_ble_enable_resolving_list(rl_mask); - else - btm_ble_disable_resolving_list(rl_mask, true); - return; - } - - list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); - if (n) - btm_ble_enable_resolving_list(rl_mask); +void btm_ble_enable_resolving_list_for_platform(uint8_t rl_mask) { + /* if controller does not support, skip */ + if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) + return; + + if (btm_cb.ble_ctr_cb.wl_state == BTM_BLE_WL_IDLE) { + if (controller_get_interface()->get_ble_resolving_list_max_size() > + btm_cb.ble_ctr_cb.resolving_list_avail_size) + btm_ble_enable_resolving_list(rl_mask); else - btm_ble_disable_resolving_list(rl_mask, true); + btm_ble_disable_resolving_list(rl_mask, true); + return; + } + + list_node_t* n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); + if (n) + btm_ble_enable_resolving_list(rl_mask); + else + btm_ble_disable_resolving_list(rl_mask, true); } /******************************************************************************* @@ -966,27 +863,26 @@ void btm_ble_enable_resolving_list_for_platform (uint8_t rl_mask) * Returns void * ******************************************************************************/ -void btm_ble_resolving_list_init(uint8_t max_irk_list_sz) -{ - tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; - uint8_t irk_mask_size = (max_irk_list_sz % 8) ? - (max_irk_list_sz/8 + 1) : (max_irk_list_sz/8); - - if (max_irk_list_sz > 0) - { - p_q->resolve_q_random_pseudo = (BD_ADDR *)osi_malloc(sizeof(BD_ADDR) * max_irk_list_sz); - p_q->resolve_q_action = (uint8_t *)osi_malloc(max_irk_list_sz); - - /* RPA offloading feature */ - if (btm_cb.ble_ctr_cb.irk_list_mask == NULL) - btm_cb.ble_ctr_cb.irk_list_mask = (uint8_t *)osi_malloc(irk_mask_size); - - BTM_TRACE_DEBUG ("%s max_irk_list_sz = %d", __func__, max_irk_list_sz); - } - - controller_get_interface()->set_ble_resolving_list_max_size(max_irk_list_sz); - btm_ble_clear_resolving_list(); - btm_cb.ble_ctr_cb.resolving_list_avail_size = max_irk_list_sz; +void btm_ble_resolving_list_init(uint8_t max_irk_list_sz) { + tBTM_BLE_RESOLVE_Q* p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; + uint8_t irk_mask_size = + (max_irk_list_sz % 8) ? (max_irk_list_sz / 8 + 1) : (max_irk_list_sz / 8); + + if (max_irk_list_sz > 0) { + p_q->resolve_q_random_pseudo = + (BD_ADDR*)osi_malloc(sizeof(BD_ADDR) * max_irk_list_sz); + p_q->resolve_q_action = (uint8_t*)osi_malloc(max_irk_list_sz); + + /* RPA offloading feature */ + if (btm_cb.ble_ctr_cb.irk_list_mask == NULL) + btm_cb.ble_ctr_cb.irk_list_mask = (uint8_t*)osi_malloc(irk_mask_size); + + BTM_TRACE_DEBUG("%s max_irk_list_sz = %d", __func__, max_irk_list_sz); + } + + controller_get_interface()->set_ble_resolving_list_max_size(max_irk_list_sz); + btm_ble_clear_resolving_list(); + btm_cb.ble_ctr_cb.resolving_list_avail_size = max_irk_list_sz; } /******************************************************************************* @@ -1000,15 +896,14 @@ void btm_ble_resolving_list_init(uint8_t max_irk_list_sz) * Returns void * ******************************************************************************/ -void btm_ble_resolving_list_cleanup(void) -{ - tBTM_BLE_RESOLVE_Q *p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; +void btm_ble_resolving_list_cleanup(void) { + tBTM_BLE_RESOLVE_Q* p_q = &btm_cb.ble_ctr_cb.resolving_list_pend_q; - osi_free_and_reset((void **)&p_q->resolve_q_random_pseudo); - osi_free_and_reset((void **)&p_q->resolve_q_action); + osi_free_and_reset((void**)&p_q->resolve_q_random_pseudo); + osi_free_and_reset((void**)&p_q->resolve_q_action); - controller_get_interface()->set_ble_resolving_list_max_size(0); + controller_get_interface()->set_ble_resolving_list_max_size(0); - osi_free_and_reset((void **)&btm_cb.ble_ctr_cb.irk_list_mask); + osi_free_and_reset((void**)&btm_cb.ble_ctr_cb.irk_list_mask); } #endif diff --git a/stack/btm/btm_dev.cc b/stack/btm/btm_dev.cc index 2bc87da79..bf69ccd01 100644 --- a/stack/btm/btm_dev.cc +++ b/stack/btm/btm_dev.cc @@ -22,19 +22,19 @@ * ******************************************************************************/ +#include +#include #include #include -#include -#include -#include "bt_types.h" -#include "device/include/controller.h" #include "bt_common.h" -#include "hcimsgs.h" -#include "btu.h" +#include "bt_types.h" #include "btm_api.h" #include "btm_int.h" +#include "btu.h" +#include "device/include/controller.h" #include "hcidefs.h" +#include "hcimsgs.h" #include "l2c_api.h" /******************************************************************************* @@ -58,105 +58,95 @@ * Returns true if added OK, else false * ******************************************************************************/ -bool BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, - uint8_t *features, uint32_t trusted_mask[], - LINK_KEY link_key, uint8_t key_type, tBTM_IO_CAP io_cap, - uint8_t pin_length) -{ - BTM_TRACE_API("%s: link key type:%x", __func__, key_type); - - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - if (!p_dev_rec) - { - p_dev_rec = btm_sec_allocate_dev_rec(); - - memcpy (p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); - p_dev_rec->hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_BR_EDR); - - /* use default value for background connection params */ - /* update conn params, use default value for background connection params */ - memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS)); - } else { - /* "Bump" timestamp for existing record */ - p_dev_rec->timestamp = btm_cb.dev_rec_count++; - - /* TODO(eisenbach): - * Small refactor, but leaving original logic for now. - * On the surface, this does not make any sense at all. Why change the - * bond state for an existing device here? This logic should be verified - * as part of a larger refactor. - */ - p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; - } +bool BTM_SecAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, + uint8_t* features, uint32_t trusted_mask[], + LINK_KEY link_key, uint8_t key_type, tBTM_IO_CAP io_cap, + uint8_t pin_length) { + BTM_TRACE_API("%s: link key type:%x", __func__, key_type); - if (dev_class) - memcpy (p_dev_rec->dev_class, dev_class, DEV_CLASS_LEN); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (!p_dev_rec) { + p_dev_rec = btm_sec_allocate_dev_rec(); - memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); + memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); + p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); - if (bd_name && bd_name[0]) - { - p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; - strlcpy ((char *)p_dev_rec->sec_bd_name, - (char *)bd_name, BTM_MAX_REM_BD_NAME_LEN); - } + /* use default value for background connection params */ + /* update conn params, use default value for background connection params */ + memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS)); + } else { + /* "Bump" timestamp for existing record */ + p_dev_rec->timestamp = btm_cb.dev_rec_count++; - p_dev_rec->num_read_pages = 0; - if (features) - { - bool found = false; - memcpy (p_dev_rec->features, features, sizeof (p_dev_rec->features)); - for (int i = HCI_EXT_FEATURES_PAGE_MAX; !found && i >= 0; i--) - { - for (int j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++) - { - if (p_dev_rec->features[i][j] != 0) - { - found = true; - p_dev_rec->num_read_pages = i + 1; - break; - } - } + /* TODO(eisenbach): + * Small refactor, but leaving original logic for now. + * On the surface, this does not make any sense at all. Why change the + * bond state for an existing device here? This logic should be verified + * as part of a larger refactor. + */ + p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; + } + + if (dev_class) memcpy(p_dev_rec->dev_class, dev_class, DEV_CLASS_LEN); + + memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); + + if (bd_name && bd_name[0]) { + p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; + strlcpy((char*)p_dev_rec->sec_bd_name, (char*)bd_name, + BTM_MAX_REM_BD_NAME_LEN); + } + + p_dev_rec->num_read_pages = 0; + if (features) { + bool found = false; + memcpy(p_dev_rec->features, features, sizeof(p_dev_rec->features)); + for (int i = HCI_EXT_FEATURES_PAGE_MAX; !found && i >= 0; i--) { + for (int j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++) { + if (p_dev_rec->features[i][j] != 0) { + found = true; + p_dev_rec->num_read_pages = i + 1; + break; } - } else { - memset (p_dev_rec->features, 0, sizeof (p_dev_rec->features)); + } } - - BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); - - if (link_key) - { - BTM_TRACE_EVENT ("%s: BDA: %02x:%02x:%02x:%02x:%02x:%02x", __func__, - bd_addr[0], bd_addr[1], bd_addr[2], - bd_addr[3], bd_addr[4], bd_addr[5]); - p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN; - memcpy (p_dev_rec->link_key, link_key, LINK_KEY_LEN); - p_dev_rec->link_key_type = key_type; - p_dev_rec->pin_code_length = pin_length; - - if (pin_length >= 16 || - key_type == BTM_LKEY_TYPE_AUTH_COMB || - key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { - // Set the flag if the link key was made by using either a 16 digit - // pin or MITM. - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED | BTM_SEC_LINK_KEY_AUTHED; - } + } else { + memset(p_dev_rec->features, 0, sizeof(p_dev_rec->features)); + } + + BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); + + if (link_key) { + BTM_TRACE_EVENT("%s: BDA: %02x:%02x:%02x:%02x:%02x:%02x", __func__, + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN; + memcpy(p_dev_rec->link_key, link_key, LINK_KEY_LEN); + p_dev_rec->link_key_type = key_type; + p_dev_rec->pin_code_length = pin_length; + + if (pin_length >= 16 || key_type == BTM_LKEY_TYPE_AUTH_COMB || + key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { + // Set the flag if the link key was made by using either a 16 digit + // pin or MITM. + p_dev_rec->sec_flags |= + BTM_SEC_16_DIGIT_PIN_AUTHED | BTM_SEC_LINK_KEY_AUTHED; } + } #if (BTIF_MIXED_MODE_INCLUDED == TRUE) - if (key_type < BTM_MAX_PRE_SM4_LKEY_TYPE) - p_dev_rec->sm4 = BTM_SM4_KNOWN; - else - p_dev_rec->sm4 = BTM_SM4_TRUE; + if (key_type < BTM_MAX_PRE_SM4_LKEY_TYPE) + p_dev_rec->sm4 = BTM_SM4_KNOWN; + else + p_dev_rec->sm4 = BTM_SM4_TRUE; #endif - p_dev_rec->rmt_io_caps = io_cap; - p_dev_rec->device_type |= BT_DEVICE_TYPE_BREDR; + p_dev_rec->rmt_io_caps = io_cap; + p_dev_rec->device_type |= BT_DEVICE_TYPE_BREDR; - return true; + return true; } - /******************************************************************************* * * Function BTM_SecDeleteDevice @@ -168,24 +158,22 @@ bool BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, * Returns true if removed OK, false if not found or ACL link is active * ******************************************************************************/ -bool BTM_SecDeleteDevice (BD_ADDR bd_addr) -{ - if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) || - BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) - { - BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", __func__); - return false; - } - - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) - { - btm_sec_free_dev(p_dev_rec); - /* Tell controller to get rid of the link key, if it has one stored */ - BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL); - } - - return true; +bool BTM_SecDeleteDevice(BD_ADDR bd_addr) { + if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) || + BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) { + BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", + __func__); + return false; + } + + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + btm_sec_free_dev(p_dev_rec); + /* Tell controller to get rid of the link key, if it has one stored */ + BTM_DeleteStoredLinkKey(p_dev_rec->bd_addr, NULL); + } + + return true; } /******************************************************************************* @@ -196,15 +184,13 @@ bool BTM_SecDeleteDevice (BD_ADDR bd_addr) * remove device. * ******************************************************************************/ -extern void BTM_SecClearSecurityFlags (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - return; - - p_dev_rec->sec_flags = 0; - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - p_dev_rec->sm4 = BTM_SM4_UNKNOWN; +extern void BTM_SecClearSecurityFlags(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) return; + + p_dev_rec->sec_flags = 0; + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + p_dev_rec->sm4 = BTM_SM4_UNKNOWN; } /******************************************************************************* @@ -217,27 +203,23 @@ extern void BTM_SecClearSecurityFlags (BD_ADDR bd_addr) * Returns Pointer to the name or NULL * ******************************************************************************/ -char *BTM_SecReadDevName (BD_ADDR bd_addr) -{ - char *p_name = NULL; - tBTM_SEC_DEV_REC *p_srec; +char* BTM_SecReadDevName(BD_ADDR bd_addr) { + char* p_name = NULL; + tBTM_SEC_DEV_REC* p_srec; - p_srec = btm_find_dev(bd_addr); - if (p_srec != NULL) - p_name = (char *)p_srec->sec_bd_name; + p_srec = btm_find_dev(bd_addr); + if (p_srec != NULL) p_name = (char*)p_srec->sec_bd_name; - return(p_name); + return (p_name); } -bool is_bd_addr_equal(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - BD_ADDR *bd_addr = static_cast(context); +bool is_bd_addr_equal(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + BD_ADDR* bd_addr = static_cast(context); - if (!memcmp(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN)) - return false; + if (!memcmp(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN)) return false; - return true; + return true; } /******************************************************************************* @@ -250,37 +232,33 @@ bool is_bd_addr_equal(void *data, void *context) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr) -{ - tBTM_INQ_INFO *p_inq_info; - BTM_TRACE_EVENT ("btm_sec_alloc_dev"); - - tBTM_SEC_DEV_REC *p_dev_rec = btm_sec_allocate_dev_rec(); - - /* Check with the BT manager if details about remote device are known */ - /* outgoing connection */ - p_inq_info = BTM_InqDbRead(bd_addr); - if (p_inq_info != NULL) - { - memcpy (p_dev_rec->dev_class, p_inq_info->results.dev_class, DEV_CLASS_LEN); - - p_dev_rec->device_type = p_inq_info->results.device_type; - p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type; - } - else if (!memcmp (bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) - memcpy (p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); +tBTM_SEC_DEV_REC* btm_sec_alloc_dev(BD_ADDR bd_addr) { + tBTM_INQ_INFO* p_inq_info; + BTM_TRACE_EVENT("btm_sec_alloc_dev"); - /* update conn params, use default value for background connection params */ - memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS)); + tBTM_SEC_DEV_REC* p_dev_rec = btm_sec_allocate_dev_rec(); - memcpy (p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); + /* Check with the BT manager if details about remote device are known */ + /* outgoing connection */ + p_inq_info = BTM_InqDbRead(bd_addr); + if (p_inq_info != NULL) { + memcpy(p_dev_rec->dev_class, p_inq_info->results.dev_class, DEV_CLASS_LEN); - p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_LE); - p_dev_rec->hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_BR_EDR); + p_dev_rec->device_type = p_inq_info->results.device_type; + p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type; + } else if (!memcmp(bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) + memcpy(p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); - return(p_dev_rec); -} + /* update conn params, use default value for background connection params */ + memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS)); + + memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); + + p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE); + p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); + return (p_dev_rec); +} /******************************************************************************* * @@ -289,11 +267,10 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr) * Description Mark device record as not used * ******************************************************************************/ -void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec) -{ - /* Clear out any saved BLE keys */ - btm_sec_clear_ble_keys (p_dev_rec); - list_remove(btm_cb.sec_dev_rec, p_dev_rec); +void btm_sec_free_dev(tBTM_SEC_DEV_REC* p_dev_rec) { + /* Clear out any saved BLE keys */ + btm_sec_clear_ble_keys(p_dev_rec); + list_remove(btm_cb.sec_dev_rec, p_dev_rec); } /******************************************************************************* @@ -308,58 +285,50 @@ void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if device is known and role switch is supported * ******************************************************************************/ -bool btm_dev_support_switch (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - uint8_t xx; - bool feature_empty = true; +bool btm_dev_support_switch(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec; + uint8_t xx; + bool feature_empty = true; #if (BTM_SCO_INCLUDED == TRUE) - /* Role switch is not allowed if a SCO is up */ - if (btm_is_sco_active_by_bdaddr(bd_addr)) - return(false); + /* Role switch is not allowed if a SCO is up */ + if (btm_is_sco_active_by_bdaddr(bd_addr)) return (false); #endif - p_dev_rec = btm_find_dev (bd_addr); - if (p_dev_rec && controller_get_interface()->supports_master_slave_role_switch()) - { - if (HCI_SWITCH_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0])) - { - BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature found)"); - return (true); - } + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec && + controller_get_interface()->supports_master_slave_role_switch()) { + if (HCI_SWITCH_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0])) { + BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature found)"); + return (true); + } - /* If the feature field is all zero, we never received them */ - for (xx = 0 ; xx < BD_FEATURES_LEN ; xx++) - { - if (p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0][xx] != 0x00) - { - feature_empty = false; /* at least one is != 0 */ - break; - } - } + /* If the feature field is all zero, we never received them */ + for (xx = 0; xx < BD_FEATURES_LEN; xx++) { + if (p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0][xx] != 0x00) { + feature_empty = false; /* at least one is != 0 */ + break; + } + } - /* If we don't know peer's capabilities, assume it supports Role-switch */ - if (feature_empty) - { - BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature empty)"); - return (true); - } + /* If we don't know peer's capabilities, assume it supports Role-switch */ + if (feature_empty) { + BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature empty)"); + return (true); } + } - BTM_TRACE_DEBUG("btm_dev_support_switch return false"); - return(false); + BTM_TRACE_DEBUG("btm_dev_support_switch return false"); + return (false); } -bool is_handle_equal(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - uint16_t *handle = static_cast(context); +bool is_handle_equal(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + uint16_t* handle = static_cast(context); - if (p_dev_rec->hci_handle == *handle || - p_dev_rec->ble_hci_handle == *handle) - return false; + if (p_dev_rec->hci_handle == *handle || p_dev_rec->ble_hci_handle == *handle) + return false; - return true; + return true; } /******************************************************************************* @@ -372,29 +341,23 @@ bool is_handle_equal(void *data, void *context) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_DEV_REC *btm_find_dev_by_handle (uint16_t handle) -{ - list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_handle_equal, &handle); - if (n) - return static_cast(list_node(n)); +tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) { + list_node_t* n = list_foreach(btm_cb.sec_dev_rec, is_handle_equal, &handle); + if (n) return static_cast(list_node(n)); - return NULL; + return NULL; } -bool is_address_equal(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - BD_ADDR *bd_addr = static_cast(context); +bool is_address_equal(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + BD_ADDR* bd_addr = static_cast(context); - if (!memcmp (p_dev_rec->bd_addr, *bd_addr, BD_ADDR_LEN)) - return false; - // If a LE random address is looking for device record - if (!memcmp(p_dev_rec->ble.pseudo_addr, *bd_addr, BD_ADDR_LEN)) - return false; + if (!memcmp(p_dev_rec->bd_addr, *bd_addr, BD_ADDR_LEN)) return false; + // If a LE random address is looking for device record + if (!memcmp(p_dev_rec->ble.pseudo_addr, *bd_addr, BD_ADDR_LEN)) return false; - if (btm_ble_addr_resolvable(*bd_addr, p_dev_rec)) - return false; - return true; + if (btm_ble_addr_resolvable(*bd_addr, p_dev_rec)) return false; + return true; } /******************************************************************************* @@ -407,16 +370,14 @@ bool is_address_equal(void *data, void *context) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_DEV_REC *btm_find_dev(const BD_ADDR bd_addr) -{ - if (!bd_addr) - return NULL; +tBTM_SEC_DEV_REC* btm_find_dev(const BD_ADDR bd_addr) { + if (!bd_addr) return NULL; - list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_address_equal, (void*)bd_addr); - if (n) - return static_cast(list_node(n)); + list_node_t* n = + list_foreach(btm_cb.sec_dev_rec, is_address_equal, (void*)bd_addr); + if (n) return static_cast(list_node(n)); - return NULL; + return NULL; } /******************************************************************************* @@ -428,53 +389,51 @@ tBTM_SEC_DEV_REC *btm_find_dev(const BD_ADDR bd_addr) * Returns none * ******************************************************************************/ -void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec) -{ - tBTM_SEC_DEV_REC temp_rec = *p_target_rec; - - BTM_TRACE_DEBUG("%s", __func__); - - list_node_t *end = list_end(btm_cb.sec_dev_rec); - for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) { - tBTM_SEC_DEV_REC *p_dev_rec = - static_cast(list_node(node)); - - if (p_target_rec == p_dev_rec) - continue; - - if (!memcmp (p_dev_rec->bd_addr, p_target_rec->bd_addr, BD_ADDR_LEN)) - { - memcpy(p_target_rec, p_dev_rec, sizeof(tBTM_SEC_DEV_REC)); - p_target_rec->ble = temp_rec.ble; - p_target_rec->ble_hci_handle = temp_rec.ble_hci_handle; - p_target_rec->enc_key_size = temp_rec.enc_key_size; - p_target_rec->conn_params = temp_rec.conn_params; - p_target_rec->device_type |= temp_rec.device_type; - p_target_rec->sec_flags |= temp_rec.sec_flags; - - p_target_rec->new_encryption_key_is_p256 = temp_rec.new_encryption_key_is_p256; - p_target_rec->no_smp_on_br = temp_rec.no_smp_on_br; - p_target_rec->bond_type = temp_rec.bond_type; - - /* remove the combined record */ - list_remove(btm_cb.sec_dev_rec, p_dev_rec); - break; - } +void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec) { + tBTM_SEC_DEV_REC temp_rec = *p_target_rec; + + BTM_TRACE_DEBUG("%s", __func__); + + list_node_t* end = list_end(btm_cb.sec_dev_rec); + for (list_node_t* node = list_begin(btm_cb.sec_dev_rec); node != end; + node = list_next(node)) { + tBTM_SEC_DEV_REC* p_dev_rec = + static_cast(list_node(node)); + + if (p_target_rec == p_dev_rec) continue; + + if (!memcmp(p_dev_rec->bd_addr, p_target_rec->bd_addr, BD_ADDR_LEN)) { + memcpy(p_target_rec, p_dev_rec, sizeof(tBTM_SEC_DEV_REC)); + p_target_rec->ble = temp_rec.ble; + p_target_rec->ble_hci_handle = temp_rec.ble_hci_handle; + p_target_rec->enc_key_size = temp_rec.enc_key_size; + p_target_rec->conn_params = temp_rec.conn_params; + p_target_rec->device_type |= temp_rec.device_type; + p_target_rec->sec_flags |= temp_rec.sec_flags; + + p_target_rec->new_encryption_key_is_p256 = + temp_rec.new_encryption_key_is_p256; + p_target_rec->no_smp_on_br = temp_rec.no_smp_on_br; + p_target_rec->bond_type = temp_rec.bond_type; + + /* remove the combined record */ + list_remove(btm_cb.sec_dev_rec, p_dev_rec); + break; + } - /* an RPA device entry is a duplicate of the target record */ - if (btm_ble_addr_resolvable(p_dev_rec->bd_addr, p_target_rec)) - { - if (memcmp(p_target_rec->ble.pseudo_addr, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0) - { - p_target_rec->ble.ble_addr_type = p_dev_rec->ble.ble_addr_type; - p_target_rec->device_type |= p_dev_rec->device_type; - - /* remove the combined record */ - list_remove(btm_cb.sec_dev_rec, p_dev_rec); - } - break; - } + /* an RPA device entry is a duplicate of the target record */ + if (btm_ble_addr_resolvable(p_dev_rec->bd_addr, p_target_rec)) { + if (memcmp(p_target_rec->ble.pseudo_addr, p_dev_rec->bd_addr, + BD_ADDR_LEN) == 0) { + p_target_rec->ble.ble_addr_type = p_dev_rec->ble.ble_addr_type; + p_target_rec->device_type |= p_dev_rec->device_type; + + /* remove the combined record */ + list_remove(btm_cb.sec_dev_rec, p_dev_rec); + } + break; } + } } /******************************************************************************* @@ -487,18 +446,15 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - BTM_TRACE_EVENT ("btm_find_or_alloc_dev"); - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - { - - /* Allocate a new device record or reuse the oldest one */ - p_dev_rec = btm_sec_alloc_dev (bd_addr); - } - return(p_dev_rec); +tBTM_SEC_DEV_REC* btm_find_or_alloc_dev(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec; + BTM_TRACE_EVENT("btm_find_or_alloc_dev"); + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) { + /* Allocate a new device record or reuse the oldest one */ + p_dev_rec = btm_sec_alloc_dev(bd_addr); + } + return (p_dev_rec); } /******************************************************************************* @@ -512,38 +468,38 @@ tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr) * Returns Pointer to the record or NULL * ******************************************************************************/ -static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec (void) -{ - tBTM_SEC_DEV_REC *p_oldest = NULL; - uint32_t ts_oldest = 0xFFFFFFFF; - tBTM_SEC_DEV_REC *p_oldest_paired = NULL; - uint32_t ts_oldest_paired = 0xFFFFFFFF; - - list_node_t *end = list_end(btm_cb.sec_dev_rec); - for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) { - tBTM_SEC_DEV_REC *p_dev_rec = - static_cast(list_node(node)); - - if ((p_dev_rec->sec_flags & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_KNOWN)) == 0) { - // Device is not paired - if (p_dev_rec->timestamp < ts_oldest) { - p_oldest = p_dev_rec; - ts_oldest = p_dev_rec->timestamp; - } - } else { - // Paired device - if (p_dev_rec->timestamp < ts_oldest_paired) { - p_oldest_paired = p_dev_rec; - ts_oldest_paired = p_dev_rec->timestamp; - } - } +static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec(void) { + tBTM_SEC_DEV_REC* p_oldest = NULL; + uint32_t ts_oldest = 0xFFFFFFFF; + tBTM_SEC_DEV_REC* p_oldest_paired = NULL; + uint32_t ts_oldest_paired = 0xFFFFFFFF; + + list_node_t* end = list_end(btm_cb.sec_dev_rec); + for (list_node_t* node = list_begin(btm_cb.sec_dev_rec); node != end; + node = list_next(node)) { + tBTM_SEC_DEV_REC* p_dev_rec = + static_cast(list_node(node)); + + if ((p_dev_rec->sec_flags & + (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_KNOWN)) == 0) { + // Device is not paired + if (p_dev_rec->timestamp < ts_oldest) { + p_oldest = p_dev_rec; + ts_oldest = p_dev_rec->timestamp; + } + } else { + // Paired device + if (p_dev_rec->timestamp < ts_oldest_paired) { + p_oldest_paired = p_dev_rec; + ts_oldest_paired = p_dev_rec->timestamp; + } } + } - // If we did not find any non-paired devices, use the oldest paired one... - if (ts_oldest == 0xFFFFFFFF) - p_oldest = p_oldest_paired; + // If we did not find any non-paired devices, use the oldest paired one... + if (ts_oldest == 0xFFFFFFFF) p_oldest = p_oldest_paired; - return p_oldest; + return p_oldest; } /******************************************************************************* @@ -558,26 +514,24 @@ static tBTM_SEC_DEV_REC* btm_find_oldest_dev_rec (void) * Returns Pointer to the newly allocated record * ******************************************************************************/ -tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) -{ - tBTM_SEC_DEV_REC *p_dev_rec = NULL; +tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) { + tBTM_SEC_DEV_REC* p_dev_rec = NULL; - if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) - { - p_dev_rec = btm_find_oldest_dev_rec(); - list_remove(btm_cb.sec_dev_rec, p_dev_rec); - } + if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) { + p_dev_rec = btm_find_oldest_dev_rec(); + list_remove(btm_cb.sec_dev_rec, p_dev_rec); + } - p_dev_rec = - static_cast(osi_calloc(sizeof(tBTM_SEC_DEV_REC))); - list_append(btm_cb.sec_dev_rec, p_dev_rec); + p_dev_rec = + static_cast(osi_calloc(sizeof(tBTM_SEC_DEV_REC))); + list_append(btm_cb.sec_dev_rec, p_dev_rec); - // Initialize defaults - p_dev_rec->sec_flags = BTM_SEC_IN_USE; - p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; - p_dev_rec->timestamp = btm_cb.dev_rec_count++; + // Initialize defaults + p_dev_rec->sec_flags = BTM_SEC_IN_USE; + p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; + p_dev_rec->timestamp = btm_cb.dev_rec_count++; - return p_dev_rec; + return p_dev_rec; } /******************************************************************************* @@ -590,14 +544,12 @@ tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) * Returns The device bond type if known, otherwise BOND_TYPE_UNKNOWN * ******************************************************************************/ -tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); +tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - return BOND_TYPE_UNKNOWN; + if (p_dev_rec == NULL) return BOND_TYPE_UNKNOWN; - return p_dev_rec->bond_type; + return p_dev_rec->bond_type; } /******************************************************************************* @@ -610,13 +562,11 @@ tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr) * Returns true on success, otherwise false * ******************************************************************************/ -bool btm_set_bond_type_dev(BD_ADDR bd_addr, tBTM_BOND_TYPE bond_type) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); +bool btm_set_bond_type_dev(BD_ADDR bd_addr, tBTM_BOND_TYPE bond_type) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - return false; + if (p_dev_rec == NULL) return false; - p_dev_rec->bond_type = bond_type; - return true; + p_dev_rec->bond_type = bond_type; + return true; } diff --git a/stack/btm/btm_devctl.cc b/stack/btm/btm_devctl.cc index ac983c43b..bc4c5f934 100644 --- a/stack/btm/btm_devctl.cc +++ b/stack/btm/btm_devctl.cc @@ -24,46 +24,49 @@ ******************************************************************************/ #include +#include +#include #include #include -#include -#include #include "bt_types.h" #include "bt_utils.h" +#include "btcore/include/module.h" #include "btm_int.h" #include "btu.h" #include "device/include/controller.h" #include "hci_layer.h" #include "hcimsgs.h" #include "l2c_int.h" -#include "btcore/include/module.h" #include "osi/include/osi.h" #include "osi/include/thread.h" #include "gatt_int.h" -extern fixed_queue_t *btu_general_alarm_queue; -extern thread_t *bt_workqueue_thread; +extern fixed_queue_t* btu_general_alarm_queue; +extern thread_t* bt_workqueue_thread; /******************************************************************************/ /* L O C A L D A T A D E F I N I T I O N S */ /******************************************************************************/ #ifndef BTM_DEV_RESET_TIMEOUT -#define BTM_DEV_RESET_TIMEOUT 4 +#define BTM_DEV_RESET_TIMEOUT 4 #endif // TODO: Reevaluate this value in the context of timers with ms granularity -#define BTM_DEV_NAME_REPLY_TIMEOUT_MS (2 * 1000) /* 2 seconds for name reply */ +#define BTM_DEV_NAME_REPLY_TIMEOUT_MS \ + (2 * 1000) /* 2 seconds for name reply \ + */ -#define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */ +#define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */ /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void btm_decode_ext_features_page (uint8_t page_number, const BD_FEATURES p_features); +static void btm_decode_ext_features_page(uint8_t page_number, + const BD_FEATURES p_features); /******************************************************************************* * @@ -74,34 +77,30 @@ static void btm_decode_ext_features_page (uint8_t page_number, const BD_FEATURES * Returns void * ******************************************************************************/ -void btm_dev_init (void) -{ - /* Initialize nonzero defaults */ - memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); - - btm_cb.devcb.read_local_name_timer = - alarm_new("btm.read_local_name_timer"); - btm_cb.devcb.read_rssi_timer = alarm_new("btm.read_rssi_timer"); - btm_cb.devcb.read_link_quality_timer = - alarm_new("btm.read_link_quality_timer"); - btm_cb.devcb.read_inq_tx_power_timer = - alarm_new("btm.read_inq_tx_power_timer"); - btm_cb.devcb.qos_setup_timer = alarm_new("btm.qos_setup_timer"); - btm_cb.devcb.read_tx_power_timer = alarm_new("btm.read_tx_power_timer"); - - btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 + - BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 + - BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5; - - btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1 + - BTM_SCO_PKT_TYPES_MASK_HV2 + - BTM_SCO_PKT_TYPES_MASK_HV3 + - BTM_SCO_PKT_TYPES_MASK_EV3 + - BTM_SCO_PKT_TYPES_MASK_EV4 + - BTM_SCO_PKT_TYPES_MASK_EV5; +void btm_dev_init(void) { + /* Initialize nonzero defaults */ + memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); + + btm_cb.devcb.read_local_name_timer = alarm_new("btm.read_local_name_timer"); + btm_cb.devcb.read_rssi_timer = alarm_new("btm.read_rssi_timer"); + btm_cb.devcb.read_link_quality_timer = + alarm_new("btm.read_link_quality_timer"); + btm_cb.devcb.read_inq_tx_power_timer = + alarm_new("btm.read_inq_tx_power_timer"); + btm_cb.devcb.qos_setup_timer = alarm_new("btm.qos_setup_timer"); + btm_cb.devcb.read_tx_power_timer = alarm_new("btm.read_tx_power_timer"); + + btm_cb.btm_acl_pkt_types_supported = + BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 + + BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 + + BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5; + + btm_cb.btm_sco_pkt_types_supported = + BTM_SCO_PKT_TYPES_MASK_HV1 + BTM_SCO_PKT_TYPES_MASK_HV2 + + BTM_SCO_PKT_TYPES_MASK_HV3 + BTM_SCO_PKT_TYPES_MASK_EV3 + + BTM_SCO_PKT_TYPES_MASK_EV4 + BTM_SCO_PKT_TYPES_MASK_EV5; } - /******************************************************************************* * * Function btm_db_reset @@ -113,58 +112,52 @@ void btm_dev_init (void) * Returns void * ******************************************************************************/ -static void btm_db_reset (void) -{ - tBTM_CMPL_CB *p_cb; - tBTM_STATUS status = BTM_DEV_RESET; +static void btm_db_reset(void) { + tBTM_CMPL_CB* p_cb; + tBTM_STATUS status = BTM_DEV_RESET; - btm_inq_db_reset(); + btm_inq_db_reset(); - if (btm_cb.devcb.p_rln_cmpl_cb) - { - p_cb = btm_cb.devcb.p_rln_cmpl_cb; - btm_cb.devcb.p_rln_cmpl_cb = NULL; + if (btm_cb.devcb.p_rln_cmpl_cb) { + p_cb = btm_cb.devcb.p_rln_cmpl_cb; + btm_cb.devcb.p_rln_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); - } + if (p_cb) (*p_cb)((void*)NULL); + } - if (btm_cb.devcb.p_rssi_cmpl_cb) - { - p_cb = btm_cb.devcb.p_rssi_cmpl_cb; - btm_cb.devcb.p_rssi_cmpl_cb = NULL; + if (btm_cb.devcb.p_rssi_cmpl_cb) { + p_cb = btm_cb.devcb.p_rssi_cmpl_cb; + btm_cb.devcb.p_rssi_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((tBTM_RSSI_RESULTS *) &status); - } + if (p_cb) (*p_cb)((tBTM_RSSI_RESULTS*)&status); + } } -bool set_sec_state_idle(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - return true; +bool set_sec_state_idle(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + return true; } -static void reset_complete(void *result) { +static void reset_complete(void* result) { assert(result == FUTURE_SUCCESS); - const controller_t *controller = controller_get_interface(); + const controller_t* controller = controller_get_interface(); /* Tell L2CAP that all connections are gone */ - l2cu_device_reset (); + l2cu_device_reset(); /* Clear current security state */ list_foreach(btm_cb.sec_dev_rec, set_sec_state_idle, NULL); /* After the reset controller should restore all parameters to defaults. */ - btm_cb.btm_inq_vars.inq_counter = 1; - btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW; - btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL; - btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE; + btm_cb.btm_inq_vars.inq_counter = 1; + btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW; + btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL; + btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE; - btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW; - btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL; - btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE; + btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW; + btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL; + btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE; btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE; btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE; @@ -179,9 +172,10 @@ static void reset_complete(void *result) { /* Set up the BLE privacy settings */ if (controller->supports_ble() && controller->supports_ble_privacy() && controller->get_ble_resolving_list_max_size() > 0) { - btm_ble_resolving_list_init(controller->get_ble_resolving_list_max_size()); - /* set the default random private address timeout */ - btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT_MS / 1000); + btm_ble_resolving_list_init(controller->get_ble_resolving_list_max_size()); + /* set the default random private address timeout */ + btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT_MS / + 1000); } #endif @@ -190,28 +184,27 @@ static void reset_complete(void *result) { l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble()); } - BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len); + BTM_SetPinType(btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, + btm_cb.cfg.pin_code_len); for (int i = 0; i <= controller->get_last_features_classic_index(); i++) { - btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array); + btm_decode_ext_features_page(i, + controller->get_features_classic(i)->as_array); } btm_report_device_status(BTM_DEV_STATUS_UP); } // TODO(zachoverflow): remove this function -void BTM_DeviceReset (UNUSED_ATTR tBTM_CMPL_CB *p_cb) { +void BTM_DeviceReset(UNUSED_ATTR tBTM_CMPL_CB* p_cb) { /* Flush all ACL connections */ btm_acl_device_down(); /* Clear the callback, so application would not hang on reset */ btm_db_reset(); - module_start_up_callbacked_wrapper( - get_module(CONTROLLER_MODULE), - bt_workqueue_thread, - reset_complete - ); + module_start_up_callbacked_wrapper(get_module(CONTROLLER_MODULE), + bt_workqueue_thread, reset_complete); } /******************************************************************************* @@ -223,10 +216,7 @@ void BTM_DeviceReset (UNUSED_ATTR tBTM_CMPL_CB *p_cb) { * Returns true if device is up, else false * ******************************************************************************/ -bool BTM_IsDeviceUp (void) -{ - return controller_get_interface()->get_is_ready(); -} +bool BTM_IsDeviceUp(void) { return controller_get_interface()->get_is_ready(); } /******************************************************************************* * @@ -237,12 +227,10 @@ bool BTM_IsDeviceUp (void) * Returns void * ******************************************************************************/ -void btm_read_local_name_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb; - btm_cb.devcb.p_rln_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_read_local_name_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rln_cmpl_cb; + btm_cb.devcb.p_rln_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -254,170 +242,164 @@ void btm_read_local_name_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -static void btm_decode_ext_features_page (uint8_t page_number, const uint8_t *p_features) -{ - BTM_TRACE_DEBUG ("btm_decode_ext_features_page page: %d", page_number); - switch (page_number) - { +static void btm_decode_ext_features_page(uint8_t page_number, + const uint8_t* p_features) { + BTM_TRACE_DEBUG("btm_decode_ext_features_page page: %d", page_number); + switch (page_number) { /* Extended (Legacy) Page 0 */ case HCI_EXT_FEATURES_PAGE_0: - /* Create ACL supported packet types mask */ - btm_cb.btm_acl_pkt_types_supported = (BTM_ACL_PKT_TYPES_MASK_DH1 + - BTM_ACL_PKT_TYPES_MASK_DM1); - - if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features)) - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH3 + - BTM_ACL_PKT_TYPES_MASK_DM3); - - if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features)) - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH5 + - BTM_ACL_PKT_TYPES_MASK_DM5); - - /* Add in EDR related ACL types */ - if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features)) - { - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + - BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + - BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); - } - - if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) - { - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + - BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + - BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); - } - - /* Check to see if 3 and 5 slot packets are available */ - if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) || - HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) - { - if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features)) - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + - BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); - - if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features)) - btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + - BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); - } - - BTM_TRACE_DEBUG("Local supported ACL packet types: 0x%04x", - btm_cb.btm_acl_pkt_types_supported); - - /* Create (e)SCO supported packet types mask */ - btm_cb.btm_sco_pkt_types_supported = 0; + /* Create ACL supported packet types mask */ + btm_cb.btm_acl_pkt_types_supported = + (BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1); + + if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features)) + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3); + + if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features)) + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5); + + /* Add in EDR related ACL types */ + if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features)) { + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + + BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); + } + + if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) { + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); + } + + /* Check to see if 3 and 5 slot packets are available */ + if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) || + HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) { + if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features)) + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); + + if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features)) + btm_cb.btm_acl_pkt_types_supported |= + (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); + } + + BTM_TRACE_DEBUG("Local supported ACL packet types: 0x%04x", + btm_cb.btm_acl_pkt_types_supported); + + /* Create (e)SCO supported packet types mask */ + btm_cb.btm_sco_pkt_types_supported = 0; #if (BTM_SCO_INCLUDED == TRUE) - btm_cb.sco_cb.esco_supported = false; + btm_cb.sco_cb.esco_supported = false; #endif - if (HCI_SCO_LINK_SUPPORTED(p_features)) - { - btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1; + if (HCI_SCO_LINK_SUPPORTED(p_features)) { + btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1; - if (HCI_HV2_PACKETS_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2; + if (HCI_HV2_PACKETS_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2; - if (HCI_HV3_PACKETS_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3; - } + if (HCI_HV3_PACKETS_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3; + } - if (HCI_ESCO_EV3_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3; + if (HCI_ESCO_EV3_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3; - if (HCI_ESCO_EV4_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4; + if (HCI_ESCO_EV4_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4; - if (HCI_ESCO_EV5_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5; + if (HCI_ESCO_EV5_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5; #if (BTM_SCO_INCLUDED == TRUE) - if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) - { - btm_cb.sco_cb.esco_supported = true; - - /* Add in EDR related eSCO types */ - if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features)) - { - if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_2_EV5; - } - else - { - btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 + - BTM_SCO_PKT_TYPES_MASK_NO_2_EV5); - } - - if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features)) - { - if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) - btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_3_EV5; - } - else - { - btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 + - BTM_SCO_PKT_TYPES_MASK_NO_3_EV5); - } + if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) { + btm_cb.sco_cb.esco_supported = true; + + /* Add in EDR related eSCO types */ + if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features)) { + if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= + BTM_SCO_PKT_TYPES_MASK_NO_2_EV5; + } else { + btm_cb.btm_sco_pkt_types_supported |= + (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 + + BTM_SCO_PKT_TYPES_MASK_NO_2_EV5); + } + + if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features)) { + if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) + btm_cb.btm_sco_pkt_types_supported |= + BTM_SCO_PKT_TYPES_MASK_NO_3_EV5; + } else { + btm_cb.btm_sco_pkt_types_supported |= + (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 + + BTM_SCO_PKT_TYPES_MASK_NO_3_EV5); } + } #endif - BTM_TRACE_DEBUG("Local supported SCO packet types: 0x%04x", - btm_cb.btm_sco_pkt_types_supported); + BTM_TRACE_DEBUG("Local supported SCO packet types: 0x%04x", + btm_cb.btm_sco_pkt_types_supported); - /* Create Default Policy Settings */ - if (HCI_SWITCH_SUPPORTED(p_features)) - btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; - else - btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; + /* Create Default Policy Settings */ + if (HCI_SWITCH_SUPPORTED(p_features)) + btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; + else + btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; - if (HCI_HOLD_MODE_SUPPORTED(p_features)) - btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE; - else - btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE; + if (HCI_HOLD_MODE_SUPPORTED(p_features)) + btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE; + else + btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE; - if (HCI_SNIFF_MODE_SUPPORTED(p_features)) - btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE; - else - btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE; + if (HCI_SNIFF_MODE_SUPPORTED(p_features)) + btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE; + else + btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE; - if (HCI_PARK_MODE_SUPPORTED(p_features)) - btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE; - else - btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE; + if (HCI_PARK_MODE_SUPPORTED(p_features)) + btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE; + else + btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE; - btm_sec_dev_reset (); + btm_sec_dev_reset(); - if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) - { - if (HCI_EXT_INQ_RSP_SUPPORTED(p_features)) - BTM_SetInquiryMode (BTM_INQ_RESULT_EXTENDED); - else - BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI); - } + if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) { + if (HCI_EXT_INQ_RSP_SUPPORTED(p_features)) + BTM_SetInquiryMode(BTM_INQ_RESULT_EXTENDED); + else + BTM_SetInquiryMode(BTM_INQ_RESULT_WITH_RSSI); + } #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - if( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features)) - l2cu_set_non_flushable_pbf(true); - else - l2cu_set_non_flushable_pbf(false); + if (HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features)) + l2cu_set_non_flushable_pbf(true); + else + l2cu_set_non_flushable_pbf(false); #endif - BTM_SetPageScanType (BTM_DEFAULT_SCAN_TYPE); - BTM_SetInquiryScanType (BTM_DEFAULT_SCAN_TYPE); + BTM_SetPageScanType(BTM_DEFAULT_SCAN_TYPE); + BTM_SetInquiryScanType(BTM_DEFAULT_SCAN_TYPE); - break; + break; /* Extended Page 1 */ case HCI_EXT_FEATURES_PAGE_1: - /* Nothing to do for page 1 */ - break; + /* Nothing to do for page 1 */ + break; /* Extended Page 2 */ case HCI_EXT_FEATURES_PAGE_2: - /* Nothing to do for page 2 */ - break; + /* Nothing to do for page 2 */ + break; default: - BTM_TRACE_ERROR("btm_decode_ext_features_page page=%d unknown", page_number); - break; - } + BTM_TRACE_ERROR("btm_decode_ext_features_page page=%d unknown", + page_number); + break; + } } /******************************************************************************* @@ -429,25 +411,21 @@ static void btm_decode_ext_features_page (uint8_t page_number, const uint8_t *p_ * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) -{ - uint8_t *p; - - if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN)) - return (BTM_ILLEGAL_VALUE); - - if (!controller_get_interface()->get_is_ready()) - return (BTM_DEV_RESET); - /* Save the device name if local storage is enabled */ - p = (uint8_t *)btm_cb.cfg.bd_name; - if (p != (uint8_t *)p_name) - strlcpy(btm_cb.cfg.bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN); - - btsnd_hcic_change_name(p); - return (BTM_CMD_STARTED); -} +tBTM_STATUS BTM_SetLocalDeviceName(char* p_name) { + uint8_t* p; + + if (!p_name || !p_name[0] || (strlen((char*)p_name) > BD_NAME_LEN)) + return (BTM_ILLEGAL_VALUE); + if (!controller_get_interface()->get_is_ready()) return (BTM_DEV_RESET); + /* Save the device name if local storage is enabled */ + p = (uint8_t*)btm_cb.cfg.bd_name; + if (p != (uint8_t*)p_name) + strlcpy(btm_cb.cfg.bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN); + btsnd_hcic_change_name(p); + return (BTM_CMD_STARTED); +} /******************************************************************************* * @@ -462,13 +440,11 @@ tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) * is returned and p_name is set to NULL * ******************************************************************************/ -tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name) -{ - *p_name = btm_cb.cfg.bd_name; - return(BTM_SUCCESS); +tBTM_STATUS BTM_ReadLocalDeviceName(char** p_name) { + *p_name = btm_cb.cfg.bd_name; + return (BTM_SUCCESS); } - /******************************************************************************* * * Function BTM_ReadLocalDeviceNameFromController @@ -479,22 +455,20 @@ tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name) * Returns BTM_CMD_STARTED if successful, otherwise an error * ******************************************************************************/ -tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback) -{ - /* Check if rln already in progress */ - if (btm_cb.devcb.p_rln_cmpl_cb) - return(BTM_NO_RESOURCES); - - /* Save callback */ - btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback; - - btsnd_hcic_read_name(); - alarm_set_on_queue(btm_cb.devcb.read_local_name_timer, - BTM_DEV_NAME_REPLY_TIMEOUT_MS, - btm_read_local_name_timeout, NULL, - btu_general_alarm_queue); - - return BTM_CMD_STARTED; +tBTM_STATUS BTM_ReadLocalDeviceNameFromController( + tBTM_CMPL_CB* p_rln_cmpl_cback) { + /* Check if rln already in progress */ + if (btm_cb.devcb.p_rln_cmpl_cb) return (BTM_NO_RESOURCES); + + /* Save callback */ + btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback; + + btsnd_hcic_read_name(); + alarm_set_on_queue(btm_cb.devcb.read_local_name_timer, + BTM_DEV_NAME_REPLY_TIMEOUT_MS, btm_read_local_name_timeout, + NULL, btu_general_alarm_queue); + + return BTM_CMD_STARTED; } /******************************************************************************* @@ -507,26 +481,23 @@ tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cbac * Returns void * ******************************************************************************/ -void btm_read_local_name_complete (uint8_t *p, - UNUSED_ATTR uint16_t evt_len) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb; - uint8_t status; +void btm_read_local_name_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rln_cmpl_cb; + uint8_t status; - alarm_cancel(btm_cb.devcb.read_local_name_timer); + alarm_cancel(btm_cb.devcb.read_local_name_timer); - /* If there was a callback address for read local name, call it */ - btm_cb.devcb.p_rln_cmpl_cb = NULL; + /* If there was a callback address for read local name, call it */ + btm_cb.devcb.p_rln_cmpl_cb = NULL; - if (p_cb) - { - STREAM_TO_UINT8 (status, p); + if (p_cb) { + STREAM_TO_UINT8(status, p); - if (status == HCI_SUCCESS) - (*p_cb)(p); - else - (*p_cb)(NULL); - } + if (status == HCI_SUCCESS) + (*p_cb)(p); + else + (*p_cb)(NULL); + } } /******************************************************************************* @@ -538,22 +509,19 @@ void btm_read_local_name_complete (uint8_t *p, * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class) -{ - if(!memcmp (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN)) - return(BTM_SUCCESS); +tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class) { + if (!memcmp(btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN)) + return (BTM_SUCCESS); - memcpy (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN); + memcpy(btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN); - if (!controller_get_interface()->get_is_ready()) - return (BTM_DEV_RESET); + if (!controller_get_interface()->get_is_ready()) return (BTM_DEV_RESET); - btsnd_hcic_write_dev_class(dev_class); + btsnd_hcic_write_dev_class(dev_class); - return (BTM_SUCCESS); + return (BTM_SUCCESS); } - /******************************************************************************* * * Function BTM_ReadDeviceClass @@ -563,12 +531,10 @@ tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class) * Returns pointer to the device class * ******************************************************************************/ -uint8_t *BTM_ReadDeviceClass (void) -{ - return ((uint8_t *)btm_cb.devcb.dev_class); +uint8_t* BTM_ReadDeviceClass(void) { + return ((uint8_t*)btm_cb.devcb.dev_class); } - /******************************************************************************* * * Function BTM_ReadLocalFeatures @@ -579,10 +545,11 @@ uint8_t *BTM_ReadDeviceClass (void) * ******************************************************************************/ // TODO(zachoverflow): get rid of this function -uint8_t *BTM_ReadLocalFeatures (void) -{ - // Discarding const modifier for now, until this function dies - return (uint8_t *)controller_get_interface()->get_features_classic(0)->as_array; +uint8_t* BTM_ReadLocalFeatures(void) { + // Discarding const modifier for now, until this function dies + return (uint8_t*)controller_get_interface() + ->get_features_classic(0) + ->as_array; } /******************************************************************************* @@ -599,12 +566,11 @@ uint8_t *BTM_ReadLocalFeatures (void) * Returns status of the operation * ******************************************************************************/ -tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb) -{ - tBTM_DEV_STATUS_CB *p_prev = btm_cb.devcb.p_dev_status_cb; +tBTM_DEV_STATUS_CB* BTM_RegisterForDeviceStatusNotif(tBTM_DEV_STATUS_CB* p_cb) { + tBTM_DEV_STATUS_CB* p_prev = btm_cb.devcb.p_dev_status_cb; - btm_cb.devcb.p_dev_status_cb = p_cb; - return (p_prev); + btm_cb.devcb.p_dev_status_cb = p_cb; + return (p_prev); } /******************************************************************************* @@ -618,20 +584,19 @@ tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb) * ******************************************************************************/ void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len, - uint8_t *p_param_buf, tBTM_VSC_CMPL_CB *p_cb) -{ - /* Allocate a buffer to hold HCI command plus the callback function */ - void *p_buf = osi_malloc(sizeof(BT_HDR) + sizeof(tBTM_CMPL_CB *) + - param_len + HCIC_PREAMBLE_SIZE); + uint8_t* p_param_buf, tBTM_VSC_CMPL_CB* p_cb) { + /* Allocate a buffer to hold HCI command plus the callback function */ + void* p_buf = osi_malloc(sizeof(BT_HDR) + sizeof(tBTM_CMPL_CB*) + param_len + + HCIC_PREAMBLE_SIZE); - BTM_TRACE_EVENT("BTM: %s: Opcode: 0x%04X, ParamLen: %i.", __func__, - opcode, param_len); + BTM_TRACE_EVENT("BTM: %s: Opcode: 0x%04X, ParamLen: %i.", __func__, opcode, + param_len); - /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */ - btsnd_hcic_vendor_spec_cmd(p_buf, opcode, param_len, p_param_buf, (void *)p_cb); + /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */ + btsnd_hcic_vendor_spec_cmd(p_buf, opcode, param_len, p_param_buf, + (void*)p_cb); } - /******************************************************************************* * * Function btm_vsc_complete @@ -642,20 +607,19 @@ void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len, * Returns void * ******************************************************************************/ -void btm_vsc_complete (uint8_t *p, uint16_t opcode, uint16_t evt_len, - tBTM_CMPL_CB *p_vsc_cplt_cback) -{ - tBTM_VSC_CMPL vcs_cplt_params; - - /* If there was a callback address for vcs complete, call it */ - if (p_vsc_cplt_cback) - { - /* Pass paramters to the callback function */ - vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */ - vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */ - vcs_cplt_params.p_param_buf = p; - (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */ - } +void btm_vsc_complete(uint8_t* p, uint16_t opcode, uint16_t evt_len, + tBTM_CMPL_CB* p_vsc_cplt_cback) { + tBTM_VSC_CMPL vcs_cplt_params; + + /* If there was a callback address for vcs complete, call it */ + if (p_vsc_cplt_cback) { + /* Pass paramters to the callback function */ + vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */ + vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */ + vcs_cplt_params.p_param_buf = p; + (*p_vsc_cplt_cback)( + &vcs_cplt_params); /* Call the VSC complete callback function */ + } } /******************************************************************************* @@ -673,49 +637,39 @@ void btm_vsc_complete (uint8_t *p, uint16_t opcode, uint16_t evt_len, * registered. * ******************************************************************************/ -tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, bool is_register) -{ - tBTM_STATUS retval = BTM_SUCCESS; - uint8_t i, free_idx = BTM_MAX_VSE_CALLBACKS; - - /* See if callback is already registered */ - for (i=0; itransmit_command( - hci_packet_factory_get_interface()->make_set_event_mask((const bt_event_mask_t *)("\x00\x00\x00\x00\x00\x00\x00\x00")), - NULL, - NULL, - NULL); + /* set auto accept connection as this is needed during test mode */ + /* Allocate a buffer to hold HCI command */ + cond = HCI_DO_AUTO_ACCEPT_CONNECT; + btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP, + HCI_FILTER_COND_NEW_DEVICE, &cond, sizeof(cond)); - /* Send the HCI command */ - btsnd_hcic_enable_test_mode(); - return (BTM_SUCCESS); + /* put device to connectable mode */ + if (BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW, + BTM_DEFAULT_CONN_INTERVAL) != BTM_SUCCESS) { + return BTM_NO_RESOURCES; + } + + /* put device to discoverable mode */ + if (BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW, + BTM_DEFAULT_DISC_INTERVAL) != BTM_SUCCESS) { + return BTM_NO_RESOURCES; + } + + /* mask off all of event from controller */ + hci_layer_get_interface()->transmit_command( + hci_packet_factory_get_interface()->make_set_event_mask( + (const bt_event_mask_t*)("\x00\x00\x00\x00\x00\x00\x00\x00")), + NULL, NULL, NULL); + + /* Send the HCI command */ + btsnd_hcic_enable_test_mode(); + return (BTM_SUCCESS); } /******************************************************************************* @@ -841,31 +786,28 @@ tBTM_STATUS BTM_EnableTestMode(void) * the results * ******************************************************************************/ -tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb) -{ - BD_ADDR local_bd_addr; - bool delete_all_flag = false; - - /* Check if the previous command is completed */ - if (btm_cb.devcb.p_stored_link_key_cmpl_cb) - return (BTM_BUSY); - - if (!bd_addr) - { - /* This is to delete all link keys */ - delete_all_flag = true; - - /* We don't care the BD address. Just pass a non zero pointer */ - bd_addr = local_bd_addr; - } +tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB* p_cb) { + BD_ADDR local_bd_addr; + bool delete_all_flag = false; - BTM_TRACE_EVENT ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s", - delete_all_flag ? "true" : "false"); + /* Check if the previous command is completed */ + if (btm_cb.devcb.p_stored_link_key_cmpl_cb) return (BTM_BUSY); - /* Send the HCI command */ - btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb; - btsnd_hcic_delete_stored_key(bd_addr, delete_all_flag); - return (BTM_SUCCESS); + if (!bd_addr) { + /* This is to delete all link keys */ + delete_all_flag = true; + + /* We don't care the BD address. Just pass a non zero pointer */ + bd_addr = local_bd_addr; + } + + BTM_TRACE_EVENT("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s", + delete_all_flag ? "true" : "false"); + + /* Send the HCI command */ + btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb; + btsnd_hcic_delete_stored_key(bd_addr, delete_all_flag); + return (BTM_SUCCESS); } /******************************************************************************* @@ -879,26 +821,24 @@ tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb) * Returns void * ******************************************************************************/ -void btm_delete_stored_link_key_complete (uint8_t *p) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; - tBTM_DELETE_STORED_LINK_KEY_COMPLETE result; +void btm_delete_stored_link_key_complete(uint8_t* p) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; + tBTM_DELETE_STORED_LINK_KEY_COMPLETE result; - /* If there was a callback registered for read stored link key, call it */ - btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL; + /* If there was a callback registered for read stored link key, call it */ + btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL; - if (p_cb) - { - /* Set the call back event to indicate command complete */ - result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS; + if (p_cb) { + /* Set the call back event to indicate command complete */ + result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS; - /* Extract the result fields from the HCI event */ - STREAM_TO_UINT8 (result.status, p); - STREAM_TO_UINT16 (result.num_keys, p); + /* Extract the result fields from the HCI event */ + STREAM_TO_UINT8(result.status, p); + STREAM_TO_UINT16(result.num_keys, p); - /* Call the call back and pass the result */ - (*p_cb)(&result); - } + /* Call the call back and pass the result */ + (*p_cb)(&result); + } } /******************************************************************************* @@ -912,13 +852,9 @@ void btm_delete_stored_link_key_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_report_device_status (tBTM_DEV_STATUS status) -{ - tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb; +void btm_report_device_status(tBTM_DEV_STATUS status) { + tBTM_DEV_STATUS_CB* p_cb = btm_cb.devcb.p_dev_status_cb; - /* Call the call back to pass the device status to application */ - if (p_cb) - (*p_cb)(status); + /* Call the call back to pass the device status to application */ + if (p_cb) (*p_cb)(status); } - - diff --git a/stack/btm/btm_inq.cc b/stack/btm/btm_inq.cc index 17f45c43e..ff59c8635 100644 --- a/stack/btm/btm_inq.cc +++ b/stack/btm/btm_inq.cc @@ -25,22 +25,22 @@ * ******************************************************************************/ +#include +#include #include #include -#include -#include #include "device/include/controller.h" #include "osi/include/osi.h" #include "osi/include/time.h" -#include "bt_types.h" #include "bt_common.h" -#include "hcimsgs.h" -#include "btu.h" +#include "bt_types.h" #include "btm_api.h" #include "btm_int.h" +#include "btu.h" #include "hcidefs.h" +#include "hcimsgs.h" /* 3 second timeout waiting for responses */ #define BTM_INQ_REPLY_TIMEOUT_MS (3 * 1000) @@ -50,99 +50,78 @@ #define BTM_INQ_DEBUG FALSE #endif -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* L O C A L D A T A D E F I N I T I O N S */ /******************************************************************************/ -static const LAP general_inq_lap = {0x9e,0x8b,0x33}; -static const LAP limited_inq_lap = {0x9e,0x8b,0x00}; +static const LAP general_inq_lap = {0x9e, 0x8b, 0x33}; +static const LAP limited_inq_lap = {0x9e, 0x8b, 0x00}; -const uint16_t BTM_EIR_UUID_LKUP_TBL[BTM_EIR_MAX_SERVICES] = -{ +const uint16_t BTM_EIR_UUID_LKUP_TBL[BTM_EIR_MAX_SERVICES] = { UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER, -/* UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ -/* UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ - UUID_SERVCLASS_SERIAL_PORT, - UUID_SERVCLASS_LAN_ACCESS_USING_PPP, - UUID_SERVCLASS_DIALUP_NETWORKING, - UUID_SERVCLASS_IRMC_SYNC, - UUID_SERVCLASS_OBEX_OBJECT_PUSH, - UUID_SERVCLASS_OBEX_FILE_TRANSFER, - UUID_SERVCLASS_IRMC_SYNC_COMMAND, - UUID_SERVCLASS_HEADSET, - UUID_SERVCLASS_CORDLESS_TELEPHONY, - UUID_SERVCLASS_AUDIO_SOURCE, - UUID_SERVCLASS_AUDIO_SINK, - UUID_SERVCLASS_AV_REM_CTRL_TARGET, -/* UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ + /* UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ + /* UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ + UUID_SERVCLASS_SERIAL_PORT, UUID_SERVCLASS_LAN_ACCESS_USING_PPP, + UUID_SERVCLASS_DIALUP_NETWORKING, UUID_SERVCLASS_IRMC_SYNC, + UUID_SERVCLASS_OBEX_OBJECT_PUSH, UUID_SERVCLASS_OBEX_FILE_TRANSFER, + UUID_SERVCLASS_IRMC_SYNC_COMMAND, UUID_SERVCLASS_HEADSET, + UUID_SERVCLASS_CORDLESS_TELEPHONY, UUID_SERVCLASS_AUDIO_SOURCE, + UUID_SERVCLASS_AUDIO_SINK, UUID_SERVCLASS_AV_REM_CTRL_TARGET, + /* UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ UUID_SERVCLASS_AV_REMOTE_CONTROL, -/* UUID_SERVCLASS_VIDEO_CONFERENCING, */ - UUID_SERVCLASS_INTERCOM, - UUID_SERVCLASS_FAX, + /* UUID_SERVCLASS_VIDEO_CONFERENCING, */ + UUID_SERVCLASS_INTERCOM, UUID_SERVCLASS_FAX, UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, -/* UUID_SERVCLASS_WAP, */ -/* UUID_SERVCLASS_WAP_CLIENT, */ - UUID_SERVCLASS_PANU, - UUID_SERVCLASS_NAP, - UUID_SERVCLASS_GN, + /* UUID_SERVCLASS_WAP, */ + /* UUID_SERVCLASS_WAP_CLIENT, */ + UUID_SERVCLASS_PANU, UUID_SERVCLASS_NAP, UUID_SERVCLASS_GN, UUID_SERVCLASS_DIRECT_PRINTING, -/* UUID_SERVCLASS_REFERENCE_PRINTING, */ - UUID_SERVCLASS_IMAGING, - UUID_SERVCLASS_IMAGING_RESPONDER, - UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, - UUID_SERVCLASS_IMAGING_REF_OBJECTS, - UUID_SERVCLASS_HF_HANDSFREE, - UUID_SERVCLASS_AG_HANDSFREE, + /* UUID_SERVCLASS_REFERENCE_PRINTING, */ + UUID_SERVCLASS_IMAGING, UUID_SERVCLASS_IMAGING_RESPONDER, + UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, UUID_SERVCLASS_IMAGING_REF_OBJECTS, + UUID_SERVCLASS_HF_HANDSFREE, UUID_SERVCLASS_AG_HANDSFREE, UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE, -/* UUID_SERVCLASS_REFLECTED_UI, */ - UUID_SERVCLASS_BASIC_PRINTING, - UUID_SERVCLASS_PRINTING_STATUS, - UUID_SERVCLASS_HUMAN_INTERFACE, - UUID_SERVCLASS_CABLE_REPLACEMENT, - UUID_SERVCLASS_HCRP_PRINT, - UUID_SERVCLASS_HCRP_SCAN, -/* UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ -/* UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ -/* UUID_SERVCLASS_UDI_MT, */ -/* UUID_SERVCLASS_UDI_TA, */ -/* UUID_SERVCLASS_VCP, */ - UUID_SERVCLASS_SAP, - UUID_SERVCLASS_PBAP_PCE, - UUID_SERVCLASS_PBAP_PSE, - UUID_SERVCLASS_PHONE_ACCESS, - UUID_SERVCLASS_HEADSET_HS, + /* UUID_SERVCLASS_REFLECTED_UI, */ + UUID_SERVCLASS_BASIC_PRINTING, UUID_SERVCLASS_PRINTING_STATUS, + UUID_SERVCLASS_HUMAN_INTERFACE, UUID_SERVCLASS_CABLE_REPLACEMENT, + UUID_SERVCLASS_HCRP_PRINT, UUID_SERVCLASS_HCRP_SCAN, + /* UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ + /* UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ + /* UUID_SERVCLASS_UDI_MT, */ + /* UUID_SERVCLASS_UDI_TA, */ + /* UUID_SERVCLASS_VCP, */ + UUID_SERVCLASS_SAP, UUID_SERVCLASS_PBAP_PCE, UUID_SERVCLASS_PBAP_PSE, + UUID_SERVCLASS_PHONE_ACCESS, UUID_SERVCLASS_HEADSET_HS, UUID_SERVCLASS_PNP_INFORMATION, -/* UUID_SERVCLASS_GENERIC_NETWORKING, */ -/* UUID_SERVCLASS_GENERIC_FILETRANSFER, */ -/* UUID_SERVCLASS_GENERIC_AUDIO, */ -/* UUID_SERVCLASS_GENERIC_TELEPHONY, */ -/* UUID_SERVCLASS_UPNP_SERVICE, */ -/* UUID_SERVCLASS_UPNP_IP_SERVICE, */ -/* UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ -/* UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ -/* UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ - UUID_SERVCLASS_VIDEO_SOURCE, - UUID_SERVCLASS_VIDEO_SINK, -/* UUID_SERVCLASS_VIDEO_DISTRIBUTION */ - UUID_SERVCLASS_MESSAGE_ACCESS, - UUID_SERVCLASS_MESSAGE_NOTIFICATION, - UUID_SERVCLASS_HDP_SOURCE, - UUID_SERVCLASS_HDP_SINK -}; + /* UUID_SERVCLASS_GENERIC_NETWORKING, */ + /* UUID_SERVCLASS_GENERIC_FILETRANSFER, */ + /* UUID_SERVCLASS_GENERIC_AUDIO, */ + /* UUID_SERVCLASS_GENERIC_TELEPHONY, */ + /* UUID_SERVCLASS_UPNP_SERVICE, */ + /* UUID_SERVCLASS_UPNP_IP_SERVICE, */ + /* UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ + /* UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ + /* UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ + UUID_SERVCLASS_VIDEO_SOURCE, UUID_SERVCLASS_VIDEO_SINK, + /* UUID_SERVCLASS_VIDEO_DISTRIBUTION */ + UUID_SERVCLASS_MESSAGE_ACCESS, UUID_SERVCLASS_MESSAGE_NOTIFICATION, + UUID_SERVCLASS_HDP_SOURCE, UUID_SERVCLASS_HDP_SINK}; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq); -static tBTM_STATUS btm_set_inq_event_filter (uint8_t filter_cond_type, tBTM_INQ_FILT_COND *p_filt_cond); -static void btm_clr_inq_result_flt (void); - -static uint8_t btm_convert_uuid_to_eir_service( uint16_t uuid16 ); -static void btm_set_eir_uuid( uint8_t *p_eir, tBTM_INQ_RESULTS *p_results ); -static uint8_t *btm_eir_get_uuid_list( uint8_t *p_eir, uint8_t uuid_size, - uint8_t *p_num_uuid, uint8_t *p_uuid_list_type ); -static uint16_t btm_convert_uuid_to_uuid16( uint8_t *p_uuid, uint8_t uuid_size ); +static void btm_initiate_inquiry(tBTM_INQUIRY_VAR_ST* p_inq); +static tBTM_STATUS btm_set_inq_event_filter(uint8_t filter_cond_type, + tBTM_INQ_FILT_COND* p_filt_cond); +static void btm_clr_inq_result_flt(void); + +static uint8_t btm_convert_uuid_to_eir_service(uint16_t uuid16); +static void btm_set_eir_uuid(uint8_t* p_eir, tBTM_INQ_RESULTS* p_results); +static uint8_t* btm_eir_get_uuid_list(uint8_t* p_eir, uint8_t uuid_size, + uint8_t* p_num_uuid, + uint8_t* p_uuid_list_type); +static uint16_t btm_convert_uuid_to_uuid16(uint8_t* p_uuid, uint8_t uuid_size); /******************************************************************************* * @@ -160,116 +139,103 @@ static uint16_t btm_convert_uuid_to_uuid16( uint8_t *p_uuid, uint8_t uuid_si * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetDiscoverability (uint16_t inq_mode, uint16_t window, uint16_t interval) -{ - uint8_t scan_mode = 0; - uint16_t service_class; - uint8_t *p_cod; - uint8_t major, minor; - DEV_CLASS cod; - LAP temp_lap[2]; - bool is_limited; - bool cod_limited; - - BTM_TRACE_API ("BTM_SetDiscoverability"); - if (controller_get_interface()->supports_ble()) - { - if (btm_ble_set_discoverability((uint16_t)(inq_mode)) - == BTM_SUCCESS) - { - btm_cb.btm_inq_vars.discoverable_mode &= (~BTM_BLE_DISCOVERABLE_MASK); - btm_cb.btm_inq_vars.discoverable_mode |= (inq_mode & BTM_BLE_DISCOVERABLE_MASK); - } - } - inq_mode &= ~BTM_BLE_DISCOVERABLE_MASK; - - /*** Check mode parameter ***/ - if (inq_mode > BTM_MAX_DISCOVERABLE) - return (BTM_ILLEGAL_VALUE); - - /* Make sure the controller is active */ - if (!controller_get_interface()->get_is_ready()) - return (BTM_DEV_RESET); - - /* If the window and/or interval is '0', set to default values */ - if (!window) - window = BTM_DEFAULT_DISC_WINDOW; - - if (!interval) - interval = BTM_DEFAULT_DISC_INTERVAL; - - BTM_TRACE_API ("BTM_SetDiscoverability: mode %d [NonDisc-0, Lim-1, Gen-2], window 0x%04x, interval 0x%04x", - inq_mode, window, interval); - - /*** Check for valid window and interval parameters ***/ - /*** Only check window and duration if mode is connectable ***/ - if (inq_mode != BTM_NON_DISCOVERABLE) - { - /* window must be less than or equal to interval */ - if (window < HCI_MIN_INQUIRYSCAN_WINDOW || - window > HCI_MAX_INQUIRYSCAN_WINDOW || - interval < HCI_MIN_INQUIRYSCAN_INTERVAL || - interval > HCI_MAX_INQUIRYSCAN_INTERVAL || - window > interval) - { - return (BTM_ILLEGAL_VALUE); - } - } - - /* Set the IAC if needed */ - if (inq_mode != BTM_NON_DISCOVERABLE) - { - if (inq_mode & BTM_LIMITED_DISCOVERABLE) - { - /* Use the GIAC and LIAC codes for limited discoverable mode */ - memcpy (temp_lap[0], limited_inq_lap, LAP_LEN); - memcpy (temp_lap[1], general_inq_lap, LAP_LEN); - - btsnd_hcic_write_cur_iac_lap(2, (LAP * const) temp_lap); - } - else - { - btsnd_hcic_write_cur_iac_lap(1, (LAP * const) &general_inq_lap); - } - - scan_mode |= HCI_INQUIRY_SCAN_ENABLED; - } - - /* Send down the inquiry scan window and period if changed */ - if ((window != btm_cb.btm_inq_vars.inq_scan_window) || - (interval != btm_cb.btm_inq_vars.inq_scan_period)) - { - btsnd_hcic_write_inqscan_cfg(interval, window); - btm_cb.btm_inq_vars.inq_scan_window = window; - btm_cb.btm_inq_vars.inq_scan_period = interval; - } - - if (btm_cb.btm_inq_vars.connectable_mode & BTM_CONNECTABLE_MASK) - scan_mode |= HCI_PAGE_SCAN_ENABLED; - - btsnd_hcic_write_scan_enable (scan_mode); - btm_cb.btm_inq_vars.discoverable_mode &= (~BTM_DISCOVERABLE_MASK); - btm_cb.btm_inq_vars.discoverable_mode |= inq_mode; +tBTM_STATUS BTM_SetDiscoverability(uint16_t inq_mode, uint16_t window, + uint16_t interval) { + uint8_t scan_mode = 0; + uint16_t service_class; + uint8_t* p_cod; + uint8_t major, minor; + DEV_CLASS cod; + LAP temp_lap[2]; + bool is_limited; + bool cod_limited; + + BTM_TRACE_API("BTM_SetDiscoverability"); + if (controller_get_interface()->supports_ble()) { + if (btm_ble_set_discoverability((uint16_t)(inq_mode)) == BTM_SUCCESS) { + btm_cb.btm_inq_vars.discoverable_mode &= (~BTM_BLE_DISCOVERABLE_MASK); + btm_cb.btm_inq_vars.discoverable_mode |= + (inq_mode & BTM_BLE_DISCOVERABLE_MASK); + } + } + inq_mode &= ~BTM_BLE_DISCOVERABLE_MASK; + + /*** Check mode parameter ***/ + if (inq_mode > BTM_MAX_DISCOVERABLE) return (BTM_ILLEGAL_VALUE); + + /* Make sure the controller is active */ + if (!controller_get_interface()->get_is_ready()) return (BTM_DEV_RESET); + + /* If the window and/or interval is '0', set to default values */ + if (!window) window = BTM_DEFAULT_DISC_WINDOW; + + if (!interval) interval = BTM_DEFAULT_DISC_INTERVAL; + + BTM_TRACE_API( + "BTM_SetDiscoverability: mode %d [NonDisc-0, Lim-1, Gen-2], window " + "0x%04x, interval 0x%04x", + inq_mode, window, interval); + + /*** Check for valid window and interval parameters ***/ + /*** Only check window and duration if mode is connectable ***/ + if (inq_mode != BTM_NON_DISCOVERABLE) { + /* window must be less than or equal to interval */ + if (window < HCI_MIN_INQUIRYSCAN_WINDOW || + window > HCI_MAX_INQUIRYSCAN_WINDOW || + interval < HCI_MIN_INQUIRYSCAN_INTERVAL || + interval > HCI_MAX_INQUIRYSCAN_INTERVAL || window > interval) { + return (BTM_ILLEGAL_VALUE); + } + } + + /* Set the IAC if needed */ + if (inq_mode != BTM_NON_DISCOVERABLE) { + if (inq_mode & BTM_LIMITED_DISCOVERABLE) { + /* Use the GIAC and LIAC codes for limited discoverable mode */ + memcpy(temp_lap[0], limited_inq_lap, LAP_LEN); + memcpy(temp_lap[1], general_inq_lap, LAP_LEN); + + btsnd_hcic_write_cur_iac_lap(2, (LAP * const)temp_lap); + } else { + btsnd_hcic_write_cur_iac_lap(1, (LAP * const) & general_inq_lap); + } + + scan_mode |= HCI_INQUIRY_SCAN_ENABLED; + } + + /* Send down the inquiry scan window and period if changed */ + if ((window != btm_cb.btm_inq_vars.inq_scan_window) || + (interval != btm_cb.btm_inq_vars.inq_scan_period)) { + btsnd_hcic_write_inqscan_cfg(interval, window); + btm_cb.btm_inq_vars.inq_scan_window = window; + btm_cb.btm_inq_vars.inq_scan_period = interval; + } + + if (btm_cb.btm_inq_vars.connectable_mode & BTM_CONNECTABLE_MASK) + scan_mode |= HCI_PAGE_SCAN_ENABLED; + + btsnd_hcic_write_scan_enable(scan_mode); + btm_cb.btm_inq_vars.discoverable_mode &= (~BTM_DISCOVERABLE_MASK); + btm_cb.btm_inq_vars.discoverable_mode |= inq_mode; + + /* Change the service class bit if mode has changed */ + p_cod = BTM_ReadDeviceClass(); + BTM_COD_SERVICE_CLASS(service_class, p_cod); + is_limited = (inq_mode & BTM_LIMITED_DISCOVERABLE) ? true : false; + cod_limited = (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false; + if (is_limited ^ cod_limited) { + BTM_COD_MINOR_CLASS(minor, p_cod); + BTM_COD_MAJOR_CLASS(major, p_cod); + if (is_limited) + service_class |= BTM_COD_SERVICE_LMTD_DISCOVER; + else + service_class &= ~BTM_COD_SERVICE_LMTD_DISCOVER; - /* Change the service class bit if mode has changed */ - p_cod = BTM_ReadDeviceClass(); - BTM_COD_SERVICE_CLASS(service_class, p_cod); - is_limited = (inq_mode & BTM_LIMITED_DISCOVERABLE) ? true : false; - cod_limited = (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false; - if (is_limited ^ cod_limited) - { - BTM_COD_MINOR_CLASS(minor, p_cod ); - BTM_COD_MAJOR_CLASS(major, p_cod ); - if (is_limited) - service_class |= BTM_COD_SERVICE_LMTD_DISCOVER; - else - service_class &= ~BTM_COD_SERVICE_LMTD_DISCOVER; - - FIELDS_TO_COD(cod, minor, major, service_class); - (void) BTM_SetDeviceClass (cod); - } + FIELDS_TO_COD(cod, minor, major, service_class); + (void)BTM_SetDeviceClass(cod); + } - return (BTM_SUCCESS); + return (BTM_SUCCESS); } /******************************************************************************* @@ -284,28 +250,25 @@ tBTM_STATUS BTM_SetDiscoverability (uint16_t inq_mode, uint16_t window, uint16_t * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetInquiryScanType (uint16_t scan_type) -{ - - BTM_TRACE_API ("BTM_SetInquiryScanType"); - if (scan_type != BTM_SCAN_TYPE_STANDARD && scan_type != BTM_SCAN_TYPE_INTERLACED) - return (BTM_ILLEGAL_VALUE); - - /* whatever app wants if device is not 1.2 scan type should be STANDARD */ - if (!controller_get_interface()->supports_interlaced_inquiry_scan()) - return (BTM_MODE_UNSUPPORTED); - - /* Check for scan type if configuration has been changed */ - if (scan_type != btm_cb.btm_inq_vars.inq_scan_type) - { - if (BTM_IsDeviceUp()) - { - btsnd_hcic_write_inqscan_type((uint8_t)scan_type); - btm_cb.btm_inq_vars.inq_scan_type = scan_type; - } - else return (BTM_WRONG_MODE); - } - return (BTM_SUCCESS); +tBTM_STATUS BTM_SetInquiryScanType(uint16_t scan_type) { + BTM_TRACE_API("BTM_SetInquiryScanType"); + if (scan_type != BTM_SCAN_TYPE_STANDARD && + scan_type != BTM_SCAN_TYPE_INTERLACED) + return (BTM_ILLEGAL_VALUE); + + /* whatever app wants if device is not 1.2 scan type should be STANDARD */ + if (!controller_get_interface()->supports_interlaced_inquiry_scan()) + return (BTM_MODE_UNSUPPORTED); + + /* Check for scan type if configuration has been changed */ + if (scan_type != btm_cb.btm_inq_vars.inq_scan_type) { + if (BTM_IsDeviceUp()) { + btsnd_hcic_write_inqscan_type((uint8_t)scan_type); + btm_cb.btm_inq_vars.inq_scan_type = scan_type; + } else + return (BTM_WRONG_MODE); + } + return (BTM_SUCCESS); } /******************************************************************************* @@ -320,30 +283,27 @@ tBTM_STATUS BTM_SetInquiryScanType (uint16_t scan_type) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetPageScanType (uint16_t scan_type) -{ - BTM_TRACE_API ("BTM_SetPageScanType"); - if (scan_type != BTM_SCAN_TYPE_STANDARD && scan_type != BTM_SCAN_TYPE_INTERLACED) - return (BTM_ILLEGAL_VALUE); - - /* whatever app wants if device is not 1.2 scan type should be STANDARD */ - if (!controller_get_interface()->supports_interlaced_inquiry_scan()) - return (BTM_MODE_UNSUPPORTED); - - /* Check for scan type if configuration has been changed */ - if (scan_type != btm_cb.btm_inq_vars.page_scan_type) - { - if (BTM_IsDeviceUp()) - { - btsnd_hcic_write_pagescan_type ((uint8_t)scan_type); - btm_cb.btm_inq_vars.page_scan_type = scan_type; - } - else return (BTM_WRONG_MODE); - } - return (BTM_SUCCESS); +tBTM_STATUS BTM_SetPageScanType(uint16_t scan_type) { + BTM_TRACE_API("BTM_SetPageScanType"); + if (scan_type != BTM_SCAN_TYPE_STANDARD && + scan_type != BTM_SCAN_TYPE_INTERLACED) + return (BTM_ILLEGAL_VALUE); + + /* whatever app wants if device is not 1.2 scan type should be STANDARD */ + if (!controller_get_interface()->supports_interlaced_inquiry_scan()) + return (BTM_MODE_UNSUPPORTED); + + /* Check for scan type if configuration has been changed */ + if (scan_type != btm_cb.btm_inq_vars.page_scan_type) { + if (BTM_IsDeviceUp()) { + btsnd_hcic_write_pagescan_type((uint8_t)scan_type); + btm_cb.btm_inq_vars.page_scan_type = scan_type; + } else + return (BTM_WRONG_MODE); + } + return (BTM_SUCCESS); } - /******************************************************************************* * * Function BTM_SetInquiryMode @@ -359,33 +319,25 @@ tBTM_STATUS BTM_SetPageScanType (uint16_t scan_type) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetInquiryMode (uint8_t mode) -{ - const controller_t *controller = controller_get_interface(); - BTM_TRACE_API ("BTM_SetInquiryMode"); - if (mode == BTM_INQ_RESULT_STANDARD) - { - /* mandatory mode */ - } - else if (mode == BTM_INQ_RESULT_WITH_RSSI) - { - if (!controller->supports_rssi_with_inquiry_results()) - return (BTM_MODE_UNSUPPORTED); - } - else if (mode == BTM_INQ_RESULT_EXTENDED) - { - if (!controller->supports_extended_inquiry_response()) - return (BTM_MODE_UNSUPPORTED); - } - else - return (BTM_ILLEGAL_VALUE); - - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - btsnd_hcic_write_inquiry_mode(mode); - - return (BTM_SUCCESS); +tBTM_STATUS BTM_SetInquiryMode(uint8_t mode) { + const controller_t* controller = controller_get_interface(); + BTM_TRACE_API("BTM_SetInquiryMode"); + if (mode == BTM_INQ_RESULT_STANDARD) { + /* mandatory mode */ + } else if (mode == BTM_INQ_RESULT_WITH_RSSI) { + if (!controller->supports_rssi_with_inquiry_results()) + return (BTM_MODE_UNSUPPORTED); + } else if (mode == BTM_INQ_RESULT_EXTENDED) { + if (!controller->supports_extended_inquiry_response()) + return (BTM_MODE_UNSUPPORTED); + } else + return (BTM_ILLEGAL_VALUE); + + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); + + btsnd_hcic_write_inquiry_mode(mode); + + return (BTM_SUCCESS); } /******************************************************************************* @@ -402,19 +354,15 @@ tBTM_STATUS BTM_SetInquiryMode (uint8_t mode) * BTM_GENERAL_DISCOVERABLE * ******************************************************************************/ -uint16_t BTM_ReadDiscoverability (uint16_t *p_window, uint16_t *p_interval) -{ - BTM_TRACE_API ("BTM_ReadDiscoverability"); - if (p_window) - *p_window = btm_cb.btm_inq_vars.inq_scan_window; +uint16_t BTM_ReadDiscoverability(uint16_t* p_window, uint16_t* p_interval) { + BTM_TRACE_API("BTM_ReadDiscoverability"); + if (p_window) *p_window = btm_cb.btm_inq_vars.inq_scan_window; - if (p_interval) - *p_interval = btm_cb.btm_inq_vars.inq_scan_period; + if (p_interval) *p_interval = btm_cb.btm_inq_vars.inq_scan_period; - return (btm_cb.btm_inq_vars.discoverable_mode); + return (btm_cb.btm_inq_vars.discoverable_mode); } - /******************************************************************************* * * Function BTM_SetPeriodicInquiryMode @@ -453,81 +401,83 @@ uint16_t BTM_ReadDiscoverability (uint16_t *p_window, uint16_t *p_interval) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, uint16_t max_delay, - uint16_t min_delay, tBTM_INQ_RESULTS_CB *p_results_cb) -{ - tBTM_STATUS status; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - BTM_TRACE_API ("BTM_SetPeriodicInquiryMode: mode: %d, dur: %d, rsps: %d, flt: %d, min: %d, max: %d", - p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps, - p_inqparms->filter_cond_type, min_delay, max_delay); - - /*** Make sure the device is ready ***/ - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - /* Only one active inquiry is allowed in this implementation. - Also do not allow an inquiry if the inquiry filter is being updated */ - if (p_inq->inq_active || p_inq->inqfilt_active) - return (BTM_BUSY); - - /* If illegal parameters return false */ - if (p_inqparms->mode != BTM_GENERAL_INQUIRY && - p_inqparms->mode != BTM_LIMITED_INQUIRY) - return (BTM_ILLEGAL_VALUE); - - /* Verify the parameters for this command */ - if (p_inqparms->duration < BTM_MIN_INQUIRY_LEN || - p_inqparms->duration > BTM_MAX_INQUIRY_LENGTH || - min_delay <= p_inqparms->duration || - min_delay < BTM_PER_INQ_MIN_MIN_PERIOD || - min_delay > BTM_PER_INQ_MAX_MIN_PERIOD || - max_delay <= min_delay || - max_delay < BTM_PER_INQ_MIN_MAX_PERIOD) - /* max_delay > BTM_PER_INQ_MAX_MAX_PERIOD)*/ - /* BTM_PER_INQ_MAX_MAX_PERIOD set to 1's in all bits. Condition resulting in false always*/ - { - return (BTM_ILLEGAL_VALUE); - } - - /* Save the inquiry parameters to be used upon the completion of setting/clearing the inquiry filter */ - p_inq->inqparms = *p_inqparms; - p_inq->per_min_delay = min_delay; - p_inq->per_max_delay = max_delay; - p_inq->inq_cmpl_info.num_resp = 0; /* Clear the results counter */ - p_inq->p_inq_results_cb = p_results_cb; - - p_inq->inq_active = (uint8_t)((p_inqparms->mode == BTM_LIMITED_INQUIRY) ? - (BTM_LIMITED_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE) : - (BTM_GENERAL_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE)); - - /* If a filter is specified, then save it for later and clear the current filter. - The setting of the filter is done upon completion of clearing of the previous - filter. - */ - if (p_inqparms->filter_cond_type != BTM_CLR_INQUIRY_FILTER) - { - p_inq->state = BTM_INQ_CLR_FILT_STATE; - p_inqparms->filter_cond_type = BTM_CLR_INQUIRY_FILTER; - } - else /* The filter is not being used so simply clear it; the inquiry can start after this operation */ - p_inq->state = BTM_INQ_SET_FILT_STATE; - - /* Before beginning the inquiry the current filter must be cleared, so initiate the command */ - status = btm_set_inq_event_filter(p_inqparms->filter_cond_type, &p_inqparms->filter_cond); - if (status != BTM_CMD_STARTED) - { - /* If set filter command is not succesful reset the state */ - p_inq->p_inq_results_cb = NULL; - p_inq->state = BTM_INQ_INACTIVE_STATE; - - } +tBTM_STATUS BTM_SetPeriodicInquiryMode(tBTM_INQ_PARMS* p_inqparms, + uint16_t max_delay, uint16_t min_delay, + tBTM_INQ_RESULTS_CB* p_results_cb) { + tBTM_STATUS status; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + + BTM_TRACE_API( + "BTM_SetPeriodicInquiryMode: mode: %d, dur: %d, rsps: %d, flt: %d, min: " + "%d, max: %d", + p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps, + p_inqparms->filter_cond_type, min_delay, max_delay); + + /*** Make sure the device is ready ***/ + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); + + /* Only one active inquiry is allowed in this implementation. + Also do not allow an inquiry if the inquiry filter is being updated */ + if (p_inq->inq_active || p_inq->inqfilt_active) return (BTM_BUSY); + + /* If illegal parameters return false */ + if (p_inqparms->mode != BTM_GENERAL_INQUIRY && + p_inqparms->mode != BTM_LIMITED_INQUIRY) + return (BTM_ILLEGAL_VALUE); + + /* Verify the parameters for this command */ + if (p_inqparms->duration < BTM_MIN_INQUIRY_LEN || + p_inqparms->duration > BTM_MAX_INQUIRY_LENGTH || + min_delay <= p_inqparms->duration || + min_delay < BTM_PER_INQ_MIN_MIN_PERIOD || + min_delay > BTM_PER_INQ_MAX_MIN_PERIOD || max_delay <= min_delay || + max_delay < BTM_PER_INQ_MIN_MAX_PERIOD) + /* max_delay > BTM_PER_INQ_MAX_MAX_PERIOD)*/ + /* BTM_PER_INQ_MAX_MAX_PERIOD set to 1's in all bits. Condition resulting in + false always*/ + { + return (BTM_ILLEGAL_VALUE); + } + + /* Save the inquiry parameters to be used upon the completion of + * setting/clearing the inquiry filter */ + p_inq->inqparms = *p_inqparms; + p_inq->per_min_delay = min_delay; + p_inq->per_max_delay = max_delay; + p_inq->inq_cmpl_info.num_resp = 0; /* Clear the results counter */ + p_inq->p_inq_results_cb = p_results_cb; + + p_inq->inq_active = (uint8_t)( + (p_inqparms->mode == BTM_LIMITED_INQUIRY) + ? (BTM_LIMITED_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE) + : (BTM_GENERAL_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE)); + + /* If a filter is specified, then save it for later and clear the current + filter. + The setting of the filter is done upon completion of clearing of the + previous + filter. + */ + if (p_inqparms->filter_cond_type != BTM_CLR_INQUIRY_FILTER) { + p_inq->state = BTM_INQ_CLR_FILT_STATE; + p_inqparms->filter_cond_type = BTM_CLR_INQUIRY_FILTER; + } else /* The filter is not being used so simply clear it; the inquiry can + start after this operation */ + p_inq->state = BTM_INQ_SET_FILT_STATE; + + /* Before beginning the inquiry the current filter must be cleared, so + * initiate the command */ + status = btm_set_inq_event_filter(p_inqparms->filter_cond_type, + &p_inqparms->filter_cond); + if (status != BTM_CMD_STARTED) { + /* If set filter command is not succesful reset the state */ + p_inq->p_inq_results_cb = NULL; + p_inq->state = BTM_INQ_INACTIVE_STATE; + } - return (status); + return (status); } - /******************************************************************************* * * Function BTM_CancelPeriodicInquiry @@ -540,36 +490,32 @@ tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, uint16_t max * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_CancelPeriodicInquiry(void) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_STATUS status = BTM_SUCCESS; - BTM_TRACE_API ("BTM_CancelPeriodicInquiry called"); - - /*** Make sure the device is ready ***/ - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - /* Only cancel if one is active */ - if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) - { - btm_cb.btm_inq_vars.inq_active = BTM_INQUIRY_INACTIVE; - btm_cb.btm_inq_vars.p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL; +tBTM_STATUS BTM_CancelPeriodicInquiry(void) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_STATUS status = BTM_SUCCESS; + BTM_TRACE_API("BTM_CancelPeriodicInquiry called"); - btsnd_hcic_exit_per_inq(); + /*** Make sure the device is ready ***/ + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); - /* If the event filter is in progress, mark it so that the processing of the return - event will be ignored */ - if(p_inq->inqfilt_active) - p_inq->pending_filt_complete_event++; + /* Only cancel if one is active */ + if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) { + btm_cb.btm_inq_vars.inq_active = BTM_INQUIRY_INACTIVE; + btm_cb.btm_inq_vars.p_inq_results_cb = (tBTM_INQ_RESULTS_CB*)NULL; - p_inq->inqfilt_active = false; - p_inq->inq_counter++; - } + btsnd_hcic_exit_per_inq(); - return (status); -} + /* If the event filter is in progress, mark it so that the processing of the + return + event will be ignored */ + if (p_inq->inqfilt_active) p_inq->pending_filt_complete_event++; + p_inq->inqfilt_active = false; + p_inq->inq_counter++; + } + + return (status); +} /******************************************************************************* * @@ -585,78 +531,69 @@ tBTM_STATUS BTM_CancelPeriodicInquiry(void) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_SetConnectability (uint16_t page_mode, uint16_t window, uint16_t interval) -{ - uint8_t scan_mode = 0; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - BTM_TRACE_API ("BTM_SetConnectability"); - - if (controller_get_interface()->supports_ble()) - { - if (btm_ble_set_connectability(page_mode) != BTM_SUCCESS) - { - return BTM_NO_RESOURCES; - } - p_inq->connectable_mode &= (~BTM_BLE_CONNECTABLE_MASK); - p_inq->connectable_mode |= (page_mode & BTM_BLE_CONNECTABLE_MASK); - } - page_mode &= ~BTM_BLE_CONNECTABLE_MASK; - - /*** Check mode parameter ***/ - if (page_mode != BTM_NON_CONNECTABLE && page_mode != BTM_CONNECTABLE) - return (BTM_ILLEGAL_VALUE); - - /* Make sure the controller is active */ - if (!controller_get_interface()->get_is_ready()) - return (BTM_DEV_RESET); - - /* If the window and/or interval is '0', set to default values */ - if (!window) - window = BTM_DEFAULT_CONN_WINDOW; - - if (!interval) - interval = BTM_DEFAULT_CONN_INTERVAL; - - BTM_TRACE_API ("BTM_SetConnectability: mode %d [NonConn-0, Conn-1], window 0x%04x, interval 0x%04x", - page_mode, window, interval); - - /*** Check for valid window and interval parameters ***/ - /*** Only check window and duration if mode is connectable ***/ - if (page_mode == BTM_CONNECTABLE) - { - /* window must be less than or equal to interval */ - if (window < HCI_MIN_PAGESCAN_WINDOW || - window > HCI_MAX_PAGESCAN_WINDOW || - interval < HCI_MIN_PAGESCAN_INTERVAL || - interval > HCI_MAX_PAGESCAN_INTERVAL || - window > interval) - { - return (BTM_ILLEGAL_VALUE); - } - - scan_mode |= HCI_PAGE_SCAN_ENABLED; - } - - if ((window != p_inq->page_scan_window) || - (interval != p_inq->page_scan_period)) - { - p_inq->page_scan_window = window; - p_inq->page_scan_period = interval; - btsnd_hcic_write_pagescan_cfg(interval, window); - } - - /* Keep the inquiry scan as previouosly set */ - if (p_inq->discoverable_mode & BTM_DISCOVERABLE_MASK) - scan_mode |= HCI_INQUIRY_SCAN_ENABLED; - - btsnd_hcic_write_scan_enable (scan_mode); - p_inq->connectable_mode &= (~BTM_CONNECTABLE_MASK); - p_inq->connectable_mode |= page_mode; - return (BTM_SUCCESS); +tBTM_STATUS BTM_SetConnectability(uint16_t page_mode, uint16_t window, + uint16_t interval) { + uint8_t scan_mode = 0; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + + BTM_TRACE_API("BTM_SetConnectability"); + + if (controller_get_interface()->supports_ble()) { + if (btm_ble_set_connectability(page_mode) != BTM_SUCCESS) { + return BTM_NO_RESOURCES; + } + p_inq->connectable_mode &= (~BTM_BLE_CONNECTABLE_MASK); + p_inq->connectable_mode |= (page_mode & BTM_BLE_CONNECTABLE_MASK); + } + page_mode &= ~BTM_BLE_CONNECTABLE_MASK; + + /*** Check mode parameter ***/ + if (page_mode != BTM_NON_CONNECTABLE && page_mode != BTM_CONNECTABLE) + return (BTM_ILLEGAL_VALUE); + + /* Make sure the controller is active */ + if (!controller_get_interface()->get_is_ready()) return (BTM_DEV_RESET); + + /* If the window and/or interval is '0', set to default values */ + if (!window) window = BTM_DEFAULT_CONN_WINDOW; + + if (!interval) interval = BTM_DEFAULT_CONN_INTERVAL; + + BTM_TRACE_API( + "BTM_SetConnectability: mode %d [NonConn-0, Conn-1], window 0x%04x, " + "interval 0x%04x", + page_mode, window, interval); + + /*** Check for valid window and interval parameters ***/ + /*** Only check window and duration if mode is connectable ***/ + if (page_mode == BTM_CONNECTABLE) { + /* window must be less than or equal to interval */ + if (window < HCI_MIN_PAGESCAN_WINDOW || window > HCI_MAX_PAGESCAN_WINDOW || + interval < HCI_MIN_PAGESCAN_INTERVAL || + interval > HCI_MAX_PAGESCAN_INTERVAL || window > interval) { + return (BTM_ILLEGAL_VALUE); + } + + scan_mode |= HCI_PAGE_SCAN_ENABLED; + } + + if ((window != p_inq->page_scan_window) || + (interval != p_inq->page_scan_period)) { + p_inq->page_scan_window = window; + p_inq->page_scan_period = interval; + btsnd_hcic_write_pagescan_cfg(interval, window); + } + + /* Keep the inquiry scan as previouosly set */ + if (p_inq->discoverable_mode & BTM_DISCOVERABLE_MASK) + scan_mode |= HCI_INQUIRY_SCAN_ENABLED; + + btsnd_hcic_write_scan_enable(scan_mode); + p_inq->connectable_mode &= (~BTM_CONNECTABLE_MASK); + p_inq->connectable_mode |= page_mode; + return (BTM_SUCCESS); } - /******************************************************************************* * * Function BTM_ReadConnectability @@ -669,20 +606,15 @@ tBTM_STATUS BTM_SetConnectability (uint16_t page_mode, uint16_t window, uint16_t * Returns BTM_NON_CONNECTABLE or BTM_CONNECTABLE * ******************************************************************************/ -uint16_t BTM_ReadConnectability (uint16_t *p_window, uint16_t *p_interval) -{ - BTM_TRACE_API ("BTM_ReadConnectability"); - if (p_window) - *p_window = btm_cb.btm_inq_vars.page_scan_window; +uint16_t BTM_ReadConnectability(uint16_t* p_window, uint16_t* p_interval) { + BTM_TRACE_API("BTM_ReadConnectability"); + if (p_window) *p_window = btm_cb.btm_inq_vars.page_scan_window; - if (p_interval) - *p_interval = btm_cb.btm_inq_vars.page_scan_period; + if (p_interval) *p_interval = btm_cb.btm_inq_vars.page_scan_period; - return (btm_cb.btm_inq_vars.connectable_mode); + return (btm_cb.btm_inq_vars.connectable_mode); } - - /******************************************************************************* * * Function BTM_IsInquiryActive @@ -696,15 +628,12 @@ uint16_t BTM_ReadConnectability (uint16_t *p_window, uint16_t *p_interval) * BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active * ******************************************************************************/ -uint16_t BTM_IsInquiryActive (void) -{ - BTM_TRACE_API ("BTM_IsInquiryActive"); +uint16_t BTM_IsInquiryActive(void) { + BTM_TRACE_API("BTM_IsInquiryActive"); - return(btm_cb.btm_inq_vars.inq_active); + return (btm_cb.btm_inq_vars.inq_active); } - - /******************************************************************************* * * Function BTM_CancelInquiry @@ -716,67 +645,64 @@ uint16_t BTM_IsInquiryActive (void) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_CancelInquiry(void) -{ - tBTM_STATUS status = BTM_SUCCESS; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; +tBTM_STATUS BTM_CancelInquiry(void) { + tBTM_STATUS status = BTM_SUCCESS; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - uint8_t active_mode=p_inq->inq_active; + uint8_t active_mode = p_inq->inq_active; #endif - BTM_TRACE_API ("BTM_CancelInquiry called"); + BTM_TRACE_API("BTM_CancelInquiry called"); - /*** Make sure the device is ready ***/ - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - /* Only cancel if not in periodic mode, otherwise the caller should call BTM_CancelPeriodicMode */ - if ((p_inq->inq_active &BTM_INQUIRY_ACTIVE_MASK) != 0 && - (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE))) - { - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - p_inq->state = BTM_INQ_INACTIVE_STATE; - p_inq->p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL; /* Do not notify caller anymore */ - p_inq->p_inq_cmpl_cb = (tBTM_CMPL_CB *) NULL; /* Do not notify caller anymore */ + /*** Make sure the device is ready ***/ + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); - /* If the event filter is in progress, mark it so that the processing of the return - event will be ignored */ - if (p_inq->inqfilt_active) - { - p_inq->inqfilt_active = false; - p_inq->pending_filt_complete_event++; - } - /* Initiate the cancel inquiry */ - else - { - if (((p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK) != 0) + /* Only cancel if not in periodic mode, otherwise the caller should call + * BTM_CancelPeriodicMode */ + if ((p_inq->inq_active & BTM_INQUIRY_ACTIVE_MASK) != 0 && + (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE))) { + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + p_inq->state = BTM_INQ_INACTIVE_STATE; + p_inq->p_inq_results_cb = + (tBTM_INQ_RESULTS_CB*)NULL; /* Do not notify caller anymore */ + p_inq->p_inq_cmpl_cb = + (tBTM_CMPL_CB*)NULL; /* Do not notify caller anymore */ + + /* If the event filter is in progress, mark it so that the processing of the + return + event will be ignored */ + if (p_inq->inqfilt_active) { + p_inq->inqfilt_active = false; + p_inq->pending_filt_complete_event++; + } + /* Initiate the cancel inquiry */ + else { + if (((p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK) != 0) #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - &&(active_mode & BTM_BR_INQUIRY_MASK) + && (active_mode & BTM_BR_INQUIRY_MASK) #endif - ) - { - btsnd_hcic_inq_cancel(); - } - if (((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) + ) { + btsnd_hcic_inq_cancel(); + } + if (((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - &&(active_mode & BTM_BLE_INQ_ACTIVE_MASK) + && (active_mode & BTM_BLE_INQ_ACTIVE_MASK) #endif - ) - btm_ble_stop_inquiry(); - } + ) + btm_ble_stop_inquiry(); + } - /* Do not send the BUSY_LEVEL event yet. Wait for the cancel_complete event - * and then send the BUSY_LEVEL event - * btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); - */ + /* Do not send the BUSY_LEVEL event yet. Wait for the cancel_complete event + * and then send the BUSY_LEVEL event + * btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); + */ - p_inq->inq_counter++; - btm_clr_inq_result_flt(); - } + p_inq->inq_counter++; + btm_clr_inq_result_flt(); + } - return (status); + return (status); } - /******************************************************************************* * * Function BTM_StartInquiry @@ -814,162 +740,154 @@ tBTM_STATUS BTM_CancelInquiry(void) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p_results_cb, - tBTM_CMPL_CB *p_cmpl_cb) -{ - tBTM_STATUS status = BTM_CMD_STARTED; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - BTM_TRACE_API ("BTM_StartInquiry: mode: %d, dur: %d, rsps: %d, flt: %d", - p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps, - p_inqparms->filter_cond_type); - - /* Only one active inquiry is allowed in this implementation. - Also do not allow an inquiry if the inquiry filter is being updated */ - if (p_inq->inq_active || p_inq->inqfilt_active) - { - /*check if LE observe is already running*/ - if(p_inq->scan_type==INQ_LE_OBSERVE && p_inq->p_inq_ble_results_cb!=NULL) - { - BTM_TRACE_API("BTM_StartInquiry: LE observe in progress"); - p_inq->scan_type = INQ_GENERAL; - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; - btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); - } - else - { - return (BTM_BUSY); - BTM_TRACE_API("BTM_StartInquiry: return BUSY"); - } - } - else - p_inq->scan_type = INQ_GENERAL; - - /*** Make sure the device is ready ***/ - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK)!= BTM_GENERAL_INQUIRY && - (p_inqparms->mode & BTM_BR_INQUIRY_MASK)!= BTM_LIMITED_INQUIRY && - (p_inqparms->mode & BTM_BLE_INQUIRY_MASK)!= BTM_BLE_GENERAL_INQUIRY && - (p_inqparms->mode & BTM_BLE_INQUIRY_MASK)!= BTM_BLE_LIMITED_INQUIRY) - return (BTM_ILLEGAL_VALUE); +tBTM_STATUS BTM_StartInquiry(tBTM_INQ_PARMS* p_inqparms, + tBTM_INQ_RESULTS_CB* p_results_cb, + tBTM_CMPL_CB* p_cmpl_cb) { + tBTM_STATUS status = BTM_CMD_STARTED; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + + BTM_TRACE_API("BTM_StartInquiry: mode: %d, dur: %d, rsps: %d, flt: %d", + p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps, + p_inqparms->filter_cond_type); + + /* Only one active inquiry is allowed in this implementation. + Also do not allow an inquiry if the inquiry filter is being updated */ + if (p_inq->inq_active || p_inq->inqfilt_active) { + /*check if LE observe is already running*/ + if (p_inq->scan_type == INQ_LE_OBSERVE && + p_inq->p_inq_ble_results_cb != NULL) { + BTM_TRACE_API("BTM_StartInquiry: LE observe in progress"); + p_inq->scan_type = INQ_GENERAL; + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; + btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_DISABLE, + BTM_BLE_DUPLICATE_ENABLE); + } else { + return (BTM_BUSY); + BTM_TRACE_API("BTM_StartInquiry: return BUSY"); + } + } else + p_inq->scan_type = INQ_GENERAL; + + /*** Make sure the device is ready ***/ + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); + + if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK) != BTM_GENERAL_INQUIRY && + (p_inqparms->mode & BTM_BR_INQUIRY_MASK) != BTM_LIMITED_INQUIRY && + (p_inqparms->mode & BTM_BLE_INQUIRY_MASK) != BTM_BLE_GENERAL_INQUIRY && + (p_inqparms->mode & BTM_BLE_INQUIRY_MASK) != BTM_BLE_LIMITED_INQUIRY) + return (BTM_ILLEGAL_VALUE); #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - if(p_inq->next_state==BTM_FINISH) - return BTM_ILLEGAL_VALUE; + if (p_inq->next_state == BTM_FINISH) return BTM_ILLEGAL_VALUE; #endif - /* Save the inquiry parameters to be used upon the completion of setting/clearing the inquiry filter */ - p_inq->inqparms = *p_inqparms; + /* Save the inquiry parameters to be used upon the completion of + * setting/clearing the inquiry filter */ + p_inq->inqparms = *p_inqparms; - /* Initialize the inquiry variables */ - p_inq->state = BTM_INQ_ACTIVE_STATE; - p_inq->p_inq_cmpl_cb = p_cmpl_cb; - p_inq->p_inq_results_cb = p_results_cb; - p_inq->inq_cmpl_info.num_resp = 0; /* Clear the results counter */ - p_inq->inq_active = p_inqparms->mode; + /* Initialize the inquiry variables */ + p_inq->state = BTM_INQ_ACTIVE_STATE; + p_inq->p_inq_cmpl_cb = p_cmpl_cb; + p_inq->p_inq_results_cb = p_results_cb; + p_inq->inq_cmpl_info.num_resp = 0; /* Clear the results counter */ + p_inq->inq_active = p_inqparms->mode; - BTM_TRACE_DEBUG("BTM_StartInquiry: p_inq->inq_active = 0x%02x", p_inq->inq_active); + BTM_TRACE_DEBUG("BTM_StartInquiry: p_inq->inq_active = 0x%02x", + p_inq->inq_active); /* interleave scan minimal conditions */ #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - /* check if both modes are present */ - if((p_inqparms->mode & BTM_BLE_INQUIRY_MASK) && (p_inqparms->mode & BTM_BR_INQUIRY_MASK)) - { - BTM_TRACE_API("BTM:Interleave Inquiry Mode Set"); - p_inqparms->duration=p_inqparms->intl_duration[p_inq->next_state]; - p_inq->inqparms.duration=p_inqparms->duration; - } - else - { - BTM_TRACE_API("BTM:Single Mode: No interleaving, Mode:0x%02x", p_inqparms->mode); - p_inq->next_state=BTM_NO_INTERLEAVING; - } + /* check if both modes are present */ + if ((p_inqparms->mode & BTM_BLE_INQUIRY_MASK) && + (p_inqparms->mode & BTM_BR_INQUIRY_MASK)) { + BTM_TRACE_API("BTM:Interleave Inquiry Mode Set"); + p_inqparms->duration = p_inqparms->intl_duration[p_inq->next_state]; + p_inq->inqparms.duration = p_inqparms->duration; + } else { + BTM_TRACE_API("BTM:Single Mode: No interleaving, Mode:0x%02x", + p_inqparms->mode); + p_inq->next_state = BTM_NO_INTERLEAVING; + } #endif - - -/* start LE inquiry here if requested */ - if ((p_inqparms->mode & BTM_BLE_INQUIRY_MASK) + /* start LE inquiry here if requested */ + if ((p_inqparms->mode & BTM_BLE_INQUIRY_MASK) #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - &&(p_inq->next_state==BTM_BLE_ONE || p_inq->next_state==BTM_BLE_TWO || - p_inq->next_state==BTM_NO_INTERLEAVING) + && + (p_inq->next_state == BTM_BLE_ONE || p_inq->next_state == BTM_BLE_TWO || + p_inq->next_state == BTM_NO_INTERLEAVING) #endif - ) + ) - { + { #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - p_inq->inq_active = (p_inqparms->mode & BTM_BLE_INQUIRY_MASK); - BTM_TRACE_API("BTM:Starting LE Scan with duration %d and activeMode:0x%02x", - p_inqparms->duration, (p_inqparms->mode & BTM_BLE_INQUIRY_MASK)); + p_inq->inq_active = (p_inqparms->mode & BTM_BLE_INQUIRY_MASK); + BTM_TRACE_API("BTM:Starting LE Scan with duration %d and activeMode:0x%02x", + p_inqparms->duration, + (p_inqparms->mode & BTM_BLE_INQUIRY_MASK)); #endif - if (!controller_get_interface()->supports_ble()) - { - p_inq->inqparms.mode &= ~ BTM_BLE_INQUIRY_MASK; - status = BTM_ILLEGAL_VALUE; - } - /* BLE for now does not support filter condition for inquiry */ - else { - status = btm_ble_start_inquiry((uint8_t)(p_inqparms->mode & BTM_BLE_INQUIRY_MASK), p_inqparms->duration); - if (status != BTM_CMD_STARTED) - { - BTM_TRACE_ERROR("Err Starting LE Inquiry."); - p_inq->inqparms.mode &= ~ BTM_BLE_INQUIRY_MASK; - } - } + if (!controller_get_interface()->supports_ble()) { + p_inq->inqparms.mode &= ~BTM_BLE_INQUIRY_MASK; + status = BTM_ILLEGAL_VALUE; + } + /* BLE for now does not support filter condition for inquiry */ + else { + status = btm_ble_start_inquiry( + (uint8_t)(p_inqparms->mode & BTM_BLE_INQUIRY_MASK), + p_inqparms->duration); + if (status != BTM_CMD_STARTED) { + BTM_TRACE_ERROR("Err Starting LE Inquiry."); + p_inq->inqparms.mode &= ~BTM_BLE_INQUIRY_MASK; + } + } #if (BTA_HOST_INTERLEAVE_SEARCH == FALSE) - p_inqparms->mode &= ~BTM_BLE_INQUIRY_MASK; + p_inqparms->mode &= ~BTM_BLE_INQUIRY_MASK; #endif #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - if(p_inq->next_state==BTM_NO_INTERLEAVING) - { - p_inq->next_state=BTM_FINISH; - } - else - { - BTM_TRACE_API("BTM:Interleaving: started LE scan, Advancing to next state: %d", - p_inq->next_state+1); - p_inq->next_state+=1; - } - /* reset next_state if status <> BTM_Started */ - if(status!=BTM_CMD_STARTED) - p_inq->next_state=BTM_BR_ONE; - - /* if interleave scan..return here */ - return status; + if (p_inq->next_state == BTM_NO_INTERLEAVING) { + p_inq->next_state = BTM_FINISH; + } else { + BTM_TRACE_API( + "BTM:Interleaving: started LE scan, Advancing to next state: %d", + p_inq->next_state + 1); + p_inq->next_state += 1; + } + /* reset next_state if status <> BTM_Started */ + if (status != BTM_CMD_STARTED) p_inq->next_state = BTM_BR_ONE; + + /* if interleave scan..return here */ + return status; #endif + BTM_TRACE_DEBUG("BTM_StartInquiry: mode = %02x", p_inqparms->mode); + } - BTM_TRACE_DEBUG("BTM_StartInquiry: mode = %02x", p_inqparms->mode); - } - - /* we're done with this routine if BR/EDR inquiry is not desired. */ - if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK) == BTM_INQUIRY_NONE) - return status; + /* we're done with this routine if BR/EDR inquiry is not desired. */ + if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK) == BTM_INQUIRY_NONE) + return status; - /* BR/EDR inquiry portion */ +/* BR/EDR inquiry portion */ #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - if((p_inq->next_state==BTM_BR_ONE || p_inq->next_state==BTM_BR_TWO || - p_inq->next_state==BTM_NO_INTERLEAVING )) - { - p_inq->inq_active = (p_inqparms->mode & BTM_BR_INQUIRY_MASK); + if ((p_inq->next_state == BTM_BR_ONE || p_inq->next_state == BTM_BR_TWO || + p_inq->next_state == BTM_NO_INTERLEAVING)) { + p_inq->inq_active = (p_inqparms->mode & BTM_BR_INQUIRY_MASK); #endif - /* If a filter is specified, then save it for later and clear the current filter. - The setting of the filter is done upon completion of clearing of the previous + /* If a filter is specified, then save it for later and clear the current + filter. + The setting of the filter is done upon completion of clearing of the + previous filter. */ - switch (p_inqparms->filter_cond_type) - { - case BTM_CLR_INQUIRY_FILTER: + switch (p_inqparms->filter_cond_type) { + case BTM_CLR_INQUIRY_FILTER: p_inq->state = BTM_INQ_SET_FILT_STATE; break; - case BTM_FILTER_COND_DEVICE_CLASS: - case BTM_FILTER_COND_BD_ADDR: + case BTM_FILTER_COND_DEVICE_CLASS: + case BTM_FILTER_COND_BD_ADDR: /* The filter is not being used so simply clear it; the inquiry can start after this operation */ p_inq->state = BTM_INQ_CLR_FILT_STATE; @@ -977,40 +895,39 @@ tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p /* =============>>>> adding LE filtering here ????? */ break; - default: + default: return (BTM_ILLEGAL_VALUE); } - /* Before beginning the inquiry the current filter must be cleared, so initiate the command */ - status = btm_set_inq_event_filter(p_inqparms->filter_cond_type, &p_inqparms->filter_cond); - if (status != BTM_CMD_STARTED) - p_inq->state = BTM_INQ_INACTIVE_STATE; + /* Before beginning the inquiry the current filter must be cleared, so + * initiate the command */ + status = btm_set_inq_event_filter(p_inqparms->filter_cond_type, + &p_inqparms->filter_cond); + if (status != BTM_CMD_STARTED) p_inq->state = BTM_INQ_INACTIVE_STATE; #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - if (p_inq->next_state==BTM_NO_INTERLEAVING) - p_inq->next_state=BTM_FINISH; - else - { - BTM_TRACE_API("BTM:Interleaving: Started BTM inq, Advancing to next state: %d", - p_inq->next_state+1); - p_inq->next_state+=1; - } - } - if (status!=BTM_CMD_STARTED) - { - /* Some error beginning the scan process. - Reset the next_state parameter.. Do we need to reset the inq_active also? - */ - BTM_TRACE_API("BTM:Interleaving: Error in Starting inquiry, status: 0x%02x", status); - p_inq->next_state=BTM_BR_ONE; - } + if (p_inq->next_state == BTM_NO_INTERLEAVING) + p_inq->next_state = BTM_FINISH; + else { + BTM_TRACE_API( + "BTM:Interleaving: Started BTM inq, Advancing to next state: %d", + p_inq->next_state + 1); + p_inq->next_state += 1; + } + } + if (status != BTM_CMD_STARTED) { + /* Some error beginning the scan process. + Reset the next_state parameter.. Do we need to reset the inq_active also? + */ + BTM_TRACE_API("BTM:Interleaving: Error in Starting inquiry, status: 0x%02x", + status); + p_inq->next_state = BTM_BR_ONE; + } #endif - - return (status); + return (status); } - /******************************************************************************* * * Function BTM_ReadRemoteDeviceName @@ -1035,36 +952,34 @@ tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb - ,tBT_TRANSPORT transport) -{ - tBTM_INQ_INFO *p_cur = NULL; - tINQ_DB_ENT *p_i; - - BTM_TRACE_API ("BTM_ReadRemoteDeviceName: bd addr [%02x%02x%02x%02x%02x%02x]", - remote_bda[0], remote_bda[1], remote_bda[2], - remote_bda[3], remote_bda[4], remote_bda[5]); - - /* Use the remote device's clock offset if it is in the local inquiry database */ - p_i = btm_inq_db_find(remote_bda); - if (p_i != NULL) - { - p_cur = &p_i->inq_info; - if ((p_cur->results.ble_evt_type == BTM_BLE_EVT_NON_CONN_ADV) && - (p_cur->results.device_type != BT_DEVICE_TYPE_BREDR)) - {/* Non-connectable LE device: do not request its name! */ - return BTM_ERR_PROCESSING; - } - } - BTM_TRACE_API ("no device found in inquiry db"); - - if (transport == BT_TRANSPORT_LE) - { - return btm_ble_read_remote_name(remote_bda, p_cur, p_cb); - } - else - return (btm_initiate_rem_name (remote_bda, p_cur, BTM_RMT_NAME_EXT, - BTM_EXT_RMT_NAME_TIMEOUT_MS, p_cb)); +tBTM_STATUS BTM_ReadRemoteDeviceName(BD_ADDR remote_bda, tBTM_CMPL_CB* p_cb, + tBT_TRANSPORT transport) { + tBTM_INQ_INFO* p_cur = NULL; + tINQ_DB_ENT* p_i; + + BTM_TRACE_API("BTM_ReadRemoteDeviceName: bd addr [%02x%02x%02x%02x%02x%02x]", + remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3], + remote_bda[4], remote_bda[5]); + + /* Use the remote device's clock offset if it is in the local inquiry database + */ + p_i = btm_inq_db_find(remote_bda); + if (p_i != NULL) { + p_cur = &p_i->inq_info; + if ((p_cur->results.ble_evt_type == BTM_BLE_EVT_NON_CONN_ADV) && + (p_cur->results.device_type != + BT_DEVICE_TYPE_BREDR)) { /* Non-connectable LE device: do not request + its name! */ + return BTM_ERR_PROCESSING; + } + } + BTM_TRACE_API("no device found in inquiry db"); + + if (transport == BT_TRANSPORT_LE) { + return btm_ble_read_remote_name(remote_bda, p_cur, p_cb); + } else + return (btm_initiate_rem_name(remote_bda, p_cur, BTM_RMT_NAME_EXT, + BTM_EXT_RMT_NAME_TIMEOUT_MS, p_cb)); } /******************************************************************************* @@ -1085,28 +1000,23 @@ tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb * request. * ******************************************************************************/ -tBTM_STATUS BTM_CancelRemoteDeviceName (void) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; +tBTM_STATUS BTM_CancelRemoteDeviceName(void) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; - BTM_TRACE_API ("BTM_CancelRemoteDeviceName()"); + BTM_TRACE_API("BTM_CancelRemoteDeviceName()"); - /* Make sure there is not already one in progress */ - if (p_inq->remname_active) - { - if (BTM_UseLeLink(p_inq->remname_bda)) - { - if (btm_ble_cancel_remote_name(p_inq->remname_bda)) - return (BTM_CMD_STARTED); - else - return (BTM_UNKNOWN_ADDR); - } - else - btsnd_hcic_rmt_name_req_cancel(p_inq->remname_bda); + /* Make sure there is not already one in progress */ + if (p_inq->remname_active) { + if (BTM_UseLeLink(p_inq->remname_bda)) { + if (btm_ble_cancel_remote_name(p_inq->remname_bda)) return (BTM_CMD_STARTED); - } - else - return (BTM_WRONG_MODE); + else + return (BTM_UNKNOWN_ADDR); + } else + btsnd_hcic_rmt_name_req_cancel(p_inq->remname_bda); + return (BTM_CMD_STARTED); + } else + return (BTM_WRONG_MODE); } /******************************************************************************* @@ -1121,19 +1031,16 @@ tBTM_STATUS BTM_CancelRemoteDeviceName (void) * Returns pointer to entry, or NULL if not found * ******************************************************************************/ -tBTM_INQ_INFO *BTM_InqDbRead (const BD_ADDR p_bda) -{ - BTM_TRACE_API ("BTM_InqDbRead: bd addr [%02x%02x%02x%02x%02x%02x]", - p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); +tBTM_INQ_INFO* BTM_InqDbRead(const BD_ADDR p_bda) { + BTM_TRACE_API("BTM_InqDbRead: bd addr [%02x%02x%02x%02x%02x%02x]", p_bda[0], + p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); - tINQ_DB_ENT *p_ent = btm_inq_db_find(p_bda); - if (!p_ent) - return NULL; + tINQ_DB_ENT* p_ent = btm_inq_db_find(p_bda); + if (!p_ent) return NULL; - return &p_ent->inq_info; + return &p_ent->inq_info; } - /******************************************************************************* * * Function BTM_InqDbFirst @@ -1147,22 +1054,18 @@ tBTM_INQ_INFO *BTM_InqDbRead (const BD_ADDR p_bda) * Returns pointer to first in-use entry, or NULL if DB is empty * ******************************************************************************/ -tBTM_INQ_INFO *BTM_InqDbFirst (void) -{ - uint16_t xx; - tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; +tBTM_INQ_INFO* BTM_InqDbFirst(void) { + uint16_t xx; + tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; - for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) - { - if (p_ent->in_use) - return (&p_ent->inq_info); - } + for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { + if (p_ent->in_use) return (&p_ent->inq_info); + } - /* If here, no used entry found */ - return ((tBTM_INQ_INFO *)NULL); + /* If here, no used entry found */ + return ((tBTM_INQ_INFO*)NULL); } - /******************************************************************************* * * Function BTM_InqDbNext @@ -1174,29 +1077,24 @@ tBTM_INQ_INFO *BTM_InqDbFirst (void) * Returns pointer to next in-use entry, or NULL if no more found. * ******************************************************************************/ -tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur) -{ - tINQ_DB_ENT *p_ent; - uint16_t inx; - - if (p_cur) - { - p_ent = (tINQ_DB_ENT *) ((uint8_t *)p_cur - offsetof (tINQ_DB_ENT, inq_info)); - inx = (uint16_t)((p_ent - btm_cb.btm_inq_vars.inq_db) + 1); +tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) { + tINQ_DB_ENT* p_ent; + uint16_t inx; - for (p_ent = &btm_cb.btm_inq_vars.inq_db[inx]; inx < BTM_INQ_DB_SIZE; inx++, p_ent++) - { - if (p_ent->in_use) - return (&p_ent->inq_info); - } + if (p_cur) { + p_ent = (tINQ_DB_ENT*)((uint8_t*)p_cur - offsetof(tINQ_DB_ENT, inq_info)); + inx = (uint16_t)((p_ent - btm_cb.btm_inq_vars.inq_db) + 1); - /* If here, more entries found */ - return ((tBTM_INQ_INFO *)NULL); + for (p_ent = &btm_cb.btm_inq_vars.inq_db[inx]; inx < BTM_INQ_DB_SIZE; + inx++, p_ent++) { + if (p_ent->in_use) return (&p_ent->inq_info); } - else - return (BTM_InqDbFirst()); -} + /* If here, more entries found */ + return ((tBTM_INQ_INFO*)NULL); + } else + return (BTM_InqDbFirst()); +} /******************************************************************************* * @@ -1212,18 +1110,16 @@ tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur) * is active, otherwise BTM_SUCCESS * ******************************************************************************/ -tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; +tBTM_STATUS BTM_ClearInqDb(BD_ADDR p_bda) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; - /* If an inquiry or remote name is in progress return busy */ - if (p_inq->inq_active != BTM_INQUIRY_INACTIVE || - p_inq->inqfilt_active) - return (BTM_BUSY); + /* If an inquiry or remote name is in progress return busy */ + if (p_inq->inq_active != BTM_INQUIRY_INACTIVE || p_inq->inqfilt_active) + return (BTM_BUSY); - btm_clr_inq_db(p_bda); + btm_clr_inq_db(p_bda); - return (BTM_SUCCESS); + return (BTM_SUCCESS); } /******************************************************************************* @@ -1237,19 +1133,16 @@ tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda) * Returns BTM_SUCCESS if successful * ******************************************************************************/ -tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb) -{ - if (btm_cb.devcb.p_inq_tx_power_cmpl_cb) - return (BTM_BUSY); - - btm_cb.devcb.p_inq_tx_power_cmpl_cb = p_cb; - alarm_set_on_queue(btm_cb.devcb.read_inq_tx_power_timer, - BTM_INQ_REPLY_TIMEOUT_MS, - btm_read_inq_tx_power_timeout, NULL, - btu_general_alarm_queue); - - btsnd_hcic_read_inq_tx_power(); - return (BTM_CMD_STARTED); +tBTM_STATUS BTM_ReadInquiryRspTxPower(tBTM_CMPL_CB* p_cb) { + if (btm_cb.devcb.p_inq_tx_power_cmpl_cb) return (BTM_BUSY); + + btm_cb.devcb.p_inq_tx_power_cmpl_cb = p_cb; + alarm_set_on_queue(btm_cb.devcb.read_inq_tx_power_timer, + BTM_INQ_REPLY_TIMEOUT_MS, btm_read_inq_tx_power_timeout, + NULL, btu_general_alarm_queue); + + btsnd_hcic_read_inq_tx_power(); + return (BTM_CMD_STARTED); } /******************************************************************************* @@ -1269,78 +1162,72 @@ tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb) * Returns void * ******************************************************************************/ -void btm_inq_db_reset (void) -{ - tBTM_REMOTE_DEV_NAME rem_name; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - uint8_t num_responses; - uint8_t temp_inq_active; - tBTM_STATUS status; - - /* If an inquiry or periodic inquiry is active, reset the mode to inactive */ - if (p_inq->inq_active != BTM_INQUIRY_INACTIVE) - { - temp_inq_active = p_inq->inq_active; /* Save so state can change BEFORE - callback is called */ - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - - /* If not a periodic inquiry, the complete callback must be called to notify caller */ - if (temp_inq_active == BTM_LIMITED_INQUIRY_ACTIVE || - temp_inq_active == BTM_GENERAL_INQUIRY_ACTIVE) - { - if (p_inq->p_inq_cmpl_cb) - { - num_responses = 0; - (*p_inq->p_inq_cmpl_cb)(&num_responses); - } - } - } - - /* Cancel a remote name request if active, and notify the caller (if waiting) */ - if (p_inq->remname_active ) - { - alarm_cancel(p_inq->remote_name_timer); - p_inq->remname_active = false; - memset(p_inq->remname_bda, 0, BD_ADDR_LEN); - - if (p_inq->p_remname_cmpl_cb) - { - rem_name.status = BTM_DEV_RESET; - - (*p_inq->p_remname_cmpl_cb)(&rem_name); - p_inq->p_remname_cmpl_cb = NULL; - } - } - - /* Cancel an inquiry filter request if active, and notify the caller (if waiting) */ - if (p_inq->inqfilt_active) - { - p_inq->inqfilt_active = false; - - if (p_inq->p_inqfilter_cmpl_cb) - { - status = BTM_DEV_RESET; - (*p_inq->p_inqfilter_cmpl_cb)(&status); - } - } - - p_inq->state = BTM_INQ_INACTIVE_STATE; - p_inq->pending_filt_complete_event = 0; - p_inq->p_inq_results_cb = NULL; - btm_clr_inq_db(NULL); /* Clear out all the entries in the database */ - btm_clr_inq_result_flt(); - - p_inq->discoverable_mode = BTM_NON_DISCOVERABLE; - p_inq->connectable_mode = BTM_NON_CONNECTABLE; - p_inq->page_scan_type = BTM_SCAN_TYPE_STANDARD; - p_inq->inq_scan_type = BTM_SCAN_TYPE_STANDARD; - - p_inq->discoverable_mode |= BTM_BLE_NON_DISCOVERABLE; - p_inq->connectable_mode |= BTM_BLE_NON_CONNECTABLE; - return; +void btm_inq_db_reset(void) { + tBTM_REMOTE_DEV_NAME rem_name; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + uint8_t num_responses; + uint8_t temp_inq_active; + tBTM_STATUS status; + + /* If an inquiry or periodic inquiry is active, reset the mode to inactive */ + if (p_inq->inq_active != BTM_INQUIRY_INACTIVE) { + temp_inq_active = p_inq->inq_active; /* Save so state can change BEFORE + callback is called */ + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + + /* If not a periodic inquiry, the complete callback must be called to notify + * caller */ + if (temp_inq_active == BTM_LIMITED_INQUIRY_ACTIVE || + temp_inq_active == BTM_GENERAL_INQUIRY_ACTIVE) { + if (p_inq->p_inq_cmpl_cb) { + num_responses = 0; + (*p_inq->p_inq_cmpl_cb)(&num_responses); + } + } + } + + /* Cancel a remote name request if active, and notify the caller (if waiting) + */ + if (p_inq->remname_active) { + alarm_cancel(p_inq->remote_name_timer); + p_inq->remname_active = false; + memset(p_inq->remname_bda, 0, BD_ADDR_LEN); + + if (p_inq->p_remname_cmpl_cb) { + rem_name.status = BTM_DEV_RESET; + + (*p_inq->p_remname_cmpl_cb)(&rem_name); + p_inq->p_remname_cmpl_cb = NULL; + } + } + + /* Cancel an inquiry filter request if active, and notify the caller (if + * waiting) */ + if (p_inq->inqfilt_active) { + p_inq->inqfilt_active = false; + + if (p_inq->p_inqfilter_cmpl_cb) { + status = BTM_DEV_RESET; + (*p_inq->p_inqfilter_cmpl_cb)(&status); + } + } + + p_inq->state = BTM_INQ_INACTIVE_STATE; + p_inq->pending_filt_complete_event = 0; + p_inq->p_inq_results_cb = NULL; + btm_clr_inq_db(NULL); /* Clear out all the entries in the database */ + btm_clr_inq_result_flt(); + + p_inq->discoverable_mode = BTM_NON_DISCOVERABLE; + p_inq->connectable_mode = BTM_NON_CONNECTABLE; + p_inq->page_scan_type = BTM_SCAN_TYPE_STANDARD; + p_inq->inq_scan_type = BTM_SCAN_TYPE_STANDARD; + + p_inq->discoverable_mode |= BTM_BLE_NON_DISCOVERABLE; + p_inq->connectable_mode |= BTM_BLE_NON_CONNECTABLE; + return; } - /******************************************************************************* * * Function btm_inq_db_init @@ -1351,12 +1238,11 @@ void btm_inq_db_reset (void) * Returns void * ******************************************************************************/ -void btm_inq_db_init (void) -{ - alarm_free(btm_cb.btm_inq_vars.remote_name_timer); - btm_cb.btm_inq_vars.remote_name_timer = - alarm_new("btm_inq.remote_name_timer"); - btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY; +void btm_inq_db_init(void) { + alarm_free(btm_cb.btm_inq_vars.remote_name_timer); + btm_cb.btm_inq_vars.remote_name_timer = + alarm_new("btm_inq.remote_name_timer"); + btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY; } /******************************************************************************* @@ -1368,31 +1254,30 @@ void btm_inq_db_init (void) * Returns void * ******************************************************************************/ -void btm_inq_stop_on_ssp(void) -{ - uint8_t normal_active = (BTM_GENERAL_INQUIRY_ACTIVE|BTM_LIMITED_INQUIRY_ACTIVE); +void btm_inq_stop_on_ssp(void) { + uint8_t normal_active = + (BTM_GENERAL_INQUIRY_ACTIVE | BTM_LIMITED_INQUIRY_ACTIVE); #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_inq_stop_on_ssp: no_inc_ssp=%d inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.no_inc_ssp, btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG( + "btm_inq_stop_on_ssp: no_inc_ssp=%d inq_active:0x%x state:%d " + "inqfilt_active:%d", + btm_cb.btm_inq_vars.no_inc_ssp, btm_cb.btm_inq_vars.inq_active, + btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); #endif - if (btm_cb.btm_inq_vars.no_inc_ssp) - { - if (btm_cb.btm_inq_vars.state == BTM_INQ_ACTIVE_STATE) - { - if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) - { - BTM_CancelPeriodicInquiry(); - } - else if (btm_cb.btm_inq_vars.inq_active & normal_active) - { - /* can not call BTM_CancelInquiry() here. We need to report inquiry complete evt */ - btsnd_hcic_inq_cancel(); - } - } - /* do not allow inquiry to start */ - btm_cb.btm_inq_vars.inq_active |= BTM_SSP_INQUIRY_ACTIVE; - } + if (btm_cb.btm_inq_vars.no_inc_ssp) { + if (btm_cb.btm_inq_vars.state == BTM_INQ_ACTIVE_STATE) { + if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) { + BTM_CancelPeriodicInquiry(); + } else if (btm_cb.btm_inq_vars.inq_active & normal_active) { + /* can not call BTM_CancelInquiry() here. We need to report inquiry + * complete evt */ + btsnd_hcic_inq_cancel(); + } + } + /* do not allow inquiry to start */ + btm_cb.btm_inq_vars.inq_active |= BTM_SSP_INQUIRY_ACTIVE; + } } /******************************************************************************* @@ -1404,9 +1289,8 @@ void btm_inq_stop_on_ssp(void) * Returns void * ******************************************************************************/ -void btm_inq_clear_ssp(void) -{ - btm_cb.btm_inq_vars.inq_active &= ~BTM_SSP_INQUIRY_ACTIVE; +void btm_inq_clear_ssp(void) { + btm_cb.btm_inq_vars.inq_active &= ~BTM_SSP_INQUIRY_ACTIVE; } /******************************************************************************* @@ -1422,35 +1306,30 @@ void btm_inq_clear_ssp(void) * Returns void * ******************************************************************************/ -void btm_clr_inq_db (BD_ADDR p_bda) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tINQ_DB_ENT *p_ent = p_inq->inq_db; - uint16_t xx; +void btm_clr_inq_db(BD_ADDR p_bda) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tINQ_DB_ENT* p_ent = p_inq->inq_db; + uint16_t xx; #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_clr_inq_db: inq_active:0x%x state:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state); + BTM_TRACE_DEBUG("btm_clr_inq_db: inq_active:0x%x state:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state); #endif - for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) - { - if (p_ent->in_use) - { - /* If this is the specified BD_ADDR or clearing all devices */ - if (p_bda == NULL || - (!memcmp (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN))) - { - p_ent->in_use = false; - } - } - } + for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { + if (p_ent->in_use) { + /* If this is the specified BD_ADDR or clearing all devices */ + if (p_bda == NULL || (!memcmp(p_ent->inq_info.results.remote_bd_addr, + p_bda, BD_ADDR_LEN))) { + p_ent->in_use = false; + } + } + } #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("inq_active:0x%x state:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state); + BTM_TRACE_DEBUG("inq_active:0x%x state:%d", btm_cb.btm_inq_vars.inq_active, + btm_cb.btm_inq_vars.state); #endif } - /******************************************************************************* * * Function btm_clr_inq_result_flt @@ -1461,13 +1340,12 @@ void btm_clr_inq_db (BD_ADDR p_bda) * Returns true if found, else false (new entry) * ******************************************************************************/ -static void btm_clr_inq_result_flt (void) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; +static void btm_clr_inq_result_flt(void) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; - osi_free_and_reset((void **)&p_inq->p_bd_db); - p_inq->num_bd_entries = 0; - p_inq->max_bd_entries = 0; + osi_free_and_reset((void**)&p_inq->p_bd_db); + p_inq->num_bd_entries = 0; + p_inq->max_bd_entries = 0; } /******************************************************************************* @@ -1480,32 +1358,29 @@ static void btm_clr_inq_result_flt (void) * Returns true if found, else false (new entry) * ******************************************************************************/ -bool btm_inq_find_bdaddr (BD_ADDR p_bda) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tINQ_BDADDR *p_db = &p_inq->p_bd_db[0]; - uint16_t xx; +bool btm_inq_find_bdaddr(BD_ADDR p_bda) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tINQ_BDADDR* p_db = &p_inq->p_bd_db[0]; + uint16_t xx; - /* Don't bother searching, database doesn't exist or periodic mode */ - if ((p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) || !p_db) - return (false); + /* Don't bother searching, database doesn't exist or periodic mode */ + if ((p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) || !p_db) + return (false); - for (xx = 0; xx < p_inq->num_bd_entries; xx++, p_db++) - { - if (!memcmp(p_db->bd_addr, p_bda, BD_ADDR_LEN) - && p_db->inq_count == p_inq->inq_counter) - return (true); - } + for (xx = 0; xx < p_inq->num_bd_entries; xx++, p_db++) { + if (!memcmp(p_db->bd_addr, p_bda, BD_ADDR_LEN) && + p_db->inq_count == p_inq->inq_counter) + return (true); + } - if (xx < p_inq->max_bd_entries) - { - p_db->inq_count = p_inq->inq_counter; - memcpy(p_db->bd_addr, p_bda, BD_ADDR_LEN); - p_inq->num_bd_entries++; - } + if (xx < p_inq->max_bd_entries) { + p_db->inq_count = p_inq->inq_counter; + memcpy(p_db->bd_addr, p_bda, BD_ADDR_LEN); + p_inq->num_bd_entries++; + } - /* If here, New Entry */ - return (false); + /* If here, New Entry */ + return (false); } /******************************************************************************* @@ -1518,22 +1393,20 @@ bool btm_inq_find_bdaddr (BD_ADDR p_bda) * Returns pointer to entry, or NULL if not found * ******************************************************************************/ -tINQ_DB_ENT *btm_inq_db_find (const BD_ADDR p_bda) -{ - uint16_t xx; - tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; - - for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) - { - if ((p_ent->in_use) && (!memcmp (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN))) - return (p_ent); - } - - /* If here, not found */ - return (NULL); +tINQ_DB_ENT* btm_inq_db_find(const BD_ADDR p_bda) { + uint16_t xx; + tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; + + for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { + if ((p_ent->in_use) && + (!memcmp(p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN))) + return (p_ent); + } + + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function btm_inq_db_new @@ -1545,41 +1418,36 @@ tINQ_DB_ENT *btm_inq_db_find (const BD_ADDR p_bda) * Returns pointer to entry * ******************************************************************************/ -tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda) -{ - uint16_t xx; - tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; - tINQ_DB_ENT *p_old = btm_cb.btm_inq_vars.inq_db; - uint32_t ot = 0xFFFFFFFF; - - for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) - { - if (!p_ent->in_use) - { - memset (p_ent, 0, sizeof (tINQ_DB_ENT)); - memcpy (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN); - p_ent->in_use = true; +tINQ_DB_ENT* btm_inq_db_new(BD_ADDR p_bda) { + uint16_t xx; + tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; + tINQ_DB_ENT* p_old = btm_cb.btm_inq_vars.inq_db; + uint32_t ot = 0xFFFFFFFF; - return (p_ent); - } + for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { + if (!p_ent->in_use) { + memset(p_ent, 0, sizeof(tINQ_DB_ENT)); + memcpy(p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN); + p_ent->in_use = true; - if (p_ent->time_of_resp < ot) - { - p_old = p_ent; - ot = p_ent->time_of_resp; - } + return (p_ent); + } + + if (p_ent->time_of_resp < ot) { + p_old = p_ent; + ot = p_ent->time_of_resp; } + } - /* If here, no free entry found. Return the oldest. */ + /* If here, no free entry found. Return the oldest. */ - memset (p_old, 0, sizeof (tINQ_DB_ENT)); - memcpy (p_old->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN); - p_old->in_use = true; + memset(p_old, 0, sizeof(tINQ_DB_ENT)); + memcpy(p_old->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN); + p_old->in_use = true; - return (p_old); + return (p_old); } - /******************************************************************************* * * Function btm_set_inq_event_filter @@ -1605,56 +1473,57 @@ tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda) * BTM_ILLEGAL_VALUE if a bad parameter was detected * ******************************************************************************/ -static tBTM_STATUS btm_set_inq_event_filter (uint8_t filter_cond_type, - tBTM_INQ_FILT_COND *p_filt_cond) -{ - uint8_t condition_length = DEV_CLASS_LEN * 2; - uint8_t condition_buf[DEV_CLASS_LEN * 2]; - uint8_t *p_cond = condition_buf; /* points to the condition to pass to HCI */ +static tBTM_STATUS btm_set_inq_event_filter(uint8_t filter_cond_type, + tBTM_INQ_FILT_COND* p_filt_cond) { + uint8_t condition_length = DEV_CLASS_LEN * 2; + uint8_t condition_buf[DEV_CLASS_LEN * 2]; + uint8_t* p_cond = condition_buf; /* points to the condition to pass to HCI */ #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_set_inq_event_filter: filter type %d [Clear-0, COD-1, BDADDR-2]", - filter_cond_type); - BTM_TRACE_DEBUG (" condition [%02x%02x%02x %02x%02x%02x]", - p_filt_cond->bdaddr_cond[0], p_filt_cond->bdaddr_cond[1], p_filt_cond->bdaddr_cond[2], - p_filt_cond->bdaddr_cond[3], p_filt_cond->bdaddr_cond[4], p_filt_cond->bdaddr_cond[5]); + BTM_TRACE_DEBUG( + "btm_set_inq_event_filter: filter type %d [Clear-0, COD-1, BDADDR-2]", + filter_cond_type); + BTM_TRACE_DEBUG( + " condition [%02x%02x%02x %02x%02x%02x]", + p_filt_cond->bdaddr_cond[0], p_filt_cond->bdaddr_cond[1], + p_filt_cond->bdaddr_cond[2], p_filt_cond->bdaddr_cond[3], + p_filt_cond->bdaddr_cond[4], p_filt_cond->bdaddr_cond[5]); #endif - /* Load the correct filter condition to pass to the lower layer */ - switch (filter_cond_type) - { + /* Load the correct filter condition to pass to the lower layer */ + switch (filter_cond_type) { case BTM_FILTER_COND_DEVICE_CLASS: - /* copy the device class and device class fields into contiguous memory to send to HCI */ - memcpy (condition_buf, p_filt_cond->cod_cond.dev_class, DEV_CLASS_LEN); - memcpy (&condition_buf[DEV_CLASS_LEN], - p_filt_cond->cod_cond.dev_class_mask, DEV_CLASS_LEN); + /* copy the device class and device class fields into contiguous memory to + * send to HCI */ + memcpy(condition_buf, p_filt_cond->cod_cond.dev_class, DEV_CLASS_LEN); + memcpy(&condition_buf[DEV_CLASS_LEN], + p_filt_cond->cod_cond.dev_class_mask, DEV_CLASS_LEN); - /* condition length should already be set as the default */ - break; + /* condition length should already be set as the default */ + break; case BTM_FILTER_COND_BD_ADDR: - p_cond = p_filt_cond->bdaddr_cond; + p_cond = p_filt_cond->bdaddr_cond; - /* condition length should already be set as the default */ - break; + /* condition length should already be set as the default */ + break; case BTM_CLR_INQUIRY_FILTER: - condition_length = 0; - break; + condition_length = 0; + break; default: - return (BTM_ILLEGAL_VALUE); /* Bad parameter was passed in */ - } + return (BTM_ILLEGAL_VALUE); /* Bad parameter was passed in */ + } - btm_cb.btm_inq_vars.inqfilt_active = true; + btm_cb.btm_inq_vars.inqfilt_active = true; - /* Filter the inquiry results for the specified condition type and value */ - btsnd_hcic_set_event_filter(HCI_FILTER_INQUIRY_RESULT, filter_cond_type, - p_cond, condition_length); - return (BTM_CMD_STARTED); + /* Filter the inquiry results for the specified condition type and value */ + btsnd_hcic_set_event_filter(HCI_FILTER_INQUIRY_RESULT, filter_cond_type, + p_cond, condition_length); + return (BTM_CMD_STARTED); } - /******************************************************************************* * * Function btm_event_filter_complete @@ -1667,90 +1536,92 @@ static tBTM_STATUS btm_set_inq_event_filter (uint8_t filter_cond_type, * Returns void * ******************************************************************************/ -void btm_event_filter_complete (uint8_t *p) -{ - uint8_t hci_status; - tBTM_STATUS status; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_CMPL_CB *p_cb = p_inq->p_inqfilter_cmpl_cb; +void btm_event_filter_complete(uint8_t* p) { + uint8_t hci_status; + tBTM_STATUS status; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_CMPL_CB* p_cb = p_inq->p_inqfilter_cmpl_cb; #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_event_filter_complete: inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG( + "btm_event_filter_complete: inq_active:0x%x state:%d inqfilt_active:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, + btm_cb.btm_inq_vars.inqfilt_active); #endif - /* If the filter complete event is from an old or cancelled request, ignore it */ - if(p_inq->pending_filt_complete_event) - { - p_inq->pending_filt_complete_event--; - return; - } + /* If the filter complete event is from an old or cancelled request, ignore it + */ + if (p_inq->pending_filt_complete_event) { + p_inq->pending_filt_complete_event--; + return; + } + + /* Only process the inquiry filter; Ignore the connection filter until it + is used by the upper layers */ + if (p_inq->inqfilt_active == true) { + /* Extract the returned status from the buffer */ + STREAM_TO_UINT8(hci_status, p); + if (hci_status != HCI_SUCCESS) { + /* If standalone operation, return the error status; if embedded in the + * inquiry, continue the inquiry */ + BTM_TRACE_WARNING( + "BTM Warning: Set Event Filter Failed (HCI returned 0x%x)", + hci_status); + status = BTM_ERR_PROCESSING; + } else + status = BTM_SUCCESS; + + /* If the set filter was initiated externally (via BTM_SetInqEventFilter), + call the + callback function to notify the initiator that it has completed */ + if (p_inq->state == BTM_INQ_INACTIVE_STATE) { + p_inq->inqfilt_active = false; + if (p_cb) (*p_cb)(&status); + } else /* An inquiry is active (the set filter command was internally + generated), + process the next state of the process (Set a new filter or start + the inquiry). */ + { + if (status != BTM_SUCCESS) { + /* Process the inquiry complete (Error Status) */ + btm_process_inq_complete( + BTM_ERR_PROCESSING, + (uint8_t)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK)); + + /* btm_process_inq_complete() does not restore the following settings on + * periodic inquiry */ + p_inq->inqfilt_active = false; + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + p_inq->state = BTM_INQ_INACTIVE_STATE; - /* Only process the inquiry filter; Ignore the connection filter until it - is used by the upper layers */ - if (p_inq->inqfilt_active == true ) - { - /* Extract the returned status from the buffer */ - STREAM_TO_UINT8 (hci_status, p); - if (hci_status != HCI_SUCCESS) + return; + } + + /* Check to see if a new filter needs to be set up */ + if (p_inq->state == BTM_INQ_CLR_FILT_STATE) { + status = btm_set_inq_event_filter(p_inq->inqparms.filter_cond_type, + &p_inq->inqparms.filter_cond); + if (status == BTM_CMD_STARTED) { + p_inq->state = BTM_INQ_SET_FILT_STATE; + } else /* Error setting the filter: Call the initiator's callback + function to indicate a failure */ { - /* If standalone operation, return the error status; if embedded in the inquiry, continue the inquiry */ - BTM_TRACE_WARNING ("BTM Warning: Set Event Filter Failed (HCI returned 0x%x)", hci_status); - status = BTM_ERR_PROCESSING; - } - else - status = BTM_SUCCESS; + p_inq->inqfilt_active = false; - /* If the set filter was initiated externally (via BTM_SetInqEventFilter), call the - callback function to notify the initiator that it has completed */ - if (p_inq->state == BTM_INQ_INACTIVE_STATE) - { - p_inq->inqfilt_active = false; - if (p_cb) - (*p_cb) (&status); - } - else /* An inquiry is active (the set filter command was internally generated), - process the next state of the process (Set a new filter or start the inquiry). */ - { - if(status != BTM_SUCCESS) - { - /* Process the inquiry complete (Error Status) */ - btm_process_inq_complete (BTM_ERR_PROCESSING, (uint8_t)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK)); - - /* btm_process_inq_complete() does not restore the following settings on periodic inquiry */ - p_inq->inqfilt_active = false; - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - p_inq->state = BTM_INQ_INACTIVE_STATE; - - return; - } - - /* Check to see if a new filter needs to be set up */ - if (p_inq->state == BTM_INQ_CLR_FILT_STATE) - { - status = btm_set_inq_event_filter(p_inq->inqparms.filter_cond_type, &p_inq->inqparms.filter_cond); - if (status == BTM_CMD_STARTED) - { - p_inq->state = BTM_INQ_SET_FILT_STATE; - } - else /* Error setting the filter: Call the initiator's callback function to indicate a failure */ - { - p_inq->inqfilt_active = false; - - /* Process the inquiry complete (Error Status) */ - btm_process_inq_complete (BTM_ERR_PROCESSING, (uint8_t)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK)); - } - } - else /* Initiate the Inquiry or Periodic Inquiry */ - { - p_inq->state = BTM_INQ_ACTIVE_STATE; - p_inq->inqfilt_active = false; - btm_initiate_inquiry (p_inq); - } + /* Process the inquiry complete (Error Status) */ + btm_process_inq_complete( + BTM_ERR_PROCESSING, + (uint8_t)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK)); } + } else /* Initiate the Inquiry or Periodic Inquiry */ + { + p_inq->state = BTM_INQ_ACTIVE_STATE; + p_inq->inqfilt_active = false; + btm_initiate_inquiry(p_inq); + } } + } } - /******************************************************************************* * * Function btm_initiate_inquiry @@ -1776,45 +1647,46 @@ void btm_event_filter_complete (uint8_t *p) * the error status. * ******************************************************************************/ -static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq) -{ - const LAP *lap; - tBTM_INQ_PARMS *p_inqparms = &p_inq->inqparms; +static void btm_initiate_inquiry(tBTM_INQUIRY_VAR_ST* p_inq) { + const LAP* lap; + tBTM_INQ_PARMS* p_inqparms = &p_inq->inqparms; #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_initiate_inquiry: inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG( + "btm_initiate_inquiry: inq_active:0x%x state:%d inqfilt_active:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, + btm_cb.btm_inq_vars.inqfilt_active); #endif - btm_acl_update_busy_level (BTM_BLI_INQ_EVT); + btm_acl_update_busy_level(BTM_BLI_INQ_EVT); - if (p_inq->inq_active & BTM_SSP_INQUIRY_ACTIVE) - { - btm_process_inq_complete (BTM_NO_RESOURCES, (uint8_t)(p_inqparms->mode & BTM_BR_INQUIRY_MASK)); - return; - } + if (p_inq->inq_active & BTM_SSP_INQUIRY_ACTIVE) { + btm_process_inq_complete(BTM_NO_RESOURCES, + (uint8_t)(p_inqparms->mode & BTM_BR_INQUIRY_MASK)); + return; + } - /* Make sure the number of responses doesn't overflow the database configuration */ - p_inqparms->max_resps = (uint8_t)((p_inqparms->max_resps <= BTM_INQ_DB_SIZE) ? p_inqparms->max_resps : BTM_INQ_DB_SIZE); + /* Make sure the number of responses doesn't overflow the database + * configuration */ + p_inqparms->max_resps = (uint8_t)((p_inqparms->max_resps <= BTM_INQ_DB_SIZE) + ? p_inqparms->max_resps + : BTM_INQ_DB_SIZE); - lap = (p_inq->inq_active & BTM_LIMITED_INQUIRY_ACTIVE) ? &limited_inq_lap : &general_inq_lap; + lap = (p_inq->inq_active & BTM_LIMITED_INQUIRY_ACTIVE) ? &limited_inq_lap + : &general_inq_lap; - if (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) - { - btsnd_hcic_per_inq_mode (p_inq->per_max_delay, - p_inq->per_min_delay, - *lap, p_inqparms->duration, - p_inqparms->max_resps); - } - else - { - btm_clr_inq_result_flt(); + if (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) { + btsnd_hcic_per_inq_mode(p_inq->per_max_delay, p_inq->per_min_delay, *lap, + p_inqparms->duration, p_inqparms->max_resps); + } else { + btm_clr_inq_result_flt(); - /* Allocate memory to hold bd_addrs responding */ - p_inq->p_bd_db = (tINQ_BDADDR *)osi_calloc(BT_DEFAULT_BUFFER_SIZE); - p_inq->max_bd_entries = (uint16_t)(BT_DEFAULT_BUFFER_SIZE / sizeof(tINQ_BDADDR)); + /* Allocate memory to hold bd_addrs responding */ + p_inq->p_bd_db = (tINQ_BDADDR*)osi_calloc(BT_DEFAULT_BUFFER_SIZE); + p_inq->max_bd_entries = + (uint16_t)(BT_DEFAULT_BUFFER_SIZE / sizeof(tINQ_BDADDR)); - btsnd_hcic_inquiry(*lap, p_inqparms->duration, 0); - } + btsnd_hcic_inquiry(*lap, p_inqparms->duration, 0); + } } /******************************************************************************* @@ -1832,197 +1704,191 @@ static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq) * Returns void * ******************************************************************************/ -void btm_process_inq_results (uint8_t *p, uint8_t inq_res_mode) -{ - uint8_t num_resp, xx; - BD_ADDR bda; - tINQ_DB_ENT *p_i; - tBTM_INQ_RESULTS *p_cur=NULL; - bool is_new = true; - bool update = false; - int8_t i_rssi; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb; - uint8_t page_scan_rep_mode = 0; - uint8_t page_scan_per_mode = 0; - uint8_t page_scan_mode = 0; - uint8_t rssi = 0; - DEV_CLASS dc; - uint16_t clock_offset; - uint8_t *p_eir_data = NULL; +void btm_process_inq_results(uint8_t* p, uint8_t inq_res_mode) { + uint8_t num_resp, xx; + BD_ADDR bda; + tINQ_DB_ENT* p_i; + tBTM_INQ_RESULTS* p_cur = NULL; + bool is_new = true; + bool update = false; + int8_t i_rssi; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_INQ_RESULTS_CB* p_inq_results_cb = p_inq->p_inq_results_cb; + uint8_t page_scan_rep_mode = 0; + uint8_t page_scan_per_mode = 0; + uint8_t page_scan_mode = 0; + uint8_t rssi = 0; + DEV_CLASS dc; + uint16_t clock_offset; + uint8_t* p_eir_data = NULL; #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_process_inq_results inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG( + "btm_process_inq_results inq_active:0x%x state:%d inqfilt_active:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, + btm_cb.btm_inq_vars.inqfilt_active); #endif - /* Only process the results if the BR inquiry is still active */ - if (!(p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK)) - return; - - STREAM_TO_UINT8 (num_resp, p); - - if (inq_res_mode == BTM_INQ_RESULT_EXTENDED && (num_resp > 1)) { - BTM_TRACE_ERROR ("btm_process_inq_results() extended results (%d) > 1", - num_resp); - return; - } + /* Only process the results if the BR inquiry is still active */ + if (!(p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK)) return; - for (xx = 0; xx < num_resp; xx++) - { - update = false; - /* Extract inquiry results */ - STREAM_TO_BDADDR (bda, p); - STREAM_TO_UINT8 (page_scan_rep_mode, p); - STREAM_TO_UINT8 (page_scan_per_mode, p); + STREAM_TO_UINT8(num_resp, p); - if (inq_res_mode == BTM_INQ_RESULT_STANDARD) - { - STREAM_TO_UINT8(page_scan_mode, p); - } + if (inq_res_mode == BTM_INQ_RESULT_EXTENDED && (num_resp > 1)) { + BTM_TRACE_ERROR("btm_process_inq_results() extended results (%d) > 1", + num_resp); + return; + } - STREAM_TO_DEVCLASS (dc, p); - STREAM_TO_UINT16 (clock_offset, p); - if (inq_res_mode != BTM_INQ_RESULT_STANDARD) - { - STREAM_TO_UINT8(rssi, p); - } + for (xx = 0; xx < num_resp; xx++) { + update = false; + /* Extract inquiry results */ + STREAM_TO_BDADDR(bda, p); + STREAM_TO_UINT8(page_scan_rep_mode, p); + STREAM_TO_UINT8(page_scan_per_mode, p); - p_i = btm_inq_db_find (bda); - - /* Only process the num_resp is smaller than max_resps. - If results are queued to BTU task while canceling inquiry, - or when more than one result is in this response, > max_resp - responses could be processed which can confuse some apps - */ - if (p_inq->inqparms.max_resps && - p_inq->inq_cmpl_info.num_resp >= p_inq->inqparms.max_resps - /* new device response */ - && ( p_i == NULL || - /* exisiting device with BR/EDR info */ - (p_i && (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0) - )) - { - /* BTM_TRACE_WARNING("INQ RES: Extra Response Received...ignoring"); */ - return; - } + if (inq_res_mode == BTM_INQ_RESULT_STANDARD) { + STREAM_TO_UINT8(page_scan_mode, p); + } - /* Check if this address has already been processed for this inquiry */ - if (btm_inq_find_bdaddr(bda)) - { - /* BTM_TRACE_DEBUG("BDA seen before [%02x%02x %02x%02x %02x%02x]", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);*/ - /* By default suppose no update needed */ - i_rssi = (int8_t)rssi; - - /* If this new RSSI is higher than the last one */ - if(p_inq->inqparms.report_dup && (rssi != 0) && - p_i && (i_rssi > p_i->inq_info.results.rssi || p_i->inq_info.results.rssi == 0 - /* BR/EDR inquiry information update */ - || (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)) - { - p_cur = &p_i->inq_info.results; - BTM_TRACE_DEBUG("update RSSI new:%d, old:%d", i_rssi, p_cur->rssi); - p_cur->rssi = i_rssi; - update = true; - } - /* If we received a second Extended Inq Event for an already */ - /* discovered device, this is because for the first one EIR was not received */ - else if ((inq_res_mode == BTM_INQ_RESULT_EXTENDED) && (p_i)) - { - p_cur = &p_i->inq_info.results; - update = true; - } - /* If no update needed continue with next response (if any) */ - else - continue; - } + STREAM_TO_DEVCLASS(dc, p); + STREAM_TO_UINT16(clock_offset, p); + if (inq_res_mode != BTM_INQ_RESULT_STANDARD) { + STREAM_TO_UINT8(rssi, p); + } - /* If existing entry, use that, else get a new one (possibly reusing the oldest) */ - if (p_i == NULL) - { - p_i = btm_inq_db_new (bda); - is_new = true; - } + p_i = btm_inq_db_find(bda); - /* If an entry for the device already exists, overwrite it ONLY if it is from - a previous inquiry. (Ignore it if it is a duplicate response from the same - inquiry. - */ - else if (p_i->inq_count == p_inq->inq_counter && - (p_i->inq_info.results.device_type == BT_DEVICE_TYPE_BREDR)) - is_new = false; - - /* keep updating RSSI to have latest value */ - if( inq_res_mode != BTM_INQ_RESULT_STANDARD ) - p_i->inq_info.results.rssi = (int8_t)rssi; - else - p_i->inq_info.results.rssi = BTM_INQ_RES_IGNORE_RSSI; - - if (is_new == true) - { - /* Save the info */ - p_cur = &p_i->inq_info.results; - p_cur->page_scan_rep_mode = page_scan_rep_mode; - p_cur->page_scan_per_mode = page_scan_per_mode; - p_cur->page_scan_mode = page_scan_mode; - p_cur->dev_class[0] = dc[0]; - p_cur->dev_class[1] = dc[1]; - p_cur->dev_class[2] = dc[2]; - p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; - - p_i->time_of_resp = time_get_os_boottime_ms(); - - if (p_i->inq_count != p_inq->inq_counter) - p_inq->inq_cmpl_info.num_resp++; /* A new response was found */ - - p_cur->inq_result_type = BTM_INQ_RESULT_BR; - if (p_i->inq_count != p_inq->inq_counter) - { - p_cur->device_type = BT_DEVICE_TYPE_BREDR; - p_i->scan_rsp = false; - } - else - p_cur->device_type |= BT_DEVICE_TYPE_BREDR; - p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ - - /* If the number of responses found and not unlimited, issue a cancel inquiry */ - if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) && - p_inq->inqparms.max_resps && - p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps && - /* BLE scanning is active and received adv */ - ((((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) && - p_cur->device_type == BT_DEVICE_TYPE_DUMO && p_i->scan_rsp) || - (p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) == 0)) - { -/* BTM_TRACE_DEBUG("BTMINQ: Found devices, cancelling inquiry..."); */ - btsnd_hcic_inq_cancel(); - - if ((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) - btm_ble_stop_inquiry(); - btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); - } - /* Initialize flag to false. This flag is set/used by application */ - p_i->inq_info.appl_knows_rem_name = false; - } + /* Only process the num_resp is smaller than max_resps. + If results are queued to BTU task while canceling inquiry, + or when more than one result is in this response, > max_resp + responses could be processed which can confuse some apps + */ + if (p_inq->inqparms.max_resps && + p_inq->inq_cmpl_info.num_resp >= p_inq->inqparms.max_resps + /* new device response */ + && + (p_i == NULL || + /* exisiting device with BR/EDR info */ + (p_i && + (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0))) { + /* BTM_TRACE_WARNING("INQ RES: Extra Response Received...ignoring"); */ + return; + } + + /* Check if this address has already been processed for this inquiry */ + if (btm_inq_find_bdaddr(bda)) { + /* BTM_TRACE_DEBUG("BDA seen before [%02x%02x %02x%02x %02x%02x]", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);*/ + /* By default suppose no update needed */ + i_rssi = (int8_t)rssi; + + /* If this new RSSI is higher than the last one */ + if (p_inq->inqparms.report_dup && (rssi != 0) && p_i && + (i_rssi > p_i->inq_info.results.rssi || + p_i->inq_info.results.rssi == 0 + /* BR/EDR inquiry information update */ + || + (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)) { + p_cur = &p_i->inq_info.results; + BTM_TRACE_DEBUG("update RSSI new:%d, old:%d", i_rssi, p_cur->rssi); + p_cur->rssi = i_rssi; + update = true; + } + /* If we received a second Extended Inq Event for an already */ + /* discovered device, this is because for the first one EIR was not + received */ + else if ((inq_res_mode == BTM_INQ_RESULT_EXTENDED) && (p_i)) { + p_cur = &p_i->inq_info.results; + update = true; + } + /* If no update needed continue with next response (if any) */ + else + continue; + } + + /* If existing entry, use that, else get a new one (possibly reusing the + * oldest) */ + if (p_i == NULL) { + p_i = btm_inq_db_new(bda); + is_new = true; + } + + /* If an entry for the device already exists, overwrite it ONLY if it is + from + a previous inquiry. (Ignore it if it is a duplicate response from the + same + inquiry. + */ + else if (p_i->inq_count == p_inq->inq_counter && + (p_i->inq_info.results.device_type == BT_DEVICE_TYPE_BREDR)) + is_new = false; - if (is_new || update) - { - if( inq_res_mode == BTM_INQ_RESULT_EXTENDED ) - { - memset( p_cur->eir_uuid, 0, - BTM_EIR_SERVICE_ARRAY_SIZE * (BTM_EIR_ARRAY_BITS/8)); - /* set bit map of UUID list from received EIR */ - btm_set_eir_uuid( p, p_cur ); - p_eir_data = p; - } - else - p_eir_data = NULL; - - /* If a callback is registered, call it with the results */ - if (p_inq_results_cb) - (p_inq_results_cb)((tBTM_INQ_RESULTS *) p_cur, p_eir_data); - } - } + /* keep updating RSSI to have latest value */ + if (inq_res_mode != BTM_INQ_RESULT_STANDARD) + p_i->inq_info.results.rssi = (int8_t)rssi; + else + p_i->inq_info.results.rssi = BTM_INQ_RES_IGNORE_RSSI; + + if (is_new == true) { + /* Save the info */ + p_cur = &p_i->inq_info.results; + p_cur->page_scan_rep_mode = page_scan_rep_mode; + p_cur->page_scan_per_mode = page_scan_per_mode; + p_cur->page_scan_mode = page_scan_mode; + p_cur->dev_class[0] = dc[0]; + p_cur->dev_class[1] = dc[1]; + p_cur->dev_class[2] = dc[2]; + p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; + + p_i->time_of_resp = time_get_os_boottime_ms(); + + if (p_i->inq_count != p_inq->inq_counter) + p_inq->inq_cmpl_info.num_resp++; /* A new response was found */ + + p_cur->inq_result_type = BTM_INQ_RESULT_BR; + if (p_i->inq_count != p_inq->inq_counter) { + p_cur->device_type = BT_DEVICE_TYPE_BREDR; + p_i->scan_rsp = false; + } else + p_cur->device_type |= BT_DEVICE_TYPE_BREDR; + p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ + + /* If the number of responses found and not unlimited, issue a cancel + * inquiry */ + if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) && + p_inq->inqparms.max_resps && + p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps && + /* BLE scanning is active and received adv */ + ((((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) && + p_cur->device_type == BT_DEVICE_TYPE_DUMO && p_i->scan_rsp) || + (p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) == 0)) { + /* BTM_TRACE_DEBUG("BTMINQ: Found devices, cancelling + * inquiry..."); */ + btsnd_hcic_inq_cancel(); + + if ((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) + btm_ble_stop_inquiry(); + btm_acl_update_busy_level(BTM_BLI_INQ_DONE_EVT); + } + /* Initialize flag to false. This flag is set/used by application */ + p_i->inq_info.appl_knows_rem_name = false; + } + + if (is_new || update) { + if (inq_res_mode == BTM_INQ_RESULT_EXTENDED) { + memset(p_cur->eir_uuid, 0, + BTM_EIR_SERVICE_ARRAY_SIZE * (BTM_EIR_ARRAY_BITS / 8)); + /* set bit map of UUID list from received EIR */ + btm_set_eir_uuid(p, p_cur); + p_eir_data = p; + } else + p_eir_data = NULL; + + /* If a callback is registered, call it with the results */ + if (p_inq_results_cb) + (p_inq_results_cb)((tBTM_INQ_RESULTS*)p_cur, p_eir_data); + } + } } /******************************************************************************* @@ -2035,29 +1901,29 @@ void btm_process_inq_results (uint8_t *p, uint8_t inq_res_mode) * Returns void * ******************************************************************************/ -void btm_sort_inq_result(void) -{ - uint8_t xx, yy, num_resp; - tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; - tINQ_DB_ENT *p_next = btm_cb.btm_inq_vars.inq_db+1; - int size; - tINQ_DB_ENT *p_tmp = (tINQ_DB_ENT *)osi_malloc(sizeof(tINQ_DB_ENT)); - - num_resp = (btm_cb.btm_inq_vars.inq_cmpl_info.num_respinq_info.results.rssi < p_next->inq_info.results.rssi) { - memcpy(p_tmp, p_next, size); - memcpy(p_next, p_ent, size); - memcpy(p_ent, p_tmp, size); - } - } - } - - osi_free(p_tmp); +void btm_sort_inq_result(void) { + uint8_t xx, yy, num_resp; + tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; + tINQ_DB_ENT* p_next = btm_cb.btm_inq_vars.inq_db + 1; + int size; + tINQ_DB_ENT* p_tmp = (tINQ_DB_ENT*)osi_malloc(sizeof(tINQ_DB_ENT)); + + num_resp = (btm_cb.btm_inq_vars.inq_cmpl_info.num_resp < BTM_INQ_DB_SIZE) + ? btm_cb.btm_inq_vars.inq_cmpl_info.num_resp + : BTM_INQ_DB_SIZE; + + size = sizeof(tINQ_DB_ENT); + for (xx = 0; xx < num_resp - 1; xx++, p_ent++) { + for (yy = xx + 1, p_next = p_ent + 1; yy < num_resp; yy++, p_next++) { + if (p_ent->inq_info.results.rssi < p_next->inq_info.results.rssi) { + memcpy(p_tmp, p_next, size); + memcpy(p_next, p_ent, size); + memcpy(p_ent, p_tmp, size); + } + } + } + + osi_free(p_tmp); } /******************************************************************************* @@ -2075,100 +1941,101 @@ void btm_sort_inq_result(void) * Returns void * ******************************************************************************/ -void btm_process_inq_complete (uint8_t status, uint8_t mode) -{ - tBTM_CMPL_CB *p_inq_cb = btm_cb.btm_inq_vars.p_inq_cmpl_cb; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; +void btm_process_inq_complete(uint8_t status, uint8_t mode) { + tBTM_CMPL_CB* p_inq_cb = btm_cb.btm_inq_vars.p_inq_cmpl_cb; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - /* inquiry inactive case happens when inquiry is cancelled. - Make mode 0 for no further inquiries from the current inquiry process - */ - if(status!=HCI_SUCCESS || p_inq->next_state==BTM_FINISH || !p_inq->inq_active) - { - /* re-initialize for next inquiry request */ - p_inq->next_state=BTM_BR_ONE; - /* make the mode 0 here */ - p_inq->inqparms.mode &= ~(p_inq->inqparms.mode); - - } + /* inquiry inactive case happens when inquiry is cancelled. + Make mode 0 for no further inquiries from the current inquiry process + */ + if (status != HCI_SUCCESS || p_inq->next_state == BTM_FINISH || + !p_inq->inq_active) { + /* re-initialize for next inquiry request */ + p_inq->next_state = BTM_BR_ONE; + /* make the mode 0 here */ + p_inq->inqparms.mode &= ~(p_inq->inqparms.mode); + } #endif #if (BTA_HOST_INTERLEAVE_SEARCH == FALSE) - p_inq->inqparms.mode &= ~(mode); + p_inq->inqparms.mode &= ~(mode); #endif - if(p_inq->scan_type == INQ_LE_OBSERVE && !p_inq->inq_active) - { - /*end of LE observe*/ - p_inq->p_inq_ble_results_cb = (tBTM_INQ_RESULTS_CB *) NULL; - p_inq->p_inq_ble_cmpl_cb = (tBTM_CMPL_CB *) NULL; - p_inq->scan_type=INQ_NONE; - } - + if (p_inq->scan_type == INQ_LE_OBSERVE && !p_inq->inq_active) { + /*end of LE observe*/ + p_inq->p_inq_ble_results_cb = (tBTM_INQ_RESULTS_CB*)NULL; + p_inq->p_inq_ble_cmpl_cb = (tBTM_CMPL_CB*)NULL; + p_inq->scan_type = INQ_NONE; + } #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("btm_process_inq_complete inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG( + "btm_process_inq_complete inq_active:0x%x state:%d inqfilt_active:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, + btm_cb.btm_inq_vars.inqfilt_active); #endif - btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); - /* Ignore any stray or late complete messages if the inquiry is not active */ - if (p_inq->inq_active) - { - p_inq->inq_cmpl_info.status = (tBTM_STATUS)((status == HCI_SUCCESS) ? BTM_SUCCESS : BTM_ERR_PROCESSING); + btm_acl_update_busy_level(BTM_BLI_INQ_DONE_EVT); + /* Ignore any stray or late complete messages if the inquiry is not active */ + if (p_inq->inq_active) { + p_inq->inq_cmpl_info.status = (tBTM_STATUS)( + (status == HCI_SUCCESS) ? BTM_SUCCESS : BTM_ERR_PROCESSING); - /* Notify caller that the inquiry has completed; (periodic inquiries do not send completion events */ - if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) && p_inq->inqparms.mode == 0) - { - btm_clear_all_pending_le_entry(); - p_inq->state = BTM_INQ_INACTIVE_STATE; + /* Notify caller that the inquiry has completed; (periodic inquiries do not + * send completion events */ + if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) && + p_inq->inqparms.mode == 0) { + btm_clear_all_pending_le_entry(); + p_inq->state = BTM_INQ_INACTIVE_STATE; - /* Increment so the start of a next inquiry has a new count */ - p_inq->inq_counter++; + /* Increment so the start of a next inquiry has a new count */ + p_inq->inq_counter++; - btm_clr_inq_result_flt(); + btm_clr_inq_result_flt(); - if((p_inq->inq_cmpl_info.status == BTM_SUCCESS) && - controller_get_interface()->supports_rssi_with_inquiry_results()) - { - btm_sort_inq_result(); - } + if ((p_inq->inq_cmpl_info.status == BTM_SUCCESS) && + controller_get_interface()->supports_rssi_with_inquiry_results()) { + btm_sort_inq_result(); + } - /* Clear the results callback if set */ - p_inq->p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL; - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - p_inq->p_inq_cmpl_cb = (tBTM_CMPL_CB *) NULL; + /* Clear the results callback if set */ + p_inq->p_inq_results_cb = (tBTM_INQ_RESULTS_CB*)NULL; + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + p_inq->p_inq_cmpl_cb = (tBTM_CMPL_CB*)NULL; - /* If we have a callback registered for inquiry complete, call it */ - BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d", - p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); + /* If we have a callback registered for inquiry complete, call it */ + BTM_TRACE_DEBUG("BTM Inq Compl Callback: status 0x%02x, num results %d", + p_inq->inq_cmpl_info.status, + p_inq->inq_cmpl_info.num_resp); - if (p_inq_cb) - (p_inq_cb)((tBTM_INQUIRY_CMPL *) &p_inq->inq_cmpl_info); - } -#if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - if(p_inq->inqparms.mode != 0 && !(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE)) - { - /* make inquiry inactive for next iteration */ - p_inq->inq_active = BTM_INQUIRY_INACTIVE; - /* call the inquiry again */ - BTM_StartInquiry(&p_inq->inqparms,p_inq->p_inq_results_cb,p_inq->p_inq_cmpl_cb); - } -#endif + if (p_inq_cb) (p_inq_cb)((tBTM_INQUIRY_CMPL*)&p_inq->inq_cmpl_info); } - if(p_inq->inqparms.mode == 0 && p_inq->scan_type == INQ_GENERAL)//this inquiry is complete - { - p_inq->scan_type = INQ_NONE; - /* check if the LE observe is pending */ - if(p_inq->p_inq_ble_results_cb != NULL) - { - BTM_TRACE_DEBUG("BTM Inq Compl: resuming a pending LE scan"); - BTM_BleObserve(1,0, p_inq->p_inq_ble_results_cb, p_inq->p_inq_ble_cmpl_cb); - } +#if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) + if (p_inq->inqparms.mode != 0 && + !(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE)) { + /* make inquiry inactive for next iteration */ + p_inq->inq_active = BTM_INQUIRY_INACTIVE; + /* call the inquiry again */ + BTM_StartInquiry(&p_inq->inqparms, p_inq->p_inq_results_cb, + p_inq->p_inq_cmpl_cb); } +#endif + } + if (p_inq->inqparms.mode == 0 && + p_inq->scan_type == INQ_GENERAL) // this inquiry is complete + { + p_inq->scan_type = INQ_NONE; + /* check if the LE observe is pending */ + if (p_inq->p_inq_ble_results_cb != NULL) { + BTM_TRACE_DEBUG("BTM Inq Compl: resuming a pending LE scan"); + BTM_BleObserve(1, 0, p_inq->p_inq_ble_results_cb, + p_inq->p_inq_ble_cmpl_cb); + } + } #if (BTM_INQ_DEBUG == TRUE) - BTM_TRACE_DEBUG ("inq_active:0x%x state:%d inqfilt_active:%d", - btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); + BTM_TRACE_DEBUG("inq_active:0x%x state:%d inqfilt_active:%d", + btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, + btm_cb.btm_inq_vars.inqfilt_active); #endif } @@ -2184,10 +2051,9 @@ void btm_process_inq_complete (uint8_t status, uint8_t mode) * Returns void * ******************************************************************************/ -void btm_process_cancel_complete(uint8_t status, uint8_t mode) -{ - btm_acl_update_busy_level (BTM_BLI_INQ_CANCEL_EVT); - btm_process_inq_complete(status, mode); +void btm_process_cancel_complete(uint8_t status, uint8_t mode) { + btm_acl_update_busy_level(BTM_BLI_INQ_CANCEL_EVT); + btm_process_inq_complete(status, mode); } /******************************************************************************* * @@ -2212,63 +2078,52 @@ void btm_process_cancel_complete(uint8_t status, uint8_t mode) * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, - uint8_t origin, period_ms_t timeout_ms, - tBTM_CMPL_CB *p_cb) -{ - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - - /*** Make sure the device is ready ***/ - if (!BTM_IsDeviceUp()) - return (BTM_WRONG_MODE); - - - if (origin == BTM_RMT_NAME_SEC) - { +tBTM_STATUS btm_initiate_rem_name(BD_ADDR remote_bda, tBTM_INQ_INFO* p_cur, + uint8_t origin, period_ms_t timeout_ms, + tBTM_CMPL_CB* p_cb) { + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + + /*** Make sure the device is ready ***/ + if (!BTM_IsDeviceUp()) return (BTM_WRONG_MODE); + + if (origin == BTM_RMT_NAME_SEC) { + btsnd_hcic_rmt_name_req(remote_bda, HCI_PAGE_SCAN_REP_MODE_R1, + HCI_MANDATARY_PAGE_SCAN_MODE, 0); + return BTM_CMD_STARTED; + } + /* Make sure there are no two remote name requests from external API in + progress */ + else if (origin == BTM_RMT_NAME_EXT) { + if (p_inq->remname_active) { + return (BTM_BUSY); + } else { + /* If there is no remote name request running,call the callback function + * and start timer */ + p_inq->p_remname_cmpl_cb = p_cb; + memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); + + alarm_set_on_queue(p_inq->remote_name_timer, timeout_ms, + btm_inq_remote_name_timer_timeout, NULL, + btu_general_alarm_queue); + + /* If the database entry exists for the device, use its clock offset */ + if (p_cur) { + btsnd_hcic_rmt_name_req( + remote_bda, p_cur->results.page_scan_rep_mode, + p_cur->results.page_scan_mode, + (uint16_t)(p_cur->results.clock_offset | BTM_CLOCK_OFFSET_VALID)); + } else /* Otherwise use defaults and mark the clock offset as invalid */ + { btsnd_hcic_rmt_name_req(remote_bda, HCI_PAGE_SCAN_REP_MODE_R1, HCI_MANDATARY_PAGE_SCAN_MODE, 0); - return BTM_CMD_STARTED; - } - /* Make sure there are no two remote name requests from external API in progress */ - else if (origin == BTM_RMT_NAME_EXT) - { - if (p_inq->remname_active) - { - return (BTM_BUSY); - } - else - { - /* If there is no remote name request running,call the callback function and start timer */ - p_inq->p_remname_cmpl_cb = p_cb; - memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); - - alarm_set_on_queue(p_inq->remote_name_timer, timeout_ms, - btm_inq_remote_name_timer_timeout, NULL, - btu_general_alarm_queue); - - /* If the database entry exists for the device, use its clock offset */ - if (p_cur) - { - btsnd_hcic_rmt_name_req(remote_bda, - p_cur->results.page_scan_rep_mode, - p_cur->results.page_scan_mode, - (uint16_t)(p_cur->results.clock_offset | - BTM_CLOCK_OFFSET_VALID)); - } - else /* Otherwise use defaults and mark the clock offset as invalid */ - { - btsnd_hcic_rmt_name_req(remote_bda, HCI_PAGE_SCAN_REP_MODE_R1, - HCI_MANDATARY_PAGE_SCAN_MODE, 0); - } - - p_inq->remname_active = true; - return BTM_CMD_STARTED; - } - } - else - { - return BTM_ILLEGAL_VALUE; + } + + p_inq->remname_active = true; + return BTM_CMD_STARTED; } + } else { + return BTM_ILLEGAL_VALUE; + } } /******************************************************************************* @@ -2282,84 +2137,76 @@ tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, * Returns void * ******************************************************************************/ -void btm_process_remote_name (BD_ADDR bda, BD_NAME bdn, uint16_t evt_len, uint8_t hci_status) -{ - tBTM_REMOTE_DEV_NAME rem_name; - tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; - tBTM_CMPL_CB *p_cb = p_inq->p_remname_cmpl_cb; - uint8_t *p_n1; - - uint16_t temp_evt_len; - - if (bda != NULL) - { - BTM_TRACE_EVENT("BDA %02x:%02x:%02x:%02x:%02x:%02x",bda[0], bda[1], - bda[2], bda[3], - bda[4], bda[5]); - } - - BTM_TRACE_EVENT("Inquire BDA %02x:%02x:%02x:%02x:%02x:%02x",p_inq->remname_bda[0], p_inq->remname_bda[1], - p_inq->remname_bda[2], p_inq->remname_bda[3], - p_inq->remname_bda[4], p_inq->remname_bda[5]); - - - - /* If the inquire BDA and remote DBA are the same, then stop the timer and set the active to false */ - if ((p_inq->remname_active ==true)&& - (((bda != NULL) && - (memcmp(bda, p_inq->remname_bda,BD_ADDR_LEN)==0)) || bda == NULL)) - - { - if (BTM_UseLeLink(p_inq->remname_bda)) - { - if (hci_status == HCI_ERR_UNSPECIFIED) - btm_ble_cancel_remote_name(p_inq->remname_bda); - } - alarm_cancel(p_inq->remote_name_timer); - p_inq->remname_active = false; - /* Clean up and return the status if the command was not successful */ - /* Note: If part of the inquiry, the name is not stored, and the */ - /* inquiry complete callback is called. */ - - if (hci_status == HCI_SUCCESS) - { - /* Copy the name from the data stream into the return structure */ - /* Note that even if it is not being returned, it is used as a */ - /* temporary buffer. */ - p_n1 = (uint8_t *)rem_name.remote_bd_name; - rem_name.length = (evt_len < BD_NAME_LEN) ? evt_len : BD_NAME_LEN; - rem_name.remote_bd_name[rem_name.length] = 0; - rem_name.status = BTM_SUCCESS; - temp_evt_len = rem_name.length; - - while (temp_evt_len > 0) - { - *p_n1++ = *bdn++; - temp_evt_len--; - } - rem_name.remote_bd_name[rem_name.length] = 0; - } - - - /* If processing a stand alone remote name then report the error in the callback */ - else - { - rem_name.status = BTM_BAD_VALUE_RET; - rem_name.length = 0; - rem_name.remote_bd_name[0] = 0; - } - /* Reset the remote BAD to zero and call callback if possible */ - memset(p_inq->remname_bda, 0, BD_ADDR_LEN); - - p_inq->p_remname_cmpl_cb = NULL; - if (p_cb) - (p_cb)((tBTM_REMOTE_DEV_NAME *)&rem_name); - } +void btm_process_remote_name(BD_ADDR bda, BD_NAME bdn, uint16_t evt_len, + uint8_t hci_status) { + tBTM_REMOTE_DEV_NAME rem_name; + tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; + tBTM_CMPL_CB* p_cb = p_inq->p_remname_cmpl_cb; + uint8_t* p_n1; + + uint16_t temp_evt_len; + + if (bda != NULL) { + BTM_TRACE_EVENT("BDA %02x:%02x:%02x:%02x:%02x:%02x", bda[0], bda[1], bda[2], + bda[3], bda[4], bda[5]); + } + + BTM_TRACE_EVENT("Inquire BDA %02x:%02x:%02x:%02x:%02x:%02x", + p_inq->remname_bda[0], p_inq->remname_bda[1], + p_inq->remname_bda[2], p_inq->remname_bda[3], + p_inq->remname_bda[4], p_inq->remname_bda[5]); + + /* If the inquire BDA and remote DBA are the same, then stop the timer and set + * the active to false */ + if ((p_inq->remname_active == true) && + (((bda != NULL) && (memcmp(bda, p_inq->remname_bda, BD_ADDR_LEN) == 0)) || + bda == NULL)) + + { + if (BTM_UseLeLink(p_inq->remname_bda)) { + if (hci_status == HCI_ERR_UNSPECIFIED) + btm_ble_cancel_remote_name(p_inq->remname_bda); + } + alarm_cancel(p_inq->remote_name_timer); + p_inq->remname_active = false; + /* Clean up and return the status if the command was not successful */ + /* Note: If part of the inquiry, the name is not stored, and the */ + /* inquiry complete callback is called. */ + + if (hci_status == HCI_SUCCESS) { + /* Copy the name from the data stream into the return structure */ + /* Note that even if it is not being returned, it is used as a */ + /* temporary buffer. */ + p_n1 = (uint8_t*)rem_name.remote_bd_name; + rem_name.length = (evt_len < BD_NAME_LEN) ? evt_len : BD_NAME_LEN; + rem_name.remote_bd_name[rem_name.length] = 0; + rem_name.status = BTM_SUCCESS; + temp_evt_len = rem_name.length; + + while (temp_evt_len > 0) { + *p_n1++ = *bdn++; + temp_evt_len--; + } + rem_name.remote_bd_name[rem_name.length] = 0; + } + + /* If processing a stand alone remote name then report the error in the + callback */ + else { + rem_name.status = BTM_BAD_VALUE_RET; + rem_name.length = 0; + rem_name.remote_bd_name[0] = 0; + } + /* Reset the remote BAD to zero and call callback if possible */ + memset(p_inq->remname_bda, 0, BD_ADDR_LEN); + + p_inq->p_remname_cmpl_cb = NULL; + if (p_cb) (p_cb)((tBTM_REMOTE_DEV_NAME*)&rem_name); + } } -void btm_inq_remote_name_timer_timeout(UNUSED_ATTR void *data) -{ - btm_inq_rmt_name_failed(); +void btm_inq_remote_name_timer_timeout(UNUSED_ATTR void* data) { + btm_inq_rmt_name_failed(); } /******************************************************************************* @@ -2373,16 +2220,17 @@ void btm_inq_remote_name_timer_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_inq_rmt_name_failed (void) -{ - BTM_TRACE_ERROR ("btm_inq_rmt_name_failed() remname_active=%d", btm_cb.btm_inq_vars.remname_active); +void btm_inq_rmt_name_failed(void) { + BTM_TRACE_ERROR("btm_inq_rmt_name_failed() remname_active=%d", + btm_cb.btm_inq_vars.remname_active); - if (btm_cb.btm_inq_vars.remname_active) - btm_process_remote_name (btm_cb.btm_inq_vars.remname_bda, NULL, 0, HCI_ERR_UNSPECIFIED); - else - btm_process_remote_name (NULL, NULL, 0, HCI_ERR_UNSPECIFIED); + if (btm_cb.btm_inq_vars.remname_active) + btm_process_remote_name(btm_cb.btm_inq_vars.remname_bda, NULL, 0, + HCI_ERR_UNSPECIFIED); + else + btm_process_remote_name(NULL, NULL, 0, HCI_ERR_UNSPECIFIED); - btm_sec_rmt_name_request_complete (NULL, NULL, HCI_ERR_UNSPECIFIED); + btm_sec_rmt_name_request_complete(NULL, NULL, HCI_ERR_UNSPECIFIED); } /******************************************************************************* @@ -2394,12 +2242,10 @@ void btm_inq_rmt_name_failed (void) * Returns void * ******************************************************************************/ -void btm_read_inq_tx_power_timeout(UNUSED_ATTR void *data) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb; - btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL; - if (p_cb) - (*p_cb)((void *) NULL); +void btm_read_inq_tx_power_timeout(UNUSED_ATTR void* data) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb; + btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL; + if (p_cb) (*p_cb)((void*)NULL); } /******************************************************************************* @@ -2411,34 +2257,30 @@ void btm_read_inq_tx_power_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_read_inq_tx_power_complete(uint8_t *p) -{ - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb; - tBTM_INQ_TXPWR_RESULTS results; - - BTM_TRACE_DEBUG("%s", __func__); - alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer); - btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL; - - /* If there was a registered callback, call it */ - if (p_cb) - { - STREAM_TO_UINT8 (results.hci_status, p); - - if (results.hci_status == HCI_SUCCESS) - { - results.status = BTM_SUCCESS; - - STREAM_TO_UINT8 (results.tx_power, p); - BTM_TRACE_EVENT ("BTM INQ TX POWER Complete: tx_power %d, hci status 0x%02x", - results.tx_power, results.hci_status); - } - else - results.status = BTM_ERR_PROCESSING; - - (*p_cb)(&results); - } - +void btm_read_inq_tx_power_complete(uint8_t* p) { + tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb; + tBTM_INQ_TXPWR_RESULTS results; + + BTM_TRACE_DEBUG("%s", __func__); + alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer); + btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL; + + /* If there was a registered callback, call it */ + if (p_cb) { + STREAM_TO_UINT8(results.hci_status, p); + + if (results.hci_status == HCI_SUCCESS) { + results.status = BTM_SUCCESS; + + STREAM_TO_UINT8(results.tx_power, p); + BTM_TRACE_EVENT( + "BTM INQ TX POWER Complete: tx_power %d, hci status 0x%02x", + results.tx_power, results.hci_status); + } else + results.status = BTM_ERR_PROCESSING; + + (*p_cb)(&results); + } } /******************************************************************************* * @@ -2453,19 +2295,15 @@ void btm_read_inq_tx_power_complete(uint8_t *p) * BTM_MODE_UNSUPPORTED - if local device cannot support it * ******************************************************************************/ -tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff ) -{ - if (controller_get_interface()->supports_extended_inquiry_response()) - { - BTM_TRACE_API("Write Extended Inquiry Response to controller"); - btsnd_hcic_write_ext_inquiry_response (p_buff, BTM_EIR_DEFAULT_FEC_REQUIRED); - return BTM_SUCCESS; - } - else - { - osi_free(p_buff); - return BTM_MODE_UNSUPPORTED; - } +tBTM_STATUS BTM_WriteEIR(BT_HDR* p_buff) { + if (controller_get_interface()->supports_extended_inquiry_response()) { + BTM_TRACE_API("Write Extended Inquiry Response to controller"); + btsnd_hcic_write_ext_inquiry_response(p_buff, BTM_EIR_DEFAULT_FEC_REQUIRED); + return BTM_SUCCESS; + } else { + osi_free(p_buff); + return BTM_MODE_UNSUPPORTED; + } } /******************************************************************************* @@ -2482,29 +2320,26 @@ tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff ) * Returns pointer of EIR data * ******************************************************************************/ -uint8_t *BTM_CheckEirData( uint8_t *p_eir, uint8_t type, uint8_t *p_length ) -{ - uint8_t *p = p_eir; - uint8_t length; - uint8_t eir_type; - BTM_TRACE_API("BTM_CheckEirData type=0x%02X", type); - +uint8_t* BTM_CheckEirData(uint8_t* p_eir, uint8_t type, uint8_t* p_length) { + uint8_t* p = p_eir; + uint8_t length; + uint8_t eir_type; + BTM_TRACE_API("BTM_CheckEirData type=0x%02X", type); + + STREAM_TO_UINT8(length, p); + while (length && (p - p_eir <= HCI_EXT_INQ_RESPONSE_LEN)) { + STREAM_TO_UINT8(eir_type, p); + if (eir_type == type) { + /* length doesn't include itself */ + *p_length = length - 1; /* minus the length of type */ + return p; + } + p += length - 1; /* skip the length of data */ STREAM_TO_UINT8(length, p); - while( length && (p - p_eir <= HCI_EXT_INQ_RESPONSE_LEN)) - { - STREAM_TO_UINT8(eir_type, p); - if( eir_type == type ) - { - /* length doesn't include itself */ - *p_length = length - 1; /* minus the length of type */ - return p; - } - p += length - 1; /* skip the length of data */ - STREAM_TO_UINT8(length, p); - } + } - *p_length = 0; - return NULL; + *p_length = 0; + return NULL; } /******************************************************************************* @@ -2519,18 +2354,15 @@ uint8_t *BTM_CheckEirData( uint8_t *p_eir, uint8_t type, uint8_t *p_length ) * BTM_EIR_MAX_SERVICES - if not found * ******************************************************************************/ -static uint8_t btm_convert_uuid_to_eir_service( uint16_t uuid16 ) -{ - uint8_t xx; +static uint8_t btm_convert_uuid_to_eir_service(uint16_t uuid16) { + uint8_t xx; - for( xx = 0; xx < BTM_EIR_MAX_SERVICES; xx++ ) - { - if( uuid16 == BTM_EIR_UUID_LKUP_TBL[xx]) - { - return xx; - } + for (xx = 0; xx < BTM_EIR_MAX_SERVICES; xx++) { + if (uuid16 == BTM_EIR_UUID_LKUP_TBL[xx]) { + return xx; } - return BTM_EIR_MAX_SERVICES; + } + return BTM_EIR_MAX_SERVICES; } /******************************************************************************* @@ -2546,15 +2378,14 @@ static uint8_t btm_convert_uuid_to_eir_service( uint16_t uuid16 ) * false - if not found * ******************************************************************************/ -bool BTM_HasEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) -{ - uint8_t service_id; +bool BTM_HasEirService(uint32_t* p_eir_uuid, uint16_t uuid16) { + uint8_t service_id; - service_id = btm_convert_uuid_to_eir_service(uuid16); - if( service_id < BTM_EIR_MAX_SERVICES ) - return( BTM_EIR_HAS_SERVICE( p_eir_uuid, service_id )); - else - return( false ); + service_id = btm_convert_uuid_to_eir_service(uuid16); + if (service_id < BTM_EIR_MAX_SERVICES) + return (BTM_EIR_HAS_SERVICE(p_eir_uuid, service_id)); + else + return (false); } /******************************************************************************* @@ -2572,18 +2403,14 @@ bool BTM_HasEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) * BTM_EIR_UNKNOWN - if not found and it is not complete list * ******************************************************************************/ -tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results, uint16_t uuid16 ) -{ - if( BTM_HasEirService( p_results->eir_uuid, uuid16 )) - { - return BTM_EIR_FOUND; - } - else if( p_results->eir_complete_list ) - { - return BTM_EIR_NOT_FOUND; - } - else - return BTM_EIR_UNKNOWN; +tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService(tBTM_INQ_RESULTS* p_results, + uint16_t uuid16) { + if (BTM_HasEirService(p_results->eir_uuid, uuid16)) { + return BTM_EIR_FOUND; + } else if (p_results->eir_complete_list) { + return BTM_EIR_NOT_FOUND; + } else + return BTM_EIR_UNKNOWN; } /******************************************************************************* @@ -2599,13 +2426,12 @@ tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results, ui * Returns None * ******************************************************************************/ -void BTM_AddEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) -{ - uint8_t service_id; +void BTM_AddEirService(uint32_t* p_eir_uuid, uint16_t uuid16) { + uint8_t service_id; - service_id = btm_convert_uuid_to_eir_service(uuid16); - if( service_id < BTM_EIR_MAX_SERVICES ) - BTM_EIR_SET_SERVICE( p_eir_uuid, service_id ); + service_id = btm_convert_uuid_to_eir_service(uuid16); + if (service_id < BTM_EIR_MAX_SERVICES) + BTM_EIR_SET_SERVICE(p_eir_uuid, service_id); } /******************************************************************************* @@ -2621,13 +2447,12 @@ void BTM_AddEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) * Returns None * ******************************************************************************/ -void BTM_RemoveEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) -{ - uint8_t service_id; +void BTM_RemoveEirService(uint32_t* p_eir_uuid, uint16_t uuid16) { + uint8_t service_id; - service_id = btm_convert_uuid_to_eir_service(uuid16); - if( service_id < BTM_EIR_MAX_SERVICES ) - BTM_EIR_CLR_SERVICE( p_eir_uuid, service_id ); + service_id = btm_convert_uuid_to_eir_service(uuid16); + if (service_id < BTM_EIR_MAX_SERVICES) + BTM_EIR_CLR_SERVICE(p_eir_uuid, service_id); } /******************************************************************************* @@ -2646,30 +2471,27 @@ void BTM_RemoveEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ) * BTM_EIR_COMPLETE_16BITS_UUID_TYPE, otherwise * ******************************************************************************/ -uint8_t BTM_GetEirSupportedServices( uint32_t *p_eir_uuid, uint8_t **p, - uint8_t max_num_uuid16, uint8_t *p_num_uuid16) -{ - uint8_t service_index; - - *p_num_uuid16 = 0; - - for(service_index = 0; service_index < BTM_EIR_MAX_SERVICES; service_index++) - { - if( BTM_EIR_HAS_SERVICE( p_eir_uuid, service_index )) - { - if( *p_num_uuid16 < max_num_uuid16 ) - { - UINT16_TO_STREAM(*p, BTM_EIR_UUID_LKUP_TBL[service_index]); - (*p_num_uuid16)++; - } - /* if max number of UUIDs are stored and found one more */ - else - { - return BTM_EIR_MORE_16BITS_UUID_TYPE; - } - } - } - return BTM_EIR_COMPLETE_16BITS_UUID_TYPE; +uint8_t BTM_GetEirSupportedServices(uint32_t* p_eir_uuid, uint8_t** p, + uint8_t max_num_uuid16, + uint8_t* p_num_uuid16) { + uint8_t service_index; + + *p_num_uuid16 = 0; + + for (service_index = 0; service_index < BTM_EIR_MAX_SERVICES; + service_index++) { + if (BTM_EIR_HAS_SERVICE(p_eir_uuid, service_index)) { + if (*p_num_uuid16 < max_num_uuid16) { + UINT16_TO_STREAM(*p, BTM_EIR_UUID_LKUP_TBL[service_index]); + (*p_num_uuid16)++; + } + /* if max number of UUIDs are stored and found one more */ + else { + return BTM_EIR_MORE_16BITS_UUID_TYPE; + } + } + } + return BTM_EIR_COMPLETE_16BITS_UUID_TYPE; } /******************************************************************************* @@ -2693,63 +2515,54 @@ uint8_t BTM_GetEirSupportedServices( uint32_t *p_eir_uuid, uint8_t **p, * BTM_EIR_MORE_128BITS_UUID_TYPE * ******************************************************************************/ -uint8_t BTM_GetEirUuidList( uint8_t *p_eir, uint8_t uuid_size, uint8_t *p_num_uuid, - uint8_t *p_uuid_list, uint8_t max_num_uuid) -{ - uint8_t *p_uuid_data; - uint8_t type; - uint8_t yy, xx; - uint16_t *p_uuid16 = (uint16_t *)p_uuid_list; - uint32_t *p_uuid32 = (uint32_t *)p_uuid_list; - char buff[LEN_UUID_128 * 2 + 1]; - - p_uuid_data = btm_eir_get_uuid_list( p_eir, uuid_size, p_num_uuid, &type ); - if( p_uuid_data == NULL ) - { - return 0x00; - } - - if( *p_num_uuid > max_num_uuid ) - { - BTM_TRACE_WARNING("BTM_GetEirUuidList number of uuid in EIR = %d, size of uuid list = %d", - *p_num_uuid, max_num_uuid ); - *p_num_uuid = max_num_uuid; - } - - BTM_TRACE_DEBUG("BTM_GetEirUuidList type = %02X, number of uuid = %d", type, *p_num_uuid ); - - if( uuid_size == LEN_UUID_16 ) - { - for( yy = 0; yy < *p_num_uuid; yy++ ) - { - STREAM_TO_UINT16(*(p_uuid16 + yy), p_uuid_data); - BTM_TRACE_DEBUG(" 0x%04X", *(p_uuid16 + yy)); - } - } - else if( uuid_size == LEN_UUID_32 ) - { - for( yy = 0; yy < *p_num_uuid; yy++ ) - { - STREAM_TO_UINT32(*(p_uuid32 + yy), p_uuid_data); - BTM_TRACE_DEBUG(" 0x%08X", *(p_uuid32 + yy)); - } - } - else if( uuid_size == LEN_UUID_128 ) - { - for( yy = 0; yy < *p_num_uuid; yy++ ) - { - STREAM_TO_ARRAY16(p_uuid_list + yy * LEN_UUID_128, p_uuid_data); - for( xx = 0; xx < LEN_UUID_128; xx++ ) - snprintf(buff + xx*2, sizeof(buff) - xx*2, "%02X", - *(p_uuid_list + yy * LEN_UUID_128 + xx)); - BTM_TRACE_DEBUG(" 0x%s", buff); - } - } - - return type; +uint8_t BTM_GetEirUuidList(uint8_t* p_eir, uint8_t uuid_size, + uint8_t* p_num_uuid, uint8_t* p_uuid_list, + uint8_t max_num_uuid) { + uint8_t* p_uuid_data; + uint8_t type; + uint8_t yy, xx; + uint16_t* p_uuid16 = (uint16_t*)p_uuid_list; + uint32_t* p_uuid32 = (uint32_t*)p_uuid_list; + char buff[LEN_UUID_128 * 2 + 1]; + + p_uuid_data = btm_eir_get_uuid_list(p_eir, uuid_size, p_num_uuid, &type); + if (p_uuid_data == NULL) { + return 0x00; + } + + if (*p_num_uuid > max_num_uuid) { + BTM_TRACE_WARNING( + "BTM_GetEirUuidList number of uuid in EIR = %d, size of uuid list = %d", + *p_num_uuid, max_num_uuid); + *p_num_uuid = max_num_uuid; + } + + BTM_TRACE_DEBUG("BTM_GetEirUuidList type = %02X, number of uuid = %d", type, + *p_num_uuid); + + if (uuid_size == LEN_UUID_16) { + for (yy = 0; yy < *p_num_uuid; yy++) { + STREAM_TO_UINT16(*(p_uuid16 + yy), p_uuid_data); + BTM_TRACE_DEBUG(" 0x%04X", *(p_uuid16 + yy)); + } + } else if (uuid_size == LEN_UUID_32) { + for (yy = 0; yy < *p_num_uuid; yy++) { + STREAM_TO_UINT32(*(p_uuid32 + yy), p_uuid_data); + BTM_TRACE_DEBUG(" 0x%08X", *(p_uuid32 + yy)); + } + } else if (uuid_size == LEN_UUID_128) { + for (yy = 0; yy < *p_num_uuid; yy++) { + STREAM_TO_ARRAY16(p_uuid_list + yy * LEN_UUID_128, p_uuid_data); + for (xx = 0; xx < LEN_UUID_128; xx++) + snprintf(buff + xx * 2, sizeof(buff) - xx * 2, "%02X", + *(p_uuid_list + yy * LEN_UUID_128 + xx)); + BTM_TRACE_DEBUG(" 0x%s", buff); + } + } + + return type; } - /******************************************************************************* * * Function btm_eir_get_uuid_list @@ -2765,46 +2578,42 @@ uint8_t BTM_GetEirUuidList( uint8_t *p_eir, uint8_t uuid_size, uint8_t *p_num_uu * beginning of UUID list in EIR - otherwise * ******************************************************************************/ -static uint8_t *btm_eir_get_uuid_list( uint8_t *p_eir, uint8_t uuid_size, - uint8_t *p_num_uuid, uint8_t *p_uuid_list_type ) -{ - uint8_t *p_uuid_data; - uint8_t complete_type, more_type; - uint8_t uuid_len; - - switch( uuid_size ) - { +static uint8_t* btm_eir_get_uuid_list(uint8_t* p_eir, uint8_t uuid_size, + uint8_t* p_num_uuid, + uint8_t* p_uuid_list_type) { + uint8_t* p_uuid_data; + uint8_t complete_type, more_type; + uint8_t uuid_len; + + switch (uuid_size) { case LEN_UUID_16: - complete_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE; - more_type = BTM_EIR_MORE_16BITS_UUID_TYPE; - break; + complete_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE; + more_type = BTM_EIR_MORE_16BITS_UUID_TYPE; + break; case LEN_UUID_32: - complete_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE; - more_type = BTM_EIR_MORE_32BITS_UUID_TYPE; - break; + complete_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE; + more_type = BTM_EIR_MORE_32BITS_UUID_TYPE; + break; case LEN_UUID_128: - complete_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE; - more_type = BTM_EIR_MORE_128BITS_UUID_TYPE; - break; + complete_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE; + more_type = BTM_EIR_MORE_128BITS_UUID_TYPE; + break; default: - *p_num_uuid = 0; - return NULL; - break; - } - - p_uuid_data = BTM_CheckEirData( p_eir, complete_type, &uuid_len ); - if(p_uuid_data == NULL) - { - p_uuid_data = BTM_CheckEirData( p_eir, more_type, &uuid_len ); - *p_uuid_list_type = more_type; - } - else - { - *p_uuid_list_type = complete_type; - } - - *p_num_uuid = uuid_len / uuid_size; - return p_uuid_data; + *p_num_uuid = 0; + return NULL; + break; + } + + p_uuid_data = BTM_CheckEirData(p_eir, complete_type, &uuid_len); + if (p_uuid_data == NULL) { + p_uuid_data = BTM_CheckEirData(p_eir, more_type, &uuid_len); + *p_uuid_list_type = more_type; + } else { + *p_uuid_list_type = complete_type; + } + + *p_num_uuid = uuid_len / uuid_size; + return p_uuid_data; } /******************************************************************************* @@ -2820,51 +2629,46 @@ static uint8_t *btm_eir_get_uuid_list( uint8_t *p_eir, uint8_t uuid_size, * UUID 16-bit - otherwise * ******************************************************************************/ -static uint16_t btm_convert_uuid_to_uuid16( uint8_t *p_uuid, uint8_t uuid_size ) -{ - static const uint8_t base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint16_t uuid16 = 0; - uint32_t uuid32; - bool is_base_uuid; - uint8_t xx; - - switch (uuid_size) - { +static uint16_t btm_convert_uuid_to_uuid16(uint8_t* p_uuid, uint8_t uuid_size) { + static const uint8_t base_uuid[LEN_UUID_128] = { + 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint16_t uuid16 = 0; + uint32_t uuid32; + bool is_base_uuid; + uint8_t xx; + + switch (uuid_size) { case LEN_UUID_16: - STREAM_TO_UINT16 (uuid16, p_uuid); - break; + STREAM_TO_UINT16(uuid16, p_uuid); + break; case LEN_UUID_32: - STREAM_TO_UINT32 (uuid32, p_uuid); - if (uuid32 < 0x10000) - uuid16 = (uint16_t) uuid32; - break; + STREAM_TO_UINT32(uuid32, p_uuid); + if (uuid32 < 0x10000) uuid16 = (uint16_t)uuid32; + break; case LEN_UUID_128: - /* See if we can compress his UUID down to 16 or 32bit UUIDs */ - is_base_uuid = true; - for (xx = 0; xx < LEN_UUID_128 - 4; xx++) - { - if (p_uuid[xx] != base_uuid[xx]) - { - is_base_uuid = false; - break; - } + /* See if we can compress his UUID down to 16 or 32bit UUIDs */ + is_base_uuid = true; + for (xx = 0; xx < LEN_UUID_128 - 4; xx++) { + if (p_uuid[xx] != base_uuid[xx]) { + is_base_uuid = false; + break; } - if (is_base_uuid) - { - if ((p_uuid[LEN_UUID_128 - 1] == 0) && (p_uuid[LEN_UUID_128 - 2] == 0)) - { - p_uuid += (LEN_UUID_128 - 4); - STREAM_TO_UINT16(uuid16, p_uuid); - } + } + if (is_base_uuid) { + if ((p_uuid[LEN_UUID_128 - 1] == 0) && + (p_uuid[LEN_UUID_128 - 2] == 0)) { + p_uuid += (LEN_UUID_128 - 4); + STREAM_TO_UINT16(uuid16, p_uuid); } - break; + } + break; default: - BTM_TRACE_WARNING("btm_convert_uuid_to_uuid16 invalid uuid size"); - break; - } + BTM_TRACE_WARNING("btm_convert_uuid_to_uuid16 invalid uuid size"); + break; + } - return( uuid16); + return (uuid16); } /******************************************************************************* @@ -2880,57 +2684,46 @@ static uint16_t btm_convert_uuid_to_uuid16( uint8_t *p_uuid, uint8_t uuid_size ) * Returns None * ******************************************************************************/ -void btm_set_eir_uuid( uint8_t *p_eir, tBTM_INQ_RESULTS *p_results ) -{ - uint8_t *p_uuid_data; - uint8_t num_uuid; - uint16_t uuid16; - uint8_t yy; - uint8_t type = BTM_EIR_MORE_16BITS_UUID_TYPE; - - p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_16, &num_uuid, &type ); - - if(type == BTM_EIR_COMPLETE_16BITS_UUID_TYPE) - { - p_results->eir_complete_list = true; - } - else - { - p_results->eir_complete_list = false; - } - - BTM_TRACE_API("btm_set_eir_uuid eir_complete_list=0x%02X", p_results->eir_complete_list); - - if( p_uuid_data ) - { - for( yy = 0; yy < num_uuid; yy++ ) - { - STREAM_TO_UINT16(uuid16, p_uuid_data); - BTM_AddEirService( p_results->eir_uuid, uuid16 ); - } - } - - p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_32, &num_uuid, &type ); - if( p_uuid_data ) - { - for( yy = 0; yy < num_uuid; yy++ ) - { - uuid16 = btm_convert_uuid_to_uuid16( p_uuid_data, LEN_UUID_32 ); - p_uuid_data += LEN_UUID_32; - if( uuid16 ) - BTM_AddEirService( p_results->eir_uuid, uuid16 ); - } - } - - p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_128, &num_uuid, &type ); - if( p_uuid_data ) - { - for( yy = 0; yy < num_uuid; yy++ ) - { - uuid16 = btm_convert_uuid_to_uuid16( p_uuid_data, LEN_UUID_128 ); - p_uuid_data += LEN_UUID_128; - if( uuid16 ) - BTM_AddEirService( p_results->eir_uuid, uuid16 ); - } - } +void btm_set_eir_uuid(uint8_t* p_eir, tBTM_INQ_RESULTS* p_results) { + uint8_t* p_uuid_data; + uint8_t num_uuid; + uint16_t uuid16; + uint8_t yy; + uint8_t type = BTM_EIR_MORE_16BITS_UUID_TYPE; + + p_uuid_data = btm_eir_get_uuid_list(p_eir, LEN_UUID_16, &num_uuid, &type); + + if (type == BTM_EIR_COMPLETE_16BITS_UUID_TYPE) { + p_results->eir_complete_list = true; + } else { + p_results->eir_complete_list = false; + } + + BTM_TRACE_API("btm_set_eir_uuid eir_complete_list=0x%02X", + p_results->eir_complete_list); + + if (p_uuid_data) { + for (yy = 0; yy < num_uuid; yy++) { + STREAM_TO_UINT16(uuid16, p_uuid_data); + BTM_AddEirService(p_results->eir_uuid, uuid16); + } + } + + p_uuid_data = btm_eir_get_uuid_list(p_eir, LEN_UUID_32, &num_uuid, &type); + if (p_uuid_data) { + for (yy = 0; yy < num_uuid; yy++) { + uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, LEN_UUID_32); + p_uuid_data += LEN_UUID_32; + if (uuid16) BTM_AddEirService(p_results->eir_uuid, uuid16); + } + } + + p_uuid_data = btm_eir_get_uuid_list(p_eir, LEN_UUID_128, &num_uuid, &type); + if (p_uuid_data) { + for (yy = 0; yy < num_uuid; yy++) { + uuid16 = btm_convert_uuid_to_uuid16(p_uuid_data, LEN_UUID_128); + p_uuid_data += LEN_UUID_128; + if (uuid16) BTM_AddEirService(p_results->eir_uuid, uuid16); + } + } } diff --git a/stack/btm/btm_int.h b/stack/btm/btm_int.h index 16a81d0e8..7852d0b22 100644 --- a/stack/btm/btm_int.h +++ b/stack/btm/btm_int.h @@ -25,14 +25,14 @@ #ifndef BTM_INT_H #define BTM_INT_H -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" #include "hcidefs.h" -#include "rfcdefs.h" #include "osi/include/alarm.h" -#include "osi/include/list.h" #include "osi/include/fixed_queue.h" +#include "osi/include/list.h" +#include "rfcdefs.h" #include "btm_api.h" #include "btm_ble_int.h" @@ -48,216 +48,233 @@ extern tBTM_CB btm_cb; /* Internal functions provided by btm_main.cc ******************************************* */ -extern void btm_init (void); +extern void btm_init(void); /* Internal functions provided by btm_inq.cc ****************************************** */ -extern tBTM_STATUS btm_initiate_rem_name(BD_ADDR remote_bda, - tBTM_INQ_INFO *p_cur, - uint8_t origin, period_ms_t timeout_ms, - tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS btm_initiate_rem_name(BD_ADDR remote_bda, + tBTM_INQ_INFO* p_cur, uint8_t origin, + period_ms_t timeout_ms, + tBTM_CMPL_CB* p_cb); -extern void btm_process_remote_name (BD_ADDR bda, BD_NAME name, uint16_t evt_len, - uint8_t hci_status); -extern void btm_inq_rmt_name_failed(void); -extern void btm_inq_remote_name_timer_timeout(void *data); +extern void btm_process_remote_name(BD_ADDR bda, BD_NAME name, uint16_t evt_len, + uint8_t hci_status); +extern void btm_inq_rmt_name_failed(void); +extern void btm_inq_remote_name_timer_timeout(void* data); /* Inquiry related functions */ -extern void btm_clr_inq_db (BD_ADDR p_bda); -extern void btm_inq_db_init (void); -extern void btm_process_inq_results (uint8_t *p, uint8_t inq_res_mode); -extern void btm_process_inq_complete (uint8_t status, uint8_t mode); -extern void btm_process_cancel_complete(uint8_t status, uint8_t mode); -extern void btm_event_filter_complete (uint8_t *p); -extern void btm_inq_stop_on_ssp(void); -extern void btm_inq_clear_ssp(void); -extern tINQ_DB_ENT *btm_inq_db_find (const BD_ADDR p_bda); -extern bool btm_inq_find_bdaddr (BD_ADDR p_bda); - -extern bool btm_lookup_eir(BD_ADDR_PTR p_rem_addr); +extern void btm_clr_inq_db(BD_ADDR p_bda); +extern void btm_inq_db_init(void); +extern void btm_process_inq_results(uint8_t* p, uint8_t inq_res_mode); +extern void btm_process_inq_complete(uint8_t status, uint8_t mode); +extern void btm_process_cancel_complete(uint8_t status, uint8_t mode); +extern void btm_event_filter_complete(uint8_t* p); +extern void btm_inq_stop_on_ssp(void); +extern void btm_inq_clear_ssp(void); +extern tINQ_DB_ENT* btm_inq_db_find(const BD_ADDR p_bda); +extern bool btm_inq_find_bdaddr(BD_ADDR p_bda); + +extern bool btm_lookup_eir(BD_ADDR_PTR p_rem_addr); /* Internal functions provided by btm_acl.cc ******************************************* */ -extern void btm_acl_init (void); -extern void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, - uint16_t hci_handle, uint8_t link_role, tBT_TRANSPORT transport); -extern void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport); -extern void btm_acl_device_down (void); -extern void btm_acl_update_busy_level (tBTM_BLI_EVENT event); - -extern void btm_cont_rswitch (tACL_CONN *p, - tBTM_SEC_DEV_REC *p_dev_rec, - uint8_t hci_status); - -extern uint8_t btm_handle_to_acl_index (uint16_t hci_handle); -extern void btm_read_link_policy_complete (uint8_t *p); - -extern void btm_read_rssi_timeout(void *data); -extern void btm_read_rssi_complete(uint8_t *p); - -extern void btm_read_tx_power_timeout(void *data); -extern void btm_read_tx_power_complete(uint8_t *p, bool is_ble); - -extern void btm_read_link_quality_timeout(void *data); -extern void btm_read_link_quality_complete(uint8_t *p); - -extern tBTM_STATUS btm_set_packet_types (tACL_CONN *p, uint16_t pkt_types); -extern void btm_process_clk_off_comp_evt (uint16_t hci_handle, uint16_t clock_offset); -extern void btm_acl_role_changed (uint8_t hci_status, BD_ADDR bd_addr, uint8_t new_role); -extern void btm_acl_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enable); -extern uint16_t btm_get_acl_disc_reason_code (void); -extern tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport); -extern void btm_read_remote_features_complete (uint8_t *p); -extern void btm_read_remote_ext_features_complete (uint8_t *p); -extern void btm_read_remote_ext_features_failed (uint8_t status, uint16_t handle); -extern void btm_read_remote_version_complete (uint8_t *p); -extern void btm_establish_continue (tACL_CONN *p_acl_cb); - -extern void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, uint16_t *p_pkt_type); +extern void btm_acl_init(void); +extern void btm_acl_created(BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, + uint16_t hci_handle, uint8_t link_role, + tBT_TRANSPORT transport); +extern void btm_acl_removed(BD_ADDR bda, tBT_TRANSPORT transport); +extern void btm_acl_device_down(void); +extern void btm_acl_update_busy_level(tBTM_BLI_EVENT event); + +extern void btm_cont_rswitch(tACL_CONN* p, tBTM_SEC_DEV_REC* p_dev_rec, + uint8_t hci_status); + +extern uint8_t btm_handle_to_acl_index(uint16_t hci_handle); +extern void btm_read_link_policy_complete(uint8_t* p); + +extern void btm_read_rssi_timeout(void* data); +extern void btm_read_rssi_complete(uint8_t* p); + +extern void btm_read_tx_power_timeout(void* data); +extern void btm_read_tx_power_complete(uint8_t* p, bool is_ble); + +extern void btm_read_link_quality_timeout(void* data); +extern void btm_read_link_quality_complete(uint8_t* p); + +extern tBTM_STATUS btm_set_packet_types(tACL_CONN* p, uint16_t pkt_types); +extern void btm_process_clk_off_comp_evt(uint16_t hci_handle, + uint16_t clock_offset); +extern void btm_acl_role_changed(uint8_t hci_status, BD_ADDR bd_addr, + uint8_t new_role); +extern void btm_acl_encrypt_change(uint16_t handle, uint8_t status, + uint8_t encr_enable); +extern uint16_t btm_get_acl_disc_reason_code(void); +extern tBTM_STATUS btm_remove_acl(BD_ADDR bd_addr, tBT_TRANSPORT transport); +extern void btm_read_remote_features_complete(uint8_t* p); +extern void btm_read_remote_ext_features_complete(uint8_t* p); +extern void btm_read_remote_ext_features_failed(uint8_t status, + uint16_t handle); +extern void btm_read_remote_version_complete(uint8_t* p); +extern void btm_establish_continue(tACL_CONN* p_acl_cb); + +extern void btm_acl_chk_peer_pkt_type_support(tACL_CONN* p, + uint16_t* p_pkt_type); /* Read maximum data packet that can be sent over current connection */ -extern uint16_t btm_get_max_packet_size (BD_ADDR addr); -extern tACL_CONN *btm_bda_to_acl (const BD_ADDR bda, tBT_TRANSPORT transport); -extern bool btm_acl_notif_conn_collision (BD_ADDR bda); +extern uint16_t btm_get_max_packet_size(BD_ADDR addr); +extern tACL_CONN* btm_bda_to_acl(const BD_ADDR bda, tBT_TRANSPORT transport); +extern bool btm_acl_notif_conn_collision(BD_ADDR bda); extern void btm_acl_update_conn_addr(uint8_t conn_handle, BD_ADDR address); extern void btm_pm_reset(void); extern void btm_pm_sm_alloc(uint8_t ind); extern void btm_pm_proc_cmd_status(uint8_t status); -extern void btm_pm_proc_mode_change (uint8_t hci_status, uint16_t hci_handle, uint8_t mode, - uint16_t interval); -extern void btm_pm_proc_ssr_evt (uint8_t *p, uint16_t evt_len); -extern tBTM_STATUS btm_read_power_mode_state (BD_ADDR remote_bda, - tBTM_PM_STATE *pmState); +extern void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, + uint8_t mode, uint16_t interval); +extern void btm_pm_proc_ssr_evt(uint8_t* p, uint16_t evt_len); +extern tBTM_STATUS btm_read_power_mode_state(BD_ADDR remote_bda, + tBTM_PM_STATE* pmState); #if (BTM_SCO_INCLUDED == TRUE) -extern void btm_sco_chk_pend_unpark (uint8_t hci_status, uint16_t hci_handle); +extern void btm_sco_chk_pend_unpark(uint8_t hci_status, uint16_t hci_handle); #else #define btm_sco_chk_pend_unpark(hci_status, hci_handle) #endif /* BTM_SCO_INCLUDED */ -extern void btm_qos_setup_timeout(void *data); +extern void btm_qos_setup_timeout(void* data); extern void btm_qos_setup_complete(uint8_t status, uint16_t handle, - FLOW_SPEC *p_flow); - + FLOW_SPEC* p_flow); /* Internal functions provided by btm_sco.cc ******************************************* */ -extern void btm_sco_init (void); -extern void btm_sco_connected (uint8_t hci_status, BD_ADDR bda, uint16_t hci_handle, - tBTM_ESCO_DATA *p_esco_data); -extern void btm_esco_proc_conn_chg (uint8_t status, uint16_t handle, uint8_t tx_interval, - uint8_t retrans_window, uint16_t rx_pkt_len, - uint16_t tx_pkt_len); -extern void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, uint8_t link_type); -extern void btm_sco_removed (uint16_t hci_handle, uint8_t reason); -extern void btm_sco_acl_removed (BD_ADDR bda); -extern void btm_route_sco_data (BT_HDR *p_msg); -extern bool btm_is_sco_active (uint16_t handle); -extern void btm_remove_sco_links (BD_ADDR bda); -extern bool btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda); - -extern tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms); -extern uint16_t btm_find_scb_by_handle (uint16_t handle); +extern void btm_sco_init(void); +extern void btm_sco_connected(uint8_t hci_status, BD_ADDR bda, + uint16_t hci_handle, tBTM_ESCO_DATA* p_esco_data); +extern void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle, + uint8_t tx_interval, uint8_t retrans_window, + uint16_t rx_pkt_len, uint16_t tx_pkt_len); +extern void btm_sco_conn_req(BD_ADDR bda, DEV_CLASS dev_class, + uint8_t link_type); +extern void btm_sco_removed(uint16_t hci_handle, uint8_t reason); +extern void btm_sco_acl_removed(BD_ADDR bda); +extern void btm_route_sco_data(BT_HDR* p_msg); +extern bool btm_is_sco_active(uint16_t handle); +extern void btm_remove_sco_links(BD_ADDR bda); +extern bool btm_is_sco_active_by_bdaddr(BD_ADDR remote_bda); + +extern tBTM_SCO_TYPE btm_read_def_esco_mode(tBTM_ESCO_PARAMS* p_parms); +extern uint16_t btm_find_scb_by_handle(uint16_t handle); extern void btm_sco_flush_sco_data(uint16_t sco_inx); /* Internal functions provided by btm_devctl.cc ********************************************* */ extern void btm_dev_init(void); -extern void btm_read_local_name_timeout(void *data); -extern void btm_read_local_name_complete(uint8_t *p, uint16_t evt_len); +extern void btm_read_local_name_timeout(void* data); +extern void btm_read_local_name_complete(uint8_t* p, uint16_t evt_len); extern void btm_ble_add_2_white_list_complete(uint8_t status); -extern void btm_ble_remove_from_white_list_complete(uint8_t *p, uint16_t evt_len); -extern void btm_ble_clear_white_list_complete(uint8_t *p, uint16_t evt_len); -extern bool btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec); -extern tBTM_STATUS btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC *p_dev_rec); -extern bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec); -extern void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec); +extern void btm_ble_remove_from_white_list_complete(uint8_t* p, + uint16_t evt_len); +extern void btm_ble_clear_white_list_complete(uint8_t* p, uint16_t evt_len); +extern bool btm_ble_addr_resolvable(BD_ADDR rpa, tBTM_SEC_DEV_REC* p_dev_rec); +extern tBTM_STATUS btm_ble_read_resolving_list_entry( + tBTM_SEC_DEV_REC* p_dev_rec); +extern bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec); +extern void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC* p_dev_rec); /* Vendor Specific Command complete evt handler */ -extern void btm_vsc_complete (uint8_t *p, uint16_t cc_opcode, uint16_t evt_len, - tBTM_CMPL_CB *p_vsc_cplt_cback); -extern void btm_inq_db_reset (void); -extern void btm_vendor_specific_evt (uint8_t *p, uint8_t evt_len); -extern void btm_delete_stored_link_key_complete (uint8_t *p); -extern void btm_report_device_status (tBTM_DEV_STATUS status); - +extern void btm_vsc_complete(uint8_t* p, uint16_t cc_opcode, uint16_t evt_len, + tBTM_CMPL_CB* p_vsc_cplt_cback); +extern void btm_inq_db_reset(void); +extern void btm_vendor_specific_evt(uint8_t* p, uint8_t evt_len); +extern void btm_delete_stored_link_key_complete(uint8_t* p); +extern void btm_report_device_status(tBTM_DEV_STATUS status); /* Internal functions provided by btm_dev.cc ********************************************* */ -extern bool btm_dev_support_switch (BD_ADDR bd_addr); - -extern tBTM_SEC_DEV_REC *btm_sec_allocate_dev_rec(void); -extern tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr); -extern void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec); -extern tBTM_SEC_DEV_REC *btm_find_dev (const BD_ADDR bd_addr); -extern tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr); -extern tBTM_SEC_DEV_REC *btm_find_dev_by_handle (uint16_t handle); -extern tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr); -extern bool btm_set_bond_type_dev(BD_ADDR bd_addr, - tBTM_BOND_TYPE bond_type); +extern bool btm_dev_support_switch(BD_ADDR bd_addr); + +extern tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void); +extern tBTM_SEC_DEV_REC* btm_sec_alloc_dev(BD_ADDR bd_addr); +extern void btm_sec_free_dev(tBTM_SEC_DEV_REC* p_dev_rec); +extern tBTM_SEC_DEV_REC* btm_find_dev(const BD_ADDR bd_addr); +extern tBTM_SEC_DEV_REC* btm_find_or_alloc_dev(BD_ADDR bd_addr); +extern tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle); +extern tBTM_BOND_TYPE btm_get_bond_type_dev(BD_ADDR bd_addr); +extern bool btm_set_bond_type_dev(BD_ADDR bd_addr, tBTM_BOND_TYPE bond_type); /* Internal functions provided by btm_sec.cc ********************************************* */ -extern bool btm_dev_support_switch (BD_ADDR bd_addr); -extern tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, uint16_t psm, - uint16_t handle, CONNECTION_TYPE conn_type, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); -extern tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, uint16_t psm, bool is_originator, - uint32_t mx_proto_id, uint32_t mx_chan_id, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); -extern void btm_sec_conn_req (uint8_t *bda, uint8_t *dc); -extern void btm_create_conn_cancel_complete (uint8_t *p); - -extern void btm_read_inq_tx_power_timeout(void *data); -extern void btm_read_inq_tx_power_complete(uint8_t *p); - -extern void btm_sec_init (uint8_t sec_mode); -extern void btm_sec_dev_reset (void); -extern void btm_sec_abort_access_req (BD_ADDR bd_addr); -extern void btm_sec_auth_complete (uint16_t handle, uint8_t status); -extern void btm_sec_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enable); -extern void btm_sec_connected (uint8_t *bda, uint16_t handle, uint8_t status, uint8_t enc_mode); -extern tBTM_STATUS btm_sec_disconnect (uint16_t handle, uint8_t reason); -extern void btm_sec_disconnected (uint16_t handle, uint8_t reason); -extern void btm_sec_rmt_name_request_complete (uint8_t *bd_addr, uint8_t *bd_name, uint8_t status); -extern void btm_sec_rmt_host_support_feat_evt (uint8_t *p); -extern void btm_io_capabilities_req (uint8_t *p); -extern void btm_io_capabilities_rsp (uint8_t *p); -extern void btm_proc_sp_req_evt (tBTM_SP_EVT event, uint8_t *p); -extern void btm_keypress_notif_evt (uint8_t *p); -extern void btm_simple_pair_complete (uint8_t *p); -extern void btm_sec_link_key_notification (uint8_t *p_bda, uint8_t *p_link_key, uint8_t key_type); -extern void btm_sec_link_key_request (uint8_t *p_bda); -extern void btm_sec_pin_code_request (uint8_t *p_bda); -extern void btm_sec_update_clock_offset (uint16_t handle, uint16_t clock_offset); -extern void btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, uint8_t res, bool is_le_trasnport); -extern void btm_sec_set_peer_sec_caps (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec); - -extern void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec); -extern bool btm_sec_is_a_bonded_dev (BD_ADDR bda); -extern void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec); -extern bool btm_sec_is_le_capable_dev (BD_ADDR bda); -extern bool btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr); -extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, uint16_t psm); -extern bool btm_ble_start_sec_check(BD_ADDR bd_addr, uint16_t psm, bool is_originator, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); - -extern tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda); - -extern void btm_rem_oob_req (uint8_t *p); -extern void btm_read_local_oob_complete (uint8_t *p); - -extern void btm_acl_resubmit_page (void); -extern void btm_acl_reset_paging (void); -extern void btm_acl_paging (BT_HDR *p, BD_ADDR dest); -extern uint8_t btm_sec_clr_service_by_psm (uint16_t psm); -extern void btm_sec_clr_temp_auth_service (BD_ADDR bda); +extern bool btm_dev_support_switch(BD_ADDR bd_addr); +extern tBTM_STATUS btm_sec_l2cap_access_req(BD_ADDR bd_addr, uint16_t psm, + uint16_t handle, + CONNECTION_TYPE conn_type, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data); +extern tBTM_STATUS btm_sec_mx_access_request( + BD_ADDR bd_addr, uint16_t psm, bool is_originator, uint32_t mx_proto_id, + uint32_t mx_chan_id, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data); +extern void btm_sec_conn_req(uint8_t* bda, uint8_t* dc); +extern void btm_create_conn_cancel_complete(uint8_t* p); + +extern void btm_read_inq_tx_power_timeout(void* data); +extern void btm_read_inq_tx_power_complete(uint8_t* p); + +extern void btm_sec_init(uint8_t sec_mode); +extern void btm_sec_dev_reset(void); +extern void btm_sec_abort_access_req(BD_ADDR bd_addr); +extern void btm_sec_auth_complete(uint16_t handle, uint8_t status); +extern void btm_sec_encrypt_change(uint16_t handle, uint8_t status, + uint8_t encr_enable); +extern void btm_sec_connected(uint8_t* bda, uint16_t handle, uint8_t status, + uint8_t enc_mode); +extern tBTM_STATUS btm_sec_disconnect(uint16_t handle, uint8_t reason); +extern void btm_sec_disconnected(uint16_t handle, uint8_t reason); +extern void btm_sec_rmt_name_request_complete(uint8_t* bd_addr, + uint8_t* bd_name, uint8_t status); +extern void btm_sec_rmt_host_support_feat_evt(uint8_t* p); +extern void btm_io_capabilities_req(uint8_t* p); +extern void btm_io_capabilities_rsp(uint8_t* p); +extern void btm_proc_sp_req_evt(tBTM_SP_EVT event, uint8_t* p); +extern void btm_keypress_notif_evt(uint8_t* p); +extern void btm_simple_pair_complete(uint8_t* p); +extern void btm_sec_link_key_notification(uint8_t* p_bda, uint8_t* p_link_key, + uint8_t key_type); +extern void btm_sec_link_key_request(uint8_t* p_bda); +extern void btm_sec_pin_code_request(uint8_t* p_bda); +extern void btm_sec_update_clock_offset(uint16_t handle, uint16_t clock_offset); +extern void btm_sec_dev_rec_cback_event(tBTM_SEC_DEV_REC* p_dev_rec, + uint8_t res, bool is_le_trasnport); +extern void btm_sec_set_peer_sec_caps(tACL_CONN* p_acl_cb, + tBTM_SEC_DEV_REC* p_dev_rec); + +extern void btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC* p_dev_rec); +extern bool btm_sec_is_a_bonded_dev(BD_ADDR bda); +extern void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec); +extern bool btm_sec_is_le_capable_dev(BD_ADDR bda); +extern bool btm_ble_init_pseudo_addr(tBTM_SEC_DEV_REC* p_dev_rec, + BD_ADDR new_pseudo_addr); +extern tBTM_SEC_SERV_REC* btm_sec_find_first_serv(CONNECTION_TYPE conn_type, + uint16_t psm); +extern bool btm_ble_start_sec_check(BD_ADDR bd_addr, uint16_t psm, + bool is_originator, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data); + +extern tINQ_DB_ENT* btm_inq_db_new(BD_ADDR p_bda); + +extern void btm_rem_oob_req(uint8_t* p); +extern void btm_read_local_oob_complete(uint8_t* p); + +extern void btm_acl_resubmit_page(void); +extern void btm_acl_reset_paging(void); +extern void btm_acl_paging(BT_HDR* p, BD_ADDR dest); +extern uint8_t btm_sec_clr_service_by_psm(uint16_t psm); +extern void btm_sec_clr_temp_auth_service(BD_ADDR bda); #ifdef __cplusplus } diff --git a/stack/btm/btm_int_types.h b/stack/btm/btm_int_types.h index 860bc4fb3..46b0582e0 100644 --- a/stack/btm/btm_int_types.h +++ b/stack/btm/btm_int_types.h @@ -20,8 +20,8 @@ #include "btm_api_types.h" #include "btm_ble_api_types.h" -#include "hcidefs.h" #include "btm_ble_int_types.h" +#include "hcidefs.h" #include "osi/include/alarm.h" #include "osi/include/list.h" #include "rfcdefs.h" @@ -32,259 +32,269 @@ extern "C" { typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1]; -#define BTM_ACL_IS_CONNECTED(bda) (btm_bda_to_acl (bda, BT_TRANSPORT_BR_EDR) != NULL) +#define BTM_ACL_IS_CONNECTED(bda) \ + (btm_bda_to_acl(bda, BT_TRANSPORT_BR_EDR) != NULL) /* Definitions for Server Channel Number (SCN) management */ -#define BTM_MAX_SCN PORT_MAX_RFC_PORTS +#define BTM_MAX_SCN PORT_MAX_RFC_PORTS /* Define masks for supported and exception 2.0 ACL packet types */ -#define BTM_ACL_SUPPORTED_PKTS_MASK (HCI_PKT_TYPES_MASK_DM1 | \ - HCI_PKT_TYPES_MASK_DH1 | \ - HCI_PKT_TYPES_MASK_DM3 | \ - HCI_PKT_TYPES_MASK_DH3 | \ - HCI_PKT_TYPES_MASK_DM5 | \ - HCI_PKT_TYPES_MASK_DH5) - -#define BTM_ACL_EXCEPTION_PKTS_MASK (HCI_PKT_TYPES_MASK_NO_2_DH1 | \ - HCI_PKT_TYPES_MASK_NO_3_DH1 | \ - HCI_PKT_TYPES_MASK_NO_2_DH3 | \ - HCI_PKT_TYPES_MASK_NO_3_DH3 | \ - HCI_PKT_TYPES_MASK_NO_2_DH5 | \ - HCI_PKT_TYPES_MASK_NO_3_DH5) - -#define BTM_EPR_AVAILABLE(p) ((HCI_ATOMIC_ENCRYPT_SUPPORTED((p)->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) && \ - HCI_ATOMIC_ENCRYPT_SUPPORTED(controller_get_interface()->get_features_classic(0)->as_array)) \ - ? true : false) - -#define BTM_IS_BRCM_CONTROLLER() (controller_get_interface()->get_bt_version()->manufacturer == LMP_COMPID_BROADCOM) +#define BTM_ACL_SUPPORTED_PKTS_MASK \ + (HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | HCI_PKT_TYPES_MASK_DM3 | \ + HCI_PKT_TYPES_MASK_DH3 | HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5) + +#define BTM_ACL_EXCEPTION_PKTS_MASK \ + (HCI_PKT_TYPES_MASK_NO_2_DH1 | HCI_PKT_TYPES_MASK_NO_3_DH1 | \ + HCI_PKT_TYPES_MASK_NO_2_DH3 | HCI_PKT_TYPES_MASK_NO_3_DH3 | \ + HCI_PKT_TYPES_MASK_NO_2_DH5 | HCI_PKT_TYPES_MASK_NO_3_DH5) + +#define BTM_EPR_AVAILABLE(p) \ + ((HCI_ATOMIC_ENCRYPT_SUPPORTED( \ + (p)->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) && \ + HCI_ATOMIC_ENCRYPT_SUPPORTED( \ + controller_get_interface()->get_features_classic(0)->as_array)) \ + ? true \ + : false) + +#define BTM_IS_BRCM_CONTROLLER() \ + (controller_get_interface()->get_bt_version()->manufacturer == \ + LMP_COMPID_BROADCOM) /* Define the ACL Management control structure */ -typedef struct -{ - uint16_t hci_handle; - uint16_t pkt_types_mask; - uint16_t clock_offset; - BD_ADDR remote_addr; - DEV_CLASS remote_dc; - BD_NAME remote_name; - - uint16_t manufacturer; - uint16_t lmp_subversion; - uint16_t link_super_tout; - BD_FEATURES peer_lmp_features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Peer LMP Extended features mask table for the device */ - uint8_t num_read_pages; - uint8_t lmp_version; - - bool in_use; - uint8_t link_role; - bool link_up_issued; /* True if busy_level link up has been issued */ - -#define BTM_ACL_SWKEY_STATE_IDLE 0 -#define BTM_ACL_SWKEY_STATE_MODE_CHANGE 1 -#define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF 2 -#define BTM_ACL_SWKEY_STATE_SWITCHING 3 -#define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON 4 -#define BTM_ACL_SWKEY_STATE_IN_PROGRESS 5 - uint8_t switch_role_state; - -#define BTM_ACL_ENCRYPT_STATE_IDLE 0 -#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF 1 /* encryption turning off */ -#define BTM_ACL_ENCRYPT_STATE_TEMP_FUNC 2 /* temporarily off for change link key or role switch */ -#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON 3 /* encryption turning on */ - uint8_t encrypt_state; /* overall BTM encryption state */ - - tBT_TRANSPORT transport; - BD_ADDR conn_addr; /* local device address used for this connection */ - uint8_t conn_addr_type; /* local device address type for this connection */ - BD_ADDR active_remote_addr; /* remote address used on this connection */ - uint8_t active_remote_addr_type; /* local device address type for this connection */ - BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */ +typedef struct { + uint16_t hci_handle; + uint16_t pkt_types_mask; + uint16_t clock_offset; + BD_ADDR remote_addr; + DEV_CLASS remote_dc; + BD_NAME remote_name; + + uint16_t manufacturer; + uint16_t lmp_subversion; + uint16_t link_super_tout; + BD_FEATURES + peer_lmp_features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Peer LMP Extended + features mask table + for the device */ + uint8_t num_read_pages; + uint8_t lmp_version; + + bool in_use; + uint8_t link_role; + bool link_up_issued; /* True if busy_level link up has been issued */ + +#define BTM_ACL_SWKEY_STATE_IDLE 0 +#define BTM_ACL_SWKEY_STATE_MODE_CHANGE 1 +#define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF 2 +#define BTM_ACL_SWKEY_STATE_SWITCHING 3 +#define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON 4 +#define BTM_ACL_SWKEY_STATE_IN_PROGRESS 5 + uint8_t switch_role_state; + +#define BTM_ACL_ENCRYPT_STATE_IDLE 0 +#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF 1 /* encryption turning off */ +#define BTM_ACL_ENCRYPT_STATE_TEMP_FUNC \ + 2 /* temporarily off for change link key or role switch */ +#define BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON 3 /* encryption turning on */ + uint8_t encrypt_state; /* overall BTM encryption state */ + + tBT_TRANSPORT transport; + BD_ADDR conn_addr; /* local device address used for this connection */ + uint8_t conn_addr_type; /* local device address type for this connection */ + BD_ADDR active_remote_addr; /* remote address used on this connection */ + uint8_t active_remote_addr_type; /* local device address type for this + connection */ + BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */ } tACL_CONN; /* Define the Device Management control structure */ -typedef struct -{ - tBTM_DEV_STATUS_CB *p_dev_status_cb; /* Device status change callback */ - tBTM_VS_EVT_CB *p_vend_spec_cb[BTM_MAX_VSE_CALLBACKS]; /* Register for vendor specific events */ +typedef struct { + tBTM_DEV_STATUS_CB* p_dev_status_cb; /* Device status change callback */ + tBTM_VS_EVT_CB* p_vend_spec_cb + [BTM_MAX_VSE_CALLBACKS]; /* Register for vendor specific events */ - tBTM_CMPL_CB *p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */ + tBTM_CMPL_CB* + p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */ - alarm_t *read_local_name_timer; /* Read local name timer */ - tBTM_CMPL_CB *p_rln_cmpl_cb; /* Callback function to be called when */ - /* read local name function complete */ - alarm_t *read_rssi_timer; /* Read RSSI timer */ - tBTM_CMPL_CB *p_rssi_cmpl_cb; /* Callback function to be called when */ - /* read RSSI function completes */ - alarm_t *read_link_quality_timer; - tBTM_CMPL_CB *p_link_qual_cmpl_cb; /* Callback function to be called when */ - /* read link quality function completes */ + alarm_t* read_local_name_timer; /* Read local name timer */ + tBTM_CMPL_CB* p_rln_cmpl_cb; /* Callback function to be called when */ + /* read local name function complete */ + alarm_t* read_rssi_timer; /* Read RSSI timer */ + tBTM_CMPL_CB* p_rssi_cmpl_cb; /* Callback function to be called when */ + /* read RSSI function completes */ + alarm_t* read_link_quality_timer; + tBTM_CMPL_CB* p_link_qual_cmpl_cb; /* Callback function to be called when */ + /* read link quality function completes */ - alarm_t *read_inq_tx_power_timer; - tBTM_CMPL_CB *p_inq_tx_power_cmpl_cb; /* Callback function to be called when */ - /* read inq tx power function completes */ + alarm_t* read_inq_tx_power_timer; + tBTM_CMPL_CB* + p_inq_tx_power_cmpl_cb; /* Callback function to be called when */ + /* read inq tx power function completes */ - alarm_t *qos_setup_timer; /* QoS setup timer */ - tBTM_CMPL_CB *p_qos_setup_cmpl_cb; /* Callback function to be called when */ - /* qos setup function completes */ + alarm_t* qos_setup_timer; /* QoS setup timer */ + tBTM_CMPL_CB* p_qos_setup_cmpl_cb; /* Callback function to be called when */ + /* qos setup function completes */ - tBTM_ROLE_SWITCH_CMPL switch_role_ref_data; - tBTM_CMPL_CB *p_switch_role_cb; /* Callback function to be called when */ - /* requested switch role is completed */ + tBTM_ROLE_SWITCH_CMPL switch_role_ref_data; + tBTM_CMPL_CB* p_switch_role_cb; /* Callback function to be called when */ + /* requested switch role is completed */ - alarm_t *read_tx_power_timer; /* Read tx power timer */ - tBTM_CMPL_CB *p_tx_power_cmpl_cb;/* Callback function to be called */ + alarm_t* read_tx_power_timer; /* Read tx power timer */ + tBTM_CMPL_CB* p_tx_power_cmpl_cb; /* Callback function to be called */ - DEV_CLASS dev_class; /* Local device class */ + DEV_CLASS dev_class; /* Local device class */ - tBTM_CMPL_CB *p_le_test_cmd_cmpl_cb; /* Callback function to be called when - LE test mode command has been sent successfully */ + tBTM_CMPL_CB* + p_le_test_cmd_cmpl_cb; /* Callback function to be called when + LE test mode command has been sent successfully */ - BD_ADDR read_tx_pwr_addr; /* read TX power target address */ + BD_ADDR read_tx_pwr_addr; /* read TX power target address */ -#define BTM_LE_SUPPORT_STATE_SIZE 8 -uint8_t le_supported_states[BTM_LE_SUPPORT_STATE_SIZE]; +#define BTM_LE_SUPPORT_STATE_SIZE 8 + uint8_t le_supported_states[BTM_LE_SUPPORT_STATE_SIZE]; -tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */ -BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */ + tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */ + BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */ #if (BTM_BLE_CONFORMANCE_TESTING == TRUE) - bool no_disc_if_pair_fail; - bool enable_test_mac_val; - BT_OCTET8 test_mac; - bool enable_test_local_sign_cntr; - uint32_t test_local_sign_cntr; + bool no_disc_if_pair_fail; + bool enable_test_mac_val; + BT_OCTET8 test_mac; + bool enable_test_local_sign_cntr; + uint32_t test_local_sign_cntr; #endif - tBTM_IO_CAP loc_io_caps; /* IO capability of the local device */ - tBTM_AUTH_REQ loc_auth_req; /* the auth_req flag */ - bool secure_connections_only; /* Rejects service level 0 connections if */ - /* itself or peer device doesn't support */ - /* secure connections */ + tBTM_IO_CAP loc_io_caps; /* IO capability of the local device */ + tBTM_AUTH_REQ loc_auth_req; /* the auth_req flag */ + bool secure_connections_only; /* Rejects service level 0 connections if */ + /* itself or peer device doesn't support */ + /* secure connections */ } tBTM_DEVCB; - /* Define the structures and constants used for inquiry */ /* Definitions of limits for inquiries */ -#define BTM_PER_INQ_MIN_MAX_PERIOD HCI_PER_INQ_MIN_MAX_PERIOD -#define BTM_PER_INQ_MAX_MAX_PERIOD HCI_PER_INQ_MAX_MAX_PERIOD -#define BTM_PER_INQ_MIN_MIN_PERIOD HCI_PER_INQ_MIN_MIN_PERIOD -#define BTM_PER_INQ_MAX_MIN_PERIOD HCI_PER_INQ_MAX_MIN_PERIOD -#define BTM_MAX_INQUIRY_LENGTH HCI_MAX_INQUIRY_LENGTH -#define BTM_MIN_INQUIRY_LEN 0x01 - -#define BTM_MIN_INQ_TX_POWER (-70) -#define BTM_MAX_INQ_TX_POWER 20 - -typedef struct -{ - uint32_t inq_count; /* Used for determining if a response has already been */ - /* received for the current inquiry operation. (We do not */ - /* want to flood the caller with multiple responses from */ - /* the same device. */ - BD_ADDR bd_addr; +#define BTM_PER_INQ_MIN_MAX_PERIOD HCI_PER_INQ_MIN_MAX_PERIOD +#define BTM_PER_INQ_MAX_MAX_PERIOD HCI_PER_INQ_MAX_MAX_PERIOD +#define BTM_PER_INQ_MIN_MIN_PERIOD HCI_PER_INQ_MIN_MIN_PERIOD +#define BTM_PER_INQ_MAX_MIN_PERIOD HCI_PER_INQ_MAX_MIN_PERIOD +#define BTM_MAX_INQUIRY_LENGTH HCI_MAX_INQUIRY_LENGTH +#define BTM_MIN_INQUIRY_LEN 0x01 + +#define BTM_MIN_INQ_TX_POWER (-70) +#define BTM_MAX_INQ_TX_POWER 20 + +typedef struct { + uint32_t inq_count; /* Used for determining if a response has already been */ + /* received for the current inquiry operation. (We do not */ + /* want to flood the caller with multiple responses from */ + /* the same device. */ + BD_ADDR bd_addr; } tINQ_BDADDR; -typedef struct -{ - uint32_t time_of_resp; - uint32_t inq_count; /* "timestamps" the entry with a particular inquiry count */ - /* Used for determining if a response has already been */ - /* received for the current inquiry operation. (We do not */ - /* want to flood the caller with multiple responses from */ - /* the same device. */ - tBTM_INQ_INFO inq_info; - bool in_use; - bool scan_rsp; +typedef struct { + uint32_t time_of_resp; + uint32_t + inq_count; /* "timestamps" the entry with a particular inquiry count */ + /* Used for determining if a response has already been */ + /* received for the current inquiry operation. (We do not */ + /* want to flood the caller with multiple responses from */ + /* the same device. */ + tBTM_INQ_INFO inq_info; + bool in_use; + bool scan_rsp; } tINQ_DB_ENT; - -enum -{ - INQ_NONE, - INQ_LE_OBSERVE, - INQ_GENERAL -}; +enum { INQ_NONE, INQ_LE_OBSERVE, INQ_GENERAL }; typedef uint8_t tBTM_INQ_TYPE; -typedef struct -{ - tBTM_CMPL_CB *p_remname_cmpl_cb; +typedef struct { + tBTM_CMPL_CB* p_remname_cmpl_cb; #define BTM_EXT_RMT_NAME_TIMEOUT_MS (40 * 1000) /* 40 seconds */ - - alarm_t *remote_name_timer; - - uint16_t discoverable_mode; - uint16_t connectable_mode; - uint16_t page_scan_window; - uint16_t page_scan_period; - uint16_t inq_scan_window; - uint16_t inq_scan_period; - uint16_t inq_scan_type; - uint16_t page_scan_type; /* current page scan type */ - tBTM_INQ_TYPE scan_type; - - BD_ADDR remname_bda; /* Name of bd addr for active remote name request */ -#define BTM_RMT_NAME_INACTIVE 0 -#define BTM_RMT_NAME_EXT 0x1 /* Initiated through API */ -#define BTM_RMT_NAME_SEC 0x2 /* Initiated internally by security manager */ -#define BTM_RMT_NAME_INQ 0x4 /* Remote name initiated internally by inquiry */ - bool remname_active; /* State of a remote name request by external API */ - - tBTM_CMPL_CB *p_inq_cmpl_cb; - tBTM_INQ_RESULTS_CB *p_inq_results_cb; - tBTM_CMPL_CB *p_inq_ble_cmpl_cb; /*completion callback exclusively for LE Observe*/ - tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb;/*results callback exclusively for LE observe*/ - tBTM_CMPL_CB *p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry filter completed */ - uint32_t inq_counter; /* Counter incremented each time an inquiry completes */ - /* Used for determining whether or not duplicate devices */ - /* have responded to the same inquiry */ - tINQ_BDADDR *p_bd_db; /* Pointer to memory that holds bdaddrs */ - uint16_t num_bd_entries; /* Number of entries in database */ - uint16_t max_bd_entries; /* Maximum number of entries that can be stored */ - tINQ_DB_ENT inq_db[BTM_INQ_DB_SIZE]; - tBTM_INQ_PARMS inqparms; /* Contains the parameters for the current inquiry */ - tBTM_INQUIRY_CMPL inq_cmpl_info; /* Status and number of responses from the last inquiry */ - - uint16_t per_min_delay; /* Current periodic minimum delay */ - uint16_t per_max_delay; /* Current periodic maximum delay */ - bool inqfilt_active; - uint8_t pending_filt_complete_event; /* to take care of btm_event_filter_complete corresponding to */ - /* inquiry that has been cancelled*/ - uint8_t inqfilt_type; /* Contains the inquiry filter type (BD ADDR, COD, or Clear) */ - -#define BTM_INQ_INACTIVE_STATE 0 -#define BTM_INQ_CLR_FILT_STATE 1 /* Currently clearing the inquiry filter preceeding the inquiry request */ - /* (bypassed if filtering is not used) */ -#define BTM_INQ_SET_FILT_STATE 2 /* Sets the new filter (or turns off filtering) in this state */ -#define BTM_INQ_ACTIVE_STATE 3 /* Actual inquiry or periodic inquiry is in progress */ -#define BTM_INQ_REMNAME_STATE 4 /* Remote name requests are active */ - - uint8_t state; /* Current state that the inquiry process is in */ - uint8_t inq_active; /* Bit Mask indicating type of inquiry is active */ - bool no_inc_ssp; /* true, to stop inquiry on incoming SSP */ + alarm_t* remote_name_timer; + + uint16_t discoverable_mode; + uint16_t connectable_mode; + uint16_t page_scan_window; + uint16_t page_scan_period; + uint16_t inq_scan_window; + uint16_t inq_scan_period; + uint16_t inq_scan_type; + uint16_t page_scan_type; /* current page scan type */ + tBTM_INQ_TYPE scan_type; + + BD_ADDR remname_bda; /* Name of bd addr for active remote name request */ +#define BTM_RMT_NAME_INACTIVE 0 +#define BTM_RMT_NAME_EXT 0x1 /* Initiated through API */ +#define BTM_RMT_NAME_SEC 0x2 /* Initiated internally by security manager */ +#define BTM_RMT_NAME_INQ 0x4 /* Remote name initiated internally by inquiry */ + bool remname_active; /* State of a remote name request by external API */ + + tBTM_CMPL_CB* p_inq_cmpl_cb; + tBTM_INQ_RESULTS_CB* p_inq_results_cb; + tBTM_CMPL_CB* + p_inq_ble_cmpl_cb; /*completion callback exclusively for LE Observe*/ + tBTM_INQ_RESULTS_CB* + p_inq_ble_results_cb; /*results callback exclusively for LE observe*/ + tBTM_CMPL_CB* p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry + filter completed */ + uint32_t inq_counter; /* Counter incremented each time an inquiry completes */ + /* Used for determining whether or not duplicate devices */ + /* have responded to the same inquiry */ + tINQ_BDADDR* p_bd_db; /* Pointer to memory that holds bdaddrs */ + uint16_t num_bd_entries; /* Number of entries in database */ + uint16_t max_bd_entries; /* Maximum number of entries that can be stored */ + tINQ_DB_ENT inq_db[BTM_INQ_DB_SIZE]; + tBTM_INQ_PARMS inqparms; /* Contains the parameters for the current inquiry */ + tBTM_INQUIRY_CMPL + inq_cmpl_info; /* Status and number of responses from the last inquiry */ + + uint16_t per_min_delay; /* Current periodic minimum delay */ + uint16_t per_max_delay; /* Current periodic maximum delay */ + bool inqfilt_active; + uint8_t pending_filt_complete_event; /* to take care of + btm_event_filter_complete + corresponding to */ + /* inquiry that has been cancelled*/ + uint8_t inqfilt_type; /* Contains the inquiry filter type (BD ADDR, COD, or + Clear) */ + +#define BTM_INQ_INACTIVE_STATE 0 +#define BTM_INQ_CLR_FILT_STATE \ + 1 /* Currently clearing the inquiry filter preceeding the inquiry request */ + /* (bypassed if filtering is not used) */ +#define BTM_INQ_SET_FILT_STATE \ + 2 /* Sets the new filter (or turns off filtering) in this state */ +#define BTM_INQ_ACTIVE_STATE \ + 3 /* Actual inquiry or periodic inquiry is in progress */ +#define BTM_INQ_REMNAME_STATE 4 /* Remote name requests are active */ + + uint8_t state; /* Current state that the inquiry process is in */ + uint8_t inq_active; /* Bit Mask indicating type of inquiry is active */ + bool no_inc_ssp; /* true, to stop inquiry on incoming SSP */ #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - btm_inq_state next_state; /*interleaving state to determine next mode to be inquired*/ + btm_inq_state + next_state; /*interleaving state to determine next mode to be inquired*/ #endif } tBTM_INQUIRY_VAR_ST; /* The MSB of the clock offset field indicates whether the offset is valid. */ -#define BTM_CLOCK_OFFSET_VALID 0x8000 +#define BTM_CLOCK_OFFSET_VALID 0x8000 /* Define the structures needed by security management */ -#define BTM_SEC_INVALID_HANDLE 0xFFFF +#define BTM_SEC_INVALID_HANDLE 0xFFFF -typedef uint8_t *BTM_BD_NAME_PTR; /* Pointer to Device name */ +typedef uint8_t* BTM_BD_NAME_PTR; /* Pointer to Device name */ /* Security callback is called by this unit when security * procedures are completed. Parameters are @@ -293,569 +303,583 @@ typedef uint8_t *BTM_BD_NAME_PTR; /* Pointer to Device na */ typedef tBTM_SEC_CBACK tBTM_SEC_CALLBACK; -typedef void (tBTM_SCO_IND_CBACK) (uint16_t sco_inx) ; +typedef void(tBTM_SCO_IND_CBACK)(uint16_t sco_inx); /* MACROs to convert from SCO packet types mask to ESCO and back */ -#define BTM_SCO_PKT_TYPE_MASK ( HCI_PKT_TYPES_MASK_HV1 \ - | HCI_PKT_TYPES_MASK_HV2 \ - | HCI_PKT_TYPES_MASK_HV3) +#define BTM_SCO_PKT_TYPE_MASK \ + (HCI_PKT_TYPES_MASK_HV1 | HCI_PKT_TYPES_MASK_HV2 | HCI_PKT_TYPES_MASK_HV3) /* Mask defining only the SCO types of an esco packet type */ -#define BTM_ESCO_PKT_TYPE_MASK ( HCI_ESCO_PKT_TYPES_MASK_HV1 \ - | HCI_ESCO_PKT_TYPES_MASK_HV2 \ - | HCI_ESCO_PKT_TYPES_MASK_HV3) +#define BTM_ESCO_PKT_TYPE_MASK \ + (HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | \ + HCI_ESCO_PKT_TYPES_MASK_HV3) -#define BTM_SCO_2_ESCO(scotype) ((uint16_t)(((scotype) & BTM_SCO_PKT_TYPE_MASK) >> 5)) -#define BTM_ESCO_2_SCO(escotype) ((uint16_t)(((escotype) & BTM_ESCO_PKT_TYPE_MASK) << 5)) +#define BTM_SCO_2_ESCO(scotype) \ + ((uint16_t)(((scotype)&BTM_SCO_PKT_TYPE_MASK) >> 5)) +#define BTM_ESCO_2_SCO(escotype) \ + ((uint16_t)(((escotype)&BTM_ESCO_PKT_TYPE_MASK) << 5)) /* Define masks for supported and exception 2.0 SCO packet types */ -#define BTM_SCO_SUPPORTED_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_HV1 | \ - HCI_ESCO_PKT_TYPES_MASK_HV2 | \ - HCI_ESCO_PKT_TYPES_MASK_HV3 | \ - HCI_ESCO_PKT_TYPES_MASK_EV3 | \ - HCI_ESCO_PKT_TYPES_MASK_EV4 | \ - HCI_ESCO_PKT_TYPES_MASK_EV5) - -#define BTM_SCO_EXCEPTION_PKTS_MASK (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | \ - HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | \ - HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 | \ - HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5) +#define BTM_SCO_SUPPORTED_PKTS_MASK \ + (HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | \ + HCI_ESCO_PKT_TYPES_MASK_HV3 | HCI_ESCO_PKT_TYPES_MASK_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_EV4 | HCI_ESCO_PKT_TYPES_MASK_EV5) +#define BTM_SCO_EXCEPTION_PKTS_MASK \ + (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 | HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5) -#define BTM_SCO_ROUTE_UNKNOWN 0xff +#define BTM_SCO_ROUTE_UNKNOWN 0xff /* Define the structure that contains (e)SCO data */ -typedef struct -{ - tBTM_ESCO_CBACK *p_esco_cback; /* Callback for eSCO events */ - tBTM_ESCO_PARAMS setup; - tBTM_ESCO_DATA data; /* Connection complete information */ - uint8_t hci_status; +typedef struct { + tBTM_ESCO_CBACK* p_esco_cback; /* Callback for eSCO events */ + tBTM_ESCO_PARAMS setup; + tBTM_ESCO_DATA data; /* Connection complete information */ + uint8_t hci_status; } tBTM_ESCO_INFO; /* Define the structure used for SCO Management */ -typedef struct -{ - tBTM_ESCO_INFO esco; /* Current settings */ +typedef struct { + tBTM_ESCO_INFO esco; /* Current settings */ #if (BTM_SCO_HCI_INCLUDED == TRUE) - fixed_queue_t *xmit_data_q; /* SCO data transmitting queue */ + fixed_queue_t* xmit_data_q; /* SCO data transmitting queue */ #endif - tBTM_SCO_CB *p_conn_cb; /* Callback for when connected */ - tBTM_SCO_CB *p_disc_cb; /* Callback for when disconnect */ - uint16_t state; /* The state of the SCO link */ - uint16_t hci_handle; /* HCI Handle */ - bool is_orig; /* true if the originator */ - bool rem_bd_known; /* true if remote BD addr known */ + tBTM_SCO_CB* p_conn_cb; /* Callback for when connected */ + tBTM_SCO_CB* p_disc_cb; /* Callback for when disconnect */ + uint16_t state; /* The state of the SCO link */ + uint16_t hci_handle; /* HCI Handle */ + bool is_orig; /* true if the originator */ + bool rem_bd_known; /* true if remote BD addr known */ } tSCO_CONN; /* SCO Management control block */ -typedef struct -{ - tBTM_SCO_IND_CBACK *app_sco_ind_cb; +typedef struct { + tBTM_SCO_IND_CBACK* app_sco_ind_cb; #if (BTM_SCO_HCI_INCLUDED == TRUE) - tBTM_SCO_DATA_CB *p_data_cb; /* Callback for SCO data over HCI */ - uint32_t xmit_window_size; /* Total SCO window in bytes */ + tBTM_SCO_DATA_CB* p_data_cb; /* Callback for SCO data over HCI */ + uint32_t xmit_window_size; /* Total SCO window in bytes */ #endif - tSCO_CONN sco_db[BTM_MAX_SCO_LINKS]; - tBTM_ESCO_PARAMS def_esco_parms; - BD_ADDR xfer_addr; - uint16_t sco_disc_reason; - bool esco_supported; /* true if 1.2 cntlr AND supports eSCO links */ - tBTM_SCO_TYPE desired_sco_mode; - tBTM_SCO_TYPE xfer_sco_type; - tBTM_SCO_PCM_PARAM sco_pcm_param; - tBTM_SCO_CODEC_TYPE codec_in_use; /* None, CVSD, MSBC, etc. */ + tSCO_CONN sco_db[BTM_MAX_SCO_LINKS]; + tBTM_ESCO_PARAMS def_esco_parms; + BD_ADDR xfer_addr; + uint16_t sco_disc_reason; + bool esco_supported; /* true if 1.2 cntlr AND supports eSCO links */ + tBTM_SCO_TYPE desired_sco_mode; + tBTM_SCO_TYPE xfer_sco_type; + tBTM_SCO_PCM_PARAM sco_pcm_param; + tBTM_SCO_CODEC_TYPE codec_in_use; /* None, CVSD, MSBC, etc. */ #if (BTM_SCO_HCI_INCLUDED == TRUE) - tBTM_SCO_ROUTE_TYPE sco_path; + tBTM_SCO_ROUTE_TYPE sco_path; #endif } tSCO_CB; - #if (BTM_SCO_INCLUDED == TRUE) -extern void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb ); -extern void btm_accept_sco_link(uint16_t sco_inx, tBTM_ESCO_PARAMS *p_setup, - tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb); -extern void btm_reject_sco_link(uint16_t sco_inx ); -extern void btm_sco_chk_pend_rolechange (uint16_t hci_handle); -extern void btm_sco_disc_chk_pend_for_modechange (uint16_t hci_handle); +extern void btm_set_sco_ind_cback(tBTM_SCO_IND_CBACK* sco_ind_cb); +extern void btm_accept_sco_link(uint16_t sco_inx, tBTM_ESCO_PARAMS* p_setup, + tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb); +extern void btm_reject_sco_link(uint16_t sco_inx); +extern void btm_sco_chk_pend_rolechange(uint16_t hci_handle); +extern void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle); #else #define btm_accept_sco_link(sco_inx, p_setup, p_conn_cb, p_disc_cb) #define btm_reject_sco_link(sco_inx) #define btm_set_sco_ind_cback(sco_ind_cb) #define btm_sco_chk_pend_rolechange(hci_handle) -#endif /* BTM_SCO_INCLUDED */ +#endif /* BTM_SCO_INCLUDED */ /* * Define structure for Security Service Record. * A record exists for each service registered with the Security Manager */ -#define BTM_SEC_OUT_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHORIZE) -#define BTM_SEC_IN_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE) - -#define BTM_SEC_OUT_LEVEL4_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | \ - BTM_SEC_OUT_MITM | BTM_SEC_MODE4_LEVEL4) - -#define BTM_SEC_IN_LEVEL4_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \ - BTM_SEC_IN_MITM | BTM_SEC_MODE4_LEVEL4) -typedef struct -{ - uint32_t mx_proto_id; /* Service runs over this multiplexer protocol */ - uint32_t orig_mx_chan_id; /* Channel on the multiplexer protocol */ - uint32_t term_mx_chan_id; /* Channel on the multiplexer protocol */ - uint16_t psm; /* L2CAP PSM value */ - uint16_t security_flags; /* Bitmap of required security features */ - uint8_t service_id; /* Passed in authorization callback */ +#define BTM_SEC_OUT_FLAGS \ + (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHORIZE) +#define BTM_SEC_IN_FLAGS \ + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE) + +#define BTM_SEC_OUT_LEVEL4_FLAGS \ + (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_MITM | \ + BTM_SEC_MODE4_LEVEL4) + +#define BTM_SEC_IN_LEVEL4_FLAGS \ + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_MITM | \ + BTM_SEC_MODE4_LEVEL4) +typedef struct { + uint32_t mx_proto_id; /* Service runs over this multiplexer protocol */ + uint32_t orig_mx_chan_id; /* Channel on the multiplexer protocol */ + uint32_t term_mx_chan_id; /* Channel on the multiplexer protocol */ + uint16_t psm; /* L2CAP PSM value */ + uint16_t security_flags; /* Bitmap of required security features */ + uint8_t service_id; /* Passed in authorization callback */ #if (L2CAP_UCD_INCLUDED == TRUE) - uint16_t ucd_security_flags; /* Bitmap of required security features for UCD */ + uint16_t + ucd_security_flags; /* Bitmap of required security features for UCD */ #endif #if BTM_SEC_SERVICE_NAME_LEN > 0 - uint8_t orig_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; - uint8_t term_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; + uint8_t orig_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; + uint8_t term_service_name[BTM_SEC_SERVICE_NAME_LEN + 1]; #endif } tBTM_SEC_SERV_REC; /* LE Security information of device in Slave Role */ -typedef struct -{ - BT_OCTET16 irk; /* peer diverified identity root */ - BT_OCTET16 pltk; /* peer long term key */ - BT_OCTET16 pcsrk; /* peer SRK peer device used to secured sign local data */ - - BT_OCTET16 lltk; /* local long term key */ - BT_OCTET16 lcsrk; /* local SRK peer device used to secured sign local data */ - - BT_OCTET8 rand; /* random vector for LTK generation */ - uint16_t ediv; /* LTK diversifier of this slave device */ - uint16_t div; /* local DIV to generate local LTK=d1(ER,DIV,0) and CSRK=d1(ER,DIV,1) */ - uint8_t sec_level; /* local pairing security level */ - uint8_t key_size; /* key size of the LTK delivered to peer device */ - uint8_t srk_sec_level; /* security property of peer SRK for this device */ - uint8_t local_csrk_sec_level; /* security property of local CSRK for this device */ - - uint32_t counter; /* peer sign counter for verifying rcv signed cmd */ - uint32_t local_counter; /* local sign counter for sending signed write cmd*/ -}tBTM_SEC_BLE_KEYS; - -typedef struct -{ - BD_ADDR pseudo_addr; /* LE pseudo address of the device if different from device address */ - tBLE_ADDR_TYPE ble_addr_type; /* LE device type: public or random address */ - tBLE_ADDR_TYPE static_addr_type; /* static address type */ - BD_ADDR static_addr; /* static address */ - -#define BTM_WHITE_LIST_BIT 0x01 -#define BTM_RESOLVING_LIST_BIT 0x02 - uint8_t in_controller_list; /* in controller resolving list or not */ - uint8_t resolving_list_index; +typedef struct { + BT_OCTET16 irk; /* peer diverified identity root */ + BT_OCTET16 pltk; /* peer long term key */ + BT_OCTET16 pcsrk; /* peer SRK peer device used to secured sign local data */ + + BT_OCTET16 lltk; /* local long term key */ + BT_OCTET16 lcsrk; /* local SRK peer device used to secured sign local data */ + + BT_OCTET8 rand; /* random vector for LTK generation */ + uint16_t ediv; /* LTK diversifier of this slave device */ + uint16_t div; /* local DIV to generate local LTK=d1(ER,DIV,0) and + CSRK=d1(ER,DIV,1) */ + uint8_t sec_level; /* local pairing security level */ + uint8_t key_size; /* key size of the LTK delivered to peer device */ + uint8_t srk_sec_level; /* security property of peer SRK for this device */ + uint8_t local_csrk_sec_level; /* security property of local CSRK for this + device */ + + uint32_t counter; /* peer sign counter for verifying rcv signed cmd */ + uint32_t local_counter; /* local sign counter for sending signed write cmd*/ +} tBTM_SEC_BLE_KEYS; + +typedef struct { + BD_ADDR pseudo_addr; /* LE pseudo address of the device if different from + device address */ + tBLE_ADDR_TYPE ble_addr_type; /* LE device type: public or random address */ + tBLE_ADDR_TYPE static_addr_type; /* static address type */ + BD_ADDR static_addr; /* static address */ + +#define BTM_WHITE_LIST_BIT 0x01 +#define BTM_RESOLVING_LIST_BIT 0x02 + uint8_t in_controller_list; /* in controller resolving list or not */ + uint8_t resolving_list_index; #if (BLE_PRIVACY_SPT == TRUE) - BD_ADDR cur_rand_addr; /* current random address */ + BD_ADDR cur_rand_addr; /* current random address */ -#define BTM_BLE_ADDR_PSEUDO 0 /* address index device record */ -#define BTM_BLE_ADDR_RRA 1 /* cur_rand_addr */ -#define BTM_BLE_ADDR_STATIC 2 /* static_addr */ - uint8_t active_addr_type; +#define BTM_BLE_ADDR_PSEUDO 0 /* address index device record */ +#define BTM_BLE_ADDR_RRA 1 /* cur_rand_addr */ +#define BTM_BLE_ADDR_STATIC 2 /* static_addr */ + uint8_t active_addr_type; #endif - tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */ - tBTM_SEC_BLE_KEYS keys; /* LE device security info in slave rode */ + tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */ + tBTM_SEC_BLE_KEYS keys; /* LE device security info in slave rode */ } tBTM_SEC_BLE; /* Peering bond type */ -enum -{ - BOND_TYPE_UNKNOWN, - BOND_TYPE_PERSISTENT, - BOND_TYPE_TEMPORARY -}; +enum { BOND_TYPE_UNKNOWN, BOND_TYPE_PERSISTENT, BOND_TYPE_TEMPORARY }; typedef uint8_t tBTM_BOND_TYPE; /* * Define structure for Security Device Record. * A record exists for each device authenticated with this device */ -typedef struct -{ - tBTM_SEC_SERV_REC *p_cur_service; - tBTM_SEC_CALLBACK *p_callback; - void *p_ref_data; - uint32_t timestamp; /* Timestamp of the last connection */ - uint32_t trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; /* Bitwise OR of trusted services */ - uint16_t hci_handle; /* Handle to connection when exists */ - uint16_t clock_offset; /* Latest known clock offset */ - BD_ADDR bd_addr; /* BD_ADDR of the device */ - DEV_CLASS dev_class; /* DEV_CLASS of the device */ - LINK_KEY link_key; /* Device link key */ - uint8_t pin_code_length; /* Length of the pin_code used for paring */ - -#define BTM_SEC_AUTHORIZED BTM_SEC_FLAG_AUTHORIZED /* 0x01 */ -#define BTM_SEC_AUTHENTICATED BTM_SEC_FLAG_AUTHENTICATED /* 0x02 */ -#define BTM_SEC_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED /* 0x04 */ -#define BTM_SEC_NAME_KNOWN 0x08 -#define BTM_SEC_LINK_KEY_KNOWN BTM_SEC_FLAG_LKEY_KNOWN /* 0x10 */ -#define BTM_SEC_LINK_KEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED /* 0x20 */ -#define BTM_SEC_ROLE_SWITCHED 0x40 -#define BTM_SEC_IN_USE 0x80 - /* LE link security flag */ -#define BTM_SEC_LE_AUTHENTICATED 0x0200 /* LE link is encrypted after pairing with MITM */ -#define BTM_SEC_LE_ENCRYPTED 0x0400 /* LE link is encrypted */ -#define BTM_SEC_LE_NAME_KNOWN 0x0800 /* not used */ -#define BTM_SEC_LE_LINK_KEY_KNOWN 0x1000 /* bonded with peer (peer LTK and/or SRK is saved) */ -#define BTM_SEC_LE_LINK_KEY_AUTHED 0x2000 /* pairing is done with MITM */ -#define BTM_SEC_16_DIGIT_PIN_AUTHED 0x4000 /* pairing is done with 16 digit pin */ - - uint16_t sec_flags; /* Current device security state */ - - tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be truncated to save space in dev_rec table) */ - BD_FEATURES features[HCI_EXT_FEATURES_PAGE_MAX + 1]; /* Features supported by the device */ - uint8_t num_read_pages; - -#define BTM_SEC_STATE_IDLE 0 -#define BTM_SEC_STATE_AUTHENTICATING 1 -#define BTM_SEC_STATE_ENCRYPTING 2 -#define BTM_SEC_STATE_GETTING_NAME 3 -#define BTM_SEC_STATE_AUTHORIZING 4 -#define BTM_SEC_STATE_SWITCHING_ROLE 5 -#define BTM_SEC_STATE_DISCONNECTING 6 /* disconnecting BR/EDR */ -#define BTM_SEC_STATE_DELAY_FOR_ENC 7 /* delay to check for encryption to work around */ - /* controller problems */ -#define BTM_SEC_STATE_DISCONNECTING_BLE 8 /* disconnecting BLE */ +typedef struct { + tBTM_SEC_SERV_REC* p_cur_service; + tBTM_SEC_CALLBACK* p_callback; + void* p_ref_data; + uint32_t timestamp; /* Timestamp of the last connection */ + uint32_t trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; /* Bitwise OR of trusted + services */ + uint16_t hci_handle; /* Handle to connection when exists */ + uint16_t clock_offset; /* Latest known clock offset */ + BD_ADDR bd_addr; /* BD_ADDR of the device */ + DEV_CLASS dev_class; /* DEV_CLASS of the device */ + LINK_KEY link_key; /* Device link key */ + uint8_t pin_code_length; /* Length of the pin_code used for paring */ + +#define BTM_SEC_AUTHORIZED BTM_SEC_FLAG_AUTHORIZED /* 0x01 */ +#define BTM_SEC_AUTHENTICATED BTM_SEC_FLAG_AUTHENTICATED /* 0x02 */ +#define BTM_SEC_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED /* 0x04 */ +#define BTM_SEC_NAME_KNOWN 0x08 +#define BTM_SEC_LINK_KEY_KNOWN BTM_SEC_FLAG_LKEY_KNOWN /* 0x10 */ +#define BTM_SEC_LINK_KEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED /* 0x20 */ +#define BTM_SEC_ROLE_SWITCHED 0x40 +#define BTM_SEC_IN_USE 0x80 +/* LE link security flag */ +#define BTM_SEC_LE_AUTHENTICATED \ + 0x0200 /* LE link is encrypted after pairing with MITM */ +#define BTM_SEC_LE_ENCRYPTED 0x0400 /* LE link is encrypted */ +#define BTM_SEC_LE_NAME_KNOWN 0x0800 /* not used */ +#define BTM_SEC_LE_LINK_KEY_KNOWN \ + 0x1000 /* bonded with peer (peer LTK and/or SRK is saved) */ +#define BTM_SEC_LE_LINK_KEY_AUTHED 0x2000 /* pairing is done with MITM */ +#define BTM_SEC_16_DIGIT_PIN_AUTHED \ + 0x4000 /* pairing is done with 16 digit pin */ + + uint16_t sec_flags; /* Current device security state */ + + tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be + truncated to save space in dev_rec table) */ + BD_FEATURES features[HCI_EXT_FEATURES_PAGE_MAX + + 1]; /* Features supported by the device */ + uint8_t num_read_pages; + +#define BTM_SEC_STATE_IDLE 0 +#define BTM_SEC_STATE_AUTHENTICATING 1 +#define BTM_SEC_STATE_ENCRYPTING 2 +#define BTM_SEC_STATE_GETTING_NAME 3 +#define BTM_SEC_STATE_AUTHORIZING 4 +#define BTM_SEC_STATE_SWITCHING_ROLE 5 +#define BTM_SEC_STATE_DISCONNECTING 6 /* disconnecting BR/EDR */ +#define BTM_SEC_STATE_DELAY_FOR_ENC \ + 7 /* delay to check for encryption to work around */ + /* controller problems */ +#define BTM_SEC_STATE_DISCONNECTING_BLE 8 /* disconnecting BLE */ #define BTM_SEC_STATE_DISCONNECTING_BOTH 9 /* disconnecting BR/EDR and BLE */ - uint8_t sec_state; /* Operating state */ - bool is_originator; /* true if device is originating connection */ + uint8_t sec_state; /* Operating state */ + bool is_originator; /* true if device is originating connection */ #if (L2CAP_UCD_INCLUDED == TRUE) - bool is_ucd; /* true if device is sending or receiving UCD */ - /* if incoming security failed, received UCD will be discarded */ + bool is_ucd; /* true if device is sending or receiving UCD */ + /* if incoming security failed, received UCD will be discarded */ #endif - bool role_master; /* true if current mode is master */ - uint16_t security_required; /* Security required for connection */ - bool link_key_not_sent; /* link key notification has not been sent waiting for name */ - uint8_t link_key_type; /* Type of key used in pairing */ - bool link_key_changed; /* Changed link key during current connection */ - -#define BTM_MAX_PRE_SM4_LKEY_TYPE BTM_LKEY_TYPE_REMOTE_UNIT /* the link key type used by legacy pairing */ - -#define BTM_SM4_UNKNOWN 0x00 -#define BTM_SM4_KNOWN 0x10 -#define BTM_SM4_TRUE 0x11 -#define BTM_SM4_REQ_PEND 0x08 /* set this bit when getting remote features */ -#define BTM_SM4_UPGRADE 0x04 /* set this bit when upgrading link key */ -#define BTM_SM4_RETRY 0x02 /* set this bit to retry on HCI_ERR_KEY_MISSING or HCI_ERR_LMP_ERR_TRANS_COLLISION */ -#define BTM_SM4_DD_ACP 0x20 /* set this bit to indicate peer initiated dedicated bonding */ -#define BTM_SM4_CONN_PEND 0x40 /* set this bit to indicate accepting acl conn; to be cleared on btm_acl_created */ - uint8_t sm4; /* BTM_SM4_TRUE, if the peer supports SM4 */ - tBTM_IO_CAP rmt_io_caps; /* IO capability of the peer device */ - tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */ - bool remote_supports_secure_connections; - bool remote_features_needed; /* set to true if the local device is in */ - /* "Secure Connections Only" mode and it receives */ - /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */ - /* it knows peer's support for Secure Connections */ - - uint16_t ble_hci_handle; /* use in DUMO connection */ - uint8_t enc_key_size; /* current link encryption key size */ - tBT_DEVICE_TYPE device_type; - bool new_encryption_key_is_p256; /* Set to true when the newly generated LK - ** is generated from P-256. - ** Link encrypted with such LK can be used - ** for SM over BR/EDR. - */ - bool no_smp_on_br; /* if set to true then SMP on BR/EDR doesn't */ - /* work, i.e. link keys crosspairing */ - /* SC BR/EDR->SC LE doesn't happen */ - tBTM_BOND_TYPE bond_type; /* peering bond type */ - - tBTM_SEC_BLE ble; - tBTM_LE_CONN_PRAMS conn_params; + bool role_master; /* true if current mode is master */ + uint16_t security_required; /* Security required for connection */ + bool link_key_not_sent; /* link key notification has not been sent waiting for + name */ + uint8_t link_key_type; /* Type of key used in pairing */ + bool link_key_changed; /* Changed link key during current connection */ + +#define BTM_MAX_PRE_SM4_LKEY_TYPE \ + BTM_LKEY_TYPE_REMOTE_UNIT /* the link key type used by legacy pairing */ + +#define BTM_SM4_UNKNOWN 0x00 +#define BTM_SM4_KNOWN 0x10 +#define BTM_SM4_TRUE 0x11 +#define BTM_SM4_REQ_PEND 0x08 /* set this bit when getting remote features */ +#define BTM_SM4_UPGRADE 0x04 /* set this bit when upgrading link key */ +#define BTM_SM4_RETRY \ + 0x02 /* set this bit to retry on HCI_ERR_KEY_MISSING or \ + HCI_ERR_LMP_ERR_TRANS_COLLISION */ +#define BTM_SM4_DD_ACP \ + 0x20 /* set this bit to indicate peer initiated dedicated bonding */ +#define BTM_SM4_CONN_PEND \ + 0x40 /* set this bit to indicate accepting acl conn; to be cleared on \ + btm_acl_created */ + uint8_t sm4; /* BTM_SM4_TRUE, if the peer supports SM4 */ + tBTM_IO_CAP rmt_io_caps; /* IO capability of the peer device */ + tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */ + bool remote_supports_secure_connections; + bool remote_features_needed; /* set to true if the local device is in */ + /* "Secure Connections Only" mode and it receives */ + /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */ + /* it knows peer's support for Secure Connections */ + + uint16_t ble_hci_handle; /* use in DUMO connection */ + uint8_t enc_key_size; /* current link encryption key size */ + tBT_DEVICE_TYPE device_type; + bool new_encryption_key_is_p256; /* Set to true when the newly generated LK + ** is generated from P-256. + ** Link encrypted with such LK can be used + ** for SM over BR/EDR. + */ + bool no_smp_on_br; /* if set to true then SMP on BR/EDR doesn't */ + /* work, i.e. link keys crosspairing */ + /* SC BR/EDR->SC LE doesn't happen */ + tBTM_BOND_TYPE bond_type; /* peering bond type */ + + tBTM_SEC_BLE ble; + tBTM_LE_CONN_PRAMS conn_params; #if (BTM_DISC_DURING_RS == TRUE) -#define BTM_SEC_RS_NOT_PENDING 0 /* Role Switch not in progress */ -#define BTM_SEC_RS_PENDING 1 /* Role Switch in progress */ -#define BTM_SEC_DISC_PENDING 2 /* Disconnect is pending */ - uint8_t rs_disc_pending; +#define BTM_SEC_RS_NOT_PENDING 0 /* Role Switch not in progress */ +#define BTM_SEC_RS_PENDING 1 /* Role Switch in progress */ +#define BTM_SEC_DISC_PENDING 2 /* Disconnect is pending */ + uint8_t rs_disc_pending; #endif -#define BTM_SEC_NO_LAST_SERVICE_ID 0 - uint8_t last_author_service_id; /* ID of last serviced authorized: Reset after each l2cap connection */ +#define BTM_SEC_NO_LAST_SERVICE_ID 0 + uint8_t last_author_service_id; /* ID of last serviced authorized: Reset after + each l2cap connection */ } tBTM_SEC_DEV_REC; -#define BTM_SEC_IS_SM4(sm) ((bool )(BTM_SM4_TRUE == ((sm)&BTM_SM4_TRUE))) -#define BTM_SEC_IS_SM4_LEGACY(sm) ((bool )(BTM_SM4_KNOWN == ((sm)&BTM_SM4_TRUE))) -#define BTM_SEC_IS_SM4_UNKNOWN(sm) ((bool )(BTM_SM4_UNKNOWN == ((sm)&BTM_SM4_TRUE))) +#define BTM_SEC_IS_SM4(sm) ((bool)(BTM_SM4_TRUE == ((sm)&BTM_SM4_TRUE))) +#define BTM_SEC_IS_SM4_LEGACY(sm) ((bool)(BTM_SM4_KNOWN == ((sm)&BTM_SM4_TRUE))) +#define BTM_SEC_IS_SM4_UNKNOWN(sm) \ + ((bool)(BTM_SM4_UNKNOWN == ((sm)&BTM_SM4_TRUE))) -#define BTM_SEC_LE_MASK (BTM_SEC_LE_AUTHENTICATED|BTM_SEC_LE_ENCRYPTED|BTM_SEC_LE_LINK_KEY_KNOWN|BTM_SEC_LE_LINK_KEY_AUTHED) +#define BTM_SEC_LE_MASK \ + (BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED | \ + BTM_SEC_LE_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_AUTHED) /* * Define device configuration structure */ -typedef struct -{ - tBTM_LOC_BD_NAME bd_name; /* local Bluetooth device name */ - bool pin_type; /* true if PIN type is fixed */ - uint8_t pin_code_len; /* Bonding information */ - PIN_CODE pin_code; /* PIN CODE if pin type is fixed */ - bool connectable; /* If true page scan should be enabled */ - uint8_t def_inq_scan_mode; /* ??? limited/general/none */ +typedef struct { + tBTM_LOC_BD_NAME bd_name; /* local Bluetooth device name */ + bool pin_type; /* true if PIN type is fixed */ + uint8_t pin_code_len; /* Bonding information */ + PIN_CODE pin_code; /* PIN CODE if pin type is fixed */ + bool connectable; /* If true page scan should be enabled */ + uint8_t def_inq_scan_mode; /* ??? limited/general/none */ } tBTM_CFG; -enum -{ - BTM_PM_ST_ACTIVE = BTM_PM_STS_ACTIVE, - BTM_PM_ST_HOLD = BTM_PM_STS_HOLD, - BTM_PM_ST_SNIFF = BTM_PM_STS_SNIFF, - BTM_PM_ST_PARK = BTM_PM_STS_PARK, - BTM_PM_ST_PENDING = BTM_PM_STS_PENDING, - BTM_PM_ST_INVALID = 0xFF +enum { + BTM_PM_ST_ACTIVE = BTM_PM_STS_ACTIVE, + BTM_PM_ST_HOLD = BTM_PM_STS_HOLD, + BTM_PM_ST_SNIFF = BTM_PM_STS_SNIFF, + BTM_PM_ST_PARK = BTM_PM_STS_PARK, + BTM_PM_ST_PENDING = BTM_PM_STS_PENDING, + BTM_PM_ST_INVALID = 0xFF }; typedef uint8_t tBTM_PM_STATE; -enum -{ - BTM_PM_SET_MODE_EVT, /* Set power mode API is called. */ - BTM_PM_UPDATE_EVT, - BTM_PM_RD_MODE_EVT /* Read power mode API is called. */ +enum { + BTM_PM_SET_MODE_EVT, /* Set power mode API is called. */ + BTM_PM_UPDATE_EVT, + BTM_PM_RD_MODE_EVT /* Read power mode API is called. */ }; typedef uint8_t tBTM_PM_EVENT; -typedef struct -{ - uint16_t event; - uint16_t len; - uint8_t link_ind; +typedef struct { + uint16_t event; + uint16_t len; + uint8_t link_ind; } tBTM_PM_MSG_DATA; -typedef struct -{ - uint8_t hci_status; - uint8_t mode; - uint16_t interval; +typedef struct { + uint8_t hci_status; + uint8_t mode; + uint16_t interval; } tBTM_PM_MD_CHG_DATA; -typedef struct -{ - uint8_t pm_id; /* the entity that calls SetPowerMode API */ - tBTM_PM_PWR_MD *p_pmd; +typedef struct { + uint8_t pm_id; /* the entity that calls SetPowerMode API */ + tBTM_PM_PWR_MD* p_pmd; } tBTM_PM_SET_MD_DATA; -typedef struct -{ - void *p_data; - uint8_t link_ind; +typedef struct { + void* p_data; + uint8_t link_ind; } tBTM_PM_SM_DATA; -typedef struct -{ - tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS+1]; /* the desired mode and parameters of the connection*/ - tBTM_PM_PWR_MD set_mode; /* the mode and parameters sent down to the host controller. */ - uint16_t interval; /* the interval from last mode change event. */ +typedef struct { + tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1]; /* the desired mode and + parameters of the + connection*/ + tBTM_PM_PWR_MD + set_mode; /* the mode and parameters sent down to the host controller. */ + uint16_t interval; /* the interval from last mode change event. */ #if (BTM_SSR_INCLUDED == TRUE) - uint16_t max_lat; /* stored SSR maximum latency */ - uint16_t min_rmt_to;/* stored SSR minimum remote timeout */ - uint16_t min_loc_to;/* stored SSR minimum local timeout */ + uint16_t max_lat; /* stored SSR maximum latency */ + uint16_t min_rmt_to; /* stored SSR minimum remote timeout */ + uint16_t min_loc_to; /* stored SSR minimum local timeout */ #endif - tBTM_PM_STATE state; /* contains the current mode of the connection */ - bool chg_ind; /* a request change indication */ + tBTM_PM_STATE state; /* contains the current mode of the connection */ + bool chg_ind; /* a request change indication */ } tBTM_PM_MCB; #define BTM_PM_REC_NOT_USED 0 -typedef struct -{ - tBTM_PM_STATUS_CBACK *cback;/* to notify the registered party of mode change event */ - uint8_t mask; /* registered request mask. 0, if this entry is not used */ +typedef struct { + tBTM_PM_STATUS_CBACK* + cback; /* to notify the registered party of mode change event */ + uint8_t mask; /* registered request mask. 0, if this entry is not used */ } tBTM_PM_RCB; -enum -{ - BTM_BLI_ACL_UP_EVT, - BTM_BLI_ACL_DOWN_EVT, - BTM_BLI_PAGE_EVT, - BTM_BLI_PAGE_DONE_EVT, - BTM_BLI_INQ_EVT, - BTM_BLI_INQ_CANCEL_EVT, - BTM_BLI_INQ_DONE_EVT +enum { + BTM_BLI_ACL_UP_EVT, + BTM_BLI_ACL_DOWN_EVT, + BTM_BLI_PAGE_EVT, + BTM_BLI_PAGE_DONE_EVT, + BTM_BLI_INQ_EVT, + BTM_BLI_INQ_CANCEL_EVT, + BTM_BLI_INQ_DONE_EVT }; typedef uint8_t tBTM_BLI_EVENT; /* Pairing State */ -enum -{ - BTM_PAIR_STATE_IDLE, /* Idle */ - BTM_PAIR_STATE_GET_REM_NAME, /* Getting the remote name (to check for SM4) */ - BTM_PAIR_STATE_WAIT_PIN_REQ, /* Started authentication, waiting for PIN req (PIN is pre-fetched) */ - BTM_PAIR_STATE_WAIT_LOCAL_PIN, /* Waiting for local PIN code */ - BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM, /* Waiting user 'yes' to numeric confirmation */ - BTM_PAIR_STATE_KEY_ENTRY, /* Key entry state (we are a keyboard) */ - BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP, /* Waiting for local response to peer OOB data */ - BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS, /* Waiting for local IO capabilities and OOB data */ - BTM_PAIR_STATE_INCOMING_SSP, /* Incoming SSP (got peer IO caps when idle) */ - BTM_PAIR_STATE_WAIT_AUTH_COMPLETE, /* All done, waiting authentication cpmplete */ - BTM_PAIR_STATE_WAIT_DISCONNECT /* Waiting to disconnect the ACL */ +enum { + BTM_PAIR_STATE_IDLE, /* Idle */ + BTM_PAIR_STATE_GET_REM_NAME, /* Getting the remote name (to check for SM4) */ + BTM_PAIR_STATE_WAIT_PIN_REQ, /* Started authentication, waiting for PIN req + (PIN is pre-fetched) */ + BTM_PAIR_STATE_WAIT_LOCAL_PIN, /* Waiting for local PIN code */ + BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM, /* Waiting user 'yes' to numeric + confirmation */ + BTM_PAIR_STATE_KEY_ENTRY, /* Key entry state (we are a keyboard) */ + BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP, /* Waiting for local response to peer OOB + data */ + BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS, /* Waiting for local IO capabilities and OOB + data */ + BTM_PAIR_STATE_INCOMING_SSP, /* Incoming SSP (got peer IO caps when idle) */ + BTM_PAIR_STATE_WAIT_AUTH_COMPLETE, /* All done, waiting authentication + cpmplete */ + BTM_PAIR_STATE_WAIT_DISCONNECT /* Waiting to disconnect the ACL */ }; typedef uint8_t tBTM_PAIRING_STATE; -#define BTM_PAIR_FLAGS_WE_STARTED_DD 0x01 /* We want to do dedicated bonding */ -#define BTM_PAIR_FLAGS_PEER_STARTED_DD 0x02 /* Peer initiated dedicated bonding */ -#define BTM_PAIR_FLAGS_DISC_WHEN_DONE 0x04 /* Disconnect when done */ -#define BTM_PAIR_FLAGS_PIN_REQD 0x08 /* set this bit when pin_callback is called */ -#define BTM_PAIR_FLAGS_PRE_FETCH_PIN 0x10 /* set this bit when pre-fetch pin */ -#define BTM_PAIR_FLAGS_REJECTED_CONNECT 0x20 /* set this bit when rejected incoming connection */ -#define BTM_PAIR_FLAGS_WE_CANCEL_DD 0x40 /* set this bit when cancelling a bonding procedure */ -#define BTM_PAIR_FLAGS_LE_ACTIVE 0x80 /* use this bit when SMP pairing is active */ - - -typedef struct -{ - bool is_mux; - BD_ADDR bd_addr; - uint16_t psm; - bool is_orig; - tBTM_SEC_CALLBACK *p_callback; - void *p_ref_data; - uint32_t mx_proto_id; - uint32_t mx_chan_id; - tBT_TRANSPORT transport; - tBTM_BLE_SEC_ACT sec_act; +#define BTM_PAIR_FLAGS_WE_STARTED_DD \ + 0x01 /* We want to do dedicated bonding */ +#define BTM_PAIR_FLAGS_PEER_STARTED_DD \ + 0x02 /* Peer initiated dedicated bonding */ +#define BTM_PAIR_FLAGS_DISC_WHEN_DONE 0x04 /* Disconnect when done */ +#define BTM_PAIR_FLAGS_PIN_REQD \ + 0x08 /* set this bit when pin_callback is called */ +#define BTM_PAIR_FLAGS_PRE_FETCH_PIN \ + 0x10 /* set this bit when pre-fetch pin */ +#define BTM_PAIR_FLAGS_REJECTED_CONNECT \ + 0x20 /* set this bit when rejected incoming connection */ +#define BTM_PAIR_FLAGS_WE_CANCEL_DD \ + 0x40 /* set this bit when cancelling a bonding procedure */ +#define BTM_PAIR_FLAGS_LE_ACTIVE \ + 0x80 /* use this bit when SMP pairing is active */ + +typedef struct { + bool is_mux; + BD_ADDR bd_addr; + uint16_t psm; + bool is_orig; + tBTM_SEC_CALLBACK* p_callback; + void* p_ref_data; + uint32_t mx_proto_id; + uint32_t mx_chan_id; + tBT_TRANSPORT transport; + tBTM_BLE_SEC_ACT sec_act; } tBTM_SEC_QUEUE_ENTRY; #if (L2CAP_UCD_INCLUDED == TRUE) -#define CONN_ORIENT_TERM 0x00 /* incoming connection oriented */ -#define CONN_ORIENT_ORIG 0x01 /* outgoing connection oriented */ -#define CONNLESS_TERM 0x02 /* incoming connectionless */ -#define CONNLESS_ORIG 0x03 /* outgoing connectionless */ -#define CONNECTION_TYPE_ORIG_MASK 0x01 /* mask for direction */ -#define CONNECTION_TYPE_CONNLESS_MASK 0x02 /* mask for connectionless or not */ +#define CONN_ORIENT_TERM 0x00 /* incoming connection oriented */ +#define CONN_ORIENT_ORIG 0x01 /* outgoing connection oriented */ +#define CONNLESS_TERM 0x02 /* incoming connectionless */ +#define CONNLESS_ORIG 0x03 /* outgoing connectionless */ +#define CONNECTION_TYPE_ORIG_MASK 0x01 /* mask for direction */ +#define CONNECTION_TYPE_CONNLESS_MASK \ + 0x02 /* mask for connectionless or not \ + */ typedef uint8_t CONNECTION_TYPE; #else -#define CONN_ORIENT_TERM false -#define CONN_ORIENT_ORIG true -typedef bool CONNECTION_TYPE; +#define CONN_ORIENT_TERM false +#define CONN_ORIENT_ORIG true +typedef bool CONNECTION_TYPE; #endif /* (L2CAP_UCD_INCLUDED == TRUE) */ /* Define a structure to hold all the BTM data */ -#define BTM_STATE_BUFFER_SIZE 5 /* size of state buffer */ - -typedef struct -{ - tBTM_CFG cfg; /* Device configuration */ - - /**************************************************** - ** ACL Management - ****************************************************/ - tACL_CONN acl_db[MAX_L2CAP_LINKS]; - uint8_t btm_scn[BTM_MAX_SCN]; /* current SCNs: true if SCN is in use */ - uint16_t btm_def_link_policy; - uint16_t btm_def_link_super_tout; - - tBTM_BL_EVENT_MASK bl_evt_mask; - tBTM_BL_CHANGE_CB *p_bl_changed_cb; /* Callback for when Busy Level changed */ - - /**************************************************** - ** Power Management - ****************************************************/ - tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS]; /* per ACL link */ - tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS+1]; /* per application/module */ - uint8_t pm_pend_link; /* the index of acl_db, which has a pending PM cmd */ - uint8_t pm_pend_id; /* the id pf the module, which has a pending PM cmd */ - - /***************************************************** - ** Device control - *****************************************************/ - tBTM_DEVCB devcb; - - /***************************************************** - ** BLE Device controllers - *****************************************************/ - tBTM_BLE_CB ble_ctr_cb; - - uint16_t enc_handle; - BT_OCTET8 enc_rand; /* received rand value from LTK request*/ - uint16_t ediv; /* received ediv value from LTK request */ - uint8_t key_size; - tBTM_BLE_VSC_CB cmn_ble_vsc_cb; - - /* Packet types supported by the local device */ - uint16_t btm_acl_pkt_types_supported; - uint16_t btm_sco_pkt_types_supported; - - - /***************************************************** - ** Inquiry - *****************************************************/ - tBTM_INQUIRY_VAR_ST btm_inq_vars; - - /***************************************************** - ** SCO Management - *****************************************************/ +#define BTM_STATE_BUFFER_SIZE 5 /* size of state buffer */ + +typedef struct { + tBTM_CFG cfg; /* Device configuration */ + + /**************************************************** + ** ACL Management + ****************************************************/ + tACL_CONN acl_db[MAX_L2CAP_LINKS]; + uint8_t btm_scn[BTM_MAX_SCN]; /* current SCNs: true if SCN is in use */ + uint16_t btm_def_link_policy; + uint16_t btm_def_link_super_tout; + + tBTM_BL_EVENT_MASK bl_evt_mask; + tBTM_BL_CHANGE_CB* p_bl_changed_cb; /* Callback for when Busy Level changed */ + + /**************************************************** + ** Power Management + ****************************************************/ + tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS]; /* per ACL link */ + tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */ + uint8_t pm_pend_link; /* the index of acl_db, which has a pending PM cmd */ + uint8_t pm_pend_id; /* the id pf the module, which has a pending PM cmd */ + + /***************************************************** + ** Device control + *****************************************************/ + tBTM_DEVCB devcb; + + /***************************************************** + ** BLE Device controllers + *****************************************************/ + tBTM_BLE_CB ble_ctr_cb; + + uint16_t enc_handle; + BT_OCTET8 enc_rand; /* received rand value from LTK request*/ + uint16_t ediv; /* received ediv value from LTK request */ + uint8_t key_size; + tBTM_BLE_VSC_CB cmn_ble_vsc_cb; + + /* Packet types supported by the local device */ + uint16_t btm_acl_pkt_types_supported; + uint16_t btm_sco_pkt_types_supported; + + /***************************************************** + ** Inquiry + *****************************************************/ + tBTM_INQUIRY_VAR_ST btm_inq_vars; + +/***************************************************** +** SCO Management +*****************************************************/ #if (BTM_SCO_INCLUDED == TRUE) - tSCO_CB sco_cb; + tSCO_CB sco_cb; #endif - /***************************************************** - ** Security Management - *****************************************************/ - tBTM_APPL_INFO api; - -#define BTM_SEC_MAX_RMT_NAME_CALLBACKS 2 - tBTM_RMT_NAME_CALLBACK *p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS]; - - tBTM_SEC_DEV_REC *p_collided_dev_rec; - alarm_t *sec_collision_timer; - uint32_t collision_start_time; - uint32_t max_collision_delay; - uint32_t dev_rec_count; /* Counter used for device record timestamp */ - uint8_t security_mode; - bool pairing_disabled; - bool connect_only_paired; - bool security_mode_changed; /* mode changed during bonding */ - bool pin_type_changed; /* pin type changed during bonding */ - bool sec_req_pending; /* true if a request is pending */ - - uint8_t pin_code_len; /* for legacy devices */ - PIN_CODE pin_code; /* for legacy devices */ - tBTM_PAIRING_STATE pairing_state; /* The current pairing state */ - uint8_t pairing_flags; /* The current pairing flags */ - BD_ADDR pairing_bda; /* The device currently pairing */ - alarm_t *pairing_timer; /* Timer for pairing process */ - uint16_t disc_handle; /* for legacy devices */ - uint8_t disc_reason; /* for legacy devices */ - tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS]; - list_t *sec_dev_rec; /* list of tBTM_SEC_DEV_REC */ - tBTM_SEC_SERV_REC *p_out_serv; - tBTM_MKEY_CALLBACK *mkey_cback; - - BD_ADDR connecting_bda; - DEV_CLASS connecting_dc; - - uint8_t acl_disc_reason; - uint8_t trace_level; - uint8_t busy_level; /* the current busy level */ - bool is_paging; /* true, if paging is in progess */ - bool is_inquiry; /* true, if inquiry is in progess */ - fixed_queue_t *page_queue; - bool paging; - bool discing; - fixed_queue_t *sec_pending_q; /* pending sequrity requests in tBTM_SEC_QUEUE_ENTRY format */ - - char state_temp_buffer[BTM_STATE_BUFFER_SIZE]; + /***************************************************** + ** Security Management + *****************************************************/ + tBTM_APPL_INFO api; + +#define BTM_SEC_MAX_RMT_NAME_CALLBACKS 2 + tBTM_RMT_NAME_CALLBACK* p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS]; + + tBTM_SEC_DEV_REC* p_collided_dev_rec; + alarm_t* sec_collision_timer; + uint32_t collision_start_time; + uint32_t max_collision_delay; + uint32_t dev_rec_count; /* Counter used for device record timestamp */ + uint8_t security_mode; + bool pairing_disabled; + bool connect_only_paired; + bool security_mode_changed; /* mode changed during bonding */ + bool pin_type_changed; /* pin type changed during bonding */ + bool sec_req_pending; /* true if a request is pending */ + + uint8_t pin_code_len; /* for legacy devices */ + PIN_CODE pin_code; /* for legacy devices */ + tBTM_PAIRING_STATE pairing_state; /* The current pairing state */ + uint8_t pairing_flags; /* The current pairing flags */ + BD_ADDR pairing_bda; /* The device currently pairing */ + alarm_t* pairing_timer; /* Timer for pairing process */ + uint16_t disc_handle; /* for legacy devices */ + uint8_t disc_reason; /* for legacy devices */ + tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS]; + list_t* sec_dev_rec; /* list of tBTM_SEC_DEV_REC */ + tBTM_SEC_SERV_REC* p_out_serv; + tBTM_MKEY_CALLBACK* mkey_cback; + + BD_ADDR connecting_bda; + DEV_CLASS connecting_dc; + + uint8_t acl_disc_reason; + uint8_t trace_level; + uint8_t busy_level; /* the current busy level */ + bool is_paging; /* true, if paging is in progess */ + bool is_inquiry; /* true, if inquiry is in progess */ + fixed_queue_t* page_queue; + bool paging; + bool discing; + fixed_queue_t* sec_pending_q; /* pending sequrity requests in + tBTM_SEC_QUEUE_ENTRY format */ + + char state_temp_buffer[BTM_STATE_BUFFER_SIZE]; } tBTM_CB; /* security action for L2CAP COC channels */ -#define BTM_SEC_OK 1 -#define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */ -#define BTM_SEC_ENCRYPT_NO_MITM 3 /* unauthenticated encryption or better */ -#define BTM_SEC_ENCRYPT_MITM 4 /* authenticated encryption */ -#define BTM_SEC_ENC_PENDING 5 /* wait for link encryption pending */ +#define BTM_SEC_OK 1 +#define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */ +#define BTM_SEC_ENCRYPT_NO_MITM 3 /* unauthenticated encryption or better */ +#define BTM_SEC_ENCRYPT_MITM 4 /* authenticated encryption */ +#define BTM_SEC_ENC_PENDING 5 /* wait for link encryption pending */ typedef uint8_t tBTM_SEC_ACTION; @@ -863,4 +887,4 @@ typedef uint8_t tBTM_SEC_ACTION; } #endif -#endif // BTM_INT_TYPES_H +#endif // BTM_INT_TYPES_H diff --git a/stack/btm/btm_main.cc b/stack/btm/btm_main.cc index ed3b4a988..70f3ee4ef 100644 --- a/stack/btm/btm_main.cc +++ b/stack/btm/btm_main.cc @@ -22,15 +22,15 @@ * ******************************************************************************/ -#include "bt_types.h" -#include "bt_target.h" #include +#include "bt_target.h" +#include "bt_types.h" #include "btm_int.h" #include "stack_config.h" /* Global BTM control block structure */ -tBTM_CB btm_cb; +tBTM_CB btm_cb; /******************************************************************************* * @@ -44,35 +44,33 @@ tBTM_CB btm_cb; * Returns void * ******************************************************************************/ -void btm_init (void) -{ - /* All fields are cleared; nonzero fields are reinitialized in appropriate function */ - memset(&btm_cb, 0, sizeof(tBTM_CB)); - btm_cb.page_queue = fixed_queue_new(SIZE_MAX); - btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX); - btm_cb.sec_collision_timer = alarm_new("btm.sec_collision_timer"); - btm_cb.pairing_timer = alarm_new("btm.pairing_timer"); +void btm_init(void) { + /* All fields are cleared; nonzero fields are reinitialized in appropriate + * function */ + memset(&btm_cb, 0, sizeof(tBTM_CB)); + btm_cb.page_queue = fixed_queue_new(SIZE_MAX); + btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX); + btm_cb.sec_collision_timer = alarm_new("btm.sec_collision_timer"); + btm_cb.pairing_timer = alarm_new("btm.pairing_timer"); #if defined(BTM_INITIAL_TRACE_LEVEL) - btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL; + btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL; #else - btm_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + btm_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif - /* Initialize BTM component structures */ - btm_inq_db_init(); /* Inquiry Database and Structures */ - btm_acl_init(); /* ACL Database and Structures */ - /* Security Manager Database and Structures */ - if (stack_config_get_interface()->get_pts_secure_only_mode()) - btm_sec_init(BTM_SEC_MODE_SC); - else - btm_sec_init(BTM_SEC_MODE_SP); + /* Initialize BTM component structures */ + btm_inq_db_init(); /* Inquiry Database and Structures */ + btm_acl_init(); /* ACL Database and Structures */ + /* Security Manager Database and Structures */ + if (stack_config_get_interface()->get_pts_secure_only_mode()) + btm_sec_init(BTM_SEC_MODE_SC); + else + btm_sec_init(BTM_SEC_MODE_SP); #if (BTM_SCO_INCLUDED == TRUE) - btm_sco_init(); /* SCO Database and Structures (If included) */ + btm_sco_init(); /* SCO Database and Structures (If included) */ #endif - btm_cb.sec_dev_rec = list_new(osi_free); + btm_cb.sec_dev_rec = list_new(osi_free); - btm_dev_init(); /* Device Manager Structures & HCI_Reset */ + btm_dev_init(); /* Device Manager Structures & HCI_Reset */ } - - diff --git a/stack/btm/btm_pm.cc b/stack/btm/btm_pm.cc index a275d2d11..bc47166ab 100644 --- a/stack/btm/btm_pm.cc +++ b/stack/btm/btm_pm.cc @@ -35,12 +35,12 @@ #include #include +#include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" #include "btu.h" -#include "bt_common.h" #include "hcidefs.h" #include "hcimsgs.h" #include "l2c_int.h" @@ -50,38 +50,32 @@ /*****************************************************************************/ /* to handle different modes */ /*****************************************************************************/ -#define BTM_PM_STORED_MASK 0x80 /* set this mask if the command is stored */ -#define BTM_PM_NUM_SET_MODES 3 /* only hold, sniff & park */ +#define BTM_PM_STORED_MASK 0x80 /* set this mask if the command is stored */ +#define BTM_PM_NUM_SET_MODES 3 /* only hold, sniff & park */ /* Usage: (ptr_features[ offset ] & mask )?true:false */ /* offset to supported feature */ -const uint8_t btm_pm_mode_off[BTM_PM_NUM_SET_MODES] = {0, 0, 1}; +const uint8_t btm_pm_mode_off[BTM_PM_NUM_SET_MODES] = {0, 0, 1}; /* mask to supported feature */ const uint8_t btm_pm_mode_msk[BTM_PM_NUM_SET_MODES] = {0x40, 0x80, 0x01}; -#define BTM_PM_GET_MD1 1 -#define BTM_PM_GET_MD2 2 -#define BTM_PM_GET_COMP 3 +#define BTM_PM_GET_MD1 1 +#define BTM_PM_GET_MD2 2 +#define BTM_PM_GET_COMP 3 -const uint8_t btm_pm_md_comp_matrix[BTM_PM_NUM_SET_MODES*BTM_PM_NUM_SET_MODES] = -{ - BTM_PM_GET_COMP, - BTM_PM_GET_MD2, - BTM_PM_GET_MD2, +const uint8_t + btm_pm_md_comp_matrix[BTM_PM_NUM_SET_MODES * BTM_PM_NUM_SET_MODES] = { + BTM_PM_GET_COMP, BTM_PM_GET_MD2, BTM_PM_GET_MD2, - BTM_PM_GET_MD1, - BTM_PM_GET_COMP, - BTM_PM_GET_MD1, + BTM_PM_GET_MD1, BTM_PM_GET_COMP, BTM_PM_GET_MD1, - BTM_PM_GET_MD1, - BTM_PM_GET_MD2, - BTM_PM_GET_COMP -}; + BTM_PM_GET_MD1, BTM_PM_GET_MD2, BTM_PM_GET_COMP}; /* function prototype */ static int btm_pm_find_acl_ind(BD_ADDR remote_bda); -static tBTM_STATUS btm_pm_snd_md_req( uint8_t pm_id, int link_ind, tBTM_PM_PWR_MD *p_mode ); -static const char *mode_to_string(tBTM_PM_MODE mode); +static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind, + tBTM_PM_PWR_MD* p_mode); +static const char* mode_to_string(tBTM_PM_MODE mode); /* #ifdef BTM_PM_DEBUG @@ -91,31 +85,16 @@ static const char *mode_to_string(tBTM_PM_MODE mode); */ #if (BTM_PM_DEBUG == TRUE) -const char * btm_pm_state_str[] = -{ - "pm_active_state", - "pm_hold_state", - "pm_sniff_state", - "pm_park_state", - "pm_pend_state" -}; - -const char * btm_pm_event_str[] = -{ - "pm_set_mode_event", - "pm_hci_sts_event", - "pm_mod_chg_event", - "pm_update_event" -}; - -const char * btm_pm_action_str[] = -{ - "pm_set_mode_action", - "pm_update_db_action", - "pm_mod_chg_action", - "pm_hci_sts_action", - "pm_update_action" -}; +const char* btm_pm_state_str[] = {"pm_active_state", "pm_hold_state", + "pm_sniff_state", "pm_park_state", + "pm_pend_state"}; + +const char* btm_pm_event_str[] = {"pm_set_mode_event", "pm_hci_sts_event", + "pm_mod_chg_event", "pm_update_event"}; + +const char* btm_pm_action_str[] = {"pm_set_mode_action", "pm_update_db_action", + "pm_mod_chg_action", "pm_hci_sts_action", + "pm_update_action"}; #endif // BTM_PM_DEBUG /*****************************************************************************/ @@ -132,38 +111,32 @@ const char * btm_pm_action_str[] = * BTM_ILLEGAL_VALUE * ******************************************************************************/ -tBTM_STATUS BTM_PmRegister (uint8_t mask, uint8_t *p_pm_id, tBTM_PM_STATUS_CBACK *p_cb) -{ - int xx; - - /* de-register */ - if(mask & BTM_PM_DEREG) - { - if(*p_pm_id >= BTM_MAX_PM_RECORDS) - return BTM_ILLEGAL_VALUE; - btm_cb.pm_reg_db[*p_pm_id].mask = BTM_PM_REC_NOT_USED; - return BTM_SUCCESS; - } +tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id, + tBTM_PM_STATUS_CBACK* p_cb) { + int xx; + + /* de-register */ + if (mask & BTM_PM_DEREG) { + if (*p_pm_id >= BTM_MAX_PM_RECORDS) return BTM_ILLEGAL_VALUE; + btm_cb.pm_reg_db[*p_pm_id].mask = BTM_PM_REC_NOT_USED; + return BTM_SUCCESS; + } - for(xx=0; xx= BTM_MAX_PM_RECORDS) - pm_id = BTM_PM_SET_ONLY_ID; - - if(p_mode == NULL) - return BTM_ILLEGAL_VALUE; - - BTM_TRACE_API( "BTM_SetPowerMode: pm_id %d BDA: %08x mode:0x%x", pm_id, - (remote_bda[2]<<24)+(remote_bda[3]<<16)+(remote_bda[4]<<8)+remote_bda[5], p_mode->mode); - - /* take out the force bit */ - mode = p_mode->mode & ~BTM_PM_MD_FORCE; - - acl_ind = btm_pm_find_acl_ind(remote_bda); - if(acl_ind == MAX_L2CAP_LINKS) - return (BTM_UNKNOWN_ADDR); - - p_cb = &(btm_cb.pm_mode_db[acl_ind]); - - if(mode != BTM_PM_MD_ACTIVE) - { - /* check if the requested mode is supported */ - ind = mode - BTM_PM_MD_HOLD; /* make it base 0 */ - p_features = BTM_ReadLocalFeatures(); - if( !(p_features[ btm_pm_mode_off[ind] ] & btm_pm_mode_msk[ind] ) ) - return BTM_MODE_UNSUPPORTED; - } +tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, BD_ADDR remote_bda, + tBTM_PM_PWR_MD* p_mode) { + uint8_t* p_features; + int ind, acl_ind; + tBTM_PM_MCB* p_cb = NULL; /* per ACL link */ + tBTM_PM_MODE mode; + int temp_pm_id; + + if (pm_id >= BTM_MAX_PM_RECORDS) pm_id = BTM_PM_SET_ONLY_ID; + + if (p_mode == NULL) return BTM_ILLEGAL_VALUE; + + BTM_TRACE_API("BTM_SetPowerMode: pm_id %d BDA: %08x mode:0x%x", pm_id, + (remote_bda[2] << 24) + (remote_bda[3] << 16) + + (remote_bda[4] << 8) + remote_bda[5], + p_mode->mode); + + /* take out the force bit */ + mode = p_mode->mode & ~BTM_PM_MD_FORCE; - if(mode == p_cb->state) /* the requested mode is current mode */ - { - /* already in the requested mode and the current interval has less latency than the max */ - if( (mode == BTM_PM_MD_ACTIVE) || - ((p_mode->mode & BTM_PM_MD_FORCE) && (p_mode->max >= p_cb->interval) && (p_mode->min <= p_cb->interval)) || - ((p_mode->mode & BTM_PM_MD_FORCE)==0 && (p_mode->max >= p_cb->interval)) ) - { - BTM_TRACE_DEBUG( "BTM_SetPowerMode: mode:0x%x interval %d max:%d, min:%d", p_mode->mode, p_cb->interval, p_mode->max, p_mode->min); - return BTM_SUCCESS; - } + acl_ind = btm_pm_find_acl_ind(remote_bda); + if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); + + p_cb = &(btm_cb.pm_mode_db[acl_ind]); + + if (mode != BTM_PM_MD_ACTIVE) { + /* check if the requested mode is supported */ + ind = mode - BTM_PM_MD_HOLD; /* make it base 0 */ + p_features = BTM_ReadLocalFeatures(); + if (!(p_features[btm_pm_mode_off[ind]] & btm_pm_mode_msk[ind])) + return BTM_MODE_UNSUPPORTED; + } + + if (mode == p_cb->state) /* the requested mode is current mode */ + { + /* already in the requested mode and the current interval has less latency + * than the max */ + if ((mode == BTM_PM_MD_ACTIVE) || + ((p_mode->mode & BTM_PM_MD_FORCE) && (p_mode->max >= p_cb->interval) && + (p_mode->min <= p_cb->interval)) || + ((p_mode->mode & BTM_PM_MD_FORCE) == 0 && + (p_mode->max >= p_cb->interval))) { + BTM_TRACE_DEBUG("BTM_SetPowerMode: mode:0x%x interval %d max:%d, min:%d", + p_mode->mode, p_cb->interval, p_mode->max, p_mode->min); + return BTM_SUCCESS; } + } - temp_pm_id = pm_id; - if(pm_id == BTM_PM_SET_ONLY_ID) - temp_pm_id = BTM_MAX_PM_RECORDS; + temp_pm_id = pm_id; + if (pm_id == BTM_PM_SET_ONLY_ID) temp_pm_id = BTM_MAX_PM_RECORDS; - /* update mode database */ - if( ((pm_id != BTM_PM_SET_ONLY_ID) && - (btm_cb.pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) - || ((pm_id == BTM_PM_SET_ONLY_ID) && (btm_cb.pm_pend_link != MAX_L2CAP_LINKS)) ) - { + /* update mode database */ + if (((pm_id != BTM_PM_SET_ONLY_ID) && + (btm_cb.pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) || + ((pm_id == BTM_PM_SET_ONLY_ID) && + (btm_cb.pm_pend_link != MAX_L2CAP_LINKS))) { #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "BTM_SetPowerMode: Saving cmd acl_ind %d temp_pm_id %d", acl_ind,temp_pm_id); + BTM_TRACE_DEBUG("BTM_SetPowerMode: Saving cmd acl_ind %d temp_pm_id %d", + acl_ind, temp_pm_id); #endif // BTM_PM_DEBUG - /* Make sure mask is set to BTM_PM_REG_SET */ - btm_cb.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET; - *(&p_cb->req_mode[temp_pm_id]) = *((tBTM_PM_PWR_MD *)p_mode); - p_cb->chg_ind = true; - } + /* Make sure mask is set to BTM_PM_REG_SET */ + btm_cb.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET; + *(&p_cb->req_mode[temp_pm_id]) = *((tBTM_PM_PWR_MD*)p_mode); + p_cb->chg_ind = true; + } #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm state:0x%x, pm_pend_link: %d", p_cb->state, btm_cb.pm_pend_link); + BTM_TRACE_DEBUG("btm_pm state:0x%x, pm_pend_link: %d", p_cb->state, + btm_cb.pm_pend_link); #endif // BTM_PM_DEBUG - /* if mode == hold or pending, return */ - if( (p_cb->state == BTM_PM_STS_HOLD) || - (p_cb->state == BTM_PM_STS_PENDING) || - (btm_cb.pm_pend_link != MAX_L2CAP_LINKS) ) /* command pending */ - { - if(acl_ind != btm_cb.pm_pend_link) - { - /* set the stored mask */ - p_cb->state |= BTM_PM_STORED_MASK; - BTM_TRACE_DEBUG( "btm_pm state stored:%d",acl_ind); - } - return BTM_CMD_STORED; + /* if mode == hold or pending, return */ + if ((p_cb->state == BTM_PM_STS_HOLD) || (p_cb->state == BTM_PM_STS_PENDING) || + (btm_cb.pm_pend_link != MAX_L2CAP_LINKS)) /* command pending */ + { + if (acl_ind != btm_cb.pm_pend_link) { + /* set the stored mask */ + p_cb->state |= BTM_PM_STORED_MASK; + BTM_TRACE_DEBUG("btm_pm state stored:%d", acl_ind); } + return BTM_CMD_STORED; + } - return btm_pm_snd_md_req(pm_id, acl_ind, p_mode); + return btm_pm_snd_md_req(pm_id, acl_ind, p_mode); } /******************************************************************************* @@ -282,16 +255,14 @@ tBTM_STATUS BTM_SetPowerMode (uint8_t pm_id, BD_ADDR remote_bda, tBTM_PM_PWR_MD * BTM_UNKNOWN_ADDR if bd addr is not active or bad * ******************************************************************************/ -tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, tBTM_PM_MODE *p_mode) -{ - int acl_ind; +tBTM_STATUS BTM_ReadPowerMode(BD_ADDR remote_bda, tBTM_PM_MODE* p_mode) { + int acl_ind; - acl_ind = btm_pm_find_acl_ind(remote_bda); - if(acl_ind == MAX_L2CAP_LINKS) - return (BTM_UNKNOWN_ADDR); + acl_ind = btm_pm_find_acl_ind(remote_bda); + if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); - *p_mode = btm_cb.pm_mode_db[acl_ind].state; - return BTM_SUCCESS; + *p_mode = btm_cb.pm_mode_db[acl_ind].state; + return BTM_SUCCESS; } /******************************************************************************* @@ -315,15 +286,14 @@ tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, tBTM_PM_MODE *p_mode) * BTM_UNKNOWN_ADDR if bd addr is not active or bad * ******************************************************************************/ -tBTM_STATUS btm_read_power_mode_state (BD_ADDR remote_bda, tBTM_PM_STATE *pmState) -{ - int acl_ind = btm_pm_find_acl_ind(remote_bda); +tBTM_STATUS btm_read_power_mode_state(BD_ADDR remote_bda, + tBTM_PM_STATE* pmState) { + int acl_ind = btm_pm_find_acl_ind(remote_bda); - if( acl_ind == MAX_L2CAP_LINKS) - return (BTM_UNKNOWN_ADDR); + if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); - *pmState = btm_cb.pm_mode_db[acl_ind].state; - return BTM_SUCCESS; + *pmState = btm_cb.pm_mode_db[acl_ind].state; + return BTM_SUCCESS; } /******************************************************************************* @@ -344,31 +314,28 @@ tBTM_STATUS btm_read_power_mode_state (BD_ADDR remote_bda, tBTM_PM_STATE *pmStat * BTM_CMD_STORED if the command is stored * ******************************************************************************/ -tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, uint16_t max_lat, - uint16_t min_rmt_to, uint16_t min_loc_to) -{ +tBTM_STATUS BTM_SetSsrParams(BD_ADDR remote_bda, uint16_t max_lat, + uint16_t min_rmt_to, uint16_t min_loc_to) { #if (BTM_SSR_INCLUDED == TRUE) - int acl_ind; - tBTM_PM_MCB *p_cb; - - acl_ind = btm_pm_find_acl_ind(remote_bda); - if(acl_ind == MAX_L2CAP_LINKS) - return (BTM_UNKNOWN_ADDR); - - if(BTM_PM_STS_ACTIVE == btm_cb.pm_mode_db[acl_ind].state || - BTM_PM_STS_SNIFF == btm_cb.pm_mode_db[acl_ind].state) - { - btsnd_hcic_sniff_sub_rate(btm_cb.acl_db[acl_ind].hci_handle, max_lat, - min_rmt_to, min_loc_to); - return BTM_SUCCESS; - } - p_cb = &btm_cb.pm_mode_db[acl_ind]; - p_cb->max_lat = max_lat; - p_cb->min_rmt_to = min_rmt_to; - p_cb->min_loc_to = min_loc_to; - return BTM_CMD_STORED; + int acl_ind; + tBTM_PM_MCB* p_cb; + + acl_ind = btm_pm_find_acl_ind(remote_bda); + if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); + + if (BTM_PM_STS_ACTIVE == btm_cb.pm_mode_db[acl_ind].state || + BTM_PM_STS_SNIFF == btm_cb.pm_mode_db[acl_ind].state) { + btsnd_hcic_sniff_sub_rate(btm_cb.acl_db[acl_ind].hci_handle, max_lat, + min_rmt_to, min_loc_to); + return BTM_SUCCESS; + } + p_cb = &btm_cb.pm_mode_db[acl_ind]; + p_cb->max_lat = max_lat; + p_cb->min_rmt_to = min_rmt_to; + p_cb->min_loc_to = min_loc_to; + return BTM_CMD_STORED; #else - return BTM_ILLEGAL_ACTION; + return BTM_ILLEGAL_ACTION; #endif // BTM_SSR_INCLUDED } @@ -381,29 +348,27 @@ tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, uint16_t max_lat, * Returns void * ******************************************************************************/ -void btm_pm_reset(void) -{ - int xx; - tBTM_PM_STATUS_CBACK *cb = NULL; - - /* clear the pending request for application */ - if( (btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) && - (btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF) ) - { - cb = btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback; - } +void btm_pm_reset(void) { + int xx; + tBTM_PM_STATUS_CBACK* cb = NULL; + + /* clear the pending request for application */ + if ((btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) && + (btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF)) { + cb = btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback; + } - /* clear the register record */ - for(xx=0; xxstate = BTM_PM_ST_ACTIVE; +void btm_pm_sm_alloc(uint8_t ind) { + tBTM_PM_MCB* p_db = &btm_cb.pm_mode_db[ind]; /* per ACL link */ + memset(p_db, 0, sizeof(tBTM_PM_MCB)); + p_db->state = BTM_PM_ST_ACTIVE; #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_sm_alloc ind:%d st:%d", ind, p_db->state); + BTM_TRACE_DEBUG("btm_pm_sm_alloc ind:%d st:%d", ind, p_db->state); #endif // BTM_PM_DEBUG } @@ -436,23 +400,21 @@ void btm_pm_sm_alloc(uint8_t ind) * Returns void * ******************************************************************************/ -static int btm_pm_find_acl_ind(BD_ADDR remote_bda) -{ - tACL_CONN *p = &btm_cb.acl_db[0]; - uint8_t xx; - - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) - { - if ((p->in_use) && (!memcmp (p->remote_addr, remote_bda, BD_ADDR_LEN)) && - p->transport == BT_TRANSPORT_BR_EDR) - { +static int btm_pm_find_acl_ind(BD_ADDR remote_bda) { + tACL_CONN* p = &btm_cb.acl_db[0]; + uint8_t xx; + + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { + if ((p->in_use) && (!memcmp(p->remote_addr, remote_bda, BD_ADDR_LEN)) && + p->transport == BT_TRANSPORT_BR_EDR) { #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_find_acl_ind ind:%d, st:%d", xx, btm_cb.pm_mode_db[xx].state); + BTM_TRACE_DEBUG("btm_pm_find_acl_ind ind:%d, st:%d", xx, + btm_cb.pm_mode_db[xx].state); #endif // BTM_PM_DEBUG - break; - } + break; } - return xx; + } + return xx; } /******************************************************************************* @@ -462,70 +424,66 @@ static int btm_pm_find_acl_ind(BD_ADDR remote_bda) * Returns void * ******************************************************************************/ -static tBTM_PM_PWR_MD * btm_pm_compare_modes(tBTM_PM_PWR_MD *p_md1, tBTM_PM_PWR_MD *p_md2, tBTM_PM_PWR_MD *p_res) -{ - uint8_t res; +static tBTM_PM_PWR_MD* btm_pm_compare_modes(tBTM_PM_PWR_MD* p_md1, + tBTM_PM_PWR_MD* p_md2, + tBTM_PM_PWR_MD* p_res) { + uint8_t res; - if(p_md1 == NULL) - { - *p_res = *p_md2; - p_res->mode &= ~BTM_PM_MD_FORCE; + if (p_md1 == NULL) { + *p_res = *p_md2; + p_res->mode &= ~BTM_PM_MD_FORCE; - return p_md2; - } + return p_md2; + } - if(p_md2->mode == BTM_PM_MD_ACTIVE || p_md1->mode == BTM_PM_MD_ACTIVE) - { - return NULL; - } + if (p_md2->mode == BTM_PM_MD_ACTIVE || p_md1->mode == BTM_PM_MD_ACTIVE) { + return NULL; + } - /* check if force bit is involved */ - if(p_md1->mode & BTM_PM_MD_FORCE) - { - *p_res = *p_md1; - p_res->mode &= ~BTM_PM_MD_FORCE; - return p_res; - } + /* check if force bit is involved */ + if (p_md1->mode & BTM_PM_MD_FORCE) { + *p_res = *p_md1; + p_res->mode &= ~BTM_PM_MD_FORCE; + return p_res; + } - if(p_md2->mode & BTM_PM_MD_FORCE) - { - *p_res = *p_md2; - p_res->mode &= ~BTM_PM_MD_FORCE; - return p_res; - } + if (p_md2->mode & BTM_PM_MD_FORCE) { + *p_res = *p_md2; + p_res->mode &= ~BTM_PM_MD_FORCE; + return p_res; + } - res = (p_md1->mode - 1) * BTM_PM_NUM_SET_MODES + (p_md2->mode - 1); - res = btm_pm_md_comp_matrix[res]; - switch(res) - { + res = (p_md1->mode - 1) * BTM_PM_NUM_SET_MODES + (p_md2->mode - 1); + res = btm_pm_md_comp_matrix[res]; + switch (res) { case BTM_PM_GET_MD1: - *p_res = *p_md1; - return p_md1; + *p_res = *p_md1; + return p_md1; case BTM_PM_GET_MD2: - *p_res = *p_md2; - return p_md2; + *p_res = *p_md2; + return p_md2; case BTM_PM_GET_COMP: - p_res->mode = p_md1->mode; - /* min of the two */ - p_res->max = (p_md1->max < p_md2->max)? (p_md1->max) : (p_md2->max); + p_res->mode = p_md1->mode; + /* min of the two */ + p_res->max = (p_md1->max < p_md2->max) ? (p_md1->max) : (p_md2->max); + /* max of the two */ + p_res->min = (p_md1->min > p_md2->min) ? (p_md1->min) : (p_md2->min); + + /* the intersection is NULL */ + if (p_res->max < p_res->min) return NULL; + + if (p_res->mode == BTM_PM_MD_SNIFF) { /* max of the two */ - p_res->min = (p_md1->min > p_md2->min)? (p_md1->min) : (p_md2->min); - - /* the intersection is NULL */ - if( p_res->max < p_res->min) - return NULL; - - if(p_res->mode == BTM_PM_MD_SNIFF) - { - /* max of the two */ - p_res->attempt = (p_md1->attempt > p_md2->attempt)? (p_md1->attempt) : (p_md2->attempt); - p_res->timeout = (p_md1->timeout > p_md2->timeout)? (p_md1->timeout) : (p_md2->timeout); - } - return p_res; - } - return NULL; + p_res->attempt = (p_md1->attempt > p_md2->attempt) ? (p_md1->attempt) + : (p_md2->attempt); + p_res->timeout = (p_md1->timeout > p_md2->timeout) ? (p_md1->timeout) + : (p_md2->timeout); + } + return p_res; + } + return NULL; } /******************************************************************************* @@ -538,61 +496,55 @@ static tBTM_PM_PWR_MD * btm_pm_compare_modes(tBTM_PM_PWR_MD *p_md1, tBTM_PM_PWR_ * Returns void * ******************************************************************************/ -static tBTM_PM_MODE btm_pm_get_set_mode(uint8_t pm_id, tBTM_PM_MCB *p_cb, tBTM_PM_PWR_MD *p_mode, tBTM_PM_PWR_MD *p_res) -{ - int xx, loop_max; - tBTM_PM_PWR_MD *p_md = NULL; - - if(p_mode != NULL && p_mode->mode & BTM_PM_MD_FORCE) - { - *p_res = *p_mode; - p_res->mode &= ~BTM_PM_MD_FORCE; - return p_res->mode; - } +static tBTM_PM_MODE btm_pm_get_set_mode(uint8_t pm_id, tBTM_PM_MCB* p_cb, + tBTM_PM_PWR_MD* p_mode, + tBTM_PM_PWR_MD* p_res) { + int xx, loop_max; + tBTM_PM_PWR_MD* p_md = NULL; + + if (p_mode != NULL && p_mode->mode & BTM_PM_MD_FORCE) { + *p_res = *p_mode; + p_res->mode &= ~BTM_PM_MD_FORCE; + return p_res->mode; + } - if(!p_mode) - loop_max = BTM_MAX_PM_RECORDS+1; - else - loop_max = BTM_MAX_PM_RECORDS; - - for( xx=0; xxreq_mode[xx].mode == BTM_PM_MD_ACTIVE) - { - /* if at least one registered (SET) party says ACTIVE, stay active */ - return BTM_PM_MD_ACTIVE; - } - else - { - /* if registered parties give conflicting information, stay active */ - if( (btm_pm_compare_modes(p_md, &p_cb->req_mode[xx], p_res)) == NULL) - return BTM_PM_MD_ACTIVE; - p_md = p_res; - } - } + if (!p_mode) + loop_max = BTM_MAX_PM_RECORDS + 1; + else + loop_max = BTM_MAX_PM_RECORDS; + + for (xx = 0; xx < loop_max; xx++) { + /* g through all the registered "set" parties */ + if (btm_cb.pm_reg_db[xx].mask & BTM_PM_REG_SET) { + if (p_cb->req_mode[xx].mode == BTM_PM_MD_ACTIVE) { + /* if at least one registered (SET) party says ACTIVE, stay active */ + return BTM_PM_MD_ACTIVE; + } else { + /* if registered parties give conflicting information, stay active */ + if ((btm_pm_compare_modes(p_md, &p_cb->req_mode[xx], p_res)) == NULL) + return BTM_PM_MD_ACTIVE; + p_md = p_res; + } } + } - /* if the resulting mode is NULL(nobody registers SET), use the requested mode */ - if(p_md == NULL) - { - if(p_mode) - *p_res = *((tBTM_PM_PWR_MD *)p_mode); - else /* p_mode is NULL when btm_pm_snd_md_req is called from btm_pm_proc_mode_change */ - return BTM_PM_MD_ACTIVE; - } - else - { - /* if the command is from unregistered party, - compare the resulting mode from registered party*/ - if( (pm_id == BTM_PM_SET_ONLY_ID) && - ((btm_pm_compare_modes(p_mode, p_md, p_res)) == NULL) ) - return BTM_PM_MD_ACTIVE; - } + /* if the resulting mode is NULL(nobody registers SET), use the requested mode + */ + if (p_md == NULL) { + if (p_mode) + *p_res = *((tBTM_PM_PWR_MD*)p_mode); + else /* p_mode is NULL when btm_pm_snd_md_req is called from + btm_pm_proc_mode_change */ + return BTM_PM_MD_ACTIVE; + } else { + /* if the command is from unregistered party, + compare the resulting mode from registered party*/ + if ((pm_id == BTM_PM_SET_ONLY_ID) && + ((btm_pm_compare_modes(p_mode, p_md, p_res)) == NULL)) + return BTM_PM_MD_ACTIVE; + } - return p_res->mode; + return p_res->mode; } /******************************************************************************* @@ -602,110 +554,104 @@ static tBTM_PM_MODE btm_pm_get_set_mode(uint8_t pm_id, tBTM_PM_MCB *p_cb, tBTM_P * Returns tBTM_STATUS *, bool *p_chg_ind ******************************************************************************/ -static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind, tBTM_PM_PWR_MD *p_mode) -{ - tBTM_PM_PWR_MD md_res; - tBTM_PM_MODE mode; - tBTM_PM_MCB *p_cb = &btm_cb.pm_mode_db[link_ind]; - bool chg_ind = false; +static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind, + tBTM_PM_PWR_MD* p_mode) { + tBTM_PM_PWR_MD md_res; + tBTM_PM_MODE mode; + tBTM_PM_MCB* p_cb = &btm_cb.pm_mode_db[link_ind]; + bool chg_ind = false; - mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res); - md_res.mode = mode; + mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res); + md_res.mode = mode; #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_snd_md_req link_ind:%d, mode: %d", - link_ind, mode); + BTM_TRACE_DEBUG("btm_pm_snd_md_req link_ind:%d, mode: %d", link_ind, mode); #endif // BTM_PM_DEBUG - if( p_cb->state == mode) - { - /* already in the resulting mode */ - if( (mode == BTM_PM_MD_ACTIVE) || - ((md_res.max >= p_cb->interval) && (md_res.min <= p_cb->interval)) ) - return BTM_CMD_STORED; - /* Otherwise, needs to wake, then sleep */ - chg_ind = true; - } - p_cb->chg_ind = chg_ind; + if (p_cb->state == mode) { + /* already in the resulting mode */ + if ((mode == BTM_PM_MD_ACTIVE) || + ((md_res.max >= p_cb->interval) && (md_res.min <= p_cb->interval))) + return BTM_CMD_STORED; + /* Otherwise, needs to wake, then sleep */ + chg_ind = true; + } + p_cb->chg_ind = chg_ind; - /* cannot go directly from current mode to resulting mode. */ - if( mode != BTM_PM_MD_ACTIVE && p_cb->state != BTM_PM_MD_ACTIVE) - p_cb->chg_ind = true; /* needs to wake, then sleep */ + /* cannot go directly from current mode to resulting mode. */ + if (mode != BTM_PM_MD_ACTIVE && p_cb->state != BTM_PM_MD_ACTIVE) + p_cb->chg_ind = true; /* needs to wake, then sleep */ - if(p_cb->chg_ind == true) /* needs to wake first */ - md_res.mode = BTM_PM_MD_ACTIVE; + if (p_cb->chg_ind == true) /* needs to wake first */ + md_res.mode = BTM_PM_MD_ACTIVE; #if (BTM_SSR_INCLUDED == TRUE) - else if(BTM_PM_MD_SNIFF == md_res.mode && p_cb->max_lat) - { - btsnd_hcic_sniff_sub_rate(btm_cb.acl_db[link_ind].hci_handle, p_cb->max_lat, - p_cb->min_rmt_to, p_cb->min_loc_to); - p_cb->max_lat = 0; - } + else if (BTM_PM_MD_SNIFF == md_res.mode && p_cb->max_lat) { + btsnd_hcic_sniff_sub_rate(btm_cb.acl_db[link_ind].hci_handle, p_cb->max_lat, + p_cb->min_rmt_to, p_cb->min_loc_to); + p_cb->max_lat = 0; + } #endif // BTM_SSR_INCLUDED - /* Default is failure */ - btm_cb.pm_pend_link = MAX_L2CAP_LINKS; + /* Default is failure */ + btm_cb.pm_pend_link = MAX_L2CAP_LINKS; - /* send the appropriate HCI command */ - btm_cb.pm_pend_id = pm_id; + /* send the appropriate HCI command */ + btm_cb.pm_pend_id = pm_id; #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG("btm_pm_snd_md_req state:0x%x, link_ind: %d", p_cb->state, link_ind); + BTM_TRACE_DEBUG("btm_pm_snd_md_req state:0x%x, link_ind: %d", p_cb->state, + link_ind); #endif // BTM_PM_DEBUG - BTM_TRACE_DEBUG("%s switching from %s to %s.", __func__, - mode_to_string(p_cb->state), mode_to_string(md_res.mode)); - switch(md_res.mode) - { + BTM_TRACE_DEBUG("%s switching from %s to %s.", __func__, + mode_to_string(p_cb->state), mode_to_string(md_res.mode)); + switch (md_res.mode) { case BTM_PM_MD_ACTIVE: - switch(p_cb->state) - { + switch (p_cb->state) { case BTM_PM_MD_SNIFF: - btsnd_hcic_exit_sniff_mode(btm_cb.acl_db[link_ind].hci_handle); - btm_cb.pm_pend_link = link_ind; - break; + btsnd_hcic_exit_sniff_mode(btm_cb.acl_db[link_ind].hci_handle); + btm_cb.pm_pend_link = link_ind; + break; case BTM_PM_MD_PARK: - btsnd_hcic_exit_park_mode(btm_cb.acl_db[link_ind].hci_handle); - btm_cb.pm_pend_link = link_ind; - break; + btsnd_hcic_exit_park_mode(btm_cb.acl_db[link_ind].hci_handle); + btm_cb.pm_pend_link = link_ind; + break; default: - /* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */ - break; - } - break; + /* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */ + break; + } + break; case BTM_PM_MD_HOLD: - btsnd_hcic_hold_mode(btm_cb.acl_db[link_ind].hci_handle, - md_res.max, md_res.min); - btm_cb.pm_pend_link = link_ind; - break; + btsnd_hcic_hold_mode(btm_cb.acl_db[link_ind].hci_handle, md_res.max, + md_res.min); + btm_cb.pm_pend_link = link_ind; + break; case BTM_PM_MD_SNIFF: - btsnd_hcic_sniff_mode(btm_cb.acl_db[link_ind].hci_handle, - md_res.max, md_res.min, md_res.attempt, - md_res.timeout); - btm_cb.pm_pend_link = link_ind; - break; + btsnd_hcic_sniff_mode(btm_cb.acl_db[link_ind].hci_handle, md_res.max, + md_res.min, md_res.attempt, md_res.timeout); + btm_cb.pm_pend_link = link_ind; + break; case BTM_PM_MD_PARK: - btsnd_hcic_park_mode(btm_cb.acl_db[link_ind].hci_handle, - md_res.max, md_res.min); - btm_cb.pm_pend_link = link_ind; - break; + btsnd_hcic_park_mode(btm_cb.acl_db[link_ind].hci_handle, md_res.max, + md_res.min); + btm_cb.pm_pend_link = link_ind; + break; default: - /* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */ - break; - } + /* Failure btm_cb.pm_pend_link = MAX_L2CAP_LINKS */ + break; + } - if(btm_cb.pm_pend_link == MAX_L2CAP_LINKS) - { - /* the command was not sent */ + if (btm_cb.pm_pend_link == MAX_L2CAP_LINKS) { +/* the command was not sent */ #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "pm_pend_link: %d",btm_cb.pm_pend_link); + BTM_TRACE_DEBUG("pm_pend_link: %d", btm_cb.pm_pend_link); #endif // BTM_PM_DEBUG - return (BTM_NO_RESOURCES); - } + return (BTM_NO_RESOURCES); + } - return BTM_CMD_STARTED; + return BTM_CMD_STARTED; } /******************************************************************************* @@ -719,19 +665,16 @@ static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind, tBTM_PM_PWR_MD * Returns none. * ******************************************************************************/ -static void btm_pm_check_stored(void) -{ - int xx; - for(xx=0; xx= MAX_L2CAP_LINKS) - return; + if (btm_cb.pm_pend_link >= MAX_L2CAP_LINKS) return; - p_cb = &btm_cb.pm_mode_db[btm_cb.pm_pend_link]; + p_cb = &btm_cb.pm_mode_db[btm_cb.pm_pend_link]; - if(status == HCI_SUCCESS) - { - p_cb->state = BTM_PM_ST_PENDING; - pm_status = BTM_PM_STS_PENDING; + if (status == HCI_SUCCESS) { + p_cb->state = BTM_PM_ST_PENDING; + pm_status = BTM_PM_STS_PENDING; #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status new state:0x%x", p_cb->state); -#endif // BTM_PM_DEBUG - } - else /* the command was not successfull. Stay in the same state */ - { - pm_status = BTM_PM_STS_ERROR; - } + BTM_TRACE_DEBUG("btm_pm_proc_cmd_status new state:0x%x", p_cb->state); +#endif // BTM_PM_DEBUG + } else /* the command was not successfull. Stay in the same state */ + { + pm_status = BTM_PM_STS_ERROR; + } - /* notify the caller is appropriate */ - if( (btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) && - (btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF) ) - { - (*btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback)(btm_cb.acl_db[btm_cb.pm_pend_link].remote_addr, pm_status, 0, status); - } + /* notify the caller is appropriate */ + if ((btm_cb.pm_pend_id != BTM_PM_SET_ONLY_ID) && + (btm_cb.pm_reg_db[btm_cb.pm_pend_id].mask & BTM_PM_REG_NOTIF)) { + (*btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback)( + btm_cb.acl_db[btm_cb.pm_pend_link].remote_addr, pm_status, 0, status); + } - /* no pending cmd now */ +/* no pending cmd now */ #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status state:0x%x, pm_pend_link: %d(new: %d)", - p_cb->state, btm_cb.pm_pend_link, MAX_L2CAP_LINKS); + BTM_TRACE_DEBUG( + "btm_pm_proc_cmd_status state:0x%x, pm_pend_link: %d(new: %d)", + p_cb->state, btm_cb.pm_pend_link, MAX_L2CAP_LINKS); #endif // BTM_PM_DEBUG - btm_cb.pm_pend_link = MAX_L2CAP_LINKS; + btm_cb.pm_pend_link = MAX_L2CAP_LINKS; - btm_pm_check_stored(); + btm_pm_check_stored(); } /******************************************************************************* @@ -803,88 +743,79 @@ void btm_pm_proc_cmd_status(uint8_t status) * Returns none. * ******************************************************************************/ -void btm_pm_proc_mode_change (uint8_t hci_status, uint16_t hci_handle, uint8_t mode, uint16_t interval) -{ - tACL_CONN *p; - tBTM_PM_MCB *p_cb = NULL; - int xx, yy, zz; - tBTM_PM_STATE old_state; - tL2C_LCB *p_lcb; - - /* get the index to acl_db */ - xx = btm_handle_to_acl_index(hci_handle); - if (xx >= MAX_L2CAP_LINKS) - return; - - p = &btm_cb.acl_db[xx]; - - /* update control block */ - p_cb = &(btm_cb.pm_mode_db[xx]); - old_state = p_cb->state; - p_cb->state = mode; - p_cb->interval = interval; - - BTM_TRACE_DEBUG("%s switched from %s to %s.", __func__, - mode_to_string(old_state), mode_to_string(p_cb->state)); - - p_lcb = l2cu_find_lcb_by_bd_addr(p->remote_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb != NULL) - { - if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) - { - /* There might be any pending packets due to SNIFF or PENDING state */ - /* Trigger L2C to start transmission of the pending packets. */ - BTM_TRACE_DEBUG("btm mode change to active; check l2c_link for outgoing packets"); - l2c_link_check_send_pkts(p_lcb, NULL, NULL); - } +void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, + uint8_t mode, uint16_t interval) { + tACL_CONN* p; + tBTM_PM_MCB* p_cb = NULL; + int xx, yy, zz; + tBTM_PM_STATE old_state; + tL2C_LCB* p_lcb; + + /* get the index to acl_db */ + xx = btm_handle_to_acl_index(hci_handle); + if (xx >= MAX_L2CAP_LINKS) return; + + p = &btm_cb.acl_db[xx]; + + /* update control block */ + p_cb = &(btm_cb.pm_mode_db[xx]); + old_state = p_cb->state; + p_cb->state = mode; + p_cb->interval = interval; + + BTM_TRACE_DEBUG("%s switched from %s to %s.", __func__, + mode_to_string(old_state), mode_to_string(p_cb->state)); + + p_lcb = l2cu_find_lcb_by_bd_addr(p->remote_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb != NULL) { + if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) { + /* There might be any pending packets due to SNIFF or PENDING state */ + /* Trigger L2C to start transmission of the pending packets. */ + BTM_TRACE_DEBUG( + "btm mode change to active; check l2c_link for outgoing packets"); + l2c_link_check_send_pkts(p_lcb, NULL, NULL); } + } - /* notify registered parties */ - for(yy=0; yy<=BTM_MAX_PM_RECORDS; yy++) - { - /* set req_mode HOLD mode->ACTIVE */ - if( (mode == BTM_PM_MD_ACTIVE) && (p_cb->req_mode[yy].mode == BTM_PM_MD_HOLD) ) - p_cb->req_mode[yy].mode = BTM_PM_MD_ACTIVE; - } + /* notify registered parties */ + for (yy = 0; yy <= BTM_MAX_PM_RECORDS; yy++) { + /* set req_mode HOLD mode->ACTIVE */ + if ((mode == BTM_PM_MD_ACTIVE) && + (p_cb->req_mode[yy].mode == BTM_PM_MD_HOLD)) + p_cb->req_mode[yy].mode = BTM_PM_MD_ACTIVE; + } - /* new request has been made. - post a message to BTU task */ - if(old_state & BTM_PM_STORED_MASK) - { + /* new request has been made. - post a message to BTU task */ + if (old_state & BTM_PM_STORED_MASK) { #if (BTM_PM_DEBUG == TRUE) - BTM_TRACE_DEBUG( "btm_pm_proc_mode_change: Sending stored req:%d", xx); + BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending stored req:%d", xx); #endif // BTM_PM_DEBUG - btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, xx, NULL); - } - else - { - for(zz=0; zzremote_addr, mode, interval, hci_status); - } + /* notify registered parties */ + for (yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) { + if (btm_cb.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) { + (*btm_cb.pm_reg_db[yy].cback)(p->remote_addr, mode, interval, hci_status); } + } #if (BTM_SCO_INCLUDED == TRUE) - /*check if sco disconnect is waiting for the mode change */ - btm_sco_disc_chk_pend_for_modechange(hci_handle); + /*check if sco disconnect is waiting for the mode change */ + btm_sco_disc_chk_pend_for_modechange(hci_handle); #endif - /* If mode change was because of an active role switch or change link key */ - btm_cont_rswitch(p, btm_find_dev(p->remote_addr), hci_status); + /* If mode change was because of an active role switch or change link key */ + btm_cont_rswitch(p, btm_find_dev(p->remote_addr), hci_status); } /******************************************************************************* @@ -898,47 +829,41 @@ void btm_pm_proc_mode_change (uint8_t hci_status, uint16_t hci_handle, uint8_t m * ******************************************************************************/ #if (BTM_SSR_INCLUDED == TRUE) -void btm_pm_proc_ssr_evt (uint8_t *p, - UNUSED_ATTR uint16_t evt_len) -{ - uint8_t status; - uint16_t handle; - uint16_t max_rx_lat; - int xx, yy; - tBTM_PM_MCB *p_cb; - tACL_CONN *p_acl=NULL; - uint16_t use_ssr = true; - - STREAM_TO_UINT8 (status, p); - - STREAM_TO_UINT16 (handle, p); - /* get the index to acl_db */ - xx = btm_handle_to_acl_index(handle); - if (xx >= MAX_L2CAP_LINKS) - return; - - p += 2; - STREAM_TO_UINT16 (max_rx_lat, p); - p_cb = &(btm_cb.pm_mode_db[xx]); - - p_acl = &btm_cb.acl_db[xx]; - if(p_cb->interval == max_rx_lat) - { - /* using legacy sniff */ - use_ssr = false; - } +void btm_pm_proc_ssr_evt(uint8_t* p, UNUSED_ATTR uint16_t evt_len) { + uint8_t status; + uint16_t handle; + uint16_t max_rx_lat; + int xx, yy; + tBTM_PM_MCB* p_cb; + tACL_CONN* p_acl = NULL; + uint16_t use_ssr = true; + + STREAM_TO_UINT8(status, p); + + STREAM_TO_UINT16(handle, p); + /* get the index to acl_db */ + xx = btm_handle_to_acl_index(handle); + if (xx >= MAX_L2CAP_LINKS) return; + + p += 2; + STREAM_TO_UINT16(max_rx_lat, p); + p_cb = &(btm_cb.pm_mode_db[xx]); + + p_acl = &btm_cb.acl_db[xx]; + if (p_cb->interval == max_rx_lat) { + /* using legacy sniff */ + use_ssr = false; + } - /* notify registered parties */ - for(yy=0; yyremote_addr, BTM_PM_STS_SSR, use_ssr, status); - } - } + /* notify registered parties */ + for (yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) { + if (btm_cb.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) { + if (p_acl) { + (*btm_cb.pm_reg_db[yy].cback)(p_acl->remote_addr, BTM_PM_STS_SSR, + use_ssr, status); + } } + } } #endif // BTM_SSR_INCLUDED @@ -951,25 +876,23 @@ void btm_pm_proc_ssr_evt (uint8_t *p, * Returns true, if in active or sniff mode * ******************************************************************************/ -bool btm_pm_device_in_active_or_sniff_mode(void) -{ - /* The active state is the highest state-includes connected device and sniff mode*/ - - /* Covers active and sniff modes */ - if (BTM_GetNumAclLinks() > 0) - { - BTM_TRACE_DEBUG("%s - ACL links: %d", __func__, BTM_GetNumAclLinks()); - return true; - } +bool btm_pm_device_in_active_or_sniff_mode(void) { + /* The active state is the highest state-includes connected device and sniff + * mode*/ + + /* Covers active and sniff modes */ + if (BTM_GetNumAclLinks() > 0) { + BTM_TRACE_DEBUG("%s - ACL links: %d", __func__, BTM_GetNumAclLinks()); + return true; + } - /* Check BLE states */ - if (btm_ble_get_conn_st() != BLE_CONN_IDLE) - { - BTM_TRACE_DEBUG("%s - BLE state: %x", __func__, btm_ble_get_conn_st()); - return true; - } + /* Check BLE states */ + if (btm_ble_get_conn_st() != BLE_CONN_IDLE) { + BTM_TRACE_DEBUG("%s - BLE state: %x", __func__, btm_ble_get_conn_st()); + return true; + } - return false; + return false; } /******************************************************************************* @@ -982,26 +905,24 @@ bool btm_pm_device_in_active_or_sniff_mode(void) * Returns true, if in paging, inquiry or connecting mode * ******************************************************************************/ -bool btm_pm_device_in_scan_state(void) -{ - /* Scan state-paging, inquiry, and trying to connect */ - - /* Check for paging */ - if (btm_cb.is_paging || (!fixed_queue_is_empty(btm_cb.page_queue)) || - BTM_BL_PAGING_STARTED == btm_cb.busy_level) - { - BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- paging"); - return true; - } +bool btm_pm_device_in_scan_state(void) { + /* Scan state-paging, inquiry, and trying to connect */ + + /* Check for paging */ + if (btm_cb.is_paging || (!fixed_queue_is_empty(btm_cb.page_queue)) || + BTM_BL_PAGING_STARTED == btm_cb.busy_level) { + BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- paging"); + return true; + } - /* Check for inquiry */ - if ((btm_cb.btm_inq_vars.inq_active & (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK)) != 0) - { - BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- Inq active"); - return true; - } + /* Check for inquiry */ + if ((btm_cb.btm_inq_vars.inq_active & + (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK)) != 0) { + BTM_TRACE_DEBUG("btm_pm_device_in_scan_state- Inq active"); + return true; + } - return false; + return false; } /******************************************************************************* @@ -1014,23 +935,26 @@ bool btm_pm_device_in_scan_state(void) * BTM_CONTRL_IDLE * ******************************************************************************/ -tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void) -{ - if (true == btm_pm_device_in_active_or_sniff_mode()) - return BTM_CONTRL_ACTIVE; - else - if (true == btm_pm_device_in_scan_state()) - return BTM_CONTRL_SCAN; - else - return BTM_CONTRL_IDLE; +tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void) { + if (true == btm_pm_device_in_active_or_sniff_mode()) + return BTM_CONTRL_ACTIVE; + else if (true == btm_pm_device_in_scan_state()) + return BTM_CONTRL_SCAN; + else + return BTM_CONTRL_IDLE; } -static const char *mode_to_string(tBTM_PM_MODE mode) { +static const char* mode_to_string(tBTM_PM_MODE mode) { switch (mode) { - case BTM_PM_MD_ACTIVE: return "ACTIVE"; - case BTM_PM_MD_SNIFF: return "SNIFF"; - case BTM_PM_MD_PARK: return "PARK"; - case BTM_PM_MD_HOLD: return "HOLD"; - default: return "UNKNOWN"; + case BTM_PM_MD_ACTIVE: + return "ACTIVE"; + case BTM_PM_MD_SNIFF: + return "SNIFF"; + case BTM_PM_MD_PARK: + return "PARK"; + case BTM_PM_MD_HOLD: + return "HOLD"; + default: + return "UNKNOWN"; } } diff --git a/stack/btm/btm_sco.cc b/stack/btm/btm_sco.cc index 8d2a3890e..8936139c8 100644 --- a/stack/btm/btm_sco.cc +++ b/stack/btm/btm_sco.cc @@ -24,53 +24,48 @@ ******************************************************************************/ #include -#include "bt_types.h" -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" #include "bt_types.h" -#include "hcimsgs.h" -#include "btu.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" -#include "hcidefs.h" -#include "bt_utils.h" +#include "btu.h" #include "device/include/controller.h" +#include "hcidefs.h" +#include "hcimsgs.h" #include "osi/include/osi.h" - #if (BTM_SCO_INCLUDED == TRUE) /******************************************************************************/ /* L O C A L D A T A D E F I N I T I O N S */ /******************************************************************************/ -#define SCO_ST_UNUSED 0 -#define SCO_ST_LISTENING 1 -#define SCO_ST_W4_CONN_RSP 2 -#define SCO_ST_CONNECTING 3 -#define SCO_ST_CONNECTED 4 -#define SCO_ST_DISCONNECTING 5 -#define SCO_ST_PEND_UNPARK 6 -#define SCO_ST_PEND_ROLECHANGE 7 -#define SCO_ST_PEND_MODECHANGE 8 +#define SCO_ST_UNUSED 0 +#define SCO_ST_LISTENING 1 +#define SCO_ST_W4_CONN_RSP 2 +#define SCO_ST_CONNECTING 3 +#define SCO_ST_CONNECTED 4 +#define SCO_ST_DISCONNECTING 5 +#define SCO_ST_PEND_UNPARK 6 +#define SCO_ST_PEND_ROLECHANGE 7 +#define SCO_ST_PEND_MODECHANGE 8 /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static const tBTM_ESCO_PARAMS btm_esco_defaults = -{ - BTM_64KBITS_RATE, /* TX Bandwidth (64 kbits/sec) */ - BTM_64KBITS_RATE, /* RX Bandwidth (64 kbits/sec) */ - 0x000c, /* 12 ms (HS/HF can use EV3, 2-EV3, 3-EV3) */ - 0x0060, /* Inp Linear, Air CVSD, 2s Comp, 16bit */ - (BTM_SCO_PKT_TYPES_MASK_HV1 + /* Packet Types */ - BTM_SCO_PKT_TYPES_MASK_HV2 + - BTM_SCO_PKT_TYPES_MASK_HV3 + - BTM_SCO_PKT_TYPES_MASK_EV3 + - BTM_SCO_PKT_TYPES_MASK_EV4 + +static const tBTM_ESCO_PARAMS btm_esco_defaults = { + BTM_64KBITS_RATE, /* TX Bandwidth (64 kbits/sec) */ + BTM_64KBITS_RATE, /* RX Bandwidth (64 kbits/sec) */ + 0x000c, /* 12 ms (HS/HF can use EV3, 2-EV3, 3-EV3) */ + 0x0060, /* Inp Linear, Air CVSD, 2s Comp, 16bit */ + (BTM_SCO_PKT_TYPES_MASK_HV1 + /* Packet Types */ + BTM_SCO_PKT_TYPES_MASK_HV2 + BTM_SCO_PKT_TYPES_MASK_HV3 + + BTM_SCO_PKT_TYPES_MASK_EV3 + BTM_SCO_PKT_TYPES_MASK_EV4 + BTM_SCO_PKT_TYPES_MASK_EV5), - BTM_ESCO_RETRANS_QUALITY /* Retransmission Effort */ + BTM_ESCO_RETRANS_QUALITY /* Retransmission Effort */ }; /******************************************************************************* @@ -83,24 +78,20 @@ static const tBTM_ESCO_PARAMS btm_esco_defaults = * Returns void * ******************************************************************************/ -#if (BTM_SCO_HCI_INCLUDED == TRUE && BTM_MAX_SCO_LINKS>0) -void btm_sco_flush_sco_data(uint16_t sco_inx) -{ - tSCO_CONN *p ; - BT_HDR *p_buf; +#if (BTM_SCO_HCI_INCLUDED == TRUE && BTM_MAX_SCO_LINKS > 0) +void btm_sco_flush_sco_data(uint16_t sco_inx) { + tSCO_CONN* p; + BT_HDR* p_buf; - if (sco_inx < BTM_MAX_SCO_LINKS) - { - p = &btm_cb.sco_cb.sco_db[sco_inx]; - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p->xmit_data_q)) != NULL) - osi_free(p_buf); - } - } + if (sco_inx < BTM_MAX_SCO_LINKS) { + p = &btm_cb.sco_cb.sco_db[sco_inx]; + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p->xmit_data_q)) != NULL) + osi_free(p_buf); + } } -#else -void btm_sco_flush_sco_data(UNUSED_ATTR uint16_t sco_inx) -{ } +#else +void btm_sco_flush_sco_data(UNUSED_ATTR uint16_t sco_inx) {} #endif /******************************************************************************* * @@ -111,18 +102,18 @@ void btm_sco_flush_sco_data(UNUSED_ATTR uint16_t sco_inx) * Returns void * ******************************************************************************/ -void btm_sco_init (void) -{ +void btm_sco_init(void) { #if (BTM_SCO_HCI_INCLUDED == TRUE) - for (int i = 0; i < BTM_MAX_SCO_LINKS; i++) - btm_cb.sco_cb.sco_db[i].xmit_data_q = fixed_queue_new(SIZE_MAX); + for (int i = 0; i < BTM_MAX_SCO_LINKS; i++) + btm_cb.sco_cb.sco_db[i].xmit_data_q = fixed_queue_new(SIZE_MAX); #endif - /* Initialize nonzero defaults */ - btm_cb.sco_cb.sco_disc_reason = BTM_INVALID_SCO_DISC_REASON; + /* Initialize nonzero defaults */ + btm_cb.sco_cb.sco_disc_reason = BTM_INVALID_SCO_DISC_REASON; - btm_cb.sco_cb.def_esco_parms = btm_esco_defaults; /* Initialize with defaults */ - btm_cb.sco_cb.desired_sco_mode = BTM_DEFAULT_SCO_MODE; + btm_cb.sco_cb.def_esco_parms = + btm_esco_defaults; /* Initialize with defaults */ + btm_cb.sco_cb.desired_sco_mode = BTM_DEFAULT_SCO_MODE; } /******************************************************************************* @@ -141,82 +132,71 @@ void btm_sco_init (void) * Returns void * ******************************************************************************/ -static void btm_esco_conn_rsp (uint16_t sco_inx, uint8_t hci_status, BD_ADDR bda, - tBTM_ESCO_PARAMS *p_parms) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p_sco = NULL; - tBTM_ESCO_PARAMS *p_setup; - uint16_t temp_pkt_types; - - if (sco_inx < BTM_MAX_SCO_LINKS) - p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; - - /* Reject the connect request if refused by caller or wrong state */ - if (hci_status != HCI_SUCCESS || p_sco == NULL) - { - if (p_sco) - { - p_sco->state = (p_sco->state == SCO_ST_W4_CONN_RSP) ? SCO_ST_LISTENING - : SCO_ST_UNUSED; - } +static void btm_esco_conn_rsp(uint16_t sco_inx, uint8_t hci_status, BD_ADDR bda, + tBTM_ESCO_PARAMS* p_parms) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p_sco = NULL; + tBTM_ESCO_PARAMS* p_setup; + uint16_t temp_pkt_types; - if (!btm_cb.sco_cb.esco_supported) - { - btsnd_hcic_reject_conn(bda, hci_status); - } - else - { - btsnd_hcic_reject_esco_conn(bda, hci_status); - } + if (sco_inx < BTM_MAX_SCO_LINKS) p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; + + /* Reject the connect request if refused by caller or wrong state */ + if (hci_status != HCI_SUCCESS || p_sco == NULL) { + if (p_sco) { + p_sco->state = (p_sco->state == SCO_ST_W4_CONN_RSP) ? SCO_ST_LISTENING + : SCO_ST_UNUSED; } - else /* Connection is being accepted */ + + if (!btm_cb.sco_cb.esco_supported) { + btsnd_hcic_reject_conn(bda, hci_status); + } else { + btsnd_hcic_reject_esco_conn(bda, hci_status); + } + } else /* Connection is being accepted */ + { + p_sco->state = SCO_ST_CONNECTING; + p_setup = &p_sco->esco.setup; + /* If parameters not specified use the default */ + if (p_parms) + *p_setup = *p_parms; + else /* Use the last setup passed thru BTM_SetEscoMode (or defaults) */ { - p_sco->state = SCO_ST_CONNECTING; - p_setup = &p_sco->esco.setup; - /* If parameters not specified use the default */ - if (p_parms) - *p_setup = *p_parms; - else /* Use the last setup passed thru BTM_SetEscoMode (or defaults) */ - { - *p_setup = btm_cb.sco_cb.def_esco_parms; - } + *p_setup = btm_cb.sco_cb.def_esco_parms; + } - temp_pkt_types = (p_setup->packet_types & - BTM_SCO_SUPPORTED_PKTS_MASK & - btm_cb.btm_sco_pkt_types_supported); + temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & + btm_cb.btm_sco_pkt_types_supported); - /* Make sure at least one eSCO packet type is sent, else might confuse peer */ - /* Taking this out to confirm with BQB tests - ** Real application would like to include this though, as many devices - ** do not retry with SCO only if an eSCO connection fails. - if (!(temp_pkt_types & BTM_ESCO_LINK_ONLY_MASK)) - { - temp_pkt_types |= BTM_SCO_PKT_TYPES_MASK_EV3; - } - */ - /* If SCO request, remove eSCO packet types (conformance) */ - if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO) - { - temp_pkt_types &= BTM_SCO_LINK_ONLY_MASK; - temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK; - } - else - { - /* OR in any exception packet types */ - temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | - (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); - } - - btsnd_hcic_accept_esco_conn(bda, p_setup->tx_bw, p_setup->rx_bw, - p_setup->max_latency, p_setup->voice_contfmt, - p_setup->retrans_effort, temp_pkt_types); - p_setup->packet_types = temp_pkt_types; + /* Make sure at least one eSCO packet type is sent, else might confuse peer + */ + /* Taking this out to confirm with BQB tests + ** Real application would like to include this though, as many devices + ** do not retry with SCO only if an eSCO connection fails. + if (!(temp_pkt_types & BTM_ESCO_LINK_ONLY_MASK)) + { + temp_pkt_types |= BTM_SCO_PKT_TYPES_MASK_EV3; } + */ + /* If SCO request, remove eSCO packet types (conformance) */ + if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO) { + temp_pkt_types &= BTM_SCO_LINK_ONLY_MASK; + temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK; + } else { + /* OR in any exception packet types */ + temp_pkt_types |= + ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | + (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); + } + + btsnd_hcic_accept_esco_conn(bda, p_setup->tx_bw, p_setup->rx_bw, + p_setup->max_latency, p_setup->voice_contfmt, + p_setup->retrans_effort, temp_pkt_types); + p_setup->packet_types = temp_pkt_types; + } #endif } - #if (BTM_SCO_HCI_INCLUDED == TRUE) /******************************************************************************* * @@ -228,22 +208,21 @@ static void btm_esco_conn_rsp (uint16_t sco_inx, uint8_t hci_status, BD_ADDR bda * Returns void * ******************************************************************************/ -void btm_sco_check_send_pkts (uint16_t sco_inx) -{ - tSCO_CB *p_cb = &btm_cb.sco_cb; - tSCO_CONN *p_ccb = &p_cb->sco_db[sco_inx]; - - /* If there is data to send, send it now */ - BT_HDR *p_buf; - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_data_q)) != NULL) - { +void btm_sco_check_send_pkts(uint16_t sco_inx) { + tSCO_CB* p_cb = &btm_cb.sco_cb; + tSCO_CONN* p_ccb = &p_cb->sco_db[sco_inx]; + + /* If there is data to send, send it now */ + BT_HDR* p_buf; + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_data_q)) != + NULL) { #if (BTM_SCO_HCI_DEBUG == TRUE) - BTM_TRACE_DEBUG("btm: [%d] buf in xmit_data_q", - fixed_queue_length(p_ccb->xmit_data_q) + 1); + BTM_TRACE_DEBUG("btm: [%d] buf in xmit_data_q", + fixed_queue_length(p_ccb->xmit_data_q) + 1); #endif - HCI_SCO_DATA_TO_LOWER(p_buf); - } + HCI_SCO_DATA_TO_LOWER(p_buf); + } } #endif /* BTM_SCO_HCI_INCLUDED == TRUE */ @@ -256,39 +235,36 @@ void btm_sco_check_send_pkts (uint16_t sco_inx) * Returns void * ******************************************************************************/ -void btm_route_sco_data(BT_HDR *p_msg) -{ +void btm_route_sco_data(BT_HDR* p_msg) { #if (BTM_SCO_HCI_INCLUDED == TRUE) - uint16_t sco_inx, handle; - uint8_t *p = (uint8_t *)(p_msg + 1) + p_msg->offset; - uint8_t pkt_size = 0; - uint8_t pkt_status = 0; - - /* Extract Packet_Status_Flag and handle */ - STREAM_TO_UINT16 (handle, p); - pkt_status = HCID_GET_EVENT(handle); - handle = HCID_GET_HANDLE (handle); - - STREAM_TO_UINT8 (pkt_size, p); - - sco_inx = btm_find_scb_by_handle(handle); - if (sco_inx != BTM_MAX_SCO_LINKS) - { - /* send data callback */ - if (!btm_cb.sco_cb.p_data_cb) - /* if no data callback registered, just free the buffer */ - osi_free(p_msg); - else - { - (*btm_cb.sco_cb.p_data_cb)(sco_inx, p_msg, (tBTM_SCO_DATA_FLAG) pkt_status); - } - } - else /* no mapping handle SCO connection is active, free the buffer */ - { - osi_free(p_msg); + uint16_t sco_inx, handle; + uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint8_t pkt_size = 0; + uint8_t pkt_status = 0; + + /* Extract Packet_Status_Flag and handle */ + STREAM_TO_UINT16(handle, p); + pkt_status = HCID_GET_EVENT(handle); + handle = HCID_GET_HANDLE(handle); + + STREAM_TO_UINT8(pkt_size, p); + + sco_inx = btm_find_scb_by_handle(handle); + if (sco_inx != BTM_MAX_SCO_LINKS) { + /* send data callback */ + if (!btm_cb.sco_cb.p_data_cb) + /* if no data callback registered, just free the buffer */ + osi_free(p_msg); + else { + (*btm_cb.sco_cb.p_data_cb)(sco_inx, p_msg, + (tBTM_SCO_DATA_FLAG)pkt_status); } -#else + } else /* no mapping handle SCO connection is active, free the buffer */ + { osi_free(p_msg); + } +#else + osi_free(p_msg); #endif } @@ -314,67 +290,59 @@ void btm_route_sco_data(BT_HDR *p_msg) * ******************************************************************************/ #if (BTM_SCO_HCI_INCLUDED == TRUE && BTM_MAX_SCO_LINKS > 0) -tBTM_STATUS BTM_WriteScoData (uint16_t sco_inx, BT_HDR *p_buf) -{ - tSCO_CONN *p_ccb = &btm_cb.sco_cb.sco_db[sco_inx]; - uint8_t *p; - tBTM_STATUS status = BTM_SUCCESS; - - if (sco_inx < BTM_MAX_SCO_LINKS && btm_cb.sco_cb.p_data_cb && - p_ccb->state == SCO_ST_CONNECTED) - { - /* Ensure we have enough space in the buffer for the SCO and HCI headers */ - if (p_buf->offset < HCI_SCO_PREAMBLE_SIZE) - { - BTM_TRACE_ERROR ("BTM SCO - cannot send buffer, offset: %d", p_buf->offset); - osi_free(p_buf); - status = BTM_ILLEGAL_VALUE; - } - else /* write HCI header */ - { - /* Step back 3 bytes to add the headers */ - p_buf->offset -= HCI_SCO_PREAMBLE_SIZE; - /* Set the pointer to the beginning of the data */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - /* add HCI handle */ - UINT16_TO_STREAM (p, p_ccb->hci_handle); - /* only sent the first BTM_SCO_DATA_SIZE_MAX bytes data if more than max, - and set warning status */ - if (p_buf->len > BTM_SCO_DATA_SIZE_MAX) - { - p_buf->len = BTM_SCO_DATA_SIZE_MAX; - status = BTM_SCO_BAD_LENGTH; - } - - UINT8_TO_STREAM (p, (uint8_t)p_buf->len); - p_buf->len += HCI_SCO_PREAMBLE_SIZE; - - fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf); - - btm_sco_check_send_pkts (sco_inx); - } - } - else +tBTM_STATUS BTM_WriteScoData(uint16_t sco_inx, BT_HDR* p_buf) { + tSCO_CONN* p_ccb = &btm_cb.sco_cb.sco_db[sco_inx]; + uint8_t* p; + tBTM_STATUS status = BTM_SUCCESS; + + if (sco_inx < BTM_MAX_SCO_LINKS && btm_cb.sco_cb.p_data_cb && + p_ccb->state == SCO_ST_CONNECTED) { + /* Ensure we have enough space in the buffer for the SCO and HCI headers */ + if (p_buf->offset < HCI_SCO_PREAMBLE_SIZE) { + BTM_TRACE_ERROR("BTM SCO - cannot send buffer, offset: %d", + p_buf->offset); + osi_free(p_buf); + status = BTM_ILLEGAL_VALUE; + } else /* write HCI header */ { - osi_free(p_buf); - - BTM_TRACE_WARNING ("BTM_WriteScoData, invalid sco index: %d at state [%d]", - sco_inx, btm_cb.sco_cb.sco_db[sco_inx].state); - status = BTM_UNKNOWN_ADDR; + /* Step back 3 bytes to add the headers */ + p_buf->offset -= HCI_SCO_PREAMBLE_SIZE; + /* Set the pointer to the beginning of the data */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + /* add HCI handle */ + UINT16_TO_STREAM(p, p_ccb->hci_handle); + /* only sent the first BTM_SCO_DATA_SIZE_MAX bytes data if more than max, + and set warning status */ + if (p_buf->len > BTM_SCO_DATA_SIZE_MAX) { + p_buf->len = BTM_SCO_DATA_SIZE_MAX; + status = BTM_SCO_BAD_LENGTH; + } + + UINT8_TO_STREAM(p, (uint8_t)p_buf->len); + p_buf->len += HCI_SCO_PREAMBLE_SIZE; + + fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf); + + btm_sco_check_send_pkts(sco_inx); } + } else { + osi_free(p_buf); - return (status); + BTM_TRACE_WARNING("BTM_WriteScoData, invalid sco index: %d at state [%d]", + sco_inx, btm_cb.sco_cb.sco_db[sco_inx].state); + status = BTM_UNKNOWN_ADDR; + } + return (status); } #else tBTM_STATUS BTM_WriteScoData(UNUSED_ATTR uint16_t sco_inx, - UNUSED_ATTR BT_HDR *p_buf) -{ - return (BTM_NO_RESOURCES); + UNUSED_ATTR BT_HDR* p_buf) { + return (BTM_NO_RESOURCES); } #endif -#if (BTM_MAX_SCO_LINKS>0) +#if (BTM_MAX_SCO_LINKS > 0) /******************************************************************************* * * Function btm_send_connect_request @@ -386,89 +354,76 @@ tBTM_STATUS BTM_WriteScoData(UNUSED_ATTR uint16_t sco_inx, * ******************************************************************************/ static tBTM_STATUS btm_send_connect_request(uint16_t acl_handle, - tBTM_ESCO_PARAMS *p_setup) -{ - uint16_t temp_pkt_types; - uint8_t xx; - tACL_CONN *p_acl; - - /* Send connect request depending on version of spec */ - if (!btm_cb.sco_cb.esco_supported) - { - btsnd_hcic_add_SCO_conn(acl_handle, BTM_ESCO_2_SCO(p_setup->packet_types)); - } - else - { - temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & - btm_cb.btm_sco_pkt_types_supported); - - /* OR in any exception packet types */ - temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | - (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); - - /* Finally, remove EDR eSCO if the remote device doesn't support it */ - /* UPF25: Only SCO was brought up in this case */ - btm_handle_to_acl_index(acl_handle); - xx = btm_handle_to_acl_index(acl_handle); - if (xx < MAX_L2CAP_LINKS) - { - p_acl = &btm_cb.acl_db[xx]; - if (!HCI_EDR_ESCO_2MPS_SUPPORTED(p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - { - - BTM_TRACE_WARNING("BTM Remote does not support 2-EDR eSCO"); - temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | - HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5); - } - if (!HCI_EDR_ESCO_3MPS_SUPPORTED(p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) - { - - BTM_TRACE_WARNING("BTM Remote does not support 3-EDR eSCO"); - temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | - HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5); - } - - /* Check to see if BR/EDR Secure Connections is being used - ** If so, we cannot use SCO-only packet types (HFP 1.7) - */ - if (BTM_BothEndsSupportSecureConnections(p_acl->remote_addr)) - { - temp_pkt_types &= ~(BTM_SCO_PKT_TYPE_MASK); - BTM_TRACE_DEBUG("%s: SCO Conn: pkt_types after removing SCO (0x%04x)", __func__, - temp_pkt_types); - - /* Return error if no packet types left */ - if (temp_pkt_types == 0) - { - BTM_TRACE_ERROR("%s: SCO Conn (BR/EDR SC): No packet types available", - __func__); - return (BTM_WRONG_MODE); - } - } - else - { - BTM_TRACE_DEBUG("%s: SCO Conn(BR/EDR SC):local or peer does not support BR/EDR SC", - __func__); - } + tBTM_ESCO_PARAMS* p_setup) { + uint16_t temp_pkt_types; + uint8_t xx; + tACL_CONN* p_acl; + + /* Send connect request depending on version of spec */ + if (!btm_cb.sco_cb.esco_supported) { + btsnd_hcic_add_SCO_conn(acl_handle, BTM_ESCO_2_SCO(p_setup->packet_types)); + } else { + temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & + btm_cb.btm_sco_pkt_types_supported); + + /* OR in any exception packet types */ + temp_pkt_types |= + ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | + (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); + + /* Finally, remove EDR eSCO if the remote device doesn't support it */ + /* UPF25: Only SCO was brought up in this case */ + btm_handle_to_acl_index(acl_handle); + xx = btm_handle_to_acl_index(acl_handle); + if (xx < MAX_L2CAP_LINKS) { + p_acl = &btm_cb.acl_db[xx]; + if (!HCI_EDR_ESCO_2MPS_SUPPORTED( + p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) { + BTM_TRACE_WARNING("BTM Remote does not support 2-EDR eSCO"); + temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 | + HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5); + } + if (!HCI_EDR_ESCO_3MPS_SUPPORTED( + p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) { + BTM_TRACE_WARNING("BTM Remote does not support 3-EDR eSCO"); + temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 | + HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5); + } + + /* Check to see if BR/EDR Secure Connections is being used + ** If so, we cannot use SCO-only packet types (HFP 1.7) + */ + if (BTM_BothEndsSupportSecureConnections(p_acl->remote_addr)) { + temp_pkt_types &= ~(BTM_SCO_PKT_TYPE_MASK); + BTM_TRACE_DEBUG("%s: SCO Conn: pkt_types after removing SCO (0x%04x)", + __func__, temp_pkt_types); + + /* Return error if no packet types left */ + if (temp_pkt_types == 0) { + BTM_TRACE_ERROR("%s: SCO Conn (BR/EDR SC): No packet types available", + __func__); + return (BTM_WRONG_MODE); } + } else { + BTM_TRACE_DEBUG( + "%s: SCO Conn(BR/EDR SC):local or peer does not support BR/EDR SC", + __func__); + } + } + BTM_TRACE_API( + " txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt " + "0x%04x", + p_setup->tx_bw, p_setup->rx_bw, p_setup->max_latency, + p_setup->voice_contfmt, p_setup->retrans_effort, temp_pkt_types); - BTM_TRACE_API(" txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt 0x%04x", - p_setup->tx_bw, p_setup->rx_bw, - p_setup->max_latency, p_setup->voice_contfmt, - p_setup->retrans_effort, temp_pkt_types); - - btsnd_hcic_setup_esco_conn(acl_handle, - p_setup->tx_bw, - p_setup->rx_bw, - p_setup->max_latency, - p_setup->voice_contfmt, - p_setup->retrans_effort, - temp_pkt_types); - p_setup->packet_types = temp_pkt_types; - } + btsnd_hcic_setup_esco_conn(acl_handle, p_setup->tx_bw, p_setup->rx_bw, + p_setup->max_latency, p_setup->voice_contfmt, + p_setup->retrans_effort, temp_pkt_types); + p_setup->packet_types = temp_pkt_types; + } - return (BTM_CMD_STARTED); + return (BTM_CMD_STARTED); } #endif @@ -482,9 +437,8 @@ static tBTM_STATUS btm_send_connect_request(uint16_t acl_handle, * Returns void * ******************************************************************************/ -void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb ) -{ - btm_cb.sco_cb.app_sco_ind_cb = sco_ind_cb; +void btm_set_sco_ind_cback(tBTM_SCO_IND_CBACK* sco_ind_cb) { + btm_cb.sco_cb.app_sco_ind_cb = sco_ind_cb; } /******************************************************************************* @@ -497,29 +451,28 @@ void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb ) * Returns void * ******************************************************************************/ -void btm_accept_sco_link(uint16_t sco_inx, tBTM_ESCO_PARAMS *p_setup, - tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p_sco; +void btm_accept_sco_link(uint16_t sco_inx, tBTM_ESCO_PARAMS* p_setup, + tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p_sco; - if (sco_inx >= BTM_MAX_SCO_LINKS) - { - BTM_TRACE_ERROR("btm_accept_sco_link: Invalid sco_inx(%d)", sco_inx); - return; - } + if (sco_inx >= BTM_MAX_SCO_LINKS) { + BTM_TRACE_ERROR("btm_accept_sco_link: Invalid sco_inx(%d)", sco_inx); + return; + } - /* Link role is ignored in for this message */ - p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; - p_sco->p_conn_cb = p_conn_cb; - p_sco->p_disc_cb = p_disc_cb; - p_sco->esco.data.link_type = BTM_LINK_TYPE_ESCO; /* Accept with all supported types */ + /* Link role is ignored in for this message */ + p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; + p_sco->p_conn_cb = p_conn_cb; + p_sco->p_disc_cb = p_disc_cb; + p_sco->esco.data.link_type = + BTM_LINK_TYPE_ESCO; /* Accept with all supported types */ - BTM_TRACE_DEBUG("TCS accept SCO: Packet Types 0x%04x", p_setup->packet_types); + BTM_TRACE_DEBUG("TCS accept SCO: Packet Types 0x%04x", p_setup->packet_types); - btm_esco_conn_rsp(sco_inx, HCI_SUCCESS, p_sco->esco.data.bd_addr, p_setup); + btm_esco_conn_rsp(sco_inx, HCI_SUCCESS, p_sco->esco.data.bd_addr, p_setup); #else - btm_reject_sco_link(sco_inx); + btm_reject_sco_link(sco_inx); #endif } @@ -533,10 +486,9 @@ void btm_accept_sco_link(uint16_t sco_inx, tBTM_ESCO_PARAMS *p_setup, * Returns void * ******************************************************************************/ -void btm_reject_sco_link( uint16_t sco_inx ) -{ - btm_esco_conn_rsp(sco_inx, HCI_ERR_HOST_REJECT_RESOURCES, - btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, NULL); +void btm_reject_sco_link(uint16_t sco_inx) { + btm_esco_conn_rsp(sco_inx, HCI_ERR_HOST_REJECT_RESOURCES, + btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, NULL); } /******************************************************************************* @@ -559,161 +511,153 @@ void btm_reject_sco_link( uint16_t sco_inx ) * with the sco index used for the connection. * ******************************************************************************/ -tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, bool is_orig, uint16_t pkt_types, - uint16_t *p_sco_inx, tBTM_SCO_CB *p_conn_cb, - tBTM_SCO_CB *p_disc_cb) -{ +tBTM_STATUS BTM_CreateSco(BD_ADDR remote_bda, bool is_orig, uint16_t pkt_types, + uint16_t* p_sco_inx, tBTM_SCO_CB* p_conn_cb, + tBTM_SCO_CB* p_disc_cb) { #if (BTM_MAX_SCO_LINKS > 0) - tBTM_ESCO_PARAMS *p_setup; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; - uint16_t acl_handle = 0; - uint16_t temp_pkt_types; - tACL_CONN *p_acl; + tBTM_ESCO_PARAMS* p_setup; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; + uint16_t acl_handle = 0; + uint16_t temp_pkt_types; + tACL_CONN* p_acl; #if (BTM_SCO_WAKE_PARKED_LINK == TRUE) - tBTM_PM_PWR_MD pm; - tBTM_PM_STATE state; + tBTM_PM_PWR_MD pm; + tBTM_PM_STATE state; #else - uint8_t mode; + uint8_t mode; #endif // BTM_SCO_WAKE_PARKED_LINK - *p_sco_inx = BTM_INVALID_SCO_INDEX; + *p_sco_inx = BTM_INVALID_SCO_INDEX; - /* If originating, ensure that there is an ACL connection to the BD Address */ - if (is_orig) - { - if ((!remote_bda) || ((acl_handle = BTM_GetHCIConnHandle (remote_bda, BT_TRANSPORT_BR_EDR)) == 0xFFFF)) - return (BTM_UNKNOWN_ADDR); - } + /* If originating, ensure that there is an ACL connection to the BD Address */ + if (is_orig) { + if ((!remote_bda) || ((acl_handle = BTM_GetHCIConnHandle( + remote_bda, BT_TRANSPORT_BR_EDR)) == 0xFFFF)) + return (BTM_UNKNOWN_ADDR); + } - if (remote_bda) - { - /* If any SCO is being established to the remote BD address, refuse this */ - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (((p->state == SCO_ST_CONNECTING) || (p->state == SCO_ST_LISTENING) - || (p->state == SCO_ST_PEND_UNPARK)) - && (!memcmp (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN))) - { - return (BTM_BUSY); - } - } + if (remote_bda) { + /* If any SCO is being established to the remote BD address, refuse this */ + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (((p->state == SCO_ST_CONNECTING) || (p->state == SCO_ST_LISTENING) || + (p->state == SCO_ST_PEND_UNPARK)) && + (!memcmp(p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN))) { + return (BTM_BUSY); + } } - else - { - /* Support only 1 wildcard BD address at a time */ - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state == SCO_ST_LISTENING) && (!p->rem_bd_known)) - return (BTM_BUSY); - } + } else { + /* Support only 1 wildcard BD address at a time */ + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state == SCO_ST_LISTENING) && (!p->rem_bd_known)) + return (BTM_BUSY); } - - /* Now, try to find an unused control block, and kick off the SCO establishment */ - for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (p->state == SCO_ST_UNUSED) - { - if (remote_bda) - { - if (is_orig) - { - /* can not create SCO link if in park mode */ + } + + /* Now, try to find an unused control block, and kick off the SCO + * establishment */ + for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; + xx++, p++) { + if (p->state == SCO_ST_UNUSED) { + if (remote_bda) { + if (is_orig) { +/* can not create SCO link if in park mode */ #if (BTM_SCO_WAKE_PARKED_LINK == TRUE) - if ((btm_read_power_mode_state(p->esco.data.bd_addr, &state) == BTM_SUCCESS)) - { - if (state == BTM_PM_ST_SNIFF || state == BTM_PM_ST_PARK || - state == BTM_PM_ST_PENDING) - { - BTM_TRACE_DEBUG("%s In sniff, park or pend mode: %d", __func__, state); - memset( (void*)&pm, 0, sizeof(pm)); - pm.mode = BTM_PM_MD_ACTIVE; - BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, remote_bda, &pm); - p->state = SCO_ST_PEND_UNPARK; - } - } -#else // BTM_SCO_WAKE_PARKED_LINK - if( (BTM_ReadPowerMode(remote_bda, &mode) == BTM_SUCCESS) && (mode == BTM_PM_MD_PARK) ) - return (BTM_WRONG_MODE); -#endif // BTM_SCO_WAKE_PARKED_LINK - } - memcpy (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN); - p->rem_bd_known = true; - } - else - p->rem_bd_known = false; - - /* Link role is ignored in for this message */ - if (pkt_types == BTM_IGNORE_SCO_PKT_TYPE) - pkt_types = btm_cb.sco_cb.def_esco_parms.packet_types; - - p_setup = &p->esco.setup; - *p_setup = btm_cb.sco_cb.def_esco_parms; - p_setup->packet_types = (btm_cb.sco_cb.desired_sco_mode == BTM_LINK_TYPE_SCO) - ? (pkt_types & BTM_SCO_LINK_ONLY_MASK) : pkt_types; - - temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & - btm_cb.btm_sco_pkt_types_supported); - - /* OR in any exception packet types */ - if (controller_get_interface()->get_bt_version()->hci_version >= HCI_PROTO_VERSION_2_0) - { - temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | - (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); - } - else /* Only using SCO packet types; turn off EDR also */ - { - temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK; - } - - p_setup->packet_types = temp_pkt_types; - p->p_conn_cb = p_conn_cb; - p->p_disc_cb = p_disc_cb; - p->hci_handle = BTM_INVALID_HCI_HANDLE; - p->is_orig = is_orig; - - if( p->state != SCO_ST_PEND_UNPARK ) - { - if (is_orig) - { - /* If role change is in progress, do not proceed with SCO setup - * Wait till role change is complete */ - p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); - if (p_acl && p_acl->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) - { - BTM_TRACE_API("Role Change is in progress for ACL handle 0x%04x",acl_handle); - p->state = SCO_ST_PEND_ROLECHANGE; - - } - } + if ((btm_read_power_mode_state(p->esco.data.bd_addr, &state) == + BTM_SUCCESS)) { + if (state == BTM_PM_ST_SNIFF || state == BTM_PM_ST_PARK || + state == BTM_PM_ST_PENDING) { + BTM_TRACE_DEBUG("%s In sniff, park or pend mode: %d", __func__, + state); + memset((void*)&pm, 0, sizeof(pm)); + pm.mode = BTM_PM_MD_ACTIVE; + BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, remote_bda, &pm); + p->state = SCO_ST_PEND_UNPARK; } + } +#else // BTM_SCO_WAKE_PARKED_LINK + if ((BTM_ReadPowerMode(remote_bda, &mode) == BTM_SUCCESS) && + (mode == BTM_PM_MD_PARK)) + return (BTM_WRONG_MODE); +#endif // BTM_SCO_WAKE_PARKED_LINK + } + memcpy(p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN); + p->rem_bd_known = true; + } else + p->rem_bd_known = false; + + /* Link role is ignored in for this message */ + if (pkt_types == BTM_IGNORE_SCO_PKT_TYPE) + pkt_types = btm_cb.sco_cb.def_esco_parms.packet_types; + + p_setup = &p->esco.setup; + *p_setup = btm_cb.sco_cb.def_esco_parms; + p_setup->packet_types = + (btm_cb.sco_cb.desired_sco_mode == BTM_LINK_TYPE_SCO) + ? (pkt_types & BTM_SCO_LINK_ONLY_MASK) + : pkt_types; + + temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & + btm_cb.btm_sco_pkt_types_supported); + + /* OR in any exception packet types */ + if (controller_get_interface()->get_bt_version()->hci_version >= + HCI_PROTO_VERSION_2_0) { + temp_pkt_types |= + ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | + (btm_cb.btm_sco_pkt_types_supported & + BTM_SCO_EXCEPTION_PKTS_MASK)); + } else /* Only using SCO packet types; turn off EDR also */ + { + temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK; + } + + p_setup->packet_types = temp_pkt_types; + p->p_conn_cb = p_conn_cb; + p->p_disc_cb = p_disc_cb; + p->hci_handle = BTM_INVALID_HCI_HANDLE; + p->is_orig = is_orig; + + if (p->state != SCO_ST_PEND_UNPARK) { + if (is_orig) { + /* If role change is in progress, do not proceed with SCO setup + * Wait till role change is complete */ + p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); + if (p_acl && p_acl->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) { + BTM_TRACE_API("Role Change is in progress for ACL handle 0x%04x", + acl_handle); + p->state = SCO_ST_PEND_ROLECHANGE; + } + } + } - if( p->state != SCO_ST_PEND_UNPARK && p->state != SCO_ST_PEND_ROLECHANGE ) - { - if (is_orig) - { - BTM_TRACE_API("BTM_CreateSco -> (e)SCO Link for ACL handle 0x%04x, Desired Type %d", - acl_handle, btm_cb.sco_cb.desired_sco_mode); + if (p->state != SCO_ST_PEND_UNPARK && + p->state != SCO_ST_PEND_ROLECHANGE) { + if (is_orig) { + BTM_TRACE_API( + "BTM_CreateSco -> (e)SCO Link for ACL handle 0x%04x, Desired " + "Type %d", + acl_handle, btm_cb.sco_cb.desired_sco_mode); - if ((btm_send_connect_request(acl_handle, p_setup)) != BTM_CMD_STARTED) - return (BTM_NO_RESOURCES); + if ((btm_send_connect_request(acl_handle, p_setup)) != + BTM_CMD_STARTED) + return (BTM_NO_RESOURCES); - p->state = SCO_ST_CONNECTING; - } - else - p->state = SCO_ST_LISTENING; - } + p->state = SCO_ST_CONNECTING; + } else + p->state = SCO_ST_LISTENING; + } - *p_sco_inx = xx; + *p_sco_inx = xx; - return (BTM_CMD_STARTED); - } + return (BTM_CMD_STARTED); } + } #endif - /* If here, all SCO blocks in use */ - return (BTM_NO_RESOURCES); + /* If here, all SCO blocks in use */ + return (BTM_NO_RESOURCES); } #if (BTM_SCO_WAKE_PARKED_LINK == TRUE) @@ -728,26 +672,28 @@ tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, bool is_orig, uint16_t pkt_typ * Returns void * ******************************************************************************/ -void btm_sco_chk_pend_unpark (uint8_t hci_status, uint16_t hci_handle) -{ -#if (BTM_MAX_SCO_LINKS>0) - uint16_t xx; - uint16_t acl_handle; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state == SCO_ST_PEND_UNPARK) && - ((acl_handle = BTM_GetHCIConnHandle (p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle)) +void btm_sco_chk_pend_unpark(uint8_t hci_status, uint16_t hci_handle) { +#if (BTM_MAX_SCO_LINKS > 0) + uint16_t xx; + uint16_t acl_handle; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; - { - BTM_TRACE_API("btm_sco_chk_pend_unpark -> (e)SCO Link for ACL handle 0x%04x, Desired Type %d, hci_status 0x%02x", - acl_handle, btm_cb.sco_cb.desired_sco_mode, hci_status); + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state == SCO_ST_PEND_UNPARK) && + ((acl_handle = BTM_GetHCIConnHandle( + p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle)) - if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == BTM_CMD_STARTED) - p->state = SCO_ST_CONNECTING; - } + { + BTM_TRACE_API( + "btm_sco_chk_pend_unpark -> (e)SCO Link for ACL handle 0x%04x, " + "Desired Type %d, hci_status 0x%02x", + acl_handle, btm_cb.sco_cb.desired_sco_mode, hci_status); + + if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == + BTM_CMD_STARTED) + p->state = SCO_ST_CONNECTING; } + } #endif // BTM_MAX_SCO_LINKS } #endif // BTM_SCO_WAKE_PARKED_LINK @@ -763,25 +709,27 @@ void btm_sco_chk_pend_unpark (uint8_t hci_status, uint16_t hci_handle) * Returns void * ******************************************************************************/ -void btm_sco_chk_pend_rolechange (uint16_t hci_handle) -{ -#if (BTM_MAX_SCO_LINKS>0) - uint16_t xx; - uint16_t acl_handle; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state == SCO_ST_PEND_ROLECHANGE) && - ((acl_handle = BTM_GetHCIConnHandle (p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle)) +void btm_sco_chk_pend_rolechange(uint16_t hci_handle) { +#if (BTM_MAX_SCO_LINKS > 0) + uint16_t xx; + uint16_t acl_handle; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; - { - BTM_TRACE_API("btm_sco_chk_pend_rolechange -> (e)SCO Link for ACL handle 0x%04x", acl_handle); + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state == SCO_ST_PEND_ROLECHANGE) && + ((acl_handle = BTM_GetHCIConnHandle( + p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle)) - if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == BTM_CMD_STARTED) - p->state = SCO_ST_CONNECTING; - } + { + BTM_TRACE_API( + "btm_sco_chk_pend_rolechange -> (e)SCO Link for ACL handle 0x%04x", + acl_handle); + + if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == + BTM_CMD_STARTED) + p->state = SCO_ST_CONNECTING; } + } #endif } @@ -796,24 +744,23 @@ void btm_sco_chk_pend_rolechange (uint16_t hci_handle) * Returns void * ******************************************************************************/ -void btm_sco_disc_chk_pend_for_modechange (uint16_t hci_handle) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; +void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; - BTM_TRACE_DEBUG("%s: hci_handle 0x%04x, p->state 0x%02x", __func__, - hci_handle, p->state); + BTM_TRACE_DEBUG("%s: hci_handle 0x%04x, p->state 0x%02x", __func__, + hci_handle, p->state); - for (uint16_t xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state == SCO_ST_PEND_MODECHANGE) && - (BTM_GetHCIConnHandle (p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle) + for (uint16_t xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state == SCO_ST_PEND_MODECHANGE) && + (BTM_GetHCIConnHandle(p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == + hci_handle) - { - BTM_TRACE_DEBUG("%s: SCO Link handle 0x%04x", __func__, p->hci_handle); - BTM_RemoveSco(xx); - } + { + BTM_TRACE_DEBUG("%s: SCO Link handle 0x%04x", __func__, p->hci_handle); + BTM_RemoveSco(xx); } + } #endif } @@ -827,92 +774,87 @@ void btm_sco_disc_chk_pend_for_modechange (uint16_t hci_handle) * Returns void * ******************************************************************************/ -void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, uint8_t link_type) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CB *p_sco = &btm_cb.sco_cb; - tSCO_CONN *p = &p_sco->sco_db[0]; - uint16_t xx; - tBTM_ESCO_CONN_REQ_EVT_DATA evt_data; - - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - /* - * If the sco state is in the SCO_ST_CONNECTING state, we still need - * to return accept sco to avoid race conditon for sco creation - */ - int rem_bd_matches = p->rem_bd_known && - !memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN); - if (((p->state == SCO_ST_CONNECTING) && rem_bd_matches) || - ((p->state == SCO_ST_LISTENING) && (rem_bd_matches || !p->rem_bd_known))) +void btm_sco_conn_req(BD_ADDR bda, DEV_CLASS dev_class, uint8_t link_type) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CB* p_sco = &btm_cb.sco_cb; + tSCO_CONN* p = &p_sco->sco_db[0]; + uint16_t xx; + tBTM_ESCO_CONN_REQ_EVT_DATA evt_data; + + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + /* + * If the sco state is in the SCO_ST_CONNECTING state, we still need + * to return accept sco to avoid race conditon for sco creation + */ + int rem_bd_matches = + p->rem_bd_known && !memcmp(p->esco.data.bd_addr, bda, BD_ADDR_LEN); + if (((p->state == SCO_ST_CONNECTING) && rem_bd_matches) || + ((p->state == SCO_ST_LISTENING) && + (rem_bd_matches || !p->rem_bd_known))) { + /* If this guy was a wildcard, he is not one any more */ + p->rem_bd_known = true; + p->esco.data.link_type = link_type; + p->state = SCO_ST_W4_CONN_RSP; + memcpy(p->esco.data.bd_addr, bda, BD_ADDR_LEN); + + /* If no callback, auto-accept the connection if packet types match */ + if (!p->esco.p_esco_cback) { + /* If requesting eSCO reject if default parameters are SCO only */ + if ((link_type == BTM_LINK_TYPE_ESCO && + !(p_sco->def_esco_parms.packet_types & BTM_ESCO_LINK_ONLY_MASK) && + ((p_sco->def_esco_parms.packet_types & + BTM_SCO_EXCEPTION_PKTS_MASK) == BTM_SCO_EXCEPTION_PKTS_MASK)) + + /* Reject request if SCO is desired but no SCO packets delected */ + || + (link_type == BTM_LINK_TYPE_SCO && + !(p_sco->def_esco_parms.packet_types & BTM_SCO_LINK_ONLY_MASK))) { + btm_esco_conn_rsp(xx, HCI_ERR_HOST_REJECT_RESOURCES, bda, NULL); + } else /* Accept the request */ { - /* If this guy was a wildcard, he is not one any more */ - p->rem_bd_known = true; - p->esco.data.link_type = link_type; - p->state = SCO_ST_W4_CONN_RSP; - memcpy (p->esco.data.bd_addr, bda, BD_ADDR_LEN); - - /* If no callback, auto-accept the connection if packet types match */ - if (!p->esco.p_esco_cback) - { - /* If requesting eSCO reject if default parameters are SCO only */ - if ((link_type == BTM_LINK_TYPE_ESCO - && !(p_sco->def_esco_parms.packet_types & BTM_ESCO_LINK_ONLY_MASK) - && ((p_sco->def_esco_parms.packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) - == BTM_SCO_EXCEPTION_PKTS_MASK)) - - /* Reject request if SCO is desired but no SCO packets delected */ - || (link_type == BTM_LINK_TYPE_SCO - && !(p_sco->def_esco_parms.packet_types & BTM_SCO_LINK_ONLY_MASK))) - { - btm_esco_conn_rsp(xx, HCI_ERR_HOST_REJECT_RESOURCES, bda, NULL); - } - else /* Accept the request */ - { - btm_esco_conn_rsp(xx, HCI_SUCCESS, bda, NULL); - } - } - else /* Notify upper layer of connect indication */ - { - memcpy(evt_data.bd_addr, bda, BD_ADDR_LEN); - memcpy(evt_data.dev_class, dev_class, DEV_CLASS_LEN); - evt_data.link_type = link_type; - evt_data.sco_inx = xx; - p->esco.p_esco_cback(BTM_ESCO_CONN_REQ_EVT, (tBTM_ESCO_EVT_DATA *)&evt_data); - } - - return; + btm_esco_conn_rsp(xx, HCI_SUCCESS, bda, NULL); } + } else /* Notify upper layer of connect indication */ + { + memcpy(evt_data.bd_addr, bda, BD_ADDR_LEN); + memcpy(evt_data.dev_class, dev_class, DEV_CLASS_LEN); + evt_data.link_type = link_type; + evt_data.sco_inx = xx; + p->esco.p_esco_cback(BTM_ESCO_CONN_REQ_EVT, + (tBTM_ESCO_EVT_DATA*)&evt_data); + } + + return; } - - /* TCS usage */ - if (btm_cb.sco_cb.app_sco_ind_cb) - { - /* Now, try to find an unused control block */ - for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (p->state == SCO_ST_UNUSED) - { - p->is_orig = false; - p->state = SCO_ST_LISTENING; - - p->esco.data.link_type = link_type; - memcpy (p->esco.data.bd_addr, bda, BD_ADDR_LEN); - p->rem_bd_known = true; - break; - } - } - if( xx < BTM_MAX_SCO_LINKS) - { - btm_cb.sco_cb.app_sco_ind_cb(xx); - return; - } + } + + /* TCS usage */ + if (btm_cb.sco_cb.app_sco_ind_cb) { + /* Now, try to find an unused control block */ + for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; + xx++, p++) { + if (p->state == SCO_ST_UNUSED) { + p->is_orig = false; + p->state = SCO_ST_LISTENING; + + p->esco.data.link_type = link_type; + memcpy(p->esco.data.bd_addr, bda, BD_ADDR_LEN); + p->rem_bd_known = true; + break; + } } + if (xx < BTM_MAX_SCO_LINKS) { + btm_cb.sco_cb.app_sco_ind_cb(xx); + return; + } + } #endif - /* If here, no one wants the SCO connection. Reject it */ - BTM_TRACE_WARNING("btm_sco_conn_req: No one wants this SCO connection; rejecting it"); - btm_esco_conn_rsp(BTM_MAX_SCO_LINKS, HCI_ERR_HOST_REJECT_RESOURCES, bda, NULL); + /* If here, no one wants the SCO connection. Reject it */ + BTM_TRACE_WARNING( + "btm_sco_conn_req: No one wants this SCO connection; rejecting it"); + btm_esco_conn_rsp(BTM_MAX_SCO_LINKS, HCI_ERR_HOST_REJECT_RESOURCES, bda, + NULL); } /******************************************************************************* @@ -925,94 +867,77 @@ void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, uint8_t link_type) * Returns void * ******************************************************************************/ -void btm_sco_connected (uint8_t hci_status, BD_ADDR bda, uint16_t hci_handle, - tBTM_ESCO_DATA *p_esco_data) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; - bool spt = false; - tBTM_CHG_ESCO_PARAMS parms; +void btm_sco_connected(uint8_t hci_status, BD_ADDR bda, uint16_t hci_handle, + tBTM_ESCO_DATA* p_esco_data) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; + bool spt = false; + tBTM_CHG_ESCO_PARAMS parms; #endif - btm_cb.sco_cb.sco_disc_reason = hci_status; - -#if (BTM_MAX_SCO_LINKS>0) - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (((p->state == SCO_ST_CONNECTING) || - (p->state == SCO_ST_LISTENING) || - (p->state == SCO_ST_W4_CONN_RSP)) - && (p->rem_bd_known) - && (!bda || !memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN))) - { - if (hci_status != HCI_SUCCESS) - { - /* Report the error if originator, otherwise remain in Listen mode */ - if (p->is_orig) - { - /* If role switch is pending, we need try again after role switch is complete */ - if(hci_status == HCI_ERR_ROLE_SWITCH_PENDING) - { - BTM_TRACE_API("Role Change pending for HCI handle 0x%04x",hci_handle); - p->state = SCO_ST_PEND_ROLECHANGE; - } - /* avoid calling disconnect callback because of sco creation race */ - else if (hci_status != HCI_ERR_LMP_ERR_TRANS_COLLISION) - { - p->state = SCO_ST_UNUSED; - (*p->p_disc_cb)(xx); - } - } - else - { - /* Notify the upper layer that incoming sco connection has failed. */ - if (p->state == SCO_ST_CONNECTING) - { - p->state = SCO_ST_UNUSED; - (*p->p_disc_cb)(xx); - } - else - p->state = SCO_ST_LISTENING; - } - - return; - } + btm_cb.sco_cb.sco_disc_reason = hci_status; - if (p->state == SCO_ST_LISTENING) - spt = true; +#if (BTM_MAX_SCO_LINKS > 0) + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (((p->state == SCO_ST_CONNECTING) || (p->state == SCO_ST_LISTENING) || + (p->state == SCO_ST_W4_CONN_RSP)) && + (p->rem_bd_known) && + (!bda || !memcmp(p->esco.data.bd_addr, bda, BD_ADDR_LEN))) { + if (hci_status != HCI_SUCCESS) { + /* Report the error if originator, otherwise remain in Listen mode */ + if (p->is_orig) { + /* If role switch is pending, we need try again after role switch is + * complete */ + if (hci_status == HCI_ERR_ROLE_SWITCH_PENDING) { + BTM_TRACE_API("Role Change pending for HCI handle 0x%04x", + hci_handle); + p->state = SCO_ST_PEND_ROLECHANGE; + } + /* avoid calling disconnect callback because of sco creation race */ + else if (hci_status != HCI_ERR_LMP_ERR_TRANS_COLLISION) { + p->state = SCO_ST_UNUSED; + (*p->p_disc_cb)(xx); + } + } else { + /* Notify the upper layer that incoming sco connection has failed. */ + if (p->state == SCO_ST_CONNECTING) { + p->state = SCO_ST_UNUSED; + (*p->p_disc_cb)(xx); + } else + p->state = SCO_ST_LISTENING; + } - p->state = SCO_ST_CONNECTED; - p->hci_handle = hci_handle; + return; + } - if (!btm_cb.sco_cb.esco_supported) - { - p->esco.data.link_type = BTM_LINK_TYPE_SCO; - if (spt) - { - parms.packet_types = p->esco.setup.packet_types; - /* Keep the other parameters the same for SCO */ - parms.max_latency = p->esco.setup.max_latency; - parms.retrans_effort = p->esco.setup.retrans_effort; + if (p->state == SCO_ST_LISTENING) spt = true; - BTM_ChangeEScoLinkParms(xx, &parms); - } - } - else - { - if (p_esco_data) - p->esco.data = *p_esco_data; - } + p->state = SCO_ST_CONNECTED; + p->hci_handle = hci_handle; - (*p->p_conn_cb)(xx); + if (!btm_cb.sco_cb.esco_supported) { + p->esco.data.link_type = BTM_LINK_TYPE_SCO; + if (spt) { + parms.packet_types = p->esco.setup.packet_types; + /* Keep the other parameters the same for SCO */ + parms.max_latency = p->esco.setup.max_latency; + parms.retrans_effort = p->esco.setup.retrans_effort; - return; + BTM_ChangeEScoLinkParms(xx, &parms); } + } else { + if (p_esco_data) p->esco.data = *p_esco_data; + } + + (*p->p_conn_cb)(xx); + + return; } + } #endif } - /******************************************************************************* * * Function btm_find_scb_by_handle @@ -1024,21 +949,18 @@ void btm_sco_connected (uint8_t hci_status, BD_ADDR bda, uint16_t hci_handle, * no match. * ******************************************************************************/ -uint16_t btm_find_scb_by_handle (uint16_t handle) -{ - int xx; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; +uint16_t btm_find_scb_by_handle(uint16_t handle) { + int xx; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state == SCO_ST_CONNECTED) && (p->hci_handle == handle)) - { - return (xx); - } + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state == SCO_ST_CONNECTED) && (p->hci_handle == handle)) { + return (xx); } + } - /* If here, no match found */ - return (xx); + /* If here, no match found */ + return (xx); } /******************************************************************************* @@ -1050,45 +972,44 @@ uint16_t btm_find_scb_by_handle (uint16_t handle) * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_RemoveSco (uint16_t sco_inx) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[sco_inx]; - uint16_t tempstate; - tBTM_PM_STATE state = BTM_PM_ST_INVALID; - - BTM_TRACE_DEBUG("%s", __func__); +tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx]; + uint16_t tempstate; + tBTM_PM_STATE state = BTM_PM_ST_INVALID; - /* Validity check */ - if ((sco_inx >= BTM_MAX_SCO_LINKS) || (p->state == SCO_ST_UNUSED)) - return (BTM_UNKNOWN_ADDR); + BTM_TRACE_DEBUG("%s", __func__); - /* If no HCI handle, simply drop the connection and return */ - if (p->hci_handle == BTM_INVALID_HCI_HANDLE || p->state == SCO_ST_PEND_UNPARK) - { - p->hci_handle = BTM_INVALID_HCI_HANDLE; - p->state = SCO_ST_UNUSED; - p->esco.p_esco_cback = NULL; /* Deregister the eSCO event callback */ - return (BTM_SUCCESS); - } + /* Validity check */ + if ((sco_inx >= BTM_MAX_SCO_LINKS) || (p->state == SCO_ST_UNUSED)) + return (BTM_UNKNOWN_ADDR); - if ((btm_read_power_mode_state(p->esco.data.bd_addr, &state) == BTM_SUCCESS) - && state == BTM_PM_ST_PENDING) - { - BTM_TRACE_DEBUG("%s: BTM_PM_ST_PENDING for ACL mapped with SCO Link 0x%04x", - __func__, p->hci_handle); - p->state = SCO_ST_PEND_MODECHANGE; - return (BTM_CMD_STARTED); - } + /* If no HCI handle, simply drop the connection and return */ + if (p->hci_handle == BTM_INVALID_HCI_HANDLE || + p->state == SCO_ST_PEND_UNPARK) { + p->hci_handle = BTM_INVALID_HCI_HANDLE; + p->state = SCO_ST_UNUSED; + p->esco.p_esco_cback = NULL; /* Deregister the eSCO event callback */ + return (BTM_SUCCESS); + } + + if ((btm_read_power_mode_state(p->esco.data.bd_addr, &state) == + BTM_SUCCESS) && + state == BTM_PM_ST_PENDING) { + BTM_TRACE_DEBUG("%s: BTM_PM_ST_PENDING for ACL mapped with SCO Link 0x%04x", + __func__, p->hci_handle); + p->state = SCO_ST_PEND_MODECHANGE; + return (BTM_CMD_STARTED); + } - tempstate = p->state; - p->state = SCO_ST_DISCONNECTING; + tempstate = p->state; + p->state = SCO_ST_DISCONNECTING; - btsnd_hcic_disconnect(p->hci_handle, HCI_ERR_PEER_USER); + btsnd_hcic_disconnect(p->hci_handle, HCI_ERR_PEER_USER); - return (BTM_CMD_STARTED); + return (BTM_CMD_STARTED); #else - return (BTM_NO_RESOURCES); + return (BTM_NO_RESOURCES); #endif } @@ -1102,19 +1023,16 @@ tBTM_STATUS BTM_RemoveSco (uint16_t sco_inx) * Returns void * ******************************************************************************/ -void btm_remove_sco_links (BD_ADDR bda) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; +void btm_remove_sco_links(BD_ADDR bda) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (p->rem_bd_known && (!memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN))) - { - BTM_RemoveSco(xx); - } + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (p->rem_bd_known && (!memcmp(p->esco.data.bd_addr, bda, BD_ADDR_LEN))) { + BTM_RemoveSco(xx); } + } #endif } @@ -1128,36 +1046,33 @@ void btm_remove_sco_links (BD_ADDR bda) * Returns void * ******************************************************************************/ -void btm_sco_removed (uint16_t hci_handle, uint8_t reason) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; +void btm_sco_removed(uint16_t hci_handle, uint8_t reason) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; #endif - btm_cb.sco_cb.sco_disc_reason = reason; - -#if (BTM_MAX_SCO_LINKS>0) - p = &btm_cb.sco_cb.sco_db[0]; - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((p->state != SCO_ST_UNUSED) && (p->state != SCO_ST_LISTENING) && (p->hci_handle == hci_handle)) - { - btm_sco_flush_sco_data(xx); + btm_cb.sco_cb.sco_disc_reason = reason; - p->state = SCO_ST_UNUSED; - p->hci_handle = BTM_INVALID_HCI_HANDLE; - p->rem_bd_known = false; - p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */ - (*p->p_disc_cb)(xx); - - return; - } +#if (BTM_MAX_SCO_LINKS > 0) + p = &btm_cb.sco_cb.sco_db[0]; + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((p->state != SCO_ST_UNUSED) && (p->state != SCO_ST_LISTENING) && + (p->hci_handle == hci_handle)) { + btm_sco_flush_sco_data(xx); + + p->state = SCO_ST_UNUSED; + p->hci_handle = BTM_INVALID_HCI_HANDLE; + p->rem_bd_known = false; + p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */ + (*p->p_disc_cb)(xx); + + return; } + } #endif } - /******************************************************************************* * * Function btm_sco_acl_removed @@ -1171,30 +1086,26 @@ void btm_sco_removed (uint16_t hci_handle, uint8_t reason) * Returns void * ******************************************************************************/ -void btm_sco_acl_removed (BD_ADDR bda) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; +void btm_sco_acl_removed(BD_ADDR bda) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (p->state != SCO_ST_UNUSED) - { - if ((!bda) || (!memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN) && p->rem_bd_known)) - { - btm_sco_flush_sco_data(xx); + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (p->state != SCO_ST_UNUSED) { + if ((!bda) || (!memcmp(p->esco.data.bd_addr, bda, BD_ADDR_LEN) && + p->rem_bd_known)) { + btm_sco_flush_sco_data(xx); - p->state = SCO_ST_UNUSED; - p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */ - (*p->p_disc_cb)(xx); - } - } + p->state = SCO_ST_UNUSED; + p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */ + (*p->p_disc_cb)(xx); + } } + } #endif } - /******************************************************************************* * * Function BTM_SetScoPacketTypes @@ -1219,30 +1130,27 @@ void btm_sco_acl_removed (BD_ADDR bda) * Returns status of the operation * ******************************************************************************/ -tBTM_STATUS BTM_SetScoPacketTypes (uint16_t sco_inx, uint16_t pkt_types) -{ -#if (BTM_MAX_SCO_LINKS>0) - tBTM_CHG_ESCO_PARAMS parms; - tSCO_CONN *p; +tBTM_STATUS BTM_SetScoPacketTypes(uint16_t sco_inx, uint16_t pkt_types) { +#if (BTM_MAX_SCO_LINKS > 0) + tBTM_CHG_ESCO_PARAMS parms; + tSCO_CONN* p; - /* Validity check */ - if (sco_inx >= BTM_MAX_SCO_LINKS) - return (BTM_UNKNOWN_ADDR); + /* Validity check */ + if (sco_inx >= BTM_MAX_SCO_LINKS) return (BTM_UNKNOWN_ADDR); - p = &btm_cb.sco_cb.sco_db[sco_inx]; - parms.packet_types = pkt_types; + p = &btm_cb.sco_cb.sco_db[sco_inx]; + parms.packet_types = pkt_types; - /* Keep the other parameters the same for SCO */ - parms.max_latency = p->esco.setup.max_latency; - parms.retrans_effort = p->esco.setup.retrans_effort; + /* Keep the other parameters the same for SCO */ + parms.max_latency = p->esco.setup.max_latency; + parms.retrans_effort = p->esco.setup.retrans_effort; - return (BTM_ChangeEScoLinkParms(sco_inx, &parms)); + return (BTM_ChangeEScoLinkParms(sco_inx, &parms)); #else - return (BTM_UNKNOWN_ADDR); + return (BTM_UNKNOWN_ADDR); #endif } - /******************************************************************************* * * Function BTM_ReadScoPacketTypes @@ -1264,18 +1172,17 @@ tBTM_STATUS BTM_SetScoPacketTypes (uint16_t sco_inx, uint16_t pkt_types) * BTM_SCO_PKT_TYPES_MASK_NO_3_EV5 * ******************************************************************************/ -uint16_t BTM_ReadScoPacketTypes (uint16_t sco_inx) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[sco_inx]; - - /* Validity check */ - if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED)) - return (p->esco.setup.packet_types); - else - return (0); -#else +uint16_t BTM_ReadScoPacketTypes(uint16_t sco_inx) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx]; + + /* Validity check */ + if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED)) + return (p->esco.setup.packet_types); + else return (0); +#else + return (0); #endif } @@ -1290,11 +1197,10 @@ uint16_t BTM_ReadScoPacketTypes (uint16_t sco_inx) * Returns HCI reason or BTM_INVALID_SCO_DISC_REASON if not set. * ******************************************************************************/ -uint16_t BTM_ReadScoDiscReason (void) -{ - uint16_t res = btm_cb.sco_cb.sco_disc_reason; - btm_cb.sco_cb.sco_disc_reason = BTM_INVALID_SCO_DISC_REASON; - return (res); +uint16_t BTM_ReadScoDiscReason(void) { + uint16_t res = btm_cb.sco_cb.sco_disc_reason; + btm_cb.sco_cb.sco_disc_reason = BTM_INVALID_SCO_DISC_REASON; + return (res); } /******************************************************************************* @@ -1318,9 +1224,8 @@ uint16_t BTM_ReadScoDiscReason (void) * BTM_SCO_PKT_TYPES_MASK_NO_3_EV5 * ******************************************************************************/ -uint16_t BTM_ReadDeviceScoPacketTypes (void) -{ - return (btm_cb.btm_sco_pkt_types_supported); +uint16_t BTM_ReadDeviceScoPacketTypes(void) { + return (btm_cb.btm_sco_pkt_types_supported); } /******************************************************************************* @@ -1333,18 +1238,17 @@ uint16_t BTM_ReadDeviceScoPacketTypes (void) * Returns handle for the connection, or 0xFFFF if invalid SCO index. * ******************************************************************************/ -uint16_t BTM_ReadScoHandle (uint16_t sco_inx) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[sco_inx]; - - /* Validity check */ - if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED)) - return (p->hci_handle); - else - return (BTM_INVALID_HCI_HANDLE); -#else +uint16_t BTM_ReadScoHandle(uint16_t sco_inx) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx]; + + /* Validity check */ + if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED)) + return (p->hci_handle); + else return (BTM_INVALID_HCI_HANDLE); +#else + return (BTM_INVALID_HCI_HANDLE); #endif } @@ -1358,18 +1262,17 @@ uint16_t BTM_ReadScoHandle (uint16_t sco_inx) * Returns pointer to BD address or NULL if not known * ******************************************************************************/ -uint8_t *BTM_ReadScoBdAddr (uint16_t sco_inx) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[sco_inx]; - - /* Validity check */ - if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->rem_bd_known)) - return (p->esco.data.bd_addr); - else - return (NULL); -#else +uint8_t* BTM_ReadScoBdAddr(uint16_t sco_inx) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[sco_inx]; + + /* Validity check */ + if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->rem_bd_known)) + return (p->esco.data.bd_addr); + else return (NULL); +#else + return (NULL); #endif } @@ -1390,51 +1293,45 @@ uint8_t *BTM_ReadScoBdAddr (uint16_t sco_inx) * BTM_BUSY if there are one or more active (e)SCO links. * ******************************************************************************/ -tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS *p_parms) -{ - tSCO_CB *p_esco = &btm_cb.sco_cb; - tBTM_ESCO_PARAMS *p_def = &p_esco->def_esco_parms; - - if (p_esco->esco_supported) - { - if (p_parms) - { - if (sco_mode == BTM_LINK_TYPE_ESCO) - *p_def = *p_parms; /* Save as the default parameters */ - else /* Load only the SCO packet types */ - { - p_def->packet_types = p_parms->packet_types; - p_def->tx_bw = BTM_64KBITS_RATE; - p_def->rx_bw = BTM_64KBITS_RATE; - p_def->max_latency = 0x000a; - p_def->voice_contfmt = 0x0060; - p_def->retrans_effort = 0; - - /* OR in any exception packet types */ - p_def->packet_types |= BTM_SCO_EXCEPTION_PKTS_MASK; - } - } - p_esco->desired_sco_mode = sco_mode; - BTM_TRACE_API("BTM_SetEScoMode -> mode %d", sco_mode); - } - else - { - p_esco->desired_sco_mode = BTM_LINK_TYPE_SCO; - p_def->packet_types &= BTM_SCO_LINK_ONLY_MASK; +tBTM_STATUS BTM_SetEScoMode(tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS* p_parms) { + tSCO_CB* p_esco = &btm_cb.sco_cb; + tBTM_ESCO_PARAMS* p_def = &p_esco->def_esco_parms; + + if (p_esco->esco_supported) { + if (p_parms) { + if (sco_mode == BTM_LINK_TYPE_ESCO) + *p_def = *p_parms; /* Save as the default parameters */ + else /* Load only the SCO packet types */ + { + p_def->packet_types = p_parms->packet_types; + p_def->tx_bw = BTM_64KBITS_RATE; + p_def->rx_bw = BTM_64KBITS_RATE; + p_def->max_latency = 0x000a; + p_def->voice_contfmt = 0x0060; p_def->retrans_effort = 0; - BTM_TRACE_API("BTM_SetEScoMode -> mode SCO (eSCO not supported)"); - } - - BTM_TRACE_DEBUG(" txbw 0x%08x, rxbw 0x%08x, max_lat 0x%04x, voice 0x%04x, pkt 0x%04x, rtx effort 0x%02x", - p_def->tx_bw, p_def->rx_bw, p_def->max_latency, - p_def->voice_contfmt, p_def->packet_types, - p_def->retrans_effort); - return (BTM_SUCCESS); + /* OR in any exception packet types */ + p_def->packet_types |= BTM_SCO_EXCEPTION_PKTS_MASK; + } + } + p_esco->desired_sco_mode = sco_mode; + BTM_TRACE_API("BTM_SetEScoMode -> mode %d", sco_mode); + } else { + p_esco->desired_sco_mode = BTM_LINK_TYPE_SCO; + p_def->packet_types &= BTM_SCO_LINK_ONLY_MASK; + p_def->retrans_effort = 0; + BTM_TRACE_API("BTM_SetEScoMode -> mode SCO (eSCO not supported)"); + } + + BTM_TRACE_DEBUG( + " txbw 0x%08x, rxbw 0x%08x, max_lat 0x%04x, voice 0x%04x, pkt 0x%04x, " + "rtx effort 0x%02x", + p_def->tx_bw, p_def->rx_bw, p_def->max_latency, p_def->voice_contfmt, + p_def->packet_types, p_def->retrans_effort); + + return (BTM_SUCCESS); } - - /******************************************************************************* * * Function BTM_RegForEScoEvts @@ -1450,24 +1347,22 @@ tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS *p_parms) * later or does not support eSCO. * ******************************************************************************/ -tBTM_STATUS BTM_RegForEScoEvts (uint16_t sco_inx, tBTM_ESCO_CBACK *p_esco_cback) -{ -#if (BTM_MAX_SCO_LINKS>0) - if (!btm_cb.sco_cb.esco_supported) - { - btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = NULL; - return (BTM_MODE_UNSUPPORTED); - } +tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx, + tBTM_ESCO_CBACK* p_esco_cback) { +#if (BTM_MAX_SCO_LINKS > 0) + if (!btm_cb.sco_cb.esco_supported) { + btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = NULL; + return (BTM_MODE_UNSUPPORTED); + } - if (sco_inx < BTM_MAX_SCO_LINKS && - btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_UNUSED) - { - btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = p_esco_cback; - return (BTM_SUCCESS); - } - return (BTM_ILLEGAL_VALUE); + if (sco_inx < BTM_MAX_SCO_LINKS && + btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_UNUSED) { + btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = p_esco_cback; + return (BTM_SUCCESS); + } + return (BTM_ILLEGAL_VALUE); #else - return (BTM_MODE_UNSUPPORTED); + return (BTM_MODE_UNSUPPORTED); #endif } @@ -1488,38 +1383,34 @@ tBTM_STATUS BTM_RegForEScoEvts (uint16_t sco_inx, tBTM_ESCO_CBACK *p_esco_cback) * sco_inx. * ******************************************************************************/ -tBTM_STATUS BTM_ReadEScoLinkParms (uint16_t sco_inx, tBTM_ESCO_DATA *p_parms) -{ -#if (BTM_MAX_SCO_LINKS>0) - uint8_t index; +tBTM_STATUS BTM_ReadEScoLinkParms(uint16_t sco_inx, tBTM_ESCO_DATA* p_parms) { +#if (BTM_MAX_SCO_LINKS > 0) + uint8_t index; - BTM_TRACE_API("BTM_ReadEScoLinkParms -> sco_inx 0x%04x", sco_inx); + BTM_TRACE_API("BTM_ReadEScoLinkParms -> sco_inx 0x%04x", sco_inx); - if (sco_inx < BTM_MAX_SCO_LINKS && - btm_cb.sco_cb.sco_db[sco_inx].state >= SCO_ST_CONNECTED) - { - *p_parms = btm_cb.sco_cb.sco_db[sco_inx].esco.data; + if (sco_inx < BTM_MAX_SCO_LINKS && + btm_cb.sco_cb.sco_db[sco_inx].state >= SCO_ST_CONNECTED) { + *p_parms = btm_cb.sco_cb.sco_db[sco_inx].esco.data; + return (BTM_SUCCESS); + } + + if (sco_inx == BTM_FIRST_ACTIVE_SCO_INDEX) { + for (index = 0; index < BTM_MAX_SCO_LINKS; index++) { + if (btm_cb.sco_cb.sco_db[index].state >= SCO_ST_CONNECTED) { + BTM_TRACE_API("BTM_ReadEScoLinkParms the first active SCO index is %d", + index); + *p_parms = btm_cb.sco_cb.sco_db[index].esco.data; return (BTM_SUCCESS); + } } - - if (sco_inx == BTM_FIRST_ACTIVE_SCO_INDEX) - { - for (index = 0; index < BTM_MAX_SCO_LINKS; index++) - { - if (btm_cb.sco_cb.sco_db[index].state >= SCO_ST_CONNECTED) - { - BTM_TRACE_API("BTM_ReadEScoLinkParms the first active SCO index is %d",index); - *p_parms = btm_cb.sco_cb.sco_db[index].esco.data; - return (BTM_SUCCESS); - } - } - } + } #endif - BTM_TRACE_API("BTM_ReadEScoLinkParms cannot find the SCO index!"); - memset(p_parms, 0, sizeof(tBTM_ESCO_DATA)); - return (BTM_WRONG_MODE); + BTM_TRACE_API("BTM_ReadEScoLinkParms cannot find the SCO index!"); + memset(p_parms, 0, sizeof(tBTM_ESCO_DATA)); + return (BTM_WRONG_MODE); } /******************************************************************************* @@ -1542,61 +1433,61 @@ tBTM_STATUS BTM_ReadEScoLinkParms (uint16_t sco_inx, tBTM_ESCO_DATA *p_parms) * sco_inx. * ******************************************************************************/ -tBTM_STATUS BTM_ChangeEScoLinkParms (uint16_t sco_inx, tBTM_CHG_ESCO_PARAMS *p_parms) -{ -#if (BTM_MAX_SCO_LINKS>0) - tBTM_ESCO_PARAMS *p_setup; - tSCO_CONN *p_sco; - uint16_t temp_pkt_types; - - /* Make sure sco handle is valid and on an active link */ - if (sco_inx >= BTM_MAX_SCO_LINKS || - btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_CONNECTED) - return (BTM_WRONG_MODE); - - p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; - p_setup = &p_sco->esco.setup; - - /* If SCO connection OR eSCO not supported just send change packet types */ - if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO || - !btm_cb.sco_cb.esco_supported) - { - p_setup->packet_types = p_parms->packet_types & - (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_LINK_ONLY_MASK); - - - BTM_TRACE_API("BTM_ChangeEScoLinkParms -> SCO Link for handle 0x%04x, pkt 0x%04x", - p_sco->hci_handle, p_setup->packet_types); - - btsnd_hcic_change_conn_type(p_sco->hci_handle, - BTM_ESCO_2_SCO(p_setup->packet_types)); - } - else - { - temp_pkt_types = (p_parms->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & - btm_cb.btm_sco_pkt_types_supported); +tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx, + tBTM_CHG_ESCO_PARAMS* p_parms) { +#if (BTM_MAX_SCO_LINKS > 0) + tBTM_ESCO_PARAMS* p_setup; + tSCO_CONN* p_sco; + uint16_t temp_pkt_types; - /* OR in any exception packet types */ - temp_pkt_types |= ((p_parms->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | - (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); - - BTM_TRACE_API("BTM_ChangeEScoLinkParms -> eSCO Link for handle 0x%04x", p_sco->hci_handle); - BTM_TRACE_API(" txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt 0x%04x", - p_setup->tx_bw, p_setup->rx_bw, p_parms->max_latency, - p_setup->voice_contfmt, p_parms->retrans_effort, temp_pkt_types); - - /* When changing an existing link, only change latency, retrans, and pkts */ - btsnd_hcic_setup_esco_conn(p_sco->hci_handle, p_setup->tx_bw, - p_setup->rx_bw, p_parms->max_latency, - p_setup->voice_contfmt, - p_parms->retrans_effort, - temp_pkt_types); - p_parms->packet_types = temp_pkt_types; - } + /* Make sure sco handle is valid and on an active link */ + if (sco_inx >= BTM_MAX_SCO_LINKS || + btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_CONNECTED) + return (BTM_WRONG_MODE); - return (BTM_CMD_STARTED); + p_sco = &btm_cb.sco_cb.sco_db[sco_inx]; + p_setup = &p_sco->esco.setup; + + /* If SCO connection OR eSCO not supported just send change packet types */ + if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO || + !btm_cb.sco_cb.esco_supported) { + p_setup->packet_types = + p_parms->packet_types & + (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_LINK_ONLY_MASK); + + BTM_TRACE_API( + "BTM_ChangeEScoLinkParms -> SCO Link for handle 0x%04x, pkt 0x%04x", + p_sco->hci_handle, p_setup->packet_types); + + btsnd_hcic_change_conn_type(p_sco->hci_handle, + BTM_ESCO_2_SCO(p_setup->packet_types)); + } else { + temp_pkt_types = (p_parms->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK & + btm_cb.btm_sco_pkt_types_supported); + + /* OR in any exception packet types */ + temp_pkt_types |= + ((p_parms->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) | + (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK)); + + BTM_TRACE_API("BTM_ChangeEScoLinkParms -> eSCO Link for handle 0x%04x", + p_sco->hci_handle); + BTM_TRACE_API( + " txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt " + "0x%04x", + p_setup->tx_bw, p_setup->rx_bw, p_parms->max_latency, + p_setup->voice_contfmt, p_parms->retrans_effort, temp_pkt_types); + + /* When changing an existing link, only change latency, retrans, and pkts */ + btsnd_hcic_setup_esco_conn( + p_sco->hci_handle, p_setup->tx_bw, p_setup->rx_bw, p_parms->max_latency, + p_setup->voice_contfmt, p_parms->retrans_effort, temp_pkt_types); + p_parms->packet_types = temp_pkt_types; + } + + return (BTM_CMD_STARTED); #else - return (BTM_WRONG_MODE); + return (BTM_WRONG_MODE); #endif } @@ -1618,16 +1509,14 @@ tBTM_STATUS BTM_ChangeEScoLinkParms (uint16_t sco_inx, tBTM_CHG_ESCO_PARAMS *p_p * Returns void * ******************************************************************************/ -void BTM_EScoConnRsp (uint16_t sco_inx, uint8_t hci_status, tBTM_ESCO_PARAMS *p_parms) -{ -#if (BTM_MAX_SCO_LINKS>0) - if (sco_inx < BTM_MAX_SCO_LINKS && - btm_cb.sco_cb.sco_db[sco_inx].state == SCO_ST_W4_CONN_RSP) - { - btm_esco_conn_rsp(sco_inx, hci_status, - btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, - p_parms); - } +void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status, + tBTM_ESCO_PARAMS* p_parms) { +#if (BTM_MAX_SCO_LINKS > 0) + if (sco_inx < BTM_MAX_SCO_LINKS && + btm_cb.sco_cb.sco_db[sco_inx].state == SCO_ST_W4_CONN_RSP) { + btm_esco_conn_rsp(sco_inx, hci_status, + btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, p_parms); + } #endif } @@ -1641,13 +1530,12 @@ void BTM_EScoConnRsp (uint16_t sco_inx, uint8_t hci_status, tBTM_ESCO_PARAMS *p_ * Returns tBTM_SCO_TYPE * ******************************************************************************/ -tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms) -{ -#if (BTM_MAX_SCO_LINKS>0) - *p_parms = btm_cb.sco_cb.def_esco_parms; - return btm_cb.sco_cb.desired_sco_mode; +tBTM_SCO_TYPE btm_read_def_esco_mode(tBTM_ESCO_PARAMS* p_parms) { +#if (BTM_MAX_SCO_LINKS > 0) + *p_parms = btm_cb.sco_cb.def_esco_parms; + return btm_cb.sco_cb.desired_sco_mode; #else - return BTM_LINK_TYPE_SCO; + return BTM_LINK_TYPE_SCO; #endif } @@ -1661,39 +1549,34 @@ tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms) * Returns void * ******************************************************************************/ -void btm_esco_proc_conn_chg (uint8_t status, uint16_t handle, uint8_t tx_interval, - uint8_t retrans_window, uint16_t rx_pkt_len, - uint16_t tx_pkt_len) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - tBTM_CHG_ESCO_EVT_DATA data; - uint16_t xx; - - BTM_TRACE_EVENT("btm_esco_proc_conn_chg -> handle 0x%04x, status 0x%02x", - handle, status); - - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (p->state == SCO_ST_CONNECTED && handle == p->hci_handle) - { - /* If upper layer wants notification */ - if (p->esco.p_esco_cback) - { - memcpy(data.bd_addr, p->esco.data.bd_addr, BD_ADDR_LEN); - data.hci_status = status; - data.sco_inx = xx; - data.rx_pkt_len = p->esco.data.rx_pkt_len = rx_pkt_len; - data.tx_pkt_len = p->esco.data.tx_pkt_len = tx_pkt_len; - data.tx_interval = p->esco.data.tx_interval = tx_interval; - data.retrans_window = p->esco.data.retrans_window = retrans_window; - - (*p->esco.p_esco_cback)(BTM_ESCO_CHG_EVT, - (tBTM_ESCO_EVT_DATA *)&data); - } - return; - } +void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle, + uint8_t tx_interval, uint8_t retrans_window, + uint16_t rx_pkt_len, uint16_t tx_pkt_len) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + tBTM_CHG_ESCO_EVT_DATA data; + uint16_t xx; + + BTM_TRACE_EVENT("btm_esco_proc_conn_chg -> handle 0x%04x, status 0x%02x", + handle, status); + + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (p->state == SCO_ST_CONNECTED && handle == p->hci_handle) { + /* If upper layer wants notification */ + if (p->esco.p_esco_cback) { + memcpy(data.bd_addr, p->esco.data.bd_addr, BD_ADDR_LEN); + data.hci_status = status; + data.sco_inx = xx; + data.rx_pkt_len = p->esco.data.rx_pkt_len = rx_pkt_len; + data.tx_pkt_len = p->esco.data.tx_pkt_len = tx_pkt_len; + data.tx_interval = p->esco.data.tx_interval = tx_interval; + data.retrans_window = p->esco.data.retrans_window = retrans_window; + + (*p->esco.p_esco_cback)(BTM_ESCO_CHG_EVT, (tBTM_ESCO_EVT_DATA*)&data); + } + return; } + } #endif } @@ -1707,19 +1590,16 @@ void btm_esco_proc_conn_chg (uint8_t status, uint16_t handle, uint8_t tx_interva * Returns bool * ******************************************************************************/ -bool btm_is_sco_active (uint16_t handle) -{ -#if (BTM_MAX_SCO_LINKS>0) - uint16_t xx; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; +bool btm_is_sco_active(uint16_t handle) { +#if (BTM_MAX_SCO_LINKS > 0) + uint16_t xx; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if (handle == p->hci_handle && p->state == SCO_ST_CONNECTED) - return (true); - } + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if (handle == p->hci_handle && p->state == SCO_ST_CONNECTED) return (true); + } #endif - return (false); + return (false); } /******************************************************************************* @@ -1731,32 +1611,28 @@ bool btm_is_sco_active (uint16_t handle) * Returns uint8_t * ******************************************************************************/ -uint8_t BTM_GetNumScoLinks (void) -{ -#if (BTM_MAX_SCO_LINKS>0) - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - uint16_t xx; - uint8_t num_scos = 0; - - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - switch (p->state) - { - case SCO_ST_W4_CONN_RSP: - case SCO_ST_CONNECTING: - case SCO_ST_CONNECTED: - case SCO_ST_DISCONNECTING: - case SCO_ST_PEND_UNPARK: - num_scos++; - } +uint8_t BTM_GetNumScoLinks(void) { +#if (BTM_MAX_SCO_LINKS > 0) + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + uint16_t xx; + uint8_t num_scos = 0; + + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + switch (p->state) { + case SCO_ST_W4_CONN_RSP: + case SCO_ST_CONNECTING: + case SCO_ST_CONNECTED: + case SCO_ST_DISCONNECTING: + case SCO_ST_PEND_UNPARK: + num_scos++; } - return (num_scos); + } + return (num_scos); #else - return (0); + return (0); #endif } - /******************************************************************************* * * Function btm_is_sco_active_by_bdaddr @@ -1767,41 +1643,55 @@ uint8_t BTM_GetNumScoLinks (void) * Returns bool * ******************************************************************************/ -bool btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda) -{ -#if (BTM_MAX_SCO_LINKS>0) - uint8_t xx; - tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0]; - - /* If any SCO is being established to the remote BD address, refuse this */ - for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) - { - if ((!memcmp (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN)) && (p->state == SCO_ST_CONNECTED)) - { - return (true); - } +bool btm_is_sco_active_by_bdaddr(BD_ADDR remote_bda) { +#if (BTM_MAX_SCO_LINKS > 0) + uint8_t xx; + tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; + + /* If any SCO is being established to the remote BD address, refuse this */ + for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) { + if ((!memcmp(p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN)) && + (p->state == SCO_ST_CONNECTED)) { + return (true); } + } #endif - return (false); + return (false); +} +#else /* SCO_EXCLUDED == TRUE (Link in stubs) */ + +tBTM_STATUS BTM_CreateSco(BD_ADDR remote_bda, bool is_orig, uint16_t pkt_types, + uint16_t* p_sco_inx, tBTM_SCO_CB* p_conn_cb, + tBTM_SCO_CB* p_disc_cb) { + return (BTM_NO_RESOURCES); +} +tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx) { return (BTM_NO_RESOURCES); } +tBTM_STATUS BTM_SetScoPacketTypes(uint16_t sco_inx, uint16_t pkt_types) { + return (BTM_NO_RESOURCES); +} +uint16_t BTM_ReadScoPacketTypes(uint16_t sco_inx) { return (0); } +uint16_t BTM_ReadDeviceScoPacketTypes(void) { return (0); } +uint16_t BTM_ReadScoHandle(uint16_t sco_inx) { + return (BTM_INVALID_HCI_HANDLE); +} +uint8_t* BTM_ReadScoBdAddr(uint16_t sco_inx) { return ((uint8_t*)NULL); } +uint16_t BTM_ReadScoDiscReason(void) { return (BTM_INVALID_SCO_DISC_REASON); } +tBTM_STATUS BTM_SetEScoMode(tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS* p_parms) { + return (BTM_MODE_UNSUPPORTED); +} +tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx, + tBTM_ESCO_CBACK* p_esco_cback) { + return (BTM_ILLEGAL_VALUE); +} +tBTM_STATUS BTM_ReadEScoLinkParms(uint16_t sco_inx, tBTM_ESCO_DATA* p_parms) { + return (BTM_MODE_UNSUPPORTED); +} +tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx, + tBTM_CHG_ESCO_PARAMS* p_parms) { + return (BTM_MODE_UNSUPPORTED); } -#else /* SCO_EXCLUDED == TRUE (Link in stubs) */ - -tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, bool is_orig, - uint16_t pkt_types, uint16_t *p_sco_inx, - tBTM_SCO_CB *p_conn_cb, - tBTM_SCO_CB *p_disc_cb) {return (BTM_NO_RESOURCES);} -tBTM_STATUS BTM_RemoveSco (uint16_t sco_inx) {return (BTM_NO_RESOURCES);} -tBTM_STATUS BTM_SetScoPacketTypes (uint16_t sco_inx, uint16_t pkt_types) {return (BTM_NO_RESOURCES);} -uint16_t BTM_ReadScoPacketTypes (uint16_t sco_inx) {return (0);} -uint16_t BTM_ReadDeviceScoPacketTypes (void) {return (0);} -uint16_t BTM_ReadScoHandle (uint16_t sco_inx) {return (BTM_INVALID_HCI_HANDLE);} -uint8_t *BTM_ReadScoBdAddr(uint16_t sco_inx) {return((uint8_t *) NULL);} -uint16_t BTM_ReadScoDiscReason (void) {return (BTM_INVALID_SCO_DISC_REASON);} -tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS *p_parms) {return (BTM_MODE_UNSUPPORTED);} -tBTM_STATUS BTM_RegForEScoEvts (uint16_t sco_inx, tBTM_ESCO_CBACK *p_esco_cback) { return (BTM_ILLEGAL_VALUE);} -tBTM_STATUS BTM_ReadEScoLinkParms (uint16_t sco_inx, tBTM_ESCO_DATA *p_parms) { return (BTM_MODE_UNSUPPORTED);} -tBTM_STATUS BTM_ChangeEScoLinkParms (uint16_t sco_inx, tBTM_CHG_ESCO_PARAMS *p_parms) { return (BTM_MODE_UNSUPPORTED);} -void BTM_EScoConnRsp (uint16_t sco_inx, uint8_t hci_status, tBTM_ESCO_PARAMS *p_parms) {} -uint8_t BTM_GetNumScoLinks (void) {return (0);} +void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status, + tBTM_ESCO_PARAMS* p_parms) {} +uint8_t BTM_GetNumScoLinks(void) { return (0); } #endif /* If SCO is being used */ diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index 614f11729..bfbd3074f 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -42,79 +42,89 @@ #include "gatt_int.h" -#define BTM_SEC_MAX_COLLISION_DELAY (5000) +#define BTM_SEC_MAX_COLLISION_DELAY (5000) -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; #ifdef APPL_AUTH_WRITE_EXCEPTION -bool (APPL_AUTH_WRITE_EXCEPTION)(BD_ADDR bd_addr); +bool(APPL_AUTH_WRITE_EXCEPTION)(BD_ADDR bd_addr); #endif /******************************************************************************* * L O C A L F U N C T I O N P R O T O T Y P E S * ******************************************************************************/ -tBTM_SEC_SERV_REC *btm_sec_find_first_serv (bool is_originator, uint16_t psm); -static tBTM_SEC_SERV_REC *btm_sec_find_next_serv (tBTM_SEC_SERV_REC *p_cur); -static tBTM_SEC_SERV_REC *btm_sec_find_mx_serv (uint8_t is_originator, uint16_t psm, - uint32_t mx_proto_id, - uint32_t mx_chan_id); - -static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_sec_start_get_name (tBTM_SEC_DEV_REC *p_dev_rec); -static void btm_sec_start_authentication (tBTM_SEC_DEV_REC *p_dev_rec); -static void btm_sec_start_encryption (tBTM_SEC_DEV_REC *p_dev_rec); -static void btm_sec_collision_timeout(void *data); -static void btm_restore_mode(void); -static void btm_sec_pairing_timeout(void *data); -static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec); -static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state); - -static const char* btm_pair_state_descr (tBTM_PAIRING_STATE state); - -static void btm_sec_check_pending_reqs(void); -static bool btm_sec_queue_mx_request (BD_ADDR bd_addr, uint16_t psm, bool is_orig, - uint32_t mx_proto_id, uint32_t mx_chan_id, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); -static void btm_sec_bond_cancel_complete (void); -static void btm_send_link_key_notif (tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec); - -static uint8_t btm_sec_start_authorization (tBTM_SEC_DEV_REC *p_dev_rec); -bool btm_sec_are_all_trusted(uint32_t p_mask[]); - -static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, uint8_t reason, uint16_t conn_handle); -uint8_t btm_sec_start_role_switch (tBTM_SEC_DEV_REC *p_dev_rec); -tBTM_SEC_DEV_REC *btm_sec_find_dev_by_sec_state (uint8_t state); - -static bool btm_sec_set_security_level ( CONNECTION_TYPE conn_type, const char *p_name, - uint8_t service_id, uint16_t sec_level, uint16_t psm, - uint32_t mx_proto_id, uint32_t mx_chan_id); - -static bool btm_dev_authenticated(tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_dev_encrypted(tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_dev_authorized(tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_serv_trusted(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_SEC_SERV_REC *p_serv_rec); -static bool btm_sec_is_serv_level0 (uint16_t psm); -static uint16_t btm_sec_set_serv_level4_flags (uint16_t cur_security, bool is_originator); - -static bool btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT transport, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data, - tBTM_BLE_SEC_ACT sec_act); -static void btm_sec_check_pending_enc_req (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRANSPORT transport, - uint8_t encr_enable); - -static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC *p_dev_rec); -static bool btm_sec_is_master(tBTM_SEC_DEV_REC *p_dev_rec); +tBTM_SEC_SERV_REC* btm_sec_find_first_serv(bool is_originator, uint16_t psm); +static tBTM_SEC_SERV_REC* btm_sec_find_next_serv(tBTM_SEC_SERV_REC* p_cur); +static tBTM_SEC_SERV_REC* btm_sec_find_mx_serv(uint8_t is_originator, + uint16_t psm, + uint32_t mx_proto_id, + uint32_t mx_chan_id); + +static tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_sec_start_get_name(tBTM_SEC_DEV_REC* p_dev_rec); +static void btm_sec_start_authentication(tBTM_SEC_DEV_REC* p_dev_rec); +static void btm_sec_start_encryption(tBTM_SEC_DEV_REC* p_dev_rec); +static void btm_sec_collision_timeout(void* data); +static void btm_restore_mode(void); +static void btm_sec_pairing_timeout(void* data); +static tBTM_STATUS btm_sec_dd_create_conn(tBTM_SEC_DEV_REC* p_dev_rec); +static void btm_sec_change_pairing_state(tBTM_PAIRING_STATE new_state); + +static const char* btm_pair_state_descr(tBTM_PAIRING_STATE state); + +static void btm_sec_check_pending_reqs(void); +static bool btm_sec_queue_mx_request(BD_ADDR bd_addr, uint16_t psm, + bool is_orig, uint32_t mx_proto_id, + uint32_t mx_chan_id, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data); +static void btm_sec_bond_cancel_complete(void); +static void btm_send_link_key_notif(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_sec_check_prefetch_pin(tBTM_SEC_DEV_REC* p_dev_rec); + +static uint8_t btm_sec_start_authorization(tBTM_SEC_DEV_REC* p_dev_rec); +bool btm_sec_are_all_trusted(uint32_t p_mask[]); + +static tBTM_STATUS btm_sec_send_hci_disconnect(tBTM_SEC_DEV_REC* p_dev_rec, + uint8_t reason, + uint16_t conn_handle); +uint8_t btm_sec_start_role_switch(tBTM_SEC_DEV_REC* p_dev_rec); +tBTM_SEC_DEV_REC* btm_sec_find_dev_by_sec_state(uint8_t state); + +static bool btm_sec_set_security_level(CONNECTION_TYPE conn_type, + const char* p_name, uint8_t service_id, + uint16_t sec_level, uint16_t psm, + uint32_t mx_proto_id, + uint32_t mx_chan_id); + +static bool btm_dev_authenticated(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_dev_encrypted(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_dev_authorized(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_serv_trusted(tBTM_SEC_DEV_REC* p_dev_rec, + tBTM_SEC_SERV_REC* p_serv_rec); +static bool btm_sec_is_serv_level0(uint16_t psm); +static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security, + bool is_originator); + +static bool btm_sec_queue_encrypt_request(BD_ADDR bd_addr, + tBT_TRANSPORT transport, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data, + tBTM_BLE_SEC_ACT sec_act); +static void btm_sec_check_pending_enc_req(tBTM_SEC_DEV_REC* p_dev_rec, + tBT_TRANSPORT transport, + uint8_t encr_enable); + +static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC* p_dev_rec); +static bool btm_sec_is_master(tBTM_SEC_DEV_REC* p_dev_rec); /* true - authenticated link key is possible */ -static const bool btm_sec_io_map [BTM_IO_CAP_MAX][BTM_IO_CAP_MAX] = -{ +static const bool btm_sec_io_map[BTM_IO_CAP_MAX][BTM_IO_CAP_MAX] = { /* OUT, IO, IN, NONE */ -/* OUT */ {false, false, true, false}, -/* IO */ {false, true, true, false}, -/* IN */ {true, true, true, false}, -/* NONE */ {false, false, false, false} -}; + /* OUT */ {false, false, true, false}, + /* IO */ {false, true, true, false}, + /* IN */ {true, true, true, false}, + /* NONE */ {false, false, false, false}}; /* BTM_IO_CAP_OUT 0 DisplayOnly */ /* BTM_IO_CAP_IO 1 DisplayYesNo */ /* BTM_IO_CAP_IN 2 KeyboardOnly */ @@ -129,13 +139,11 @@ static const bool btm_sec_io_map [BTM_IO_CAP_MAX][BTM_IO_CAP_MAX] = * Returns bool true or false * ******************************************************************************/ -static bool btm_dev_authenticated (tBTM_SEC_DEV_REC *p_dev_rec) -{ - if(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED) - { - return(true); - } - return(false); +static bool btm_dev_authenticated(tBTM_SEC_DEV_REC* p_dev_rec) { + if (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED) { + return (true); + } + return (false); } /******************************************************************************* @@ -147,13 +155,11 @@ static bool btm_dev_authenticated (tBTM_SEC_DEV_REC *p_dev_rec) * Returns bool true or false * ******************************************************************************/ -static bool btm_dev_encrypted (tBTM_SEC_DEV_REC *p_dev_rec) -{ - if(p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) - { - return(true); - } - return(false); +static bool btm_dev_encrypted(tBTM_SEC_DEV_REC* p_dev_rec) { + if (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) { + return (true); + } + return (false); } /******************************************************************************* @@ -165,13 +171,11 @@ static bool btm_dev_encrypted (tBTM_SEC_DEV_REC *p_dev_rec) * Returns bool true or false * ******************************************************************************/ -static bool btm_dev_authorized (tBTM_SEC_DEV_REC *p_dev_rec) -{ - if(p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED) - { - return(true); - } - return(false); +static bool btm_dev_authorized(tBTM_SEC_DEV_REC* p_dev_rec) { + if (p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED) { + return (true); + } + return (false); } /******************************************************************************* @@ -183,14 +187,12 @@ static bool btm_dev_authorized (tBTM_SEC_DEV_REC *p_dev_rec) * Returns bool true or false * ******************************************************************************/ -static bool btm_dev_16_digit_authenticated(tBTM_SEC_DEV_REC *p_dev_rec) -{ - // BTM_SEC_16_DIGIT_PIN_AUTHED is set if MITM or 16 digit pin is used - if(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) - { - return(true); - } - return(false); +static bool btm_dev_16_digit_authenticated(tBTM_SEC_DEV_REC* p_dev_rec) { + // BTM_SEC_16_DIGIT_PIN_AUTHED is set if MITM or 16 digit pin is used + if (p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) { + return (true); + } + return (false); } /******************************************************************************* @@ -202,13 +204,13 @@ static bool btm_dev_16_digit_authenticated(tBTM_SEC_DEV_REC *p_dev_rec) * Returns bool true or false * ******************************************************************************/ -static bool btm_serv_trusted(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_SEC_SERV_REC *p_serv_rec) -{ - if(BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, p_serv_rec->service_id)) - { - return(true); - } - return(false); +static bool btm_serv_trusted(tBTM_SEC_DEV_REC* p_dev_rec, + tBTM_SEC_SERV_REC* p_serv_rec) { + if (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, + p_serv_rec->service_id)) { + return (true); + } + return (false); } /******************************************************************************* @@ -223,32 +225,29 @@ static bool btm_serv_trusted(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_SEC_SERV_REC * * Returns true if registered OK, else false * ******************************************************************************/ -bool BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) -{ - BT_OCTET16 temp_value = {0}; - - BTM_TRACE_EVENT("%s application registered", __func__); - - LOG_INFO(LOG_TAG, "%s p_cb_info->p_le_callback == 0x%p", __func__, p_cb_info->p_le_callback); - if (p_cb_info->p_le_callback) - { - BTM_TRACE_EVENT("%s SMP_Register( btm_proc_smp_cback )", __func__); - SMP_Register(btm_proc_smp_cback); - /* if no IR is loaded, need to regenerate all the keys */ - if (memcmp(btm_cb.devcb.id_keys.ir, &temp_value, sizeof(BT_OCTET16)) == 0) - { - btm_ble_reset_id(); - } - } - else - { - LOG_WARN(LOG_TAG, "%s p_cb_info->p_le_callback == NULL", __func__); - } - - btm_cb.api = *p_cb_info; - LOG_INFO(LOG_TAG, "%s btm_cb.api.p_le_callback = 0x%p ", __func__, btm_cb.api.p_le_callback); - BTM_TRACE_EVENT("%s application registered", __func__); - return(true); +bool BTM_SecRegister(tBTM_APPL_INFO* p_cb_info) { + BT_OCTET16 temp_value = {0}; + + BTM_TRACE_EVENT("%s application registered", __func__); + + LOG_INFO(LOG_TAG, "%s p_cb_info->p_le_callback == 0x%p", __func__, + p_cb_info->p_le_callback); + if (p_cb_info->p_le_callback) { + BTM_TRACE_EVENT("%s SMP_Register( btm_proc_smp_cback )", __func__); + SMP_Register(btm_proc_smp_cback); + /* if no IR is loaded, need to regenerate all the keys */ + if (memcmp(btm_cb.devcb.id_keys.ir, &temp_value, sizeof(BT_OCTET16)) == 0) { + btm_ble_reset_id(); + } + } else { + LOG_WARN(LOG_TAG, "%s p_cb_info->p_le_callback == NULL", __func__); + } + + btm_cb.api = *p_cb_info; + LOG_INFO(LOG_TAG, "%s btm_cb.api.p_le_callback = 0x%p ", __func__, + btm_cb.api.p_le_callback); + BTM_TRACE_EVENT("%s application registered", __func__); + return (true); } /******************************************************************************* @@ -262,10 +261,10 @@ bool BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) * Returns true if registered OK, else false * ******************************************************************************/ -bool BTM_SecRegisterLinkKeyNotificationCallback (tBTM_LINK_KEY_CALLBACK *p_callback) -{ - btm_cb.api.p_link_key_callback = p_callback; - return true; +bool BTM_SecRegisterLinkKeyNotificationCallback( + tBTM_LINK_KEY_CALLBACK* p_callback) { + btm_cb.api.p_link_key_callback = p_callback; + return true; } /******************************************************************************* @@ -278,20 +277,17 @@ bool BTM_SecRegisterLinkKeyNotificationCallback (tBTM_LINK_KEY_CALLBACK *p_ca * Returns true if registered OK, else false * ******************************************************************************/ -bool BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback) -{ - int i; +bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) { + int i; - for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) - { - if (btm_cb.p_rmt_name_callback[i] == NULL) - { - btm_cb.p_rmt_name_callback[i] = p_callback; - return(true); - } + for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) { + if (btm_cb.p_rmt_name_callback[i] == NULL) { + btm_cb.p_rmt_name_callback[i] = p_callback; + return (true); } + } - return(false); + return (false); } /******************************************************************************* @@ -304,20 +300,17 @@ bool BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback) * Returns true if OK, else false * ******************************************************************************/ -bool BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback) -{ - int i; +bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback) { + int i; - for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) - { - if (btm_cb.p_rmt_name_callback[i] == p_callback) - { - btm_cb.p_rmt_name_callback[i] = NULL; - return(true); - } + for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) { + if (btm_cb.p_rmt_name_callback[i] == p_callback) { + btm_cb.p_rmt_name_callback[i] = NULL; + return (true); } + } - return(false); + return (false); } /******************************************************************************* @@ -329,18 +322,16 @@ bool BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback) * Returns bool true or false is device found * ******************************************************************************/ -bool BTM_GetSecurityFlags (BD_ADDR bd_addr, uint8_t * p_sec_flags) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) - { - *p_sec_flags = (uint8_t) p_dev_rec->sec_flags; - return(true); - } - BTM_TRACE_ERROR ("BTM_GetSecurityFlags false"); - return(false); +bool BTM_GetSecurityFlags(BD_ADDR bd_addr, uint8_t* p_sec_flags) { + tBTM_SEC_DEV_REC* p_dev_rec; + + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + *p_sec_flags = (uint8_t)p_dev_rec->sec_flags; + return (true); + } + BTM_TRACE_ERROR("BTM_GetSecurityFlags false"); + return (false); } /******************************************************************************* @@ -352,23 +343,21 @@ bool BTM_GetSecurityFlags (BD_ADDR bd_addr, uint8_t * p_sec_flags) * Returns bool true or false is device found * ******************************************************************************/ -bool BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, uint8_t * p_sec_flags, - tBT_TRANSPORT transport) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) - { - if (transport == BT_TRANSPORT_BR_EDR) - *p_sec_flags = (uint8_t) p_dev_rec->sec_flags; - else - *p_sec_flags = (uint8_t) (p_dev_rec->sec_flags >> 8); +bool BTM_GetSecurityFlagsByTransport(BD_ADDR bd_addr, uint8_t* p_sec_flags, + tBT_TRANSPORT transport) { + tBTM_SEC_DEV_REC* p_dev_rec; + + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + if (transport == BT_TRANSPORT_BR_EDR) + *p_sec_flags = (uint8_t)p_dev_rec->sec_flags; + else + *p_sec_flags = (uint8_t)(p_dev_rec->sec_flags >> 8); - return(true); - } - BTM_TRACE_ERROR ("BTM_GetSecurityFlags false"); - return(false); + return (true); + } + BTM_TRACE_ERROR("BTM_GetSecurityFlags false"); + return (false); } /******************************************************************************* @@ -380,21 +369,20 @@ bool BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, uint8_t * p_sec_flags, * Returns void * ******************************************************************************/ -void BTM_SetPinType (uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len) -{ - BTM_TRACE_API ("BTM_SetPinType: pin type %d [variable-0, fixed-1], code %s, length %d", - pin_type, (char *) pin_code, pin_code_len); - - /* If device is not up security mode will be set as a part of startup */ - if ( (btm_cb.cfg.pin_type != pin_type) - && controller_get_interface()->get_is_ready() ) - { - btsnd_hcic_write_pin_type (pin_type); - } - - btm_cb.cfg.pin_type = pin_type; - btm_cb.cfg.pin_code_len = pin_code_len; - memcpy (btm_cb.cfg.pin_code, pin_code, pin_code_len); +void BTM_SetPinType(uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len) { + BTM_TRACE_API( + "BTM_SetPinType: pin type %d [variable-0, fixed-1], code %s, length %d", + pin_type, (char*)pin_code, pin_code_len); + + /* If device is not up security mode will be set as a part of startup */ + if ((btm_cb.cfg.pin_type != pin_type) && + controller_get_interface()->get_is_ready()) { + btsnd_hcic_write_pin_type(pin_type); + } + + btm_cb.cfg.pin_type = pin_type; + btm_cb.cfg.pin_code_len = pin_code_len; + memcpy(btm_cb.cfg.pin_code, pin_code, pin_code_len); } /******************************************************************************* @@ -411,12 +399,13 @@ void BTM_SetPinType (uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len) * Returns void * ******************************************************************************/ -void BTM_SetPairableMode (bool allow_pairing, bool connect_only_paired) -{ - BTM_TRACE_API ("BTM_SetPairableMode() allow_pairing: %u connect_only_paired: %u", allow_pairing, connect_only_paired); +void BTM_SetPairableMode(bool allow_pairing, bool connect_only_paired) { + BTM_TRACE_API( + "BTM_SetPairableMode() allow_pairing: %u connect_only_paired: %u", + allow_pairing, connect_only_paired); - btm_cb.pairing_disabled = !allow_pairing; - btm_cb.connect_only_paired = connect_only_paired; + btm_cb.pairing_disabled = !allow_pairing; + btm_cb.connect_only_paired = connect_only_paired; } /******************************************************************************* @@ -435,15 +424,13 @@ void BTM_SetPairableMode (bool allow_pairing, bool connect_only_paired) * Returns void * ******************************************************************************/ -void BTM_SetSecureConnectionsOnly (bool secure_connections_only_mode) -{ - BTM_TRACE_API("%s: Mode : %u", __func__, - secure_connections_only_mode); +void BTM_SetSecureConnectionsOnly(bool secure_connections_only_mode) { + BTM_TRACE_API("%s: Mode : %u", __func__, secure_connections_only_mode); - btm_cb.devcb.secure_connections_only = secure_connections_only_mode; - btm_cb.security_mode = BTM_SEC_MODE_SC; + btm_cb.devcb.secure_connections_only = secure_connections_only_mode; + btm_cb.security_mode = BTM_SEC_MODE_SC; } -#define BTM_NO_AVAIL_SEC_SERVICES ((uint16_t) 0xffff) +#define BTM_NO_AVAIL_SEC_SERVICES ((uint16_t)0xffff) /******************************************************************************* * @@ -465,23 +452,22 @@ void BTM_SetSecureConnectionsOnly (bool secure_connections_only_mode) * Returns true if registered OK, else false * ******************************************************************************/ -bool BTM_SetSecurityLevel (bool is_originator, const char *p_name, uint8_t service_id, - uint16_t sec_level, uint16_t psm, uint32_t mx_proto_id, - uint32_t mx_chan_id) -{ +bool BTM_SetSecurityLevel(bool is_originator, const char* p_name, + uint8_t service_id, uint16_t sec_level, uint16_t psm, + uint32_t mx_proto_id, uint32_t mx_chan_id) { #if (L2CAP_UCD_INCLUDED == TRUE) - CONNECTION_TYPE conn_type; + CONNECTION_TYPE conn_type; - if (is_originator) - conn_type = CONN_ORIENT_ORIG; - else - conn_type = CONN_ORIENT_TERM; + if (is_originator) + conn_type = CONN_ORIENT_ORIG; + else + conn_type = CONN_ORIENT_TERM; - return(btm_sec_set_security_level (conn_type, p_name, service_id, - sec_level, psm, mx_proto_id, mx_chan_id)); + return (btm_sec_set_security_level(conn_type, p_name, service_id, sec_level, + psm, mx_proto_id, mx_chan_id)); #else - return(btm_sec_set_security_level (is_originator, p_name, service_id, - sec_level, psm, mx_proto_id, mx_chan_id)); + return (btm_sec_set_security_level(is_originator, p_name, service_id, + sec_level, psm, mx_proto_id, mx_chan_id)); #endif } @@ -505,215 +491,205 @@ bool BTM_SetSecurityLevel (bool is_originator, const char *p_name, uint8_t * Returns true if registered OK, else false * ******************************************************************************/ -static bool btm_sec_set_security_level (CONNECTION_TYPE conn_type, const char *p_name, - uint8_t service_id, uint16_t sec_level, uint16_t psm, - uint32_t mx_proto_id, uint32_t mx_chan_id) -{ - tBTM_SEC_SERV_REC *p_srec; - uint16_t index; - uint16_t first_unused_record = BTM_NO_AVAIL_SEC_SERVICES; - bool record_allocated = false; - bool is_originator; +static bool btm_sec_set_security_level(CONNECTION_TYPE conn_type, + const char* p_name, uint8_t service_id, + uint16_t sec_level, uint16_t psm, + uint32_t mx_proto_id, + uint32_t mx_chan_id) { + tBTM_SEC_SERV_REC* p_srec; + uint16_t index; + uint16_t first_unused_record = BTM_NO_AVAIL_SEC_SERVICES; + bool record_allocated = false; + bool is_originator; #if (L2CAP_UCD_INCLUDED == TRUE) - bool is_ucd; - - if (conn_type & CONNECTION_TYPE_ORIG_MASK) - is_originator = true; - else - is_originator = false; - - if (conn_type & CONNECTION_TYPE_CONNLESS_MASK ) - { - is_ucd = true; - } - else - { - is_ucd = false; - } + bool is_ucd; + + if (conn_type & CONNECTION_TYPE_ORIG_MASK) + is_originator = true; + else + is_originator = false; + + if (conn_type & CONNECTION_TYPE_CONNLESS_MASK) { + is_ucd = true; + } else { + is_ucd = false; + } #else - is_originator = conn_type; + is_originator = conn_type; #endif - BTM_TRACE_API("%s : sec: 0x%x", __func__, sec_level); + BTM_TRACE_API("%s : sec: 0x%x", __func__, sec_level); - /* See if the record can be reused (same service name, psm, mx_proto_id, - service_id, and mx_chan_id), or obtain the next unused record */ + /* See if the record can be reused (same service name, psm, mx_proto_id, + service_id, and mx_chan_id), or obtain the next unused record */ - p_srec = &btm_cb.sec_serv_rec[0]; + p_srec = &btm_cb.sec_serv_rec[0]; - for (index = 0; index < BTM_SEC_MAX_SERVICE_RECORDS; index++, p_srec++) - { - /* Check if there is already a record for this service */ - if (p_srec->security_flags & BTM_SEC_IN_USE) - { + for (index = 0; index < BTM_SEC_MAX_SERVICE_RECORDS; index++, p_srec++) { + /* Check if there is already a record for this service */ + if (p_srec->security_flags & BTM_SEC_IN_USE) { #if BTM_SEC_SERVICE_NAME_LEN > 0 - if (p_srec->psm == psm && - p_srec->mx_proto_id == mx_proto_id && - service_id == p_srec->service_id && - p_name && - (!strncmp (p_name, (char *) p_srec->orig_service_name, - BTM_SEC_SERVICE_NAME_LEN) || - !strncmp (p_name, (char *) p_srec->term_service_name, - BTM_SEC_SERVICE_NAME_LEN))) + if (p_srec->psm == psm && p_srec->mx_proto_id == mx_proto_id && + service_id == p_srec->service_id && p_name && + (!strncmp(p_name, (char*)p_srec->orig_service_name, + BTM_SEC_SERVICE_NAME_LEN) || + !strncmp(p_name, (char*)p_srec->term_service_name, + BTM_SEC_SERVICE_NAME_LEN))) #else - if (p_srec->psm == psm && - p_srec->mx_proto_id == mx_proto_id && - service_id == p_srec->service_id) + if (p_srec->psm == psm && p_srec->mx_proto_id == mx_proto_id && + service_id == p_srec->service_id) #endif - { - record_allocated = true; - break; - } - } - /* Mark the first available service record */ - else if (!record_allocated) - { - memset (p_srec, 0, sizeof(tBTM_SEC_SERV_REC)); - record_allocated = true; - first_unused_record = index; - } - } - - if (!record_allocated) - { - BTM_TRACE_WARNING("BTM_SEC_REG: Out of Service Records (%d)", BTM_SEC_MAX_SERVICE_RECORDS); - return(record_allocated); - } - - /* Process the request if service record is valid */ - /* If a duplicate service wasn't found, use the first available */ - if (index >= BTM_SEC_MAX_SERVICE_RECORDS) - { - index = first_unused_record; - p_srec = &btm_cb.sec_serv_rec[index]; + { + record_allocated = true; + break; + } } - - p_srec->psm = psm; - p_srec->service_id = service_id; - p_srec->mx_proto_id = mx_proto_id; - - if (is_originator) - { - p_srec->orig_mx_chan_id = mx_chan_id; + /* Mark the first available service record */ + else if (!record_allocated) { + memset(p_srec, 0, sizeof(tBTM_SEC_SERV_REC)); + record_allocated = true; + first_unused_record = index; + } + } + + if (!record_allocated) { + BTM_TRACE_WARNING("BTM_SEC_REG: Out of Service Records (%d)", + BTM_SEC_MAX_SERVICE_RECORDS); + return (record_allocated); + } + + /* Process the request if service record is valid */ + /* If a duplicate service wasn't found, use the first available */ + if (index >= BTM_SEC_MAX_SERVICE_RECORDS) { + index = first_unused_record; + p_srec = &btm_cb.sec_serv_rec[index]; + } + + p_srec->psm = psm; + p_srec->service_id = service_id; + p_srec->mx_proto_id = mx_proto_id; + + if (is_originator) { + p_srec->orig_mx_chan_id = mx_chan_id; #if BTM_SEC_SERVICE_NAME_LEN > 0 - strlcpy ((char *)p_srec->orig_service_name, p_name, BTM_SEC_SERVICE_NAME_LEN + 1); + strlcpy((char*)p_srec->orig_service_name, p_name, + BTM_SEC_SERVICE_NAME_LEN + 1); #endif - /* clear out the old setting, just in case it exists */ +/* clear out the old setting, just in case it exists */ #if (L2CAP_UCD_INCLUDED == TRUE) - if ( is_ucd ) - { - p_srec->ucd_security_flags &= - ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM | - BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); - } - else + if (is_ucd) { + p_srec->ucd_security_flags &= ~( + BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | + BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM | BTM_SEC_FORCE_MASTER | + BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); + } else #endif - { - p_srec->security_flags &= - ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM | - BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); - } + { + p_srec->security_flags &= ~( + BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | + BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM | BTM_SEC_FORCE_MASTER | + BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); + } - /* Parameter validation. Originator should not set requirements for incoming connections */ - sec_level &= ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHENTICATE - | BTM_SEC_IN_MITM | BTM_SEC_IN_MIN_16_DIGIT_PIN ); + /* Parameter validation. Originator should not set requirements for + * incoming connections */ + sec_level &= + ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHENTICATE | + BTM_SEC_IN_MITM | BTM_SEC_IN_MIN_16_DIGIT_PIN); - if (btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) - { - if (sec_level & BTM_SEC_OUT_AUTHENTICATE) - sec_level |= BTM_SEC_OUT_MITM; - } + if (btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) { + if (sec_level & BTM_SEC_OUT_AUTHENTICATE) sec_level |= BTM_SEC_OUT_MITM; + } - /* Make sure the authenticate bit is set, when encrypt bit is set */ - if (sec_level & BTM_SEC_OUT_ENCRYPT) - sec_level |= BTM_SEC_OUT_AUTHENTICATE; + /* Make sure the authenticate bit is set, when encrypt bit is set */ + if (sec_level & BTM_SEC_OUT_ENCRYPT) sec_level |= BTM_SEC_OUT_AUTHENTICATE; - /* outgoing connections usually set the security level right before - * the connection is initiated. - * set it to be the outgoing service */ +/* outgoing connections usually set the security level right before + * the connection is initiated. + * set it to be the outgoing service */ #if (L2CAP_UCD_INCLUDED == TRUE) - if ( is_ucd == false ) + if (is_ucd == false) #endif - { - btm_cb.p_out_serv = p_srec; - } - } - else { - p_srec->term_mx_chan_id = mx_chan_id; + btm_cb.p_out_serv = p_srec; + } + } else { + p_srec->term_mx_chan_id = mx_chan_id; #if BTM_SEC_SERVICE_NAME_LEN > 0 - strlcpy ((char *)p_srec->term_service_name, p_name, BTM_SEC_SERVICE_NAME_LEN + 1); + strlcpy((char*)p_srec->term_service_name, p_name, + BTM_SEC_SERVICE_NAME_LEN + 1); #endif - /* clear out the old setting, just in case it exists */ +/* clear out the old setting, just in case it exists */ #if (L2CAP_UCD_INCLUDED == TRUE) - if ( is_ucd ) - { - p_srec->ucd_security_flags &= - ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_MITM | - BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE - | BTM_SEC_IN_MIN_16_DIGIT_PIN); - } - else + if (is_ucd) { + p_srec->ucd_security_flags &= + ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | + BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_MITM | BTM_SEC_FORCE_MASTER | + BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | + BTM_SEC_ATTEMPT_SLAVE | BTM_SEC_IN_MIN_16_DIGIT_PIN); + } else #endif - { - p_srec->security_flags &= - ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_MITM | - BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE - | BTM_SEC_IN_MIN_16_DIGIT_PIN); - } - - /* Parameter validation. Acceptor should not set requirements for outgoing connections */ - sec_level &= ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM); + { + p_srec->security_flags &= + ~(BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT | + BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_MITM | BTM_SEC_FORCE_MASTER | + BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | + BTM_SEC_ATTEMPT_SLAVE | BTM_SEC_IN_MIN_16_DIGIT_PIN); + } - if (btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) - { - if (sec_level & BTM_SEC_IN_AUTHENTICATE) - sec_level |= BTM_SEC_IN_MITM; - } + /* Parameter validation. Acceptor should not set requirements for outgoing + * connections */ + sec_level &= ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_ENCRYPT | + BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_MITM); - /* Make sure the authenticate bit is set, when encrypt bit is set */ - if (sec_level & BTM_SEC_IN_ENCRYPT) - sec_level |= BTM_SEC_IN_AUTHENTICATE; + if (btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) { + if (sec_level & BTM_SEC_IN_AUTHENTICATE) sec_level |= BTM_SEC_IN_MITM; } + /* Make sure the authenticate bit is set, when encrypt bit is set */ + if (sec_level & BTM_SEC_IN_ENCRYPT) sec_level |= BTM_SEC_IN_AUTHENTICATE; + } + #if (L2CAP_UCD_INCLUDED == TRUE) - if ( is_ucd ) - { - p_srec->security_flags |= (uint16_t)(BTM_SEC_IN_USE); - p_srec->ucd_security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); - } - else - { - p_srec->security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); - } + if (is_ucd) { + p_srec->security_flags |= (uint16_t)(BTM_SEC_IN_USE); + p_srec->ucd_security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); + } else { + p_srec->security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); + } - BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, conn_type 0x%x, psm 0x%04x, proto_id %d, chan_id %d", - index, service_id, conn_type, psm, mx_proto_id, mx_chan_id); + BTM_TRACE_API( + "BTM_SEC_REG[%d]: id %d, conn_type 0x%x, psm 0x%04x, proto_id %d, " + "chan_id %d", + index, service_id, conn_type, psm, mx_proto_id, mx_chan_id); - BTM_TRACE_API(" : security_flags: 0x%04x, ucd_security_flags: 0x%04x", - p_srec->security_flags, p_srec->ucd_security_flags); + BTM_TRACE_API( + " : security_flags: 0x%04x, ucd_security_flags: 0x%04x", + p_srec->security_flags, p_srec->ucd_security_flags); #if BTM_SEC_SERVICE_NAME_LEN > 0 - BTM_TRACE_API(" : service name [%s] (up to %d chars saved)", - p_name, BTM_SEC_SERVICE_NAME_LEN); + BTM_TRACE_API(" : service name [%s] (up to %d chars saved)", + p_name, BTM_SEC_SERVICE_NAME_LEN); #endif #else - p_srec->security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); + p_srec->security_flags |= (uint16_t)(sec_level | BTM_SEC_IN_USE); - BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, is_orig %d, psm 0x%04x, proto_id %d, chan_id %d", - index, service_id, is_originator, psm, mx_proto_id, mx_chan_id); + BTM_TRACE_API( + "BTM_SEC_REG[%d]: id %d, is_orig %d, psm 0x%04x, proto_id %d, chan_id %d", + index, service_id, is_originator, psm, mx_proto_id, mx_chan_id); #if BTM_SEC_SERVICE_NAME_LEN > 0 - BTM_TRACE_API(" : sec: 0x%x, service name [%s] (up to %d chars saved)", - p_srec->security_flags, p_name, BTM_SEC_SERVICE_NAME_LEN); + BTM_TRACE_API( + " : sec: 0x%x, service name [%s] (up to %d chars saved)", + p_srec->security_flags, p_name, BTM_SEC_SERVICE_NAME_LEN); #endif #endif - return(record_allocated); + return (record_allocated); } /******************************************************************************* @@ -734,28 +710,26 @@ static bool btm_sec_set_security_level (CONNECTION_TYPE conn_type, const char * Returns Number of records that were freed. * ******************************************************************************/ -uint8_t BTM_SecClrService (uint8_t service_id) -{ - tBTM_SEC_SERV_REC *p_srec = &btm_cb.sec_serv_rec[0]; - uint8_t num_freed = 0; - int i; - - for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_srec++) - { - /* Delete services with specified name (if in use and not SDP) */ - if ((p_srec->security_flags & BTM_SEC_IN_USE) && (p_srec->psm != BT_PSM_SDP) && - (!service_id || (service_id == p_srec->service_id))) - { - BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d", i, service_id); - p_srec->security_flags = 0; +uint8_t BTM_SecClrService(uint8_t service_id) { + tBTM_SEC_SERV_REC* p_srec = &btm_cb.sec_serv_rec[0]; + uint8_t num_freed = 0; + int i; + + for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_srec++) { + /* Delete services with specified name (if in use and not SDP) */ + if ((p_srec->security_flags & BTM_SEC_IN_USE) && + (p_srec->psm != BT_PSM_SDP) && + (!service_id || (service_id == p_srec->service_id))) { + BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d", i, service_id); + p_srec->security_flags = 0; #if (L2CAP_UCD_INCLUDED == TRUE) - p_srec->ucd_security_flags = 0; + p_srec->ucd_security_flags = 0; #endif - num_freed++; - } + num_freed++; } + } - return(num_freed); + return (num_freed); } /******************************************************************************* @@ -774,25 +748,23 @@ uint8_t BTM_SecClrService (uint8_t service_id) * Returns Number of records that were freed. * ******************************************************************************/ -uint8_t btm_sec_clr_service_by_psm (uint16_t psm) -{ - tBTM_SEC_SERV_REC *p_srec = &btm_cb.sec_serv_rec[0]; - uint8_t num_freed = 0; - int i; - - for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_srec++) - { - /* Delete services with specified name (if in use and not SDP) */ - if ((p_srec->security_flags & BTM_SEC_IN_USE) && (p_srec->psm == psm) ) - { - BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d ", i, p_srec->service_id); - p_srec->security_flags = 0; - num_freed++; - } - } - BTM_TRACE_API("btm_sec_clr_service_by_psm psm:0x%x num_freed:%d", psm, num_freed); - - return(num_freed); +uint8_t btm_sec_clr_service_by_psm(uint16_t psm) { + tBTM_SEC_SERV_REC* p_srec = &btm_cb.sec_serv_rec[0]; + uint8_t num_freed = 0; + int i; + + for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_srec++) { + /* Delete services with specified name (if in use and not SDP) */ + if ((p_srec->security_flags & BTM_SEC_IN_USE) && (p_srec->psm == psm)) { + BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d ", i, p_srec->service_id); + p_srec->security_flags = 0; + num_freed++; + } + } + BTM_TRACE_API("btm_sec_clr_service_by_psm psm:0x%x num_freed:%d", psm, + num_freed); + + return (num_freed); } /******************************************************************************* @@ -807,25 +779,26 @@ uint8_t btm_sec_clr_service_by_psm (uint16_t psm) * Returns void. * ******************************************************************************/ -void btm_sec_clr_temp_auth_service (BD_ADDR bda) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - p_dev_rec = btm_find_dev(bda); - if (p_dev_rec == NULL) - { - BTM_TRACE_WARNING ("btm_sec_clr_temp_auth_service() - no dev CB"); - return; - } - - /* Reset the temporary authorized flag so that next time (untrusted) service is accessed autorization will take place */ - if (p_dev_rec->last_author_service_id != BTM_SEC_NO_LAST_SERVICE_ID && p_dev_rec->p_cur_service) - { - BTM_TRACE_DEBUG ("btm_sec_clr_auth_service_by_psm [clearing device: %02x:%02x:%02x:%02x:%02x:%02x]", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); +void btm_sec_clr_temp_auth_service(BD_ADDR bda) { + tBTM_SEC_DEV_REC* p_dev_rec; - p_dev_rec->last_author_service_id = BTM_SEC_NO_LAST_SERVICE_ID; - } + p_dev_rec = btm_find_dev(bda); + if (p_dev_rec == NULL) { + BTM_TRACE_WARNING("btm_sec_clr_temp_auth_service() - no dev CB"); + return; + } + + /* Reset the temporary authorized flag so that next time (untrusted) service + * is accessed autorization will take place */ + if (p_dev_rec->last_author_service_id != BTM_SEC_NO_LAST_SERVICE_ID && + p_dev_rec->p_cur_service) { + BTM_TRACE_DEBUG( + "btm_sec_clr_auth_service_by_psm [clearing device: " + "%02x:%02x:%02x:%02x:%02x:%02x]", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + + p_dev_rec->last_author_service_id = BTM_SEC_NO_LAST_SERVICE_ID; + } } /******************************************************************************* @@ -845,111 +818,112 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda) * (array of uint32_t) * ******************************************************************************/ -void BTM_PINCodeReply (BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, uint8_t *p_pin, uint32_t trusted_mask[]) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - BTM_TRACE_API ("BTM_PINCodeReply(): PairState: %s PairFlags: 0x%02x PinLen:%d Result:%d", - btm_pair_state_descr(btm_cb.pairing_state), btm_cb.pairing_flags, pin_len, res); - - /* If timeout already expired or has been canceled, ignore the reply */ - if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_PIN) - { - BTM_TRACE_WARNING ("BTM_PINCodeReply() - Wrong State: %d", btm_cb.pairing_state); - return; - } - - if (memcmp (bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) - { - BTM_TRACE_ERROR ("BTM_PINCodeReply() - Wrong BD Addr"); - return; - } - - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR ("BTM_PINCodeReply() - no dev CB"); - return; - } +void BTM_PINCodeReply(BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, + uint8_t* p_pin, uint32_t trusted_mask[]) { + tBTM_SEC_DEV_REC* p_dev_rec; + + BTM_TRACE_API( + "BTM_PINCodeReply(): PairState: %s PairFlags: 0x%02x PinLen:%d " + "Result:%d", + btm_pair_state_descr(btm_cb.pairing_state), btm_cb.pairing_flags, pin_len, + res); + + /* If timeout already expired or has been canceled, ignore the reply */ + if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_PIN) { + BTM_TRACE_WARNING("BTM_PINCodeReply() - Wrong State: %d", + btm_cb.pairing_state); + return; + } - if ( (pin_len > PIN_CODE_LEN) || (pin_len == 0) || (p_pin == NULL) ) - res = BTM_ILLEGAL_VALUE; + if (memcmp(bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) { + BTM_TRACE_ERROR("BTM_PINCodeReply() - Wrong BD Addr"); + return; + } - if (res != BTM_SUCCESS) - { - /* if peer started dd OR we started dd and pre-fetch pin was not used send negative reply */ - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PEER_STARTED_DD) || - ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && - (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE)) ) - { - /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed event */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - - btsnd_hcic_pin_code_neg_reply (bd_addr); - } - else - { - p_dev_rec->security_required = BTM_SEC_NONE; - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - } - return; - } - if (trusted_mask) - BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); - p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_AUTHED; - p_dev_rec->pin_code_length = pin_len; - if (pin_len >= 16) { - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("BTM_PINCodeReply() - no dev CB"); + return; + } + + if ((pin_len > PIN_CODE_LEN) || (pin_len == 0) || (p_pin == NULL)) + res = BTM_ILLEGAL_VALUE; + + if (res != BTM_SUCCESS) { + /* if peer started dd OR we started dd and pre-fetch pin was not used send + * negative reply */ + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PEER_STARTED_DD) || + ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE))) { + /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed + * event */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + + btsnd_hcic_pin_code_neg_reply(bd_addr); + } else { + p_dev_rec->security_required = BTM_SEC_NONE; + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); } - - if ( (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - && (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) - && (btm_cb.security_mode_changed == false) ) - { - /* This is start of the dedicated bonding if local device is 2.0 */ - btm_cb.pin_code_len = pin_len; - memcpy (btm_cb.pin_code, p_pin, pin_len); - - btm_cb.security_mode_changed = true; + return; + } + if (trusted_mask) + BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); + p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_AUTHED; + p_dev_rec->pin_code_length = pin_len; + if (pin_len >= 16) { + p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + } + + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) && + (btm_cb.security_mode_changed == false)) { + /* This is start of the dedicated bonding if local device is 2.0 */ + btm_cb.pin_code_len = pin_len; + memcpy(btm_cb.pin_code, p_pin, pin_len); + + btm_cb.security_mode_changed = true; #ifdef APPL_AUTH_WRITE_EXCEPTION - if(!(APPL_AUTH_WRITE_EXCEPTION)(p_dev_rec->bd_addr)) + if (!(APPL_AUTH_WRITE_EXCEPTION)(p_dev_rec->bd_addr)) #endif - btsnd_hcic_write_auth_enable (true); - - btm_cb.acl_disc_reason = 0xff ; - - /* if we rejected incoming connection request, we have to wait HCI_Connection_Complete event */ - /* before originating */ - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) - { - BTM_TRACE_WARNING ("BTM_PINCodeReply(): waiting HCI_Connection_Complete after rejected incoming connection"); - /* we change state little bit early so btm_sec_connected() will originate connection */ - /* when existing ACL link is down completely */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); - } - /* if we already accepted incoming connection from pairing device */ - else if (p_dev_rec->sm4 & BTM_SM4_CONN_PEND) - { - BTM_TRACE_WARNING ("BTM_PINCodeReply(): link is connecting so wait pin code request from peer"); - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); - } - else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_AUTHED; - - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_ERR_AUTH_FAILURE); - } - return; + btsnd_hcic_write_auth_enable(true); + + btm_cb.acl_disc_reason = 0xff; + + /* if we rejected incoming connection request, we have to wait + * HCI_Connection_Complete event */ + /* before originating */ + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) { + BTM_TRACE_WARNING( + "BTM_PINCodeReply(): waiting HCI_Connection_Complete after rejected " + "incoming connection"); + /* we change state little bit early so btm_sec_connected() will originate + * connection */ + /* when existing ACL link is down completely */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); + } + /* if we already accepted incoming connection from pairing device */ + else if (p_dev_rec->sm4 & BTM_SM4_CONN_PEND) { + BTM_TRACE_WARNING( + "BTM_PINCodeReply(): link is connecting so wait pin code request " + "from peer"); + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); + } else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) { + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_AUTHED; + + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_ERR_AUTH_FAILURE); } + return; + } - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - btm_cb.acl_disc_reason = HCI_SUCCESS; + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + btm_cb.acl_disc_reason = HCI_SUCCESS; - btsnd_hcic_pin_code_req_reply (bd_addr, pin_len, p_pin); + btsnd_hcic_pin_code_req_reply(bd_addr, pin_len, p_pin); } /******************************************************************************* @@ -966,173 +940,163 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, uint8_t *p * * Note: After 2.1 parameters are not used and preserved here not to change API ******************************************************************************/ -tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, - uint8_t pin_len, uint8_t *p_pin, uint32_t trusted_mask[]) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_STATUS status; - uint8_t *p_features; - uint8_t ii; - tACL_CONN *p= btm_bda_to_acl(bd_addr, transport); - BTM_TRACE_API ("btm_sec_bond_by_transport BDA: %02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - - BTM_TRACE_DEBUG("btm_sec_bond_by_transport: Transport used %d" , transport); - - /* Other security process is in progress */ - if (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - { - BTM_TRACE_ERROR ("BTM_SecBond: already busy in state: %s", btm_pair_state_descr(btm_cb.pairing_state)); - return(BTM_WRONG_MODE); - } - - p_dev_rec = btm_find_or_alloc_dev(bd_addr); - if (p_dev_rec == NULL) - { - return(BTM_NO_RESOURCES); - } - - if (!controller_get_interface()->get_is_ready()) - { - BTM_TRACE_ERROR ("%s controller module is not ready", __func__); - return(BTM_NO_RESOURCES); - } - - BTM_TRACE_DEBUG ("before update sec_flags=0x%x", p_dev_rec->sec_flags); - - /* Finished if connection is active and already paired */ - if (((p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) && transport == BT_TRANSPORT_BR_EDR - && (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) || - ((p_dev_rec->ble_hci_handle != BTM_SEC_INVALID_HANDLE) && transport == BT_TRANSPORT_LE - && (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED))) - { - BTM_TRACE_WARNING("BTM_SecBond -> Already Paired"); - return(BTM_SUCCESS); - } - - /* Tell controller to get rid of the link key if it has one stored */ - if ((BTM_DeleteStoredLinkKey (bd_addr, NULL)) != BTM_SUCCESS) - return(BTM_NO_RESOURCES); - - /* Save the PIN code if we got a valid one */ - if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) - { - btm_cb.pin_code_len = pin_len; - p_dev_rec->pin_code_length = pin_len; - memcpy (btm_cb.pin_code, p_pin, PIN_CODE_LEN); - } - - memcpy (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); - - btm_cb.pairing_flags = BTM_PAIR_FLAGS_WE_STARTED_DD; - - p_dev_rec->security_required = BTM_SEC_OUT_AUTHENTICATE; - p_dev_rec->is_originator = true; - if (trusted_mask) - BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); - - if (transport == BT_TRANSPORT_LE) - { - btm_ble_init_pseudo_addr (p_dev_rec, bd_addr); - p_dev_rec->sec_flags &= ~ BTM_SEC_LE_MASK; - - if (SMP_Pair(bd_addr) == SMP_STARTED) - { - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; - p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - return BTM_CMD_STARTED; - } - - btm_cb.pairing_flags = 0; - return(BTM_NO_RESOURCES); - } - - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED - | BTM_SEC_ROLE_SWITCHED | BTM_SEC_LINK_KEY_AUTHED); - - BTM_TRACE_DEBUG ("after update sec_flags=0x%x", p_dev_rec->sec_flags); - if (!controller_get_interface()->supports_simple_pairing()) - { - /* The special case when we authenticate keyboard. Set pin type to fixed */ - /* It would be probably better to do it from the application, but it is */ - /* complicated */ - if (((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == BTM_COD_MAJOR_PERIPHERAL) - && (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD) - && (btm_cb.cfg.pin_type != HCI_PIN_TYPE_FIXED)) - { - btm_cb.pin_type_changed = true; - btsnd_hcic_write_pin_type (HCI_PIN_TYPE_FIXED); - } - } - - for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) - { - p_features = p_dev_rec->features[ii]; - BTM_TRACE_EVENT(" remote_features page[%1d] = %02x-%02x-%02x-%02x", - ii, p_features[0], p_features[1], p_features[2], p_features[3]); - BTM_TRACE_EVENT(" %02x-%02x-%02x-%02x", - p_features[4], p_features[5], p_features[6], p_features[7]); - } - - BTM_TRACE_EVENT ("BTM_SecBond: Remote sm4: 0x%x HCI Handle: 0x%04x", p_dev_rec->sm4, p_dev_rec->hci_handle); +tBTM_STATUS btm_sec_bond_by_transport(BD_ADDR bd_addr, tBT_TRANSPORT transport, + uint8_t pin_len, uint8_t* p_pin, + uint32_t trusted_mask[]) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_STATUS status; + uint8_t* p_features; + uint8_t ii; + tACL_CONN* p = btm_bda_to_acl(bd_addr, transport); + BTM_TRACE_API("btm_sec_bond_by_transport BDA: %02x:%02x:%02x:%02x:%02x:%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + + BTM_TRACE_DEBUG("btm_sec_bond_by_transport: Transport used %d", transport); + + /* Other security process is in progress */ + if (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) { + BTM_TRACE_ERROR("BTM_SecBond: already busy in state: %s", + btm_pair_state_descr(btm_cb.pairing_state)); + return (BTM_WRONG_MODE); + } + + p_dev_rec = btm_find_or_alloc_dev(bd_addr); + if (p_dev_rec == NULL) { + return (BTM_NO_RESOURCES); + } + + if (!controller_get_interface()->get_is_ready()) { + BTM_TRACE_ERROR("%s controller module is not ready", __func__); + return (BTM_NO_RESOURCES); + } + + BTM_TRACE_DEBUG("before update sec_flags=0x%x", p_dev_rec->sec_flags); + + /* Finished if connection is active and already paired */ + if (((p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) && + transport == BT_TRANSPORT_BR_EDR && + (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) || + ((p_dev_rec->ble_hci_handle != BTM_SEC_INVALID_HANDLE) && + transport == BT_TRANSPORT_LE && + (p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED))) { + BTM_TRACE_WARNING("BTM_SecBond -> Already Paired"); + return (BTM_SUCCESS); + } + + /* Tell controller to get rid of the link key if it has one stored */ + if ((BTM_DeleteStoredLinkKey(bd_addr, NULL)) != BTM_SUCCESS) + return (BTM_NO_RESOURCES); + + /* Save the PIN code if we got a valid one */ + if (p_pin && (pin_len <= PIN_CODE_LEN) && (pin_len != 0)) { + btm_cb.pin_code_len = pin_len; + p_dev_rec->pin_code_length = pin_len; + memcpy(btm_cb.pin_code, p_pin, PIN_CODE_LEN); + } + + memcpy(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); + + btm_cb.pairing_flags = BTM_PAIR_FLAGS_WE_STARTED_DD; + + p_dev_rec->security_required = BTM_SEC_OUT_AUTHENTICATE; + p_dev_rec->is_originator = true; + if (trusted_mask) + BTM_SEC_COPY_TRUSTED_DEVICE(trusted_mask, p_dev_rec->trusted_mask); + + if (transport == BT_TRANSPORT_LE) { + btm_ble_init_pseudo_addr(p_dev_rec, bd_addr); + p_dev_rec->sec_flags &= ~BTM_SEC_LE_MASK; + + if (SMP_Pair(bd_addr) == SMP_STARTED) { + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; + p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + return BTM_CMD_STARTED; + } + + btm_cb.pairing_flags = 0; + return (BTM_NO_RESOURCES); + } + + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED | + BTM_SEC_ROLE_SWITCHED | BTM_SEC_LINK_KEY_AUTHED); + + BTM_TRACE_DEBUG("after update sec_flags=0x%x", p_dev_rec->sec_flags); + if (!controller_get_interface()->supports_simple_pairing()) { + /* The special case when we authenticate keyboard. Set pin type to fixed */ + /* It would be probably better to do it from the application, but it is */ + /* complicated */ + if (((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == + BTM_COD_MAJOR_PERIPHERAL) && + (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD) && + (btm_cb.cfg.pin_type != HCI_PIN_TYPE_FIXED)) { + btm_cb.pin_type_changed = true; + btsnd_hcic_write_pin_type(HCI_PIN_TYPE_FIXED); + } + } + + for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) { + p_features = p_dev_rec->features[ii]; + BTM_TRACE_EVENT(" remote_features page[%1d] = %02x-%02x-%02x-%02x", ii, + p_features[0], p_features[1], p_features[2], p_features[3]); + BTM_TRACE_EVENT(" %02x-%02x-%02x-%02x", + p_features[4], p_features[5], p_features[6], p_features[7]); + } + + BTM_TRACE_EVENT("BTM_SecBond: Remote sm4: 0x%x HCI Handle: 0x%04x", + p_dev_rec->sm4, p_dev_rec->hci_handle); #if (BTM_SEC_FORCE_RNR_FOR_DBOND == TRUE) - p_dev_rec->sec_flags &= ~BTM_SEC_NAME_KNOWN; + p_dev_rec->sec_flags &= ~BTM_SEC_NAME_KNOWN; #endif - /* If connection already exists... */ - if (p && p->hci_handle != BTM_SEC_INVALID_HANDLE) - { - btm_sec_start_authentication(p_dev_rec); - - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); - - /* Mark lcb as bonding */ - l2cu_update_lcb_4_bonding (bd_addr, true); - return(BTM_CMD_STARTED); - } - - BTM_TRACE_DEBUG ("sec mode: %d sm4:x%x", btm_cb.security_mode, p_dev_rec->sm4); - if (!controller_get_interface()->supports_simple_pairing() - || (p_dev_rec->sm4 == BTM_SM4_KNOWN)) - { - if ( btm_sec_check_prefetch_pin (p_dev_rec) ) - return (BTM_CMD_STARTED); - } - if ((btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) && - BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) - { - /* local is 2.1 and peer is unknown */ - if ((p_dev_rec->sm4 & BTM_SM4_CONN_PEND) == 0) - { - /* we are not accepting connection request from peer - * -> RNR (to learn if peer is 2.1) - * RNR when no ACL causes HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_GET_REM_NAME); - BTM_ReadRemoteDeviceName(bd_addr, NULL, BT_TRANSPORT_BR_EDR); - } - else - { - /* We are accepting connection request from peer */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); - } - BTM_TRACE_DEBUG ("State:%s sm4: 0x%x sec_state:%d", - btm_pair_state_descr (btm_cb.pairing_state), p_dev_rec->sm4, p_dev_rec->sec_state); - return BTM_CMD_STARTED; + /* If connection already exists... */ + if (p && p->hci_handle != BTM_SEC_INVALID_HANDLE) { + btm_sec_start_authentication(p_dev_rec); + + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); + + /* Mark lcb as bonding */ + l2cu_update_lcb_4_bonding(bd_addr, true); + return (BTM_CMD_STARTED); + } + + BTM_TRACE_DEBUG("sec mode: %d sm4:x%x", btm_cb.security_mode, p_dev_rec->sm4); + if (!controller_get_interface()->supports_simple_pairing() || + (p_dev_rec->sm4 == BTM_SM4_KNOWN)) { + if (btm_sec_check_prefetch_pin(p_dev_rec)) return (BTM_CMD_STARTED); + } + if ((btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) && + BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) { + /* local is 2.1 and peer is unknown */ + if ((p_dev_rec->sm4 & BTM_SM4_CONN_PEND) == 0) { + /* we are not accepting connection request from peer + * -> RNR (to learn if peer is 2.1) + * RNR when no ACL causes HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_GET_REM_NAME); + BTM_ReadRemoteDeviceName(bd_addr, NULL, BT_TRANSPORT_BR_EDR); + } else { + /* We are accepting connection request from peer */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); } + BTM_TRACE_DEBUG("State:%s sm4: 0x%x sec_state:%d", + btm_pair_state_descr(btm_cb.pairing_state), p_dev_rec->sm4, + p_dev_rec->sec_state); + return BTM_CMD_STARTED; + } - /* both local and peer are 2.1 */ - status = btm_sec_dd_create_conn(p_dev_rec); + /* both local and peer are 2.1 */ + status = btm_sec_dd_create_conn(p_dev_rec); - if (status != BTM_CMD_STARTED) - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - } + if (status != BTM_CMD_STARTED) { + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + } - return status; + return status; } /******************************************************************************* @@ -1152,20 +1116,21 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, * * Note: After 2.1 parameters are not used and preserved here not to change API ******************************************************************************/ -tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport, - uint8_t pin_len, uint8_t *p_pin, uint32_t trusted_mask[]) -{ - tBT_DEVICE_TYPE dev_type; - tBLE_ADDR_TYPE addr_type; - - BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); - /* LE device, do SMP pairing */ - if ((transport == BT_TRANSPORT_LE && (dev_type & BT_DEVICE_TYPE_BLE) == 0) || - (transport == BT_TRANSPORT_BR_EDR && (dev_type & BT_DEVICE_TYPE_BREDR) == 0)) - { - return BTM_ILLEGAL_ACTION; - } - return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); +tBTM_STATUS BTM_SecBondByTransport(BD_ADDR bd_addr, tBT_TRANSPORT transport, + uint8_t pin_len, uint8_t* p_pin, + uint32_t trusted_mask[]) { + tBT_DEVICE_TYPE dev_type; + tBLE_ADDR_TYPE addr_type; + + BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); + /* LE device, do SMP pairing */ + if ((transport == BT_TRANSPORT_LE && (dev_type & BT_DEVICE_TYPE_BLE) == 0) || + (transport == BT_TRANSPORT_BR_EDR && + (dev_type & BT_DEVICE_TYPE_BREDR) == 0)) { + return BTM_ILLEGAL_ACTION; + } + return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, + trusted_mask); } /******************************************************************************* @@ -1184,12 +1149,12 @@ tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, tBT_TRANSPORT transport, * * Note: After 2.1 parameters are not used and preserved here not to change API ******************************************************************************/ -tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, uint8_t pin_len, uint8_t *p_pin, uint32_t trusted_mask[]) -{ - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - if (BTM_UseLeLink(bd_addr)) - transport = BT_TRANSPORT_LE; - return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, trusted_mask); +tBTM_STATUS BTM_SecBond(BD_ADDR bd_addr, uint8_t pin_len, uint8_t* p_pin, + uint32_t trusted_mask[]) { + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + if (BTM_UseLeLink(bd_addr)) transport = BT_TRANSPORT_LE; + return btm_sec_bond_by_transport(bd_addr, transport, pin_len, p_pin, + trusted_mask); } /******************************************************************************* * @@ -1202,78 +1167,71 @@ tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, uint8_t pin_len, uint8_t *p_pin, uint3 * transport - false for BR/EDR link; true for LE link * ******************************************************************************/ -tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - BTM_TRACE_API ("BTM_SecBondCancel() State: %s flags:0x%x", - btm_pair_state_descr (btm_cb.pairing_state), btm_cb.pairing_flags); +tBTM_STATUS BTM_SecBondCancel(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec; - if (((p_dev_rec = btm_find_dev (bd_addr)) == NULL) - || (memcmp (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0) ) - return BTM_UNKNOWN_ADDR; + BTM_TRACE_API("BTM_SecBondCancel() State: %s flags:0x%x", + btm_pair_state_descr(btm_cb.pairing_state), + btm_cb.pairing_flags); - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) - { - if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) - { - BTM_TRACE_DEBUG ("Cancel LE pairing"); - if (SMP_PairCancel(bd_addr)) - { - return BTM_CMD_STARTED; - } - } - return BTM_WRONG_MODE; - } + if (((p_dev_rec = btm_find_dev(bd_addr)) == NULL) || + (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0)) + return BTM_UNKNOWN_ADDR; - BTM_TRACE_DEBUG ("hci_handle:0x%x sec_state:%d", p_dev_rec->hci_handle, p_dev_rec->sec_state ); - if (BTM_PAIR_STATE_WAIT_LOCAL_PIN == btm_cb.pairing_state && - BTM_PAIR_FLAGS_WE_STARTED_DD & btm_cb.pairing_flags) - { - /* pre-fetching pin for dedicated bonding */ - btm_sec_bond_cancel_complete(); - return BTM_SUCCESS; + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) { + if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) { + BTM_TRACE_DEBUG("Cancel LE pairing"); + if (SMP_PairCancel(bd_addr)) { + return BTM_CMD_STARTED; + } } - - /* If this BDA is in a bonding procedure */ - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) - { - /* If the HCI link is up */ - if (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) - { - /* If some other thread disconnecting, we do not send second command */ - if ((p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING) || - (p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH)) - return(BTM_CMD_STARTED); - - /* If the HCI link was set up by Bonding process */ - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) - return btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_PEER_USER, p_dev_rec->hci_handle); - else - l2cu_update_lcb_4_bonding(bd_addr, false); - - return BTM_NOT_AUTHORIZED; - } - else /*HCI link is not up */ - { - /* If the HCI link creation was started by Bonding process */ - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) - { - btsnd_hcic_create_conn_cancel(bd_addr); - return BTM_CMD_STARTED; - } - if (btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME) - { - BTM_CancelRemoteDeviceName(); - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_WE_CANCEL_DD; - return BTM_CMD_STARTED; - } - return BTM_NOT_AUTHORIZED; - } + return BTM_WRONG_MODE; + } + + BTM_TRACE_DEBUG("hci_handle:0x%x sec_state:%d", p_dev_rec->hci_handle, + p_dev_rec->sec_state); + if (BTM_PAIR_STATE_WAIT_LOCAL_PIN == btm_cb.pairing_state && + BTM_PAIR_FLAGS_WE_STARTED_DD & btm_cb.pairing_flags) { + /* pre-fetching pin for dedicated bonding */ + btm_sec_bond_cancel_complete(); + return BTM_SUCCESS; + } + + /* If this BDA is in a bonding procedure */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) { + /* If the HCI link is up */ + if (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) { + /* If some other thread disconnecting, we do not send second command */ + if ((p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING) || + (p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH)) + return (BTM_CMD_STARTED); + + /* If the HCI link was set up by Bonding process */ + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) + return btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_PEER_USER, + p_dev_rec->hci_handle); + else + l2cu_update_lcb_4_bonding(bd_addr, false); + + return BTM_NOT_AUTHORIZED; + } else /*HCI link is not up */ + { + /* If the HCI link creation was started by Bonding process */ + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) { + btsnd_hcic_create_conn_cancel(bd_addr); + return BTM_CMD_STARTED; + } + if (btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME) { + BTM_CancelRemoteDeviceName(); + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_WE_CANCEL_DD; + return BTM_CMD_STARTED; + } + return BTM_NOT_AUTHORIZED; } + } - return BTM_WRONG_MODE; + return BTM_WRONG_MODE; } /******************************************************************************* @@ -1289,17 +1247,15 @@ tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr) * link_key - Link Key is copied into this array * ******************************************************************************/ -tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr, LINK_KEY link_key) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - if (((p_dev_rec = btm_find_dev (bd_addr)) != NULL) - && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) - { - memcpy (link_key, p_dev_rec->link_key, LINK_KEY_LEN); - return(BTM_SUCCESS); - } - return(BTM_UNKNOWN_ADDR); +tBTM_STATUS BTM_SecGetDeviceLinkKey(BD_ADDR bd_addr, LINK_KEY link_key) { + tBTM_SEC_DEV_REC* p_dev_rec; + + if (((p_dev_rec = btm_find_dev(bd_addr)) != NULL) && + (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) { + memcpy(link_key, p_dev_rec->link_key, LINK_KEY_LEN); + return (BTM_SUCCESS); + } + return (BTM_UNKNOWN_ADDR); } /******************************************************************************* @@ -1316,15 +1272,13 @@ tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr, LINK_KEY link_key) * otherwise. * ******************************************************************************/ -tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if ((p_dev_rec != NULL) && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) - { - return p_dev_rec->link_key_type; - } - return BTM_LKEY_TYPE_IGNORE; + if ((p_dev_rec != NULL) && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) { + return p_dev_rec->link_key_type; + } + return BTM_LKEY_TYPE_IGNORE; } /******************************************************************************* @@ -1354,193 +1308,182 @@ tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr) * BTM_MODE_UNSUPPORTED - if security manager not linked in. * ******************************************************************************/ -tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SEC_CBACK *p_callback, - void *p_ref_data, tBTM_BLE_SEC_ACT sec_act) -{ - tBTM_STATUS rc = 0; - - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - if (!p_dev_rec || - (transport == BT_TRANSPORT_BR_EDR && p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) || - (transport == BT_TRANSPORT_LE && p_dev_rec->ble_hci_handle == BTM_SEC_INVALID_HANDLE)) - { - /* Connection should be up and runnning */ - BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption not connected"); - - if (p_callback) - (*p_callback) (bd_addr, transport, p_ref_data, BTM_WRONG_MODE); +tBTM_STATUS BTM_SetEncryption(BD_ADDR bd_addr, tBT_TRANSPORT transport, + tBTM_SEC_CBACK* p_callback, void* p_ref_data, + tBTM_BLE_SEC_ACT sec_act) { + tBTM_STATUS rc = 0; + + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (!p_dev_rec || (transport == BT_TRANSPORT_BR_EDR && + p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) || + (transport == BT_TRANSPORT_LE && + p_dev_rec->ble_hci_handle == BTM_SEC_INVALID_HANDLE)) { + /* Connection should be up and runnning */ + BTM_TRACE_WARNING("Security Manager: BTM_SetEncryption not connected"); + + if (p_callback) + (*p_callback)(bd_addr, transport, p_ref_data, BTM_WRONG_MODE); + + return (BTM_WRONG_MODE); + } + + if (transport == BT_TRANSPORT_BR_EDR && + (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED)) { + BTM_TRACE_EVENT("Security Manager: BTM_SetEncryption already encrypted"); + + if (p_callback) (*p_callback)(bd_addr, transport, p_ref_data, BTM_SUCCESS); + + return (BTM_SUCCESS); + } + + /* enqueue security request if security is active */ + if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) { + BTM_TRACE_WARNING( + "Security Manager: BTM_SetEncryption busy, enqueue request"); + + if (btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, + p_ref_data, sec_act)) { + return BTM_CMD_STARTED; + } else { + if (p_callback) + (*p_callback)(bd_addr, transport, p_ref_data, BTM_NO_RESOURCES); + return BTM_NO_RESOURCES; + } + } + + p_dev_rec->p_callback = p_callback; + p_dev_rec->p_ref_data = p_ref_data; + p_dev_rec->security_required |= + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT); + p_dev_rec->is_originator = false; + + BTM_TRACE_API( + "Security Manager: BTM_SetEncryption Handle:%d State:%d Flags:0x%x " + "Required:0x%x", + p_dev_rec->hci_handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, + p_dev_rec->security_required); + + if (transport == BT_TRANSPORT_LE) { + tACL_CONN* p = btm_bda_to_acl(bd_addr, transport); + if (p) { + rc = btm_ble_set_encryption(bd_addr, sec_act, p->link_role); + } else { + rc = BTM_WRONG_MODE; + BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL", + __func__); + } + } else { + rc = btm_sec_execute_procedure(p_dev_rec); + } - return(BTM_WRONG_MODE); + if (rc != BTM_CMD_STARTED && rc != BTM_BUSY) { + if (p_callback) { + p_dev_rec->p_callback = NULL; + (*p_callback)(bd_addr, transport, p_dev_rec->p_ref_data, rc); } + } - if (transport == BT_TRANSPORT_BR_EDR && - (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED)) - { - BTM_TRACE_EVENT ("Security Manager: BTM_SetEncryption already encrypted"); + return (rc); +} - if (p_callback) - (*p_callback) (bd_addr, transport, p_ref_data, BTM_SUCCESS); +/******************************************************************************* + * disconnect the ACL link, if it's not done yet. + ******************************************************************************/ +static tBTM_STATUS btm_sec_send_hci_disconnect(tBTM_SEC_DEV_REC* p_dev_rec, + uint8_t reason, + uint16_t conn_handle) { + uint8_t old_state = p_dev_rec->sec_state; + tBTM_STATUS status = BTM_CMD_STARTED; + + BTM_TRACE_EVENT("btm_sec_send_hci_disconnect: handle:0x%x, reason=0x%x", + conn_handle, reason); + + /* send HCI_Disconnect on a transport only once */ + switch (old_state) { + case BTM_SEC_STATE_DISCONNECTING: + if (conn_handle == p_dev_rec->hci_handle) return status; + + p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; + break; + + case BTM_SEC_STATE_DISCONNECTING_BLE: + if (conn_handle == p_dev_rec->ble_hci_handle) return status; + + p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; + break; + + case BTM_SEC_STATE_DISCONNECTING_BOTH: + return status; + + default: + p_dev_rec->sec_state = (conn_handle == p_dev_rec->hci_handle) + ? BTM_SEC_STATE_DISCONNECTING + : BTM_SEC_STATE_DISCONNECTING_BLE; + + break; + } + + /* If a role switch is in progress, delay the HCI Disconnect to avoid + * controller problem */ + if (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING && + p_dev_rec->hci_handle == conn_handle) { + BTM_TRACE_DEBUG( + "RS in progress - Set DISC Pending flag in btm_sec_send_hci_disconnect " + "to delay disconnect"); + p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; + status = BTM_SUCCESS; + } + /* Tear down the HCI link */ + else { + btsnd_hcic_disconnect(conn_handle, reason); + } + + return status; +} - return(BTM_SUCCESS); - } +/******************************************************************************* + * + * Function BTM_ConfirmReqReply + * + * Description This function is called to confirm the numeric value for + * Simple Pairing in response to BTM_SP_CFM_REQ_EVT + * + * Parameters: res - result of the operation BTM_SUCCESS if + * success + * bd_addr - Address of the peer device + * + ******************************************************************************/ +void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec; - /* enqueue security request if security is active */ - if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) - { - BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption busy, enqueue request"); + BTM_TRACE_EVENT("BTM_ConfirmReqReply() State: %s Res: %u", + btm_pair_state_descr(btm_cb.pairing_state), res); - if (btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data, sec_act)) - { - return BTM_CMD_STARTED; - } - else - { - if (p_callback) - (*p_callback) (bd_addr, transport, p_ref_data, BTM_NO_RESOURCES); - return BTM_NO_RESOURCES; - } - } + /* If timeout already expired or has been canceled, ignore the reply */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM) || + (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0)) + return; - p_dev_rec->p_callback = p_callback; - p_dev_rec->p_ref_data = p_ref_data; - p_dev_rec->security_required |= (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT); - p_dev_rec->is_originator = false; + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - BTM_TRACE_API ("Security Manager: BTM_SetEncryption Handle:%d State:%d Flags:0x%x Required:0x%x", - p_dev_rec->hci_handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, - p_dev_rec->security_required); + if ((res == BTM_SUCCESS) || (res == BTM_SUCCESS_NO_SECURITY)) { + btm_cb.acl_disc_reason = HCI_SUCCESS; - if (transport == BT_TRANSPORT_LE) - { - tACL_CONN *p = btm_bda_to_acl(bd_addr, transport); - if (p) - { - rc = btm_ble_set_encryption(bd_addr, sec_act, p->link_role); - } - else - { - rc = BTM_WRONG_MODE; - BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL", __func__); - } - } - else - { - rc = btm_sec_execute_procedure (p_dev_rec); + if (res == BTM_SUCCESS) { + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_AUTHED; + p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + } } - if (rc != BTM_CMD_STARTED && rc != BTM_BUSY) - { - if (p_callback) - { - p_dev_rec->p_callback = NULL; - (*p_callback) (bd_addr, transport, p_dev_rec->p_ref_data, rc); - } - } - - return(rc); -} - -/******************************************************************************* - * disconnect the ACL link, if it's not done yet. - ******************************************************************************/ -static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, uint8_t reason, uint16_t conn_handle) -{ - uint8_t old_state = p_dev_rec->sec_state; - tBTM_STATUS status = BTM_CMD_STARTED; - - BTM_TRACE_EVENT ("btm_sec_send_hci_disconnect: handle:0x%x, reason=0x%x", - conn_handle, reason); - - /* send HCI_Disconnect on a transport only once */ - switch (old_state) - { - case BTM_SEC_STATE_DISCONNECTING: - if (conn_handle == p_dev_rec->hci_handle) - return status; - - p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; - break; - - case BTM_SEC_STATE_DISCONNECTING_BLE: - if (conn_handle == p_dev_rec->ble_hci_handle) - return status; - - p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; - break; - - case BTM_SEC_STATE_DISCONNECTING_BOTH: - return status; - - default: - p_dev_rec->sec_state = (conn_handle == p_dev_rec->hci_handle) ? - BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; - - break; - } - - /* If a role switch is in progress, delay the HCI Disconnect to avoid controller problem */ - if (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING && p_dev_rec->hci_handle == conn_handle) - { - BTM_TRACE_DEBUG("RS in progress - Set DISC Pending flag in btm_sec_send_hci_disconnect to delay disconnect"); - p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; - status = BTM_SUCCESS; - } - /* Tear down the HCI link */ - else - { - btsnd_hcic_disconnect(conn_handle, reason); - } - - return status; -} - -/******************************************************************************* - * - * Function BTM_ConfirmReqReply - * - * Description This function is called to confirm the numeric value for - * Simple Pairing in response to BTM_SP_CFM_REQ_EVT - * - * Parameters: res - result of the operation BTM_SUCCESS if - * success - * bd_addr - Address of the peer device - * - ******************************************************************************/ -void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - BTM_TRACE_EVENT ("BTM_ConfirmReqReply() State: %s Res: %u", - btm_pair_state_descr(btm_cb.pairing_state), res); - - /* If timeout already expired or has been canceled, ignore the reply */ - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM) - || (memcmp (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0) ) - return; - - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - - if ( (res == BTM_SUCCESS) || (res == BTM_SUCCESS_NO_SECURITY) ) - { - btm_cb.acl_disc_reason = HCI_SUCCESS; - - if (res == BTM_SUCCESS) - { - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec != NULL) { - p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_AUTHED; - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; - } - } - - btsnd_hcic_user_conf_reply (bd_addr, true); - } - else - { - /* Report authentication failed event from state BTM_PAIR_STATE_WAIT_AUTH_COMPLETE */ - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - btsnd_hcic_user_conf_reply (bd_addr, false); - } + btsnd_hcic_user_conf_reply(bd_addr, true); + } else { + /* Report authentication failed event from state + * BTM_PAIR_STATE_WAIT_AUTH_COMPLETE */ + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + btsnd_hcic_user_conf_reply(bd_addr, false); + } } /******************************************************************************* @@ -1558,53 +1501,50 @@ void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr) * ******************************************************************************/ #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) -void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, uint32_t passkey) -{ - BTM_TRACE_API ("BTM_PasskeyReqReply: State: %s res:%d", - btm_pair_state_descr(btm_cb.pairing_state), res); +void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, uint32_t passkey) { + BTM_TRACE_API("BTM_PasskeyReqReply: State: %s res:%d", + btm_pair_state_descr(btm_cb.pairing_state), res); - if ( (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) - || (memcmp (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0) ) - { - return; - } + if ((btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) || + (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0)) { + return; + } - /* If timeout already expired or has been canceled, ignore the reply */ - if ( (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_AUTH_COMPLETE) && (res != BTM_SUCCESS) ) - { - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - if (p_dev_rec != NULL) - { - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + /* If timeout already expired or has been canceled, ignore the reply */ + if ((btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_AUTH_COMPLETE) && + (res != BTM_SUCCESS)) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) { + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - if (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) - btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_AUTH_FAILURE, p_dev_rec->hci_handle); - else - BTM_SecBondCancel(bd_addr); + if (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) + btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_AUTH_FAILURE, + p_dev_rec->hci_handle); + else + BTM_SecBondCancel(bd_addr); - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_AUTHED | BTM_SEC_LINK_KEY_KNOWN); + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_AUTHED | BTM_SEC_LINK_KEY_KNOWN); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - return; - } + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + return; } - else if (btm_cb.pairing_state != BTM_PAIR_STATE_KEY_ENTRY) - return; + } else if (btm_cb.pairing_state != BTM_PAIR_STATE_KEY_ENTRY) + return; - if (passkey > BTM_MAX_PASSKEY_VAL) - res = BTM_ILLEGAL_VALUE; + if (passkey > BTM_MAX_PASSKEY_VAL) res = BTM_ILLEGAL_VALUE; - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - if (res != BTM_SUCCESS) - { - /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed event */ - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - btsnd_hcic_user_passkey_neg_reply (bd_addr); - } else { - btm_cb.acl_disc_reason = HCI_SUCCESS; - btsnd_hcic_user_passkey_reply (bd_addr, passkey); - } + if (res != BTM_SUCCESS) { + /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed + * event */ + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + btsnd_hcic_user_passkey_neg_reply(bd_addr); + } else { + btm_cb.acl_disc_reason = HCI_SUCCESS; + btsnd_hcic_user_passkey_reply(bd_addr, passkey); + } } #endif @@ -1623,11 +1563,10 @@ void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, uint32_t passkey) * ******************************************************************************/ #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) -void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type) -{ - /* This API only make sense between PASSKEY_REQ and SP complete */ - if (btm_cb.pairing_state == BTM_PAIR_STATE_KEY_ENTRY) - btsnd_hcic_send_keypress_notif(bd_addr, type); +void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type) { + /* This API only make sense between PASSKEY_REQ and SP complete */ + if (btm_cb.pairing_state == BTM_PAIR_STATE_KEY_ENTRY) + btsnd_hcic_send_keypress_notif(bd_addr, type); } #endif @@ -1646,25 +1585,24 @@ void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type) * auth_req- MITM protection required or not. * ******************************************************************************/ -void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req) -{ - BTM_TRACE_EVENT ("BTM_IoCapRsp: state: %s oob: %d io_cap: %d", - btm_pair_state_descr(btm_cb.pairing_state), oob, io_cap); +void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob, + tBTM_AUTH_REQ auth_req) { + BTM_TRACE_EVENT("BTM_IoCapRsp: state: %s oob: %d io_cap: %d", + btm_pair_state_descr(btm_cb.pairing_state), oob, io_cap); - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS) - || (memcmp (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0) ) - return; + if ((btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS) || + (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0)) + return; - if (oob < BTM_OOB_UNKNOWN && io_cap < BTM_IO_CAP_MAX) - { - btm_cb.devcb.loc_auth_req = auth_req; - btm_cb.devcb.loc_io_caps = io_cap; + if (oob < BTM_OOB_UNKNOWN && io_cap < BTM_IO_CAP_MAX) { + btm_cb.devcb.loc_auth_req = auth_req; + btm_cb.devcb.loc_io_caps = io_cap; - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - auth_req = (BTM_AUTH_DD_BOND | (auth_req&BTM_AUTH_YN_BIT)); + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) + auth_req = (BTM_AUTH_DD_BOND | (auth_req & BTM_AUTH_YN_BIT)); - btsnd_hcic_io_cap_req_reply (bd_addr, io_cap, oob, auth_req); - } + btsnd_hcic_io_cap_req_reply(bd_addr, io_cap, oob, auth_req); + } } /******************************************************************************* @@ -1675,10 +1613,7 @@ void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob, tBTM_A * LM * ******************************************************************************/ -void BTM_ReadLocalOobData(void) -{ - btsnd_hcic_read_local_oob_data(); -} +void BTM_ReadLocalOobData(void) { btsnd_hcic_read_local_oob_data(); } /******************************************************************************* * @@ -1692,26 +1627,25 @@ void BTM_ReadLocalOobData(void) * r - simple pairing Randomizer C. * ******************************************************************************/ -void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, BT_OCTET16 c, BT_OCTET16 r) -{ - BTM_TRACE_EVENT ("%s() - State: %s res: %d", __func__, - btm_pair_state_descr(btm_cb.pairing_state), res); +void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, BT_OCTET16 c, + BT_OCTET16 r) { + BTM_TRACE_EVENT("%s() - State: %s res: %d", __func__, + btm_pair_state_descr(btm_cb.pairing_state), res); - /* If timeout already expired or has been canceled, ignore the reply */ - if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP) - return; + /* If timeout already expired or has been canceled, ignore the reply */ + if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP) return; - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - if (res != BTM_SUCCESS) - { - /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed event */ - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - btsnd_hcic_rem_oob_neg_reply (bd_addr); - } else { - btm_cb.acl_disc_reason = HCI_SUCCESS; - btsnd_hcic_rem_oob_reply (bd_addr, c, r); - } + if (res != BTM_SUCCESS) { + /* use BTM_PAIR_STATE_WAIT_AUTH_COMPLETE to report authentication failed + * event */ + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + btsnd_hcic_rem_oob_neg_reply(bd_addr); + } else { + btm_cb.acl_disc_reason = HCI_SUCCESS; + btsnd_hcic_rem_oob_reply(bd_addr, c, r); + } } /******************************************************************************* @@ -1732,77 +1666,70 @@ void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, BT_OCTET16 c, BT_O * Returns Number of bytes in p_data. * ******************************************************************************/ -uint16_t BTM_BuildOobData(uint8_t *p_data, uint16_t max_len, BT_OCTET16 c, - BT_OCTET16 r, uint8_t name_len) -{ - uint8_t *p = p_data; - uint16_t len = 0; - uint16_t name_size; - uint8_t name_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE; - - if (p_data && max_len >= BTM_OOB_MANDATORY_SIZE) - { - /* add mandatory part */ - UINT16_TO_STREAM(p, len); - BDADDR_TO_STREAM(p, controller_get_interface()->get_address()->address); - - len = BTM_OOB_MANDATORY_SIZE; - max_len -= len; - - /* now optional part */ - - /* add Hash C */ - uint16_t delta = BTM_OOB_HASH_C_SIZE + 2; - if (max_len >= delta) - { - *p++ = BTM_OOB_HASH_C_SIZE + 1; - *p++ = BTM_EIR_OOB_SSP_HASH_C_TYPE; - ARRAY_TO_STREAM(p, c, BTM_OOB_HASH_C_SIZE); - len += delta; - max_len -= delta; - } - - /* add Rand R */ - delta = BTM_OOB_RAND_R_SIZE + 2; - if (max_len >= delta) - { - *p++ = BTM_OOB_RAND_R_SIZE + 1; - *p++ = BTM_EIR_OOB_SSP_RAND_R_TYPE; - ARRAY_TO_STREAM(p, r, BTM_OOB_RAND_R_SIZE); - len += delta; - max_len -= delta; - } - - /* add class of device */ - delta = BTM_OOB_COD_SIZE + 2; - if (max_len >= delta) - { - *p++ = BTM_OOB_COD_SIZE + 1; - *p++ = BTM_EIR_OOB_COD_TYPE; - DEVCLASS_TO_STREAM(p, btm_cb.devcb.dev_class); - len += delta; - max_len -= delta; - } - name_size = name_len; - if (name_size > strlen(btm_cb.cfg.bd_name)) - { - name_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; - name_size = (uint16_t)strlen(btm_cb.cfg.bd_name); - } - delta = name_size + 2; - if (max_len >= delta) - { - *p++ = name_size + 1; - *p++ = name_type; - ARRAY_TO_STREAM (p, btm_cb.cfg.bd_name, name_size); - len += delta; - max_len -= delta; - } - /* update len */ - p = p_data; - UINT16_TO_STREAM(p, len); - } - return len; +uint16_t BTM_BuildOobData(uint8_t* p_data, uint16_t max_len, BT_OCTET16 c, + BT_OCTET16 r, uint8_t name_len) { + uint8_t* p = p_data; + uint16_t len = 0; + uint16_t name_size; + uint8_t name_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE; + + if (p_data && max_len >= BTM_OOB_MANDATORY_SIZE) { + /* add mandatory part */ + UINT16_TO_STREAM(p, len); + BDADDR_TO_STREAM(p, controller_get_interface()->get_address()->address); + + len = BTM_OOB_MANDATORY_SIZE; + max_len -= len; + + /* now optional part */ + + /* add Hash C */ + uint16_t delta = BTM_OOB_HASH_C_SIZE + 2; + if (max_len >= delta) { + *p++ = BTM_OOB_HASH_C_SIZE + 1; + *p++ = BTM_EIR_OOB_SSP_HASH_C_TYPE; + ARRAY_TO_STREAM(p, c, BTM_OOB_HASH_C_SIZE); + len += delta; + max_len -= delta; + } + + /* add Rand R */ + delta = BTM_OOB_RAND_R_SIZE + 2; + if (max_len >= delta) { + *p++ = BTM_OOB_RAND_R_SIZE + 1; + *p++ = BTM_EIR_OOB_SSP_RAND_R_TYPE; + ARRAY_TO_STREAM(p, r, BTM_OOB_RAND_R_SIZE); + len += delta; + max_len -= delta; + } + + /* add class of device */ + delta = BTM_OOB_COD_SIZE + 2; + if (max_len >= delta) { + *p++ = BTM_OOB_COD_SIZE + 1; + *p++ = BTM_EIR_OOB_COD_TYPE; + DEVCLASS_TO_STREAM(p, btm_cb.devcb.dev_class); + len += delta; + max_len -= delta; + } + name_size = name_len; + if (name_size > strlen(btm_cb.cfg.bd_name)) { + name_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; + name_size = (uint16_t)strlen(btm_cb.cfg.bd_name); + } + delta = name_size + 2; + if (max_len >= delta) { + *p++ = name_size + 1; + *p++ = name_type; + ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, name_size); + len += delta; + max_len -= delta; + } + /* update len */ + p = p_data; + UINT16_TO_STREAM(p, len); + } + return len; } /******************************************************************************* @@ -1819,10 +1746,9 @@ uint16_t BTM_BuildOobData(uint8_t *p_data, uint16_t max_len, BT_OCTET16 c, * local and the remote device, else false. * ******************************************************************************/ -bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr) -{ - return ((controller_get_interface()->supports_secure_connections()) && - (BTM_PeerSupportsSecureConnections(bd_addr))); +bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr) { + return ((controller_get_interface()->supports_secure_connections()) && + (BTM_PeerSupportsSecureConnections(bd_addr))); } /******************************************************************************* @@ -1838,20 +1764,19 @@ bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr) * else false. * ******************************************************************************/ -bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - p_dev_rec = btm_find_dev(bd_addr); - if (p_dev_rec == NULL) - { - BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x", __func__, - (bd_addr[0]<<24) + (bd_addr[1]<<16) + (bd_addr[2]<<8) + bd_addr[3], - (bd_addr[4]<< 8) + bd_addr[5]); - return false; - } +bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec; + + p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec == NULL) { + BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x", __func__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + return false; + } - return (p_dev_rec->remote_supports_secure_connections); + return (p_dev_rec->remote_supports_secure_connections); } /******************************************************************************* @@ -1869,58 +1794,47 @@ bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) * NULL, if the tag is not found. * ******************************************************************************/ -uint8_t * BTM_ReadOobData(uint8_t *p_data, uint8_t eir_tag, uint8_t *p_len) -{ - uint8_t *p = p_data; - uint16_t max_len; - uint8_t len, type; - uint8_t *p_ret = NULL; - uint8_t ret_len = 0; - - if (p_data) - { - STREAM_TO_UINT16(max_len, p); - if (max_len >= BTM_OOB_MANDATORY_SIZE) - { - if (BTM_EIR_OOB_BD_ADDR_TYPE == eir_tag) - { - p_ret = p; /* the location for bd_addr */ - ret_len = BTM_OOB_BD_ADDR_SIZE; - } - else - { - p += BD_ADDR_LEN; - max_len -= BTM_OOB_MANDATORY_SIZE; - /* now the optional data in EIR format */ - while (max_len > 0) - { - len = *p++; /* tag data len + 1 */ - type = *p++; - if (eir_tag == type) - { - p_ret = p; - ret_len = len - 1; - break; - } - /* the data size of this tag is len + 1 (tag data len + 2) */ - if (max_len > len) - { - max_len -= len; - max_len--; - len--; - p += len; - } - else - max_len = 0; - } - } +uint8_t* BTM_ReadOobData(uint8_t* p_data, uint8_t eir_tag, uint8_t* p_len) { + uint8_t* p = p_data; + uint16_t max_len; + uint8_t len, type; + uint8_t* p_ret = NULL; + uint8_t ret_len = 0; + + if (p_data) { + STREAM_TO_UINT16(max_len, p); + if (max_len >= BTM_OOB_MANDATORY_SIZE) { + if (BTM_EIR_OOB_BD_ADDR_TYPE == eir_tag) { + p_ret = p; /* the location for bd_addr */ + ret_len = BTM_OOB_BD_ADDR_SIZE; + } else { + p += BD_ADDR_LEN; + max_len -= BTM_OOB_MANDATORY_SIZE; + /* now the optional data in EIR format */ + while (max_len > 0) { + len = *p++; /* tag data len + 1 */ + type = *p++; + if (eir_tag == type) { + p_ret = p; + ret_len = len - 1; + break; + } + /* the data size of this tag is len + 1 (tag data len + 2) */ + if (max_len > len) { + max_len -= len; + max_len--; + len--; + p += len; + } else + max_len = 0; } + } } + } - if (p_len) - *p_len = ret_len; + if (p_len) *p_len = ret_len; - return p_ret; + return p_ret; } /******************************************************************************* @@ -1937,28 +1851,28 @@ uint8_t * BTM_ReadOobData(uint8_t *p_data, uint8_t eir_tag, uint8_t *p_len) * Returns void * ******************************************************************************/ -void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, uint32_t mx_chan_id) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_SEC_SERV_REC *p_serv_rec = &btm_cb.sec_serv_rec[0]; - - btm_cb.p_out_serv = p_serv_rec; - p_dev_rec = btm_find_dev (bd_addr); - - for (int i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) - { - if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) - && (p_serv_rec->service_id == service_id) - && (p_serv_rec->orig_mx_chan_id == mx_chan_id)) - { - BTM_TRACE_API("BTM_SetOutService p_out_serv id %d, psm 0x%04x, proto_id %d, chan_id %d", - p_serv_rec->service_id, p_serv_rec->psm, p_serv_rec->mx_proto_id, p_serv_rec->orig_mx_chan_id); - btm_cb.p_out_serv = p_serv_rec; - if (p_dev_rec) - p_dev_rec->p_cur_service = p_serv_rec; - break; - } - } +void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, + uint32_t mx_chan_id) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_SEC_SERV_REC* p_serv_rec = &btm_cb.sec_serv_rec[0]; + + btm_cb.p_out_serv = p_serv_rec; + p_dev_rec = btm_find_dev(bd_addr); + + for (int i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) { + if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) && + (p_serv_rec->service_id == service_id) && + (p_serv_rec->orig_mx_chan_id == mx_chan_id)) { + BTM_TRACE_API( + "BTM_SetOutService p_out_serv id %d, psm 0x%04x, proto_id %d, " + "chan_id %d", + p_serv_rec->service_id, p_serv_rec->psm, p_serv_rec->mx_proto_id, + p_serv_rec->orig_mx_chan_id); + btm_cb.p_out_serv = p_serv_rec; + if (p_dev_rec) p_dev_rec->p_cur_service = p_serv_rec; + break; + } + } } /************************************************************************ @@ -1974,46 +1888,49 @@ void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, uint32_t mx_chan_id) * Returns bool * ******************************************************************************/ -static bool btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC *p_dev_rec, bool is_originator) -{ - uint16_t mtm_check = is_originator ? BTM_SEC_OUT_MITM : BTM_SEC_IN_MITM; - bool is_possible = true; - - if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) - { - is_possible = false; - if(p_dev_rec->p_cur_service) - { - BTM_TRACE_DEBUG ("%s() id: %d, link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x, flags: 0x%x", - __func__, p_dev_rec->p_cur_service->service_id, p_dev_rec->link_key_type, - p_dev_rec->rmt_io_caps, mtm_check, p_dev_rec->p_cur_service->security_flags); - } - else - { - BTM_TRACE_DEBUG ("%s() link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x", - __func__, p_dev_rec->link_key_type, p_dev_rec->rmt_io_caps, mtm_check); - } - /* Already have a link key to the connected peer. Is the link key secure enough? - ** Is a link key upgrade even possible? - */ - if ((p_dev_rec->security_required & mtm_check) /* needs MITM */ - && ((p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB) || - (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) - /* has unauthenticated - link key */ - && (p_dev_rec->rmt_io_caps < BTM_IO_CAP_MAX) /* a valid peer IO cap */ - && (btm_sec_io_map[p_dev_rec->rmt_io_caps][btm_cb.devcb.loc_io_caps])) - /* authenticated - link key is possible */ - { - /* upgrade is possible: check if the application wants the upgrade. - * If the application is configured to use a global MITM flag, - * it probably would not want to upgrade the link key based on the security level database */ - is_possible = true; - } +static bool btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC* p_dev_rec, + bool is_originator) { + uint16_t mtm_check = is_originator ? BTM_SEC_OUT_MITM : BTM_SEC_IN_MITM; + bool is_possible = true; + + if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) { + is_possible = false; + if (p_dev_rec->p_cur_service) { + BTM_TRACE_DEBUG( + "%s() id: %d, link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x, " + "flags: 0x%x", + __func__, p_dev_rec->p_cur_service->service_id, + p_dev_rec->link_key_type, p_dev_rec->rmt_io_caps, mtm_check, + p_dev_rec->p_cur_service->security_flags); + } else { + BTM_TRACE_DEBUG( + "%s() link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x", __func__, + p_dev_rec->link_key_type, p_dev_rec->rmt_io_caps, mtm_check); } - BTM_TRACE_DEBUG ("%s() is_possible: %d sec_flags: 0x%x", __func__, is_possible, p_dev_rec->sec_flags); - return is_possible; + /* Already have a link key to the connected peer. Is the link key secure + *enough? + ** Is a link key upgrade even possible? + */ + if ((p_dev_rec->security_required & mtm_check) /* needs MITM */ + && ((p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB) || + (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) + /* has unauthenticated + link key */ + && (p_dev_rec->rmt_io_caps < BTM_IO_CAP_MAX) /* a valid peer IO cap */ + && (btm_sec_io_map[p_dev_rec->rmt_io_caps][btm_cb.devcb.loc_io_caps])) + /* authenticated + link key is possible */ + { + /* upgrade is possible: check if the application wants the upgrade. + * If the application is configured to use a global MITM flag, + * it probably would not want to upgrade the link key based on the + * security level database */ + is_possible = true; + } + } + BTM_TRACE_DEBUG("%s() is_possible: %d sec_flags: 0x%x", __func__, is_possible, + p_dev_rec->sec_flags); + return is_possible; } /******************************************************************************* @@ -2026,39 +1943,38 @@ static bool btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC *p_dev_rec, bool * Returns void * ******************************************************************************/ -static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, bool is_originator) -{ - - BTM_TRACE_DEBUG ("%s()", __func__); +static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC* p_dev_rec, + bool is_originator) { + BTM_TRACE_DEBUG("%s()", __func__); + + /* Only check if link key already exists */ + if (!(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) return; + + if (btm_sec_is_upgrade_possible(p_dev_rec, is_originator) == true) { + BTM_TRACE_DEBUG("need upgrade!! sec_flags:0x%x", p_dev_rec->sec_flags); + /* upgrade is possible: check if the application wants the upgrade. + * If the application is configured to use a global MITM flag, + * it probably would not want to upgrade the link key based on the security + * level database */ + tBTM_SP_UPGRADE evt_data; + memcpy(evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + evt_data.upgrade = true; + if (btm_cb.api.p_sp_callback) + (*btm_cb.api.p_sp_callback)(BTM_SP_UPGRADE_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); - /* Only check if link key already exists */ - if (!(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) - return; + BTM_TRACE_DEBUG("evt_data.upgrade:0x%x", evt_data.upgrade); + if (evt_data.upgrade) { + /* if the application confirms the upgrade, set the upgrade bit */ + p_dev_rec->sm4 |= BTM_SM4_UPGRADE; - if (btm_sec_is_upgrade_possible (p_dev_rec, is_originator) == true) - { - BTM_TRACE_DEBUG ("need upgrade!! sec_flags:0x%x", p_dev_rec->sec_flags); - /* upgrade is possible: check if the application wants the upgrade. - * If the application is configured to use a global MITM flag, - * it probably would not want to upgrade the link key based on the security level database */ - tBTM_SP_UPGRADE evt_data; - memcpy (evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - evt_data.upgrade = true; - if (btm_cb.api.p_sp_callback) - (*btm_cb.api.p_sp_callback) (BTM_SP_UPGRADE_EVT, (tBTM_SP_EVT_DATA *)&evt_data); - - BTM_TRACE_DEBUG ("evt_data.upgrade:0x%x", evt_data.upgrade); - if (evt_data.upgrade) - { - /* if the application confirms the upgrade, set the upgrade bit */ - p_dev_rec->sm4 |= BTM_SM4_UPGRADE; - - /* Clear the link key known to go through authentication/pairing again */ - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED); - p_dev_rec->sec_flags &= ~BTM_SEC_AUTHENTICATED; - BTM_TRACE_DEBUG ("sec_flags:0x%x", p_dev_rec->sec_flags); - } + /* Clear the link key known to go through authentication/pairing again */ + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED); + p_dev_rec->sec_flags &= ~BTM_SEC_AUTHENTICATED; + BTM_TRACE_DEBUG("sec_flags:0x%x", p_dev_rec->sec_flags); } + } } /******************************************************************************* @@ -2079,370 +1995,396 @@ static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, bool is_origi * Returns tBTM_STATUS * ******************************************************************************/ -tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, uint16_t psm, uint16_t handle, - CONNECTION_TYPE conn_type, - tBTM_SEC_CALLBACK *p_callback, - void *p_ref_data) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_SEC_SERV_REC *p_serv_rec; - uint16_t security_required; - uint16_t old_security_required; - bool old_is_originator; - tBTM_STATUS rc = BTM_SUCCESS; - bool chk_acp_auth_done = false; - bool is_originator; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; /* should check PSM range in LE connection oriented L2CAP connection */ +tBTM_STATUS btm_sec_l2cap_access_req(BD_ADDR bd_addr, uint16_t psm, + uint16_t handle, CONNECTION_TYPE conn_type, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_SEC_SERV_REC* p_serv_rec; + uint16_t security_required; + uint16_t old_security_required; + bool old_is_originator; + tBTM_STATUS rc = BTM_SUCCESS; + bool chk_acp_auth_done = false; + bool is_originator; + tBT_TRANSPORT transport = + BT_TRANSPORT_BR_EDR; /* should check PSM range in LE connection oriented + L2CAP connection */ #if (L2CAP_UCD_INCLUDED == TRUE) - if (conn_type & CONNECTION_TYPE_ORIG_MASK) - is_originator = true; - else - is_originator = false; + if (conn_type & CONNECTION_TYPE_ORIG_MASK) + is_originator = true; + else + is_originator = false; - BTM_TRACE_DEBUG ("%s() conn_type: 0x%x, 0x%x", __func__, conn_type, p_ref_data); + BTM_TRACE_DEBUG("%s() conn_type: 0x%x, 0x%x", __func__, conn_type, + p_ref_data); #else - is_originator = conn_type; + is_originator = conn_type; - BTM_TRACE_DEBUG ("%s() is_originator:%d, 0x%x", __func__, is_originator, p_ref_data); + BTM_TRACE_DEBUG("%s() is_originator:%d, 0x%x", __func__, is_originator, + p_ref_data); #endif - /* Find or get oldest record */ - p_dev_rec = btm_find_or_alloc_dev (bd_addr); + /* Find or get oldest record */ + p_dev_rec = btm_find_or_alloc_dev(bd_addr); - p_dev_rec->hci_handle = handle; + p_dev_rec->hci_handle = handle; - /* Find the service record for the PSM */ - p_serv_rec = btm_sec_find_first_serv (conn_type, psm); + /* Find the service record for the PSM */ + p_serv_rec = btm_sec_find_first_serv(conn_type, psm); - /* If there is no application registered with this PSM do not allow connection */ - if (!p_serv_rec) - { - BTM_TRACE_WARNING ("%s() PSM: %d no application registerd", __func__, psm); - (*p_callback) (bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); - return(BTM_MODE_UNSUPPORTED); - } + /* If there is no application registered with this PSM do not allow connection + */ + if (!p_serv_rec) { + BTM_TRACE_WARNING("%s() PSM: %d no application registerd", __func__, psm); + (*p_callback)(bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); + return (BTM_MODE_UNSUPPORTED); + } - /* Services level0 by default have no security */ - if ((btm_sec_is_serv_level0(psm)) && (!btm_cb.devcb.secure_connections_only)) - { - (*p_callback) (bd_addr,transport, p_ref_data, BTM_SUCCESS_NO_SECURITY); - return(BTM_SUCCESS); - } + /* Services level0 by default have no security */ + if ((btm_sec_is_serv_level0(psm)) && + (!btm_cb.devcb.secure_connections_only)) { + (*p_callback)(bd_addr, transport, p_ref_data, BTM_SUCCESS_NO_SECURITY); + return (BTM_SUCCESS); + } #if (L2CAP_UCD_INCLUDED == TRUE) - if ( conn_type & CONNECTION_TYPE_CONNLESS_MASK ) - { - if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - security_required = btm_sec_set_serv_level4_flags (p_serv_rec->ucd_security_flags, - is_originator); - } - else - { - security_required = p_serv_rec->ucd_security_flags; - } - - rc = BTM_CMD_STARTED; - if (is_originator) - { - if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || - ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_AUTHENTICATE) && (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED))) || - ((((security_required & BTM_SEC_OUT_FLAGS) == (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) || - ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_FLAGS) && (p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED))) ) - { - rc = BTM_SUCCESS; - } - } - else - { - if (((security_required & BTM_SEC_IN_FLAGS) == 0) || - ((((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHENTICATE) && (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED))) || - ((((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) || - ((((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_FLAGS) && (p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED))) ) - { - // Check for 16 digits (or MITM) - if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || - (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == BTM_SEC_IN_MIN_16_DIGIT_PIN) && - btm_dev_16_digit_authenticated(p_dev_rec))) { - rc = BTM_SUCCESS; - } - } + if (conn_type & CONNECTION_TYPE_CONNLESS_MASK) { + if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + security_required = btm_sec_set_serv_level4_flags( + p_serv_rec->ucd_security_flags, is_originator); + } else { + security_required = p_serv_rec->ucd_security_flags; + } + + rc = BTM_CMD_STARTED; + if (is_originator) { + if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + BTM_SEC_OUT_AUTHENTICATE) && + (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED))) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && + (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) || + ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_FLAGS) && + (p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED)))) { + rc = BTM_SUCCESS; + } + } else { + if (((security_required & BTM_SEC_IN_FLAGS) == 0) || + ((((security_required & BTM_SEC_IN_FLAGS) == + BTM_SEC_IN_AUTHENTICATE) && + (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED))) || + ((((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && + (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) || + ((((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_FLAGS) && + (p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED)))) { + // Check for 16 digits (or MITM) + if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || + (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == + BTM_SEC_IN_MIN_16_DIGIT_PIN) && + btm_dev_16_digit_authenticated(p_dev_rec))) { + rc = BTM_SUCCESS; } + } + } - if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - rc = BTM_CMD_STARTED; - } + if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + rc = BTM_CMD_STARTED; + } - if (rc == BTM_SUCCESS) - { - if (p_callback) - (*p_callback) (bd_addr, transport, (void *)p_ref_data, BTM_SUCCESS); + if (rc == BTM_SUCCESS) { + if (p_callback) + (*p_callback)(bd_addr, transport, (void*)p_ref_data, BTM_SUCCESS); - return(BTM_SUCCESS); - } + return (BTM_SUCCESS); } - else + } else #endif - { - if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - security_required = btm_sec_set_serv_level4_flags (p_serv_rec->security_flags, - is_originator); - } - else - { - security_required = p_serv_rec->security_flags; + { + if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + security_required = btm_sec_set_serv_level4_flags( + p_serv_rec->security_flags, is_originator); + } else { + security_required = p_serv_rec->security_flags; + } + } + + BTM_TRACE_DEBUG( + "%s: security_required 0x%04x, is_originator 0x%02x, psm 0x%04x", + __func__, security_required, is_originator, psm); + + if ((!is_originator) && (security_required & BTM_SEC_MODE4_LEVEL4)) { + bool local_supports_sc = + controller_get_interface()->supports_secure_connections(); + /* acceptor receives L2CAP Channel Connect Request for Secure Connections + * Only service */ + if (!(local_supports_sc) || + !(p_dev_rec->remote_supports_secure_connections)) { + BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d", + "rmt_support_for_sc : %d -> fail pairing", __func__, + local_supports_sc, + p_dev_rec->remote_supports_secure_connections); + if (p_callback) + (*p_callback)(bd_addr, transport, (void*)p_ref_data, + BTM_MODE4_LEVEL4_NOT_SUPPORTED); + + return (BTM_MODE4_LEVEL4_NOT_SUPPORTED); + } + } + + /* there are some devices (moto KRZR) which connects to several services at + * the same time */ + /* we will process one after another */ + if ((p_dev_rec->p_callback) || + (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE)) { + BTM_TRACE_EVENT("%s() - busy - PSM:%d delayed state: %s mode:%d, sm4:0x%x", + __func__, psm, btm_pair_state_descr(btm_cb.pairing_state), + btm_cb.security_mode, p_dev_rec->sm4); + BTM_TRACE_EVENT("security_flags:x%x, sec_flags:x%x", security_required, + p_dev_rec->sec_flags); + rc = BTM_CMD_STARTED; + if ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || + btm_cb.security_mode == BTM_SEC_MODE_NONE || + btm_cb.security_mode == BTM_SEC_MODE_SERVICE || + btm_cb.security_mode == BTM_SEC_MODE_LINK) || + (BTM_SM4_KNOWN == p_dev_rec->sm4) || + (BTM_SEC_IS_SM4(p_dev_rec->sm4) && + (btm_sec_is_upgrade_possible(p_dev_rec, is_originator) == false))) { + /* legacy mode - local is legacy or local is lisbon/peer is legacy + * or SM4 with no possibility of link key upgrade */ + if (is_originator) { + if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + BTM_SEC_OUT_AUTHENTICATE) && + btm_dev_authenticated(p_dev_rec))) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && + btm_dev_encrypted(p_dev_rec))) || + ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_FLAGS) && + btm_dev_authorized(p_dev_rec) && btm_dev_encrypted(p_dev_rec)))) { + rc = BTM_SUCCESS; + } + } else { + if (((security_required & BTM_SEC_IN_FLAGS) == 0) || + (((security_required & BTM_SEC_IN_FLAGS) == + BTM_SEC_IN_AUTHENTICATE) && + btm_dev_authenticated(p_dev_rec)) || + (((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && + btm_dev_encrypted(p_dev_rec)) || + (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHORIZE) && + (btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_AUTHORIZE)) && + ((btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec)) && + btm_dev_authenticated(p_dev_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE)) && + ((btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec)) && + btm_dev_encrypted(p_dev_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_FLAGS) && + btm_dev_encrypted(p_dev_rec) && + (btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec)))) { + // Check for 16 digits (or MITM) + if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || + (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == + BTM_SEC_IN_MIN_16_DIGIT_PIN) && + btm_dev_16_digit_authenticated(p_dev_rec))) { + rc = BTM_SUCCESS; + } } - } + } - BTM_TRACE_DEBUG("%s: security_required 0x%04x, is_originator 0x%02x, psm 0x%04x", - __func__, security_required, is_originator, psm); + if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + rc = BTM_CMD_STARTED; + } - if ((!is_originator) && (security_required & BTM_SEC_MODE4_LEVEL4)) - { - bool local_supports_sc = controller_get_interface()->supports_secure_connections(); - /* acceptor receives L2CAP Channel Connect Request for Secure Connections Only service */ - if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) - { - BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d", - "rmt_support_for_sc : %d -> fail pairing", __func__, - local_supports_sc, - p_dev_rec->remote_supports_secure_connections); - if (p_callback) - (*p_callback) (bd_addr, transport, (void *)p_ref_data, - BTM_MODE4_LEVEL4_NOT_SUPPORTED); - - return (BTM_MODE4_LEVEL4_NOT_SUPPORTED); - } + if (rc == BTM_SUCCESS) { + if (p_callback) + (*p_callback)(bd_addr, transport, (void*)p_ref_data, BTM_SUCCESS); + return (BTM_SUCCESS); + } } - /* there are some devices (moto KRZR) which connects to several services at the same time */ - /* we will process one after another */ - if ( (p_dev_rec->p_callback) || (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) ) - { - BTM_TRACE_EVENT ("%s() - busy - PSM:%d delayed state: %s mode:%d, sm4:0x%x", __func__, - psm, btm_pair_state_descr(btm_cb.pairing_state), btm_cb.security_mode, p_dev_rec->sm4); - BTM_TRACE_EVENT ("security_flags:x%x, sec_flags:x%x", security_required, p_dev_rec->sec_flags); - rc = BTM_CMD_STARTED; - if ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || - btm_cb.security_mode == BTM_SEC_MODE_NONE || - btm_cb.security_mode == BTM_SEC_MODE_SERVICE || - btm_cb.security_mode == BTM_SEC_MODE_LINK) || - (BTM_SM4_KNOWN == p_dev_rec->sm4) || (BTM_SEC_IS_SM4(p_dev_rec->sm4) && - (btm_sec_is_upgrade_possible(p_dev_rec, is_originator) == false))) - { - /* legacy mode - local is legacy or local is lisbon/peer is legacy - * or SM4 with no possibility of link key upgrade */ - if (is_originator) - { - if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || - ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_AUTHENTICATE) && btm_dev_authenticated(p_dev_rec))) || - ((((security_required & BTM_SEC_OUT_FLAGS) == (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && btm_dev_encrypted(p_dev_rec))) || - ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_FLAGS) && btm_dev_authorized(p_dev_rec) && btm_dev_encrypted(p_dev_rec))) ) - { - rc = BTM_SUCCESS; - } - } - else - { - if (((security_required & BTM_SEC_IN_FLAGS) == 0) || - (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHENTICATE) && btm_dev_authenticated(p_dev_rec)) || - (((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && btm_dev_encrypted(p_dev_rec)) || - (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHORIZE) && (btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_AUTHORIZE)) && ((btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec)) && btm_dev_authenticated(p_dev_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE)) && ((btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec)) && btm_dev_encrypted(p_dev_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_FLAGS) && btm_dev_encrypted(p_dev_rec) && (btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec)))) - { - // Check for 16 digits (or MITM) - if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || - (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == BTM_SEC_IN_MIN_16_DIGIT_PIN) && btm_dev_16_digit_authenticated(p_dev_rec))) { - rc = BTM_SUCCESS; - } - } - } - - if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - rc = BTM_CMD_STARTED; - } - - if (rc == BTM_SUCCESS) - { - if (p_callback) - (*p_callback) (bd_addr, transport, (void *)p_ref_data, BTM_SUCCESS); - return(BTM_SUCCESS); - } - } + btm_cb.sec_req_pending = true; + return (BTM_CMD_STARTED); + } - btm_cb.sec_req_pending = true; - return(BTM_CMD_STARTED); - } + /* Save pointer to service record */ + p_dev_rec->p_cur_service = p_serv_rec; - /* Save pointer to service record */ - p_dev_rec->p_cur_service = p_serv_rec; + /* Modify security_required in btm_sec_l2cap_access_req for Lisbon */ + if (btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) { + if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) { + if (is_originator) { + /* SM4 to SM4 -> always authenticate & encrypt */ + security_required |= (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT); + } else /* acceptor */ + { + /* SM4 to SM4: the acceptor needs to make sure the authentication is + * already done */ + chk_acp_auth_done = true; + /* SM4 to SM4 -> always authenticate & encrypt */ + security_required |= (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT); + } + } else if (!(BTM_SM4_KNOWN & p_dev_rec->sm4)) { + /* the remote features are not known yet */ + BTM_TRACE_DEBUG("%s: (%s) remote features unknown!!sec_flags:0x%02x", + __func__, (is_originator) ? "initiator" : "acceptor", + p_dev_rec->sec_flags); - /* Modify security_required in btm_sec_l2cap_access_req for Lisbon */ - if (btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) - { - if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) - { - if (is_originator) - { - /* SM4 to SM4 -> always authenticate & encrypt */ - security_required |= (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT); - } - else /* acceptor */ - { - /* SM4 to SM4: the acceptor needs to make sure the authentication is already done */ - chk_acp_auth_done = true; - /* SM4 to SM4 -> always authenticate & encrypt */ - security_required |= (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT); - } - } - else if (!(BTM_SM4_KNOWN & p_dev_rec->sm4)) - { - /* the remote features are not known yet */ - BTM_TRACE_DEBUG("%s: (%s) remote features unknown!!sec_flags:0x%02x", __func__, - (is_originator) ? "initiator" : "acceptor", p_dev_rec->sec_flags); - - p_dev_rec->sm4 |= BTM_SM4_REQ_PEND; - return (BTM_CMD_STARTED); - } + p_dev_rec->sm4 |= BTM_SM4_REQ_PEND; + return (BTM_CMD_STARTED); } + } - BTM_TRACE_DEBUG ("%s() sm4:0x%x, sec_flags:0x%x, security_required:0x%x chk:%d", __func__, - p_dev_rec->sm4, p_dev_rec->sec_flags, security_required, chk_acp_auth_done); + BTM_TRACE_DEBUG( + "%s() sm4:0x%x, sec_flags:0x%x, security_required:0x%x chk:%d", __func__, + p_dev_rec->sm4, p_dev_rec->sec_flags, security_required, + chk_acp_auth_done); - old_security_required = p_dev_rec->security_required; - old_is_originator = p_dev_rec->is_originator; - p_dev_rec->security_required = security_required; - p_dev_rec->p_ref_data = p_ref_data; - p_dev_rec->is_originator = is_originator; + old_security_required = p_dev_rec->security_required; + old_is_originator = p_dev_rec->is_originator; + p_dev_rec->security_required = security_required; + p_dev_rec->p_ref_data = p_ref_data; + p_dev_rec->is_originator = is_originator; #if (L2CAP_UCD_INCLUDED == TRUE) - if ( conn_type & CONNECTION_TYPE_CONNLESS_MASK ) - p_dev_rec->is_ucd = true; - else - p_dev_rec->is_ucd = false; + if (conn_type & CONNECTION_TYPE_CONNLESS_MASK) + p_dev_rec->is_ucd = true; + else + p_dev_rec->is_ucd = false; #endif - /* If there are multiple service records used through the same PSM */ - /* leave security decision for the multiplexor on the top */ +/* If there are multiple service records used through the same PSM */ +/* leave security decision for the multiplexor on the top */ #if (L2CAP_UCD_INCLUDED == TRUE) - if (((btm_sec_find_next_serv (p_serv_rec)) != NULL) - &&(!( conn_type & CONNECTION_TYPE_CONNLESS_MASK ))) /* if not UCD */ + if (((btm_sec_find_next_serv(p_serv_rec)) != NULL) && + (!(conn_type & CONNECTION_TYPE_CONNLESS_MASK))) /* if not UCD */ #else - if ((btm_sec_find_next_serv (p_serv_rec)) != NULL) + if ((btm_sec_find_next_serv(p_serv_rec)) != NULL) #endif - { - BTM_TRACE_DEBUG ("no next_serv sm4:0x%x, chk:%d", p_dev_rec->sm4, chk_acp_auth_done); - if (!BTM_SEC_IS_SM4(p_dev_rec->sm4)) - { - BTM_TRACE_EVENT ("Security Manager: l2cap_access_req PSM:%d postponed for multiplexer", psm); - /* pre-Lisbon: restore the old settings */ - p_dev_rec->security_required = old_security_required; - p_dev_rec->is_originator = old_is_originator; - - (*p_callback) (bd_addr, transport, p_ref_data, BTM_SUCCESS); - - return(BTM_SUCCESS); - } - } - - /* if the originator is using dynamic PSM in legacy mode, do not start any security process now - * The layer above L2CAP needs to carry out the security requirement after L2CAP connect - * response is received */ - if (is_originator && - ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || - btm_cb.security_mode == BTM_SEC_MODE_NONE || - btm_cb.security_mode == BTM_SEC_MODE_SERVICE || - btm_cb.security_mode == BTM_SEC_MODE_LINK) || - !BTM_SEC_IS_SM4(p_dev_rec->sm4)) && (psm >= 0x1001)) - { - BTM_TRACE_EVENT ("dynamic PSM:0x%x in legacy mode - postponed for upper layer", psm); - /* restore the old settings */ - p_dev_rec->security_required = old_security_required; - p_dev_rec->is_originator = old_is_originator; - - (*p_callback) (bd_addr, transport, p_ref_data, BTM_SUCCESS); - - return(BTM_SUCCESS); - } - - if (chk_acp_auth_done) - { - BTM_TRACE_DEBUG ("(SM4 to SM4) btm_sec_l2cap_access_req rspd. authenticated: x%x, enc: x%x", - (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED), (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED)); - /* SM4, but we do not know for sure which level of security we need. - * as long as we have a link key, it's OK */ - if ((0 == (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) - ||(0 == (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) - { - rc = BTM_DELAY_CHECK; - /* - 2046 may report HCI_Encryption_Change and L2C Connection Request out of sequence - because of data path issues. Delay this disconnect a little bit - */ - LOG_INFO(LOG_TAG, "%s peer should have initiated security process by now (SM4 to SM4)", __func__); - p_dev_rec->p_callback = p_callback; - p_dev_rec->sec_state = BTM_SEC_STATE_DELAY_FOR_ENC; - (*p_callback) (bd_addr, transport, p_ref_data, rc); - - return BTM_SUCCESS; - } - } - - p_dev_rec->p_callback = p_callback; - - if (p_dev_rec->last_author_service_id == BTM_SEC_NO_LAST_SERVICE_ID - || p_dev_rec->last_author_service_id != p_dev_rec->p_cur_service->service_id) - { - /* Although authentication and encryption are per connection - ** authorization is per access request. For example when serial connection - ** is up and authorized and client requests to read file (access to other - ** scn), we need to request user's permission again. - */ - p_dev_rec->sec_flags &= ~BTM_SEC_AUTHORIZED; - } + { + BTM_TRACE_DEBUG("no next_serv sm4:0x%x, chk:%d", p_dev_rec->sm4, + chk_acp_auth_done); + if (!BTM_SEC_IS_SM4(p_dev_rec->sm4)) { + BTM_TRACE_EVENT( + "Security Manager: l2cap_access_req PSM:%d postponed for multiplexer", + psm); + /* pre-Lisbon: restore the old settings */ + p_dev_rec->security_required = old_security_required; + p_dev_rec->is_originator = old_is_originator; + + (*p_callback)(bd_addr, transport, p_ref_data, BTM_SUCCESS); + + return (BTM_SUCCESS); + } + } + + /* if the originator is using dynamic PSM in legacy mode, do not start any + * security process now + * The layer above L2CAP needs to carry out the security requirement after + * L2CAP connect + * response is received */ + if (is_originator && ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || + btm_cb.security_mode == BTM_SEC_MODE_NONE || + btm_cb.security_mode == BTM_SEC_MODE_SERVICE || + btm_cb.security_mode == BTM_SEC_MODE_LINK) || + !BTM_SEC_IS_SM4(p_dev_rec->sm4)) && + (psm >= 0x1001)) { + BTM_TRACE_EVENT( + "dynamic PSM:0x%x in legacy mode - postponed for upper layer", psm); + /* restore the old settings */ + p_dev_rec->security_required = old_security_required; + p_dev_rec->is_originator = old_is_originator; + + (*p_callback)(bd_addr, transport, p_ref_data, BTM_SUCCESS); + + return (BTM_SUCCESS); + } + + if (chk_acp_auth_done) { + BTM_TRACE_DEBUG( + "(SM4 to SM4) btm_sec_l2cap_access_req rspd. authenticated: x%x, enc: " + "x%x", + (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED), + (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED)); + /* SM4, but we do not know for sure which level of security we need. + * as long as we have a link key, it's OK */ + if ((0 == (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) || + (0 == (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED))) { + rc = BTM_DELAY_CHECK; + /* + 2046 may report HCI_Encryption_Change and L2C Connection Request out of + sequence + because of data path issues. Delay this disconnect a little bit + */ + LOG_INFO( + LOG_TAG, + "%s peer should have initiated security process by now (SM4 to SM4)", + __func__); + p_dev_rec->p_callback = p_callback; + p_dev_rec->sec_state = BTM_SEC_STATE_DELAY_FOR_ENC; + (*p_callback)(bd_addr, transport, p_ref_data, rc); + + return BTM_SUCCESS; + } + } + + p_dev_rec->p_callback = p_callback; + + if (p_dev_rec->last_author_service_id == BTM_SEC_NO_LAST_SERVICE_ID || + p_dev_rec->last_author_service_id != + p_dev_rec->p_cur_service->service_id) { + /* Although authentication and encryption are per connection + ** authorization is per access request. For example when serial connection + ** is up and authorized and client requests to read file (access to other + ** scn), we need to request user's permission again. + */ + p_dev_rec->sec_flags &= ~BTM_SEC_AUTHORIZED; + } - if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) - { - if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - /* BTM_LKEY_TYPE_AUTH_COMB_P_256 is the only acceptable key in this case */ - if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) != 0) - { - p_dev_rec->sm4 |= BTM_SM4_UPGRADE; - } - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | - BTM_SEC_AUTHENTICATED); - BTM_TRACE_DEBUG ("%s: sec_flags:0x%x", __func__, p_dev_rec->sec_flags); - } - else - { - /* If we already have a link key to the connected peer, is it secure enough? */ - btm_sec_check_upgrade(p_dev_rec, is_originator); - } + if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) { + if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + /* BTM_LKEY_TYPE_AUTH_COMB_P_256 is the only acceptable key in this case + */ + if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) != 0) { + p_dev_rec->sm4 |= BTM_SM4_UPGRADE; + } + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | + BTM_SEC_AUTHENTICATED); + BTM_TRACE_DEBUG("%s: sec_flags:0x%x", __func__, p_dev_rec->sec_flags); + } else { + /* If we already have a link key to the connected peer, is it secure + * enough? */ + btm_sec_check_upgrade(p_dev_rec, is_originator); } + } - BTM_TRACE_EVENT ("%s() PSM:%d Handle:%d State:%d Flags: 0x%x Required: 0x%x Service ID:%d", - __func__, psm, handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, - p_dev_rec->security_required, p_dev_rec->p_cur_service->service_id); + BTM_TRACE_EVENT( + "%s() PSM:%d Handle:%d State:%d Flags: 0x%x Required: 0x%x Service ID:%d", + __func__, psm, handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, + p_dev_rec->security_required, p_dev_rec->p_cur_service->service_id); - rc = btm_sec_execute_procedure(p_dev_rec); - if (rc != BTM_CMD_STARTED) - { - p_dev_rec->p_callback = NULL; - (*p_callback) (bd_addr, transport, p_dev_rec->p_ref_data, (uint8_t)rc); - } + rc = btm_sec_execute_procedure(p_dev_rec); + if (rc != BTM_CMD_STARTED) { + p_dev_rec->p_callback = NULL; + (*p_callback)(bd_addr, transport, p_dev_rec->p_ref_data, (uint8_t)rc); + } - return(rc); + return (rc); } /******************************************************************************* @@ -2468,211 +2410,224 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, uint16_t psm, uint16_t ha * Returns BTM_CMD_STARTED * ******************************************************************************/ -tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, uint16_t psm, bool is_originator, - uint32_t mx_proto_id, uint32_t mx_chan_id, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_SEC_SERV_REC *p_serv_rec; - tBTM_STATUS rc; - uint16_t security_required; - bool transport = false;/* should check PSM range in LE connection oriented L2CAP connection */ - - BTM_TRACE_DEBUG ("%s() is_originator: %d", __func__, is_originator); - /* Find or get oldest record */ - p_dev_rec = btm_find_or_alloc_dev (bd_addr); - - /* Find the service record for the PSM */ - p_serv_rec = btm_sec_find_mx_serv (is_originator, psm, mx_proto_id, mx_chan_id); - - /* If there is no application registered with this PSM do not allow connection */ - if (!p_serv_rec) - { - if (p_callback) - (*p_callback) (bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); - - BTM_TRACE_ERROR ("Security Manager: MX service not found PSM:%d Proto:%d SCN:%d", - psm, mx_proto_id, mx_chan_id); - return BTM_NO_RESOURCES; - } - - if ((btm_cb.security_mode == BTM_SEC_MODE_SC) && (!btm_sec_is_serv_level0(psm))) - { - security_required = btm_sec_set_serv_level4_flags (p_serv_rec->security_flags, - is_originator); - } - else - { - security_required = p_serv_rec->security_flags; +tBTM_STATUS btm_sec_mx_access_request(BD_ADDR bd_addr, uint16_t psm, + bool is_originator, uint32_t mx_proto_id, + uint32_t mx_chan_id, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_SEC_SERV_REC* p_serv_rec; + tBTM_STATUS rc; + uint16_t security_required; + bool transport = false; /* should check PSM range in LE connection oriented + L2CAP connection */ + + BTM_TRACE_DEBUG("%s() is_originator: %d", __func__, is_originator); + /* Find or get oldest record */ + p_dev_rec = btm_find_or_alloc_dev(bd_addr); + + /* Find the service record for the PSM */ + p_serv_rec = + btm_sec_find_mx_serv(is_originator, psm, mx_proto_id, mx_chan_id); + + /* If there is no application registered with this PSM do not allow connection + */ + if (!p_serv_rec) { + if (p_callback) + (*p_callback)(bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); + + BTM_TRACE_ERROR( + "Security Manager: MX service not found PSM:%d Proto:%d SCN:%d", psm, + mx_proto_id, mx_chan_id); + return BTM_NO_RESOURCES; + } + + if ((btm_cb.security_mode == BTM_SEC_MODE_SC) && + (!btm_sec_is_serv_level0(psm))) { + security_required = btm_sec_set_serv_level4_flags( + p_serv_rec->security_flags, is_originator); + } else { + security_required = p_serv_rec->security_flags; + } + + /* there are some devices (moto phone) which connects to several services at + * the same time */ + /* we will process one after another */ + if ((p_dev_rec->p_callback) || + (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE)) { + BTM_TRACE_EVENT("%s() service PSM:%d Proto:%d SCN:%d delayed state: %s", + __func__, psm, mx_proto_id, mx_chan_id, + btm_pair_state_descr(btm_cb.pairing_state)); + + rc = BTM_CMD_STARTED; + + if ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || + btm_cb.security_mode == BTM_SEC_MODE_NONE || + btm_cb.security_mode == BTM_SEC_MODE_SERVICE || + btm_cb.security_mode == BTM_SEC_MODE_LINK) || + (BTM_SM4_KNOWN == p_dev_rec->sm4) || + (BTM_SEC_IS_SM4(p_dev_rec->sm4) && + (btm_sec_is_upgrade_possible(p_dev_rec, is_originator) == false))) { + /* legacy mode - local is legacy or local is lisbon/peer is legacy + * or SM4 with no possibility of link key upgrade */ + if (is_originator) { + if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + BTM_SEC_OUT_AUTHENTICATE) && + btm_dev_authenticated(p_dev_rec))) || + ((((security_required & BTM_SEC_OUT_FLAGS) == + (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && + btm_dev_encrypted(p_dev_rec)))) { + rc = BTM_SUCCESS; + } + } else { + if (((security_required & BTM_SEC_IN_FLAGS) == 0) || + ((((security_required & BTM_SEC_IN_FLAGS) == + BTM_SEC_IN_AUTHENTICATE) && + btm_dev_authenticated(p_dev_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHORIZE) && + (btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_AUTHENTICATE)) && + ((btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec)) && + btm_dev_authenticated(p_dev_rec))) || + (((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT)) && + ((btm_dev_authorized(p_dev_rec) || + btm_serv_trusted(p_dev_rec, p_serv_rec)) && + btm_dev_encrypted(p_dev_rec))) || + ((((security_required & BTM_SEC_IN_FLAGS) == + (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && + btm_dev_encrypted(p_dev_rec)))) { + // Check for 16 digits (or MITM) + if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || + (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == + BTM_SEC_IN_MIN_16_DIGIT_PIN) && + btm_dev_16_digit_authenticated(p_dev_rec))) { + rc = BTM_SUCCESS; + } + } + } + if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + rc = BTM_CMD_STARTED; + } } - /* there are some devices (moto phone) which connects to several services at the same time */ - /* we will process one after another */ - if ( (p_dev_rec->p_callback) || (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) ) - { - BTM_TRACE_EVENT ("%s() service PSM:%d Proto:%d SCN:%d delayed state: %s", __func__, - psm, mx_proto_id, mx_chan_id, btm_pair_state_descr(btm_cb.pairing_state)); - + if (rc == BTM_SUCCESS) { + BTM_TRACE_EVENT("%s: allow to bypass, checking authorization", __func__); + /* the security in BTM_SEC_IN_FLAGS is fullfilled so far, check the + * requirements in */ + /* btm_sec_execute_procedure */ + if ((is_originator && + (p_serv_rec->security_flags & BTM_SEC_OUT_AUTHORIZE)) || + (!is_originator && + (p_serv_rec->security_flags & BTM_SEC_IN_AUTHORIZE))) { + BTM_TRACE_EVENT("%s: still need authorization", __func__); rc = BTM_CMD_STARTED; - - if ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || - btm_cb.security_mode == BTM_SEC_MODE_NONE || - btm_cb.security_mode == BTM_SEC_MODE_SERVICE || - btm_cb.security_mode == BTM_SEC_MODE_LINK) || - (BTM_SM4_KNOWN == p_dev_rec->sm4) || (BTM_SEC_IS_SM4(p_dev_rec->sm4) && - (btm_sec_is_upgrade_possible(p_dev_rec, is_originator) == false))) - { - /* legacy mode - local is legacy or local is lisbon/peer is legacy - * or SM4 with no possibility of link key upgrade */ - if (is_originator) - { - if (((security_required & BTM_SEC_OUT_FLAGS) == 0) || - ((((security_required & BTM_SEC_OUT_FLAGS) == BTM_SEC_OUT_AUTHENTICATE) && btm_dev_authenticated(p_dev_rec))) || - ((((security_required & BTM_SEC_OUT_FLAGS) == (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT)) && btm_dev_encrypted(p_dev_rec))) - ) - { - rc = BTM_SUCCESS; - } - } - else - { - if (((security_required & BTM_SEC_IN_FLAGS) == 0) || - ((((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHENTICATE) && btm_dev_authenticated(p_dev_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == BTM_SEC_IN_AUTHORIZE) && (btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_AUTHENTICATE)) && ((btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec)) && btm_dev_authenticated(p_dev_rec))) || - (((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHORIZE | BTM_SEC_IN_ENCRYPT)) && ((btm_dev_authorized(p_dev_rec)||btm_serv_trusted(p_dev_rec, p_serv_rec))&& btm_dev_encrypted(p_dev_rec))) || - ((((security_required & BTM_SEC_IN_FLAGS) == (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT)) && btm_dev_encrypted(p_dev_rec))) - ) - { - // Check for 16 digits (or MITM) - if (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == 0) || - (((security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) == BTM_SEC_IN_MIN_16_DIGIT_PIN) && btm_dev_16_digit_authenticated(p_dev_rec))) { - rc = BTM_SUCCESS; - } - } - } - if ((rc == BTM_SUCCESS) && (security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - rc = BTM_CMD_STARTED; - } - } - - if (rc == BTM_SUCCESS) - { - BTM_TRACE_EVENT("%s: allow to bypass, checking authorization", __func__); - /* the security in BTM_SEC_IN_FLAGS is fullfilled so far, check the requirements in */ - /* btm_sec_execute_procedure */ - if ((is_originator && (p_serv_rec->security_flags & BTM_SEC_OUT_AUTHORIZE)) || - (!is_originator && (p_serv_rec->security_flags & BTM_SEC_IN_AUTHORIZE))) - { - BTM_TRACE_EVENT("%s: still need authorization", __func__); - rc = BTM_CMD_STARTED; - } - } - - /* Check whether there is a pending security procedure, if so we should always queue */ - /* the new security request */ - if (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE) - { - BTM_TRACE_EVENT("%s: There is a pending security procedure", __func__); - rc = BTM_CMD_STARTED; - } - if (rc == BTM_CMD_STARTED) - { - BTM_TRACE_EVENT("%s: call btm_sec_queue_mx_request", __func__); - btm_sec_queue_mx_request (bd_addr, psm, is_originator, mx_proto_id, - mx_chan_id, p_callback, p_ref_data); - } - else /* rc == BTM_SUCCESS */ - { - /* access granted */ - if (p_callback) - { - (*p_callback) (bd_addr, transport, p_ref_data, (uint8_t)rc); - } - } - - BTM_TRACE_EVENT("%s: return with rc = 0x%02x in delayed state %s", __func__, rc, - btm_pair_state_descr(btm_cb.pairing_state)); - return rc; + } } - if ((!is_originator) && ((security_required & BTM_SEC_MODE4_LEVEL4) || - (btm_cb.security_mode == BTM_SEC_MODE_SC))) + /* Check whether there is a pending security procedure, if so we should + * always queue */ + /* the new security request */ + if (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE) { + BTM_TRACE_EVENT("%s: There is a pending security procedure", __func__); + rc = BTM_CMD_STARTED; + } + if (rc == BTM_CMD_STARTED) { + BTM_TRACE_EVENT("%s: call btm_sec_queue_mx_request", __func__); + btm_sec_queue_mx_request(bd_addr, psm, is_originator, mx_proto_id, + mx_chan_id, p_callback, p_ref_data); + } else /* rc == BTM_SUCCESS */ { - bool local_supports_sc = controller_get_interface()->supports_secure_connections(); - /* acceptor receives service connection establishment Request for */ - /* Secure Connections Only service */ - if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) - { - BTM_TRACE_DEBUG("%s: SC only service,local_support_for_sc %d,", - "remote_support_for_sc %d: fail pairing",__func__, - local_supports_sc, p_dev_rec->remote_supports_secure_connections); - - if (p_callback) - (*p_callback) (bd_addr, transport, (void *)p_ref_data, - BTM_MODE4_LEVEL4_NOT_SUPPORTED); - - return (BTM_MODE4_LEVEL4_NOT_SUPPORTED); - } + /* access granted */ + if (p_callback) { + (*p_callback)(bd_addr, transport, p_ref_data, (uint8_t)rc); + } } - p_dev_rec->p_cur_service = p_serv_rec; - p_dev_rec->security_required = security_required; - - if (btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) - { - if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) - { - if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - /* BTM_LKEY_TYPE_AUTH_COMB_P_256 is the only acceptable key in this case */ - if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) != 0) - { - p_dev_rec->sm4 |= BTM_SM4_UPGRADE; - } - - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | - BTM_SEC_AUTHENTICATED); - BTM_TRACE_DEBUG("%s: sec_flags:0x%x", __func__, p_dev_rec->sec_flags); - } - else - { - /* If we already have a link key, check if that link key is good enough */ - btm_sec_check_upgrade(p_dev_rec, is_originator); - } + BTM_TRACE_EVENT("%s: return with rc = 0x%02x in delayed state %s", __func__, + rc, btm_pair_state_descr(btm_cb.pairing_state)); + return rc; + } + + if ((!is_originator) && ((security_required & BTM_SEC_MODE4_LEVEL4) || + (btm_cb.security_mode == BTM_SEC_MODE_SC))) { + bool local_supports_sc = + controller_get_interface()->supports_secure_connections(); + /* acceptor receives service connection establishment Request for */ + /* Secure Connections Only service */ + if (!(local_supports_sc) || + !(p_dev_rec->remote_supports_secure_connections)) { + BTM_TRACE_DEBUG("%s: SC only service,local_support_for_sc %d,", + "remote_support_for_sc %d: fail pairing", __func__, + local_supports_sc, + p_dev_rec->remote_supports_secure_connections); + + if (p_callback) + (*p_callback)(bd_addr, transport, (void*)p_ref_data, + BTM_MODE4_LEVEL4_NOT_SUPPORTED); + + return (BTM_MODE4_LEVEL4_NOT_SUPPORTED); + } + } + + p_dev_rec->p_cur_service = p_serv_rec; + p_dev_rec->security_required = security_required; + + if (btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) { + if (BTM_SEC_IS_SM4(p_dev_rec->sm4)) { + if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + /* BTM_LKEY_TYPE_AUTH_COMB_P_256 is the only acceptable key in this case + */ + if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) != 0) { + p_dev_rec->sm4 |= BTM_SM4_UPGRADE; } + + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | + BTM_SEC_AUTHENTICATED); + BTM_TRACE_DEBUG("%s: sec_flags:0x%x", __func__, p_dev_rec->sec_flags); + } else { + /* If we already have a link key, check if that link key is good enough + */ + btm_sec_check_upgrade(p_dev_rec, is_originator); + } } + } - p_dev_rec->is_originator = is_originator; - p_dev_rec->p_callback = p_callback; - p_dev_rec->p_ref_data = p_ref_data; + p_dev_rec->is_originator = is_originator; + p_dev_rec->p_callback = p_callback; + p_dev_rec->p_ref_data = p_ref_data; - /* Although authentication and encryption are per connection */ - /* authorization is per access request. For example when serial connection */ - /* is up and authorized and client requests to read file (access to other */ - /* scn, we need to request user's permission again. */ - p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED); + /* Although authentication and encryption are per connection */ + /* authorization is per access request. For example when serial connection */ + /* is up and authorized and client requests to read file (access to other */ + /* scn, we need to request user's permission again. */ + p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED); - BTM_TRACE_EVENT ("%s() proto_id:%d chan_id:%d State:%d Flags:0x%x Required:0x%x Service ID:%d", - __func__, mx_proto_id, mx_chan_id, p_dev_rec->sec_state, p_dev_rec->sec_flags, - p_dev_rec->security_required, p_dev_rec->p_cur_service->service_id); + BTM_TRACE_EVENT( + "%s() proto_id:%d chan_id:%d State:%d Flags:0x%x Required:0x%x Service " + "ID:%d", + __func__, mx_proto_id, mx_chan_id, p_dev_rec->sec_state, + p_dev_rec->sec_flags, p_dev_rec->security_required, + p_dev_rec->p_cur_service->service_id); - rc = btm_sec_execute_procedure(p_dev_rec); - if (rc != BTM_CMD_STARTED) - { - if (p_callback) - { - p_dev_rec->p_callback = NULL; - (*p_callback) (bd_addr,transport, p_ref_data, (uint8_t)rc); - } + rc = btm_sec_execute_procedure(p_dev_rec); + if (rc != BTM_CMD_STARTED) { + if (p_callback) { + p_dev_rec->p_callback = NULL; + (*p_callback)(bd_addr, transport, p_ref_data, (uint8_t)rc); } + } - return rc; + return rc; } /******************************************************************************* @@ -2685,73 +2640,67 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, uint16_t psm, bool is * Returns void * ******************************************************************************/ -void btm_sec_conn_req (uint8_t *bda, uint8_t *dc) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); - - /* Some device may request a connection before we are done with the HCI_Reset sequence */ - if (!controller_get_interface()->get_is_ready()) - { - BTM_TRACE_EVENT ("Security Manager: connect request when device not ready"); - btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); - return; - } +void btm_sec_conn_req(uint8_t* bda, uint8_t* dc) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + + /* Some device may request a connection before we are done with the HCI_Reset + * sequence */ + if (!controller_get_interface()->get_is_ready()) { + BTM_TRACE_EVENT("Security Manager: connect request when device not ready"); + btsnd_hcic_reject_conn(bda, HCI_ERR_HOST_REJECT_DEVICE); + return; + } - /* Security guys wants us not to allow connection from not paired devices */ + /* Security guys wants us not to allow connection from not paired devices */ - /* Check if connection is allowed for only paired devices */ - if (btm_cb.connect_only_paired) - { - if (!p_dev_rec || !(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)) - { - BTM_TRACE_EVENT ("Security Manager: connect request from non-paired device"); - btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); - return; - } + /* Check if connection is allowed for only paired devices */ + if (btm_cb.connect_only_paired) { + if (!p_dev_rec || !(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)) { + BTM_TRACE_EVENT( + "Security Manager: connect request from non-paired device"); + btsnd_hcic_reject_conn(bda, HCI_ERR_HOST_REJECT_DEVICE); + return; } + } #if (BTM_ALLOW_CONN_IF_NONDISCOVER == FALSE) - /* If non-discoverable, only allow known devices to connect */ - if (btm_cb.btm_inq_vars.discoverable_mode == BTM_NON_DISCOVERABLE) - { - if (!p_dev_rec) - { - BTM_TRACE_EVENT ("Security Manager: connect request from not paired device"); - btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); - return; - } - } + /* If non-discoverable, only allow known devices to connect */ + if (btm_cb.btm_inq_vars.discoverable_mode == BTM_NON_DISCOVERABLE) { + if (!p_dev_rec) { + BTM_TRACE_EVENT( + "Security Manager: connect request from not paired device"); + btsnd_hcic_reject_conn(bda, HCI_ERR_HOST_REJECT_DEVICE); + return; + } + } #endif - if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - &&(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - &&(!memcmp (btm_cb.pairing_bda, bda, BD_ADDR_LEN))) - { - BTM_TRACE_EVENT ("Security Manager: reject connect request from bonding device"); + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + (!memcmp(btm_cb.pairing_bda, bda, BD_ADDR_LEN))) { + BTM_TRACE_EVENT( + "Security Manager: reject connect request from bonding device"); - /* incoming connection from bonding device is rejected */ - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_REJECTED_CONNECT; - btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); - return; - } + /* incoming connection from bonding device is rejected */ + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_REJECTED_CONNECT; + btsnd_hcic_reject_conn(bda, HCI_ERR_HOST_REJECT_DEVICE); + return; + } - /* Host is not interested or approved connection. Save BDA and DC and */ - /* pass request to L2CAP */ - memcpy (btm_cb.connecting_bda, bda, BD_ADDR_LEN); - memcpy (btm_cb.connecting_dc, dc, DEV_CLASS_LEN); + /* Host is not interested or approved connection. Save BDA and DC and */ + /* pass request to L2CAP */ + memcpy(btm_cb.connecting_bda, bda, BD_ADDR_LEN); + memcpy(btm_cb.connecting_dc, dc, DEV_CLASS_LEN); - if (l2c_link_hci_conn_req (bda)) - { - if (!p_dev_rec) - { - /* accept the connection -> allocate a device record */ - p_dev_rec = btm_sec_alloc_dev (bda); - } - if (p_dev_rec) - { - p_dev_rec->sm4 |= BTM_SM4_CONN_PEND; - } + if (l2c_link_hci_conn_req(bda)) { + if (!p_dev_rec) { + /* accept the connection -> allocate a device record */ + p_dev_rec = btm_sec_alloc_dev(bda); } + if (p_dev_rec) { + p_dev_rec->sm4 |= BTM_SM4_CONN_PEND; + } + } } /******************************************************************************* @@ -2764,31 +2713,31 @@ void btm_sec_conn_req (uint8_t *bda, uint8_t *dc) * Returns void * ******************************************************************************/ -static void btm_sec_bond_cancel_complete (void) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) || - (BTM_PAIR_STATE_WAIT_LOCAL_PIN == btm_cb.pairing_state && - BTM_PAIR_FLAGS_WE_STARTED_DD & btm_cb.pairing_flags) || - (btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME && - BTM_PAIR_FLAGS_WE_CANCEL_DD & btm_cb.pairing_flags)) - { - /* for dedicated bonding in legacy mode, authentication happens at "link level" - * btm_sec_connected is called with failed status. - * In theory, the code that handles is_pairing_device/true should clean out security related code. - * However, this function may clean out the security related flags and btm_sec_connected would not know - * this function also needs to do proper clean up. - */ - p_dev_rec = btm_find_dev(btm_cb.pairing_bda); - if (p_dev_rec != NULL) - p_dev_rec->security_required = BTM_SEC_NONE; - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - - /* Notify application that the cancel succeeded */ - if (btm_cb.api.p_bond_cancel_cmpl_callback) - btm_cb.api.p_bond_cancel_cmpl_callback(BTM_SUCCESS); - } +static void btm_sec_bond_cancel_complete(void) { + tBTM_SEC_DEV_REC* p_dev_rec; + + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) || + (BTM_PAIR_STATE_WAIT_LOCAL_PIN == btm_cb.pairing_state && + BTM_PAIR_FLAGS_WE_STARTED_DD & btm_cb.pairing_flags) || + (btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME && + BTM_PAIR_FLAGS_WE_CANCEL_DD & btm_cb.pairing_flags)) { + /* for dedicated bonding in legacy mode, authentication happens at "link + * level" + * btm_sec_connected is called with failed status. + * In theory, the code that handles is_pairing_device/true should clean out + * security related code. + * However, this function may clean out the security related flags and + * btm_sec_connected would not know + * this function also needs to do proper clean up. + */ + p_dev_rec = btm_find_dev(btm_cb.pairing_bda); + if (p_dev_rec != NULL) p_dev_rec->security_required = BTM_SEC_NONE; + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + + /* Notify application that the cancel succeeded */ + if (btm_cb.api.p_bond_cancel_cmpl_callback) + btm_cb.api.p_bond_cancel_cmpl_callback(BTM_SUCCESS); + } } /******************************************************************************* @@ -2802,30 +2751,28 @@ static void btm_sec_bond_cancel_complete (void) * Returns void * ******************************************************************************/ -void btm_create_conn_cancel_complete (uint8_t *p) -{ - uint8_t status; +void btm_create_conn_cancel_complete(uint8_t* p) { + uint8_t status; - STREAM_TO_UINT8 (status, p); - BTM_TRACE_EVENT ("btm_create_conn_cancel_complete(): in State: %s status:%d", - btm_pair_state_descr(btm_cb.pairing_state), status); + STREAM_TO_UINT8(status, p); + BTM_TRACE_EVENT("btm_create_conn_cancel_complete(): in State: %s status:%d", + btm_pair_state_descr(btm_cb.pairing_state), status); - /* if the create conn cancel cmd was issued by the bond cancel, - ** the application needs to be notified that bond cancel succeeded - */ - switch (status) - { - case HCI_SUCCESS: - btm_sec_bond_cancel_complete(); - break; - case HCI_ERR_CONNECTION_EXISTS: - case HCI_ERR_NO_CONNECTION: - default: - /* Notify application of the error */ - if (btm_cb.api.p_bond_cancel_cmpl_callback) - btm_cb.api.p_bond_cancel_cmpl_callback(BTM_ERR_PROCESSING); - break; - } + /* if the create conn cancel cmd was issued by the bond cancel, + ** the application needs to be notified that bond cancel succeeded + */ + switch (status) { + case HCI_SUCCESS: + btm_sec_bond_cancel_complete(); + break; + case HCI_ERR_CONNECTION_EXISTS: + case HCI_ERR_NO_CONNECTION: + default: + /* Notify application of the error */ + if (btm_cb.api.p_bond_cancel_cmpl_callback) + btm_cb.api.p_bond_cancel_cmpl_callback(BTM_ERR_PROCESSING); + break; + } } /******************************************************************************* @@ -2839,49 +2786,41 @@ void btm_create_conn_cancel_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_sec_check_pending_reqs (void) -{ - if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) - { - /* First, resubmit L2CAP requests */ - if (btm_cb.sec_req_pending) - { - btm_cb.sec_req_pending = false; - l2cu_resubmit_pending_sec_req (NULL); +void btm_sec_check_pending_reqs(void) { + if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) { + /* First, resubmit L2CAP requests */ + if (btm_cb.sec_req_pending) { + btm_cb.sec_req_pending = false; + l2cu_resubmit_pending_sec_req(NULL); + } + + /* Now, re-submit anything in the mux queue */ + fixed_queue_t* bq = btm_cb.sec_pending_q; + + btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX); + + tBTM_SEC_QUEUE_ENTRY* p_e; + while ((p_e = (tBTM_SEC_QUEUE_ENTRY*)fixed_queue_try_dequeue(bq)) != NULL) { + /* Check that the ACL is still up before starting security procedures */ + if (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) { + if (p_e->psm != 0) { + BTM_TRACE_EVENT( + "%s PSM:0x%04x Is_Orig:%u mx_proto_id:%u mx_chan_id:%u", __func__, + p_e->psm, p_e->is_orig, p_e->mx_proto_id, p_e->mx_chan_id); + + btm_sec_mx_access_request(p_e->bd_addr, p_e->psm, p_e->is_orig, + p_e->mx_proto_id, p_e->mx_chan_id, + p_e->p_callback, p_e->p_ref_data); + } else { + BTM_SetEncryption(p_e->bd_addr, p_e->transport, p_e->p_callback, + p_e->p_ref_data, p_e->sec_act); } + } - /* Now, re-submit anything in the mux queue */ - fixed_queue_t *bq = btm_cb.sec_pending_q; - - btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX); - - tBTM_SEC_QUEUE_ENTRY *p_e; - while ((p_e = (tBTM_SEC_QUEUE_ENTRY *)fixed_queue_try_dequeue(bq)) != NULL) - { - /* Check that the ACL is still up before starting security procedures */ - if (btm_bda_to_acl(p_e->bd_addr, p_e->transport) != NULL) - { - if (p_e->psm != 0) - { - BTM_TRACE_EVENT("%s PSM:0x%04x Is_Orig:%u mx_proto_id:%u mx_chan_id:%u", - __func__, p_e->psm, p_e->is_orig, - p_e->mx_proto_id, p_e->mx_chan_id); - - btm_sec_mx_access_request (p_e->bd_addr, p_e->psm, p_e->is_orig, - p_e->mx_proto_id, p_e->mx_chan_id, - p_e->p_callback, p_e->p_ref_data); - } - else - { - BTM_SetEncryption(p_e->bd_addr, p_e->transport, p_e->p_callback, - p_e->p_ref_data, p_e->sec_act); - } - } - - osi_free(p_e); - } - fixed_queue_free(bq, NULL); + osi_free(p_e); } + fixed_queue_free(bq, NULL); + } } /******************************************************************************* @@ -2893,11 +2832,10 @@ void btm_sec_check_pending_reqs (void) * Returns void * ******************************************************************************/ -void btm_sec_init (uint8_t sec_mode) -{ - btm_cb.security_mode = sec_mode; - memset (btm_cb.pairing_bda, 0xff, BD_ADDR_LEN); - btm_cb.max_collision_delay = BTM_SEC_MAX_COLLISION_DELAY; +void btm_sec_init(uint8_t sec_mode) { + btm_cb.security_mode = sec_mode; + memset(btm_cb.pairing_bda, 0xff, BD_ADDR_LEN); + btm_cb.max_collision_delay = BTM_SEC_MAX_COLLISION_DELAY; } /******************************************************************************* @@ -2910,10 +2848,10 @@ void btm_sec_init (uint8_t sec_mode) * Returns void * ******************************************************************************/ -void btm_sec_device_down (void) -{ - BTM_TRACE_EVENT ("%s() State: %s", __func__, btm_pair_state_descr(btm_cb.pairing_state)); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); +void btm_sec_device_down(void) { + BTM_TRACE_EVENT("%s() State: %s", __func__, + btm_pair_state_descr(btm_cb.pairing_state)); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); } /******************************************************************************* @@ -2925,22 +2863,18 @@ void btm_sec_device_down (void) * Returns void * ******************************************************************************/ -void btm_sec_dev_reset (void) -{ - if (controller_get_interface()->supports_simple_pairing()) - { - /* set the default IO capabilities */ - btm_cb.devcb.loc_io_caps = BTM_LOCAL_IO_CAPS; - /* add mx service to use no security */ - BTM_SetSecurityLevel(false, "RFC_MUX", BTM_SEC_SERVICE_RFC_MUX, - BTM_SEC_NONE, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, 0); - } - else - { - btm_cb.security_mode = BTM_SEC_MODE_SERVICE; - } - - BTM_TRACE_DEBUG ("btm_sec_dev_reset sec mode: %d", btm_cb.security_mode); +void btm_sec_dev_reset(void) { + if (controller_get_interface()->supports_simple_pairing()) { + /* set the default IO capabilities */ + btm_cb.devcb.loc_io_caps = BTM_LOCAL_IO_CAPS; + /* add mx service to use no security */ + BTM_SetSecurityLevel(false, "RFC_MUX", BTM_SEC_SERVICE_RFC_MUX, + BTM_SEC_NONE, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, 0); + } else { + btm_cb.security_mode = BTM_SEC_MODE_SERVICE; + } + + BTM_TRACE_DEBUG("btm_sec_dev_reset sec mode: %d", btm_cb.security_mode); } /******************************************************************************* @@ -2955,19 +2889,17 @@ void btm_sec_dev_reset (void) * Returns void * ******************************************************************************/ -void btm_sec_abort_access_req (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); +void btm_sec_abort_access_req(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if (!p_dev_rec) - return; + if (!p_dev_rec) return; - if ((p_dev_rec->sec_state != BTM_SEC_STATE_AUTHORIZING) - && (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING)) - return; + if ((p_dev_rec->sec_state != BTM_SEC_STATE_AUTHORIZING) && + (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING)) + return; - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - p_dev_rec->p_callback = NULL; + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + p_dev_rec->p_callback = NULL; } /******************************************************************************* @@ -2980,59 +2912,60 @@ void btm_sec_abort_access_req (BD_ADDR bd_addr) * Returns void * ******************************************************************************/ -static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb && (p_lcb->link_state == LST_CONNECTED || p_lcb->link_state == LST_CONNECTING)) - { - BTM_TRACE_WARNING("%s Connection already exists", __func__); - btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); - return BTM_CMD_STARTED; - } - - /* Make sure an L2cap link control block is available */ - if (!p_lcb && (p_lcb = l2cu_allocate_lcb (p_dev_rec->bd_addr, true, BT_TRANSPORT_BR_EDR)) == NULL) - { - BTM_TRACE_WARNING ("Security Manager: failed allocate LCB [%02x%02x%02x%02x%02x%02x]", - p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], - p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); - - return(BTM_NO_RESOURCES); - } - - /* set up the control block to indicated dedicated bonding */ - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_DISC_WHEN_DONE; - - if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) - { - BTM_TRACE_WARNING ("Security Manager: failed create [%02x%02x%02x%02x%02x%02x]", - p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], - p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); - - l2cu_release_lcb(p_lcb); - return(BTM_NO_RESOURCES); - } - - btm_acl_update_busy_level (BTM_BLI_PAGE_EVT); - - BTM_TRACE_DEBUG ("Security Manager: btm_sec_dd_create_conn [%02x%02x%02x%02x%02x%02x]", - p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], - p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); - - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); - - return(BTM_CMD_STARTED); +static tBTM_STATUS btm_sec_dd_create_conn(tBTM_SEC_DEV_REC* p_dev_rec) { + tL2C_LCB* p_lcb = + l2cu_find_lcb_by_bd_addr(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb && (p_lcb->link_state == LST_CONNECTED || + p_lcb->link_state == LST_CONNECTING)) { + BTM_TRACE_WARNING("%s Connection already exists", __func__); + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); + return BTM_CMD_STARTED; + } + + /* Make sure an L2cap link control block is available */ + if (!p_lcb && + (p_lcb = l2cu_allocate_lcb(p_dev_rec->bd_addr, true, + BT_TRANSPORT_BR_EDR)) == NULL) { + BTM_TRACE_WARNING( + "Security Manager: failed allocate LCB [%02x%02x%02x%02x%02x%02x]", + p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], + p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); + + return (BTM_NO_RESOURCES); + } + + /* set up the control block to indicated dedicated bonding */ + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_DISC_WHEN_DONE; + + if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) { + BTM_TRACE_WARNING( + "Security Manager: failed create [%02x%02x%02x%02x%02x%02x]", + p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], + p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); + + l2cu_release_lcb(p_lcb); + return (BTM_NO_RESOURCES); + } + + btm_acl_update_busy_level(BTM_BLI_PAGE_EVT); + + BTM_TRACE_DEBUG( + "Security Manager: btm_sec_dd_create_conn [%02x%02x%02x%02x%02x%02x]", + p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], + p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); + + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_PIN_REQ); + + return (BTM_CMD_STARTED); } +bool is_state_getting_name(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); -bool is_state_getting_name(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - - if (p_dev_rec->sec_state == BTM_SEC_STATE_GETTING_NAME) { - return false; - } - return true; + if (p_dev_rec->sec_state == BTM_SEC_STATE_GETTING_NAME) { + return false; + } + return true; } /******************************************************************************* @@ -3045,238 +2978,239 @@ bool is_state_getting_name(void *data, void *context) * Returns void * ******************************************************************************/ -void btm_sec_rmt_name_request_complete (uint8_t *p_bd_addr, uint8_t *p_bd_name, uint8_t status) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - int i; - DEV_CLASS dev_class; - uint8_t old_sec_state; - - BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete"); - if (((p_bd_addr == NULL) && !BTM_ACL_IS_CONNECTED(btm_cb.connecting_bda)) - || ((p_bd_addr != NULL) && !BTM_ACL_IS_CONNECTED(p_bd_addr))) - { - btm_acl_resubmit_page(); +void btm_sec_rmt_name_request_complete(uint8_t* p_bd_addr, uint8_t* p_bd_name, + uint8_t status) { + tBTM_SEC_DEV_REC* p_dev_rec; + int i; + DEV_CLASS dev_class; + uint8_t old_sec_state; + + BTM_TRACE_EVENT("btm_sec_rmt_name_request_complete"); + if (((p_bd_addr == NULL) && !BTM_ACL_IS_CONNECTED(btm_cb.connecting_bda)) || + ((p_bd_addr != NULL) && !BTM_ACL_IS_CONNECTED(p_bd_addr))) { + btm_acl_resubmit_page(); + } + + /* If remote name request failed, p_bd_addr is null and we need to search */ + /* based on state assuming that we are doing 1 at a time */ + if (p_bd_addr) + p_dev_rec = btm_find_dev(p_bd_addr); + else { + list_node_t* node = + list_foreach(btm_cb.sec_dev_rec, is_state_getting_name, NULL); + if (node != NULL) { + p_dev_rec = static_cast(list_node(node)); + p_bd_addr = p_dev_rec->bd_addr; + } else { + p_dev_rec = NULL; } + } - /* If remote name request failed, p_bd_addr is null and we need to search */ - /* based on state assuming that we are doing 1 at a time */ - if (p_bd_addr) - p_dev_rec = btm_find_dev (p_bd_addr); - else - { - list_node_t *node = list_foreach(btm_cb.sec_dev_rec, is_state_getting_name, NULL); - if (node != NULL) { - p_dev_rec = static_cast(list_node(node)); - p_bd_addr = p_dev_rec->bd_addr; - } else { - p_dev_rec = NULL; - } + /* Commenting out trace due to obf/compilation problems. + */ + if (!p_bd_name) p_bd_name = (uint8_t*)""; + + if (p_dev_rec) { + BTM_TRACE_EVENT( + "%s PairState: %s RemName: %s status: %d State:%d p_dev_rec: " + "0x%08x ", + __func__, btm_pair_state_descr(btm_cb.pairing_state), p_bd_name, status, + p_dev_rec->sec_state, p_dev_rec); + } else { + BTM_TRACE_EVENT("%s PairState: %s RemName: %s status: %d", __func__, + btm_pair_state_descr(btm_cb.pairing_state), p_bd_name, + status); + } + + if (p_dev_rec) { + old_sec_state = p_dev_rec->sec_state; + if (status == HCI_SUCCESS) { + strlcpy((char*)p_dev_rec->sec_bd_name, (char*)p_bd_name, + BTM_MAX_REM_BD_NAME_LEN); + p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; + BTM_TRACE_EVENT("setting BTM_SEC_NAME_KNOWN sec_flags:0x%x", + p_dev_rec->sec_flags); + } else { + /* Notify all clients waiting for name to be resolved even if it failed so + * clients can continue */ + p_dev_rec->sec_bd_name[0] = 0; } - /* Commenting out trace due to obf/compilation problems. - */ - if (!p_bd_name) - p_bd_name = (uint8_t *)""; + if (p_dev_rec->sec_state == BTM_SEC_STATE_GETTING_NAME) + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - if (p_dev_rec) - { - BTM_TRACE_EVENT ("%s PairState: %s RemName: %s status: %d State:%d p_dev_rec: 0x%08x ", __func__, - btm_pair_state_descr (btm_cb.pairing_state), p_bd_name, - status, p_dev_rec->sec_state, p_dev_rec); - } else { - BTM_TRACE_EVENT ("%s PairState: %s RemName: %s status: %d", __func__, - btm_pair_state_descr (btm_cb.pairing_state), p_bd_name, - status); + /* Notify all clients waiting for name to be resolved */ + for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) { + if (btm_cb.p_rmt_name_callback[i] && p_bd_addr) + (*btm_cb.p_rmt_name_callback[i])(p_bd_addr, p_dev_rec->dev_class, + p_dev_rec->sec_bd_name); } + } else { + dev_class[0] = 0; + dev_class[1] = 0; + dev_class[2] = 0; - if (p_dev_rec) - { - old_sec_state = p_dev_rec->sec_state; - if (status == HCI_SUCCESS) - { - strlcpy((char *)p_dev_rec->sec_bd_name, (char *)p_bd_name, BTM_MAX_REM_BD_NAME_LEN); - p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; - BTM_TRACE_EVENT ("setting BTM_SEC_NAME_KNOWN sec_flags:0x%x", p_dev_rec->sec_flags); - } - else - { - /* Notify all clients waiting for name to be resolved even if it failed so clients can continue */ - p_dev_rec->sec_bd_name[0] = 0; - } + /* Notify all clients waiting for name to be resolved even if not found so + * clients can continue */ + for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) { + if (btm_cb.p_rmt_name_callback[i] && p_bd_addr) + (*btm_cb.p_rmt_name_callback[i])(p_bd_addr, dev_class, (uint8_t*)""); + } - if (p_dev_rec->sec_state == BTM_SEC_STATE_GETTING_NAME) - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + return; + } + + /* If we were delaying asking UI for a PIN because name was not resolved, ask + * now */ + if ((btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_LOCAL_PIN) && p_bd_addr && + (memcmp(btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0)) { + BTM_TRACE_EVENT( + "%s() delayed pin now being requested flags:0x%x, " + "(p_pin_callback=0x%p)", + __func__, btm_cb.pairing_flags, btm_cb.api.p_pin_callback); + + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0 && + btm_cb.api.p_pin_callback) { + BTM_TRACE_EVENT("%s() calling pin_callback", __func__); + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; + (*btm_cb.api.p_pin_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_bd_name, + (p_dev_rec->p_cur_service == NULL) + ? false + : (p_dev_rec->p_cur_service->security_flags & + BTM_SEC_IN_MIN_16_DIGIT_PIN)); + } + + /* Set the same state again to force the timer to be restarted */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_PIN); + return; + } + + /* Check if we were delaying bonding because name was not resolved */ + if (btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME) { + if (p_bd_addr && memcmp(btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0) { + BTM_TRACE_EVENT("%s() continue bonding sm4: 0x%04x, status:0x%x", + __func__, p_dev_rec->sm4, status); + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_CANCEL_DD) { + btm_sec_bond_cancel_complete(); + return; + } - /* Notify all clients waiting for name to be resolved */ - for (i = 0;i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) - { - if (btm_cb.p_rmt_name_callback[i] && p_bd_addr) - (*btm_cb.p_rmt_name_callback[i])(p_bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name); - } - } else { - dev_class[0] = 0; - dev_class[1] = 0; - dev_class[2] = 0; - - /* Notify all clients waiting for name to be resolved even if not found so clients can continue */ - for (i = 0;i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) - { - if (btm_cb.p_rmt_name_callback[i] && p_bd_addr) - (*btm_cb.p_rmt_name_callback[i])(p_bd_addr, dev_class, (uint8_t *)""); - } + if (status != HCI_SUCCESS) { + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + status); return; - } + } - /* If we were delaying asking UI for a PIN because name was not resolved, ask now */ - if ( (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_LOCAL_PIN) && p_bd_addr - && (memcmp (btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0) ) - { - BTM_TRACE_EVENT ("%s() delayed pin now being requested flags:0x%x, (p_pin_callback=0x%p)", - __func__, btm_cb.pairing_flags, btm_cb.api.p_pin_callback); - - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0 && btm_cb.api.p_pin_callback) - { - BTM_TRACE_EVENT ("%s() calling pin_callback", __func__); - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; - (*btm_cb.api.p_pin_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, p_bd_name, - (p_dev_rec->p_cur_service==NULL) ? false - : (p_dev_rec->p_cur_service->security_flags & BTM_SEC_IN_MIN_16_DIGIT_PIN)); + /* if peer is very old legacy devices, HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT is + * not reported */ + if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) { + /* set the KNOWN flag only if BTM_PAIR_FLAGS_REJECTED_CONNECT is not + * set.*/ + /* If it is set, there may be a race condition */ + BTM_TRACE_DEBUG("%s IS_SM4_UNKNOWN Flags:0x%04x", __func__, + btm_cb.pairing_flags); + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) == 0) + p_dev_rec->sm4 |= BTM_SM4_KNOWN; + } + + BTM_TRACE_DEBUG("%s, SM4 Value: %x, Legacy:%d,IS SM4:%d, Unknown:%d", + __func__, p_dev_rec->sm4, + BTM_SEC_IS_SM4_LEGACY(p_dev_rec->sm4), + BTM_SEC_IS_SM4(p_dev_rec->sm4), + BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)); + + /* BT 2.1 or carkit, bring up the connection to force the peer to request + *PIN. + ** Else prefetch (btm_sec_check_prefetch_pin will do the prefetching if + *needed) + */ + if ((p_dev_rec->sm4 != BTM_SM4_KNOWN) || + !btm_sec_check_prefetch_pin(p_dev_rec)) { + /* if we rejected incoming connection request, we have to wait + * HCI_Connection_Complete event */ + /* before originating */ + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) { + BTM_TRACE_WARNING( + "%s: waiting HCI_Connection_Complete after rejecting connection", + __func__); } + /* Both we and the peer are 2.1 - continue to create connection */ + else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) { + BTM_TRACE_WARNING("%s: failed to start connection", __func__); - /* Set the same state again to force the timer to be restarted */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_LOCAL_PIN); - return; - } + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - /* Check if we were delaying bonding because name was not resolved */ - if ( btm_cb.pairing_state == BTM_PAIR_STATE_GET_REM_NAME) - { - if (p_bd_addr && memcmp (btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0) - { - BTM_TRACE_EVENT ("%s() continue bonding sm4: 0x%04x, status:0x%x", __func__, p_dev_rec->sm4, status); - if(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_CANCEL_DD) - { - btm_sec_bond_cancel_complete(); - return; - } - - if (status != HCI_SUCCESS) - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, status); - return; - } - - /* if peer is very old legacy devices, HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT is not reported */ - if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) - { - /* set the KNOWN flag only if BTM_PAIR_FLAGS_REJECTED_CONNECT is not set.*/ - /* If it is set, there may be a race condition */ - BTM_TRACE_DEBUG ("%s IS_SM4_UNKNOWN Flags:0x%04x", __func__, - btm_cb.pairing_flags); - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) == 0) - p_dev_rec->sm4 |= BTM_SM4_KNOWN; - } - - BTM_TRACE_DEBUG("%s, SM4 Value: %x, Legacy:%d,IS SM4:%d, Unknown:%d",__func__, - p_dev_rec->sm4, BTM_SEC_IS_SM4_LEGACY(p_dev_rec->sm4), - BTM_SEC_IS_SM4(p_dev_rec->sm4),BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)); - - /* BT 2.1 or carkit, bring up the connection to force the peer to request PIN. - ** Else prefetch (btm_sec_check_prefetch_pin will do the prefetching if needed) - */ - if ((p_dev_rec->sm4 != BTM_SM4_KNOWN) || !btm_sec_check_prefetch_pin(p_dev_rec)) - { - /* if we rejected incoming connection request, we have to wait HCI_Connection_Complete event */ - /* before originating */ - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) - { - BTM_TRACE_WARNING ("%s: waiting HCI_Connection_Complete after rejecting connection", __func__); - } - /* Both we and the peer are 2.1 - continue to create connection */ - else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) - { - BTM_TRACE_WARNING ("%s: failed to start connection", __func__); - - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_ERR_MEMORY_FULL); - } - } - return; - } else { - BTM_TRACE_WARNING ("%s: wrong BDA, retry with pairing BDA", __func__); - BTM_ReadRemoteDeviceName (btm_cb.pairing_bda, NULL, BT_TRANSPORT_BR_EDR); - return; + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, HCI_ERR_MEMORY_FULL); } + } + return; + } else { + BTM_TRACE_WARNING("%s: wrong BDA, retry with pairing BDA", __func__); + BTM_ReadRemoteDeviceName(btm_cb.pairing_bda, NULL, BT_TRANSPORT_BR_EDR); + return; } + } - /* check if we were delaying link_key_callback because name was not resolved */ - if (p_dev_rec->link_key_not_sent) - { - /* If HCI connection complete has not arrived, wait for it */ - if (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) - return; + /* check if we were delaying link_key_callback because name was not resolved + */ + if (p_dev_rec->link_key_not_sent) { + /* If HCI connection complete has not arrived, wait for it */ + if (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE) return; - p_dev_rec->link_key_not_sent = false; - btm_send_link_key_notif(p_dev_rec); + p_dev_rec->link_key_not_sent = false; + btm_send_link_key_notif(p_dev_rec); - /* If its not us who perform authentication, we should tell stackserver */ - /* that some authentication has been completed */ - /* This is required when different entities receive link notification and auth complete */ - if (!(p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) - { - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_SUCCESS); - - } - } - - /* If this is a bonding procedure can disconnect the link now */ - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - && (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) - { - BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete (none/ce)"); - p_dev_rec->security_required &= ~(BTM_SEC_OUT_AUTHENTICATE); - l2cu_start_post_bond_timer(p_dev_rec->hci_handle); - return; - } + /* If its not us who perform authentication, we should tell stackserver */ + /* that some authentication has been completed */ + /* This is required when different entities receive link notification and + * auth complete */ + if (!(p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) { + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_SUCCESS); + } + } + + /* If this is a bonding procedure can disconnect the link now */ + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) { + BTM_TRACE_WARNING("btm_sec_rmt_name_request_complete (none/ce)"); + p_dev_rec->security_required &= ~(BTM_SEC_OUT_AUTHENTICATE); + l2cu_start_post_bond_timer(p_dev_rec->hci_handle); + return; + } - if (old_sec_state != BTM_SEC_STATE_GETTING_NAME) - return; + if (old_sec_state != BTM_SEC_STATE_GETTING_NAME) return; - /* If get name failed, notify the waiting layer */ - if (status != HCI_SUCCESS) - { - btm_sec_dev_rec_cback_event (p_dev_rec, BTM_ERR_PROCESSING, false); - return; - } + /* If get name failed, notify the waiting layer */ + if (status != HCI_SUCCESS) { + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); + return; + } - if (p_dev_rec->sm4 & BTM_SM4_REQ_PEND) - { - BTM_TRACE_EVENT ("waiting for remote features!!"); - return; - } + if (p_dev_rec->sm4 & BTM_SM4_REQ_PEND) { + BTM_TRACE_EVENT("waiting for remote features!!"); + return; + } - /* Remote Name succeeded, execute the next security procedure, if any */ - status = (uint8_t)btm_sec_execute_procedure (p_dev_rec); + /* Remote Name succeeded, execute the next security procedure, if any */ + status = (uint8_t)btm_sec_execute_procedure(p_dev_rec); - /* If result is pending reply from the user or from the device is pending */ - if (status == BTM_CMD_STARTED) - return; + /* If result is pending reply from the user or from the device is pending */ + if (status == BTM_CMD_STARTED) return; - /* There is no next procedure or start of procedure failed, notify the waiting layer */ - btm_sec_dev_rec_cback_event (p_dev_rec, status, false); + /* There is no next procedure or start of procedure failed, notify the waiting + * layer */ + btm_sec_dev_rec_cback_event(p_dev_rec, status, false); } /******************************************************************************* @@ -3289,27 +3223,27 @@ void btm_sec_rmt_name_request_complete (uint8_t *p_bd_addr, uint8_t *p_bd_name, * Returns void * ******************************************************************************/ -void btm_sec_rmt_host_support_feat_evt (uint8_t *p) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - BD_ADDR bd_addr; /* peer address */ - BD_FEATURES features; +void btm_sec_rmt_host_support_feat_evt(uint8_t* p) { + tBTM_SEC_DEV_REC* p_dev_rec; + BD_ADDR bd_addr; /* peer address */ + BD_FEATURES features; - STREAM_TO_BDADDR (bd_addr, p); - p_dev_rec = btm_find_or_alloc_dev (bd_addr); + STREAM_TO_BDADDR(bd_addr, p); + p_dev_rec = btm_find_or_alloc_dev(bd_addr); - BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x p[0]: 0x%x", p_dev_rec->sm4, p[0]); + BTM_TRACE_EVENT("btm_sec_rmt_host_support_feat_evt sm4: 0x%x p[0]: 0x%x", + p_dev_rec->sm4, p[0]); - if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) - { - p_dev_rec->sm4 = BTM_SM4_KNOWN; - STREAM_TO_ARRAY(features, p, HCI_FEATURE_BYTES_PER_PAGE); - if (HCI_SSP_HOST_SUPPORTED(features)) - { - p_dev_rec->sm4 = BTM_SM4_TRUE; - } - BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x features[0]: 0x%x", p_dev_rec->sm4, features[0]); - } + if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) { + p_dev_rec->sm4 = BTM_SM4_KNOWN; + STREAM_TO_ARRAY(features, p, HCI_FEATURE_BYTES_PER_PAGE); + if (HCI_SSP_HOST_SUPPORTED(features)) { + p_dev_rec->sm4 = BTM_SM4_TRUE; + } + BTM_TRACE_EVENT( + "btm_sec_rmt_host_support_feat_evt sm4: 0x%x features[0]: 0x%x", + p_dev_rec->sm4, features[0]); + } } /******************************************************************************* @@ -3323,200 +3257,193 @@ void btm_sec_rmt_host_support_feat_evt (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_io_capabilities_req (uint8_t *p) -{ - tBTM_SP_IO_REQ evt_data; - uint8_t err_code = 0; - tBTM_SEC_DEV_REC *p_dev_rec; - bool is_orig = true; - uint8_t callback_rc = BTM_SUCCESS; - - STREAM_TO_BDADDR (evt_data.bd_addr, p); - - /* setup the default response according to compile options */ - /* assume that the local IO capability does not change - * loc_io_caps is initialized with the default value */ - evt_data.io_cap = btm_cb.devcb.loc_io_caps; - evt_data.oob_data = BTM_OOB_NONE; - evt_data.auth_req = BTM_DEFAULT_AUTH_REQ; - - BTM_TRACE_EVENT("%s: State: %s", __func__, btm_pair_state_descr(btm_cb.pairing_state)); - - p_dev_rec = btm_find_or_alloc_dev (evt_data.bd_addr); - - BTM_TRACE_DEBUG("%s:Security mode: %d, Num Read Remote Feat pages: %d", __func__, - btm_cb.security_mode, p_dev_rec->num_read_pages); - - if ((btm_cb.security_mode == BTM_SEC_MODE_SC) && (p_dev_rec->num_read_pages == 0)) - { - BTM_TRACE_EVENT("%s: Device security mode is SC only.", - "To continue need to know remote features.", __func__); - - p_dev_rec->remote_features_needed = true; - return; - } +void btm_io_capabilities_req(uint8_t* p) { + tBTM_SP_IO_REQ evt_data; + uint8_t err_code = 0; + tBTM_SEC_DEV_REC* p_dev_rec; + bool is_orig = true; + uint8_t callback_rc = BTM_SUCCESS; - p_dev_rec->sm4 |= BTM_SM4_TRUE; + STREAM_TO_BDADDR(evt_data.bd_addr, p); - BTM_TRACE_EVENT("%s: State: %s Flags: 0x%04x p_cur_service: 0x%08x", - __func__, btm_pair_state_descr(btm_cb.pairing_state), - btm_cb.pairing_flags, p_dev_rec->p_cur_service); + /* setup the default response according to compile options */ + /* assume that the local IO capability does not change + * loc_io_caps is initialized with the default value */ + evt_data.io_cap = btm_cb.devcb.loc_io_caps; + evt_data.oob_data = BTM_OOB_NONE; + evt_data.auth_req = BTM_DEFAULT_AUTH_REQ; - if (p_dev_rec->p_cur_service) - { - BTM_TRACE_EVENT("%s: cur_service psm: 0x%04x, security_flags: 0x%04x", - __func__, p_dev_rec->p_cur_service->psm, - p_dev_rec->p_cur_service->security_flags); - } - - switch (btm_cb.pairing_state) - { - /* initiator connecting */ - case BTM_PAIR_STATE_IDLE: - //TODO: Handle Idle pairing state - //security_required = p_dev_rec->security_required; - break; - - /* received IO capability response already->acceptor */ - case BTM_PAIR_STATE_INCOMING_SSP: - is_orig = false; - - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_PEER_STARTED_DD) - { - /* acceptor in dedicated bonding */ - evt_data.auth_req = BTM_DEFAULT_DD_AUTH_REQ; - } - break; - - /* initiator, at this point it is expected to be dedicated bonding - initiated by local device */ - case BTM_PAIR_STATE_WAIT_PIN_REQ: - if (!memcmp (evt_data.bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN)) - { - evt_data.auth_req = BTM_DEFAULT_DD_AUTH_REQ; - } - else - { - err_code = HCI_ERR_HOST_BUSY_PAIRING; - } - break; - - /* any other state is unexpected */ - default: - err_code = HCI_ERR_HOST_BUSY_PAIRING; - BTM_TRACE_ERROR("%s: Unexpected Pairing state received %d", __func__, - btm_cb.pairing_state); - break; - } - - if (btm_cb.pairing_disabled) - { - /* pairing is not allowed */ - BTM_TRACE_DEBUG("%s: Pairing is not allowed -> fail pairing.", __func__); - err_code = HCI_ERR_PAIRING_NOT_ALLOWED; - } - else if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - bool local_supports_sc = controller_get_interface()->supports_secure_connections(); - /* device in Secure Connections Only mode */ - if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) - { - BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d,", - " remote_support_for_sc 0x%02x -> fail pairing", __func__, - local_supports_sc, p_dev_rec->remote_supports_secure_connections); - - err_code = HCI_ERR_PAIRING_NOT_ALLOWED; - } - } - - if (err_code != 0) - { -/* coverity[uninit_use_in_call] -Event uninit_use_in_call: Using uninitialized element of array "evt_data.bd_addr" in call to function "memcmp" -False-positive: evt_data.bd_addr is set at the beginning with: STREAM_TO_BDADDR (evt_data.bd_addr, p); -*/ - btsnd_hcic_io_cap_req_neg_reply(evt_data.bd_addr, err_code); - return; - } - - evt_data.is_orig = is_orig; - - if (is_orig) - { - /* local device initiated the pairing non-bonding -> use p_cur_service */ - if (!(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && - p_dev_rec->p_cur_service && - (p_dev_rec->p_cur_service->security_flags & BTM_SEC_OUT_AUTHENTICATE)) - { - if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - /* SC only mode device requires MITM protection */ - evt_data.auth_req = BTM_AUTH_SP_YES; - } - else - { - evt_data.auth_req = (p_dev_rec->p_cur_service->security_flags & - BTM_SEC_OUT_MITM)? BTM_AUTH_SP_YES : BTM_AUTH_SP_NO; - } - } - } - - /* Notify L2CAP to increase timeout */ - l2c_pin_code_request (evt_data.bd_addr); + BTM_TRACE_EVENT("%s: State: %s", __func__, + btm_pair_state_descr(btm_cb.pairing_state)); - memcpy (btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN); + p_dev_rec = btm_find_or_alloc_dev(evt_data.bd_addr); -/* coverity[uninit_use_in_call] -Event uninit_use_in_call: Using uninitialized element of array "evt_data.bd_addr" in call to function "memcmp" -False-positive: False-positive: evt_data.bd_addr is set at the beginning with: STREAM_TO_BDADDR (evt_data.bd_addr, p); -*/ - if (!memcmp (evt_data.bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) - memcpy (p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); + BTM_TRACE_DEBUG("%s:Security mode: %d, Num Read Remote Feat pages: %d", + __func__, btm_cb.security_mode, p_dev_rec->num_read_pages); - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS); - - callback_rc = BTM_SUCCESS; - if (p_dev_rec->sm4 & BTM_SM4_UPGRADE) - { - p_dev_rec->sm4 &= ~BTM_SM4_UPGRADE; + if ((btm_cb.security_mode == BTM_SEC_MODE_SC) && + (p_dev_rec->num_read_pages == 0)) { + BTM_TRACE_EVENT("%s: Device security mode is SC only.", + "To continue need to know remote features.", __func__); - /* link key upgrade: always use SPGB_YES - assuming we want to save the link key */ - evt_data.auth_req = BTM_AUTH_SPGB_YES; - } - else if (btm_cb.api.p_sp_callback) - { - /* the callback function implementation may change the IO capability... */ - callback_rc = (*btm_cb.api.p_sp_callback) (BTM_SP_IO_REQ_EVT, (tBTM_SP_EVT_DATA *)&evt_data); + p_dev_rec->remote_features_needed = true; + return; + } + + p_dev_rec->sm4 |= BTM_SM4_TRUE; + + BTM_TRACE_EVENT("%s: State: %s Flags: 0x%04x p_cur_service: 0x%08x", + __func__, btm_pair_state_descr(btm_cb.pairing_state), + btm_cb.pairing_flags, p_dev_rec->p_cur_service); + + if (p_dev_rec->p_cur_service) { + BTM_TRACE_EVENT("%s: cur_service psm: 0x%04x, security_flags: 0x%04x", + __func__, p_dev_rec->p_cur_service->psm, + p_dev_rec->p_cur_service->security_flags); + } + + switch (btm_cb.pairing_state) { + /* initiator connecting */ + case BTM_PAIR_STATE_IDLE: + // TODO: Handle Idle pairing state + // security_required = p_dev_rec->security_required; + break; + + /* received IO capability response already->acceptor */ + case BTM_PAIR_STATE_INCOMING_SSP: + is_orig = false; + + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_PEER_STARTED_DD) { + /* acceptor in dedicated bonding */ + evt_data.auth_req = BTM_DEFAULT_DD_AUTH_REQ; + } + break; + + /* initiator, at this point it is expected to be dedicated bonding + initiated by local device */ + case BTM_PAIR_STATE_WAIT_PIN_REQ: + if (!memcmp(evt_data.bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN)) { + evt_data.auth_req = BTM_DEFAULT_DD_AUTH_REQ; + } else { + err_code = HCI_ERR_HOST_BUSY_PAIRING; + } + break; + + /* any other state is unexpected */ + default: + err_code = HCI_ERR_HOST_BUSY_PAIRING; + BTM_TRACE_ERROR("%s: Unexpected Pairing state received %d", __func__, + btm_cb.pairing_state); + break; + } + + if (btm_cb.pairing_disabled) { + /* pairing is not allowed */ + BTM_TRACE_DEBUG("%s: Pairing is not allowed -> fail pairing.", __func__); + err_code = HCI_ERR_PAIRING_NOT_ALLOWED; + } else if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + bool local_supports_sc = + controller_get_interface()->supports_secure_connections(); + /* device in Secure Connections Only mode */ + if (!(local_supports_sc) || + !(p_dev_rec->remote_supports_secure_connections)) { + BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d,", + " remote_support_for_sc 0x%02x -> fail pairing", __func__, + local_supports_sc, + p_dev_rec->remote_supports_secure_connections); + + err_code = HCI_ERR_PAIRING_NOT_ALLOWED; + } + } + + if (err_code != 0) { + /* coverity[uninit_use_in_call] + Event uninit_use_in_call: Using uninitialized element of array + "evt_data.bd_addr" in call to function "memcmp" + False-positive: evt_data.bd_addr is set at the beginning with: + STREAM_TO_BDADDR (evt_data.bd_addr, p); + */ + btsnd_hcic_io_cap_req_neg_reply(evt_data.bd_addr, err_code); + return; + } + + evt_data.is_orig = is_orig; + + if (is_orig) { + /* local device initiated the pairing non-bonding -> use p_cur_service */ + if (!(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + p_dev_rec->p_cur_service && + (p_dev_rec->p_cur_service->security_flags & BTM_SEC_OUT_AUTHENTICATE)) { + if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + /* SC only mode device requires MITM protection */ + evt_data.auth_req = BTM_AUTH_SP_YES; + } else { + evt_data.auth_req = + (p_dev_rec->p_cur_service->security_flags & BTM_SEC_OUT_MITM) + ? BTM_AUTH_SP_YES + : BTM_AUTH_SP_NO; + } } + } - if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != evt_data.oob_data)) - { - if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) - { - evt_data.auth_req = (BTM_AUTH_DD_BOND | (evt_data.auth_req & BTM_AUTH_YN_BIT)); - } - - if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - /* At this moment we know that both sides are SC capable, device in */ - /* SC only mode requires MITM for any service so let's set MITM bit */ - evt_data.auth_req |= BTM_AUTH_YN_BIT; - BTM_TRACE_DEBUG("%s: for device in \"SC only\" mode set auth_req to 0x%02x", - __func__, evt_data.auth_req); - } - - /* if the user does not indicate "reply later" by setting the oob_data to unknown */ - /* send the response right now. Save the current IO capability in the control block */ - btm_cb.devcb.loc_auth_req = evt_data.auth_req; - btm_cb.devcb.loc_io_caps = evt_data.io_cap; + /* Notify L2CAP to increase timeout */ + l2c_pin_code_request(evt_data.bd_addr); - BTM_TRACE_EVENT("%s: State: %s IO_CAP:%d oob_data:%d auth_req:%d", - __func__, btm_pair_state_descr(btm_cb.pairing_state), evt_data.io_cap, - evt_data.oob_data, evt_data.auth_req); + memcpy(btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN); - btsnd_hcic_io_cap_req_reply(evt_data.bd_addr, evt_data.io_cap, - evt_data.oob_data, evt_data.auth_req); - } + /* coverity[uninit_use_in_call] + Event uninit_use_in_call: Using uninitialized element of array + "evt_data.bd_addr" in call to function "memcmp" + False-positive: False-positive: evt_data.bd_addr is set at the beginning with: + STREAM_TO_BDADDR (evt_data.bd_addr, p); + */ + if (!memcmp(evt_data.bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) + memcpy(p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); + + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS); + + callback_rc = BTM_SUCCESS; + if (p_dev_rec->sm4 & BTM_SM4_UPGRADE) { + p_dev_rec->sm4 &= ~BTM_SM4_UPGRADE; + + /* link key upgrade: always use SPGB_YES - assuming we want to save the link + * key */ + evt_data.auth_req = BTM_AUTH_SPGB_YES; + } else if (btm_cb.api.p_sp_callback) { + /* the callback function implementation may change the IO capability... */ + callback_rc = (*btm_cb.api.p_sp_callback)(BTM_SP_IO_REQ_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); + } + + if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != evt_data.oob_data)) { + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) { + evt_data.auth_req = + (BTM_AUTH_DD_BOND | (evt_data.auth_req & BTM_AUTH_YN_BIT)); + } + + if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + /* At this moment we know that both sides are SC capable, device in */ + /* SC only mode requires MITM for any service so let's set MITM bit */ + evt_data.auth_req |= BTM_AUTH_YN_BIT; + BTM_TRACE_DEBUG( + "%s: for device in \"SC only\" mode set auth_req to 0x%02x", __func__, + evt_data.auth_req); + } + + /* if the user does not indicate "reply later" by setting the oob_data to + * unknown */ + /* send the response right now. Save the current IO capability in the + * control block */ + btm_cb.devcb.loc_auth_req = evt_data.auth_req; + btm_cb.devcb.loc_io_caps = evt_data.io_cap; + + BTM_TRACE_EVENT("%s: State: %s IO_CAP:%d oob_data:%d auth_req:%d", + __func__, btm_pair_state_descr(btm_cb.pairing_state), + evt_data.io_cap, evt_data.oob_data, evt_data.auth_req); + + btsnd_hcic_io_cap_req_reply(evt_data.bd_addr, evt_data.io_cap, + evt_data.oob_data, evt_data.auth_req); + } } /******************************************************************************* @@ -3529,58 +3456,62 @@ False-positive: False-positive: evt_data.bd_addr is set at the beginning with: * Returns void * ******************************************************************************/ -void btm_io_capabilities_rsp (uint8_t *p) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_SP_IO_RSP evt_data; +void btm_io_capabilities_rsp(uint8_t* p) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_SP_IO_RSP evt_data; - STREAM_TO_BDADDR (evt_data.bd_addr, p); - STREAM_TO_UINT8 (evt_data.io_cap, p); - STREAM_TO_UINT8 (evt_data.oob_data, p); - STREAM_TO_UINT8 (evt_data.auth_req, p); + STREAM_TO_BDADDR(evt_data.bd_addr, p); + STREAM_TO_UINT8(evt_data.io_cap, p); + STREAM_TO_UINT8(evt_data.oob_data, p); + STREAM_TO_UINT8(evt_data.auth_req, p); - /* Allocate a new device record or reuse the oldest one */ - p_dev_rec = btm_find_or_alloc_dev (evt_data.bd_addr); + /* Allocate a new device record or reuse the oldest one */ + p_dev_rec = btm_find_or_alloc_dev(evt_data.bd_addr); - /* If no security is in progress, this indicates incoming security */ - if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) - { - memcpy (btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN); - - btm_sec_change_pairing_state (BTM_PAIR_STATE_INCOMING_SSP); + /* If no security is in progress, this indicates incoming security */ + if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) { + memcpy(btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN); - /* Make sure we reset the trusted mask to help against attacks */ - BTM_SEC_CLR_TRUSTED_DEVICE(p_dev_rec->trusted_mask); + btm_sec_change_pairing_state(BTM_PAIR_STATE_INCOMING_SSP); - /* work around for FW bug */ - btm_inq_stop_on_ssp(); - } + /* Make sure we reset the trusted mask to help against attacks */ + BTM_SEC_CLR_TRUSTED_DEVICE(p_dev_rec->trusted_mask); - /* Notify L2CAP to increase timeout */ - l2c_pin_code_request (evt_data.bd_addr); - - /* We must have a device record here. - * Use the connecting device's CoD for the connection */ -/* coverity[uninit_use_in_call] -Event uninit_use_in_call: Using uninitialized element of array "evt_data.bd_addr" in call to function "memcmp" -FALSE-POSITIVE error from Coverity test-tool. evt_data.bd_addr is set at the beginning with: STREAM_TO_BDADDR (evt_data.bd_addr, p); -*/ - if (!memcmp (evt_data.bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) - memcpy (p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); - - /* peer sets dedicated bonding bit and we did not initiate dedicated bonding */ - if (btm_cb.pairing_state == BTM_PAIR_STATE_INCOMING_SSP /* peer initiated bonding */ - && (evt_data.auth_req & BTM_AUTH_DD_BOND) ) /* and dedicated bonding bit is set */ - { - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PEER_STARTED_DD; - } + /* work around for FW bug */ + btm_inq_stop_on_ssp(); + } - /* save the IO capability in the device record */ - p_dev_rec->rmt_io_caps = evt_data.io_cap; - p_dev_rec->rmt_auth_req = evt_data.auth_req; + /* Notify L2CAP to increase timeout */ + l2c_pin_code_request(evt_data.bd_addr); - if (btm_cb.api.p_sp_callback) - (*btm_cb.api.p_sp_callback) (BTM_SP_IO_RSP_EVT, (tBTM_SP_EVT_DATA *)&evt_data); + /* We must have a device record here. + * Use the connecting device's CoD for the connection */ + /* coverity[uninit_use_in_call] + Event uninit_use_in_call: Using uninitialized element of array + "evt_data.bd_addr" in call to function "memcmp" + FALSE-POSITIVE error from Coverity test-tool. evt_data.bd_addr is set at the + beginning with: STREAM_TO_BDADDR (evt_data.bd_addr, p); + */ + if (!memcmp(evt_data.bd_addr, btm_cb.connecting_bda, BD_ADDR_LEN)) + memcpy(p_dev_rec->dev_class, btm_cb.connecting_dc, DEV_CLASS_LEN); + + /* peer sets dedicated bonding bit and we did not initiate dedicated bonding + */ + if (btm_cb.pairing_state == + BTM_PAIR_STATE_INCOMING_SSP /* peer initiated bonding */ + && (evt_data.auth_req & + BTM_AUTH_DD_BOND)) /* and dedicated bonding bit is set */ + { + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PEER_STARTED_DD; + } + + /* save the IO capability in the device record */ + p_dev_rec->rmt_io_caps = evt_data.io_cap; + p_dev_rec->rmt_auth_req = evt_data.auth_req; + + if (btm_cb.api.p_sp_callback) + (*btm_cb.api.p_sp_callback)(BTM_SP_IO_RSP_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); } /******************************************************************************* @@ -3595,133 +3526,130 @@ FALSE-POSITIVE error from Coverity test-tool. evt_data.bd_addr is set at the beg * Returns void * ******************************************************************************/ -void btm_proc_sp_req_evt (tBTM_SP_EVT event, uint8_t *p) -{ - tBTM_STATUS status = BTM_ERR_PROCESSING; - tBTM_SP_EVT_DATA evt_data; - uint8_t *p_bda = evt_data.cfm_req.bd_addr; - tBTM_SEC_DEV_REC *p_dev_rec; - - /* All events start with bd_addr */ - STREAM_TO_BDADDR (p_bda, p); - - BTM_TRACE_EVENT ("btm_proc_sp_req_evt() BDA: %08x%04x event: 0x%x, State: %s", - (p_bda[0]<<24) + (p_bda[1]<<16) + (p_bda[2]<<8) + p_bda[3], (p_bda[4] << 8) + p_bda[5], - event, btm_pair_state_descr(btm_cb.pairing_state)); - - if ( ((p_dev_rec = btm_find_dev (p_bda)) != NULL) - && (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, p_bda, BD_ADDR_LEN) == 0) ) - { - memcpy (evt_data.cfm_req.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - memcpy (evt_data.cfm_req.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); +void btm_proc_sp_req_evt(tBTM_SP_EVT event, uint8_t* p) { + tBTM_STATUS status = BTM_ERR_PROCESSING; + tBTM_SP_EVT_DATA evt_data; + uint8_t* p_bda = evt_data.cfm_req.bd_addr; + tBTM_SEC_DEV_REC* p_dev_rec; + + /* All events start with bd_addr */ + STREAM_TO_BDADDR(p_bda, p); + + BTM_TRACE_EVENT( + "btm_proc_sp_req_evt() BDA: %08x%04x event: 0x%x, State: %s", + (p_bda[0] << 24) + (p_bda[1] << 16) + (p_bda[2] << 8) + p_bda[3], + (p_bda[4] << 8) + p_bda[5], event, + btm_pair_state_descr(btm_cb.pairing_state)); - strlcpy((char *)evt_data.cfm_req.bd_name, (char *)p_dev_rec->sec_bd_name, BTM_MAX_REM_BD_NAME_LEN); + if (((p_dev_rec = btm_find_dev(p_bda)) != NULL) && + (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, p_bda, BD_ADDR_LEN) == 0)) { + memcpy(evt_data.cfm_req.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + memcpy(evt_data.cfm_req.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); - switch (event) - { - case BTM_SP_CFM_REQ_EVT: - /* Numeric confirmation. Need user to conf the passkey */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM); + strlcpy((char*)evt_data.cfm_req.bd_name, (char*)p_dev_rec->sec_bd_name, + BTM_MAX_REM_BD_NAME_LEN); - /* The device record must be allocated in the "IO cap exchange" step */ - STREAM_TO_UINT32 (evt_data.cfm_req.num_val, p); + switch (event) { + case BTM_SP_CFM_REQ_EVT: + /* Numeric confirmation. Need user to conf the passkey */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM); - evt_data.cfm_req.just_works = true; + /* The device record must be allocated in the "IO cap exchange" step */ + STREAM_TO_UINT32(evt_data.cfm_req.num_val, p); - /* process user confirm req in association with the auth_req param */ + evt_data.cfm_req.just_works = true; + +/* process user confirm req in association with the auth_req param */ #if (BTM_LOCAL_IO_CAPS == BTM_IO_CAP_IO) - if ( (p_dev_rec->rmt_io_caps == BTM_IO_CAP_IO) - && (btm_cb.devcb.loc_io_caps == BTM_IO_CAP_IO) - && ((p_dev_rec->rmt_auth_req & BTM_AUTH_SP_YES) || (btm_cb.devcb.loc_auth_req & BTM_AUTH_SP_YES)) ) - { - /* Both devices are DisplayYesNo and one or both devices want to authenticate - -> use authenticated link key */ - evt_data.cfm_req.just_works = false; - } + if ((p_dev_rec->rmt_io_caps == BTM_IO_CAP_IO) && + (btm_cb.devcb.loc_io_caps == BTM_IO_CAP_IO) && + ((p_dev_rec->rmt_auth_req & BTM_AUTH_SP_YES) || + (btm_cb.devcb.loc_auth_req & BTM_AUTH_SP_YES))) { + /* Both devices are DisplayYesNo and one or both devices want to + authenticate + -> use authenticated link key */ + evt_data.cfm_req.just_works = false; + } #endif - BTM_TRACE_DEBUG ("btm_proc_sp_req_evt() just_works:%d, io loc:%d, rmt:%d, auth loc:%d, rmt:%d", - evt_data.cfm_req.just_works, btm_cb.devcb.loc_io_caps, p_dev_rec->rmt_io_caps, - btm_cb.devcb.loc_auth_req, p_dev_rec->rmt_auth_req); + BTM_TRACE_DEBUG( + "btm_proc_sp_req_evt() just_works:%d, io loc:%d, rmt:%d, auth " + "loc:%d, rmt:%d", + evt_data.cfm_req.just_works, btm_cb.devcb.loc_io_caps, + p_dev_rec->rmt_io_caps, btm_cb.devcb.loc_auth_req, + p_dev_rec->rmt_auth_req); - evt_data.cfm_req.loc_auth_req = btm_cb.devcb.loc_auth_req; - evt_data.cfm_req.rmt_auth_req = p_dev_rec->rmt_auth_req; - evt_data.cfm_req.loc_io_caps = btm_cb.devcb.loc_io_caps; - evt_data.cfm_req.rmt_io_caps = p_dev_rec->rmt_io_caps; - break; + evt_data.cfm_req.loc_auth_req = btm_cb.devcb.loc_auth_req; + evt_data.cfm_req.rmt_auth_req = p_dev_rec->rmt_auth_req; + evt_data.cfm_req.loc_io_caps = btm_cb.devcb.loc_io_caps; + evt_data.cfm_req.rmt_io_caps = p_dev_rec->rmt_io_caps; + break; - case BTM_SP_KEY_NOTIF_EVT: - /* Passkey notification (other side is a keyboard) */ - STREAM_TO_UINT32 (evt_data.key_notif.passkey, p); + case BTM_SP_KEY_NOTIF_EVT: + /* Passkey notification (other side is a keyboard) */ + STREAM_TO_UINT32(evt_data.key_notif.passkey, p); - BTM_TRACE_DEBUG ("BTM_SP_KEY_NOTIF_EVT: passkey: %u", evt_data.key_notif.passkey); + BTM_TRACE_DEBUG("BTM_SP_KEY_NOTIF_EVT: passkey: %u", + evt_data.key_notif.passkey); - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - break; + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + break; #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) - case BTM_SP_KEY_REQ_EVT: - /* HCI_USER_PASSKEY_REQUEST_EVT */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_KEY_ENTRY); - break; + case BTM_SP_KEY_REQ_EVT: + /* HCI_USER_PASSKEY_REQUEST_EVT */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_KEY_ENTRY); + break; #endif - } - - if (btm_cb.api.p_sp_callback) - { - status = (*btm_cb.api.p_sp_callback) (event, (tBTM_SP_EVT_DATA *)&evt_data); - if (status != BTM_NOT_AUTHORIZED) - { - return; - } - /* else BTM_NOT_AUTHORIZED means when the app wants to reject the req right now */ - } - else if ( (event == BTM_SP_CFM_REQ_EVT) && (evt_data.cfm_req.just_works == true) ) - { - /* automatically reply with just works if no sp_cback */ - status = BTM_SUCCESS; - } + } - if (event == BTM_SP_CFM_REQ_EVT) - { - BTM_TRACE_DEBUG ("calling BTM_ConfirmReqReply with status: %d", status); - BTM_ConfirmReqReply (status, p_bda); - } -#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) - else if (event == BTM_SP_KEY_REQ_EVT) - { - BTM_PasskeyReqReply(status, p_bda, 0); - } -#endif + if (btm_cb.api.p_sp_callback) { + status = (*btm_cb.api.p_sp_callback)(event, (tBTM_SP_EVT_DATA*)&evt_data); + if (status != BTM_NOT_AUTHORIZED) { return; + } + /* else BTM_NOT_AUTHORIZED means when the app wants to reject the req + * right now */ + } else if ((event == BTM_SP_CFM_REQ_EVT) && + (evt_data.cfm_req.just_works == true)) { + /* automatically reply with just works if no sp_cback */ + status = BTM_SUCCESS; } - /* Something bad. we can only fail this connection */ - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - - if (BTM_SP_CFM_REQ_EVT == event) - { - btsnd_hcic_user_conf_reply (p_bda, false); - } - else if (BTM_SP_KEY_NOTIF_EVT == event) - { - /* do nothing -> it very unlikely to happen. - This event is most likely to be received by a HID host when it first connects to a HID device. - Usually the Host initiated the connection in this case. - On Mobile platforms, if there's a security process happening, - the host probably can not initiate another connection. - BTW (PC) is another story. */ - if (NULL != (p_dev_rec = btm_find_dev (p_bda)) ) - { - btm_sec_disconnect (p_dev_rec->hci_handle, HCI_ERR_AUTH_FAILURE); - } + if (event == BTM_SP_CFM_REQ_EVT) { + BTM_TRACE_DEBUG("calling BTM_ConfirmReqReply with status: %d", status); + BTM_ConfirmReqReply(status, p_bda); } #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) - else - { - btsnd_hcic_user_passkey_neg_reply(p_bda); + else if (event == BTM_SP_KEY_REQ_EVT) { + BTM_PasskeyReqReply(status, p_bda, 0); } #endif + return; + } + + /* Something bad. we can only fail this connection */ + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + + if (BTM_SP_CFM_REQ_EVT == event) { + btsnd_hcic_user_conf_reply(p_bda, false); + } else if (BTM_SP_KEY_NOTIF_EVT == event) { + /* do nothing -> it very unlikely to happen. + This event is most likely to be received by a HID host when it first + connects to a HID device. + Usually the Host initiated the connection in this case. + On Mobile platforms, if there's a security process happening, + the host probably can not initiate another connection. + BTW (PC) is another story. */ + if (NULL != (p_dev_rec = btm_find_dev(p_bda))) { + btm_sec_disconnect(p_dev_rec->hci_handle, HCI_ERR_AUTH_FAILURE); + } + } +#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) + else { + btsnd_hcic_user_passkey_neg_reply(p_bda); + } +#endif } /******************************************************************************* @@ -3734,21 +3662,20 @@ void btm_proc_sp_req_evt (tBTM_SP_EVT event, uint8_t *p) * Returns void * ******************************************************************************/ -void btm_keypress_notif_evt (uint8_t *p) -{ - tBTM_SP_KEYPRESS evt_data; - uint8_t *p_bda; +void btm_keypress_notif_evt(uint8_t* p) { + tBTM_SP_KEYPRESS evt_data; + uint8_t* p_bda; - /* parse & report BTM_SP_KEYPRESS_EVT */ - if (btm_cb.api.p_sp_callback) - { - p_bda = evt_data.bd_addr; + /* parse & report BTM_SP_KEYPRESS_EVT */ + if (btm_cb.api.p_sp_callback) { + p_bda = evt_data.bd_addr; - STREAM_TO_BDADDR (p_bda, p); - evt_data.notif_type = *p; + STREAM_TO_BDADDR(p_bda, p); + evt_data.notif_type = *p; - (*btm_cb.api.p_sp_callback) (BTM_SP_KEYPRESS_EVT, (tBTM_SP_EVT_DATA *)&evt_data); - } + (*btm_cb.api.p_sp_callback)(BTM_SP_KEYPRESS_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); + } } /******************************************************************************* @@ -3761,77 +3688,72 @@ void btm_keypress_notif_evt (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_simple_pair_complete (uint8_t *p) -{ - tBTM_SP_COMPLT evt_data; - tBTM_SEC_DEV_REC *p_dev_rec; - uint8_t status; - bool disc = false; - - status = *p++; - STREAM_TO_BDADDR (evt_data.bd_addr, p); - - p_dev_rec = btm_find_dev(evt_data.bd_addr); - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR ("btm_simple_pair_complete() with unknown BDA: %08x%04x", - (evt_data.bd_addr[0]<<24) + (evt_data.bd_addr[1]<<16) + (evt_data.bd_addr[2]<<8) + evt_data.bd_addr[3], - (evt_data.bd_addr[4] << 8) + evt_data.bd_addr[5]); - return; - } - - BTM_TRACE_EVENT ("btm_simple_pair_complete() Pair State: %s Status:%d sec_state: %u", - btm_pair_state_descr(btm_cb.pairing_state), status, p_dev_rec->sec_state); - - evt_data.status = BTM_ERR_PROCESSING; - if (status == HCI_SUCCESS) - { - evt_data.status = BTM_SUCCESS; - p_dev_rec->sec_flags |= BTM_SEC_AUTHENTICATED; - } - else - { - if (status == HCI_ERR_PAIRING_NOT_ALLOWED) - { - /* The test spec wants the peer device to get this failure code. */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_DISCONNECT); - - /* Change the timer to 1 second */ - alarm_set_on_queue(btm_cb.pairing_timer, BT_1SEC_TIMEOUT_MS, - btm_sec_pairing_timeout, NULL, - btu_general_alarm_queue); - } - else if (memcmp (btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN) == 0) - { - /* stop the timer */ - alarm_cancel(btm_cb.pairing_timer); - - if (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING) - { - /* the initiating side: will receive auth complete event. disconnect ACL at that time */ - disc = true; - } - } - else - disc = true; - } - - /* Let the pairing state stay active, p_auth_complete_callback will report the failure */ - memcpy (evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - memcpy (evt_data.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); +void btm_simple_pair_complete(uint8_t* p) { + tBTM_SP_COMPLT evt_data; + tBTM_SEC_DEV_REC* p_dev_rec; + uint8_t status; + bool disc = false; + + status = *p++; + STREAM_TO_BDADDR(evt_data.bd_addr, p); + + p_dev_rec = btm_find_dev(evt_data.bd_addr); + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR("btm_simple_pair_complete() with unknown BDA: %08x%04x", + (evt_data.bd_addr[0] << 24) + (evt_data.bd_addr[1] << 16) + + (evt_data.bd_addr[2] << 8) + evt_data.bd_addr[3], + (evt_data.bd_addr[4] << 8) + evt_data.bd_addr[5]); + return; + } - if (btm_cb.api.p_sp_callback) - (*btm_cb.api.p_sp_callback) (BTM_SP_COMPLT_EVT, (tBTM_SP_EVT_DATA *)&evt_data); + BTM_TRACE_EVENT( + "btm_simple_pair_complete() Pair State: %s Status:%d sec_state: %u", + btm_pair_state_descr(btm_cb.pairing_state), status, p_dev_rec->sec_state); - if (disc) - { - /* simple pairing failed */ - /* Avoid sending disconnect on HCI_ERR_PEER_USER */ - if ((status != HCI_ERR_PEER_USER) && (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST)) - { - btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_AUTH_FAILURE, p_dev_rec->hci_handle); - } - } + evt_data.status = BTM_ERR_PROCESSING; + if (status == HCI_SUCCESS) { + evt_data.status = BTM_SUCCESS; + p_dev_rec->sec_flags |= BTM_SEC_AUTHENTICATED; + } else { + if (status == HCI_ERR_PAIRING_NOT_ALLOWED) { + /* The test spec wants the peer device to get this failure code. */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_DISCONNECT); + + /* Change the timer to 1 second */ + alarm_set_on_queue(btm_cb.pairing_timer, BT_1SEC_TIMEOUT_MS, + btm_sec_pairing_timeout, NULL, + btu_general_alarm_queue); + } else if (memcmp(btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN) == 0) { + /* stop the timer */ + alarm_cancel(btm_cb.pairing_timer); + + if (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING) { + /* the initiating side: will receive auth complete event. disconnect ACL + * at that time */ + disc = true; + } + } else + disc = true; + } + + /* Let the pairing state stay active, p_auth_complete_callback will report the + * failure */ + memcpy(evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + memcpy(evt_data.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); + + if (btm_cb.api.p_sp_callback) + (*btm_cb.api.p_sp_callback)(BTM_SP_COMPLT_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); + + if (disc) { + /* simple pairing failed */ + /* Avoid sending disconnect on HCI_ERR_PEER_USER */ + if ((status != HCI_ERR_PEER_USER) && + (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST)) { + btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_AUTH_FAILURE, + p_dev_rec->hci_handle); + } + } } /******************************************************************************* @@ -3844,39 +3766,38 @@ void btm_simple_pair_complete (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_rem_oob_req (uint8_t *p) -{ - uint8_t *p_bda; - tBTM_SP_RMT_OOB evt_data; - tBTM_SEC_DEV_REC *p_dev_rec; - BT_OCTET16 c; - BT_OCTET16 r; +void btm_rem_oob_req(uint8_t* p) { + uint8_t* p_bda; + tBTM_SP_RMT_OOB evt_data; + tBTM_SEC_DEV_REC* p_dev_rec; + BT_OCTET16 c; + BT_OCTET16 r; - p_bda = evt_data.bd_addr; + p_bda = evt_data.bd_addr; - STREAM_TO_BDADDR (p_bda, p); + STREAM_TO_BDADDR(p_bda, p); - BTM_TRACE_EVENT ("btm_rem_oob_req() BDA: %02x:%02x:%02x:%02x:%02x:%02x", - p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); + BTM_TRACE_EVENT("btm_rem_oob_req() BDA: %02x:%02x:%02x:%02x:%02x:%02x", + p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); - if ( (NULL != (p_dev_rec = btm_find_dev (p_bda))) && - btm_cb.api.p_sp_callback) - { - memcpy (evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); - memcpy (evt_data.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); - strlcpy((char *)evt_data.bd_name, (char *)p_dev_rec->sec_bd_name, BTM_MAX_REM_BD_NAME_LEN); - - btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP); - if ((*btm_cb.api.p_sp_callback) (BTM_SP_RMT_OOB_EVT, (tBTM_SP_EVT_DATA *)&evt_data) == BTM_NOT_AUTHORIZED) - { - BTM_RemoteOobDataReply(true, p_bda, c, r); - } - return; + if ((NULL != (p_dev_rec = btm_find_dev(p_bda))) && btm_cb.api.p_sp_callback) { + memcpy(evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); + memcpy(evt_data.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN); + strlcpy((char*)evt_data.bd_name, (char*)p_dev_rec->sec_bd_name, + BTM_MAX_REM_BD_NAME_LEN); + + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP); + if ((*btm_cb.api.p_sp_callback)(BTM_SP_RMT_OOB_EVT, + (tBTM_SP_EVT_DATA*)&evt_data) == + BTM_NOT_AUTHORIZED) { + BTM_RemoteOobDataReply(true, p_bda, c, r); } + return; + } - /* something bad. we can only fail this connection */ - btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; - btsnd_hcic_rem_oob_neg_reply (p_bda); + /* something bad. we can only fail this connection */ + btm_cb.acl_disc_reason = HCI_ERR_HOST_REJECT_SECURITY; + btsnd_hcic_rem_oob_neg_reply(p_bda); } /******************************************************************************* @@ -3889,23 +3810,21 @@ void btm_rem_oob_req (uint8_t *p) * Returns void * ******************************************************************************/ -void btm_read_local_oob_complete (uint8_t *p) -{ - tBTM_SP_LOC_OOB evt_data; - uint8_t status = *p++; - - BTM_TRACE_EVENT ("btm_read_local_oob_complete:%d", status); - if (status == HCI_SUCCESS) - { - evt_data.status = BTM_SUCCESS; - STREAM_TO_ARRAY16(evt_data.c, p); - STREAM_TO_ARRAY16(evt_data.r, p); - } - else - evt_data.status = BTM_ERR_PROCESSING; +void btm_read_local_oob_complete(uint8_t* p) { + tBTM_SP_LOC_OOB evt_data; + uint8_t status = *p++; + + BTM_TRACE_EVENT("btm_read_local_oob_complete:%d", status); + if (status == HCI_SUCCESS) { + evt_data.status = BTM_SUCCESS; + STREAM_TO_ARRAY16(evt_data.c, p); + STREAM_TO_ARRAY16(evt_data.r, p); + } else + evt_data.status = BTM_ERR_PROCESSING; - if (btm_cb.api.p_sp_callback) - (*btm_cb.api.p_sp_callback) (BTM_SP_LOC_OOB_EVT, (tBTM_SP_EVT_DATA *)&evt_data); + if (btm_cb.api.p_sp_callback) + (*btm_cb.api.p_sp_callback)(BTM_SP_LOC_OOB_EVT, + (tBTM_SP_EVT_DATA*)&evt_data); } /******************************************************************************* @@ -3918,37 +3837,36 @@ void btm_read_local_oob_complete (uint8_t *p) * Returns void * ******************************************************************************/ -static void btm_sec_auth_collision (uint16_t handle) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - - if (!btm_cb.collision_start_time) - btm_cb.collision_start_time = time_get_os_boottime_ms(); - - if ((time_get_os_boottime_ms() - btm_cb.collision_start_time) < btm_cb.max_collision_delay) - { - if (handle == BTM_SEC_INVALID_HANDLE) - { - p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING); - if (p_dev_rec == NULL) - p_dev_rec = btm_sec_find_dev_by_sec_state (BTM_SEC_STATE_ENCRYPTING); - } - else - p_dev_rec = btm_find_dev_by_handle (handle); - - if (p_dev_rec != NULL) - { - BTM_TRACE_DEBUG ("btm_sec_auth_collision: state %d (retrying in a moment...)", p_dev_rec->sec_state); - /* We will restart authentication after timeout */ - if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) - p_dev_rec->sec_state = 0; - - btm_cb.p_collided_dev_rec = p_dev_rec; - alarm_set_on_queue(btm_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, - btm_sec_collision_timeout, NULL, - btu_general_alarm_queue); - } - } +static void btm_sec_auth_collision(uint16_t handle) { + tBTM_SEC_DEV_REC* p_dev_rec; + + if (!btm_cb.collision_start_time) + btm_cb.collision_start_time = time_get_os_boottime_ms(); + + if ((time_get_os_boottime_ms() - btm_cb.collision_start_time) < + btm_cb.max_collision_delay) { + if (handle == BTM_SEC_INVALID_HANDLE) { + p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING); + if (p_dev_rec == NULL) + p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_ENCRYPTING); + } else + p_dev_rec = btm_find_dev_by_handle(handle); + + if (p_dev_rec != NULL) { + BTM_TRACE_DEBUG( + "btm_sec_auth_collision: state %d (retrying in a moment...)", + p_dev_rec->sec_state); + /* We will restart authentication after timeout */ + if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING || + p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) + p_dev_rec->sec_state = 0; + + btm_cb.p_collided_dev_rec = p_dev_rec; + alarm_set_on_queue(btm_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, + btm_sec_collision_timeout, NULL, + btu_general_alarm_queue); + } + } } /******************************************************************************* @@ -3961,198 +3879,189 @@ static void btm_sec_auth_collision (uint16_t handle) * Returns void * ******************************************************************************/ -void btm_sec_auth_complete (uint16_t handle, uint8_t status) -{ - uint8_t old_sm4; - tBTM_PAIRING_STATE old_state = btm_cb.pairing_state; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - bool are_bonding = false; - - if (p_dev_rec) - { - BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d dev->sec_state: %u Bda:%08x, RName:%s", - btm_pair_state_descr (btm_cb.pairing_state), - handle, status, - p_dev_rec->sec_state, - (p_dev_rec->bd_addr[2]<<24)+(p_dev_rec->bd_addr[3]<<16)+(p_dev_rec->bd_addr[4]<<8)+p_dev_rec->bd_addr[5], - p_dev_rec->sec_bd_name); - } - else - { - BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d", - btm_pair_state_descr (btm_cb.pairing_state), - handle, status); - } - - /* For transaction collision we need to wait and repeat. There is no need */ - /* for random timeout because only slave should receive the result */ - if ((status == HCI_ERR_LMP_ERR_TRANS_COLLISION) || (status == HCI_ERR_DIFF_TRANSACTION_COLLISION)) - { - btm_sec_auth_collision(handle); - return; - } - btm_cb.collision_start_time = 0; +void btm_sec_auth_complete(uint16_t handle, uint8_t status) { + uint8_t old_sm4; + tBTM_PAIRING_STATE old_state = btm_cb.pairing_state; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + bool are_bonding = false; + + if (p_dev_rec) { + BTM_TRACE_EVENT( + "Security Manager: auth_complete PairState: %s handle:%u status:%d " + "dev->sec_state: %u Bda:%08x, RName:%s", + btm_pair_state_descr(btm_cb.pairing_state), handle, status, + p_dev_rec->sec_state, + (p_dev_rec->bd_addr[2] << 24) + (p_dev_rec->bd_addr[3] << 16) + + (p_dev_rec->bd_addr[4] << 8) + p_dev_rec->bd_addr[5], + p_dev_rec->sec_bd_name); + } else { + BTM_TRACE_EVENT( + "Security Manager: auth_complete PairState: %s handle:%u status:%d", + btm_pair_state_descr(btm_cb.pairing_state), handle, status); + } + + /* For transaction collision we need to wait and repeat. There is no need */ + /* for random timeout because only slave should receive the result */ + if ((status == HCI_ERR_LMP_ERR_TRANS_COLLISION) || + (status == HCI_ERR_DIFF_TRANSACTION_COLLISION)) { + btm_sec_auth_collision(handle); + return; + } + btm_cb.collision_start_time = 0; - btm_restore_mode(); + btm_restore_mode(); - /* Check if connection was made just to do bonding. If we authenticate - the connection that is up, this is the last event received. - */ - if (p_dev_rec - && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - && !(btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE)) - { - p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + /* Check if connection was made just to do bonding. If we authenticate + the connection that is up, this is the last event received. + */ + if (p_dev_rec && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + !(btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE)) { + p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; - l2cu_start_post_bond_timer (p_dev_rec->hci_handle); - } + l2cu_start_post_bond_timer(p_dev_rec->hci_handle); + } - if (!p_dev_rec) - return; + if (!p_dev_rec) return; - /* keep the old sm4 flag and clear the retry bit in control block */ - old_sm4 = p_dev_rec->sm4; - p_dev_rec->sm4 &= ~BTM_SM4_RETRY; + /* keep the old sm4 flag and clear the retry bit in control block */ + old_sm4 = p_dev_rec->sm4; + p_dev_rec->sm4 &= ~BTM_SM4_RETRY; - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - && (memcmp (p_dev_rec->bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) ) - are_bonding = true; + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && + (memcmp(p_dev_rec->bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0)) + are_bonding = true; - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (p_dev_rec->bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) ) - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(p_dev_rec->bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) == 0)) + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - if (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING) - { - if ( (btm_cb.api.p_auth_complete_callback && status != HCI_SUCCESS) - && (old_state != BTM_PAIR_STATE_IDLE) ) - { - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, status); - } - return; + if (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING) { + if ((btm_cb.api.p_auth_complete_callback && status != HCI_SUCCESS) && + (old_state != BTM_PAIR_STATE_IDLE)) { + (*btm_cb.api.p_auth_complete_callback)(p_dev_rec->bd_addr, + p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, status); } + return; + } - /* There can be a race condition, when we are starting authentication and - ** the peer device is doing encryption. - ** If first we receive encryption change up, then initiated authentication - ** can not be performed. According to the spec we can not do authentication - ** on the encrypted link, so device is correct. - */ - if ((status == HCI_ERR_COMMAND_DISALLOWED) - && ((p_dev_rec->sec_flags & (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED)) == - (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED))) - { - status = HCI_SUCCESS; - } - /* Currently we do not notify user if it is a keyboard which connects */ - /* User probably Disabled the keyboard while it was asleap. Let her try */ - if (btm_cb.api.p_auth_complete_callback) - { - /* report the suthentication status */ - if ((old_state != BTM_PAIR_STATE_IDLE) || (status != HCI_SUCCESS)) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, status); + /* There can be a race condition, when we are starting authentication and + ** the peer device is doing encryption. + ** If first we receive encryption change up, then initiated authentication + ** can not be performed. According to the spec we can not do authentication + ** on the encrypted link, so device is correct. + */ + if ((status == HCI_ERR_COMMAND_DISALLOWED) && + ((p_dev_rec->sec_flags & (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED)) == + (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED))) { + status = HCI_SUCCESS; + } + /* Currently we do not notify user if it is a keyboard which connects */ + /* User probably Disabled the keyboard while it was asleap. Let her try */ + if (btm_cb.api.p_auth_complete_callback) { + /* report the suthentication status */ + if ((old_state != BTM_PAIR_STATE_IDLE) || (status != HCI_SUCCESS)) + (*btm_cb.api.p_auth_complete_callback)(p_dev_rec->bd_addr, + p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, status); + } + + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + + /* If this is a bonding procedure can disconnect the link now */ + if (are_bonding) { + p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + + if (status != HCI_SUCCESS) { + if (((status != HCI_ERR_PEER_USER) && + (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST))) + btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_PEER_USER, + p_dev_rec->hci_handle); + } else { + BTM_TRACE_DEBUG("TRYING TO DECIDE IF CAN USE SMP_BR_CHNL"); + if (p_dev_rec->new_encryption_key_is_p256 && + (btm_sec_use_smp_br_chnl(p_dev_rec)) + /* no LE keys are available, do deriving */ + && (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) || + /* or BR key is higher security than existing LE keys */ + (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) && + (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)))) { + BTM_TRACE_DEBUG( + "link encrypted afer dedic bonding can use SMP_BR_CHNL"); + + if (btm_sec_is_master(p_dev_rec)) { + // Encryption is required to start SM over BR/EDR + // indicate that this is encryption after authentication + BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL, + 0); + } + } + l2cu_start_post_bond_timer(p_dev_rec->hci_handle); } - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - - /* If this is a bonding procedure can disconnect the link now */ - if (are_bonding) - { - p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + return; + } + + /* If authentication failed, notify the waiting layer */ + if (status != HCI_SUCCESS) { + if ((old_sm4 & BTM_SM4_RETRY) == 0) { + /* allow retry only once */ + if (status == HCI_ERR_LMP_ERR_TRANS_COLLISION) { + /* not retried yet. set the retry bit */ + p_dev_rec->sm4 |= BTM_SM4_RETRY; + BTM_TRACE_DEBUG("Collision retry sm4:x%x sec_flags:0x%x", + p_dev_rec->sm4, p_dev_rec->sec_flags); + } + /* this retry for missing key is for Lisbon or later only. + * Legacy device do not need this. the controller will drive the retry + * automatically */ + else if (HCI_ERR_KEY_MISSING == status && + BTM_SEC_IS_SM4(p_dev_rec->sm4)) { + /* not retried yet. set the retry bit */ + p_dev_rec->sm4 |= BTM_SM4_RETRY; + p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; + BTM_TRACE_DEBUG("Retry for missing key sm4:x%x sec_flags:0x%x", + p_dev_rec->sm4, p_dev_rec->sec_flags); - if (status != HCI_SUCCESS) - { - if(((status != HCI_ERR_PEER_USER) && (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST))) - btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_PEER_USER, p_dev_rec->hci_handle); - } - else - { - BTM_TRACE_DEBUG ("TRYING TO DECIDE IF CAN USE SMP_BR_CHNL"); - if (p_dev_rec->new_encryption_key_is_p256 && (btm_sec_use_smp_br_chnl(p_dev_rec)) - /* no LE keys are available, do deriving */ - && (!(p_dev_rec->sec_flags &BTM_SEC_LE_LINK_KEY_KNOWN) || - /* or BR key is higher security than existing LE keys */ - (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) && - (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)))) - { - BTM_TRACE_DEBUG ("link encrypted afer dedic bonding can use SMP_BR_CHNL"); - - if (btm_sec_is_master(p_dev_rec)) - { - // Encryption is required to start SM over BR/EDR - // indicate that this is encryption after authentication - BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL, 0); - } - } - l2cu_start_post_bond_timer (p_dev_rec->hci_handle); - } + /* With BRCM controller, we do not need to delete the stored link key in + controller. + If the stack may sit on top of other controller, we may need this + BTM_DeleteStoredLinkKey (bd_addr, NULL); */ + } + if (p_dev_rec->sm4 & BTM_SM4_RETRY) { + btm_sec_execute_procedure(p_dev_rec); return; + } } - /* If authentication failed, notify the waiting layer */ - if (status != HCI_SUCCESS) - { - if ((old_sm4 & BTM_SM4_RETRY) == 0) - { - /* allow retry only once */ - if (status == HCI_ERR_LMP_ERR_TRANS_COLLISION) - { - /* not retried yet. set the retry bit */ - p_dev_rec->sm4 |= BTM_SM4_RETRY; - BTM_TRACE_DEBUG ("Collision retry sm4:x%x sec_flags:0x%x", p_dev_rec->sm4, p_dev_rec->sec_flags); - } - /* this retry for missing key is for Lisbon or later only. - * Legacy device do not need this. the controller will drive the retry automatically */ - else if (HCI_ERR_KEY_MISSING == status && BTM_SEC_IS_SM4(p_dev_rec->sm4)) - { - /* not retried yet. set the retry bit */ - p_dev_rec->sm4 |= BTM_SM4_RETRY; - p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; - BTM_TRACE_DEBUG ("Retry for missing key sm4:x%x sec_flags:0x%x", p_dev_rec->sm4, p_dev_rec->sec_flags); - - /* With BRCM controller, we do not need to delete the stored link key in controller. - If the stack may sit on top of other controller, we may need this - BTM_DeleteStoredLinkKey (bd_addr, NULL); */ - } - - if (p_dev_rec->sm4 & BTM_SM4_RETRY) - { - btm_sec_execute_procedure (p_dev_rec); - return; - } - } + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); - btm_sec_dev_rec_cback_event (p_dev_rec, BTM_ERR_PROCESSING, false); - - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) - { - btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_AUTH_FAILURE, p_dev_rec->hci_handle); - } - return; + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) { + btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_AUTH_FAILURE, + p_dev_rec->hci_handle); } + return; + } - p_dev_rec->sec_flags |= BTM_SEC_AUTHENTICATED; + p_dev_rec->sec_flags |= BTM_SEC_AUTHENTICATED; - if (p_dev_rec->pin_code_length >= 16 || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { - // If we have MITM protection we have a higher level of security than - // provided by 16 digits PIN - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; - } + if (p_dev_rec->pin_code_length >= 16 || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { + // If we have MITM protection we have a higher level of security than + // provided by 16 digits PIN + p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + } - /* Authentication succeeded, execute the next security procedure, if any */ - status = btm_sec_execute_procedure (p_dev_rec); + /* Authentication succeeded, execute the next security procedure, if any */ + status = btm_sec_execute_procedure(p_dev_rec); - /* If there is no next procedure, or procedure failed to start, notify the caller */ - if (status != BTM_CMD_STARTED) - btm_sec_dev_rec_cback_event (p_dev_rec, status, false); + /* If there is no next procedure, or procedure failed to start, notify the + * caller */ + if (status != BTM_CMD_STARTED) + btm_sec_dev_rec_cback_event(p_dev_rec, status, false); } /******************************************************************************* @@ -4165,160 +4074,145 @@ void btm_sec_auth_complete (uint16_t handle, uint8_t status) * Returns void * ******************************************************************************/ -void btm_sec_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enable) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - tACL_CONN *p_acl = NULL; - uint8_t acl_idx = btm_handle_to_acl_index(handle); - BTM_TRACE_EVENT ("Security Manager: encrypt_change status:%d State:%d, encr_enable = %d", - status, (p_dev_rec) ? p_dev_rec->sec_state : 0, encr_enable); - BTM_TRACE_DEBUG ("before update p_dev_rec->sec_flags=0x%x", (p_dev_rec) ? p_dev_rec->sec_flags : 0 ); - - /* For transaction collision we need to wait and repeat. There is no need */ - /* for random timeout because only slave should receive the result */ - if ((status == HCI_ERR_LMP_ERR_TRANS_COLLISION) || - (status == HCI_ERR_DIFF_TRANSACTION_COLLISION)) - { - btm_sec_auth_collision(handle); - return; - } - btm_cb.collision_start_time = 0; +void btm_sec_encrypt_change(uint16_t handle, uint8_t status, + uint8_t encr_enable) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + tACL_CONN* p_acl = NULL; + uint8_t acl_idx = btm_handle_to_acl_index(handle); + BTM_TRACE_EVENT( + "Security Manager: encrypt_change status:%d State:%d, encr_enable = %d", + status, (p_dev_rec) ? p_dev_rec->sec_state : 0, encr_enable); + BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", + (p_dev_rec) ? p_dev_rec->sec_flags : 0); + + /* For transaction collision we need to wait and repeat. There is no need */ + /* for random timeout because only slave should receive the result */ + if ((status == HCI_ERR_LMP_ERR_TRANS_COLLISION) || + (status == HCI_ERR_DIFF_TRANSACTION_COLLISION)) { + btm_sec_auth_collision(handle); + return; + } + btm_cb.collision_start_time = 0; - if (!p_dev_rec) - return; + if (!p_dev_rec) return; - if ((status == HCI_SUCCESS) && encr_enable) - { - if (p_dev_rec->hci_handle == handle) { - p_dev_rec->sec_flags |= (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED); - if (p_dev_rec->pin_code_length >= 16 || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; - } - } - else - { - p_dev_rec->sec_flags |= (BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED); - } - } - - /* It is possible that we decrypted the link to perform role switch */ - /* mark link not to be encrypted, so that when we execute security next time it will kick in again */ - if ((status == HCI_SUCCESS) && !encr_enable) - { - if (p_dev_rec->hci_handle == handle) - p_dev_rec->sec_flags &= ~BTM_SEC_ENCRYPTED; - else - p_dev_rec->sec_flags &= ~BTM_SEC_LE_ENCRYPTED; + if ((status == HCI_SUCCESS) && encr_enable) { + if (p_dev_rec->hci_handle == handle) { + p_dev_rec->sec_flags |= (BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED); + if (p_dev_rec->pin_code_length >= 16 || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { + p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + } + } else { + p_dev_rec->sec_flags |= (BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED); } + } - BTM_TRACE_DEBUG ("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags ); - - if (acl_idx != MAX_L2CAP_LINKS) - p_acl = &btm_cb.acl_db[acl_idx]; + /* It is possible that we decrypted the link to perform role switch */ + /* mark link not to be encrypted, so that when we execute security next time + * it will kick in again */ + if ((status == HCI_SUCCESS) && !encr_enable) { + if (p_dev_rec->hci_handle == handle) + p_dev_rec->sec_flags &= ~BTM_SEC_ENCRYPTED; + else + p_dev_rec->sec_flags &= ~BTM_SEC_LE_ENCRYPTED; + } - if (p_acl != NULL) - btm_sec_check_pending_enc_req(p_dev_rec, p_acl->transport, encr_enable); + BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", + p_dev_rec->sec_flags); - if (p_acl && p_acl->transport == BT_TRANSPORT_LE) - { - if (status == HCI_ERR_KEY_MISSING || status == HCI_ERR_AUTH_FAILURE || - status == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) - { - p_dev_rec->sec_flags &= ~ (BTM_SEC_LE_LINK_KEY_KNOWN); - p_dev_rec->ble.key_type = BTM_LE_KEY_NONE; - } - btm_ble_link_encrypted(p_dev_rec->ble.pseudo_addr, encr_enable); - return; - } - else - { - /* BR/EDR connection, update the encryption key size to be 16 as always */ - p_dev_rec->enc_key_size = 16; - } + if (acl_idx != MAX_L2CAP_LINKS) p_acl = &btm_cb.acl_db[acl_idx]; - BTM_TRACE_DEBUG ("in %s new_encr_key_256 is %d", - __func__, p_dev_rec->new_encryption_key_is_p256); + if (p_acl != NULL) + btm_sec_check_pending_enc_req(p_dev_rec, p_acl->transport, encr_enable); - if ((status == HCI_SUCCESS) && encr_enable && (p_dev_rec->hci_handle == handle)) - { - /* if BR key is temporary no need for LE LTK derivation */ - bool derive_ltk = true; - if(p_dev_rec->rmt_auth_req == BTM_AUTH_SP_NO && btm_cb.devcb.loc_auth_req == BTM_AUTH_SP_NO) - { - derive_ltk = false; - BTM_TRACE_DEBUG("%s: BR key is temporary, skip derivation of LE LTK", __func__); - } - if (p_dev_rec->new_encryption_key_is_p256) - { - if (btm_sec_use_smp_br_chnl(p_dev_rec) && - btm_sec_is_master(p_dev_rec) && - /* if LE key is not known, do deriving */ - (!(p_dev_rec->sec_flags &BTM_SEC_LE_LINK_KEY_KNOWN) || - /* or BR key is higher security than existing LE keys */ - (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) - && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED))) && derive_ltk) - { - /* BR/EDR is encrypted with LK that can be used to derive LE LTK */ - p_dev_rec->new_encryption_key_is_p256 = false; - - if (p_dev_rec->no_smp_on_br) - { - BTM_TRACE_DEBUG ("%s NO SM over BR/EDR", __func__); - } - else - { - BTM_TRACE_DEBUG ("%s start SM over BR/EDR", __func__); - SMP_BR_PairWith(p_dev_rec->bd_addr); - } - } - } - else - { - // BR/EDR is successfully encrypted. Correct LK type if needed - // (BR/EDR LK derived from LE LTK was used for encryption) - if ((encr_enable == 1) && /* encryption is ON for SSP */ - /* LK type is for BR/EDR SC */ - (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256 || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - if (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256) - p_dev_rec->link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB; - else /* BTM_LKEY_TYPE_AUTH_COMB_P_256 */ - p_dev_rec->link_key_type = BTM_LKEY_TYPE_AUTH_COMB; - - BTM_TRACE_DEBUG("updated link key type to %d", p_dev_rec->link_key_type); - btm_send_link_key_notif(p_dev_rec); - } - } + if (p_acl && p_acl->transport == BT_TRANSPORT_LE) { + if (status == HCI_ERR_KEY_MISSING || status == HCI_ERR_AUTH_FAILURE || + status == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) { + p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_KNOWN); + p_dev_rec->ble.key_type = BTM_LE_KEY_NONE; } - - /* If this encryption was started by peer do not need to do anything */ - if (p_dev_rec->sec_state != BTM_SEC_STATE_ENCRYPTING) - { - if (BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_state) - { - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - p_dev_rec->p_callback = NULL; - l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); + btm_ble_link_encrypted(p_dev_rec->ble.pseudo_addr, encr_enable); + return; + } else { + /* BR/EDR connection, update the encryption key size to be 16 as always */ + p_dev_rec->enc_key_size = 16; + } + + BTM_TRACE_DEBUG("in %s new_encr_key_256 is %d", __func__, + p_dev_rec->new_encryption_key_is_p256); + + if ((status == HCI_SUCCESS) && encr_enable && + (p_dev_rec->hci_handle == handle)) { + /* if BR key is temporary no need for LE LTK derivation */ + bool derive_ltk = true; + if (p_dev_rec->rmt_auth_req == BTM_AUTH_SP_NO && + btm_cb.devcb.loc_auth_req == BTM_AUTH_SP_NO) { + derive_ltk = false; + BTM_TRACE_DEBUG("%s: BR key is temporary, skip derivation of LE LTK", + __func__); + } + if (p_dev_rec->new_encryption_key_is_p256) { + if (btm_sec_use_smp_br_chnl(p_dev_rec) && btm_sec_is_master(p_dev_rec) && + /* if LE key is not known, do deriving */ + (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) || + /* or BR key is higher security than existing LE keys */ + (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) && + (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED))) && + derive_ltk) { + /* BR/EDR is encrypted with LK that can be used to derive LE LTK */ + p_dev_rec->new_encryption_key_is_p256 = false; + + if (p_dev_rec->no_smp_on_br) { + BTM_TRACE_DEBUG("%s NO SM over BR/EDR", __func__); + } else { + BTM_TRACE_DEBUG("%s start SM over BR/EDR", __func__); + SMP_BR_PairWith(p_dev_rec->bd_addr); } - return; + } + } else { + // BR/EDR is successfully encrypted. Correct LK type if needed + // (BR/EDR LK derived from LE LTK was used for encryption) + if ((encr_enable == 1) && /* encryption is ON for SSP */ + /* LK type is for BR/EDR SC */ + (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256 || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + if (p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256) + p_dev_rec->link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB; + else /* BTM_LKEY_TYPE_AUTH_COMB_P_256 */ + p_dev_rec->link_key_type = BTM_LKEY_TYPE_AUTH_COMB; + + BTM_TRACE_DEBUG("updated link key type to %d", + p_dev_rec->link_key_type); + btm_send_link_key_notif(p_dev_rec); + } } + } - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - /* If encryption setup failed, notify the waiting layer */ - if (status != HCI_SUCCESS) - { - btm_sec_dev_rec_cback_event (p_dev_rec, BTM_ERR_PROCESSING, false); - return; + /* If this encryption was started by peer do not need to do anything */ + if (p_dev_rec->sec_state != BTM_SEC_STATE_ENCRYPTING) { + if (BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_state) { + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + p_dev_rec->p_callback = NULL; + l2cu_resubmit_pending_sec_req(p_dev_rec->bd_addr); } + return; + } - /* Encryption setup succeeded, execute the next security procedure, if any */ - status = (uint8_t)btm_sec_execute_procedure (p_dev_rec); - /* If there is no next procedure, or procedure failed to start, notify the caller */ - if (status != BTM_CMD_STARTED) - btm_sec_dev_rec_cback_event (p_dev_rec, status, false); + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + /* If encryption setup failed, notify the waiting layer */ + if (status != HCI_SUCCESS) { + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); + return; + } + + /* Encryption setup succeeded, execute the next security procedure, if any */ + status = (uint8_t)btm_sec_execute_procedure(p_dev_rec); + /* If there is no next procedure, or procedure failed to start, notify the + * caller */ + if (status != BTM_CMD_STARTED) + btm_sec_dev_rec_cback_event(p_dev_rec, status, false); } /******************************************************************************* @@ -4331,24 +4225,23 @@ void btm_sec_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enabl * Returns Pointer to the TLE struct * ******************************************************************************/ -static void btm_sec_connect_after_reject_timeout(UNUSED_ATTR void *data) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_cb.p_collided_dev_rec; +static void btm_sec_connect_after_reject_timeout(UNUSED_ATTR void* data) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_cb.p_collided_dev_rec; - BTM_TRACE_EVENT("%s", __func__); - btm_cb.p_collided_dev_rec = 0; + BTM_TRACE_EVENT("%s", __func__); + btm_cb.p_collided_dev_rec = 0; - if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) - { - BTM_TRACE_WARNING("Security Manager: %s: failed to start connection", - __func__); + if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) { + BTM_TRACE_WARNING("Security Manager: %s: failed to start connection", + __func__); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_ERR_MEMORY_FULL); - } + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_ERR_MEMORY_FULL); + } } /******************************************************************************* @@ -4361,304 +4254,291 @@ static void btm_sec_connect_after_reject_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void btm_sec_connected (uint8_t *bda, uint16_t handle, uint8_t status, uint8_t enc_mode) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); - uint8_t res; - bool is_pairing_device = false; - tACL_CONN *p_acl_cb; - uint8_t bit_shift = 0; - - btm_acl_resubmit_page(); - - if (p_dev_rec) - { - BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x RName:%s", - btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, - (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5], - p_dev_rec->sec_bd_name); - } - else - { - BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x ", - btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, - (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5]); - } +void btm_sec_connected(uint8_t* bda, uint16_t handle, uint8_t status, + uint8_t enc_mode) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + uint8_t res; + bool is_pairing_device = false; + tACL_CONN* p_acl_cb; + uint8_t bit_shift = 0; + + btm_acl_resubmit_page(); + + if (p_dev_rec) { + BTM_TRACE_EVENT( + "Security Manager: btm_sec_connected in state: %s handle:%d status:%d " + "enc_mode:%d bda:%x RName:%s", + btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, + (bda[2] << 24) + (bda[3] << 16) + (bda[4] << 8) + bda[5], + p_dev_rec->sec_bd_name); + } else { + BTM_TRACE_EVENT( + "Security Manager: btm_sec_connected in state: %s handle:%d status:%d " + "enc_mode:%d bda:%x ", + btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, + (bda[2] << 24) + (bda[3] << 16) + (bda[4] << 8) + bda[5]); + } + + if (!p_dev_rec) { + /* There is no device record for new connection. Allocate one */ + if (status == HCI_SUCCESS) { + p_dev_rec = btm_sec_alloc_dev(bda); + } else { + /* If the device matches with stored paring address + * reset the paring state to idle */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, bda, BD_ADDR_LEN) == 0)) { + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + } - if (!p_dev_rec) - { - /* There is no device record for new connection. Allocate one */ - if (status == HCI_SUCCESS) - { - p_dev_rec = btm_sec_alloc_dev (bda); - } - else - { - /* If the device matches with stored paring address - * reset the paring state to idle */ - if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && - (memcmp (btm_cb.pairing_bda, bda, BD_ADDR_LEN) == 0)) - { - btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - } - - /* can not find the device record and the status is error, - * just ignore it */ - return; - } - } - else /* Update the timestamp for this device */ - { - bit_shift = (handle == p_dev_rec->ble_hci_handle) ? 8 :0; - p_dev_rec->timestamp = btm_cb.dev_rec_count++; - if (p_dev_rec->sm4 & BTM_SM4_CONN_PEND) - { - /* tell L2CAP it's a bonding connection. */ - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0) - && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) ) - { - /* if incoming connection failed while pairing, then try to connect and continue */ - /* Motorola S9 disconnects without asking pin code */ - if ((status != HCI_SUCCESS)&&(btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ)) - { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: incoming connection failed without asking PIN"); - - p_dev_rec->sm4 &= ~BTM_SM4_CONN_PEND; - if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) - { - /* Start timer with 0 to initiate connection with new LCB */ - /* because L2CAP will delete current LCB with this event */ - btm_cb.p_collided_dev_rec = p_dev_rec; - alarm_set_on_queue(btm_cb.sec_collision_timer, 0, - btm_sec_connect_after_reject_timeout, - NULL, btu_general_alarm_queue); - } - else - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_GET_REM_NAME); - BTM_ReadRemoteDeviceName(p_dev_rec->bd_addr, NULL, BT_TRANSPORT_BR_EDR); - } + /* can not find the device record and the status is error, + * just ignore it */ + return; + } + } else /* Update the timestamp for this device */ + { + bit_shift = (handle == p_dev_rec->ble_hci_handle) ? 8 : 0; + p_dev_rec->timestamp = btm_cb.dev_rec_count++; + if (p_dev_rec->sm4 & BTM_SM4_CONN_PEND) { + /* tell L2CAP it's a bonding connection. */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) { + /* if incoming connection failed while pairing, then try to connect and + * continue */ + /* Motorola S9 disconnects without asking pin code */ + if ((status != HCI_SUCCESS) && + (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ)) { + BTM_TRACE_WARNING( + "Security Manager: btm_sec_connected: incoming connection failed " + "without asking PIN"); + + p_dev_rec->sm4 &= ~BTM_SM4_CONN_PEND; + if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) { + /* Start timer with 0 to initiate connection with new LCB */ + /* because L2CAP will delete current LCB with this event */ + btm_cb.p_collided_dev_rec = p_dev_rec; + alarm_set_on_queue(btm_cb.sec_collision_timer, 0, + btm_sec_connect_after_reject_timeout, NULL, + btu_general_alarm_queue); + } else { + btm_sec_change_pairing_state(BTM_PAIR_STATE_GET_REM_NAME); + BTM_ReadRemoteDeviceName(p_dev_rec->bd_addr, NULL, + BT_TRANSPORT_BR_EDR); + } #if (BTM_DISC_DURING_RS == TRUE) - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ #endif - return; - } - else - { - l2cu_update_lcb_4_bonding(p_dev_rec->bd_addr, true); - } - } - /* always clear the pending flag */ - p_dev_rec->sm4 &= ~BTM_SM4_CONN_PEND; + return; + } else { + l2cu_update_lcb_4_bonding(p_dev_rec->bd_addr, true); } + } + /* always clear the pending flag */ + p_dev_rec->sm4 &= ~BTM_SM4_CONN_PEND; } + } - p_dev_rec->device_type |= BT_DEVICE_TYPE_BREDR; + p_dev_rec->device_type |= BT_DEVICE_TYPE_BREDR; #if (BTM_DISC_DURING_RS == TRUE) - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ #endif - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ + + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, bda, BD_ADDR_LEN) == 0)) { + /* if we rejected incoming connection from bonding device */ + if ((status == HCI_ERR_HOST_REJECT_DEVICE) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT)) { + BTM_TRACE_WARNING( + "Security Manager: btm_sec_connected: HCI_Conn_Comp Flags:0x%04x, " + "sm4: 0x%x", + btm_cb.pairing_flags, p_dev_rec->sm4); + + btm_cb.pairing_flags &= ~BTM_PAIR_FLAGS_REJECTED_CONNECT; + if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) { + /* Try again: RNR when no ACL causes HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_GET_REM_NAME); + BTM_ReadRemoteDeviceName(bda, NULL, BT_TRANSPORT_BR_EDR); + return; + } - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, bda, BD_ADDR_LEN) == 0) ) - { - /* if we rejected incoming connection from bonding device */ - if ((status == HCI_ERR_HOST_REJECT_DEVICE) - &&(btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT)) - { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: HCI_Conn_Comp Flags:0x%04x, sm4: 0x%x", - btm_cb.pairing_flags, p_dev_rec->sm4); - - btm_cb.pairing_flags &= ~BTM_PAIR_FLAGS_REJECTED_CONNECT; - if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) - { - /* Try again: RNR when no ACL causes HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT */ - btm_sec_change_pairing_state (BTM_PAIR_STATE_GET_REM_NAME); - BTM_ReadRemoteDeviceName(bda, NULL, BT_TRANSPORT_BR_EDR); - return; - } - - /* if we already have pin code */ - if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_PIN) - { - /* Start timer with 0 to initiate connection with new LCB */ - /* because L2CAP will delete current LCB with this event */ - btm_cb.p_collided_dev_rec = p_dev_rec; - alarm_set_on_queue(btm_cb.sec_collision_timer, 0, - btm_sec_connect_after_reject_timeout, - NULL, btu_general_alarm_queue); - } - - return; - } - /* wait for incoming connection without resetting pairing state */ - else if (status == HCI_ERR_CONNECTION_EXISTS) - { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: Wait for incoming connection"); - return; - } + /* if we already have pin code */ + if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_PIN) { + /* Start timer with 0 to initiate connection with new LCB */ + /* because L2CAP will delete current LCB with this event */ + btm_cb.p_collided_dev_rec = p_dev_rec; + alarm_set_on_queue(btm_cb.sec_collision_timer, 0, + btm_sec_connect_after_reject_timeout, NULL, + btu_general_alarm_queue); + } - is_pairing_device = true; + return; } - - /* If connection was made to do bonding restore link security if changed */ - btm_restore_mode(); - - /* if connection fails during pin request, notify application */ - if (status != HCI_SUCCESS) - { - /* If connection failed because of during pairing, need to tell user */ - if (is_pairing_device) - { - p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; - p_dev_rec->sec_flags &= ~((BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED) << bit_shift); - BTM_TRACE_DEBUG ("security_required:%x ", p_dev_rec->security_required ); - - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - - /* We need to notify host that the key is not known any more */ - if (btm_cb.api.p_auth_complete_callback) - { - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, status); - } - } - /* - Do not send authentication failure, if following conditions hold good - 1. BTM Sec Pairing state is idle - 2. Link key for the remote device is present. - 3. Remote is SSP capable. - */ - else if ((p_dev_rec->link_key_type <= BTM_LKEY_TYPE_REMOTE_UNIT) && - (((status == HCI_ERR_AUTH_FAILURE) || - (status == HCI_ERR_KEY_MISSING) || - (status == HCI_ERR_HOST_REJECT_SECURITY) || - (status == HCI_ERR_PAIRING_NOT_ALLOWED) || - (status == HCI_ERR_UNIT_KEY_USED) || - (status == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || - (status == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) || - (status == HCI_ERR_REPEATED_ATTEMPTS)))) - { - p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; - p_dev_rec->sec_flags &= ~ (BTM_SEC_LE_LINK_KEY_KNOWN << bit_shift); - -#ifdef BRCM_NOT_4_BTE - /* If we rejected pairing, pass this special result code */ - if (btm_cb.acl_disc_reason == HCI_ERR_HOST_REJECT_SECURITY) - { - status = HCI_ERR_HOST_REJECT_SECURITY; - } -#endif - - /* We need to notify host that the key is not known any more */ - if (btm_cb.api.p_auth_complete_callback) - { - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, status); - } - } - - if (status == HCI_ERR_CONNECTION_TOUT || status == HCI_ERR_LMP_RESPONSE_TIMEOUT || - status == HCI_ERR_UNSPECIFIED || status == HCI_ERR_PAGE_TIMEOUT) - btm_sec_dev_rec_cback_event (p_dev_rec, BTM_DEVICE_TIMEOUT, false); - else - btm_sec_dev_rec_cback_event (p_dev_rec, BTM_ERR_PROCESSING, false); - - return; + /* wait for incoming connection without resetting pairing state */ + else if (status == HCI_ERR_CONNECTION_EXISTS) { + BTM_TRACE_WARNING( + "Security Manager: btm_sec_connected: Wait for incoming connection"); + return; } - /* If initiated dedicated bonding, return the link key now, and initiate disconnect */ - /* If dedicated bonding, and we now have a link key, we are all done */ - if ( is_pairing_device - && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) ) - { - if (p_dev_rec->link_key_not_sent) - { - p_dev_rec->link_key_not_sent = false; - btm_send_link_key_notif(p_dev_rec); - } + is_pairing_device = true; + } - p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + /* If connection was made to do bonding restore link security if changed */ + btm_restore_mode(); - /* remember flag before it is initialized */ - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - res = true; - else - res = false; + /* if connection fails during pin request, notify application */ + if (status != HCI_SUCCESS) { + /* If connection failed because of during pairing, need to tell user */ + if (is_pairing_device) { + p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + p_dev_rec->sec_flags &= + ~((BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED) << bit_shift); + BTM_TRACE_DEBUG("security_required:%x ", p_dev_rec->security_required); - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_SUCCESS); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); + /* We need to notify host that the key is not known any more */ + if (btm_cb.api.p_auth_complete_callback) { + (*btm_cb.api.p_auth_complete_callback)(p_dev_rec->bd_addr, + p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, status); + } + } + /* + Do not send authentication failure, if following conditions hold good + 1. BTM Sec Pairing state is idle + 2. Link key for the remote device is present. + 3. Remote is SSP capable. + */ + else if ((p_dev_rec->link_key_type <= BTM_LKEY_TYPE_REMOTE_UNIT) && + (((status == HCI_ERR_AUTH_FAILURE) || + (status == HCI_ERR_KEY_MISSING) || + (status == HCI_ERR_HOST_REJECT_SECURITY) || + (status == HCI_ERR_PAIRING_NOT_ALLOWED) || + (status == HCI_ERR_UNIT_KEY_USED) || + (status == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || + (status == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) || + (status == HCI_ERR_REPEATED_ATTEMPTS)))) { + p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; + p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_KNOWN << bit_shift); - if ( res ) - { - /* Let l2cap start bond timer */ - l2cu_update_lcb_4_bonding (p_dev_rec->bd_addr, true); - } +#ifdef BRCM_NOT_4_BTE + /* If we rejected pairing, pass this special result code */ + if (btm_cb.acl_disc_reason == HCI_ERR_HOST_REJECT_SECURITY) { + status = HCI_ERR_HOST_REJECT_SECURITY; + } +#endif - return; + /* We need to notify host that the key is not known any more */ + if (btm_cb.api.p_auth_complete_callback) { + (*btm_cb.api.p_auth_complete_callback)(p_dev_rec->bd_addr, + p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, status); + } } - p_dev_rec->hci_handle = handle; + if (status == HCI_ERR_CONNECTION_TOUT || + status == HCI_ERR_LMP_RESPONSE_TIMEOUT || + status == HCI_ERR_UNSPECIFIED || status == HCI_ERR_PAGE_TIMEOUT) + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_DEVICE_TIMEOUT, false); + else + btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); - /* role may not be correct here, it will be updated by l2cap, but we need to */ - /* notify btm_acl that link is up, so starting of rmt name request will not */ - /* set paging flag up */ - p_acl_cb = btm_bda_to_acl(bda, BT_TRANSPORT_BR_EDR); - if (p_acl_cb) - { - /* whatever is in btm_establish_continue() without reporting the BTM_BL_CONN_EVT event */ -#if (BTM_BYPASS_EXTRA_ACL_SETUP == FALSE) - /* For now there are a some devices that do not like sending */ - /* commands events and data at the same time. */ - /* Set the packet types to the default allowed by the device */ - btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported); + return; + } - if (btm_cb.btm_def_link_policy) - BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); -#endif + /* If initiated dedicated bonding, return the link key now, and initiate + * disconnect */ + /* If dedicated bonding, and we now have a link key, we are all done */ + if (is_pairing_device && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) { + if (p_dev_rec->link_key_not_sent) { + p_dev_rec->link_key_not_sent = false; + btm_send_link_key_notif(p_dev_rec); } - btm_acl_created (bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, handle, HCI_ROLE_SLAVE, BT_TRANSPORT_BR_EDR); - /* Initialize security flags. We need to do that because some */ - /* authorization complete could have come after the connection is dropped */ - /* and that would set wrong flag that link has been authorized already */ - p_dev_rec->sec_flags &= ~((BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | - BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED) << bit_shift); + p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; - if (enc_mode != HCI_ENCRYPT_MODE_DISABLED) - p_dev_rec->sec_flags |= ((BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED) << bit_shift); - - if (btm_cb.security_mode == BTM_SEC_MODE_LINK) - p_dev_rec->sec_flags |= (BTM_SEC_AUTHENTICATED << bit_shift); + /* remember flag before it is initialized */ + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) + res = true; + else + res = false; - if (p_dev_rec->pin_code_length >= 16 || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { - p_dev_rec->sec_flags |= (BTM_SEC_16_DIGIT_PIN_AUTHED << bit_shift); - } + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_SUCCESS); - p_dev_rec->link_key_changed = false; + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); - /* After connection is established we perform security if we do not know */ - /* the name, or if we are originator because some procedure can have */ - /* been scheduled while connection was down */ - BTM_TRACE_DEBUG ("is_originator:%d ", p_dev_rec->is_originator); - if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || p_dev_rec->is_originator) - { - res = btm_sec_execute_procedure(p_dev_rec); - if (res != BTM_CMD_STARTED) - btm_sec_dev_rec_cback_event (p_dev_rec, res, false); + if (res) { + /* Let l2cap start bond timer */ + l2cu_update_lcb_4_bonding(p_dev_rec->bd_addr, true); } + return; + } + + p_dev_rec->hci_handle = handle; + + /* role may not be correct here, it will be updated by l2cap, but we need to + */ + /* notify btm_acl that link is up, so starting of rmt name request will not */ + /* set paging flag up */ + p_acl_cb = btm_bda_to_acl(bda, BT_TRANSPORT_BR_EDR); + if (p_acl_cb) { +/* whatever is in btm_establish_continue() without reporting the BTM_BL_CONN_EVT + * event */ +#if (BTM_BYPASS_EXTRA_ACL_SETUP == FALSE) + /* For now there are a some devices that do not like sending */ + /* commands events and data at the same time. */ + /* Set the packet types to the default allowed by the device */ + btm_set_packet_types(p_acl_cb, btm_cb.btm_acl_pkt_types_supported); + + if (btm_cb.btm_def_link_policy) + BTM_SetLinkPolicy(p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); +#endif + } + btm_acl_created(bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, handle, + HCI_ROLE_SLAVE, BT_TRANSPORT_BR_EDR); + + /* Initialize security flags. We need to do that because some */ + /* authorization complete could have come after the connection is dropped */ + /* and that would set wrong flag that link has been authorized already */ + p_dev_rec->sec_flags &= ~((BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | + BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED) + << bit_shift); + + if (enc_mode != HCI_ENCRYPT_MODE_DISABLED) + p_dev_rec->sec_flags |= + ((BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED) << bit_shift); + + if (btm_cb.security_mode == BTM_SEC_MODE_LINK) + p_dev_rec->sec_flags |= (BTM_SEC_AUTHENTICATED << bit_shift); + + if (p_dev_rec->pin_code_length >= 16 || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { + p_dev_rec->sec_flags |= (BTM_SEC_16_DIGIT_PIN_AUTHED << bit_shift); + } + + p_dev_rec->link_key_changed = false; + + /* After connection is established we perform security if we do not know */ + /* the name, or if we are originator because some procedure can have */ + /* been scheduled while connection was down */ + BTM_TRACE_DEBUG("is_originator:%d ", p_dev_rec->is_originator); + if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || + p_dev_rec->is_originator) { + res = btm_sec_execute_procedure(p_dev_rec); + if (res != BTM_CMD_STARTED) + btm_sec_dev_rec_cback_event(p_dev_rec, res, false); + } + return; } /******************************************************************************* @@ -4670,28 +4550,26 @@ void btm_sec_connected (uint8_t *bda, uint16_t handle, uint8_t status, uint8_t e * Returns btm status * ******************************************************************************/ -tBTM_STATUS btm_sec_disconnect (uint16_t handle, uint8_t reason) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - - /* In some weird race condition we may not have a record */ - if (!p_dev_rec) - { - btsnd_hcic_disconnect (handle, reason); - return(BTM_SUCCESS); - } - - /* If we are in the process of bonding we need to tell client that auth failed */ - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0) - && (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) ) - { - /* we are currently doing bonding. Link will be disconnected when done */ - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_DISC_WHEN_DONE; - return(BTM_BUSY); - } +tBTM_STATUS btm_sec_disconnect(uint16_t handle, uint8_t reason) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + + /* In some weird race condition we may not have a record */ + if (!p_dev_rec) { + btsnd_hcic_disconnect(handle, reason); + return (BTM_SUCCESS); + } + + /* If we are in the process of bonding we need to tell client that auth failed + */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0) && + (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD)) { + /* we are currently doing bonding. Link will be disconnected when done */ + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_DISC_WHEN_DONE; + return (BTM_BUSY); + } - return(btm_sec_send_hci_disconnect(p_dev_rec, reason, handle)); + return (btm_sec_send_hci_disconnect(p_dev_rec, reason, handle)); } /******************************************************************************* @@ -4702,104 +4580,107 @@ tBTM_STATUS btm_sec_disconnect (uint16_t handle, uint8_t reason) * dropped * * Returns void - * - ******************************************************************************/ -void btm_sec_disconnected (uint16_t handle, uint8_t reason) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); - uint8_t old_pairing_flags = btm_cb.pairing_flags; - int result = HCI_ERR_AUTH_FAILURE; - tBTM_SEC_CALLBACK *p_callback = NULL; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - /* If page was delayed for disc complete, can do it now */ - btm_cb.discing = false; - - btm_acl_resubmit_page(); - - if (!p_dev_rec) - return; - - transport = (handle == p_dev_rec->hci_handle) ? BT_TRANSPORT_BR_EDR: BT_TRANSPORT_LE; - - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ - -#if (BTM_DISC_DURING_RS == TRUE) - LOG_INFO(LOG_TAG, "%s clearing pending flag handle:%d reason:%d", __func__, handle, reason); - p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ -#endif - - /* clear unused flags */ - p_dev_rec->sm4 &= BTM_SM4_TRUE; - - uint8_t *bd_addr = (uint8_t *)p_dev_rec->bd_addr; - BTM_TRACE_EVENT("%s sec_req:x%x state:%s reason:%d bd_addr:%02x:%02x:%02x:%02x:%02x:%02x" - " remote_name:%s", __func__, p_dev_rec->security_required, btm_pair_state_descr(btm_cb.pairing_state), - reason, bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5], p_dev_rec->sec_bd_name); - - BTM_TRACE_EVENT("%s before update sec_flags=0x%x", __func__, p_dev_rec->sec_flags); - - /* If we are in the process of bonding we need to tell client that auth failed */ - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0)) - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; - if (btm_cb.api.p_auth_complete_callback) - { - /* If the disconnection reason is REPEATED_ATTEMPTS, - send this error message to complete callback function - to display the error message of Repeated attempts. - All others, send HCI_ERR_AUTH_FAILURE. */ - if (reason == HCI_ERR_REPEATED_ATTEMPTS) - { - result = HCI_ERR_REPEATED_ATTEMPTS; - } - else if (old_pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - { - result = HCI_ERR_HOST_REJECT_SECURITY; - } - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, result); - } - } + * + ******************************************************************************/ +void btm_sec_disconnected(uint16_t handle, uint8_t reason) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); + uint8_t old_pairing_flags = btm_cb.pairing_flags; + int result = HCI_ERR_AUTH_FAILURE; + tBTM_SEC_CALLBACK* p_callback = NULL; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, p_dev_rec->bd_addr, HCI_SUCCESS); - /* see sec_flags processing in btm_acl_removed */ + /* If page was delayed for disc complete, can do it now */ + btm_cb.discing = false; - if (transport == BT_TRANSPORT_LE) - { - p_dev_rec->ble_hci_handle = BTM_SEC_INVALID_HANDLE; - p_dev_rec->sec_flags &= ~(BTM_SEC_LE_AUTHENTICATED|BTM_SEC_LE_ENCRYPTED); - p_dev_rec->enc_key_size = 0; - } - else - { - p_dev_rec->hci_handle = BTM_SEC_INVALID_HANDLE; - p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED - | BTM_SEC_ROLE_SWITCHED | BTM_SEC_16_DIGIT_PIN_AUTHED); - } + btm_acl_resubmit_page(); - if (p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH) - { - p_dev_rec->sec_state = (transport == BT_TRANSPORT_LE) ? - BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; - return; - } - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - p_dev_rec->security_required = BTM_SEC_NONE; + if (!p_dev_rec) return; - p_callback = p_dev_rec->p_callback; + transport = + (handle == p_dev_rec->hci_handle) ? BT_TRANSPORT_BR_EDR : BT_TRANSPORT_LE; - /* if security is pending, send callback to clean up the security state */ - if(p_callback) - { - p_dev_rec->p_callback = NULL; /* when the peer device time out the authentication before - we do, this call back must be reset here */ - (*p_callback) (p_dev_rec->bd_addr, transport, p_dev_rec->p_ref_data, BTM_ERR_PROCESSING); - } + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ - BTM_TRACE_EVENT("%s after update sec_flags=0x%x", __func__, p_dev_rec->sec_flags); +#if (BTM_DISC_DURING_RS == TRUE) + LOG_INFO(LOG_TAG, "%s clearing pending flag handle:%d reason:%d", __func__, + handle, reason); + p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ +#endif + + /* clear unused flags */ + p_dev_rec->sm4 &= BTM_SM4_TRUE; + + uint8_t* bd_addr = (uint8_t*)p_dev_rec->bd_addr; + BTM_TRACE_EVENT( + "%s sec_req:x%x state:%s reason:%d bd_addr:%02x:%02x:%02x:%02x:%02x:%02x" + " remote_name:%s", + __func__, p_dev_rec->security_required, + btm_pair_state_descr(btm_cb.pairing_state), reason, bd_addr[0], + bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5], + p_dev_rec->sec_bd_name); + + BTM_TRACE_EVENT("%s before update sec_flags=0x%x", __func__, + p_dev_rec->sec_flags); + + /* If we are in the process of bonding we need to tell client that auth failed + */ + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0)) { + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; + if (btm_cb.api.p_auth_complete_callback) { + /* If the disconnection reason is REPEATED_ATTEMPTS, + send this error message to complete callback function + to display the error message of Repeated attempts. + All others, send HCI_ERR_AUTH_FAILURE. */ + if (reason == HCI_ERR_REPEATED_ATTEMPTS) { + result = HCI_ERR_REPEATED_ATTEMPTS; + } else if (old_pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) { + result = HCI_ERR_HOST_REJECT_SECURITY; + } + (*btm_cb.api.p_auth_complete_callback)(p_dev_rec->bd_addr, + p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, result); + } + } + + btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, p_dev_rec->bd_addr, + HCI_SUCCESS); + /* see sec_flags processing in btm_acl_removed */ + + if (transport == BT_TRANSPORT_LE) { + p_dev_rec->ble_hci_handle = BTM_SEC_INVALID_HANDLE; + p_dev_rec->sec_flags &= ~(BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED); + p_dev_rec->enc_key_size = 0; + } else { + p_dev_rec->hci_handle = BTM_SEC_INVALID_HANDLE; + p_dev_rec->sec_flags &= + ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED | + BTM_SEC_ROLE_SWITCHED | BTM_SEC_16_DIGIT_PIN_AUTHED); + } + + if (p_dev_rec->sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH) { + p_dev_rec->sec_state = (transport == BT_TRANSPORT_LE) + ? BTM_SEC_STATE_DISCONNECTING + : BTM_SEC_STATE_DISCONNECTING_BLE; + return; + } + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; + p_dev_rec->security_required = BTM_SEC_NONE; + + p_callback = p_dev_rec->p_callback; + + /* if security is pending, send callback to clean up the security state */ + if (p_callback) { + p_dev_rec->p_callback = + NULL; /* when the peer device time out the authentication before + we do, this call back must be reset here */ + (*p_callback)(p_dev_rec->bd_addr, transport, p_dev_rec->p_ref_data, + BTM_ERR_PROCESSING); + } + + BTM_TRACE_EVENT("%s after update sec_flags=0x%x", __func__, + p_dev_rec->sec_flags); } /******************************************************************************* @@ -4812,130 +4693,132 @@ void btm_sec_disconnected (uint16_t handle, uint8_t reason) * Returns Pointer to the record or NULL * ******************************************************************************/ -void btm_sec_link_key_notification (uint8_t *p_bda, uint8_t *p_link_key, uint8_t key_type) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_bda); - bool we_are_bonding = false; - bool ltk_derived_lk = false; - - BTM_TRACE_EVENT ("btm_sec_link_key_notification() BDA:%04x%08x, TYPE: %d", - (p_bda[0]<<8)+p_bda[1], (p_bda[2]<<24)+(p_bda[3]<<16)+(p_bda[4]<<8)+p_bda[5], - key_type); - - if ((key_type >= BTM_LTK_DERIVED_LKEY_OFFSET + BTM_LKEY_TYPE_COMBINATION) && - (key_type <= BTM_LTK_DERIVED_LKEY_OFFSET + BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - ltk_derived_lk = true; - key_type -= BTM_LTK_DERIVED_LKEY_OFFSET; - } - /* If connection was made to do bonding restore link security if changed */ - btm_restore_mode(); - - if (key_type != BTM_LKEY_TYPE_CHANGED_COMB) - p_dev_rec->link_key_type = key_type; - - p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN; - - /* - * Until this point in time, we do not know if MITM was enabled, hence we - * add the extended security flag here. - */ - if (p_dev_rec->pin_code_length >= 16 || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || - p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { - p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; - } - - /* BR/EDR connection, update the encryption key size to be 16 as always */ - p_dev_rec->enc_key_size = 16; - memcpy (p_dev_rec->link_key, p_link_key, LINK_KEY_LEN); - - if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - && (memcmp (btm_cb.pairing_bda, p_bda, BD_ADDR_LEN) == 0) ) - { - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - we_are_bonding = true; - else - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - } - - /* save LTK derived LK no matter what */ - if (ltk_derived_lk) - { - if (btm_cb.api.p_link_key_callback) - { - BTM_TRACE_DEBUG ("%s() Save LTK derived LK (key_type = %d)", - __func__, p_dev_rec->link_key_type); - (*btm_cb.api.p_link_key_callback) (p_bda, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, - p_link_key, p_dev_rec->link_key_type); - } - } +void btm_sec_link_key_notification(uint8_t* p_bda, uint8_t* p_link_key, + uint8_t key_type) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(p_bda); + bool we_are_bonding = false; + bool ltk_derived_lk = false; + + BTM_TRACE_EVENT( + "btm_sec_link_key_notification() BDA:%04x%08x, TYPE: %d", + (p_bda[0] << 8) + p_bda[1], + (p_bda[2] << 24) + (p_bda[3] << 16) + (p_bda[4] << 8) + p_bda[5], + key_type); + + if ((key_type >= BTM_LTK_DERIVED_LKEY_OFFSET + BTM_LKEY_TYPE_COMBINATION) && + (key_type <= + BTM_LTK_DERIVED_LKEY_OFFSET + BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + ltk_derived_lk = true; + key_type -= BTM_LTK_DERIVED_LKEY_OFFSET; + } + /* If connection was made to do bonding restore link security if changed */ + btm_restore_mode(); + + if (key_type != BTM_LKEY_TYPE_CHANGED_COMB) + p_dev_rec->link_key_type = key_type; + + p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN; + + /* + * Until this point in time, we do not know if MITM was enabled, hence we + * add the extended security flag here. + */ + if (p_dev_rec->pin_code_length >= 16 || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB || + p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) { + p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED; + } + + /* BR/EDR connection, update the encryption key size to be 16 as always */ + p_dev_rec->enc_key_size = 16; + memcpy(p_dev_rec->link_key, p_link_key, LINK_KEY_LEN); + + if ((btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) && + (memcmp(btm_cb.pairing_bda, p_bda, BD_ADDR_LEN) == 0)) { + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) + we_are_bonding = true; else - { - if ((p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256) || - (p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - p_dev_rec->new_encryption_key_is_p256 = true; - BTM_TRACE_DEBUG ("%s set new_encr_key_256 to %d", - __func__, p_dev_rec->new_encryption_key_is_p256); - } - } - - /* If name is not known at this point delay calling callback until the name is */ - /* resolved. Unless it is a HID Device and we really need to send all link keys. */ - if ((!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) - && ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) != BTM_COD_MAJOR_PERIPHERAL)) - && !ltk_derived_lk) - { - BTM_TRACE_EVENT ("btm_sec_link_key_notification() Delayed BDA: %08x%04x Type:%d", - (p_bda[0]<<24) + (p_bda[1]<<16) + (p_bda[2]<<8) + p_bda[3], - (p_bda[4] << 8) + p_bda[5], key_type); - - p_dev_rec->link_key_not_sent = true; - - /* If it is for bonding nothing else will follow, so we need to start name resolution */ - if (we_are_bonding) - { - btsnd_hcic_rmt_name_req(p_bda, HCI_PAGE_SCAN_REP_MODE_R1, HCI_MANDATARY_PAGE_SCAN_MODE, 0); - } - - BTM_TRACE_EVENT ("rmt_io_caps:%d, sec_flags:x%x, dev_class[1]:x%02x", p_dev_rec->rmt_io_caps, p_dev_rec->sec_flags, p_dev_rec->dev_class[1]) - return; - } + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + } - /* If its not us who perform authentication, we should tell stackserver */ - /* that some authentication has been completed */ - /* This is required when different entities receive link notification and auth complete */ - if (!(p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE) - /* for derived key, always send authentication callback for BR channel */ - || ltk_derived_lk) - { - if (btm_cb.api.p_auth_complete_callback) - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_SUCCESS); - } + /* save LTK derived LK no matter what */ + if (ltk_derived_lk) { + if (btm_cb.api.p_link_key_callback) { + BTM_TRACE_DEBUG("%s() Save LTK derived LK (key_type = %d)", __func__, + p_dev_rec->link_key_type); + (*btm_cb.api.p_link_key_callback)(p_bda, p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, p_link_key, + p_dev_rec->link_key_type); + } + } else { + if ((p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256) || + (p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + p_dev_rec->new_encryption_key_is_p256 = true; + BTM_TRACE_DEBUG("%s set new_encr_key_256 to %d", __func__, + p_dev_rec->new_encryption_key_is_p256); + } + } + + /* If name is not known at this point delay calling callback until the name is + */ + /* resolved. Unless it is a HID Device and we really need to send all link + * keys. */ + if ((!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) && + ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) != + BTM_COD_MAJOR_PERIPHERAL)) && + !ltk_derived_lk) { + BTM_TRACE_EVENT( + "btm_sec_link_key_notification() Delayed BDA: %08x%04x Type:%d", + (p_bda[0] << 24) + (p_bda[1] << 16) + (p_bda[2] << 8) + p_bda[3], + (p_bda[4] << 8) + p_bda[5], key_type); + + p_dev_rec->link_key_not_sent = true; + + /* If it is for bonding nothing else will follow, so we need to start name + * resolution */ + if (we_are_bonding) { + btsnd_hcic_rmt_name_req(p_bda, HCI_PAGE_SCAN_REP_MODE_R1, + HCI_MANDATARY_PAGE_SCAN_MODE, 0); + } + + BTM_TRACE_EVENT("rmt_io_caps:%d, sec_flags:x%x, dev_class[1]:x%02x", + p_dev_rec->rmt_io_caps, p_dev_rec->sec_flags, + p_dev_rec->dev_class[1]) + return; + } + + /* If its not us who perform authentication, we should tell stackserver */ + /* that some authentication has been completed */ + /* This is required when different entities receive link notification and auth + * complete */ + if (!(p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE) + /* for derived key, always send authentication callback for BR channel */ + || ltk_derived_lk) { + if (btm_cb.api.p_auth_complete_callback) + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_SUCCESS); + } - /* We will save link key only if the user authorized it - BTE report link key in all cases */ +/* We will save link key only if the user authorized it - BTE report link key in + * all cases */ #ifdef BRCM_NONE_BTE - if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED) + if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED) #endif - { - if (btm_cb.api.p_link_key_callback) - { - if (ltk_derived_lk) - { - BTM_TRACE_DEBUG ("btm_sec_link_key_notification() LTK derived LK is saved already" - " (key_type = %d)", p_dev_rec->link_key_type); - } - else - { - (*btm_cb.api.p_link_key_callback) (p_bda, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, - p_link_key, p_dev_rec->link_key_type); - } - } + { + if (btm_cb.api.p_link_key_callback) { + if (ltk_derived_lk) { + BTM_TRACE_DEBUG( + "btm_sec_link_key_notification() LTK derived LK is saved already" + " (key_type = %d)", + p_dev_rec->link_key_type); + } else { + (*btm_cb.api.p_link_key_callback)(p_bda, p_dev_rec->dev_class, + p_dev_rec->sec_bd_name, p_link_key, + p_dev_rec->link_key_type); + } } + } } /******************************************************************************* @@ -4947,34 +4830,33 @@ void btm_sec_link_key_notification (uint8_t *p_bda, uint8_t *p_link_key, uint8_t * Returns Pointer to the record or NULL * ******************************************************************************/ -void btm_sec_link_key_request (uint8_t *p_bda) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_bda); - - BTM_TRACE_EVENT ("btm_sec_link_key_request() BDA: %02x:%02x:%02x:%02x:%02x:%02x", - p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); - - if( (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && - (btm_cb.collision_start_time != 0) && - (memcmp (btm_cb.p_collided_dev_rec->bd_addr, p_bda, BD_ADDR_LEN) == 0) ) - { - BTM_TRACE_EVENT ("btm_sec_link_key_request() rejecting link key req " - "State: %d START_TIMEOUT : %d", - btm_cb.pairing_state, btm_cb.collision_start_time); - btsnd_hcic_link_key_neg_reply (p_bda); - return; - } - if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) - { - btsnd_hcic_link_key_req_reply (p_bda, p_dev_rec->link_key); - return; - } +void btm_sec_link_key_request(uint8_t* p_bda) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(p_bda); + + BTM_TRACE_EVENT( + "btm_sec_link_key_request() BDA: %02x:%02x:%02x:%02x:%02x:%02x", + p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]); + + if ((btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && + (btm_cb.collision_start_time != 0) && + (memcmp(btm_cb.p_collided_dev_rec->bd_addr, p_bda, BD_ADDR_LEN) == 0)) { + BTM_TRACE_EVENT( + "btm_sec_link_key_request() rejecting link key req " + "State: %d START_TIMEOUT : %d", + btm_cb.pairing_state, btm_cb.collision_start_time); + btsnd_hcic_link_key_neg_reply(p_bda); + return; + } + if (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) { + btsnd_hcic_link_key_req_reply(p_bda, p_dev_rec->link_key); + return; + } - /* Notify L2CAP to increase timeout */ - l2c_pin_code_request (p_bda); + /* Notify L2CAP to increase timeout */ + l2c_pin_code_request(p_bda); - /* The link key is not in the database and it is not known to the manager */ - btsnd_hcic_link_key_neg_reply (p_bda); + /* The link key is not in the database and it is not known to the manager */ + btsnd_hcic_link_key_neg_reply(p_bda); } /******************************************************************************* @@ -4987,122 +4869,116 @@ void btm_sec_link_key_request (uint8_t *p_bda) * Returns Pointer to the TLE struct * ******************************************************************************/ -static void btm_sec_pairing_timeout(UNUSED_ATTR void *data) -{ - tBTM_CB *p_cb = &btm_cb; - tBTM_SEC_DEV_REC *p_dev_rec; +static void btm_sec_pairing_timeout(UNUSED_ATTR void* data) { + tBTM_CB* p_cb = &btm_cb; + tBTM_SEC_DEV_REC* p_dev_rec; #if (BTM_LOCAL_IO_CAPS == BTM_IO_CAP_NONE) - tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO; + tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO; #else - tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_YES; + tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_YES; #endif - uint8_t name[2]; - -/* Coverity: FALSE-POSITIVE error from Coverity tool. Please do NOT remove - * the following comment. - */ -/* coverity[UNUSED_VALUE] pointer p_dev_rec is actually used several times... - * This is a Coverity false-positive, i.e. a fake issue. - */ - p_dev_rec = btm_find_dev (p_cb->pairing_bda); - - BTM_TRACE_EVENT ("%s State: %s Flags: %u", __func__, - btm_pair_state_descr(p_cb->pairing_state), p_cb->pairing_flags); - - switch (p_cb->pairing_state) - { - case BTM_PAIR_STATE_WAIT_PIN_REQ: - btm_sec_bond_cancel_complete(); - break; - - case BTM_PAIR_STATE_WAIT_LOCAL_PIN: - if ( (btm_cb.pairing_flags & BTM_PAIR_FLAGS_PRE_FETCH_PIN) == 0) - btsnd_hcic_pin_code_neg_reply (p_cb->pairing_bda); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - /* We need to notify the UI that no longer need the PIN */ - if (btm_cb.api.p_auth_complete_callback) - { - if (p_dev_rec == NULL) - { - name[0] = 0; - (*btm_cb.api.p_auth_complete_callback) (p_cb->pairing_bda, - NULL, - name, HCI_ERR_CONNECTION_TOUT); - } - else - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_ERR_CONNECTION_TOUT); - } - break; + uint8_t name[2]; + + /* Coverity: FALSE-POSITIVE error from Coverity tool. Please do NOT remove + * the following comment. + */ + /* coverity[UNUSED_VALUE] pointer p_dev_rec is actually used several times... + * This is a Coverity false-positive, i.e. a fake issue. + */ + p_dev_rec = btm_find_dev(p_cb->pairing_bda); + + BTM_TRACE_EVENT("%s State: %s Flags: %u", __func__, + btm_pair_state_descr(p_cb->pairing_state), + p_cb->pairing_flags); + + switch (p_cb->pairing_state) { + case BTM_PAIR_STATE_WAIT_PIN_REQ: + btm_sec_bond_cancel_complete(); + break; + + case BTM_PAIR_STATE_WAIT_LOCAL_PIN: + if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PRE_FETCH_PIN) == 0) + btsnd_hcic_pin_code_neg_reply(p_cb->pairing_bda); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + /* We need to notify the UI that no longer need the PIN */ + if (btm_cb.api.p_auth_complete_callback) { + if (p_dev_rec == NULL) { + name[0] = 0; + (*btm_cb.api.p_auth_complete_callback)(p_cb->pairing_bda, NULL, name, + HCI_ERR_CONNECTION_TOUT); + } else + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_ERR_CONNECTION_TOUT); + } + break; - case BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM: - btsnd_hcic_user_conf_reply (p_cb->pairing_bda, false); - /* btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); */ - break; + case BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM: + btsnd_hcic_user_conf_reply(p_cb->pairing_bda, false); + /* btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); */ + break; #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) - case BTM_PAIR_STATE_KEY_ENTRY: - btsnd_hcic_user_passkey_neg_reply(p_cb->pairing_bda); - /* btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); */ - break; + case BTM_PAIR_STATE_KEY_ENTRY: + btsnd_hcic_user_passkey_neg_reply(p_cb->pairing_bda); + /* btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); */ + break; #endif /* !BTM_IO_CAP_NONE */ - case BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS: - if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) - auth_req |= BTM_AUTH_DD_BOND; - - btsnd_hcic_io_cap_req_reply (p_cb->pairing_bda, btm_cb.devcb.loc_io_caps, - BTM_OOB_NONE, auth_req); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - break; - - case BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP: - btsnd_hcic_rem_oob_neg_reply (p_cb->pairing_bda); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - break; - - case BTM_PAIR_STATE_WAIT_DISCONNECT: - /* simple pairing failed. Started a 1-sec timer at simple pairing complete. - * now it's time to tear down the ACL link*/ - if (p_dev_rec == NULL) - { - BTM_TRACE_ERROR("%s BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x", - __func__, - (p_cb->pairing_bda[0]<<24) + (p_cb->pairing_bda[1]<<16) + (p_cb->pairing_bda[2]<<8) + p_cb->pairing_bda[3], - (p_cb->pairing_bda[4] << 8) + p_cb->pairing_bda[5]); - break; - } - btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_AUTH_FAILURE, p_dev_rec->hci_handle); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - break; - - case BTM_PAIR_STATE_WAIT_AUTH_COMPLETE: - case BTM_PAIR_STATE_GET_REM_NAME: - /* We need to notify the UI that timeout has happened while waiting for authentication*/ - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - if (btm_cb.api.p_auth_complete_callback) - { - if (p_dev_rec == NULL) - { - name[0] = 0; - (*btm_cb.api.p_auth_complete_callback) (p_cb->pairing_bda, - NULL, - name, HCI_ERR_CONNECTION_TOUT); - } - else - (*btm_cb.api.p_auth_complete_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, HCI_ERR_CONNECTION_TOUT); - } - break; - - default: - BTM_TRACE_WARNING("%s not processed state: %s", __func__, - btm_pair_state_descr(btm_cb.pairing_state)); - btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); - break; - } + case BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS: + if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) + auth_req |= BTM_AUTH_DD_BOND; + + btsnd_hcic_io_cap_req_reply(p_cb->pairing_bda, btm_cb.devcb.loc_io_caps, + BTM_OOB_NONE, auth_req); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + break; + + case BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP: + btsnd_hcic_rem_oob_neg_reply(p_cb->pairing_bda); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + break; + + case BTM_PAIR_STATE_WAIT_DISCONNECT: + /* simple pairing failed. Started a 1-sec timer at simple pairing + * complete. + * now it's time to tear down the ACL link*/ + if (p_dev_rec == NULL) { + BTM_TRACE_ERROR( + "%s BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x", __func__, + (p_cb->pairing_bda[0] << 24) + (p_cb->pairing_bda[1] << 16) + + (p_cb->pairing_bda[2] << 8) + p_cb->pairing_bda[3], + (p_cb->pairing_bda[4] << 8) + p_cb->pairing_bda[5]); + break; + } + btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_AUTH_FAILURE, + p_dev_rec->hci_handle); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + break; + + case BTM_PAIR_STATE_WAIT_AUTH_COMPLETE: + case BTM_PAIR_STATE_GET_REM_NAME: + /* We need to notify the UI that timeout has happened while waiting for + * authentication*/ + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + if (btm_cb.api.p_auth_complete_callback) { + if (p_dev_rec == NULL) { + name[0] = 0; + (*btm_cb.api.p_auth_complete_callback)(p_cb->pairing_bda, NULL, name, + HCI_ERR_CONNECTION_TOUT); + } else + (*btm_cb.api.p_auth_complete_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + HCI_ERR_CONNECTION_TOUT); + } + break; + + default: + BTM_TRACE_WARNING("%s not processed state: %s", __func__, + btm_pair_state_descr(btm_cb.pairing_state)); + btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE); + break; + } } /******************************************************************************* @@ -5114,131 +4990,129 @@ static void btm_sec_pairing_timeout(UNUSED_ATTR void *data) * Returns Pointer to the record or NULL * ******************************************************************************/ -void btm_sec_pin_code_request (uint8_t *p_bda) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_CB *p_cb = &btm_cb; - - BTM_TRACE_EVENT ("btm_sec_pin_code_request() State: %s, BDA:%04x%08x", - btm_pair_state_descr(btm_cb.pairing_state), - (p_bda[0]<<8)+p_bda[1], (p_bda[2]<<24)+(p_bda[3]<<16)+(p_bda[4]<<8)+p_bda[5] ); - - if (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) - { - if ( (memcmp (p_bda, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) && - (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_AUTH_COMPLETE) ) - { - btsnd_hcic_pin_code_neg_reply (p_bda); - return; - } - else if ((btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_PIN_REQ) - || memcmp (p_bda, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) - { - BTM_TRACE_WARNING ("btm_sec_pin_code_request() rejected - state: %s", - btm_pair_state_descr(btm_cb.pairing_state)); - btsnd_hcic_pin_code_neg_reply (p_bda); - return; - } - } - - p_dev_rec = btm_find_or_alloc_dev (p_bda); - /* received PIN code request. must be non-sm4 */ - p_dev_rec->sm4 = BTM_SM4_KNOWN; - - if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) - { - memcpy (btm_cb.pairing_bda, p_bda, BD_ADDR_LEN); - - btm_cb.pairing_flags = BTM_PAIR_FLAGS_PEER_STARTED_DD; - /* Make sure we reset the trusted mask to help against attacks */ - BTM_SEC_CLR_TRUSTED_DEVICE(p_dev_rec->trusted_mask); - } +void btm_sec_pin_code_request(uint8_t* p_bda) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_CB* p_cb = &btm_cb; + + BTM_TRACE_EVENT( + "btm_sec_pin_code_request() State: %s, BDA:%04x%08x", + btm_pair_state_descr(btm_cb.pairing_state), (p_bda[0] << 8) + p_bda[1], + (p_bda[2] << 24) + (p_bda[3] << 16) + (p_bda[4] << 8) + p_bda[5]); + + if (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) { + if ((memcmp(p_bda, btm_cb.pairing_bda, BD_ADDR_LEN) == 0) && + (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_AUTH_COMPLETE)) { + btsnd_hcic_pin_code_neg_reply(p_bda); + return; + } else if ((btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_PIN_REQ) || + memcmp(p_bda, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) { + BTM_TRACE_WARNING("btm_sec_pin_code_request() rejected - state: %s", + btm_pair_state_descr(btm_cb.pairing_state)); + btsnd_hcic_pin_code_neg_reply(p_bda); + return; + } + } + + p_dev_rec = btm_find_or_alloc_dev(p_bda); + /* received PIN code request. must be non-sm4 */ + p_dev_rec->sm4 = BTM_SM4_KNOWN; + + if (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) { + memcpy(btm_cb.pairing_bda, p_bda, BD_ADDR_LEN); + + btm_cb.pairing_flags = BTM_PAIR_FLAGS_PEER_STARTED_DD; + /* Make sure we reset the trusted mask to help against attacks */ + BTM_SEC_CLR_TRUSTED_DEVICE(p_dev_rec->trusted_mask); + } + + if (!p_cb->pairing_disabled && (p_cb->cfg.pin_type == HCI_PIN_TYPE_FIXED)) { + BTM_TRACE_EVENT("btm_sec_pin_code_request fixed pin replying"); + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + btsnd_hcic_pin_code_req_reply(p_bda, p_cb->cfg.pin_code_len, + p_cb->cfg.pin_code); + return; + } - if (!p_cb->pairing_disabled && (p_cb->cfg.pin_type == HCI_PIN_TYPE_FIXED)) - { - BTM_TRACE_EVENT ("btm_sec_pin_code_request fixed pin replying"); - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - btsnd_hcic_pin_code_req_reply (p_bda, p_cb->cfg.pin_code_len, p_cb->cfg.pin_code); - return; - } + /* Use the connecting device's CoD for the connection */ + if ((!memcmp(p_bda, p_cb->connecting_bda, BD_ADDR_LEN)) && + (p_cb->connecting_dc[0] || p_cb->connecting_dc[1] || + p_cb->connecting_dc[2])) + memcpy(p_dev_rec->dev_class, p_cb->connecting_dc, DEV_CLASS_LEN); - /* Use the connecting device's CoD for the connection */ - if ( (!memcmp (p_bda, p_cb->connecting_bda, BD_ADDR_LEN)) - && (p_cb->connecting_dc[0] || p_cb->connecting_dc[1] || p_cb->connecting_dc[2]) ) - memcpy (p_dev_rec->dev_class, p_cb->connecting_dc, DEV_CLASS_LEN); + /* We could have started connection after asking user for the PIN code */ + if (btm_cb.pin_code_len != 0) { + BTM_TRACE_EVENT("btm_sec_pin_code_request bonding sending reply"); + btsnd_hcic_pin_code_req_reply(p_bda, btm_cb.pin_code_len, p_cb->pin_code); - /* We could have started connection after asking user for the PIN code */ - if (btm_cb.pin_code_len != 0) - { - BTM_TRACE_EVENT ("btm_sec_pin_code_request bonding sending reply"); - btsnd_hcic_pin_code_req_reply (p_bda, btm_cb.pin_code_len, p_cb->pin_code); + /* Mark that we forwarded received from the user PIN code */ + btm_cb.pin_code_len = 0; - /* Mark that we forwarded received from the user PIN code */ - btm_cb.pin_code_len = 0; + /* We can change mode back right away, that other connection being + * established */ + /* is not forced to be secure - found a FW issue, so we can not do this + btm_restore_mode(); */ - /* We can change mode back right away, that other connection being established */ - /* is not forced to be secure - found a FW issue, so we can not do this - btm_restore_mode(); */ + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); + } - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); - } + /* If pairing disabled OR (no PIN callback and not bonding) */ + /* OR we could not allocate entry in the database reject pairing request */ + else if ( + p_cb->pairing_disabled || (p_cb->api.p_pin_callback == NULL) - /* If pairing disabled OR (no PIN callback and not bonding) */ - /* OR we could not allocate entry in the database reject pairing request */ - else if (p_cb->pairing_disabled - || (p_cb->api.p_pin_callback == NULL) - - /* OR Microsoft keyboard can for some reason try to establish connection */ - /* the only thing we can do here is to shut it up. Normally we will be originator */ - /* for keyboard bonding */ - || (!p_dev_rec->is_originator - && ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == BTM_COD_MAJOR_PERIPHERAL) - && (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD)) ) - { - BTM_TRACE_WARNING("btm_sec_pin_code_request(): Pairing disabled:%d; PIN callback:%x, Dev Rec:%x!", - p_cb->pairing_disabled, p_cb->api.p_pin_callback, p_dev_rec); + /* OR Microsoft keyboard can for some reason try to establish connection + */ + /* the only thing we can do here is to shut it up. Normally we will be + originator */ + /* for keyboard bonding */ + || (!p_dev_rec->is_originator && + ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == + BTM_COD_MAJOR_PERIPHERAL) && + (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD))) { + BTM_TRACE_WARNING( + "btm_sec_pin_code_request(): Pairing disabled:%d; PIN callback:%x, Dev " + "Rec:%x!", + p_cb->pairing_disabled, p_cb->api.p_pin_callback, p_dev_rec); + + btsnd_hcic_pin_code_neg_reply(p_bda); + } + /* Notify upper layer of PIN request and start expiration timer */ + else { + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_PIN); + /* Pin code request can not come at the same time as connection request */ + memcpy(p_cb->connecting_bda, p_bda, BD_ADDR_LEN); + memcpy(p_cb->connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); + + /* Check if the name is known */ + /* Even if name is not known we might not be able to get one */ + /* this is the case when we are already getting something from the */ + /* device, so HCI level is flow controlled */ + /* Also cannot send remote name request while paging, i.e. connection is not + * completed */ + if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) { + BTM_TRACE_EVENT("btm_sec_pin_code_request going for callback"); + + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; + if (p_cb->api.p_pin_callback) { + (*p_cb->api.p_pin_callback)( + p_bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + (p_dev_rec->p_cur_service == NULL) + ? false + : (p_dev_rec->p_cur_service->security_flags & + BTM_SEC_IN_MIN_16_DIGIT_PIN)); + } + } else { + BTM_TRACE_EVENT("btm_sec_pin_code_request going for remote name"); - btsnd_hcic_pin_code_neg_reply (p_bda); - } - /* Notify upper layer of PIN request and start expiration timer */ - else - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_LOCAL_PIN); - /* Pin code request can not come at the same time as connection request */ - memcpy (p_cb->connecting_bda, p_bda, BD_ADDR_LEN); - memcpy (p_cb->connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); - - /* Check if the name is known */ - /* Even if name is not known we might not be able to get one */ - /* this is the case when we are already getting something from the */ - /* device, so HCI level is flow controlled */ - /* Also cannot send remote name request while paging, i.e. connection is not completed */ - if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) - { - BTM_TRACE_EVENT ("btm_sec_pin_code_request going for callback"); - - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; - if (p_cb->api.p_pin_callback) { - (*p_cb->api.p_pin_callback) (p_bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, - (p_dev_rec->p_cur_service == NULL) ? false - : (p_dev_rec->p_cur_service->security_flags - & BTM_SEC_IN_MIN_16_DIGIT_PIN)); - } - } - else - { - BTM_TRACE_EVENT ("btm_sec_pin_code_request going for remote name"); - - /* We received PIN code request for the device with unknown name */ - /* it is not user friendly just to ask for the PIN without name */ - /* try to get name at first */ - btsnd_hcic_rmt_name_req(p_dev_rec->bd_addr, - HCI_PAGE_SCAN_REP_MODE_R1, - HCI_MANDATARY_PAGE_SCAN_MODE, 0); - } + /* We received PIN code request for the device with unknown name */ + /* it is not user friendly just to ask for the PIN without name */ + /* try to get name at first */ + btsnd_hcic_rmt_name_req(p_dev_rec->bd_addr, HCI_PAGE_SCAN_REP_MODE_R1, + HCI_MANDATARY_PAGE_SCAN_MODE, 0); } + } - return; + return; } /******************************************************************************* @@ -5250,22 +5124,19 @@ void btm_sec_pin_code_request (uint8_t *p_bda) * Returns void * ******************************************************************************/ -void btm_sec_update_clock_offset (uint16_t handle, uint16_t clock_offset) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - tBTM_INQ_INFO *p_inq_info; +void btm_sec_update_clock_offset(uint16_t handle, uint16_t clock_offset) { + tBTM_SEC_DEV_REC* p_dev_rec; + tBTM_INQ_INFO* p_inq_info; - p_dev_rec = btm_find_dev_by_handle(handle); - if (p_dev_rec == NULL) - return; + p_dev_rec = btm_find_dev_by_handle(handle); + if (p_dev_rec == NULL) return; - p_dev_rec->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; + p_dev_rec->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; - p_inq_info = BTM_InqDbRead(p_dev_rec->bd_addr); - if (p_inq_info == NULL) - return; + p_inq_info = BTM_InqDbRead(p_dev_rec->bd_addr); + if (p_inq_info == NULL) return; - p_inq_info->results.clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; + p_inq_info->results.clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; } /****************************************************************** @@ -5287,133 +5158,135 @@ void btm_sec_update_clock_offset (uint16_t handle, uint16_t clock_offset) * BTM_NO_RESOURCES - permission declined * ******************************************************************************/ -static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) -{ - BTM_TRACE_EVENT ("btm_sec_execute_procedure: Required:0x%x Flags:0x%x State:%d", - p_dev_rec->security_required, p_dev_rec->sec_flags, p_dev_rec->sec_state); - - /* There is a chance that we are getting name. Wait until done. */ - if (p_dev_rec->sec_state != 0) - return(BTM_CMD_STARTED); - - /* If any security is required, get the name first */ - if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) - && (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) - { - BTM_TRACE_EVENT ("Security Manager: Start get name"); - if (!btm_sec_start_get_name (p_dev_rec)) - { - return(BTM_NO_RESOURCES); - } - return(BTM_CMD_STARTED); - } - - /* If connection is not authenticated and authentication is required */ - /* start authentication and return PENDING to the caller */ - if ((((!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) - && (( p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) - || (!p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_IN_AUTHENTICATE)))) - || (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) - && (!p_dev_rec->is_originator - && (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) - && (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) - { - /* - * We rely on BTM_SEC_16_DIGIT_PIN_AUTHED being set if MITM is in use, - * as 16 DIGIT is only needed if MITM is not used. Unfortunately, the - * BTM_SEC_AUTHENTICATED is used for both MITM and non-MITM - * authenticated connections, hence we cannot distinguish here. - */ +static tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { + BTM_TRACE_EVENT( + "btm_sec_execute_procedure: Required:0x%x Flags:0x%x State:%d", + p_dev_rec->security_required, p_dev_rec->sec_flags, p_dev_rec->sec_state); + + /* There is a chance that we are getting name. Wait until done. */ + if (p_dev_rec->sec_state != 0) return (BTM_CMD_STARTED); + + /* If any security is required, get the name first */ + if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) && + (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) { + BTM_TRACE_EVENT("Security Manager: Start get name"); + if (!btm_sec_start_get_name(p_dev_rec)) { + return (BTM_NO_RESOURCES); + } + return (BTM_CMD_STARTED); + } + + /* If connection is not authenticated and authentication is required */ + /* start authentication and return PENDING to the caller */ + if ((((!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) && + ((p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) || + (!p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_IN_AUTHENTICATE)))) || + (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) && + (!p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) && + (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) { +/* + * We rely on BTM_SEC_16_DIGIT_PIN_AUTHED being set if MITM is in use, + * as 16 DIGIT is only needed if MITM is not used. Unfortunately, the + * BTM_SEC_AUTHENTICATED is used for both MITM and non-MITM + * authenticated connections, hence we cannot distinguish here. + */ #if (L2CAP_UCD_INCLUDED == TRUE) - /* if incoming UCD packet, discard it */ - if ( !p_dev_rec->is_originator && (p_dev_rec->is_ucd == true )) - return(BTM_FAILED_ON_SECURITY); + /* if incoming UCD packet, discard it */ + if (!p_dev_rec->is_originator && (p_dev_rec->is_ucd == true)) + return (BTM_FAILED_ON_SECURITY); #endif - BTM_TRACE_EVENT ("Security Manager: Start authentication"); - - /* - * If we do have a link-key, but we end up here because we need an - * upgrade, then clear the link-key known and authenticated flag before - * restarting authentication. - * WARNING: If the controller has link-key, it is optional and - * recommended for the controller to send a Link_Key_Request. - * In case we need an upgrade, the only alternative would be to delete - * the existing link-key. That could lead to very bad user experience - * or even IOP issues, if a reconnect causes a new connection that - * requires an upgrade. - */ - if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) - && (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) - && (!p_dev_rec->is_originator && (p_dev_rec->security_required - & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) { - p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED - | BTM_SEC_AUTHENTICATED); - } - - btm_sec_start_authentication(p_dev_rec); - return(BTM_CMD_STARTED); - } + BTM_TRACE_EVENT("Security Manager: Start authentication"); - /* If connection is not encrypted and encryption is required */ - /* start encryption and return PENDING to the caller */ - if (!(p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) - && (( p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_OUT_ENCRYPT)) - || (!p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_IN_ENCRYPT))) - && (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) - { + /* + * If we do have a link-key, but we end up here because we need an + * upgrade, then clear the link-key known and authenticated flag before + * restarting authentication. + * WARNING: If the controller has link-key, it is optional and + * recommended for the controller to send a Link_Key_Request. + * In case we need an upgrade, the only alternative would be to delete + * the existing link-key. That could lead to very bad user experience + * or even IOP issues, if a reconnect causes a new connection that + * requires an upgrade. + */ + if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) && + (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) && + (!p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) { + p_dev_rec->sec_flags &= + ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | + BTM_SEC_AUTHENTICATED); + } + + btm_sec_start_authentication(p_dev_rec); + return (BTM_CMD_STARTED); + } + + /* If connection is not encrypted and encryption is required */ + /* start encryption and return PENDING to the caller */ + if (!(p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) && + ((p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_OUT_ENCRYPT)) || + (!p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_IN_ENCRYPT))) && + (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) { #if (L2CAP_UCD_INCLUDED == TRUE) - /* if incoming UCD packet, discard it */ - if ( !p_dev_rec->is_originator && (p_dev_rec->is_ucd == true )) - return(BTM_FAILED_ON_SECURITY); + /* if incoming UCD packet, discard it */ + if (!p_dev_rec->is_originator && (p_dev_rec->is_ucd == true)) + return (BTM_FAILED_ON_SECURITY); #endif - BTM_TRACE_EVENT ("Security Manager: Start encryption"); - - btm_sec_start_encryption(p_dev_rec); - return(BTM_CMD_STARTED); - } - - if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - { - BTM_TRACE_EVENT("%s: Security Manager: SC only service, but link key type is 0x%02x -", - "security failure", __func__, p_dev_rec->link_key_type); - return (BTM_FAILED_ON_SECURITY); - } - - /* If connection is not authorized and authorization is required */ - /* start authorization and return PENDING to the caller */ - if (!(p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED) - && (( p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_OUT_AUTHORIZE)) - || (!p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_IN_AUTHORIZE)))) - { - BTM_TRACE_EVENT ("service id:%d, is trusted:%d", - p_dev_rec->p_cur_service->service_id, - (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, - p_dev_rec->p_cur_service->service_id))); - if ((btm_sec_are_all_trusted(p_dev_rec->trusted_mask) == false) && - (p_dev_rec->p_cur_service->service_id < BTM_SEC_MAX_SERVICES) && - (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, - p_dev_rec->p_cur_service->service_id) == false)) - { - BTM_TRACE_EVENT ("Security Manager: Start authorization"); - return(btm_sec_start_authorization (p_dev_rec)); - } - } - - /* All required security procedures already established */ - p_dev_rec->security_required &= ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_IN_AUTHORIZE | - BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_AUTHENTICATE | - BTM_SEC_OUT_ENCRYPT | BTM_SEC_IN_ENCRYPT | - BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | - BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); - - BTM_TRACE_EVENT ("Security Manager: trusted:0x%04x%04x", p_dev_rec->trusted_mask[1], p_dev_rec->trusted_mask[0]); - BTM_TRACE_EVENT ("Security Manager: access granted"); - - return(BTM_SUCCESS); + BTM_TRACE_EVENT("Security Manager: Start encryption"); + + btm_sec_start_encryption(p_dev_rec); + return (BTM_CMD_STARTED); + } + + if ((p_dev_rec->security_required & BTM_SEC_MODE4_LEVEL4) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { + BTM_TRACE_EVENT( + "%s: Security Manager: SC only service, but link key type is 0x%02x -", + "security failure", __func__, p_dev_rec->link_key_type); + return (BTM_FAILED_ON_SECURITY); + } + + /* If connection is not authorized and authorization is required */ + /* start authorization and return PENDING to the caller */ + if (!(p_dev_rec->sec_flags & BTM_SEC_AUTHORIZED) && + ((p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_OUT_AUTHORIZE)) || + (!p_dev_rec->is_originator && + (p_dev_rec->security_required & BTM_SEC_IN_AUTHORIZE)))) { + BTM_TRACE_EVENT( + "service id:%d, is trusted:%d", p_dev_rec->p_cur_service->service_id, + (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, + p_dev_rec->p_cur_service->service_id))); + if ((btm_sec_are_all_trusted(p_dev_rec->trusted_mask) == false) && + (p_dev_rec->p_cur_service->service_id < BTM_SEC_MAX_SERVICES) && + (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, + p_dev_rec->p_cur_service->service_id) == + false)) { + BTM_TRACE_EVENT("Security Manager: Start authorization"); + return (btm_sec_start_authorization(p_dev_rec)); + } + } + + /* All required security procedures already established */ + p_dev_rec->security_required &= + ~(BTM_SEC_OUT_AUTHORIZE | BTM_SEC_IN_AUTHORIZE | + BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_AUTHENTICATE | + BTM_SEC_OUT_ENCRYPT | BTM_SEC_IN_ENCRYPT | BTM_SEC_FORCE_MASTER | + BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); + + BTM_TRACE_EVENT("Security Manager: trusted:0x%04x%04x", + p_dev_rec->trusted_mask[1], p_dev_rec->trusted_mask[0]); + BTM_TRACE_EVENT("Security Manager: access granted"); + + return (BTM_SUCCESS); } /******************************************************************************* @@ -5425,22 +5298,21 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if started * ******************************************************************************/ -static bool btm_sec_start_get_name (tBTM_SEC_DEV_REC *p_dev_rec) -{ - uint8_t tempstate = p_dev_rec->sec_state; +static bool btm_sec_start_get_name(tBTM_SEC_DEV_REC* p_dev_rec) { + uint8_t tempstate = p_dev_rec->sec_state; - p_dev_rec->sec_state = BTM_SEC_STATE_GETTING_NAME; + p_dev_rec->sec_state = BTM_SEC_STATE_GETTING_NAME; - /* Device should be connected, no need to provide correct page params */ - /* 0 and NULL are as timeout and callback params because they are not used in security get name case */ - if ((btm_initiate_rem_name (p_dev_rec->bd_addr, NULL, BTM_RMT_NAME_SEC, - 0, NULL)) != BTM_CMD_STARTED) - { - p_dev_rec->sec_state = tempstate; - return(false); - } + /* Device should be connected, no need to provide correct page params */ + /* 0 and NULL are as timeout and callback params because they are not used in + * security get name case */ + if ((btm_initiate_rem_name(p_dev_rec->bd_addr, NULL, BTM_RMT_NAME_SEC, 0, + NULL)) != BTM_CMD_STARTED) { + p_dev_rec->sec_state = tempstate; + return (false); + } - return(true); + return (true); } /******************************************************************************* @@ -5450,10 +5322,9 @@ static bool btm_sec_start_get_name (tBTM_SEC_DEV_REC *p_dev_rec) * Description This function is called to start authentication * ******************************************************************************/ -static void btm_sec_start_authentication(tBTM_SEC_DEV_REC *p_dev_rec) -{ - p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; - btsnd_hcic_auth_request(p_dev_rec->hci_handle); +static void btm_sec_start_authentication(tBTM_SEC_DEV_REC* p_dev_rec) { + p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; + btsnd_hcic_auth_request(p_dev_rec->hci_handle); } /******************************************************************************* @@ -5463,10 +5334,9 @@ static void btm_sec_start_authentication(tBTM_SEC_DEV_REC *p_dev_rec) * Description This function is called to start encryption * ******************************************************************************/ -static void btm_sec_start_encryption(tBTM_SEC_DEV_REC *p_dev_rec) -{ - btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); - p_dev_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; +static void btm_sec_start_encryption(tBTM_SEC_DEV_REC* p_dev_rec) { + btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); + p_dev_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; } /******************************************************************************* @@ -5478,64 +5348,59 @@ static void btm_sec_start_encryption(tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if started * ******************************************************************************/ -static uint8_t btm_sec_start_authorization (tBTM_SEC_DEV_REC *p_dev_rec) -{ - uint8_t result; - uint8_t *p_service_name = NULL; - uint8_t service_id; - - if ((p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) - || (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE)) - { - if (!btm_cb.api.p_authorize_callback) - return(BTM_MODE_UNSUPPORTED); +static uint8_t btm_sec_start_authorization(tBTM_SEC_DEV_REC* p_dev_rec) { + uint8_t result; + uint8_t* p_service_name = NULL; + uint8_t service_id; - if (p_dev_rec->p_cur_service) - { + if ((p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || + (p_dev_rec->hci_handle == BTM_SEC_INVALID_HANDLE)) { + if (!btm_cb.api.p_authorize_callback) return (BTM_MODE_UNSUPPORTED); + + if (p_dev_rec->p_cur_service) { #if BTM_SEC_SERVICE_NAME_LEN > 0 - if (p_dev_rec->is_originator) - p_service_name = p_dev_rec->p_cur_service->orig_service_name; - else - p_service_name = p_dev_rec->p_cur_service->term_service_name; + if (p_dev_rec->is_originator) + p_service_name = p_dev_rec->p_cur_service->orig_service_name; + else + p_service_name = p_dev_rec->p_cur_service->term_service_name; #endif - service_id = p_dev_rec->p_cur_service->service_id; - } - else - service_id = 0; - - /* Send authorization request if not already sent during this service connection */ - if (p_dev_rec->last_author_service_id == BTM_SEC_NO_LAST_SERVICE_ID - || p_dev_rec->last_author_service_id != service_id) - { - p_dev_rec->sec_state = BTM_SEC_STATE_AUTHORIZING; - result = (*btm_cb.api.p_authorize_callback) (p_dev_rec->bd_addr, - p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, - p_service_name, - service_id, - p_dev_rec->is_originator); - } + service_id = p_dev_rec->p_cur_service->service_id; + } else + service_id = 0; - else /* Already authorized once for this L2CAP bringup */ - { - BTM_TRACE_DEBUG ("btm_sec_start_authorization: (Ignoring extra Authorization prompt for service %d)", service_id); - return (BTM_SUCCESS); - } + /* Send authorization request if not already sent during this service + * connection */ + if (p_dev_rec->last_author_service_id == BTM_SEC_NO_LAST_SERVICE_ID || + p_dev_rec->last_author_service_id != service_id) { + p_dev_rec->sec_state = BTM_SEC_STATE_AUTHORIZING; + result = (*btm_cb.api.p_authorize_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + p_service_name, service_id, p_dev_rec->is_originator); + } + + else /* Already authorized once for this L2CAP bringup */ + { + BTM_TRACE_DEBUG( + "btm_sec_start_authorization: (Ignoring extra Authorization prompt " + "for service %d)", + service_id); + return (BTM_SUCCESS); + } - if (result == BTM_SUCCESS) - { - p_dev_rec->sec_flags |= BTM_SEC_AUTHORIZED; + if (result == BTM_SUCCESS) { + p_dev_rec->sec_flags |= BTM_SEC_AUTHORIZED; - /* Save the currently authorized service in case we are asked again by another multiplexer layer */ - if (!p_dev_rec->is_originator) - p_dev_rec->last_author_service_id = service_id; + /* Save the currently authorized service in case we are asked again by + * another multiplexer layer */ + if (!p_dev_rec->is_originator) + p_dev_rec->last_author_service_id = service_id; - p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; - } - return(result); + p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; } - btm_sec_start_get_name (p_dev_rec); - return(BTM_CMD_STARTED); + return (result); + } + btm_sec_start_get_name(p_dev_rec); + return (BTM_CMD_STARTED); } /******************************************************************************* @@ -5547,16 +5412,14 @@ static uint8_t btm_sec_start_authorization (tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if all are trusted, otherwise false * ******************************************************************************/ -bool btm_sec_are_all_trusted(uint32_t p_mask[]) -{ - uint32_t trusted_inx; - for (trusted_inx = 0; trusted_inx < BTM_SEC_SERVICE_ARRAY_SIZE; trusted_inx++) - { - if (p_mask[trusted_inx] != BTM_SEC_TRUST_ALL) - return(false); - } - - return(true); +bool btm_sec_are_all_trusted(uint32_t p_mask[]) { + uint32_t trusted_inx; + for (trusted_inx = 0; trusted_inx < BTM_SEC_SERVICE_ARRAY_SIZE; + trusted_inx++) { + if (p_mask[trusted_inx] != BTM_SEC_TRUST_ALL) return (false); + } + + return (true); } /******************************************************************************* @@ -5569,36 +5432,35 @@ bool btm_sec_are_all_trusted(uint32_t p_mask[]) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, uint16_t psm) -{ - tBTM_SEC_SERV_REC *p_serv_rec = &btm_cb.sec_serv_rec[0]; - int i; - bool is_originator; +tBTM_SEC_SERV_REC* btm_sec_find_first_serv(CONNECTION_TYPE conn_type, + uint16_t psm) { + tBTM_SEC_SERV_REC* p_serv_rec = &btm_cb.sec_serv_rec[0]; + int i; + bool is_originator; #if (L2CAP_UCD_INCLUDED == TRUE) - if ( conn_type & CONNECTION_TYPE_ORIG_MASK ) - is_originator = true; - else - is_originator = false; + if (conn_type & CONNECTION_TYPE_ORIG_MASK) + is_originator = true; + else + is_originator = false; #else - is_originator = conn_type; + is_originator = conn_type; #endif - if (is_originator && btm_cb.p_out_serv && btm_cb.p_out_serv->psm == psm) - { - /* If this is outgoing connection and the PSM matches p_out_serv, - * use it as the current service */ - return btm_cb.p_out_serv; - } - - /* otherwise, just find the first record with the specified PSM */ - for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) - { - if ( (p_serv_rec->security_flags & BTM_SEC_IN_USE) && (p_serv_rec->psm == psm) ) - return(p_serv_rec); - } - return(NULL); + if (is_originator && btm_cb.p_out_serv && btm_cb.p_out_serv->psm == psm) { + /* If this is outgoing connection and the PSM matches p_out_serv, + * use it as the current service */ + return btm_cb.p_out_serv; + } + + /* otherwise, just find the first record with the specified PSM */ + for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) { + if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) && + (p_serv_rec->psm == psm)) + return (p_serv_rec); + } + return (NULL); } /******************************************************************************* @@ -5611,23 +5473,19 @@ tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, uint16_t * Returns Pointer to the record or NULL * ******************************************************************************/ -static tBTM_SEC_SERV_REC *btm_sec_find_next_serv (tBTM_SEC_SERV_REC *p_cur) -{ - tBTM_SEC_SERV_REC *p_serv_rec = &btm_cb.sec_serv_rec[0]; - int i; - - for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) - { - if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) - && (p_serv_rec->psm == p_cur->psm) ) - { - if (p_cur != p_serv_rec) - { - return(p_serv_rec); - } - } +static tBTM_SEC_SERV_REC* btm_sec_find_next_serv(tBTM_SEC_SERV_REC* p_cur) { + tBTM_SEC_SERV_REC* p_serv_rec = &btm_cb.sec_serv_rec[0]; + int i; + + for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) { + if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) && + (p_serv_rec->psm == p_cur->psm)) { + if (p_cur != p_serv_rec) { + return (p_serv_rec); + } } - return(NULL); + } + return (NULL); } /******************************************************************************* @@ -5640,36 +5498,33 @@ static tBTM_SEC_SERV_REC *btm_sec_find_next_serv (tBTM_SEC_SERV_REC *p_cur) * Returns Pointer to the record or NULL * ******************************************************************************/ -static tBTM_SEC_SERV_REC *btm_sec_find_mx_serv (uint8_t is_originator, uint16_t psm, - uint32_t mx_proto_id, uint32_t mx_chan_id) -{ - tBTM_SEC_SERV_REC *p_out_serv = btm_cb.p_out_serv; - tBTM_SEC_SERV_REC *p_serv_rec = &btm_cb.sec_serv_rec[0]; - int i; - - BTM_TRACE_DEBUG ("%s()", __func__); - if (is_originator && p_out_serv && p_out_serv->psm == psm - && p_out_serv->mx_proto_id == mx_proto_id - && p_out_serv->orig_mx_chan_id == mx_chan_id) - { - /* If this is outgoing connection and the parameters match p_out_serv, - * use it as the current service */ - return btm_cb.p_out_serv; - } - - /* otherwise, the old way */ - for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) - { - if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) - && (p_serv_rec->psm == psm) - && (p_serv_rec->mx_proto_id == mx_proto_id) - && (( is_originator && (p_serv_rec->orig_mx_chan_id == mx_chan_id)) - || (!is_originator && (p_serv_rec->term_mx_chan_id == mx_chan_id)))) - { - return(p_serv_rec); - } - } - return(NULL); +static tBTM_SEC_SERV_REC* btm_sec_find_mx_serv(uint8_t is_originator, + uint16_t psm, + uint32_t mx_proto_id, + uint32_t mx_chan_id) { + tBTM_SEC_SERV_REC* p_out_serv = btm_cb.p_out_serv; + tBTM_SEC_SERV_REC* p_serv_rec = &btm_cb.sec_serv_rec[0]; + int i; + + BTM_TRACE_DEBUG("%s()", __func__); + if (is_originator && p_out_serv && p_out_serv->psm == psm && + p_out_serv->mx_proto_id == mx_proto_id && + p_out_serv->orig_mx_chan_id == mx_chan_id) { + /* If this is outgoing connection and the parameters match p_out_serv, + * use it as the current service */ + return btm_cb.p_out_serv; + } + + /* otherwise, the old way */ + for (i = 0; i < BTM_SEC_MAX_SERVICE_RECORDS; i++, p_serv_rec++) { + if ((p_serv_rec->security_flags & BTM_SEC_IN_USE) && + (p_serv_rec->psm == psm) && (p_serv_rec->mx_proto_id == mx_proto_id) && + ((is_originator && (p_serv_rec->orig_mx_chan_id == mx_chan_id)) || + (!is_originator && (p_serv_rec->term_mx_chan_id == mx_chan_id)))) { + return (p_serv_rec); + } + } + return (NULL); } /******************************************************************************* @@ -5682,18 +5537,17 @@ static tBTM_SEC_SERV_REC *btm_sec_find_mx_serv (uint8_t is_originator, uint16_t * Returns Pointer to the TLE struct * ******************************************************************************/ -static void btm_sec_collision_timeout(UNUSED_ATTR void *data) -{ - BTM_TRACE_EVENT ("%s()", __func__); +static void btm_sec_collision_timeout(UNUSED_ATTR void* data) { + BTM_TRACE_EVENT("%s()", __func__); - tBTM_STATUS status = btm_sec_execute_procedure (btm_cb.p_collided_dev_rec); + tBTM_STATUS status = btm_sec_execute_procedure(btm_cb.p_collided_dev_rec); - /* If result is pending reply from the user or from the device is pending */ - if (status != BTM_CMD_STARTED) - { - /* There is no next procedure or start of procedure failed, notify the waiting layer */ - btm_sec_dev_rec_cback_event (btm_cb.p_collided_dev_rec, status, false); - } + /* If result is pending reply from the user or from the device is pending */ + if (status != BTM_CMD_STARTED) { + /* There is no next procedure or start of procedure failed, notify the + * waiting layer */ + btm_sec_dev_rec_cback_event(btm_cb.p_collided_dev_rec, status, false); + } } /******************************************************************************* @@ -5705,12 +5559,11 @@ static void btm_sec_collision_timeout(UNUSED_ATTR void *data) * Returns Pointer to the record or NULL * ******************************************************************************/ -static void btm_send_link_key_notif (tBTM_SEC_DEV_REC *p_dev_rec) -{ - if (btm_cb.api.p_link_key_callback) - (*btm_cb.api.p_link_key_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, p_dev_rec->link_key, - p_dev_rec->link_key_type); +static void btm_send_link_key_notif(tBTM_SEC_DEV_REC* p_dev_rec) { + if (btm_cb.api.p_link_key_callback) + (*btm_cb.api.p_link_key_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + p_dev_rec->link_key, p_dev_rec->link_key_type); } /******************************************************************************* @@ -5725,12 +5578,10 @@ static void btm_send_link_key_notif (tBTM_SEC_DEV_REC *p_dev_rec) * otherwise, the trusted mask * ******************************************************************************/ -uint32_t * BTM_ReadTrustedMask (BD_ADDR bd_addr) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - if (p_dev_rec != NULL) - return(p_dev_rec->trusted_mask); - return NULL; +uint32_t* BTM_ReadTrustedMask(BD_ADDR bd_addr) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if (p_dev_rec != NULL) return (p_dev_rec->trusted_mask); + return NULL; } /******************************************************************************* @@ -5744,32 +5595,28 @@ uint32_t * BTM_ReadTrustedMask (BD_ADDR bd_addr) * Parameters: void * ******************************************************************************/ -static void btm_restore_mode(void) -{ - if (btm_cb.security_mode_changed) - { - btm_cb.security_mode_changed = false; - BTM_TRACE_DEBUG("%s() Auth enable -> %d", __func__, (btm_cb.security_mode == BTM_SEC_MODE_LINK)); - btsnd_hcic_write_auth_enable ((uint8_t)(btm_cb.security_mode == BTM_SEC_MODE_LINK)); - } - - if (btm_cb.pin_type_changed) - { - btm_cb.pin_type_changed = false; - btsnd_hcic_write_pin_type (btm_cb.cfg.pin_type); - } +static void btm_restore_mode(void) { + if (btm_cb.security_mode_changed) { + btm_cb.security_mode_changed = false; + BTM_TRACE_DEBUG("%s() Auth enable -> %d", __func__, + (btm_cb.security_mode == BTM_SEC_MODE_LINK)); + btsnd_hcic_write_auth_enable( + (uint8_t)(btm_cb.security_mode == BTM_SEC_MODE_LINK)); + } + + if (btm_cb.pin_type_changed) { + btm_cb.pin_type_changed = false; + btsnd_hcic_write_pin_type(btm_cb.cfg.pin_type); + } } +bool is_sec_state_equal(void* data, void* context) { + tBTM_SEC_DEV_REC* p_dev_rec = static_cast(data); + uint8_t* state = static_cast(context); -bool is_sec_state_equal(void *data, void *context) -{ - tBTM_SEC_DEV_REC *p_dev_rec = static_cast(data); - uint8_t *state = static_cast(context); - - if (p_dev_rec->sec_state == *state) - return false; + if (p_dev_rec->sec_state == *state) return false; - return true; + return true; } /******************************************************************************* @@ -5782,13 +5629,11 @@ bool is_sec_state_equal(void *data, void *context) * Returns Pointer to the record or NULL * ******************************************************************************/ -tBTM_SEC_DEV_REC *btm_sec_find_dev_by_sec_state (uint8_t state) -{ - list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_sec_state_equal, &state); - if (n) - return static_cast(list_node(n)); +tBTM_SEC_DEV_REC* btm_sec_find_dev_by_sec_state(uint8_t state) { + list_node_t* n = list_foreach(btm_cb.sec_dev_rec, is_sec_state_equal, &state); + if (n) return static_cast(list_node(n)); - return NULL; + return NULL; } /******************************************************************************* @@ -5798,43 +5643,38 @@ tBTM_SEC_DEV_REC *btm_sec_find_dev_by_sec_state (uint8_t state) * Description This function is called to change pairing state * ******************************************************************************/ -static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state) -{ - tBTM_PAIRING_STATE old_state = btm_cb.pairing_state; +static void btm_sec_change_pairing_state(tBTM_PAIRING_STATE new_state) { + tBTM_PAIRING_STATE old_state = btm_cb.pairing_state; - BTM_TRACE_EVENT ("%s() Old: %s", __func__, btm_pair_state_descr(btm_cb.pairing_state)); - BTM_TRACE_EVENT ("%s() New: %s pairing_flags:0x%x", __func__, - btm_pair_state_descr(new_state), btm_cb.pairing_flags); + BTM_TRACE_EVENT("%s() Old: %s", __func__, + btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_EVENT("%s() New: %s pairing_flags:0x%x", __func__, + btm_pair_state_descr(new_state), btm_cb.pairing_flags); - btm_cb.pairing_state = new_state; + btm_cb.pairing_state = new_state; - if (new_state == BTM_PAIR_STATE_IDLE) - { - alarm_cancel(btm_cb.pairing_timer); + if (new_state == BTM_PAIR_STATE_IDLE) { + alarm_cancel(btm_cb.pairing_timer); - btm_cb.pairing_flags = 0; - btm_cb.pin_code_len = 0; + btm_cb.pairing_flags = 0; + btm_cb.pin_code_len = 0; - /* Make sure the the lcb shows we are not bonding */ - l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, false); + /* Make sure the the lcb shows we are not bonding */ + l2cu_update_lcb_4_bonding(btm_cb.pairing_bda, false); - btm_restore_mode(); - btm_sec_check_pending_reqs(); - btm_inq_clear_ssp(); + btm_restore_mode(); + btm_sec_check_pending_reqs(); + btm_inq_clear_ssp(); - memset (btm_cb.pairing_bda, 0xFF, BD_ADDR_LEN); - } - else - { - /* If transitioning out of idle, mark the lcb as bonding */ - if (old_state == BTM_PAIR_STATE_IDLE) - l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, true); + memset(btm_cb.pairing_bda, 0xFF, BD_ADDR_LEN); + } else { + /* If transitioning out of idle, mark the lcb as bonding */ + if (old_state == BTM_PAIR_STATE_IDLE) + l2cu_update_lcb_4_bonding(btm_cb.pairing_bda, true); - alarm_set_on_queue(btm_cb.pairing_timer, - BTM_SEC_TIMEOUT_VALUE * 1000, - btm_sec_pairing_timeout, NULL, - btu_general_alarm_queue); - } + alarm_set_on_queue(btm_cb.pairing_timer, BTM_SEC_TIMEOUT_VALUE * 1000, + btm_sec_pairing_timeout, NULL, btu_general_alarm_queue); + } } /******************************************************************************* @@ -5844,24 +5684,33 @@ static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state) * Description Return state description for tracing * ******************************************************************************/ -static const char *btm_pair_state_descr (tBTM_PAIRING_STATE state) -{ - switch (state) - { - case BTM_PAIR_STATE_IDLE: return("IDLE"); - case BTM_PAIR_STATE_GET_REM_NAME: return("GET_REM_NAME"); - case BTM_PAIR_STATE_WAIT_PIN_REQ: return("WAIT_PIN_REQ"); - case BTM_PAIR_STATE_WAIT_LOCAL_PIN: return("WAIT_LOCAL_PIN"); - case BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM: return("WAIT_NUM_CONFIRM"); - case BTM_PAIR_STATE_KEY_ENTRY: return("KEY_ENTRY"); - case BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP: return("WAIT_LOCAL_OOB_RSP"); - case BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS: return("WAIT_LOCAL_IOCAPS"); - case BTM_PAIR_STATE_INCOMING_SSP: return("INCOMING_SSP"); - case BTM_PAIR_STATE_WAIT_AUTH_COMPLETE: return("WAIT_AUTH_COMPLETE"); - case BTM_PAIR_STATE_WAIT_DISCONNECT: return("WAIT_DISCONNECT"); - } - - return("???"); +static const char* btm_pair_state_descr(tBTM_PAIRING_STATE state) { + switch (state) { + case BTM_PAIR_STATE_IDLE: + return ("IDLE"); + case BTM_PAIR_STATE_GET_REM_NAME: + return ("GET_REM_NAME"); + case BTM_PAIR_STATE_WAIT_PIN_REQ: + return ("WAIT_PIN_REQ"); + case BTM_PAIR_STATE_WAIT_LOCAL_PIN: + return ("WAIT_LOCAL_PIN"); + case BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM: + return ("WAIT_NUM_CONFIRM"); + case BTM_PAIR_STATE_KEY_ENTRY: + return ("KEY_ENTRY"); + case BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP: + return ("WAIT_LOCAL_OOB_RSP"); + case BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS: + return ("WAIT_LOCAL_IOCAPS"); + case BTM_PAIR_STATE_INCOMING_SSP: + return ("INCOMING_SSP"); + case BTM_PAIR_STATE_WAIT_AUTH_COMPLETE: + return ("WAIT_AUTH_COMPLETE"); + case BTM_PAIR_STATE_WAIT_DISCONNECT: + return ("WAIT_DISCONNECT"); + } + + return ("???"); } /******************************************************************************* @@ -5874,21 +5723,22 @@ static const char *btm_pair_state_descr (tBTM_PAIRING_STATE state) * Parameters: void * ******************************************************************************/ -void btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, uint8_t res, bool is_le_transport) -{ - tBTM_SEC_CALLBACK *p_callback = p_dev_rec->p_callback; +void btm_sec_dev_rec_cback_event(tBTM_SEC_DEV_REC* p_dev_rec, uint8_t res, + bool is_le_transport) { + tBTM_SEC_CALLBACK* p_callback = p_dev_rec->p_callback; - if (p_dev_rec->p_callback) - { - p_dev_rec->p_callback = NULL; + if (p_dev_rec->p_callback) { + p_dev_rec->p_callback = NULL; - if (is_le_transport) - (*p_callback) (p_dev_rec->ble.pseudo_addr, BT_TRANSPORT_LE, p_dev_rec->p_ref_data, res); - else - (*p_callback) (p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, p_dev_rec->p_ref_data, res); - } + if (is_le_transport) + (*p_callback)(p_dev_rec->ble.pseudo_addr, BT_TRANSPORT_LE, + p_dev_rec->p_ref_data, res); + else + (*p_callback)(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, + p_dev_rec->p_ref_data, res); + } - btm_sec_check_pending_reqs(); + btm_sec_check_pending_reqs(); } /******************************************************************************* @@ -5898,80 +5748,81 @@ void btm_sec_dev_rec_cback_event (tBTM_SEC_DEV_REC *p_dev_rec, uint8_t res, bool * Description Return state description for tracing * ******************************************************************************/ -static bool btm_sec_queue_mx_request (BD_ADDR bd_addr, uint16_t psm, bool is_orig, - uint32_t mx_proto_id, uint32_t mx_chan_id, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data) -{ - tBTM_SEC_QUEUE_ENTRY *p_e = (tBTM_SEC_QUEUE_ENTRY *)osi_malloc(sizeof(tBTM_SEC_QUEUE_ENTRY)); - - p_e->psm = psm; - p_e->is_orig = is_orig; - p_e->p_callback = p_callback; - p_e->p_ref_data = p_ref_data; - p_e->mx_proto_id = mx_proto_id; - p_e->mx_chan_id = mx_chan_id; - p_e->transport = BT_TRANSPORT_BR_EDR; - p_e->sec_act = 0; - - memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); - - BTM_TRACE_EVENT("%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u", - __func__, psm, is_orig, mx_proto_id, mx_chan_id); - - fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); - - return true; +static bool btm_sec_queue_mx_request(BD_ADDR bd_addr, uint16_t psm, + bool is_orig, uint32_t mx_proto_id, + uint32_t mx_chan_id, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data) { + tBTM_SEC_QUEUE_ENTRY* p_e = + (tBTM_SEC_QUEUE_ENTRY*)osi_malloc(sizeof(tBTM_SEC_QUEUE_ENTRY)); + + p_e->psm = psm; + p_e->is_orig = is_orig; + p_e->p_callback = p_callback; + p_e->p_ref_data = p_ref_data; + p_e->mx_proto_id = mx_proto_id; + p_e->mx_chan_id = mx_chan_id; + p_e->transport = BT_TRANSPORT_BR_EDR; + p_e->sec_act = 0; + + memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); + + BTM_TRACE_EVENT( + "%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u", + __func__, psm, is_orig, mx_proto_id, mx_chan_id); + + fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); + + return true; } -static bool btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) -{ - uint8_t major = (uint8_t)(p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK); - uint8_t minor = (uint8_t)(p_dev_rec->dev_class[2] & BTM_COD_MINOR_CLASS_MASK); - bool rv = false; - - if ((major == BTM_COD_MAJOR_AUDIO) - && ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || (minor == BTM_COD_MINOR_CAR_AUDIO)) ) - { - BTM_TRACE_EVENT ("%s() Skipping pre-fetch PIN for carkit COD Major: 0x%02x Minor: 0x%02x", - __func__, major, minor); - - if (btm_cb.security_mode_changed == false) - { - btm_cb.security_mode_changed = true; +static bool btm_sec_check_prefetch_pin(tBTM_SEC_DEV_REC* p_dev_rec) { + uint8_t major = (uint8_t)(p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK); + uint8_t minor = (uint8_t)(p_dev_rec->dev_class[2] & BTM_COD_MINOR_CLASS_MASK); + bool rv = false; + + if ((major == BTM_COD_MAJOR_AUDIO) && + ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || + (minor == BTM_COD_MINOR_CAR_AUDIO))) { + BTM_TRACE_EVENT( + "%s() Skipping pre-fetch PIN for carkit COD Major: 0x%02x Minor: " + "0x%02x", + __func__, major, minor); + + if (btm_cb.security_mode_changed == false) { + btm_cb.security_mode_changed = true; #ifdef APPL_AUTH_WRITE_EXCEPTION - if(!(APPL_AUTH_WRITE_EXCEPTION)(p_dev_rec->bd_addr)) + if (!(APPL_AUTH_WRITE_EXCEPTION)(p_dev_rec->bd_addr)) #endif - btsnd_hcic_write_auth_enable (true); - } + btsnd_hcic_write_auth_enable(true); } - else - { - btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_LOCAL_PIN); - - /* If we got a PIN, use that, else try to get one */ - if (btm_cb.pin_code_len) - { - BTM_PINCodeReply (p_dev_rec->bd_addr, BTM_SUCCESS, btm_cb.pin_code_len, btm_cb.pin_code, p_dev_rec->trusted_mask); - } - else - { - /* pin was not supplied - pre-fetch pin code now */ - if (btm_cb.api.p_pin_callback && ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0)) - { - BTM_TRACE_DEBUG("%s() PIN code callback called", __func__); - if (btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR) == NULL) - btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; - (btm_cb.api.p_pin_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, - p_dev_rec->sec_bd_name, (p_dev_rec->p_cur_service == NULL) ? false - : (p_dev_rec->p_cur_service->security_flags - & BTM_SEC_IN_MIN_16_DIGIT_PIN)); - } - } + } else { + btm_sec_change_pairing_state(BTM_PAIR_STATE_WAIT_LOCAL_PIN); - rv = true; + /* If we got a PIN, use that, else try to get one */ + if (btm_cb.pin_code_len) { + BTM_PINCodeReply(p_dev_rec->bd_addr, BTM_SUCCESS, btm_cb.pin_code_len, + btm_cb.pin_code, p_dev_rec->trusted_mask); + } else { + /* pin was not supplied - pre-fetch pin code now */ + if (btm_cb.api.p_pin_callback && + ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0)) { + BTM_TRACE_DEBUG("%s() PIN code callback called", __func__); + if (btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR) == NULL) + btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; + (btm_cb.api.p_pin_callback)( + p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, + (p_dev_rec->p_cur_service == NULL) + ? false + : (p_dev_rec->p_cur_service->security_flags & + BTM_SEC_IN_MIN_16_DIGIT_PIN)); + } } - return rv; + rv = true; + } + + return rv; } /******************************************************************************* @@ -5985,15 +5836,15 @@ static bool btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) * changed via the BTM_SecSetAuthPayloadTimeout() function. * ******************************************************************************/ -void btm_sec_auth_payload_tout (uint8_t *p, uint16_t hci_evt_len) -{ - uint16_t handle; +void btm_sec_auth_payload_tout(uint8_t* p, uint16_t hci_evt_len) { + uint16_t handle; - STREAM_TO_UINT16 (handle, p); - handle = HCID_GET_HANDLE (handle); + STREAM_TO_UINT16(handle, p); + handle = HCID_GET_HANDLE(handle); - /* Will be exposed to upper layers in the future if/when determined necessary */ - BTM_TRACE_ERROR ("%s on handle 0x%02x", __func__, handle); + /* Will be exposed to upper layers in the future if/when determined necessary + */ + BTM_TRACE_ERROR("%s on handle 0x%02x", __func__, handle); } /******************************************************************************* @@ -6004,22 +5855,23 @@ void btm_sec_auth_payload_tout (uint8_t *p, uint16_t hci_evt_len) * process pending. * ******************************************************************************/ -static bool btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT transport, - tBTM_SEC_CALLBACK *p_callback, void *p_ref_data, - tBTM_BLE_SEC_ACT sec_act) -{ - tBTM_SEC_QUEUE_ENTRY *p_e = - (tBTM_SEC_QUEUE_ENTRY *)osi_malloc(sizeof(tBTM_SEC_QUEUE_ENTRY) + 1); - - p_e->psm = 0; /* if PSM 0, encryption request */ - p_e->p_callback = p_callback; - p_e->p_ref_data = p_ref_data; - p_e->transport = transport; - p_e->sec_act = sec_act; - memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); - fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); - - return true; +static bool btm_sec_queue_encrypt_request(BD_ADDR bd_addr, + tBT_TRANSPORT transport, + tBTM_SEC_CALLBACK* p_callback, + void* p_ref_data, + tBTM_BLE_SEC_ACT sec_act) { + tBTM_SEC_QUEUE_ENTRY* p_e = + (tBTM_SEC_QUEUE_ENTRY*)osi_malloc(sizeof(tBTM_SEC_QUEUE_ENTRY) + 1); + + p_e->psm = 0; /* if PSM 0, encryption request */ + p_e->p_callback = p_callback; + p_e->p_ref_data = p_ref_data; + p_e->transport = transport; + p_e->sec_act = sec_act; + memcpy(p_e->bd_addr, bd_addr, BD_ADDR_LEN); + fixed_queue_enqueue(btm_cb.sec_pending_q, p_e); + + return true; } /******************************************************************************* @@ -6032,39 +5884,38 @@ static bool btm_sec_queue_encrypt_request (BD_ADDR bd_addr, tBT_TRANSPORT tra * Returns void * ******************************************************************************/ -void btm_sec_set_peer_sec_caps(tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec) -{ - BD_ADDR rem_bd_addr; - uint8_t *p_rem_bd_addr; - - if ((btm_cb.security_mode == BTM_SEC_MODE_SP || - btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || - btm_cb.security_mode == BTM_SEC_MODE_SC) && - HCI_SSP_HOST_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1])) - { - p_dev_rec->sm4 = BTM_SM4_TRUE; - p_dev_rec->remote_supports_secure_connections = - (HCI_SC_HOST_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1])); - } - else - { - p_dev_rec->sm4 = BTM_SM4_KNOWN; - p_dev_rec->remote_supports_secure_connections = false; - } - - BTM_TRACE_API("%s: sm4: 0x%02x, rmt_support_for_secure_connections %d", __func__, - p_dev_rec->sm4, p_dev_rec->remote_supports_secure_connections); - - if (p_dev_rec->remote_features_needed) - { - BTM_TRACE_EVENT("%s: Now device in SC Only mode, waiting for peer remote features!", - __func__); - p_rem_bd_addr = (uint8_t*) rem_bd_addr; - BDADDR_TO_STREAM(p_rem_bd_addr, p_dev_rec->bd_addr); - p_rem_bd_addr = (uint8_t*) rem_bd_addr; - btm_io_capabilities_req(p_rem_bd_addr); - p_dev_rec->remote_features_needed = false; - } +void btm_sec_set_peer_sec_caps(tACL_CONN* p_acl_cb, + tBTM_SEC_DEV_REC* p_dev_rec) { + BD_ADDR rem_bd_addr; + uint8_t* p_rem_bd_addr; + + if ((btm_cb.security_mode == BTM_SEC_MODE_SP || + btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG || + btm_cb.security_mode == BTM_SEC_MODE_SC) && + HCI_SSP_HOST_SUPPORTED( + p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1])) { + p_dev_rec->sm4 = BTM_SM4_TRUE; + p_dev_rec->remote_supports_secure_connections = (HCI_SC_HOST_SUPPORTED( + p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1])); + } else { + p_dev_rec->sm4 = BTM_SM4_KNOWN; + p_dev_rec->remote_supports_secure_connections = false; + } + + BTM_TRACE_API("%s: sm4: 0x%02x, rmt_support_for_secure_connections %d", + __func__, p_dev_rec->sm4, + p_dev_rec->remote_supports_secure_connections); + + if (p_dev_rec->remote_features_needed) { + BTM_TRACE_EVENT( + "%s: Now device in SC Only mode, waiting for peer remote features!", + __func__); + p_rem_bd_addr = (uint8_t*)rem_bd_addr; + BDADDR_TO_STREAM(p_rem_bd_addr, p_dev_rec->bd_addr); + p_rem_bd_addr = (uint8_t*)rem_bd_addr; + btm_io_capabilities_req(p_rem_bd_addr); + p_dev_rec->remote_features_needed = false; + } } /******************************************************************************* @@ -6077,14 +5928,12 @@ void btm_sec_set_peer_sec_caps(tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec) * Returns true if the service is security mode 4 level 0 service * ******************************************************************************/ -static bool btm_sec_is_serv_level0(uint16_t psm) -{ - if (psm == BT_PSM_SDP) - { - BTM_TRACE_DEBUG("%s: PSM: 0x%04x -> mode 4 level 0 service", __func__, psm); - return true; - } - return false; +static bool btm_sec_is_serv_level0(uint16_t psm) { + if (psm == BT_PSM_SDP) { + BTM_TRACE_DEBUG("%s: PSM: 0x%04x -> mode 4 level 0 service", __func__, psm); + return true; + } + return false; } /******************************************************************************* @@ -6097,33 +5946,31 @@ static bool btm_sec_is_serv_level0(uint16_t psm) * Returns void * ******************************************************************************/ -static void btm_sec_check_pending_enc_req (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRANSPORT transport, - uint8_t encr_enable) -{ - if (fixed_queue_is_empty(btm_cb.sec_pending_q)) - return; - - uint8_t res = encr_enable ? BTM_SUCCESS : BTM_ERR_PROCESSING; - list_t *list = fixed_queue_get_list(btm_cb.sec_pending_q); - for (const list_node_t *node = list_begin(list); node != list_end(list); ) { - tBTM_SEC_QUEUE_ENTRY *p_e = (tBTM_SEC_QUEUE_ENTRY *)list_node(node); - node = list_next(node); - - if (memcmp(p_e->bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0 && - p_e->psm == 0 && p_e->transport == transport) - { - if (encr_enable == 0 || transport == BT_TRANSPORT_BR_EDR || - p_e->sec_act == BTM_BLE_SEC_ENCRYPT || - p_e->sec_act == BTM_BLE_SEC_ENCRYPT_NO_MITM || - (p_e->sec_act == BTM_BLE_SEC_ENCRYPT_MITM && p_dev_rec->sec_flags - & BTM_SEC_LE_AUTHENTICATED)) - { - if (p_e->p_callback) - (*p_e->p_callback) (p_dev_rec->bd_addr, transport, p_e->p_ref_data, res); - fixed_queue_try_remove_from_queue(btm_cb.sec_pending_q, (void *)p_e); - } - } +static void btm_sec_check_pending_enc_req(tBTM_SEC_DEV_REC* p_dev_rec, + tBT_TRANSPORT transport, + uint8_t encr_enable) { + if (fixed_queue_is_empty(btm_cb.sec_pending_q)) return; + + uint8_t res = encr_enable ? BTM_SUCCESS : BTM_ERR_PROCESSING; + list_t* list = fixed_queue_get_list(btm_cb.sec_pending_q); + for (const list_node_t* node = list_begin(list); node != list_end(list);) { + tBTM_SEC_QUEUE_ENTRY* p_e = (tBTM_SEC_QUEUE_ENTRY*)list_node(node); + node = list_next(node); + + if (memcmp(p_e->bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN) == 0 && + p_e->psm == 0 && p_e->transport == transport) { + if (encr_enable == 0 || transport == BT_TRANSPORT_BR_EDR || + p_e->sec_act == BTM_BLE_SEC_ENCRYPT || + p_e->sec_act == BTM_BLE_SEC_ENCRYPT_NO_MITM || + (p_e->sec_act == BTM_BLE_SEC_ENCRYPT_MITM && + p_dev_rec->sec_flags & BTM_SEC_LE_AUTHENTICATED)) { + if (p_e->p_callback) + (*p_e->p_callback)(p_dev_rec->bd_addr, transport, p_e->p_ref_data, + res); + fixed_queue_try_remove_from_queue(btm_cb.sec_pending_q, (void*)p_e); + } } + } } /******************************************************************************* @@ -6137,11 +5984,12 @@ static void btm_sec_check_pending_enc_req (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRA * connections only mode. * ******************************************************************************/ -static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security, bool is_originator) -{ - uint16_t sec_level4_flags = is_originator ? BTM_SEC_OUT_LEVEL4_FLAGS : BTM_SEC_IN_LEVEL4_FLAGS; +static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security, + bool is_originator) { + uint16_t sec_level4_flags = + is_originator ? BTM_SEC_OUT_LEVEL4_FLAGS : BTM_SEC_IN_LEVEL4_FLAGS; - return cur_security | sec_level4_flags; + return cur_security | sec_level4_flags; } /******************************************************************************* @@ -6155,15 +6003,13 @@ static uint16_t btm_sec_set_serv_level4_flags(uint16_t cur_security, bool is_ * Returns void * ******************************************************************************/ -void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) -{ - - BTM_TRACE_DEBUG ("%s() Clearing BLE Keys", __func__); - p_dev_rec->ble.key_type = BTM_LE_KEY_NONE; - memset (&p_dev_rec->ble.keys, 0, sizeof(tBTM_SEC_BLE_KEYS)); +void btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC* p_dev_rec) { + BTM_TRACE_DEBUG("%s() Clearing BLE Keys", __func__); + p_dev_rec->ble.key_type = BTM_LE_KEY_NONE; + memset(&p_dev_rec->ble.keys, 0, sizeof(tBTM_SEC_BLE_KEYS)); #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_resolving_list_remove_dev(p_dev_rec); + btm_ble_resolving_list_remove_dev(p_dev_rec); #endif } @@ -6176,20 +6022,17 @@ void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) * Returns true - dev is bonded * ******************************************************************************/ -bool btm_sec_is_a_bonded_dev (BD_ADDR bda) -{ - - tBTM_SEC_DEV_REC *p_dev_rec= btm_find_dev (bda); - bool is_bonded= false; - - if (p_dev_rec && - ((p_dev_rec->ble.key_type && (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN))|| - (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN))) - { - is_bonded = true; - } - BTM_TRACE_DEBUG ("%s() is_bonded=%d", __func__, is_bonded); - return(is_bonded); +bool btm_sec_is_a_bonded_dev(BD_ADDR bda) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + bool is_bonded = false; + + if (p_dev_rec && ((p_dev_rec->ble.key_type && + (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN)) || + (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN))) { + is_bonded = true; + } + BTM_TRACE_DEBUG("%s() is_bonded=%d", __func__, is_bonded); + return (is_bonded); } /******************************************************************************* @@ -6201,14 +6044,14 @@ bool btm_sec_is_a_bonded_dev (BD_ADDR bda) * Returns true - dev is a dual mode * ******************************************************************************/ -bool btm_sec_is_le_capable_dev (BD_ADDR bda) -{ - tBTM_SEC_DEV_REC *p_dev_rec= btm_find_dev (bda); - bool le_capable = false; - - if (p_dev_rec && (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) - le_capable = true; - return le_capable; +bool btm_sec_is_le_capable_dev(BD_ADDR bda) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + bool le_capable = false; + + if (p_dev_rec && + (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) + le_capable = true; + return le_capable; } /******************************************************************************* @@ -6225,25 +6068,23 @@ bool btm_sec_is_le_capable_dev (BD_ADDR bda) * Manager over BR). * ******************************************************************************/ -static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC *p_dev_rec) -{ - uint32_t ext_feat; - uint8_t chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; +static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC* p_dev_rec) { + uint32_t ext_feat; + uint8_t chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; - BTM_TRACE_DEBUG ("%s() link_key_type = 0x%x", __func__, - p_dev_rec->link_key_type); + BTM_TRACE_DEBUG("%s() link_key_type = 0x%x", __func__, + p_dev_rec->link_key_type); - if ((p_dev_rec->link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256) && - (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) - return false; + if ((p_dev_rec->link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256) && + (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) + return false; - if (!L2CA_GetPeerFeatures (p_dev_rec->bd_addr, &ext_feat, chnl_mask)) - return false; + if (!L2CA_GetPeerFeatures(p_dev_rec->bd_addr, &ext_feat, chnl_mask)) + return false; - if (!(chnl_mask[0] & L2CAP_FIXED_CHNL_SMP_BR_BIT)) - return false; + if (!(chnl_mask[0] & L2CAP_FIXED_CHNL_SMP_BR_BIT)) return false; - return true; + return true; } /******************************************************************************* @@ -6256,9 +6097,7 @@ static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC *p_dev_rec) * Returns true - if the device is master. * ******************************************************************************/ -static bool btm_sec_is_master(tBTM_SEC_DEV_REC *p_dev_rec) -{ - tACL_CONN *p= btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR); - return (p && (p->link_role == BTM_ROLE_MASTER)); +static bool btm_sec_is_master(tBTM_SEC_DEV_REC* p_dev_rec) { + tACL_CONN* p = btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR); + return (p && (p->link_role == BTM_ROLE_MASTER)); } - diff --git a/stack/btu/btu_hcif.cc b/stack/btu/btu_hcif.cc index 2b2307515..7e1ceddfb 100644 --- a/stack/btu/btu_hcif.cc +++ b/stack/btu/btu_hcif.cc @@ -32,96 +32,97 @@ #include #include -#include "device/include/controller.h" -#include "osi/include/log.h" -#include "osi/include/osi.h" +#include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" #include "btu.h" -#include "bt_common.h" +#include "device/include/controller.h" #include "hci_layer.h" #include "hcimsgs.h" #include "l2c_int.h" +#include "osi/include/log.h" +#include "osi/include/osi.h" // TODO(zachoverflow): remove this horrible hack #include "btu.h" -extern fixed_queue_t *btu_hci_msg_queue; +extern fixed_queue_t* btu_hci_msg_queue; extern void btm_process_cancel_complete(uint8_t status, uint8_t mode); -extern void btm_ble_test_command_complete(uint8_t *p); +extern void btm_ble_test_command_complete(uint8_t* p); /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void btu_hcif_inquiry_comp_evt (uint8_t *p); -static void btu_hcif_inquiry_result_evt (uint8_t *p); -static void btu_hcif_inquiry_rssi_result_evt (uint8_t *p); -static void btu_hcif_extended_inquiry_result_evt (uint8_t *p); - -static void btu_hcif_connection_comp_evt (uint8_t *p); -static void btu_hcif_connection_request_evt (uint8_t *p); -static void btu_hcif_disconnection_comp_evt (uint8_t *p); -static void btu_hcif_authentication_comp_evt (uint8_t *p); -static void btu_hcif_rmt_name_request_comp_evt (uint8_t *p, uint16_t evt_len); -static void btu_hcif_encryption_change_evt (uint8_t *p); -static void btu_hcif_read_rmt_features_comp_evt (uint8_t *p); -static void btu_hcif_read_rmt_ext_features_comp_evt (uint8_t *p); -static void btu_hcif_read_rmt_version_comp_evt (uint8_t *p); -static void btu_hcif_qos_setup_comp_evt (uint8_t *p); -static void btu_hcif_command_complete_evt (BT_HDR *response, void *context); -static void btu_hcif_command_status_evt (uint8_t status, BT_HDR *command, void *context); -static void btu_hcif_hardware_error_evt (uint8_t *p); -static void btu_hcif_flush_occured_evt (void); -static void btu_hcif_role_change_evt (uint8_t *p); -static void btu_hcif_num_compl_data_pkts_evt (uint8_t *p); -static void btu_hcif_mode_change_evt (uint8_t *p); -static void btu_hcif_pin_code_request_evt (uint8_t *p); -static void btu_hcif_link_key_request_evt (uint8_t *p); -static void btu_hcif_link_key_notification_evt (uint8_t *p); -static void btu_hcif_loopback_command_evt (void); -static void btu_hcif_data_buf_overflow_evt (void); -static void btu_hcif_max_slots_changed_evt (void); -static void btu_hcif_read_clock_off_comp_evt (uint8_t *p); -static void btu_hcif_conn_pkt_type_change_evt (void); -static void btu_hcif_qos_violation_evt (uint8_t *p); -static void btu_hcif_page_scan_mode_change_evt (void); -static void btu_hcif_page_scan_rep_mode_chng_evt (void); -static void btu_hcif_esco_connection_comp_evt(uint8_t *p); -static void btu_hcif_esco_connection_chg_evt(uint8_t *p); +static void btu_hcif_inquiry_comp_evt(uint8_t* p); +static void btu_hcif_inquiry_result_evt(uint8_t* p); +static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p); +static void btu_hcif_extended_inquiry_result_evt(uint8_t* p); + +static void btu_hcif_connection_comp_evt(uint8_t* p); +static void btu_hcif_connection_request_evt(uint8_t* p); +static void btu_hcif_disconnection_comp_evt(uint8_t* p); +static void btu_hcif_authentication_comp_evt(uint8_t* p); +static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len); +static void btu_hcif_encryption_change_evt(uint8_t* p); +static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p); +static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p); +static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p); +static void btu_hcif_qos_setup_comp_evt(uint8_t* p); +static void btu_hcif_command_complete_evt(BT_HDR* response, void* context); +static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command, + void* context); +static void btu_hcif_hardware_error_evt(uint8_t* p); +static void btu_hcif_flush_occured_evt(void); +static void btu_hcif_role_change_evt(uint8_t* p); +static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p); +static void btu_hcif_mode_change_evt(uint8_t* p); +static void btu_hcif_pin_code_request_evt(uint8_t* p); +static void btu_hcif_link_key_request_evt(uint8_t* p); +static void btu_hcif_link_key_notification_evt(uint8_t* p); +static void btu_hcif_loopback_command_evt(void); +static void btu_hcif_data_buf_overflow_evt(void); +static void btu_hcif_max_slots_changed_evt(void); +static void btu_hcif_read_clock_off_comp_evt(uint8_t* p); +static void btu_hcif_conn_pkt_type_change_evt(void); +static void btu_hcif_qos_violation_evt(uint8_t* p); +static void btu_hcif_page_scan_mode_change_evt(void); +static void btu_hcif_page_scan_rep_mode_chng_evt(void); +static void btu_hcif_esco_connection_comp_evt(uint8_t* p); +static void btu_hcif_esco_connection_chg_evt(uint8_t* p); /* Simple Pairing Events */ -static void btu_hcif_host_support_evt (uint8_t *p); -static void btu_hcif_io_cap_request_evt (uint8_t *p); -static void btu_hcif_io_cap_response_evt (uint8_t *p); -static void btu_hcif_user_conf_request_evt (uint8_t *p); -static void btu_hcif_user_passkey_request_evt (uint8_t *p); -static void btu_hcif_user_passkey_notif_evt (uint8_t *p); -static void btu_hcif_keypress_notif_evt (uint8_t *p); -static void btu_hcif_rem_oob_request_evt (uint8_t *p); - -static void btu_hcif_simple_pair_complete_evt (uint8_t *p); - #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == true -static void btu_hcif_enhanced_flush_complete_evt (void); - #endif - - #if (BTM_SSR_INCLUDED == true) -static void btu_hcif_ssr_evt (uint8_t *p, uint16_t evt_len); - #endif /* BTM_SSR_INCLUDED == TRUE */ - -static void btu_ble_ll_conn_complete_evt (uint8_t *p, uint16_t evt_len); -static void btu_ble_process_adv_pkt (uint8_t *p); -static void btu_ble_read_remote_feat_evt (uint8_t *p); -static void btu_ble_ll_conn_param_upd_evt (uint8_t *p, uint16_t evt_len); -static void btu_ble_proc_ltk_req (uint8_t *p); -static void btu_hcif_encryption_key_refresh_cmpl_evt (uint8_t *p); -static void btu_ble_data_length_change_evt (uint8_t *p, uint16_t evt_len); +static void btu_hcif_host_support_evt(uint8_t* p); +static void btu_hcif_io_cap_request_evt(uint8_t* p); +static void btu_hcif_io_cap_response_evt(uint8_t* p); +static void btu_hcif_user_conf_request_evt(uint8_t* p); +static void btu_hcif_user_passkey_request_evt(uint8_t* p); +static void btu_hcif_user_passkey_notif_evt(uint8_t* p); +static void btu_hcif_keypress_notif_evt(uint8_t* p); +static void btu_hcif_rem_oob_request_evt(uint8_t* p); + +static void btu_hcif_simple_pair_complete_evt(uint8_t* p); +#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == true +static void btu_hcif_enhanced_flush_complete_evt(void); +#endif + +#if (BTM_SSR_INCLUDED == true) +static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len); +#endif /* BTM_SSR_INCLUDED == TRUE */ + +static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len); +static void btu_ble_process_adv_pkt(uint8_t* p); +static void btu_ble_read_remote_feat_evt(uint8_t* p); +static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len); +static void btu_ble_proc_ltk_req(uint8_t* p); +static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p); +static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len); #if (BLE_LLT_INCLUDED == TRUE) -static void btu_ble_rc_param_req_evt(uint8_t *p); +static void btu_ble_rc_param_req_evt(uint8_t* p); #endif #if (BLE_PRIVACY_SPT == TRUE) -static void btu_ble_proc_enhanced_conn_cmpl (uint8_t *p, uint16_t evt_len); +static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len); #endif /******************************************************************************* @@ -134,202 +135,204 @@ static void btu_ble_proc_enhanced_conn_cmpl (uint8_t *p, uint16_t evt_len); * Returns void * ******************************************************************************/ -void btu_hcif_process_event (UNUSED_ATTR uint8_t controller_id, BT_HDR *p_msg) -{ - uint8_t *p = (uint8_t *)(p_msg + 1) + p_msg->offset; - uint8_t hci_evt_code, hci_evt_len; - uint8_t ble_sub_code; - STREAM_TO_UINT8 (hci_evt_code, p); - STREAM_TO_UINT8 (hci_evt_len, p); - - switch (hci_evt_code) - { - case HCI_INQUIRY_COMP_EVT: - btu_hcif_inquiry_comp_evt (p); - break; - case HCI_INQUIRY_RESULT_EVT: - btu_hcif_inquiry_result_evt (p); - break; - case HCI_INQUIRY_RSSI_RESULT_EVT: - btu_hcif_inquiry_rssi_result_evt (p); - break; - case HCI_EXTENDED_INQUIRY_RESULT_EVT: - btu_hcif_extended_inquiry_result_evt (p); - break; - case HCI_CONNECTION_COMP_EVT: - btu_hcif_connection_comp_evt (p); - break; - case HCI_CONNECTION_REQUEST_EVT: - btu_hcif_connection_request_evt (p); - break; - case HCI_DISCONNECTION_COMP_EVT: - btu_hcif_disconnection_comp_evt (p); - break; - case HCI_AUTHENTICATION_COMP_EVT: - btu_hcif_authentication_comp_evt (p); - break; - case HCI_RMT_NAME_REQUEST_COMP_EVT: - btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len); - break; - case HCI_ENCRYPTION_CHANGE_EVT: - btu_hcif_encryption_change_evt (p); - break; - case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT: - btu_hcif_encryption_key_refresh_cmpl_evt(p); - break; - case HCI_READ_RMT_FEATURES_COMP_EVT: - btu_hcif_read_rmt_features_comp_evt (p); - break; - case HCI_READ_RMT_EXT_FEATURES_COMP_EVT: - btu_hcif_read_rmt_ext_features_comp_evt (p); - break; - case HCI_READ_RMT_VERSION_COMP_EVT: - btu_hcif_read_rmt_version_comp_evt (p); - break; - case HCI_QOS_SETUP_COMP_EVT: - btu_hcif_qos_setup_comp_evt (p); - break; - case HCI_COMMAND_COMPLETE_EVT: - LOG_ERROR(LOG_TAG, "%s should not have received a command complete event. " - "Someone didn't go through the hci transmit_command function.", __func__); - break; - case HCI_COMMAND_STATUS_EVT: - LOG_ERROR(LOG_TAG, "%s should not have received a command status event. " - "Someone didn't go through the hci transmit_command function.", __func__); - break; - case HCI_HARDWARE_ERROR_EVT: - btu_hcif_hardware_error_evt (p); - break; - case HCI_FLUSH_OCCURED_EVT: - btu_hcif_flush_occured_evt (); - break; - case HCI_ROLE_CHANGE_EVT: - btu_hcif_role_change_evt (p); - break; - case HCI_NUM_COMPL_DATA_PKTS_EVT: - btu_hcif_num_compl_data_pkts_evt (p); - break; - case HCI_MODE_CHANGE_EVT: - btu_hcif_mode_change_evt (p); - break; - case HCI_PIN_CODE_REQUEST_EVT: - btu_hcif_pin_code_request_evt (p); - break; - case HCI_LINK_KEY_REQUEST_EVT: - btu_hcif_link_key_request_evt (p); - break; - case HCI_LINK_KEY_NOTIFICATION_EVT: - btu_hcif_link_key_notification_evt (p); - break; - case HCI_LOOPBACK_COMMAND_EVT: - btu_hcif_loopback_command_evt (); - break; - case HCI_DATA_BUF_OVERFLOW_EVT: - btu_hcif_data_buf_overflow_evt (); - break; - case HCI_MAX_SLOTS_CHANGED_EVT: - btu_hcif_max_slots_changed_evt (); - break; - case HCI_READ_CLOCK_OFF_COMP_EVT: - btu_hcif_read_clock_off_comp_evt (p); - break; - case HCI_CONN_PKT_TYPE_CHANGE_EVT: - btu_hcif_conn_pkt_type_change_evt (); - break; - case HCI_QOS_VIOLATION_EVT: - btu_hcif_qos_violation_evt (p); - break; - case HCI_PAGE_SCAN_MODE_CHANGE_EVT: - btu_hcif_page_scan_mode_change_evt (); - break; - case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT: - btu_hcif_page_scan_rep_mode_chng_evt (); - break; - case HCI_ESCO_CONNECTION_COMP_EVT: - btu_hcif_esco_connection_comp_evt (p); - break; - case HCI_ESCO_CONNECTION_CHANGED_EVT: - btu_hcif_esco_connection_chg_evt (p); - break; +void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) { + uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint8_t hci_evt_code, hci_evt_len; + uint8_t ble_sub_code; + STREAM_TO_UINT8(hci_evt_code, p); + STREAM_TO_UINT8(hci_evt_len, p); + + switch (hci_evt_code) { + case HCI_INQUIRY_COMP_EVT: + btu_hcif_inquiry_comp_evt(p); + break; + case HCI_INQUIRY_RESULT_EVT: + btu_hcif_inquiry_result_evt(p); + break; + case HCI_INQUIRY_RSSI_RESULT_EVT: + btu_hcif_inquiry_rssi_result_evt(p); + break; + case HCI_EXTENDED_INQUIRY_RESULT_EVT: + btu_hcif_extended_inquiry_result_evt(p); + break; + case HCI_CONNECTION_COMP_EVT: + btu_hcif_connection_comp_evt(p); + break; + case HCI_CONNECTION_REQUEST_EVT: + btu_hcif_connection_request_evt(p); + break; + case HCI_DISCONNECTION_COMP_EVT: + btu_hcif_disconnection_comp_evt(p); + break; + case HCI_AUTHENTICATION_COMP_EVT: + btu_hcif_authentication_comp_evt(p); + break; + case HCI_RMT_NAME_REQUEST_COMP_EVT: + btu_hcif_rmt_name_request_comp_evt(p, hci_evt_len); + break; + case HCI_ENCRYPTION_CHANGE_EVT: + btu_hcif_encryption_change_evt(p); + break; + case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT: + btu_hcif_encryption_key_refresh_cmpl_evt(p); + break; + case HCI_READ_RMT_FEATURES_COMP_EVT: + btu_hcif_read_rmt_features_comp_evt(p); + break; + case HCI_READ_RMT_EXT_FEATURES_COMP_EVT: + btu_hcif_read_rmt_ext_features_comp_evt(p); + break; + case HCI_READ_RMT_VERSION_COMP_EVT: + btu_hcif_read_rmt_version_comp_evt(p); + break; + case HCI_QOS_SETUP_COMP_EVT: + btu_hcif_qos_setup_comp_evt(p); + break; + case HCI_COMMAND_COMPLETE_EVT: + LOG_ERROR(LOG_TAG, + "%s should not have received a command complete event. " + "Someone didn't go through the hci transmit_command function.", + __func__); + break; + case HCI_COMMAND_STATUS_EVT: + LOG_ERROR(LOG_TAG, + "%s should not have received a command status event. " + "Someone didn't go through the hci transmit_command function.", + __func__); + break; + case HCI_HARDWARE_ERROR_EVT: + btu_hcif_hardware_error_evt(p); + break; + case HCI_FLUSH_OCCURED_EVT: + btu_hcif_flush_occured_evt(); + break; + case HCI_ROLE_CHANGE_EVT: + btu_hcif_role_change_evt(p); + break; + case HCI_NUM_COMPL_DATA_PKTS_EVT: + btu_hcif_num_compl_data_pkts_evt(p); + break; + case HCI_MODE_CHANGE_EVT: + btu_hcif_mode_change_evt(p); + break; + case HCI_PIN_CODE_REQUEST_EVT: + btu_hcif_pin_code_request_evt(p); + break; + case HCI_LINK_KEY_REQUEST_EVT: + btu_hcif_link_key_request_evt(p); + break; + case HCI_LINK_KEY_NOTIFICATION_EVT: + btu_hcif_link_key_notification_evt(p); + break; + case HCI_LOOPBACK_COMMAND_EVT: + btu_hcif_loopback_command_evt(); + break; + case HCI_DATA_BUF_OVERFLOW_EVT: + btu_hcif_data_buf_overflow_evt(); + break; + case HCI_MAX_SLOTS_CHANGED_EVT: + btu_hcif_max_slots_changed_evt(); + break; + case HCI_READ_CLOCK_OFF_COMP_EVT: + btu_hcif_read_clock_off_comp_evt(p); + break; + case HCI_CONN_PKT_TYPE_CHANGE_EVT: + btu_hcif_conn_pkt_type_change_evt(); + break; + case HCI_QOS_VIOLATION_EVT: + btu_hcif_qos_violation_evt(p); + break; + case HCI_PAGE_SCAN_MODE_CHANGE_EVT: + btu_hcif_page_scan_mode_change_evt(); + break; + case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT: + btu_hcif_page_scan_rep_mode_chng_evt(); + break; + case HCI_ESCO_CONNECTION_COMP_EVT: + btu_hcif_esco_connection_comp_evt(p); + break; + case HCI_ESCO_CONNECTION_CHANGED_EVT: + btu_hcif_esco_connection_chg_evt(p); + break; #if (BTM_SSR_INCLUDED == TRUE) - case HCI_SNIFF_SUB_RATE_EVT: - btu_hcif_ssr_evt (p, hci_evt_len); - break; -#endif /* BTM_SSR_INCLUDED == TRUE */ - case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT: - btu_hcif_host_support_evt (p); - break; - case HCI_IO_CAPABILITY_REQUEST_EVT: - btu_hcif_io_cap_request_evt (p); - break; - case HCI_IO_CAPABILITY_RESPONSE_EVT: - btu_hcif_io_cap_response_evt (p); - break; - case HCI_USER_CONFIRMATION_REQUEST_EVT: - btu_hcif_user_conf_request_evt (p); - break; - case HCI_USER_PASSKEY_REQUEST_EVT: - btu_hcif_user_passkey_request_evt (p); - break; - case HCI_REMOTE_OOB_DATA_REQUEST_EVT: - btu_hcif_rem_oob_request_evt (p); - break; - case HCI_SIMPLE_PAIRING_COMPLETE_EVT: - btu_hcif_simple_pair_complete_evt (p); - break; - case HCI_USER_PASSKEY_NOTIFY_EVT: - btu_hcif_user_passkey_notif_evt (p); - break; - case HCI_KEYPRESS_NOTIFY_EVT: - btu_hcif_keypress_notif_evt (p); - break; + case HCI_SNIFF_SUB_RATE_EVT: + btu_hcif_ssr_evt(p, hci_evt_len); + break; +#endif /* BTM_SSR_INCLUDED == TRUE */ + case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT: + btu_hcif_host_support_evt(p); + break; + case HCI_IO_CAPABILITY_REQUEST_EVT: + btu_hcif_io_cap_request_evt(p); + break; + case HCI_IO_CAPABILITY_RESPONSE_EVT: + btu_hcif_io_cap_response_evt(p); + break; + case HCI_USER_CONFIRMATION_REQUEST_EVT: + btu_hcif_user_conf_request_evt(p); + break; + case HCI_USER_PASSKEY_REQUEST_EVT: + btu_hcif_user_passkey_request_evt(p); + break; + case HCI_REMOTE_OOB_DATA_REQUEST_EVT: + btu_hcif_rem_oob_request_evt(p); + break; + case HCI_SIMPLE_PAIRING_COMPLETE_EVT: + btu_hcif_simple_pair_complete_evt(p); + break; + case HCI_USER_PASSKEY_NOTIFY_EVT: + btu_hcif_user_passkey_notif_evt(p); + break; + case HCI_KEYPRESS_NOTIFY_EVT: + btu_hcif_keypress_notif_evt(p); + break; #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - case HCI_ENHANCED_FLUSH_COMPLETE_EVT: - btu_hcif_enhanced_flush_complete_evt (); - break; + case HCI_ENHANCED_FLUSH_COMPLETE_EVT: + btu_hcif_enhanced_flush_complete_evt(); + break; #endif - case HCI_BLE_EVENT: - STREAM_TO_UINT8 (ble_sub_code, p); - - HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, ble_sub_code); - - switch (ble_sub_code) - { - case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */ - btu_ble_process_adv_pkt(p); - break; - case HCI_BLE_CONN_COMPLETE_EVT: - btu_ble_ll_conn_complete_evt(p, hci_evt_len); - break; - case HCI_BLE_LL_CONN_PARAM_UPD_EVT: - btu_ble_ll_conn_param_upd_evt(p, hci_evt_len); - break; - case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT: - btu_ble_read_remote_feat_evt(p); - break; - case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */ - btu_ble_proc_ltk_req(p); - break; + case HCI_BLE_EVENT: + STREAM_TO_UINT8(ble_sub_code, p); + + HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, + ble_sub_code); + + switch (ble_sub_code) { + case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */ + btu_ble_process_adv_pkt(p); + break; + case HCI_BLE_CONN_COMPLETE_EVT: + btu_ble_ll_conn_complete_evt(p, hci_evt_len); + break; + case HCI_BLE_LL_CONN_PARAM_UPD_EVT: + btu_ble_ll_conn_param_upd_evt(p, hci_evt_len); + break; + case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT: + btu_ble_read_remote_feat_evt(p); + break; + case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */ + btu_ble_proc_ltk_req(p); + break; #if (BLE_PRIVACY_SPT == TRUE) - case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT: - btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len); - break; + case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT: + btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len); + break; #endif #if (BLE_LLT_INCLUDED == TRUE) - case HCI_BLE_RC_PARAM_REQ_EVT: - btu_ble_rc_param_req_evt(p); - break; + case HCI_BLE_RC_PARAM_REQ_EVT: + btu_ble_rc_param_req_evt(p); + break; #endif - case HCI_BLE_DATA_LENGTH_CHANGE_EVT: - btu_ble_data_length_change_evt(p, hci_evt_len); - break; - } - break; - case HCI_VENDOR_SPECIFIC_EVT: - btm_vendor_specific_evt (p, hci_evt_len); - break; - } + case HCI_BLE_DATA_LENGTH_CHANGE_EVT: + btu_ble_data_length_change_evt(p, hci_evt_len); + break; + } + break; + case HCI_VENDOR_SPECIFIC_EVT: + btm_vendor_specific_evt(p, hci_evt_len); + break; + } } /******************************************************************************* @@ -342,114 +345,109 @@ void btu_hcif_process_event (UNUSED_ATTR uint8_t controller_id, BT_HDR *p_msg) * Returns void * ******************************************************************************/ -void btu_hcif_send_cmd (UNUSED_ATTR uint8_t controller_id, BT_HDR *p_buf) -{ - if (!p_buf) - return; - - uint16_t opcode; - uint8_t *stream = p_buf->data + p_buf->offset; - void * vsc_callback = NULL; - - STREAM_TO_UINT16(opcode, stream); - - // Eww...horrible hackery here - /* If command was a VSC, then extract command_complete callback */ - if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC || - (opcode == HCI_BLE_RAND) || - (opcode == HCI_BLE_ENCRYPT)) { - vsc_callback = *((void **)(p_buf + 1)); - } - - hci_layer_get_interface()->transmit_command( - p_buf, - btu_hcif_command_complete_evt, - btu_hcif_command_status_evt, +void btu_hcif_send_cmd(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_buf) { + if (!p_buf) return; + + uint16_t opcode; + uint8_t* stream = p_buf->data + p_buf->offset; + void* vsc_callback = NULL; + + STREAM_TO_UINT16(opcode, stream); + + // Eww...horrible hackery here + /* If command was a VSC, then extract command_complete callback */ + if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC || + (opcode == HCI_BLE_RAND) || (opcode == HCI_BLE_ENCRYPT)) { + vsc_callback = *((void**)(p_buf + 1)); + } + + hci_layer_get_interface()->transmit_command( + p_buf, btu_hcif_command_complete_evt, btu_hcif_command_status_evt, vsc_callback); #if (HCILP_INCLUDED == TRUE) - btu_check_bt_sleep (); + btu_check_bt_sleep(); #endif } +typedef void (*hci_cmd_complete_cb)(uint16_t opcode, uint8_t* return_parameters, + uint16_t return_parameters_length); -typedef void (*hci_cmd_complete_cb)(uint16_t opcode, uint8_t *return_parameters, uint16_t return_parameters_length); - -static void btu_hcif_command_complete_evt_with_cb_on_task(BT_HDR *event) -{ - command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; +static void btu_hcif_command_complete_evt_with_cb_on_task(BT_HDR* event) { + command_complete_hack_t* hack = (command_complete_hack_t*)&event->data[0]; - command_opcode_t opcode; - uint8_t *stream = hack->response->data + hack->response->offset + 3; // 2 to skip the event headers, 1 to skip the command credits - STREAM_TO_UINT16(opcode, stream); + command_opcode_t opcode; + uint8_t* stream = + hack->response->data + hack->response->offset + + 3; // 2 to skip the event headers, 1 to skip the command credits + STREAM_TO_UINT16(opcode, stream); - hci_cmd_complete_cb cb = (hci_cmd_complete_cb)hack->context; - cb(opcode, stream, hack->response->len - 5); + hci_cmd_complete_cb cb = (hci_cmd_complete_cb)hack->context; + cb(opcode, stream, hack->response->len - 5); - osi_free(hack->response); - osi_free(event); + osi_free(hack->response); + osi_free(event); } -static void btu_hcif_command_complete_evt_with_cb(BT_HDR *response, void *context) -{ - BT_HDR *event = - static_cast(osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t))); - command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; +static void btu_hcif_command_complete_evt_with_cb(BT_HDR* response, + void* context) { + BT_HDR* event = static_cast( + osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t))); + command_complete_hack_t* hack = (command_complete_hack_t*)&event->data[0]; - hack->callback = btu_hcif_command_complete_evt_with_cb_on_task; - hack->response = response; - hack->context = context; - event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; + hack->callback = btu_hcif_command_complete_evt_with_cb_on_task; + hack->response = response; + hack->context = context; + event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); + fixed_queue_enqueue(btu_hci_msg_queue, event); } -static void btu_hcif_command_status_evt_with_cb_on_task(BT_HDR *event) -{ - command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; +static void btu_hcif_command_status_evt_with_cb_on_task(BT_HDR* event) { + command_status_hack_t* hack = (command_status_hack_t*)&event->data[0]; - command_opcode_t opcode; - uint8_t *stream = hack->command->data + hack->command->offset; - STREAM_TO_UINT16(opcode, stream); + command_opcode_t opcode; + uint8_t* stream = hack->command->data + hack->command->offset; + STREAM_TO_UINT16(opcode, stream); - hci_cmd_complete_cb cb = (hci_cmd_complete_cb)hack->context; - assert( hack->status != 0 ); - // report command status error - cb(opcode, &hack->status, sizeof(uint16_t)); + hci_cmd_complete_cb cb = (hci_cmd_complete_cb)hack->context; + assert(hack->status != 0); + // report command status error + cb(opcode, &hack->status, sizeof(uint16_t)); - osi_free(hack->command); - osi_free(event); + osi_free(hack->command); + osi_free(event); } -static void btu_hcif_command_status_evt_with_cb(uint8_t status, BT_HDR *command, void *context) -{ - // Command is pending, we report only error. - if (!status) { - osi_free(command); - return; - } +static void btu_hcif_command_status_evt_with_cb(uint8_t status, BT_HDR* command, + void* context) { + // Command is pending, we report only error. + if (!status) { + osi_free(command); + return; + } - BT_HDR *event = - static_cast(osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t))); - command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; + BT_HDR* event = static_cast( + osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t))); + command_status_hack_t* hack = (command_status_hack_t*)&event->data[0]; - hack->callback = btu_hcif_command_status_evt_with_cb_on_task; - hack->status = status; - hack->command = command; - hack->context = context; + hack->callback = btu_hcif_command_status_evt_with_cb_on_task; + hack->status = status; + hack->command = command; + hack->context = context; - event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; + event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); + fixed_queue_enqueue(btu_hci_msg_queue, event); } /* This function is called to send commands to the Host Controller. |cb| is * called when command status event is called with error code, or when the * command complete event is received. */ -void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t *params, +void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t* params, uint8_t params_len, hci_cmd_complete_cb cb) { - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); p->len = HCIC_PREAMBLE_SIZE + params_len; p->offset = 0; @@ -462,7 +460,7 @@ void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t *params, hci_layer_get_interface()->transmit_command( p, btu_hcif_command_complete_evt_with_cb, - btu_hcif_command_status_evt_with_cb, (void*) cb); + btu_hcif_command_status_evt_with_cb, (void*)cb); #if (HCILP_INCLUDED == TRUE) btu_check_bt_sleep(); @@ -478,14 +476,13 @@ void btu_hcif_send_cmd_with_cb(uint16_t opcode, uint8_t *params, * Returns void * ******************************************************************************/ -static void btu_hcif_inquiry_comp_evt (uint8_t *p) -{ - uint8_t status; +static void btu_hcif_inquiry_comp_evt(uint8_t* p) { + uint8_t status; - STREAM_TO_UINT8 (status, p); + STREAM_TO_UINT8(status, p); - /* Tell inquiry processing that we are done */ - btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); + /* Tell inquiry processing that we are done */ + btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); } /******************************************************************************* @@ -497,10 +494,9 @@ static void btu_hcif_inquiry_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_inquiry_result_evt (uint8_t *p) -{ - /* Store results in the cache */ - btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD); +static void btu_hcif_inquiry_result_evt(uint8_t* p) { + /* Store results in the cache */ + btm_process_inq_results(p, BTM_INQ_RESULT_STANDARD); } /******************************************************************************* @@ -512,10 +508,9 @@ static void btu_hcif_inquiry_result_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_inquiry_rssi_result_evt (uint8_t *p) -{ - /* Store results in the cache */ - btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI); +static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p) { + /* Store results in the cache */ + btm_process_inq_results(p, BTM_INQ_RESULT_WITH_RSSI); } /******************************************************************************* @@ -527,10 +522,9 @@ static void btu_hcif_inquiry_rssi_result_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_extended_inquiry_result_evt (uint8_t *p) -{ - /* Store results in the cache */ - btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED); +static void btu_hcif_extended_inquiry_result_evt(uint8_t* p) { + /* Store results in the cache */ + btm_process_inq_results(p, BTM_INQ_RESULT_EXTENDED); } /******************************************************************************* @@ -542,39 +536,36 @@ static void btu_hcif_extended_inquiry_result_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_connection_comp_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; - BD_ADDR bda; - uint8_t link_type; - uint8_t enc_mode; +static void btu_hcif_connection_comp_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; + BD_ADDR bda; + uint8_t link_type; + uint8_t enc_mode; #if (BTM_SCO_INCLUDED == TRUE) - tBTM_ESCO_DATA esco_data; + tBTM_ESCO_DATA esco_data; #endif - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - STREAM_TO_BDADDR (bda, p); - STREAM_TO_UINT8 (link_type, p); - STREAM_TO_UINT8 (enc_mode, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_BDADDR(bda, p); + STREAM_TO_UINT8(link_type, p); + STREAM_TO_UINT8(enc_mode, p); - handle = HCID_GET_HANDLE (handle); + handle = HCID_GET_HANDLE(handle); - if (link_type == HCI_LINK_TYPE_ACL) - { - btm_sec_connected (bda, handle, status, enc_mode); + if (link_type == HCI_LINK_TYPE_ACL) { + btm_sec_connected(bda, handle, status, enc_mode); - l2c_link_hci_conn_comp (status, handle, bda); - } + l2c_link_hci_conn_comp(status, handle, bda); + } #if (BTM_SCO_INCLUDED == TRUE) - else - { - memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA)); - /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */ - memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN); - btm_sco_connected (status, bda, handle, &esco_data); - } + else { + memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA)); + /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */ + memcpy(esco_data.bd_addr, bda, BD_ADDR_LEN); + btm_sco_connected(status, bda, handle, &esco_data); + } #endif /* BTM_SCO_INCLUDED */ } @@ -587,27 +578,24 @@ static void btu_hcif_connection_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_connection_request_evt (uint8_t *p) -{ - BD_ADDR bda; - DEV_CLASS dc; - uint8_t link_type; - - STREAM_TO_BDADDR (bda, p); - STREAM_TO_DEVCLASS (dc, p); - STREAM_TO_UINT8 (link_type, p); - - /* Pass request to security manager to check connect filters before */ - /* passing request to l2cap */ - if (link_type == HCI_LINK_TYPE_ACL) - { - btm_sec_conn_req (bda, dc); - } +static void btu_hcif_connection_request_evt(uint8_t* p) { + BD_ADDR bda; + DEV_CLASS dc; + uint8_t link_type; + + STREAM_TO_BDADDR(bda, p); + STREAM_TO_DEVCLASS(dc, p); + STREAM_TO_UINT8(link_type, p); + + /* Pass request to security manager to check connect filters before */ + /* passing request to l2cap */ + if (link_type == HCI_LINK_TYPE_ACL) { + btm_sec_conn_req(bda, dc); + } #if (BTM_SCO_INCLUDED == TRUE) - else - { - btm_sco_conn_req (bda, dc, link_type); - } + else { + btm_sco_conn_req(bda, dc, link_type); + } #endif /* BTM_SCO_INCLUDED */ } @@ -620,27 +608,25 @@ static void btu_hcif_connection_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_disconnection_comp_evt (uint8_t *p) -{ - uint16_t handle; - uint8_t reason; +static void btu_hcif_disconnection_comp_evt(uint8_t* p) { + uint16_t handle; + uint8_t reason; - ++p; - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (reason, p); + ++p; + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(reason, p); - handle = HCID_GET_HANDLE (handle); + handle = HCID_GET_HANDLE(handle); #if (BTM_SCO_INCLUDED == TRUE) - /* If L2CAP doesn't know about it, send it to SCO */ - if (!l2c_link_hci_disc_comp (handle, reason)) - btm_sco_removed (handle, reason); + /* If L2CAP doesn't know about it, send it to SCO */ + if (!l2c_link_hci_disc_comp(handle, reason)) btm_sco_removed(handle, reason); #else - l2c_link_hci_disc_comp (handle, reason); + l2c_link_hci_disc_comp(handle, reason); #endif /* BTM_SCO_INCLUDED */ - /* Notify security manager */ - btm_sec_disconnected (handle, reason); + /* Notify security manager */ + btm_sec_disconnected(handle, reason); } /******************************************************************************* @@ -652,15 +638,14 @@ static void btu_hcif_disconnection_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_authentication_comp_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; +static void btu_hcif_authentication_comp_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); - btm_sec_auth_complete (handle, status); + btm_sec_auth_complete(handle, status); } /******************************************************************************* @@ -672,19 +657,18 @@ static void btu_hcif_authentication_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_rmt_name_request_comp_evt (uint8_t *p, uint16_t evt_len) -{ - uint8_t status; - BD_ADDR bd_addr; +static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len) { + uint8_t status; + BD_ADDR bd_addr; - STREAM_TO_UINT8 (status, p); - STREAM_TO_BDADDR (bd_addr, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_BDADDR(bd_addr, p); - evt_len -= (1 + BD_ADDR_LEN); + evt_len -= (1 + BD_ADDR_LEN); - btm_process_remote_name (bd_addr, p, evt_len, status); + btm_process_remote_name(bd_addr, p, evt_len, status); - btm_sec_rmt_name_request_complete (bd_addr, p, status); + btm_sec_rmt_name_request_complete(bd_addr, p, status); } /******************************************************************************* @@ -696,18 +680,17 @@ static void btu_hcif_rmt_name_request_comp_evt (uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -static void btu_hcif_encryption_change_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; - uint8_t encr_enable; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (encr_enable, p); - - btm_acl_encrypt_change (handle, status, encr_enable); - btm_sec_encrypt_change (handle, status, encr_enable); +static void btu_hcif_encryption_change_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; + uint8_t encr_enable; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(encr_enable, p); + + btm_acl_encrypt_change(handle, status, encr_enable); + btm_sec_encrypt_change(handle, status, encr_enable); } /******************************************************************************* @@ -719,9 +702,8 @@ static void btu_hcif_encryption_change_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_read_rmt_features_comp_evt (uint8_t *p) -{ - btm_read_remote_features_complete(p); +static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p) { + btm_read_remote_features_complete(p); } /******************************************************************************* @@ -733,21 +715,19 @@ static void btu_hcif_read_rmt_features_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_read_rmt_ext_features_comp_evt (uint8_t *p) -{ - uint8_t *p_cur = p; - uint8_t status; - uint16_t handle; - - STREAM_TO_UINT8 (status, p_cur); - - if (status == HCI_SUCCESS) - btm_read_remote_ext_features_complete(p); - else - { - STREAM_TO_UINT16 (handle, p_cur); - btm_read_remote_ext_features_failed(status, handle); - } +static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) { + uint8_t* p_cur = p; + uint8_t status; + uint16_t handle; + + STREAM_TO_UINT8(status, p_cur); + + if (status == HCI_SUCCESS) + btm_read_remote_ext_features_complete(p); + else { + STREAM_TO_UINT16(handle, p_cur); + btm_read_remote_ext_features_failed(status, handle); + } } /******************************************************************************* @@ -759,9 +739,8 @@ static void btu_hcif_read_rmt_ext_features_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_read_rmt_version_comp_evt (uint8_t *p) -{ - btm_read_remote_version_complete (p); +static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p) { + btm_read_remote_version_complete(p); } /******************************************************************************* @@ -773,22 +752,21 @@ static void btu_hcif_read_rmt_version_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_qos_setup_comp_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; - FLOW_SPEC flow; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (flow.qos_flags, p); - STREAM_TO_UINT8 (flow.service_type, p); - STREAM_TO_UINT32 (flow.token_rate, p); - STREAM_TO_UINT32 (flow.peak_bandwidth, p); - STREAM_TO_UINT32 (flow.latency, p); - STREAM_TO_UINT32 (flow.delay_variation, p); - - btm_qos_setup_complete(status, handle, &flow); +static void btu_hcif_qos_setup_comp_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; + FLOW_SPEC flow; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(flow.qos_flags, p); + STREAM_TO_UINT8(flow.service_type, p); + STREAM_TO_UINT32(flow.token_rate, p); + STREAM_TO_UINT32(flow.peak_bandwidth, p); + STREAM_TO_UINT32(flow.latency, p); + STREAM_TO_UINT32(flow.delay_variation, p); + + btm_qos_setup_complete(status, handle, &flow); } /******************************************************************************* @@ -800,27 +778,26 @@ static void btu_hcif_qos_setup_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_esco_connection_comp_evt (uint8_t *p) -{ +static void btu_hcif_esco_connection_comp_evt(uint8_t* p) { #if (BTM_SCO_INCLUDED == TRUE) - tBTM_ESCO_DATA data; - uint16_t handle; - BD_ADDR bda; - uint8_t status; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - STREAM_TO_BDADDR (bda, p); - - STREAM_TO_UINT8 (data.link_type, p); - STREAM_TO_UINT8 (data.tx_interval, p); - STREAM_TO_UINT8 (data.retrans_window, p); - STREAM_TO_UINT16 (data.rx_pkt_len, p); - STREAM_TO_UINT16 (data.tx_pkt_len, p); - STREAM_TO_UINT8 (data.air_mode, p); - - memcpy (data.bd_addr, bda, BD_ADDR_LEN); - btm_sco_connected (status, bda, handle, &data); + tBTM_ESCO_DATA data; + uint16_t handle; + BD_ADDR bda; + uint8_t status; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_BDADDR(bda, p); + + STREAM_TO_UINT8(data.link_type, p); + STREAM_TO_UINT8(data.tx_interval, p); + STREAM_TO_UINT8(data.retrans_window, p); + STREAM_TO_UINT16(data.rx_pkt_len, p); + STREAM_TO_UINT16(data.tx_pkt_len, p); + STREAM_TO_UINT8(data.air_mode, p); + + memcpy(data.bd_addr, bda, BD_ADDR_LEN); + btm_sco_connected(status, bda, handle, &data); #endif } @@ -833,26 +810,25 @@ static void btu_hcif_esco_connection_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_esco_connection_chg_evt (uint8_t *p) -{ +static void btu_hcif_esco_connection_chg_evt(uint8_t* p) { #if (BTM_SCO_INCLUDED == TRUE) - uint16_t handle; - uint16_t tx_pkt_len; - uint16_t rx_pkt_len; - uint8_t status; - uint8_t tx_interval; - uint8_t retrans_window; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); - - STREAM_TO_UINT8 (tx_interval, p); - STREAM_TO_UINT8 (retrans_window, p); - STREAM_TO_UINT16 (rx_pkt_len, p); - STREAM_TO_UINT16 (tx_pkt_len, p); - - btm_esco_proc_conn_chg (status, handle, tx_interval, retrans_window, - rx_pkt_len, tx_pkt_len); + uint16_t handle; + uint16_t tx_pkt_len; + uint16_t rx_pkt_len; + uint8_t status; + uint8_t tx_interval; + uint8_t retrans_window; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + + STREAM_TO_UINT8(tx_interval, p); + STREAM_TO_UINT8(retrans_window, p); + STREAM_TO_UINT16(rx_pkt_len, p); + STREAM_TO_UINT16(tx_pkt_len, p); + + btm_esco_proc_conn_chg(status, handle, tx_interval, retrans_window, + rx_pkt_len, tx_pkt_len); #endif } @@ -865,114 +841,113 @@ static void btu_hcif_esco_connection_chg_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_hdl_command_complete (uint16_t opcode, uint8_t *p, uint16_t evt_len, - void *p_cplt_cback) -{ - switch (opcode) - { - case HCI_INQUIRY_CANCEL: - /* Tell inquiry processing that we are done */ - btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK); - break; - case HCI_SET_EVENT_FILTER: - btm_event_filter_complete (p); - break; - - case HCI_DELETE_STORED_LINK_KEY: - btm_delete_stored_link_key_complete (p); - break; - - case HCI_READ_LOCAL_NAME: - btm_read_local_name_complete (p, evt_len); - break; - - case HCI_GET_LINK_QUALITY: - btm_read_link_quality_complete (p); - break; - - case HCI_READ_RSSI: - btm_read_rssi_complete (p); - break; - - case HCI_READ_TRANSMIT_POWER_LEVEL: - btm_read_tx_power_complete(p, false); - break; - - case HCI_CREATE_CONNECTION_CANCEL: - btm_create_conn_cancel_complete(p); - break; - - case HCI_READ_LOCAL_OOB_DATA: - btm_read_local_oob_complete(p); - break; - - case HCI_READ_INQ_TX_POWER_LEVEL: - btm_read_inq_tx_power_complete(p); - break; - -/* BLE Commands sComplete*/ - case HCI_BLE_ADD_WHITE_LIST: - btm_ble_add_2_white_list_complete(*p); - break; - - case HCI_BLE_CLEAR_WHITE_LIST: - btm_ble_clear_white_list_complete(p, evt_len); - break; - - case HCI_BLE_REMOVE_WHITE_LIST: - btm_ble_remove_from_white_list_complete(p, evt_len); - break; - - case HCI_BLE_RAND: - case HCI_BLE_ENCRYPT: - btm_ble_rand_enc_complete (p, opcode, (tBTM_RAND_ENC_CB *)p_cplt_cback); - break; - - case HCI_BLE_READ_ADV_CHNL_TX_POWER: - btm_read_tx_power_complete(p, true); - break; - - case HCI_BLE_WRITE_ADV_ENABLE: - btm_ble_write_adv_enable_complete(p); - break; - - case HCI_BLE_CREATE_LL_CONN: - btm_ble_create_ll_conn_complete(*p); - break; - - case HCI_BLE_TRANSMITTER_TEST: - case HCI_BLE_RECEIVER_TEST: - case HCI_BLE_TEST_END: - btm_ble_test_command_complete(p); - break; +static void btu_hcif_hdl_command_complete(uint16_t opcode, uint8_t* p, + uint16_t evt_len, + void* p_cplt_cback) { + switch (opcode) { + case HCI_INQUIRY_CANCEL: + /* Tell inquiry processing that we are done */ + btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK); + break; + case HCI_SET_EVENT_FILTER: + btm_event_filter_complete(p); + break; + + case HCI_DELETE_STORED_LINK_KEY: + btm_delete_stored_link_key_complete(p); + break; + + case HCI_READ_LOCAL_NAME: + btm_read_local_name_complete(p, evt_len); + break; + + case HCI_GET_LINK_QUALITY: + btm_read_link_quality_complete(p); + break; + + case HCI_READ_RSSI: + btm_read_rssi_complete(p); + break; + + case HCI_READ_TRANSMIT_POWER_LEVEL: + btm_read_tx_power_complete(p, false); + break; + + case HCI_CREATE_CONNECTION_CANCEL: + btm_create_conn_cancel_complete(p); + break; + + case HCI_READ_LOCAL_OOB_DATA: + btm_read_local_oob_complete(p); + break; + + case HCI_READ_INQ_TX_POWER_LEVEL: + btm_read_inq_tx_power_complete(p); + break; + + /* BLE Commands sComplete*/ + case HCI_BLE_ADD_WHITE_LIST: + btm_ble_add_2_white_list_complete(*p); + break; + + case HCI_BLE_CLEAR_WHITE_LIST: + btm_ble_clear_white_list_complete(p, evt_len); + break; + + case HCI_BLE_REMOVE_WHITE_LIST: + btm_ble_remove_from_white_list_complete(p, evt_len); + break; + + case HCI_BLE_RAND: + case HCI_BLE_ENCRYPT: + btm_ble_rand_enc_complete(p, opcode, (tBTM_RAND_ENC_CB*)p_cplt_cback); + break; + + case HCI_BLE_READ_ADV_CHNL_TX_POWER: + btm_read_tx_power_complete(p, true); + break; + + case HCI_BLE_WRITE_ADV_ENABLE: + btm_ble_write_adv_enable_complete(p); + break; + + case HCI_BLE_CREATE_LL_CONN: + btm_ble_create_ll_conn_complete(*p); + break; + + case HCI_BLE_TRANSMITTER_TEST: + case HCI_BLE_RECEIVER_TEST: + case HCI_BLE_TEST_END: + btm_ble_test_command_complete(p); + break; #if (BLE_PRIVACY_SPT == TRUE) - case HCI_BLE_ADD_DEV_RESOLVING_LIST: - btm_ble_add_resolving_list_entry_complete(p, evt_len); - break; - - case HCI_BLE_RM_DEV_RESOLVING_LIST: - btm_ble_remove_resolving_list_entry_complete(p, evt_len); - break; - - case HCI_BLE_CLEAR_RESOLVING_LIST: - btm_ble_clear_resolving_list_complete(p, evt_len); - break; - - case HCI_BLE_READ_RESOLVABLE_ADDR_PEER: - btm_ble_read_resolving_list_entry_complete(p, evt_len); - break; - - case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL: - case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE: - case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT: - break; + case HCI_BLE_ADD_DEV_RESOLVING_LIST: + btm_ble_add_resolving_list_entry_complete(p, evt_len); + break; + + case HCI_BLE_RM_DEV_RESOLVING_LIST: + btm_ble_remove_resolving_list_entry_complete(p, evt_len); + break; + + case HCI_BLE_CLEAR_RESOLVING_LIST: + btm_ble_clear_resolving_list_complete(p, evt_len); + break; + + case HCI_BLE_READ_RESOLVABLE_ADDR_PEER: + btm_ble_read_resolving_list_entry_complete(p, evt_len); + break; + + case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL: + case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE: + case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT: + break; #endif - default: - if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) - btm_vsc_complete (p, opcode, evt_len, (tBTM_CMPL_CB *)p_cplt_cback); - break; - } + default: + if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) + btm_vsc_complete(p, opcode, evt_len, (tBTM_CMPL_CB*)p_cplt_cback); + break; + } } /******************************************************************************* @@ -984,37 +959,37 @@ static void btu_hcif_hdl_command_complete (uint16_t opcode, uint8_t *p, uint16_t * Returns void * ******************************************************************************/ -static void btu_hcif_command_complete_evt_on_task(BT_HDR *event) -{ - command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; - - command_opcode_t opcode; - uint8_t *stream = hack->response->data + hack->response->offset + 3; // 2 to skip the event headers, 1 to skip the command credits - STREAM_TO_UINT16(opcode, stream); - - btu_hcif_hdl_command_complete( - opcode, - stream, - hack->response->len - 5, // 3 for the command complete headers, 2 for the event headers +static void btu_hcif_command_complete_evt_on_task(BT_HDR* event) { + command_complete_hack_t* hack = (command_complete_hack_t*)&event->data[0]; + + command_opcode_t opcode; + uint8_t* stream = + hack->response->data + hack->response->offset + + 3; // 2 to skip the event headers, 1 to skip the command credits + STREAM_TO_UINT16(opcode, stream); + + btu_hcif_hdl_command_complete( + opcode, stream, + hack->response->len - + 5, // 3 for the command complete headers, 2 for the event headers hack->context); - osi_free(hack->response); - osi_free(event); + osi_free(hack->response); + osi_free(event); } -static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) -{ - BT_HDR *event = - static_cast(osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t))); - command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; +static void btu_hcif_command_complete_evt(BT_HDR* response, void* context) { + BT_HDR* event = static_cast( + osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t))); + command_complete_hack_t* hack = (command_complete_hack_t*)&event->data[0]; - hack->callback = btu_hcif_command_complete_evt_on_task; - hack->response = response; - hack->context = context; + hack->callback = btu_hcif_command_complete_evt_on_task; + hack->response = response; + hack->context = context; - event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; + event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); + fixed_queue_enqueue(btu_hci_msg_queue, event); } /******************************************************************************* @@ -1026,149 +1001,143 @@ static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) * Returns void * ******************************************************************************/ -static void btu_hcif_hdl_command_status (uint16_t opcode, uint8_t status, uint8_t *p_cmd, - void *p_vsc_status_cback) -{ - BD_ADDR bd_addr; - uint16_t handle; +static void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status, + uint8_t* p_cmd, + void* p_vsc_status_cback) { + BD_ADDR bd_addr; + uint16_t handle; #if (BTM_SCO_INCLUDED == TRUE) - tBTM_ESCO_DATA esco_data; + tBTM_ESCO_DATA esco_data; #endif - switch (opcode) - { - case HCI_EXIT_SNIFF_MODE: - case HCI_EXIT_PARK_MODE: + switch (opcode) { + case HCI_EXIT_SNIFF_MODE: + case HCI_EXIT_PARK_MODE: #if (BTM_SCO_WAKE_PARKED_LINK == TRUE) - if (status != HCI_SUCCESS) - { - /* Allow SCO initiation to continue if waiting for change mode event */ - if (p_cmd != NULL) - { - p_cmd++; /* bypass length field */ - STREAM_TO_UINT16 (handle, p_cmd); - btm_sco_chk_pend_unpark (status, handle); - } - } + if (status != HCI_SUCCESS) { + /* Allow SCO initiation to continue if waiting for change mode event */ + if (p_cmd != NULL) { + p_cmd++; /* bypass length field */ + STREAM_TO_UINT16(handle, p_cmd); + btm_sco_chk_pend_unpark(status, handle); + } + } #endif - /* Case Falls Through */ + /* Case Falls Through */ + + case HCI_HOLD_MODE: + case HCI_SNIFF_MODE: + case HCI_PARK_MODE: + btm_pm_proc_cmd_status(status); + break; + + default: + /* If command failed to start, we may need to tell BTM */ + if (status != HCI_SUCCESS) { + switch (opcode) { + case HCI_INQUIRY: + /* Tell inquiry processing that we are done */ + btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); + break; - case HCI_HOLD_MODE: - case HCI_SNIFF_MODE: - case HCI_PARK_MODE: - btm_pm_proc_cmd_status(status); + case HCI_RMT_NAME_REQUEST: + /* Tell inquiry processing that we are done */ + btm_process_remote_name(NULL, NULL, 0, status); + + btm_sec_rmt_name_request_complete(NULL, NULL, status); break; - default: - /* If command failed to start, we may need to tell BTM */ - if (status != HCI_SUCCESS) - { - switch (opcode) - { - case HCI_INQUIRY: - /* Tell inquiry processing that we are done */ - btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); - break; - - case HCI_RMT_NAME_REQUEST: - /* Tell inquiry processing that we are done */ - btm_process_remote_name (NULL, NULL, 0, status); - - btm_sec_rmt_name_request_complete (NULL, NULL, status); - break; - - case HCI_QOS_SETUP_COMP_EVT: - /* Tell qos setup that we are done */ - btm_qos_setup_complete(status,0,NULL); - break; - - case HCI_SWITCH_ROLE: - /* Tell BTM that the command failed */ - /* read bd addr out of stored command */ - if (p_cmd != NULL) - { - p_cmd++; - STREAM_TO_BDADDR (bd_addr, p_cmd); - btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED); - } - else - btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED); - l2c_link_role_changed (NULL, BTM_ROLE_UNDEFINED, HCI_ERR_COMMAND_DISALLOWED); - break; - - case HCI_CREATE_CONNECTION: - /* read bd addr out of stored command */ - if (p_cmd != NULL) - { - p_cmd++; - STREAM_TO_BDADDR (bd_addr, p_cmd); - btm_sec_connected (bd_addr, HCI_INVALID_HANDLE, status, 0); - l2c_link_hci_conn_comp (status, HCI_INVALID_HANDLE, bd_addr); - } - break; - - case HCI_READ_RMT_EXT_FEATURES: - if (p_cmd != NULL) - { - p_cmd++; /* skip command length */ - STREAM_TO_UINT16 (handle, p_cmd); - } - else - handle = HCI_INVALID_HANDLE; - - btm_read_remote_ext_features_failed(status, handle); - break; - - case HCI_AUTHENTICATION_REQUESTED: - /* Device refused to start authentication. That should be treated as authentication failure. */ - btm_sec_auth_complete (BTM_INVALID_HCI_HANDLE, status); - break; - - case HCI_SET_CONN_ENCRYPTION: - /* Device refused to start encryption. That should be treated as encryption failure. */ - btm_sec_encrypt_change (BTM_INVALID_HCI_HANDLE, status, false); - break; - - case HCI_BLE_CREATE_LL_CONN: - btm_ble_create_ll_conn_complete(status); - break; + case HCI_QOS_SETUP_COMP_EVT: + /* Tell qos setup that we are done */ + btm_qos_setup_complete(status, 0, NULL); + break; + + case HCI_SWITCH_ROLE: + /* Tell BTM that the command failed */ + /* read bd addr out of stored command */ + if (p_cmd != NULL) { + p_cmd++; + STREAM_TO_BDADDR(bd_addr, p_cmd); + btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED); + } else + btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED); + l2c_link_role_changed(NULL, BTM_ROLE_UNDEFINED, + HCI_ERR_COMMAND_DISALLOWED); + break; + + case HCI_CREATE_CONNECTION: + /* read bd addr out of stored command */ + if (p_cmd != NULL) { + p_cmd++; + STREAM_TO_BDADDR(bd_addr, p_cmd); + btm_sec_connected(bd_addr, HCI_INVALID_HANDLE, status, 0); + l2c_link_hci_conn_comp(status, HCI_INVALID_HANDLE, bd_addr); + } + break; + + case HCI_READ_RMT_EXT_FEATURES: + if (p_cmd != NULL) { + p_cmd++; /* skip command length */ + STREAM_TO_UINT16(handle, p_cmd); + } else + handle = HCI_INVALID_HANDLE; + + btm_read_remote_ext_features_failed(status, handle); + break; + + case HCI_AUTHENTICATION_REQUESTED: + /* Device refused to start authentication. That should be treated + * as authentication failure. */ + btm_sec_auth_complete(BTM_INVALID_HCI_HANDLE, status); + break; + + case HCI_SET_CONN_ENCRYPTION: + /* Device refused to start encryption. That should be treated as + * encryption failure. */ + btm_sec_encrypt_change(BTM_INVALID_HCI_HANDLE, status, false); + break; + + case HCI_BLE_CREATE_LL_CONN: + btm_ble_create_ll_conn_complete(status); + break; #if (BTM_SCO_INCLUDED == TRUE) - case HCI_SETUP_ESCO_CONNECTION: - /* read handle out of stored command */ - if (p_cmd != NULL) - { - p_cmd++; - STREAM_TO_UINT16 (handle, p_cmd); - - /* Determine if initial connection failed or is a change of setup */ - if (btm_is_sco_active(handle)) - btm_esco_proc_conn_chg (status, handle, 0, 0, 0, 0); - else - btm_sco_connected (status, NULL, handle, &esco_data); - } - break; + case HCI_SETUP_ESCO_CONNECTION: + /* read handle out of stored command */ + if (p_cmd != NULL) { + p_cmd++; + STREAM_TO_UINT16(handle, p_cmd); + + /* Determine if initial connection failed or is a change of setup + */ + if (btm_is_sco_active(handle)) + btm_esco_proc_conn_chg(status, handle, 0, 0, 0, 0); + else + btm_sco_connected(status, NULL, handle, &esco_data); + } + break; #endif -/* This is commented out until an upper layer cares about returning event -#if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - case HCI_ENHANCED_FLUSH: - break; -#endif -*/ - default: - if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) - btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback); - break; - } + /* This is commented out until an upper layer cares about returning + event + #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) + case HCI_ENHANCED_FLUSH: + break; + #endif + */ + default: + if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) + btm_vsc_complete(&status, opcode, 1, + (tBTM_CMPL_CB*)p_vsc_status_cback); + break; + } - } - else - { - if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) - btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback); - } - } + } else { + if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) + btm_vsc_complete(&status, opcode, 1, + (tBTM_CMPL_CB*)p_vsc_status_cback); + } + } } /******************************************************************************* @@ -1180,38 +1149,33 @@ static void btu_hcif_hdl_command_status (uint16_t opcode, uint8_t status, uint8_ * Returns void * ******************************************************************************/ -static void btu_hcif_command_status_evt_on_task(BT_HDR *event) -{ - command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; - - command_opcode_t opcode; - uint8_t *stream = hack->command->data + hack->command->offset; - STREAM_TO_UINT16(opcode, stream); - - btu_hcif_hdl_command_status( - opcode, - hack->status, - stream, - hack->context); +static void btu_hcif_command_status_evt_on_task(BT_HDR* event) { + command_status_hack_t* hack = (command_status_hack_t*)&event->data[0]; - osi_free(hack->command); - osi_free(event); + command_opcode_t opcode; + uint8_t* stream = hack->command->data + hack->command->offset; + STREAM_TO_UINT16(opcode, stream); + + btu_hcif_hdl_command_status(opcode, hack->status, stream, hack->context); + + osi_free(hack->command); + osi_free(event); } -static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *context) -{ - BT_HDR *event = - static_cast(osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t))); - command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; +static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command, + void* context) { + BT_HDR* event = static_cast( + osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t))); + command_status_hack_t* hack = (command_status_hack_t*)&event->data[0]; - hack->callback = btu_hcif_command_status_evt_on_task; - hack->status = status; - hack->command = command; - hack->context = context; + hack->callback = btu_hcif_command_status_evt_on_task; + hack->status = status; + hack->command = command; + hack->context = context; - event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; + event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; - fixed_queue_enqueue(btu_hci_msg_queue, event); + fixed_queue_enqueue(btu_hci_msg_queue, event); } /******************************************************************************* @@ -1223,16 +1187,14 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c * Returns void * ******************************************************************************/ -static void btu_hcif_hardware_error_evt (uint8_t *p) -{ - HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p); +static void btu_hcif_hardware_error_evt(uint8_t* p) { + HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p); - /* If anyone wants device status notifications, give him one. */ - btm_report_device_status (BTM_DEV_STATUS_DOWN); + /* If anyone wants device status notifications, give him one. */ + btm_report_device_status(BTM_DEV_STATUS_DOWN); - /* Reset the controller */ - if (BTM_IsDeviceUp()) - BTM_DeviceReset (NULL); + /* Reset the controller */ + if (BTM_IsDeviceUp()) BTM_DeviceReset(NULL); } /******************************************************************************* @@ -1244,9 +1206,7 @@ static void btu_hcif_hardware_error_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_flush_occured_evt (void) -{ -} +static void btu_hcif_flush_occured_evt(void) {} /******************************************************************************* * @@ -1257,18 +1217,17 @@ static void btu_hcif_flush_occured_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_role_change_evt (uint8_t *p) -{ - uint8_t status; - BD_ADDR bda; - uint8_t role; - - STREAM_TO_UINT8 (status, p); - STREAM_TO_BDADDR (bda, p); - STREAM_TO_UINT8 (role, p); - - l2c_link_role_changed (bda, role, status); - btm_acl_role_changed(status, bda, role); +static void btu_hcif_role_change_evt(uint8_t* p) { + uint8_t status; + BD_ADDR bda; + uint8_t role; + + STREAM_TO_UINT8(status, p); + STREAM_TO_BDADDR(bda, p); + STREAM_TO_UINT8(role, p); + + l2c_link_role_changed(bda, role, status); + btm_acl_role_changed(status, bda, role); } /******************************************************************************* @@ -1280,13 +1239,12 @@ static void btu_hcif_role_change_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_num_compl_data_pkts_evt (uint8_t *p) -{ - /* Process for L2CAP and SCO */ - l2c_link_process_num_completed_pkts (p); +static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p) { + /* Process for L2CAP and SCO */ + l2c_link_process_num_completed_pkts(p); - /* Send on to SCO */ - /*?? No SCO for now */ + /* Send on to SCO */ + /*?? No SCO for now */ } /******************************************************************************* @@ -1298,25 +1256,24 @@ static void btu_hcif_num_compl_data_pkts_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_mode_change_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; - uint8_t current_mode; - uint16_t interval; - - STREAM_TO_UINT8 (status, p); - - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT8 (current_mode, p); - STREAM_TO_UINT16 (interval, p); +static void btu_hcif_mode_change_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; + uint8_t current_mode; + uint16_t interval; + + STREAM_TO_UINT8(status, p); + + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(current_mode, p); + STREAM_TO_UINT16(interval, p); #if (BTM_SCO_WAKE_PARKED_LINK == TRUE) - btm_sco_chk_pend_unpark (status, handle); + btm_sco_chk_pend_unpark(status, handle); #endif - btm_pm_proc_mode_change (status, handle, current_mode, interval); + btm_pm_proc_mode_change(status, handle, current_mode, interval); #if (HID_DEV_INCLUDED == TRUE && HID_DEV_PM_INCLUDED == TRUE) - hidd_pm_proc_mode_change( status, current_mode, interval ) ; + hidd_pm_proc_mode_change(status, current_mode, interval); #endif } @@ -1329,12 +1286,11 @@ static void btu_hcif_mode_change_evt (uint8_t *p) * Returns void * ******************************************************************************/ - #if (BTM_SSR_INCLUDED == true) -static void btu_hcif_ssr_evt (uint8_t *p, uint16_t evt_len) -{ - btm_pm_proc_ssr_evt(p, evt_len); +#if (BTM_SSR_INCLUDED == true) +static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len) { + btm_pm_proc_ssr_evt(p, evt_len); } - #endif +#endif /******************************************************************************* * @@ -1345,17 +1301,16 @@ static void btu_hcif_ssr_evt (uint8_t *p, uint16_t evt_len) * Returns void * ******************************************************************************/ -static void btu_hcif_pin_code_request_evt (uint8_t *p) -{ - BD_ADDR bda; +static void btu_hcif_pin_code_request_evt(uint8_t* p) { + BD_ADDR bda; - STREAM_TO_BDADDR (bda, p); + STREAM_TO_BDADDR(bda, p); - /* Tell L2CAP that there was a PIN code request, */ - /* it may need to stretch timeouts */ - l2c_pin_code_request (bda); + /* Tell L2CAP that there was a PIN code request, */ + /* it may need to stretch timeouts */ + l2c_pin_code_request(bda); - btm_sec_pin_code_request (bda); + btm_sec_pin_code_request(bda); } /******************************************************************************* @@ -1367,12 +1322,11 @@ static void btu_hcif_pin_code_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_link_key_request_evt (uint8_t *p) -{ - BD_ADDR bda; +static void btu_hcif_link_key_request_evt(uint8_t* p) { + BD_ADDR bda; - STREAM_TO_BDADDR (bda, p); - btm_sec_link_key_request (bda); + STREAM_TO_BDADDR(bda, p); + btm_sec_link_key_request(bda); } /******************************************************************************* @@ -1384,17 +1338,16 @@ static void btu_hcif_link_key_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_link_key_notification_evt (uint8_t *p) -{ - BD_ADDR bda; - LINK_KEY key; - uint8_t key_type; +static void btu_hcif_link_key_notification_evt(uint8_t* p) { + BD_ADDR bda; + LINK_KEY key; + uint8_t key_type; - STREAM_TO_BDADDR (bda, p); - STREAM_TO_ARRAY16 (key, p); - STREAM_TO_UINT8 (key_type, p); + STREAM_TO_BDADDR(bda, p); + STREAM_TO_ARRAY16(key, p); + STREAM_TO_UINT8(key_type, p); - btm_sec_link_key_notification (bda, key, key_type); + btm_sec_link_key_notification(bda, key, key_type); } /******************************************************************************* @@ -1406,9 +1359,7 @@ static void btu_hcif_link_key_notification_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_loopback_command_evt (void) -{ -} +static void btu_hcif_loopback_command_evt(void) {} /******************************************************************************* * @@ -1419,9 +1370,7 @@ static void btu_hcif_loopback_command_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_data_buf_overflow_evt (void) -{ -} +static void btu_hcif_data_buf_overflow_evt(void) {} /******************************************************************************* * @@ -1432,9 +1381,7 @@ static void btu_hcif_data_buf_overflow_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_max_slots_changed_evt (void) -{ -} +static void btu_hcif_max_slots_changed_evt(void) {} /******************************************************************************* * @@ -1445,25 +1392,23 @@ static void btu_hcif_max_slots_changed_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_read_clock_off_comp_evt (uint8_t *p) -{ - uint8_t status; - uint16_t handle; - uint16_t clock_offset; +static void btu_hcif_read_clock_off_comp_evt(uint8_t* p) { + uint8_t status; + uint16_t handle; + uint16_t clock_offset; - STREAM_TO_UINT8 (status, p); + STREAM_TO_UINT8(status, p); - /* If failed to get clock offset just drop the result */ - if (status != HCI_SUCCESS) - return; + /* If failed to get clock offset just drop the result */ + if (status != HCI_SUCCESS) return; - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT16 (clock_offset, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(clock_offset, p); - handle = HCID_GET_HANDLE (handle); + handle = HCID_GET_HANDLE(handle); - btm_process_clk_off_comp_evt (handle, clock_offset); - btm_sec_update_clock_offset (handle, clock_offset); + btm_process_clk_off_comp_evt(handle, clock_offset); + btm_sec_update_clock_offset(handle, clock_offset); } /******************************************************************************* @@ -1475,9 +1420,7 @@ static void btu_hcif_read_clock_off_comp_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_conn_pkt_type_change_evt (void) -{ -} +static void btu_hcif_conn_pkt_type_change_evt(void) {} /******************************************************************************* * @@ -1488,15 +1431,14 @@ static void btu_hcif_conn_pkt_type_change_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_qos_violation_evt (uint8_t *p) -{ - uint16_t handle; +static void btu_hcif_qos_violation_evt(uint8_t* p) { + uint16_t handle; - STREAM_TO_UINT16 (handle, p); + STREAM_TO_UINT16(handle, p); - handle = HCID_GET_HANDLE (handle); + handle = HCID_GET_HANDLE(handle); - l2c_link_hci_qos_violation (handle); + l2c_link_hci_qos_violation(handle); } /******************************************************************************* @@ -1508,9 +1450,7 @@ static void btu_hcif_qos_violation_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_page_scan_mode_change_evt (void) -{ -} +static void btu_hcif_page_scan_mode_change_evt(void) {} /******************************************************************************* * @@ -1521,9 +1461,7 @@ static void btu_hcif_page_scan_mode_change_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_page_scan_rep_mode_chng_evt (void) -{ -} +static void btu_hcif_page_scan_rep_mode_chng_evt(void) {} /********************************************** * Simple Pairing Events @@ -1538,9 +1476,8 @@ static void btu_hcif_page_scan_rep_mode_chng_evt (void) * Returns void * ******************************************************************************/ -static void btu_hcif_host_support_evt (uint8_t *p) -{ - btm_sec_rmt_host_support_feat_evt(p); +static void btu_hcif_host_support_evt(uint8_t* p) { + btm_sec_rmt_host_support_feat_evt(p); } /******************************************************************************* @@ -1552,9 +1489,8 @@ static void btu_hcif_host_support_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_io_cap_request_evt (uint8_t *p) -{ - btm_io_capabilities_req(p); +static void btu_hcif_io_cap_request_evt(uint8_t* p) { + btm_io_capabilities_req(p); } /******************************************************************************* @@ -1566,9 +1502,8 @@ static void btu_hcif_io_cap_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_io_cap_response_evt (uint8_t *p) -{ - btm_io_capabilities_rsp(p); +static void btu_hcif_io_cap_response_evt(uint8_t* p) { + btm_io_capabilities_rsp(p); } /******************************************************************************* @@ -1580,9 +1515,8 @@ static void btu_hcif_io_cap_response_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_user_conf_request_evt (uint8_t *p) -{ - btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p); +static void btu_hcif_user_conf_request_evt(uint8_t* p) { + btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p); } /******************************************************************************* @@ -1594,9 +1528,8 @@ static void btu_hcif_user_conf_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_user_passkey_request_evt (uint8_t *p) -{ - btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p); +static void btu_hcif_user_passkey_request_evt(uint8_t* p) { + btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p); } /******************************************************************************* @@ -1608,9 +1541,8 @@ static void btu_hcif_user_passkey_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_user_passkey_notif_evt (uint8_t *p) -{ - btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p); +static void btu_hcif_user_passkey_notif_evt(uint8_t* p) { + btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p); } /******************************************************************************* @@ -1622,9 +1554,8 @@ static void btu_hcif_user_passkey_notif_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_keypress_notif_evt (uint8_t *p) -{ - btm_keypress_notif_evt(p); +static void btu_hcif_keypress_notif_evt(uint8_t* p) { + btm_keypress_notif_evt(p); } /******************************************************************************* @@ -1636,10 +1567,7 @@ static void btu_hcif_keypress_notif_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_rem_oob_request_evt (uint8_t *p) -{ - btm_rem_oob_req(p); -} +static void btu_hcif_rem_oob_request_evt(uint8_t* p) { btm_rem_oob_req(p); } /******************************************************************************* * @@ -1650,9 +1578,8 @@ static void btu_hcif_rem_oob_request_evt (uint8_t *p) * Returns void * ******************************************************************************/ -static void btu_hcif_simple_pair_complete_evt (uint8_t *p) -{ - btm_simple_pair_complete(p); +static void btu_hcif_simple_pair_complete_evt(uint8_t* p) { + btm_simple_pair_complete(p); } /******************************************************************************* @@ -1665,9 +1592,8 @@ static void btu_hcif_simple_pair_complete_evt (uint8_t *p) * ******************************************************************************/ #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) -static void btu_hcif_enhanced_flush_complete_evt (void) -{ -/* This is empty until an upper layer cares about returning event */ +static void btu_hcif_enhanced_flush_complete_evt(void) { + /* This is empty until an upper layer cares about returning event */ } #endif /********************************************** @@ -1677,110 +1603,100 @@ static void btu_hcif_enhanced_flush_complete_evt (void) /********************************************** * BLE Events **********************************************/ -static void btu_hcif_encryption_key_refresh_cmpl_evt (uint8_t *p) -{ - uint8_t status; - uint8_t enc_enable = 0; - uint16_t handle; +static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p) { + uint8_t status; + uint8_t enc_enable = 0; + uint16_t handle; - STREAM_TO_UINT8 (status, p); - STREAM_TO_UINT16 (handle, p); + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); - if (status == HCI_SUCCESS) enc_enable = 1; + if (status == HCI_SUCCESS) enc_enable = 1; - btm_sec_encrypt_change (handle, status, enc_enable); + btm_sec_encrypt_change(handle, status, enc_enable); } -static void btu_ble_process_adv_pkt (uint8_t *p) -{ - HCI_TRACE_EVENT("btu_ble_process_adv_pkt"); +static void btu_ble_process_adv_pkt(uint8_t* p) { + HCI_TRACE_EVENT("btu_ble_process_adv_pkt"); - btm_ble_process_adv_pkt(p); + btm_ble_process_adv_pkt(p); } -static void btu_ble_ll_conn_complete_evt ( uint8_t *p, uint16_t evt_len) -{ - btm_ble_conn_complete(p, evt_len, false); +static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len) { + btm_ble_conn_complete(p, evt_len, false); } #if (BLE_PRIVACY_SPT == TRUE) -static void btu_ble_proc_enhanced_conn_cmpl( uint8_t *p, uint16_t evt_len) -{ - btm_ble_conn_complete(p, evt_len, true); +static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len) { + btm_ble_conn_complete(p, evt_len, true); } #endif -static void btu_ble_ll_conn_param_upd_evt (uint8_t *p, uint16_t evt_len) -{ - /* LE connection update has completed successfully as a master. */ - /* We can enable the update request if the result is a success. */ - /* extract the HCI handle first */ - uint8_t status; - uint16_t handle; - uint16_t interval; - uint16_t latency; - uint16_t timeout; - - STREAM_TO_UINT8(status, p); - STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT16(interval, p); - STREAM_TO_UINT16(latency, p); - STREAM_TO_UINT16(timeout, p); - - l2cble_process_conn_update_evt(handle, status, interval, latency, timeout); +static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len) { + /* LE connection update has completed successfully as a master. */ + /* We can enable the update request if the result is a success. */ + /* extract the HCI handle first */ + uint8_t status; + uint16_t handle; + uint16_t interval; + uint16_t latency; + uint16_t timeout; + + STREAM_TO_UINT8(status, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(interval, p); + STREAM_TO_UINT16(latency, p); + STREAM_TO_UINT16(timeout, p); + + l2cble_process_conn_update_evt(handle, status, interval, latency, timeout); } -static void btu_ble_read_remote_feat_evt (uint8_t *p) -{ - btm_ble_read_remote_features_complete(p); +static void btu_ble_read_remote_feat_evt(uint8_t* p) { + btm_ble_read_remote_features_complete(p); } -static void btu_ble_proc_ltk_req (uint8_t *p) -{ - uint16_t ediv, handle; - uint8_t *pp; +static void btu_ble_proc_ltk_req(uint8_t* p) { + uint16_t ediv, handle; + uint8_t* pp; - STREAM_TO_UINT16(handle, p); - pp = p + 8; - STREAM_TO_UINT16(ediv, pp); - btm_ble_ltk_request(handle, p, ediv); - /* This is empty until an upper layer cares about returning event */ + STREAM_TO_UINT16(handle, p); + pp = p + 8; + STREAM_TO_UINT16(ediv, pp); + btm_ble_ltk_request(handle, p, ediv); + /* This is empty until an upper layer cares about returning event */ } -static void btu_ble_data_length_change_evt(uint8_t *p, uint16_t evt_len) -{ - uint16_t handle; - uint16_t tx_data_len; - uint16_t rx_data_len; +static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len) { + uint16_t handle; + uint16_t tx_data_len; + uint16_t rx_data_len; - if (!controller_get_interface()->supports_ble_packet_extension()) - { - HCI_TRACE_WARNING("%s, request not supported", __func__); - return; - } + if (!controller_get_interface()->supports_ble_packet_extension()) { + HCI_TRACE_WARNING("%s, request not supported", __func__); + return; + } - STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT16(tx_data_len, p); - p += 2; /* Skip the TxTimer */ - STREAM_TO_UINT16(rx_data_len, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(tx_data_len, p); + p += 2; /* Skip the TxTimer */ + STREAM_TO_UINT16(rx_data_len, p); - l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len); + l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len); } /********************************************** * End of BLE Events Handler **********************************************/ #if (BLE_LLT_INCLUDED == TRUE) -static void btu_ble_rc_param_req_evt(uint8_t *p) -{ - uint16_t handle; - uint16_t int_min, int_max, latency, timeout; - - STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT16(int_min, p); - STREAM_TO_UINT16(int_max, p); - STREAM_TO_UINT16(latency, p); - STREAM_TO_UINT16(timeout, p); - - l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, timeout); +static void btu_ble_rc_param_req_evt(uint8_t* p) { + uint16_t handle; + uint16_t int_min, int_max, latency, timeout; + + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(int_min, p); + STREAM_TO_UINT16(int_max, p); + STREAM_TO_UINT16(latency, p); + STREAM_TO_UINT16(timeout, p); + + l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, + timeout); } #endif /* BLE_LLT_INCLUDED */ - diff --git a/stack/btu/btu_init.cc b/stack/btu/btu_init.cc index 404dc5865..7dd480900 100644 --- a/stack/btu/btu_init.cc +++ b/stack/btu/btu_init.cc @@ -40,29 +40,29 @@ // of audio realated tasks. #define BTU_TASK_THREAD_PRIORITY (-19) -extern fixed_queue_t *btif_msg_queue; +extern fixed_queue_t* btif_msg_queue; // Communication queue from bta thread to bt_workqueue. -fixed_queue_t *btu_bta_msg_queue; +fixed_queue_t* btu_bta_msg_queue; // Communication queue from hci thread to bt_workqueue. -extern fixed_queue_t *btu_hci_msg_queue; +extern fixed_queue_t* btu_hci_msg_queue; // General timer queue. -fixed_queue_t *btu_general_alarm_queue; +fixed_queue_t* btu_general_alarm_queue; -thread_t *bt_workqueue_thread; -static const char *BT_WORKQUEUE_NAME = "bt_workqueue"; +thread_t* bt_workqueue_thread; +static const char* BT_WORKQUEUE_NAME = "bt_workqueue"; extern void PLATFORM_DisableHciTransport(uint8_t bDisable); /***************************************************************************** * V A R I A B L E S * *****************************************************************************/ // TODO(cmanton) Move this out of this file -const BD_ADDR BT_BD_ANY = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; +const BD_ADDR BT_BD_ANY = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -void btu_task_start_up(void *context); -void btu_task_shut_down(void *context); +void btu_task_start_up(void* context); +void btu_task_shut_down(void* context); /***************************************************************************** * @@ -74,20 +74,19 @@ void btu_task_shut_down(void *context); * Returns void * *****************************************************************************/ -void btu_init_core(void) -{ - /* Initialize the mandatory core stack components */ - btm_init(); +void btu_init_core(void) { + /* Initialize the mandatory core stack components */ + btm_init(); - l2c_init(); + l2c_init(); - sdp_init(); + sdp_init(); - gatt_init(); + gatt_init(); - SMP_Init(); + SMP_Init(); - btm_ble_init(); + btm_ble_init(); } /***************************************************************************** @@ -100,12 +99,11 @@ void btu_init_core(void) * Returns void * *****************************************************************************/ -void btu_free_core(void) -{ - /* Free the mandatory core stack components */ - l2c_free(); +void btu_free_core(void) { + /* Free the mandatory core stack components */ + l2c_free(); - gatt_free(); + gatt_free(); } /***************************************************************************** @@ -120,31 +118,28 @@ void btu_free_core(void) * Returns void * *****************************************************************************/ -void BTU_StartUp(void) -{ - btu_trace_level = HCI_INITIAL_TRACE_LEVEL; +void BTU_StartUp(void) { + btu_trace_level = HCI_INITIAL_TRACE_LEVEL; - btu_bta_msg_queue = fixed_queue_new(SIZE_MAX); - if (btu_bta_msg_queue == NULL) - goto error_exit; + btu_bta_msg_queue = fixed_queue_new(SIZE_MAX); + if (btu_bta_msg_queue == NULL) goto error_exit; - btu_general_alarm_queue = fixed_queue_new(SIZE_MAX); - if (btu_general_alarm_queue == NULL) - goto error_exit; + btu_general_alarm_queue = fixed_queue_new(SIZE_MAX); + if (btu_general_alarm_queue == NULL) goto error_exit; - bt_workqueue_thread = thread_new(BT_WORKQUEUE_NAME); - if (bt_workqueue_thread == NULL) - goto error_exit; + bt_workqueue_thread = thread_new(BT_WORKQUEUE_NAME); + if (bt_workqueue_thread == NULL) goto error_exit; - thread_set_priority(bt_workqueue_thread, BTU_TASK_THREAD_PRIORITY); + thread_set_priority(bt_workqueue_thread, BTU_TASK_THREAD_PRIORITY); - // Continue startup on bt workqueue thread. - thread_post(bt_workqueue_thread, btu_task_start_up, NULL); - return; + // Continue startup on bt workqueue thread. + thread_post(bt_workqueue_thread, btu_task_start_up, NULL); + return; - error_exit:; - LOG_ERROR(LOG_TAG, "%s Unable to allocate resources for bt_workqueue", __func__); - BTU_ShutDown(); +error_exit:; + LOG_ERROR(LOG_TAG, "%s Unable to allocate resources for bt_workqueue", + __func__); + BTU_ShutDown(); } void BTU_ShutDown(void) { diff --git a/stack/btu/btu_task.cc b/stack/btu/btu_task.cc index 81a1f8316..8b9119865 100644 --- a/stack/btu/btu_task.cc +++ b/stack/btu/btu_task.cc @@ -24,6 +24,7 @@ #include #include +#include "bt_common.h" #include "bt_target.h" #include "bt_trace.h" #include "bt_types.h" @@ -35,7 +36,6 @@ #include "btm_int.h" #include "btu.h" #include "gap_int.h" -#include "bt_common.h" #include "hcimsgs.h" #include "l2c_int.h" #include "osi/include/alarm.h" @@ -63,7 +63,7 @@ #if (AVDT_INCLUDED == TRUE) #include "avdt_int.h" #else -extern void avdt_rcv_sync_info (BT_HDR *p_buf); /* this is for hci_test */ +extern void avdt_rcv_sync_info(BT_HDR* p_buf); /* this is for hci_test */ #endif #if (MCA_INCLUDED == TRUE) @@ -77,95 +77,93 @@ extern void avdt_rcv_sync_info (BT_HDR *p_buf); /* this is for hci_test */ #include "gatt_int.h" #include "smp_int.h" - - /* Define BTU storage area */ uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL; // Communication queue between btu_task and bta. -extern fixed_queue_t *btu_bta_msg_queue; +extern fixed_queue_t* btu_bta_msg_queue; // Communication queue between btu_task and hci. -extern fixed_queue_t *btu_hci_msg_queue; +extern fixed_queue_t* btu_hci_msg_queue; // General timer queue. -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; -extern fixed_queue_t *event_queue; -extern fixed_queue_t *btif_msg_queue; +extern fixed_queue_t* event_queue; +extern fixed_queue_t* btif_msg_queue; -extern thread_t *bt_workqueue_thread; +extern thread_t* bt_workqueue_thread; -static void btu_hci_msg_process(BT_HDR *p_msg); +static void btu_hci_msg_process(BT_HDR* p_msg); -void btu_hci_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { - BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue); - btu_hci_msg_process(p_msg); +void btu_hci_msg_ready(fixed_queue_t* queue, UNUSED_ATTR void* context) { + BT_HDR* p_msg = (BT_HDR*)fixed_queue_dequeue(queue); + btu_hci_msg_process(p_msg); } -void btu_bta_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) { - BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue); - bta_sys_event(p_msg); +void btu_bta_msg_ready(fixed_queue_t* queue, UNUSED_ATTR void* context) { + BT_HDR* p_msg = (BT_HDR*)fixed_queue_dequeue(queue); + bta_sys_event(p_msg); } -static void btu_hci_msg_process(BT_HDR *p_msg) { - /* Determine the input message type. */ - switch (p_msg->event & BT_EVT_MASK) - { - case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this - ((post_to_task_hack_t *)(&p_msg->data[0]))->callback(p_msg); +static void btu_hci_msg_process(BT_HDR* p_msg) { + /* Determine the input message type. */ + switch (p_msg->event & BT_EVT_MASK) { + case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove + // this + ((post_to_task_hack_t*)(&p_msg->data[0]))->callback(p_msg); #if (HCILP_INCLUDED == TRUE) - /* If the host receives events which it doesn't responsd to, */ - /* it should start an idle timer to enter sleep mode. */ - btu_check_bt_sleep (); + /* If the host receives events which it doesn't responsd to, */ + /* it should start an idle timer to enter sleep mode. */ + btu_check_bt_sleep(); #endif - break; - case BT_EVT_TO_BTU_HCI_ACL: - /* All Acl Data goes to L2CAP */ - l2c_rcv_acl_data (p_msg); - break; - - case BT_EVT_TO_BTU_L2C_SEG_XMIT: - /* L2CAP segment transmit complete */ - l2c_link_segments_xmitted (p_msg); - break; - - case BT_EVT_TO_BTU_HCI_SCO: + break; + case BT_EVT_TO_BTU_HCI_ACL: + /* All Acl Data goes to L2CAP */ + l2c_rcv_acl_data(p_msg); + break; + + case BT_EVT_TO_BTU_L2C_SEG_XMIT: + /* L2CAP segment transmit complete */ + l2c_link_segments_xmitted(p_msg); + break; + + case BT_EVT_TO_BTU_HCI_SCO: #if (BTM_SCO_INCLUDED == TRUE) - btm_route_sco_data (p_msg); - break; + btm_route_sco_data(p_msg); + break; #endif - case BT_EVT_TO_BTU_HCI_EVT: - btu_hcif_process_event ((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg); - osi_free(p_msg); + case BT_EVT_TO_BTU_HCI_EVT: + btu_hcif_process_event((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg); + osi_free(p_msg); #if (HCILP_INCLUDED == TRUE) - /* If host receives events which it doesn't response to, */ - /* host should start idle timer to enter sleep mode. */ - btu_check_bt_sleep (); + /* If host receives events which it doesn't response to, */ + /* host should start idle timer to enter sleep mode. */ + btu_check_bt_sleep(); #endif - break; + break; - case BT_EVT_TO_BTU_HCI_CMD: - btu_hcif_send_cmd ((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg); - break; + case BT_EVT_TO_BTU_HCI_CMD: + btu_hcif_send_cmd((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg); + break; - default: - osi_free(p_msg); - break; - } + default: + osi_free(p_msg); + break; + } } -void btu_task_start_up(UNUSED_ATTR void *context) { +void btu_task_start_up(UNUSED_ATTR void* context) { BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, - "btu_task pending for preload complete event"); + "btu_task pending for preload complete event"); LOG_INFO(LOG_TAG, "Bluetooth chip preload is complete"); BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, - "btu_task received preload complete event"); + "btu_task received preload complete event"); /* Initialize the mandatory core stack control blocks (BTU, BTM, L2CAP, and SDP) @@ -177,8 +175,10 @@ void btu_task_start_up(UNUSED_ATTR void *context) { bta_sys_init(); - /* Initialise platform trace levels at this point as BTE_InitStack() and bta_sys_init() - * reset the control blocks and preset the trace level with XXX_INITIAL_TRACE_LEVEL + /* Initialise platform trace levels at this point as BTE_InitStack() and + * bta_sys_init() + * reset the control blocks and preset the trace level with + * XXX_INITIAL_TRACE_LEVEL */ module_init(get_module(BTE_LOGMSG_MODULE)); @@ -186,19 +186,17 @@ void btu_task_start_up(UNUSED_ATTR void *context) { btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL); fixed_queue_register_dequeue(btu_bta_msg_queue, - thread_get_reactor(bt_workqueue_thread), - btu_bta_msg_ready, - NULL); + thread_get_reactor(bt_workqueue_thread), + btu_bta_msg_ready, NULL); fixed_queue_register_dequeue(btu_hci_msg_queue, - thread_get_reactor(bt_workqueue_thread), - btu_hci_msg_ready, - NULL); + thread_get_reactor(bt_workqueue_thread), + btu_hci_msg_ready, NULL); alarm_register_processing_queue(btu_general_alarm_queue, bt_workqueue_thread); } -void btu_task_shut_down(UNUSED_ATTR void *context) { +void btu_task_shut_down(UNUSED_ATTR void* context) { fixed_queue_unregister_dequeue(btu_bta_msg_queue); fixed_queue_unregister_dequeue(btu_hci_msg_queue); alarm_unregister_processing_queue(btu_general_alarm_queue); @@ -220,12 +218,10 @@ void btu_task_shut_down(UNUSED_ATTR void *context) { * Returns void * ******************************************************************************/ -void btu_check_bt_sleep (void) -{ - // TODO(zachoverflow) take pending commands into account? - if (l2cb.controller_xmit_window == l2cb.num_lm_acl_bufs) - { - bte_main_lpm_allow_bt_device_sleep(); - } +void btu_check_bt_sleep(void) { + // TODO(zachoverflow) take pending commands into account? + if (l2cb.controller_xmit_window == l2cb.num_lm_acl_bufs) { + bte_main_lpm_allow_bt_device_sleep(); + } } #endif diff --git a/stack/gap/gap_api.cc b/stack/gap/gap_api.cc index 2b385a168..994ba65ce 100644 --- a/stack/gap/gap_api.cc +++ b/stack/gap/gap_api.cc @@ -22,7 +22,7 @@ #include "bt_utils.h" #include "gap_int.h" -tGAP_CB gap_cb; +tGAP_CB gap_cb; /******************************************************************************* * @@ -34,12 +34,10 @@ tGAP_CB gap_cb; * Returns The new or current trace level * ******************************************************************************/ -uint8_t GAP_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - gap_cb.trace_level = new_level; +uint8_t GAP_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) gap_cb.trace_level = new_level; - return (gap_cb.trace_level); + return (gap_cb.trace_level); } /******************************************************************************* @@ -54,20 +52,18 @@ uint8_t GAP_SetTraceLevel (uint8_t new_level) * Returns Nothing * ******************************************************************************/ -void GAP_Init(void) -{ - memset (&gap_cb, 0, sizeof (tGAP_CB)); +void GAP_Init(void) { + memset(&gap_cb, 0, sizeof(tGAP_CB)); #if defined(GAP_INITIAL_TRACE_LEVEL) - gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL; + gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL; #else - gap_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + gap_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif #if (GAP_CONN_INCLUDED == TRUE) - gap_conn_init(); + gap_conn_init(); #endif - gap_attr_db_init(); + gap_attr_db_init(); } - diff --git a/stack/gap/gap_ble.cc b/stack/gap/gap_ble.cc index e8f20ee19..48f55e1e6 100644 --- a/stack/gap/gap_ble.cc +++ b/stack/gap/gap_ble.cc @@ -17,48 +17,50 @@ ******************************************************************************/ #include "bt_target.h" -#include "bt_utils.h" #include -#include "gap_int.h" +#include "bt_utils.h" +#include "btcore/include/uuid.h" +#include "btm_int.h" #include "gap_api.h" -#include "gattdefs.h" +#include "gap_int.h" #include "gatt_api.h" #include "gatt_int.h" -#include "btm_int.h" +#include "gattdefs.h" #include "hcimsgs.h" -#include "btcore/include/uuid.h" #include "osi/include/osi.h" -#define GAP_CHAR_ICON_SIZE 2 -#define GAP_CHAR_DEV_NAME_SIZE 248 -#define GAP_MAX_NUM_INC_SVR 0 -#define GAP_MAX_ATTR_NUM (2 * GAP_MAX_CHAR_NUM + GAP_MAX_NUM_INC_SVR + 1) -#define GAP_MAX_CHAR_VALUE_SIZE (30 + GAP_CHAR_DEV_NAME_SIZE) - +#define GAP_CHAR_ICON_SIZE 2 +#define GAP_CHAR_DEV_NAME_SIZE 248 +#define GAP_MAX_NUM_INC_SVR 0 +#define GAP_MAX_ATTR_NUM (2 * GAP_MAX_CHAR_NUM + GAP_MAX_NUM_INC_SVR + 1) +#define GAP_MAX_CHAR_VALUE_SIZE (30 + GAP_CHAR_DEV_NAME_SIZE) #ifndef GAP_ATTR_DB_SIZE -#define GAP_ATTR_DB_SIZE GATT_DB_MEM_SIZE(GAP_MAX_NUM_INC_SVR, GAP_MAX_CHAR_NUM, GAP_MAX_CHAR_VALUE_SIZE) +#define GAP_ATTR_DB_SIZE \ + GATT_DB_MEM_SIZE(GAP_MAX_NUM_INC_SVR, GAP_MAX_CHAR_NUM, \ + GAP_MAX_CHAR_VALUE_SIZE) #endif -static void gap_ble_s_attr_request_cback (uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE op_code, tGATTS_DATA *p_data); +static void gap_ble_s_attr_request_cback(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE op_code, + tGATTS_DATA* p_data); /* client connection callback */ -static void gap_ble_c_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, uint16_t conn_id, bool connected, - tGATT_DISCONN_REASON reason, tGATT_TRANSPORT transport); -static void gap_ble_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); - -static tGATT_CBACK gap_cback = -{ - gap_ble_c_connect_cback, - gap_ble_c_cmpl_cback, - NULL, - NULL, - gap_ble_s_attr_request_cback, - NULL, - NULL -}; - - +static void gap_ble_c_connect_cback(tGATT_IF gatt_if, BD_ADDR bda, + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + tGATT_TRANSPORT transport); +static void gap_ble_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, + tGATT_STATUS status, + tGATT_CL_COMPLETE* p_data); + +static tGATT_CBACK gap_cback = {gap_ble_c_connect_cback, + gap_ble_c_cmpl_cback, + NULL, + NULL, + gap_ble_s_attr_request_cback, + NULL, + NULL}; /******************************************************************************* * @@ -69,20 +71,18 @@ static tGATT_CBACK gap_cback = * Returns total number of clcb found. * ******************************************************************************/ -tGAP_CLCB *gap_find_clcb_by_bd_addr(BD_ADDR bda) -{ - uint8_t i_clcb; - tGAP_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) - { - return p_clcb; - } +tGAP_CLCB* gap_find_clcb_by_bd_addr(BD_ADDR bda) { + uint8_t i_clcb; + tGAP_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = gap_cb.clcb; i_clcb < GAP_MAX_CL; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) { + return p_clcb; } + } - return NULL; + return NULL; } /******************************************************************************* @@ -94,20 +94,18 @@ tGAP_CLCB *gap_find_clcb_by_bd_addr(BD_ADDR bda) * Returns total number of clcb found. * ******************************************************************************/ -tGAP_CLCB *gap_ble_find_clcb_by_conn_id(uint16_t conn_id) -{ - uint8_t i_clcb; - tGAP_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) - { - return p_clcb; - } +tGAP_CLCB* gap_ble_find_clcb_by_conn_id(uint16_t conn_id) { + uint8_t i_clcb; + tGAP_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = gap_cb.clcb; i_clcb < GAP_MAX_CL; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) { + return p_clcb; } + } - return p_clcb; + return p_clcb; } /******************************************************************************* @@ -120,24 +118,22 @@ tGAP_CLCB *gap_ble_find_clcb_by_conn_id(uint16_t conn_id) * block. * ******************************************************************************/ -tGAP_CLCB *gap_clcb_alloc (BD_ADDR bda) -{ - uint8_t i_clcb = 0; - tGAP_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) - { - if (!p_clcb->in_use) - { - fixed_queue_free(p_clcb->pending_req_q, NULL); - memset(p_clcb, 0, sizeof(tGAP_CLCB)); - p_clcb->in_use = true; - memcpy (p_clcb->bda, bda, BD_ADDR_LEN); - p_clcb->pending_req_q = fixed_queue_new(SIZE_MAX); - break; - } +tGAP_CLCB* gap_clcb_alloc(BD_ADDR bda) { + uint8_t i_clcb = 0; + tGAP_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = gap_cb.clcb; i_clcb < GAP_MAX_CL; + i_clcb++, p_clcb++) { + if (!p_clcb->in_use) { + fixed_queue_free(p_clcb->pending_req_q, NULL); + memset(p_clcb, 0, sizeof(tGAP_CLCB)); + p_clcb->in_use = true; + memcpy(p_clcb->bda, bda, BD_ADDR_LEN); + p_clcb->pending_req_q = fixed_queue_new(SIZE_MAX); + break; } - return p_clcb; + } + return p_clcb; } /******************************************************************************* @@ -149,21 +145,19 @@ tGAP_CLCB *gap_clcb_alloc (BD_ADDR bda) * Returns none * ******************************************************************************/ -void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb) -{ - tGAP_BLE_REQ *p_q; +void gap_ble_dealloc_clcb(tGAP_CLCB* p_clcb) { + tGAP_BLE_REQ* p_q; - while ((p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q)) != NULL) - { - /* send callback to all pending requests if being removed*/ - if (p_q->p_cback != NULL) - (*p_q->p_cback)(false, p_clcb->bda, 0, NULL); + while ((p_q = (tGAP_BLE_REQ*)fixed_queue_try_dequeue( + p_clcb->pending_req_q)) != NULL) { + /* send callback to all pending requests if being removed*/ + if (p_q->p_cback != NULL) (*p_q->p_cback)(false, p_clcb->bda, 0, NULL); - osi_free(p_q); - } - fixed_queue_free(p_clcb->pending_req_q, NULL); + osi_free(p_q); + } + fixed_queue_free(p_clcb->pending_req_q, NULL); - memset(p_clcb, 0, sizeof(tGAP_CLCB)); + memset(p_clcb, 0, sizeof(tGAP_CLCB)); } /******************************************************************************* @@ -175,15 +169,15 @@ void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb) * Returns true is successul; false otherwise * ******************************************************************************/ -bool gap_ble_enqueue_request (tGAP_CLCB *p_clcb, uint16_t uuid, tGAP_BLE_CMPL_CBACK *p_cback) -{ - tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)osi_malloc(sizeof(tGAP_BLE_REQ)); +bool gap_ble_enqueue_request(tGAP_CLCB* p_clcb, uint16_t uuid, + tGAP_BLE_CMPL_CBACK* p_cback) { + tGAP_BLE_REQ* p_q = (tGAP_BLE_REQ*)osi_malloc(sizeof(tGAP_BLE_REQ)); - p_q->p_cback = p_cback; - p_q->uuid = uuid; - fixed_queue_enqueue(p_clcb->pending_req_q, p_q); + p_q->p_cback = p_cback; + p_q->uuid = uuid; + fixed_queue_enqueue(p_clcb->pending_req_q, p_q); - return true; + return true; } /******************************************************************************* @@ -195,100 +189,100 @@ bool gap_ble_enqueue_request (tGAP_CLCB *p_clcb, uint16_t uuid, tGAP_BLE_CMPL * Returns true is successul; false otherwise * ******************************************************************************/ -bool gap_ble_dequeue_request (tGAP_CLCB *p_clcb, uint16_t * p_uuid, tGAP_BLE_CMPL_CBACK **p_cback) -{ - tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q);; - - if (p_q != NULL) - { - *p_cback = p_q->p_cback; - *p_uuid = p_q->uuid; - osi_free(p_q); - return true; - } +bool gap_ble_dequeue_request(tGAP_CLCB* p_clcb, uint16_t* p_uuid, + tGAP_BLE_CMPL_CBACK** p_cback) { + tGAP_BLE_REQ* p_q = + (tGAP_BLE_REQ*)fixed_queue_try_dequeue(p_clcb->pending_req_q); + ; + + if (p_q != NULL) { + *p_cback = p_q->p_cback; + *p_uuid = p_q->uuid; + osi_free(p_q); + return true; + } - return false; + return false; } /******************************************************************************* * GAP Attributes Database Request callback ******************************************************************************/ -tGATT_STATUS gap_read_attr_value (uint16_t handle, tGATT_VALUE *p_value, bool is_long) -{ - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; - uint8_t *p = p_value->value, i; - uint16_t offset = p_value->offset; - uint8_t *p_dev_name = NULL; - - for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) - { - if (handle == p_db_attr->handle) - { - if (p_db_attr->uuid != GATT_UUID_GAP_DEVICE_NAME && - is_long == true) - return GATT_NOT_LONG; - - switch (p_db_attr->uuid) - { - case GATT_UUID_GAP_DEVICE_NAME: - BTM_ReadLocalDeviceName((char **)&p_dev_name); - if (strlen ((char *)p_dev_name) > GATT_MAX_ATTR_LEN) - p_value->len = GATT_MAX_ATTR_LEN; - else - p_value->len = (uint16_t)strlen ((char *)p_dev_name); - - if (offset > p_value->len) - return GATT_INVALID_OFFSET; - else - { - p_value->len -= offset; - p_dev_name += offset; - ARRAY_TO_STREAM(p, p_dev_name, p_value->len); - GAP_TRACE_EVENT("GATT_UUID_GAP_DEVICE_NAME len=0x%04x", p_value->len); - } - break; - - case GATT_UUID_GAP_ICON: - UINT16_TO_STREAM(p, p_db_attr->attr_value.icon); - p_value->len = 2; - break; - - case GATT_UUID_GAP_PREF_CONN_PARAM: - UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.int_min); /* int_min */ - UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.int_max); /* int_max */ - UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.latency); /* latency */ - UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.sp_tout); /* sp_tout */ - p_value->len =8; - break; - - /* address resolution */ - case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: - UINT8_TO_STREAM(p, p_db_attr->attr_value.addr_resolution); - p_value->len =1; - break; - } - return GATT_SUCCESS; - } +tGATT_STATUS gap_read_attr_value(uint16_t handle, tGATT_VALUE* p_value, + bool is_long) { + tGAP_ATTR* p_db_attr = gap_cb.gatt_attr; + uint8_t *p = p_value->value, i; + uint16_t offset = p_value->offset; + uint8_t* p_dev_name = NULL; + + for (i = 0; i < GAP_MAX_CHAR_NUM; i++, p_db_attr++) { + if (handle == p_db_attr->handle) { + if (p_db_attr->uuid != GATT_UUID_GAP_DEVICE_NAME && is_long == true) + return GATT_NOT_LONG; + + switch (p_db_attr->uuid) { + case GATT_UUID_GAP_DEVICE_NAME: + BTM_ReadLocalDeviceName((char**)&p_dev_name); + if (strlen((char*)p_dev_name) > GATT_MAX_ATTR_LEN) + p_value->len = GATT_MAX_ATTR_LEN; + else + p_value->len = (uint16_t)strlen((char*)p_dev_name); + + if (offset > p_value->len) + return GATT_INVALID_OFFSET; + else { + p_value->len -= offset; + p_dev_name += offset; + ARRAY_TO_STREAM(p, p_dev_name, p_value->len); + GAP_TRACE_EVENT("GATT_UUID_GAP_DEVICE_NAME len=0x%04x", + p_value->len); + } + break; + + case GATT_UUID_GAP_ICON: + UINT16_TO_STREAM(p, p_db_attr->attr_value.icon); + p_value->len = 2; + break; + + case GATT_UUID_GAP_PREF_CONN_PARAM: + UINT16_TO_STREAM( + p, p_db_attr->attr_value.conn_param.int_min); /* int_min */ + UINT16_TO_STREAM( + p, p_db_attr->attr_value.conn_param.int_max); /* int_max */ + UINT16_TO_STREAM( + p, p_db_attr->attr_value.conn_param.latency); /* latency */ + UINT16_TO_STREAM( + p, p_db_attr->attr_value.conn_param.sp_tout); /* sp_tout */ + p_value->len = 8; + break; + + /* address resolution */ + case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: + UINT8_TO_STREAM(p, p_db_attr->attr_value.addr_resolution); + p_value->len = 1; + break; + } + return GATT_SUCCESS; } - return GATT_NOT_FOUND; + } + return GATT_NOT_FOUND; } /******************************************************************************* * GAP Attributes Database Read/Read Blob Request process ******************************************************************************/ -tGATT_STATUS gap_proc_read (UNUSED_ATTR tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, - tGATTS_RSP *p_rsp) -{ - tGATT_STATUS status = GATT_NO_RESOURCES; +tGATT_STATUS gap_proc_read(UNUSED_ATTR tGATTS_REQ_TYPE type, + tGATT_READ_REQ* p_data, tGATTS_RSP* p_rsp) { + tGATT_STATUS status = GATT_NO_RESOURCES; - if (p_data->is_long) - p_rsp->attr_value.offset = p_data->offset; + if (p_data->is_long) p_rsp->attr_value.offset = p_data->offset; - p_rsp->attr_value.handle = p_data->handle; + p_rsp->attr_value.handle = p_data->handle; - status = gap_read_attr_value(p_data->handle, &p_rsp->attr_value, p_data->is_long); + status = + gap_read_attr_value(p_data->handle, &p_rsp->attr_value, p_data->is_long); - return status; + return status; } /****************************************************************************** @@ -300,20 +294,17 @@ tGATT_STATUS gap_proc_read (UNUSED_ATTR tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_ * Returns void. * ******************************************************************************/ -uint8_t gap_proc_write_req(UNUSED_ATTR tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data) -{ - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; - uint8_t i; - - for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) - { - if (p_data-> handle == p_db_attr->handle) - { - return GATT_WRITE_NOT_PERMIT; - } +uint8_t gap_proc_write_req(UNUSED_ATTR tGATTS_REQ_TYPE type, + tGATT_WRITE_REQ* p_data) { + tGAP_ATTR* p_db_attr = gap_cb.gatt_attr; + uint8_t i; + + for (i = 0; i < GAP_MAX_CHAR_NUM; i++, p_db_attr++) { + if (p_data->handle == p_db_attr->handle) { + return GATT_WRITE_NOT_PERMIT; } - return GATT_NOT_FOUND; - + } + return GATT_NOT_FOUND; } /****************************************************************************** @@ -325,49 +316,45 @@ uint8_t gap_proc_write_req(UNUSED_ATTR tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_ * Returns void. * ******************************************************************************/ -void gap_ble_s_attr_request_cback (uint16_t conn_id, uint32_t trans_id, - tGATTS_REQ_TYPE type, tGATTS_DATA *p_data) -{ - uint8_t status = GATT_INVALID_PDU; - tGATTS_RSP rsp_msg; - bool ignore = false; - - GAP_TRACE_EVENT("gap_ble_s_attr_request_cback : recv type (0x%02x)", type); - - memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); - - switch (type) - { - case GATTS_REQ_TYPE_READ_CHARACTERISTIC: - case GATTS_REQ_TYPE_READ_DESCRIPTOR: - status = gap_proc_read(type, &p_data->read_req, &rsp_msg); - break; - - case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: - case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: - if (!p_data->write_req.need_rsp) - ignore = true; - - status = gap_proc_write_req(type, &p_data->write_req); - break; - - case GATTS_REQ_TYPE_WRITE_EXEC: - ignore = true; - GAP_TRACE_EVENT("Ignore GATTS_REQ_TYPE_WRITE_EXEC" ); - break; - - case GATTS_REQ_TYPE_MTU: - GAP_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); - ignore = true; - break; - - default: - GAP_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); - break; - } +void gap_ble_s_attr_request_cback(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { + uint8_t status = GATT_INVALID_PDU; + tGATTS_RSP rsp_msg; + bool ignore = false; + + GAP_TRACE_EVENT("gap_ble_s_attr_request_cback : recv type (0x%02x)", type); + + memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); + + switch (type) { + case GATTS_REQ_TYPE_READ_CHARACTERISTIC: + case GATTS_REQ_TYPE_READ_DESCRIPTOR: + status = gap_proc_read(type, &p_data->read_req, &rsp_msg); + break; + + case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: + case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: + if (!p_data->write_req.need_rsp) ignore = true; + + status = gap_proc_write_req(type, &p_data->write_req); + break; + + case GATTS_REQ_TYPE_WRITE_EXEC: + ignore = true; + GAP_TRACE_EVENT("Ignore GATTS_REQ_TYPE_WRITE_EXEC"); + break; + + case GATTS_REQ_TYPE_MTU: + GAP_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); + ignore = true; + break; + + default: + GAP_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); + break; + } - if (!ignore) - GATTS_SendRsp (conn_id, trans_id, status, &rsp_msg); + if (!ignore) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg); } /******************************************************************************* @@ -379,60 +366,77 @@ void gap_ble_s_attr_request_cback (uint16_t conn_id, uint32_t trans_id, * Returns void. * ******************************************************************************/ -void gap_attr_db_init(void) -{ - tBT_UUID app_uuid = {LEN_UUID_128,{0}}; - uint16_t service_handle; - - /* Fill our internal UUID with a fixed pattern 0x82 */ - memset (&app_uuid.uu.uuid128, 0x82, LEN_UUID_128); - memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM); - - gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback); - - GATT_StartIf(gap_cb.gatt_if); - - bt_uuid_t svc_uuid, name_uuid, icon_uuid, pref_uuid, addr_res_uuid; - uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_GAP_SERVER); - uuid_128_from_16(&name_uuid, GATT_UUID_GAP_DEVICE_NAME); - uuid_128_from_16(&icon_uuid, GATT_UUID_GAP_ICON); - uuid_128_from_16(&pref_uuid, GATT_UUID_GAP_PREF_CONN_PARAM); - uuid_128_from_16(&addr_res_uuid, GATT_UUID_GAP_CENTRAL_ADDR_RESOL); - - btgatt_db_element_t service[] = { - {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = svc_uuid}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid = name_uuid, .properties = GATT_CHAR_PROP_BIT_READ, .permissions = GATT_PERM_READ}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid = icon_uuid, .properties = GATT_CHAR_PROP_BIT_READ, .permissions = GATT_PERM_READ}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid = addr_res_uuid, .properties = GATT_CHAR_PROP_BIT_READ, .permissions = GATT_PERM_READ} -#if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */ - ,{.type = BTGATT_DB_CHARACTERISTIC, .uuid = pref_uuid, .properties = GATT_CHAR_PROP_BIT_READ, .permissions = GATT_PERM_READ} +void gap_attr_db_init(void) { + tBT_UUID app_uuid = {LEN_UUID_128, {0}}; + uint16_t service_handle; + + /* Fill our internal UUID with a fixed pattern 0x82 */ + memset(&app_uuid.uu.uuid128, 0x82, LEN_UUID_128); + memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) * GAP_MAX_CHAR_NUM); + + gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback); + + GATT_StartIf(gap_cb.gatt_if); + + bt_uuid_t svc_uuid, name_uuid, icon_uuid, pref_uuid, addr_res_uuid; + uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_GAP_SERVER); + uuid_128_from_16(&name_uuid, GATT_UUID_GAP_DEVICE_NAME); + uuid_128_from_16(&icon_uuid, GATT_UUID_GAP_ICON); + uuid_128_from_16(&pref_uuid, GATT_UUID_GAP_PREF_CONN_PARAM); + uuid_128_from_16(&addr_res_uuid, GATT_UUID_GAP_CENTRAL_ADDR_RESOL); + + btgatt_db_element_t service[] = { + {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = svc_uuid}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = name_uuid, + .properties = GATT_CHAR_PROP_BIT_READ, + .permissions = GATT_PERM_READ}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = icon_uuid, + .properties = GATT_CHAR_PROP_BIT_READ, + .permissions = GATT_PERM_READ}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = addr_res_uuid, + .properties = GATT_CHAR_PROP_BIT_READ, + .permissions = GATT_PERM_READ} +#if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */ + , + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = pref_uuid, + .properties = GATT_CHAR_PROP_BIT_READ, + .permissions = GATT_PERM_READ} #endif - }; + }; - /* Add a GAP service */ - GATTS_AddService(gap_cb.gatt_if, service, sizeof(service)/sizeof(btgatt_db_element_t)); - service_handle = service[0].attribute_handle; + /* Add a GAP service */ + GATTS_AddService(gap_cb.gatt_if, service, + sizeof(service) / sizeof(btgatt_db_element_t)); + service_handle = service[0].attribute_handle; - GAP_TRACE_EVENT("%s: service_handle = %d",__func__, service_handle); + GAP_TRACE_EVENT("%s: service_handle = %d", __func__, service_handle); - gap_cb.gatt_attr[0].uuid = GATT_UUID_GAP_DEVICE_NAME; - gap_cb.gatt_attr[0].handle = service[1].attribute_handle; + gap_cb.gatt_attr[0].uuid = GATT_UUID_GAP_DEVICE_NAME; + gap_cb.gatt_attr[0].handle = service[1].attribute_handle; - gap_cb.gatt_attr[1].uuid = GATT_UUID_GAP_ICON; - gap_cb.gatt_attr[1].handle = service[2].attribute_handle; + gap_cb.gatt_attr[1].uuid = GATT_UUID_GAP_ICON; + gap_cb.gatt_attr[1].handle = service[2].attribute_handle; - gap_cb.gatt_attr[2].uuid = GATT_UUID_GAP_CENTRAL_ADDR_RESOL; - gap_cb.gatt_attr[2].handle = service[3].attribute_handle; - gap_cb.gatt_attr[2].attr_value.addr_resolution = 0; + gap_cb.gatt_attr[2].uuid = GATT_UUID_GAP_CENTRAL_ADDR_RESOL; + gap_cb.gatt_attr[2].handle = service[3].attribute_handle; + gap_cb.gatt_attr[2].attr_value.addr_resolution = 0; -#if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */ +#if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */ - gap_cb.gatt_attr[3].uuid = GATT_UUID_GAP_PREF_CONN_PARAM; - gap_cb.gatt_attr[3].attr_value.conn_param.int_max = GAP_PREFER_CONN_INT_MAX; /* 6 */ - gap_cb.gatt_attr[3].attr_value.conn_param.int_min = GAP_PREFER_CONN_INT_MIN; /* 0 */ - gap_cb.gatt_attr[3].attr_value.conn_param.latency = GAP_PREFER_CONN_LATENCY; /* 0 */ - gap_cb.gatt_attr[3].attr_value.conn_param.sp_tout = GAP_PREFER_CONN_SP_TOUT; /* 2000 */ - gap_cb.gatt_attr[3].handle = service[4].attribute_handle; + gap_cb.gatt_attr[3].uuid = GATT_UUID_GAP_PREF_CONN_PARAM; + gap_cb.gatt_attr[3].attr_value.conn_param.int_max = + GAP_PREFER_CONN_INT_MAX; /* 6 */ + gap_cb.gatt_attr[3].attr_value.conn_param.int_min = + GAP_PREFER_CONN_INT_MIN; /* 0 */ + gap_cb.gatt_attr[3].attr_value.conn_param.latency = + GAP_PREFER_CONN_LATENCY; /* 0 */ + gap_cb.gatt_attr[3].attr_value.conn_param.sp_tout = + GAP_PREFER_CONN_SP_TOUT; /* 2000 */ + gap_cb.gatt_attr[3].handle = service[4].attribute_handle; #endif } @@ -445,44 +449,40 @@ void gap_attr_db_init(void) * Returns void. * ******************************************************************************/ -void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) -{ - tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; - uint8_t i = 0; - - GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x", attr_uuid); - - for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) - { - if (p_db_attr->uuid == attr_uuid) - { - GAP_TRACE_EVENT("Found attr_uuid=0x%04x", attr_uuid); - - switch (attr_uuid) - { - case GATT_UUID_GAP_ICON: - p_db_attr->attr_value.icon = p_value->icon; - break; - - case GATT_UUID_GAP_PREF_CONN_PARAM: - memcpy((void *)&p_db_attr->attr_value.conn_param, - (const void *)&p_value->conn_param, sizeof(tGAP_BLE_PREF_PARAM)); - break; - - case GATT_UUID_GAP_DEVICE_NAME: - BTM_SetLocalDeviceName((char *)p_value->p_dev_name); - break; - - case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: - p_db_attr->attr_value.addr_resolution = p_value->addr_resolution; - break; - - } - break; - } +void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE* p_value) { + tGAP_ATTR* p_db_attr = gap_cb.gatt_attr; + uint8_t i = 0; + + GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x", attr_uuid); + + for (i = 0; i < GAP_MAX_CHAR_NUM; i++, p_db_attr++) { + if (p_db_attr->uuid == attr_uuid) { + GAP_TRACE_EVENT("Found attr_uuid=0x%04x", attr_uuid); + + switch (attr_uuid) { + case GATT_UUID_GAP_ICON: + p_db_attr->attr_value.icon = p_value->icon; + break; + + case GATT_UUID_GAP_PREF_CONN_PARAM: + memcpy((void*)&p_db_attr->attr_value.conn_param, + (const void*)&p_value->conn_param, + sizeof(tGAP_BLE_PREF_PARAM)); + break; + + case GATT_UUID_GAP_DEVICE_NAME: + BTM_SetLocalDeviceName((char*)p_value->p_dev_name); + break; + + case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: + p_db_attr->attr_value.addr_resolution = p_value->addr_resolution; + break; + } + break; } + } - return; + return; } /******************************************************************************* @@ -495,30 +495,28 @@ void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) * Returns true if read started, else false if GAP is busy * ******************************************************************************/ -bool gap_ble_send_cl_read_request(tGAP_CLCB *p_clcb) -{ - tGATT_READ_PARAM param; - uint16_t uuid = 0; - bool started = false; - - if (gap_ble_dequeue_request(p_clcb, &uuid, &p_clcb->p_cback)) - { - memset(¶m, 0, sizeof(tGATT_READ_PARAM)); - - param.service.uuid.len = LEN_UUID_16; - param.service.uuid.uu.uuid16 = uuid; - param.service.s_handle = 1; - param.service.e_handle = 0xFFFF; - param.service.auth_req = 0; - - if (GATTC_Read(p_clcb->conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS) - { - p_clcb->cl_op_uuid = uuid; - started = true; - } +bool gap_ble_send_cl_read_request(tGAP_CLCB* p_clcb) { + tGATT_READ_PARAM param; + uint16_t uuid = 0; + bool started = false; + + if (gap_ble_dequeue_request(p_clcb, &uuid, &p_clcb->p_cback)) { + memset(¶m, 0, sizeof(tGATT_READ_PARAM)); + + param.service.uuid.len = LEN_UUID_16; + param.service.uuid.uu.uuid16 = uuid; + param.service.s_handle = 1; + param.service.e_handle = 0xFFFF; + param.service.auth_req = 0; + + if (GATTC_Read(p_clcb->conn_id, GATT_READ_BY_TYPE, ¶m) == + GATT_SUCCESS) { + p_clcb->cl_op_uuid = uuid; + started = true; } + } - return started; + return started; } /******************************************************************************* @@ -530,31 +528,28 @@ bool gap_ble_send_cl_read_request(tGAP_CLCB *p_clcb) * Returns void * ******************************************************************************/ -void gap_ble_cl_op_cmpl(tGAP_CLCB *p_clcb, bool status, uint16_t len, uint8_t *p_name) -{ - tGAP_BLE_CMPL_CBACK *p_cback = p_clcb->p_cback; - uint16_t op = p_clcb->cl_op_uuid; - - GAP_TRACE_EVENT("gap_ble_cl_op_cmpl status: %d", status); - - p_clcb->cl_op_uuid = 0; - p_clcb->p_cback=NULL; - - if (p_cback && op) - { - GAP_TRACE_EVENT("calling gap_ble_cl_op_cmpl"); - (* p_cback)(status, p_clcb->bda, len, (char *)p_name); - } - - /* if no further activity is requested in callback, drop the link */ - if (p_clcb->connected) - { - if (!gap_ble_send_cl_read_request(p_clcb)) - { - GATT_Disconnect(p_clcb->conn_id); - gap_ble_dealloc_clcb(p_clcb); - } +void gap_ble_cl_op_cmpl(tGAP_CLCB* p_clcb, bool status, uint16_t len, + uint8_t* p_name) { + tGAP_BLE_CMPL_CBACK* p_cback = p_clcb->p_cback; + uint16_t op = p_clcb->cl_op_uuid; + + GAP_TRACE_EVENT("gap_ble_cl_op_cmpl status: %d", status); + + p_clcb->cl_op_uuid = 0; + p_clcb->p_cback = NULL; + + if (p_cback && op) { + GAP_TRACE_EVENT("calling gap_ble_cl_op_cmpl"); + (*p_cback)(status, p_clcb->bda, len, (char*)p_name); + } + + /* if no further activity is requested in callback, drop the link */ + if (p_clcb->connected) { + if (!gap_ble_send_cl_read_request(p_clcb)) { + GATT_Disconnect(p_clcb->conn_id); + gap_ble_dealloc_clcb(p_clcb); } + } } /******************************************************************************* @@ -566,30 +561,25 @@ void gap_ble_cl_op_cmpl(tGAP_CLCB *p_clcb, bool status, uint16_t len, uint8_t * Returns void * ******************************************************************************/ -static void gap_ble_c_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, - uint16_t conn_id, - bool connected, tGATT_DISCONN_REASON reason, - UNUSED_ATTR tGATT_TRANSPORT transport) -{ - tGAP_CLCB *p_clcb = gap_find_clcb_by_bd_addr (bda); - - if (p_clcb != NULL) - { - if (connected) - { - p_clcb->conn_id = conn_id; - p_clcb->connected = true; - /* start operation is pending */ - gap_ble_send_cl_read_request(p_clcb); - } - else - { - p_clcb->connected = false; - gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); - /* clean up clcb */ - gap_ble_dealloc_clcb(p_clcb); - } +static void gap_ble_c_connect_cback(UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + UNUSED_ATTR tGATT_TRANSPORT transport) { + tGAP_CLCB* p_clcb = gap_find_clcb_by_bd_addr(bda); + + if (p_clcb != NULL) { + if (connected) { + p_clcb->conn_id = conn_id; + p_clcb->connected = true; + /* start operation is pending */ + gap_ble_send_cl_read_request(p_clcb); + } else { + p_clcb->connected = false; + gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); + /* clean up clcb */ + gap_ble_dealloc_clcb(p_clcb); } + } } /******************************************************************************* @@ -601,64 +591,62 @@ static void gap_ble_c_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, * Returns void * ******************************************************************************/ -static void gap_ble_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) +static void gap_ble_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, + tGATT_STATUS status, tGATT_CL_COMPLETE* p_data) { - tGAP_CLCB *p_clcb = gap_ble_find_clcb_by_conn_id(conn_id); - uint16_t op_type; - uint16_t min, max, latency, tout; - uint16_t len; - uint8_t *pp; - - if (p_clcb == NULL) - return; - - op_type = p_clcb->cl_op_uuid; - - GAP_TRACE_EVENT ("gap_ble_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x read_type: 0x%04x", op, status, op_type); - /* Currently we only issue read commands */ - if (op != GATTC_OPTYPE_READ) - return; - - if (status != GATT_SUCCESS) - { - gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); - return; - } + tGAP_CLCB* p_clcb = gap_ble_find_clcb_by_conn_id(conn_id); + uint16_t op_type; + uint16_t min, max, latency, tout; + uint16_t len; + uint8_t* pp; - pp = p_data->att_value.value; + if (p_clcb == NULL) return; - switch (op_type) - { - case GATT_UUID_GAP_PREF_CONN_PARAM: - GAP_TRACE_EVENT ("GATT_UUID_GAP_PREF_CONN_PARAM"); - /* Extract the peripheral preferred connection parameters and save them */ - - STREAM_TO_UINT16 (min, pp); - STREAM_TO_UINT16 (max, pp); - STREAM_TO_UINT16 (latency, pp); - STREAM_TO_UINT16 (tout, pp); - - BTM_BleSetPrefConnParams (p_clcb->bda, min, max, latency, tout); - /* release the connection here */ - gap_ble_cl_op_cmpl(p_clcb, true, 0, NULL); - break; + op_type = p_clcb->cl_op_uuid; - case GATT_UUID_GAP_DEVICE_NAME: - GAP_TRACE_EVENT ("GATT_UUID_GAP_DEVICE_NAME"); - len = (uint16_t)strlen((char *)pp); - if (len > GAP_CHAR_DEV_NAME_SIZE) - len = GAP_CHAR_DEV_NAME_SIZE; - gap_ble_cl_op_cmpl(p_clcb, true, len, pp); - break; + GAP_TRACE_EVENT( + "gap_ble_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x read_type: " + "0x%04x", + op, status, op_type); + /* Currently we only issue read commands */ + if (op != GATTC_OPTYPE_READ) return; - case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: - gap_ble_cl_op_cmpl(p_clcb, true, 1, pp); - break; - } + if (status != GATT_SUCCESS) { + gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); + return; + } + + pp = p_data->att_value.value; + + switch (op_type) { + case GATT_UUID_GAP_PREF_CONN_PARAM: + GAP_TRACE_EVENT("GATT_UUID_GAP_PREF_CONN_PARAM"); + /* Extract the peripheral preferred connection parameters and save them */ + + STREAM_TO_UINT16(min, pp); + STREAM_TO_UINT16(max, pp); + STREAM_TO_UINT16(latency, pp); + STREAM_TO_UINT16(tout, pp); + + BTM_BleSetPrefConnParams(p_clcb->bda, min, max, latency, tout); + /* release the connection here */ + gap_ble_cl_op_cmpl(p_clcb, true, 0, NULL); + break; + + case GATT_UUID_GAP_DEVICE_NAME: + GAP_TRACE_EVENT("GATT_UUID_GAP_DEVICE_NAME"); + len = (uint16_t)strlen((char*)pp); + if (len > GAP_CHAR_DEV_NAME_SIZE) len = GAP_CHAR_DEV_NAME_SIZE; + gap_ble_cl_op_cmpl(p_clcb, true, len, pp); + break; + + case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: + gap_ble_cl_op_cmpl(p_clcb, true, 1, pp); + break; + } } - /******************************************************************************* * * Function gap_ble_accept_cl_operation @@ -668,46 +656,45 @@ static void gap_ble_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STAT * Returns true if request accepted * ******************************************************************************/ -bool gap_ble_accept_cl_operation(BD_ADDR peer_bda, uint16_t uuid, tGAP_BLE_CMPL_CBACK *p_cback) -{ - tGAP_CLCB *p_clcb; - bool started = false; - - if (p_cback == NULL && uuid != GATT_UUID_GAP_PREF_CONN_PARAM) - return(started); - - p_clcb = gap_find_clcb_by_bd_addr(peer_bda); - if (p_clcb == NULL) - { - p_clcb = gap_clcb_alloc(peer_bda); - if (p_clcb == NULL) - { - GAP_TRACE_ERROR("gap_ble_accept_cl_operation max connection reached"); - return started; - } +bool gap_ble_accept_cl_operation(BD_ADDR peer_bda, uint16_t uuid, + tGAP_BLE_CMPL_CBACK* p_cback) { + tGAP_CLCB* p_clcb; + bool started = false; + + if (p_cback == NULL && uuid != GATT_UUID_GAP_PREF_CONN_PARAM) + return (started); + + p_clcb = gap_find_clcb_by_bd_addr(peer_bda); + if (p_clcb == NULL) { + p_clcb = gap_clcb_alloc(peer_bda); + if (p_clcb == NULL) { + GAP_TRACE_ERROR("gap_ble_accept_cl_operation max connection reached"); + return started; } + } - GAP_TRACE_EVENT ("%s() - BDA: %08x%04x cl_op_uuid: 0x%04x", - __func__, - (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], - (peer_bda[4]<<8)+peer_bda[5], uuid); + GAP_TRACE_EVENT("%s() - BDA: %08x%04x cl_op_uuid: 0x%04x", __func__, + (peer_bda[0] << 24) + (peer_bda[1] << 16) + + (peer_bda[2] << 8) + peer_bda[3], + (peer_bda[4] << 8) + peer_bda[5], uuid); - if (GATT_GetConnIdIfConnected(gap_cb.gatt_if, peer_bda, &p_clcb->conn_id, BT_TRANSPORT_LE)) - p_clcb->connected = true; + if (GATT_GetConnIdIfConnected(gap_cb.gatt_if, peer_bda, &p_clcb->conn_id, + BT_TRANSPORT_LE)) + p_clcb->connected = true; - /* hold the link here */ - if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, true, BT_TRANSPORT_LE, false)) - return started; + /* hold the link here */ + if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, true, BT_TRANSPORT_LE, false)) + return started; - /* enqueue the request */ - gap_ble_enqueue_request(p_clcb, uuid, p_cback); + /* enqueue the request */ + gap_ble_enqueue_request(p_clcb, uuid, p_cback); - if (p_clcb->connected && p_clcb->cl_op_uuid == 0) - started = gap_ble_send_cl_read_request(p_clcb); - else /* wait for connection up or pending operation to finish */ - started = true; + if (p_clcb->connected && p_clcb->cl_op_uuid == 0) + started = gap_ble_send_cl_read_request(p_clcb); + else /* wait for connection up or pending operation to finish */ + started = true; - return started; + return started; } /******************************************************************************* * @@ -719,9 +706,9 @@ bool gap_ble_accept_cl_operation(BD_ADDR peer_bda, uint16_t uuid, tGAP_BLE_CM * Returns true if read started, else false if GAP is busy * ******************************************************************************/ -bool GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda) -{ - return gap_ble_accept_cl_operation (peer_bda, GATT_UUID_GAP_PREF_CONN_PARAM, NULL); +bool GAP_BleReadPeerPrefConnParams(BD_ADDR peer_bda) { + return gap_ble_accept_cl_operation(peer_bda, GATT_UUID_GAP_PREF_CONN_PARAM, + NULL); } /******************************************************************************* @@ -734,9 +721,9 @@ bool GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda) * Returns true if request accepted * ******************************************************************************/ -bool GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback) -{ - return gap_ble_accept_cl_operation (peer_bda, GATT_UUID_GAP_DEVICE_NAME, p_cback); +bool GAP_BleReadPeerDevName(BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK* p_cback) { + return gap_ble_accept_cl_operation(peer_bda, GATT_UUID_GAP_DEVICE_NAME, + p_cback); } /******************************************************************************* @@ -748,9 +735,10 @@ bool GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback) * Returns true if request accepted * ******************************************************************************/ -bool GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback) -{ - return gap_ble_accept_cl_operation(peer_bda, GATT_UUID_GAP_CENTRAL_ADDR_RESOL, p_cback); +bool GAP_BleReadPeerAddressResolutionCap(BD_ADDR peer_bda, + tGAP_BLE_CMPL_CBACK* p_cback) { + return gap_ble_accept_cl_operation(peer_bda, GATT_UUID_GAP_CENTRAL_ADDR_RESOL, + p_cback); } /******************************************************************************* @@ -762,31 +750,29 @@ bool GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBA * Returns true if request accepted * ******************************************************************************/ -bool GAP_BleCancelReadPeerDevName (BD_ADDR peer_bda) -{ - tGAP_CLCB *p_clcb = gap_find_clcb_by_bd_addr (peer_bda); - - GAP_TRACE_EVENT ("GAP_BleCancelReadPeerDevName() - BDA: %08x%04x cl_op_uuid: 0x%04x", - (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], - (peer_bda[4]<<8)+peer_bda[5], (p_clcb == NULL)? 0 : p_clcb->cl_op_uuid); +bool GAP_BleCancelReadPeerDevName(BD_ADDR peer_bda) { + tGAP_CLCB* p_clcb = gap_find_clcb_by_bd_addr(peer_bda); + + GAP_TRACE_EVENT( + "GAP_BleCancelReadPeerDevName() - BDA: %08x%04x cl_op_uuid: 0x%04x", + (peer_bda[0] << 24) + (peer_bda[1] << 16) + (peer_bda[2] << 8) + + peer_bda[3], + (peer_bda[4] << 8) + peer_bda[5], + (p_clcb == NULL) ? 0 : p_clcb->cl_op_uuid); + + if (p_clcb == NULL) { + GAP_TRACE_ERROR("Cannot cancel current op is not get dev name"); + return false; + } - if (p_clcb == NULL) - { - GAP_TRACE_ERROR ("Cannot cancel current op is not get dev name"); - return false; + if (!p_clcb->connected) { + if (!GATT_CancelConnect(gap_cb.gatt_if, peer_bda, true)) { + GAP_TRACE_ERROR("Cannot cancel where No connection id"); + return false; } + } - if (!p_clcb->connected) - { - if (!GATT_CancelConnect(gap_cb.gatt_if, peer_bda, true)) - { - GAP_TRACE_ERROR ("Cannot cancel where No connection id"); - return false; - } - } + gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); - gap_ble_cl_op_cmpl(p_clcb, false, 0, NULL); - - return(true); + return (true); } - diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 2bab7732f..1b490739a 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -16,14 +16,13 @@ * ******************************************************************************/ - +#include #include "bt_target.h" #include "bt_utils.h" #include "btu.h" #include "gap_int.h" -#include "l2cdefs.h" #include "l2c_int.h" -#include +#include "l2cdefs.h" #include "osi/include/mutex.h" #include "osi/include/osi.h" #if (GAP_CONN_INCLUDED == TRUE) @@ -32,20 +31,21 @@ /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void gap_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, uint8_t l2cap_id); -static void gap_connect_cfm (uint16_t l2cap_cid, uint16_t result); -static void gap_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void gap_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void gap_disconnect_ind (uint16_t l2cap_cid, bool ack_needed); -static void gap_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg); -static void gap_congestion_ind (uint16_t lcid, bool is_congested); -static void gap_tx_complete_ind (uint16_t l2cap_cid, uint16_t sdu_sent); - -static tGAP_CCB *gap_find_ccb_by_cid (uint16_t cid); -static tGAP_CCB *gap_find_ccb_by_handle (uint16_t handle); -static tGAP_CCB *gap_allocate_ccb (void); -static void gap_release_ccb (tGAP_CCB *p_ccb); -static void gap_checks_con_flags (tGAP_CCB *p_ccb); +static void gap_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, + uint8_t l2cap_id); +static void gap_connect_cfm(uint16_t l2cap_cid, uint16_t result); +static void gap_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void gap_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); +static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); +static void gap_congestion_ind(uint16_t lcid, bool is_congested); +static void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent); + +static tGAP_CCB* gap_find_ccb_by_cid(uint16_t cid); +static tGAP_CCB* gap_find_ccb_by_handle(uint16_t handle); +static tGAP_CCB* gap_allocate_ccb(void); +static void gap_release_ccb(tGAP_CCB* p_ccb); +static void gap_checks_con_flags(tGAP_CCB* p_ccb); /******************************************************************************* * @@ -57,41 +57,39 @@ static void gap_checks_con_flags (tGAP_CCB *p_ccb); * Returns void * ******************************************************************************/ -void gap_conn_init (void) -{ +void gap_conn_init(void) { #if (AMP_INCLUDED == TRUE) - gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = gap_connect_ind; - gap_cb.conn.reg_info.pAMP_ConnectCfm_Cb = gap_connect_cfm; - gap_cb.conn.reg_info.pAMP_ConnectPnd_Cb = NULL; - gap_cb.conn.reg_info.pAMP_ConfigInd_Cb = gap_config_ind; - gap_cb.conn.reg_info.pAMP_ConfigCfm_Cb = gap_config_cfm; - gap_cb.conn.reg_info.pAMP_DisconnectInd_Cb = gap_disconnect_ind; - gap_cb.conn.reg_info.pAMP_DisconnectCfm_Cb = NULL; - gap_cb.conn.reg_info.pAMP_QoSViolationInd_Cb = NULL; - gap_cb.conn.reg_info.pAMP_DataInd_Cb = gap_data_ind; - gap_cb.conn.reg_info.pAMP_CongestionStatus_Cb = gap_congestion_ind; - gap_cb.conn.reg_info.pAMP_TxComplete_Cb = NULL; - gap_cb.conn.reg_info.pAMP_MoveInd_Cb = NULL; - gap_cb.conn.reg_info.pAMP_MoveRsp_Cb = NULL; - gap_cb.conn.reg_info.pAMP_MoveCfm_Cb = NULL; //gap_move_cfm - gap_cb.conn.reg_info.pAMP_MoveCfmRsp_Cb = NULL; //gap_move_cfm_rsp + gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = gap_connect_ind; + gap_cb.conn.reg_info.pAMP_ConnectCfm_Cb = gap_connect_cfm; + gap_cb.conn.reg_info.pAMP_ConnectPnd_Cb = NULL; + gap_cb.conn.reg_info.pAMP_ConfigInd_Cb = gap_config_ind; + gap_cb.conn.reg_info.pAMP_ConfigCfm_Cb = gap_config_cfm; + gap_cb.conn.reg_info.pAMP_DisconnectInd_Cb = gap_disconnect_ind; + gap_cb.conn.reg_info.pAMP_DisconnectCfm_Cb = NULL; + gap_cb.conn.reg_info.pAMP_QoSViolationInd_Cb = NULL; + gap_cb.conn.reg_info.pAMP_DataInd_Cb = gap_data_ind; + gap_cb.conn.reg_info.pAMP_CongestionStatus_Cb = gap_congestion_ind; + gap_cb.conn.reg_info.pAMP_TxComplete_Cb = NULL; + gap_cb.conn.reg_info.pAMP_MoveInd_Cb = NULL; + gap_cb.conn.reg_info.pAMP_MoveRsp_Cb = NULL; + gap_cb.conn.reg_info.pAMP_MoveCfm_Cb = NULL; // gap_move_cfm + gap_cb.conn.reg_info.pAMP_MoveCfmRsp_Cb = NULL; // gap_move_cfm_rsp #else - gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = gap_connect_ind; - gap_cb.conn.reg_info.pL2CA_ConnectCfm_Cb = gap_connect_cfm; - gap_cb.conn.reg_info.pL2CA_ConnectPnd_Cb = NULL; - gap_cb.conn.reg_info.pL2CA_ConfigInd_Cb = gap_config_ind; - gap_cb.conn.reg_info.pL2CA_ConfigCfm_Cb = gap_config_cfm; - gap_cb.conn.reg_info.pL2CA_DisconnectInd_Cb = gap_disconnect_ind; - gap_cb.conn.reg_info.pL2CA_DisconnectCfm_Cb = NULL; - gap_cb.conn.reg_info.pL2CA_QoSViolationInd_Cb = NULL; - gap_cb.conn.reg_info.pL2CA_DataInd_Cb = gap_data_ind; - gap_cb.conn.reg_info.pL2CA_CongestionStatus_Cb = gap_congestion_ind; - gap_cb.conn.reg_info.pL2CA_TxComplete_Cb = gap_tx_complete_ind; + gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = gap_connect_ind; + gap_cb.conn.reg_info.pL2CA_ConnectCfm_Cb = gap_connect_cfm; + gap_cb.conn.reg_info.pL2CA_ConnectPnd_Cb = NULL; + gap_cb.conn.reg_info.pL2CA_ConfigInd_Cb = gap_config_ind; + gap_cb.conn.reg_info.pL2CA_ConfigCfm_Cb = gap_config_cfm; + gap_cb.conn.reg_info.pL2CA_DisconnectInd_Cb = gap_disconnect_ind; + gap_cb.conn.reg_info.pL2CA_DisconnectCfm_Cb = NULL; + gap_cb.conn.reg_info.pL2CA_QoSViolationInd_Cb = NULL; + gap_cb.conn.reg_info.pL2CA_DataInd_Cb = gap_data_ind; + gap_cb.conn.reg_info.pL2CA_CongestionStatus_Cb = gap_congestion_ind; + gap_cb.conn.reg_info.pL2CA_TxComplete_Cb = gap_tx_complete_ind; #endif } - /******************************************************************************* * * Function GAP_ConnOpen @@ -127,173 +125,158 @@ void gap_conn_init (void) * GAP_INVALID_HANDLE * ******************************************************************************/ -uint16_t GAP_ConnOpen(const char *p_serv_name, uint8_t service_id, bool is_server, - BD_ADDR p_rem_bda, uint16_t psm, tL2CAP_CFG_INFO *p_cfg, - tL2CAP_ERTM_INFO *ertm_info, uint16_t security, uint8_t chan_mode_mask, - tGAP_CONN_CALLBACK *p_cb, tBT_TRANSPORT transport) -{ - tGAP_CCB *p_ccb; - uint16_t cid; - - GAP_TRACE_EVENT ("GAP_CONN - Open Request"); - - /* Allocate a new CCB. Return if none available. */ - p_ccb = gap_allocate_ccb(); - if (p_ccb == NULL) - return (GAP_INVALID_HANDLE); - - /* update the transport */ - p_ccb->transport = transport; - - /* If caller specified a BD address, save it */ - if (p_rem_bda) - { - /* the bd addr is not BT_BD_ANY, then a bd address was specified */ - if (memcmp (p_rem_bda, BT_BD_ANY, BD_ADDR_LEN)) - p_ccb->rem_addr_specified = true; - - memcpy (&p_ccb->rem_dev_address[0], p_rem_bda, BD_ADDR_LEN); - } - else if (!is_server) - { - /* remore addr is not specified and is not a server -> bad */ - return (GAP_INVALID_HANDLE); - } - - /* A client MUST have specified a bd addr to connect with */ - if (!p_ccb->rem_addr_specified && !is_server) - { - gap_release_ccb (p_ccb); - GAP_TRACE_ERROR ("GAP ERROR: Client must specify a remote BD ADDR to connect to!"); - return (GAP_INVALID_HANDLE); - } - - /* Check if configuration was specified */ - if (p_cfg) - p_ccb->cfg = *p_cfg; - - /* Configure L2CAP COC, if transport is LE */ - if (transport == BT_TRANSPORT_LE) - { - p_ccb->local_coc_cfg.credits = L2CAP_LE_DEFAULT_CREDIT; - p_ccb->local_coc_cfg.mtu = p_cfg->mtu; - p_ccb->local_coc_cfg.mps = L2CAP_LE_DEFAULT_MPS; - } - - p_ccb->p_callback = p_cb; - - /* If originator, use a dynamic PSM */ +uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, + bool is_server, BD_ADDR p_rem_bda, uint16_t psm, + tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info, + uint16_t security, uint8_t chan_mode_mask, + tGAP_CONN_CALLBACK* p_cb, tBT_TRANSPORT transport) { + tGAP_CCB* p_ccb; + uint16_t cid; + + GAP_TRACE_EVENT("GAP_CONN - Open Request"); + + /* Allocate a new CCB. Return if none available. */ + p_ccb = gap_allocate_ccb(); + if (p_ccb == NULL) return (GAP_INVALID_HANDLE); + + /* update the transport */ + p_ccb->transport = transport; + + /* If caller specified a BD address, save it */ + if (p_rem_bda) { + /* the bd addr is not BT_BD_ANY, then a bd address was specified */ + if (memcmp(p_rem_bda, BT_BD_ANY, BD_ADDR_LEN)) + p_ccb->rem_addr_specified = true; + + memcpy(&p_ccb->rem_dev_address[0], p_rem_bda, BD_ADDR_LEN); + } else if (!is_server) { + /* remore addr is not specified and is not a server -> bad */ + return (GAP_INVALID_HANDLE); + } + + /* A client MUST have specified a bd addr to connect with */ + if (!p_ccb->rem_addr_specified && !is_server) { + gap_release_ccb(p_ccb); + GAP_TRACE_ERROR( + "GAP ERROR: Client must specify a remote BD ADDR to connect to!"); + return (GAP_INVALID_HANDLE); + } + + /* Check if configuration was specified */ + if (p_cfg) p_ccb->cfg = *p_cfg; + + /* Configure L2CAP COC, if transport is LE */ + if (transport == BT_TRANSPORT_LE) { + p_ccb->local_coc_cfg.credits = L2CAP_LE_DEFAULT_CREDIT; + p_ccb->local_coc_cfg.mtu = p_cfg->mtu; + p_ccb->local_coc_cfg.mps = L2CAP_LE_DEFAULT_MPS; + } + + p_ccb->p_callback = p_cb; + +/* If originator, use a dynamic PSM */ #if (AMP_INCLUDED == TRUE) - if (!is_server) - gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = NULL; - else - gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = gap_connect_ind; + if (!is_server) + gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = NULL; + else + gap_cb.conn.reg_info.pAMP_ConnectInd_Cb = gap_connect_ind; #else - if (!is_server) - gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = NULL; - else - gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = gap_connect_ind; + if (!is_server) + gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = NULL; + else + gap_cb.conn.reg_info.pL2CA_ConnectInd_Cb = gap_connect_ind; #endif - /* Register the PSM with L2CAP */ - if (transport == BT_TRANSPORT_BR_EDR) - { - p_ccb->psm = L2CA_REGISTER (psm, &gap_cb.conn.reg_info, - AMP_AUTOSWITCH_ALLOWED|AMP_USE_AMP_IF_POSSIBLE); - if (p_ccb->psm == 0) - { - GAP_TRACE_ERROR ("%s: Failure registering PSM 0x%04x", __func__, psm); - gap_release_ccb (p_ccb); - return (GAP_INVALID_HANDLE); - } + /* Register the PSM with L2CAP */ + if (transport == BT_TRANSPORT_BR_EDR) { + p_ccb->psm = + L2CA_REGISTER(psm, &gap_cb.conn.reg_info, + AMP_AUTOSWITCH_ALLOWED | AMP_USE_AMP_IF_POSSIBLE); + if (p_ccb->psm == 0) { + GAP_TRACE_ERROR("%s: Failure registering PSM 0x%04x", __func__, psm); + gap_release_ccb(p_ccb); + return (GAP_INVALID_HANDLE); } - - if (transport == BT_TRANSPORT_LE) - { - p_ccb->psm = L2CA_REGISTER_COC (psm, &gap_cb.conn.reg_info, - AMP_AUTOSWITCH_ALLOWED|AMP_USE_AMP_IF_POSSIBLE); - if (p_ccb->psm == 0) - { - GAP_TRACE_ERROR ("%s: Failure registering PSM 0x%04x", __func__, psm); - gap_release_ccb (p_ccb); - return (GAP_INVALID_HANDLE); - } - } - - /* Register with Security Manager for the specific security level */ - p_ccb->service_id = service_id; - if (!BTM_SetSecurityLevel ((uint8_t)!is_server, p_serv_name, - p_ccb->service_id, security, p_ccb->psm, 0, 0)) - { - GAP_TRACE_ERROR ("GAP_CONN - Security Error"); - gap_release_ccb (p_ccb); - return (GAP_INVALID_HANDLE); + } + + if (transport == BT_TRANSPORT_LE) { + p_ccb->psm = + L2CA_REGISTER_COC(psm, &gap_cb.conn.reg_info, + AMP_AUTOSWITCH_ALLOWED | AMP_USE_AMP_IF_POSSIBLE); + if (p_ccb->psm == 0) { + GAP_TRACE_ERROR("%s: Failure registering PSM 0x%04x", __func__, psm); + gap_release_ccb(p_ccb); + return (GAP_INVALID_HANDLE); } - - /* Fill in eL2CAP parameter data */ - if( p_ccb->cfg.fcr_present ) - { - if(ertm_info == NULL) { - p_ccb->ertm_info.preferred_mode = p_ccb->cfg.fcr.mode; - p_ccb->ertm_info.user_rx_buf_size = GAP_DATA_BUF_SIZE; - p_ccb->ertm_info.user_tx_buf_size = GAP_DATA_BUF_SIZE; - p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; - p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; - } else { - p_ccb->ertm_info = *ertm_info; - } + } + + /* Register with Security Manager for the specific security level */ + p_ccb->service_id = service_id; + if (!BTM_SetSecurityLevel((uint8_t)!is_server, p_serv_name, p_ccb->service_id, + security, p_ccb->psm, 0, 0)) { + GAP_TRACE_ERROR("GAP_CONN - Security Error"); + gap_release_ccb(p_ccb); + return (GAP_INVALID_HANDLE); + } + + /* Fill in eL2CAP parameter data */ + if (p_ccb->cfg.fcr_present) { + if (ertm_info == NULL) { + p_ccb->ertm_info.preferred_mode = p_ccb->cfg.fcr.mode; + p_ccb->ertm_info.user_rx_buf_size = GAP_DATA_BUF_SIZE; + p_ccb->ertm_info.user_tx_buf_size = GAP_DATA_BUF_SIZE; + p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; + p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_INVALID_ERM_BUF_SIZE; + } else { + p_ccb->ertm_info = *ertm_info; } - - /* optional FCR channel modes */ - if(ertm_info != NULL) { - p_ccb->ertm_info.allowed_modes = - (chan_mode_mask) ? chan_mode_mask : (uint8_t)L2CAP_FCR_CHAN_OPT_BASIC; + } + + /* optional FCR channel modes */ + if (ertm_info != NULL) { + p_ccb->ertm_info.allowed_modes = + (chan_mode_mask) ? chan_mode_mask : (uint8_t)L2CAP_FCR_CHAN_OPT_BASIC; + } + + if (is_server) { + p_ccb->con_flags |= + GAP_CCB_FLAGS_SEC_DONE; /* assume btm/l2cap would handle it */ + p_ccb->con_state = GAP_CCB_STATE_LISTENING; + return (p_ccb->gap_handle); + } else { + /* We are the originator of this connection */ + p_ccb->con_flags = GAP_CCB_FLAGS_IS_ORIG; + + /* Transition to the next appropriate state, waiting for connection confirm. + */ + p_ccb->con_state = GAP_CCB_STATE_CONN_SETUP; + + /* mark security done flag, when security is not required */ + if ((security & (BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_AUTHENTICATE | + BTM_SEC_OUT_ENCRYPT)) == 0) + p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; + + /* Check if L2CAP started the connection process */ + if (p_rem_bda && (transport == BT_TRANSPORT_BR_EDR)) { + cid = L2CA_CONNECT_REQ(p_ccb->psm, p_rem_bda, &p_ccb->ertm_info); + if (cid != 0) { + p_ccb->connection_id = cid; + return (p_ccb->gap_handle); + } } - if (is_server) - { - p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; /* assume btm/l2cap would handle it */ - p_ccb->con_state = GAP_CCB_STATE_LISTENING; + if (p_rem_bda && (transport == BT_TRANSPORT_LE)) { + cid = L2CA_CONNECT_COC_REQ(p_ccb->psm, p_rem_bda, &p_ccb->local_coc_cfg); + if (cid != 0) { + p_ccb->connection_id = cid; return (p_ccb->gap_handle); + } } - else - { - /* We are the originator of this connection */ - p_ccb->con_flags = GAP_CCB_FLAGS_IS_ORIG; - - /* Transition to the next appropriate state, waiting for connection confirm. */ - p_ccb->con_state = GAP_CCB_STATE_CONN_SETUP; - - /* mark security done flag, when security is not required */ - if ((security & (BTM_SEC_OUT_AUTHORIZE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT) ) == 0) - p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; - - /* Check if L2CAP started the connection process */ - if (p_rem_bda && (transport == BT_TRANSPORT_BR_EDR)) - { - cid = L2CA_CONNECT_REQ (p_ccb->psm, p_rem_bda, &p_ccb->ertm_info); - if (cid != 0) - { - p_ccb->connection_id = cid; - return (p_ccb->gap_handle); - } - } - - if (p_rem_bda && (transport == BT_TRANSPORT_LE)) - { - cid = L2CA_CONNECT_COC_REQ (p_ccb->psm, p_rem_bda, &p_ccb->local_coc_cfg); - if (cid != 0) - { - p_ccb->connection_id = cid; - return (p_ccb->gap_handle); - } - } - - gap_release_ccb (p_ccb); - return (GAP_INVALID_HANDLE); - } -} + gap_release_ccb(p_ccb); + return (GAP_INVALID_HANDLE); + } +} /******************************************************************************* * @@ -307,28 +290,24 @@ uint16_t GAP_ConnOpen(const char *p_serv_name, uint8_t service_id, bool is_serve * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -uint16_t GAP_ConnClose (uint16_t gap_handle) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); +uint16_t GAP_ConnClose(uint16_t gap_handle) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); - GAP_TRACE_EVENT ("GAP_CONN - close handle: 0x%x", gap_handle); + GAP_TRACE_EVENT("GAP_CONN - close handle: 0x%x", gap_handle); - if (p_ccb) - { - /* Check if we have a connection ID */ - if (p_ccb->con_state != GAP_CCB_STATE_LISTENING) - L2CA_DISCONNECT_REQ (p_ccb->connection_id); + if (p_ccb) { + /* Check if we have a connection ID */ + if (p_ccb->con_state != GAP_CCB_STATE_LISTENING) + L2CA_DISCONNECT_REQ(p_ccb->connection_id); - gap_release_ccb (p_ccb); + gap_release_ccb(p_ccb); - return (BT_PASS); - } + return (BT_PASS); + } - return (GAP_ERR_BAD_HANDLE); + return (GAP_ERR_BAD_HANDLE); } - - /******************************************************************************* * * Function GAP_ConnReadData @@ -346,54 +325,48 @@ uint16_t GAP_ConnClose (uint16_t gap_handle) * GAP_NO_DATA_AVAIL - no data available * ******************************************************************************/ -uint16_t GAP_ConnReadData (uint16_t gap_handle, uint8_t *p_data, uint16_t max_len, uint16_t *p_len) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); - uint16_t copy_len; - - if (!p_ccb) - return (GAP_ERR_BAD_HANDLE); - - *p_len = 0; - - if (fixed_queue_is_empty(p_ccb->rx_queue)) - return (GAP_NO_DATA_AVAIL); - - mutex_global_lock(); - - while (max_len) - { - BT_HDR *p_buf = - static_cast(fixed_queue_try_peek_first(p_ccb->rx_queue)); - if (p_buf == NULL) - break; - - copy_len = (p_buf->len > max_len)?max_len:p_buf->len; - max_len -= copy_len; - *p_len += copy_len; - if (p_data) - { - memcpy (p_data, (uint8_t *)(p_buf + 1) + p_buf->offset, copy_len); - p_data += copy_len; - } - - if (p_buf->len > copy_len) - { - p_buf->offset += copy_len; - p_buf->len -= copy_len; - break; - } - osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); +uint16_t GAP_ConnReadData(uint16_t gap_handle, uint8_t* p_data, + uint16_t max_len, uint16_t* p_len) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); + uint16_t copy_len; + + if (!p_ccb) return (GAP_ERR_BAD_HANDLE); + + *p_len = 0; + + if (fixed_queue_is_empty(p_ccb->rx_queue)) return (GAP_NO_DATA_AVAIL); + + mutex_global_lock(); + + while (max_len) { + BT_HDR* p_buf = + static_cast(fixed_queue_try_peek_first(p_ccb->rx_queue)); + if (p_buf == NULL) break; + + copy_len = (p_buf->len > max_len) ? max_len : p_buf->len; + max_len -= copy_len; + *p_len += copy_len; + if (p_data) { + memcpy(p_data, (uint8_t*)(p_buf + 1) + p_buf->offset, copy_len); + p_data += copy_len; + } + + if (p_buf->len > copy_len) { + p_buf->offset += copy_len; + p_buf->len -= copy_len; + break; } + osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); + } - p_ccb->rx_queue_size -= *p_len; + p_ccb->rx_queue_size -= *p_len; - mutex_global_unlock(); + mutex_global_unlock(); - GAP_TRACE_EVENT ("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d", - p_ccb->rx_queue_size, *p_len); + GAP_TRACE_EVENT("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d", + p_ccb->rx_queue_size, *p_len); - return (BT_PASS); + return (BT_PASS); } /******************************************************************************* @@ -407,30 +380,25 @@ uint16_t GAP_ConnReadData (uint16_t gap_handle, uint8_t *p_data, uint16_t max_le * * ******************************************************************************/ -int GAP_GetRxQueueCnt (uint16_t handle, uint32_t *p_rx_queue_count) -{ - tGAP_CCB *p_ccb; - int rc = BT_PASS; - - /* Check that handle is valid */ - if (handle < GAP_MAX_CONNECTIONS) - { - p_ccb = &gap_cb.conn.ccb_pool[handle]; - - if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) - { - *p_rx_queue_count = p_ccb->rx_queue_size; - } - else - rc = GAP_INVALID_HANDLE; - } - else - rc = GAP_INVALID_HANDLE; +int GAP_GetRxQueueCnt(uint16_t handle, uint32_t* p_rx_queue_count) { + tGAP_CCB* p_ccb; + int rc = BT_PASS; + + /* Check that handle is valid */ + if (handle < GAP_MAX_CONNECTIONS) { + p_ccb = &gap_cb.conn.ccb_pool[handle]; + + if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) { + *p_rx_queue_count = p_ccb->rx_queue_size; + } else + rc = GAP_INVALID_HANDLE; + } else + rc = GAP_INVALID_HANDLE; - GAP_TRACE_EVENT ("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", - rc , *p_rx_queue_count); + GAP_TRACE_EVENT("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", rc, + *p_rx_queue_count); - return (rc); + return (rc); } /******************************************************************************* @@ -448,28 +416,23 @@ int GAP_GetRxQueueCnt (uint16_t handle, uint32_t *p_rx_queue_count) * GAP_NO_DATA_AVAIL - no data available * ******************************************************************************/ -uint16_t GAP_ConnBTRead (uint16_t gap_handle, BT_HDR **pp_buf) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); - BT_HDR *p_buf; +uint16_t GAP_ConnBTRead(uint16_t gap_handle, BT_HDR** pp_buf) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); + BT_HDR* p_buf; - if (!p_ccb) - return (GAP_ERR_BAD_HANDLE); + if (!p_ccb) return (GAP_ERR_BAD_HANDLE); - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->rx_queue); + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->rx_queue); - if (p_buf) - { - *pp_buf = p_buf; + if (p_buf) { + *pp_buf = p_buf; - p_ccb->rx_queue_size -= p_buf->len; - return (BT_PASS); - } - else - { - *pp_buf = NULL; - return (GAP_NO_DATA_AVAIL); - } + p_ccb->rx_queue_size -= p_buf->len; + return (BT_PASS); + } else { + *pp_buf = NULL; + return (GAP_NO_DATA_AVAIL); + } } /******************************************************************************* @@ -490,63 +453,56 @@ uint16_t GAP_ConnBTRead (uint16_t gap_handle, BT_HDR **pp_buf) * GAP_CONGESTION - system is congested * ******************************************************************************/ -uint16_t GAP_ConnWriteData (uint16_t gap_handle, uint8_t *p_data, uint16_t max_len, uint16_t *p_len) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); - BT_HDR *p_buf; +uint16_t GAP_ConnWriteData(uint16_t gap_handle, uint8_t* p_data, + uint16_t max_len, uint16_t* p_len) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); + BT_HDR* p_buf; - *p_len = 0; + *p_len = 0; - if (!p_ccb) - return (GAP_ERR_BAD_HANDLE); + if (!p_ccb) return (GAP_ERR_BAD_HANDLE); - if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) - return (GAP_ERR_BAD_STATE); + if (p_ccb->con_state != GAP_CCB_STATE_CONNECTED) return (GAP_ERR_BAD_STATE); - while (max_len) - { - if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - p_buf = (BT_HDR *)osi_malloc(L2CAP_FCR_ERTM_BUF_SIZE); - else - p_buf = (BT_HDR *)osi_malloc(GAP_DATA_BUF_SIZE); + while (max_len) { + if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) + p_buf = (BT_HDR*)osi_malloc(L2CAP_FCR_ERTM_BUF_SIZE); + else + p_buf = (BT_HDR*)osi_malloc(GAP_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = (p_ccb->rem_mtu_size < max_len) ? p_ccb->rem_mtu_size : max_len; - p_buf->event = BT_EVT_TO_BTU_SP_DATA; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = + (p_ccb->rem_mtu_size < max_len) ? p_ccb->rem_mtu_size : max_len; + p_buf->event = BT_EVT_TO_BTU_SP_DATA; - memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset, p_data, p_buf->len); + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, p_buf->len); - *p_len += p_buf->len; - max_len -= p_buf->len; - p_data += p_buf->len; + *p_len += p_buf->len; + max_len -= p_buf->len; + p_data += p_buf->len; - GAP_TRACE_EVENT ("GAP_WriteData %d bytes", p_buf->len); + GAP_TRACE_EVENT("GAP_WriteData %d bytes", p_buf->len); - fixed_queue_enqueue(p_ccb->tx_queue, p_buf); - } + fixed_queue_enqueue(p_ccb->tx_queue, p_buf); + } - if (p_ccb->is_congested) - { - return (BT_PASS); - } + if (p_ccb->is_congested) { + return (BT_PASS); + } - /* Send the buffer through L2CAP */ - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) - { - uint8_t status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf); - - if (status == L2CAP_DW_CONGESTED) - { - p_ccb->is_congested = true; - break; - } - else if (status != L2CAP_DW_SUCCESS) - return (GAP_ERR_BAD_STATE); - } + /* Send the buffer through L2CAP */ + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) { + uint8_t status = L2CA_DATA_WRITE(p_ccb->connection_id, p_buf); - return (BT_PASS); -} + if (status == L2CAP_DW_CONGESTED) { + p_ccb->is_congested = true; + break; + } else if (status != L2CAP_DW_SUCCESS) + return (GAP_ERR_BAD_STATE); + } + return (BT_PASS); +} /******************************************************************************* * @@ -562,23 +518,19 @@ uint16_t GAP_ConnWriteData (uint16_t gap_handle, uint8_t *p_data, uint16_t max_l * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -uint16_t GAP_ConnReconfig (uint16_t gap_handle, tL2CAP_CFG_INFO *p_cfg) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); +uint16_t GAP_ConnReconfig(uint16_t gap_handle, tL2CAP_CFG_INFO* p_cfg) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); - if (!p_ccb) - return (GAP_ERR_BAD_HANDLE); + if (!p_ccb) return (GAP_ERR_BAD_HANDLE); - p_ccb->cfg = *p_cfg; + p_ccb->cfg = *p_cfg; - if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) - L2CA_CONFIG_REQ (p_ccb->connection_id, p_cfg); + if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) + L2CA_CONFIG_REQ(p_ccb->connection_id, p_cfg); - return (BT_PASS); + return (BT_PASS); } - - /******************************************************************************* * * Function GAP_ConnSetIdleTimeout @@ -601,22 +553,18 @@ uint16_t GAP_ConnReconfig (uint16_t gap_handle, tL2CAP_CFG_INFO *p_cfg) * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -uint16_t GAP_ConnSetIdleTimeout (uint16_t gap_handle, uint16_t timeout) -{ - tGAP_CCB *p_ccb; +uint16_t GAP_ConnSetIdleTimeout(uint16_t gap_handle, uint16_t timeout) { + tGAP_CCB* p_ccb; - p_ccb = gap_find_ccb_by_handle(gap_handle); - if (p_ccb == NULL) - return (GAP_ERR_BAD_HANDLE); + p_ccb = gap_find_ccb_by_handle(gap_handle); + if (p_ccb == NULL) return (GAP_ERR_BAD_HANDLE); - if (L2CA_SetIdleTimeout (p_ccb->connection_id, timeout, false)) - return (BT_PASS); - else - return (GAP_ERR_BAD_HANDLE); + if (L2CA_SetIdleTimeout(p_ccb->connection_id, timeout, false)) + return (BT_PASS); + else + return (GAP_ERR_BAD_HANDLE); } - - /******************************************************************************* * * Function GAP_ConnGetRemoteAddr @@ -630,27 +578,25 @@ uint16_t GAP_ConnSetIdleTimeout (uint16_t gap_handle, uint16_t timeout) * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -uint8_t *GAP_ConnGetRemoteAddr (uint16_t gap_handle) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_handle (gap_handle); - - GAP_TRACE_EVENT ("GAP_ConnGetRemoteAddr gap_handle = %d", gap_handle); - - if ((p_ccb) && (p_ccb->con_state > GAP_CCB_STATE_LISTENING)) - { - GAP_TRACE_EVENT("GAP_ConnGetRemoteAddr bda :0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n", \ - p_ccb->rem_dev_address[0],p_ccb->rem_dev_address[1],p_ccb->rem_dev_address[2], - p_ccb->rem_dev_address[3],p_ccb->rem_dev_address[4],p_ccb->rem_dev_address[5]); - return (p_ccb->rem_dev_address); - } - else - { - GAP_TRACE_EVENT ("GAP_ConnGetRemoteAddr return Error "); - return (NULL); - } +uint8_t* GAP_ConnGetRemoteAddr(uint16_t gap_handle) { + tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle); + + GAP_TRACE_EVENT("GAP_ConnGetRemoteAddr gap_handle = %d", gap_handle); + + if ((p_ccb) && (p_ccb->con_state > GAP_CCB_STATE_LISTENING)) { + GAP_TRACE_EVENT( + "GAP_ConnGetRemoteAddr bda " + ":0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n", + p_ccb->rem_dev_address[0], p_ccb->rem_dev_address[1], + p_ccb->rem_dev_address[2], p_ccb->rem_dev_address[3], + p_ccb->rem_dev_address[4], p_ccb->rem_dev_address[5]); + return (p_ccb->rem_dev_address); + } else { + GAP_TRACE_EVENT("GAP_ConnGetRemoteAddr return Error "); + return (NULL); + } } - /******************************************************************************* * * Function GAP_ConnGetRemMtuSize @@ -663,15 +609,13 @@ uint8_t *GAP_ConnGetRemoteAddr (uint16_t gap_handle) * the peer * ******************************************************************************/ -uint16_t GAP_ConnGetRemMtuSize (uint16_t gap_handle) -{ - tGAP_CCB *p_ccb; +uint16_t GAP_ConnGetRemMtuSize(uint16_t gap_handle) { + tGAP_CCB* p_ccb; - p_ccb = gap_find_ccb_by_handle(gap_handle); - if (p_ccb == NULL) - return (0); + p_ccb = gap_find_ccb_by_handle(gap_handle); + if (p_ccb == NULL) return (0); - return (p_ccb->rem_mtu_size); + return (p_ccb->rem_mtu_size); } /******************************************************************************* @@ -686,15 +630,13 @@ uint16_t GAP_ConnGetRemMtuSize (uint16_t gap_handle) * 0, if error * ******************************************************************************/ -uint16_t GAP_ConnGetL2CAPCid (uint16_t gap_handle) -{ - tGAP_CCB *p_ccb; +uint16_t GAP_ConnGetL2CAPCid(uint16_t gap_handle) { + tGAP_CCB* p_ccb; - p_ccb = gap_find_ccb_by_handle(gap_handle); - if (p_ccb == NULL) - return (0); + p_ccb = gap_find_ccb_by_handle(gap_handle); + if (p_ccb == NULL) return (0); - return (p_ccb->connection_id); + return (p_ccb->connection_id); } /******************************************************************************* @@ -707,17 +649,14 @@ uint16_t GAP_ConnGetL2CAPCid (uint16_t gap_handle) * Returns void * ******************************************************************************/ -void gap_tx_complete_ind (uint16_t l2cap_cid, uint16_t sdu_sent) -{ - tGAP_CCB *p_ccb = gap_find_ccb_by_cid (l2cap_cid); - if (p_ccb == NULL) - return; - - if ((p_ccb->con_state == GAP_CCB_STATE_CONNECTED) && (sdu_sent == 0xFFFF)) - { - GAP_TRACE_EVENT("%s: GAP_EVT_TX_EMPTY", __func__); - p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_TX_EMPTY); - } +void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent) { + tGAP_CCB* p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) return; + + if ((p_ccb->con_state == GAP_CCB_STATE_CONNECTED) && (sdu_sent == 0xFFFF)) { + GAP_TRACE_EVENT("%s: GAP_EVT_TX_EMPTY", __func__); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_TX_EMPTY); + } } /******************************************************************************* @@ -731,63 +670,64 @@ void gap_tx_complete_ind (uint16_t l2cap_cid, uint16_t sdu_sent) * Returns void * ******************************************************************************/ -static void gap_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, uint8_t l2cap_id) -{ - uint16_t xx; - tGAP_CCB *p_ccb; - - /* See if we have a CCB listening for the connection */ - for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if ((p_ccb->con_state == GAP_CCB_STATE_LISTENING) - && (p_ccb->psm == psm) - && ((p_ccb->rem_addr_specified == false) - || (!memcmp (bd_addr, p_ccb->rem_dev_address, BD_ADDR_LEN)))) - break; - } - - if (xx == GAP_MAX_CONNECTIONS) - { - GAP_TRACE_WARNING("*******"); - GAP_TRACE_WARNING("WARNING: GAP Conn Indication for Unexpected Bd Addr...Disconnecting"); - GAP_TRACE_WARNING("*******"); - - /* Disconnect because it is an unexpected connection */ - L2CA_DISCONNECT_REQ (l2cap_cid); - return; - } - - /* Transition to the next appropriate state, waiting for config setup. */ - if (p_ccb->transport == BT_TRANSPORT_BR_EDR) - p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; - - /* Save the BD Address and Channel ID. */ - memcpy (&p_ccb->rem_dev_address[0], bd_addr, BD_ADDR_LEN); - p_ccb->connection_id = l2cap_cid; - - /* Send response to the L2CAP layer. */ - if (p_ccb->transport == BT_TRANSPORT_BR_EDR) - L2CA_CONNECT_RSP (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK, &p_ccb->ertm_info); - - if (p_ccb->transport == BT_TRANSPORT_LE) - { - L2CA_CONNECT_COC_RSP (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK, &p_ccb->local_coc_cfg); - - /* get the remote coc configuration */ - L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); - p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; - - /* configuration is not required for LE COC */ - p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; - p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; - gap_checks_con_flags (p_ccb); - } +static void gap_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, + uint8_t l2cap_id) { + uint16_t xx; + tGAP_CCB* p_ccb; + + /* See if we have a CCB listening for the connection */ + for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; + xx++, p_ccb++) { + if ((p_ccb->con_state == GAP_CCB_STATE_LISTENING) && (p_ccb->psm == psm) && + ((p_ccb->rem_addr_specified == false) || + (!memcmp(bd_addr, p_ccb->rem_dev_address, BD_ADDR_LEN)))) + break; + } + + if (xx == GAP_MAX_CONNECTIONS) { + GAP_TRACE_WARNING("*******"); + GAP_TRACE_WARNING( + "WARNING: GAP Conn Indication for Unexpected Bd Addr...Disconnecting"); + GAP_TRACE_WARNING("*******"); + + /* Disconnect because it is an unexpected connection */ + L2CA_DISCONNECT_REQ(l2cap_cid); + return; + } + + /* Transition to the next appropriate state, waiting for config setup. */ + if (p_ccb->transport == BT_TRANSPORT_BR_EDR) + p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; + + /* Save the BD Address and Channel ID. */ + memcpy(&p_ccb->rem_dev_address[0], bd_addr, BD_ADDR_LEN); + p_ccb->connection_id = l2cap_cid; + + /* Send response to the L2CAP layer. */ + if (p_ccb->transport == BT_TRANSPORT_BR_EDR) + L2CA_CONNECT_RSP(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK, + &p_ccb->ertm_info); + + if (p_ccb->transport == BT_TRANSPORT_LE) { + L2CA_CONNECT_COC_RSP(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, + L2CAP_CONN_OK, &p_ccb->local_coc_cfg); + + /* get the remote coc configuration */ + L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); + p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; + + /* configuration is not required for LE COC */ + p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; + p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; + gap_checks_con_flags(p_ccb); + } - GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP conn ind, CID: 0x%x", p_ccb->connection_id); + GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP conn ind, CID: 0x%x", + p_ccb->connection_id); - /* Send a Configuration Request. */ - if (p_ccb->transport == BT_TRANSPORT_BR_EDR) - L2CA_CONFIG_REQ (l2cap_cid, &p_ccb->cfg); + /* Send a Configuration Request. */ + if (p_ccb->transport == BT_TRANSPORT_BR_EDR) + L2CA_CONFIG_REQ(l2cap_cid, &p_ccb->cfg); } /******************************************************************************* @@ -800,16 +740,14 @@ static void gap_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, * Returns void * ******************************************************************************/ -static void gap_checks_con_flags (tGAP_CCB *p_ccb) -{ - GAP_TRACE_EVENT ("gap_checks_con_flags conn_flags:0x%x, ", p_ccb->con_flags); - /* if all the required con_flags are set, report the OPEN event now */ - if ((p_ccb->con_flags & GAP_CCB_FLAGS_CONN_DONE) == GAP_CCB_FLAGS_CONN_DONE) - { - p_ccb->con_state = GAP_CCB_STATE_CONNECTED; - - p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_CONN_OPENED); - } +static void gap_checks_con_flags(tGAP_CCB* p_ccb) { + GAP_TRACE_EVENT("gap_checks_con_flags conn_flags:0x%x, ", p_ccb->con_flags); + /* if all the required con_flags are set, report the OPEN event now */ + if ((p_ccb->con_flags & GAP_CCB_FLAGS_CONN_DONE) == GAP_CCB_FLAGS_CONN_DONE) { + p_ccb->con_state = GAP_CCB_STATE_CONNECTED; + + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_OPENED); + } } /******************************************************************************* @@ -822,26 +760,23 @@ static void gap_checks_con_flags (tGAP_CCB *p_ccb) * Returns void * ******************************************************************************/ -static void gap_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tGAP_CCB *p_ccb = (tGAP_CCB *)p_ref_data; - - GAP_TRACE_EVENT ("gap_sec_check_complete conn_state:%d, conn_flags:0x%x, status:%d", - p_ccb->con_state, p_ccb->con_flags, res); - if (p_ccb->con_state == GAP_CCB_STATE_IDLE) - return; - - if (res == BTM_SUCCESS) - { - p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; - gap_checks_con_flags (p_ccb); - } - else - { - /* security failed - disconnect the channel */ - L2CA_DISCONNECT_REQ (p_ccb->connection_id); - } +static void gap_sec_check_complete(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tGAP_CCB* p_ccb = (tGAP_CCB*)p_ref_data; + + GAP_TRACE_EVENT( + "gap_sec_check_complete conn_state:%d, conn_flags:0x%x, status:%d", + p_ccb->con_state, p_ccb->con_flags, res); + if (p_ccb->con_state == GAP_CCB_STATE_IDLE) return; + + if (res == BTM_SUCCESS) { + p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; + gap_checks_con_flags(p_ccb); + } else { + /* security failed - disconnect the channel */ + L2CA_DISCONNECT_REQ(p_ccb->connection_id); + } } /******************************************************************************* @@ -855,55 +790,49 @@ static void gap_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT * Returns void * ******************************************************************************/ -static void gap_connect_cfm (uint16_t l2cap_cid, uint16_t result) -{ - tGAP_CCB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - return; - - /* initiate security process, if needed */ - if ( (p_ccb->con_flags & GAP_CCB_FLAGS_SEC_DONE) == 0 && p_ccb->transport != BT_TRANSPORT_LE) - { - btm_sec_mx_access_request (p_ccb->rem_dev_address, p_ccb->psm, true, - 0, 0, &gap_sec_check_complete, p_ccb); +static void gap_connect_cfm(uint16_t l2cap_cid, uint16_t result) { + tGAP_CCB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) return; + + /* initiate security process, if needed */ + if ((p_ccb->con_flags & GAP_CCB_FLAGS_SEC_DONE) == 0 && + p_ccb->transport != BT_TRANSPORT_LE) { + btm_sec_mx_access_request(p_ccb->rem_dev_address, p_ccb->psm, true, 0, 0, + &gap_sec_check_complete, p_ccb); + } + + /* If the connection response contains success status, then */ + /* Transition to the next state and startup the timer. */ + if ((result == L2CAP_CONN_OK) && + (p_ccb->con_state == GAP_CCB_STATE_CONN_SETUP)) { + if (p_ccb->transport == BT_TRANSPORT_BR_EDR) { + p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; + + /* Send a Configuration Request. */ + L2CA_CONFIG_REQ(l2cap_cid, &p_ccb->cfg); } - /* If the connection response contains success status, then */ - /* Transition to the next state and startup the timer. */ - if ((result == L2CAP_CONN_OK) && (p_ccb->con_state == GAP_CCB_STATE_CONN_SETUP)) - { - if (p_ccb->transport == BT_TRANSPORT_BR_EDR) - { - p_ccb->con_state = GAP_CCB_STATE_CFG_SETUP; - - /* Send a Configuration Request. */ - L2CA_CONFIG_REQ (l2cap_cid, &p_ccb->cfg); - } - - if (p_ccb->transport == BT_TRANSPORT_LE) - { - /* get the remote coc configuration */ - L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); - p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; - - /* configuration is not required for LE COC */ - p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; - p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; - p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; - gap_checks_con_flags (p_ccb); - } - } - else - { - /* Tell the user if he has a callback */ - if (p_ccb->p_callback) - (*p_ccb->p_callback) (p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + if (p_ccb->transport == BT_TRANSPORT_LE) { + /* get the remote coc configuration */ + L2CA_GET_PEER_COC_CONFIG(l2cap_cid, &p_ccb->peer_coc_cfg); + p_ccb->rem_mtu_size = p_ccb->peer_coc_cfg.mtu; - gap_release_ccb (p_ccb); + /* configuration is not required for LE COC */ + p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; + p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; + p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; + gap_checks_con_flags(p_ccb); } + } else { + /* Tell the user if he has a callback */ + if (p_ccb->p_callback) + (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + + gap_release_ccb(p_ccb); + } } /******************************************************************************* @@ -916,47 +845,40 @@ static void gap_connect_cfm (uint16_t l2cap_cid, uint16_t result) * Returns void * ******************************************************************************/ -static void gap_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tGAP_CCB *p_ccb; - uint16_t local_mtu_size; +static void gap_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tGAP_CCB* p_ccb; + uint16_t local_mtu_size; - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - return; + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) return; - /* Remember the remote MTU size */ + /* Remember the remote MTU size */ - if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - { - local_mtu_size = p_ccb->ertm_info.user_tx_buf_size - - sizeof(BT_HDR) - L2CAP_MIN_OFFSET; - } - else - local_mtu_size = L2CAP_MTU_SIZE; + if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { + local_mtu_size = + p_ccb->ertm_info.user_tx_buf_size - sizeof(BT_HDR) - L2CAP_MIN_OFFSET; + } else + local_mtu_size = L2CAP_MTU_SIZE; - if ((!p_cfg->mtu_present)||(p_cfg->mtu > local_mtu_size)) - { - p_ccb->rem_mtu_size = local_mtu_size; - } - else - p_ccb->rem_mtu_size = p_cfg->mtu; + if ((!p_cfg->mtu_present) || (p_cfg->mtu > local_mtu_size)) { + p_ccb->rem_mtu_size = local_mtu_size; + } else + p_ccb->rem_mtu_size = p_cfg->mtu; - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = false; - p_cfg->mtu_present = false; - p_cfg->result = L2CAP_CFG_OK; - p_cfg->fcs_present = false; + /* For now, always accept configuration from the other side */ + p_cfg->flush_to_present = false; + p_cfg->mtu_present = false; + p_cfg->result = L2CAP_CFG_OK; + p_cfg->fcs_present = false; - L2CA_CONFIG_RSP (l2cap_cid, p_cfg); + L2CA_CONFIG_RSP(l2cap_cid, p_cfg); - p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; + p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; - gap_checks_con_flags (p_ccb); + gap_checks_con_flags(p_ccb); } - /******************************************************************************* * * Function gap_config_cfm @@ -967,34 +889,27 @@ static void gap_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void gap_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tGAP_CCB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - return; +static void gap_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tGAP_CCB* p_ccb; - if (p_cfg->result == L2CAP_CFG_OK) - { - p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) return; + if (p_cfg->result == L2CAP_CFG_OK) { + p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; - if (p_ccb->cfg.fcr_present) - p_ccb->cfg.fcr.mode = p_cfg->fcr.mode; - else - p_ccb->cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; - - gap_checks_con_flags (p_ccb); - } + if (p_ccb->cfg.fcr_present) + p_ccb->cfg.fcr.mode = p_cfg->fcr.mode; else - { - p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); - gap_release_ccb (p_ccb); - } -} + p_ccb->cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; + gap_checks_con_flags(p_ccb); + } else { + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + gap_release_ccb(p_ccb); + } +} /******************************************************************************* * @@ -1006,25 +921,21 @@ static void gap_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void gap_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) -{ - tGAP_CCB *p_ccb; +static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) { + tGAP_CCB* p_ccb; - GAP_TRACE_EVENT ("GAP_CONN - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); + GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - return; + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) return; - if (ack_needed) - L2CA_DISCONNECT_RSP (l2cap_cid); + if (ack_needed) L2CA_DISCONNECT_RSP(l2cap_cid); - p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); - gap_release_ccb (p_ccb); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + gap_release_ccb(p_ccb); } - /******************************************************************************* * * Function gap_data_ind @@ -1034,37 +945,31 @@ static void gap_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) * Returns void * ******************************************************************************/ -static void gap_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) -{ - tGAP_CCB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - osi_free(p_msg); - return; - } - - if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) - { - fixed_queue_enqueue(p_ccb->rx_queue, p_msg); - - p_ccb->rx_queue_size += p_msg->len; - /* - GAP_TRACE_EVENT ("gap_data_ind - rx_queue_size=%d, msg len=%d", - p_ccb->rx_queue_size, p_msg->len); - */ - - p_ccb->p_callback (p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL); - } - else - { - osi_free(p_msg); - } +static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) { + tGAP_CCB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + osi_free(p_msg); + return; + } + + if (p_ccb->con_state == GAP_CCB_STATE_CONNECTED) { + fixed_queue_enqueue(p_ccb->rx_queue, p_msg); + + p_ccb->rx_queue_size += p_msg->len; + /* + GAP_TRACE_EVENT ("gap_data_ind - rx_queue_size=%d, msg len=%d", + p_ccb->rx_queue_size, p_msg->len); + */ + + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL); + } else { + osi_free(p_msg); + } } - /******************************************************************************* * * Function gap_congestion_ind @@ -1073,44 +978,38 @@ static void gap_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) * data L2CAP congestion status changes * ******************************************************************************/ -static void gap_congestion_ind (uint16_t lcid, bool is_congested) -{ - tGAP_CCB *p_ccb; - uint16_t event; - BT_HDR *p_buf; - uint8_t status; - - GAP_TRACE_EVENT ("GAP_CONN - Rcvd L2CAP Is Congested (%d), CID: 0x%x", - is_congested, lcid); - - /* Find CCB based on CID */ - p_ccb = gap_find_ccb_by_cid(lcid); - if (p_ccb == NULL) - return; - - p_ccb->is_congested = is_congested; - - event = (is_congested) ? GAP_EVT_CONN_CONGESTED : GAP_EVT_CONN_UNCONGESTED; - p_ccb->p_callback (p_ccb->gap_handle, event); - - if (!is_congested) - { - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->tx_queue)) != NULL) - { - status = L2CA_DATA_WRITE (p_ccb->connection_id, p_buf); - - if (status == L2CAP_DW_CONGESTED) - { - p_ccb->is_congested = true; - break; - } - else if (status != L2CAP_DW_SUCCESS) - break; - } +static void gap_congestion_ind(uint16_t lcid, bool is_congested) { + tGAP_CCB* p_ccb; + uint16_t event; + BT_HDR* p_buf; + uint8_t status; + + GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP Is Congested (%d), CID: 0x%x", + is_congested, lcid); + + /* Find CCB based on CID */ + p_ccb = gap_find_ccb_by_cid(lcid); + if (p_ccb == NULL) return; + + p_ccb->is_congested = is_congested; + + event = (is_congested) ? GAP_EVT_CONN_CONGESTED : GAP_EVT_CONN_UNCONGESTED; + p_ccb->p_callback(p_ccb->gap_handle, event); + + if (!is_congested) { + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->tx_queue)) != + NULL) { + status = L2CA_DATA_WRITE(p_ccb->connection_id, p_buf); + + if (status == L2CAP_DW_CONGESTED) { + p_ccb->is_congested = true; + break; + } else if (status != L2CAP_DW_SUCCESS) + break; } + } } - /******************************************************************************* * * Function gap_find_ccb_by_cid @@ -1121,23 +1020,22 @@ static void gap_congestion_ind (uint16_t lcid, bool is_congested) * Returns the CCB address, or NULL if not found. * ******************************************************************************/ -static tGAP_CCB *gap_find_ccb_by_cid (uint16_t cid) -{ - uint16_t xx; - tGAP_CCB *p_ccb; - - /* Look through each connection control block */ - for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if ((p_ccb->con_state != GAP_CCB_STATE_IDLE) && (p_ccb->connection_id == cid)) - return (p_ccb); - } - - /* If here, not found */ - return (NULL); +static tGAP_CCB* gap_find_ccb_by_cid(uint16_t cid) { + uint16_t xx; + tGAP_CCB* p_ccb; + + /* Look through each connection control block */ + for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; + xx++, p_ccb++) { + if ((p_ccb->con_state != GAP_CCB_STATE_IDLE) && + (p_ccb->connection_id == cid)) + return (p_ccb); + } + + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function gap_find_ccb_by_handle @@ -1148,24 +1046,20 @@ static tGAP_CCB *gap_find_ccb_by_cid (uint16_t cid) * Returns the CCB address, or NULL if not found. * ******************************************************************************/ -static tGAP_CCB *gap_find_ccb_by_handle (uint16_t handle) -{ - tGAP_CCB *p_ccb; +static tGAP_CCB* gap_find_ccb_by_handle(uint16_t handle) { + tGAP_CCB* p_ccb; - /* Check that handle is valid */ - if (handle < GAP_MAX_CONNECTIONS) - { - p_ccb = &gap_cb.conn.ccb_pool[handle]; + /* Check that handle is valid */ + if (handle < GAP_MAX_CONNECTIONS) { + p_ccb = &gap_cb.conn.ccb_pool[handle]; - if (p_ccb->con_state != GAP_CCB_STATE_IDLE) - return (p_ccb); - } + if (p_ccb->con_state != GAP_CCB_STATE_IDLE) return (p_ccb); + } - /* If here, handle points to invalid connection */ - return (NULL); + /* If here, handle points to invalid connection */ + return (NULL); } - /******************************************************************************* * * Function gap_allocate_ccb @@ -1175,32 +1069,29 @@ static tGAP_CCB *gap_find_ccb_by_handle (uint16_t handle) * Returns CCB address, or NULL if none available. * ******************************************************************************/ -static tGAP_CCB *gap_allocate_ccb (void) -{ - uint16_t xx; - tGAP_CCB *p_ccb; - - /* Look through each connection control block for a free one */ - for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if (p_ccb->con_state == GAP_CCB_STATE_IDLE) - { - memset (p_ccb, 0, sizeof (tGAP_CCB)); - p_ccb->tx_queue = fixed_queue_new(SIZE_MAX); - p_ccb->rx_queue = fixed_queue_new(SIZE_MAX); - - p_ccb->gap_handle = xx; - p_ccb->rem_mtu_size = L2CAP_MTU_SIZE; - - return (p_ccb); - } +static tGAP_CCB* gap_allocate_ccb(void) { + uint16_t xx; + tGAP_CCB* p_ccb; + + /* Look through each connection control block for a free one */ + for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; + xx++, p_ccb++) { + if (p_ccb->con_state == GAP_CCB_STATE_IDLE) { + memset(p_ccb, 0, sizeof(tGAP_CCB)); + p_ccb->tx_queue = fixed_queue_new(SIZE_MAX); + p_ccb->rx_queue = fixed_queue_new(SIZE_MAX); + + p_ccb->gap_handle = xx; + p_ccb->rem_mtu_size = L2CAP_MTU_SIZE; + + return (p_ccb); } + } - /* If here, no free CCB found */ - return (NULL); + /* If here, no free CCB found */ + return (NULL); } - /******************************************************************************* * * Function gap_release_ccb @@ -1210,41 +1101,37 @@ static tGAP_CCB *gap_allocate_ccb (void) * Returns void * ******************************************************************************/ -static void gap_release_ccb (tGAP_CCB *p_ccb) -{ - uint16_t xx; - uint16_t psm = p_ccb->psm; - uint8_t service_id = p_ccb->service_id; - - /* Drop any buffers we may be holding */ - p_ccb->rx_queue_size = 0; - - while (!fixed_queue_is_empty(p_ccb->rx_queue)) - osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); - fixed_queue_free(p_ccb->rx_queue, NULL); - p_ccb->rx_queue = NULL; - - while (!fixed_queue_is_empty(p_ccb->tx_queue)) - osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue)); - fixed_queue_free(p_ccb->tx_queue, NULL); - p_ccb->tx_queue = NULL; - - p_ccb->con_state = GAP_CCB_STATE_IDLE; - - /* If no-one else is using the PSM, deregister from L2CAP */ - for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if ((p_ccb->con_state != GAP_CCB_STATE_IDLE) && (p_ccb->psm == psm)) - return; - } +static void gap_release_ccb(tGAP_CCB* p_ccb) { + uint16_t xx; + uint16_t psm = p_ccb->psm; + uint8_t service_id = p_ccb->service_id; + + /* Drop any buffers we may be holding */ + p_ccb->rx_queue_size = 0; + + while (!fixed_queue_is_empty(p_ccb->rx_queue)) + osi_free(fixed_queue_try_dequeue(p_ccb->rx_queue)); + fixed_queue_free(p_ccb->rx_queue, NULL); + p_ccb->rx_queue = NULL; + + while (!fixed_queue_is_empty(p_ccb->tx_queue)) + osi_free(fixed_queue_try_dequeue(p_ccb->tx_queue)); + fixed_queue_free(p_ccb->tx_queue, NULL); + p_ccb->tx_queue = NULL; + + p_ccb->con_state = GAP_CCB_STATE_IDLE; + + /* If no-one else is using the PSM, deregister from L2CAP */ + for (xx = 0, p_ccb = gap_cb.conn.ccb_pool; xx < GAP_MAX_CONNECTIONS; + xx++, p_ccb++) { + if ((p_ccb->con_state != GAP_CCB_STATE_IDLE) && (p_ccb->psm == psm)) return; + } - /* Free the security record for this PSM */ - BTM_SecClrService(service_id); - if (p_ccb->transport == BT_TRANSPORT_BR_EDR) - L2CA_DEREGISTER (psm); + /* Free the security record for this PSM */ + BTM_SecClrService(service_id); + if (p_ccb->transport == BT_TRANSPORT_BR_EDR) L2CA_DEREGISTER(psm); - if(p_ccb->transport == BT_TRANSPORT_LE) - L2CA_DEREGISTER_COC (psm); + if (p_ccb->transport == BT_TRANSPORT_LE) L2CA_DEREGISTER_COC(psm); } -#endif /* GAP_CONN_INCLUDED */ +#endif /* GAP_CONN_INCLUDED */ diff --git a/stack/gap/gap_int.h b/stack/gap/gap_int.h index 29d975710..0f27f0411 100644 --- a/stack/gap/gap_int.h +++ b/stack/gap/gap_int.h @@ -16,145 +16,135 @@ * ******************************************************************************/ - #ifndef GAP_INT_H #define GAP_INT_H +#include "bt_common.h" #include "bt_target.h" -#include "osi/include/fixed_queue.h" #include "gap_api.h" -#include "bt_common.h" #include "gatt_api.h" -#define GAP_MAX_BLOCKS 2 /* Concurrent GAP commands pending at a time*/ +#include "osi/include/fixed_queue.h" +#define GAP_MAX_BLOCKS 2 /* Concurrent GAP commands pending at a time*/ /* Define the Generic Access Profile control structure */ -typedef struct -{ - void *p_data; /* Pointer to any data returned in callback */ - tGAP_CALLBACK *gap_cback; /* Pointer to users callback function */ - tGAP_CALLBACK *gap_inq_rslt_cback; /* Used for inquiry results */ - uint16_t event; /* Passed back in the callback */ - uint8_t index; /* Index of this control block and callback */ - bool in_use; /* True when structure is allocated */ +typedef struct { + void* p_data; /* Pointer to any data returned in callback */ + tGAP_CALLBACK* gap_cback; /* Pointer to users callback function */ + tGAP_CALLBACK* gap_inq_rslt_cback; /* Used for inquiry results */ + uint16_t event; /* Passed back in the callback */ + uint8_t index; /* Index of this control block and callback */ + bool in_use; /* True when structure is allocated */ } tGAP_INFO; /* The control block for FindAddrByName (Only 1 active at a time) */ -typedef struct -{ - tGAP_CALLBACK *p_cback; - /* Pointer to the current inquiry database entry */ - tBTM_INQ_INFO *p_cur_inq; - tGAP_FINDADDR_RESULTS results; - bool in_use; +typedef struct { + tGAP_CALLBACK* p_cback; + /* Pointer to the current inquiry database entry */ + tBTM_INQ_INFO* p_cur_inq; + tGAP_FINDADDR_RESULTS results; + bool in_use; } tGAP_FINDADDR_CB; /* Define the GAP Connection Control Block. */ -typedef struct -{ -#define GAP_CCB_STATE_IDLE 0 -#define GAP_CCB_STATE_LISTENING 1 -#define GAP_CCB_STATE_CONN_SETUP 2 -#define GAP_CCB_STATE_CFG_SETUP 3 -#define GAP_CCB_STATE_WAIT_SEC 4 -#define GAP_CCB_STATE_CONNECTED 5 - uint8_t con_state; - -#define GAP_CCB_FLAGS_IS_ORIG 0x01 -#define GAP_CCB_FLAGS_HIS_CFG_DONE 0x02 -#define GAP_CCB_FLAGS_MY_CFG_DONE 0x04 -#define GAP_CCB_FLAGS_SEC_DONE 0x08 -#define GAP_CCB_FLAGS_CONN_DONE 0x0E - uint8_t con_flags; - - uint8_t service_id; /* Used by BTM */ - uint16_t gap_handle; /* GAP handle */ - uint16_t connection_id; /* L2CAP CID */ - bool rem_addr_specified; - uint8_t chan_mode_mask; /* Supported channel modes (FCR) */ - BD_ADDR rem_dev_address; - uint16_t psm; - uint16_t rem_mtu_size; - - bool is_congested; - fixed_queue_t *tx_queue; /* Queue of buffers waiting to be sent */ - fixed_queue_t *rx_queue; /* Queue of buffers waiting to be read */ - - uint32_t rx_queue_size; /* Total data count in rx_queue */ - - tGAP_CONN_CALLBACK *p_callback; /* Users callback function */ - - tL2CAP_CFG_INFO cfg; /* Configuration */ - tL2CAP_ERTM_INFO ertm_info; /* Pools and modes for ertm */ - tBT_TRANSPORT transport; /* Transport channel BR/EDR or BLE */ - tL2CAP_LE_CFG_INFO local_coc_cfg; /* local configuration for LE Coc */ - tL2CAP_LE_CFG_INFO peer_coc_cfg; /* local configuration for LE Coc */ +typedef struct { +#define GAP_CCB_STATE_IDLE 0 +#define GAP_CCB_STATE_LISTENING 1 +#define GAP_CCB_STATE_CONN_SETUP 2 +#define GAP_CCB_STATE_CFG_SETUP 3 +#define GAP_CCB_STATE_WAIT_SEC 4 +#define GAP_CCB_STATE_CONNECTED 5 + uint8_t con_state; + +#define GAP_CCB_FLAGS_IS_ORIG 0x01 +#define GAP_CCB_FLAGS_HIS_CFG_DONE 0x02 +#define GAP_CCB_FLAGS_MY_CFG_DONE 0x04 +#define GAP_CCB_FLAGS_SEC_DONE 0x08 +#define GAP_CCB_FLAGS_CONN_DONE 0x0E + uint8_t con_flags; + + uint8_t service_id; /* Used by BTM */ + uint16_t gap_handle; /* GAP handle */ + uint16_t connection_id; /* L2CAP CID */ + bool rem_addr_specified; + uint8_t chan_mode_mask; /* Supported channel modes (FCR) */ + BD_ADDR rem_dev_address; + uint16_t psm; + uint16_t rem_mtu_size; + + bool is_congested; + fixed_queue_t* tx_queue; /* Queue of buffers waiting to be sent */ + fixed_queue_t* rx_queue; /* Queue of buffers waiting to be read */ + + uint32_t rx_queue_size; /* Total data count in rx_queue */ + + tGAP_CONN_CALLBACK* p_callback; /* Users callback function */ + + tL2CAP_CFG_INFO cfg; /* Configuration */ + tL2CAP_ERTM_INFO ertm_info; /* Pools and modes for ertm */ + tBT_TRANSPORT transport; /* Transport channel BR/EDR or BLE */ + tL2CAP_LE_CFG_INFO local_coc_cfg; /* local configuration for LE Coc */ + tL2CAP_LE_CFG_INFO peer_coc_cfg; /* local configuration for LE Coc */ } tGAP_CCB; -typedef struct -{ +typedef struct { #if (AMP_INCLUDED == TRUE) - tAMP_APPL_INFO reg_info; + tAMP_APPL_INFO reg_info; #else - tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ + tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ #endif - tGAP_CCB ccb_pool[GAP_MAX_CONNECTIONS]; + tGAP_CCB ccb_pool[GAP_MAX_CONNECTIONS]; } tGAP_CONN; +#define GAP_MAX_CHAR_NUM 4 -#define GAP_MAX_CHAR_NUM 4 - -typedef struct -{ - uint16_t handle; - uint16_t uuid; - tGAP_BLE_ATTR_VALUE attr_value; -}tGAP_ATTR; +typedef struct { + uint16_t handle; + uint16_t uuid; + tGAP_BLE_ATTR_VALUE attr_value; +} tGAP_ATTR; /********************************************************************** * M A I N C O N T R O L B L O C K **********************************************************************/ #define GAP_MAX_CL GATT_CL_MAX_LCB -typedef struct -{ - uint16_t uuid; - tGAP_BLE_CMPL_CBACK *p_cback; +typedef struct { + uint16_t uuid; + tGAP_BLE_CMPL_CBACK* p_cback; } tGAP_BLE_REQ; -typedef struct -{ - BD_ADDR bda; - tGAP_BLE_CMPL_CBACK *p_cback; - uint16_t conn_id; - uint16_t cl_op_uuid; - bool in_use; - bool connected; - fixed_queue_t *pending_req_q; - -}tGAP_CLCB; - -typedef struct -{ - tGAP_INFO blk[GAP_MAX_BLOCKS]; - tBTM_CMPL_CB *btm_cback[GAP_MAX_BLOCKS]; - uint8_t trace_level; - tGAP_FINDADDR_CB findaddr_cb; /* Contains the control block for finding a device addr */ - tBTM_INQ_INFO *cur_inqptr; +typedef struct { + BD_ADDR bda; + tGAP_BLE_CMPL_CBACK* p_cback; + uint16_t conn_id; + uint16_t cl_op_uuid; + bool in_use; + bool connected; + fixed_queue_t* pending_req_q; + +} tGAP_CLCB; + +typedef struct { + tGAP_INFO blk[GAP_MAX_BLOCKS]; + tBTM_CMPL_CB* btm_cback[GAP_MAX_BLOCKS]; + uint8_t trace_level; + tGAP_FINDADDR_CB + findaddr_cb; /* Contains the control block for finding a device addr */ + tBTM_INQ_INFO* cur_inqptr; #if (GAP_CONN_INCLUDED == TRUE) - tGAP_CONN conn; + tGAP_CONN conn; #endif - /* LE GAP attribute database */ - tGAP_ATTR gatt_attr[GAP_MAX_CHAR_NUM]; - tGAP_CLCB clcb[GAP_MAX_CL]; /* connection link*/ - tGATT_IF gatt_if; + /* LE GAP attribute database */ + tGAP_ATTR gatt_attr[GAP_MAX_CHAR_NUM]; + tGAP_CLCB clcb[GAP_MAX_CL]; /* connection link*/ + tGATT_IF gatt_if; } tGAP_CB; - -extern tGAP_CB gap_cb; +extern tGAP_CB gap_cb; #if (GAP_CONN_INCLUDED == TRUE) - extern void gap_conn_init(void); +extern void gap_conn_init(void); #endif - extern void gap_attr_db_init(void); +extern void gap_attr_db_init(void); #endif diff --git a/stack/gap/gap_utils.cc b/stack/gap/gap_utils.cc index d3ef93eb4..fa8b30e44 100644 --- a/stack/gap/gap_utils.cc +++ b/stack/gap/gap_utils.cc @@ -30,29 +30,25 @@ * Returns Pointer to the control block or NULL if not found * ******************************************************************************/ -tGAP_INFO *gap_allocate_cb (void) -{ - tGAP_INFO *p_cb = &gap_cb.blk[0]; - uint8_t x; - - for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) - { - if (!p_cb->in_use) - { - memset (p_cb, 0, sizeof (tGAP_INFO)); - - p_cb->in_use = true; - p_cb->index = x; - p_cb->p_data = (void *)NULL; - return (p_cb); - } +tGAP_INFO* gap_allocate_cb(void) { + tGAP_INFO* p_cb = &gap_cb.blk[0]; + uint8_t x; + + for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) { + if (!p_cb->in_use) { + memset(p_cb, 0, sizeof(tGAP_INFO)); + + p_cb->in_use = true; + p_cb->index = x; + p_cb->p_data = (void*)NULL; + return (p_cb); } + } - /* If here, no free control blocks found */ - return (NULL); + /* If here, no free control blocks found */ + return (NULL); } - /******************************************************************************* * * Function gap_free_cb @@ -62,16 +58,13 @@ tGAP_INFO *gap_allocate_cb (void) * Returns Pointer to the control block or NULL if not found * ******************************************************************************/ -void gap_free_cb (tGAP_INFO *p_cb) -{ - if (p_cb) - { - p_cb->gap_cback = NULL; - p_cb->in_use = false; - } +void gap_free_cb(tGAP_INFO* p_cb) { + if (p_cb) { + p_cb->gap_cback = NULL; + p_cb->in_use = false; + } } - /******************************************************************************* * * Function gap_is_service_busy @@ -84,21 +77,17 @@ void gap_free_cb (tGAP_INFO *p_cb) * false if not busy * ******************************************************************************/ -bool gap_is_service_busy (uint16_t request) -{ - tGAP_INFO *p_cb = &gap_cb.blk[0]; - uint8_t x; - - for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) - { - if (p_cb->in_use && p_cb->event == request) - return (true); - } +bool gap_is_service_busy(uint16_t request) { + tGAP_INFO* p_cb = &gap_cb.blk[0]; + uint8_t x; - /* If here, service is not busy */ - return (false); -} + for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) { + if (p_cb->in_use && p_cb->event == request) return (true); + } + /* If here, service is not busy */ + return (false); +} /******************************************************************************* * @@ -110,33 +99,31 @@ bool gap_is_service_busy (uint16_t request) * Returns GAP_UNKNOWN_BTM_STATUS is returned if not recognized * ******************************************************************************/ -uint16_t gap_convert_btm_status (tBTM_STATUS btm_status) -{ - switch (btm_status) - { +uint16_t gap_convert_btm_status(tBTM_STATUS btm_status) { + switch (btm_status) { case BTM_SUCCESS: - return (BT_PASS); + return (BT_PASS); case BTM_CMD_STARTED: - return (GAP_CMD_INITIATED); + return (GAP_CMD_INITIATED); case BTM_BUSY: - return (GAP_ERR_BUSY); + return (GAP_ERR_BUSY); case BTM_MODE_UNSUPPORTED: case BTM_ILLEGAL_VALUE: - return (GAP_ERR_ILL_PARM); + return (GAP_ERR_ILL_PARM); case BTM_WRONG_MODE: - return (GAP_DEVICE_NOT_UP); + return (GAP_DEVICE_NOT_UP); case BTM_UNKNOWN_ADDR: - return (GAP_BAD_BD_ADDR); + return (GAP_BAD_BD_ADDR); case BTM_DEVICE_TIMEOUT: - return (GAP_ERR_TIMEOUT); + return (GAP_ERR_TIMEOUT); default: - return (GAP_ERR_PROCESSING); - } + return (GAP_ERR_PROCESSING); + } } diff --git a/stack/gatt/att_protocol.cc b/stack/gatt/att_protocol.cc index 167d12c47..26bacc0d5 100644 --- a/stack/gatt/att_protocol.cc +++ b/stack/gatt/att_protocol.cc @@ -27,9 +27,9 @@ #include "gatt_int.h" #include "l2c_api.h" -#define GATT_HDR_FIND_TYPE_VALUE_LEN 21 -#define GATT_OP_CODE_SIZE 1 -#define GATT_START_END_HANDLE_SIZE 4 +#define GATT_HDR_FIND_TYPE_VALUE_LEN 21 +#define GATT_OP_CODE_SIZE 1 +#define GATT_START_END_HANDLE_SIZE 4 /********************************************************************** * ATT protocl message building utility * @@ -43,20 +43,19 @@ * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_mtu_cmd(uint8_t op_code, uint16_t rx_mtu) -{ - uint8_t *p; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + GATT_HDR_SIZE + L2CAP_MIN_OFFSET); +BT_HDR* attp_build_mtu_cmd(uint8_t op_code, uint16_t rx_mtu) { + uint8_t* p; + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + GATT_HDR_SIZE + L2CAP_MIN_OFFSET); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, op_code); - UINT16_TO_STREAM(p, rx_mtu); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, op_code); + UINT16_TO_STREAM(p, rx_mtu); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = GATT_HDR_SIZE; /* opcode + 2 bytes mtu */ + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = GATT_HDR_SIZE; /* opcode + 2 bytes mtu */ - return p_buf; + return p_buf; } /******************************************************************************* * @@ -67,25 +66,24 @@ BT_HDR *attp_build_mtu_cmd(uint8_t op_code, uint16_t rx_mtu) * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_exec_write_cmd (uint8_t op_code, uint8_t flag) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(GATT_DATA_BUF_SIZE); - uint8_t *p; +BT_HDR* attp_build_exec_write_cmd(uint8_t op_code, uint8_t flag) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(GATT_DATA_BUF_SIZE); + uint8_t* p; - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = GATT_OP_CODE_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = GATT_OP_CODE_SIZE; - UINT8_TO_STREAM(p, op_code); + UINT8_TO_STREAM(p, op_code); - if (op_code == GATT_REQ_EXEC_WRITE) { - flag &= GATT_PREP_WRITE_EXEC; - UINT8_TO_STREAM (p, flag); - p_buf->len += 1; - } + if (op_code == GATT_REQ_EXEC_WRITE) { + flag &= GATT_PREP_WRITE_EXEC; + UINT8_TO_STREAM(p, flag); + p_buf->len += 1; + } - return p_buf; + return p_buf; } /******************************************************************************* @@ -97,22 +95,23 @@ BT_HDR *attp_build_exec_write_cmd (uint8_t op_code, uint8_t flag) * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_err_cmd(uint8_t cmd_code, uint16_t err_handle, uint8_t reason) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + 5); - - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, GATT_RSP_ERROR); - UINT8_TO_STREAM(p, cmd_code); - UINT16_TO_STREAM(p, err_handle); - UINT8_TO_STREAM(p, reason); - - p_buf->offset = L2CAP_MIN_OFFSET; - /* GATT_HDR_SIZE (1B ERR_RSP op code+ 2B handle) + 1B cmd_op_code + 1B status */ - p_buf->len = GATT_HDR_SIZE + 1 + 1; - - return p_buf; +BT_HDR* attp_build_err_cmd(uint8_t cmd_code, uint16_t err_handle, + uint8_t reason) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + 5); + + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, GATT_RSP_ERROR); + UINT8_TO_STREAM(p, cmd_code); + UINT16_TO_STREAM(p, err_handle); + UINT8_TO_STREAM(p, reason); + + p_buf->offset = L2CAP_MIN_OFFSET; + /* GATT_HDR_SIZE (1B ERR_RSP op code+ 2B handle) + 1B cmd_op_code + 1B status + */ + p_buf->len = GATT_HDR_SIZE + 1 + 1; + + return p_buf; } /******************************************************************************* * @@ -123,22 +122,24 @@ BT_HDR *attp_build_err_cmd(uint8_t cmd_code, uint16_t err_handle, uint8_t reason * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_browse_cmd(uint8_t op_code, uint16_t s_hdl, uint16_t e_hdl, tBT_UUID uuid) -{ - const size_t payload_size = (GATT_OP_CODE_SIZE) + (GATT_START_END_HANDLE_SIZE) + (LEN_UUID_128); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); - - uint8_t *p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Describe the built message location and size */ - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = GATT_OP_CODE_SIZE + 4; - - UINT8_TO_STREAM(p, op_code); - UINT16_TO_STREAM(p, s_hdl); - UINT16_TO_STREAM(p, e_hdl); - p_buf->len += gatt_build_uuid_to_stream(&p, uuid); - - return p_buf; +BT_HDR* attp_build_browse_cmd(uint8_t op_code, uint16_t s_hdl, uint16_t e_hdl, + tBT_UUID uuid) { + const size_t payload_size = + (GATT_OP_CODE_SIZE) + (GATT_START_END_HANDLE_SIZE) + (LEN_UUID_128); + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); + + uint8_t* p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + /* Describe the built message location and size */ + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = GATT_OP_CODE_SIZE + 4; + + UINT8_TO_STREAM(p, op_code); + UINT16_TO_STREAM(p, s_hdl); + UINT16_TO_STREAM(p, e_hdl); + p_buf->len += gatt_build_uuid_to_stream(&p, uuid); + + return p_buf; } /******************************************************************************* @@ -150,30 +151,30 @@ BT_HDR *attp_build_browse_cmd(uint8_t op_code, uint16_t s_hdl, uint16_t e_hdl, t * Returns pointer to the command buffer. * ******************************************************************************/ -BT_HDR *attp_build_read_by_type_value_cmd (uint16_t payload_size, tGATT_FIND_TYPE_VALUE *p_value_type) -{ - uint8_t *p; - uint16_t len = p_value_type->value_len; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); +BT_HDR* attp_build_read_by_type_value_cmd(uint16_t payload_size, + tGATT_FIND_TYPE_VALUE* p_value_type) { + uint8_t* p; + uint16_t len = p_value_type->value_len; + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = 5; /* opcode + s_handle + e_handle */ + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = 5; /* opcode + s_handle + e_handle */ - UINT8_TO_STREAM(p, GATT_REQ_FIND_TYPE_VALUE); - UINT16_TO_STREAM(p, p_value_type->s_handle); - UINT16_TO_STREAM(p, p_value_type->e_handle); + UINT8_TO_STREAM(p, GATT_REQ_FIND_TYPE_VALUE); + UINT16_TO_STREAM(p, p_value_type->s_handle); + UINT16_TO_STREAM(p, p_value_type->e_handle); - p_buf->len += gatt_build_uuid_to_stream(&p, p_value_type->uuid); + p_buf->len += gatt_build_uuid_to_stream(&p, p_value_type->uuid); - if (p_value_type->value_len + p_buf->len > payload_size) - len = payload_size - p_buf->len; + if (p_value_type->value_len + p_buf->len > payload_size) + len = payload_size - p_buf->len; - memcpy(p, p_value_type->value, len); - p_buf->len += len; + memcpy(p, p_value_type->value, len); + p_buf->len += len; - return p_buf; + return p_buf; } /******************************************************************************* @@ -185,24 +186,24 @@ BT_HDR *attp_build_read_by_type_value_cmd (uint16_t payload_size, tGATT_FIND_TYP * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_read_multi_cmd(uint16_t payload_size, uint16_t num_handle, uint16_t *p_handle) -{ - uint8_t *p, i = 0; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + num_handle * 2 + 1 + L2CAP_MIN_OFFSET); +BT_HDR* attp_build_read_multi_cmd(uint16_t payload_size, uint16_t num_handle, + uint16_t* p_handle) { + uint8_t *p, i = 0; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + num_handle * 2 + 1 + + L2CAP_MIN_OFFSET); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = 1; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = 1; - UINT8_TO_STREAM(p, GATT_REQ_READ_MULTI); + UINT8_TO_STREAM(p, GATT_REQ_READ_MULTI); - for (i = 0; i < num_handle && p_buf->len + 2 <= payload_size; i ++) { - UINT16_TO_STREAM (p, *(p_handle + i)); - p_buf->len += 2; - } + for (i = 0; i < num_handle && p_buf->len + 2 <= payload_size; i++) { + UINT16_TO_STREAM(p, *(p_handle + i)); + p_buf->len += 2; + } - return p_buf; + return p_buf; } /******************************************************************************* * @@ -213,27 +214,26 @@ BT_HDR *attp_build_read_multi_cmd(uint16_t payload_size, uint16_t num_handle, ui * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_handle_cmd(uint8_t op_code, uint16_t handle, uint16_t offset) -{ - uint8_t *p; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 5 + L2CAP_MIN_OFFSET); +BT_HDR* attp_build_handle_cmd(uint8_t op_code, uint16_t handle, + uint16_t offset) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + 5 + L2CAP_MIN_OFFSET); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, op_code); - p_buf->len = 1; + UINT8_TO_STREAM(p, op_code); + p_buf->len = 1; - UINT16_TO_STREAM(p, handle); - p_buf->len += 2; + UINT16_TO_STREAM(p, handle); + p_buf->len += 2; - if (op_code == GATT_REQ_READ_BLOB) { - UINT16_TO_STREAM (p, offset); - p_buf->len += 2; - } + if (op_code == GATT_REQ_READ_BLOB) { + UINT16_TO_STREAM(p, offset); + p_buf->len += 2; + } - return p_buf; + return p_buf; } /******************************************************************************* @@ -245,19 +245,17 @@ BT_HDR *attp_build_handle_cmd(uint8_t op_code, uint16_t handle, uint16_t offset) * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_opcode_cmd(uint8_t op_code) -{ - uint8_t *p; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + 1 + L2CAP_MIN_OFFSET); +BT_HDR* attp_build_opcode_cmd(uint8_t op_code) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + 1 + L2CAP_MIN_OFFSET); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, op_code); - p_buf->len = 1; + UINT8_TO_STREAM(p, op_code); + p_buf->len = 1; - return p_buf; + return p_buf; } /******************************************************************************* @@ -269,50 +267,50 @@ BT_HDR *attp_build_opcode_cmd(uint8_t op_code) * Returns None. * ******************************************************************************/ -BT_HDR *attp_build_value_cmd (uint16_t payload_size, uint8_t op_code, uint16_t handle, - uint16_t offset, uint16_t len, uint8_t *p_data) -{ - uint8_t *p, *pp, pair_len, *p_pair_len; - BT_HDR *p_buf = - (BT_HDR *)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); - - p = pp = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, op_code); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = 1; - - if (op_code == GATT_RSP_READ_BY_TYPE) { - p_pair_len = p; - pair_len = len + 2; - UINT8_TO_STREAM (p, pair_len); - p_buf->len += 1; - } - if (op_code != GATT_RSP_READ_BLOB && op_code != GATT_RSP_READ) { - UINT16_TO_STREAM (p, handle); - p_buf->len += 2; - } - - if (op_code == GATT_REQ_PREPARE_WRITE ||op_code == GATT_RSP_PREPARE_WRITE) { - UINT16_TO_STREAM (p, offset); - p_buf->len += 2; - } +BT_HDR* attp_build_value_cmd(uint16_t payload_size, uint8_t op_code, + uint16_t handle, uint16_t offset, uint16_t len, + uint8_t* p_data) { + uint8_t *p, *pp, pair_len, *p_pair_len; + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET); + + p = pp = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, op_code); + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = 1; + + if (op_code == GATT_RSP_READ_BY_TYPE) { + p_pair_len = p; + pair_len = len + 2; + UINT8_TO_STREAM(p, pair_len); + p_buf->len += 1; + } + if (op_code != GATT_RSP_READ_BLOB && op_code != GATT_RSP_READ) { + UINT16_TO_STREAM(p, handle); + p_buf->len += 2; + } - if (len > 0 && p_data != NULL) { - /* ensure data not exceed MTU size */ - if (payload_size - p_buf->len < len) { - len = payload_size - p_buf->len; - /* update handle value pair length */ - if (op_code == GATT_RSP_READ_BY_TYPE) - *p_pair_len = (len + 2); + if (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_RSP_PREPARE_WRITE) { + UINT16_TO_STREAM(p, offset); + p_buf->len += 2; + } - GATT_TRACE_WARNING("attribute value too long, to be truncated to %d", len); - } + if (len > 0 && p_data != NULL) { + /* ensure data not exceed MTU size */ + if (payload_size - p_buf->len < len) { + len = payload_size - p_buf->len; + /* update handle value pair length */ + if (op_code == GATT_RSP_READ_BY_TYPE) *p_pair_len = (len + 2); - ARRAY_TO_STREAM(p, p_data, len); - p_buf->len += len; + GATT_TRACE_WARNING("attribute value too long, to be truncated to %d", + len); } - return p_buf; + ARRAY_TO_STREAM(p, p_data, len); + p_buf->len += len; + } + + return p_buf; } /******************************************************************************* @@ -322,28 +320,24 @@ BT_HDR *attp_build_value_cmd (uint16_t payload_size, uint8_t op_code, uint16_t h * Description Send message to L2CAP. * ******************************************************************************/ -tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB *p_tcb, BT_HDR *p_toL2CAP) -{ - uint16_t l2cap_ret; - - - if (p_tcb->att_lcid == L2CAP_ATT_CID) - l2cap_ret = L2CA_SendFixedChnlData (L2CAP_ATT_CID, p_tcb->peer_bda, p_toL2CAP); - else - l2cap_ret = (uint16_t) L2CA_DataWrite (p_tcb->att_lcid, p_toL2CAP); - - if (l2cap_ret == L2CAP_DW_FAILED) - { - GATT_TRACE_ERROR("ATT failed to pass msg:0x%0x to L2CAP", - *((uint8_t *)(p_toL2CAP + 1) + p_toL2CAP->offset)); - return GATT_INTERNAL_ERROR; - } - else if (l2cap_ret == L2CAP_DW_CONGESTED) - { - GATT_TRACE_DEBUG("ATT congested, message accepted"); - return GATT_CONGESTED; - } - return GATT_SUCCESS; +tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB* p_tcb, BT_HDR* p_toL2CAP) { + uint16_t l2cap_ret; + + if (p_tcb->att_lcid == L2CAP_ATT_CID) + l2cap_ret = + L2CA_SendFixedChnlData(L2CAP_ATT_CID, p_tcb->peer_bda, p_toL2CAP); + else + l2cap_ret = (uint16_t)L2CA_DataWrite(p_tcb->att_lcid, p_toL2CAP); + + if (l2cap_ret == L2CAP_DW_FAILED) { + GATT_TRACE_ERROR("ATT failed to pass msg:0x%0x to L2CAP", + *((uint8_t*)(p_toL2CAP + 1) + p_toL2CAP->offset)); + return GATT_INTERNAL_ERROR; + } else if (l2cap_ret == L2CAP_DW_CONGESTED) { + GATT_TRACE_DEBUG("ATT congested, message accepted"); + return GATT_CONGESTED; + } + return GATT_SUCCESS; } /******************************************************************************* @@ -353,58 +347,55 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB *p_tcb, BT_HDR *p_toL2CAP) * Description Build ATT Server PDUs. * ******************************************************************************/ -BT_HDR *attp_build_sr_msg(tGATT_TCB *p_tcb, uint8_t op_code, tGATT_SR_MSG *p_msg) -{ - BT_HDR *p_cmd = NULL; - uint16_t offset = 0; +BT_HDR* attp_build_sr_msg(tGATT_TCB* p_tcb, uint8_t op_code, + tGATT_SR_MSG* p_msg) { + BT_HDR* p_cmd = NULL; + uint16_t offset = 0; - switch (op_code) - { + switch (op_code) { case GATT_RSP_READ_BLOB: case GATT_RSP_PREPARE_WRITE: - GATT_TRACE_EVENT ("ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = %d offset = %d", - p_msg->attr_value.len, p_msg->attr_value.offset); - offset = p_msg->attr_value.offset; -/* Coverity: [FALSE-POSITIVE error] intended fall through */ -/* Missing break statement between cases in switch statement */ - /* fall through */ + GATT_TRACE_EVENT( + "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = %d offset = %d", + p_msg->attr_value.len, p_msg->attr_value.offset); + offset = p_msg->attr_value.offset; + /* Coverity: [FALSE-POSITIVE error] intended fall through */ + /* Missing break statement between cases in switch statement */ + /* fall through */ case GATT_RSP_READ_BY_TYPE: case GATT_RSP_READ: case GATT_HANDLE_VALUE_NOTIF: case GATT_HANDLE_VALUE_IND: - p_cmd = attp_build_value_cmd(p_tcb->payload_size, - op_code, - p_msg->attr_value.handle, - offset, - p_msg->attr_value.len, - p_msg->attr_value.value); - break; + p_cmd = attp_build_value_cmd( + p_tcb->payload_size, op_code, p_msg->attr_value.handle, offset, + p_msg->attr_value.len, p_msg->attr_value.value); + break; case GATT_RSP_WRITE: - p_cmd = attp_build_opcode_cmd(op_code); - break; + p_cmd = attp_build_opcode_cmd(op_code); + break; case GATT_RSP_ERROR: - p_cmd = attp_build_err_cmd(p_msg->error.cmd_code, p_msg->error.handle, p_msg->error.reason); - break; + p_cmd = attp_build_err_cmd(p_msg->error.cmd_code, p_msg->error.handle, + p_msg->error.reason); + break; case GATT_RSP_EXEC_WRITE: - p_cmd = attp_build_exec_write_cmd(op_code, 0); - break; + p_cmd = attp_build_exec_write_cmd(op_code, 0); + break; case GATT_RSP_MTU: - p_cmd = attp_build_mtu_cmd(op_code, p_msg->mtu); - break; + p_cmd = attp_build_mtu_cmd(op_code, p_msg->mtu); + break; default: - GATT_TRACE_DEBUG("attp_build_sr_msg: unknown op code = %d", op_code); - break; - } + GATT_TRACE_DEBUG("attp_build_sr_msg: unknown op code = %d", op_code); + break; + } - if (!p_cmd) - GATT_TRACE_ERROR("No resources"); + if (!p_cmd) GATT_TRACE_ERROR("No resources"); - return p_cmd; + return p_cmd; } /******************************************************************************* @@ -421,19 +412,16 @@ BT_HDR *attp_build_sr_msg(tGATT_TCB *p_tcb, uint8_t op_code, tGATT_SR_MSG *p_msg * * ******************************************************************************/ -tGATT_STATUS attp_send_sr_msg (tGATT_TCB *p_tcb, BT_HDR *p_msg) -{ - tGATT_STATUS cmd_sent = GATT_NO_RESOURCES; - - if (p_tcb != NULL) - { - if (p_msg != NULL) - { - p_msg->offset = L2CAP_MIN_OFFSET; - cmd_sent = attp_send_msg_to_l2cap (p_tcb, p_msg); - } +tGATT_STATUS attp_send_sr_msg(tGATT_TCB* p_tcb, BT_HDR* p_msg) { + tGATT_STATUS cmd_sent = GATT_NO_RESOURCES; + + if (p_tcb != NULL) { + if (p_msg != NULL) { + p_msg->offset = L2CAP_MIN_OFFSET; + cmd_sent = attp_send_msg_to_l2cap(p_tcb, p_msg); } - return cmd_sent; + } + return cmd_sent; } /******************************************************************************* @@ -448,41 +436,33 @@ tGATT_STATUS attp_send_sr_msg (tGATT_TCB *p_tcb, BT_HDR *p_msg) * GATT_ERROR if command sending failure * ******************************************************************************/ -tGATT_STATUS attp_cl_send_cmd(tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t cmd_code, BT_HDR *p_cmd) -{ - tGATT_STATUS att_ret = GATT_SUCCESS; - - if (p_tcb != NULL) - { - cmd_code &= ~GATT_AUTH_SIGN_MASK; - - /* no pending request or value confirmation */ - if (p_tcb->pending_cl_req == p_tcb->next_slot_inq || - cmd_code == GATT_HANDLE_VALUE_CONF) - { - att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd); - if (att_ret == GATT_CONGESTED || att_ret == GATT_SUCCESS) - { - /* do not enq cmd if handle value confirmation or set request */ - if (cmd_code != GATT_HANDLE_VALUE_CONF && cmd_code != GATT_CMD_WRITE) - { - gatt_start_rsp_timer (clcb_idx); - gatt_cmd_enq(p_tcb, clcb_idx, false, cmd_code, NULL); - } - } - else - att_ret = GATT_INTERNAL_ERROR; - } - else - { - att_ret = GATT_CMD_STARTED; - gatt_cmd_enq(p_tcb, clcb_idx, true, cmd_code, p_cmd); +tGATT_STATUS attp_cl_send_cmd(tGATT_TCB* p_tcb, uint16_t clcb_idx, + uint8_t cmd_code, BT_HDR* p_cmd) { + tGATT_STATUS att_ret = GATT_SUCCESS; + + if (p_tcb != NULL) { + cmd_code &= ~GATT_AUTH_SIGN_MASK; + + /* no pending request or value confirmation */ + if (p_tcb->pending_cl_req == p_tcb->next_slot_inq || + cmd_code == GATT_HANDLE_VALUE_CONF) { + att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd); + if (att_ret == GATT_CONGESTED || att_ret == GATT_SUCCESS) { + /* do not enq cmd if handle value confirmation or set request */ + if (cmd_code != GATT_HANDLE_VALUE_CONF && cmd_code != GATT_CMD_WRITE) { + gatt_start_rsp_timer(clcb_idx); + gatt_cmd_enq(p_tcb, clcb_idx, false, cmd_code, NULL); } + } else + att_ret = GATT_INTERNAL_ERROR; + } else { + att_ret = GATT_CMD_STARTED; + gatt_cmd_enq(p_tcb, clcb_idx, true, cmd_code, p_cmd); } - else - att_ret = GATT_ERROR; + } else + att_ret = GATT_ERROR; - return att_ret; + return att_ret; } /******************************************************************************* * @@ -500,104 +480,91 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t cmd_c * * ******************************************************************************/ -tGATT_STATUS attp_send_cl_msg (tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t op_code, tGATT_CL_MSG *p_msg) -{ - tGATT_STATUS status = GATT_NO_RESOURCES; - BT_HDR *p_cmd = NULL; - uint16_t offset = 0, handle; - - if (p_tcb != NULL) - { - switch (op_code) - { - case GATT_REQ_MTU: - if (p_msg->mtu <= GATT_MAX_MTU_SIZE) - { - p_tcb->payload_size = p_msg->mtu; - p_cmd = attp_build_mtu_cmd(GATT_REQ_MTU, p_msg->mtu); - } - else - status = GATT_ILLEGAL_PARAMETER; - break; - - case GATT_REQ_FIND_INFO: - case GATT_REQ_READ_BY_TYPE: - case GATT_REQ_READ_BY_GRP_TYPE: - if (GATT_HANDLE_IS_VALID (p_msg->browse.s_handle) && - GATT_HANDLE_IS_VALID (p_msg->browse.e_handle) && - p_msg->browse.s_handle <= p_msg->browse.e_handle) - { - p_cmd = attp_build_browse_cmd(op_code, - p_msg->browse.s_handle, - p_msg->browse.e_handle, - p_msg->browse.uuid); - } - else - status = GATT_ILLEGAL_PARAMETER; - break; - - case GATT_REQ_READ_BLOB: - offset = p_msg->read_blob.offset; - /* fall through */ - case GATT_REQ_READ: - handle = (op_code == GATT_REQ_READ) ? p_msg->handle: p_msg->read_blob.handle; - /* handle checking */ - if (GATT_HANDLE_IS_VALID (handle)) - { - p_cmd = attp_build_handle_cmd(op_code, handle, offset); - } - else - status = GATT_ILLEGAL_PARAMETER; - break; - - case GATT_HANDLE_VALUE_CONF: - p_cmd = attp_build_opcode_cmd(op_code); - break; - - case GATT_REQ_PREPARE_WRITE: - offset = p_msg->attr_value.offset; - /* fall through */ - case GATT_REQ_WRITE: - case GATT_CMD_WRITE: - case GATT_SIGN_CMD_WRITE: - if (GATT_HANDLE_IS_VALID (p_msg->attr_value.handle)) - { - p_cmd = attp_build_value_cmd (p_tcb->payload_size, - op_code, p_msg->attr_value.handle, - offset, - p_msg->attr_value.len, - p_msg->attr_value.value); - } - else - status = GATT_ILLEGAL_PARAMETER; - break; - - case GATT_REQ_EXEC_WRITE: - p_cmd = attp_build_exec_write_cmd(op_code, p_msg->exec_write); - break; - - case GATT_REQ_FIND_TYPE_VALUE: - p_cmd = attp_build_read_by_type_value_cmd(p_tcb->payload_size, &p_msg->find_type_value); - break; - - case GATT_REQ_READ_MULTI: - p_cmd = attp_build_read_multi_cmd(p_tcb->payload_size, - p_msg->read_multi.num_handles, - p_msg->read_multi.handles); - break; - - default: - break; - } +tGATT_STATUS attp_send_cl_msg(tGATT_TCB* p_tcb, uint16_t clcb_idx, + uint8_t op_code, tGATT_CL_MSG* p_msg) { + tGATT_STATUS status = GATT_NO_RESOURCES; + BT_HDR* p_cmd = NULL; + uint16_t offset = 0, handle; + + if (p_tcb != NULL) { + switch (op_code) { + case GATT_REQ_MTU: + if (p_msg->mtu <= GATT_MAX_MTU_SIZE) { + p_tcb->payload_size = p_msg->mtu; + p_cmd = attp_build_mtu_cmd(GATT_REQ_MTU, p_msg->mtu); + } else + status = GATT_ILLEGAL_PARAMETER; + break; - if (p_cmd != NULL) - status = attp_cl_send_cmd(p_tcb, clcb_idx, op_code, p_cmd); + case GATT_REQ_FIND_INFO: + case GATT_REQ_READ_BY_TYPE: + case GATT_REQ_READ_BY_GRP_TYPE: + if (GATT_HANDLE_IS_VALID(p_msg->browse.s_handle) && + GATT_HANDLE_IS_VALID(p_msg->browse.e_handle) && + p_msg->browse.s_handle <= p_msg->browse.e_handle) { + p_cmd = + attp_build_browse_cmd(op_code, p_msg->browse.s_handle, + p_msg->browse.e_handle, p_msg->browse.uuid); + } else + status = GATT_ILLEGAL_PARAMETER; + break; + case GATT_REQ_READ_BLOB: + offset = p_msg->read_blob.offset; + /* fall through */ + case GATT_REQ_READ: + handle = (op_code == GATT_REQ_READ) ? p_msg->handle + : p_msg->read_blob.handle; + /* handle checking */ + if (GATT_HANDLE_IS_VALID(handle)) { + p_cmd = attp_build_handle_cmd(op_code, handle, offset); + } else + status = GATT_ILLEGAL_PARAMETER; + break; + + case GATT_HANDLE_VALUE_CONF: + p_cmd = attp_build_opcode_cmd(op_code); + break; + + case GATT_REQ_PREPARE_WRITE: + offset = p_msg->attr_value.offset; + /* fall through */ + case GATT_REQ_WRITE: + case GATT_CMD_WRITE: + case GATT_SIGN_CMD_WRITE: + if (GATT_HANDLE_IS_VALID(p_msg->attr_value.handle)) { + p_cmd = attp_build_value_cmd( + p_tcb->payload_size, op_code, p_msg->attr_value.handle, offset, + p_msg->attr_value.len, p_msg->attr_value.value); + } else + status = GATT_ILLEGAL_PARAMETER; + break; + + case GATT_REQ_EXEC_WRITE: + p_cmd = attp_build_exec_write_cmd(op_code, p_msg->exec_write); + break; + + case GATT_REQ_FIND_TYPE_VALUE: + p_cmd = attp_build_read_by_type_value_cmd(p_tcb->payload_size, + &p_msg->find_type_value); + break; + + case GATT_REQ_READ_MULTI: + p_cmd = attp_build_read_multi_cmd(p_tcb->payload_size, + p_msg->read_multi.num_handles, + p_msg->read_multi.handles); + break; + + default: + break; } - else - { - GATT_TRACE_ERROR("Peer device not connected"); - } - return status; + if (p_cmd != NULL) + status = attp_cl_send_cmd(p_tcb, clcb_idx, op_code, p_cmd); + + } else { + GATT_TRACE_ERROR("Peer device not connected"); + } + + return status; } diff --git a/stack/gatt/gatt_api.cc b/stack/gatt/gatt_api.cc index f2747cf71..f3b5a1f07 100644 --- a/stack/gatt/gatt_api.cc +++ b/stack/gatt/gatt_api.cc @@ -23,13 +23,13 @@ ******************************************************************************/ #include "bt_target.h" -#include "bt_common.h" #include #include +#include "bt_common.h" +#include "btm_int.h" #include "gatt_api.h" #include "gatt_int.h" #include "l2c_api.h" -#include "btm_int.h" /******************************************************************************* * @@ -51,12 +51,10 @@ * Returns The new or current trace level * ******************************************************************************/ -uint8_t GATT_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - gatt_cb.trace_level = new_level; +uint8_t GATT_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) gatt_cb.trace_level = new_level; - return(gatt_cb.trace_level); + return (gatt_cb.trace_level); } /***************************************************************************** @@ -78,21 +76,18 @@ uint8_t GATT_SetTraceLevel (uint8_t new_level) * ******************************************************************************/ -bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range) -{ - tGATT_HDL_LIST_ELEM *p_buf; - bool status= false; +bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE* p_hndl_range) { + tGATT_HDL_LIST_ELEM* p_buf; + bool status = false; - p_buf = gatt_alloc_hdl_buffer(); - if (p_buf != NULL) - { - p_buf->asgn_range = *p_hndl_range; - status = gatt_add_an_item_to_list(&gatt_cb.hdl_list_info, p_buf); - } - return status; + p_buf = gatt_alloc_hdl_buffer(); + if (p_buf != NULL) { + p_buf->asgn_range = *p_hndl_range; + status = gatt_add_an_item_to_list(&gatt_cb.hdl_list_info, p_buf); + } + return status; } - /******************************************************************************* * * Function GATTS_NVRegister @@ -106,89 +101,80 @@ bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range) * Returns true if registered OK, else false * ******************************************************************************/ -bool GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info) -{ - bool status= false; - if (p_cb_info) - { - gatt_cb.cb_info = *p_cb_info; - status = true; - gatt_init_srv_chg(); - } - - return status; +bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info) { + bool status = false; + if (p_cb_info) { + gatt_cb.cb_info = *p_cb_info; + status = true; + gatt_init_srv_chg(); + } + + return status; } static uint8_t BASE_UUID[16] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -static int uuidType(unsigned char* p_uuid) -{ - if (memcmp(p_uuid, BASE_UUID, 12) != 0) - return LEN_UUID_128; - if (memcmp(p_uuid + 14, BASE_UUID + 14, 2) != 0) - return LEN_UUID_32; +static int uuidType(unsigned char* p_uuid) { + if (memcmp(p_uuid, BASE_UUID, 12) != 0) return LEN_UUID_128; + if (memcmp(p_uuid + 14, BASE_UUID + 14, 2) != 0) return LEN_UUID_32; - return LEN_UUID_16; + return LEN_UUID_16; } /******************************************************************************* * BTIF -> BTA conversion functions ******************************************************************************/ -static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) -{ - char *p_byte = (char*)p_src; - int i = 0; +static void btif_to_bta_uuid(tBT_UUID* p_dest, bt_uuid_t* p_src) { + char* p_byte = (char*)p_src; + int i = 0; - p_dest->len = uuidType(p_src->uu); + p_dest->len = uuidType(p_src->uu); - switch (p_dest->len) - { - case LEN_UUID_16: - p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12]; - break; + switch (p_dest->len) { + case LEN_UUID_16: + p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12]; + break; - case LEN_UUID_32: - p_dest->uu.uuid32 = (p_src->uu[15] << 24) + (p_src->uu[14] << 16) - + (p_src->uu[13] << 8) + p_src->uu[12]; - break; + case LEN_UUID_32: + p_dest->uu.uuid32 = (p_src->uu[15] << 24) + (p_src->uu[14] << 16) + + (p_src->uu[13] << 8) + p_src->uu[12]; + break; - case LEN_UUID_128: - for(i = 0; i != 16; ++i) - p_dest->uu.uuid128[i] = p_byte[i]; - break; + case LEN_UUID_128: + for (i = 0; i != 16; ++i) p_dest->uu.uuid128[i] = p_byte[i]; + break; - default: - GATT_TRACE_ERROR("%s: Unknown UUID length %d!", __func__, p_dest->len); - break; - } + default: + GATT_TRACE_ERROR("%s: Unknown UUID length %d!", __func__, p_dest->len); + break; + } } -void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16) { +void uuid_128_from_16(bt_uuid_t* uuid, uint16_t uuid16) { memcpy(uuid, &BASE_UUID, sizeof(bt_uuid_t)); - uuid->uu[13] = (uint8_t)((0xFF00 & uuid16)>>8); + uuid->uu[13] = (uint8_t)((0xFF00 & uuid16) >> 8); uuid->uu[12] = (uint8_t)(0x00FF & uuid16); } +static uint16_t compute_service_size(btgatt_db_element_t* service, int count) { + int db_size = 0; + btgatt_db_element_t* el = service; + + for (int i = 0; i < count; i++, el++) + if (el->type == BTGATT_DB_PRIMARY_SERVICE || + el->type == BTGATT_DB_SECONDARY_SERVICE || + el->type == BTGATT_DB_DESCRIPTOR || + el->type == BTGATT_DB_INCLUDED_SERVICE) + db_size += 1; + else if (el->type == BTGATT_DB_CHARACTERISTIC) + db_size += 2; + else + GATT_TRACE_ERROR("%s: Unknown element type: %d", __func__, el->type); -static uint16_t compute_service_size(btgatt_db_element_t *service, int count) { - int db_size = 0; - btgatt_db_element_t *el = service; - - for (int i = 0; itype == BTGATT_DB_PRIMARY_SERVICE || - el->type == BTGATT_DB_SECONDARY_SERVICE || - el->type == BTGATT_DB_DESCRIPTOR || - el->type == BTGATT_DB_INCLUDED_SERVICE) - db_size += 1; - else if (el->type == BTGATT_DB_CHARACTERISTIC) - db_size += 2; - else - GATT_TRACE_ERROR("%s: Unknown element type: %d", __func__, el->type); - - return db_size; + return db_size; } /******************************************************************************* * @@ -205,158 +191,163 @@ static uint16_t compute_service_size(btgatt_db_element_t *service, int count) { * on error error status is returned. * ******************************************************************************/ -uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t *service, int count) { - tGATT_HDL_LIST_INFO *p_list_info= &gatt_cb.hdl_list_info; - tGATT_HDL_LIST_ELEM *p_list=NULL; - uint16_t s_hdl=0; - bool save_hdl=false; - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tBT_UUID *p_app_uuid128; - - bool is_pri = (service->type == BTGATT_DB_PRIMARY_SERVICE) ? true : false; - tBT_UUID svc_uuid; - btif_to_bta_uuid(&svc_uuid, &service->uuid); - - GATT_TRACE_API("%s", __func__); - - if (p_reg == NULL) - { - GATT_TRACE_ERROR ("Inavlid gatt_if=%d", gatt_if); - return GATT_INTERNAL_ERROR; +uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t* service, + int count) { + tGATT_HDL_LIST_INFO* p_list_info = &gatt_cb.hdl_list_info; + tGATT_HDL_LIST_ELEM* p_list = NULL; + uint16_t s_hdl = 0; + bool save_hdl = false; + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tBT_UUID* p_app_uuid128; + + bool is_pri = (service->type == BTGATT_DB_PRIMARY_SERVICE) ? true : false; + tBT_UUID svc_uuid; + btif_to_bta_uuid(&svc_uuid, &service->uuid); + + GATT_TRACE_API("%s", __func__); + + if (p_reg == NULL) { + GATT_TRACE_ERROR("Inavlid gatt_if=%d", gatt_if); + return GATT_INTERNAL_ERROR; + } + + p_app_uuid128 = &p_reg->app_uuid128; + + uint16_t num_handles = compute_service_size(service, count); + + if ((svc_uuid.len == LEN_UUID_16) && + (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GATT_SERVER)) { + s_hdl = gatt_cb.hdl_cfg.gatt_start_hdl; + } else if ((svc_uuid.len == LEN_UUID_16) && + (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GAP_SERVER)) { + s_hdl = gatt_cb.hdl_cfg.gap_start_hdl; + } else { + p_list = p_list_info->p_first; + + if (p_list) s_hdl = p_list->asgn_range.e_handle + 1; + + if (s_hdl < gatt_cb.hdl_cfg.app_start_hdl) + s_hdl = gatt_cb.hdl_cfg.app_start_hdl; + + save_hdl = true; + } + + /* check for space */ + if (num_handles > (0xFFFF - s_hdl + 1)) { + GATT_TRACE_ERROR("GATTS_ReserveHandles: no handles, s_hdl: %u needed: %u", + s_hdl, num_handles); + return GATT_INTERNAL_ERROR; + } + + p_list = gatt_alloc_hdl_buffer(); + if (p_list == NULL) { + /* No free entry */ + GATT_TRACE_ERROR("GATTS_ReserveHandles: no free handle blocks"); + return GATT_INTERNAL_ERROR; + } + + p_list->asgn_range.app_uuid128 = *p_app_uuid128; + p_list->asgn_range.svc_uuid = svc_uuid; + p_list->asgn_range.s_handle = s_hdl; + p_list->asgn_range.e_handle = s_hdl + num_handles - 1; + p_list->asgn_range.is_primary = is_pri; + + gatt_add_an_item_to_list(p_list_info, p_list); + + if (save_hdl) { + if (gatt_cb.cb_info.p_nv_save_callback) + (*gatt_cb.cb_info.p_nv_save_callback)(true, &p_list->asgn_range); + } + + if (!gatts_init_service_db(&p_list->svc_db, &svc_uuid, is_pri, s_hdl, + num_handles)) { + GATT_TRACE_ERROR("GATTS_ReserveHandles: service DB initialization failed"); + if (p_list) { + gatt_remove_an_item_from_list(p_list_info, p_list); + gatt_free_hdl_buffer(p_list); } - p_app_uuid128 = &p_reg->app_uuid128; - - uint16_t num_handles = compute_service_size(service, count); - - if ( (svc_uuid.len == LEN_UUID_16) && (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GATT_SERVER)) { - s_hdl= gatt_cb.hdl_cfg.gatt_start_hdl; - } else if ((svc_uuid.len == LEN_UUID_16) && (svc_uuid.uu.uuid16 == UUID_SERVCLASS_GAP_SERVER)) { - s_hdl= gatt_cb.hdl_cfg.gap_start_hdl; - } else { - p_list = p_list_info->p_first; - - if (p_list) - s_hdl = p_list->asgn_range.e_handle + 1; - - if (s_hdl < gatt_cb.hdl_cfg.app_start_hdl) - s_hdl = gatt_cb.hdl_cfg.app_start_hdl; - - save_hdl = true; - } - - /* check for space */ - if (num_handles > (0xFFFF - s_hdl + 1)) { - GATT_TRACE_ERROR ("GATTS_ReserveHandles: no handles, s_hdl: %u needed: %u", s_hdl, num_handles); + return GATT_INTERNAL_ERROR; + } + + GATT_TRACE_DEBUG( + "%d: handles needed:%u s_hdl=%u e_hdl=%u %s[%x] is_primary=%d", __func__, + num_handles, p_list->asgn_range.s_handle, p_list->asgn_range.e_handle, + ((p_list->asgn_range.svc_uuid.len == 2) ? "uuid16" : "uuid128"), + p_list->asgn_range.svc_uuid.uu.uuid16, p_list->asgn_range.is_primary); + + service->attribute_handle = s_hdl; + + btgatt_db_element_t* el = service + 1; + for (int i = 0; i < count - 1; i++, el++) { + tBT_UUID uuid; + btif_to_bta_uuid(&uuid, &el->uuid); + + if (el->type == BTGATT_DB_CHARACTERISTIC) { + /* data validity checking */ + if (((el->properties & GATT_CHAR_PROP_BIT_AUTH) && + !(el->permissions & GATT_WRITE_SIGNED_PERM)) || + ((el->permissions & GATT_WRITE_SIGNED_PERM) && + !(el->properties & GATT_CHAR_PROP_BIT_AUTH))) { + GATT_TRACE_DEBUG("Invalid configuration property=0x%02x perm=0x%04x ", + el->properties, el->permissions); return GATT_INTERNAL_ERROR; - } - - p_list = gatt_alloc_hdl_buffer(); - if (p_list == NULL) { - /* No free entry */ - GATT_TRACE_ERROR ("GATTS_ReserveHandles: no free handle blocks"); + } + + el->attribute_handle = gatts_add_characteristic( + &p_list->svc_db, el->permissions, el->properties, &uuid); + } else if (el->type == BTGATT_DB_DESCRIPTOR) { + el->attribute_handle = + gatts_add_char_descr(&p_list->svc_db, el->permissions, &uuid); + } else if (el->type == BTGATT_DB_INCLUDED_SERVICE) { + tGATT_HDL_LIST_ELEM* p_incl_decl; + p_incl_decl = gatt_find_hdl_buffer_by_handle(el->attribute_handle); + if (p_incl_decl == NULL) { + GATT_TRACE_DEBUG("Included Service not created"); return GATT_INTERNAL_ERROR; - } - - p_list->asgn_range.app_uuid128 = *p_app_uuid128; - p_list->asgn_range.svc_uuid = svc_uuid; - p_list->asgn_range.s_handle = s_hdl; - p_list->asgn_range.e_handle = s_hdl+num_handles-1; - p_list->asgn_range.is_primary = is_pri; + } - gatt_add_an_item_to_list(p_list_info, p_list); - - if (save_hdl) { - if (gatt_cb.cb_info.p_nv_save_callback) - (*gatt_cb.cb_info.p_nv_save_callback)(true, &p_list->asgn_range); + el->attribute_handle = gatts_add_included_service( + &p_list->svc_db, p_incl_decl->asgn_range.s_handle, + p_incl_decl->asgn_range.e_handle, p_incl_decl->asgn_range.svc_uuid); } + } - if (!gatts_init_service_db(&p_list->svc_db, &svc_uuid, is_pri, s_hdl , num_handles)) - { - GATT_TRACE_ERROR ("GATTS_ReserveHandles: service DB initialization failed"); - if (p_list) - { - gatt_remove_an_item_from_list(p_list_info, p_list); - gatt_free_hdl_buffer(p_list); - } + tGATT_SR_REG* p_sreg; + uint8_t i_sreg; + tBT_UUID* p_uuid; - return GATT_INTERNAL_ERROR; - } + GATT_TRACE_API("%s: service parsed correctly, now starting", __func__); - GATT_TRACE_DEBUG ("%d: handles needed:%u s_hdl=%u e_hdl=%u %s[%x] is_primary=%d", __func__, - num_handles, p_list->asgn_range.s_handle , p_list->asgn_range.e_handle, - ((p_list->asgn_range.svc_uuid.len == 2) ? "uuid16": "uuid128" ), - p_list->asgn_range.svc_uuid.uu.uuid16, - p_list->asgn_range.is_primary); - - service->attribute_handle = s_hdl; - - btgatt_db_element_t *el = service +1; - for (int i = 0; iuuid); - - if (el->type == BTGATT_DB_CHARACTERISTIC) { - /* data validity checking */ - if (((el->properties & GATT_CHAR_PROP_BIT_AUTH) && !(el->permissions & GATT_WRITE_SIGNED_PERM)) || - ((el->permissions & GATT_WRITE_SIGNED_PERM) && !(el->properties & GATT_CHAR_PROP_BIT_AUTH)) ) { - GATT_TRACE_DEBUG("Invalid configuration property=0x%02x perm=0x%04x ", el->properties, el->permissions); - return GATT_INTERNAL_ERROR; - } - - el->attribute_handle = gatts_add_characteristic(&p_list->svc_db, el->permissions, el->properties, &uuid); - } else if (el->type == BTGATT_DB_DESCRIPTOR) { - el->attribute_handle = gatts_add_char_descr(&p_list->svc_db, el->permissions, &uuid); - } else if (el->type == BTGATT_DB_INCLUDED_SERVICE) { - tGATT_HDL_LIST_ELEM *p_incl_decl; - p_incl_decl = gatt_find_hdl_buffer_by_handle(el->attribute_handle); - if (p_incl_decl == NULL) { - GATT_TRACE_DEBUG("Included Service not created"); - return GATT_INTERNAL_ERROR; - } - - el->attribute_handle = gatts_add_included_service(&p_list->svc_db, - p_incl_decl->asgn_range.s_handle, - p_incl_decl->asgn_range.e_handle, - p_incl_decl->asgn_range.svc_uuid); - } - } - - tGATT_SR_REG *p_sreg; - uint8_t i_sreg; - tBT_UUID *p_uuid; + /*this is a new application servoce start */ + i_sreg = gatt_sr_alloc_rcb(p_list); + if (i_sreg == GATT_MAX_SR_PROFILES) { + GATT_TRACE_ERROR("%s: no free server registration block", __func__); + return GATT_NO_RESOURCES; + } - GATT_TRACE_API("%s: service parsed correctly, now starting", __func__); + p_sreg = &gatt_cb.sr_reg[i_sreg]; + p_sreg->gatt_if = gatt_if; - /*this is a new application servoce start */ - i_sreg = gatt_sr_alloc_rcb(p_list); - if (i_sreg == GATT_MAX_SR_PROFILES) { - GATT_TRACE_ERROR ("%s: no free server registration block", __func__); - return GATT_NO_RESOURCES; - } + if (p_sreg->type == GATT_UUID_PRI_SERVICE) { + p_uuid = gatts_get_service_uuid(p_sreg->p_db); + p_sreg->sdp_handle = + gatt_add_sdp_record(p_uuid, p_sreg->s_hdl, p_sreg->e_hdl); + } - p_sreg = &gatt_cb.sr_reg[i_sreg]; - p_sreg->gatt_if = gatt_if; - - if (p_sreg->type == GATT_UUID_PRI_SERVICE) { - p_uuid = gatts_get_service_uuid(p_sreg->p_db); - p_sreg->sdp_handle = gatt_add_sdp_record(p_uuid, p_sreg->s_hdl, p_sreg->e_hdl); - } + gatts_update_srv_list_elem(i_sreg, p_sreg->s_hdl, + p_list->asgn_range.is_primary); - gatts_update_srv_list_elem(i_sreg, p_sreg->s_hdl, - p_list->asgn_range.is_primary); + gatt_add_a_srv_to_list(&gatt_cb.srv_list_info, &gatt_cb.srv_list[i_sreg]); - gatt_add_a_srv_to_list(&gatt_cb.srv_list_info, &gatt_cb.srv_list[i_sreg]); + GATT_TRACE_DEBUG("%s: allocated i_sreg=%d ", __func__, i_sreg); + GATT_TRACE_DEBUG("%s: s_hdl=%d e_hdl=%d type=0x%x sdp_hdl=0x%x", __func__, + p_sreg->s_hdl, p_sreg->e_hdl, p_sreg->type, + p_sreg->sdp_handle); - GATT_TRACE_DEBUG("%s: allocated i_sreg=%d ",__func__, i_sreg); - GATT_TRACE_DEBUG("%s: s_hdl=%d e_hdl=%d type=0x%x sdp_hdl=0x%x", __func__, - p_sreg->s_hdl,p_sreg->e_hdl, - p_sreg->type, - p_sreg->sdp_handle); + gatt_proc_srv_chg(); - gatt_proc_srv_chg(); - - return GATT_SERVICE_STARTED; + return GATT_SERVICE_STARTED; } /******************************************************************************* @@ -373,50 +364,46 @@ uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t *service, int co * was not found. * ******************************************************************************/ -bool GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, uint16_t svc_inst) -{ - - tGATT_HDL_LIST_INFO *p_list_info= &gatt_cb.hdl_list_info; - tGATT_HDL_LIST_ELEM *p_list=NULL; - uint8_t i_sreg; - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tBT_UUID *p_app_uuid128; - - GATT_TRACE_DEBUG ("GATTS_DeleteService"); - - if (p_reg == NULL) - { - GATT_TRACE_ERROR ("Applicaiton not foud"); - return false; - } - p_app_uuid128 = &p_reg->app_uuid128; - - p_list = gatt_find_hdl_buffer_by_app_id(p_app_uuid128, p_svc_uuid, svc_inst); - if (p_list == NULL) - { - GATT_TRACE_ERROR ("No Service found"); - return false; - } - - gatt_proc_srv_chg(); - - i_sreg = gatt_sr_find_i_rcb_by_app_id(p_app_uuid128, p_svc_uuid, svc_inst); - if (i_sreg != GATT_MAX_SR_PROFILES) - { - GATTS_StopService(gatt_cb.sr_reg[i_sreg].s_hdl); - } - - GATT_TRACE_DEBUG ("released handles s_hdl=%u e_hdl=%u", - p_list->asgn_range.s_handle , p_list->asgn_range.e_handle ); - - if ( (p_list->asgn_range.s_handle >= gatt_cb.hdl_cfg.app_start_hdl) - && gatt_cb.cb_info.p_nv_save_callback) - (*gatt_cb.cb_info.p_nv_save_callback)(false, &p_list->asgn_range); - - gatt_remove_an_item_from_list(p_list_info, p_list); - gatt_free_hdl_buffer(p_list); - - return true; +bool GATTS_DeleteService(tGATT_IF gatt_if, tBT_UUID* p_svc_uuid, + uint16_t svc_inst) { + tGATT_HDL_LIST_INFO* p_list_info = &gatt_cb.hdl_list_info; + tGATT_HDL_LIST_ELEM* p_list = NULL; + uint8_t i_sreg; + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tBT_UUID* p_app_uuid128; + + GATT_TRACE_DEBUG("GATTS_DeleteService"); + + if (p_reg == NULL) { + GATT_TRACE_ERROR("Applicaiton not foud"); + return false; + } + p_app_uuid128 = &p_reg->app_uuid128; + + p_list = gatt_find_hdl_buffer_by_app_id(p_app_uuid128, p_svc_uuid, svc_inst); + if (p_list == NULL) { + GATT_TRACE_ERROR("No Service found"); + return false; + } + + gatt_proc_srv_chg(); + + i_sreg = gatt_sr_find_i_rcb_by_app_id(p_app_uuid128, p_svc_uuid, svc_inst); + if (i_sreg != GATT_MAX_SR_PROFILES) { + GATTS_StopService(gatt_cb.sr_reg[i_sreg].s_hdl); + } + + GATT_TRACE_DEBUG("released handles s_hdl=%u e_hdl=%u", + p_list->asgn_range.s_handle, p_list->asgn_range.e_handle); + + if ((p_list->asgn_range.s_handle >= gatt_cb.hdl_cfg.app_start_hdl) && + gatt_cb.cb_info.p_nv_save_callback) + (*gatt_cb.cb_info.p_nv_save_callback)(false, &p_list->asgn_range); + + gatt_remove_an_item_from_list(p_list_info, p_list); + gatt_free_hdl_buffer(p_list); + + return true; } /******************************************************************************* @@ -430,27 +417,23 @@ bool GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, uint16_t sv * Returns None. * ******************************************************************************/ -void GATTS_StopService (uint16_t service_handle) -{ - uint8_t ii = gatt_sr_find_i_rcb_by_handle(service_handle); - - GATT_TRACE_API("GATTS_StopService %u", service_handle); - - /* Index 0 is reserved for GATT, and is never stopped */ - if ( (ii > 0) && (ii < GATT_MAX_SR_PROFILES) && (gatt_cb.sr_reg[ii].in_use) ) - { - if (gatt_cb.sr_reg[ii].sdp_handle) - { - SDP_DeleteRecord(gatt_cb.sr_reg[ii].sdp_handle); - } - gatt_remove_a_srv_from_list(&gatt_cb.srv_list_info, &gatt_cb.srv_list[ii]); - gatt_cb.srv_list[ii].in_use = false; - memset (&gatt_cb.sr_reg[ii], 0, sizeof(tGATT_SR_REG)); - } - else - { - GATT_TRACE_ERROR("GATTS_StopService service_handle: %u is not in use", service_handle); +void GATTS_StopService(uint16_t service_handle) { + uint8_t ii = gatt_sr_find_i_rcb_by_handle(service_handle); + + GATT_TRACE_API("GATTS_StopService %u", service_handle); + + /* Index 0 is reserved for GATT, and is never stopped */ + if ((ii > 0) && (ii < GATT_MAX_SR_PROFILES) && (gatt_cb.sr_reg[ii].in_use)) { + if (gatt_cb.sr_reg[ii].sdp_handle) { + SDP_DeleteRecord(gatt_cb.sr_reg[ii].sdp_handle); } + gatt_remove_a_srv_from_list(&gatt_cb.srv_list_info, &gatt_cb.srv_list[ii]); + gatt_cb.srv_list[ii].in_use = false; + memset(&gatt_cb.sr_reg[ii], 0, sizeof(tGATT_SR_REG)); + } else { + GATT_TRACE_ERROR("GATTS_StopService service_handle: %u is not in use", + service_handle); + } } /******************************************************************************* * @@ -468,64 +451,54 @@ void GATTS_StopService (uint16_t service_handle) * code. * ******************************************************************************/ -tGATT_STATUS GATTS_HandleValueIndication (uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t *p_val) -{ - tGATT_STATUS cmd_status = GATT_NO_RESOURCES; - - tGATT_VALUE indication; - BT_HDR *p_msg; - tGATT_VALUE *p_buf; - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - - - GATT_TRACE_API ("GATTS_HandleValueIndication"); - if ( (p_reg == NULL) || (p_tcb == NULL)) - { - GATT_TRACE_ERROR ("GATTS_HandleValueIndication Unknown conn_id: %u ", conn_id); - return(tGATT_STATUS) GATT_INVALID_CONN_ID; +tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle, + uint16_t val_len, uint8_t* p_val) { + tGATT_STATUS cmd_status = GATT_NO_RESOURCES; + + tGATT_VALUE indication; + BT_HDR* p_msg; + tGATT_VALUE* p_buf; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + + GATT_TRACE_API("GATTS_HandleValueIndication"); + if ((p_reg == NULL) || (p_tcb == NULL)) { + GATT_TRACE_ERROR("GATTS_HandleValueIndication Unknown conn_id: %u ", + conn_id); + return (tGATT_STATUS)GATT_INVALID_CONN_ID; + } + + if (!GATT_HANDLE_IS_VALID(attr_handle)) return GATT_ILLEGAL_PARAMETER; + + indication.conn_id = conn_id; + indication.handle = attr_handle; + indication.len = val_len; + memcpy(indication.value, p_val, val_len); + indication.auth_req = GATT_AUTH_REQ_NONE; + + if (GATT_HANDLE_IS_VALID(p_tcb->indicate_handle)) { + GATT_TRACE_DEBUG("Add a pending indication"); + p_buf = gatt_add_pending_ind(p_tcb, &indication); + if (p_buf != NULL) { + cmd_status = GATT_SUCCESS; + } else { + cmd_status = GATT_NO_RESOURCES; } - - if (! GATT_HANDLE_IS_VALID (attr_handle)) - return GATT_ILLEGAL_PARAMETER; - - indication.conn_id = conn_id; - indication.handle = attr_handle; - indication.len = val_len; - memcpy (indication.value, p_val, val_len); - indication.auth_req = GATT_AUTH_REQ_NONE; - - if (GATT_HANDLE_IS_VALID(p_tcb->indicate_handle)) - { - GATT_TRACE_DEBUG ("Add a pending indication"); - p_buf = gatt_add_pending_ind(p_tcb, &indication); - if (p_buf !=NULL) - { - cmd_status = GATT_SUCCESS; - } - else - { - cmd_status = GATT_NO_RESOURCES; - } + } else { + p_msg = attp_build_sr_msg(p_tcb, GATT_HANDLE_VALUE_IND, + (tGATT_SR_MSG*)&indication); + if (p_msg != NULL) { + cmd_status = attp_send_sr_msg(p_tcb, p_msg); + + if (cmd_status == GATT_SUCCESS || cmd_status == GATT_CONGESTED) { + p_tcb->indicate_handle = indication.handle; + gatt_start_conf_timer(p_tcb); + } } - else - { - - p_msg = attp_build_sr_msg(p_tcb, GATT_HANDLE_VALUE_IND, (tGATT_SR_MSG *)&indication); - if (p_msg != NULL) - { - cmd_status = attp_send_sr_msg (p_tcb, p_msg); - - if (cmd_status == GATT_SUCCESS || cmd_status == GATT_CONGESTED) - { - p_tcb->indicate_handle = indication.handle; - gatt_start_conf_timer(p_tcb); - } - } - } - return cmd_status; + } + return cmd_status; } /******************************************************************************* @@ -543,41 +516,40 @@ tGATT_STATUS GATTS_HandleValueIndication (uint16_t conn_id, uint16_t attr_handl * Returns GATT_SUCCESS if sucessfully sent; otherwise error code. * ******************************************************************************/ -tGATT_STATUS GATTS_HandleValueNotification (uint16_t conn_id, uint16_t attr_handle, - uint16_t val_len, uint8_t *p_val) -{ - tGATT_STATUS cmd_sent = GATT_ILLEGAL_PARAMETER; - BT_HDR *p_buf; - tGATT_VALUE notif; - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - - GATT_TRACE_API ("GATTS_HandleValueNotification"); - - if ( (p_reg == NULL) || (p_tcb == NULL)) - { - GATT_TRACE_ERROR ("GATTS_HandleValueNotification Unknown conn_id: %u ", conn_id); - return(tGATT_STATUS) GATT_INVALID_CONN_ID; - } - - if (GATT_HANDLE_IS_VALID (attr_handle)) - { - notif.handle = attr_handle; - notif.len = val_len; - memcpy (notif.value, p_val, val_len); - notif.auth_req = GATT_AUTH_REQ_NONE;; - - p_buf = attp_build_sr_msg(p_tcb, GATT_HANDLE_VALUE_NOTIF, (tGATT_SR_MSG *)¬if); - if (p_buf != NULL) - { - cmd_sent = attp_send_sr_msg (p_tcb, p_buf); - } - else - cmd_sent = GATT_NO_RESOURCES; - } - return cmd_sent; +tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, + uint16_t attr_handle, + uint16_t val_len, uint8_t* p_val) { + tGATT_STATUS cmd_sent = GATT_ILLEGAL_PARAMETER; + BT_HDR* p_buf; + tGATT_VALUE notif; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + + GATT_TRACE_API("GATTS_HandleValueNotification"); + + if ((p_reg == NULL) || (p_tcb == NULL)) { + GATT_TRACE_ERROR("GATTS_HandleValueNotification Unknown conn_id: %u ", + conn_id); + return (tGATT_STATUS)GATT_INVALID_CONN_ID; + } + + if (GATT_HANDLE_IS_VALID(attr_handle)) { + notif.handle = attr_handle; + notif.len = val_len; + memcpy(notif.value, p_val, val_len); + notif.auth_req = GATT_AUTH_REQ_NONE; + ; + + p_buf = attp_build_sr_msg(p_tcb, GATT_HANDLE_VALUE_NOTIF, + (tGATT_SR_MSG*)¬if); + if (p_buf != NULL) { + cmd_sent = attp_send_sr_msg(p_tcb, p_buf); + } else + cmd_sent = GATT_NO_RESOURCES; + } + return cmd_sent; } /******************************************************************************* @@ -594,35 +566,33 @@ tGATT_STATUS GATTS_HandleValueNotification (uint16_t conn_id, uint16_t attr_hand * Returns GATT_SUCCESS if sucessfully sent; otherwise error code. * ******************************************************************************/ -tGATT_STATUS GATTS_SendRsp (uint16_t conn_id, uint32_t trans_id, - tGATT_STATUS status, tGATTS_RSP *p_msg) -{ - tGATT_STATUS cmd_sent = GATT_ILLEGAL_PARAMETER; - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - - GATT_TRACE_API ("GATTS_SendRsp: conn_id: %u trans_id: %u Status: 0x%04x", - conn_id, trans_id, status); - - if ( (p_reg == NULL) || (p_tcb == NULL)) - { - GATT_TRACE_ERROR ("GATTS_SendRsp Unknown conn_id: %u ", conn_id); - return(tGATT_STATUS) GATT_INVALID_CONN_ID; - } - - if (p_tcb->sr_cmd.trans_id != trans_id) - { - GATT_TRACE_ERROR ("GATTS_SendRsp conn_id: %u waiting for op_code = %02x", - conn_id, p_tcb->sr_cmd.op_code); - - return(GATT_WRONG_STATE); - } - /* Process App response */ - cmd_sent = gatt_sr_process_app_rsp (p_tcb, gatt_if, trans_id, p_tcb->sr_cmd.op_code, status, p_msg); - - return cmd_sent; +tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, + tGATT_STATUS status, tGATTS_RSP* p_msg) { + tGATT_STATUS cmd_sent = GATT_ILLEGAL_PARAMETER; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + + GATT_TRACE_API("GATTS_SendRsp: conn_id: %u trans_id: %u Status: 0x%04x", + conn_id, trans_id, status); + + if ((p_reg == NULL) || (p_tcb == NULL)) { + GATT_TRACE_ERROR("GATTS_SendRsp Unknown conn_id: %u ", conn_id); + return (tGATT_STATUS)GATT_INVALID_CONN_ID; + } + + if (p_tcb->sr_cmd.trans_id != trans_id) { + GATT_TRACE_ERROR("GATTS_SendRsp conn_id: %u waiting for op_code = %02x", + conn_id, p_tcb->sr_cmd.op_code); + + return (GATT_WRONG_STATE); + } + /* Process App response */ + cmd_sent = gatt_sr_process_app_rsp(p_tcb, gatt_if, trans_id, + p_tcb->sr_cmd.op_code, status, p_msg); + + return cmd_sent; } /******************************************************************************/ @@ -635,7 +605,6 @@ tGATT_STATUS GATTS_SendRsp (uint16_t conn_id, uint32_t trans_id, /* */ /******************************************************************************/ - /******************************************************************************* * * Function GATTC_ConfigureMTU @@ -648,45 +617,42 @@ tGATT_STATUS GATTS_SendRsp (uint16_t conn_id, uint32_t trans_id, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_ConfigureMTU (uint16_t conn_id, uint16_t mtu) -{ - uint8_t ret = GATT_NO_RESOURCES; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - tGATT_CLCB *p_clcb; - - GATT_TRACE_API ("GATTC_ConfigureMTU conn_id=%d mtu=%d", conn_id, mtu ); - - if ( (p_tcb == NULL) || (p_reg == NULL) || (mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)) - { - return GATT_ILLEGAL_PARAMETER; - } - - /* Validate that the link is BLE, not BR/EDR */ - if (p_tcb->transport != BT_TRANSPORT_LE) - { - return GATT_ERROR; - } - - if (gatt_is_clcb_allocated(conn_id)) - { - GATT_TRACE_ERROR("GATTC_ConfigureMTU GATT_BUSY conn_id = %d", conn_id); - return GATT_BUSY; - } - - p_clcb = gatt_clcb_alloc(conn_id); - if (p_clcb != NULL) - { - p_clcb->p_tcb->payload_size = mtu; - p_clcb->operation = GATTC_OPTYPE_CONFIG; - - ret = attp_send_cl_msg (p_clcb->p_tcb, p_clcb->clcb_idx, GATT_REQ_MTU, (tGATT_CL_MSG *)&mtu); - } - - return ret; +tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) { + uint8_t ret = GATT_NO_RESOURCES; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + tGATT_CLCB* p_clcb; + + GATT_TRACE_API("GATTC_ConfigureMTU conn_id=%d mtu=%d", conn_id, mtu); + + if ((p_tcb == NULL) || (p_reg == NULL) || (mtu < GATT_DEF_BLE_MTU_SIZE) || + (mtu > GATT_MAX_MTU_SIZE)) { + return GATT_ILLEGAL_PARAMETER; + } + + /* Validate that the link is BLE, not BR/EDR */ + if (p_tcb->transport != BT_TRANSPORT_LE) { + return GATT_ERROR; + } + + if (gatt_is_clcb_allocated(conn_id)) { + GATT_TRACE_ERROR("GATTC_ConfigureMTU GATT_BUSY conn_id = %d", conn_id); + return GATT_BUSY; + } + + p_clcb = gatt_clcb_alloc(conn_id); + if (p_clcb != NULL) { + p_clcb->p_tcb->payload_size = mtu; + p_clcb->operation = GATTC_OPTYPE_CONFIG; + + ret = attp_send_cl_msg(p_clcb->p_tcb, p_clcb->clcb_idx, GATT_REQ_MTU, + (tGATT_CL_MSG*)&mtu); + } + + return ret; } /******************************************************************************* @@ -703,60 +669,50 @@ tGATT_STATUS GATTC_ConfigureMTU (uint16_t conn_id, uint16_t mtu) * Returns GATT_SUCCESS if command received/sent successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Discover (uint16_t conn_id, tGATT_DISC_TYPE disc_type, - tGATT_DISC_PARAM *p_param) -{ - tGATT_STATUS status = GATT_SUCCESS; - tGATT_CLCB *p_clcb; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - - GATT_TRACE_API ("GATTC_Discover conn_id=%d disc_type=%d",conn_id, disc_type); - - if ( (p_tcb == NULL) || (p_reg==NULL) ||(p_param == NULL) || - (disc_type >= GATT_DISC_MAX)) - { - GATT_TRACE_ERROR("GATTC_Discover Illegal param: disc_type %d conn_id = %d", disc_type, conn_id); - return GATT_ILLEGAL_PARAMETER; +tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_PARAM* p_param) { + tGATT_STATUS status = GATT_SUCCESS; + tGATT_CLCB* p_clcb; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + GATT_TRACE_API("GATTC_Discover conn_id=%d disc_type=%d", conn_id, disc_type); + + if ((p_tcb == NULL) || (p_reg == NULL) || (p_param == NULL) || + (disc_type >= GATT_DISC_MAX)) { + GATT_TRACE_ERROR("GATTC_Discover Illegal param: disc_type %d conn_id = %d", + disc_type, conn_id); + return GATT_ILLEGAL_PARAMETER; + } + + if (gatt_is_clcb_allocated(conn_id)) { + GATT_TRACE_ERROR("GATTC_Discover GATT_BUSY conn_id = %d", conn_id); + return GATT_BUSY; + } + + p_clcb = gatt_clcb_alloc(conn_id); + if (p_clcb != NULL) { + if (!GATT_HANDLE_IS_VALID(p_param->s_handle) || + !GATT_HANDLE_IS_VALID(p_param->e_handle) || + /* search by type does not have a valid UUID param */ + (disc_type == GATT_DISC_SRVC_BY_UUID && p_param->service.len == 0)) { + gatt_clcb_dealloc(p_clcb); + return GATT_ILLEGAL_PARAMETER; } - - if (gatt_is_clcb_allocated(conn_id)) - { - GATT_TRACE_ERROR("GATTC_Discover GATT_BUSY conn_id = %d", conn_id); - return GATT_BUSY; - } - - - p_clcb = gatt_clcb_alloc(conn_id); - if (p_clcb != NULL) - { - if (!GATT_HANDLE_IS_VALID(p_param->s_handle) || - !GATT_HANDLE_IS_VALID(p_param->e_handle) || - /* search by type does not have a valid UUID param */ - (disc_type == GATT_DISC_SRVC_BY_UUID && - p_param->service.len == 0)) - { - gatt_clcb_dealloc(p_clcb); - return GATT_ILLEGAL_PARAMETER; - } - - p_clcb->operation = GATTC_OPTYPE_DISCOVERY; - p_clcb->op_subtype = disc_type; - p_clcb->s_handle = p_param->s_handle; - p_clcb->e_handle = p_param->e_handle; - p_clcb->uuid = p_param->service; - - gatt_act_discovery(p_clcb); - } - else - { - status = GATT_NO_RESOURCES; - } - return status; + p_clcb->operation = GATTC_OPTYPE_DISCOVERY; + p_clcb->op_subtype = disc_type; + p_clcb->s_handle = p_param->s_handle; + p_clcb->e_handle = p_param->e_handle; + p_clcb->uuid = p_param->service; + + gatt_act_discovery(p_clcb); + } else { + status = GATT_NO_RESOURCES; + } + return status; } /******************************************************************************* @@ -773,82 +729,74 @@ tGATT_STATUS GATTC_Discover (uint16_t conn_id, tGATT_DISC_TYPE disc_type, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Read (uint16_t conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM *p_read) -{ - tGATT_STATUS status = GATT_SUCCESS; - tGATT_CLCB *p_clcb; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - - GATT_TRACE_API ("GATTC_Read conn_id=%d type=%d", conn_id, type); - - if ( (p_tcb == NULL) || (p_reg==NULL) || (p_read == NULL) || ((type >= GATT_READ_MAX) || (type == 0))) - { - GATT_TRACE_ERROR("GATT_Read Illegal param: conn_id %d, type 0%d,", conn_id, type); - return GATT_ILLEGAL_PARAMETER; - } - - if (gatt_is_clcb_allocated(conn_id)) - { - GATT_TRACE_ERROR("GATTC_Read GATT_BUSY conn_id = %d", conn_id); - return GATT_BUSY; - } - - p_clcb = gatt_clcb_alloc(conn_id); - if (p_clcb != NULL) - { - p_clcb->operation = GATTC_OPTYPE_READ; - p_clcb->op_subtype = type; - p_clcb->auth_req = p_read->by_handle.auth_req; - p_clcb->counter = 0; - - switch (type) - { - case GATT_READ_BY_TYPE: - case GATT_READ_CHAR_VALUE: - p_clcb->s_handle = p_read->service.s_handle; - p_clcb->e_handle = p_read->service.e_handle; - memcpy(&p_clcb->uuid, &p_read->service.uuid, sizeof(tBT_UUID)); - break; - case GATT_READ_MULTIPLE: - { - p_clcb->s_handle = 0; - /* copy multiple handles in CB */ - tGATT_READ_MULTI *p_read_multi = - (tGATT_READ_MULTI *)osi_malloc(sizeof(tGATT_READ_MULTI)); - p_clcb->p_attr_buf = (uint8_t*)p_read_multi; - memcpy(p_read_multi, &p_read->read_multiple, sizeof(tGATT_READ_MULTI)); - break; - } - case GATT_READ_BY_HANDLE: - case GATT_READ_PARTIAL: - memset(&p_clcb->uuid, 0, sizeof(tBT_UUID)); - p_clcb->s_handle = p_read->by_handle.handle; - - if (type == GATT_READ_PARTIAL) - { - p_clcb->counter = p_read->partial.offset; - } - - break; - default: - break; - } - /* start security check */ - if (gatt_security_check_start(p_clcb) == false) - { - status = GATT_NO_RESOURCES; - gatt_clcb_dealloc(p_clcb); +tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type, + tGATT_READ_PARAM* p_read) { + tGATT_STATUS status = GATT_SUCCESS; + tGATT_CLCB* p_clcb; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + GATT_TRACE_API("GATTC_Read conn_id=%d type=%d", conn_id, type); + + if ((p_tcb == NULL) || (p_reg == NULL) || (p_read == NULL) || + ((type >= GATT_READ_MAX) || (type == 0))) { + GATT_TRACE_ERROR("GATT_Read Illegal param: conn_id %d, type 0%d,", conn_id, + type); + return GATT_ILLEGAL_PARAMETER; + } + + if (gatt_is_clcb_allocated(conn_id)) { + GATT_TRACE_ERROR("GATTC_Read GATT_BUSY conn_id = %d", conn_id); + return GATT_BUSY; + } + + p_clcb = gatt_clcb_alloc(conn_id); + if (p_clcb != NULL) { + p_clcb->operation = GATTC_OPTYPE_READ; + p_clcb->op_subtype = type; + p_clcb->auth_req = p_read->by_handle.auth_req; + p_clcb->counter = 0; + + switch (type) { + case GATT_READ_BY_TYPE: + case GATT_READ_CHAR_VALUE: + p_clcb->s_handle = p_read->service.s_handle; + p_clcb->e_handle = p_read->service.e_handle; + memcpy(&p_clcb->uuid, &p_read->service.uuid, sizeof(tBT_UUID)); + break; + case GATT_READ_MULTIPLE: { + p_clcb->s_handle = 0; + /* copy multiple handles in CB */ + tGATT_READ_MULTI* p_read_multi = + (tGATT_READ_MULTI*)osi_malloc(sizeof(tGATT_READ_MULTI)); + p_clcb->p_attr_buf = (uint8_t*)p_read_multi; + memcpy(p_read_multi, &p_read->read_multiple, sizeof(tGATT_READ_MULTI)); + break; + } + case GATT_READ_BY_HANDLE: + case GATT_READ_PARTIAL: + memset(&p_clcb->uuid, 0, sizeof(tBT_UUID)); + p_clcb->s_handle = p_read->by_handle.handle; + + if (type == GATT_READ_PARTIAL) { + p_clcb->counter = p_read->partial.offset; } + + break; + default: + break; } - else - { - status = GATT_NO_RESOURCES; + /* start security check */ + if (gatt_security_check_start(p_clcb) == false) { + status = GATT_NO_RESOURCES; + gatt_clcb_dealloc(p_clcb); } - return status; + } else { + status = GATT_NO_RESOURCES; + } + return status; } /******************************************************************************* @@ -865,58 +813,55 @@ tGATT_STATUS GATTC_Read (uint16_t conn_id, tGATT_READ_TYPE type, tGATT_READ_PARA * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_Write (uint16_t conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE *p_write) -{ - tGATT_STATUS status = GATT_SUCCESS; - tGATT_CLCB *p_clcb; - tGATT_VALUE *p; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - if ( (p_tcb == NULL) || (p_reg==NULL) || (p_write == NULL) || - ((type != GATT_WRITE) && (type != GATT_WRITE_PREPARE) && (type != GATT_WRITE_NO_RSP)) ) - { - GATT_TRACE_ERROR("GATT_Write Illegal param: conn_id %d, type 0%d,", conn_id, type); - return GATT_ILLEGAL_PARAMETER; +tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type, + tGATT_VALUE* p_write) { + tGATT_STATUS status = GATT_SUCCESS; + tGATT_CLCB* p_clcb; + tGATT_VALUE* p; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + if ((p_tcb == NULL) || (p_reg == NULL) || (p_write == NULL) || + ((type != GATT_WRITE) && (type != GATT_WRITE_PREPARE) && + (type != GATT_WRITE_NO_RSP))) { + GATT_TRACE_ERROR("GATT_Write Illegal param: conn_id %d, type 0%d,", conn_id, + type); + return GATT_ILLEGAL_PARAMETER; + } + + if (gatt_is_clcb_allocated(conn_id)) { + GATT_TRACE_ERROR("GATTC_Write GATT_BUSY conn_id = %d", conn_id); + return GATT_BUSY; + } + + p_clcb = gatt_clcb_alloc(conn_id); + if (p_clcb != NULL) { + p_clcb->operation = GATTC_OPTYPE_WRITE; + p_clcb->op_subtype = type; + p_clcb->auth_req = p_write->auth_req; + + p_clcb->p_attr_buf = (uint8_t*)osi_malloc(sizeof(tGATT_VALUE)); + memcpy(p_clcb->p_attr_buf, (void*)p_write, sizeof(tGATT_VALUE)); + + p = (tGATT_VALUE*)p_clcb->p_attr_buf; + if (type == GATT_WRITE_PREPARE) { + p_clcb->start_offset = p_write->offset; + p->offset = 0; } - if (gatt_is_clcb_allocated(conn_id)) - { - GATT_TRACE_ERROR("GATTC_Write GATT_BUSY conn_id = %d", conn_id); - return GATT_BUSY; + if (gatt_security_check_start(p_clcb) == false) { + status = GATT_NO_RESOURCES; } - p_clcb = gatt_clcb_alloc(conn_id); - if (p_clcb != NULL) - { - p_clcb->operation = GATTC_OPTYPE_WRITE; - p_clcb->op_subtype = type; - p_clcb->auth_req = p_write->auth_req; - - p_clcb->p_attr_buf = (uint8_t *)osi_malloc(sizeof(tGATT_VALUE)); - memcpy(p_clcb->p_attr_buf, (void *)p_write, sizeof(tGATT_VALUE)); - - p = (tGATT_VALUE *)p_clcb->p_attr_buf; - if (type == GATT_WRITE_PREPARE) { - p_clcb->start_offset = p_write->offset; - p->offset = 0; - } - - if (gatt_security_check_start(p_clcb) == false) { - status = GATT_NO_RESOURCES; - } - - if (status == GATT_NO_RESOURCES) - gatt_clcb_dealloc(p_clcb); - } else { - status = GATT_NO_RESOURCES; - } - return status; + if (status == GATT_NO_RESOURCES) gatt_clcb_dealloc(p_clcb); + } else { + status = GATT_NO_RESOURCES; + } + return status; } - /******************************************************************************* * * Function GATTC_ExecuteWrite @@ -931,43 +876,38 @@ tGATT_STATUS GATTC_Write (uint16_t conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE * * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_ExecuteWrite (uint16_t conn_id, bool is_execute) -{ - tGATT_STATUS status = GATT_SUCCESS; - tGATT_CLCB *p_clcb; - tGATT_EXEC_FLAG flag; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - GATT_TRACE_API ("GATTC_ExecuteWrite conn_id=%d is_execute=%d", conn_id, is_execute); - - if ( (p_tcb == NULL) || (p_reg==NULL) ) - { - GATT_TRACE_ERROR("GATTC_ExecuteWrite Illegal param: conn_id %d", conn_id); - return GATT_ILLEGAL_PARAMETER; - } - - if (gatt_is_clcb_allocated(conn_id)) - { - GATT_TRACE_ERROR("GATTC_Write GATT_BUSY conn_id = %d", conn_id); - return GATT_BUSY; - } - - p_clcb = gatt_clcb_alloc(conn_id); - if (p_clcb != NULL) - { - p_clcb->operation = GATTC_OPTYPE_EXE_WRITE; - flag = is_execute ? GATT_PREP_WRITE_EXEC : GATT_PREP_WRITE_CANCEL; - gatt_send_queue_write_cancel (p_clcb->p_tcb, p_clcb, flag); - } - else - { - GATT_TRACE_ERROR("Unable to allocate client CB for conn_id %d ", conn_id); - status = GATT_NO_RESOURCES; - } - return status; +tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) { + tGATT_STATUS status = GATT_SUCCESS; + tGATT_CLCB* p_clcb; + tGATT_EXEC_FLAG flag; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + GATT_TRACE_API("GATTC_ExecuteWrite conn_id=%d is_execute=%d", conn_id, + is_execute); + + if ((p_tcb == NULL) || (p_reg == NULL)) { + GATT_TRACE_ERROR("GATTC_ExecuteWrite Illegal param: conn_id %d", conn_id); + return GATT_ILLEGAL_PARAMETER; + } + + if (gatt_is_clcb_allocated(conn_id)) { + GATT_TRACE_ERROR("GATTC_Write GATT_BUSY conn_id = %d", conn_id); + return GATT_BUSY; + } + + p_clcb = gatt_clcb_alloc(conn_id); + if (p_clcb != NULL) { + p_clcb->operation = GATTC_OPTYPE_EXE_WRITE; + flag = is_execute ? GATT_PREP_WRITE_EXEC : GATT_PREP_WRITE_CANCEL; + gatt_send_queue_write_cancel(p_clcb->p_tcb, p_clcb, flag); + } else { + GATT_TRACE_ERROR("Unable to allocate client CB for conn_id %d ", conn_id); + status = GATT_NO_RESOURCES; + } + return status; } /******************************************************************************* @@ -983,40 +923,38 @@ tGATT_STATUS GATTC_ExecuteWrite (uint16_t conn_id, bool is_execute) * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -tGATT_STATUS GATTC_SendHandleValueConfirm (uint16_t conn_id, uint16_t handle) -{ - tGATT_STATUS ret = GATT_ILLEGAL_PARAMETER; - tGATT_TCB *p_tcb=gatt_get_tcb_by_idx(GATT_GET_TCB_IDX(conn_id)); +tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t handle) { + tGATT_STATUS ret = GATT_ILLEGAL_PARAMETER; + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(GATT_GET_TCB_IDX(conn_id)); - GATT_TRACE_API ("GATTC_SendHandleValueConfirm conn_id=%d handle=0x%x", conn_id, handle); + GATT_TRACE_API("GATTC_SendHandleValueConfirm conn_id=%d handle=0x%x", conn_id, + handle); - if (p_tcb) - { - if (p_tcb->ind_count > 0 ) - { - alarm_cancel(p_tcb->ind_ack_timer); + if (p_tcb) { + if (p_tcb->ind_count > 0) { + alarm_cancel(p_tcb->ind_ack_timer); - GATT_TRACE_DEBUG ("notif_count=%d ", p_tcb->ind_count); - /* send confirmation now */ - ret = attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, (tGATT_CL_MSG *)&handle); + GATT_TRACE_DEBUG("notif_count=%d ", p_tcb->ind_count); + /* send confirmation now */ + ret = attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, + (tGATT_CL_MSG*)&handle); - p_tcb->ind_count = 0; + p_tcb->ind_count = 0; - } - else - { - GATT_TRACE_DEBUG ("GATTC_SendHandleValueConfirm - conn_id: %u - ignored not waiting for indicaiton ack", conn_id); - ret = GATT_SUCCESS; - } - } - else - { - GATT_TRACE_ERROR ("GATTC_SendHandleValueConfirm - Unknown conn_id: %u", conn_id); + } else { + GATT_TRACE_DEBUG( + "GATTC_SendHandleValueConfirm - conn_id: %u - ignored not waiting " + "for indicaiton ack", + conn_id); + ret = GATT_SUCCESS; } - return ret; + } else { + GATT_TRACE_ERROR("GATTC_SendHandleValueConfirm - Unknown conn_id: %u", + conn_id); + } + return ret; } - /******************************************************************************/ /* */ /* GATT APIs */ @@ -1035,33 +973,30 @@ tGATT_STATUS GATTC_SendHandleValueConfirm (uint16_t conn_id, uint16_t handle) * Returns void * ******************************************************************************/ -void GATT_SetIdleTimeout (BD_ADDR bd_addr, uint16_t idle_tout, tBT_TRANSPORT transport) -{ - tGATT_TCB *p_tcb; - bool status = false; - - p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); - if (p_tcb != NULL) - { - if (p_tcb->att_lcid == L2CAP_ATT_CID) - { - status = L2CA_SetFixedChannelTout (bd_addr, L2CAP_ATT_CID, idle_tout); - - if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) - L2CA_SetIdleTimeoutByBdAddr(p_tcb->peer_bda, - GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, BT_TRANSPORT_LE); - } - else - { - status = L2CA_SetIdleTimeout (p_tcb->att_lcid, idle_tout, false); - } +void GATT_SetIdleTimeout(BD_ADDR bd_addr, uint16_t idle_tout, + tBT_TRANSPORT transport) { + tGATT_TCB* p_tcb; + bool status = false; + + p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); + if (p_tcb != NULL) { + if (p_tcb->att_lcid == L2CAP_ATT_CID) { + status = L2CA_SetFixedChannelTout(bd_addr, L2CAP_ATT_CID, idle_tout); + + if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) + L2CA_SetIdleTimeoutByBdAddr(p_tcb->peer_bda, + GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, + BT_TRANSPORT_LE); + } else { + status = L2CA_SetIdleTimeout(p_tcb->att_lcid, idle_tout, false); } + } - GATT_TRACE_API ("GATT_SetIdleTimeout idle_tout=%d status=%d(1-OK 0-not performed)", - idle_tout, status); + GATT_TRACE_API( + "GATT_SetIdleTimeout idle_tout=%d status=%d(1-OK 0-not performed)", + idle_tout, status); } - /******************************************************************************* * * Function GATT_Register @@ -1076,47 +1011,44 @@ void GATT_SetIdleTimeout (BD_ADDR bd_addr, uint16_t idle_tout, tBT_TRANSPORT tra * with GATT * ******************************************************************************/ -tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info) -{ - tGATT_REG *p_reg; - uint8_t i_gatt_if=0; - tGATT_IF gatt_if=0; - - GATT_TRACE_API("%s", __func__); - gatt_dbg_display_uuid(*p_app_uuid128); - - for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; i_gatt_if++, p_reg++) - { - if (p_reg->in_use && !memcmp(p_app_uuid128->uu.uuid128, p_reg->app_uuid128.uu.uuid128, LEN_UUID_128)) - { - GATT_TRACE_ERROR("application already registered."); - return 0; - } +tGATT_IF GATT_Register(tBT_UUID* p_app_uuid128, tGATT_CBACK* p_cb_info) { + tGATT_REG* p_reg; + uint8_t i_gatt_if = 0; + tGATT_IF gatt_if = 0; + + GATT_TRACE_API("%s", __func__); + gatt_dbg_display_uuid(*p_app_uuid128); + + for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; + i_gatt_if++, p_reg++) { + if (p_reg->in_use && + !memcmp(p_app_uuid128->uu.uuid128, p_reg->app_uuid128.uu.uuid128, + LEN_UUID_128)) { + GATT_TRACE_ERROR("application already registered."); + return 0; } - - for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; i_gatt_if++, p_reg++) - { - if (!p_reg->in_use) - { - memset(p_reg, 0 , sizeof(tGATT_REG)); - i_gatt_if++; /* one based number */ - p_reg->app_uuid128 = *p_app_uuid128; - gatt_if = - p_reg->gatt_if = (tGATT_IF)i_gatt_if; - p_reg->app_cb = *p_cb_info; - p_reg->in_use = true; - - GATT_TRACE_API("%s: allocated gatt_if=%d", __func__, gatt_if); - return gatt_if; - } + } + + for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; + i_gatt_if++, p_reg++) { + if (!p_reg->in_use) { + memset(p_reg, 0, sizeof(tGATT_REG)); + i_gatt_if++; /* one based number */ + p_reg->app_uuid128 = *p_app_uuid128; + gatt_if = p_reg->gatt_if = (tGATT_IF)i_gatt_if; + p_reg->app_cb = *p_cb_info; + p_reg->in_use = true; + + GATT_TRACE_API("%s: allocated gatt_if=%d", __func__, gatt_if); + return gatt_if; } + } - GATT_TRACE_ERROR("%s: can't Register GATT client, MAX client %d reached!", - __func__, GATT_MAX_APPS); - return 0; + GATT_TRACE_ERROR("%s: can't Register GATT client, MAX client %d reached!", + __func__, GATT_MAX_APPS); + return 0; } - /******************************************************************************* * * Function GATT_Deregister @@ -1128,69 +1060,62 @@ tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info) * Returns None. * ******************************************************************************/ -void GATT_Deregister (tGATT_IF gatt_if) -{ - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tGATT_TCB *p_tcb; - tGATT_CLCB *p_clcb; - uint8_t i, ii, j; - tGATT_SR_REG *p_sreg; - - GATT_TRACE_API ("GATT_Deregister gatt_if=%d", gatt_if); - /* Index 0 is GAP and is never deregistered */ - if ( (gatt_if == 0) || (p_reg == NULL) ) - { - GATT_TRACE_ERROR ("GATT_Deregister with invalid gatt_if: %u", gatt_if); - return; +void GATT_Deregister(tGATT_IF gatt_if) { + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tGATT_TCB* p_tcb; + tGATT_CLCB* p_clcb; + uint8_t i, ii, j; + tGATT_SR_REG* p_sreg; + + GATT_TRACE_API("GATT_Deregister gatt_if=%d", gatt_if); + /* Index 0 is GAP and is never deregistered */ + if ((gatt_if == 0) || (p_reg == NULL)) { + GATT_TRACE_ERROR("GATT_Deregister with invalid gatt_if: %u", gatt_if); + return; + } + + /* stop all services */ + /* todo an applcaiton can not be deregistered if its services is also used by + other application + deregisteration need to bed performed in an orderly fashion + no check for now */ + + for (ii = 0, p_sreg = gatt_cb.sr_reg; ii < GATT_MAX_SR_PROFILES; + ii++, p_sreg++) { + if (p_sreg->in_use && (p_sreg->gatt_if == gatt_if)) { + GATTS_StopService(p_sreg->s_hdl); } + } - /* stop all services */ - /* todo an applcaiton can not be deregistered if its services is also used by other application - deregisteration need to bed performed in an orderly fashion - no check for now */ + /* free all services db buffers if owned by this application */ + gatt_free_srvc_db_buffer_app_id(&p_reg->app_uuid128); - for (ii = 0, p_sreg = gatt_cb.sr_reg; ii < GATT_MAX_SR_PROFILES; ii++, p_sreg++) - { - if (p_sreg->in_use && (p_sreg->gatt_if == gatt_if)) - { - GATTS_StopService(p_sreg->s_hdl); - } - } + /* When an application deregisters, check remove the link associated with the + * app */ - /* free all services db buffers if owned by this application */ - gatt_free_srvc_db_buffer_app_id(&p_reg->app_uuid128); - - /* When an application deregisters, check remove the link associated with the app */ - - for (i=0, p_tcb = gatt_cb.tcb; i < GATT_MAX_PHY_CHANNEL; i++, p_tcb++) - { - if (p_tcb->in_use) - { - if (gatt_get_ch_state(p_tcb) != GATT_CH_CLOSE) - { - gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); - } - - for (j = 0, p_clcb= &gatt_cb.clcb[j]; j < GATT_CL_MAX_LCB; j++, p_clcb++) - { - if (p_clcb->in_use && - (p_clcb->p_reg->gatt_if == gatt_if) && - (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx)) - { - alarm_cancel(p_clcb->gatt_rsp_timer_ent); - gatt_clcb_dealloc (p_clcb); - break; - } - } + for (i = 0, p_tcb = gatt_cb.tcb; i < GATT_MAX_PHY_CHANNEL; i++, p_tcb++) { + if (p_tcb->in_use) { + if (gatt_get_ch_state(p_tcb) != GATT_CH_CLOSE) { + gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); + } + + for (j = 0, p_clcb = &gatt_cb.clcb[j]; j < GATT_CL_MAX_LCB; + j++, p_clcb++) { + if (p_clcb->in_use && (p_clcb->p_reg->gatt_if == gatt_if) && + (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx)) { + alarm_cancel(p_clcb->gatt_rsp_timer_ent); + gatt_clcb_dealloc(p_clcb); + break; } + } } + } - gatt_deregister_bgdev_list(gatt_if); + gatt_deregister_bgdev_list(gatt_if); - memset (p_reg, 0, sizeof(tGATT_REG)); + memset(p_reg, 0, sizeof(tGATT_REG)); } - /******************************************************************************* * * Function GATT_StartIf @@ -1204,34 +1129,30 @@ void GATT_Deregister (tGATT_IF gatt_if) * Returns None. * ******************************************************************************/ -void GATT_StartIf (tGATT_IF gatt_if) -{ - tGATT_REG *p_reg; - tGATT_TCB *p_tcb; - BD_ADDR bda; - uint8_t start_idx, found_idx; - uint16_t conn_id; - tGATT_TRANSPORT transport ; - - GATT_TRACE_API ("GATT_StartIf gatt_if=%d", gatt_if); - p_reg = gatt_get_regcb(gatt_if); - if (p_reg != NULL) - { - start_idx = 0; - while (gatt_find_the_connected_bda(start_idx, bda, &found_idx, &transport)) - { - p_tcb = gatt_find_tcb_by_addr(bda, transport); - if (p_reg->app_cb.p_conn_cb && p_tcb) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); - (*p_reg->app_cb.p_conn_cb)(gatt_if, bda, conn_id, true, 0, transport); - } - start_idx = ++found_idx; - } +void GATT_StartIf(tGATT_IF gatt_if) { + tGATT_REG* p_reg; + tGATT_TCB* p_tcb; + BD_ADDR bda; + uint8_t start_idx, found_idx; + uint16_t conn_id; + tGATT_TRANSPORT transport; + + GATT_TRACE_API("GATT_StartIf gatt_if=%d", gatt_if); + p_reg = gatt_get_regcb(gatt_if); + if (p_reg != NULL) { + start_idx = 0; + while ( + gatt_find_the_connected_bda(start_idx, bda, &found_idx, &transport)) { + p_tcb = gatt_find_tcb_by_addr(bda, transport); + if (p_reg->app_cb.p_conn_cb && p_tcb) { + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); + (*p_reg->app_cb.p_conn_cb)(gatt_if, bda, conn_id, true, 0, transport); + } + start_idx = ++found_idx; } + } } - /******************************************************************************* * * Function GATT_Connect @@ -1248,36 +1169,31 @@ void GATT_StartIf (tGATT_IF gatt_if) * failure. * ******************************************************************************/ -bool GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct, - tBT_TRANSPORT transport, bool opportunistic) -{ - tGATT_REG *p_reg; - bool status = false; - - GATT_TRACE_API ("GATT_Connect gatt_if=%d", gatt_if); - - /* Make sure app is registered */ - p_reg = gatt_get_regcb(gatt_if); - if (p_reg == NULL) - { - GATT_TRACE_ERROR("GATT_Connect - gatt_if =%d is not registered", gatt_if); - return(false); +bool GATT_Connect(tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct, + tBT_TRANSPORT transport, bool opportunistic) { + tGATT_REG* p_reg; + bool status = false; + + GATT_TRACE_API("GATT_Connect gatt_if=%d", gatt_if); + + /* Make sure app is registered */ + p_reg = gatt_get_regcb(gatt_if); + if (p_reg == NULL) { + GATT_TRACE_ERROR("GATT_Connect - gatt_if =%d is not registered", gatt_if); + return (false); + } + + if (is_direct) + status = gatt_act_connect(p_reg, bd_addr, transport, opportunistic); + else { + if (transport == BT_TRANSPORT_LE) + status = gatt_update_auto_connect_dev(gatt_if, true, bd_addr); + else { + GATT_TRACE_ERROR("Unsupported transport for background connection"); } + } - if (is_direct) - status = gatt_act_connect (p_reg, bd_addr, transport, opportunistic); - else - { - if (transport == BT_TRANSPORT_LE) - status = gatt_update_auto_connect_dev(gatt_if,true, bd_addr); - else - { - GATT_TRACE_ERROR("Unsupported transport for background connection"); - } - } - - return status; - + return status; } /******************************************************************************* @@ -1295,70 +1211,57 @@ bool GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct, * Returns true if the connection started; false otherwise. * ******************************************************************************/ -bool GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct){ - tGATT_REG *p_reg; - tGATT_TCB *p_tcb; - bool status = true; - tGATT_IF temp_gatt_if; - uint8_t start_idx, found_idx; - - GATT_TRACE_API ("GATT_CancelConnect gatt_if=%d", gatt_if); - - if ((gatt_if != 0) && ((p_reg = gatt_get_regcb(gatt_if)) == NULL)) - { - GATT_TRACE_ERROR("GATT_CancelConnect - gatt_if =%d is not registered", gatt_if); - return(false); - } - - if (is_direct) - { - if (!gatt_if) - { - GATT_TRACE_DEBUG("GATT_CancelConnect - unconditional"); - start_idx = 0; - /* only LE connection can be cancelled */ - p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); - if (p_tcb && gatt_num_apps_hold_link(p_tcb)) - { - while (status && gatt_find_app_hold_link(p_tcb, start_idx, &found_idx, &temp_gatt_if)) - { - status = gatt_cancel_open(temp_gatt_if, bd_addr); - start_idx = ++found_idx; - } - } - else - { - GATT_TRACE_ERROR("GATT_CancelConnect - no app found"); - status = false; - } - } - else - { - status = gatt_cancel_open(gatt_if, bd_addr); +bool GATT_CancelConnect(tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct) { + tGATT_REG* p_reg; + tGATT_TCB* p_tcb; + bool status = true; + tGATT_IF temp_gatt_if; + uint8_t start_idx, found_idx; + + GATT_TRACE_API("GATT_CancelConnect gatt_if=%d", gatt_if); + + if ((gatt_if != 0) && ((p_reg = gatt_get_regcb(gatt_if)) == NULL)) { + GATT_TRACE_ERROR("GATT_CancelConnect - gatt_if =%d is not registered", + gatt_if); + return (false); + } + + if (is_direct) { + if (!gatt_if) { + GATT_TRACE_DEBUG("GATT_CancelConnect - unconditional"); + start_idx = 0; + /* only LE connection can be cancelled */ + p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); + if (p_tcb && gatt_num_apps_hold_link(p_tcb)) { + while (status && gatt_find_app_hold_link(p_tcb, start_idx, &found_idx, + &temp_gatt_if)) { + status = gatt_cancel_open(temp_gatt_if, bd_addr); + start_idx = ++found_idx; } + } else { + GATT_TRACE_ERROR("GATT_CancelConnect - no app found"); + status = false; + } + } else { + status = gatt_cancel_open(gatt_if, bd_addr); } - else - { - if (!gatt_if) - { - if (gatt_get_num_apps_for_bg_dev(bd_addr)) - { - while (gatt_find_app_for_bg_dev(bd_addr, &temp_gatt_if)) - gatt_remove_bg_dev_for_app(temp_gatt_if, bd_addr); - } - else - { - GATT_TRACE_ERROR("GATT_CancelConnect -no app associated with the bg device for unconditional removal"); - status = false; - } - } - else - { - status = gatt_remove_bg_dev_for_app(gatt_if, bd_addr); - } + } else { + if (!gatt_if) { + if (gatt_get_num_apps_for_bg_dev(bd_addr)) { + while (gatt_find_app_for_bg_dev(bd_addr, &temp_gatt_if)) + gatt_remove_bg_dev_for_app(temp_gatt_if, bd_addr); + } else { + GATT_TRACE_ERROR( + "GATT_CancelConnect -no app associated with the bg device for " + "unconditional removal"); + status = false; + } + } else { + status = gatt_remove_bg_dev_for_app(gatt_if, bd_addr); } + } - return status; + return status; } /******************************************************************************* @@ -1373,26 +1276,23 @@ bool GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct * Returns GATT_SUCCESS if disconnected. * ******************************************************************************/ -tGATT_STATUS GATT_Disconnect (uint16_t conn_id) -{ - tGATT_STATUS ret = GATT_ILLEGAL_PARAMETER; - tGATT_TCB *p_tcb=NULL; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); +tGATT_STATUS GATT_Disconnect(uint16_t conn_id) { + tGATT_STATUS ret = GATT_ILLEGAL_PARAMETER; + tGATT_TCB* p_tcb = NULL; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - GATT_TRACE_API ("GATT_Disconnect conn_id=%d ", conn_id); + GATT_TRACE_API("GATT_Disconnect conn_id=%d ", conn_id); - p_tcb = gatt_get_tcb_by_idx(tcb_idx); + p_tcb = gatt_get_tcb_by_idx(tcb_idx); - if (p_tcb) - { - gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); - ret = GATT_SUCCESS; - } - return ret; + if (p_tcb) { + gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); + ret = GATT_SUCCESS; + } + return ret; } - /******************************************************************************* * * Function GATT_GetConnectionInfor @@ -1407,29 +1307,25 @@ tGATT_STATUS GATT_Disconnect (uint16_t conn_id) * Returns true the ligical link information is found for conn_id * ******************************************************************************/ -bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF *p_gatt_if, BD_ADDR bd_addr, - tBT_TRANSPORT *p_transport) -{ - - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb= gatt_get_tcb_by_idx(tcb_idx); - bool status=false; - - GATT_TRACE_API ("GATT_GetConnectionInfor conn_id=%d", conn_id); - - if (p_tcb && p_reg ) - { - memcpy(bd_addr, p_tcb->peer_bda, BD_ADDR_LEN); - *p_gatt_if = gatt_if; - *p_transport = p_tcb->transport; - status = true; - } - return status; +bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, + BD_ADDR bd_addr, tBT_TRANSPORT* p_transport) { + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + bool status = false; + + GATT_TRACE_API("GATT_GetConnectionInfor conn_id=%d", conn_id); + + if (p_tcb && p_reg) { + memcpy(bd_addr, p_tcb->peer_bda, BD_ADDR_LEN); + *p_gatt_if = gatt_if; + *p_transport = p_tcb->transport; + status = true; + } + return status; } - /******************************************************************************* * * Function GATT_GetConnIdIfConnected @@ -1445,19 +1341,17 @@ bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF *p_gatt_if, BD_ADDR b * Returns true the logical link is connected * ******************************************************************************/ -bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, uint16_t *p_conn_id, - tBT_TRANSPORT transport) -{ - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - tGATT_TCB *p_tcb= gatt_find_tcb_by_addr(bd_addr, transport); - bool status=false; - - if (p_reg && p_tcb && (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) ) - { - *p_conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); - status = true; - } - - GATT_TRACE_API ("GATT_GetConnIdIfConnected status=%d", status); - return status; +bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, + uint16_t* p_conn_id, tBT_TRANSPORT transport) { + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); + bool status = false; + + if (p_reg && p_tcb && (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN)) { + *p_conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); + status = true; + } + + GATT_TRACE_API("GATT_GetConnIdIfConnected status=%d", status); + return status; } diff --git a/stack/gatt/gatt_attr.cc b/stack/gatt/gatt_attr.cc index e2439ea24..b6f42c97e 100644 --- a/stack/gatt/gatt_attr.cc +++ b/stack/gatt/gatt_attr.cc @@ -26,42 +26,46 @@ #include "bt_target.h" #include "bt_utils.h" +#include "btcore/include/uuid.h" #include "gatt_api.h" #include "gatt_int.h" -#include "btcore/include/uuid.h" #include "osi/include/osi.h" -#define GATTP_MAX_NUM_INC_SVR 0 -#define GATTP_MAX_CHAR_NUM 2 -#define GATTP_MAX_ATTR_NUM (GATTP_MAX_CHAR_NUM * 2 + GATTP_MAX_NUM_INC_SVR + 1) -#define GATTP_MAX_CHAR_VALUE_SIZE 50 +#define GATTP_MAX_NUM_INC_SVR 0 +#define GATTP_MAX_CHAR_NUM 2 +#define GATTP_MAX_ATTR_NUM (GATTP_MAX_CHAR_NUM * 2 + GATTP_MAX_NUM_INC_SVR + 1) +#define GATTP_MAX_CHAR_VALUE_SIZE 50 #ifndef GATTP_ATTR_DB_SIZE -#define GATTP_ATTR_DB_SIZE GATT_DB_MEM_SIZE(GATTP_MAX_NUM_INC_SVR, GATTP_MAX_CHAR_NUM, GATTP_MAX_CHAR_VALUE_SIZE) +#define GATTP_ATTR_DB_SIZE \ + GATT_DB_MEM_SIZE(GATTP_MAX_NUM_INC_SVR, GATTP_MAX_CHAR_NUM, \ + GATTP_MAX_CHAR_VALUE_SIZE) #endif -static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, uint8_t op_code, tGATTS_DATA *p_data); +static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, + uint8_t op_code, tGATTS_DATA* p_data); static void gatt_connect_cback(UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, - uint16_t conn_id, bool connected, - tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data); -static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); -static void gatt_cl_op_cmpl_cback(UNUSED_ATTR uint16_t conn_id, UNUSED_ATTR tGATTC_OPTYPE op, UNUSED_ATTR tGATT_STATUS status, - UNUSED_ATTR tGATT_CL_COMPLETE *p_data); - -static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb); - - -static tGATT_CBACK gatt_profile_cback = -{ - gatt_connect_cback, - gatt_cl_op_cmpl_cback, - gatt_disc_res_cback, - gatt_disc_cmpl_cback, - gatt_request_cback, - NULL, - NULL -} ; + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + tBT_TRANSPORT transport); +static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_RES* p_data); +static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_STATUS status); +static void gatt_cl_op_cmpl_cback(UNUSED_ATTR uint16_t conn_id, + UNUSED_ATTR tGATTC_OPTYPE op, + UNUSED_ATTR tGATT_STATUS status, + UNUSED_ATTR tGATT_CL_COMPLETE* p_data); + +static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB* p_clcb); + +static tGATT_CBACK gatt_profile_cback = {gatt_connect_cback, + gatt_cl_op_cmpl_cback, + gatt_disc_res_cback, + gatt_disc_cmpl_cback, + gatt_request_cback, + NULL, + NULL}; /******************************************************************************* * @@ -72,11 +76,11 @@ static tGATT_CBACK gatt_profile_cback = * Returns Connection ID * ******************************************************************************/ -uint16_t gatt_profile_find_conn_id_by_bd_addr(BD_ADDR remote_bda) -{ - uint16_t conn_id = GATT_INVALID_CONN_ID; - GATT_GetConnIdIfConnected (gatt_cb.gatt_if, remote_bda, &conn_id, BT_TRANSPORT_LE); - return conn_id; +uint16_t gatt_profile_find_conn_id_by_bd_addr(BD_ADDR remote_bda) { + uint16_t conn_id = GATT_INVALID_CONN_ID; + GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id, + BT_TRANSPORT_LE); + return conn_id; } /******************************************************************************* @@ -88,18 +92,16 @@ uint16_t gatt_profile_find_conn_id_by_bd_addr(BD_ADDR remote_bda) * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_conn_id(uint16_t conn_id) -{ - uint8_t i_clcb; - tGATT_PROFILE_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->conn_id == conn_id) - return p_clcb; - } +static tGATT_PROFILE_CLCB* gatt_profile_find_clcb_by_conn_id(uint16_t conn_id) { + uint8_t i_clcb; + tGATT_PROFILE_CLCB* p_clcb = NULL; - return NULL; + for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->conn_id == conn_id) return p_clcb; + } + + return NULL; } /******************************************************************************* @@ -111,19 +113,19 @@ static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_conn_id(uint16_t conn_id) * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_bd_addr(BD_ADDR bda, tBT_TRANSPORT transport) -{ - uint8_t i_clcb; - tGATT_PROFILE_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->transport == transport && - p_clcb->connected && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) - return p_clcb; - } - - return NULL; +static tGATT_PROFILE_CLCB* gatt_profile_find_clcb_by_bd_addr( + BD_ADDR bda, tBT_TRANSPORT transport) { + uint8_t i_clcb; + tGATT_PROFILE_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->transport == transport && p_clcb->connected && + !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) + return p_clcb; + } + + return NULL; } /******************************************************************************* @@ -137,27 +139,25 @@ static tGATT_PROFILE_CLCB *gatt_profile_find_clcb_by_bd_addr(BD_ADDR bda, tBT_TR * block. * ******************************************************************************/ -tGATT_PROFILE_CLCB *gatt_profile_clcb_alloc (uint16_t conn_id, BD_ADDR bda, tBT_TRANSPORT tranport) -{ - uint8_t i_clcb = 0; - tGATT_PROFILE_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; i_clcb++, p_clcb++) - { - if (!p_clcb->in_use) - { - p_clcb->in_use = true; - p_clcb->conn_id = conn_id; - p_clcb->connected = true; - p_clcb->transport = tranport; - memcpy (p_clcb->bda, bda, BD_ADDR_LEN); - break; - } +tGATT_PROFILE_CLCB* gatt_profile_clcb_alloc(uint16_t conn_id, BD_ADDR bda, + tBT_TRANSPORT tranport) { + uint8_t i_clcb = 0; + tGATT_PROFILE_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = gatt_cb.profile_clcb; i_clcb < GATT_MAX_APPS; + i_clcb++, p_clcb++) { + if (!p_clcb->in_use) { + p_clcb->in_use = true; + p_clcb->conn_id = conn_id; + p_clcb->connected = true; + p_clcb->transport = tranport; + memcpy(p_clcb->bda, bda, BD_ADDR_LEN); + break; } - if(i_clcb < GATT_MAX_APPS) - return p_clcb; + } + if (i_clcb < GATT_MAX_APPS) return p_clcb; - return NULL; + return NULL; } /******************************************************************************* @@ -170,9 +170,8 @@ tGATT_PROFILE_CLCB *gatt_profile_clcb_alloc (uint16_t conn_id, BD_ADDR bda, tBT_ * Returns void * ******************************************************************************/ -void gatt_profile_clcb_dealloc (tGATT_PROFILE_CLCB *p_clcb) -{ - memset(p_clcb, 0, sizeof(tGATT_PROFILE_CLCB)); +void gatt_profile_clcb_dealloc(tGATT_PROFILE_CLCB* p_clcb) { + memset(p_clcb, 0, sizeof(tGATT_PROFILE_CLCB)); } /******************************************************************************* @@ -184,46 +183,42 @@ void gatt_profile_clcb_dealloc (tGATT_PROFILE_CLCB *p_clcb) * Returns void. * ******************************************************************************/ -static void gatt_request_cback (uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, - tGATTS_DATA *p_data) -{ - uint8_t status = GATT_INVALID_PDU; - tGATTS_RSP rsp_msg ; - bool ignore = false; - - memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); - - switch (type) - { - case GATTS_REQ_TYPE_READ_CHARACTERISTIC: - case GATTS_REQ_TYPE_READ_DESCRIPTOR: - status = GATT_READ_NOT_PERMIT; - break; - - case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: - case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: - status = GATT_WRITE_NOT_PERMIT; - break; - - case GATTS_REQ_TYPE_WRITE_EXEC: - case GATT_CMD_WRITE: - ignore = true; - GATT_TRACE_EVENT("Ignore GATT_REQ_EXEC_WRITE/WRITE_CMD" ); - break; - - case GATTS_REQ_TYPE_MTU: - GATT_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); - ignore = true; - break; - - default: - GATT_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); - break; - } - - if (!ignore) - GATTS_SendRsp (conn_id, trans_id, status, &rsp_msg); - +static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { + uint8_t status = GATT_INVALID_PDU; + tGATTS_RSP rsp_msg; + bool ignore = false; + + memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); + + switch (type) { + case GATTS_REQ_TYPE_READ_CHARACTERISTIC: + case GATTS_REQ_TYPE_READ_DESCRIPTOR: + status = GATT_READ_NOT_PERMIT; + break; + + case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: + case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: + status = GATT_WRITE_NOT_PERMIT; + break; + + case GATTS_REQ_TYPE_WRITE_EXEC: + case GATT_CMD_WRITE: + ignore = true; + GATT_TRACE_EVENT("Ignore GATT_REQ_EXEC_WRITE/WRITE_CMD"); + break; + + case GATTS_REQ_TYPE_MTU: + GATT_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); + ignore = true; + break; + + default: + GATT_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); + break; + } + + if (!ignore) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg); } /******************************************************************************* @@ -235,32 +230,30 @@ static void gatt_request_cback (uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_ * Returns void * ******************************************************************************/ -static void gatt_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, - uint16_t conn_id, - bool connected, tGATT_DISCONN_REASON reason, - tBT_TRANSPORT transport) -{ - GATT_TRACE_EVENT ("%s: from %08x%04x connected:%d conn_id=%d reason = 0x%04x", __FUNCTION__, - (bda[0]<<24)+(bda[1]<<16)+(bda[2]<<8)+bda[3], - (bda[4]<<8)+bda[5], connected, conn_id, reason); - - tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_bd_addr(bda, transport); - if (p_clcb == NULL) - return; - - if (connected) - { - p_clcb->conn_id = conn_id; - p_clcb->connected = true; - - if (p_clcb->ccc_stage == GATT_SVC_CHANGED_CONNECTING) - { - p_clcb->ccc_stage ++; - gatt_cl_start_config_ccc(p_clcb); - } - } else { - gatt_profile_clcb_dealloc(p_clcb); +static void gatt_connect_cback(UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + tBT_TRANSPORT transport) { + GATT_TRACE_EVENT("%s: from %08x%04x connected:%d conn_id=%d reason = 0x%04x", + __FUNCTION__, + (bda[0] << 24) + (bda[1] << 16) + (bda[2] << 8) + bda[3], + (bda[4] << 8) + bda[5], connected, conn_id, reason); + + tGATT_PROFILE_CLCB* p_clcb = + gatt_profile_find_clcb_by_bd_addr(bda, transport); + if (p_clcb == NULL) return; + + if (connected) { + p_clcb->conn_id = conn_id; + p_clcb->connected = true; + + if (p_clcb->ccc_stage == GATT_SVC_CHANGED_CONNECTING) { + p_clcb->ccc_stage++; + gatt_cl_start_config_ccc(p_clcb); } + } else { + gatt_profile_clcb_dealloc(p_clcb); + } } /******************************************************************************* @@ -270,36 +263,37 @@ static void gatt_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, * Description Initializa the GATT profile attribute database. * ******************************************************************************/ -void gatt_profile_db_init (void) -{ - tBT_UUID app_uuid = {LEN_UUID_128, {0}}; - uint16_t service_handle = 0; +void gatt_profile_db_init(void) { + tBT_UUID app_uuid = {LEN_UUID_128, {0}}; + uint16_t service_handle = 0; - /* Fill our internal UUID with a fixed pattern 0x81 */ - memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128); + /* Fill our internal UUID with a fixed pattern 0x81 */ + memset(&app_uuid.uu.uuid128, 0x81, LEN_UUID_128); - /* Create a GATT profile service */ - gatt_cb.gatt_if = GATT_Register(&app_uuid, &gatt_profile_cback); - GATT_StartIf(gatt_cb.gatt_if); + /* Create a GATT profile service */ + gatt_cb.gatt_if = GATT_Register(&app_uuid, &gatt_profile_cback); + GATT_StartIf(gatt_cb.gatt_if); - bt_uuid_t service_uuid; - uuid_128_from_16(&service_uuid, UUID_SERVCLASS_GATT_SERVER); + bt_uuid_t service_uuid; + uuid_128_from_16(&service_uuid, UUID_SERVCLASS_GATT_SERVER); - bt_uuid_t char_uuid; - uuid_128_from_16(&char_uuid, GATT_UUID_GATT_SRV_CHGD); + bt_uuid_t char_uuid; + uuid_128_from_16(&char_uuid, GATT_UUID_GATT_SRV_CHGD); - btgatt_db_element_t service[] = { - {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = service_uuid}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid = char_uuid, - .properties = GATT_CHAR_PROP_BIT_INDICATE, .permissions = 0} - }; + btgatt_db_element_t service[] = { + {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = service_uuid}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = char_uuid, + .properties = GATT_CHAR_PROP_BIT_INDICATE, + .permissions = 0}}; - GATTS_AddService(gatt_cb.gatt_if, service, sizeof(service)/sizeof(btgatt_db_element_t)); + GATTS_AddService(gatt_cb.gatt_if, service, + sizeof(service) / sizeof(btgatt_db_element_t)); - service_handle = service[0].attribute_handle; - gatt_cb.handle_of_h_r = service[1].attribute_handle; + service_handle = service[0].attribute_handle; + gatt_cb.handle_of_h_r = service[1].attribute_handle; - GATT_TRACE_ERROR("gatt_profile_db_init: gatt_if=%d", gatt_cb.gatt_if); + GATT_TRACE_ERROR("gatt_profile_db_init: gatt_if=%d", gatt_cb.gatt_if); } /******************************************************************************* @@ -311,33 +305,30 @@ void gatt_profile_db_init (void) * Returns void * ******************************************************************************/ -static void gatt_disc_res_cback (uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data) -{ - tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); +static void gatt_disc_res_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_RES* p_data) { + tGATT_PROFILE_CLCB* p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); - if (p_clcb == NULL) - return; + if (p_clcb == NULL) return; - switch (disc_type) - { - case GATT_DISC_SRVC_BY_UUID:/* stage 1 */ - p_clcb->e_handle = p_data->value.group_value.e_handle; - p_clcb->ccc_result ++; - break; + switch (disc_type) { + case GATT_DISC_SRVC_BY_UUID: /* stage 1 */ + p_clcb->e_handle = p_data->value.group_value.e_handle; + p_clcb->ccc_result++; + break; - case GATT_DISC_CHAR:/* stage 2 */ - p_clcb->s_handle = p_data->value.dclr_value.val_handle; - p_clcb->ccc_result ++; - break; + case GATT_DISC_CHAR: /* stage 2 */ + p_clcb->s_handle = p_data->value.dclr_value.val_handle; + p_clcb->ccc_result++; + break; case GATT_DISC_CHAR_DSCPT: /* stage 3 */ - if (p_data->type.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) - { - p_clcb->s_handle = p_data->handle; - p_clcb->ccc_result ++; - } - break; - } + if (p_data->type.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) { + p_clcb->s_handle = p_data->handle; + p_clcb->ccc_result++; + } + break; + } } /******************************************************************************* @@ -349,21 +340,20 @@ static void gatt_disc_res_cback (uint16_t conn_id, tGATT_DISC_TYPE disc_type, tG * Returns void * ******************************************************************************/ -static void gatt_disc_cmpl_cback (uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status) -{ - tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); - - if (p_clcb == NULL) - return; - - if (status == GATT_SUCCESS && p_clcb->ccc_result > 0) - { - p_clcb->ccc_result = 0; - p_clcb->ccc_stage ++; - gatt_cl_start_config_ccc(p_clcb); - } else { - GATT_TRACE_ERROR("%s() - Unable to register for service changed indication", __func__); - } +static void gatt_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_STATUS status) { + tGATT_PROFILE_CLCB* p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id); + + if (p_clcb == NULL) return; + + if (status == GATT_SUCCESS && p_clcb->ccc_result > 0) { + p_clcb->ccc_result = 0; + p_clcb->ccc_stage++; + gatt_cl_start_config_ccc(p_clcb); + } else { + GATT_TRACE_ERROR("%s() - Unable to register for service changed indication", + __func__); + } } /******************************************************************************* @@ -375,11 +365,10 @@ static void gatt_disc_cmpl_cback (uint16_t conn_id, tGATT_DISC_TYPE disc_type, t * Returns void * ******************************************************************************/ -static void gatt_cl_op_cmpl_cback (UNUSED_ATTR uint16_t conn_id, UNUSED_ATTR tGATTC_OPTYPE op, - UNUSED_ATTR tGATT_STATUS status, - UNUSED_ATTR tGATT_CL_COMPLETE *p_data) -{ -} +static void gatt_cl_op_cmpl_cback(UNUSED_ATTR uint16_t conn_id, + UNUSED_ATTR tGATTC_OPTYPE op, + UNUSED_ATTR tGATT_STATUS status, + UNUSED_ATTR tGATT_CL_COMPLETE* p_data) {} /******************************************************************************* * @@ -390,47 +379,45 @@ static void gatt_cl_op_cmpl_cback (UNUSED_ATTR uint16_t conn_id, UNUSED_ATTR tGA * Returns void * ******************************************************************************/ -static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb) -{ - tGATT_DISC_PARAM srvc_disc_param; - tGATT_VALUE ccc_value; +static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB* p_clcb) { + tGATT_DISC_PARAM srvc_disc_param; + tGATT_VALUE ccc_value; - GATT_TRACE_DEBUG("%s() - stage: %d", __func__, p_clcb->ccc_stage); + GATT_TRACE_DEBUG("%s() - stage: %d", __func__, p_clcb->ccc_stage); - memset (&srvc_disc_param, 0 , sizeof(tGATT_DISC_PARAM)); - memset (&ccc_value, 0 , sizeof(tGATT_VALUE)); + memset(&srvc_disc_param, 0, sizeof(tGATT_DISC_PARAM)); + memset(&ccc_value, 0, sizeof(tGATT_VALUE)); - switch(p_clcb->ccc_stage) - { + switch (p_clcb->ccc_stage) { case GATT_SVC_CHANGED_SERVICE: /* discover GATT service */ - srvc_disc_param.s_handle = 1; - srvc_disc_param.e_handle = 0xffff; - srvc_disc_param.service.len = 2; - srvc_disc_param.service.uu.uuid16 = UUID_SERVCLASS_GATT_SERVER; - GATTC_Discover(p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, &srvc_disc_param); - break; + srvc_disc_param.s_handle = 1; + srvc_disc_param.e_handle = 0xffff; + srvc_disc_param.service.len = 2; + srvc_disc_param.service.uu.uuid16 = UUID_SERVCLASS_GATT_SERVER; + GATTC_Discover(p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, &srvc_disc_param); + break; case GATT_SVC_CHANGED_CHARACTERISTIC: /* discover service change char */ - srvc_disc_param.s_handle = 1; - srvc_disc_param.e_handle = p_clcb->e_handle; - srvc_disc_param.service.len = 2; - srvc_disc_param.service.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD; - GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR, &srvc_disc_param); - break; + srvc_disc_param.s_handle = 1; + srvc_disc_param.e_handle = p_clcb->e_handle; + srvc_disc_param.service.len = 2; + srvc_disc_param.service.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD; + GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR, &srvc_disc_param); + break; case GATT_SVC_CHANGED_DESCRIPTOR: /* discover service change ccc */ - srvc_disc_param.s_handle = p_clcb->s_handle; - srvc_disc_param.e_handle = p_clcb->e_handle; - GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR_DSCPT, &srvc_disc_param); - break; + srvc_disc_param.s_handle = p_clcb->s_handle; + srvc_disc_param.e_handle = p_clcb->e_handle; + GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR_DSCPT, &srvc_disc_param); + break; case GATT_SVC_CHANGED_CONFIGURE_CCCD: /* write ccc */ - ccc_value.handle = p_clcb->s_handle; - ccc_value.len = 2; - ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION; - GATTC_Write(p_clcb->conn_id, GATT_WRITE, &ccc_value); - break; - } + ccc_value.handle = p_clcb->s_handle; + ccc_value.len = 2; + ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION; + GATTC_Write(p_clcb->conn_id, GATT_WRITE, &ccc_value); + break; + } } /******************************************************************************* @@ -442,30 +429,29 @@ static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB *p_clcb) * Returns none * ******************************************************************************/ -void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, bool enable, tBT_TRANSPORT transport) -{ - tGATT_PROFILE_CLCB *p_clcb = gatt_profile_find_clcb_by_bd_addr (remote_bda, transport); - - if (p_clcb == NULL) - p_clcb = gatt_profile_clcb_alloc (0, remote_bda, transport); - - if (p_clcb == NULL) - return; - - if (GATT_GetConnIdIfConnected (gatt_cb.gatt_if, remote_bda, &p_clcb->conn_id, transport)) - { - p_clcb->connected = true; - } - /* hold the link here */ - GATT_Connect(gatt_cb.gatt_if, remote_bda, true, transport, true); - p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING; - - if (!p_clcb->connected) - { - /* wait for connection */ - return; - } - - p_clcb->ccc_stage ++; - gatt_cl_start_config_ccc(p_clcb); +void GATT_ConfigServiceChangeCCC(BD_ADDR remote_bda, bool enable, + tBT_TRANSPORT transport) { + tGATT_PROFILE_CLCB* p_clcb = + gatt_profile_find_clcb_by_bd_addr(remote_bda, transport); + + if (p_clcb == NULL) + p_clcb = gatt_profile_clcb_alloc(0, remote_bda, transport); + + if (p_clcb == NULL) return; + + if (GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &p_clcb->conn_id, + transport)) { + p_clcb->connected = true; + } + /* hold the link here */ + GATT_Connect(gatt_cb.gatt_if, remote_bda, true, transport, true); + p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING; + + if (!p_clcb->connected) { + /* wait for connection */ + return; + } + + p_clcb->ccc_stage++; + gatt_cl_start_config_ccc(p_clcb); } diff --git a/stack/gatt/gatt_auth.cc b/stack/gatt/gatt_auth.cc index 1d5029282..82b03a627 100644 --- a/stack/gatt/gatt_auth.cc +++ b/stack/gatt/gatt_auth.cc @@ -27,9 +27,9 @@ #include #include "bt_common.h" -#include "gatt_int.h" -#include "gatt_api.h" #include "btm_int.h" +#include "gatt_api.h" +#include "gatt_int.h" #include "osi/include/osi.h" /******************************************************************************* @@ -41,43 +41,44 @@ * Returns true if encrypted, otherwise false. * ******************************************************************************/ -static bool gatt_sign_data (tGATT_CLCB *p_clcb) -{ - tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf; - uint8_t *p_data = NULL, *p; - uint16_t payload_size = p_clcb->p_tcb->payload_size; - bool status = false; - uint8_t *p_signature; - - /* do not need to mark channel securoty activity for data signing */ - gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_OK); - - p_data = (uint8_t *)osi_malloc(p_attr->len + 3); /* 3 = 2 byte handle + opcode */ - - p = p_data; - UINT8_TO_STREAM(p, GATT_SIGN_CMD_WRITE); - UINT16_TO_STREAM(p, p_attr->handle); - ARRAY_TO_STREAM(p, p_attr->value, p_attr->len); - - /* sign data length should be attribulte value length plus 2B handle + 1B op code */ - if ((payload_size - GATT_AUTH_SIGN_LEN - 3) < p_attr->len) - p_attr->len = payload_size - GATT_AUTH_SIGN_LEN - 3; - - p_signature = p_attr->value + p_attr->len; - if (BTM_BleDataSignature(p_clcb->p_tcb->peer_bda, - p_data, - (uint16_t)(p_attr->len + 3), /* 3 = 2 byte handle + opcode */ - p_signature)) { - p_attr->len += BTM_BLE_AUTH_SIGN_LEN; - gatt_set_ch_state(p_clcb->p_tcb, GATT_CH_OPEN); - gatt_act_write(p_clcb, GATT_SEC_SIGN_DATA); - } else { - gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, NULL); - } - - osi_free(p_data); - - return status; +static bool gatt_sign_data(tGATT_CLCB* p_clcb) { + tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf; + uint8_t *p_data = NULL, *p; + uint16_t payload_size = p_clcb->p_tcb->payload_size; + bool status = false; + uint8_t* p_signature; + + /* do not need to mark channel securoty activity for data signing */ + gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_OK); + + p_data = + (uint8_t*)osi_malloc(p_attr->len + 3); /* 3 = 2 byte handle + opcode */ + + p = p_data; + UINT8_TO_STREAM(p, GATT_SIGN_CMD_WRITE); + UINT16_TO_STREAM(p, p_attr->handle); + ARRAY_TO_STREAM(p, p_attr->value, p_attr->len); + + /* sign data length should be attribulte value length plus 2B handle + 1B op + * code */ + if ((payload_size - GATT_AUTH_SIGN_LEN - 3) < p_attr->len) + p_attr->len = payload_size - GATT_AUTH_SIGN_LEN - 3; + + p_signature = p_attr->value + p_attr->len; + if (BTM_BleDataSignature( + p_clcb->p_tcb->peer_bda, p_data, + (uint16_t)(p_attr->len + 3), /* 3 = 2 byte handle + opcode */ + p_signature)) { + p_attr->len += BTM_BLE_AUTH_SIGN_LEN; + gatt_set_ch_state(p_clcb->p_tcb, GATT_CH_OPEN); + gatt_act_write(p_clcb, GATT_SEC_SIGN_DATA); + } else { + gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, NULL); + } + + osi_free(p_data); + + return status; } /******************************************************************************* @@ -90,34 +91,31 @@ static bool gatt_sign_data (tGATT_CLCB *p_clcb) * Returns * ******************************************************************************/ -void gatt_verify_signature(tGATT_TCB *p_tcb, BT_HDR *p_buf) -{ - uint16_t cmd_len; - uint8_t op_code; - uint8_t *p, *p_orig = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint32_t counter; - - if (p_buf->len < GATT_AUTH_SIGN_LEN + 4) { - GATT_TRACE_ERROR("%s: Data length %u less than expected %u", - __func__, p_buf->len, GATT_AUTH_SIGN_LEN + 4); - return; - } - cmd_len = p_buf->len - GATT_AUTH_SIGN_LEN + 4; - p = p_orig + cmd_len - 4; - STREAM_TO_UINT32(counter, p); - - if (BTM_BleVerifySignature(p_tcb->peer_bda, p_orig, cmd_len, counter, p)) - { - STREAM_TO_UINT8(op_code, p_orig); - gatt_server_handle_client_req (p_tcb, op_code, (uint16_t)(p_buf->len - 1), p_orig); - } - else - { - /* if this is a bad signature, assume from attacker, ignore it */ - GATT_TRACE_ERROR("Signature Verification Failed, data ignored"); - } - +void gatt_verify_signature(tGATT_TCB* p_tcb, BT_HDR* p_buf) { + uint16_t cmd_len; + uint8_t op_code; + uint8_t *p, *p_orig = (uint8_t *)(p_buf + 1) + p_buf->offset; + uint32_t counter; + + if (p_buf->len < GATT_AUTH_SIGN_LEN + 4) { + GATT_TRACE_ERROR("%s: Data length %u less than expected %u", __func__, + p_buf->len, GATT_AUTH_SIGN_LEN + 4); return; + } + cmd_len = p_buf->len - GATT_AUTH_SIGN_LEN + 4; + p = p_orig + cmd_len - 4; + STREAM_TO_UINT32(counter, p); + + if (BTM_BleVerifySignature(p_tcb->peer_bda, p_orig, cmd_len, counter, p)) { + STREAM_TO_UINT8(op_code, p_orig); + gatt_server_handle_client_req(p_tcb, op_code, (uint16_t)(p_buf->len - 1), + p_orig); + } else { + /* if this is a bad signature, assume from attacker, ignore it */ + GATT_TRACE_ERROR("Signature Verification Failed, data ignored"); + } + + return; } /******************************************************************************* * @@ -128,25 +126,20 @@ void gatt_verify_signature(tGATT_TCB *p_tcb, BT_HDR *p_buf) * Returns void. * ******************************************************************************/ -void gatt_sec_check_complete(bool sec_check_ok, tGATT_CLCB *p_clcb, uint8_t sec_act) -{ - if (p_clcb && p_clcb->p_tcb && - fixed_queue_is_empty(p_clcb->p_tcb->pending_enc_clcb)) { - gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_NONE); - } - - if (!sec_check_ok) - { - gatt_end_operation(p_clcb, GATT_AUTH_FAIL, NULL); - } - else if (p_clcb->operation == GATTC_OPTYPE_WRITE) - { - gatt_act_write(p_clcb, sec_act); - } - else if (p_clcb->operation == GATTC_OPTYPE_READ) - { - gatt_act_read(p_clcb, p_clcb->counter); - } +void gatt_sec_check_complete(bool sec_check_ok, tGATT_CLCB* p_clcb, + uint8_t sec_act) { + if (p_clcb && p_clcb->p_tcb && + fixed_queue_is_empty(p_clcb->p_tcb->pending_enc_clcb)) { + gatt_set_sec_act(p_clcb->p_tcb, GATT_SEC_NONE); + } + + if (!sec_check_ok) { + gatt_end_operation(p_clcb, GATT_AUTH_FAIL, NULL); + } else if (p_clcb->operation == GATTC_OPTYPE_WRITE) { + gatt_act_write(p_clcb, sec_act); + } else if (p_clcb->operation == GATTC_OPTYPE_READ) { + gatt_act_read(p_clcb, p_clcb->counter); + } } /******************************************************************************* * @@ -158,64 +151,50 @@ void gatt_sec_check_complete(bool sec_check_ok, tGATT_CLCB *p_clcb, uint8_t * ******************************************************************************/ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, - UNUSED_ATTR void *p_ref_data, tBTM_STATUS result) -{ - tGATT_TCB *p_tcb; - uint8_t sec_flag; - bool status = false; - - GATT_TRACE_DEBUG("gatt_enc_cmpl_cback"); - p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); - if (p_tcb != NULL) - { - if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) - return; - - tGATT_PENDING_ENC_CLCB *p_buf = - (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); - if (p_buf != NULL) - { - if (result == BTM_SUCCESS) - { - if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENCRYPT_MITM ) - { - BTM_GetSecurityFlagsByTransport(bd_addr, &sec_flag, transport); - - if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) - { - status = true; - } - } - else - { - status = true; - } - } - gatt_sec_check_complete(status, p_buf->p_clcb, p_tcb->sec_act); - osi_free(p_buf); - /* start all other pending operation in queue */ - for (size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); - count > 0; count--) - { - p_buf = (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); - if (p_buf != NULL) - { - gatt_security_check_start(p_buf->p_clcb); - osi_free(p_buf); - } - else - break; - } - } - else - { - GATT_TRACE_ERROR("Unknown operation encryption completed"); + UNUSED_ATTR void* p_ref_data, tBTM_STATUS result) { + tGATT_TCB* p_tcb; + uint8_t sec_flag; + bool status = false; + + GATT_TRACE_DEBUG("gatt_enc_cmpl_cback"); + p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); + if (p_tcb != NULL) { + if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) return; + + tGATT_PENDING_ENC_CLCB* p_buf = + (tGATT_PENDING_ENC_CLCB*)fixed_queue_try_dequeue( + p_tcb->pending_enc_clcb); + if (p_buf != NULL) { + if (result == BTM_SUCCESS) { + if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENCRYPT_MITM) { + BTM_GetSecurityFlagsByTransport(bd_addr, &sec_flag, transport); + + if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) { + status = true; + } + } else { + status = true; } + } + gatt_sec_check_complete(status, p_buf->p_clcb, p_tcb->sec_act); + osi_free(p_buf); + /* start all other pending operation in queue */ + for (size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); + count > 0; count--) { + p_buf = (tGATT_PENDING_ENC_CLCB*)fixed_queue_try_dequeue( + p_tcb->pending_enc_clcb); + if (p_buf != NULL) { + gatt_security_check_start(p_buf->p_clcb); + osi_free(p_buf); + } else + break; + } + } else { + GATT_TRACE_ERROR("Unknown operation encryption completed"); } - else - { - GATT_TRACE_ERROR("enc callback for unknown bd_addr"); - } + } else { + GATT_TRACE_ERROR("enc callback for unknown bd_addr"); + } } /******************************************************************************* @@ -228,46 +207,38 @@ void gatt_enc_cmpl_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, * Returns * ******************************************************************************/ -void gatt_notify_enc_cmpl(BD_ADDR bd_addr) -{ - tGATT_TCB *p_tcb; - uint8_t i = 0; - - p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); - if (p_tcb != NULL) - { - for (i = 0; i < GATT_MAX_APPS; i++) - { - if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) - { - (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr); - } - } - - if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) - { - gatt_set_sec_act(p_tcb, GATT_SEC_NONE); - - size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); - for (; count > 0; count--) - { - tGATT_PENDING_ENC_CLCB *p_buf = - (tGATT_PENDING_ENC_CLCB *)fixed_queue_try_dequeue(p_tcb->pending_enc_clcb); - if (p_buf != NULL) - { - gatt_security_check_start(p_buf->p_clcb); - osi_free(p_buf); - } - else - break; - } - } +void gatt_notify_enc_cmpl(BD_ADDR bd_addr) { + tGATT_TCB* p_tcb; + uint8_t i = 0; + + p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); + if (p_tcb != NULL) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) { + (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, + bd_addr); + } } - else - { - GATT_TRACE_DEBUG("notify GATT for encryption completion of unknown device"); + + if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) { + gatt_set_sec_act(p_tcb, GATT_SEC_NONE); + + size_t count = fixed_queue_length(p_tcb->pending_enc_clcb); + for (; count > 0; count--) { + tGATT_PENDING_ENC_CLCB* p_buf = + (tGATT_PENDING_ENC_CLCB*)fixed_queue_try_dequeue( + p_tcb->pending_enc_clcb); + if (p_buf != NULL) { + gatt_security_check_start(p_buf->p_clcb); + osi_free(p_buf); + } else + break; + } } - return; + } else { + GATT_TRACE_DEBUG("notify GATT for encryption completion of unknown device"); + } + return; } /******************************************************************************* * @@ -278,12 +249,10 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr) * Returns none * ******************************************************************************/ -void gatt_set_sec_act(tGATT_TCB *p_tcb, tGATT_SEC_ACTION sec_act) -{ - if (p_tcb) - { - p_tcb->sec_act = sec_act; - } +void gatt_set_sec_act(tGATT_TCB* p_tcb, tGATT_SEC_ACTION sec_act) { + if (p_tcb) { + p_tcb->sec_act = sec_act; + } } /******************************************************************************* * @@ -294,14 +263,12 @@ void gatt_set_sec_act(tGATT_TCB *p_tcb, tGATT_SEC_ACTION sec_act) * Returns none * ******************************************************************************/ -tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB *p_tcb) -{ - tGATT_SEC_ACTION sec_act = GATT_SEC_NONE; - if (p_tcb) - { - sec_act = p_tcb->sec_act; - } - return sec_act; +tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB* p_tcb) { + tGATT_SEC_ACTION sec_act = GATT_SEC_NONE; + if (p_tcb) { + sec_act = p_tcb->sec_act; + } + return sec_act; } /******************************************************************************* * @@ -313,100 +280,80 @@ tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB *p_tcb) * Returns tGATT_SEC_ACTION security action * ******************************************************************************/ -tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB *p_clcb ) -{ - tGATT_SEC_ACTION act = GATT_SEC_OK; - uint8_t sec_flag; - tGATT_TCB *p_tcb = p_clcb->p_tcb; - tGATT_AUTH_REQ auth_req = p_clcb->auth_req; - bool is_link_encrypted= false; - bool is_link_key_known=false; - bool is_key_mitm=false; - uint8_t key_type; - tBTM_BLE_SEC_REQ_ACT sec_act = BTM_LE_SEC_NONE; - - if (auth_req == GATT_AUTH_REQ_NONE ) - return act; - - BTM_GetSecurityFlagsByTransport(p_tcb->peer_bda, &sec_flag, p_clcb->p_tcb->transport); - - btm_ble_link_sec_check(p_tcb->peer_bda, auth_req, &sec_act); - - /* if a encryption is pending, need to wait */ - if (sec_act == BTM_BLE_SEC_REQ_ACT_DISCARD && - auth_req != GATT_AUTH_REQ_NONE) - return GATT_SEC_ENC_PENDING; - - if (sec_flag & (BTM_SEC_FLAG_ENCRYPTED| BTM_SEC_FLAG_LKEY_KNOWN)) - { - if (sec_flag & BTM_SEC_FLAG_ENCRYPTED) - is_link_encrypted = true; - - is_link_key_known = true; - - if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) - is_key_mitm = true; - } - - /* first check link key upgrade required or not */ - switch (auth_req) - { - case GATT_AUTH_REQ_MITM: - case GATT_AUTH_REQ_SIGNED_MITM: - if (!is_key_mitm) - act = GATT_SEC_ENCRYPT_MITM; - break; - - case GATT_AUTH_REQ_NO_MITM: - case GATT_AUTH_REQ_SIGNED_NO_MITM: - if (!is_link_key_known) - act = GATT_SEC_ENCRYPT_NO_MITM; - break; - default: - break; - } - - /* now check link needs to be encrypted or not if the link key upgrade is not required */ - if (act == GATT_SEC_OK) - { - if (p_tcb->transport == BT_TRANSPORT_LE && - (p_clcb->operation == GATTC_OPTYPE_WRITE) && - (p_clcb->op_subtype == GATT_WRITE_NO_RSP)) - { - /* this is a write command request - check data signing required or not */ - if (!is_link_encrypted) - { - btm_ble_get_enc_key_type(p_tcb->peer_bda, &key_type); - - if ( (key_type & BTM_LE_KEY_LCSRK) && - ((auth_req == GATT_AUTH_REQ_SIGNED_NO_MITM) || - (auth_req == GATT_AUTH_REQ_SIGNED_MITM))) - { - act = GATT_SEC_SIGN_DATA; - } - else - { - act = GATT_SEC_ENCRYPT; - } - } - } - else - { - if (!is_link_encrypted) - { - act = GATT_SEC_ENCRYPT; - } +tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB* p_clcb) { + tGATT_SEC_ACTION act = GATT_SEC_OK; + uint8_t sec_flag; + tGATT_TCB* p_tcb = p_clcb->p_tcb; + tGATT_AUTH_REQ auth_req = p_clcb->auth_req; + bool is_link_encrypted = false; + bool is_link_key_known = false; + bool is_key_mitm = false; + uint8_t key_type; + tBTM_BLE_SEC_REQ_ACT sec_act = BTM_LE_SEC_NONE; + + if (auth_req == GATT_AUTH_REQ_NONE) return act; + + BTM_GetSecurityFlagsByTransport(p_tcb->peer_bda, &sec_flag, + p_clcb->p_tcb->transport); + + btm_ble_link_sec_check(p_tcb->peer_bda, auth_req, &sec_act); + + /* if a encryption is pending, need to wait */ + if (sec_act == BTM_BLE_SEC_REQ_ACT_DISCARD && auth_req != GATT_AUTH_REQ_NONE) + return GATT_SEC_ENC_PENDING; + + if (sec_flag & (BTM_SEC_FLAG_ENCRYPTED | BTM_SEC_FLAG_LKEY_KNOWN)) { + if (sec_flag & BTM_SEC_FLAG_ENCRYPTED) is_link_encrypted = true; + + is_link_key_known = true; + + if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) is_key_mitm = true; + } + + /* first check link key upgrade required or not */ + switch (auth_req) { + case GATT_AUTH_REQ_MITM: + case GATT_AUTH_REQ_SIGNED_MITM: + if (!is_key_mitm) act = GATT_SEC_ENCRYPT_MITM; + break; + + case GATT_AUTH_REQ_NO_MITM: + case GATT_AUTH_REQ_SIGNED_NO_MITM: + if (!is_link_key_known) act = GATT_SEC_ENCRYPT_NO_MITM; + break; + default: + break; + } + + /* now check link needs to be encrypted or not if the link key upgrade is not + * required */ + if (act == GATT_SEC_OK) { + if (p_tcb->transport == BT_TRANSPORT_LE && + (p_clcb->operation == GATTC_OPTYPE_WRITE) && + (p_clcb->op_subtype == GATT_WRITE_NO_RSP)) { + /* this is a write command request + check data signing required or not */ + if (!is_link_encrypted) { + btm_ble_get_enc_key_type(p_tcb->peer_bda, &key_type); + + if ((key_type & BTM_LE_KEY_LCSRK) && + ((auth_req == GATT_AUTH_REQ_SIGNED_NO_MITM) || + (auth_req == GATT_AUTH_REQ_SIGNED_MITM))) { + act = GATT_SEC_SIGN_DATA; + } else { + act = GATT_SEC_ENCRYPT; } - + } + } else { + if (!is_link_encrypted) { + act = GATT_SEC_ENCRYPT; + } } + } - return act ; - + return act; } - - /******************************************************************************* * * Function gatt_get_link_encrypt_status @@ -417,24 +364,22 @@ tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB *p_clcb ) * Returns tGATT_STATUS link encryption status * ******************************************************************************/ -tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB *p_tcb) -{ - tGATT_STATUS encrypt_status = GATT_NOT_ENCRYPTED; - uint8_t sec_flag=0; - - BTM_GetSecurityFlagsByTransport(p_tcb->peer_bda, &sec_flag, p_tcb->transport); - - if ((sec_flag & BTM_SEC_FLAG_ENCRYPTED) && (sec_flag & BTM_SEC_FLAG_LKEY_KNOWN)) - { - encrypt_status = GATT_ENCRYPED_NO_MITM; - if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) - encrypt_status = GATT_ENCRYPED_MITM; - } +tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB* p_tcb) { + tGATT_STATUS encrypt_status = GATT_NOT_ENCRYPTED; + uint8_t sec_flag = 0; - GATT_TRACE_DEBUG("gatt_get_link_encrypt_status status=0x%x",encrypt_status); - return encrypt_status ; -} + BTM_GetSecurityFlagsByTransport(p_tcb->peer_bda, &sec_flag, p_tcb->transport); + if ((sec_flag & BTM_SEC_FLAG_ENCRYPTED) && + (sec_flag & BTM_SEC_FLAG_LKEY_KNOWN)) { + encrypt_status = GATT_ENCRYPED_NO_MITM; + if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) + encrypt_status = GATT_ENCRYPED_MITM; + } + + GATT_TRACE_DEBUG("gatt_get_link_encrypt_status status=0x%x", encrypt_status); + return encrypt_status; +} /******************************************************************************* * @@ -446,26 +391,25 @@ tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB *p_tcb) * Returns bool true - conversation is successful * ******************************************************************************/ -static bool gatt_convert_sec_action(tGATT_SEC_ACTION gatt_sec_act, tBTM_BLE_SEC_ACT *p_btm_sec_act ) -{ - bool status = true; - switch (gatt_sec_act) - { - case GATT_SEC_ENCRYPT: - *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT; - break; - case GATT_SEC_ENCRYPT_NO_MITM: - *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT_NO_MITM; - break; - case GATT_SEC_ENCRYPT_MITM: - *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT_MITM; - break; - default: - status = false; - break; - } - - return status; +static bool gatt_convert_sec_action(tGATT_SEC_ACTION gatt_sec_act, + tBTM_BLE_SEC_ACT* p_btm_sec_act) { + bool status = true; + switch (gatt_sec_act) { + case GATT_SEC_ENCRYPT: + *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT; + break; + case GATT_SEC_ENCRYPT_NO_MITM: + *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT_NO_MITM; + break; + case GATT_SEC_ENCRYPT_MITM: + *p_btm_sec_act = BTM_BLE_SEC_ENCRYPT_MITM; + break; + default: + status = false; + break; + } + + return status; } /******************************************************************************* * @@ -476,58 +420,56 @@ static bool gatt_convert_sec_action(tGATT_SEC_ACTION gatt_sec_act, tBTM_BLE_S * Returns true if encrypted, otherwise false. * ******************************************************************************/ -bool gatt_security_check_start(tGATT_CLCB *p_clcb) -{ - tGATT_TCB *p_tcb = p_clcb->p_tcb; - tGATT_SEC_ACTION gatt_sec_act; - tBTM_BLE_SEC_ACT btm_ble_sec_act; - bool status = true; - tBTM_STATUS btm_status; - tGATT_SEC_ACTION sec_act_old = gatt_get_sec_act(p_tcb); - - gatt_sec_act = gatt_determine_sec_act(p_clcb); - - if (sec_act_old == GATT_SEC_NONE) - gatt_set_sec_act(p_tcb, gatt_sec_act); - - switch (gatt_sec_act ) - { - case GATT_SEC_SIGN_DATA: - GATT_TRACE_DEBUG("gatt_security_check_start: Do data signing"); - gatt_sign_data(p_clcb); - break; - case GATT_SEC_ENCRYPT: - case GATT_SEC_ENCRYPT_NO_MITM: - case GATT_SEC_ENCRYPT_MITM: - if (sec_act_old < GATT_SEC_ENCRYPT) - { - GATT_TRACE_DEBUG("gatt_security_check_start: Encrypt now or key upgreade first"); - gatt_convert_sec_action(gatt_sec_act, &btm_ble_sec_act); - btm_status = BTM_SetEncryption(p_tcb->peer_bda, p_tcb->transport, - gatt_enc_cmpl_cback, NULL, btm_ble_sec_act); - if ( (btm_status != BTM_SUCCESS) && (btm_status != BTM_CMD_STARTED)) - { - GATT_TRACE_ERROR("gatt_security_check_start BTM_SetEncryption failed btm_status=%d", btm_status); - status = false; - } - } - if (status) - gatt_add_pending_enc_channel_clcb (p_tcb, p_clcb); - break; - case GATT_SEC_ENC_PENDING: - gatt_add_pending_enc_channel_clcb (p_tcb, p_clcb); - /* wait for link encrypotion to finish */ - break; - default: - gatt_sec_check_complete(true, p_clcb, gatt_sec_act); - break; - } - - if (status == false) - { - gatt_set_sec_act(p_tcb, GATT_SEC_NONE); - gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - } - - return status; +bool gatt_security_check_start(tGATT_CLCB* p_clcb) { + tGATT_TCB* p_tcb = p_clcb->p_tcb; + tGATT_SEC_ACTION gatt_sec_act; + tBTM_BLE_SEC_ACT btm_ble_sec_act; + bool status = true; + tBTM_STATUS btm_status; + tGATT_SEC_ACTION sec_act_old = gatt_get_sec_act(p_tcb); + + gatt_sec_act = gatt_determine_sec_act(p_clcb); + + if (sec_act_old == GATT_SEC_NONE) gatt_set_sec_act(p_tcb, gatt_sec_act); + + switch (gatt_sec_act) { + case GATT_SEC_SIGN_DATA: + GATT_TRACE_DEBUG("gatt_security_check_start: Do data signing"); + gatt_sign_data(p_clcb); + break; + case GATT_SEC_ENCRYPT: + case GATT_SEC_ENCRYPT_NO_MITM: + case GATT_SEC_ENCRYPT_MITM: + if (sec_act_old < GATT_SEC_ENCRYPT) { + GATT_TRACE_DEBUG( + "gatt_security_check_start: Encrypt now or key upgreade first"); + gatt_convert_sec_action(gatt_sec_act, &btm_ble_sec_act); + btm_status = + BTM_SetEncryption(p_tcb->peer_bda, p_tcb->transport, + gatt_enc_cmpl_cback, NULL, btm_ble_sec_act); + if ((btm_status != BTM_SUCCESS) && (btm_status != BTM_CMD_STARTED)) { + GATT_TRACE_ERROR( + "gatt_security_check_start BTM_SetEncryption failed " + "btm_status=%d", + btm_status); + status = false; + } + } + if (status) gatt_add_pending_enc_channel_clcb(p_tcb, p_clcb); + break; + case GATT_SEC_ENC_PENDING: + gatt_add_pending_enc_channel_clcb(p_tcb, p_clcb); + /* wait for link encrypotion to finish */ + break; + default: + gatt_sec_check_complete(true, p_clcb, gatt_sec_act); + break; + } + + if (status == false) { + gatt_set_sec_act(p_tcb, GATT_SEC_NONE); + gatt_set_ch_state(p_tcb, GATT_CH_OPEN); + } + + return status; } diff --git a/stack/gatt/gatt_cl.cc b/stack/gatt/gatt_cl.cc index 6a5ef8855..a714c4acc 100644 --- a/stack/gatt/gatt_cl.cc +++ b/stack/gatt/gatt_cl.cc @@ -25,49 +25,46 @@ #include "bt_target.h" #include -#include "bt_utils.h" #include "bt_common.h" +#include "bt_utils.h" #include "gatt_int.h" #include "l2c_int.h" #include "osi/include/osi.h" -#define GATT_WRITE_LONG_HDR_SIZE 5 /* 1 opcode + 2 handle + 2 offset */ -#define GATT_READ_CHAR_VALUE_HDL (GATT_READ_CHAR_VALUE | 0x80) -#define GATT_READ_INC_SRV_UUID128 (GATT_DISC_INC_SRVC | 0x90) +#define GATT_WRITE_LONG_HDR_SIZE 5 /* 1 opcode + 2 handle + 2 offset */ +#define GATT_READ_CHAR_VALUE_HDL (GATT_READ_CHAR_VALUE | 0x80) +#define GATT_READ_INC_SRV_UUID128 (GATT_DISC_INC_SRVC | 0x90) #define GATT_PREP_WRITE_RSP_MIN_LEN 4 #define GATT_NOTIFICATION_MIN_LEN 2 -#define GATT_WRITE_RSP_MIN_LEN 2 -#define GATT_INFO_RSP_MIN_LEN 1 -#define GATT_MTU_RSP_MIN_LEN 2 -#define GATT_READ_BY_TYPE_RSP_MIN_LEN 1 +#define GATT_WRITE_RSP_MIN_LEN 2 +#define GATT_INFO_RSP_MIN_LEN 1 +#define GATT_MTU_RSP_MIN_LEN 2 +#define GATT_READ_BY_TYPE_RSP_MIN_LEN 1 /******************************************************************************* * G L O B A L G A T T D A T A * ******************************************************************************/ -void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb); +void gatt_send_prepare_write(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb); -uint8_t disc_type_to_att_opcode[GATT_DISC_MAX] = -{ +uint8_t disc_type_to_att_opcode[GATT_DISC_MAX] = { 0, - GATT_REQ_READ_BY_GRP_TYPE, /* GATT_DISC_SRVC_ALL = 1, */ - GATT_REQ_FIND_TYPE_VALUE, /* GATT_DISC_SRVC_BY_UUID, */ - GATT_REQ_READ_BY_TYPE, /* GATT_DISC_INC_SRVC, */ - GATT_REQ_READ_BY_TYPE, /* GATT_DISC_CHAR, */ - GATT_REQ_FIND_INFO /* GATT_DISC_CHAR_DSCPT, */ + GATT_REQ_READ_BY_GRP_TYPE, /* GATT_DISC_SRVC_ALL = 1, */ + GATT_REQ_FIND_TYPE_VALUE, /* GATT_DISC_SRVC_BY_UUID, */ + GATT_REQ_READ_BY_TYPE, /* GATT_DISC_INC_SRVC, */ + GATT_REQ_READ_BY_TYPE, /* GATT_DISC_CHAR, */ + GATT_REQ_FIND_INFO /* GATT_DISC_CHAR_DSCPT, */ }; -uint16_t disc_type_to_uuid[GATT_DISC_MAX] = -{ - 0, /* reserved */ - GATT_UUID_PRI_SERVICE, /* DISC_SRVC_ALL */ - GATT_UUID_PRI_SERVICE, /* for DISC_SERVC_BY_UUID */ +uint16_t disc_type_to_uuid[GATT_DISC_MAX] = { + 0, /* reserved */ + GATT_UUID_PRI_SERVICE, /* DISC_SRVC_ALL */ + GATT_UUID_PRI_SERVICE, /* for DISC_SERVC_BY_UUID */ GATT_UUID_INCLUDE_SERVICE, /* for DISC_INC_SRVC */ - GATT_UUID_CHAR_DECLARE, /* for DISC_CHAR */ - 0 /* no type filtering for DISC_CHAR_DSCPT */ + GATT_UUID_CHAR_DECLARE, /* for DISC_CHAR */ + 0 /* no type filtering for DISC_CHAR_DSCPT */ }; - /******************************************************************************* * * Function gatt_act_discovery @@ -77,51 +74,48 @@ uint16_t disc_type_to_uuid[GATT_DISC_MAX] = * Returns void. * ******************************************************************************/ -void gatt_act_discovery(tGATT_CLCB *p_clcb) -{ - uint8_t op_code = disc_type_to_att_opcode[p_clcb->op_subtype]; - tGATT_CL_MSG cl_req; - tGATT_STATUS st; +void gatt_act_discovery(tGATT_CLCB* p_clcb) { + uint8_t op_code = disc_type_to_att_opcode[p_clcb->op_subtype]; + tGATT_CL_MSG cl_req; + tGATT_STATUS st; - if (p_clcb->s_handle <= p_clcb->e_handle && p_clcb->s_handle != 0) - { - memset(&cl_req, 0, sizeof(tGATT_CL_MSG)); + if (p_clcb->s_handle <= p_clcb->e_handle && p_clcb->s_handle != 0) { + memset(&cl_req, 0, sizeof(tGATT_CL_MSG)); - cl_req.browse.s_handle = p_clcb->s_handle; - cl_req.browse.e_handle = p_clcb->e_handle; + cl_req.browse.s_handle = p_clcb->s_handle; + cl_req.browse.e_handle = p_clcb->e_handle; - if (disc_type_to_uuid[p_clcb->op_subtype] != 0) - { - cl_req.browse.uuid.len = 2; - cl_req.browse.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype]; - } + if (disc_type_to_uuid[p_clcb->op_subtype] != 0) { + cl_req.browse.uuid.len = 2; + cl_req.browse.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype]; + } - if (p_clcb->op_subtype == GATT_DISC_SRVC_BY_UUID) /* fill in the FindByTypeValue request info*/ - { - cl_req.find_type_value.uuid.len = 2; - cl_req.find_type_value.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype]; - cl_req.find_type_value.s_handle = p_clcb->s_handle; - cl_req.find_type_value.e_handle = p_clcb->e_handle; - cl_req.find_type_value.value_len = p_clcb->uuid.len; - /* if service type is 32 bits UUID, convert it now */ - if (p_clcb->uuid.len == LEN_UUID_32) - { - cl_req.find_type_value.value_len = LEN_UUID_128; - gatt_convert_uuid32_to_uuid128(cl_req.find_type_value.value, p_clcb->uuid.uu.uuid32); - } - else - memcpy (cl_req.find_type_value.value, &p_clcb->uuid.uu, p_clcb->uuid.len); - } + if (p_clcb->op_subtype == + GATT_DISC_SRVC_BY_UUID) /* fill in the FindByTypeValue request info*/ + { + cl_req.find_type_value.uuid.len = 2; + cl_req.find_type_value.uuid.uu.uuid16 = + disc_type_to_uuid[p_clcb->op_subtype]; + cl_req.find_type_value.s_handle = p_clcb->s_handle; + cl_req.find_type_value.e_handle = p_clcb->e_handle; + cl_req.find_type_value.value_len = p_clcb->uuid.len; + /* if service type is 32 bits UUID, convert it now */ + if (p_clcb->uuid.len == LEN_UUID_32) { + cl_req.find_type_value.value_len = LEN_UUID_128; + gatt_convert_uuid32_to_uuid128(cl_req.find_type_value.value, + p_clcb->uuid.uu.uuid32); + } else + memcpy(cl_req.find_type_value.value, &p_clcb->uuid.uu, + p_clcb->uuid.len); + } - st = attp_send_cl_msg(p_clcb->p_tcb, p_clcb->clcb_idx, op_code, &cl_req); + st = attp_send_cl_msg(p_clcb->p_tcb, p_clcb->clcb_idx, op_code, &cl_req); - if (st != GATT_SUCCESS && st != GATT_CMD_STARTED) - { - gatt_end_operation(p_clcb, GATT_ERROR, NULL); - } + if (st != GATT_SUCCESS && st != GATT_CMD_STARTED) { + gatt_end_operation(p_clcb, GATT_ERROR, NULL); } - else /* end of handle range */ - gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); + } else /* end of handle range */ + gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); } /******************************************************************************* @@ -133,83 +127,76 @@ void gatt_act_discovery(tGATT_CLCB *p_clcb) * Returns void. * ******************************************************************************/ -void gatt_act_read (tGATT_CLCB *p_clcb, uint16_t offset) -{ - tGATT_TCB *p_tcb = p_clcb->p_tcb; - uint8_t rt = GATT_INTERNAL_ERROR; - tGATT_CL_MSG msg; - uint8_t op_code = 0; - - memset (&msg, 0, sizeof(tGATT_CL_MSG)); - - switch (p_clcb->op_subtype) - { - case GATT_READ_CHAR_VALUE: - case GATT_READ_BY_TYPE: - op_code = GATT_REQ_READ_BY_TYPE; - msg.browse.s_handle = p_clcb->s_handle; - msg.browse.e_handle = p_clcb->e_handle; - if (p_clcb->op_subtype == GATT_READ_BY_TYPE) - memcpy(&msg.browse.uuid, &p_clcb->uuid, sizeof(tBT_UUID)); - else - { - msg.browse.uuid.len = LEN_UUID_16; - msg.browse.uuid.uu.uuid16 = GATT_UUID_CHAR_DECLARE; - } - break; - - case GATT_READ_CHAR_VALUE_HDL: - case GATT_READ_BY_HANDLE: - if (!p_clcb->counter) - { - op_code = GATT_REQ_READ; - msg.handle = p_clcb->s_handle; - } - else - { - if (!p_clcb->first_read_blob_after_read) - p_clcb->first_read_blob_after_read = true; - else - p_clcb->first_read_blob_after_read = false; - - GATT_TRACE_DEBUG("gatt_act_read first_read_blob_after_read=%d", - p_clcb->first_read_blob_after_read); - op_code = GATT_REQ_READ_BLOB; - msg.read_blob.offset = offset; - msg.read_blob.handle = p_clcb->s_handle; - } - p_clcb->op_subtype &= ~ 0x80; - break; - - case GATT_READ_PARTIAL: - op_code = GATT_REQ_READ_BLOB; - msg.read_blob.handle = p_clcb->s_handle; - msg.read_blob.offset = offset; - break; - - case GATT_READ_MULTIPLE: - op_code = GATT_REQ_READ_MULTI; - memcpy (&msg.read_multi, p_clcb->p_attr_buf, sizeof(tGATT_READ_MULTI)); - break; - - case GATT_READ_INC_SRV_UUID128: - op_code = GATT_REQ_READ; - msg.handle = p_clcb->s_handle; - p_clcb->op_subtype &= ~ 0x90; - break; - - default: - GATT_TRACE_ERROR("Unknown read type: %d", p_clcb->op_subtype); - break; - } - - if (op_code != 0) - rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, op_code, &msg); - - if ( op_code == 0 || (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED)) - { - gatt_end_operation(p_clcb, rt, NULL); - } +void gatt_act_read(tGATT_CLCB* p_clcb, uint16_t offset) { + tGATT_TCB* p_tcb = p_clcb->p_tcb; + uint8_t rt = GATT_INTERNAL_ERROR; + tGATT_CL_MSG msg; + uint8_t op_code = 0; + + memset(&msg, 0, sizeof(tGATT_CL_MSG)); + + switch (p_clcb->op_subtype) { + case GATT_READ_CHAR_VALUE: + case GATT_READ_BY_TYPE: + op_code = GATT_REQ_READ_BY_TYPE; + msg.browse.s_handle = p_clcb->s_handle; + msg.browse.e_handle = p_clcb->e_handle; + if (p_clcb->op_subtype == GATT_READ_BY_TYPE) + memcpy(&msg.browse.uuid, &p_clcb->uuid, sizeof(tBT_UUID)); + else { + msg.browse.uuid.len = LEN_UUID_16; + msg.browse.uuid.uu.uuid16 = GATT_UUID_CHAR_DECLARE; + } + break; + + case GATT_READ_CHAR_VALUE_HDL: + case GATT_READ_BY_HANDLE: + if (!p_clcb->counter) { + op_code = GATT_REQ_READ; + msg.handle = p_clcb->s_handle; + } else { + if (!p_clcb->first_read_blob_after_read) + p_clcb->first_read_blob_after_read = true; + else + p_clcb->first_read_blob_after_read = false; + + GATT_TRACE_DEBUG("gatt_act_read first_read_blob_after_read=%d", + p_clcb->first_read_blob_after_read); + op_code = GATT_REQ_READ_BLOB; + msg.read_blob.offset = offset; + msg.read_blob.handle = p_clcb->s_handle; + } + p_clcb->op_subtype &= ~0x80; + break; + + case GATT_READ_PARTIAL: + op_code = GATT_REQ_READ_BLOB; + msg.read_blob.handle = p_clcb->s_handle; + msg.read_blob.offset = offset; + break; + + case GATT_READ_MULTIPLE: + op_code = GATT_REQ_READ_MULTI; + memcpy(&msg.read_multi, p_clcb->p_attr_buf, sizeof(tGATT_READ_MULTI)); + break; + + case GATT_READ_INC_SRV_UUID128: + op_code = GATT_REQ_READ; + msg.handle = p_clcb->s_handle; + p_clcb->op_subtype &= ~0x90; + break; + + default: + GATT_TRACE_ERROR("Unknown read type: %d", p_clcb->op_subtype); + break; + } + + if (op_code != 0) + rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, op_code, &msg); + + if (op_code == 0 || (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED)) { + gatt_end_operation(p_clcb, rt, NULL); + } } /******************************************************************************* @@ -221,69 +208,54 @@ void gatt_act_read (tGATT_CLCB *p_clcb, uint16_t offset) * Returns void. * ******************************************************************************/ -void gatt_act_write (tGATT_CLCB *p_clcb, uint8_t sec_act) -{ - tGATT_TCB *p_tcb = p_clcb->p_tcb; - uint8_t rt = GATT_SUCCESS, op_code = 0; - tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf; - - if (p_attr) - { - switch (p_clcb->op_subtype) +void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act) { + tGATT_TCB* p_tcb = p_clcb->p_tcb; + uint8_t rt = GATT_SUCCESS, op_code = 0; + tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf; + + if (p_attr) { + switch (p_clcb->op_subtype) { + case GATT_WRITE_NO_RSP: + p_clcb->s_handle = p_attr->handle; + op_code = (sec_act == GATT_SEC_SIGN_DATA) ? GATT_SIGN_CMD_WRITE + : GATT_CMD_WRITE; + rt = gatt_send_write_msg(p_tcb, p_clcb->clcb_idx, op_code, + p_attr->handle, p_attr->len, 0, p_attr->value); + break; + + case GATT_WRITE: + if (p_attr->len <= (p_tcb->payload_size - GATT_HDR_SIZE)) { + p_clcb->s_handle = p_attr->handle; + + rt = gatt_send_write_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_WRITE, + p_attr->handle, p_attr->len, 0, + p_attr->value); + } else /* prepare write for long attribute */ { - case GATT_WRITE_NO_RSP: - p_clcb->s_handle = p_attr->handle; - op_code = (sec_act == GATT_SEC_SIGN_DATA) ? GATT_SIGN_CMD_WRITE : GATT_CMD_WRITE; - rt = gatt_send_write_msg(p_tcb, - p_clcb->clcb_idx, - op_code, - p_attr->handle, - p_attr->len, - 0, - p_attr->value); - break; - - case GATT_WRITE: - if (p_attr->len <= (p_tcb->payload_size - GATT_HDR_SIZE)) - { - p_clcb->s_handle = p_attr->handle; - - rt = gatt_send_write_msg(p_tcb, - p_clcb->clcb_idx, - GATT_REQ_WRITE, - p_attr->handle, - p_attr->len, - 0, - p_attr->value); - } - else /* prepare write for long attribute */ - { - gatt_send_prepare_write(p_tcb, p_clcb); - } - break; - - case GATT_WRITE_PREPARE: - gatt_send_prepare_write(p_tcb, p_clcb); - break; - - default: - rt = GATT_INTERNAL_ERROR; - GATT_TRACE_ERROR("Unknown write type: %d", p_clcb->op_subtype); - break; + gatt_send_prepare_write(p_tcb, p_clcb); } - } - else - rt = GATT_INTERNAL_ERROR; + break; - if ((rt != GATT_SUCCESS && rt != GATT_CMD_STARTED && rt != GATT_CONGESTED) - || (rt != GATT_CMD_STARTED && p_clcb->op_subtype == GATT_WRITE_NO_RSP)) - { - if (rt != GATT_SUCCESS) - { - GATT_TRACE_ERROR("gatt_act_write() failed op_code=0x%x rt=%d", op_code, rt); - } - gatt_end_operation(p_clcb, rt, NULL); + case GATT_WRITE_PREPARE: + gatt_send_prepare_write(p_tcb, p_clcb); + break; + + default: + rt = GATT_INTERNAL_ERROR; + GATT_TRACE_ERROR("Unknown write type: %d", p_clcb->op_subtype); + break; + } + } else + rt = GATT_INTERNAL_ERROR; + + if ((rt != GATT_SUCCESS && rt != GATT_CMD_STARTED && rt != GATT_CONGESTED) || + (rt != GATT_CMD_STARTED && p_clcb->op_subtype == GATT_WRITE_NO_RSP)) { + if (rt != GATT_SUCCESS) { + GATT_TRACE_ERROR("gatt_act_write() failed op_code=0x%x rt=%d", op_code, + rt); } + gatt_end_operation(p_clcb, rt, NULL); + } } /******************************************************************************* * @@ -294,18 +266,18 @@ void gatt_act_write (tGATT_CLCB *p_clcb, uint8_t sec_act) * Returns void. * ******************************************************************************/ -void gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_EXEC_FLAG flag) -{ - uint8_t rt ; +void gatt_send_queue_write_cancel(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + tGATT_EXEC_FLAG flag) { + uint8_t rt; - GATT_TRACE_DEBUG("gatt_send_queue_write_cancel "); + GATT_TRACE_DEBUG("gatt_send_queue_write_cancel "); - rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_EXEC_WRITE, (tGATT_CL_MSG *)&flag); + rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_EXEC_WRITE, + (tGATT_CL_MSG*)&flag); - if (rt != GATT_SUCCESS) - { - gatt_end_operation(p_clcb, rt, NULL); - } + if (rt != GATT_SUCCESS) { + gatt_end_operation(p_clcb, rt, NULL); + } } /******************************************************************************* * @@ -316,39 +288,35 @@ void gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_E * Returns true: write long is terminated; false keep sending. * ******************************************************************************/ -bool gatt_check_write_long_terminate(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_VALUE *p_rsp_value) -{ - tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf; - bool exec = false; - tGATT_EXEC_FLAG flag = GATT_PREP_WRITE_EXEC; - - GATT_TRACE_DEBUG("gatt_check_write_long_terminate "); - /* check the first write response status */ - if (p_rsp_value != NULL) - { - if (p_rsp_value->handle != p_attr->handle || - p_rsp_value->len != p_clcb->counter || - memcmp(p_rsp_value->value, p_attr->value + p_attr->offset, p_rsp_value->len)) - { - /* data does not match */ - p_clcb->status = GATT_ERROR; - flag = GATT_PREP_WRITE_CANCEL; - exec = true; - } - else /* response checking is good */ - { - p_clcb->status = GATT_SUCCESS; - /* update write offset and check if end of attribute value */ - if ((p_attr->offset += p_rsp_value->len) >= p_attr->len) - exec = true; - } - } - if (exec) +bool gatt_check_write_long_terminate(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + tGATT_VALUE* p_rsp_value) { + tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf; + bool exec = false; + tGATT_EXEC_FLAG flag = GATT_PREP_WRITE_EXEC; + + GATT_TRACE_DEBUG("gatt_check_write_long_terminate "); + /* check the first write response status */ + if (p_rsp_value != NULL) { + if (p_rsp_value->handle != p_attr->handle || + p_rsp_value->len != p_clcb->counter || + memcmp(p_rsp_value->value, p_attr->value + p_attr->offset, + p_rsp_value->len)) { + /* data does not match */ + p_clcb->status = GATT_ERROR; + flag = GATT_PREP_WRITE_CANCEL; + exec = true; + } else /* response checking is good */ { - gatt_send_queue_write_cancel (p_tcb, p_clcb, flag); - return true; + p_clcb->status = GATT_SUCCESS; + /* update write offset and check if end of attribute value */ + if ((p_attr->offset += p_rsp_value->len) >= p_attr->len) exec = true; } - return false; + } + if (exec) { + gatt_send_queue_write_cancel(p_tcb, p_clcb, flag); + return true; + } + return false; } /******************************************************************************* * @@ -359,47 +327,41 @@ bool gatt_check_write_long_terminate(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, t * Returns void. * ******************************************************************************/ -void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb) -{ - tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf; - uint16_t to_send, offset; - uint8_t rt = GATT_SUCCESS; - uint8_t type = p_clcb->op_subtype; +void gatt_send_prepare_write(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb) { + tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf; + uint16_t to_send, offset; + uint8_t rt = GATT_SUCCESS; + uint8_t type = p_clcb->op_subtype; - GATT_TRACE_DEBUG("gatt_send_prepare_write type=0x%x", type ); - to_send = p_attr->len - p_attr->offset; + GATT_TRACE_DEBUG("gatt_send_prepare_write type=0x%x", type); + to_send = p_attr->len - p_attr->offset; - if (to_send > (p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE)) /* 2 = uint16_t offset bytes */ - to_send = p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE; + if (to_send > (p_tcb->payload_size - + GATT_WRITE_LONG_HDR_SIZE)) /* 2 = uint16_t offset bytes */ + to_send = p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE; - p_clcb->s_handle = p_attr->handle; + p_clcb->s_handle = p_attr->handle; - offset = p_attr->offset; - if (type == GATT_WRITE_PREPARE) - { - offset += p_clcb->start_offset; - } + offset = p_attr->offset; + if (type == GATT_WRITE_PREPARE) { + offset += p_clcb->start_offset; + } - GATT_TRACE_DEBUG("offset =0x%x len=%d", offset, to_send ); + GATT_TRACE_DEBUG("offset =0x%x len=%d", offset, to_send); - rt = gatt_send_write_msg(p_tcb, - p_clcb->clcb_idx, - GATT_REQ_PREPARE_WRITE, - p_attr->handle, - to_send, /* length */ - offset, /* used as offset */ - p_attr->value + p_attr->offset); /* data */ + rt = gatt_send_write_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_PREPARE_WRITE, + p_attr->handle, to_send, /* length */ + offset, /* used as offset */ + p_attr->value + p_attr->offset); /* data */ - /* remember the write long attribute length */ - p_clcb->counter = to_send; + /* remember the write long attribute length */ + p_clcb->counter = to_send; - if (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED) - { - gatt_end_operation(p_clcb, rt, NULL); - } + if (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED) { + gatt_end_operation(p_clcb, rt, NULL); + } } - /******************************************************************************* * * Function gatt_process_find_type_value_rsp @@ -410,38 +372,42 @@ void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb) * Returns void * ******************************************************************************/ -void gatt_process_find_type_value_rsp (UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, - uint16_t len, uint8_t *p_data) -{ - tGATT_DISC_RES result; - uint8_t *p = p_data; - - GATT_TRACE_DEBUG("gatt_process_find_type_value_rsp "); - /* unexpected response */ - if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_SRVC_BY_UUID) - return; - - memset (&result, 0, sizeof(tGATT_DISC_RES)); - result.type.len = 2; - result.type.uu.uuid16 = GATT_UUID_PRI_SERVICE; - - /* returns a series of handle ranges */ - while (len >= 4) - { - STREAM_TO_UINT16 (result.handle, p); - STREAM_TO_UINT16 (result.value.group_value.e_handle, p); - memcpy (&result.value.group_value.service_type, &p_clcb->uuid, sizeof(tBT_UUID)); - - len -= 4; - - if (p_clcb->p_reg->app_cb.p_disc_res_cb) - (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result); - } +void gatt_process_find_type_value_rsp(UNUSED_ATTR tGATT_TCB* p_tcb, + tGATT_CLCB* p_clcb, uint16_t len, + uint8_t* p_data) { + tGATT_DISC_RES result; + uint8_t* p = p_data; + + GATT_TRACE_DEBUG("gatt_process_find_type_value_rsp "); + /* unexpected response */ + if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || + p_clcb->op_subtype != GATT_DISC_SRVC_BY_UUID) + return; - /* last handle + 1 */ - p_clcb->s_handle = (result.value.group_value.e_handle == 0) ? 0 : (result.value.group_value.e_handle + 1); - /* initiate another request */ - gatt_act_discovery(p_clcb) ; + memset(&result, 0, sizeof(tGATT_DISC_RES)); + result.type.len = 2; + result.type.uu.uuid16 = GATT_UUID_PRI_SERVICE; + + /* returns a series of handle ranges */ + while (len >= 4) { + STREAM_TO_UINT16(result.handle, p); + STREAM_TO_UINT16(result.value.group_value.e_handle, p); + memcpy(&result.value.group_value.service_type, &p_clcb->uuid, + sizeof(tBT_UUID)); + + len -= 4; + + if (p_clcb->p_reg->app_cb.p_disc_res_cb) + (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, + p_clcb->op_subtype, &result); + } + + /* last handle + 1 */ + p_clcb->s_handle = (result.value.group_value.e_handle == 0) + ? 0 + : (result.value.group_value.e_handle + 1); + /* initiate another request */ + gatt_act_discovery(p_clcb); } /******************************************************************************* * @@ -454,51 +420,48 @@ void gatt_process_find_type_value_rsp (UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB * Returns void * ******************************************************************************/ -void gatt_process_read_info_rsp(UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UNUSED_ATTR uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - tGATT_DISC_RES result; - uint8_t *p = p_data, uuid_len = 0, type; +void gatt_process_read_info_rsp(UNUSED_ATTR tGATT_TCB* p_tcb, + tGATT_CLCB* p_clcb, UNUSED_ATTR uint8_t op_code, + uint16_t len, uint8_t* p_data) { + tGATT_DISC_RES result; + uint8_t *p = p_data, uuid_len = 0, type; + + if (len < GATT_INFO_RSP_MIN_LEN) { + GATT_TRACE_ERROR("invalid Info Response PDU received, discard."); + gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL); + return; + } + /* unexpected response */ + if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || + p_clcb->op_subtype != GATT_DISC_CHAR_DSCPT) + return; - if (len < GATT_INFO_RSP_MIN_LEN) - { - GATT_TRACE_ERROR("invalid Info Response PDU received, discard."); - gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL); - return; - } - /* unexpected response */ - if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_CHAR_DSCPT) - return; + STREAM_TO_UINT8(type, p); + len -= 1; - STREAM_TO_UINT8(type, p); - len -= 1; + if (type == GATT_INFO_TYPE_PAIR_16) + uuid_len = LEN_UUID_16; + else if (type == GATT_INFO_TYPE_PAIR_128) + uuid_len = LEN_UUID_128; - if (type == GATT_INFO_TYPE_PAIR_16) - uuid_len = LEN_UUID_16; - else if (type == GATT_INFO_TYPE_PAIR_128) - uuid_len = LEN_UUID_128; + while (len >= uuid_len + 2) { + STREAM_TO_UINT16(result.handle, p); - while (len >= uuid_len + 2) - { - STREAM_TO_UINT16 (result.handle, p); + if (uuid_len > 0) { + if (!gatt_parse_uuid_from_cmd(&result.type, uuid_len, &p)) break; + } else + memcpy(&result.type, &p_clcb->uuid, sizeof(tBT_UUID)); - if (uuid_len > 0) - { - if (!gatt_parse_uuid_from_cmd(&result.type, uuid_len, &p)) - break; - } - else - memcpy (&result.type, &p_clcb->uuid, sizeof(tBT_UUID)); - - len -= (uuid_len + 2); + len -= (uuid_len + 2); - if (p_clcb->p_reg->app_cb.p_disc_res_cb) - (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result); - } + if (p_clcb->p_reg->app_cb.p_disc_res_cb) + (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, + p_clcb->op_subtype, &result); + } - p_clcb->s_handle = (result.handle == 0) ? 0 :(result.handle + 1); - /* initiate another request */ - gatt_act_discovery(p_clcb) ; + p_clcb->s_handle = (result.handle == 0) ? 0 : (result.handle + 1); + /* initiate another request */ + gatt_act_discovery(p_clcb); } /******************************************************************************* * @@ -510,32 +473,30 @@ void gatt_process_read_info_rsp(UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb * Returns void. * ******************************************************************************/ -void gatt_proc_disc_error_rsp(UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, - uint8_t opcode, - UNUSED_ATTR uint16_t handle, uint8_t reason) -{ - tGATT_STATUS status = (tGATT_STATUS) reason; - - GATT_TRACE_DEBUG("gatt_proc_disc_error_rsp reason: %02x cmd_code %04x", reason, opcode); - - switch (opcode) - { - case GATT_REQ_READ_BY_GRP_TYPE: - case GATT_REQ_FIND_TYPE_VALUE: - case GATT_REQ_READ_BY_TYPE: - case GATT_REQ_FIND_INFO: - if (reason == GATT_NOT_FOUND) - { - status = GATT_SUCCESS; - GATT_TRACE_DEBUG("Discovery completed"); - } - break; - default: - GATT_TRACE_ERROR("Incorrect discovery opcode %04x", opcode); - break; - } - - gatt_end_operation(p_clcb, status, NULL); +void gatt_proc_disc_error_rsp(UNUSED_ATTR tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + uint8_t opcode, UNUSED_ATTR uint16_t handle, + uint8_t reason) { + tGATT_STATUS status = (tGATT_STATUS)reason; + + GATT_TRACE_DEBUG("gatt_proc_disc_error_rsp reason: %02x cmd_code %04x", + reason, opcode); + + switch (opcode) { + case GATT_REQ_READ_BY_GRP_TYPE: + case GATT_REQ_FIND_TYPE_VALUE: + case GATT_REQ_READ_BY_TYPE: + case GATT_REQ_FIND_INFO: + if (reason == GATT_NOT_FOUND) { + status = GATT_SUCCESS; + GATT_TRACE_DEBUG("Discovery completed"); + } + break; + default: + GATT_TRACE_ERROR("Incorrect discovery opcode %04x", opcode); + break; + } + + gatt_end_operation(p_clcb, status, NULL); } /******************************************************************************* @@ -548,45 +509,37 @@ void gatt_proc_disc_error_rsp(UNUSED_ATTR tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, * Returns void * ******************************************************************************/ -void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UNUSED_ATTR uint8_t op_code, - UNUSED_ATTR uint16_t len, uint8_t *p_data) -{ - uint8_t opcode, reason, * p= p_data; - uint16_t handle; - tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf; - - GATT_TRACE_DEBUG("gatt_process_error_rsp "); - STREAM_TO_UINT8(opcode, p); - STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT8(reason, p); - - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) - { - gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason); - } - else - { - if ( (p_clcb->operation == GATTC_OPTYPE_WRITE) && - (p_clcb->op_subtype == GATT_WRITE) && - (opcode == GATT_REQ_PREPARE_WRITE) && - (p_attr) && - (handle == p_attr->handle) ) - { - p_clcb->status = reason; - gatt_send_queue_write_cancel(p_tcb, p_clcb, GATT_PREP_WRITE_CANCEL); - } - else if ((p_clcb->operation == GATTC_OPTYPE_READ) && - ((p_clcb->op_subtype == GATT_READ_CHAR_VALUE_HDL) || - (p_clcb->op_subtype == GATT_READ_BY_HANDLE)) && - (opcode == GATT_REQ_READ_BLOB) && - p_clcb->first_read_blob_after_read && - (reason == GATT_NOT_LONG)) - { - gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf); - } - else - gatt_end_operation(p_clcb, reason, NULL); - } +void gatt_process_error_rsp(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + UNUSED_ATTR uint8_t op_code, + UNUSED_ATTR uint16_t len, uint8_t* p_data) { + uint8_t opcode, reason, *p = p_data; + uint16_t handle; + tGATT_VALUE* p_attr = (tGATT_VALUE*)p_clcb->p_attr_buf; + + GATT_TRACE_DEBUG("gatt_process_error_rsp "); + STREAM_TO_UINT8(opcode, p); + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT8(reason, p); + + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) { + gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason); + } else { + if ((p_clcb->operation == GATTC_OPTYPE_WRITE) && + (p_clcb->op_subtype == GATT_WRITE) && + (opcode == GATT_REQ_PREPARE_WRITE) && (p_attr) && + (handle == p_attr->handle)) { + p_clcb->status = reason; + gatt_send_queue_write_cancel(p_tcb, p_clcb, GATT_PREP_WRITE_CANCEL); + } else if ((p_clcb->operation == GATTC_OPTYPE_READ) && + ((p_clcb->op_subtype == GATT_READ_CHAR_VALUE_HDL) || + (p_clcb->op_subtype == GATT_READ_BY_HANDLE)) && + (opcode == GATT_REQ_READ_BLOB) && + p_clcb->first_read_blob_after_read && + (reason == GATT_NOT_LONG)) { + gatt_end_operation(p_clcb, GATT_SUCCESS, (void*)p_clcb->p_attr_buf); + } else + gatt_end_operation(p_clcb, reason, NULL); + } } /******************************************************************************* * @@ -598,46 +551,41 @@ void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UNUSED_ATTR ui * Returns void * ******************************************************************************/ -void gatt_process_prep_write_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - uint8_t *p = p_data; - - tGATT_VALUE value = { - .conn_id = p_clcb->conn_id, - .auth_req = GATT_AUTH_REQ_NONE, - }; +void gatt_process_prep_write_rsp(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + uint8_t op_code, uint16_t len, + uint8_t* p_data) { + uint8_t* p = p_data; - GATT_TRACE_ERROR("value resp op_code = %s len = %d", gatt_dbg_op_name(op_code), len); + tGATT_VALUE value = { + .conn_id = p_clcb->conn_id, .auth_req = GATT_AUTH_REQ_NONE, + }; - if (len < GATT_PREP_WRITE_RSP_MIN_LEN) - { - GATT_TRACE_ERROR("illegal prepare write response length, discard"); - gatt_end_operation(p_clcb, GATT_INVALID_PDU, &value); - return; - } + GATT_TRACE_ERROR("value resp op_code = %s len = %d", + gatt_dbg_op_name(op_code), len); - STREAM_TO_UINT16 (value.handle, p); - STREAM_TO_UINT16 (value.offset, p); + if (len < GATT_PREP_WRITE_RSP_MIN_LEN) { + GATT_TRACE_ERROR("illegal prepare write response length, discard"); + gatt_end_operation(p_clcb, GATT_INVALID_PDU, &value); + return; + } - value.len = len - 4; + STREAM_TO_UINT16(value.handle, p); + STREAM_TO_UINT16(value.offset, p); - memcpy (value.value, p, value.len); + value.len = len - 4; - if (p_clcb->op_subtype == GATT_WRITE_PREPARE) - { - p_clcb->status = GATT_SUCCESS; - /* application should verify handle offset - and value are matched or not */ + memcpy(value.value, p, value.len); - gatt_end_operation(p_clcb, p_clcb->status, &value); - } - else if (p_clcb->op_subtype == GATT_WRITE ) - { - if (!gatt_check_write_long_terminate(p_tcb, p_clcb, &value)) - gatt_send_prepare_write(p_tcb, p_clcb); - } + if (p_clcb->op_subtype == GATT_WRITE_PREPARE) { + p_clcb->status = GATT_SUCCESS; + /* application should verify handle offset + and value are matched or not */ + gatt_end_operation(p_clcb, p_clcb->status, &value); + } else if (p_clcb->op_subtype == GATT_WRITE) { + if (!gatt_check_write_long_terminate(p_tcb, p_clcb, &value)) + gatt_send_prepare_write(p_tcb, p_clcb); + } } /******************************************************************************* * @@ -648,80 +596,78 @@ void gatt_process_prep_write_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint8_t * Returns void * ******************************************************************************/ -void gatt_process_notification(tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - tGATT_VALUE value; - tGATT_REG *p_reg; - uint16_t conn_id; - tGATT_STATUS encrypt_status; - uint8_t *p= p_data, i, - event = (op_code == GATT_HANDLE_VALUE_NOTIF) ? GATTC_OPTYPE_NOTIFICATION : GATTC_OPTYPE_INDICATION; - - GATT_TRACE_DEBUG("gatt_process_notification "); - - if (len < GATT_NOTIFICATION_MIN_LEN) - { - GATT_TRACE_ERROR("illegal notification PDU length, discard"); - return; - } - - memset(&value, 0, sizeof(value)); - STREAM_TO_UINT16(value.handle, p); - value.len = len - 2; - memcpy (value.value, p, value.len); - - if (!GATT_HANDLE_IS_VALID(value.handle)) - { - /* illegal handle, send ack now */ - if (op_code == GATT_HANDLE_VALUE_IND) - attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); - return; - } - - if (event == GATTC_OPTYPE_INDICATION) - { - if (p_tcb->ind_count) - { - /* this is an error case that receiving an indication but we - still has an indication not being acked yet. - For now, just log the error reset the counter. - Later we need to disconnect the link unconditionally. - */ - GATT_TRACE_ERROR("gatt_process_notification rcv Ind. but ind_count=%d (will reset ind_count)", p_tcb->ind_count); - } - p_tcb->ind_count = 0; - } - - /* should notify all registered client with the handle value notificaion/indication - Note: need to do the indication count and start timer first then do callback - */ +void gatt_process_notification(tGATT_TCB* p_tcb, uint8_t op_code, uint16_t len, + uint8_t* p_data) { + tGATT_VALUE value; + tGATT_REG* p_reg; + uint16_t conn_id; + tGATT_STATUS encrypt_status; + uint8_t *p = p_data, i, event = (op_code == GATT_HANDLE_VALUE_NOTIF) + ? GATTC_OPTYPE_NOTIFICATION + : GATTC_OPTYPE_INDICATION; + + GATT_TRACE_DEBUG("gatt_process_notification "); + + if (len < GATT_NOTIFICATION_MIN_LEN) { + GATT_TRACE_ERROR("illegal notification PDU length, discard"); + return; + } - for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) - { - if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb && (event == GATTC_OPTYPE_INDICATION)) - p_tcb->ind_count++; - } + memset(&value, 0, sizeof(value)); + STREAM_TO_UINT16(value.handle, p); + value.len = len - 2; + memcpy(value.value, p, value.len); - if (event == GATTC_OPTYPE_INDICATION) - { - /* start a timer for app confirmation */ - if (p_tcb->ind_count > 0) - gatt_start_ind_ack_timer(p_tcb); - else /* no app to indicate, or invalid handle */ - attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); + if (!GATT_HANDLE_IS_VALID(value.handle)) { + /* illegal handle, send ack now */ + if (op_code == GATT_HANDLE_VALUE_IND) + attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); + return; + } + + if (event == GATTC_OPTYPE_INDICATION) { + if (p_tcb->ind_count) { + /* this is an error case that receiving an indication but we + still has an indication not being acked yet. + For now, just log the error reset the counter. + Later we need to disconnect the link unconditionally. + */ + GATT_TRACE_ERROR( + "gatt_process_notification rcv Ind. but ind_count=%d (will reset " + "ind_count)", + p_tcb->ind_count); } - - encrypt_status = gatt_get_link_encrypt_status(p_tcb); - for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) - { - if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); - (*p_reg->app_cb.p_cmpl_cb) (conn_id, event, encrypt_status, (tGATT_CL_COMPLETE *)&value); - } + p_tcb->ind_count = 0; + } + + /* should notify all registered client with the handle value + notificaion/indication + Note: need to do the indication count and start timer first then do + callback + */ + + for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { + if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb && + (event == GATTC_OPTYPE_INDICATION)) + p_tcb->ind_count++; + } + + if (event == GATTC_OPTYPE_INDICATION) { + /* start a timer for app confirmation */ + if (p_tcb->ind_count > 0) + gatt_start_ind_ack_timer(p_tcb); + else /* no app to indicate, or invalid handle */ + attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); + } + + encrypt_status = gatt_get_link_encrypt_status(p_tcb); + for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { + if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) { + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, + (tGATT_CL_COMPLETE*)&value); } - + } } /******************************************************************************* @@ -735,195 +681,182 @@ void gatt_process_notification(tGATT_TCB *p_tcb, uint8_t op_code, * Returns void * ******************************************************************************/ -void gatt_process_read_by_type_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - tGATT_DISC_RES result; - tGATT_DISC_VALUE record_value; - uint8_t *p = p_data, value_len, handle_len = 2; - uint16_t handle = 0; - - /* discovery procedure and no callback function registered */ - if (((!p_clcb->p_reg) || (!p_clcb->p_reg->app_cb.p_disc_res_cb)) && (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)) - return; - - if (len < GATT_READ_BY_TYPE_RSP_MIN_LEN) - { - GATT_TRACE_ERROR("Illegal ReadByType/ReadByGroupType Response length, discard"); - gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL); - return; - } +void gatt_process_read_by_type_rsp(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + uint8_t op_code, uint16_t len, + uint8_t* p_data) { + tGATT_DISC_RES result; + tGATT_DISC_VALUE record_value; + uint8_t *p = p_data, value_len, handle_len = 2; + uint16_t handle = 0; + + /* discovery procedure and no callback function registered */ + if (((!p_clcb->p_reg) || (!p_clcb->p_reg->app_cb.p_disc_res_cb)) && + (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)) + return; - STREAM_TO_UINT8(value_len, p); + if (len < GATT_READ_BY_TYPE_RSP_MIN_LEN) { + GATT_TRACE_ERROR( + "Illegal ReadByType/ReadByGroupType Response length, discard"); + gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL); + return; + } + + STREAM_TO_UINT8(value_len, p); + + if ((value_len > (p_tcb->payload_size - 2)) || (value_len > (len - 1))) { + /* this is an error case that server's response containing a value length + which is larger than MTU-2 + or value_len > message total length -1 */ + GATT_TRACE_ERROR( + "gatt_process_read_by_type_rsp: Discard response op_code=%d " + "vale_len=%d > (MTU-2=%d or msg_len-1=%d)", + op_code, value_len, (p_tcb->payload_size - 2), (len - 1)); + gatt_end_operation(p_clcb, GATT_ERROR, NULL); + return; + } - if ((value_len > (p_tcb->payload_size - 2)) || (value_len > (len-1)) ) - { - /* this is an error case that server's response containing a value length which is larger than MTU-2 - or value_len > message total length -1 */ - GATT_TRACE_ERROR("gatt_process_read_by_type_rsp: Discard response op_code=%d vale_len=%d > (MTU-2=%d or msg_len-1=%d)", - op_code, value_len, (p_tcb->payload_size - 2), (len-1)); - gatt_end_operation(p_clcb, GATT_ERROR, NULL); - return; - } + if (op_code == GATT_RSP_READ_BY_GRP_TYPE) handle_len = 4; - if (op_code == GATT_RSP_READ_BY_GRP_TYPE) - handle_len = 4; + value_len -= handle_len; /* substract the handle pairs bytes */ + len -= 1; - value_len -= handle_len; /* substract the handle pairs bytes */ - len -= 1; + while (len >= (handle_len + value_len)) { + STREAM_TO_UINT16(handle, p); - while (len >= (handle_len + value_len)) - { - STREAM_TO_UINT16(handle, p); + if (!GATT_HANDLE_IS_VALID(handle)) { + gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); + return; + } - if (!GATT_HANDLE_IS_VALID(handle)) - { - gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); - return; - } + memset(&result, 0, sizeof(tGATT_DISC_RES)); + memset(&record_value, 0, sizeof(tGATT_DISC_VALUE)); - memset(&result, 0, sizeof(tGATT_DISC_RES)); - memset(&record_value, 0, sizeof(tGATT_DISC_VALUE)); + result.handle = handle; + result.type.len = 2; + result.type.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype]; - result.handle = handle; - result.type.len = 2; - result.type.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype]; + /* discover all services */ + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->op_subtype == GATT_DISC_SRVC_ALL && + op_code == GATT_RSP_READ_BY_GRP_TYPE) { + STREAM_TO_UINT16(handle, p); - /* discover all services */ - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && - p_clcb->op_subtype == GATT_DISC_SRVC_ALL && - op_code == GATT_RSP_READ_BY_GRP_TYPE) - { - STREAM_TO_UINT16(handle, p); - - if (!GATT_HANDLE_IS_VALID(handle)) - { - gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); - return; - } - else - { - record_value.group_value.e_handle = handle; - if (!gatt_parse_uuid_from_cmd(&record_value.group_value.service_type, value_len, &p)) - { - GATT_TRACE_ERROR("discover all service response parsing failure"); - break; - } - } - } - /* discover included service */ - else if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->op_subtype == GATT_DISC_INC_SRVC) - { - STREAM_TO_UINT16(record_value.incl_service.s_handle, p); - STREAM_TO_UINT16(record_value.incl_service.e_handle, p); - - if (!GATT_HANDLE_IS_VALID(record_value.incl_service.s_handle) || - !GATT_HANDLE_IS_VALID(record_value.incl_service.e_handle)) - { - gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); - return; - } - - if(value_len == 6) - { - STREAM_TO_UINT16(record_value.incl_service.service_type.uu.uuid16, p); - record_value.incl_service.service_type.len = LEN_UUID_16; - } - else if (value_len == 4) - { - p_clcb->s_handle = record_value.incl_service.s_handle; - p_clcb->read_uuid128.wait_for_read_rsp = true; - p_clcb->read_uuid128.next_disc_start_hdl = handle + 1; - memcpy(&p_clcb->read_uuid128.result, &result, sizeof(result)); - memcpy(&p_clcb->read_uuid128.result.value, &record_value, sizeof (result.value)); - p_clcb->op_subtype |= 0x90; - gatt_act_read(p_clcb, 0); - return; - } - else - { - GATT_TRACE_ERROR("gatt_process_read_by_type_rsp INCL_SRVC failed with invalid data value_len=%d", value_len); - gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p); - return; - } - } - /* read by type */ - else if (p_clcb->operation == GATTC_OPTYPE_READ && p_clcb->op_subtype == GATT_READ_BY_TYPE) - { - p_clcb->counter = len - 2; - p_clcb->s_handle = handle; - if ( p_clcb->counter == (p_clcb->p_tcb->payload_size -4)) - { - p_clcb->op_subtype = GATT_READ_BY_HANDLE; - if (!p_clcb->p_attr_buf) - p_clcb->p_attr_buf = (uint8_t *)osi_malloc(GATT_MAX_ATTR_LEN); - if (p_clcb->counter <= GATT_MAX_ATTR_LEN) { - memcpy(p_clcb->p_attr_buf, p, p_clcb->counter); - gatt_act_read(p_clcb, p_clcb->counter); - } else { - gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, (void *)p); - } - } - else - { - gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p); - } - return; - } - else /* discover characterisitic */ - { - STREAM_TO_UINT8 (record_value.dclr_value.char_prop, p); - STREAM_TO_UINT16(record_value.dclr_value.val_handle, p); - if (!GATT_HANDLE_IS_VALID(record_value.dclr_value.val_handle)) - { - gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); - return; - } - if (!gatt_parse_uuid_from_cmd(&record_value.dclr_value.char_uuid, (uint16_t)(value_len - 3), &p)) - { - gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); - /* invalid format, and skip the result */ - return; - } - - /* UUID not matching */ - if (!gatt_uuid_compare(record_value.dclr_value.char_uuid, p_clcb->uuid)) - { - len -= (value_len + 2); - continue; /* skip the result, and look for next one */ - } - else if (p_clcb->operation == GATTC_OPTYPE_READ) - /* UUID match for read characteristic value */ - { - /* only read the first matching UUID characteristic value, and - discard the rest results */ - p_clcb->s_handle = record_value.dclr_value.val_handle; - p_clcb->op_subtype |= 0x80; - gatt_act_read(p_clcb, 0); - return; - } + if (!GATT_HANDLE_IS_VALID(handle)) { + gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); + return; + } else { + record_value.group_value.e_handle = handle; + if (!gatt_parse_uuid_from_cmd(&record_value.group_value.service_type, + value_len, &p)) { + GATT_TRACE_ERROR("discover all service response parsing failure"); + break; } - len -= (value_len + handle_len); - - /* result is (handle, 16bits UUID) pairs */ - memcpy (&result.value, &record_value, sizeof (result.value)); - - /* send callback if is discover procedure */ - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->p_reg->app_cb.p_disc_res_cb) - (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result); + } } - - p_clcb->s_handle = (handle == 0) ? 0 : (handle + 1); - - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) - { - /* initiate another request */ - gatt_act_discovery(p_clcb) ; + /* discover included service */ + else if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->op_subtype == GATT_DISC_INC_SRVC) { + STREAM_TO_UINT16(record_value.incl_service.s_handle, p); + STREAM_TO_UINT16(record_value.incl_service.e_handle, p); + + if (!GATT_HANDLE_IS_VALID(record_value.incl_service.s_handle) || + !GATT_HANDLE_IS_VALID(record_value.incl_service.e_handle)) { + gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); + return; + } + + if (value_len == 6) { + STREAM_TO_UINT16(record_value.incl_service.service_type.uu.uuid16, p); + record_value.incl_service.service_type.len = LEN_UUID_16; + } else if (value_len == 4) { + p_clcb->s_handle = record_value.incl_service.s_handle; + p_clcb->read_uuid128.wait_for_read_rsp = true; + p_clcb->read_uuid128.next_disc_start_hdl = handle + 1; + memcpy(&p_clcb->read_uuid128.result, &result, sizeof(result)); + memcpy(&p_clcb->read_uuid128.result.value, &record_value, + sizeof(result.value)); + p_clcb->op_subtype |= 0x90; + gatt_act_read(p_clcb, 0); + return; + } else { + GATT_TRACE_ERROR( + "gatt_process_read_by_type_rsp INCL_SRVC failed with invalid data " + "value_len=%d", + value_len); + gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void*)p); + return; + } } - else /* read characteristic value */ + /* read by type */ + else if (p_clcb->operation == GATTC_OPTYPE_READ && + p_clcb->op_subtype == GATT_READ_BY_TYPE) { + p_clcb->counter = len - 2; + p_clcb->s_handle = handle; + if (p_clcb->counter == (p_clcb->p_tcb->payload_size - 4)) { + p_clcb->op_subtype = GATT_READ_BY_HANDLE; + if (!p_clcb->p_attr_buf) + p_clcb->p_attr_buf = (uint8_t*)osi_malloc(GATT_MAX_ATTR_LEN); + if (p_clcb->counter <= GATT_MAX_ATTR_LEN) { + memcpy(p_clcb->p_attr_buf, p, p_clcb->counter); + gatt_act_read(p_clcb, p_clcb->counter); + } else { + gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, (void*)p); + } + } else { + gatt_end_operation(p_clcb, GATT_SUCCESS, (void*)p); + } + return; + } else /* discover characterisitic */ { + STREAM_TO_UINT8(record_value.dclr_value.char_prop, p); + STREAM_TO_UINT16(record_value.dclr_value.val_handle, p); + if (!GATT_HANDLE_IS_VALID(record_value.dclr_value.val_handle)) { + gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL); + return; + } + if (!gatt_parse_uuid_from_cmd(&record_value.dclr_value.char_uuid, + (uint16_t)(value_len - 3), &p)) { + gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); + /* invalid format, and skip the result */ + return; + } + + /* UUID not matching */ + if (!gatt_uuid_compare(record_value.dclr_value.char_uuid, p_clcb->uuid)) { + len -= (value_len + 2); + continue; /* skip the result, and look for next one */ + } else if (p_clcb->operation == GATTC_OPTYPE_READ) + /* UUID match for read characteristic value */ + { + /* only read the first matching UUID characteristic value, and + discard the rest results */ + p_clcb->s_handle = record_value.dclr_value.val_handle; + p_clcb->op_subtype |= 0x80; gatt_act_read(p_clcb, 0); + return; + } } + len -= (value_len + handle_len); + + /* result is (handle, 16bits UUID) pairs */ + memcpy(&result.value, &record_value, sizeof(result.value)); + + /* send callback if is discover procedure */ + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->p_reg->app_cb.p_disc_res_cb) + (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, + p_clcb->op_subtype, &result); + } + + p_clcb->s_handle = (handle == 0) ? 0 : (handle + 1); + + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) { + /* initiate another request */ + gatt_act_discovery(p_clcb); + } else /* read characteristic value */ + { + gatt_act_read(p_clcb, 0); + } } /******************************************************************************* @@ -936,83 +869,76 @@ void gatt_process_read_by_type_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint8_ * Returns void * ******************************************************************************/ -void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UNUSED_ATTR uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - uint16_t offset = p_clcb->counter; - uint8_t * p= p_data; - - if (p_clcb->operation == GATTC_OPTYPE_READ) - { - if (p_clcb->op_subtype != GATT_READ_BY_HANDLE) - { - p_clcb->counter = len; - gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p); - } - else +void gatt_process_read_rsp(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + UNUSED_ATTR uint8_t op_code, uint16_t len, + uint8_t* p_data) { + uint16_t offset = p_clcb->counter; + uint8_t* p = p_data; + + if (p_clcb->operation == GATTC_OPTYPE_READ) { + if (p_clcb->op_subtype != GATT_READ_BY_HANDLE) { + p_clcb->counter = len; + gatt_end_operation(p_clcb, GATT_SUCCESS, (void*)p); + } else { + /* allocate GKI buffer holding up long attribute value */ + if (!p_clcb->p_attr_buf) + p_clcb->p_attr_buf = (uint8_t*)osi_malloc(GATT_MAX_ATTR_LEN); + + /* copy attrobute value into cb buffer */ + if (offset < GATT_MAX_ATTR_LEN) { + if ((len + offset) > GATT_MAX_ATTR_LEN) + len = GATT_MAX_ATTR_LEN - offset; + + p_clcb->counter += len; + + memcpy(p_clcb->p_attr_buf + offset, p, len); + + /* send next request if needed */ + + if (len == (p_tcb->payload_size - + 1) && /* full packet for read or read blob rsp */ + len + offset < GATT_MAX_ATTR_LEN) { + GATT_TRACE_DEBUG( + "full pkt issue read blob for remianing bytes old offset=%d " + "len=%d new offset=%d", + offset, len, p_clcb->counter); + gatt_act_read(p_clcb, p_clcb->counter); + } else /* end of request, send callback */ { - - /* allocate GKI buffer holding up long attribute value */ - if (!p_clcb->p_attr_buf) - p_clcb->p_attr_buf = (uint8_t *)osi_malloc(GATT_MAX_ATTR_LEN); - - /* copy attrobute value into cb buffer */ - if (offset < GATT_MAX_ATTR_LEN) { - if ((len + offset) > GATT_MAX_ATTR_LEN) - len = GATT_MAX_ATTR_LEN - offset; - - p_clcb->counter += len; - - memcpy(p_clcb->p_attr_buf + offset, p, len); - - /* send next request if needed */ - - if (len == (p_tcb->payload_size - 1) && /* full packet for read or read blob rsp */ - len + offset < GATT_MAX_ATTR_LEN) - { - GATT_TRACE_DEBUG("full pkt issue read blob for remianing bytes old offset=%d len=%d new offset=%d", - offset, len, p_clcb->counter); - gatt_act_read(p_clcb, p_clcb->counter); - } - else /* end of request, send callback */ - { - gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf); - } - } - else /* exception, should not happen */ - { - GATT_TRACE_ERROR("attr offset = %d p_attr_buf = %d ", offset, p_clcb->p_attr_buf); - gatt_end_operation(p_clcb, GATT_NO_RESOURCES, (void *)p_clcb->p_attr_buf); - } + gatt_end_operation(p_clcb, GATT_SUCCESS, (void*)p_clcb->p_attr_buf); } + } else /* exception, should not happen */ + { + GATT_TRACE_ERROR("attr offset = %d p_attr_buf = %d ", offset, + p_clcb->p_attr_buf); + gatt_end_operation(p_clcb, GATT_NO_RESOURCES, + (void*)p_clcb->p_attr_buf); + } } - else - { - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && - p_clcb->op_subtype == GATT_DISC_INC_SRVC && - p_clcb->read_uuid128.wait_for_read_rsp ) - { - p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl; - p_clcb->read_uuid128.wait_for_read_rsp = false; - if (len == LEN_UUID_128) - { - - memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu.uuid128, p, len); - p_clcb->read_uuid128.result.value.incl_service.service_type.len = LEN_UUID_128; - if ( p_clcb->p_reg->app_cb.p_disc_res_cb) - (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &p_clcb->read_uuid128.result); - gatt_act_discovery(p_clcb) ; - } - else - { - gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p); - } - } + } else { + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->op_subtype == GATT_DISC_INC_SRVC && + p_clcb->read_uuid128.wait_for_read_rsp) { + p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl; + p_clcb->read_uuid128.wait_for_read_rsp = false; + if (len == LEN_UUID_128) { + memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu + .uuid128, + p, len); + p_clcb->read_uuid128.result.value.incl_service.service_type.len = + LEN_UUID_128; + if (p_clcb->p_reg->app_cb.p_disc_res_cb) + (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, + p_clcb->op_subtype, + &p_clcb->read_uuid128.result); + gatt_act_discovery(p_clcb); + } else { + gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void*)p); + } } - + } } - /******************************************************************************* * * Function gatt_process_handle_rsp @@ -1023,9 +949,8 @@ void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UNUSED_ATTR ui * Returns void * ******************************************************************************/ -void gatt_process_handle_rsp(tGATT_CLCB *p_clcb) -{ - gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); +void gatt_process_handle_rsp(tGATT_CLCB* p_clcb) { + gatt_end_operation(p_clcb, GATT_SUCCESS, NULL); } /******************************************************************************* * @@ -1037,26 +962,24 @@ void gatt_process_handle_rsp(tGATT_CLCB *p_clcb) * Returns void * ******************************************************************************/ -void gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint16_t len, uint8_t *p_data) -{ - uint16_t mtu; - tGATT_STATUS status = GATT_SUCCESS; - - if (len < GATT_MTU_RSP_MIN_LEN) - { - GATT_TRACE_ERROR("invalid MTU response PDU received, discard."); - status = GATT_INVALID_PDU; - } - else - { +void gatt_process_mtu_rsp(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, uint16_t len, + uint8_t* p_data) { + uint16_t mtu; + tGATT_STATUS status = GATT_SUCCESS; + + if (len < GATT_MTU_RSP_MIN_LEN) { + GATT_TRACE_ERROR("invalid MTU response PDU received, discard."); + status = GATT_INVALID_PDU; + } else { STREAM_TO_UINT16(mtu, p_data); if (mtu < p_tcb->payload_size && mtu >= GATT_DEF_BLE_MTU_SIZE) - p_tcb->payload_size = mtu; - } + p_tcb->payload_size = mtu; + } - l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); - gatt_end_operation(p_clcb, status, NULL); + l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, + p_tcb->payload_size); + gatt_end_operation(p_clcb, status, NULL); } /******************************************************************************* * @@ -1068,15 +991,13 @@ void gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, uint16_t len, ui * Returns response code. * ******************************************************************************/ -uint8_t gatt_cmd_to_rsp_code (uint8_t cmd_code) -{ - uint8_t rsp_code = 0; +uint8_t gatt_cmd_to_rsp_code(uint8_t cmd_code) { + uint8_t rsp_code = 0; - if (cmd_code > 1 && cmd_code != GATT_CMD_WRITE) - { - rsp_code = cmd_code + 1; - } - return rsp_code; + if (cmd_code > 1 && cmd_code != GATT_CMD_WRITE) { + rsp_code = cmd_code + 1; + } + return rsp_code; } /******************************************************************************* * @@ -1087,55 +1008,45 @@ uint8_t gatt_cmd_to_rsp_code (uint8_t cmd_code) * Returns true if command sent, otherwise false. * ******************************************************************************/ -bool gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb) -{ - tGATT_CMD_Q *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; - bool sent = false; - uint8_t rsp_code; - tGATT_CLCB *p_clcb = NULL; - tGATT_STATUS att_ret = GATT_SUCCESS; - - while (!sent && - p_tcb->pending_cl_req != p_tcb->next_slot_inq && - p_cmd->to_send && p_cmd->p_cmd != NULL) - { - att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd->p_cmd); +bool gatt_cl_send_next_cmd_inq(tGATT_TCB* p_tcb) { + tGATT_CMD_Q* p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; + bool sent = false; + uint8_t rsp_code; + tGATT_CLCB* p_clcb = NULL; + tGATT_STATUS att_ret = GATT_SUCCESS; + + while (!sent && p_tcb->pending_cl_req != p_tcb->next_slot_inq && + p_cmd->to_send && p_cmd->p_cmd != NULL) { + att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd->p_cmd); + + if (att_ret == GATT_SUCCESS || att_ret == GATT_CONGESTED) { + sent = true; + p_cmd->to_send = false; + p_cmd->p_cmd = NULL; + + /* dequeue the request if is write command or sign write */ + if (p_cmd->op_code != GATT_CMD_WRITE && + p_cmd->op_code != GATT_SIGN_CMD_WRITE) { + gatt_start_rsp_timer(p_cmd->clcb_idx); + } else { + p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code); - if (att_ret == GATT_SUCCESS || att_ret == GATT_CONGESTED) - { - sent = true; - p_cmd->to_send = false; - p_cmd->p_cmd = NULL; - - /* dequeue the request if is write command or sign write */ - if (p_cmd->op_code != GATT_CMD_WRITE && p_cmd->op_code != GATT_SIGN_CMD_WRITE) - { - gatt_start_rsp_timer (p_cmd->clcb_idx); - } - else - { - p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code); - - /* if no ack needed, keep sending */ - if (att_ret == GATT_SUCCESS) - sent = false; - - p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; - /* send command complete callback here */ - gatt_end_operation(p_clcb, att_ret, NULL); - } - } - else - { - GATT_TRACE_ERROR("gatt_cl_send_next_cmd_inq: L2CAP sent error"); + /* if no ack needed, keep sending */ + if (att_ret == GATT_SUCCESS) sent = false; - memset(p_cmd, 0, sizeof(tGATT_CMD_Q)); - p_tcb->pending_cl_req ++; - p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; - } + p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; + /* send command complete callback here */ + gatt_end_operation(p_clcb, att_ret, NULL); + } + } else { + GATT_TRACE_ERROR("gatt_cl_send_next_cmd_inq: L2CAP sent error"); + memset(p_cmd, 0, sizeof(tGATT_CMD_Q)); + p_tcb->pending_cl_req++; + p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; } - return sent; + } + return sent; } /******************************************************************************* @@ -1149,98 +1060,91 @@ bool gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb) * Returns void * ******************************************************************************/ -void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - tGATT_CLCB *p_clcb = NULL; - uint8_t rsp_code; - - if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) - { - p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code); - - rsp_code = gatt_cmd_to_rsp_code(rsp_code); - - if (p_clcb == NULL || (rsp_code != op_code && op_code != GATT_RSP_ERROR)) - { - GATT_TRACE_WARNING ("ATT - Ignore wrong response. Receives (%02x) \ - Request(%02x) Ignored", op_code, rsp_code); - - return; - } - else - { - alarm_cancel(p_clcb->gatt_rsp_timer_ent); - p_clcb->retry_count = 0; - } +void gatt_client_handle_server_rsp(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + tGATT_CLCB* p_clcb = NULL; + uint8_t rsp_code; + + if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) { + p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code); + + rsp_code = gatt_cmd_to_rsp_code(rsp_code); + + if (p_clcb == NULL || (rsp_code != op_code && op_code != GATT_RSP_ERROR)) { + GATT_TRACE_WARNING( + "ATT - Ignore wrong response. Receives (%02x) \ + Request(%02x) Ignored", + op_code, rsp_code); + + return; + } else { + alarm_cancel(p_clcb->gatt_rsp_timer_ent); + p_clcb->retry_count = 0; } - /* the size of the message may not be bigger than the local max PDU size*/ - /* The message has to be smaller than the agreed MTU, len does not count op_code */ - if (len >= p_tcb->payload_size) - { - GATT_TRACE_ERROR("invalid response/indicate pkt size: %d, PDU size: %d", len + 1, p_tcb->payload_size); - if (op_code != GATT_HANDLE_VALUE_NOTIF && - op_code != GATT_HANDLE_VALUE_IND) - gatt_end_operation(p_clcb, GATT_ERROR, NULL); - } - else - { - switch (op_code) - { - case GATT_RSP_ERROR: - gatt_process_error_rsp(p_tcb, p_clcb, op_code, len, p_data); - break; - - case GATT_RSP_MTU: /* 2 bytes mtu */ - gatt_process_mtu_rsp(p_tcb, p_clcb, len ,p_data); - break; - - case GATT_RSP_FIND_INFO: - gatt_process_read_info_rsp(p_tcb, p_clcb, op_code, len, p_data); - break; - - case GATT_RSP_READ_BY_TYPE: - case GATT_RSP_READ_BY_GRP_TYPE: - gatt_process_read_by_type_rsp(p_tcb, p_clcb, op_code, len, p_data); - break; - - case GATT_RSP_READ: - case GATT_RSP_READ_BLOB: - case GATT_RSP_READ_MULTI: - gatt_process_read_rsp(p_tcb, p_clcb, op_code, len, p_data); - break; - - case GATT_RSP_FIND_TYPE_VALUE: /* disc service with UUID */ - gatt_process_find_type_value_rsp(p_tcb, p_clcb, len, p_data); - break; - - case GATT_RSP_WRITE: - gatt_process_handle_rsp(p_clcb); - break; - - case GATT_RSP_PREPARE_WRITE: - gatt_process_prep_write_rsp(p_tcb, p_clcb, op_code, len, p_data); - break; - - case GATT_RSP_EXEC_WRITE: - gatt_end_operation(p_clcb, p_clcb->status, NULL); - break; - - case GATT_HANDLE_VALUE_NOTIF: - case GATT_HANDLE_VALUE_IND: - gatt_process_notification(p_tcb, op_code, len, p_data); - break; - - default: - GATT_TRACE_ERROR("Unknown opcode = %d", op_code); - break; - } + } + /* the size of the message may not be bigger than the local max PDU size*/ + /* The message has to be smaller than the agreed MTU, len does not count + * op_code */ + if (len >= p_tcb->payload_size) { + GATT_TRACE_ERROR("invalid response/indicate pkt size: %d, PDU size: %d", + len + 1, p_tcb->payload_size); + if (op_code != GATT_HANDLE_VALUE_NOTIF && op_code != GATT_HANDLE_VALUE_IND) + gatt_end_operation(p_clcb, GATT_ERROR, NULL); + } else { + switch (op_code) { + case GATT_RSP_ERROR: + gatt_process_error_rsp(p_tcb, p_clcb, op_code, len, p_data); + break; + + case GATT_RSP_MTU: /* 2 bytes mtu */ + gatt_process_mtu_rsp(p_tcb, p_clcb, len, p_data); + break; + + case GATT_RSP_FIND_INFO: + gatt_process_read_info_rsp(p_tcb, p_clcb, op_code, len, p_data); + break; + + case GATT_RSP_READ_BY_TYPE: + case GATT_RSP_READ_BY_GRP_TYPE: + gatt_process_read_by_type_rsp(p_tcb, p_clcb, op_code, len, p_data); + break; + + case GATT_RSP_READ: + case GATT_RSP_READ_BLOB: + case GATT_RSP_READ_MULTI: + gatt_process_read_rsp(p_tcb, p_clcb, op_code, len, p_data); + break; + + case GATT_RSP_FIND_TYPE_VALUE: /* disc service with UUID */ + gatt_process_find_type_value_rsp(p_tcb, p_clcb, len, p_data); + break; + + case GATT_RSP_WRITE: + gatt_process_handle_rsp(p_clcb); + break; + + case GATT_RSP_PREPARE_WRITE: + gatt_process_prep_write_rsp(p_tcb, p_clcb, op_code, len, p_data); + break; + + case GATT_RSP_EXEC_WRITE: + gatt_end_operation(p_clcb, p_clcb->status, NULL); + break; + + case GATT_HANDLE_VALUE_NOTIF: + case GATT_HANDLE_VALUE_IND: + gatt_process_notification(p_tcb, op_code, len, p_data); + break; + + default: + GATT_TRACE_ERROR("Unknown opcode = %d", op_code); + break; } + } - if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) - { - gatt_cl_send_next_cmd_inq(p_tcb); - } + if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) { + gatt_cl_send_next_cmd_inq(p_tcb); + } - return; + return; } diff --git a/stack/gatt/gatt_db.cc b/stack/gatt/gatt_db.cc index d5a987ce6..44a85230d 100644 --- a/stack/gatt/gatt_db.cc +++ b/stack/gatt/gatt_db.cc @@ -29,23 +29,26 @@ #include #include +#include "btm_int.h" #include "gatt_int.h" #include "l2c_api.h" -#include "btm_int.h" #include "osi/include/osi.h" /******************************************************************************* * L O C A L F U N C T I O N P R O T O T Y P E S * ******************************************************************************/ -static bool allocate_svc_db_buf(tGATT_SVC_DB *p_db); -static void *allocate_attr_in_db(tGATT_SVC_DB *p_db, tBT_UUID *p_uuid, tGATT_PERM perm); -static bool deallocate_attr_in_db(tGATT_SVC_DB *p_db, void *p_attr); -static bool copy_extra_byte_in_db(tGATT_SVC_DB *p_db, void **p_dst, uint16_t len); - -static bool gatts_db_add_service_declaration(tGATT_SVC_DB *p_db, tBT_UUID *p_service, bool is_pri); -static tGATT_STATUS gatts_send_app_read_request(tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t handle, uint16_t offset, uint32_t trans_id, - bt_gatt_db_attribute_type_t gatt_type); +static bool allocate_svc_db_buf(tGATT_SVC_DB* p_db); +static void* allocate_attr_in_db(tGATT_SVC_DB* p_db, tBT_UUID* p_uuid, + tGATT_PERM perm); +static bool deallocate_attr_in_db(tGATT_SVC_DB* p_db, void* p_attr); +static bool copy_extra_byte_in_db(tGATT_SVC_DB* p_db, void** p_dst, + uint16_t len); + +static bool gatts_db_add_service_declaration(tGATT_SVC_DB* p_db, + tBT_UUID* p_service, bool is_pri); +static tGATT_STATUS gatts_send_app_read_request( + tGATT_TCB* p_tcb, uint8_t op_code, uint16_t handle, uint16_t offset, + uint32_t trans_id, bt_gatt_db_attribute_type_t gatt_type); /******************************************************************************* * @@ -59,25 +62,23 @@ static tGATT_STATUS gatts_send_app_read_request(tGATT_TCB *p_tcb, uint8_t op_cod * Returns Status of te operation. * ******************************************************************************/ -bool gatts_init_service_db (tGATT_SVC_DB *p_db, tBT_UUID *p_service, bool is_pri, - uint16_t s_hdl, uint16_t num_handle) -{ - p_db->svc_buffer = fixed_queue_new(SIZE_MAX); - - if (!allocate_svc_db_buf(p_db)) - { - GATT_TRACE_ERROR("gatts_init_service_db failed, no resources"); - return false; - } +bool gatts_init_service_db(tGATT_SVC_DB* p_db, tBT_UUID* p_service, bool is_pri, + uint16_t s_hdl, uint16_t num_handle) { + p_db->svc_buffer = fixed_queue_new(SIZE_MAX); + + if (!allocate_svc_db_buf(p_db)) { + GATT_TRACE_ERROR("gatts_init_service_db failed, no resources"); + return false; + } - GATT_TRACE_DEBUG("gatts_init_service_db"); - GATT_TRACE_DEBUG("s_hdl = %d num_handle = %d", s_hdl, num_handle ); + GATT_TRACE_DEBUG("gatts_init_service_db"); + GATT_TRACE_DEBUG("s_hdl = %d num_handle = %d", s_hdl, num_handle); - /* update service database information */ - p_db->next_handle = s_hdl; - p_db->end_handle = s_hdl + num_handle; + /* update service database information */ + p_db->next_handle = s_hdl; + p_db->end_handle = s_hdl + num_handle; - return gatts_db_add_service_declaration(p_db, p_service, is_pri); + return gatts_db_add_service_declaration(p_db, p_service, is_pri); } /******************************************************************************* @@ -92,18 +93,14 @@ bool gatts_init_service_db (tGATT_SVC_DB *p_db, tBT_UUID *p_service, bool * Returns Status of te operation. * ******************************************************************************/ -tBT_UUID * gatts_get_service_uuid (tGATT_SVC_DB *p_db) -{ - if (!p_db || !p_db->p_attr_list) - { - GATT_TRACE_ERROR("service DB empty"); - - return NULL; - } - else - { - return &((tGATT_ATTR *)p_db->p_attr_list)->p_value->uuid; - } +tBT_UUID* gatts_get_service_uuid(tGATT_SVC_DB* p_db) { + if (!p_db || !p_db->p_attr_list) { + GATT_TRACE_ERROR("service DB empty"); + + return NULL; + } else { + return &((tGATT_ATTR*)p_db->p_attr_list)->p_value->uuid; + } } /******************************************************************************* @@ -115,74 +112,68 @@ tBT_UUID * gatts_get_service_uuid (tGATT_SVC_DB *p_db) * Returns status of operation. * ******************************************************************************/ -static tGATT_STATUS gatts_check_attr_readability(tGATT_ATTR *p_attr, +static tGATT_STATUS gatts_check_attr_readability(tGATT_ATTR* p_attr, UNUSED_ATTR uint16_t offset, - bool read_long, + bool read_long, tGATT_SEC_FLAG sec_flag, - uint8_t key_size) -{ - uint16_t min_key_size; - tGATT_PERM perm = p_attr->permission; - - min_key_size = (((perm & GATT_ENCRYPT_KEY_SIZE_MASK) >> 12)); - if (min_key_size != 0 ) - { - min_key_size +=6; - } - - if (!(perm & GATT_READ_ALLOWED)) - { - GATT_TRACE_ERROR("%s: GATT_READ_NOT_PERMIT", __func__); - return GATT_READ_NOT_PERMIT; - } - - if ((perm & GATT_READ_AUTH_REQUIRED ) && !(sec_flag & GATT_SEC_FLAG_LKEY_UNAUTHED) && - !(sec_flag & BTM_SEC_FLAG_ENCRYPTED)) - { - GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION", __func__); - return GATT_INSUF_AUTHENTICATION; - } - - if ((perm & GATT_READ_MITM_REQUIRED ) && !(sec_flag & GATT_SEC_FLAG_LKEY_AUTHED)) - { - GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION: MITM Required", __func__); - return GATT_INSUF_AUTHENTICATION; - } - - if ((perm & GATT_READ_ENCRYPTED_REQUIRED ) && !(sec_flag & GATT_SEC_FLAG_ENCRYPTED)) - { - GATT_TRACE_ERROR("%s: GATT_INSUF_ENCRYPTION", __func__); - return GATT_INSUF_ENCRYPTION; - } - - if ( (perm & GATT_READ_ENCRYPTED_REQUIRED) && (sec_flag & GATT_SEC_FLAG_ENCRYPTED) && (key_size < min_key_size)) - { - GATT_TRACE_ERROR("%s: GATT_INSUF_KEY_SIZE", __func__); - return GATT_INSUF_KEY_SIZE; + uint8_t key_size) { + uint16_t min_key_size; + tGATT_PERM perm = p_attr->permission; + + min_key_size = (((perm & GATT_ENCRYPT_KEY_SIZE_MASK) >> 12)); + if (min_key_size != 0) { + min_key_size += 6; + } + + if (!(perm & GATT_READ_ALLOWED)) { + GATT_TRACE_ERROR("%s: GATT_READ_NOT_PERMIT", __func__); + return GATT_READ_NOT_PERMIT; + } + + if ((perm & GATT_READ_AUTH_REQUIRED) && + !(sec_flag & GATT_SEC_FLAG_LKEY_UNAUTHED) && + !(sec_flag & BTM_SEC_FLAG_ENCRYPTED)) { + GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION", __func__); + return GATT_INSUF_AUTHENTICATION; + } + + if ((perm & GATT_READ_MITM_REQUIRED) && + !(sec_flag & GATT_SEC_FLAG_LKEY_AUTHED)) { + GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION: MITM Required", __func__); + return GATT_INSUF_AUTHENTICATION; + } + + if ((perm & GATT_READ_ENCRYPTED_REQUIRED) && + !(sec_flag & GATT_SEC_FLAG_ENCRYPTED)) { + GATT_TRACE_ERROR("%s: GATT_INSUF_ENCRYPTION", __func__); + return GATT_INSUF_ENCRYPTION; + } + + if ((perm & GATT_READ_ENCRYPTED_REQUIRED) && + (sec_flag & GATT_SEC_FLAG_ENCRYPTED) && (key_size < min_key_size)) { + GATT_TRACE_ERROR("%s: GATT_INSUF_KEY_SIZE", __func__); + return GATT_INSUF_KEY_SIZE; + } + + if (read_long && p_attr->uuid.len == LEN_UUID_16) { + switch (p_attr->uuid.uu.uuid16) { + case GATT_UUID_PRI_SERVICE: + case GATT_UUID_SEC_SERVICE: + case GATT_UUID_CHAR_DECLARE: + case GATT_UUID_INCLUDE_SERVICE: + case GATT_UUID_CHAR_EXT_PROP: + case GATT_UUID_CHAR_CLIENT_CONFIG: + case GATT_UUID_CHAR_SRVR_CONFIG: + case GATT_UUID_CHAR_PRESENT_FORMAT: + GATT_TRACE_ERROR("%s: GATT_NOT_LONG", __func__); + return GATT_NOT_LONG; + + default: + break; } + } - - if (read_long && p_attr->uuid.len == LEN_UUID_16) - { - switch (p_attr->uuid.uu.uuid16) - { - case GATT_UUID_PRI_SERVICE: - case GATT_UUID_SEC_SERVICE: - case GATT_UUID_CHAR_DECLARE: - case GATT_UUID_INCLUDE_SERVICE: - case GATT_UUID_CHAR_EXT_PROP: - case GATT_UUID_CHAR_CLIENT_CONFIG: - case GATT_UUID_CHAR_SRVR_CONFIG: - case GATT_UUID_CHAR_PRESENT_FORMAT: - GATT_TRACE_ERROR("%s: GATT_NOT_LONG", __func__); - return GATT_NOT_LONG; - - default: - break; - } - } - - return GATT_SUCCESS; + return GATT_SUCCESS; } /******************************************************************************* @@ -203,100 +194,81 @@ static tGATT_STATUS gatts_check_attr_readability(tGATT_ATTR *p_attr, * Returns status of operation. * ******************************************************************************/ -static tGATT_STATUS read_attr_value (void *p_attr, - uint16_t offset, - uint8_t **p_data, - bool read_long, - uint16_t mtu, - uint16_t *p_len, - tGATT_SEC_FLAG sec_flag, - uint8_t key_size) -{ - uint16_t len = 0, uuid16 = 0; - uint8_t *p = *p_data; - tGATT_STATUS status; - tGATT_ATTR *p_attr16 = (tGATT_ATTR *)p_attr; - - GATT_TRACE_DEBUG("read_attr_value uuid=0x%04x perm=0x%02x sec_flag=0x%x offset=%d read_long=%d", - p_attr16->uuid, - p_attr16->permission, - sec_flag, - offset, - read_long); - - status = gatts_check_attr_readability((tGATT_ATTR *)p_attr, offset, read_long, sec_flag, key_size); - - if (status != GATT_SUCCESS) - return status; - - if (p_attr16->uuid.len == LEN_UUID_16) - uuid16 = p_attr16->uuid.uu.uuid16; - - status = GATT_NO_RESOURCES; - - if (uuid16 == GATT_UUID_PRI_SERVICE || uuid16 == GATT_UUID_SEC_SERVICE) - { - len = p_attr16->p_value->uuid.len; - if (mtu >= p_attr16->p_value->uuid.len) - { - gatt_build_uuid_to_stream(&p, p_attr16->p_value->uuid); - status = GATT_SUCCESS; - } +static tGATT_STATUS read_attr_value(void* p_attr, uint16_t offset, + uint8_t** p_data, bool read_long, + uint16_t mtu, uint16_t* p_len, + tGATT_SEC_FLAG sec_flag, uint8_t key_size) { + uint16_t len = 0, uuid16 = 0; + uint8_t* p = *p_data; + tGATT_STATUS status; + tGATT_ATTR* p_attr16 = (tGATT_ATTR*)p_attr; + + GATT_TRACE_DEBUG( + "read_attr_value uuid=0x%04x perm=0x%02x sec_flag=0x%x offset=%d " + "read_long=%d", + p_attr16->uuid, p_attr16->permission, sec_flag, offset, read_long); + + status = gatts_check_attr_readability((tGATT_ATTR*)p_attr, offset, read_long, + sec_flag, key_size); + + if (status != GATT_SUCCESS) return status; + + if (p_attr16->uuid.len == LEN_UUID_16) uuid16 = p_attr16->uuid.uu.uuid16; + + status = GATT_NO_RESOURCES; + + if (uuid16 == GATT_UUID_PRI_SERVICE || uuid16 == GATT_UUID_SEC_SERVICE) { + len = p_attr16->p_value->uuid.len; + if (mtu >= p_attr16->p_value->uuid.len) { + gatt_build_uuid_to_stream(&p, p_attr16->p_value->uuid); + status = GATT_SUCCESS; + } + } else if (uuid16 == GATT_UUID_CHAR_DECLARE) { + len = (((tGATT_ATTR*)(p_attr16->p_next))->uuid.len == LEN_UUID_16) ? 5 : 19; + + if (mtu >= len) { + UINT8_TO_STREAM(p, p_attr16->p_value->char_decl.property); + UINT16_TO_STREAM(p, p_attr16->p_value->char_decl.char_val_handle); + + if (((tGATT_ATTR*)(p_attr16->p_next))->uuid.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, ((tGATT_ATTR*)(p_attr16->p_next))->uuid.uu.uuid16); + } + /* convert a 32bits UUID to 128 bits */ + else if (((tGATT_ATTR*)(p_attr16->p_next))->uuid.len == LEN_UUID_32) { + gatt_convert_uuid32_to_uuid128( + p, ((tGATT_ATTR*)(p_attr16->p_next))->uuid.uu.uuid32); + p += LEN_UUID_128; + } else { + ARRAY_TO_STREAM(p, ((tGATT_ATTR*)(p_attr16->p_next))->uuid.uu.uuid128, + LEN_UUID_128); + } + status = GATT_SUCCESS; } - else if (uuid16 == GATT_UUID_CHAR_DECLARE) - { - len = (((tGATT_ATTR *)(p_attr16->p_next))->uuid.len == LEN_UUID_16) ? 5 :19; - - if (mtu >= len) - { - UINT8_TO_STREAM(p, p_attr16->p_value->char_decl.property); - UINT16_TO_STREAM(p, p_attr16->p_value->char_decl.char_val_handle); - if (((tGATT_ATTR *)(p_attr16->p_next))->uuid.len == LEN_UUID_16) - { - UINT16_TO_STREAM(p, ((tGATT_ATTR *)(p_attr16->p_next))->uuid.uu.uuid16); - } - /* convert a 32bits UUID to 128 bits */ - else if (((tGATT_ATTR *)(p_attr16->p_next))->uuid.len == LEN_UUID_32) - { - gatt_convert_uuid32_to_uuid128 (p, ((tGATT_ATTR *)(p_attr16->p_next))->uuid.uu.uuid32); - p += LEN_UUID_128; - } - else - { - ARRAY_TO_STREAM (p, ((tGATT_ATTR *)(p_attr16->p_next))->uuid.uu.uuid128, LEN_UUID_128); - } - status = GATT_SUCCESS; - } + } else if (uuid16 == GATT_UUID_INCLUDE_SERVICE) { + if (p_attr16->p_value->incl_handle.service_type.len == LEN_UUID_16) + len = 6; + else + len = 4; - } - else if (uuid16 == GATT_UUID_INCLUDE_SERVICE) - { - if (p_attr16->p_value->incl_handle.service_type.len == LEN_UUID_16) - len = 6; - else - len = 4; - - if (mtu >= len) - { - UINT16_TO_STREAM(p, p_attr16->p_value->incl_handle.s_handle); - UINT16_TO_STREAM(p, p_attr16->p_value->incl_handle.e_handle); + if (mtu >= len) { + UINT16_TO_STREAM(p, p_attr16->p_value->incl_handle.s_handle); + UINT16_TO_STREAM(p, p_attr16->p_value->incl_handle.e_handle); - if (p_attr16->p_value->incl_handle.service_type.len == LEN_UUID_16) - { - UINT16_TO_STREAM(p, p_attr16->p_value->incl_handle.service_type.uu.uuid16); - } - status = GATT_SUCCESS; - } - } - else /* characteristic description or characteristic value */ - { - status = GATT_PENDING; + if (p_attr16->p_value->incl_handle.service_type.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, + p_attr16->p_value->incl_handle.service_type.uu.uuid16); + } + status = GATT_SUCCESS; } - - *p_len = len; - *p_data = p; - return status; + } else /* characteristic description or characteristic value */ + { + status = GATT_PENDING; + } + + *p_len = len; + *p_data = p; + return status; } /******************************************************************************* @@ -317,98 +289,77 @@ static tGATT_STATUS read_attr_value (void *p_attr, * Returns Status of the operation. * ******************************************************************************/ -tGATT_STATUS gatts_db_read_attr_value_by_type (tGATT_TCB *p_tcb, - tGATT_SVC_DB *p_db, - uint8_t op_code, - BT_HDR *p_rsp, - uint16_t s_handle, - uint16_t e_handle, - tBT_UUID type, - uint16_t *p_len, - tGATT_SEC_FLAG sec_flag, - uint8_t key_size, - uint32_t trans_id, - uint16_t *p_cur_handle) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - tGATT_ATTR *p_attr; - uint16_t len = 0; - uint8_t *p = (uint8_t *)(p_rsp + 1) + p_rsp->len + L2CAP_MIN_OFFSET; - tBT_UUID attr_uuid; - - if (p_db && p_db->p_attr_list) - { - p_attr = (tGATT_ATTR *)p_db->p_attr_list; - - while (p_attr && p_attr->handle <= e_handle) - { - attr_uuid = p_attr->uuid; +tGATT_STATUS gatts_db_read_attr_value_by_type( + tGATT_TCB* p_tcb, tGATT_SVC_DB* p_db, uint8_t op_code, BT_HDR* p_rsp, + uint16_t s_handle, uint16_t e_handle, tBT_UUID type, uint16_t* p_len, + tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id, + uint16_t* p_cur_handle) { + tGATT_STATUS status = GATT_NOT_FOUND; + tGATT_ATTR* p_attr; + uint16_t len = 0; + uint8_t* p = (uint8_t*)(p_rsp + 1) + p_rsp->len + L2CAP_MIN_OFFSET; + tBT_UUID attr_uuid; + + if (p_db && p_db->p_attr_list) { + p_attr = (tGATT_ATTR*)p_db->p_attr_list; + + while (p_attr && p_attr->handle <= e_handle) { + attr_uuid = p_attr->uuid; + + if (p_attr->handle >= s_handle && gatt_uuid_compare(type, attr_uuid)) { + if (*p_len <= 2) { + status = GATT_NO_RESOURCES; + break; + } - if (p_attr->handle >= s_handle && gatt_uuid_compare(type, attr_uuid)) - { - if (*p_len <= 2) - { - status = GATT_NO_RESOURCES; - break; - } - - UINT16_TO_STREAM (p, p_attr->handle); - - status = read_attr_value ((void *)p_attr, 0, &p, false, (uint16_t)(*p_len -2), &len, sec_flag, key_size); - - if (status == GATT_PENDING) - { - status = gatts_send_app_read_request(p_tcb, op_code, p_attr->handle, 0, - trans_id, p_attr->gatt_type); - - /* one callback at a time */ - break; - } - else if (status == GATT_SUCCESS) - { - if (p_rsp->offset == 0) - p_rsp->offset = len + 2; - - if (p_rsp->offset == len + 2) - { - p_rsp->len += (len + 2); - *p_len -= (len + 2); - } - else - { - GATT_TRACE_ERROR("format mismatch"); - status = GATT_NO_RESOURCES; - break; - } - } - else - { - *p_cur_handle = p_attr->handle; - break; - } - } - p_attr = (tGATT_ATTR *)p_attr->p_next; + UINT16_TO_STREAM(p, p_attr->handle); + + status = + read_attr_value((void*)p_attr, 0, &p, false, (uint16_t)(*p_len - 2), + &len, sec_flag, key_size); + + if (status == GATT_PENDING) { + status = gatts_send_app_read_request(p_tcb, op_code, p_attr->handle, + 0, trans_id, p_attr->gatt_type); + + /* one callback at a time */ + break; + } else if (status == GATT_SUCCESS) { + if (p_rsp->offset == 0) p_rsp->offset = len + 2; + + if (p_rsp->offset == len + 2) { + p_rsp->len += (len + 2); + *p_len -= (len + 2); + } else { + GATT_TRACE_ERROR("format mismatch"); + status = GATT_NO_RESOURCES; + break; + } + } else { + *p_cur_handle = p_attr->handle; + break; } + } + p_attr = (tGATT_ATTR*)p_attr->p_next; } + } #if (BLE_DELAY_REQUEST_ENC == TRUE) - uint8_t flag = 0; - if (BTM_GetSecurityFlags(p_tcb->peer_bda, &flag)) - { - if ((p_tcb->att_lcid == L2CAP_ATT_CID) && (status == GATT_PENDING) && - (type.uu.uuid16 == GATT_UUID_GAP_DEVICE_NAME)) - { - if ((flag & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_FLAG_ENCRYPTED)) == - BTM_SEC_LINK_KEY_KNOWN) - { - tACL_CONN *p = btm_bda_to_acl(p_tcb->peer_bda, BT_TRANSPORT_LE); - if ((p != NULL) && (p->link_role == BTM_ROLE_MASTER)) - btm_ble_set_encryption(p_tcb->peer_bda, BTM_BLE_SEC_ENCRYPT, p->link_role); - } - } + uint8_t flag = 0; + if (BTM_GetSecurityFlags(p_tcb->peer_bda, &flag)) { + if ((p_tcb->att_lcid == L2CAP_ATT_CID) && (status == GATT_PENDING) && + (type.uu.uuid16 == GATT_UUID_GAP_DEVICE_NAME)) { + if ((flag & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_FLAG_ENCRYPTED)) == + BTM_SEC_LINK_KEY_KNOWN) { + tACL_CONN* p = btm_bda_to_acl(p_tcb->peer_bda, BT_TRANSPORT_LE); + if ((p != NULL) && (p->link_role == BTM_ROLE_MASTER)) + btm_ble_set_encryption(p_tcb->peer_bda, BTM_BLE_SEC_ENCRYPT, + p->link_role); + } } + } #endif - return status; + return status; } /******************************************************************************* @@ -423,39 +374,36 @@ tGATT_STATUS gatts_db_read_attr_value_by_type (tGATT_TCB *p_tcb, * Returns Status of the operation. * ******************************************************************************/ -uint16_t gatts_add_included_service (tGATT_SVC_DB *p_db, uint16_t s_handle, - uint16_t e_handle, tBT_UUID service) -{ - tGATT_ATTR *p_attr; - tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_INCLUDE_SERVICE}}; - - GATT_TRACE_DEBUG("gatts_add_included_service: s_hdl = 0x%04x e_hdl = 0x%04x uuid = 0x%04x", - s_handle, e_handle, service.uu.uuid16); - - if (service.len == 0 || s_handle == 0 || e_handle == 0) - { - GATT_TRACE_ERROR("gatts_add_included_service Illegal Params."); - return 0; - } +uint16_t gatts_add_included_service(tGATT_SVC_DB* p_db, uint16_t s_handle, + uint16_t e_handle, tBT_UUID service) { + tGATT_ATTR* p_attr; + tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_INCLUDE_SERVICE}}; - p_attr = (tGATT_ATTR *)allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ); - if (p_attr != NULL) - { - if (copy_extra_byte_in_db(p_db, (void **)&p_attr->p_value, sizeof(tGATT_INCL_SRVC))) - { - p_attr->p_value->incl_handle.s_handle = s_handle; - p_attr->p_value->incl_handle.e_handle = e_handle; - memcpy(&p_attr->p_value->incl_handle.service_type, &service, sizeof(tBT_UUID)); + GATT_TRACE_DEBUG( + "gatts_add_included_service: s_hdl = 0x%04x e_hdl = 0x%04x uuid = 0x%04x", + s_handle, e_handle, service.uu.uuid16); - return p_attr->handle; - } - else - { - deallocate_attr_in_db(p_db, p_attr); - } + if (service.len == 0 || s_handle == 0 || e_handle == 0) { + GATT_TRACE_ERROR("gatts_add_included_service Illegal Params."); + return 0; + } + + p_attr = (tGATT_ATTR*)allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ); + if (p_attr != NULL) { + if (copy_extra_byte_in_db(p_db, (void**)&p_attr->p_value, + sizeof(tGATT_INCL_SRVC))) { + p_attr->p_value->incl_handle.s_handle = s_handle; + p_attr->p_value->incl_handle.e_handle = e_handle; + memcpy(&p_attr->p_value->incl_handle.service_type, &service, + sizeof(tBT_UUID)); + + return p_attr->handle; + } else { + deallocate_attr_in_db(p_db, p_attr); } + } - return 0; + return 0; } /******************************************************************************* @@ -473,42 +421,39 @@ uint16_t gatts_add_included_service (tGATT_SVC_DB *p_db, uint16_t s_handle, * Returns Status of te operation. * ******************************************************************************/ -uint16_t gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm, - tGATT_CHAR_PROP property, - tBT_UUID * p_char_uuid) -{ - tGATT_ATTR *p_char_decl, *p_char_val; - tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_CHAR_DECLARE}}; - - GATT_TRACE_DEBUG("%s: perm=0x%0x property=0x%0x", __func__, perm, property); - - p_char_decl = (tGATT_ATTR *)allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ); - if (p_char_decl != NULL) - { - if (!copy_extra_byte_in_db(p_db, (void **)&p_char_decl->p_value, sizeof(tGATT_CHAR_DECL))) - { - deallocate_attr_in_db(p_db, p_char_decl); - return 0; - } +uint16_t gatts_add_characteristic(tGATT_SVC_DB* p_db, tGATT_PERM perm, + tGATT_CHAR_PROP property, + tBT_UUID* p_char_uuid) { + tGATT_ATTR *p_char_decl, *p_char_val; + tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_CHAR_DECLARE}}; + + GATT_TRACE_DEBUG("%s: perm=0x%0x property=0x%0x", __func__, perm, property); + + p_char_decl = (tGATT_ATTR*)allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ); + if (p_char_decl != NULL) { + if (!copy_extra_byte_in_db(p_db, (void**)&p_char_decl->p_value, + sizeof(tGATT_CHAR_DECL))) { + deallocate_attr_in_db(p_db, p_char_decl); + return 0; + } - p_char_val = (tGATT_ATTR *)allocate_attr_in_db(p_db, p_char_uuid, perm); + p_char_val = (tGATT_ATTR*)allocate_attr_in_db(p_db, p_char_uuid, perm); - if (p_char_val == NULL) - { - deallocate_attr_in_db(p_db, p_char_decl); - return 0; - } + if (p_char_val == NULL) { + deallocate_attr_in_db(p_db, p_char_decl); + return 0; + } - p_char_decl->p_value->char_decl.property = property; - p_char_decl->p_value->char_decl.char_val_handle = p_char_val->handle; + p_char_decl->p_value->char_decl.property = property; + p_char_decl->p_value->char_decl.char_val_handle = p_char_val->handle; - p_char_val->gatt_type = BTGATT_DB_CHARACTERISTIC; - p_char_val->p_value = NULL; + p_char_val->gatt_type = BTGATT_DB_CHARACTERISTIC; + p_char_val->p_value = NULL; - return p_char_val->handle; - } + return p_char_val->handle; + } - return 0; + return 0; } /******************************************************************************* @@ -520,39 +465,35 @@ uint16_t gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm, * Returns descriptor type. * ******************************************************************************/ -uint8_t gatt_convertchar_descr_type(tBT_UUID *p_descr_uuid) -{ - tBT_UUID std_descr = {LEN_UUID_16, {GATT_UUID_CHAR_EXT_PROP}}; - - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_EXT_DSCPTOR; +uint8_t gatt_convertchar_descr_type(tBT_UUID* p_descr_uuid) { + tBT_UUID std_descr = {LEN_UUID_16, {GATT_UUID_CHAR_EXT_PROP}}; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_USER_DSCPTOR; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) + return GATT_DESCR_EXT_DSCPTOR; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_CLT_CONFIG; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) + return GATT_DESCR_USER_DSCPTOR; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_SVR_CONFIG; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) return GATT_DESCR_CLT_CONFIG; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_PRES_FORMAT; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) return GATT_DESCR_SVR_CONFIG; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_AGGR_FORMAT; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) + return GATT_DESCR_PRES_FORMAT; - std_descr.uu.uuid16 ++; - if (gatt_uuid_compare(std_descr, * p_descr_uuid)) - return GATT_DESCR_VALID_RANGE; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) + return GATT_DESCR_AGGR_FORMAT; + std_descr.uu.uuid16++; + if (gatt_uuid_compare(std_descr, *p_descr_uuid)) + return GATT_DESCR_VALID_RANGE; - return GATT_DESCR_UNKNOWN; + return GATT_DESCR_UNKNOWN; } /******************************************************************************* @@ -569,25 +510,21 @@ uint8_t gatt_convertchar_descr_type(tBT_UUID *p_descr_uuid) * Returns Status of the operation. * ******************************************************************************/ -uint16_t gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm, - tBT_UUID * p_descr_uuid) -{ - tGATT_ATTR *p_char_dscptr; - - GATT_TRACE_DEBUG("gatts_add_char_descr uuid=0x%04x", p_descr_uuid->uu.uuid16); - - /* Add characteristic descriptors */ - p_char_dscptr = (tGATT_ATTR *)allocate_attr_in_db(p_db, p_descr_uuid, perm); - if (p_char_dscptr == NULL) - { - GATT_TRACE_DEBUG("gatts_add_char_descr Fail for adding char descriptors."); - return 0; - } - else - { - p_char_dscptr->gatt_type = BTGATT_DB_DESCRIPTOR; - return p_char_dscptr->handle; - } +uint16_t gatts_add_char_descr(tGATT_SVC_DB* p_db, tGATT_PERM perm, + tBT_UUID* p_descr_uuid) { + tGATT_ATTR* p_char_dscptr; + + GATT_TRACE_DEBUG("gatts_add_char_descr uuid=0x%04x", p_descr_uuid->uu.uuid16); + + /* Add characteristic descriptors */ + p_char_dscptr = (tGATT_ATTR*)allocate_attr_in_db(p_db, p_descr_uuid, perm); + if (p_char_dscptr == NULL) { + GATT_TRACE_DEBUG("gatts_add_char_descr Fail for adding char descriptors."); + return 0; + } else { + p_char_dscptr->gatt_type = BTGATT_DB_DESCRIPTOR; + return p_char_dscptr->handle; + } } /******************************************************************************/ @@ -612,44 +549,35 @@ uint16_t gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm, * Returns Status of operation. * ******************************************************************************/ -tGATT_STATUS gatts_read_attr_value_by_handle(tGATT_TCB *p_tcb, - tGATT_SVC_DB *p_db, - uint8_t op_code, - uint16_t handle, uint16_t offset, - uint8_t *p_value, uint16_t *p_len, - uint16_t mtu, - tGATT_SEC_FLAG sec_flag, - uint8_t key_size, - uint32_t trans_id) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - tGATT_ATTR *p_attr; - uint8_t *pp = p_value; - - if (p_db && p_db->p_attr_list) - { - p_attr = (tGATT_ATTR *)p_db->p_attr_list; - - while (p_attr && handle >= p_attr->handle) - { - if (p_attr->handle == handle) - { - status = read_attr_value (p_attr, offset, &pp, - (bool )(op_code == GATT_REQ_READ_BLOB), - mtu, p_len, sec_flag, key_size); - - if (status == GATT_PENDING) - { - status = gatts_send_app_read_request(p_tcb, op_code, p_attr->handle, offset, - trans_id, p_attr->gatt_type); - } - break; - } - p_attr = (tGATT_ATTR *)p_attr->p_next; +tGATT_STATUS gatts_read_attr_value_by_handle( + tGATT_TCB* p_tcb, tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle, + uint16_t offset, uint8_t* p_value, uint16_t* p_len, uint16_t mtu, + tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id) { + tGATT_STATUS status = GATT_NOT_FOUND; + tGATT_ATTR* p_attr; + uint8_t* pp = p_value; + + if (p_db && p_db->p_attr_list) { + p_attr = (tGATT_ATTR*)p_db->p_attr_list; + + while (p_attr && handle >= p_attr->handle) { + if (p_attr->handle == handle) { + status = read_attr_value(p_attr, offset, &pp, + (bool)(op_code == GATT_REQ_READ_BLOB), mtu, + p_len, sec_flag, key_size); + + if (status == GATT_PENDING) { + status = + gatts_send_app_read_request(p_tcb, op_code, p_attr->handle, + offset, trans_id, p_attr->gatt_type); } + break; + } + p_attr = (tGATT_ATTR*)p_attr->p_next; } + } - return status; + return status; } /******************************************************************************* @@ -671,33 +599,27 @@ tGATT_STATUS gatts_read_attr_value_by_handle(tGATT_TCB *p_tcb, * Returns Status of operation. * ******************************************************************************/ -tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB *p_db, - bool is_long, +tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB* p_db, bool is_long, uint16_t handle, tGATT_SEC_FLAG sec_flag, - uint8_t key_size) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - tGATT_ATTR *p_attr; - - if (p_db && p_db->p_attr_list) - { - p_attr = (tGATT_ATTR *)p_db->p_attr_list; - - while (p_attr && handle >= p_attr->handle) - { - if (p_attr->handle == handle) - { - status = gatts_check_attr_readability (p_attr, 0, - is_long, - sec_flag, key_size); - break; - } - p_attr = (tGATT_ATTR *) p_attr->p_next; - } + uint8_t key_size) { + tGATT_STATUS status = GATT_NOT_FOUND; + tGATT_ATTR* p_attr; + + if (p_db && p_db->p_attr_list) { + p_attr = (tGATT_ATTR*)p_db->p_attr_list; + + while (p_attr && handle >= p_attr->handle) { + if (p_attr->handle == handle) { + status = gatts_check_attr_readability(p_attr, 0, is_long, sec_flag, + key_size); + break; + } + p_attr = (tGATT_ATTR*)p_attr->p_next; } + } - return status; + return status; } /******************************************************************************* * @@ -717,189 +639,176 @@ tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB *p_db, * Returns Status of the operation. * ******************************************************************************/ -tGATT_STATUS gatts_write_attr_perm_check (tGATT_SVC_DB *p_db, uint8_t op_code, - uint16_t handle, uint16_t offset, uint8_t *p_data, - uint16_t len, tGATT_SEC_FLAG sec_flag, uint8_t key_size) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - tGATT_ATTR *p_attr; - uint16_t max_size = 0; - tGATT_PERM perm; - uint16_t min_key_size; - - GATT_TRACE_DEBUG( "%s: op_code=0x%0x handle=0x%04x offset=%d len=%d sec_flag=0x%0x key_size=%d", - __func__, op_code, handle, offset, len, sec_flag, key_size); - - if (p_db != NULL) - { - p_attr = (tGATT_ATTR *) p_db->p_attr_list; - - while (p_attr != NULL) +tGATT_STATUS gatts_write_attr_perm_check(tGATT_SVC_DB* p_db, uint8_t op_code, + uint16_t handle, uint16_t offset, + uint8_t* p_data, uint16_t len, + tGATT_SEC_FLAG sec_flag, + uint8_t key_size) { + tGATT_STATUS status = GATT_NOT_FOUND; + tGATT_ATTR* p_attr; + uint16_t max_size = 0; + tGATT_PERM perm; + uint16_t min_key_size; + + GATT_TRACE_DEBUG( + "%s: op_code=0x%0x handle=0x%04x offset=%d len=%d sec_flag=0x%0x " + "key_size=%d", + __func__, op_code, handle, offset, len, sec_flag, key_size); + + if (p_db != NULL) { + p_attr = (tGATT_ATTR*)p_db->p_attr_list; + + while (p_attr != NULL) { + if (p_attr->handle == handle) { + perm = p_attr->permission; + min_key_size = (((perm & GATT_ENCRYPT_KEY_SIZE_MASK) >> 12)); + if (min_key_size != 0) { + min_key_size += 6; + } + GATT_TRACE_DEBUG("%s: p_attr->permission =0x%04x min_key_size==0x%04x", + __func__, p_attr->permission, min_key_size); + + if ((op_code == GATT_CMD_WRITE || op_code == GATT_REQ_WRITE) && + (perm & GATT_WRITE_SIGNED_PERM)) { + /* use the rules for the mixed security see section 10.2.3*/ + /* use security mode 1 level 2 when the following condition follows */ + /* LE security mode 2 level 1 and LE security mode 1 level 2 */ + if ((perm & GATT_PERM_WRITE_SIGNED) && + (perm & GATT_PERM_WRITE_ENCRYPTED)) { + perm = GATT_PERM_WRITE_ENCRYPTED; + } + /* use security mode 1 level 3 when the following condition follows */ + /* LE security mode 2 level 2 and security mode 1 and LE */ + else if (((perm & GATT_PERM_WRITE_SIGNED_MITM) && + (perm & GATT_PERM_WRITE_ENCRYPTED)) || + /* LE security mode 2 and security mode 1 level 3 */ + ((perm & GATT_WRITE_SIGNED_PERM) && + (perm & GATT_PERM_WRITE_ENC_MITM))) { + perm = GATT_PERM_WRITE_ENC_MITM; + } + } + + if ((op_code == GATT_SIGN_CMD_WRITE) && + !(perm & GATT_WRITE_SIGNED_PERM)) { + status = GATT_WRITE_NOT_PERMIT; + GATT_TRACE_DEBUG("%s: sign cmd write not allowed", __func__); + } + if ((op_code == GATT_SIGN_CMD_WRITE) && + (sec_flag & GATT_SEC_FLAG_ENCRYPTED)) { + status = GATT_INVALID_PDU; + GATT_TRACE_ERROR("%s: Error!! sign cmd write sent on a encypted link", + __func__); + } else if (!(perm & GATT_WRITE_ALLOWED)) { + status = GATT_WRITE_NOT_PERMIT; + GATT_TRACE_ERROR("%s: GATT_WRITE_NOT_PERMIT", __func__); + } + /* require authentication, but not been authenticated */ + else if ((perm & GATT_WRITE_AUTH_REQUIRED) && + !(sec_flag & GATT_SEC_FLAG_LKEY_UNAUTHED)) { + status = GATT_INSUF_AUTHENTICATION; + GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION", __func__); + } else if ((perm & GATT_WRITE_MITM_REQUIRED) && + !(sec_flag & GATT_SEC_FLAG_LKEY_AUTHED)) { + status = GATT_INSUF_AUTHENTICATION; + GATT_TRACE_ERROR("%s: GATT_INSUF_AUTHENTICATION: MITM required", + __func__); + } else if ((perm & GATT_WRITE_ENCRYPTED_PERM) && + !(sec_flag & GATT_SEC_FLAG_ENCRYPTED)) { + status = GATT_INSUF_ENCRYPTION; + GATT_TRACE_ERROR("%s: GATT_INSUF_ENCRYPTION", __func__); + } else if ((perm & GATT_WRITE_ENCRYPTED_PERM) && + (sec_flag & GATT_SEC_FLAG_ENCRYPTED) && + (key_size < min_key_size)) { + status = GATT_INSUF_KEY_SIZE; + GATT_TRACE_ERROR("%s: GATT_INSUF_KEY_SIZE", __func__); + } + /* LE security mode 2 attribute */ + else if (perm & GATT_WRITE_SIGNED_PERM && + op_code != GATT_SIGN_CMD_WRITE && + !(sec_flag & GATT_SEC_FLAG_ENCRYPTED) && + (perm & GATT_WRITE_ALLOWED) == 0) { + status = GATT_INSUF_AUTHENTICATION; + GATT_TRACE_ERROR( + "%s: GATT_INSUF_AUTHENTICATION: LE security mode 2 required", + __func__); + } else /* writable: must be char value declaration or char descritpors + */ { - if (p_attr->handle == handle) - { - perm = p_attr->permission; - min_key_size = (((perm & GATT_ENCRYPT_KEY_SIZE_MASK) >> 12)); - if (min_key_size != 0 ) - { - min_key_size +=6; - } - GATT_TRACE_DEBUG( "%s: p_attr->permission =0x%04x min_key_size==0x%04x", - __func__, p_attr->permission, min_key_size); - - if ((op_code == GATT_CMD_WRITE || op_code == GATT_REQ_WRITE) - && (perm & GATT_WRITE_SIGNED_PERM)) - { - /* use the rules for the mixed security see section 10.2.3*/ - /* use security mode 1 level 2 when the following condition follows */ - /* LE security mode 2 level 1 and LE security mode 1 level 2 */ - if ((perm & GATT_PERM_WRITE_SIGNED) && (perm & GATT_PERM_WRITE_ENCRYPTED)) - { - perm = GATT_PERM_WRITE_ENCRYPTED; - } - /* use security mode 1 level 3 when the following condition follows */ - /* LE security mode 2 level 2 and security mode 1 and LE */ - else if (((perm & GATT_PERM_WRITE_SIGNED_MITM) && (perm & GATT_PERM_WRITE_ENCRYPTED)) || - /* LE security mode 2 and security mode 1 level 3 */ - ((perm & GATT_WRITE_SIGNED_PERM) && (perm & GATT_PERM_WRITE_ENC_MITM))) - { - perm = GATT_PERM_WRITE_ENC_MITM; - } - } - - if ((op_code == GATT_SIGN_CMD_WRITE) && !(perm & GATT_WRITE_SIGNED_PERM)) - { - status = GATT_WRITE_NOT_PERMIT; - GATT_TRACE_DEBUG( "%s: sign cmd write not allowed", __func__); - } - if ((op_code == GATT_SIGN_CMD_WRITE) && (sec_flag & GATT_SEC_FLAG_ENCRYPTED)) - { - status = GATT_INVALID_PDU; - GATT_TRACE_ERROR( "%s: Error!! sign cmd write sent on a encypted link", __func__); - } - else if (!(perm & GATT_WRITE_ALLOWED)) - { - status = GATT_WRITE_NOT_PERMIT; - GATT_TRACE_ERROR( "%s: GATT_WRITE_NOT_PERMIT", __func__); - } - /* require authentication, but not been authenticated */ - else if ((perm & GATT_WRITE_AUTH_REQUIRED ) && !(sec_flag & GATT_SEC_FLAG_LKEY_UNAUTHED)) - { - status = GATT_INSUF_AUTHENTICATION; - GATT_TRACE_ERROR( "%s: GATT_INSUF_AUTHENTICATION", __func__); - } - else if ((perm & GATT_WRITE_MITM_REQUIRED ) && !(sec_flag & GATT_SEC_FLAG_LKEY_AUTHED)) - { - status = GATT_INSUF_AUTHENTICATION; - GATT_TRACE_ERROR( "%s: GATT_INSUF_AUTHENTICATION: MITM required", __func__); - } - else if ((perm & GATT_WRITE_ENCRYPTED_PERM ) && !(sec_flag & GATT_SEC_FLAG_ENCRYPTED)) - { - status = GATT_INSUF_ENCRYPTION; - GATT_TRACE_ERROR( "%s: GATT_INSUF_ENCRYPTION", __func__); - } - else if ((perm & GATT_WRITE_ENCRYPTED_PERM ) && (sec_flag & GATT_SEC_FLAG_ENCRYPTED) && (key_size < min_key_size)) - { - status = GATT_INSUF_KEY_SIZE; - GATT_TRACE_ERROR( "%s: GATT_INSUF_KEY_SIZE", __func__); - } - /* LE security mode 2 attribute */ - else if (perm & GATT_WRITE_SIGNED_PERM && op_code != GATT_SIGN_CMD_WRITE && !(sec_flag & GATT_SEC_FLAG_ENCRYPTED) - && (perm & GATT_WRITE_ALLOWED) == 0) - { - status = GATT_INSUF_AUTHENTICATION; - GATT_TRACE_ERROR( "%s: GATT_INSUF_AUTHENTICATION: LE security mode 2 required", __func__); - } - else /* writable: must be char value declaration or char descritpors */ - { - if(p_attr->uuid.len == LEN_UUID_16) - { - switch (p_attr->uuid.uu.uuid16) - { - case GATT_UUID_CHAR_PRESENT_FORMAT:/* should be readable only */ - case GATT_UUID_CHAR_EXT_PROP:/* should be readable only */ - case GATT_UUID_CHAR_AGG_FORMAT: /* should be readable only */ - case GATT_UUID_CHAR_VALID_RANGE: - status = GATT_WRITE_NOT_PERMIT; - break; - - case GATT_UUID_CHAR_CLIENT_CONFIG: - /* fall through */ - case GATT_UUID_CHAR_SRVR_CONFIG: - max_size = 2; - /* fall through */ - case GATT_UUID_CHAR_DESCRIPTION: - default: /* any other must be character value declaration */ - status = GATT_SUCCESS; - break; - } - } - else if (p_attr->uuid.len == LEN_UUID_128 || - p_attr->uuid.len == LEN_UUID_32) - { - status = GATT_SUCCESS; - } - else - { - status = GATT_INVALID_PDU; - } - - if (p_data == NULL && len > 0) - { - status = GATT_INVALID_PDU; - } - /* these attribute does not allow write blob */ - else if ( (p_attr->uuid.len == LEN_UUID_16) && - (p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG || - p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_SRVR_CONFIG) ) - { - if (op_code == GATT_REQ_PREPARE_WRITE && offset != 0) /* does not allow write blob */ - { - status = GATT_NOT_LONG; - GATT_TRACE_ERROR( "%s: GATT_NOT_LONG", __func__); - } - else if (len != max_size) /* data does not match the required format */ - { - status = GATT_INVALID_ATTR_LEN; - GATT_TRACE_ERROR( "%s: GATT_INVALID_PDU", __func__); - } - else - { - status = GATT_SUCCESS; - } - } - } + if (p_attr->uuid.len == LEN_UUID_16) { + switch (p_attr->uuid.uu.uuid16) { + case GATT_UUID_CHAR_PRESENT_FORMAT: /* should be readable only */ + case GATT_UUID_CHAR_EXT_PROP: /* should be readable only */ + case GATT_UUID_CHAR_AGG_FORMAT: /* should be readable only */ + case GATT_UUID_CHAR_VALID_RANGE: + status = GATT_WRITE_NOT_PERMIT; break; + + case GATT_UUID_CHAR_CLIENT_CONFIG: + /* fall through */ + case GATT_UUID_CHAR_SRVR_CONFIG: + max_size = 2; + /* fall through */ + case GATT_UUID_CHAR_DESCRIPTION: + default: /* any other must be character value declaration */ + status = GATT_SUCCESS; + break; + } + } else if (p_attr->uuid.len == LEN_UUID_128 || + p_attr->uuid.len == LEN_UUID_32) { + status = GATT_SUCCESS; + } else { + status = GATT_INVALID_PDU; + } + + if (p_data == NULL && len > 0) { + status = GATT_INVALID_PDU; + } + /* these attribute does not allow write blob */ + else if ((p_attr->uuid.len == LEN_UUID_16) && + (p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG || + p_attr->uuid.uu.uuid16 == GATT_UUID_CHAR_SRVR_CONFIG)) { + if (op_code == GATT_REQ_PREPARE_WRITE && + offset != 0) /* does not allow write blob */ + { + status = GATT_NOT_LONG; + GATT_TRACE_ERROR("%s: GATT_NOT_LONG", __func__); + } else if (len != + max_size) /* data does not match the required format */ + { + status = GATT_INVALID_ATTR_LEN; + GATT_TRACE_ERROR("%s: GATT_INVALID_PDU", __func__); + } else { + status = GATT_SUCCESS; } - else - p_attr = (tGATT_ATTR *)p_attr->p_next; + } } + break; + } else + p_attr = (tGATT_ATTR*)p_attr->p_next; } + } - return status; + return status; } -static void uuid_to_str(const tBT_UUID bt_uuid, char *str_buf, size_t buf_len) -{ - if (bt_uuid.len == LEN_UUID_16) { - snprintf(str_buf, buf_len, "0x%04x", bt_uuid.uu.uuid16); - } else if (bt_uuid.len == LEN_UUID_32) { - snprintf(str_buf, buf_len, "0x%08x", bt_uuid.uu.uuid32); - } else if (bt_uuid.len == LEN_UUID_128) - { - int x = snprintf(str_buf, buf_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-", - bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14], - bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12], - bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10], - bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]); - snprintf(&str_buf[x], buf_len - x, "%02x%02x-%02x%02x%02x%02x%02x%02x", - bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6], - bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4], - bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2], - bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]); - } - else - snprintf(str_buf, buf_len, "Unknown (len=%d)", bt_uuid.len); +static void uuid_to_str(const tBT_UUID bt_uuid, char* str_buf, size_t buf_len) { + if (bt_uuid.len == LEN_UUID_16) { + snprintf(str_buf, buf_len, "0x%04x", bt_uuid.uu.uuid16); + } else if (bt_uuid.len == LEN_UUID_32) { + snprintf(str_buf, buf_len, "0x%08x", bt_uuid.uu.uuid32); + } else if (bt_uuid.len == LEN_UUID_128) { + int x = snprintf(str_buf, buf_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-", + bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14], + bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12], + bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10], + bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]); + snprintf(&str_buf[x], buf_len - x, "%02x%02x-%02x%02x%02x%02x%02x%02x", + bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6], + bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4], + bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2], + bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]); + } else + snprintf(str_buf, buf_len, "Unknown (len=%d)", bt_uuid.len); } /******************************************************************************* @@ -917,56 +826,55 @@ static void uuid_to_str(const tBT_UUID bt_uuid, char *str_buf, size_t buf_len) * Returns pointer to the newly allocated attribute. * ******************************************************************************/ -static void *allocate_attr_in_db(tGATT_SVC_DB *p_db, tBT_UUID *p_uuid, tGATT_PERM perm) -{ - if (p_uuid == NULL) { - GATT_TRACE_ERROR("illegal UUID"); - return NULL; - } - - if (p_db->end_handle <= p_db->next_handle) { - GATT_TRACE_DEBUG("handle space full. handle_max = %d next_handle = %d", - p_db->end_handle, p_db->next_handle); - return NULL; +static void* allocate_attr_in_db(tGATT_SVC_DB* p_db, tBT_UUID* p_uuid, + tGATT_PERM perm) { + if (p_uuid == NULL) { + GATT_TRACE_ERROR("illegal UUID"); + return NULL; + } + + if (p_db->end_handle <= p_db->next_handle) { + GATT_TRACE_DEBUG("handle space full. handle_max = %d next_handle = %d", + p_db->end_handle, p_db->next_handle); + return NULL; + } + + uint16_t len = sizeof(tGATT_ATTR); + if (p_db->mem_free < len) { + if (!allocate_svc_db_buf(p_db)) { + GATT_TRACE_ERROR("allocate_attr_in_db failed, no resources"); + return NULL; } + } + memset(p_db->p_free_mem, 0, len); - uint16_t len = sizeof(tGATT_ATTR); - if (p_db->mem_free < len) { - if (!allocate_svc_db_buf(p_db)) { - GATT_TRACE_ERROR("allocate_attr_in_db failed, no resources"); - return NULL; - } - } - memset(p_db->p_free_mem, 0, len); + tGATT_ATTR* p_attr = (tGATT_ATTR*)p_db->p_free_mem; + p_db->p_free_mem += len; + p_db->mem_free -= len; - tGATT_ATTR *p_attr = (tGATT_ATTR *) p_db->p_free_mem; - p_db->p_free_mem += len; - p_db->mem_free -= len; + p_attr->handle = p_db->next_handle++; + p_attr->uuid = *p_uuid; + p_attr->permission = perm; + p_attr->p_next = NULL; - p_attr->handle = p_db->next_handle++; - p_attr->uuid = *p_uuid; - p_attr->permission = perm; - p_attr->p_next = NULL; + /* link the attribute record into the end of DB */ + if (p_db->p_attr_list == NULL) + p_db->p_attr_list = p_attr; + else { + tGATT_ATTR* p_last = (tGATT_ATTR*)p_db->p_attr_list; - /* link the attribute record into the end of DB */ - if (p_db->p_attr_list == NULL) - p_db->p_attr_list = p_attr; - else - { - tGATT_ATTR *p_last = (tGATT_ATTR *)p_db->p_attr_list; + while (p_last != NULL && p_last->p_next != NULL) + p_last = (tGATT_ATTR*)p_last->p_next; - while (p_last != NULL && p_last->p_next != NULL) - p_last = (tGATT_ATTR *)p_last->p_next; + p_last->p_next = p_attr; + } - p_last->p_next = p_attr; - } + char uuid_str[37]; + uuid_to_str(p_attr->uuid, uuid_str, sizeof(uuid_str)); + GATT_TRACE_ERROR("=====> handle = [0x%04x] uuid = [%s] perm=0x%02x ", + p_attr->handle, uuid_str, p_attr->permission); - char uuid_str[37]; - uuid_to_str(p_attr->uuid, uuid_str, sizeof(uuid_str)); - GATT_TRACE_ERROR("=====> handle = [0x%04x] uuid = [%s] perm=0x%02x ", - p_attr->handle, uuid_str, p_attr->permission); - - return(void *)p_attr; + return (void*)p_attr; } /******************************************************************************* @@ -981,36 +889,30 @@ static void *allocate_attr_in_db(tGATT_SVC_DB *p_db, tBT_UUID *p_uuid, tGATT_PER * Returns bool : success * ******************************************************************************/ -static bool deallocate_attr_in_db(tGATT_SVC_DB *p_db, void *p_attr) -{ - tGATT_ATTR *p_cur, *p_next; - bool found = false; +static bool deallocate_attr_in_db(tGATT_SVC_DB* p_db, void* p_attr) { + tGATT_ATTR *p_cur, *p_next; + bool found = false; - if (p_db->p_attr_list == NULL) - return found; + if (p_db->p_attr_list == NULL) return found; - p_cur = (tGATT_ATTR *) p_db->p_attr_list; - p_next = (tGATT_ATTR *) p_cur->p_next; + p_cur = (tGATT_ATTR*)p_db->p_attr_list; + p_next = (tGATT_ATTR*)p_cur->p_next; - for (; p_cur != NULL && p_next != NULL; - p_cur = p_next, p_next = (tGATT_ATTR *)p_next->p_next) - { - if (p_next == p_attr) - { - p_cur->p_next = p_next->p_next; - found = true; - } - } - if (p_cur == p_attr && p_cur == p_db->p_attr_list) - { - p_db->p_attr_list = p_cur->p_next; - found = true; + for (; p_cur != NULL && p_next != NULL; + p_cur = p_next, p_next = (tGATT_ATTR*)p_next->p_next) { + if (p_next == p_attr) { + p_cur->p_next = p_next->p_next; + found = true; } - /* else attr not found */ - if ( found) - p_db->next_handle --; - - return found; + } + if (p_cur == p_attr && p_cur == p_db->p_attr_list) { + p_db->p_attr_list = p_cur->p_next; + found = true; + } + /* else attr not found */ + if (found) p_db->next_handle--; + + return found; } /******************************************************************************* @@ -1029,26 +931,24 @@ static bool deallocate_attr_in_db(tGATT_SVC_DB *p_db, void *p_attr) * Returns None. * ******************************************************************************/ -static bool copy_extra_byte_in_db(tGATT_SVC_DB *p_db, void **p_dst, uint16_t len) -{ - uint8_t *p = (uint8_t *)*p_dst; - - if (p_db->mem_free < len) - { - if (!allocate_svc_db_buf(p_db)) - { - GATT_TRACE_ERROR("copy_extra_byte_in_db failed, no resources"); - return false; - } +static bool copy_extra_byte_in_db(tGATT_SVC_DB* p_db, void** p_dst, + uint16_t len) { + uint8_t* p = (uint8_t*)*p_dst; + + if (p_db->mem_free < len) { + if (!allocate_svc_db_buf(p_db)) { + GATT_TRACE_ERROR("copy_extra_byte_in_db failed, no resources"); + return false; } + } - p = p_db->p_free_mem; - p_db->p_free_mem += len; - p_db->mem_free -= len; - memset((void *)p, 0, len); - *p_dst = (void *)p; + p = p_db->p_free_mem; + p_db->p_free_mem += len; + p_db->mem_free -= len; + memset((void*)p, 0, len); + *p_dst = (void*)p; - return true; + return true; } /******************************************************************************* @@ -1061,19 +961,17 @@ static bool copy_extra_byte_in_db(tGATT_SVC_DB *p_db, void **p_dst, uint16_t * Returns true if allocation succeed, otherwise false. * ******************************************************************************/ -static bool allocate_svc_db_buf(tGATT_SVC_DB *p_db) -{ - BT_HDR *p_buf = (BT_HDR *)osi_calloc(GATT_DB_BUF_SIZE); - - GATT_TRACE_DEBUG("%s allocating extra buffer", __func__); +static bool allocate_svc_db_buf(tGATT_SVC_DB* p_db) { + BT_HDR* p_buf = (BT_HDR*)osi_calloc(GATT_DB_BUF_SIZE); - p_db->p_free_mem = (uint8_t *) p_buf; - p_db->mem_free = GATT_DB_BUF_SIZE; + GATT_TRACE_DEBUG("%s allocating extra buffer", __func__); - fixed_queue_enqueue(p_db->svc_buffer, p_buf); + p_db->p_free_mem = (uint8_t*)p_buf; + p_db->mem_free = GATT_DB_BUF_SIZE; - return true; + fixed_queue_enqueue(p_db->svc_buffer, p_buf); + return true; } /******************************************************************************* @@ -1085,51 +983,47 @@ static bool allocate_svc_db_buf(tGATT_SVC_DB *p_db) * Returns status of operation. * ******************************************************************************/ -static tGATT_STATUS gatts_send_app_read_request(tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t handle, uint16_t offset, uint32_t trans_id, - bt_gatt_db_attribute_type_t gatt_type) -{ - tGATTS_DATA sr_data; - uint8_t i_rcb; - tGATT_SR_REG *p_sreg; - uint16_t conn_id; - - i_rcb = gatt_sr_find_i_rcb_by_handle(handle); - p_sreg = &gatt_cb.sr_reg[i_rcb]; - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_sreg->gatt_if); - - if (trans_id == 0) - { - trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); - gatt_sr_update_cback_cnt(p_tcb, p_sreg->gatt_if, true, true); +static tGATT_STATUS gatts_send_app_read_request( + tGATT_TCB* p_tcb, uint8_t op_code, uint16_t handle, uint16_t offset, + uint32_t trans_id, bt_gatt_db_attribute_type_t gatt_type) { + tGATTS_DATA sr_data; + uint8_t i_rcb; + tGATT_SR_REG* p_sreg; + uint16_t conn_id; + + i_rcb = gatt_sr_find_i_rcb_by_handle(handle); + p_sreg = &gatt_cb.sr_reg[i_rcb]; + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_sreg->gatt_if); + + if (trans_id == 0) { + trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); + gatt_sr_update_cback_cnt(p_tcb, p_sreg->gatt_if, true, true); + } + + if (trans_id != 0) { + memset(&sr_data, 0, sizeof(tGATTS_DATA)); + + sr_data.read_req.handle = handle; + sr_data.read_req.is_long = (bool)(op_code == GATT_REQ_READ_BLOB); + sr_data.read_req.offset = offset; + + uint8_t opcode; + if (gatt_type == BTGATT_DB_DESCRIPTOR) { + opcode = GATTS_REQ_TYPE_READ_DESCRIPTOR; + } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) { + opcode = GATTS_REQ_TYPE_READ_CHARACTERISTIC; + } else { + GATT_TRACE_ERROR( + "%s: Attempt to read attribute that's not tied with" + " characteristic or descriptor value.", + __func__); + return GATT_ERROR; } - if (trans_id != 0 ) - { - memset(&sr_data, 0, sizeof(tGATTS_DATA)); - - sr_data.read_req.handle = handle; - sr_data.read_req.is_long = (bool)(op_code == GATT_REQ_READ_BLOB); - sr_data.read_req.offset = offset; - - uint8_t opcode; - if (gatt_type == BTGATT_DB_DESCRIPTOR) { - opcode = GATTS_REQ_TYPE_READ_DESCRIPTOR; - } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) { - opcode = GATTS_REQ_TYPE_READ_CHARACTERISTIC; - } else { - GATT_TRACE_ERROR("%s: Attempt to read attribute that's not tied with" - " characteristic or descriptor value.", __func__); - return GATT_ERROR; - } - - gatt_sr_send_req_callback(conn_id, - trans_id, opcode, &sr_data); - return(tGATT_STATUS) GATT_PENDING; - } - else - return(tGATT_STATUS) GATT_BUSY; /* max pending command, application error */ - + gatt_sr_send_req_callback(conn_id, trans_id, opcode, &sr_data); + return (tGATT_STATUS)GATT_PENDING; + } else + return (tGATT_STATUS)GATT_BUSY; /* max pending command, application error */ } /******************************************************************************* @@ -1144,43 +1038,38 @@ static tGATT_STATUS gatts_send_app_read_request(tGATT_TCB *p_tcb, uint8_t op_cod * Returns void * ******************************************************************************/ -static bool gatts_db_add_service_declaration(tGATT_SVC_DB *p_db, tBT_UUID *p_service, bool is_pri) -{ - tGATT_ATTR *p_attr; - tBT_UUID uuid = {LEN_UUID_16, {0}}; - bool rt = false; - - GATT_TRACE_DEBUG( "add_service_declaration"); - - if (is_pri) - uuid.uu.uuid16 = GATT_UUID_PRI_SERVICE; - else - uuid.uu.uuid16 = GATT_UUID_SEC_SERVICE; - - /* add service declration record */ - p_attr = (tGATT_ATTR *)(allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ)); - if (p_attr != NULL) - { - if (copy_extra_byte_in_db (p_db, (void **)&p_attr->p_value, sizeof(tBT_UUID))) - { - if (p_service->len == LEN_UUID_16) - { - p_attr->p_value->uuid.len = LEN_UUID_16; - p_attr->p_value->uuid.uu.uuid16 = p_service->uu.uuid16; - } - else if (p_service->len == LEN_UUID_32) - { - p_attr->p_value->uuid.len = LEN_UUID_128; - gatt_convert_uuid32_to_uuid128(p_attr->p_value->uuid.uu.uuid128, p_service->uu.uuid32); - } - else - { - p_attr->p_value->uuid.len = LEN_UUID_128; - memcpy(p_attr->p_value->uuid.uu.uuid128, p_service->uu.uuid128, LEN_UUID_128); - } - rt = true; - } - +static bool gatts_db_add_service_declaration(tGATT_SVC_DB* p_db, + tBT_UUID* p_service, bool is_pri) { + tGATT_ATTR* p_attr; + tBT_UUID uuid = {LEN_UUID_16, {0}}; + bool rt = false; + + GATT_TRACE_DEBUG("add_service_declaration"); + + if (is_pri) + uuid.uu.uuid16 = GATT_UUID_PRI_SERVICE; + else + uuid.uu.uuid16 = GATT_UUID_SEC_SERVICE; + + /* add service declration record */ + p_attr = (tGATT_ATTR*)(allocate_attr_in_db(p_db, &uuid, GATT_PERM_READ)); + if (p_attr != NULL) { + if (copy_extra_byte_in_db(p_db, (void**)&p_attr->p_value, + sizeof(tBT_UUID))) { + if (p_service->len == LEN_UUID_16) { + p_attr->p_value->uuid.len = LEN_UUID_16; + p_attr->p_value->uuid.uu.uuid16 = p_service->uu.uuid16; + } else if (p_service->len == LEN_UUID_32) { + p_attr->p_value->uuid.len = LEN_UUID_128; + gatt_convert_uuid32_to_uuid128(p_attr->p_value->uuid.uu.uuid128, + p_service->uu.uuid32); + } else { + p_attr->p_value->uuid.len = LEN_UUID_128; + memcpy(p_attr->p_value->uuid.uu.uuid128, p_service->uu.uuid128, + LEN_UUID_128); + } + rt = true; } - return rt; + } + return rt; } diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h index 0dfac8904..7a75390eb 100644 --- a/stack/gatt/gatt_int.h +++ b/stack/gatt/gatt_int.h @@ -16,16 +16,16 @@ * ******************************************************************************/ -#ifndef GATT_INT_H -#define GATT_INT_H +#ifndef GATT_INT_H +#define GATT_INT_H #include "bt_target.h" -#include "osi/include/fixed_queue.h" #include "bt_trace.h" -#include "gatt_api.h" #include "btm_ble_api.h" #include "btu.h" +#include "gatt_api.h" +#include "osi/include/fixed_queue.h" #include @@ -33,186 +33,177 @@ extern "C" { #endif -#define GATT_CREATE_CONN_ID(tcb_idx, gatt_if) ((uint16_t) ((((uint8_t)(tcb_idx) ) << 8) | ((uint8_t) (gatt_if)))) -#define GATT_GET_TCB_IDX(conn_id) ((uint8_t) (((uint16_t) (conn_id)) >> 8)) -#define GATT_GET_GATT_IF(conn_id) ((tGATT_IF)((uint8_t) (conn_id))) +#define GATT_CREATE_CONN_ID(tcb_idx, gatt_if) \ + ((uint16_t)((((uint8_t)(tcb_idx)) << 8) | ((uint8_t)(gatt_if)))) +#define GATT_GET_TCB_IDX(conn_id) ((uint8_t)(((uint16_t)(conn_id)) >> 8)) +#define GATT_GET_GATT_IF(conn_id) ((tGATT_IF)((uint8_t)(conn_id))) -#define GATT_GET_SR_REG_PTR(index) (&gatt_cb.sr_reg[(uint8_t) (index)]); -#define GATT_TRANS_ID_MAX 0x0fffffff /* 4 MSB is reserved */ +#define GATT_GET_SR_REG_PTR(index) (&gatt_cb.sr_reg[(uint8_t)(index)]); +#define GATT_TRANS_ID_MAX 0x0fffffff /* 4 MSB is reserved */ /* security action for GATT write and read request */ -#define GATT_SEC_NONE 0 -#define GATT_SEC_OK 1 -#define GATT_SEC_SIGN_DATA 2 /* compute the signature for the write cmd */ -#define GATT_SEC_ENCRYPT 3 /* encrypt the link with current key */ -#define GATT_SEC_ENCRYPT_NO_MITM 4 /* unauthenticated encryption or better */ -#define GATT_SEC_ENCRYPT_MITM 5 /* authenticated encryption */ -#define GATT_SEC_ENC_PENDING 6 /* wait for link encryption pending */ +#define GATT_SEC_NONE 0 +#define GATT_SEC_OK 1 +#define GATT_SEC_SIGN_DATA 2 /* compute the signature for the write cmd */ +#define GATT_SEC_ENCRYPT 3 /* encrypt the link with current key */ +#define GATT_SEC_ENCRYPT_NO_MITM 4 /* unauthenticated encryption or better */ +#define GATT_SEC_ENCRYPT_MITM 5 /* authenticated encryption */ +#define GATT_SEC_ENC_PENDING 6 /* wait for link encryption pending */ typedef uint8_t tGATT_SEC_ACTION; +#define GATT_ATTR_OP_SPT_MTU (0x00000001 << 0) +#define GATT_ATTR_OP_SPT_FIND_INFO (0x00000001 << 1) +#define GATT_ATTR_OP_SPT_FIND_BY_TYPE (0x00000001 << 2) +#define GATT_ATTR_OP_SPT_READ_BY_TYPE (0x00000001 << 3) +#define GATT_ATTR_OP_SPT_READ (0x00000001 << 4) +#define GATT_ATTR_OP_SPT_MULT_READ (0x00000001 << 5) +#define GATT_ATTR_OP_SPT_READ_BLOB (0x00000001 << 6) +#define GATT_ATTR_OP_SPT_READ_BY_GRP_TYPE (0x00000001 << 7) +#define GATT_ATTR_OP_SPT_WRITE (0x00000001 << 8) +#define GATT_ATTR_OP_SPT_WRITE_CMD (0x00000001 << 9) +#define GATT_ATTR_OP_SPT_PREP_WRITE (0x00000001 << 10) +#define GATT_ATTR_OP_SPT_EXE_WRITE (0x00000001 << 11) +#define GATT_ATTR_OP_SPT_HDL_VALUE_CONF (0x00000001 << 12) +#define GATT_ATTR_OP_SP_SIGN_WRITE (0x00000001 << 13) -#define GATT_ATTR_OP_SPT_MTU (0x00000001 << 0) -#define GATT_ATTR_OP_SPT_FIND_INFO (0x00000001 << 1) -#define GATT_ATTR_OP_SPT_FIND_BY_TYPE (0x00000001 << 2) -#define GATT_ATTR_OP_SPT_READ_BY_TYPE (0x00000001 << 3) -#define GATT_ATTR_OP_SPT_READ (0x00000001 << 4) -#define GATT_ATTR_OP_SPT_MULT_READ (0x00000001 << 5) -#define GATT_ATTR_OP_SPT_READ_BLOB (0x00000001 << 6) -#define GATT_ATTR_OP_SPT_READ_BY_GRP_TYPE (0x00000001 << 7) -#define GATT_ATTR_OP_SPT_WRITE (0x00000001 << 8) -#define GATT_ATTR_OP_SPT_WRITE_CMD (0x00000001 << 9) -#define GATT_ATTR_OP_SPT_PREP_WRITE (0x00000001 << 10) -#define GATT_ATTR_OP_SPT_EXE_WRITE (0x00000001 << 11) -#define GATT_ATTR_OP_SPT_HDL_VALUE_CONF (0x00000001 << 12) -#define GATT_ATTR_OP_SP_SIGN_WRITE (0x00000001 << 13) +#define GATT_INDEX_INVALID 0xff -#define GATT_INDEX_INVALID 0xff +#define GATT_PENDING_REQ_NONE 0 -#define GATT_PENDING_REQ_NONE 0 +#define GATT_WRITE_CMD_MASK 0xc0 /*0x1100-0000*/ +#define GATT_AUTH_SIGN_MASK 0x80 /*0x1000-0000*/ +#define GATT_AUTH_SIGN_LEN 12 - -#define GATT_WRITE_CMD_MASK 0xc0 /*0x1100-0000*/ -#define GATT_AUTH_SIGN_MASK 0x80 /*0x1000-0000*/ -#define GATT_AUTH_SIGN_LEN 12 - -#define GATT_HDR_SIZE 3 /* 1B opcode + 2B handle */ +#define GATT_HDR_SIZE 3 /* 1B opcode + 2B handle */ /* wait for ATT cmd response timeout value */ -#define GATT_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000) +#define GATT_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000) #define GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS (5 * 1000) -#define GATT_REQ_RETRY_LIMIT 2 +#define GATT_REQ_RETRY_LIMIT 2 /* characteristic descriptor type */ -#define GATT_DESCR_EXT_DSCPTOR 1 /* Characteristic Extended Properties */ -#define GATT_DESCR_USER_DSCPTOR 2 /* Characteristic User Description */ -#define GATT_DESCR_CLT_CONFIG 3 /* Client Characteristic Configuration */ -#define GATT_DESCR_SVR_CONFIG 4 /* Server Characteristic Configuration */ -#define GATT_DESCR_PRES_FORMAT 5 /* Characteristic Presentation Format */ -#define GATT_DESCR_AGGR_FORMAT 6 /* Characteristic Aggregate Format */ -#define GATT_DESCR_VALID_RANGE 7 /* Characteristic Valid Range */ -#define GATT_DESCR_UNKNOWN 0xff - -#define GATT_SEC_FLAG_LKEY_UNAUTHED BTM_SEC_FLAG_LKEY_KNOWN -#define GATT_SEC_FLAG_LKEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED -#define GATT_SEC_FLAG_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED +#define GATT_DESCR_EXT_DSCPTOR 1 /* Characteristic Extended Properties */ +#define GATT_DESCR_USER_DSCPTOR 2 /* Characteristic User Description */ +#define GATT_DESCR_CLT_CONFIG 3 /* Client Characteristic Configuration */ +#define GATT_DESCR_SVR_CONFIG 4 /* Server Characteristic Configuration */ +#define GATT_DESCR_PRES_FORMAT 5 /* Characteristic Presentation Format */ +#define GATT_DESCR_AGGR_FORMAT 6 /* Characteristic Aggregate Format */ +#define GATT_DESCR_VALID_RANGE 7 /* Characteristic Valid Range */ +#define GATT_DESCR_UNKNOWN 0xff + +#define GATT_SEC_FLAG_LKEY_UNAUTHED BTM_SEC_FLAG_LKEY_KNOWN +#define GATT_SEC_FLAG_LKEY_AUTHED BTM_SEC_FLAG_LKEY_AUTHED +#define GATT_SEC_FLAG_ENCRYPTED BTM_SEC_FLAG_ENCRYPTED typedef uint8_t tGATT_SEC_FLAG; /* Find Information Response Type */ -#define GATT_INFO_TYPE_PAIR_16 0x01 -#define GATT_INFO_TYPE_PAIR_128 0x02 +#define GATT_INFO_TYPE_PAIR_16 0x01 +#define GATT_INFO_TYPE_PAIR_128 0x02 /* GATT client FIND_TYPE_VALUE_Request data */ -typedef struct -{ - tBT_UUID uuid; /* type of attribute to be found */ - uint16_t s_handle; /* starting handle */ - uint16_t e_handle; /* ending handle */ - uint16_t value_len; /* length of the attribute value */ - uint8_t value[GATT_MAX_MTU_SIZE]; /* pointer to the attribute value to be found */ +typedef struct { + tBT_UUID uuid; /* type of attribute to be found */ + uint16_t s_handle; /* starting handle */ + uint16_t e_handle; /* ending handle */ + uint16_t value_len; /* length of the attribute value */ + uint8_t + value[GATT_MAX_MTU_SIZE]; /* pointer to the attribute value to be found */ } tGATT_FIND_TYPE_VALUE; /* client request message to ATT protocol */ -typedef union -{ - tGATT_READ_BY_TYPE browse; /* read by type request */ - tGATT_FIND_TYPE_VALUE find_type_value;/* find by type value */ - tGATT_READ_MULTI read_multi; /* read multiple request */ - tGATT_READ_PARTIAL read_blob; /* read blob */ - tGATT_VALUE attr_value; /* write request */ - /* prepare write */ - /* write blob */ - uint16_t handle; /* read, handle value confirmation */ - uint16_t mtu; - tGATT_EXEC_FLAG exec_write; /* execute write */ -}tGATT_CL_MSG; +typedef union { + tGATT_READ_BY_TYPE browse; /* read by type request */ + tGATT_FIND_TYPE_VALUE find_type_value; /* find by type value */ + tGATT_READ_MULTI read_multi; /* read multiple request */ + tGATT_READ_PARTIAL read_blob; /* read blob */ + tGATT_VALUE attr_value; /* write request */ + /* prepare write */ + /* write blob */ + uint16_t handle; /* read, handle value confirmation */ + uint16_t mtu; + tGATT_EXEC_FLAG exec_write; /* execute write */ +} tGATT_CL_MSG; /* error response strucutre */ -typedef struct -{ - uint16_t handle; - uint8_t cmd_code; - uint8_t reason; -}tGATT_ERROR; +typedef struct { + uint16_t handle; + uint8_t cmd_code; + uint8_t reason; +} tGATT_ERROR; /* server response message to ATT protocol */ -typedef union -{ - /* data type member event */ - tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ - /* READ_BLOB, READ_BY_TYPE */ - tGATT_ERROR error; /* ERROR_RSP */ - uint16_t handle; /* WRITE, WRITE_BLOB */ - uint16_t mtu; /* exchange MTU request */ +typedef union { + /* data type member event */ + tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ + /* READ_BLOB, READ_BY_TYPE */ + tGATT_ERROR error; /* ERROR_RSP */ + uint16_t handle; /* WRITE, WRITE_BLOB */ + uint16_t mtu; /* exchange MTU request */ } tGATT_SR_MSG; /* Characteristic declaration attribute value */ -typedef struct -{ - tGATT_CHAR_PROP property; - uint16_t char_val_handle; +typedef struct { + tGATT_CHAR_PROP property; + uint16_t char_val_handle; } tGATT_CHAR_DECL; /* attribute value maintained in the server database */ -typedef union -{ - tBT_UUID uuid; /* service declaration */ - tGATT_CHAR_DECL char_decl; /* characteristic declaration */ - tGATT_INCL_SRVC incl_handle; /* included service */ +typedef union { + tBT_UUID uuid; /* service declaration */ + tGATT_CHAR_DECL char_decl; /* characteristic declaration */ + tGATT_INCL_SRVC incl_handle; /* included service */ } tGATT_ATTR_VALUE; /* Attribute UUID type */ -#define GATT_ATTR_UUID_TYPE_16 0 -#define GATT_ATTR_UUID_TYPE_128 1 -#define GATT_ATTR_UUID_TYPE_32 2 +#define GATT_ATTR_UUID_TYPE_16 0 +#define GATT_ATTR_UUID_TYPE_128 1 +#define GATT_ATTR_UUID_TYPE_32 2 typedef uint8_t tGATT_ATTR_UUID_TYPE; /* 16 bits UUID Attribute in server database */ -typedef struct -{ - void *p_next; /* pointer to the next attribute, - either tGATT_ATTR16 or tGATT_ATTR128 */ - tGATT_ATTR_VALUE *p_value; - tGATT_PERM permission; - uint16_t handle; - tBT_UUID uuid; - bt_gatt_db_attribute_type_t gatt_type; +typedef struct { + void* p_next; /* pointer to the next attribute, + either tGATT_ATTR16 or tGATT_ATTR128 */ + tGATT_ATTR_VALUE* p_value; + tGATT_PERM permission; + uint16_t handle; + tBT_UUID uuid; + bt_gatt_db_attribute_type_t gatt_type; } tGATT_ATTR; /* Service Database definition */ -typedef struct -{ - void *p_attr_list; /* pointer to the first attribute, - either tGATT_ATTR16 or tGATT_ATTR128 */ - uint8_t *p_free_mem; /* Pointer to free memory */ - fixed_queue_t *svc_buffer; /* buffer queue used for service database */ - uint32_t mem_free; /* Memory still available */ - uint16_t end_handle; /* Last handle number */ - uint16_t next_handle; /* Next usable handle value */ +typedef struct { + void* p_attr_list; /* pointer to the first attribute, + either tGATT_ATTR16 or tGATT_ATTR128 */ + uint8_t* p_free_mem; /* Pointer to free memory */ + fixed_queue_t* svc_buffer; /* buffer queue used for service database */ + uint32_t mem_free; /* Memory still available */ + uint16_t end_handle; /* Last handle number */ + uint16_t next_handle; /* Next usable handle value */ } tGATT_SVC_DB; /* Data Structure used for GATT server */ /* A GATT registration record consists of a handle, and 1 or more attributes */ /* A service registration information record consists of beginning and ending */ /* attribute handle, service UUID and a set of GATT server callback. */ -typedef struct -{ - tGATT_SVC_DB *p_db; /* pointer to the service database */ - tBT_UUID app_uuid; /* applicatino UUID */ - uint32_t sdp_handle; /* primamry service SDP handle */ - uint16_t type; /* service type UUID, primary or secondary */ - uint16_t s_hdl; /* service starting handle */ - uint16_t e_hdl; /* service ending handle */ - tGATT_IF gatt_if; /* this service is belong to which application */ - bool in_use; +typedef struct { + tGATT_SVC_DB* p_db; /* pointer to the service database */ + tBT_UUID app_uuid; /* applicatino UUID */ + uint32_t sdp_handle; /* primamry service SDP handle */ + uint16_t type; /* service type UUID, primary or secondary */ + uint16_t s_hdl; /* service starting handle */ + uint16_t e_hdl; /* service ending handle */ + tGATT_IF gatt_if; /* this service is belong to which application */ + bool in_use; } tGATT_SR_REG; /* Data Structure used for GATT server */ @@ -220,27 +211,21 @@ typedef struct /* A service registration information record consists of beginning and ending */ /* attribute handle, service UUID and a set of GATT server callback. */ -typedef struct -{ - tBT_UUID app_uuid128; - tGATT_CBACK app_cb; - tGATT_IF gatt_if; /* one based */ - bool in_use; - uint8_t listening; /* if adv for all has been enabled */ +typedef struct { + tBT_UUID app_uuid128; + tGATT_CBACK app_cb; + tGATT_IF gatt_if; /* one based */ + bool in_use; + uint8_t listening; /* if adv for all has been enabled */ } tGATT_REG; - - - /* command queue for each connection */ -typedef struct -{ - BT_HDR *p_cmd; - uint16_t clcb_idx; - uint8_t op_code; - bool to_send; -}tGATT_CMD_Q; - +typedef struct { + BT_HDR* p_cmd; + uint16_t clcb_idx; + uint8_t op_code; + bool to_send; +} tGATT_CMD_Q; #if GATT_MAX_SR_PROFILES <= 8 typedef uint8_t tGATT_APP_MASK; @@ -251,236 +236,217 @@ typedef uint32_t tGATT_APP_MASK; #endif /* command details for each connection */ -typedef struct -{ - BT_HDR *p_rsp_msg; - uint32_t trans_id; - tGATT_READ_MULTI multi_req; - fixed_queue_t *multi_rsp_q; - uint16_t handle; - uint8_t op_code; - uint8_t status; - uint8_t cback_cnt[GATT_MAX_APPS]; +typedef struct { + BT_HDR* p_rsp_msg; + uint32_t trans_id; + tGATT_READ_MULTI multi_req; + fixed_queue_t* multi_rsp_q; + uint16_t handle; + uint8_t op_code; + uint8_t status; + uint8_t cback_cnt[GATT_MAX_APPS]; } tGATT_SR_CMD; -#define GATT_CH_CLOSE 0 -#define GATT_CH_CLOSING 1 -#define GATT_CH_CONN 2 -#define GATT_CH_CFG 3 -#define GATT_CH_OPEN 4 +#define GATT_CH_CLOSE 0 +#define GATT_CH_CLOSING 1 +#define GATT_CH_CONN 2 +#define GATT_CH_CFG 3 +#define GATT_CH_OPEN 4 typedef uint8_t tGATT_CH_STATE; -#define GATT_GATT_START_HANDLE 1 -#define GATT_GAP_START_HANDLE 20 -#define GATT_APP_START_HANDLE 40 - -typedef struct hdl_cfg -{ - uint16_t gatt_start_hdl; - uint16_t gap_start_hdl; - uint16_t app_start_hdl; -}tGATT_HDL_CFG; - -typedef struct hdl_list_elem -{ - struct hdl_list_elem *p_next; - struct hdl_list_elem *p_prev; - tGATTS_HNDL_RANGE asgn_range; /* assigned handle range */ - tGATT_SVC_DB svc_db; - bool in_use; -}tGATT_HDL_LIST_ELEM; - -typedef struct -{ - tGATT_HDL_LIST_ELEM *p_first; - tGATT_HDL_LIST_ELEM *p_last; - uint16_t count; -}tGATT_HDL_LIST_INFO; - - -typedef struct srv_list_elem -{ - struct srv_list_elem *p_next; - struct srv_list_elem *p_prev; - uint16_t s_hdl; - uint8_t i_sreg; - bool in_use; - bool is_primary; -}tGATT_SRV_LIST_ELEM; - - -typedef struct -{ - tGATT_SRV_LIST_ELEM *p_last_primary; - tGATT_SRV_LIST_ELEM *p_first; - tGATT_SRV_LIST_ELEM *p_last; - uint16_t count; -}tGATT_SRV_LIST_INFO; - -typedef struct -{ - fixed_queue_t *pending_enc_clcb; /* pending encryption channel q */ - tGATT_SEC_ACTION sec_act; - BD_ADDR peer_bda; - tBT_TRANSPORT transport; - uint32_t trans_id; - - uint16_t att_lcid; /* L2CAP channel ID for ATT */ - uint16_t payload_size; - - tGATT_CH_STATE ch_state; - uint8_t ch_flags; - - tGATT_IF app_hold_link[GATT_MAX_APPS]; - - /* server needs */ - /* server response data */ - tGATT_SR_CMD sr_cmd; - uint16_t indicate_handle; - fixed_queue_t *pending_ind_q; - - alarm_t *conf_timer; /* peer confirm to indication timer */ - - uint8_t prep_cnt[GATT_MAX_APPS]; - uint8_t ind_count; - - tGATT_CMD_Q cl_cmd_q[GATT_CL_MAX_LCB]; - alarm_t *ind_ack_timer; /* local app confirm to indication timer */ - uint8_t pending_cl_req; - uint8_t next_slot_inq; /* index of next available slot in queue */ - - bool in_use; - uint8_t tcb_idx; +#define GATT_GATT_START_HANDLE 1 +#define GATT_GAP_START_HANDLE 20 +#define GATT_APP_START_HANDLE 40 + +typedef struct hdl_cfg { + uint16_t gatt_start_hdl; + uint16_t gap_start_hdl; + uint16_t app_start_hdl; +} tGATT_HDL_CFG; + +typedef struct hdl_list_elem { + struct hdl_list_elem* p_next; + struct hdl_list_elem* p_prev; + tGATTS_HNDL_RANGE asgn_range; /* assigned handle range */ + tGATT_SVC_DB svc_db; + bool in_use; +} tGATT_HDL_LIST_ELEM; + +typedef struct { + tGATT_HDL_LIST_ELEM* p_first; + tGATT_HDL_LIST_ELEM* p_last; + uint16_t count; +} tGATT_HDL_LIST_INFO; + +typedef struct srv_list_elem { + struct srv_list_elem* p_next; + struct srv_list_elem* p_prev; + uint16_t s_hdl; + uint8_t i_sreg; + bool in_use; + bool is_primary; +} tGATT_SRV_LIST_ELEM; + +typedef struct { + tGATT_SRV_LIST_ELEM* p_last_primary; + tGATT_SRV_LIST_ELEM* p_first; + tGATT_SRV_LIST_ELEM* p_last; + uint16_t count; +} tGATT_SRV_LIST_INFO; + +typedef struct { + fixed_queue_t* pending_enc_clcb; /* pending encryption channel q */ + tGATT_SEC_ACTION sec_act; + BD_ADDR peer_bda; + tBT_TRANSPORT transport; + uint32_t trans_id; + + uint16_t att_lcid; /* L2CAP channel ID for ATT */ + uint16_t payload_size; + + tGATT_CH_STATE ch_state; + uint8_t ch_flags; + + tGATT_IF app_hold_link[GATT_MAX_APPS]; + + /* server needs */ + /* server response data */ + tGATT_SR_CMD sr_cmd; + uint16_t indicate_handle; + fixed_queue_t* pending_ind_q; + + alarm_t* conf_timer; /* peer confirm to indication timer */ + + uint8_t prep_cnt[GATT_MAX_APPS]; + uint8_t ind_count; + + tGATT_CMD_Q cl_cmd_q[GATT_CL_MAX_LCB]; + alarm_t* ind_ack_timer; /* local app confirm to indication timer */ + uint8_t pending_cl_req; + uint8_t next_slot_inq; /* index of next available slot in queue */ + + bool in_use; + uint8_t tcb_idx; } tGATT_TCB; - /* logic channel */ -typedef struct -{ - uint16_t next_disc_start_hdl; /* starting handle for the next inc srvv discovery */ - tGATT_DISC_RES result; - bool wait_for_read_rsp; +typedef struct { + uint16_t + next_disc_start_hdl; /* starting handle for the next inc srvv discovery */ + tGATT_DISC_RES result; + bool wait_for_read_rsp; } tGATT_READ_INC_UUID128; -typedef struct -{ - tGATT_TCB *p_tcb; /* associated TCB of this CLCB */ - tGATT_REG *p_reg; /* owner of this CLCB */ - uint8_t sccb_idx; - uint8_t *p_attr_buf; /* attribute buffer for read multiple, prepare write */ - tBT_UUID uuid; - uint16_t conn_id; /* connection handle */ - uint16_t clcb_idx; - uint16_t s_handle; /* starting handle of the active request */ - uint16_t e_handle; /* ending handle of the active request */ - uint16_t counter; /* used as offset, attribute length, num of prepare write */ - uint16_t start_offset; - tGATT_AUTH_REQ auth_req; /* authentication requirement */ - uint8_t operation; /* one logic channel can have one operation active */ - uint8_t op_subtype; /* operation subtype */ - uint8_t status; /* operation status */ - bool first_read_blob_after_read; - tGATT_READ_INC_UUID128 read_uuid128; - bool in_use; - alarm_t *gatt_rsp_timer_ent; /* peer response timer */ - uint8_t retry_count; +typedef struct { + tGATT_TCB* p_tcb; /* associated TCB of this CLCB */ + tGATT_REG* p_reg; /* owner of this CLCB */ + uint8_t sccb_idx; + uint8_t* p_attr_buf; /* attribute buffer for read multiple, prepare write */ + tBT_UUID uuid; + uint16_t conn_id; /* connection handle */ + uint16_t clcb_idx; + uint16_t s_handle; /* starting handle of the active request */ + uint16_t e_handle; /* ending handle of the active request */ + uint16_t counter; /* used as offset, attribute length, num of prepare write */ + uint16_t start_offset; + tGATT_AUTH_REQ auth_req; /* authentication requirement */ + uint8_t operation; /* one logic channel can have one operation active */ + uint8_t op_subtype; /* operation subtype */ + uint8_t status; /* operation status */ + bool first_read_blob_after_read; + tGATT_READ_INC_UUID128 read_uuid128; + bool in_use; + alarm_t* gatt_rsp_timer_ent; /* peer response timer */ + uint8_t retry_count; } tGATT_CLCB; -typedef struct -{ - tGATT_CLCB *p_clcb; -}tGATT_PENDING_ENC_CLCB; +typedef struct { tGATT_CLCB* p_clcb; } tGATT_PENDING_ENC_CLCB; -typedef struct -{ - uint16_t clcb_idx; - bool in_use; +typedef struct { + uint16_t clcb_idx; + bool in_use; } tGATT_SCCB; -typedef struct -{ - uint16_t handle; - uint16_t uuid; - uint32_t service_change; -}tGATT_SVC_CHG; - -typedef struct -{ - tGATT_IF gatt_if[GATT_MAX_APPS]; - BD_ADDR remote_bda; - bool in_use; -}tGATT_BG_CONN_DEV; - -#define GATT_SVC_CHANGED_CONNECTING 1 /* wait for connection */ -#define GATT_SVC_CHANGED_SERVICE 2 /* GATT service discovery */ -#define GATT_SVC_CHANGED_CHARACTERISTIC 3 /* service change char discovery */ -#define GATT_SVC_CHANGED_DESCRIPTOR 4 /* service change CCC discoery */ -#define GATT_SVC_CHANGED_CONFIGURE_CCCD 5 /* config CCC */ - -typedef struct -{ - uint16_t conn_id; - bool in_use; - bool connected; - BD_ADDR bda; - tBT_TRANSPORT transport; - - /* GATT service change CCC related variables */ - uint8_t ccc_stage; - uint8_t ccc_result; - uint16_t s_handle; - uint16_t e_handle; -}tGATT_PROFILE_CLCB; - -typedef struct -{ - tGATT_TCB tcb[GATT_MAX_PHY_CHANNEL]; - fixed_queue_t *sign_op_queue; - - tGATT_SR_REG sr_reg[GATT_MAX_SR_PROFILES]; - uint16_t next_handle; /* next available handle */ - tGATT_SVC_CHG gattp_attr; /* GATT profile attribute service change */ - tGATT_IF gatt_if; - tGATT_HDL_LIST_INFO hdl_list_info; - tGATT_HDL_LIST_ELEM hdl_list[GATT_MAX_SR_PROFILES]; - tGATT_SRV_LIST_INFO srv_list_info; - tGATT_SRV_LIST_ELEM srv_list[GATT_MAX_SR_PROFILES]; - - fixed_queue_t *srv_chg_clt_q; /* service change clients queue */ - tGATT_REG cl_rcb[GATT_MAX_APPS]; - tGATT_CLCB clcb[GATT_CL_MAX_LCB]; /* connection link control block*/ - tGATT_SCCB sccb[GATT_MAX_SCCB]; /* sign complete callback function GATT_MAX_SCCB <= GATT_CL_MAX_LCB */ - uint8_t trace_level; - uint16_t def_mtu_size; +typedef struct { + uint16_t handle; + uint16_t uuid; + uint32_t service_change; +} tGATT_SVC_CHG; + +typedef struct { + tGATT_IF gatt_if[GATT_MAX_APPS]; + BD_ADDR remote_bda; + bool in_use; +} tGATT_BG_CONN_DEV; + +#define GATT_SVC_CHANGED_CONNECTING 1 /* wait for connection */ +#define GATT_SVC_CHANGED_SERVICE 2 /* GATT service discovery */ +#define GATT_SVC_CHANGED_CHARACTERISTIC 3 /* service change char discovery */ +#define GATT_SVC_CHANGED_DESCRIPTOR 4 /* service change CCC discoery */ +#define GATT_SVC_CHANGED_CONFIGURE_CCCD 5 /* config CCC */ + +typedef struct { + uint16_t conn_id; + bool in_use; + bool connected; + BD_ADDR bda; + tBT_TRANSPORT transport; + + /* GATT service change CCC related variables */ + uint8_t ccc_stage; + uint8_t ccc_result; + uint16_t s_handle; + uint16_t e_handle; +} tGATT_PROFILE_CLCB; + +typedef struct { + tGATT_TCB tcb[GATT_MAX_PHY_CHANNEL]; + fixed_queue_t* sign_op_queue; + + tGATT_SR_REG sr_reg[GATT_MAX_SR_PROFILES]; + uint16_t next_handle; /* next available handle */ + tGATT_SVC_CHG gattp_attr; /* GATT profile attribute service change */ + tGATT_IF gatt_if; + tGATT_HDL_LIST_INFO hdl_list_info; + tGATT_HDL_LIST_ELEM hdl_list[GATT_MAX_SR_PROFILES]; + tGATT_SRV_LIST_INFO srv_list_info; + tGATT_SRV_LIST_ELEM srv_list[GATT_MAX_SR_PROFILES]; + + fixed_queue_t* srv_chg_clt_q; /* service change clients queue */ + tGATT_REG cl_rcb[GATT_MAX_APPS]; + tGATT_CLCB clcb[GATT_CL_MAX_LCB]; /* connection link control block*/ + tGATT_SCCB sccb[GATT_MAX_SCCB]; /* sign complete callback function + GATT_MAX_SCCB <= GATT_CL_MAX_LCB */ + uint8_t trace_level; + uint16_t def_mtu_size; #if (GATT_CONFORMANCE_TESTING == TRUE) - bool enable_err_rsp; - uint8_t req_op_code; - uint8_t err_status; - uint16_t handle; + bool enable_err_rsp; + uint8_t req_op_code; + uint8_t err_status; + uint16_t handle; #endif - tGATT_PROFILE_CLCB profile_clcb[GATT_MAX_APPS]; - uint16_t handle_of_h_r; /* Handle of the handles reused characteristic value */ - - tGATT_APPL_INFO cb_info; + tGATT_PROFILE_CLCB profile_clcb[GATT_MAX_APPS]; + uint16_t + handle_of_h_r; /* Handle of the handles reused characteristic value */ + tGATT_APPL_INFO cb_info; - - tGATT_HDL_CFG hdl_cfg; - tGATT_BG_CONN_DEV bgconn_dev[GATT_MAX_BG_CONN_DEV]; + tGATT_HDL_CFG hdl_cfg; + tGATT_BG_CONN_DEV bgconn_dev[GATT_MAX_BG_CONN_DEV]; } tGATT_CB; - #define GATT_SIZE_OF_SRV_CHG_HNDL_RANGE 4 /* Global GATT data */ extern tGATT_CB gatt_cb; #if (GATT_CONFORMANCE_TESTING == TRUE) -extern void gatt_set_err_rsp(bool enable, uint8_t req_op_code, uint8_t err_status); +extern void gatt_set_err_rsp(bool enable, uint8_t req_op_code, + uint8_t err_status); #endif #ifdef __cplusplus @@ -488,156 +454,211 @@ extern void gatt_set_err_rsp(bool enable, uint8_t req_op_code, uint8_t err_st #endif /* from gatt_main.cc */ -extern bool gatt_disconnect (tGATT_TCB *p_tcb); -extern bool gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, tBT_TRANSPORT transport, bool opportunistic); -extern bool gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport); -extern void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf); -extern void gatt_update_app_use_link_flag ( tGATT_IF gatt_if, tGATT_TCB *p_tcb, bool is_add, bool check_acl_link); +extern bool gatt_disconnect(tGATT_TCB* p_tcb); +extern bool gatt_act_connect(tGATT_REG* p_reg, BD_ADDR bd_addr, + tBT_TRANSPORT transport, bool opportunistic); +extern bool gatt_connect(BD_ADDR rem_bda, tGATT_TCB* p_tcb, + tBT_TRANSPORT transport); +extern void gatt_data_process(tGATT_TCB* p_tcb, BT_HDR* p_buf); +extern void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, + bool is_add, bool check_acl_link); extern void gatt_profile_db_init(void); -extern void gatt_set_ch_state(tGATT_TCB *p_tcb, tGATT_CH_STATE ch_state); -extern tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB *p_tcb); +extern void gatt_set_ch_state(tGATT_TCB* p_tcb, tGATT_CH_STATE ch_state); +extern tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* p_tcb); extern void gatt_init_srv_chg(void); -extern void gatt_proc_srv_chg (void); -extern void gatt_send_srv_chg_ind (BD_ADDR peer_bda); -extern void gatt_chk_srv_chg(tGATTS_SRV_CHG *p_srv_chg_clt); -extern void gatt_add_a_bonded_dev_for_srv_chg (BD_ADDR bda); +extern void gatt_proc_srv_chg(void); +extern void gatt_send_srv_chg_ind(BD_ADDR peer_bda); +extern void gatt_chk_srv_chg(tGATTS_SRV_CHG* p_srv_chg_clt); +extern void gatt_add_a_bonded_dev_for_srv_chg(BD_ADDR bda); /* from gatt_attr.cc */ extern uint16_t gatt_profile_find_conn_id_by_bd_addr(BD_ADDR bda); - /* Functions provided by att_protocol.cc */ -extern tGATT_STATUS attp_send_cl_msg (tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t op_code, tGATT_CL_MSG *p_msg); -extern BT_HDR *attp_build_sr_msg(tGATT_TCB *p_tcb, uint8_t op_code, tGATT_SR_MSG *p_msg); -extern tGATT_STATUS attp_send_sr_msg (tGATT_TCB *p_tcb, BT_HDR *p_msg); -extern tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB *p_tcb, BT_HDR *p_toL2CAP); +extern tGATT_STATUS attp_send_cl_msg(tGATT_TCB* p_tcb, uint16_t clcb_idx, + uint8_t op_code, tGATT_CL_MSG* p_msg); +extern BT_HDR* attp_build_sr_msg(tGATT_TCB* p_tcb, uint8_t op_code, + tGATT_SR_MSG* p_msg); +extern tGATT_STATUS attp_send_sr_msg(tGATT_TCB* p_tcb, BT_HDR* p_msg); +extern tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB* p_tcb, BT_HDR* p_toL2CAP); /* utility functions */ -extern uint8_t * gatt_dbg_op_name(uint8_t op_code); -extern uint32_t gatt_add_sdp_record (tBT_UUID *p_uuid, uint16_t start_hdl, uint16_t end_hdl); -extern bool gatt_parse_uuid_from_cmd(tBT_UUID *p_uuid, uint16_t len, uint8_t **p_data); -extern uint8_t gatt_build_uuid_to_stream(uint8_t **p_dst, tBT_UUID uuid); -extern bool gatt_uuid_compare(tBT_UUID src, tBT_UUID tar); -extern void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128], uint32_t uuid_32); -extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, uint8_t *p_sec_flag, uint8_t *p_key_size); +extern uint8_t* gatt_dbg_op_name(uint8_t op_code); +extern uint32_t gatt_add_sdp_record(tBT_UUID* p_uuid, uint16_t start_hdl, + uint16_t end_hdl); +extern bool gatt_parse_uuid_from_cmd(tBT_UUID* p_uuid, uint16_t len, + uint8_t** p_data); +extern uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst, tBT_UUID uuid); +extern bool gatt_uuid_compare(tBT_UUID src, tBT_UUID tar); +extern void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128], + uint32_t uuid_32); +extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, + uint8_t* p_sec_flag, uint8_t* p_key_size); extern void gatt_start_rsp_timer(uint16_t clcb_idx); -extern void gatt_start_conf_timer(tGATT_TCB *p_tcb); -extern void gatt_rsp_timeout(void *data); -extern void gatt_indication_confirmation_timeout(void *data); -extern void gatt_ind_ack_timeout(void *data); -extern void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb); -extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB *p_tcb, uint8_t err_code, uint8_t op_code, uint16_t handle, bool deq); +extern void gatt_start_conf_timer(tGATT_TCB* p_tcb); +extern void gatt_rsp_timeout(void* data); +extern void gatt_indication_confirmation_timeout(void* data); +extern void gatt_ind_ack_timeout(void* data); +extern void gatt_start_ind_ack_timer(tGATT_TCB* p_tcb); +extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB* p_tcb, uint8_t err_code, + uint8_t op_code, uint16_t handle, + bool deq); extern void gatt_dbg_display_uuid(tBT_UUID bt_uuid); -extern tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb ); +extern tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb( + tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb); -extern bool gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb); -extern tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda); +extern bool gatt_is_srv_chg_ind_pending(tGATT_TCB* p_tcb); +extern tGATTS_SRV_CHG* gatt_is_bda_in_the_srv_chg_clt_list(BD_ADDR bda); -extern bool gatt_find_the_connected_bda(uint8_t start_idx, BD_ADDR bda, uint8_t *p_found_idx, tBT_TRANSPORT *p_transport); +extern bool gatt_find_the_connected_bda(uint8_t start_idx, BD_ADDR bda, + uint8_t* p_found_idx, + tBT_TRANSPORT* p_transport); extern void gatt_set_srv_chg(void); extern void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr); -extern tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind); -extern void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id); -extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb); +extern tGATT_VALUE* gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind); +extern void gatt_free_srvc_db_buffer_app_id(tBT_UUID* p_app_id); +extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB* p_tcb); /* reserved handle list */ -extern tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_app_id (tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, uint16_t svc_inst); -extern tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_handle(uint16_t handle); -extern tGATT_HDL_LIST_ELEM *gatt_alloc_hdl_buffer(void); -extern void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p); -extern bool gatt_is_last_attribute(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_start, tBT_UUID value); -extern void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO *p_list); -extern bool gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_new); -extern bool gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_remove); -extern bool gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_new); -extern bool gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_remove); -extern tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg); +extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_app_id( + tBT_UUID* p_app_uuid128, tBT_UUID* p_svc_uuid, uint16_t svc_inst); +extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle); +extern tGATT_HDL_LIST_ELEM* gatt_alloc_hdl_buffer(void); +extern void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM* p); +extern bool gatt_is_last_attribute(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_start, + tBT_UUID value); +extern void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO* p_list); +extern bool gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_new); +extern bool gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_remove); +extern bool gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO* p_list, + tGATT_HDL_LIST_ELEM* p_new); +extern bool gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO* p_list, + tGATT_HDL_LIST_ELEM* p_remove); +extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg); /* for background connection */ -extern bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr); -extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV *p_dev, tGATT_IF gatt_if); -extern bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr); +extern bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add, + BD_ADDR bd_addr); +extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if); +extern bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr); extern uint8_t gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr); -extern bool gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF *p_gatt_if); -extern tGATT_BG_CONN_DEV * gatt_find_bg_dev(BD_ADDR remote_bda); +extern bool gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF* p_gatt_if); +extern tGATT_BG_CONN_DEV* gatt_find_bg_dev(BD_ADDR remote_bda); extern void gatt_deregister_bgdev_list(tGATT_IF gatt_if); /* server function */ extern uint8_t gatt_sr_find_i_rcb_by_handle(uint16_t handle); -extern uint8_t gatt_sr_find_i_rcb_by_app_id(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, uint16_t svc_inst); -extern uint8_t gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM *p_list); -extern tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if, uint32_t trans_id, uint8_t op_code, tGATT_STATUS status, tGATTS_RSP *p_msg); -extern void gatt_server_handle_client_req (tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data); -extern void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, - uint8_t op_code, tGATTS_DATA *p_req_data); -extern uint32_t gatt_sr_enqueue_cmd (tGATT_TCB *p_tcb, uint8_t op_code, uint16_t handle); -extern bool gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda); +extern uint8_t gatt_sr_find_i_rcb_by_app_id(tBT_UUID* p_app_uuid128, + tBT_UUID* p_svc_uuid, + uint16_t svc_inst); +extern uint8_t gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM* p_list); +extern tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB* p_tcb, tGATT_IF gatt_if, + uint32_t trans_id, uint8_t op_code, + tGATT_STATUS status, + tGATTS_RSP* p_msg); +extern void gatt_server_handle_client_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data); +extern void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, + uint8_t op_code, tGATTS_DATA* p_req_data); +extern uint32_t gatt_sr_enqueue_cmd(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t handle); +extern bool gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda); /* */ -extern tGATT_REG *gatt_get_regcb (tGATT_IF gatt_if); -extern bool gatt_is_clcb_allocated (uint16_t conn_id); -extern tGATT_CLCB *gatt_clcb_alloc (uint16_t conn_id); -extern void gatt_clcb_dealloc (tGATT_CLCB *p_clcb); - -extern void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB *p_tcb ); -extern bool gatt_sr_is_cback_cnt_zero(tGATT_TCB *p_tcb ); -extern bool gatt_sr_is_prep_cnt_zero(tGATT_TCB *p_tcb ); -extern void gatt_sr_reset_cback_cnt(tGATT_TCB *p_tcb ); -extern void gatt_sr_reset_prep_cnt(tGATT_TCB *p_tcb ); -extern void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc, bool is_reset_first); -extern void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc, bool is_reset_first); - -extern bool gatt_find_app_hold_link(tGATT_TCB *p_tcb, uint8_t start_idx, uint8_t *p_found_idx, tGATT_IF *p_gatt_if); -extern uint8_t gatt_num_apps_hold_link(tGATT_TCB *p_tcb); +extern tGATT_REG* gatt_get_regcb(tGATT_IF gatt_if); +extern bool gatt_is_clcb_allocated(uint16_t conn_id); +extern tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id); +extern void gatt_clcb_dealloc(tGATT_CLCB* p_clcb); + +extern void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB* p_tcb); +extern bool gatt_sr_is_cback_cnt_zero(tGATT_TCB* p_tcb); +extern bool gatt_sr_is_prep_cnt_zero(tGATT_TCB* p_tcb); +extern void gatt_sr_reset_cback_cnt(tGATT_TCB* p_tcb); +extern void gatt_sr_reset_prep_cnt(tGATT_TCB* p_tcb); +extern void gatt_sr_update_cback_cnt(tGATT_TCB* p_tcb, tGATT_IF gatt_if, + bool is_inc, bool is_reset_first); +extern void gatt_sr_update_prep_cnt(tGATT_TCB* p_tcb, tGATT_IF gatt_if, + bool is_inc, bool is_reset_first); + +extern bool gatt_find_app_hold_link(tGATT_TCB* p_tcb, uint8_t start_idx, + uint8_t* p_found_idx, tGATT_IF* p_gatt_if); +extern uint8_t gatt_num_apps_hold_link(tGATT_TCB* p_tcb); extern uint8_t gatt_num_clcb_by_bd_addr(BD_ADDR bda); -extern tGATT_TCB * gatt_find_tcb_by_cid(uint16_t lcid); -extern tGATT_TCB * gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport); -extern tGATT_TCB * gatt_get_tcb_by_idx(uint8_t tcb_idx); -extern tGATT_TCB * gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport); -extern bool gatt_send_ble_burst_data (BD_ADDR remote_bda, BT_HDR *p_buf); +extern tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid); +extern tGATT_TCB* gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, + tBT_TRANSPORT transport); +extern tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx); +extern tGATT_TCB* gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport); +extern bool gatt_send_ble_burst_data(BD_ADDR remote_bda, BT_HDR* p_buf); /* GATT client functions */ -extern void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb); -extern uint8_t gatt_send_write_msg(tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t op_code, uint16_t handle, - uint16_t len, uint16_t offset, uint8_t *p_data); -extern void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason, tBT_TRANSPORT transport); -extern void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data); - -extern void gatt_act_discovery(tGATT_CLCB *p_clcb); -extern void gatt_act_read(tGATT_CLCB *p_clcb, uint16_t offset); -extern void gatt_act_write(tGATT_CLCB *p_clcb, uint8_t sec_act); -extern uint8_t gatt_act_send_browse(tGATT_TCB *p_tcb, uint16_t index, uint8_t op, uint16_t s_handle, uint16_t e_handle, - tBT_UUID uuid); -extern tGATT_CLCB *gatt_cmd_dequeue(tGATT_TCB *p_tcb, uint8_t *p_opcode); -extern bool gatt_cmd_enq(tGATT_TCB *p_tcb, uint16_t clcb_idx, bool to_send, uint8_t op_code, BT_HDR *p_buf); -extern void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data); -extern void gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_EXEC_FLAG flag); +extern void gatt_dequeue_sr_cmd(tGATT_TCB* p_tcb); +extern uint8_t gatt_send_write_msg(tGATT_TCB* p_tcb, uint16_t clcb_idx, + uint8_t op_code, uint16_t handle, + uint16_t len, uint16_t offset, + uint8_t* p_data); +extern void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason, + tBT_TRANSPORT transport); +extern void gatt_end_operation(tGATT_CLCB* p_clcb, tGATT_STATUS status, + void* p_data); + +extern void gatt_act_discovery(tGATT_CLCB* p_clcb); +extern void gatt_act_read(tGATT_CLCB* p_clcb, uint16_t offset); +extern void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act); +extern uint8_t gatt_act_send_browse(tGATT_TCB* p_tcb, uint16_t index, + uint8_t op, uint16_t s_handle, + uint16_t e_handle, tBT_UUID uuid); +extern tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB* p_tcb, uint8_t* p_opcode); +extern bool gatt_cmd_enq(tGATT_TCB* p_tcb, uint16_t clcb_idx, bool to_send, + uint8_t op_code, BT_HDR* p_buf); +extern void gatt_client_handle_server_rsp(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data); +extern void gatt_send_queue_write_cancel(tGATT_TCB* p_tcb, tGATT_CLCB* p_clcb, + tGATT_EXEC_FLAG flag); /* gatt_auth.cc */ -extern bool gatt_security_check_start(tGATT_CLCB *p_clcb); -extern void gatt_verify_signature(tGATT_TCB *p_tcb, BT_HDR *p_buf); -extern tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB *p_clcb ); -extern tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB *p_tcb); -extern tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB *p_tcb); -extern void gatt_set_sec_act(tGATT_TCB *p_tcb, tGATT_SEC_ACTION sec_act); +extern bool gatt_security_check_start(tGATT_CLCB* p_clcb); +extern void gatt_verify_signature(tGATT_TCB* p_tcb, BT_HDR* p_buf); +extern tGATT_SEC_ACTION gatt_determine_sec_act(tGATT_CLCB* p_clcb); +extern tGATT_STATUS gatt_get_link_encrypt_status(tGATT_TCB* p_tcb); +extern tGATT_SEC_ACTION gatt_get_sec_act(tGATT_TCB* p_tcb); +extern void gatt_set_sec_act(tGATT_TCB* p_tcb, tGATT_SEC_ACTION sec_act); /* gatt_db.cc */ -extern bool gatts_init_service_db (tGATT_SVC_DB *p_db, tBT_UUID *p_service, bool is_pri, uint16_t s_hdl, uint16_t num_handle); -extern uint16_t gatts_add_included_service (tGATT_SVC_DB *p_db, uint16_t s_handle, uint16_t e_handle, tBT_UUID service); -extern uint16_t gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm, tGATT_CHAR_PROP property, tBT_UUID *p_char_uuid); -extern uint16_t gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm, tBT_UUID *p_dscp_uuid); -extern tGATT_STATUS gatts_db_read_attr_value_by_type (tGATT_TCB *p_tcb, tGATT_SVC_DB *p_db, uint8_t op_code, BT_HDR *p_rsp, uint16_t s_handle, - uint16_t e_handle, tBT_UUID type, uint16_t *p_len, tGATT_SEC_FLAG sec_flag, uint8_t key_size,uint32_t trans_id, uint16_t *p_cur_handle); -extern tGATT_STATUS gatts_read_attr_value_by_handle(tGATT_TCB *p_tcb,tGATT_SVC_DB *p_db, uint8_t op_code, uint16_t handle, uint16_t offset, - uint8_t *p_value, uint16_t *p_len, uint16_t mtu,tGATT_SEC_FLAG sec_flag,uint8_t key_size,uint32_t trans_id); -extern tGATT_STATUS gatts_write_attr_perm_check (tGATT_SVC_DB *p_db, uint8_t op_code,uint16_t handle, uint16_t offset, uint8_t *p_data, - uint16_t len, tGATT_SEC_FLAG sec_flag, uint8_t key_size); -extern tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB *p_db, bool is_long, uint16_t handle, tGATT_SEC_FLAG sec_flag,uint8_t key_size); -extern void gatts_update_srv_list_elem(uint8_t i_sreg, uint16_t handle, bool is_primary); -extern tBT_UUID * gatts_get_service_uuid (tGATT_SVC_DB *p_db); +extern bool gatts_init_service_db(tGATT_SVC_DB* p_db, tBT_UUID* p_service, + bool is_pri, uint16_t s_hdl, + uint16_t num_handle); +extern uint16_t gatts_add_included_service(tGATT_SVC_DB* p_db, + uint16_t s_handle, uint16_t e_handle, + tBT_UUID service); +extern uint16_t gatts_add_characteristic(tGATT_SVC_DB* p_db, tGATT_PERM perm, + tGATT_CHAR_PROP property, + tBT_UUID* p_char_uuid); +extern uint16_t gatts_add_char_descr(tGATT_SVC_DB* p_db, tGATT_PERM perm, + tBT_UUID* p_dscp_uuid); +extern tGATT_STATUS gatts_db_read_attr_value_by_type( + tGATT_TCB* p_tcb, tGATT_SVC_DB* p_db, uint8_t op_code, BT_HDR* p_rsp, + uint16_t s_handle, uint16_t e_handle, tBT_UUID type, uint16_t* p_len, + tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id, + uint16_t* p_cur_handle); +extern tGATT_STATUS gatts_read_attr_value_by_handle( + tGATT_TCB* p_tcb, tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle, + uint16_t offset, uint8_t* p_value, uint16_t* p_len, uint16_t mtu, + tGATT_SEC_FLAG sec_flag, uint8_t key_size, uint32_t trans_id); +extern tGATT_STATUS gatts_write_attr_perm_check( + tGATT_SVC_DB* p_db, uint8_t op_code, uint16_t handle, uint16_t offset, + uint8_t* p_data, uint16_t len, tGATT_SEC_FLAG sec_flag, uint8_t key_size); +extern tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB* p_db, bool is_long, + uint16_t handle, + tGATT_SEC_FLAG sec_flag, + uint8_t key_size); +extern void gatts_update_srv_list_elem(uint8_t i_sreg, uint16_t handle, + bool is_primary); +extern tBT_UUID* gatts_get_service_uuid(tGATT_SVC_DB* p_db); #endif diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 43d3d3a9f..0a31d574a 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -25,54 +25,56 @@ #include "bt_target.h" #include "bt_common.h" +#include "bt_utils.h" +#include "btm_ble_int.h" +#include "btm_int.h" #include "gatt_int.h" #include "l2c_api.h" -#include "btm_int.h" -#include "btm_ble_int.h" -#include "bt_utils.h" #include "osi/include/osi.h" /* Configuration flags. */ -#define GATT_L2C_CFG_IND_DONE (1<<0) -#define GATT_L2C_CFG_CFM_DONE (1<<1) +#define GATT_L2C_CFG_IND_DONE (1 << 0) +#define GATT_L2C_CFG_CFM_DONE (1 << 1) /* minimum GATT MTU size over BR/EDR link */ -#define GATT_MIN_BR_MTU_SIZE 48 +#define GATT_MIN_BR_MTU_SIZE 48 /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void gatt_le_connect_cback (uint16_t chan, BD_ADDR bd_addr, bool connected, - uint16_t reason, tBT_TRANSPORT transport); -static void gatt_le_data_ind (uint16_t chan, BD_ADDR bd_addr, BT_HDR *p_buf); -static void gatt_le_cong_cback(BD_ADDR remote_bda, bool congest); - -static void gatt_l2cif_connect_ind_cback (BD_ADDR bd_addr, uint16_t l2cap_cid, - uint16_t psm, uint8_t l2cap_id); -static void gatt_l2cif_connect_cfm_cback (uint16_t l2cap_cid, uint16_t result); -static void gatt_l2cif_config_ind_cback (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void gatt_l2cif_config_cfm_cback (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void gatt_l2cif_disconnect_ind_cback (uint16_t l2cap_cid, bool ack_needed); -static void gatt_l2cif_disconnect_cfm_cback (uint16_t l2cap_cid, uint16_t result); -static void gatt_l2cif_data_ind_cback (uint16_t l2cap_cid, BT_HDR *p_msg); -static void gatt_send_conn_cback (tGATT_TCB *p_tcb); -static void gatt_l2cif_congest_cback (uint16_t cid, bool congested); - -static const tL2CAP_APPL_INFO dyn_info = -{ - gatt_l2cif_connect_ind_cback, - gatt_l2cif_connect_cfm_cback, - NULL, - gatt_l2cif_config_ind_cback, - gatt_l2cif_config_cfm_cback, - gatt_l2cif_disconnect_ind_cback, - gatt_l2cif_disconnect_cfm_cback, - NULL, - gatt_l2cif_data_ind_cback, - gatt_l2cif_congest_cback, - NULL -} ; +static void gatt_le_connect_cback(uint16_t chan, BD_ADDR bd_addr, + bool connected, uint16_t reason, + tBT_TRANSPORT transport); +static void gatt_le_data_ind(uint16_t chan, BD_ADDR bd_addr, BT_HDR* p_buf); +static void gatt_le_cong_cback(BD_ADDR remote_bda, bool congest); + +static void gatt_l2cif_connect_ind_cback(BD_ADDR bd_addr, uint16_t l2cap_cid, + uint16_t psm, uint8_t l2cap_id); +static void gatt_l2cif_connect_cfm_cback(uint16_t l2cap_cid, uint16_t result); +static void gatt_l2cif_config_ind_cback(uint16_t l2cap_cid, + tL2CAP_CFG_INFO* p_cfg); +static void gatt_l2cif_config_cfm_cback(uint16_t l2cap_cid, + tL2CAP_CFG_INFO* p_cfg); +static void gatt_l2cif_disconnect_ind_cback(uint16_t l2cap_cid, + bool ack_needed); +static void gatt_l2cif_disconnect_cfm_cback(uint16_t l2cap_cid, + uint16_t result); +static void gatt_l2cif_data_ind_cback(uint16_t l2cap_cid, BT_HDR* p_msg); +static void gatt_send_conn_cback(tGATT_TCB* p_tcb); +static void gatt_l2cif_congest_cback(uint16_t cid, bool congested); + +static const tL2CAP_APPL_INFO dyn_info = {gatt_l2cif_connect_ind_cback, + gatt_l2cif_connect_cfm_cback, + NULL, + gatt_l2cif_config_ind_cback, + gatt_l2cif_config_cfm_cback, + gatt_l2cif_disconnect_ind_cback, + gatt_l2cif_disconnect_cfm_cback, + NULL, + gatt_l2cif_data_ind_cback, + gatt_l2cif_congest_cback, + NULL}; tGATT_CB gatt_cb; @@ -86,55 +88,53 @@ tGATT_CB gatt_cb; * Returns void * ******************************************************************************/ -void gatt_init (void) -{ - tL2CAP_FIXED_CHNL_REG fixed_reg; +void gatt_init(void) { + tL2CAP_FIXED_CHNL_REG fixed_reg; - GATT_TRACE_DEBUG("gatt_init()"); + GATT_TRACE_DEBUG("gatt_init()"); - memset (&gatt_cb, 0, sizeof(tGATT_CB)); - memset (&fixed_reg, 0, sizeof(tL2CAP_FIXED_CHNL_REG)); + memset(&gatt_cb, 0, sizeof(tGATT_CB)); + memset(&fixed_reg, 0, sizeof(tL2CAP_FIXED_CHNL_REG)); #if defined(GATT_INITIAL_TRACE_LEVEL) - gatt_cb.trace_level = GATT_INITIAL_TRACE_LEVEL; + gatt_cb.trace_level = GATT_INITIAL_TRACE_LEVEL; #else - gatt_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + gatt_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif - gatt_cb.def_mtu_size = GATT_DEF_BLE_MTU_SIZE; - gatt_cb.sign_op_queue = fixed_queue_new(SIZE_MAX); - gatt_cb.srv_chg_clt_q = fixed_queue_new(SIZE_MAX); - /* First, register fixed L2CAP channel for ATT over BLE */ - fixed_reg.fixed_chnl_opts.mode = L2CAP_FCR_BASIC_MODE; - fixed_reg.fixed_chnl_opts.max_transmit = 0xFF; - fixed_reg.fixed_chnl_opts.rtrans_tout = 2000; - fixed_reg.fixed_chnl_opts.mon_tout = 12000; - fixed_reg.fixed_chnl_opts.mps = 670; - fixed_reg.fixed_chnl_opts.tx_win_sz = 1; - - fixed_reg.pL2CA_FixedConn_Cb = gatt_le_connect_cback; - fixed_reg.pL2CA_FixedData_Cb = gatt_le_data_ind; - fixed_reg.pL2CA_FixedCong_Cb = gatt_le_cong_cback; /* congestion callback */ - fixed_reg.default_idle_tout = 0xffff; /* 0xffff default idle timeout */ - - L2CA_RegisterFixedChannel (L2CAP_ATT_CID, &fixed_reg); - - /* Now, register with L2CAP for ATT PSM over BR/EDR */ - if (!L2CA_Register (BT_PSM_ATT, (tL2CAP_APPL_INFO *) &dyn_info)) - { - GATT_TRACE_ERROR ("ATT Dynamic Registration failed"); - } - - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_ATT, BTM_SEC_NONE, BT_PSM_ATT, 0, 0); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_ATT, BTM_SEC_NONE, BT_PSM_ATT, 0, 0); - - gatt_cb.hdl_cfg.gatt_start_hdl = GATT_GATT_START_HANDLE; - gatt_cb.hdl_cfg.gap_start_hdl = GATT_GAP_START_HANDLE; - gatt_cb.hdl_cfg.app_start_hdl = GATT_APP_START_HANDLE; - gatt_profile_db_init(); - + gatt_cb.def_mtu_size = GATT_DEF_BLE_MTU_SIZE; + gatt_cb.sign_op_queue = fixed_queue_new(SIZE_MAX); + gatt_cb.srv_chg_clt_q = fixed_queue_new(SIZE_MAX); + /* First, register fixed L2CAP channel for ATT over BLE */ + fixed_reg.fixed_chnl_opts.mode = L2CAP_FCR_BASIC_MODE; + fixed_reg.fixed_chnl_opts.max_transmit = 0xFF; + fixed_reg.fixed_chnl_opts.rtrans_tout = 2000; + fixed_reg.fixed_chnl_opts.mon_tout = 12000; + fixed_reg.fixed_chnl_opts.mps = 670; + fixed_reg.fixed_chnl_opts.tx_win_sz = 1; + + fixed_reg.pL2CA_FixedConn_Cb = gatt_le_connect_cback; + fixed_reg.pL2CA_FixedData_Cb = gatt_le_data_ind; + fixed_reg.pL2CA_FixedCong_Cb = gatt_le_cong_cback; /* congestion callback */ + fixed_reg.default_idle_tout = 0xffff; /* 0xffff default idle timeout */ + + L2CA_RegisterFixedChannel(L2CAP_ATT_CID, &fixed_reg); + + /* Now, register with L2CAP for ATT PSM over BR/EDR */ + if (!L2CA_Register(BT_PSM_ATT, (tL2CAP_APPL_INFO*)&dyn_info)) { + GATT_TRACE_ERROR("ATT Dynamic Registration failed"); + } + + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_ATT, BTM_SEC_NONE, BT_PSM_ATT, + 0, 0); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_ATT, BTM_SEC_NONE, BT_PSM_ATT, + 0, 0); + + gatt_cb.hdl_cfg.gatt_start_hdl = GATT_GATT_START_HANDLE; + gatt_cb.hdl_cfg.gap_start_hdl = GATT_GAP_START_HANDLE; + gatt_cb.hdl_cfg.app_start_hdl = GATT_APP_START_HANDLE; + gatt_profile_db_init(); } - /******************************************************************************* * * Function gatt_free @@ -144,36 +144,33 @@ void gatt_init (void) * Returns void * ******************************************************************************/ -void gatt_free(void) -{ - int i; - GATT_TRACE_DEBUG("gatt_free()"); - - fixed_queue_free(gatt_cb.sign_op_queue, NULL); - gatt_cb.sign_op_queue = NULL; - fixed_queue_free(gatt_cb.srv_chg_clt_q, NULL); - gatt_cb.srv_chg_clt_q = NULL; - for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++) - { - fixed_queue_free(gatt_cb.tcb[i].pending_enc_clcb, NULL); - gatt_cb.tcb[i].pending_enc_clcb = NULL; - - fixed_queue_free(gatt_cb.tcb[i].pending_ind_q, NULL); - gatt_cb.tcb[i].pending_ind_q = NULL; - - alarm_free(gatt_cb.tcb[i].conf_timer); - gatt_cb.tcb[i].conf_timer = NULL; - - alarm_free(gatt_cb.tcb[i].ind_ack_timer); - gatt_cb.tcb[i].ind_ack_timer = NULL; - - fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL); - gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL; - } - for (i = 0; i < GATT_MAX_SR_PROFILES; i++) - { - gatt_free_hdl_buffer(&gatt_cb.hdl_list[i]); - } +void gatt_free(void) { + int i; + GATT_TRACE_DEBUG("gatt_free()"); + + fixed_queue_free(gatt_cb.sign_op_queue, NULL); + gatt_cb.sign_op_queue = NULL; + fixed_queue_free(gatt_cb.srv_chg_clt_q, NULL); + gatt_cb.srv_chg_clt_q = NULL; + for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++) { + fixed_queue_free(gatt_cb.tcb[i].pending_enc_clcb, NULL); + gatt_cb.tcb[i].pending_enc_clcb = NULL; + + fixed_queue_free(gatt_cb.tcb[i].pending_ind_q, NULL); + gatt_cb.tcb[i].pending_ind_q = NULL; + + alarm_free(gatt_cb.tcb[i].conf_timer); + gatt_cb.tcb[i].conf_timer = NULL; + + alarm_free(gatt_cb.tcb[i].ind_ack_timer); + gatt_cb.tcb[i].ind_ack_timer = NULL; + + fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL); + gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL; + } + for (i = 0; i < GATT_MAX_SR_PROFILES; i++) { + gatt_free_hdl_buffer(&gatt_cb.hdl_list[i]); + } } /******************************************************************************* @@ -188,26 +185,21 @@ void gatt_free(void) * Returns true if connection is started, otherwise return false. * ******************************************************************************/ -bool gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport) -{ - bool gatt_ret = false; +bool gatt_connect(BD_ADDR rem_bda, tGATT_TCB* p_tcb, tBT_TRANSPORT transport) { + bool gatt_ret = false; - if (gatt_get_ch_state(p_tcb) != GATT_CH_OPEN) - gatt_set_ch_state(p_tcb, GATT_CH_CONN); + if (gatt_get_ch_state(p_tcb) != GATT_CH_OPEN) + gatt_set_ch_state(p_tcb, GATT_CH_CONN); - if (transport == BT_TRANSPORT_LE) - { - p_tcb->att_lcid = L2CAP_ATT_CID; - gatt_ret = L2CA_ConnectFixedChnl (L2CAP_ATT_CID, rem_bda); - } - else - { - p_tcb->att_lcid = L2CA_ConnectReq(BT_PSM_ATT, rem_bda); - if (p_tcb->att_lcid != 0) - gatt_ret = true; - } + if (transport == BT_TRANSPORT_LE) { + p_tcb->att_lcid = L2CAP_ATT_CID; + gatt_ret = L2CA_ConnectFixedChnl(L2CAP_ATT_CID, rem_bda); + } else { + p_tcb->att_lcid = L2CA_ConnectReq(BT_PSM_ATT, rem_bda); + if (p_tcb->att_lcid != 0) gatt_ret = true; + } - return gatt_ret; + return gatt_ret; } /******************************************************************************* @@ -222,49 +214,37 @@ bool gatt_connect (BD_ADDR rem_bda, tGATT_TCB *p_tcb, tBT_TRANSPORT transport * return false. * ******************************************************************************/ -bool gatt_disconnect (tGATT_TCB *p_tcb) -{ - bool ret = false; - tGATT_CH_STATE ch_state; - - GATT_TRACE_EVENT ("%s", __func__); - - if (p_tcb != NULL) - { - ret = true; - ch_state = gatt_get_ch_state(p_tcb); - if (ch_state != GATT_CH_CLOSING) - { - if (p_tcb->att_lcid == L2CAP_ATT_CID) - { - if (ch_state == GATT_CH_OPEN) - { - /* only LCB exist between remote device and local */ - ret = L2CA_RemoveFixedChnl (L2CAP_ATT_CID, p_tcb->peer_bda); - } - else - { - ret = L2CA_CancelBleConnectReq (p_tcb->peer_bda); - if (!ret) - gatt_set_ch_state(p_tcb, GATT_CH_CLOSE); - } - gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); - } - else - { - if ((ch_state == GATT_CH_OPEN) || (ch_state == GATT_CH_CFG)) - ret = L2CA_DisconnectReq(p_tcb->att_lcid); - else - GATT_TRACE_DEBUG ("%s gatt_disconnect channel not opened", __func__); - } +bool gatt_disconnect(tGATT_TCB* p_tcb) { + bool ret = false; + tGATT_CH_STATE ch_state; + + GATT_TRACE_EVENT("%s", __func__); + + if (p_tcb != NULL) { + ret = true; + ch_state = gatt_get_ch_state(p_tcb); + if (ch_state != GATT_CH_CLOSING) { + if (p_tcb->att_lcid == L2CAP_ATT_CID) { + if (ch_state == GATT_CH_OPEN) { + /* only LCB exist between remote device and local */ + ret = L2CA_RemoveFixedChnl(L2CAP_ATT_CID, p_tcb->peer_bda); + } else { + ret = L2CA_CancelBleConnectReq(p_tcb->peer_bda); + if (!ret) gatt_set_ch_state(p_tcb, GATT_CH_CLOSE); } + gatt_set_ch_state(p_tcb, GATT_CH_CLOSING); + } else { + if ((ch_state == GATT_CH_OPEN) || (ch_state == GATT_CH_CFG)) + ret = L2CA_DisconnectReq(p_tcb->att_lcid); else - { - GATT_TRACE_DEBUG ("%s already in closing state", __func__); - } + GATT_TRACE_DEBUG("%s gatt_disconnect channel not opened", __func__); + } + } else { + GATT_TRACE_DEBUG("%s already in closing state", __func__); } + } - return ret; + return ret; } /******************************************************************************* @@ -276,22 +256,23 @@ bool gatt_disconnect (tGATT_TCB *p_tcb) * Returns true if any modifications are made, false otherwise. * ******************************************************************************/ -bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB *p_tcb, bool is_add) -{ - for (int i=0; iapp_hold_link[i] == 0 && is_add) { - p_tcb->app_hold_link[i] = gatt_if; - GATT_TRACE_DEBUG("%s: added gatt_if=%d idx=%d ", __func__, gatt_if, i); - return true; - } else if (p_tcb->app_hold_link[i] == gatt_if && !is_add) { - p_tcb->app_hold_link[i] = 0; - GATT_TRACE_DEBUG("%s: removed gatt_if=%d idx=%d", __func__, gatt_if, i); - return true; - } +bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb, + bool is_add) { + for (int i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->app_hold_link[i] == 0 && is_add) { + p_tcb->app_hold_link[i] = gatt_if; + GATT_TRACE_DEBUG("%s: added gatt_if=%d idx=%d ", __func__, gatt_if, i); + return true; + } else if (p_tcb->app_hold_link[i] == gatt_if && !is_add) { + p_tcb->app_hold_link[i] = 0; + GATT_TRACE_DEBUG("%s: removed gatt_if=%d idx=%d", __func__, gatt_if, i); + return true; } + } - GATT_TRACE_DEBUG("%s: gatt_if=%d not found; is_add=%d", __func__, gatt_if, is_add); - return false; + GATT_TRACE_DEBUG("%s: gatt_if=%d not found; is_add=%d", __func__, gatt_if, + is_add); + return false; } /******************************************************************************* @@ -305,39 +286,41 @@ bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB *p_tcb, boo * Returns void. * ******************************************************************************/ -void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB *p_tcb, bool is_add, - bool check_acl_link) -{ - GATT_TRACE_DEBUG("%s: is_add=%d chk_link=%d", __func__, is_add, check_acl_link); - - if (!p_tcb) - return; - - // If we make no modification, i.e. kill app that was never connected to a - // device, skip updating the device state. - if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) - return; - - if (!check_acl_link || - p_tcb->att_lcid != L2CAP_ATT_CID || /* only update link idle timer for fixed channel */ - (BTM_GetHCIConnHandle(p_tcb->peer_bda, p_tcb->transport) == GATT_INVALID_ACL_HANDLE)) { - return; - } - - if (is_add) { - GATT_TRACE_DEBUG("%s: disable link idle timer", __func__); - /* acl link is connected disable the idle timeout */ - GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, p_tcb->transport); - } else { - if (!gatt_num_apps_hold_link(p_tcb)) { - /* acl link is connected but no application needs to use the link - so set the timeout value to GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP seconds */ - GATT_TRACE_DEBUG("%s: start link idle timer =%d sec", __func__, - GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP); - GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, - p_tcb->transport); - } +void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, + bool is_add, bool check_acl_link) { + GATT_TRACE_DEBUG("%s: is_add=%d chk_link=%d", __func__, is_add, + check_acl_link); + + if (!p_tcb) return; + + // If we make no modification, i.e. kill app that was never connected to a + // device, skip updating the device state. + if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) return; + + if (!check_acl_link || + p_tcb->att_lcid != + L2CAP_ATT_CID || /* only update link idle timer for fixed channel */ + (BTM_GetHCIConnHandle(p_tcb->peer_bda, p_tcb->transport) == + GATT_INVALID_ACL_HANDLE)) { + return; + } + + if (is_add) { + GATT_TRACE_DEBUG("%s: disable link idle timer", __func__); + /* acl link is connected disable the idle timeout */ + GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, + p_tcb->transport); + } else { + if (!gatt_num_apps_hold_link(p_tcb)) { + /* acl link is connected but no application needs to use the link + so set the timeout value to GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP seconds + */ + GATT_TRACE_DEBUG("%s: start link idle timer =%d sec", __func__, + GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP); + GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, + p_tcb->transport); } + } } /******************************************************************************* @@ -349,64 +332,50 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB *p_tcb, bool i * Returns void. * ******************************************************************************/ -bool gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, - tBT_TRANSPORT transport, bool opportunistic) -{ - bool ret = false; - tGATT_TCB *p_tcb; - uint8_t st; - - p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); - if (p_tcb != NULL) - { - ret = true; - st = gatt_get_ch_state(p_tcb); - - /* before link down, another app try to open a GATT connection */ - if(st == GATT_CH_OPEN && gatt_num_apps_hold_link(p_tcb) == 0 && - transport == BT_TRANSPORT_LE ) - { - if (!gatt_connect(bd_addr, p_tcb, transport)) - ret = false; - } - else if(st == GATT_CH_CLOSING) - { - /* need to complete the closing first */ - ret = false; - } +bool gatt_act_connect(tGATT_REG* p_reg, BD_ADDR bd_addr, + tBT_TRANSPORT transport, bool opportunistic) { + bool ret = false; + tGATT_TCB* p_tcb; + uint8_t st; + + p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); + if (p_tcb != NULL) { + ret = true; + st = gatt_get_ch_state(p_tcb); + + /* before link down, another app try to open a GATT connection */ + if (st == GATT_CH_OPEN && gatt_num_apps_hold_link(p_tcb) == 0 && + transport == BT_TRANSPORT_LE) { + if (!gatt_connect(bd_addr, p_tcb, transport)) ret = false; + } else if (st == GATT_CH_CLOSING) { + /* need to complete the closing first */ + ret = false; } - else - { - p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport); - if (p_tcb != NULL) - { - if (!gatt_connect(bd_addr, p_tcb, transport)) - { - GATT_TRACE_ERROR("gatt_connect failed"); - fixed_queue_free(p_tcb->pending_enc_clcb, NULL); - fixed_queue_free(p_tcb->pending_ind_q, NULL); - memset(p_tcb, 0, sizeof(tGATT_TCB)); - } - else - ret = true; - } - else - { - ret = 0; - GATT_TRACE_ERROR("Max TCB for gatt_if [%d] reached.", p_reg->gatt_if); - } + } else { + p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, transport); + if (p_tcb != NULL) { + if (!gatt_connect(bd_addr, p_tcb, transport)) { + GATT_TRACE_ERROR("gatt_connect failed"); + fixed_queue_free(p_tcb->pending_enc_clcb, NULL); + fixed_queue_free(p_tcb->pending_ind_q, NULL); + memset(p_tcb, 0, sizeof(tGATT_TCB)); + } else + ret = true; + } else { + ret = 0; + GATT_TRACE_ERROR("Max TCB for gatt_if [%d] reached.", p_reg->gatt_if); } + } - if (ret) - { - if (!opportunistic) - gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, false); - else - GATT_TRACE_DEBUG("%s: connection is opportunistic, not updating app usage", - __func__); - } + if (ret) { + if (!opportunistic) + gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, false); + else + GATT_TRACE_DEBUG( + "%s: connection is opportunistic, not updating app usage", __func__); + } - return ret; + return ret; } /******************************************************************************* @@ -418,80 +387,66 @@ bool gatt_act_connect (tGATT_REG *p_reg, BD_ADDR bd_addr, * connected (conn = true)/disconnected (conn = false). * ******************************************************************************/ -static void gatt_le_connect_cback (uint16_t chan, BD_ADDR bd_addr, bool connected, - uint16_t reason, tBT_TRANSPORT transport) -{ - - tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); - bool check_srv_chg = false; - tGATTS_SRV_CHG *p_srv_chg_clt=NULL; - - /* ignore all fixed channel connect/disconnect on BR/EDR link for GATT */ - if (transport == BT_TRANSPORT_BR_EDR) - return; +static void gatt_le_connect_cback(uint16_t chan, BD_ADDR bd_addr, + bool connected, uint16_t reason, + tBT_TRANSPORT transport) { + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); + bool check_srv_chg = false; + tGATTS_SRV_CHG* p_srv_chg_clt = NULL; + + /* ignore all fixed channel connect/disconnect on BR/EDR link for GATT */ + if (transport == BT_TRANSPORT_BR_EDR) return; + + GATT_TRACE_DEBUG( + "GATT ATT protocol channel with BDA: %08x%04x is %s", + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], + (connected) ? "connected" : "disconnected"); + + p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(bd_addr); + if (p_srv_chg_clt != NULL) { + check_srv_chg = true; + } else { + if (btm_sec_is_a_bonded_dev(bd_addr)) + gatt_add_a_bonded_dev_for_srv_chg(bd_addr); + } + + if (connected) { + /* do we have a channel initiating a connection? */ + if (p_tcb) { + /* we are initiating connection */ + if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { + /* send callback */ + gatt_set_ch_state(p_tcb, GATT_CH_OPEN); + p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; + + gatt_send_conn_cback(p_tcb); + } + if (check_srv_chg) gatt_chk_srv_chg(p_srv_chg_clt); + } + /* this is incoming connection or background connection callback */ - GATT_TRACE_DEBUG ("GATT ATT protocol channel with BDA: %08x%04x is %s", - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], (connected) ? "connected" : "disconnected"); + else { + p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_LE); + if (p_tcb != NULL) { + p_tcb->att_lcid = L2CAP_ATT_CID; - p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(bd_addr); - if (p_srv_chg_clt != NULL) - { - check_srv_chg = true; - } - else - { - if (btm_sec_is_a_bonded_dev(bd_addr)) - gatt_add_a_bonded_dev_for_srv_chg(bd_addr); - } + gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - if (connected) - { - /* do we have a channel initiating a connection? */ - if (p_tcb) - { - /* we are initiating connection */ - if ( gatt_get_ch_state(p_tcb) == GATT_CH_CONN) - { - /* send callback */ - gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; - - gatt_send_conn_cback(p_tcb); - } - if (check_srv_chg) - gatt_chk_srv_chg (p_srv_chg_clt); - } - /* this is incoming connection or background connection callback */ + p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; - else - { - p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_LE); - if (p_tcb != NULL) - { - p_tcb->att_lcid = L2CAP_ATT_CID; - - gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - - p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; - - gatt_send_conn_cback (p_tcb); - if (check_srv_chg) - { - gatt_chk_srv_chg (p_srv_chg_clt); - } - } - else - { - GATT_TRACE_ERROR("CCB max out, no rsources"); - } + gatt_send_conn_cback(p_tcb); + if (check_srv_chg) { + gatt_chk_srv_chg(p_srv_chg_clt); } + } else { + GATT_TRACE_ERROR("CCB max out, no rsources"); + } } - else - { - gatt_cleanup_upon_disc(bd_addr, reason, transport); - GATT_TRACE_DEBUG ("ATT disconnected"); - } + } else { + gatt_cleanup_upon_disc(bd_addr, reason, transport); + GATT_TRACE_DEBUG("ATT disconnected"); + } } /******************************************************************************* @@ -504,29 +459,24 @@ static void gatt_le_connect_cback (uint16_t chan, BD_ADDR bd_addr, bool conne * Returns void * ******************************************************************************/ -static void gatt_channel_congestion(tGATT_TCB *p_tcb, bool congested) -{ - uint8_t i = 0; - tGATT_REG *p_reg=NULL; - uint16_t conn_id; - - /* if uncongested, check to see if there is any more pending data */ - if (p_tcb != NULL && congested == false) - { - gatt_cl_send_next_cmd_inq(p_tcb); - } - /* notifying all applications for the connection up event */ - for (i = 0, p_reg = gatt_cb.cl_rcb ; i < GATT_MAX_APPS; i++, p_reg++) - { - if (p_reg->in_use) - { - if (p_reg->app_cb.p_congestion_cb) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); - (*p_reg->app_cb.p_congestion_cb)(conn_id, congested); - } - } +static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) { + uint8_t i = 0; + tGATT_REG* p_reg = NULL; + uint16_t conn_id; + + /* if uncongested, check to see if there is any more pending data */ + if (p_tcb != NULL && congested == false) { + gatt_cl_send_next_cmd_inq(p_tcb); + } + /* notifying all applications for the connection up event */ + for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { + if (p_reg->in_use) { + if (p_reg->app_cb.p_congestion_cb) { + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + (*p_reg->app_cb.p_congestion_cb)(conn_id, congested); + } } + } } /******************************************************************************* @@ -539,15 +489,13 @@ static void gatt_channel_congestion(tGATT_TCB *p_tcb, bool congested) * Returns void * ******************************************************************************/ -static void gatt_le_cong_cback(BD_ADDR remote_bda, bool congested) -{ - tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(remote_bda, BT_TRANSPORT_LE); +static void gatt_le_cong_cback(BD_ADDR remote_bda, bool congested) { + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(remote_bda, BT_TRANSPORT_LE); - /* if uncongested, check to see if there is any more pending data */ - if (p_tcb != NULL) - { - gatt_channel_congestion(p_tcb, congested); - } + /* if uncongested, check to see if there is any more pending data */ + if (p_tcb != NULL) { + gatt_channel_congestion(p_tcb, congested); + } } /******************************************************************************* @@ -566,26 +514,21 @@ static void gatt_le_cong_cback(BD_ADDR remote_bda, bool congested) * Returns void * ******************************************************************************/ -static void gatt_le_data_ind (uint16_t chan, BD_ADDR bd_addr, BT_HDR *p_buf) -{ - tGATT_TCB *p_tcb; - - /* Find CCB based on bd addr */ - if ((p_tcb = gatt_find_tcb_by_addr (bd_addr, BT_TRANSPORT_LE)) != NULL && - gatt_get_ch_state(p_tcb) >= GATT_CH_OPEN) - { - gatt_data_process(p_tcb, p_buf); - } - else - { - osi_free(p_buf); +static void gatt_le_data_ind(uint16_t chan, BD_ADDR bd_addr, BT_HDR* p_buf) { + tGATT_TCB* p_tcb; + + /* Find CCB based on bd addr */ + if ((p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE)) != NULL && + gatt_get_ch_state(p_tcb) >= GATT_CH_OPEN) { + gatt_data_process(p_tcb, p_buf); + } else { + osi_free(p_buf); - if (p_tcb != NULL) - { - GATT_TRACE_WARNING ("ATT - Ignored L2CAP data while in state: %d", - gatt_get_ch_state(p_tcb)); - } + if (p_tcb != NULL) { + GATT_TRACE_WARNING("ATT - Ignored L2CAP data while in state: %d", + gatt_get_ch_state(p_tcb)); } + } } /******************************************************************************* @@ -599,50 +542,44 @@ static void gatt_le_data_ind (uint16_t chan, BD_ADDR bd_addr, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -static void gatt_l2cif_connect_ind_cback (BD_ADDR bd_addr, uint16_t lcid, - UNUSED_ATTR uint16_t psm, uint8_t id) -{ - /* do we already have a control channel for this peer? */ - uint8_t result = L2CAP_CONN_OK; - tL2CAP_CFG_INFO cfg; - tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_BR_EDR); - - GATT_TRACE_ERROR("Connection indication cid = %d", lcid); - /* new connection ? */ - if (p_tcb == NULL) - { - /* allocate tcb */ - p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_BR_EDR); - if (p_tcb == NULL) - { - /* no tcb available, reject L2CAP connection */ - result = L2CAP_CONN_NO_RESOURCES; - } - else - p_tcb->att_lcid = lcid; - - } - else /* existing connection , reject it */ - { - result = L2CAP_CONN_NO_RESOURCES; - } - - /* Send L2CAP connect rsp */ - L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* transition to configuration state */ - gatt_set_ch_state(p_tcb, GATT_CH_CFG); - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = GATT_MAX_MTU_SIZE; - - L2CA_ConfigReq(lcid, &cfg); - } +static void gatt_l2cif_connect_ind_cback(BD_ADDR bd_addr, uint16_t lcid, + UNUSED_ATTR uint16_t psm, uint8_t id) { + /* do we already have a control channel for this peer? */ + uint8_t result = L2CAP_CONN_OK; + tL2CAP_CFG_INFO cfg; + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_BR_EDR); + + GATT_TRACE_ERROR("Connection indication cid = %d", lcid); + /* new connection ? */ + if (p_tcb == NULL) { + /* allocate tcb */ + p_tcb = gatt_allocate_tcb_by_bdaddr(bd_addr, BT_TRANSPORT_BR_EDR); + if (p_tcb == NULL) { + /* no tcb available, reject L2CAP connection */ + result = L2CAP_CONN_NO_RESOURCES; + } else + p_tcb->att_lcid = lcid; + + } else /* existing connection , reject it */ + { + result = L2CAP_CONN_NO_RESOURCES; + } + + /* Send L2CAP connect rsp */ + L2CA_ConnectRsp(bd_addr, id, lcid, result, 0); + + /* if result ok, proceed with connection */ + if (result == L2CAP_CONN_OK) { + /* transition to configuration state */ + gatt_set_ch_state(p_tcb, GATT_CH_CFG); + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = GATT_MAX_MTU_SIZE; + + L2CA_ConfigReq(lcid, &cfg); + } } /******************************************************************************* @@ -655,47 +592,43 @@ static void gatt_l2cif_connect_ind_cback (BD_ADDR bd_addr, uint16_t lcid, * Returns void * ******************************************************************************/ -static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tGATT_TCB *p_tcb; - tL2CAP_CFG_INFO cfg; - - /* look up clcb for this channel */ - p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) +static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) { + tGATT_TCB* p_tcb; + tL2CAP_CFG_INFO cfg; + + /* look up clcb for this channel */ + p_tcb = gatt_find_tcb_by_cid(lcid); + if (p_tcb != NULL) { + GATT_TRACE_DEBUG( + "gatt_l2c_connect_cfm_cback result: %d ch_state: %d, lcid:0x%x", result, + gatt_get_ch_state(p_tcb), p_tcb->att_lcid); + + /* if in correct state */ + if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) { + /* if result successful */ + if (result == L2CAP_CONN_OK) { + /* set channel state */ + gatt_set_ch_state(p_tcb, GATT_CH_CFG); + + /* Send L2CAP config req */ + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = GATT_MAX_MTU_SIZE; + L2CA_ConfigReq(lcid, &cfg); + } + /* else initiating connection failure */ + else { + gatt_cleanup_upon_disc(p_tcb->peer_bda, result, GATT_TRANSPORT_BR_EDR); + } + } else /* wrong state, disconnect it */ { - GATT_TRACE_DEBUG("gatt_l2c_connect_cfm_cback result: %d ch_state: %d, lcid:0x%x", result, gatt_get_ch_state(p_tcb), p_tcb->att_lcid); - - /* if in correct state */ - if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - /* set channel state */ - gatt_set_ch_state(p_tcb, GATT_CH_CFG); - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = GATT_MAX_MTU_SIZE; - L2CA_ConfigReq(lcid, &cfg); - } - /* else initiating connection failure */ - else - { - gatt_cleanup_upon_disc(p_tcb->peer_bda, result, GATT_TRANSPORT_BR_EDR); - } - } - else /* wrong state, disconnect it */ - { - if (result == L2CAP_CONN_OK) - { - /* just in case the peer also accepts our connection - Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } - } + if (result == L2CAP_CONN_OK) { + /* just in case the peer also accepts our connection - Send L2CAP + * disconnect req */ + L2CA_DisconnectReq(lcid); + } } + } } /******************************************************************************* @@ -708,52 +641,43 @@ static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void gatt_l2cif_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tGATT_TCB *p_tcb; - tGATTS_SRV_CHG *p_srv_chg_clt=NULL; - - /* look up clcb for this channel */ - p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) - { - /* if in correct state */ - if ( gatt_get_ch_state(p_tcb) == GATT_CH_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) - { - /* update flags */ - p_tcb->ch_flags |= GATT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE) - { - gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - - p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); - if (p_srv_chg_clt != NULL) - { - gatt_chk_srv_chg(p_srv_chg_clt); - } - else - { - if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) - gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); - } - - /* send callback */ - gatt_send_conn_cback(p_tcb); - } - } - /* else failure */ - else - { - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } +void gatt_l2cif_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tGATT_TCB* p_tcb; + tGATTS_SRV_CHG* p_srv_chg_clt = NULL; + + /* look up clcb for this channel */ + p_tcb = gatt_find_tcb_by_cid(lcid); + if (p_tcb != NULL) { + /* if in correct state */ + if (gatt_get_ch_state(p_tcb) == GATT_CH_CFG) { + /* if result successful */ + if (p_cfg->result == L2CAP_CFG_OK) { + /* update flags */ + p_tcb->ch_flags |= GATT_L2C_CFG_CFM_DONE; + + /* if configuration complete */ + if (p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE) { + gatt_set_ch_state(p_tcb, GATT_CH_OPEN); + + p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); + if (p_srv_chg_clt != NULL) { + gatt_chk_srv_chg(p_srv_chg_clt); + } else { + if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) + gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); + } + + /* send callback */ + gatt_send_conn_cback(p_tcb); } + } + /* else failure */ + else { + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } } + } } /******************************************************************************* @@ -766,52 +690,45 @@ void gatt_l2cif_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void gatt_l2cif_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tGATT_TCB *p_tcb; - tGATTS_SRV_CHG *p_srv_chg_clt=NULL; - /* look up clcb for this channel */ - p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) - { - /* GATT uses the smaller of our MTU and peer's MTU */ - if ( p_cfg->mtu_present && - (p_cfg->mtu >= GATT_MIN_BR_MTU_SIZE && p_cfg->mtu < L2CAP_DEFAULT_MTU)) - p_tcb->payload_size = p_cfg->mtu; - else - p_tcb->payload_size = L2CAP_DEFAULT_MTU; - - /* send L2CAP configure response */ - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->result = L2CAP_CFG_OK; - L2CA_ConfigRsp(lcid, p_cfg); - - /* if first config ind */ - if ((p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE) == 0) - { - /* update flags */ - p_tcb->ch_flags |= GATT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_tcb->ch_flags & GATT_L2C_CFG_CFM_DONE) - { - gatt_set_ch_state(p_tcb, GATT_CH_OPEN); - p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); - if (p_srv_chg_clt != NULL) - { - gatt_chk_srv_chg(p_srv_chg_clt); - } - else - { - if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) - gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); - } - - /* send callback */ - gatt_send_conn_cback(p_tcb); - } +void gatt_l2cif_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tGATT_TCB* p_tcb; + tGATTS_SRV_CHG* p_srv_chg_clt = NULL; + /* look up clcb for this channel */ + p_tcb = gatt_find_tcb_by_cid(lcid); + if (p_tcb != NULL) { + /* GATT uses the smaller of our MTU and peer's MTU */ + if (p_cfg->mtu_present && + (p_cfg->mtu >= GATT_MIN_BR_MTU_SIZE && p_cfg->mtu < L2CAP_DEFAULT_MTU)) + p_tcb->payload_size = p_cfg->mtu; + else + p_tcb->payload_size = L2CAP_DEFAULT_MTU; + + /* send L2CAP configure response */ + memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + p_cfg->result = L2CAP_CFG_OK; + L2CA_ConfigRsp(lcid, p_cfg); + + /* if first config ind */ + if ((p_tcb->ch_flags & GATT_L2C_CFG_IND_DONE) == 0) { + /* update flags */ + p_tcb->ch_flags |= GATT_L2C_CFG_IND_DONE; + + /* if configuration complete */ + if (p_tcb->ch_flags & GATT_L2C_CFG_CFM_DONE) { + gatt_set_ch_state(p_tcb, GATT_CH_OPEN); + p_srv_chg_clt = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); + if (p_srv_chg_clt != NULL) { + gatt_chk_srv_chg(p_srv_chg_clt); + } else { + if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) + gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); } + + /* send callback */ + gatt_send_conn_cback(p_tcb); + } } + } } /******************************************************************************* @@ -824,33 +741,29 @@ void gatt_l2cif_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void gatt_l2cif_disconnect_ind_cback(uint16_t lcid, bool ack_needed) -{ - tGATT_TCB *p_tcb; - uint16_t reason; - - /* look up clcb for this channel */ - p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) - { - if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) - gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); - } - /* if ACL link is still up, no reason is logged, l2cap is disconnect from peer */ - reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); - if (reason == 0) - reason = GATT_CONN_TERMINATE_PEER_USER; - - /* send disconnect callback */ - gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); +void gatt_l2cif_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { + tGATT_TCB* p_tcb; + uint16_t reason; + + /* look up clcb for this channel */ + p_tcb = gatt_find_tcb_by_cid(lcid); + if (p_tcb != NULL) { + if (ack_needed) { + /* send L2CAP disconnect response */ + L2CA_DisconnectRsp(lcid); } + if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) { + if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) + gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); + } + /* if ACL link is still up, no reason is logged, l2cap is disconnect from + * peer */ + reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); + if (reason == 0) reason = GATT_CONN_TERMINATE_PEER_USER; + + /* send disconnect callback */ + gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); + } } /******************************************************************************* @@ -864,30 +777,27 @@ void gatt_l2cif_disconnect_ind_cback(uint16_t lcid, bool ack_needed) * ******************************************************************************/ static void gatt_l2cif_disconnect_cfm_cback(uint16_t lcid, - UNUSED_ATTR uint16_t result) -{ - tGATT_TCB *p_tcb; - uint16_t reason; - - /* look up clcb for this channel */ - p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) - { - /* If the device is not in the service changed client list, add it... */ - if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) - { - if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) - gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); - } + UNUSED_ATTR uint16_t result) { + tGATT_TCB* p_tcb; + uint16_t reason; + + /* look up clcb for this channel */ + p_tcb = gatt_find_tcb_by_cid(lcid); + if (p_tcb != NULL) { + /* If the device is not in the service changed client list, add it... */ + if (gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda) == NULL) { + if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda)) + gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda); + } - /* send disconnect callback */ - /* if ACL link is still up, no reason is logged, l2cap is disconnect from peer */ - reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); - if (reason == 0) - reason = GATT_CONN_TERMINATE_LOCAL_HOST; + /* send disconnect callback */ + /* if ACL link is still up, no reason is logged, l2cap is disconnect from + * peer */ + reason = L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport); + if (reason == 0) reason = GATT_CONN_TERMINATE_LOCAL_HOST; - gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); - } + gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, GATT_TRANSPORT_BR_EDR); + } } /******************************************************************************* @@ -900,19 +810,16 @@ static void gatt_l2cif_disconnect_cfm_cback(uint16_t lcid, * Returns void * ******************************************************************************/ -static void gatt_l2cif_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) -{ - tGATT_TCB *p_tcb; - - /* look up clcb for this channel */ - if ((p_tcb = gatt_find_tcb_by_cid(lcid)) != NULL && - gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) - { - /* process the data */ - gatt_data_process(p_tcb, p_buf); - } - else /* prevent buffer leak */ - osi_free(p_buf); +static void gatt_l2cif_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) { + tGATT_TCB* p_tcb; + + /* look up clcb for this channel */ + if ((p_tcb = gatt_find_tcb_by_cid(lcid)) != NULL && + gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) { + /* process the data */ + gatt_data_process(p_tcb, p_buf); + } else /* prevent buffer leak */ + osi_free(p_buf); } /******************************************************************************* @@ -924,14 +831,12 @@ static void gatt_l2cif_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -static void gatt_l2cif_congest_cback (uint16_t lcid, bool congested) -{ - tGATT_TCB *p_tcb = gatt_find_tcb_by_cid(lcid); +static void gatt_l2cif_congest_cback(uint16_t lcid, bool congested) { + tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); - if (p_tcb != NULL) - { - gatt_channel_congestion(p_tcb, congested); - } + if (p_tcb != NULL) { + gatt_channel_congestion(p_tcb, congested); + } } /******************************************************************************* @@ -944,38 +849,34 @@ static void gatt_l2cif_congest_cback (uint16_t lcid, bool congested) * Returns void * ******************************************************************************/ -static void gatt_send_conn_cback(tGATT_TCB *p_tcb) -{ - uint8_t i; - tGATT_REG *p_reg; - tGATT_BG_CONN_DEV *p_bg_dev=NULL; - uint16_t conn_id; - - p_bg_dev = gatt_find_bg_dev(p_tcb->peer_bda); - - /* notifying all applications for the connection up event */ - for (i = 0, p_reg = gatt_cb.cl_rcb ; i < GATT_MAX_APPS; i++, p_reg++) - { - if (p_reg->in_use) - { - if (p_bg_dev && gatt_is_bg_dev_for_app(p_bg_dev, p_reg->gatt_if)) - gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true); - - if (p_reg->app_cb.p_conn_cb) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); - (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, - true, 0, p_tcb->transport); - } - } - } - - - if (gatt_num_apps_hold_link(p_tcb) && p_tcb->att_lcid == L2CAP_ATT_CID ) - { - /* disable idle timeout if one or more clients are holding the link disable the idle timer */ - GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, p_tcb->transport); +static void gatt_send_conn_cback(tGATT_TCB* p_tcb) { + uint8_t i; + tGATT_REG* p_reg; + tGATT_BG_CONN_DEV* p_bg_dev = NULL; + uint16_t conn_id; + + p_bg_dev = gatt_find_bg_dev(p_tcb->peer_bda); + + /* notifying all applications for the connection up event */ + for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) { + if (p_reg->in_use) { + if (p_bg_dev && gatt_is_bg_dev_for_app(p_bg_dev, p_reg->gatt_if)) + gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true); + + if (p_reg->app_cb.p_conn_cb) { + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, + true, 0, p_tcb->transport); + } } + } + + if (gatt_num_apps_hold_link(p_tcb) && p_tcb->att_lcid == L2CAP_ATT_CID) { + /* disable idle timeout if one or more clients are holding the link disable + * the idle timer */ + GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, + p_tcb->transport); + } } /******************************************************************************* @@ -994,46 +895,36 @@ static void gatt_send_conn_cback(tGATT_TCB *p_tcb) * Returns void * ******************************************************************************/ -void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf) -{ - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint8_t op_code, pseudo_op_code; - uint16_t msg_len; - - if (p_buf->len > 0) - { - msg_len = p_buf->len - 1; - STREAM_TO_UINT8(op_code, p); - - /* remove the two MSBs associated with sign write and write cmd */ - pseudo_op_code = op_code & (~GATT_WRITE_CMD_MASK); - - if (pseudo_op_code < GATT_OP_CODE_MAX) - { - if (op_code == GATT_SIGN_CMD_WRITE) - { - gatt_verify_signature(p_tcb, p_buf); - } - else - { - /* message from client */ - if ((op_code % 2) == 0) - gatt_server_handle_client_req (p_tcb, op_code, msg_len, p); - else - gatt_client_handle_server_rsp (p_tcb, op_code, msg_len, p); - } - } +void gatt_data_process(tGATT_TCB* p_tcb, BT_HDR* p_buf) { + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint8_t op_code, pseudo_op_code; + uint16_t msg_len; + + if (p_buf->len > 0) { + msg_len = p_buf->len - 1; + STREAM_TO_UINT8(op_code, p); + + /* remove the two MSBs associated with sign write and write cmd */ + pseudo_op_code = op_code & (~GATT_WRITE_CMD_MASK); + + if (pseudo_op_code < GATT_OP_CODE_MAX) { + if (op_code == GATT_SIGN_CMD_WRITE) { + gatt_verify_signature(p_tcb, p_buf); + } else { + /* message from client */ + if ((op_code % 2) == 0) + gatt_server_handle_client_req(p_tcb, op_code, msg_len, p); else - { - GATT_TRACE_ERROR ("ATT - Rcvd L2CAP data, unknown cmd: 0x%x", op_code); - } - } - else - { - GATT_TRACE_ERROR ("invalid data length, ignore"); + gatt_client_handle_server_rsp(p_tcb, op_code, msg_len, p); + } + } else { + GATT_TRACE_ERROR("ATT - Rcvd L2CAP data, unknown cmd: 0x%x", op_code); } + } else { + GATT_TRACE_ERROR("invalid data length, ignore"); + } - osi_free(p_buf); + osi_free(p_buf); } /******************************************************************************* @@ -1045,20 +936,19 @@ void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -void gatt_add_a_bonded_dev_for_srv_chg (BD_ADDR bda) -{ - tGATTS_SRV_CHG_REQ req; - tGATTS_SRV_CHG srv_chg_clt; - - memcpy(srv_chg_clt.bda, bda, BD_ADDR_LEN); - srv_chg_clt.srv_changed = false; - if (gatt_add_srv_chg_clt(&srv_chg_clt) != NULL) - { - memcpy(req.srv_chg.bda, bda, BD_ADDR_LEN); - req.srv_chg.srv_changed = false; - if (gatt_cb.cb_info.p_srv_chg_callback) - (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_ADD_CLIENT, &req, NULL); - } +void gatt_add_a_bonded_dev_for_srv_chg(BD_ADDR bda) { + tGATTS_SRV_CHG_REQ req; + tGATTS_SRV_CHG srv_chg_clt; + + memcpy(srv_chg_clt.bda, bda, BD_ADDR_LEN); + srv_chg_clt.srv_changed = false; + if (gatt_add_srv_chg_clt(&srv_chg_clt) != NULL) { + memcpy(req.srv_chg.bda, bda, BD_ADDR_LEN); + req.srv_chg.srv_changed = false; + if (gatt_cb.cb_info.p_srv_chg_callback) + (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_ADD_CLIENT, &req, + NULL); + } } /******************************************************************************* @@ -1071,33 +961,28 @@ void gatt_add_a_bonded_dev_for_srv_chg (BD_ADDR bda) * Returns void * ******************************************************************************/ -void gatt_send_srv_chg_ind (BD_ADDR peer_bda) -{ - uint8_t handle_range[GATT_SIZE_OF_SRV_CHG_HNDL_RANGE]; - uint8_t *p = handle_range; - uint16_t conn_id; - - GATT_TRACE_DEBUG("gatt_send_srv_chg_ind"); - - if (gatt_cb.handle_of_h_r) - { - conn_id = gatt_profile_find_conn_id_by_bd_addr(peer_bda); - if (conn_id != GATT_INVALID_CONN_ID) - { - UINT16_TO_STREAM (p, 1); - UINT16_TO_STREAM (p, 0xFFFF); - GATTS_HandleValueIndication (conn_id, - gatt_cb.handle_of_h_r, - GATT_SIZE_OF_SRV_CHG_HNDL_RANGE, - handle_range); - } - else - { - GATT_TRACE_ERROR("Unable to find conn_id for %08x%04x ", - (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], - (peer_bda[4]<<8)+peer_bda[5] ); - } +void gatt_send_srv_chg_ind(BD_ADDR peer_bda) { + uint8_t handle_range[GATT_SIZE_OF_SRV_CHG_HNDL_RANGE]; + uint8_t* p = handle_range; + uint16_t conn_id; + + GATT_TRACE_DEBUG("gatt_send_srv_chg_ind"); + + if (gatt_cb.handle_of_h_r) { + conn_id = gatt_profile_find_conn_id_by_bd_addr(peer_bda); + if (conn_id != GATT_INVALID_CONN_ID) { + UINT16_TO_STREAM(p, 1); + UINT16_TO_STREAM(p, 0xFFFF); + GATTS_HandleValueIndication(conn_id, gatt_cb.handle_of_h_r, + GATT_SIZE_OF_SRV_CHG_HNDL_RANGE, + handle_range); + } else { + GATT_TRACE_ERROR("Unable to find conn_id for %08x%04x ", + (peer_bda[0] << 24) + (peer_bda[1] << 16) + + (peer_bda[2] << 8) + peer_bda[3], + (peer_bda[4] << 8) + peer_bda[5]); } + } } /******************************************************************************* @@ -1110,14 +995,13 @@ void gatt_send_srv_chg_ind (BD_ADDR peer_bda) * Returns void * ******************************************************************************/ -void gatt_chk_srv_chg(tGATTS_SRV_CHG *p_srv_chg_clt) -{ - GATT_TRACE_DEBUG("gatt_chk_srv_chg srv_changed=%d", p_srv_chg_clt->srv_changed ); +void gatt_chk_srv_chg(tGATTS_SRV_CHG* p_srv_chg_clt) { + GATT_TRACE_DEBUG("gatt_chk_srv_chg srv_changed=%d", + p_srv_chg_clt->srv_changed); - if (p_srv_chg_clt->srv_changed) - { - gatt_send_srv_chg_ind(p_srv_chg_clt->bda); - } + if (p_srv_chg_clt->srv_changed) { + gatt_send_srv_chg_ind(p_srv_chg_clt->bda); + } } /******************************************************************************* @@ -1130,45 +1014,40 @@ void gatt_chk_srv_chg(tGATTS_SRV_CHG *p_srv_chg_clt) * Returns void * ******************************************************************************/ -void gatt_init_srv_chg (void) -{ - tGATTS_SRV_CHG_REQ req; - tGATTS_SRV_CHG_RSP rsp; - bool status; - uint8_t num_clients,i; - tGATTS_SRV_CHG srv_chg_clt; - - GATT_TRACE_DEBUG("gatt_init_srv_chg"); - if (gatt_cb.cb_info.p_srv_chg_callback) - { - status = (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_READ_NUM_CLENTS, NULL, &rsp); - - if (status && rsp.num_clients) - { - GATT_TRACE_DEBUG("gatt_init_srv_chg num_srv_chg_clt_clients=%d", rsp.num_clients); - num_clients = rsp.num_clients; - i = 1; /* use one based index */ - while ((i <= num_clients) && status) - { - req.client_read_index = i; - status = (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_READ_CLENT, &req, &rsp); - if (status == true) - { - memcpy(&srv_chg_clt, &rsp.srv_chg ,sizeof(tGATTS_SRV_CHG)); - if (gatt_add_srv_chg_clt(&srv_chg_clt) == NULL) - { - GATT_TRACE_ERROR("Unable to add a service change client"); - status = false; - } - } - i++; - } +void gatt_init_srv_chg(void) { + tGATTS_SRV_CHG_REQ req; + tGATTS_SRV_CHG_RSP rsp; + bool status; + uint8_t num_clients, i; + tGATTS_SRV_CHG srv_chg_clt; + + GATT_TRACE_DEBUG("gatt_init_srv_chg"); + if (gatt_cb.cb_info.p_srv_chg_callback) { + status = (*gatt_cb.cb_info.p_srv_chg_callback)( + GATTS_SRV_CHG_CMD_READ_NUM_CLENTS, NULL, &rsp); + + if (status && rsp.num_clients) { + GATT_TRACE_DEBUG("gatt_init_srv_chg num_srv_chg_clt_clients=%d", + rsp.num_clients); + num_clients = rsp.num_clients; + i = 1; /* use one based index */ + while ((i <= num_clients) && status) { + req.client_read_index = i; + status = (*gatt_cb.cb_info.p_srv_chg_callback)( + GATTS_SRV_CHG_CMD_READ_CLENT, &req, &rsp); + if (status == true) { + memcpy(&srv_chg_clt, &rsp.srv_chg, sizeof(tGATTS_SRV_CHG)); + if (gatt_add_srv_chg_clt(&srv_chg_clt) == NULL) { + GATT_TRACE_ERROR("Unable to add a service change client"); + status = false; + } } + i++; + } } - else - { - GATT_TRACE_DEBUG("gatt_init_srv_chg callback not registered yet"); - } + } else { + GATT_TRACE_DEBUG("gatt_init_srv_chg callback not registered yet"); + } } /******************************************************************************* @@ -1180,36 +1059,32 @@ void gatt_init_srv_chg (void) * Returns void * ******************************************************************************/ -void gatt_proc_srv_chg (void) -{ - uint8_t start_idx, found_idx; - BD_ADDR bda; - bool srv_chg_ind_pending=false; - tGATT_TCB *p_tcb; - tBT_TRANSPORT transport; - - GATT_TRACE_DEBUG ("gatt_proc_srv_chg"); - - if (gatt_cb.cb_info.p_srv_chg_callback && gatt_cb.handle_of_h_r) - { - gatt_set_srv_chg(); - start_idx =0; - while (gatt_find_the_connected_bda(start_idx, bda, &found_idx, &transport)) - { - p_tcb = &gatt_cb.tcb[found_idx];; - srv_chg_ind_pending = gatt_is_srv_chg_ind_pending(p_tcb); - - if (!srv_chg_ind_pending) - { - gatt_send_srv_chg_ind(bda); - } - else - { - GATT_TRACE_DEBUG ("discard srv chg - already has one in the queue"); - } - start_idx = ++found_idx; - } +void gatt_proc_srv_chg(void) { + uint8_t start_idx, found_idx; + BD_ADDR bda; + bool srv_chg_ind_pending = false; + tGATT_TCB* p_tcb; + tBT_TRANSPORT transport; + + GATT_TRACE_DEBUG("gatt_proc_srv_chg"); + + if (gatt_cb.cb_info.p_srv_chg_callback && gatt_cb.handle_of_h_r) { + gatt_set_srv_chg(); + start_idx = 0; + while ( + gatt_find_the_connected_bda(start_idx, bda, &found_idx, &transport)) { + p_tcb = &gatt_cb.tcb[found_idx]; + ; + srv_chg_ind_pending = gatt_is_srv_chg_ind_pending(p_tcb); + + if (!srv_chg_ind_pending) { + gatt_send_srv_chg_ind(bda); + } else { + GATT_TRACE_DEBUG("discard srv chg - already has one in the queue"); + } + start_idx = ++found_idx; } + } } /******************************************************************************* @@ -1221,13 +1096,12 @@ void gatt_proc_srv_chg (void) * Returns none * ******************************************************************************/ -void gatt_set_ch_state(tGATT_TCB *p_tcb, tGATT_CH_STATE ch_state) -{ - if (p_tcb) - { - GATT_TRACE_DEBUG ("gatt_set_ch_state: old=%d new=%d", p_tcb->ch_state, ch_state); - p_tcb->ch_state = ch_state; - } +void gatt_set_ch_state(tGATT_TCB* p_tcb, tGATT_CH_STATE ch_state) { + if (p_tcb) { + GATT_TRACE_DEBUG("gatt_set_ch_state: old=%d new=%d", p_tcb->ch_state, + ch_state); + p_tcb->ch_state = ch_state; + } } /******************************************************************************* @@ -1239,13 +1113,11 @@ void gatt_set_ch_state(tGATT_TCB *p_tcb, tGATT_CH_STATE ch_state) * Returns none * ******************************************************************************/ -tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB *p_tcb) -{ - tGATT_CH_STATE ch_state = GATT_CH_CLOSE; - if (p_tcb) - { - GATT_TRACE_DEBUG ("gatt_get_ch_state: ch_state=%d", p_tcb->ch_state); - ch_state = p_tcb->ch_state; - } - return ch_state; +tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* p_tcb) { + tGATT_CH_STATE ch_state = GATT_CH_CLOSE; + if (p_tcb) { + GATT_TRACE_DEBUG("gatt_get_ch_state: ch_state=%d", p_tcb->ch_state); + ch_state = p_tcb->ch_state; + } + return ch_state; } diff --git a/stack/gatt/gatt_sr.cc b/stack/gatt/gatt_sr.cc index b0e5b87a2..d5d4de6fb 100644 --- a/stack/gatt/gatt_sr.cc +++ b/stack/gatt/gatt_sr.cc @@ -30,8 +30,7 @@ #include "gatt_int.h" #include "l2c_api.h" #include "l2c_int.h" -#define GATT_MTU_REQ_MIN_LEN 2 - +#define GATT_MTU_REQ_MIN_LEN 2 /******************************************************************************* * @@ -43,33 +42,28 @@ * Returns void * ******************************************************************************/ -uint32_t gatt_sr_enqueue_cmd (tGATT_TCB *p_tcb, uint8_t op_code, uint16_t handle) -{ - tGATT_SR_CMD *p_cmd = &p_tcb->sr_cmd; - uint32_t trans_id = 0; - - if ( (p_cmd->op_code == 0) || - (op_code == GATT_HANDLE_VALUE_CONF)) /* no pending request */ - { - if (op_code == GATT_CMD_WRITE || - op_code == GATT_SIGN_CMD_WRITE || - op_code == GATT_REQ_MTU || - op_code == GATT_HANDLE_VALUE_CONF) - { - trans_id = ++p_tcb->trans_id; - } - else - { - p_cmd->trans_id = ++p_tcb->trans_id; - p_cmd->op_code = op_code; - p_cmd->handle = handle; - p_cmd->status = GATT_NOT_FOUND; - p_tcb->trans_id %= GATT_TRANS_ID_MAX; - trans_id = p_cmd->trans_id; - } +uint32_t gatt_sr_enqueue_cmd(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t handle) { + tGATT_SR_CMD* p_cmd = &p_tcb->sr_cmd; + uint32_t trans_id = 0; + + if ((p_cmd->op_code == 0) || + (op_code == GATT_HANDLE_VALUE_CONF)) /* no pending request */ + { + if (op_code == GATT_CMD_WRITE || op_code == GATT_SIGN_CMD_WRITE || + op_code == GATT_REQ_MTU || op_code == GATT_HANDLE_VALUE_CONF) { + trans_id = ++p_tcb->trans_id; + } else { + p_cmd->trans_id = ++p_tcb->trans_id; + p_cmd->op_code = op_code; + p_cmd->handle = handle; + p_cmd->status = GATT_NOT_FOUND; + p_tcb->trans_id %= GATT_TRANS_ID_MAX; + trans_id = p_cmd->trans_id; } + } - return trans_id; + return trans_id; } /******************************************************************************* @@ -81,9 +75,8 @@ uint32_t gatt_sr_enqueue_cmd (tGATT_TCB *p_tcb, uint8_t op_code, uint16_t handle * Returns true if empty, false if there is pending command. * ******************************************************************************/ -bool gatt_sr_cmd_empty (tGATT_TCB *p_tcb) -{ - return(p_tcb->sr_cmd.op_code == 0); +bool gatt_sr_cmd_empty(tGATT_TCB* p_tcb) { + return (p_tcb->sr_cmd.op_code == 0); } /******************************************************************************* @@ -95,18 +88,18 @@ bool gatt_sr_cmd_empty (tGATT_TCB *p_tcb) * Returns void * ******************************************************************************/ -void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb) -{ - /* Double check in case any buffers are queued */ - GATT_TRACE_DEBUG("gatt_dequeue_sr_cmd" ); - if (p_tcb->sr_cmd.p_rsp_msg) - GATT_TRACE_ERROR("free p_tcb->sr_cmd.p_rsp_msg = %d", p_tcb->sr_cmd.p_rsp_msg); - osi_free_and_reset((void **)&p_tcb->sr_cmd.p_rsp_msg); - - while (!fixed_queue_is_empty(p_tcb->sr_cmd.multi_rsp_q)) - osi_free(fixed_queue_try_dequeue(p_tcb->sr_cmd.multi_rsp_q)); - fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL); - memset( &p_tcb->sr_cmd, 0, sizeof(tGATT_SR_CMD)); +void gatt_dequeue_sr_cmd(tGATT_TCB* p_tcb) { + /* Double check in case any buffers are queued */ + GATT_TRACE_DEBUG("gatt_dequeue_sr_cmd"); + if (p_tcb->sr_cmd.p_rsp_msg) + GATT_TRACE_ERROR("free p_tcb->sr_cmd.p_rsp_msg = %d", + p_tcb->sr_cmd.p_rsp_msg); + osi_free_and_reset((void**)&p_tcb->sr_cmd.p_rsp_msg); + + while (!fixed_queue_is_empty(p_tcb->sr_cmd.multi_rsp_q)) + osi_free(fixed_queue_try_dequeue(p_tcb->sr_cmd.multi_rsp_q)); + fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL); + memset(&p_tcb->sr_cmd, 0, sizeof(tGATT_SR_CMD)); } /******************************************************************************* @@ -118,129 +111,108 @@ void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb) * Returns bool if all replies have been received * ******************************************************************************/ -static bool process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status, - tGATTS_RSP *p_msg, uint16_t mtu) -{ - uint16_t ii, total_len, len; - uint8_t *p; - bool is_overflow = false; - - GATT_TRACE_DEBUG ("%s status=%d mtu=%d", __func__, status, mtu); - - if (p_cmd->multi_rsp_q == NULL) - p_cmd->multi_rsp_q = fixed_queue_new(SIZE_MAX); - - /* Enqueue the response */ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(tGATTS_RSP)); - memcpy((void *)p_buf, (const void *)p_msg, sizeof(tGATTS_RSP)); - fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf); - - p_cmd->status = status; - if (status == GATT_SUCCESS) - { - GATT_TRACE_DEBUG("Multi read count=%d num_hdls=%d", - fixed_queue_length(p_cmd->multi_rsp_q), - p_cmd->multi_req.num_handles); - /* Wait till we get all the responses */ - if (fixed_queue_length(p_cmd->multi_rsp_q) == p_cmd->multi_req.num_handles) - { - len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu; - p_buf = (BT_HDR *)osi_calloc(len); - p_buf->offset = L2CAP_MIN_OFFSET; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* First byte in the response is the opcode */ - *p++ = GATT_RSP_READ_MULTI; - p_buf->len = 1; - - /* Now walk through the buffers puting the data into the response in order */ - list_t *list = NULL; - const list_node_t *node = NULL; - if (! fixed_queue_is_empty(p_cmd->multi_rsp_q)) - list = fixed_queue_get_list(p_cmd->multi_rsp_q); - for (ii = 0; ii < p_cmd->multi_req.num_handles; ii++) - { - tGATTS_RSP *p_rsp = NULL; - - if (list != NULL) { - if (ii == 0) - node = list_begin(list); - else - node = list_next(node); - if (node != list_end(list)) - p_rsp = (tGATTS_RSP *)list_node(node); - } - - if (p_rsp != NULL) - { - - total_len = (p_buf->len + p_rsp->attr_value.len); - - if (total_len > mtu) - { - /* just send the partial response for the overflow case */ - len = p_rsp->attr_value.len - (total_len - mtu); - is_overflow = true; - GATT_TRACE_DEBUG ("multi read overflow available len=%d val_len=%d", len, p_rsp->attr_value.len ); - } - else - { - len = p_rsp->attr_value.len; - } - - if (p_rsp->attr_value.handle == p_cmd->multi_req.handles[ii]) - { - memcpy (p, p_rsp->attr_value.value, len); - if (!is_overflow) - p += len; - p_buf->len += len; - } - else - { - p_cmd->status = GATT_NOT_FOUND; - break; - } - - if (is_overflow) - break; - - } - else - { - p_cmd->status = GATT_NOT_FOUND; - break; - } - - } /* loop through all handles*/ - - - /* Sanity check on the buffer length */ - if (p_buf->len == 0) - { - GATT_TRACE_ERROR("process_read_multi_rsp - nothing found!!"); - p_cmd->status = GATT_NOT_FOUND; - osi_free(p_buf); - GATT_TRACE_DEBUG("osi_free(p_buf)"); - } - else if (p_cmd->p_rsp_msg != NULL) - { - osi_free(p_buf); - } - else - { - p_cmd->p_rsp_msg = p_buf; - } +static bool process_read_multi_rsp(tGATT_SR_CMD* p_cmd, tGATT_STATUS status, + tGATTS_RSP* p_msg, uint16_t mtu) { + uint16_t ii, total_len, len; + uint8_t* p; + bool is_overflow = false; + + GATT_TRACE_DEBUG("%s status=%d mtu=%d", __func__, status, mtu); + + if (p_cmd->multi_rsp_q == NULL) + p_cmd->multi_rsp_q = fixed_queue_new(SIZE_MAX); + + /* Enqueue the response */ + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(tGATTS_RSP)); + memcpy((void*)p_buf, (const void*)p_msg, sizeof(tGATTS_RSP)); + fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf); + + p_cmd->status = status; + if (status == GATT_SUCCESS) { + GATT_TRACE_DEBUG("Multi read count=%d num_hdls=%d", + fixed_queue_length(p_cmd->multi_rsp_q), + p_cmd->multi_req.num_handles); + /* Wait till we get all the responses */ + if (fixed_queue_length(p_cmd->multi_rsp_q) == + p_cmd->multi_req.num_handles) { + len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu; + p_buf = (BT_HDR*)osi_calloc(len); + p_buf->offset = L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* First byte in the response is the opcode */ + *p++ = GATT_RSP_READ_MULTI; + p_buf->len = 1; + + /* Now walk through the buffers puting the data into the response in order + */ + list_t* list = NULL; + const list_node_t* node = NULL; + if (!fixed_queue_is_empty(p_cmd->multi_rsp_q)) + list = fixed_queue_get_list(p_cmd->multi_rsp_q); + for (ii = 0; ii < p_cmd->multi_req.num_handles; ii++) { + tGATTS_RSP* p_rsp = NULL; + + if (list != NULL) { + if (ii == 0) + node = list_begin(list); + else + node = list_next(node); + if (node != list_end(list)) p_rsp = (tGATTS_RSP*)list_node(node); + } + + if (p_rsp != NULL) { + total_len = (p_buf->len + p_rsp->attr_value.len); + + if (total_len > mtu) { + /* just send the partial response for the overflow case */ + len = p_rsp->attr_value.len - (total_len - mtu); + is_overflow = true; + GATT_TRACE_DEBUG("multi read overflow available len=%d val_len=%d", + len, p_rsp->attr_value.len); + } else { + len = p_rsp->attr_value.len; + } + + if (p_rsp->attr_value.handle == p_cmd->multi_req.handles[ii]) { + memcpy(p, p_rsp->attr_value.value, len); + if (!is_overflow) p += len; + p_buf->len += len; + } else { + p_cmd->status = GATT_NOT_FOUND; + break; + } - return(true); + if (is_overflow) break; + + } else { + p_cmd->status = GATT_NOT_FOUND; + break; } + + } /* loop through all handles*/ + + /* Sanity check on the buffer length */ + if (p_buf->len == 0) { + GATT_TRACE_ERROR("process_read_multi_rsp - nothing found!!"); + p_cmd->status = GATT_NOT_FOUND; + osi_free(p_buf); + GATT_TRACE_DEBUG("osi_free(p_buf)"); + } else if (p_cmd->p_rsp_msg != NULL) { + osi_free(p_buf); + } else { + p_cmd->p_rsp_msg = p_buf; + } + + return (true); } - else /* any handle read exception occurs, return error */ - { - return(true); - } + } else /* any handle read exception occurs, return error */ + { + return (true); + } - /* If here, still waiting */ - return(false); + /* If here, still waiting */ + return (false); } /******************************************************************************* @@ -253,63 +225,54 @@ static bool process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status, * Returns void * ******************************************************************************/ -tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if, - UNUSED_ATTR uint32_t trans_id, uint8_t op_code, - tGATT_STATUS status, tGATTS_RSP *p_msg) -{ - tGATT_STATUS ret_code = GATT_SUCCESS; - - GATT_TRACE_DEBUG("gatt_sr_process_app_rsp gatt_if=%d", gatt_if); - - gatt_sr_update_cback_cnt(p_tcb, gatt_if, false, false); - - if (op_code == GATT_REQ_READ_MULTI) - { - /* If no error and still waiting, just return */ - if (!process_read_multi_rsp (&p_tcb->sr_cmd, status, p_msg, p_tcb->payload_size)) - return(GATT_SUCCESS); +tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB* p_tcb, tGATT_IF gatt_if, + UNUSED_ATTR uint32_t trans_id, + uint8_t op_code, tGATT_STATUS status, + tGATTS_RSP* p_msg) { + tGATT_STATUS ret_code = GATT_SUCCESS; + + GATT_TRACE_DEBUG("gatt_sr_process_app_rsp gatt_if=%d", gatt_if); + + gatt_sr_update_cback_cnt(p_tcb, gatt_if, false, false); + + if (op_code == GATT_REQ_READ_MULTI) { + /* If no error and still waiting, just return */ + if (!process_read_multi_rsp(&p_tcb->sr_cmd, status, p_msg, + p_tcb->payload_size)) + return (GATT_SUCCESS); + } else { + if (op_code == GATT_REQ_PREPARE_WRITE && status == GATT_SUCCESS) + gatt_sr_update_prep_cnt(p_tcb, gatt_if, true, false); + + if (op_code == GATT_REQ_EXEC_WRITE && status != GATT_SUCCESS) + gatt_sr_reset_cback_cnt(p_tcb); + + p_tcb->sr_cmd.status = status; + + if (gatt_sr_is_cback_cnt_zero(p_tcb) && status == GATT_SUCCESS) { + if (p_tcb->sr_cmd.p_rsp_msg == NULL) { + p_tcb->sr_cmd.p_rsp_msg = attp_build_sr_msg( + p_tcb, (uint8_t)(op_code + 1), (tGATT_SR_MSG*)p_msg); + } else { + GATT_TRACE_ERROR("Exception!!! already has respond message"); + } } - else - { - if (op_code == GATT_REQ_PREPARE_WRITE && status == GATT_SUCCESS) - gatt_sr_update_prep_cnt(p_tcb, gatt_if, true, false); - - if (op_code == GATT_REQ_EXEC_WRITE && status != GATT_SUCCESS) - gatt_sr_reset_cback_cnt(p_tcb); - - p_tcb->sr_cmd.status = status; - - if (gatt_sr_is_cback_cnt_zero(p_tcb) - && status == GATT_SUCCESS) - { - if (p_tcb->sr_cmd.p_rsp_msg == NULL) - { - p_tcb->sr_cmd.p_rsp_msg = attp_build_sr_msg (p_tcb, (uint8_t)(op_code + 1), (tGATT_SR_MSG *)p_msg); - } - else - { - GATT_TRACE_ERROR("Exception!!! already has respond message"); - } - } + } + if (gatt_sr_is_cback_cnt_zero(p_tcb)) { + if ((p_tcb->sr_cmd.status == GATT_SUCCESS) && (p_tcb->sr_cmd.p_rsp_msg)) { + ret_code = attp_send_sr_msg(p_tcb, p_tcb->sr_cmd.p_rsp_msg); + p_tcb->sr_cmd.p_rsp_msg = NULL; + } else { + ret_code = gatt_send_error_rsp(p_tcb, status, op_code, + p_tcb->sr_cmd.handle, false); } - if (gatt_sr_is_cback_cnt_zero(p_tcb)) - { - if ( (p_tcb->sr_cmd.status == GATT_SUCCESS) && (p_tcb->sr_cmd.p_rsp_msg) ) - { - ret_code = attp_send_sr_msg (p_tcb, p_tcb->sr_cmd.p_rsp_msg); - p_tcb->sr_cmd.p_rsp_msg = NULL; - } - else - { - ret_code = gatt_send_error_rsp (p_tcb, status, op_code, p_tcb->sr_cmd.handle, false); - } - gatt_dequeue_sr_cmd(p_tcb); - } + gatt_dequeue_sr_cmd(p_tcb); + } - GATT_TRACE_DEBUG("gatt_sr_process_app_rsp ret_code=%d", ret_code); + GATT_TRACE_DEBUG("gatt_sr_process_app_rsp ret_code=%d", ret_code); - return ret_code; + return ret_code; } /******************************************************************************* @@ -322,57 +285,50 @@ tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if, * Returns void * ******************************************************************************/ -void gatt_process_exec_write_req (tGATT_TCB *p_tcb, uint8_t op_code, - UNUSED_ATTR uint16_t len, uint8_t *p_data) -{ - uint8_t *p = p_data, flag, i = 0; - uint32_t trans_id = 0; - tGATT_IF gatt_if; - uint16_t conn_id; +void gatt_process_exec_write_req(tGATT_TCB* p_tcb, uint8_t op_code, + UNUSED_ATTR uint16_t len, uint8_t* p_data) { + uint8_t *p = p_data, flag, i = 0; + uint32_t trans_id = 0; + tGATT_IF gatt_if; + uint16_t conn_id; #if (GATT_CONFORMANCE_TESTING == TRUE) - if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) - { - GATT_TRACE_DEBUG("Conformance tst: forced err rspv for Execute Write: error status=%d", + if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { + GATT_TRACE_DEBUG( + "Conformance tst: forced err rspv for Execute Write: error status=%d", gatt_cb.err_status); - gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, gatt_cb.handle, false); + gatt_send_error_rsp(p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, + gatt_cb.handle, false); - return; - } + return; + } #endif - STREAM_TO_UINT8(flag, p); - - /* mask the flag */ - flag &= GATT_PREP_WRITE_EXEC; - - - /* no prep write is queued */ - if (!gatt_sr_is_prep_cnt_zero(p_tcb)) - { - trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, 0); - gatt_sr_copy_prep_cnt_to_cback_cnt(p_tcb); - - for (i=0; iprep_cnt[i]) - { - gatt_if = (tGATT_IF) (i+1); - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); - gatt_sr_send_req_callback(conn_id, - trans_id, - GATTS_REQ_TYPE_WRITE_EXEC, - (tGATTS_DATA *)&flag); - p_tcb->prep_cnt[i]= 0; - } - } - } - else /* nothing needs to be executed , send response now */ - { - GATT_TRACE_ERROR("gatt_process_exec_write_req: no prepare write pending"); - gatt_send_error_rsp(p_tcb, GATT_ERROR, GATT_REQ_EXEC_WRITE, 0, false); + STREAM_TO_UINT8(flag, p); + + /* mask the flag */ + flag &= GATT_PREP_WRITE_EXEC; + + /* no prep write is queued */ + if (!gatt_sr_is_prep_cnt_zero(p_tcb)) { + trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, 0); + gatt_sr_copy_prep_cnt_to_cback_cnt(p_tcb); + + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->prep_cnt[i]) { + gatt_if = (tGATT_IF)(i + 1); + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if); + gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, + (tGATTS_DATA*)&flag); + p_tcb->prep_cnt[i] = 0; + } } + } else /* nothing needs to be executed , send response now */ + { + GATT_TRACE_ERROR("gatt_process_exec_write_req: no prepare write pending"); + gatt_send_error_rsp(p_tcb, GATT_ERROR, GATT_REQ_EXEC_WRITE, 0, false); + } } /******************************************************************************* @@ -385,109 +341,96 @@ void gatt_process_exec_write_req (tGATT_TCB *p_tcb, uint8_t op_code, * Returns void * ******************************************************************************/ -void gatt_process_read_multi_req (tGATT_TCB *p_tcb, uint8_t op_code, uint16_t len, uint8_t *p_data) -{ - uint32_t trans_id; - uint16_t handle = 0, ll = len; - uint8_t *p = p_data, i_rcb; - tGATT_STATUS err = GATT_SUCCESS; - uint8_t sec_flag, key_size; - - GATT_TRACE_DEBUG("gatt_process_read_multi_req" ); - p_tcb->sr_cmd.multi_req.num_handles = 0; - - gatt_sr_get_sec_info(p_tcb->peer_bda, - p_tcb->transport, - &sec_flag, - &key_size); +void gatt_process_read_multi_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + uint32_t trans_id; + uint16_t handle = 0, ll = len; + uint8_t *p = p_data, i_rcb; + tGATT_STATUS err = GATT_SUCCESS; + uint8_t sec_flag, key_size; + + GATT_TRACE_DEBUG("gatt_process_read_multi_req"); + p_tcb->sr_cmd.multi_req.num_handles = 0; + + gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag, &key_size); #if (GATT_CONFORMANCE_TESTING == TRUE) - if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) - { - GATT_TRACE_DEBUG("Conformance tst: forced err rspvofr ReadMultiple: error status=%d", gatt_cb.err_status); + if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { + GATT_TRACE_DEBUG( + "Conformance tst: forced err rspvofr ReadMultiple: error status=%d", + gatt_cb.err_status); - STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(handle, p); - gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, false); + gatt_send_error_rsp(p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, + false); - return; - } + return; + } #endif - while (ll >= 2 && p_tcb->sr_cmd.multi_req.num_handles < GATT_MAX_READ_MULTI_HANDLES) - { - STREAM_TO_UINT16(handle, p); + while (ll >= 2 && + p_tcb->sr_cmd.multi_req.num_handles < GATT_MAX_READ_MULTI_HANDLES) { + STREAM_TO_UINT16(handle, p); + + i_rcb = gatt_sr_find_i_rcb_by_handle(handle); + if (i_rcb < GATT_MAX_SR_PROFILES) { + p_tcb->sr_cmd.multi_req.handles[p_tcb->sr_cmd.multi_req.num_handles++] = + handle; + + /* check read permission */ + err = gatts_read_attr_perm_check(gatt_cb.sr_reg[i_rcb].p_db, false, + handle, sec_flag, key_size); + if (err != GATT_SUCCESS) { + GATT_TRACE_DEBUG("read permission denied : 0x%02x", err); + break; + } + } else { + /* invalid handle */ + err = GATT_INVALID_HANDLE; + break; + } + ll -= 2; + } + + if (ll != 0) { + GATT_TRACE_ERROR("max attribute handle reached in ReadMultiple Request."); + } + if (p_tcb->sr_cmd.multi_req.num_handles == 0) err = GATT_INVALID_HANDLE; + + if (err == GATT_SUCCESS) { + trans_id = + gatt_sr_enqueue_cmd(p_tcb, op_code, p_tcb->sr_cmd.multi_req.handles[0]); + if (trans_id != 0) { + gatt_sr_reset_cback_cnt(p_tcb); /* read multiple use multi_rsp_q's count*/ + + for (ll = 0; ll < p_tcb->sr_cmd.multi_req.num_handles; ll++) { + tGATTS_RSP* p_msg = (tGATTS_RSP*)osi_calloc(sizeof(tGATTS_RSP)); + handle = p_tcb->sr_cmd.multi_req.handles[ll]; i_rcb = gatt_sr_find_i_rcb_by_handle(handle); - if (i_rcb < GATT_MAX_SR_PROFILES) - { - p_tcb->sr_cmd.multi_req.handles[p_tcb->sr_cmd.multi_req.num_handles++] = handle; - - /* check read permission */ - err = gatts_read_attr_perm_check(gatt_cb.sr_reg[i_rcb].p_db, - false, handle, sec_flag, key_size); - if (err != GATT_SUCCESS) - { - GATT_TRACE_DEBUG("read permission denied : 0x%02x", err); - break; - } - } - else - { - /* invalid handle */ - err = GATT_INVALID_HANDLE; - break; - } - ll -= 2; - } - if (ll != 0) - { - GATT_TRACE_ERROR("max attribute handle reached in ReadMultiple Request."); - } + p_msg->attr_value.handle = handle; + err = gatts_read_attr_value_by_handle( + p_tcb, gatt_cb.sr_reg[i_rcb].p_db, op_code, handle, 0, + p_msg->attr_value.value, &p_msg->attr_value.len, GATT_MAX_ATTR_LEN, + sec_flag, key_size, trans_id); - if (p_tcb->sr_cmd.multi_req.num_handles == 0) - err = GATT_INVALID_HANDLE; - - if (err == GATT_SUCCESS) - { - trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, p_tcb->sr_cmd.multi_req.handles[0]); - if (trans_id != 0) - { - gatt_sr_reset_cback_cnt(p_tcb); /* read multiple use multi_rsp_q's count*/ - - for (ll = 0; ll < p_tcb->sr_cmd.multi_req.num_handles; ll ++) { - tGATTS_RSP *p_msg = (tGATTS_RSP *)osi_calloc(sizeof(tGATTS_RSP)); - handle = p_tcb->sr_cmd.multi_req.handles[ll]; - i_rcb = gatt_sr_find_i_rcb_by_handle(handle); - - p_msg->attr_value.handle = handle; - err = gatts_read_attr_value_by_handle(p_tcb, - gatt_cb.sr_reg[i_rcb].p_db, - op_code, - handle, - 0, - p_msg->attr_value.value, - &p_msg->attr_value.len, - GATT_MAX_ATTR_LEN, - sec_flag, - key_size, - trans_id); - - if (err == GATT_SUCCESS) { - gatt_sr_process_app_rsp(p_tcb, gatt_cb.sr_reg[i_rcb].gatt_if ,trans_id, op_code, GATT_SUCCESS, p_msg); - } - /* either not using or done using the buffer, release it now */ - osi_free(p_msg); - } + if (err == GATT_SUCCESS) { + gatt_sr_process_app_rsp(p_tcb, gatt_cb.sr_reg[i_rcb].gatt_if, + trans_id, op_code, GATT_SUCCESS, p_msg); } - else - err = GATT_NO_RESOURCES; - } - - /* in theroy BUSY is not possible(should already been checked), protected check */ - if (err != GATT_SUCCESS && err != GATT_PENDING && err != GATT_BUSY) - gatt_send_error_rsp(p_tcb, err, op_code, handle, false); + /* either not using or done using the buffer, release it now */ + osi_free(p_msg); + } + } else + err = GATT_NO_RESOURCES; + } + + /* in theroy BUSY is not possible(should already been checked), protected + * check */ + if (err != GATT_SUCCESS && err != GATT_PENDING && err != GATT_BUSY) + gatt_send_error_rsp(p_tcb, err, op_code, handle, false); } /******************************************************************************* @@ -500,86 +443,71 @@ void gatt_process_read_multi_req (tGATT_TCB *p_tcb, uint8_t op_code, uint16_t le * Returns void * ******************************************************************************/ -static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_tcb, - uint8_t op_code, uint16_t s_hdl, - uint16_t e_hdl, - UNUSED_ATTR uint8_t *p_data, tBT_UUID value) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - uint8_t handle_len =4, *p ; - tGATT_SR_REG *p_rcb; - tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info; - tGATT_SRV_LIST_ELEM *p_srv=NULL; - tBT_UUID *p_uuid; - - p = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; - - p_srv = p_list->p_first; +static tGATT_STATUS gatt_build_primary_service_rsp( + BT_HDR* p_msg, tGATT_TCB* p_tcb, uint8_t op_code, uint16_t s_hdl, + uint16_t e_hdl, UNUSED_ATTR uint8_t* p_data, tBT_UUID value) { + tGATT_STATUS status = GATT_NOT_FOUND; + uint8_t handle_len = 4, *p; + tGATT_SR_REG* p_rcb; + tGATT_SRV_LIST_INFO* p_list = &gatt_cb.srv_list_info; + tGATT_SRV_LIST_ELEM* p_srv = NULL; + tBT_UUID* p_uuid; + + p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; + + p_srv = p_list->p_first; + + while (p_srv) { + p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); + + if (p_rcb->in_use && p_rcb->s_hdl >= s_hdl && p_rcb->s_hdl <= e_hdl && + p_rcb->type == GATT_UUID_PRI_SERVICE) { + p_uuid = gatts_get_service_uuid(p_rcb->p_db); + if (p_uuid != NULL) { + if (op_code == GATT_REQ_READ_BY_GRP_TYPE) handle_len = 4 + p_uuid->len; + + /* get the length byte in the repsonse */ + if (p_msg->offset == 0) { + *p++ = op_code + 1; + p_msg->len++; + p_msg->offset = handle_len; + + if (op_code == GATT_REQ_READ_BY_GRP_TYPE) { + *p++ = (uint8_t)p_msg->offset; /* length byte */ + p_msg->len++; + } + } - while (p_srv) - { - p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); - - if (p_rcb->in_use && - p_rcb->s_hdl >= s_hdl && - p_rcb->s_hdl <= e_hdl && - p_rcb->type == GATT_UUID_PRI_SERVICE) - { - p_uuid = gatts_get_service_uuid(p_rcb->p_db); - if (p_uuid != NULL) - { - if (op_code == GATT_REQ_READ_BY_GRP_TYPE) - handle_len = 4 + p_uuid->len; - - /* get the length byte in the repsonse */ - if (p_msg->offset ==0) - { - *p ++ = op_code + 1; - p_msg->len ++; - p_msg->offset = handle_len; - - if (op_code == GATT_REQ_READ_BY_GRP_TYPE) - { - *p ++ = (uint8_t)p_msg->offset; /* length byte */ - p_msg->len ++; - } - } - - if (p_msg->len + p_msg->offset <= p_tcb->payload_size && - handle_len == p_msg->offset) - { - if (op_code != GATT_REQ_FIND_TYPE_VALUE || - gatt_uuid_compare(value, *p_uuid)) - { - UINT16_TO_STREAM(p, p_rcb->s_hdl); - - if (p_list->p_last_primary == p_srv && - p_list->p_last_primary == p_list->p_last) - { - GATT_TRACE_DEBUG("Use 0xFFFF for the last primary attribute"); - UINT16_TO_STREAM(p, 0xFFFF); /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */ - } - else - { - UINT16_TO_STREAM(p, p_rcb->e_hdl); - } - - if (op_code == GATT_REQ_READ_BY_GRP_TYPE) - gatt_build_uuid_to_stream(&p, *p_uuid); - - status = GATT_SUCCESS; - p_msg->len += p_msg->offset; - } - } - else - break; + if (p_msg->len + p_msg->offset <= p_tcb->payload_size && + handle_len == p_msg->offset) { + if (op_code != GATT_REQ_FIND_TYPE_VALUE || + gatt_uuid_compare(value, *p_uuid)) { + UINT16_TO_STREAM(p, p_rcb->s_hdl); + + if (p_list->p_last_primary == p_srv && + p_list->p_last_primary == p_list->p_last) { + GATT_TRACE_DEBUG("Use 0xFFFF for the last primary attribute"); + UINT16_TO_STREAM( + p, 0xFFFF); /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */ + } else { + UINT16_TO_STREAM(p, p_rcb->e_hdl); } - } - p_srv = p_srv->p_next; + + if (op_code == GATT_REQ_READ_BY_GRP_TYPE) + gatt_build_uuid_to_stream(&p, *p_uuid); + + status = GATT_SUCCESS; + p_msg->len += p_msg->offset; + } + } else + break; + } } - p_msg->offset = L2CAP_MIN_OFFSET; + p_srv = p_srv->p_next; + } + p_msg->offset = L2CAP_MIN_OFFSET; - return status; + return status; } /******************************************************************************* @@ -593,76 +521,67 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_ * false: packet full, or format mismatch. * ******************************************************************************/ -static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, uint16_t *p_len, - uint16_t s_hdl, uint16_t e_hdl) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - uint8_t *p; - uint16_t len = *p_len; - tGATT_ATTR *p_attr = NULL; - uint8_t info_pair_len[2] = {4, 18}; - - if (!p_rcb->p_db || !p_rcb->p_db->p_attr_list) - return status; - - /* check the attribute database */ - p_attr = (tGATT_ATTR *) p_rcb->p_db->p_attr_list; - - p = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET + p_msg->len; - - while (p_attr) - { - if (p_attr->handle > e_hdl) - { - break; - } +static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG* p_rcb, BT_HDR* p_msg, + uint16_t* p_len, uint16_t s_hdl, + uint16_t e_hdl) { + tGATT_STATUS status = GATT_NOT_FOUND; + uint8_t* p; + uint16_t len = *p_len; + tGATT_ATTR* p_attr = NULL; + uint8_t info_pair_len[2] = {4, 18}; - if (p_attr->handle >= s_hdl) - { - if (p_msg->offset == 0) - p_msg->offset = (p_attr->uuid.len == LEN_UUID_16) ? GATT_INFO_TYPE_PAIR_16 : GATT_INFO_TYPE_PAIR_128; - - if (len >= info_pair_len[p_msg->offset - 1]) - { - if (p_msg->offset == GATT_INFO_TYPE_PAIR_16 && p_attr->uuid.len == LEN_UUID_16) - { - UINT16_TO_STREAM(p, p_attr->handle); - UINT16_TO_STREAM(p, p_attr->uuid.uu.uuid16); - } - else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && p_attr->uuid.len == LEN_UUID_128 ) - { - UINT16_TO_STREAM(p, p_attr->handle); - ARRAY_TO_STREAM (p, p_attr->uuid.uu.uuid128, LEN_UUID_128); - } - else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && p_attr->uuid.len == LEN_UUID_32) - { - UINT16_TO_STREAM(p, p_attr->handle); - gatt_convert_uuid32_to_uuid128(p, p_attr->uuid.uu.uuid32); - p += LEN_UUID_128; - } - else - { - GATT_TRACE_ERROR("format mismatch"); - status = GATT_NO_RESOURCES; - break; - /* format mismatch */ - } - p_msg->len += info_pair_len[p_msg->offset - 1]; - len -= info_pair_len[p_msg->offset - 1]; - status = GATT_SUCCESS; + if (!p_rcb->p_db || !p_rcb->p_db->p_attr_list) return status; - } - else - { - status = GATT_NO_RESOURCES; - break; - } + /* check the attribute database */ + p_attr = (tGATT_ATTR*)p_rcb->p_db->p_attr_list; + + p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET + p_msg->len; + + while (p_attr) { + if (p_attr->handle > e_hdl) { + break; + } + + if (p_attr->handle >= s_hdl) { + if (p_msg->offset == 0) + p_msg->offset = (p_attr->uuid.len == LEN_UUID_16) + ? GATT_INFO_TYPE_PAIR_16 + : GATT_INFO_TYPE_PAIR_128; + + if (len >= info_pair_len[p_msg->offset - 1]) { + if (p_msg->offset == GATT_INFO_TYPE_PAIR_16 && + p_attr->uuid.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, p_attr->handle); + UINT16_TO_STREAM(p, p_attr->uuid.uu.uuid16); + } else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && + p_attr->uuid.len == LEN_UUID_128) { + UINT16_TO_STREAM(p, p_attr->handle); + ARRAY_TO_STREAM(p, p_attr->uuid.uu.uuid128, LEN_UUID_128); + } else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && + p_attr->uuid.len == LEN_UUID_32) { + UINT16_TO_STREAM(p, p_attr->handle); + gatt_convert_uuid32_to_uuid128(p, p_attr->uuid.uu.uuid32); + p += LEN_UUID_128; + } else { + GATT_TRACE_ERROR("format mismatch"); + status = GATT_NO_RESOURCES; + break; + /* format mismatch */ } - p_attr = (tGATT_ATTR *)p_attr->p_next; + p_msg->len += info_pair_len[p_msg->offset - 1]; + len -= info_pair_len[p_msg->offset - 1]; + status = GATT_SUCCESS; + + } else { + status = GATT_NO_RESOURCES; + break; + } } + p_attr = (tGATT_ATTR*)p_attr->p_next; + } - *p_len = len; - return status; + *p_len = len; + return status; } /******************************************************************************* @@ -675,58 +594,50 @@ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, * Returns void * ******************************************************************************/ -static tGATT_STATUS gatts_validate_packet_format(uint8_t op_code, uint16_t *p_len, - uint8_t **p_data, tBT_UUID *p_uuid_filter, - uint16_t *p_s_hdl, uint16_t *p_e_hdl) -{ - tGATT_STATUS reason = GATT_SUCCESS; - uint16_t uuid_len, s_hdl = 0, e_hdl = 0; - uint16_t len = *p_len; - uint8_t *p = *p_data; - - if (len >= 4) - { - /* obtain starting handle, and ending handle */ - STREAM_TO_UINT16(s_hdl, p); - STREAM_TO_UINT16(e_hdl, p); - len -= 4; - - if (s_hdl > e_hdl || !GATT_HANDLE_IS_VALID(s_hdl) || !GATT_HANDLE_IS_VALID(e_hdl)) - { - reason = GATT_INVALID_HANDLE; - } - /* for these PDUs, uuid filter must present */ - else if (op_code == GATT_REQ_READ_BY_GRP_TYPE || - op_code == GATT_REQ_FIND_TYPE_VALUE || - op_code == GATT_REQ_READ_BY_TYPE) - { - if (len >= 2 && p_uuid_filter != NULL) - { - uuid_len = (op_code == GATT_REQ_FIND_TYPE_VALUE) ? 2 : len; - - /* parse uuid now */ - if (gatt_parse_uuid_from_cmd (p_uuid_filter, uuid_len, &p) == false || - p_uuid_filter->len == 0) - { - GATT_TRACE_DEBUG("UUID filter does not exsit"); - reason = GATT_INVALID_PDU; - } - else - len -= p_uuid_filter->len; - } - else - reason = GATT_INVALID_PDU; - } +static tGATT_STATUS gatts_validate_packet_format( + uint8_t op_code, uint16_t* p_len, uint8_t** p_data, tBT_UUID* p_uuid_filter, + uint16_t* p_s_hdl, uint16_t* p_e_hdl) { + tGATT_STATUS reason = GATT_SUCCESS; + uint16_t uuid_len, s_hdl = 0, e_hdl = 0; + uint16_t len = *p_len; + uint8_t* p = *p_data; + + if (len >= 4) { + /* obtain starting handle, and ending handle */ + STREAM_TO_UINT16(s_hdl, p); + STREAM_TO_UINT16(e_hdl, p); + len -= 4; + + if (s_hdl > e_hdl || !GATT_HANDLE_IS_VALID(s_hdl) || + !GATT_HANDLE_IS_VALID(e_hdl)) { + reason = GATT_INVALID_HANDLE; } - else + /* for these PDUs, uuid filter must present */ + else if (op_code == GATT_REQ_READ_BY_GRP_TYPE || + op_code == GATT_REQ_FIND_TYPE_VALUE || + op_code == GATT_REQ_READ_BY_TYPE) { + if (len >= 2 && p_uuid_filter != NULL) { + uuid_len = (op_code == GATT_REQ_FIND_TYPE_VALUE) ? 2 : len; + + /* parse uuid now */ + if (gatt_parse_uuid_from_cmd(p_uuid_filter, uuid_len, &p) == false || + p_uuid_filter->len == 0) { + GATT_TRACE_DEBUG("UUID filter does not exsit"); + reason = GATT_INVALID_PDU; + } else + len -= p_uuid_filter->len; + } else reason = GATT_INVALID_PDU; + } + } else + reason = GATT_INVALID_PDU; - *p_data = p; - *p_len = len; - *p_s_hdl = s_hdl; - *p_e_hdl = e_hdl; + *p_data = p; + *p_len = len; + *p_s_hdl = s_hdl; + *p_e_hdl = e_hdl; - return reason; + return reason; } /******************************************************************************* @@ -740,58 +651,52 @@ static tGATT_STATUS gatts_validate_packet_format(uint8_t op_code, uint16_t *p_le * Returns void * ******************************************************************************/ -void gatts_process_primary_service_req(tGATT_TCB *p_tcb, uint8_t op_code, uint16_t len, uint8_t *p_data) -{ - uint8_t reason = GATT_INVALID_PDU; - uint16_t s_hdl = 0, e_hdl = 0; - tBT_UUID uuid, value, primary_service = {LEN_UUID_16, {GATT_UUID_PRI_SERVICE}}; - BT_HDR *p_msg = NULL; - uint16_t msg_len = (uint16_t)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET); - - memset (&value, 0, sizeof(tBT_UUID)); - reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, &e_hdl); - - if (reason == GATT_SUCCESS) - { - if (gatt_uuid_compare(uuid, primary_service)) - { - if (op_code == GATT_REQ_FIND_TYPE_VALUE) - { - if (gatt_parse_uuid_from_cmd(&value, len, &p_data) == false) - reason = GATT_INVALID_PDU; - } - - if (reason == GATT_SUCCESS) { - p_msg = (BT_HDR *)osi_calloc(msg_len); - reason = gatt_build_primary_service_rsp (p_msg, p_tcb, op_code, - s_hdl, e_hdl, p_data, - value); - } - } - else - { - if (op_code == GATT_REQ_READ_BY_GRP_TYPE) - { - reason = GATT_UNSUPPORT_GRP_TYPE; - GATT_TRACE_DEBUG("unexpected ReadByGrpType Group: 0x%04x", uuid.uu.uuid16); - } - else - { - /* we do not support ReadByTypeValue with any non-primamry_service type */ - reason = GATT_NOT_FOUND; - GATT_TRACE_DEBUG("unexpected ReadByTypeValue type: 0x%04x", uuid.uu.uuid16); - } - } - } - - if (reason != GATT_SUCCESS) - { - osi_free(p_msg); - gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, false); +void gatts_process_primary_service_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + uint8_t reason = GATT_INVALID_PDU; + uint16_t s_hdl = 0, e_hdl = 0; + tBT_UUID uuid, value, + primary_service = {LEN_UUID_16, {GATT_UUID_PRI_SERVICE}}; + BT_HDR* p_msg = NULL; + uint16_t msg_len = + (uint16_t)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET); + + memset(&value, 0, sizeof(tBT_UUID)); + reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, + &e_hdl); + + if (reason == GATT_SUCCESS) { + if (gatt_uuid_compare(uuid, primary_service)) { + if (op_code == GATT_REQ_FIND_TYPE_VALUE) { + if (gatt_parse_uuid_from_cmd(&value, len, &p_data) == false) + reason = GATT_INVALID_PDU; + } + + if (reason == GATT_SUCCESS) { + p_msg = (BT_HDR*)osi_calloc(msg_len); + reason = gatt_build_primary_service_rsp(p_msg, p_tcb, op_code, s_hdl, + e_hdl, p_data, value); + } + } else { + if (op_code == GATT_REQ_READ_BY_GRP_TYPE) { + reason = GATT_UNSUPPORT_GRP_TYPE; + GATT_TRACE_DEBUG("unexpected ReadByGrpType Group: 0x%04x", + uuid.uu.uuid16); + } else { + /* we do not support ReadByTypeValue with any non-primamry_service type + */ + reason = GATT_NOT_FOUND; + GATT_TRACE_DEBUG("unexpected ReadByTypeValue type: 0x%04x", + uuid.uu.uuid16); + } } - else - attp_send_sr_msg(p_tcb, p_msg); + } + if (reason != GATT_SUCCESS) { + osi_free(p_msg); + gatt_send_error_rsp(p_tcb, reason, op_code, s_hdl, false); + } else + attp_send_sr_msg(p_tcb, p_msg); } /******************************************************************************* @@ -804,59 +709,55 @@ void gatts_process_primary_service_req(tGATT_TCB *p_tcb, uint8_t op_code, uint16 * Returns void * ******************************************************************************/ -static void gatts_process_find_info(tGATT_TCB *p_tcb, uint8_t op_code, uint16_t len, uint8_t *p_data) -{ - uint8_t reason = GATT_INVALID_PDU, *p; - uint16_t s_hdl = 0, e_hdl = 0, buf_len; - BT_HDR *p_msg = NULL; - tGATT_SR_REG *p_rcb; - tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info; - tGATT_SRV_LIST_ELEM *p_srv=NULL; - - reason = gatts_validate_packet_format(op_code, &len, &p_data, NULL, &s_hdl, &e_hdl); - - if (reason == GATT_SUCCESS) - { - buf_len = (uint16_t)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET); - - p_msg = (BT_HDR *)osi_calloc(buf_len); - reason = GATT_NOT_FOUND; +static void gatts_process_find_info(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + uint8_t reason = GATT_INVALID_PDU, *p; + uint16_t s_hdl = 0, e_hdl = 0, buf_len; + BT_HDR* p_msg = NULL; + tGATT_SR_REG* p_rcb; + tGATT_SRV_LIST_INFO* p_list = &gatt_cb.srv_list_info; + tGATT_SRV_LIST_ELEM* p_srv = NULL; - p = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; - *p ++ = op_code + 1; - p_msg->len = 2; + reason = gatts_validate_packet_format(op_code, &len, &p_data, NULL, &s_hdl, + &e_hdl); - buf_len = p_tcb->payload_size - 2; + if (reason == GATT_SUCCESS) { + buf_len = + (uint16_t)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET); - p_srv = p_list->p_first; + p_msg = (BT_HDR*)osi_calloc(buf_len); + reason = GATT_NOT_FOUND; - while (p_srv) { - p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); + p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; + *p++ = op_code + 1; + p_msg->len = 2; - if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl || - p_rcb->e_hdl < s_hdl)) { - reason = gatt_build_find_info_rsp(p_rcb, p_msg, &buf_len, - s_hdl, e_hdl); - if (reason == GATT_NO_RESOURCES) { - reason = GATT_SUCCESS; - break; - } - } - p_srv = p_srv->p_next; - } - *p = (uint8_t)p_msg->offset; + buf_len = p_tcb->payload_size - 2; - p_msg->offset = L2CAP_MIN_OFFSET; - } + p_srv = p_list->p_first; - if (reason != GATT_SUCCESS) - { - osi_free(p_msg); - gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, false); + while (p_srv) { + p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); + + if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl || p_rcb->e_hdl < s_hdl)) { + reason = gatt_build_find_info_rsp(p_rcb, p_msg, &buf_len, s_hdl, e_hdl); + if (reason == GATT_NO_RESOURCES) { + reason = GATT_SUCCESS; + break; + } + } + p_srv = p_srv->p_next; } - else - attp_send_sr_msg(p_tcb, p_msg); + *p = (uint8_t)p_msg->offset; + p_msg->offset = L2CAP_MIN_OFFSET; + } + + if (reason != GATT_SUCCESS) { + osi_free(p_msg); + gatt_send_error_rsp(p_tcb, reason, op_code, s_hdl, false); + } else + attp_send_sr_msg(p_tcb, p_msg); } /******************************************************************************* @@ -869,59 +770,53 @@ static void gatts_process_find_info(tGATT_TCB *p_tcb, uint8_t op_code, uint16_t * Returns void * ******************************************************************************/ -static void gatts_process_mtu_req (tGATT_TCB *p_tcb, uint16_t len, uint8_t *p_data) -{ - uint16_t mtu = 0; - uint8_t *p = p_data, i; - BT_HDR *p_buf; - uint16_t conn_id; - - /* BR/EDR conenction, send error response */ - if (p_tcb->att_lcid != L2CAP_ATT_CID) - { - gatt_send_error_rsp (p_tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, false); - } - else if (len < GATT_MTU_REQ_MIN_LEN) - { - GATT_TRACE_ERROR("invalid MTU request PDU received."); - gatt_send_error_rsp (p_tcb, GATT_INVALID_PDU, GATT_REQ_MTU, 0, false); - } +static void gatts_process_mtu_req(tGATT_TCB* p_tcb, uint16_t len, + uint8_t* p_data) { + uint16_t mtu = 0; + uint8_t *p = p_data, i; + BT_HDR* p_buf; + uint16_t conn_id; + + /* BR/EDR conenction, send error response */ + if (p_tcb->att_lcid != L2CAP_ATT_CID) { + gatt_send_error_rsp(p_tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, false); + } else if (len < GATT_MTU_REQ_MIN_LEN) { + GATT_TRACE_ERROR("invalid MTU request PDU received."); + gatt_send_error_rsp(p_tcb, GATT_INVALID_PDU, GATT_REQ_MTU, 0, false); + } else { + STREAM_TO_UINT16(mtu, p); + /* mtu must be greater than default MTU which is 23/48 */ + if (mtu < GATT_DEF_BLE_MTU_SIZE) + p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; + else if (mtu > GATT_MAX_MTU_SIZE) + p_tcb->payload_size = GATT_MAX_MTU_SIZE; else - { - STREAM_TO_UINT16 (mtu, p); - /* mtu must be greater than default MTU which is 23/48 */ - if (mtu < GATT_DEF_BLE_MTU_SIZE) - p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE; - else if (mtu > GATT_MAX_MTU_SIZE) - p_tcb->payload_size = GATT_MAX_MTU_SIZE; - else - p_tcb->payload_size = mtu; - - GATT_TRACE_ERROR("MTU request PDU with MTU size %d", p_tcb->payload_size); - - l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); - - p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, - (tGATT_SR_MSG *)&p_tcb->payload_size); - if (p_buf != NULL) - { - attp_send_sr_msg (p_tcb, p_buf); - - /* Notify all registered applicaiton with new MTU size. Us a transaction ID */ - /* of 0, as no response is allowed from applcations */ - - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (gatt_cb.cl_rcb[i].in_use ) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_cb.cl_rcb[i].gatt_if); - gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, - (tGATTS_DATA *)&p_tcb->payload_size); - } - } + p_tcb->payload_size = mtu; + + GATT_TRACE_ERROR("MTU request PDU with MTU size %d", p_tcb->payload_size); + l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, + p_tcb->payload_size); + + p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, + (tGATT_SR_MSG*)&p_tcb->payload_size); + if (p_buf != NULL) { + attp_send_sr_msg(p_tcb, p_buf); + + /* Notify all registered applicaiton with new MTU size. Us a transaction + * ID */ + /* of 0, as no response is allowed from applcations */ + + for (i = 0; i < GATT_MAX_APPS; i++) { + if (gatt_cb.cl_rcb[i].in_use) { + conn_id = + GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_cb.cl_rcb[i].gatt_if); + gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, + (tGATTS_DATA*)&p_tcb->payload_size); } + } } + } } /******************************************************************************* @@ -939,93 +834,82 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, uint16_t len, uint8_t *p_da * Returns void * ******************************************************************************/ -void gatts_process_read_by_type_req(tGATT_TCB *p_tcb, uint8_t op_code, uint16_t len, uint8_t *p_data) -{ - tBT_UUID uuid; - tGATT_SR_REG *p_rcb; - size_t msg_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET; - uint16_t buf_len, s_hdl, e_hdl, err_hdl = 0; - BT_HDR *p_msg = NULL; - tGATT_STATUS reason, ret; - uint8_t *p; - uint8_t sec_flag, key_size; - tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info; - tGATT_SRV_LIST_ELEM *p_srv=NULL; - - reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, &e_hdl); +void gatts_process_read_by_type_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + tBT_UUID uuid; + tGATT_SR_REG* p_rcb; + size_t msg_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET; + uint16_t buf_len, s_hdl, e_hdl, err_hdl = 0; + BT_HDR* p_msg = NULL; + tGATT_STATUS reason, ret; + uint8_t* p; + uint8_t sec_flag, key_size; + tGATT_SRV_LIST_INFO* p_list = &gatt_cb.srv_list_info; + tGATT_SRV_LIST_ELEM* p_srv = NULL; + + reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, + &e_hdl); #if (GATT_CONFORMANCE_TESTING == TRUE) - if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) - { - GATT_TRACE_DEBUG("Conformance tst: forced err rsp for ReadByType: error status=%d", gatt_cb.err_status); + if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { + GATT_TRACE_DEBUG( + "Conformance tst: forced err rsp for ReadByType: error status=%d", + gatt_cb.err_status); - gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, s_hdl, false); + gatt_send_error_rsp(p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, s_hdl, + false); - return; - } + return; + } #endif - if (reason == GATT_SUCCESS) - { - p_msg = (BT_HDR *)osi_calloc(msg_len); - p = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; + if (reason == GATT_SUCCESS) { + p_msg = (BT_HDR*)osi_calloc(msg_len); + p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; - *p ++ = op_code + 1; - /* reserve length byte */ - p_msg->len = 2; - buf_len = p_tcb->payload_size - 2; + *p++ = op_code + 1; + /* reserve length byte */ + p_msg->len = 2; + buf_len = p_tcb->payload_size - 2; - reason = GATT_NOT_FOUND; + reason = GATT_NOT_FOUND; - p_srv = p_list->p_first; - - while (p_srv) { - p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); - - if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl || - p_rcb->e_hdl < s_hdl)) { - gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, - &sec_flag, &key_size); - - ret = gatts_db_read_attr_value_by_type(p_tcb, - p_rcb->p_db, - op_code, - p_msg, - s_hdl, - e_hdl, - uuid, - &buf_len, - sec_flag, - key_size, - 0, - &err_hdl); - if (ret != GATT_NOT_FOUND) { - reason = ret; - - if (ret == GATT_NO_RESOURCES) - reason = GATT_SUCCESS; - } - if (ret != GATT_SUCCESS && ret != GATT_NOT_FOUND) { - s_hdl = err_hdl; - break; - } - } - p_srv = p_srv->p_next; - } - *p = (uint8_t)p_msg->offset; - p_msg->offset = L2CAP_MIN_OFFSET; - } - if (reason != GATT_SUCCESS) - { - osi_free(p_msg); + p_srv = p_list->p_first; - /* in theroy BUSY is not possible(should already been checked), protected check */ - if (reason != GATT_PENDING && reason != GATT_BUSY) - gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, false); - } - else - attp_send_sr_msg(p_tcb, p_msg); + while (p_srv) { + p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); + if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl || p_rcb->e_hdl < s_hdl)) { + gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag, + &key_size); + + ret = gatts_db_read_attr_value_by_type( + p_tcb, p_rcb->p_db, op_code, p_msg, s_hdl, e_hdl, uuid, &buf_len, + sec_flag, key_size, 0, &err_hdl); + if (ret != GATT_NOT_FOUND) { + reason = ret; + + if (ret == GATT_NO_RESOURCES) reason = GATT_SUCCESS; + } + if (ret != GATT_SUCCESS && ret != GATT_NOT_FOUND) { + s_hdl = err_hdl; + break; + } + } + p_srv = p_srv->p_next; + } + *p = (uint8_t)p_msg->offset; + p_msg->offset = L2CAP_MIN_OFFSET; + } + if (reason != GATT_SUCCESS) { + osi_free(p_msg); + + /* in theroy BUSY is not possible(should already been checked), protected + * check */ + if (reason != GATT_PENDING && reason != GATT_BUSY) + gatt_send_error_rsp(p_tcb, reason, op_code, s_hdl, false); + } else + attp_send_sr_msg(p_tcb, p_msg); } /******************************************************************************* @@ -1038,103 +922,92 @@ void gatts_process_read_by_type_req(tGATT_TCB *p_tcb, uint8_t op_code, uint16_t * Returns void * ******************************************************************************/ -void gatts_process_write_req (tGATT_TCB *p_tcb, uint8_t i_rcb, uint16_t handle, - uint8_t op_code, uint16_t len, uint8_t *p_data, - bt_gatt_db_attribute_type_t gatt_type) -{ - tGATTS_DATA sr_data; - uint32_t trans_id; - tGATT_STATUS status; - uint8_t sec_flag, key_size, *p = p_data; - tGATT_SR_REG *p_sreg; - uint16_t conn_id; - - memset(&sr_data, 0, sizeof(tGATTS_DATA)); - - switch (op_code) - { - case GATT_REQ_PREPARE_WRITE: - if (len < 2) { - GATT_TRACE_ERROR("%s: Prepare write request was invalid - missing offset, sending error response", __func__); - gatt_send_error_rsp(p_tcb, GATT_INVALID_PDU, op_code, handle, false); - return; - } - sr_data.write_req.is_prep = true; - STREAM_TO_UINT16(sr_data.write_req.offset, p); - len -= 2; - /* fall through */ - case GATT_SIGN_CMD_WRITE: - if (op_code == GATT_SIGN_CMD_WRITE) - { - GATT_TRACE_DEBUG("Write CMD with data sigining" ); - len -= GATT_AUTH_SIGN_LEN; - } - /* fall through */ - case GATT_CMD_WRITE: - case GATT_REQ_WRITE: - if (op_code == GATT_REQ_WRITE || op_code == GATT_REQ_PREPARE_WRITE) - sr_data.write_req.need_rsp = true; - sr_data.write_req.handle = handle; - sr_data.write_req.len = len; - if (len != 0 && p != NULL) - { - memcpy (sr_data.write_req.value, p, len); - } - break; - } - - gatt_sr_get_sec_info(p_tcb->peer_bda, - p_tcb->transport, - &sec_flag, - &key_size); - - status = gatts_write_attr_perm_check (gatt_cb.sr_reg[i_rcb].p_db, - op_code, - handle, - sr_data.write_req.offset, - p, - len, - sec_flag, - key_size); - - if (status == GATT_SUCCESS) - { - trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); - if (trans_id != 0) - { - p_sreg = &gatt_cb.sr_reg[i_rcb]; - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_sreg->gatt_if); - - uint8_t opcode = 0; - if (gatt_type == BTGATT_DB_DESCRIPTOR) { - opcode = GATTS_REQ_TYPE_WRITE_DESCRIPTOR; - } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) { - opcode = GATTS_REQ_TYPE_WRITE_CHARACTERISTIC; - } else { - GATT_TRACE_ERROR("%s: Attempt to write attribute that's not tied with" - " characteristic or descriptor value.", __func__); - status = GATT_ERROR; - } - - if (opcode) { - gatt_sr_send_req_callback(conn_id, trans_id, opcode, &sr_data); - status = GATT_PENDING; - } - } - else - { - GATT_TRACE_ERROR("max pending command, send error"); - status = GATT_BUSY; /* max pending command, application error */ - } - } - - /* in theroy BUSY is not possible(should already been checked), protected check */ - if (status != GATT_PENDING && status != GATT_BUSY && - (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_REQ_WRITE)) - { - gatt_send_error_rsp (p_tcb, status, op_code, handle, false); +void gatts_process_write_req(tGATT_TCB* p_tcb, uint8_t i_rcb, uint16_t handle, + uint8_t op_code, uint16_t len, uint8_t* p_data, + bt_gatt_db_attribute_type_t gatt_type) { + tGATTS_DATA sr_data; + uint32_t trans_id; + tGATT_STATUS status; + uint8_t sec_flag, key_size, *p = p_data; + tGATT_SR_REG* p_sreg; + uint16_t conn_id; + + memset(&sr_data, 0, sizeof(tGATTS_DATA)); + + switch (op_code) { + case GATT_REQ_PREPARE_WRITE: + if (len < 2) { + GATT_TRACE_ERROR( + "%s: Prepare write request was invalid - missing offset, sending " + "error response", + __func__); + gatt_send_error_rsp(p_tcb, GATT_INVALID_PDU, op_code, handle, false); + return; + } + sr_data.write_req.is_prep = true; + STREAM_TO_UINT16(sr_data.write_req.offset, p); + len -= 2; + /* fall through */ + case GATT_SIGN_CMD_WRITE: + if (op_code == GATT_SIGN_CMD_WRITE) { + GATT_TRACE_DEBUG("Write CMD with data sigining"); + len -= GATT_AUTH_SIGN_LEN; + } + /* fall through */ + case GATT_CMD_WRITE: + case GATT_REQ_WRITE: + if (op_code == GATT_REQ_WRITE || op_code == GATT_REQ_PREPARE_WRITE) + sr_data.write_req.need_rsp = true; + sr_data.write_req.handle = handle; + sr_data.write_req.len = len; + if (len != 0 && p != NULL) { + memcpy(sr_data.write_req.value, p, len); + } + break; + } + + gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag, &key_size); + + status = gatts_write_attr_perm_check(gatt_cb.sr_reg[i_rcb].p_db, op_code, + handle, sr_data.write_req.offset, p, len, + sec_flag, key_size); + + if (status == GATT_SUCCESS) { + trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); + if (trans_id != 0) { + p_sreg = &gatt_cb.sr_reg[i_rcb]; + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_sreg->gatt_if); + + uint8_t opcode = 0; + if (gatt_type == BTGATT_DB_DESCRIPTOR) { + opcode = GATTS_REQ_TYPE_WRITE_DESCRIPTOR; + } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) { + opcode = GATTS_REQ_TYPE_WRITE_CHARACTERISTIC; + } else { + GATT_TRACE_ERROR( + "%s: Attempt to write attribute that's not tied with" + " characteristic or descriptor value.", + __func__); + status = GATT_ERROR; + } + + if (opcode) { + gatt_sr_send_req_callback(conn_id, trans_id, opcode, &sr_data); + status = GATT_PENDING; + } + } else { + GATT_TRACE_ERROR("max pending command, send error"); + status = GATT_BUSY; /* max pending command, application error */ } - return; + } + + /* in theroy BUSY is not possible(should already been checked), protected + * check */ + if (status != GATT_PENDING && status != GATT_BUSY && + (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_REQ_WRITE)) { + gatt_send_error_rsp(p_tcb, status, op_code, handle, false); + } + return; } /******************************************************************************* @@ -1147,52 +1020,39 @@ void gatts_process_write_req (tGATT_TCB *p_tcb, uint8_t i_rcb, uint16_t handle, * Returns void * ******************************************************************************/ -static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, uint8_t op_code, - uint16_t handle, - UNUSED_ATTR uint16_t len, uint8_t *p_data) -{ - size_t buf_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET; - tGATT_STATUS reason; - uint8_t sec_flag, key_size, *p; - uint16_t offset = 0, value_len = 0; - BT_HDR *p_msg = (BT_HDR *)osi_calloc(buf_len); - - if (op_code == GATT_REQ_READ_BLOB) - STREAM_TO_UINT16(offset, p_data); - - p = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; - *p ++ = op_code + 1; - p_msg->len = 1; - buf_len = p_tcb->payload_size - 1; - - gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag, - &key_size); - - reason = gatts_read_attr_value_by_handle(p_tcb, - p_rcb->p_db, - op_code, - handle, - offset, - p, - &value_len, - (uint16_t)buf_len, - sec_flag, - key_size, - 0); - - p_msg->len += value_len; - - if (reason != GATT_SUCCESS) - { - osi_free(p_msg); - - /* in theroy BUSY is not possible(should already been checked), protected check */ - if (reason != GATT_PENDING && reason != GATT_BUSY) - gatt_send_error_rsp (p_tcb, reason, op_code, handle, false); - } - else - attp_send_sr_msg(p_tcb, p_msg); - +static void gatts_process_read_req(tGATT_TCB* p_tcb, tGATT_SR_REG* p_rcb, + uint8_t op_code, uint16_t handle, + UNUSED_ATTR uint16_t len, uint8_t* p_data) { + size_t buf_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET; + tGATT_STATUS reason; + uint8_t sec_flag, key_size, *p; + uint16_t offset = 0, value_len = 0; + BT_HDR* p_msg = (BT_HDR*)osi_calloc(buf_len); + + if (op_code == GATT_REQ_READ_BLOB) STREAM_TO_UINT16(offset, p_data); + + p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; + *p++ = op_code + 1; + p_msg->len = 1; + buf_len = p_tcb->payload_size - 1; + + gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag, &key_size); + + reason = gatts_read_attr_value_by_handle( + p_tcb, p_rcb->p_db, op_code, handle, offset, p, &value_len, + (uint16_t)buf_len, sec_flag, key_size, 0); + + p_msg->len += value_len; + + if (reason != GATT_SUCCESS) { + osi_free(p_msg); + + /* in theroy BUSY is not possible(should already been checked), protected + * check */ + if (reason != GATT_PENDING && reason != GATT_BUSY) + gatt_send_error_rsp(p_tcb, reason, op_code, handle, false); + } else + attp_send_sr_msg(p_tcb, p_msg); } /******************************************************************************* @@ -1205,79 +1065,71 @@ static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, uint8_ * Returns void * ******************************************************************************/ -void gatts_process_attribute_req (tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - uint16_t handle = 0; - uint8_t *p = p_data, i; - tGATT_SR_REG *p_rcb = gatt_cb.sr_reg; - tGATT_STATUS status = GATT_INVALID_HANDLE; - tGATT_ATTR *p_attr; - - if (len < 2) - { - GATT_TRACE_ERROR("Illegal PDU length, discard request"); - status = GATT_INVALID_PDU; - } - else - { - STREAM_TO_UINT16(handle, p); - len -= 2; - } +void gatts_process_attribute_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + uint16_t handle = 0; + uint8_t *p = p_data, i; + tGATT_SR_REG* p_rcb = gatt_cb.sr_reg; + tGATT_STATUS status = GATT_INVALID_HANDLE; + tGATT_ATTR* p_attr; + + if (len < 2) { + GATT_TRACE_ERROR("Illegal PDU length, discard request"); + status = GATT_INVALID_PDU; + } else { + STREAM_TO_UINT16(handle, p); + len -= 2; + } #if (GATT_CONFORMANCE_TESTING == TRUE) - gatt_cb.handle = handle; - if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) - { - GATT_TRACE_DEBUG("Conformance tst: forced err rsp: error status=%d", gatt_cb.err_status); + gatt_cb.handle = handle; + if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { + GATT_TRACE_DEBUG("Conformance tst: forced err rsp: error status=%d", + gatt_cb.err_status); - gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, false); + gatt_send_error_rsp(p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, + false); - return; - } + return; + } #endif - if (GATT_HANDLE_IS_VALID(handle)) - { - for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_rcb ++) - { - if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle) - { - p_attr = (tGATT_ATTR *)p_rcb->p_db->p_attr_list; - - while (p_attr) - { - if (p_attr->handle == handle) - { - switch (op_code) - { - case GATT_REQ_READ: /* read char/char descriptor value */ - case GATT_REQ_READ_BLOB: - gatts_process_read_req(p_tcb, p_rcb, op_code, handle, len, p); - break; - - case GATT_REQ_WRITE: /* write char/char descriptor value */ - case GATT_CMD_WRITE: - case GATT_SIGN_CMD_WRITE: - case GATT_REQ_PREPARE_WRITE: - gatts_process_write_req(p_tcb, i, handle, op_code, len, p, - p_attr->gatt_type); - break; - default: - break; - } - status = GATT_SUCCESS; - break; - } - p_attr = (tGATT_ATTR *)p_attr->p_next; - } + if (GATT_HANDLE_IS_VALID(handle)) { + for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_rcb++) { + if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle) { + p_attr = (tGATT_ATTR*)p_rcb->p_db->p_attr_list; + + while (p_attr) { + if (p_attr->handle == handle) { + switch (op_code) { + case GATT_REQ_READ: /* read char/char descriptor value */ + case GATT_REQ_READ_BLOB: + gatts_process_read_req(p_tcb, p_rcb, op_code, handle, len, p); + break; + + case GATT_REQ_WRITE: /* write char/char descriptor value */ + case GATT_CMD_WRITE: + case GATT_SIGN_CMD_WRITE: + case GATT_REQ_PREPARE_WRITE: + gatts_process_write_req(p_tcb, i, handle, op_code, len, p, + p_attr->gatt_type); + break; + default: break; } + status = GATT_SUCCESS; + break; + } + p_attr = (tGATT_ATTR*)p_attr->p_next; } + break; + } } + } - if (status != GATT_SUCCESS && op_code != GATT_CMD_WRITE && op_code != GATT_SIGN_CMD_WRITE) - gatt_send_error_rsp (p_tcb, status, op_code, handle, false); + if (status != GATT_SUCCESS && op_code != GATT_CMD_WRITE && + op_code != GATT_SIGN_CMD_WRITE) + gatt_send_error_rsp(p_tcb, status, op_code, handle, false); } /******************************************************************************* @@ -1289,22 +1141,21 @@ void gatts_process_attribute_req (tGATT_TCB *p_tcb, uint8_t op_code, * Returns void * ******************************************************************************/ -static void gatts_proc_srv_chg_ind_ack(tGATT_TCB *p_tcb ) -{ - tGATTS_SRV_CHG_REQ req; - tGATTS_SRV_CHG *p_buf = NULL; - - GATT_TRACE_DEBUG("gatts_proc_srv_chg_ind_ack"); - - p_buf = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); - if (p_buf != NULL) - { - GATT_TRACE_DEBUG("NV update set srv chg = false"); - p_buf->srv_changed = false; - memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG)); - if (gatt_cb.cb_info.p_srv_chg_callback) - (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT,&req, NULL); - } +static void gatts_proc_srv_chg_ind_ack(tGATT_TCB* p_tcb) { + tGATTS_SRV_CHG_REQ req; + tGATTS_SRV_CHG* p_buf = NULL; + + GATT_TRACE_DEBUG("gatts_proc_srv_chg_ind_ack"); + + p_buf = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda); + if (p_buf != NULL) { + GATT_TRACE_DEBUG("NV update set srv chg = false"); + p_buf->srv_changed = false; + memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG)); + if (gatt_cb.cb_info.p_srv_chg_callback) + (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT, + &req, NULL); + } } /******************************************************************************* @@ -1317,20 +1168,16 @@ static void gatts_proc_srv_chg_ind_ack(tGATT_TCB *p_tcb ) * Returns void * ******************************************************************************/ -static void gatts_chk_pending_ind(tGATT_TCB *p_tcb ) -{ - GATT_TRACE_DEBUG("%s", __func__); - - tGATT_VALUE *p_buf = (tGATT_VALUE *)fixed_queue_try_peek_first(p_tcb->pending_ind_q); - if (p_buf != NULL) - { - GATTS_HandleValueIndication(p_buf->conn_id, - p_buf->handle, - p_buf->len, - p_buf->value); - osi_free(fixed_queue_try_remove_from_queue(p_tcb->pending_ind_q, - p_buf)); - } +static void gatts_chk_pending_ind(tGATT_TCB* p_tcb) { + GATT_TRACE_DEBUG("%s", __func__); + + tGATT_VALUE* p_buf = + (tGATT_VALUE*)fixed_queue_try_peek_first(p_tcb->pending_ind_q); + if (p_buf != NULL) { + GATTS_HandleValueIndication(p_buf->conn_id, p_buf->handle, p_buf->len, + p_buf->value); + osi_free(fixed_queue_try_remove_from_queue(p_tcb->pending_ind_q, p_buf)); + } } /******************************************************************************* @@ -1343,21 +1190,20 @@ static void gatts_chk_pending_ind(tGATT_TCB *p_tcb ) * application if the ACK is not a Service Changed Indication * ******************************************************************************/ -static bool gatts_proc_ind_ack(tGATT_TCB *p_tcb, uint16_t ack_handle) -{ - bool continue_processing = true; +static bool gatts_proc_ind_ack(tGATT_TCB* p_tcb, uint16_t ack_handle) { + bool continue_processing = true; - GATT_TRACE_DEBUG ("gatts_proc_ind_ack ack handle=%d", ack_handle); + GATT_TRACE_DEBUG("gatts_proc_ind_ack ack handle=%d", ack_handle); - if (ack_handle == gatt_cb.handle_of_h_r) - { - gatts_proc_srv_chg_ind_ack(p_tcb); - /* there is no need to inform the application since srv chg is handled internally by GATT */ - continue_processing = false; - } + if (ack_handle == gatt_cb.handle_of_h_r) { + gatts_proc_srv_chg_ind_ack(p_tcb); + /* there is no need to inform the application since srv chg is handled + * internally by GATT */ + continue_processing = false; + } - gatts_chk_pending_ind(p_tcb); - return continue_processing; + gatts_chk_pending_ind(p_tcb); + return continue_processing; } /******************************************************************************* @@ -1370,39 +1216,32 @@ static bool gatts_proc_ind_ack(tGATT_TCB *p_tcb, uint16_t ack_handle) * Returns void * ******************************************************************************/ -void gatts_process_value_conf(tGATT_TCB *p_tcb, uint8_t op_code) -{ - uint16_t handle = p_tcb->indicate_handle; - uint32_t trans_id; - uint8_t i; - tGATT_SR_REG *p_rcb = gatt_cb.sr_reg; - bool continue_processing; - uint16_t conn_id; - - alarm_cancel(p_tcb->conf_timer); - if (GATT_HANDLE_IS_VALID(handle)) - { - p_tcb->indicate_handle = 0; - continue_processing = gatts_proc_ind_ack(p_tcb, handle); - - if (continue_processing) - { - for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_rcb ++) - { - if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle) - { - trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_rcb->gatt_if); - gatt_sr_send_req_callback(conn_id, - trans_id, GATTS_REQ_TYPE_CONF, (tGATTS_DATA *)&handle); - } - } +void gatts_process_value_conf(tGATT_TCB* p_tcb, uint8_t op_code) { + uint16_t handle = p_tcb->indicate_handle; + uint32_t trans_id; + uint8_t i; + tGATT_SR_REG* p_rcb = gatt_cb.sr_reg; + bool continue_processing; + uint16_t conn_id; + + alarm_cancel(p_tcb->conf_timer); + if (GATT_HANDLE_IS_VALID(handle)) { + p_tcb->indicate_handle = 0; + continue_processing = gatts_proc_ind_ack(p_tcb, handle); + + if (continue_processing) { + for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_rcb++) { + if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle) { + trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle); + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_rcb->gatt_if); + gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_CONF, + (tGATTS_DATA*)&handle); } + } } - else - { - GATT_TRACE_ERROR("unexpected handle value confirmation"); - } + } else { + GATT_TRACE_ERROR("unexpected handle value confirmation"); + } } /******************************************************************************* @@ -1416,73 +1255,67 @@ void gatts_process_value_conf(tGATT_TCB *p_tcb, uint8_t op_code) * Returns void * ******************************************************************************/ -void gatt_server_handle_client_req (tGATT_TCB *p_tcb, uint8_t op_code, - uint16_t len, uint8_t *p_data) -{ - /* there is pending command, discard this one */ - if (!gatt_sr_cmd_empty(p_tcb) && op_code != GATT_HANDLE_VALUE_CONF) - return; - - /* the size of the message may not be bigger than the local max PDU size*/ - /* The message has to be smaller than the agreed MTU, len does not include op code */ - if (len >= p_tcb->payload_size) - { - GATT_TRACE_ERROR("server receive invalid PDU size:%d pdu size:%d", len + 1, p_tcb->payload_size ); - /* for invalid request expecting response, send it now */ - if (op_code != GATT_CMD_WRITE && - op_code != GATT_SIGN_CMD_WRITE && - op_code != GATT_HANDLE_VALUE_CONF) - { - gatt_send_error_rsp (p_tcb, GATT_INVALID_PDU, op_code, 0, false); - } - /* otherwise, ignore the pkt */ +void gatt_server_handle_client_req(tGATT_TCB* p_tcb, uint8_t op_code, + uint16_t len, uint8_t* p_data) { + /* there is pending command, discard this one */ + if (!gatt_sr_cmd_empty(p_tcb) && op_code != GATT_HANDLE_VALUE_CONF) return; + + /* the size of the message may not be bigger than the local max PDU size*/ + /* The message has to be smaller than the agreed MTU, len does not include op + * code */ + if (len >= p_tcb->payload_size) { + GATT_TRACE_ERROR("server receive invalid PDU size:%d pdu size:%d", len + 1, + p_tcb->payload_size); + /* for invalid request expecting response, send it now */ + if (op_code != GATT_CMD_WRITE && op_code != GATT_SIGN_CMD_WRITE && + op_code != GATT_HANDLE_VALUE_CONF) { + gatt_send_error_rsp(p_tcb, GATT_INVALID_PDU, op_code, 0, false); } - else - { - switch (op_code) - { - case GATT_REQ_READ_BY_GRP_TYPE: /* discover primary services */ - case GATT_REQ_FIND_TYPE_VALUE: /* discover service by UUID */ - gatts_process_primary_service_req (p_tcb, op_code, len, p_data); - break; - - case GATT_REQ_FIND_INFO:/* discover char descrptor */ - gatts_process_find_info(p_tcb, op_code, len, p_data); - break; - - case GATT_REQ_READ_BY_TYPE: /* read characteristic value, char descriptor value */ - /* discover characteristic, discover char by UUID */ - gatts_process_read_by_type_req(p_tcb, op_code, len, p_data); - break; - - - case GATT_REQ_READ: /* read char/char descriptor value */ - case GATT_REQ_READ_BLOB: - case GATT_REQ_WRITE: /* write char/char descriptor value */ - case GATT_CMD_WRITE: - case GATT_SIGN_CMD_WRITE: - case GATT_REQ_PREPARE_WRITE: - gatts_process_attribute_req (p_tcb, op_code, len, p_data); - break; - - case GATT_HANDLE_VALUE_CONF: - gatts_process_value_conf (p_tcb, op_code); - break; - - case GATT_REQ_MTU: - gatts_process_mtu_req (p_tcb, len, p_data); - break; - - case GATT_REQ_EXEC_WRITE: - gatt_process_exec_write_req (p_tcb, op_code, len, p_data); - break; - - case GATT_REQ_READ_MULTI: - gatt_process_read_multi_req (p_tcb, op_code, len, p_data); - break; - - default: - break; - } + /* otherwise, ignore the pkt */ + } else { + switch (op_code) { + case GATT_REQ_READ_BY_GRP_TYPE: /* discover primary services */ + case GATT_REQ_FIND_TYPE_VALUE: /* discover service by UUID */ + gatts_process_primary_service_req(p_tcb, op_code, len, p_data); + break; + + case GATT_REQ_FIND_INFO: /* discover char descrptor */ + gatts_process_find_info(p_tcb, op_code, len, p_data); + break; + + case GATT_REQ_READ_BY_TYPE: /* read characteristic value, char descriptor + value */ + /* discover characteristic, discover char by UUID */ + gatts_process_read_by_type_req(p_tcb, op_code, len, p_data); + break; + + case GATT_REQ_READ: /* read char/char descriptor value */ + case GATT_REQ_READ_BLOB: + case GATT_REQ_WRITE: /* write char/char descriptor value */ + case GATT_CMD_WRITE: + case GATT_SIGN_CMD_WRITE: + case GATT_REQ_PREPARE_WRITE: + gatts_process_attribute_req(p_tcb, op_code, len, p_data); + break; + + case GATT_HANDLE_VALUE_CONF: + gatts_process_value_conf(p_tcb, op_code); + break; + + case GATT_REQ_MTU: + gatts_process_mtu_req(p_tcb, len, p_data); + break; + + case GATT_REQ_EXEC_WRITE: + gatt_process_exec_write_req(p_tcb, op_code, len, p_data); + break; + + case GATT_REQ_READ_MULTI: + gatt_process_read_multi_req(p_tcb, op_code, len, p_data); + break; + + default: + break; } + } } diff --git a/stack/gatt/gatt_utils.cc b/stack/gatt/gatt_utils.cc index e1e3a9c64..e16476688 100644 --- a/stack/gatt/gatt_utils.cc +++ b/stack/gatt/gatt_utils.cc @@ -26,60 +26,58 @@ #include "osi/include/osi.h" #include -#include "stdio.h" #include "bt_common.h" +#include "stdio.h" -#include "l2cdefs.h" -#include "gatt_int.h" +#include "btm_int.h" #include "gatt_api.h" +#include "gatt_int.h" #include "gattdefs.h" +#include "l2cdefs.h" #include "sdp_api.h" -#include "btm_int.h" /* check if [x, y] and [a, b] have overlapping range */ -#define GATT_VALIDATE_HANDLE_RANGE(x, y, a, b) ((y) >= (a) && (x) <= (b)) - -#define GATT_GET_NEXT_VALID_HANDLE(x) (((x)/10 + 1) * 10) - -const char * const op_code_name[] = -{ - "UNKNOWN", - "ATT_RSP_ERROR", - "ATT_REQ_MTU", - "ATT_RSP_MTU", - "ATT_REQ_READ_INFO", - "ATT_RSP_READ_INFO", - "ATT_REQ_FIND_TYPE_VALUE", - "ATT_RSP_FIND_TYPE_VALUE", - "ATT_REQ_READ_BY_TYPE", - "ATT_RSP_READ_BY_TYPE", - "ATT_REQ_READ", - "ATT_RSP_READ", - "ATT_REQ_READ_BLOB", - "ATT_RSP_READ_BLOB", - "GATT_REQ_READ_MULTI", - "GATT_RSP_READ_MULTI", - "GATT_REQ_READ_BY_GRP_TYPE", - "GATT_RSP_READ_BY_GRP_TYPE", - "ATT_REQ_WRITE", - "ATT_RSP_WRITE", - "ATT_CMD_WRITE", - "ATT_SIGN_CMD_WRITE", - "ATT_REQ_PREPARE_WRITE", - "ATT_RSP_PREPARE_WRITE", - "ATT_REQ_EXEC_WRITE", - "ATT_RSP_EXEC_WRITE", - "Reserved", - "ATT_HANDLE_VALUE_NOTIF", - "Reserved", - "ATT_HANDLE_VALUE_IND", - "ATT_HANDLE_VALUE_CONF", - "ATT_OP_CODE_MAX" -}; - -static const uint8_t base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, +#define GATT_VALIDATE_HANDLE_RANGE(x, y, a, b) ((y) >= (a) && (x) <= (b)) + +#define GATT_GET_NEXT_VALID_HANDLE(x) (((x) / 10 + 1) * 10) + +const char* const op_code_name[] = {"UNKNOWN", + "ATT_RSP_ERROR", + "ATT_REQ_MTU", + "ATT_RSP_MTU", + "ATT_REQ_READ_INFO", + "ATT_RSP_READ_INFO", + "ATT_REQ_FIND_TYPE_VALUE", + "ATT_RSP_FIND_TYPE_VALUE", + "ATT_REQ_READ_BY_TYPE", + "ATT_RSP_READ_BY_TYPE", + "ATT_REQ_READ", + "ATT_RSP_READ", + "ATT_REQ_READ_BLOB", + "ATT_RSP_READ_BLOB", + "GATT_REQ_READ_MULTI", + "GATT_RSP_READ_MULTI", + "GATT_REQ_READ_BY_GRP_TYPE", + "GATT_RSP_READ_BY_GRP_TYPE", + "ATT_REQ_WRITE", + "ATT_RSP_WRITE", + "ATT_CMD_WRITE", + "ATT_SIGN_CMD_WRITE", + "ATT_REQ_PREPARE_WRITE", + "ATT_RSP_PREPARE_WRITE", + "ATT_REQ_EXEC_WRITE", + "ATT_RSP_EXEC_WRITE", + "Reserved", + "ATT_HANDLE_VALUE_NOTIF", + "Reserved", + "ATT_HANDLE_VALUE_IND", + "ATT_HANDLE_VALUE_CONF", + "ATT_OP_CODE_MAX"}; + +static const uint8_t base_uuid[LEN_UUID_128] = { + 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -90,18 +88,16 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns None * ******************************************************************************/ -void gatt_free_pending_ind(tGATT_TCB *p_tcb) -{ - GATT_TRACE_DEBUG("%s", __func__); +void gatt_free_pending_ind(tGATT_TCB* p_tcb) { + GATT_TRACE_DEBUG("%s", __func__); - if (p_tcb->pending_ind_q == NULL) - return; + if (p_tcb->pending_ind_q == NULL) return; - /* release all queued indications */ - while (!fixed_queue_is_empty(p_tcb->pending_ind_q)) - osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q)); - fixed_queue_free(p_tcb->pending_ind_q, NULL); - p_tcb->pending_ind_q = NULL; + /* release all queued indications */ + while (!fixed_queue_is_empty(p_tcb->pending_ind_q)) + osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q)); + fixed_queue_free(p_tcb->pending_ind_q, NULL); + p_tcb->pending_ind_q = NULL; } /******************************************************************************* @@ -113,18 +109,16 @@ void gatt_free_pending_ind(tGATT_TCB *p_tcb) * Returns None * ******************************************************************************/ -void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb) -{ - GATT_TRACE_DEBUG("%s", __func__); +void gatt_free_pending_enc_queue(tGATT_TCB* p_tcb) { + GATT_TRACE_DEBUG("%s", __func__); - if (p_tcb->pending_enc_clcb == NULL) - return; + if (p_tcb->pending_enc_clcb == NULL) return; - /* release all queued indications */ - while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb)) - osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb)); - fixed_queue_free(p_tcb->pending_enc_clcb, NULL); - p_tcb->pending_enc_clcb = NULL; + /* release all queued indications */ + while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb)) + osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb)); + fixed_queue_free(p_tcb->pending_enc_clcb, NULL); + p_tcb->pending_enc_clcb = NULL; } /******************************************************************************* @@ -136,23 +130,20 @@ void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb) * Returns None * ******************************************************************************/ -void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr) -{ - GATT_TRACE_DEBUG("gatt_delete_dev_from_srv_chg_clt_list"); +void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr) { + GATT_TRACE_DEBUG("gatt_delete_dev_from_srv_chg_clt_list"); - tGATTS_SRV_CHG *p_buf = gatt_is_bda_in_the_srv_chg_clt_list(bd_addr); - if (p_buf != NULL) - { - if (gatt_cb.cb_info.p_srv_chg_callback) - { - /* delete from NV */ - tGATTS_SRV_CHG_REQ req; - memcpy(req.srv_chg.bda, bd_addr, BD_ADDR_LEN); - (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_REMOVE_CLIENT,&req, NULL); - } - osi_free(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q, - p_buf)); + tGATTS_SRV_CHG* p_buf = gatt_is_bda_in_the_srv_chg_clt_list(bd_addr); + if (p_buf != NULL) { + if (gatt_cb.cb_info.p_srv_chg_callback) { + /* delete from NV */ + tGATTS_SRV_CHG_REQ req; + memcpy(req.srv_chg.bda, bd_addr, BD_ADDR_LEN); + (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_REMOVE_CLIENT, + &req, NULL); } + osi_free(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q, p_buf)); + } } /******************************************************************************* @@ -164,29 +155,27 @@ void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr) * Returns None * ******************************************************************************/ -void gatt_set_srv_chg(void) -{ - GATT_TRACE_DEBUG ("gatt_set_srv_chg"); +void gatt_set_srv_chg(void) { + GATT_TRACE_DEBUG("gatt_set_srv_chg"); - if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) - return; + if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) return; - list_t *list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q); - for (const list_node_t *node = list_begin(list); node != list_end(list); - node = list_next(node)) { - GATT_TRACE_DEBUG ("found a srv_chg clt"); - - tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)list_node(node); - if (!p_buf->srv_changed) - { - GATT_TRACE_DEBUG("set srv_changed to true"); - p_buf->srv_changed = true; - tGATTS_SRV_CHG_REQ req; - memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG)); - if (gatt_cb.cb_info.p_srv_chg_callback) - (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT,&req, NULL); - } + list_t* list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q); + for (const list_node_t* node = list_begin(list); node != list_end(list); + node = list_next(node)) { + GATT_TRACE_DEBUG("found a srv_chg clt"); + + tGATTS_SRV_CHG* p_buf = (tGATTS_SRV_CHG*)list_node(node); + if (!p_buf->srv_changed) { + GATT_TRACE_DEBUG("set srv_changed to true"); + p_buf->srv_changed = true; + tGATTS_SRV_CHG_REQ req; + memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG)); + if (gatt_cb.cb_info.p_srv_chg_callback) + (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT, + &req, NULL); } + } } /******************************************************************************* @@ -199,17 +188,16 @@ void gatt_set_srv_chg(void) * available * ******************************************************************************/ -tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind) -{ - tGATT_VALUE *p_buf = (tGATT_VALUE *)osi_malloc(sizeof(tGATT_VALUE)); +tGATT_VALUE* gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind) { + tGATT_VALUE* p_buf = (tGATT_VALUE*)osi_malloc(sizeof(tGATT_VALUE)); - GATT_TRACE_DEBUG("%s", __func__); - GATT_TRACE_DEBUG("enqueue a pending indication"); + GATT_TRACE_DEBUG("%s", __func__); + GATT_TRACE_DEBUG("enqueue a pending indication"); - memcpy(p_buf, p_ind, sizeof(tGATT_VALUE)); - fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf); + memcpy(p_buf, p_ind, sizeof(tGATT_VALUE)); + fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf); - return p_buf; + return p_buf; } /******************************************************************************* @@ -222,17 +210,16 @@ tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind) * available * ******************************************************************************/ -tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg) -{ - tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)osi_malloc(sizeof(tGATTS_SRV_CHG)); +tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg) { + tGATTS_SRV_CHG* p_buf = (tGATTS_SRV_CHG*)osi_malloc(sizeof(tGATTS_SRV_CHG)); - GATT_TRACE_DEBUG("%s", __func__); - GATT_TRACE_DEBUG("enqueue a srv chg client"); + GATT_TRACE_DEBUG("%s", __func__); + GATT_TRACE_DEBUG("enqueue a srv chg client"); - memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG)); - fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf); + memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG)); + fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf); - return p_buf; + return p_buf; } /******************************************************************************* @@ -244,24 +231,21 @@ tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg) * Returns Pointer to the allocated buffer, NULL no buffer available * ******************************************************************************/ -tGATT_HDL_LIST_ELEM *gatt_alloc_hdl_buffer(void) -{ - uint8_t i; - tGATT_CB *p_cb = &gatt_cb; - tGATT_HDL_LIST_ELEM * p_elem= &p_cb->hdl_list[0]; - - for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_elem++) - { - if (!p_cb->hdl_list[i].in_use) - { - memset(p_elem, 0, sizeof(tGATT_HDL_LIST_ELEM)); - p_elem->in_use = true; - p_elem->svc_db.svc_buffer = fixed_queue_new(SIZE_MAX); - return p_elem; - } +tGATT_HDL_LIST_ELEM* gatt_alloc_hdl_buffer(void) { + uint8_t i; + tGATT_CB* p_cb = &gatt_cb; + tGATT_HDL_LIST_ELEM* p_elem = &p_cb->hdl_list[0]; + + for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_elem++) { + if (!p_cb->hdl_list[i].in_use) { + memset(p_elem, 0, sizeof(tGATT_HDL_LIST_ELEM)); + p_elem->in_use = true; + p_elem->svc_db.svc_buffer = fixed_queue_new(SIZE_MAX); + return p_elem; } + } - return NULL; + return NULL; } /******************************************************************************* @@ -273,22 +257,19 @@ tGATT_HDL_LIST_ELEM *gatt_alloc_hdl_buffer(void) * Returns Pointer to the buffer, NULL no buffer available * ******************************************************************************/ -tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_handle(uint16_t handle) -{ - tGATT_HDL_LIST_INFO *p_list_info= &gatt_cb.hdl_list_info; - tGATT_HDL_LIST_ELEM *p_list = NULL; +tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle) { + tGATT_HDL_LIST_INFO* p_list_info = &gatt_cb.hdl_list_info; + tGATT_HDL_LIST_ELEM* p_list = NULL; - p_list = p_list_info->p_first; + p_list = p_list_info->p_first; - while (p_list != NULL) - { - if (p_list->in_use && p_list->asgn_range.s_handle == handle) - { - return(p_list); - } - p_list = p_list->p_next; + while (p_list != NULL) { + if (p_list->in_use && p_list->asgn_range.s_handle == handle) { + return (p_list); } - return NULL; + p_list = p_list->p_next; + } + return NULL; } /******************************************************************************* * @@ -300,27 +281,24 @@ tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_handle(uint16_t handle) * Returns Pointer to the buffer, NULL no buffer available * ******************************************************************************/ -tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_app_id (tBT_UUID *p_app_uuid128, - tBT_UUID *p_svc_uuid, - uint16_t start_handle) -{ - tGATT_HDL_LIST_INFO *p_list_info= &gatt_cb.hdl_list_info; - tGATT_HDL_LIST_ELEM *p_list = NULL; +tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_app_id(tBT_UUID* p_app_uuid128, + tBT_UUID* p_svc_uuid, + uint16_t start_handle) { + tGATT_HDL_LIST_INFO* p_list_info = &gatt_cb.hdl_list_info; + tGATT_HDL_LIST_ELEM* p_list = NULL; - p_list = p_list_info->p_first; + p_list = p_list_info->p_first; - while (p_list != NULL) - { - if ( gatt_uuid_compare (*p_app_uuid128, p_list->asgn_range.app_uuid128) - && gatt_uuid_compare (*p_svc_uuid, p_list->asgn_range.svc_uuid) - && (start_handle == p_list->asgn_range.s_handle) ) - { - GATT_TRACE_DEBUG ("Already allocated handles for this service before!!"); - return(p_list); - } - p_list = p_list->p_next; + while (p_list != NULL) { + if (gatt_uuid_compare(*p_app_uuid128, p_list->asgn_range.app_uuid128) && + gatt_uuid_compare(*p_svc_uuid, p_list->asgn_range.svc_uuid) && + (start_handle == p_list->asgn_range.s_handle)) { + GATT_TRACE_DEBUG("Already allocated handles for this service before!!"); + return (p_list); } - return NULL; + p_list = p_list->p_next; + } + return NULL; } /******************************************************************************* * @@ -331,16 +309,13 @@ tGATT_HDL_LIST_ELEM *gatt_find_hdl_buffer_by_app_id (tBT_UUID *p_app_uuid128, * Returns None * ******************************************************************************/ -void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p) -{ - - if (p) - { - while (!fixed_queue_is_empty(p->svc_db.svc_buffer)) - osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer)); - fixed_queue_free(p->svc_db.svc_buffer, NULL); - memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM)); - } +void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM* p) { + if (p) { + while (!fixed_queue_is_empty(p->svc_db.svc_buffer)) + osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer)); + fixed_queue_free(p->svc_db.svc_buffer, NULL); + memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM)); + } } /******************************************************************************* * @@ -352,24 +327,22 @@ void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p) * Returns None * ******************************************************************************/ -void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id) -{ - tGATT_HDL_LIST_ELEM *p_elem = &gatt_cb.hdl_list[0]; - uint8_t i; +void gatt_free_srvc_db_buffer_app_id(tBT_UUID* p_app_id) { + tGATT_HDL_LIST_ELEM* p_elem = &gatt_cb.hdl_list[0]; + uint8_t i; - for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_elem ++) - { - if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0) - { - while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer)) - osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer)); - fixed_queue_free(p_elem->svc_db.svc_buffer, NULL); - p_elem->svc_db.svc_buffer = NULL; + for (i = 0; i < GATT_MAX_SR_PROFILES; i++, p_elem++) { + if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == + 0) { + while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer)) + osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer)); + fixed_queue_free(p_elem->svc_db.svc_buffer, NULL); + p_elem->svc_db.svc_buffer = NULL; - p_elem->svc_db.mem_free = 0; - p_elem->svc_db.p_attr_list = p_elem->svc_db.p_free_mem = NULL; - } + p_elem->svc_db.mem_free = 0; + p_elem->svc_db.p_attr_list = p_elem->svc_db.p_free_mem = NULL; } + } } /******************************************************************************* * @@ -380,32 +353,28 @@ void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id) * Returns true - yes this is the last attribute * ******************************************************************************/ -bool gatt_is_last_attribute(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_start, tBT_UUID value) -{ - tGATT_SRV_LIST_ELEM *p_srv= p_start->p_next; - bool is_last_attribute = true; - tGATT_SR_REG *p_rcb = NULL; - tBT_UUID *p_svc_uuid; +bool gatt_is_last_attribute(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_start, tBT_UUID value) { + tGATT_SRV_LIST_ELEM* p_srv = p_start->p_next; + bool is_last_attribute = true; + tGATT_SR_REG* p_rcb = NULL; + tBT_UUID* p_svc_uuid; - p_list->p_last_primary = NULL; + p_list->p_last_primary = NULL; - while (p_srv) - { - p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); + while (p_srv) { + p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg); - p_svc_uuid = gatts_get_service_uuid (p_rcb->p_db); + p_svc_uuid = gatts_get_service_uuid(p_rcb->p_db); - if (gatt_uuid_compare(value, *p_svc_uuid)) - { - is_last_attribute = false; - break; - - } - p_srv = p_srv->p_next; + if (gatt_uuid_compare(value, *p_svc_uuid)) { + is_last_attribute = false; + break; } + p_srv = p_srv->p_next; + } - return is_last_attribute; - + return is_last_attribute; } /******************************************************************************* @@ -417,21 +386,17 @@ bool gatt_is_last_attribute(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM * Returns None * ******************************************************************************/ -void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO *p_list) -{ - tGATT_SRV_LIST_ELEM *p_srv= p_list->p_first; +void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO* p_list) { + tGATT_SRV_LIST_ELEM* p_srv = p_list->p_first; - p_list->p_last_primary = NULL; + p_list->p_last_primary = NULL; - while (p_srv) - { - if (p_srv->is_primary) - { - p_list->p_last_primary = p_srv; - } - p_srv = p_srv->p_next; + while (p_srv) { + if (p_srv->is_primary) { + p_list->p_last_primary = p_srv; } - + p_srv = p_srv->p_next; + } } /******************************************************************************* * @@ -442,15 +407,14 @@ void gatt_update_last_pri_srv_info(tGATT_SRV_LIST_INFO *p_list) * Returns None. * ******************************************************************************/ -void gatts_update_srv_list_elem(uint8_t i_sreg, - UNUSED_ATTR uint16_t handle, bool is_primary) -{ - gatt_cb.srv_list[i_sreg].in_use = true; - gatt_cb.srv_list[i_sreg].i_sreg = i_sreg; - gatt_cb.srv_list[i_sreg].s_hdl = gatt_cb.sr_reg[i_sreg].s_hdl; - gatt_cb.srv_list[i_sreg].is_primary = is_primary; +void gatts_update_srv_list_elem(uint8_t i_sreg, UNUSED_ATTR uint16_t handle, + bool is_primary) { + gatt_cb.srv_list[i_sreg].in_use = true; + gatt_cb.srv_list[i_sreg].i_sreg = i_sreg; + gatt_cb.srv_list[i_sreg].s_hdl = gatt_cb.sr_reg[i_sreg].s_hdl; + gatt_cb.srv_list[i_sreg].is_primary = is_primary; - return; + return; } /******************************************************************************* * @@ -462,61 +426,49 @@ void gatts_update_srv_list_elem(uint8_t i_sreg, * Returns bool true-if add is successful * ******************************************************************************/ -bool gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_new) -{ - tGATT_SRV_LIST_ELEM *p_old; +bool gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_new) { + tGATT_SRV_LIST_ELEM* p_old; - if (!p_new) - { - GATT_TRACE_DEBUG("p_new==NULL"); - return false; - } - - if (!p_list->p_first) - { - /* this is an empty list */ - p_list->p_first = - p_list->p_last = p_new; - p_new->p_next = - p_new->p_prev = NULL; - } - else - { - p_old = p_list->p_first; - while (1) - { - if (p_old == NULL) - { - p_list->p_last->p_next = p_new; - p_new->p_prev = p_list->p_last; - p_new->p_next = NULL; - p_list->p_last = p_new; - break; - } - else - { - if (p_new->s_hdl < p_old->s_hdl) - { - /* if not the first in list */ - if (p_old->p_prev != NULL) - p_old->p_prev->p_next = p_new; - else - p_list->p_first = p_new; - - p_new->p_prev = p_old->p_prev; - p_new->p_next = p_old; - p_old->p_prev = p_new; - break; - } - } - p_old = p_old->p_next; + if (!p_new) { + GATT_TRACE_DEBUG("p_new==NULL"); + return false; + } + + if (!p_list->p_first) { + /* this is an empty list */ + p_list->p_first = p_list->p_last = p_new; + p_new->p_next = p_new->p_prev = NULL; + } else { + p_old = p_list->p_first; + while (1) { + if (p_old == NULL) { + p_list->p_last->p_next = p_new; + p_new->p_prev = p_list->p_last; + p_new->p_next = NULL; + p_list->p_last = p_new; + break; + } else { + if (p_new->s_hdl < p_old->s_hdl) { + /* if not the first in list */ + if (p_old->p_prev != NULL) + p_old->p_prev->p_next = p_new; + else + p_list->p_first = p_new; + + p_new->p_prev = p_old->p_prev; + p_new->p_next = p_old; + p_old->p_prev = p_new; + break; } + } + p_old = p_old->p_next; } - p_list->count++; - - gatt_update_last_pri_srv_info(p_list); - return true; + } + p_list->count++; + gatt_update_last_pri_srv_info(p_list); + return true; } /******************************************************************************* @@ -528,34 +480,26 @@ bool gatt_add_a_srv_to_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM * Returns bool true-if remove is successful * ******************************************************************************/ -bool gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ELEM *p_remove) -{ - if (!p_remove || !p_list->p_first) - { - GATT_TRACE_DEBUG("p_remove==NULL || p_list->p_first==NULL"); - return false; - } - - if (p_remove->p_prev == NULL) - { - p_list->p_first = p_remove->p_next; - if (p_remove->p_next) - p_remove->p_next->p_prev = NULL; - } - else if (p_remove->p_next == NULL) - { - p_list->p_last = p_remove->p_prev; - p_remove->p_prev->p_next = NULL; - } - else - { - p_remove->p_next->p_prev = p_remove->p_prev; - p_remove->p_prev->p_next = p_remove->p_next; - } - p_list->count--; - gatt_update_last_pri_srv_info(p_list); - return true; +bool gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO* p_list, + tGATT_SRV_LIST_ELEM* p_remove) { + if (!p_remove || !p_list->p_first) { + GATT_TRACE_DEBUG("p_remove==NULL || p_list->p_first==NULL"); + return false; + } + if (p_remove->p_prev == NULL) { + p_list->p_first = p_remove->p_next; + if (p_remove->p_next) p_remove->p_next->p_prev = NULL; + } else if (p_remove->p_next == NULL) { + p_list->p_last = p_remove->p_prev; + p_remove->p_prev->p_next = NULL; + } else { + p_remove->p_next->p_prev = p_remove->p_prev; + p_remove->p_prev->p_next = p_remove->p_next; + } + p_list->count--; + gatt_update_last_pri_srv_info(p_list); + return true; } /******************************************************************************* @@ -568,59 +512,45 @@ bool gatt_remove_a_srv_from_list(tGATT_SRV_LIST_INFO *p_list, tGATT_SRV_LIST_ * Returns bool true-if add is successful * ******************************************************************************/ -bool gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_new) -{ - tGATT_HDL_LIST_ELEM *p_old; - if (!p_new) - { - GATT_TRACE_DEBUG("p_new==NULL"); - return false; - } - - if (!p_list->p_first) - { - /* this is an empty list */ - p_list->p_first = - p_list->p_last = p_new; - p_new->p_next = - p_new->p_prev = NULL; - } - else - { - p_old = p_list->p_first; - while (1) - { - if (p_old == NULL) - { - p_list->p_last->p_next = p_new; - p_new->p_prev = p_list->p_last; - p_new->p_next = NULL; - p_list->p_last = p_new; - - break; - - } - else - { - if (p_new->asgn_range.s_handle > p_old->asgn_range.s_handle) - { - if (p_old == p_list->p_first) - p_list->p_first = p_new; - - p_new->p_prev = p_old->p_prev; - p_new->p_next = p_old; - - - p_old->p_prev = p_new; - break; - } - } - p_old = p_old->p_next; +bool gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO* p_list, + tGATT_HDL_LIST_ELEM* p_new) { + tGATT_HDL_LIST_ELEM* p_old; + if (!p_new) { + GATT_TRACE_DEBUG("p_new==NULL"); + return false; + } + + if (!p_list->p_first) { + /* this is an empty list */ + p_list->p_first = p_list->p_last = p_new; + p_new->p_next = p_new->p_prev = NULL; + } else { + p_old = p_list->p_first; + while (1) { + if (p_old == NULL) { + p_list->p_last->p_next = p_new; + p_new->p_prev = p_list->p_last; + p_new->p_next = NULL; + p_list->p_last = p_new; + + break; + + } else { + if (p_new->asgn_range.s_handle > p_old->asgn_range.s_handle) { + if (p_old == p_list->p_first) p_list->p_first = p_new; + + p_new->p_prev = p_old->p_prev; + p_new->p_next = p_old; + + p_old->p_prev = p_new; + break; } + } + p_old = p_old->p_next; } - p_list->count++; - return true; - + } + p_list->count++; + return true; } /******************************************************************************* @@ -632,33 +562,25 @@ bool gatt_add_an_item_to_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELE * Returns bool true-if remove is successful * ******************************************************************************/ -bool gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIST_ELEM *p_remove) -{ - if (!p_remove || !p_list->p_first) - { - GATT_TRACE_DEBUG("p_remove==NULL || p_list->p_first==NULL"); - return false; - } - - if (p_remove->p_prev == NULL) - { - p_list->p_first = p_remove->p_next; - if (p_remove->p_next) - p_remove->p_next->p_prev = NULL; - } - else if (p_remove->p_next == NULL) - { - p_list->p_last = p_remove->p_prev; - p_remove->p_prev->p_next = NULL; - } - else - { - p_remove->p_next->p_prev = p_remove->p_prev; - p_remove->p_prev->p_next = p_remove->p_next; - } - p_list->count--; - return true; +bool gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO* p_list, + tGATT_HDL_LIST_ELEM* p_remove) { + if (!p_remove || !p_list->p_first) { + GATT_TRACE_DEBUG("p_remove==NULL || p_list->p_first==NULL"); + return false; + } + if (p_remove->p_prev == NULL) { + p_list->p_first = p_remove->p_next; + if (p_remove->p_next) p_remove->p_next->p_prev = NULL; + } else if (p_remove->p_next == NULL) { + p_list->p_last = p_remove->p_prev; + p_remove->p_prev->p_next = NULL; + } else { + p_remove->p_next->p_prev = p_remove->p_prev; + p_remove->p_prev->p_next = p_remove->p_next; + } + p_list->count--; + return true; } /******************************************************************************* @@ -670,32 +592,30 @@ bool gatt_remove_an_item_from_list(tGATT_HDL_LIST_INFO *p_list, tGATT_HDL_LIS * Returns true if found * ******************************************************************************/ -bool gatt_find_the_connected_bda(uint8_t start_idx, BD_ADDR bda, uint8_t *p_found_idx, - tBT_TRANSPORT *p_transport) -{ - uint8_t i; - bool found = false; - GATT_TRACE_DEBUG("gatt_find_the_connected_bda start_idx=%d",start_idx); - - for (i = start_idx ; i < GATT_MAX_PHY_CHANNEL; i ++) - { - if (gatt_cb.tcb[i].in_use && gatt_cb.tcb[i].ch_state == GATT_CH_OPEN) - { - memcpy( bda, gatt_cb.tcb[i].peer_bda, BD_ADDR_LEN); - *p_found_idx = i; - *p_transport = gatt_cb.tcb[i].transport; - found = true; - GATT_TRACE_DEBUG("gatt_find_the_connected_bda bda :%02x-%02x-%02x-%02x-%02x-%02x", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); - break; - } +bool gatt_find_the_connected_bda(uint8_t start_idx, BD_ADDR bda, + uint8_t* p_found_idx, + tBT_TRANSPORT* p_transport) { + uint8_t i; + bool found = false; + GATT_TRACE_DEBUG("gatt_find_the_connected_bda start_idx=%d", start_idx); + + for (i = start_idx; i < GATT_MAX_PHY_CHANNEL; i++) { + if (gatt_cb.tcb[i].in_use && gatt_cb.tcb[i].ch_state == GATT_CH_OPEN) { + memcpy(bda, gatt_cb.tcb[i].peer_bda, BD_ADDR_LEN); + *p_found_idx = i; + *p_transport = gatt_cb.tcb[i].transport; + found = true; + GATT_TRACE_DEBUG( + "gatt_find_the_connected_bda bda :%02x-%02x-%02x-%02x-%02x-%02x", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + break; } - GATT_TRACE_DEBUG("gatt_find_the_connected_bda found=%d found_idx=%d", found, i); - return found; + } + GATT_TRACE_DEBUG("gatt_find_the_connected_bda found=%d found_idx=%d", found, + i); + return found; } - - /******************************************************************************* * * Function gatt_is_srv_chg_ind_pending @@ -706,37 +626,30 @@ bool gatt_find_the_connected_bda(uint8_t start_idx, BD_ADDR bda, uint8_t *p_f * Returns bool * ******************************************************************************/ -bool gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb) -{ - bool srv_chg_ind_pending = false; +bool gatt_is_srv_chg_ind_pending(tGATT_TCB* p_tcb) { + bool srv_chg_ind_pending = false; - GATT_TRACE_DEBUG("gatt_is_srv_chg_ind_pending is_queue_empty=%d", - fixed_queue_is_empty(p_tcb->pending_ind_q)); + GATT_TRACE_DEBUG("gatt_is_srv_chg_ind_pending is_queue_empty=%d", + fixed_queue_is_empty(p_tcb->pending_ind_q)); - if (p_tcb->indicate_handle == gatt_cb.handle_of_h_r) - { + if (p_tcb->indicate_handle == gatt_cb.handle_of_h_r) { + srv_chg_ind_pending = true; + } else if (!fixed_queue_is_empty(p_tcb->pending_ind_q)) { + list_t* list = fixed_queue_get_list(p_tcb->pending_ind_q); + for (const list_node_t* node = list_begin(list); node != list_end(list); + node = list_next(node)) { + tGATT_VALUE* p_buf = (tGATT_VALUE*)list_node(node); + if (p_buf->handle == gatt_cb.handle_of_h_r) { srv_chg_ind_pending = true; + break; + } } - else if (! fixed_queue_is_empty(p_tcb->pending_ind_q)) - { - list_t *list = fixed_queue_get_list(p_tcb->pending_ind_q); - for (const list_node_t *node = list_begin(list); - node != list_end(list); - node = list_next(node)) { - tGATT_VALUE *p_buf = (tGATT_VALUE *)list_node(node); - if (p_buf->handle == gatt_cb.handle_of_h_r) - { - srv_chg_ind_pending = true; - break; - } - } - } + } - GATT_TRACE_DEBUG("srv_chg_ind_pending = %d", srv_chg_ind_pending); - return srv_chg_ind_pending; + GATT_TRACE_DEBUG("srv_chg_ind_pending = %d", srv_chg_ind_pending); + return srv_chg_ind_pending; } - /******************************************************************************* * * Function gatt_is_bda_in_the_srv_chg_clt_list @@ -747,31 +660,28 @@ bool gatt_is_srv_chg_ind_pending (tGATT_TCB *p_tcb) * Returns pointer to the found elemenet otherwise NULL * ******************************************************************************/ -tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda) -{ - tGATTS_SRV_CHG *p_buf = NULL; +tGATTS_SRV_CHG* gatt_is_bda_in_the_srv_chg_clt_list(BD_ADDR bda) { + tGATTS_SRV_CHG* p_buf = NULL; - GATT_TRACE_DEBUG("gatt_is_bda_in_the_srv_chg_clt_list :%02x-%02x-%02x-%02x-%02x-%02x", - bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); + GATT_TRACE_DEBUG( + "gatt_is_bda_in_the_srv_chg_clt_list :%02x-%02x-%02x-%02x-%02x-%02x", + bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); - if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) - return NULL; + if (fixed_queue_is_empty(gatt_cb.srv_chg_clt_q)) return NULL; - list_t *list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q); - for (const list_node_t *node = list_begin(list); node != list_end(list); - node = list_next(node)) { - tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)list_node(node); - if (!memcmp( bda, p_buf->bda, BD_ADDR_LEN)) - { - GATT_TRACE_DEBUG("bda is in the srv chg clt list"); - break; - } + list_t* list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q); + for (const list_node_t* node = list_begin(list); node != list_end(list); + node = list_next(node)) { + tGATTS_SRV_CHG* p_buf = (tGATTS_SRV_CHG*)list_node(node); + if (!memcmp(bda, p_buf->bda, BD_ADDR_LEN)) { + GATT_TRACE_DEBUG("bda is in the srv chg clt list"); + break; } + } - return p_buf; + return p_buf; } - /******************************************************************************* * * Function gatt_is_bda_connected @@ -781,21 +691,18 @@ tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda) * Returns GATT_INDEX_INVALID if not found. Otherwise index to the tcb. * ******************************************************************************/ -bool gatt_is_bda_connected(BD_ADDR bda) -{ - uint8_t i = 0; - bool connected=false; +bool gatt_is_bda_connected(BD_ADDR bda) { + uint8_t i = 0; + bool connected = false; - for ( i=0; i < GATT_MAX_PHY_CHANNEL; i ++) - { - if (gatt_cb.tcb[i].in_use && - !memcmp(gatt_cb.tcb[i].peer_bda, bda, BD_ADDR_LEN)) - { - connected = true; - break; - } + for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++) { + if (gatt_cb.tcb[i].in_use && + !memcmp(gatt_cb.tcb[i].peer_bda, bda, BD_ADDR_LEN)) { + connected = true; + break; } - return connected; + } + return connected; } /******************************************************************************* @@ -807,22 +714,18 @@ bool gatt_is_bda_connected(BD_ADDR bda) * Returns GATT_INDEX_INVALID if not found. Otherwise index to the tcb. * ******************************************************************************/ -uint8_t gatt_find_i_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) -{ - uint8_t i = 0; +uint8_t gatt_find_i_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) { + uint8_t i = 0; - for ( ; i < GATT_MAX_PHY_CHANNEL; i ++) - { - if (!memcmp(gatt_cb.tcb[i].peer_bda, bda, BD_ADDR_LEN) && - gatt_cb.tcb[i].transport == transport) - { - return i; - } + for (; i < GATT_MAX_PHY_CHANNEL; i++) { + if (!memcmp(gatt_cb.tcb[i].peer_bda, bda, BD_ADDR_LEN) && + gatt_cb.tcb[i].transport == transport) { + return i; } - return GATT_INDEX_INVALID; + } + return GATT_INDEX_INVALID; } - /******************************************************************************* * * Function gatt_get_tcb_by_idx @@ -832,14 +735,13 @@ uint8_t gatt_find_i_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) * Returns NULL if not found. Otherwise index to the tcb. * ******************************************************************************/ -tGATT_TCB * gatt_get_tcb_by_idx(uint8_t tcb_idx) -{ - tGATT_TCB *p_tcb = NULL; +tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx) { + tGATT_TCB* p_tcb = NULL; - if ( (tcb_idx < GATT_MAX_PHY_CHANNEL) && gatt_cb.tcb[tcb_idx].in_use) - p_tcb = &gatt_cb.tcb[tcb_idx]; + if ((tcb_idx < GATT_MAX_PHY_CHANNEL) && gatt_cb.tcb[tcb_idx].in_use) + p_tcb = &gatt_cb.tcb[tcb_idx]; - return p_tcb; + return p_tcb; } /******************************************************************************* @@ -851,16 +753,14 @@ tGATT_TCB * gatt_get_tcb_by_idx(uint8_t tcb_idx) * Returns NULL if not found. Otherwise index to the tcb. * ******************************************************************************/ -tGATT_TCB * gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) -{ - tGATT_TCB *p_tcb = NULL; - uint8_t i = 0; +tGATT_TCB* gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) { + tGATT_TCB* p_tcb = NULL; + uint8_t i = 0; - i = gatt_find_i_tcb_by_addr(bda, transport); - if (i != GATT_INDEX_INVALID) - p_tcb = &gatt_cb.tcb[i]; + i = gatt_find_i_tcb_by_addr(bda, transport); + if (i != GATT_INDEX_INVALID) p_tcb = &gatt_cb.tcb[i]; - return p_tcb; + return p_tcb; } /******************************************************************************* * @@ -871,19 +771,16 @@ tGATT_TCB * gatt_find_tcb_by_addr(BD_ADDR bda, tBT_TRANSPORT transport) * Returns GATT_INDEX_INVALID if not found. Otherwise index to the tcb. * ******************************************************************************/ -uint8_t gatt_find_i_tcb_free(void) -{ - uint8_t i = 0, j = GATT_INDEX_INVALID; +uint8_t gatt_find_i_tcb_free(void) { + uint8_t i = 0, j = GATT_INDEX_INVALID; - for (i = 0; i < GATT_MAX_PHY_CHANNEL; i ++) - { - if (!gatt_cb.tcb[i].in_use) - { - j = i; - break; - } + for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++) { + if (!gatt_cb.tcb[i].in_use) { + j = i; + break; } - return j; + } + return j; } /******************************************************************************* * @@ -894,38 +791,34 @@ uint8_t gatt_find_i_tcb_free(void) * Returns GATT_INDEX_INVALID if not found. Otherwise index to the tcb. * ******************************************************************************/ -tGATT_TCB * gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport) -{ - uint8_t i = 0; - bool allocated = false; - tGATT_TCB *p_tcb = NULL; +tGATT_TCB* gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport) { + uint8_t i = 0; + bool allocated = false; + tGATT_TCB* p_tcb = NULL; - /* search for existing tcb with matching bda */ - i = gatt_find_i_tcb_by_addr(bda, transport); - /* find free tcb */ - if (i == GATT_INDEX_INVALID) - { - i = gatt_find_i_tcb_free(); - allocated = true; - } - if (i != GATT_INDEX_INVALID) - { - p_tcb = &gatt_cb.tcb[i]; - - if (allocated) - { - memset(p_tcb, 0, sizeof(tGATT_TCB)); - p_tcb->pending_enc_clcb = fixed_queue_new(SIZE_MAX); - p_tcb->pending_ind_q = fixed_queue_new(SIZE_MAX); - p_tcb->conf_timer = alarm_new("gatt.conf_timer"); - p_tcb->ind_ack_timer = alarm_new("gatt.ind_ack_timer"); - p_tcb->in_use = true; - p_tcb->tcb_idx = i; - p_tcb->transport = transport; - } - memcpy(p_tcb->peer_bda, bda, BD_ADDR_LEN); + /* search for existing tcb with matching bda */ + i = gatt_find_i_tcb_by_addr(bda, transport); + /* find free tcb */ + if (i == GATT_INDEX_INVALID) { + i = gatt_find_i_tcb_free(); + allocated = true; + } + if (i != GATT_INDEX_INVALID) { + p_tcb = &gatt_cb.tcb[i]; + + if (allocated) { + memset(p_tcb, 0, sizeof(tGATT_TCB)); + p_tcb->pending_enc_clcb = fixed_queue_new(SIZE_MAX); + p_tcb->pending_ind_q = fixed_queue_new(SIZE_MAX); + p_tcb->conf_timer = alarm_new("gatt.conf_timer"); + p_tcb->ind_ack_timer = alarm_new("gatt.ind_ack_timer"); + p_tcb->in_use = true; + p_tcb->tcb_idx = i; + p_tcb->transport = transport; } - return p_tcb; + memcpy(p_tcb->peer_bda, bda, BD_ADDR_LEN); + } + return p_tcb; } /******************************************************************************* @@ -937,13 +830,13 @@ tGATT_TCB * gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport) * Returns true if two uuid match; false otherwise. * ******************************************************************************/ -void gatt_convert_uuid16_to_uuid128(uint8_t uuid_128[LEN_UUID_128], uint16_t uuid_16) -{ - uint8_t *p = &uuid_128[LEN_UUID_128 - 4]; +void gatt_convert_uuid16_to_uuid128(uint8_t uuid_128[LEN_UUID_128], + uint16_t uuid_16) { + uint8_t* p = &uuid_128[LEN_UUID_128 - 4]; - memcpy (uuid_128, base_uuid, LEN_UUID_128); + memcpy(uuid_128, base_uuid, LEN_UUID_128); - UINT16_TO_STREAM(p, uuid_16); + UINT16_TO_STREAM(p, uuid_16); } /******************************************************************************* @@ -955,13 +848,13 @@ void gatt_convert_uuid16_to_uuid128(uint8_t uuid_128[LEN_UUID_128], uint16_t uui * Returns true if two uuid match; false otherwise. * ******************************************************************************/ -void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128], uint32_t uuid_32) -{ - uint8_t *p = &uuid_128[LEN_UUID_128 - 4]; +void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128], + uint32_t uuid_32) { + uint8_t* p = &uuid_128[LEN_UUID_128 - 4]; - memcpy (uuid_128, base_uuid, LEN_UUID_128); + memcpy(uuid_128, base_uuid, LEN_UUID_128); - UINT32_TO_STREAM(p, uuid_32); + UINT32_TO_STREAM(p, uuid_32); } /******************************************************************************* * @@ -972,60 +865,48 @@ void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128], uint32_t uui * Returns true if two uuid match; false otherwise. * ******************************************************************************/ -bool gatt_uuid_compare (tBT_UUID src, tBT_UUID tar) -{ - uint8_t su[LEN_UUID_128], tu[LEN_UUID_128]; - uint8_t *ps, *pt; +bool gatt_uuid_compare(tBT_UUID src, tBT_UUID tar) { + uint8_t su[LEN_UUID_128], tu[LEN_UUID_128]; + uint8_t *ps, *pt; - /* any of the UUID is unspecified */ - if (src.len == 0 || tar.len == 0) - { - return true; - } + /* any of the UUID is unspecified */ + if (src.len == 0 || tar.len == 0) { + return true; + } - /* If both are 16-bit, we can do a simple compare */ - if (src.len == LEN_UUID_16 && tar.len == LEN_UUID_16) - { - return src.uu.uuid16 == tar.uu.uuid16; - } + /* If both are 16-bit, we can do a simple compare */ + if (src.len == LEN_UUID_16 && tar.len == LEN_UUID_16) { + return src.uu.uuid16 == tar.uu.uuid16; + } - /* If both are 32-bit, we can do a simple compare */ - if (src.len == LEN_UUID_32 && tar.len == LEN_UUID_32) - { - return src.uu.uuid32 == tar.uu.uuid32; - } + /* If both are 32-bit, we can do a simple compare */ + if (src.len == LEN_UUID_32 && tar.len == LEN_UUID_32) { + return src.uu.uuid32 == tar.uu.uuid32; + } - /* One or both of the UUIDs is 128-bit */ - if (src.len == LEN_UUID_16) - { - /* convert a 16 bits UUID to 128 bits value */ - gatt_convert_uuid16_to_uuid128(su, src.uu.uuid16); - ps = su; - } - else if (src.len == LEN_UUID_32) - { - gatt_convert_uuid32_to_uuid128(su, src.uu.uuid32); - ps = su; - } - else - ps = src.uu.uuid128; - - if (tar.len == LEN_UUID_16) - { - /* convert a 16 bits UUID to 128 bits value */ - gatt_convert_uuid16_to_uuid128(tu, tar.uu.uuid16); - pt = tu; - } - else if (tar.len == LEN_UUID_32) - { - /* convert a 32 bits UUID to 128 bits value */ - gatt_convert_uuid32_to_uuid128(tu, tar.uu.uuid32); - pt = tu; - } - else - pt = tar.uu.uuid128; + /* One or both of the UUIDs is 128-bit */ + if (src.len == LEN_UUID_16) { + /* convert a 16 bits UUID to 128 bits value */ + gatt_convert_uuid16_to_uuid128(su, src.uu.uuid16); + ps = su; + } else if (src.len == LEN_UUID_32) { + gatt_convert_uuid32_to_uuid128(su, src.uu.uuid32); + ps = su; + } else + ps = src.uu.uuid128; + + if (tar.len == LEN_UUID_16) { + /* convert a 16 bits UUID to 128 bits value */ + gatt_convert_uuid16_to_uuid128(tu, tar.uu.uuid16); + pt = tu; + } else if (tar.len == LEN_UUID_32) { + /* convert a 32 bits UUID to 128 bits value */ + gatt_convert_uuid32_to_uuid128(tu, tar.uu.uuid32); + pt = tu; + } else + pt = tar.uu.uuid128; - return(memcmp(ps, pt, LEN_UUID_128) == 0); + return (memcmp(ps, pt, LEN_UUID_128) == 0); } /******************************************************************************* @@ -1037,30 +918,26 @@ bool gatt_uuid_compare (tBT_UUID src, tBT_UUID tar) * Returns UUID length. * ******************************************************************************/ -uint8_t gatt_build_uuid_to_stream(uint8_t **p_dst, tBT_UUID uuid) -{ - uint8_t *p = *p_dst; - uint8_t len = 0; +uint8_t gatt_build_uuid_to_stream(uint8_t** p_dst, tBT_UUID uuid) { + uint8_t* p = *p_dst; + uint8_t len = 0; - if (uuid.len == LEN_UUID_16) - { - UINT16_TO_STREAM (p, uuid.uu.uuid16); - len = LEN_UUID_16; - } - else if (uuid.len == LEN_UUID_32) /* always convert 32 bits into 128 bits as alwats */ - { - gatt_convert_uuid32_to_uuid128(p, uuid.uu.uuid32); - p += LEN_UUID_128; - len = LEN_UUID_128; - } - else if (uuid.len == LEN_UUID_128) - { - ARRAY_TO_STREAM (p, uuid.uu.uuid128, LEN_UUID_128); - len = LEN_UUID_128; - } + if (uuid.len == LEN_UUID_16) { + UINT16_TO_STREAM(p, uuid.uu.uuid16); + len = LEN_UUID_16; + } else if (uuid.len == + LEN_UUID_32) /* always convert 32 bits into 128 bits as alwats */ + { + gatt_convert_uuid32_to_uuid128(p, uuid.uu.uuid32); + p += LEN_UUID_128; + len = LEN_UUID_128; + } else if (uuid.len == LEN_UUID_128) { + ARRAY_TO_STREAM(p, uuid.uu.uuid128, LEN_UUID_128); + len = LEN_UUID_128; + } - *p_dst = p; - return len; + *p_dst = p; + return len; } /******************************************************************************* @@ -1072,68 +949,61 @@ uint8_t gatt_build_uuid_to_stream(uint8_t **p_dst, tBT_UUID uuid) * Returns true if command sent, otherwise false. * ******************************************************************************/ -bool gatt_parse_uuid_from_cmd(tBT_UUID *p_uuid_rec, uint16_t uuid_size, uint8_t **p_data) -{ - bool is_base_uuid, ret = true; - uint8_t xx; - uint8_t *p_uuid = *p_data; - - memset(p_uuid_rec, 0, sizeof(tBT_UUID)); - - switch (uuid_size) - { - case LEN_UUID_16: - p_uuid_rec->len = uuid_size; - STREAM_TO_UINT16 (p_uuid_rec->uu.uuid16, p_uuid); - *p_data += LEN_UUID_16; - break; - - case LEN_UUID_128: - /* See if we can compress his UUID down to 16 or 32bit UUIDs */ - is_base_uuid = true; - for (xx = 0; xx < LEN_UUID_128 - 4; xx++) - { - if (p_uuid[xx] != base_uuid[xx]) - { - is_base_uuid = false; - break; - } - } - if (is_base_uuid) - { - if ((p_uuid[LEN_UUID_128 - 1] == 0) && (p_uuid[LEN_UUID_128 - 2] == 0)) - { - p_uuid += (LEN_UUID_128 - 4); - p_uuid_rec->len = LEN_UUID_16; - STREAM_TO_UINT16(p_uuid_rec->uu.uuid16, p_uuid); - } - else - { - p_uuid += (LEN_UUID_128 - LEN_UUID_32); - p_uuid_rec->len = LEN_UUID_32; - STREAM_TO_UINT32(p_uuid_rec->uu.uuid32, p_uuid); - } - } - if (!is_base_uuid) - { - p_uuid_rec->len = LEN_UUID_128; - memcpy(p_uuid_rec->uu.uuid128, p_uuid, LEN_UUID_128); - } - *p_data += LEN_UUID_128; - break; - - /* do not allow 32 bits UUID in ATT PDU now */ - case LEN_UUID_32: - GATT_TRACE_ERROR("DO NOT ALLOW 32 BITS UUID IN ATT PDU"); - return false; - case 0: - default: - if (uuid_size != 0) ret = false; - GATT_TRACE_WARNING("gatt_parse_uuid_from_cmd invalid uuid size"); - break; - } +bool gatt_parse_uuid_from_cmd(tBT_UUID* p_uuid_rec, uint16_t uuid_size, + uint8_t** p_data) { + bool is_base_uuid, ret = true; + uint8_t xx; + uint8_t* p_uuid = *p_data; + + memset(p_uuid_rec, 0, sizeof(tBT_UUID)); + + switch (uuid_size) { + case LEN_UUID_16: + p_uuid_rec->len = uuid_size; + STREAM_TO_UINT16(p_uuid_rec->uu.uuid16, p_uuid); + *p_data += LEN_UUID_16; + break; + + case LEN_UUID_128: + /* See if we can compress his UUID down to 16 or 32bit UUIDs */ + is_base_uuid = true; + for (xx = 0; xx < LEN_UUID_128 - 4; xx++) { + if (p_uuid[xx] != base_uuid[xx]) { + is_base_uuid = false; + break; + } + } + if (is_base_uuid) { + if ((p_uuid[LEN_UUID_128 - 1] == 0) && + (p_uuid[LEN_UUID_128 - 2] == 0)) { + p_uuid += (LEN_UUID_128 - 4); + p_uuid_rec->len = LEN_UUID_16; + STREAM_TO_UINT16(p_uuid_rec->uu.uuid16, p_uuid); + } else { + p_uuid += (LEN_UUID_128 - LEN_UUID_32); + p_uuid_rec->len = LEN_UUID_32; + STREAM_TO_UINT32(p_uuid_rec->uu.uuid32, p_uuid); + } + } + if (!is_base_uuid) { + p_uuid_rec->len = LEN_UUID_128; + memcpy(p_uuid_rec->uu.uuid128, p_uuid, LEN_UUID_128); + } + *p_data += LEN_UUID_128; + break; + + /* do not allow 32 bits UUID in ATT PDU now */ + case LEN_UUID_32: + GATT_TRACE_ERROR("DO NOT ALLOW 32 BITS UUID IN ATT PDU"); + return false; + case 0: + default: + if (uuid_size != 0) ret = false; + GATT_TRACE_WARNING("gatt_parse_uuid_from_cmd invalid uuid size"); + break; + } - return( ret); + return (ret); } /******************************************************************************* @@ -1145,23 +1015,22 @@ bool gatt_parse_uuid_from_cmd(tBT_UUID *p_uuid_rec, uint16_t uuid_size, uint8 * Returns void * ******************************************************************************/ -void gatt_start_rsp_timer(uint16_t clcb_idx) -{ - tGATT_CLCB *p_clcb = &gatt_cb.clcb[clcb_idx]; - period_ms_t timeout_ms = GATT_WAIT_FOR_RSP_TIMEOUT_MS; +void gatt_start_rsp_timer(uint16_t clcb_idx) { + tGATT_CLCB* p_clcb = &gatt_cb.clcb[clcb_idx]; + period_ms_t timeout_ms = GATT_WAIT_FOR_RSP_TIMEOUT_MS; - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && - p_clcb->op_subtype == GATT_DISC_SRVC_ALL) { - timeout_ms = GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS; - } + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->op_subtype == GATT_DISC_SRVC_ALL) { + timeout_ms = GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS; + } - // TODO: The tGATT_CLCB memory and state management needs cleanup, - // and then the timers can be allocated elsewhere. - if (p_clcb->gatt_rsp_timer_ent == NULL) { - p_clcb->gatt_rsp_timer_ent = alarm_new("gatt.gatt_rsp_timer_ent"); - } - alarm_set_on_queue(p_clcb->gatt_rsp_timer_ent, timeout_ms, - gatt_rsp_timeout, p_clcb, btu_general_alarm_queue); + // TODO: The tGATT_CLCB memory and state management needs cleanup, + // and then the timers can be allocated elsewhere. + if (p_clcb->gatt_rsp_timer_ent == NULL) { + p_clcb->gatt_rsp_timer_ent = alarm_new("gatt.gatt_rsp_timer_ent"); + } + alarm_set_on_queue(p_clcb->gatt_rsp_timer_ent, timeout_ms, gatt_rsp_timeout, + p_clcb, btu_general_alarm_queue); } /******************************************************************************* @@ -1173,11 +1042,10 @@ void gatt_start_rsp_timer(uint16_t clcb_idx) * Returns void * ******************************************************************************/ -void gatt_start_conf_timer(tGATT_TCB *p_tcb) -{ - alarm_set_on_queue(p_tcb->conf_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS, - gatt_indication_confirmation_timeout, p_tcb, - btu_general_alarm_queue); +void gatt_start_conf_timer(tGATT_TCB* p_tcb) { + alarm_set_on_queue(p_tcb->conf_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS, + gatt_indication_confirmation_timeout, p_tcb, + btu_general_alarm_queue); } /******************************************************************************* @@ -1189,11 +1057,10 @@ void gatt_start_conf_timer(tGATT_TCB *p_tcb) * Returns void * ******************************************************************************/ -void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb) -{ - /* start notification cache timer */ - alarm_set_on_queue(p_tcb->ind_ack_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS, - gatt_ind_ack_timeout, p_tcb, btu_general_alarm_queue); +void gatt_start_ind_ack_timer(tGATT_TCB* p_tcb) { + /* start notification cache timer */ + alarm_set_on_queue(p_tcb->ind_ack_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS, + gatt_ind_ack_timeout, p_tcb, btu_general_alarm_queue); } /******************************************************************************* @@ -1205,36 +1072,29 @@ void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb) * Returns void * ******************************************************************************/ -void gatt_rsp_timeout(void *data) -{ - tGATT_CLCB *p_clcb = (tGATT_CLCB *)data; +void gatt_rsp_timeout(void* data) { + tGATT_CLCB* p_clcb = (tGATT_CLCB*)data; - if (p_clcb == NULL || p_clcb->p_tcb == NULL) - { - GATT_TRACE_WARNING("%s clcb is already deleted", __func__); - return; - } - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && - p_clcb->op_subtype == GATT_DISC_SRVC_ALL && - p_clcb->retry_count < GATT_REQ_RETRY_LIMIT) - { - uint8_t rsp_code; - GATT_TRACE_WARNING("%s retry discovery primary service", __func__); - if (p_clcb != gatt_cmd_dequeue(p_clcb->p_tcb, &rsp_code)) - { - GATT_TRACE_ERROR("%s command queue out of sync, disconnect", - __func__); - } - else - { - p_clcb->retry_count++; - gatt_act_discovery(p_clcb); - return; - } + if (p_clcb == NULL || p_clcb->p_tcb == NULL) { + GATT_TRACE_WARNING("%s clcb is already deleted", __func__); + return; + } + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && + p_clcb->op_subtype == GATT_DISC_SRVC_ALL && + p_clcb->retry_count < GATT_REQ_RETRY_LIMIT) { + uint8_t rsp_code; + GATT_TRACE_WARNING("%s retry discovery primary service", __func__); + if (p_clcb != gatt_cmd_dequeue(p_clcb->p_tcb, &rsp_code)) { + GATT_TRACE_ERROR("%s command queue out of sync, disconnect", __func__); + } else { + p_clcb->retry_count++; + gatt_act_discovery(p_clcb); + return; } + } - GATT_TRACE_WARNING("%s disconnecting...", __func__); - gatt_disconnect (p_clcb->p_tcb); + GATT_TRACE_WARNING("%s disconnecting...", __func__); + gatt_disconnect(p_clcb->p_tcb); } /******************************************************************************* @@ -1246,12 +1106,11 @@ void gatt_rsp_timeout(void *data) * Returns void * ******************************************************************************/ -void gatt_indication_confirmation_timeout(void *data) -{ - tGATT_TCB *p_tcb = (tGATT_TCB *)data; +void gatt_indication_confirmation_timeout(void* data) { + tGATT_TCB* p_tcb = (tGATT_TCB*)data; - GATT_TRACE_WARNING("%s disconnecting...", __func__); - gatt_disconnect(p_tcb); + GATT_TRACE_WARNING("%s disconnecting...", __func__); + gatt_disconnect(p_tcb); } /******************************************************************************* @@ -1263,16 +1122,14 @@ void gatt_indication_confirmation_timeout(void *data) * Returns void * ******************************************************************************/ -void gatt_ind_ack_timeout(void *data) -{ - tGATT_TCB *p_tcb = (tGATT_TCB *)data; +void gatt_ind_ack_timeout(void* data) { + tGATT_TCB* p_tcb = (tGATT_TCB*)data; - GATT_TRACE_WARNING("%s send ack now", __func__); + GATT_TRACE_WARNING("%s send ack now", __func__); - if (p_tcb != NULL) - p_tcb->ind_count = 0; + if (p_tcb != NULL) p_tcb->ind_count = 0; - attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); + attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL); } /******************************************************************************* * @@ -1284,20 +1141,16 @@ void gatt_ind_ack_timeout(void *data) * the service. * ******************************************************************************/ -uint8_t gatt_sr_find_i_rcb_by_handle(uint16_t handle) -{ - uint8_t i_rcb = 0; +uint8_t gatt_sr_find_i_rcb_by_handle(uint16_t handle) { + uint8_t i_rcb = 0; - for ( ; i_rcb < GATT_MAX_SR_PROFILES; i_rcb++) - { - if (gatt_cb.sr_reg[i_rcb].in_use && - gatt_cb.sr_reg[i_rcb].s_hdl <= handle && - gatt_cb.sr_reg[i_rcb].e_hdl >= handle ) - { - break; - } + for (; i_rcb < GATT_MAX_SR_PROFILES; i_rcb++) { + if (gatt_cb.sr_reg[i_rcb].in_use && gatt_cb.sr_reg[i_rcb].s_hdl <= handle && + gatt_cb.sr_reg[i_rcb].e_hdl >= handle) { + break; } - return i_rcb; + } + return i_rcb; } /******************************************************************************* @@ -1310,31 +1163,29 @@ uint8_t gatt_sr_find_i_rcb_by_handle(uint16_t handle) * Returns 0 if not found. Otherwise index of th eservice. * ******************************************************************************/ -uint8_t gatt_sr_find_i_rcb_by_app_id(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uuid, uint16_t start_handle) -{ - uint8_t i_rcb = 0; - tGATT_SR_REG *p_sreg; - tBT_UUID *p_this_uuid; - - for (i_rcb = 0, p_sreg = gatt_cb.sr_reg; i_rcb < GATT_MAX_SR_PROFILES; i_rcb++, p_sreg++) - { - if ( p_sreg->in_use ) - { - p_this_uuid = gatts_get_service_uuid (p_sreg->p_db); - - if (p_this_uuid && - gatt_uuid_compare (*p_app_uuid128, p_sreg->app_uuid ) && - gatt_uuid_compare (*p_svc_uuid, *p_this_uuid) && - (start_handle == p_sreg->s_hdl)) - { - GATT_TRACE_ERROR ("Active Service Found "); - gatt_dbg_display_uuid(*p_svc_uuid); - - break; - } - } +uint8_t gatt_sr_find_i_rcb_by_app_id(tBT_UUID* p_app_uuid128, + tBT_UUID* p_svc_uuid, + uint16_t start_handle) { + uint8_t i_rcb = 0; + tGATT_SR_REG* p_sreg; + tBT_UUID* p_this_uuid; + + for (i_rcb = 0, p_sreg = gatt_cb.sr_reg; i_rcb < GATT_MAX_SR_PROFILES; + i_rcb++, p_sreg++) { + if (p_sreg->in_use) { + p_this_uuid = gatts_get_service_uuid(p_sreg->p_db); + + if (p_this_uuid && gatt_uuid_compare(*p_app_uuid128, p_sreg->app_uuid) && + gatt_uuid_compare(*p_svc_uuid, *p_this_uuid) && + (start_handle == p_sreg->s_hdl)) { + GATT_TRACE_ERROR("Active Service Found "); + gatt_dbg_display_uuid(*p_svc_uuid); + + break; + } } - return i_rcb; + } + return i_rcb; } /******************************************************************************* * @@ -1346,33 +1197,33 @@ uint8_t gatt_sr_find_i_rcb_by_app_id(tBT_UUID *p_app_uuid128, tBT_UUID *p_svc_uu * Returns 0 if not found. Otherwise index of th eservice. * ******************************************************************************/ -uint8_t gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM *p_list ) -{ - uint8_t ii = 0; - tGATT_SR_REG *p_sreg = NULL; +uint8_t gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM* p_list) { + uint8_t ii = 0; + tGATT_SR_REG* p_sreg = NULL; - /*this is a new application servoce start */ - for (ii = 0, p_sreg = gatt_cb.sr_reg; ii < GATT_MAX_SR_PROFILES; ii++, p_sreg++) - { - if (!p_sreg->in_use) - { - memset (p_sreg, 0, sizeof(tGATT_SR_REG)); + /*this is a new application servoce start */ + for (ii = 0, p_sreg = gatt_cb.sr_reg; ii < GATT_MAX_SR_PROFILES; + ii++, p_sreg++) { + if (!p_sreg->in_use) { + memset(p_sreg, 0, sizeof(tGATT_SR_REG)); - p_sreg->in_use = true; - memcpy (&p_sreg->app_uuid, &p_list->asgn_range.app_uuid128, sizeof(tBT_UUID)); + p_sreg->in_use = true; + memcpy(&p_sreg->app_uuid, &p_list->asgn_range.app_uuid128, + sizeof(tBT_UUID)); - p_sreg->type = p_list->asgn_range.is_primary ? GATT_UUID_PRI_SERVICE: GATT_UUID_SEC_SERVICE; - p_sreg->s_hdl = p_list->asgn_range.s_handle; - p_sreg->e_hdl = p_list->asgn_range.e_handle; - p_sreg->p_db = &p_list->svc_db; + p_sreg->type = p_list->asgn_range.is_primary ? GATT_UUID_PRI_SERVICE + : GATT_UUID_SEC_SERVICE; + p_sreg->s_hdl = p_list->asgn_range.s_handle; + p_sreg->e_hdl = p_list->asgn_range.e_handle; + p_sreg->p_db = &p_list->svc_db; - GATT_TRACE_DEBUG("total buffer in db [%d]", - fixed_queue_length(p_sreg->p_db->svc_buffer)); - break; - } + GATT_TRACE_DEBUG("total buffer in db [%d]", + fixed_queue_length(p_sreg->p_db->svc_buffer)); + break; } + } - return ii; + return ii; } /******************************************************************************* * @@ -1384,16 +1235,17 @@ uint8_t gatt_sr_alloc_rcb(tGATT_HDL_LIST_ELEM *p_list ) * Returns void * ******************************************************************************/ -void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, uint8_t *p_sec_flag, uint8_t *p_key_size) -{ - uint8_t sec_flag = 0; +void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, + uint8_t* p_sec_flag, uint8_t* p_key_size) { + uint8_t sec_flag = 0; - BTM_GetSecurityFlagsByTransport(rem_bda, &sec_flag, transport); + BTM_GetSecurityFlagsByTransport(rem_bda, &sec_flag, transport); - sec_flag &= (GATT_SEC_FLAG_LKEY_UNAUTHED | GATT_SEC_FLAG_LKEY_AUTHED | GATT_SEC_FLAG_ENCRYPTED); + sec_flag &= (GATT_SEC_FLAG_LKEY_UNAUTHED | GATT_SEC_FLAG_LKEY_AUTHED | + GATT_SEC_FLAG_ENCRYPTED); - *p_key_size = btm_ble_read_sec_key_size(rem_bda); - *p_sec_flag = sec_flag; + *p_key_size = btm_ble_read_sec_key_size(rem_bda); + *p_sec_flag = sec_flag; } /******************************************************************************* * @@ -1405,29 +1257,22 @@ void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, uint8_t *p_s * Returns void * ******************************************************************************/ -void gatt_sr_send_req_callback(uint16_t conn_id, - uint32_t trans_id, - tGATTS_REQ_TYPE type, tGATTS_DATA *p_data) -{ - tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); +void gatt_sr_send_req_callback(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) { + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); - if (!p_reg ) - { - GATT_TRACE_ERROR ("p_reg not found discard request"); - return; - } - - if ( p_reg->in_use && - p_reg->app_cb.p_req_cb) - { - (*p_reg->app_cb.p_req_cb)(conn_id, trans_id, type, p_data); - } - else - { - GATT_TRACE_WARNING("Call back not found for application conn_id=%d", conn_id); - } + if (!p_reg) { + GATT_TRACE_ERROR("p_reg not found discard request"); + return; + } + if (p_reg->in_use && p_reg->app_cb.p_req_cb) { + (*p_reg->app_cb.p_req_cb)(conn_id, trans_id, type, p_data); + } else { + GATT_TRACE_WARNING("Call back not found for application conn_id=%d", + conn_id); + } } /******************************************************************************* @@ -1439,32 +1284,27 @@ void gatt_sr_send_req_callback(uint16_t conn_id, * Returns void * ******************************************************************************/ -tGATT_STATUS gatt_send_error_rsp (tGATT_TCB *p_tcb, uint8_t err_code, uint8_t op_code, - uint16_t handle, bool deq) -{ - tGATT_ERROR error; - tGATT_STATUS status; - BT_HDR *p_buf; +tGATT_STATUS gatt_send_error_rsp(tGATT_TCB* p_tcb, uint8_t err_code, + uint8_t op_code, uint16_t handle, bool deq) { + tGATT_ERROR error; + tGATT_STATUS status; + BT_HDR* p_buf; - error.cmd_code = op_code; - error.reason = err_code; - error.handle =handle; + error.cmd_code = op_code; + error.reason = err_code; + error.handle = handle; - p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_ERROR, (tGATT_SR_MSG *)&error); - if (p_buf != NULL) - { - status = attp_send_sr_msg (p_tcb, p_buf); - } - else - status = GATT_INSUF_RESOURCE; + p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_ERROR, (tGATT_SR_MSG*)&error); + if (p_buf != NULL) { + status = attp_send_sr_msg(p_tcb, p_buf); + } else + status = GATT_INSUF_RESOURCE; - if (deq) - gatt_dequeue_sr_cmd(p_tcb); + if (deq) gatt_dequeue_sr_cmd(p_tcb); - return status; + return status; } - /******************************************************************************* * * Function gatt_add_sdp_record @@ -1474,66 +1314,64 @@ tGATT_STATUS gatt_send_error_rsp (tGATT_TCB *p_tcb, uint8_t err_code, uint8_t op * Returns 0 if error else sdp handle for the record. * ******************************************************************************/ -uint32_t gatt_add_sdp_record (tBT_UUID *p_uuid, uint16_t start_hdl, uint16_t end_hdl) -{ - tSDP_PROTOCOL_ELEM proto_elem_list[2]; - uint32_t sdp_handle; - uint16_t list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - uint8_t buff[60]; - uint8_t *p = buff; - - GATT_TRACE_DEBUG("gatt_add_sdp_record s_hdl=0x%x s_hdl=0x%x",start_hdl, end_hdl); - - sdp_handle = SDP_CreateRecord(); - if (sdp_handle == 0) - return 0; - - switch (p_uuid->len) - { - case LEN_UUID_16: - SDP_AddServiceClassIdList(sdp_handle, 1, &p_uuid->uu.uuid16); - break; - - case LEN_UUID_32: - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES); - UINT32_TO_BE_STREAM (p, p_uuid->uu.uuid32); - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST, DATA_ELE_SEQ_DESC_TYPE, - (uint32_t) (p - buff), buff); - break; - - case LEN_UUID_128: - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES); - ARRAY_TO_BE_STREAM_REVERSE (p, p_uuid->uu.uuid128, LEN_UUID_128); - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST, DATA_ELE_SEQ_DESC_TYPE, - (uint32_t) (p - buff), buff); - break; - - default: - GATT_TRACE_ERROR("inavlid UUID len=%d", p_uuid->len); - SDP_DeleteRecord(sdp_handle); - return 0; - break; - } +uint32_t gatt_add_sdp_record(tBT_UUID* p_uuid, uint16_t start_hdl, + uint16_t end_hdl) { + tSDP_PROTOCOL_ELEM proto_elem_list[2]; + uint32_t sdp_handle; + uint16_t list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; + uint8_t buff[60]; + uint8_t* p = buff; - /*** Fill out the protocol element sequence for SDP ***/ - proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; - proto_elem_list[0].num_params = 1; - proto_elem_list[0].params[0] = BT_PSM_ATT; - proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_ATT; - proto_elem_list[1].num_params = 2; - proto_elem_list[1].params[0] = start_hdl; - proto_elem_list[1].params[1] = end_hdl; + GATT_TRACE_DEBUG("gatt_add_sdp_record s_hdl=0x%x s_hdl=0x%x", start_hdl, + end_hdl); - SDP_AddProtocolList(sdp_handle, 2, proto_elem_list); + sdp_handle = SDP_CreateRecord(); + if (sdp_handle == 0) return 0; - /* Make the service browseable */ - SDP_AddUuidSequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &list); + switch (p_uuid->len) { + case LEN_UUID_16: + SDP_AddServiceClassIdList(sdp_handle, 1, &p_uuid->uu.uuid16); + break; - return(sdp_handle); -} + case LEN_UUID_32: + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES); + UINT32_TO_BE_STREAM(p, p_uuid->uu.uuid32); + SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - buff), buff); + break; + + case LEN_UUID_128: + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES); + ARRAY_TO_BE_STREAM_REVERSE(p, p_uuid->uu.uuid128, LEN_UUID_128); + SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_CLASS_ID_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - buff), buff); + break; + + default: + GATT_TRACE_ERROR("inavlid UUID len=%d", p_uuid->len); + SDP_DeleteRecord(sdp_handle); + return 0; + break; + } + /*** Fill out the protocol element sequence for SDP ***/ + proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP; + proto_elem_list[0].num_params = 1; + proto_elem_list[0].params[0] = BT_PSM_ATT; + proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_ATT; + proto_elem_list[1].num_params = 2; + proto_elem_list[1].params[0] = start_hdl; + proto_elem_list[1].params[1] = end_hdl; - #if GATT_CONFORMANCE_TESTING == true + SDP_AddProtocolList(sdp_handle, 2, proto_elem_list); + + /* Make the service browseable */ + SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &list); + + return (sdp_handle); +} + +#if GATT_CONFORMANCE_TESTING == true /******************************************************************************* * * Function gatt_set_err_rsp @@ -1543,16 +1381,14 @@ uint32_t gatt_add_sdp_record (tBT_UUID *p_uuid, uint16_t start_hdl, uint16_t end * Returns void * ******************************************************************************/ -void gatt_set_err_rsp(bool enable, uint8_t req_op_code, uint8_t err_status) -{ - GATT_TRACE_DEBUG("gatt_set_err_rsp enable=%d op_code=%d, err_status=%d", enable, req_op_code, err_status); - gatt_cb.enable_err_rsp = enable; - gatt_cb.req_op_code = req_op_code; - gatt_cb.err_status = err_status; +void gatt_set_err_rsp(bool enable, uint8_t req_op_code, uint8_t err_status) { + GATT_TRACE_DEBUG("gatt_set_err_rsp enable=%d op_code=%d, err_status=%d", + enable, req_op_code, err_status); + gatt_cb.enable_err_rsp = enable; + gatt_cb.req_op_code = req_op_code; + gatt_cb.err_status = err_status; } - #endif - - +#endif /******************************************************************************* * @@ -1563,28 +1399,26 @@ void gatt_set_err_rsp(bool enable, uint8_t req_op_code, uint8_t err_status) * Returns pointer to the registration control block or NULL * ******************************************************************************/ -tGATT_REG *gatt_get_regcb (tGATT_IF gatt_if) -{ - uint8_t ii = (uint8_t)gatt_if; - tGATT_REG *p_reg = NULL; +tGATT_REG* gatt_get_regcb(tGATT_IF gatt_if) { + uint8_t ii = (uint8_t)gatt_if; + tGATT_REG* p_reg = NULL; - if (ii < 1 || ii > GATT_MAX_APPS) { - GATT_TRACE_WARNING("gatt_if out of range [ = %d]", ii); - return NULL; - } + if (ii < 1 || ii > GATT_MAX_APPS) { + GATT_TRACE_WARNING("gatt_if out of range [ = %d]", ii); + return NULL; + } - // Index for cl_rcb is always 1 less than gatt_if. - p_reg = &gatt_cb.cl_rcb[ii - 1]; + // Index for cl_rcb is always 1 less than gatt_if. + p_reg = &gatt_cb.cl_rcb[ii - 1]; - if (!p_reg->in_use) { - GATT_TRACE_WARNING("gatt_if found but not in use."); - return NULL; - } + if (!p_reg->in_use) { + GATT_TRACE_WARNING("gatt_if found but not in use."); + return NULL; + } - return p_reg; + return p_reg; } - /******************************************************************************* * * Function gatt_is_clcb_allocated @@ -1595,21 +1429,18 @@ tGATT_REG *gatt_get_regcb (tGATT_IF gatt_if) * ******************************************************************************/ -bool gatt_is_clcb_allocated (uint16_t conn_id) -{ - uint8_t i = 0; - bool is_allocated= false; +bool gatt_is_clcb_allocated(uint16_t conn_id) { + uint8_t i = 0; + bool is_allocated = false; - for (i = 0; i < GATT_CL_MAX_LCB; i++) - { - if (gatt_cb.clcb[i].in_use && (gatt_cb.clcb[i].conn_id == conn_id)) - { - is_allocated = true; - break; - } + for (i = 0; i < GATT_CL_MAX_LCB; i++) { + if (gatt_cb.clcb[i].in_use && (gatt_cb.clcb[i].conn_id == conn_id)) { + is_allocated = true; + break; } + } - return is_allocated; + return is_allocated; } /******************************************************************************* @@ -1622,30 +1453,27 @@ bool gatt_is_clcb_allocated (uint16_t conn_id) * block. * ******************************************************************************/ -tGATT_CLCB *gatt_clcb_alloc (uint16_t conn_id) -{ - uint8_t i = 0; - tGATT_CLCB *p_clcb = NULL; - tGATT_IF gatt_if=GATT_GET_GATT_IF(conn_id); - uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); - tGATT_TCB *p_tcb = gatt_get_tcb_by_idx(tcb_idx); - tGATT_REG *p_reg = gatt_get_regcb(gatt_if); - - for (i = 0; i < GATT_CL_MAX_LCB; i++) - { - if (!gatt_cb.clcb[i].in_use) - { - p_clcb = &gatt_cb.clcb[i]; - - p_clcb->in_use = true; - p_clcb->conn_id = conn_id; - p_clcb->clcb_idx = i; - p_clcb->p_reg = p_reg; - p_clcb->p_tcb = p_tcb; - break; - } +tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id) { + uint8_t i = 0; + tGATT_CLCB* p_clcb = NULL; + tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); + uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); + tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); + tGATT_REG* p_reg = gatt_get_regcb(gatt_if); + + for (i = 0; i < GATT_CL_MAX_LCB; i++) { + if (!gatt_cb.clcb[i].in_use) { + p_clcb = &gatt_cb.clcb[i]; + + p_clcb->in_use = true; + p_clcb->conn_id = conn_id; + p_clcb->clcb_idx = i; + p_clcb->p_reg = p_reg; + p_clcb->p_tcb = p_tcb; + break; } - return p_clcb; + } + return p_clcb; } /******************************************************************************* @@ -1658,17 +1486,13 @@ tGATT_CLCB *gatt_clcb_alloc (uint16_t conn_id) * Returns None * ******************************************************************************/ -void gatt_clcb_dealloc (tGATT_CLCB *p_clcb) -{ - if (p_clcb && p_clcb->in_use) - { - alarm_free(p_clcb->gatt_rsp_timer_ent); - memset(p_clcb, 0, sizeof(tGATT_CLCB)); - } +void gatt_clcb_dealloc(tGATT_CLCB* p_clcb) { + if (p_clcb && p_clcb->in_use) { + alarm_free(p_clcb->gatt_rsp_timer_ent); + memset(p_clcb, 0, sizeof(tGATT_CLCB)); + } } - - /******************************************************************************* * * Function gatt_find_tcb_by_cid @@ -1679,23 +1503,19 @@ void gatt_clcb_dealloc (tGATT_CLCB *p_clcb) * Returns NULL if not found. Otherwise pointer to the rcb. * ******************************************************************************/ -tGATT_TCB * gatt_find_tcb_by_cid (uint16_t lcid) -{ - uint16_t xx = 0; - tGATT_TCB *p_tcb = NULL; +tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid) { + uint16_t xx = 0; + tGATT_TCB* p_tcb = NULL; - for (xx = 0; xx < GATT_MAX_PHY_CHANNEL; xx++) - { - if (gatt_cb.tcb[xx].in_use && gatt_cb.tcb[xx].att_lcid == lcid) - { - p_tcb = &gatt_cb.tcb[xx]; - break; - } + for (xx = 0; xx < GATT_MAX_PHY_CHANNEL; xx++) { + if (gatt_cb.tcb[xx].in_use && gatt_cb.tcb[xx].att_lcid == lcid) { + p_tcb = &gatt_cb.tcb[xx]; + break; } - return p_tcb; + } + return p_tcb; } - /******************************************************************************* * * Function gatt_num_apps_hold_link @@ -1706,21 +1526,17 @@ tGATT_TCB * gatt_find_tcb_by_cid (uint16_t lcid) * Returns total number of applications holding this acl link. * ******************************************************************************/ -uint8_t gatt_num_apps_hold_link(tGATT_TCB *p_tcb) -{ - uint8_t i, num = 0; +uint8_t gatt_num_apps_hold_link(tGATT_TCB* p_tcb) { + uint8_t i, num = 0; - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_tcb->app_hold_link[i]) - num ++; - } + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->app_hold_link[i]) num++; + } - GATT_TRACE_DEBUG("gatt_num_apps_hold_link num=%d", num); - return num; + GATT_TRACE_DEBUG("gatt_num_apps_hold_link num=%d", num); + return num; } - /******************************************************************************* * * Function gatt_num_clcb_by_bd_addr @@ -1730,16 +1546,15 @@ uint8_t gatt_num_apps_hold_link(tGATT_TCB *p_tcb) * Returns total number of clcb found. * ******************************************************************************/ -uint8_t gatt_num_clcb_by_bd_addr(BD_ADDR bda) -{ - uint8_t i, num = 0; +uint8_t gatt_num_clcb_by_bd_addr(BD_ADDR bda) { + uint8_t i, num = 0; - for (i = 0; i < GATT_CL_MAX_LCB; i ++) - { - if (gatt_cb.clcb[i].in_use && memcmp(gatt_cb.clcb[i].p_tcb->peer_bda, bda, BD_ADDR_LEN) == 0) - num ++; - } - return num; + for (i = 0; i < GATT_CL_MAX_LCB; i++) { + if (gatt_cb.clcb[i].in_use && + memcmp(gatt_cb.clcb[i].p_tcb->peer_bda, bda, BD_ADDR_LEN) == 0) + num++; + } + return num; } /******************************************************************************* @@ -1751,21 +1566,16 @@ uint8_t gatt_num_clcb_by_bd_addr(BD_ADDR bda) * Returns total number of clcb found. * ******************************************************************************/ -void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB *p_tcb ) -{ - uint8_t i; +void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB* p_tcb) { + uint8_t i; - if (p_tcb) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_tcb->prep_cnt[i]) - { - p_tcb->sr_cmd.cback_cnt[i]=1; - } - } + if (p_tcb) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->prep_cnt[i]) { + p_tcb->sr_cmd.cback_cnt[i] = 1; + } } - + } } /******************************************************************************* @@ -1777,27 +1587,21 @@ void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB *p_tcb ) * Returns True if thetotal application callback count is zero * ******************************************************************************/ -bool gatt_sr_is_cback_cnt_zero(tGATT_TCB *p_tcb ) -{ - bool status = true; - uint8_t i; - - if (p_tcb) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_tcb->sr_cmd.cback_cnt[i]) - { - status = false; - break; - } - } - } - else - { +bool gatt_sr_is_cback_cnt_zero(tGATT_TCB* p_tcb) { + bool status = true; + uint8_t i; + + if (p_tcb) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->sr_cmd.cback_cnt[i]) { status = false; + break; + } } - return status; + } else { + status = false; + } + return status; } /******************************************************************************* @@ -1809,30 +1613,23 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB *p_tcb ) * Returns True no prepare write request * ******************************************************************************/ -bool gatt_sr_is_prep_cnt_zero(tGATT_TCB *p_tcb) -{ - bool status = true; - uint8_t i; - - if (p_tcb) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_tcb->prep_cnt[i]) - { - status = false; - break; - } - } - } - else - { +bool gatt_sr_is_prep_cnt_zero(tGATT_TCB* p_tcb) { + bool status = true; + uint8_t i; + + if (p_tcb) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_tcb->prep_cnt[i]) { status = false; + break; + } } - return status; + } else { + status = false; + } + return status; } - /******************************************************************************* * * Function gatt_sr_reset_cback_cnt @@ -1842,17 +1639,14 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB *p_tcb) * Returns None * ******************************************************************************/ -void gatt_sr_reset_cback_cnt(tGATT_TCB *p_tcb ) -{ - uint8_t i; +void gatt_sr_reset_cback_cnt(tGATT_TCB* p_tcb) { + uint8_t i; - if (p_tcb) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - p_tcb->sr_cmd.cback_cnt[i]=0; - } + if (p_tcb) { + for (i = 0; i < GATT_MAX_APPS; i++) { + p_tcb->sr_cmd.cback_cnt[i] = 0; } + } } /******************************************************************************* @@ -1864,19 +1658,15 @@ void gatt_sr_reset_cback_cnt(tGATT_TCB *p_tcb ) * Returns None * ******************************************************************************/ -void gatt_sr_reset_prep_cnt(tGATT_TCB *p_tcb ) -{ - uint8_t i; - if (p_tcb) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - p_tcb->prep_cnt[i]=0; - } +void gatt_sr_reset_prep_cnt(tGATT_TCB* p_tcb) { + uint8_t i; + if (p_tcb) { + for (i = 0; i < GATT_MAX_APPS; i++) { + p_tcb->prep_cnt[i] = 0; } + } } - /******************************************************************************* * * Function gatt_sr_update_cback_cnt @@ -1886,32 +1676,24 @@ void gatt_sr_reset_prep_cnt(tGATT_TCB *p_tcb ) * Returns None * ******************************************************************************/ -void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc, bool is_reset_first) -{ +void gatt_sr_update_cback_cnt(tGATT_TCB* p_tcb, tGATT_IF gatt_if, bool is_inc, + bool is_reset_first) { + uint8_t idx = ((uint8_t)gatt_if) - 1; - uint8_t idx = ((uint8_t) gatt_if) - 1 ; - - if (p_tcb) - { - if (is_reset_first) - { - gatt_sr_reset_cback_cnt(p_tcb); - } - if (is_inc) - { - p_tcb->sr_cmd.cback_cnt[idx]++; - } - else - { - if ( p_tcb->sr_cmd.cback_cnt[idx]) - { - p_tcb->sr_cmd.cback_cnt[idx]--; - } - } + if (p_tcb) { + if (is_reset_first) { + gatt_sr_reset_cback_cnt(p_tcb); + } + if (is_inc) { + p_tcb->sr_cmd.cback_cnt[idx]++; + } else { + if (p_tcb->sr_cmd.cback_cnt[idx]) { + p_tcb->sr_cmd.cback_cnt[idx]--; + } } + } } - /******************************************************************************* * * Function gatt_sr_update_prep_cnt @@ -1921,31 +1703,27 @@ void gatt_sr_update_cback_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc * Returns None * ******************************************************************************/ -void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc, bool is_reset_first) -{ - uint8_t idx = ((uint8_t) gatt_if) - 1 ; +void gatt_sr_update_prep_cnt(tGATT_TCB* p_tcb, tGATT_IF gatt_if, bool is_inc, + bool is_reset_first) { + uint8_t idx = ((uint8_t)gatt_if) - 1; - GATT_TRACE_DEBUG("gatt_sr_update_prep_cnt tcb idx=%d gatt_if=%d is_inc=%d is_reset_first=%d", - p_tcb->tcb_idx, gatt_if, is_inc, is_reset_first); + GATT_TRACE_DEBUG( + "gatt_sr_update_prep_cnt tcb idx=%d gatt_if=%d is_inc=%d " + "is_reset_first=%d", + p_tcb->tcb_idx, gatt_if, is_inc, is_reset_first); - if (p_tcb) - { - if (is_reset_first) - { - gatt_sr_reset_prep_cnt(p_tcb); - } - if (is_inc) - { - p_tcb->prep_cnt[idx]++; - } - else - { - if (p_tcb->prep_cnt[idx]) - { - p_tcb->prep_cnt[idx]--; - } - } + if (p_tcb) { + if (is_reset_first) { + gatt_sr_reset_prep_cnt(p_tcb); } + if (is_inc) { + p_tcb->prep_cnt[idx]++; + } else { + if (p_tcb->prep_cnt[idx]) { + p_tcb->prep_cnt[idx]--; + } + } + } } /******************************************************************************* * @@ -1956,31 +1734,26 @@ void gatt_sr_update_prep_cnt(tGATT_TCB *p_tcb, tGATT_IF gatt_if, bool is_inc, * Returns Boolean * ******************************************************************************/ -bool gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda) -{ - tGATT_TCB *p_tcb=NULL; - bool status= true; +bool gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda) { + tGATT_TCB* p_tcb = NULL; + bool status = true; - p_tcb = gatt_find_tcb_by_addr(bda, BT_TRANSPORT_LE); + p_tcb = gatt_find_tcb_by_addr(bda, BT_TRANSPORT_LE); - if (p_tcb) - { - if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) - { - GATT_TRACE_ERROR("GATT_CancelConnect - link connected Too late to cancel"); - status = false; - } - else - { - gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false); - if (!gatt_num_apps_hold_link(p_tcb)) - { - gatt_disconnect(p_tcb); - } - } + if (p_tcb) { + if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) { + GATT_TRACE_ERROR( + "GATT_CancelConnect - link connected Too late to cancel"); + status = false; + } else { + gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false); + if (!gatt_num_apps_hold_link(p_tcb)) { + gatt_disconnect(p_tcb); + } } + } - return status; + return status; } /******************************************************************************* @@ -1992,22 +1765,20 @@ bool gatt_cancel_open(tGATT_IF gatt_if, BD_ADDR bda) * Returns Boolean * ******************************************************************************/ -bool gatt_find_app_hold_link(tGATT_TCB *p_tcb, uint8_t start_idx, uint8_t *p_found_idx, tGATT_IF *p_gatt_if) -{ - uint8_t i; - bool found= false; +bool gatt_find_app_hold_link(tGATT_TCB* p_tcb, uint8_t start_idx, + uint8_t* p_found_idx, tGATT_IF* p_gatt_if) { + uint8_t i; + bool found = false; - for (i = start_idx; i < GATT_MAX_APPS; i ++) - { - if (p_tcb->app_hold_link[i]) - { - *p_gatt_if = gatt_cb.clcb[i].p_reg->gatt_if; - *p_found_idx = i; - found = true; - break; - } + for (i = start_idx; i < GATT_MAX_APPS; i++) { + if (p_tcb->app_hold_link[i]) { + *p_gatt_if = gatt_cb.clcb[i].p_reg->gatt_if; + *p_found_idx = i; + found = true; + break; } - return found; + } + return found; } /******************************************************************************* @@ -2019,24 +1790,23 @@ bool gatt_find_app_hold_link(tGATT_TCB *p_tcb, uint8_t start_idx, uint8_t *p_ * Returns None. * ******************************************************************************/ -bool gatt_cmd_enq(tGATT_TCB *p_tcb, uint16_t clcb_idx, bool to_send, uint8_t op_code, BT_HDR *p_buf) -{ - tGATT_CMD_Q *p_cmd = &p_tcb->cl_cmd_q[p_tcb->next_slot_inq]; +bool gatt_cmd_enq(tGATT_TCB* p_tcb, uint16_t clcb_idx, bool to_send, + uint8_t op_code, BT_HDR* p_buf) { + tGATT_CMD_Q* p_cmd = &p_tcb->cl_cmd_q[p_tcb->next_slot_inq]; - p_cmd->to_send = to_send; /* waiting to be sent */ - p_cmd->op_code = op_code; - p_cmd->p_cmd = p_buf; - p_cmd->clcb_idx = clcb_idx; + p_cmd->to_send = to_send; /* waiting to be sent */ + p_cmd->op_code = op_code; + p_cmd->p_cmd = p_buf; + p_cmd->clcb_idx = clcb_idx; - if (!to_send) - { - p_tcb->pending_cl_req = p_tcb->next_slot_inq; - } + if (!to_send) { + p_tcb->pending_cl_req = p_tcb->next_slot_inq; + } - p_tcb->next_slot_inq ++; - p_tcb->next_slot_inq %= GATT_CL_MAX_LCB; + p_tcb->next_slot_inq++; + p_tcb->next_slot_inq %= GATT_CL_MAX_LCB; - return true; + return true; } /******************************************************************************* @@ -2048,22 +1818,20 @@ bool gatt_cmd_enq(tGATT_TCB *p_tcb, uint16_t clcb_idx, bool to_send, uint8 * Returns total number of clcb found. * ******************************************************************************/ -tGATT_CLCB * gatt_cmd_dequeue(tGATT_TCB *p_tcb, uint8_t *p_op_code) -{ - tGATT_CMD_Q *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; - tGATT_CLCB *p_clcb = NULL; +tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB* p_tcb, uint8_t* p_op_code) { + tGATT_CMD_Q* p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req]; + tGATT_CLCB* p_clcb = NULL; - if (p_tcb->pending_cl_req != p_tcb->next_slot_inq) - { - p_clcb = &gatt_cb.clcb[p_cmd->clcb_idx]; + if (p_tcb->pending_cl_req != p_tcb->next_slot_inq) { + p_clcb = &gatt_cb.clcb[p_cmd->clcb_idx]; - *p_op_code = p_cmd->op_code; + *p_op_code = p_cmd->op_code; - p_tcb->pending_cl_req ++; - p_tcb->pending_cl_req %= GATT_CL_MAX_LCB; - } + p_tcb->pending_cl_req++; + p_tcb->pending_cl_req %= GATT_CL_MAX_LCB; + } - return p_clcb; + return p_clcb; } /******************************************************************************* @@ -2075,20 +1843,19 @@ tGATT_CLCB * gatt_cmd_dequeue(tGATT_TCB *p_tcb, uint8_t *p_op_code) * Returns status code * ******************************************************************************/ -uint8_t gatt_send_write_msg (tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t op_code, - uint16_t handle, uint16_t len, - uint16_t offset, uint8_t *p_data) -{ - tGATT_CL_MSG msg; +uint8_t gatt_send_write_msg(tGATT_TCB* p_tcb, uint16_t clcb_idx, + uint8_t op_code, uint16_t handle, uint16_t len, + uint16_t offset, uint8_t* p_data) { + tGATT_CL_MSG msg; - msg.attr_value.handle = handle; - msg.attr_value.len = len; - msg.attr_value.offset = offset; + msg.attr_value.handle = handle; + msg.attr_value.len = len; + msg.attr_value.offset = offset; - memcpy (msg.attr_value.value, p_data, len); + memcpy(msg.attr_value.value, p_data, len); - /* write by handle */ - return attp_send_cl_msg(p_tcb, clcb_idx, op_code, &msg); + /* write by handle */ + return attp_send_cl_msg(p_tcb, clcb_idx, op_code, &msg); } /******************************************************************************* @@ -2101,17 +1868,17 @@ uint8_t gatt_send_write_msg (tGATT_TCB *p_tcb, uint16_t clcb_idx, uint8_t op_cod * Returns status code * ******************************************************************************/ -uint8_t gatt_act_send_browse(tGATT_TCB *p_tcb, uint16_t index, uint8_t op, uint16_t s_handle, - uint16_t e_handle, tBT_UUID uuid) -{ - tGATT_CL_MSG msg; +uint8_t gatt_act_send_browse(tGATT_TCB* p_tcb, uint16_t index, uint8_t op, + uint16_t s_handle, uint16_t e_handle, + tBT_UUID uuid) { + tGATT_CL_MSG msg; - msg.browse.s_handle = s_handle; - msg.browse.e_handle = e_handle; - memcpy(&msg.browse.uuid, &uuid, sizeof(tBT_UUID)); + msg.browse.s_handle = s_handle; + msg.browse.e_handle = e_handle; + memcpy(&msg.browse.uuid, &uuid, sizeof(tBT_UUID)); - /* write by handle */ - return attp_send_cl_msg(p_tcb, index, op, &msg); + /* write by handle */ + return attp_send_cl_msg(p_tcb, index, op, &msg); } /******************************************************************************* @@ -2124,72 +1891,65 @@ uint8_t gatt_act_send_browse(tGATT_TCB *p_tcb, uint16_t index, uint8_t op, uint1 * Returns 16 bits uuid. * ******************************************************************************/ -void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data) -{ - tGATT_CL_COMPLETE cb_data; - tGATT_CMPL_CBACK *p_cmpl_cb = (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_cmpl_cb : NULL; - uint8_t op = p_clcb->operation, disc_type=GATT_DISC_MAX; - tGATT_DISC_CMPL_CB *p_disc_cmpl_cb = (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_disc_cmpl_cb : NULL; - uint16_t conn_id; - uint8_t operation; - - GATT_TRACE_DEBUG ("gatt_end_operation status=%d op=%d subtype=%d", - status, p_clcb->operation, p_clcb->op_subtype); - memset(&cb_data.att_value, 0, sizeof(tGATT_VALUE)); - - if (p_cmpl_cb != NULL && p_clcb->operation != 0) - { - if (p_clcb->operation == GATTC_OPTYPE_READ) - { - cb_data.att_value.handle = p_clcb->s_handle; - cb_data.att_value.len = p_clcb->counter; - - if (p_data && p_clcb->counter) - memcpy (cb_data.att_value.value, p_data, cb_data.att_value.len); - } - - if (p_clcb->operation == GATTC_OPTYPE_WRITE) - { - memset(&cb_data.att_value, 0, sizeof(tGATT_VALUE)); - cb_data.handle = - cb_data.att_value.handle = p_clcb->s_handle; - if (p_clcb->op_subtype == GATT_WRITE_PREPARE) - { - if (p_data) - { - cb_data.att_value = *((tGATT_VALUE *) p_data); - } - else - { - GATT_TRACE_DEBUG("Rcv Prepare write rsp but no data"); - } - } +void gatt_end_operation(tGATT_CLCB* p_clcb, tGATT_STATUS status, void* p_data) { + tGATT_CL_COMPLETE cb_data; + tGATT_CMPL_CBACK* p_cmpl_cb = + (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_cmpl_cb : NULL; + uint8_t op = p_clcb->operation, disc_type = GATT_DISC_MAX; + tGATT_DISC_CMPL_CB* p_disc_cmpl_cb = + (p_clcb->p_reg) ? p_clcb->p_reg->app_cb.p_disc_cmpl_cb : NULL; + uint16_t conn_id; + uint8_t operation; + + GATT_TRACE_DEBUG("gatt_end_operation status=%d op=%d subtype=%d", status, + p_clcb->operation, p_clcb->op_subtype); + memset(&cb_data.att_value, 0, sizeof(tGATT_VALUE)); + + if (p_cmpl_cb != NULL && p_clcb->operation != 0) { + if (p_clcb->operation == GATTC_OPTYPE_READ) { + cb_data.att_value.handle = p_clcb->s_handle; + cb_data.att_value.len = p_clcb->counter; + + if (p_data && p_clcb->counter) + memcpy(cb_data.att_value.value, p_data, cb_data.att_value.len); + } + + if (p_clcb->operation == GATTC_OPTYPE_WRITE) { + memset(&cb_data.att_value, 0, sizeof(tGATT_VALUE)); + cb_data.handle = cb_data.att_value.handle = p_clcb->s_handle; + if (p_clcb->op_subtype == GATT_WRITE_PREPARE) { + if (p_data) { + cb_data.att_value = *((tGATT_VALUE*)p_data); + } else { + GATT_TRACE_DEBUG("Rcv Prepare write rsp but no data"); } + } + } - if (p_clcb->operation == GATTC_OPTYPE_CONFIG) - cb_data.mtu = p_clcb->p_tcb->payload_size; + if (p_clcb->operation == GATTC_OPTYPE_CONFIG) + cb_data.mtu = p_clcb->p_tcb->payload_size; - if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) - { - disc_type = p_clcb->op_subtype; - } + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) { + disc_type = p_clcb->op_subtype; } + } - osi_free_and_reset((void **)&p_clcb->p_attr_buf); + osi_free_and_reset((void**)&p_clcb->p_attr_buf); - operation = p_clcb->operation; - conn_id = p_clcb->conn_id; - alarm_cancel(p_clcb->gatt_rsp_timer_ent); + operation = p_clcb->operation; + conn_id = p_clcb->conn_id; + alarm_cancel(p_clcb->gatt_rsp_timer_ent); - gatt_clcb_dealloc(p_clcb); + gatt_clcb_dealloc(p_clcb); - if (p_disc_cmpl_cb && (op == GATTC_OPTYPE_DISCOVERY)) - (*p_disc_cmpl_cb)(conn_id, disc_type, status); - else if (p_cmpl_cb && op) - (*p_cmpl_cb)(conn_id, op, status, &cb_data); - else - GATT_TRACE_WARNING ("gatt_end_operation not sent out op=%d p_disc_cmpl_cb:%p p_cmpl_cb:%p", - operation, p_disc_cmpl_cb, p_cmpl_cb); + if (p_disc_cmpl_cb && (op == GATTC_OPTYPE_DISCOVERY)) + (*p_disc_cmpl_cb)(conn_id, disc_type, status); + else if (p_cmpl_cb && op) + (*p_cmpl_cb)(conn_id, op, status, &cb_data); + else + GATT_TRACE_WARNING( + "gatt_end_operation not sent out op=%d p_disc_cmpl_cb:%p p_cmpl_cb:%p", + operation, p_disc_cmpl_cb, p_cmpl_cb); } /******************************************************************************* @@ -2202,60 +1962,55 @@ void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data) * Returns 16 bits uuid. * ******************************************************************************/ -void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason, tBT_TRANSPORT transport) -{ - tGATT_TCB *p_tcb = NULL; - tGATT_CLCB *p_clcb; - uint8_t i; - uint16_t conn_id; - tGATT_REG *p_reg=NULL; - - - GATT_TRACE_DEBUG ("gatt_cleanup_upon_disc "); - - p_tcb = gatt_find_tcb_by_addr(bda, transport); - if (p_tcb != NULL) - { - GATT_TRACE_DEBUG ("found p_tcb "); - gatt_set_ch_state(p_tcb, GATT_CH_CLOSE); - for (i = 0; i < GATT_CL_MAX_LCB; i ++) - { - p_clcb = &gatt_cb.clcb[i]; - if (p_clcb->in_use && p_clcb->p_tcb == p_tcb) - { - alarm_cancel(p_clcb->gatt_rsp_timer_ent); - GATT_TRACE_DEBUG ("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id, p_clcb->clcb_idx); - if (p_clcb->operation != GATTC_OPTYPE_NONE) - gatt_end_operation(p_clcb, GATT_ERROR, NULL); - - gatt_clcb_dealloc(p_clcb); - - } - } - - alarm_free(p_tcb->ind_ack_timer); - p_tcb->ind_ack_timer = NULL; - alarm_free(p_tcb->conf_timer); - p_tcb->conf_timer = NULL; - gatt_free_pending_ind(p_tcb); - gatt_free_pending_enc_queue(p_tcb); - fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL); - p_tcb->sr_cmd.multi_rsp_q = NULL; - - for (i = 0; i < GATT_MAX_APPS; i ++) - { - p_reg = &gatt_cb.cl_rcb[i]; - if (p_reg->in_use && p_reg->app_cb.p_conn_cb) - { - conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); - GATT_TRACE_DEBUG ("found p_reg tcb_idx=%d gatt_if=%d conn_id=0x%x", p_tcb->tcb_idx, p_reg->gatt_if, conn_id); - (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, false, reason, transport); - } - } - memset(p_tcb, 0, sizeof(tGATT_TCB)); - - } - GATT_TRACE_DEBUG ("exit gatt_cleanup_upon_disc "); +void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason, + tBT_TRANSPORT transport) { + tGATT_TCB* p_tcb = NULL; + tGATT_CLCB* p_clcb; + uint8_t i; + uint16_t conn_id; + tGATT_REG* p_reg = NULL; + + GATT_TRACE_DEBUG("gatt_cleanup_upon_disc "); + + p_tcb = gatt_find_tcb_by_addr(bda, transport); + if (p_tcb != NULL) { + GATT_TRACE_DEBUG("found p_tcb "); + gatt_set_ch_state(p_tcb, GATT_CH_CLOSE); + for (i = 0; i < GATT_CL_MAX_LCB; i++) { + p_clcb = &gatt_cb.clcb[i]; + if (p_clcb->in_use && p_clcb->p_tcb == p_tcb) { + alarm_cancel(p_clcb->gatt_rsp_timer_ent); + GATT_TRACE_DEBUG("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id, + p_clcb->clcb_idx); + if (p_clcb->operation != GATTC_OPTYPE_NONE) + gatt_end_operation(p_clcb, GATT_ERROR, NULL); + + gatt_clcb_dealloc(p_clcb); + } + } + + alarm_free(p_tcb->ind_ack_timer); + p_tcb->ind_ack_timer = NULL; + alarm_free(p_tcb->conf_timer); + p_tcb->conf_timer = NULL; + gatt_free_pending_ind(p_tcb); + gatt_free_pending_enc_queue(p_tcb); + fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL); + p_tcb->sr_cmd.multi_rsp_q = NULL; + + for (i = 0; i < GATT_MAX_APPS; i++) { + p_reg = &gatt_cb.cl_rcb[i]; + if (p_reg->in_use && p_reg->app_cb.p_conn_cb) { + conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if); + GATT_TRACE_DEBUG("found p_reg tcb_idx=%d gatt_if=%d conn_id=0x%x", + p_tcb->tcb_idx, p_reg->gatt_if, conn_id); + (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, false, reason, + transport); + } + } + memset(p_tcb, 0, sizeof(tGATT_TCB)); + } + GATT_TRACE_DEBUG("exit gatt_cleanup_upon_disc "); } /******************************************************************************* * @@ -2266,25 +2021,21 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason, tBT_TRANSPORT transpor * Returns uint8_t *: name of the operation. * ******************************************************************************/ -uint8_t * gatt_dbg_op_name(uint8_t op_code) -{ - uint8_t pseduo_op_code_idx = op_code & (~GATT_WRITE_CMD_MASK); - - if (op_code == GATT_CMD_WRITE ) - { - pseduo_op_code_idx = 0x14; /* just an index to op_code_name */ +uint8_t* gatt_dbg_op_name(uint8_t op_code) { + uint8_t pseduo_op_code_idx = op_code & (~GATT_WRITE_CMD_MASK); - } + if (op_code == GATT_CMD_WRITE) { + pseduo_op_code_idx = 0x14; /* just an index to op_code_name */ + } - if (op_code == GATT_SIGN_CMD_WRITE) - { - pseduo_op_code_idx = 0x15; /* just an index to op_code_name */ - } + if (op_code == GATT_SIGN_CMD_WRITE) { + pseduo_op_code_idx = 0x15; /* just an index to op_code_name */ + } - if (pseduo_op_code_idx <= GATT_OP_CODE_MAX) - return(uint8_t*) op_code_name[pseduo_op_code_idx]; - else - return(uint8_t *)"Op Code Exceed Max"; + if (pseduo_op_code_idx <= GATT_OP_CODE_MAX) + return (uint8_t*)op_code_name[pseduo_op_code_idx]; + else + return (uint8_t*)"Op Code Exceed Max"; } /******************************************************************************* @@ -2296,40 +2047,31 @@ uint8_t * gatt_dbg_op_name(uint8_t op_code) * Returns None * ******************************************************************************/ -void gatt_dbg_display_uuid(tBT_UUID bt_uuid) -{ - char str_buf[50]; +void gatt_dbg_display_uuid(tBT_UUID bt_uuid) { + char str_buf[50]; - if (bt_uuid.len == LEN_UUID_16) - { - snprintf(str_buf, sizeof(str_buf), "0x%04x", bt_uuid.uu.uuid16); - } - else if (bt_uuid.len == LEN_UUID_32) - { - snprintf(str_buf, sizeof(str_buf), "0x%08x", (unsigned int)bt_uuid.uu.uuid32); - } - else if (bt_uuid.len == LEN_UUID_128) - { - int x = snprintf(str_buf, sizeof(str_buf), - "0x%02x%02x%02x%02x%02x%02x%02x%02x", - bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14], - bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12], - bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10], - bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]); - snprintf(&str_buf[x], sizeof(str_buf) - x, - "%02x%02x%02x%02x%02x%02x%02x%02x", - bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6], - bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4], - bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2], - bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]); - } - else - strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf)); + if (bt_uuid.len == LEN_UUID_16) { + snprintf(str_buf, sizeof(str_buf), "0x%04x", bt_uuid.uu.uuid16); + } else if (bt_uuid.len == LEN_UUID_32) { + snprintf(str_buf, sizeof(str_buf), "0x%08x", + (unsigned int)bt_uuid.uu.uuid32); + } else if (bt_uuid.len == LEN_UUID_128) { + int x = snprintf( + str_buf, sizeof(str_buf), "0x%02x%02x%02x%02x%02x%02x%02x%02x", + bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14], bt_uuid.uu.uuid128[13], + bt_uuid.uu.uuid128[12], bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10], + bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]); + snprintf( + &str_buf[x], sizeof(str_buf) - x, "%02x%02x%02x%02x%02x%02x%02x%02x", + bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6], bt_uuid.uu.uuid128[5], + bt_uuid.uu.uuid128[4], bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2], + bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]); + } else + strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf)); - GATT_TRACE_DEBUG ("UUID=[%s]", str_buf); + GATT_TRACE_DEBUG("UUID=[%s]", str_buf); } - /******************************************************************************* * * Function gatt_is_bg_dev_for_app @@ -2339,18 +2081,15 @@ void gatt_dbg_display_uuid(tBT_UUID bt_uuid) * Returns true if it is, otherwise false * ******************************************************************************/ -bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV *p_dev, tGATT_IF gatt_if) -{ - uint8_t i; +bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if) { + uint8_t i; - for (i = 0; i < GATT_MAX_APPS; i ++ ) - { - if (p_dev->in_use && (p_dev->gatt_if[i] == gatt_if)) - { - return true; - } + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_dev->in_use && (p_dev->gatt_if[i] == gatt_if)) { + return true; } - return false; + } + return false; } /******************************************************************************* * @@ -2361,19 +2100,17 @@ bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV *p_dev, tGATT_IF gatt_if) * Returns pointer to the device record * ******************************************************************************/ -tGATT_BG_CONN_DEV * gatt_find_bg_dev(BD_ADDR remote_bda) -{ - tGATT_BG_CONN_DEV *p_dev_list = &gatt_cb.bgconn_dev[0]; - uint8_t i; +tGATT_BG_CONN_DEV* gatt_find_bg_dev(BD_ADDR remote_bda) { + tGATT_BG_CONN_DEV* p_dev_list = &gatt_cb.bgconn_dev[0]; + uint8_t i; - for (i = 0; i < GATT_MAX_BG_CONN_DEV; i ++, p_dev_list ++) - { - if (p_dev_list->in_use && !memcmp(p_dev_list->remote_bda, remote_bda, BD_ADDR_LEN)) - { - return p_dev_list; - } + for (i = 0; i < GATT_MAX_BG_CONN_DEV; i++, p_dev_list++) { + if (p_dev_list->in_use && + !memcmp(p_dev_list->remote_bda, remote_bda, BD_ADDR_LEN)) { + return p_dev_list; } - return NULL; + } + return NULL; } /******************************************************************************* * @@ -2384,22 +2121,19 @@ tGATT_BG_CONN_DEV * gatt_find_bg_dev(BD_ADDR remote_bda) * Returns pointer to the device record * ******************************************************************************/ -tGATT_BG_CONN_DEV * gatt_alloc_bg_dev(BD_ADDR remote_bda) -{ - tGATT_BG_CONN_DEV *p_dev_list = &gatt_cb.bgconn_dev[0]; - uint8_t i; +tGATT_BG_CONN_DEV* gatt_alloc_bg_dev(BD_ADDR remote_bda) { + tGATT_BG_CONN_DEV* p_dev_list = &gatt_cb.bgconn_dev[0]; + uint8_t i; - for (i = 0; i < GATT_MAX_BG_CONN_DEV; i ++, p_dev_list ++) - { - if (!p_dev_list->in_use) - { - p_dev_list->in_use = true; - memcpy(p_dev_list->remote_bda, remote_bda, BD_ADDR_LEN); + for (i = 0; i < GATT_MAX_BG_CONN_DEV; i++, p_dev_list++) { + if (!p_dev_list->in_use) { + p_dev_list->in_use = true; + memcpy(p_dev_list->remote_bda, remote_bda, BD_ADDR_LEN); - return p_dev_list; - } + return p_dev_list; } - return NULL; + } + return NULL; } /******************************************************************************* @@ -2411,45 +2145,36 @@ tGATT_BG_CONN_DEV * gatt_alloc_bg_dev(BD_ADDR remote_bda) * Returns true if device added to the list; false failed * ******************************************************************************/ -bool gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr) -{ - tGATT_IF gatt_if = p_reg->gatt_if; - tGATT_BG_CONN_DEV *p_dev = NULL; - uint8_t i; - bool ret = false; +bool gatt_add_bg_dev_list(tGATT_REG* p_reg, BD_ADDR bd_addr) { + tGATT_IF gatt_if = p_reg->gatt_if; + tGATT_BG_CONN_DEV* p_dev = NULL; + uint8_t i; + bool ret = false; - p_dev = gatt_find_bg_dev(bd_addr); - if (p_dev == NULL) - { - p_dev = gatt_alloc_bg_dev(bd_addr); - } + p_dev = gatt_find_bg_dev(bd_addr); + if (p_dev == NULL) { + p_dev = gatt_alloc_bg_dev(bd_addr); + } - if (p_dev) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_dev->gatt_if[i] == gatt_if) - { - GATT_TRACE_ERROR("device already in iniator white list"); - return true; - } - else if (p_dev->gatt_if[i] == 0) - { - p_dev->gatt_if[i] = gatt_if; - if (i == 0) - ret = BTM_BleUpdateBgConnDev(true, bd_addr); - else - ret = true; - break; - } - } - } - else - { - GATT_TRACE_ERROR("no device record available"); + if (p_dev) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_dev->gatt_if[i] == gatt_if) { + GATT_TRACE_ERROR("device already in iniator white list"); + return true; + } else if (p_dev->gatt_if[i] == 0) { + p_dev->gatt_if[i] = gatt_if; + if (i == 0) + ret = BTM_BleUpdateBgConnDev(true, bd_addr); + else + ret = true; + break; + } } + } else { + GATT_TRACE_ERROR("no device record available"); + } - return ret; + return ret; } /******************************************************************************* @@ -2462,18 +2187,15 @@ bool gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr) * Returns Boolean * ******************************************************************************/ -bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr) -{ - tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); - bool status; +bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr) { + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); + bool status; - if (p_tcb) - gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false); - status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr); - return status; + if (p_tcb) gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false); + status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr); + return status; } - /******************************************************************************* * * Function gatt_get_num_apps_for_bg_dev @@ -2484,22 +2206,18 @@ bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr) * Returns uint8_t total number fo applications * ******************************************************************************/ -uint8_t gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr) -{ - tGATT_BG_CONN_DEV *p_dev = NULL; - uint8_t i; - uint8_t cnt = 0; +uint8_t gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr) { + tGATT_BG_CONN_DEV* p_dev = NULL; + uint8_t i; + uint8_t cnt = 0; - p_dev = gatt_find_bg_dev(bd_addr); - if (p_dev != NULL) - { - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_dev->gatt_if[i]) - cnt++; - } + p_dev = gatt_find_bg_dev(bd_addr); + if (p_dev != NULL) { + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_dev->gatt_if[i]) cnt++; } - return cnt; + } + return cnt; } /******************************************************************************* @@ -2512,31 +2230,26 @@ uint8_t gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr) * Returns Boolean * ******************************************************************************/ -bool gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF *p_gatt_if) -{ - tGATT_BG_CONN_DEV *p_dev = NULL; - uint8_t i; - bool ret = false; +bool gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF* p_gatt_if) { + tGATT_BG_CONN_DEV* p_dev = NULL; + uint8_t i; + bool ret = false; - p_dev = gatt_find_bg_dev(bd_addr); - if (p_dev == NULL) - { - return ret; - } + p_dev = gatt_find_bg_dev(bd_addr); + if (p_dev == NULL) { + return ret; + } - for (i = 0; i < GATT_MAX_APPS; i ++) - { - if (p_dev->gatt_if[i] != 0 ) - { - *p_gatt_if = p_dev->gatt_if[i]; - ret = true; - break; - } + for (i = 0; i < GATT_MAX_APPS; i++) { + if (p_dev->gatt_if[i] != 0) { + *p_gatt_if = p_dev->gatt_if[i]; + ret = true; + break; } - return ret; + } + return ret; } - /******************************************************************************* * * Function gatt_remove_bg_dev_from_list @@ -2547,43 +2260,38 @@ bool gatt_find_app_for_bg_dev(BD_ADDR bd_addr, tGATT_IF *p_gatt_if) * Returns pointer to the device record * ******************************************************************************/ -bool gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr) -{ - tGATT_IF gatt_if = p_reg->gatt_if; - tGATT_BG_CONN_DEV *p_dev = NULL; - uint8_t i, j; - bool ret = false; +bool gatt_remove_bg_dev_from_list(tGATT_REG* p_reg, BD_ADDR bd_addr) { + tGATT_IF gatt_if = p_reg->gatt_if; + tGATT_BG_CONN_DEV* p_dev = NULL; + uint8_t i, j; + bool ret = false; - p_dev = gatt_find_bg_dev(bd_addr); - if (p_dev == NULL) - { - return ret; - } + p_dev = gatt_find_bg_dev(bd_addr); + if (p_dev == NULL) { + return ret; + } - for (i = 0; i < GATT_MAX_APPS && (p_dev->gatt_if[i] > 0); i ++) - { - if (p_dev->gatt_if[i] == gatt_if) - { - p_dev->gatt_if[i] = 0; - /* move all element behind one forward */ - for (j = i + 1; j < GATT_MAX_APPS; j ++) - p_dev->gatt_if[j - 1] = p_dev->gatt_if[j]; - - if (p_dev->gatt_if[0] == 0) - ret = BTM_BleUpdateBgConnDev(false, p_dev->remote_bda); - else - ret = true; - - break; - } - } + for (i = 0; i < GATT_MAX_APPS && (p_dev->gatt_if[i] > 0); i++) { + if (p_dev->gatt_if[i] == gatt_if) { + p_dev->gatt_if[i] = 0; + /* move all element behind one forward */ + for (j = i + 1; j < GATT_MAX_APPS; j++) + p_dev->gatt_if[j - 1] = p_dev->gatt_if[j]; - if (i != GATT_MAX_APPS && p_dev->gatt_if[0] == 0) - { - memset(p_dev, 0, sizeof(tGATT_BG_CONN_DEV)); + if (p_dev->gatt_if[0] == 0) + ret = BTM_BleUpdateBgConnDev(false, p_dev->remote_bda); + else + ret = true; + + break; } + } - return ret; + if (i != GATT_MAX_APPS && p_dev->gatt_if[0] == 0) { + memset(p_dev, 0, sizeof(tGATT_BG_CONN_DEV)); + } + + return ret; } /******************************************************************************* * @@ -2594,35 +2302,28 @@ bool gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr) * Returns pointer to the device record * ******************************************************************************/ -void gatt_deregister_bgdev_list(tGATT_IF gatt_if) -{ - tGATT_BG_CONN_DEV *p_dev_list = &gatt_cb.bgconn_dev[0]; - uint8_t i , j, k; - - /* update the BG conn device list */ - for (i = 0 ; i in_use) - { - for (j = 0; j < GATT_MAX_APPS; j ++) - { - if (p_dev_list->gatt_if[j] == 0) - break; - - if (p_dev_list->gatt_if[j] == gatt_if) - { - for (k = j + 1; k < GATT_MAX_APPS; k ++) - p_dev_list->gatt_if[k - 1] = p_dev_list->gatt_if[k]; - - if (p_dev_list->gatt_if[0] == 0) - BTM_BleUpdateBgConnDev(false, p_dev_list->remote_bda); - } - } +void gatt_deregister_bgdev_list(tGATT_IF gatt_if) { + tGATT_BG_CONN_DEV* p_dev_list = &gatt_cb.bgconn_dev[0]; + uint8_t i, j, k; + + /* update the BG conn device list */ + for (i = 0; i < GATT_MAX_BG_CONN_DEV; i++, p_dev_list++) { + if (p_dev_list->in_use) { + for (j = 0; j < GATT_MAX_APPS; j++) { + if (p_dev_list->gatt_if[j] == 0) break; + + if (p_dev_list->gatt_if[j] == gatt_if) { + for (k = j + 1; k < GATT_MAX_APPS; k++) + p_dev_list->gatt_if[k - 1] = p_dev_list->gatt_if[k]; + + if (p_dev_list->gatt_if[0] == 0) + BTM_BleUpdateBgConnDev(false, p_dev_list->remote_bda); } + } } + } } - /******************************************************************************* * * Function gatt_reset_bgdev_list @@ -2632,10 +2333,9 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) * Returns pointer to the device record * ******************************************************************************/ -void gatt_reset_bgdev_list(void) -{ - memset(&gatt_cb.bgconn_dev, 0 , sizeof(tGATT_BG_CONN_DEV)*GATT_MAX_BG_CONN_DEV); - +void gatt_reset_bgdev_list(void) { + memset(&gatt_cb.bgconn_dev, 0, + sizeof(tGATT_BG_CONN_DEV) * GATT_MAX_BG_CONN_DEV); } /******************************************************************************* * @@ -2651,40 +2351,33 @@ void gatt_reset_bgdev_list(void) * Returns true if connection started; false otherwise. * ******************************************************************************/ -bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr) -{ - bool ret = false; - tGATT_REG *p_reg; - tGATT_TCB *p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); +bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add, BD_ADDR bd_addr) { + bool ret = false; + tGATT_REG* p_reg; + tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE); - GATT_TRACE_API ("gatt_update_auto_connect_dev "); - /* Make sure app is registered */ - p_reg = gatt_get_regcb(gatt_if); - if (p_reg == NULL) - { - GATT_TRACE_ERROR("gatt_update_auto_connect_dev - gatt_if is not registered", gatt_if); - return(false); - } + GATT_TRACE_API("gatt_update_auto_connect_dev "); + /* Make sure app is registered */ + p_reg = gatt_get_regcb(gatt_if); + if (p_reg == NULL) { + GATT_TRACE_ERROR("gatt_update_auto_connect_dev - gatt_if is not registered", + gatt_if); + return (false); + } - if (add) - { - ret = gatt_add_bg_dev_list(p_reg, bd_addr); + if (add) { + ret = gatt_add_bg_dev_list(p_reg, bd_addr); - if (ret && p_tcb != NULL) - { - /* if a connected device, update the link holding number */ - gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true); - } - } - else - { - ret = gatt_remove_bg_dev_from_list(p_reg, bd_addr); + if (ret && p_tcb != NULL) { + /* if a connected device, update the link holding number */ + gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true); } - return ret; + } else { + ret = gatt_remove_bg_dev_from_list(p_reg, bd_addr); + } + return ret; } - - /******************************************************************************* * * Function gatt_add_pending_new_srv_start @@ -2694,16 +2387,16 @@ bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_ * Returns Pointer to the new service start buffer, NULL no buffer available * ******************************************************************************/ -tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb) -{ - tGATT_PENDING_ENC_CLCB *p_buf = - (tGATT_PENDING_ENC_CLCB *)osi_malloc(sizeof(tGATT_PENDING_ENC_CLCB)); +tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb(tGATT_TCB* p_tcb, + tGATT_CLCB* p_clcb) { + tGATT_PENDING_ENC_CLCB* p_buf = + (tGATT_PENDING_ENC_CLCB*)osi_malloc(sizeof(tGATT_PENDING_ENC_CLCB)); - GATT_TRACE_DEBUG ("%s", __func__); - GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb"); + GATT_TRACE_DEBUG("%s", __func__); + GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb"); - p_buf->p_clcb = p_clcb; - fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf); + p_buf->p_clcb = p_clcb; + fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf); - return p_buf; + return p_buf; } diff --git a/stack/hcic/hciblecmds.cc b/stack/hcic/hciblecmds.cc index 65251682f..407752744 100644 --- a/stack/hcic/hciblecmds.cc +++ b/stack/hcic/hciblecmds.cc @@ -23,706 +23,669 @@ * ******************************************************************************/ -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" +#include "btu.h" #include "hcidefs.h" #include "hcimsgs.h" -#include "hcidefs.h" -#include "btu.h" #include #include -void btsnd_hcic_ble_set_local_used_feat (uint8_t feat_set[8]) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT); - ARRAY_TO_STREAM (pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT); + ARRAY_TO_STREAM(pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_random_addr (BD_ADDR random_bda) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_random_addr(BD_ADDR random_bda) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_RANDOM_ADDR); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_RANDOM_ADDR); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD); - BDADDR_TO_STREAM (pp, random_bda); + BDADDR_TO_STREAM(pp, random_bda); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_write_adv_params (uint16_t adv_int_min, uint16_t adv_int_max, - uint8_t adv_type, uint8_t addr_type_own, - uint8_t addr_type_dir, BD_ADDR direct_bda, - uint8_t channel_map, uint8_t adv_filter_policy) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, + uint8_t adv_type, uint8_t addr_type_own, + uint8_t addr_type_dir, BD_ADDR direct_bda, + uint8_t channel_map, + uint8_t adv_filter_policy) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS ; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_PARAMS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS ); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_PARAMS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS); - UINT16_TO_STREAM (pp, adv_int_min); - UINT16_TO_STREAM (pp, adv_int_max); - UINT8_TO_STREAM (pp, adv_type); - UINT8_TO_STREAM (pp, addr_type_own); - UINT8_TO_STREAM (pp, addr_type_dir); - BDADDR_TO_STREAM (pp, direct_bda); - UINT8_TO_STREAM (pp, channel_map); - UINT8_TO_STREAM (pp, adv_filter_policy); + UINT16_TO_STREAM(pp, adv_int_min); + UINT16_TO_STREAM(pp, adv_int_max); + UINT8_TO_STREAM(pp, adv_type); + UINT8_TO_STREAM(pp, addr_type_own); + UINT8_TO_STREAM(pp, addr_type_dir); + BDADDR_TO_STREAM(pp, direct_bda); + UINT8_TO_STREAM(pp, channel_map); + UINT8_TO_STREAM(pp, adv_filter_policy); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_adv_chnl_tx_power (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_read_adv_chnl_tx_power(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_READ_ADV_CHNL_TX_POWER); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CMD); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_READ_ADV_CHNL_TX_POWER); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_adv_data (uint8_t data_len, uint8_t *p_data) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1; - p->offset = 0; +void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_DATA); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1; + p->offset = 0; - memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_DATA); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1); - if (p_data != NULL && data_len > 0) - { - if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) - data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA; + memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA); - UINT8_TO_STREAM (pp, data_len); + if (p_data != NULL && data_len > 0) { + if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) + data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA; - ARRAY_TO_STREAM (pp, p_data, data_len); - } - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT8_TO_STREAM(pp, data_len); + ARRAY_TO_STREAM(pp, p_data, data_len); + } + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_scan_rsp_data (uint8_t data_len, uint8_t *p_scan_rsp) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1; - p->offset = 0; - - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_RSP_DATA); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1); +void btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len, uint8_t* p_scan_rsp) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1; + p->offset = 0; - if (p_scan_rsp != NULL && data_len > 0) - { + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_RSP_DATA); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1); - if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP ) - data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP; + memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP); - UINT8_TO_STREAM (pp, data_len); + if (p_scan_rsp != NULL && data_len > 0) { + if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP) + data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP; - ARRAY_TO_STREAM (pp, p_scan_rsp, data_len); - } + UINT8_TO_STREAM(pp, data_len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + ARRAY_TO_STREAM(pp, p_scan_rsp, data_len); + } + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_adv_enable (uint8_t adv_enable) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_ENABLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE); - UINT8_TO_STREAM (pp, adv_enable); + UINT8_TO_STREAM(pp, adv_enable); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_scan_params (uint8_t scan_type, - uint16_t scan_int, uint16_t scan_win, - uint8_t addr_type_own, uint8_t scan_filter_policy) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int, + uint16_t scan_win, uint8_t addr_type_own, + uint8_t scan_filter_policy) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_PARAMS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_PARAMS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM); - UINT8_TO_STREAM (pp, scan_type); - UINT16_TO_STREAM (pp, scan_int); - UINT16_TO_STREAM (pp, scan_win); - UINT8_TO_STREAM (pp, addr_type_own); - UINT8_TO_STREAM (pp, scan_filter_policy); + UINT8_TO_STREAM(pp, scan_type); + UINT16_TO_STREAM(pp, scan_int); + UINT16_TO_STREAM(pp, scan_win); + UINT8_TO_STREAM(pp, addr_type_own); + UINT8_TO_STREAM(pp, scan_filter_policy); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_scan_enable (uint8_t scan_enable, uint8_t duplicate) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, uint8_t duplicate) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_ENABLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE); + UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE); - UINT8_TO_STREAM (pp, scan_enable); - UINT8_TO_STREAM (pp, duplicate); + UINT8_TO_STREAM(pp, scan_enable); + UINT8_TO_STREAM(pp, duplicate); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } /* link layer connection management commands */ -void btsnd_hcic_ble_create_ll_conn (uint16_t scan_int, uint16_t scan_win, - uint8_t init_filter_policy, - uint8_t addr_type_peer, BD_ADDR bda_peer, - uint8_t addr_type_own, - uint16_t conn_int_min, uint16_t conn_int_max, - uint16_t conn_latency, uint16_t conn_timeout, - uint16_t min_ce_len, uint16_t max_ce_len) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_create_ll_conn(uint16_t scan_int, uint16_t scan_win, + uint8_t init_filter_policy, + uint8_t addr_type_peer, BD_ADDR bda_peer, + uint8_t addr_type_own, uint16_t conn_int_min, + uint16_t conn_int_max, uint16_t conn_latency, + uint16_t conn_timeout, uint16_t min_ce_len, + uint16_t max_ce_len) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_CREATE_LL_CONN); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN); + UINT16_TO_STREAM(pp, HCI_BLE_CREATE_LL_CONN); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN); - UINT16_TO_STREAM (pp, scan_int); - UINT16_TO_STREAM (pp, scan_win); - UINT8_TO_STREAM (pp, init_filter_policy); + UINT16_TO_STREAM(pp, scan_int); + UINT16_TO_STREAM(pp, scan_win); + UINT8_TO_STREAM(pp, init_filter_policy); - UINT8_TO_STREAM (pp, addr_type_peer); - BDADDR_TO_STREAM (pp, bda_peer); - UINT8_TO_STREAM (pp, addr_type_own); + UINT8_TO_STREAM(pp, addr_type_peer); + BDADDR_TO_STREAM(pp, bda_peer); + UINT8_TO_STREAM(pp, addr_type_own); - UINT16_TO_STREAM (pp, conn_int_min); - UINT16_TO_STREAM (pp, conn_int_max); - UINT16_TO_STREAM (pp, conn_latency); - UINT16_TO_STREAM (pp, conn_timeout); + UINT16_TO_STREAM(pp, conn_int_min); + UINT16_TO_STREAM(pp, conn_int_max); + UINT16_TO_STREAM(pp, conn_latency); + UINT16_TO_STREAM(pp, conn_timeout); - UINT16_TO_STREAM (pp, min_ce_len); - UINT16_TO_STREAM (pp, max_ce_len); + UINT16_TO_STREAM(pp, min_ce_len); + UINT16_TO_STREAM(pp, max_ce_len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_create_conn_cancel (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_create_conn_cancel(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_CREATE_CONN_CANCEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL); + UINT16_TO_STREAM(pp, HCI_BLE_CREATE_CONN_CANCEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_clear_white_list (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_clear_white_list(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CLEAR_WHITE_LIST; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CLEAR_WHITE_LIST; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_CLEAR_WHITE_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CLEAR_WHITE_LIST); + UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_WHITE_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_WHITE_LIST); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_add_white_list (uint8_t addr_type, BD_ADDR bda) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_add_white_list(uint8_t addr_type, BD_ADDR bda) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_WHITE_LIST; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_WHITE_LIST; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_ADD_WHITE_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_ADD_WHITE_LIST); + UINT16_TO_STREAM(pp, HCI_BLE_ADD_WHITE_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_WHITE_LIST); - UINT8_TO_STREAM (pp, addr_type); - BDADDR_TO_STREAM (pp, bda); + UINT8_TO_STREAM(pp, addr_type); + BDADDR_TO_STREAM(pp, bda); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_remove_from_white_list (uint8_t addr_type, BD_ADDR bda) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_remove_from_white_list(uint8_t addr_type, BD_ADDR bda) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REMOVE_WHITE_LIST; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REMOVE_WHITE_LIST; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_REMOVE_WHITE_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_REMOVE_WHITE_LIST); + UINT16_TO_STREAM(pp, HCI_BLE_REMOVE_WHITE_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REMOVE_WHITE_LIST); - UINT8_TO_STREAM (pp, addr_type); - BDADDR_TO_STREAM (pp, bda); + UINT8_TO_STREAM(pp, addr_type); + BDADDR_TO_STREAM(pp, bda); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_upd_ll_conn_params (uint16_t handle, - uint16_t conn_int_min, uint16_t conn_int_max, - uint16_t conn_latency, uint16_t conn_timeout, - uint16_t min_ce_len, uint16_t max_ce_len) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_upd_ll_conn_params(uint16_t handle, uint16_t conn_int_min, + uint16_t conn_int_max, + uint16_t conn_latency, + uint16_t conn_timeout, + uint16_t min_ce_len, + uint16_t max_ce_len) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_UPD_LL_CONN_PARAMS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS); + UINT16_TO_STREAM(pp, HCI_BLE_UPD_LL_CONN_PARAMS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - UINT16_TO_STREAM (pp, conn_int_min); - UINT16_TO_STREAM (pp, conn_int_max); - UINT16_TO_STREAM (pp, conn_latency); - UINT16_TO_STREAM (pp, conn_timeout); - UINT16_TO_STREAM (pp, min_ce_len); - UINT16_TO_STREAM (pp, max_ce_len); + UINT16_TO_STREAM(pp, conn_int_min); + UINT16_TO_STREAM(pp, conn_int_max); + UINT16_TO_STREAM(pp, conn_latency); + UINT16_TO_STREAM(pp, conn_timeout); + UINT16_TO_STREAM(pp, min_ce_len); + UINT16_TO_STREAM(pp, max_ce_len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_host_chnl_class (uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_host_chnl_class( + uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_SET_HOST_CHNL_CLASS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS); + UINT16_TO_STREAM(pp, HCI_BLE_SET_HOST_CHNL_CLASS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS); - ARRAY_TO_STREAM (pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE); + ARRAY_TO_STREAM(pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_chnl_map (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_read_chnl_map(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_READ_CHNL_MAP); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CHNL_MAP); + UINT16_TO_STREAM(pp, HCI_BLE_READ_CHNL_MAP); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CHNL_MAP); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_remote_feat (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_read_remote_feat(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_READ_REMOTE_FEAT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT); + UINT16_TO_STREAM(pp, HCI_BLE_READ_REMOTE_FEAT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } /* security management commands */ -void btsnd_hcic_ble_encrypt (uint8_t *key, uint8_t key_len, - uint8_t *plain_text, uint8_t pt_len, - void *p_cmd_cplt_cback) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, void* p_cmd_cplt_cback) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT; - p->offset = sizeof(void *); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT; + p->offset = sizeof(void*); - *((void **)pp) = p_cmd_cplt_cback; /* Store command complete callback in buffer */ - pp += sizeof(void *); /* Skip over callback pointer */ + *((void**)pp) = + p_cmd_cplt_cback; /* Store command complete callback in buffer */ + pp += sizeof(void*); /* Skip over callback pointer */ + UINT16_TO_STREAM(pp, HCI_BLE_ENCRYPT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENCRYPT); - UINT16_TO_STREAM (pp, HCI_BLE_ENCRYPT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_ENCRYPT); + memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT); - memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT); + if (key_len > HCIC_BLE_ENCRYT_KEY_SIZE) key_len = HCIC_BLE_ENCRYT_KEY_SIZE; + if (pt_len > HCIC_BLE_ENCRYT_KEY_SIZE) pt_len = HCIC_BLE_ENCRYT_KEY_SIZE; - if (key_len > HCIC_BLE_ENCRYT_KEY_SIZE) key_len = HCIC_BLE_ENCRYT_KEY_SIZE; - if (pt_len > HCIC_BLE_ENCRYT_KEY_SIZE) pt_len = HCIC_BLE_ENCRYT_KEY_SIZE; + ARRAY_TO_STREAM(pp, key, key_len); + pp += (HCIC_BLE_ENCRYT_KEY_SIZE - key_len); + ARRAY_TO_STREAM(pp, plain_text, pt_len); - ARRAY_TO_STREAM (pp, key, key_len); - pp += (HCIC_BLE_ENCRYT_KEY_SIZE - key_len); - ARRAY_TO_STREAM (pp, plain_text, pt_len); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_rand (void *p_cmd_cplt_cback) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_rand(void* p_cmd_cplt_cback) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RAND; - p->offset = sizeof(void *); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RAND; + p->offset = sizeof(void*); - *((void **)pp) = p_cmd_cplt_cback; /* Store command complete callback in buffer */ - pp += sizeof(void *); /* Skip over callback pointer */ + *((void**)pp) = + p_cmd_cplt_cback; /* Store command complete callback in buffer */ + pp += sizeof(void*); /* Skip over callback pointer */ - UINT16_TO_STREAM (pp, HCI_BLE_RAND); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_RAND); + UINT16_TO_STREAM(pp, HCI_BLE_RAND); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RAND); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_start_enc (uint16_t handle, uint8_t rand[HCIC_BLE_RAND_DI_SIZE], - uint16_t ediv, uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_start_enc(uint16_t handle, + uint8_t rand[HCIC_BLE_RAND_DI_SIZE], + uint16_t ediv, + uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_START_ENC); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_START_ENC); + UINT16_TO_STREAM(pp, HCI_BLE_START_ENC); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_START_ENC); - UINT16_TO_STREAM (pp, handle); - ARRAY_TO_STREAM (pp, rand, HCIC_BLE_RAND_DI_SIZE); - UINT16_TO_STREAM (pp, ediv); - ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE); + UINT16_TO_STREAM(pp, handle); + ARRAY_TO_STREAM(pp, rand, HCIC_BLE_RAND_DI_SIZE); + UINT16_TO_STREAM(pp, ediv); + ARRAY_TO_STREAM(pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_ltk_req_reply (uint16_t handle, uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, + uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY); + UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY); - UINT16_TO_STREAM (pp, handle); - ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE); + UINT16_TO_STREAM(pp, handle); + ARRAY_TO_STREAM(pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_ltk_req_neg_reply (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_receiver_test(uint8_t rx_freq) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_receiver_test(uint8_t rx_freq) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_RECEIVER_TEST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_BLE_RECEIVER_TEST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, rx_freq); + UINT8_TO_STREAM(pp, rx_freq); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, uint8_t payload) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, + uint8_t payload) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_TRANSMITTER_TEST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM3); + UINT16_TO_STREAM(pp, HCI_BLE_TRANSMITTER_TEST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3); - UINT8_TO_STREAM (pp, tx_freq); - UINT8_TO_STREAM (pp, test_data_len); - UINT8_TO_STREAM (pp, payload); + UINT8_TO_STREAM(pp, tx_freq); + UINT8_TO_STREAM(pp, test_data_len); + UINT8_TO_STREAM(pp, payload); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_test_end(void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_test_end(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_TEST_END); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CMD); + UINT16_TO_STREAM(pp, HCI_BLE_TEST_END); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_host_supported (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_read_host_supported(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_LE_HOST_SUPPORT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CMD); + UINT16_TO_STREAM(pp, HCI_READ_LE_HOST_SUPPORT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #if (BLE_LLT_INCLUDED == TRUE) -void btsnd_hcic_ble_rc_param_req_reply( uint16_t handle, - uint16_t conn_int_min, uint16_t conn_int_max, - uint16_t conn_latency, uint16_t conn_timeout, - uint16_t min_ce_len, uint16_t max_ce_len ) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_rc_param_req_reply(uint16_t handle, uint16_t conn_int_min, + uint16_t conn_int_max, + uint16_t conn_latency, + uint16_t conn_timeout, + uint16_t min_ce_len, + uint16_t max_ce_len) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY); + UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, conn_int_min); - UINT16_TO_STREAM (pp, conn_int_max); - UINT16_TO_STREAM (pp, conn_latency); - UINT16_TO_STREAM (pp, conn_timeout); - UINT16_TO_STREAM (pp, min_ce_len); - UINT16_TO_STREAM (pp, max_ce_len); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, conn_int_min); + UINT16_TO_STREAM(pp, conn_int_max); + UINT16_TO_STREAM(pp, conn_latency); + UINT16_TO_STREAM(pp, conn_timeout); + UINT16_TO_STREAM(pp, min_ce_len); + UINT16_TO_STREAM(pp, max_ce_len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, reason); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, reason); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif -void btsnd_hcic_ble_add_device_resolving_list (uint8_t addr_type_peer, BD_ADDR bda_peer, - uint8_t irk_peer[HCIC_BLE_IRK_SIZE], - uint8_t irk_local[HCIC_BLE_IRK_SIZE]) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST; - p->offset = 0; +void btsnd_hcic_ble_add_device_resolving_list( + uint8_t addr_type_peer, BD_ADDR bda_peer, + uint8_t irk_peer[HCIC_BLE_IRK_SIZE], uint8_t irk_local[HCIC_BLE_IRK_SIZE]) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_BLE_ADD_DEV_RESOLVING_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST); - UINT8_TO_STREAM (pp, addr_type_peer); - BDADDR_TO_STREAM (pp, bda_peer); - ARRAY_TO_STREAM (pp, irk_peer, HCIC_BLE_ENCRYT_KEY_SIZE); - ARRAY_TO_STREAM (pp, irk_local, HCIC_BLE_ENCRYT_KEY_SIZE); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST; + p->offset = 0; - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_ADD_DEV_RESOLVING_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST); + UINT8_TO_STREAM(pp, addr_type_peer); + BDADDR_TO_STREAM(pp, bda_peer); + ARRAY_TO_STREAM(pp, irk_peer, HCIC_BLE_ENCRYT_KEY_SIZE); + ARRAY_TO_STREAM(pp, irk_local, HCIC_BLE_ENCRYT_KEY_SIZE); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_rm_device_resolving_list (uint8_t addr_type_peer, BD_ADDR bda_peer) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer, + BD_ADDR bda_peer) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_RM_DEV_RESOLVING_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST); - UINT8_TO_STREAM (pp, addr_type_peer); - BDADDR_TO_STREAM (pp, bda_peer); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_RM_DEV_RESOLVING_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST); + UINT8_TO_STREAM(pp, addr_type_peer); + BDADDR_TO_STREAM(pp, bda_peer); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_clear_resolving_list (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST; - p->offset = 0; +void btsnd_hcic_ble_clear_resolving_list(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_BLE_CLEAR_RESOLVING_LIST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST; + p->offset = 0; - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_RESOLVING_LIST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_resolvable_addr_peer (uint8_t addr_type_peer, BD_ADDR bda_peer) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, + BD_ADDR bda_peer) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER); - UINT8_TO_STREAM (pp, addr_type_peer); - BDADDR_TO_STREAM (pp, bda_peer); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER); + UINT8_TO_STREAM(pp, addr_type_peer); + BDADDR_TO_STREAM(pp, bda_peer); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_read_resolvable_addr_local (uint8_t addr_type_peer, BD_ADDR bda_peer) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL; - p->offset = 0; +void btsnd_hcic_ble_read_resolvable_addr_local(uint8_t addr_type_peer, + BD_ADDR bda_peer) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL); - UINT8_TO_STREAM (pp, addr_type_peer); - BDADDR_TO_STREAM (pp, bda_peer); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL; + p->offset = 0; - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL); + UINT8_TO_STREAM(pp, addr_type_peer); + BDADDR_TO_STREAM(pp, bda_peer); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_addr_resolution_enable (uint8_t addr_resolution_enable) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_addr_resolution_enable(uint8_t addr_resolution_enable) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_BLE_SET_ADDR_RESOLUTION_ENABLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE); - UINT8_TO_STREAM (pp, addr_resolution_enable); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_SET_ADDR_RESOLUTION_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE); + UINT8_TO_STREAM(pp, addr_resolution_enable); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_rand_priv_addr_timeout (uint16_t rpa_timout) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT; - p->offset = 0; +void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT); - UINT16_TO_STREAM (pp, rpa_timout); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT; + p->offset = 0; - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + UINT16_TO_STREAM(pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT); + UINT16_TO_STREAM(pp, rpa_timout); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, + uint16_t tx_time) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH; + p->offset = 0; - UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH); - UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH); + UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH); - UINT16_TO_STREAM(pp, conn_handle); - UINT16_TO_STREAM(pp, tx_octets); - UINT16_TO_STREAM(pp, tx_time); + UINT16_TO_STREAM(pp, conn_handle); + UINT16_TO_STREAM(pp, tx_octets); + UINT16_TO_STREAM(pp, tx_time); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } diff --git a/stack/hcic/hcicmds.cc b/stack/hcic/hcicmds.cc index 752011ac7..e46c33e5b 100644 --- a/stack/hcic/hcicmds.cc +++ b/stack/hcic/hcicmds.cc @@ -23,995 +23,929 @@ * ******************************************************************************/ -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" +#include "btu.h" #include "hcidefs.h" #include "hcimsgs.h" -#include "hcidefs.h" -#include "btu.h" #include #include -#include "btm_int.h" /* Included for UIPC_* macro definitions */ +#include "btm_int.h" /* Included for UIPC_* macro definitions */ -void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration, uint8_t response_cnt) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration, + uint8_t response_cnt) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQUIRY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQUIRY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_INQUIRY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_INQUIRY); + UINT16_TO_STREAM(pp, HCI_INQUIRY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_INQUIRY); - LAP_TO_STREAM (pp, inq_lap); - UINT8_TO_STREAM (pp, duration); - UINT8_TO_STREAM (pp, response_cnt); + LAP_TO_STREAM(pp, inq_lap); + UINT8_TO_STREAM(pp, duration); + UINT8_TO_STREAM(pp, response_cnt); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_inq_cancel(void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_inq_cancel(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQ_CANCEL; - p->offset = 0; - UINT16_TO_STREAM (pp, HCI_INQUIRY_CANCEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_INQ_CANCEL); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQ_CANCEL; + p->offset = 0; + UINT16_TO_STREAM(pp, HCI_INQUIRY_CANCEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_INQ_CANCEL); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_per_inq_mode (uint16_t max_period, uint16_t min_period, - const LAP inq_lap, uint8_t duration, uint8_t response_cnt) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_per_inq_mode(uint16_t max_period, uint16_t min_period, + const LAP inq_lap, uint8_t duration, + uint8_t response_cnt) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PER_INQ_MODE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PER_INQ_MODE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_PERIODIC_INQUIRY_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_PER_INQ_MODE); + UINT16_TO_STREAM(pp, HCI_PERIODIC_INQUIRY_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PER_INQ_MODE); - UINT16_TO_STREAM (pp, max_period); - UINT16_TO_STREAM (pp, min_period); - LAP_TO_STREAM (pp, inq_lap); - UINT8_TO_STREAM (pp, duration); - UINT8_TO_STREAM (pp, response_cnt); + UINT16_TO_STREAM(pp, max_period); + UINT16_TO_STREAM(pp, min_period); + LAP_TO_STREAM(pp, inq_lap); + UINT8_TO_STREAM(pp, duration); + UINT8_TO_STREAM(pp, response_cnt); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_exit_per_inq (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_exit_per_inq(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXIT_PER_INQ; - p->offset = 0; - UINT16_TO_STREAM (pp, HCI_EXIT_PERIODIC_INQUIRY_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_EXIT_PER_INQ); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXIT_PER_INQ; + p->offset = 0; + UINT16_TO_STREAM(pp, HCI_EXIT_PERIODIC_INQUIRY_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXIT_PER_INQ); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } - void btsnd_hcic_create_conn(BD_ADDR dest, uint16_t packet_types, - uint8_t page_scan_rep_mode, uint8_t page_scan_mode, - uint16_t clock_offset, uint8_t allow_switch) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); + uint8_t page_scan_rep_mode, uint8_t page_scan_mode, + uint16_t clock_offset, uint8_t allow_switch) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); #ifndef BT_10A - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN; #else - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN - 1; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN - 1; #endif - p->offset = 0; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_CREATE_CONNECTION); + UINT16_TO_STREAM(pp, HCI_CREATE_CONNECTION); #ifndef BT_10A - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CREATE_CONN); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CREATE_CONN); #else - UINT8_TO_STREAM (pp, (HCIC_PARAM_SIZE_CREATE_CONN - 1)); + UINT8_TO_STREAM(pp, (HCIC_PARAM_SIZE_CREATE_CONN - 1)); #endif - BDADDR_TO_STREAM (pp, dest); - UINT16_TO_STREAM (pp, packet_types); - UINT8_TO_STREAM (pp, page_scan_rep_mode); - UINT8_TO_STREAM (pp, page_scan_mode); - UINT16_TO_STREAM (pp, clock_offset); -#if !defined (BT_10A) - UINT8_TO_STREAM (pp, allow_switch); + BDADDR_TO_STREAM(pp, dest); + UINT16_TO_STREAM(pp, packet_types); + UINT8_TO_STREAM(pp, page_scan_rep_mode); + UINT8_TO_STREAM(pp, page_scan_mode); + UINT16_TO_STREAM(pp, clock_offset); +#if !defined(BT_10A) + UINT8_TO_STREAM(pp, allow_switch); #endif - btm_acl_paging (p, dest); + btm_acl_paging(p, dest); } -void btsnd_hcic_disconnect (uint16_t handle, uint8_t reason) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DISCONNECT; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DISCONNECT; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_DISCONNECT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_DISCONNECT); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, reason); + UINT16_TO_STREAM(pp, HCI_DISCONNECT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_DISCONNECT); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, reason); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #if (BTM_SCO_INCLUDED == TRUE) -void btsnd_hcic_add_SCO_conn (uint16_t handle, uint16_t packet_types) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_add_SCO_conn(uint16_t handle, uint16_t packet_types) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_SCO_CONN; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_SCO_CONN; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_ADD_SCO_CONNECTION); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_ADD_SCO_CONN); + UINT16_TO_STREAM(pp, HCI_ADD_SCO_CONNECTION); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_SCO_CONN); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, packet_types); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, packet_types); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif /* BTM_SCO_INCLUDED */ -void btsnd_hcic_create_conn_cancel(BD_ADDR dest) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_create_conn_cancel(BD_ADDR dest) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN_CANCEL; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN_CANCEL; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_CREATE_CONNECTION_CANCEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CREATE_CONN_CANCEL); + UINT16_TO_STREAM(pp, HCI_CREATE_CONNECTION_CANCEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CREATE_CONN_CANCEL); - BDADDR_TO_STREAM (pp, dest); + BDADDR_TO_STREAM(pp, dest); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_accept_conn (BD_ADDR dest, uint8_t role) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_accept_conn(BD_ADDR dest, uint8_t role) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_CONN; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_CONN; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_ACCEPT_CONNECTION_REQUEST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_ACCEPT_CONN); - BDADDR_TO_STREAM (pp, dest); - UINT8_TO_STREAM (pp, role); + UINT16_TO_STREAM(pp, HCI_ACCEPT_CONNECTION_REQUEST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ACCEPT_CONN); + BDADDR_TO_STREAM(pp, dest); + UINT8_TO_STREAM(pp, role); - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_reject_conn (BD_ADDR dest, uint8_t reason) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_CONN; - p->offset = 0; +void btsnd_hcic_reject_conn(BD_ADDR dest, uint8_t reason) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_REJECT_CONNECTION_REQUEST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_REJECT_CONN); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_CONN; + p->offset = 0; - BDADDR_TO_STREAM (pp, dest); - UINT8_TO_STREAM (pp, reason); + UINT16_TO_STREAM(pp, HCI_REJECT_CONNECTION_REQUEST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REJECT_CONN); + BDADDR_TO_STREAM(pp, dest); + UINT8_TO_STREAM(pp, reason); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_link_key_req_reply (BD_ADDR bd_addr, LINK_KEY link_key) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_link_key_req_reply(BD_ADDR bd_addr, LINK_KEY link_key) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_LINK_KEY_REQUEST_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY); + UINT16_TO_STREAM(pp, HCI_LINK_KEY_REQUEST_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); - ARRAY16_TO_STREAM (pp, link_key); + BDADDR_TO_STREAM(pp, bd_addr); + ARRAY16_TO_STREAM(pp, link_key); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_link_key_neg_reply (BD_ADDR bd_addr) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_link_key_neg_reply(BD_ADDR bd_addr) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_LINK_KEY_REQUEST_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_LINK_KEY_REQUEST_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_pin_code_req_reply (BD_ADDR bd_addr, uint8_t pin_code_len, - PIN_CODE pin_code) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - int i; +void btsnd_hcic_pin_code_req_reply(BD_ADDR bd_addr, uint8_t pin_code_len, + PIN_CODE pin_code) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); + int i; - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_PIN_CODE_REQUEST_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY); + UINT16_TO_STREAM(pp, HCI_PIN_CODE_REQUEST_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, pin_code_len); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, pin_code_len); - for (i = 0; i < pin_code_len; i++) - *pp++ = *pin_code++; + for (i = 0; i < pin_code_len; i++) *pp++ = *pin_code++; - for (; i < PIN_CODE_LEN; i++) - *pp++ = 0; + for (; i < PIN_CODE_LEN; i++) *pp++ = 0; - - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_pin_code_neg_reply (BD_ADDR bd_addr) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_pin_code_neg_reply(BD_ADDR bd_addr) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_PIN_CODE_REQUEST_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_PIN_CODE_REQUEST_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_change_conn_type (uint16_t handle, uint16_t packet_types) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_change_conn_type(uint16_t handle, uint16_t packet_types) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_CONN_TYPE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_CONN_TYPE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_CHANGE_CONN_PACKET_TYPE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CHANGE_CONN_TYPE); + UINT16_TO_STREAM(pp, HCI_CHANGE_CONN_PACKET_TYPE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CHANGE_CONN_TYPE); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, packet_types); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, packet_types); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_auth_request (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_auth_request(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_AUTHENTICATION_REQUESTED); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_AUTHENTICATION_REQUESTED); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_set_conn_encrypt (uint16_t handle, bool enable) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_set_conn_encrypt(uint16_t handle, bool enable) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_CONN_ENCRYPT; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_CONN_ENCRYPT; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SET_CONN_ENCRYPTION); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SET_CONN_ENCRYPT); + UINT16_TO_STREAM(pp, HCI_SET_CONN_ENCRYPTION); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_CONN_ENCRYPT); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, enable); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, enable); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rmt_name_req (BD_ADDR bd_addr, uint8_t page_scan_rep_mode, - uint8_t page_scan_mode, uint16_t clock_offset) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rmt_name_req(BD_ADDR bd_addr, uint8_t page_scan_rep_mode, + uint8_t page_scan_mode, uint16_t clock_offset) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_RMT_NAME_REQUEST); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_RMT_NAME_REQ); + UINT16_TO_STREAM(pp, HCI_RMT_NAME_REQUEST); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_NAME_REQ); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, page_scan_rep_mode); - UINT8_TO_STREAM (pp, page_scan_mode); - UINT16_TO_STREAM (pp, clock_offset); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, page_scan_rep_mode); + UINT8_TO_STREAM(pp, page_scan_mode); + UINT16_TO_STREAM(pp, clock_offset); - btm_acl_paging (p, bd_addr); + btm_acl_paging(p, bd_addr); } -void btsnd_hcic_rmt_name_req_cancel (BD_ADDR bd_addr) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rmt_name_req_cancel(BD_ADDR bd_addr) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_RMT_NAME_REQUEST_CANCEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL); + UINT16_TO_STREAM(pp, HCI_RMT_NAME_REQUEST_CANCEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rmt_features_req (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rmt_features_req(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_RMT_FEATURES); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_READ_RMT_FEATURES); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rmt_ext_features (uint16_t handle, uint8_t page_num) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rmt_ext_features(uint16_t handle, uint8_t page_num) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_EXT_FEATURES; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_EXT_FEATURES; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_RMT_EXT_FEATURES); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_RMT_EXT_FEATURES); + UINT16_TO_STREAM(pp, HCI_READ_RMT_EXT_FEATURES); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_EXT_FEATURES); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, page_num); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, page_num); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rmt_ver_req (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rmt_ver_req(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_RMT_VERSION_INFO); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_READ_RMT_VERSION_INFO); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_rmt_clk_offset (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_rmt_clk_offset(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_RMT_CLOCK_OFFSET); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_READ_RMT_CLOCK_OFFSET); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_lmp_handle (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_lmp_handle(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_LMP_HANDLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_READ_LMP_HANDLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_setup_esco_conn (uint16_t handle, uint32_t tx_bw, - uint32_t rx_bw, uint16_t max_latency, uint16_t voice, - uint8_t retrans_effort, uint16_t packet_types) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_setup_esco_conn(uint16_t handle, uint32_t tx_bw, uint32_t rx_bw, + uint16_t max_latency, uint16_t voice, + uint8_t retrans_effort, uint16_t packet_types) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SETUP_ESCO; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SETUP_ESCO; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SETUP_ESCO_CONNECTION); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SETUP_ESCO); + UINT16_TO_STREAM(pp, HCI_SETUP_ESCO_CONNECTION); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SETUP_ESCO); - UINT16_TO_STREAM (pp, handle); - UINT32_TO_STREAM (pp, tx_bw); - UINT32_TO_STREAM (pp, rx_bw); - UINT16_TO_STREAM (pp, max_latency); - UINT16_TO_STREAM (pp, voice); - UINT8_TO_STREAM (pp, retrans_effort); - UINT16_TO_STREAM (pp, packet_types); + UINT16_TO_STREAM(pp, handle); + UINT32_TO_STREAM(pp, tx_bw); + UINT32_TO_STREAM(pp, rx_bw); + UINT16_TO_STREAM(pp, max_latency); + UINT16_TO_STREAM(pp, voice); + UINT8_TO_STREAM(pp, retrans_effort); + UINT16_TO_STREAM(pp, packet_types); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_accept_esco_conn (BD_ADDR bd_addr, uint32_t tx_bw, - uint32_t rx_bw, uint16_t max_latency, - uint16_t content_fmt, uint8_t retrans_effort, - uint16_t packet_types) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_accept_esco_conn(BD_ADDR bd_addr, uint32_t tx_bw, + uint32_t rx_bw, uint16_t max_latency, + uint16_t content_fmt, uint8_t retrans_effort, + uint16_t packet_types) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_ESCO; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_ESCO; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_ACCEPT_ESCO_CONNECTION); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_ACCEPT_ESCO); + UINT16_TO_STREAM(pp, HCI_ACCEPT_ESCO_CONNECTION); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ACCEPT_ESCO); - BDADDR_TO_STREAM (pp, bd_addr); - UINT32_TO_STREAM (pp, tx_bw); - UINT32_TO_STREAM (pp, rx_bw); - UINT16_TO_STREAM (pp, max_latency); - UINT16_TO_STREAM (pp, content_fmt); - UINT8_TO_STREAM (pp, retrans_effort); - UINT16_TO_STREAM (pp, packet_types); + BDADDR_TO_STREAM(pp, bd_addr); + UINT32_TO_STREAM(pp, tx_bw); + UINT32_TO_STREAM(pp, rx_bw); + UINT16_TO_STREAM(pp, max_latency); + UINT16_TO_STREAM(pp, content_fmt); + UINT8_TO_STREAM(pp, retrans_effort); + UINT16_TO_STREAM(pp, packet_types); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_reject_esco_conn (BD_ADDR bd_addr, uint8_t reason) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_reject_esco_conn(BD_ADDR bd_addr, uint8_t reason) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_ESCO; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_ESCO; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_REJECT_ESCO_CONNECTION); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_REJECT_ESCO); + UINT16_TO_STREAM(pp, HCI_REJECT_ESCO_CONNECTION); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REJECT_ESCO); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, reason); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, reason); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_hold_mode (uint16_t handle, uint16_t max_hold_period, - uint16_t min_hold_period) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_hold_mode(uint16_t handle, uint16_t max_hold_period, + uint16_t min_hold_period) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_HOLD_MODE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_HOLD_MODE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_HOLD_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_HOLD_MODE); + UINT16_TO_STREAM(pp, HCI_HOLD_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_HOLD_MODE); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, max_hold_period); - UINT16_TO_STREAM (pp, min_hold_period); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, max_hold_period); + UINT16_TO_STREAM(pp, min_hold_period); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_sniff_mode (uint16_t handle, uint16_t max_sniff_period, - uint16_t min_sniff_period, uint16_t sniff_attempt, - uint16_t sniff_timeout) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_sniff_mode(uint16_t handle, uint16_t max_sniff_period, + uint16_t min_sniff_period, uint16_t sniff_attempt, + uint16_t sniff_timeout) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_MODE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_MODE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SNIFF_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SNIFF_MODE); + UINT16_TO_STREAM(pp, HCI_SNIFF_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SNIFF_MODE); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, max_sniff_period); - UINT16_TO_STREAM (pp, min_sniff_period); - UINT16_TO_STREAM (pp, sniff_attempt); - UINT16_TO_STREAM (pp, sniff_timeout); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, max_sniff_period); + UINT16_TO_STREAM(pp, min_sniff_period); + UINT16_TO_STREAM(pp, sniff_attempt); + UINT16_TO_STREAM(pp, sniff_timeout); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_exit_sniff_mode (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_exit_sniff_mode(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_EXIT_SNIFF_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_EXIT_SNIFF_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_park_mode (uint16_t handle, uint16_t beacon_max_interval, - uint16_t beacon_min_interval) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_park_mode(uint16_t handle, uint16_t beacon_max_interval, + uint16_t beacon_min_interval) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PARK_MODE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PARK_MODE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_PARK_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_PARK_MODE); + UINT16_TO_STREAM(pp, HCI_PARK_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PARK_MODE); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, beacon_max_interval); - UINT16_TO_STREAM (pp, beacon_min_interval); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, beacon_max_interval); + UINT16_TO_STREAM(pp, beacon_min_interval); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_exit_park_mode (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_exit_park_mode(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_EXIT_PARK_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_EXIT_PARK_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_qos_setup (uint16_t handle, uint8_t flags, uint8_t service_type, - uint32_t token_rate, uint32_t peak, uint32_t latency, - uint32_t delay_var) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags, uint8_t service_type, + uint32_t token_rate, uint32_t peak, uint32_t latency, + uint32_t delay_var) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_QOS_SETUP; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_QOS_SETUP; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_QOS_SETUP); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_QOS_SETUP); + UINT16_TO_STREAM(pp, HCI_QOS_SETUP); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_QOS_SETUP); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, flags); - UINT8_TO_STREAM (pp, service_type); - UINT32_TO_STREAM (pp, token_rate); - UINT32_TO_STREAM (pp, peak); - UINT32_TO_STREAM (pp, latency); - UINT32_TO_STREAM (pp, delay_var); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, flags); + UINT8_TO_STREAM(pp, service_type); + UINT32_TO_STREAM(pp, token_rate); + UINT32_TO_STREAM(pp, peak); + UINT32_TO_STREAM(pp, latency); + UINT32_TO_STREAM(pp, delay_var); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_switch_role (BD_ADDR bd_addr, uint8_t role) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_switch_role(BD_ADDR bd_addr, uint8_t role) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SWITCH_ROLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SWITCH_ROLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SWITCH_ROLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SWITCH_ROLE); + UINT16_TO_STREAM(pp, HCI_SWITCH_ROLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SWITCH_ROLE); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, role); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, role); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_policy_set (uint16_t handle, uint16_t settings) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_policy_set(uint16_t handle, uint16_t settings) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_POLICY_SET; - p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_POLICY_SETTINGS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_POLICY_SET); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_POLICY_SET; + p->offset = 0; + UINT16_TO_STREAM(pp, HCI_WRITE_POLICY_SETTINGS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_POLICY_SET); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, settings); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, settings); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_def_policy_set (uint16_t settings) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_def_policy_set(uint16_t settings) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET; - p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_DEF_POLICY_SETTINGS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET; + p->offset = 0; + UINT16_TO_STREAM(pp, HCI_WRITE_DEF_POLICY_SETTINGS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET); - UINT16_TO_STREAM (pp, settings); + UINT16_TO_STREAM(pp, settings); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_set_event_filter (uint8_t filt_type, uint8_t filt_cond_type, - uint8_t *filt_cond, uint8_t filt_cond_len) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->offset = 0; +void btsnd_hcic_set_event_filter(uint8_t filt_type, uint8_t filt_cond_type, + uint8_t* filt_cond, uint8_t filt_cond_len) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - UINT16_TO_STREAM (pp, HCI_SET_EVENT_FILTER); + p->offset = 0; - if (filt_type) - { - p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 2 + filt_cond_len); - UINT8_TO_STREAM (pp, (uint8_t)(2 + filt_cond_len)); + UINT16_TO_STREAM(pp, HCI_SET_EVENT_FILTER); - UINT8_TO_STREAM (pp, filt_type); - UINT8_TO_STREAM (pp, filt_cond_type); + if (filt_type) { + p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 2 + filt_cond_len); + UINT8_TO_STREAM(pp, (uint8_t)(2 + filt_cond_len)); - if (filt_cond_type == HCI_FILTER_COND_DEVICE_CLASS) - { - DEVCLASS_TO_STREAM (pp, filt_cond); - filt_cond += DEV_CLASS_LEN; - DEVCLASS_TO_STREAM (pp, filt_cond); - filt_cond += DEV_CLASS_LEN; + UINT8_TO_STREAM(pp, filt_type); + UINT8_TO_STREAM(pp, filt_cond_type); - filt_cond_len -= (2 * DEV_CLASS_LEN); - } - else if (filt_cond_type == HCI_FILTER_COND_BD_ADDR) - { - BDADDR_TO_STREAM (pp, filt_cond); - filt_cond += BD_ADDR_LEN; + if (filt_cond_type == HCI_FILTER_COND_DEVICE_CLASS) { + DEVCLASS_TO_STREAM(pp, filt_cond); + filt_cond += DEV_CLASS_LEN; + DEVCLASS_TO_STREAM(pp, filt_cond); + filt_cond += DEV_CLASS_LEN; - filt_cond_len -= BD_ADDR_LEN; - } + filt_cond_len -= (2 * DEV_CLASS_LEN); + } else if (filt_cond_type == HCI_FILTER_COND_BD_ADDR) { + BDADDR_TO_STREAM(pp, filt_cond); + filt_cond += BD_ADDR_LEN; - if (filt_cond_len) - ARRAY_TO_STREAM (pp, filt_cond, filt_cond_len); + filt_cond_len -= BD_ADDR_LEN; } - else - { - p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 1); - UINT8_TO_STREAM (pp, 1); - UINT8_TO_STREAM (pp, filt_type); - } + if (filt_cond_len) ARRAY_TO_STREAM(pp, filt_cond, filt_cond_len); + } else { + p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 1); + UINT8_TO_STREAM(pp, 1); + + UINT8_TO_STREAM(pp, filt_type); + } - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_pin_type (uint8_t type) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_pin_type(uint8_t type) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_PIN_TYPE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_PIN_TYPE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, type); + UINT8_TO_STREAM(pp, type); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_delete_stored_key (BD_ADDR bd_addr, bool delete_all_flag) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_delete_stored_key(BD_ADDR bd_addr, bool delete_all_flag) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DELETE_STORED_KEY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DELETE_STORED_KEY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_DELETE_STORED_LINK_KEY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_DELETE_STORED_KEY); + UINT16_TO_STREAM(pp, HCI_DELETE_STORED_LINK_KEY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_DELETE_STORED_KEY); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, delete_all_flag); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, delete_all_flag); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_change_name (BD_NAME name) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - uint16_t len = strlen((char *)name) + 1; +void btsnd_hcic_change_name(BD_NAME name) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); + uint16_t len = strlen((char*)name) + 1; - memset(pp, 0, HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME); + memset(pp, 0, HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_CHANGE_LOCAL_NAME); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CHANGE_NAME); + UINT16_TO_STREAM(pp, HCI_CHANGE_LOCAL_NAME); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CHANGE_NAME); - if (len > HCIC_PARAM_SIZE_CHANGE_NAME) - len = HCIC_PARAM_SIZE_CHANGE_NAME; + if (len > HCIC_PARAM_SIZE_CHANGE_NAME) len = HCIC_PARAM_SIZE_CHANGE_NAME; - ARRAY_TO_STREAM (pp, name, len); + ARRAY_TO_STREAM(pp, name, len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_name (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_name(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_LOCAL_NAME); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CMD); + UINT16_TO_STREAM(pp, HCI_READ_LOCAL_NAME); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_page_tout (uint16_t timeout) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_page_tout(uint16_t timeout) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_PAGE_TOUT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM2); + UINT16_TO_STREAM(pp, HCI_WRITE_PAGE_TOUT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM2); - UINT16_TO_STREAM (pp, timeout); + UINT16_TO_STREAM(pp, timeout); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_scan_enable (uint8_t flag) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_scan_enable(uint8_t flag) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_SCAN_ENABLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_SCAN_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, flag); + UINT8_TO_STREAM(pp, flag); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_pagescan_cfg(uint16_t interval, uint16_t window) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_pagescan_cfg(uint16_t interval, uint16_t window) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_PAGESCAN_CFG); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG); + UINT16_TO_STREAM(pp, HCI_WRITE_PAGESCAN_CFG); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG); - UINT16_TO_STREAM (pp, interval); - UINT16_TO_STREAM (pp, window); + UINT16_TO_STREAM(pp, interval); + UINT16_TO_STREAM(pp, window); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_INQUIRYSCAN_CFG); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG); + UINT16_TO_STREAM(pp, HCI_WRITE_INQUIRYSCAN_CFG); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG); - UINT16_TO_STREAM (pp, interval); - UINT16_TO_STREAM (pp, window); + UINT16_TO_STREAM(pp, interval); + UINT16_TO_STREAM(pp, window); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_auth_enable (uint8_t flag) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_auth_enable(uint8_t flag) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_AUTHENTICATION_ENABLE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_AUTHENTICATION_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, flag); + UINT8_TO_STREAM(pp, flag); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_dev_class(DEV_CLASS dev_class) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_dev_class(DEV_CLASS dev_class) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_CLASS_OF_DEVICE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM3); + UINT16_TO_STREAM(pp, HCI_WRITE_CLASS_OF_DEVICE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3); - DEVCLASS_TO_STREAM (pp, dev_class); + DEVCLASS_TO_STREAM(pp, dev_class); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_voice_settings(uint16_t flags) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_voice_settings(uint16_t flags) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_VOICE_SETTINGS); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM2); + UINT16_TO_STREAM(pp, HCI_WRITE_VOICE_SETTINGS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM2); - UINT16_TO_STREAM (pp, flags); + UINT16_TO_STREAM(pp, flags); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_auto_flush_tout (uint16_t handle, uint16_t tout) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_auto_flush_tout(uint16_t handle, uint16_t tout) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_AUTO_FLUSH_TOUT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT); + UINT16_TO_STREAM(pp, HCI_WRITE_AUTO_FLUSH_TOUT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, tout); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, tout); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_tx_power (uint16_t handle, uint8_t type) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_tx_power(uint16_t handle, uint8_t type) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_TX_POWER; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_TX_POWER; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_TRANSMIT_POWER_LEVEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_TX_POWER); + UINT16_TO_STREAM(pp, HCI_READ_TRANSMIT_POWER_LEVEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_TX_POWER); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, type); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, type); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_host_num_xmitted_pkts (uint8_t num_handles, uint16_t *handle, - uint16_t *num_pkts) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_host_num_xmitted_pkts(uint8_t num_handles, uint16_t* handle, + uint16_t* num_pkts) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + 1 + (num_handles * 4); - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + 1 + (num_handles * 4); + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_HOST_NUM_PACKETS_DONE); - UINT8_TO_STREAM (pp, p->len - HCIC_PREAMBLE_SIZE); + UINT16_TO_STREAM(pp, HCI_HOST_NUM_PACKETS_DONE); + UINT8_TO_STREAM(pp, p->len - HCIC_PREAMBLE_SIZE); - UINT8_TO_STREAM (pp, num_handles); + UINT8_TO_STREAM(pp, num_handles); - for (int i = 0; i < num_handles; i++) { - UINT16_TO_STREAM(pp, handle[i]); - UINT16_TO_STREAM(pp, num_pkts[i]); - } + for (int i = 0; i < num_handles; i++) { + UINT16_TO_STREAM(pp, handle[i]); + UINT16_TO_STREAM(pp, num_pkts[i]); + } - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_link_super_tout (uint8_t local_controller_id, uint16_t handle, uint16_t timeout) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_link_super_tout(uint8_t local_controller_id, + uint16_t handle, uint16_t timeout) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_LINK_SUPER_TOUT); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT); + UINT16_TO_STREAM(pp, HCI_WRITE_LINK_SUPER_TOUT); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, timeout); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, timeout); - btu_hcif_send_cmd (local_controller_id, p); + btu_hcif_send_cmd(local_controller_id, p); } -void btsnd_hcic_write_cur_iac_lap (uint8_t num_cur_iac, LAP * const iac_lap) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_cur_iac_lap(uint8_t num_cur_iac, LAP* const iac_lap) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + 1 + (LAP_LEN * num_cur_iac); - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + 1 + (LAP_LEN * num_cur_iac); + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_CURRENT_IAC_LAP); - UINT8_TO_STREAM (pp, p->len - HCIC_PREAMBLE_SIZE); + UINT16_TO_STREAM(pp, HCI_WRITE_CURRENT_IAC_LAP); + UINT8_TO_STREAM(pp, p->len - HCIC_PREAMBLE_SIZE); - UINT8_TO_STREAM (pp, num_cur_iac); + UINT8_TO_STREAM(pp, num_cur_iac); - for (int i = 0; i < num_cur_iac; i++) - LAP_TO_STREAM (pp, iac_lap[i]); + for (int i = 0; i < num_cur_iac; i++) LAP_TO_STREAM(pp, iac_lap[i]); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } /****************************************** @@ -1020,236 +954,220 @@ void btsnd_hcic_write_cur_iac_lap (uint8_t num_cur_iac, LAP * const iac_lap) #if (BTM_SSR_INCLUDED == TRUE) void btsnd_hcic_sniff_sub_rate(uint16_t handle, uint16_t max_lat, - uint16_t min_remote_lat, uint16_t min_local_lat) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); + uint16_t min_remote_lat, + uint16_t min_local_lat) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_SUB_RATE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_SUB_RATE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SNIFF_SUB_RATE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SNIFF_SUB_RATE); + UINT16_TO_STREAM(pp, HCI_SNIFF_SUB_RATE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SNIFF_SUB_RATE); - UINT16_TO_STREAM (pp, handle); - UINT16_TO_STREAM (pp, max_lat); - UINT16_TO_STREAM (pp, min_remote_lat); - UINT16_TO_STREAM (pp, min_local_lat); + UINT16_TO_STREAM(pp, handle); + UINT16_TO_STREAM(pp, max_lat); + UINT16_TO_STREAM(pp, min_remote_lat); + UINT16_TO_STREAM(pp, min_local_lat); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif /* BTM_SSR_INCLUDED */ /**** Extended Inquiry Response Commands ****/ -void btsnd_hcic_write_ext_inquiry_response (void *buffer, uint8_t fec_req) -{ - BT_HDR *p = (BT_HDR *)buffer; - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_ext_inquiry_response(void* buffer, uint8_t fec_req) { + BT_HDR* p = (BT_HDR*)buffer; + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXT_INQ_RESP; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXT_INQ_RESP; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_EXT_INQ_RESPONSE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_EXT_INQ_RESP); + UINT16_TO_STREAM(pp, HCI_WRITE_EXT_INQ_RESPONSE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_INQ_RESP); - UINT8_TO_STREAM (pp, fec_req); + UINT8_TO_STREAM(pp, fec_req); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_io_cap_req_reply (BD_ADDR bd_addr, uint8_t capability, - uint8_t oob_present, uint8_t auth_req) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_io_cap_req_reply(BD_ADDR bd_addr, uint8_t capability, + uint8_t oob_present, uint8_t auth_req) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_RESP; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_RESP; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_IO_CAPABILITY_REQUEST_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_IO_CAP_RESP); + UINT16_TO_STREAM(pp, HCI_IO_CAPABILITY_REQUEST_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_IO_CAP_RESP); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, capability); - UINT8_TO_STREAM (pp, oob_present); - UINT8_TO_STREAM (pp, auth_req); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, capability); + UINT8_TO_STREAM(pp, oob_present); + UINT8_TO_STREAM(pp, auth_req); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_io_cap_req_neg_reply (BD_ADDR bd_addr, uint8_t err_code) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_io_cap_req_neg_reply(BD_ADDR bd_addr, uint8_t err_code) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_IO_CAP_REQ_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_IO_CAP_REQ_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, err_code); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, err_code); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_local_oob_data (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_local_oob_data(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_LOCAL_OOB; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_LOCAL_OOB; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_LOCAL_OOB_DATA); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_R_LOCAL_OOB); + UINT16_TO_STREAM(pp, HCI_READ_LOCAL_OOB_DATA); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_R_LOCAL_OOB); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_user_conf_reply (BD_ADDR bd_addr, bool is_yes) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_user_conf_reply(BD_ADDR bd_addr, bool is_yes) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_UCONF_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_UCONF_REPLY; + p->offset = 0; - if (!is_yes) - { - /* Negative reply */ - UINT16_TO_STREAM (pp, HCI_USER_CONF_VALUE_NEG_REPLY); - } - else - { - /* Confirmation */ - UINT16_TO_STREAM (pp, HCI_USER_CONF_REQUEST_REPLY); - } + if (!is_yes) { + /* Negative reply */ + UINT16_TO_STREAM(pp, HCI_USER_CONF_VALUE_NEG_REPLY); + } else { + /* Confirmation */ + UINT16_TO_STREAM(pp, HCI_USER_CONF_REQUEST_REPLY); + } - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_UCONF_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_UCONF_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_user_passkey_reply (BD_ADDR bd_addr, uint32_t value) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_user_passkey_reply(BD_ADDR bd_addr, uint32_t value) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_USER_PASSKEY_REQ_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_U_PKEY_REPLY); + UINT16_TO_STREAM(pp, HCI_USER_PASSKEY_REQ_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_U_PKEY_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); - UINT32_TO_STREAM (pp, value); + BDADDR_TO_STREAM(pp, bd_addr); + UINT32_TO_STREAM(pp, value); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_user_passkey_neg_reply (BD_ADDR bd_addr) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_user_passkey_neg_reply(BD_ADDR bd_addr) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_USER_PASSKEY_REQ_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_USER_PASSKEY_REQ_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rem_oob_reply (BD_ADDR bd_addr, uint8_t *p_c, uint8_t *p_r) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rem_oob_reply(BD_ADDR bd_addr, uint8_t* p_c, uint8_t* p_r) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_REM_OOB_DATA_REQ_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_REM_OOB_REPLY); + UINT16_TO_STREAM(pp, HCI_REM_OOB_DATA_REQ_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REM_OOB_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); - ARRAY16_TO_STREAM (pp, p_c); - ARRAY16_TO_STREAM (pp, p_r); + BDADDR_TO_STREAM(pp, bd_addr); + ARRAY16_TO_STREAM(pp, p_c); + ARRAY16_TO_STREAM(pp, p_r); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_rem_oob_neg_reply (BD_ADDR bd_addr) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_rem_oob_neg_reply(BD_ADDR bd_addr) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_REM_OOB_DATA_REQ_NEG_REPLY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY); + UINT16_TO_STREAM(pp, HCI_REM_OOB_DATA_REQ_NEG_REPLY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY); - BDADDR_TO_STREAM (pp, bd_addr); + BDADDR_TO_STREAM(pp, bd_addr); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } +void btsnd_hcic_read_inq_tx_power(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); -void btsnd_hcic_read_inq_tx_power (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_TX_POWER; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_TX_POWER; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_INQ_TX_POWER_LEVEL); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_R_TX_POWER); + UINT16_TO_STREAM(pp, HCI_READ_INQ_TX_POWER_LEVEL); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_R_TX_POWER); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_send_keypress_notif (BD_ADDR bd_addr, uint8_t notif) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_send_keypress_notif(BD_ADDR bd_addr, uint8_t notif) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_SEND_KEYPRESS_NOTIF); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF); + UINT16_TO_STREAM(pp, HCI_SEND_KEYPRESS_NOTIF); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF); - BDADDR_TO_STREAM (pp, bd_addr); - UINT8_TO_STREAM (pp, notif); + BDADDR_TO_STREAM(pp, bd_addr); + UINT8_TO_STREAM(pp, notif); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } /**** end of Simple Pairing Commands ****/ #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) -void btsnd_hcic_enhanced_flush (uint16_t handle, uint8_t packet_type) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_enhanced_flush(uint16_t handle, uint8_t packet_type) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENHANCED_FLUSH; - p->offset = 0; - UINT16_TO_STREAM (pp, HCI_ENHANCED_FLUSH); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_ENHANCED_FLUSH); + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENHANCED_FLUSH; + p->offset = 0; + UINT16_TO_STREAM(pp, HCI_ENHANCED_FLUSH); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENHANCED_FLUSH); - UINT16_TO_STREAM (pp, handle); - UINT8_TO_STREAM (pp, packet_type); + UINT16_TO_STREAM(pp, handle); + UINT8_TO_STREAM(pp, packet_type); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif @@ -1257,98 +1175,92 @@ void btsnd_hcic_enhanced_flush (uint16_t handle, uint8_t packet_type) * End of Lisbon Commands *************************/ -void btsnd_hcic_get_link_quality (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_get_link_quality(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_GET_LINK_QUALITY); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_GET_LINK_QUALITY); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_read_rssi (uint16_t handle) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_read_rssi(uint16_t handle) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_READ_RSSI); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_CMD_HANDLE); + UINT16_TO_STREAM(pp, HCI_READ_RSSI); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE); - UINT16_TO_STREAM (pp, handle); + UINT16_TO_STREAM(pp, handle); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_enable_test_mode (void) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_enable_test_mode(void) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_ENABLE_DEV_UNDER_TEST_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_READ_CMD); + UINT16_TO_STREAM(pp, HCI_ENABLE_DEV_UNDER_TEST_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_inqscan_type (uint8_t type) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_inqscan_type(uint8_t type) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_INQSCAN_TYPE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_INQSCAN_TYPE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, type); + UINT8_TO_STREAM(pp, type); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_inquiry_mode (uint8_t mode) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_inquiry_mode(uint8_t mode) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_INQUIRY_MODE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_INQUIRY_MODE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, mode); + UINT8_TO_STREAM(pp, mode); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_write_pagescan_type (uint8_t type) -{ - BT_HDR *p = (BT_HDR *)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_write_pagescan_type(uint8_t type) { + BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; - p->offset = 0; + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; + p->offset = 0; - UINT16_TO_STREAM (pp, HCI_WRITE_PAGESCAN_TYPE); - UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM1); + UINT16_TO_STREAM(pp, HCI_WRITE_PAGESCAN_TYPE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); - UINT8_TO_STREAM (pp, type); + UINT8_TO_STREAM(pp, type); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } /* Must have room to store BT_HDR + max VSC length + callback pointer */ @@ -1356,21 +1268,21 @@ void btsnd_hcic_write_pagescan_type (uint8_t type) #error "HCI_CMD_BUF_SIZE must be larger than 268" #endif -void btsnd_hcic_vendor_spec_cmd (void *buffer, uint16_t opcode, uint8_t len, - uint8_t *p_data, void *p_cmd_cplt_cback) -{ - BT_HDR *p = (BT_HDR *)buffer; - uint8_t *pp = (uint8_t *)(p + 1); +void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len, + uint8_t* p_data, void* p_cmd_cplt_cback) { + BT_HDR* p = (BT_HDR*)buffer; + uint8_t* pp = (uint8_t*)(p + 1); - p->len = HCIC_PREAMBLE_SIZE + len; - p->offset = sizeof(void *); + p->len = HCIC_PREAMBLE_SIZE + len; + p->offset = sizeof(void*); - *((void **)pp) = p_cmd_cplt_cback; /* Store command complete callback in buffer */ - pp += sizeof(void *); /* Skip over callback pointer */ + *((void**)pp) = + p_cmd_cplt_cback; /* Store command complete callback in buffer */ + pp += sizeof(void*); /* Skip over callback pointer */ - UINT16_TO_STREAM (pp, HCI_GRP_VENDOR_SPECIFIC | opcode); - UINT8_TO_STREAM (pp, len); - ARRAY_TO_STREAM (pp, p_data, len); + UINT16_TO_STREAM(pp, HCI_GRP_VENDOR_SPECIFIC | opcode); + UINT8_TO_STREAM(pp, len); + ARRAY_TO_STREAM(pp, p_data, len); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } diff --git a/stack/hid/hid_conn.h b/stack/hid/hid_conn.h index 49a6ebd52..5e3ffe760 100644 --- a/stack/hid/hid_conn.h +++ b/stack/hid/hid_conn.h @@ -29,41 +29,40 @@ /* Define the HID Connection Block */ -typedef struct hid_conn -{ -#define HID_CONN_STATE_UNUSED (0) -#define HID_CONN_STATE_CONNECTING_CTRL (1) -#define HID_CONN_STATE_CONNECTING_INTR (2) -#define HID_CONN_STATE_CONFIG (3) -#define HID_CONN_STATE_CONNECTED (4) -#define HID_CONN_STATE_DISCONNECTING (5) -#define HID_CONN_STATE_SECURITY (6) +typedef struct hid_conn { +#define HID_CONN_STATE_UNUSED (0) +#define HID_CONN_STATE_CONNECTING_CTRL (1) +#define HID_CONN_STATE_CONNECTING_INTR (2) +#define HID_CONN_STATE_CONFIG (3) +#define HID_CONN_STATE_CONNECTED (4) +#define HID_CONN_STATE_DISCONNECTING (5) +#define HID_CONN_STATE_SECURITY (6) - uint8_t conn_state; + uint8_t conn_state; -#define HID_CONN_FLAGS_IS_ORIG (0x01) -#define HID_CONN_FLAGS_HIS_CTRL_CFG_DONE (0x02) -#define HID_CONN_FLAGS_MY_CTRL_CFG_DONE (0x04) -#define HID_CONN_FLAGS_HIS_INTR_CFG_DONE (0x08) -#define HID_CONN_FLAGS_MY_INTR_CFG_DONE (0x10) -#define HID_CONN_FLAGS_ALL_CONFIGURED (0x1E) /* All the config done */ -#define HID_CONN_FLAGS_CONGESTED (0x20) -#define HID_CONN_FLAGS_INACTIVE (0x40) +#define HID_CONN_FLAGS_IS_ORIG (0x01) +#define HID_CONN_FLAGS_HIS_CTRL_CFG_DONE (0x02) +#define HID_CONN_FLAGS_MY_CTRL_CFG_DONE (0x04) +#define HID_CONN_FLAGS_HIS_INTR_CFG_DONE (0x08) +#define HID_CONN_FLAGS_MY_INTR_CFG_DONE (0x10) +#define HID_CONN_FLAGS_ALL_CONFIGURED (0x1E) /* All the config done */ +#define HID_CONN_FLAGS_CONGESTED (0x20) +#define HID_CONN_FLAGS_INACTIVE (0x40) - uint8_t conn_flags; + uint8_t conn_flags; - uint8_t ctrl_id; - uint16_t ctrl_cid; - uint16_t intr_cid; - uint16_t rem_mtu_size; - uint16_t disc_reason; /* Reason for disconnecting (for HID_HDEV_EVT_CLOSE) */ - alarm_t *process_repage_timer; + uint8_t ctrl_id; + uint16_t ctrl_cid; + uint16_t intr_cid; + uint16_t rem_mtu_size; + uint16_t disc_reason; /* Reason for disconnecting (for HID_HDEV_EVT_CLOSE) */ + alarm_t* process_repage_timer; } tHID_CONN; -#define HID_SEC_CHN 1 +#define HID_SEC_CHN 1 #define HID_NOSEC_CHN 2 -#define HIDD_SEC_CHN 3 -#define HIDD_NOSEC_CHN 4 +#define HIDD_SEC_CHN 3 +#define HIDD_NOSEC_CHN 4 #endif diff --git a/stack/hid/hidh_api.cc b/stack/hid/hidh_api.cc index 4b4dd7e44..c3ab31543 100644 --- a/stack/hid/hidh_api.cc +++ b/stack/hid/hidh_api.cc @@ -22,22 +22,22 @@ * ******************************************************************************/ +#include #include #include -#include #include "bt_common.h" #include "bt_types.h" +#include "btm_api.h" +#include "btm_int.h" +#include "btu.h" #include "hiddefs.h" #include "hidh_api.h" #include "hidh_int.h" -#include "btm_api.h" -#include "btu.h" -#include "btm_int.h" tHID_HOST_CTB hh_cb; -static void hidh_search_callback (uint16_t sdp_result); +static void hidh_search_callback(uint16_t sdp_result); /******************************************************************************* * @@ -48,188 +48,177 @@ static void hidh_search_callback (uint16_t sdp_result); * Returns tHID_STATUS * ******************************************************************************/ -tHID_STATUS HID_HostGetSDPRecord ( BD_ADDR addr, tSDP_DISCOVERY_DB *p_db, uint32_t db_len, - tHID_HOST_SDP_CALLBACK *sdp_cback ) -{ - tSDP_UUID uuid_list; +tHID_STATUS HID_HostGetSDPRecord(BD_ADDR addr, tSDP_DISCOVERY_DB* p_db, + uint32_t db_len, + tHID_HOST_SDP_CALLBACK* sdp_cback) { + tSDP_UUID uuid_list; - if( hh_cb.sdp_busy ) - return HID_ERR_SDP_BUSY; + if (hh_cb.sdp_busy) return HID_ERR_SDP_BUSY; - uuid_list.len = 2; - uuid_list.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE; + uuid_list.len = 2; + uuid_list.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE; - hh_cb.p_sdp_db = p_db; - SDP_InitDiscoveryDb (p_db, db_len, 1, &uuid_list, 0, NULL); + hh_cb.p_sdp_db = p_db; + SDP_InitDiscoveryDb(p_db, db_len, 1, &uuid_list, 0, NULL); - if (SDP_ServiceSearchRequest (addr, p_db, hidh_search_callback)) - { - hh_cb.sdp_cback = sdp_cback ; - hh_cb.sdp_busy = true; - return HID_SUCCESS; - } - else - return HID_ERR_NO_RESOURCES; + if (SDP_ServiceSearchRequest(addr, p_db, hidh_search_callback)) { + hh_cb.sdp_cback = sdp_cback; + hh_cb.sdp_busy = true; + return HID_SUCCESS; + } else + return HID_ERR_NO_RESOURCES; } -void hidh_get_str_attr( tSDP_DISC_REC *p_rec, uint16_t attr_id, uint16_t max_len, char *str ) -{ - tSDP_DISC_ATTR *p_attr; - uint16_t name_len; - - p_attr = SDP_FindAttributeInRec(p_rec, attr_id); - if (p_attr != NULL) - { - name_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); - if(name_len < max_len) - { - memcpy( str, (char *) p_attr->attr_value.v.array, name_len ); - str[name_len] = '\0'; - } - else - { - memcpy( str, (char *) p_attr->attr_value.v.array, max_len-1 ); - str[max_len-1] = '\0'; - } - } - else - str[0] = '\0'; +void hidh_get_str_attr(tSDP_DISC_REC* p_rec, uint16_t attr_id, uint16_t max_len, + char* str) { + tSDP_DISC_ATTR* p_attr; + uint16_t name_len; + + p_attr = SDP_FindAttributeInRec(p_rec, attr_id); + if (p_attr != NULL) { + name_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + if (name_len < max_len) { + memcpy(str, (char*)p_attr->attr_value.v.array, name_len); + str[name_len] = '\0'; + } else { + memcpy(str, (char*)p_attr->attr_value.v.array, max_len - 1); + str[max_len - 1] = '\0'; + } + } else + str[0] = '\0'; } - -static void hidh_search_callback (uint16_t sdp_result) -{ - tSDP_DISCOVERY_DB *p_db = hh_cb.p_sdp_db; - tSDP_DISC_REC *p_rec; - tSDP_DISC_ATTR *p_attr, *p_subattr1, *p_subattr2, *p_repdesc; - tBT_UUID hid_uuid; - tHID_DEV_SDP_INFO *p_nvi = &hh_cb.sdp_rec; - uint16_t attr_mask = 0; - - hid_uuid.len = LEN_UUID_16; - hid_uuid.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE; - - hh_cb.sdp_busy = false; - - if (sdp_result != SDP_SUCCESS) - { - hh_cb.sdp_cback(sdp_result, 0, NULL); - return; - } - - p_rec = SDP_FindServiceUUIDInDb(p_db, &hid_uuid, NULL); - if (p_rec == NULL) - { - hh_cb.sdp_cback(HID_SDP_NO_SERV_UUID, 0, NULL); - return; - } - - memset (&hh_cb.sdp_rec, 0, sizeof( tHID_DEV_SDP_INFO )); - - /* First, verify the mandatory fields we care about */ - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_DESCRIPTOR_LIST)) == NULL) - || (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - || ((p_subattr1 = p_attr->attr_value.v.p_sub_attr) == NULL) - || (SDP_DISC_ATTR_TYPE(p_subattr1->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - || ((p_subattr2 = p_subattr1->attr_value.v.p_sub_attr) == NULL) - || ((p_repdesc = p_subattr2->p_next_attr) == NULL) - || (SDP_DISC_ATTR_TYPE(p_repdesc->attr_len_type) != TEXT_STR_DESC_TYPE)) - { - hh_cb.sdp_cback(HID_SDP_MANDATORY_MISSING, 0, NULL); - return; - } - - p_nvi->dscp_info.dl_len = SDP_DISC_ATTR_LEN(p_repdesc->attr_len_type); - if (p_nvi->dscp_info.dl_len != 0) - p_nvi->dscp_info.dsc_list = (uint8_t *) &p_repdesc->attr_value; - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_VIRTUAL_CABLE)) != NULL) && - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_VIRTUAL_CABLE; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_RECONNECT_INITIATE)) != NULL) && - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_RECONN_INIT; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_NORMALLY_CONNECTABLE)) != NULL) && - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_NORMALLY_CONNECTABLE; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_SDP_DISABLE)) != NULL)&& - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_SDP_DISABLE; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_BATTERY_POWER)) != NULL)&& - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_BATTERY_POWER; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_REMOTE_WAKE)) != NULL)&& - (p_attr->attr_value.v.u8) ) - { - attr_mask |= HID_REMOTE_WAKE; - } - - hidh_get_str_attr( p_rec, ATTR_ID_SERVICE_NAME, HID_MAX_SVC_NAME_LEN, p_nvi->svc_name ); - hidh_get_str_attr( p_rec, ATTR_ID_SERVICE_DESCRIPTION, HID_MAX_SVC_DESCR_LEN, p_nvi->svc_descr ); - hidh_get_str_attr( p_rec, ATTR_ID_PROVIDER_NAME, HID_MAX_PROV_NAME_LEN, p_nvi->prov_name ); - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_DEVICE_RELNUM)) != NULL)) - { - p_nvi->rel_num = p_attr->attr_value.v.u16; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_COUNTRY_CODE)) != NULL)) - { - p_nvi->ctry_code = p_attr->attr_value.v.u8; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_DEVICE_SUBCLASS)) != NULL)) - { - p_nvi->sub_class = p_attr->attr_value.v.u8; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_PARSER_VERSION)) != NULL)) - { - p_nvi->hpars_ver = p_attr->attr_value.v.u16; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_LINK_SUPERVISION_TO)) != NULL)) - { - attr_mask |= HID_SUP_TOUT_AVLBL; - p_nvi->sup_timeout = p_attr->attr_value.v.u16; - } - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_SSR_HOST_MAX_LAT)) != NULL)) - { - attr_mask |= HID_SSR_MAX_LATENCY; - p_nvi->ssr_max_latency = p_attr->attr_value.v.u16; - } - else - p_nvi->ssr_max_latency = HID_SSR_PARAM_INVALID; - - if (((p_attr = SDP_FindAttributeInRec (p_rec, ATTR_ID_HID_SSR_HOST_MIN_TOUT)) != NULL)) - { - attr_mask |= HID_SSR_MIN_TOUT; - p_nvi->ssr_min_tout = p_attr->attr_value.v.u16; - } - else - p_nvi->ssr_min_tout = HID_SSR_PARAM_INVALID; - - hh_cb.sdp_rec.p_sdp_layer_rec = p_rec; - hh_cb.sdp_cback(SDP_SUCCESS, attr_mask, &hh_cb.sdp_rec); +static void hidh_search_callback(uint16_t sdp_result) { + tSDP_DISCOVERY_DB* p_db = hh_cb.p_sdp_db; + tSDP_DISC_REC* p_rec; + tSDP_DISC_ATTR *p_attr, *p_subattr1, *p_subattr2, *p_repdesc; + tBT_UUID hid_uuid; + tHID_DEV_SDP_INFO* p_nvi = &hh_cb.sdp_rec; + uint16_t attr_mask = 0; + + hid_uuid.len = LEN_UUID_16; + hid_uuid.uu.uuid16 = UUID_SERVCLASS_HUMAN_INTERFACE; + + hh_cb.sdp_busy = false; + + if (sdp_result != SDP_SUCCESS) { + hh_cb.sdp_cback(sdp_result, 0, NULL); + return; + } + + p_rec = SDP_FindServiceUUIDInDb(p_db, &hid_uuid, NULL); + if (p_rec == NULL) { + hh_cb.sdp_cback(HID_SDP_NO_SERV_UUID, 0, NULL); + return; + } + + memset(&hh_cb.sdp_rec, 0, sizeof(tHID_DEV_SDP_INFO)); + + /* First, verify the mandatory fields we care about */ + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_DESCRIPTOR_LIST)) == + NULL) || + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) || + ((p_subattr1 = p_attr->attr_value.v.p_sub_attr) == NULL) || + (SDP_DISC_ATTR_TYPE(p_subattr1->attr_len_type) != + DATA_ELE_SEQ_DESC_TYPE) || + ((p_subattr2 = p_subattr1->attr_value.v.p_sub_attr) == NULL) || + ((p_repdesc = p_subattr2->p_next_attr) == NULL) || + (SDP_DISC_ATTR_TYPE(p_repdesc->attr_len_type) != TEXT_STR_DESC_TYPE)) { + hh_cb.sdp_cback(HID_SDP_MANDATORY_MISSING, 0, NULL); + return; + } + + p_nvi->dscp_info.dl_len = SDP_DISC_ATTR_LEN(p_repdesc->attr_len_type); + if (p_nvi->dscp_info.dl_len != 0) + p_nvi->dscp_info.dsc_list = (uint8_t*)&p_repdesc->attr_value; + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_VIRTUAL_CABLE)) != + NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_VIRTUAL_CABLE; + } + + if (((p_attr = SDP_FindAttributeInRec( + p_rec, ATTR_ID_HID_RECONNECT_INITIATE)) != NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_RECONN_INIT; + } + + if (((p_attr = SDP_FindAttributeInRec( + p_rec, ATTR_ID_HID_NORMALLY_CONNECTABLE)) != NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_NORMALLY_CONNECTABLE; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_SDP_DISABLE)) != + NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_SDP_DISABLE; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_BATTERY_POWER)) != + NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_BATTERY_POWER; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_REMOTE_WAKE)) != + NULL) && + (p_attr->attr_value.v.u8)) { + attr_mask |= HID_REMOTE_WAKE; + } + + hidh_get_str_attr(p_rec, ATTR_ID_SERVICE_NAME, HID_MAX_SVC_NAME_LEN, + p_nvi->svc_name); + hidh_get_str_attr(p_rec, ATTR_ID_SERVICE_DESCRIPTION, HID_MAX_SVC_DESCR_LEN, + p_nvi->svc_descr); + hidh_get_str_attr(p_rec, ATTR_ID_PROVIDER_NAME, HID_MAX_PROV_NAME_LEN, + p_nvi->prov_name); + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_DEVICE_RELNUM)) != + NULL)) { + p_nvi->rel_num = p_attr->attr_value.v.u16; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_COUNTRY_CODE)) != + NULL)) { + p_nvi->ctry_code = p_attr->attr_value.v.u8; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_DEVICE_SUBCLASS)) != + NULL)) { + p_nvi->sub_class = p_attr->attr_value.v.u8; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_PARSER_VERSION)) != + NULL)) { + p_nvi->hpars_ver = p_attr->attr_value.v.u16; + } + + if (((p_attr = SDP_FindAttributeInRec( + p_rec, ATTR_ID_HID_LINK_SUPERVISION_TO)) != NULL)) { + attr_mask |= HID_SUP_TOUT_AVLBL; + p_nvi->sup_timeout = p_attr->attr_value.v.u16; + } + + if (((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_HID_SSR_HOST_MAX_LAT)) != + NULL)) { + attr_mask |= HID_SSR_MAX_LATENCY; + p_nvi->ssr_max_latency = p_attr->attr_value.v.u16; + } else + p_nvi->ssr_max_latency = HID_SSR_PARAM_INVALID; + + if (((p_attr = SDP_FindAttributeInRec( + p_rec, ATTR_ID_HID_SSR_HOST_MIN_TOUT)) != NULL)) { + attr_mask |= HID_SSR_MIN_TOUT; + p_nvi->ssr_min_tout = p_attr->attr_value.v.u16; + } else + p_nvi->ssr_min_tout = HID_SSR_PARAM_INVALID; + + hh_cb.sdp_rec.p_sdp_layer_rec = p_rec; + hh_cb.sdp_cback(SDP_SUCCESS, attr_mask, &hh_cb.sdp_rec); } - /******************************************************************************* * * Function HID_HostInit @@ -240,19 +229,18 @@ static void hidh_search_callback (uint16_t sdp_result) * Returns void * ******************************************************************************/ -void HID_HostInit (void) -{ - memset(&hh_cb, 0, sizeof(tHID_HOST_CTB)); +void HID_HostInit(void) { + memset(&hh_cb, 0, sizeof(tHID_HOST_CTB)); - for (size_t i = 0; i < HID_HOST_MAX_DEVICES; i++) { - hh_cb.devices[i].conn.process_repage_timer = - alarm_new("hid_devices_conn.process_repage_timer"); - } + for (size_t i = 0; i < HID_HOST_MAX_DEVICES; i++) { + hh_cb.devices[i].conn.process_repage_timer = + alarm_new("hid_devices_conn.process_repage_timer"); + } #if defined(HID_INITIAL_TRACE_LEVEL) - hh_cb.trace_level = HID_INITIAL_TRACE_LEVEL; + hh_cb.trace_level = HID_INITIAL_TRACE_LEVEL; #else - hh_cb.trace_level = BT_TRACE_LEVEL_NONE; + hh_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif } @@ -266,12 +254,10 @@ void HID_HostInit (void) * Returns the new (current) trace level * ******************************************************************************/ -uint8_t HID_HostSetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - hh_cb.trace_level = new_level; +uint8_t HID_HostSetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) hh_cb.trace_level = new_level; - return (hh_cb.trace_level); + return (hh_cb.trace_level); } /******************************************************************************* @@ -283,27 +269,23 @@ uint8_t HID_HostSetTraceLevel (uint8_t new_level) * Returns tHID_STATUS * ******************************************************************************/ -tHID_STATUS HID_HostRegister (tHID_HOST_DEV_CALLBACK *dev_cback) -{ - tHID_STATUS st; +tHID_STATUS HID_HostRegister(tHID_HOST_DEV_CALLBACK* dev_cback) { + tHID_STATUS st; - if( hh_cb.reg_flag ) - return HID_ERR_ALREADY_REGISTERED; + if (hh_cb.reg_flag) return HID_ERR_ALREADY_REGISTERED; - if( dev_cback == NULL ) - return HID_ERR_INVALID_PARAM; + if (dev_cback == NULL) return HID_ERR_INVALID_PARAM; - /* Register with L2CAP */ - st = hidh_conn_reg(); - if(st != HID_SUCCESS) - { - return st; - } + /* Register with L2CAP */ + st = hidh_conn_reg(); + if (st != HID_SUCCESS) { + return st; + } - hh_cb.callback = dev_cback ; - hh_cb.reg_flag = true; + hh_cb.callback = dev_cback; + hh_cb.reg_flag = true; - return (HID_SUCCESS); + return (HID_SUCCESS); } /******************************************************************************* @@ -315,22 +297,19 @@ tHID_STATUS HID_HostRegister (tHID_HOST_DEV_CALLBACK *dev_cback) * Returns tHID_STATUS * ******************************************************************************/ -tHID_STATUS HID_HostDeregister(void) -{ - uint8_t i; +tHID_STATUS HID_HostDeregister(void) { + uint8_t i; - if( !hh_cb.reg_flag ) - return (HID_ERR_NOT_REGISTERED); + if (!hh_cb.reg_flag) return (HID_ERR_NOT_REGISTERED); - for( i=0; i= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use) ) - return HID_ERR_INVALID_PARAM; - - HID_HostCloseDev( dev_handle ) ; - hh_cb.devices[dev_handle].in_use = false; - hh_cb.devices[dev_handle].conn.conn_state = HID_CONN_STATE_UNUSED; - hh_cb.devices[dev_handle].conn.ctrl_cid = hh_cb.devices[dev_handle].conn.intr_cid = 0; - hh_cb.devices[dev_handle].attr_mask = 0; - return HID_SUCCESS; +tHID_STATUS HID_HostRemoveDev(uint8_t dev_handle) { + if (!hh_cb.reg_flag) return (HID_ERR_NOT_REGISTERED); + + if ((dev_handle >= HID_HOST_MAX_DEVICES) || + (!hh_cb.devices[dev_handle].in_use)) + return HID_ERR_INVALID_PARAM; + + HID_HostCloseDev(dev_handle); + hh_cb.devices[dev_handle].in_use = false; + hh_cb.devices[dev_handle].conn.conn_state = HID_CONN_STATE_UNUSED; + hh_cb.devices[dev_handle].conn.ctrl_cid = + hh_cb.devices[dev_handle].conn.intr_cid = 0; + hh_cb.devices[dev_handle].attr_mask = 0; + return HID_SUCCESS; } /******************************************************************************* @@ -421,19 +390,18 @@ tHID_STATUS HID_HostRemoveDev ( uint8_t dev_handle ) * Returns void * ******************************************************************************/ -tHID_STATUS HID_HostOpenDev ( uint8_t dev_handle ) -{ - if( !hh_cb.reg_flag ) - return (HID_ERR_NOT_REGISTERED); +tHID_STATUS HID_HostOpenDev(uint8_t dev_handle) { + if (!hh_cb.reg_flag) return (HID_ERR_NOT_REGISTERED); - if( (dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use) ) - return HID_ERR_INVALID_PARAM; + if ((dev_handle >= HID_HOST_MAX_DEVICES) || + (!hh_cb.devices[dev_handle].in_use)) + return HID_ERR_INVALID_PARAM; - if( hh_cb.devices[dev_handle].state != HID_DEV_NO_CONN ) - return HID_ERR_ALREADY_CONN; + if (hh_cb.devices[dev_handle].state != HID_DEV_NO_CONN) + return HID_ERR_ALREADY_CONN; - hh_cb.devices[dev_handle].conn_tries = 1; - return hidh_conn_initiate( dev_handle ); + hh_cb.devices[dev_handle].conn_tries = 1; + return hidh_conn_initiate(dev_handle); } /******************************************************************************* @@ -448,35 +416,33 @@ tHID_STATUS HID_HostOpenDev ( uint8_t dev_handle ) * Returns void * ******************************************************************************/ -tHID_STATUS HID_HostWriteDev( uint8_t dev_handle, uint8_t t_type, - uint8_t param, uint16_t data, uint8_t report_id, BT_HDR *pbuf ) -{ - tHID_STATUS status = HID_SUCCESS; - - if( !hh_cb.reg_flag ) - { - HIDH_TRACE_ERROR("HID_ERR_NOT_REGISTERED"); - status = HID_ERR_NOT_REGISTERED; - } - - if( (dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use) ) - { - HIDH_TRACE_ERROR("HID_ERR_INVALID_PARAM"); - status = HID_ERR_INVALID_PARAM; - } - - else if( hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED ) - { - HIDH_TRACE_ERROR("HID_ERR_NO_CONNECTION dev_handle %d", dev_handle); - status = HID_ERR_NO_CONNECTION; - } - - if (status != HID_SUCCESS) - osi_free(pbuf); - else - status = hidh_conn_snd_data(dev_handle, t_type, param, data, report_id, pbuf); - - return status; +tHID_STATUS HID_HostWriteDev(uint8_t dev_handle, uint8_t t_type, uint8_t param, + uint16_t data, uint8_t report_id, BT_HDR* pbuf) { + tHID_STATUS status = HID_SUCCESS; + + if (!hh_cb.reg_flag) { + HIDH_TRACE_ERROR("HID_ERR_NOT_REGISTERED"); + status = HID_ERR_NOT_REGISTERED; + } + + if ((dev_handle >= HID_HOST_MAX_DEVICES) || + (!hh_cb.devices[dev_handle].in_use)) { + HIDH_TRACE_ERROR("HID_ERR_INVALID_PARAM"); + status = HID_ERR_INVALID_PARAM; + } + + else if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) { + HIDH_TRACE_ERROR("HID_ERR_NO_CONNECTION dev_handle %d", dev_handle); + status = HID_ERR_NO_CONNECTION; + } + + if (status != HID_SUCCESS) + osi_free(pbuf); + else + status = + hidh_conn_snd_data(dev_handle, t_type, param, data, report_id, pbuf); + + return status; } /******************************************************************************* @@ -488,67 +454,65 @@ tHID_STATUS HID_HostWriteDev( uint8_t dev_handle, uint8_t t_type, * Returns void * ******************************************************************************/ -tHID_STATUS HID_HostCloseDev( uint8_t dev_handle ) -{ - if( !hh_cb.reg_flag ) - return (HID_ERR_NOT_REGISTERED); +tHID_STATUS HID_HostCloseDev(uint8_t dev_handle) { + if (!hh_cb.reg_flag) return (HID_ERR_NOT_REGISTERED); - if( (dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use) ) - return HID_ERR_INVALID_PARAM; + if ((dev_handle >= HID_HOST_MAX_DEVICES) || + (!hh_cb.devices[dev_handle].in_use)) + return HID_ERR_INVALID_PARAM; - if( hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED ) - return HID_ERR_NO_CONNECTION; + if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) + return HID_ERR_NO_CONNECTION; - alarm_cancel(hh_cb.devices[dev_handle].conn.process_repage_timer); - hh_cb.devices[dev_handle].conn_tries = HID_HOST_MAX_CONN_RETRY+1; - return hidh_conn_disconnect( dev_handle ); + alarm_cancel(hh_cb.devices[dev_handle].conn.process_repage_timer); + hh_cb.devices[dev_handle].conn_tries = HID_HOST_MAX_CONN_RETRY + 1; + return hidh_conn_disconnect(dev_handle); } -tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl ) -{ - if (!BTM_SetSecurityLevel (false, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL, - sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HID_SEC_CHN)) - { - HIDH_TRACE_ERROR ("Security Registration 1 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (true, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL, - sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HID_SEC_CHN)) - { - HIDH_TRACE_ERROR ("Security Registration 2 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (false, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL, - BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HID_NOSEC_CHN)) - { - HIDH_TRACE_ERROR ("Security Registration 3 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (true, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL, - BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, HID_NOSEC_CHN)) - { - HIDH_TRACE_ERROR ("Security Registration 4 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (true, serv_name, BTM_SEC_SERVICE_HIDH_INTR, - BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, 0)) - { - HIDH_TRACE_ERROR ("Security Registration 5 failed"); - return (HID_ERR_NO_RESOURCES); - } - - if (!BTM_SetSecurityLevel (false, serv_name, BTM_SEC_SERVICE_HIDH_INTR, - BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, 0)) - { - HIDH_TRACE_ERROR ("Security Registration 6 failed"); - return (HID_ERR_NO_RESOURCES); - } - - return( HID_SUCCESS ); +tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl) { + if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL, + sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, + HID_SEC_CHN)) { + HIDH_TRACE_ERROR("Security Registration 1 failed"); + return (HID_ERR_NO_RESOURCES); + } + + if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_SEC_CTRL, + sec_lvl, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, + HID_SEC_CHN)) { + HIDH_TRACE_ERROR("Security Registration 2 failed"); + return (HID_ERR_NO_RESOURCES); + } + + if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL, + BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, + HID_NOSEC_CHN)) { + HIDH_TRACE_ERROR("Security Registration 3 failed"); + return (HID_ERR_NO_RESOURCES); + } + + if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_NOSEC_CTRL, + BTM_SEC_NONE, HID_PSM_CONTROL, BTM_SEC_PROTO_HID, + HID_NOSEC_CHN)) { + HIDH_TRACE_ERROR("Security Registration 4 failed"); + return (HID_ERR_NO_RESOURCES); + } + + if (!BTM_SetSecurityLevel(true, serv_name, BTM_SEC_SERVICE_HIDH_INTR, + BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, + 0)) { + HIDH_TRACE_ERROR("Security Registration 5 failed"); + return (HID_ERR_NO_RESOURCES); + } + + if (!BTM_SetSecurityLevel(false, serv_name, BTM_SEC_SERVICE_HIDH_INTR, + BTM_SEC_NONE, HID_PSM_INTERRUPT, BTM_SEC_PROTO_HID, + 0)) { + HIDH_TRACE_ERROR("Security Registration 6 failed"); + return (HID_ERR_NO_RESOURCES); + } + + return (HID_SUCCESS); } /****************************************************************************** @@ -560,45 +524,41 @@ tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl ) * Returns true if device is HID Device else false * ******************************************************************************/ -bool hid_known_hid_device (BD_ADDR bd_addr) -{ - uint8_t i; - tBTM_INQ_INFO *p_inq_info = BTM_InqDbRead(bd_addr); - - if ( !hh_cb.reg_flag ) - return false; - - /* First check for class of device , if Inq DB has information about this device*/ - if (p_inq_info != NULL) - { - /* Check if remote major device class is of type BTM_COD_MAJOR_PERIPHERAL */ - if ((p_inq_info->results.dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) - == BTM_COD_MAJOR_PERIPHERAL ) - { - HIDH_TRACE_DEBUG("hid_known_hid_device:dev found in InqDB & COD matches HID dev"); - return true; - } - } - else - { - /* Look for this device in security device DB */ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); - if ((p_dev_rec != NULL) && - ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == BTM_COD_MAJOR_PERIPHERAL )) - { - HIDH_TRACE_DEBUG("hid_known_hid_device:dev found in SecDevDB & COD matches HID dev"); - return true; - } - } - - /* Find an entry for this device in hh_cb.devices array */ - for ( i=0; iresults.dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == + BTM_COD_MAJOR_PERIPHERAL) { + HIDH_TRACE_DEBUG( + "hid_known_hid_device:dev found in InqDB & COD matches HID dev"); + return true; + } + } else { + /* Look for this device in security device DB */ + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); + if ((p_dev_rec != NULL) && + ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == + BTM_COD_MAJOR_PERIPHERAL)) { + HIDH_TRACE_DEBUG( + "hid_known_hid_device:dev found in SecDevDB & COD matches HID dev"); + return true; + } + } + + /* Find an entry for this device in hh_cb.devices array */ + for (i = 0; i < HID_HOST_MAX_DEVICES; i++) { + if ((hh_cb.devices[i].in_use) && + (memcmp(bd_addr, hh_cb.devices[i].addr, BD_ADDR_LEN) == 0)) + return true; + } + /* Check if this device is marked as HID Device in IOP Dev */ + HIDH_TRACE_DEBUG("hid_known_hid_device:remote is not HID device"); + return false; } diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc index 7a5720230..cd5a9f667 100644 --- a/stack/hid/hidh_conn.cc +++ b/stack/hid/hidh_conn.cc @@ -22,50 +22,47 @@ * ******************************************************************************/ +#include #include #include -#include - #include "bt_common.h" #include "bt_types.h" -#include "l2cdefs.h" #include "l2c_api.h" +#include "l2cdefs.h" -#include "btu.h" #include "btm_api.h" #include "btm_int.h" +#include "btu.h" #include "hiddefs.h" +#include "bt_utils.h" #include "hidh_api.h" #include "hidh_int.h" -#include "bt_utils.h" #include "osi/include/osi.h" +extern fixed_queue_t* btu_general_alarm_queue; -extern fixed_queue_t *btu_general_alarm_queue; - -static uint8_t find_conn_by_cid (uint16_t cid); -static void hidh_conn_retry (uint8_t dhandle); +static uint8_t find_conn_by_cid(uint16_t cid); +static void hidh_conn_retry(uint8_t dhandle); /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void hidh_l2cif_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, - uint16_t psm, uint8_t l2cap_id); -static void hidh_l2cif_connect_cfm (uint16_t l2cap_cid, uint16_t result); -static void hidh_l2cif_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void hidh_l2cif_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void hidh_l2cif_disconnect_ind (uint16_t l2cap_cid, bool ack_needed); -static void hidh_l2cif_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg); -static void hidh_l2cif_disconnect_cfm (uint16_t l2cap_cid, uint16_t result); -static void hidh_l2cif_cong_ind (uint16_t l2cap_cid, bool congested); - -static const tL2CAP_APPL_INFO hst_reg_info = -{ +static void hidh_l2cif_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, + uint16_t psm, uint8_t l2cap_id); +static void hidh_l2cif_connect_cfm(uint16_t l2cap_cid, uint16_t result); +static void hidh_l2cif_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); +static void hidh_l2cif_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); +static void hidh_l2cif_disconnect_cfm(uint16_t l2cap_cid, uint16_t result); +static void hidh_l2cif_cong_ind(uint16_t l2cap_cid, bool congested); + +static const tL2CAP_APPL_INFO hst_reg_info = { hidh_l2cif_connect_ind, hidh_l2cif_connect_cfm, NULL, @@ -76,7 +73,7 @@ static const tL2CAP_APPL_INFO hst_reg_info = NULL, hidh_l2cif_data_ind, hidh_l2cif_cong_ind, - NULL /* tL2CA_TX_COMPLETE_CB */ + NULL /* tL2CA_TX_COMPLETE_CB */ }; /******************************************************************************* @@ -88,38 +85,34 @@ static const tL2CAP_APPL_INFO hst_reg_info = * Returns void * ******************************************************************************/ -tHID_STATUS hidh_conn_reg (void) -{ - int xx; - - /* Initialize the L2CAP configuration. We only care about MTU and flush */ - memset(&hh_cb.l2cap_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - - hh_cb.l2cap_cfg.mtu_present = true; - hh_cb.l2cap_cfg.mtu = HID_HOST_MTU; - hh_cb.l2cap_cfg.flush_to_present = true; - hh_cb.l2cap_cfg.flush_to = HID_HOST_FLUSH_TO; - - /* Now, register with L2CAP */ - if (!L2CA_Register (HID_PSM_CONTROL, (tL2CAP_APPL_INFO *) &hst_reg_info)) - { - HIDH_TRACE_ERROR ("HID-Host Control Registration failed"); - return (HID_ERR_L2CAP_FAILED) ; - } - if (!L2CA_Register (HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO *) &hst_reg_info)) - { - L2CA_Deregister( HID_PSM_CONTROL ) ; - HIDH_TRACE_ERROR ("HID-Host Interrupt Registration failed"); - return (HID_ERR_L2CAP_FAILED) ; - } - - for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) - { - hh_cb.devices[xx].in_use = false ; - hh_cb.devices[xx].conn.conn_state = HID_CONN_STATE_UNUSED; - } - - return (HID_SUCCESS); +tHID_STATUS hidh_conn_reg(void) { + int xx; + + /* Initialize the L2CAP configuration. We only care about MTU and flush */ + memset(&hh_cb.l2cap_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + + hh_cb.l2cap_cfg.mtu_present = true; + hh_cb.l2cap_cfg.mtu = HID_HOST_MTU; + hh_cb.l2cap_cfg.flush_to_present = true; + hh_cb.l2cap_cfg.flush_to = HID_HOST_FLUSH_TO; + + /* Now, register with L2CAP */ + if (!L2CA_Register(HID_PSM_CONTROL, (tL2CAP_APPL_INFO*)&hst_reg_info)) { + HIDH_TRACE_ERROR("HID-Host Control Registration failed"); + return (HID_ERR_L2CAP_FAILED); + } + if (!L2CA_Register(HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO*)&hst_reg_info)) { + L2CA_Deregister(HID_PSM_CONTROL); + HIDH_TRACE_ERROR("HID-Host Interrupt Registration failed"); + return (HID_ERR_L2CAP_FAILED); + } + + for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) { + hh_cb.devices[xx].in_use = false; + hh_cb.devices[xx].conn.conn_state = HID_CONN_STATE_UNUSED; + } + + return (HID_SUCCESS); } /******************************************************************************* @@ -131,31 +124,28 @@ tHID_STATUS hidh_conn_reg (void) * Returns true if disconnect started, false if already disconnected * ******************************************************************************/ -tHID_STATUS hidh_conn_disconnect (uint8_t dhandle) -{ - tHID_CONN *p_hcon = &hh_cb.devices[dhandle].conn; +tHID_STATUS hidh_conn_disconnect(uint8_t dhandle) { + tHID_CONN* p_hcon = &hh_cb.devices[dhandle].conn; - HIDH_TRACE_EVENT ("HID-Host disconnect"); + HIDH_TRACE_EVENT("HID-Host disconnect"); - if ((p_hcon->ctrl_cid != 0) || (p_hcon->intr_cid != 0)) - { - p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; - - /* Set l2cap idle timeout to 0 (so ACL link is disconnected - * immediately after last channel is closed) */ - L2CA_SetIdleTimeoutByBdAddr(hh_cb.devices[dhandle].addr, 0, BT_TRANSPORT_BR_EDR); - /* Disconnect both interrupt and control channels */ - if (p_hcon->intr_cid) - L2CA_DisconnectReq (p_hcon->intr_cid); - else if (p_hcon->ctrl_cid) - L2CA_DisconnectReq (p_hcon->ctrl_cid); - } - else - { - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - } + if ((p_hcon->ctrl_cid != 0) || (p_hcon->intr_cid != 0)) { + p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; - return (HID_SUCCESS); + /* Set l2cap idle timeout to 0 (so ACL link is disconnected + * immediately after last channel is closed) */ + L2CA_SetIdleTimeoutByBdAddr(hh_cb.devices[dhandle].addr, 0, + BT_TRANSPORT_BR_EDR); + /* Disconnect both interrupt and control channels */ + if (p_hcon->intr_cid) + L2CA_DisconnectReq(p_hcon->intr_cid); + else if (p_hcon->ctrl_cid) + L2CA_DisconnectReq(p_hcon->ctrl_cid); + } else { + p_hcon->conn_state = HID_CONN_STATE_UNUSED; + } + + return (HID_SUCCESS); } /******************************************************************************* @@ -168,31 +158,34 @@ tHID_STATUS hidh_conn_disconnect (uint8_t dhandle) * send security block L2C connection response. * ******************************************************************************/ -void hidh_sec_check_complete_term (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tHID_HOST_DEV_CTB *p_dev= (tHID_HOST_DEV_CTB *) p_ref_data; +void hidh_sec_check_complete_term(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tHID_HOST_DEV_CTB* p_dev = (tHID_HOST_DEV_CTB*)p_ref_data; - if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) - { - p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */ + if (res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY) { + p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset + disc_reason (from + HID_ERR_AUTH_FAILED) */ - p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_INTR; + p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_INTR; - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); + /* Send response to the L2CAP layer. */ + L2CA_ConnectRsp(p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, + L2CAP_CONN_OK, L2CAP_CONN_OK); - /* Send a Configuration Request. */ - L2CA_ConfigReq (p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg); + /* Send a Configuration Request. */ + L2CA_ConfigReq(p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg); - } - /* security check fail */ - else if (res != BTM_SUCCESS) - { - p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ - p_dev->conn.conn_state = HID_CONN_STATE_UNUSED; - L2CA_ConnectRsp (p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK); - } + } + /* security check fail */ + else if (res != BTM_SUCCESS) { + p_dev->conn.disc_reason = + HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ + p_dev->conn.conn_state = HID_CONN_STATE_UNUSED; + L2CA_ConnectRsp(p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, + L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK); + } } /******************************************************************************* @@ -206,96 +199,93 @@ void hidh_sec_check_complete_term (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_ * Returns void * ******************************************************************************/ -static void hidh_l2cif_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm, uint8_t l2cap_id) -{ - tHID_CONN *p_hcon; - bool bAccept = true; - uint8_t i = HID_HOST_MAX_DEVICES; - tHID_HOST_DEV_CTB *p_dev; +static void hidh_l2cif_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, + uint16_t psm, uint8_t l2cap_id) { + tHID_CONN* p_hcon; + bool bAccept = true; + uint8_t i = HID_HOST_MAX_DEVICES; + tHID_HOST_DEV_CTB* p_dev; + + HIDH_TRACE_EVENT("HID-Host Rcvd L2CAP conn ind, PSM: 0x%04x CID 0x%x", psm, + l2cap_cid); + + /* always add incoming connection device into HID database by default */ + if (HID_HostAddDev(bd_addr, HID_SEC_REQUIRED, &i) != HID_SUCCESS) { + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_SECURITY_BLOCK, 0); + return; + } - HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP conn ind, PSM: 0x%04x CID 0x%x", psm, l2cap_cid); + p_hcon = &hh_cb.devices[i].conn; + p_dev = &hh_cb.devices[i]; - /* always add incoming connection device into HID database by default */ - if (HID_HostAddDev(bd_addr, HID_SEC_REQUIRED, &i) != HID_SUCCESS) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_SECURITY_BLOCK, 0); - return; + /* Check we are in the correct state for this */ + if (psm == HID_PSM_INTERRUPT) { + if (p_hcon->ctrl_cid == 0) { + HIDH_TRACE_WARNING( + "HID-Host Rcvd INTR L2CAP conn ind, but no CTL channel"); + bAccept = false; } - - p_hcon = &hh_cb.devices[i].conn; - p_dev = &hh_cb.devices[i]; - - /* Check we are in the correct state for this */ - if (psm == HID_PSM_INTERRUPT) - { - if (p_hcon->ctrl_cid == 0) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd INTR L2CAP conn ind, but no CTL channel"); - bAccept = false; - } - if (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd INTR L2CAP conn ind, wrong state: %d", - p_hcon->conn_state); - bAccept = false; - } + if (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) { + HIDH_TRACE_WARNING("HID-Host Rcvd INTR L2CAP conn ind, wrong state: %d", + p_hcon->conn_state); + bAccept = false; } - else /* CTRL channel */ - { + } else /* CTRL channel */ + { #if (HID_HOST_ACPT_NEW_CONN == TRUE) - p_hcon->ctrl_cid = p_hcon->intr_cid = 0; - p_hcon->conn_state = HID_CONN_STATE_UNUSED; + p_hcon->ctrl_cid = p_hcon->intr_cid = 0; + p_hcon->conn_state = HID_CONN_STATE_UNUSED; #else - if (p_hcon->conn_state != HID_CONN_STATE_UNUSED) - { - HIDH_TRACE_WARNING ("HID-Host - Rcvd CTL L2CAP conn ind, wrong state: %d", - p_hcon->conn_state); - bAccept = false; - } -#endif - } - - if (!bAccept) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_RESOURCES, 0); - return; + if (p_hcon->conn_state != HID_CONN_STATE_UNUSED) { + HIDH_TRACE_WARNING("HID-Host - Rcvd CTL L2CAP conn ind, wrong state: %d", + p_hcon->conn_state); + bAccept = false; } +#endif + } - if (psm == HID_PSM_CONTROL) - { - p_hcon->conn_flags = 0; - p_hcon->ctrl_cid = l2cap_cid; - p_hcon->ctrl_id = l2cap_id; - p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to 'connection failure' */ - - p_hcon->conn_state = HID_CONN_STATE_SECURITY; - if(btm_sec_mx_access_request (p_dev->addr, HID_PSM_CONTROL, - false, BTM_SEC_PROTO_HID, + if (!bAccept) { + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_RESOURCES, 0); + return; + } + + if (psm == HID_PSM_CONTROL) { + p_hcon->conn_flags = 0; + p_hcon->ctrl_cid = l2cap_cid; + p_hcon->ctrl_id = l2cap_id; + p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs + before security is completed, + then set CLOSE_EVT reason code + to 'connection failure' */ + + p_hcon->conn_state = HID_CONN_STATE_SECURITY; + if (btm_sec_mx_access_request( + p_dev->addr, HID_PSM_CONTROL, false, BTM_SEC_PROTO_HID, (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN, - &hidh_sec_check_complete_term, p_dev) == BTM_CMD_STARTED) - { - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_PENDING, L2CAP_CONN_OK); - } - - return; + &hidh_sec_check_complete_term, p_dev) == BTM_CMD_STARTED) { + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_PENDING, + L2CAP_CONN_OK); } - /* Transition to the next appropriate state, configuration */ - p_hcon->conn_state = HID_CONN_STATE_CONFIG; - p_hcon->intr_cid = l2cap_cid; + return; + } - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); + /* Transition to the next appropriate state, configuration */ + p_hcon->conn_state = HID_CONN_STATE_CONFIG; + p_hcon->intr_cid = l2cap_cid; - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg); + /* Send response to the L2CAP layer. */ + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); - HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP conn ind, sent config req, PSM: 0x%04x CID 0x%x", - psm, l2cap_cid); + /* Send a Configuration Request. */ + L2CA_ConfigReq(l2cap_cid, &hh_cb.l2cap_cfg); + + HIDH_TRACE_EVENT( + "HID-Host Rcvd L2CAP conn ind, sent config req, PSM: 0x%04x CID 0x%x", + psm, l2cap_cid); } -void hidh_process_repage_timer_timeout(void *data) -{ +void hidh_process_repage_timer_timeout(void* data) { uint8_t dhandle = PTR_TO_UINT(data); hidh_try_repage(dhandle); } @@ -309,17 +299,16 @@ void hidh_process_repage_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void hidh_try_repage(uint8_t dhandle) -{ - tHID_HOST_DEV_CTB *device; +void hidh_try_repage(uint8_t dhandle) { + tHID_HOST_DEV_CTB* device; - hidh_conn_initiate(dhandle); + hidh_conn_initiate(dhandle); - device = &hh_cb.devices[dhandle]; - device->conn_tries++; + device = &hh_cb.devices[dhandle]; + device->conn_tries++; - hh_cb.callback(dhandle, device->addr, HID_HDEV_EVT_RETRYING, - device->conn_tries, NULL ) ; + hh_cb.callback(dhandle, device->addr, HID_HDEV_EVT_RETRYING, + device->conn_tries, NULL); } /******************************************************************************* @@ -332,43 +321,42 @@ void hidh_try_repage(uint8_t dhandle) * Returns void * ******************************************************************************/ -void hidh_sec_check_complete_orig (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tHID_HOST_DEV_CTB *p_dev = (tHID_HOST_DEV_CTB *) p_ref_data; - uint8_t dhandle; - - // TODO(armansito): This kind of math to determine a device handle is way - // too dirty and unnecessary. Why can't |p_dev| store it's handle? - dhandle = (PTR_TO_UINT(p_dev) - PTR_TO_UINT(&(hh_cb.devices[0])))/ sizeof(tHID_HOST_DEV_CTB); - if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) - { - HIDH_TRACE_EVENT ("HID-Host Originator security pass."); - p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */ - - /* Transition to the next appropriate state, configuration */ - p_dev->conn.conn_state = HID_CONN_STATE_CONFIG; - L2CA_ConfigReq (p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg); - HIDH_TRACE_EVENT ("HID-Host Got Control conn cnf, sent cfg req, CID: 0x%x", p_dev->conn.ctrl_cid); +void hidh_sec_check_complete_orig(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tHID_HOST_DEV_CTB* p_dev = (tHID_HOST_DEV_CTB*)p_ref_data; + uint8_t dhandle; + + // TODO(armansito): This kind of math to determine a device handle is way + // too dirty and unnecessary. Why can't |p_dev| store it's handle? + dhandle = (PTR_TO_UINT(p_dev) - PTR_TO_UINT(&(hh_cb.devices[0]))) / + sizeof(tHID_HOST_DEV_CTB); + if (res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY) { + HIDH_TRACE_EVENT("HID-Host Originator security pass."); + p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset + disc_reason (from + HID_ERR_AUTH_FAILED) */ - } + /* Transition to the next appropriate state, configuration */ + p_dev->conn.conn_state = HID_CONN_STATE_CONFIG; + L2CA_ConfigReq(p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg); + HIDH_TRACE_EVENT("HID-Host Got Control conn cnf, sent cfg req, CID: 0x%x", + p_dev->conn.ctrl_cid); + } - if( res != BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) - { + if (res != BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY) { #if (HID_HOST_MAX_CONN_RETRY > 0) - if( res == BTM_DEVICE_TIMEOUT ) - { - if( p_dev->conn_tries <= HID_HOST_MAX_CONN_RETRY ) - { - hidh_conn_retry (dhandle); - return; - } - } -#endif - p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ - hidh_conn_disconnect(dhandle); + if (res == BTM_DEVICE_TIMEOUT) { + if (p_dev->conn_tries <= HID_HOST_MAX_CONN_RETRY) { + hidh_conn_retry(dhandle); + return; + } } - +#endif + p_dev->conn.disc_reason = + HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */ + hidh_conn_disconnect(dhandle); + } } /******************************************************************************* @@ -382,76 +370,75 @@ void hidh_sec_check_complete_orig (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_ * Returns void * ******************************************************************************/ -static void hidh_l2cif_connect_cfm (uint16_t l2cap_cid, uint16_t result) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - uint32_t reason; - tHID_HOST_DEV_CTB *p_dev = NULL; - - /* Find CCB based on CID, and verify we are in a state to accept this message */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES) - { - p_dev = &hh_cb.devices[dhandle]; - p_hcon = &hh_cb.devices[dhandle].conn; - } - - if ((p_hcon == NULL) - || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG)) - || ((l2cap_cid == p_hcon->ctrl_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL)) - || ((l2cap_cid == p_hcon->intr_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) - && (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING))) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd unexpected conn cnf, CID 0x%x ", l2cap_cid); - return; - } +static void hidh_l2cif_connect_cfm(uint16_t l2cap_cid, uint16_t result) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + uint32_t reason; + tHID_HOST_DEV_CTB* p_dev = NULL; + + /* Find CCB based on CID, and verify we are in a state to accept this message + */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) { + p_dev = &hh_cb.devices[dhandle]; + p_hcon = &hh_cb.devices[dhandle].conn; + } + + if ((p_hcon == NULL) || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG)) || + ((l2cap_cid == p_hcon->ctrl_cid) && + (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL)) || + ((l2cap_cid == p_hcon->intr_cid) && + (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) && + (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING))) { + HIDH_TRACE_WARNING("HID-Host Rcvd unexpected conn cnf, CID 0x%x ", + l2cap_cid); + return; + } - if (result != L2CAP_CONN_OK) - { - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - p_hcon->intr_cid = 0; + if (result != L2CAP_CONN_OK) { + if (l2cap_cid == p_hcon->ctrl_cid) + p_hcon->ctrl_cid = 0; + else + p_hcon->intr_cid = 0; - hidh_conn_disconnect(dhandle); + hidh_conn_disconnect(dhandle); #if (HID_HOST_MAX_CONN_RETRY > 0) - if( (hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) && - (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED || - result == HCI_ERR_PAGE_TIMEOUT) ) - { - hidh_conn_retry(dhandle); - } - else + if ((hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) && + (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED || + result == HCI_ERR_PAGE_TIMEOUT)) { + hidh_conn_retry(dhandle); + } else #endif - { - reason = HID_L2CAP_CONN_FAIL | (uint32_t) result ; - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; - } - return; - } - /* receive Control Channel connect confirmation */ - if (l2cap_cid == p_hcon->ctrl_cid) - { - /* check security requirement */ - p_hcon->conn_state = HID_CONN_STATE_SECURITY; - p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to "connection failure" */ - - btm_sec_mx_access_request (p_dev->addr, HID_PSM_CONTROL, - true, BTM_SEC_PROTO_HID, - (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN, - &hidh_sec_check_complete_orig, p_dev); - } - else { - p_hcon->conn_state = HID_CONN_STATE_CONFIG; - /* Send a Configuration Request. */ - L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg); - HIDH_TRACE_EVENT ("HID-Host got Interrupt conn cnf, sent cfg req, CID: 0x%x", l2cap_cid); + reason = HID_L2CAP_CONN_FAIL | (uint32_t)result; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + reason, NULL); } - return; + } + /* receive Control Channel connect confirmation */ + if (l2cap_cid == p_hcon->ctrl_cid) { + /* check security requirement */ + p_hcon->conn_state = HID_CONN_STATE_SECURITY; + p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs + before security is completed, + then set CLOSE_EVT reason code + to "connection failure" */ + + btm_sec_mx_access_request( + p_dev->addr, HID_PSM_CONTROL, true, BTM_SEC_PROTO_HID, + (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN, + &hidh_sec_check_complete_orig, p_dev); + } else { + p_hcon->conn_state = HID_CONN_STATE_CONFIG; + /* Send a Configuration Request. */ + L2CA_ConfigReq(l2cap_cid, &hh_cb.l2cap_cfg); + HIDH_TRACE_EVENT("HID-Host got Interrupt conn cnf, sent cfg req, CID: 0x%x", + l2cap_cid); + } + + return; } /******************************************************************************* @@ -464,82 +451,81 @@ static void hidh_l2cif_connect_cfm (uint16_t l2cap_cid, uint16_t result) * Returns void * ******************************************************************************/ -static void hidh_l2cif_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - uint32_t reason; - - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES) - { - p_hcon = &hh_cb.devices[dhandle].conn; - } - - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); +static void hidh_l2cif_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + uint32_t reason; + + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) { + p_hcon = &hh_cb.devices[dhandle].conn; + } + + if (p_hcon == NULL) { + HIDH_TRACE_WARNING("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", + l2cap_cid); + return; + } + + HIDH_TRACE_EVENT("HID-Host Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid); + + /* Remember the remote MTU size */ + if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_HOST_MTU)) + p_hcon->rem_mtu_size = HID_HOST_MTU; + else + p_hcon->rem_mtu_size = p_cfg->mtu; + + /* For now, always accept configuration from the other side */ + p_cfg->flush_to_present = false; + p_cfg->mtu_present = false; + p_cfg->result = L2CAP_CFG_OK; + + L2CA_ConfigRsp(l2cap_cid, p_cfg); + + if (l2cap_cid == p_hcon->ctrl_cid) { + p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE; + if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) && + (p_hcon->conn_flags & HID_CONN_FLAGS_MY_CTRL_CFG_DONE)) { + /* Connect interrupt channel */ + p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for + CLOSE_EVT: Connection + Attempt was made but failed + */ + p_hcon->intr_cid = + L2CA_ConnectReq(HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr); + if (p_hcon->intr_cid == 0) { + HIDH_TRACE_WARNING("HID-Host INTR Originate failed"); + reason = HID_L2CAP_REQ_FAIL; + p_hcon->conn_state = HID_CONN_STATE_UNUSED; + hidh_conn_disconnect(dhandle); + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + reason, NULL); return; + } else { + /* Transition to the next appropriate state, waiting for connection + * confirm on interrupt channel. */ + p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; + } } - - HIDH_TRACE_EVENT ("HID-Host Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid); - - /* Remember the remote MTU size */ - if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_HOST_MTU)) - p_hcon->rem_mtu_size = HID_HOST_MTU; - else - p_hcon->rem_mtu_size = p_cfg->mtu; - - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = false; - p_cfg->mtu_present = false; - p_cfg->result = L2CAP_CFG_OK; - - L2CA_ConfigRsp (l2cap_cid, p_cfg); - - if (l2cap_cid == p_hcon->ctrl_cid) - { - p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE; - if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) && - (p_hcon->conn_flags & HID_CONN_FLAGS_MY_CTRL_CFG_DONE)) - { - /* Connect interrupt channel */ - p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */ - p_hcon->intr_cid = L2CA_ConnectReq(HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr); - if (p_hcon->intr_cid == 0) - { - HIDH_TRACE_WARNING ("HID-Host INTR Originate failed"); - reason = HID_L2CAP_REQ_FAIL ; - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - hidh_conn_disconnect (dhandle); - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; - return; - } - else - { - /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */ - p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; - } - } - } - else - p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE; - - /* If all configuration is complete, change state and tell management we are up */ - if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED) - && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) - { - p_hcon->conn_state = HID_CONN_STATE_CONNECTED; - /* Reset disconnect reason to success, as connection successful */ - p_hcon->disc_reason = HID_SUCCESS; - - hh_cb.devices[dhandle].state = HID_DEV_CONNECTED; - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ; - } + } else + p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE; + + /* If all configuration is complete, change state and tell management we are + * up */ + if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == + HID_CONN_FLAGS_ALL_CONFIGURED) && + (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) { + p_hcon->conn_state = HID_CONN_STATE_CONNECTED; + /* Reset disconnect reason to success, as connection successful */ + p_hcon->disc_reason = HID_SUCCESS; + + hh_cb.devices[dhandle].state = HID_DEV_CONNECTED; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, + NULL); + } } - /******************************************************************************* * * Function hidh_l2cif_config_cfm @@ -550,76 +536,76 @@ static void hidh_l2cif_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void hidh_l2cif_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - uint32_t reason; +static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + uint32_t reason; - HIDH_TRACE_EVENT ("HID-Host Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result); + HIDH_TRACE_EVENT("HID-Host Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, + p_cfg->result); - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES ) - p_hcon = &hh_cb.devices[dhandle].conn; + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) p_hcon = &hh_cb.devices[dhandle].conn; - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; - } - - /* If configuration failed, disconnect the channel(s) */ - if (p_cfg->result != L2CAP_CFG_OK) - { - hidh_conn_disconnect (dhandle); - reason = HID_L2CAP_CFG_FAIL | (uint32_t) p_cfg->result ; - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; + if (p_hcon == NULL) { + HIDH_TRACE_WARNING("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", + l2cap_cid); + return; + } + + /* If configuration failed, disconnect the channel(s) */ + if (p_cfg->result != L2CAP_CFG_OK) { + hidh_conn_disconnect(dhandle); + reason = HID_L2CAP_CFG_FAIL | (uint32_t)p_cfg->result; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + reason, NULL); + return; + } + + if (l2cap_cid == p_hcon->ctrl_cid) { + p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE; + if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) && + (p_hcon->conn_flags & HID_CONN_FLAGS_HIS_CTRL_CFG_DONE)) { + /* Connect interrupt channel */ + p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for + CLOSE_EVT: Connection + Attempt was made but failed + */ + p_hcon->intr_cid = + L2CA_ConnectReq(HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr); + if (p_hcon->intr_cid == 0) { + HIDH_TRACE_WARNING("HID-Host INTR Originate failed"); + reason = HID_L2CAP_REQ_FAIL; + p_hcon->conn_state = HID_CONN_STATE_UNUSED; + hidh_conn_disconnect(dhandle); + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + reason, NULL); return; + } else { + /* Transition to the next appropriate state, waiting for connection + * confirm on interrupt channel. */ + p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; + } } - - if (l2cap_cid == p_hcon->ctrl_cid) - { - p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE; - if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) && - (p_hcon->conn_flags & HID_CONN_FLAGS_HIS_CTRL_CFG_DONE)) - { - /* Connect interrupt channel */ - p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */ - p_hcon->intr_cid = L2CA_ConnectReq(HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr); - if (p_hcon->intr_cid == 0) - { - HIDH_TRACE_WARNING ("HID-Host INTR Originate failed"); - reason = HID_L2CAP_REQ_FAIL ; - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - hidh_conn_disconnect (dhandle); - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ; - return; - } - else - { - /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */ - p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR; - } - } - } - else - p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE; - - /* If all configuration is complete, change state and tell management we are up */ - if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED) - && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) - { - p_hcon->conn_state = HID_CONN_STATE_CONNECTED; - /* Reset disconnect reason to success, as connection successful */ - p_hcon->disc_reason = HID_SUCCESS; - - hh_cb.devices[dhandle].state = HID_DEV_CONNECTED; - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ; - } + } else + p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE; + + /* If all configuration is complete, change state and tell management we are + * up */ + if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == + HID_CONN_FLAGS_ALL_CONFIGURED) && + (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) { + p_hcon->conn_state = HID_CONN_STATE_CONNECTED; + /* Reset disconnect reason to success, as connection successful */ + p_hcon->disc_reason = HID_SUCCESS; + + hh_cb.devices[dhandle].state = HID_DEV_CONNECTED; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, + NULL); + } } - /******************************************************************************* * * Function hidh_l2cif_disconnect_ind @@ -630,81 +616,76 @@ static void hidh_l2cif_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void hidh_l2cif_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - uint16_t disc_res = HCI_SUCCESS; - uint16_t hid_close_evt_reason; - - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES ) - p_hcon = &hh_cb.devices[dhandle].conn; - - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); - return; - } +static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + uint16_t disc_res = HCI_SUCCESS; + uint16_t hid_close_evt_reason; + + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) p_hcon = &hh_cb.devices[dhandle].conn; + + if (p_hcon == NULL) { + HIDH_TRACE_WARNING("HID-Host Rcvd L2CAP disc, unknown CID: 0x%x", + l2cap_cid); + return; + } - if (ack_needed) - L2CA_DisconnectRsp (l2cap_cid); + if (ack_needed) L2CA_DisconnectRsp(l2cap_cid); - HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); + HIDH_TRACE_EVENT("HID-Host Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); - p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; + p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING; - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - p_hcon->intr_cid = 0; + if (l2cap_cid == p_hcon->ctrl_cid) + p_hcon->ctrl_cid = 0; + else + p_hcon->intr_cid = 0; - if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) - { - hh_cb.devices[dhandle].state = HID_DEV_NO_CONN; - p_hcon->conn_state = HID_CONN_STATE_UNUSED; + if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) { + hh_cb.devices[dhandle].state = HID_DEV_NO_CONN; + p_hcon->conn_state = HID_CONN_STATE_UNUSED; - if( !ack_needed ) - disc_res = btm_get_acl_disc_reason_code(); + if (!ack_needed) disc_res = btm_get_acl_disc_reason_code(); #if (HID_HOST_MAX_CONN_RETRY > 0) - if( (disc_res == HCI_ERR_CONNECTION_TOUT || disc_res == HCI_ERR_UNSPECIFIED) && - (!(hh_cb.devices[dhandle].attr_mask & HID_RECONN_INIT)) && - (hh_cb.devices[dhandle].attr_mask & HID_NORMALLY_CONNECTABLE)) - { - hh_cb.devices[dhandle].conn_tries = 0; - period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000; - alarm_set_on_queue(hh_cb.devices[dhandle].conn.process_repage_timer, - interval_ms, hidh_process_repage_timer_timeout, - UINT_TO_PTR(dhandle), btu_general_alarm_queue); - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, disc_res, NULL); - } - else + if ((disc_res == HCI_ERR_CONNECTION_TOUT || + disc_res == HCI_ERR_UNSPECIFIED) && + (!(hh_cb.devices[dhandle].attr_mask & HID_RECONN_INIT)) && + (hh_cb.devices[dhandle].attr_mask & HID_NORMALLY_CONNECTABLE)) { + hh_cb.devices[dhandle].conn_tries = 0; + period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000; + alarm_set_on_queue(hh_cb.devices[dhandle].conn.process_repage_timer, + interval_ms, hidh_process_repage_timer_timeout, + UINT_TO_PTR(dhandle), btu_general_alarm_queue); + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + disc_res, NULL); + } else #endif - { - /* Set reason code for HID_HDEV_EVT_CLOSE */ - hid_close_evt_reason = p_hcon->disc_reason; - - /* If we got baseband sent HCI_DISCONNECT_COMPLETE_EVT due to security failure, then set reason to HID_ERR_AUTH_FAILED */ - if ((disc_res == HCI_ERR_AUTH_FAILURE) || - (disc_res == HCI_ERR_KEY_MISSING) || - (disc_res == HCI_ERR_HOST_REJECT_SECURITY) || - (disc_res == HCI_ERR_PAIRING_NOT_ALLOWED) || - (disc_res == HCI_ERR_UNIT_KEY_USED) || - (disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || - (disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) || - (disc_res == HCI_ERR_REPEATED_ATTEMPTS)) - { - hid_close_evt_reason = HID_ERR_AUTH_FAILED; - } - - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, hid_close_evt_reason, NULL ) ; - } + { + /* Set reason code for HID_HDEV_EVT_CLOSE */ + hid_close_evt_reason = p_hcon->disc_reason; + + /* If we got baseband sent HCI_DISCONNECT_COMPLETE_EVT due to security + * failure, then set reason to HID_ERR_AUTH_FAILED */ + if ((disc_res == HCI_ERR_AUTH_FAILURE) || + (disc_res == HCI_ERR_KEY_MISSING) || + (disc_res == HCI_ERR_HOST_REJECT_SECURITY) || + (disc_res == HCI_ERR_PAIRING_NOT_ALLOWED) || + (disc_res == HCI_ERR_UNIT_KEY_USED) || + (disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || + (disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) || + (disc_res == HCI_ERR_REPEATED_ATTEMPTS)) { + hid_close_evt_reason = HID_ERR_AUTH_FAILED; + } + + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + hid_close_evt_reason, NULL); } + } } - /******************************************************************************* * * Function hidh_l2cif_disconnect_cfm @@ -714,46 +695,41 @@ static void hidh_l2cif_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) * Returns void * ******************************************************************************/ -static void hidh_l2cif_disconnect_cfm (uint16_t l2cap_cid, - UNUSED_ATTR uint16_t result) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES ) - p_hcon = &hh_cb.devices[dhandle].conn; - - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid); - return; - } - - HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); +static void hidh_l2cif_disconnect_cfm(uint16_t l2cap_cid, + UNUSED_ATTR uint16_t result) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) p_hcon = &hh_cb.devices[dhandle].conn; + + if (p_hcon == NULL) { + HIDH_TRACE_WARNING("HID-Host Rcvd L2CAP disc cfm, unknown CID: 0x%x", + l2cap_cid); + return; + } - if (l2cap_cid == p_hcon->ctrl_cid) - p_hcon->ctrl_cid = 0; - else - { - p_hcon->intr_cid = 0; - if (p_hcon->ctrl_cid) - { - HIDH_TRACE_EVENT ("HID-Host Initiating L2CAP Ctrl disconnection"); - L2CA_DisconnectReq (p_hcon->ctrl_cid); - } - } + HIDH_TRACE_EVENT("HID-Host Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); - if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) - { - hh_cb.devices[dhandle].state = HID_DEV_NO_CONN; - p_hcon->conn_state = HID_CONN_STATE_UNUSED; - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, p_hcon->disc_reason, NULL ) ; + if (l2cap_cid == p_hcon->ctrl_cid) + p_hcon->ctrl_cid = 0; + else { + p_hcon->intr_cid = 0; + if (p_hcon->ctrl_cid) { + HIDH_TRACE_EVENT("HID-Host Initiating L2CAP Ctrl disconnection"); + L2CA_DisconnectReq(p_hcon->ctrl_cid); } + } + + if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) { + hh_cb.devices[dhandle].state = HID_DEV_NO_CONN; + p_hcon->conn_state = HID_CONN_STATE_UNUSED; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + p_hcon->disc_reason, NULL); + } } - /******************************************************************************* * * Function hidh_l2cif_cong_ind @@ -763,34 +739,30 @@ static void hidh_l2cif_disconnect_cfm (uint16_t l2cap_cid, * Returns void * ******************************************************************************/ -static void hidh_l2cif_cong_ind (uint16_t l2cap_cid, bool congested) -{ - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; +static void hidh_l2cif_cong_ind(uint16_t l2cap_cid, bool congested) { + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if(dhandle < HID_HOST_MAX_DEVICES ) - p_hcon = &hh_cb.devices[dhandle].conn; + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) p_hcon = &hh_cb.devices[dhandle].conn; - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP congestion status, unknown CID: 0x%x", l2cap_cid); - return; - } + if (p_hcon == NULL) { + HIDH_TRACE_WARNING( + "HID-Host Rcvd L2CAP congestion status, unknown CID: 0x%x", l2cap_cid); + return; + } - HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP congestion status, CID: 0x%x Cong: %d", l2cap_cid, congested); + HIDH_TRACE_EVENT("HID-Host Rcvd L2CAP congestion status, CID: 0x%x Cong: %d", + l2cap_cid, congested); - if (congested) - p_hcon->conn_flags |= HID_CONN_FLAGS_CONGESTED; - else - { - p_hcon->conn_flags &= ~HID_CONN_FLAGS_CONGESTED; - - } + if (congested) + p_hcon->conn_flags |= HID_CONN_FLAGS_CONGESTED; + else { + p_hcon->conn_flags &= ~HID_CONN_FLAGS_CONGESTED; + } } - /******************************************************************************* * * Function hidh_l2cif_data_ind @@ -807,76 +779,77 @@ static void hidh_l2cif_cong_ind (uint16_t l2cap_cid, bool congested) * Returns void * ******************************************************************************/ -static void hidh_l2cif_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) -{ - uint8_t *p_data = (uint8_t *)(p_msg + 1) + p_msg->offset; - uint8_t ttype, param, rep_type, evt; - uint8_t dhandle; - tHID_CONN *p_hcon = NULL; - - HIDH_TRACE_DEBUG ("HID-Host hidh_l2cif_data_ind [l2cap_cid=0x%04x]", l2cap_cid); - - /* Find CCB based on CID */ - dhandle = find_conn_by_cid(l2cap_cid); - if (dhandle < HID_HOST_MAX_DEVICES) - p_hcon = &hh_cb.devices[dhandle].conn; - - if (p_hcon == NULL) - { - HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); - osi_free(p_msg); - return; - } - +static void hidh_l2cif_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) { + uint8_t* p_data = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint8_t ttype, param, rep_type, evt; + uint8_t dhandle; + tHID_CONN* p_hcon = NULL; + + HIDH_TRACE_DEBUG("HID-Host hidh_l2cif_data_ind [l2cap_cid=0x%04x]", + l2cap_cid); + + /* Find CCB based on CID */ + dhandle = find_conn_by_cid(l2cap_cid); + if (dhandle < HID_HOST_MAX_DEVICES) p_hcon = &hh_cb.devices[dhandle].conn; + + if (p_hcon == NULL) { + HIDH_TRACE_WARNING("HID-Host Rcvd L2CAP data, unknown CID: 0x%x", + l2cap_cid); + osi_free(p_msg); + return; + } - ttype = HID_GET_TRANS_FROM_HDR(*p_data); - param = HID_GET_PARAM_FROM_HDR(*p_data); - rep_type = param & HID_PAR_REP_TYPE_MASK; - p_data++; + ttype = HID_GET_TRANS_FROM_HDR(*p_data); + param = HID_GET_PARAM_FROM_HDR(*p_data); + rep_type = param & HID_PAR_REP_TYPE_MASK; + p_data++; - /* Get rid of the data type */ - p_msg->len--; - p_msg->offset++; + /* Get rid of the data type */ + p_msg->len--; + p_msg->offset++; - switch (ttype) - { + switch (ttype) { case HID_TRANS_HANDSHAKE: - hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_HANDSHAKE, param, NULL); - osi_free(p_msg); - break; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, + HID_HDEV_EVT_HANDSHAKE, param, NULL); + osi_free(p_msg); + break; case HID_TRANS_CONTROL: - switch (param) - { + switch (param) { case HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG: - hidh_conn_disconnect( dhandle ) ; - /* Device is unplugging from us. Tell USB */ - hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_VC_UNPLUG, 0, NULL); - break; + hidh_conn_disconnect(dhandle); + /* Device is unplugging from us. Tell USB */ + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, + HID_HDEV_EVT_VC_UNPLUG, 0, NULL); + break; default: - break; - } - osi_free(p_msg); - break; - + break; + } + osi_free(p_msg); + break; case HID_TRANS_DATA: - evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ? - HID_HDEV_EVT_INTR_DATA : HID_HDEV_EVT_CTRL_DATA; - hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, p_msg); - break; + evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) + ? HID_HDEV_EVT_INTR_DATA + : HID_HDEV_EVT_CTRL_DATA; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, + p_msg); + break; case HID_TRANS_DATAC: - evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ? - HID_HDEV_EVT_INTR_DATC : HID_HDEV_EVT_CTRL_DATC; - hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, p_msg); - break; + evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) + ? HID_HDEV_EVT_INTR_DATC + : HID_HDEV_EVT_CTRL_DATC; + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, + p_msg); + break; default: - osi_free(p_msg); - break; - } + osi_free(p_msg); + break; + } } /******************************************************************************* @@ -888,34 +861,32 @@ static void hidh_l2cif_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) * Returns tHID_STATUS * ******************************************************************************/ -tHID_STATUS hidh_conn_snd_data (uint8_t dhandle, uint8_t trans_type, uint8_t param, - uint16_t data, uint8_t report_id, BT_HDR *buf) -{ - tHID_CONN *p_hcon = &hh_cb.devices[dhandle].conn; - BT_HDR *p_buf; - uint8_t *p_out; - uint16_t bytes_copied; - bool seg_req = false; - uint16_t data_size; - uint16_t cid; - uint16_t buf_size; - uint8_t use_data = 0 ; - bool blank_datc = false; - - if (!BTM_IsAclConnectionUp(hh_cb.devices[dhandle].addr, BT_TRANSPORT_BR_EDR)) - { - osi_free(buf); - return HID_ERR_NO_CONNECTION; - } - - if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) - { - osi_free(buf); - return HID_ERR_CONGESTED; - } - - switch( trans_type ) - { +tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, + uint8_t param, uint16_t data, uint8_t report_id, + BT_HDR* buf) { + tHID_CONN* p_hcon = &hh_cb.devices[dhandle].conn; + BT_HDR* p_buf; + uint8_t* p_out; + uint16_t bytes_copied; + bool seg_req = false; + uint16_t data_size; + uint16_t cid; + uint16_t buf_size; + uint8_t use_data = 0; + bool blank_datc = false; + + if (!BTM_IsAclConnectionUp(hh_cb.devices[dhandle].addr, + BT_TRANSPORT_BR_EDR)) { + osi_free(buf); + return HID_ERR_NO_CONNECTION; + } + + if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) { + osi_free(buf); + return HID_ERR_CONGESTED; + } + + switch (trans_type) { case HID_TRANS_CONTROL: case HID_TRANS_GET_REPORT: case HID_TRANS_SET_REPORT: @@ -923,97 +894,84 @@ tHID_STATUS hidh_conn_snd_data (uint8_t dhandle, uint8_t trans_type, uint8_t par case HID_TRANS_SET_PROTOCOL: case HID_TRANS_GET_IDLE: case HID_TRANS_SET_IDLE: - cid = p_hcon->ctrl_cid; - buf_size = HID_CONTROL_BUF_SIZE; - break; + cid = p_hcon->ctrl_cid; + buf_size = HID_CONTROL_BUF_SIZE; + break; case HID_TRANS_DATA: - cid = p_hcon->intr_cid; - buf_size = HID_INTERRUPT_BUF_SIZE; - break; + cid = p_hcon->intr_cid; + buf_size = HID_INTERRUPT_BUF_SIZE; + break; default: - return (HID_ERR_INVALID_PARAM) ; + return (HID_ERR_INVALID_PARAM); + } + + if (trans_type == HID_TRANS_SET_IDLE) + use_data = 1; + else if ((trans_type == HID_TRANS_GET_REPORT) && (param & 0x08)) + use_data = 2; + + do { + if (buf == NULL || blank_datc) { + p_buf = (BT_HDR*)osi_malloc(buf_size); + + p_buf->offset = L2CAP_MIN_OFFSET; + seg_req = false; + data_size = 0; + bytes_copied = 0; + blank_datc = false; + } else if ((buf->len > (p_hcon->rem_mtu_size - 1))) { + p_buf = (BT_HDR*)osi_malloc(buf_size); + + p_buf->offset = L2CAP_MIN_OFFSET; + seg_req = true; + data_size = buf->len; + bytes_copied = p_hcon->rem_mtu_size - 1; + } else { + p_buf = buf; + p_buf->offset -= 1; + seg_req = false; + data_size = buf->len; + bytes_copied = buf->len; } - if( trans_type == HID_TRANS_SET_IDLE ) - use_data = 1; - else if( (trans_type == HID_TRANS_GET_REPORT) && (param & 0x08) ) - use_data = 2; + p_out = (uint8_t*)(p_buf + 1) + p_buf->offset; + *p_out++ = HID_BUILD_HDR(trans_type, param); - do - { - if ( buf == NULL || blank_datc ) - { - p_buf = (BT_HDR *)osi_malloc(buf_size); - - p_buf->offset = L2CAP_MIN_OFFSET; - seg_req = false; - data_size = 0; - bytes_copied = 0; - blank_datc = false; - } - else if ( (buf->len > (p_hcon->rem_mtu_size - 1))) - { - p_buf = (BT_HDR *)osi_malloc(buf_size); - - p_buf->offset = L2CAP_MIN_OFFSET; - seg_req = true; - data_size = buf->len; - bytes_copied = p_hcon->rem_mtu_size - 1; - } - else - { - p_buf = buf ; - p_buf->offset -= 1; - seg_req = false; - data_size = buf->len; - bytes_copied = buf->len; - } - - p_out = (uint8_t *)(p_buf + 1) + p_buf->offset; - *p_out++ = HID_BUILD_HDR(trans_type, param); - - /* If report ID required for this device */ - if( (trans_type == HID_TRANS_GET_REPORT) && (report_id != 0) ) - { - *p_out = report_id; - data_size = bytes_copied = 1; - } - - - if (seg_req) - { - memcpy (p_out, (((uint8_t *)(buf+1)) + buf->offset), bytes_copied); - buf->offset += bytes_copied; - buf->len -= bytes_copied; - } - else if( use_data == 1) - { - *(p_out+bytes_copied) = data & 0xff; - } - else if( use_data == 2 ) - { - *(p_out+bytes_copied) = data & 0xff; - *(p_out+bytes_copied+1) = (data >> 8) & 0xff ; - } - - p_buf->len = bytes_copied + 1 + use_data; - data_size -= bytes_copied; - - /* Send the buffer through L2CAP */ - if ((p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) || (!L2CA_DataWrite (cid, p_buf))) - return (HID_ERR_CONGESTED); - - if (data_size) - trans_type = HID_TRANS_DATAC; - else if( bytes_copied == (p_hcon->rem_mtu_size - 1) ) - { - trans_type = HID_TRANS_DATAC; - blank_datc = true; - } - - } while ((data_size != 0) || blank_datc ) ; - - return (HID_SUCCESS); + /* If report ID required for this device */ + if ((trans_type == HID_TRANS_GET_REPORT) && (report_id != 0)) { + *p_out = report_id; + data_size = bytes_copied = 1; + } + + if (seg_req) { + memcpy(p_out, (((uint8_t*)(buf + 1)) + buf->offset), bytes_copied); + buf->offset += bytes_copied; + buf->len -= bytes_copied; + } else if (use_data == 1) { + *(p_out + bytes_copied) = data & 0xff; + } else if (use_data == 2) { + *(p_out + bytes_copied) = data & 0xff; + *(p_out + bytes_copied + 1) = (data >> 8) & 0xff; + } + + p_buf->len = bytes_copied + 1 + use_data; + data_size -= bytes_copied; + + /* Send the buffer through L2CAP */ + if ((p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) || + (!L2CA_DataWrite(cid, p_buf))) + return (HID_ERR_CONGESTED); + + if (data_size) + trans_type = HID_TRANS_DATAC; + else if (bytes_copied == (p_hcon->rem_mtu_size - 1)) { + trans_type = HID_TRANS_DATAC; + blank_datc = true; + } + + } while ((data_size != 0) || blank_datc); + + return (HID_SUCCESS); } /******************************************************************************* * @@ -1025,48 +983,45 @@ tHID_STATUS hidh_conn_snd_data (uint8_t dhandle, uint8_t trans_type, uint8_t par * Returns void * ******************************************************************************/ -tHID_STATUS hidh_conn_initiate (uint8_t dhandle) -{ - uint8_t service_id = BTM_SEC_SERVICE_HIDH_NOSEC_CTRL; - uint32_t mx_chan_id = HID_NOSEC_CHN; - - tHID_HOST_DEV_CTB *p_dev = &hh_cb.devices[dhandle]; - - if( p_dev->conn.conn_state != HID_CONN_STATE_UNUSED ) - return( HID_ERR_CONN_IN_PROCESS ); - - p_dev->conn.ctrl_cid = 0; - p_dev->conn.intr_cid = 0; - p_dev->conn.disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */ - - /* We are the originator of this connection */ - p_dev->conn.conn_flags = HID_CONN_FLAGS_IS_ORIG; - - if(p_dev->attr_mask & HID_SEC_REQUIRED) - { - service_id = BTM_SEC_SERVICE_HIDH_SEC_CTRL; - mx_chan_id = HID_SEC_CHN; - } - BTM_SetOutService (p_dev->addr, service_id, mx_chan_id); - - /* Check if L2CAP started the connection process */ - p_dev->conn.ctrl_cid = L2CA_ConnectReq(HID_PSM_CONTROL, p_dev->addr); - if (p_dev->conn.ctrl_cid == 0) - { - HIDH_TRACE_WARNING ("HID-Host Originate failed"); - hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, - HID_ERR_L2CAP_FAILED, NULL ) ; - } - else - { - /* Transition to the next appropriate state, waiting for connection confirm on control channel. */ - p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL; - } - - return( HID_SUCCESS ); +tHID_STATUS hidh_conn_initiate(uint8_t dhandle) { + uint8_t service_id = BTM_SEC_SERVICE_HIDH_NOSEC_CTRL; + uint32_t mx_chan_id = HID_NOSEC_CHN; + + tHID_HOST_DEV_CTB* p_dev = &hh_cb.devices[dhandle]; + + if (p_dev->conn.conn_state != HID_CONN_STATE_UNUSED) + return (HID_ERR_CONN_IN_PROCESS); + + p_dev->conn.ctrl_cid = 0; + p_dev->conn.intr_cid = 0; + p_dev->conn.disc_reason = + HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection + Attempt was made but failed */ + + /* We are the originator of this connection */ + p_dev->conn.conn_flags = HID_CONN_FLAGS_IS_ORIG; + + if (p_dev->attr_mask & HID_SEC_REQUIRED) { + service_id = BTM_SEC_SERVICE_HIDH_SEC_CTRL; + mx_chan_id = HID_SEC_CHN; + } + BTM_SetOutService(p_dev->addr, service_id, mx_chan_id); + + /* Check if L2CAP started the connection process */ + p_dev->conn.ctrl_cid = L2CA_ConnectReq(HID_PSM_CONTROL, p_dev->addr); + if (p_dev->conn.ctrl_cid == 0) { + HIDH_TRACE_WARNING("HID-Host Originate failed"); + hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, + HID_ERR_L2CAP_FAILED, NULL); + } else { + /* Transition to the next appropriate state, waiting for connection confirm + * on control channel. */ + p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL; + } + + return (HID_SUCCESS); } - /******************************************************************************* * * Function find_conn_by_cid @@ -1076,24 +1031,23 @@ tHID_STATUS hidh_conn_initiate (uint8_t dhandle) * Returns address of control block, or NULL if not found * ******************************************************************************/ -static uint8_t find_conn_by_cid (uint16_t cid) -{ - uint8_t xx; - - for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) - { - if ((hh_cb.devices[xx].in_use) && (hh_cb.devices[xx].conn.conn_state != HID_CONN_STATE_UNUSED) - && ((hh_cb.devices[xx].conn.ctrl_cid == cid) || (hh_cb.devices[xx].conn.intr_cid == cid))) - break; - } - - return (xx); +static uint8_t find_conn_by_cid(uint16_t cid) { + uint8_t xx; + + for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) { + if ((hh_cb.devices[xx].in_use) && + (hh_cb.devices[xx].conn.conn_state != HID_CONN_STATE_UNUSED) && + ((hh_cb.devices[xx].conn.ctrl_cid == cid) || + (hh_cb.devices[xx].conn.intr_cid == cid))) + break; + } + + return (xx); } -void hidh_conn_dereg( void ) -{ - L2CA_Deregister (HID_PSM_CONTROL); - L2CA_Deregister (HID_PSM_INTERRUPT); +void hidh_conn_dereg(void) { + L2CA_Deregister(HID_PSM_CONTROL); + L2CA_Deregister(HID_PSM_INTERRUPT); } /******************************************************************************* @@ -1105,17 +1059,16 @@ void hidh_conn_dereg( void ) * Returns void * ******************************************************************************/ -static void hidh_conn_retry( uint8_t dhandle ) -{ - tHID_HOST_DEV_CTB *p_dev = &hh_cb.devices[dhandle]; +static void hidh_conn_retry(uint8_t dhandle) { + tHID_HOST_DEV_CTB* p_dev = &hh_cb.devices[dhandle]; - p_dev->conn.conn_state = HID_CONN_STATE_UNUSED; + p_dev->conn.conn_state = HID_CONN_STATE_UNUSED; #if (HID_HOST_REPAGE_WIN > 0) - period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000; - alarm_set_on_queue(p_dev->conn.process_repage_timer, - interval_ms, hidh_process_repage_timer_timeout, - UINT_TO_PTR(dhandle), btu_general_alarm_queue); + period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000; + alarm_set_on_queue(p_dev->conn.process_repage_timer, interval_ms, + hidh_process_repage_timer_timeout, UINT_TO_PTR(dhandle), + btu_general_alarm_queue); #else - hidh_try_repage(dhandle); + hidh_try_repage(dhandle); #endif } diff --git a/stack/hid/hidh_int.h b/stack/hid/hidh_int.h index 0951b3809..38f32a2f9 100644 --- a/stack/hid/hidh_int.h +++ b/stack/hid/hidh_int.h @@ -25,61 +25,59 @@ #ifndef HIDH_INT_H #define HIDH_INT_H -#include "hidh_api.h" #include "hid_conn.h" +#include "hidh_api.h" #include "l2c_api.h" #ifdef __cplusplus extern "C" { #endif -enum { - HID_DEV_NO_CONN, - HID_DEV_CONNECTED -}; +enum { HID_DEV_NO_CONN, HID_DEV_CONNECTED }; -typedef struct per_device_ctb -{ - bool in_use; - BD_ADDR addr; /* BD-Addr of the host device */ - uint16_t attr_mask; /* 0x01- virtual_cable; 0x02- normally_connectable; 0x03- reconn_initiate; - 0x04- sdp_disable; */ - uint8_t state; /* Device state if in HOST-KNOWN mode */ - uint8_t conn_substate; - uint8_t conn_tries; /* Remembers the number of connection attempts while CONNECTING */ +typedef struct per_device_ctb { + bool in_use; + BD_ADDR addr; /* BD-Addr of the host device */ + uint16_t attr_mask; /* 0x01- virtual_cable; 0x02- normally_connectable; 0x03- + reconn_initiate; + 0x04- sdp_disable; */ + uint8_t state; /* Device state if in HOST-KNOWN mode */ + uint8_t conn_substate; + uint8_t conn_tries; /* Remembers the number of connection attempts while + CONNECTING */ - tHID_CONN conn; /* L2CAP channel info */ + tHID_CONN conn; /* L2CAP channel info */ } tHID_HOST_DEV_CTB; -typedef struct host_ctb -{ - tHID_HOST_DEV_CTB devices[HID_HOST_MAX_DEVICES]; - tHID_HOST_DEV_CALLBACK *callback; /* Application callbacks */ - tL2CAP_CFG_INFO l2cap_cfg; +typedef struct host_ctb { + tHID_HOST_DEV_CTB devices[HID_HOST_MAX_DEVICES]; + tHID_HOST_DEV_CALLBACK* callback; /* Application callbacks */ + tL2CAP_CFG_INFO l2cap_cfg; -#define MAX_SERVICE_DB_SIZE 4000 +#define MAX_SERVICE_DB_SIZE 4000 - bool sdp_busy; - tHID_HOST_SDP_CALLBACK *sdp_cback; - tSDP_DISCOVERY_DB *p_sdp_db; - tHID_DEV_SDP_INFO sdp_rec; - bool reg_flag; - uint8_t trace_level; + bool sdp_busy; + tHID_HOST_SDP_CALLBACK* sdp_cback; + tSDP_DISCOVERY_DB* p_sdp_db; + tHID_DEV_SDP_INFO sdp_rec; + bool reg_flag; + uint8_t trace_level; } tHID_HOST_CTB; -extern tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, uint8_t param, \ - uint16_t data,uint8_t rpt_id, BT_HDR *buf); -extern tHID_STATUS hidh_conn_reg (void); -extern void hidh_conn_dereg( void ); -extern tHID_STATUS hidh_conn_disconnect (uint8_t dhandle); -extern tHID_STATUS hidh_conn_initiate (uint8_t dhandle); -extern void hidh_process_repage_timer_timeout(void *data); +extern tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, + uint8_t param, uint16_t data, + uint8_t rpt_id, BT_HDR* buf); +extern tHID_STATUS hidh_conn_reg(void); +extern void hidh_conn_dereg(void); +extern tHID_STATUS hidh_conn_disconnect(uint8_t dhandle); +extern tHID_STATUS hidh_conn_initiate(uint8_t dhandle); +extern void hidh_process_repage_timer_timeout(void* data); extern void hidh_try_repage(uint8_t dhandle); /****************************************************************************** * Main Control Block ******************************************************************************/ -extern tHID_HOST_CTB hh_cb; +extern tHID_HOST_CTB hh_cb; #ifdef __cplusplus } diff --git a/stack/include/avct_api.h b/stack/include/avct_api.h index 0d914b977..62a2af4ad 100644 --- a/stack/include/avct_api.h +++ b/stack/include/avct_api.h @@ -25,8 +25,8 @@ #ifndef AVCT_API_H #define AVCT_API_H -#include "bt_types.h" #include "bt_target.h" +#include "bt_types.h" #ifdef __cplusplus extern "C" { @@ -37,90 +37,89 @@ extern "C" { ****************************************************************************/ /* API function return value result codes. */ -#define AVCT_SUCCESS 0 /* Function successful */ -#define AVCT_NO_RESOURCES 1 /* Not enough resources */ -#define AVCT_BAD_HANDLE 2 /* Bad handle */ -#define AVCT_PID_IN_USE 3 /* PID already in use */ -#define AVCT_NOT_OPEN 4 /* Connection not open */ +#define AVCT_SUCCESS 0 /* Function successful */ +#define AVCT_NO_RESOURCES 1 /* Not enough resources */ +#define AVCT_BAD_HANDLE 2 /* Bad handle */ +#define AVCT_PID_IN_USE 3 /* PID already in use */ +#define AVCT_NOT_OPEN 4 /* Connection not open */ /* PSM for AVCT. */ -#define AVCT_PSM 0x0017 -#define AVCT_BR_PSM 0x001B +#define AVCT_PSM 0x0017 +#define AVCT_BR_PSM 0x001B /* Protocol revision numbers */ -#define AVCT_REV_1_0 0x0100 -#define AVCT_REV_1_2 0x0102 -#define AVCT_REV_1_3 0x0103 -#define AVCT_REV_1_4 0x0104 +#define AVCT_REV_1_0 0x0100 +#define AVCT_REV_1_2 0x0102 +#define AVCT_REV_1_3 0x0103 +#define AVCT_REV_1_4 0x0104 /* the layer_specific settings */ -#define AVCT_DATA_CTRL 0x0001 /* for the control channel */ -#define AVCT_DATA_BROWSE 0x0002 /* for the browsing channel */ -#define AVCT_DATA_PARTIAL 0x0100 /* Only have room for a partial message */ +#define AVCT_DATA_CTRL 0x0001 /* for the control channel */ +#define AVCT_DATA_BROWSE 0x0002 /* for the browsing channel */ +#define AVCT_DATA_PARTIAL 0x0100 /* Only have room for a partial message */ /* Per the AVRC spec, minimum MTU for the control channel */ -#define AVCT_MIN_CONTROL_MTU 48 +#define AVCT_MIN_CONTROL_MTU 48 /* Per the AVRC spec, minimum MTU for the browsing channel */ -#define AVCT_MIN_BROWSE_MTU 335 +#define AVCT_MIN_BROWSE_MTU 335 /* Message offset. The number of bytes needed by the protocol stack for the * protocol headers of an AVCTP message packet. */ -#define AVCT_MSG_OFFSET 15 -#define AVCT_BROWSE_OFFSET 17 /* the default offset for browsing channel */ +#define AVCT_MSG_OFFSET 15 +#define AVCT_BROWSE_OFFSET 17 /* the default offset for browsing channel */ /* Connection role. */ -#define AVCT_INT 0 /* Initiator connection */ -#define AVCT_ACP 1 /* Acceptor connection */ +#define AVCT_INT 0 /* Initiator connection */ +#define AVCT_ACP 1 /* Acceptor connection */ /* Control role. */ -#define AVCT_TARGET 1 /* target */ -#define AVCT_CONTROL 2 /* controller */ -#define AVCT_PASSIVE 4 /* If conflict, allow the other side to succeed */ +#define AVCT_TARGET 1 /* target */ +#define AVCT_CONTROL 2 /* controller */ +#define AVCT_PASSIVE 4 /* If conflict, allow the other side to succeed */ /* Command/Response indicator. */ -#define AVCT_CMD 0 /* Command message */ -#define AVCT_RSP 2 /* Response message */ -#define AVCT_REJ 3 /* Message rejected */ +#define AVCT_CMD 0 /* Command message */ +#define AVCT_RSP 2 /* Response message */ +#define AVCT_REJ 3 /* Message rejected */ /* Control callback events. */ -#define AVCT_CONNECT_CFM_EVT 0 /* Connection confirm */ -#define AVCT_CONNECT_IND_EVT 1 /* Connection indication */ -#define AVCT_DISCONNECT_CFM_EVT 2 /* Disconnect confirm */ -#define AVCT_DISCONNECT_IND_EVT 3 /* Disconnect indication */ -#define AVCT_CONG_IND_EVT 4 /* Congestion indication */ -#define AVCT_UNCONG_IND_EVT 5 /* Uncongestion indication */ -#define AVCT_BROWSE_CONN_CFM_EVT 6 /* Browse Connection confirm */ -#define AVCT_BROWSE_CONN_IND_EVT 7 /* Browse Connection indication */ -#define AVCT_BROWSE_DISCONN_CFM_EVT 8 /* Browse Disconnect confirm */ -#define AVCT_BROWSE_DISCONN_IND_EVT 9 /* Browse Disconnect indication */ -#define AVCT_BROWSE_CONG_IND_EVT 10 /* Congestion indication */ -#define AVCT_BROWSE_UNCONG_IND_EVT 11 /* Uncongestion indication */ - +#define AVCT_CONNECT_CFM_EVT 0 /* Connection confirm */ +#define AVCT_CONNECT_IND_EVT 1 /* Connection indication */ +#define AVCT_DISCONNECT_CFM_EVT 2 /* Disconnect confirm */ +#define AVCT_DISCONNECT_IND_EVT 3 /* Disconnect indication */ +#define AVCT_CONG_IND_EVT 4 /* Congestion indication */ +#define AVCT_UNCONG_IND_EVT 5 /* Uncongestion indication */ +#define AVCT_BROWSE_CONN_CFM_EVT 6 /* Browse Connection confirm */ +#define AVCT_BROWSE_CONN_IND_EVT 7 /* Browse Connection indication */ +#define AVCT_BROWSE_DISCONN_CFM_EVT 8 /* Browse Disconnect confirm */ +#define AVCT_BROWSE_DISCONN_IND_EVT 9 /* Browse Disconnect indication */ +#define AVCT_BROWSE_CONG_IND_EVT 10 /* Congestion indication */ +#define AVCT_BROWSE_UNCONG_IND_EVT 11 /* Uncongestion indication */ /* General purpose failure result code for callback events. */ -#define AVCT_RESULT_FAIL 5 +#define AVCT_RESULT_FAIL 5 /***************************************************************************** * Type Definitions ****************************************************************************/ /* Control callback function. */ -typedef void (tAVCT_CTRL_CBACK)(uint8_t handle, uint8_t event, uint16_t result, - BD_ADDR peer_addr); +typedef void(tAVCT_CTRL_CBACK)(uint8_t handle, uint8_t event, uint16_t result, + BD_ADDR peer_addr); /* Message callback function */ /* p_pkt->layer_specific is AVCT_DATA_CTRL or AVCT_DATA_BROWSE */ -typedef void (tAVCT_MSG_CBACK)(uint8_t handle, uint8_t label, uint8_t cr, - BT_HDR *p_pkt); +typedef void(tAVCT_MSG_CBACK)(uint8_t handle, uint8_t label, uint8_t cr, + BT_HDR* p_pkt); /* Structure used by AVCT_CreateConn. */ typedef struct { - tAVCT_CTRL_CBACK *p_ctrl_cback; /* Control callback */ - tAVCT_MSG_CBACK *p_msg_cback; /* Message callback */ - uint16_t pid; /* Profile ID */ - uint8_t role; /* Initiator/acceptor role */ - uint8_t control; /* Control role (Control/Target) */ + tAVCT_CTRL_CBACK* p_ctrl_cback; /* Control callback */ + tAVCT_MSG_CBACK* p_msg_cback; /* Message callback */ + uint16_t pid; /* Profile ID */ + uint8_t role; /* Initiator/acceptor role */ + uint8_t control; /* Control role (Control/Target) */ } tAVCT_CC; /***************************************************************************** @@ -176,8 +175,8 @@ extern void AVCT_Deregister(void); * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVCT_CreateConn(uint8_t *p_handle, tAVCT_CC *p_cc, - BD_ADDR peer_addr); +extern uint16_t AVCT_CreateConn(uint8_t* p_handle, tAVCT_CC* p_cc, + BD_ADDR peer_addr); /******************************************************************************* * @@ -238,7 +237,7 @@ extern uint16_t AVCT_RemoveBrowse(uint8_t handle); * Returns the peer browsing channel MTU. * ******************************************************************************/ -extern uint16_t AVCT_GetBrowseMtu (uint8_t handle); +extern uint16_t AVCT_GetBrowseMtu(uint8_t handle); /******************************************************************************* * @@ -250,7 +249,7 @@ extern uint16_t AVCT_GetBrowseMtu (uint8_t handle); * Returns the peer MTU size. * ******************************************************************************/ -extern uint16_t AVCT_GetPeerMtu (uint8_t handle); +extern uint16_t AVCT_GetPeerMtu(uint8_t handle); /******************************************************************************* * @@ -275,11 +274,11 @@ extern uint16_t AVCT_GetPeerMtu (uint8_t handle); * Returns AVCT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVCT_MsgReq(uint8_t handle, uint8_t label, uint8_t cr, BT_HDR *p_msg); +extern uint16_t AVCT_MsgReq(uint8_t handle, uint8_t label, uint8_t cr, + BT_HDR* p_msg); #ifdef __cplusplus } #endif - #endif /* AVCT_API_H */ diff --git a/stack/include/avdt_api.h b/stack/include/avdt_api.h index 34755f9a0..def0ecdab 100644 --- a/stack/include/avdt_api.h +++ b/stack/include/avdt_api.h @@ -25,8 +25,8 @@ #ifndef AVDT_API_H #define AVDT_API_H -#include "bt_types.h" #include "bt_target.h" +#include "bt_types.h" #ifdef __cplusplus extern "C" { @@ -36,114 +36,114 @@ extern "C" { * Constants ****************************************************************************/ #ifndef AVDT_VERSION -#define AVDT_VERSION 0x0102 +#define AVDT_VERSION 0x0102 #endif -#define AVDT_VERSION_SYNC 0x0103 +#define AVDT_VERSION_SYNC 0x0103 /* Maximum size in bytes of the codec capabilities information element. */ -#define AVDT_CODEC_SIZE 20 +#define AVDT_CODEC_SIZE 20 /* API function return value result codes. */ -#define AVDT_SUCCESS 0 /* Function successful */ -#define AVDT_BAD_PARAMS 1 /* Invalid parameters */ -#define AVDT_NO_RESOURCES 2 /* Not enough resources */ -#define AVDT_BAD_HANDLE 3 /* Bad handle */ -#define AVDT_BUSY 4 /* A procedure is already in progress */ -#define AVDT_WRITE_FAIL 5 /* Write failed */ +#define AVDT_SUCCESS 0 /* Function successful */ +#define AVDT_BAD_PARAMS 1 /* Invalid parameters */ +#define AVDT_NO_RESOURCES 2 /* Not enough resources */ +#define AVDT_BAD_HANDLE 3 /* Bad handle */ +#define AVDT_BUSY 4 /* A procedure is already in progress */ +#define AVDT_WRITE_FAIL 5 /* Write failed */ /* The index to access the codec type in codec_info[]. */ -#define AVDT_CODEC_TYPE_INDEX 2 +#define AVDT_CODEC_TYPE_INDEX 2 /* The size in bytes of a Adaptation Layer header. */ -#define AVDT_AL_HDR_SIZE 3 +#define AVDT_AL_HDR_SIZE 3 /* The size in bytes of a media packet header. */ -#define AVDT_MEDIA_HDR_SIZE 12 +#define AVDT_MEDIA_HDR_SIZE 12 /* The handle is used when reporting MULTI_AV specific events */ -#define AVDT_MULTI_AV_HANDLE 0xFF +#define AVDT_MULTI_AV_HANDLE 0xFF /* The number of bytes needed by the protocol stack for the protocol headers * of a media packet. This is the size of the media packet header, the * L2CAP packet header and HCI header. */ -#define AVDT_MEDIA_OFFSET 23 +#define AVDT_MEDIA_OFFSET 23 /* The marker bit is used by the application to mark significant events such * as frame boundaries in the data stream. This constant is used to check or * set the marker bit in the m_pt parameter of an AVDT_WriteReq() * or AVDT_DATA_IND_EVT. */ -#define AVDT_MARKER_SET 0x80 +#define AVDT_MARKER_SET 0x80 /* SEP Type. This indicates the stream endpoint type. */ -#define AVDT_TSEP_SRC 0 /* Source SEP */ -#define AVDT_TSEP_SNK 1 /* Sink SEP */ -#define AVDT_TSEP_INVALID 3 /* Invalid SEP */ +#define AVDT_TSEP_SRC 0 /* Source SEP */ +#define AVDT_TSEP_SNK 1 /* Sink SEP */ +#define AVDT_TSEP_INVALID 3 /* Invalid SEP */ /* initiator/acceptor role for adaption */ -#define AVDT_INT 0 /* initiator */ -#define AVDT_ACP 1 /* acceptor */ +#define AVDT_INT 0 /* initiator */ +#define AVDT_ACP 1 /* acceptor */ /* Media Type of the stream endpoint */ /* The value does not include the reserved 4-bit LSBs field */ -#define AVDT_MEDIA_TYPE_AUDIO 0 /* Audio SEP */ -#define AVDT_MEDIA_TYPE_VIDEO 1 /* Video SEP */ -#define AVDT_MEDIA_TYPE_MULTI 2 /* Multimedia SEP */ +#define AVDT_MEDIA_TYPE_AUDIO 0 /* Audio SEP */ +#define AVDT_MEDIA_TYPE_VIDEO 1 /* Video SEP */ +#define AVDT_MEDIA_TYPE_MULTI 2 /* Multimedia SEP */ /* for reporting packets (packet types) */ -#define AVDT_RTCP_PT_SR 200 /* SR (Sender Report) */ -#define AVDT_RTCP_PT_RR 201 /* RR (Receiver Report) */ -#define AVDT_RTCP_PT_SDES 202 /* SDES (Source Description) */ +#define AVDT_RTCP_PT_SR 200 /* SR (Sender Report) */ +#define AVDT_RTCP_PT_RR 201 /* RR (Receiver Report) */ +#define AVDT_RTCP_PT_SDES 202 /* SDES (Source Description) */ typedef uint8_t AVDT_REPORT_TYPE; -#define AVDT_RTCP_SDES_CNAME 1 /* SDES item CNAME */ +#define AVDT_RTCP_SDES_CNAME 1 /* SDES item CNAME */ #ifndef AVDT_MAX_CNAME_SIZE -#define AVDT_MAX_CNAME_SIZE 28 +#define AVDT_MAX_CNAME_SIZE 28 #endif /* Protocol service capabilities. This indicates the protocol service * capabilities of a stream endpoint. This value is a mask. * Multiple values can be combined with a bitwise OR. */ -#define AVDT_PSC_TRANS (1<<1) /* Media transport */ -#define AVDT_PSC_REPORT (1<<2) /* Reporting */ -#define AVDT_PSC_RECOV (1<<3) /* Recovery */ -#define AVDT_PSC_HDRCMP (1<<5) /* Header compression */ -#define AVDT_PSC_MUX (1<<6) /* Multiplexing */ -#define AVDT_PSC_DELAY_RPT (1<<8) /* Delay Report */ +#define AVDT_PSC_TRANS (1 << 1) /* Media transport */ +#define AVDT_PSC_REPORT (1 << 2) /* Reporting */ +#define AVDT_PSC_RECOV (1 << 3) /* Recovery */ +#define AVDT_PSC_HDRCMP (1 << 5) /* Header compression */ +#define AVDT_PSC_MUX (1 << 6) /* Multiplexing */ +#define AVDT_PSC_DELAY_RPT (1 << 8) /* Delay Report */ /* Recovery type. This indicates the recovery type. */ -#define AVDT_RECOV_RFC2733 1 /* RFC2733 recovery */ +#define AVDT_RECOV_RFC2733 1 /* RFC2733 recovery */ /* Header compression capabilities. This indicates the header compression * capabilities. This value is a mask. Multiple values can be combined * with a bitwise OR. */ -#define AVDT_HDRCMP_MEDIA (1<<5) /* Available for media packets */ -#define AVDT_HDRCMP_RECOV (1<<6) /* Available for recovery packets */ -#define AVDT_HDRCMP_BACKCH (1<<7) /* Back channel supported */ +#define AVDT_HDRCMP_MEDIA (1 << 5) /* Available for media packets */ +#define AVDT_HDRCMP_RECOV (1 << 6) /* Available for recovery packets */ +#define AVDT_HDRCMP_BACKCH (1 << 7) /* Back channel supported */ /* Multiplexing capabilities mask. */ -#define AVDT_MUX_FRAG (1<<7) /* Allow Adaptation Layer Fragmentation */ +#define AVDT_MUX_FRAG (1 << 7) /* Allow Adaptation Layer Fragmentation */ /* Application service category. This indicates the application * service category. */ -#define AVDT_ASC_PROTECT 4 /* Content protection */ -#define AVDT_ASC_CODEC 7 /* Codec */ +#define AVDT_ASC_PROTECT 4 /* Content protection */ +#define AVDT_ASC_CODEC 7 /* Codec */ /* the content protection IDs assigned by BT SIG */ -#define AVDT_CP_SCMS_T_ID 0x0002 -#define AVDT_CP_DTCP_ID 0x0001 +#define AVDT_CP_SCMS_T_ID 0x0002 +#define AVDT_CP_DTCP_ID 0x0001 -#define AVDT_CP_LOSC 2 -#define AVDT_CP_INFO_LEN 3 +#define AVDT_CP_LOSC 2 +#define AVDT_CP_INFO_LEN 3 -#define AVDT_CP_SCMS_COPY_MASK 3 -#define AVDT_CP_SCMS_COPY_FREE 2 -#define AVDT_CP_SCMS_COPY_ONCE 1 -#define AVDT_CP_SCMS_COPY_NEVER 0 +#define AVDT_CP_SCMS_COPY_MASK 3 +#define AVDT_CP_SCMS_COPY_FREE 2 +#define AVDT_CP_SCMS_COPY_ONCE 1 +#define AVDT_CP_SCMS_COPY_NEVER 0 /* Error codes. The following are error codes defined in the AVDTP and GAVDP * specifications. These error codes communicate protocol errors between @@ -153,235 +153,234 @@ typedef uint8_t AVDT_REPORT_TYPE; * AVDTP API functions. */ /* Bad packet header format */ -#define AVDT_ERR_HEADER 0x01 +#define AVDT_ERR_HEADER 0x01 /* Bad packet length */ -#define AVDT_ERR_LENGTH 0x11 +#define AVDT_ERR_LENGTH 0x11 /* Invalid SEID */ -#define AVDT_ERR_SEID 0x12 +#define AVDT_ERR_SEID 0x12 /* The SEP is in use */ -#define AVDT_ERR_IN_USE 0x13 +#define AVDT_ERR_IN_USE 0x13 /* The SEP is not in use */ -#define AVDT_ERR_NOT_IN_USE 0x14 +#define AVDT_ERR_NOT_IN_USE 0x14 /* Bad service category */ -#define AVDT_ERR_CATEGORY 0x17 +#define AVDT_ERR_CATEGORY 0x17 /* Bad payload format */ -#define AVDT_ERR_PAYLOAD 0x18 +#define AVDT_ERR_PAYLOAD 0x18 /* Requested command not supported */ -#define AVDT_ERR_NSC 0x19 +#define AVDT_ERR_NSC 0x19 /* Reconfigure attempted invalid capabilities */ -#define AVDT_ERR_INVALID_CAP 0x1A +#define AVDT_ERR_INVALID_CAP 0x1A /* Requested recovery type not defined */ -#define AVDT_ERR_RECOV_TYPE 0x22 +#define AVDT_ERR_RECOV_TYPE 0x22 /* Media transport capability not correct */ -#define AVDT_ERR_MEDIA_TRANS 0x23 +#define AVDT_ERR_MEDIA_TRANS 0x23 /* Recovery service capability not correct */ -#define AVDT_ERR_RECOV_FMT 0x25 +#define AVDT_ERR_RECOV_FMT 0x25 /* Header compression service capability not correct */ -#define AVDT_ERR_ROHC_FMT 0x26 +#define AVDT_ERR_ROHC_FMT 0x26 /* Content protection service capability not correct */ -#define AVDT_ERR_CP_FMT 0x27 +#define AVDT_ERR_CP_FMT 0x27 /* Multiplexing service capability not correct */ -#define AVDT_ERR_MUX_FMT 0x28 +#define AVDT_ERR_MUX_FMT 0x28 /* Configuration not supported */ -#define AVDT_ERR_UNSUP_CFG 0x29 +#define AVDT_ERR_UNSUP_CFG 0x29 /* Message cannot be processed in this state */ -#define AVDT_ERR_BAD_STATE 0x31 +#define AVDT_ERR_BAD_STATE 0x31 /* Report service capability not correct */ -#define AVDT_ERR_REPORT_FMT 0x65 +#define AVDT_ERR_REPORT_FMT 0x65 /* Invalid service category */ -#define AVDT_ERR_SERVICE 0x80 +#define AVDT_ERR_SERVICE 0x80 /* Insufficient resources */ -#define AVDT_ERR_RESOURCE 0x81 +#define AVDT_ERR_RESOURCE 0x81 /* Invalid Media Codec Type */ -#define AVDT_ERR_INVALID_MCT 0xC1 +#define AVDT_ERR_INVALID_MCT 0xC1 /* Unsupported Media Codec Type */ -#define AVDT_ERR_UNSUP_MCT 0xC2 +#define AVDT_ERR_UNSUP_MCT 0xC2 /* Invalid Level */ -#define AVDT_ERR_INVALID_LEVEL 0xC3 +#define AVDT_ERR_INVALID_LEVEL 0xC3 /* Unsupported Level */ -#define AVDT_ERR_UNSUP_LEVEL 0xC4 +#define AVDT_ERR_UNSUP_LEVEL 0xC4 /* Invalid Content Protection Type */ -#define AVDT_ERR_INVALID_CP 0xE0 +#define AVDT_ERR_INVALID_CP 0xE0 /* Invalid Content Protection format */ -#define AVDT_ERR_INVALID_FORMAT 0xE1 +#define AVDT_ERR_INVALID_FORMAT 0xE1 /* Additional error codes. This indicates error codes used by AVDTP * in addition to the ones defined in the specifications. */ -#define AVDT_ERR_CONNECT 0x07 /* Connection failed. */ -#define AVDT_ERR_TIMEOUT 0x08 /* Response timeout. */ +#define AVDT_ERR_CONNECT 0x07 /* Connection failed. */ +#define AVDT_ERR_TIMEOUT 0x08 /* Response timeout. */ /* Control callback events. */ -#define AVDT_DISCOVER_CFM_EVT 0 /* Discover confirm */ -#define AVDT_GETCAP_CFM_EVT 1 /* Get capabilities confirm */ -#define AVDT_OPEN_CFM_EVT 2 /* Open confirm */ -#define AVDT_OPEN_IND_EVT 3 /* Open indication */ -#define AVDT_CONFIG_IND_EVT 4 /* Configuration indication */ -#define AVDT_START_CFM_EVT 5 /* Start confirm */ -#define AVDT_START_IND_EVT 6 /* Start indication */ -#define AVDT_SUSPEND_CFM_EVT 7 /* Suspend confirm */ -#define AVDT_SUSPEND_IND_EVT 8 /* Suspend indication */ -#define AVDT_CLOSE_CFM_EVT 9 /* Close confirm */ -#define AVDT_CLOSE_IND_EVT 10 /* Close indication */ -#define AVDT_RECONFIG_CFM_EVT 11 /* Reconfiguration confirm */ -#define AVDT_RECONFIG_IND_EVT 12 /* Reconfiguration indication */ -#define AVDT_SECURITY_CFM_EVT 13 /* Security confirm */ -#define AVDT_SECURITY_IND_EVT 14 /* Security indication */ -#define AVDT_WRITE_CFM_EVT 15 /* Write confirm */ -#define AVDT_CONNECT_IND_EVT 16 /* Signaling channel connected */ -#define AVDT_DISCONNECT_IND_EVT 17 /* Signaling channel disconnected */ -#define AVDT_REPORT_CONN_EVT 18 /* Reporting channel connected */ -#define AVDT_REPORT_DISCONN_EVT 19 /* Reporting channel disconnected */ -#define AVDT_DELAY_REPORT_EVT 20 /* Delay report received */ -#define AVDT_DELAY_REPORT_CFM_EVT 21 /* Delay report response received */ - -#define AVDT_MAX_EVT (AVDT_DELAY_REPORT_CFM_EVT) +#define AVDT_DISCOVER_CFM_EVT 0 /* Discover confirm */ +#define AVDT_GETCAP_CFM_EVT 1 /* Get capabilities confirm */ +#define AVDT_OPEN_CFM_EVT 2 /* Open confirm */ +#define AVDT_OPEN_IND_EVT 3 /* Open indication */ +#define AVDT_CONFIG_IND_EVT 4 /* Configuration indication */ +#define AVDT_START_CFM_EVT 5 /* Start confirm */ +#define AVDT_START_IND_EVT 6 /* Start indication */ +#define AVDT_SUSPEND_CFM_EVT 7 /* Suspend confirm */ +#define AVDT_SUSPEND_IND_EVT 8 /* Suspend indication */ +#define AVDT_CLOSE_CFM_EVT 9 /* Close confirm */ +#define AVDT_CLOSE_IND_EVT 10 /* Close indication */ +#define AVDT_RECONFIG_CFM_EVT 11 /* Reconfiguration confirm */ +#define AVDT_RECONFIG_IND_EVT 12 /* Reconfiguration indication */ +#define AVDT_SECURITY_CFM_EVT 13 /* Security confirm */ +#define AVDT_SECURITY_IND_EVT 14 /* Security indication */ +#define AVDT_WRITE_CFM_EVT 15 /* Write confirm */ +#define AVDT_CONNECT_IND_EVT 16 /* Signaling channel connected */ +#define AVDT_DISCONNECT_IND_EVT 17 /* Signaling channel disconnected */ +#define AVDT_REPORT_CONN_EVT 18 /* Reporting channel connected */ +#define AVDT_REPORT_DISCONN_EVT 19 /* Reporting channel disconnected */ +#define AVDT_DELAY_REPORT_EVT 20 /* Delay report received */ +#define AVDT_DELAY_REPORT_CFM_EVT 21 /* Delay report response received */ + +#define AVDT_MAX_EVT (AVDT_DELAY_REPORT_CFM_EVT) /* PSM for AVDT */ -#define AVDT_PSM 0x0019 +#define AVDT_PSM 0x0019 /* Nonsupported protocol command messages. This value is used in tAVDT_CS */ -#define AVDT_NSC_SUSPEND 0x01 /* Suspend command not supported */ -#define AVDT_NSC_RECONFIG 0x02 /* Reconfigure command not supported */ -#define AVDT_NSC_SECURITY 0x04 /* Security command not supported */ +#define AVDT_NSC_SUSPEND 0x01 /* Suspend command not supported */ +#define AVDT_NSC_RECONFIG 0x02 /* Reconfigure command not supported */ +#define AVDT_NSC_SECURITY 0x04 /* Security command not supported */ /***************************************************************************** * Type Definitions ****************************************************************************/ -typedef struct -{ - uint32_t ntp_sec; /* NTP time: seconds relative to 0h UTC on 1 January 1900 */ - uint32_t ntp_frac; /* NTP time: the fractional part */ - uint32_t rtp_time; /* timestamp in RTP header */ - uint32_t pkt_count; /* sender's packet count: since starting transmission - * up until the time this SR packet was generated. */ - uint32_t octet_count; /* sender's octet count: same comment */ +typedef struct { + uint32_t ntp_sec; /* NTP time: seconds relative to 0h UTC on 1 January 1900 */ + uint32_t ntp_frac; /* NTP time: the fractional part */ + uint32_t rtp_time; /* timestamp in RTP header */ + uint32_t pkt_count; /* sender's packet count: since starting transmission + * up until the time this SR packet was generated. */ + uint32_t octet_count; /* sender's octet count: same comment */ } tAVDT_SENDER_INFO; -typedef struct -{ - uint8_t frag_lost; /* fraction lost since last RR */ - uint32_t packet_lost; /* cumulative number of packets lost since the beginning */ - uint32_t seq_num_rcvd; /* extended highest sequence number received */ - uint32_t jitter; /* interarrival jitter */ - uint32_t lsr; /* last SR timestamp */ - uint32_t dlsr; /* delay since last SR */ +typedef struct { + uint8_t frag_lost; /* fraction lost since last RR */ + uint32_t + packet_lost; /* cumulative number of packets lost since the beginning */ + uint32_t seq_num_rcvd; /* extended highest sequence number received */ + uint32_t jitter; /* interarrival jitter */ + uint32_t lsr; /* last SR timestamp */ + uint32_t dlsr; /* delay since last SR */ } tAVDT_REPORT_BLK; -typedef union -{ - tAVDT_SENDER_INFO sr; - tAVDT_REPORT_BLK rr; - uint8_t cname[AVDT_MAX_CNAME_SIZE + 1]; +typedef union { + tAVDT_SENDER_INFO sr; + tAVDT_REPORT_BLK rr; + uint8_t cname[AVDT_MAX_CNAME_SIZE + 1]; } tAVDT_REPORT_DATA; /* This structure contains parameters which are set at registration. */ typedef struct { - uint16_t ctrl_mtu; /* L2CAP MTU of the AVDTP signaling channel */ - uint8_t ret_tout; /* AVDTP signaling retransmission timeout */ - uint8_t sig_tout; /* AVDTP signaling message timeout */ - uint8_t idle_tout; /* AVDTP idle signaling channel timeout */ - uint8_t sec_mask; /* Security mask for BTM_SetSecurityLevel() */ + uint16_t ctrl_mtu; /* L2CAP MTU of the AVDTP signaling channel */ + uint8_t ret_tout; /* AVDTP signaling retransmission timeout */ + uint8_t sig_tout; /* AVDTP signaling message timeout */ + uint8_t idle_tout; /* AVDTP idle signaling channel timeout */ + uint8_t sec_mask; /* Security mask for BTM_SetSecurityLevel() */ } tAVDT_REG; /* This structure contains the SEP information. This information is * transferred during the discovery procedure. */ typedef struct { - bool in_use; /* true if stream is currently in use */ - uint8_t seid; /* Stream endpoint identifier */ - uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */ - uint8_t tsep; /* SEP type */ + bool in_use; /* true if stream is currently in use */ + uint8_t seid; /* Stream endpoint identifier */ + uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */ + uint8_t tsep; /* SEP type */ } tAVDT_SEP_INFO; /* This structure contains the SEP configuration. */ typedef struct { - uint8_t codec_info[AVDT_CODEC_SIZE]; /* Codec capabilities array */ - uint8_t protect_info[AVDT_PROTECT_SIZE]; /* Content protection capabilities */ - uint8_t num_codec; /* Number of media codec information elements */ - uint8_t num_protect; /* Number of content protection information elements */ - uint16_t psc_mask; /* Protocol service capabilities mask */ - uint8_t recov_type; /* Recovery type */ - uint8_t recov_mrws; /* Maximum recovery window size */ - uint8_t recov_mnmp; /* Recovery maximum number of media packets */ - uint8_t hdrcmp_mask; /* Header compression capabilities */ + uint8_t codec_info[AVDT_CODEC_SIZE]; /* Codec capabilities array */ + uint8_t protect_info[AVDT_PROTECT_SIZE]; /* Content protection capabilities */ + uint8_t num_codec; /* Number of media codec information elements */ + uint8_t num_protect; /* Number of content protection information elements */ + uint16_t psc_mask; /* Protocol service capabilities mask */ + uint8_t recov_type; /* Recovery type */ + uint8_t recov_mrws; /* Maximum recovery window size */ + uint8_t recov_mnmp; /* Recovery maximum number of media packets */ + uint8_t hdrcmp_mask; /* Header compression capabilities */ } tAVDT_CFG; /* Header structure for callback event parameters. */ typedef struct { - uint8_t err_code; /* Zero if operation succeeded; nonzero if operation failed */ - uint8_t err_param; /* Error parameter included for some events */ - uint8_t label; /* Transaction label */ - uint8_t seid; /* For internal use only */ - uint8_t sig_id; /* For internal use only */ - uint8_t ccb_idx; /* For internal use only */ + uint8_t + err_code; /* Zero if operation succeeded; nonzero if operation failed */ + uint8_t err_param; /* Error parameter included for some events */ + uint8_t label; /* Transaction label */ + uint8_t seid; /* For internal use only */ + uint8_t sig_id; /* For internal use only */ + uint8_t ccb_idx; /* For internal use only */ } tAVDT_EVT_HDR; /* This data structure is associated with the AVDT_GETCAP_CFM_EVT, * AVDT_RECONFIG_IND_EVT, and AVDT_RECONFIG_CFM_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - tAVDT_CFG *p_cfg; /* Pointer to configuration for this SEP */ + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_CFG* p_cfg; /* Pointer to configuration for this SEP */ } tAVDT_CONFIG; /* This data structure is associated with the AVDT_CONFIG_IND_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - tAVDT_CFG *p_cfg; /* Pointer to configuration for this SEP */ - uint8_t int_seid; /* Stream endpoint ID of stream initiating the operation */ + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_CFG* p_cfg; /* Pointer to configuration for this SEP */ + uint8_t int_seid; /* Stream endpoint ID of stream initiating the operation */ } tAVDT_SETCONFIG; /* This data structure is associated with the AVDT_OPEN_IND_EVT and * AVDT_OPEN_CFM_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - uint16_t peer_mtu; /* Transport channel L2CAP MTU of the peer */ - uint16_t lcid; /* L2CAP LCID for media channel */ + tAVDT_EVT_HDR hdr; /* Event header */ + uint16_t peer_mtu; /* Transport channel L2CAP MTU of the peer */ + uint16_t lcid; /* L2CAP LCID for media channel */ } tAVDT_OPEN; /* This data structure is associated with the AVDT_SECURITY_IND_EVT * and AVDT_SECURITY_CFM_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - uint8_t *p_data; /* Pointer to security data */ - uint16_t len; /* Length in bytes of the security data */ + tAVDT_EVT_HDR hdr; /* Event header */ + uint8_t* p_data; /* Pointer to security data */ + uint16_t len; /* Length in bytes of the security data */ } tAVDT_SECURITY; /* This data structure is associated with the AVDT_DISCOVER_CFM_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - tAVDT_SEP_INFO *p_sep_info; /* Pointer to SEP information */ - uint8_t num_seps; /* Number of stream endpoints */ + tAVDT_EVT_HDR hdr; /* Event header */ + tAVDT_SEP_INFO* p_sep_info; /* Pointer to SEP information */ + uint8_t num_seps; /* Number of stream endpoints */ } tAVDT_DISCOVER; /* This data structure is associated with the AVDT_DELAY_REPORT_EVT. */ typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - uint16_t delay; /* Delay value */ + tAVDT_EVT_HDR hdr; /* Event header */ + uint16_t delay; /* Delay value */ } tAVDT_DELAY_RPT; /* Union of all control callback event data structures */ typedef union { - tAVDT_EVT_HDR hdr; - tAVDT_DISCOVER discover_cfm; - tAVDT_CONFIG getcap_cfm; - tAVDT_OPEN open_cfm; - tAVDT_OPEN open_ind; - tAVDT_SETCONFIG config_ind; - tAVDT_EVT_HDR start_cfm; - tAVDT_EVT_HDR suspend_cfm; - tAVDT_EVT_HDR close_cfm; - tAVDT_CONFIG reconfig_cfm; - tAVDT_CONFIG reconfig_ind; - tAVDT_SECURITY security_cfm; - tAVDT_SECURITY security_ind; - tAVDT_EVT_HDR connect_ind; - tAVDT_EVT_HDR disconnect_ind; - tAVDT_EVT_HDR report_conn; - tAVDT_DELAY_RPT delay_rpt_cmd; + tAVDT_EVT_HDR hdr; + tAVDT_DISCOVER discover_cfm; + tAVDT_CONFIG getcap_cfm; + tAVDT_OPEN open_cfm; + tAVDT_OPEN open_ind; + tAVDT_SETCONFIG config_ind; + tAVDT_EVT_HDR start_cfm; + tAVDT_EVT_HDR suspend_cfm; + tAVDT_EVT_HDR close_cfm; + tAVDT_CONFIG reconfig_cfm; + tAVDT_CONFIG reconfig_ind; + tAVDT_SECURITY security_cfm; + tAVDT_SECURITY security_ind; + tAVDT_EVT_HDR connect_ind; + tAVDT_EVT_HDR disconnect_ind; + tAVDT_EVT_HDR report_conn; + tAVDT_DELAY_RPT delay_rpt_cmd; } tAVDT_CTRL; /* This is the control callback function. This function passes control events @@ -389,52 +388,51 @@ typedef union { * endpoints and for the AVDT_DiscoverReq() and AVDT_GetCapReq() functions. * */ -typedef void (tAVDT_CTRL_CBACK)(uint8_t handle, BD_ADDR bd_addr, uint8_t event, - tAVDT_CTRL *p_data); +typedef void(tAVDT_CTRL_CBACK)(uint8_t handle, BD_ADDR bd_addr, uint8_t event, + tAVDT_CTRL* p_data); /* This is the data callback function. It is executed when AVDTP has a media * packet ready for the application. This function is required for SNK * endpoints and not applicable for SRC endpoints. */ -typedef void (tAVDT_SINK_DATA_CBACK)(uint8_t handle, BT_HDR *p_pkt, - uint32_t time_stamp, uint8_t m_pt); +typedef void(tAVDT_SINK_DATA_CBACK)(uint8_t handle, BT_HDR* p_pkt, + uint32_t time_stamp, uint8_t m_pt); #if (AVDT_REPORTING == TRUE) /* This is the report callback function. It is executed when AVDTP has a * reporting packet ready for the application. This function is required for * streams created with AVDT_PSC_REPORT. */ -typedef void (tAVDT_REPORT_CBACK)(uint8_t handle, AVDT_REPORT_TYPE type, - tAVDT_REPORT_DATA *p_data); +typedef void(tAVDT_REPORT_CBACK)(uint8_t handle, AVDT_REPORT_TYPE type, + tAVDT_REPORT_DATA* p_data); #endif -typedef uint16_t (tAVDT_GETCAP_REQ) (BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, tAVDT_CTRL_CBACK *p_cback); +typedef uint16_t(tAVDT_GETCAP_REQ)(BD_ADDR bd_addr, uint8_t seid, + tAVDT_CFG* p_cfg, tAVDT_CTRL_CBACK* p_cback); /* This structure contains information required when a stream is created. * It is passed to the AVDT_CreateStream() function. */ typedef struct { - tAVDT_CFG cfg; /* SEP configuration */ - tAVDT_CTRL_CBACK *p_ctrl_cback; /* Control callback function */ - tAVDT_SINK_DATA_CBACK *p_sink_data_cback; /* Sink data callback function */ + tAVDT_CFG cfg; /* SEP configuration */ + tAVDT_CTRL_CBACK* p_ctrl_cback; /* Control callback function */ + tAVDT_SINK_DATA_CBACK* p_sink_data_cback; /* Sink data callback function */ #if (AVDT_REPORTING == TRUE) - tAVDT_REPORT_CBACK *p_report_cback;/* Report callback function. */ + tAVDT_REPORT_CBACK* p_report_cback; /* Report callback function. */ #endif - uint16_t mtu; /* The L2CAP MTU of the transport channel */ - uint16_t flush_to; /* The L2CAP flush timeout of the transport channel */ - uint8_t tsep; /* SEP type */ - uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */ - uint16_t nsc_mask; /* Nonsupported protocol command messages */ + uint16_t mtu; /* The L2CAP MTU of the transport channel */ + uint16_t flush_to; /* The L2CAP flush timeout of the transport channel */ + uint8_t tsep; /* SEP type */ + uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */ + uint16_t nsc_mask; /* Nonsupported protocol command messages */ } tAVDT_CS; /* AVDT data option mask is used in the write request */ -#define AVDT_DATA_OPT_NONE 0x00 /* No option still add RTP header */ -#define AVDT_DATA_OPT_NO_RTP (0x01 << 0) /* Skip adding RTP header */ +#define AVDT_DATA_OPT_NONE 0x00 /* No option still add RTP header */ +#define AVDT_DATA_OPT_NO_RTP (0x01 << 0) /* Skip adding RTP header */ typedef uint8_t tAVDT_DATA_OPT_MASK; - - /***************************************************************************** * External Function Declarations ****************************************************************************/ @@ -453,7 +451,7 @@ typedef uint8_t tAVDT_DATA_OPT_MASK; * Returns void * ******************************************************************************/ -extern void AVDT_Register(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback); +extern void AVDT_Register(tAVDT_REG* p_reg, tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -495,7 +493,7 @@ extern void AVDT_AbortReq(uint8_t handle); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_CreateStream(uint8_t *p_handle, tAVDT_CS *p_cs); +extern uint16_t AVDT_CreateStream(uint8_t* p_handle, tAVDT_CS* p_cs); /******************************************************************************* * @@ -539,9 +537,8 @@ extern uint16_t AVDT_RemoveStream(uint8_t handle); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info, - uint8_t max_seps, tAVDT_CTRL_CBACK *p_cback); - +extern uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO* p_sep_info, + uint8_t max_seps, tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -567,8 +564,8 @@ extern uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO *p_sep_info, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, - tAVDT_CTRL_CBACK *p_cback); +extern uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG* p_cfg, + tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -594,8 +591,8 @@ extern uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG *p_cfg, - tAVDT_CTRL_CBACK *p_cback); +extern uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid, + tAVDT_CFG* p_cfg, tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -625,8 +622,7 @@ extern uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay); * ******************************************************************************/ extern uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid, - tAVDT_CFG *p_cfg); - + tAVDT_CFG* p_cfg); /******************************************************************************* * @@ -640,8 +636,8 @@ extern uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, - uint8_t category); +extern uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, + uint8_t error_code, uint8_t category); /******************************************************************************* * @@ -658,7 +654,7 @@ extern uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_StartReq(uint8_t *p_handles, uint8_t num_handles); +extern uint16_t AVDT_StartReq(uint8_t* p_handles, uint8_t num_handles); /******************************************************************************* * @@ -675,7 +671,7 @@ extern uint16_t AVDT_StartReq(uint8_t *p_handles, uint8_t num_handles); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_SuspendReq(uint8_t *p_handles, uint8_t num_handles); +extern uint16_t AVDT_SuspendReq(uint8_t* p_handles, uint8_t num_handles); /******************************************************************************* * @@ -710,7 +706,7 @@ extern uint16_t AVDT_CloseReq(uint8_t handle); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG *p_cfg); +extern uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG* p_cfg); /******************************************************************************* * @@ -724,8 +720,8 @@ extern uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG *p_cfg); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_code, - uint8_t category); +extern uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, + uint8_t error_code, uint8_t category); /******************************************************************************* * @@ -741,7 +737,7 @@ extern uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_co * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t *p_data, uint16_t len); +extern uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t* p_data, uint16_t len); /******************************************************************************* * @@ -757,8 +753,9 @@ extern uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t *p_data, uint16_t len); * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_code, - uint8_t *p_data, uint16_t len); +extern uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, + uint8_t error_code, uint8_t* p_data, + uint16_t len); /******************************************************************************* * @@ -794,8 +791,8 @@ extern uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_co * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, - uint8_t m_pt); +extern uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR* p_pkt, + uint32_t time_stamp, uint8_t m_pt); /******************************************************************************* * * Function AVDT_WriteReqOpt @@ -832,8 +829,9 @@ extern uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR *p_pkt, uint32_t time_stamp, - uint8_t m_pt, tAVDT_DATA_OPT_MASK opt); +extern uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt, + uint32_t time_stamp, uint8_t m_pt, + tAVDT_DATA_OPT_MASK opt); /******************************************************************************* * @@ -851,7 +849,7 @@ extern uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR *p_pkt, uint32_t time_st * ******************************************************************************/ extern uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask, - tAVDT_CTRL_CBACK *p_cback); + tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -865,7 +863,7 @@ extern uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask, * Returns AVDT_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK *p_cback); +extern uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -902,7 +900,7 @@ extern uint16_t AVDT_GetSignalChannel(uint8_t handle, BD_ADDR bd_addr); * ******************************************************************************/ extern uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type, - tAVDT_REPORT_DATA *p_data); + tAVDT_REPORT_DATA* p_data); /****************************************************************************** * @@ -925,11 +923,10 @@ extern uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type, * the input parameter is 0xff. * *****************************************************************************/ -extern uint8_t AVDT_SetTraceLevel (uint8_t new_level); +extern uint8_t AVDT_SetTraceLevel(uint8_t new_level); #ifdef __cplusplus } #endif - #endif /* AVDT_API_H */ diff --git a/stack/include/avdtc_api.h b/stack/include/avdtc_api.h index c8c3bb691..4748b44fa 100644 --- a/stack/include/avdtc_api.h +++ b/stack/include/avdtc_api.h @@ -34,46 +34,47 @@ extern "C" { #endif /* start AVDTC events here to distinguish from AVDT events */ -#define AVDTC_EVT_BEGIN 0x80 +#define AVDTC_EVT_BEGIN 0x80 /* Discover indication */ -#define AVDTC_DISCOVER_IND_EVT (0 + AVDTC_EVT_BEGIN) +#define AVDTC_DISCOVER_IND_EVT (0 + AVDTC_EVT_BEGIN) /* Get capabilities indication */ -#define AVDTC_GETCAP_IND_EVT (1 + AVDTC_EVT_BEGIN) +#define AVDTC_GETCAP_IND_EVT (1 + AVDTC_EVT_BEGIN) /* Set configuration confirm */ -#define AVDTC_SETCONFIG_CFM_EVT (2 + AVDTC_EVT_BEGIN) +#define AVDTC_SETCONFIG_CFM_EVT (2 + AVDTC_EVT_BEGIN) /* Get configuration indication */ -#define AVDTC_GETCONFIG_IND_EVT (3 + AVDTC_EVT_BEGIN) +#define AVDTC_GETCONFIG_IND_EVT (3 + AVDTC_EVT_BEGIN) /* Get configuration confirm */ -#define AVDTC_GETCONFIG_CFM_EVT (4 + AVDTC_EVT_BEGIN) +#define AVDTC_GETCONFIG_CFM_EVT (4 + AVDTC_EVT_BEGIN) /* Open indication */ -#define AVDTC_OPEN_IND_EVT (5 + AVDTC_EVT_BEGIN) +#define AVDTC_OPEN_IND_EVT (5 + AVDTC_EVT_BEGIN) /* Start indication */ -#define AVDTC_START_IND_EVT (6 + AVDTC_EVT_BEGIN) +#define AVDTC_START_IND_EVT (6 + AVDTC_EVT_BEGIN) /* Close indication */ -#define AVDTC_CLOSE_IND_EVT (7 + AVDTC_EVT_BEGIN) +#define AVDTC_CLOSE_IND_EVT (7 + AVDTC_EVT_BEGIN) /* Suspend indication */ -#define AVDTC_SUSPEND_IND_EVT (8 + AVDTC_EVT_BEGIN) +#define AVDTC_SUSPEND_IND_EVT (8 + AVDTC_EVT_BEGIN) /* Abort indication */ -#define AVDTC_ABORT_IND_EVT (9 + AVDTC_EVT_BEGIN) +#define AVDTC_ABORT_IND_EVT (9 + AVDTC_EVT_BEGIN) /* Abort confirm */ -#define AVDTC_ABORT_CFM_EVT (10 + AVDTC_EVT_BEGIN) +#define AVDTC_ABORT_CFM_EVT (10 + AVDTC_EVT_BEGIN) typedef struct { - tAVDT_EVT_HDR hdr; /* Event header */ - uint8_t seid_list[AVDT_NUM_SEPS]; /* Array of SEID values */ - uint8_t num_seps; /* Number of values in array */ + tAVDT_EVT_HDR hdr; /* Event header */ + uint8_t seid_list[AVDT_NUM_SEPS]; /* Array of SEID values */ + uint8_t num_seps; /* Number of values in array */ } tAVDT_MULTI; /* Union of all control callback event data structures */ typedef union { - tAVDT_EVT_HDR hdr; - tAVDT_CONFIG getconfig_cfm; - tAVDT_MULTI start_ind; - tAVDT_MULTI suspend_ind; + tAVDT_EVT_HDR hdr; + tAVDT_CONFIG getconfig_cfm; + tAVDT_MULTI start_ind; + tAVDT_MULTI suspend_ind; } tAVDTC_CTRL; -typedef void tAVDTC_CTRL_CBACK(uint8_t handle, BD_ADDR bd_addr, uint8_t event, tAVDTC_CTRL *p_data); +typedef void tAVDTC_CTRL_CBACK(uint8_t handle, BD_ADDR bd_addr, uint8_t event, + tAVDTC_CTRL* p_data); /******************************************************************************* * @@ -86,7 +87,7 @@ typedef void tAVDTC_CTRL_CBACK(uint8_t handle, BD_ADDR bd_addr, uint8_t event, t * Returns void * ******************************************************************************/ -extern void AVDTC_Init(tAVDTC_CTRL_CBACK *p_cback); +extern void AVDTC_Init(tAVDTC_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -109,7 +110,7 @@ extern void AVDTC_DiscoverRsp(BD_ADDR bd_addr, uint8_t label, * Returns void * ******************************************************************************/ -extern void AVDTC_GetCapRsp(BD_ADDR bd_addr, uint8_t label, tAVDT_CFG *p_cap); +extern void AVDTC_GetCapRsp(BD_ADDR bd_addr, uint8_t label, tAVDT_CFG* p_cap); /******************************************************************************* * @@ -120,7 +121,8 @@ extern void AVDTC_GetCapRsp(BD_ADDR bd_addr, uint8_t label, tAVDT_CFG *p_cap); * Returns void * ******************************************************************************/ -extern void AVDTC_GetAllCapRsp(BD_ADDR bd_addr, uint8_t label, tAVDT_CFG *p_cap); +extern void AVDTC_GetAllCapRsp(BD_ADDR bd_addr, uint8_t label, + tAVDT_CFG* p_cap); /******************************************************************************* * @@ -142,7 +144,7 @@ extern void AVDTC_GetConfigReq(uint8_t handle); * Returns void * ******************************************************************************/ -extern void AVDTC_GetConfigRsp(uint8_t handle, uint8_t label, tAVDT_CFG *p_cfg); +extern void AVDTC_GetConfigRsp(uint8_t handle, uint8_t label, tAVDT_CFG* p_cfg); /******************************************************************************* * @@ -175,7 +177,8 @@ extern void AVDTC_OpenRsp(uint8_t handle, uint8_t label); * Returns void * ******************************************************************************/ -extern void AVDTC_StartRsp(uint8_t *p_handles, uint8_t num_handles, uint8_t label); +extern void AVDTC_StartRsp(uint8_t* p_handles, uint8_t num_handles, + uint8_t label); /******************************************************************************* * @@ -197,7 +200,8 @@ extern void AVDTC_CloseRsp(uint8_t handle, uint8_t label); * Returns void * ******************************************************************************/ -extern void AVDTC_SuspendRsp(uint8_t *p_handles, uint8_t num_handles, uint8_t label); +extern void AVDTC_SuspendRsp(uint8_t* p_handles, uint8_t num_handles, + uint8_t label); /******************************************************************************* * @@ -230,8 +234,8 @@ extern void AVDTC_AbortRsp(uint8_t handle, uint8_t label); * Returns void * ******************************************************************************/ -extern void AVDTC_Rej(uint8_t handle, BD_ADDR bd_addr, uint8_t cmd, uint8_t label, - uint8_t err_code, uint8_t err_param); +extern void AVDTC_Rej(uint8_t handle, BD_ADDR bd_addr, uint8_t cmd, + uint8_t label, uint8_t err_code, uint8_t err_param); #ifdef __cplusplus } diff --git a/stack/include/avrc_api.h b/stack/include/avrc_api.h index 14af632bc..9e72a5661 100644 --- a/stack/include/avrc_api.h +++ b/stack/include/avrc_api.h @@ -23,10 +23,10 @@ ******************************************************************************/ #ifndef AVRC_API_H #define AVRC_API_H -#include "bt_target.h" #include "avct_api.h" -#include "sdp_api.h" #include "avrc_defs.h" +#include "bt_target.h" +#include "sdp_api.h" #ifdef __cplusplus extern "C" { @@ -38,110 +38,108 @@ extern "C" { /* API function return value result codes. */ /* 0 Function successful */ -#define AVRC_SUCCESS AVCT_SUCCESS +#define AVRC_SUCCESS AVCT_SUCCESS /* 1 Not enough resources */ -#define AVRC_NO_RESOURCES AVCT_NO_RESOURCES +#define AVRC_NO_RESOURCES AVCT_NO_RESOURCES /* 2 Bad handle */ -#define AVRC_BAD_HANDLE AVCT_BAD_HANDLE +#define AVRC_BAD_HANDLE AVCT_BAD_HANDLE /* 3 PID already in use */ -#define AVRC_PID_IN_USE AVCT_PID_IN_USE +#define AVRC_PID_IN_USE AVCT_PID_IN_USE /* 4 Connection not open */ -#define AVRC_NOT_OPEN AVCT_NOT_OPEN +#define AVRC_NOT_OPEN AVCT_NOT_OPEN /* 5 the message length exceed the MTU of the browsing channel */ -#define AVRC_MSG_TOO_BIG 5 +#define AVRC_MSG_TOO_BIG 5 /* 0x10 generic failure */ -#define AVRC_FAIL 0x10 +#define AVRC_FAIL 0x10 /* 0x11 bad parameter */ -#define AVRC_BAD_PARAM 0x11 +#define AVRC_BAD_PARAM 0x11 /* Control role - same as AVCT_TARGET/AVCT_CONTROL */ /* target */ -#define AVRC_CT_TARGET 1 +#define AVRC_CT_TARGET 1 /* controller */ -#define AVRC_CT_CONTROL 2 +#define AVRC_CT_CONTROL 2 /* If conflict, allow the other side to succeed */ -#define AVRC_CT_PASSIVE 4 +#define AVRC_CT_PASSIVE 4 /* Connection role */ /* initiator */ -#define AVRC_CONN_INT AVCT_INT +#define AVRC_CONN_INT AVCT_INT /* Acceptor */ -#define AVRC_CONN_ACP AVCT_ACP - +#define AVRC_CONN_ACP AVCT_ACP /* AVRC CTRL events */ /* AVRC_OPEN_IND_EVT event is sent when the connection is successfully opened. * This eventis sent in response to an AVRC_Open(). */ -#define AVRC_OPEN_IND_EVT 0 +#define AVRC_OPEN_IND_EVT 0 /* AVRC_CLOSE_IND_EVT event is sent when a connection is closed. * This event can result from a call to AVRC_Close() or when the peer closes * the connection. It is also sent when a connection attempted through * AVRC_Open() fails. */ -#define AVRC_CLOSE_IND_EVT 1 +#define AVRC_CLOSE_IND_EVT 1 /* AVRC_CONG_IND_EVT event indicates that AVCTP is congested and cannot send * any more messages. */ -#define AVRC_CONG_IND_EVT 2 +#define AVRC_CONG_IND_EVT 2 /* AVRC_UNCONG_IND_EVT event indicates that AVCTP is uncongested and ready to * send messages. */ -#define AVRC_UNCONG_IND_EVT 3 +#define AVRC_UNCONG_IND_EVT 3 - /* AVRC_BROWSE_OPEN_IND_EVT event is sent when the browse channel is successfully opened. - * This eventis sent in response to an AVRC_Open() or AVRC_OpenBrowse() . */ -#define AVRC_BROWSE_OPEN_IND_EVT 4 +/* AVRC_BROWSE_OPEN_IND_EVT event is sent when the browse channel is +* successfully opened. +* This eventis sent in response to an AVRC_Open() or AVRC_OpenBrowse() . */ +#define AVRC_BROWSE_OPEN_IND_EVT 4 /* AVRC_BROWSE_CLOSE_IND_EVT event is sent when a browse channel is closed. * This event can result from a call to AVRC_Close(), AVRC_CloseBrowse() or * when the peer closes the connection. It is also sent when a connection * attempted through AVRC_OpenBrowse() fails. */ -#define AVRC_BROWSE_CLOSE_IND_EVT 5 +#define AVRC_BROWSE_CLOSE_IND_EVT 5 /* AVRC_BROWSE_CONG_IND_EVT event indicates that AVCTP browse channel is * congested and cannot send any more messages. */ -#define AVRC_BROWSE_CONG_IND_EVT 6 +#define AVRC_BROWSE_CONG_IND_EVT 6 /* AVRC_BROWSE_UNCONG_IND_EVT event indicates that AVCTP browse channel is * uncongested and ready to send messages. */ -#define AVRC_BROWSE_UNCONG_IND_EVT 7 +#define AVRC_BROWSE_UNCONG_IND_EVT 7 /* AVRC_CMD_TIMEOUT_EVT event indicates timeout waiting for AVRC command * response from the peer */ -#define AVRC_CMD_TIMEOUT_EVT 8 +#define AVRC_CMD_TIMEOUT_EVT 8 /* Supported categories */ -#define AVRC_SUPF_CT_CAT1 0x0001 /* Category 1 */ -#define AVRC_SUPF_CT_CAT2 0x0002 /* Category 2 */ -#define AVRC_SUPF_CT_CAT3 0x0004 /* Category 3 */ -#define AVRC_SUPF_CT_CAT4 0x0008 /* Category 4 */ -#define AVRC_SUPF_CT_APP_SETTINGS 0x0010 /* Player Application Settings */ -#define AVRC_SUPF_CT_GROUP_NAVI 0x0020 /* Group Navigation */ -#define AVRC_SUPF_CT_BROWSE 0x0040 /* Browsing */ +#define AVRC_SUPF_CT_CAT1 0x0001 /* Category 1 */ +#define AVRC_SUPF_CT_CAT2 0x0002 /* Category 2 */ +#define AVRC_SUPF_CT_CAT3 0x0004 /* Category 3 */ +#define AVRC_SUPF_CT_CAT4 0x0008 /* Category 4 */ +#define AVRC_SUPF_CT_APP_SETTINGS 0x0010 /* Player Application Settings */ +#define AVRC_SUPF_CT_GROUP_NAVI 0x0020 /* Group Navigation */ +#define AVRC_SUPF_CT_BROWSE 0x0040 /* Browsing */ /* Cover Art, get image property */ -#define AVRC_SUPF_CT_COVER_ART_GET_IMAGE_PROP 0x0080 +#define AVRC_SUPF_CT_COVER_ART_GET_IMAGE_PROP 0x0080 /* Cover Art, get image */ -#define AVRC_SUPF_CT_COVER_ART_GET_IMAGE 0x0100 +#define AVRC_SUPF_CT_COVER_ART_GET_IMAGE 0x0100 /* Cover Art, get Linked Thumbnail */ -#define AVRC_SUPF_CT_COVER_ART_GET_THUMBNAIL 0x0200 - -#define AVRC_SUPF_TG_CAT1 0x0001 /* Category 1 */ -#define AVRC_SUPF_TG_CAT2 0x0002 /* Category 2 */ -#define AVRC_SUPF_TG_CAT3 0x0004 /* Category 3 */ -#define AVRC_SUPF_TG_CAT4 0x0008 /* Category 4 */ -#define AVRC_SUPF_TG_APP_SETTINGS 0x0010 /* Player Application Settings */ -#define AVRC_SUPF_TG_GROUP_NAVI 0x0020 /* Group Navigation */ -#define AVRC_SUPF_TG_BROWSE 0x0040 /* Browsing */ -#define AVRC_SUPF_TG_MULTI_PLAYER 0x0080 /* Muliple Media Player */ -#define AVRC_SUPF_TG_PLAYER_COVER_ART 0x0100 /* Cover Art */ - -#define AVRC_META_SUCCESS AVRC_SUCCESS -#define AVRC_META_FAIL AVRC_FAIL -#define AVRC_METADATA_CMD 0x0000 -#define AVRC_METADATA_RESP 0x0001 - - +#define AVRC_SUPF_CT_COVER_ART_GET_THUMBNAIL 0x0200 + +#define AVRC_SUPF_TG_CAT1 0x0001 /* Category 1 */ +#define AVRC_SUPF_TG_CAT2 0x0002 /* Category 2 */ +#define AVRC_SUPF_TG_CAT3 0x0004 /* Category 3 */ +#define AVRC_SUPF_TG_CAT4 0x0008 /* Category 4 */ +#define AVRC_SUPF_TG_APP_SETTINGS 0x0010 /* Player Application Settings */ +#define AVRC_SUPF_TG_GROUP_NAVI 0x0020 /* Group Navigation */ +#define AVRC_SUPF_TG_BROWSE 0x0040 /* Browsing */ +#define AVRC_SUPF_TG_MULTI_PLAYER 0x0080 /* Muliple Media Player */ +#define AVRC_SUPF_TG_PLAYER_COVER_ART 0x0100 /* Cover Art */ + +#define AVRC_META_SUCCESS AVRC_SUCCESS +#define AVRC_META_FAIL AVRC_FAIL +#define AVRC_METADATA_CMD 0x0000 +#define AVRC_METADATA_RESP 0x0001 /***************************************************************************** * data type definitions @@ -149,15 +147,17 @@ extern "C" { /* This data type is used in AVRC_FindService() to initialize the SDP database * to hold the result service search. */ -typedef struct -{ - uint32_t db_len; /* Length, in bytes, of the discovery database */ - tSDP_DISCOVERY_DB *p_db; /* Pointer to the discovery database */ - uint16_t num_attr;/* The number of attributes in p_attrs */ - uint16_t *p_attrs; /* The attributes filter. If NULL, AVRCP API sets the attribute filter - * to be ATTR_ID_SERVICE_CLASS_ID_LIST, ATTR_ID_BT_PROFILE_DESC_LIST, - * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and ATTR_ID_PROVIDER_NAME. - * If not NULL, the input is taken as the filter. */ +typedef struct { + uint32_t db_len; /* Length, in bytes, of the discovery database */ + tSDP_DISCOVERY_DB* p_db; /* Pointer to the discovery database */ + uint16_t num_attr; /* The number of attributes in p_attrs */ + uint16_t* p_attrs; /* The attributes filter. If NULL, AVRCP API sets the + * attribute filter + * to be ATTR_ID_SERVICE_CLASS_ID_LIST, + * ATTR_ID_BT_PROFILE_DESC_LIST, + * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and + * ATTR_ID_PROVIDER_NAME. + * If not NULL, the input is taken as the filter. */ } tAVRC_SDP_DB_PARAMS; /* This callback function returns service discovery information to the @@ -165,38 +165,34 @@ typedef struct * implementation of this callback function must copy the p_service_name * and p_provider_name parameters passed to it as they are not guaranteed * to remain after the callback function exits. */ -typedef void (tAVRC_FIND_CBACK) (uint16_t status); - +typedef void(tAVRC_FIND_CBACK)(uint16_t status); /* This is the control callback function. This function passes events * listed in Table 20 to the application. */ -typedef void (tAVRC_CTRL_CBACK) (uint8_t handle, uint8_t event, uint16_t result, - BD_ADDR peer_addr); - +typedef void(tAVRC_CTRL_CBACK)(uint8_t handle, uint8_t event, uint16_t result, + BD_ADDR peer_addr); /* This is the message callback function. It is executed when AVCTP has * a message packet ready for the application. The implementation of this * callback function must copy the tAVRC_MSG structure passed to it as it * is not guaranteed to remain after the callback function exits. */ -typedef void (tAVRC_MSG_CBACK) (uint8_t handle, uint8_t label, uint8_t opcode, - tAVRC_MSG *p_msg); - -typedef struct -{ - tAVRC_CTRL_CBACK *p_ctrl_cback; /* pointer to application control callback */ - tAVRC_MSG_CBACK *p_msg_cback; /* pointer to application message callback */ - uint32_t company_id; /* the company ID */ - uint8_t conn; /* Connection role (Initiator/acceptor) */ - uint8_t control; /* Control role (Control/Target) */ +typedef void(tAVRC_MSG_CBACK)(uint8_t handle, uint8_t label, uint8_t opcode, + tAVRC_MSG* p_msg); + +typedef struct { + tAVRC_CTRL_CBACK* p_ctrl_cback; /* pointer to application control callback */ + tAVRC_MSG_CBACK* p_msg_cback; /* pointer to application message callback */ + uint32_t company_id; /* the company ID */ + uint8_t conn; /* Connection role (Initiator/acceptor) */ + uint8_t control; /* Control role (Control/Target) */ } tAVRC_CONN_CB; typedef struct { - uint8_t handle; - uint8_t label; - uint8_t msg_mask; + uint8_t handle; + uint8_t label; + uint8_t msg_mask; } tAVRC_PARAM; - /***************************************************************************** * external function declarations ****************************************************************************/ @@ -235,10 +231,9 @@ typedef struct { * *****************************************************************************/ extern uint16_t AVRC_AddRecord(uint16_t service_uuid, - const char *p_service_name, - const char *p_provider_name, - uint16_t categories, uint32_t sdp_handle, - bool browse_supported, + const char* p_service_name, + const char* p_provider_name, uint16_t categories, + uint32_t sdp_handle, bool browse_supported, uint16_t profile_version); /****************************************************************************** @@ -281,7 +276,8 @@ extern uint16_t AVRC_AddRecord(uint16_t service_uuid, * *****************************************************************************/ extern uint16_t AVRC_FindService(uint16_t service_uuid, BD_ADDR bd_addr, - tAVRC_SDP_DB_PARAMS *p_db, tAVRC_FIND_CBACK *p_cback); + tAVRC_SDP_DB_PARAMS* p_db, + tAVRC_FIND_CBACK* p_cback); /****************************************************************************** * @@ -331,8 +327,8 @@ extern uint16_t AVRC_FindService(uint16_t service_uuid, BD_ADDR bd_addr, * the connection. * *****************************************************************************/ -extern uint16_t AVRC_Open(uint8_t *p_handle, tAVRC_CONN_CB *p_ccb, - BD_ADDR_PTR peer_addr); +extern uint16_t AVRC_Open(uint8_t* p_handle, tAVRC_CONN_CB* p_ccb, + BD_ADDR_PTR peer_addr); /****************************************************************************** * @@ -403,7 +399,8 @@ extern uint16_t AVRC_CloseBrowse(uint8_t handle); * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -extern uint16_t AVRC_MsgReq (uint8_t handle, uint8_t label, uint8_t ctype, BT_HDR *p_pkt); +extern uint16_t AVRC_MsgReq(uint8_t handle, uint8_t label, uint8_t ctype, + BT_HDR* p_pkt); /****************************************************************************** * @@ -455,7 +452,6 @@ extern uint16_t AVRC_UnitCmd(uint8_t handle, uint8_t label); *****************************************************************************/ extern uint16_t AVRC_SubCmd(uint8_t handle, uint8_t label, uint8_t page); - /****************************************************************************** * * Function AVRC_PassCmd @@ -479,7 +475,8 @@ extern uint16_t AVRC_SubCmd(uint8_t handle, uint8_t label, uint8_t page); * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -extern uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_msg); +extern uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, + tAVRC_MSG_PASS* p_msg); /****************************************************************************** * @@ -507,8 +504,8 @@ extern uint16_t AVRC_PassCmd(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_ms * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -extern uint16_t AVRC_PassRsp(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_msg); - +extern uint16_t AVRC_PassRsp(uint8_t handle, uint8_t label, + tAVRC_MSG_PASS* p_msg); /****************************************************************************** * @@ -533,8 +530,8 @@ extern uint16_t AVRC_PassRsp(uint8_t handle, uint8_t label, tAVRC_MSG_PASS *p_ms * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -extern uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR *p_msg); - +extern uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, + tAVRC_MSG_VENDOR* p_msg); /****************************************************************************** * @@ -562,8 +559,8 @@ extern uint16_t AVRC_VendorCmd(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR * * AVRC_BAD_HANDLE if handle is invalid. * *****************************************************************************/ -extern uint16_t AVRC_VendorRsp(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR *p_msg); - +extern uint16_t AVRC_VendorRsp(uint8_t handle, uint8_t label, + tAVRC_MSG_VENDOR* p_msg); /****************************************************************************** * @@ -586,7 +583,7 @@ extern uint16_t AVRC_VendorRsp(uint8_t handle, uint8_t label, tAVRC_MSG_VENDOR * * the input parameter is 0xff. * *****************************************************************************/ -extern uint8_t AVRC_SetTraceLevel (uint8_t new_level); +extern uint8_t AVRC_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -614,7 +611,8 @@ extern void AVRC_Init(void); * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -extern tAVRC_STS AVRC_Ctrl_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result); +extern tAVRC_STS AVRC_Ctrl_ParsCommand(tAVRC_MSG* p_msg, + tAVRC_COMMAND* p_result); /******************************************************************************* * @@ -627,8 +625,8 @@ extern tAVRC_STS AVRC_Ctrl_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_resul * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -extern tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, - uint8_t *p_buf, uint16_t buf_len); +extern tAVRC_STS AVRC_ParsCommand(tAVRC_MSG* p_msg, tAVRC_COMMAND* p_result, + uint8_t* p_buf, uint16_t buf_len); /******************************************************************************* * @@ -641,8 +639,8 @@ extern tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -extern tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, - uint8_t *p_buf, uint16_t buf_len); +extern tAVRC_STS AVRC_ParsResponse(tAVRC_MSG* p_msg, tAVRC_RESPONSE* p_result, + uint8_t* p_buf, uint16_t buf_len); /******************************************************************************* * @@ -655,8 +653,9 @@ extern tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, * Otherwise, the error code defined by AVRCP 1.4 * ******************************************************************************/ -extern tAVRC_STS AVRC_Ctrl_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, - uint8_t *p_buf, uint16_t* buf_len); +extern tAVRC_STS AVRC_Ctrl_ParsResponse(tAVRC_MSG* p_msg, + tAVRC_RESPONSE* p_result, + uint8_t* p_buf, uint16_t* buf_len); /******************************************************************************* * @@ -669,7 +668,7 @@ extern tAVRC_STS AVRC_Ctrl_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_res * Otherwise, the error code. * ******************************************************************************/ -extern tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt); +extern tAVRC_STS AVRC_BldCommand(tAVRC_COMMAND* p_cmd, BT_HDR** pp_pkt); /******************************************************************************* * @@ -682,7 +681,8 @@ extern tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt); * Otherwise, the error code. * ******************************************************************************/ -extern tAVRC_STS AVRC_BldResponse( uint8_t handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt); +extern tAVRC_STS AVRC_BldResponse(uint8_t handle, tAVRC_RESPONSE* p_rsp, + BT_HDR** pp_pkt); /************************************************************************** * @@ -694,7 +694,7 @@ extern tAVRC_STS AVRC_BldResponse( uint8_t handle, tAVRC_RESPONSE *p_rsp, BT_HDR * * ******************************************************************************/ -extern bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type); +extern bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type); /******************************************************************************* * @@ -706,7 +706,7 @@ extern bool AVRC_IsValidAvcType(uint8_t pdu_id, uint8_t avc_type); * Returns returns true if it is valid * ******************************************************************************/ -extern bool AVRC_IsValidPlayerAttr(uint8_t attr); +extern bool AVRC_IsValidPlayerAttr(uint8_t attr); #ifdef __cplusplus } diff --git a/stack/include/avrc_defs.h b/stack/include/avrc_defs.h index e4026ed24..9fe4397ba 100644 --- a/stack/include/avrc_defs.h +++ b/stack/include/avrc_defs.h @@ -31,152 +31,163 @@ ****************************************************************************/ /* Profile revision numbers */ -#define AVRC_REV_1_0 0x0100 -#define AVRC_REV_1_3 0x0103 -#define AVRC_REV_1_4 0x0104 -#define AVRC_REV_1_5 0x0105 -#define AVRC_REV_1_6 0x0106 +#define AVRC_REV_1_0 0x0100 +#define AVRC_REV_1_3 0x0103 +#define AVRC_REV_1_4 0x0104 +#define AVRC_REV_1_5 0x0105 +#define AVRC_REV_1_6 0x0106 /* defines from the spec */ -#define AVRC_PACKET_LEN 512 /* You must support 512 byte RC packets */ +#define AVRC_PACKET_LEN 512 /* You must support 512 byte RC packets */ -#define AVRC_MIN_CONTROL_MTU 48 /* Minimum MTU for the control channel */ -#define AVRC_MIN_BROWSE_MTU 335 /* Minimum MTU for the browsing channel */ +#define AVRC_MIN_CONTROL_MTU 48 /* Minimum MTU for the control channel */ +#define AVRC_MIN_BROWSE_MTU 335 /* Minimum MTU for the browsing channel */ -#define AVRC_META_PDU_OFFSET 4 -#define AVRC_SUB_TYPE_LEN 4 -#define AVRC_UID_SIZE 8 -#define AVRC_FEATURE_MASK_SIZE 16 +#define AVRC_META_PDU_OFFSET 4 +#define AVRC_SUB_TYPE_LEN 4 +#define AVRC_UID_SIZE 8 +#define AVRC_FEATURE_MASK_SIZE 16 /* command type codes */ -#define AVRC_CMD_CTRL 0 /* Instruct a target to perform an operation */ -#define AVRC_CMD_STATUS 1 /* Check a device's current status */ -#define AVRC_CMD_SPEC_INQ 2 /* Check whether a target supports a particular - control command; all operands are included */ -#define AVRC_CMD_NOTIF 3 /* Notification of a change in a device's state */ -#define AVRC_CMD_GEN_INQ 4 /* Check whether a target supports a particular - control command; operands are not included */ +#define AVRC_CMD_CTRL 0 /* Instruct a target to perform an operation */ +#define AVRC_CMD_STATUS 1 /* Check a device's current status */ +#define AVRC_CMD_SPEC_INQ \ + 2 /* Check whether a target supports a particular \ + control command; all operands are included */ +#define AVRC_CMD_NOTIF 3 /* Notification of a change in a device's state */ +#define AVRC_CMD_GEN_INQ \ + 4 /* Check whether a target supports a particular \ + control command; operands are not included */ /* response type codes */ -#define AVRC_RSP_NOT_IMPL 8 /* The target does not implement the command specified - by the opcode and operand, - or doesn't implement the specified subunit */ -#define AVRC_RSP_ACCEPT 9 /* The target executed or is executing the command */ -#define AVRC_RSP_REJ 10 /* The target implements the command specified by the - opcode but cannot respond because the current state - of the target doesn't allow it */ -#define AVRC_RSP_IN_TRANS 11 /* The target implements the status command but it is - in a state of transition; the status command may - be retried at a future time */ -#define AVRC_RSP_IMPL_STBL 12 /* For specific inquiry or general inquiy commands, - the target implements the command; for status - commands, the target returns stable and includes - the status results */ -#define AVRC_RSP_CHANGED 13 /* The response frame contains a notification that the - target device's state has changed */ -#define AVRC_RSP_INTERIM 15 /* For control commands, the target has accepted the - request but cannot return information within 100 - milliseconds; for notify commands, the target accepted - the command, and will notify the controller of a change - of target state at a future time */ +#define AVRC_RSP_NOT_IMPL \ + 8 /* The target does not implement the command specified \ + by the opcode and operand, \ + or doesn't implement the specified subunit */ +#define AVRC_RSP_ACCEPT \ + 9 /* The target executed or is executing the command \ + */ +#define AVRC_RSP_REJ \ + 10 /* The target implements the command specified by the \ + opcode but cannot respond because the current state \ + of the target doesn't allow it */ +#define AVRC_RSP_IN_TRANS \ + 11 /* The target implements the status command but it is \ + in a state of transition; the status command may \ + be retried at a future time */ +#define AVRC_RSP_IMPL_STBL \ + 12 /* For specific inquiry or general inquiy commands, \ + the target implements the command; for status \ + commands, the target returns stable and includes \ + the status results */ +#define AVRC_RSP_CHANGED \ + 13 /* The response frame contains a notification that the \ + target device's state has changed */ +#define AVRC_RSP_INTERIM \ + 15 /* For control commands, the target has accepted the \ + request but cannot return information within 100 \ + milliseconds; for notify commands, the target accepted \ + the command, and will notify the controller of a change \ + of target state at a future time */ /* subunit type */ -#define AVRC_SUB_MONITOR 0x00 /* Monitor */ -#define AVRC_SUB_AUDIO 0x01 /* Audio */ -#define AVRC_SUB_PRINTER 0x02 /* Printer */ -#define AVRC_SUB_DISC 0x03 /* Disc */ -#define AVRC_SUB_TAPE 0x04 /* Tape recorder/player */ -#define AVRC_SUB_TUNER 0x05 /* Tuner */ -#define AVRC_SUB_CA 0x06 /* CA */ -#define AVRC_SUB_CAMERA 0x07 /* Camera */ -#define AVRC_SUB_PANEL 0x09 /* Panel */ -#define AVRC_SUB_BB 0x0A /* Bulletin Board */ -#define AVRC_SUB_CAM_STOR 0x0B /* Camera Storage */ -#define AVRC_SUB_VENDOR 0x1C /* Vendor unique */ -#define AVRC_SUB_EXT 0x1E /* Subunit type extended to next byte */ -#define AVRC_SUB_UNIT 0x1F /* Unit */ +#define AVRC_SUB_MONITOR 0x00 /* Monitor */ +#define AVRC_SUB_AUDIO 0x01 /* Audio */ +#define AVRC_SUB_PRINTER 0x02 /* Printer */ +#define AVRC_SUB_DISC 0x03 /* Disc */ +#define AVRC_SUB_TAPE 0x04 /* Tape recorder/player */ +#define AVRC_SUB_TUNER 0x05 /* Tuner */ +#define AVRC_SUB_CA 0x06 /* CA */ +#define AVRC_SUB_CAMERA 0x07 /* Camera */ +#define AVRC_SUB_PANEL 0x09 /* Panel */ +#define AVRC_SUB_BB 0x0A /* Bulletin Board */ +#define AVRC_SUB_CAM_STOR 0x0B /* Camera Storage */ +#define AVRC_SUB_VENDOR 0x1C /* Vendor unique */ +#define AVRC_SUB_EXT 0x1E /* Subunit type extended to next byte */ +#define AVRC_SUB_UNIT 0x1F /* Unit */ /* opcodes - defined by 1394ta */ -#define AVRC_OP_UNIT_INFO 0x30 /* Report unit information */ -#define AVRC_OP_SUB_INFO 0x31 /* Report subunit information */ -#define AVRC_OP_VENDOR 0x00 /* Vendor-dependent commands */ -#define AVRC_OP_PASS_THRU 0x7C /* panel subunit opcode */ +#define AVRC_OP_UNIT_INFO 0x30 /* Report unit information */ +#define AVRC_OP_SUB_INFO 0x31 /* Report subunit information */ +#define AVRC_OP_VENDOR 0x00 /* Vendor-dependent commands */ +#define AVRC_OP_PASS_THRU 0x7C /* panel subunit opcode */ /* opcodes 80-9F and E0-FF are not used by 1394ta. Sneak one for browsing */ -#define AVRC_OP_BROWSE 0xFF /* Browsing */ -#define AVRC_OP_INVALID 0xFE /* invalid one */ +#define AVRC_OP_BROWSE 0xFF /* Browsing */ +#define AVRC_OP_INVALID 0xFE /* invalid one */ /* Company ID's */ -#define AVRC_CO_BLUETOOTH_SIG 0x00FFFFFF -#define AVRC_CO_WIDCOMM 0x00000361 -#define AVRC_CO_BROADCOM 0x00001018 -#define AVRC_CO_GOOGLE 0x00DAA119 -#define AVRC_CO_METADATA 0x00001958 /* Unique COMPANY ID for Metadata messages */ +#define AVRC_CO_BLUETOOTH_SIG 0x00FFFFFF +#define AVRC_CO_WIDCOMM 0x00000361 +#define AVRC_CO_BROADCOM 0x00001018 +#define AVRC_CO_GOOGLE 0x00DAA119 +#define AVRC_CO_METADATA \ + 0x00001958 /* Unique COMPANY ID for Metadata messages */ /* State flag for Passthrough commands */ -#define AVRC_STATE_PRESS 0 -#define AVRC_STATE_RELEASE 1 +#define AVRC_STATE_PRESS 0 +#define AVRC_STATE_RELEASE 1 /* Operation ID list for Passthrough commands */ -#define AVRC_ID_SELECT 0x00 /* select */ -#define AVRC_ID_UP 0x01 /* up */ -#define AVRC_ID_DOWN 0x02 /* down */ -#define AVRC_ID_LEFT 0x03 /* left */ -#define AVRC_ID_RIGHT 0x04 /* right */ -#define AVRC_ID_RIGHT_UP 0x05 /* right-up */ -#define AVRC_ID_RIGHT_DOWN 0x06 /* right-down */ -#define AVRC_ID_LEFT_UP 0x07 /* left-up */ -#define AVRC_ID_LEFT_DOWN 0x08 /* left-down */ -#define AVRC_ID_ROOT_MENU 0x09 /* root menu */ -#define AVRC_ID_SETUP_MENU 0x0A /* setup menu */ -#define AVRC_ID_CONT_MENU 0x0B /* contents menu */ -#define AVRC_ID_FAV_MENU 0x0C /* favorite menu */ -#define AVRC_ID_EXIT 0x0D /* exit */ -#define AVRC_ID_0 0x20 /* 0 */ -#define AVRC_ID_1 0x21 /* 1 */ -#define AVRC_ID_2 0x22 /* 2 */ -#define AVRC_ID_3 0x23 /* 3 */ -#define AVRC_ID_4 0x24 /* 4 */ -#define AVRC_ID_5 0x25 /* 5 */ -#define AVRC_ID_6 0x26 /* 6 */ -#define AVRC_ID_7 0x27 /* 7 */ -#define AVRC_ID_8 0x28 /* 8 */ -#define AVRC_ID_9 0x29 /* 9 */ -#define AVRC_ID_DOT 0x2A /* dot */ -#define AVRC_ID_ENTER 0x2B /* enter */ -#define AVRC_ID_CLEAR 0x2C /* clear */ -#define AVRC_ID_CHAN_UP 0x30 /* channel up */ -#define AVRC_ID_CHAN_DOWN 0x31 /* channel down */ -#define AVRC_ID_PREV_CHAN 0x32 /* previous channel */ -#define AVRC_ID_SOUND_SEL 0x33 /* sound select */ -#define AVRC_ID_INPUT_SEL 0x34 /* input select */ -#define AVRC_ID_DISP_INFO 0x35 /* display information */ -#define AVRC_ID_HELP 0x36 /* help */ -#define AVRC_ID_PAGE_UP 0x37 /* page up */ -#define AVRC_ID_PAGE_DOWN 0x38 /* page down */ -#define AVRC_ID_POWER 0x40 /* power */ -#define AVRC_ID_VOL_UP 0x41 /* volume up */ -#define AVRC_ID_VOL_DOWN 0x42 /* volume down */ -#define AVRC_ID_MUTE 0x43 /* mute */ -#define AVRC_ID_PLAY 0x44 /* play */ -#define AVRC_ID_STOP 0x45 /* stop */ -#define AVRC_ID_PAUSE 0x46 /* pause */ -#define AVRC_ID_RECORD 0x47 /* record */ -#define AVRC_ID_REWIND 0x48 /* rewind */ -#define AVRC_ID_FAST_FOR 0x49 /* fast forward */ -#define AVRC_ID_EJECT 0x4A /* eject */ -#define AVRC_ID_FORWARD 0x4B /* forward */ -#define AVRC_ID_BACKWARD 0x4C /* backward */ -#define AVRC_ID_ANGLE 0x50 /* angle */ -#define AVRC_ID_SUBPICT 0x51 /* subpicture */ -#define AVRC_ID_F1 0x71 /* F1 */ -#define AVRC_ID_F2 0x72 /* F2 */ -#define AVRC_ID_F3 0x73 /* F3 */ -#define AVRC_ID_F4 0x74 /* F4 */ -#define AVRC_ID_F5 0x75 /* F5 */ -#define AVRC_ID_VENDOR 0x7E /* vendor unique */ +#define AVRC_ID_SELECT 0x00 /* select */ +#define AVRC_ID_UP 0x01 /* up */ +#define AVRC_ID_DOWN 0x02 /* down */ +#define AVRC_ID_LEFT 0x03 /* left */ +#define AVRC_ID_RIGHT 0x04 /* right */ +#define AVRC_ID_RIGHT_UP 0x05 /* right-up */ +#define AVRC_ID_RIGHT_DOWN 0x06 /* right-down */ +#define AVRC_ID_LEFT_UP 0x07 /* left-up */ +#define AVRC_ID_LEFT_DOWN 0x08 /* left-down */ +#define AVRC_ID_ROOT_MENU 0x09 /* root menu */ +#define AVRC_ID_SETUP_MENU 0x0A /* setup menu */ +#define AVRC_ID_CONT_MENU 0x0B /* contents menu */ +#define AVRC_ID_FAV_MENU 0x0C /* favorite menu */ +#define AVRC_ID_EXIT 0x0D /* exit */ +#define AVRC_ID_0 0x20 /* 0 */ +#define AVRC_ID_1 0x21 /* 1 */ +#define AVRC_ID_2 0x22 /* 2 */ +#define AVRC_ID_3 0x23 /* 3 */ +#define AVRC_ID_4 0x24 /* 4 */ +#define AVRC_ID_5 0x25 /* 5 */ +#define AVRC_ID_6 0x26 /* 6 */ +#define AVRC_ID_7 0x27 /* 7 */ +#define AVRC_ID_8 0x28 /* 8 */ +#define AVRC_ID_9 0x29 /* 9 */ +#define AVRC_ID_DOT 0x2A /* dot */ +#define AVRC_ID_ENTER 0x2B /* enter */ +#define AVRC_ID_CLEAR 0x2C /* clear */ +#define AVRC_ID_CHAN_UP 0x30 /* channel up */ +#define AVRC_ID_CHAN_DOWN 0x31 /* channel down */ +#define AVRC_ID_PREV_CHAN 0x32 /* previous channel */ +#define AVRC_ID_SOUND_SEL 0x33 /* sound select */ +#define AVRC_ID_INPUT_SEL 0x34 /* input select */ +#define AVRC_ID_DISP_INFO 0x35 /* display information */ +#define AVRC_ID_HELP 0x36 /* help */ +#define AVRC_ID_PAGE_UP 0x37 /* page up */ +#define AVRC_ID_PAGE_DOWN 0x38 /* page down */ +#define AVRC_ID_POWER 0x40 /* power */ +#define AVRC_ID_VOL_UP 0x41 /* volume up */ +#define AVRC_ID_VOL_DOWN 0x42 /* volume down */ +#define AVRC_ID_MUTE 0x43 /* mute */ +#define AVRC_ID_PLAY 0x44 /* play */ +#define AVRC_ID_STOP 0x45 /* stop */ +#define AVRC_ID_PAUSE 0x46 /* pause */ +#define AVRC_ID_RECORD 0x47 /* record */ +#define AVRC_ID_REWIND 0x48 /* rewind */ +#define AVRC_ID_FAST_FOR 0x49 /* fast forward */ +#define AVRC_ID_EJECT 0x4A /* eject */ +#define AVRC_ID_FORWARD 0x4B /* forward */ +#define AVRC_ID_BACKWARD 0x4C /* backward */ +#define AVRC_ID_ANGLE 0x50 /* angle */ +#define AVRC_ID_SUBPICT 0x51 /* subpicture */ +#define AVRC_ID_F1 0x71 /* F1 */ +#define AVRC_ID_F2 0x72 /* F2 */ +#define AVRC_ID_F3 0x73 /* F3 */ +#define AVRC_ID_F4 0x74 /* F4 */ +#define AVRC_ID_F5 0x75 /* F5 */ +#define AVRC_ID_VENDOR 0x7E /* vendor unique */ #define AVRC_KEYPRESSED_RELEASE 0x80 /***************************************************************************** @@ -185,109 +196,109 @@ /* Define the Metadata Packet types */ -#define AVRC_PKT_SINGLE 0 -#define AVRC_PKT_START 1 -#define AVRC_PKT_CONTINUE 2 -#define AVRC_PKT_END 3 -#define AVRC_PKT_TYPE_MASK 3 +#define AVRC_PKT_SINGLE 0 +#define AVRC_PKT_START 1 +#define AVRC_PKT_CONTINUE 2 +#define AVRC_PKT_END 3 +#define AVRC_PKT_TYPE_MASK 3 /* Define the PDUs carried in the vendor dependant data */ -#define AVRC_PDU_GET_CAPABILITIES 0x10 -#define AVRC_PDU_LIST_PLAYER_APP_ATTR 0x11 -#define AVRC_PDU_LIST_PLAYER_APP_VALUES 0x12 -#define AVRC_PDU_GET_CUR_PLAYER_APP_VALUE 0x13 -#define AVRC_PDU_SET_PLAYER_APP_VALUE 0x14 -#define AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT 0x15 -#define AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT 0x16 -#define AVRC_PDU_INFORM_DISPLAY_CHARSET 0x17 -#define AVRC_PDU_INFORM_BATTERY_STAT_OF_CT 0x18 -#define AVRC_PDU_GET_ELEMENT_ATTR 0x20 -#define AVRC_PDU_GET_PLAY_STATUS 0x30 -#define AVRC_PDU_REGISTER_NOTIFICATION 0x31 -#define AVRC_PDU_REQUEST_CONTINUATION_RSP 0x40 -#define AVRC_PDU_ABORT_CONTINUATION_RSP 0x41 +#define AVRC_PDU_GET_CAPABILITIES 0x10 +#define AVRC_PDU_LIST_PLAYER_APP_ATTR 0x11 +#define AVRC_PDU_LIST_PLAYER_APP_VALUES 0x12 +#define AVRC_PDU_GET_CUR_PLAYER_APP_VALUE 0x13 +#define AVRC_PDU_SET_PLAYER_APP_VALUE 0x14 +#define AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT 0x15 +#define AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT 0x16 +#define AVRC_PDU_INFORM_DISPLAY_CHARSET 0x17 +#define AVRC_PDU_INFORM_BATTERY_STAT_OF_CT 0x18 +#define AVRC_PDU_GET_ELEMENT_ATTR 0x20 +#define AVRC_PDU_GET_PLAY_STATUS 0x30 +#define AVRC_PDU_REGISTER_NOTIFICATION 0x31 +#define AVRC_PDU_REQUEST_CONTINUATION_RSP 0x40 +#define AVRC_PDU_ABORT_CONTINUATION_RSP 0x41 /* added in 1.4 */ -#define AVRC_PDU_SET_ABSOLUTE_VOLUME 0x50 -#define AVRC_PDU_SET_ADDRESSED_PLAYER 0x60 -#define AVRC_PDU_SET_BROWSED_PLAYER 0x70 -#define AVRC_PDU_GET_FOLDER_ITEMS 0x71 -#define AVRC_PDU_CHANGE_PATH 0x72 -#define AVRC_PDU_GET_ITEM_ATTRIBUTES 0x73 -#define AVRC_PDU_PLAY_ITEM 0x74 +#define AVRC_PDU_SET_ABSOLUTE_VOLUME 0x50 +#define AVRC_PDU_SET_ADDRESSED_PLAYER 0x60 +#define AVRC_PDU_SET_BROWSED_PLAYER 0x70 +#define AVRC_PDU_GET_FOLDER_ITEMS 0x71 +#define AVRC_PDU_CHANGE_PATH 0x72 +#define AVRC_PDU_GET_ITEM_ATTRIBUTES 0x73 +#define AVRC_PDU_PLAY_ITEM 0x74 /* Added in post 1.5 */ -#define AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS 0x75 -#define AVRC_PDU_SEARCH 0x80 -#define AVRC_PDU_ADD_TO_NOW_PLAYING 0x90 -#define AVRC_PDU_GENERAL_REJECT 0xA0 +#define AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS 0x75 +#define AVRC_PDU_SEARCH 0x80 +#define AVRC_PDU_ADD_TO_NOW_PLAYING 0x90 +#define AVRC_PDU_GENERAL_REJECT 0xA0 /* Define the vendor unique id carried in the pass through data */ -#define AVRC_PDU_NEXT_GROUP 0x00 -#define AVRC_PDU_PREV_GROUP 0x01 +#define AVRC_PDU_NEXT_GROUP 0x00 +#define AVRC_PDU_PREV_GROUP 0x01 /* The only pass through vendor unique commands defined by AVRC are the group * navigation commands. * The len for vendor unique data is 5 */ -#define AVRC_PASS_THRU_GROUP_LEN 5 +#define AVRC_PASS_THRU_GROUP_LEN 5 -#define AVRC_PDU_INVALID 0xff +#define AVRC_PDU_INVALID 0xff /* 6.15.3 error status code for general reject */ /* Invalid command, sent if TG received a PDU that it did not understand. */ -#define AVRC_STS_BAD_CMD 0x00 +#define AVRC_STS_BAD_CMD 0x00 /* Invalid parameter, sent if the TG received a PDU with a parameter ID that it * did not understand. Sent if there is only one parameter ID in the PDU. */ -#define AVRC_STS_BAD_PARAM 0x01 +#define AVRC_STS_BAD_PARAM 0x01 /* Specified parameter not found., sent if the parameter ID is understood, but * content is wrong or corrupted. */ -#define AVRC_STS_NOT_FOUND 0x02 +#define AVRC_STS_NOT_FOUND 0x02 /* Internal Error, sent if there are error conditions not covered by a more * specific error code. */ -#define AVRC_STS_INTERNAL_ERR 0x03 +#define AVRC_STS_INTERNAL_ERR 0x03 /* Operation completed without error. This is the status that should be * returned if the operation was successful. */ -#define AVRC_STS_NO_ERROR 0x04 +#define AVRC_STS_NO_ERROR 0x04 /* UID Changed - The UIDs on the device have changed */ -#define AVRC_STS_UID_CHANGED 0x05 +#define AVRC_STS_UID_CHANGED 0x05 /* #define AVRC_STS_GEN_ERROR 0x06 Unknown Error - now "reserved" */ /* Invalid Direction - The Direction parameter is invalid - Change Path*/ -#define AVRC_STS_BAD_DIR 0x07 +#define AVRC_STS_BAD_DIR 0x07 /* Not a Directory - The UID provided does not refer to a folder item - * Change Path */ -#define AVRC_STS_NOT_DIR 0x08 +#define AVRC_STS_NOT_DIR 0x08 /* Does Not Exist - The UID provided does not refer to any item - Change Path, * PlayItem, AddToNowPlaying, GetItemAttributes */ -#define AVRC_STS_NOT_EXIST 0x09 +#define AVRC_STS_NOT_EXIST 0x09 /* Invalid Scope - The scope parameter is invalid - GetFolderItems, PlayItem, * AddToNowPlayer, GetItemAttributes */ -#define AVRC_STS_BAD_SCOPE 0x0a +#define AVRC_STS_BAD_SCOPE 0x0a /* Range Out of Bounds - The start of range provided is not valid * GetFolderItems*/ -#define AVRC_STS_BAD_RANGE 0x0b +#define AVRC_STS_BAD_RANGE 0x0b /* UID is a Directory - The UID provided refers to a directory, which cannot be * handled by this media player - PlayItem, AddToNowPlaying */ -#define AVRC_STS_UID_IS_DIR 0x0c +#define AVRC_STS_UID_IS_DIR 0x0c /* Media in Use - The media is not able to be used for this operation at this * time - PlayItem, AddToNowPlaying */ -#define AVRC_STS_IN_USE 0x0d +#define AVRC_STS_IN_USE 0x0d /* Now Playing List Full - No more items can be added to the Now Playing List - * AddToNowPlaying*/ -#define AVRC_STS_NOW_LIST_FULL 0x0e +#define AVRC_STS_NOW_LIST_FULL 0x0e /* Search Not Supported - The Browsed Media Player does not support search - * Search */ #define AVRC_STS_SEARCH_NOT_SUP 0x0f /* Search in Progress - A search operation is already in progress - Search*/ -#define AVRC_STS_SEARCH_BUSY 0x10 +#define AVRC_STS_SEARCH_BUSY 0x10 /* Invalid Player Id - The specified Player Id does not refer to a valid player * - SetAddressedPlayer, SetBrowsedPlayer*/ -#define AVRC_STS_BAD_PLAYER_ID 0x11 +#define AVRC_STS_BAD_PLAYER_ID 0x11 /* Player Not Browsable - The Player Id supplied refers to a Media Player which * does not support browsing - SetBrowsedPlayer */ -#define AVRC_STS_PLAYER_N_BR 0x12 +#define AVRC_STS_PLAYER_N_BR 0x12 /* Player Not Addressed. The Player Id supplied refers to a player which is not * currently addressed, and the command is not able to be performed if the * player is not set as addressed - Search, SetBrowsedPlayer*/ -#define AVRC_STS_PLAYER_N_ADDR 0x13 +#define AVRC_STS_PLAYER_N_ADDR 0x13 /* No valid Search Results - The Search result list does not contain valid * entries, e.g. after being invalidated due to change of browsed player - * GetFolderItems */ @@ -300,519 +311,559 @@ typedef uint8_t tAVRC_STS; /* Define the Capability IDs */ -#define AVRC_CAP_COMPANY_ID 0x02 -#define AVRC_CAP_EVENTS_SUPPORTED 0x03 -#define AVRC_COMPANY_ID_LEN 3 -#define AVRC_CAPABILITY_OFFSET 2 +#define AVRC_CAP_COMPANY_ID 0x02 +#define AVRC_CAP_EVENTS_SUPPORTED 0x03 +#define AVRC_COMPANY_ID_LEN 3 +#define AVRC_CAPABILITY_OFFSET 2 /* Define the Player Application Settings IDs */ -#define AVRC_PLAYER_SETTING_EQUALIZER 0x01 -#define AVRC_PLAYER_SETTING_REPEAT 0x02 -#define AVRC_PLAYER_SETTING_SHUFFLE 0x03 -#define AVRC_PLAYER_SETTING_SCAN 0x04 -#define AVRC_PLAYER_SETTING_LOW_MENU_EXT 0x80 -#define AVRC_PLAYER_SETTING_HIGH_MENU_EXT 0xff +#define AVRC_PLAYER_SETTING_EQUALIZER 0x01 +#define AVRC_PLAYER_SETTING_REPEAT 0x02 +#define AVRC_PLAYER_SETTING_SHUFFLE 0x03 +#define AVRC_PLAYER_SETTING_SCAN 0x04 +#define AVRC_PLAYER_SETTING_LOW_MENU_EXT 0x80 +#define AVRC_PLAYER_SETTING_HIGH_MENU_EXT 0xff /* Define the possible values of the Player Application Settings */ -#define AVRC_PLAYER_VAL_OFF 0x01 -#define AVRC_PLAYER_VAL_ON 0x02 -#define AVRC_PLAYER_VAL_SINGLE_REPEAT 0x02 -#define AVRC_PLAYER_VAL_ALL_REPEAT 0x03 -#define AVRC_PLAYER_VAL_GROUP_REPEAT 0x04 -#define AVRC_PLAYER_VAL_ALL_SHUFFLE 0x02 -#define AVRC_PLAYER_VAL_GROUP_SHUFFLE 0x03 -#define AVRC_PLAYER_VAL_ALL_SCAN 0x02 -#define AVRC_PLAYER_VAL_GROUP_SCAN 0x03 +#define AVRC_PLAYER_VAL_OFF 0x01 +#define AVRC_PLAYER_VAL_ON 0x02 +#define AVRC_PLAYER_VAL_SINGLE_REPEAT 0x02 +#define AVRC_PLAYER_VAL_ALL_REPEAT 0x03 +#define AVRC_PLAYER_VAL_GROUP_REPEAT 0x04 +#define AVRC_PLAYER_VAL_ALL_SHUFFLE 0x02 +#define AVRC_PLAYER_VAL_GROUP_SHUFFLE 0x03 +#define AVRC_PLAYER_VAL_ALL_SCAN 0x02 +#define AVRC_PLAYER_VAL_GROUP_SCAN 0x03 /* Define the possible values of Battery Status PDU */ -#define AVRC_BATTERY_STATUS_NORMAL 0x00 -#define AVRC_BATTERY_STATUS_WARNING 0x01 -#define AVRC_BATTERY_STATUS_CRITICAL 0x02 -#define AVRC_BATTERY_STATUS_EXTERNAL 0x03 -#define AVRC_BATTERY_STATUS_FULL_CHARGE 0x04 +#define AVRC_BATTERY_STATUS_NORMAL 0x00 +#define AVRC_BATTERY_STATUS_WARNING 0x01 +#define AVRC_BATTERY_STATUS_CRITICAL 0x02 +#define AVRC_BATTERY_STATUS_EXTERNAL 0x03 +#define AVRC_BATTERY_STATUS_FULL_CHARGE 0x04 typedef uint8_t tAVRC_BATTERY_STATUS; /* Define character set */ -#define AVRC_CHAR_SET_SIZE 2 +#define AVRC_CHAR_SET_SIZE 2 /* Define the Media Attribute IDs */ -#define AVRC_MEDIA_ATTR_ID_TITLE 0x00000001 -#define AVRC_MEDIA_ATTR_ID_ARTIST 0x00000002 -#define AVRC_MEDIA_ATTR_ID_ALBUM 0x00000003 -#define AVRC_MEDIA_ATTR_ID_TRACK_NUM 0x00000004 -#define AVRC_MEDIA_ATTR_ID_NUM_TRACKS 0x00000005 -#define AVRC_MEDIA_ATTR_ID_GENRE 0x00000006 -#define AVRC_MEDIA_ATTR_ID_PLAYING_TIME 0x00000007 /* in miliseconds */ -#define AVRC_MAX_NUM_MEDIA_ATTR_ID 7 +#define AVRC_MEDIA_ATTR_ID_TITLE 0x00000001 +#define AVRC_MEDIA_ATTR_ID_ARTIST 0x00000002 +#define AVRC_MEDIA_ATTR_ID_ALBUM 0x00000003 +#define AVRC_MEDIA_ATTR_ID_TRACK_NUM 0x00000004 +#define AVRC_MEDIA_ATTR_ID_NUM_TRACKS 0x00000005 +#define AVRC_MEDIA_ATTR_ID_GENRE 0x00000006 +#define AVRC_MEDIA_ATTR_ID_PLAYING_TIME 0x00000007 /* in miliseconds */ +#define AVRC_MAX_NUM_MEDIA_ATTR_ID 7 /* Define the possible values of play state */ -#define AVRC_PLAYSTATE_RESP_MSG_SIZE 9 -#define AVRC_PLAYSTATE_STOPPED 0x00 /* Stopped */ -#define AVRC_PLAYSTATE_PLAYING 0x01 /* Playing */ -#define AVRC_PLAYSTATE_PAUSED 0x02 /* Paused */ -#define AVRC_PLAYSTATE_FWD_SEEK 0x03 /* Fwd Seek*/ -#define AVRC_PLAYSTATE_REV_SEEK 0x04 /* Rev Seek*/ -#define AVRC_PLAYSTATE_ERROR 0xFF /* Error */ +#define AVRC_PLAYSTATE_RESP_MSG_SIZE 9 +#define AVRC_PLAYSTATE_STOPPED 0x00 /* Stopped */ +#define AVRC_PLAYSTATE_PLAYING 0x01 /* Playing */ +#define AVRC_PLAYSTATE_PAUSED 0x02 /* Paused */ +#define AVRC_PLAYSTATE_FWD_SEEK 0x03 /* Fwd Seek*/ +#define AVRC_PLAYSTATE_REV_SEEK 0x04 /* Rev Seek*/ +#define AVRC_PLAYSTATE_ERROR 0xFF /* Error */ typedef uint8_t tAVRC_PLAYSTATE; /* Define the events that can be registered for notifications */ -#define AVRC_EVT_PLAY_STATUS_CHANGE 0x01 -#define AVRC_EVT_TRACK_CHANGE 0x02 -#define AVRC_EVT_TRACK_REACHED_END 0x03 -#define AVRC_EVT_TRACK_REACHED_START 0x04 -#define AVRC_EVT_PLAY_POS_CHANGED 0x05 -#define AVRC_EVT_BATTERY_STATUS_CHANGE 0x06 -#define AVRC_EVT_SYSTEM_STATUS_CHANGE 0x07 -#define AVRC_EVT_APP_SETTING_CHANGE 0x08 +#define AVRC_EVT_PLAY_STATUS_CHANGE 0x01 +#define AVRC_EVT_TRACK_CHANGE 0x02 +#define AVRC_EVT_TRACK_REACHED_END 0x03 +#define AVRC_EVT_TRACK_REACHED_START 0x04 +#define AVRC_EVT_PLAY_POS_CHANGED 0x05 +#define AVRC_EVT_BATTERY_STATUS_CHANGE 0x06 +#define AVRC_EVT_SYSTEM_STATUS_CHANGE 0x07 +#define AVRC_EVT_APP_SETTING_CHANGE 0x08 /* added in AVRCP 1.4 */ -#define AVRC_EVT_NOW_PLAYING_CHANGE 0x09 -#define AVRC_EVT_AVAL_PLAYERS_CHANGE 0x0a -#define AVRC_EVT_ADDR_PLAYER_CHANGE 0x0b -#define AVRC_EVT_UIDS_CHANGE 0x0c -#define AVRC_EVT_VOLUME_CHANGE 0x0d +#define AVRC_EVT_NOW_PLAYING_CHANGE 0x09 +#define AVRC_EVT_AVAL_PLAYERS_CHANGE 0x0a +#define AVRC_EVT_ADDR_PLAYER_CHANGE 0x0b +#define AVRC_EVT_UIDS_CHANGE 0x0c +#define AVRC_EVT_VOLUME_CHANGE 0x0d /* the number of events that can be registered for notifications */ -#define AVRC_NUM_NOTIF_EVENTS 0x0d +#define AVRC_NUM_NOTIF_EVENTS 0x0d -#define AVRC_EVT_MSG_LEN_1 0x01 -#define AVRC_EVT_MSG_LEN_2 0x02 -#define AVRC_EVT_MSG_LEN_5 0x05 -#define AVRC_EVT_MSG_LEN_9 0x09 +#define AVRC_EVT_MSG_LEN_1 0x01 +#define AVRC_EVT_MSG_LEN_2 0x02 +#define AVRC_EVT_MSG_LEN_5 0x05 +#define AVRC_EVT_MSG_LEN_9 0x09 -#define AVRC_MAX_VOLUME 0x7F +#define AVRC_MAX_VOLUME 0x7F /* Define the possible values of system status */ -#define AVRC_SYSTEMSTATE_PWR_ON 0x00 -#define AVRC_SYSTEMSTATE_PWR_OFF 0x01 -#define AVRC_SYSTEMSTATE_PWR_UNPLUGGED 0x02 +#define AVRC_SYSTEMSTATE_PWR_ON 0x00 +#define AVRC_SYSTEMSTATE_PWR_OFF 0x01 +#define AVRC_SYSTEMSTATE_PWR_UNPLUGGED 0x02 typedef uint8_t tAVRC_SYSTEMSTATE; /* the frequently used character set ids */ -#define AVRC_CHARSET_ID_ASCII ((uint16_t) 0x0003) /* ASCII */ -#define AVRC_CHARSET_ID_UTF8 ((uint16_t) 0x006a) /* UTF-8 */ -#define AVRC_CHARSET_ID_UTF16 ((uint16_t) 0x03f7) /* 1015 */ -#define AVRC_CHARSET_ID_UTF32 ((uint16_t) 0x03f9) /* 1017 */ +#define AVRC_CHARSET_ID_ASCII ((uint16_t)0x0003) /* ASCII */ +#define AVRC_CHARSET_ID_UTF8 ((uint16_t)0x006a) /* UTF-8 */ +#define AVRC_CHARSET_ID_UTF16 ((uint16_t)0x03f7) /* 1015 */ +#define AVRC_CHARSET_ID_UTF32 ((uint16_t)0x03f9) /* 1017 */ /***************************************************************************** * Advanced Control ****************************************************************************/ -#define AVRC_ITEM_PLAYER 0x01 -#define AVRC_ITEM_FOLDER 0x02 -#define AVRC_ITEM_MEDIA 0x03 +#define AVRC_ITEM_PLAYER 0x01 +#define AVRC_ITEM_FOLDER 0x02 +#define AVRC_ITEM_MEDIA 0x03 /* Media Player Item - Contains all available media players */ -#define AVRC_SCOPE_PLAYER_LIST 0x00 -/* Folder Item, Media Element Item - The virtual filesystem containing the media content of the browsed player */ -#define AVRC_SCOPE_FILE_SYSTEM 0x01 -/* Media Element Item The results of a search operation on the browsed player */ -#define AVRC_SCOPE_SEARCH 0x02 -/* Media Element Item The Now Playing list (or queue) of the addressed player */ -#define AVRC_SCOPE_NOW_PLAYING 0x03 +#define AVRC_SCOPE_PLAYER_LIST 0x00 +/* Folder Item, Media Element Item - The virtual filesystem containing the media + * content of the browsed player */ +#define AVRC_SCOPE_FILE_SYSTEM 0x01 +/* Media Element Item The results of a search operation on the browsed player + */ +#define AVRC_SCOPE_SEARCH 0x02 +/* Media Element Item The Now Playing list (or queue) of the addressed player + */ +#define AVRC_SCOPE_NOW_PLAYING 0x03 #define AVRC_FOLDER_ITEM_COUNT_NONE 0xFF /* folder type */ -#define AVRC_FOLDER_TYPE_MIXED 0x00 -#define AVRC_FOLDER_TYPE_TITLES 0x01 -#define AVRC_FOLDER_TYPE_ALNUMS 0x02 -#define AVRC_FOLDER_TYPE_ARTISTS 0x03 -#define AVRC_FOLDER_TYPE_GENRES 0x04 -#define AVRC_FOLDER_TYPE_PLAYLISTS 0x05 -#define AVRC_FOLDER_TYPE_YEARS 0x06 +#define AVRC_FOLDER_TYPE_MIXED 0x00 +#define AVRC_FOLDER_TYPE_TITLES 0x01 +#define AVRC_FOLDER_TYPE_ALNUMS 0x02 +#define AVRC_FOLDER_TYPE_ARTISTS 0x03 +#define AVRC_FOLDER_TYPE_GENRES 0x04 +#define AVRC_FOLDER_TYPE_PLAYLISTS 0x05 +#define AVRC_FOLDER_TYPE_YEARS 0x06 /* major player type */ -#define AVRC_MJ_TYPE_AUDIO 0x01 /* Audio */ -#define AVRC_MJ_TYPE_VIDEO 0x02 /* Video */ -#define AVRC_MJ_TYPE_BC_AUDIO 0x04 /* Broadcasting Audio */ -#define AVRC_MJ_TYPE_BC_VIDEO 0x08 /* Broadcasting Video */ -#define AVRC_MJ_TYPE_INVALID 0xF0 +#define AVRC_MJ_TYPE_AUDIO 0x01 /* Audio */ +#define AVRC_MJ_TYPE_VIDEO 0x02 /* Video */ +#define AVRC_MJ_TYPE_BC_AUDIO 0x04 /* Broadcasting Audio */ +#define AVRC_MJ_TYPE_BC_VIDEO 0x08 /* Broadcasting Video */ +#define AVRC_MJ_TYPE_INVALID 0xF0 /* player sub type */ -#define AVRC_SUB_TYPE_NONE 0x00 -#define AVRC_SUB_TYPE_AUDIO_BOOK 0x01 /* Audio Book */ -#define AVRC_SUB_TYPE_PODCAST 0x02 /* Podcast */ -#define AVRC_SUB_TYPE_INVALID 0xFC +#define AVRC_SUB_TYPE_NONE 0x00 +#define AVRC_SUB_TYPE_AUDIO_BOOK 0x01 /* Audio Book */ +#define AVRC_SUB_TYPE_PODCAST 0x02 /* Podcast */ +#define AVRC_SUB_TYPE_INVALID 0xFC /* media item - media type */ -#define AVRC_MEDIA_TYPE_AUDIO 0x00 -#define AVRC_MEDIA_TYPE_VIDEO 0x01 +#define AVRC_MEDIA_TYPE_AUDIO 0x00 +#define AVRC_MEDIA_TYPE_VIDEO 0x01 -#define AVRC_DIR_UP 0x00 /* Folder Up */ -#define AVRC_DIR_DOWN 0x01 /* Folder Down */ +#define AVRC_DIR_UP 0x00 /* Folder Up */ +#define AVRC_DIR_DOWN 0x01 /* Folder Down */ -#define AVRC_UID_SIZE 8 +#define AVRC_UID_SIZE 8 typedef uint8_t tAVRC_UID[AVRC_UID_SIZE]; /***************************************************************************** * player attribute - supported features ****************************************************************************/ -#define AVRC_PF_SELECT_BIT_NO 0 -#define AVRC_PF_SELECT_MASK 0x01 -#define AVRC_PF_SELECT_OFF 0 -#define AVRC_PF_SELECT_SUPPORTED(x) ((x)[AVRC_PF_SELECT_OFF] & AVRC_PF_SELECT_MASK) - -#define AVRC_PF_UP_BIT_NO 1 -#define AVRC_PF_UP_MASK 0x02 -#define AVRC_PF_UP_OFF 0 -#define AVRC_PF_UP_SUPPORTED(x) ((x)[AVRC_PF_UP_OFF] & AVRC_PF_UP_MASK) - -#define AVRC_PF_DOWN_BIT_NO 2 -#define AVRC_PF_DOWN_MASK 0x04 -#define AVRC_PF_DOWN_OFF 0 -#define AVRC_PF_DOWN_SUPPORTED(x) ((x)[AVRC_PF_DOWN_OFF] & AVRC_PF_DOWN_MASK) - -#define AVRC_PF_LEFT_BIT_NO 3 -#define AVRC_PF_LEFT_MASK 0x08 -#define AVRC_PF_LEFT_OFF 0 -#define AVRC_PF_LEFT_SUPPORTED(x) ((x)[AVRC_PF_LEFT_OFF] & AVRC_PF_LEFT_MASK) - -#define AVRC_PF_RIGHT_BIT_NO 4 -#define AVRC_PF_RIGHT_MASK 0x10 -#define AVRC_PF_RIGHT_OFF 0 -#define AVRC_PF_RIGHT_SUPPORTED(x) ((x)[AVRC_PF_RIGHT_OFF] & AVRC_PF_RIGHT_MASK) - -#define AVRC_PF_RIGHTUP_BIT_NO 5 -#define AVRC_PF_RIGHTUP_MASK 0x20 -#define AVRC_PF_RIGHTUP_OFF 0 -#define AVRC_PF_RIGHTUP_SUPPORTED(x) ((x)[AVRC_PF_RIGHTUP_OFF] & AVRC_PF_RIGHTUP_MASK) - -#define AVRC_PF_RIGHTDOWN_BIT_NO 6 -#define AVRC_PF_RIGHTDOWN_MASK 0x40 -#define AVRC_PF_RIGHTDOWN_OFF 0 -#define AVRC_PF_RIGHTDOWN_SUPPORTED(x) ((x)[AVRC_PF_RIGHTDOWN_OFF] & AVRC_PF_RIGHTDOWN_MASK) - -#define AVRC_PF_LEFTUP_BIT_NO 7 -#define AVRC_PF_LEFTUP_MASK 0x80 -#define AVRC_PF_LEFTUP_OFF 0 -#define AVRC_PF_LEFTUP_SUPPORTED(x) ((x)[AVRC_PF_LEFTUP_OFF] & AVRC_PF_LEFTUP_MASK) - -#define AVRC_PF_LEFTDOWN_BIT_NO 8 -#define AVRC_PF_LEFTDOWN_MASK 0x01 -#define AVRC_PF_LEFTDOWN_OFF 1 -#define AVRC_PF_LEFTDOWN_SUPPORTED(x) ((x)[AVRC_PF_LEFTDOWN_OFF] & AVRC_PF_LEFTDOWN_MASK) - -#define AVRC_PF_ROOT_MENU_BIT_NO 9 -#define AVRC_PF_ROOT_MENU_MASK 0x02 -#define AVRC_PF_ROOT_MENU_OFF 1 -#define AVRC_PF_ROOT_MENU_SUPPORTED(x) ((x)[AVRC_PF_ROOT_MENU_OFF] & AVRC_PF_ROOT_MENU_MASK) - -#define AVRC_PF_SETUP_MENU_BIT_NO 10 -#define AVRC_PF_SETUP_MENU_MASK 0x04 -#define AVRC_PF_SETUP_MENU_OFF 1 -#define AVRC_PF_SETUP_MENU_SUPPORTED(x) ((x)[AVRC_PF_SETUP_MENU_OFF] & AVRC_PF_SETUP_MENU_MASK) - -#define AVRC_PF_CONTENTS_MENU_BIT_NO 11 -#define AVRC_PF_CONTENTS_MENU_MASK 0x08 -#define AVRC_PF_CONTENTS_MENU_OFF 1 -#define AVRC_PF_CONTENTS_MENU_SUPPORTED(x) ((x)[AVRC_PF_CONTENTS_MENU_OFF] & AVRC_PF_CONTENTS_MENU_MASK) - -#define AVRC_PF_FAVORITE_MENU_BIT_NO 12 -#define AVRC_PF_FAVORITE_MENU_MASK 0x10 -#define AVRC_PF_FAVORITE_MENU_OFF 1 -#define AVRC_PF_FAVORITE_MENU_SUPPORTED(x) ((x)[AVRC_PF_FAVORITE_MENU_OFF] & AVRC_PF_FAVORITE_MENU_MASK) - -#define AVRC_PF_EXIT_BIT_NO 13 -#define AVRC_PF_EXIT_MASK 0x20 -#define AVRC_PF_EXIT_OFF 1 -#define AVRC_PF_EXIT_SUPPORTED(x) ((x)[AVRC_PF_EXIT_OFF] & AVRC_PF_EXIT_MASK) - -#define AVRC_PF_0_BIT_NO 14 -#define AVRC_PF_0_MASK 0x40 -#define AVRC_PF_0_OFF 1 -#define AVRC_PF_0_SUPPORTED(x) ((x)[AVRC_PF_0_OFF] & AVRC_PF_0_MASK) - -#define AVRC_PF_1_BIT_NO 15 -#define AVRC_PF_1_MASK 0x80 -#define AVRC_PF_1_OFF 1 -#define AVRC_PF_1_SUPPORTED(x) ((x)[AVRC_PF_1_OFF] & AVRC_PF_1_MASK) - -#define AVRC_PF_2_BIT_NO 16 -#define AVRC_PF_2_MASK 0x01 -#define AVRC_PF_2_OFF 2 -#define AVRC_PF_2_SUPPORTED(x) ((x)[AVRC_PF_2_OFF] & AVRC_PF_2_MASK) - -#define AVRC_PF_3_BIT_NO 17 -#define AVRC_PF_3_MASK 0x02 -#define AVRC_PF_3_OFF 2 -#define AVRC_PF_3_SUPPORTED(x) ((x)[AVRC_PF_3_OFF] & AVRC_PF_3_MASK) - -#define AVRC_PF_4_BIT_NO 18 -#define AVRC_PF_4_MASK 0x04 -#define AVRC_PF_4_OFF 2 -#define AVRC_PF_4_SUPPORTED(x) ((x)[AVRC_PF_4_OFF] & AVRC_PF_4_MASK) - -#define AVRC_PF_5_BIT_NO 19 -#define AVRC_PF_5_MASK 0x08 -#define AVRC_PF_5_OFF 2 -#define AVRC_PF_5_SUPPORTED(x) ((x)[AVRC_PF_5_OFF] & AVRC_PF_5_MASK) - -#define AVRC_PF_6_BIT_NO 20 -#define AVRC_PF_6_MASK 0x10 -#define AVRC_PF_6_OFF 2 -#define AVRC_PF_6_SUPPORTED(x) ((x)[AVRC_PF_6_OFF] & AVRC_PF_6_MASK) - -#define AVRC_PF_7_BIT_NO 21 -#define AVRC_PF_7_MASK 0x20 -#define AVRC_PF_7_OFF 2 -#define AVRC_PF_7_SUPPORTED(x) ((x)[AVRC_PF_7_OFF] & AVRC_PF_7_MASK) - -#define AVRC_PF_8_BIT_NO 22 -#define AVRC_PF_8_MASK 0x40 -#define AVRC_PF_8_OFF 2 -#define AVRC_PF_8_SUPPORTED(x) ((x)[AVRC_PF_8_OFF] & AVRC_PF_8_MASK) - -#define AVRC_PF_9_BIT_NO 23 -#define AVRC_PF_9_MASK 0x80 -#define AVRC_PF_9_OFF 2 -#define AVRC_PF_9_SUPPORTED(x) ((x)[AVRC_PF_9_OFF] & AVRC_PF_9_MASK) - -#define AVRC_PF_DOT_BIT_NO 24 -#define AVRC_PF_DOT_MASK 0x01 -#define AVRC_PF_DOT_OFF 3 -#define AVRC_PF_DOT_SUPPORTED(x) ((x)[AVRC_PF_DOT_OFF] & AVRC_PF_DOT_MASK) - -#define AVRC_PF_ENTER_BIT_NO 25 -#define AVRC_PF_ENTER_MASK 0x02 -#define AVRC_PF_ENTER_OFF 3 -#define AVRC_PF_ENTER_SUPPORTED(x) ((x)[AVRC_PF_ENTER_OFF] & AVRC_PF_ENTER_MASK) - -#define AVRC_PF_CLEAR_BIT_NO 26 -#define AVRC_PF_CLEAR_MASK 0x04 -#define AVRC_PF_CLEAR_OFF 3 -#define AVRC_PF_CLEAR_SUPPORTED(x) ((x)[AVRC_PF_CLEAR_OFF] & AVRC_PF_CLEAR_MASK) - -#define AVRC_PF_CHNL_UP_BIT_NO 27 -#define AVRC_PF_CHNL_UP_MASK 0x08 -#define AVRC_PF_CHNL_UP_OFF 3 -#define AVRC_PF_CHNL_UP_SUPPORTED(x) ((x)[AVRC_PF_CHNL_UP_OFF] & AVRC_PF_CHNL_UP_MASK) - -#define AVRC_PF_CHNL_DOWN_BIT_NO 28 -#define AVRC_PF_CHNL_DOWN_MASK 0x10 -#define AVRC_PF_CHNL_DOWN_OFF 3 -#define AVRC_PF_CHNL_DOWN_SUPPORTED(x) ((x)[AVRC_PF_CHNL_DOWN_OFF] & AVRC_PF_CHNL_DOWN_MASK) - -#define AVRC_PF_PREV_CHNL_BIT_NO 29 -#define AVRC_PF_PREV_CHNL_MASK 0x20 -#define AVRC_PF_PREV_CHNL_OFF 3 -#define AVRC_PF_PREV_CHNL_SUPPORTED(x) ((x)[AVRC_PF_PREV_CHNL_OFF] & AVRC_PF_PREV_CHNL_MASK) - -#define AVRC_PF_SOUND_SEL_BIT_NO 30 -#define AVRC_PF_SOUND_SEL_MASK 0x40 -#define AVRC_PF_SOUND_SEL_OFF 3 -#define AVRC_PF_SOUND_SEL_SUPPORTED(x) ((x)[AVRC_PF_SOUND_SEL_OFF] & AVRC_PF_SOUND_SEL_MASK) - -#define AVRC_PF_INPUT_SEL_BIT_NO 31 -#define AVRC_PF_INPUT_SEL_MASK 0x80 -#define AVRC_PF_INPUT_SEL_OFF 3 -#define AVRC_PF_INPUT_SEL_SUPPORTED(x) ((x)[AVRC_PF_INPUT_SEL_OFF] & AVRC_PF_INPUT_SEL_MASK) - -#define AVRC_PF_DISP_INFO_BIT_NO 32 -#define AVRC_PF_DISP_INFO_MASK 0x01 -#define AVRC_PF_DISP_INFO_OFF 4 -#define AVRC_PF_DISP_INFO_SUPPORTED(x) ((x)[AVRC_PF_DISP_INFO_OFF] & AVRC_PF_DISP_INFO_MASK) - -#define AVRC_PF_HELP_BIT_NO 33 -#define AVRC_PF_HELP_MASK 0x02 -#define AVRC_PF_HELP_OFF 4 -#define AVRC_PF_HELP_SUPPORTED(x) ((x)[AVRC_PF_HELP_OFF] & AVRC_PF_HELP_MASK) - -#define AVRC_PF_PAGE_UP_BIT_NO 34 -#define AVRC_PF_PAGE_UP_MASK 0x04 -#define AVRC_PF_PAGE_UP_OFF 4 -#define AVRC_PF_PAGE_UP_SUPPORTED(x) ((x)[AVRC_PF_PAGE_UP_OFF] & AVRC_PF_PAGE_UP_MASK) - -#define AVRC_PF_PAGE_DOWN_BIT_NO 35 -#define AVRC_PF_PAGE_DOWN_MASK 0x08 -#define AVRC_PF_PAGE_DOWN_OFF 4 -#define AVRC_PF_PAGE_DOWN_SUPPORTED(x) ((x)[AVRC_PF_PAGE_DOWN_OFF] & AVRC_PF_PAGE_DOWN_MASK) - -#define AVRC_PF_POWER_BIT_NO 36 -#define AVRC_PF_POWER_MASK 0x10 -#define AVRC_PF_POWER_OFF 4 -#define AVRC_PF_POWER_SUPPORTED(x) ((x)[AVRC_PF_POWER_OFF] & AVRC_PF_POWER_MASK) - -#define AVRC_PF_VOL_UP_BIT_NO 37 -#define AVRC_PF_VOL_UP_MASK 0x20 -#define AVRC_PF_VOL_UP_OFF 4 -#define AVRC_PF_VOL_UP_SUPPORTED(x) ((x)[AVRC_PF_VOL_UP_OFF] & AVRC_PF_VOL_UP_MASK) - -#define AVRC_PF_VOL_DOWN_BIT_NO 38 -#define AVRC_PF_VOL_DOWN_MASK 0x40 -#define AVRC_PF_VOL_DOWN_OFF 4 -#define AVRC_PF_VOL_DOWN_SUPPORTED(x) ((x)[AVRC_PF_VOL_DOWN_OFF] & AVRC_PF_VOL_DOWN_MASK) - -#define AVRC_PF_MUTE_BIT_NO 39 -#define AVRC_PF_MUTE_MASK 0x80 -#define AVRC_PF_MUTE_OFF 4 -#define AVRC_PF_MUTE_SUPPORTED(x) ((x)[AVRC_PF_MUTE_OFF] & AVRC_PF_MUTE_MASK) - -#define AVRC_PF_PLAY_BIT_NO 40 -#define AVRC_PF_PLAY_MASK 0x01 -#define AVRC_PF_PLAY_OFF 5 -#define AVRC_PF_PLAY_SUPPORTED(x) ((x)[AVRC_PF_PLAY_OFF] & AVRC_PF_PLAY_MASK) - -#define AVRC_PF_STOP_BIT_NO 41 -#define AVRC_PF_STOP_MASK 0x02 -#define AVRC_PF_STOP_OFF 5 -#define AVRC_PF_STOP_SUPPORTED(x) ((x)[AVRC_PF_STOP_OFF] & AVRC_PF_STOP_MASK) - -#define AVRC_PF_PAUSE_BIT_NO 42 -#define AVRC_PF_PAUSE_MASK 0x04 -#define AVRC_PF_PAUSE_OFF 5 -#define AVRC_PF_PAUSE_SUPPORTED(x) ((x)[AVRC_PF_PAUSE_OFF] & AVRC_PF_PAUSE_MASK) - -#define AVRC_PF_RECORD_BIT_NO 43 -#define AVRC_PF_RECORD_MASK 0x08 -#define AVRC_PF_RECORD_OFF 5 -#define AVRC_PF_RECORD_SUPPORTED(x) ((x)[AVRC_PF_RECORD_OFF] & AVRC_PF_RECORD_MASK) - -#define AVRC_PF_REWIND_BIT_NO 44 -#define AVRC_PF_REWIND_MASK 0x10 -#define AVRC_PF_REWIND_OFF 5 -#define AVRC_PF_REWIND_SUPPORTED(x) ((x)[AVRC_PF_REWIND_OFF] & AVRC_PF_REWIND_MASK) - -#define AVRC_PF_FAST_FWD_BIT_NO 45 -#define AVRC_PF_FAST_FWD_MASK 0x20 -#define AVRC_PF_FAST_FWD_OFF 5 -#define AVRC_PF_FAST_FWD_SUPPORTED(x) ((x)[AVRC_PF_FAST_FWD_OFF] & AVRC_PF_FAST_FWD_MASK) - -#define AVRC_PF_EJECT_BIT_NO 46 -#define AVRC_PF_EJECT_MASK 0x40 -#define AVRC_PF_EJECT_OFF 5 -#define AVRC_PF_EJECT_SUPPORTED(x) ((x)[AVRC_PF_EJECT_OFF] & AVRC_PF_EJECT_MASK) - -#define AVRC_PF_FORWARD_BIT_NO 47 -#define AVRC_PF_FORWARD_MASK 0x80 -#define AVRC_PF_FORWARD_OFF 5 -#define AVRC_PF_FORWARD_SUPPORTED(x) ((x)[AVRC_PF_FORWARD_OFF] & AVRC_PF_FORWARD_MASK) - -#define AVRC_PF_BACKWARD_BIT_NO 48 -#define AVRC_PF_BACKWARD_MASK 0x01 -#define AVRC_PF_BACKWARD_OFF 6 -#define AVRC_PF_BACKWARD_SUPPORTED(x) ((x)[AVRC_PF_BACKWARD_OFF] & AVRC_PF_BACKWARD_MASK) - -#define AVRC_PF_ANGLE_BIT_NO 49 -#define AVRC_PF_ANGLE_MASK 0x02 -#define AVRC_PF_ANGLE_OFF 6 -#define AVRC_PF_ANGLE_SUPPORTED(x) ((x)[AVRC_PF_ANGLE_OFF] & AVRC_PF_ANGLE_MASK) - -#define AVRC_PF_SUBPICTURE_BIT_NO 50 -#define AVRC_PF_SUBPICTURE_MASK 0x04 -#define AVRC_PF_SUBPICTURE_OFF 6 -#define AVRC_PF_SUBPICTURE_SUPPORTED(x) ((x)[AVRC_PF_SUBPICTURE_OFF] & AVRC_PF_SUBPICTURE_MASK) - -#define AVRC_PF_F1_BIT_NO 51 -#define AVRC_PF_F1_MASK 0x08 -#define AVRC_PF_F1_OFF 6 -#define AVRC_PF_F1_SUPPORTED(x) ((x)[AVRC_PF_F1_OFF] & AVRC_PF_F1_MASK) - -#define AVRC_PF_F2_BIT_NO 52 -#define AVRC_PF_F2_MASK 0x10 -#define AVRC_PF_F2_OFF 6 -#define AVRC_PF_F2_SUPPORTED(x) ((x)[AVRC_PF_F2_OFF] & AVRC_PF_F2_MASK) - -#define AVRC_PF_F3_BIT_NO 53 -#define AVRC_PF_F3_MASK 0x20 -#define AVRC_PF_F3_OFF 6 -#define AVRC_PF_F3_SUPPORTED(x) ((x)[AVRC_PF_F3_OFF] & AVRC_PF_F3_MASK) - -#define AVRC_PF_F4_BIT_NO 54 -#define AVRC_PF_F4_MASK 0x40 -#define AVRC_PF_F4_OFF 6 -#define AVRC_PF_F4_SUPPORTED(x) ((x)[AVRC_PF_F4_OFF] & AVRC_PF_F4_MASK) - -#define AVRC_PF_F5_BIT_NO 55 -#define AVRC_PF_F5_MASK 0x80 -#define AVRC_PF_F5_OFF 6 -#define AVRC_PF_F5_SUPPORTED(x) ((x)[AVRC_PF_F5_OFF] & AVRC_PF_F5_MASK) +#define AVRC_PF_SELECT_BIT_NO 0 +#define AVRC_PF_SELECT_MASK 0x01 +#define AVRC_PF_SELECT_OFF 0 +#define AVRC_PF_SELECT_SUPPORTED(x) \ + ((x)[AVRC_PF_SELECT_OFF] & AVRC_PF_SELECT_MASK) + +#define AVRC_PF_UP_BIT_NO 1 +#define AVRC_PF_UP_MASK 0x02 +#define AVRC_PF_UP_OFF 0 +#define AVRC_PF_UP_SUPPORTED(x) ((x)[AVRC_PF_UP_OFF] & AVRC_PF_UP_MASK) + +#define AVRC_PF_DOWN_BIT_NO 2 +#define AVRC_PF_DOWN_MASK 0x04 +#define AVRC_PF_DOWN_OFF 0 +#define AVRC_PF_DOWN_SUPPORTED(x) ((x)[AVRC_PF_DOWN_OFF] & AVRC_PF_DOWN_MASK) + +#define AVRC_PF_LEFT_BIT_NO 3 +#define AVRC_PF_LEFT_MASK 0x08 +#define AVRC_PF_LEFT_OFF 0 +#define AVRC_PF_LEFT_SUPPORTED(x) ((x)[AVRC_PF_LEFT_OFF] & AVRC_PF_LEFT_MASK) + +#define AVRC_PF_RIGHT_BIT_NO 4 +#define AVRC_PF_RIGHT_MASK 0x10 +#define AVRC_PF_RIGHT_OFF 0 +#define AVRC_PF_RIGHT_SUPPORTED(x) ((x)[AVRC_PF_RIGHT_OFF] & AVRC_PF_RIGHT_MASK) + +#define AVRC_PF_RIGHTUP_BIT_NO 5 +#define AVRC_PF_RIGHTUP_MASK 0x20 +#define AVRC_PF_RIGHTUP_OFF 0 +#define AVRC_PF_RIGHTUP_SUPPORTED(x) \ + ((x)[AVRC_PF_RIGHTUP_OFF] & AVRC_PF_RIGHTUP_MASK) + +#define AVRC_PF_RIGHTDOWN_BIT_NO 6 +#define AVRC_PF_RIGHTDOWN_MASK 0x40 +#define AVRC_PF_RIGHTDOWN_OFF 0 +#define AVRC_PF_RIGHTDOWN_SUPPORTED(x) \ + ((x)[AVRC_PF_RIGHTDOWN_OFF] & AVRC_PF_RIGHTDOWN_MASK) + +#define AVRC_PF_LEFTUP_BIT_NO 7 +#define AVRC_PF_LEFTUP_MASK 0x80 +#define AVRC_PF_LEFTUP_OFF 0 +#define AVRC_PF_LEFTUP_SUPPORTED(x) \ + ((x)[AVRC_PF_LEFTUP_OFF] & AVRC_PF_LEFTUP_MASK) + +#define AVRC_PF_LEFTDOWN_BIT_NO 8 +#define AVRC_PF_LEFTDOWN_MASK 0x01 +#define AVRC_PF_LEFTDOWN_OFF 1 +#define AVRC_PF_LEFTDOWN_SUPPORTED(x) \ + ((x)[AVRC_PF_LEFTDOWN_OFF] & AVRC_PF_LEFTDOWN_MASK) + +#define AVRC_PF_ROOT_MENU_BIT_NO 9 +#define AVRC_PF_ROOT_MENU_MASK 0x02 +#define AVRC_PF_ROOT_MENU_OFF 1 +#define AVRC_PF_ROOT_MENU_SUPPORTED(x) \ + ((x)[AVRC_PF_ROOT_MENU_OFF] & AVRC_PF_ROOT_MENU_MASK) + +#define AVRC_PF_SETUP_MENU_BIT_NO 10 +#define AVRC_PF_SETUP_MENU_MASK 0x04 +#define AVRC_PF_SETUP_MENU_OFF 1 +#define AVRC_PF_SETUP_MENU_SUPPORTED(x) \ + ((x)[AVRC_PF_SETUP_MENU_OFF] & AVRC_PF_SETUP_MENU_MASK) + +#define AVRC_PF_CONTENTS_MENU_BIT_NO 11 +#define AVRC_PF_CONTENTS_MENU_MASK 0x08 +#define AVRC_PF_CONTENTS_MENU_OFF 1 +#define AVRC_PF_CONTENTS_MENU_SUPPORTED(x) \ + ((x)[AVRC_PF_CONTENTS_MENU_OFF] & AVRC_PF_CONTENTS_MENU_MASK) + +#define AVRC_PF_FAVORITE_MENU_BIT_NO 12 +#define AVRC_PF_FAVORITE_MENU_MASK 0x10 +#define AVRC_PF_FAVORITE_MENU_OFF 1 +#define AVRC_PF_FAVORITE_MENU_SUPPORTED(x) \ + ((x)[AVRC_PF_FAVORITE_MENU_OFF] & AVRC_PF_FAVORITE_MENU_MASK) + +#define AVRC_PF_EXIT_BIT_NO 13 +#define AVRC_PF_EXIT_MASK 0x20 +#define AVRC_PF_EXIT_OFF 1 +#define AVRC_PF_EXIT_SUPPORTED(x) ((x)[AVRC_PF_EXIT_OFF] & AVRC_PF_EXIT_MASK) + +#define AVRC_PF_0_BIT_NO 14 +#define AVRC_PF_0_MASK 0x40 +#define AVRC_PF_0_OFF 1 +#define AVRC_PF_0_SUPPORTED(x) ((x)[AVRC_PF_0_OFF] & AVRC_PF_0_MASK) + +#define AVRC_PF_1_BIT_NO 15 +#define AVRC_PF_1_MASK 0x80 +#define AVRC_PF_1_OFF 1 +#define AVRC_PF_1_SUPPORTED(x) ((x)[AVRC_PF_1_OFF] & AVRC_PF_1_MASK) + +#define AVRC_PF_2_BIT_NO 16 +#define AVRC_PF_2_MASK 0x01 +#define AVRC_PF_2_OFF 2 +#define AVRC_PF_2_SUPPORTED(x) ((x)[AVRC_PF_2_OFF] & AVRC_PF_2_MASK) + +#define AVRC_PF_3_BIT_NO 17 +#define AVRC_PF_3_MASK 0x02 +#define AVRC_PF_3_OFF 2 +#define AVRC_PF_3_SUPPORTED(x) ((x)[AVRC_PF_3_OFF] & AVRC_PF_3_MASK) + +#define AVRC_PF_4_BIT_NO 18 +#define AVRC_PF_4_MASK 0x04 +#define AVRC_PF_4_OFF 2 +#define AVRC_PF_4_SUPPORTED(x) ((x)[AVRC_PF_4_OFF] & AVRC_PF_4_MASK) + +#define AVRC_PF_5_BIT_NO 19 +#define AVRC_PF_5_MASK 0x08 +#define AVRC_PF_5_OFF 2 +#define AVRC_PF_5_SUPPORTED(x) ((x)[AVRC_PF_5_OFF] & AVRC_PF_5_MASK) + +#define AVRC_PF_6_BIT_NO 20 +#define AVRC_PF_6_MASK 0x10 +#define AVRC_PF_6_OFF 2 +#define AVRC_PF_6_SUPPORTED(x) ((x)[AVRC_PF_6_OFF] & AVRC_PF_6_MASK) + +#define AVRC_PF_7_BIT_NO 21 +#define AVRC_PF_7_MASK 0x20 +#define AVRC_PF_7_OFF 2 +#define AVRC_PF_7_SUPPORTED(x) ((x)[AVRC_PF_7_OFF] & AVRC_PF_7_MASK) + +#define AVRC_PF_8_BIT_NO 22 +#define AVRC_PF_8_MASK 0x40 +#define AVRC_PF_8_OFF 2 +#define AVRC_PF_8_SUPPORTED(x) ((x)[AVRC_PF_8_OFF] & AVRC_PF_8_MASK) + +#define AVRC_PF_9_BIT_NO 23 +#define AVRC_PF_9_MASK 0x80 +#define AVRC_PF_9_OFF 2 +#define AVRC_PF_9_SUPPORTED(x) ((x)[AVRC_PF_9_OFF] & AVRC_PF_9_MASK) + +#define AVRC_PF_DOT_BIT_NO 24 +#define AVRC_PF_DOT_MASK 0x01 +#define AVRC_PF_DOT_OFF 3 +#define AVRC_PF_DOT_SUPPORTED(x) ((x)[AVRC_PF_DOT_OFF] & AVRC_PF_DOT_MASK) + +#define AVRC_PF_ENTER_BIT_NO 25 +#define AVRC_PF_ENTER_MASK 0x02 +#define AVRC_PF_ENTER_OFF 3 +#define AVRC_PF_ENTER_SUPPORTED(x) ((x)[AVRC_PF_ENTER_OFF] & AVRC_PF_ENTER_MASK) + +#define AVRC_PF_CLEAR_BIT_NO 26 +#define AVRC_PF_CLEAR_MASK 0x04 +#define AVRC_PF_CLEAR_OFF 3 +#define AVRC_PF_CLEAR_SUPPORTED(x) ((x)[AVRC_PF_CLEAR_OFF] & AVRC_PF_CLEAR_MASK) + +#define AVRC_PF_CHNL_UP_BIT_NO 27 +#define AVRC_PF_CHNL_UP_MASK 0x08 +#define AVRC_PF_CHNL_UP_OFF 3 +#define AVRC_PF_CHNL_UP_SUPPORTED(x) \ + ((x)[AVRC_PF_CHNL_UP_OFF] & AVRC_PF_CHNL_UP_MASK) + +#define AVRC_PF_CHNL_DOWN_BIT_NO 28 +#define AVRC_PF_CHNL_DOWN_MASK 0x10 +#define AVRC_PF_CHNL_DOWN_OFF 3 +#define AVRC_PF_CHNL_DOWN_SUPPORTED(x) \ + ((x)[AVRC_PF_CHNL_DOWN_OFF] & AVRC_PF_CHNL_DOWN_MASK) + +#define AVRC_PF_PREV_CHNL_BIT_NO 29 +#define AVRC_PF_PREV_CHNL_MASK 0x20 +#define AVRC_PF_PREV_CHNL_OFF 3 +#define AVRC_PF_PREV_CHNL_SUPPORTED(x) \ + ((x)[AVRC_PF_PREV_CHNL_OFF] & AVRC_PF_PREV_CHNL_MASK) + +#define AVRC_PF_SOUND_SEL_BIT_NO 30 +#define AVRC_PF_SOUND_SEL_MASK 0x40 +#define AVRC_PF_SOUND_SEL_OFF 3 +#define AVRC_PF_SOUND_SEL_SUPPORTED(x) \ + ((x)[AVRC_PF_SOUND_SEL_OFF] & AVRC_PF_SOUND_SEL_MASK) + +#define AVRC_PF_INPUT_SEL_BIT_NO 31 +#define AVRC_PF_INPUT_SEL_MASK 0x80 +#define AVRC_PF_INPUT_SEL_OFF 3 +#define AVRC_PF_INPUT_SEL_SUPPORTED(x) \ + ((x)[AVRC_PF_INPUT_SEL_OFF] & AVRC_PF_INPUT_SEL_MASK) + +#define AVRC_PF_DISP_INFO_BIT_NO 32 +#define AVRC_PF_DISP_INFO_MASK 0x01 +#define AVRC_PF_DISP_INFO_OFF 4 +#define AVRC_PF_DISP_INFO_SUPPORTED(x) \ + ((x)[AVRC_PF_DISP_INFO_OFF] & AVRC_PF_DISP_INFO_MASK) + +#define AVRC_PF_HELP_BIT_NO 33 +#define AVRC_PF_HELP_MASK 0x02 +#define AVRC_PF_HELP_OFF 4 +#define AVRC_PF_HELP_SUPPORTED(x) ((x)[AVRC_PF_HELP_OFF] & AVRC_PF_HELP_MASK) + +#define AVRC_PF_PAGE_UP_BIT_NO 34 +#define AVRC_PF_PAGE_UP_MASK 0x04 +#define AVRC_PF_PAGE_UP_OFF 4 +#define AVRC_PF_PAGE_UP_SUPPORTED(x) \ + ((x)[AVRC_PF_PAGE_UP_OFF] & AVRC_PF_PAGE_UP_MASK) + +#define AVRC_PF_PAGE_DOWN_BIT_NO 35 +#define AVRC_PF_PAGE_DOWN_MASK 0x08 +#define AVRC_PF_PAGE_DOWN_OFF 4 +#define AVRC_PF_PAGE_DOWN_SUPPORTED(x) \ + ((x)[AVRC_PF_PAGE_DOWN_OFF] & AVRC_PF_PAGE_DOWN_MASK) + +#define AVRC_PF_POWER_BIT_NO 36 +#define AVRC_PF_POWER_MASK 0x10 +#define AVRC_PF_POWER_OFF 4 +#define AVRC_PF_POWER_SUPPORTED(x) ((x)[AVRC_PF_POWER_OFF] & AVRC_PF_POWER_MASK) + +#define AVRC_PF_VOL_UP_BIT_NO 37 +#define AVRC_PF_VOL_UP_MASK 0x20 +#define AVRC_PF_VOL_UP_OFF 4 +#define AVRC_PF_VOL_UP_SUPPORTED(x) \ + ((x)[AVRC_PF_VOL_UP_OFF] & AVRC_PF_VOL_UP_MASK) + +#define AVRC_PF_VOL_DOWN_BIT_NO 38 +#define AVRC_PF_VOL_DOWN_MASK 0x40 +#define AVRC_PF_VOL_DOWN_OFF 4 +#define AVRC_PF_VOL_DOWN_SUPPORTED(x) \ + ((x)[AVRC_PF_VOL_DOWN_OFF] & AVRC_PF_VOL_DOWN_MASK) + +#define AVRC_PF_MUTE_BIT_NO 39 +#define AVRC_PF_MUTE_MASK 0x80 +#define AVRC_PF_MUTE_OFF 4 +#define AVRC_PF_MUTE_SUPPORTED(x) ((x)[AVRC_PF_MUTE_OFF] & AVRC_PF_MUTE_MASK) + +#define AVRC_PF_PLAY_BIT_NO 40 +#define AVRC_PF_PLAY_MASK 0x01 +#define AVRC_PF_PLAY_OFF 5 +#define AVRC_PF_PLAY_SUPPORTED(x) ((x)[AVRC_PF_PLAY_OFF] & AVRC_PF_PLAY_MASK) + +#define AVRC_PF_STOP_BIT_NO 41 +#define AVRC_PF_STOP_MASK 0x02 +#define AVRC_PF_STOP_OFF 5 +#define AVRC_PF_STOP_SUPPORTED(x) ((x)[AVRC_PF_STOP_OFF] & AVRC_PF_STOP_MASK) + +#define AVRC_PF_PAUSE_BIT_NO 42 +#define AVRC_PF_PAUSE_MASK 0x04 +#define AVRC_PF_PAUSE_OFF 5 +#define AVRC_PF_PAUSE_SUPPORTED(x) ((x)[AVRC_PF_PAUSE_OFF] & AVRC_PF_PAUSE_MASK) + +#define AVRC_PF_RECORD_BIT_NO 43 +#define AVRC_PF_RECORD_MASK 0x08 +#define AVRC_PF_RECORD_OFF 5 +#define AVRC_PF_RECORD_SUPPORTED(x) \ + ((x)[AVRC_PF_RECORD_OFF] & AVRC_PF_RECORD_MASK) + +#define AVRC_PF_REWIND_BIT_NO 44 +#define AVRC_PF_REWIND_MASK 0x10 +#define AVRC_PF_REWIND_OFF 5 +#define AVRC_PF_REWIND_SUPPORTED(x) \ + ((x)[AVRC_PF_REWIND_OFF] & AVRC_PF_REWIND_MASK) + +#define AVRC_PF_FAST_FWD_BIT_NO 45 +#define AVRC_PF_FAST_FWD_MASK 0x20 +#define AVRC_PF_FAST_FWD_OFF 5 +#define AVRC_PF_FAST_FWD_SUPPORTED(x) \ + ((x)[AVRC_PF_FAST_FWD_OFF] & AVRC_PF_FAST_FWD_MASK) + +#define AVRC_PF_EJECT_BIT_NO 46 +#define AVRC_PF_EJECT_MASK 0x40 +#define AVRC_PF_EJECT_OFF 5 +#define AVRC_PF_EJECT_SUPPORTED(x) ((x)[AVRC_PF_EJECT_OFF] & AVRC_PF_EJECT_MASK) + +#define AVRC_PF_FORWARD_BIT_NO 47 +#define AVRC_PF_FORWARD_MASK 0x80 +#define AVRC_PF_FORWARD_OFF 5 +#define AVRC_PF_FORWARD_SUPPORTED(x) \ + ((x)[AVRC_PF_FORWARD_OFF] & AVRC_PF_FORWARD_MASK) + +#define AVRC_PF_BACKWARD_BIT_NO 48 +#define AVRC_PF_BACKWARD_MASK 0x01 +#define AVRC_PF_BACKWARD_OFF 6 +#define AVRC_PF_BACKWARD_SUPPORTED(x) \ + ((x)[AVRC_PF_BACKWARD_OFF] & AVRC_PF_BACKWARD_MASK) + +#define AVRC_PF_ANGLE_BIT_NO 49 +#define AVRC_PF_ANGLE_MASK 0x02 +#define AVRC_PF_ANGLE_OFF 6 +#define AVRC_PF_ANGLE_SUPPORTED(x) ((x)[AVRC_PF_ANGLE_OFF] & AVRC_PF_ANGLE_MASK) + +#define AVRC_PF_SUBPICTURE_BIT_NO 50 +#define AVRC_PF_SUBPICTURE_MASK 0x04 +#define AVRC_PF_SUBPICTURE_OFF 6 +#define AVRC_PF_SUBPICTURE_SUPPORTED(x) \ + ((x)[AVRC_PF_SUBPICTURE_OFF] & AVRC_PF_SUBPICTURE_MASK) + +#define AVRC_PF_F1_BIT_NO 51 +#define AVRC_PF_F1_MASK 0x08 +#define AVRC_PF_F1_OFF 6 +#define AVRC_PF_F1_SUPPORTED(x) ((x)[AVRC_PF_F1_OFF] & AVRC_PF_F1_MASK) + +#define AVRC_PF_F2_BIT_NO 52 +#define AVRC_PF_F2_MASK 0x10 +#define AVRC_PF_F2_OFF 6 +#define AVRC_PF_F2_SUPPORTED(x) ((x)[AVRC_PF_F2_OFF] & AVRC_PF_F2_MASK) + +#define AVRC_PF_F3_BIT_NO 53 +#define AVRC_PF_F3_MASK 0x20 +#define AVRC_PF_F3_OFF 6 +#define AVRC_PF_F3_SUPPORTED(x) ((x)[AVRC_PF_F3_OFF] & AVRC_PF_F3_MASK) + +#define AVRC_PF_F4_BIT_NO 54 +#define AVRC_PF_F4_MASK 0x40 +#define AVRC_PF_F4_OFF 6 +#define AVRC_PF_F4_SUPPORTED(x) ((x)[AVRC_PF_F4_OFF] & AVRC_PF_F4_MASK) + +#define AVRC_PF_F5_BIT_NO 55 +#define AVRC_PF_F5_MASK 0x80 +#define AVRC_PF_F5_OFF 6 +#define AVRC_PF_F5_SUPPORTED(x) ((x)[AVRC_PF_F5_OFF] & AVRC_PF_F5_MASK) /* Vendor unique. This PASSTHROUGH command is supported. */ -#define AVRC_PF_VENDOR_BIT_NO 56 -#define AVRC_PF_VENDOR_MASK 0x01 -#define AVRC_PF_VENDOR_OFF 7 -#define AVRC_PF_VENDOR_SUPPORTED(x) ((x)[AVRC_PF_VENDOR_OFF] & AVRC_PF_VENDOR_MASK) +#define AVRC_PF_VENDOR_BIT_NO 56 +#define AVRC_PF_VENDOR_MASK 0x01 +#define AVRC_PF_VENDOR_OFF 7 +#define AVRC_PF_VENDOR_SUPPORTED(x) \ + ((x)[AVRC_PF_VENDOR_OFF] & AVRC_PF_VENDOR_MASK) /* Basic Group Navigation. This overrules the SDP entry as it is set per * player.7 */ -#define AVRC_PF_GROUP_NAVI_BIT_NO 57 -#define AVRC_PF_GROUP_NAVI_MASK 0x02 -#define AVRC_PF_GROUP_NAVI_OFF 7 -#define AVRC_PF_GROUP_NAVI_SUPPORTED(x) ((x)[AVRC_PF_GROUP_NAVI_OFF] & AVRC_PF_GROUP_NAVI_MASK) +#define AVRC_PF_GROUP_NAVI_BIT_NO 57 +#define AVRC_PF_GROUP_NAVI_MASK 0x02 +#define AVRC_PF_GROUP_NAVI_OFF 7 +#define AVRC_PF_GROUP_NAVI_SUPPORTED(x) \ + ((x)[AVRC_PF_GROUP_NAVI_OFF] & AVRC_PF_GROUP_NAVI_MASK) /* Advanced Control Player. This bit is set if the player supports at least * AVRCP 1.4. */ -#define AVRC_PF_ADV_CTRL_BIT_NO 58 -#define AVRC_PF_ADV_CTRL_MASK 0x04 -#define AVRC_PF_ADV_CTRL_OFF 7 -#define AVRC_PF_ADV_CTRL_SUPPORTED(x) ((x)[AVRC_PF_ADV_CTRL_OFF] & AVRC_PF_ADV_CTRL_MASK) +#define AVRC_PF_ADV_CTRL_BIT_NO 58 +#define AVRC_PF_ADV_CTRL_MASK 0x04 +#define AVRC_PF_ADV_CTRL_OFF 7 +#define AVRC_PF_ADV_CTRL_SUPPORTED(x) \ + ((x)[AVRC_PF_ADV_CTRL_OFF] & AVRC_PF_ADV_CTRL_MASK) /* Browsing. This bit is set if the player supports browsing. */ -#define AVRC_PF_BROWSE_BIT_NO 59 -#define AVRC_PF_BROWSE_MASK 0x08 -#define AVRC_PF_BROWSE_OFF 7 -#define AVRC_PF_BROWSE_SUPPORTED(x) ((x)[AVRC_PF_BROWSE_OFF] & AVRC_PF_BROWSE_MASK) +#define AVRC_PF_BROWSE_BIT_NO 59 +#define AVRC_PF_BROWSE_MASK 0x08 +#define AVRC_PF_BROWSE_OFF 7 +#define AVRC_PF_BROWSE_SUPPORTED(x) \ + ((x)[AVRC_PF_BROWSE_OFF] & AVRC_PF_BROWSE_MASK) /* Searching. This bit is set if the player supports searching. */ -#define AVRC_PF_SEARCH_BIT_NO 60 -#define AVRC_PF_SEARCH_MASK 0x10 -#define AVRC_PF_SEARCH_OFF 7 -#define AVRC_PF_SEARCH_SUPPORTED(x) ((x)[AVRC_PF_SEARCH_OFF] & AVRC_PF_SEARCH_MASK) +#define AVRC_PF_SEARCH_BIT_NO 60 +#define AVRC_PF_SEARCH_MASK 0x10 +#define AVRC_PF_SEARCH_OFF 7 +#define AVRC_PF_SEARCH_SUPPORTED(x) \ + ((x)[AVRC_PF_SEARCH_OFF] & AVRC_PF_SEARCH_MASK) /* AddToNowPlaying. This bit is set if the player supports the AddToNowPlaying * command. */ -#define AVRC_PF_ADD2NOWPLAY_BIT_NO 61 -#define AVRC_PF_ADD2NOWPLAY_MASK 0x20 -#define AVRC_PF_ADD2NOWPLAY_OFF 7 -#define AVRC_PF_ADD2NOWPLAY_SUPPORTED(x) ((x)[AVRC_PF_ADD2NOWPLAY_OFF] & AVRC_PF_ADD2NOWPLAY_MASK) +#define AVRC_PF_ADD2NOWPLAY_BIT_NO 61 +#define AVRC_PF_ADD2NOWPLAY_MASK 0x20 +#define AVRC_PF_ADD2NOWPLAY_OFF 7 +#define AVRC_PF_ADD2NOWPLAY_SUPPORTED(x) \ + ((x)[AVRC_PF_ADD2NOWPLAY_OFF] & AVRC_PF_ADD2NOWPLAY_MASK) /* UIDs unique in player browse tree. This bit is set if the player is able to * maintain unique UIDs across the player browse tree. */ -#define AVRC_PF_UID_UNIQUE_BIT_NO 62 -#define AVRC_PF_UID_UNIQUE_MASK 0x40 -#define AVRC_PF_UID_UNIQUE_OFF 7 -#define AVRC_PF_UID_UNIQUE_SUPPORTED(x) ((x)[AVRC_PF_UID_UNIQUE_OFF] & AVRC_PF_UID_UNIQUE_MASK) +#define AVRC_PF_UID_UNIQUE_BIT_NO 62 +#define AVRC_PF_UID_UNIQUE_MASK 0x40 +#define AVRC_PF_UID_UNIQUE_OFF 7 +#define AVRC_PF_UID_UNIQUE_SUPPORTED(x) \ + ((x)[AVRC_PF_UID_UNIQUE_OFF] & AVRC_PF_UID_UNIQUE_MASK) /* OnlyBrowsableWhenAddressed. This bit is set if the player is only able to be * browsed when it is set as the Addressed Player. */ -#define AVRC_PF_BR_WH_ADDR_BIT_NO 63 -#define AVRC_PF_BR_WH_ADDR_MASK 0x80 -#define AVRC_PF_BR_WH_ADDR_OFF 7 -#define AVRC_PF_BR_WH_ADDR_SUPPORTED(x) ((x)[AVRC_PF_BR_WH_ADDR_OFF] & AVRC_PF_BR_WH_ADDR_MASK) +#define AVRC_PF_BR_WH_ADDR_BIT_NO 63 +#define AVRC_PF_BR_WH_ADDR_MASK 0x80 +#define AVRC_PF_BR_WH_ADDR_OFF 7 +#define AVRC_PF_BR_WH_ADDR_SUPPORTED(x) \ + ((x)[AVRC_PF_BR_WH_ADDR_OFF] & AVRC_PF_BR_WH_ADDR_MASK) /* OnlySearchableWhenAddressed. This bit is set if the player is only able to * be searched when it is set as the Addressed player. */ -#define AVRC_PF_SEARCH_WH_ADDR_BIT_NO 64 -#define AVRC_PF_SEARCH_WH_ADDR_MASK 0x01 -#define AVRC_PF_SEARCH_WH_ADDR_OFF 8 -#define AVRC_PF_SEARCH_WH_ADDR_SUPPORTED(x) ((x)[AVRC_PF_SEARCH_WH_ADDR_OFF] & AVRC_PF_SEARCH_WH_ADDR_MASK) +#define AVRC_PF_SEARCH_WH_ADDR_BIT_NO 64 +#define AVRC_PF_SEARCH_WH_ADDR_MASK 0x01 +#define AVRC_PF_SEARCH_WH_ADDR_OFF 8 +#define AVRC_PF_SEARCH_WH_ADDR_SUPPORTED(x) \ + ((x)[AVRC_PF_SEARCH_WH_ADDR_OFF] & AVRC_PF_SEARCH_WH_ADDR_MASK) /* NowPlaying. This bit is set if the player supports the NowPlaying folder. * Note that for all players that support browsing this bit shall be set */ -#define AVRC_PF_NOW_PLAY_BIT_NO 65 -#define AVRC_PF_NOW_PLAY_MASK 0x02 -#define AVRC_PF_NOW_PLAY_OFF 8 -#define AVRC_PF_NOW_PLAY_SUPPORTED(x) ((x)[AVRC_PF_NOW_PLAY_OFF] & AVRC_PF_NOW_PLAY_MASK) +#define AVRC_PF_NOW_PLAY_BIT_NO 65 +#define AVRC_PF_NOW_PLAY_MASK 0x02 +#define AVRC_PF_NOW_PLAY_OFF 8 +#define AVRC_PF_NOW_PLAY_SUPPORTED(x) \ + ((x)[AVRC_PF_NOW_PLAY_OFF] & AVRC_PF_NOW_PLAY_MASK) /* UIDPersistency. This bit is set if the Player is able to persist UID values * between AVRCP Browse Reconnect */ -#define AVRC_PF_UID_PERSIST_BIT_NO 66 -#define AVRC_PF_UID_PERSIST_MASK 0x04 -#define AVRC_PF_UID_PERSIST_OFF 8 -#define AVRC_PF_UID_PERSIST_SUPPORTED(x) ((x)[AVRC_PF_UID_PERSIST_OFF] & AVRC_PF_UID_PERSIST_MASK) +#define AVRC_PF_UID_PERSIST_BIT_NO 66 +#define AVRC_PF_UID_PERSIST_MASK 0x04 +#define AVRC_PF_UID_PERSIST_OFF 8 +#define AVRC_PF_UID_PERSIST_SUPPORTED(x) \ + ((x)[AVRC_PF_UID_PERSIST_OFF] & AVRC_PF_UID_PERSIST_MASK) /* NumberOfItems. This bit is set if player supports the GetTotalNumberOfItems * browsing command. */ -#define AVRC_PF_GET_NUM_OF_ITEMS_BIT_NO 67 -#define AVRC_PF_GET_NUM_OF_ITEMS_MASK 0x08 -#define AVRC_PF_GET_NUM_OF_ITEMS_OFF 8 -#define AVRC_PF_GET_NUM_OF_ITEMS_SUPPORTED(x) ((x)[AVRC_PF_GET_NUM_OF_ITEMS_OFF] & AVRC_PF_GET_NUM_OF_ITEMS_MASK) +#define AVRC_PF_GET_NUM_OF_ITEMS_BIT_NO 67 +#define AVRC_PF_GET_NUM_OF_ITEMS_MASK 0x08 +#define AVRC_PF_GET_NUM_OF_ITEMS_OFF 8 +#define AVRC_PF_GET_NUM_OF_ITEMS_SUPPORTED(x) \ + ((x)[AVRC_PF_GET_NUM_OF_ITEMS_OFF] & AVRC_PF_GET_NUM_OF_ITEMS_MASK) /***************************************************************************** * data type definitions @@ -821,677 +872,666 @@ typedef uint8_t tAVRC_UID[AVRC_UID_SIZE]; /* This structure contains the header parameters of an AV/C message. */ -typedef struct -{ - uint8_t ctype; /* Command type. */ - uint8_t subunit_type; /* Subunit type. */ - uint8_t subunit_id; /* Subunit ID. This value is typically ignored in AVRCP, - * except for VENDOR DEPENDENT messages when the value is - * vendor-dependent. Value range is 0-7. */ - uint8_t opcode; /* Op Code (passthrough, vendor, etc) */ +typedef struct { + uint8_t ctype; /* Command type. */ + uint8_t subunit_type; /* Subunit type. */ + uint8_t subunit_id; /* Subunit ID. This value is typically ignored in AVRCP, + * except for VENDOR DEPENDENT messages when the value is + * vendor-dependent. Value range is 0-7. */ + uint8_t opcode; /* Op Code (passthrough, vendor, etc) */ } tAVRC_HDR; /* This structure contains a UNIT INFO message. */ -typedef struct -{ - tAVRC_HDR hdr; /* Message header. */ - uint32_t company_id; /* Company identifier. */ - uint8_t unit_type; /* Unit type. Uses the same values as subunit type. */ - uint8_t unit; /* This value is vendor dependent and typically zero. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + uint32_t company_id; /* Company identifier. */ + uint8_t unit_type; /* Unit type. Uses the same values as subunit type. */ + uint8_t unit; /* This value is vendor dependent and typically zero. */ } tAVRC_MSG_UNIT; /* This structure contains a SUBUNIT INFO message. */ -typedef struct -{ - tAVRC_HDR hdr; /* Message header. */ - uint8_t subunit_type[AVRC_SUB_TYPE_LEN]; - /* Array containing subunit type values. */ - bool panel; /* true if the panel subunit type is in the - * subunit_type array, false otherwise. */ - uint8_t page; /* Specifies which part of the subunit type table is - * returned. For AVRCP it is typically zero. - * Value range is 0-7. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + uint8_t subunit_type[AVRC_SUB_TYPE_LEN]; + /* Array containing subunit type values. */ + bool panel; /* true if the panel subunit type is in the + * subunit_type array, false otherwise. */ + uint8_t page; /* Specifies which part of the subunit type table is + * returned. For AVRCP it is typically zero. + * Value range is 0-7. */ } tAVRC_MSG_SUB; /* This structure contains a VENDOR DEPENDENT message. */ -typedef struct -{ - tAVRC_HDR hdr; /* Message header. */ - uint32_t company_id; /* Company identifier. */ - uint8_t *p_vendor_data;/* Pointer to vendor dependent data. */ - uint16_t vendor_len; /* Length in bytes of vendor dependent data. */ +typedef struct { + tAVRC_HDR hdr; /* Message header. */ + uint32_t company_id; /* Company identifier. */ + uint8_t* p_vendor_data; /* Pointer to vendor dependent data. */ + uint16_t vendor_len; /* Length in bytes of vendor dependent data. */ } tAVRC_MSG_VENDOR; /* PASS THROUGH message structure */ -typedef struct -{ - tAVRC_HDR hdr; /* hdr.ctype Unused. - * hdr.subunit_type Unused. - * hdr.subunit_id Unused. */ - uint8_t op_id; /* Operation ID. */ - uint8_t state; /* Keypress state. */ - uint8_t *p_pass_data;/* Pointer to data. This parameter is only valid - * when the op_id is AVRC_ID_VENDOR.*/ - uint8_t pass_len; /* Length in bytes of data. This parameter is only - * valid when the op_id is AVRC_ID_VENDOR.*/ +typedef struct { + tAVRC_HDR hdr; /* hdr.ctype Unused. + * hdr.subunit_type Unused. + * hdr.subunit_id Unused. */ + uint8_t op_id; /* Operation ID. */ + uint8_t state; /* Keypress state. */ + uint8_t* p_pass_data; /* Pointer to data. This parameter is only valid + * when the op_id is AVRC_ID_VENDOR.*/ + uint8_t pass_len; /* Length in bytes of data. This parameter is only + * valid when the op_id is AVRC_ID_VENDOR.*/ } tAVRC_MSG_PASS; /* Command/Response indicator. */ -#define AVRC_CMD AVCT_CMD /* Command message */ -#define AVRC_RSP AVCT_RSP /* Response message */ +#define AVRC_CMD AVCT_CMD /* Command message */ +#define AVRC_RSP AVCT_RSP /* Response message */ /* Browsing channel message structure */ -typedef struct -{ - tAVRC_HDR hdr; /* hdr.ctype AVRC_CMD or AVRC_RSP. - * hdr.subunit_type Unused. - * hdr.subunit_id Unused. */ - uint8_t *p_browse_data; /* Pointer to data. */ - uint16_t browse_len; /* Length in bytes of data. */ - BT_HDR *p_browse_pkt; /* The GKI buffer received. Set to NULL, if the callback function wants to keep the buffer */ +typedef struct { + tAVRC_HDR hdr; /* hdr.ctype AVRC_CMD or AVRC_RSP. + * hdr.subunit_type Unused. + * hdr.subunit_id Unused. */ + uint8_t* p_browse_data; /* Pointer to data. */ + uint16_t browse_len; /* Length in bytes of data. */ + BT_HDR* p_browse_pkt; /* The GKI buffer received. Set to NULL, if the callback + function wants to keep the buffer */ } tAVRC_MSG_BROWSE; /* This is a union of all message type structures. */ -typedef union -{ - tAVRC_HDR hdr; /* Message header. */ - tAVRC_MSG_UNIT unit; /* UNIT INFO message. */ - tAVRC_MSG_SUB sub; /* SUBUNIT INFO message. */ - tAVRC_MSG_VENDOR vendor; /* VENDOR DEPENDENT message. */ - tAVRC_MSG_PASS pass; /* PASS THROUGH message. */ - tAVRC_MSG_BROWSE browse; /* messages thru browsing channel */ +typedef union { + tAVRC_HDR hdr; /* Message header. */ + tAVRC_MSG_UNIT unit; /* UNIT INFO message. */ + tAVRC_MSG_SUB sub; /* SUBUNIT INFO message. */ + tAVRC_MSG_VENDOR vendor; /* VENDOR DEPENDENT message. */ + tAVRC_MSG_PASS pass; /* PASS THROUGH message. */ + tAVRC_MSG_BROWSE browse; /* messages thru browsing channel */ } tAVRC_MSG; /* macros */ -#define AVRC_IS_VALID_CAP_ID(a) ((((a) == AVRC_CAP_COMPANY_ID) || ((a) == AVRC_CAP_EVENTS_SUPPORTED)) ? true : false) +#define AVRC_IS_VALID_CAP_ID(a) \ + ((((a) == AVRC_CAP_COMPANY_ID) || ((a) == AVRC_CAP_EVENTS_SUPPORTED)) \ + ? true \ + : false) -#define AVRC_IS_VALID_EVENT_ID(a) ((((a) >= AVRC_EVT_PLAY_STATUS_CHANGE) && \ - ((a) <= AVRC_EVT_VOLUME_CHANGE)) ? true : false) +#define AVRC_IS_VALID_EVENT_ID(a) \ + ((((a) >= AVRC_EVT_PLAY_STATUS_CHANGE) && ((a) <= AVRC_EVT_VOLUME_CHANGE)) \ + ? true \ + : false) -#define AVRC_IS_VALID_ATTRIBUTE(a) ((((((a) > 0) && (a) <= AVRC_PLAYER_SETTING_SCAN)) || \ - ((a) >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)) ? true : false) +#define AVRC_IS_VALID_ATTRIBUTE(a) \ + ((((((a) > 0) && (a) <= AVRC_PLAYER_SETTING_SCAN)) || \ + ((a) >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)) \ + ? true \ + : false) -#define AVRC_IS_VALID_MEDIA_ATTRIBUTE(a) (((a) >= AVRC_MEDIA_ATTR_ID_TITLE) && \ - ((a) <= AVRC_MEDIA_ATTR_ID_PLAYING_TIME) ? true : false) +#define AVRC_IS_VALID_MEDIA_ATTRIBUTE(a) \ + (((a) >= AVRC_MEDIA_ATTR_ID_TITLE) && \ + ((a) <= AVRC_MEDIA_ATTR_ID_PLAYING_TIME) \ + ? true \ + : false) -#define AVRC_IS_VALID_BATTERY_STATUS(a) (((a) <= AVRC_BATTERY_STATUS_FULL_CHARGE) ? true : false) +#define AVRC_IS_VALID_BATTERY_STATUS(a) \ + (((a) <= AVRC_BATTERY_STATUS_FULL_CHARGE) ? true : false) -#define AVRC_IS_VALID_SYSTEM_STATUS(a) (((a) <= AVRC_SYSTEMSTATE_PWR_UNPLUGGED) ? true : false) +#define AVRC_IS_VALID_SYSTEM_STATUS(a) \ + (((a) <= AVRC_SYSTEMSTATE_PWR_UNPLUGGED) ? true : false) -#define AVRC_IS_VALID_GROUP(a) (((a) <= AVRC_PDU_PREV_GROUP) ? true : false) +#define AVRC_IS_VALID_GROUP(a) (((a) <= AVRC_PDU_PREV_GROUP) ? true : false) /* Company ID is 24-bit integer We can not use the macros in bt_types.h */ -#define AVRC_CO_ID_TO_BE_STREAM(p, u32) {*(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)(u32); } -#define AVRC_BE_STREAM_TO_CO_ID(u32, p) {(u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + (((uint32_t)(*(p))) << 16)); (p) += 3;} +#define AVRC_CO_ID_TO_BE_STREAM(p, u32) \ + { \ + *(p)++ = (uint8_t)((u32) >> 16); \ + *(p)++ = (uint8_t)((u32) >> 8); \ + *(p)++ = (uint8_t)(u32); \ + } +#define AVRC_BE_STREAM_TO_CO_ID(u32, p) \ + { \ + (u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + \ + (((uint32_t)(*(p))) << 16)); \ + (p) += 3; \ + } /***************************************************************************** * data type definitions ****************************************************************************/ -#define AVRC_MAX_APP_ATTR_SIZE 16 -#define AVRC_MAX_CHARSET_SIZE 16 -#define AVRC_MAX_ELEM_ATTR_SIZE 8 +#define AVRC_MAX_APP_ATTR_SIZE 16 +#define AVRC_MAX_CHARSET_SIZE 16 +#define AVRC_MAX_ELEM_ATTR_SIZE 8 /***************************************************************************** * Metadata transfer Building/Parsing definitions ****************************************************************************/ typedef struct { - uint16_t charset_id; - uint16_t str_len; - uint8_t *p_str; + uint16_t charset_id; + uint16_t str_len; + uint8_t* p_str; } tAVRC_FULL_NAME; typedef struct { - uint16_t str_len; - uint8_t *p_str; + uint16_t str_len; + uint8_t* p_str; } tAVRC_NAME; #ifndef AVRC_CAP_MAX_NUM_COMP_ID -#define AVRC_CAP_MAX_NUM_COMP_ID 4 +#define AVRC_CAP_MAX_NUM_COMP_ID 4 #endif #ifndef AVRC_CAP_MAX_NUM_EVT_ID -#define AVRC_CAP_MAX_NUM_EVT_ID 16 +#define AVRC_CAP_MAX_NUM_EVT_ID 16 #endif -typedef union -{ - uint32_t company_id[AVRC_CAP_MAX_NUM_COMP_ID]; - uint8_t event_id[AVRC_CAP_MAX_NUM_EVT_ID]; +typedef union { + uint32_t company_id[AVRC_CAP_MAX_NUM_COMP_ID]; + uint8_t event_id[AVRC_CAP_MAX_NUM_EVT_ID]; } tAVRC_CAPS_PARAM; -typedef struct -{ - uint8_t attr_id; - uint8_t attr_val; +typedef struct { + uint8_t attr_id; + uint8_t attr_val; } tAVRC_APP_SETTING; -typedef struct -{ - uint8_t attr_id; - uint16_t charset_id; - uint8_t str_len; - uint8_t *p_str; +typedef struct { + uint8_t attr_id; + uint16_t charset_id; + uint8_t str_len; + uint8_t* p_str; } tAVRC_APP_SETTING_TEXT; typedef uint8_t tAVRC_FEATURE_MASK[AVRC_FEATURE_MASK_SIZE]; -typedef struct -{ - uint16_t player_id; /* A unique identifier for this media player.*/ - uint8_t major_type; /* Use AVRC_MJ_TYPE_AUDIO, AVRC_MJ_TYPE_VIDEO, AVRC_MJ_TYPE_BC_AUDIO, or AVRC_MJ_TYPE_BC_VIDEO.*/ - uint32_t sub_type; /* Use AVRC_SUB_TYPE_NONE, AVRC_SUB_TYPE_AUDIO_BOOK, or AVRC_SUB_TYPE_PODCAST*/ - uint8_t play_status; /* Use AVRC_PLAYSTATE_STOPPED, AVRC_PLAYSTATE_PLAYING, AVRC_PLAYSTATE_PAUSED, AVRC_PLAYSTATE_FWD_SEEK, - AVRC_PLAYSTATE_REV_SEEK, or AVRC_PLAYSTATE_ERROR*/ - tAVRC_FEATURE_MASK features; /* Supported feature bit mask*/ - tAVRC_FULL_NAME name; /* The player name, name length and character set id.*/ +typedef struct { + uint16_t player_id; /* A unique identifier for this media player.*/ + uint8_t major_type; /* Use AVRC_MJ_TYPE_AUDIO, AVRC_MJ_TYPE_VIDEO, + AVRC_MJ_TYPE_BC_AUDIO, or AVRC_MJ_TYPE_BC_VIDEO.*/ + uint32_t sub_type; /* Use AVRC_SUB_TYPE_NONE, AVRC_SUB_TYPE_AUDIO_BOOK, or + AVRC_SUB_TYPE_PODCAST*/ + uint8_t play_status; /* Use AVRC_PLAYSTATE_STOPPED, AVRC_PLAYSTATE_PLAYING, + AVRC_PLAYSTATE_PAUSED, AVRC_PLAYSTATE_FWD_SEEK, + AVRC_PLAYSTATE_REV_SEEK, or AVRC_PLAYSTATE_ERROR*/ + tAVRC_FEATURE_MASK features; /* Supported feature bit mask*/ + tAVRC_FULL_NAME name; /* The player name, name length and character set id.*/ } tAVRC_ITEM_PLAYER; -typedef struct -{ - tAVRC_UID uid; /* The uid of this folder */ - uint8_t type; /* Use AVRC_FOLDER_TYPE_MIXED, AVRC_FOLDER_TYPE_TITLES, - AVRC_FOLDER_TYPE_ALNUMS, AVRC_FOLDER_TYPE_ARTISTS, AVRC_FOLDER_TYPE_GENRES, - AVRC_FOLDER_TYPE_PLAYLISTS, or AVRC_FOLDER_TYPE_YEARS.*/ - bool playable; /* true, if the folder can be played. */ - tAVRC_FULL_NAME name; /* The folder name, name length and character set id. */ +typedef struct { + tAVRC_UID uid; /* The uid of this folder */ + uint8_t type; /* Use AVRC_FOLDER_TYPE_MIXED, AVRC_FOLDER_TYPE_TITLES, + AVRC_FOLDER_TYPE_ALNUMS, AVRC_FOLDER_TYPE_ARTISTS, + AVRC_FOLDER_TYPE_GENRES, + AVRC_FOLDER_TYPE_PLAYLISTS, or AVRC_FOLDER_TYPE_YEARS.*/ + bool playable; /* true, if the folder can be played. */ + tAVRC_FULL_NAME name; /* The folder name, name length and character set id. */ } tAVRC_ITEM_FOLDER; -typedef struct -{ - uint32_t attr_id; /* Use AVRC_MEDIA_ATTR_ID_TITLE, AVRC_MEDIA_ATTR_ID_ARTIST, AVRC_MEDIA_ATTR_ID_ALBUM, - AVRC_MEDIA_ATTR_ID_TRACK_NUM, AVRC_MEDIA_ATTR_ID_NUM_TRACKS, - AVRC_MEDIA_ATTR_ID_GENRE, AVRC_MEDIA_ATTR_ID_PLAYING_TIME */ - tAVRC_FULL_NAME name; /* The attribute value, value length and character set id. */ +typedef struct { + uint32_t + attr_id; /* Use AVRC_MEDIA_ATTR_ID_TITLE, AVRC_MEDIA_ATTR_ID_ARTIST, + AVRC_MEDIA_ATTR_ID_ALBUM, + AVRC_MEDIA_ATTR_ID_TRACK_NUM, AVRC_MEDIA_ATTR_ID_NUM_TRACKS, + AVRC_MEDIA_ATTR_ID_GENRE, AVRC_MEDIA_ATTR_ID_PLAYING_TIME */ + tAVRC_FULL_NAME + name; /* The attribute value, value length and character set id. */ } tAVRC_ATTR_ENTRY; -typedef struct -{ - tAVRC_UID uid; /* The uid of this media element item */ - uint8_t type; /* Use AVRC_MEDIA_TYPE_AUDIO or AVRC_MEDIA_TYPE_VIDEO. */ - tAVRC_FULL_NAME name; /* The media name, name length and character set id. */ - uint8_t attr_count; /* The number of attributes in p_attr_list */ - tAVRC_ATTR_ENTRY* p_attr_list; /* Attribute entry list. */ +typedef struct { + tAVRC_UID uid; /* The uid of this media element item */ + uint8_t type; /* Use AVRC_MEDIA_TYPE_AUDIO or AVRC_MEDIA_TYPE_VIDEO. */ + tAVRC_FULL_NAME name; /* The media name, name length and character set id. */ + uint8_t attr_count; /* The number of attributes in p_attr_list */ + tAVRC_ATTR_ENTRY* p_attr_list; /* Attribute entry list. */ } tAVRC_ITEM_MEDIA; -typedef struct -{ - uint8_t item_type; /* AVRC_ITEM_PLAYER, AVRC_ITEM_FOLDER, or AVRC_ITEM_MEDIA */ - union - { - tAVRC_ITEM_PLAYER player; /* The properties of a media player item.*/ - tAVRC_ITEM_FOLDER folder; /* The properties of a folder item.*/ - tAVRC_ITEM_MEDIA media; /* The properties of a media item.*/ - } u; +typedef struct { + uint8_t + item_type; /* AVRC_ITEM_PLAYER, AVRC_ITEM_FOLDER, or AVRC_ITEM_MEDIA */ + union { + tAVRC_ITEM_PLAYER player; /* The properties of a media player item.*/ + tAVRC_ITEM_FOLDER folder; /* The properties of a folder item.*/ + tAVRC_ITEM_MEDIA media; /* The properties of a media item.*/ + } u; } tAVRC_ITEM; /* GetCapability */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t capability_id; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t capability_id; } tAVRC_GET_CAPS_CMD; /* ListPlayerAppValues */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t attr_id; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t attr_id; } tAVRC_LIST_APP_VALUES_CMD; /* GetCurAppValue */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t num_attr; - uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t num_attr; + uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; } tAVRC_GET_CUR_APP_VALUE_CMD; /* SetAppValue */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t num_val; - tAVRC_APP_SETTING *p_vals; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t num_val; + tAVRC_APP_SETTING* p_vals; } tAVRC_SET_APP_VALUE_CMD; /* GetAppAttrTxt */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t num_attr; - uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t num_attr; + uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; } tAVRC_GET_APP_ATTR_TXT_CMD; /* GetAppValueTxt */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t attr_id; - uint8_t num_val; - uint8_t vals[AVRC_MAX_APP_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t attr_id; + uint8_t num_val; + uint8_t vals[AVRC_MAX_APP_ATTR_SIZE]; } tAVRC_GET_APP_VAL_TXT_CMD; /* InformCharset */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t num_id; - uint16_t charsets[AVRC_MAX_CHARSET_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t num_id; + uint16_t charsets[AVRC_MAX_CHARSET_SIZE]; } tAVRC_INFORM_CHARSET_CMD; /* InformBatteryStatus */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t battery_status; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t battery_status; } tAVRC_BATTERY_STATUS_CMD; /* GetElemAttrs */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t num_attr; - uint32_t attrs[AVRC_MAX_ELEM_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t num_attr; + uint32_t attrs[AVRC_MAX_ELEM_ATTR_SIZE]; } tAVRC_GET_ELEM_ATTRS_CMD; /* RegNotify */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t event_id; - uint32_t param; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t event_id; + uint32_t param; } tAVRC_REG_NOTIF_CMD; /* SetAddrPlayer */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint16_t player_id; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint16_t player_id; } tAVRC_SET_ADDR_PLAYER_CMD; /* SetBrowsedPlayer */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint16_t player_id; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint16_t player_id; } tAVRC_SET_BR_PLAYER_CMD; /* SetAbsVolume */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t volume; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t volume; } tAVRC_SET_VOLUME_CMD; /* GetFolderItems */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t scope; - uint32_t start_item; - uint32_t end_item; - uint8_t attr_count; - uint32_t *p_attr_list; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t scope; + uint32_t start_item; + uint32_t end_item; + uint8_t attr_count; + uint32_t* p_attr_list; } tAVRC_GET_ITEMS_CMD; /* ChangePath */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint16_t uid_counter; - uint8_t direction; - tAVRC_UID folder_uid; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint16_t uid_counter; + uint8_t direction; + tAVRC_UID folder_uid; } tAVRC_CHG_PATH_CMD; /* GetItemAttrs */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t scope; - tAVRC_UID uid; - uint16_t uid_counter; - uint8_t attr_count; - uint32_t *p_attr_list; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t scope; + tAVRC_UID uid; + uint16_t uid_counter; + uint8_t attr_count; + uint32_t* p_attr_list; } tAVRC_GET_ATTRS_CMD; /* Search */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - tAVRC_FULL_NAME string; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + tAVRC_FULL_NAME string; } tAVRC_SEARCH_CMD; /* PlayItem */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t scope; - tAVRC_UID uid; - uint16_t uid_counter; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t scope; + tAVRC_UID uid; + uint16_t uid_counter; } tAVRC_PLAY_ITEM_CMD; /* AddToNowPlaying */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t scope; - tAVRC_UID uid; - uint16_t uid_counter; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t scope; + tAVRC_UID uid; + uint16_t uid_counter; } tAVRC_ADD_TO_PLAY_CMD; /* GetTotalNumOfItems */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t scope; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t scope; } tAVRC_GET_NUM_OF_ITEMS_CMD; -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ } tAVRC_CMD; /* Continue and Abort */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ - uint8_t target_pdu; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (assigned by AVRC_BldCommand according to pdu) */ + uint8_t target_pdu; } tAVRC_NEXT_CMD; -typedef union -{ - uint8_t pdu; - tAVRC_CMD cmd; - tAVRC_GET_CAPS_CMD get_caps; /* GetCapability */ - tAVRC_CMD list_app_attr; /* ListPlayerAppAttr */ - tAVRC_LIST_APP_VALUES_CMD list_app_values; /* ListPlayerAppValues */ - tAVRC_GET_CUR_APP_VALUE_CMD get_cur_app_val; /* GetCurAppValue */ - tAVRC_SET_APP_VALUE_CMD set_app_val; /* SetAppValue */ - tAVRC_GET_APP_ATTR_TXT_CMD get_app_attr_txt; /* GetAppAttrTxt */ - tAVRC_GET_APP_VAL_TXT_CMD get_app_val_txt; /* GetAppValueTxt */ - tAVRC_INFORM_CHARSET_CMD inform_charset; /* InformCharset */ - tAVRC_BATTERY_STATUS_CMD inform_battery_status; /* InformBatteryStatus */ - tAVRC_GET_ELEM_ATTRS_CMD get_elem_attrs; /* GetElemAttrs */ - tAVRC_CMD get_play_status; /* GetPlayStatus */ - tAVRC_REG_NOTIF_CMD reg_notif; /* RegNotify */ - tAVRC_NEXT_CMD continu; /* Continue */ - tAVRC_NEXT_CMD abort; /* Abort */ - - tAVRC_SET_ADDR_PLAYER_CMD addr_player; /* SetAddrPlayer */ - tAVRC_SET_VOLUME_CMD volume; /* SetAbsVolume */ - tAVRC_SET_BR_PLAYER_CMD br_player; /* SetBrowsedPlayer */ - tAVRC_GET_ITEMS_CMD get_items; /* GetFolderItems */ - tAVRC_CHG_PATH_CMD chg_path; /* ChangePath */ - tAVRC_GET_ATTRS_CMD get_attrs; /* GetItemAttrs */ - tAVRC_SEARCH_CMD search; /* Search */ - tAVRC_PLAY_ITEM_CMD play_item; /* PlayItem */ - tAVRC_ADD_TO_PLAY_CMD add_to_play; /* AddToNowPlaying */ - tAVRC_GET_NUM_OF_ITEMS_CMD get_num_of_items; /* GetTotalNumOfItems */ +typedef union { + uint8_t pdu; + tAVRC_CMD cmd; + tAVRC_GET_CAPS_CMD get_caps; /* GetCapability */ + tAVRC_CMD list_app_attr; /* ListPlayerAppAttr */ + tAVRC_LIST_APP_VALUES_CMD list_app_values; /* ListPlayerAppValues */ + tAVRC_GET_CUR_APP_VALUE_CMD get_cur_app_val; /* GetCurAppValue */ + tAVRC_SET_APP_VALUE_CMD set_app_val; /* SetAppValue */ + tAVRC_GET_APP_ATTR_TXT_CMD get_app_attr_txt; /* GetAppAttrTxt */ + tAVRC_GET_APP_VAL_TXT_CMD get_app_val_txt; /* GetAppValueTxt */ + tAVRC_INFORM_CHARSET_CMD inform_charset; /* InformCharset */ + tAVRC_BATTERY_STATUS_CMD inform_battery_status; /* InformBatteryStatus */ + tAVRC_GET_ELEM_ATTRS_CMD get_elem_attrs; /* GetElemAttrs */ + tAVRC_CMD get_play_status; /* GetPlayStatus */ + tAVRC_REG_NOTIF_CMD reg_notif; /* RegNotify */ + tAVRC_NEXT_CMD continu; /* Continue */ + tAVRC_NEXT_CMD abort; /* Abort */ + + tAVRC_SET_ADDR_PLAYER_CMD addr_player; /* SetAddrPlayer */ + tAVRC_SET_VOLUME_CMD volume; /* SetAbsVolume */ + tAVRC_SET_BR_PLAYER_CMD br_player; /* SetBrowsedPlayer */ + tAVRC_GET_ITEMS_CMD get_items; /* GetFolderItems */ + tAVRC_CHG_PATH_CMD chg_path; /* ChangePath */ + tAVRC_GET_ATTRS_CMD get_attrs; /* GetItemAttrs */ + tAVRC_SEARCH_CMD search; /* Search */ + tAVRC_PLAY_ITEM_CMD play_item; /* PlayItem */ + tAVRC_ADD_TO_PLAY_CMD add_to_play; /* AddToNowPlaying */ + tAVRC_GET_NUM_OF_ITEMS_CMD get_num_of_items; /* GetTotalNumOfItems */ } tAVRC_COMMAND; /* GetCapability */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t capability_id; - uint8_t count; - tAVRC_CAPS_PARAM param; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t capability_id; + uint8_t count; + tAVRC_CAPS_PARAM param; } tAVRC_GET_CAPS_RSP; /* ListPlayerAppAttr */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t num_attr; - uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t num_attr; + uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE]; } tAVRC_LIST_APP_ATTR_RSP; /* ListPlayerAppValues */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t num_val; - uint8_t vals[AVRC_MAX_APP_ATTR_SIZE]; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t num_val; + uint8_t vals[AVRC_MAX_APP_ATTR_SIZE]; } tAVRC_LIST_APP_VALUES_RSP; /* GetCurAppValue */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t num_val; - tAVRC_APP_SETTING *p_vals; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t num_val; + tAVRC_APP_SETTING* p_vals; } tAVRC_GET_CUR_APP_VALUE_RSP; /* GetAppAttrTxt */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t num_attr; - tAVRC_APP_SETTING_TEXT *p_attrs; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t num_attr; + tAVRC_APP_SETTING_TEXT* p_attrs; } tAVRC_GET_APP_ATTR_TXT_RSP; /* GetPlayStatus */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint32_t song_len; - uint32_t song_pos; - uint8_t play_status; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint32_t song_len; + uint32_t song_pos; + uint8_t play_status; } tAVRC_GET_PLAY_STATUS_RSP; /* notification event parameter for AddressedPlayer change */ -typedef struct -{ - uint16_t player_id; - uint16_t uid_counter; +typedef struct { + uint16_t player_id; + uint16_t uid_counter; } tAVRC_ADDR_PLAYER_PARAM; #ifndef AVRC_MAX_APP_SETTINGS -#define AVRC_MAX_APP_SETTINGS 8 +#define AVRC_MAX_APP_SETTINGS 8 #endif /* notification event parameter for Player Application setting change */ -typedef struct -{ - uint8_t num_attr; - uint8_t attr_id[AVRC_MAX_APP_SETTINGS]; - uint8_t attr_value[AVRC_MAX_APP_SETTINGS]; +typedef struct { + uint8_t num_attr; + uint8_t attr_id[AVRC_MAX_APP_SETTINGS]; + uint8_t attr_value[AVRC_MAX_APP_SETTINGS]; } tAVRC_PLAYER_APP_PARAM; -typedef union -{ - tAVRC_PLAYSTATE play_status; - tAVRC_UID track; - uint32_t play_pos; - tAVRC_BATTERY_STATUS battery_status; - tAVRC_SYSTEMSTATE system_status; - tAVRC_PLAYER_APP_PARAM player_setting; - tAVRC_ADDR_PLAYER_PARAM addr_player; - uint16_t uid_counter; - uint8_t volume; +typedef union { + tAVRC_PLAYSTATE play_status; + tAVRC_UID track; + uint32_t play_pos; + tAVRC_BATTERY_STATUS battery_status; + tAVRC_SYSTEMSTATE system_status; + tAVRC_PLAYER_APP_PARAM player_setting; + tAVRC_ADDR_PLAYER_PARAM addr_player; + uint16_t uid_counter; + uint8_t volume; } tAVRC_NOTIF_RSP_PARAM; /* RegNotify */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t event_id; - tAVRC_NOTIF_RSP_PARAM param; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t event_id; + tAVRC_NOTIF_RSP_PARAM param; } tAVRC_REG_NOTIF_RSP; /* SetAbsVolume */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t volume; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t volume; } tAVRC_SET_VOLUME_RSP; /* SetBrowsedPlayer */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint16_t uid_counter; - uint32_t num_items; - uint16_t charset_id; - uint8_t folder_depth; - tAVRC_NAME *p_folders; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint16_t uid_counter; + uint32_t num_items; + uint16_t charset_id; + uint8_t folder_depth; + tAVRC_NAME* p_folders; } tAVRC_SET_BR_PLAYER_RSP; /* GetFolderItems */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint16_t uid_counter; - uint16_t item_count; - tAVRC_ITEM *p_item_list; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint16_t uid_counter; + uint16_t item_count; + tAVRC_ITEM* p_item_list; } tAVRC_GET_ITEMS_RSP; /* ChangePath */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint32_t num_items; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint32_t num_items; } tAVRC_CHG_PATH_RSP; /* GetItemAttrs, GetElemAttrs */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t num_attrs; - tAVRC_ATTR_ENTRY *p_attrs; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t num_attrs; + tAVRC_ATTR_ENTRY* p_attrs; } tAVRC_GET_ATTRS_RSP; /* Get Total Number of Items */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint16_t uid_counter; - uint32_t num_items; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint16_t uid_counter; + uint32_t num_items; } tAVRC_GET_NUM_OF_ITEMS_RSP; /* Search */ -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint16_t uid_counter; - uint32_t num_items; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint16_t uid_counter; + uint32_t num_items; } tAVRC_SEARCH_RSP; -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ - uint8_t target_pdu; +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ + uint8_t target_pdu; } tAVRC_NEXT_RSP; -typedef struct -{ - uint8_t pdu; - tAVRC_STS status; - uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse user. invalid one to generate according to pdu) */ +typedef struct { + uint8_t pdu; + tAVRC_STS status; + uint8_t opcode; /* Op Code (copied from avrc_cmd.opcode by AVRC_BldResponse + user. invalid one to generate according to pdu) */ } tAVRC_RSP; -typedef union -{ - uint8_t pdu; - tAVRC_RSP rsp; - tAVRC_GET_CAPS_RSP get_caps; /* GetCapability */ - tAVRC_LIST_APP_ATTR_RSP list_app_attr; /* ListPlayerAppAttr */ - tAVRC_LIST_APP_VALUES_RSP list_app_values; /* ListPlayerAppValues */ - tAVRC_GET_CUR_APP_VALUE_RSP get_cur_app_val; /* GetCurAppValue */ - tAVRC_RSP set_app_val; /* SetAppValue */ - tAVRC_GET_APP_ATTR_TXT_RSP get_app_attr_txt; /* GetAppAttrTxt */ - tAVRC_GET_APP_ATTR_TXT_RSP get_app_val_txt; /* GetAppValueTxt */ - tAVRC_RSP inform_charset; /* InformCharset */ - tAVRC_RSP inform_battery_status; /* InformBatteryStatus */ - tAVRC_GET_PLAY_STATUS_RSP get_play_status; /* GetPlayStatus */ - tAVRC_REG_NOTIF_RSP reg_notif; /* RegNotify */ - tAVRC_NEXT_RSP continu; /* Continue */ - tAVRC_NEXT_RSP abort; /* Abort */ - tAVRC_RSP addr_player; /* SetAddrPlayer */ - tAVRC_SET_VOLUME_RSP volume; /* SetAbsVolume */ - tAVRC_SET_BR_PLAYER_RSP br_player; /* SetBrowsedPlayer */ - tAVRC_GET_ITEMS_RSP get_items; /* GetFolderItems */ - tAVRC_CHG_PATH_RSP chg_path; /* ChangePath */ - tAVRC_GET_ATTRS_RSP get_attrs; /* GetItemAttrs, GetElemAttrs */ - tAVRC_GET_NUM_OF_ITEMS_RSP get_num_of_items; /* GetTotalNumberOfItems */ - tAVRC_SEARCH_RSP search; /* Search */ - tAVRC_RSP play_item; /* PlayItem */ - tAVRC_RSP add_to_play; /* AddToNowPlaying */ +typedef union { + uint8_t pdu; + tAVRC_RSP rsp; + tAVRC_GET_CAPS_RSP get_caps; /* GetCapability */ + tAVRC_LIST_APP_ATTR_RSP list_app_attr; /* ListPlayerAppAttr */ + tAVRC_LIST_APP_VALUES_RSP list_app_values; /* ListPlayerAppValues */ + tAVRC_GET_CUR_APP_VALUE_RSP get_cur_app_val; /* GetCurAppValue */ + tAVRC_RSP set_app_val; /* SetAppValue */ + tAVRC_GET_APP_ATTR_TXT_RSP get_app_attr_txt; /* GetAppAttrTxt */ + tAVRC_GET_APP_ATTR_TXT_RSP get_app_val_txt; /* GetAppValueTxt */ + tAVRC_RSP inform_charset; /* InformCharset */ + tAVRC_RSP inform_battery_status; /* InformBatteryStatus */ + tAVRC_GET_PLAY_STATUS_RSP get_play_status; /* GetPlayStatus */ + tAVRC_REG_NOTIF_RSP reg_notif; /* RegNotify */ + tAVRC_NEXT_RSP continu; /* Continue */ + tAVRC_NEXT_RSP abort; /* Abort */ + tAVRC_RSP addr_player; /* SetAddrPlayer */ + tAVRC_SET_VOLUME_RSP volume; /* SetAbsVolume */ + tAVRC_SET_BR_PLAYER_RSP br_player; /* SetBrowsedPlayer */ + tAVRC_GET_ITEMS_RSP get_items; /* GetFolderItems */ + tAVRC_CHG_PATH_RSP chg_path; /* ChangePath */ + tAVRC_GET_ATTRS_RSP get_attrs; /* GetItemAttrs, GetElemAttrs */ + tAVRC_GET_NUM_OF_ITEMS_RSP get_num_of_items; /* GetTotalNumberOfItems */ + tAVRC_SEARCH_RSP search; /* Search */ + tAVRC_RSP play_item; /* PlayItem */ + tAVRC_RSP add_to_play; /* AddToNowPlaying */ } tAVRC_RESPONSE; #endif diff --git a/stack/include/ble_advertiser.h b/stack/include/ble_advertiser.h index a0b5ef22d..7f089ddb4 100644 --- a/stack/include/ble_advertiser.h +++ b/stack/include/ble_advertiser.h @@ -31,10 +31,10 @@ using MultiAdvCb = base::Callback; extern "C" { // methods we must have defined -void btm_ble_update_dmt_flag_bits(uint8_t *flag_value, +void btm_ble_update_dmt_flag_bits(uint8_t* flag_value, const uint16_t connect_mode, const uint16_t disc_mode); -void btm_gen_resolvable_private_addr(void *p_cmd_cplt_cback); +void btm_gen_resolvable_private_addr(void* p_cmd_cplt_cback); void btm_acl_update_conn_addr(uint8_t conn_handle, BD_ADDR address); // methods we expose to c code: @@ -57,9 +57,9 @@ class BleAdvertisingManager { public: virtual ~BleAdvertisingManager() = default; - static void Initialize(BleAdvertiserHciInterface *interface); + static void Initialize(BleAdvertiserHciInterface* interface); static void CleanUp(); - static BleAdvertisingManager *Get(); + static BleAdvertisingManager* Get(); /* Register an advertising instance, status will be returned in |cb| * callback, with assigned id, if operation succeeds. Instance is freed when @@ -68,11 +68,11 @@ class BleAdvertisingManager { * The instance will have data set to |advertise_data|, scan response set to * |scan_response_data|, and will be enabled. */ - virtual void StartAdvertising( - uint8_t advertiser_id, MultiAdvCb cb, - tBTM_BLE_ADV_PARAMS *params, std::vector advertise_data, - std::vector scan_response_data, int timeout_s, - MultiAdvCb timeout_cb) = 0; + virtual void StartAdvertising(uint8_t advertiser_id, MultiAdvCb cb, + tBTM_BLE_ADV_PARAMS* params, + std::vector advertise_data, + std::vector scan_response_data, + int timeout_s, MultiAdvCb timeout_cb) = 0; /* Register an advertising instance, status will be returned in |cb| * callback, with assigned id, if operation succeeds. Instance is freed when @@ -88,7 +88,7 @@ class BleAdvertisingManager { /* This function update a Multi-ADV instance with the specififed adv * parameters. */ - virtual void SetParameters(uint8_t inst_id, tBTM_BLE_ADV_PARAMS *p_params, + virtual void SetParameters(uint8_t inst_id, tBTM_BLE_ADV_PARAMS* p_params, MultiAdvCb cb) = 0; /* This function configure a Multi-ADV instance with the specified adv data or diff --git a/stack/include/bnep_api.h b/stack/include/bnep_api.h index 0355be4e8..4a3b94010 100644 --- a/stack/include/bnep_api.h +++ b/stack/include/bnep_api.h @@ -40,8 +40,8 @@ extern "C" { * extension headers, but may in the future, so allow * space for them */ -#define BNEP_MINIMUM_OFFSET (15 + L2CAP_MIN_OFFSET) -#define BNEP_INVALID_HANDLE 0xFFFF +#define BNEP_MINIMUM_OFFSET (15 + L2CAP_MIN_OFFSET) +#define BNEP_INVALID_HANDLE 0xFFFF /***************************************************************************** * Type Definitions @@ -49,30 +49,29 @@ extern "C" { /* Define the result codes from BNEP */ -enum -{ - BNEP_SUCCESS, /* Success */ - BNEP_CONN_DISCONNECTED, /* Connection terminated */ - BNEP_NO_RESOURCES, /* No resources */ - BNEP_MTU_EXCEDED, /* Attempt to write long data */ - BNEP_INVALID_OFFSET, /* Insufficient offset in GKI buffer */ - BNEP_CONN_FAILED, /* Connection failed */ - BNEP_CONN_FAILED_CFG, /* Connection failed cos of config */ - BNEP_CONN_FAILED_SRC_UUID, /* Connection failed wrong source UUID */ - BNEP_CONN_FAILED_DST_UUID, /* Connection failed wrong destination UUID */ - BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID */ - BNEP_Q_SIZE_EXCEEDED, /* Too many buffers to dest */ - BNEP_TOO_MANY_FILTERS, /* Too many local filters specified */ - BNEP_SET_FILTER_FAIL, /* Set Filter failed */ - BNEP_WRONG_HANDLE, /* Wrong handle for the connection */ - BNEP_WRONG_STATE, /* Connection is in wrong state */ - BNEP_SECURITY_FAIL, /* Failed because of security */ - BNEP_IGNORE_CMD, /* To ignore the rcvd command */ - BNEP_TX_FLOW_ON, /* tx data flow enabled */ - BNEP_TX_FLOW_OFF /* tx data flow disabled */ - -}; typedef uint8_t tBNEP_RESULT; - +enum { + BNEP_SUCCESS, /* Success */ + BNEP_CONN_DISCONNECTED, /* Connection terminated */ + BNEP_NO_RESOURCES, /* No resources */ + BNEP_MTU_EXCEDED, /* Attempt to write long data */ + BNEP_INVALID_OFFSET, /* Insufficient offset in GKI buffer */ + BNEP_CONN_FAILED, /* Connection failed */ + BNEP_CONN_FAILED_CFG, /* Connection failed cos of config */ + BNEP_CONN_FAILED_SRC_UUID, /* Connection failed wrong source UUID */ + BNEP_CONN_FAILED_DST_UUID, /* Connection failed wrong destination UUID */ + BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID */ + BNEP_Q_SIZE_EXCEEDED, /* Too many buffers to dest */ + BNEP_TOO_MANY_FILTERS, /* Too many local filters specified */ + BNEP_SET_FILTER_FAIL, /* Set Filter failed */ + BNEP_WRONG_HANDLE, /* Wrong handle for the connection */ + BNEP_WRONG_STATE, /* Connection is in wrong state */ + BNEP_SECURITY_FAIL, /* Failed because of security */ + BNEP_IGNORE_CMD, /* To ignore the rcvd command */ + BNEP_TX_FLOW_ON, /* tx data flow enabled */ + BNEP_TX_FLOW_OFF /* tx data flow disabled */ + +}; +typedef uint8_t tBNEP_RESULT; /*************************** * Callback Functions @@ -86,13 +85,8 @@ enum * All values are used to indicate the reason for failure * Flag to indicate if it is just a role change */ -typedef void (tBNEP_CONN_STATE_CB) (uint16_t handle, - BD_ADDR rem_bda, - tBNEP_RESULT result, - bool is_role_change); - - - +typedef void(tBNEP_CONN_STATE_CB)(uint16_t handle, BD_ADDR rem_bda, + tBNEP_RESULT result, bool is_role_change); /* Connection indication callback prototype. Parameters are * BD Address of remote, remote UUID and local UUID @@ -100,13 +94,9 @@ typedef void (tBNEP_CONN_STATE_CB) (uint16_t handle, * When BNEP calls this function profile should * use BNEP_ConnectResp call to accept or reject the request */ -typedef void (tBNEP_CONNECT_IND_CB) (uint16_t handle, - BD_ADDR bd_addr, - tBT_UUID *remote_uuid, - tBT_UUID *local_uuid, - bool is_role_change); - - +typedef void(tBNEP_CONNECT_IND_CB)(uint16_t handle, BD_ADDR bd_addr, + tBT_UUID* remote_uuid, tBT_UUID* local_uuid, + bool is_role_change); /* Data buffer received indication callback prototype. Parameters are * Handle to the connection @@ -117,13 +107,9 @@ typedef void (tBNEP_CONNECT_IND_CB) (uint16_t handle, * Flag to indicate whether extension headers to be forwarded are * present */ -typedef void (tBNEP_DATA_BUF_CB) (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - BT_HDR *p_buf, - bool fw_ext_present); - +typedef void(tBNEP_DATA_BUF_CB)(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, BT_HDR* p_buf, + bool fw_ext_present); /* Data received indication callback prototype. Parameters are * Handle to the connection @@ -135,20 +121,15 @@ typedef void (tBNEP_DATA_BUF_CB) (uint16_t handle, * Flag to indicate whether extension headers to be forwarded are * present */ -typedef void (tBNEP_DATA_IND_CB) (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - uint8_t *p_data, - uint16_t len, - bool fw_ext_present); +typedef void(tBNEP_DATA_IND_CB)(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, uint8_t* p_data, + uint16_t len, bool fw_ext_present); /* Flow control callback for TX data. Parameters are * Handle to the connection * Event flow status */ -typedef void (tBNEP_TX_DATA_FLOW_CB) (uint16_t handle, - tBNEP_RESULT event); +typedef void(tBNEP_TX_DATA_FLOW_CB)(uint16_t handle, tBNEP_RESULT event); /* Filters received indication callback prototype. Parameters are * Handle to the connection @@ -163,13 +144,9 @@ typedef void (tBNEP_TX_DATA_FLOW_CB) (uint16_t handle, * two bytes will be starting of the first range and * next two bytes will be ending of the range. */ -typedef void (tBNEP_FILTER_IND_CB) (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters); - - +typedef void(tBNEP_FILTER_IND_CB)(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters); /* Multicast Filters received indication callback prototype. Parameters are * Handle to the connection @@ -183,50 +160,44 @@ typedef void (tBNEP_FILTER_IND_CB) (uint16_t handle, * First six bytes will be starting of the first range and * next six bytes will be ending of the range. */ -typedef void (tBNEP_MFILTER_IND_CB) (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_mfilters, - uint8_t *p_mfilters); +typedef void(tBNEP_MFILTER_IND_CB)(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_mfilters, + uint8_t* p_mfilters); /* This is the structure used by profile to register with BNEP */ -typedef struct -{ - tBNEP_CONNECT_IND_CB *p_conn_ind_cb; /* To indicate the conn request */ - tBNEP_CONN_STATE_CB *p_conn_state_cb; /* To indicate conn state change */ - tBNEP_DATA_IND_CB *p_data_ind_cb; /* To pass the data received */ - tBNEP_DATA_BUF_CB *p_data_buf_cb; /* To pass the data buffer received */ - tBNEP_TX_DATA_FLOW_CB *p_tx_data_flow_cb; /* data flow callback */ - tBNEP_FILTER_IND_CB *p_filter_ind_cb; /* To indicate that peer set protocol filters */ - tBNEP_MFILTER_IND_CB *p_mfilter_ind_cb; /* To indicate that peer set mcast filters */ +typedef struct { + tBNEP_CONNECT_IND_CB* p_conn_ind_cb; /* To indicate the conn request */ + tBNEP_CONN_STATE_CB* p_conn_state_cb; /* To indicate conn state change */ + tBNEP_DATA_IND_CB* p_data_ind_cb; /* To pass the data received */ + tBNEP_DATA_BUF_CB* p_data_buf_cb; /* To pass the data buffer received */ + tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; /* data flow callback */ + tBNEP_FILTER_IND_CB* + p_filter_ind_cb; /* To indicate that peer set protocol filters */ + tBNEP_MFILTER_IND_CB* + p_mfilter_ind_cb; /* To indicate that peer set mcast filters */ } tBNEP_REGISTER; - - /* This is the structure used by profile to get the status of BNEP */ -typedef struct -{ -#define BNEP_STATUS_FAILE 0 -#define BNEP_STATUS_CONNECTED 1 - uint8_t con_status; - - uint16_t l2cap_cid; - BD_ADDR rem_bda; - uint16_t rem_mtu_size; - uint16_t xmit_q_depth; - - uint16_t sent_num_filters; - uint16_t sent_mcast_filters; - uint16_t rcvd_num_filters; - uint16_t rcvd_mcast_filters; - tBT_UUID src_uuid; - tBT_UUID dst_uuid; +typedef struct { +#define BNEP_STATUS_FAILE 0 +#define BNEP_STATUS_CONNECTED 1 + uint8_t con_status; + + uint16_t l2cap_cid; + BD_ADDR rem_bda; + uint16_t rem_mtu_size; + uint16_t xmit_q_depth; + + uint16_t sent_num_filters; + uint16_t sent_mcast_filters; + uint16_t rcvd_num_filters; + uint16_t rcvd_mcast_filters; + tBT_UUID src_uuid; + tBT_UUID dst_uuid; } tBNEP_STATUS; - - /***************************************************************************** * External Function Declarations ****************************************************************************/ @@ -244,7 +215,7 @@ typedef struct * BNEP_FAILURE if connection state callback is missing * ******************************************************************************/ -extern tBNEP_RESULT BNEP_Register (tBNEP_REGISTER *p_reg_info); +extern tBNEP_RESULT BNEP_Register(tBNEP_REGISTER* p_reg_info); /******************************************************************************* * @@ -259,8 +230,7 @@ extern tBNEP_RESULT BNEP_Register (tBNEP_REGISTER *p_reg_info); * Returns void * ******************************************************************************/ -extern void BNEP_Deregister (void); - +extern void BNEP_Deregister(void); /******************************************************************************* * @@ -278,10 +248,8 @@ extern void BNEP_Deregister (void); * BNEP_NO_RESOURCES if no resources * ******************************************************************************/ -extern tBNEP_RESULT BNEP_Connect (BD_ADDR p_rem_bda, - tBT_UUID *src_uuid, - tBT_UUID *dst_uuid, - uint16_t *p_handle); +extern tBNEP_RESULT BNEP_Connect(BD_ADDR p_rem_bda, tBT_UUID* src_uuid, + tBT_UUID* dst_uuid, uint16_t* p_handle); /******************************************************************************* * @@ -298,7 +266,7 @@ extern tBNEP_RESULT BNEP_Connect (BD_ADDR p_rem_bda, * BNEP_WRONG_STATE if the responce is not expected * ******************************************************************************/ -extern tBNEP_RESULT BNEP_ConnectResp (uint16_t handle, tBNEP_RESULT resp); +extern tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp); /******************************************************************************* * @@ -312,7 +280,7 @@ extern tBNEP_RESULT BNEP_ConnectResp (uint16_t handle, tBNEP_RESULT resp); * BNEP_WRONG_HANDLE if no connection is not found * ******************************************************************************/ -extern tBNEP_RESULT BNEP_Disconnect (uint16_t handle); +extern tBNEP_RESULT BNEP_Disconnect(uint16_t handle); /******************************************************************************* * @@ -337,12 +305,9 @@ extern tBNEP_RESULT BNEP_Disconnect (uint16_t handle); * BNEP_SUCCESS - If written successfully * ******************************************************************************/ -extern tBNEP_RESULT BNEP_WriteBuf (uint16_t handle, - uint8_t *p_dest_addr, - BT_HDR *p_buf, - uint16_t protocol, - uint8_t *p_src_addr, - bool fw_ext_present); +extern tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, uint8_t* p_dest_addr, + BT_HDR* p_buf, uint16_t protocol, + uint8_t* p_src_addr, bool fw_ext_present); /******************************************************************************* * @@ -368,13 +333,9 @@ extern tBNEP_RESULT BNEP_WriteBuf (uint16_t handle, * BNEP_SUCCESS - If written successfully * ******************************************************************************/ -extern tBNEP_RESULT BNEP_Write (uint16_t handle, - uint8_t *p_dest_addr, - uint8_t *p_data, - uint16_t len, - uint16_t protocol, - uint8_t *p_src_addr, - bool fw_ext_present); +extern tBNEP_RESULT BNEP_Write(uint16_t handle, uint8_t* p_dest_addr, + uint8_t* p_data, uint16_t len, uint16_t protocol, + uint8_t* p_src_addr, bool fw_ext_present); /******************************************************************************* * @@ -395,10 +356,10 @@ extern tBNEP_RESULT BNEP_Write (uint16_t handle, * BNEP_SUCCESS - if request sent successfully * ******************************************************************************/ -extern tBNEP_RESULT BNEP_SetProtocolFilters (uint16_t handle, - uint16_t num_filters, - uint16_t *p_start_array, - uint16_t *p_end_array); +extern tBNEP_RESULT BNEP_SetProtocolFilters(uint16_t handle, + uint16_t num_filters, + uint16_t* p_start_array, + uint16_t* p_end_array); /******************************************************************************* * @@ -422,10 +383,10 @@ extern tBNEP_RESULT BNEP_SetProtocolFilters (uint16_t handle, * BNEP_SUCCESS - if request sent successfully * ******************************************************************************/ -extern tBNEP_RESULT BNEP_SetMulticastFilters (uint16_t handle, - uint16_t num_filters, - uint8_t *p_start_array, - uint8_t *p_end_array); +extern tBNEP_RESULT BNEP_SetMulticastFilters(uint16_t handle, + uint16_t num_filters, + uint8_t* p_start_array, + uint8_t* p_end_array); /******************************************************************************* * @@ -437,7 +398,7 @@ extern tBNEP_RESULT BNEP_SetMulticastFilters (uint16_t handle, * Returns the new (current) trace level * ******************************************************************************/ -extern uint8_t BNEP_SetTraceLevel (uint8_t new_level); +extern uint8_t BNEP_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -450,7 +411,7 @@ extern uint8_t BNEP_SetTraceLevel (uint8_t new_level); * Returns void * ******************************************************************************/ -extern void BNEP_Init (void); +extern void BNEP_Init(void); /******************************************************************************* * @@ -466,13 +427,10 @@ extern void BNEP_Init (void); * BNEP_WRONG_STATE - if not in connected state * ******************************************************************************/ -extern tBNEP_RESULT BNEP_GetStatus (uint16_t handle, tBNEP_STATUS *p_status); - - +extern tBNEP_RESULT BNEP_GetStatus(uint16_t handle, tBNEP_STATUS* p_status); #ifdef __cplusplus } #endif - #endif diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h index f2a2dfb16..70f89dce2 100644 --- a/stack/include/bt_types.h +++ b/stack/include/bt_types.h @@ -19,23 +19,23 @@ #ifndef BT_TYPES_H #define BT_TYPES_H -#include #include +#include #ifndef FALSE -# define FALSE false +#define FALSE false #endif #ifndef TRUE -# define TRUE true +#define TRUE true #endif #ifdef __arm -# define PACKED __packed -# define INLINE __inline +#define PACKED __packed +#define INLINE __inline #else -# define PACKED -# define INLINE +#define PACKED +#define INLINE #endif /* READ WELL !! @@ -48,448 +48,652 @@ * The convention used is the the event name contains the layer that the * event is going to. */ -#define BT_EVT_MASK 0xFF00 -#define BT_SUB_EVT_MASK 0x00FF +#define BT_EVT_MASK 0xFF00 +#define BT_SUB_EVT_MASK 0x00FF /* To Bluetooth Upper Layers */ /************************************/ /* L2CAP event */ -#define BT_EVT_TO_BTU_L2C_EVT 0x0900 +#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* HCI Event */ -#define BT_EVT_TO_BTU_HCI_EVT 0x1000 +#define BT_EVT_TO_BTU_HCI_EVT 0x1000 /* event from BR/EDR controller */ #define BT_EVT_TO_BTU_HCI_BR_EDR_EVT (0x0000 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 1 controller */ -#define BT_EVT_TO_BTU_HCI_AMP1_EVT (0x0001 | BT_EVT_TO_BTU_HCI_EVT) +#define BT_EVT_TO_BTU_HCI_AMP1_EVT (0x0001 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 2 controller */ -#define BT_EVT_TO_BTU_HCI_AMP2_EVT (0x0002 | BT_EVT_TO_BTU_HCI_EVT) +#define BT_EVT_TO_BTU_HCI_AMP2_EVT (0x0002 | BT_EVT_TO_BTU_HCI_EVT) /* event from local AMP 3 controller */ -#define BT_EVT_TO_BTU_HCI_AMP3_EVT (0x0003 | BT_EVT_TO_BTU_HCI_EVT) +#define BT_EVT_TO_BTU_HCI_AMP3_EVT (0x0003 | BT_EVT_TO_BTU_HCI_EVT) /* ACL Data from HCI */ -#define BT_EVT_TO_BTU_HCI_ACL 0x1100 +#define BT_EVT_TO_BTU_HCI_ACL 0x1100 /* SCO Data from HCI */ -#define BT_EVT_TO_BTU_HCI_SCO 0x1200 +#define BT_EVT_TO_BTU_HCI_SCO 0x1200 /* HCI Transport Error */ -#define BT_EVT_TO_BTU_HCIT_ERR 0x1300 +#define BT_EVT_TO_BTU_HCIT_ERR 0x1300 /* Serial Port Event */ -#define BT_EVT_TO_BTU_SP_EVT 0x1400 +#define BT_EVT_TO_BTU_SP_EVT 0x1400 /* Serial Port Data */ -#define BT_EVT_TO_BTU_SP_DATA 0x1500 +#define BT_EVT_TO_BTU_SP_DATA 0x1500 /* HCI command from upper layer */ -#define BT_EVT_TO_BTU_HCI_CMD 0x1600 - +#define BT_EVT_TO_BTU_HCI_CMD 0x1600 /* L2CAP segment(s) transmitted */ -#define BT_EVT_TO_BTU_L2C_SEG_XMIT 0x1900 +#define BT_EVT_TO_BTU_L2C_SEG_XMIT 0x1900 /* BlueStackTester event: incoming message from target */ -#define BT_EVT_PROXY_INCOMING_MSG 0x1A00 +#define BT_EVT_PROXY_INCOMING_MSG 0x1A00 /* Insight BTSIM event */ -#define BT_EVT_BTSIM 0x1B00 +#define BT_EVT_BTSIM 0x1B00 /* Insight Script Engine event */ -#define BT_EVT_BTISE 0x1C00 +#define BT_EVT_BTISE 0x1C00 /* To LM */ /************************************/ /* HCI Command */ -#define BT_EVT_TO_LM_HCI_CMD 0x2000 +#define BT_EVT_TO_LM_HCI_CMD 0x2000 /* HCI ACL Data */ -#define BT_EVT_TO_LM_HCI_ACL 0x2100 +#define BT_EVT_TO_LM_HCI_ACL 0x2100 /* HCI SCO Data */ -#define BT_EVT_TO_LM_HCI_SCO 0x2200 +#define BT_EVT_TO_LM_HCI_SCO 0x2200 /* HCI Transport Error */ -#define BT_EVT_TO_LM_HCIT_ERR 0x2300 +#define BT_EVT_TO_LM_HCIT_ERR 0x2300 /* LC event */ -#define BT_EVT_TO_LM_LC_EVT 0x2400 +#define BT_EVT_TO_LM_LC_EVT 0x2400 /* LC Received LMP command frame */ -#define BT_EVT_TO_LM_LC_LMP 0x2500 +#define BT_EVT_TO_LM_LC_LMP 0x2500 /* LC Received ACL data */ -#define BT_EVT_TO_LM_LC_ACL 0x2600 +#define BT_EVT_TO_LM_LC_ACL 0x2600 /* LC Received SCO data (not used) */ -#define BT_EVT_TO_LM_LC_SCO 0x2700 +#define BT_EVT_TO_LM_LC_SCO 0x2700 /* LMP data transmit complete */ -#define BT_EVT_TO_LM_LC_ACL_TX 0x2800 +#define BT_EVT_TO_LM_LC_ACL_TX 0x2800 /* LMP Command transmit complete */ -#define BT_EVT_TO_LM_LC_LMPC_TX 0x2900 +#define BT_EVT_TO_LM_LC_LMPC_TX 0x2900 /* Data to be locally loopbacked */ -#define BT_EVT_TO_LM_LOCAL_ACL_LB 0x2a00 +#define BT_EVT_TO_LM_LOCAL_ACL_LB 0x2a00 /* HCI ACL Data ack (not used) */ -#define BT_EVT_TO_LM_HCI_ACL_ACK 0x2b00 +#define BT_EVT_TO_LM_HCI_ACL_ACK 0x2b00 /* LM Diagnostics commands */ -#define BT_EVT_TO_LM_DIAG 0x2c00 - +#define BT_EVT_TO_LM_DIAG 0x2c00 -#define BT_EVT_TO_BTM_CMDS 0x2f00 +#define BT_EVT_TO_BTM_CMDS 0x2f00 #define BT_EVT_TO_BTM_PM_MDCHG_EVT (0x0001 | BT_EVT_TO_BTM_CMDS) -#define BT_EVT_TO_TCS_CMDS 0x3000 +#define BT_EVT_TO_TCS_CMDS 0x3000 -#define BT_EVT_TO_CTP_CMDS 0x3300 +#define BT_EVT_TO_CTP_CMDS 0x3300 /* ftp events */ -#define BT_EVT_TO_FTP_SRVR_CMDS 0x3600 -#define BT_EVT_TO_FTP_CLNT_CMDS 0x3700 +#define BT_EVT_TO_FTP_SRVR_CMDS 0x3600 +#define BT_EVT_TO_FTP_CLNT_CMDS 0x3700 /* SIM Access Profile events */ -#define BT_EVT_TO_BTU_SAP 0x3800 +#define BT_EVT_TO_BTU_SAP 0x3800 /* opp events */ -#define BT_EVT_TO_OPP_SRVR_CMDS 0x3900 -#define BT_EVT_TO_OPP_CLNT_CMDS 0x3a00 +#define BT_EVT_TO_OPP_SRVR_CMDS 0x3900 +#define BT_EVT_TO_OPP_CLNT_CMDS 0x3a00 /* gap events */ -#define BT_EVT_TO_GAP_MSG 0x3b00 +#define BT_EVT_TO_GAP_MSG 0x3b00 /* for NFC */ /************************************/ /* NCI Command, Notification or Data*/ -#define BT_EVT_TO_NFC_NCI 0x4000 +#define BT_EVT_TO_NFC_NCI 0x4000 /* Initialization message */ -#define BT_EVT_TO_NFC_INIT 0x4100 +#define BT_EVT_TO_NFC_INIT 0x4100 /* Low power */ -#define BT_EVT_TO_NCI_LP 0x4200 +#define BT_EVT_TO_NCI_LP 0x4200 /* Error notification to NFC Task */ -#define BT_EVT_TO_NFC_ERR 0x4300 +#define BT_EVT_TO_NFC_ERR 0x4300 /* events to NFCC simulation (NCI packets) */ -#define BT_EVT_TO_NFCCSIM_NCI 0x4a00 +#define BT_EVT_TO_NFCCSIM_NCI 0x4a00 /* HCISU Events */ -#define BT_EVT_HCISU 0x5000 +#define BT_EVT_HCISU 0x5000 -#define BT_EVT_TO_HCISU_RECONFIG_EVT (0x0001 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_UPDATE_BAUDRATE_EVT (0x0002 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_ENABLE_EVT (0x0003 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_DISABLE_EVT (0x0004 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_APP_SLEEPING_EVT (0x0005 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_ALLOW_BT_SLEEP_EVT (0x0006 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_WAKEUP_HOST_EVT (0x0007 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_LP_RCV_H4IBSS_EVT (0x0008 | BT_EVT_HCISU) -#define BT_EVT_TO_HCISU_H5_RESET_EVT (0x0009 | BT_EVT_HCISU) -#define BT_EVT_HCISU_START_QUICK_TIMER (0x000a | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_RECONFIG_EVT (0x0001 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_UPDATE_BAUDRATE_EVT (0x0002 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_ENABLE_EVT (0x0003 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_DISABLE_EVT (0x0004 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_APP_SLEEPING_EVT (0x0005 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_ALLOW_BT_SLEEP_EVT (0x0006 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_WAKEUP_HOST_EVT (0x0007 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_LP_RCV_H4IBSS_EVT (0x0008 | BT_EVT_HCISU) +#define BT_EVT_TO_HCISU_H5_RESET_EVT (0x0009 | BT_EVT_HCISU) +#define BT_EVT_HCISU_START_QUICK_TIMER (0x000a | BT_EVT_HCISU) -#define BT_EVT_DATA_TO_AMP_1 0x5100 -#define BT_EVT_DATA_TO_AMP_15 0x5f00 +#define BT_EVT_DATA_TO_AMP_1 0x5100 +#define BT_EVT_DATA_TO_AMP_15 0x5f00 /* HSP Events */ -#define BT_EVT_BTU_HSP2 0x6000 +#define BT_EVT_BTU_HSP2 0x6000 -#define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2) +#define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2) /* BPP Events */ -#define BT_EVT_TO_BPP_PR_CMDS 0x6100 /* Printer Events */ -#define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */ +#define BT_EVT_TO_BPP_PR_CMDS 0x6100 /* Printer Events */ +#define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */ /* BIP Events */ -#define BT_EVT_TO_BIP_CMDS 0x6300 +#define BT_EVT_TO_BIP_CMDS 0x6300 /* HCRP Events */ -#define BT_EVT_BTU_HCRP 0x7000 +#define BT_EVT_BTU_HCRP 0x7000 -#define BT_EVT_TO_BTU_HCRP_EVT (0x0001 | BT_EVT_BTU_HCRP) -#define BT_EVT_TO_BTU_HCRPM_EVT (0x0002 | BT_EVT_BTU_HCRP) +#define BT_EVT_TO_BTU_HCRP_EVT (0x0001 | BT_EVT_BTU_HCRP) +#define BT_EVT_TO_BTU_HCRPM_EVT (0x0002 | BT_EVT_BTU_HCRP) +#define BT_EVT_BTU_HFP 0x8000 +#define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP) -#define BT_EVT_BTU_HFP 0x8000 -#define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP) - -#define BT_EVT_BTU_IPC_EVT 0x9000 -#define BT_EVT_BTU_IPC_LOGMSG_EVT (0x0000 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_ACL_EVT (0x0001 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_BTU_EVT (0x0002 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_L2C_EVT (0x0003 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_EVT 0x9000 +#define BT_EVT_BTU_IPC_LOGMSG_EVT (0x0000 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_ACL_EVT (0x0001 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BTU_EVT (0x0002 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_L2C_EVT (0x0003 | BT_EVT_BTU_IPC_EVT) #define BT_EVT_BTU_IPC_L2C_MSG_EVT (0x0004 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_BTM_EVT (0x0005 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_AVDT_EVT (0x0006 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_SLIP_EVT (0x0007 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_MGMT_EVT (0x0008 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_BTTRC_EVT (0x0009 | BT_EVT_BTU_IPC_EVT) -#define BT_EVT_BTU_IPC_BURST_EVT (0x000A | BT_EVT_BTU_IPC_EVT) - +#define BT_EVT_BTU_IPC_BTM_EVT (0x0005 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_AVDT_EVT (0x0006 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_SLIP_EVT (0x0007 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_MGMT_EVT (0x0008 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BTTRC_EVT (0x0009 | BT_EVT_BTU_IPC_EVT) +#define BT_EVT_BTU_IPC_BURST_EVT (0x000A | BT_EVT_BTU_IPC_EVT) /* BTIF Events */ -#define BT_EVT_BTIF 0xA000 -#define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF) +#define BT_EVT_BTIF 0xA000 +#define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF) /* Define the header of each buffer used in the Bluetooth stack. */ -typedef struct -{ - uint16_t event; - uint16_t len; - uint16_t offset; - uint16_t layer_specific; - uint8_t data[]; +typedef struct { + uint16_t event; + uint16_t len; + uint16_t offset; + uint16_t layer_specific; + uint8_t data[]; } BT_HDR; -#define BT_HDR_SIZE (sizeof (BT_HDR)) - -#define BT_PSM_SDP 0x0001 -#define BT_PSM_RFCOMM 0x0003 -#define BT_PSM_TCS 0x0005 -#define BT_PSM_CTP 0x0007 -#define BT_PSM_BNEP 0x000F -#define BT_PSM_HIDC 0x0011 -#define BT_PSM_HIDI 0x0013 -#define BT_PSM_UPNP 0x0015 -#define BT_PSM_AVCTP 0x0017 -#define BT_PSM_AVDTP 0x0019 -#define BT_PSM_AVCTP_13 0x001B /* Advanced Control - Browsing */ -#define BT_PSM_UDI_CP 0x001D /* Unrestricted Digital Information Profile C-Plane */ -#define BT_PSM_ATT 0x001F /* Attribute Protocol */ +#define BT_HDR_SIZE (sizeof(BT_HDR)) + +#define BT_PSM_SDP 0x0001 +#define BT_PSM_RFCOMM 0x0003 +#define BT_PSM_TCS 0x0005 +#define BT_PSM_CTP 0x0007 +#define BT_PSM_BNEP 0x000F +#define BT_PSM_HIDC 0x0011 +#define BT_PSM_HIDI 0x0013 +#define BT_PSM_UPNP 0x0015 +#define BT_PSM_AVCTP 0x0017 +#define BT_PSM_AVDTP 0x0019 +#define BT_PSM_AVCTP_13 0x001B /* Advanced Control - Browsing */ +#define BT_PSM_UDI_CP \ + 0x001D /* Unrestricted Digital Information Profile C-Plane */ +#define BT_PSM_ATT 0x001F /* Attribute Protocol */ /* These macros extract the HCI opcodes from a buffer */ -#define HCI_GET_CMD_HDR_OPCODE(p) (uint16_t)((*((uint8_t *)((p) + 1) + (p)->offset) + \ - (*((uint8_t *)((p) + 1) + (p)->offset + 1) << 8))) -#define HCI_GET_CMD_HDR_PARAM_LEN(p) (uint8_t) (*((uint8_t *)((p) + 1) + (p)->offset + 2)) - -#define HCI_GET_EVT_HDR_OPCODE(p) (uint8_t)(*((uint8_t *)((p) + 1) + (p)->offset)) -#define HCI_GET_EVT_HDR_PARAM_LEN(p) (uint8_t) (*((uint8_t *)((p) + 1) + (p)->offset + 1)) +#define HCI_GET_CMD_HDR_OPCODE(p) \ + (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \ + (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8))) +#define HCI_GET_CMD_HDR_PARAM_LEN(p) \ + (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 2)) +#define HCI_GET_EVT_HDR_OPCODE(p) \ + (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset)) +#define HCI_GET_EVT_HDR_PARAM_LEN(p) \ + (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 1)) /******************************************************************************* * Macros to get and put bytes to and from a stream (Little Endian format). */ -#define UINT64_TO_BE_STREAM(p, u64) {*(p)++ = (uint8_t)((u64) >> 56); *(p)++ = (uint8_t)((u64) >> 48); *(p)++ = (uint8_t)((u64) >> 40); *(p)++ = (uint8_t)((u64) >> 32); \ - *(p)++ = (uint8_t)((u64) >> 24); *(p)++ = (uint8_t)((u64) >> 16); *(p)++ = (uint8_t)((u64) >> 8); *(p)++ = (uint8_t)(u64); } -#define UINT32_TO_STREAM(p, u32) {*(p)++ = (uint8_t)(u32); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 24);} -#define UINT24_TO_STREAM(p, u24) {*(p)++ = (uint8_t)(u24); *(p)++ = (uint8_t)((u24) >> 8); *(p)++ = (uint8_t)((u24) >> 16);} -#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);} -#define UINT8_TO_STREAM(p, u8) {*(p)++ = (uint8_t)(u8);} -#define INT8_TO_STREAM(p, u8) {*(p)++ = (int8_t)(u8);} -#define ARRAY32_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < 32; ijk++) *(p)++ = (uint8_t) (a)[31 - ijk];} -#define ARRAY16_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < 16; ijk++) *(p)++ = (uint8_t) (a)[15 - ijk];} -#define ARRAY8_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t) (a)[7 - ijk];} -#define BDADDR_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *(p)++ = (uint8_t) (a)[BD_ADDR_LEN - 1 - ijk];} -#define LAP_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < LAP_LEN; ijk++) *(p)++ = (uint8_t) (a)[LAP_LEN - 1 - ijk];} -#define DEVCLASS_TO_STREAM(p, a) {int ijk; for (ijk = 0; ijk < DEV_CLASS_LEN;ijk++) *(p)++ = (uint8_t) (a)[DEV_CLASS_LEN - 1 - ijk];} -#define ARRAY_TO_STREAM(p, a, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t) (a)[ijk];} -#define REVERSE_ARRAY_TO_STREAM(p, a, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t) (a)[(len) - 1 - ijk];} - -#define STREAM_TO_UINT8(u8, p) {(u8) = (uint8_t)(*(p)); (p) += 1;} -#define STREAM_TO_UINT16(u16, p) {(u16) = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;} -#define STREAM_TO_UINT24(u32, p) {(u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) ); (p) += 3;} -#define STREAM_TO_UINT32(u32, p) {(u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); (p) += 4;} -#define STREAM_TO_BDADDR(a, p) {int ijk; uint8_t *pbda = (uint8_t *)(a) + BD_ADDR_LEN - 1; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *(p)++;} -#define STREAM_TO_ARRAY32(a, p) {int ijk; uint8_t *_pa = (uint8_t *)(a) + 31; for (ijk = 0; ijk < 32; ijk++) *_pa-- = *(p)++;} -#define STREAM_TO_ARRAY16(a, p) {int ijk; uint8_t *_pa = (uint8_t *)(a) + 15; for (ijk = 0; ijk < 16; ijk++) *_pa-- = *(p)++;} -#define STREAM_TO_ARRAY8(a, p) {int ijk; uint8_t *_pa = (uint8_t *)(a) + 7; for (ijk = 0; ijk < 8; ijk++) *_pa-- = *(p)++;} -#define STREAM_TO_DEVCLASS(a, p) {int ijk; uint8_t *_pa = (uint8_t *)(a) + DEV_CLASS_LEN - 1; for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *(p)++;} -#define STREAM_TO_LAP(a, p) {int ijk; uint8_t *plap = (uint8_t *)(a) + LAP_LEN - 1; for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *(p)++;} -#define STREAM_TO_ARRAY(a, p, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) ((uint8_t *) (a))[ijk] = *(p)++;} -#define REVERSE_STREAM_TO_ARRAY(a, p, len) {int ijk; uint8_t *_pa = (uint8_t *)(a) + (len) - 1; for (ijk = 0; ijk < (len); ijk++) *_pa-- = *(p)++;} - -#define STREAM_SKIP_UINT8(p) do { (p) += 1; } while (0) -#define STREAM_SKIP_UINT16(p) do { (p) += 2; } while (0) +#define UINT64_TO_BE_STREAM(p, u64) \ + { \ + *(p)++ = (uint8_t)((u64) >> 56); \ + *(p)++ = (uint8_t)((u64) >> 48); \ + *(p)++ = (uint8_t)((u64) >> 40); \ + *(p)++ = (uint8_t)((u64) >> 32); \ + *(p)++ = (uint8_t)((u64) >> 24); \ + *(p)++ = (uint8_t)((u64) >> 16); \ + *(p)++ = (uint8_t)((u64) >> 8); \ + *(p)++ = (uint8_t)(u64); \ + } +#define UINT32_TO_STREAM(p, u32) \ + { \ + *(p)++ = (uint8_t)(u32); \ + *(p)++ = (uint8_t)((u32) >> 8); \ + *(p)++ = (uint8_t)((u32) >> 16); \ + *(p)++ = (uint8_t)((u32) >> 24); \ + } +#define UINT24_TO_STREAM(p, u24) \ + { \ + *(p)++ = (uint8_t)(u24); \ + *(p)++ = (uint8_t)((u24) >> 8); \ + *(p)++ = (uint8_t)((u24) >> 16); \ + } +#define UINT16_TO_STREAM(p, u16) \ + { \ + *(p)++ = (uint8_t)(u16); \ + *(p)++ = (uint8_t)((u16) >> 8); \ + } +#define UINT8_TO_STREAM(p, u8) \ + { *(p)++ = (uint8_t)(u8); } +#define INT8_TO_STREAM(p, u8) \ + { *(p)++ = (int8_t)(u8); } +#define ARRAY32_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < 32; ijk++) *(p)++ = (uint8_t)(a)[31 - ijk]; \ + } +#define ARRAY16_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < 16; ijk++) *(p)++ = (uint8_t)(a)[15 - ijk]; \ + } +#define ARRAY8_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t)(a)[7 - ijk]; \ + } +#define BDADDR_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) \ + *(p)++ = (uint8_t)(a)[BD_ADDR_LEN - 1 - ijk]; \ + } +#define LAP_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < LAP_LEN; ijk++) \ + *(p)++ = (uint8_t)(a)[LAP_LEN - 1 - ijk]; \ + } +#define DEVCLASS_TO_STREAM(p, a) \ + { \ + int ijk; \ + for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) \ + *(p)++ = (uint8_t)(a)[DEV_CLASS_LEN - 1 - ijk]; \ + } +#define ARRAY_TO_STREAM(p, a, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \ + } +#define REVERSE_ARRAY_TO_STREAM(p, a, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-1 - ijk]; \ + } + +#define STREAM_TO_UINT8(u8, p) \ + { \ + (u8) = (uint8_t)(*(p)); \ + (p) += 1; \ + } +#define STREAM_TO_UINT16(u16, p) \ + { \ + (u16) = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \ + (p) += 2; \ + } +#define STREAM_TO_UINT24(u32, p) \ + { \ + (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \ + ((((uint32_t)(*((p) + 2)))) << 16)); \ + (p) += 3; \ + } +#define STREAM_TO_UINT32(u32, p) \ + { \ + (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \ + ((((uint32_t)(*((p) + 2)))) << 16) + \ + ((((uint32_t)(*((p) + 3)))) << 24)); \ + (p) += 4; \ + } +#define STREAM_TO_BDADDR(a, p) \ + { \ + int ijk; \ + uint8_t* pbda = (uint8_t*)(a) + BD_ADDR_LEN - 1; \ + for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *(p)++; \ + } +#define STREAM_TO_ARRAY32(a, p) \ + { \ + int ijk; \ + uint8_t* _pa = (uint8_t*)(a) + 31; \ + for (ijk = 0; ijk < 32; ijk++) *_pa-- = *(p)++; \ + } +#define STREAM_TO_ARRAY16(a, p) \ + { \ + int ijk; \ + uint8_t* _pa = (uint8_t*)(a) + 15; \ + for (ijk = 0; ijk < 16; ijk++) *_pa-- = *(p)++; \ + } +#define STREAM_TO_ARRAY8(a, p) \ + { \ + int ijk; \ + uint8_t* _pa = (uint8_t*)(a) + 7; \ + for (ijk = 0; ijk < 8; ijk++) *_pa-- = *(p)++; \ + } +#define STREAM_TO_DEVCLASS(a, p) \ + { \ + int ijk; \ + uint8_t* _pa = (uint8_t*)(a) + DEV_CLASS_LEN - 1; \ + for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *(p)++; \ + } +#define STREAM_TO_LAP(a, p) \ + { \ + int ijk; \ + uint8_t* plap = (uint8_t*)(a) + LAP_LEN - 1; \ + for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *(p)++; \ + } +#define STREAM_TO_ARRAY(a, p, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \ + } +#define REVERSE_STREAM_TO_ARRAY(a, p, len) \ + { \ + int ijk; \ + uint8_t* _pa = (uint8_t*)(a) + (len)-1; \ + for (ijk = 0; ijk < (len); ijk++) *_pa-- = *(p)++; \ + } + +#define STREAM_SKIP_UINT8(p) \ + do { \ + (p) += 1; \ + } while (0) +#define STREAM_SKIP_UINT16(p) \ + do { \ + (p) += 2; \ + } while (0) /******************************************************************************* * Macros to get and put bytes to and from a field (Little Endian format). * These are the same as to stream, except the pointer is not incremented. */ -#define UINT32_TO_FIELD(p, u32) {*(uint8_t *)(p) = (uint8_t)(u32); *((uint8_t *)(p)+1) = (uint8_t)((u32) >> 8); *((uint8_t *)(p)+2) = (uint8_t)((u32) >> 16); *((uint8_t *)(p)+3) = (uint8_t)((u32) >> 24);} -#define UINT24_TO_FIELD(p, u24) {*(uint8_t *)(p) = (uint8_t)(u24); *((uint8_t *)(p)+1) = (uint8_t)((u24) >> 8); *((uint8_t *)(p)+2) = (uint8_t)((u24) >> 16);} -#define UINT16_TO_FIELD(p, u16) {*(uint8_t *)(p) = (uint8_t)(u16); *((uint8_t *)(p)+1) = (uint8_t)((u16) >> 8);} -#define UINT8_TO_FIELD(p, u8) {*(uint8_t *)(p) = (uint8_t)(u8);} - +#define UINT32_TO_FIELD(p, u32) \ + { \ + *(uint8_t*)(p) = (uint8_t)(u32); \ + *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 8); \ + *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 16); \ + *((uint8_t*)(p) + 3) = (uint8_t)((u32) >> 24); \ + } +#define UINT24_TO_FIELD(p, u24) \ + { \ + *(uint8_t*)(p) = (uint8_t)(u24); \ + *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \ + *((uint8_t*)(p) + 2) = (uint8_t)((u24) >> 16); \ + } +#define UINT16_TO_FIELD(p, u16) \ + { \ + *(uint8_t*)(p) = (uint8_t)(u16); \ + *((uint8_t*)(p) + 1) = (uint8_t)((u16) >> 8); \ + } +#define UINT8_TO_FIELD(p, u8) \ + { *(uint8_t*)(p) = (uint8_t)(u8); } /******************************************************************************* * Macros to get and put bytes to and from a stream (Big Endian format) */ -#define UINT32_TO_BE_STREAM(p, u32) {*(p)++ = (uint8_t)((u32) >> 24); *(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)(u32); } -#define UINT24_TO_BE_STREAM(p, u24) {*(p)++ = (uint8_t)((u24) >> 16); *(p)++ = (uint8_t)((u24) >> 8); *(p)++ = (uint8_t)(u24);} -#define UINT16_TO_BE_STREAM(p, u16) {*(p)++ = (uint8_t)((u16) >> 8); *(p)++ = (uint8_t)(u16);} -#define UINT8_TO_BE_STREAM(p, u8) {*(p)++ = (uint8_t)(u8);} -#define ARRAY_TO_BE_STREAM(p, a, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t) (a)[ijk];} -#define ARRAY_TO_BE_STREAM_REVERSE(p, a, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t) (a)[(len) - ijk - 1];} - -#define BE_STREAM_TO_UINT8(u8, p) {(u8) = (uint8_t)(*(p)); (p) += 1;} -#define BE_STREAM_TO_UINT16(u16, p) {(u16) = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); (p) += 2;} -#define BE_STREAM_TO_UINT24(u32, p) {(u32) = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + ((uint32_t)(*(p)) << 16)); (p) += 3;} -#define BE_STREAM_TO_UINT32(u32, p) {(u32) = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) + ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); (p) += 4;} -#define BE_STREAM_TO_UINT64(u64, p) {(u64) = ((uint64_t)(*((p) + 7)) + ((uint64_t)(*((p) + 6)) << 8) + \ - ((uint64_t)(*((p) + 5)) << 16) + ((uint64_t)(*((p) + 4)) << 24) + \ - ((uint64_t)(*((p) + 3)) << 32) + ((uint64_t)(*((p) + 2)) << 40) + \ - ((uint64_t)(*((p) + 1)) << 48) + ((uint64_t)(*(p)) << 56)); \ - (p) += 8;} -#define BE_STREAM_TO_ARRAY(p, a, len) {int ijk; for (ijk = 0; ijk < (len); ijk++) ((uint8_t *) (a))[ijk] = *(p)++;} - +#define UINT32_TO_BE_STREAM(p, u32) \ + { \ + *(p)++ = (uint8_t)((u32) >> 24); \ + *(p)++ = (uint8_t)((u32) >> 16); \ + *(p)++ = (uint8_t)((u32) >> 8); \ + *(p)++ = (uint8_t)(u32); \ + } +#define UINT24_TO_BE_STREAM(p, u24) \ + { \ + *(p)++ = (uint8_t)((u24) >> 16); \ + *(p)++ = (uint8_t)((u24) >> 8); \ + *(p)++ = (uint8_t)(u24); \ + } +#define UINT16_TO_BE_STREAM(p, u16) \ + { \ + *(p)++ = (uint8_t)((u16) >> 8); \ + *(p)++ = (uint8_t)(u16); \ + } +#define UINT8_TO_BE_STREAM(p, u8) \ + { *(p)++ = (uint8_t)(u8); } +#define ARRAY_TO_BE_STREAM(p, a, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \ + } +#define ARRAY_TO_BE_STREAM_REVERSE(p, a, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-ijk - 1]; \ + } + +#define BE_STREAM_TO_UINT8(u8, p) \ + { \ + (u8) = (uint8_t)(*(p)); \ + (p) += 1; \ + } +#define BE_STREAM_TO_UINT16(u16, p) \ + { \ + (u16) = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); \ + (p) += 2; \ + } +#define BE_STREAM_TO_UINT24(u32, p) \ + { \ + (u32) = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + \ + ((uint32_t)(*(p)) << 16)); \ + (p) += 3; \ + } +#define BE_STREAM_TO_UINT32(u32, p) \ + { \ + (u32) = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) + \ + ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); \ + (p) += 4; \ + } +#define BE_STREAM_TO_UINT64(u64, p) \ + { \ + (u64) = ((uint64_t)(*((p) + 7)) + ((uint64_t)(*((p) + 6)) << 8) + \ + ((uint64_t)(*((p) + 5)) << 16) + ((uint64_t)(*((p) + 4)) << 24) + \ + ((uint64_t)(*((p) + 3)) << 32) + ((uint64_t)(*((p) + 2)) << 40) + \ + ((uint64_t)(*((p) + 1)) << 48) + ((uint64_t)(*(p)) << 56)); \ + (p) += 8; \ + } +#define BE_STREAM_TO_ARRAY(p, a, len) \ + { \ + int ijk; \ + for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \ + } /******************************************************************************* * Macros to get and put bytes to and from a field (Big Endian format). * These are the same as to stream, except the pointer is not incremented. */ -#define UINT32_TO_BE_FIELD(p, u32) {*(uint8_t *)(p) = (uint8_t)((u32) >> 24); *((uint8_t *)(p)+1) = (uint8_t)((u32) >> 16); *((uint8_t *)(p)+2) = (uint8_t)((u32) >> 8); *((uint8_t *)(p)+3) = (uint8_t)(u32); } -#define UINT24_TO_BE_FIELD(p, u24) {*(uint8_t *)(p) = (uint8_t)((u24) >> 16); *((uint8_t *)(p)+1) = (uint8_t)((u24) >> 8); *((uint8_t *)(p)+2) = (uint8_t)(u24);} -#define UINT16_TO_BE_FIELD(p, u16) {*(uint8_t *)(p) = (uint8_t)((u16) >> 8); *((uint8_t *)(p)+1) = (uint8_t)(u16);} -#define UINT8_TO_BE_FIELD(p, u8) {*(uint8_t *)(p) = (uint8_t)(u8);} - +#define UINT32_TO_BE_FIELD(p, u32) \ + { \ + *(uint8_t*)(p) = (uint8_t)((u32) >> 24); \ + *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 16); \ + *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 8); \ + *((uint8_t*)(p) + 3) = (uint8_t)(u32); \ + } +#define UINT24_TO_BE_FIELD(p, u24) \ + { \ + *(uint8_t*)(p) = (uint8_t)((u24) >> 16); \ + *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \ + *((uint8_t*)(p) + 2) = (uint8_t)(u24); \ + } +#define UINT16_TO_BE_FIELD(p, u16) \ + { \ + *(uint8_t*)(p) = (uint8_t)((u16) >> 8); \ + *((uint8_t*)(p) + 1) = (uint8_t)(u16); \ + } +#define UINT8_TO_BE_FIELD(p, u8) \ + { *(uint8_t*)(p) = (uint8_t)(u8); } /* Common Bluetooth field definitions */ -#define BD_ADDR_LEN 6 /* Device address length */ -typedef uint8_t BD_ADDR[BD_ADDR_LEN]; /* Device address */ -typedef uint8_t *BD_ADDR_PTR; /* Pointer to Device Address */ +#define BD_ADDR_LEN 6 /* Device address length */ +typedef uint8_t BD_ADDR[BD_ADDR_LEN]; /* Device address */ +typedef uint8_t* BD_ADDR_PTR; /* Pointer to Device Address */ -#define AMP_KEY_TYPE_GAMP 0 -#define AMP_KEY_TYPE_WIFI 1 -#define AMP_KEY_TYPE_UWB 2 +#define AMP_KEY_TYPE_GAMP 0 +#define AMP_KEY_TYPE_WIFI 1 +#define AMP_KEY_TYPE_UWB 2 typedef uint8_t tAMP_KEY_TYPE; -#define BT_OCTET8_LEN 8 -typedef uint8_t BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */ +#define BT_OCTET8_LEN 8 +typedef uint8_t BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */ -#define LINK_KEY_LEN 16 -typedef uint8_t LINK_KEY[LINK_KEY_LEN]; /* Link Key */ +#define LINK_KEY_LEN 16 +typedef uint8_t LINK_KEY[LINK_KEY_LEN]; /* Link Key */ -#define AMP_LINK_KEY_LEN 32 -typedef uint8_t AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */ +#define AMP_LINK_KEY_LEN 32 +typedef uint8_t + AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */ -#define BT_OCTET16_LEN 16 -typedef uint8_t BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */ +#define BT_OCTET16_LEN 16 +typedef uint8_t BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */ -#define PIN_CODE_LEN 16 -typedef uint8_t PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */ -typedef uint8_t *PIN_CODE_PTR; /* Pointer to Pin Code */ +#define PIN_CODE_LEN 16 +typedef uint8_t PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */ +typedef uint8_t* PIN_CODE_PTR; /* Pointer to Pin Code */ -#define BT_OCTET32_LEN 32 -typedef uint8_t BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */ +#define BT_OCTET32_LEN 32 +typedef uint8_t BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */ -#define DEV_CLASS_LEN 3 -typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ -typedef uint8_t *DEV_CLASS_PTR; /* Pointer to Device class */ +#define DEV_CLASS_LEN 3 +typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ +typedef uint8_t* DEV_CLASS_PTR; /* Pointer to Device class */ -#define EXT_INQ_RESP_LEN 3 -typedef uint8_t EXT_INQ_RESP[EXT_INQ_RESP_LEN];/* Extended Inquiry Response */ -typedef uint8_t *EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */ +#define EXT_INQ_RESP_LEN 3 +typedef uint8_t EXT_INQ_RESP[EXT_INQ_RESP_LEN]; /* Extended Inquiry Response */ +typedef uint8_t* EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */ -#define BD_NAME_LEN 248 -typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */ -typedef uint8_t *BD_NAME_PTR; /* Pointer to Device name */ +#define BD_NAME_LEN 248 +typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */ +typedef uint8_t* BD_NAME_PTR; /* Pointer to Device name */ #define BD_FEATURES_LEN 8 -typedef uint8_t BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */ +typedef uint8_t + BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */ -#define BT_EVENT_MASK_LEN 8 -typedef uint8_t BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */ +#define BT_EVENT_MASK_LEN 8 +typedef uint8_t BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */ -#define LAP_LEN 3 -typedef uint8_t LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ -typedef uint8_t INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ +#define LAP_LEN 3 +typedef uint8_t LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ +typedef uint8_t INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ -#define RAND_NUM_LEN 16 +#define RAND_NUM_LEN 16 typedef uint8_t RAND_NUM[RAND_NUM_LEN]; -#define ACO_LEN 12 -typedef uint8_t ACO[ACO_LEN]; /* Authenticated ciphering offset */ +#define ACO_LEN 12 +typedef uint8_t ACO[ACO_LEN]; /* Authenticated ciphering offset */ -#define COF_LEN 12 -typedef uint8_t COF[COF_LEN]; /* ciphering offset number */ +#define COF_LEN 12 +typedef uint8_t COF[COF_LEN]; /* ciphering offset number */ typedef struct { - uint8_t qos_flags; /* TBD */ - uint8_t service_type; /* see below */ - uint32_t token_rate; /* bytes/second */ - uint32_t token_bucket_size; /* bytes */ - uint32_t peak_bandwidth; /* bytes/second */ - uint32_t latency; /* microseconds */ - uint32_t delay_variation; /* microseconds */ + uint8_t qos_flags; /* TBD */ + uint8_t service_type; /* see below */ + uint32_t token_rate; /* bytes/second */ + uint32_t token_bucket_size; /* bytes */ + uint32_t peak_bandwidth; /* bytes/second */ + uint32_t latency; /* microseconds */ + uint32_t delay_variation; /* microseconds */ } FLOW_SPEC; /* Values for service_type */ -#define NO_TRAFFIC 0 -#define BEST_EFFORT 1 -#define GUARANTEED 2 +#define NO_TRAFFIC 0 +#define BEST_EFFORT 1 +#define GUARANTEED 2 /* Service class of the CoD */ -#define SERV_CLASS_NETWORKING (1 << 1) -#define SERV_CLASS_RENDERING (1 << 2) -#define SERV_CLASS_CAPTURING (1 << 3) -#define SERV_CLASS_OBJECT_TRANSFER (1 << 4) -#define SERV_CLASS_OBJECT_AUDIO (1 << 5) -#define SERV_CLASS_OBJECT_TELEPHONY (1 << 6) -#define SERV_CLASS_OBJECT_INFORMATION (1 << 7) +#define SERV_CLASS_NETWORKING (1 << 1) +#define SERV_CLASS_RENDERING (1 << 2) +#define SERV_CLASS_CAPTURING (1 << 3) +#define SERV_CLASS_OBJECT_TRANSFER (1 << 4) +#define SERV_CLASS_OBJECT_AUDIO (1 << 5) +#define SERV_CLASS_OBJECT_TELEPHONY (1 << 6) +#define SERV_CLASS_OBJECT_INFORMATION (1 << 7) /* Second byte */ -#define SERV_CLASS_LIMITED_DISC_MODE (0x20) +#define SERV_CLASS_LIMITED_DISC_MODE (0x20) /* Field size definitions. Note that byte lengths are rounded up. */ -#define ACCESS_CODE_BIT_LEN 72 -#define ACCESS_CODE_BYTE_LEN 9 -#define SHORTENED_ACCESS_CODE_BIT_LEN 68 +#define ACCESS_CODE_BIT_LEN 72 +#define ACCESS_CODE_BYTE_LEN 9 +#define SHORTENED_ACCESS_CODE_BIT_LEN 68 typedef uint8_t ACCESS_CODE[ACCESS_CODE_BYTE_LEN]; -#define SYNTH_TX 1 /* want synth code to TRANSMIT at this freq */ -#define SYNTH_RX 2 /* want synth code to RECEIVE at this freq */ +#define SYNTH_TX 1 /* want synth code to TRANSMIT at this freq */ +#define SYNTH_RX 2 /* want synth code to RECEIVE at this freq */ -#define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */ +#define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */ -#define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */ +#define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */ /* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */ -#define MAX_UUID_SIZE 16 -typedef struct -{ -#define LEN_UUID_16 2 -#define LEN_UUID_32 4 -#define LEN_UUID_128 16 - - uint16_t len; - - union - { - uint16_t uuid16; - uint32_t uuid32; - uint8_t uuid128[MAX_UUID_SIZE]; - } uu; +#define MAX_UUID_SIZE 16 +typedef struct { +#define LEN_UUID_16 2 +#define LEN_UUID_32 4 +#define LEN_UUID_128 16 + + uint16_t len; + + union { + uint16_t uuid16; + uint32_t uuid32; + uint8_t uuid128[MAX_UUID_SIZE]; + } uu; } tBT_UUID; -#define BT_EIR_FLAGS_TYPE 0x01 -#define BT_EIR_MORE_16BITS_UUID_TYPE 0x02 -#define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03 -#define BT_EIR_MORE_32BITS_UUID_TYPE 0x04 -#define BT_EIR_COMPLETE_32BITS_UUID_TYPE 0x05 -#define BT_EIR_MORE_128BITS_UUID_TYPE 0x06 -#define BT_EIR_COMPLETE_128BITS_UUID_TYPE 0x07 -#define BT_EIR_SHORTENED_LOCAL_NAME_TYPE 0x08 -#define BT_EIR_COMPLETE_LOCAL_NAME_TYPE 0x09 -#define BT_EIR_TX_POWER_LEVEL_TYPE 0x0A -#define BT_EIR_OOB_BD_ADDR_TYPE 0x0C -#define BT_EIR_OOB_COD_TYPE 0x0D -#define BT_EIR_OOB_SSP_HASH_C_TYPE 0x0E -#define BT_EIR_OOB_SSP_RAND_R_TYPE 0x0F -#define BT_EIR_SERVICE_DATA_TYPE 0x16 -#define BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE 0x16 -#define BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE 0x20 -#define BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE 0x21 -#define BT_EIR_MANUFACTURER_SPECIFIC_TYPE 0xFF - -#define BT_OOB_COD_SIZE 3 -#define BT_OOB_HASH_C_SIZE 16 -#define BT_OOB_RAND_R_SIZE 16 +#define BT_EIR_FLAGS_TYPE 0x01 +#define BT_EIR_MORE_16BITS_UUID_TYPE 0x02 +#define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03 +#define BT_EIR_MORE_32BITS_UUID_TYPE 0x04 +#define BT_EIR_COMPLETE_32BITS_UUID_TYPE 0x05 +#define BT_EIR_MORE_128BITS_UUID_TYPE 0x06 +#define BT_EIR_COMPLETE_128BITS_UUID_TYPE 0x07 +#define BT_EIR_SHORTENED_LOCAL_NAME_TYPE 0x08 +#define BT_EIR_COMPLETE_LOCAL_NAME_TYPE 0x09 +#define BT_EIR_TX_POWER_LEVEL_TYPE 0x0A +#define BT_EIR_OOB_BD_ADDR_TYPE 0x0C +#define BT_EIR_OOB_COD_TYPE 0x0D +#define BT_EIR_OOB_SSP_HASH_C_TYPE 0x0E +#define BT_EIR_OOB_SSP_RAND_R_TYPE 0x0F +#define BT_EIR_SERVICE_DATA_TYPE 0x16 +#define BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE 0x16 +#define BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE 0x20 +#define BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE 0x21 +#define BT_EIR_MANUFACTURER_SPECIFIC_TYPE 0xFF + +#define BT_OOB_COD_SIZE 3 +#define BT_OOB_HASH_C_SIZE 16 +#define BT_OOB_RAND_R_SIZE 16 /* Broadcom proprietary UUIDs and reserved PSMs * * The lowest 4 bytes byte of the UUID or GUID depend on the feature. Typically, * the value of those bytes will be the PSM or SCN. */ -#define BRCM_PROPRIETARY_UUID_BASE 0xDA, 0x23, 0x41, 0x02, 0xA3, 0xBB, 0xC1, 0x71, 0xBA, 0x09, 0x6f, 0x21 -#define BRCM_PROPRIETARY_GUID_BASE 0xda23, 0x4102, 0xa3, 0xbb, 0xc1, 0x71, 0xba, 0x09, 0x6f, 0x21 +#define BRCM_PROPRIETARY_UUID_BASE \ + 0xDA, 0x23, 0x41, 0x02, 0xA3, 0xBB, 0xC1, 0x71, 0xBA, 0x09, 0x6f, 0x21 +#define BRCM_PROPRIETARY_GUID_BASE \ + 0xda23, 0x4102, 0xa3, 0xbb, 0xc1, 0x71, 0xba, 0x09, 0x6f, 0x21 /* We will not allocate a PSM in the reserved range to 3rd party apps */ -#define BRCM_RESERVED_PSM_START 0x5AE1 -#define BRCM_RESERVED_PSM_END 0x5AFF +#define BRCM_RESERVED_PSM_START 0x5AE1 +#define BRCM_RESERVED_PSM_END 0x5AFF -#define BRCM_UTILITY_SERVICE_PSM 0x5AE1 -#define BRCM_MATCHER_PSM 0x5AE3 +#define BRCM_UTILITY_SERVICE_PSM 0x5AE1 +#define BRCM_MATCHER_PSM 0x5AE3 /* Connection statistics */ @@ -499,233 +703,227 @@ typedef struct #define BT_CONN_STATS_DEFINED /* These bits are used in the bIsConnected field */ -#define BT_CONNECTED_USING_BREDR 1 -#define BT_CONNECTED_USING_AMP 2 - -typedef struct -{ - uint32_t is_connected; - int32_t rssi; - uint32_t bytes_sent; - uint32_t bytes_rcvd; - uint32_t duration; +#define BT_CONNECTED_USING_BREDR 1 +#define BT_CONNECTED_USING_AMP 2 + +typedef struct { + uint32_t is_connected; + int32_t rssi; + uint32_t bytes_sent; + uint32_t bytes_rcvd; + uint32_t duration; } tBT_CONN_STATS; #endif - /***************************************************************************** * Low Energy definitions * * Address types */ -#define BLE_ADDR_PUBLIC 0x00 -#define BLE_ADDR_RANDOM 0x01 -#define BLE_ADDR_PUBLIC_ID 0x02 -#define BLE_ADDR_RANDOM_ID 0x03 +#define BLE_ADDR_PUBLIC 0x00 +#define BLE_ADDR_RANDOM 0x01 +#define BLE_ADDR_PUBLIC_ID 0x02 +#define BLE_ADDR_RANDOM_ID 0x03 typedef uint8_t tBLE_ADDR_TYPE; -#define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC) +#define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC) -#define BT_TRANSPORT_INVALID 0 -#define BT_TRANSPORT_BR_EDR 1 -#define BT_TRANSPORT_LE 2 +#define BT_TRANSPORT_INVALID 0 +#define BT_TRANSPORT_BR_EDR 1 +#define BT_TRANSPORT_LE 2 typedef uint8_t tBT_TRANSPORT; -#define BLE_ADDR_IS_STATIC(x) (((x)[0] & 0xC0) == 0xC0) +#define BLE_ADDR_IS_STATIC(x) (((x)[0] & 0xC0) == 0xC0) -typedef struct -{ - tBLE_ADDR_TYPE type; - BD_ADDR bda; +typedef struct { + tBLE_ADDR_TYPE type; + BD_ADDR bda; } tBLE_BD_ADDR; /* Device Types */ -#define BT_DEVICE_TYPE_BREDR 0x01 -#define BT_DEVICE_TYPE_BLE 0x02 -#define BT_DEVICE_TYPE_DUMO 0x03 +#define BT_DEVICE_TYPE_BREDR 0x01 +#define BT_DEVICE_TYPE_BLE 0x02 +#define BT_DEVICE_TYPE_DUMO 0x03 typedef uint8_t tBT_DEVICE_TYPE; /*****************************************************************************/ - /* Define trace levels */ -#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ -#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ -#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ -#define BT_TRACE_LEVEL_API 3 /* API traces */ -#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ -#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ -#define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ - -#define MAX_TRACE_LEVEL 6 +#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ +#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ +#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ +#define BT_TRACE_LEVEL_API 3 /* API traces */ +#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ +#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ +#define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ +#define MAX_TRACE_LEVEL 6 /* Define New Trace Type Definition */ /* TRACE_CTRL_TYPE 0x^^000000*/ -#define TRACE_CTRL_MASK 0xff000000 -#define TRACE_GET_CTRL(x) ((((uint32_t)(x)) & TRACE_CTRL_MASK) >> 24) +#define TRACE_CTRL_MASK 0xff000000 +#define TRACE_GET_CTRL(x) ((((uint32_t)(x)) & TRACE_CTRL_MASK) >> 24) -#define TRACE_CTRL_GENERAL 0x00000000 -#define TRACE_CTRL_STR_RESOURCE 0x01000000 -#define TRACE_CTRL_SEQ_FLOW 0x02000000 -#define TRACE_CTRL_MAX_NUM 3 +#define TRACE_CTRL_GENERAL 0x00000000 +#define TRACE_CTRL_STR_RESOURCE 0x01000000 +#define TRACE_CTRL_SEQ_FLOW 0x02000000 +#define TRACE_CTRL_MAX_NUM 3 /* LAYER SPECIFIC 0x00^^0000*/ -#define TRACE_LAYER_MASK 0x00ff0000 -#define TRACE_GET_LAYER(x) ((((uint32_t)(x)) & TRACE_LAYER_MASK) >> 16) - -#define TRACE_LAYER_NONE 0x00000000 -#define TRACE_LAYER_USB 0x00010000 -#define TRACE_LAYER_SERIAL 0x00020000 -#define TRACE_LAYER_SOCKET 0x00030000 -#define TRACE_LAYER_RS232 0x00040000 -#define TRACE_LAYER_TRANS_MAX_NUM 5 -#define TRACE_LAYER_TRANS_ALL 0x007f0000 -#define TRACE_LAYER_LC 0x00050000 -#define TRACE_LAYER_LM 0x00060000 -#define TRACE_LAYER_HCI 0x00070000 -#define TRACE_LAYER_L2CAP 0x00080000 -#define TRACE_LAYER_RFCOMM 0x00090000 -#define TRACE_LAYER_SDP 0x000a0000 -#define TRACE_LAYER_TCS 0x000b0000 -#define TRACE_LAYER_OBEX 0x000c0000 -#define TRACE_LAYER_BTM 0x000d0000 -#define TRACE_LAYER_GAP 0x000e0000 -#define TRACE_LAYER_ICP 0x00110000 -#define TRACE_LAYER_HSP2 0x00120000 -#define TRACE_LAYER_SPP 0x00130000 -#define TRACE_LAYER_CTP 0x00140000 -#define TRACE_LAYER_BPP 0x00150000 -#define TRACE_LAYER_HCRP 0x00160000 -#define TRACE_LAYER_FTP 0x00170000 -#define TRACE_LAYER_OPP 0x00180000 -#define TRACE_LAYER_BTU 0x00190000 -#define TRACE_LAYER_GKI 0x001a0000 /* OBSOLETED */ -#define TRACE_LAYER_BNEP 0x001b0000 -#define TRACE_LAYER_PAN 0x001c0000 -#define TRACE_LAYER_HFP 0x001d0000 -#define TRACE_LAYER_HID 0x001e0000 -#define TRACE_LAYER_BIP 0x001f0000 -#define TRACE_LAYER_AVP 0x00200000 -#define TRACE_LAYER_A2DP 0x00210000 -#define TRACE_LAYER_SAP 0x00220000 -#define TRACE_LAYER_AMP 0x00230000 -#define TRACE_LAYER_MCA 0x00240000 -#define TRACE_LAYER_ATT 0x00250000 -#define TRACE_LAYER_SMP 0x00260000 -#define TRACE_LAYER_NFC 0x00270000 -#define TRACE_LAYER_NCI 0x00280000 -#define TRACE_LAYER_LLCP 0x00290000 -#define TRACE_LAYER_NDEF 0x002a0000 -#define TRACE_LAYER_RW 0x002b0000 -#define TRACE_LAYER_CE 0x002c0000 -#define TRACE_LAYER_P2P 0x002d0000 -#define TRACE_LAYER_SNEP 0x002e0000 -#define TRACE_LAYER_CHO 0x002f0000 -#define TRACE_LAYER_NFA 0x00300000 - -#define TRACE_LAYER_MAX_NUM 0x0031 - +#define TRACE_LAYER_MASK 0x00ff0000 +#define TRACE_GET_LAYER(x) ((((uint32_t)(x)) & TRACE_LAYER_MASK) >> 16) + +#define TRACE_LAYER_NONE 0x00000000 +#define TRACE_LAYER_USB 0x00010000 +#define TRACE_LAYER_SERIAL 0x00020000 +#define TRACE_LAYER_SOCKET 0x00030000 +#define TRACE_LAYER_RS232 0x00040000 +#define TRACE_LAYER_TRANS_MAX_NUM 5 +#define TRACE_LAYER_TRANS_ALL 0x007f0000 +#define TRACE_LAYER_LC 0x00050000 +#define TRACE_LAYER_LM 0x00060000 +#define TRACE_LAYER_HCI 0x00070000 +#define TRACE_LAYER_L2CAP 0x00080000 +#define TRACE_LAYER_RFCOMM 0x00090000 +#define TRACE_LAYER_SDP 0x000a0000 +#define TRACE_LAYER_TCS 0x000b0000 +#define TRACE_LAYER_OBEX 0x000c0000 +#define TRACE_LAYER_BTM 0x000d0000 +#define TRACE_LAYER_GAP 0x000e0000 +#define TRACE_LAYER_ICP 0x00110000 +#define TRACE_LAYER_HSP2 0x00120000 +#define TRACE_LAYER_SPP 0x00130000 +#define TRACE_LAYER_CTP 0x00140000 +#define TRACE_LAYER_BPP 0x00150000 +#define TRACE_LAYER_HCRP 0x00160000 +#define TRACE_LAYER_FTP 0x00170000 +#define TRACE_LAYER_OPP 0x00180000 +#define TRACE_LAYER_BTU 0x00190000 +#define TRACE_LAYER_GKI 0x001a0000 /* OBSOLETED */ +#define TRACE_LAYER_BNEP 0x001b0000 +#define TRACE_LAYER_PAN 0x001c0000 +#define TRACE_LAYER_HFP 0x001d0000 +#define TRACE_LAYER_HID 0x001e0000 +#define TRACE_LAYER_BIP 0x001f0000 +#define TRACE_LAYER_AVP 0x00200000 +#define TRACE_LAYER_A2DP 0x00210000 +#define TRACE_LAYER_SAP 0x00220000 +#define TRACE_LAYER_AMP 0x00230000 +#define TRACE_LAYER_MCA 0x00240000 +#define TRACE_LAYER_ATT 0x00250000 +#define TRACE_LAYER_SMP 0x00260000 +#define TRACE_LAYER_NFC 0x00270000 +#define TRACE_LAYER_NCI 0x00280000 +#define TRACE_LAYER_LLCP 0x00290000 +#define TRACE_LAYER_NDEF 0x002a0000 +#define TRACE_LAYER_RW 0x002b0000 +#define TRACE_LAYER_CE 0x002c0000 +#define TRACE_LAYER_P2P 0x002d0000 +#define TRACE_LAYER_SNEP 0x002e0000 +#define TRACE_LAYER_CHO 0x002f0000 +#define TRACE_LAYER_NFA 0x00300000 + +#define TRACE_LAYER_MAX_NUM 0x0031 /* TRACE_ORIGINATOR 0x0000^^00*/ -#define TRACE_ORG_MASK 0x0000ff00 -#define TRACE_GET_ORG(x) ((((uint32_t)(x)) & TRACE_ORG_MASK) >> 8) - -#define TRACE_ORG_STACK 0x00000000 -#define TRACE_ORG_HCI_TRANS 0x00000100 -#define TRACE_ORG_PROTO_DISP 0x00000200 -#define TRACE_ORG_RPC 0x00000300 -#define TRACE_ORG_GKI 0x00000400 /* OBSOLETED */ -#define TRACE_ORG_APPL 0x00000500 -#define TRACE_ORG_SCR_WRAPPER 0x00000600 -#define TRACE_ORG_SCR_ENGINE 0x00000700 -#define TRACE_ORG_USER_SCR 0x00000800 -#define TRACE_ORG_TESTER 0x00000900 -#define TRACE_ORG_MAX_NUM 10 /* 32-bit mask; must be < 32 */ -#define TRACE_LITE_ORG_MAX_NUM 6 -#define TRACE_ORG_ALL 0x03ff -#define TRACE_ORG_RPC_TRANS 0x04 - -#define TRACE_ORG_REG 0x00000909 -#define TRACE_ORG_REG_SUCCESS 0x0000090a +#define TRACE_ORG_MASK 0x0000ff00 +#define TRACE_GET_ORG(x) ((((uint32_t)(x)) & TRACE_ORG_MASK) >> 8) + +#define TRACE_ORG_STACK 0x00000000 +#define TRACE_ORG_HCI_TRANS 0x00000100 +#define TRACE_ORG_PROTO_DISP 0x00000200 +#define TRACE_ORG_RPC 0x00000300 +#define TRACE_ORG_GKI 0x00000400 /* OBSOLETED */ +#define TRACE_ORG_APPL 0x00000500 +#define TRACE_ORG_SCR_WRAPPER 0x00000600 +#define TRACE_ORG_SCR_ENGINE 0x00000700 +#define TRACE_ORG_USER_SCR 0x00000800 +#define TRACE_ORG_TESTER 0x00000900 +#define TRACE_ORG_MAX_NUM 10 /* 32-bit mask; must be < 32 */ +#define TRACE_LITE_ORG_MAX_NUM 6 +#define TRACE_ORG_ALL 0x03ff +#define TRACE_ORG_RPC_TRANS 0x04 + +#define TRACE_ORG_REG 0x00000909 +#define TRACE_ORG_REG_SUCCESS 0x0000090a /* TRACE_TYPE 0x000000^^*/ -#define TRACE_TYPE_MASK 0x000000ff -#define TRACE_GET_TYPE(x) (((uint32_t)(x)) & TRACE_TYPE_MASK) - -#define TRACE_TYPE_ERROR 0x00000000 -#define TRACE_TYPE_WARNING 0x00000001 -#define TRACE_TYPE_API 0x00000002 -#define TRACE_TYPE_EVENT 0x00000003 -#define TRACE_TYPE_DEBUG 0x00000004 -#define TRACE_TYPE_STACK_ONLY_MAX TRACE_TYPE_DEBUG -#define TRACE_TYPE_TX 0x00000005 -#define TRACE_TYPE_RX 0x00000006 -#define TRACE_TYPE_DEBUG_ASSERT 0x00000007 -#define TRACE_TYPE_GENERIC 0x00000008 -#define TRACE_TYPE_REG 0x00000009 -#define TRACE_TYPE_REG_SUCCESS 0x0000000a -#define TRACE_TYPE_CMD_TX 0x0000000b -#define TRACE_TYPE_EVT_TX 0x0000000c -#define TRACE_TYPE_ACL_TX 0x0000000d -#define TRACE_TYPE_CMD_RX 0x0000000e -#define TRACE_TYPE_EVT_RX 0x0000000f -#define TRACE_TYPE_ACL_RX 0x00000010 -#define TRACE_TYPE_TARGET_TRACE 0x00000011 -#define TRACE_TYPE_SCO_TX 0x00000012 -#define TRACE_TYPE_SCO_RX 0x00000013 - - -#define TRACE_TYPE_MAX_NUM 20 -#define TRACE_TYPE_ALL 0xffff +#define TRACE_TYPE_MASK 0x000000ff +#define TRACE_GET_TYPE(x) (((uint32_t)(x)) & TRACE_TYPE_MASK) + +#define TRACE_TYPE_ERROR 0x00000000 +#define TRACE_TYPE_WARNING 0x00000001 +#define TRACE_TYPE_API 0x00000002 +#define TRACE_TYPE_EVENT 0x00000003 +#define TRACE_TYPE_DEBUG 0x00000004 +#define TRACE_TYPE_STACK_ONLY_MAX TRACE_TYPE_DEBUG +#define TRACE_TYPE_TX 0x00000005 +#define TRACE_TYPE_RX 0x00000006 +#define TRACE_TYPE_DEBUG_ASSERT 0x00000007 +#define TRACE_TYPE_GENERIC 0x00000008 +#define TRACE_TYPE_REG 0x00000009 +#define TRACE_TYPE_REG_SUCCESS 0x0000000a +#define TRACE_TYPE_CMD_TX 0x0000000b +#define TRACE_TYPE_EVT_TX 0x0000000c +#define TRACE_TYPE_ACL_TX 0x0000000d +#define TRACE_TYPE_CMD_RX 0x0000000e +#define TRACE_TYPE_EVT_RX 0x0000000f +#define TRACE_TYPE_ACL_RX 0x00000010 +#define TRACE_TYPE_TARGET_TRACE 0x00000011 +#define TRACE_TYPE_SCO_TX 0x00000012 +#define TRACE_TYPE_SCO_RX 0x00000013 + +#define TRACE_TYPE_MAX_NUM 20 +#define TRACE_TYPE_ALL 0xffff /* Define color for script type */ -#define SCR_COLOR_DEFAULT 0 -#define SCR_COLOR_TYPE_COMMENT 1 -#define SCR_COLOR_TYPE_COMMAND 2 -#define SCR_COLOR_TYPE_EVENT 3 -#define SCR_COLOR_TYPE_SELECT 4 +#define SCR_COLOR_DEFAULT 0 +#define SCR_COLOR_TYPE_COMMENT 1 +#define SCR_COLOR_TYPE_COMMAND 2 +#define SCR_COLOR_TYPE_EVENT 3 +#define SCR_COLOR_TYPE_SELECT 4 /* Define protocol trace flag values */ #define SCR_PROTO_TRACE_HCI_SUMMARY 0x00000001 -#define SCR_PROTO_TRACE_HCI_DATA 0x00000002 -#define SCR_PROTO_TRACE_L2CAP 0x00000004 -#define SCR_PROTO_TRACE_RFCOMM 0x00000008 -#define SCR_PROTO_TRACE_SDP 0x00000010 -#define SCR_PROTO_TRACE_TCS 0x00000020 -#define SCR_PROTO_TRACE_OBEX 0x00000040 -#define SCR_PROTO_TRACE_OAPP 0x00000080 /* OBEX Application Profile */ -#define SCR_PROTO_TRACE_AMP 0x00000100 -#define SCR_PROTO_TRACE_BNEP 0x00000200 -#define SCR_PROTO_TRACE_AVP 0x00000400 -#define SCR_PROTO_TRACE_MCA 0x00000800 -#define SCR_PROTO_TRACE_ATT 0x00001000 -#define SCR_PROTO_TRACE_SMP 0x00002000 -#define SCR_PROTO_TRACE_NCI 0x00004000 -#define SCR_PROTO_TRACE_LLCP 0x00008000 -#define SCR_PROTO_TRACE_NDEF 0x00010000 -#define SCR_PROTO_TRACE_RW 0x00020000 -#define SCR_PROTO_TRACE_CE 0x00040000 -#define SCR_PROTO_TRACE_SNEP 0x00080000 -#define SCR_PROTO_TRACE_CHO 0x00100000 -#define SCR_PROTO_TRACE_ALL 0x001fffff -#define SCR_PROTO_TRACE_HCI_LOGGING_VSE 0x0800 /* Brcm vs event for logmsg and protocol traces */ - -#define MAX_SCRIPT_TYPE 5 - -#define TCS_PSM_INTERCOM 5 -#define TCS_PSM_CORDLESS 7 -#define BT_PSM_BNEP 0x000F +#define SCR_PROTO_TRACE_HCI_DATA 0x00000002 +#define SCR_PROTO_TRACE_L2CAP 0x00000004 +#define SCR_PROTO_TRACE_RFCOMM 0x00000008 +#define SCR_PROTO_TRACE_SDP 0x00000010 +#define SCR_PROTO_TRACE_TCS 0x00000020 +#define SCR_PROTO_TRACE_OBEX 0x00000040 +#define SCR_PROTO_TRACE_OAPP 0x00000080 /* OBEX Application Profile */ +#define SCR_PROTO_TRACE_AMP 0x00000100 +#define SCR_PROTO_TRACE_BNEP 0x00000200 +#define SCR_PROTO_TRACE_AVP 0x00000400 +#define SCR_PROTO_TRACE_MCA 0x00000800 +#define SCR_PROTO_TRACE_ATT 0x00001000 +#define SCR_PROTO_TRACE_SMP 0x00002000 +#define SCR_PROTO_TRACE_NCI 0x00004000 +#define SCR_PROTO_TRACE_LLCP 0x00008000 +#define SCR_PROTO_TRACE_NDEF 0x00010000 +#define SCR_PROTO_TRACE_RW 0x00020000 +#define SCR_PROTO_TRACE_CE 0x00040000 +#define SCR_PROTO_TRACE_SNEP 0x00080000 +#define SCR_PROTO_TRACE_CHO 0x00100000 +#define SCR_PROTO_TRACE_ALL 0x001fffff +#define SCR_PROTO_TRACE_HCI_LOGGING_VSE \ + 0x0800 /* Brcm vs event for logmsg and protocol traces */ + +#define MAX_SCRIPT_TYPE 5 + +#define TCS_PSM_INTERCOM 5 +#define TCS_PSM_CORDLESS 7 +#define BT_PSM_BNEP 0x000F /* Define PSMs HID uses */ -#define HID_PSM_CONTROL 0x0011 -#define HID_PSM_INTERRUPT 0x0013 +#define HID_PSM_CONTROL 0x0011 +#define HID_PSM_INTERRUPT 0x0013 /* Define a function for logging */ -typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...); +typedef void(BT_LOG_FUNC)(int trace_type, const char* fmt_str, ...); /* bd addr length and type */ #ifndef BD_ADDR_LEN -#define BD_ADDR_LEN 6 +#define BD_ADDR_LEN 6 typedef uint8_t BD_ADDR[BD_ADDR_LEN]; #endif @@ -737,7 +935,7 @@ typedef uint8_t BD_ADDR[BD_ADDR_LEN]; /* global constant for "any" bd addr */ static const BD_ADDR bd_addr_any = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -static const BD_ADDR bd_addr_null= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const BD_ADDR bd_addr_null = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /***************************************************************************** * Functions @@ -753,14 +951,12 @@ static const BD_ADDR bd_addr_null= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; * Returns void * ******************************************************************************/ -static inline void bdcpy(BD_ADDR a, const BD_ADDR b) -{ - int i; +static inline void bdcpy(BD_ADDR a, const BD_ADDR b) { + int i; - for (i = BD_ADDR_LEN; i != 0; i--) - { - *a++ = *b++; - } + for (i = BD_ADDR_LEN; i != 0; i--) { + *a++ = *b++; + } } /******************************************************************************* @@ -773,18 +969,15 @@ static inline void bdcpy(BD_ADDR a, const BD_ADDR b) * Returns Zero if b==a, nonzero otherwise (like memcmp). * ******************************************************************************/ -static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) -{ - int i; - - for (i = BD_ADDR_LEN; i != 0; i--) - { - if (*a++ != *b++) - { - return -1; - } +static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) { + int i; + + for (i = BD_ADDR_LEN; i != 0; i--) { + if (*a++ != *b++) { + return -1; } - return 0; + } + return 0; } /******************************************************************************* @@ -797,10 +990,7 @@ static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) * Returns Zero if a equals bd_addr_any. * ******************************************************************************/ -static inline int bdcmpany(const BD_ADDR a) -{ - return bdcmp(a, bd_addr_any); -} +static inline int bdcmpany(const BD_ADDR a) { return bdcmp(a, bd_addr_any); } /******************************************************************************* * @@ -812,8 +1002,5 @@ static inline int bdcmpany(const BD_ADDR a) * Returns void * ******************************************************************************/ -static inline void bdsetany(BD_ADDR a) -{ - bdcpy(a, bd_addr_any); -} +static inline void bdsetany(BD_ADDR a) { bdcpy(a, bd_addr_any); } #endif diff --git a/stack/include/btm_api.h b/stack/include/btm_api.h index 9e99d3115..5e7c9376e 100644 --- a/stack/include/btm_api.h +++ b/stack/include/btm_api.h @@ -26,8 +26,8 @@ #define BTM_API_H #include "bt_target.h" -#include "sdp_api.h" #include "hcidefs.h" +#include "sdp_api.h" #include "smp_api.h" @@ -60,8 +60,7 @@ extern "C" { * Returns void * ******************************************************************************/ -extern void BTM_DeviceReset (tBTM_CMPL_CB *p_cb); - +extern void BTM_DeviceReset(tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -72,8 +71,7 @@ extern void BTM_DeviceReset (tBTM_CMPL_CB *p_cb); * Returns true if device is up, else false * ******************************************************************************/ -extern bool BTM_IsDeviceUp (void); - +extern bool BTM_IsDeviceUp(void); /******************************************************************************* * @@ -84,7 +82,7 @@ extern bool BTM_IsDeviceUp (void); * Returns BTM_CMD_STARTED if successful, otherwise an error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetLocalDeviceName (char *p_name); +extern tBTM_STATUS BTM_SetLocalDeviceName(char* p_name); /******************************************************************************* * @@ -95,8 +93,7 @@ extern tBTM_STATUS BTM_SetLocalDeviceName (char *p_name); * Returns BTM_SUCCESS if successful, otherwise an error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class); - +extern tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class); /******************************************************************************* * @@ -111,7 +108,7 @@ extern tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class); * is returned and p_name is set to NULL * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name); +extern tBTM_STATUS BTM_ReadLocalDeviceName(char** p_name); /******************************************************************************* * @@ -123,7 +120,8 @@ extern tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name); * Returns BTM_CMD_STARTED if successful, otherwise an error * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback); +extern tBTM_STATUS BTM_ReadLocalDeviceNameFromController( + tBTM_CMPL_CB* p_rln_cmpl_cback); /******************************************************************************* * @@ -134,8 +132,7 @@ extern tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cm * Returns pointer to the device class * ******************************************************************************/ -extern uint8_t *BTM_ReadDeviceClass (void); - +extern uint8_t* BTM_ReadDeviceClass(void); /******************************************************************************* * @@ -146,7 +143,7 @@ extern uint8_t *BTM_ReadDeviceClass (void); * Returns pointer to the local features string * ******************************************************************************/ -extern uint8_t *BTM_ReadLocalFeatures (void); +extern uint8_t* BTM_ReadLocalFeatures(void); /******************************************************************************* * @@ -159,8 +156,8 @@ extern uint8_t *BTM_ReadLocalFeatures (void); * first registration. * ******************************************************************************/ -extern tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb); - +extern tBTM_DEV_STATUS_CB* BTM_RegisterForDeviceStatusNotif( + tBTM_DEV_STATUS_CB* p_cb); /******************************************************************************* * @@ -177,8 +174,8 @@ extern tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB * registered. * ******************************************************************************/ -extern tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, bool is_register); - +extern tBTM_STATUS BTM_RegisterForVSEvents(tBTM_VS_EVT_CB* p_cb, + bool is_register); /******************************************************************************* * @@ -187,11 +184,9 @@ extern tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, bool is_reg * Description Send a vendor specific HCI command to the controller. * ******************************************************************************/ -extern void BTM_VendorSpecificCommand(uint16_t opcode, - uint8_t param_len, - uint8_t *p_param_buf, - tBTM_VSC_CMPL_CB *p_cb); - +extern void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len, + uint8_t* p_param_buf, + tBTM_VSC_CMPL_CB* p_cb); /******************************************************************************* * @@ -214,8 +209,7 @@ extern uint8_t BTM_AllocateSCN(void); * Returns Returns true if server channel was available * ******************************************************************************/ -extern bool BTM_TryAllocateSCN(uint8_t scn); - +extern bool BTM_TryAllocateSCN(uint8_t scn); /******************************************************************************* * @@ -226,8 +220,7 @@ extern bool BTM_TryAllocateSCN(uint8_t scn); * Returns true if successful, false if SCN is not in use or invalid * ******************************************************************************/ -extern bool BTM_FreeSCN(uint8_t scn); - +extern bool BTM_FreeSCN(uint8_t scn); /******************************************************************************* * @@ -239,8 +232,7 @@ extern bool BTM_FreeSCN(uint8_t scn); * Returns The new or current trace level * ******************************************************************************/ -extern uint8_t BTM_SetTraceLevel (uint8_t new_level); - +extern uint8_t BTM_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -278,7 +270,6 @@ extern void BTM_WriteVoiceSettings(uint16_t settings); ******************************************************************************/ extern tBTM_STATUS BTM_EnableTestMode(void); - /******************************************************************************* * DEVICE DISCOVERY FUNCTIONS - Inquiry, Remote Name, Discovery, Class of Device ******************************************************************************/ @@ -299,9 +290,8 @@ extern tBTM_STATUS BTM_EnableTestMode(void); * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetDiscoverability (uint16_t inq_mode, uint16_t window, - uint16_t interval); - +extern tBTM_STATUS BTM_SetDiscoverability(uint16_t inq_mode, uint16_t window, + uint16_t interval); /******************************************************************************* * @@ -317,9 +307,8 @@ extern tBTM_STATUS BTM_SetDiscoverability (uint16_t inq_mode, uint16_t window, * BTM_GENERAL_DISCOVERABLE * ******************************************************************************/ -extern uint16_t BTM_ReadDiscoverability (uint16_t *p_window, - uint16_t *p_interval); - +extern uint16_t BTM_ReadDiscoverability(uint16_t* p_window, + uint16_t* p_interval); /******************************************************************************* * @@ -356,10 +345,9 @@ extern uint16_t BTM_ReadDiscoverability (uint16_t *p_window, * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, - uint16_t max_delay, uint16_t min_delay, - tBTM_INQ_RESULTS_CB *p_results_cb); - +extern tBTM_STATUS BTM_SetPeriodicInquiryMode( + tBTM_INQ_PARMS* p_inqparms, uint16_t max_delay, uint16_t min_delay, + tBTM_INQ_RESULTS_CB* p_results_cb); /******************************************************************************* * @@ -397,10 +385,9 @@ extern tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, - tBTM_INQ_RESULTS_CB *p_results_cb, - tBTM_CMPL_CB *p_cmpl_cb); - +extern tBTM_STATUS BTM_StartInquiry(tBTM_INQ_PARMS* p_inqparms, + tBTM_INQ_RESULTS_CB* p_results_cb, + tBTM_CMPL_CB* p_cmpl_cb); /******************************************************************************* * @@ -414,8 +401,7 @@ extern tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, * BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active * ******************************************************************************/ -extern uint16_t BTM_IsInquiryActive (void); - +extern uint16_t BTM_IsInquiryActive(void); /******************************************************************************* * @@ -430,7 +416,6 @@ extern uint16_t BTM_IsInquiryActive (void); ******************************************************************************/ extern tBTM_STATUS BTM_CancelInquiry(void); - /******************************************************************************* * * Function BTM_CancelPeriodicInquiry @@ -445,7 +430,6 @@ extern tBTM_STATUS BTM_CancelInquiry(void); ******************************************************************************/ extern tBTM_STATUS BTM_CancelPeriodicInquiry(void); - /******************************************************************************* * * Function BTM_SetConnectability @@ -460,9 +444,8 @@ extern tBTM_STATUS BTM_CancelPeriodicInquiry(void); * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetConnectability (uint16_t page_mode, uint16_t window, - uint16_t interval); - +extern tBTM_STATUS BTM_SetConnectability(uint16_t page_mode, uint16_t window, + uint16_t interval); /******************************************************************************* * @@ -476,8 +459,8 @@ extern tBTM_STATUS BTM_SetConnectability (uint16_t page_mode, uint16_t window, * Returns BTM_NON_CONNECTABLE or BTM_CONNECTABLE * ******************************************************************************/ -extern uint16_t BTM_ReadConnectability (uint16_t *p_window, uint16_t *p_interval); - +extern uint16_t BTM_ReadConnectability(uint16_t* p_window, + uint16_t* p_interval); /******************************************************************************* * @@ -495,7 +478,7 @@ extern uint16_t BTM_ReadConnectability (uint16_t *p_window, uint16_t *p_interval * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetInquiryMode (uint8_t mode); +extern tBTM_STATUS BTM_SetInquiryMode(uint8_t mode); /******************************************************************************* * @@ -511,7 +494,7 @@ extern tBTM_STATUS BTM_SetInquiryMode (uint8_t mode); * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetInquiryScanType (uint16_t scan_type); +extern tBTM_STATUS BTM_SetInquiryScanType(uint16_t scan_type); /******************************************************************************* * @@ -528,7 +511,7 @@ extern tBTM_STATUS BTM_SetInquiryScanType (uint16_t scan_type); * ******************************************************************************/ -extern tBTM_STATUS BTM_SetPageScanType (uint16_t scan_type); +extern tBTM_STATUS BTM_SetPageScanType(uint16_t scan_type); /******************************************************************************* * @@ -554,10 +537,9 @@ extern tBTM_STATUS BTM_SetPageScanType (uint16_t scan_type); * BTM_WRONG_MODE if the device is not up. * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, - tBTM_CMPL_CB *p_cb, - tBT_TRANSPORT transport); - +extern tBTM_STATUS BTM_ReadRemoteDeviceName(BD_ADDR remote_bda, + tBTM_CMPL_CB* p_cb, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -576,7 +558,7 @@ extern tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, * BTM_WRONG_MODE if there is no active remote name request. * ******************************************************************************/ -extern tBTM_STATUS BTM_CancelRemoteDeviceName (void); +extern tBTM_STATUS BTM_CancelRemoteDeviceName(void); /******************************************************************************* * @@ -587,10 +569,9 @@ extern tBTM_STATUS BTM_CancelRemoteDeviceName (void); * Returns BTM_SUCCESS if successful, otherwise an error * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, - uint8_t *lmp_version, - uint16_t *manufacturer, - uint16_t *lmp_sub_version); +extern tBTM_STATUS BTM_ReadRemoteVersion(BD_ADDR addr, uint8_t* lmp_version, + uint16_t* manufacturer, + uint16_t* lmp_sub_version); /******************************************************************************* * @@ -605,7 +586,7 @@ extern tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, * Returns pointer to the remote supported features mask * ******************************************************************************/ -extern uint8_t *BTM_ReadRemoteFeatures (BD_ADDR addr); +extern uint8_t* BTM_ReadRemoteFeatures(BD_ADDR addr); /******************************************************************************* * @@ -624,7 +605,8 @@ extern uint8_t *BTM_ReadRemoteFeatures (BD_ADDR addr); * or NULL if page_number is not valid * ******************************************************************************/ -extern uint8_t *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, uint8_t page_number); +extern uint8_t* BTM_ReadRemoteExtendedFeatures(BD_ADDR addr, + uint8_t page_number); /******************************************************************************* * @@ -636,7 +618,7 @@ extern uint8_t *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, uint8_t page_numbe * Returns number of features pages read from the remote device * ******************************************************************************/ -extern uint8_t BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr); +extern uint8_t BTM_ReadNumberRemoteFeaturesPages(BD_ADDR addr); /******************************************************************************* * @@ -651,7 +633,7 @@ extern uint8_t BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr); * BTM_FEATURE_BYTES_PER_PAGE * (BTM_EXT_FEATURES_PAGE_MAX + 1) * ******************************************************************************/ -extern uint8_t *BTM_ReadAllRemoteFeatures (BD_ADDR addr); +extern uint8_t* BTM_ReadAllRemoteFeatures(BD_ADDR addr); /******************************************************************************* * @@ -665,8 +647,7 @@ extern uint8_t *BTM_ReadAllRemoteFeatures (BD_ADDR addr); * Returns pointer to entry, or NULL if not found * ******************************************************************************/ -extern tBTM_INQ_INFO *BTM_InqDbRead (const BD_ADDR p_bda); - +extern tBTM_INQ_INFO* BTM_InqDbRead(const BD_ADDR p_bda); /******************************************************************************* * @@ -680,8 +661,7 @@ extern tBTM_INQ_INFO *BTM_InqDbRead (const BD_ADDR p_bda); * Returns pointer to first in-use entry, or NULL if DB is empty * ******************************************************************************/ -extern tBTM_INQ_INFO *BTM_InqDbFirst (void); - +extern tBTM_INQ_INFO* BTM_InqDbFirst(void); /******************************************************************************* * @@ -694,8 +674,7 @@ extern tBTM_INQ_INFO *BTM_InqDbFirst (void); * Returns pointer to next in-use entry, or NULL if no more found. * ******************************************************************************/ -extern tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur); - +extern tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur); /******************************************************************************* * @@ -711,7 +690,7 @@ extern tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur); * is active, otherwise BTM_SUCCESS * ******************************************************************************/ -extern tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda); +extern tBTM_STATUS BTM_ClearInqDb(BD_ADDR p_bda); /******************************************************************************* * @@ -725,7 +704,7 @@ extern tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda); * Returns BTM_SUCCESS if successful * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS BTM_ReadInquiryRspTxPower(tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -742,9 +721,8 @@ extern tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb); * BTM_ERR_PROCESSING if err initiating the command * ******************************************************************************/ -extern tBTM_STATUS BTM_StartDiscovery (tBTM_CMPL_CB *p_cmpl_cb, - BD_ADDR_PTR p_rem_addr); - +extern tBTM_STATUS BTM_StartDiscovery(tBTM_CMPL_CB* p_cmpl_cb, + BD_ADDR_PTR p_rem_addr); /******************************************************************************* * @@ -757,9 +735,8 @@ extern tBTM_STATUS BTM_StartDiscovery (tBTM_CMPL_CB *p_cmpl_cb, * Returns Pointer to matching record, or NULL * ******************************************************************************/ -extern tSDP_DISC_REC *BTM_FindAttribute (uint16_t attr_id, - tSDP_DISC_REC *p_start_rec); - +extern tSDP_DISC_REC* BTM_FindAttribute(uint16_t attr_id, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -772,9 +749,8 @@ extern tSDP_DISC_REC *BTM_FindAttribute (uint16_t attr_id, * Returns Pointer to matching record, or NULL * ******************************************************************************/ -extern tSDP_DISC_REC *BTM_FindService (uint16_t service_uuid, - tSDP_DISC_REC *p_start_rec); - +extern tSDP_DISC_REC* BTM_FindService(uint16_t service_uuid, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -787,9 +763,8 @@ extern tSDP_DISC_REC *BTM_FindService (uint16_t service_uuid, * Returns void * ******************************************************************************/ -extern void BTM_SetDiscoveryParams (uint16_t num_uuid, tSDP_UUID *p_uuid_list, - uint16_t num_attr, uint16_t *p_attr_list); - +extern void BTM_SetDiscoveryParams(uint16_t num_uuid, tSDP_UUID* p_uuid_list, + uint16_t num_attr, uint16_t* p_attr_list); /***************************************************************************** * ACL CHANNEL MANAGEMENT FUNCTIONS @@ -803,8 +778,7 @@ extern void BTM_SetDiscoveryParams (uint16_t num_uuid, tSDP_UUID *p_uuid_list, * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, - uint16_t *settings); +extern tBTM_STATUS BTM_SetLinkPolicy(BD_ADDR remote_bda, uint16_t* settings); /******************************************************************************* * @@ -816,8 +790,7 @@ extern tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, * Returns void * ******************************************************************************/ -extern void BTM_SetDefaultLinkPolicy (uint16_t settings); - +extern void BTM_SetDefaultLinkPolicy(uint16_t settings); /******************************************************************************* * @@ -829,8 +802,7 @@ extern void BTM_SetDefaultLinkPolicy (uint16_t settings); * Returns void * ******************************************************************************/ -extern void BTM_SetDefaultLinkSuperTout (uint16_t timeout); - +extern void BTM_SetDefaultLinkSuperTout(uint16_t timeout); /******************************************************************************* * @@ -841,8 +813,7 @@ extern void BTM_SetDefaultLinkSuperTout (uint16_t timeout); * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, - uint16_t timeout); +extern tBTM_STATUS BTM_SetLinkSuperTout(BD_ADDR remote_bda, uint16_t timeout); /******************************************************************************* * * Function BTM_GetLinkSuperTout @@ -852,8 +823,8 @@ extern tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, * Returns status of the operation * ******************************************************************************/ -extern tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, - uint16_t *p_timeout); +extern tBTM_STATUS BTM_GetLinkSuperTout(BD_ADDR remote_bda, + uint16_t* p_timeout); /******************************************************************************* * @@ -865,8 +836,7 @@ extern tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, * Returns true if connection is up, else false. * ******************************************************************************/ -extern bool BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport); - +extern bool BTM_IsAclConnectionUp(BD_ADDR remote_bda, tBT_TRANSPORT transport); /******************************************************************************* * @@ -879,9 +849,7 @@ extern bool BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transpor * BTM_UNKNOWN_ADDR if no active link with bd addr specified * ******************************************************************************/ -extern tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, uint8_t *p_role); - - +extern tBTM_STATUS BTM_GetRole(BD_ADDR remote_bd_addr, uint8_t* p_role); /******************************************************************************* * @@ -901,9 +869,8 @@ extern tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, uint8_t *p_role); * role switching * ******************************************************************************/ -extern tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, - uint8_t new_role, - tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS BTM_SwitchRole(BD_ADDR remote_bd_addr, uint8_t new_role, + tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -920,8 +887,7 @@ extern tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, * BTM_BUSY if command is already in progress * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadRSSI (const BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); - +extern tBTM_STATUS BTM_ReadRSSI(const BD_ADDR remote_bda, tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -939,8 +905,8 @@ extern tBTM_STATUS BTM_ReadRSSI (const BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); * BTM_BUSY if command is already in progress * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, - tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS BTM_ReadTxPower(BD_ADDR remote_bda, tBT_TRANSPORT transport, + tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -957,7 +923,7 @@ extern tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, * BTM_BUSY if command is already in progress * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS BTM_ReadLinkQuality(BD_ADDR remote_bda, tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -969,8 +935,9 @@ extern tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); * Returns BTM_SUCCESS if successfully registered, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, uint8_t *p_level, - tBTM_BL_EVENT_MASK evt_mask); +extern tBTM_STATUS BTM_RegBusyLevelNotif(tBTM_BL_CHANGE_CB* p_cb, + uint8_t* p_level, + tBTM_BL_EVENT_MASK evt_mask); /******************************************************************************* * @@ -982,7 +949,7 @@ extern tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, uint8_t *p_le * Returns BTM_SUCCESS if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb); +extern tBTM_STATUS BTM_AclRegisterForChanges(tBTM_ACL_DB_CHANGE_CB* p_cb); /******************************************************************************* * @@ -994,7 +961,7 @@ extern tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb); * Returns uint16_t Number of active ACL links * ******************************************************************************/ -extern uint16_t BTM_GetNumAclLinks (void); +extern uint16_t BTM_GetNumAclLinks(void); /******************************************************************************* * @@ -1005,9 +972,8 @@ extern uint16_t BTM_GetNumAclLinks (void); * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC *p_flow, - tBTM_CMPL_CB *p_cb); - +extern tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC* p_flow, + tBTM_CMPL_CB* p_cb); /***************************************************************************** * (e)SCO CHANNEL MANAGEMENT FUNCTIONS @@ -1029,11 +995,10 @@ extern tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC *p_flow, * with the sco index used for the connection. * ******************************************************************************/ -extern tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, bool is_orig, - uint16_t pkt_types, uint16_t *p_sco_inx, - tBTM_SCO_CB *p_conn_cb, - tBTM_SCO_CB *p_disc_cb); - +extern tBTM_STATUS BTM_CreateSco(BD_ADDR remote_bda, bool is_orig, + uint16_t pkt_types, uint16_t* p_sco_inx, + tBTM_SCO_CB* p_conn_cb, + tBTM_SCO_CB* p_disc_cb); /******************************************************************************* * @@ -1044,8 +1009,7 @@ extern tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, bool is_orig, * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_RemoveSco (uint16_t sco_inx); - +extern tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx); /******************************************************************************* * @@ -1067,8 +1031,7 @@ extern tBTM_STATUS BTM_RemoveSco (uint16_t sco_inx); * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SetScoPacketTypes (uint16_t sco_inx, uint16_t pkt_types); - +extern tBTM_STATUS BTM_SetScoPacketTypes(uint16_t sco_inx, uint16_t pkt_types); /******************************************************************************* * @@ -1088,8 +1051,7 @@ extern tBTM_STATUS BTM_SetScoPacketTypes (uint16_t sco_inx, uint16_t pkt_types); * Returns packet types supported for the connection * ******************************************************************************/ -extern uint16_t BTM_ReadScoPacketTypes (uint16_t sco_inx); - +extern uint16_t BTM_ReadScoPacketTypes(uint16_t sco_inx); /******************************************************************************* * @@ -1101,8 +1063,7 @@ extern uint16_t BTM_ReadScoPacketTypes (uint16_t sco_inx); * Returns packet types supported by the device. * ******************************************************************************/ -extern uint16_t BTM_ReadDeviceScoPacketTypes (void); - +extern uint16_t BTM_ReadDeviceScoPacketTypes(void); /******************************************************************************* * @@ -1113,8 +1074,7 @@ extern uint16_t BTM_ReadDeviceScoPacketTypes (void); * Returns handle for the connection, or 0xFFFF if invalid SCO index. * ******************************************************************************/ -extern uint16_t BTM_ReadScoHandle (uint16_t sco_inx); - +extern uint16_t BTM_ReadScoHandle(uint16_t sco_inx); /******************************************************************************* * @@ -1126,8 +1086,7 @@ extern uint16_t BTM_ReadScoHandle (uint16_t sco_inx); * Returns pointer to BD address or NULL if not known * ******************************************************************************/ -extern uint8_t *BTM_ReadScoBdAddr (uint16_t sco_inx); - +extern uint8_t* BTM_ReadScoBdAddr(uint16_t sco_inx); /******************************************************************************* * @@ -1140,8 +1099,7 @@ extern uint8_t *BTM_ReadScoBdAddr (uint16_t sco_inx); * Returns HCI reason or BTM_INVALID_SCO_DISC_REASON if not set. * ******************************************************************************/ -extern uint16_t BTM_ReadScoDiscReason (void); - +extern uint16_t BTM_ReadScoDiscReason(void); /******************************************************************************* * @@ -1156,8 +1114,8 @@ extern uint16_t BTM_ReadScoDiscReason (void); * BTM_BUSY if there are one or more active (e)SCO links. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, - tBTM_ESCO_PARAMS *p_parms); +extern tBTM_STATUS BTM_SetEScoMode(tBTM_SCO_TYPE sco_mode, + tBTM_ESCO_PARAMS* p_parms); /******************************************************************************* * @@ -1170,7 +1128,7 @@ extern tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, * * ******************************************************************************/ -extern tBTM_STATUS BTM_SetWBSCodec (tBTM_SCO_CODEC_TYPE codec_type); +extern tBTM_STATUS BTM_SetWBSCodec(tBTM_SCO_CODEC_TYPE codec_type); /******************************************************************************* * @@ -1185,8 +1143,8 @@ extern tBTM_STATUS BTM_SetWBSCodec (tBTM_SCO_CODEC_TYPE codec_type); * BTM_ILLEGAL_VALUE if there is an illegal sco_inx * ******************************************************************************/ -extern tBTM_STATUS BTM_RegForEScoEvts (uint16_t sco_inx, - tBTM_ESCO_CBACK *p_esco_cback); +extern tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx, + tBTM_ESCO_CBACK* p_esco_cback); /******************************************************************************* * @@ -1209,8 +1167,8 @@ extern tBTM_STATUS BTM_RegForEScoEvts (uint16_t sco_inx, * 1.2 specification. * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadEScoLinkParms (uint16_t sco_inx, - tBTM_ESCO_DATA *p_parms); +extern tBTM_STATUS BTM_ReadEScoLinkParms(uint16_t sco_inx, + tBTM_ESCO_DATA* p_parms); /******************************************************************************* * @@ -1231,8 +1189,8 @@ extern tBTM_STATUS BTM_ReadEScoLinkParms (uint16_t sco_inx, * 1.2 specification. * ******************************************************************************/ -extern tBTM_STATUS BTM_ChangeEScoLinkParms (uint16_t sco_inx, - tBTM_CHG_ESCO_PARAMS *p_parms); +extern tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx, + tBTM_CHG_ESCO_PARAMS* p_parms); /******************************************************************************* * @@ -1252,8 +1210,8 @@ extern tBTM_STATUS BTM_ChangeEScoLinkParms (uint16_t sco_inx, * Returns void * ******************************************************************************/ -extern void BTM_EScoConnRsp (uint16_t sco_inx, uint8_t hci_status, - tBTM_ESCO_PARAMS *p_parms); +extern void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status, + tBTM_ESCO_PARAMS* p_parms); /******************************************************************************* * @@ -1264,7 +1222,7 @@ extern void BTM_EScoConnRsp (uint16_t sco_inx, uint8_t hci_status, * Returns uint8_t * ******************************************************************************/ -extern uint8_t BTM_GetNumScoLinks (void); +extern uint8_t BTM_GetNumScoLinks(void); /***************************************************************************** * SECURITY MANAGEMENT FUNCTIONS @@ -1281,7 +1239,7 @@ extern uint8_t BTM_GetNumScoLinks (void); * Returns true if registered OK, else false * ******************************************************************************/ -extern bool BTM_SecRegister (tBTM_APPL_INFO *p_cb_info); +extern bool BTM_SecRegister(tBTM_APPL_INFO* p_cb_info); /******************************************************************************* * @@ -1293,8 +1251,8 @@ extern bool BTM_SecRegister (tBTM_APPL_INFO *p_cb_info); * Returns true if registered OK, else false * ******************************************************************************/ -extern bool BTM_SecRegisterLinkKeyNotificationCallback( - tBTM_LINK_KEY_CALLBACK *p_callback); +extern bool BTM_SecRegisterLinkKeyNotificationCallback( + tBTM_LINK_KEY_CALLBACK* p_callback); /******************************************************************************* * @@ -1307,8 +1265,7 @@ extern bool BTM_SecRegisterLinkKeyNotificationCallback( * Returns true if registered OK, else false * ******************************************************************************/ -extern bool BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback); - +extern bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback); /******************************************************************************* * @@ -1320,7 +1277,8 @@ extern bool BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callba * Returns true if OK, else false * ******************************************************************************/ -extern bool BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback); +extern bool BTM_SecDeleteRmtNameNotifyCallback( + tBTM_RMT_NAME_CALLBACK* p_callback); /******************************************************************************* * @@ -1331,7 +1289,7 @@ extern bool BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_cal * Returns bool true or false is device found * ******************************************************************************/ -extern bool BTM_GetSecurityFlags (BD_ADDR bd_addr, uint8_t * p_sec_flags); +extern bool BTM_GetSecurityFlags(BD_ADDR bd_addr, uint8_t* p_sec_flags); /******************************************************************************* * @@ -1348,8 +1306,9 @@ extern bool BTM_GetSecurityFlags (BD_ADDR bd_addr, uint8_t * p_sec_flags); * Returns bool true or false is device found * ******************************************************************************/ -extern bool BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, - uint8_t * p_sec_flags, tBT_TRANSPORT transport); +extern bool BTM_GetSecurityFlagsByTransport(BD_ADDR bd_addr, + uint8_t* p_sec_flags, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -1361,7 +1320,7 @@ extern bool BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, * otherwise, the trusted mask * ******************************************************************************/ -extern uint32_t * BTM_ReadTrustedMask (BD_ADDR bd_addr); +extern uint32_t* BTM_ReadTrustedMask(BD_ADDR bd_addr); /******************************************************************************* * @@ -1372,8 +1331,8 @@ extern uint32_t * BTM_ReadTrustedMask (BD_ADDR bd_addr); * Returns void * ******************************************************************************/ -extern void BTM_SetPinType (uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len); - +extern void BTM_SetPinType(uint8_t pin_type, PIN_CODE pin_code, + uint8_t pin_code_len); /******************************************************************************* * @@ -1389,7 +1348,7 @@ extern void BTM_SetPinType (uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_cod * Returns void * ******************************************************************************/ -extern void BTM_SetPairableMode (bool allow_pairing, bool connect_only_paired); +extern void BTM_SetPairableMode(bool allow_pairing, bool connect_only_paired); /******************************************************************************* * @@ -1407,7 +1366,7 @@ extern void BTM_SetPairableMode (bool allow_pairing, bool connect_only_pai * Returns void * ******************************************************************************/ -extern void BTM_SetSecureConnectionsOnly (bool secure_connections_only_mode); +extern void BTM_SetSecureConnectionsOnly(bool secure_connections_only_mode); /******************************************************************************* * @@ -1421,10 +1380,10 @@ extern void BTM_SetSecureConnectionsOnly (bool secure_connections_only_mode); * Returns true if registered OK, else false * ******************************************************************************/ -extern bool BTM_SetSecurityLevel (bool is_originator, const char *p_name, - uint8_t service_id, uint16_t sec_level, - uint16_t psm, uint32_t mx_proto_id, - uint32_t mx_chan_id); +extern bool BTM_SetSecurityLevel(bool is_originator, const char* p_name, + uint8_t service_id, uint16_t sec_level, + uint16_t psm, uint32_t mx_proto_id, + uint32_t mx_chan_id); /******************************************************************************* * @@ -1436,7 +1395,8 @@ extern bool BTM_SetSecurityLevel (bool is_originator, const char *p_name, * Returns void * ******************************************************************************/ -extern void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, uint32_t mx_chan_id); +extern void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, + uint32_t mx_chan_id); /******************************************************************************* * @@ -1450,7 +1410,7 @@ extern void BTM_SetOutService(BD_ADDR bd_addr, uint8_t service_id, uint32_t mx_c * Returns Number of records that were freed. * ******************************************************************************/ -extern uint8_t BTM_SecClrService (uint8_t service_id); +extern uint8_t BTM_SecClrService(uint8_t service_id); /******************************************************************************* * @@ -1465,11 +1425,11 @@ extern uint8_t BTM_SecClrService (uint8_t service_id); * Returns true if added OK, else false * ******************************************************************************/ -extern bool BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, - BD_NAME bd_name, uint8_t *features, - uint32_t trusted_mask[], LINK_KEY link_key, - uint8_t key_type, tBTM_IO_CAP io_cap, uint8_t pin_length); - +extern bool BTM_SecAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, + BD_NAME bd_name, uint8_t* features, + uint32_t trusted_mask[], LINK_KEY link_key, + uint8_t key_type, tBTM_IO_CAP io_cap, + uint8_t pin_length); /******************************************************************************* * @@ -1480,7 +1440,7 @@ extern bool BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, * Returns true if rmoved OK, false if not found * ******************************************************************************/ -extern bool BTM_SecDeleteDevice (BD_ADDR bd_addr); +extern bool BTM_SecDeleteDevice(BD_ADDR bd_addr); /******************************************************************************* * @@ -1490,7 +1450,7 @@ extern bool BTM_SecDeleteDevice (BD_ADDR bd_addr); * remove device. * ******************************************************************************/ -extern void BTM_SecClearSecurityFlags (BD_ADDR bd_addr); +extern void BTM_SecClearSecurityFlags(BD_ADDR bd_addr); /******************************************************************************* * @@ -1504,9 +1464,7 @@ extern void BTM_SecClearSecurityFlags (BD_ADDR bd_addr); * Returns BTM_SUCCESS if successful, otherwise error code * ******************************************************************************/ -extern tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr, - LINK_KEY link_key); - +extern tBTM_STATUS BTM_SecGetDeviceLinkKey(BD_ADDR bd_addr, LINK_KEY link_key); /******************************************************************************* * @@ -1522,8 +1480,7 @@ extern tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr, * otherwise. * ******************************************************************************/ -extern tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr); - +extern tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(BD_ADDR bd_addr); /******************************************************************************* * @@ -1544,9 +1501,8 @@ extern tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr); * Returns void * ******************************************************************************/ -extern void BTM_PINCodeReply (BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, - uint8_t *p_pin, uint32_t trusted_mask[]); - +extern void BTM_PINCodeReply(BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, + uint8_t* p_pin, uint32_t trusted_mask[]); /******************************************************************************* * @@ -1562,9 +1518,8 @@ extern void BTM_PINCodeReply (BD_ADDR bd_addr, uint8_t res, uint8_t pin_len, * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, - uint8_t pin_len, uint8_t *p_pin, - uint32_t trusted_mask[]); +extern tBTM_STATUS BTM_SecBond(BD_ADDR bd_addr, uint8_t pin_len, uint8_t* p_pin, + uint32_t trusted_mask[]); /******************************************************************************* * @@ -1583,10 +1538,10 @@ extern tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr, * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, - tBT_TRANSPORT transport, - uint8_t pin_len, uint8_t *p_pin, - uint32_t trusted_mask[]); +extern tBTM_STATUS BTM_SecBondByTransport(BD_ADDR bd_addr, + tBT_TRANSPORT transport, + uint8_t pin_len, uint8_t* p_pin, + uint32_t trusted_mask[]); /******************************************************************************* * @@ -1598,7 +1553,7 @@ extern tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr, * Returns BTM_CMD_STARTED if successfully initiated, otherwise error * ******************************************************************************/ -extern tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr); +extern tBTM_STATUS BTM_SecBondCancel(BD_ADDR bd_addr); /******************************************************************************* * @@ -1628,9 +1583,10 @@ extern tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr); * BTM_MODE_UNSUPPORTED - if security manager not linked in. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, - tBTM_SEC_CBACK *p_callback, - void *p_ref_data, tBTM_BLE_SEC_ACT sec_act); +extern tBTM_STATUS BTM_SetEncryption(BD_ADDR bd_addr, tBT_TRANSPORT transport, + tBTM_SEC_CBACK* p_callback, + void* p_ref_data, + tBTM_BLE_SEC_ACT sec_act); /******************************************************************************* * @@ -1660,7 +1616,8 @@ extern void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr); * 0 - 999999(0xF423F). * ******************************************************************************/ -extern void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, uint32_t passkey); +extern void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, + uint32_t passkey); /******************************************************************************* * @@ -1693,8 +1650,8 @@ extern void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type); * auth_req- MITM protection required or not. * ******************************************************************************/ -extern void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, - tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req); +extern void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob, + tBTM_AUTH_REQ auth_req); /******************************************************************************* * @@ -1739,8 +1696,8 @@ extern void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, * Returns Number of bytes in p_data. * ******************************************************************************/ -extern uint16_t BTM_BuildOobData(uint8_t *p_data, uint16_t max_len, BT_OCTET16 c, - BT_OCTET16 r, uint8_t name_len); +extern uint16_t BTM_BuildOobData(uint8_t* p_data, uint16_t max_len, + BT_OCTET16 c, BT_OCTET16 r, uint8_t name_len); /******************************************************************************* * @@ -1757,7 +1714,7 @@ extern uint16_t BTM_BuildOobData(uint8_t *p_data, uint16_t max_len, BT_OCTET16 c * else false. * ******************************************************************************/ -extern bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr); +extern bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr); /******************************************************************************* * @@ -1772,7 +1729,7 @@ extern bool BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr); * else false. * ******************************************************************************/ -extern bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr); +extern bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr); /******************************************************************************* * @@ -1789,7 +1746,8 @@ extern bool BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr); * NULL, if the tag is not found. * ******************************************************************************/ -extern uint8_t * BTM_ReadOobData(uint8_t *p_data, uint8_t eir_tag, uint8_t *p_len); +extern uint8_t* BTM_ReadOobData(uint8_t* p_data, uint8_t eir_tag, + uint8_t* p_len); /******************************************************************************* * @@ -1801,8 +1759,7 @@ extern uint8_t * BTM_ReadOobData(uint8_t *p_data, uint8_t eir_tag, uint8_t *p_le * Returns Pointer to the name or NULL * ******************************************************************************/ -extern char *BTM_SecReadDevName (BD_ADDR bd_addr); - +extern char* BTM_SecReadDevName(BD_ADDR bd_addr); /***************************************************************************** * POWER MANAGEMENT FUNCTIONS @@ -1818,9 +1775,8 @@ extern char *BTM_SecReadDevName (BD_ADDR bd_addr); * BTM_ILLEGAL_VALUE * ******************************************************************************/ -extern tBTM_STATUS BTM_PmRegister (uint8_t mask, uint8_t *p_pm_id, - tBTM_PM_STATUS_CBACK *p_cb); - +extern tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id, + tBTM_PM_STATUS_CBACK* p_cb); /******************************************************************************* * @@ -1833,9 +1789,8 @@ extern tBTM_STATUS BTM_PmRegister (uint8_t mask, uint8_t *p_pm_id, * BTM_UNKNOWN_ADDR if bd addr is not active or bad * ******************************************************************************/ -extern tBTM_STATUS BTM_SetPowerMode (uint8_t pm_id, BD_ADDR remote_bda, - tBTM_PM_PWR_MD *p_mode); - +extern tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, BD_ADDR remote_bda, + tBTM_PM_PWR_MD* p_mode); /******************************************************************************* * @@ -1857,8 +1812,7 @@ extern tBTM_STATUS BTM_SetPowerMode (uint8_t pm_id, BD_ADDR remote_bda, * BTM_UNKNOWN_ADDR if bd addr is not active or bad * ******************************************************************************/ -extern tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, - tBTM_PM_MODE *p_mode); +extern tBTM_STATUS BTM_ReadPowerMode(BD_ADDR remote_bda, tBTM_PM_MODE* p_mode); /******************************************************************************* * @@ -1878,8 +1832,8 @@ extern tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda, * BTM_CMD_STORED if the command is stored * ******************************************************************************/ -extern tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, uint16_t max_lat, - uint16_t min_rmt_to, uint16_t min_loc_to); +extern tBTM_STATUS BTM_SetSsrParams(BD_ADDR remote_bda, uint16_t max_lat, + uint16_t min_rmt_to, uint16_t min_loc_to); /******************************************************************************* * @@ -1891,7 +1845,8 @@ extern tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, uint16_t max_lat, * Returns the handle of the connection, or 0xFFFF if none. * ******************************************************************************/ -extern uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT transport); +extern uint16_t BTM_GetHCIConnHandle(const BD_ADDR remote_bda, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -1906,7 +1861,7 @@ extern uint16_t BTM_GetHCIConnHandle (const BD_ADDR remote_bda, tBT_TRANSPORT tr * the results * ******************************************************************************/ -extern tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb); +extern tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB* p_cb); /******************************************************************************* * @@ -1921,7 +1876,7 @@ extern tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb); * BTM_MODE_UNSUPPORTED - if local device cannot support it * ******************************************************************************/ -extern tBTM_STATUS BTM_WriteEIR( BT_HDR * p_buff ); +extern tBTM_STATUS BTM_WriteEIR(BT_HDR* p_buff); /******************************************************************************* * @@ -1936,7 +1891,8 @@ extern tBTM_STATUS BTM_WriteEIR( BT_HDR * p_buff ); * Returns pointer of EIR data * ******************************************************************************/ -extern uint8_t *BTM_CheckEirData( uint8_t *p_eir, uint8_t type, uint8_t *p_length ); +extern uint8_t* BTM_CheckEirData(uint8_t* p_eir, uint8_t type, + uint8_t* p_length); /******************************************************************************* * @@ -1951,7 +1907,7 @@ extern uint8_t *BTM_CheckEirData( uint8_t *p_eir, uint8_t type, uint8_t *p_lengt * false - if not found * ******************************************************************************/ -extern bool BTM_HasEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); +extern bool BTM_HasEirService(uint32_t* p_eir_uuid, uint16_t uuid16); /******************************************************************************* * @@ -1967,8 +1923,8 @@ extern bool BTM_HasEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); * BTM_EIR_UNKNOWN - if not found and it is not complete list * ******************************************************************************/ -extern tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results, - uint16_t uuid16 ); +extern tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( + tBTM_INQ_RESULTS* p_results, uint16_t uuid16); /******************************************************************************* * @@ -1983,7 +1939,7 @@ extern tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_resu * Returns None * ******************************************************************************/ -extern void BTM_AddEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); +extern void BTM_AddEirService(uint32_t* p_eir_uuid, uint16_t uuid16); /******************************************************************************* * @@ -1998,7 +1954,7 @@ extern void BTM_AddEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); * Returns None * ******************************************************************************/ -extern void BTM_RemoveEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); +extern void BTM_RemoveEirService(uint32_t* p_eir_uuid, uint16_t uuid16); /******************************************************************************* * @@ -2016,8 +1972,9 @@ extern void BTM_RemoveEirService( uint32_t *p_eir_uuid, uint16_t uuid16 ); * BTM_EIR_COMPLETE_16BITS_UUID_TYPE, otherwise * ******************************************************************************/ -extern uint8_t BTM_GetEirSupportedServices( uint32_t *p_eir_uuid, uint8_t **p, - uint8_t max_num_uuid16, uint8_t *p_num_uuid16); +extern uint8_t BTM_GetEirSupportedServices(uint32_t* p_eir_uuid, uint8_t** p, + uint8_t max_num_uuid16, + uint8_t* p_num_uuid16); /******************************************************************************* * @@ -2040,8 +1997,9 @@ extern uint8_t BTM_GetEirSupportedServices( uint32_t *p_eir_uuid, uint8_t **p * BTM_EIR_MORE_128BITS_UUID_TYPE * ******************************************************************************/ -extern uint8_t BTM_GetEirUuidList( uint8_t *p_eir, uint8_t uuid_size, uint8_t *p_num_uuid, - uint8_t *p_uuid_list, uint8_t max_num_uuid); +extern uint8_t BTM_GetEirUuidList(uint8_t* p_eir, uint8_t uuid_size, + uint8_t* p_num_uuid, uint8_t* p_uuid_list, + uint8_t max_num_uuid); /***************************************************************************** * SCO OVER HCI @@ -2071,10 +2029,10 @@ extern uint8_t BTM_GetEirUuidList( uint8_t *p_eir, uint8_t uuid_size, uint8_t *p * * ******************************************************************************/ -extern tBTM_STATUS BTM_ConfigScoPath (tBTM_SCO_ROUTE_TYPE path, - tBTM_SCO_DATA_CB *p_sco_data_cb, - tBTM_SCO_PCM_PARAM *p_pcm_param, - bool err_data_rpt); +extern tBTM_STATUS BTM_ConfigScoPath(tBTM_SCO_ROUTE_TYPE path, + tBTM_SCO_DATA_CB* p_sco_data_cb, + tBTM_SCO_PCM_PARAM* p_pcm_param, + bool err_data_rpt); /******************************************************************************* * @@ -2097,7 +2055,7 @@ extern tBTM_STATUS BTM_ConfigScoPath (tBTM_SCO_ROUTE_TYPE path, * * ******************************************************************************/ -extern tBTM_STATUS BTM_WriteScoData (uint16_t sco_inx, BT_HDR *p_buf); +extern tBTM_STATUS BTM_WriteScoData(uint16_t sco_inx, BT_HDR* p_buf); /******************************************************************************* * @@ -2108,8 +2066,8 @@ extern tBTM_STATUS BTM_WriteScoData (uint16_t sco_inx, BT_HDR *p_buf); * Returns void * ******************************************************************************/ -extern void BTM_SetARCMode (uint8_t iface, uint8_t arc_mode, tBTM_VSC_CMPL_CB *p_arc_cb); - +extern void BTM_SetARCMode(uint8_t iface, uint8_t arc_mode, + tBTM_VSC_CMPL_CB* p_arc_cb); /******************************************************************************* * @@ -2120,8 +2078,7 @@ extern void BTM_SetARCMode (uint8_t iface, uint8_t arc_mode, tBTM_VSC_CMPL_CB *p * Returns void * ******************************************************************************/ -extern void BTM_PCM2Setup_Write (bool clk_master, tBTM_VSC_CMPL_CB *p_arc_cb); - +extern void BTM_PCM2Setup_Write(bool clk_master, tBTM_VSC_CMPL_CB* p_arc_cb); /******************************************************************************* * diff --git a/stack/include/btm_api_types.h b/stack/include/btm_api_types.h index f26deb166..fa8b2d7be 100644 --- a/stack/include/btm_api_types.h +++ b/stack/include/btm_api_types.h @@ -20,84 +20,80 @@ #define BTM_API_TYPES_H #include "bt_target.h" -#include "smp_api_types.h" #include "hcidefs.h" +#include "smp_api_types.h" /* Maximum number of bytes allowed for vendor specific command parameters */ -#define BTM_MAX_VENDOR_SPECIFIC_LEN HCI_COMMAND_SIZE +#define BTM_MAX_VENDOR_SPECIFIC_LEN HCI_COMMAND_SIZE /* BTM application return status codes */ -enum -{ - BTM_SUCCESS = 0, /* 0 Command succeeded */ - BTM_CMD_STARTED, /* 1 Command started OK. */ - BTM_BUSY, /* 2 Device busy with another command */ - BTM_NO_RESOURCES, /* 3 No resources to issue command */ - BTM_MODE_UNSUPPORTED, /* 4 Request for 1 or more unsupported modes */ - BTM_ILLEGAL_VALUE, /* 5 Illegal parameter value */ - BTM_WRONG_MODE, /* 6 Device in wrong mode for request */ - BTM_UNKNOWN_ADDR, /* 7 Unknown remote BD address */ - BTM_DEVICE_TIMEOUT, /* 8 Device timeout */ - BTM_BAD_VALUE_RET, /* 9 A bad value was received from HCI */ - BTM_ERR_PROCESSING, /* 10 Generic error */ - BTM_NOT_AUTHORIZED, /* 11 Authorization failed */ - BTM_DEV_RESET, /* 12 Device has been reset */ - BTM_CMD_STORED, /* 13 request is stored in control block */ - BTM_ILLEGAL_ACTION, /* 14 state machine gets illegal command */ - BTM_DELAY_CHECK, /* 15 delay the check on encryption */ - BTM_SCO_BAD_LENGTH, /* 16 Bad SCO over HCI data length */ - BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */ - BTM_FAILED_ON_SECURITY, /* 18 security failed */ - BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */ - BTM_MODE4_LEVEL4_NOT_SUPPORTED /* 20 Secure Connections Only Mode can't be supported */ +enum { + BTM_SUCCESS = 0, /* 0 Command succeeded */ + BTM_CMD_STARTED, /* 1 Command started OK. */ + BTM_BUSY, /* 2 Device busy with another command */ + BTM_NO_RESOURCES, /* 3 No resources to issue command */ + BTM_MODE_UNSUPPORTED, /* 4 Request for 1 or more unsupported modes */ + BTM_ILLEGAL_VALUE, /* 5 Illegal parameter value */ + BTM_WRONG_MODE, /* 6 Device in wrong mode for request */ + BTM_UNKNOWN_ADDR, /* 7 Unknown remote BD address */ + BTM_DEVICE_TIMEOUT, /* 8 Device timeout */ + BTM_BAD_VALUE_RET, /* 9 A bad value was received from HCI */ + BTM_ERR_PROCESSING, /* 10 Generic error */ + BTM_NOT_AUTHORIZED, /* 11 Authorization failed */ + BTM_DEV_RESET, /* 12 Device has been reset */ + BTM_CMD_STORED, /* 13 request is stored in control block */ + BTM_ILLEGAL_ACTION, /* 14 state machine gets illegal command */ + BTM_DELAY_CHECK, /* 15 delay the check on encryption */ + BTM_SCO_BAD_LENGTH, /* 16 Bad SCO over HCI data length */ + BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */ + BTM_FAILED_ON_SECURITY, /* 18 security failed */ + BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */ + BTM_MODE4_LEVEL4_NOT_SUPPORTED /* 20 Secure Connections Only Mode can't be + supported */ }; typedef uint8_t tBTM_STATUS; #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) -typedef enum -{ - BTM_BR_ONE, /*0 First state or BR/EDR scan 1*/ - BTM_BLE_ONE, /*1BLE scan 1*/ - BTM_BR_TWO, /*2 BR/EDR scan 2*/ - BTM_BLE_TWO, /*3 BLE scan 2*/ - BTM_FINISH, /*4 End of Interleave Scan, or normal scan*/ - BTM_NO_INTERLEAVING /*5 No Interleaving*/ -}btm_inq_state; +typedef enum { + BTM_BR_ONE, /*0 First state or BR/EDR scan 1*/ + BTM_BLE_ONE, /*1BLE scan 1*/ + BTM_BR_TWO, /*2 BR/EDR scan 2*/ + BTM_BLE_TWO, /*3 BLE scan 2*/ + BTM_FINISH, /*4 End of Interleave Scan, or normal scan*/ + BTM_NO_INTERLEAVING /*5 No Interleaving*/ +} btm_inq_state; #endif - - /************************* * Device Control Types *************************/ -#define BTM_DEVICE_ROLE_BR 0x01 -#define BTM_DEVICE_ROLE_DUAL 0x02 -#define BTM_MAX_DEVICE_ROLE BTM_DEVICE_ROLE_DUAL +#define BTM_DEVICE_ROLE_BR 0x01 +#define BTM_DEVICE_ROLE_DUAL 0x02 +#define BTM_MAX_DEVICE_ROLE BTM_DEVICE_ROLE_DUAL typedef uint8_t tBTM_DEVICE_ROLE; /* Device name of peer (may be truncated to save space in BTM database) */ typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1]; /* Structure returned with local version information */ -typedef struct -{ - uint8_t hci_version; - uint16_t hci_revision; - uint8_t lmp_version; - uint16_t manufacturer; - uint16_t lmp_subversion; +typedef struct { + uint8_t hci_version; + uint16_t hci_revision; + uint8_t lmp_version; + uint16_t manufacturer; + uint16_t lmp_subversion; } tBTM_VERSION_INFO; /* Structure returned with Vendor Specific Command complete callback */ -typedef struct -{ - uint16_t opcode; - uint16_t param_len; - uint8_t *p_param_buf; +typedef struct { + uint16_t opcode; + uint16_t param_len; + uint8_t* p_param_buf; } tBTM_VSC_CMPL; -#define BTM_VSC_CMPL_DATA_SIZE (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL)) +#define BTM_VSC_CMPL_DATA_SIZE \ + (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL)) /************************************************** * Device Control and General Callback Functions **************************************************/ @@ -106,43 +102,35 @@ typedef struct * has detected that the controller status has changed. This asynchronous event * is enabled/disabled by calling BTM_RegisterForDeviceStatusNotif(). */ -enum -{ - BTM_DEV_STATUS_UP, - BTM_DEV_STATUS_DOWN, - BTM_DEV_STATUS_CMD_TOUT -}; +enum { BTM_DEV_STATUS_UP, BTM_DEV_STATUS_DOWN, BTM_DEV_STATUS_CMD_TOUT }; typedef uint8_t tBTM_DEV_STATUS; - -typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status); - +typedef void(tBTM_DEV_STATUS_CB)(tBTM_DEV_STATUS status); /* Callback function for when a vendor specific event occurs. The length and * array of returned parameter bytes are included. This asynchronous event * is enabled/disabled by calling BTM_RegisterForVSEvents(). */ -typedef void (tBTM_VS_EVT_CB) (uint8_t len, uint8_t *p); - +typedef void(tBTM_VS_EVT_CB)(uint8_t len, uint8_t* p); /* General callback function for notifying an application that a synchronous * BTM function is complete. The pointer contains the address of any returned * data. */ -typedef void (tBTM_CMPL_CB) (void *p1); +typedef void(tBTM_CMPL_CB)(void* p1); /* VSC callback function for notifying an application that a synchronous * BTM function is complete. The pointer contains the address of any returned * data. */ -typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1); +typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1); /* Callback for apps to check connection and inquiry filters. * Parameters are the BD Address of remote and the Dev Class of remote. If the * app returns none zero, the connection or inquiry result will be dropped. */ -typedef uint8_t (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); +typedef uint8_t(tBTM_FILTER_CB)(BD_ADDR bd_addr, DEV_CLASS dc); /***************************************************************************** * DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device @@ -151,426 +139,445 @@ typedef uint8_t (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); * Device Discovery Constants *******************************/ /* Discoverable modes */ -#define BTM_NON_DISCOVERABLE 0 -#define BTM_LIMITED_DISCOVERABLE 1 -#define BTM_GENERAL_DISCOVERABLE 2 -#define BTM_DISCOVERABLE_MASK (BTM_LIMITED_DISCOVERABLE|BTM_GENERAL_DISCOVERABLE) -#define BTM_MAX_DISCOVERABLE BTM_GENERAL_DISCOVERABLE +#define BTM_NON_DISCOVERABLE 0 +#define BTM_LIMITED_DISCOVERABLE 1 +#define BTM_GENERAL_DISCOVERABLE 2 +#define BTM_DISCOVERABLE_MASK \ + (BTM_LIMITED_DISCOVERABLE | BTM_GENERAL_DISCOVERABLE) +#define BTM_MAX_DISCOVERABLE BTM_GENERAL_DISCOVERABLE /* high byte for BLE Discoverable modes */ -#define BTM_BLE_NON_DISCOVERABLE 0x0000 -#define BTM_BLE_LIMITED_DISCOVERABLE 0x0100 -#define BTM_BLE_GENERAL_DISCOVERABLE 0x0200 -#define BTM_BLE_MAX_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE -#define BTM_BLE_DISCOVERABLE_MASK (BTM_BLE_NON_DISCOVERABLE|BTM_BLE_LIMITED_DISCOVERABLE|BTM_BLE_GENERAL_DISCOVERABLE) +#define BTM_BLE_NON_DISCOVERABLE 0x0000 +#define BTM_BLE_LIMITED_DISCOVERABLE 0x0100 +#define BTM_BLE_GENERAL_DISCOVERABLE 0x0200 +#define BTM_BLE_MAX_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE +#define BTM_BLE_DISCOVERABLE_MASK \ + (BTM_BLE_NON_DISCOVERABLE | BTM_BLE_LIMITED_DISCOVERABLE | \ + BTM_BLE_GENERAL_DISCOVERABLE) /* Connectable modes */ -#define BTM_NON_CONNECTABLE 0 -#define BTM_CONNECTABLE 1 -#define BTM_CONNECTABLE_MASK (BTM_NON_CONNECTABLE | BTM_CONNECTABLE) +#define BTM_NON_CONNECTABLE 0 +#define BTM_CONNECTABLE 1 +#define BTM_CONNECTABLE_MASK (BTM_NON_CONNECTABLE | BTM_CONNECTABLE) /* high byte for BLE Connectable modes */ -#define BTM_BLE_NON_CONNECTABLE 0x0000 -#define BTM_BLE_CONNECTABLE 0x0100 -#define BTM_BLE_MAX_CONNECTABLE BTM_BLE_CONNECTABLE -#define BTM_BLE_CONNECTABLE_MASK (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE) +#define BTM_BLE_NON_CONNECTABLE 0x0000 +#define BTM_BLE_CONNECTABLE 0x0100 +#define BTM_BLE_MAX_CONNECTABLE BTM_BLE_CONNECTABLE +#define BTM_BLE_CONNECTABLE_MASK (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE) /* Inquiry modes * Note: These modes are associated with the inquiry active values (BTM_*ACTIVE) */ -#define BTM_INQUIRY_NONE 0 -#define BTM_GENERAL_INQUIRY 0x01 -#define BTM_LIMITED_INQUIRY 0x02 -#define BTM_BR_INQUIRY_MASK (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY) +#define BTM_INQUIRY_NONE 0 +#define BTM_GENERAL_INQUIRY 0x01 +#define BTM_LIMITED_INQUIRY 0x02 +#define BTM_BR_INQUIRY_MASK (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY) /* high byte of inquiry mode for BLE inquiry mode */ -#define BTM_BLE_INQUIRY_NONE 0x00 -#define BTM_BLE_GENERAL_INQUIRY 0x10 -#define BTM_BLE_LIMITED_INQUIRY 0x20 -#define BTM_BLE_INQUIRY_MASK (BTM_BLE_GENERAL_INQUIRY|BTM_BLE_LIMITED_INQUIRY) +#define BTM_BLE_INQUIRY_NONE 0x00 +#define BTM_BLE_GENERAL_INQUIRY 0x10 +#define BTM_BLE_LIMITED_INQUIRY 0x20 +#define BTM_BLE_INQUIRY_MASK (BTM_BLE_GENERAL_INQUIRY | BTM_BLE_LIMITED_INQUIRY) /* BTM_IsInquiryActive return values (Bit Mask) * Note: These bit masks are associated with the inquiry modes (BTM_*_INQUIRY) */ /* no inquiry in progress */ -#define BTM_INQUIRY_INACTIVE 0x0 +#define BTM_INQUIRY_INACTIVE 0x0 /* a general inquiry is in progress */ -#define BTM_GENERAL_INQUIRY_ACTIVE BTM_GENERAL_INQUIRY +#define BTM_GENERAL_INQUIRY_ACTIVE BTM_GENERAL_INQUIRY /* a limited inquiry is in progress */ -#define BTM_LIMITED_INQUIRY_ACTIVE BTM_LIMITED_INQUIRY +#define BTM_LIMITED_INQUIRY_ACTIVE BTM_LIMITED_INQUIRY /* a periodic inquiry is active */ #define BTM_PERIODIC_INQUIRY_ACTIVE 0x8 /* SSP is active, so inquiry is disallowed (work around for FW bug) */ -#define BTM_SSP_INQUIRY_ACTIVE 0x4 +#define BTM_SSP_INQUIRY_ACTIVE 0x4 /* a general inquiry is in progress */ -#define BTM_LE_GENERAL_INQUIRY_ACTIVE BTM_BLE_GENERAL_INQUIRY +#define BTM_LE_GENERAL_INQUIRY_ACTIVE BTM_BLE_GENERAL_INQUIRY /* a limited inquiry is in progress */ -#define BTM_LE_LIMITED_INQUIRY_ACTIVE BTM_BLE_LIMITED_INQUIRY +#define BTM_LE_LIMITED_INQUIRY_ACTIVE BTM_BLE_LIMITED_INQUIRY /* inquiry activity mask */ /* BR/EDR inquiry activity mask */ -#define BTM_BR_INQ_ACTIVE_MASK (BTM_GENERAL_INQUIRY_ACTIVE|BTM_LIMITED_INQUIRY_ACTIVE|BTM_PERIODIC_INQUIRY_ACTIVE) +#define BTM_BR_INQ_ACTIVE_MASK \ + (BTM_GENERAL_INQUIRY_ACTIVE | BTM_LIMITED_INQUIRY_ACTIVE | \ + BTM_PERIODIC_INQUIRY_ACTIVE) /* LE scan activity mask */ -#define BTM_BLE_SCAN_ACTIVE_MASK 0xF0 +#define BTM_BLE_SCAN_ACTIVE_MASK 0xF0 /* LE inquiry activity mask*/ -#define BTM_BLE_INQ_ACTIVE_MASK (BTM_LE_GENERAL_INQUIRY_ACTIVE|BTM_LE_LIMITED_INQUIRY_ACTIVE) +#define BTM_BLE_INQ_ACTIVE_MASK \ + (BTM_LE_GENERAL_INQUIRY_ACTIVE | BTM_LE_LIMITED_INQUIRY_ACTIVE) /* inquiry activity mask */ -#define BTM_INQUIRY_ACTIVE_MASK (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) +#define BTM_INQUIRY_ACTIVE_MASK \ + (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) /* Define scan types */ -#define BTM_SCAN_TYPE_STANDARD 0 -#define BTM_SCAN_TYPE_INTERLACED 1 /* 1.2 devices only */ +#define BTM_SCAN_TYPE_STANDARD 0 +#define BTM_SCAN_TYPE_INTERLACED 1 /* 1.2 devices only */ /* Define inquiry results mode */ -#define BTM_INQ_RESULT_STANDARD 0 -#define BTM_INQ_RESULT_WITH_RSSI 1 -#define BTM_INQ_RESULT_EXTENDED 2 +#define BTM_INQ_RESULT_STANDARD 0 +#define BTM_INQ_RESULT_WITH_RSSI 1 +#define BTM_INQ_RESULT_EXTENDED 2 /* RSSI value not supplied (ignore it) */ -#define BTM_INQ_RES_IGNORE_RSSI 0x7f +#define BTM_INQ_RES_IGNORE_RSSI 0x7f /* Inquiry Filter Condition types (see tBTM_INQ_PARMS) */ /* Inquiry Filtering is turned off */ -#define BTM_CLR_INQUIRY_FILTER 0 +#define BTM_CLR_INQUIRY_FILTER 0 /* Filter on device class */ -#define BTM_FILTER_COND_DEVICE_CLASS HCI_FILTER_COND_DEVICE_CLASS +#define BTM_FILTER_COND_DEVICE_CLASS HCI_FILTER_COND_DEVICE_CLASS /* Filter on device addr */ -#define BTM_FILTER_COND_BD_ADDR HCI_FILTER_COND_BD_ADDR +#define BTM_FILTER_COND_BD_ADDR HCI_FILTER_COND_BD_ADDR /* State of the remote name retrieval during inquiry operations. * Used in the tBTM_INQ_INFO structure, and returned in the * BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext functions. * The name field is valid when the state returned is * BTM_INQ_RMT_NAME_DONE */ -#define BTM_INQ_RMT_NAME_EMPTY 0 -#define BTM_INQ_RMT_NAME_PENDING 1 -#define BTM_INQ_RMT_NAME_DONE 2 -#define BTM_INQ_RMT_NAME_FAILED 3 +#define BTM_INQ_RMT_NAME_EMPTY 0 +#define BTM_INQ_RMT_NAME_PENDING 1 +#define BTM_INQ_RMT_NAME_DONE 2 +#define BTM_INQ_RMT_NAME_FAILED 3 /********************************* *** Class of Device constants *** *********************************/ -#define BTM_FORMAT_TYPE_1 0x00 +#define BTM_FORMAT_TYPE_1 0x00 /**************************** * minor device class field ****************************/ /* 0x00 is used as unclassified for all minor device classes */ -#define BTM_COD_MINOR_UNCLASSIFIED 0x00 +#define BTM_COD_MINOR_UNCLASSIFIED 0x00 /* minor device class field for Computer Major Class */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ -#define BTM_COD_MINOR_DESKTOP_WORKSTATION 0x04 -#define BTM_COD_MINOR_SERVER_COMPUTER 0x08 -#define BTM_COD_MINOR_LAPTOP 0x0C -#define BTM_COD_MINOR_HANDHELD_PC_PDA 0x10 /* clam shell */ -#define BTM_COD_MINOR_PALM_SIZE_PC_PDA 0x14 -#define BTM_COD_MINOR_WEARABLE_COMPUTER 0x18 /* watch sized */ +#define BTM_COD_MINOR_DESKTOP_WORKSTATION 0x04 +#define BTM_COD_MINOR_SERVER_COMPUTER 0x08 +#define BTM_COD_MINOR_LAPTOP 0x0C +#define BTM_COD_MINOR_HANDHELD_PC_PDA 0x10 /* clam shell */ +#define BTM_COD_MINOR_PALM_SIZE_PC_PDA 0x14 +#define BTM_COD_MINOR_WEARABLE_COMPUTER 0x18 /* watch sized */ /* minor device class field for Phone Major Class */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ -#define BTM_COD_MINOR_CELLULAR 0x04 -#define BTM_COD_MINOR_CORDLESS 0x08 -#define BTM_COD_MINOR_SMART_PHONE 0x0C +#define BTM_COD_MINOR_CELLULAR 0x04 +#define BTM_COD_MINOR_CORDLESS 0x08 +#define BTM_COD_MINOR_SMART_PHONE 0x0C /* wired modem or voice gatway */ -#define BTM_COD_MINOR_WIRED_MDM_V_GTWY 0x10 -#define BTM_COD_MINOR_ISDN_ACCESS 0x14 +#define BTM_COD_MINOR_WIRED_MDM_V_GTWY 0x10 +#define BTM_COD_MINOR_ISDN_ACCESS 0x14 /* minor device class field for LAN Access Point Major Class */ /* Load Factor Field bit 5-7 */ -#define BTM_COD_MINOR_FULLY_AVAILABLE 0x00 -#define BTM_COD_MINOR_1_17_UTILIZED 0x20 -#define BTM_COD_MINOR_17_33_UTILIZED 0x40 -#define BTM_COD_MINOR_33_50_UTILIZED 0x60 -#define BTM_COD_MINOR_50_67_UTILIZED 0x80 -#define BTM_COD_MINOR_67_83_UTILIZED 0xA0 -#define BTM_COD_MINOR_83_99_UTILIZED 0xC0 -#define BTM_COD_MINOR_NO_SERVICE_AVAILABLE 0xE0 +#define BTM_COD_MINOR_FULLY_AVAILABLE 0x00 +#define BTM_COD_MINOR_1_17_UTILIZED 0x20 +#define BTM_COD_MINOR_17_33_UTILIZED 0x40 +#define BTM_COD_MINOR_33_50_UTILIZED 0x60 +#define BTM_COD_MINOR_50_67_UTILIZED 0x80 +#define BTM_COD_MINOR_67_83_UTILIZED 0xA0 +#define BTM_COD_MINOR_83_99_UTILIZED 0xC0 +#define BTM_COD_MINOR_NO_SERVICE_AVAILABLE 0xE0 /* sub-Field bit 2-4 */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ /* minor device class field for Audio/Video Major Class */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ -#define BTM_COD_MINOR_CONFM_HEADSET 0x04 -#define BTM_COD_MINOR_CONFM_HANDSFREE 0x08 -#define BTM_COD_MINOR_MICROPHONE 0x10 -#define BTM_COD_MINOR_LOUDSPEAKER 0x14 -#define BTM_COD_MINOR_HEADPHONES 0x18 -#define BTM_COD_MINOR_PORTABLE_AUDIO 0x1C -#define BTM_COD_MINOR_CAR_AUDIO 0x20 -#define BTM_COD_MINOR_SET_TOP_BOX 0x24 -#define BTM_COD_MINOR_HIFI_AUDIO 0x28 -#define BTM_COD_MINOR_VCR 0x2C -#define BTM_COD_MINOR_VIDEO_CAMERA 0x30 -#define BTM_COD_MINOR_CAMCORDER 0x34 -#define BTM_COD_MINOR_VIDEO_MONITOR 0x38 -#define BTM_COD_MINOR_VIDDISP_LDSPKR 0x3C -#define BTM_COD_MINOR_VIDEO_CONFERENCING 0x40 -#define BTM_COD_MINOR_GAMING_TOY 0x48 +#define BTM_COD_MINOR_CONFM_HEADSET 0x04 +#define BTM_COD_MINOR_CONFM_HANDSFREE 0x08 +#define BTM_COD_MINOR_MICROPHONE 0x10 +#define BTM_COD_MINOR_LOUDSPEAKER 0x14 +#define BTM_COD_MINOR_HEADPHONES 0x18 +#define BTM_COD_MINOR_PORTABLE_AUDIO 0x1C +#define BTM_COD_MINOR_CAR_AUDIO 0x20 +#define BTM_COD_MINOR_SET_TOP_BOX 0x24 +#define BTM_COD_MINOR_HIFI_AUDIO 0x28 +#define BTM_COD_MINOR_VCR 0x2C +#define BTM_COD_MINOR_VIDEO_CAMERA 0x30 +#define BTM_COD_MINOR_CAMCORDER 0x34 +#define BTM_COD_MINOR_VIDEO_MONITOR 0x38 +#define BTM_COD_MINOR_VIDDISP_LDSPKR 0x3C +#define BTM_COD_MINOR_VIDEO_CONFERENCING 0x40 +#define BTM_COD_MINOR_GAMING_TOY 0x48 /* minor device class field for Peripheral Major Class */ /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */ -#define BTM_COD_MINOR_KEYBOARD 0x40 -#define BTM_COD_MINOR_POINTING 0x80 -#define BTM_COD_MINOR_COMBO 0xC0 +#define BTM_COD_MINOR_KEYBOARD 0x40 +#define BTM_COD_MINOR_POINTING 0x80 +#define BTM_COD_MINOR_COMBO 0xC0 /* Bits 2-5 OR'd with selection from bits 6-7 */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ -#define BTM_COD_MINOR_JOYSTICK 0x04 -#define BTM_COD_MINOR_GAMEPAD 0x08 -#define BTM_COD_MINOR_REMOTE_CONTROL 0x0C -#define BTM_COD_MINOR_SENSING_DEVICE 0x10 -#define BTM_COD_MINOR_DIGITIZING_TABLET 0x14 -#define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */ -#define BTM_COD_MINOR_DIGITAL_PAN 0x1C -#define BTM_COD_MINOR_HAND_SCANNER 0x20 -#define BTM_COD_MINOR_HAND_GESTURAL_INPUT 0x24 +#define BTM_COD_MINOR_JOYSTICK 0x04 +#define BTM_COD_MINOR_GAMEPAD 0x08 +#define BTM_COD_MINOR_REMOTE_CONTROL 0x0C +#define BTM_COD_MINOR_SENSING_DEVICE 0x10 +#define BTM_COD_MINOR_DIGITIZING_TABLET 0x14 +#define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */ +#define BTM_COD_MINOR_DIGITAL_PAN 0x1C +#define BTM_COD_MINOR_HAND_SCANNER 0x20 +#define BTM_COD_MINOR_HAND_GESTURAL_INPUT 0x24 /* minor device class field for Imaging Major Class */ /* Bits 5-7 independently specify display, camera, scanner, or printer */ -#define BTM_COD_MINOR_DISPLAY 0x10 -#define BTM_COD_MINOR_CAMERA 0x20 -#define BTM_COD_MINOR_SCANNER 0x40 -#define BTM_COD_MINOR_PRINTER 0x80 +#define BTM_COD_MINOR_DISPLAY 0x10 +#define BTM_COD_MINOR_CAMERA 0x20 +#define BTM_COD_MINOR_SCANNER 0x40 +#define BTM_COD_MINOR_PRINTER 0x80 /* Bits 2-3 Reserved */ /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ /* minor device class field for Wearable Major Class */ /* Bits 2-7 meaningful */ -#define BTM_COD_MINOR_WRIST_WATCH 0x04 -#define BTM_COD_MINOR_PAGER 0x08 -#define BTM_COD_MINOR_JACKET 0x0C -#define BTM_COD_MINOR_HELMET 0x10 -#define BTM_COD_MINOR_GLASSES 0x14 +#define BTM_COD_MINOR_WRIST_WATCH 0x04 +#define BTM_COD_MINOR_PAGER 0x08 +#define BTM_COD_MINOR_JACKET 0x0C +#define BTM_COD_MINOR_HELMET 0x10 +#define BTM_COD_MINOR_GLASSES 0x14 /* minor device class field for Toy Major Class */ /* Bits 2-7 meaningful */ -#define BTM_COD_MINOR_ROBOT 0x04 -#define BTM_COD_MINOR_VEHICLE 0x08 -#define BTM_COD_MINOR_DOLL_ACTION_FIGURE 0x0C -#define BTM_COD_MINOR_CONTROLLER 0x10 -#define BTM_COD_MINOR_GAME 0x14 +#define BTM_COD_MINOR_ROBOT 0x04 +#define BTM_COD_MINOR_VEHICLE 0x08 +#define BTM_COD_MINOR_DOLL_ACTION_FIGURE 0x0C +#define BTM_COD_MINOR_CONTROLLER 0x10 +#define BTM_COD_MINOR_GAME 0x14 /* minor device class field for Health Major Class */ /* Bits 2-7 meaningful */ -#define BTM_COD_MINOR_BLOOD_MONITOR 0x04 -#define BTM_COD_MINOR_THERMOMETER 0x08 -#define BTM_COD_MINOR_WEIGHING_SCALE 0x0C -#define BTM_COD_MINOR_GLUCOSE_METER 0x10 -#define BTM_COD_MINOR_PULSE_OXIMETER 0x14 -#define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18 -#define BTM_COD_MINOR_HEALTH_DATA_DISPLAY 0x1C -#define BTM_COD_MINOR_STEP_COUNTER 0x20 -#define BTM_COD_MINOR_BODY_COM_ANALYZER 0x24 -#define BTM_COD_MINOR_PEAK_FLOW_MONITOR 0x28 -#define BTM_COD_MINOR_MEDICATION_MONITOR 0x2C -#define BTM_COD_MINOR_KNEE_PROSTHESIS 0x30 -#define BTM_COD_MINOR_ANKLE_PROSTHESIS 0x34 - +#define BTM_COD_MINOR_BLOOD_MONITOR 0x04 +#define BTM_COD_MINOR_THERMOMETER 0x08 +#define BTM_COD_MINOR_WEIGHING_SCALE 0x0C +#define BTM_COD_MINOR_GLUCOSE_METER 0x10 +#define BTM_COD_MINOR_PULSE_OXIMETER 0x14 +#define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18 +#define BTM_COD_MINOR_HEALTH_DATA_DISPLAY 0x1C +#define BTM_COD_MINOR_STEP_COUNTER 0x20 +#define BTM_COD_MINOR_BODY_COM_ANALYZER 0x24 +#define BTM_COD_MINOR_PEAK_FLOW_MONITOR 0x28 +#define BTM_COD_MINOR_MEDICATION_MONITOR 0x2C +#define BTM_COD_MINOR_KNEE_PROSTHESIS 0x30 +#define BTM_COD_MINOR_ANKLE_PROSTHESIS 0x34 /*************************** * major device class field ***************************/ -#define BTM_COD_MAJOR_MISCELLANEOUS 0x00 -#define BTM_COD_MAJOR_COMPUTER 0x01 -#define BTM_COD_MAJOR_PHONE 0x02 -#define BTM_COD_MAJOR_LAN_ACCESS_PT 0x03 -#define BTM_COD_MAJOR_AUDIO 0x04 -#define BTM_COD_MAJOR_PERIPHERAL 0x05 -#define BTM_COD_MAJOR_IMAGING 0x06 -#define BTM_COD_MAJOR_WEARABLE 0x07 -#define BTM_COD_MAJOR_TOY 0x08 -#define BTM_COD_MAJOR_HEALTH 0x09 -#define BTM_COD_MAJOR_UNCLASSIFIED 0x1F +#define BTM_COD_MAJOR_MISCELLANEOUS 0x00 +#define BTM_COD_MAJOR_COMPUTER 0x01 +#define BTM_COD_MAJOR_PHONE 0x02 +#define BTM_COD_MAJOR_LAN_ACCESS_PT 0x03 +#define BTM_COD_MAJOR_AUDIO 0x04 +#define BTM_COD_MAJOR_PERIPHERAL 0x05 +#define BTM_COD_MAJOR_IMAGING 0x06 +#define BTM_COD_MAJOR_WEARABLE 0x07 +#define BTM_COD_MAJOR_TOY 0x08 +#define BTM_COD_MAJOR_HEALTH 0x09 +#define BTM_COD_MAJOR_UNCLASSIFIED 0x1F /*************************** * service class fields ***************************/ -#define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020 -#define BTM_COD_SERVICE_POSITIONING 0x0100 -#define BTM_COD_SERVICE_NETWORKING 0x0200 -#define BTM_COD_SERVICE_RENDERING 0x0400 -#define BTM_COD_SERVICE_CAPTURING 0x0800 -#define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000 -#define BTM_COD_SERVICE_AUDIO 0x2000 -#define BTM_COD_SERVICE_TELEPHONY 0x4000 -#define BTM_COD_SERVICE_INFORMATION 0x8000 +#define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020 +#define BTM_COD_SERVICE_POSITIONING 0x0100 +#define BTM_COD_SERVICE_NETWORKING 0x0200 +#define BTM_COD_SERVICE_RENDERING 0x0400 +#define BTM_COD_SERVICE_CAPTURING 0x0800 +#define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000 +#define BTM_COD_SERVICE_AUDIO 0x2000 +#define BTM_COD_SERVICE_TELEPHONY 0x4000 +#define BTM_COD_SERVICE_INFORMATION 0x8000 /* class of device field macros */ -#define BTM_COD_FORMAT_TYPE(u8, pd) {(u8) = (pd)[2]&0x03;} -#define BTM_COD_MINOR_CLASS(u8, pd) {(u8) = (pd)[2]&0xFC;} -#define BTM_COD_MAJOR_CLASS(u8, pd) {(u8) = (pd)[1]&0x1F;} -#define BTM_COD_SERVICE_CLASS(u16, pd) {(u16) = (pd)[0]; (u16)<<=8; (u16) += (pd)[1]&0xE0;} +#define BTM_COD_FORMAT_TYPE(u8, pd) \ + { (u8) = (pd)[2] & 0x03; } +#define BTM_COD_MINOR_CLASS(u8, pd) \ + { (u8) = (pd)[2] & 0xFC; } +#define BTM_COD_MAJOR_CLASS(u8, pd) \ + { (u8) = (pd)[1] & 0x1F; } +#define BTM_COD_SERVICE_CLASS(u16, pd) \ + { \ + (u16) = (pd)[0]; \ + (u16) <<= 8; \ + (u16) += (pd)[1] & 0xE0; \ + } /* to set the fields (assumes that format type is always 0) */ -#define FIELDS_TO_COD(pd, mn, mj, sv) {(pd)[2] = mn; (pd)[1] = \ - (mj)+ ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \ - (pd)[0] = (sv) >> 8;} +#define FIELDS_TO_COD(pd, mn, mj, sv) \ + { \ + (pd)[2] = mn; \ + (pd)[1] = (mj) + ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \ + (pd)[0] = (sv) >> 8; \ + } /* the COD masks */ -#define BTM_COD_FORMAT_TYPE_MASK 0x03 -#define BTM_COD_MINOR_CLASS_MASK 0xFC -#define BTM_COD_MAJOR_CLASS_MASK 0x1F -#define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 -#define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 - +#define BTM_COD_FORMAT_TYPE_MASK 0x03 +#define BTM_COD_MINOR_CLASS_MASK 0xFC +#define BTM_COD_MAJOR_CLASS_MASK 0x1F +#define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 +#define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 /* BTM service definitions * Used for storing EIR data to bit mask */ -enum -{ - BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER, -/* BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ -/* BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ - BTM_EIR_UUID_SERVCLASS_SERIAL_PORT, - BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP, - BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING, - BTM_EIR_UUID_SERVCLASS_IRMC_SYNC, - BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH, - BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER, - BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND, - BTM_EIR_UUID_SERVCLASS_HEADSET, - BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY, - BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE, - BTM_EIR_UUID_SERVCLASS_AUDIO_SINK, - BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET, -/* BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ - BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL, -/* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING, */ - BTM_EIR_UUID_SERVCLASS_INTERCOM, - BTM_EIR_UUID_SERVCLASS_FAX, - BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, -/* BTM_EIR_UUID_SERVCLASS_WAP, */ -/* BTM_EIR_UUID_SERVCLASS_WAP_CLIENT, */ - BTM_EIR_UUID_SERVCLASS_PANU, - BTM_EIR_UUID_SERVCLASS_NAP, - BTM_EIR_UUID_SERVCLASS_GN, - BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING, -/* BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING, */ - BTM_EIR_UUID_SERVCLASS_IMAGING, - BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER, - BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, - BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS, - BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE, - BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE, - BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE, -/* BTM_EIR_UUID_SERVCLASS_REFLECTED_UI, */ - BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING, - BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS, - BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE, - BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT, - BTM_EIR_UUID_SERVCLASS_HCRP_PRINT, - BTM_EIR_UUID_SERVCLASS_HCRP_SCAN, -/* BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ -/* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ -/* BTM_EIR_UUID_SERVCLASS_UDI_MT, */ -/* BTM_EIR_UUID_SERVCLASS_UDI_TA, */ -/* BTM_EIR_UUID_SERVCLASS_VCP, */ - BTM_EIR_UUID_SERVCLASS_SAP, - BTM_EIR_UUID_SERVCLASS_PBAP_PCE, - BTM_EIR_UUID_SERVCLASS_PBAP_PSE, -/* BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS, */ -/* BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS, */ - BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS, - BTM_EIR_UUID_SERVCLASS_HEADSET_HS, - BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION, -/* BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING, */ -/* BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER, */ -/* BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO, */ -/* BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY, */ -/* BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE, */ -/* BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE, */ -/* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ -/* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ -/* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ - BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE, - BTM_EIR_UUID_SERVCLASS_VIDEO_SINK, -/* BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION */ -/* BTM_EIR_UUID_SERVCLASS_HDP_PROFILE */ - BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS, - BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION, - BTM_EIR_UUID_SERVCLASS_HDP_SOURCE, - BTM_EIR_UUID_SERVCLASS_HDP_SINK, - BTM_EIR_MAX_SERVICES +enum { + BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER, + /* BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ + /* BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ + BTM_EIR_UUID_SERVCLASS_SERIAL_PORT, + BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP, + BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING, + BTM_EIR_UUID_SERVCLASS_IRMC_SYNC, + BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH, + BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER, + BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND, + BTM_EIR_UUID_SERVCLASS_HEADSET, + BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY, + BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE, + BTM_EIR_UUID_SERVCLASS_AUDIO_SINK, + BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET, + /* BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ + BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL, + /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING, */ + BTM_EIR_UUID_SERVCLASS_INTERCOM, + BTM_EIR_UUID_SERVCLASS_FAX, + BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, + /* BTM_EIR_UUID_SERVCLASS_WAP, */ + /* BTM_EIR_UUID_SERVCLASS_WAP_CLIENT, */ + BTM_EIR_UUID_SERVCLASS_PANU, + BTM_EIR_UUID_SERVCLASS_NAP, + BTM_EIR_UUID_SERVCLASS_GN, + BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING, + /* BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING, */ + BTM_EIR_UUID_SERVCLASS_IMAGING, + BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER, + BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, + BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS, + BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE, + BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE, + BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE, + /* BTM_EIR_UUID_SERVCLASS_REFLECTED_UI, */ + BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING, + BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS, + BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE, + BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT, + BTM_EIR_UUID_SERVCLASS_HCRP_PRINT, + BTM_EIR_UUID_SERVCLASS_HCRP_SCAN, + /* BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ + /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ + /* BTM_EIR_UUID_SERVCLASS_UDI_MT, */ + /* BTM_EIR_UUID_SERVCLASS_UDI_TA, */ + /* BTM_EIR_UUID_SERVCLASS_VCP, */ + BTM_EIR_UUID_SERVCLASS_SAP, + BTM_EIR_UUID_SERVCLASS_PBAP_PCE, + BTM_EIR_UUID_SERVCLASS_PBAP_PSE, + /* BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS, */ + /* BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS, */ + BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS, + BTM_EIR_UUID_SERVCLASS_HEADSET_HS, + BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION, + /* BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO, */ + /* BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY, */ + /* BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE, */ + /* BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ + /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ + BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE, + BTM_EIR_UUID_SERVCLASS_VIDEO_SINK, + /* BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION */ + /* BTM_EIR_UUID_SERVCLASS_HDP_PROFILE */ + BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS, + BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION, + BTM_EIR_UUID_SERVCLASS_HDP_SOURCE, + BTM_EIR_UUID_SERVCLASS_HDP_SINK, + BTM_EIR_MAX_SERVICES }; /* search result in EIR of inquiry database */ -#define BTM_EIR_FOUND 0 -#define BTM_EIR_NOT_FOUND 1 -#define BTM_EIR_UNKNOWN 2 +#define BTM_EIR_FOUND 0 +#define BTM_EIR_NOT_FOUND 1 +#define BTM_EIR_UNKNOWN 2 typedef uint8_t tBTM_EIR_SEARCH_RESULT; /* 0x01 */ -#define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE +#define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE /* 0x02 */ -#define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE +#define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE /* 0x03 */ -#define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE +#define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x04 */ -#define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE +#define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE /* 0x05 */ -#define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE +#define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE /* 0x06 */ -#define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE +#define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE /* 0x07 */ -#define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE +#define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE /* 0x08 */ -#define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE +#define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE /* 0x09 */ -#define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE +#define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE /* 0x0A */ -#define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE +#define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE /* 0xFF */ -#define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE HCI_EIR_MANUFACTURER_SPECIFIC_TYPE +#define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE HCI_EIR_MANUFACTURER_SPECIFIC_TYPE /* the following EIR tags are defined to OOB, not regular EIR data */ /* 6 bytes */ -#define BTM_EIR_OOB_BD_ADDR_TYPE HCI_EIR_OOB_BD_ADDR_TYPE +#define BTM_EIR_OOB_BD_ADDR_TYPE HCI_EIR_OOB_BD_ADDR_TYPE /* 3 bytes */ -#define BTM_EIR_OOB_COD_TYPE HCI_EIR_OOB_COD_TYPE +#define BTM_EIR_OOB_COD_TYPE HCI_EIR_OOB_COD_TYPE /* 16 bytes */ -#define BTM_EIR_OOB_SSP_HASH_C_TYPE HCI_EIR_OOB_SSP_HASH_C_TYPE +#define BTM_EIR_OOB_SSP_HASH_C_TYPE HCI_EIR_OOB_SSP_HASH_C_TYPE /* 16 bytes */ -#define BTM_EIR_OOB_SSP_RAND_R_TYPE HCI_EIR_OOB_SSP_RAND_R_TYPE +#define BTM_EIR_OOB_SSP_RAND_R_TYPE HCI_EIR_OOB_SSP_RAND_R_TYPE /* include 2 bytes length & 6 bytes bd_addr */ -#define BTM_OOB_MANDATORY_SIZE 8 -#define BTM_OOB_DATA_LEN_SIZE 2 -#define BTM_OOB_BD_ADDR_SIZE 6 -#define BTM_OOB_COD_SIZE BT_OOB_COD_SIZE -#define BTM_OOB_HASH_C_SIZE BT_OOB_HASH_C_SIZE -#define BTM_OOB_RAND_R_SIZE BT_OOB_RAND_R_SIZE - -#define BTM_BLE_SEC_NONE 0 +#define BTM_OOB_MANDATORY_SIZE 8 +#define BTM_OOB_DATA_LEN_SIZE 2 +#define BTM_OOB_BD_ADDR_SIZE 6 +#define BTM_OOB_COD_SIZE BT_OOB_COD_SIZE +#define BTM_OOB_HASH_C_SIZE BT_OOB_HASH_C_SIZE +#define BTM_OOB_RAND_R_SIZE BT_OOB_RAND_R_SIZE + +#define BTM_BLE_SEC_NONE 0 /* encrypt the link using current key */ -#define BTM_BLE_SEC_ENCRYPT 1 -#define BTM_BLE_SEC_ENCRYPT_NO_MITM 2 -#define BTM_BLE_SEC_ENCRYPT_MITM 3 +#define BTM_BLE_SEC_ENCRYPT 1 +#define BTM_BLE_SEC_ENCRYPT_NO_MITM 2 +#define BTM_BLE_SEC_ENCRYPT_MITM 3 typedef uint8_t tBTM_BLE_SEC_ACT; /******************************************************************************* * BTM Services MACROS handle array of uint32_t bits for more than 32 services ******************************************************************************/ /* Determine the number of uint32_t's necessary for services */ -#define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */ -#define BTM_EIR_SERVICE_ARRAY_SIZE (((uint32_t)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \ - (((uint32_t)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0)) +#define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */ +#define BTM_EIR_SERVICE_ARRAY_SIZE \ + (((uint32_t)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \ + (((uint32_t)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0)) /* MACRO to set the service bit mask in a bit stream */ -#define BTM_EIR_SET_SERVICE(p, service) (((uint32_t *)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] |= \ - ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) - +#define BTM_EIR_SET_SERVICE(p, service) \ + (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] |= \ + ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) /* MACRO to clear the service bit mask in a bit stream */ -#define BTM_EIR_CLR_SERVICE(p, service) (((uint32_t *)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &= \ - ~((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) +#define BTM_EIR_CLR_SERVICE(p, service) \ + (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &= \ + ~((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) /* MACRO to check the service bit mask in a bit stream */ -#define BTM_EIR_HAS_SERVICE(p, service) ((((uint32_t *)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] & \ - ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) >> (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)) +#define BTM_EIR_HAS_SERVICE(p, service) \ + ((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] & \ + ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) >> \ + (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)) /* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1) */ -#define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4) +#define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4) /*************************** * Device Discovery Types @@ -578,110 +585,105 @@ typedef uint8_t tBTM_BLE_SEC_ACT; /* Definitions of the parameters passed to BTM_StartInquiry and * BTM_SetPeriodicInquiryMode. */ -typedef struct /* contains the two device class condition fields */ +typedef struct /* contains the two device class condition fields */ { - DEV_CLASS dev_class; - DEV_CLASS dev_class_mask; + DEV_CLASS dev_class; + DEV_CLASS dev_class_mask; } tBTM_COD_COND; - -typedef union /* contains the inquiry filter condition */ +typedef union /* contains the inquiry filter condition */ { - BD_ADDR bdaddr_cond; - tBTM_COD_COND cod_cond; + BD_ADDR bdaddr_cond; + tBTM_COD_COND cod_cond; } tBTM_INQ_FILT_COND; - -typedef struct /* contains the parameters passed to the inquiry functions */ +typedef struct /* contains the parameters passed to the inquiry functions */ { - uint8_t mode; /* general or limited */ - uint8_t duration; /* duration of the inquiry (1.28 sec increments) */ - uint8_t max_resps; /* maximum number of responses to return */ - bool report_dup; /* report duplicated inquiry response with higher RSSI value */ - uint8_t filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */ - tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */ + uint8_t mode; /* general or limited */ + uint8_t duration; /* duration of the inquiry (1.28 sec increments) */ + uint8_t max_resps; /* maximum number of responses to return */ + bool report_dup; /* report duplicated inquiry response with higher RSSI value + */ + uint8_t filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */ + tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */ #if (BTA_HOST_INTERLEAVE_SEARCH == TRUE) - uint8_t intl_duration[4]; /*duration array storing the interleave scan's time portions*/ + uint8_t intl_duration + [4]; /*duration array storing the interleave scan's time portions*/ #endif } tBTM_INQ_PARMS; -#define BTM_INQ_RESULT_BR 0x01 -#define BTM_INQ_RESULT_BLE 0x02 +#define BTM_INQ_RESULT_BR 0x01 +#define BTM_INQ_RESULT_BLE 0x02 -#define BTM_BLE_EVT_CONN_ADV 0x00 -#define BTM_BLE_EVT_CONN_DIR_ADV 0x01 -#define BTM_BLE_EVT_DISC_ADV 0x02 -#define BTM_BLE_EVT_NON_CONN_ADV 0x03 -#define BTM_BLE_EVT_SCAN_RSP 0x04 +#define BTM_BLE_EVT_CONN_ADV 0x00 +#define BTM_BLE_EVT_CONN_DIR_ADV 0x01 +#define BTM_BLE_EVT_DISC_ADV 0x02 +#define BTM_BLE_EVT_NON_CONN_ADV 0x03 +#define BTM_BLE_EVT_SCAN_RSP 0x04 typedef uint8_t tBTM_BLE_EVT_TYPE; /* These are the fields returned in each device's response to the inquiry. It * is returned in the results callback if registered. */ -typedef struct -{ - uint16_t clock_offset; - BD_ADDR remote_bd_addr; - DEV_CLASS dev_class; - uint8_t page_scan_rep_mode; - uint8_t page_scan_per_mode; - uint8_t page_scan_mode; - int8_t rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if not valid */ - uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE]; - bool eir_complete_list; - tBT_DEVICE_TYPE device_type; - uint8_t inq_result_type; - uint8_t ble_addr_type; - tBTM_BLE_EVT_TYPE ble_evt_type; - uint8_t flag; +typedef struct { + uint16_t clock_offset; + BD_ADDR remote_bd_addr; + DEV_CLASS dev_class; + uint8_t page_scan_rep_mode; + uint8_t page_scan_per_mode; + uint8_t page_scan_mode; + int8_t rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if not valid */ + uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE]; + bool eir_complete_list; + tBT_DEVICE_TYPE device_type; + uint8_t inq_result_type; + uint8_t ble_addr_type; + tBTM_BLE_EVT_TYPE ble_evt_type; + uint8_t flag; } tBTM_INQ_RESULTS; - /* This is the inquiry response information held in its database by BTM, and * available to applications via BTM_InqDbRead, BTM_InqDbFirst, and * BTM_InqDbNext. */ -typedef struct -{ - tBTM_INQ_RESULTS results; - - bool appl_knows_rem_name; /* set by application if it knows the remote name of the peer device. - This is later used by application to determine if remote name request is - required to be done. Having the flag here avoid duplicate store of inquiry results */ - uint16_t remote_name_len; - tBTM_BD_NAME remote_name; - uint8_t remote_name_state; - uint8_t remote_name_type; +typedef struct { + tBTM_INQ_RESULTS results; + + bool appl_knows_rem_name; /* set by application if it knows the remote name of + the peer device. + This is later used by application to determine if + remote name request is + required to be done. Having the flag here avoid + duplicate store of inquiry results */ + uint16_t remote_name_len; + tBTM_BD_NAME remote_name; + uint8_t remote_name_state; + uint8_t remote_name_type; } tBTM_INQ_INFO; - /* Structure returned with inquiry complete callback */ -typedef struct -{ - tBTM_STATUS status; - uint8_t num_resp; /* Number of results from the current inquiry */ +typedef struct { + tBTM_STATUS status; + uint8_t num_resp; /* Number of results from the current inquiry */ } tBTM_INQUIRY_CMPL; - /* Structure returned with remote name request */ -typedef struct -{ - uint16_t status; - BD_ADDR bd_addr; - uint16_t length; - BD_NAME remote_bd_name; +typedef struct { + uint16_t status; + BD_ADDR bd_addr; + uint16_t length; + BD_NAME remote_bd_name; } tBTM_REMOTE_DEV_NAME; -typedef struct -{ - uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps; - 2:512 bps; 3: 1024kbps; 4: 2048kbps */ - uint8_t frame_type; /* frame type: 0: short; 1: long */ - uint8_t sync_mode; /* sync mode: 0: slave; 1: master */ - uint8_t clock_mode; /* clock mode: 0: slave; 1: master */ +typedef struct { + uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps; + 2:512 bps; 3: 1024kbps; 4: 2048kbps */ + uint8_t frame_type; /* frame type: 0: short; 1: long */ + uint8_t sync_mode; /* sync mode: 0: slave; 1: master */ + uint8_t clock_mode; /* clock mode: 0: slave; 1: master */ -}tBTM_SCO_PCM_PARAM; +} tBTM_SCO_PCM_PARAM; /**************************************** * Device Discovery Callback Functions @@ -690,12 +692,13 @@ typedef struct * changes. First param is inquiry database, second is if added to or removed * from the inquiry database. */ -typedef void (tBTM_INQ_DB_CHANGE_CB) (void *p1, bool is_new); +typedef void(tBTM_INQ_DB_CHANGE_CB)(void* p1, bool is_new); /* Callback function for notifications when the BTM gets inquiry response. * First param is inquiry results database, second is pointer of EIR. */ -typedef void (tBTM_INQ_RESULTS_CB) (tBTM_INQ_RESULTS *p_inq_results, uint8_t *p_eir); +typedef void(tBTM_INQ_RESULTS_CB)(tBTM_INQ_RESULTS* p_inq_results, + uint8_t* p_eir); /***************************************************************************** * ACL CHANNEL MANAGEMENT @@ -705,23 +708,23 @@ typedef void (tBTM_INQ_RESULTS_CB) (tBTM_INQ_RESULTS *p_inq_results, uint8_t *p_ ******************/ /* ACL modes */ -#define BTM_ACL_MODE_NORMAL HCI_MODE_ACTIVE -#define BTM_ACL_MODE_HOLD HCI_MODE_HOLD -#define BTM_ACL_MODE_SNIFF HCI_MODE_SNIFF -#define BTM_ACL_MODE_PARK HCI_MODE_PARK +#define BTM_ACL_MODE_NORMAL HCI_MODE_ACTIVE +#define BTM_ACL_MODE_HOLD HCI_MODE_HOLD +#define BTM_ACL_MODE_SNIFF HCI_MODE_SNIFF +#define BTM_ACL_MODE_PARK HCI_MODE_PARK /* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */ -#define BTM_ROLE_MASTER HCI_ROLE_MASTER -#define BTM_ROLE_SLAVE HCI_ROLE_SLAVE -#define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */ +#define BTM_ROLE_MASTER HCI_ROLE_MASTER +#define BTM_ROLE_SLAVE HCI_ROLE_SLAVE +#define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */ /* ACL Packet Types */ -#define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1 -#define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1 -#define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3 -#define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3 -#define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5 -#define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5 +#define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1 +#define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1 +#define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3 +#define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3 +#define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5 +#define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3 @@ -736,147 +739,136 @@ typedef void (tBTM_INQ_RESULTS_CB) (tBTM_INQ_RESULTS *p_inq_results, uint8_t *p_ /* Structure returned with Role Switch information (in tBTM_CMPL_CB callback * function) in response to BTM_SwitchRole call. */ -typedef struct -{ - uint8_t hci_status; /* HCI status returned with the event */ - uint8_t role; /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */ - BD_ADDR remote_bd_addr; /* Remote BD addr involved with the switch */ +typedef struct { + uint8_t hci_status; /* HCI status returned with the event */ + uint8_t role; /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */ + BD_ADDR remote_bd_addr; /* Remote BD addr involved with the switch */ } tBTM_ROLE_SWITCH_CMPL; /* Structure returned with QoS information (in tBTM_CMPL_CB callback function) * in response to BTM_SetQoS call. */ -typedef struct -{ - FLOW_SPEC flow; - uint16_t handle; - uint8_t status; +typedef struct { + FLOW_SPEC flow; + uint16_t handle; + uint8_t status; } tBTM_QOS_SETUP_CMPL; - /* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function) * in response to BTM_ReadRSSI call. */ -typedef struct -{ - tBTM_STATUS status; - uint8_t hci_status; - int8_t rssi; - BD_ADDR rem_bda; +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; + int8_t rssi; + BD_ADDR rem_bda; } tBTM_RSSI_RESULTS; /* Structure returned with read current TX power event (in tBTM_CMPL_CB callback * function) in response to BTM_ReadTxPower call. */ -typedef struct -{ - tBTM_STATUS status; - uint8_t hci_status; - int8_t tx_power; - BD_ADDR rem_bda; +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; + int8_t tx_power; + BD_ADDR rem_bda; } tBTM_TX_POWER_RESULTS; /* Structure returned with read link quality event (in tBTM_CMPL_CB callback * function) in response to BTM_ReadLinkQuality call. */ -typedef struct -{ - tBTM_STATUS status; - uint8_t hci_status; - uint8_t link_quality; - BD_ADDR rem_bda; +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; + uint8_t link_quality; + BD_ADDR rem_bda; } tBTM_LINK_QUALITY_RESULTS; /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB * callback function) in response to BTM_ReadInquiryRspTxPower call. */ -typedef struct -{ - tBTM_STATUS status; - uint8_t hci_status; - int8_t tx_power; +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; + int8_t tx_power; } tBTM_INQ_TXPWR_RESULTS; -enum -{ - BTM_BL_CONN_EVT, - BTM_BL_DISCN_EVT, - BTM_BL_UPDATE_EVT, - BTM_BL_ROLE_CHG_EVT, - BTM_BL_COLLISION_EVT +enum { + BTM_BL_CONN_EVT, + BTM_BL_DISCN_EVT, + BTM_BL_UPDATE_EVT, + BTM_BL_ROLE_CHG_EVT, + BTM_BL_COLLISION_EVT }; typedef uint8_t tBTM_BL_EVENT; typedef uint16_t tBTM_BL_EVENT_MASK; -#define BTM_BL_CONN_MASK 0x0001 -#define BTM_BL_DISCN_MASK 0x0002 -#define BTM_BL_UPDATE_MASK 0x0004 -#define BTM_BL_ROLE_CHG_MASK 0x0008 +#define BTM_BL_CONN_MASK 0x0001 +#define BTM_BL_DISCN_MASK 0x0002 +#define BTM_BL_UPDATE_MASK 0x0004 +#define BTM_BL_ROLE_CHG_MASK 0x0008 /* Device features mask definitions */ -#define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE -#define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX +#define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE +#define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX /* the data type associated with BTM_BL_CONN_EVT */ -typedef struct -{ - tBTM_BL_EVENT event; /* The event reported. */ - BD_ADDR_PTR p_bda; /* The address of the newly connected device */ - DEV_CLASS_PTR p_dc; /* The device class */ - BD_NAME_PTR p_bdn; /* The device name */ - uint8_t *p_features; /* pointer to the remote device's features page[0] (supported features page) */ - uint16_t handle; /* connection handle */ - tBT_TRANSPORT transport; /* link is LE or not */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the newly connected device */ + DEV_CLASS_PTR p_dc; /* The device class */ + BD_NAME_PTR p_bdn; /* The device name */ + uint8_t* p_features; /* pointer to the remote device's features page[0] + (supported features page) */ + uint16_t handle; /* connection handle */ + tBT_TRANSPORT transport; /* link is LE or not */ } tBTM_BL_CONN_DATA; /* the data type associated with BTM_BL_DISCN_EVT */ -typedef struct -{ - tBTM_BL_EVENT event; /* The event reported. */ - BD_ADDR_PTR p_bda; /* The address of the disconnected device */ - uint16_t handle; /* disconnected connection handle */ - tBT_TRANSPORT transport; /* link is LE link or not */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the disconnected device */ + uint16_t handle; /* disconnected connection handle */ + tBT_TRANSPORT transport; /* link is LE link or not */ } tBTM_BL_DISCN_DATA; /* Busy-Level shall have the inquiry_paging mask set when * inquiry/paging is in progress, Else the number of ACL links */ #define BTM_BL_INQUIRY_PAGING_MASK 0x10 -#define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1) +#define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1) #define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2) -#define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3) -#define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4) -#define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5) +#define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3) +#define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4) +#define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5) /* the data type associated with BTM_BL_UPDATE_EVT */ -typedef struct -{ - tBTM_BL_EVENT event; /* The event reported. */ - uint8_t busy_level;/* when paging or inquiring, level is 10. - * Otherwise, the number of ACL links. */ - uint8_t busy_level_flags; /* Notifies actual inquiry/page activities */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + uint8_t busy_level; /* when paging or inquiring, level is 10. + * Otherwise, the number of ACL links. */ + uint8_t busy_level_flags; /* Notifies actual inquiry/page activities */ } tBTM_BL_UPDATE_DATA; /* the data type associated with BTM_BL_ROLE_CHG_EVT */ -typedef struct -{ - tBTM_BL_EVENT event; /* The event reported. */ - BD_ADDR_PTR p_bda; /* The address of the peer connected device */ - uint8_t new_role; - uint8_t hci_status; /* HCI status returned with the event */ +typedef struct { + tBTM_BL_EVENT event; /* The event reported. */ + BD_ADDR_PTR p_bda; /* The address of the peer connected device */ + uint8_t new_role; + uint8_t hci_status; /* HCI status returned with the event */ } tBTM_BL_ROLE_CHG_DATA; -typedef union -{ - tBTM_BL_EVENT event; /* The event reported. */ - tBTM_BL_CONN_DATA conn; /* The data associated with BTM_BL_CONN_EVT */ - tBTM_BL_DISCN_DATA discn; /* The data associated with BTM_BL_DISCN_EVT */ - tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */ - tBTM_BL_ROLE_CHG_DATA role_chg;/*The data associated with BTM_BL_ROLE_CHG_EVT */ +typedef union { + tBTM_BL_EVENT event; /* The event reported. */ + tBTM_BL_CONN_DATA conn; /* The data associated with BTM_BL_CONN_EVT */ + tBTM_BL_DISCN_DATA discn; /* The data associated with BTM_BL_DISCN_EVT */ + tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */ + tBTM_BL_ROLE_CHG_DATA + role_chg; /*The data associated with BTM_BL_ROLE_CHG_EVT */ } tBTM_BL_EVENT_DATA; /* Callback function for notifications when the BTM busy level * changes. */ -typedef void (tBTM_BL_CHANGE_CB) (tBTM_BL_EVENT_DATA *p_data); +typedef void(tBTM_BL_CHANGE_CB)(tBTM_BL_EVENT_DATA* p_data); /*************************** * ACL Callback Functions @@ -885,10 +877,10 @@ typedef void (tBTM_BL_CHANGE_CB) (tBTM_BL_EVENT_DATA *p_data); * changes. First param is BD address, second is if added or removed. * Registered through BTM_AclRegisterForChanges call. */ -typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc, - BD_NAME p_bdn, uint8_t *features, - bool is_new, uint16_t handle, - tBT_TRANSPORT transport); +typedef void(tBTM_ACL_DB_CHANGE_CB)(BD_ADDR p_bda, DEV_CLASS p_dc, + BD_NAME p_bdn, uint8_t* features, + bool is_new, uint16_t handle, + tBT_TRANSPORT transport); /***************************************************************************** * SCO CHANNEL MANAGEMENT ****************************************************************************/ @@ -897,193 +889,180 @@ typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc, ******************/ /* Define an invalid SCO index and an invalid HCI handle */ -#define BTM_INVALID_SCO_INDEX 0xFFFF -#define BTM_INVALID_HCI_HANDLE 0xFFFF +#define BTM_INVALID_SCO_INDEX 0xFFFF +#define BTM_INVALID_HCI_HANDLE 0xFFFF /* Define an invalid SCO disconnect reason */ #define BTM_INVALID_SCO_DISC_REASON 0xFFFF /* Define first active SCO index */ -#define BTM_FIRST_ACTIVE_SCO_INDEX BTM_MAX_SCO_LINKS +#define BTM_FIRST_ACTIVE_SCO_INDEX BTM_MAX_SCO_LINKS /* Define SCO packet types used in APIs */ -#define BTM_SCO_PKT_TYPES_MASK_HV1 HCI_ESCO_PKT_TYPES_MASK_HV1 -#define BTM_SCO_PKT_TYPES_MASK_HV2 HCI_ESCO_PKT_TYPES_MASK_HV2 -#define BTM_SCO_PKT_TYPES_MASK_HV3 HCI_ESCO_PKT_TYPES_MASK_HV3 -#define BTM_SCO_PKT_TYPES_MASK_EV3 HCI_ESCO_PKT_TYPES_MASK_EV3 -#define BTM_SCO_PKT_TYPES_MASK_EV4 HCI_ESCO_PKT_TYPES_MASK_EV4 -#define BTM_SCO_PKT_TYPES_MASK_EV5 HCI_ESCO_PKT_TYPES_MASK_EV5 -#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 -#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 -#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 -#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 - -#define BTM_SCO_LINK_ONLY_MASK (BTM_SCO_PKT_TYPES_MASK_HV1 | \ - BTM_SCO_PKT_TYPES_MASK_HV2 | \ - BTM_SCO_PKT_TYPES_MASK_HV3) - -#define BTM_ESCO_LINK_ONLY_MASK (BTM_SCO_PKT_TYPES_MASK_EV3 | \ - BTM_SCO_PKT_TYPES_MASK_EV4 | \ - BTM_SCO_PKT_TYPES_MASK_EV5) - -#define BTM_SCO_LINK_ALL_PKT_MASK (BTM_SCO_LINK_ONLY_MASK | \ - BTM_ESCO_LINK_ONLY_MASK) +#define BTM_SCO_PKT_TYPES_MASK_HV1 HCI_ESCO_PKT_TYPES_MASK_HV1 +#define BTM_SCO_PKT_TYPES_MASK_HV2 HCI_ESCO_PKT_TYPES_MASK_HV2 +#define BTM_SCO_PKT_TYPES_MASK_HV3 HCI_ESCO_PKT_TYPES_MASK_HV3 +#define BTM_SCO_PKT_TYPES_MASK_EV3 HCI_ESCO_PKT_TYPES_MASK_EV3 +#define BTM_SCO_PKT_TYPES_MASK_EV4 HCI_ESCO_PKT_TYPES_MASK_EV4 +#define BTM_SCO_PKT_TYPES_MASK_EV5 HCI_ESCO_PKT_TYPES_MASK_EV5 +#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 +#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 +#define BTM_SCO_PKT_TYPES_MASK_NO_2_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 +#define BTM_SCO_PKT_TYPES_MASK_NO_3_EV5 HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 + +#define BTM_SCO_LINK_ONLY_MASK \ + (BTM_SCO_PKT_TYPES_MASK_HV1 | BTM_SCO_PKT_TYPES_MASK_HV2 | \ + BTM_SCO_PKT_TYPES_MASK_HV3) + +#define BTM_ESCO_LINK_ONLY_MASK \ + (BTM_SCO_PKT_TYPES_MASK_EV3 | BTM_SCO_PKT_TYPES_MASK_EV4 | \ + BTM_SCO_PKT_TYPES_MASK_EV5) + +#define BTM_SCO_LINK_ALL_PKT_MASK \ + (BTM_SCO_LINK_ONLY_MASK | BTM_ESCO_LINK_ONLY_MASK) #define BTM_VALID_SCO_ALL_PKT_TYPE HCI_VALID_SCO_ALL_PKT_TYPE /* Passed in BTM_CreateSco if the packet type parameter should be ignored */ -#define BTM_IGNORE_SCO_PKT_TYPE 0 +#define BTM_IGNORE_SCO_PKT_TYPE 0 /*************** * SCO Types ***************/ -#define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO -#define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO +#define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO +#define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO typedef uint8_t tBTM_SCO_TYPE; - /******************* * SCO Routing Path *******************/ -#define BTM_SCO_ROUTE_PCM HCI_BRCM_SCO_ROUTE_PCM -#define BTM_SCO_ROUTE_HCI HCI_BRCM_SCO_ROUTE_HCI +#define BTM_SCO_ROUTE_PCM HCI_BRCM_SCO_ROUTE_PCM +#define BTM_SCO_ROUTE_HCI HCI_BRCM_SCO_ROUTE_HCI typedef uint8_t tBTM_SCO_ROUTE_TYPE; - /******************* * SCO Codec Types *******************/ // TODO(google) This should use common definitions // in hci/include/hci_audio.h -#define BTM_SCO_CODEC_NONE 0x0000 -#define BTM_SCO_CODEC_CVSD 0x0001 -#define BTM_SCO_CODEC_MSBC 0x0002 +#define BTM_SCO_CODEC_NONE 0x0000 +#define BTM_SCO_CODEC_CVSD 0x0001 +#define BTM_SCO_CODEC_MSBC 0x0002 typedef uint16_t tBTM_SCO_CODEC_TYPE; - - /******************* * SCO Air Mode Types *******************/ -#define BTM_SCO_AIR_MODE_U_LAW 0 -#define BTM_SCO_AIR_MODE_A_LAW 1 -#define BTM_SCO_AIR_MODE_CVSD 2 -#define BTM_SCO_AIR_MODE_TRANSPNT 3 +#define BTM_SCO_AIR_MODE_U_LAW 0 +#define BTM_SCO_AIR_MODE_A_LAW 1 +#define BTM_SCO_AIR_MODE_CVSD 2 +#define BTM_SCO_AIR_MODE_TRANSPNT 3 typedef uint8_t tBTM_SCO_AIR_MODE_TYPE; /******************* * SCO Voice Settings *******************/ -#define BTM_VOICE_SETTING_CVSD ((uint16_t) (HCI_INP_CODING_LINEAR | \ - HCI_INP_DATA_FMT_2S_COMPLEMENT | \ - HCI_INP_SAMPLE_SIZE_16BIT | \ - HCI_AIR_CODING_FORMAT_CVSD)) +#define BTM_VOICE_SETTING_CVSD \ + ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \ + HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD)) -#define BTM_VOICE_SETTING_TRANS ((uint16_t) (HCI_INP_CODING_LINEAR | \ - HCI_INP_DATA_FMT_2S_COMPLEMENT | \ - HCI_INP_SAMPLE_SIZE_16BIT | \ - HCI_AIR_CODING_FORMAT_TRANSPNT)) +#define BTM_VOICE_SETTING_TRANS \ + ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \ + HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT)) /******************* * SCO Data Status *******************/ -enum -{ - BTM_SCO_DATA_CORRECT, - BTM_SCO_DATA_PAR_ERR, - BTM_SCO_DATA_NONE, - BTM_SCO_DATA_PAR_LOST +enum { + BTM_SCO_DATA_CORRECT, + BTM_SCO_DATA_PAR_ERR, + BTM_SCO_DATA_NONE, + BTM_SCO_DATA_PAR_LOST }; typedef uint8_t tBTM_SCO_DATA_FLAG; /*************************** * SCO Callback Functions ***************************/ -typedef void (tBTM_SCO_CB) (uint16_t sco_inx); -typedef void (tBTM_SCO_DATA_CB) (uint16_t sco_inx, BT_HDR *p_data, tBTM_SCO_DATA_FLAG status); +typedef void(tBTM_SCO_CB)(uint16_t sco_inx); +typedef void(tBTM_SCO_DATA_CB)(uint16_t sco_inx, BT_HDR* p_data, + tBTM_SCO_DATA_FLAG status); /****************** * eSCO Constants ******************/ -#define BTM_64KBITS_RATE 0x00001f40 /* 64 kbits/sec data rate */ +#define BTM_64KBITS_RATE 0x00001f40 /* 64 kbits/sec data rate */ /* Retransmission effort */ -#define BTM_ESCO_RETRANS_OFF 0 -#define BTM_ESCO_RETRANS_POWER 1 -#define BTM_ESCO_RETRANS_QUALITY 2 -#define BTM_ESCO_RETRANS_DONTCARE 0xff +#define BTM_ESCO_RETRANS_OFF 0 +#define BTM_ESCO_RETRANS_POWER 1 +#define BTM_ESCO_RETRANS_QUALITY 2 +#define BTM_ESCO_RETRANS_DONTCARE 0xff /* Max Latency Don't Care */ -#define BTM_ESCO_MAX_LAT_DONTCARE 0xffff +#define BTM_ESCO_MAX_LAT_DONTCARE 0xffff /*************** * eSCO Types ***************/ /* tBTM_ESCO_CBACK event types */ -#define BTM_ESCO_CHG_EVT 1 -#define BTM_ESCO_CONN_REQ_EVT 2 +#define BTM_ESCO_CHG_EVT 1 +#define BTM_ESCO_CONN_REQ_EVT 2 typedef uint8_t tBTM_ESCO_EVT; /* Passed into BTM_SetEScoMode() */ -typedef struct -{ - uint32_t tx_bw; - uint32_t rx_bw; - uint16_t max_latency; - uint16_t voice_contfmt; /* Voice Settings or Content Format */ - uint16_t packet_types; - uint8_t retrans_effort; +typedef struct { + uint32_t tx_bw; + uint32_t rx_bw; + uint16_t max_latency; + uint16_t voice_contfmt; /* Voice Settings or Content Format */ + uint16_t packet_types; + uint8_t retrans_effort; } tBTM_ESCO_PARAMS; -typedef struct -{ - uint16_t max_latency; - uint16_t packet_types; - uint8_t retrans_effort; +typedef struct { + uint16_t max_latency; + uint16_t packet_types; + uint8_t retrans_effort; } tBTM_CHG_ESCO_PARAMS; /* Returned by BTM_ReadEScoLinkParms() */ -typedef struct -{ - uint16_t rx_pkt_len; - uint16_t tx_pkt_len; - BD_ADDR bd_addr; - uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */ - uint8_t tx_interval; - uint8_t retrans_window; - uint8_t air_mode; +typedef struct { + uint16_t rx_pkt_len; + uint16_t tx_pkt_len; + BD_ADDR bd_addr; + uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */ + uint8_t tx_interval; + uint8_t retrans_window; + uint8_t air_mode; } tBTM_ESCO_DATA; -typedef struct -{ - uint16_t sco_inx; - uint16_t rx_pkt_len; - uint16_t tx_pkt_len; - BD_ADDR bd_addr; - uint8_t hci_status; - uint8_t tx_interval; - uint8_t retrans_window; +typedef struct { + uint16_t sco_inx; + uint16_t rx_pkt_len; + uint16_t tx_pkt_len; + BD_ADDR bd_addr; + uint8_t hci_status; + uint8_t tx_interval; + uint8_t retrans_window; } tBTM_CHG_ESCO_EVT_DATA; -typedef struct -{ - uint16_t sco_inx; - BD_ADDR bd_addr; - DEV_CLASS dev_class; - tBTM_SCO_TYPE link_type; +typedef struct { + uint16_t sco_inx; + BD_ADDR bd_addr; + DEV_CLASS dev_class; + tBTM_SCO_TYPE link_type; } tBTM_ESCO_CONN_REQ_EVT_DATA; -typedef union -{ - tBTM_CHG_ESCO_EVT_DATA chg_evt; - tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt; +typedef union { + tBTM_CHG_ESCO_EVT_DATA chg_evt; + tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt; } tBTM_ESCO_EVT_DATA; /*************************** * eSCO Callback Functions ***************************/ -typedef void (tBTM_ESCO_CBACK) (tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *p_data); - +typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data); /***************************************************************************** * SECURITY MANAGEMENT @@ -1093,161 +1072,163 @@ typedef void (tBTM_ESCO_CBACK) (tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *p_data) *******************************/ /* Security Mode (BTM_SetSecurityMode) */ -#define BTM_SEC_MODE_UNDEFINED 0 -#define BTM_SEC_MODE_NONE 1 -#define BTM_SEC_MODE_SERVICE 2 -#define BTM_SEC_MODE_LINK 3 -#define BTM_SEC_MODE_SP 4 -#define BTM_SEC_MODE_SP_DEBUG 5 -#define BTM_SEC_MODE_SC 6 +#define BTM_SEC_MODE_UNDEFINED 0 +#define BTM_SEC_MODE_NONE 1 +#define BTM_SEC_MODE_SERVICE 2 +#define BTM_SEC_MODE_LINK 3 +#define BTM_SEC_MODE_SP 4 +#define BTM_SEC_MODE_SP_DEBUG 5 +#define BTM_SEC_MODE_SC 6 /* Maximum Number of BTM Security Modes */ -#define BTM_SEC_MODES_MAX 7 +#define BTM_SEC_MODES_MAX 7 /* Security Service Levels [bit mask] (BTM_SetSecurityLevel) * Encryption should not be used without authentication */ /* Nothing required */ -#define BTM_SEC_NONE 0x0000 +#define BTM_SEC_NONE 0x0000 /* Inbound call requires authorization */ -#define BTM_SEC_IN_AUTHORIZE 0x0001 +#define BTM_SEC_IN_AUTHORIZE 0x0001 /* Inbound call requires authentication */ -#define BTM_SEC_IN_AUTHENTICATE 0x0002 +#define BTM_SEC_IN_AUTHENTICATE 0x0002 /* Inbound call requires encryption */ -#define BTM_SEC_IN_ENCRYPT 0x0004 +#define BTM_SEC_IN_ENCRYPT 0x0004 /* Outbound call requires authorization */ -#define BTM_SEC_OUT_AUTHORIZE 0x0008 +#define BTM_SEC_OUT_AUTHORIZE 0x0008 /* Outbound call requires authentication */ -#define BTM_SEC_OUT_AUTHENTICATE 0x0010 +#define BTM_SEC_OUT_AUTHENTICATE 0x0010 /* Outbound call requires encryption */ -#define BTM_SEC_OUT_ENCRYPT 0x0020 +#define BTM_SEC_OUT_ENCRYPT 0x0020 /* Secure Connections Only Mode */ -#define BTM_SEC_MODE4_LEVEL4 0x0040 +#define BTM_SEC_MODE4_LEVEL4 0x0040 /* Need to switch connection to be master */ -#define BTM_SEC_FORCE_MASTER 0x0100 +#define BTM_SEC_FORCE_MASTER 0x0100 /* Try to switch connection to be master */ -#define BTM_SEC_ATTEMPT_MASTER 0x0200 +#define BTM_SEC_ATTEMPT_MASTER 0x0200 /* Need to switch connection to be master */ -#define BTM_SEC_FORCE_SLAVE 0x0400 +#define BTM_SEC_FORCE_SLAVE 0x0400 /* Try to switch connection to be slave */ -#define BTM_SEC_ATTEMPT_SLAVE 0x0800 +#define BTM_SEC_ATTEMPT_SLAVE 0x0800 /* inbound Do man in the middle protection */ -#define BTM_SEC_IN_MITM 0x1000 +#define BTM_SEC_IN_MITM 0x1000 /* outbound Do man in the middle protection */ -#define BTM_SEC_OUT_MITM 0x2000 +#define BTM_SEC_OUT_MITM 0x2000 /* enforce a minimum of 16 digit for sec mode 2 */ #define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000 /* Security Flags [bit mask] (BTM_GetSecurityFlags) */ -#define BTM_SEC_FLAG_AUTHORIZED 0x01 -#define BTM_SEC_FLAG_AUTHENTICATED 0x02 -#define BTM_SEC_FLAG_ENCRYPTED 0x04 -#define BTM_SEC_FLAG_LKEY_KNOWN 0x10 -#define BTM_SEC_FLAG_LKEY_AUTHED 0x20 +#define BTM_SEC_FLAG_AUTHORIZED 0x01 +#define BTM_SEC_FLAG_AUTHENTICATED 0x02 +#define BTM_SEC_FLAG_ENCRYPTED 0x04 +#define BTM_SEC_FLAG_LKEY_KNOWN 0x10 +#define BTM_SEC_FLAG_LKEY_AUTHED 0x20 /* PIN types */ -#define BTM_PIN_TYPE_VARIABLE HCI_PIN_TYPE_VARIABLE -#define BTM_PIN_TYPE_FIXED HCI_PIN_TYPE_FIXED +#define BTM_PIN_TYPE_VARIABLE HCI_PIN_TYPE_VARIABLE +#define BTM_PIN_TYPE_FIXED HCI_PIN_TYPE_FIXED /* Link Key types used to generate the new link key. * returned in link key notification callback function */ -#define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION -#define BTM_LKEY_TYPE_LOCAL_UNIT HCI_LKEY_TYPE_LOCAL_UNIT -#define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT -#define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB -#define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB -#define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB -#define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB +#define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION +#define BTM_LKEY_TYPE_LOCAL_UNIT HCI_LKEY_TYPE_LOCAL_UNIT +#define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT +#define BTM_LKEY_TYPE_DEBUG_COMB HCI_LKEY_TYPE_DEBUG_COMB +#define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB +#define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB +#define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256 -#define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256 +#define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256 /* "easy" requirements for LK derived from LTK */ #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20 -#define BTM_LKEY_TYPE_IGNORE 0xff /* used when event is response from - hci return link keys request */ +#define BTM_LKEY_TYPE_IGNORE \ + 0xff /* used when event is response from \ + hci return link keys request */ typedef uint8_t tBTM_LINK_KEY_TYPE; /* Protocol level security (BTM_SetSecurityLevel) */ -#define BTM_SEC_PROTO_L2CAP 0 -#define BTM_SEC_PROTO_SDP 1 -#define BTM_SEC_PROTO_TCS 2 -#define BTM_SEC_PROTO_RFCOMM 3 -#define BTM_SEC_PROTO_OBEX 4 -#define BTM_SEC_PROTO_BNEP 5 -#define BTM_SEC_PROTO_HID 6 /* HID */ -#define BTM_SEC_PROTO_AVDT 7 -#define BTM_SEC_PROTO_MCA 8 +#define BTM_SEC_PROTO_L2CAP 0 +#define BTM_SEC_PROTO_SDP 1 +#define BTM_SEC_PROTO_TCS 2 +#define BTM_SEC_PROTO_RFCOMM 3 +#define BTM_SEC_PROTO_OBEX 4 +#define BTM_SEC_PROTO_BNEP 5 +#define BTM_SEC_PROTO_HID 6 /* HID */ +#define BTM_SEC_PROTO_AVDT 7 +#define BTM_SEC_PROTO_MCA 8 /* Determine the number of uint32_t's necessary for security services */ -#define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */ -#define BTM_SEC_SERVICE_ARRAY_SIZE (((uint32_t)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \ - (((uint32_t)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0)) +#define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */ +#define BTM_SEC_SERVICE_ARRAY_SIZE \ + (((uint32_t)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \ + (((uint32_t)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0)) /* Security service definitions (BTM_SetSecurityLevel) * Used for Authorization APIs */ -#define BTM_SEC_SERVICE_SDP_SERVER 0 -#define BTM_SEC_SERVICE_SERIAL_PORT 1 -#define BTM_SEC_SERVICE_LAN_ACCESS 2 -#define BTM_SEC_SERVICE_DUN 3 -#define BTM_SEC_SERVICE_IRMC_SYNC 4 -#define BTM_SEC_SERVICE_IRMC_SYNC_CMD 5 -#define BTM_SEC_SERVICE_OBEX 6 -#define BTM_SEC_SERVICE_OBEX_FTP 7 -#define BTM_SEC_SERVICE_HEADSET 8 -#define BTM_SEC_SERVICE_CORDLESS 9 -#define BTM_SEC_SERVICE_INTERCOM 10 -#define BTM_SEC_SERVICE_FAX 11 -#define BTM_SEC_SERVICE_HEADSET_AG 12 -#define BTM_SEC_SERVICE_PNP_INFO 13 -#define BTM_SEC_SERVICE_GEN_NET 14 -#define BTM_SEC_SERVICE_GEN_FILE 15 -#define BTM_SEC_SERVICE_GEN_AUDIO 16 -#define BTM_SEC_SERVICE_GEN_TEL 17 -#define BTM_SEC_SERVICE_CTP_DATA 18 -#define BTM_SEC_SERVICE_HCRP_CTRL 19 -#define BTM_SEC_SERVICE_HCRP_DATA 20 -#define BTM_SEC_SERVICE_HCRP_NOTIF 21 -#define BTM_SEC_SERVICE_BPP_JOB 22 -#define BTM_SEC_SERVICE_BPP_STATUS 23 -#define BTM_SEC_SERVICE_BPP_REF 24 -#define BTM_SEC_SERVICE_BNEP_PANU 25 -#define BTM_SEC_SERVICE_BNEP_GN 26 -#define BTM_SEC_SERVICE_BNEP_NAP 27 -#define BTM_SEC_SERVICE_HF_HANDSFREE 28 -#define BTM_SEC_SERVICE_AG_HANDSFREE 29 +#define BTM_SEC_SERVICE_SDP_SERVER 0 +#define BTM_SEC_SERVICE_SERIAL_PORT 1 +#define BTM_SEC_SERVICE_LAN_ACCESS 2 +#define BTM_SEC_SERVICE_DUN 3 +#define BTM_SEC_SERVICE_IRMC_SYNC 4 +#define BTM_SEC_SERVICE_IRMC_SYNC_CMD 5 +#define BTM_SEC_SERVICE_OBEX 6 +#define BTM_SEC_SERVICE_OBEX_FTP 7 +#define BTM_SEC_SERVICE_HEADSET 8 +#define BTM_SEC_SERVICE_CORDLESS 9 +#define BTM_SEC_SERVICE_INTERCOM 10 +#define BTM_SEC_SERVICE_FAX 11 +#define BTM_SEC_SERVICE_HEADSET_AG 12 +#define BTM_SEC_SERVICE_PNP_INFO 13 +#define BTM_SEC_SERVICE_GEN_NET 14 +#define BTM_SEC_SERVICE_GEN_FILE 15 +#define BTM_SEC_SERVICE_GEN_AUDIO 16 +#define BTM_SEC_SERVICE_GEN_TEL 17 +#define BTM_SEC_SERVICE_CTP_DATA 18 +#define BTM_SEC_SERVICE_HCRP_CTRL 19 +#define BTM_SEC_SERVICE_HCRP_DATA 20 +#define BTM_SEC_SERVICE_HCRP_NOTIF 21 +#define BTM_SEC_SERVICE_BPP_JOB 22 +#define BTM_SEC_SERVICE_BPP_STATUS 23 +#define BTM_SEC_SERVICE_BPP_REF 24 +#define BTM_SEC_SERVICE_BNEP_PANU 25 +#define BTM_SEC_SERVICE_BNEP_GN 26 +#define BTM_SEC_SERVICE_BNEP_NAP 27 +#define BTM_SEC_SERVICE_HF_HANDSFREE 28 +#define BTM_SEC_SERVICE_AG_HANDSFREE 29 #define BTM_SEC_SERVICE_TE_PHONE_ACCESS 30 #define BTM_SEC_SERVICE_ME_PHONE_ACCESS 31 -#define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32 +#define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32 #define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33 -#define BTM_SEC_SERVICE_HIDH_INTR 34 -#define BTM_SEC_SERVICE_BIP 35 -#define BTM_SEC_SERVICE_BIP_REF 36 -#define BTM_SEC_SERVICE_AVDTP 37 -#define BTM_SEC_SERVICE_AVDTP_NOSEC 38 -#define BTM_SEC_SERVICE_AVCTP 39 -#define BTM_SEC_SERVICE_SAP 40 -#define BTM_SEC_SERVICE_PBAP 41 -#define BTM_SEC_SERVICE_RFC_MUX 42 -#define BTM_SEC_SERVICE_AVCTP_BROWSE 43 -#define BTM_SEC_SERVICE_MAP 44 -#define BTM_SEC_SERVICE_MAP_NOTIF 45 -#define BTM_SEC_SERVICE_MCAP_CTRL 46 -#define BTM_SEC_SERVICE_MCAP_DATA 47 -#define BTM_SEC_SERVICE_HDP_SNK 48 -#define BTM_SEC_SERVICE_HDP_SRC 49 -#define BTM_SEC_SERVICE_ATT 50 +#define BTM_SEC_SERVICE_HIDH_INTR 34 +#define BTM_SEC_SERVICE_BIP 35 +#define BTM_SEC_SERVICE_BIP_REF 36 +#define BTM_SEC_SERVICE_AVDTP 37 +#define BTM_SEC_SERVICE_AVDTP_NOSEC 38 +#define BTM_SEC_SERVICE_AVCTP 39 +#define BTM_SEC_SERVICE_SAP 40 +#define BTM_SEC_SERVICE_PBAP 41 +#define BTM_SEC_SERVICE_RFC_MUX 42 +#define BTM_SEC_SERVICE_AVCTP_BROWSE 43 +#define BTM_SEC_SERVICE_MAP 44 +#define BTM_SEC_SERVICE_MAP_NOTIF 45 +#define BTM_SEC_SERVICE_MCAP_CTRL 46 +#define BTM_SEC_SERVICE_MCAP_DATA 47 +#define BTM_SEC_SERVICE_HDP_SNK 48 +#define BTM_SEC_SERVICE_HDP_SRC 49 +#define BTM_SEC_SERVICE_ATT 50 /* Update these as services are added */ -#define BTM_SEC_SERVICE_FIRST_EMPTY 51 +#define BTM_SEC_SERVICE_FIRST_EMPTY 51 #ifndef BTM_SEC_MAX_SERVICES -#define BTM_SEC_MAX_SERVICES 75 +#define BTM_SEC_MAX_SERVICES 75 #endif /******************************************************************************* @@ -1255,83 +1236,96 @@ typedef uint8_t tBTM_LINK_KEY_TYPE; * trusted services ******************************************************************************/ /* MACRO to set the security service bit mask in a bit stream */ -#define BTM_SEC_SET_SERVICE(p, service) (((uint32_t *)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] |= \ - ((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS))) - +#define BTM_SEC_SET_SERVICE(p, service) \ + (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] |= \ + ((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS))) /* MACRO to clear the security service bit mask in a bit stream */ -#define BTM_SEC_CLR_SERVICE(p, service) (((uint32_t *)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] &= \ - ~((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS))) +#define BTM_SEC_CLR_SERVICE(p, service) \ + (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)] &= \ + ~((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS))) /* MACRO to check the security service bit mask in a bit stream (Returns true or * false) */ -#define BTM_SEC_IS_SERVICE_TRUSTED(p, service) (((((uint32_t *)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)]) & \ - (uint32_t)(((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))) ? true : false) +#define BTM_SEC_IS_SERVICE_TRUSTED(p, service) \ + (((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)]) & \ + (uint32_t)(((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))) \ + ? true \ + : false) /* MACRO to copy two trusted device bitmask */ -#define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst) {uint32_t trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ - ((uint32_t *)(p_dst))[trst] = ((uint32_t *)(p_src))[trst];} +#define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst) \ + { \ + uint32_t trst; \ + for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ + ((uint32_t*)(p_dst))[trst] = ((uint32_t*)(p_src))[trst]; \ + } /* MACRO to clear two trusted device bitmask */ -#define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst) {uint32_t trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ - ((uint32_t *)(p_dst))[trst] = 0;} +#define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst) \ + { \ + uint32_t trst; \ + for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ + ((uint32_t*)(p_dst))[trst] = 0; \ + } /* Following bits can be provided by host in the trusted_mask array */ /* 0..31 bits of mask[0] (Least Significant Word) */ -#define BTM_SEC_TRUST_SDP_SERVER (1 << BTM_SEC_SERVICE_SDP_SERVER) -#define BTM_SEC_TRUST_SERIAL_PORT (1 << BTM_SEC_SERVICE_SERIAL_PORT) -#define BTM_SEC_TRUST_LAN_ACCESS (1 << BTM_SEC_SERVICE_LAN_ACCESS) -#define BTM_SEC_TRUST_DUN (1 << BTM_SEC_SERVICE_DUN) -#define BTM_SEC_TRUST_IRMC_SYNC (1 << BTM_SEC_SERVICE_IRMC_SYNC) -#define BTM_SEC_TRUST_IRMC_SYNC_CMD (1 << BTM_SEC_SERVICE_IRMC_SYNC_CMD) -#define BTM_SEC_TRUST_OBEX (1 << BTM_SEC_SERVICE_OBEX) -#define BTM_SEC_TRUST_OBEX_FTP (1 << BTM_SEC_SERVICE_OBEX_FTP) -#define BTM_SEC_TRUST_HEADSET (1 << BTM_SEC_SERVICE_HEADSET) -#define BTM_SEC_TRUST_CORDLESS (1 << BTM_SEC_SERVICE_CORDLESS) -#define BTM_SEC_TRUST_INTERCOM (1 << BTM_SEC_SERVICE_INTERCOM) -#define BTM_SEC_TRUST_FAX (1 << BTM_SEC_SERVICE_FAX) -#define BTM_SEC_TRUST_HEADSET_AG (1 << BTM_SEC_SERVICE_HEADSET_AG) -#define BTM_SEC_TRUST_PNP_INFO (1 << BTM_SEC_SERVICE_PNP_INFO) -#define BTM_SEC_TRUST_GEN_NET (1 << BTM_SEC_SERVICE_GEN_NET) -#define BTM_SEC_TRUST_GEN_FILE (1 << BTM_SEC_SERVICE_GEN_FILE) -#define BTM_SEC_TRUST_GEN_AUDIO (1 << BTM_SEC_SERVICE_GEN_AUDIO) -#define BTM_SEC_TRUST_GEN_TEL (1 << BTM_SEC_SERVICE_GEN_TEL) -#define BTM_SEC_TRUST_CTP_DATA (1 << BTM_SEC_SERVICE_CTP_DATA) -#define BTM_SEC_TRUST_HCRP_CTRL (1 << BTM_SEC_SERVICE_HCRP_CTRL) -#define BTM_SEC_TRUST_HCRP_DATA (1 << BTM_SEC_SERVICE_HCRP_DATA) -#define BTM_SEC_TRUST_HCRP_NOTIF (1 << BTM_SEC_SERVICE_HCRP_NOTIF) -#define BTM_SEC_TRUST_BPP_JOB (1 << BTM_SEC_SERVICE_JOB) -#define BTM_SEC_TRUST_BPP_STATUS (1 << BTM_SEC_SERVICE_STATUS) -#define BTM_SEC_TRUST_BPP_REF (1 << BTM_SEC_SERVICE_REF) -#define BTM_SEC_TRUST_BNEP_PANU (1 << BTM_SEC_SERVICE_BNEP_PANU) -#define BTM_SEC_TRUST_BNEP_GN (1 << BTM_SEC_SERVICE_BNEP_GN) -#define BTM_SEC_TRUST_BNEP_NAP (1 << BTM_SEC_SERVICE_BNEP_NAP) -#define BTM_SEC_TRUST_HFP_HF (1 << BTM_SEC_SERVICE_HF_HANDSFREE) -#define BTM_SEC_TRUST_HFP_AG (1 << BTM_SEC_SERVICE_AG_HANDSFREE) -#define BTM_SEC_TRUST_TE_PHONE_ACCESS (1 << BTM_SEC_SERVICE_TE_PHONE_ACCESS) -#define BTM_SEC_TRUST_ME_PHONE_ACCESS (1 << BTM_SEC_SERVICE_ME_PHONE_ACCESS) +#define BTM_SEC_TRUST_SDP_SERVER (1 << BTM_SEC_SERVICE_SDP_SERVER) +#define BTM_SEC_TRUST_SERIAL_PORT (1 << BTM_SEC_SERVICE_SERIAL_PORT) +#define BTM_SEC_TRUST_LAN_ACCESS (1 << BTM_SEC_SERVICE_LAN_ACCESS) +#define BTM_SEC_TRUST_DUN (1 << BTM_SEC_SERVICE_DUN) +#define BTM_SEC_TRUST_IRMC_SYNC (1 << BTM_SEC_SERVICE_IRMC_SYNC) +#define BTM_SEC_TRUST_IRMC_SYNC_CMD (1 << BTM_SEC_SERVICE_IRMC_SYNC_CMD) +#define BTM_SEC_TRUST_OBEX (1 << BTM_SEC_SERVICE_OBEX) +#define BTM_SEC_TRUST_OBEX_FTP (1 << BTM_SEC_SERVICE_OBEX_FTP) +#define BTM_SEC_TRUST_HEADSET (1 << BTM_SEC_SERVICE_HEADSET) +#define BTM_SEC_TRUST_CORDLESS (1 << BTM_SEC_SERVICE_CORDLESS) +#define BTM_SEC_TRUST_INTERCOM (1 << BTM_SEC_SERVICE_INTERCOM) +#define BTM_SEC_TRUST_FAX (1 << BTM_SEC_SERVICE_FAX) +#define BTM_SEC_TRUST_HEADSET_AG (1 << BTM_SEC_SERVICE_HEADSET_AG) +#define BTM_SEC_TRUST_PNP_INFO (1 << BTM_SEC_SERVICE_PNP_INFO) +#define BTM_SEC_TRUST_GEN_NET (1 << BTM_SEC_SERVICE_GEN_NET) +#define BTM_SEC_TRUST_GEN_FILE (1 << BTM_SEC_SERVICE_GEN_FILE) +#define BTM_SEC_TRUST_GEN_AUDIO (1 << BTM_SEC_SERVICE_GEN_AUDIO) +#define BTM_SEC_TRUST_GEN_TEL (1 << BTM_SEC_SERVICE_GEN_TEL) +#define BTM_SEC_TRUST_CTP_DATA (1 << BTM_SEC_SERVICE_CTP_DATA) +#define BTM_SEC_TRUST_HCRP_CTRL (1 << BTM_SEC_SERVICE_HCRP_CTRL) +#define BTM_SEC_TRUST_HCRP_DATA (1 << BTM_SEC_SERVICE_HCRP_DATA) +#define BTM_SEC_TRUST_HCRP_NOTIF (1 << BTM_SEC_SERVICE_HCRP_NOTIF) +#define BTM_SEC_TRUST_BPP_JOB (1 << BTM_SEC_SERVICE_JOB) +#define BTM_SEC_TRUST_BPP_STATUS (1 << BTM_SEC_SERVICE_STATUS) +#define BTM_SEC_TRUST_BPP_REF (1 << BTM_SEC_SERVICE_REF) +#define BTM_SEC_TRUST_BNEP_PANU (1 << BTM_SEC_SERVICE_BNEP_PANU) +#define BTM_SEC_TRUST_BNEP_GN (1 << BTM_SEC_SERVICE_BNEP_GN) +#define BTM_SEC_TRUST_BNEP_NAP (1 << BTM_SEC_SERVICE_BNEP_NAP) +#define BTM_SEC_TRUST_HFP_HF (1 << BTM_SEC_SERVICE_HF_HANDSFREE) +#define BTM_SEC_TRUST_HFP_AG (1 << BTM_SEC_SERVICE_AG_HANDSFREE) +#define BTM_SEC_TRUST_TE_PHONE_ACCESS (1 << BTM_SEC_SERVICE_TE_PHONE_ACCESS) +#define BTM_SEC_TRUST_ME_PHONE_ACCESS (1 << BTM_SEC_SERVICE_ME_PHONE_ACCESS) /* 0..31 bits of mask[1] (Most Significant Word) */ -#define BTM_SEC_TRUST_HIDH_CTRL (1 << (BTM_SEC_SERVICE_HIDH_SEC_CTRL - 32)) -#define BTM_SEC_TRUST_HIDH_NOSEC_CTRL (1 << (BTM_SEC_SERVICE_HIDH_NOSEC_CTRL - 32)) -#define BTM_SEC_TRUST_HIDH_INTR (1 << (BTM_SEC_SERVICE_HIDH_INTR - 32)) -#define BTM_SEC_TRUST_BIP (1 << (BTM_SEC_SERVICE_BIP - 32)) -#define BTM_SEC_TRUST_BIP_REF (1 << (BTM_SEC_SERVICE_BIP_REF - 32)) -#define BTM_SEC_TRUST_AVDTP (1 << (BTM_SEC_SERVICE_AVDTP - 32)) -#define BTM_SEC_TRUST_AVDTP_NOSEC (1 << (BTM_SEC_SERVICE_AVDTP_NOSEC - 32)) -#define BTM_SEC_TRUST_AVCTP (1 << (BTM_SEC_SERVICE_AVCTP - 32)) -#define BTM_SEC_TRUST_SAP (1 << (BTM_SEC_SERVICE_SAP - 32)) -#define BTM_SEC_TRUST_PBAP (1 << (BTM_SEC_SERVICE_PBAP - 32)) -#define BTM_SEC_TRUST_RFC_MUX (1 << (BTM_SEC_SERVICE_RFC_MUX - 32)) -#define BTM_SEC_TRUST_AVCTP_BROWSE (1 << (BTM_SEC_SERVICE_AVCTP_BROWSE - 32)) -#define BTM_SEC_TRUST_MAP (1 << (BTM_SEC_SERVICE_MAP - 32)) -#define BTM_SEC_TRUST_MAP_NOTIF (1 << (BTM_SEC_SERVICE_MAP_NOTIF - 32)) -#define BTM_SEC_TRUST_MCAP_CTRL (1 << (BTM_SEC_SERVICE_MCAP_CTRL - 32)) -#define BTM_SEC_TRUST_MCAP_DATA (1 << (BTM_SEC_SERVICE_MCAP_DATA - 32)) -#define BTM_SEC_TRUST_HDP_SNK (1 << (BTM_SEC_SERVICE_HDP_SNK - 32)) -#define BTM_SEC_TRUST_HDP_SRC (1 << (BTM_SEC_SERVICE_HDP_SRC - 32)) - -#define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */ +#define BTM_SEC_TRUST_HIDH_CTRL (1 << (BTM_SEC_SERVICE_HIDH_SEC_CTRL - 32)) +#define BTM_SEC_TRUST_HIDH_NOSEC_CTRL \ + (1 << (BTM_SEC_SERVICE_HIDH_NOSEC_CTRL - 32)) +#define BTM_SEC_TRUST_HIDH_INTR (1 << (BTM_SEC_SERVICE_HIDH_INTR - 32)) +#define BTM_SEC_TRUST_BIP (1 << (BTM_SEC_SERVICE_BIP - 32)) +#define BTM_SEC_TRUST_BIP_REF (1 << (BTM_SEC_SERVICE_BIP_REF - 32)) +#define BTM_SEC_TRUST_AVDTP (1 << (BTM_SEC_SERVICE_AVDTP - 32)) +#define BTM_SEC_TRUST_AVDTP_NOSEC (1 << (BTM_SEC_SERVICE_AVDTP_NOSEC - 32)) +#define BTM_SEC_TRUST_AVCTP (1 << (BTM_SEC_SERVICE_AVCTP - 32)) +#define BTM_SEC_TRUST_SAP (1 << (BTM_SEC_SERVICE_SAP - 32)) +#define BTM_SEC_TRUST_PBAP (1 << (BTM_SEC_SERVICE_PBAP - 32)) +#define BTM_SEC_TRUST_RFC_MUX (1 << (BTM_SEC_SERVICE_RFC_MUX - 32)) +#define BTM_SEC_TRUST_AVCTP_BROWSE (1 << (BTM_SEC_SERVICE_AVCTP_BROWSE - 32)) +#define BTM_SEC_TRUST_MAP (1 << (BTM_SEC_SERVICE_MAP - 32)) +#define BTM_SEC_TRUST_MAP_NOTIF (1 << (BTM_SEC_SERVICE_MAP_NOTIF - 32)) +#define BTM_SEC_TRUST_MCAP_CTRL (1 << (BTM_SEC_SERVICE_MCAP_CTRL - 32)) +#define BTM_SEC_TRUST_MCAP_DATA (1 << (BTM_SEC_SERVICE_MCAP_DATA - 32)) +#define BTM_SEC_TRUST_HDP_SNK (1 << (BTM_SEC_SERVICE_HDP_SNK - 32)) +#define BTM_SEC_TRUST_HDP_SRC (1 << (BTM_SEC_SERVICE_HDP_SRC - 32)) + +#define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */ /**************************************** * Security Manager Callback Functions @@ -1346,9 +1340,11 @@ typedef uint8_t tBTM_LINK_KEY_TYPE; * Is originator of the connection * Result of the operation */ -typedef uint8_t (tBTM_AUTHORIZE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, - tBTM_BD_NAME bd_name, uint8_t *service_name, - uint8_t service_id, bool is_originator); +typedef uint8_t(tBTM_AUTHORIZE_CALLBACK)(BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, + uint8_t* service_name, + uint8_t service_id, + bool is_originator); /* Get PIN for the connection. Parameters are * BD Address of remote @@ -1356,26 +1352,24 @@ typedef uint8_t (tBTM_AUTHORIZE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, * BD Name of remote * Flag indicating the minimum pin code length to be 16 digits */ -typedef uint8_t (tBTM_PIN_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, - tBTM_BD_NAME bd_name, bool min_16_digit); +typedef uint8_t(tBTM_PIN_CALLBACK)(BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, bool min_16_digit); /* New Link Key for the connection. Parameters are * BD Address of remote * Link Key * Key Type: Combination, Local Unit, or Remote Unit */ -typedef uint8_t (tBTM_LINK_KEY_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, - tBTM_BD_NAME bd_name, uint8_t *key, +typedef uint8_t(tBTM_LINK_KEY_CALLBACK)(BD_ADDR bd_addr, DEV_CLASS dev_class, + tBTM_BD_NAME bd_name, uint8_t* key, uint8_t key_type); - /* Remote Name Resolved. Parameters are * BD Address of remote * BD Name of remote */ -typedef void (tBTM_RMT_NAME_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dc, - tBTM_BD_NAME bd_name); - +typedef void(tBTM_RMT_NAME_CALLBACK)(BD_ADDR bd_addr, DEV_CLASS dc, + tBTM_BD_NAME bd_name); /* Authentication complete for the connection. Parameters are * BD Address of remote @@ -1383,30 +1377,31 @@ typedef void (tBTM_RMT_NAME_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dc, * BD Name of remote * */ -typedef uint8_t (tBTM_AUTH_COMPLETE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class, +typedef uint8_t(tBTM_AUTH_COMPLETE_CALLBACK)(BD_ADDR bd_addr, + DEV_CLASS dev_class, tBTM_BD_NAME bd_name, int result); -enum -{ - BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */ - BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */ - BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */ - BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */ - BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */ - BTM_SP_KEYPRESS_EVT, /* received KEYPRESS_NOTIFY event */ - BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */ - BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */ - BTM_SP_COMPLT_EVT, /* received SIMPLE_PAIRING_COMPLETE event */ - BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key */ +enum { + BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */ + BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */ + BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */ + BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */ + BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */ + BTM_SP_KEYPRESS_EVT, /* received KEYPRESS_NOTIFY event */ + BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */ + BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */ + BTM_SP_COMPLT_EVT, /* received SIMPLE_PAIRING_COMPLETE event */ + BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key + */ }; typedef uint8_t tBTM_SP_EVT; -#define BTM_IO_CAP_OUT 0 /* DisplayOnly */ -#define BTM_IO_CAP_IO 1 /* DisplayYesNo */ -#define BTM_IO_CAP_IN 2 /* KeyboardOnly */ -#define BTM_IO_CAP_NONE 3 /* NoInputNoOutput */ -#define BTM_IO_CAP_KBDISP 4 /* Keyboard display */ -#define BTM_IO_CAP_MAX 5 +#define BTM_IO_CAP_OUT 0 /* DisplayOnly */ +#define BTM_IO_CAP_IO 1 /* DisplayYesNo */ +#define BTM_IO_CAP_IN 2 /* KeyboardOnly */ +#define BTM_IO_CAP_NONE 3 /* NoInputNoOutput */ +#define BTM_IO_CAP_KBDISP 4 /* Keyboard display */ +#define BTM_IO_CAP_MAX 5 typedef uint8_t tBTM_IO_CAP; @@ -1415,165 +1410,149 @@ typedef uint8_t tBTM_IO_CAP; /* MITM Protection Not Required - Single Profile/non-bonding Numeric comparison * with automatic accept allowed */ -#define BTM_AUTH_SP_NO 0 +#define BTM_AUTH_SP_NO 0 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities to * determine authentication procedure */ -#define BTM_AUTH_SP_YES 1 +#define BTM_AUTH_SP_YES 1 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric * comparison with automatic accept allowed */ -#define BTM_AUTH_AP_NO 2 +#define BTM_AUTH_AP_NO 2 /* MITM Protection Required - All Profiles/dedicated bonding Use IO Capabilities * to determine authentication procedure */ -#define BTM_AUTH_AP_YES 3 +#define BTM_AUTH_AP_YES 3 /* MITM Protection Not Required - Single Profiles/general bonding Numeric * comparison with automatic accept allowed */ -#define BTM_AUTH_SPGB_NO 4 +#define BTM_AUTH_SPGB_NO 4 /* MITM Protection Required - Single Profiles/general bonding Use IO * Capabilities to determine authentication procedure */ -#define BTM_AUTH_SPGB_YES 5 +#define BTM_AUTH_SPGB_YES 5 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */ -#define BTM_AUTH_DD_BOND 2 -#define BTM_AUTH_GB_BIT 4 /* the genernal bonding bit */ -#define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */ -#define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */ +#define BTM_AUTH_DD_BOND 2 +#define BTM_AUTH_GB_BIT 4 /* the genernal bonding bit */ +#define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */ +#define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */ #define BTM_BLE_INITIATOR_KEY_SIZE 15 #define BTM_BLE_RESPONDER_KEY_SIZE 15 -#define BTM_BLE_MAX_KEY_SIZE 16 +#define BTM_BLE_MAX_KEY_SIZE 16 typedef uint8_t tBTM_AUTH_REQ; -enum -{ - BTM_OOB_NONE, - BTM_OOB_PRESENT, - BTM_OOB_UNKNOWN -}; +enum { BTM_OOB_NONE, BTM_OOB_PRESENT, BTM_OOB_UNKNOWN }; typedef uint8_t tBTM_OOB_DATA; /* data type for BTM_SP_IO_REQ_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - tBTM_IO_CAP io_cap; /* local IO capabilities */ - tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */ - tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */ - bool is_orig; /* true, if local device initiated the SP process */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_IO_CAP io_cap; /* local IO capabilities */ + tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */ + tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */ + bool is_orig; /* true, if local device initiated the SP process */ } tBTM_SP_IO_REQ; /* data type for BTM_SP_IO_RSP_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - tBTM_IO_CAP io_cap; /* peer IO capabilities */ - tBTM_OOB_DATA oob_data; /* OOB data present at peer device for the local device */ - tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_IO_CAP io_cap; /* peer IO capabilities */ + tBTM_OOB_DATA + oob_data; /* OOB data present at peer device for the local device */ + tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */ } tBTM_SP_IO_RSP; /* data type for BTM_SP_CFM_REQ_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - DEV_CLASS dev_class; /* peer CoD */ - tBTM_BD_NAME bd_name; /* peer device name */ - uint32_t num_val; /* the numeric value for comparison. If just_works, do not show this number to UI */ - bool just_works; /* true, if "Just Works" association model */ - tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */ - tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */ - tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */ - tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + uint32_t num_val; /* the numeric value for comparison. If just_works, do not + show this number to UI */ + bool just_works; /* true, if "Just Works" association model */ + tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */ + tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */ + tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */ + tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */ } tBTM_SP_CFM_REQ; /* data type for BTM_SP_KEY_REQ_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - DEV_CLASS dev_class; /* peer CoD */ - tBTM_BD_NAME bd_name; /* peer device name */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ } tBTM_SP_KEY_REQ; /* data type for BTM_SP_KEY_NOTIF_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - DEV_CLASS dev_class; /* peer CoD */ - tBTM_BD_NAME bd_name; /* peer device name */ - uint32_t passkey; /* passkey */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + uint32_t passkey; /* passkey */ } tBTM_SP_KEY_NOTIF; -enum -{ - BTM_SP_KEY_STARTED, /* 0 - passkey entry started */ - BTM_SP_KEY_ENTERED, /* 1 - passkey digit entered */ - BTM_SP_KEY_ERASED, /* 2 - passkey digit erased */ - BTM_SP_KEY_CLEARED, /* 3 - passkey cleared */ - BTM_SP_KEY_COMPLT, /* 4 - passkey entry completed */ - BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */ +enum { + BTM_SP_KEY_STARTED, /* 0 - passkey entry started */ + BTM_SP_KEY_ENTERED, /* 1 - passkey digit entered */ + BTM_SP_KEY_ERASED, /* 2 - passkey digit erased */ + BTM_SP_KEY_CLEARED, /* 3 - passkey cleared */ + BTM_SP_KEY_COMPLT, /* 4 - passkey entry completed */ + BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */ }; typedef uint8_t tBTM_SP_KEY_TYPE; /* data type for BTM_SP_KEYPRESS_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - tBTM_SP_KEY_TYPE notif_type; +typedef struct { + BD_ADDR bd_addr; /* peer address */ + tBTM_SP_KEY_TYPE notif_type; } tBTM_SP_KEYPRESS; /* data type for BTM_SP_LOC_OOB_EVT */ -typedef struct -{ - tBTM_STATUS status; /* */ - BT_OCTET16 c; /* Simple Pairing Hash C */ - BT_OCTET16 r; /* Simple Pairing Randomnizer R */ +typedef struct { + tBTM_STATUS status; /* */ + BT_OCTET16 c; /* Simple Pairing Hash C */ + BT_OCTET16 r; /* Simple Pairing Randomnizer R */ } tBTM_SP_LOC_OOB; /* data type for BTM_SP_RMT_OOB_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - DEV_CLASS dev_class; /* peer CoD */ - tBTM_BD_NAME bd_name; /* peer device name */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ } tBTM_SP_RMT_OOB; - /* data type for BTM_SP_COMPLT_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - DEV_CLASS dev_class; /* peer CoD */ - tBTM_BD_NAME bd_name; /* peer device name */ - tBTM_STATUS status; /* status of the simple pairing process */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + DEV_CLASS dev_class; /* peer CoD */ + tBTM_BD_NAME bd_name; /* peer device name */ + tBTM_STATUS status; /* status of the simple pairing process */ } tBTM_SP_COMPLT; /* data type for BTM_SP_UPGRADE_EVT */ -typedef struct -{ - BD_ADDR bd_addr; /* peer address */ - bool upgrade; /* true, to upgrade the link key */ +typedef struct { + BD_ADDR bd_addr; /* peer address */ + bool upgrade; /* true, to upgrade the link key */ } tBTM_SP_UPGRADE; -typedef union -{ - tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */ - tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */ - tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */ - tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */ - tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */ - tBTM_SP_KEYPRESS key_press; /* BTM_SP_KEYPRESS_EVT */ - tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */ - tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */ - tBTM_SP_COMPLT complt; /* BTM_SP_COMPLT_EVT */ - tBTM_SP_UPGRADE upgrade; /* BTM_SP_UPGRADE_EVT */ +typedef union { + tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */ + tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */ + tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */ + tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */ + tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */ + tBTM_SP_KEYPRESS key_press; /* BTM_SP_KEYPRESS_EVT */ + tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */ + tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */ + tBTM_SP_COMPLT complt; /* BTM_SP_COMPLT_EVT */ + tBTM_SP_UPGRADE upgrade; /* BTM_SP_UPGRADE_EVT */ } tBTM_SP_EVT_DATA; /* Simple Pairing Events. Called by the stack when Simple Pairing related * events occur. */ -typedef uint8_t (tBTM_SP_CALLBACK) (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data); +typedef uint8_t(tBTM_SP_CALLBACK)(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); - -typedef void (tBTM_MKEY_CALLBACK) (BD_ADDR bd_addr, uint8_t status, uint8_t key_flag) ; +typedef void(tBTM_MKEY_CALLBACK)(BD_ADDR bd_addr, uint8_t status, + uint8_t key_flag); /* Encryption enabled/disabled complete: Optionally passed with * BTM_SetEncryption. @@ -1582,225 +1561,211 @@ typedef void (tBTM_MKEY_CALLBACK) (BD_ADDR bd_addr, uint8_t status, uint8_t key_ * optional data passed in by BTM_SetEncryption * tBTM_STATUS - result of the operation */ -typedef void (tBTM_SEC_CBACK) (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, - void *p_ref_data, tBTM_STATUS result); +typedef void(tBTM_SEC_CBACK)(BD_ADDR bd_addr, tBT_TRANSPORT trasnport, + void* p_ref_data, tBTM_STATUS result); /* Bond Cancel complete. Parameters are * Result of the cancel operation * */ -typedef void (tBTM_BOND_CANCEL_CMPL_CALLBACK) (tBTM_STATUS result); +typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result); /* LE related event and data structure */ /* received IO_CAPABILITY_REQUEST event */ -#define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT +#define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT /* security request event */ -#define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT +#define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT /* received USER_PASSKEY_NOTIFY event */ -#define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT +#define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT /* received USER_PASSKEY_REQUEST event */ -#define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT +#define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT /* OOB data request event */ -#define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT +#define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT /* Numeric Comparison request event */ -#define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT +#define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT /* Peer keypress notification recd event */ #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT /* SC OOB request event (both local and peer OOB data) can be expected in * response */ -#define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT +#define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */ -#define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT +#define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT /* SMP over BR keys request event */ -#define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT +#define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT /* SMP complete event */ -#define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT -#define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT +#define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT +#define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT /* KEY update event */ -#define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1) +#define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1) typedef uint8_t tBTM_LE_EVT; -#define BTM_LE_KEY_NONE 0 +#define BTM_LE_KEY_NONE 0 /* encryption information of peer device */ -#define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC +#define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC /* identity key of the peer device */ -#define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID +#define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID /* peer SRK */ -#define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK -#define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK -#define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4) +#define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK +#define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK +#define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4) /* master role security information:div */ -#define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4) +#define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4) /* master device ID key */ -#define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4) +#define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4) /* local CSRK has been deliver to peer */ -#define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4) +#define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4) typedef uint8_t tBTM_LE_KEY_TYPE; -#define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */ -#define BTM_LE_AUTH_REQ_BOND SMP_AUTH_GEN_BOND /* 1 << 0 */ -#define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */ +#define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */ +#define BTM_LE_AUTH_REQ_BOND SMP_AUTH_GEN_BOND /* 1 << 0 */ +#define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */ typedef uint8_t tBTM_LE_AUTH_REQ; -#define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */ -#define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */ +#define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */ +#define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */ -#define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 1 << 3 */ -#define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 1001 */ -#define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 1100 */ -#define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 1101 */ -#define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x1D */ +#define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 1 << 3 */ +#define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 1001 */ +#define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 1100 */ +#define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 1101 */ +#define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x1D */ /* LE security level */ -#define BTM_LE_SEC_NONE SMP_SEC_NONE -#define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */ -#define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED /* 4 */ +#define BTM_LE_SEC_NONE SMP_SEC_NONE +#define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */ +#define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED /* 4 */ typedef uint8_t tBTM_LE_SEC; - -typedef struct -{ - /* local IO capabilities */ - tBTM_IO_CAP io_cap; - /* OOB data present (locally) for the peer device */ - uint8_t oob_data; - /* Authentication request (for local device) containing bonding and MITM - * info */ - tBTM_LE_AUTH_REQ auth_req; - uint8_t max_key_size; /* max encryption key size */ - tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */ - tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */ +typedef struct { + /* local IO capabilities */ + tBTM_IO_CAP io_cap; + /* OOB data present (locally) for the peer device */ + uint8_t oob_data; + /* Authentication request (for local device) containing bonding and MITM + * info */ + tBTM_LE_AUTH_REQ auth_req; + uint8_t max_key_size; /* max encryption key size */ + tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */ + tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */ } tBTM_LE_IO_REQ; /* data type for tBTM_LE_COMPLT */ -typedef struct -{ - uint8_t reason; - uint8_t sec_level; - bool is_pair_cancel; - bool smp_over_br; -}tBTM_LE_COMPLT; +typedef struct { + uint8_t reason; + uint8_t sec_level; + bool is_pair_cancel; + bool smp_over_br; +} tBTM_LE_COMPLT; /* BLE encryption keys */ -typedef struct -{ - BT_OCTET16 ltk; - BT_OCTET8 rand; - uint16_t ediv; - uint8_t sec_level; - uint8_t key_size; -}tBTM_LE_PENC_KEYS; +typedef struct { + BT_OCTET16 ltk; + BT_OCTET8 rand; + uint16_t ediv; + uint8_t sec_level; + uint8_t key_size; +} tBTM_LE_PENC_KEYS; /* BLE CSRK keys */ -typedef struct -{ - uint32_t counter; - BT_OCTET16 csrk; - uint8_t sec_level; -}tBTM_LE_PCSRK_KEYS; +typedef struct { + uint32_t counter; + BT_OCTET16 csrk; + uint8_t sec_level; +} tBTM_LE_PCSRK_KEYS; /* BLE Encryption reproduction keys */ -typedef struct -{ - BT_OCTET16 ltk; - uint16_t div; - uint8_t key_size; - uint8_t sec_level; -}tBTM_LE_LENC_KEYS; +typedef struct { + BT_OCTET16 ltk; + uint16_t div; + uint8_t key_size; + uint8_t sec_level; +} tBTM_LE_LENC_KEYS; /* BLE SRK keys */ -typedef struct -{ - uint32_t counter; - uint16_t div; - uint8_t sec_level; - BT_OCTET16 csrk; -}tBTM_LE_LCSRK_KEYS; - -typedef struct -{ - BT_OCTET16 irk; - tBLE_ADDR_TYPE addr_type; - BD_ADDR static_addr; -}tBTM_LE_PID_KEYS; - -typedef union -{ - tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ - tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ - tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ - tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys - * LTK = = d1(ER,DIV,0) */ - tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ -}tBTM_LE_KEY_VALUE; - -typedef struct -{ - tBTM_LE_KEY_TYPE key_type; - tBTM_LE_KEY_VALUE *p_key_value; -}tBTM_LE_KEY; - -typedef union -{ - tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT */ - uint32_t key_notif; /* BTM_LE_KEY_NOTIF_EVT */ - /* BTM_LE_NC_REQ_EVT */ - /* no callback data for - * BTM_LE_KEY_REQ_EVT - * and BTM_LE_OOB_REQ_EVT */ - tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT */ - tSMP_OOB_DATA_TYPE req_oob_type; - tBTM_LE_KEY key; +typedef struct { + uint32_t counter; + uint16_t div; + uint8_t sec_level; + BT_OCTET16 csrk; +} tBTM_LE_LCSRK_KEYS; + +typedef struct { + BT_OCTET16 irk; + tBLE_ADDR_TYPE addr_type; + BD_ADDR static_addr; +} tBTM_LE_PID_KEYS; + +typedef union { + tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ + tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ + tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ + tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys + * LTK = = d1(ER,DIV,0) */ + tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ +} tBTM_LE_KEY_VALUE; + +typedef struct { + tBTM_LE_KEY_TYPE key_type; + tBTM_LE_KEY_VALUE* p_key_value; +} tBTM_LE_KEY; + +typedef union { + tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT */ + uint32_t key_notif; /* BTM_LE_KEY_NOTIF_EVT */ + /* BTM_LE_NC_REQ_EVT */ + /* no callback data for + * BTM_LE_KEY_REQ_EVT + * and BTM_LE_OOB_REQ_EVT */ + tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT */ + tSMP_OOB_DATA_TYPE req_oob_type; + tBTM_LE_KEY key; } tBTM_LE_EVT_DATA; /* Simple Pairing Events. Called by the stack when Simple Pairing related * events occur. */ -typedef uint8_t (tBTM_LE_CALLBACK) (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data); - -#define BTM_BLE_KEY_TYPE_ID 1 -#define BTM_BLE_KEY_TYPE_ER 2 -#define BTM_BLE_KEY_TYPE_COUNTER 3 //tobe obsolete +typedef uint8_t(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, BD_ADDR bda, + tBTM_LE_EVT_DATA* p_data); -typedef struct -{ - BT_OCTET16 ir; - BT_OCTET16 irk; - BT_OCTET16 dhk; +#define BTM_BLE_KEY_TYPE_ID 1 +#define BTM_BLE_KEY_TYPE_ER 2 +#define BTM_BLE_KEY_TYPE_COUNTER 3 // tobe obsolete -}tBTM_BLE_LOCAL_ID_KEYS; +typedef struct { + BT_OCTET16 ir; + BT_OCTET16 irk; + BT_OCTET16 dhk; -typedef union -{ - tBTM_BLE_LOCAL_ID_KEYS id_keys; - BT_OCTET16 er; -}tBTM_BLE_LOCAL_KEYS; +} tBTM_BLE_LOCAL_ID_KEYS; +typedef union { + tBTM_BLE_LOCAL_ID_KEYS id_keys; + BT_OCTET16 er; +} tBTM_BLE_LOCAL_KEYS; /* New LE identity key for local device. */ -typedef void (tBTM_LE_KEY_CALLBACK) (uint8_t key_type, tBTM_BLE_LOCAL_KEYS *p_key); - +typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type, + tBTM_BLE_LOCAL_KEYS* p_key); /*************************** * Security Manager Types ***************************/ /* Structure that applications use to register with BTM_SecRegister */ -typedef struct -{ - tBTM_AUTHORIZE_CALLBACK *p_authorize_callback; - tBTM_PIN_CALLBACK *p_pin_callback; - tBTM_LINK_KEY_CALLBACK *p_link_key_callback; - tBTM_AUTH_COMPLETE_CALLBACK *p_auth_complete_callback; - tBTM_BOND_CANCEL_CMPL_CALLBACK *p_bond_cancel_cmpl_callback; - tBTM_SP_CALLBACK *p_sp_callback; - tBTM_LE_CALLBACK *p_le_callback; - tBTM_LE_KEY_CALLBACK *p_le_key_callback; +typedef struct { + tBTM_AUTHORIZE_CALLBACK* p_authorize_callback; + tBTM_PIN_CALLBACK* p_pin_callback; + tBTM_LINK_KEY_CALLBACK* p_link_key_callback; + tBTM_AUTH_COMPLETE_CALLBACK* p_auth_complete_callback; + tBTM_BOND_CANCEL_CMPL_CALLBACK* p_bond_cancel_cmpl_callback; + tBTM_SP_CALLBACK* p_sp_callback; + tBTM_LE_CALLBACK* p_le_callback; + tBTM_LE_KEY_CALLBACK* p_le_key_callback; } tBTM_APPL_INFO; /* Callback function for when a link supervision timeout event occurs. * This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt(). */ -typedef void (tBTM_LSTO_CBACK) (BD_ADDR remote_bda, uint16_t timeout); +typedef void(tBTM_LSTO_CBACK)(BD_ADDR remote_bda, uint16_t timeout); /***************************************************************************** * POWER MANAGEMENT @@ -1809,141 +1774,130 @@ typedef void (tBTM_LSTO_CBACK) (BD_ADDR remote_bda, uint16_t timeout); * Power Manager Constants ****************************/ /* BTM Power manager status codes */ -enum -{ - BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE, - BTM_PM_STS_HOLD = HCI_MODE_HOLD, - BTM_PM_STS_SNIFF = HCI_MODE_SNIFF, - BTM_PM_STS_PARK = HCI_MODE_PARK, - BTM_PM_STS_SSR, /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */ - BTM_PM_STS_PENDING, /* when waiting for status from controller */ - BTM_PM_STS_ERROR /* when HCI command status returns error */ +enum { + BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE, + BTM_PM_STS_HOLD = HCI_MODE_HOLD, + BTM_PM_STS_SNIFF = HCI_MODE_SNIFF, + BTM_PM_STS_PARK = HCI_MODE_PARK, + BTM_PM_STS_SSR, /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */ + BTM_PM_STS_PENDING, /* when waiting for status from controller */ + BTM_PM_STS_ERROR /* when HCI command status returns error */ }; typedef uint8_t tBTM_PM_STATUS; /* BTM Power manager modes */ -enum -{ - BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE, - BTM_PM_MD_HOLD = BTM_PM_STS_HOLD, - BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF, - BTM_PM_MD_PARK = BTM_PM_STS_PARK, - BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */ +enum { + BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE, + BTM_PM_MD_HOLD = BTM_PM_STS_HOLD, + BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF, + BTM_PM_MD_PARK = BTM_PM_STS_PARK, + BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */ }; typedef uint8_t tBTM_PM_MODE; -#define BTM_PM_SET_ONLY_ID 0x80 +#define BTM_PM_SET_ONLY_ID 0x80 /* Operation codes */ /* The module wants to set the desired power mode */ -#define BTM_PM_REG_SET 1 +#define BTM_PM_REG_SET 1 /* The module wants to receive mode change event */ -#define BTM_PM_REG_NOTIF 2 +#define BTM_PM_REG_NOTIF 2 /* The module does not want to involve with PM anymore */ -#define BTM_PM_DEREG 4 +#define BTM_PM_DEREG 4 /************************ * Power Manager Types ************************/ -typedef struct -{ - uint16_t max; - uint16_t min; - uint16_t attempt; - uint16_t timeout; - tBTM_PM_MODE mode; +typedef struct { + uint16_t max; + uint16_t min; + uint16_t attempt; + uint16_t timeout; + tBTM_PM_MODE mode; } tBTM_PM_PWR_MD; /************************************* * Power Manager Callback Functions *************************************/ -typedef void (tBTM_PM_STATUS_CBACK) (BD_ADDR p_bda, tBTM_PM_STATUS status, - uint16_t value, uint8_t hci_status); - +typedef void(tBTM_PM_STATUS_CBACK)(BD_ADDR p_bda, tBTM_PM_STATUS status, + uint16_t value, uint8_t hci_status); /************************ * Stored Linkkey Types ************************/ -#define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4 +#define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4 -typedef struct -{ - uint8_t event; - uint8_t status; - uint16_t num_keys; +typedef struct { + uint8_t event; + uint8_t status; + uint16_t num_keys; } tBTM_DELETE_STORED_LINK_KEY_COMPLETE; /* MIP evnets, callbacks */ -enum -{ - BTM_MIP_MODE_CHG_EVT, - BTM_MIP_DISCONNECT_EVT, - BTM_MIP_PKTS_COMPL_EVT, - BTM_MIP_RXDATA_EVT +enum { + BTM_MIP_MODE_CHG_EVT, + BTM_MIP_DISCONNECT_EVT, + BTM_MIP_PKTS_COMPL_EVT, + BTM_MIP_RXDATA_EVT }; typedef uint8_t tBTM_MIP_EVT; -typedef struct -{ - tBTM_MIP_EVT event; - BD_ADDR bd_addr; - uint16_t mip_id; +typedef struct { + tBTM_MIP_EVT event; + BD_ADDR bd_addr; + uint16_t mip_id; } tBTM_MIP_MODE_CHANGE; -typedef struct -{ - tBTM_MIP_EVT event; - uint16_t mip_id; - uint8_t disc_reason; +typedef struct { + tBTM_MIP_EVT event; + uint16_t mip_id; + uint8_t disc_reason; } tBTM_MIP_CONN_TIMEOUT; -#define BTM_MIP_MAX_RX_LEN 17 +#define BTM_MIP_MAX_RX_LEN 17 -typedef struct -{ - tBTM_MIP_EVT event; - uint16_t mip_id; - uint8_t rx_len; - uint8_t rx_data[BTM_MIP_MAX_RX_LEN]; +typedef struct { + tBTM_MIP_EVT event; + uint16_t mip_id; + uint8_t rx_len; + uint8_t rx_data[BTM_MIP_MAX_RX_LEN]; } tBTM_MIP_RXDATA; -typedef struct -{ - tBTM_MIP_EVT event; - BD_ADDR bd_addr; - uint8_t data[11]; /* data[0] shows Vender-specific device type */ +typedef struct { + tBTM_MIP_EVT event; + BD_ADDR bd_addr; + uint8_t data[11]; /* data[0] shows Vender-specific device type */ } tBTM_MIP_EIR_HANDSHAKE; -typedef struct -{ - tBTM_MIP_EVT event; - uint16_t num_sent; /* Completed packet count at the controller */ +typedef struct { + tBTM_MIP_EVT event; + uint16_t num_sent; /* Completed packet count at the controller */ } tBTM_MIP_PKTS_COMPL; -typedef union -{ - tBTM_MIP_EVT event; - tBTM_MIP_MODE_CHANGE mod_chg; - tBTM_MIP_CONN_TIMEOUT conn_tmo; - tBTM_MIP_EIR_HANDSHAKE eir; - tBTM_MIP_PKTS_COMPL completed; - tBTM_MIP_RXDATA rxdata; +typedef union { + tBTM_MIP_EVT event; + tBTM_MIP_MODE_CHANGE mod_chg; + tBTM_MIP_CONN_TIMEOUT conn_tmo; + tBTM_MIP_EIR_HANDSHAKE eir; + tBTM_MIP_PKTS_COMPL completed; + tBTM_MIP_RXDATA rxdata; } tBTM_MIP_EVENT_DATA; /* MIP event callback function */ -typedef void (tBTM_MIP_EVENTS_CB) (tBTM_MIP_EVT event, tBTM_MIP_EVENT_DATA data); +typedef void(tBTM_MIP_EVENTS_CB)(tBTM_MIP_EVT event, tBTM_MIP_EVENT_DATA data); /* MIP Device query callback function */ -typedef bool (tBTM_MIP_QUERY_CB) (BD_ADDR dev_addr, uint8_t *p_mode, LINK_KEY link_key); +typedef bool(tBTM_MIP_QUERY_CB)(BD_ADDR dev_addr, uint8_t* p_mode, + LINK_KEY link_key); /* ACL link on, SCO link ongoing, sniff mode */ -#define BTM_CONTRL_ACTIVE 1 +#define BTM_CONTRL_ACTIVE 1 /* Scan state - paging/inquiry/trying to connect*/ -#define BTM_CONTRL_SCAN 2 +#define BTM_CONTRL_SCAN 2 /* Idle state - page scan, LE advt, inquiry scan */ -#define BTM_CONTRL_IDLE 3 +#define BTM_CONTRL_IDLE 3 typedef uint8_t tBTM_CONTRL_STATE; -#endif // BTM_API_TYPES_H +#endif // BTM_API_TYPES_H diff --git a/stack/include/btm_ble_api.h b/stack/include/btm_ble_api.h index bbe1ec24d..8ce50af50 100644 --- a/stack/include/btm_ble_api.h +++ b/stack/include/btm_ble_api.h @@ -25,11 +25,11 @@ #ifndef BTM_BLE_API_H #define BTM_BLE_API_H -#include "btm_api.h" -#include "bt_common.h" -#include "osi/include/alarm.h" #include +#include "bt_common.h" +#include "btm_api.h" #include "btm_ble_api_types.h" +#include "osi/include/alarm.h" #ifdef __cplusplus extern "C" { @@ -56,8 +56,9 @@ tBTM_BLE_SCAN_SETUP_CBACK bta_ble_scan_setup_cb; * Returns true if added OK, else false * ******************************************************************************/ -extern bool BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name, - tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type); +extern bool BTM_SecAddBleDevice(const BD_ADDR bd_addr, BD_NAME bd_name, + tBT_DEVICE_TYPE dev_type, + tBLE_ADDR_TYPE addr_type); /******************************************************************************* * @@ -74,8 +75,8 @@ extern bool BTM_SecAddBleDevice (const BD_ADDR bd_addr, BD_NAME bd_name, * Returns true if added OK, else false * ******************************************************************************/ -extern bool BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, - tBTM_LE_KEY_TYPE key_type); +extern bool BTM_SecAddBleKey(BD_ADDR bd_addr, tBTM_LE_KEY_VALUE* p_le_key, + tBTM_LE_KEY_TYPE key_type); /******************************************************************************* * @@ -88,8 +89,10 @@ extern bool BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, * Returns void * ******************************************************************************/ -extern tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, uint16_t adv_int_max, - tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP chnl_map); +extern tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, + uint16_t adv_int_max, + tBLE_BD_ADDR* p_dir_bda, + tBTM_BLE_ADV_CHNL_MAP chnl_map); /******************************************************************************* * @@ -102,7 +105,7 @@ extern tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, uint16_t adv_int_ma * Returns void * ******************************************************************************/ -extern void BTM_BleObtainVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); +extern void BTM_BleObtainVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb); /******************************************************************************* * @@ -119,9 +122,10 @@ extern void BTM_BleObtainVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); * Returns void * ******************************************************************************/ -extern void BTM_BleSetScanParams(tGATT_IF client_if, uint32_t scan_interval, - uint32_t scan_window, tBLE_SCAN_MODE scan_type, - tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); +extern void BTM_BleSetScanParams( + tGATT_IF client_if, uint32_t scan_interval, uint32_t scan_window, + tBLE_SCAN_MODE scan_type, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); /******************************************************************************* * @@ -134,7 +138,7 @@ extern void BTM_BleSetScanParams(tGATT_IF client_if, uint32_t scan_interval, * Returns void * ******************************************************************************/ -extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); +extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb); /******************************************************************************* * * Function BTM_BleSetStorageConfig @@ -143,22 +147,23 @@ extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb); * setup callbacks. * * Parameters uint8_t batch_scan_full_max -Batch scan full maximum - uint8_t batch_scan_trunc_max - Batch scan truncated value maximum + uint8_t batch_scan_trunc_max - Batch scan truncated value + maximum uint8_t batch_scan_notify_threshold - Threshold value tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback - Setup callback - tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold callback + tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold + callback void *p_ref - Reference value * * Returns tBTM_STATUS * ******************************************************************************/ -extern tBTM_STATUS BTM_BleSetStorageConfig(uint8_t batch_scan_full_max, - uint8_t batch_scan_trunc_max, - uint8_t batch_scan_notify_threshold, - tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback, - tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback, - tBTM_BLE_SCAN_REP_CBACK* p_cback, - tBTM_BLE_REF_VALUE ref_value); +extern tBTM_STATUS BTM_BleSetStorageConfig( + uint8_t batch_scan_full_max, uint8_t batch_scan_trunc_max, + uint8_t batch_scan_notify_threshold, + tBTM_BLE_SCAN_SETUP_CBACK* p_setup_cback, + tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback, + tBTM_BLE_SCAN_REP_CBACK* p_cback, tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -176,10 +181,11 @@ extern tBTM_STATUS BTM_BleSetStorageConfig(uint8_t batch_scan_full_max, * ******************************************************************************/ extern tBTM_STATUS BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode, - uint32_t scan_interval, uint32_t scan_window, - tBTM_BLE_DISCARD_RULE discard_rule, - tBLE_ADDR_TYPE addr_type, - tBTM_BLE_REF_VALUE ref_value); + uint32_t scan_interval, + uint32_t scan_window, + tBTM_BLE_DISCARD_RULE discard_rule, + tBLE_ADDR_TYPE addr_type, + tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -205,7 +211,7 @@ extern tBTM_STATUS BTM_BleDisableBatchScan(tBTM_BLE_REF_VALUE ref_value); * ******************************************************************************/ extern tBTM_STATUS BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode, - tBTM_BLE_REF_VALUE ref_value); + tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -219,8 +225,8 @@ extern tBTM_STATUS BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode, * Returns tBTM_STATUS * ******************************************************************************/ -extern tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cback, - tBTM_BLE_REF_VALUE ref_value); +extern tBTM_STATUS BTM_BleTrackAdvertiser( + tBTM_BLE_TRACK_ADV_CBACK* p_track_cback, tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -234,7 +240,7 @@ extern tBTM_STATUS BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK *p_track_cbac * ******************************************************************************/ extern void BTM_BleWriteScanRsp(uint8_t* data, uint8_t length, - tBTM_BLE_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + tBTM_BLE_ADV_DATA_CMPL_CBACK* p_adv_data_cback); /******************************************************************************* * @@ -248,9 +254,9 @@ extern void BTM_BleWriteScanRsp(uint8_t* data, uint8_t length, * Returns void * ******************************************************************************/ -extern tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, - tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb); - +extern tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, + tBTM_INQ_RESULTS_CB* p_results_cb, + tBTM_CMPL_CB* p_cmpl_cb); /******************************************************************************* * @@ -263,7 +269,7 @@ extern tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, * the local device ER is copied into er * ******************************************************************************/ -extern void BTM_GetDeviceIDRoot (BT_OCTET16 ir); +extern void BTM_GetDeviceIDRoot(BT_OCTET16 ir); /******************************************************************************* * @@ -276,7 +282,7 @@ extern void BTM_GetDeviceIDRoot (BT_OCTET16 ir); * the local device ER is copied into er * ******************************************************************************/ -extern void BTM_GetDeviceEncRoot (BT_OCTET16 er); +extern void BTM_GetDeviceEncRoot(BT_OCTET16 er); /******************************************************************************* * @@ -288,7 +294,7 @@ extern void BTM_GetDeviceEncRoot (BT_OCTET16 er); * the local device DHK is copied into dhk * ******************************************************************************/ -extern void BTM_GetDeviceDHK (BT_OCTET16 dhk); +extern void BTM_GetDeviceDHK(BT_OCTET16 dhk); /******************************************************************************* * @@ -321,7 +327,7 @@ extern void BTM_SecurityGrant(BD_ADDR bd_addr, uint8_t res); * BTM_MAX_PASSKEY_VAL(999999(0xF423F)). * ******************************************************************************/ -extern void BTM_BlePasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey); +extern void BTM_BlePasskeyReply(BD_ADDR bd_addr, uint8_t res, uint32_t passkey); /******************************************************************************* * @@ -335,7 +341,7 @@ extern void BTM_BlePasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey) * res - comparison result BTM_SUCCESS if success * ******************************************************************************/ -extern void BTM_BleConfirmReply (BD_ADDR bd_addr, uint8_t res); +extern void BTM_BleConfirmReply(BD_ADDR bd_addr, uint8_t res); /******************************************************************************* * @@ -349,7 +355,8 @@ extern void BTM_BleConfirmReply (BD_ADDR bd_addr, uint8_t res); * p_data - simple pairing Randomizer C. * ******************************************************************************/ -extern void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, uint8_t *p_data); +extern void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, + uint8_t* p_data); /******************************************************************************* * @@ -364,9 +371,8 @@ extern void BTM_BleOobDataReply(BD_ADDR bd_addr, uint8_t res, uint8_t len, uint8 * p_r - pointer to Randomizer. * ******************************************************************************/ -extern void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, - uint8_t *p_c, uint8_t *p_r); - +extern void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, uint8_t* p_c, + uint8_t* p_r); /******************************************************************************* * @@ -384,8 +390,8 @@ extern void BTM_BleSecureConnectionOobDataReply(BD_ADDR bd_addr, * Returns true if signing sucessul, otherwise false. * ******************************************************************************/ -extern bool BTM_BleDataSignature (BD_ADDR bd_addr, uint8_t *p_text, uint16_t len, - BLE_SIGNATURE signature); +extern bool BTM_BleDataSignature(BD_ADDR bd_addr, uint8_t* p_text, uint16_t len, + BLE_SIGNATURE signature); /******************************************************************************* * @@ -402,9 +408,9 @@ extern bool BTM_BleDataSignature (BD_ADDR bd_addr, uint8_t *p_text, uint16_t * Returns true if signature verified correctly; otherwise false. * ******************************************************************************/ -extern bool BTM_BleVerifySignature (BD_ADDR bd_addr, uint8_t *p_orig, - uint16_t len, uint32_t counter, - uint8_t *p_comp); +extern bool BTM_BleVerifySignature(BD_ADDR bd_addr, uint8_t* p_orig, + uint16_t len, uint32_t counter, + uint8_t* p_comp); /******************************************************************************* * @@ -415,10 +421,8 @@ extern bool BTM_BleVerifySignature (BD_ADDR bd_addr, uint8_t *p_orig, * Returns void * ******************************************************************************/ -extern void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, - tBLE_ADDR_TYPE *p_addr_type); - - +extern void BTM_ReadConnectionAddr(BD_ADDR remote_bda, BD_ADDR local_conn_addr, + tBLE_ADDR_TYPE* p_addr_type); /******************************************************************************* * @@ -429,9 +433,8 @@ extern void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, * Returns void * ******************************************************************************/ -extern bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, - BD_ADDR conn_addr, - tBLE_ADDR_TYPE *p_addr_type); +extern bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, + tBLE_ADDR_TYPE* p_addr_type); /******************************************************************************* * @@ -447,8 +450,7 @@ extern bool BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, * Returns non2. * ******************************************************************************/ -extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS *p_key); - +extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); /******************************************************************************* * @@ -466,8 +468,8 @@ extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS *p_key); * Returns void * ******************************************************************************/ -extern bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type, - tBTM_BLE_SEL_CBACK *p_select_cback); +extern bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type, + tBTM_BLE_SEL_CBACK* p_select_cback); /******************************************************************************* * @@ -475,7 +477,8 @@ extern bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type, * * Description This function is called to add or remove a device into/from * background connection procedure. The background connection -* procedure is decided by the background connection type, it can be +* procedure is decided by the background connection type, it +*can be * auto connection, or selective connection. * * Parameters add_remove: true to add; false to remove. @@ -484,7 +487,7 @@ extern bool BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE conn_type, * Returns void * ******************************************************************************/ -extern bool BTM_BleUpdateBgConnDev(bool add_remove, BD_ADDR remote_bda); +extern bool BTM_BleUpdateBgConnDev(bool add_remove, BD_ADDR remote_bda); /******************************************************************************* * @@ -519,9 +522,10 @@ extern void BTM_BleClearBgConnDev(void); * Returns void * ******************************************************************************/ -extern void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, - uint16_t min_conn_int, uint16_t max_conn_int, - uint16_t slave_latency, uint16_t supervision_tout); +extern void BTM_BleSetPrefConnParams(BD_ADDR bd_addr, uint16_t min_conn_int, + uint16_t max_conn_int, + uint16_t slave_latency, + uint16_t supervision_tout); /****************************************************************************** * @@ -535,7 +539,8 @@ extern void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, * Returns void * ******************************************************************************/ -extern void BTM_BleSetConnScanParams (uint32_t scan_interval, uint32_t scan_window); +extern void BTM_BleSetConnScanParams(uint32_t scan_interval, + uint32_t scan_window); /****************************************************************************** * @@ -549,7 +554,8 @@ extern void BTM_BleSetConnScanParams (uint32_t scan_interval, uint32_t scan_win * Returns void * ******************************************************************************/ -extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback); +extern void BTM_BleReadControllerFeatures( + tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback); /******************************************************************************* * @@ -564,7 +570,8 @@ extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_c * Returns pointer of ADV data * ******************************************************************************/ -extern uint8_t *BTM_CheckAdvData( uint8_t *p_adv, uint8_t type, uint8_t *p_length); +extern uint8_t* BTM_CheckAdvData(uint8_t* p_adv, uint8_t type, + uint8_t* p_length); /******************************************************************************* * @@ -589,7 +596,7 @@ uint16_t BTM_BleReadDiscoverability(); * Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE * ******************************************************************************/ -extern uint16_t BTM_BleReadConnectability (); +extern uint16_t BTM_BleReadConnectability(); /******************************************************************************* * @@ -603,9 +610,9 @@ extern uint16_t BTM_BleReadConnectability (); * p_addr_type: output parameter to read the address type. * ******************************************************************************/ -extern void BTM_ReadDevInfo (const BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, - tBLE_ADDR_TYPE *p_addr_type); - +extern void BTM_ReadDevInfo(const BD_ADDR remote_bda, + tBT_DEVICE_TYPE* p_dev_type, + tBLE_ADDR_TYPE* p_addr_type); /******************************************************************************* * @@ -621,8 +628,8 @@ extern void BTM_ReadDevInfo (const BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_ty * Return true if an active link is identified; false otherwise * ******************************************************************************/ -extern bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, - tBT_TRANSPORT transport); +extern bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -636,7 +643,7 @@ extern bool BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, * Returns bool privacy mode set success; otherwise failed. * ******************************************************************************/ -extern bool BTM_BleConfigPrivacy(bool enable); +extern bool BTM_BleConfigPrivacy(bool enable); /******************************************************************************* * @@ -647,7 +654,7 @@ extern bool BTM_BleConfigPrivacy(bool enable); * Returns Return true if local privacy is enabled else false * ******************************************************************************/ -extern bool BTM_BleLocalPrivacyEnabled(void); +extern bool BTM_BleLocalPrivacyEnabled(void); /******************************************************************************* * @@ -661,7 +668,7 @@ extern bool BTM_BleLocalPrivacyEnabled(void); * Returns void * ******************************************************************************/ -extern void BTM_BleEnableMixedPrivacyMode(bool mixed_on); +extern void BTM_BleEnableMixedPrivacyMode(bool mixed_on); /******************************************************************************* * @@ -692,7 +699,8 @@ extern uint8_t BTM_BleMaxMultiAdvInstanceCount(); * BTM_SUCCESS is status set successfully; otherwise failure. * ******************************************************************************/ -extern tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode); +extern tBTM_STATUS BTM_BleSetConnectableMode( + tBTM_BLE_CONN_MODE connectable_mode); /******************************************************************************* * @@ -707,8 +715,7 @@ extern tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode * Returns void * ******************************************************************************/ -extern void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, - bool privacy_on); +extern void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, bool privacy_on); /******************************************************************************* * @@ -732,8 +739,7 @@ extern void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy); * p_cmd_cmpl_cback - Command Complete callback * ******************************************************************************/ -void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback); - +void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB* p_cmd_cmpl_cback); /******************************************************************************* * @@ -749,7 +755,8 @@ void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback); * ******************************************************************************/ void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len, - uint8_t packet_payload, tBTM_CMPL_CB *p_cmd_cmpl_cback); + uint8_t packet_payload, + tBTM_CMPL_CB* p_cmd_cmpl_cback); /******************************************************************************* * @@ -760,7 +767,7 @@ void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len, * Parameter p_cmd_cmpl_cback - Command complete callback * ******************************************************************************/ -void BTM_BleTestEnd(tBTM_CMPL_CB *p_cmd_cmpl_cback); +void BTM_BleTestEnd(tBTM_CMPL_CB* p_cmd_cmpl_cback); /******************************************************************************* * @@ -771,7 +778,7 @@ void BTM_BleTestEnd(tBTM_CMPL_CB *p_cmd_cmpl_cback); * Returns true to use LE, false use BR/EDR. * ******************************************************************************/ -extern bool BTM_UseLeLink (BD_ADDR bd_addr); +extern bool BTM_UseLeLink(BD_ADDR bd_addr); /******************************************************************************* * @@ -785,7 +792,7 @@ extern bool BTM_UseLeLink (BD_ADDR bd_addr); * Returns true if added OK, else false * ******************************************************************************/ -extern tBTM_STATUS BTM_BleStackEnable (bool enable); +extern tBTM_STATUS BTM_BleStackEnable(bool enable); /******************************************************************************* * @@ -797,9 +804,8 @@ extern tBTM_STATUS BTM_BleStackEnable (bool enable); * Returns bool true if LE device is found, false otherwise. * ******************************************************************************/ -extern bool BTM_GetLeSecurityState (BD_ADDR bd_addr, - uint8_t *p_le_dev_sec_flags, - uint8_t *p_le_key_size); +extern bool BTM_GetLeSecurityState(BD_ADDR bd_addr, uint8_t* p_le_dev_sec_flags, + uint8_t* p_le_key_size); /******************************************************************************* * @@ -811,7 +817,7 @@ extern bool BTM_GetLeSecurityState (BD_ADDR bd_addr, * Returns bool true if security procedure is running, false otherwise. * ******************************************************************************/ -extern bool BTM_BleSecurityProcedureIsRunning (BD_ADDR bd_addr); +extern bool BTM_BleSecurityProcedureIsRunning(BD_ADDR bd_addr); /******************************************************************************* * @@ -824,7 +830,7 @@ extern bool BTM_BleSecurityProcedureIsRunning (BD_ADDR bd_addr); * Returns the key size or 0 if the size can't be retrieved. * ******************************************************************************/ -extern uint8_t BTM_BleGetSupportedKeySize (BD_ADDR bd_addr); +extern uint8_t BTM_BleGetSupportedKeySize(BD_ADDR bd_addr); /******************************************************************************* * @@ -840,11 +846,10 @@ extern uint8_t BTM_BleGetSupportedKeySize (BD_ADDR bd_addr); * Returns void * ******************************************************************************/ -extern tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_FILT_PARAMS *p_filt_params, - tBLE_BD_ADDR *p_target, tBTM_BLE_PF_PARAM_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value); +extern tBTM_STATUS BTM_BleAdvFilterParamSetup( + int action, tBTM_BLE_PF_FILT_INDEX filt_index, + tBTM_BLE_PF_FILT_PARAMS* p_filt_params, tBLE_BD_ADDR* p_target, + tBTM_BLE_PF_PARAM_CBACK* p_cmpl_cback, tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -860,12 +865,10 @@ extern tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, * Returns tBTM_STATUS * ******************************************************************************/ -extern tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_COND_TYPE cond_type, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value); +extern tBTM_STATUS BTM_BleCfgFilterCondition( + tBTM_BLE_SCAN_COND_OP action, tBTM_BLE_PF_COND_TYPE cond_type, + tBTM_BLE_PF_FILT_INDEX filt_index, tBTM_BLE_PF_COND_PARAM* p_cond, + tBTM_BLE_PF_CFG_CBACK* p_cmpl_cback, tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -879,9 +882,9 @@ extern tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, * Returns tBTM_STATUS * ******************************************************************************/ -extern tBTM_STATUS BTM_BleEnableDisableFilterFeature(uint8_t enable, - tBTM_BLE_PF_STATUS_CBACK *p_stat_cback, - tBTM_BLE_REF_VALUE ref_value); +extern tBTM_STATUS BTM_BleEnableDisableFilterFeature( + uint8_t enable, tBTM_BLE_PF_STATUS_CBACK* p_stat_cback, + tBTM_BLE_REF_VALUE ref_value); /******************************************************************************* * @@ -894,7 +897,8 @@ extern tBTM_STATUS BTM_BleEnableDisableFilterFeature(uint8_t enable, * Returns status * ******************************************************************************/ -extern tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback); +extern tBTM_STATUS BTM_BleGetEnergyInfo( + tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback); /******************************************************************************* * @@ -905,7 +909,8 @@ extern tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback * Returns BTM_SUCCESS if success; otherwise failed. * ******************************************************************************/ -extern tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, uint16_t tx_pdu_length); +extern tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, + uint16_t tx_pdu_length); extern void btm_ble_multi_adv_cleanup(void); diff --git a/stack/include/btm_ble_api_types.h b/stack/include/btm_ble_api_types.h index a23a564ef..87aab69cb 100644 --- a/stack/include/btm_ble_api_types.h +++ b/stack/include/btm_ble_api_types.h @@ -25,464 +25,464 @@ extern "C" { #endif -#define CHNL_MAP_LEN 5 +#define CHNL_MAP_LEN 5 typedef uint8_t tBTM_BLE_CHNL_MAP[CHNL_MAP_LEN]; /* 0x00-0x04 only used for set advertising parameter command */ -#define BTM_BLE_CONNECT_EVT 0x00 +#define BTM_BLE_CONNECT_EVT 0x00 /* Connectable directed advertising */ #define BTM_BLE_CONNECT_DIR_EVT 0x01 /* Scannable undirected advertising */ -#define BTM_BLE_DISCOVER_EVT 0x02 +#define BTM_BLE_DISCOVER_EVT 0x02 /* Non connectable undirected advertising */ #define BTM_BLE_NON_CONNECT_EVT 0x03 /* Connectable low duty cycle directed advertising */ #define BTM_BLE_CONNECT_LO_DUTY_DIR_EVT 0x04 /* 0x00 - 0x05 can be received on adv event type */ -#define BTM_BLE_SCAN_RSP_EVT 0x04 -#define BTM_BLE_SCAN_REQ_EVT 0x05 -#define BTM_BLE_UNKNOWN_EVT 0xff +#define BTM_BLE_SCAN_RSP_EVT 0x04 +#define BTM_BLE_SCAN_REQ_EVT 0x05 +#define BTM_BLE_UNKNOWN_EVT 0xff -#define BTM_BLE_UNKNOWN_EVT 0xff +#define BTM_BLE_UNKNOWN_EVT 0xff typedef uint8_t tBTM_BLE_EVT; typedef uint8_t tBTM_BLE_CONN_MODE; typedef uint32_t tBTM_BLE_REF_VALUE; -#define BTM_BLE_SCAN_MODE_PASS 0 -#define BTM_BLE_SCAN_MODE_ACTI 1 -#define BTM_BLE_SCAN_MODE_NONE 0xff +#define BTM_BLE_SCAN_MODE_PASS 0 +#define BTM_BLE_SCAN_MODE_ACTI 1 +#define BTM_BLE_SCAN_MODE_NONE 0xff typedef uint8_t tBLE_SCAN_MODE; #define BTM_BLE_BATCH_SCAN_MODE_DISABLE 0 -#define BTM_BLE_BATCH_SCAN_MODE_PASS 1 -#define BTM_BLE_BATCH_SCAN_MODE_ACTI 2 +#define BTM_BLE_BATCH_SCAN_MODE_PASS 1 +#define BTM_BLE_BATCH_SCAN_MODE_ACTI 2 #define BTM_BLE_BATCH_SCAN_MODE_PASS_ACTI 3 typedef uint8_t tBTM_BLE_BATCH_SCAN_MODE; /* advertising channel map */ -#define BTM_BLE_ADV_CHNL_37 (0x01 << 0) -#define BTM_BLE_ADV_CHNL_38 (0x01 << 1) -#define BTM_BLE_ADV_CHNL_39 (0x01 << 2) +#define BTM_BLE_ADV_CHNL_37 (0x01 << 0) +#define BTM_BLE_ADV_CHNL_38 (0x01 << 1) +#define BTM_BLE_ADV_CHNL_39 (0x01 << 2) typedef uint8_t tBTM_BLE_ADV_CHNL_MAP; /*d efault advertising channel map */ #ifndef BTM_BLE_DEFAULT_ADV_CHNL_MAP -#define BTM_BLE_DEFAULT_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37| BTM_BLE_ADV_CHNL_38| BTM_BLE_ADV_CHNL_39) +#define BTM_BLE_DEFAULT_ADV_CHNL_MAP \ + (BTM_BLE_ADV_CHNL_37 | BTM_BLE_ADV_CHNL_38 | BTM_BLE_ADV_CHNL_39) #endif /* advertising filter policy */ -#define AP_SCAN_CONN_ALL 0x00 /* default */ -#define AP_SCAN_WL_CONN_ALL 0x01 -#define AP_SCAN_ALL_CONN_WL 0x02 -#define AP_SCAN_CONN_WL 0x03 -#define AP_SCAN_CONN_POLICY_MAX 0x04 +#define AP_SCAN_CONN_ALL 0x00 /* default */ +#define AP_SCAN_WL_CONN_ALL 0x01 +#define AP_SCAN_ALL_CONN_WL 0x02 +#define AP_SCAN_CONN_WL 0x03 +#define AP_SCAN_CONN_POLICY_MAX 0x04 typedef uint8_t tBTM_BLE_AFP; /* default advertising filter policy */ #ifndef BTM_BLE_DEFAULT_AFP -#define BTM_BLE_DEFAULT_AFP AP_SCAN_CONN_ALL +#define BTM_BLE_DEFAULT_AFP AP_SCAN_CONN_ALL #endif /* scanning filter policy */ /* 0: accept adv packet from all, directed adv pkt not directed */ /* to local device is ignored */ -#define SP_ADV_ALL 0x00 +#define SP_ADV_ALL 0x00 /* 1: accept adv packet from device in white list, directed adv */ /* packet not directed to local device is ignored */ -#define SP_ADV_WL 0x01 +#define SP_ADV_WL 0x01 /* 2: accept adv packet from all, directed adv pkt */ /* not directed to me is ignored except direct adv with RPA */ #define SP_ADV_ALL_RPA_DIR_ADV 0x02 /* 3: accept adv packet from device in white list, directed */ /* adv pkt not directed to me is ignored except direct adv with RPA */ -#define SP_ADV_WL_RPA_DIR_ADV 0x03 +#define SP_ADV_WL_RPA_DIR_ADV 0x03 typedef uint8_t tBTM_BLE_SFP; #ifndef BTM_BLE_DEFAULT_SFP -#define BTM_BLE_DEFAULT_SFP SP_ADV_ALL +#define BTM_BLE_DEFAULT_SFP SP_ADV_ALL #endif /* adv parameter boundary values */ -#define BTM_BLE_ADV_INT_MIN 0x0020 -#define BTM_BLE_ADV_INT_MAX 0x4000 +#define BTM_BLE_ADV_INT_MIN 0x0020 +#define BTM_BLE_ADV_INT_MAX 0x4000 /* Full scan boundary values */ -#define BTM_BLE_ADV_SCAN_FULL_MIN 0x00 -#define BTM_BLE_ADV_SCAN_FULL_MAX 0x64 +#define BTM_BLE_ADV_SCAN_FULL_MIN 0x00 +#define BTM_BLE_ADV_SCAN_FULL_MAX 0x64 /* Partial scan boundary values */ -#define BTM_BLE_ADV_SCAN_TRUNC_MIN BTM_BLE_ADV_SCAN_FULL_MIN -#define BTM_BLE_ADV_SCAN_TRUNC_MAX BTM_BLE_ADV_SCAN_FULL_MAX +#define BTM_BLE_ADV_SCAN_TRUNC_MIN BTM_BLE_ADV_SCAN_FULL_MIN +#define BTM_BLE_ADV_SCAN_TRUNC_MAX BTM_BLE_ADV_SCAN_FULL_MAX /* Threshold values */ -#define BTM_BLE_ADV_SCAN_THR_MIN BTM_BLE_ADV_SCAN_FULL_MIN -#define BTM_BLE_ADV_SCAN_THR_MAX BTM_BLE_ADV_SCAN_FULL_MAX +#define BTM_BLE_ADV_SCAN_THR_MIN BTM_BLE_ADV_SCAN_FULL_MIN +#define BTM_BLE_ADV_SCAN_THR_MAX BTM_BLE_ADV_SCAN_FULL_MAX /* connection parameter boundary values */ -#define BTM_BLE_SCAN_INT_MIN 0x0004 -#define BTM_BLE_SCAN_INT_MAX 0x4000 -#define BTM_BLE_SCAN_WIN_MIN 0x0004 -#define BTM_BLE_SCAN_WIN_MAX 0x4000 -#define BTM_BLE_EXT_SCAN_INT_MAX 0x00FFFFFF -#define BTM_BLE_EXT_SCAN_WIN_MAX 0xFFFF -#define BTM_BLE_CONN_INT_MIN 0x0006 -#define BTM_BLE_CONN_INT_MAX 0x0C80 -#define BTM_BLE_CONN_LATENCY_MAX 500 -#define BTM_BLE_CONN_SUP_TOUT_MIN 0x000A -#define BTM_BLE_CONN_SUP_TOUT_MAX 0x0C80 +#define BTM_BLE_SCAN_INT_MIN 0x0004 +#define BTM_BLE_SCAN_INT_MAX 0x4000 +#define BTM_BLE_SCAN_WIN_MIN 0x0004 +#define BTM_BLE_SCAN_WIN_MAX 0x4000 +#define BTM_BLE_EXT_SCAN_INT_MAX 0x00FFFFFF +#define BTM_BLE_EXT_SCAN_WIN_MAX 0xFFFF +#define BTM_BLE_CONN_INT_MIN 0x0006 +#define BTM_BLE_CONN_INT_MAX 0x0C80 +#define BTM_BLE_CONN_LATENCY_MAX 500 +#define BTM_BLE_CONN_SUP_TOUT_MIN 0x000A +#define BTM_BLE_CONN_SUP_TOUT_MAX 0x0C80 /* use this value when a specific value not to be overwritten */ -#define BTM_BLE_CONN_PARAM_UNDEF 0xffff -#define BTM_BLE_SCAN_PARAM_UNDEF 0xffffffff +#define BTM_BLE_CONN_PARAM_UNDEF 0xffff +#define BTM_BLE_SCAN_PARAM_UNDEF 0xffffffff /* default connection parameters if not configured, use GAP recommended value * for auto/selective connection */ /* default scan interval */ #ifndef BTM_BLE_SCAN_FAST_INT -#define BTM_BLE_SCAN_FAST_INT 96 /* 30 ~ 60 ms (use 60) = 96 *0.625 */ +#define BTM_BLE_SCAN_FAST_INT 96 /* 30 ~ 60 ms (use 60) = 96 *0.625 */ #endif /* default scan window for background connection, applicable for auto connection * or selective connection */ #ifndef BTM_BLE_SCAN_FAST_WIN -#define BTM_BLE_SCAN_FAST_WIN 48 /* 30 ms = 48 *0.625 */ +#define BTM_BLE_SCAN_FAST_WIN 48 /* 30 ms = 48 *0.625 */ #endif /* default scan paramter used in reduced power cycle (background scanning) */ #ifndef BTM_BLE_SCAN_SLOW_INT_1 -#define BTM_BLE_SCAN_SLOW_INT_1 2048 /* 1.28 s = 2048 *0.625 */ +#define BTM_BLE_SCAN_SLOW_INT_1 2048 /* 1.28 s = 2048 *0.625 */ #endif #ifndef BTM_BLE_SCAN_SLOW_WIN_1 -#define BTM_BLE_SCAN_SLOW_WIN_1 48 /* 30 ms = 48 *0.625 */ +#define BTM_BLE_SCAN_SLOW_WIN_1 48 /* 30 ms = 48 *0.625 */ #endif /* default scan paramter used in reduced power cycle (background scanning) */ #ifndef BTM_BLE_SCAN_SLOW_INT_2 -#define BTM_BLE_SCAN_SLOW_INT_2 4096 /* 2.56 s = 4096 *0.625 */ +#define BTM_BLE_SCAN_SLOW_INT_2 4096 /* 2.56 s = 4096 *0.625 */ #endif #ifndef BTM_BLE_SCAN_SLOW_WIN_2 -#define BTM_BLE_SCAN_SLOW_WIN_2 36 /* 22.5 ms = 36 *0.625 */ +#define BTM_BLE_SCAN_SLOW_WIN_2 36 /* 22.5 ms = 36 *0.625 */ #endif /* default connection interval min */ #ifndef BTM_BLE_CONN_INT_MIN_DEF /* recommended min: 30ms = 24 * 1.25 */ -#define BTM_BLE_CONN_INT_MIN_DEF 24 +#define BTM_BLE_CONN_INT_MIN_DEF 24 #endif /* default connectino interval max */ #ifndef BTM_BLE_CONN_INT_MAX_DEF /* recommended max: 50 ms = 56 * 1.25 */ -#define BTM_BLE_CONN_INT_MAX_DEF 40 +#define BTM_BLE_CONN_INT_MAX_DEF 40 #endif /* default slave latency */ #ifndef BTM_BLE_CONN_SLAVE_LATENCY_DEF -#define BTM_BLE_CONN_SLAVE_LATENCY_DEF 0 /* 0 */ +#define BTM_BLE_CONN_SLAVE_LATENCY_DEF 0 /* 0 */ #endif /* default supervision timeout */ #ifndef BTM_BLE_CONN_TIMEOUT_DEF -#define BTM_BLE_CONN_TIMEOUT_DEF 2000 +#define BTM_BLE_CONN_TIMEOUT_DEF 2000 #endif /* minimum supervision timeout */ #ifndef BTM_BLE_CONN_TIMEOUT_MIN_DEF -#define BTM_BLE_CONN_TIMEOUT_MIN_DEF 100 +#define BTM_BLE_CONN_TIMEOUT_MIN_DEF 100 #endif /* minimum acceptable connection interval */ #ifndef BTM_BLE_CONN_INT_MIN_LIMIT -#define BTM_BLE_CONN_INT_MIN_LIMIT 0x0009 +#define BTM_BLE_CONN_INT_MIN_LIMIT 0x0009 #endif -#define BTM_BLE_DIR_CONN_FALLBACK_UNDIR 1 -#define BTM_BLE_DIR_CONN_FALLBACK_NO_ADV 2 +#define BTM_BLE_DIR_CONN_FALLBACK_UNDIR 1 +#define BTM_BLE_DIR_CONN_FALLBACK_NO_ADV 2 #ifndef BTM_BLE_DIR_CONN_FALLBACK -#define BTM_BLE_DIR_CONN_FALLBACK BTM_BLE_DIR_CONN_FALLBACK_UNDIR +#define BTM_BLE_DIR_CONN_FALLBACK BTM_BLE_DIR_CONN_FALLBACK_UNDIR #endif -#define BTM_CMAC_TLEN_SIZE 8 /* 64 bits */ -#define BTM_BLE_AUTH_SIGN_LEN 12 /* BLE data signature length 8 Bytes + 4 bytes counter*/ -typedef uint8_t BLE_SIGNATURE[BTM_BLE_AUTH_SIGN_LEN]; /* Device address */ +#define BTM_CMAC_TLEN_SIZE 8 /* 64 bits */ +#define BTM_BLE_AUTH_SIGN_LEN \ + 12 /* BLE data signature length 8 Bytes + 4 bytes counter*/ +typedef uint8_t BLE_SIGNATURE[BTM_BLE_AUTH_SIGN_LEN]; /* Device address */ #ifndef BTM_BLE_HOST_SUPPORT -#define BTM_BLE_HOST_SUPPORT 0x01 +#define BTM_BLE_HOST_SUPPORT 0x01 #endif #ifndef BTM_BLE_SIMULTANEOUS_HOST -#define BTM_BLE_SIMULTANEOUS_HOST 0x01 +#define BTM_BLE_SIMULTANEOUS_HOST 0x01 #endif /* Appearance Values Reported with BTM_BLE_AD_TYPE_APPEARANCE */ -#define BTM_BLE_APPEARANCE_UKNOWN 0x0000 -#define BTM_BLE_APPEARANCE_GENERIC_PHONE 0x0040 -#define BTM_BLE_APPEARANCE_GENERIC_COMPUTER 0x0080 -#define BTM_BLE_APPEARANCE_GENERIC_WATCH 0x00C0 -#define BTM_BLE_APPEARANCE_SPORTS_WATCH 0x00C1 -#define BTM_BLE_APPEARANCE_GENERIC_CLOCK 0x0100 -#define BTM_BLE_APPEARANCE_GENERIC_DISPLAY 0x0140 -#define BTM_BLE_APPEARANCE_GENERIC_REMOTE 0x0180 -#define BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES 0x01C0 -#define BTM_BLE_APPEARANCE_GENERIC_TAG 0x0200 -#define BTM_BLE_APPEARANCE_GENERIC_KEYRING 0x0240 -#define BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280 +#define BTM_BLE_APPEARANCE_UKNOWN 0x0000 +#define BTM_BLE_APPEARANCE_GENERIC_PHONE 0x0040 +#define BTM_BLE_APPEARANCE_GENERIC_COMPUTER 0x0080 +#define BTM_BLE_APPEARANCE_GENERIC_WATCH 0x00C0 +#define BTM_BLE_APPEARANCE_SPORTS_WATCH 0x00C1 +#define BTM_BLE_APPEARANCE_GENERIC_CLOCK 0x0100 +#define BTM_BLE_APPEARANCE_GENERIC_DISPLAY 0x0140 +#define BTM_BLE_APPEARANCE_GENERIC_REMOTE 0x0180 +#define BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES 0x01C0 +#define BTM_BLE_APPEARANCE_GENERIC_TAG 0x0200 +#define BTM_BLE_APPEARANCE_GENERIC_KEYRING 0x0240 +#define BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280 #define BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0 -#define BTM_BLE_APPEARANCE_GENERIC_THERMOMETER 0x0300 -#define BTM_BLE_APPEARANCE_THERMOMETER_EAR 0x0301 -#define BTM_BLE_APPEARANCE_GENERIC_HEART_RATE 0x0340 -#define BTM_BLE_APPEARANCE_HEART_RATE_BELT 0x0341 -#define BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380 -#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381 -#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382 -#define BTM_BLE_APPEARANCE_GENERIC_HID 0x03C0 -#define BTM_BLE_APPEARANCE_HID_KEYBOARD 0x03C1 -#define BTM_BLE_APPEARANCE_HID_MOUSE 0x03C2 -#define BTM_BLE_APPEARANCE_HID_JOYSTICK 0x03C3 -#define BTM_BLE_APPEARANCE_HID_GAMEPAD 0x03C4 -#define BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET 0x03C5 -#define BTM_BLE_APPEARANCE_HID_CARD_READER 0x03C6 -#define BTM_BLE_APPEARANCE_HID_DIGITAL_PEN 0x03C7 -#define BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER 0x03C8 -#define BTM_BLE_APPEARANCE_GENERIC_GLUCOSE 0x0400 -#define BTM_BLE_APPEARANCE_GENERIC_WALKING 0x0440 -#define BTM_BLE_APPEARANCE_WALKING_IN_SHOE 0x0441 -#define BTM_BLE_APPEARANCE_WALKING_ON_SHOE 0x0442 -#define BTM_BLE_APPEARANCE_WALKING_ON_HIP 0x0443 -#define BTM_BLE_APPEARANCE_GENERIC_CYCLING 0x0480 -#define BTM_BLE_APPEARANCE_CYCLING_COMPUTER 0x0481 -#define BTM_BLE_APPEARANCE_CYCLING_SPEED 0x0482 -#define BTM_BLE_APPEARANCE_CYCLING_CADENCE 0x0483 -#define BTM_BLE_APPEARANCE_CYCLING_POWER 0x0484 -#define BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE 0x0485 -#define BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 0x0C40 +#define BTM_BLE_APPEARANCE_GENERIC_THERMOMETER 0x0300 +#define BTM_BLE_APPEARANCE_THERMOMETER_EAR 0x0301 +#define BTM_BLE_APPEARANCE_GENERIC_HEART_RATE 0x0340 +#define BTM_BLE_APPEARANCE_HEART_RATE_BELT 0x0341 +#define BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380 +#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381 +#define BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382 +#define BTM_BLE_APPEARANCE_GENERIC_HID 0x03C0 +#define BTM_BLE_APPEARANCE_HID_KEYBOARD 0x03C1 +#define BTM_BLE_APPEARANCE_HID_MOUSE 0x03C2 +#define BTM_BLE_APPEARANCE_HID_JOYSTICK 0x03C3 +#define BTM_BLE_APPEARANCE_HID_GAMEPAD 0x03C4 +#define BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET 0x03C5 +#define BTM_BLE_APPEARANCE_HID_CARD_READER 0x03C6 +#define BTM_BLE_APPEARANCE_HID_DIGITAL_PEN 0x03C7 +#define BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER 0x03C8 +#define BTM_BLE_APPEARANCE_GENERIC_GLUCOSE 0x0400 +#define BTM_BLE_APPEARANCE_GENERIC_WALKING 0x0440 +#define BTM_BLE_APPEARANCE_WALKING_IN_SHOE 0x0441 +#define BTM_BLE_APPEARANCE_WALKING_ON_SHOE 0x0442 +#define BTM_BLE_APPEARANCE_WALKING_ON_HIP 0x0443 +#define BTM_BLE_APPEARANCE_GENERIC_CYCLING 0x0480 +#define BTM_BLE_APPEARANCE_CYCLING_COMPUTER 0x0481 +#define BTM_BLE_APPEARANCE_CYCLING_SPEED 0x0482 +#define BTM_BLE_APPEARANCE_CYCLING_CADENCE 0x0483 +#define BTM_BLE_APPEARANCE_CYCLING_POWER 0x0484 +#define BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE 0x0485 +#define BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 0x0C40 #define BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41 -#define BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST 0x0C42 -#define BTM_BLE_APPEARANCE_GENERIC_WEIGHT 0x0C80 -#define BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS 0x1440 +#define BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST 0x0C42 +#define BTM_BLE_APPEARANCE_GENERIC_WEIGHT 0x0C80 +#define BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS 0x1440 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441 -#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV 0x1442 -#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD 0x1443 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV 0x1442 +#define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD 0x1443 #define BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV 0x1444 - /* Structure returned with Rand/Encrypt complete callback */ -typedef struct -{ - uint8_t status; - uint8_t param_len; - uint16_t opcode; - uint8_t param_buf[BT_OCTET16_LEN]; +typedef struct { + uint8_t status; + uint8_t param_len; + uint16_t opcode; + uint8_t param_buf[BT_OCTET16_LEN]; } tBTM_RAND_ENC; /* General callback function for notifying an application that a synchronous * BTM function is complete. The pointer contains the address of any returned * data. */ -typedef void (tBTM_RAND_ENC_CB) (tBTM_RAND_ENC *p1); +typedef void(tBTM_RAND_ENC_CB)(tBTM_RAND_ENC* p1); -#define BTM_BLE_FILTER_TARGET_SCANNER 0x01 -#define BTM_BLE_FILTER_TARGET_ADVR 0x00 +#define BTM_BLE_FILTER_TARGET_SCANNER 0x01 +#define BTM_BLE_FILTER_TARGET_ADVR 0x00 -#define BTM_BLE_POLICY_BLACK_ALL 0x00 /* relevant to both */ -#define BTM_BLE_POLICY_ALLOW_SCAN 0x01 /* relevant to advertiser */ -#define BTM_BLE_POLICY_ALLOW_CONN 0x02 /* relevant to advertiser */ -#define BTM_BLE_POLICY_WHITE_ALL 0x03 /* relevant to both */ +#define BTM_BLE_POLICY_BLACK_ALL 0x00 /* relevant to both */ +#define BTM_BLE_POLICY_ALLOW_SCAN 0x01 /* relevant to advertiser */ +#define BTM_BLE_POLICY_ALLOW_CONN 0x02 /* relevant to advertiser */ +#define BTM_BLE_POLICY_WHITE_ALL 0x03 /* relevant to both */ /* ADV data flag bit definition used for BTM_BLE_AD_TYPE_FLAG */ -#define BTM_BLE_LIMIT_DISC_FLAG (0x01 << 0) -#define BTM_BLE_GEN_DISC_FLAG (0x01 << 1) -#define BTM_BLE_BREDR_NOT_SPT (0x01 << 2) +#define BTM_BLE_LIMIT_DISC_FLAG (0x01 << 0) +#define BTM_BLE_GEN_DISC_FLAG (0x01 << 1) +#define BTM_BLE_BREDR_NOT_SPT (0x01 << 2) /* 4.1 spec adv flag for simultaneous BR/EDR+LE connection support */ -#define BTM_BLE_DMT_CONTROLLER_SPT (0x01 << 3) -#define BTM_BLE_DMT_HOST_SPT (0x01 << 4) -#define BTM_BLE_NON_LIMIT_DISC_FLAG (0x00 ) /* lowest bit unset */ -#define BTM_BLE_ADV_FLAG_MASK (BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG) -#define BTM_BLE_LIMIT_DISC_MASK (BTM_BLE_LIMIT_DISC_FLAG ) - -//TODO(jpawlowski): this should be removed with code that depend on it. -#define BTM_BLE_AD_BIT_FLAGS (0x00000001 << 1) - -#define BTM_BLE_AD_TYPE_FLAG HCI_EIR_FLAGS_TYPE /* 0x01 */ -#define BTM_BLE_AD_TYPE_16SRV_CMPL HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x03 */ -#define BTM_BLE_AD_TYPE_NAME_SHORT HCI_EIR_SHORTENED_LOCAL_NAME_TYPE /* 0x08 */ -#define BTM_BLE_AD_TYPE_NAME_CMPL HCI_EIR_COMPLETE_LOCAL_NAME_TYPE /* 0x09 */ - -#define BTM_BLE_AD_TYPE_APPEARANCE 0x19 +#define BTM_BLE_DMT_CONTROLLER_SPT (0x01 << 3) +#define BTM_BLE_DMT_HOST_SPT (0x01 << 4) +#define BTM_BLE_NON_LIMIT_DISC_FLAG (0x00) /* lowest bit unset */ +#define BTM_BLE_ADV_FLAG_MASK \ + (BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_BREDR_NOT_SPT | BTM_BLE_GEN_DISC_FLAG) +#define BTM_BLE_LIMIT_DISC_MASK (BTM_BLE_LIMIT_DISC_FLAG) + +// TODO(jpawlowski): this should be removed with code that depend on it. +#define BTM_BLE_AD_BIT_FLAGS (0x00000001 << 1) + +#define BTM_BLE_AD_TYPE_FLAG HCI_EIR_FLAGS_TYPE /* 0x01 */ +#define BTM_BLE_AD_TYPE_16SRV_CMPL \ + HCI_EIR_COMPLETE_16BITS_UUID_TYPE /* 0x03 \ + */ +#define BTM_BLE_AD_TYPE_NAME_SHORT \ + HCI_EIR_SHORTENED_LOCAL_NAME_TYPE /* 0x08 \ + */ +#define BTM_BLE_AD_TYPE_NAME_CMPL HCI_EIR_COMPLETE_LOCAL_NAME_TYPE /* 0x09 */ + +#define BTM_BLE_AD_TYPE_APPEARANCE 0x19 /* Security settings used with L2CAP LE COC */ -#define BTM_SEC_LE_LINK_ENCRYPTED 0x01 +#define BTM_SEC_LE_LINK_ENCRYPTED 0x01 #define BTM_SEC_LE_LINK_PAIRED_WITHOUT_MITM 0x02 -#define BTM_SEC_LE_LINK_PAIRED_WITH_MITM 0x04 +#define BTM_SEC_LE_LINK_PAIRED_WITH_MITM 0x04 /* Min/max Preferred number of payload octets that the local Controller should include in a single Link Layer Data Channel PDU. */ -#define BTM_BLE_DATA_SIZE_MAX 0x00fb -#define BTM_BLE_DATA_SIZE_MIN 0x001b +#define BTM_BLE_DATA_SIZE_MAX 0x00fb +#define BTM_BLE_DATA_SIZE_MIN 0x001b /* Preferred maximum number of microseconds that the local Controller should use to transmit a single Link Layer Data Channel PDU. */ -#define BTM_BLE_DATA_TX_TIME_MIN 0x0148 -#define BTM_BLE_DATA_TX_TIME_MAX 0x0848 +#define BTM_BLE_DATA_TX_TIME_MIN 0x0148 +#define BTM_BLE_DATA_TX_TIME_MAX 0x0848 /* adv tx power level */ -#define BTM_BLE_ADV_TX_POWER_MIN 0 /* minimum tx power */ -#define BTM_BLE_ADV_TX_POWER_LOW 1 /* low tx power */ -#define BTM_BLE_ADV_TX_POWER_MID 2 /* middle tx power */ -#define BTM_BLE_ADV_TX_POWER_UPPER 3 /* upper tx power */ -#define BTM_BLE_ADV_TX_POWER_MAX 4 /* maximum tx power */ +#define BTM_BLE_ADV_TX_POWER_MIN 0 /* minimum tx power */ +#define BTM_BLE_ADV_TX_POWER_LOW 1 /* low tx power */ +#define BTM_BLE_ADV_TX_POWER_MID 2 /* middle tx power */ +#define BTM_BLE_ADV_TX_POWER_UPPER 3 /* upper tx power */ +#define BTM_BLE_ADV_TX_POWER_MAX 4 /* maximum tx power */ typedef uint8_t tBTM_BLE_ADV_TX_POWER; /* adv tx power in dBm */ -typedef struct -{ - uint8_t adv_inst_max; /* max adv instance supported in controller */ - uint8_t rpa_offloading; - uint16_t tot_scan_results_strg; - uint8_t max_irk_list_sz; - uint8_t filter_support; - uint8_t max_filter; - uint8_t energy_support; - bool values_read; - uint16_t version_supported; - uint16_t total_trackable_advertisers; - uint8_t extended_scan_support; - uint8_t debug_logging_supported; -}tBTM_BLE_VSC_CB; - -typedef void (tBTM_BLE_ADV_DATA_CMPL_CBACK) (tBTM_STATUS status); +typedef struct { + uint8_t adv_inst_max; /* max adv instance supported in controller */ + uint8_t rpa_offloading; + uint16_t tot_scan_results_strg; + uint8_t max_irk_list_sz; + uint8_t filter_support; + uint8_t max_filter; + uint8_t energy_support; + bool values_read; + uint16_t version_supported; + uint16_t total_trackable_advertisers; + uint8_t extended_scan_support; + uint8_t debug_logging_supported; +} tBTM_BLE_VSC_CB; + +typedef void(tBTM_BLE_ADV_DATA_CMPL_CBACK)(tBTM_STATUS status); #ifndef BTM_BLE_MULTI_ADV_MAX -#define BTM_BLE_MULTI_ADV_MAX 16 /* controller returned adv_inst_max should be less - than this number */ +#define BTM_BLE_MULTI_ADV_MAX \ + 16 /* controller returned adv_inst_max should be less \ + than this number */ #endif typedef uint8_t tGATT_IF; -typedef void (tBTM_BLE_SCAN_THRESHOLD_CBACK)(tBTM_BLE_REF_VALUE ref_value); -typedef void (tBTM_BLE_SCAN_REP_CBACK)(tBTM_BLE_REF_VALUE ref_value, uint8_t report_format, - uint8_t num_records, uint16_t total_len, - uint8_t* p_rep_data, uint8_t status); -typedef void (tBTM_BLE_SCAN_SETUP_CBACK)(uint8_t evt, tBTM_BLE_REF_VALUE ref_value, uint8_t status); +typedef void(tBTM_BLE_SCAN_THRESHOLD_CBACK)(tBTM_BLE_REF_VALUE ref_value); +typedef void(tBTM_BLE_SCAN_REP_CBACK)(tBTM_BLE_REF_VALUE ref_value, + uint8_t report_format, + uint8_t num_records, uint16_t total_len, + uint8_t* p_rep_data, uint8_t status); +typedef void(tBTM_BLE_SCAN_SETUP_CBACK)(uint8_t evt, + tBTM_BLE_REF_VALUE ref_value, + uint8_t status); #ifndef BTM_BLE_BATCH_SCAN_MAX -#define BTM_BLE_BATCH_SCAN_MAX 5 +#define BTM_BLE_BATCH_SCAN_MAX 5 #endif #ifndef BTM_BLE_BATCH_REP_MAIN_Q_SIZE -#define BTM_BLE_BATCH_REP_MAIN_Q_SIZE 2 +#define BTM_BLE_BATCH_REP_MAIN_Q_SIZE 2 #endif -typedef enum -{ - BTM_BLE_SCAN_INVALID_STATE=0, - BTM_BLE_SCAN_ENABLE_CALLED=1, - BTM_BLE_SCAN_ENABLED_STATE=2, - BTM_BLE_SCAN_DISABLE_CALLED=3, - BTM_BLE_SCAN_DISABLED_STATE=4 -}tBTM_BLE_BATCH_SCAN_STATE; - -enum -{ - BTM_BLE_DISCARD_OLD_ITEMS, - BTM_BLE_DISCARD_LOWER_RSSI_ITEMS -}; +typedef enum { + BTM_BLE_SCAN_INVALID_STATE = 0, + BTM_BLE_SCAN_ENABLE_CALLED = 1, + BTM_BLE_SCAN_ENABLED_STATE = 2, + BTM_BLE_SCAN_DISABLE_CALLED = 3, + BTM_BLE_SCAN_DISABLED_STATE = 4 +} tBTM_BLE_BATCH_SCAN_STATE; + +enum { BTM_BLE_DISCARD_OLD_ITEMS, BTM_BLE_DISCARD_LOWER_RSSI_ITEMS }; typedef uint8_t tBTM_BLE_DISCARD_RULE; -typedef struct -{ - uint8_t sub_code[BTM_BLE_BATCH_SCAN_MAX]; - tBTM_BLE_BATCH_SCAN_STATE cur_state[BTM_BLE_BATCH_SCAN_MAX]; - tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_SCAN_MAX]; - uint8_t pending_idx; - uint8_t next_idx; -}tBTM_BLE_BATCH_SCAN_OPQ; - -typedef struct -{ - uint8_t rep_mode[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; - tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; - uint8_t num_records[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; - uint16_t data_len[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; - uint8_t *p_data[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; - uint8_t pending_idx; - uint8_t next_idx; -}tBTM_BLE_BATCH_SCAN_REP_Q; - -typedef struct -{ - tBTM_BLE_BATCH_SCAN_STATE cur_state; - tBTM_BLE_BATCH_SCAN_MODE scan_mode; - uint32_t scan_interval; - uint32_t scan_window; - tBLE_ADDR_TYPE addr_type; - tBTM_BLE_DISCARD_RULE discard_rule; - tBTM_BLE_BATCH_SCAN_OPQ op_q; - tBTM_BLE_BATCH_SCAN_REP_Q main_rep_q; - tBTM_BLE_SCAN_SETUP_CBACK *p_setup_cback; - tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback; - tBTM_BLE_SCAN_REP_CBACK *p_scan_rep_cback; - tBTM_BLE_REF_VALUE ref_value; -}tBTM_BLE_BATCH_SCAN_CB; +typedef struct { + uint8_t sub_code[BTM_BLE_BATCH_SCAN_MAX]; + tBTM_BLE_BATCH_SCAN_STATE cur_state[BTM_BLE_BATCH_SCAN_MAX]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_SCAN_MAX]; + uint8_t pending_idx; + uint8_t next_idx; +} tBTM_BLE_BATCH_SCAN_OPQ; + +typedef struct { + uint8_t rep_mode[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + uint8_t num_records[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + uint16_t data_len[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + uint8_t* p_data[BTM_BLE_BATCH_REP_MAIN_Q_SIZE]; + uint8_t pending_idx; + uint8_t next_idx; +} tBTM_BLE_BATCH_SCAN_REP_Q; + +typedef struct { + tBTM_BLE_BATCH_SCAN_STATE cur_state; + tBTM_BLE_BATCH_SCAN_MODE scan_mode; + uint32_t scan_interval; + uint32_t scan_window; + tBLE_ADDR_TYPE addr_type; + tBTM_BLE_DISCARD_RULE discard_rule; + tBTM_BLE_BATCH_SCAN_OPQ op_q; + tBTM_BLE_BATCH_SCAN_REP_Q main_rep_q; + tBTM_BLE_SCAN_SETUP_CBACK* p_setup_cback; + tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback; + tBTM_BLE_SCAN_REP_CBACK* p_scan_rep_cback; + tBTM_BLE_REF_VALUE ref_value; +} tBTM_BLE_BATCH_SCAN_CB; /* filter selection bit index */ -#define BTM_BLE_PF_ADDR_FILTER 0 -#define BTM_BLE_PF_SRVC_DATA 1 -#define BTM_BLE_PF_SRVC_UUID 2 -#define BTM_BLE_PF_SRVC_SOL_UUID 3 -#define BTM_BLE_PF_LOCAL_NAME 4 -#define BTM_BLE_PF_MANU_DATA 5 -#define BTM_BLE_PF_SRVC_DATA_PATTERN 6 +#define BTM_BLE_PF_ADDR_FILTER 0 +#define BTM_BLE_PF_SRVC_DATA 1 +#define BTM_BLE_PF_SRVC_UUID 2 +#define BTM_BLE_PF_SRVC_SOL_UUID 3 +#define BTM_BLE_PF_LOCAL_NAME 4 +#define BTM_BLE_PF_MANU_DATA 5 +#define BTM_BLE_PF_SRVC_DATA_PATTERN 6 /* when passed in payload filter type all, only clear action is applicable */ -#define BTM_BLE_PF_TYPE_ALL 7 -#define BTM_BLE_PF_TYPE_MAX 8 +#define BTM_BLE_PF_TYPE_ALL 7 +#define BTM_BLE_PF_TYPE_MAX 8 /* max number of filter spot for different filter type */ #ifndef BTM_BLE_MAX_UUID_FILTER -#define BTM_BLE_MAX_UUID_FILTER 8 +#define BTM_BLE_MAX_UUID_FILTER 8 #endif #ifndef BTM_BLE_MAX_ADDR_FILTER -#define BTM_BLE_MAX_ADDR_FILTER 8 +#define BTM_BLE_MAX_ADDR_FILTER 8 #endif #ifndef BTM_BLE_PF_STR_COND_MAX -#define BTM_BLE_PF_STR_COND_MAX 4 /* apply to manu data , or local name */ +#define BTM_BLE_PF_STR_COND_MAX 4 /* apply to manu data , or local name */ #endif #ifndef BTM_BLE_PF_STR_LEN_MAX -#define BTM_BLE_PF_STR_LEN_MAX 29 /* match for first 29 bytes */ +#define BTM_BLE_PF_STR_LEN_MAX 29 /* match for first 29 bytes */ #endif typedef uint8_t tBTM_BLE_PF_COND_TYPE; -#define BTM_BLE_PF_LOGIC_OR 0 -#define BTM_BLE_PF_LOGIC_AND 1 +#define BTM_BLE_PF_LOGIC_OR 0 +#define BTM_BLE_PF_LOGIC_AND 1 typedef uint8_t tBTM_BLE_PF_LOGIC_TYPE; -#define BTM_BLE_PF_ENABLE 1 -#define BTM_BLE_PF_CONFIG 2 +#define BTM_BLE_PF_ENABLE 1 +#define BTM_BLE_PF_CONFIG 2 typedef uint8_t tBTM_BLE_PF_ACTION; typedef uint8_t tBTM_BLE_PF_FILT_INDEX; typedef uint8_t tBTM_BLE_PF_AVBL_SPACE; -#define BTM_BLE_PF_BRDCAST_ADDR_FILT 1 +#define BTM_BLE_PF_BRDCAST_ADDR_FILT 1 #define BTM_BLE_PF_SERV_DATA_CHG_FILT 2 -#define BTM_BLE_PF_SERV_UUID 4 -#define BTM_BLE_PF_SERV_SOLC_UUID 8 -#define BTM_BLE_PF_LOC_NAME_CHECK 16 -#define BTM_BLE_PF_MANUF_NAME_CHECK 32 -#define BTM_BLE_PF_SERV_DATA_CHECK 64 +#define BTM_BLE_PF_SERV_UUID 4 +#define BTM_BLE_PF_SERV_SOLC_UUID 8 +#define BTM_BLE_PF_LOC_NAME_CHECK 16 +#define BTM_BLE_PF_MANUF_NAME_CHECK 32 +#define BTM_BLE_PF_SERV_DATA_CHECK 64 typedef uint16_t tBTM_BLE_PF_FEAT_SEL; -#define BTM_BLE_PF_LIST_LOGIC_OR 1 -#define BTM_BLE_PF_LIST_LOGIC_AND 2 +#define BTM_BLE_PF_LIST_LOGIC_OR 1 +#define BTM_BLE_PF_LIST_LOGIC_AND 2 typedef uint16_t tBTM_BLE_PF_LIST_LOGIC_TYPE; -#define BTM_BLE_PF_FILT_LOGIC_OR 0 -#define BTM_BLE_PF_FILT_LOGIC_AND 1 +#define BTM_BLE_PF_FILT_LOGIC_OR 0 +#define BTM_BLE_PF_FILT_LOGIC_AND 1 typedef uint16_t tBTM_BLE_PF_FILT_LOGIC_TYPE; typedef uint8_t tBTM_BLE_PF_RSSI_THRESHOLD; @@ -491,193 +491,178 @@ typedef uint16_t tBTM_BLE_PF_TIMEOUT; typedef uint8_t tBTM_BLE_PF_TIMEOUT_CNT; typedef uint16_t tBTM_BLE_PF_ADV_TRACK_ENTRIES; -typedef struct -{ - tBTM_BLE_PF_FEAT_SEL feat_seln; - tBTM_BLE_PF_LIST_LOGIC_TYPE logic_type; - tBTM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type; - tBTM_BLE_PF_RSSI_THRESHOLD rssi_high_thres; - tBTM_BLE_PF_RSSI_THRESHOLD rssi_low_thres; - tBTM_BLE_PF_DELIVERY_MODE dely_mode; - tBTM_BLE_PF_TIMEOUT found_timeout; - tBTM_BLE_PF_TIMEOUT lost_timeout; - tBTM_BLE_PF_TIMEOUT_CNT found_timeout_cnt; - tBTM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries; -}tBTM_BLE_PF_FILT_PARAMS; - -enum -{ - BTM_BLE_SCAN_COND_ADD, - BTM_BLE_SCAN_COND_DELETE, - BTM_BLE_SCAN_COND_CLEAR = 2 +typedef struct { + tBTM_BLE_PF_FEAT_SEL feat_seln; + tBTM_BLE_PF_LIST_LOGIC_TYPE logic_type; + tBTM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type; + tBTM_BLE_PF_RSSI_THRESHOLD rssi_high_thres; + tBTM_BLE_PF_RSSI_THRESHOLD rssi_low_thres; + tBTM_BLE_PF_DELIVERY_MODE dely_mode; + tBTM_BLE_PF_TIMEOUT found_timeout; + tBTM_BLE_PF_TIMEOUT lost_timeout; + tBTM_BLE_PF_TIMEOUT_CNT found_timeout_cnt; + tBTM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries; +} tBTM_BLE_PF_FILT_PARAMS; + +enum { + BTM_BLE_SCAN_COND_ADD, + BTM_BLE_SCAN_COND_DELETE, + BTM_BLE_SCAN_COND_CLEAR = 2 }; typedef uint8_t tBTM_BLE_SCAN_COND_OP; -enum -{ - BTM_BLE_FILT_ENABLE_DISABLE = 1, - BTM_BLE_FILT_CFG = 2, - BTM_BLE_FILT_ADV_PARAM = 3 +enum { + BTM_BLE_FILT_ENABLE_DISABLE = 1, + BTM_BLE_FILT_CFG = 2, + BTM_BLE_FILT_ADV_PARAM = 3 }; typedef uint8_t tBTM_BLE_FILT_CB_EVT; /* BLE adv payload filtering config complete callback */ -typedef void (tBTM_BLE_PF_CFG_CBACK)(tBTM_BLE_PF_ACTION action, tBTM_BLE_SCAN_COND_OP cfg_op, - tBTM_BLE_PF_AVBL_SPACE avbl_space, tBTM_STATUS status, - tBTM_BLE_REF_VALUE ref_value); +typedef void(tBTM_BLE_PF_CFG_CBACK)(tBTM_BLE_PF_ACTION action, + tBTM_BLE_SCAN_COND_OP cfg_op, + tBTM_BLE_PF_AVBL_SPACE avbl_space, + tBTM_STATUS status, + tBTM_BLE_REF_VALUE ref_value); -typedef void (tBTM_BLE_PF_CMPL_CBACK) (tBTM_BLE_PF_CFG_CBACK); +typedef void(tBTM_BLE_PF_CMPL_CBACK)(tBTM_BLE_PF_CFG_CBACK); /* BLE adv payload filtering status setup complete callback */ -typedef void (tBTM_BLE_PF_STATUS_CBACK) (uint8_t action, tBTM_STATUS status, - tBTM_BLE_REF_VALUE ref_value); +typedef void(tBTM_BLE_PF_STATUS_CBACK)(uint8_t action, tBTM_STATUS status, + tBTM_BLE_REF_VALUE ref_value); /* BLE adv payload filtering param setup complete callback */ -typedef void (tBTM_BLE_PF_PARAM_CBACK) (tBTM_BLE_PF_ACTION action_type, - tBTM_BLE_PF_AVBL_SPACE avbl_space, - tBTM_BLE_REF_VALUE ref_value, tBTM_STATUS status); - -typedef union -{ - uint16_t uuid16_mask; - uint32_t uuid32_mask; - uint8_t uuid128_mask[LEN_UUID_128]; -}tBTM_BLE_PF_COND_MASK; - -typedef struct -{ - tBLE_BD_ADDR *p_target_addr; /* target address, if NULL, generic UUID filter */ - tBT_UUID uuid; /* UUID condition */ - tBTM_BLE_PF_LOGIC_TYPE cond_logic; /* AND/OR */ - tBTM_BLE_PF_COND_MASK *p_uuid_mask; /* UUID mask */ -}tBTM_BLE_PF_UUID_COND; - -typedef struct -{ - uint8_t data_len; /* <= 20 bytes */ - uint8_t *p_data; -}tBTM_BLE_PF_LOCAL_NAME_COND; - -typedef struct -{ - uint16_t company_id; /* company ID */ - uint8_t data_len; /* <= 20 bytes */ - uint8_t *p_pattern; - uint16_t company_id_mask; /* UUID value mask */ - uint8_t *p_pattern_mask; /* Manufacturer data matching mask, - same length as data pattern, - set to all 0xff, match exact data */ -}tBTM_BLE_PF_MANU_COND; - -typedef struct -{ - uint16_t uuid; /* service ID */ - uint8_t data_len; /* <= 20 bytes */ - uint8_t *p_pattern; - uint8_t *p_pattern_mask; /* Service data matching mask, same length as data pattern, - set to all 0xff, match exact data */ -}tBTM_BLE_PF_SRVC_PATTERN_COND; - - -typedef union -{ - tBLE_BD_ADDR target_addr; - tBTM_BLE_PF_LOCAL_NAME_COND local_name; /* lcoal name filtering */ - tBTM_BLE_PF_MANU_COND manu_data; /* manufactuer data filtering */ - tBTM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */ - tBTM_BLE_PF_UUID_COND solicitate_uuid; /* solicitated service UUID filtering */ - tBTM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */ -}tBTM_BLE_PF_COND_PARAM; - -typedef struct -{ - uint8_t action_ocf[BTM_BLE_PF_TYPE_MAX]; - tBTM_BLE_REF_VALUE ref_value[BTM_BLE_PF_TYPE_MAX]; - tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback[BTM_BLE_PF_TYPE_MAX]; - tBTM_BLE_PF_CFG_CBACK *p_scan_cfg_cback[BTM_BLE_PF_TYPE_MAX]; - uint8_t cb_evt[BTM_BLE_PF_TYPE_MAX]; - uint8_t pending_idx; - uint8_t next_idx; -}tBTM_BLE_ADV_FILTER_ADV_OPQ; +typedef void(tBTM_BLE_PF_PARAM_CBACK)(tBTM_BLE_PF_ACTION action_type, + tBTM_BLE_PF_AVBL_SPACE avbl_space, + tBTM_BLE_REF_VALUE ref_value, + tBTM_STATUS status); + +typedef union { + uint16_t uuid16_mask; + uint32_t uuid32_mask; + uint8_t uuid128_mask[LEN_UUID_128]; +} tBTM_BLE_PF_COND_MASK; + +typedef struct { + tBLE_BD_ADDR* + p_target_addr; /* target address, if NULL, generic UUID filter */ + tBT_UUID uuid; /* UUID condition */ + tBTM_BLE_PF_LOGIC_TYPE cond_logic; /* AND/OR */ + tBTM_BLE_PF_COND_MASK* p_uuid_mask; /* UUID mask */ +} tBTM_BLE_PF_UUID_COND; + +typedef struct { + uint8_t data_len; /* <= 20 bytes */ + uint8_t* p_data; +} tBTM_BLE_PF_LOCAL_NAME_COND; + +typedef struct { + uint16_t company_id; /* company ID */ + uint8_t data_len; /* <= 20 bytes */ + uint8_t* p_pattern; + uint16_t company_id_mask; /* UUID value mask */ + uint8_t* p_pattern_mask; /* Manufacturer data matching mask, + same length as data pattern, + set to all 0xff, match exact data */ +} tBTM_BLE_PF_MANU_COND; + +typedef struct { + uint16_t uuid; /* service ID */ + uint8_t data_len; /* <= 20 bytes */ + uint8_t* p_pattern; + uint8_t* p_pattern_mask; /* Service data matching mask, same length as data + pattern, + set to all 0xff, match exact data */ +} tBTM_BLE_PF_SRVC_PATTERN_COND; + +typedef union { + tBLE_BD_ADDR target_addr; + tBTM_BLE_PF_LOCAL_NAME_COND local_name; /* lcoal name filtering */ + tBTM_BLE_PF_MANU_COND manu_data; /* manufactuer data filtering */ + tBTM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */ + tBTM_BLE_PF_UUID_COND + solicitate_uuid; /* solicitated service UUID filtering */ + tBTM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */ +} tBTM_BLE_PF_COND_PARAM; + +typedef struct { + uint8_t action_ocf[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_REF_VALUE ref_value[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_PF_PARAM_CBACK* p_filt_param_cback[BTM_BLE_PF_TYPE_MAX]; + tBTM_BLE_PF_CFG_CBACK* p_scan_cfg_cback[BTM_BLE_PF_TYPE_MAX]; + uint8_t cb_evt[BTM_BLE_PF_TYPE_MAX]; + uint8_t pending_idx; + uint8_t next_idx; +} tBTM_BLE_ADV_FILTER_ADV_OPQ; /* per device filter + one generic filter indexed by 0 */ -#define BTM_BLE_MAX_FILTER_COUNTER (BTM_BLE_MAX_ADDR_FILTER + 1) +#define BTM_BLE_MAX_FILTER_COUNTER (BTM_BLE_MAX_ADDR_FILTER + 1) #ifndef BTM_CS_IRK_LIST_MAX #define BTM_CS_IRK_LIST_MAX 0x20 #endif -typedef struct -{ - bool in_use; - BD_ADDR bd_addr; - uint8_t pf_counter[BTM_BLE_PF_TYPE_MAX]; /* number of filter indexed by tBTM_BLE_PF_COND_TYPE */ -}tBTM_BLE_PF_COUNT; - -typedef struct -{ - bool enable; - uint8_t op_type; - tBTM_BLE_PF_COUNT *p_addr_filter_count; /* per BDA filter array */ - tBLE_BD_ADDR cur_filter_target; - tBTM_BLE_PF_STATUS_CBACK *p_filt_stat_cback; - tBTM_BLE_ADV_FILTER_ADV_OPQ op_q; -}tBTM_BLE_ADV_FILTER_CB; +typedef struct { + bool in_use; + BD_ADDR bd_addr; + uint8_t pf_counter[BTM_BLE_PF_TYPE_MAX]; /* number of filter indexed by + tBTM_BLE_PF_COND_TYPE */ +} tBTM_BLE_PF_COUNT; + +typedef struct { + bool enable; + uint8_t op_type; + tBTM_BLE_PF_COUNT* p_addr_filter_count; /* per BDA filter array */ + tBLE_BD_ADDR cur_filter_target; + tBTM_BLE_PF_STATUS_CBACK* p_filt_stat_cback; + tBTM_BLE_ADV_FILTER_ADV_OPQ op_q; +} tBTM_BLE_ADV_FILTER_CB; /* Sub codes */ -#define BTM_BLE_META_PF_ENABLE 0x00 -#define BTM_BLE_META_PF_FEAT_SEL 0x01 -#define BTM_BLE_META_PF_ADDR 0x02 -#define BTM_BLE_META_PF_UUID 0x03 -#define BTM_BLE_META_PF_SOL_UUID 0x04 -#define BTM_BLE_META_PF_LOCAL_NAME 0x05 -#define BTM_BLE_META_PF_MANU_DATA 0x06 -#define BTM_BLE_META_PF_SRVC_DATA 0x07 -#define BTM_BLE_META_PF_ALL 0x08 +#define BTM_BLE_META_PF_ENABLE 0x00 +#define BTM_BLE_META_PF_FEAT_SEL 0x01 +#define BTM_BLE_META_PF_ADDR 0x02 +#define BTM_BLE_META_PF_UUID 0x03 +#define BTM_BLE_META_PF_SOL_UUID 0x04 +#define BTM_BLE_META_PF_LOCAL_NAME 0x05 +#define BTM_BLE_META_PF_MANU_DATA 0x06 +#define BTM_BLE_META_PF_SRVC_DATA 0x07 +#define BTM_BLE_META_PF_ALL 0x08 typedef uint8_t BTM_BLE_ADV_STATE; typedef uint8_t BTM_BLE_ADV_INFO_PRESENT; typedef uint8_t BTM_BLE_RSSI_VALUE; typedef uint16_t BTM_BLE_ADV_INFO_TIMESTAMP; -enum -{ - BTM_BLE_CONN_NONE, - BTM_BLE_CONN_AUTO, - BTM_BLE_CONN_SELECTIVE -}; +enum { BTM_BLE_CONN_NONE, BTM_BLE_CONN_AUTO, BTM_BLE_CONN_SELECTIVE }; typedef uint8_t tBTM_BLE_CONN_TYPE; -#define ADV_INFO_PRESENT 0x00 -#define NO_ADV_INFO_PRESENT 0x01 +#define ADV_INFO_PRESENT 0x00 +#define NO_ADV_INFO_PRESENT 0x01 typedef btgatt_track_adv_info_t tBTM_BLE_TRACK_ADV_DATA; -typedef void (tBTM_BLE_TRACK_ADV_CBACK)(tBTM_BLE_TRACK_ADV_DATA *p_track_adv_data); +typedef void(tBTM_BLE_TRACK_ADV_CBACK)( + tBTM_BLE_TRACK_ADV_DATA* p_track_adv_data); typedef uint8_t tBTM_BLE_TRACK_ADV_EVT; -typedef struct -{ - tBTM_BLE_REF_VALUE ref_value; - tBTM_BLE_TRACK_ADV_CBACK *p_track_cback; -}tBTM_BLE_ADV_TRACK_CB; +typedef struct { + tBTM_BLE_REF_VALUE ref_value; + tBTM_BLE_TRACK_ADV_CBACK* p_track_cback; +} tBTM_BLE_ADV_TRACK_CB; -enum -{ - BTM_BLE_TRACK_ADV_ADD, - BTM_BLE_TRACK_ADV_REMOVE -}; +enum { BTM_BLE_TRACK_ADV_ADD, BTM_BLE_TRACK_ADV_REMOVE }; typedef uint8_t tBTM_BLE_TRACK_ADV_ACTION; -#define BTM_BLE_BATCH_SCAN_ENABLE_EVT 1 -#define BTM_BLE_BATCH_SCAN_CFG_STRG_EVT 2 +#define BTM_BLE_BATCH_SCAN_ENABLE_EVT 1 +#define BTM_BLE_BATCH_SCAN_CFG_STRG_EVT 2 #define BTM_BLE_BATCH_SCAN_READ_REPTS_EVT 3 -#define BTM_BLE_BATCH_SCAN_THR_EVT 4 -#define BTM_BLE_BATCH_SCAN_PARAM_EVT 5 -#define BTM_BLE_BATCH_SCAN_DISABLE_EVT 6 +#define BTM_BLE_BATCH_SCAN_THR_EVT 4 +#define BTM_BLE_BATCH_SCAN_PARAM_EVT 5 +#define BTM_BLE_BATCH_SCAN_DISABLE_EVT 6 typedef uint8_t tBTM_BLE_BATCH_SCAN_EVT; @@ -686,31 +671,34 @@ typedef uint32_t tBTM_BLE_RX_TIME_MS; typedef uint32_t tBTM_BLE_IDLE_TIME_MS; typedef uint32_t tBTM_BLE_ENERGY_USED; -typedef void (tBTM_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time, tBTM_BLE_RX_TIME_MS rx_time, - tBTM_BLE_IDLE_TIME_MS idle_time, - tBTM_BLE_ENERGY_USED energy_used, - tBTM_STATUS status); +typedef void(tBTM_BLE_ENERGY_INFO_CBACK)(tBTM_BLE_TX_TIME_MS tx_time, + tBTM_BLE_RX_TIME_MS rx_time, + tBTM_BLE_IDLE_TIME_MS idle_time, + tBTM_BLE_ENERGY_USED energy_used, + tBTM_STATUS status); -typedef struct -{ - tBTM_BLE_ENERGY_INFO_CBACK *p_ener_cback; -}tBTM_BLE_ENERGY_INFO_CB; +typedef struct { + tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback; +} tBTM_BLE_ENERGY_INFO_CB; -typedef bool (tBTM_BLE_SEL_CBACK)(BD_ADDR random_bda, uint8_t *p_remote_name); -typedef void (tBTM_BLE_CTRL_FEATURES_CBACK)(tBTM_STATUS status); +typedef bool(tBTM_BLE_SEL_CBACK)(BD_ADDR random_bda, uint8_t* p_remote_name); +typedef void(tBTM_BLE_CTRL_FEATURES_CBACK)(tBTM_STATUS status); /* callback function for SMP signing algorithm, signed data in little endian * order with tlen bits long */ -typedef void (tBTM_BLE_SIGN_CBACK)(void *p_ref_data, uint8_t *p_signing_data); -typedef void (tBTM_BLE_VERIFY_CBACK)(void *p_ref_data, bool match); +typedef void(tBTM_BLE_SIGN_CBACK)(void* p_ref_data, uint8_t* p_signing_data); +typedef void(tBTM_BLE_VERIFY_CBACK)(void* p_ref_data, bool match); /* random address set complete callback */ -typedef void (tBTM_BLE_RANDOM_SET_CBACK) (BD_ADDR random_bda); +typedef void(tBTM_BLE_RANDOM_SET_CBACK)(BD_ADDR random_bda); -typedef void (tBTM_BLE_SCAN_REQ_CBACK)(BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type, uint8_t adv_evt); -typedef void (*tBLE_SCAN_PARAM_SETUP_CBACK)(tGATT_IF client_if, tBTM_STATUS status); +typedef void(tBTM_BLE_SCAN_REQ_CBACK)(BD_ADDR remote_bda, + tBLE_ADDR_TYPE addr_type, + uint8_t adv_evt); +typedef void (*tBLE_SCAN_PARAM_SETUP_CBACK)(tGATT_IF client_if, + tBTM_STATUS status); #ifdef __cplusplus } #endif -#endif // BTM_BLE_API_TYPES_H +#endif // BTM_BLE_API_TYPES_H diff --git a/stack/include/btu.h b/stack/include/btu.h index 0ff76fc7f..eb61309c3 100644 --- a/stack/include/btu.h +++ b/stack/include/btu.h @@ -27,8 +27,8 @@ #ifndef BTU_H #define BTU_H -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" #include "osi/include/alarm.h" #ifdef __cplusplus @@ -36,48 +36,47 @@ extern "C" { #endif // HACK(zachoverflow): temporary dark magic -#define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing -typedef struct { - void (*callback)(BT_HDR *); -} post_to_task_hack_t; +#define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK \ + 0x1700 // didn't look used in bt_types...here goes nothing +typedef struct { void (*callback)(BT_HDR*); } post_to_task_hack_t; typedef struct { - void (*callback)(BT_HDR *); - BT_HDR *response; - void *context; + void (*callback)(BT_HDR*); + BT_HDR* response; + void* context; } command_complete_hack_t; typedef struct { - void (*callback)(BT_HDR *); + void (*callback)(BT_HDR*); uint8_t status; - BT_HDR *command; - void *context; + BT_HDR* command; + void* context; } command_status_hack_t; /* Global BTU data */ extern uint8_t btu_trace_level; -extern const BD_ADDR BT_BD_ANY; +extern const BD_ADDR BT_BD_ANY; /* Functions provided by btu_task.cc *********************************** */ #if (HCILP_INCLUDED == TRUE) -extern void btu_check_bt_sleep (void); +extern void btu_check_bt_sleep(void); #endif /* Functions provided by btu_hcif.cc *********************************** */ -extern void btu_hcif_process_event (uint8_t controller_id, BT_HDR *p_buf); -extern void btu_hcif_send_cmd (uint8_t controller_id, BT_HDR *p_msg); +extern void btu_hcif_process_event(uint8_t controller_id, BT_HDR* p_buf); +extern void btu_hcif_send_cmd(uint8_t controller_id, BT_HDR* p_msg); /* Functions provided by btu_init.cc *********************************** */ -extern void btu_init_core(void); -extern void btu_free_core(void); +extern void btu_init_core(void); +extern void btu_free_core(void); void BTU_StartUp(void); void BTU_ShutDown(void); diff --git a/stack/include/gap_api.h b/stack/include/gap_api.h index b2cb3e836..56532ccef 100644 --- a/stack/include/gap_api.h +++ b/stack/include/gap_api.h @@ -19,9 +19,9 @@ #ifndef GAP_API_H #define GAP_API_H -#include "profiles_api.h" #include "btm_api.h" #include "l2c_api.h" +#include "profiles_api.h" #ifdef __cplusplus extern "C" { @@ -32,82 +32,81 @@ extern "C" { ****************************************************************************/ /*** GAP Error and Status Codes ***/ /* Unsupported call */ -#define GAP_UNSUPPORTED (GAP_ERR_GRP + 0x01) +#define GAP_UNSUPPORTED (GAP_ERR_GRP + 0x01) /* End of inquiry database marker */ -#define GAP_EOINQDB (GAP_ERR_GRP + 0x02) +#define GAP_EOINQDB (GAP_ERR_GRP + 0x02) /* The requested function was busy */ -#define GAP_ERR_BUSY (GAP_ERR_GRP + 0x03) +#define GAP_ERR_BUSY (GAP_ERR_GRP + 0x03) /* No control blocks available */ #define GAP_ERR_NO_CTRL_BLK (GAP_ERR_GRP + 0x04) /* Error occurred while initiating the command */ #define GAP_ERR_STARTING_CMD (GAP_ERR_GRP + 0x05) /* No Inquiry DB record for BD_ADDR */ -#define GAP_NO_BDADDR_REC (GAP_ERR_GRP + 0x06) +#define GAP_NO_BDADDR_REC (GAP_ERR_GRP + 0x06) /* An illegal mode parameter was detected */ -#define GAP_ERR_ILL_MODE (GAP_ERR_GRP + 0x07) +#define GAP_ERR_ILL_MODE (GAP_ERR_GRP + 0x07) /* An illegal time parameter was detected */ #define GAP_ERR_ILL_INQ_TIME (GAP_ERR_GRP + 0x08) /* An illegal parameter was detected */ -#define GAP_ERR_ILL_PARM (GAP_ERR_GRP + 0x09) +#define GAP_ERR_ILL_PARM (GAP_ERR_GRP + 0x09) /* Error starting the remote device name request */ -#define GAP_ERR_REM_NAME (GAP_ERR_GRP + 0x0a) +#define GAP_ERR_REM_NAME (GAP_ERR_GRP + 0x0a) /* The GAP command was started (result pending) */ -#define GAP_CMD_INITIATED (GAP_ERR_GRP + 0x0b) +#define GAP_CMD_INITIATED (GAP_ERR_GRP + 0x0b) /* The device was not up; the request was not executed */ -#define GAP_DEVICE_NOT_UP (GAP_ERR_GRP + 0x0c) +#define GAP_DEVICE_NOT_UP (GAP_ERR_GRP + 0x0c) /* The bd addr passed in was not found or invalid */ -#define GAP_BAD_BD_ADDR (GAP_ERR_GRP + 0x0d) +#define GAP_BAD_BD_ADDR (GAP_ERR_GRP + 0x0d) /* Bad GAP handle */ -#define GAP_ERR_BAD_HANDLE (GAP_ERR_GRP + 0x0e) +#define GAP_ERR_BAD_HANDLE (GAP_ERR_GRP + 0x0e) /* Buffer offset invalid */ -#define GAP_ERR_BUF_OFFSET (GAP_ERR_GRP + 0x0f) +#define GAP_ERR_BUF_OFFSET (GAP_ERR_GRP + 0x0f) /* Connection is in invalid state */ -#define GAP_ERR_BAD_STATE (GAP_ERR_GRP + 0x10) +#define GAP_ERR_BAD_STATE (GAP_ERR_GRP + 0x10) /* No data available */ -#define GAP_NO_DATA_AVAIL (GAP_ERR_GRP + 0x11) +#define GAP_NO_DATA_AVAIL (GAP_ERR_GRP + 0x11) /* BT stack is congested */ -#define GAP_ERR_CONGESTED (GAP_ERR_GRP + 0x12) +#define GAP_ERR_CONGESTED (GAP_ERR_GRP + 0x12) /* Security failed */ -#define GAP_ERR_SECURITY (GAP_ERR_GRP + 0x13) +#define GAP_ERR_SECURITY (GAP_ERR_GRP + 0x13) /* General error processing BTM request */ -#define GAP_ERR_PROCESSING (GAP_ERR_GRP + 0x14) +#define GAP_ERR_PROCESSING (GAP_ERR_GRP + 0x14) /* Timeout occurred while processing cmd */ -#define GAP_ERR_TIMEOUT (GAP_ERR_GRP + 0x15) -#define GAP_EVT_CONN_OPENED 0x0100 -#define GAP_EVT_CONN_CLOSED 0x0101 -#define GAP_EVT_CONN_DATA_AVAIL 0x0102 -#define GAP_EVT_CONN_CONGESTED 0x0103 -#define GAP_EVT_CONN_UNCONGESTED 0x0104 -#define GAP_EVT_TX_EMPTY 0x0105 +#define GAP_ERR_TIMEOUT (GAP_ERR_GRP + 0x15) +#define GAP_EVT_CONN_OPENED 0x0100 +#define GAP_EVT_CONN_CLOSED 0x0101 +#define GAP_EVT_CONN_DATA_AVAIL 0x0102 +#define GAP_EVT_CONN_CONGESTED 0x0103 +#define GAP_EVT_CONN_UNCONGESTED 0x0104 +#define GAP_EVT_TX_EMPTY 0x0105 /* Values for 'chan_mode_mask' field */ /* GAP_ConnOpen() - optional channels to negotiate */ -#define GAP_FCR_CHAN_OPT_BASIC L2CAP_FCR_CHAN_OPT_BASIC -#define GAP_FCR_CHAN_OPT_ERTM L2CAP_FCR_CHAN_OPT_ERTM -#define GAP_FCR_CHAN_OPT_STREAM L2CAP_FCR_CHAN_OPT_STREAM +#define GAP_FCR_CHAN_OPT_BASIC L2CAP_FCR_CHAN_OPT_BASIC +#define GAP_FCR_CHAN_OPT_ERTM L2CAP_FCR_CHAN_OPT_ERTM +#define GAP_FCR_CHAN_OPT_STREAM L2CAP_FCR_CHAN_OPT_STREAM /*** used in connection variables and functions ***/ -#define GAP_INVALID_HANDLE 0xFFFF +#define GAP_INVALID_HANDLE 0xFFFF /* This is used to change the criteria for AMP */ -#define GAP_PROTOCOL_ID (UUID_PROTOCOL_UDP) +#define GAP_PROTOCOL_ID (UUID_PROTOCOL_UDP) - -#ifndef GAP_PREFER_CONN_INT_MAX -#define GAP_PREFER_CONN_INT_MAX BTM_BLE_CONN_INT_MIN +#ifndef GAP_PREFER_CONN_INT_MAX +#define GAP_PREFER_CONN_INT_MAX BTM_BLE_CONN_INT_MIN #endif -#ifndef GAP_PREFER_CONN_INT_MIN -#define GAP_PREFER_CONN_INT_MIN BTM_BLE_CONN_INT_MIN +#ifndef GAP_PREFER_CONN_INT_MIN +#define GAP_PREFER_CONN_INT_MIN BTM_BLE_CONN_INT_MIN #endif -#ifndef GAP_PREFER_CONN_LATENCY -#define GAP_PREFER_CONN_LATENCY 0 +#ifndef GAP_PREFER_CONN_LATENCY +#define GAP_PREFER_CONN_LATENCY 0 #endif -#ifndef GAP_PREFER_CONN_SP_TOUT -#define GAP_PREFER_CONN_SP_TOUT 2000 +#ifndef GAP_PREFER_CONN_SP_TOUT +#define GAP_PREFER_CONN_SP_TOUT 2000 #endif /***************************************************************************** @@ -116,43 +115,39 @@ extern "C" { /* * Callback function for connection services */ -typedef void (tGAP_CONN_CALLBACK) (uint16_t gap_handle, uint16_t event); +typedef void(tGAP_CONN_CALLBACK)(uint16_t gap_handle, uint16_t event); /* * Define the callback function prototypes. Parameters are specific * to each event and are described below */ -typedef void (tGAP_CALLBACK) (uint16_t event, void *p_data); - +typedef void(tGAP_CALLBACK)(uint16_t event, void* p_data); /* Definition of the GAP_FindAddrByName results structure */ -typedef struct -{ - uint16_t status; - BD_ADDR bd_addr; - tBTM_BD_NAME devname; +typedef struct { + uint16_t status; + BD_ADDR bd_addr; + tBTM_BD_NAME devname; } tGAP_FINDADDR_RESULTS; -typedef struct -{ - uint16_t int_min; - uint16_t int_max; - uint16_t latency; - uint16_t sp_tout; -}tGAP_BLE_PREF_PARAM; +typedef struct { + uint16_t int_min; + uint16_t int_max; + uint16_t latency; + uint16_t sp_tout; +} tGAP_BLE_PREF_PARAM; -typedef union -{ - tGAP_BLE_PREF_PARAM conn_param; - BD_ADDR reconn_bda; - uint16_t icon; - uint8_t *p_dev_name; - uint8_t addr_resolution; +typedef union { + tGAP_BLE_PREF_PARAM conn_param; + BD_ADDR reconn_bda; + uint16_t icon; + uint8_t* p_dev_name; + uint8_t addr_resolution; -}tGAP_BLE_ATTR_VALUE; - -typedef void (tGAP_BLE_CMPL_CBACK)(bool status, BD_ADDR addr, uint16_t length, char *p_name); +} tGAP_BLE_ATTR_VALUE; +typedef void(tGAP_BLE_CMPL_CBACK)(bool status, BD_ADDR addr, uint16_t length, + char* p_name); /***************************************************************************** * External Function Declarations @@ -170,11 +165,12 @@ typedef void (tGAP_BLE_CMPL_CBACK)(bool status, BD_ADDR addr, uint16_t length * GAP_INVALID_HANDLE * ******************************************************************************/ -extern uint16_t GAP_ConnOpen(const char *p_serv_name, uint8_t service_id, bool is_server, - BD_ADDR p_rem_bda, uint16_t psm, tL2CAP_CFG_INFO *p_cfg, - tL2CAP_ERTM_INFO *ertm_info, - uint16_t security, uint8_t chan_mode_mask, - tGAP_CONN_CALLBACK *p_cb, tBT_TRANSPORT transport); +extern uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, + bool is_server, BD_ADDR p_rem_bda, uint16_t psm, + tL2CAP_CFG_INFO* p_cfg, + tL2CAP_ERTM_INFO* ertm_info, uint16_t security, + uint8_t chan_mode_mask, tGAP_CONN_CALLBACK* p_cb, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -186,7 +182,7 @@ extern uint16_t GAP_ConnOpen(const char *p_serv_name, uint8_t service_id, bool i * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -extern uint16_t GAP_ConnClose (uint16_t gap_handle); +extern uint16_t GAP_ConnClose(uint16_t gap_handle); /******************************************************************************* * @@ -201,8 +197,8 @@ extern uint16_t GAP_ConnClose (uint16_t gap_handle); * GAP_NO_DATA_AVAIL - no data available * ******************************************************************************/ -extern uint16_t GAP_ConnReadData (uint16_t gap_handle, uint8_t *p_data, - uint16_t max_len, uint16_t *p_len); +extern uint16_t GAP_ConnReadData(uint16_t gap_handle, uint8_t* p_data, + uint16_t max_len, uint16_t* p_len); /******************************************************************************* * @@ -215,7 +211,7 @@ extern uint16_t GAP_ConnReadData (uint16_t gap_handle, uint8_t *p_data, * * ******************************************************************************/ -extern int GAP_GetRxQueueCnt (uint16_t handle, uint32_t *p_rx_queue_count); +extern int GAP_GetRxQueueCnt(uint16_t handle, uint32_t* p_rx_queue_count); /******************************************************************************* * @@ -230,7 +226,7 @@ extern int GAP_GetRxQueueCnt (uint16_t handle, uint32_t *p_rx_queue_count); * GAP_NO_DATA_AVAIL - no data available * ******************************************************************************/ -extern uint16_t GAP_ConnBTRead (uint16_t gap_handle, BT_HDR **pp_buf); +extern uint16_t GAP_ConnBTRead(uint16_t gap_handle, BT_HDR** pp_buf); /******************************************************************************* * @@ -246,8 +242,8 @@ extern uint16_t GAP_ConnBTRead (uint16_t gap_handle, BT_HDR **pp_buf); * GAP_CONGESTION - system is congested * ******************************************************************************/ -extern uint16_t GAP_ConnWriteData (uint16_t gap_handle, uint8_t *p_data, - uint16_t max_len, uint16_t *p_len); +extern uint16_t GAP_ConnWriteData(uint16_t gap_handle, uint8_t* p_data, + uint16_t max_len, uint16_t* p_len); /******************************************************************************* * @@ -260,7 +256,7 @@ extern uint16_t GAP_ConnWriteData (uint16_t gap_handle, uint8_t *p_data, * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -extern uint16_t GAP_ConnReconfig (uint16_t gap_handle, tL2CAP_CFG_INFO *p_cfg); +extern uint16_t GAP_ConnReconfig(uint16_t gap_handle, tL2CAP_CFG_INFO* p_cfg); /******************************************************************************* * @@ -278,7 +274,7 @@ extern uint16_t GAP_ConnReconfig (uint16_t gap_handle, tL2CAP_CFG_INFO *p_cfg); * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -extern uint16_t GAP_ConnSetIdleTimeout (uint16_t gap_handle, uint16_t timeout); +extern uint16_t GAP_ConnSetIdleTimeout(uint16_t gap_handle, uint16_t timeout); /******************************************************************************* * @@ -291,7 +287,7 @@ extern uint16_t GAP_ConnSetIdleTimeout (uint16_t gap_handle, uint16_t timeout); * GAP_ERR_BAD_HANDLE - invalid handle * ******************************************************************************/ -extern uint8_t *GAP_ConnGetRemoteAddr (uint16_t gap_handle); +extern uint8_t* GAP_ConnGetRemoteAddr(uint16_t gap_handle); /******************************************************************************* * @@ -303,7 +299,7 @@ extern uint8_t *GAP_ConnGetRemoteAddr (uint16_t gap_handle); * the peer * ******************************************************************************/ -extern uint16_t GAP_ConnGetRemMtuSize (uint16_t gap_handle); +extern uint16_t GAP_ConnGetRemMtuSize(uint16_t gap_handle); /******************************************************************************* * @@ -317,7 +313,7 @@ extern uint16_t GAP_ConnGetRemMtuSize (uint16_t gap_handle); * 0, if error * ******************************************************************************/ -extern uint16_t GAP_ConnGetL2CAPCid (uint16_t gap_handle); +extern uint16_t GAP_ConnGetL2CAPCid(uint16_t gap_handle); /******************************************************************************* * @@ -329,7 +325,7 @@ extern uint16_t GAP_ConnGetL2CAPCid (uint16_t gap_handle); * Returns The new or current trace level * ******************************************************************************/ -extern uint8_t GAP_SetTraceLevel (uint8_t new_level); +extern uint8_t GAP_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -353,8 +349,8 @@ extern void GAP_Init(void); * Returns Nothing * ******************************************************************************/ -extern void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE *p_value); - +extern void GAP_BleAttrDBUpdate(uint16_t attr_uuid, + tGAP_BLE_ATTR_VALUE* p_value); /******************************************************************************* * @@ -366,7 +362,7 @@ extern void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE *p_value * Returns true if read started, else false if GAP is busy * ******************************************************************************/ -extern bool GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda); +extern bool GAP_BleReadPeerPrefConnParams(BD_ADDR peer_bda); /******************************************************************************* * @@ -378,8 +374,8 @@ extern bool GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda); * Returns true if request accepted * ******************************************************************************/ -extern bool GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback); - +extern bool GAP_BleReadPeerDevName(BD_ADDR peer_bda, + tGAP_BLE_CMPL_CBACK* p_cback); /******************************************************************************* * @@ -390,8 +386,8 @@ extern bool GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_ * Returns true if request accepted * ******************************************************************************/ -extern bool GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, - tGAP_BLE_CMPL_CBACK *p_cback); +extern bool GAP_BleReadPeerAddressResolutionCap(BD_ADDR peer_bda, + tGAP_BLE_CMPL_CBACK* p_cback); /******************************************************************************* * @@ -402,10 +398,10 @@ extern bool GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, * Returns true if request accepted * ******************************************************************************/ -extern bool GAP_BleCancelReadPeerDevName (BD_ADDR peer_bda); +extern bool GAP_BleCancelReadPeerDevName(BD_ADDR peer_bda); #ifdef __cplusplus } #endif -#endif /* GAP_API_H */ +#endif /* GAP_API_H */ diff --git a/stack/include/gatt_api.h b/stack/include/gatt_api.h index e12a9d78d..53cde7e84 100644 --- a/stack/include/gatt_api.h +++ b/stack/include/gatt_api.h @@ -19,8 +19,8 @@ #define GATT_API_H #include "bt_target.h" -#include "gattdefs.h" #include "btm_ble_api.h" +#include "gattdefs.h" #ifdef __cplusplus extern "C" { @@ -30,142 +30,138 @@ extern "C" { * Constants ****************************************************************************/ /* Success code and error codes */ -#define GATT_SUCCESS 0x00 -#define GATT_INVALID_HANDLE 0x01 -#define GATT_READ_NOT_PERMIT 0x02 -#define GATT_WRITE_NOT_PERMIT 0x03 -#define GATT_INVALID_PDU 0x04 -#define GATT_INSUF_AUTHENTICATION 0x05 -#define GATT_REQ_NOT_SUPPORTED 0x06 -#define GATT_INVALID_OFFSET 0x07 -#define GATT_INSUF_AUTHORIZATION 0x08 -#define GATT_PREPARE_Q_FULL 0x09 -#define GATT_NOT_FOUND 0x0a -#define GATT_NOT_LONG 0x0b -#define GATT_INSUF_KEY_SIZE 0x0c -#define GATT_INVALID_ATTR_LEN 0x0d -#define GATT_ERR_UNLIKELY 0x0e -#define GATT_INSUF_ENCRYPTION 0x0f -#define GATT_UNSUPPORT_GRP_TYPE 0x10 -#define GATT_INSUF_RESOURCE 0x11 - - -#define GATT_ILLEGAL_PARAMETER 0x87 -#define GATT_NO_RESOURCES 0x80 -#define GATT_INTERNAL_ERROR 0x81 -#define GATT_WRONG_STATE 0x82 -#define GATT_DB_FULL 0x83 -#define GATT_BUSY 0x84 -#define GATT_ERROR 0x85 -#define GATT_CMD_STARTED 0x86 -#define GATT_PENDING 0x88 -#define GATT_AUTH_FAIL 0x89 -#define GATT_MORE 0x8a -#define GATT_INVALID_CFG 0x8b -#define GATT_SERVICE_STARTED 0x8c -#define GATT_ENCRYPED_MITM GATT_SUCCESS -#define GATT_ENCRYPED_NO_MITM 0x8d -#define GATT_NOT_ENCRYPTED 0x8e -#define GATT_CONGESTED 0x8f +#define GATT_SUCCESS 0x00 +#define GATT_INVALID_HANDLE 0x01 +#define GATT_READ_NOT_PERMIT 0x02 +#define GATT_WRITE_NOT_PERMIT 0x03 +#define GATT_INVALID_PDU 0x04 +#define GATT_INSUF_AUTHENTICATION 0x05 +#define GATT_REQ_NOT_SUPPORTED 0x06 +#define GATT_INVALID_OFFSET 0x07 +#define GATT_INSUF_AUTHORIZATION 0x08 +#define GATT_PREPARE_Q_FULL 0x09 +#define GATT_NOT_FOUND 0x0a +#define GATT_NOT_LONG 0x0b +#define GATT_INSUF_KEY_SIZE 0x0c +#define GATT_INVALID_ATTR_LEN 0x0d +#define GATT_ERR_UNLIKELY 0x0e +#define GATT_INSUF_ENCRYPTION 0x0f +#define GATT_UNSUPPORT_GRP_TYPE 0x10 +#define GATT_INSUF_RESOURCE 0x11 + +#define GATT_ILLEGAL_PARAMETER 0x87 +#define GATT_NO_RESOURCES 0x80 +#define GATT_INTERNAL_ERROR 0x81 +#define GATT_WRONG_STATE 0x82 +#define GATT_DB_FULL 0x83 +#define GATT_BUSY 0x84 +#define GATT_ERROR 0x85 +#define GATT_CMD_STARTED 0x86 +#define GATT_PENDING 0x88 +#define GATT_AUTH_FAIL 0x89 +#define GATT_MORE 0x8a +#define GATT_INVALID_CFG 0x8b +#define GATT_SERVICE_STARTED 0x8c +#define GATT_ENCRYPED_MITM GATT_SUCCESS +#define GATT_ENCRYPED_NO_MITM 0x8d +#define GATT_NOT_ENCRYPTED 0x8e +#define GATT_CONGESTED 0x8f /* 0xE0 ~ 0xFC reserved for future use */ /* Client Characteristic Configuration Descriptor Improperly Configured */ -#define GATT_CCC_CFG_ERR 0xFD +#define GATT_CCC_CFG_ERR 0xFD /* Procedure Already in progress */ -#define GATT_PRC_IN_PROGRESS 0xFE +#define GATT_PRC_IN_PROGRESS 0xFE /* Attribute value out of range */ -#define GATT_OUT_OF_RANGE 0xFF +#define GATT_OUT_OF_RANGE 0xFF typedef uint8_t tGATT_STATUS; - -#define GATT_RSP_ERROR 0x01 -#define GATT_REQ_MTU 0x02 -#define GATT_RSP_MTU 0x03 -#define GATT_REQ_FIND_INFO 0x04 -#define GATT_RSP_FIND_INFO 0x05 -#define GATT_REQ_FIND_TYPE_VALUE 0x06 -#define GATT_RSP_FIND_TYPE_VALUE 0x07 -#define GATT_REQ_READ_BY_TYPE 0x08 -#define GATT_RSP_READ_BY_TYPE 0x09 -#define GATT_REQ_READ 0x0A -#define GATT_RSP_READ 0x0B -#define GATT_REQ_READ_BLOB 0x0C -#define GATT_RSP_READ_BLOB 0x0D -#define GATT_REQ_READ_MULTI 0x0E -#define GATT_RSP_READ_MULTI 0x0F -#define GATT_REQ_READ_BY_GRP_TYPE 0x10 -#define GATT_RSP_READ_BY_GRP_TYPE 0x11 +#define GATT_RSP_ERROR 0x01 +#define GATT_REQ_MTU 0x02 +#define GATT_RSP_MTU 0x03 +#define GATT_REQ_FIND_INFO 0x04 +#define GATT_RSP_FIND_INFO 0x05 +#define GATT_REQ_FIND_TYPE_VALUE 0x06 +#define GATT_RSP_FIND_TYPE_VALUE 0x07 +#define GATT_REQ_READ_BY_TYPE 0x08 +#define GATT_RSP_READ_BY_TYPE 0x09 +#define GATT_REQ_READ 0x0A +#define GATT_RSP_READ 0x0B +#define GATT_REQ_READ_BLOB 0x0C +#define GATT_RSP_READ_BLOB 0x0D +#define GATT_REQ_READ_MULTI 0x0E +#define GATT_RSP_READ_MULTI 0x0F +#define GATT_REQ_READ_BY_GRP_TYPE 0x10 +#define GATT_RSP_READ_BY_GRP_TYPE 0x11 /* 0001-0010 (write)*/ -#define GATT_REQ_WRITE 0x12 -#define GATT_RSP_WRITE 0x13 +#define GATT_REQ_WRITE 0x12 +#define GATT_RSP_WRITE 0x13 /* changed in V4.0 01001-0010(write cmd)*/ -#define GATT_CMD_WRITE 0x52 -#define GATT_REQ_PREPARE_WRITE 0x16 -#define GATT_RSP_PREPARE_WRITE 0x17 -#define GATT_REQ_EXEC_WRITE 0x18 -#define GATT_RSP_EXEC_WRITE 0x19 -#define GATT_HANDLE_VALUE_NOTIF 0x1B -#define GATT_HANDLE_VALUE_IND 0x1D -#define GATT_HANDLE_VALUE_CONF 0x1E +#define GATT_CMD_WRITE 0x52 +#define GATT_REQ_PREPARE_WRITE 0x16 +#define GATT_RSP_PREPARE_WRITE 0x17 +#define GATT_REQ_EXEC_WRITE 0x18 +#define GATT_RSP_EXEC_WRITE 0x19 +#define GATT_HANDLE_VALUE_NOTIF 0x1B +#define GATT_HANDLE_VALUE_IND 0x1D +#define GATT_HANDLE_VALUE_CONF 0x1E /* changed in V4.0 1101-0010 (signed write) see write cmd above*/ -#define GATT_SIGN_CMD_WRITE 0xD2 +#define GATT_SIGN_CMD_WRITE 0xD2 /* 0x1E = 30 + 1 = 31*/ -#define GATT_OP_CODE_MAX (GATT_HANDLE_VALUE_CONF + 1) +#define GATT_OP_CODE_MAX (GATT_HANDLE_VALUE_CONF + 1) +#define GATT_HANDLE_IS_VALID(x) ((x) != 0) -#define GATT_HANDLE_IS_VALID(x) ((x) != 0) - -#define GATT_CONN_UNKNOWN 0 +#define GATT_CONN_UNKNOWN 0 /* general L2cap failure */ -#define GATT_CONN_L2C_FAILURE 1 +#define GATT_CONN_L2C_FAILURE 1 /* 0x08 connection timeout */ -#define GATT_CONN_TIMEOUT HCI_ERR_CONNECTION_TOUT +#define GATT_CONN_TIMEOUT HCI_ERR_CONNECTION_TOUT /* 0x13 connection terminate by peer user */ -#define GATT_CONN_TERMINATE_PEER_USER HCI_ERR_PEER_USER +#define GATT_CONN_TERMINATE_PEER_USER HCI_ERR_PEER_USER /* 0x16 connectionterminated by local host */ -#define GATT_CONN_TERMINATE_LOCAL_HOST HCI_ERR_CONN_CAUSE_LOCAL_HOST +#define GATT_CONN_TERMINATE_LOCAL_HOST HCI_ERR_CONN_CAUSE_LOCAL_HOST /* 0x03E connection fail to establish */ -#define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT +#define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT /* 0x22 connection fail for LMP response tout */ -#define GATT_CONN_LMP_TIMEOUT HCI_ERR_LMP_RESPONSE_TIMEOUT +#define GATT_CONN_LMP_TIMEOUT HCI_ERR_LMP_RESPONSE_TIMEOUT /* 0x0100 L2CAP connection cancelled */ -#define GATT_CONN_CANCEL L2CAP_CONN_CANCEL +#define GATT_CONN_CANCEL L2CAP_CONN_CANCEL typedef uint16_t tGATT_DISCONN_REASON; /* MAX GATT MTU size */ #ifndef GATT_MAX_MTU_SIZE - #define GATT_MAX_MTU_SIZE 517 +#define GATT_MAX_MTU_SIZE 517 #endif /* max legth of an attribute value */ #ifndef GATT_MAX_ATTR_LEN - #define GATT_MAX_ATTR_LEN 600 +#define GATT_MAX_ATTR_LEN 600 #endif /* default GATT MTU size over LE link */ -#define GATT_DEF_BLE_MTU_SIZE 23 +#define GATT_DEF_BLE_MTU_SIZE 23 /* invalid connection ID */ -#define GATT_INVALID_CONN_ID 0xFFFF +#define GATT_INVALID_CONN_ID 0xFFFF #ifndef GATT_CL_MAX_LCB - #define GATT_CL_MAX_LCB 22 +#define GATT_CL_MAX_LCB 22 #endif #ifndef GATT_MAX_SCCB - #define GATT_MAX_SCCB 10 +#define GATT_MAX_SCCB 10 #endif - /* GATT notification caching timer, default to be three seconds */ #ifndef GATTC_NOTIF_TIMEOUT - #define GATTC_NOTIF_TIMEOUT 3 +#define GATTC_NOTIF_TIMEOUT 3 #endif /***************************************************************************** @@ -174,507 +170,477 @@ typedef uint16_t tGATT_DISCONN_REASON; /* Attribute permissions */ -#define GATT_PERM_READ (1 << 0) /* bit 0 */ -#define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */ -#define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */ -#define GATT_PERM_WRITE (1 << 4) /* bit 4 */ -#define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */ -#define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */ -#define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */ +#define GATT_PERM_READ (1 << 0) /* bit 0 */ +#define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */ +#define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */ +#define GATT_PERM_WRITE (1 << 4) /* bit 4 */ +#define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */ +#define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */ +#define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */ #define GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 */ typedef uint16_t tGATT_PERM; /* the MS nibble of tGATT_PERM; key size 7=0; size 16=9 */ -#define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000) +#define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000) -#define GATT_READ_ALLOWED (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) -#define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED) -#define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM) -#define GATT_READ_ENCRYPTED_REQUIRED (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) +#define GATT_READ_ALLOWED \ + (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) +#define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED) +#define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM) +#define GATT_READ_ENCRYPTED_REQUIRED \ + (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM) +#define GATT_WRITE_ALLOWED \ + (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \ + GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) -#define GATT_WRITE_ALLOWED (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \ - GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) +#define GATT_WRITE_AUTH_REQUIRED \ + (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED) -#define GATT_WRITE_AUTH_REQUIRED (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED) +#define GATT_WRITE_MITM_REQUIRED \ + (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM) -#define GATT_WRITE_MITM_REQUIRED (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM) - -#define GATT_WRITE_ENCRYPTED_PERM (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM) - -#define GATT_WRITE_SIGNED_PERM (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) +#define GATT_WRITE_ENCRYPTED_PERM \ + (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM) +#define GATT_WRITE_SIGNED_PERM \ + (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM) /* Characteristic properties */ -#define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) -#define GATT_CHAR_PROP_BIT_READ (1 << 1) -#define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) -#define GATT_CHAR_PROP_BIT_WRITE (1 << 3) -#define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) -#define GATT_CHAR_PROP_BIT_INDICATE (1 << 5) -#define GATT_CHAR_PROP_BIT_AUTH (1 << 6) -#define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) +#define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) +#define GATT_CHAR_PROP_BIT_READ (1 << 1) +#define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) +#define GATT_CHAR_PROP_BIT_WRITE (1 << 3) +#define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) +#define GATT_CHAR_PROP_BIT_INDICATE (1 << 5) +#define GATT_CHAR_PROP_BIT_AUTH (1 << 6) +#define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) typedef uint8_t tGATT_CHAR_PROP; - /* Format of the value of a characteristic. enumeration type */ -enum -{ - GATT_FORMAT_RES, /* rfu */ - GATT_FORMAT_BOOL, /* 0x01 boolean */ - GATT_FORMAT_2BITS, /* 0x02 2 bit */ - GATT_FORMAT_NIBBLE, /* 0x03 nibble */ - GATT_FORMAT_UINT8, /* 0x04 uint8 */ - GATT_FORMAT_UINT12, /* 0x05 uint12 */ - GATT_FORMAT_UINT16, /* 0x06 uint16 */ - GATT_FORMAT_UINT24, /* 0x07 uint24 */ - GATT_FORMAT_UINT32, /* 0x08 uint32 */ - GATT_FORMAT_UINT48, /* 0x09 uint48 */ - GATT_FORMAT_UINT64, /* 0x0a uint64 */ - GATT_FORMAT_UINT128, /* 0x0B uint128 */ - GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */ - GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */ - GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */ - GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */ - GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */ - GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */ - GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */ - GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */ - GATT_FORMAT_FLOAT32, /* 0x14 float 32 */ - GATT_FORMAT_FLOAT64, /* 0x15 float 64*/ - GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */ - GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */ - GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */ - GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */ - GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */ - GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/ - GATT_FORMAT_MAX /* 0x1c or above reserved */ +enum { + GATT_FORMAT_RES, /* rfu */ + GATT_FORMAT_BOOL, /* 0x01 boolean */ + GATT_FORMAT_2BITS, /* 0x02 2 bit */ + GATT_FORMAT_NIBBLE, /* 0x03 nibble */ + GATT_FORMAT_UINT8, /* 0x04 uint8 */ + GATT_FORMAT_UINT12, /* 0x05 uint12 */ + GATT_FORMAT_UINT16, /* 0x06 uint16 */ + GATT_FORMAT_UINT24, /* 0x07 uint24 */ + GATT_FORMAT_UINT32, /* 0x08 uint32 */ + GATT_FORMAT_UINT48, /* 0x09 uint48 */ + GATT_FORMAT_UINT64, /* 0x0a uint64 */ + GATT_FORMAT_UINT128, /* 0x0B uint128 */ + GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */ + GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */ + GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */ + GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */ + GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */ + GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */ + GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */ + GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */ + GATT_FORMAT_FLOAT32, /* 0x14 float 32 */ + GATT_FORMAT_FLOAT64, /* 0x15 float 64*/ + GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */ + GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */ + GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */ + GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */ + GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */ + GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/ + GATT_FORMAT_MAX /* 0x1c or above reserved */ }; typedef uint8_t tGATT_FORMAT; /* Characteristic Presentation Format Descriptor value */ -typedef struct -{ - uint16_t unit; /* as UUIUD defined by SIG */ - uint16_t descr; /* as UUID as defined by SIG */ - tGATT_FORMAT format; - int8_t exp; - uint8_t name_spc; /* The name space of the description */ +typedef struct { + uint16_t unit; /* as UUIUD defined by SIG */ + uint16_t descr; /* as UUID as defined by SIG */ + tGATT_FORMAT format; + int8_t exp; + uint8_t name_spc; /* The name space of the description */ } tGATT_CHAR_PRES; /* Characteristic Report reference Descriptor format */ -typedef struct -{ - uint8_t rpt_id; /* report ID */ - uint8_t rpt_type; /* report type */ +typedef struct { + uint8_t rpt_id; /* report ID */ + uint8_t rpt_type; /* report type */ } tGATT_CHAR_RPT_REF; - -#define GATT_VALID_RANGE_MAX_SIZE 16 -typedef struct -{ - uint8_t format; - uint16_t len; - uint8_t lower_range[GATT_VALID_RANGE_MAX_SIZE]; /* in little endian format */ - uint8_t upper_range[GATT_VALID_RANGE_MAX_SIZE]; +#define GATT_VALID_RANGE_MAX_SIZE 16 +typedef struct { + uint8_t format; + uint16_t len; + uint8_t lower_range[GATT_VALID_RANGE_MAX_SIZE]; /* in little endian format */ + uint8_t upper_range[GATT_VALID_RANGE_MAX_SIZE]; } tGATT_VALID_RANGE; /* Characteristic Aggregate Format attribute value */ -#define GATT_AGGR_HANDLE_NUM_MAX 10 -typedef struct -{ - uint8_t num_handle; - uint16_t handle_list[GATT_AGGR_HANDLE_NUM_MAX]; +#define GATT_AGGR_HANDLE_NUM_MAX 10 +typedef struct { + uint8_t num_handle; + uint16_t handle_list[GATT_AGGR_HANDLE_NUM_MAX]; } tGATT_CHAR_AGGRE; /* Characteristic descriptor: Extended Properties value */ /* permits reliable writes of the Characteristic Value */ -#define GATT_CHAR_BIT_REL_WRITE 0x0001 +#define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits writes to the characteristic descriptor */ -#define GATT_CHAR_BIT_WRITE_AUX 0x0002 - +#define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* characteristic descriptor: client configuration value */ -#define GATT_CLT_CONFIG_NONE 0x0000 -#define GATT_CLT_CONFIG_NOTIFICATION 0x0001 -#define GATT_CLT_CONFIG_INDICATION 0x0002 +#define GATT_CLT_CONFIG_NONE 0x0000 +#define GATT_CLT_CONFIG_NOTIFICATION 0x0001 +#define GATT_CLT_CONFIG_INDICATION 0x0002 typedef uint16_t tGATT_CLT_CHAR_CONFIG; - /* characteristic descriptor: server configuration value */ -#define GATT_SVR_CONFIG_NONE 0x0000 -#define GATT_SVR_CONFIG_BROADCAST 0x0001 +#define GATT_SVR_CONFIG_NONE 0x0000 +#define GATT_SVR_CONFIG_BROADCAST 0x0001 typedef uint16_t tGATT_SVR_CHAR_CONFIG; /* Characteristic descriptor: Extended Properties value */ /* permits reliable writes of the Characteristic Value */ -#define GATT_CHAR_BIT_REL_WRITE 0x0001 +#define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits writes to the characteristic descriptor */ -#define GATT_CHAR_BIT_WRITE_AUX 0x0002 +#define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* authentication requirement */ -#define GATT_AUTH_REQ_NONE 0 -#define GATT_AUTH_REQ_NO_MITM 1 /* unauthenticated encryption */ -#define GATT_AUTH_REQ_MITM 2 /* authenticated encryption */ -#define GATT_AUTH_REQ_SIGNED_NO_MITM 3 -#define GATT_AUTH_REQ_SIGNED_MITM 4 +#define GATT_AUTH_REQ_NONE 0 +#define GATT_AUTH_REQ_NO_MITM 1 /* unauthenticated encryption */ +#define GATT_AUTH_REQ_MITM 2 /* authenticated encryption */ +#define GATT_AUTH_REQ_SIGNED_NO_MITM 3 +#define GATT_AUTH_REQ_SIGNED_MITM 4 typedef uint8_t tGATT_AUTH_REQ; /* Attribute Value structure */ -typedef struct -{ - uint16_t conn_id; - uint16_t handle; /* attribute handle */ - uint16_t offset; /* attribute value offset, if no offfset is needed for the command, ignore it */ - uint16_t len; /* length of attribute value */ - tGATT_AUTH_REQ auth_req; /* authentication request */ - uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ +typedef struct { + uint16_t conn_id; + uint16_t handle; /* attribute handle */ + uint16_t offset; /* attribute value offset, if no offfset is needed for the + command, ignore it */ + uint16_t len; /* length of attribute value */ + tGATT_AUTH_REQ auth_req; /* authentication request */ + uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ } tGATT_VALUE; /* Union of the event data which is used in the server respond API to carry the * server response information */ -typedef union -{ - /* data type member event */ - tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ - /* READ_BLOB, READ_BY_TYPE */ - uint16_t handle; /* WRITE, WRITE_BLOB */ +typedef union { + /* data type member event */ + tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */ + /* READ_BLOB, READ_BY_TYPE */ + uint16_t handle; /* WRITE, WRITE_BLOB */ } tGATTS_RSP; /* Transports for the primary service */ -#define GATT_TRANSPORT_LE BT_TRANSPORT_LE -#define GATT_TRANSPORT_BR_EDR BT_TRANSPORT_BR_EDR -#define GATT_TRANSPORT_LE_BR_EDR (BT_TRANSPORT_LE|BT_TRANSPORT_BR_EDR) +#define GATT_TRANSPORT_LE BT_TRANSPORT_LE +#define GATT_TRANSPORT_BR_EDR BT_TRANSPORT_BR_EDR +#define GATT_TRANSPORT_LE_BR_EDR (BT_TRANSPORT_LE | BT_TRANSPORT_BR_EDR) typedef uint8_t tGATT_TRANSPORT; -#define GATT_PREP_WRITE_CANCEL 0x00 -#define GATT_PREP_WRITE_EXEC 0x01 +#define GATT_PREP_WRITE_CANCEL 0x00 +#define GATT_PREP_WRITE_EXEC 0x01 typedef uint8_t tGATT_EXEC_FLAG; /* read request always based on UUID */ -typedef struct -{ - uint16_t handle; - uint16_t offset; - bool is_long; - bt_gatt_db_attribute_type_t gatt_type; /* are we writing characteristic or descriptor */ +typedef struct { + uint16_t handle; + uint16_t offset; + bool is_long; + bt_gatt_db_attribute_type_t + gatt_type; /* are we writing characteristic or descriptor */ } tGATT_READ_REQ; /* write request data */ -typedef struct -{ - uint16_t handle; /* attribute handle */ - uint16_t offset; /* attribute value offset, if no offfset is needed for the command, ignore it */ - uint16_t len; /* length of attribute value */ - uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ - bool need_rsp; /* need write response */ - bool is_prep; /* is prepare write */ - bt_gatt_db_attribute_type_t gatt_type; /* are we writing characteristic or descriptor */ +typedef struct { + uint16_t handle; /* attribute handle */ + uint16_t offset; /* attribute value offset, if no offfset is needed for the + command, ignore it */ + uint16_t len; /* length of attribute value */ + uint8_t value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */ + bool need_rsp; /* need write response */ + bool is_prep; /* is prepare write */ + bt_gatt_db_attribute_type_t + gatt_type; /* are we writing characteristic or descriptor */ } tGATT_WRITE_REQ; /* callback data for server access request from client */ -typedef union -{ - tGATT_READ_REQ read_req; /* read request, read by Type, read blob */ - - tGATT_WRITE_REQ write_req; /* write */ - /* prepare write */ - /* write blob */ - uint16_t handle; /* handle value confirmation */ - uint16_t mtu; /* MTU exchange request */ - tGATT_EXEC_FLAG exec_write; /* execute write */ +typedef union { + tGATT_READ_REQ read_req; /* read request, read by Type, read blob */ + + tGATT_WRITE_REQ write_req; /* write */ + /* prepare write */ + /* write blob */ + uint16_t handle; /* handle value confirmation */ + uint16_t mtu; /* MTU exchange request */ + tGATT_EXEC_FLAG exec_write; /* execute write */ } tGATTS_DATA; -typedef uint8_t tGATT_SERV_IF; /* GATT Service Interface */ - -enum -{ - GATTS_REQ_TYPE_READ_CHARACTERISTIC = 1, /* Char read request */ - GATTS_REQ_TYPE_READ_DESCRIPTOR, /* Desc read request */ - GATTS_REQ_TYPE_WRITE_CHARACTERISTIC, /* Char write request */ - GATTS_REQ_TYPE_WRITE_DESCRIPTOR, /* Desc write request */ - GATTS_REQ_TYPE_WRITE_EXEC, /* Execute write */ - GATTS_REQ_TYPE_MTU, /* MTU exchange information */ - GATTS_REQ_TYPE_CONF /* handle value confirmation */ +typedef uint8_t tGATT_SERV_IF; /* GATT Service Interface */ + +enum { + GATTS_REQ_TYPE_READ_CHARACTERISTIC = 1, /* Char read request */ + GATTS_REQ_TYPE_READ_DESCRIPTOR, /* Desc read request */ + GATTS_REQ_TYPE_WRITE_CHARACTERISTIC, /* Char write request */ + GATTS_REQ_TYPE_WRITE_DESCRIPTOR, /* Desc write request */ + GATTS_REQ_TYPE_WRITE_EXEC, /* Execute write */ + GATTS_REQ_TYPE_MTU, /* MTU exchange information */ + GATTS_REQ_TYPE_CONF /* handle value confirmation */ }; typedef uint8_t tGATTS_REQ_TYPE; - - /* Client Used Data Structure */ /* definition of different discovery types */ -enum -{ - GATT_DISC_SRVC_ALL = 1, /* discover all services */ - GATT_DISC_SRVC_BY_UUID, /* discover service of a special type */ - GATT_DISC_INC_SRVC, /* discover the included service within a service */ - GATT_DISC_CHAR, /* discover characteristics of a service with/without type requirement */ - GATT_DISC_CHAR_DSCPT, /* discover characteristic descriptors of a character */ - GATT_DISC_MAX /* maximnun discover type */ +enum { + GATT_DISC_SRVC_ALL = 1, /* discover all services */ + GATT_DISC_SRVC_BY_UUID, /* discover service of a special type */ + GATT_DISC_INC_SRVC, /* discover the included service within a service */ + GATT_DISC_CHAR, /* discover characteristics of a service with/without type + requirement */ + GATT_DISC_CHAR_DSCPT, /* discover characteristic descriptors of a character */ + GATT_DISC_MAX /* maximnun discover type */ }; typedef uint8_t tGATT_DISC_TYPE; /* Discover parameters of different discovery types */ -typedef struct -{ - tBT_UUID service; - uint16_t s_handle; - uint16_t e_handle; -}tGATT_DISC_PARAM; +typedef struct { + tBT_UUID service; + uint16_t s_handle; + uint16_t e_handle; +} tGATT_DISC_PARAM; /* GATT read type enumeration */ -enum -{ - GATT_READ_BY_TYPE = 1, - GATT_READ_BY_HANDLE, - GATT_READ_MULTIPLE, - GATT_READ_CHAR_VALUE, - GATT_READ_PARTIAL, - GATT_READ_MAX +enum { + GATT_READ_BY_TYPE = 1, + GATT_READ_BY_HANDLE, + GATT_READ_MULTIPLE, + GATT_READ_CHAR_VALUE, + GATT_READ_PARTIAL, + GATT_READ_MAX }; typedef uint8_t tGATT_READ_TYPE; /* Read By Type Request (GATT_READ_BY_TYPE) Data */ -typedef struct -{ - tGATT_AUTH_REQ auth_req; - uint16_t s_handle; - uint16_t e_handle; - tBT_UUID uuid; +typedef struct { + tGATT_AUTH_REQ auth_req; + uint16_t s_handle; + uint16_t e_handle; + tBT_UUID uuid; } tGATT_READ_BY_TYPE; /* GATT_READ_MULTIPLE request data */ -#define GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */ -typedef struct -{ - tGATT_AUTH_REQ auth_req; - uint16_t num_handles; /* number of handles to read */ - uint16_t handles[GATT_MAX_READ_MULTI_HANDLES]; /* handles list to be read */ +#define GATT_MAX_READ_MULTI_HANDLES \ + 10 /* Max attributes to read in one request */ +typedef struct { + tGATT_AUTH_REQ auth_req; + uint16_t num_handles; /* number of handles to read */ + uint16_t handles[GATT_MAX_READ_MULTI_HANDLES]; /* handles list to be read */ } tGATT_READ_MULTI; /* Read By Handle Request (GATT_READ_BY_HANDLE) data */ -typedef struct -{ - tGATT_AUTH_REQ auth_req; - uint16_t handle; +typedef struct { + tGATT_AUTH_REQ auth_req; + uint16_t handle; } tGATT_READ_BY_HANDLE; /* READ_BT_HANDLE_Request data */ -typedef struct -{ - tGATT_AUTH_REQ auth_req; - uint16_t handle; - uint16_t offset; +typedef struct { + tGATT_AUTH_REQ auth_req; + uint16_t handle; + uint16_t offset; } tGATT_READ_PARTIAL; /* Read Request Data */ -typedef union -{ - tGATT_READ_BY_TYPE service; - tGATT_READ_BY_TYPE char_type; /* characterisitc type */ - tGATT_READ_MULTI read_multiple; - tGATT_READ_BY_HANDLE by_handle; - tGATT_READ_PARTIAL partial; +typedef union { + tGATT_READ_BY_TYPE service; + tGATT_READ_BY_TYPE char_type; /* characterisitc type */ + tGATT_READ_MULTI read_multiple; + tGATT_READ_BY_HANDLE by_handle; + tGATT_READ_PARTIAL partial; } tGATT_READ_PARAM; /* GATT write type enumeration */ -enum -{ - GATT_WRITE_NO_RSP = 1, - GATT_WRITE , - GATT_WRITE_PREPARE -}; +enum { GATT_WRITE_NO_RSP = 1, GATT_WRITE, GATT_WRITE_PREPARE }; typedef uint8_t tGATT_WRITE_TYPE; /* Client Operation Complete Callback Data */ -typedef union -{ - tGATT_VALUE att_value; - uint16_t mtu; - uint16_t handle; +typedef union { + tGATT_VALUE att_value; + uint16_t mtu; + uint16_t handle; } tGATT_CL_COMPLETE; /* GATT client operation type, used in client callback function */ -#define GATTC_OPTYPE_NONE 0 -#define GATTC_OPTYPE_DISCOVERY 1 -#define GATTC_OPTYPE_READ 2 -#define GATTC_OPTYPE_WRITE 3 -#define GATTC_OPTYPE_EXE_WRITE 4 -#define GATTC_OPTYPE_CONFIG 5 -#define GATTC_OPTYPE_NOTIFICATION 6 -#define GATTC_OPTYPE_INDICATION 7 +#define GATTC_OPTYPE_NONE 0 +#define GATTC_OPTYPE_DISCOVERY 1 +#define GATTC_OPTYPE_READ 2 +#define GATTC_OPTYPE_WRITE 3 +#define GATTC_OPTYPE_EXE_WRITE 4 +#define GATTC_OPTYPE_CONFIG 5 +#define GATTC_OPTYPE_NOTIFICATION 6 +#define GATTC_OPTYPE_INDICATION 7 typedef uint8_t tGATTC_OPTYPE; /* characteristic declaration */ -typedef struct -{ - tGATT_CHAR_PROP char_prop; /* characterisitc properties */ - uint16_t val_handle; /* characteristic value attribute handle */ - tBT_UUID char_uuid; /* characteristic UUID type */ +typedef struct { + tGATT_CHAR_PROP char_prop; /* characterisitc properties */ + uint16_t val_handle; /* characteristic value attribute handle */ + tBT_UUID char_uuid; /* characteristic UUID type */ } tGATT_CHAR_DCLR_VAL; /* primary service group data */ -typedef struct -{ - uint16_t e_handle; /* ending handle of the group */ - tBT_UUID service_type; /* group type */ +typedef struct { + uint16_t e_handle; /* ending handle of the group */ + tBT_UUID service_type; /* group type */ } tGATT_GROUP_VALUE; - /* included service attribute value */ -typedef struct -{ - tBT_UUID service_type; /* included service UUID */ - uint16_t s_handle; /* starting handle */ - uint16_t e_handle; /* ending handle */ +typedef struct { + tBT_UUID service_type; /* included service UUID */ + uint16_t s_handle; /* starting handle */ + uint16_t e_handle; /* ending handle */ } tGATT_INCL_SRVC; -typedef union -{ - tGATT_INCL_SRVC incl_service; /* include service value */ - tGATT_GROUP_VALUE group_value; /* Service UUID type. - This field is used with GATT_DISC_SRVC_ALL - or GATT_DISC_SRVC_BY_UUID - type of discovery result callback. */ +typedef union { + tGATT_INCL_SRVC incl_service; /* include service value */ + tGATT_GROUP_VALUE group_value; /* Service UUID type. + This field is used with GATT_DISC_SRVC_ALL + or GATT_DISC_SRVC_BY_UUID + type of discovery result callback. */ - uint16_t handle; /* When used with GATT_DISC_INC_SRVC type discovery result, - it is the included service starting handle.*/ + uint16_t handle; /* When used with GATT_DISC_INC_SRVC type discovery result, + it is the included service starting handle.*/ - tGATT_CHAR_DCLR_VAL dclr_value; /* Characteristic declaration value. - This field is used with GATT_DISC_CHAR type discovery.*/ + tGATT_CHAR_DCLR_VAL + dclr_value; /* Characteristic declaration value. + This field is used with GATT_DISC_CHAR type discovery.*/ } tGATT_DISC_VALUE; /* discover result record */ -typedef struct -{ - tBT_UUID type; - uint16_t handle; - tGATT_DISC_VALUE value; +typedef struct { + tBT_UUID type; + uint16_t handle; + tGATT_DISC_VALUE value; } tGATT_DISC_RES; +#define GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP \ + 1 /* start a idle timer for this duration \ + when no application need to use the link */ -#define GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP 1 /* start a idle timer for this duration - when no application need to use the link */ +#define GATT_LINK_NO_IDLE_TIMEOUT 0xFFFF -#define GATT_LINK_NO_IDLE_TIMEOUT 0xFFFF - -#define GATT_INVALID_ACL_HANDLE 0xFFFF +#define GATT_INVALID_ACL_HANDLE 0xFFFF /* discover result callback function */ -typedef void (tGATT_DISC_RES_CB) (uint16_t conn_id, tGATT_DISC_TYPE disc_type, - tGATT_DISC_RES *p_data); +typedef void(tGATT_DISC_RES_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_RES* p_data); /* discover complete callback function */ -typedef void (tGATT_DISC_CMPL_CB) (uint16_t conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status); +typedef void(tGATT_DISC_CMPL_CB)(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_STATUS status); /* Define a callback function for when read/write/disc/config operation is * completed. */ -typedef void (tGATT_CMPL_CBACK) (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, - tGATT_CL_COMPLETE *p_data); +typedef void(tGATT_CMPL_CBACK)(uint16_t conn_id, tGATTC_OPTYPE op, + tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); /* Define a callback function when an initialized connection is established. */ -typedef void (tGATT_CONN_CBACK) (tGATT_IF gatt_if, BD_ADDR bda, uint16_t conn_id, bool connected, - tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); +typedef void(tGATT_CONN_CBACK)(tGATT_IF gatt_if, BD_ADDR bda, uint16_t conn_id, + bool connected, tGATT_DISCONN_REASON reason, + tBT_TRANSPORT transport); /* attribute request callback for ATT server */ -typedef void (tGATT_REQ_CBACK )(uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, - tGATTS_DATA *p_data); +typedef void(tGATT_REQ_CBACK)(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE type, tGATTS_DATA* p_data); /* channel congestion/uncongestion callback */ -typedef void (tGATT_CONGESTION_CBACK )(uint16_t conn_id, bool congested); +typedef void(tGATT_CONGESTION_CBACK)(uint16_t conn_id, bool congested); /* Define a callback function when encryption is established. */ -typedef void (tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda); - +typedef void(tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda); /* Define the structure that applications use to register with * GATT. This structure includes callback functions. All functions * MUST be provided. */ -typedef struct -{ - tGATT_CONN_CBACK *p_conn_cb; - tGATT_CMPL_CBACK *p_cmpl_cb; - tGATT_DISC_RES_CB *p_disc_res_cb; - tGATT_DISC_CMPL_CB *p_disc_cmpl_cb; - tGATT_REQ_CBACK *p_req_cb; - tGATT_ENC_CMPL_CB *p_enc_cmpl_cb; - tGATT_CONGESTION_CBACK *p_congestion_cb; +typedef struct { + tGATT_CONN_CBACK* p_conn_cb; + tGATT_CMPL_CBACK* p_cmpl_cb; + tGATT_DISC_RES_CB* p_disc_res_cb; + tGATT_DISC_CMPL_CB* p_disc_cmpl_cb; + tGATT_REQ_CBACK* p_req_cb; + tGATT_ENC_CMPL_CB* p_enc_cmpl_cb; + tGATT_CONGESTION_CBACK* p_congestion_cb; } tGATT_CBACK; /***************** Start Handle Management Definitions *********************/ -typedef struct -{ - tBT_UUID app_uuid128; - tBT_UUID svc_uuid; - uint16_t s_handle; - uint16_t e_handle; - bool is_primary; /* primary service or secondary */ +typedef struct { + tBT_UUID app_uuid128; + tBT_UUID svc_uuid; + uint16_t s_handle; + uint16_t e_handle; + bool is_primary; /* primary service or secondary */ } tGATTS_HNDL_RANGE; - - -#define GATTS_SRV_CHG_CMD_ADD_CLIENT 1 -#define GATTS_SRV_CHG_CMD_UPDATE_CLIENT 2 -#define GATTS_SRV_CHG_CMD_REMOVE_CLIENT 3 -#define GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 4 -#define GATTS_SRV_CHG_CMD_READ_CLENT 5 +#define GATTS_SRV_CHG_CMD_ADD_CLIENT 1 +#define GATTS_SRV_CHG_CMD_UPDATE_CLIENT 2 +#define GATTS_SRV_CHG_CMD_REMOVE_CLIENT 3 +#define GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 4 +#define GATTS_SRV_CHG_CMD_READ_CLENT 5 typedef uint8_t tGATTS_SRV_CHG_CMD; -typedef struct -{ - BD_ADDR bda; - bool srv_changed; +typedef struct { + BD_ADDR bda; + bool srv_changed; } tGATTS_SRV_CHG; - -typedef union -{ - tGATTS_SRV_CHG srv_chg; - uint8_t client_read_index; /* only used for sequential reading client srv chg info */ +typedef union { + tGATTS_SRV_CHG srv_chg; + uint8_t client_read_index; /* only used for sequential reading client srv chg + info */ } tGATTS_SRV_CHG_REQ; -typedef union -{ - tGATTS_SRV_CHG srv_chg; - uint8_t num_clients; +typedef union { + tGATTS_SRV_CHG srv_chg; + uint8_t num_clients; } tGATTS_SRV_CHG_RSP; /* Attibute server handle ranges NV storage callback functions */ -typedef void (tGATTS_NV_SAVE_CBACK)(bool is_saved, tGATTS_HNDL_RANGE *p_hndl_range); -typedef bool (tGATTS_NV_SRV_CHG_CBACK)(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req, - tGATTS_SRV_CHG_RSP *p_rsp); - -typedef struct -{ - tGATTS_NV_SAVE_CBACK *p_nv_save_callback; - tGATTS_NV_SRV_CHG_CBACK *p_srv_chg_callback; +typedef void(tGATTS_NV_SAVE_CBACK)(bool is_saved, + tGATTS_HNDL_RANGE* p_hndl_range); +typedef bool(tGATTS_NV_SRV_CHG_CBACK)(tGATTS_SRV_CHG_CMD cmd, + tGATTS_SRV_CHG_REQ* p_req, + tGATTS_SRV_CHG_RSP* p_rsp); + +typedef struct { + tGATTS_NV_SAVE_CBACK* p_nv_save_callback; + tGATTS_NV_SRV_CHG_CBACK* p_srv_chg_callback; } tGATT_APPL_INFO; /******************** End Handle Management Definitions ********************/ @@ -693,8 +659,7 @@ typedef struct * Returns The new or current trace level * ******************************************************************************/ -extern uint8_t GATT_SetTraceLevel (uint8_t new_level); - +extern uint8_t GATT_SetTraceLevel(uint8_t new_level); /******************************************************************************/ /* GATT Profile API Functions */ @@ -715,7 +680,7 @@ extern uint8_t GATT_SetTraceLevel (uint8_t new_level); * ******************************************************************************/ -extern bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range); +extern bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE* p_hndl_range); /******************************************************************************* * @@ -730,11 +695,11 @@ extern bool GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range); * Returns true if registered OK, else false * ******************************************************************************/ -extern bool GATTS_NVRegister (tGATT_APPL_INFO *p_cb_info); +extern bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info); /* Converts 16bit uuid to bt_uuid_t that can be used when adding * service/characteristic/descriptor with GATTS_AddService */ -void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16); +void uuid_128_from_16(bt_uuid_t* uuid, uint16_t uuid16); /******************************************************************************* * @@ -753,7 +718,8 @@ void uuid_128_from_16(bt_uuid_t *uuid, uint16_t uuid16); * on error error status is returned. * ******************************************************************************/ -extern uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t *service, int count); +extern uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t* service, + int count); /******************************************************************************* * @@ -769,8 +735,8 @@ extern uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t *service, * Returns true if operation succeed, else false * ******************************************************************************/ -extern bool GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, uint16_t svc_inst); - +extern bool GATTS_DeleteService(tGATT_IF gatt_if, tBT_UUID* p_svc_uuid, + uint16_t svc_inst); /******************************************************************************* * @@ -783,8 +749,7 @@ extern bool GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid, uint16_ * Returns None. * ******************************************************************************/ -extern void GATTS_StopService (uint16_t service_handle); - +extern void GATTS_StopService(uint16_t service_handle); /******************************************************************************* * @@ -802,9 +767,10 @@ extern void GATTS_StopService (uint16_t service_handle); * code. * ******************************************************************************/ -extern tGATT_STATUS GATTS_HandleValueIndication (uint16_t conn_id, - uint16_t attr_handle, - uint16_t val_len, uint8_t *p_val); +extern tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, + uint16_t attr_handle, + uint16_t val_len, + uint8_t* p_val); /******************************************************************************* * @@ -821,9 +787,10 @@ extern tGATT_STATUS GATTS_HandleValueIndication (uint16_t conn_id, * Returns GATT_SUCCESS if sucessfully sent; otherwise error code. * ******************************************************************************/ -extern tGATT_STATUS GATTS_HandleValueNotification (uint16_t conn_id, uint16_t attr_handle, - uint16_t val_len, uint8_t *p_val); - +extern tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id, + uint16_t attr_handle, + uint16_t val_len, + uint8_t* p_val); /******************************************************************************* * @@ -839,9 +806,8 @@ extern tGATT_STATUS GATTS_HandleValueNotification (uint16_t conn_id, uint16_t a * Returns GATT_SUCCESS if sucessfully sent; otherwise error code. * ******************************************************************************/ -extern tGATT_STATUS GATTS_SendRsp (uint16_t conn_id, uint32_t trans_id, - tGATT_STATUS status, tGATTS_RSP *p_msg); - +extern tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id, + tGATT_STATUS status, tGATTS_RSP* p_msg); /******************************************************************************/ /* GATT Profile Client Functions */ @@ -860,7 +826,7 @@ extern tGATT_STATUS GATTS_SendRsp (uint16_t conn_id, uint32_t trans_id, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_ConfigureMTU (uint16_t conn_id, uint16_t mtu); +extern tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu); /******************************************************************************* * @@ -876,9 +842,8 @@ extern tGATT_STATUS GATTC_ConfigureMTU (uint16_t conn_id, uint16_t mtu); * Returns GATT_SUCCESS if command received/sent successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_Discover (uint16_t conn_id, - tGATT_DISC_TYPE disc_type, - tGATT_DISC_PARAM *p_param ); +extern tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type, + tGATT_DISC_PARAM* p_param); /******************************************************************************* * * Function GATTC_Read @@ -893,8 +858,8 @@ extern tGATT_STATUS GATTC_Discover (uint16_t conn_id, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_Read (uint16_t conn_id, tGATT_READ_TYPE type, - tGATT_READ_PARAM *p_read); +extern tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type, + tGATT_READ_PARAM* p_read); /******************************************************************************* * @@ -910,9 +875,8 @@ extern tGATT_STATUS GATTC_Read (uint16_t conn_id, tGATT_READ_TYPE type, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_Write (uint16_t conn_id, tGATT_WRITE_TYPE type, - tGATT_VALUE *p_write); - +extern tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type, + tGATT_VALUE* p_write); /******************************************************************************* * @@ -928,7 +892,7 @@ extern tGATT_STATUS GATTC_Write (uint16_t conn_id, tGATT_WRITE_TYPE type, * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_ExecuteWrite (uint16_t conn_id, bool is_execute); +extern tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute); /******************************************************************************* * @@ -943,8 +907,8 @@ extern tGATT_STATUS GATTC_ExecuteWrite (uint16_t conn_id, bool is_execute); * Returns GATT_SUCCESS if command started successfully. * ******************************************************************************/ -extern tGATT_STATUS GATTC_SendHandleValueConfirm (uint16_t conn_id, uint16_t handle); - +extern tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, + uint16_t handle); /******************************************************************************* * @@ -960,9 +924,8 @@ extern tGATT_STATUS GATTC_SendHandleValueConfirm (uint16_t conn_id, uint16_t han * Returns void * ******************************************************************************/ -extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, uint16_t idle_tout, - tGATT_TRANSPORT transport); - +extern void GATT_SetIdleTimeout(BD_ADDR bd_addr, uint16_t idle_tout, + tGATT_TRANSPORT transport); /******************************************************************************* * @@ -978,7 +941,7 @@ extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, uint16_t idle_tout, * with GATT * ******************************************************************************/ -extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info); +extern tGATT_IF GATT_Register(tBT_UUID* p_app_uuid128, tGATT_CBACK* p_cb_info); /******************************************************************************* * @@ -991,7 +954,7 @@ extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info) * Returns None. * ******************************************************************************/ -extern void GATT_Deregister (tGATT_IF gatt_if); +extern void GATT_Deregister(tGATT_IF gatt_if); /******************************************************************************* * @@ -1006,7 +969,7 @@ extern void GATT_Deregister (tGATT_IF gatt_if); * Returns None * ******************************************************************************/ -extern void GATT_StartIf (tGATT_IF gatt_if); +extern void GATT_StartIf(tGATT_IF gatt_if); /******************************************************************************* * @@ -1028,10 +991,8 @@ extern void GATT_StartIf (tGATT_IF gatt_if); * Returns true if connection started; else false * ******************************************************************************/ -extern bool GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, - bool is_direct, tBT_TRANSPORT transport, - bool opportunistic); - +extern bool GATT_Connect(tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct, + tBT_TRANSPORT transport, bool opportunistic); /******************************************************************************* * @@ -1050,8 +1011,8 @@ extern bool GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, * Returns true if connection started; else false * ******************************************************************************/ -extern bool GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr, - bool is_direct); +extern bool GATT_CancelConnect(tGATT_IF gatt_if, BD_ADDR bd_addr, + bool is_direct); /******************************************************************************* * @@ -1064,9 +1025,7 @@ extern bool GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr, * Returns GATT_SUCCESS if disconnected. * ******************************************************************************/ -extern tGATT_STATUS GATT_Disconnect (uint16_t conn_id); - - +extern tGATT_STATUS GATT_Disconnect(uint16_t conn_id); /******************************************************************************* * @@ -1084,9 +1043,9 @@ extern tGATT_STATUS GATT_Disconnect (uint16_t conn_id); * Returns true the ligical link information is found for conn_id * ******************************************************************************/ -extern bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF *p_gatt_if, - BD_ADDR bd_addr, tBT_TRANSPORT *p_transport); - +extern bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, + BD_ADDR bd_addr, + tBT_TRANSPORT* p_transport); /******************************************************************************* * @@ -1104,8 +1063,9 @@ extern bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF *p_gatt_if, * Returns true the ligical link is connected * ******************************************************************************/ -extern bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, - uint16_t *p_conn_id, tBT_TRANSPORT transport); +extern bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, + uint16_t* p_conn_id, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -1116,8 +1076,8 @@ extern bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, * Returns None. * ******************************************************************************/ -extern void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, bool enable, - tBT_TRANSPORT transport); +extern void GATT_ConfigServiceChangeCCC(BD_ADDR remote_bda, bool enable, + tBT_TRANSPORT transport); // Enables the GATT profile on the device. // It clears out the control blocks, and registers with L2CAP. @@ -1137,4 +1097,4 @@ extern void gatt_reset_bgdev_list(void); } #endif -#endif /* GATT_API_H */ +#endif /* GATT_API_H */ diff --git a/stack/include/gattdefs.h b/stack/include/gattdefs.h index 4cd22f89f..de968a801 100644 --- a/stack/include/gattdefs.h +++ b/stack/include/gattdefs.h @@ -22,111 +22,109 @@ * ******************************************************************************/ -#ifndef _GATTDEFS_H -#define _GATTDEFS_H +#ifndef _GATTDEFS_H +#define _GATTDEFS_H -#define GATT_ILLEGAL_UUID 0 +#define GATT_ILLEGAL_UUID 0 /* GATT attribute types */ -#define GATT_UUID_PRI_SERVICE 0x2800 -#define GATT_UUID_SEC_SERVICE 0x2801 -#define GATT_UUID_INCLUDE_SERVICE 0x2802 +#define GATT_UUID_PRI_SERVICE 0x2800 +#define GATT_UUID_SEC_SERVICE 0x2801 +#define GATT_UUID_INCLUDE_SERVICE 0x2802 /* Characteristic Declaration*/ -#define GATT_UUID_CHAR_DECLARE 0x2803 +#define GATT_UUID_CHAR_DECLARE 0x2803 /* Characteristic Extended Properties */ -#define GATT_UUID_CHAR_EXT_PROP 0x2900 +#define GATT_UUID_CHAR_EXT_PROP 0x2900 /* Characteristic User Description*/ -#define GATT_UUID_CHAR_DESCRIPTION 0x2901 +#define GATT_UUID_CHAR_DESCRIPTION 0x2901 /* Client Characteristic Configuration */ -#define GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 +#define GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Server Characteristic Configuration */ -#define GATT_UUID_CHAR_SRVR_CONFIG 0x2903 +#define GATT_UUID_CHAR_SRVR_CONFIG 0x2903 /* Characteristic Presentation Format*/ -#define GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 +#define GATT_UUID_CHAR_PRESENT_FORMAT 0x2904 /* Characteristic Aggregate Format*/ -#define GATT_UUID_CHAR_AGG_FORMAT 0x2905 +#define GATT_UUID_CHAR_AGG_FORMAT 0x2905 /* Characteristic Valid Range */ -#define GATT_UUID_CHAR_VALID_RANGE 0x2906 -#define GATT_UUID_EXT_RPT_REF_DESCR 0x2907 -#define GATT_UUID_RPT_REF_DESCR 0x2908 - +#define GATT_UUID_CHAR_VALID_RANGE 0x2906 +#define GATT_UUID_EXT_RPT_REF_DESCR 0x2907 +#define GATT_UUID_RPT_REF_DESCR 0x2908 /* GAP Profile Attributes */ -#define GATT_UUID_GAP_DEVICE_NAME 0x2A00 -#define GATT_UUID_GAP_ICON 0x2A01 -#define GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 +#define GATT_UUID_GAP_DEVICE_NAME 0x2A00 +#define GATT_UUID_GAP_ICON 0x2A01 +#define GATT_UUID_GAP_PREF_CONN_PARAM 0x2A04 #define GATT_UUID_GAP_CENTRAL_ADDR_RESOL 0x2AA6 /* Attribute Profile Attribute UUID */ -#define GATT_UUID_GATT_SRV_CHGD 0x2A05 +#define GATT_UUID_GATT_SRV_CHGD 0x2A05 /* Attribute Protocol Test */ /* Link Loss Service */ -#define GATT_UUID_ALERT_LEVEL 0x2A06 /* Alert Level */ -#define GATT_UUID_TX_POWER_LEVEL 0x2A07 /* TX power level */ +#define GATT_UUID_ALERT_LEVEL 0x2A06 /* Alert Level */ +#define GATT_UUID_TX_POWER_LEVEL 0x2A07 /* TX power level */ /* Time Profile */ /* Current Time Service */ -#define GATT_UUID_CURRENT_TIME 0x2A2B /* Current Time */ -#define GATT_UUID_LOCAL_TIME_INFO 0x2A0F /* Local time info */ -#define GATT_UUID_REF_TIME_INFO 0x2A14 /* reference time information */ +#define GATT_UUID_CURRENT_TIME 0x2A2B /* Current Time */ +#define GATT_UUID_LOCAL_TIME_INFO 0x2A0F /* Local time info */ +#define GATT_UUID_REF_TIME_INFO 0x2A14 /* reference time information */ /* NwA Profile */ -#define GATT_UUID_NW_STATUS 0x2A18 /* network availability status */ -#define GATT_UUID_NW_TRIGGER 0x2A1A /* Network availability trigger */ +#define GATT_UUID_NW_STATUS 0x2A18 /* network availability status */ +#define GATT_UUID_NW_TRIGGER 0x2A1A /* Network availability trigger */ /* phone alert */ -#define GATT_UUID_ALERT_STATUS 0x2A3F /* alert status */ -#define GATT_UUID_RINGER_CP 0x2A40 /* ringer control point */ -#define GATT_UUID_RINGER_SETTING 0x2A41 /* ringer setting */ +#define GATT_UUID_ALERT_STATUS 0x2A3F /* alert status */ +#define GATT_UUID_RINGER_CP 0x2A40 /* ringer control point */ +#define GATT_UUID_RINGER_SETTING 0x2A41 /* ringer setting */ /* Glucose Service */ -#define GATT_UUID_GM_MEASUREMENT 0x2A18 -#define GATT_UUID_GM_CONTEXT 0x2A34 -#define GATT_UUID_GM_CONTROL_POINT 0x2A52 -#define GATT_UUID_GM_FEATURE 0x2A51 +#define GATT_UUID_GM_MEASUREMENT 0x2A18 +#define GATT_UUID_GM_CONTEXT 0x2A34 +#define GATT_UUID_GM_CONTROL_POINT 0x2A52 +#define GATT_UUID_GM_FEATURE 0x2A51 /* device infor characteristic */ -#define GATT_UUID_SYSTEM_ID 0x2A23 -#define GATT_UUID_MODEL_NUMBER_STR 0x2A24 -#define GATT_UUID_SERIAL_NUMBER_STR 0x2A25 -#define GATT_UUID_FW_VERSION_STR 0x2A26 -#define GATT_UUID_HW_VERSION_STR 0x2A27 -#define GATT_UUID_SW_VERSION_STR 0x2A28 -#define GATT_UUID_MANU_NAME 0x2A29 -#define GATT_UUID_IEEE_DATA 0x2A2A -#define GATT_UUID_PNP_ID 0x2A50 +#define GATT_UUID_SYSTEM_ID 0x2A23 +#define GATT_UUID_MODEL_NUMBER_STR 0x2A24 +#define GATT_UUID_SERIAL_NUMBER_STR 0x2A25 +#define GATT_UUID_FW_VERSION_STR 0x2A26 +#define GATT_UUID_HW_VERSION_STR 0x2A27 +#define GATT_UUID_SW_VERSION_STR 0x2A28 +#define GATT_UUID_MANU_NAME 0x2A29 +#define GATT_UUID_IEEE_DATA 0x2A2A +#define GATT_UUID_PNP_ID 0x2A50 /* HID characteristics */ -#define GATT_UUID_HID_INFORMATION 0x2A4A -#define GATT_UUID_HID_REPORT_MAP 0x2A4B -#define GATT_UUID_HID_CONTROL_POINT 0x2A4C -#define GATT_UUID_HID_REPORT 0x2A4D -#define GATT_UUID_HID_PROTO_MODE 0x2A4E -#define GATT_UUID_HID_BT_KB_INPUT 0x2A22 -#define GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 -#define GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 +#define GATT_UUID_HID_INFORMATION 0x2A4A +#define GATT_UUID_HID_REPORT_MAP 0x2A4B +#define GATT_UUID_HID_CONTROL_POINT 0x2A4C +#define GATT_UUID_HID_REPORT 0x2A4D +#define GATT_UUID_HID_PROTO_MODE 0x2A4E +#define GATT_UUID_HID_BT_KB_INPUT 0x2A22 +#define GATT_UUID_HID_BT_KB_OUTPUT 0x2A32 +#define GATT_UUID_HID_BT_MOUSE_INPUT 0x2A33 /* Battery Service char */ -#define GATT_UUID_BATTERY_LEVEL 0x2A19 +#define GATT_UUID_BATTERY_LEVEL 0x2A19 -#define GATT_UUID_SC_CONTROL_POINT 0x2A55 -#define GATT_UUID_SENSOR_LOCATION 0x2A5D +#define GATT_UUID_SC_CONTROL_POINT 0x2A55 +#define GATT_UUID_SENSOR_LOCATION 0x2A5D /* RUNNERS SPEED AND CADENCE SERVICE */ -#define GATT_UUID_RSC_MEASUREMENT 0x2A53 -#define GATT_UUID_RSC_FEATURE 0x2A54 +#define GATT_UUID_RSC_MEASUREMENT 0x2A53 +#define GATT_UUID_RSC_FEATURE 0x2A54 /* CYCLING SPEED AND CADENCE SERVICE */ -#define GATT_UUID_CSC_MEASUREMENT 0x2A5B -#define GATT_UUID_CSC_FEATURE 0x2A5C - +#define GATT_UUID_CSC_MEASUREMENT 0x2A5B +#define GATT_UUID_CSC_FEATURE 0x2A5C /* Scan Parameter charatceristics */ -#define GATT_UUID_SCAN_INT_WINDOW 0x2A4F -#define GATT_UUID_SCAN_REFRESH 0x2A31 +#define GATT_UUID_SCAN_INT_WINDOW 0x2A4F +#define GATT_UUID_SCAN_REFRESH 0x2A31 #endif diff --git a/stack/include/hcidefs.h b/stack/include/hcidefs.h index 1d4897283..ae18a3e20 100644 --- a/stack/include/hcidefs.h +++ b/stack/include/hcidefs.h @@ -19,853 +19,943 @@ #ifndef HCIDEFS_H #define HCIDEFS_H -#define HCI_PROTO_VERSION 0x01 /* Version for BT spec 1.1 */ -#define HCI_PROTO_VERSION_1_2 0x02 /* Version for BT spec 1.2 */ -#define HCI_PROTO_VERSION_2_0 0x03 /* Version for BT spec 2.0 */ -#define HCI_PROTO_VERSION_2_1 0x04 /* Version for BT spec 2.1 [Lisbon] */ -#define HCI_PROTO_VERSION_3_0 0x05 /* Version for BT spec 3.0 */ -#define HCI_PROTO_VERSION_4_0 0x06 /* Version for BT spec 4.0 */ -#define HCI_PROTO_VERSION_4_1 0x07 /* Version for BT spec 4.1 */ -#define HCI_PROTO_VERSION_4_2 0x08 /* Version for BT spec 4.2 */ +#define HCI_PROTO_VERSION 0x01 /* Version for BT spec 1.1 */ +#define HCI_PROTO_VERSION_1_2 0x02 /* Version for BT spec 1.2 */ +#define HCI_PROTO_VERSION_2_0 0x03 /* Version for BT spec 2.0 */ +#define HCI_PROTO_VERSION_2_1 0x04 /* Version for BT spec 2.1 [Lisbon] */ +#define HCI_PROTO_VERSION_3_0 0x05 /* Version for BT spec 3.0 */ +#define HCI_PROTO_VERSION_4_0 0x06 /* Version for BT spec 4.0 */ +#define HCI_PROTO_VERSION_4_1 0x07 /* Version for BT spec 4.1 */ +#define HCI_PROTO_VERSION_4_2 0x08 /* Version for BT spec 4.2 */ /* * Definitions for HCI groups */ -#define HCI_GRP_LINK_CONTROL_CMDS (0x01 << 10) /* 0x0400 */ -#define HCI_GRP_LINK_POLICY_CMDS (0x02 << 10) /* 0x0800 */ -#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */ -#define HCI_GRP_INFORMATIONAL_PARAMS (0x04 << 10) /* 0x1000 */ -#define HCI_GRP_STATUS_PARAMS (0x05 << 10) /* 0x1400 */ -#define HCI_GRP_TESTING_CMDS (0x06 << 10) /* 0x1800 */ +#define HCI_GRP_LINK_CONTROL_CMDS (0x01 << 10) /* 0x0400 */ +#define HCI_GRP_LINK_POLICY_CMDS (0x02 << 10) /* 0x0800 */ +#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */ +#define HCI_GRP_INFORMATIONAL_PARAMS (0x04 << 10) /* 0x1000 */ +#define HCI_GRP_STATUS_PARAMS (0x05 << 10) /* 0x1400 */ +#define HCI_GRP_TESTING_CMDS (0x06 << 10) /* 0x1800 */ -#define HCI_GRP_VENDOR_SPECIFIC (0x3F << 10) /* 0xFC00 */ +#define HCI_GRP_VENDOR_SPECIFIC (0x3F << 10) /* 0xFC00 */ /* Group occupies high 6 bits of the HCI command rest is opcode itself */ -#define HCI_OGF(p) (uint8_t)((0xFC00 & (p)) >> 10) -#define HCI_OCF(p) ( 0x3FF & (p)) +#define HCI_OGF(p) (uint8_t)((0xFC00 & (p)) >> 10) +#define HCI_OCF(p) (0x3FF & (p)) /* * Definitions for Link Control Commands */ /* Following opcode is used only in command complete event for flow control */ -#define HCI_COMMAND_NONE 0x0000 +#define HCI_COMMAND_NONE 0x0000 /* Commands of HCI_GRP_LINK_CONTROL_CMDS group */ -#define HCI_INQUIRY (0x0001 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_INQUIRY_CANCEL (0x0002 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PERIODIC_INQUIRY_MODE (0x0003 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_EXIT_PERIODIC_INQUIRY_MODE (0x0004 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_CONNECTION (0x0005 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT (0x0006 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ADD_SCO_CONNECTION (0x0007 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_CONNECTION_CANCEL (0x0008 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_CONNECTION_REQUEST (0x0009 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REJECT_CONNECTION_REQUEST (0x000A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LINK_KEY_REQUEST_REPLY (0x000B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LINK_KEY_REQUEST_NEG_REPLY (0x000C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PIN_CODE_REQUEST_REPLY (0x000D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PIN_CODE_REQUEST_NEG_REPLY (0x000E | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CHANGE_CONN_PACKET_TYPE (0x000F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_AUTHENTICATION_REQUESTED (0x0011 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SET_CONN_ENCRYPTION (0x0013 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CHANGE_CONN_LINK_KEY (0x0015 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_MASTER_LINK_KEY (0x0017 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RMT_NAME_REQUEST (0x0019 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RMT_NAME_REQUEST_CANCEL (0x001A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_FEATURES (0x001B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_EXT_FEATURES (0x001C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_VERSION_INFO (0x001D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_CLOCK_OFFSET (0x001F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_LMP_HANDLE (0x0020 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SETUP_ESCO_CONNECTION (0x0028 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_ESCO_CONNECTION (0x0029 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REJECT_ESCO_CONNECTION (0x002A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_INQUIRY (0x0001 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_INQUIRY_CANCEL (0x0002 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PERIODIC_INQUIRY_MODE (0x0003 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_EXIT_PERIODIC_INQUIRY_MODE (0x0004 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_CONNECTION (0x0005 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT (0x0006 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ADD_SCO_CONNECTION (0x0007 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_CONNECTION_CANCEL (0x0008 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_CONNECTION_REQUEST (0x0009 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REJECT_CONNECTION_REQUEST (0x000A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LINK_KEY_REQUEST_REPLY (0x000B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LINK_KEY_REQUEST_NEG_REPLY (0x000C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PIN_CODE_REQUEST_REPLY (0x000D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_PIN_CODE_REQUEST_NEG_REPLY (0x000E | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CHANGE_CONN_PACKET_TYPE (0x000F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_AUTHENTICATION_REQUESTED (0x0011 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SET_CONN_ENCRYPTION (0x0013 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CHANGE_CONN_LINK_KEY (0x0015 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_MASTER_LINK_KEY (0x0017 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RMT_NAME_REQUEST (0x0019 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RMT_NAME_REQUEST_CANCEL (0x001A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_FEATURES (0x001B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_EXT_FEATURES (0x001C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_VERSION_INFO (0x001D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_RMT_CLOCK_OFFSET (0x001F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_READ_LMP_HANDLE (0x0020 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SETUP_ESCO_CONNECTION (0x0028 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_ESCO_CONNECTION (0x0029 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REJECT_ESCO_CONNECTION (0x002A | HCI_GRP_LINK_CONTROL_CMDS) #define HCI_IO_CAPABILITY_REQUEST_REPLY (0x002B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_CONF_REQUEST_REPLY (0x002C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_CONF_VALUE_NEG_REPLY (0x002D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_PASSKEY_REQ_REPLY (0x002E | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_PASSKEY_REQ_NEG_REPLY (0x002F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REM_OOB_DATA_REQ_REPLY (0x0030 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REM_OOB_DATA_REQ_NEG_REPLY (0x0033 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_IO_CAP_REQ_NEG_REPLY (0x0034 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_CONF_REQUEST_REPLY (0x002C | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_CONF_VALUE_NEG_REPLY (0x002D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_PASSKEY_REQ_REPLY (0x002E | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_USER_PASSKEY_REQ_NEG_REPLY (0x002F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REM_OOB_DATA_REQ_REPLY (0x0030 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_REM_OOB_DATA_REQ_NEG_REPLY (0x0033 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_IO_CAP_REQ_NEG_REPLY (0x0034 | HCI_GRP_LINK_CONTROL_CMDS) /* AMP HCI */ -#define HCI_CREATE_PHYSICAL_LINK (0x0035 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_PHYSICAL_LINK (0x0036 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT_PHYSICAL_LINK (0x0037 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_LOGICAL_LINK (0x0038 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_LOGICAL_LINK (0x0039 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT_LOGICAL_LINK (0x003A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LOGICAL_LINK_CANCEL (0x003B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_FLOW_SPEC_MODIFY (0x003C | HCI_GRP_LINK_CONTROL_CMDS) - -#define HCI_ENH_SETUP_ESCO_CONNECTION (0x003D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ENH_ACCEPT_ESCO_CONNECTION (0x003E | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_PHYSICAL_LINK (0x0035 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_PHYSICAL_LINK (0x0036 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT_PHYSICAL_LINK (0x0037 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_CREATE_LOGICAL_LINK (0x0038 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ACCEPT_LOGICAL_LINK (0x0039 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_DISCONNECT_LOGICAL_LINK (0x003A | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_LOGICAL_LINK_CANCEL (0x003B | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_FLOW_SPEC_MODIFY (0x003C | HCI_GRP_LINK_CONTROL_CMDS) + +#define HCI_ENH_SETUP_ESCO_CONNECTION (0x003D | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_ENH_ACCEPT_ESCO_CONNECTION (0x003E | HCI_GRP_LINK_CONTROL_CMDS) /* ConnectionLess Broadcast */ -#define HCI_TRUNCATED_PAGE (0x003F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_TRUNCATED_PAGE_CANCEL (0x0040 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SET_CLB (0x0041 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RECEIVE_CLB (0x0042 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_START_SYNC_TRAIN (0x0043 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RECEIVE_SYNC_TRAIN (0x0044 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_TRUNCATED_PAGE (0x003F | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_TRUNCATED_PAGE_CANCEL (0x0040 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_SET_CLB (0x0041 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RECEIVE_CLB (0x0042 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_START_SYNC_TRAIN (0x0043 | HCI_GRP_LINK_CONTROL_CMDS) +#define HCI_RECEIVE_SYNC_TRAIN (0x0044 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LINK_CTRL_CMDS_FIRST HCI_INQUIRY -#define HCI_LINK_CTRL_CMDS_LAST HCI_RECEIVE_SYNC_TRAIN +#define HCI_LINK_CTRL_CMDS_FIRST HCI_INQUIRY +#define HCI_LINK_CTRL_CMDS_LAST HCI_RECEIVE_SYNC_TRAIN /* Commands of HCI_GRP_LINK_POLICY_CMDS */ -#define HCI_HOLD_MODE (0x0001 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SNIFF_MODE (0x0003 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_EXIT_SNIFF_MODE (0x0004 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_PARK_MODE (0x0005 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_EXIT_PARK_MODE (0x0006 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_QOS_SETUP (0x0007 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_ROLE_DISCOVERY (0x0009 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SWITCH_ROLE (0x000B | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_READ_POLICY_SETTINGS (0x000C | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_WRITE_POLICY_SETTINGS (0x000D | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_READ_DEF_POLICY_SETTINGS (0x000E | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_WRITE_DEF_POLICY_SETTINGS (0x000F | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_FLOW_SPECIFICATION (0x0010 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SNIFF_SUB_RATE (0x0011 | HCI_GRP_LINK_POLICY_CMDS) - -#define HCI_LINK_POLICY_CMDS_FIRST HCI_HOLD_MODE -#define HCI_LINK_POLICY_CMDS_LAST HCI_SNIFF_SUB_RATE - +#define HCI_HOLD_MODE (0x0001 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SNIFF_MODE (0x0003 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_EXIT_SNIFF_MODE (0x0004 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_PARK_MODE (0x0005 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_EXIT_PARK_MODE (0x0006 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_QOS_SETUP (0x0007 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_ROLE_DISCOVERY (0x0009 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SWITCH_ROLE (0x000B | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_READ_POLICY_SETTINGS (0x000C | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_WRITE_POLICY_SETTINGS (0x000D | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_READ_DEF_POLICY_SETTINGS (0x000E | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_WRITE_DEF_POLICY_SETTINGS (0x000F | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_FLOW_SPECIFICATION (0x0010 | HCI_GRP_LINK_POLICY_CMDS) +#define HCI_SNIFF_SUB_RATE (0x0011 | HCI_GRP_LINK_POLICY_CMDS) + +#define HCI_LINK_POLICY_CMDS_FIRST HCI_HOLD_MODE +#define HCI_LINK_POLICY_CMDS_LAST HCI_SNIFF_SUB_RATE /* Commands of HCI_GRP_HOST_CONT_BASEBAND_CMDS */ -#define HCI_SET_EVENT_MASK (0x0001 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EVENT_FILTER (0x0005 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_FLUSH (0x0008 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PIN_TYPE (0x0009 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PIN_TYPE (0x000A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CREATE_NEW_UNIT_KEY (0x000B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_GET_MWS_TRANS_LAYER_CFG (0x000C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_STORED_LINK_KEY (0x000D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_STORED_LINK_KEY (0x0011 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_DELETE_STORED_LINK_KEY (0x0012 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CHANGE_LOCAL_NAME (0x0013 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCAL_NAME (0x0014 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CONN_ACCEPT_TOUT (0x0015 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CONN_ACCEPT_TOUT (0x0016 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGE_TOUT (0x0017 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGE_TOUT (0x0018 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SCAN_ENABLE (0x0019 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SCAN_ENABLE (0x001A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_CFG (0x001B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_CFG (0x001C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQUIRYSCAN_CFG (0x001D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQUIRYSCAN_CFG (0x001E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AUTHENTICATION_ENABLE (0x001F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AUTHENTICATION_ENABLE (0x0020 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_ENCRYPTION_MODE (0x0021 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_ENCRYPTION_MODE (0x0022 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CLASS_OF_DEVICE (0x0023 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CLASS_OF_DEVICE (0x0024 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_VOICE_SETTINGS (0x0025 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_VOICE_SETTINGS (0x0026 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AUTO_FLUSH_TOUT (0x0027 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AUTO_FLUSH_TOUT (0x0028 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_NUM_BCAST_REXMITS (0x0029 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_NUM_BCAST_REXMITS (0x002A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_HOLD_MODE_ACTIVITY (0x002B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_HOLD_MODE_ACTIVITY (0x002C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_TRANSMIT_POWER_LEVEL (0x002D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SCO_FLOW_CTRL_ENABLE (0x002E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SCO_FLOW_CTRL_ENABLE (0x002F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_HC_TO_HOST_FLOW_CTRL (0x0031 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_HOST_BUFFER_SIZE (0x0033 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_HOST_NUM_PACKETS_DONE (0x0035 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LINK_SUPER_TOUT (0x0036 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LINK_SUPER_TOUT (0x0037 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_NUM_SUPPORTED_IAC (0x0038 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CURRENT_IAC_LAP (0x0039 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CURRENT_IAC_LAP (0x003A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_PERIOD_MODE (0x003B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_PERIOD_MODE (0x003C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_MODE (0x003D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_MODE (0x003E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_AFH_CHANNELS (0x003F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -#define HCI_READ_INQSCAN_TYPE (0x0042 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQSCAN_TYPE (0x0043 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQUIRY_MODE (0x0044 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQUIRY_MODE (0x0045 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_TYPE (0x0046 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_TYPE (0x0047 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AFH_ASSESSMENT_MODE (0x0048 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AFH_ASSESSMENT_MODE (0x0049 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_EXT_INQ_RESPONSE (0x0051 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_EXT_INQ_RESPONSE (0x0052 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_REFRESH_ENCRYPTION_KEY (0x0053 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SIMPLE_PAIRING_MODE (0x0055 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SIMPLE_PAIRING_MODE (0x0056 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCAL_OOB_DATA (0x0057 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQ_TX_POWER_LEVEL (0x0058 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQ_TX_POWER_LEVEL (0x0059 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_ERRONEOUS_DATA_RPT (0x005A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_ERRONEOUS_DATA_RPT (0x005B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_ENHANCED_FLUSH (0x005F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SEND_KEYPRESS_NOTIF (0x0060 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - +#define HCI_SET_EVENT_MASK (0x0001 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EVENT_FILTER (0x0005 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_FLUSH (0x0008 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PIN_TYPE (0x0009 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PIN_TYPE (0x000A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CREATE_NEW_UNIT_KEY (0x000B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_GET_MWS_TRANS_LAYER_CFG (0x000C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_STORED_LINK_KEY (0x000D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_STORED_LINK_KEY (0x0011 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_DELETE_STORED_LINK_KEY (0x0012 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CHANGE_LOCAL_NAME (0x0013 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCAL_NAME (0x0014 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CONN_ACCEPT_TOUT (0x0015 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CONN_ACCEPT_TOUT (0x0016 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGE_TOUT (0x0017 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGE_TOUT (0x0018 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SCAN_ENABLE (0x0019 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SCAN_ENABLE (0x001A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_CFG (0x001B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_CFG (0x001C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQUIRYSCAN_CFG (0x001D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQUIRYSCAN_CFG (0x001E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AUTHENTICATION_ENABLE \ + (0x001F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AUTHENTICATION_ENABLE \ + (0x0020 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_ENCRYPTION_MODE (0x0021 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_ENCRYPTION_MODE (0x0022 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CLASS_OF_DEVICE (0x0023 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CLASS_OF_DEVICE (0x0024 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_VOICE_SETTINGS (0x0025 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_VOICE_SETTINGS (0x0026 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AUTO_FLUSH_TOUT (0x0027 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AUTO_FLUSH_TOUT (0x0028 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_NUM_BCAST_REXMITS (0x0029 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_NUM_BCAST_REXMITS (0x002A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_HOLD_MODE_ACTIVITY (0x002B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_HOLD_MODE_ACTIVITY (0x002C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_TRANSMIT_POWER_LEVEL (0x002D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SCO_FLOW_CTRL_ENABLE (0x002E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SCO_FLOW_CTRL_ENABLE \ + (0x002F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_HC_TO_HOST_FLOW_CTRL (0x0031 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_HOST_BUFFER_SIZE (0x0033 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_HOST_NUM_PACKETS_DONE (0x0035 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LINK_SUPER_TOUT (0x0036 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LINK_SUPER_TOUT (0x0037 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_NUM_SUPPORTED_IAC (0x0038 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_CURRENT_IAC_LAP (0x0039 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CURRENT_IAC_LAP (0x003A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_PERIOD_MODE (0x003B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_PERIOD_MODE \ + (0x003C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_MODE (0x003D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_MODE (0x003E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_AFH_CHANNELS (0x003F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + +#define HCI_READ_INQSCAN_TYPE (0x0042 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQSCAN_TYPE (0x0043 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQUIRY_MODE (0x0044 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQUIRY_MODE (0x0045 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_PAGESCAN_TYPE (0x0046 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_PAGESCAN_TYPE (0x0047 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_AFH_ASSESSMENT_MODE (0x0048 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_AFH_ASSESSMENT_MODE (0x0049 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_EXT_INQ_RESPONSE (0x0051 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_EXT_INQ_RESPONSE (0x0052 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_REFRESH_ENCRYPTION_KEY (0x0053 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SIMPLE_PAIRING_MODE (0x0055 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SIMPLE_PAIRING_MODE (0x0056 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCAL_OOB_DATA (0x0057 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_INQ_TX_POWER_LEVEL (0x0058 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_INQ_TX_POWER_LEVEL (0x0059 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_ERRONEOUS_DATA_RPT (0x005A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_ERRONEOUS_DATA_RPT (0x005B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_ENHANCED_FLUSH (0x005F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SEND_KEYPRESS_NOTIF (0x0060 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* AMP HCI */ -#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0061 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0062 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EVENT_MASK_PAGE_2 (0x0063 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCATION_DATA (0x0064 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LOCATION_DATA (0x0065 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_FLOW_CONTROL_MODE (0x0066 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_FLOW_CONTROL_MODE (0x0067 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_BE_FLUSH_TOUT (0x0069 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_BE_FLUSH_TOUT (0x006A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT \ + (0x0061 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT \ + (0x0062 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EVENT_MASK_PAGE_2 (0x0063 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LOCATION_DATA (0x0064 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LOCATION_DATA (0x0065 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_FLOW_CONTROL_MODE (0x0066 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_FLOW_CONTROL_MODE (0x0067 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_BE_FLUSH_TOUT (0x0069 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_BE_FLUSH_TOUT (0x006A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* 802.11 only */ -#define HCI_SHORT_RANGE_MODE (0x006B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LE_HOST_SUPPORT (0x006C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LE_HOST_SUPPORT (0x006D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - +#define HCI_SHORT_RANGE_MODE (0x006B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_LE_HOST_SUPPORT (0x006C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_LE_HOST_SUPPORT (0x006D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* MWS coexistence */ -#define HCI_SET_MWS_CHANNEL_PARAMETERS (0x006E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION (0x006F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_SIGNALING (0x0070 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_TRANSPORT_LAYER (0x0071 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE (0x0072 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_PATTERN_CONFIGURATION (0x0073 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_CHANNEL_PARAMETERS \ + (0x006E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION \ + (0x006F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_SIGNALING (0x0070 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_TRANSPORT_LAYER (0x0071 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE \ + (0x0072 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_SET_MWS_PATTERN_CONFIGURATION \ + (0x0073 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* Connectionless Broadcast */ -#define HCI_SET_RESERVED_LT_ADDR (0x0074 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_DELETE_RESERVED_LT_ADDR (0x0075 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CLB_DATA (0x0076 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SYNC_TRAIN_PARAM (0x0077 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SYNC_TRAIN_PARAM (0x0078 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -#define HCI_READ_SECURE_CONNS_SUPPORT (0x0079 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SECURE_CONNS_SUPPORT (0x007A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CONT_BASEBAND_CMDS_FIRST HCI_SET_EVENT_MASK -#define HCI_CONT_BASEBAND_CMDS_LAST HCI_READ_SYNC_TRAIN_PARAM - +#define HCI_SET_RESERVED_LT_ADDR (0x0074 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_DELETE_RESERVED_LT_ADDR (0x0075 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_CLB_DATA (0x0076 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_READ_SYNC_TRAIN_PARAM (0x0077 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SYNC_TRAIN_PARAM (0x0078 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) + +#define HCI_READ_SECURE_CONNS_SUPPORT (0x0079 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_WRITE_SECURE_CONNS_SUPPORT \ + (0x007A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) +#define HCI_CONT_BASEBAND_CMDS_FIRST HCI_SET_EVENT_MASK +#define HCI_CONT_BASEBAND_CMDS_LAST HCI_READ_SYNC_TRAIN_PARAM /* Commands of HCI_GRP_INFORMATIONAL_PARAMS group */ -#define HCI_READ_LOCAL_VERSION_INFO (0x0001 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_SUPPORTED_CMDS (0x0002 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_FEATURES (0x0003 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_EXT_FEATURES (0x0004 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_BUFFER_SIZE (0x0005 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_COUNTRY_CODE (0x0007 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_BD_ADDR (0x0009 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_DATA_BLOCK_SIZE (0x000A | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_VERSION_INFO (0x0001 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_SUPPORTED_CMDS (0x0002 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_FEATURES (0x0003 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_LOCAL_EXT_FEATURES (0x0004 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_BUFFER_SIZE (0x0005 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_COUNTRY_CODE (0x0007 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_BD_ADDR (0x0009 | HCI_GRP_INFORMATIONAL_PARAMS) +#define HCI_READ_DATA_BLOCK_SIZE (0x000A | HCI_GRP_INFORMATIONAL_PARAMS) #define HCI_READ_LOCAL_SUPPORTED_CODECS (0x000B | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_INFORMATIONAL_CMDS_FIRST HCI_READ_LOCAL_VERSION_INFO -#define HCI_INFORMATIONAL_CMDS_LAST HCI_READ_LOCAL_SUPPORTED_CODECS - +#define HCI_INFORMATIONAL_CMDS_FIRST HCI_READ_LOCAL_VERSION_INFO +#define HCI_INFORMATIONAL_CMDS_LAST HCI_READ_LOCAL_SUPPORTED_CODECS /* Commands of HCI_GRP_STATUS_PARAMS group */ -#define HCI_READ_FAILED_CONTACT_COUNT (0x0001 | HCI_GRP_STATUS_PARAMS) -#define HCI_RESET_FAILED_CONTACT_COUNT (0x0002 | HCI_GRP_STATUS_PARAMS) -#define HCI_GET_LINK_QUALITY (0x0003 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_RSSI (0x0005 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_AFH_CH_MAP (0x0006 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_CLOCK (0x0007 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_ENCR_KEY_SIZE (0x0008 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_FAILED_CONTACT_COUNT (0x0001 | HCI_GRP_STATUS_PARAMS) +#define HCI_RESET_FAILED_CONTACT_COUNT (0x0002 | HCI_GRP_STATUS_PARAMS) +#define HCI_GET_LINK_QUALITY (0x0003 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_RSSI (0x0005 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_AFH_CH_MAP (0x0006 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_CLOCK (0x0007 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_ENCR_KEY_SIZE (0x0008 | HCI_GRP_STATUS_PARAMS) /* AMP HCI */ -#define HCI_READ_LOCAL_AMP_INFO (0x0009 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_LOCAL_AMP_ASSOC (0x000A | HCI_GRP_STATUS_PARAMS) -#define HCI_WRITE_REMOTE_AMP_ASSOC (0x000B | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_LOCAL_AMP_INFO (0x0009 | HCI_GRP_STATUS_PARAMS) +#define HCI_READ_LOCAL_AMP_ASSOC (0x000A | HCI_GRP_STATUS_PARAMS) +#define HCI_WRITE_REMOTE_AMP_ASSOC (0x000B | HCI_GRP_STATUS_PARAMS) -#define HCI_STATUS_PARAMS_CMDS_FIRST HCI_READ_FAILED_CONTACT_COUNT -#define HCI_STATUS_PARAMS_CMDS_LAST HCI_WRITE_REMOTE_AMP_ASSOC +#define HCI_STATUS_PARAMS_CMDS_FIRST HCI_READ_FAILED_CONTACT_COUNT +#define HCI_STATUS_PARAMS_CMDS_LAST HCI_WRITE_REMOTE_AMP_ASSOC /* Commands of HCI_GRP_TESTING_CMDS group */ -#define HCI_READ_LOOPBACK_MODE (0x0001 | HCI_GRP_TESTING_CMDS) -#define HCI_WRITE_LOOPBACK_MODE (0x0002 | HCI_GRP_TESTING_CMDS) -#define HCI_ENABLE_DEV_UNDER_TEST_MODE (0x0003 | HCI_GRP_TESTING_CMDS) -#define HCI_WRITE_SIMP_PAIR_DEBUG_MODE (0x0004 | HCI_GRP_TESTING_CMDS) +#define HCI_READ_LOOPBACK_MODE (0x0001 | HCI_GRP_TESTING_CMDS) +#define HCI_WRITE_LOOPBACK_MODE (0x0002 | HCI_GRP_TESTING_CMDS) +#define HCI_ENABLE_DEV_UNDER_TEST_MODE (0x0003 | HCI_GRP_TESTING_CMDS) +#define HCI_WRITE_SIMP_PAIR_DEBUG_MODE (0x0004 | HCI_GRP_TESTING_CMDS) /* AMP HCI */ -#define HCI_ENABLE_AMP_RCVR_REPORTS (0x0007 | HCI_GRP_TESTING_CMDS) -#define HCI_AMP_TEST_END (0x0008 | HCI_GRP_TESTING_CMDS) -#define HCI_AMP_TEST (0x0009 | HCI_GRP_TESTING_CMDS) +#define HCI_ENABLE_AMP_RCVR_REPORTS (0x0007 | HCI_GRP_TESTING_CMDS) +#define HCI_AMP_TEST_END (0x0008 | HCI_GRP_TESTING_CMDS) +#define HCI_AMP_TEST (0x0009 | HCI_GRP_TESTING_CMDS) -#define HCI_TESTING_CMDS_FIRST HCI_READ_LOOPBACK_MODE -#define HCI_TESTING_CMDS_LAST HCI_AMP_TEST +#define HCI_TESTING_CMDS_FIRST HCI_READ_LOOPBACK_MODE +#define HCI_TESTING_CMDS_LAST HCI_AMP_TEST -#define HCI_VENDOR_CMDS_FIRST 0x0001 -#define HCI_VENDOR_CMDS_LAST 0xFFFF -#define HCI_VSC_MULTI_AV_HANDLE 0x0AAA -#define HCI_VSC_BURST_MODE_HANDLE 0x0BBB +#define HCI_VENDOR_CMDS_FIRST 0x0001 +#define HCI_VENDOR_CMDS_LAST 0xFFFF +#define HCI_VSC_MULTI_AV_HANDLE 0x0AAA +#define HCI_VSC_BURST_MODE_HANDLE 0x0BBB /* BLE HCI */ -#define HCI_GRP_BLE_CMDS (0x08 << 10) +#define HCI_GRP_BLE_CMDS (0x08 << 10) /* Commands of BLE Controller setup and configuration */ -#define HCI_BLE_SET_EVENT_MASK (0x0001 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_BUFFER_SIZE (0x0002 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_LOCAL_SPT_FEAT (0x0003 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_LOCAL_SPT_FEAT (0x0004 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_RANDOM_ADDR (0x0005 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_PARAMS (0x0006 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_ADV_CHNL_TX_POWER (0x0007 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_DATA (0x0008 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_RSP_DATA (0x0009 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_ENABLE (0x000A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_PARAMS (0x000B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_ENABLE (0x000C | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CREATE_LL_CONN (0x000D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CREATE_CONN_CANCEL (0x000E | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_WHITE_LIST_SIZE (0x000F | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CLEAR_WHITE_LIST (0x0010 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ADD_WHITE_LIST (0x0011 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_REMOVE_WHITE_LIST (0x0012 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_UPD_LL_CONN_PARAMS (0x0013 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_HOST_CHNL_CLASS (0x0014 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_CHNL_MAP (0x0015 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_REMOTE_FEAT (0x0016 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ENCRYPT (0x0017 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RAND (0x0018 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_START_ENC (0x0019 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_LTK_REQ_REPLY (0x001A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_LTK_REQ_NEG_REPLY (0x001B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_SUPPORTED_STATES (0x001C | HCI_GRP_BLE_CMDS) - /* 0x001D, 0x001E and 0x001F are reserved */ -#define HCI_BLE_RECEIVER_TEST (0x001D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_TRANSMITTER_TEST (0x001E | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_EVENT_MASK (0x0001 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_BUFFER_SIZE (0x0002 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_LOCAL_SPT_FEAT (0x0003 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_LOCAL_SPT_FEAT (0x0004 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_RANDOM_ADDR (0x0005 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_PARAMS (0x0006 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_ADV_CHNL_TX_POWER (0x0007 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_DATA (0x0008 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_RSP_DATA (0x0009 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_ADV_ENABLE (0x000A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_PARAMS (0x000B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_SCAN_ENABLE (0x000C | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CREATE_LL_CONN (0x000D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CREATE_CONN_CANCEL (0x000E | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_WHITE_LIST_SIZE (0x000F | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CLEAR_WHITE_LIST (0x0010 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_ADD_WHITE_LIST (0x0011 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_REMOVE_WHITE_LIST (0x0012 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_UPD_LL_CONN_PARAMS (0x0013 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_HOST_CHNL_CLASS (0x0014 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_CHNL_MAP (0x0015 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_REMOTE_FEAT (0x0016 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_ENCRYPT (0x0017 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RAND (0x0018 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_START_ENC (0x0019 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_LTK_REQ_REPLY (0x001A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_LTK_REQ_NEG_REPLY (0x001B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_SUPPORTED_STATES (0x001C | HCI_GRP_BLE_CMDS) +/* 0x001D, 0x001E and 0x001F are reserved */ +#define HCI_BLE_RECEIVER_TEST (0x001D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_TRANSMITTER_TEST (0x001E | HCI_GRP_BLE_CMDS) /* BLE TEST COMMANDS */ -#define HCI_BLE_TEST_END (0x001F | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RC_PARAM_REQ_REPLY (0x0020 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RC_PARAM_REQ_NEG_REPLY (0x0021 | HCI_GRP_BLE_CMDS) - -#define HCI_BLE_SET_DATA_LENGTH (0x0022 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_DEFAULT_DATA_LENGTH (0x0023 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_DEFAULT_DATA_LENGTH (0x0024 | HCI_GRP_BLE_CMDS) - -#define HCI_BLE_ADD_DEV_RESOLVING_LIST (0x0027 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RM_DEV_RESOLVING_LIST (0x0028 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CLEAR_RESOLVING_LIST (0x0029 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVING_LIST_SIZE (0x002A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVABLE_ADDR_PEER (0x002B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL (0x002C | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_ADDR_RESOLUTION_ENABLE (0x002D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT (0x002E | HCI_GRP_BLE_CMDS) +#define HCI_BLE_TEST_END (0x001F | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RC_PARAM_REQ_REPLY (0x0020 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RC_PARAM_REQ_NEG_REPLY (0x0021 | HCI_GRP_BLE_CMDS) + +#define HCI_BLE_SET_DATA_LENGTH (0x0022 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_DEFAULT_DATA_LENGTH (0x0023 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_WRITE_DEFAULT_DATA_LENGTH (0x0024 | HCI_GRP_BLE_CMDS) + +#define HCI_BLE_ADD_DEV_RESOLVING_LIST (0x0027 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_RM_DEV_RESOLVING_LIST (0x0028 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CLEAR_RESOLVING_LIST (0x0029 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVING_LIST_SIZE (0x002A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVABLE_ADDR_PEER (0x002B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL (0x002C | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_ADDR_RESOLUTION_ENABLE (0x002D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT (0x002E | HCI_GRP_BLE_CMDS) /* LE Get Vendor Capabilities Command OCF */ -#define HCI_BLE_VENDOR_CAP_OCF (0x0153 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_VENDOR_CAP_OCF (0x0153 | HCI_GRP_VENDOR_SPECIFIC) /* Multi adv OCF */ -#define HCI_BLE_MULTI_ADV_OCF (0x0154 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_MULTI_ADV_OCF (0x0154 | HCI_GRP_VENDOR_SPECIFIC) /* Batch scan OCF */ -#define HCI_BLE_BATCH_SCAN_OCF (0x0156 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_BATCH_SCAN_OCF (0x0156 | HCI_GRP_VENDOR_SPECIFIC) /* ADV filter OCF */ -#define HCI_BLE_ADV_FILTER_OCF (0x0157 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_ADV_FILTER_OCF (0x0157 | HCI_GRP_VENDOR_SPECIFIC) /* Tracking OCF */ -#define HCI_BLE_TRACK_ADV_OCF (0x0158 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_TRACK_ADV_OCF (0x0158 | HCI_GRP_VENDOR_SPECIFIC) /* Energy info OCF */ -#define HCI_BLE_ENERGY_INFO_OCF (0x0159 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_ENERGY_INFO_OCF (0x0159 | HCI_GRP_VENDOR_SPECIFIC) /* Extended BLE Scan parameters OCF */ -#define HCI_BLE_EXTENDED_SCAN_PARAMS_OCF (0x015A | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BLE_EXTENDED_SCAN_PARAMS_OCF (0x015A | HCI_GRP_VENDOR_SPECIFIC) /* Controller debug info OCF */ -#define HCI_CONTROLLER_DEBUG_INFO_OCF (0x015B | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_CONTROLLER_DEBUG_INFO_OCF (0x015B | HCI_GRP_VENDOR_SPECIFIC) /* subcode for multi adv feature */ -#define BTM_BLE_MULTI_ADV_SET_PARAM 0x01 -#define BTM_BLE_MULTI_ADV_WRITE_ADV_DATA 0x02 -#define BTM_BLE_MULTI_ADV_WRITE_SCAN_RSP_DATA 0x03 -#define BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR 0x04 -#define BTM_BLE_MULTI_ADV_ENB 0x05 +#define BTM_BLE_MULTI_ADV_SET_PARAM 0x01 +#define BTM_BLE_MULTI_ADV_WRITE_ADV_DATA 0x02 +#define BTM_BLE_MULTI_ADV_WRITE_SCAN_RSP_DATA 0x03 +#define BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR 0x04 +#define BTM_BLE_MULTI_ADV_ENB 0x05 /* multi adv VSE subcode */ /* multi adv instance state change */ -#define HCI_VSE_SUBCODE_BLE_MULTI_ADV_ST_CHG 0x55 +#define HCI_VSE_SUBCODE_BLE_MULTI_ADV_ST_CHG 0x55 /* subcode for batch scan feature */ -#define BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE 0x01 -#define BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM 0x02 -#define BTM_BLE_BATCH_SCAN_SET_PARAMS 0x03 -#define BTM_BLE_BATCH_SCAN_READ_RESULTS 0x04 +#define BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE 0x01 +#define BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM 0x02 +#define BTM_BLE_BATCH_SCAN_SET_PARAMS 0x03 +#define BTM_BLE_BATCH_SCAN_READ_RESULTS 0x04 /* batch scan VSE subcode */ -#define HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT 0x54 /* Threshold event */ +#define HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT 0x54 /* Threshold event */ /* tracking sub event */ -#define HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT 0x56 /* Tracking event */ +#define HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT 0x56 /* Tracking event */ /* LE supported states definition */ -#define HCI_LE_ADV_STATE 0x00000001 -#define HCI_LE_SCAN_STATE 0x00000002 -#define HCI_LE_INIT_STATE 0x00000004 -#define HCI_LE_CONN_SL_STATE 0x00000008 -#define HCI_LE_ADV_SCAN_STATE 0x00000010 -#define HCI_LE_ADV_INIT_STATE 0x00000020 -#define HCI_LE_ADV_MA_STATE 0x00000040 -#define HCI_LE_ADV_SL_STATE 0x00000080 -#define HCI_LE_SCAN_INIT_STATE 0x00000100 -#define HCI_LE_SCAN_MA_STATE 0x00000200 -#define HCI_LE_SCAN_SL_STATE 0x00000400 -#define HCI_LE_INIT_MA_STATE 0x00000800 +#define HCI_LE_ADV_STATE 0x00000001 +#define HCI_LE_SCAN_STATE 0x00000002 +#define HCI_LE_INIT_STATE 0x00000004 +#define HCI_LE_CONN_SL_STATE 0x00000008 +#define HCI_LE_ADV_SCAN_STATE 0x00000010 +#define HCI_LE_ADV_INIT_STATE 0x00000020 +#define HCI_LE_ADV_MA_STATE 0x00000040 +#define HCI_LE_ADV_SL_STATE 0x00000080 +#define HCI_LE_SCAN_INIT_STATE 0x00000100 +#define HCI_LE_SCAN_MA_STATE 0x00000200 +#define HCI_LE_SCAN_SL_STATE 0x00000400 +#define HCI_LE_INIT_MA_STATE 0x00000800 /* LE Supported States */ /* Non Connectable Adv state is supported. 0x0000000000000001 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF 0 -#define HCI_LE_STATES_NON_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF 0 +#define HCI_LE_STATES_NON_CONN_ADV_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK) /* Scanneable Connectable Adv state is supported. 0x0000000000000002 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASK 0x02 -#define HCI_SUPP_LE_STATESSCAN_ADV_OFF 0 -#define HCI_LE_STATES_SCAN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATESSCAN_ADV_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASK 0x02 +#define HCI_SUPP_LE_STATESSCAN_ADV_OFF 0 +#define HCI_LE_STATES_SCAN_ADV_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATESSCAN_ADV_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASK) /* Connectable Adv state is supported. 0x0000000000000004 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_MASK 0x04 -#define HCI_SUPP_LE_STATES_CONN_ADV_OFF 0 -#define HCI_LE_STATES_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_MASK 0x04 +#define HCI_SUPP_LE_STATES_CONN_ADV_OFF 0 +#define HCI_LE_STATES_CONN_ADV_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASK) /* Hi duty Cycle Directed Adv state is supported. 0x0000000000000008 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK 0x08 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF 0 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK 0x08 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF 0 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK) /* Passive Scan state is supported. 0x0000000000000010 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASK 0x10 -#define HCI_SUPP_LE_STATES_PASS_SCAN_OFF 0 -#define HCI_LE_STATES_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASK) +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASK 0x10 +#define HCI_SUPP_LE_STATES_PASS_SCAN_OFF 0 +#define HCI_LE_STATES_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASK) /* Active Scan state is supported. 0x0000000000000020 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK 0x20 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF 0 -#define HCI_LE_STATES_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK) +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK 0x20 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF 0 +#define HCI_LE_STATES_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK) /* Initiating state is supported. 0x0000000000000040 (or connection state in * master role is also supported) */ -#define HCI_SUPP_LE_STATES_INIT_MASK 0x40 -#define HCI_SUPP_LE_STATES_INIT_OFF 0 -#define HCI_LE_STATES_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_OFF] & HCI_SUPP_LE_STATES_INIT_MASK) +#define HCI_SUPP_LE_STATES_INIT_MASK 0x40 +#define HCI_SUPP_LE_STATES_INIT_OFF 0 +#define HCI_LE_STATES_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_INIT_OFF] & HCI_SUPP_LE_STATES_INIT_MASK) /* connection state in slave role is also supported. 0x0000000000000080 */ -#define HCI_SUPP_LE_STATES_SLAVE_MASK 0x80 -#define HCI_SUPP_LE_STATES_SLAVE_OFF 0 -#define HCI_LE_STATES_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SLAVE_OFF] & HCI_SUPP_LE_STATES_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_SLAVE_MASK 0x80 +#define HCI_SUPP_LE_STATES_SLAVE_OFF 0 +#define HCI_LE_STATES_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SLAVE_OFF] & HCI_SUPP_LE_STATES_SLAVE_MASK) /* Non Connectable Adv state and Passive Scanning State combination is * supported. 0x0000000000000100 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK) /* Scannable Adv state and Passive Scanning State combination is supported. * 0x0000000000000200 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK 0x02 -#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_SCAN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK 0x02 +#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_SCAN_ADV_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK) /* Connectable Adv state and Passive Scanning State combination is supported. * 0x0000000000000400 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK 0x04 -#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK 0x04 +#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_CONN_ADV_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK) /* High Duty Cycl Directed ADv and Passive Scanning State combination is * supported. 0x0000000000000800 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK 0x08 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK 0x08 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF 1 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF) /* Non Connectable Adv state and Passive Scanning State combination is * supported. 0x0000000000001000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK 0x10 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK 0x10 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK) /* Scannable Adv state and Active Scanning State combination is supported. * 0x0000000000002000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK 0x20 -#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK 0x20 +#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK) /* Connectable Adv state and Active Scanning State combination is supported. * 0x0000000000004000 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK 0x40 -#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK 0x40 +#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK) /* High Duty Cycl Directed ADv and ACtive Scanning State combination is * supported. 0x0000000000008000 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 1 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF) /* Non-Connectable Adv state and Initiating State combination is supported. * 0x0000000000010000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF 2 -#define HCI_LE_STATES_NON_CONN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF] & HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK 0x01 +#define HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF 2 +#define HCI_LE_STATES_NON_CONN_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK) /* Scannable Adv state and Initiating State combination is supported. * 0x0000000000020000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK 0x02 -#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK 0x02 +#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF] & \ + HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK) /* Non-Connectable Adv state and Master Role combination is supported. * 0x0000000000040000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK 0x04 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF 2 -#define HCI_LE_STATES_NON_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK 0x04 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF 2 +#define HCI_LE_STATES_NON_CONN_ADV_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK) /* Scannable Adv state and Master Role combination is supported. * 0x0000000000040000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK 0x08 -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK 0x08 +#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK) /* Non-Connectable Adv and Slave Role combination is supported. * 0x000000000100000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK 0x10 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF 2 -#define HCI_LE_STATES_NON_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK 0x10 +#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF 2 +#define HCI_LE_STATES_NON_CONN_ADV_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK) /* Scannable Adv and Slave Role combination is supported. 0x000000000200000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK 0x20 -#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK 0x20 +#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF 2 +#define HCI_LE_STATES_SCAN_ADV_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK) /* Passive Scan and Initiating State combination is supported. * 0x000000000400000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK 0x40 -#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF 2 -#define HCI_LE_STATES_PASS_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK) +#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK 0x40 +#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF 2 +#define HCI_LE_STATES_PASS_SCAN_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF] & \ + HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK) /* Active Scan and Initiating State combination is supported. * 0x000000000800000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK 0x80 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF 2 -#define HCI_LE_STATES_ACTIVE_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK) +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK 0x80 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF 2 +#define HCI_LE_STATES_ACTIVE_SCAN_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF] & \ + HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK) /* Passive Scan and Master Role combination is supported. 0x000000001000000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK 0x01 -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF 3 -#define HCI_LE_STATES_PASS_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK) +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK 0x01 +#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF 3 +#define HCI_LE_STATES_PASS_SCAN_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK) /* Active Scan and Master Role combination is supported. 0x000000002000000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK 0x02 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF 3 -#define HCI_LE_STATES_ACTIVE_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK) +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK 0x02 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF 3 +#define HCI_LE_STATES_ACTIVE_SCAN_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK) /* Passive Scan and Slave Role combination is supported. 0x000000004000000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK 0x04 -#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF 3 -#define HCI_LE_STATES_PASS_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK 0x04 +#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF 3 +#define HCI_LE_STATES_PASS_SCAN_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK) /* Active Scan and Slave Role combination is supported. 0x000000008000000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK 0x08 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF 3 -#define HCI_LE_STATES_ACTIVE_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK 0x08 +#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF 3 +#define HCI_LE_STATES_ACTIVE_SCAN_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK) /* Link Layer Topology Added States Combo */ /* Initiating State and Master Role combination supported. - Master Role and Master Role combination is also supported. 0x0000000010000000 */ -#define HCI_SUPP_LE_STATES_INIT_MASTER_MASK 0x10 -#define HCI_SUPP_LE_STATES_INIT_MASTER_OFF 3 -#define HCI_LE_STATES_INIT_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_MASK) + Master Role and Master Role combination is also supported. 0x0000000010000000 + */ +#define HCI_SUPP_LE_STATES_INIT_MASTER_MASK 0x10 +#define HCI_SUPP_LE_STATES_INIT_MASTER_OFF 3 +#define HCI_LE_STATES_INIT_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_INIT_MASTER_MASK) /* Low Duty Cycle Directed Advertising State . 0x0000000020000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASK 0x20 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_OFF 3 -#define HCI_LE_STATES_LOW_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASK 0x20 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_OFF 3 +#define HCI_LE_STATES_LOW_DUTY_DIR_ADV_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_OFF] & \ + HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_MASK) /* Low Duty Cycle Directed Advertising State and Passive scan combination. * 0x0000000040000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK 0x40 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF 3 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK 0x40 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF 3 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK) /* Low Duty Cycle Directed Advertising State and Active scan combination. * 0x0000000080000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 3 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 3 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF] & \ + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK) /* Connectable Advertising State and Initiating State combination supported. * 0x0000000100000000 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK 0x01 -#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF 4 -#define HCI_LE_STATES_CONN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK 0x01 +#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF 4 +#define HCI_LE_STATES_CONN_ADV_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF] & \ + HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK) /* High Duty Cycle Directed Advertising State and Initiating State combination * supported. */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK 0x02 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK 0x02 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK) /* Low Duty Cycle Directed Advertising State and Initiating State combination * supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK 0x04 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF 4 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK 0x04 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF 4 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF] & \ + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK) /* Connectable Advertising State and Master Role combination supported.*/ -#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK 0x08 -#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK 0x08 +#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_CONN_ADV_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK) /* High Duty Cycle Directed Advertising State and Master Role combination * supported.*/ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK 0x10 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK 0x10 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK) /* Low Duty Cycle Directed Advertising State and Master Role combination * supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK 0x20 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK 0x20 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF 4 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF] & \ + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK) /* Connectable Advertising State and Slave Role combination supported. */ -#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK 0x40 -#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF 4 -#define HCI_LE_STATES_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK 0x40 +#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF 4 +#define HCI_LE_STATES_CONN_ADV_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK) /* High Duty Cycle Directed Advertising State and slave Role combination * supported.*/ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK 0x80 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK 0x80 +#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF 4 +#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK) /* Low Duty Cycle Directed Advertising State and slave Role combination * supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK 0x01 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF 5 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK 0x01 +#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF 5 +#define HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK) /* Initiating State and Slave Role combination supported. Master Role and Slave Role combination also supported. */ -#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK 0x02 -#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF 5 -#define HCI_LE_STATES_INIT_MASTER_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK) +#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK 0x02 +#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF 5 +#define HCI_LE_STATES_INIT_MASTER_SLAVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF] & \ + HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK) /* * Definitions for HCI Events */ -#define HCI_INQUIRY_COMP_EVT 0x01 -#define HCI_INQUIRY_RESULT_EVT 0x02 -#define HCI_CONNECTION_COMP_EVT 0x03 -#define HCI_CONNECTION_REQUEST_EVT 0x04 -#define HCI_DISCONNECTION_COMP_EVT 0x05 -#define HCI_AUTHENTICATION_COMP_EVT 0x06 -#define HCI_RMT_NAME_REQUEST_COMP_EVT 0x07 -#define HCI_ENCRYPTION_CHANGE_EVT 0x08 -#define HCI_CHANGE_CONN_LINK_KEY_EVT 0x09 -#define HCI_MASTER_LINK_KEY_COMP_EVT 0x0A -#define HCI_READ_RMT_FEATURES_COMP_EVT 0x0B -#define HCI_READ_RMT_VERSION_COMP_EVT 0x0C -#define HCI_QOS_SETUP_COMP_EVT 0x0D -#define HCI_COMMAND_COMPLETE_EVT 0x0E -#define HCI_COMMAND_STATUS_EVT 0x0F -#define HCI_HARDWARE_ERROR_EVT 0x10 -#define HCI_FLUSH_OCCURED_EVT 0x11 -#define HCI_ROLE_CHANGE_EVT 0x12 -#define HCI_NUM_COMPL_DATA_PKTS_EVT 0x13 -#define HCI_MODE_CHANGE_EVT 0x14 -#define HCI_RETURN_LINK_KEYS_EVT 0x15 -#define HCI_PIN_CODE_REQUEST_EVT 0x16 -#define HCI_LINK_KEY_REQUEST_EVT 0x17 -#define HCI_LINK_KEY_NOTIFICATION_EVT 0x18 -#define HCI_LOOPBACK_COMMAND_EVT 0x19 -#define HCI_DATA_BUF_OVERFLOW_EVT 0x1A -#define HCI_MAX_SLOTS_CHANGED_EVT 0x1B -#define HCI_READ_CLOCK_OFF_COMP_EVT 0x1C -#define HCI_CONN_PKT_TYPE_CHANGE_EVT 0x1D -#define HCI_QOS_VIOLATION_EVT 0x1E -#define HCI_PAGE_SCAN_MODE_CHANGE_EVT 0x1F -#define HCI_PAGE_SCAN_REP_MODE_CHNG_EVT 0x20 -#define HCI_FLOW_SPECIFICATION_COMP_EVT 0x21 -#define HCI_INQUIRY_RSSI_RESULT_EVT 0x22 -#define HCI_READ_RMT_EXT_FEATURES_COMP_EVT 0x23 -#define HCI_ESCO_CONNECTION_COMP_EVT 0x2C -#define HCI_ESCO_CONNECTION_CHANGED_EVT 0x2D -#define HCI_SNIFF_SUB_RATE_EVT 0x2E -#define HCI_EXTENDED_INQUIRY_RESULT_EVT 0x2F +#define HCI_INQUIRY_COMP_EVT 0x01 +#define HCI_INQUIRY_RESULT_EVT 0x02 +#define HCI_CONNECTION_COMP_EVT 0x03 +#define HCI_CONNECTION_REQUEST_EVT 0x04 +#define HCI_DISCONNECTION_COMP_EVT 0x05 +#define HCI_AUTHENTICATION_COMP_EVT 0x06 +#define HCI_RMT_NAME_REQUEST_COMP_EVT 0x07 +#define HCI_ENCRYPTION_CHANGE_EVT 0x08 +#define HCI_CHANGE_CONN_LINK_KEY_EVT 0x09 +#define HCI_MASTER_LINK_KEY_COMP_EVT 0x0A +#define HCI_READ_RMT_FEATURES_COMP_EVT 0x0B +#define HCI_READ_RMT_VERSION_COMP_EVT 0x0C +#define HCI_QOS_SETUP_COMP_EVT 0x0D +#define HCI_COMMAND_COMPLETE_EVT 0x0E +#define HCI_COMMAND_STATUS_EVT 0x0F +#define HCI_HARDWARE_ERROR_EVT 0x10 +#define HCI_FLUSH_OCCURED_EVT 0x11 +#define HCI_ROLE_CHANGE_EVT 0x12 +#define HCI_NUM_COMPL_DATA_PKTS_EVT 0x13 +#define HCI_MODE_CHANGE_EVT 0x14 +#define HCI_RETURN_LINK_KEYS_EVT 0x15 +#define HCI_PIN_CODE_REQUEST_EVT 0x16 +#define HCI_LINK_KEY_REQUEST_EVT 0x17 +#define HCI_LINK_KEY_NOTIFICATION_EVT 0x18 +#define HCI_LOOPBACK_COMMAND_EVT 0x19 +#define HCI_DATA_BUF_OVERFLOW_EVT 0x1A +#define HCI_MAX_SLOTS_CHANGED_EVT 0x1B +#define HCI_READ_CLOCK_OFF_COMP_EVT 0x1C +#define HCI_CONN_PKT_TYPE_CHANGE_EVT 0x1D +#define HCI_QOS_VIOLATION_EVT 0x1E +#define HCI_PAGE_SCAN_MODE_CHANGE_EVT 0x1F +#define HCI_PAGE_SCAN_REP_MODE_CHNG_EVT 0x20 +#define HCI_FLOW_SPECIFICATION_COMP_EVT 0x21 +#define HCI_INQUIRY_RSSI_RESULT_EVT 0x22 +#define HCI_READ_RMT_EXT_FEATURES_COMP_EVT 0x23 +#define HCI_ESCO_CONNECTION_COMP_EVT 0x2C +#define HCI_ESCO_CONNECTION_CHANGED_EVT 0x2D +#define HCI_SNIFF_SUB_RATE_EVT 0x2E +#define HCI_EXTENDED_INQUIRY_RESULT_EVT 0x2F #define HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT 0x30 -#define HCI_IO_CAPABILITY_REQUEST_EVT 0x31 -#define HCI_IO_CAPABILITY_RESPONSE_EVT 0x32 -#define HCI_USER_CONFIRMATION_REQUEST_EVT 0x33 -#define HCI_USER_PASSKEY_REQUEST_EVT 0x34 -#define HCI_REMOTE_OOB_DATA_REQUEST_EVT 0x35 -#define HCI_SIMPLE_PAIRING_COMPLETE_EVT 0x36 -#define HCI_LINK_SUPER_TOUT_CHANGED_EVT 0x38 -#define HCI_ENHANCED_FLUSH_COMPLETE_EVT 0x39 -#define HCI_USER_PASSKEY_NOTIFY_EVT 0x3B -#define HCI_KEYPRESS_NOTIFY_EVT 0x3C -#define HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT 0x3D +#define HCI_IO_CAPABILITY_REQUEST_EVT 0x31 +#define HCI_IO_CAPABILITY_RESPONSE_EVT 0x32 +#define HCI_USER_CONFIRMATION_REQUEST_EVT 0x33 +#define HCI_USER_PASSKEY_REQUEST_EVT 0x34 +#define HCI_REMOTE_OOB_DATA_REQUEST_EVT 0x35 +#define HCI_SIMPLE_PAIRING_COMPLETE_EVT 0x36 +#define HCI_LINK_SUPER_TOUT_CHANGED_EVT 0x38 +#define HCI_ENHANCED_FLUSH_COMPLETE_EVT 0x39 +#define HCI_USER_PASSKEY_NOTIFY_EVT 0x3B +#define HCI_KEYPRESS_NOTIFY_EVT 0x3C +#define HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT 0x3D /*#define HCI_GENERIC_AMP_LINK_KEY_NOTIF_EVT 0x3E Removed from spec */ -#define HCI_PHYSICAL_LINK_COMP_EVT 0x40 -#define HCI_CHANNEL_SELECTED_EVT 0x41 -#define HCI_DISC_PHYSICAL_LINK_COMP_EVT 0x42 +#define HCI_PHYSICAL_LINK_COMP_EVT 0x40 +#define HCI_CHANNEL_SELECTED_EVT 0x41 +#define HCI_DISC_PHYSICAL_LINK_COMP_EVT 0x42 #define HCI_PHY_LINK_LOSS_EARLY_WARNING_EVT 0x43 -#define HCI_PHY_LINK_RECOVERY_EVT 0x44 -#define HCI_LOGICAL_LINK_COMP_EVT 0x45 -#define HCI_DISC_LOGICAL_LINK_COMP_EVT 0x46 -#define HCI_FLOW_SPEC_MODIFY_COMP_EVT 0x47 -#define HCI_NUM_COMPL_DATA_BLOCKS_EVT 0x48 -#define HCI_SHORT_RANGE_MODE_COMPLETE_EVT 0x4C -#define HCI_AMP_STATUS_CHANGE_EVT 0x4D +#define HCI_PHY_LINK_RECOVERY_EVT 0x44 +#define HCI_LOGICAL_LINK_COMP_EVT 0x45 +#define HCI_DISC_LOGICAL_LINK_COMP_EVT 0x46 +#define HCI_FLOW_SPEC_MODIFY_COMP_EVT 0x47 +#define HCI_NUM_COMPL_DATA_BLOCKS_EVT 0x48 +#define HCI_SHORT_RANGE_MODE_COMPLETE_EVT 0x4C +#define HCI_AMP_STATUS_CHANGE_EVT 0x4D #define HCI_SET_TRIGGERED_CLOCK_CAPTURE_EVT 0x4E /* ULP HCI Event */ -#define HCI_BLE_EVENT 0x3e +#define HCI_BLE_EVENT 0x3e /* ULP Event sub code */ -#define HCI_BLE_CONN_COMPLETE_EVT 0x01 -#define HCI_BLE_ADV_PKT_RPT_EVT 0x02 -#define HCI_BLE_LL_CONN_PARAM_UPD_EVT 0x03 -#define HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT 0x04 -#define HCI_BLE_LTK_REQ_EVT 0x05 -#define HCI_BLE_RC_PARAM_REQ_EVT 0x06 -#define HCI_BLE_DATA_LENGTH_CHANGE_EVT 0x07 -#define HCI_BLE_ENHANCED_CONN_COMPLETE_EVT 0x0a -#define HCI_BLE_DIRECT_ADV_EVT 0x0b +#define HCI_BLE_CONN_COMPLETE_EVT 0x01 +#define HCI_BLE_ADV_PKT_RPT_EVT 0x02 +#define HCI_BLE_LL_CONN_PARAM_UPD_EVT 0x03 +#define HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT 0x04 +#define HCI_BLE_LTK_REQ_EVT 0x05 +#define HCI_BLE_RC_PARAM_REQ_EVT 0x06 +#define HCI_BLE_DATA_LENGTH_CHANGE_EVT 0x07 +#define HCI_BLE_ENHANCED_CONN_COMPLETE_EVT 0x0a +#define HCI_BLE_DIRECT_ADV_EVT 0x0b /* Definitions for LE Channel Map */ -#define HCI_BLE_CHNL_MAP_SIZE 5 +#define HCI_BLE_CHNL_MAP_SIZE 5 -#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ -#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF - because conflict w/ TCI_EVT and per - specification compliant */ +#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ +#define HCI_NAP_TRACE_EVT \ + 0xFF /* was define 0xFE, 0xFD, change to 0xFF \ + because conflict w/ TCI_EVT and per \ + specification compliant */ /* * Defentions for HCI Error Codes that are past in the events */ -#define HCI_SUCCESS 0x00 -#define HCI_PENDING 0x00 -#define HCI_ERR_ILLEGAL_COMMAND 0x01 -#define HCI_ERR_NO_CONNECTION 0x02 -#define HCI_ERR_HW_FAILURE 0x03 -#define HCI_ERR_PAGE_TIMEOUT 0x04 -#define HCI_ERR_AUTH_FAILURE 0x05 -#define HCI_ERR_KEY_MISSING 0x06 -#define HCI_ERR_MEMORY_FULL 0x07 -#define HCI_ERR_CONNECTION_TOUT 0x08 -#define HCI_ERR_MAX_NUM_OF_CONNECTIONS 0x09 -#define HCI_ERR_MAX_NUM_OF_SCOS 0x0A -#define HCI_ERR_CONNECTION_EXISTS 0x0B -#define HCI_ERR_COMMAND_DISALLOWED 0x0C -#define HCI_ERR_HOST_REJECT_RESOURCES 0x0D -#define HCI_ERR_HOST_REJECT_SECURITY 0x0E -#define HCI_ERR_HOST_REJECT_DEVICE 0x0F -#define HCI_ERR_HOST_TIMEOUT 0x10 -#define HCI_ERR_UNSUPPORTED_VALUE 0x11 -#define HCI_ERR_ILLEGAL_PARAMETER_FMT 0x12 -#define HCI_ERR_PEER_USER 0x13 -#define HCI_ERR_PEER_LOW_RESOURCES 0x14 -#define HCI_ERR_PEER_POWER_OFF 0x15 -#define HCI_ERR_CONN_CAUSE_LOCAL_HOST 0x16 -#define HCI_ERR_REPEATED_ATTEMPTS 0x17 -#define HCI_ERR_PAIRING_NOT_ALLOWED 0x18 -#define HCI_ERR_UNKNOWN_LMP_PDU 0x19 -#define HCI_ERR_UNSUPPORTED_REM_FEATURE 0x1A -#define HCI_ERR_SCO_OFFSET_REJECTED 0x1B -#define HCI_ERR_SCO_INTERVAL_REJECTED 0x1C -#define HCI_ERR_SCO_AIR_MODE 0x1D -#define HCI_ERR_INVALID_LMP_PARAM 0x1E -#define HCI_ERR_UNSPECIFIED 0x1F -#define HCI_ERR_UNSUPPORTED_LMP_FEATURE 0x20 -#define HCI_ERR_ROLE_CHANGE_NOT_ALLOWED 0x21 -#define HCI_ERR_LMP_RESPONSE_TIMEOUT 0x22 -#define HCI_ERR_LMP_ERR_TRANS_COLLISION 0x23 -#define HCI_ERR_LMP_PDU_NOT_ALLOWED 0x24 -#define HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE 0x25 -#define HCI_ERR_UNIT_KEY_USED 0x26 -#define HCI_ERR_QOS_NOT_SUPPORTED 0x27 -#define HCI_ERR_INSTANT_PASSED 0x28 -#define HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 -#define HCI_ERR_DIFF_TRANSACTION_COLLISION 0x2A -#define HCI_ERR_UNDEFINED_0x2B 0x2B -#define HCI_ERR_QOS_UNACCEPTABLE_PARAM 0x2C -#define HCI_ERR_QOS_REJECTED 0x2D -#define HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED 0x2E -#define HCI_ERR_INSUFFCIENT_SECURITY 0x2F -#define HCI_ERR_PARAM_OUT_OF_RANGE 0x30 -#define HCI_ERR_UNDEFINED_0x31 0x31 -#define HCI_ERR_ROLE_SWITCH_PENDING 0x32 -#define HCI_ERR_UNDEFINED_0x33 0x33 -#define HCI_ERR_RESERVED_SLOT_VIOLATION 0x34 -#define HCI_ERR_ROLE_SWITCH_FAILED 0x35 -#define HCI_ERR_INQ_RSP_DATA_TOO_LARGE 0x36 -#define HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 -#define HCI_ERR_HOST_BUSY_PAIRING 0x38 -#define HCI_ERR_REJ_NO_SUITABLE_CHANNEL 0x39 -#define HCI_ERR_CONTROLLER_BUSY 0x3A -#define HCI_ERR_UNACCEPT_CONN_INTERVAL 0x3B -#define HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT 0x3C -#define HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE 0x3D -#define HCI_ERR_CONN_FAILED_ESTABLISHMENT 0x3E -#define HCI_ERR_MAC_CONNECTION_FAILED 0x3F +#define HCI_SUCCESS 0x00 +#define HCI_PENDING 0x00 +#define HCI_ERR_ILLEGAL_COMMAND 0x01 +#define HCI_ERR_NO_CONNECTION 0x02 +#define HCI_ERR_HW_FAILURE 0x03 +#define HCI_ERR_PAGE_TIMEOUT 0x04 +#define HCI_ERR_AUTH_FAILURE 0x05 +#define HCI_ERR_KEY_MISSING 0x06 +#define HCI_ERR_MEMORY_FULL 0x07 +#define HCI_ERR_CONNECTION_TOUT 0x08 +#define HCI_ERR_MAX_NUM_OF_CONNECTIONS 0x09 +#define HCI_ERR_MAX_NUM_OF_SCOS 0x0A +#define HCI_ERR_CONNECTION_EXISTS 0x0B +#define HCI_ERR_COMMAND_DISALLOWED 0x0C +#define HCI_ERR_HOST_REJECT_RESOURCES 0x0D +#define HCI_ERR_HOST_REJECT_SECURITY 0x0E +#define HCI_ERR_HOST_REJECT_DEVICE 0x0F +#define HCI_ERR_HOST_TIMEOUT 0x10 +#define HCI_ERR_UNSUPPORTED_VALUE 0x11 +#define HCI_ERR_ILLEGAL_PARAMETER_FMT 0x12 +#define HCI_ERR_PEER_USER 0x13 +#define HCI_ERR_PEER_LOW_RESOURCES 0x14 +#define HCI_ERR_PEER_POWER_OFF 0x15 +#define HCI_ERR_CONN_CAUSE_LOCAL_HOST 0x16 +#define HCI_ERR_REPEATED_ATTEMPTS 0x17 +#define HCI_ERR_PAIRING_NOT_ALLOWED 0x18 +#define HCI_ERR_UNKNOWN_LMP_PDU 0x19 +#define HCI_ERR_UNSUPPORTED_REM_FEATURE 0x1A +#define HCI_ERR_SCO_OFFSET_REJECTED 0x1B +#define HCI_ERR_SCO_INTERVAL_REJECTED 0x1C +#define HCI_ERR_SCO_AIR_MODE 0x1D +#define HCI_ERR_INVALID_LMP_PARAM 0x1E +#define HCI_ERR_UNSPECIFIED 0x1F +#define HCI_ERR_UNSUPPORTED_LMP_FEATURE 0x20 +#define HCI_ERR_ROLE_CHANGE_NOT_ALLOWED 0x21 +#define HCI_ERR_LMP_RESPONSE_TIMEOUT 0x22 +#define HCI_ERR_LMP_ERR_TRANS_COLLISION 0x23 +#define HCI_ERR_LMP_PDU_NOT_ALLOWED 0x24 +#define HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE 0x25 +#define HCI_ERR_UNIT_KEY_USED 0x26 +#define HCI_ERR_QOS_NOT_SUPPORTED 0x27 +#define HCI_ERR_INSTANT_PASSED 0x28 +#define HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 +#define HCI_ERR_DIFF_TRANSACTION_COLLISION 0x2A +#define HCI_ERR_UNDEFINED_0x2B 0x2B +#define HCI_ERR_QOS_UNACCEPTABLE_PARAM 0x2C +#define HCI_ERR_QOS_REJECTED 0x2D +#define HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED 0x2E +#define HCI_ERR_INSUFFCIENT_SECURITY 0x2F +#define HCI_ERR_PARAM_OUT_OF_RANGE 0x30 +#define HCI_ERR_UNDEFINED_0x31 0x31 +#define HCI_ERR_ROLE_SWITCH_PENDING 0x32 +#define HCI_ERR_UNDEFINED_0x33 0x33 +#define HCI_ERR_RESERVED_SLOT_VIOLATION 0x34 +#define HCI_ERR_ROLE_SWITCH_FAILED 0x35 +#define HCI_ERR_INQ_RSP_DATA_TOO_LARGE 0x36 +#define HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 +#define HCI_ERR_HOST_BUSY_PAIRING 0x38 +#define HCI_ERR_REJ_NO_SUITABLE_CHANNEL 0x39 +#define HCI_ERR_CONTROLLER_BUSY 0x3A +#define HCI_ERR_UNACCEPT_CONN_INTERVAL 0x3B +#define HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT 0x3C +#define HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE 0x3D +#define HCI_ERR_CONN_FAILED_ESTABLISHMENT 0x3E +#define HCI_ERR_MAC_CONNECTION_FAILED 0x3F /* ConnectionLess Broadcast errors */ -#define HCI_ERR_LT_ADDR_ALREADY_IN_USE 0x40 -#define HCI_ERR_LT_ADDR_NOT_ALLOCATED 0x41 -#define HCI_ERR_CLB_NOT_ENABLED 0x42 -#define HCI_ERR_CLB_DATA_TOO_BIG 0x43 +#define HCI_ERR_LT_ADDR_ALREADY_IN_USE 0x40 +#define HCI_ERR_LT_ADDR_NOT_ALLOCATED 0x41 +#define HCI_ERR_CLB_NOT_ENABLED 0x42 +#define HCI_ERR_CLB_DATA_TOO_BIG 0x43 -#define HCI_ERR_MAX_ERR 0x43 +#define HCI_ERR_MAX_ERR 0x43 -#define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF +#define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF /* * Definitions for HCI enable event */ -#define HCI_INQUIRY_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000001) -#define HCI_INQUIRY_RESULT_EV(p) (*((uint32_t *)(p)) & 0x00000002) -#define HCI_CONNECTION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000004) -#define HCI_CONNECTION_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00000008) -#define HCI_DISCONNECTION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000010) -#define HCI_AUTHENTICATION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000020) -#define HCI_RMT_NAME_REQUEST_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000040) -#define HCI_CHANGE_CONN_ENCRPT_ENABLE_EV(p) (*((uint32_t *)(p)) & 0x00000080) -#define HCI_CHANGE_CONN_LINK_KEY_EV(p) (*((uint32_t *)(p)) & 0x00000100) -#define HCI_MASTER_LINK_KEY_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000200) -#define HCI_READ_RMT_FEATURES_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000400) -#define HCI_READ_RMT_VERSION_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000800) -#define HCI_QOS_SETUP_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00001000) -#define HCI_COMMAND_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00002000) -#define HCI_COMMAND_STATUS_EV(p) (*((uint32_t *)(p)) & 0x00004000) -#define HCI_HARDWARE_ERROR_EV(p) (*((uint32_t *)(p)) & 0x00008000) -#define HCI_FLASH_OCCURED_EV(p) (*((uint32_t *)(p)) & 0x00010000) -#define HCI_ROLE_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x00020000) -#define HCI_NUM_COMPLETED_PKTS_EV(p) (*((uint32_t *)(p)) & 0x00040000) -#define HCI_MODE_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x00080000) -#define HCI_RETURN_LINK_KEYS_EV(p) (*((uint32_t *)(p)) & 0x00100000) -#define HCI_PIN_CODE_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00200000) -#define HCI_LINK_KEY_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00400000) -#define HCI_LINK_KEY_NOTIFICATION_EV(p) (*((uint32_t *)(p)) & 0x00800000) -#define HCI_LOOPBACK_COMMAND_EV(p) (*((uint32_t *)(p)) & 0x01000000) -#define HCI_DATA_BUF_OVERFLOW_EV(p) (*((uint32_t *)(p)) & 0x02000000) -#define HCI_MAX_SLOTS_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x04000000) -#define HCI_READ_CLOCK_OFFSET_COMP_EV(p) (*((uint32_t *)(p)) & 0x08000000) -#define HCI_CONN_PKT_TYPE_CHANGED_EV(p) (*((uint32_t *)(p)) & 0x10000000) -#define HCI_QOS_VIOLATION_EV(p) (*((uint32_t *)(p)) & 0x20000000) -#define HCI_PAGE_SCAN_MODE_CHANGED_EV(p) (*((uint32_t *)(p)) & 0x40000000) -#define HCI_PAGE_SCAN_REP_MODE_CHNG_EV(p) (*((uint32_t *)(p)) & 0x80000000) +#define HCI_INQUIRY_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00000001) +#define HCI_INQUIRY_RESULT_EV(p) (*((uint32_t*)(p)) & 0x00000002) +#define HCI_CONNECTION_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00000004) +#define HCI_CONNECTION_REQUEST_EV(p) (*((uint32_t*)(p)) & 0x00000008) +#define HCI_DISCONNECTION_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00000010) +#define HCI_AUTHENTICATION_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00000020) +#define HCI_RMT_NAME_REQUEST_COMPL_EV(p) (*((uint32_t*)(p)) & 0x00000040) +#define HCI_CHANGE_CONN_ENCRPT_ENABLE_EV(p) (*((uint32_t*)(p)) & 0x00000080) +#define HCI_CHANGE_CONN_LINK_KEY_EV(p) (*((uint32_t*)(p)) & 0x00000100) +#define HCI_MASTER_LINK_KEY_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00000200) +#define HCI_READ_RMT_FEATURES_COMPL_EV(p) (*((uint32_t*)(p)) & 0x00000400) +#define HCI_READ_RMT_VERSION_COMPL_EV(p) (*((uint32_t*)(p)) & 0x00000800) +#define HCI_QOS_SETUP_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00001000) +#define HCI_COMMAND_COMPLETE_EV(p) (*((uint32_t*)(p)) & 0x00002000) +#define HCI_COMMAND_STATUS_EV(p) (*((uint32_t*)(p)) & 0x00004000) +#define HCI_HARDWARE_ERROR_EV(p) (*((uint32_t*)(p)) & 0x00008000) +#define HCI_FLASH_OCCURED_EV(p) (*((uint32_t*)(p)) & 0x00010000) +#define HCI_ROLE_CHANGE_EV(p) (*((uint32_t*)(p)) & 0x00020000) +#define HCI_NUM_COMPLETED_PKTS_EV(p) (*((uint32_t*)(p)) & 0x00040000) +#define HCI_MODE_CHANGE_EV(p) (*((uint32_t*)(p)) & 0x00080000) +#define HCI_RETURN_LINK_KEYS_EV(p) (*((uint32_t*)(p)) & 0x00100000) +#define HCI_PIN_CODE_REQUEST_EV(p) (*((uint32_t*)(p)) & 0x00200000) +#define HCI_LINK_KEY_REQUEST_EV(p) (*((uint32_t*)(p)) & 0x00400000) +#define HCI_LINK_KEY_NOTIFICATION_EV(p) (*((uint32_t*)(p)) & 0x00800000) +#define HCI_LOOPBACK_COMMAND_EV(p) (*((uint32_t*)(p)) & 0x01000000) +#define HCI_DATA_BUF_OVERFLOW_EV(p) (*((uint32_t*)(p)) & 0x02000000) +#define HCI_MAX_SLOTS_CHANGE_EV(p) (*((uint32_t*)(p)) & 0x04000000) +#define HCI_READ_CLOCK_OFFSET_COMP_EV(p) (*((uint32_t*)(p)) & 0x08000000) +#define HCI_CONN_PKT_TYPE_CHANGED_EV(p) (*((uint32_t*)(p)) & 0x10000000) +#define HCI_QOS_VIOLATION_EV(p) (*((uint32_t*)(p)) & 0x20000000) +#define HCI_PAGE_SCAN_MODE_CHANGED_EV(p) (*((uint32_t*)(p)) & 0x40000000) +#define HCI_PAGE_SCAN_REP_MODE_CHNG_EV(p) (*((uint32_t*)(p)) & 0x80000000) /* the default event mask for 2.1+EDR (Lisbon) does not include Lisbon events */ -#define HCI_DEFAULT_EVENT_MASK_0 0xFFFFFFFF -#define HCI_DEFAULT_EVENT_MASK_1 0x00001FFF +#define HCI_DEFAULT_EVENT_MASK_0 0xFFFFFFFF +#define HCI_DEFAULT_EVENT_MASK_1 0x00001FFF /* the event mask for 2.0 + EDR and later (includes Lisbon events) */ -#define HCI_LISBON_EVENT_MASK_0 0xFFFFFFFF -#define HCI_LISBON_EVENT_MASK_1 0x1DBFFFFF -#define HCI_LISBON_EVENT_MASK {0x0D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} -#define HCI_LISBON_EVENT_MASK_EXT {0x1D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} -#define HCI_DUMO_EVENT_MASK_EXT {0x3D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} +#define HCI_LISBON_EVENT_MASK_0 0xFFFFFFFF +#define HCI_LISBON_EVENT_MASK_1 0x1DBFFFFF +#define HCI_LISBON_EVENT_MASK \ + { 0x0D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } +#define HCI_LISBON_EVENT_MASK_EXT \ + { 0x1D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } +#define HCI_DUMO_EVENT_MASK_EXT \ + { 0x3D, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } /* 0x00001FFF FFFFFFFF Default - no Lisbon events 0x00000800 00000000 Synchronous Connection Complete Event 0x00001000 00000000 Synchronous Connection Changed Event @@ -887,9 +977,8 @@ 0x20000000 00000000 LE Meta Event */ - /* the event mask for AMP controllers */ -#define HCI_AMP_EVENT_MASK_3_0 "\x00\x00\x00\x00\x00\x00\x3F\xFF" +#define HCI_AMP_EVENT_MASK_3_0 "\x00\x00\x00\x00\x00\x00\x3F\xFF" /* 0x0000000000000000 No events specified (default) 0x0000000000000001 Physical Link Complete Event @@ -909,7 +998,7 @@ */ /* the event mask page 2 (CLB + CSA4) for BR/EDR controller */ -#define HCI_PAGE_2_EVENT_MASK "\x00\x00\x00\x00\x00\x7F\xC0\x00" +#define HCI_PAGE_2_EVENT_MASK "\x00\x00\x00\x00\x00\x7F\xC0\x00" /* 0x0000000000004000 Triggered Clock Capture Event 0x0000000000008000 Sync Train Complete Event 0x0000000000010000 Sync Train Received Event @@ -922,1567 +1011,1970 @@ */ #if (BLE_PRIVACY_SPT == TRUE) /* BLE event mask */ -#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x07\xff" +#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x07\xff" #else -#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x00\x7f" +#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x00\x7f" #endif /* * Definitions for packet type masks (BT1.2 and BT2.0 definitions) */ -#define HCI_PKT_TYPES_MASK_NO_2_DH1 0x0002 -#define HCI_PKT_TYPES_MASK_NO_3_DH1 0x0004 -#define HCI_PKT_TYPES_MASK_DM1 0x0008 -#define HCI_PKT_TYPES_MASK_DH1 0x0010 -#define HCI_PKT_TYPES_MASK_HV1 0x0020 -#define HCI_PKT_TYPES_MASK_HV2 0x0040 -#define HCI_PKT_TYPES_MASK_HV3 0x0080 -#define HCI_PKT_TYPES_MASK_NO_2_DH3 0x0100 -#define HCI_PKT_TYPES_MASK_NO_3_DH3 0x0200 -#define HCI_PKT_TYPES_MASK_DM3 0x0400 -#define HCI_PKT_TYPES_MASK_DH3 0x0800 -#define HCI_PKT_TYPES_MASK_NO_2_DH5 0x1000 -#define HCI_PKT_TYPES_MASK_NO_3_DH5 0x2000 -#define HCI_PKT_TYPES_MASK_DM5 0x4000 -#define HCI_PKT_TYPES_MASK_DH5 0x8000 +#define HCI_PKT_TYPES_MASK_NO_2_DH1 0x0002 +#define HCI_PKT_TYPES_MASK_NO_3_DH1 0x0004 +#define HCI_PKT_TYPES_MASK_DM1 0x0008 +#define HCI_PKT_TYPES_MASK_DH1 0x0010 +#define HCI_PKT_TYPES_MASK_HV1 0x0020 +#define HCI_PKT_TYPES_MASK_HV2 0x0040 +#define HCI_PKT_TYPES_MASK_HV3 0x0080 +#define HCI_PKT_TYPES_MASK_NO_2_DH3 0x0100 +#define HCI_PKT_TYPES_MASK_NO_3_DH3 0x0200 +#define HCI_PKT_TYPES_MASK_DM3 0x0400 +#define HCI_PKT_TYPES_MASK_DH3 0x0800 +#define HCI_PKT_TYPES_MASK_NO_2_DH5 0x1000 +#define HCI_PKT_TYPES_MASK_NO_3_DH5 0x2000 +#define HCI_PKT_TYPES_MASK_DM5 0x4000 +#define HCI_PKT_TYPES_MASK_DH5 0x8000 /* Packet type should be one of valid but at least one should be specified */ -#define HCI_VALID_SCO_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_HV1 \ - | HCI_PKT_TYPES_MASK_HV2 \ - | HCI_PKT_TYPES_MASK_HV3)) == 0)) \ - && ((t) != 0)) - - - - +#define HCI_VALID_SCO_PKT_TYPE(t) \ + (((((t) & \ + ~(HCI_PKT_TYPES_MASK_HV1 | HCI_PKT_TYPES_MASK_HV2 | \ + HCI_PKT_TYPES_MASK_HV3)) == 0)) && \ + ((t) != 0)) /* Packet type should not be invalid and at least one should be specified */ -#define HCI_VALID_ACL_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_DM1 \ - | HCI_PKT_TYPES_MASK_DH1 \ - | HCI_PKT_TYPES_MASK_DM3 \ - | HCI_PKT_TYPES_MASK_DH3 \ - | HCI_PKT_TYPES_MASK_DM5 \ - | HCI_PKT_TYPES_MASK_DH5 \ - | HCI_PKT_TYPES_MASK_NO_2_DH1 \ - | HCI_PKT_TYPES_MASK_NO_3_DH1 \ - | HCI_PKT_TYPES_MASK_NO_2_DH3 \ - | HCI_PKT_TYPES_MASK_NO_3_DH3 \ - | HCI_PKT_TYPES_MASK_NO_2_DH5 \ - | HCI_PKT_TYPES_MASK_NO_3_DH5 )) == 0)) \ - && (((t) & (HCI_PKT_TYPES_MASK_DM1 \ - | HCI_PKT_TYPES_MASK_DH1 \ - | HCI_PKT_TYPES_MASK_DM3 \ - | HCI_PKT_TYPES_MASK_DH3 \ - | HCI_PKT_TYPES_MASK_DM5 \ - | HCI_PKT_TYPES_MASK_DH5)) != 0)) +#define HCI_VALID_ACL_PKT_TYPE(t) \ + (((((t) & \ + ~(HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | \ + HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 | \ + HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5 | \ + HCI_PKT_TYPES_MASK_NO_2_DH1 | HCI_PKT_TYPES_MASK_NO_3_DH1 | \ + HCI_PKT_TYPES_MASK_NO_2_DH3 | HCI_PKT_TYPES_MASK_NO_3_DH3 | \ + HCI_PKT_TYPES_MASK_NO_2_DH5 | HCI_PKT_TYPES_MASK_NO_3_DH5)) == 0)) && \ + (((t) & (HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | \ + HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 | \ + HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5)) != 0)) /* * Definitions for eSCO packet type masks (BT1.2 and BT2.0 definitions) */ -#define HCI_ESCO_PKT_TYPES_MASK_HV1 0x0001 -#define HCI_ESCO_PKT_TYPES_MASK_HV2 0x0002 -#define HCI_ESCO_PKT_TYPES_MASK_HV3 0x0004 -#define HCI_ESCO_PKT_TYPES_MASK_EV3 0x0008 -#define HCI_ESCO_PKT_TYPES_MASK_EV4 0x0010 -#define HCI_ESCO_PKT_TYPES_MASK_EV5 0x0020 -#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 0x0040 -#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 0x0080 -#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 0x0100 -#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 0x0200 +#define HCI_ESCO_PKT_TYPES_MASK_HV1 0x0001 +#define HCI_ESCO_PKT_TYPES_MASK_HV2 0x0002 +#define HCI_ESCO_PKT_TYPES_MASK_HV3 0x0004 +#define HCI_ESCO_PKT_TYPES_MASK_EV3 0x0008 +#define HCI_ESCO_PKT_TYPES_MASK_EV4 0x0010 +#define HCI_ESCO_PKT_TYPES_MASK_EV5 0x0020 +#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 0x0040 +#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 0x0080 +#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 0x0100 +#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 0x0200 /* Packet type should be one of valid but at least one should be specified for * 1.2 */ -#define HCI_VALID_ESCO_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_EV3 \ - | HCI_ESCO_PKT_TYPES_MASK_EV4 \ - | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) \ - && ((t) != 0)) - -#define HCI_VALID_ESCO_SCOPKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 \ - | HCI_ESCO_PKT_TYPES_MASK_HV2 \ - | HCI_ESCO_PKT_TYPES_MASK_HV3)) == 0)) \ - && ((t) != 0)) - -#define HCI_VALID_SCO_ALL_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 \ - | HCI_ESCO_PKT_TYPES_MASK_HV2 \ - | HCI_ESCO_PKT_TYPES_MASK_HV3 \ - | HCI_ESCO_PKT_TYPES_MASK_EV3 \ - | HCI_ESCO_PKT_TYPES_MASK_EV4 \ - | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) \ - && ((t) != 0)) +#define HCI_VALID_ESCO_PKT_TYPE(t) \ + (((((t) & \ + ~(HCI_ESCO_PKT_TYPES_MASK_EV3 | HCI_ESCO_PKT_TYPES_MASK_EV4 | \ + HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) && \ + ((t) != 0)) + +#define HCI_VALID_ESCO_SCOPKT_TYPE(t) \ + (((((t) & \ + ~(HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | \ + HCI_ESCO_PKT_TYPES_MASK_HV3)) == 0)) && \ + ((t) != 0)) + +#define HCI_VALID_SCO_ALL_PKT_TYPE(t) \ + (((((t) & \ + ~(HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | \ + HCI_ESCO_PKT_TYPES_MASK_HV3 | HCI_ESCO_PKT_TYPES_MASK_EV3 | \ + HCI_ESCO_PKT_TYPES_MASK_EV4 | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) && \ + ((t) != 0)) /* * Define parameters to allow role switch during create connection */ -#define HCI_CR_CONN_NOT_ALLOW_SWITCH 0x00 -#define HCI_CR_CONN_ALLOW_SWITCH 0x01 +#define HCI_CR_CONN_NOT_ALLOW_SWITCH 0x00 +#define HCI_CR_CONN_ALLOW_SWITCH 0x01 /* * Hold Mode command destination */ -#define HOLD_MODE_DEST_LOCAL_DEVICE 0x00 -#define HOLD_MODE_DEST_RMT_DEVICE 0x01 +#define HOLD_MODE_DEST_LOCAL_DEVICE 0x00 +#define HOLD_MODE_DEST_RMT_DEVICE 0x01 /* * Definitions for different HCI parameters */ -#define HCI_PER_INQ_MIN_MAX_PERIOD 0x0003 -#define HCI_PER_INQ_MAX_MAX_PERIOD 0xFFFF -#define HCI_PER_INQ_MIN_MIN_PERIOD 0x0002 -#define HCI_PER_INQ_MAX_MIN_PERIOD 0xFFFE +#define HCI_PER_INQ_MIN_MAX_PERIOD 0x0003 +#define HCI_PER_INQ_MAX_MAX_PERIOD 0xFFFF +#define HCI_PER_INQ_MIN_MIN_PERIOD 0x0002 +#define HCI_PER_INQ_MAX_MIN_PERIOD 0xFFFE -#define HCI_MAX_INQUIRY_LENGTH 0x30 +#define HCI_MAX_INQUIRY_LENGTH 0x30 -#define HCI_MIN_INQ_LAP 0x9E8B00 -#define HCI_MAX_INQ_LAP 0x9E8B3F +#define HCI_MIN_INQ_LAP 0x9E8B00 +#define HCI_MAX_INQ_LAP 0x9E8B3F /* HCI role defenitions */ -#define HCI_ROLE_MASTER 0x00 -#define HCI_ROLE_SLAVE 0x01 -#define HCI_ROLE_UNKNOWN 0xff +#define HCI_ROLE_MASTER 0x00 +#define HCI_ROLE_SLAVE 0x01 +#define HCI_ROLE_UNKNOWN 0xff /* HCI mode defenitions */ -#define HCI_MODE_ACTIVE 0x00 -#define HCI_MODE_HOLD 0x01 -#define HCI_MODE_SNIFF 0x02 -#define HCI_MODE_PARK 0x03 +#define HCI_MODE_ACTIVE 0x00 +#define HCI_MODE_HOLD 0x01 +#define HCI_MODE_SNIFF 0x02 +#define HCI_MODE_PARK 0x03 /* HCI Flow Control Mode defenitions */ -#define HCI_PACKET_BASED_FC_MODE 0x00 -#define HCI_BLOCK_BASED_FC_MODE 0x01 +#define HCI_PACKET_BASED_FC_MODE 0x00 +#define HCI_BLOCK_BASED_FC_MODE 0x01 /* Define Packet types as requested by the Host */ -#define HCI_ACL_PKT_TYPE_NONE 0x0000 -#define HCI_ACL_PKT_TYPE_DM1 0x0008 -#define HCI_ACL_PKT_TYPE_DH1 0x0010 -#define HCI_ACL_PKT_TYPE_AUX1 0x0200 -#define HCI_ACL_PKT_TYPE_DM3 0x0400 -#define HCI_ACL_PKT_TYPE_DH3 0x0800 -#define HCI_ACL_PKT_TYPE_DM5 0x4000 -#define HCI_ACL_PKT_TYPE_DH5 0x8000 +#define HCI_ACL_PKT_TYPE_NONE 0x0000 +#define HCI_ACL_PKT_TYPE_DM1 0x0008 +#define HCI_ACL_PKT_TYPE_DH1 0x0010 +#define HCI_ACL_PKT_TYPE_AUX1 0x0200 +#define HCI_ACL_PKT_TYPE_DM3 0x0400 +#define HCI_ACL_PKT_TYPE_DH3 0x0800 +#define HCI_ACL_PKT_TYPE_DM5 0x4000 +#define HCI_ACL_PKT_TYPE_DH5 0x8000 /* Define key type in the Master Link Key command */ -#define HCI_USE_SEMI_PERMANENT_KEY 0x00 -#define HCI_USE_TEMPORARY_KEY 0x01 +#define HCI_USE_SEMI_PERMANENT_KEY 0x00 +#define HCI_USE_TEMPORARY_KEY 0x01 /* Page scan period modes */ -#define HCI_PAGE_SCAN_REP_MODE_R0 0x00 -#define HCI_PAGE_SCAN_REP_MODE_R1 0x01 -#define HCI_PAGE_SCAN_REP_MODE_R2 0x02 +#define HCI_PAGE_SCAN_REP_MODE_R0 0x00 +#define HCI_PAGE_SCAN_REP_MODE_R1 0x01 +#define HCI_PAGE_SCAN_REP_MODE_R2 0x02 /* Define limits for page scan repetition modes */ -#define HCI_PAGE_SCAN_R1_LIMIT 0x0800 -#define HCI_PAGE_SCAN_R2_LIMIT 0x1000 +#define HCI_PAGE_SCAN_R1_LIMIT 0x0800 +#define HCI_PAGE_SCAN_R2_LIMIT 0x1000 /* Page scan period modes */ -#define HCI_PAGE_SCAN_PER_MODE_P0 0x00 -#define HCI_PAGE_SCAN_PER_MODE_P1 0x01 -#define HCI_PAGE_SCAN_PER_MODE_P2 0x02 +#define HCI_PAGE_SCAN_PER_MODE_P0 0x00 +#define HCI_PAGE_SCAN_PER_MODE_P1 0x01 +#define HCI_PAGE_SCAN_PER_MODE_P2 0x02 /* Page scan modes */ -#define HCI_MANDATARY_PAGE_SCAN_MODE 0x00 -#define HCI_OPTIONAL_PAGE_SCAN_MODE1 0x01 -#define HCI_OPTIONAL_PAGE_SCAN_MODE2 0x02 -#define HCI_OPTIONAL_PAGE_SCAN_MODE3 0x03 +#define HCI_MANDATARY_PAGE_SCAN_MODE 0x00 +#define HCI_OPTIONAL_PAGE_SCAN_MODE1 0x01 +#define HCI_OPTIONAL_PAGE_SCAN_MODE2 0x02 +#define HCI_OPTIONAL_PAGE_SCAN_MODE3 0x03 /* Page and inquiry scan types */ -#define HCI_SCAN_TYPE_STANDARD 0x00 -#define HCI_SCAN_TYPE_INTERLACED 0x01 /* 1.2 devices or later */ -#define HCI_DEF_SCAN_TYPE HCI_SCAN_TYPE_STANDARD +#define HCI_SCAN_TYPE_STANDARD 0x00 +#define HCI_SCAN_TYPE_INTERLACED 0x01 /* 1.2 devices or later */ +#define HCI_DEF_SCAN_TYPE HCI_SCAN_TYPE_STANDARD /* Definitions for quality of service service types */ -#define HCI_SERVICE_NO_TRAFFIC 0x00 -#define HCI_SERVICE_BEST_EFFORT 0x01 -#define HCI_SERVICE_GUARANTEED 0x02 +#define HCI_SERVICE_NO_TRAFFIC 0x00 +#define HCI_SERVICE_BEST_EFFORT 0x01 +#define HCI_SERVICE_GUARANTEED 0x02 -#define HCI_QOS_LATENCY_DO_NOT_CARE 0xFFFFFFFF -#define HCI_QOS_DELAY_DO_NOT_CARE 0xFFFFFFFF +#define HCI_QOS_LATENCY_DO_NOT_CARE 0xFFFFFFFF +#define HCI_QOS_DELAY_DO_NOT_CARE 0xFFFFFFFF /* Definitions for Flow Specification */ #define HCI_FLOW_SPEC_LATENCY_DO_NOT_CARE 0xFFFFFFFF /* Definitions for AFH Channel Map */ -#define HCI_AFH_CHANNEL_MAP_LEN 10 +#define HCI_AFH_CHANNEL_MAP_LEN 10 /* Definitions for Extended Inquiry Response */ -#define HCI_EXT_INQ_RESPONSE_LEN 240 -#define HCI_EIR_FLAGS_TYPE BT_EIR_FLAGS_TYPE -#define HCI_EIR_MORE_16BITS_UUID_TYPE BT_EIR_MORE_16BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_16BITS_UUID_TYPE BT_EIR_COMPLETE_16BITS_UUID_TYPE -#define HCI_EIR_MORE_32BITS_UUID_TYPE BT_EIR_MORE_32BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_32BITS_UUID_TYPE BT_EIR_COMPLETE_32BITS_UUID_TYPE -#define HCI_EIR_MORE_128BITS_UUID_TYPE BT_EIR_MORE_128BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_128BITS_UUID_TYPE BT_EIR_COMPLETE_128BITS_UUID_TYPE -#define HCI_EIR_SHORTENED_LOCAL_NAME_TYPE BT_EIR_SHORTENED_LOCAL_NAME_TYPE -#define HCI_EIR_COMPLETE_LOCAL_NAME_TYPE BT_EIR_COMPLETE_LOCAL_NAME_TYPE -#define HCI_EIR_TX_POWER_LEVEL_TYPE BT_EIR_TX_POWER_LEVEL_TYPE -#define HCI_EIR_MANUFACTURER_SPECIFIC_TYPE BT_EIR_MANUFACTURER_SPECIFIC_TYPE -#define HCI_EIR_SERVICE_DATA_TYPE BT_EIR_SERVICE_DATA_TYPE -#define HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE -#define HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE -#define HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE -#define HCI_EIR_OOB_BD_ADDR_TYPE BT_EIR_OOB_BD_ADDR_TYPE -#define HCI_EIR_OOB_COD_TYPE BT_EIR_OOB_COD_TYPE -#define HCI_EIR_OOB_SSP_HASH_C_TYPE BT_EIR_OOB_SSP_HASH_C_TYPE -#define HCI_EIR_OOB_SSP_RAND_R_TYPE BT_EIR_OOB_SSP_RAND_R_TYPE +#define HCI_EXT_INQ_RESPONSE_LEN 240 +#define HCI_EIR_FLAGS_TYPE BT_EIR_FLAGS_TYPE +#define HCI_EIR_MORE_16BITS_UUID_TYPE BT_EIR_MORE_16BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_16BITS_UUID_TYPE BT_EIR_COMPLETE_16BITS_UUID_TYPE +#define HCI_EIR_MORE_32BITS_UUID_TYPE BT_EIR_MORE_32BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_32BITS_UUID_TYPE BT_EIR_COMPLETE_32BITS_UUID_TYPE +#define HCI_EIR_MORE_128BITS_UUID_TYPE BT_EIR_MORE_128BITS_UUID_TYPE +#define HCI_EIR_COMPLETE_128BITS_UUID_TYPE BT_EIR_COMPLETE_128BITS_UUID_TYPE +#define HCI_EIR_SHORTENED_LOCAL_NAME_TYPE BT_EIR_SHORTENED_LOCAL_NAME_TYPE +#define HCI_EIR_COMPLETE_LOCAL_NAME_TYPE BT_EIR_COMPLETE_LOCAL_NAME_TYPE +#define HCI_EIR_TX_POWER_LEVEL_TYPE BT_EIR_TX_POWER_LEVEL_TYPE +#define HCI_EIR_MANUFACTURER_SPECIFIC_TYPE BT_EIR_MANUFACTURER_SPECIFIC_TYPE +#define HCI_EIR_SERVICE_DATA_TYPE BT_EIR_SERVICE_DATA_TYPE +#define HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE \ + BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE +#define HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE \ + BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE +#define HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE \ + BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE +#define HCI_EIR_OOB_BD_ADDR_TYPE BT_EIR_OOB_BD_ADDR_TYPE +#define HCI_EIR_OOB_COD_TYPE BT_EIR_OOB_COD_TYPE +#define HCI_EIR_OOB_SSP_HASH_C_TYPE BT_EIR_OOB_SSP_HASH_C_TYPE +#define HCI_EIR_OOB_SSP_RAND_R_TYPE BT_EIR_OOB_SSP_RAND_R_TYPE /* Definitions for Write Simple Pairing Mode */ -#define HCI_SP_MODE_UNDEFINED 0x00 -#define HCI_SP_MODE_ENABLED 0x01 +#define HCI_SP_MODE_UNDEFINED 0x00 +#define HCI_SP_MODE_ENABLED 0x01 /* Definitions for Write Simple Pairing Debug Mode */ -#define HCI_SPD_MODE_DISABLED 0x00 -#define HCI_SPD_MODE_ENABLED 0x01 +#define HCI_SPD_MODE_DISABLED 0x00 +#define HCI_SPD_MODE_ENABLED 0x01 /* Definitions for Write Secure Connections Host Support */ -#define HCI_SC_MODE_DISABLED 0x00 -#define HCI_SC_MODE_ENABLED 0x01 +#define HCI_SC_MODE_DISABLED 0x00 +#define HCI_SC_MODE_ENABLED 0x01 /* Definitions for IO Capability Response/Command */ -#define HCI_IO_CAP_DISPLAY_ONLY 0x00 -#define HCI_IO_CAP_DISPLAY_YESNO 0x01 -#define HCI_IO_CAP_KEYBOARD_ONLY 0x02 -#define HCI_IO_CAP_NO_IO 0x03 - -#define HCI_OOB_AUTH_DATA_NOT_PRESENT 0x00 -#define HCI_OOB_REM_AUTH_DATA_PRESENT 0x01 +#define HCI_IO_CAP_DISPLAY_ONLY 0x00 +#define HCI_IO_CAP_DISPLAY_YESNO 0x01 +#define HCI_IO_CAP_KEYBOARD_ONLY 0x02 +#define HCI_IO_CAP_NO_IO 0x03 -#define HCI_MITM_PROTECT_NOT_REQUIRED 0x00 -#define HCI_MITM_PROTECT_REQUIRED 0x01 +#define HCI_OOB_AUTH_DATA_NOT_PRESENT 0x00 +#define HCI_OOB_REM_AUTH_DATA_PRESENT 0x01 +#define HCI_MITM_PROTECT_NOT_REQUIRED 0x00 +#define HCI_MITM_PROTECT_REQUIRED 0x01 /* Policy settings status */ -#define HCI_DISABLE_ALL_LM_MODES 0x0000 -#define HCI_ENABLE_MASTER_SLAVE_SWITCH 0x0001 -#define HCI_ENABLE_HOLD_MODE 0x0002 -#define HCI_ENABLE_SNIFF_MODE 0x0004 -#define HCI_ENABLE_PARK_MODE 0x0008 +#define HCI_DISABLE_ALL_LM_MODES 0x0000 +#define HCI_ENABLE_MASTER_SLAVE_SWITCH 0x0001 +#define HCI_ENABLE_HOLD_MODE 0x0002 +#define HCI_ENABLE_SNIFF_MODE 0x0004 +#define HCI_ENABLE_PARK_MODE 0x0008 /* By default allow switch, because host can not allow that */ /* that until he created the connection */ -#define HCI_DEFAULT_POLICY_SETTINGS HCI_DISABLE_ALL_LM_MODES +#define HCI_DEFAULT_POLICY_SETTINGS HCI_DISABLE_ALL_LM_MODES /* Filters that are sent in set filter command */ -#define HCI_FILTER_TYPE_CLEAR_ALL 0x00 -#define HCI_FILTER_INQUIRY_RESULT 0x01 -#define HCI_FILTER_CONNECTION_SETUP 0x02 +#define HCI_FILTER_TYPE_CLEAR_ALL 0x00 +#define HCI_FILTER_INQUIRY_RESULT 0x01 +#define HCI_FILTER_CONNECTION_SETUP 0x02 -#define HCI_FILTER_COND_NEW_DEVICE 0x00 -#define HCI_FILTER_COND_DEVICE_CLASS 0x01 -#define HCI_FILTER_COND_BD_ADDR 0x02 +#define HCI_FILTER_COND_NEW_DEVICE 0x00 +#define HCI_FILTER_COND_DEVICE_CLASS 0x01 +#define HCI_FILTER_COND_BD_ADDR 0x02 -#define HCI_DO_NOT_AUTO_ACCEPT_CONNECT 1 +#define HCI_DO_NOT_AUTO_ACCEPT_CONNECT 1 /* role switch disabled */ -#define HCI_DO_AUTO_ACCEPT_CONNECT 2 +#define HCI_DO_AUTO_ACCEPT_CONNECT 2 /* role switch enabled (1.1 errata 1115) */ -#define HCI_DO_AUTO_ACCEPT_CONNECT_RS 3 +#define HCI_DO_AUTO_ACCEPT_CONNECT_RS 3 /* Auto accept flags */ -#define HCI_AUTO_ACCEPT_OFF 0x00 +#define HCI_AUTO_ACCEPT_OFF 0x00 #define HCI_AUTO_ACCEPT_ACL_CONNECTIONS 0x01 #define HCI_AUTO_ACCEPT_SCO_CONNECTIONS 0x02 /* PIN type */ -#define HCI_PIN_TYPE_VARIABLE 0 -#define HCI_PIN_TYPE_FIXED 1 +#define HCI_PIN_TYPE_VARIABLE 0 +#define HCI_PIN_TYPE_FIXED 1 /* Loopback Modes */ -#define HCI_LOOPBACK_MODE_DISABLED 0 -#define HCI_LOOPBACK_MODE_LOCAL 1 -#define HCI_LOOPBACK_MODE_REMOTE 2 +#define HCI_LOOPBACK_MODE_DISABLED 0 +#define HCI_LOOPBACK_MODE_LOCAL 1 +#define HCI_LOOPBACK_MODE_REMOTE 2 -#define SLOTS_PER_10MS 16 /* 0.625 ms slots in a 10 ms tick */ +#define SLOTS_PER_10MS 16 /* 0.625 ms slots in a 10 ms tick */ /* Maximum connection accept timeout in 0.625msec */ -#define HCI_MAX_CONN_ACCEPT_TOUT 0xB540 /* 29 sec */ -#define HCI_DEF_CONN_ACCEPT_TOUT 0x1F40 /* 5 sec */ +#define HCI_MAX_CONN_ACCEPT_TOUT 0xB540 /* 29 sec */ +#define HCI_DEF_CONN_ACCEPT_TOUT 0x1F40 /* 5 sec */ /* Page timeout is used in LC only and LC is counting down slots not using OS */ -#define HCI_DEFAULT_PAGE_TOUT 0x2000 /* 5.12 sec (in slots) */ +#define HCI_DEFAULT_PAGE_TOUT 0x2000 /* 5.12 sec (in slots) */ /* Scan enable flags */ -#define HCI_NO_SCAN_ENABLED 0x00 -#define HCI_INQUIRY_SCAN_ENABLED 0x01 -#define HCI_PAGE_SCAN_ENABLED 0x02 +#define HCI_NO_SCAN_ENABLED 0x00 +#define HCI_INQUIRY_SCAN_ENABLED 0x01 +#define HCI_PAGE_SCAN_ENABLED 0x02 /* Pagescan timer definitions in 0.625 ms */ -#define HCI_MIN_PAGESCAN_INTERVAL 0x12 /* 11.25 ms */ -#define HCI_MAX_PAGESCAN_INTERVAL 0x1000 /* 2.56 sec */ -#define HCI_DEF_PAGESCAN_INTERVAL 0x0800 /* 1.28 sec */ +#define HCI_MIN_PAGESCAN_INTERVAL 0x12 /* 11.25 ms */ +#define HCI_MAX_PAGESCAN_INTERVAL 0x1000 /* 2.56 sec */ +#define HCI_DEF_PAGESCAN_INTERVAL 0x0800 /* 1.28 sec */ /* Parameter for pagescan window is passed to LC and is kept in slots */ -#define HCI_MIN_PAGESCAN_WINDOW 0x11 /* 10.625 ms */ -#define HCI_MAX_PAGESCAN_WINDOW 0x1000 /* 2.56 sec */ -#define HCI_DEF_PAGESCAN_WINDOW 0x12 /* 11.25 ms */ +#define HCI_MIN_PAGESCAN_WINDOW 0x11 /* 10.625 ms */ +#define HCI_MAX_PAGESCAN_WINDOW 0x1000 /* 2.56 sec */ +#define HCI_DEF_PAGESCAN_WINDOW 0x12 /* 11.25 ms */ /* Inquiryscan timer definitions in 0.625 ms */ -#define HCI_MIN_INQUIRYSCAN_INTERVAL 0x12 /* 11.25 ms */ -#define HCI_MAX_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ -#define HCI_DEF_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ +#define HCI_MIN_INQUIRYSCAN_INTERVAL 0x12 /* 11.25 ms */ +#define HCI_MAX_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ +#define HCI_DEF_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ /* Parameter for inquiryscan window is passed to LC and is kept in slots */ -#define HCI_MIN_INQUIRYSCAN_WINDOW 0x11 /* 10.625 ms */ -#define HCI_MAX_INQUIRYSCAN_WINDOW 0x1000 /* 2.56 sec */ -#define HCI_DEF_INQUIRYSCAN_WINDOW 0x12 /* 11.25 ms */ +#define HCI_MIN_INQUIRYSCAN_WINDOW 0x11 /* 10.625 ms */ +#define HCI_MAX_INQUIRYSCAN_WINDOW 0x1000 /* 2.56 sec */ +#define HCI_DEF_INQUIRYSCAN_WINDOW 0x12 /* 11.25 ms */ /* Encryption modes */ -#define HCI_ENCRYPT_MODE_DISABLED 0x00 +#define HCI_ENCRYPT_MODE_DISABLED 0x00 #define HCI_ENCRYPT_MODE_POINT_TO_POINT 0x01 -#define HCI_ENCRYPT_MODE_ALL 0x02 +#define HCI_ENCRYPT_MODE_ALL 0x02 /* Voice settings */ -#define HCI_INP_CODING_LINEAR 0x0000 /* 0000000000 */ -#define HCI_INP_CODING_U_LAW 0x0100 /* 0100000000 */ -#define HCI_INP_CODING_A_LAW 0x0200 /* 1000000000 */ -#define HCI_INP_CODING_MASK 0x0300 /* 1100000000 */ +#define HCI_INP_CODING_LINEAR 0x0000 /* 0000000000 */ +#define HCI_INP_CODING_U_LAW 0x0100 /* 0100000000 */ +#define HCI_INP_CODING_A_LAW 0x0200 /* 1000000000 */ +#define HCI_INP_CODING_MASK 0x0300 /* 1100000000 */ -#define HCI_INP_DATA_FMT_1S_COMPLEMENT 0x0000 /* 0000000000 */ -#define HCI_INP_DATA_FMT_2S_COMPLEMENT 0x0040 /* 0001000000 */ +#define HCI_INP_DATA_FMT_1S_COMPLEMENT 0x0000 /* 0000000000 */ +#define HCI_INP_DATA_FMT_2S_COMPLEMENT 0x0040 /* 0001000000 */ #define HCI_INP_DATA_FMT_SIGN_MAGNITUDE 0x0080 /* 0010000000 */ -#define HCI_INP_DATA_FMT_UNSIGNED 0x00c0 /* 0011000000 */ -#define HCI_INP_DATA_FMT_MASK 0x00c0 /* 0011000000 */ +#define HCI_INP_DATA_FMT_UNSIGNED 0x00c0 /* 0011000000 */ +#define HCI_INP_DATA_FMT_MASK 0x00c0 /* 0011000000 */ -#define HCI_INP_SAMPLE_SIZE_8BIT 0x0000 /* 0000000000 */ -#define HCI_INP_SAMPLE_SIZE_16BIT 0x0020 /* 0000100000 */ -#define HCI_INP_SAMPLE_SIZE_MASK 0x0020 /* 0000100000 */ +#define HCI_INP_SAMPLE_SIZE_8BIT 0x0000 /* 0000000000 */ +#define HCI_INP_SAMPLE_SIZE_16BIT 0x0020 /* 0000100000 */ +#define HCI_INP_SAMPLE_SIZE_MASK 0x0020 /* 0000100000 */ #define HCI_INP_LINEAR_PCM_BIT_POS_MASK 0x001c /* 0000011100 */ #define HCI_INP_LINEAR_PCM_BIT_POS_OFFS 2 -#define HCI_AIR_CODING_FORMAT_CVSD 0x0000 /* 0000000000 */ -#define HCI_AIR_CODING_FORMAT_U_LAW 0x0001 /* 0000000001 */ -#define HCI_AIR_CODING_FORMAT_A_LAW 0x0002 /* 0000000010 */ -#define HCI_AIR_CODING_FORMAT_TRANSPNT 0x0003 /* 0000000011 */ -#define HCI_AIR_CODING_FORMAT_MASK 0x0003 /* 0000000011 */ +#define HCI_AIR_CODING_FORMAT_CVSD 0x0000 /* 0000000000 */ +#define HCI_AIR_CODING_FORMAT_U_LAW 0x0001 /* 0000000001 */ +#define HCI_AIR_CODING_FORMAT_A_LAW 0x0002 /* 0000000010 */ +#define HCI_AIR_CODING_FORMAT_TRANSPNT 0x0003 /* 0000000011 */ +#define HCI_AIR_CODING_FORMAT_MASK 0x0003 /* 0000000011 */ /* default 0001100000 */ -#define HCI_DEFAULT_VOICE_SETTINGS (HCI_INP_CODING_LINEAR \ - | HCI_INP_DATA_FMT_2S_COMPLEMENT \ - | HCI_INP_SAMPLE_SIZE_16BIT \ - | HCI_AIR_CODING_FORMAT_CVSD) - -#define HCI_CVSD_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_CVSD) -#define HCI_U_LAW_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_U_LAW) -#define HCI_A_LAW_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_A_LAW) -#define HCI_TRANSPNT_SUPPORTED(x) (((x) & HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_TRANSPNT) +#define HCI_DEFAULT_VOICE_SETTINGS \ + (HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \ + HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD) + +#define HCI_CVSD_SUPPORTED(x) \ + (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_CVSD) +#define HCI_U_LAW_SUPPORTED(x) \ + (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_U_LAW) +#define HCI_A_LAW_SUPPORTED(x) \ + (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_A_LAW) +#define HCI_TRANSPNT_SUPPORTED(x) \ + (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_TRANSPNT) /* Retransmit timer definitions in 0.625 */ -#define HCI_MAX_AUTO_FLUSH_TOUT 0x07FF -#define HCI_DEFAULT_AUTO_FLUSH_TOUT 0 /* No auto flush */ +#define HCI_MAX_AUTO_FLUSH_TOUT 0x07FF +#define HCI_DEFAULT_AUTO_FLUSH_TOUT 0 /* No auto flush */ /* Broadcast retransmitions */ -#define HCI_DEFAULT_NUM_BCAST_RETRAN 1 +#define HCI_DEFAULT_NUM_BCAST_RETRAN 1 /* Define broadcast data types as passed in the hci data packet */ -#define HCI_DATA_POINT_TO_POINT 0x00 -#define HCI_DATA_ACTIVE_BCAST 0x01 -#define HCI_DATA_PICONET_BCAST 0x02 +#define HCI_DATA_POINT_TO_POINT 0x00 +#define HCI_DATA_ACTIVE_BCAST 0x01 +#define HCI_DATA_PICONET_BCAST 0x02 /* Hold mode activity */ -#define HCI_MAINTAIN_CUR_POWER_STATE 0x00 -#define HCI_SUSPEND_PAGE_SCAN 0x01 -#define HCI_SUSPEND_INQUIRY_SCAN 0x02 -#define HCI_SUSPEND_PERIODIC_INQUIRIES 0x04 +#define HCI_MAINTAIN_CUR_POWER_STATE 0x00 +#define HCI_SUSPEND_PAGE_SCAN 0x01 +#define HCI_SUSPEND_INQUIRY_SCAN 0x02 +#define HCI_SUSPEND_PERIODIC_INQUIRIES 0x04 /* Default Link Supervision timeoout */ -#define HCI_DEFAULT_INACT_TOUT 0x7D00 /* BR/EDR (20 seconds) */ -#define HCI_DEFAULT_AMP_INACT_TOUT 0x3E80 /* AMP (10 seconds) */ +#define HCI_DEFAULT_INACT_TOUT 0x7D00 /* BR/EDR (20 seconds) */ +#define HCI_DEFAULT_AMP_INACT_TOUT 0x3E80 /* AMP (10 seconds) */ /* Read transmit power level parameter */ -#define HCI_READ_CURRENT 0x00 -#define HCI_READ_MAXIMUM 0x01 +#define HCI_READ_CURRENT 0x00 +#define HCI_READ_MAXIMUM 0x01 /* Link types for connection complete event */ -#define HCI_LINK_TYPE_SCO 0x00 -#define HCI_LINK_TYPE_ACL 0x01 -#define HCI_LINK_TYPE_ESCO 0x02 +#define HCI_LINK_TYPE_SCO 0x00 +#define HCI_LINK_TYPE_ACL 0x01 +#define HCI_LINK_TYPE_ESCO 0x02 /* Link Key Notification Event (Key Type) definitions */ -#define HCI_LKEY_TYPE_COMBINATION 0x00 -#define HCI_LKEY_TYPE_LOCAL_UNIT 0x01 -#define HCI_LKEY_TYPE_REMOTE_UNIT 0x02 -#define HCI_LKEY_TYPE_DEBUG_COMB 0x03 -#define HCI_LKEY_TYPE_UNAUTH_COMB 0x04 -#define HCI_LKEY_TYPE_AUTH_COMB 0x05 -#define HCI_LKEY_TYPE_CHANGED_COMB 0x06 +#define HCI_LKEY_TYPE_COMBINATION 0x00 +#define HCI_LKEY_TYPE_LOCAL_UNIT 0x01 +#define HCI_LKEY_TYPE_REMOTE_UNIT 0x02 +#define HCI_LKEY_TYPE_DEBUG_COMB 0x03 +#define HCI_LKEY_TYPE_UNAUTH_COMB 0x04 +#define HCI_LKEY_TYPE_AUTH_COMB 0x05 +#define HCI_LKEY_TYPE_CHANGED_COMB 0x06 #define HCI_LKEY_TYPE_UNAUTH_COMB_P_256 0x07 -#define HCI_LKEY_TYPE_AUTH_COMB_P_256 0x08 +#define HCI_LKEY_TYPE_AUTH_COMB_P_256 0x08 /* Internal definitions - not used over HCI */ -#define HCI_LKEY_TYPE_AMP_WIFI 0x80 -#define HCI_LKEY_TYPE_AMP_UWB 0x81 -#define HCI_LKEY_TYPE_UNKNOWN 0xff +#define HCI_LKEY_TYPE_AMP_WIFI 0x80 +#define HCI_LKEY_TYPE_AMP_UWB 0x81 +#define HCI_LKEY_TYPE_UNKNOWN 0xff /* Read Local Version HCI Version return values (Command Complete Event) */ -#define HCI_VERSION_1_0B 0x00 -#define HCI_VERSION_1_1 0x01 +#define HCI_VERSION_1_0B 0x00 +#define HCI_VERSION_1_1 0x01 /* Define an invalid value for a handle */ -#define HCI_INVALID_HANDLE 0xFFFF +#define HCI_INVALID_HANDLE 0xFFFF /* Define max ammount of data in the HCI command */ -#define HCI_COMMAND_SIZE 255 +#define HCI_COMMAND_SIZE 255 /* Define the preamble length for all HCI Commands. * This is 2-bytes for opcode and 1 byte for length */ -#define HCIC_PREAMBLE_SIZE 3 +#define HCIC_PREAMBLE_SIZE 3 /* Define the preamble length for all HCI Events * This is 1-byte for opcode and 1 byte for length */ -#define HCIE_PREAMBLE_SIZE 2 -#define HCI_SCO_PREAMBLE_SIZE 3 -#define HCI_DATA_PREAMBLE_SIZE 4 +#define HCIE_PREAMBLE_SIZE 2 +#define HCI_SCO_PREAMBLE_SIZE 3 +#define HCI_DATA_PREAMBLE_SIZE 4 /* local Bluetooth controller id for AMP HCI */ -#define LOCAL_BR_EDR_CONTROLLER_ID 0 +#define LOCAL_BR_EDR_CONTROLLER_ID 0 /* controller id types for AMP HCI */ -#define HCI_CONTROLLER_TYPE_BR_EDR 0 -#define HCI_CONTROLLER_TYPE_802_11 1 -#define HCI_CONTROLLER_TYPE_ECMA 2 -#define HCI_MAX_CONTROLLER_TYPES 3 +#define HCI_CONTROLLER_TYPE_BR_EDR 0 +#define HCI_CONTROLLER_TYPE_802_11 1 +#define HCI_CONTROLLER_TYPE_ECMA 2 +#define HCI_MAX_CONTROLLER_TYPES 3 /* ConnectionLess Broadcast */ -#define HCI_CLB_DISABLE 0x00 -#define HCI_CLB_ENABLE 0x01 +#define HCI_CLB_DISABLE 0x00 +#define HCI_CLB_ENABLE 0x01 /* ConnectionLess Broadcast Data fragment */ -#define HCI_CLB_FRAGMENT_CONT 0x00 -#define HCI_CLB_FRAGMENT_START 0x01 -#define HCI_CLB_FRAGMENT_END 0x02 -#define HCI_CLB_FRAGMENT_SINGLE 0x03 +#define HCI_CLB_FRAGMENT_CONT 0x00 +#define HCI_CLB_FRAGMENT_START 0x01 +#define HCI_CLB_FRAGMENT_END 0x02 +#define HCI_CLB_FRAGMENT_SINGLE 0x03 /* AMP Controller Status codes */ -#define HCI_AMP_CTRLR_PHYSICALLY_DOWN 0 -#define HCI_AMP_CTRLR_USABLE_BY_BT 1 -#define HCI_AMP_CTRLR_UNUSABLE_FOR_BT 2 -#define HCI_AMP_CTRLR_LOW_CAP_FOR_BT 3 -#define HCI_AMP_CTRLR_MED_CAP_FOR_BT 4 -#define HCI_AMP_CTRLR_HIGH_CAP_FOR_BT 5 -#define HCI_AMP_CTRLR_FULL_CAP_FOR_BT 6 - -#define HCI_MAX_AMP_STATUS_TYPES 7 +#define HCI_AMP_CTRLR_PHYSICALLY_DOWN 0 +#define HCI_AMP_CTRLR_USABLE_BY_BT 1 +#define HCI_AMP_CTRLR_UNUSABLE_FOR_BT 2 +#define HCI_AMP_CTRLR_LOW_CAP_FOR_BT 3 +#define HCI_AMP_CTRLR_MED_CAP_FOR_BT 4 +#define HCI_AMP_CTRLR_HIGH_CAP_FOR_BT 5 +#define HCI_AMP_CTRLR_FULL_CAP_FOR_BT 6 +#define HCI_MAX_AMP_STATUS_TYPES 7 /* Define the extended flow specification fields used by AMP */ -typedef struct -{ - uint8_t id; - uint8_t stype; - uint16_t max_sdu_size; - uint32_t sdu_inter_time; - uint32_t access_latency; - uint32_t flush_timeout; +typedef struct { + uint8_t id; + uint8_t stype; + uint16_t max_sdu_size; + uint32_t sdu_inter_time; + uint32_t access_latency; + uint32_t flush_timeout; } tHCI_EXT_FLOW_SPEC; - /* HCI message type definitions (for H4 messages) */ -#define HCIT_TYPE_COMMAND 1 -#define HCIT_TYPE_ACL_DATA 2 -#define HCIT_TYPE_SCO_DATA 3 -#define HCIT_TYPE_EVENT 4 -#define HCIT_TYPE_LM_DIAG 7 -#define HCIT_TYPE_NFC 16 +#define HCIT_TYPE_COMMAND 1 +#define HCIT_TYPE_ACL_DATA 2 +#define HCIT_TYPE_SCO_DATA 3 +#define HCIT_TYPE_EVENT 4 +#define HCIT_TYPE_LM_DIAG 7 +#define HCIT_TYPE_NFC 16 #define HCIT_LM_DIAG_LENGTH 63 /* Parameter information for HCI_BRCM_SET_ACL_PRIORITY */ -#define HCI_BRCM_ACL_PRIORITY_PARAM_SIZE 3 -#define HCI_BRCM_ACL_PRIORITY_LOW 0x00 -#define HCI_BRCM_ACL_PRIORITY_HIGH 0xFF -#define HCI_BRCM_SET_ACL_PRIORITY (0x0057 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_BRCM_ACL_PRIORITY_PARAM_SIZE 3 +#define HCI_BRCM_ACL_PRIORITY_LOW 0x00 +#define HCI_BRCM_ACL_PRIORITY_HIGH 0xFF +#define HCI_BRCM_SET_ACL_PRIORITY (0x0057 | HCI_GRP_VENDOR_SPECIFIC) /* Define values for LMP Test Control parameters * Test Scenario, Hopping Mode, Power Control Mode */ -#define LMP_TESTCTL_TESTSC_PAUSE 0 -#define LMP_TESTCTL_TESTSC_TXTEST_0 1 -#define LMP_TESTCTL_TESTSC_TXTEST_1 2 -#define LMP_TESTCTL_TESTSC_TXTEST_1010 3 +#define LMP_TESTCTL_TESTSC_PAUSE 0 +#define LMP_TESTCTL_TESTSC_TXTEST_0 1 +#define LMP_TESTCTL_TESTSC_TXTEST_1 2 +#define LMP_TESTCTL_TESTSC_TXTEST_1010 3 #define LMP_TESTCTL_TESTSC_PSRND_BITSEQ 4 #define LMP_TESTCTL_TESTSC_CLOSEDLB_ACL 5 #define LMP_TESTCTL_TESTSC_CLOSEDLB_SCO 6 -#define LMP_TESTCTL_TESTSC_ACL_NOWHIT 7 -#define LMP_TESTCTL_TESTSC_SCO_NOWHIT 8 -#define LMP_TESTCTL_TESTSC_TXTEST_11110000 9 +#define LMP_TESTCTL_TESTSC_ACL_NOWHIT 7 +#define LMP_TESTCTL_TESTSC_SCO_NOWHIT 8 +#define LMP_TESTCTL_TESTSC_TXTEST_11110000 9 #define LMP_TESTCTL_TESTSC_EXITTESTMODE 255 -#define LMP_TESTCTL_HOPMOD_RXTX1FREQ 0 -#define LMP_TESTCTL_HOPMOD_HOP_EURUSA 1 -#define LMP_TESTCTL_HOPMOD_HOP_JAPAN 2 -#define LMP_TESTCTL_HOPMOD_HOP_FRANCE 3 -#define LMP_TESTCTL_HOPMOD_HOP_SPAIN 4 -#define LMP_TESTCTL_HOPMOD_REDUCED_HOP 5 +#define LMP_TESTCTL_HOPMOD_RXTX1FREQ 0 +#define LMP_TESTCTL_HOPMOD_HOP_EURUSA 1 +#define LMP_TESTCTL_HOPMOD_HOP_JAPAN 2 +#define LMP_TESTCTL_HOPMOD_HOP_FRANCE 3 +#define LMP_TESTCTL_HOPMOD_HOP_SPAIN 4 +#define LMP_TESTCTL_HOPMOD_REDUCED_HOP 5 -#define LMP_TESTCTL_POWCTL_FIXEDTX_OP 0 -#define LMP_TESTCTL_POWCTL_ADAPTIVE 1 +#define LMP_TESTCTL_POWCTL_FIXEDTX_OP 0 +#define LMP_TESTCTL_POWCTL_ADAPTIVE 1 // TODO(zachoverflow): remove this once broadcom specific hacks are removed -#define LMP_COMPID_BROADCOM 15 +#define LMP_COMPID_BROADCOM 15 /* * Define the packet types in the packet header, and a couple extra */ -#define PKT_TYPE_NULL 0x00 -#define PKT_TYPE_POLL 0x01 -#define PKT_TYPE_FHS 0x02 -#define PKT_TYPE_DM1 0x03 +#define PKT_TYPE_NULL 0x00 +#define PKT_TYPE_POLL 0x01 +#define PKT_TYPE_FHS 0x02 +#define PKT_TYPE_DM1 0x03 -#define PKT_TYPE_DH1 0x04 -#define PKT_TYPE_HV1 0x05 -#define PKT_TYPE_HV2 0x06 -#define PKT_TYPE_HV3 0x07 -#define PKT_TYPE_DV 0x08 -#define PKT_TYPE_AUX1 0x09 +#define PKT_TYPE_DH1 0x04 +#define PKT_TYPE_HV1 0x05 +#define PKT_TYPE_HV2 0x06 +#define PKT_TYPE_HV3 0x07 +#define PKT_TYPE_DV 0x08 +#define PKT_TYPE_AUX1 0x09 -#define PKT_TYPE_DM3 0x0a -#define PKT_TYPE_DH3 0x0b +#define PKT_TYPE_DM3 0x0a +#define PKT_TYPE_DH3 0x0b -#define PKT_TYPE_DM5 0x0e -#define PKT_TYPE_DH5 0x0f +#define PKT_TYPE_DM5 0x0e +#define PKT_TYPE_DH5 0x0f - -#define PKT_TYPE_ID 0x10 /* Internally used packet types */ -#define PKT_TYPE_BAD 0x11 -#define PKT_TYPE_NONE 0x12 +#define PKT_TYPE_ID 0x10 /* Internally used packet types */ +#define PKT_TYPE_BAD 0x11 +#define PKT_TYPE_NONE 0x12 /* * Define packet size */ -#define HCI_DM1_PACKET_SIZE 17 -#define HCI_DH1_PACKET_SIZE 27 -#define HCI_DM3_PACKET_SIZE 121 -#define HCI_DH3_PACKET_SIZE 183 -#define HCI_DM5_PACKET_SIZE 224 -#define HCI_DH5_PACKET_SIZE 339 -#define HCI_AUX1_PACKET_SIZE 29 -#define HCI_HV1_PACKET_SIZE 10 -#define HCI_HV2_PACKET_SIZE 20 -#define HCI_HV3_PACKET_SIZE 30 -#define HCI_DV_PACKET_SIZE 9 -#define HCI_EDR2_DH1_PACKET_SIZE 54 -#define HCI_EDR2_DH3_PACKET_SIZE 367 -#define HCI_EDR2_DH5_PACKET_SIZE 679 -#define HCI_EDR3_DH1_PACKET_SIZE 83 -#define HCI_EDR3_DH3_PACKET_SIZE 552 -#define HCI_EDR3_DH5_PACKET_SIZE 1021 +#define HCI_DM1_PACKET_SIZE 17 +#define HCI_DH1_PACKET_SIZE 27 +#define HCI_DM3_PACKET_SIZE 121 +#define HCI_DH3_PACKET_SIZE 183 +#define HCI_DM5_PACKET_SIZE 224 +#define HCI_DH5_PACKET_SIZE 339 +#define HCI_AUX1_PACKET_SIZE 29 +#define HCI_HV1_PACKET_SIZE 10 +#define HCI_HV2_PACKET_SIZE 20 +#define HCI_HV3_PACKET_SIZE 30 +#define HCI_DV_PACKET_SIZE 9 +#define HCI_EDR2_DH1_PACKET_SIZE 54 +#define HCI_EDR2_DH3_PACKET_SIZE 367 +#define HCI_EDR2_DH5_PACKET_SIZE 679 +#define HCI_EDR3_DH1_PACKET_SIZE 83 +#define HCI_EDR3_DH3_PACKET_SIZE 552 +#define HCI_EDR3_DH5_PACKET_SIZE 1021 /* Feature Pages */ -#define HCI_EXT_FEATURES_PAGE_0 0 /* Extended Feature Page 0 (regular features) */ -#define HCI_EXT_FEATURES_PAGE_1 1 /* Extended Feature Page 1 */ -#define HCI_EXT_FEATURES_PAGE_2 2 /* Extended Feature Page 2 */ -#define HCI_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_2 +#define HCI_EXT_FEATURES_PAGE_0 \ + 0 /* Extended Feature Page 0 (regular features) */ +#define HCI_EXT_FEATURES_PAGE_1 1 /* Extended Feature Page 1 */ +#define HCI_EXT_FEATURES_PAGE_2 2 /* Extended Feature Page 2 */ +#define HCI_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_2 -#define HCI_FEATURE_BYTES_PER_PAGE 8 +#define HCI_FEATURE_BYTES_PER_PAGE 8 -#define HCI_FEATURES_KNOWN(x) (((x)[0] | (x)[1] | (x)[2] | (x)[3] | (x)[4] | (x)[5] | (x)[6] | (x)[7]) != 0) +#define HCI_FEATURES_KNOWN(x) \ + (((x)[0] | (x)[1] | (x)[2] | (x)[3] | (x)[4] | (x)[5] | (x)[6] | (x)[7]) != 0) /* * LMP features encoding - page 0 */ #define HCI_FEATURE_3_SLOT_PACKETS_MASK 0x01 -#define HCI_FEATURE_3_SLOT_PACKETS_OFF 0 -#define HCI_3_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_PACKETS_OFF] & HCI_FEATURE_3_SLOT_PACKETS_MASK) +#define HCI_FEATURE_3_SLOT_PACKETS_OFF 0 +#define HCI_3_SLOT_PACKETS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_3_SLOT_PACKETS_OFF] & HCI_FEATURE_3_SLOT_PACKETS_MASK) #define HCI_FEATURE_5_SLOT_PACKETS_MASK 0x02 -#define HCI_FEATURE_5_SLOT_PACKETS_OFF 0 -#define HCI_5_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_PACKETS_OFF] & HCI_FEATURE_5_SLOT_PACKETS_MASK) - -#define HCI_FEATURE_ENCRYPTION_MASK 0x04 -#define HCI_FEATURE_ENCRYPTION_OFF 0 -#define HCI_ENCRYPTION_SUPPORTED(x) ((x)[HCI_FEATURE_ENCRYPTION_OFF] & HCI_FEATURE_ENCRYPTION_MASK) - -#define HCI_FEATURE_SLOT_OFFSET_MASK 0x08 -#define HCI_FEATURE_SLOT_OFFSET_OFF 0 -#define HCI_SLOT_OFFSET_SUPPORTED(x) ((x)[HCI_FEATURE_SLOT_OFFSET_OFF] & HCI_FEATURE_SLOT_OFFSET_MASK) - -#define HCI_FEATURE_TIMING_ACC_MASK 0x10 -#define HCI_FEATURE_TIMING_ACC_OFF 0 -#define HCI_TIMING_ACC_SUPPORTED(x) ((x)[HCI_FEATURE_TIMING_ACC_OFF] & HCI_FEATURE_TIMING_ACC_MASK) - -#define HCI_FEATURE_SWITCH_MASK 0x20 -#define HCI_FEATURE_SWITCH_OFF 0 -#define HCI_SWITCH_SUPPORTED(x) ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK) - -#define HCI_FEATURE_HOLD_MODE_MASK 0x40 -#define HCI_FEATURE_HOLD_MODE_OFF 0 -#define HCI_HOLD_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_HOLD_MODE_OFF] & HCI_FEATURE_HOLD_MODE_MASK) - -#define HCI_FEATURE_SNIFF_MODE_MASK 0x80 -#define HCI_FEATURE_SNIFF_MODE_OFF 0 -#define HCI_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_MODE_OFF] & HCI_FEATURE_SNIFF_MODE_MASK) - -#define HCI_FEATURE_PARK_MODE_MASK 0x01 -#define HCI_FEATURE_PARK_MODE_OFF 1 -#define HCI_PARK_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_PARK_MODE_OFF] & HCI_FEATURE_PARK_MODE_MASK) - -#define HCI_FEATURE_RSSI_MASK 0x02 -#define HCI_FEATURE_RSSI_OFF 1 -#define HCI_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_RSSI_OFF] & HCI_FEATURE_RSSI_MASK) - -#define HCI_FEATURE_CQM_DATA_RATE_MASK 0x04 -#define HCI_FEATURE_CQM_DATA_RATE_OFF 1 -#define HCI_CQM_DATA_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_CQM_DATA_RATE_OFF] & HCI_FEATURE_CQM_DATA_RATE_MASK) - -#define HCI_FEATURE_SCO_LINK_MASK 0x08 -#define HCI_FEATURE_SCO_LINK_OFF 1 -#define HCI_SCO_LINK_SUPPORTED(x) ((x)[HCI_FEATURE_SCO_LINK_OFF] & HCI_FEATURE_SCO_LINK_MASK) - -#define HCI_FEATURE_HV2_PACKETS_MASK 0x10 -#define HCI_FEATURE_HV2_PACKETS_OFF 1 -#define HCI_HV2_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV2_PACKETS_OFF] & HCI_FEATURE_HV2_PACKETS_MASK) - -#define HCI_FEATURE_HV3_PACKETS_MASK 0x20 -#define HCI_FEATURE_HV3_PACKETS_OFF 1 -#define HCI_HV3_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV3_PACKETS_OFF] & HCI_FEATURE_HV3_PACKETS_MASK) - -#define HCI_FEATURE_U_LAW_MASK 0x40 -#define HCI_FEATURE_U_LAW_OFF 1 -#define HCI_LMP_U_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_U_LAW_OFF] & HCI_FEATURE_U_LAW_MASK) - -#define HCI_FEATURE_A_LAW_MASK 0x80 -#define HCI_FEATURE_A_LAW_OFF 1 -#define HCI_LMP_A_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_A_LAW_OFF] & HCI_FEATURE_A_LAW_MASK) - -#define HCI_FEATURE_CVSD_MASK 0x01 -#define HCI_FEATURE_CVSD_OFF 2 -#define HCI_LMP_CVSD_SUPPORTED(x) ((x)[HCI_FEATURE_CVSD_OFF] & HCI_FEATURE_CVSD_MASK) - -#define HCI_FEATURE_PAGING_SCHEME_MASK 0x02 -#define HCI_FEATURE_PAGING_SCHEME_OFF 2 -#define HCI_PAGING_SCHEME_SUPPORTED(x) ((x)[HCI_FEATURE_PAGING_SCHEME_OFF] & HCI_FEATURE_PAGING_SCHEME_MASK) - -#define HCI_FEATURE_POWER_CTRL_MASK 0x04 -#define HCI_FEATURE_POWER_CTRL_OFF 2 -#define HCI_POWER_CTRL_SUPPORTED(x) ((x)[HCI_FEATURE_POWER_CTRL_OFF] & HCI_FEATURE_POWER_CTRL_MASK) - -#define HCI_FEATURE_TRANSPNT_MASK 0x08 -#define HCI_FEATURE_TRANSPNT_OFF 2 -#define HCI_LMP_TRANSPNT_SUPPORTED(x) ((x)[HCI_FEATURE_TRANSPNT_OFF] & HCI_FEATURE_TRANSPNT_MASK) - -#define HCI_FEATURE_FLOW_CTRL_LAG_MASK 0x70 -#define HCI_FEATURE_FLOW_CTRL_LAG_OFF 2 -#define HCI_FLOW_CTRL_LAG_VALUE(x) (((x)[HCI_FEATURE_FLOW_CTRL_LAG_OFF] & HCI_FEATURE_FLOW_CTRL_LAG_MASK) >> 4) - -#define HCI_FEATURE_BROADCAST_ENC_MASK 0x80 -#define HCI_FEATURE_BROADCAST_ENC_OFF 2 -#define HCI_LMP_BCAST_ENC_SUPPORTED(x) ((x)[HCI_FEATURE_BROADCAST_ENC_OFF] & HCI_FEATURE_BROADCAST_ENC_MASK) - -#define HCI_FEATURE_SCATTER_MODE_MASK 0x01 -#define HCI_FEATURE_SCATTER_MODE_OFF 3 -#define HCI_LMP_SCATTER_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SCATTER_MODE_OFF] & HCI_FEATURE_SCATTER_MODE_MASK) - -#define HCI_FEATURE_EDR_ACL_2MPS_MASK 0x02 -#define HCI_FEATURE_EDR_ACL_2MPS_OFF 3 -#define HCI_EDR_ACL_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_2MPS_OFF] & HCI_FEATURE_EDR_ACL_2MPS_MASK) - -#define HCI_FEATURE_EDR_ACL_3MPS_MASK 0x04 -#define HCI_FEATURE_EDR_ACL_3MPS_OFF 3 -#define HCI_EDR_ACL_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_3MPS_OFF] & HCI_FEATURE_EDR_ACL_3MPS_MASK) - -#define HCI_FEATURE_ENHANCED_INQ_MASK 0x08 -#define HCI_FEATURE_ENHANCED_INQ_OFF 3 -#define HCI_ENHANCED_INQ_SUPPORTED(x) ((x)[HCI_FEATURE_ENHANCED_INQ_OFF] & HCI_FEATURE_ENHANCED_INQ_MASK) - -#define HCI_FEATURE_INTERLACED_INQ_SCAN_MASK 0x10 -#define HCI_FEATURE_INTERLACED_INQ_SCAN_OFF 3 -#define HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_INQ_SCAN_OFF] & HCI_FEATURE_INTERLACED_INQ_SCAN_MASK) - -#define HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK 0x20 -#define HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF 3 -#define HCI_LMP_INTERLACED_PAGE_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF] & HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK) - -#define HCI_FEATURE_INQ_RSSI_MASK 0x40 -#define HCI_FEATURE_INQ_RSSI_OFF 3 -#define HCI_LMP_INQ_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RSSI_OFF] & HCI_FEATURE_INQ_RSSI_MASK) - -#define HCI_FEATURE_ESCO_EV3_MASK 0x80 -#define HCI_FEATURE_ESCO_EV3_OFF 3 -#define HCI_ESCO_EV3_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV3_OFF] & HCI_FEATURE_ESCO_EV3_MASK) - -#define HCI_FEATURE_ESCO_EV4_MASK 0x01 -#define HCI_FEATURE_ESCO_EV4_OFF 4 -#define HCI_ESCO_EV4_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV4_OFF] & HCI_FEATURE_ESCO_EV4_MASK) - -#define HCI_FEATURE_ESCO_EV5_MASK 0x02 -#define HCI_FEATURE_ESCO_EV5_OFF 4 -#define HCI_ESCO_EV5_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV5_OFF] & HCI_FEATURE_ESCO_EV5_MASK) - -#define HCI_FEATURE_ABSENCE_MASKS_MASK 0x04 -#define HCI_FEATURE_ABSENCE_MASKS_OFF 4 -#define HCI_LMP_ABSENCE_MASKS_SUPPORTED(x) ((x)[HCI_FEATURE_ABSENCE_MASKS_OFF] & HCI_FEATURE_ABSENCE_MASKS_MASK) - -#define HCI_FEATURE_AFH_CAP_SLAVE_MASK 0x08 -#define HCI_FEATURE_AFH_CAP_SLAVE_OFF 4 -#define HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_SLAVE_OFF] & HCI_FEATURE_AFH_CAP_SLAVE_MASK) +#define HCI_FEATURE_5_SLOT_PACKETS_OFF 0 +#define HCI_5_SLOT_PACKETS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_5_SLOT_PACKETS_OFF] & HCI_FEATURE_5_SLOT_PACKETS_MASK) + +#define HCI_FEATURE_ENCRYPTION_MASK 0x04 +#define HCI_FEATURE_ENCRYPTION_OFF 0 +#define HCI_ENCRYPTION_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ENCRYPTION_OFF] & HCI_FEATURE_ENCRYPTION_MASK) + +#define HCI_FEATURE_SLOT_OFFSET_MASK 0x08 +#define HCI_FEATURE_SLOT_OFFSET_OFF 0 +#define HCI_SLOT_OFFSET_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SLOT_OFFSET_OFF] & HCI_FEATURE_SLOT_OFFSET_MASK) + +#define HCI_FEATURE_TIMING_ACC_MASK 0x10 +#define HCI_FEATURE_TIMING_ACC_OFF 0 +#define HCI_TIMING_ACC_SUPPORTED(x) \ + ((x)[HCI_FEATURE_TIMING_ACC_OFF] & HCI_FEATURE_TIMING_ACC_MASK) + +#define HCI_FEATURE_SWITCH_MASK 0x20 +#define HCI_FEATURE_SWITCH_OFF 0 +#define HCI_SWITCH_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK) + +#define HCI_FEATURE_HOLD_MODE_MASK 0x40 +#define HCI_FEATURE_HOLD_MODE_OFF 0 +#define HCI_HOLD_MODE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_HOLD_MODE_OFF] & HCI_FEATURE_HOLD_MODE_MASK) + +#define HCI_FEATURE_SNIFF_MODE_MASK 0x80 +#define HCI_FEATURE_SNIFF_MODE_OFF 0 +#define HCI_SNIFF_MODE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SNIFF_MODE_OFF] & HCI_FEATURE_SNIFF_MODE_MASK) + +#define HCI_FEATURE_PARK_MODE_MASK 0x01 +#define HCI_FEATURE_PARK_MODE_OFF 1 +#define HCI_PARK_MODE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_PARK_MODE_OFF] & HCI_FEATURE_PARK_MODE_MASK) + +#define HCI_FEATURE_RSSI_MASK 0x02 +#define HCI_FEATURE_RSSI_OFF 1 +#define HCI_RSSI_SUPPORTED(x) \ + ((x)[HCI_FEATURE_RSSI_OFF] & HCI_FEATURE_RSSI_MASK) + +#define HCI_FEATURE_CQM_DATA_RATE_MASK 0x04 +#define HCI_FEATURE_CQM_DATA_RATE_OFF 1 +#define HCI_CQM_DATA_RATE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_CQM_DATA_RATE_OFF] & HCI_FEATURE_CQM_DATA_RATE_MASK) + +#define HCI_FEATURE_SCO_LINK_MASK 0x08 +#define HCI_FEATURE_SCO_LINK_OFF 1 +#define HCI_SCO_LINK_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SCO_LINK_OFF] & HCI_FEATURE_SCO_LINK_MASK) + +#define HCI_FEATURE_HV2_PACKETS_MASK 0x10 +#define HCI_FEATURE_HV2_PACKETS_OFF 1 +#define HCI_HV2_PACKETS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_HV2_PACKETS_OFF] & HCI_FEATURE_HV2_PACKETS_MASK) + +#define HCI_FEATURE_HV3_PACKETS_MASK 0x20 +#define HCI_FEATURE_HV3_PACKETS_OFF 1 +#define HCI_HV3_PACKETS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_HV3_PACKETS_OFF] & HCI_FEATURE_HV3_PACKETS_MASK) + +#define HCI_FEATURE_U_LAW_MASK 0x40 +#define HCI_FEATURE_U_LAW_OFF 1 +#define HCI_LMP_U_LAW_SUPPORTED(x) \ + ((x)[HCI_FEATURE_U_LAW_OFF] & HCI_FEATURE_U_LAW_MASK) + +#define HCI_FEATURE_A_LAW_MASK 0x80 +#define HCI_FEATURE_A_LAW_OFF 1 +#define HCI_LMP_A_LAW_SUPPORTED(x) \ + ((x)[HCI_FEATURE_A_LAW_OFF] & HCI_FEATURE_A_LAW_MASK) + +#define HCI_FEATURE_CVSD_MASK 0x01 +#define HCI_FEATURE_CVSD_OFF 2 +#define HCI_LMP_CVSD_SUPPORTED(x) \ + ((x)[HCI_FEATURE_CVSD_OFF] & HCI_FEATURE_CVSD_MASK) + +#define HCI_FEATURE_PAGING_SCHEME_MASK 0x02 +#define HCI_FEATURE_PAGING_SCHEME_OFF 2 +#define HCI_PAGING_SCHEME_SUPPORTED(x) \ + ((x)[HCI_FEATURE_PAGING_SCHEME_OFF] & HCI_FEATURE_PAGING_SCHEME_MASK) + +#define HCI_FEATURE_POWER_CTRL_MASK 0x04 +#define HCI_FEATURE_POWER_CTRL_OFF 2 +#define HCI_POWER_CTRL_SUPPORTED(x) \ + ((x)[HCI_FEATURE_POWER_CTRL_OFF] & HCI_FEATURE_POWER_CTRL_MASK) + +#define HCI_FEATURE_TRANSPNT_MASK 0x08 +#define HCI_FEATURE_TRANSPNT_OFF 2 +#define HCI_LMP_TRANSPNT_SUPPORTED(x) \ + ((x)[HCI_FEATURE_TRANSPNT_OFF] & HCI_FEATURE_TRANSPNT_MASK) + +#define HCI_FEATURE_FLOW_CTRL_LAG_MASK 0x70 +#define HCI_FEATURE_FLOW_CTRL_LAG_OFF 2 +#define HCI_FLOW_CTRL_LAG_VALUE(x) \ + (((x)[HCI_FEATURE_FLOW_CTRL_LAG_OFF] & HCI_FEATURE_FLOW_CTRL_LAG_MASK) >> 4) + +#define HCI_FEATURE_BROADCAST_ENC_MASK 0x80 +#define HCI_FEATURE_BROADCAST_ENC_OFF 2 +#define HCI_LMP_BCAST_ENC_SUPPORTED(x) \ + ((x)[HCI_FEATURE_BROADCAST_ENC_OFF] & HCI_FEATURE_BROADCAST_ENC_MASK) + +#define HCI_FEATURE_SCATTER_MODE_MASK 0x01 +#define HCI_FEATURE_SCATTER_MODE_OFF 3 +#define HCI_LMP_SCATTER_MODE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SCATTER_MODE_OFF] & HCI_FEATURE_SCATTER_MODE_MASK) + +#define HCI_FEATURE_EDR_ACL_2MPS_MASK 0x02 +#define HCI_FEATURE_EDR_ACL_2MPS_OFF 3 +#define HCI_EDR_ACL_2MPS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EDR_ACL_2MPS_OFF] & HCI_FEATURE_EDR_ACL_2MPS_MASK) + +#define HCI_FEATURE_EDR_ACL_3MPS_MASK 0x04 +#define HCI_FEATURE_EDR_ACL_3MPS_OFF 3 +#define HCI_EDR_ACL_3MPS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EDR_ACL_3MPS_OFF] & HCI_FEATURE_EDR_ACL_3MPS_MASK) + +#define HCI_FEATURE_ENHANCED_INQ_MASK 0x08 +#define HCI_FEATURE_ENHANCED_INQ_OFF 3 +#define HCI_ENHANCED_INQ_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ENHANCED_INQ_OFF] & HCI_FEATURE_ENHANCED_INQ_MASK) + +#define HCI_FEATURE_INTERLACED_INQ_SCAN_MASK 0x10 +#define HCI_FEATURE_INTERLACED_INQ_SCAN_OFF 3 +#define HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(x) \ + ((x)[HCI_FEATURE_INTERLACED_INQ_SCAN_OFF] & \ + HCI_FEATURE_INTERLACED_INQ_SCAN_MASK) + +#define HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK 0x20 +#define HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF 3 +#define HCI_LMP_INTERLACED_PAGE_SCAN_SUPPORTED(x) \ + ((x)[HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF] & \ + HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK) + +#define HCI_FEATURE_INQ_RSSI_MASK 0x40 +#define HCI_FEATURE_INQ_RSSI_OFF 3 +#define HCI_LMP_INQ_RSSI_SUPPORTED(x) \ + ((x)[HCI_FEATURE_INQ_RSSI_OFF] & HCI_FEATURE_INQ_RSSI_MASK) + +#define HCI_FEATURE_ESCO_EV3_MASK 0x80 +#define HCI_FEATURE_ESCO_EV3_OFF 3 +#define HCI_ESCO_EV3_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ESCO_EV3_OFF] & HCI_FEATURE_ESCO_EV3_MASK) + +#define HCI_FEATURE_ESCO_EV4_MASK 0x01 +#define HCI_FEATURE_ESCO_EV4_OFF 4 +#define HCI_ESCO_EV4_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ESCO_EV4_OFF] & HCI_FEATURE_ESCO_EV4_MASK) + +#define HCI_FEATURE_ESCO_EV5_MASK 0x02 +#define HCI_FEATURE_ESCO_EV5_OFF 4 +#define HCI_ESCO_EV5_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ESCO_EV5_OFF] & HCI_FEATURE_ESCO_EV5_MASK) + +#define HCI_FEATURE_ABSENCE_MASKS_MASK 0x04 +#define HCI_FEATURE_ABSENCE_MASKS_OFF 4 +#define HCI_LMP_ABSENCE_MASKS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ABSENCE_MASKS_OFF] & HCI_FEATURE_ABSENCE_MASKS_MASK) + +#define HCI_FEATURE_AFH_CAP_SLAVE_MASK 0x08 +#define HCI_FEATURE_AFH_CAP_SLAVE_OFF 4 +#define HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_AFH_CAP_SLAVE_OFF] & HCI_FEATURE_AFH_CAP_SLAVE_MASK) #define HCI_FEATURE_AFH_CLASS_SLAVE_MASK 0x10 -#define HCI_FEATURE_AFH_CLASS_SLAVE_OFF 4 -#define HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_SLAVE_OFF] & HCI_FEATURE_AFH_CLASS_SLAVE_MASK) +#define HCI_FEATURE_AFH_CLASS_SLAVE_OFF 4 +#define HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_AFH_CLASS_SLAVE_OFF] & HCI_FEATURE_AFH_CLASS_SLAVE_MASK) -#define HCI_FEATURE_BREDR_NOT_SPT_MASK 0x20 -#define HCI_FEATURE_BREDR_NOT_SPT_OFF 4 -#define HCI_BREDR_NOT_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_BREDR_NOT_SPT_OFF] & HCI_FEATURE_BREDR_NOT_SPT_MASK) +#define HCI_FEATURE_BREDR_NOT_SPT_MASK 0x20 +#define HCI_FEATURE_BREDR_NOT_SPT_OFF 4 +#define HCI_BREDR_NOT_SPT_SUPPORTED(x) \ + ((x)[HCI_FEATURE_BREDR_NOT_SPT_OFF] & HCI_FEATURE_BREDR_NOT_SPT_MASK) -#define HCI_FEATURE_LE_SPT_MASK 0x40 -#define HCI_FEATURE_LE_SPT_OFF 4 -#define HCI_LE_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_LE_SPT_OFF] & HCI_FEATURE_LE_SPT_MASK) +#define HCI_FEATURE_LE_SPT_MASK 0x40 +#define HCI_FEATURE_LE_SPT_OFF 4 +#define HCI_LE_SPT_SUPPORTED(x) \ + ((x)[HCI_FEATURE_LE_SPT_OFF] & HCI_FEATURE_LE_SPT_MASK) #define HCI_FEATURE_3_SLOT_EDR_ACL_MASK 0x80 -#define HCI_FEATURE_3_SLOT_EDR_ACL_OFF 4 -#define HCI_3_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ACL_OFF] & HCI_FEATURE_3_SLOT_EDR_ACL_MASK) +#define HCI_FEATURE_3_SLOT_EDR_ACL_OFF 4 +#define HCI_3_SLOT_EDR_ACL_SUPPORTED(x) \ + ((x)[HCI_FEATURE_3_SLOT_EDR_ACL_OFF] & HCI_FEATURE_3_SLOT_EDR_ACL_MASK) #define HCI_FEATURE_5_SLOT_EDR_ACL_MASK 0x01 -#define HCI_FEATURE_5_SLOT_EDR_ACL_OFF 5 -#define HCI_5_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_EDR_ACL_OFF] & HCI_FEATURE_5_SLOT_EDR_ACL_MASK) +#define HCI_FEATURE_5_SLOT_EDR_ACL_OFF 5 +#define HCI_5_SLOT_EDR_ACL_SUPPORTED(x) \ + ((x)[HCI_FEATURE_5_SLOT_EDR_ACL_OFF] & HCI_FEATURE_5_SLOT_EDR_ACL_MASK) #define HCI_FEATURE_SNIFF_SUB_RATE_MASK 0x02 -#define HCI_FEATURE_SNIFF_SUB_RATE_OFF 5 -#define HCI_SNIFF_SUB_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_SUB_RATE_OFF] & HCI_FEATURE_SNIFF_SUB_RATE_MASK) +#define HCI_FEATURE_SNIFF_SUB_RATE_OFF 5 +#define HCI_SNIFF_SUB_RATE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SNIFF_SUB_RATE_OFF] & HCI_FEATURE_SNIFF_SUB_RATE_MASK) #define HCI_FEATURE_ATOMIC_ENCRYPT_MASK 0x04 -#define HCI_FEATURE_ATOMIC_ENCRYPT_OFF 5 -#define HCI_ATOMIC_ENCRYPT_SUPPORTED(x) ((x)[HCI_FEATURE_ATOMIC_ENCRYPT_OFF] & HCI_FEATURE_ATOMIC_ENCRYPT_MASK) +#define HCI_FEATURE_ATOMIC_ENCRYPT_OFF 5 +#define HCI_ATOMIC_ENCRYPT_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ATOMIC_ENCRYPT_OFF] & HCI_FEATURE_ATOMIC_ENCRYPT_MASK) -#define HCI_FEATURE_AFH_CAP_MASTR_MASK 0x08 -#define HCI_FEATURE_AFH_CAP_MASTR_OFF 5 -#define HCI_LMP_AFH_CAP_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_MASTR_OFF] & HCI_FEATURE_AFH_CAP_MASTR_MASK) +#define HCI_FEATURE_AFH_CAP_MASTR_MASK 0x08 +#define HCI_FEATURE_AFH_CAP_MASTR_OFF 5 +#define HCI_LMP_AFH_CAP_MASTR_SUPPORTED(x) \ + ((x)[HCI_FEATURE_AFH_CAP_MASTR_OFF] & HCI_FEATURE_AFH_CAP_MASTR_MASK) #define HCI_FEATURE_AFH_CLASS_MASTR_MASK 0x10 -#define HCI_FEATURE_AFH_CLASS_MASTR_OFF 5 -#define HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_MASTR_OFF] & HCI_FEATURE_AFH_CLASS_MASTR_MASK) +#define HCI_FEATURE_AFH_CLASS_MASTR_OFF 5 +#define HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(x) \ + ((x)[HCI_FEATURE_AFH_CLASS_MASTR_OFF] & HCI_FEATURE_AFH_CLASS_MASTR_MASK) -#define HCI_FEATURE_EDR_ESCO_2MPS_MASK 0x20 -#define HCI_FEATURE_EDR_ESCO_2MPS_OFF 5 -#define HCI_EDR_ESCO_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_2MPS_OFF] & HCI_FEATURE_EDR_ESCO_2MPS_MASK) +#define HCI_FEATURE_EDR_ESCO_2MPS_MASK 0x20 +#define HCI_FEATURE_EDR_ESCO_2MPS_OFF 5 +#define HCI_EDR_ESCO_2MPS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EDR_ESCO_2MPS_OFF] & HCI_FEATURE_EDR_ESCO_2MPS_MASK) -#define HCI_FEATURE_EDR_ESCO_3MPS_MASK 0x40 -#define HCI_FEATURE_EDR_ESCO_3MPS_OFF 5 -#define HCI_EDR_ESCO_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_3MPS_OFF] & HCI_FEATURE_EDR_ESCO_3MPS_MASK) +#define HCI_FEATURE_EDR_ESCO_3MPS_MASK 0x40 +#define HCI_FEATURE_EDR_ESCO_3MPS_OFF 5 +#define HCI_EDR_ESCO_3MPS_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EDR_ESCO_3MPS_OFF] & HCI_FEATURE_EDR_ESCO_3MPS_MASK) #define HCI_FEATURE_3_SLOT_EDR_ESCO_MASK 0x80 -#define HCI_FEATURE_3_SLOT_EDR_ESCO_OFF 5 -#define HCI_3_SLOT_EDR_ESCO_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ESCO_OFF] & HCI_FEATURE_3_SLOT_EDR_ESCO_MASK) +#define HCI_FEATURE_3_SLOT_EDR_ESCO_OFF 5 +#define HCI_3_SLOT_EDR_ESCO_SUPPORTED(x) \ + ((x)[HCI_FEATURE_3_SLOT_EDR_ESCO_OFF] & HCI_FEATURE_3_SLOT_EDR_ESCO_MASK) -#define HCI_FEATURE_EXT_INQ_RSP_MASK 0x01 -#define HCI_FEATURE_EXT_INQ_RSP_OFF 6 -#define HCI_EXT_INQ_RSP_SUPPORTED(x) ((x)[HCI_FEATURE_EXT_INQ_RSP_OFF] & HCI_FEATURE_EXT_INQ_RSP_MASK) +#define HCI_FEATURE_EXT_INQ_RSP_MASK 0x01 +#define HCI_FEATURE_EXT_INQ_RSP_OFF 6 +#define HCI_EXT_INQ_RSP_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EXT_INQ_RSP_OFF] & HCI_FEATURE_EXT_INQ_RSP_MASK) #if 1 /* TOKYO spec definition */ #define HCI_FEATURE_SIMUL_LE_BREDR_MASK 0x02 -#define HCI_FEATURE_SIMUL_LE_BREDR_OFF 6 -#define HCI_SIMUL_LE_BREDR_SUPPORTED(x) ((x)[HCI_FEATURE_SIMUL_LE_BREDR_OFF] & HCI_FEATURE_SIMUL_LE_BREDR_MASK) +#define HCI_FEATURE_SIMUL_LE_BREDR_OFF 6 +#define HCI_SIMUL_LE_BREDR_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SIMUL_LE_BREDR_OFF] & HCI_FEATURE_SIMUL_LE_BREDR_MASK) #else #define HCI_FEATURE_ANUM_PIN_AWARE_MASK 0x02 -#define HCI_FEATURE_ANUM_PIN_AWARE_OFF 6 -#define HCI_ANUM_PIN_AWARE_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_AWARE_OFF] & HCI_FEATURE_ANUM_PIN_AWARE_MASK) +#define HCI_FEATURE_ANUM_PIN_AWARE_OFF 6 +#define HCI_ANUM_PIN_AWARE_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ANUM_PIN_AWARE_OFF] & HCI_FEATURE_ANUM_PIN_AWARE_MASK) #endif -#define HCI_FEATURE_ANUM_PIN_CAP_MASK 0x04 -#define HCI_FEATURE_ANUM_PIN_CAP_OFF 6 -#define HCI_ANUM_PIN_CAP_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_CAP_OFF] & HCI_FEATURE_ANUM_PIN_CAP_MASK) +#define HCI_FEATURE_ANUM_PIN_CAP_MASK 0x04 +#define HCI_FEATURE_ANUM_PIN_CAP_OFF 6 +#define HCI_ANUM_PIN_CAP_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ANUM_PIN_CAP_OFF] & HCI_FEATURE_ANUM_PIN_CAP_MASK) #define HCI_FEATURE_SIMPLE_PAIRING_MASK 0x08 -#define HCI_FEATURE_SIMPLE_PAIRING_OFF 6 -#define HCI_SIMPLE_PAIRING_SUPPORTED(x) ((x)[HCI_FEATURE_SIMPLE_PAIRING_OFF] & HCI_FEATURE_SIMPLE_PAIRING_MASK) +#define HCI_FEATURE_SIMPLE_PAIRING_OFF 6 +#define HCI_SIMPLE_PAIRING_SUPPORTED(x) \ + ((x)[HCI_FEATURE_SIMPLE_PAIRING_OFF] & HCI_FEATURE_SIMPLE_PAIRING_MASK) -#define HCI_FEATURE_ENCAP_PDU_MASK 0x10 -#define HCI_FEATURE_ENCAP_PDU_OFF 6 -#define HCI_ENCAP_PDU_SUPPORTED(x) ((x)[HCI_FEATURE_ENCAP_PDU_OFF] & HCI_FEATURE_ENCAP_PDU_MASK) +#define HCI_FEATURE_ENCAP_PDU_MASK 0x10 +#define HCI_FEATURE_ENCAP_PDU_OFF 6 +#define HCI_ENCAP_PDU_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ENCAP_PDU_OFF] & HCI_FEATURE_ENCAP_PDU_MASK) -#define HCI_FEATURE_ERROR_DATA_MASK 0x20 -#define HCI_FEATURE_ERROR_DATA_OFF 6 -#define HCI_ERROR_DATA_SUPPORTED(x) ((x)[HCI_FEATURE_ERROR_DATA_OFF] & HCI_FEATURE_ERROR_DATA_MASK) +#define HCI_FEATURE_ERROR_DATA_MASK 0x20 +#define HCI_FEATURE_ERROR_DATA_OFF 6 +#define HCI_ERROR_DATA_SUPPORTED(x) \ + ((x)[HCI_FEATURE_ERROR_DATA_OFF] & HCI_FEATURE_ERROR_DATA_MASK) -#define HCI_FEATURE_NON_FLUSHABLE_PB_MASK 0x40 -#define HCI_FEATURE_NON_FLUSHABLE_PB_OFF 6 +#define HCI_FEATURE_NON_FLUSHABLE_PB_MASK 0x40 +#define HCI_FEATURE_NON_FLUSHABLE_PB_OFF 6 /* This feature is causing frequent link drops when doing call switch with * certain av/hfp headsets */ -#define HCI_NON_FLUSHABLE_PB_SUPPORTED(x) (0)//((x)[HCI_FEATURE_NON_FLUSHABLE_PB_OFF] & HCI_FEATURE_NON_FLUSHABLE_PB_MASK) +#define HCI_NON_FLUSHABLE_PB_SUPPORTED(x) \ + (0) //((x)[HCI_FEATURE_NON_FLUSHABLE_PB_OFF] & + // HCI_FEATURE_NON_FLUSHABLE_PB_MASK) #define HCI_FEATURE_LINK_SUP_TO_EVT_MASK 0x01 -#define HCI_FEATURE_LINK_SUP_TO_EVT_OFF 7 -#define HCI_LINK_SUP_TO_EVT_SUPPORTED(x) ((x)[HCI_FEATURE_LINK_SUP_TO_EVT_OFF] & HCI_FEATURE_LINK_SUP_TO_EVT_MASK) +#define HCI_FEATURE_LINK_SUP_TO_EVT_OFF 7 +#define HCI_LINK_SUP_TO_EVT_SUPPORTED(x) \ + ((x)[HCI_FEATURE_LINK_SUP_TO_EVT_OFF] & HCI_FEATURE_LINK_SUP_TO_EVT_MASK) -#define HCI_FEATURE_INQ_RESP_TX_MASK 0x02 -#define HCI_FEATURE_INQ_RESP_TX_OFF 7 -#define HCI_INQ_RESP_TX_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RESP_TX_OFF] & HCI_FEATURE_INQ_RESP_TX_MASK) +#define HCI_FEATURE_INQ_RESP_TX_MASK 0x02 +#define HCI_FEATURE_INQ_RESP_TX_OFF 7 +#define HCI_INQ_RESP_TX_SUPPORTED(x) \ + ((x)[HCI_FEATURE_INQ_RESP_TX_OFF] & HCI_FEATURE_INQ_RESP_TX_MASK) -#define HCI_FEATURE_EXTENDED_MASK 0x80 -#define HCI_FEATURE_EXTENDED_OFF 7 -#define HCI_LMP_EXTENDED_SUPPORTED(x) ((x)[HCI_FEATURE_EXTENDED_OFF] & HCI_FEATURE_EXTENDED_MASK) +#define HCI_FEATURE_EXTENDED_MASK 0x80 +#define HCI_FEATURE_EXTENDED_OFF 7 +#define HCI_LMP_EXTENDED_SUPPORTED(x) \ + ((x)[HCI_FEATURE_EXTENDED_OFF] & HCI_FEATURE_EXTENDED_MASK) /* * LMP features encoding - page 1 */ #define HCI_EXT_FEATURE_SSP_HOST_MASK 0x01 -#define HCI_EXT_FEATURE_SSP_HOST_OFF 0 -#define HCI_SSP_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SSP_HOST_OFF] & HCI_EXT_FEATURE_SSP_HOST_MASK) +#define HCI_EXT_FEATURE_SSP_HOST_OFF 0 +#define HCI_SSP_HOST_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SSP_HOST_OFF] & HCI_EXT_FEATURE_SSP_HOST_MASK) #define HCI_EXT_FEATURE_LE_HOST_MASK 0x02 -#define HCI_EXT_FEATURE_LE_HOST_OFF 0 -#define HCI_LE_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_LE_HOST_OFF] & HCI_EXT_FEATURE_LE_HOST_MASK) +#define HCI_EXT_FEATURE_LE_HOST_OFF 0 +#define HCI_LE_HOST_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_LE_HOST_OFF] & HCI_EXT_FEATURE_LE_HOST_MASK) #define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK 0x04 -#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF 0 -#define HCI_SIMUL_DUMO_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF] & HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK) +#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF 0 +#define HCI_SIMUL_DUMO_HOST_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF] & \ + HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK) #define HCI_EXT_FEATURE_SC_HOST_MASK 0x08 -#define HCI_EXT_FEATURE_SC_HOST_OFF 0 -#define HCI_SC_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_HOST_OFF] & HCI_EXT_FEATURE_SC_HOST_MASK) +#define HCI_EXT_FEATURE_SC_HOST_OFF 0 +#define HCI_SC_HOST_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SC_HOST_OFF] & HCI_EXT_FEATURE_SC_HOST_MASK) /* * LMP features encoding - page 2 */ -#define HCI_EXT_FEATURE_CSB_MASTER_MASK 0x01 -#define HCI_EXT_FEATURE_CSB_MASTER_OFF 0 -#define HCI_CSB_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_MASTER_OFF] & HCI_EXT_FEATURE_CSB_MASTER_MASK) - -#define HCI_EXT_FEATURE_CSB_SLAVE_MASK 0x02 -#define HCI_EXT_FEATURE_CSB_SLAVE_OFF 0 -#define HCI_CSB_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_SLAVE_OFF] & HCI_EXT_FEATURE_CSB_SLAVE_MASK) - -#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK 0x04 -#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF 0 -#define HCI_SYNC_TRAIN_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF] & HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK) - -#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK 0x08 -#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF 0 -#define HCI_SYNC_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF] & HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK) - -#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK 0x10 -#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF 0 -#define HCI_INQ_RESP_NOTIF_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF] & HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK) - -#define HCI_EXT_FEATURE_SC_CTRLR_MASK 0x01 -#define HCI_EXT_FEATURE_SC_CTRLR_OFF 1 -#define HCI_SC_CTRLR_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_CTRLR_OFF] & HCI_EXT_FEATURE_SC_CTRLR_MASK) - -#define HCI_EXT_FEATURE_PING_MASK 0x02 -#define HCI_EXT_FEATURE_PING_OFF 1 -#define HCI_PING_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_PING_OFF] & HCI_EXT_FEATURE_PING_MASK) +#define HCI_EXT_FEATURE_CSB_MASTER_MASK 0x01 +#define HCI_EXT_FEATURE_CSB_MASTER_OFF 0 +#define HCI_CSB_MASTER_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_CSB_MASTER_OFF] & HCI_EXT_FEATURE_CSB_MASTER_MASK) + +#define HCI_EXT_FEATURE_CSB_SLAVE_MASK 0x02 +#define HCI_EXT_FEATURE_CSB_SLAVE_OFF 0 +#define HCI_CSB_SLAVE_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_CSB_SLAVE_OFF] & HCI_EXT_FEATURE_CSB_SLAVE_MASK) + +#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK 0x04 +#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF 0 +#define HCI_SYNC_TRAIN_MASTER_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF] & \ + HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK) + +#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK 0x08 +#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF 0 +#define HCI_SYNC_SCAN_SLAVE_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF] & \ + HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK) + +#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK 0x10 +#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF 0 +#define HCI_INQ_RESP_NOTIF_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF] & \ + HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK) + +#define HCI_EXT_FEATURE_SC_CTRLR_MASK 0x01 +#define HCI_EXT_FEATURE_SC_CTRLR_OFF 1 +#define HCI_SC_CTRLR_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_SC_CTRLR_OFF] & HCI_EXT_FEATURE_SC_CTRLR_MASK) + +#define HCI_EXT_FEATURE_PING_MASK 0x02 +#define HCI_EXT_FEATURE_PING_OFF 1 +#define HCI_PING_SUPPORTED(x) \ + ((x)[HCI_EXT_FEATURE_PING_OFF] & HCI_EXT_FEATURE_PING_MASK) /* * LE features encoding - page 0 (the only page for now) */ /* LE Encryption */ -#define HCI_LE_FEATURE_LE_ENCRYPTION_MASK 0x01 -#define HCI_LE_FEATURE_LE_ENCRYPTION_OFF 0 -#define HCI_LE_ENCRYPTION_SUPPORTED(x) ((x)[HCI_LE_FEATURE_LE_ENCRYPTION_OFF] & HCI_LE_FEATURE_LE_ENCRYPTION_MASK) +#define HCI_LE_FEATURE_LE_ENCRYPTION_MASK 0x01 +#define HCI_LE_FEATURE_LE_ENCRYPTION_OFF 0 +#define HCI_LE_ENCRYPTION_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_LE_ENCRYPTION_OFF] & HCI_LE_FEATURE_LE_ENCRYPTION_MASK) /* Connection Parameters Request Procedure */ -#define HCI_LE_FEATURE_CONN_PARAM_REQ_MASK 0x02 -#define HCI_LE_FEATURE_CONN_PARAM_REQ_OFF 0 -#define HCI_LE_CONN_PARAM_REQ_SUPPORTED(x) ((x)[HCI_LE_FEATURE_CONN_PARAM_REQ_OFF] & HCI_LE_FEATURE_CONN_PARAM_REQ_MASK) +#define HCI_LE_FEATURE_CONN_PARAM_REQ_MASK 0x02 +#define HCI_LE_FEATURE_CONN_PARAM_REQ_OFF 0 +#define HCI_LE_CONN_PARAM_REQ_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_CONN_PARAM_REQ_OFF] & HCI_LE_FEATURE_CONN_PARAM_REQ_MASK) /* Extended Reject Indication */ -#define HCI_LE_FEATURE_EXT_REJ_IND_MASK 0x04 -#define HCI_LE_FEATURE_EXT_REJ_IND_OFF 0 -#define HCI_LE_EXT_REJ_IND_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_REJ_IND_OFF] & HCI_LE_FEATURE_EXT_REJ_IND_MASK) +#define HCI_LE_FEATURE_EXT_REJ_IND_MASK 0x04 +#define HCI_LE_FEATURE_EXT_REJ_IND_OFF 0 +#define HCI_LE_EXT_REJ_IND_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_EXT_REJ_IND_OFF] & HCI_LE_FEATURE_EXT_REJ_IND_MASK) /* Slave-initiated Features Exchange */ -#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK 0x08 -#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF 0 -#define HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(x) ((x)[HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF] & HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK) +#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK 0x08 +#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF 0 +#define HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF] & \ + HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK) /* Enhanced privacy Feature: bit 6 */ -#define HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK 0x40 -#define HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF 0 -#define HCI_LE_ENHANCED_PRIVACY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF] & HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK) +#define HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK 0x40 +#define HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF 0 +#define HCI_LE_ENHANCED_PRIVACY_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF] & \ + HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK) /* Extended scanner filter policy : 7 */ -#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK 0x80 -#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF 0 -#define HCI_LE_EXT_SCAN_FILTER_POLICY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF] & HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK) +#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK 0x80 +#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF 0 +#define HCI_LE_EXT_SCAN_FILTER_POLICY_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF] & \ + HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK) /* Slave-initiated Features Exchange */ -#define HCI_LE_FEATURE_DATA_LEN_EXT_MASK 0x20 -#define HCI_LE_FEATURE_DATA_LEN_EXT_OFF 0 -#define HCI_LE_DATA_LEN_EXT_SUPPORTED(x) ((x)[HCI_LE_FEATURE_DATA_LEN_EXT_OFF] & HCI_LE_FEATURE_DATA_LEN_EXT_MASK) +#define HCI_LE_FEATURE_DATA_LEN_EXT_MASK 0x20 +#define HCI_LE_FEATURE_DATA_LEN_EXT_OFF 0 +#define HCI_LE_DATA_LEN_EXT_SUPPORTED(x) \ + ((x)[HCI_LE_FEATURE_DATA_LEN_EXT_OFF] & HCI_LE_FEATURE_DATA_LEN_EXT_MASK) /* * Local Supported Commands encoding */ -#define HCI_NUM_SUPP_COMMANDS_BYTES 64 +#define HCI_NUM_SUPP_COMMANDS_BYTES 64 /* Supported Commands Byte 0 */ #define HCI_SUPP_COMMANDS_INQUIRY_MASK 0x01 -#define HCI_SUPP_COMMANDS_INQUIRY_OFF 0 -#define HCI_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_OFF] & HCI_SUPP_COMMANDS_INQUIRY_MASK) +#define HCI_SUPP_COMMANDS_INQUIRY_OFF 0 +#define HCI_INQUIRY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_INQUIRY_OFF] & HCI_SUPP_COMMANDS_INQUIRY_MASK) #define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK 0x02 -#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF 0 -#define HCI_INQUIRY_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF] & HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK) - -#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK 0x04 -#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF 0 -#define HCI_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK 0x08 -#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF 0 -#define HCI_EXIT_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_CREATE_CONN_OFF 0 -#define HCI_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CREATE_CONN_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_MASK 0x20 -#define HCI_SUPP_COMMANDS_DISCONNECT_OFF 0 -#define HCI_DISCONNECT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_MASK) - -#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK 0x40 -#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF 0 -#define HCI_ADD_SCO_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF] & HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK) - -#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK 0x80 -#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF 0 -#define HCI_CANCEL_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK 0x01 -#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF 1 -#define HCI_ACCEPT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK 0x02 -#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF 1 -#define HCI_REJECT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK 0x04 -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF 1 -#define HCI_LINK_KEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF 1 -#define HCI_LINK_KEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK 0x10 -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF 1 -#define HCI_PIN_CODE_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK 0x20 -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF 1 -#define HCI_PIN_CODE_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK 0x40 -#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF 1 -#define HCI_CHANGE_CONN_PKT_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK 0x80 -#define HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF 1 -#define HCI_AUTH_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF] & HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF 2 -#define HCI_SET_CONN_ENCRYPTION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF] & HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK) - -#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK 0x02 -#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF 2 -#define HCI_CHANGE_CONN_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK 0x04 -#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF 2 -#define HCI_MASTER_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK 0x08 -#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF 2 -#define HCI_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK 0x10 -#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF 2 -#define HCI_CANCEL_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF 2 -#define HCI_READ_REMOTE_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF 2 -#define HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF 2 -#define HCI_READ_REMOTE_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF 3 -#define HCI_READ_CLOCK_OFFSET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF] & HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK) - -#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF 3 -#define HCI_READ_LMP_HANDLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF] & HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK) - -#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK 0x02 -#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF 4 -#define HCI_HOLD_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK) - -#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK 0x04 -#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF 4 -#define HCI_SNIFF_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK 0x08 -#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF 4 -#define HCI_EXIT_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF] & HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK) - -#define HCI_SUPP_COMMANDS_PARK_STATE_MASK 0x10 -#define HCI_SUPP_COMMANDS_PARK_STATE_OFF 4 -#define HCI_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_PARK_STATE_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK 0x20 -#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF 4 -#define HCI_EXIT_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK) - -#define HCI_SUPP_COMMANDS_QOS_SETUP_MASK 0x40 -#define HCI_SUPP_COMMANDS_QOS_SETUP_OFF 4 -#define HCI_QOS_SETUP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_QOS_SETUP_OFF] & HCI_SUPP_COMMANDS_QOS_SETUP_MASK) - -#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK 0x80 -#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF 4 -#define HCI_ROLE_DISCOVERY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF] & HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK) - -#define HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK 0x01 -#define HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF 5 -#define HCI_SWITCH_ROLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF] & HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF 5 -#define HCI_READ_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK 0x04 -#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF 5 -#define HCI_WRITE_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF 5 -#define HCI_READ_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF 5 -#define HCI_WRITE_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK 0x20 -#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF 5 -#define HCI_FLOW_SPECIFICATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF] & HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK 0x40 -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF 5 -#define HCI_SET_EVENT_MASK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK) - -#define HCI_SUPP_COMMANDS_RESET_MASK 0x80 -#define HCI_SUPP_COMMANDS_RESET_OFF 5 -#define HCI_RESET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_OFF] & HCI_SUPP_COMMANDS_RESET_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF 6 -#define HCI_SET_EVENT_FILTER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK) - -#define HCI_SUPP_COMMANDS_FLUSH_MASK 0x02 -#define HCI_SUPP_COMMANDS_FLUSH_OFF 6 -#define HCI_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLUSH_OFF] & HCI_SUPP_COMMANDS_FLUSH_MASK) - -#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF 6 -#define HCI_READ_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF 6 -#define HCI_WRITE_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK 0x10 -#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF 6 -#define HCI_CREATE_NEW_UNIT_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF] & HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK) - -#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF 6 -#define HCI_READ_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF 6 -#define HCI_WRITE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK 0x80 -#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF 6 -#define HCI_DELETE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK 0x01 -#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF 7 -#define HCI_WRITE_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF 7 -#define HCI_READ_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK) - -#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF 7 -#define HCI_READ_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF 7 -#define HCI_WRITE_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF 7 -#define HCI_READ_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF 7 -#define HCI_WRITE_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF 7 -#define HCI_READ_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF 7 -#define HCI_WRITE_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF 8 -#define HCI_READ_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF 8 -#define HCI_WRITE_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF 8 -#define HCI_READ_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF 8 -#define HCI_WRITE_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF 8 -#define HCI_READ_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF 8 -#define HCI_WRITE_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF 8 -#define HCI_READ_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF 8 -#define HCI_WRITE_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF 9 -#define HCI_READ_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF 9 -#define HCI_WRITE_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK) - -#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF 9 -#define HCI_READ_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF 9 -#define HCI_WRITE_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF 9 -#define HCI_READ_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF 9 -#define HCI_WRITE_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF 9 -#define HCI_READ_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF 9 -#define HCI_WRITE_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK) - -#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF 10 -#define HCI_READ_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF 10 -#define HCI_WRITE_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF 10 -#define HCI_READ_TRANS_PWR_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK) - -#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF 10 -#define HCI_READ_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF 10 -#define HCI_WRITE_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK 0x20 -#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF 10 -#define HCI_SET_HOST_CTRLR_TO_HOST_FC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF] & HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK) - -#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK 0x40 -#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF 10 -#define HCI_HOST_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK 0x80 -#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF 10 -#define HCI_HOST_NUM_COMPLETED_PKTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF] & HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK) - -#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF 11 -#define HCI_READ_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF 11 -#define HCI_WRITE_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF 11 -#define HCI_READ_NUM_SUPP_IAC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF] & HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK) - -#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF 11 -#define HCI_READ_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF 11 -#define HCI_WRITE_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF 11 -#define HCI_READ_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF 11 -#define HCI_WRITE_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF 11 -#define HCI_READ_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF 12 -#define HCI_WRITE_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK) - -#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK 0x02 -#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF 12 -#define HCI_SET_AFH_CHNL_CLASS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF] & HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF 12 -#define HCI_READ_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF 12 -#define HCI_WRITE_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF 12 -#define HCI_READ_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF 12 -#define HCI_WRITE_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF 13 -#define HCI_READ_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF 13 -#define HCI_WRITE_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF 13 -#define HCI_READ_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF 13 -#define HCI_WRITE_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF 14 -#define HCI_READ_LOCAL_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF 14 -#define HCI_READ_LOCAL_SUP_CMDS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF 14 -#define HCI_READ_LOCAL_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF 14 -#define HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF 14 -#define HCI_READ_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF 15 -#define HCI_READ_COUNTRY_CODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF] & HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF 15 -#define HCI_READ_BD_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF] & HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK) - -#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF 15 -#define HCI_READ_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK) - -#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK 0x08 -#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF 15 -#define HCI_RESET_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK) - -#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK 0x10 -#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF 15 -#define HCI_GET_LINK_QUALITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF] & HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_RSSI_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_RSSI_OFF 15 -#define HCI_READ_RSSI_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_RSSI_OFF] & HCI_SUPP_COMMANDS_READ_RSSI_MASK) - -#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF 15 -#define HCI_READ_AFH_CH_MAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK) - -#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF 15 -#define HCI_READ_BD_CLOCK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF] & HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF 16 -#define HCI_READ_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF 16 -#define HCI_WRITE_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK) - -#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK 0x04 -#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF 16 -#define HCI_ENABLE_DEV_UNDER_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF] & HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK) - -#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK 0x08 -#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF 16 -#define HCI_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF 16 -#define HCI_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK 0x20 -#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF 16 -#define HCI_REJECT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF 17 -#define HCI_READ_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF 17 -#define HCI_WRITE_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK) - -#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK 0x04 -#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF 17 -#define HCI_REFRESH_ENCRYPTION_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF] & HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK) +#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF 0 +#define HCI_INQUIRY_CANCEL_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF] & \ + HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK) + +#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK 0x04 +#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF 0 +#define HCI_PERIODIC_INQUIRY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF] & \ + HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK 0x08 +#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF 0 +#define HCI_EXIT_PERIODIC_INQUIRY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF] & \ + HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_CREATE_CONN_OFF 0 +#define HCI_CREATE_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CREATE_CONN_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_MASK 0x20 +#define HCI_SUPP_COMMANDS_DISCONNECT_OFF 0 +#define HCI_DISCONNECT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_DISCONNECT_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_MASK) + +#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK 0x40 +#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF 0 +#define HCI_ADD_SCO_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF] & \ + HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK) + +#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK 0x80 +#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF 0 +#define HCI_CANCEL_CREATE_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF] & \ + HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK 0x01 +#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF 1 +#define HCI_ACCEPT_CONN_REQUEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF] & \ + HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK 0x02 +#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF 1 +#define HCI_REJECT_CONN_REQUEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF] & \ + HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK 0x04 +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF 1 +#define HCI_LINK_KEY_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF 1 +#define HCI_LINK_KEY_REQUEST_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK 0x10 +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF 1 +#define HCI_PIN_CODE_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK 0x20 +#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF 1 +#define HCI_PIN_CODE_REQUEST_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK 0x40 +#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF 1 +#define HCI_CHANGE_CONN_PKT_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK 0x80 +#define HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF 1 +#define HCI_AUTH_REQUEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF] & \ + HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF 2 +#define HCI_SET_CONN_ENCRYPTION_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF] & \ + HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK) + +#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK 0x02 +#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF 2 +#define HCI_CHANGE_CONN_LINK_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF] & \ + HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK 0x04 +#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF 2 +#define HCI_MASTER_LINK_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF] & \ + HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK 0x08 +#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF 2 +#define HCI_REMOTE_NAME_REQUEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF] & \ + HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK 0x10 +#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF 2 +#define HCI_CANCEL_REMOTE_NAME_REQUEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF] & \ + HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF 2 +#define HCI_READ_REMOTE_SUPP_FEATURES_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF] & \ + HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF 2 +#define HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF] & \ + HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF 2 +#define HCI_READ_REMOTE_VER_INFO_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF] & \ + HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF 3 +#define HCI_READ_CLOCK_OFFSET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF] & \ + HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK) + +#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF 3 +#define HCI_READ_LMP_HANDLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF] & \ + HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK) + +#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK 0x02 +#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF 4 +#define HCI_HOLD_MODE_CMD_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF] & \ + HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK) + +#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK 0x04 +#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF 4 +#define HCI_SNIFF_MODE_CMD_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF] & \ + HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK 0x08 +#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF 4 +#define HCI_EXIT_SNIFF_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF] & \ + HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK) + +#define HCI_SUPP_COMMANDS_PARK_STATE_MASK 0x10 +#define HCI_SUPP_COMMANDS_PARK_STATE_OFF 4 +#define HCI_PARK_STATE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_PARK_STATE_MASK) + +#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK 0x20 +#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF 4 +#define HCI_EXIT_PARK_STATE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF] & \ + HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK) + +#define HCI_SUPP_COMMANDS_QOS_SETUP_MASK 0x40 +#define HCI_SUPP_COMMANDS_QOS_SETUP_OFF 4 +#define HCI_QOS_SETUP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_QOS_SETUP_OFF] & HCI_SUPP_COMMANDS_QOS_SETUP_MASK) + +#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK 0x80 +#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF 4 +#define HCI_ROLE_DISCOVERY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF] & \ + HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK) + +#define HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK 0x01 +#define HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF 5 +#define HCI_SWITCH_ROLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF] & HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF 5 +#define HCI_READ_LINK_POLICY_SET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF] & \ + HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK 0x04 +#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF 5 +#define HCI_WRITE_LINK_POLICY_SET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF 5 +#define HCI_READ_DEF_LINK_POLICY_SET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF] & \ + HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF 5 +#define HCI_WRITE_DEF_LINK_POLICY_SET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK) + +#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK 0x20 +#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF 5 +#define HCI_FLOW_SPECIFICATION_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF] & \ + HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK 0x40 +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF 5 +#define HCI_SET_EVENT_MASK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF] & \ + HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK) + +#define HCI_SUPP_COMMANDS_RESET_MASK 0x80 +#define HCI_SUPP_COMMANDS_RESET_OFF 5 +#define HCI_RESET_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_RESET_OFF] & HCI_SUPP_COMMANDS_RESET_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF 6 +#define HCI_SET_EVENT_FILTER_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF] & \ + HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK) + +#define HCI_SUPP_COMMANDS_FLUSH_MASK 0x02 +#define HCI_SUPP_COMMANDS_FLUSH_OFF 6 +#define HCI_FLUSH_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_FLUSH_OFF] & HCI_SUPP_COMMANDS_FLUSH_MASK) + +#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF 6 +#define HCI_READ_PIN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF 6 +#define HCI_WRITE_PIN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK 0x10 +#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF 6 +#define HCI_CREATE_NEW_UNIT_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF] & \ + HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK) + +#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF 6 +#define HCI_READ_STORED_LINK_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF] & \ + HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF 6 +#define HCI_WRITE_STORED_LINK_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK 0x80 +#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF 6 +#define HCI_DELETE_STORED_LINK_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF] & \ + HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK 0x01 +#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF 7 +#define HCI_WRITE_LOCAL_NAME_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF 7 +#define HCI_READ_LOCAL_NAME_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK) + +#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF 7 +#define HCI_READ_CONN_ACCEPT_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF 7 +#define HCI_WRITE_CONN_ACCEPT_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF 7 +#define HCI_READ_PAGE_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF 7 +#define HCI_WRITE_PAGE_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF 7 +#define HCI_READ_SCAN_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF 7 +#define HCI_WRITE_SCAN_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF 8 +#define HCI_READ_PAGE_SCAN_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF 8 +#define HCI_WRITE_PAGE_SCAN_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF 8 +#define HCI_READ_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF 8 +#define HCI_WRITE_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF 8 +#define HCI_READ_AUTH_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF 8 +#define HCI_WRITE_AUTH_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF 8 +#define HCI_READ_ENCRYPT_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF 8 +#define HCI_WRITE_ENCRYPT_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF 9 +#define HCI_READ_CLASS_DEVICE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF] & \ + HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF 9 +#define HCI_WRITE_CLASS_DEVICE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK) + +#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF 9 +#define HCI_READ_VOICE_SETTING_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF] & \ + HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF 9 +#define HCI_WRITE_VOICE_SETTING_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF 9 +#define HCI_READ_AUTO_FLUSH_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF 9 +#define HCI_WRITE_AUTO_FLUSH_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF 9 +#define HCI_READ_NUM_BROAD_RETRANS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF] & \ + HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF 9 +#define HCI_WRITE_NUM_BROAD_RETRANS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK) + +#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF 10 +#define HCI_READ_HOLD_MODE_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF 10 +#define HCI_WRITE_HOLD_MODE_ACTIVITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF 10 +#define HCI_READ_TRANS_PWR_LEVEL_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF] & \ + HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK) + +#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF 10 +#define HCI_READ_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF 10 +#define HCI_WRITE_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK) + +#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK 0x20 +#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF 10 +#define HCI_SET_HOST_CTRLR_TO_HOST_FC_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF] & \ + HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK) + +#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK 0x40 +#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF 10 +#define HCI_HOST_BUFFER_SIZE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF] & \ + HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK 0x80 +#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF 10 +#define HCI_HOST_NUM_COMPLETED_PKTS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF] & \ + HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK) + +#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF 11 +#define HCI_READ_LINK_SUP_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF 11 +#define HCI_WRITE_LINK_SUP_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF 11 +#define HCI_READ_NUM_SUPP_IAC_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF] & \ + HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK) + +#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF 11 +#define HCI_READ_CURRENT_IAC_LAP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF] & \ + HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF 11 +#define HCI_WRITE_CURRENT_IAC_LAP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF 11 +#define HCI_READ_PAGE_SCAN_PER_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF 11 +#define HCI_WRITE_PAGE_SCAN_PER_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF 11 +#define HCI_READ_PAGE_SCAN_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF 12 +#define HCI_WRITE_PAGE_SCAN_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK) + +#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK 0x02 +#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF 12 +#define HCI_SET_AFH_CHNL_CLASS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF] & \ + HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF 12 +#define HCI_READ_INQUIRY_SCAN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF 12 +#define HCI_WRITE_INQUIRY_SCAN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF 12 +#define HCI_READ_INQUIRY_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF 12 +#define HCI_WRITE_INQUIRY_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF 13 +#define HCI_READ_PAGE_SCAN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF 13 +#define HCI_WRITE_PAGE_SCAN_TYPE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK) + +#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF 13 +#define HCI_READ_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF 13 +#define HCI_WRITE_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF 14 +#define HCI_READ_LOCAL_VER_INFO_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF 14 +#define HCI_READ_LOCAL_SUP_CMDS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF 14 +#define HCI_READ_LOCAL_SUPP_FEATURES_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF 14 +#define HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK) + +#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF 14 +#define HCI_READ_BUFFER_SIZE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF] & \ + HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF 15 +#define HCI_READ_COUNTRY_CODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK 0x02 +#define HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF 15 +#define HCI_READ_BD_ADDR_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF] & \ + HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK) + +#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF 15 +#define HCI_READ_FAIL_CONTACT_CNTR_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF] & \ + HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK) + +#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK 0x08 +#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF 15 +#define HCI_RESET_FAIL_CONTACT_CNTR_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF] & \ + HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK) + +#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK 0x10 +#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF 15 +#define HCI_GET_LINK_QUALITY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF] & \ + HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK) + +#define HCI_SUPP_COMMANDS_READ_RSSI_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_RSSI_OFF 15 +#define HCI_READ_RSSI_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_RSSI_OFF] & HCI_SUPP_COMMANDS_READ_RSSI_MASK) + +#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF 15 +#define HCI_READ_AFH_CH_MAP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF] & \ + HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK) + +#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF 15 +#define HCI_READ_BD_CLOCK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF] & \ + HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF 16 +#define HCI_READ_LOOPBACK_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF 16 +#define HCI_WRITE_LOOPBACK_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK) + +#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK 0x04 +#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF 16 +#define HCI_ENABLE_DEV_UNDER_TEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF] & \ + HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK) + +#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK 0x08 +#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF 16 +#define HCI_SETUP_SYNCH_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF] & \ + HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF 16 +#define HCI_ACCEPT_SYNCH_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF] & \ + HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK 0x20 +#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF 16 +#define HCI_REJECT_SYNCH_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF] & \ + HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF 17 +#define HCI_READ_EXT_INQUIRY_RESP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF] & \ + HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF 17 +#define HCI_WRITE_EXT_INQUIRY_RESP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK) + +#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK 0x04 +#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF 17 +#define HCI_REFRESH_ENCRYPTION_KEY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF] & \ + HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK) /* Octet 17, bit 3 is reserved */ -#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK 0x10 -#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF 17 -#define HCI_SNIFF_SUB_RATE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF] & HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK) - -#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF 17 -#define HCI_READ_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF 17 -#define HCI_WRITE_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF 17 -#define HCI_READ_LOCAL_OOB_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF 18 -#define HCI_READ_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF 18 -#define HCI_WRITE_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK) - -#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 -#define HCI_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 -#define HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) - -#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK 0x80 -#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF 18 -#define HCI_IO_CAPABILITY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK 0x01 -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF 19 -#define HCI_USER_CONFIRMATION_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK 0x02 -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF 19 -#define HCI_USER_CONFIRMATION_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK 0x04 -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF 19 -#define HCI_USER_PASSKEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF 19 -#define HCI_USER_PASSKEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK 0x10 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF 19 -#define HCI_REMOTE_OOB_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF 19 -#define HCI_WRITE_SIMPLE_PAIRING_DBG_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK) - -#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK 0x40 -#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF 19 -#define HCI_ENHANCED_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF] & HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK 0x80 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF 19 -#define HCI_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK) +#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK 0x10 +#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF 17 +#define HCI_SNIFF_SUB_RATE_CMD_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF] & \ + HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK) + +#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF 17 +#define HCI_READ_SIMPLE_PAIRING_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK 0x40 +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF 17 +#define HCI_WRITE_SIMPLE_PAIRING_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK 0x80 +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF 17 +#define HCI_READ_LOCAL_OOB_DATA_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK) + +#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF 18 +#define HCI_READ_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF] & \ + HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF 18 +#define HCI_WRITE_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK) + +#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 +#define HCI_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & \ + HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 +#define HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) + +#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK 0x80 +#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF 18 +#define HCI_IO_CAPABILITY_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK 0x01 +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF 19 +#define HCI_USER_CONFIRMATION_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK 0x02 +#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF 19 +#define HCI_USER_CONFIRMATION_REQUEST_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK 0x04 +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF 19 +#define HCI_USER_PASSKEY_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF 19 +#define HCI_USER_PASSKEY_REQUEST_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK 0x10 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF 19 +#define HCI_REMOTE_OOB_DATA_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF 19 +#define HCI_WRITE_SIMPLE_PAIRING_DBG_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK) + +#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK 0x40 +#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF 19 +#define HCI_ENHANCED_FLUSH_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF] & \ + HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK 0x80 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF 19 +#define HCI_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK) /* Supported Commands (Byte 20) */ -#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK 0x04 -#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF 20 -#define HCI_SEND_NOTIF_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF] & HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK) - -#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF 20 -#define HCI_IO_CAP_REQ_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF 20 -#define HCI_READ_ENCR_KEY_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK) +#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK 0x04 +#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF 20 +#define HCI_SEND_NOTIF_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF] & \ + HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK) + +#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK 0x08 +#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF 20 +#define HCI_IO_CAP_REQ_NEG_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF 20 +#define HCI_READ_ENCR_KEY_SIZE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF] & \ + HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK) /* Supported Commands (Byte 21) */ -#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK 0x01 -#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF 21 -#define HCI_CREATE_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK 0x02 -#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF 21 -#define HCI_ACCEPT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK 0x04 -#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF 21 -#define HCI_DISCONNECT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK 0x08 -#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF 21 -#define HCI_CREATE_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK 0x10 -#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF 21 -#define HCI_ACCEPT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK 0x20 -#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF 21 -#define HCI_DISCONNECT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK 0x40 -#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF 21 -#define HCI_LOGICAL_LINK_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF] & HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK) - -#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK 0x80 -#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF 21 -#define HCI_FLOW_SPEC_MODIFY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF] & HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK) +#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK 0x01 +#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF 21 +#define HCI_CREATE_PHYSICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK 0x02 +#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF 21 +#define HCI_ACCEPT_PHYSICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK 0x04 +#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF 21 +#define HCI_DISCONNECT_PHYSICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK 0x08 +#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF 21 +#define HCI_CREATE_LOGICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK 0x10 +#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF 21 +#define HCI_ACCEPT_LOGICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK 0x20 +#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF 21 +#define HCI_DISCONNECT_LOGICAL_LINK_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF] & \ + HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK) + +#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK 0x40 +#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF 21 +#define HCI_LOGICAL_LINK_CANCEL_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF] & \ + HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK) + +#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK 0x80 +#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF 21 +#define HCI_FLOW_SPEC_MODIFY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF] & \ + HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK) /* Supported Commands (Byte 22) */ -#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 -#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 -#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK 0x04 -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF 22 -#define HCI_SET_EVENT_MASK_PAGE_2_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF 22 -#define HCI_READ_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF 22 -#define HCI_WRITE_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF 22 -#define HCI_READ_LOCAL_AMP_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF 22 -#define HCI_READ_LOCAL_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF 22 -#define HCI_WRITE_REMOTE_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK) +#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 +#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 +#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) + +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK 0x04 +#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF 22 +#define HCI_SET_EVENT_MASK_PAGE_2_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF] & \ + HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK 0x08 +#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF 22 +#define HCI_READ_LOCATION_DATA_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK 0x10 +#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF 22 +#define HCI_WRITE_LOCATION_DATA_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF 22 +#define HCI_READ_LOCAL_AMP_INFO_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK 0x40 +#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF 22 +#define HCI_READ_LOCAL_AMP_ASSOC_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF 22 +#define HCI_WRITE_REMOTE_AMP_ASSOC_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK) /* Supported Commands (Byte 23) */ -#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF 23 -#define HCI_READ_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF 23 -#define HCI_WRITE_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF 23 -#define HCI_READ_DATA_BLOCK_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK 0x20 -#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF 23 -#define HCI_ENABLE_AMP_RCVR_REPORTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF] & HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK) - -#define HCI_SUPP_COMMANDS_AMP_TEST_END_MASK 0x40 -#define HCI_SUPP_COMMANDS_AMP_TEST_END_OFF 23 -#define HCI_AMP_TEST_END_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_END_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_END_MASK) - -#define HCI_SUPP_COMMANDS_AMP_TEST_MASK 0x80 -#define HCI_SUPP_COMMANDS_AMP_TEST_OFF 23 -#define HCI_AMP_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_MASK) +#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF 23 +#define HCI_READ_FLOW_CONTROL_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF] & \ + HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK 0x02 +#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF 23 +#define HCI_WRITE_FLOW_CONTROL_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK) + +#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF 23 +#define HCI_READ_DATA_BLOCK_SIZE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF] & \ + HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK) + +#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK 0x20 +#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF 23 +#define HCI_ENABLE_AMP_RCVR_REPORTS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF] & \ + HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK) + +#define HCI_SUPP_COMMANDS_AMP_TEST_END_MASK 0x40 +#define HCI_SUPP_COMMANDS_AMP_TEST_END_OFF 23 +#define HCI_AMP_TEST_END_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_AMP_TEST_END_OFF] & \ + HCI_SUPP_COMMANDS_AMP_TEST_END_MASK) + +#define HCI_SUPP_COMMANDS_AMP_TEST_MASK 0x80 +#define HCI_SUPP_COMMANDS_AMP_TEST_OFF 23 +#define HCI_AMP_TEST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_AMP_TEST_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_MASK) /* Supported Commands (Byte 24) */ -#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF 24 -#define HCI_READ_TRANSMIT_POWER_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK) - -#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF 24 -#define HCI_READ_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF 24 -#define HCI_WRITE_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK 0x10 -#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF 24 -#define HCI_SHORT_RANGE_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF] & HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK) +#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK 0x01 +#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF 24 +#define HCI_READ_TRANSMIT_POWER_LEVEL_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF] & \ + HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK) + +#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF 24 +#define HCI_READ_BE_FLUSH_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF 24 +#define HCI_WRITE_BE_FLUSH_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK 0x10 +#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF 24 +#define HCI_SHORT_RANGE_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF] & \ + HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK) /* LE commands TBD * Supported Commands (Byte 24 continued) @@ -2493,137 +2985,195 @@ typedef struct */ /* Supported Commands (Byte 29) */ -#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK 0x08 -#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF 29 -#define HCI_READ_ENH_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF 29 -#define HCI_READ_ENH_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF 29 -#define HCI_READ_LOCAL_CODECS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK 0x40 -#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF 29 -#define HCI_SET_MWS_CHANNEL_PARAMETERS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF] & HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK) - -#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK 0x80 -#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF 29 -#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF] & HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK) - +#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK 0x08 +#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF 29 +#define HCI_READ_ENH_SETUP_SYNCH_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF] & \ + HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK 0x10 +#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF 29 +#define HCI_READ_ENH_ACCEPT_SYNCH_CONN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF] & \ + HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK) + +#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK 0x20 +#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF 29 +#define HCI_READ_LOCAL_CODECS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK 0x40 +#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF 29 +#define HCI_SET_MWS_CHANNEL_PARAMETERS_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF] & \ + HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK) + +#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK 0x80 +#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF 29 +#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF] & \ + HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK) /* Supported Commands (Byte 30) */ -#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF 30 -#define HCI_SET_MWS_SIGNALING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK 0x02 -#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF 30 -#define HCI_SET_MWS_TRANSPORT_LAYER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF] & HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK 0x04 -#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF 30 -#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK) - -#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK 0x08 -#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF 30 -#define HCI_GET_MWS_TRANS_LAYER_CFG_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF] & HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK 0x10 -#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF 30 -#define HCI_SET_MWS_PATTERN_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF] & HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK) +#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK 0x01 +#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF 30 +#define HCI_SET_MWS_SIGNALING_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF] & \ + HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK 0x02 +#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF 30 +#define HCI_SET_MWS_TRANSPORT_LAYER_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF] & \ + HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK 0x04 +#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF 30 +#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF] & \ + HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK) + +#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK 0x08 +#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF 30 +#define HCI_GET_MWS_TRANS_LAYER_CFG_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF] & \ + HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK) + +#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK 0x10 +#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF 30 +#define HCI_SET_MWS_PATTERN_CONFIGURATION_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF] & \ + HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK) /* Supported Commands (Byte 30 bit 5) */ -#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK 0x20 -#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF 30 -#define HCI_SET_TRIG_CLK_CAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF] & HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK) - +#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK 0x20 +#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF 30 +#define HCI_SET_TRIG_CLK_CAP_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF] & \ + HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK) /* Supported Commands (Byte 30 bit 6-7) */ -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE 0x06 -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF 30 -#define HCI_TRUNCATED_PAGE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE) +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE 0x06 +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF 30 +#define HCI_TRUNCATED_PAGE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE) -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL 0x07 -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF 30 -#define HCI_TRUNCATED_PAGE_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL) +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL 0x07 +#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF 30 +#define HCI_TRUNCATED_PAGE_CANCEL_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF] & \ + HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL) /* Supported Commands (Byte 31 bit 6-7) */ -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST 0x00 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST) - -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE 0x01 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_RECEIVE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE) - -#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN 0x02 -#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF 31 -#define HCI_START_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_START_SYNC_TRAIN) - -#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN 0x03 -#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF 31 -#define HCI_RECEIVE_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN) - -#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR 0x04 -#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF 31 -#define HCI_SET_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR) - -#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR 0x05 -#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF 31 -#define HCI_DELETE_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR) - -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA 0x06 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA) - -#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM 0x07 -#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF 31 -#define HCI_READ_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM) +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST 0x00 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF] & \ + HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST) + +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE 0x01 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_RECEIVE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF] & \ + HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE) + +#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN 0x02 +#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF 31 +#define HCI_START_SYNC_TRAIN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF] & \ + HCI_SUPP_COMMANDS_START_SYNC_TRAIN) + +#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN 0x03 +#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF 31 +#define HCI_RECEIVE_SYNC_TRAIN_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF] & \ + HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN) + +#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR 0x04 +#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF 31 +#define HCI_SET_RESERVED_LT_ADDR_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF] & \ + HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR) + +#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR 0x05 +#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF 31 +#define HCI_DELETE_RESERVED_LT_ADDR_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF] & \ + HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR) + +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA 0x06 +#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF 31 +#define HCI_SET_CONLESS_SLAVE_BRCST_DATA_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF] & \ + HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA) + +#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM 0x07 +#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF 31 +#define HCI_READ_SYNC_TRAIN_PARAM_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF] & \ + HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM) /* Supported Commands (Byte 32 bit 0) */ -#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM 0x00 -#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF 32 -#define HCI_WRITE_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK 0x02 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF 32 -#define HCI_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF 32 -#define HCI_READ_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF 32 -#define HCI_WRITE_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF 32 -#define HCI_READ_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF 32 -#define HCI_WRITE_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK) +#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM 0x00 +#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF 32 +#define HCI_WRITE_SYNC_TRAIN_PARAM_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM) + +#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK 0x02 +#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF 32 +#define HCI_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF] & \ + HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK) + +#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK 0x04 +#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF 32 +#define HCI_READ_SECURE_CONNS_SUPPORT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF] & \ + HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK 0x08 +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF 32 +#define HCI_WRITE_SECURE_CONNS_SUPPORT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK) + +#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK 0x10 +#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF 32 +#define HCI_READ_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK) + +#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK 0x20 +#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF 32 +#define HCI_WRITE_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK) #define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF 32 -#define HCI_READ_LOCAL_OOB_EXTENDED_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK) +#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF 32 +#define HCI_READ_LOCAL_OOB_EXTENDED_DATA_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF] & \ + HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK) -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF 32 -#define HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK) +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK 0x80 +#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF 32 +#define HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF] & \ + HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK) /* supported LE remote control connection parameter request reply */ -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK 0x10 -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF 33 -#define HCI_LE_RC_CONN_PARAM_UPD_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF] & HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK) - -#define HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK 0x20 -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF 33 -#define HCI_LE_RC_CONN_PARAM_UPD_NEG_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF] & HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK) +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK 0x10 +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF 33 +#define HCI_LE_RC_CONN_PARAM_UPD_RPY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF] & \ + HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK) + +#define HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK 0x20 +#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF 33 +#define HCI_LE_RC_CONN_PARAM_UPD_NEG_RPY_SUPPORTED(x) \ + ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF] & \ + HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK) #endif - diff --git a/stack/include/hcimsgs.h b/stack/include/hcimsgs.h index 5322222c7..598d6fd83 100644 --- a/stack/include/hcimsgs.h +++ b/stack/include/hcimsgs.h @@ -20,795 +20,813 @@ #define HCIMSGS_H #include "bt_target.h" -#include "hcidefs.h" #include "bt_types.h" +#include "hcidefs.h" #ifdef __cplusplus extern "C" { #endif -void bte_main_hci_send(BT_HDR *p_msg, uint16_t event); +void bte_main_hci_send(BT_HDR* p_msg, uint16_t event); void bte_main_lpm_allow_bt_device_sleep(void); /* Message by message.... */ extern void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration, - uint8_t response_cnt); + uint8_t response_cnt); #define HCIC_PARAM_SIZE_INQUIRY 5 +#define HCIC_INQ_INQ_LAP_OFF 0 +#define HCIC_INQ_DUR_OFF 3 +#define HCIC_INQ_RSP_CNT_OFF 4 +/* Inquiry */ -#define HCIC_INQ_INQ_LAP_OFF 0 -#define HCIC_INQ_DUR_OFF 3 -#define HCIC_INQ_RSP_CNT_OFF 4 - /* Inquiry */ - - /* Inquiry Cancel */ +/* Inquiry Cancel */ extern void btsnd_hcic_inq_cancel(void); -#define HCIC_PARAM_SIZE_INQ_CANCEL 0 +#define HCIC_PARAM_SIZE_INQ_CANCEL 0 - /* Periodic Inquiry Mode */ +/* Periodic Inquiry Mode */ extern void btsnd_hcic_per_inq_mode(uint16_t max_period, uint16_t min_period, - const LAP inq_lap, uint8_t duration, - uint8_t response_cnt); + const LAP inq_lap, uint8_t duration, + uint8_t response_cnt); -#define HCIC_PARAM_SIZE_PER_INQ_MODE 9 +#define HCIC_PARAM_SIZE_PER_INQ_MODE 9 -#define HCI_PER_INQ_MAX_INTRVL_OFF 0 -#define HCI_PER_INQ_MIN_INTRVL_OFF 2 -#define HCI_PER_INQ_INQ_LAP_OFF 4 -#define HCI_PER_INQ_DURATION_OFF 7 -#define HCI_PER_INQ_RSP_CNT_OFF 8 - /* Periodic Inquiry Mode */ +#define HCI_PER_INQ_MAX_INTRVL_OFF 0 +#define HCI_PER_INQ_MIN_INTRVL_OFF 2 +#define HCI_PER_INQ_INQ_LAP_OFF 4 +#define HCI_PER_INQ_DURATION_OFF 7 +#define HCI_PER_INQ_RSP_CNT_OFF 8 +/* Periodic Inquiry Mode */ - /* Exit Periodic Inquiry Mode */ +/* Exit Periodic Inquiry Mode */ extern void btsnd_hcic_exit_per_inq(void); -#define HCIC_PARAM_SIZE_EXIT_PER_INQ 0 - /* Create Connection */ +#define HCIC_PARAM_SIZE_EXIT_PER_INQ 0 +/* Create Connection */ extern void btsnd_hcic_create_conn(BD_ADDR dest, uint16_t packet_types, - uint8_t page_scan_rep_mode, - uint8_t page_scan_mode, - uint16_t clock_offset, - uint8_t allow_switch); + uint8_t page_scan_rep_mode, + uint8_t page_scan_mode, + uint16_t clock_offset, uint8_t allow_switch); -#define HCIC_PARAM_SIZE_CREATE_CONN 13 +#define HCIC_PARAM_SIZE_CREATE_CONN 13 -#define HCIC_CR_CONN_BD_ADDR_OFF 0 -#define HCIC_CR_CONN_PKT_TYPES_OFF 6 -#define HCIC_CR_CONN_REP_MODE_OFF 8 +#define HCIC_CR_CONN_BD_ADDR_OFF 0 +#define HCIC_CR_CONN_PKT_TYPES_OFF 6 +#define HCIC_CR_CONN_REP_MODE_OFF 8 #define HCIC_CR_CONN_PAGE_SCAN_MODE_OFF 9 -#define HCIC_CR_CONN_CLK_OFF_OFF 10 -#define HCIC_CR_CONN_ALLOW_SWITCH_OFF 12 - /* Create Connection */ +#define HCIC_CR_CONN_CLK_OFF_OFF 10 +#define HCIC_CR_CONN_ALLOW_SWITCH_OFF 12 +/* Create Connection */ - /* Disconnect */ +/* Disconnect */ extern void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason); #define HCIC_PARAM_SIZE_DISCONNECT 3 -#define HCI_DISC_HANDLE_OFF 0 -#define HCI_DISC_REASON_OFF 2 - /* Disconnect */ +#define HCI_DISC_HANDLE_OFF 0 +#define HCI_DISC_REASON_OFF 2 +/* Disconnect */ #if (BTM_SCO_INCLUDED == TRUE) - /* Add SCO Connection */ -extern void btsnd_hcic_add_SCO_conn (uint16_t handle, uint16_t packet_types); +/* Add SCO Connection */ +extern void btsnd_hcic_add_SCO_conn(uint16_t handle, uint16_t packet_types); #endif /* BTM_SCO_INCLUDED */ -#define HCIC_PARAM_SIZE_ADD_SCO_CONN 4 +#define HCIC_PARAM_SIZE_ADD_SCO_CONN 4 -#define HCI_ADD_SCO_HANDLE_OFF 0 -#define HCI_ADD_SCO_PACKET_TYPES_OFF 2 - /* Add SCO Connection */ +#define HCI_ADD_SCO_HANDLE_OFF 0 +#define HCI_ADD_SCO_PACKET_TYPES_OFF 2 +/* Add SCO Connection */ - /* Create Connection Cancel */ +/* Create Connection Cancel */ extern void btsnd_hcic_create_conn_cancel(BD_ADDR dest); -#define HCIC_PARAM_SIZE_CREATE_CONN_CANCEL 6 +#define HCIC_PARAM_SIZE_CREATE_CONN_CANCEL 6 -#define HCIC_CR_CONN_CANCEL_BD_ADDR_OFF 0 - /* Create Connection Cancel */ +#define HCIC_CR_CONN_CANCEL_BD_ADDR_OFF 0 +/* Create Connection Cancel */ - /* Accept Connection Request */ -extern void btsnd_hcic_accept_conn (BD_ADDR bd_addr, uint8_t role); +/* Accept Connection Request */ +extern void btsnd_hcic_accept_conn(BD_ADDR bd_addr, uint8_t role); -#define HCIC_PARAM_SIZE_ACCEPT_CONN 7 +#define HCIC_PARAM_SIZE_ACCEPT_CONN 7 -#define HCI_ACC_CONN_BD_ADDR_OFF 0 -#define HCI_ACC_CONN_ROLE_OFF 6 - /* Accept Connection Request */ +#define HCI_ACC_CONN_BD_ADDR_OFF 0 +#define HCI_ACC_CONN_ROLE_OFF 6 +/* Accept Connection Request */ - /* Reject Connection Request */ -extern void btsnd_hcic_reject_conn (BD_ADDR bd_addr, uint8_t reason); +/* Reject Connection Request */ +extern void btsnd_hcic_reject_conn(BD_ADDR bd_addr, uint8_t reason); -#define HCIC_PARAM_SIZE_REJECT_CONN 7 +#define HCIC_PARAM_SIZE_REJECT_CONN 7 -#define HCI_REJ_CONN_BD_ADDR_OFF 0 -#define HCI_REJ_CONN_REASON_OFF 6 - /* Reject Connection Request */ +#define HCI_REJ_CONN_BD_ADDR_OFF 0 +#define HCI_REJ_CONN_REASON_OFF 6 +/* Reject Connection Request */ - /* Link Key Request Reply */ -extern void btsnd_hcic_link_key_req_reply (BD_ADDR bd_addr, - LINK_KEY link_key); +/* Link Key Request Reply */ +extern void btsnd_hcic_link_key_req_reply(BD_ADDR bd_addr, LINK_KEY link_key); -#define HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY 22 +#define HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY 22 -#define HCI_LINK_KEY_REPLY_BD_ADDR_OFF 0 +#define HCI_LINK_KEY_REPLY_BD_ADDR_OFF 0 #define HCI_LINK_KEY_REPLY_LINK_KEY_OFF 6 - /* Link Key Request Reply */ +/* Link Key Request Reply */ - /* Link Key Request Neg Reply */ -extern void btsnd_hcic_link_key_neg_reply (BD_ADDR bd_addr); +/* Link Key Request Neg Reply */ +extern void btsnd_hcic_link_key_neg_reply(BD_ADDR bd_addr); -#define HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY 6 +#define HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY 6 #define HCI_LINK_KEY_NEG_REP_BD_ADR_OFF 0 - /* Link Key Request Neg Reply */ +/* Link Key Request Neg Reply */ - /* PIN Code Request Reply */ -extern void btsnd_hcic_pin_code_req_reply (BD_ADDR bd_addr, - uint8_t pin_code_len, - PIN_CODE pin_code); +/* PIN Code Request Reply */ +extern void btsnd_hcic_pin_code_req_reply(BD_ADDR bd_addr, uint8_t pin_code_len, + PIN_CODE pin_code); -#define HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY 23 +#define HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY 23 -#define HCI_PIN_CODE_REPLY_BD_ADDR_OFF 0 -#define HCI_PIN_CODE_REPLY_PIN_LEN_OFF 6 +#define HCI_PIN_CODE_REPLY_BD_ADDR_OFF 0 +#define HCI_PIN_CODE_REPLY_PIN_LEN_OFF 6 #define HCI_PIN_CODE_REPLY_PIN_CODE_OFF 7 - /* PIN Code Request Reply */ +/* PIN Code Request Reply */ - /* Link Key Request Neg Reply */ -extern void btsnd_hcic_pin_code_neg_reply (BD_ADDR bd_addr); +/* Link Key Request Neg Reply */ +extern void btsnd_hcic_pin_code_neg_reply(BD_ADDR bd_addr); -#define HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY 6 +#define HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY 6 #define HCI_PIN_CODE_NEG_REP_BD_ADR_OFF 0 - /* Link Key Request Neg Reply */ +/* Link Key Request Neg Reply */ - /* Change Connection Type */ -extern void btsnd_hcic_change_conn_type (uint16_t handle, uint16_t packet_types); +/* Change Connection Type */ +extern void btsnd_hcic_change_conn_type(uint16_t handle, uint16_t packet_types); -#define HCIC_PARAM_SIZE_CHANGE_CONN_TYPE 4 +#define HCIC_PARAM_SIZE_CHANGE_CONN_TYPE 4 -#define HCI_CHNG_PKT_TYPE_HANDLE_OFF 0 -#define HCI_CHNG_PKT_TYPE_PKT_TYPE_OFF 2 - /* Change Connection Type */ +#define HCI_CHNG_PKT_TYPE_HANDLE_OFF 0 +#define HCI_CHNG_PKT_TYPE_PKT_TYPE_OFF 2 +/* Change Connection Type */ -#define HCIC_PARAM_SIZE_CMD_HANDLE 2 +#define HCIC_PARAM_SIZE_CMD_HANDLE 2 -#define HCI_CMD_HANDLE_HANDLE_OFF 0 +#define HCI_CMD_HANDLE_HANDLE_OFF 0 -extern void btsnd_hcic_auth_request (uint16_t handle); /* Authentication Request */ +extern void btsnd_hcic_auth_request( + uint16_t handle); /* Authentication Request */ - /* Set Connection Encryption */ -extern void btsnd_hcic_set_conn_encrypt (uint16_t handle, bool enable); -#define HCIC_PARAM_SIZE_SET_CONN_ENCRYPT 3 +/* Set Connection Encryption */ +extern void btsnd_hcic_set_conn_encrypt(uint16_t handle, bool enable); +#define HCIC_PARAM_SIZE_SET_CONN_ENCRYPT 3 +#define HCI_SET_ENCRYPT_HANDLE_OFF 0 +#define HCI_SET_ENCRYPT_ENABLE_OFF 2 +/* Set Connection Encryption */ -#define HCI_SET_ENCRYPT_HANDLE_OFF 0 -#define HCI_SET_ENCRYPT_ENABLE_OFF 2 - /* Set Connection Encryption */ +/* Remote Name Request */ +extern void btsnd_hcic_rmt_name_req(BD_ADDR bd_addr, uint8_t page_scan_rep_mode, + uint8_t page_scan_mode, + uint16_t clock_offset); - /* Remote Name Request */ -extern void btsnd_hcic_rmt_name_req (BD_ADDR bd_addr, - uint8_t page_scan_rep_mode, - uint8_t page_scan_mode, - uint16_t clock_offset); +#define HCIC_PARAM_SIZE_RMT_NAME_REQ 10 -#define HCIC_PARAM_SIZE_RMT_NAME_REQ 10 - -#define HCI_RMT_NAME_BD_ADDR_OFF 0 -#define HCI_RMT_NAME_REP_MODE_OFF 6 +#define HCI_RMT_NAME_BD_ADDR_OFF 0 +#define HCI_RMT_NAME_REP_MODE_OFF 6 #define HCI_RMT_NAME_PAGE_SCAN_MODE_OFF 7 -#define HCI_RMT_NAME_CLK_OFF_OFF 8 - /* Remote Name Request */ +#define HCI_RMT_NAME_CLK_OFF_OFF 8 +/* Remote Name Request */ - /* Remote Name Request Cancel */ +/* Remote Name Request Cancel */ extern void btsnd_hcic_rmt_name_req_cancel(BD_ADDR bd_addr); -#define HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL 6 +#define HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL 6 -#define HCI_RMT_NAME_CANCEL_BD_ADDR_OFF 0 - /* Remote Name Request Cancel */ +#define HCI_RMT_NAME_CANCEL_BD_ADDR_OFF 0 +/* Remote Name Request Cancel */ -extern void btsnd_hcic_rmt_features_req(uint16_t handle); /* Remote Features Request */ +extern void btsnd_hcic_rmt_features_req( + uint16_t handle); /* Remote Features Request */ - /* Remote Extended Features */ +/* Remote Extended Features */ extern void btsnd_hcic_rmt_ext_features(uint16_t handle, uint8_t page_num); -#define HCIC_PARAM_SIZE_RMT_EXT_FEATURES 3 - -#define HCI_RMT_EXT_FEATURES_HANDLE_OFF 0 -#define HCI_RMT_EXT_FEATURES_PAGE_NUM_OFF 2 - /* Remote Extended Features */ - - -extern void btsnd_hcic_rmt_ver_req(uint16_t handle); /* Remote Version Info Request */ -extern void btsnd_hcic_read_rmt_clk_offset(uint16_t handle); /* Remote Clock Offset */ -extern void btsnd_hcic_read_lmp_handle(uint16_t handle); /* Remote LMP Handle */ - -extern void btsnd_hcic_setup_esco_conn (uint16_t handle, - uint32_t tx_bw, uint32_t rx_bw, - uint16_t max_latency, uint16_t voice, - uint8_t retrans_effort, - uint16_t packet_types); -#define HCIC_PARAM_SIZE_SETUP_ESCO 17 - -#define HCI_SETUP_ESCO_HANDLE_OFF 0 -#define HCI_SETUP_ESCO_TX_BW_OFF 2 -#define HCI_SETUP_ESCO_RX_BW_OFF 6 -#define HCI_SETUP_ESCO_MAX_LAT_OFF 10 -#define HCI_SETUP_ESCO_VOICE_OFF 12 -#define HCI_SETUP_ESCO_RETRAN_EFF_OFF 14 -#define HCI_SETUP_ESCO_PKT_TYPES_OFF 15 - - -extern void btsnd_hcic_accept_esco_conn (BD_ADDR bd_addr, - uint32_t tx_bw, uint32_t rx_bw, - uint16_t max_latency, - uint16_t content_fmt, - uint8_t retrans_effort, - uint16_t packet_types); -#define HCIC_PARAM_SIZE_ACCEPT_ESCO 21 - -#define HCI_ACCEPT_ESCO_BDADDR_OFF 0 -#define HCI_ACCEPT_ESCO_TX_BW_OFF 6 -#define HCI_ACCEPT_ESCO_RX_BW_OFF 10 -#define HCI_ACCEPT_ESCO_MAX_LAT_OFF 14 -#define HCI_ACCEPT_ESCO_VOICE_OFF 16 -#define HCI_ACCEPT_ESCO_RETRAN_EFF_OFF 18 -#define HCI_ACCEPT_ESCO_PKT_TYPES_OFF 19 - - -extern void btsnd_hcic_reject_esco_conn (BD_ADDR bd_addr, uint8_t reason); -#define HCIC_PARAM_SIZE_REJECT_ESCO 7 - -#define HCI_REJECT_ESCO_BDADDR_OFF 0 -#define HCI_REJECT_ESCO_REASON_OFF 6 +#define HCIC_PARAM_SIZE_RMT_EXT_FEATURES 3 + +#define HCI_RMT_EXT_FEATURES_HANDLE_OFF 0 +#define HCI_RMT_EXT_FEATURES_PAGE_NUM_OFF 2 +/* Remote Extended Features */ + +extern void btsnd_hcic_rmt_ver_req( + uint16_t handle); /* Remote Version Info Request */ +extern void btsnd_hcic_read_rmt_clk_offset( + uint16_t handle); /* Remote Clock Offset */ +extern void btsnd_hcic_read_lmp_handle(uint16_t handle); /* Remote LMP Handle */ + +extern void btsnd_hcic_setup_esco_conn(uint16_t handle, uint32_t tx_bw, + uint32_t rx_bw, uint16_t max_latency, + uint16_t voice, uint8_t retrans_effort, + uint16_t packet_types); +#define HCIC_PARAM_SIZE_SETUP_ESCO 17 + +#define HCI_SETUP_ESCO_HANDLE_OFF 0 +#define HCI_SETUP_ESCO_TX_BW_OFF 2 +#define HCI_SETUP_ESCO_RX_BW_OFF 6 +#define HCI_SETUP_ESCO_MAX_LAT_OFF 10 +#define HCI_SETUP_ESCO_VOICE_OFF 12 +#define HCI_SETUP_ESCO_RETRAN_EFF_OFF 14 +#define HCI_SETUP_ESCO_PKT_TYPES_OFF 15 + +extern void btsnd_hcic_accept_esco_conn(BD_ADDR bd_addr, uint32_t tx_bw, + uint32_t rx_bw, uint16_t max_latency, + uint16_t content_fmt, + uint8_t retrans_effort, + uint16_t packet_types); +#define HCIC_PARAM_SIZE_ACCEPT_ESCO 21 + +#define HCI_ACCEPT_ESCO_BDADDR_OFF 0 +#define HCI_ACCEPT_ESCO_TX_BW_OFF 6 +#define HCI_ACCEPT_ESCO_RX_BW_OFF 10 +#define HCI_ACCEPT_ESCO_MAX_LAT_OFF 14 +#define HCI_ACCEPT_ESCO_VOICE_OFF 16 +#define HCI_ACCEPT_ESCO_RETRAN_EFF_OFF 18 +#define HCI_ACCEPT_ESCO_PKT_TYPES_OFF 19 + +extern void btsnd_hcic_reject_esco_conn(BD_ADDR bd_addr, uint8_t reason); +#define HCIC_PARAM_SIZE_REJECT_ESCO 7 + +#define HCI_REJECT_ESCO_BDADDR_OFF 0 +#define HCI_REJECT_ESCO_REASON_OFF 6 /* Hold Mode */ extern void btsnd_hcic_hold_mode(uint16_t handle, uint16_t max_hold_period, - uint16_t min_hold_period); - -#define HCIC_PARAM_SIZE_HOLD_MODE 6 + uint16_t min_hold_period); -#define HCI_HOLD_MODE_HANDLE_OFF 0 -#define HCI_HOLD_MODE_MAX_PER_OFF 2 -#define HCI_HOLD_MODE_MIN_PER_OFF 4 - /* Hold Mode */ +#define HCIC_PARAM_SIZE_HOLD_MODE 6 - /* Sniff Mode */ -extern void btsnd_hcic_sniff_mode(uint16_t handle, - uint16_t max_sniff_period, - uint16_t min_sniff_period, - uint16_t sniff_attempt, - uint16_t sniff_timeout); +#define HCI_HOLD_MODE_HANDLE_OFF 0 +#define HCI_HOLD_MODE_MAX_PER_OFF 2 +#define HCI_HOLD_MODE_MIN_PER_OFF 4 +/* Hold Mode */ -#define HCIC_PARAM_SIZE_SNIFF_MODE 10 +/* Sniff Mode */ +extern void btsnd_hcic_sniff_mode(uint16_t handle, uint16_t max_sniff_period, + uint16_t min_sniff_period, + uint16_t sniff_attempt, + uint16_t sniff_timeout); +#define HCIC_PARAM_SIZE_SNIFF_MODE 10 -#define HCI_SNIFF_MODE_HANDLE_OFF 0 -#define HCI_SNIFF_MODE_MAX_PER_OFF 2 -#define HCI_SNIFF_MODE_MIN_PER_OFF 4 -#define HCI_SNIFF_MODE_ATTEMPT_OFF 6 -#define HCI_SNIFF_MODE_TIMEOUT_OFF 8 - /* Sniff Mode */ +#define HCI_SNIFF_MODE_HANDLE_OFF 0 +#define HCI_SNIFF_MODE_MAX_PER_OFF 2 +#define HCI_SNIFF_MODE_MIN_PER_OFF 4 +#define HCI_SNIFF_MODE_ATTEMPT_OFF 6 +#define HCI_SNIFF_MODE_TIMEOUT_OFF 8 +/* Sniff Mode */ -extern void btsnd_hcic_exit_sniff_mode(uint16_t handle); /* Exit Sniff Mode */ +extern void btsnd_hcic_exit_sniff_mode(uint16_t handle); /* Exit Sniff Mode */ - /* Park Mode */ -extern void btsnd_hcic_park_mode (uint16_t handle, - uint16_t beacon_max_interval, - uint16_t beacon_min_interval); +/* Park Mode */ +extern void btsnd_hcic_park_mode(uint16_t handle, uint16_t beacon_max_interval, + uint16_t beacon_min_interval); -#define HCIC_PARAM_SIZE_PARK_MODE 6 +#define HCIC_PARAM_SIZE_PARK_MODE 6 -#define HCI_PARK_MODE_HANDLE_OFF 0 -#define HCI_PARK_MODE_MAX_PER_OFF 2 -#define HCI_PARK_MODE_MIN_PER_OFF 4 - /* Park Mode */ +#define HCI_PARK_MODE_HANDLE_OFF 0 +#define HCI_PARK_MODE_MAX_PER_OFF 2 +#define HCI_PARK_MODE_MIN_PER_OFF 4 +/* Park Mode */ -extern void btsnd_hcic_exit_park_mode(uint16_t handle); /* Exit Park Mode */ +extern void btsnd_hcic_exit_park_mode(uint16_t handle); /* Exit Park Mode */ - /* QoS Setup */ -extern void btsnd_hcic_qos_setup (uint16_t handle, uint8_t flags, - uint8_t service_type, - uint32_t token_rate, uint32_t peak, - uint32_t latency, uint32_t delay_var); +/* QoS Setup */ +extern void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags, + uint8_t service_type, uint32_t token_rate, + uint32_t peak, uint32_t latency, + uint32_t delay_var); -#define HCIC_PARAM_SIZE_QOS_SETUP 20 +#define HCIC_PARAM_SIZE_QOS_SETUP 20 -#define HCI_QOS_HANDLE_OFF 0 -#define HCI_QOS_FLAGS_OFF 2 -#define HCI_QOS_SERVICE_TYPE_OFF 3 -#define HCI_QOS_TOKEN_RATE_OFF 4 -#define HCI_QOS_PEAK_BANDWIDTH_OFF 8 -#define HCI_QOS_LATENCY_OFF 12 -#define HCI_QOS_DELAY_VAR_OFF 16 - /* QoS Setup */ +#define HCI_QOS_HANDLE_OFF 0 +#define HCI_QOS_FLAGS_OFF 2 +#define HCI_QOS_SERVICE_TYPE_OFF 3 +#define HCI_QOS_TOKEN_RATE_OFF 4 +#define HCI_QOS_PEAK_BANDWIDTH_OFF 8 +#define HCI_QOS_LATENCY_OFF 12 +#define HCI_QOS_DELAY_VAR_OFF 16 +/* QoS Setup */ - /* Switch Role Request */ -extern void btsnd_hcic_switch_role (BD_ADDR bd_addr, uint8_t role); +/* Switch Role Request */ +extern void btsnd_hcic_switch_role(BD_ADDR bd_addr, uint8_t role); -#define HCIC_PARAM_SIZE_SWITCH_ROLE 7 +#define HCIC_PARAM_SIZE_SWITCH_ROLE 7 -#define HCI_SWITCH_BD_ADDR_OFF 0 -#define HCI_SWITCH_ROLE_OFF 6 - /* Switch Role Request */ +#define HCI_SWITCH_BD_ADDR_OFF 0 +#define HCI_SWITCH_ROLE_OFF 6 +/* Switch Role Request */ - /* Write Policy Settings */ +/* Write Policy Settings */ extern void btsnd_hcic_write_policy_set(uint16_t handle, uint16_t settings); -#define HCIC_PARAM_SIZE_WRITE_POLICY_SET 4 +#define HCIC_PARAM_SIZE_WRITE_POLICY_SET 4 -#define HCI_WRITE_POLICY_HANDLE_OFF 0 -#define HCI_WRITE_POLICY_SETTINGS_OFF 2 - /* Write Policy Settings */ +#define HCI_WRITE_POLICY_HANDLE_OFF 0 +#define HCI_WRITE_POLICY_SETTINGS_OFF 2 +/* Write Policy Settings */ - /* Write Default Policy Settings */ +/* Write Default Policy Settings */ extern void btsnd_hcic_write_def_policy_set(uint16_t settings); -#define HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET 2 +#define HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET 2 -#define HCI_WRITE_DEF_POLICY_SETTINGS_OFF 0 - /* Write Default Policy Settings */ +#define HCI_WRITE_DEF_POLICY_SETTINGS_OFF 0 +/* Write Default Policy Settings */ /****************************************** * Lisbon Features ******************************************/ #if (BTM_SSR_INCLUDED == TRUE) - /* Sniff Subrating */ +/* Sniff Subrating */ extern void btsnd_hcic_sniff_sub_rate(uint16_t handle, uint16_t max_lat, - uint16_t min_remote_lat, - uint16_t min_local_lat); + uint16_t min_remote_lat, + uint16_t min_local_lat); -#define HCIC_PARAM_SIZE_SNIFF_SUB_RATE 8 +#define HCIC_PARAM_SIZE_SNIFF_SUB_RATE 8 -#define HCI_SNIFF_SUB_RATE_HANDLE_OFF 0 -#define HCI_SNIFF_SUB_RATE_MAX_LAT_OFF 2 -#define HCI_SNIFF_SUB_RATE_MIN_REM_LAT_OFF 4 -#define HCI_SNIFF_SUB_RATE_MIN_LOC_LAT_OFF 6 - /* Sniff Subrating */ +#define HCI_SNIFF_SUB_RATE_HANDLE_OFF 0 +#define HCI_SNIFF_SUB_RATE_MAX_LAT_OFF 2 +#define HCI_SNIFF_SUB_RATE_MIN_REM_LAT_OFF 4 +#define HCI_SNIFF_SUB_RATE_MIN_LOC_LAT_OFF 6 +/* Sniff Subrating */ -#else /* BTM_SSR_INCLUDED == FALSE */ +#else /* BTM_SSR_INCLUDED == FALSE */ -#define btsnd_hcic_sniff_sub_rate(handle, max_lat, min_remote_lat, min_local_lat) false +#define btsnd_hcic_sniff_sub_rate(handle, max_lat, min_remote_lat, \ + min_local_lat) \ + false -#endif /* BTM_SSR_INCLUDED */ +#endif /* BTM_SSR_INCLUDED */ - /* Extended Inquiry Response */ -extern void btsnd_hcic_write_ext_inquiry_response(void *buffer, uint8_t fec_req); +/* Extended Inquiry Response */ +extern void btsnd_hcic_write_ext_inquiry_response(void* buffer, + uint8_t fec_req); -#define HCIC_PARAM_SIZE_EXT_INQ_RESP 241 +#define HCIC_PARAM_SIZE_EXT_INQ_RESP 241 -#define HCIC_EXT_INQ_RESP_FEC_OFF 0 -#define HCIC_EXT_INQ_RESP_RESPONSE 1 - /* IO Capabilities Response */ -extern void btsnd_hcic_io_cap_req_reply (BD_ADDR bd_addr, uint8_t capability, - uint8_t oob_present, uint8_t auth_req); +#define HCIC_EXT_INQ_RESP_FEC_OFF 0 +#define HCIC_EXT_INQ_RESP_RESPONSE 1 +/* IO Capabilities Response */ +extern void btsnd_hcic_io_cap_req_reply(BD_ADDR bd_addr, uint8_t capability, + uint8_t oob_present, uint8_t auth_req); -#define HCIC_PARAM_SIZE_IO_CAP_RESP 9 +#define HCIC_PARAM_SIZE_IO_CAP_RESP 9 -#define HCI_IO_CAP_BD_ADDR_OFF 0 -#define HCI_IO_CAPABILITY_OFF 6 -#define HCI_IO_CAP_OOB_DATA_OFF 7 -#define HCI_IO_CAP_AUTH_REQ_OFF 8 +#define HCI_IO_CAP_BD_ADDR_OFF 0 +#define HCI_IO_CAPABILITY_OFF 6 +#define HCI_IO_CAP_OOB_DATA_OFF 7 +#define HCI_IO_CAP_AUTH_REQ_OFF 8 - /* IO Capabilities Req Neg Reply */ -extern void btsnd_hcic_io_cap_req_neg_reply (BD_ADDR bd_addr, uint8_t err_code); +/* IO Capabilities Req Neg Reply */ +extern void btsnd_hcic_io_cap_req_neg_reply(BD_ADDR bd_addr, uint8_t err_code); #define HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY 7 -#define HCI_IO_CAP_NR_BD_ADDR_OFF 0 -#define HCI_IO_CAP_NR_ERR_CODE 6 +#define HCI_IO_CAP_NR_BD_ADDR_OFF 0 +#define HCI_IO_CAP_NR_ERR_CODE 6 - /* Read Local OOB Data */ -extern void btsnd_hcic_read_local_oob_data (void); +/* Read Local OOB Data */ +extern void btsnd_hcic_read_local_oob_data(void); -#define HCIC_PARAM_SIZE_R_LOCAL_OOB 0 +#define HCIC_PARAM_SIZE_R_LOCAL_OOB 0 +extern void btsnd_hcic_user_conf_reply(BD_ADDR bd_addr, bool is_yes); -extern void btsnd_hcic_user_conf_reply (BD_ADDR bd_addr, bool is_yes); +#define HCIC_PARAM_SIZE_UCONF_REPLY 6 -#define HCIC_PARAM_SIZE_UCONF_REPLY 6 +#define HCI_USER_CONF_BD_ADDR_OFF 0 -#define HCI_USER_CONF_BD_ADDR_OFF 0 +extern void btsnd_hcic_user_passkey_reply(BD_ADDR bd_addr, uint32_t value); +#define HCIC_PARAM_SIZE_U_PKEY_REPLY 10 -extern void btsnd_hcic_user_passkey_reply (BD_ADDR bd_addr, uint32_t value); +#define HCI_USER_PASSKEY_BD_ADDR_OFF 0 +#define HCI_USER_PASSKEY_VALUE_OFF 6 -#define HCIC_PARAM_SIZE_U_PKEY_REPLY 10 - -#define HCI_USER_PASSKEY_BD_ADDR_OFF 0 -#define HCI_USER_PASSKEY_VALUE_OFF 6 - - -extern void btsnd_hcic_user_passkey_neg_reply (BD_ADDR bd_addr); +extern void btsnd_hcic_user_passkey_neg_reply(BD_ADDR bd_addr); #define HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY 6 #define HCI_USER_PASSKEY_NEG_BD_ADDR_OFF 0 - /* Remote OOB Data Request Reply */ -extern void btsnd_hcic_rem_oob_reply (BD_ADDR bd_addr, uint8_t *p_c, - uint8_t *p_r); +/* Remote OOB Data Request Reply */ +extern void btsnd_hcic_rem_oob_reply(BD_ADDR bd_addr, uint8_t* p_c, + uint8_t* p_r); -#define HCIC_PARAM_SIZE_REM_OOB_REPLY 38 +#define HCIC_PARAM_SIZE_REM_OOB_REPLY 38 -#define HCI_REM_OOB_DATA_BD_ADDR_OFF 0 -#define HCI_REM_OOB_DATA_C_OFF 6 -#define HCI_REM_OOB_DATA_R_OFF 22 +#define HCI_REM_OOB_DATA_BD_ADDR_OFF 0 +#define HCI_REM_OOB_DATA_C_OFF 6 +#define HCI_REM_OOB_DATA_R_OFF 22 - /* Remote OOB Data Request Negative Reply */ -extern void btsnd_hcic_rem_oob_neg_reply (BD_ADDR bd_addr); +/* Remote OOB Data Request Negative Reply */ +extern void btsnd_hcic_rem_oob_neg_reply(BD_ADDR bd_addr); -#define HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY 6 +#define HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY 6 -#define HCI_REM_OOB_DATA_NEG_BD_ADDR_OFF 0 +#define HCI_REM_OOB_DATA_NEG_BD_ADDR_OFF 0 - /* Read Tx Power Level */ -extern void btsnd_hcic_read_inq_tx_power (void); +/* Read Tx Power Level */ +extern void btsnd_hcic_read_inq_tx_power(void); -#define HCIC_PARAM_SIZE_R_TX_POWER 0 +#define HCIC_PARAM_SIZE_R_TX_POWER 0 - /* Read Default Erroneous Data Reporting */ -extern void btsnd_hcic_read_default_erroneous_data_rpt (void); +/* Read Default Erroneous Data Reporting */ +extern void btsnd_hcic_read_default_erroneous_data_rpt(void); -#define HCIC_PARAM_SIZE_R_ERR_DATA_RPT 0 +#define HCIC_PARAM_SIZE_R_ERR_DATA_RPT 0 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) -extern void btsnd_hcic_enhanced_flush (uint16_t handle, uint8_t packet_type); +extern void btsnd_hcic_enhanced_flush(uint16_t handle, uint8_t packet_type); -#define HCIC_PARAM_SIZE_ENHANCED_FLUSH 3 +#define HCIC_PARAM_SIZE_ENHANCED_FLUSH 3 #endif +extern void btsnd_hcic_send_keypress_notif(BD_ADDR bd_addr, uint8_t notif); -extern void btsnd_hcic_send_keypress_notif (BD_ADDR bd_addr, uint8_t notif); +#define HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF 7 -#define HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF 7 - -#define HCI_SEND_KEYPRESS_NOTIF_BD_ADDR_OFF 0 -#define HCI_SEND_KEYPRESS_NOTIF_NOTIF_OFF 6 +#define HCI_SEND_KEYPRESS_NOTIF_BD_ADDR_OFF 0 +#define HCI_SEND_KEYPRESS_NOTIF_NOTIF_OFF 6 /**** end of Simple Pairing Commands ****/ - /* Store Current Settings */ -#define MAX_FILT_COND (sizeof (BD_ADDR) + 1) +/* Store Current Settings */ +#define MAX_FILT_COND (sizeof(BD_ADDR) + 1) extern void btsnd_hcic_set_event_filter(uint8_t filt_type, - uint8_t filt_cond_type, - uint8_t *filt_cond, - uint8_t filt_cond_len); + uint8_t filt_cond_type, + uint8_t* filt_cond, + uint8_t filt_cond_len); -#define HCIC_PARAM_SIZE_SET_EVT_FILTER 9 +#define HCIC_PARAM_SIZE_SET_EVT_FILTER 9 -#define HCI_FILT_COND_FILT_TYPE_OFF 0 -#define HCI_FILT_COND_COND_TYPE_OFF 1 -#define HCI_FILT_COND_FILT_OFF 2 - /* Set Event Filter */ +#define HCI_FILT_COND_FILT_TYPE_OFF 0 +#define HCI_FILT_COND_COND_TYPE_OFF 1 +#define HCI_FILT_COND_FILT_OFF 2 +/* Set Event Filter */ - /* Delete Stored Key */ -extern void btsnd_hcic_delete_stored_key (BD_ADDR bd_addr, bool delete_all_flag); +/* Delete Stored Key */ +extern void btsnd_hcic_delete_stored_key(BD_ADDR bd_addr, bool delete_all_flag); -#define HCIC_PARAM_SIZE_DELETE_STORED_KEY 7 +#define HCIC_PARAM_SIZE_DELETE_STORED_KEY 7 -#define HCI_DELETE_KEY_BD_ADDR_OFF 0 -#define HCI_DELETE_KEY_ALL_FLAG_OFF 6 - /* Delete Stored Key */ +#define HCI_DELETE_KEY_BD_ADDR_OFF 0 +#define HCI_DELETE_KEY_ALL_FLAG_OFF 6 +/* Delete Stored Key */ - /* Change Local Name */ +/* Change Local Name */ extern void btsnd_hcic_change_name(BD_NAME name); -#define HCIC_PARAM_SIZE_CHANGE_NAME BD_NAME_LEN - -#define HCI_CHANGE_NAME_NAME_OFF 0 - /* Change Local Name */ +#define HCIC_PARAM_SIZE_CHANGE_NAME BD_NAME_LEN +#define HCI_CHANGE_NAME_NAME_OFF 0 +/* Change Local Name */ -#define HCIC_PARAM_SIZE_READ_CMD 0 +#define HCIC_PARAM_SIZE_READ_CMD 0 -#define HCIC_PARAM_SIZE_WRITE_PARAM1 1 +#define HCIC_PARAM_SIZE_WRITE_PARAM1 1 -#define HCIC_WRITE_PARAM1_PARAM_OFF 0 +#define HCIC_WRITE_PARAM1_PARAM_OFF 0 -#define HCIC_PARAM_SIZE_WRITE_PARAM2 2 +#define HCIC_PARAM_SIZE_WRITE_PARAM2 2 -#define HCIC_WRITE_PARAM2_PARAM_OFF 0 +#define HCIC_WRITE_PARAM2_PARAM_OFF 0 -#define HCIC_PARAM_SIZE_WRITE_PARAM3 3 +#define HCIC_PARAM_SIZE_WRITE_PARAM3 3 -#define HCIC_WRITE_PARAM3_PARAM_OFF 0 +#define HCIC_WRITE_PARAM3_PARAM_OFF 0 -#define HCIC_PARAM_SIZE_SET_AFH_CHANNELS 10 +#define HCIC_PARAM_SIZE_SET_AFH_CHANNELS 10 -extern void btsnd_hcic_write_pin_type(uint8_t type); /* Write PIN Type */ -extern void btsnd_hcic_write_auto_accept(uint8_t flag); /* Write Auto Accept */ -extern void btsnd_hcic_read_name (void); /* Read Local Name */ -extern void btsnd_hcic_write_page_tout(uint16_t timeout); /* Write Page Timout */ -extern void btsnd_hcic_write_scan_enable(uint8_t flag); /* Write Scan Enable */ -extern void btsnd_hcic_write_pagescan_cfg(uint16_t interval, - uint16_t window); /* Write Page Scan Activity */ +extern void btsnd_hcic_write_pin_type(uint8_t type); /* Write PIN Type */ +extern void btsnd_hcic_write_auto_accept(uint8_t flag); /* Write Auto Accept */ +extern void btsnd_hcic_read_name(void); /* Read Local Name */ +extern void btsnd_hcic_write_page_tout( + uint16_t timeout); /* Write Page Timout */ +extern void btsnd_hcic_write_scan_enable(uint8_t flag); /* Write Scan Enable */ +extern void btsnd_hcic_write_pagescan_cfg( + uint16_t interval, uint16_t window); /* Write Page Scan Activity */ -#define HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG 4 +#define HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG 4 -#define HCI_SCAN_CFG_INTERVAL_OFF 0 -#define HCI_SCAN_CFG_WINDOW_OFF 2 - /* Write Page Scan Activity */ +#define HCI_SCAN_CFG_INTERVAL_OFF 0 +#define HCI_SCAN_CFG_WINDOW_OFF 2 +/* Write Page Scan Activity */ - /* Write Inquiry Scan Activity */ +/* Write Inquiry Scan Activity */ extern void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window); -#define HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG 4 +#define HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG 4 -#define HCI_SCAN_CFG_INTERVAL_OFF 0 -#define HCI_SCAN_CFG_WINDOW_OFF 2 - /* Write Inquiry Scan Activity */ +#define HCI_SCAN_CFG_INTERVAL_OFF 0 +#define HCI_SCAN_CFG_WINDOW_OFF 2 +/* Write Inquiry Scan Activity */ -extern void btsnd_hcic_write_auth_enable(uint8_t flag); /* Write Authentication Enable */ -extern void btsnd_hcic_write_dev_class(DEV_CLASS dev); /* Write Class of Device */ -extern void btsnd_hcic_write_voice_settings(uint16_t flags); /* Write Voice Settings */ +extern void btsnd_hcic_write_auth_enable( + uint8_t flag); /* Write Authentication Enable */ +extern void btsnd_hcic_write_dev_class( + DEV_CLASS dev); /* Write Class of Device */ +extern void btsnd_hcic_write_voice_settings( + uint16_t flags); /* Write Voice Settings */ /* Host Controller to Host flow control */ -#define HCI_HOST_FLOW_CTRL_OFF 0 -#define HCI_HOST_FLOW_CTRL_ACL_ON 1 -#define HCI_HOST_FLOW_CTRL_SCO_ON 2 -#define HCI_HOST_FLOW_CTRL_BOTH_ON 3 +#define HCI_HOST_FLOW_CTRL_OFF 0 +#define HCI_HOST_FLOW_CTRL_ACL_ON 1 +#define HCI_HOST_FLOW_CTRL_SCO_ON 2 +#define HCI_HOST_FLOW_CTRL_BOTH_ON 3 -extern void btsnd_hcic_write_auto_flush_tout(uint16_t handle, - uint16_t timeout); /* Write Retransmit Timout */ +extern void btsnd_hcic_write_auto_flush_tout( + uint16_t handle, uint16_t timeout); /* Write Retransmit Timout */ -#define HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT 4 +#define HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT 4 -#define HCI_FLUSH_TOUT_HANDLE_OFF 0 -#define HCI_FLUSH_TOUT_TOUT_OFF 2 +#define HCI_FLUSH_TOUT_HANDLE_OFF 0 +#define HCI_FLUSH_TOUT_TOUT_OFF 2 -extern void btsnd_hcic_read_tx_power(uint16_t handle, uint8_t type); /* Read Tx Power */ +extern void btsnd_hcic_read_tx_power(uint16_t handle, + uint8_t type); /* Read Tx Power */ -#define HCIC_PARAM_SIZE_READ_TX_POWER 3 +#define HCIC_PARAM_SIZE_READ_TX_POWER 3 -#define HCI_READ_TX_POWER_HANDLE_OFF 0 -#define HCI_READ_TX_POWER_TYPE_OFF 2 +#define HCI_READ_TX_POWER_HANDLE_OFF 0 +#define HCI_READ_TX_POWER_TYPE_OFF 2 /* Read transmit power level parameter */ -#define HCI_READ_CURRENT 0x00 -#define HCI_READ_MAXIMUM 0x01 +#define HCI_READ_CURRENT 0x00 +#define HCI_READ_MAXIMUM 0x01 -extern void btsnd_hcic_host_num_xmitted_pkts (uint8_t num_handles, - uint16_t *handle, - uint16_t *num_pkts); /* Set Host Buffer Size */ +extern void btsnd_hcic_host_num_xmitted_pkts( + uint8_t num_handles, uint16_t* handle, + uint16_t* num_pkts); /* Set Host Buffer Size */ -#define HCIC_PARAM_SIZE_NUM_PKTS_DONE_SIZE sizeof(btmsg_hcic_num_pkts_done_t) +#define HCIC_PARAM_SIZE_NUM_PKTS_DONE_SIZE sizeof(btmsg_hcic_num_pkts_done_t) -#define MAX_DATA_HANDLES 10 +#define MAX_DATA_HANDLES 10 -#define HCI_PKTS_DONE_NUM_HANDLES_OFF 0 -#define HCI_PKTS_DONE_HANDLE_OFF 1 -#define HCI_PKTS_DONE_NUM_PKTS_OFF 3 +#define HCI_PKTS_DONE_NUM_HANDLES_OFF 0 +#define HCI_PKTS_DONE_HANDLE_OFF 1 +#define HCI_PKTS_DONE_NUM_PKTS_OFF 3 - /* Write Link Supervision Timeout */ -extern void btsnd_hcic_write_link_super_tout(uint8_t local_controller_id, uint16_t handle, uint16_t timeout); +/* Write Link Supervision Timeout */ +extern void btsnd_hcic_write_link_super_tout(uint8_t local_controller_id, + uint16_t handle, uint16_t timeout); -#define HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT 4 +#define HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT 4 -#define HCI_LINK_SUPER_TOUT_HANDLE_OFF 0 -#define HCI_LINK_SUPER_TOUT_TOUT_OFF 2 - /* Write Link Supervision Timeout */ +#define HCI_LINK_SUPER_TOUT_HANDLE_OFF 0 +#define HCI_LINK_SUPER_TOUT_TOUT_OFF 2 +/* Write Link Supervision Timeout */ -extern void btsnd_hcic_write_cur_iac_lap (uint8_t num_cur_iac, - LAP * const iac_lap); /* Write Current IAC LAP */ +extern void btsnd_hcic_write_cur_iac_lap( + uint8_t num_cur_iac, LAP* const iac_lap); /* Write Current IAC LAP */ -#define MAX_IAC_LAPS 0x40 +#define MAX_IAC_LAPS 0x40 -#define HCI_WRITE_IAC_LAP_NUM_OFF 0 -#define HCI_WRITE_IAC_LAP_LAP_OFF 1 - /* Write Current IAC LAP */ +#define HCI_WRITE_IAC_LAP_NUM_OFF 0 +#define HCI_WRITE_IAC_LAP_LAP_OFF 1 +/* Write Current IAC LAP */ -extern void btsnd_hcic_get_link_quality (uint16_t handle); /* Get Link Quality */ -extern void btsnd_hcic_read_rssi (uint16_t handle); /* Read RSSI */ -extern void btsnd_hcic_enable_test_mode (void); /* Enable Device Under Test Mode */ -extern void btsnd_hcic_write_pagescan_type(uint8_t type); /* Write Page Scan Type */ -extern void btsnd_hcic_write_inqscan_type(uint8_t type); /* Write Inquiry Scan Type */ -extern void btsnd_hcic_write_inquiry_mode(uint8_t type); /* Write Inquiry Mode */ +extern void btsnd_hcic_get_link_quality(uint16_t handle); /* Get Link Quality */ +extern void btsnd_hcic_read_rssi(uint16_t handle); /* Read RSSI */ +extern void btsnd_hcic_enable_test_mode( + void); /* Enable Device Under Test Mode */ +extern void btsnd_hcic_write_pagescan_type( + uint8_t type); /* Write Page Scan Type */ +extern void btsnd_hcic_write_inqscan_type( + uint8_t type); /* Write Inquiry Scan Type */ +extern void btsnd_hcic_write_inquiry_mode( + uint8_t type); /* Write Inquiry Mode */ #define HCI_DATA_HANDLE_MASK 0x0FFF -#define HCID_GET_HANDLE_EVENT(p) (uint16_t)((*((uint8_t *)((p) + 1) + (p)->offset) + \ - (*((uint8_t *)((p) + 1) + (p)->offset + 1) << 8))) +#define HCID_GET_HANDLE_EVENT(p) \ + (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \ + (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8))) -#define HCID_GET_HANDLE(u16) (uint16_t)((u16) & HCI_DATA_HANDLE_MASK) +#define HCID_GET_HANDLE(u16) (uint16_t)((u16)&HCI_DATA_HANDLE_MASK) -#define HCI_DATA_EVENT_MASK 3 +#define HCI_DATA_EVENT_MASK 3 #define HCI_DATA_EVENT_OFFSET 12 -#define HCID_GET_EVENT(u16) (uint8_t)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK) +#define HCID_GET_EVENT(u16) \ + (uint8_t)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK) -#define HCI_DATA_BCAST_MASK 3 +#define HCI_DATA_BCAST_MASK 3 #define HCI_DATA_BCAST_OFFSET 10 -#define HCID_GET_BCAST(u16) (uint8_t)(((u16) >> HCI_DATA_BCAST_OFFSET) & HCI_DATA_BCAST_MASK) +#define HCID_GET_BCAST(u16) \ + (uint8_t)(((u16) >> HCI_DATA_BCAST_OFFSET) & HCI_DATA_BCAST_MASK) -#define HCID_GET_ACL_LEN(p) (uint16_t)((*((uint8_t *)((p) + 1) + (p)->offset + 2) + \ - (*((uint8_t *)((p) + 1) + (p)->offset + 3) << 8))) +#define HCID_GET_ACL_LEN(p) \ + (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset + 2) + \ + (*((uint8_t*)((p) + 1) + (p)->offset + 3) << 8))) -#define HCID_HEADER_SIZE 4 +#define HCID_HEADER_SIZE 4 -#define HCID_GET_SCO_LEN(p) (*((uint8_t *)((p) + 1) + (p)->offset + 2)) +#define HCID_GET_SCO_LEN(p) (*((uint8_t*)((p) + 1) + (p)->offset + 2)) -extern void btsnd_hcic_vendor_spec_cmd (void *buffer, uint16_t opcode, - uint8_t len, uint8_t *p_data, - void *p_cmd_cplt_cback); +extern void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, + uint8_t len, uint8_t* p_data, + void* p_cmd_cplt_cback); /******************************************************************************* * BLE Commands * Note: "local_controller_id" is for transport, not counted in HCI * message size ******************************************************************************/ -#define HCIC_BLE_RAND_DI_SIZE 8 -#define HCIC_BLE_ENCRYT_KEY_SIZE 16 -#define HCIC_BLE_IRK_SIZE 16 - -#define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8 -#define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6 -#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15 -#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31 -#define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1 -#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7 -#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2 -#define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25 -#define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0 -#define HCIC_PARAM_SIZE_CLEAR_WHITE_LIST 0 -#define HCIC_PARAM_SIZE_ADD_WHITE_LIST 7 -#define HCIC_PARAM_SIZE_REMOVE_WHITE_LIST 7 -#define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14 -#define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5 -#define HCIC_PARAM_SIZE_READ_CHNL_MAP 2 -#define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2 -#define HCIC_PARAM_SIZE_BLE_ENCRYPT 32 -#define HCIC_PARAM_SIZE_BLE_RAND 0 +#define HCIC_BLE_RAND_DI_SIZE 8 +#define HCIC_BLE_ENCRYT_KEY_SIZE 16 +#define HCIC_BLE_IRK_SIZE 16 + +#define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8 +#define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6 +#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31 +#define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7 +#define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2 +#define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25 +#define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0 +#define HCIC_PARAM_SIZE_CLEAR_WHITE_LIST 0 +#define HCIC_PARAM_SIZE_ADD_WHITE_LIST 7 +#define HCIC_PARAM_SIZE_REMOVE_WHITE_LIST 7 +#define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14 +#define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5 +#define HCIC_PARAM_SIZE_READ_CHNL_MAP 2 +#define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2 +#define HCIC_PARAM_SIZE_BLE_ENCRYPT 32 +#define HCIC_PARAM_SIZE_BLE_RAND 0 #define HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED 2 -#define HCIC_BLE_RAND_DI_SIZE 8 -#define HCIC_BLE_ENCRYT_KEY_SIZE 16 -#define HCIC_PARAM_SIZE_BLE_START_ENC (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYT_KEY_SIZE) -#define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYT_KEY_SIZE) -#define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2 -#define HCIC_BLE_CHNL_MAP_SIZE 5 -#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31 - -#define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2) -#define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7 -#define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0 -#define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0 -#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7 -#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7 -#define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1 -#define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT 2 -#define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6 -#define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11 +#define HCIC_BLE_RAND_DI_SIZE 8 +#define HCIC_BLE_ENCRYT_KEY_SIZE 16 +#define HCIC_PARAM_SIZE_BLE_START_ENC \ + (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYT_KEY_SIZE) +#define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYT_KEY_SIZE) +#define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2 +#define HCIC_BLE_CHNL_MAP_SIZE 5 +#define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31 + +#define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2) +#define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7 +#define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7 +#define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7 +#define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1 +#define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT 2 +#define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6 +#define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11 /* ULP HCI command */ -extern void btsnd_hcic_ble_set_evt_mask (BT_EVENT_MASK event_mask); +extern void btsnd_hcic_ble_set_evt_mask(BT_EVENT_MASK event_mask); -extern void btsnd_hcic_ble_read_buffer_size (void); +extern void btsnd_hcic_ble_read_buffer_size(void); -extern void btsnd_hcic_ble_read_local_spt_feat (void); +extern void btsnd_hcic_ble_read_local_spt_feat(void); -extern void btsnd_hcic_ble_set_local_used_feat (uint8_t feat_set[8]); +extern void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]); -extern void btsnd_hcic_ble_set_random_addr (BD_ADDR random_addr); +extern void btsnd_hcic_ble_set_random_addr(BD_ADDR random_addr); -extern void btsnd_hcic_ble_write_adv_params (uint16_t adv_int_min, uint16_t adv_int_max, - uint8_t adv_type, uint8_t addr_type_own, - uint8_t addr_type_dir, BD_ADDR direct_bda, - uint8_t channel_map, uint8_t adv_filter_policy); +extern void btsnd_hcic_ble_write_adv_params( + uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type, + uint8_t addr_type_own, uint8_t addr_type_dir, BD_ADDR direct_bda, + uint8_t channel_map, uint8_t adv_filter_policy); -extern void btsnd_hcic_ble_read_adv_chnl_tx_power (void); +extern void btsnd_hcic_ble_read_adv_chnl_tx_power(void); -extern void btsnd_hcic_ble_set_adv_data (uint8_t data_len, uint8_t *p_data); +extern void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data); -extern void btsnd_hcic_ble_set_scan_rsp_data (uint8_t data_len, uint8_t *p_scan_rsp); +extern void btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len, + uint8_t* p_scan_rsp); -extern void btsnd_hcic_ble_set_adv_enable (uint8_t adv_enable); +extern void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable); -extern void btsnd_hcic_ble_set_scan_params (uint8_t scan_type, - uint16_t scan_int, uint16_t scan_win, - uint8_t addr_type, uint8_t scan_filter_policy); +extern void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int, + uint16_t scan_win, uint8_t addr_type, + uint8_t scan_filter_policy); -extern void btsnd_hcic_ble_set_scan_enable (uint8_t scan_enable, uint8_t duplicate); +extern void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, + uint8_t duplicate); -extern void btsnd_hcic_ble_create_ll_conn (uint16_t scan_int, uint16_t scan_win, - uint8_t init_filter_policy, uint8_t addr_type_peer, BD_ADDR bda_peer, uint8_t addr_type_own, - uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency, uint16_t conn_timeout, - uint16_t min_ce_len, uint16_t max_ce_len); +extern void btsnd_hcic_ble_create_ll_conn( + uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy, + uint8_t addr_type_peer, BD_ADDR bda_peer, uint8_t addr_type_own, + uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency, + uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len); -extern void btsnd_hcic_ble_create_conn_cancel (void); +extern void btsnd_hcic_ble_create_conn_cancel(void); -extern void btsnd_hcic_ble_read_white_list_size (void); +extern void btsnd_hcic_ble_read_white_list_size(void); -extern void btsnd_hcic_ble_clear_white_list (void); +extern void btsnd_hcic_ble_clear_white_list(void); -extern void btsnd_hcic_ble_add_white_list (uint8_t addr_type, BD_ADDR bda); +extern void btsnd_hcic_ble_add_white_list(uint8_t addr_type, BD_ADDR bda); -extern void btsnd_hcic_ble_remove_from_white_list (uint8_t addr_type, BD_ADDR bda); +extern void btsnd_hcic_ble_remove_from_white_list(uint8_t addr_type, + BD_ADDR bda); -extern void btsnd_hcic_ble_upd_ll_conn_params (uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max, - uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_len, uint16_t max_len); +extern void btsnd_hcic_ble_upd_ll_conn_params( + uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max, + uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_len, + uint16_t max_len); -extern void btsnd_hcic_ble_set_host_chnl_class (uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]); +extern void btsnd_hcic_ble_set_host_chnl_class( + uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]); -extern void btsnd_hcic_ble_read_chnl_map (uint16_t handle); +extern void btsnd_hcic_ble_read_chnl_map(uint16_t handle); -extern void btsnd_hcic_ble_read_remote_feat ( uint16_t handle); +extern void btsnd_hcic_ble_read_remote_feat(uint16_t handle); -extern void btsnd_hcic_ble_encrypt (uint8_t* key, uint8_t key_len, uint8_t* plain_text, uint8_t pt_len, void *p_cmd_cplt_cback); +extern void btsnd_hcic_ble_encrypt(uint8_t* key, uint8_t key_len, + uint8_t* plain_text, uint8_t pt_len, + void* p_cmd_cplt_cback); -extern void btsnd_hcic_ble_rand (void *p_cmd_cplt_cback); +extern void btsnd_hcic_ble_rand(void* p_cmd_cplt_cback); -extern void btsnd_hcic_ble_start_enc ( uint16_t handle, - uint8_t rand[HCIC_BLE_RAND_DI_SIZE], - uint16_t ediv, uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); +extern void btsnd_hcic_ble_start_enc(uint16_t handle, + uint8_t rand[HCIC_BLE_RAND_DI_SIZE], + uint16_t ediv, + uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); -extern void btsnd_hcic_ble_ltk_req_reply (uint16_t handle, uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); +extern void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, + uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]); -extern void btsnd_hcic_ble_ltk_req_neg_reply (uint16_t handle); +extern void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle); -extern void btsnd_hcic_ble_read_supported_states (void); +extern void btsnd_hcic_ble_read_supported_states(void); -extern void btsnd_hcic_ble_write_host_supported (uint8_t le_host_spt, uint8_t simul_le_host_spt); +extern void btsnd_hcic_ble_write_host_supported(uint8_t le_host_spt, + uint8_t simul_le_host_spt); -extern void btsnd_hcic_ble_read_host_supported (void); +extern void btsnd_hcic_ble_read_host_supported(void); extern void btsnd_hcic_ble_receiver_test(uint8_t rx_freq); -extern void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, - uint8_t payload); +extern void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, + uint8_t test_data_len, + uint8_t payload); extern void btsnd_hcic_ble_test_end(void); #if (BLE_LLT_INCLUDED == TRUE) -#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14 -extern void btsnd_hcic_ble_rc_param_req_reply(uint16_t handle, - uint16_t conn_int_min, uint16_t conn_int_max, - uint16_t conn_latency, uint16_t conn_timeout, - uint16_t min_ce_len, uint16_t max_ce_len); +#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14 +extern void btsnd_hcic_ble_rc_param_req_reply( + uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max, + uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_ce_len, + uint16_t max_ce_len); -#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3 -extern void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason); +#define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3 +extern void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, + uint8_t reason); #endif /* BLE_LLT_INCLUDED */ -extern void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, - uint16_t tx_time); +extern void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, + uint16_t tx_octets, + uint16_t tx_time); -extern void btsnd_hcic_ble_add_device_resolving_list (uint8_t addr_type_peer, - BD_ADDR bda_peer, - uint8_t irk_peer[HCIC_BLE_IRK_SIZE], - uint8_t irk_local[HCIC_BLE_IRK_SIZE]); +extern void btsnd_hcic_ble_add_device_resolving_list( + uint8_t addr_type_peer, BD_ADDR bda_peer, + uint8_t irk_peer[HCIC_BLE_IRK_SIZE], uint8_t irk_local[HCIC_BLE_IRK_SIZE]); -extern void btsnd_hcic_ble_rm_device_resolving_list (uint8_t addr_type_peer, - BD_ADDR bda_peer); +extern void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer, + BD_ADDR bda_peer); -extern void btsnd_hcic_ble_clear_resolving_list (void); +extern void btsnd_hcic_ble_clear_resolving_list(void); -extern void btsnd_hcic_ble_read_resolvable_addr_peer (uint8_t addr_type_peer, - BD_ADDR bda_peer); +extern void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, + BD_ADDR bda_peer); -extern void btsnd_hcic_ble_read_resolvable_addr_local (uint8_t addr_type_peer, - BD_ADDR bda_peer); +extern void btsnd_hcic_ble_read_resolvable_addr_local(uint8_t addr_type_peer, + BD_ADDR bda_peer); -extern void btsnd_hcic_ble_set_addr_resolution_enable (uint8_t addr_resolution_enable); +extern void btsnd_hcic_ble_set_addr_resolution_enable( + uint8_t addr_resolution_enable); -extern void btsnd_hcic_ble_set_rand_priv_addr_timeout (uint16_t rpa_timout); +extern void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout); extern void btsnd_hcic_read_authenticated_payload_tout(uint16_t handle); extern void btsnd_hcic_write_authenticated_payload_tout(uint16_t handle, - uint16_t timeout); + uint16_t timeout); -#define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4 +#define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4 -#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_HANDLE_OFF 0 -#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_TOUT_OFF 2 +#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_HANDLE_OFF 0 +#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_TOUT_OFF 2 #ifdef __cplusplus } diff --git a/stack/include/hiddefs.h b/stack/include/hiddefs.h index a05019573..55f7e55b0 100644 --- a/stack/include/hiddefs.h +++ b/stack/include/hiddefs.h @@ -29,131 +29,128 @@ /* * tHID_STATUS: HID result codes, returned by HID and device and host functions. */ -enum -{ - HID_SUCCESS, - HID_ERR_NOT_REGISTERED, - HID_ERR_ALREADY_REGISTERED, - HID_ERR_NO_RESOURCES, - HID_ERR_NO_CONNECTION, - HID_ERR_INVALID_PARAM, - HID_ERR_UNSUPPORTED, - HID_ERR_UNKNOWN_COMMAND, - HID_ERR_CONGESTED, - HID_ERR_CONN_IN_PROCESS, - HID_ERR_ALREADY_CONN, - HID_ERR_DISCONNECTING, - HID_ERR_SET_CONNABLE_FAIL, - /* Device specific error codes */ - HID_ERR_HOST_UNKNOWN, - HID_ERR_L2CAP_FAILED, - HID_ERR_AUTH_FAILED, - HID_ERR_SDP_BUSY, - HID_ERR_GATT, - - HID_ERR_INVALID = 0xFF +enum { + HID_SUCCESS, + HID_ERR_NOT_REGISTERED, + HID_ERR_ALREADY_REGISTERED, + HID_ERR_NO_RESOURCES, + HID_ERR_NO_CONNECTION, + HID_ERR_INVALID_PARAM, + HID_ERR_UNSUPPORTED, + HID_ERR_UNKNOWN_COMMAND, + HID_ERR_CONGESTED, + HID_ERR_CONN_IN_PROCESS, + HID_ERR_ALREADY_CONN, + HID_ERR_DISCONNECTING, + HID_ERR_SET_CONNABLE_FAIL, + /* Device specific error codes */ + HID_ERR_HOST_UNKNOWN, + HID_ERR_L2CAP_FAILED, + HID_ERR_AUTH_FAILED, + HID_ERR_SDP_BUSY, + HID_ERR_GATT, + + HID_ERR_INVALID = 0xFF }; typedef uint8_t tHID_STATUS; -#define HID_L2CAP_CONN_FAIL (0x0100) /* Connection Attempt was made but failed */ -#define HID_L2CAP_REQ_FAIL (0x0200) /* L2CAP_ConnectReq API failed */ -#define HID_L2CAP_CFG_FAIL (0x0400) /* L2CAP Configuration was rejected by peer */ - - +#define HID_L2CAP_CONN_FAIL \ + (0x0100) /* Connection Attempt was made but failed */ +#define HID_L2CAP_REQ_FAIL (0x0200) /* L2CAP_ConnectReq API failed */ +#define HID_L2CAP_CFG_FAIL \ + (0x0400) /* L2CAP Configuration was rejected by peer */ /* Define the HID transaction types */ -#define HID_TRANS_HANDSHAKE (0) -#define HID_TRANS_CONTROL (1) -#define HID_TRANS_GET_REPORT (4) -#define HID_TRANS_SET_REPORT (5) -#define HID_TRANS_GET_PROTOCOL (6) -#define HID_TRANS_SET_PROTOCOL (7) -#define HID_TRANS_GET_IDLE (8) -#define HID_TRANS_SET_IDLE (9) -#define HID_TRANS_DATA (10) -#define HID_TRANS_DATAC (11) +#define HID_TRANS_HANDSHAKE (0) +#define HID_TRANS_CONTROL (1) +#define HID_TRANS_GET_REPORT (4) +#define HID_TRANS_SET_REPORT (5) +#define HID_TRANS_GET_PROTOCOL (6) +#define HID_TRANS_SET_PROTOCOL (7) +#define HID_TRANS_GET_IDLE (8) +#define HID_TRANS_SET_IDLE (9) +#define HID_TRANS_DATA (10) +#define HID_TRANS_DATAC (11) #define HID_GET_TRANS_FROM_HDR(x) (((x) >> 4) & 0x0f) -#define HID_GET_PARAM_FROM_HDR(x) ((x) & 0x0f) -#define HID_BUILD_HDR(t,p) (uint8_t)(((t) << 4) | ((p) & 0x0f)) - +#define HID_GET_PARAM_FROM_HDR(x) ((x)&0x0f) +#define HID_BUILD_HDR(t, p) (uint8_t)(((t) << 4) | ((p)&0x0f)) /* Parameters for Handshake */ -#define HID_PAR_HANDSHAKE_RSP_SUCCESS (0) -#define HID_PAR_HANDSHAKE_RSP_NOT_READY (1) -#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID (2) -#define HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ (3) -#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM (4) -#define HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN (14) -#define HID_PAR_HANDSHAKE_RSP_ERR_FATAL (15) - +#define HID_PAR_HANDSHAKE_RSP_SUCCESS (0) +#define HID_PAR_HANDSHAKE_RSP_NOT_READY (1) +#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID (2) +#define HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ (3) +#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM (4) +#define HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN (14) +#define HID_PAR_HANDSHAKE_RSP_ERR_FATAL (15) /* Parameters for Control */ -#define HID_PAR_CONTROL_NOP (0) -#define HID_PAR_CONTROL_HARD_RESET (1) -#define HID_PAR_CONTROL_SOFT_RESET (2) -#define HID_PAR_CONTROL_SUSPEND (3) -#define HID_PAR_CONTROL_EXIT_SUSPEND (4) -#define HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG (5) - +#define HID_PAR_CONTROL_NOP (0) +#define HID_PAR_CONTROL_HARD_RESET (1) +#define HID_PAR_CONTROL_SOFT_RESET (2) +#define HID_PAR_CONTROL_SUSPEND (3) +#define HID_PAR_CONTROL_EXIT_SUSPEND (4) +#define HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG (5) /* Different report types in get, set, data */ -#define HID_PAR_REP_TYPE_MASK (0x03) -#define HID_PAR_REP_TYPE_OTHER (0x00) -#define HID_PAR_REP_TYPE_INPUT (0x01) -#define HID_PAR_REP_TYPE_OUTPUT (0x02) -#define HID_PAR_REP_TYPE_FEATURE (0x03) +#define HID_PAR_REP_TYPE_MASK (0x03) +#define HID_PAR_REP_TYPE_OTHER (0x00) +#define HID_PAR_REP_TYPE_INPUT (0x01) +#define HID_PAR_REP_TYPE_OUTPUT (0x02) +#define HID_PAR_REP_TYPE_FEATURE (0x03) /* Parameters for Get Report */ /* Buffer size in two bytes after Report ID */ -#define HID_PAR_GET_REP_BUFSIZE_FOLLOWS (0x08) - +#define HID_PAR_GET_REP_BUFSIZE_FOLLOWS (0x08) /* Parameters for Protocol Type */ -#define HID_PAR_PROTOCOL_MASK (0x01) -#define HID_PAR_PROTOCOL_REPORT (0x01) -#define HID_PAR_PROTOCOL_BOOT_MODE (0x00) +#define HID_PAR_PROTOCOL_MASK (0x01) +#define HID_PAR_PROTOCOL_REPORT (0x01) +#define HID_PAR_PROTOCOL_BOOT_MODE (0x00) -#define HID_PAR_REP_TYPE_MASK (0x03) +#define HID_PAR_REP_TYPE_MASK (0x03) /* Descriptor types in the SDP record */ -#define HID_SDP_DESCRIPTOR_REPORT (0x22) -#define HID_SDP_DESCRIPTOR_PHYSICAL (0x23) +#define HID_SDP_DESCRIPTOR_REPORT (0x22) +#define HID_SDP_DESCRIPTOR_PHYSICAL (0x23) -typedef struct desc_info -{ - uint16_t dl_len; - uint8_t *dsc_list; +typedef struct desc_info { + uint16_t dl_len; + uint8_t* dsc_list; } tHID_DEV_DSCP_INFO; -#define HID_SSR_PARAM_INVALID 0xffff - -typedef struct sdp_info -{ - char svc_name[HID_MAX_SVC_NAME_LEN]; /*Service Name */ - char svc_descr[HID_MAX_SVC_DESCR_LEN]; /*Service Description*/ - char prov_name[HID_MAX_PROV_NAME_LEN]; /*Provider Name.*/ - uint16_t rel_num; /*Release Number */ - uint16_t hpars_ver; /*HID Parser Version.*/ - uint16_t ssr_max_latency; /* HIDSSRHostMaxLatency value, if HID_SSR_PARAM_INVALID not used*/ - uint16_t ssr_min_tout; /* HIDSSRHostMinTimeout value, if HID_SSR_PARAM_INVALID not used* */ - uint8_t sub_class; /*Device Subclass.*/ - uint8_t ctry_code; /*Country Code.*/ - uint16_t sup_timeout;/* Supervisory Timeout */ - - tHID_DEV_DSCP_INFO dscp_info; /* Descriptor list and Report list to be set in the SDP record. - This parameter is used if HID_DEV_USE_GLB_SDP_REC is set to false.*/ - tSDP_DISC_REC *p_sdp_layer_rec; +#define HID_SSR_PARAM_INVALID 0xffff + +typedef struct sdp_info { + char svc_name[HID_MAX_SVC_NAME_LEN]; /*Service Name */ + char svc_descr[HID_MAX_SVC_DESCR_LEN]; /*Service Description*/ + char prov_name[HID_MAX_PROV_NAME_LEN]; /*Provider Name.*/ + uint16_t rel_num; /*Release Number */ + uint16_t hpars_ver; /*HID Parser Version.*/ + uint16_t ssr_max_latency; /* HIDSSRHostMaxLatency value, if + HID_SSR_PARAM_INVALID not used*/ + uint16_t + ssr_min_tout; /* HIDSSRHostMinTimeout value, if HID_SSR_PARAM_INVALID not + used* */ + uint8_t sub_class; /*Device Subclass.*/ + uint8_t ctry_code; /*Country Code.*/ + uint16_t sup_timeout; /* Supervisory Timeout */ + + tHID_DEV_DSCP_INFO dscp_info; /* Descriptor list and Report list to be set in + the SDP record. + This parameter is used if + HID_DEV_USE_GLB_SDP_REC is set to false.*/ + tSDP_DISC_REC* p_sdp_layer_rec; } tHID_DEV_SDP_INFO; #endif - diff --git a/stack/include/hidh_api.h b/stack/include/hidh_api.h index 83bee774a..3529e4fce 100644 --- a/stack/include/hidh_api.h +++ b/stack/include/hidh_api.h @@ -30,31 +30,30 @@ extern "C" { ****************************************************************************/ enum { - HID_SDP_NO_SERV_UUID = (SDP_ILLEGAL_PARAMETER+1), - HID_SDP_MANDATORY_MISSING + HID_SDP_NO_SERV_UUID = (SDP_ILLEGAL_PARAMETER + 1), + HID_SDP_MANDATORY_MISSING }; /* Attributes mask values to be used in HID_HostAddDev API */ -#define HID_VIRTUAL_CABLE 0x0001 +#define HID_VIRTUAL_CABLE 0x0001 #define HID_NORMALLY_CONNECTABLE 0x0002 -#define HID_RECONN_INIT 0x0004 -#define HID_SDP_DISABLE 0x0008 -#define HID_BATTERY_POWER 0x0010 -#define HID_REMOTE_WAKE 0x0020 -#define HID_SUP_TOUT_AVLBL 0x0040 -#define HID_SSR_MAX_LATENCY 0x0080 -#define HID_SSR_MIN_TOUT 0x0100 - -#define HID_SEC_REQUIRED 0x8000 -#define HID_ATTR_MASK_IGNORE 0 +#define HID_RECONN_INIT 0x0004 +#define HID_SDP_DISABLE 0x0008 +#define HID_BATTERY_POWER 0x0010 +#define HID_REMOTE_WAKE 0x0020 +#define HID_SUP_TOUT_AVLBL 0x0040 +#define HID_SSR_MAX_LATENCY 0x0080 +#define HID_SSR_MIN_TOUT 0x0100 +#define HID_SEC_REQUIRED 0x8000 +#define HID_ATTR_MASK_IGNORE 0 /***************************************************************************** * Type Definitions ****************************************************************************/ -typedef void (tHID_HOST_SDP_CALLBACK) (uint16_t result, uint16_t attr_mask, - tHID_DEV_SDP_INFO *sdp_rec ); +typedef void(tHID_HOST_SDP_CALLBACK)(uint16_t result, uint16_t attr_mask, + tHID_DEV_SDP_INFO* sdp_rec); /* HID-HOST returns the events in the following table to the application via * tHID_HOST_DEV_CALLBACK @@ -74,24 +73,22 @@ typedef void (tHID_HOST_SDP_CALLBACK) (uint16_t result, uint16_t attr_mask, * HID_HDEV_EVT_VC_UNPLUG Device sent Virtual Unplug Data = NA. pdata = NA. */ -enum -{ - HID_HDEV_EVT_OPEN, - HID_HDEV_EVT_CLOSE, - HID_HDEV_EVT_RETRYING, - HID_HDEV_EVT_INTR_DATA, - HID_HDEV_EVT_INTR_DATC, - HID_HDEV_EVT_CTRL_DATA, - HID_HDEV_EVT_CTRL_DATC, - HID_HDEV_EVT_HANDSHAKE, - HID_HDEV_EVT_VC_UNPLUG +enum { + HID_HDEV_EVT_OPEN, + HID_HDEV_EVT_CLOSE, + HID_HDEV_EVT_RETRYING, + HID_HDEV_EVT_INTR_DATA, + HID_HDEV_EVT_INTR_DATC, + HID_HDEV_EVT_CTRL_DATA, + HID_HDEV_EVT_CTRL_DATC, + HID_HDEV_EVT_HANDSHAKE, + HID_HDEV_EVT_VC_UNPLUG }; -typedef void (tHID_HOST_DEV_CALLBACK) (uint8_t dev_handle, - BD_ADDR addr, - uint8_t event, /* Event from HID-DEVICE. */ - uint32_t data, /* Integer data corresponding to the event.*/ - BT_HDR *p_buf ); /* Pointer data corresponding to the event. */ - +typedef void(tHID_HOST_DEV_CALLBACK)( + uint8_t dev_handle, BD_ADDR addr, + uint8_t event, /* Event from HID-DEVICE. */ + uint32_t data, /* Integer data corresponding to the event.*/ + BT_HDR* p_buf); /* Pointer data corresponding to the event. */ /***************************************************************************** * External Function Declarations @@ -106,10 +103,9 @@ typedef void (tHID_HOST_DEV_CALLBACK) (uint8_t dev_handle, * Returns tHID_STATUS * ******************************************************************************/ -extern tHID_STATUS HID_HostGetSDPRecord (BD_ADDR addr, - tSDP_DISCOVERY_DB *p_db, - uint32_t db_len, - tHID_HOST_SDP_CALLBACK *sdp_cback ); +extern tHID_STATUS HID_HostGetSDPRecord(BD_ADDR addr, tSDP_DISCOVERY_DB* p_db, + uint32_t db_len, + tHID_HOST_SDP_CALLBACK* sdp_cback); /******************************************************************************* * @@ -120,7 +116,7 @@ extern tHID_STATUS HID_HostGetSDPRecord (BD_ADDR addr, * Returns tHID_STATUS * ******************************************************************************/ -extern tHID_STATUS HID_HostRegister (tHID_HOST_DEV_CALLBACK *dev_cback); +extern tHID_STATUS HID_HostRegister(tHID_HOST_DEV_CALLBACK* dev_cback); /******************************************************************************* * @@ -142,8 +138,8 @@ extern tHID_STATUS HID_HostDeregister(void); * Returns tHID_STATUS * ******************************************************************************/ -extern tHID_STATUS HID_HostAddDev (BD_ADDR addr, uint16_t attr_mask, - uint8_t *handle ); +extern tHID_STATUS HID_HostAddDev(BD_ADDR addr, uint16_t attr_mask, + uint8_t* handle); /******************************************************************************* * @@ -155,7 +151,7 @@ extern tHID_STATUS HID_HostAddDev (BD_ADDR addr, uint16_t attr_mask, * Returns tHID_STATUS * ******************************************************************************/ -extern tHID_STATUS HID_HostRemoveDev (uint8_t dev_handle ); +extern tHID_STATUS HID_HostRemoveDev(uint8_t dev_handle); /******************************************************************************* * @@ -167,7 +163,7 @@ extern tHID_STATUS HID_HostRemoveDev (uint8_t dev_handle ); * Returns void * ******************************************************************************/ -extern tHID_STATUS HID_HostOpenDev (uint8_t dev_handle ); +extern tHID_STATUS HID_HostOpenDev(uint8_t dev_handle); /******************************************************************************* * @@ -180,7 +176,7 @@ extern tHID_STATUS HID_HostOpenDev (uint8_t dev_handle ); ******************************************************************************/ extern tHID_STATUS HID_HostWriteDev(uint8_t dev_handle, uint8_t t_type, uint8_t param, uint16_t data, - uint8_t report_id, BT_HDR *pbuf); + uint8_t report_id, BT_HDR* pbuf); /******************************************************************************* * @@ -191,7 +187,7 @@ extern tHID_STATUS HID_HostWriteDev(uint8_t dev_handle, uint8_t t_type, * Returns void * ******************************************************************************/ -extern tHID_STATUS HID_HostCloseDev(uint8_t dev_handle ); +extern tHID_STATUS HID_HostCloseDev(uint8_t dev_handle); /******************************************************************************* * Function HID_HostInit @@ -210,7 +206,8 @@ extern void HID_HostInit(void); * * Returns tHID_STATUS ******************************************************************************/ -extern tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_lvl ); +extern tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], + uint8_t sec_lvl); /******************************************************************************* * @@ -221,8 +218,7 @@ extern tHID_STATUS HID_HostSetSecurityLevel(const char serv_name[], uint8_t sec_ * Returns true if device exists else false * ******************************************************************************/ -bool hid_known_hid_device (BD_ADDR bd_addr); - +bool hid_known_hid_device(BD_ADDR bd_addr); /******************************************************************************* * @@ -234,10 +230,10 @@ bool hid_known_hid_device (BD_ADDR bd_addr); * Returns the new (current) trace level * ******************************************************************************/ -extern uint8_t HID_HostSetTraceLevel (uint8_t new_level); +extern uint8_t HID_HostSetTraceLevel(uint8_t new_level); #ifdef __cplusplus } #endif -#endif /* HIDH_API_H */ +#endif /* HIDH_API_H */ diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index a2ba8aa1b..ac5f1333b 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -27,8 +27,8 @@ #include #include "bt_target.h" -#include "l2cdefs.h" #include "hcidefs.h" +#include "l2cdefs.h" #ifdef __cplusplus extern "C" { @@ -41,156 +41,153 @@ extern "C" { /* Define the minimum offset that L2CAP needs in a buffer. This is made up of * HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9 */ -#define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */ +#define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */ -#define L2CAP_LCC_SDU_LENGTH 2 -#define L2CAP_LCC_OFFSET (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */ +#define L2CAP_LCC_SDU_LENGTH 2 +#define L2CAP_LCC_OFFSET \ + (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */ /* ping result codes */ -#define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */ -#define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */ -#define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */ +#define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */ +#define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */ +#define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */ /* result code for L2CA_DataWrite() */ -#define L2CAP_DW_FAILED false -#define L2CAP_DW_SUCCESS true -#define L2CAP_DW_CONGESTED 2 +#define L2CAP_DW_FAILED false +#define L2CAP_DW_SUCCESS true +#define L2CAP_DW_CONGESTED 2 /* Values for priority parameter to L2CA_SetAclPriority */ -#define L2CAP_PRIORITY_NORMAL 0 -#define L2CAP_PRIORITY_HIGH 1 +#define L2CAP_PRIORITY_NORMAL 0 +#define L2CAP_PRIORITY_HIGH 1 /* Values for priority parameter to L2CA_SetTxPriority */ -#define L2CAP_CHNL_PRIORITY_HIGH 0 -#define L2CAP_CHNL_PRIORITY_MEDIUM 1 -#define L2CAP_CHNL_PRIORITY_LOW 2 +#define L2CAP_CHNL_PRIORITY_HIGH 0 +#define L2CAP_CHNL_PRIORITY_MEDIUM 1 +#define L2CAP_CHNL_PRIORITY_LOW 2 typedef uint8_t tL2CAP_CHNL_PRIORITY; /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */ -#define L2CAP_CHNL_DATA_RATE_HIGH 3 -#define L2CAP_CHNL_DATA_RATE_MEDIUM 2 -#define L2CAP_CHNL_DATA_RATE_LOW 1 +#define L2CAP_CHNL_DATA_RATE_HIGH 3 +#define L2CAP_CHNL_DATA_RATE_MEDIUM 2 +#define L2CAP_CHNL_DATA_RATE_LOW 1 #define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0 typedef uint8_t tL2CAP_CHNL_DATA_RATE; /* Data Packet Flags (bits 2-15 are reserved) */ /* layer specific 14-15 bits are used for FCR SAR */ -#define L2CAP_FLUSHABLE_MASK 0x0003 -#define L2CAP_FLUSHABLE_CH_BASED 0x0000 -#define L2CAP_FLUSHABLE_PKT 0x0001 -#define L2CAP_NON_FLUSHABLE_PKT 0x0002 - +#define L2CAP_FLUSHABLE_MASK 0x0003 +#define L2CAP_FLUSHABLE_CH_BASED 0x0000 +#define L2CAP_FLUSHABLE_PKT 0x0001 +#define L2CAP_NON_FLUSHABLE_PKT 0x0002 /* L2CA_FlushChannel num_to_flush definitions */ -#define L2CAP_FLUSH_CHANS_ALL 0xffff -#define L2CAP_FLUSH_CHANS_GET 0x0000 - +#define L2CAP_FLUSH_CHANS_ALL 0xffff +#define L2CAP_FLUSH_CHANS_GET 0x0000 /* special CID for Multi-AV for reporting congestion */ -#define L2CAP_MULTI_AV_CID 0 +#define L2CAP_MULTI_AV_CID 0 /* length of the HCI header block */ /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) */ -#define L2CAP_MULTI_AV_HCI_HDR_LEN 8 +#define L2CAP_MULTI_AV_HCI_HDR_LEN 8 /* length of padding for 4 bytes align */ -#define L2CAP_MULTI_AV_PADDING_LEN 2 +#define L2CAP_MULTI_AV_PADDING_LEN 2 /* length of the HCI header block with padding for FCR */ /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) + padding(2) */ -#define L2CAP_MULTI_AV_HCI_HDR_LEN_WITH_PADDING 10 +#define L2CAP_MULTI_AV_HCI_HDR_LEN_WITH_PADDING 10 /* length of the L2CAP header block */ /* HCI header(4) + L2CAP header(4) + padding(4) or control word(2) + FCS(2) */ -#define L2CAP_MULTI_AV_L2C_HDR_LEN 12 +#define L2CAP_MULTI_AV_L2C_HDR_LEN 12 /* definition used for L2CA_SetDesireRole */ -#define L2CAP_ROLE_SLAVE HCI_ROLE_SLAVE -#define L2CAP_ROLE_MASTER HCI_ROLE_MASTER +#define L2CAP_ROLE_SLAVE HCI_ROLE_SLAVE +#define L2CAP_ROLE_MASTER HCI_ROLE_MASTER /* set this bit to allow switch at create conn */ -#define L2CAP_ROLE_ALLOW_SWITCH 0x80 +#define L2CAP_ROLE_ALLOW_SWITCH 0x80 /* set this bit to disallow switch at create conn */ -#define L2CAP_ROLE_DISALLOW_SWITCH 0x40 -#define L2CAP_ROLE_CHECK_SWITCH 0xC0 - +#define L2CAP_ROLE_DISALLOW_SWITCH 0x40 +#define L2CAP_ROLE_CHECK_SWITCH 0xC0 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO */ -#define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE) -#define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE) -#define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE) +#define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE) +#define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE) +#define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE) -#define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM) +#define L2CAP_FCR_CHAN_OPT_ALL_MASK \ + (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | \ + L2CAP_FCR_CHAN_OPT_STREAM) /* Validity check for PSM. PSM values must be odd. Also, all PSM values must * be assigned such that the least significant bit of the most sigificant * octet equals zero. */ -#define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001) -#define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001) -#define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100)) +#define L2C_INVALID_PSM(psm) (((psm)&0x0101) != 0x0001) +#define L2C_IS_VALID_PSM(psm) (((psm)&0x0101) == 0x0001) +#define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100)) /***************************************************************************** * Type Definitions ****************************************************************************/ -typedef struct -{ -#define L2CAP_FCR_BASIC_MODE 0x00 -#define L2CAP_FCR_ERTM_MODE 0x03 -#define L2CAP_FCR_STREAM_MODE 0x04 -#define L2CAP_FCR_LE_COC_MODE 0x05 +typedef struct { +#define L2CAP_FCR_BASIC_MODE 0x00 +#define L2CAP_FCR_ERTM_MODE 0x03 +#define L2CAP_FCR_STREAM_MODE 0x04 +#define L2CAP_FCR_LE_COC_MODE 0x05 - uint8_t mode; + uint8_t mode; - uint8_t tx_win_sz; - uint8_t max_transmit; - uint16_t rtrans_tout; - uint16_t mon_tout; - uint16_t mps; + uint8_t tx_win_sz; + uint8_t max_transmit; + uint16_t rtrans_tout; + uint16_t mon_tout; + uint16_t mps; } tL2CAP_FCR_OPTS; /* Define a structure to hold the configuration parameters. Since the * parameters are optional, for each parameter there is a boolean to * use to signify its presence or absence. */ -typedef struct -{ - uint16_t result; /* Only used in confirm messages */ - bool mtu_present; - uint16_t mtu; - bool qos_present; - FLOW_SPEC qos; - bool flush_to_present; - uint16_t flush_to; - bool fcr_present; - tL2CAP_FCR_OPTS fcr; - bool fcs_present; /* Optionally bypasses FCS checks */ - uint8_t fcs; /* '0' if desire is to bypass FCS, otherwise '1' */ - bool ext_flow_spec_present; - tHCI_EXT_FLOW_SPEC ext_flow_spec; - uint16_t flags; /* bit 0: 0-no continuation, 1-continuation */ +typedef struct { + uint16_t result; /* Only used in confirm messages */ + bool mtu_present; + uint16_t mtu; + bool qos_present; + FLOW_SPEC qos; + bool flush_to_present; + uint16_t flush_to; + bool fcr_present; + tL2CAP_FCR_OPTS fcr; + bool fcs_present; /* Optionally bypasses FCS checks */ + uint8_t fcs; /* '0' if desire is to bypass FCS, otherwise '1' */ + bool ext_flow_spec_present; + tHCI_EXT_FLOW_SPEC ext_flow_spec; + uint16_t flags; /* bit 0: 0-no continuation, 1-continuation */ } tL2CAP_CFG_INFO; /* Define a structure to hold the configuration parameter for LE L2CAP * connection oriented channels. */ -typedef struct -{ - uint16_t mtu; - uint16_t mps; - uint16_t credits; +typedef struct { + uint16_t mtu; + uint16_t mps; + uint16_t credits; } tL2CAP_LE_CFG_INFO; /* L2CAP channel configured field bitmap */ -#define L2CAP_CH_CFG_MASK_MTU 0x0001 -#define L2CAP_CH_CFG_MASK_QOS 0x0002 -#define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004 -#define L2CAP_CH_CFG_MASK_FCR 0x0008 -#define L2CAP_CH_CFG_MASK_FCS 0x0010 +#define L2CAP_CH_CFG_MASK_MTU 0x0001 +#define L2CAP_CH_CFG_MASK_QOS 0x0002 +#define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004 +#define L2CAP_CH_CFG_MASK_FCR 0x0008 +#define L2CAP_CH_CFG_MASK_FCS 0x0010 #define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020 typedef uint16_t tL2CAP_CH_CFG_BITS; @@ -205,75 +202,64 @@ typedef uint16_t tL2CAP_CH_CFG_BITS; * PSM that the remote wants to connect to * Identifier that the remote sent */ -typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, uint16_t, uint16_t, uint8_t); - +typedef void(tL2CA_CONNECT_IND_CB)(BD_ADDR, uint16_t, uint16_t, uint8_t); /* Connection confirmation callback prototype. Parameters are * Local CID * Result - 0 = connected, non-zero means failure reason */ -typedef void (tL2CA_CONNECT_CFM_CB) (uint16_t, uint16_t); - +typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t); /* Connection pending callback prototype. Parameters are * Local CID */ -typedef void (tL2CA_CONNECT_PND_CB) (uint16_t); - +typedef void(tL2CA_CONNECT_PND_CB)(uint16_t); /* Configuration indication callback prototype. Parameters are * Local CID assigned to the connection * Pointer to configuration info */ -typedef void (tL2CA_CONFIG_IND_CB) (uint16_t, tL2CAP_CFG_INFO *); - +typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*); /* Configuration confirm callback prototype. Parameters are * Local CID assigned to the connection * Pointer to configuration info */ -typedef void (tL2CA_CONFIG_CFM_CB) (uint16_t, tL2CAP_CFG_INFO *); - +typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, tL2CAP_CFG_INFO*); /* Disconnect indication callback prototype. Parameters are * Local CID * Boolean whether upper layer should ack this */ -typedef void (tL2CA_DISCONNECT_IND_CB) (uint16_t, bool ); - +typedef void(tL2CA_DISCONNECT_IND_CB)(uint16_t, bool); /* Disconnect confirm callback prototype. Parameters are * Local CID * Result */ -typedef void (tL2CA_DISCONNECT_CFM_CB) (uint16_t, uint16_t); - +typedef void(tL2CA_DISCONNECT_CFM_CB)(uint16_t, uint16_t); /* QOS Violation indication callback prototype. Parameters are * BD Address of violating device */ -typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR); - +typedef void(tL2CA_QOS_VIOLATION_IND_CB)(BD_ADDR); /* Data received indication callback prototype. Parameters are * Local CID * Address of buffer */ -typedef void (tL2CA_DATA_IND_CB) (uint16_t, BT_HDR *); - +typedef void(tL2CA_DATA_IND_CB)(uint16_t, BT_HDR*); /* Echo response callback prototype. Note that this is not included in the * registration information, but is passed to L2CAP as part of the API to * actually send an echo request. Parameters are * Result */ -typedef void (tL2CA_ECHO_RSP_CB) (uint16_t); - +typedef void(tL2CA_ECHO_RSP_CB)(uint16_t); /* Callback function prototype to pass broadcom specific echo response */ /* to the upper layer */ -typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, uint16_t, uint8_t *); - +typedef void(tL2CA_ECHO_DATA_CB)(BD_ADDR, uint16_t, uint8_t*); /* Congestion status callback protype. This callback is optional. If * an application tries to send data when the transmit queue is full, @@ -281,7 +267,7 @@ typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, uint16_t, uint8_t *); * Local CID * true if congested, false if uncongested */ -typedef void (tL2CA_CONGESTION_STATUS_CB) (uint16_t, bool ); +typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool); /* Callback prototype for number of packets completed events. * This callback notifies the application when Number of Completed Packets @@ -290,7 +276,7 @@ typedef void (tL2CA_CONGESTION_STATUS_CB) (uint16_t, bool ); * The parameter is: * peer BD_ADDR */ -typedef void (tL2CA_NOCP_CB) (BD_ADDR); +typedef void(tL2CA_NOCP_CB)(BD_ADDR); /* Transmit complete callback protype. This callback is optional. If * set, L2CAP will call it when packets are sent or flushed. If the @@ -299,57 +285,56 @@ typedef void (tL2CA_NOCP_CB) (BD_ADDR); * Local CID * Number of SDUs sent or dropped */ -typedef void (tL2CA_TX_COMPLETE_CB) (uint16_t, uint16_t); +typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t); /* Define the structure that applications use to register with * L2CAP. This structure includes callback functions. All functions * MUST be provided, with the exception of the "connect pending" * callback and "congestion status" callback. */ -typedef struct -{ - tL2CA_CONNECT_IND_CB *pL2CA_ConnectInd_Cb; - tL2CA_CONNECT_CFM_CB *pL2CA_ConnectCfm_Cb; - tL2CA_CONNECT_PND_CB *pL2CA_ConnectPnd_Cb; - tL2CA_CONFIG_IND_CB *pL2CA_ConfigInd_Cb; - tL2CA_CONFIG_CFM_CB *pL2CA_ConfigCfm_Cb; - tL2CA_DISCONNECT_IND_CB *pL2CA_DisconnectInd_Cb; - tL2CA_DISCONNECT_CFM_CB *pL2CA_DisconnectCfm_Cb; - tL2CA_QOS_VIOLATION_IND_CB *pL2CA_QoSViolationInd_Cb; - tL2CA_DATA_IND_CB *pL2CA_DataInd_Cb; - tL2CA_CONGESTION_STATUS_CB *pL2CA_CongestionStatus_Cb; - tL2CA_TX_COMPLETE_CB *pL2CA_TxComplete_Cb; +typedef struct { + tL2CA_CONNECT_IND_CB* pL2CA_ConnectInd_Cb; + tL2CA_CONNECT_CFM_CB* pL2CA_ConnectCfm_Cb; + tL2CA_CONNECT_PND_CB* pL2CA_ConnectPnd_Cb; + tL2CA_CONFIG_IND_CB* pL2CA_ConfigInd_Cb; + tL2CA_CONFIG_CFM_CB* pL2CA_ConfigCfm_Cb; + tL2CA_DISCONNECT_IND_CB* pL2CA_DisconnectInd_Cb; + tL2CA_DISCONNECT_CFM_CB* pL2CA_DisconnectCfm_Cb; + tL2CA_QOS_VIOLATION_IND_CB* pL2CA_QoSViolationInd_Cb; + tL2CA_DATA_IND_CB* pL2CA_DataInd_Cb; + tL2CA_CONGESTION_STATUS_CB* pL2CA_CongestionStatus_Cb; + tL2CA_TX_COMPLETE_CB* pL2CA_TxComplete_Cb; } tL2CAP_APPL_INFO; /* Define the structure that applications use to create or accept * connections with enhanced retransmission mode. */ -typedef struct -{ - uint8_t preferred_mode; - uint8_t allowed_modes; - uint16_t user_rx_buf_size; - uint16_t user_tx_buf_size; - uint16_t fcr_rx_buf_size; - uint16_t fcr_tx_buf_size; +typedef struct { + uint8_t preferred_mode; + uint8_t allowed_modes; + uint16_t user_rx_buf_size; + uint16_t user_tx_buf_size; + uint16_t fcr_rx_buf_size; + uint16_t fcr_tx_buf_size; } tL2CAP_ERTM_INFO; -#define L2CA_REGISTER(a,b,c) L2CA_Register(a,(tL2CAP_APPL_INFO *)(b)) -#define L2CA_DEREGISTER(a) L2CA_Deregister(a) -#define L2CA_CONNECT_REQ(a,b,c) L2CA_ErtmConnectReq(a,b,c) -#define L2CA_CONNECT_RSP(a,b,c,d,e,f) L2CA_ErtmConnectRsp(a,b,c,d,e,f) -#define L2CA_CONFIG_REQ(a,b) L2CA_ConfigReq(a,b) -#define L2CA_CONFIG_RSP(a,b) L2CA_ConfigRsp(a,b) -#define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a) -#define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a) -#define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b) -#define L2CA_REGISTER_COC(a,b,c) L2CA_RegisterLECoc(a,(tL2CAP_APPL_INFO *)(b)) -#define L2CA_DEREGISTER_COC(a) L2CA_DeregisterLECoc(a) -#define L2CA_CONNECT_COC_REQ(a,b,c) L2CA_ConnectLECocReq(a,b,c) -#define L2CA_CONNECT_COC_RSP(a,b,c,d,e,f) L2CA_ConnectLECocRsp(a,b,c,d,e,f) -#define L2CA_GET_PEER_COC_CONFIG(a, b) L2CA_GetPeerLECocConfig(a, b) +#define L2CA_REGISTER(a, b, c) L2CA_Register(a, (tL2CAP_APPL_INFO*)(b)) +#define L2CA_DEREGISTER(a) L2CA_Deregister(a) +#define L2CA_CONNECT_REQ(a, b, c) L2CA_ErtmConnectReq(a, b, c) +#define L2CA_CONNECT_RSP(a, b, c, d, e, f) L2CA_ErtmConnectRsp(a, b, c, d, e, f) +#define L2CA_CONFIG_REQ(a, b) L2CA_ConfigReq(a, b) +#define L2CA_CONFIG_RSP(a, b) L2CA_ConfigRsp(a, b) +#define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a) +#define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a) +#define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b) +#define L2CA_REGISTER_COC(a, b, c) L2CA_RegisterLECoc(a, (tL2CAP_APPL_INFO*)(b)) +#define L2CA_DEREGISTER_COC(a) L2CA_DeregisterLECoc(a) +#define L2CA_CONNECT_COC_REQ(a, b, c) L2CA_ConnectLECocReq(a, b, c) +#define L2CA_CONNECT_COC_RSP(a, b, c, d, e, f) \ + L2CA_ConnectLECocRsp(a, b, c, d, e, f) +#define L2CA_GET_PEER_COC_CONFIG(a, b) L2CA_GetPeerLECocConfig(a, b) /***************************************************************************** * External Function Declarations @@ -369,7 +354,7 @@ typedef struct * BTM_SetSecurityLevel(). * ******************************************************************************/ -extern uint16_t L2CA_Register (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info); +extern uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info); /******************************************************************************* * @@ -381,7 +366,7 @@ extern uint16_t L2CA_Register (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info); * Returns void * ******************************************************************************/ -extern void L2CA_Deregister (uint16_t psm); +extern void L2CA_Deregister(uint16_t psm); /******************************************************************************* * @@ -408,7 +393,7 @@ extern uint16_t L2CA_AllocatePSM(void); * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -extern uint16_t L2CA_ConnectReq (uint16_t psm, BD_ADDR p_bd_addr); +extern uint16_t L2CA_ConnectReq(uint16_t psm, BD_ADDR p_bd_addr); /******************************************************************************* * @@ -421,8 +406,8 @@ extern uint16_t L2CA_ConnectReq (uint16_t psm, BD_ADDR p_bd_addr); * Returns true for success, false for failure * ******************************************************************************/ -extern bool L2CA_ConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, - uint16_t result, uint16_t status); +extern bool L2CA_ConnectRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status); /******************************************************************************* * @@ -437,8 +422,8 @@ extern bool L2CA_ConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -extern uint16_t L2CA_ErtmConnectReq (uint16_t psm, BD_ADDR p_bd_addr, - tL2CAP_ERTM_INFO *p_ertm_info); +extern uint16_t L2CA_ErtmConnectReq(uint16_t psm, BD_ADDR p_bd_addr, + tL2CAP_ERTM_INFO* p_ertm_info); /******************************************************************************* * @@ -454,7 +439,7 @@ extern uint16_t L2CA_ErtmConnectReq (uint16_t psm, BD_ADDR p_bd_addr, * and BTM_SetSecurityLevel(). * ******************************************************************************/ -extern uint16_t L2CA_RegisterLECoc (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info); +extern uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info); /******************************************************************************* * @@ -466,7 +451,7 @@ extern uint16_t L2CA_RegisterLECoc (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info); * Returns void * ******************************************************************************/ -extern void L2CA_DeregisterLECoc (uint16_t psm); +extern void L2CA_DeregisterLECoc(uint16_t psm); /******************************************************************************* * @@ -480,7 +465,8 @@ extern void L2CA_DeregisterLECoc (uint16_t psm); * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -extern uint16_t L2CA_ConnectLECocReq (uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_LE_CFG_INFO *p_cfg); +extern uint16_t L2CA_ConnectLECocReq(uint16_t psm, BD_ADDR p_bd_addr, + tL2CAP_LE_CFG_INFO* p_cfg); /******************************************************************************* * @@ -493,8 +479,9 @@ extern uint16_t L2CA_ConnectLECocReq (uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_LE * Returns true for success, false for failure * ******************************************************************************/ -extern bool L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, uint16_t result, - uint16_t status, tL2CAP_LE_CFG_INFO *p_cfg); +extern bool L2CA_ConnectLECocRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status, + tL2CAP_LE_CFG_INFO* p_cfg); /******************************************************************************* * @@ -505,14 +492,16 @@ extern bool L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lci * Return value: true if peer is connected * ******************************************************************************/ -extern bool L2CA_GetPeerLECocConfig (uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg); +extern bool L2CA_GetPeerLECocConfig(uint16_t lcid, + tL2CAP_LE_CFG_INFO* peer_cfg); // This function sets the callback routines for the L2CAP connection referred to // by |local_cid|. The callback routines can only be modified for outgoing // connections established by |L2CA_ConnectReq| or accepted incoming // connections. |callbacks| must not be NULL. This function returns true if the // callbacks could be updated, false if not (e.g. |local_cid| was not found). -bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks); +bool L2CA_SetConnectionCallbacks(uint16_t local_cid, + const tL2CAP_APPL_INFO* callbacks); /******************************************************************************* * @@ -526,9 +515,9 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal * Returns true for success, false for failure * ******************************************************************************/ -extern bool L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, - uint16_t result, uint16_t status, - tL2CAP_ERTM_INFO *p_ertm_info); +extern bool L2CA_ErtmConnectRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status, + tL2CAP_ERTM_INFO* p_ertm_info); /******************************************************************************* * @@ -539,7 +528,7 @@ extern bool L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lci * Returns true if configuration sent, else false * ******************************************************************************/ -extern bool L2CA_ConfigReq (uint16_t cid, tL2CAP_CFG_INFO *p_cfg); +extern bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); /******************************************************************************* * @@ -551,7 +540,7 @@ extern bool L2CA_ConfigReq (uint16_t cid, tL2CAP_CFG_INFO *p_cfg); * Returns true if configuration response sent, else false * ******************************************************************************/ -extern bool L2CA_ConfigRsp (uint16_t cid, tL2CAP_CFG_INFO *p_cfg); +extern bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); /******************************************************************************* * @@ -562,7 +551,7 @@ extern bool L2CA_ConfigRsp (uint16_t cid, tL2CAP_CFG_INFO *p_cfg); * Returns true if disconnect sent, else false * ******************************************************************************/ -extern bool L2CA_DisconnectReq (uint16_t cid); +extern bool L2CA_DisconnectReq(uint16_t cid); /******************************************************************************* * @@ -574,7 +563,7 @@ extern bool L2CA_DisconnectReq (uint16_t cid); * Returns void * ******************************************************************************/ -extern bool L2CA_DisconnectRsp (uint16_t cid); +extern bool L2CA_DisconnectRsp(uint16_t cid); /******************************************************************************* * @@ -588,7 +577,7 @@ extern bool L2CA_DisconnectRsp (uint16_t cid); * L2CAP_DW_FAILED, if error * ******************************************************************************/ -extern uint8_t L2CA_DataWrite (uint16_t cid, BT_HDR *p_data); +extern uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data); /******************************************************************************* * @@ -599,7 +588,7 @@ extern uint8_t L2CA_DataWrite (uint16_t cid, BT_HDR *p_data); * Returns true if echo request sent, else false. * ******************************************************************************/ -extern bool L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb); +extern bool L2CA_Ping(BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB* p_cb); /******************************************************************************* * @@ -611,14 +600,15 @@ extern bool L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb); * Returns true if echo request sent, else false. * ******************************************************************************/ -extern bool L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback); +extern bool L2CA_Echo(BD_ADDR p_bd_addr, BT_HDR* p_data, + tL2CA_ECHO_DATA_CB* p_callback); // Given a local channel identifier, |lcid|, this function returns the bound // remote channel identifier, |rcid|, and the ACL link handle, |handle|. If // |lcid| is not known or is invalid, this function returns false and does not // modify the values pointed at by |rcid| and |handle|. |rcid| and |handle| may // be NULL. -bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle); +bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t* rcid, uint16_t* handle); /******************************************************************************* * @@ -635,8 +625,7 @@ bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle); * Returns true if command succeeded, false if failed * ******************************************************************************/ -extern bool L2CA_SetIdleTimeout (uint16_t cid, uint16_t timeout, - bool is_global); +extern bool L2CA_SetIdleTimeout(uint16_t cid, uint16_t timeout, bool is_global); /******************************************************************************* * @@ -657,8 +646,8 @@ extern bool L2CA_SetIdleTimeout (uint16_t cid, uint16_t timeout, * NOTE This timeout applies to all logical channels active on the * ACL link. ******************************************************************************/ -extern bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, - tBT_TRANSPORT transport); +extern bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, + tBT_TRANSPORT transport); /******************************************************************************* * @@ -670,7 +659,7 @@ extern bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, * Returns the new (current) trace level * ******************************************************************************/ -extern uint8_t L2CA_SetTraceLevel (uint8_t trace_level); +extern uint8_t L2CA_SetTraceLevel(uint8_t trace_level); /******************************************************************************* * @@ -689,7 +678,7 @@ extern uint8_t L2CA_SetTraceLevel (uint8_t trace_level); * Returns the new (current) role * ******************************************************************************/ -extern uint8_t L2CA_SetDesireRole (uint8_t new_role); +extern uint8_t L2CA_SetDesireRole(uint8_t new_role); /******************************************************************************* * @@ -700,7 +689,8 @@ extern uint8_t L2CA_SetDesireRole (uint8_t new_role); * Returns CID of 0 if none. * ******************************************************************************/ -extern uint16_t L2CA_LocalLoopbackReq (uint16_t psm, uint16_t handle, BD_ADDR p_bd_addr); +extern uint16_t L2CA_LocalLoopbackReq(uint16_t psm, uint16_t handle, + BD_ADDR p_bd_addr); /******************************************************************************* * @@ -716,8 +706,7 @@ extern uint16_t L2CA_LocalLoopbackReq (uint16_t psm, uint16_t handle, BD_ADDR p_ * Returns Number of buffers left queued for that CID * ******************************************************************************/ -extern uint16_t L2CA_FlushChannel (uint16_t lcid, uint16_t num_to_flush); - +extern uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush); /******************************************************************************* * @@ -730,7 +719,7 @@ extern uint16_t L2CA_FlushChannel (uint16_t lcid, uint16_t num_to_flush); * Returns true if a valid channel, else false * ******************************************************************************/ -extern bool L2CA_SetAclPriority (BD_ADDR bd_addr, uint8_t priority); +extern bool L2CA_SetAclPriority(BD_ADDR bd_addr, uint8_t priority); /******************************************************************************* * @@ -743,7 +732,7 @@ extern bool L2CA_SetAclPriority (BD_ADDR bd_addr, uint8_t priority); * Returns true if valid channel, else false * ******************************************************************************/ -extern bool L2CA_FlowControl (uint16_t cid, bool data_enabled); +extern bool L2CA_FlowControl(uint16_t cid, bool data_enabled); /******************************************************************************* * @@ -754,8 +743,8 @@ extern bool L2CA_FlowControl (uint16_t cid, bool data_enabled); * Returns true if valid Channel, else false * ******************************************************************************/ -extern bool L2CA_SendTestSFrame (uint16_t cid, uint8_t sup_type, - uint8_t back_track); +extern bool L2CA_SendTestSFrame(uint16_t cid, uint8_t sup_type, + uint8_t back_track); /******************************************************************************* * @@ -766,7 +755,7 @@ extern bool L2CA_SendTestSFrame (uint16_t cid, uint8_t sup_type, * Returns true if a valid channel, else false * ******************************************************************************/ -extern bool L2CA_SetTxPriority (uint16_t cid, tL2CAP_CHNL_PRIORITY priority); +extern bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority); /******************************************************************************* * @@ -780,7 +769,7 @@ extern bool L2CA_SetTxPriority (uint16_t cid, tL2CAP_CHNL_PRIORITY priority); * Returns * ******************************************************************************/ -extern bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda); +extern bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB* p_cb, BD_ADDR p_bda); /******************************************************************************* * @@ -791,9 +780,10 @@ extern bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda); * Returns true if a valid channel, else false * ******************************************************************************/ -extern bool L2CA_SetChnlDataRate (uint16_t cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx); +extern bool L2CA_SetChnlDataRate(uint16_t cid, tL2CAP_CHNL_DATA_RATE tx, + tL2CAP_CHNL_DATA_RATE rx); -typedef void (tL2CA_RESERVE_CMPL_CBACK) (void); +typedef void(tL2CA_RESERVE_CMPL_CBACK)(void); /******************************************************************************* * @@ -819,7 +809,7 @@ typedef void (tL2CA_RESERVE_CMPL_CBACK) (void); * NOTE This flush timeout applies to all logical channels active on * the ACL link. ******************************************************************************/ -extern bool L2CA_SetFlushTimeout (BD_ADDR bd_addr, uint16_t flush_tout); +extern bool L2CA_SetFlushTimeout(BD_ADDR bd_addr, uint16_t flush_tout); /******************************************************************************* * @@ -837,7 +827,7 @@ extern bool L2CA_SetFlushTimeout (BD_ADDR bd_addr, uint16_t flush_tout); * L2CAP_DW_FAILED, if error * ******************************************************************************/ -extern uint8_t L2CA_DataWriteEx (uint16_t cid, BT_HDR *p_data, uint16_t flags); +extern uint8_t L2CA_DataWriteEx(uint16_t cid, BT_HDR* p_data, uint16_t flags); /******************************************************************************* * @@ -849,7 +839,7 @@ extern uint8_t L2CA_DataWriteEx (uint16_t cid, BT_HDR *p_data, uint16_t flags); * Returns true if CID found, else false * ******************************************************************************/ -extern bool L2CA_SetChnlFlushability (uint16_t cid, bool is_flushable); +extern bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable); /******************************************************************************* * @@ -863,7 +853,8 @@ extern bool L2CA_SetChnlFlushability (uint16_t cid, bool is_flushable); * Return value: true if peer is connected * ******************************************************************************/ -extern bool L2CA_GetPeerFeatures (BD_ADDR bd_addr, uint32_t *p_ext_feat, uint8_t *p_chnl_mask); +extern bool L2CA_GetPeerFeatures(BD_ADDR bd_addr, uint32_t* p_ext_feat, + uint8_t* p_chnl_mask); /******************************************************************************* * @@ -877,7 +868,7 @@ extern bool L2CA_GetPeerFeatures (BD_ADDR bd_addr, uint32_t *p_ext_feat, uint * Return value: true if found lcb for the given handle, false otherwise * ******************************************************************************/ -extern bool L2CA_GetBDAddrbyHandle (uint16_t handle, BD_ADDR bd_addr); +extern bool L2CA_GetBDAddrbyHandle(uint16_t handle, BD_ADDR bd_addr); /******************************************************************************* * @@ -890,8 +881,7 @@ extern bool L2CA_GetBDAddrbyHandle (uint16_t handle, BD_ADDR bd_addr); * Return value: Channel mode * ******************************************************************************/ -extern uint8_t L2CA_GetChnlFcrMode (uint16_t lcid); - +extern uint8_t L2CA_GetChnlFcrMode(uint16_t lcid); /******************************************************************************* * @@ -904,16 +894,16 @@ extern uint8_t L2CA_GetChnlFcrMode (uint16_t lcid); * Data Type * Data */ -#define L2CAP_UCD_INFO_TYPE_RECEPTION 0x01 -#define L2CAP_UCD_INFO_TYPE_MTU 0x02 +#define L2CAP_UCD_INFO_TYPE_RECEPTION 0x01 +#define L2CAP_UCD_INFO_TYPE_MTU 0x02 -typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, uint8_t, uint32_t); +typedef void(tL2CA_UCD_DISCOVER_CB)(BD_ADDR, uint8_t, uint32_t); /* UCD data received. Parameters are * BD Address of remote * Pointer to buffer with data */ -typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *); +typedef void(tL2CA_UCD_DATA_CB)(BD_ADDR, BT_HDR*); /* Congestion status callback protype. This callback is optional. If * an application tries to send data when the transmit queue is full, @@ -921,15 +911,14 @@ typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *); * remote BD_ADDR * true if congested, false if uncongested */ -typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, bool ); +typedef void(tL2CA_UCD_CONGESTION_STATUS_CB)(BD_ADDR, bool); /* UCD registration info (the callback addresses and PSM) */ -typedef struct -{ - tL2CA_UCD_DISCOVER_CB *pL2CA_UCD_Discover_Cb; - tL2CA_UCD_DATA_CB *pL2CA_UCD_Data_Cb; - tL2CA_UCD_CONGESTION_STATUS_CB *pL2CA_UCD_Congestion_Status_Cb; +typedef struct { + tL2CA_UCD_DISCOVER_CB* pL2CA_UCD_Discover_Cb; + tL2CA_UCD_DATA_CB* pL2CA_UCD_Data_Cb; + tL2CA_UCD_CONGESTION_STATUS_CB* pL2CA_UCD_Congestion_Status_Cb; } tL2CAP_UCD_CB_INFO; /******************************************************************************* @@ -943,7 +932,7 @@ typedef struct * Return value: true if successs * ******************************************************************************/ -extern bool L2CA_UcdRegister ( uint16_t psm, tL2CAP_UCD_CB_INFO *p_cb_info ); +extern bool L2CA_UcdRegister(uint16_t psm, tL2CAP_UCD_CB_INFO* p_cb_info); /******************************************************************************* * @@ -956,7 +945,7 @@ extern bool L2CA_UcdRegister ( uint16_t psm, tL2CAP_UCD_CB_INFO *p_cb_info ); * Return value: true if successs * ******************************************************************************/ -extern bool L2CA_UcdDeregister ( uint16_t psm ); +extern bool L2CA_UcdDeregister(uint16_t psm); /******************************************************************************* * @@ -973,7 +962,7 @@ extern bool L2CA_UcdDeregister ( uint16_t psm ); * Return value: true if successs * ******************************************************************************/ -extern bool L2CA_UcdDiscover ( uint16_t psm, BD_ADDR rem_bda, uint8_t info_type ); +extern bool L2CA_UcdDiscover(uint16_t psm, BD_ADDR rem_bda, uint8_t info_type); /******************************************************************************* * @@ -992,7 +981,8 @@ extern bool L2CA_UcdDiscover ( uint16_t psm, BD_ADDR rem_bda, uint8_t info_ty * L2CAP_DW_FAILED, if error * ******************************************************************************/ -extern uint16_t L2CA_UcdDataWrite (uint16_t psm, BD_ADDR rem_bda, BT_HDR *p_buf, uint16_t flags); +extern uint16_t L2CA_UcdDataWrite(uint16_t psm, BD_ADDR rem_bda, BT_HDR* p_buf, + uint16_t flags); /******************************************************************************* * @@ -1006,7 +996,7 @@ extern uint16_t L2CA_UcdDataWrite (uint16_t psm, BD_ADDR rem_bda, BT_HDR *p_buf, * Return value: true if successs * ******************************************************************************/ -extern bool L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, uint16_t timeout ); +extern bool L2CA_UcdSetIdleTimeout(BD_ADDR rem_bda, uint16_t timeout); /******************************************************************************* * @@ -1017,8 +1007,8 @@ extern bool L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, uint16_t timeout ); * Returns true if a valid channel, else false * ******************************************************************************/ -extern bool L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority ); - +extern bool L2CA_UCDSetTxPriority(BD_ADDR rem_bda, + tL2CAP_CHNL_PRIORITY priority); /******************************************************************************* * @@ -1033,14 +1023,15 @@ extern bool L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY pri * Reason for connection failure * transport : physical transport, BR/EDR or LE */ -typedef void (tL2CA_FIXED_CHNL_CB) (uint16_t, BD_ADDR, bool , uint16_t, tBT_TRANSPORT); +typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, BD_ADDR, bool, uint16_t, + tBT_TRANSPORT); /* Signalling data received. Parameters are * channel * BD Address of remote * Pointer to buffer with data */ -typedef void (tL2CA_FIXED_DATA_CB) (uint16_t, BD_ADDR, BT_HDR *); +typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, BD_ADDR, BT_HDR*); /* Congestion status callback protype. This callback is optional. If * an application tries to send data when the transmit queue is full, @@ -1048,22 +1039,21 @@ typedef void (tL2CA_FIXED_DATA_CB) (uint16_t, BD_ADDR, BT_HDR *); * remote BD_ADDR * true if congested, false if uncongested */ -typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, bool ); +typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(BD_ADDR, bool); /* Fixed channel registration info (the callback addresses and channel config) */ -typedef struct -{ - tL2CA_FIXED_CHNL_CB *pL2CA_FixedConn_Cb; - tL2CA_FIXED_DATA_CB *pL2CA_FixedData_Cb; - tL2CA_FIXED_CONGESTION_STATUS_CB *pL2CA_FixedCong_Cb; - tL2CAP_FCR_OPTS fixed_chnl_opts; - - uint16_t default_idle_tout; - tL2CA_TX_COMPLETE_CB *pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */ +typedef struct { + tL2CA_FIXED_CHNL_CB* pL2CA_FixedConn_Cb; + tL2CA_FIXED_DATA_CB* pL2CA_FixedData_Cb; + tL2CA_FIXED_CONGESTION_STATUS_CB* pL2CA_FixedCong_Cb; + tL2CAP_FCR_OPTS fixed_chnl_opts; + + uint16_t default_idle_tout; + tL2CA_TX_COMPLETE_CB* + pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */ } tL2CAP_FIXED_CHNL_REG; - #if (L2CAP_NUM_FIXED_CHNLS > 0) /******************************************************************************* * @@ -1077,7 +1067,8 @@ typedef struct * Return value: true if registered OK * ******************************************************************************/ -extern bool L2CA_RegisterFixedChannel (uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg); +extern bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, + tL2CAP_FIXED_CHNL_REG* p_freg); /******************************************************************************* * @@ -1091,7 +1082,7 @@ extern bool L2CA_RegisterFixedChannel (uint16_t fixed_cid, tL2CAP_FIXED_CHNL * Return value: true if connection started * ******************************************************************************/ -extern bool L2CA_ConnectFixedChnl (uint16_t fixed_cid, BD_ADDR bd_addr); +extern bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, BD_ADDR bd_addr); /******************************************************************************* * @@ -1107,7 +1098,8 @@ extern bool L2CA_ConnectFixedChnl (uint16_t fixed_cid, BD_ADDR bd_addr); * L2CAP_DW_FAILED, if error * ******************************************************************************/ -extern uint16_t L2CA_SendFixedChnlData (uint16_t fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf); +extern uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, BD_ADDR rem_bda, + BT_HDR* p_buf); /******************************************************************************* * @@ -1122,7 +1114,7 @@ extern uint16_t L2CA_SendFixedChnlData (uint16_t fixed_cid, BD_ADDR rem_bda, BT_ * Return value: true if channel removed * ******************************************************************************/ -extern bool L2CA_RemoveFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda); +extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, BD_ADDR rem_bda); /******************************************************************************* * @@ -1141,7 +1133,8 @@ extern bool L2CA_RemoveFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda); * Returns true if command succeeded, false if failed * ******************************************************************************/ -extern bool L2CA_SetFixedChannelTout (BD_ADDR rem_bda, uint16_t fixed_cid, uint16_t idle_tout); +extern bool L2CA_SetFixedChannelTout(BD_ADDR rem_bda, uint16_t fixed_cid, + uint16_t idle_tout); #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */ @@ -1158,9 +1151,10 @@ extern bool L2CA_SetFixedChannelTout (BD_ADDR rem_bda, uint16_t fixed_cid, ui * Returns true if successful * ******************************************************************************/ -extern bool L2CA_GetCurrentConfig (uint16_t lcid, - tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits, - tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits); +extern bool L2CA_GetCurrentConfig(uint16_t lcid, tL2CAP_CFG_INFO** pp_our_cfg, + tL2CAP_CH_CFG_BITS* p_our_cfg_bits, + tL2CAP_CFG_INFO** pp_peer_cfg, + tL2CAP_CH_CFG_BITS* p_peer_cfg_bits); /******************************************************************************* * @@ -1172,7 +1166,8 @@ extern bool L2CA_GetCurrentConfig (uint16_t lcid, * Returns true if successful * ******************************************************************************/ -extern bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t *mtu, uint16_t *rcid, uint16_t *handle); +extern bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t* mtu, + uint16_t* rcid, uint16_t* handle); /******************************************************************************* * @@ -1185,7 +1180,7 @@ extern bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t *mtu, uint16_t * * Return value: true if connection was cancelled * ******************************************************************************/ -extern bool L2CA_CancelBleConnectReq (BD_ADDR rem_bda); +extern bool L2CA_CancelBleConnectReq(BD_ADDR rem_bda); /******************************************************************************* * @@ -1198,8 +1193,9 @@ extern bool L2CA_CancelBleConnectReq (BD_ADDR rem_bda); * Return value: true if update started * ******************************************************************************/ -extern bool L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, uint16_t min_int, - uint16_t max_int, uint16_t latency, uint16_t timeout); +extern bool L2CA_UpdateBleConnParams(BD_ADDR rem_bdRa, uint16_t min_int, + uint16_t max_int, uint16_t latency, + uint16_t timeout); /******************************************************************************* * @@ -1213,7 +1209,7 @@ extern bool L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, uint16_t min_int, * Return value: true if update started * ******************************************************************************/ -extern bool L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, bool enable); +extern bool L2CA_EnableUpdateBleConnParams(BD_ADDR rem_bda, bool enable); /******************************************************************************* * @@ -1224,7 +1220,7 @@ extern bool L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, bool enable); * Returns link role. * ******************************************************************************/ -extern uint8_t L2CA_GetBleConnRole (BD_ADDR bd_addr); +extern uint8_t L2CA_GetBleConnRole(BD_ADDR bd_addr); /******************************************************************************* * @@ -1238,10 +1234,11 @@ extern uint8_t L2CA_GetBleConnRole (BD_ADDR bd_addr); * Returns disconnect reason * ******************************************************************************/ -extern uint16_t L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport); +extern uint16_t L2CA_GetDisconnectReason(BD_ADDR remote_bda, + tBT_TRANSPORT transport); #ifdef __cplusplus } #endif -#endif /* L2C_API_H */ +#endif /* L2C_API_H */ diff --git a/stack/include/l2cap_client.h b/stack/include/l2cap_client.h index 22644a401..c5ecaf6fd 100644 --- a/stack/include/l2cap_client.h +++ b/stack/include/l2cap_client.h @@ -26,27 +26,29 @@ typedef struct buffer_t buffer_t; typedef struct l2cap_client_t l2cap_client_t; typedef struct { - void (*connected)(l2cap_client_t *client, void *context); - void (*disconnected)(l2cap_client_t *client, void *context); - void (*read_ready)(l2cap_client_t *client, buffer_t *packet, void *context); - void (*write_ready)(l2cap_client_t *client, void *context); + void (*connected)(l2cap_client_t* client, void* context); + void (*disconnected)(l2cap_client_t* client, void* context); + void (*read_ready)(l2cap_client_t* client, buffer_t* packet, void* context); + void (*write_ready)(l2cap_client_t* client, void* context); } l2cap_client_callbacks_t; // Returns a new buffer with enough space for |size| bytes of L2CAP payload. // |size| must be greater than zero. This function returns NULL if the buffer // could not be allocated. The returned buffer must be freed with |buffer_free| // when it is no longer needed. -buffer_t *l2cap_buffer_new(size_t size); +buffer_t* l2cap_buffer_new(size_t size); // Creates and returns a new L2CAP client object. |callbacks| must not be NULL // and must specify a set of functions that should be called back when events // occur on the L2CAP connection. |context| may be NULL and will be passed as // the argument to all callbacks in |l2cap_client_callbacks_t|. The returned // object must be freed with |l2cap_client_free|. -l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void *context); +l2cap_client_t* l2cap_client_new(const l2cap_client_callbacks_t* callbacks, + void* context); -// Frees the L2CAP client object allocated with |l2cap_client_new|. |client| may be NULL. -void l2cap_client_free(l2cap_client_t *client); +// Frees the L2CAP client object allocated with |l2cap_client_new|. |client| may +// be NULL. +void l2cap_client_free(l2cap_client_t* client); // Attempts to connect the |client| to a peer device specified by // |remote_bdaddr| using the |psm| protocol specifier. This function returns @@ -57,20 +59,21 @@ void l2cap_client_free(l2cap_client_t *client); // This function must not be called while a connect operation is in progress or // while |l2cap_client_is_connected|. |client| and |remote_bdaddr| must not be // NULL. |psm| must be greater than zero. -bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdaddr, uint16_t psm); +bool l2cap_client_connect(l2cap_client_t* client, + const bt_bdaddr_t* remote_bdaddr, uint16_t psm); // Disconnects a connected |client|. This function is asynchronous and // idempotent. It will indicate completion with a 'disconnected' callback. // |client| must not be NULL. -void l2cap_client_disconnect(l2cap_client_t *client); +void l2cap_client_disconnect(l2cap_client_t* client); // Returns true if |client| is connected and is ready to accept data written // to it. |client| must not be NULL. -bool l2cap_client_is_connected(const l2cap_client_t *client); +bool l2cap_client_is_connected(const l2cap_client_t* client); // Writes data contained in |packet| to a connected |client|. This function // returns true if the packet was successfully queued for delivery, false if the // client cannot accept more data at this time. If this function returns false, // the caller must wait for the 'write_ready' callback to write additional data // to the client. Neither |client| nor |packet| may be NULL. -bool l2cap_client_write(l2cap_client_t *client, buffer_t *packet); +bool l2cap_client_write(l2cap_client_t* client, buffer_t* packet); diff --git a/stack/include/l2cdefs.h b/stack/include/l2cdefs.h index 5c3899ee7..60acc4ef5 100644 --- a/stack/include/l2cdefs.h +++ b/stack/include/l2cdefs.h @@ -21,285 +21,278 @@ /* L2CAP command codes */ -#define L2CAP_CMD_REJECT 0x01 -#define L2CAP_CMD_CONN_REQ 0x02 -#define L2CAP_CMD_CONN_RSP 0x03 -#define L2CAP_CMD_CONFIG_REQ 0x04 -#define L2CAP_CMD_CONFIG_RSP 0x05 -#define L2CAP_CMD_DISC_REQ 0x06 -#define L2CAP_CMD_DISC_RSP 0x07 -#define L2CAP_CMD_ECHO_REQ 0x08 -#define L2CAP_CMD_ECHO_RSP 0x09 -#define L2CAP_CMD_INFO_REQ 0x0A -#define L2CAP_CMD_INFO_RSP 0x0B -#define L2CAP_CMD_AMP_CONN_REQ 0x0C -#define L2CAP_CMD_AMP_CONN_RSP 0x0D -#define L2CAP_CMD_AMP_MOVE_REQ 0x0E -#define L2CAP_CMD_AMP_MOVE_RSP 0x0F -#define L2CAP_CMD_AMP_MOVE_CFM 0x10 -#define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11 -#define L2CAP_CMD_BLE_UPDATE_REQ 0x12 -#define L2CAP_CMD_BLE_UPDATE_RSP 0x13 +#define L2CAP_CMD_REJECT 0x01 +#define L2CAP_CMD_CONN_REQ 0x02 +#define L2CAP_CMD_CONN_RSP 0x03 +#define L2CAP_CMD_CONFIG_REQ 0x04 +#define L2CAP_CMD_CONFIG_RSP 0x05 +#define L2CAP_CMD_DISC_REQ 0x06 +#define L2CAP_CMD_DISC_RSP 0x07 +#define L2CAP_CMD_ECHO_REQ 0x08 +#define L2CAP_CMD_ECHO_RSP 0x09 +#define L2CAP_CMD_INFO_REQ 0x0A +#define L2CAP_CMD_INFO_RSP 0x0B +#define L2CAP_CMD_AMP_CONN_REQ 0x0C +#define L2CAP_CMD_AMP_CONN_RSP 0x0D +#define L2CAP_CMD_AMP_MOVE_REQ 0x0E +#define L2CAP_CMD_AMP_MOVE_RSP 0x0F +#define L2CAP_CMD_AMP_MOVE_CFM 0x10 +#define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11 +#define L2CAP_CMD_BLE_UPDATE_REQ 0x12 +#define L2CAP_CMD_BLE_UPDATE_RSP 0x13 #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ 0x14 #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES 0x15 -#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT 0x16 +#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT 0x16 /* Define some packet and header lengths */ /* Length and CID */ -#define L2CAP_PKT_OVERHEAD 4 +#define L2CAP_PKT_OVERHEAD 4 /* Cmd code, Id and length */ -#define L2CAP_CMD_OVERHEAD 4 +#define L2CAP_CMD_OVERHEAD 4 /* Reason (data is optional) */ -#define L2CAP_CMD_REJECT_LEN 2 +#define L2CAP_CMD_REJECT_LEN 2 /* PSM and source CID */ -#define L2CAP_CONN_REQ_LEN 4 +#define L2CAP_CONN_REQ_LEN 4 /* Dest CID, source CID, reason, status */ -#define L2CAP_CONN_RSP_LEN 8 +#define L2CAP_CONN_RSP_LEN 8 /* Dest CID, flags (data is optional) */ -#define L2CAP_CONFIG_REQ_LEN 4 +#define L2CAP_CONFIG_REQ_LEN 4 /* Dest CID, flags, result,data optional*/ -#define L2CAP_CONFIG_RSP_LEN 6 +#define L2CAP_CONFIG_RSP_LEN 6 /* Dest CID, source CID */ -#define L2CAP_DISC_REQ_LEN 4 +#define L2CAP_DISC_REQ_LEN 4 /* Dest CID, source CID */ -#define L2CAP_DISC_RSP_LEN 4 +#define L2CAP_DISC_RSP_LEN 4 /* Data is optional */ -#define L2CAP_ECHO_REQ_LEN 0 +#define L2CAP_ECHO_REQ_LEN 0 /* Data is optional */ -#define L2CAP_ECHO_RSP_LEN 0 +#define L2CAP_ECHO_RSP_LEN 0 /* Info type */ -#define L2CAP_INFO_REQ_LEN 2 +#define L2CAP_INFO_REQ_LEN 2 /* Info type, result (data is optional) */ -#define L2CAP_INFO_RSP_LEN 4 +#define L2CAP_INFO_RSP_LEN 4 /* Additional connectionless packet overhead */ -#define L2CAP_UCD_OVERHEAD 2 +#define L2CAP_UCD_OVERHEAD 2 /* PSM, CID, and remote controller ID */ -#define L2CAP_AMP_CONN_REQ_LEN 5 +#define L2CAP_AMP_CONN_REQ_LEN 5 /* CID and remote controller ID */ -#define L2CAP_AMP_MOVE_REQ_LEN 3 +#define L2CAP_AMP_MOVE_REQ_LEN 3 /* CID and result */ -#define L2CAP_AMP_MOVE_RSP_LEN 4 +#define L2CAP_AMP_MOVE_RSP_LEN 4 /* CID and result */ -#define L2CAP_AMP_MOVE_CFM_LEN 4 +#define L2CAP_AMP_MOVE_CFM_LEN 4 /* CID */ -#define L2CAP_AMP_MOVE_CFM_RSP_LEN 2 +#define L2CAP_AMP_MOVE_CFM_RSP_LEN 2 /* Min and max interval, latency, tout */ -#define L2CAP_CMD_BLE_UPD_REQ_LEN 8 +#define L2CAP_CMD_BLE_UPD_REQ_LEN 8 /* Result */ -#define L2CAP_CMD_BLE_UPD_RSP_LEN 2 +#define L2CAP_CMD_BLE_UPD_RSP_LEN 2 /* LE_PSM, SCID, MTU, MPS, Init Credit */ #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN 10 /* DCID, MTU, MPS, Init credit, Result */ #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN 10 /* CID, Credit */ -#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN 4 +#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN 4 /* Define the packet boundary flags */ #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) -#define L2CAP_PKT_START_FLUSHABLE 2 -#define L2CAP_PKT_START_NON_FLUSHABLE 0 +#define L2CAP_PKT_START_FLUSHABLE 2 +#define L2CAP_PKT_START_NON_FLUSHABLE 0 #endif -#define L2CAP_COMPLETE_AMP_PKT 3 /* complete L2CAP packet on AMP HCI */ -#define L2CAP_PKT_START 2 -#define L2CAP_PKT_CONTINUE 1 -#define L2CAP_MASK_FLAG 0x0FFF -#define L2CAP_PKT_TYPE_SHIFT 12 -#define L2CAP_PKT_TYPE_MASK 3 - +#define L2CAP_COMPLETE_AMP_PKT 3 /* complete L2CAP packet on AMP HCI */ +#define L2CAP_PKT_START 2 +#define L2CAP_PKT_CONTINUE 1 +#define L2CAP_MASK_FLAG 0x0FFF +#define L2CAP_PKT_TYPE_SHIFT 12 +#define L2CAP_PKT_TYPE_MASK 3 /* Define the L2CAP connection result codes */ -#define L2CAP_CONN_OK 0 -#define L2CAP_CONN_PENDING 1 -#define L2CAP_CONN_NO_PSM 2 -#define L2CAP_CONN_SECURITY_BLOCK 3 -#define L2CAP_CONN_NO_RESOURCES 4 -#define L2CAP_CONN_BAD_CTLR_ID 5 /* AMP related */ -#define L2CAP_CONN_TIMEOUT 0xEEEE -#define L2CAP_CONN_AMP_FAILED 254 +#define L2CAP_CONN_OK 0 +#define L2CAP_CONN_PENDING 1 +#define L2CAP_CONN_NO_PSM 2 +#define L2CAP_CONN_SECURITY_BLOCK 3 +#define L2CAP_CONN_NO_RESOURCES 4 +#define L2CAP_CONN_BAD_CTLR_ID 5 /* AMP related */ +#define L2CAP_CONN_TIMEOUT 0xEEEE +#define L2CAP_CONN_AMP_FAILED 254 /* Add a couple of our own for internal use */ -#define L2CAP_CONN_NO_LINK 255 -#define L2CAP_CONN_CANCEL 256 /* L2CAP connection cancelled */ +#define L2CAP_CONN_NO_LINK 255 +#define L2CAP_CONN_CANCEL 256 /* L2CAP connection cancelled */ /* Define the LE L2CAP connection result codes */ -#define L2CAP_LE_CONN_OK 0 -#define L2CAP_LE_NO_PSM 2 -#define L2CAP_LE_NO_RESOURCES 4 -#define L2CAP_LE_INSUFFICIENT_AUTHENTICATION 5 -#define L2CAP_LE_INSUFFICIENT_AUTHORIZATION 6 -#define L2CAP_LE_INSUFFICIENT_ENCRYP_KEY_SIZE 7 -#define L2CAP_LE_INSUFFICIENT_ENCRYP 8 +#define L2CAP_LE_CONN_OK 0 +#define L2CAP_LE_NO_PSM 2 +#define L2CAP_LE_NO_RESOURCES 4 +#define L2CAP_LE_INSUFFICIENT_AUTHENTICATION 5 +#define L2CAP_LE_INSUFFICIENT_AUTHORIZATION 6 +#define L2CAP_LE_INSUFFICIENT_ENCRYP_KEY_SIZE 7 +#define L2CAP_LE_INSUFFICIENT_ENCRYP 8 /* We don't like peer device response */ -#define L2CAP_LE_INVALID_SOURCE_CID 9 +#define L2CAP_LE_INVALID_SOURCE_CID 9 /* Define L2CAP Move Channel Response result codes */ -#define L2CAP_MOVE_OK 0 -#define L2CAP_MOVE_PENDING 1 -#define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT 2 -#define L2CAP_MOVE_SAME_CTRLR_ID 3 +#define L2CAP_MOVE_OK 0 +#define L2CAP_MOVE_PENDING 1 +#define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT 2 +#define L2CAP_MOVE_SAME_CTRLR_ID 3 #define L2CAP_MOVE_CONFIG_NOT_SUPPORTED 4 -#define L2CAP_MOVE_CHAN_COLLISION 5 -#define L2CAP_MOVE_NOT_ALLOWED 6 - +#define L2CAP_MOVE_CHAN_COLLISION 5 +#define L2CAP_MOVE_NOT_ALLOWED 6 /* Define L2CAP Move Channel Confirmation result codes */ -#define L2CAP_MOVE_CFM_OK 0 -#define L2CAP_MOVE_CFM_REFUSED 1 - +#define L2CAP_MOVE_CFM_OK 0 +#define L2CAP_MOVE_CFM_REFUSED 1 /* Define the L2CAP command reject reason codes */ -#define L2CAP_CMD_REJ_NOT_UNDERSTOOD 0 -#define L2CAP_CMD_REJ_MTU_EXCEEDED 1 -#define L2CAP_CMD_REJ_INVALID_CID 2 - +#define L2CAP_CMD_REJ_NOT_UNDERSTOOD 0 +#define L2CAP_CMD_REJ_MTU_EXCEEDED 1 +#define L2CAP_CMD_REJ_INVALID_CID 2 /* L2CAP Predefined CIDs */ -#define L2CAP_SIGNALLING_CID 1 -#define L2CAP_CONNECTIONLESS_CID 2 -#define L2CAP_AMP_CID 3 -#define L2CAP_ATT_CID 4 -#define L2CAP_BLE_SIGNALLING_CID 5 -#define L2CAP_SMP_CID 6 -#define L2CAP_SMP_BR_CID 7 -#define L2CAP_AMP_TEST_CID 0x003F -#define L2CAP_BASE_APPL_CID 0x0040 -#define L2CAP_BLE_CONN_MAX_CID 0x007F +#define L2CAP_SIGNALLING_CID 1 +#define L2CAP_CONNECTIONLESS_CID 2 +#define L2CAP_AMP_CID 3 +#define L2CAP_ATT_CID 4 +#define L2CAP_BLE_SIGNALLING_CID 5 +#define L2CAP_SMP_CID 6 +#define L2CAP_SMP_BR_CID 7 +#define L2CAP_AMP_TEST_CID 0x003F +#define L2CAP_BASE_APPL_CID 0x0040 +#define L2CAP_BLE_CONN_MAX_CID 0x007F /* Fixed Channels mask bits */ /* Signal channel supported (Mandatory) */ -#define L2CAP_FIXED_CHNL_SIG_BIT (1 << L2CAP_SIGNALLING_CID) +#define L2CAP_FIXED_CHNL_SIG_BIT (1 << L2CAP_SIGNALLING_CID) /* Connectionless reception */ #define L2CAP_FIXED_CHNL_CNCTLESS_BIT (1 << L2CAP_CONNECTIONLESS_CID) /* AMP Manager supported */ -#define L2CAP_FIXED_CHNL_AMP_BIT (1 << L2CAP_AMP_CID) +#define L2CAP_FIXED_CHNL_AMP_BIT (1 << L2CAP_AMP_CID) /* Attribute protocol supported */ -#define L2CAP_FIXED_CHNL_ATT_BIT (1 << L2CAP_ATT_CID) +#define L2CAP_FIXED_CHNL_ATT_BIT (1 << L2CAP_ATT_CID) /* BLE Signalling supported */ -#define L2CAP_FIXED_CHNL_BLE_SIG_BIT (1 << L2CAP_BLE_SIGNALLING_CID) +#define L2CAP_FIXED_CHNL_BLE_SIG_BIT (1 << L2CAP_BLE_SIGNALLING_CID) /* BLE Security Mgr supported */ -#define L2CAP_FIXED_CHNL_SMP_BIT (1 << L2CAP_SMP_CID) +#define L2CAP_FIXED_CHNL_SMP_BIT (1 << L2CAP_SMP_CID) /* Security Mgr over BR supported */ -#define L2CAP_FIXED_CHNL_SMP_BR_BIT (1 << L2CAP_SMP_BR_CID) - - +#define L2CAP_FIXED_CHNL_SMP_BR_BIT (1 << L2CAP_SMP_BR_CID) /* Define the L2CAP configuration result codes */ -#define L2CAP_CFG_OK 0 -#define L2CAP_CFG_UNACCEPTABLE_PARAMS 1 -#define L2CAP_CFG_FAILED_NO_REASON 2 -#define L2CAP_CFG_UNKNOWN_OPTIONS 3 -#define L2CAP_CFG_PENDING 4 -#define L2CAP_CFG_FLOW_SPEC_REJECTED 5 - +#define L2CAP_CFG_OK 0 +#define L2CAP_CFG_UNACCEPTABLE_PARAMS 1 +#define L2CAP_CFG_FAILED_NO_REASON 2 +#define L2CAP_CFG_UNKNOWN_OPTIONS 3 +#define L2CAP_CFG_PENDING 4 +#define L2CAP_CFG_FLOW_SPEC_REJECTED 5 /* Define the L2CAP configuration option types */ -#define L2CAP_CFG_TYPE_MTU 0x01 -#define L2CAP_CFG_TYPE_FLUSH_TOUT 0x02 -#define L2CAP_CFG_TYPE_QOS 0x03 -#define L2CAP_CFG_TYPE_FCR 0x04 -#define L2CAP_CFG_TYPE_FCS 0x05 -#define L2CAP_CFG_TYPE_EXT_FLOW 0x06 -#define L2CAP_CFG_TYPE_EXT_WIN_SIZE 0x07 - -#define L2CAP_CFG_MTU_OPTION_LEN 2 /* MTU option length */ -#define L2CAP_CFG_FLUSH_OPTION_LEN 2 /* Flush option len */ -#define L2CAP_CFG_QOS_OPTION_LEN 22 /* QOS option length */ -#define L2CAP_CFG_FCR_OPTION_LEN 9 /* FCR option length */ -#define L2CAP_CFG_FCS_OPTION_LEN 1 /* FCR option length */ -#define L2CAP_CFG_EXT_FLOW_OPTION_LEN 16 /* Extended Flow Spec */ -#define L2CAP_CFG_EXT_WIN_SIZE_LEN 2 /* Ext window size length */ -#define L2CAP_CFG_OPTION_OVERHEAD 2 /* Type and length */ +#define L2CAP_CFG_TYPE_MTU 0x01 +#define L2CAP_CFG_TYPE_FLUSH_TOUT 0x02 +#define L2CAP_CFG_TYPE_QOS 0x03 +#define L2CAP_CFG_TYPE_FCR 0x04 +#define L2CAP_CFG_TYPE_FCS 0x05 +#define L2CAP_CFG_TYPE_EXT_FLOW 0x06 +#define L2CAP_CFG_TYPE_EXT_WIN_SIZE 0x07 + +#define L2CAP_CFG_MTU_OPTION_LEN 2 /* MTU option length */ +#define L2CAP_CFG_FLUSH_OPTION_LEN 2 /* Flush option len */ +#define L2CAP_CFG_QOS_OPTION_LEN 22 /* QOS option length */ +#define L2CAP_CFG_FCR_OPTION_LEN 9 /* FCR option length */ +#define L2CAP_CFG_FCS_OPTION_LEN 1 /* FCR option length */ +#define L2CAP_CFG_EXT_FLOW_OPTION_LEN 16 /* Extended Flow Spec */ +#define L2CAP_CFG_EXT_WIN_SIZE_LEN 2 /* Ext window size length */ +#define L2CAP_CFG_OPTION_OVERHEAD 2 /* Type and length */ /* Configuration Cmd/Rsp Flags mask */ -#define L2CAP_CFG_FLAGS_MASK_CONT 0x0001 /* Flags mask: Continuation */ +#define L2CAP_CFG_FLAGS_MASK_CONT 0x0001 /* Flags mask: Continuation */ /* FCS Check Option values */ -#define L2CAP_CFG_FCS_BYPASS 0 /* Bypass the FCS in streaming or ERTM modes */ -#define L2CAP_CFG_FCS_USE 1 /* Use the FCS in streaming or ERTM modes [default] */ +#define L2CAP_CFG_FCS_BYPASS 0 /* Bypass the FCS in streaming or ERTM modes */ +#define L2CAP_CFG_FCS_USE \ + 1 /* Use the FCS in streaming or ERTM modes [default] */ /* Default values for configuration */ -#define L2CAP_NO_AUTOMATIC_FLUSH 0xFFFF -#define L2CAP_NO_RETRANSMISSION 0x0001 - -#define L2CAP_DEFAULT_MTU (672) -#define L2CAP_DEFAULT_FLUSH_TO L2CAP_NO_AUTOMATIC_FLUSH -#define L2CAP_DEFAULT_SERV_TYPE 1 -#define L2CAP_DEFAULT_TOKEN_RATE 0 -#define L2CAP_DEFAULT_BUCKET_SIZE 0 -#define L2CAP_DEFAULT_PEAK_BANDWIDTH 0 -#define L2CAP_DEFAULT_LATENCY 0xFFFFFFFF -#define L2CAP_DEFAULT_DELAY 0xFFFFFFFF -#define L2CAP_DEFAULT_FCS L2CAP_CFG_FCS_USE - +#define L2CAP_NO_AUTOMATIC_FLUSH 0xFFFF +#define L2CAP_NO_RETRANSMISSION 0x0001 + +#define L2CAP_DEFAULT_MTU (672) +#define L2CAP_DEFAULT_FLUSH_TO L2CAP_NO_AUTOMATIC_FLUSH +#define L2CAP_DEFAULT_SERV_TYPE 1 +#define L2CAP_DEFAULT_TOKEN_RATE 0 +#define L2CAP_DEFAULT_BUCKET_SIZE 0 +#define L2CAP_DEFAULT_PEAK_BANDWIDTH 0 +#define L2CAP_DEFAULT_LATENCY 0xFFFFFFFF +#define L2CAP_DEFAULT_DELAY 0xFFFFFFFF +#define L2CAP_DEFAULT_FCS L2CAP_CFG_FCS_USE /* Define the L2CAP disconnect result codes */ -#define L2CAP_DISC_OK 0 -#define L2CAP_DISC_TIMEOUT 0xEEEE +#define L2CAP_DISC_OK 0 +#define L2CAP_DISC_TIMEOUT 0xEEEE /* Define the L2CAP info resp result codes */ -#define L2CAP_INFO_RESP_RESULT_SUCCESS 0 -#define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED 1 +#define L2CAP_INFO_RESP_RESULT_SUCCESS 0 +#define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED 1 /* Define the info-type fields of information request & response */ -#define L2CAP_CONNLESS_MTU_INFO_TYPE 0x0001 +#define L2CAP_CONNLESS_MTU_INFO_TYPE 0x0001 /* Used in Information Req/Response */ #define L2CAP_EXTENDED_FEATURES_INFO_TYPE 0x0002 /* Used in AMP */ -#define L2CAP_FIXED_CHANNELS_INFO_TYPE 0x0003 +#define L2CAP_FIXED_CHANNELS_INFO_TYPE 0x0003 /* Connectionless MTU size */ -#define L2CAP_CONNLESS_MTU_INFO_SIZE 2 +#define L2CAP_CONNLESS_MTU_INFO_SIZE 2 /* Extended features array size */ -#define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE 4 +#define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE 4 /* Fixed channel array size */ -#define L2CAP_FIXED_CHNL_ARRAY_SIZE 8 +#define L2CAP_FIXED_CHNL_ARRAY_SIZE 8 /* Extended features mask bits */ /* Retransmission Mode (Not Supported) */ -#define L2CAP_EXTFEA_RTRANS 0x00000001 +#define L2CAP_EXTFEA_RTRANS 0x00000001 /* Flow Control Mode (Not Supported) */ -#define L2CAP_EXTFEA_FC 0x00000002 -#define L2CAP_EXTFEA_QOS 0x00000004 +#define L2CAP_EXTFEA_FC 0x00000002 +#define L2CAP_EXTFEA_QOS 0x00000004 /* Enhanced retransmission mode */ -#define L2CAP_EXTFEA_ENH_RETRANS 0x00000008 +#define L2CAP_EXTFEA_ENH_RETRANS 0x00000008 /* Streaming Mode */ -#define L2CAP_EXTFEA_STREAM_MODE 0x00000010 +#define L2CAP_EXTFEA_STREAM_MODE 0x00000010 /* Optional FCS (if set No FCS desired) */ -#define L2CAP_EXTFEA_NO_CRC 0x00000020 +#define L2CAP_EXTFEA_NO_CRC 0x00000020 /* Extended flow spec */ -#define L2CAP_EXTFEA_EXT_FLOW_SPEC 0x00000040 +#define L2CAP_EXTFEA_EXT_FLOW_SPEC 0x00000040 /* Fixed channels */ -#define L2CAP_EXTFEA_FIXED_CHNLS 0x00000080 +#define L2CAP_EXTFEA_FIXED_CHNLS 0x00000080 /* Extended Window Size */ -#define L2CAP_EXTFEA_EXT_WINDOW 0x00000100 +#define L2CAP_EXTFEA_EXT_WINDOW 0x00000100 /* Unicast Connectionless Data Reception */ -#define L2CAP_EXTFEA_UCD_RECEPTION 0x00000200 +#define L2CAP_EXTFEA_UCD_RECEPTION 0x00000200 /* Mask for locally supported features used in Information Response * (default to none) */ @@ -314,85 +307,88 @@ #endif /* Define a value that tells L2CAP to use the default HCI ACL buffer size */ -#define L2CAP_INVALID_ERM_BUF_SIZE 0 +#define L2CAP_INVALID_ERM_BUF_SIZE 0 /* Define a value that tells L2CAP to use the default MPS */ -#define L2CAP_DEFAULT_ERM_MPS 0x0000 +#define L2CAP_DEFAULT_ERM_MPS 0x0000 -#define L2CAP_FCR_OVERHEAD 2 /* Control word */ -#define L2CAP_FCS_LEN 2 /* FCS takes 2 bytes */ -#define L2CAP_SDU_LEN_OVERHEAD 2 /* SDU length field is 2 bytes */ -#define L2CAP_SDU_LEN_OFFSET 2 /* SDU length offset is 2 bytes */ -#define L2CAP_EXT_CONTROL_OVERHEAD 4 /* Extended Control Field */ +#define L2CAP_FCR_OVERHEAD 2 /* Control word */ +#define L2CAP_FCS_LEN 2 /* FCS takes 2 bytes */ +#define L2CAP_SDU_LEN_OVERHEAD 2 /* SDU length field is 2 bytes */ +#define L2CAP_SDU_LEN_OFFSET 2 /* SDU length offset is 2 bytes */ +#define L2CAP_EXT_CONTROL_OVERHEAD 4 /* Extended Control Field */ /* length(2), channel(2), control(4), SDU length(2) FCS(2) */ -#define L2CAP_MAX_HEADER_FCS (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN) +#define L2CAP_MAX_HEADER_FCS \ + (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + \ + L2CAP_FCS_LEN) /* To optimize this, it must be a multiple of the L2CAP PDU length AND match * the 3DH5 air including the l2cap headers in each packet. To match the latter, * the -5 is added. * Changed it to 8087 to have same value between BTIF and L2cap layers */ -#define L2CAP_MAX_SDU_LENGTH (8080 + 26 - (L2CAP_MIN_OFFSET + 6)) -#define L2CAP_MAX_BUF_SIZE (10240 + 24) +#define L2CAP_MAX_SDU_LENGTH (8080 + 26 - (L2CAP_MIN_OFFSET + 6)) +#define L2CAP_MAX_BUF_SIZE (10240 + 24) /* Part of L2CAP_MIN_OFFSET that is not part of L2CAP */ -#define L2CAP_OFFSET_WO_L2HDR (L2CAP_MIN_OFFSET-(L2CAP_PKT_OVERHEAD+L2CAP_FCR_OVERHEAD)) +#define L2CAP_OFFSET_WO_L2HDR \ + (L2CAP_MIN_OFFSET - (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD)) /* SAR bits in the control word */ /* Control word to begin with for unsegmented PDU*/ -#define L2CAP_FCR_UNSEG_SDU 0x0000 +#define L2CAP_FCR_UNSEG_SDU 0x0000 /* ...for Starting PDU of a semented SDU */ -#define L2CAP_FCR_START_SDU 0x4000 +#define L2CAP_FCR_START_SDU 0x4000 /* ...for ending PDU of a segmented SDU */ -#define L2CAP_FCR_END_SDU 0x8000 +#define L2CAP_FCR_END_SDU 0x8000 /* ...for continuation PDU of a segmented SDU */ -#define L2CAP_FCR_CONT_SDU 0xc000 +#define L2CAP_FCR_CONT_SDU 0xc000 /* Supervisory frame types */ /* Supervisory frame - RR */ -#define L2CAP_FCR_SUP_RR 0x0000 +#define L2CAP_FCR_SUP_RR 0x0000 /* Supervisory frame - REJ */ -#define L2CAP_FCR_SUP_REJ 0x0001 +#define L2CAP_FCR_SUP_REJ 0x0001 /* Supervisory frame - RNR */ -#define L2CAP_FCR_SUP_RNR 0x0002 +#define L2CAP_FCR_SUP_RNR 0x0002 /* Supervisory frame - SREJ */ -#define L2CAP_FCR_SUP_SREJ 0x0003 +#define L2CAP_FCR_SUP_SREJ 0x0003 /* Mask to get the SAR bits from control word */ -#define L2CAP_FCR_SAR_BITS 0xC000 +#define L2CAP_FCR_SAR_BITS 0xC000 /* Bits to shift right to get the SAR bits from ctrl-word */ -#define L2CAP_FCR_SAR_BITS_SHIFT 14 +#define L2CAP_FCR_SAR_BITS_SHIFT 14 /* Mask to check if a PDU is S-frame */ -#define L2CAP_FCR_S_FRAME_BIT 0x0001 +#define L2CAP_FCR_S_FRAME_BIT 0x0001 /* Mask to get the req-seq from control word */ -#define L2CAP_FCR_REQ_SEQ_BITS 0x3F00 +#define L2CAP_FCR_REQ_SEQ_BITS 0x3F00 /* Bits to shift right to get the req-seq from ctrl-word */ -#define L2CAP_FCR_REQ_SEQ_BITS_SHIFT 8 +#define L2CAP_FCR_REQ_SEQ_BITS_SHIFT 8 /* Mask on get the tx-seq from control word */ -#define L2CAP_FCR_TX_SEQ_BITS 0x007E +#define L2CAP_FCR_TX_SEQ_BITS 0x007E /* Bits to shift right to get the tx-seq from ctrl-word */ -#define L2CAP_FCR_TX_SEQ_BITS_SHIFT 1 +#define L2CAP_FCR_TX_SEQ_BITS_SHIFT 1 /* F-bit in the control word (Sup and I frames) */ -#define L2CAP_FCR_F_BIT 0x0080 +#define L2CAP_FCR_F_BIT 0x0080 /* P-bit in the control word (Sup frames only) */ -#define L2CAP_FCR_P_BIT 0x0010 +#define L2CAP_FCR_P_BIT 0x0010 -#define L2CAP_FCR_F_BIT_SHIFT 7 -#define L2CAP_FCR_P_BIT_SHIFT 4 +#define L2CAP_FCR_F_BIT_SHIFT 7 +#define L2CAP_FCR_P_BIT_SHIFT 4 /* Mask to get the segmentation bits from ctrl-word */ -#define L2CAP_FCR_SEG_BITS 0xC000 +#define L2CAP_FCR_SEG_BITS 0xC000 /* Bits to shift right to get the S-bits from ctrl-word */ -#define L2CAP_FCR_SUP_SHIFT 2 +#define L2CAP_FCR_SUP_SHIFT 2 /* Mask to get the supervisory bits from ctrl-word */ -#define L2CAP_FCR_SUP_BITS 0x000C +#define L2CAP_FCR_SUP_BITS 0x000C /* Initial state of the CRC register */ -#define L2CAP_FCR_INIT_CRC 0 +#define L2CAP_FCR_INIT_CRC 0 /* Mask for sequence numbers (range 0 - 63) */ -#define L2CAP_FCR_SEQ_MODULO 0x3F +#define L2CAP_FCR_SEQ_MODULO 0x3F #endif diff --git a/stack/include/mca_api.h b/stack/include/mca_api.h index e070f247f..860d37c71 100644 --- a/stack/include/mca_api.h +++ b/stack/include/mca_api.h @@ -33,195 +33,199 @@ extern "C" { #endif /* move the following to bt_target.h or other place later */ -#define MCA_NUM_TC_TBL ((MCA_NUM_REGS)*(MCA_NUM_LINKS)*(MCA_NUM_MDLS+1)) +#define MCA_NUM_TC_TBL ((MCA_NUM_REGS) * (MCA_NUM_LINKS) * (MCA_NUM_MDLS + 1)) /* Number of control channel control blocks */ -#define MCA_NUM_CCBS ((MCA_NUM_REGS)*(MCA_NUM_LINKS)) +#define MCA_NUM_CCBS ((MCA_NUM_REGS) * (MCA_NUM_LINKS)) /* Number of data channel control blocks */ -#define MCA_NUM_DCBS ((MCA_NUM_REGS)*(MCA_NUM_LINKS)*(MCA_NUM_MDLS)) - +#define MCA_NUM_DCBS ((MCA_NUM_REGS) * (MCA_NUM_LINKS) * (MCA_NUM_MDLS)) /***************************************************************************** * constants ****************************************************************************/ /* API function return value result codes. */ -#define MCA_SUCCESS 0 /* Function successful */ -#define MCA_BAD_PARAMS 1 /* Invalid parameters */ -#define MCA_NO_RESOURCES 2 /* Not enough resources */ -#define MCA_BAD_HANDLE 3 /* Bad handle */ -#define MCA_BUSY 4 /* A procedure is already in progress */ -#define MCA_WRITE_FAIL 5 /* Write failed */ -#define MCA_BAD_MDL_ID 6 /* MDL ID is not valid for the current API */ +#define MCA_SUCCESS 0 /* Function successful */ +#define MCA_BAD_PARAMS 1 /* Invalid parameters */ +#define MCA_NO_RESOURCES 2 /* Not enough resources */ +#define MCA_BAD_HANDLE 3 /* Bad handle */ +#define MCA_BUSY 4 /* A procedure is already in progress */ +#define MCA_WRITE_FAIL 5 /* Write failed */ +#define MCA_BAD_MDL_ID 6 /* MDL ID is not valid for the current API */ typedef uint8_t tMCA_RESULT; /* MDEP data type. */ -#define MCA_TDEP_ECHO 0 /* MDEP for echo test */ -#define MCA_TDEP_DATA 1 /* MDEP for normal data */ +#define MCA_TDEP_ECHO 0 /* MDEP for echo test */ +#define MCA_TDEP_DATA 1 /* MDEP for normal data */ /* Control callback events. */ -#define MCA_ERROR_RSP_EVT 0 /* error response */ -#define MCA_CREATE_IND_EVT 1 /* create mdl indication */ -#define MCA_CREATE_CFM_EVT 2 /* create mdl confirm */ -#define MCA_RECONNECT_IND_EVT 3 /* reconnect mdl indication */ -#define MCA_RECONNECT_CFM_EVT 4 /* reconnect mdl confirm */ -#define MCA_ABORT_IND_EVT 5 /* abort mdl indication */ -#define MCA_ABORT_CFM_EVT 6 /* abort mdl confirm */ -#define MCA_DELETE_IND_EVT 7 /* delete mdl indication */ -#define MCA_DELETE_CFM_EVT 8 /* delete mdl confirm */ +#define MCA_ERROR_RSP_EVT 0 /* error response */ +#define MCA_CREATE_IND_EVT 1 /* create mdl indication */ +#define MCA_CREATE_CFM_EVT 2 /* create mdl confirm */ +#define MCA_RECONNECT_IND_EVT 3 /* reconnect mdl indication */ +#define MCA_RECONNECT_CFM_EVT 4 /* reconnect mdl confirm */ +#define MCA_ABORT_IND_EVT 5 /* abort mdl indication */ +#define MCA_ABORT_CFM_EVT 6 /* abort mdl confirm */ +#define MCA_DELETE_IND_EVT 7 /* delete mdl indication */ +#define MCA_DELETE_CFM_EVT 8 /* delete mdl confirm */ /* request sync capabilities & requirements */ -#define MCA_SYNC_CAP_IND_EVT 0x11 -#define MCA_SYNC_CAP_CFM_EVT 0x12 /* indicate completion */ +#define MCA_SYNC_CAP_IND_EVT 0x11 +#define MCA_SYNC_CAP_CFM_EVT 0x12 /* indicate completion */ /* request to set the time-stamp clock */ -#define MCA_SYNC_SET_IND_EVT 0x13 -#define MCA_SYNC_SET_CFM_EVT 0x14 /* indicate completion */ +#define MCA_SYNC_SET_IND_EVT 0x13 +#define MCA_SYNC_SET_CFM_EVT 0x14 /* indicate completion */ /* update of the actual time-stamp clock instant from the sync slave */ -#define MCA_SYNC_INFO_IND_EVT 0x15 - -#define MCA_CONNECT_IND_EVT 0x20 /* Control channel connected */ -#define MCA_DISCONNECT_IND_EVT 0x21 /* Control channel disconnected */ -#define MCA_OPEN_IND_EVT 0x22 /* Data channel open indication */ -#define MCA_OPEN_CFM_EVT 0x23 /* Data channel open confirm */ -#define MCA_CLOSE_IND_EVT 0x24 /* Data channel close indication */ -#define MCA_CLOSE_CFM_EVT 0x25 /* Data channel close confirm */ -#define MCA_CONG_CHG_EVT 0x26 /* congestion change event */ -#define MCA_RSP_TOUT_IND_EVT 0x27 /* Control channel message response timeout */ +#define MCA_SYNC_INFO_IND_EVT 0x15 + +#define MCA_CONNECT_IND_EVT 0x20 /* Control channel connected */ +#define MCA_DISCONNECT_IND_EVT 0x21 /* Control channel disconnected */ +#define MCA_OPEN_IND_EVT 0x22 /* Data channel open indication */ +#define MCA_OPEN_CFM_EVT 0x23 /* Data channel open confirm */ +#define MCA_CLOSE_IND_EVT 0x24 /* Data channel close indication */ +#define MCA_CLOSE_CFM_EVT 0x25 /* Data channel close confirm */ +#define MCA_CONG_CHG_EVT 0x26 /* congestion change event */ +#define MCA_RSP_TOUT_IND_EVT \ + 0x27 /* Control channel message response timeout \ + */ /***************************************************************************** * Type Definitions ****************************************************************************/ -typedef uint8_t tMCA_HANDLE; /* the handle for registration. 1 based index to rcb */ -typedef uint8_t tMCA_CL; /* the handle for a control channel; reported at MCA_CONNECT_IND_EVT */ -typedef uint8_t tMCA_DEP; /* the handle for MCA_CreateDep. This is also the local mdep_id */ -typedef uint16_t tMCA_DL; /* the handle for the data channel. This is reported at MCA_OPEN_CFM_EVT or MCA_OPEN_IND_EVT */ +typedef uint8_t + tMCA_HANDLE; /* the handle for registration. 1 based index to rcb */ +typedef uint8_t tMCA_CL; /* the handle for a control channel; reported at + MCA_CONNECT_IND_EVT */ +typedef uint8_t + tMCA_DEP; /* the handle for MCA_CreateDep. This is also the local mdep_id */ +typedef uint16_t tMCA_DL; /* the handle for the data channel. This is reported + at MCA_OPEN_CFM_EVT or MCA_OPEN_IND_EVT */ /* This is the data callback function. It is executed when MCAP has a data * packet ready for the application. */ -typedef void (tMCA_DATA_CBACK)(tMCA_DL mdl, BT_HDR *p_pkt); - +typedef void(tMCA_DATA_CBACK)(tMCA_DL mdl, BT_HDR* p_pkt); /* This structure contains parameters which are set at registration. */ typedef struct { - uint32_t rsp_tout; /* MCAP signaling response timeout */ - uint16_t ctrl_psm; /* L2CAP PSM for the MCAP control channel */ - uint16_t data_psm; /* L2CAP PSM for the MCAP data channel */ - uint16_t sec_mask; /* Security mask for BTM_SetSecurityLevel() */ + uint32_t rsp_tout; /* MCAP signaling response timeout */ + uint16_t ctrl_psm; /* L2CAP PSM for the MCAP control channel */ + uint16_t data_psm; /* L2CAP PSM for the MCAP data channel */ + uint16_t sec_mask; /* Security mask for BTM_SetSecurityLevel() */ } tMCA_REG; /* This structure contains parameters to create a MDEP. */ typedef struct { - uint8_t type; /* MCA_TDEP_DATA, or MCA_TDEP_ECHO. a regiatration may have only one MCA_TDEP_ECHO MDEP */ - uint8_t max_mdl; /* The maximum number of MDLs for this MDEP (max is MCA_NUM_MDLS) */ - tMCA_DATA_CBACK *p_data_cback; /* Data callback function */ + uint8_t type; /* MCA_TDEP_DATA, or MCA_TDEP_ECHO. a regiatration may have only + one MCA_TDEP_ECHO MDEP */ + uint8_t max_mdl; /* The maximum number of MDLs for this MDEP (max is + MCA_NUM_MDLS) */ + tMCA_DATA_CBACK* p_data_cback; /* Data callback function */ } tMCA_CS; -#define MCA_FCS_NONE 0 /* fcs_present=false */ -#define MCA_FCS_BYPASS 0x10 /* fcs_present=true, fcs=L2CAP_CFG_FCS_BYPASS */ -#define MCA_FCS_USE 0x11 /* fcs_present=true, fcs=L2CAP_CFG_FCS_USE */ -#define MCA_FCS_PRESNT_MASK 0x10 /* fcs_present=true */ -#define MCA_FCS_USE_MASK 0x01 /* mask for fcs */ +#define MCA_FCS_NONE 0 /* fcs_present=false */ +#define MCA_FCS_BYPASS 0x10 /* fcs_present=true, fcs=L2CAP_CFG_FCS_BYPASS */ +#define MCA_FCS_USE 0x11 /* fcs_present=true, fcs=L2CAP_CFG_FCS_USE */ +#define MCA_FCS_PRESNT_MASK 0x10 /* fcs_present=true */ +#define MCA_FCS_USE_MASK 0x01 /* mask for fcs */ typedef uint8_t tMCA_FCS_OPT; /* This structure contains L2CAP configuration parameters for the channel. */ typedef struct { - tL2CAP_FCR_OPTS fcr_opt; - uint16_t user_rx_buf_size; - uint16_t user_tx_buf_size; - uint16_t fcr_rx_buf_size; - uint16_t fcr_tx_buf_size; - tMCA_FCS_OPT fcs; - uint16_t data_mtu; /* L2CAP MTU of the MCAP data channel */ + tL2CAP_FCR_OPTS fcr_opt; + uint16_t user_rx_buf_size; + uint16_t user_tx_buf_size; + uint16_t fcr_rx_buf_size; + uint16_t fcr_tx_buf_size; + tMCA_FCS_OPT fcs; + uint16_t data_mtu; /* L2CAP MTU of the MCAP data channel */ } tMCA_CHNL_CFG; - /* Header structure for callback event parameters. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - uint8_t op_code; /* The op (request/response) code */ + uint16_t mdl_id; /* The associated MDL ID */ + uint8_t op_code; /* The op (request/response) code */ } tMCA_EVT_HDR; /* Response Header structure for callback event parameters. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - uint8_t op_code; /* The op (request/response) code */ - uint8_t rsp_code; /* The response code */ + uint16_t mdl_id; /* The associated MDL ID */ + uint8_t op_code; /* The op (request/response) code */ + uint8_t rsp_code; /* The response code */ } tMCA_RSP_EVT; /* This data structure is associated with the MCA_CREATE_IND_EVT. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - uint8_t op_code; /* The op (request/response) code */ - uint8_t dep_id; /* MDEP ID */ - uint8_t cfg; /* The configuration to negotiate */ + uint16_t mdl_id; /* The associated MDL ID */ + uint8_t op_code; /* The op (request/response) code */ + uint8_t dep_id; /* MDEP ID */ + uint8_t cfg; /* The configuration to negotiate */ } tMCA_CREATE_IND; /* This data structure is associated with the MCA_CREATE_CFM_EVT. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - uint8_t op_code; /* The op (request/response) code */ - uint8_t rsp_code; /* The response code. */ - uint8_t cfg; /* The configuration to negotiate */ + uint16_t mdl_id; /* The associated MDL ID */ + uint8_t op_code; /* The op (request/response) code */ + uint8_t rsp_code; /* The response code. */ + uint8_t cfg; /* The configuration to negotiate */ } tMCA_CREATE_CFM; /* This data structure is associated with MCA_CONNECT_IND_EVT. */ typedef struct { - BD_ADDR bd_addr; /* The peer address */ - uint16_t mtu; /* peer mtu */ + BD_ADDR bd_addr; /* The peer address */ + uint16_t mtu; /* peer mtu */ } tMCA_CONNECT_IND; /* This data structure is associated with MCA_DISCONNECT_IND_EVT. */ typedef struct { - BD_ADDR bd_addr; /* The peer address */ - uint16_t reason; /* disconnect reason given by L2CAP */ + BD_ADDR bd_addr; /* The peer address */ + uint16_t reason; /* disconnect reason given by L2CAP */ } tMCA_DISCONNECT_IND; /* This data structure is for MCA_OPEN_IND_EVT, and MCA_OPEN_CFM_EVT. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - tMCA_DL mdl; /* The handle for the data channel */ - uint16_t mtu; /* peer mtu */ + uint16_t mdl_id; /* The associated MDL ID */ + tMCA_DL mdl; /* The handle for the data channel */ + uint16_t mtu; /* peer mtu */ } tMCA_DL_OPEN; /* This data structure is for MCA_CLOSE_IND_EVT and MCA_CLOSE_CFM_EVT. */ typedef struct { - uint16_t mdl_id; /* The associated MDL ID */ - tMCA_DL mdl; /* The handle for the data channel */ - uint16_t reason; /* disconnect reason given by L2CAP */ + uint16_t mdl_id; /* The associated MDL ID */ + tMCA_DL mdl; /* The handle for the data channel */ + uint16_t reason; /* disconnect reason given by L2CAP */ } tMCA_DL_CLOSE; /* This data structure is associated with MCA_CONG_CHG_EVT. */ typedef struct { - uint16_t mdl_id; /* N/A - This is a place holder */ - tMCA_DL mdl; /* The handle for the data channel */ - bool cong; /* true, if the channel is congested */ + uint16_t mdl_id; /* N/A - This is a place holder */ + tMCA_DL mdl; /* The handle for the data channel */ + bool cong; /* true, if the channel is congested */ } tMCA_CONG_CHG; /* Union of all control callback event data structures */ typedef union { - tMCA_EVT_HDR hdr; - tMCA_RSP_EVT rsp; - tMCA_CREATE_IND create_ind; - tMCA_CREATE_CFM create_cfm; - tMCA_EVT_HDR reconnect_ind; - tMCA_RSP_EVT reconnect_cfm; - tMCA_EVT_HDR abort_ind; - tMCA_RSP_EVT abort_cfm; - tMCA_EVT_HDR delete_ind; - tMCA_RSP_EVT delete_cfm; - tMCA_CONNECT_IND connect_ind; - tMCA_DISCONNECT_IND disconnect_ind; - tMCA_DL_OPEN open_ind; - tMCA_DL_OPEN open_cfm; - tMCA_DL_CLOSE close_ind; - tMCA_DL_CLOSE close_cfm; - tMCA_CONG_CHG cong_chg; + tMCA_EVT_HDR hdr; + tMCA_RSP_EVT rsp; + tMCA_CREATE_IND create_ind; + tMCA_CREATE_CFM create_cfm; + tMCA_EVT_HDR reconnect_ind; + tMCA_RSP_EVT reconnect_cfm; + tMCA_EVT_HDR abort_ind; + tMCA_RSP_EVT abort_cfm; + tMCA_EVT_HDR delete_ind; + tMCA_RSP_EVT delete_cfm; + tMCA_CONNECT_IND connect_ind; + tMCA_DISCONNECT_IND disconnect_ind; + tMCA_DL_OPEN open_ind; + tMCA_DL_OPEN open_cfm; + tMCA_DL_CLOSE close_ind; + tMCA_DL_CLOSE close_cfm; + tMCA_CONG_CHG cong_chg; } tMCA_CTRL; /* This is the control callback function. This function passes control events * to the application. */ -typedef void (tMCA_CTRL_CBACK)(tMCA_HANDLE handle, tMCA_CL mcl, uint8_t event, - tMCA_CTRL *p_data); - +typedef void(tMCA_CTRL_CBACK)(tMCA_HANDLE handle, tMCA_CL mcl, uint8_t event, + tMCA_CTRL* p_data); /******************************************************************************* * @@ -256,7 +260,7 @@ extern void MCA_Init(void); * the input parameter is 0xff. * ******************************************************************************/ -extern uint8_t MCA_SetTraceLevel (uint8_t level); +extern uint8_t MCA_SetTraceLevel(uint8_t level); /******************************************************************************* * @@ -270,7 +274,7 @@ extern uint8_t MCA_SetTraceLevel (uint8_t level); * Returns 0, if failed. Otherwise, the MCA handle. * ******************************************************************************/ -extern tMCA_HANDLE MCA_Register(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback); +extern tMCA_HANDLE MCA_Register(tMCA_REG* p_reg, tMCA_CTRL_CBACK* p_cback); /******************************************************************************* * @@ -298,7 +302,8 @@ extern void MCA_Deregister(tMCA_HANDLE handle); * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern tMCA_RESULT MCA_CreateDep(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs); +extern tMCA_RESULT MCA_CreateDep(tMCA_HANDLE handle, tMCA_DEP* p_dep, + tMCA_CS* p_cs); /******************************************************************************* * @@ -332,8 +337,7 @@ extern tMCA_RESULT MCA_DeleteDep(tMCA_HANDLE handle, tMCA_DEP dep); * ******************************************************************************/ extern tMCA_RESULT MCA_ConnectReq(tMCA_HANDLE handle, BD_ADDR bd_addr, - uint16_t ctrl_psm, - uint16_t sec_mask); + uint16_t ctrl_psm, uint16_t sec_mask); /******************************************************************************* * @@ -369,7 +373,7 @@ extern tMCA_RESULT MCA_DisconnectReq(tMCA_CL mcl); ******************************************************************************/ extern tMCA_RESULT MCA_CreateMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, uint16_t mdl_id, uint8_t peer_dep_id, - uint8_t cfg, const tMCA_CHNL_CFG *p_chnl_cfg); + uint8_t cfg, const tMCA_CHNL_CFG* p_chnl_cfg); /******************************************************************************* * @@ -386,9 +390,9 @@ extern tMCA_RESULT MCA_CreateMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern tMCA_RESULT MCA_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, - uint16_t mdl_id, uint8_t cfg, uint8_t rsp_code, - const tMCA_CHNL_CFG *p_chnl_cfg); +extern tMCA_RESULT MCA_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, uint16_t mdl_id, + uint8_t cfg, uint8_t rsp_code, + const tMCA_CHNL_CFG* p_chnl_cfg); /******************************************************************************* * @@ -416,8 +420,9 @@ extern tMCA_RESULT MCA_CloseReq(tMCA_DL mdl); * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern tMCA_RESULT MCA_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, - uint16_t mdl_id, const tMCA_CHNL_CFG *p_chnl_cfg); +extern tMCA_RESULT MCA_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, + uint16_t data_psm, uint16_t mdl_id, + const tMCA_CHNL_CFG* p_chnl_cfg); /******************************************************************************* * @@ -434,7 +439,7 @@ extern tMCA_RESULT MCA_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm ******************************************************************************/ extern tMCA_RESULT MCA_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, uint16_t mdl_id, uint8_t rsp_code, - const tMCA_CHNL_CFG *p_chnl_cfg); + const tMCA_CHNL_CFG* p_chnl_cfg); /******************************************************************************* * @@ -449,7 +454,8 @@ extern tMCA_RESULT MCA_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern tMCA_RESULT MCA_DataChnlCfg(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg); +extern tMCA_RESULT MCA_DataChnlCfg(tMCA_CL mcl, + const tMCA_CHNL_CFG* p_chnl_cfg); /******************************************************************************* * @@ -496,7 +502,7 @@ extern tMCA_RESULT MCA_Delete(tMCA_CL mcl, uint16_t mdl_id); * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -extern tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR *p_pkt); +extern tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR* p_pkt); /******************************************************************************* * @@ -507,7 +513,7 @@ extern tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR *p_pkt); * Returns L2CAP channel ID if successful, otherwise 0. * ******************************************************************************/ -extern uint16_t MCA_GetL2CapChannel (tMCA_DL mdl); +extern uint16_t MCA_GetL2CapChannel(tMCA_DL mdl); #ifdef __cplusplus } diff --git a/stack/include/mca_defs.h b/stack/include/mca_defs.h index fd52a857a..a442471b3 100644 --- a/stack/include/mca_defs.h +++ b/stack/include/mca_defs.h @@ -28,87 +28,99 @@ /***************************************************************************** * constants ****************************************************************************/ -#define MCA_MIN_MTU 48 +#define MCA_MIN_MTU 48 /* standard op codes */ /* invalid opcode response */ -#define MCA_OP_ERROR_RSP 0x00 +#define MCA_OP_ERROR_RSP 0x00 /* create an MDL, wait for an associated data channel connection */ -#define MCA_OP_MDL_CREATE_REQ 0x01 +#define MCA_OP_MDL_CREATE_REQ 0x01 /* response to above request */ -#define MCA_OP_MDL_CREATE_RSP 0x02 +#define MCA_OP_MDL_CREATE_RSP 0x02 /* req to prepare to rvc a data channel conn associated with a prev MDL */ -#define MCA_OP_MDL_RECONNECT_REQ 0x03 +#define MCA_OP_MDL_RECONNECT_REQ 0x03 /* response to above request */ -#define MCA_OP_MDL_RECONNECT_RSP 0x04 +#define MCA_OP_MDL_RECONNECT_RSP 0x04 /* stop waiting for a data channel connection */ -#define MCA_OP_MDL_ABORT_REQ 0x05 +#define MCA_OP_MDL_ABORT_REQ 0x05 /* response to above request */ -#define MCA_OP_MDL_ABORT_RSP 0x06 +#define MCA_OP_MDL_ABORT_RSP 0x06 /* delete an MDL */ -#define MCA_OP_MDL_DELETE_REQ 0x07 +#define MCA_OP_MDL_DELETE_REQ 0x07 /* response to above request */ -#define MCA_OP_MDL_DELETE_RSP 0x08 -#define MCA_NUM_STANDARD_OPCODE (1+MCA_OP_MDL_DELETE_RSP) +#define MCA_OP_MDL_DELETE_RSP 0x08 +#define MCA_NUM_STANDARD_OPCODE (1 + MCA_OP_MDL_DELETE_RSP) /* clock synchronization op codes */ /* request sync capabilities & requirements */ -#define MCA_OP_SYNC_CAP_REQ 0x11 +#define MCA_OP_SYNC_CAP_REQ 0x11 /* indicate completion */ -#define MCA_OP_SYNC_CAP_RSP 0x12 +#define MCA_OP_SYNC_CAP_RSP 0x12 /* request to set the time-stamp clock */ -#define MCA_OP_SYNC_SET_REQ 0x13 +#define MCA_OP_SYNC_SET_REQ 0x13 /* indicate completion */ -#define MCA_OP_SYNC_SET_RSP 0x14 +#define MCA_OP_SYNC_SET_RSP 0x14 /* update of the actual time-stamp clock instant from the sync slave */ -#define MCA_OP_SYNC_INFO_IND 0x15 +#define MCA_OP_SYNC_INFO_IND 0x15 -#define MCA_FIRST_SYNC_OP MCA_OP_SYNC_CAP_REQ -#define MCA_LAST_SYNC_OP MCA_OP_SYNC_INFO_IND +#define MCA_FIRST_SYNC_OP MCA_OP_SYNC_CAP_REQ +#define MCA_LAST_SYNC_OP MCA_OP_SYNC_INFO_IND /* response code */ /* The corresponding request was received and processed successfully. */ -#define MCA_RSP_SUCCESS 0x00 -/* The Op Code received is not valid (i.e. neither a Standard Op Code nor a Clock Synchronization Protocol Op Code). */ -#define MCA_RSP_BAD_OPCODE 0x01 +#define MCA_RSP_SUCCESS 0x00 +/* The Op Code received is not valid (i.e. neither a Standard Op Code nor a + * Clock Synchronization Protocol Op Code). */ +#define MCA_RSP_BAD_OPCODE 0x01 /* One or more of the values in the received request is invalid. */ -#define MCA_RSP_BAD_PARAM 0x02 +#define MCA_RSP_BAD_PARAM 0x02 /* MCA_RSP_BAD_PARAM shall be used when: - The request length is invalid -- Some of the parameters have invalid values and none of the other defined Response Codes are more appropriate. +- Some of the parameters have invalid values and none of the other defined +Response Codes are more appropriate. */ /* The MDEP ID referenced does not exist on this device. */ -#define MCA_RSP_BAD_MDEP 0x03 -/* The requested MDEP currently has as many active MDLs as it can manage simultaneously. */ -#define MCA_RSP_MDEP_BUSY 0x04 +#define MCA_RSP_BAD_MDEP 0x03 +/* The requested MDEP currently has as many active MDLs as it can manage + * simultaneously. */ +#define MCA_RSP_MDEP_BUSY 0x04 /* The MDL ID referenced is invalid. */ -#define MCA_RSP_BAD_MDL 0x05 +#define MCA_RSP_BAD_MDL 0x05 /* MCA_RSP_BAD_MDL shall be used when: - A reserved or invalid value for MDL ID was used. -- The MDL ID referenced is not available (was never created, has been deleted, or was otherwise lost), -- The MDL ID referenced in the Abort request is not the same value that was used to initiate the PENDING state +- The MDL ID referenced is not available (was never created, has been deleted, +or was otherwise lost), +- The MDL ID referenced in the Abort request is not the same value that was used +to initiate the PENDING state */ -/* The device is temporarily unable to complete the request. This is intended for reasons not related to the physical sensor (e.g. communication resources unavailable). */ -#define MCA_RSP_MDL_BUSY 0x06 +/* The device is temporarily unable to complete the request. This is intended + * for reasons not related to the physical sensor (e.g. communication resources + * unavailable). */ +#define MCA_RSP_MDL_BUSY 0x06 /* The received request is invalid in the current state. */ -#define MCA_RSP_BAD_OP 0x07 +#define MCA_RSP_BAD_OP 0x07 /* MCA_RSP_BAD_OP is used when - Abort request was received while not in the PENDING state. - Create, Reconnect, or Delete request was received while in the PENDING state. - A response is received when a request is expected */ -/* The device is temporarily unable to complete the request. This is intended for reasons relating to the physical sensor (e.g. hardware fault, low battery), or when processing resources are temporarily committed to other processes. */ +/* The device is temporarily unable to complete the request. This is intended + * for reasons relating to the physical sensor (e.g. hardware fault, low + * battery), or when processing resources are temporarily committed to other + * processes. */ #define MCA_RSP_NO_RESOURCE 0x08 -/* An internal error other than those listed in this table was encountered while processing the request. */ -#define MCA_RSP_ERROR 0x09 +/* An internal error other than those listed in this table was encountered while + * processing the request. */ +#define MCA_RSP_ERROR 0x09 /* The Op Code that was used in this request is not supported. */ -#define MCA_RSP_NO_SUPPORT 0x0A -/* A configuration required by a MD_CREATE_MDL or MD_RECONNECT_MDL operation has been rejected. */ -#define MCA_RSP_CFG_REJ 0x0B +#define MCA_RSP_NO_SUPPORT 0x0A +/* A configuration required by a MD_CREATE_MDL or MD_RECONNECT_MDL operation has + * been rejected. */ +#define MCA_RSP_CFG_REJ 0x0B /* the valid range for MDEP ID is 1-0x7F */ -#define MCA_MAX_MDEP_ID 0x7F -#define MCA_IS_VALID_MDL_ID(xxx) (((xxx)>0) && ((xxx)<=0xFEFF)) -#define MCA_ALL_MDL_ID 0xFFFF +#define MCA_MAX_MDEP_ID 0x7F +#define MCA_IS_VALID_MDL_ID(xxx) (((xxx) > 0) && ((xxx) <= 0xFEFF)) +#define MCA_ALL_MDL_ID 0xFFFF #endif /* MCA_DEFS_H */ diff --git a/stack/include/pan_api.h b/stack/include/pan_api.h index 32fdc223e..f220e3d7d 100644 --- a/stack/include/pan_api.h +++ b/stack/include/pan_api.h @@ -39,57 +39,59 @@ extern "C" { * extension headers, but may in the future, so allow * space for them */ -#define PAN_MINIMUM_OFFSET BNEP_MINIMUM_OFFSET - +#define PAN_MINIMUM_OFFSET BNEP_MINIMUM_OFFSET /* * The handle is passed from BNEP to PAN. The same handle is used * between PAN and application as well */ -#define PAN_INVALID_HANDLE BNEP_INVALID_HANDLE +#define PAN_INVALID_HANDLE BNEP_INVALID_HANDLE /* Bit map for PAN roles */ -#define PAN_ROLE_CLIENT 0x01 /* PANU role */ -#define PAN_ROLE_GN_SERVER 0x02 /* GN role */ -#define PAN_ROLE_NAP_SERVER 0x04 /* NAP role */ +#define PAN_ROLE_CLIENT 0x01 /* PANU role */ +#define PAN_ROLE_GN_SERVER 0x02 /* GN role */ +#define PAN_ROLE_NAP_SERVER 0x04 /* NAP role */ /* Bitmap to indicate the usage of the Data */ -#define PAN_DATA_TO_HOST 0x01 -#define PAN_DATA_TO_LAN 0x02 - +#define PAN_DATA_TO_HOST 0x01 +#define PAN_DATA_TO_LAN 0x02 /***************************************************************************** * Type Definitions ****************************************************************************/ /* Define the result codes from PAN */ -enum -{ - PAN_SUCCESS, /* Success */ - PAN_DISCONNECTED = BNEP_CONN_DISCONNECTED, /* Connection terminated */ - PAN_CONN_FAILED = BNEP_CONN_FAILED, /* Connection failed */ - PAN_NO_RESOURCES = BNEP_NO_RESOURCES, /* No resources */ - PAN_MTU_EXCEDED = BNEP_MTU_EXCEDED, /* Attempt to write long data */ - PAN_INVALID_OFFSET = BNEP_INVALID_OFFSET, /* Insufficient offset in GKI buffer */ - PAN_CONN_FAILED_CFG = BNEP_CONN_FAILED_CFG, /* Connection failed cos of config */ - PAN_INVALID_SRC_ROLE = BNEP_CONN_FAILED_SRC_UUID, /* Connection failed wrong source UUID */ - PAN_INVALID_DST_ROLE = BNEP_CONN_FAILED_DST_UUID, /* Connection failed wrong destination UUID */ - PAN_CONN_FAILED_UUID_SIZE = BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID */ - PAN_Q_SIZE_EXCEEDED = BNEP_Q_SIZE_EXCEEDED, /* Too many buffers to dest */ - PAN_TOO_MANY_FILTERS = BNEP_TOO_MANY_FILTERS, /* Too many local filters specified */ - PAN_SET_FILTER_FAIL = BNEP_SET_FILTER_FAIL, /* Set Filter failed */ - PAN_WRONG_HANDLE = BNEP_WRONG_HANDLE, /* Wrong handle for the connection */ - PAN_WRONG_STATE = BNEP_WRONG_STATE, /* Connection is in wrong state */ - PAN_SECURITY_FAIL = BNEP_SECURITY_FAIL, /* Failed because of security */ - PAN_IGNORE_CMD = BNEP_IGNORE_CMD, /* To ignore the rcvd command */ - PAN_TX_FLOW_ON = BNEP_TX_FLOW_ON, /* tx data flow enabled */ - PAN_TX_FLOW_OFF = BNEP_TX_FLOW_OFF, /* tx data flow disabled */ - PAN_FAILURE /* Failure */ +enum { + PAN_SUCCESS, /* Success */ + PAN_DISCONNECTED = BNEP_CONN_DISCONNECTED, /* Connection terminated */ + PAN_CONN_FAILED = BNEP_CONN_FAILED, /* Connection failed */ + PAN_NO_RESOURCES = BNEP_NO_RESOURCES, /* No resources */ + PAN_MTU_EXCEDED = BNEP_MTU_EXCEDED, /* Attempt to write long data */ + PAN_INVALID_OFFSET = + BNEP_INVALID_OFFSET, /* Insufficient offset in GKI buffer */ + PAN_CONN_FAILED_CFG = + BNEP_CONN_FAILED_CFG, /* Connection failed cos of config */ + PAN_INVALID_SRC_ROLE = + BNEP_CONN_FAILED_SRC_UUID, /* Connection failed wrong source UUID */ + PAN_INVALID_DST_ROLE = + BNEP_CONN_FAILED_DST_UUID, /* Connection failed wrong destination UUID */ + PAN_CONN_FAILED_UUID_SIZE = + BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID */ + PAN_Q_SIZE_EXCEEDED = BNEP_Q_SIZE_EXCEEDED, /* Too many buffers to dest */ + PAN_TOO_MANY_FILTERS = + BNEP_TOO_MANY_FILTERS, /* Too many local filters specified */ + PAN_SET_FILTER_FAIL = BNEP_SET_FILTER_FAIL, /* Set Filter failed */ + PAN_WRONG_HANDLE = BNEP_WRONG_HANDLE, /* Wrong handle for the connection */ + PAN_WRONG_STATE = BNEP_WRONG_STATE, /* Connection is in wrong state */ + PAN_SECURITY_FAIL = BNEP_SECURITY_FAIL, /* Failed because of security */ + PAN_IGNORE_CMD = BNEP_IGNORE_CMD, /* To ignore the rcvd command */ + PAN_TX_FLOW_ON = BNEP_TX_FLOW_ON, /* tx data flow enabled */ + PAN_TX_FLOW_OFF = BNEP_TX_FLOW_OFF, /* tx data flow disabled */ + PAN_FAILURE /* Failure */ }; typedef uint8_t tPAN_RESULT; - /***************************************************************** * Callback Function Prototypes ****************************************************************/ @@ -98,17 +100,16 @@ typedef uint8_t tPAN_RESULT; * to the application. The second parameter true means * to create the bridge and false means to remove it. */ -typedef void (tPAN_CONN_STATE_CB) (uint16_t handle, BD_ADDR bd_addr, tPAN_RESULT state, bool is_role_change, - uint8_t src_role, uint8_t dst_role); - +typedef void(tPAN_CONN_STATE_CB)(uint16_t handle, BD_ADDR bd_addr, + tPAN_RESULT state, bool is_role_change, + uint8_t src_role, uint8_t dst_role); /* This is call back function used to create bridge for the * Connected device. The parameter "state" indicates * whether to create the bridge or remove it. true means * to create the bridge and false means to remove it. */ -typedef void (tPAN_BRIDGE_REQ_CB) (BD_ADDR bd_addr, bool state); - +typedef void(tPAN_BRIDGE_REQ_CB)(BD_ADDR bd_addr, bool state); /* Data received indication callback prototype. Parameters are * Source BD/Ethernet Address @@ -121,15 +122,9 @@ typedef void (tPAN_BRIDGE_REQ_CB) (BD_ADDR bd_addr, bool state); * false - Use it for internal stack * true - Send it across the ethernet as well */ -typedef void (tPAN_DATA_IND_CB) (uint16_t handle, - BD_ADDR src, - BD_ADDR dst, - uint16_t protocol, - uint8_t *p_data, - uint16_t len, - bool ext, - bool forward); - +typedef void(tPAN_DATA_IND_CB)(uint16_t handle, BD_ADDR src, BD_ADDR dst, + uint16_t protocol, uint8_t* p_data, uint16_t len, + bool ext, bool forward); /* Data buffer received indication callback prototype. Parameters are * Source BD/Ethernet Address @@ -141,21 +136,15 @@ typedef void (tPAN_DATA_IND_CB) (uint16_t handle, * false - Use it for internal stack * true - Send it across the ethernet as well */ -typedef void (tPAN_DATA_BUF_IND_CB) (uint16_t handle, - BD_ADDR src, - BD_ADDR dst, - uint16_t protocol, - BT_HDR *p_buf, - bool ext, - bool forward); - +typedef void(tPAN_DATA_BUF_IND_CB)(uint16_t handle, BD_ADDR src, BD_ADDR dst, + uint16_t protocol, BT_HDR* p_buf, bool ext, + bool forward); /* Flow control callback for TX data. Parameters are * Handle to the connection * Event flow status */ -typedef void (tPAN_TX_DATA_FLOW_CB) (uint16_t handle, - tPAN_RESULT event); +typedef void(tPAN_TX_DATA_FLOW_CB)(uint16_t handle, tPAN_RESULT event); /* Filters received indication callback prototype. Parameters are * Handle to the connection @@ -170,13 +159,9 @@ typedef void (tPAN_TX_DATA_FLOW_CB) (uint16_t handle, * two bytes will be starting of the first range and * next two bytes will be ending of the range. */ -typedef void (tPAN_FILTER_IND_CB) (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters); - - +typedef void(tPAN_FILTER_IND_CB)(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters); /* Multicast Filters received indication callback prototype. Parameters are * Handle to the connection @@ -190,34 +175,30 @@ typedef void (tPAN_FILTER_IND_CB) (uint16_t handle, * First six bytes will be starting of the first range and * next six bytes will be ending of the range. */ -typedef void (tPAN_MFILTER_IND_CB) (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_mfilters, - uint8_t *p_mfilters); - - - +typedef void(tPAN_MFILTER_IND_CB)(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_mfilters, + uint8_t* p_mfilters); /* This structure is used to register with PAN profile * It is passed as a parameter to PAN_Register call. */ -typedef struct -{ - tPAN_CONN_STATE_CB *pan_conn_state_cb; /* Connection state callback */ - tPAN_BRIDGE_REQ_CB *pan_bridge_req_cb; /* Bridge request callback */ - tPAN_DATA_IND_CB *pan_data_ind_cb; /* Data indication callback */ - tPAN_DATA_BUF_IND_CB *pan_data_buf_ind_cb; /* Data buffer indication callback */ - tPAN_FILTER_IND_CB *pan_pfilt_ind_cb; /* protocol filter indication callback */ - tPAN_MFILTER_IND_CB *pan_mfilt_ind_cb; /* multicast filter indication callback */ - tPAN_TX_DATA_FLOW_CB *pan_tx_data_flow_cb; /* data flow callback */ - char *user_service_name; /* Service name for PANU role */ - char *gn_service_name; /* Service name for GN role */ - char *nap_service_name; /* Service name for NAP role */ +typedef struct { + tPAN_CONN_STATE_CB* pan_conn_state_cb; /* Connection state callback */ + tPAN_BRIDGE_REQ_CB* pan_bridge_req_cb; /* Bridge request callback */ + tPAN_DATA_IND_CB* pan_data_ind_cb; /* Data indication callback */ + tPAN_DATA_BUF_IND_CB* + pan_data_buf_ind_cb; /* Data buffer indication callback */ + tPAN_FILTER_IND_CB* + pan_pfilt_ind_cb; /* protocol filter indication callback */ + tPAN_MFILTER_IND_CB* + pan_mfilt_ind_cb; /* multicast filter indication callback */ + tPAN_TX_DATA_FLOW_CB* pan_tx_data_flow_cb; /* data flow callback */ + char* user_service_name; /* Service name for PANU role */ + char* gn_service_name; /* Service name for GN role */ + char* nap_service_name; /* Service name for NAP role */ } tPAN_REGISTER; - /***************************************************************************** * External Function Declarations ****************************************************************************/ @@ -236,8 +217,7 @@ typedef struct * Returns none * ******************************************************************************/ -extern void PAN_Register (tPAN_REGISTER *p_register); - +extern void PAN_Register(tPAN_REGISTER* p_register); /******************************************************************************* * @@ -251,7 +231,7 @@ extern void PAN_Register (tPAN_REGISTER *p_register); * Returns none * ******************************************************************************/ -extern void PAN_Deregister (void); +extern void PAN_Deregister(void); /******************************************************************************* * @@ -279,11 +259,9 @@ extern void PAN_Deregister (void); * PAN_FAILURE - if the role is not valid * ******************************************************************************/ -extern tPAN_RESULT PAN_SetRole (uint8_t role, - uint8_t *sec_mask, - const char *p_user_name, - const char *p_gn_name, - const char *p_nap_name); +extern tPAN_RESULT PAN_SetRole(uint8_t role, uint8_t* sec_mask, + const char* p_user_name, const char* p_gn_name, + const char* p_nap_name); /******************************************************************************* * @@ -308,7 +286,8 @@ extern tPAN_RESULT PAN_SetRole (uint8_t role, * allowed at that point of time * ******************************************************************************/ -extern tPAN_RESULT PAN_Connect (BD_ADDR rem_bda, uint8_t src_role, uint8_t dst_role, uint16_t *handle); +extern tPAN_RESULT PAN_Connect(BD_ADDR rem_bda, uint8_t src_role, + uint8_t dst_role, uint16_t* handle); /******************************************************************************* * @@ -323,7 +302,7 @@ extern tPAN_RESULT PAN_Connect (BD_ADDR rem_bda, uint8_t src_role, uint8_t dst_r * there is an error in disconnecting * ******************************************************************************/ -extern tPAN_RESULT PAN_Disconnect (uint16_t handle); +extern tPAN_RESULT PAN_Disconnect(uint16_t handle); /******************************************************************************* * @@ -348,13 +327,9 @@ extern tPAN_RESULT PAN_Disconnect (uint16_t handle); * there is an error in sending data * ******************************************************************************/ -extern tPAN_RESULT PAN_Write (uint16_t handle, - BD_ADDR dst, - BD_ADDR src, - uint16_t protocol, - uint8_t *p_data, - uint16_t len, - bool ext); +extern tPAN_RESULT PAN_Write(uint16_t handle, BD_ADDR dst, BD_ADDR src, + uint16_t protocol, uint8_t* p_data, uint16_t len, + bool ext); /******************************************************************************* * @@ -378,12 +353,8 @@ extern tPAN_RESULT PAN_Write (uint16_t handle, * there is an error in sending data * ******************************************************************************/ -extern tPAN_RESULT PAN_WriteBuf (uint16_t handle, - BD_ADDR dst, - BD_ADDR src, - uint16_t protocol, - BT_HDR *p_buf, - bool ext); +extern tPAN_RESULT PAN_WriteBuf(uint16_t handle, BD_ADDR dst, BD_ADDR src, + uint16_t protocol, BT_HDR* p_buf, bool ext); /******************************************************************************* * @@ -401,10 +372,9 @@ extern tPAN_RESULT PAN_WriteBuf (uint16_t handle, * PAN_FAILURE if connection not found or error in setting * ******************************************************************************/ -extern tPAN_RESULT PAN_SetProtocolFilters (uint16_t handle, - uint16_t num_filters, - uint16_t *p_start_array, - uint16_t *p_end_array); +extern tPAN_RESULT PAN_SetProtocolFilters(uint16_t handle, uint16_t num_filters, + uint16_t* p_start_array, + uint16_t* p_end_array); /******************************************************************************* * @@ -424,10 +394,10 @@ extern tPAN_RESULT PAN_SetProtocolFilters (uint16_t handle, * PAN_FAILURE if connection not found or error in setting * ******************************************************************************/ -extern tBNEP_RESULT PAN_SetMulticastFilters (uint16_t handle, - uint16_t num_mcast_filters, - uint8_t *p_start_array, - uint8_t *p_end_array); +extern tBNEP_RESULT PAN_SetMulticastFilters(uint16_t handle, + uint16_t num_mcast_filters, + uint8_t* p_start_array, + uint8_t* p_end_array); /******************************************************************************* * @@ -439,7 +409,7 @@ extern tBNEP_RESULT PAN_SetMulticastFilters (uint16_t handle, * Returns the new (current) trace level * ******************************************************************************/ -extern uint8_t PAN_SetTraceLevel (uint8_t new_level); +extern uint8_t PAN_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -452,10 +422,10 @@ extern uint8_t PAN_SetTraceLevel (uint8_t new_level); * Returns void * ******************************************************************************/ -extern void PAN_Init (void); +extern void PAN_Init(void); #ifdef __cplusplus } #endif -#endif /* PAN_API_H */ +#endif /* PAN_API_H */ diff --git a/stack/include/port_api.h b/stack/include/port_api.h index 3b89f2c27..15aea9ff8 100644 --- a/stack/include/port_api.h +++ b/stack/include/port_api.h @@ -38,151 +38,149 @@ extern "C" { * Define port settings structure send from the application in the * set settings request, or to the application in the set settings indication. */ -typedef struct -{ - -#define PORT_BAUD_RATE_2400 0x00 -#define PORT_BAUD_RATE_4800 0x01 -#define PORT_BAUD_RATE_7200 0x02 -#define PORT_BAUD_RATE_9600 0x03 -#define PORT_BAUD_RATE_19200 0x04 -#define PORT_BAUD_RATE_38400 0x05 -#define PORT_BAUD_RATE_57600 0x06 -#define PORT_BAUD_RATE_115200 0x07 -#define PORT_BAUD_RATE_230400 0x08 - - uint8_t baud_rate; - -#define PORT_5_BITS 0x00 -#define PORT_6_BITS 0x01 -#define PORT_7_BITS 0x02 -#define PORT_8_BITS 0x03 - - uint8_t byte_size; - -#define PORT_ONESTOPBIT 0x00 -#define PORT_ONE5STOPBITS 0x01 - uint8_t stop_bits; - -#define PORT_PARITY_NO 0x00 -#define PORT_PARITY_YES 0x01 - uint8_t parity; - -#define PORT_ODD_PARITY 0x00 -#define PORT_EVEN_PARITY 0x01 -#define PORT_MARK_PARITY 0x02 -#define PORT_SPACE_PARITY 0x03 - - uint8_t parity_type; - -#define PORT_FC_OFF 0x00 -#define PORT_FC_XONXOFF_ON_INPUT 0x01 +typedef struct { +#define PORT_BAUD_RATE_2400 0x00 +#define PORT_BAUD_RATE_4800 0x01 +#define PORT_BAUD_RATE_7200 0x02 +#define PORT_BAUD_RATE_9600 0x03 +#define PORT_BAUD_RATE_19200 0x04 +#define PORT_BAUD_RATE_38400 0x05 +#define PORT_BAUD_RATE_57600 0x06 +#define PORT_BAUD_RATE_115200 0x07 +#define PORT_BAUD_RATE_230400 0x08 + + uint8_t baud_rate; + +#define PORT_5_BITS 0x00 +#define PORT_6_BITS 0x01 +#define PORT_7_BITS 0x02 +#define PORT_8_BITS 0x03 + + uint8_t byte_size; + +#define PORT_ONESTOPBIT 0x00 +#define PORT_ONE5STOPBITS 0x01 + uint8_t stop_bits; + +#define PORT_PARITY_NO 0x00 +#define PORT_PARITY_YES 0x01 + uint8_t parity; + +#define PORT_ODD_PARITY 0x00 +#define PORT_EVEN_PARITY 0x01 +#define PORT_MARK_PARITY 0x02 +#define PORT_SPACE_PARITY 0x03 + + uint8_t parity_type; + +#define PORT_FC_OFF 0x00 +#define PORT_FC_XONXOFF_ON_INPUT 0x01 #define PORT_FC_XONXOFF_ON_OUTPUT 0x02 -#define PORT_FC_CTS_ON_INPUT 0x04 -#define PORT_FC_CTS_ON_OUTPUT 0x08 -#define PORT_FC_DSR_ON_INPUT 0x10 -#define PORT_FC_DSR_ON_OUTPUT 0x20 +#define PORT_FC_CTS_ON_INPUT 0x04 +#define PORT_FC_CTS_ON_OUTPUT 0x08 +#define PORT_FC_DSR_ON_INPUT 0x10 +#define PORT_FC_DSR_ON_OUTPUT 0x20 - uint8_t fc_type; + uint8_t fc_type; - uint8_t rx_char1; + uint8_t rx_char1; -#define PORT_XON_DC1 0x11 - uint8_t xon_char; +#define PORT_XON_DC1 0x11 + uint8_t xon_char; -#define PORT_XOFF_DC3 0x13 - uint8_t xoff_char; +#define PORT_XOFF_DC3 0x13 + uint8_t xoff_char; } tPORT_STATE; - /* * Define the callback function prototypes. Parameters are specific * to each event and are described bellow */ -typedef int (tPORT_DATA_CALLBACK) (uint16_t port_handle, void *p_data, uint16_t len); +typedef int(tPORT_DATA_CALLBACK)(uint16_t port_handle, void* p_data, + uint16_t len); -#define DATA_CO_CALLBACK_TYPE_INCOMING 1 -#define DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE 2 -#define DATA_CO_CALLBACK_TYPE_OUTGOING 3 -typedef int (tPORT_DATA_CO_CALLBACK) (uint16_t port_handle, uint8_t* p_buf, uint16_t len, int type); +#define DATA_CO_CALLBACK_TYPE_INCOMING 1 +#define DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE 2 +#define DATA_CO_CALLBACK_TYPE_OUTGOING 3 +typedef int(tPORT_DATA_CO_CALLBACK)(uint16_t port_handle, uint8_t* p_buf, + uint16_t len, int type); -typedef void (tPORT_CALLBACK) (uint32_t code, uint16_t port_handle); +typedef void(tPORT_CALLBACK)(uint32_t code, uint16_t port_handle); /* * Define events that registered application can receive in the callback */ -#define PORT_EV_RXCHAR 0x00000001 /* Any Character received */ -#define PORT_EV_RXFLAG 0x00000002 /* Received certain character */ -#define PORT_EV_TXEMPTY 0x00000004 /* Transmitt Queue Empty */ -#define PORT_EV_CTS 0x00000008 /* CTS changed state */ -#define PORT_EV_DSR 0x00000010 /* DSR changed state */ -#define PORT_EV_RLSD 0x00000020 /* RLSD changed state */ -#define PORT_EV_BREAK 0x00000040 /* BREAK received */ -#define PORT_EV_ERR 0x00000080 /* Line status error occurred */ -#define PORT_EV_RING 0x00000100 /* Ring signal detected */ -#define PORT_EV_CTSS 0x00000400 /* CTS state */ -#define PORT_EV_DSRS 0x00000800 /* DSR state */ -#define PORT_EV_RLSDS 0x00001000 /* RLSD state */ -#define PORT_EV_OVERRUN 0x00002000 /* receiver buffer overrun */ -#define PORT_EV_TXCHAR 0x00004000 /* Any character transmitted */ +#define PORT_EV_RXCHAR 0x00000001 /* Any Character received */ +#define PORT_EV_RXFLAG 0x00000002 /* Received certain character */ +#define PORT_EV_TXEMPTY 0x00000004 /* Transmitt Queue Empty */ +#define PORT_EV_CTS 0x00000008 /* CTS changed state */ +#define PORT_EV_DSR 0x00000010 /* DSR changed state */ +#define PORT_EV_RLSD 0x00000020 /* RLSD changed state */ +#define PORT_EV_BREAK 0x00000040 /* BREAK received */ +#define PORT_EV_ERR 0x00000080 /* Line status error occurred */ +#define PORT_EV_RING 0x00000100 /* Ring signal detected */ +#define PORT_EV_CTSS 0x00000400 /* CTS state */ +#define PORT_EV_DSRS 0x00000800 /* DSR state */ +#define PORT_EV_RLSDS 0x00001000 /* RLSD state */ +#define PORT_EV_OVERRUN 0x00002000 /* receiver buffer overrun */ +#define PORT_EV_TXCHAR 0x00004000 /* Any character transmitted */ /* RFCOMM connection established */ -#define PORT_EV_CONNECTED 0x00000200 +#define PORT_EV_CONNECTED 0x00000200 /* Unable to establish connection or disconnected */ -#define PORT_EV_CONNECT_ERR 0x00008000 +#define PORT_EV_CONNECT_ERR 0x00008000 /* data flow enabled flag changed by remote */ -#define PORT_EV_FC 0x00010000 +#define PORT_EV_FC 0x00010000 /* data flow enable status true = enabled */ -#define PORT_EV_FCS 0x00020000 +#define PORT_EV_FCS 0x00020000 /* * To register for events application should provide bitmask with * corresponding bit set */ -#define PORT_MASK_ALL (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_CTS | \ - PORT_EV_DSR | PORT_EV_RLSD | PORT_EV_BREAK | \ - PORT_EV_ERR | PORT_EV_RING | PORT_EV_CONNECT_ERR | \ - PORT_EV_DSRS | PORT_EV_CTSS | PORT_EV_RLSDS | \ - PORT_EV_RXFLAG | PORT_EV_TXCHAR | PORT_EV_OVERRUN | \ - PORT_EV_FC | PORT_EV_FCS | PORT_EV_CONNECTED) - +#define PORT_MASK_ALL \ + (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_CTS | PORT_EV_DSR | \ + PORT_EV_RLSD | PORT_EV_BREAK | PORT_EV_ERR | PORT_EV_RING | \ + PORT_EV_CONNECT_ERR | PORT_EV_DSRS | PORT_EV_CTSS | PORT_EV_RLSDS | \ + PORT_EV_RXFLAG | PORT_EV_TXCHAR | PORT_EV_OVERRUN | PORT_EV_FC | \ + PORT_EV_FCS | PORT_EV_CONNECTED) /* * Define port result codes */ -#define PORT_SUCCESS 0 - -#define PORT_ERR_BASE 0 - -#define PORT_UNKNOWN_ERROR (PORT_ERR_BASE + 1) -#define PORT_ALREADY_OPENED (PORT_ERR_BASE + 2) -#define PORT_CMD_PENDING (PORT_ERR_BASE + 3) -#define PORT_APP_NOT_REGISTERED (PORT_ERR_BASE + 4) -#define PORT_NO_MEM (PORT_ERR_BASE + 5) -#define PORT_NO_RESOURCES (PORT_ERR_BASE + 6) -#define PORT_BAD_BD_ADDR (PORT_ERR_BASE + 7) -#define PORT_BAD_HANDLE (PORT_ERR_BASE + 9) -#define PORT_NOT_OPENED (PORT_ERR_BASE + 10) -#define PORT_LINE_ERR (PORT_ERR_BASE + 11) -#define PORT_START_FAILED (PORT_ERR_BASE + 12) -#define PORT_PAR_NEG_FAILED (PORT_ERR_BASE + 13) -#define PORT_PORT_NEG_FAILED (PORT_ERR_BASE + 14) -#define PORT_SEC_FAILED (PORT_ERR_BASE + 15) +#define PORT_SUCCESS 0 + +#define PORT_ERR_BASE 0 + +#define PORT_UNKNOWN_ERROR (PORT_ERR_BASE + 1) +#define PORT_ALREADY_OPENED (PORT_ERR_BASE + 2) +#define PORT_CMD_PENDING (PORT_ERR_BASE + 3) +#define PORT_APP_NOT_REGISTERED (PORT_ERR_BASE + 4) +#define PORT_NO_MEM (PORT_ERR_BASE + 5) +#define PORT_NO_RESOURCES (PORT_ERR_BASE + 6) +#define PORT_BAD_BD_ADDR (PORT_ERR_BASE + 7) +#define PORT_BAD_HANDLE (PORT_ERR_BASE + 9) +#define PORT_NOT_OPENED (PORT_ERR_BASE + 10) +#define PORT_LINE_ERR (PORT_ERR_BASE + 11) +#define PORT_START_FAILED (PORT_ERR_BASE + 12) +#define PORT_PAR_NEG_FAILED (PORT_ERR_BASE + 13) +#define PORT_PORT_NEG_FAILED (PORT_ERR_BASE + 14) +#define PORT_SEC_FAILED (PORT_ERR_BASE + 15) #define PORT_PEER_CONNECTION_FAILED (PORT_ERR_BASE + 16) -#define PORT_PEER_FAILED (PORT_ERR_BASE + 17) -#define PORT_PEER_TIMEOUT (PORT_ERR_BASE + 18) -#define PORT_CLOSED (PORT_ERR_BASE + 19) -#define PORT_TX_FULL (PORT_ERR_BASE + 20) -#define PORT_LOCAL_CLOSED (PORT_ERR_BASE + 21) -#define PORT_LOCAL_TIMEOUT (PORT_ERR_BASE + 22) -#define PORT_TX_QUEUE_DISABLED (PORT_ERR_BASE + 23) -#define PORT_PAGE_TIMEOUT (PORT_ERR_BASE + 24) -#define PORT_INVALID_SCN (PORT_ERR_BASE + 25) - -#define PORT_ERR_MAX (PORT_ERR_BASE + 26) +#define PORT_PEER_FAILED (PORT_ERR_BASE + 17) +#define PORT_PEER_TIMEOUT (PORT_ERR_BASE + 18) +#define PORT_CLOSED (PORT_ERR_BASE + 19) +#define PORT_TX_FULL (PORT_ERR_BASE + 20) +#define PORT_LOCAL_CLOSED (PORT_ERR_BASE + 21) +#define PORT_LOCAL_TIMEOUT (PORT_ERR_BASE + 22) +#define PORT_TX_QUEUE_DISABLED (PORT_ERR_BASE + 23) +#define PORT_PAGE_TIMEOUT (PORT_ERR_BASE + 24) +#define PORT_INVALID_SCN (PORT_ERR_BASE + 25) + +#define PORT_ERR_MAX (PORT_ERR_BASE + 26) /***************************************************************************** * External Function Declarations @@ -219,11 +217,10 @@ typedef void (tPORT_CALLBACK) (uint32_t code, uint16_t port_handle); * (scn * 2 + 1) dlci. * ******************************************************************************/ -extern int RFCOMM_CreateConnection (uint16_t uuid, uint8_t scn, - bool is_server, uint16_t mtu, - BD_ADDR bd_addr, uint16_t *p_handle, - tPORT_CALLBACK *p_mgmt_cb); - +extern int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server, + uint16_t mtu, BD_ADDR bd_addr, + uint16_t* p_handle, + tPORT_CALLBACK* p_mgmt_cb); /******************************************************************************* * @@ -234,8 +231,7 @@ extern int RFCOMM_CreateConnection (uint16_t uuid, uint8_t scn, * Parameters: handle - Handle of the port returned in the Open * ******************************************************************************/ -extern int RFCOMM_RemoveConnection (uint16_t handle); - +extern int RFCOMM_RemoveConnection(uint16_t handle); /******************************************************************************* * @@ -246,8 +242,7 @@ extern int RFCOMM_RemoveConnection (uint16_t handle); * Parameters: handle - Handle returned in the RFCOMM_CreateConnection * ******************************************************************************/ -extern int RFCOMM_RemoveServer (uint16_t handle); - +extern int RFCOMM_RemoveServer(uint16_t handle); /******************************************************************************* * @@ -261,8 +256,8 @@ extern int RFCOMM_RemoveServer (uint16_t handle); * specified in the mask occurs. * ******************************************************************************/ -extern int PORT_SetEventCallback (uint16_t port_handle, - tPORT_CALLBACK *p_port_cb); +extern int PORT_SetEventCallback(uint16_t port_handle, + tPORT_CALLBACK* p_port_cb); /******************************************************************************* * @@ -274,7 +269,7 @@ extern int PORT_SetEventCallback (uint16_t port_handle, * Parameters: handle - Handle returned in the RFCOMM_CreateConnection * ******************************************************************************/ -int PORT_ClearKeepHandleFlag (uint16_t port_handle); +int PORT_ClearKeepHandleFlag(uint16_t port_handle); /******************************************************************************* * @@ -288,10 +283,11 @@ int PORT_ClearKeepHandleFlag (uint16_t port_handle); * packet is received. * ******************************************************************************/ -extern int PORT_SetDataCallback (uint16_t port_handle, - tPORT_DATA_CALLBACK *p_cb); +extern int PORT_SetDataCallback(uint16_t port_handle, + tPORT_DATA_CALLBACK* p_cb); -extern int PORT_SetDataCOCallback (uint16_t port_handle, tPORT_DATA_CO_CALLBACK *p_port_cb); +extern int PORT_SetDataCOCallback(uint16_t port_handle, + tPORT_DATA_CO_CALLBACK* p_port_cb); /******************************************************************************* * * Function PORT_SetEventMask @@ -303,8 +299,7 @@ extern int PORT_SetDataCOCallback (uint16_t port_handle, tPORT_DATA_CO_CALLBACK * of zero disables all events. * ******************************************************************************/ -extern int PORT_SetEventMask (uint16_t port_handle, uint32_t mask); - +extern int PORT_SetEventMask(uint16_t port_handle, uint32_t mask); /******************************************************************************* * @@ -318,8 +313,8 @@ extern int PORT_SetEventMask (uint16_t port_handle, uint32_t mask); * p_lcid - OUT L2CAP's LCID * ******************************************************************************/ -extern int PORT_CheckConnection (uint16_t handle, BD_ADDR bd_addr, - uint16_t *p_lcid); +extern int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, + uint16_t* p_lcid); /******************************************************************************* * @@ -332,7 +327,7 @@ extern int PORT_CheckConnection (uint16_t handle, BD_ADDR bd_addr, * bd_addr - bd_addr of the peer * ******************************************************************************/ -extern bool PORT_IsOpening (BD_ADDR bd_addr); +extern bool PORT_IsOpening(BD_ADDR bd_addr); /******************************************************************************* * @@ -346,7 +341,7 @@ extern bool PORT_IsOpening (BD_ADDR bd_addr); * configuration information for the connection. * ******************************************************************************/ -extern int PORT_SetState (uint16_t handle, tPORT_STATE *p_settings); +extern int PORT_SetState(uint16_t handle, tPORT_STATE* p_settings); /******************************************************************************* * @@ -358,7 +353,7 @@ extern int PORT_SetState (uint16_t handle, tPORT_STATE *p_settings); * p_rx_queue_count - Pointer to return queue count in. * ******************************************************************************/ -extern int PORT_GetRxQueueCnt (uint16_t handle, uint16_t *p_rx_queue_count); +extern int PORT_GetRxQueueCnt(uint16_t handle, uint16_t* p_rx_queue_count); /******************************************************************************* * @@ -372,8 +367,7 @@ extern int PORT_GetRxQueueCnt (uint16_t handle, uint16_t *p_rx_queue_count); * configuration information is returned. * ******************************************************************************/ -extern int PORT_GetState (uint16_t handle, tPORT_STATE *p_settings); - +extern int PORT_GetState(uint16_t handle, tPORT_STATE* p_settings); /******************************************************************************* * @@ -386,18 +380,17 @@ extern int PORT_GetState (uint16_t handle, tPORT_STATE *p_settings); * signal - specify the function to be passed * ******************************************************************************/ -#define PORT_SET_DTRDSR 0x01 -#define PORT_CLR_DTRDSR 0x02 -#define PORT_SET_CTSRTS 0x03 -#define PORT_CLR_CTSRTS 0x04 -#define PORT_SET_RI 0x05 /* DCE only */ -#define PORT_CLR_RI 0x06 /* DCE only */ -#define PORT_SET_DCD 0x07 /* DCE only */ -#define PORT_CLR_DCD 0x08 /* DCE only */ -#define PORT_BREAK 0x09 /* Break event */ - -extern int PORT_Control (uint16_t handle, uint8_t signal); - +#define PORT_SET_DTRDSR 0x01 +#define PORT_CLR_DTRDSR 0x02 +#define PORT_SET_CTSRTS 0x03 +#define PORT_CLR_CTSRTS 0x04 +#define PORT_SET_RI 0x05 /* DCE only */ +#define PORT_CLR_RI 0x06 /* DCE only */ +#define PORT_SET_DCD 0x07 /* DCE only */ +#define PORT_CLR_DCD 0x08 /* DCE only */ +#define PORT_BREAK 0x09 /* Break event */ + +extern int PORT_Control(uint16_t handle, uint8_t signal); /******************************************************************************* * @@ -411,7 +404,7 @@ extern int PORT_Control (uint16_t handle, uint8_t signal); * enable - enables data flow * ******************************************************************************/ -extern int PORT_FlowControl (uint16_t handle, bool enable); +extern int PORT_FlowControl(uint16_t handle, bool enable); /******************************************************************************* * @@ -442,21 +435,23 @@ extern int PORT_FlowControl_MaxCredit(uint16_t handle, bool enable); * p_signal - specify the pointer to control signals info * ******************************************************************************/ -#define PORT_DTRDSR_ON 0x01 -#define PORT_CTSRTS_ON 0x02 -#define PORT_RING_ON 0x04 -#define PORT_DCD_ON 0x08 +#define PORT_DTRDSR_ON 0x01 +#define PORT_CTSRTS_ON 0x02 +#define PORT_RING_ON 0x04 +#define PORT_DCD_ON 0x08 /* * Define default initial local modem signals state after connection established */ -#define PORT_OBEX_DEFAULT_SIGNAL_STATE (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) -#define PORT_SPP_DEFAULT_SIGNAL_STATE (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) -#define PORT_PPP_DEFAULT_SIGNAL_STATE (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) -#define PORT_DUN_DEFAULT_SIGNAL_STATE (PORT_DTRDSR_ON | PORT_CTSRTS_ON) - -extern int PORT_GetModemStatus (uint16_t handle, uint8_t *p_control_signal); +#define PORT_OBEX_DEFAULT_SIGNAL_STATE \ + (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) +#define PORT_SPP_DEFAULT_SIGNAL_STATE \ + (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) +#define PORT_PPP_DEFAULT_SIGNAL_STATE \ + (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON) +#define PORT_DUN_DEFAULT_SIGNAL_STATE (PORT_DTRDSR_ON | PORT_CTSRTS_ON) +extern int PORT_GetModemStatus(uint16_t handle, uint8_t* p_control_signal); /******************************************************************************* * @@ -475,28 +470,25 @@ extern int PORT_GetModemStatus (uint16_t handle, uint8_t *p_control_signal); * ******************************************************************************/ -#define PORT_ERR_BREAK 0x01 /* Break condition occured on the peer device */ -#define PORT_ERR_OVERRUN 0x02 /* Overrun is reported by peer device */ -#define PORT_ERR_FRAME 0x04 /* Framing error reported by peer device */ -#define PORT_ERR_RXOVER 0x08 /* Input queue overflow occured */ -#define PORT_ERR_TXFULL 0x10 /* Output queue overflow occured */ - -typedef struct -{ -#define PORT_FLAG_CTS_HOLD 0x01 /* Tx is waiting for CTS signal */ -#define PORT_FLAG_DSR_HOLD 0x02 /* Tx is waiting for DSR signal */ -#define PORT_FLAG_RLSD_HOLD 0x04 /* Tx is waiting for RLSD signal */ - - uint16_t flags; - uint16_t in_queue_size; /* Number of bytes in the input queue */ - uint16_t out_queue_size; /* Number of bytes in the output queue */ - uint16_t mtu_size; /* peer MTU size */ +#define PORT_ERR_BREAK 0x01 /* Break condition occured on the peer device */ +#define PORT_ERR_OVERRUN 0x02 /* Overrun is reported by peer device */ +#define PORT_ERR_FRAME 0x04 /* Framing error reported by peer device */ +#define PORT_ERR_RXOVER 0x08 /* Input queue overflow occured */ +#define PORT_ERR_TXFULL 0x10 /* Output queue overflow occured */ + +typedef struct { +#define PORT_FLAG_CTS_HOLD 0x01 /* Tx is waiting for CTS signal */ +#define PORT_FLAG_DSR_HOLD 0x02 /* Tx is waiting for DSR signal */ +#define PORT_FLAG_RLSD_HOLD 0x04 /* Tx is waiting for RLSD signal */ + + uint16_t flags; + uint16_t in_queue_size; /* Number of bytes in the input queue */ + uint16_t out_queue_size; /* Number of bytes in the output queue */ + uint16_t mtu_size; /* peer MTU size */ } tPORT_STATUS; - -extern int PORT_ClearError (uint16_t handle, uint16_t *p_errors, - tPORT_STATUS *p_status); - +extern int PORT_ClearError(uint16_t handle, uint16_t* p_errors, + tPORT_STATUS* p_status); /******************************************************************************* * @@ -508,8 +500,7 @@ extern int PORT_ClearError (uint16_t handle, uint16_t *p_errors, * errors - receive error codes * ******************************************************************************/ -extern int PORT_SendError (uint16_t handle, uint8_t errors); - +extern int PORT_SendError(uint16_t handle, uint8_t errors); /******************************************************************************* * @@ -522,8 +513,7 @@ extern int PORT_SendError (uint16_t handle, uint8_t errors); * connection status * ******************************************************************************/ -extern int PORT_GetQueueStatus (uint16_t handle, tPORT_STATUS *p_status); - +extern int PORT_GetQueueStatus(uint16_t handle, tPORT_STATUS* p_status); /******************************************************************************* * @@ -536,11 +526,10 @@ extern int PORT_GetQueueStatus (uint16_t handle, tPORT_STATUS *p_status); * purge_flags - specify the action to take. * ******************************************************************************/ -#define PORT_PURGE_TXCLEAR 0x01 -#define PORT_PURGE_RXCLEAR 0x02 - -extern int PORT_Purge (uint16_t handle, uint8_t purge_flags); +#define PORT_PURGE_TXCLEAR 0x01 +#define PORT_PURGE_RXCLEAR 0x02 +extern int PORT_Purge(uint16_t handle, uint8_t purge_flags); /******************************************************************************* * @@ -557,8 +546,7 @@ extern int PORT_Purge (uint16_t handle, uint8_t purge_flags); * pp_buf - pointer to address of buffer with data, * ******************************************************************************/ -extern int PORT_Read (uint16_t handle, BT_HDR **pp_buf); - +extern int PORT_Read(uint16_t handle, BT_HDR** pp_buf); /******************************************************************************* * @@ -574,9 +562,8 @@ extern int PORT_Read (uint16_t handle, BT_HDR **pp_buf); * p_len - Byte count received * ******************************************************************************/ -extern int PORT_ReadData (uint16_t handle, char *p_data, uint16_t max_len, - uint16_t *p_len); - +extern int PORT_ReadData(uint16_t handle, char* p_data, uint16_t max_len, + uint16_t* p_len); /******************************************************************************* * @@ -589,8 +576,7 @@ extern int PORT_ReadData (uint16_t handle, char *p_data, uint16_t max_len, * p_buf - pointer to the buffer with data, * ******************************************************************************/ -extern int PORT_Write (uint16_t handle, BT_HDR *p_buf); - +extern int PORT_Write(uint16_t handle, BT_HDR* p_buf); /******************************************************************************* * @@ -605,8 +591,8 @@ extern int PORT_Write (uint16_t handle, BT_HDR *p_buf); * p_len - Bytes written * ******************************************************************************/ -extern int PORT_WriteData (uint16_t handle, const char *p_data, - uint16_t max_len, uint16_t *p_len); +extern int PORT_WriteData(uint16_t handle, const char* p_data, uint16_t max_len, + uint16_t* p_len); /******************************************************************************* * @@ -618,7 +604,7 @@ extern int PORT_WriteData (uint16_t handle, const char *p_data, * Parameters: handle - Handle returned in the RFCOMM_CreateConnection * ******************************************************************************/ -extern int PORT_WriteDataCO (uint16_t handle, int* p_len); +extern int PORT_WriteDataCO(uint16_t handle, int* p_len); /******************************************************************************* * @@ -631,8 +617,7 @@ extern int PORT_WriteDataCO (uint16_t handle, int* p_len); * max_len - Byte count requested * ******************************************************************************/ -extern int PORT_Test (uint16_t handle, uint8_t *p_data, uint16_t len); - +extern int PORT_Test(uint16_t handle, uint8_t* p_data, uint16_t len); /******************************************************************************* * @@ -641,8 +626,7 @@ extern int PORT_Test (uint16_t handle, uint8_t *p_data, uint16_t len); * Description This function is called to initialize RFCOMM layer * ******************************************************************************/ -extern void RFCOMM_Init (void); - +extern void RFCOMM_Init(void); /******************************************************************************* * @@ -654,8 +638,7 @@ extern void RFCOMM_Init (void); * Returns the new (current) trace level * ******************************************************************************/ -extern uint8_t PORT_SetTraceLevel (uint8_t new_level); - +extern uint8_t PORT_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -668,10 +651,10 @@ extern uint8_t PORT_SetTraceLevel (uint8_t new_level); * result. Note that the string returned must not be freed. * ******************************************************************************/ -extern const char *PORT_GetResultString (const uint8_t result_code); +extern const char* PORT_GetResultString(const uint8_t result_code); #ifdef __cplusplus } #endif -#endif /* PORT_API_H */ +#endif /* PORT_API_H */ diff --git a/stack/include/port_ext.h b/stack/include/port_ext.h index b940e4e47..ec8eb9421 100644 --- a/stack/include/port_ext.h +++ b/stack/include/port_ext.h @@ -27,6 +27,6 @@ #include "bt_common.h" -extern void rfcomm_port_timer_timeout(void *data); -extern void rfcomm_mcb_timer_timeout(void *data); +extern void rfcomm_port_timer_timeout(void* data); +extern void rfcomm_mcb_timer_timeout(void* data); #endif diff --git a/stack/include/profiles_api.h b/stack/include/profiles_api.h index 5bcc124ff..aa3b8844b 100644 --- a/stack/include/profiles_api.h +++ b/stack/include/profiles_api.h @@ -25,39 +25,38 @@ /***************************************************************************** * Constants ****************************************************************************/ -#define BT_PASS 0 /* Used for general successful function returns */ +#define BT_PASS 0 /* Used for general successful function returns */ /*** Port entity passes back 8 bit errors; will use upper byte offset ***/ -#define PORT_ERR_GRP 0x0000 /* base offset for port entity */ -#define GAP_ERR_GRP 0x0100 /* base offset for GAP profile */ -#define SPP_ERR_GRP 0x0200 /* base offset for serial port profile */ -#define HCRP_ERR_GRP 0x0300 /* base offset for HCRP */ -#define HCRPM_ERR_GRP 0x0400 /* base offset for HCRPM */ +#define PORT_ERR_GRP 0x0000 /* base offset for port entity */ +#define GAP_ERR_GRP 0x0100 /* base offset for GAP profile */ +#define SPP_ERR_GRP 0x0200 /* base offset for serial port profile */ +#define HCRP_ERR_GRP 0x0300 /* base offset for HCRP */ +#define HCRPM_ERR_GRP 0x0400 /* base offset for HCRPM */ /* #define HSP2_ERR_GRP 0x0F00 */ /* security level definitions (tBT_SECURITY) */ -#define BT_USE_DEF_SECURITY 0 -#define BT_SEC_MODE_NONE BTM_SEC_MODE_NONE -#define BT_SEC_MODE_SERVICE BTM_SEC_MODE_SERVICE -#define BT_SEC_MODE_LINK BTM_SEC_MODE_LINK +#define BT_USE_DEF_SECURITY 0 +#define BT_SEC_MODE_NONE BTM_SEC_MODE_NONE +#define BT_SEC_MODE_SERVICE BTM_SEC_MODE_SERVICE +#define BT_SEC_MODE_LINK BTM_SEC_MODE_LINK /* security mask definitions (tBT_SECURITY) */ /* The following definitions are OR'd together to form the security * requirements */ /* Inbound call requires authorization */ -#define BT_SEC_IN_AUTHORIZE BTM_SEC_IN_AUTHORIZE +#define BT_SEC_IN_AUTHORIZE BTM_SEC_IN_AUTHORIZE /* Inbound call requires authentication */ -#define BT_SEC_IN_AUTHENTICATE BTM_SEC_IN_AUTHENTICATE +#define BT_SEC_IN_AUTHENTICATE BTM_SEC_IN_AUTHENTICATE /* Inbound call requires encryption */ -#define BT_SEC_IN_ENCRYPT BTM_SEC_IN_ENCRYPT +#define BT_SEC_IN_ENCRYPT BTM_SEC_IN_ENCRYPT /* Outbound call requires authorization */ -#define BT_SEC_OUT_AUTHORIZE BTM_SEC_OUT_AUTHORIZE +#define BT_SEC_OUT_AUTHORIZE BTM_SEC_OUT_AUTHORIZE /* Outbound call requires authentication */ -#define BT_SEC_OUT_AUTHENTICATE BTM_SEC_OUT_AUTHENTICATE +#define BT_SEC_OUT_AUTHENTICATE BTM_SEC_OUT_AUTHENTICATE /* Outbound call requires encryption */ -#define BT_SEC_OUT_ENCRYPT BTM_SEC_OUT_ENCRYPT - +#define BT_SEC_OUT_ENCRYPT BTM_SEC_OUT_ENCRYPT /***************************************************************************** * Type Definitions @@ -68,11 +67,9 @@ * This following definitions are used to indicate the security * requirements for a service. */ -typedef struct -{ - uint8_t level; - uint8_t mask; +typedef struct { + uint8_t level; + uint8_t mask; } tBT_SECURITY; -#endif /* PROFILES_API_H */ - +#endif /* PROFILES_API_H */ diff --git a/stack/include/rfcdefs.h b/stack/include/rfcdefs.h index 77534a1aa..5118ccd06 100644 --- a/stack/include/rfcdefs.h +++ b/stack/include/rfcdefs.h @@ -25,224 +25,221 @@ #ifndef RFCDEFS_H #define RFCDEFS_H -#define PORT_MAX_RFC_PORTS 31 +#define PORT_MAX_RFC_PORTS 31 /* * If nothing is negotiated MTU should be 127 */ -#define RFCOMM_DEFAULT_MTU 127 +#define RFCOMM_DEFAULT_MTU 127 /* * Define used by RFCOMM TS frame types */ -#define RFCOMM_SABME 0x2F -#define RFCOMM_UA 0x63 -#define RFCOMM_DM 0x0F -#define RFCOMM_DISC 0x43 -#define RFCOMM_UIH 0xEF +#define RFCOMM_SABME 0x2F +#define RFCOMM_UA 0x63 +#define RFCOMM_DM 0x0F +#define RFCOMM_DISC 0x43 +#define RFCOMM_UIH 0xEF /* * Defenitions for the TS control frames */ -#define RFCOMM_CTRL_FRAME_LEN 3 -#define RFCOMM_MIN_OFFSET 5 /* ctrl 2 , len 1 or 2 bytes, credit 1 byte */ -#define RFCOMM_DATA_OVERHEAD (RFCOMM_MIN_OFFSET + 1) /* add 1 for checksum */ - -#define RFCOMM_EA 1 -#define RFCOMM_EA_MASK 0x01 -#define RFCOMM_CR_MASK 0x02 -#define RFCOMM_SHIFT_CR 1 -#define RFCOMM_SHIFT_DLCI 2 -#define RFCOMM_SHIFT_DLCI2 6 -#define RFCOMM_PF 0x10 -#define RFCOMM_PF_MASK 0x10 -#define RFCOMM_PF_OFFSET 4 -#define RFCOMM_SHIFT_LENGTH1 1 -#define RFCOMM_SHIFT_LENGTH2 7 -#define RFCOMM_SHIFT_MX_CTRL_TYPE 2 - -#define RFCOMM_INITIATOR_CMD 1 -#define RFCOMM_INITIATOR_RSP 0 -#define RFCOMM_RESPONDER_CMD 0 -#define RFCOMM_RESPONDER_RSP 1 +#define RFCOMM_CTRL_FRAME_LEN 3 +#define RFCOMM_MIN_OFFSET 5 /* ctrl 2 , len 1 or 2 bytes, credit 1 byte */ +#define RFCOMM_DATA_OVERHEAD (RFCOMM_MIN_OFFSET + 1) /* add 1 for checksum */ + +#define RFCOMM_EA 1 +#define RFCOMM_EA_MASK 0x01 +#define RFCOMM_CR_MASK 0x02 +#define RFCOMM_SHIFT_CR 1 +#define RFCOMM_SHIFT_DLCI 2 +#define RFCOMM_SHIFT_DLCI2 6 +#define RFCOMM_PF 0x10 +#define RFCOMM_PF_MASK 0x10 +#define RFCOMM_PF_OFFSET 4 +#define RFCOMM_SHIFT_LENGTH1 1 +#define RFCOMM_SHIFT_LENGTH2 7 +#define RFCOMM_SHIFT_MX_CTRL_TYPE 2 + +#define RFCOMM_INITIATOR_CMD 1 +#define RFCOMM_INITIATOR_RSP 0 +#define RFCOMM_RESPONDER_CMD 0 +#define RFCOMM_RESPONDER_RSP 1 #define RFCOMM_PARSE_CTRL_FIELD(ea, cr, dlci, p_data) \ -{ \ - (ea) = *(p_data) & RFCOMM_EA; \ - (cr) = (*(p_data) & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; \ + { \ + (ea) = *(p_data)&RFCOMM_EA; \ + (cr) = (*(p_data)&RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; \ (dlci) = *(p_data)++ >> RFCOMM_SHIFT_DLCI; \ if (!(ea)) (dlci) += *(p_data)++ << RFCOMM_SHIFT_DLCI2; \ -} + } #define RFCOMM_FORMAT_CTRL_FIELD(p_data, ea, cr, dlci) \ - (*(p_data)++ = (ea) | (cr) | ((dlci) << RFCOMM_SHIFT_DLCI)) + (*(p_data)++ = (ea) | (cr) | ((dlci) << RFCOMM_SHIFT_DLCI)) -#define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data) \ -{ \ - (type) = *(p_data) & ~RFCOMM_PF_MASK; \ - (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET;\ -} +#define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data) \ + { \ + (type) = *(p_data) & ~RFCOMM_PF_MASK; \ + (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \ + } -#define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf) \ - *(p_data)++ = ((type) | ((pf) << RFCOMM_PF_OFFSET)) \ -{ \ - (type) = *(p_data) & ~RFCOMM_PF_MASK; \ - (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \ -} +#define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf) \ + *(p_data)++ = ((type) | ((pf) << RFCOMM_PF_OFFSET)) { \ + (type) = *(p_data) & ~RFCOMM_PF_MASK; \ + (pf) = (*(p_data)++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET; \ + } #define RFCOMM_PARSE_LEN_FIELD(ea, length, p_data) \ -{ \ - (ea) = (*(p_data) & RFCOMM_EA); \ + { \ + (ea) = (*(p_data)&RFCOMM_EA); \ (length) = (*(p_data)++ >> RFCOMM_SHIFT_LENGTH1); \ if (!(ea)) (length) += (*(p_data)++ << RFCOMM_SHIFT_LENGTH2); \ -} + } -#define RFCOMM_FRAME_IS_CMD(initiator, cr) \ - (( (initiator) && !(cr)) || (!(initiator) && (cr))) +#define RFCOMM_FRAME_IS_CMD(initiator, cr) \ + (((initiator) && !(cr)) || (!(initiator) && (cr))) -#define RFCOMM_FRAME_IS_RSP(initiator, cr) \ - (( (initiator) && (cr)) || (!(initiator) && !(cr))) +#define RFCOMM_FRAME_IS_RSP(initiator, cr) \ + (((initiator) && (cr)) || (!(initiator) && !(cr))) -#define RFCOMM_CR(initiator, is_command) \ - (( ( (initiator) && (is_command)) \ - || (!(initiator) && !(is_command))) << 1) +#define RFCOMM_CR(initiator, is_command) \ + ((((initiator) && (is_command)) || (!(initiator) && !(is_command))) << 1) #define RFCOMM_I_CR(is_command) ((is_command) ? 0x02 : 0x00) -#define RFCOMM_MAX_DLCI 61 - -#define RFCOMM_VALID_DLCI(dlci) \ - (((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI))) +#define RFCOMM_MAX_DLCI 61 +#define RFCOMM_VALID_DLCI(dlci) \ + (((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI))) /* Port Negotiation (PN) */ -#define RFCOMM_PN_DLCI_MASK 0x3F +#define RFCOMM_PN_DLCI_MASK 0x3F -#define RFCOMM_PN_FRAM_TYPE_UIH 0x00 -#define RFCOMM_PN_FRAME_TYPE_MASK 0x0F +#define RFCOMM_PN_FRAM_TYPE_UIH 0x00 +#define RFCOMM_PN_FRAME_TYPE_MASK 0x0F -#define RFCOMM_PN_CONV_LAYER_MASK 0xF0 +#define RFCOMM_PN_CONV_LAYER_MASK 0xF0 #define RFCOMM_PN_CONV_LAYER_TYPE_1 0 #define RFCOMM_PN_CONV_LAYER_CBFC_I 0xF0 #define RFCOMM_PN_CONV_LAYER_CBFC_R 0xE0 -#define RFCOMM_PN_PRIORITY_MASK 0x3F -#define RFCOMM_PN_PRIORITY_0 0 - -#define RFCOMM_PN_K_MASK 0x07 - -#define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */ -#define RFCOMM_N2 0 /* Number of retransmissions */ -#define RFCOMM_K 0 /* Window size */ -#define RFCOMM_K_MAX 7 /* Max value of K for credit based flow control */ - -#define RFCOMM_MSC_FC 0x02 /* Flow control*/ -#define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/ -#define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/ -#define RFCOMM_MSC_IC 0x40 /* Incomming call indicator*/ -#define RFCOMM_MSC_DV 0x80 /* Data Valid*/ - -#define RFCOMM_MSC_SHIFT_BREAK 4 -#define RFCOMM_MSC_BREAK_MASK 0xF0 -#define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02 - -#define RFCOMM_BAUD_RATE_2400 0x00 -#define RFCOMM_BAUD_RATE_4800 0x01 -#define RFCOMM_BAUD_RATE_7200 0x02 -#define RFCOMM_BAUD_RATE_9600 0x03 -#define RFCOMM_BAUD_RATE_19200 0x04 -#define RFCOMM_BAUD_RATE_38400 0x05 -#define RFCOMM_BAUD_RATE_57600 0x06 -#define RFCOMM_BAUD_RATE_115200 0x07 -#define RFCOMM_BAUD_RATE_230400 0x08 - -#define RFCOMM_5_BITS 0x00 -#define RFCOMM_6_BITS 0x01 -#define RFCOMM_7_BITS 0x02 -#define RFCOMM_8_BITS 0x03 - -#define RFCOMM_RPN_BITS_MASK 0x03 -#define RFCOMM_RPN_BITS_SHIFT 0 - -#define RFCOMM_ONESTOPBIT 0x00 -#define RFCOMM_ONE5STOPBITS 0x01 - -#define RFCOMM_RPN_STOP_BITS_MASK 0x01 -#define RFCOMM_RPN_STOP_BITS_SHIFT 2 - -#define RFCOMM_PARITY_NO 0x00 -#define RFCOMM_PARITY_YES 0x01 -#define RFCOMM_RPN_PARITY_MASK 0x01 -#define RFCOMM_RPN_PARITY_SHIFT 3 - -#define RFCOMM_ODD_PARITY 0x00 -#define RFCOMM_EVEN_PARITY 0x01 -#define RFCOMM_MARK_PARITY 0x02 -#define RFCOMM_SPACE_PARITY 0x03 - -#define RFCOMM_RPN_PARITY_TYPE_MASK 0x03 -#define RFCOMM_RPN_PARITY_TYPE_SHIFT 4 - -#define RFCOMM_FC_OFF 0x00 -#define RFCOMM_FC_XONXOFF_ON_INPUT 0x01 -#define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02 -#define RFCOMM_FC_RTR_ON_INPUT 0x04 -#define RFCOMM_FC_RTR_ON_OUTPUT 0x08 -#define RFCOMM_FC_RTC_ON_INPUT 0x10 -#define RFCOMM_FC_RTC_ON_OUTPUT 0x20 -#define RFCOMM_FC_MASK 0x3F - -#define RFCOMM_RPN_PM_BIT_RATE 0x0001 -#define RFCOMM_RPN_PM_DATA_BITS 0x0002 -#define RFCOMM_RPN_PM_STOP_BITS 0x0004 -#define RFCOMM_RPN_PM_PARITY 0x0008 -#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010 -#define RFCOMM_RPN_PM_XON_CHAR 0x0020 -#define RFCOMM_RPN_PM_XOFF_CHAR 0x0040 -#define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100 +#define RFCOMM_PN_PRIORITY_MASK 0x3F +#define RFCOMM_PN_PRIORITY_0 0 + +#define RFCOMM_PN_K_MASK 0x07 + +#define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */ +#define RFCOMM_N2 0 /* Number of retransmissions */ +#define RFCOMM_K 0 /* Window size */ +#define RFCOMM_K_MAX 7 /* Max value of K for credit based flow control */ + +#define RFCOMM_MSC_FC 0x02 /* Flow control*/ +#define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/ +#define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/ +#define RFCOMM_MSC_IC 0x40 /* Incomming call indicator*/ +#define RFCOMM_MSC_DV 0x80 /* Data Valid*/ + +#define RFCOMM_MSC_SHIFT_BREAK 4 +#define RFCOMM_MSC_BREAK_MASK 0xF0 +#define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02 + +#define RFCOMM_BAUD_RATE_2400 0x00 +#define RFCOMM_BAUD_RATE_4800 0x01 +#define RFCOMM_BAUD_RATE_7200 0x02 +#define RFCOMM_BAUD_RATE_9600 0x03 +#define RFCOMM_BAUD_RATE_19200 0x04 +#define RFCOMM_BAUD_RATE_38400 0x05 +#define RFCOMM_BAUD_RATE_57600 0x06 +#define RFCOMM_BAUD_RATE_115200 0x07 +#define RFCOMM_BAUD_RATE_230400 0x08 + +#define RFCOMM_5_BITS 0x00 +#define RFCOMM_6_BITS 0x01 +#define RFCOMM_7_BITS 0x02 +#define RFCOMM_8_BITS 0x03 + +#define RFCOMM_RPN_BITS_MASK 0x03 +#define RFCOMM_RPN_BITS_SHIFT 0 + +#define RFCOMM_ONESTOPBIT 0x00 +#define RFCOMM_ONE5STOPBITS 0x01 + +#define RFCOMM_RPN_STOP_BITS_MASK 0x01 +#define RFCOMM_RPN_STOP_BITS_SHIFT 2 + +#define RFCOMM_PARITY_NO 0x00 +#define RFCOMM_PARITY_YES 0x01 +#define RFCOMM_RPN_PARITY_MASK 0x01 +#define RFCOMM_RPN_PARITY_SHIFT 3 + +#define RFCOMM_ODD_PARITY 0x00 +#define RFCOMM_EVEN_PARITY 0x01 +#define RFCOMM_MARK_PARITY 0x02 +#define RFCOMM_SPACE_PARITY 0x03 + +#define RFCOMM_RPN_PARITY_TYPE_MASK 0x03 +#define RFCOMM_RPN_PARITY_TYPE_SHIFT 4 + +#define RFCOMM_FC_OFF 0x00 +#define RFCOMM_FC_XONXOFF_ON_INPUT 0x01 +#define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02 +#define RFCOMM_FC_RTR_ON_INPUT 0x04 +#define RFCOMM_FC_RTR_ON_OUTPUT 0x08 +#define RFCOMM_FC_RTC_ON_INPUT 0x10 +#define RFCOMM_FC_RTC_ON_OUTPUT 0x20 +#define RFCOMM_FC_MASK 0x3F + +#define RFCOMM_RPN_PM_BIT_RATE 0x0001 +#define RFCOMM_RPN_PM_DATA_BITS 0x0002 +#define RFCOMM_RPN_PM_STOP_BITS 0x0004 +#define RFCOMM_RPN_PM_PARITY 0x0008 +#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010 +#define RFCOMM_RPN_PM_XON_CHAR 0x0020 +#define RFCOMM_RPN_PM_XOFF_CHAR 0x0040 +#define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100 #define RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT 0x0200 -#define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400 -#define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800 -#define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000 -#define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000 -#define RFCOMM_RPN_PM_MASK 0x3F7F +#define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400 +#define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800 +#define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000 +#define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000 +#define RFCOMM_RPN_PM_MASK 0x3F7F -#define RFCOMM_RLS_ERROR 0x01 -#define RFCOMM_RLS_OVERRUN 0x02 -#define RFCOMM_RLS_PARITY 0x04 -#define RFCOMM_RLS_FRAMING 0x08 +#define RFCOMM_RLS_ERROR 0x01 +#define RFCOMM_RLS_OVERRUN 0x02 +#define RFCOMM_RLS_PARITY 0x04 +#define RFCOMM_RLS_FRAMING 0x08 /* Multiplexor channel uses DLCI 0 */ -#define RFCOMM_MX_DLCI 0 +#define RFCOMM_MX_DLCI 0 /* * Define RFCOMM Multiplexer message types */ -#define RFCOMM_MX_PN 0x80 -#define RFCOMM_MX_PN_LEN 8 +#define RFCOMM_MX_PN 0x80 +#define RFCOMM_MX_PN_LEN 8 -#define RFCOMM_MX_CLD 0xC0 -#define RFCOMM_MX_CLD_LEN 0 +#define RFCOMM_MX_CLD 0xC0 +#define RFCOMM_MX_CLD_LEN 0 -#define RFCOMM_MX_TEST 0x20 +#define RFCOMM_MX_TEST 0x20 -#define RFCOMM_MX_FCON 0xA0 -#define RFCOMM_MX_FCON_LEN 0 +#define RFCOMM_MX_FCON 0xA0 +#define RFCOMM_MX_FCON_LEN 0 -#define RFCOMM_MX_FCOFF 0x60 -#define RFCOMM_MX_FCOFF_LEN 0 +#define RFCOMM_MX_FCOFF 0x60 +#define RFCOMM_MX_FCOFF_LEN 0 -#define RFCOMM_MX_MSC 0xE0 -#define RFCOMM_MX_MSC_LEN_NO_BREAK 2 -#define RFCOMM_MX_MSC_LEN_WITH_BREAK 3 +#define RFCOMM_MX_MSC 0xE0 +#define RFCOMM_MX_MSC_LEN_NO_BREAK 2 +#define RFCOMM_MX_MSC_LEN_WITH_BREAK 3 -#define RFCOMM_MX_NSC 0x10 -#define RFCOMM_MX_NSC_LEN 1 +#define RFCOMM_MX_NSC 0x10 +#define RFCOMM_MX_NSC_LEN 1 -#define RFCOMM_MX_RPN 0x90 -#define RFCOMM_MX_RPN_REQ_LEN 1 -#define RFCOMM_MX_RPN_LEN 8 +#define RFCOMM_MX_RPN 0x90 +#define RFCOMM_MX_RPN_REQ_LEN 1 +#define RFCOMM_MX_RPN_LEN 8 -#define RFCOMM_MX_RLS 0x50 -#define RFCOMM_MX_RLS_LEN 2 +#define RFCOMM_MX_RLS 0x50 +#define RFCOMM_MX_RLS_LEN 2 #endif diff --git a/stack/include/sdp_api.h b/stack/include/sdp_api.h index c560e7294..3f1dd43c7 100644 --- a/stack/include/sdp_api.h +++ b/stack/include/sdp_api.h @@ -30,155 +30,143 @@ extern "C" { ****************************************************************************/ /* Success code and error codes */ -#define SDP_SUCCESS 0x0000 -#define SDP_INVALID_VERSION 0x0001 -#define SDP_INVALID_SERV_REC_HDL 0x0002 -#define SDP_INVALID_REQ_SYNTAX 0x0003 -#define SDP_INVALID_PDU_SIZE 0x0004 -#define SDP_INVALID_CONT_STATE 0x0005 -#define SDP_NO_RESOURCES 0x0006 -#define SDP_DI_REG_FAILED 0x0007 -#define SDP_DI_DISC_FAILED 0x0008 -#define SDP_NO_DI_RECORD_FOUND 0x0009 -#define SDP_ERR_ATTR_NOT_PRESENT 0x000A -#define SDP_ILLEGAL_PARAMETER 0x000B - -#define SDP_NO_RECS_MATCH 0xFFF0 -#define SDP_CONN_FAILED 0xFFF1 -#define SDP_CFG_FAILED 0xFFF2 -#define SDP_GENERIC_ERROR 0xFFF3 -#define SDP_DB_FULL 0xFFF4 -#define SDP_INVALID_PDU 0xFFF5 -#define SDP_SECURITY_ERR 0xFFF6 -#define SDP_CONN_REJECTED 0xFFF7 -#define SDP_CANCEL 0xFFF8 +#define SDP_SUCCESS 0x0000 +#define SDP_INVALID_VERSION 0x0001 +#define SDP_INVALID_SERV_REC_HDL 0x0002 +#define SDP_INVALID_REQ_SYNTAX 0x0003 +#define SDP_INVALID_PDU_SIZE 0x0004 +#define SDP_INVALID_CONT_STATE 0x0005 +#define SDP_NO_RESOURCES 0x0006 +#define SDP_DI_REG_FAILED 0x0007 +#define SDP_DI_DISC_FAILED 0x0008 +#define SDP_NO_DI_RECORD_FOUND 0x0009 +#define SDP_ERR_ATTR_NOT_PRESENT 0x000A +#define SDP_ILLEGAL_PARAMETER 0x000B + +#define SDP_NO_RECS_MATCH 0xFFF0 +#define SDP_CONN_FAILED 0xFFF1 +#define SDP_CFG_FAILED 0xFFF2 +#define SDP_GENERIC_ERROR 0xFFF3 +#define SDP_DB_FULL 0xFFF4 +#define SDP_INVALID_PDU 0xFFF5 +#define SDP_SECURITY_ERR 0xFFF6 +#define SDP_CONN_REJECTED 0xFFF7 +#define SDP_CANCEL 0xFFF8 /* Define the PSM that SDP uses */ -#define SDP_PSM 0x0001 +#define SDP_PSM 0x0001 /* Legacy #define to avoid code changes - SDP UUID is same as BT UUID */ -#define tSDP_UUID tBT_UUID +#define tSDP_UUID tBT_UUID /* Masks for attr_value field of tSDP_DISC_ATTR */ -#define SDP_DISC_ATTR_LEN_MASK 0x0FFF -#define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12) -#define SDP_DISC_ATTR_LEN(len_type) ((len_type) & SDP_DISC_ATTR_LEN_MASK) +#define SDP_DISC_ATTR_LEN_MASK 0x0FFF +#define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12) +#define SDP_DISC_ATTR_LEN(len_type) ((len_type)&SDP_DISC_ATTR_LEN_MASK) /* Maximum number of protocol list items (list_elem in tSDP_PROTOCOL_ELEM) */ -#define SDP_MAX_LIST_ELEMS 3 - +#define SDP_MAX_LIST_ELEMS 3 /***************************************************************************** * Type Definitions ****************************************************************************/ /* Define a callback function for when discovery is complete. */ -typedef void (tSDP_DISC_CMPL_CB) (uint16_t result); -typedef void (tSDP_DISC_CMPL_CB2) (uint16_t result, void* user_data); +typedef void(tSDP_DISC_CMPL_CB)(uint16_t result); +typedef void(tSDP_DISC_CMPL_CB2)(uint16_t result, void* user_data); -typedef struct -{ - BD_ADDR peer_addr; - uint16_t peer_mtu; +typedef struct { + BD_ADDR peer_addr; + uint16_t peer_mtu; } tSDP_DR_OPEN; -typedef struct -{ - uint8_t *p_data; - uint16_t data_len; +typedef struct { + uint8_t* p_data; + uint16_t data_len; } tSDP_DR_DATA; -typedef union -{ - tSDP_DR_OPEN open; - tSDP_DR_DATA data; +typedef union { + tSDP_DR_OPEN open; + tSDP_DR_DATA data; } tSDP_DATA; /* Define a callback function for when discovery result is received. */ -typedef void (tSDP_DISC_RES_CB) (uint16_t event, tSDP_DATA *p_data); +typedef void(tSDP_DISC_RES_CB)(uint16_t event, tSDP_DATA* p_data); /* Define a structure to hold the discovered service information. */ -typedef struct -{ - union - { - uint8_t u8; /* 8-bit integer */ - uint16_t u16; /* 16-bit integer */ - uint32_t u32; /* 32-bit integer */ - uint8_t array[4]; /* Variable length field */ - struct t_sdp_disc_attr *p_sub_attr; /* Addr of first sub-attr (list)*/ - } v; +typedef struct { + union { + uint8_t u8; /* 8-bit integer */ + uint16_t u16; /* 16-bit integer */ + uint32_t u32; /* 32-bit integer */ + uint8_t array[4]; /* Variable length field */ + struct t_sdp_disc_attr* p_sub_attr; /* Addr of first sub-attr (list)*/ + } v; } tSDP_DISC_ATVAL; -typedef struct t_sdp_disc_attr -{ - struct t_sdp_disc_attr *p_next_attr; /* Addr of next linked attr */ - uint16_t attr_id; /* Attribute ID */ - uint16_t attr_len_type; /* Length and type fields */ - tSDP_DISC_ATVAL attr_value; /* Variable length entry data */ +typedef struct t_sdp_disc_attr { + struct t_sdp_disc_attr* p_next_attr; /* Addr of next linked attr */ + uint16_t attr_id; /* Attribute ID */ + uint16_t attr_len_type; /* Length and type fields */ + tSDP_DISC_ATVAL attr_value; /* Variable length entry data */ } tSDP_DISC_ATTR; -typedef struct t_sdp_disc_rec -{ - tSDP_DISC_ATTR *p_first_attr; /* First attribute of record */ - struct t_sdp_disc_rec *p_next_rec; /* Addr of next linked record */ - uint32_t time_read; /* The time the record was read */ - BD_ADDR remote_bd_addr; /* Remote BD address */ +typedef struct t_sdp_disc_rec { + tSDP_DISC_ATTR* p_first_attr; /* First attribute of record */ + struct t_sdp_disc_rec* p_next_rec; /* Addr of next linked record */ + uint32_t time_read; /* The time the record was read */ + BD_ADDR remote_bd_addr; /* Remote BD address */ } tSDP_DISC_REC; -typedef struct -{ - uint32_t mem_size; /* Memory size of the DB */ - uint32_t mem_free; /* Memory still available */ - tSDP_DISC_REC *p_first_rec; /* Addr of first record in DB */ - uint16_t num_uuid_filters; /* Number of UUIds to filter */ - tSDP_UUID uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */ - uint16_t num_attr_filters; /* Number of attribute filters */ - uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */ - uint8_t *p_free_mem; /* Pointer to free memory */ +typedef struct { + uint32_t mem_size; /* Memory size of the DB */ + uint32_t mem_free; /* Memory still available */ + tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB */ + uint16_t num_uuid_filters; /* Number of UUIds to filter */ + tSDP_UUID uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */ + uint16_t num_attr_filters; /* Number of attribute filters */ + uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */ + uint8_t* p_free_mem; /* Pointer to free memory */ #if (SDP_RAW_DATA_INCLUDED == TRUE) - uint8_t *raw_data; /* Received record from server. allocated/released by client */ - uint32_t raw_size; /* size of raw_data */ - uint32_t raw_used; /* length of raw_data used */ + uint8_t* + raw_data; /* Received record from server. allocated/released by client */ + uint32_t raw_size; /* size of raw_data */ + uint32_t raw_used; /* length of raw_data used */ #endif -}tSDP_DISCOVERY_DB; +} tSDP_DISCOVERY_DB; /* This structure is used to add protocol lists and find protocol elements */ -typedef struct -{ - uint16_t protocol_uuid; - uint16_t num_params; - uint16_t params[SDP_MAX_PROTOCOL_PARAMS]; +typedef struct { + uint16_t protocol_uuid; + uint16_t num_params; + uint16_t params[SDP_MAX_PROTOCOL_PARAMS]; } tSDP_PROTOCOL_ELEM; -typedef struct -{ - uint16_t num_elems; - tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS]; +typedef struct { + uint16_t num_elems; + tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS]; } tSDP_PROTO_LIST_ELEM; /* Device Identification (DI) data structure */ /* Used to set the DI record */ -typedef struct t_sdp_di_record -{ - uint16_t vendor; - uint16_t vendor_id_source; - uint16_t product; - uint16_t version; - bool primary_record; - char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */ - char service_description[SDP_MAX_ATTR_LEN]; /* optional */ - char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */ -}tSDP_DI_RECORD; +typedef struct t_sdp_di_record { + uint16_t vendor; + uint16_t vendor_id_source; + uint16_t product; + uint16_t version; + bool primary_record; + char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */ + char service_description[SDP_MAX_ATTR_LEN]; /* optional */ + char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */ +} tSDP_DI_RECORD; /* Used to get the DI record */ -typedef struct t_sdp_di_get_record -{ - uint16_t spec_id; - tSDP_DI_RECORD rec; -}tSDP_DI_GET_RECORD; +typedef struct t_sdp_di_get_record { + uint16_t spec_id; + tSDP_DI_RECORD rec; +} tSDP_DI_GET_RECORD; /* API into the SDP layer for service discovery. */ @@ -191,11 +179,9 @@ typedef struct t_sdp_di_get_record * Returns true if successful, false if one or more parameters are bad * ******************************************************************************/ -bool SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, uint32_t len, - uint16_t num_uuid, - tSDP_UUID *p_uuid_list, - uint16_t num_attr, - uint16_t *p_attr_list); +bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len, + uint16_t num_uuid, tSDP_UUID* p_uuid_list, + uint16_t num_attr, uint16_t* p_attr_list); /******************************************************************************* * @@ -207,7 +193,7 @@ bool SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, uint32_t len, * not found. * ******************************************************************************/ -bool SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db); +bool SDP_CancelServiceSearch(tSDP_DISCOVERY_DB* p_db); /******************************************************************************* * @@ -218,10 +204,8 @@ bool SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db); * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchRequest (uint8_t *p_bd_addr, - tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB *p_cb); - +bool SDP_ServiceSearchRequest(uint8_t* p_bd_addr, tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB* p_cb); /******************************************************************************* * @@ -236,9 +220,9 @@ bool SDP_ServiceSearchRequest (uint8_t *p_bd_addr, * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchAttributeRequest (uint8_t *p_bd_addr, - tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB *p_cb); +bool SDP_ServiceSearchAttributeRequest(uint8_t* p_bd_addr, + tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB* p_cb); /******************************************************************************* * @@ -254,9 +238,10 @@ bool SDP_ServiceSearchAttributeRequest (uint8_t *p_bd_addr, * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchAttributeRequest2 (uint8_t *p_bd_addr, - tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB2 *p_cb, void * user_data); +bool SDP_ServiceSearchAttributeRequest2(uint8_t* p_bd_addr, + tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB2* p_cb, + void* user_data); /* API of utilities to find data in the local discovery database */ @@ -272,10 +257,8 @@ bool SDP_ServiceSearchAttributeRequest2 (uint8_t *p_bd_addr, * Returns Pointer to matching record, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, - uint16_t attr_id, - tSDP_DISC_REC *p_start_rec); - +tSDP_DISC_REC* SDP_FindAttributeInDb(tSDP_DISCOVERY_DB* p_db, uint16_t attr_id, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -287,9 +270,7 @@ tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, * Returns Pointer to matching attribute entry, or NULL * ******************************************************************************/ -tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, - uint16_t attr_id); - +tSDP_DISC_ATTR* SDP_FindAttributeInRec(tSDP_DISC_REC* p_rec, uint16_t attr_id); /******************************************************************************* * @@ -303,10 +284,9 @@ tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, - uint16_t service_uuid, - tSDP_DISC_REC *p_start_rec); - +tSDP_DISC_REC* SDP_FindServiceInDb(tSDP_DISCOVERY_DB* p_db, + uint16_t service_uuid, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -324,9 +304,9 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, - tBT_UUID *p_uuid, - tSDP_DISC_REC *p_start_rec); +tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db, + tBT_UUID* p_uuid, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -341,7 +321,7 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, * Returns true if found, otherwise false. * ******************************************************************************/ -bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid); +bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid); /******************************************************************************* * @@ -355,8 +335,8 @@ bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_REC *p_start_rec); +tSDP_DISC_REC* SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_REC* p_start_rec); /******************************************************************************* * @@ -369,10 +349,8 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, * If found, the passed protocol list element is filled in. * ******************************************************************************/ -bool SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, - uint16_t layer_uuid, - tSDP_PROTOCOL_ELEM *p_elem); - +bool SDP_FindProtocolListElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, + tSDP_PROTOCOL_ELEM* p_elem); /******************************************************************************* * @@ -385,10 +363,8 @@ bool SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, * If found, the passed protocol list element is filled in. * ******************************************************************************/ -bool SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, - uint16_t layer_uuid, - tSDP_PROTOCOL_ELEM *p_elem); - +bool SDP_FindAddProtoListsElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, + tSDP_PROTOCOL_ELEM* p_elem); /******************************************************************************* * @@ -404,10 +380,8 @@ bool SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, * passed in are filled in. * ******************************************************************************/ -bool SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, - uint16_t profile_uuid, - uint16_t *p_version); - +bool SDP_FindProfileVersionInRec(tSDP_DISC_REC* p_rec, uint16_t profile_uuid, + uint16_t* p_version); /* API into SDP for local service database updates */ @@ -423,8 +397,7 @@ bool SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, * Returns Record handle if OK, else 0. * ******************************************************************************/ -uint32_t SDP_CreateRecord (void); - +uint32_t SDP_CreateRecord(void); /******************************************************************************* * @@ -439,8 +412,7 @@ uint32_t SDP_CreateRecord (void); * Returns true if succeeded, else false * ******************************************************************************/ -bool SDP_DeleteRecord (uint32_t handle); - +bool SDP_DeleteRecord(uint32_t handle); /******************************************************************************* * @@ -455,7 +427,7 @@ bool SDP_DeleteRecord (uint32_t handle); * The size of data copied into p_data is in *p_data_len. * ******************************************************************************/ -int32_t SDP_ReadRecord(uint32_t handle, uint8_t *p_data, int32_t *p_data_len); +int32_t SDP_ReadRecord(uint32_t handle, uint8_t* p_data, int32_t* p_data_len); /******************************************************************************* * @@ -471,10 +443,8 @@ int32_t SDP_ReadRecord(uint32_t handle, uint8_t *p_data, int32_t *p_data_len); * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddAttribute (uint32_t handle, uint16_t attr_id, - uint8_t attr_type, uint32_t attr_len, - uint8_t *p_val); - +bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type, + uint32_t attr_len, uint8_t* p_val); /******************************************************************************* * @@ -490,10 +460,8 @@ bool SDP_AddAttribute (uint32_t handle, uint16_t attr_id, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddSequence (uint32_t handle, uint16_t attr_id, - uint16_t num_elem, uint8_t type[], - uint8_t len[], uint8_t *p_val[]); - +bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem, + uint8_t type[], uint8_t len[], uint8_t* p_val[]); /******************************************************************************* * @@ -507,9 +475,8 @@ bool SDP_AddSequence (uint32_t handle, uint16_t attr_id, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddUuidSequence (uint32_t handle, uint16_t attr_id, - uint16_t num_uuids, uint16_t *p_uuids); - +bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids, + uint16_t* p_uuids); /******************************************************************************* * @@ -523,9 +490,8 @@ bool SDP_AddUuidSequence (uint32_t handle, uint16_t attr_id, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddProtocolList (uint32_t handle, uint16_t num_elem, - tSDP_PROTOCOL_ELEM *p_elem_list); - +bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem, + tSDP_PROTOCOL_ELEM* p_elem_list); /******************************************************************************* * @@ -539,9 +505,8 @@ bool SDP_AddProtocolList (uint32_t handle, uint16_t num_elem, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddAdditionProtoLists (uint32_t handle, uint16_t num_elem, - tSDP_PROTO_LIST_ELEM *p_proto_list); - +bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem, + tSDP_PROTO_LIST_ELEM* p_proto_list); /******************************************************************************* * @@ -555,9 +520,8 @@ bool SDP_AddAdditionProtoLists (uint32_t handle, uint16_t num_elem, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddProfileDescriptorList (uint32_t handle, - uint16_t profile_uuid, - uint16_t version); +bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid, + uint16_t version); /******************************************************************************* * @@ -571,9 +535,8 @@ bool SDP_AddProfileDescriptorList (uint32_t handle, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddLanguageBaseAttrIDList (uint32_t handle, - uint16_t lang, uint16_t char_enc, - uint16_t base_id); +bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang, + uint16_t char_enc, uint16_t base_id); /******************************************************************************* * @@ -587,9 +550,8 @@ bool SDP_AddLanguageBaseAttrIDList (uint32_t handle, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddServiceClassIdList (uint32_t handle, - uint16_t num_services, - uint16_t *p_service_uuids); +bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services, + uint16_t* p_service_uuids); /******************************************************************************* * @@ -601,7 +563,7 @@ bool SDP_AddServiceClassIdList (uint32_t handle, * Returns true if deleted OK, else false if not found * ******************************************************************************/ -bool SDP_DeleteAttribute (uint32_t handle, uint16_t attr_id); +bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id); /* Device Identification APIs */ @@ -614,8 +576,7 @@ bool SDP_DeleteAttribute (uint32_t handle, uint16_t attr_id); * Returns Returns SDP_SUCCESS if record added successfully, else error * ******************************************************************************/ -uint16_t SDP_SetLocalDiRecord (tSDP_DI_RECORD *device_info, - uint32_t *p_handle); +uint16_t SDP_SetLocalDiRecord(tSDP_DI_RECORD* device_info, uint32_t* p_handle); /******************************************************************************* * @@ -626,9 +587,8 @@ uint16_t SDP_SetLocalDiRecord (tSDP_DI_RECORD *device_info, * Returns SDP_SUCCESS if query started successfully, else error * ******************************************************************************/ -uint16_t SDP_DiDiscover (BD_ADDR remote_device, - tSDP_DISCOVERY_DB *p_db, uint32_t len, - tSDP_DISC_CMPL_CB *p_cb); +uint16_t SDP_DiDiscover(BD_ADDR remote_device, tSDP_DISCOVERY_DB* p_db, + uint32_t len, tSDP_DISC_CMPL_CB* p_cb); /******************************************************************************* * @@ -639,7 +599,7 @@ uint16_t SDP_DiDiscover (BD_ADDR remote_device, * Returns number of DI records found * ******************************************************************************/ -uint8_t SDP_GetNumDiRecords (tSDP_DISCOVERY_DB *p_db); +uint8_t SDP_GetNumDiRecords(tSDP_DISCOVERY_DB* p_db); /******************************************************************************* * @@ -651,9 +611,9 @@ uint8_t SDP_GetNumDiRecords (tSDP_DISCOVERY_DB *p_db); * Returns SDP_SUCCESS if record retrieved, else error * ******************************************************************************/ -uint16_t SDP_GetDiRecord (uint8_t getRecordIndex, - tSDP_DI_GET_RECORD *device_info, - tSDP_DISCOVERY_DB *p_db); +uint16_t SDP_GetDiRecord(uint8_t getRecordIndex, + tSDP_DI_GET_RECORD* device_info, + tSDP_DISCOVERY_DB* p_db); /******************************************************************************* * @@ -665,7 +625,7 @@ uint16_t SDP_GetDiRecord (uint8_t getRecordIndex, * Returns the new (current) trace level * ******************************************************************************/ -uint8_t SDP_SetTraceLevel (uint8_t new_level); +uint8_t SDP_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -679,7 +639,7 @@ uint8_t SDP_SetTraceLevel (uint8_t new_level); * Returns true if found, otherwise false. * ******************************************************************************/ -bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID *p_uuid); +bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid); // Converts UUID-16 to UUID-128 by including the base UUID. // |uuid16| is the 2-byte UUID to convert. @@ -690,4 +650,4 @@ void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128); } #endif -#endif /* SDP_API_H */ +#endif /* SDP_API_H */ diff --git a/stack/include/sdpdefs.h b/stack/include/sdpdefs.h index 7985bc26a..d5dc80f36 100644 --- a/stack/include/sdpdefs.h +++ b/stack/include/sdpdefs.h @@ -27,316 +27,313 @@ /* Define the service attribute IDs. */ -#define ATTR_ID_SERVICE_RECORD_HDL 0x0000 -#define ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 -#define ATTR_ID_SERVICE_RECORD_STATE 0x0002 -#define ATTR_ID_SERVICE_ID 0x0003 -#define ATTR_ID_PROTOCOL_DESC_LIST 0x0004 -#define ATTR_ID_BROWSE_GROUP_LIST 0x0005 -#define ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST 0x0006 -#define ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 -#define ATTR_ID_SERVICE_AVAILABILITY 0x0008 -#define ATTR_ID_BT_PROFILE_DESC_LIST 0x0009 -#define ATTR_ID_DOCUMENTATION_URL 0x000A -#define ATTR_ID_CLIENT_EXE_URL 0x000B -#define ATTR_ID_ICON_URL 0x000C -#define ATTR_ID_ADDITION_PROTO_DESC_LISTS 0x000D +#define ATTR_ID_SERVICE_RECORD_HDL 0x0000 +#define ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 +#define ATTR_ID_SERVICE_RECORD_STATE 0x0002 +#define ATTR_ID_SERVICE_ID 0x0003 +#define ATTR_ID_PROTOCOL_DESC_LIST 0x0004 +#define ATTR_ID_BROWSE_GROUP_LIST 0x0005 +#define ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST 0x0006 +#define ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 +#define ATTR_ID_SERVICE_AVAILABILITY 0x0008 +#define ATTR_ID_BT_PROFILE_DESC_LIST 0x0009 +#define ATTR_ID_DOCUMENTATION_URL 0x000A +#define ATTR_ID_CLIENT_EXE_URL 0x000B +#define ATTR_ID_ICON_URL 0x000C +#define ATTR_ID_ADDITION_PROTO_DESC_LISTS 0x000D -#define LANGUAGE_BASE_ID 0x0100 -#define ATTR_ID_SERVICE_NAME (LANGUAGE_BASE_ID + 0x0000) -#define ATTR_ID_SERVICE_DESCRIPTION (LANGUAGE_BASE_ID + 0x0001) -#define ATTR_ID_PROVIDER_NAME (LANGUAGE_BASE_ID + 0x0002) +#define LANGUAGE_BASE_ID 0x0100 +#define ATTR_ID_SERVICE_NAME (LANGUAGE_BASE_ID + 0x0000) +#define ATTR_ID_SERVICE_DESCRIPTION (LANGUAGE_BASE_ID + 0x0001) +#define ATTR_ID_PROVIDER_NAME (LANGUAGE_BASE_ID + 0x0002) /* Device Identification (DI) */ -#define ATTR_ID_SPECIFICATION_ID 0x0200 -#define ATTR_ID_VENDOR_ID 0x0201 -#define ATTR_ID_PRODUCT_ID 0x0202 -#define ATTR_ID_PRODUCT_VERSION 0x0203 -#define ATTR_ID_PRIMARY_RECORD 0x0204 -#define ATTR_ID_VENDOR_ID_SOURCE 0x0205 +#define ATTR_ID_SPECIFICATION_ID 0x0200 +#define ATTR_ID_VENDOR_ID 0x0201 +#define ATTR_ID_PRODUCT_ID 0x0202 +#define ATTR_ID_PRODUCT_VERSION 0x0203 +#define ATTR_ID_PRIMARY_RECORD 0x0204 +#define ATTR_ID_VENDOR_ID_SOURCE 0x0205 -#define BLUETOOTH_DI_SPECIFICATION 0x0103 /* 1.3 */ -#define DI_VENDOR_ID_DEFAULT 0xFFFF -#define DI_VENDOR_ID_SOURCE_BTSIG 0x0001 -#define DI_VENDOR_ID_SOURCE_USBIF 0x0002 +#define BLUETOOTH_DI_SPECIFICATION 0x0103 /* 1.3 */ +#define DI_VENDOR_ID_DEFAULT 0xFFFF +#define DI_VENDOR_ID_SOURCE_BTSIG 0x0001 +#define DI_VENDOR_ID_SOURCE_USBIF 0x0002 +#define ATTR_ID_IP_SUBNET 0x0200 /* PAN Profile (***) */ +#define ATTR_ID_VERSION_NUMBER_LIST 0x0200 +#define ATTR_ID_GOEP_L2CAP_PSM 0x0200 +#define ATTR_ID_GROUP_ID 0x0200 +#define ATTR_ID_SERVICE_DATABASE_STATE 0x0201 +#define ATTR_ID_SERVICE_VERSION 0x0300 +#define ATTR_ID_HCRP_1284ID 0x0300 -#define ATTR_ID_IP_SUBNET 0x0200 /* PAN Profile (***) */ -#define ATTR_ID_VERSION_NUMBER_LIST 0x0200 -#define ATTR_ID_GOEP_L2CAP_PSM 0x0200 -#define ATTR_ID_GROUP_ID 0x0200 -#define ATTR_ID_SERVICE_DATABASE_STATE 0x0201 -#define ATTR_ID_SERVICE_VERSION 0x0300 -#define ATTR_ID_HCRP_1284ID 0x0300 - -#define ATTR_ID_SUPPORTED_DATA_STORES 0x0301 -#define ATTR_ID_NETWORK 0x0301 -#define ATTR_ID_EXTERNAL_NETWORK 0x0301 -#define ATTR_ID_FAX_CLASS_1_SUPPORT 0x0302 -#define ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 -#define ATTR_ID_DEVICE_NAME 0x0302 -#define ATTR_ID_SUPPORTED_FORMATS_LIST 0x0303 -#define ATTR_ID_FAX_CLASS_2_0_SUPPORT 0x0303 -#define ATTR_ID_FAX_CLASS_2_SUPPORT 0x0304 -#define ATTR_ID_FRIENDLY_NAME 0x0304 -#define ATTR_ID_AUDIO_FEEDBACK_SUPPORT 0x0305 -#define ATTR_ID_NETWORK_ADDRESS 0x0306 -#define ATTR_ID_DEVICE_LOCATION 0x0306 -#define ATTR_ID_WAP_GATEWAY 0x0307 -#define ATTR_ID_HOME_PAGE_URL 0x0308 -#define ATTR_ID_WAP_STACK_TYPE 0x0309 -#define ATTR_ID_IMG_SUPPORTED_CAPABILITIES 0x0310 /* Imaging Profile */ -#define ATTR_ID_SUPPORTED_FEATURES 0x0311 /* HFP, BIP */ -#define ATTR_ID_IMG_SUPPORTED_FUNCTIONS 0x0312 /* Imaging Profile */ -#define ATTR_ID_IMG_TOT_DATA_CAPABILITY 0x0313 /* Imaging Profile */ -#define ATTR_ID_SUPPORTED_REPOSITORIES 0x0314 /* Phone book access Profile */ -#define ATTR_ID_MAS_INSTANCE_ID 0x0315 /* MAP profile */ -#define ATTR_ID_SUPPORTED_MSG_TYPE 0x0316 /* MAP profile */ -#define ATTR_ID_MAP_SUPPORTED_FEATURES 0x0317 /* MAP profile */ -#define ATTR_ID_PBAP_SUPPORTED_FEATURES 0x0317 /* PBAP profile */ - +#define ATTR_ID_SUPPORTED_DATA_STORES 0x0301 +#define ATTR_ID_NETWORK 0x0301 +#define ATTR_ID_EXTERNAL_NETWORK 0x0301 +#define ATTR_ID_FAX_CLASS_1_SUPPORT 0x0302 +#define ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 +#define ATTR_ID_DEVICE_NAME 0x0302 +#define ATTR_ID_SUPPORTED_FORMATS_LIST 0x0303 +#define ATTR_ID_FAX_CLASS_2_0_SUPPORT 0x0303 +#define ATTR_ID_FAX_CLASS_2_SUPPORT 0x0304 +#define ATTR_ID_FRIENDLY_NAME 0x0304 +#define ATTR_ID_AUDIO_FEEDBACK_SUPPORT 0x0305 +#define ATTR_ID_NETWORK_ADDRESS 0x0306 +#define ATTR_ID_DEVICE_LOCATION 0x0306 +#define ATTR_ID_WAP_GATEWAY 0x0307 +#define ATTR_ID_HOME_PAGE_URL 0x0308 +#define ATTR_ID_WAP_STACK_TYPE 0x0309 +#define ATTR_ID_IMG_SUPPORTED_CAPABILITIES 0x0310 /* Imaging Profile */ +#define ATTR_ID_SUPPORTED_FEATURES 0x0311 /* HFP, BIP */ +#define ATTR_ID_IMG_SUPPORTED_FUNCTIONS 0x0312 /* Imaging Profile */ +#define ATTR_ID_IMG_TOT_DATA_CAPABILITY 0x0313 /* Imaging Profile */ +#define ATTR_ID_SUPPORTED_REPOSITORIES 0x0314 /* Phone book access Profile */ +#define ATTR_ID_MAS_INSTANCE_ID 0x0315 /* MAP profile */ +#define ATTR_ID_SUPPORTED_MSG_TYPE 0x0316 /* MAP profile */ +#define ATTR_ID_MAP_SUPPORTED_FEATURES 0x0317 /* MAP profile */ +#define ATTR_ID_PBAP_SUPPORTED_FEATURES 0x0317 /* PBAP profile */ /* These values are for the BPP profile */ -#define ATTR_ID_DOCUMENT_FORMATS_SUPPORTED 0x0350 +#define ATTR_ID_DOCUMENT_FORMATS_SUPPORTED 0x0350 #define ATTR_ID_CHARACTER_REPERTOIRES_SUPPORTED 0x0352 -#define ATTR_ID_XHTML_IMAGE_FORMATS_SUPPORTED 0x0354 -#define ATTR_ID_COLOR_SUPPORTED 0x0356 -#define ATTR_ID_1284ID 0x0358 -#define ATTR_ID_PRINTER_NAME 0x035A -#define ATTR_ID_PRINTER_LOCATION 0x035C -#define ATTR_ID_DUPLEX_SUPPORTED 0x035E -#define ATTR_ID_MEDIA_TYPES_SUPPORTED 0x0360 -#define ATTR_ID_MAX_MEDIA_WIDTH 0x0362 -#define ATTR_ID_MAX_MEDIA_LENGTH 0x0364 -#define ATTR_ID_ENHANCED_LAYOUT_SUPPORTED 0x0366 -#define ATTR_ID_RUI_FORMATS_SUPPORTED 0x0368 -#define ATTR_ID_RUI_REF_PRINTING_SUPPORTED 0x0370 /* Boolean */ -#define ATTR_ID_RUI_DIRECT_PRINTING_SUPPORTED 0x0372 /* Boolean */ -#define ATTR_ID_REF_PRINTING_TOP_URL 0x0374 -#define ATTR_ID_DIRECT_PRINTING_TOP_URL 0x0376 -#define ATTR_ID_PRINTER_ADMIN_RUI_TOP_URL 0x0378 -#define ATTR_ID_BPP_DEVICE_NAME 0x037A +#define ATTR_ID_XHTML_IMAGE_FORMATS_SUPPORTED 0x0354 +#define ATTR_ID_COLOR_SUPPORTED 0x0356 +#define ATTR_ID_1284ID 0x0358 +#define ATTR_ID_PRINTER_NAME 0x035A +#define ATTR_ID_PRINTER_LOCATION 0x035C +#define ATTR_ID_DUPLEX_SUPPORTED 0x035E +#define ATTR_ID_MEDIA_TYPES_SUPPORTED 0x0360 +#define ATTR_ID_MAX_MEDIA_WIDTH 0x0362 +#define ATTR_ID_MAX_MEDIA_LENGTH 0x0364 +#define ATTR_ID_ENHANCED_LAYOUT_SUPPORTED 0x0366 +#define ATTR_ID_RUI_FORMATS_SUPPORTED 0x0368 +#define ATTR_ID_RUI_REF_PRINTING_SUPPORTED 0x0370 /* Boolean */ +#define ATTR_ID_RUI_DIRECT_PRINTING_SUPPORTED 0x0372 /* Boolean */ +#define ATTR_ID_REF_PRINTING_TOP_URL 0x0374 +#define ATTR_ID_DIRECT_PRINTING_TOP_URL 0x0376 +#define ATTR_ID_PRINTER_ADMIN_RUI_TOP_URL 0x0378 +#define ATTR_ID_BPP_DEVICE_NAME 0x037A /* These values are for the PAN profile */ -#define ATTR_ID_SECURITY_DESCRIPTION 0x030A -#define ATTR_ID_NET_ACCESS_TYPE 0x030B -#define ATTR_ID_MAX_NET_ACCESS_RATE 0x030C -#define ATTR_ID_IPV4_SUBNET 0x030D -#define ATTR_ID_IPV6_SUBNET 0x030E -#define ATTR_ID_PAN_SECURITY 0x0400 +#define ATTR_ID_SECURITY_DESCRIPTION 0x030A +#define ATTR_ID_NET_ACCESS_TYPE 0x030B +#define ATTR_ID_MAX_NET_ACCESS_RATE 0x030C +#define ATTR_ID_IPV4_SUBNET 0x030D +#define ATTR_ID_IPV6_SUBNET 0x030E +#define ATTR_ID_PAN_SECURITY 0x0400 /* These values are for HID profile */ -#define ATTR_ID_HID_DEVICE_RELNUM 0x0200 -#define ATTR_ID_HID_PARSER_VERSION 0x0201 -#define ATTR_ID_HID_DEVICE_SUBCLASS 0x0202 -#define ATTR_ID_HID_COUNTRY_CODE 0x0203 -#define ATTR_ID_HID_VIRTUAL_CABLE 0x0204 -#define ATTR_ID_HID_RECONNECT_INITIATE 0x0205 -#define ATTR_ID_HID_DESCRIPTOR_LIST 0x0206 -#define ATTR_ID_HID_LANGUAGE_ID_BASE 0x0207 -#define ATTR_ID_HID_SDP_DISABLE 0x0208 -#define ATTR_ID_HID_BATTERY_POWER 0x0209 -#define ATTR_ID_HID_REMOTE_WAKE 0x020A -#define ATTR_ID_HID_PROFILE_VERSION 0x020B -#define ATTR_ID_HID_LINK_SUPERVISION_TO 0x020C -#define ATTR_ID_HID_NORMALLY_CONNECTABLE 0x020D -#define ATTR_ID_HID_BOOT_DEVICE 0x020E -#define ATTR_ID_HID_SSR_HOST_MAX_LAT 0x020F -#define ATTR_ID_HID_SSR_HOST_MIN_TOUT 0x0210 +#define ATTR_ID_HID_DEVICE_RELNUM 0x0200 +#define ATTR_ID_HID_PARSER_VERSION 0x0201 +#define ATTR_ID_HID_DEVICE_SUBCLASS 0x0202 +#define ATTR_ID_HID_COUNTRY_CODE 0x0203 +#define ATTR_ID_HID_VIRTUAL_CABLE 0x0204 +#define ATTR_ID_HID_RECONNECT_INITIATE 0x0205 +#define ATTR_ID_HID_DESCRIPTOR_LIST 0x0206 +#define ATTR_ID_HID_LANGUAGE_ID_BASE 0x0207 +#define ATTR_ID_HID_SDP_DISABLE 0x0208 +#define ATTR_ID_HID_BATTERY_POWER 0x0209 +#define ATTR_ID_HID_REMOTE_WAKE 0x020A +#define ATTR_ID_HID_PROFILE_VERSION 0x020B +#define ATTR_ID_HID_LINK_SUPERVISION_TO 0x020C +#define ATTR_ID_HID_NORMALLY_CONNECTABLE 0x020D +#define ATTR_ID_HID_BOOT_DEVICE 0x020E +#define ATTR_ID_HID_SSR_HOST_MAX_LAT 0x020F +#define ATTR_ID_HID_SSR_HOST_MIN_TOUT 0x0210 /* These values are for the HDP profile */ -#define ATTR_ID_HDP_SUP_FEAT_LIST 0x0200 /* Supported features list */ -#define ATTR_ID_HDP_DATA_EXCH_SPEC 0x0301 /* Data exchange specification */ -#define ATTR_ID_HDP_MCAP_SUP_PROC 0x0302 /* MCAP supported procedures */ +#define ATTR_ID_HDP_SUP_FEAT_LIST 0x0200 /* Supported features list */ +#define ATTR_ID_HDP_DATA_EXCH_SPEC 0x0301 /* Data exchange specification */ +#define ATTR_ID_HDP_MCAP_SUP_PROC 0x0302 /* MCAP supported procedures */ /* Define common 16-bit protocol UUIDs */ -#define UUID_PROTOCOL_SDP 0x0001 -#define UUID_PROTOCOL_UDP 0x0002 -#define UUID_PROTOCOL_RFCOMM 0x0003 -#define UUID_PROTOCOL_TCP 0x0004 -#define UUID_PROTOCOL_TCS_BIN 0x0005 -#define UUID_PROTOCOL_TCS_AT 0x0006 -#define UUID_PROTOCOL_OBEX 0x0008 -#define UUID_PROTOCOL_IP 0x0009 -#define UUID_PROTOCOL_FTP 0x000A -#define UUID_PROTOCOL_HTTP 0x000C -#define UUID_PROTOCOL_WSP 0x000E -#define UUID_PROTOCOL_BNEP 0x000F -#define UUID_PROTOCOL_UPNP 0x0010 -#define UUID_PROTOCOL_HIDP 0x0011 -#define UUID_PROTOCOL_HCRP_CTRL 0x0012 -#define UUID_PROTOCOL_HCRP_DATA 0x0014 -#define UUID_PROTOCOL_HCRP_NOTIF 0x0016 -#define UUID_PROTOCOL_AVCTP 0x0017 -#define UUID_PROTOCOL_AVDTP 0x0019 -#define UUID_PROTOCOL_CMTP 0x001B -#define UUID_PROTOCOL_UDI 0x001D -#define UUID_PROTOCOL_MCAP_CTRL 0x001E -#define UUID_PROTOCOL_MCAP_DATA 0x001F -#define UUID_PROTOCOL_L2CAP 0x0100 -#define UUID_PROTOCOL_ATT 0x0007 +#define UUID_PROTOCOL_SDP 0x0001 +#define UUID_PROTOCOL_UDP 0x0002 +#define UUID_PROTOCOL_RFCOMM 0x0003 +#define UUID_PROTOCOL_TCP 0x0004 +#define UUID_PROTOCOL_TCS_BIN 0x0005 +#define UUID_PROTOCOL_TCS_AT 0x0006 +#define UUID_PROTOCOL_OBEX 0x0008 +#define UUID_PROTOCOL_IP 0x0009 +#define UUID_PROTOCOL_FTP 0x000A +#define UUID_PROTOCOL_HTTP 0x000C +#define UUID_PROTOCOL_WSP 0x000E +#define UUID_PROTOCOL_BNEP 0x000F +#define UUID_PROTOCOL_UPNP 0x0010 +#define UUID_PROTOCOL_HIDP 0x0011 +#define UUID_PROTOCOL_HCRP_CTRL 0x0012 +#define UUID_PROTOCOL_HCRP_DATA 0x0014 +#define UUID_PROTOCOL_HCRP_NOTIF 0x0016 +#define UUID_PROTOCOL_AVCTP 0x0017 +#define UUID_PROTOCOL_AVDTP 0x0019 +#define UUID_PROTOCOL_CMTP 0x001B +#define UUID_PROTOCOL_UDI 0x001D +#define UUID_PROTOCOL_MCAP_CTRL 0x001E +#define UUID_PROTOCOL_MCAP_DATA 0x001F +#define UUID_PROTOCOL_L2CAP 0x0100 +#define UUID_PROTOCOL_ATT 0x0007 /* Define common 16-bit service class UUIDs */ #define UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER 0X1000 -#define UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR 0X1001 -#define UUID_SERVCLASS_PUBLIC_BROWSE_GROUP 0X1002 -#define UUID_SERVCLASS_SERIAL_PORT 0X1101 -#define UUID_SERVCLASS_LAN_ACCESS_USING_PPP 0X1102 -#define UUID_SERVCLASS_DIALUP_NETWORKING 0X1103 -#define UUID_SERVCLASS_IRMC_SYNC 0X1104 -#define UUID_SERVCLASS_OBEX_OBJECT_PUSH 0X1105 -#define UUID_SERVCLASS_OBEX_FILE_TRANSFER 0X1106 -#define UUID_SERVCLASS_IRMC_SYNC_COMMAND 0X1107 -#define UUID_SERVCLASS_HEADSET 0X1108 -#define UUID_SERVCLASS_CORDLESS_TELEPHONY 0X1109 -#define UUID_SERVCLASS_AUDIO_SOURCE 0X110A -#define UUID_SERVCLASS_AUDIO_SINK 0X110B +#define UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR 0X1001 +#define UUID_SERVCLASS_PUBLIC_BROWSE_GROUP 0X1002 +#define UUID_SERVCLASS_SERIAL_PORT 0X1101 +#define UUID_SERVCLASS_LAN_ACCESS_USING_PPP 0X1102 +#define UUID_SERVCLASS_DIALUP_NETWORKING 0X1103 +#define UUID_SERVCLASS_IRMC_SYNC 0X1104 +#define UUID_SERVCLASS_OBEX_OBJECT_PUSH 0X1105 +#define UUID_SERVCLASS_OBEX_FILE_TRANSFER 0X1106 +#define UUID_SERVCLASS_IRMC_SYNC_COMMAND 0X1107 +#define UUID_SERVCLASS_HEADSET 0X1108 +#define UUID_SERVCLASS_CORDLESS_TELEPHONY 0X1109 +#define UUID_SERVCLASS_AUDIO_SOURCE 0X110A +#define UUID_SERVCLASS_AUDIO_SINK 0X110B /* Audio/Video Control profile */ -#define UUID_SERVCLASS_AV_REM_CTRL_TARGET 0X110C +#define UUID_SERVCLASS_AV_REM_CTRL_TARGET 0X110C /* Advanced Audio Distribution profile */ -#define UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION 0X110D +#define UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION 0X110D /* Audio/Video Control profile */ -#define UUID_SERVCLASS_AV_REMOTE_CONTROL 0X110E +#define UUID_SERVCLASS_AV_REMOTE_CONTROL 0X110E /* Audio/Video Control profile */ -#define UUID_SERVCLASS_AV_REM_CTRL_CONTROL 0X110F -#define UUID_SERVCLASS_INTERCOM 0X1110 -#define UUID_SERVCLASS_FAX 0X1111 -#define UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY 0X1112 -#define UUID_SERVCLASS_WAP 0X1113 -#define UUID_SERVCLASS_WAP_CLIENT 0X1114 -#define UUID_SERVCLASS_PANU 0X1115 /* PAN profile */ -#define UUID_SERVCLASS_NAP 0X1116 /* PAN profile */ -#define UUID_SERVCLASS_GN 0X1117 /* PAN profile */ -#define UUID_SERVCLASS_DIRECT_PRINTING 0X1118 /* BPP profile */ -#define UUID_SERVCLASS_REFERENCE_PRINTING 0X1119 /* BPP profile */ -#define UUID_SERVCLASS_IMAGING 0X111A /* Imaging profile */ -#define UUID_SERVCLASS_IMAGING_RESPONDER 0X111B /* Imaging profile */ -#define UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE 0X111C /* Imaging profile */ -#define UUID_SERVCLASS_IMAGING_REF_OBJECTS 0X111D /* Imaging profile */ -#define UUID_SERVCLASS_HF_HANDSFREE 0X111E /* Handsfree profile */ -#define UUID_SERVCLASS_AG_HANDSFREE 0X111F /* Handsfree profile */ -#define UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE 0X1120 /* BPP profile */ -#define UUID_SERVCLASS_REFLECTED_UI 0X1121 /* BPP profile */ -#define UUID_SERVCLASS_BASIC_PRINTING 0X1122 /* BPP profile */ -#define UUID_SERVCLASS_PRINTING_STATUS 0X1123 /* BPP profile */ -#define UUID_SERVCLASS_HUMAN_INTERFACE 0X1124 /* HID profile */ -#define UUID_SERVCLASS_CABLE_REPLACEMENT 0X1125 /* HCRP profile */ -#define UUID_SERVCLASS_HCRP_PRINT 0X1126 /* HCRP profile */ -#define UUID_SERVCLASS_HCRP_SCAN 0X1127 /* HCRP profile */ +#define UUID_SERVCLASS_AV_REM_CTRL_CONTROL 0X110F +#define UUID_SERVCLASS_INTERCOM 0X1110 +#define UUID_SERVCLASS_FAX 0X1111 +#define UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY 0X1112 +#define UUID_SERVCLASS_WAP 0X1113 +#define UUID_SERVCLASS_WAP_CLIENT 0X1114 +#define UUID_SERVCLASS_PANU 0X1115 /* PAN profile */ +#define UUID_SERVCLASS_NAP 0X1116 /* PAN profile */ +#define UUID_SERVCLASS_GN 0X1117 /* PAN profile */ +#define UUID_SERVCLASS_DIRECT_PRINTING 0X1118 /* BPP profile */ +#define UUID_SERVCLASS_REFERENCE_PRINTING 0X1119 /* BPP profile */ +#define UUID_SERVCLASS_IMAGING 0X111A /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_RESPONDER 0X111B /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE 0X111C /* Imaging profile */ +#define UUID_SERVCLASS_IMAGING_REF_OBJECTS 0X111D /* Imaging profile */ +#define UUID_SERVCLASS_HF_HANDSFREE 0X111E /* Handsfree profile */ +#define UUID_SERVCLASS_AG_HANDSFREE 0X111F /* Handsfree profile */ +#define UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE 0X1120 /* BPP profile */ +#define UUID_SERVCLASS_REFLECTED_UI 0X1121 /* BPP profile */ +#define UUID_SERVCLASS_BASIC_PRINTING 0X1122 /* BPP profile */ +#define UUID_SERVCLASS_PRINTING_STATUS 0X1123 /* BPP profile */ +#define UUID_SERVCLASS_HUMAN_INTERFACE 0X1124 /* HID profile */ +#define UUID_SERVCLASS_CABLE_REPLACEMENT 0X1125 /* HCRP profile */ +#define UUID_SERVCLASS_HCRP_PRINT 0X1126 /* HCRP profile */ +#define UUID_SERVCLASS_HCRP_SCAN 0X1127 /* HCRP profile */ /* CAPI Message Transport Protocol*/ -#define UUID_SERVCLASS_COMMON_ISDN_ACCESS 0X1128 +#define UUID_SERVCLASS_COMMON_ISDN_ACCESS 0X1128 /* Video Conferencing profile */ -#define UUID_SERVCLASS_VIDEO_CONFERENCING_GW 0X1129 +#define UUID_SERVCLASS_VIDEO_CONFERENCING_GW 0X1129 /* Unrestricted Digital Information profile */ -#define UUID_SERVCLASS_UDI_MT 0X112A +#define UUID_SERVCLASS_UDI_MT 0X112A /* Unrestricted Digital Information profile */ -#define UUID_SERVCLASS_UDI_TA 0X112B -#define UUID_SERVCLASS_VCP 0X112C /* Video Conferencing profile */ -#define UUID_SERVCLASS_SAP 0X112D /* SIM Access profile */ -#define UUID_SERVCLASS_PBAP_PCE 0X112E /* Phonebook Access - PCE */ -#define UUID_SERVCLASS_PBAP_PSE 0X112F /* Phonebook Access - PSE */ -#define UUID_SERVCLASS_PHONE_ACCESS 0x1130 -#define UUID_SERVCLASS_HEADSET_HS 0x1131 /* Headset - HS, from HSP v1.2 */ -#define UUID_SERVCLASS_PNP_INFORMATION 0X1200 /* Device Identification */ -#define UUID_SERVCLASS_GENERIC_NETWORKING 0X1201 -#define UUID_SERVCLASS_GENERIC_FILETRANSFER 0X1202 -#define UUID_SERVCLASS_GENERIC_AUDIO 0X1203 -#define UUID_SERVCLASS_GENERIC_TELEPHONY 0X1204 -#define UUID_SERVCLASS_UPNP_SERVICE 0X1205 /* UPNP_Service [ESDP] */ -#define UUID_SERVCLASS_UPNP_IP_SERVICE 0X1206 /* UPNP_IP_Service [ESDP] */ -#define UUID_SERVCLASS_ESDP_UPNP_IP_PAN 0X1300 /* UPNP_IP_PAN [ESDP] */ -#define UUID_SERVCLASS_ESDP_UPNP_IP_LAP 0X1301 /* UPNP_IP_LAP [ESDP] */ -#define UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP 0X1302 /* UPNP_L2CAP [ESDP] */ +#define UUID_SERVCLASS_UDI_TA 0X112B +#define UUID_SERVCLASS_VCP 0X112C /* Video Conferencing profile */ +#define UUID_SERVCLASS_SAP 0X112D /* SIM Access profile */ +#define UUID_SERVCLASS_PBAP_PCE 0X112E /* Phonebook Access - PCE */ +#define UUID_SERVCLASS_PBAP_PSE 0X112F /* Phonebook Access - PSE */ +#define UUID_SERVCLASS_PHONE_ACCESS 0x1130 +#define UUID_SERVCLASS_HEADSET_HS 0x1131 /* Headset - HS, from HSP v1.2 */ +#define UUID_SERVCLASS_PNP_INFORMATION 0X1200 /* Device Identification */ +#define UUID_SERVCLASS_GENERIC_NETWORKING 0X1201 +#define UUID_SERVCLASS_GENERIC_FILETRANSFER 0X1202 +#define UUID_SERVCLASS_GENERIC_AUDIO 0X1203 +#define UUID_SERVCLASS_GENERIC_TELEPHONY 0X1204 +#define UUID_SERVCLASS_UPNP_SERVICE 0X1205 /* UPNP_Service [ESDP] */ +#define UUID_SERVCLASS_UPNP_IP_SERVICE 0X1206 /* UPNP_IP_Service [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_PAN 0X1300 /* UPNP_IP_PAN [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_LAP 0X1301 /* UPNP_IP_LAP [ESDP] */ +#define UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP 0X1302 /* UPNP_L2CAP [ESDP] */ /* Video Distribution Profile (VDP) */ -#define UUID_SERVCLASS_VIDEO_SOURCE 0X1303 -#define UUID_SERVCLASS_VIDEO_SINK 0X1304 -#define UUID_SERVCLASS_VIDEO_DISTRIBUTION 0X1305 +#define UUID_SERVCLASS_VIDEO_SOURCE 0X1303 +#define UUID_SERVCLASS_VIDEO_SINK 0X1304 +#define UUID_SERVCLASS_VIDEO_DISTRIBUTION 0X1305 -#define UUID_SERVCLASS_HDP_PROFILE 0X1400 /* Health Device profile (HDP) */ -#define UUID_SERVCLASS_HDP_SOURCE 0X1401 /* Health Device profile (HDP) */ -#define UUID_SERVCLASS_HDP_SINK 0X1402 /* Health Device profile (HDP) */ -#define UUID_SERVCLASS_MAP_PROFILE 0X1134 /* MAP profile */ -#define UUID_SERVCLASS_MESSAGE_ACCESS 0X1132 /* Message Access Service */ -#define UUID_SERVCLASS_MESSAGE_NOTIFICATION 0X1133 /* Message Notification Service */ +#define UUID_SERVCLASS_HDP_PROFILE 0X1400 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_HDP_SOURCE 0X1401 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_HDP_SINK 0X1402 /* Health Device profile (HDP) */ +#define UUID_SERVCLASS_MAP_PROFILE 0X1134 /* MAP profile */ +#define UUID_SERVCLASS_MESSAGE_ACCESS 0X1132 /* Message Access Service */ +#define UUID_SERVCLASS_MESSAGE_NOTIFICATION \ + 0X1133 /* Message Notification Service */ -#define UUID_SERVCLASS_GAP_SERVER 0x1800 -#define UUID_SERVCLASS_GATT_SERVER 0x1801 -#define UUID_SERVCLASS_IMMEDIATE_ALERT 0x1802 /* immediate alert */ -#define UUID_SERVCLASS_LINKLOSS 0x1803 /* Link Loss Alert */ -#define UUID_SERVCLASS_TX_POWER 0x1804 /* TX power */ -#define UUID_SERVCLASS_CURRENT_TIME 0x1805 /* Link Loss Alert */ -#define UUID_SERVCLASS_DST_CHG 0x1806 /* DST Time change */ -#define UUID_SERVCLASS_REF_TIME_UPD 0x1807 /* reference time update */ -#define UUID_SERVCLASS_THERMOMETER 0x1809 /* Thermometer UUID */ -#define UUID_SERVCLASS_DEVICE_INFO 0x180A /* device info service */ -#define UUID_SERVCLASS_NWA 0x180B /* Network availability */ -#define UUID_SERVCLASS_HEART_RATE 0x180D /* Heart Rate service */ -#define UUID_SERVCLASS_PHALERT 0x180E /* phone alert service */ -#define UUID_SERVCLASS_BATTERY 0x180F /* battery service */ -#define UUID_SERVCLASS_BPM 0x1810 /* blood pressure service */ -#define UUID_SERVCLASS_ALERT_NOTIFICATION 0x1811 -#define UUID_SERVCLASS_LE_HID 0x1812 /* HID over LE */ -#define UUID_SERVCLASS_SCAN_PARAM 0x1813 /* Scan Parameter service */ -#define UUID_SERVCLASS_GLUCOSE 0x1808 /* Glucose Meter Service */ -#define UUID_SERVCLASS_RSC 0x1814 /* RUNNERS SPEED AND CADENCE SERVICE */ -#define UUID_SERVCLASS_CSC 0x1816 /* Cycling SPEED AND CADENCE SERVICE */ +#define UUID_SERVCLASS_GAP_SERVER 0x1800 +#define UUID_SERVCLASS_GATT_SERVER 0x1801 +#define UUID_SERVCLASS_IMMEDIATE_ALERT 0x1802 /* immediate alert */ +#define UUID_SERVCLASS_LINKLOSS 0x1803 /* Link Loss Alert */ +#define UUID_SERVCLASS_TX_POWER 0x1804 /* TX power */ +#define UUID_SERVCLASS_CURRENT_TIME 0x1805 /* Link Loss Alert */ +#define UUID_SERVCLASS_DST_CHG 0x1806 /* DST Time change */ +#define UUID_SERVCLASS_REF_TIME_UPD 0x1807 /* reference time update */ +#define UUID_SERVCLASS_THERMOMETER 0x1809 /* Thermometer UUID */ +#define UUID_SERVCLASS_DEVICE_INFO 0x180A /* device info service */ +#define UUID_SERVCLASS_NWA 0x180B /* Network availability */ +#define UUID_SERVCLASS_HEART_RATE 0x180D /* Heart Rate service */ +#define UUID_SERVCLASS_PHALERT 0x180E /* phone alert service */ +#define UUID_SERVCLASS_BATTERY 0x180F /* battery service */ +#define UUID_SERVCLASS_BPM 0x1810 /* blood pressure service */ +#define UUID_SERVCLASS_ALERT_NOTIFICATION 0x1811 +#define UUID_SERVCLASS_LE_HID 0x1812 /* HID over LE */ +#define UUID_SERVCLASS_SCAN_PARAM 0x1813 /* Scan Parameter service */ +#define UUID_SERVCLASS_GLUCOSE 0x1808 /* Glucose Meter Service */ +#define UUID_SERVCLASS_RSC 0x1814 /* RUNNERS SPEED AND CADENCE SERVICE */ +#define UUID_SERVCLASS_CSC 0x1816 /* Cycling SPEED AND CADENCE SERVICE */ -#define UUID_SERVCLASS_TEST_SERVER 0x9000 /* Test Group UUID */ +#define UUID_SERVCLASS_TEST_SERVER 0x9000 /* Test Group UUID */ #if (BTM_WBS_INCLUDED == TRUE) -#define UUID_CODEC_CVSD 0x0001 /* CVSD */ -#define UUID_CODEC_MSBC 0x0002 /* mSBC */ +#define UUID_CODEC_CVSD 0x0001 /* CVSD */ +#define UUID_CODEC_MSBC 0x0002 /* mSBC */ #endif -#define UUID_HF_IND_ENHANCED_DRIVER_SAFETY 0x0001 /* Enhanced Safety */ -#define UUID_HF_IND_BATTERY_LEVEL_STATUS 0x0002 /* Battery Status */ +#define UUID_HF_IND_ENHANCED_DRIVER_SAFETY 0x0001 /* Enhanced Safety */ +#define UUID_HF_IND_BATTERY_LEVEL_STATUS 0x0002 /* Battery Status */ /* Define all the 'Descriptor Type' values. */ -#define NULL_DESC_TYPE 0 -#define UINT_DESC_TYPE 1 -#define TWO_COMP_INT_DESC_TYPE 2 -#define UUID_DESC_TYPE 3 -#define TEXT_STR_DESC_TYPE 4 -#define BOOLEAN_DESC_TYPE 5 -#define DATA_ELE_SEQ_DESC_TYPE 6 -#define DATA_ELE_ALT_DESC_TYPE 7 -#define URL_DESC_TYPE 8 +#define NULL_DESC_TYPE 0 +#define UINT_DESC_TYPE 1 +#define TWO_COMP_INT_DESC_TYPE 2 +#define UUID_DESC_TYPE 3 +#define TEXT_STR_DESC_TYPE 4 +#define BOOLEAN_DESC_TYPE 5 +#define DATA_ELE_SEQ_DESC_TYPE 6 +#define DATA_ELE_ALT_DESC_TYPE 7 +#define URL_DESC_TYPE 8 /* Define all the "Descriptor Size" values. */ -#define SIZE_ONE_BYTE 0 -#define SIZE_TWO_BYTES 1 -#define SIZE_FOUR_BYTES 2 -#define SIZE_EIGHT_BYTES 3 -#define SIZE_SIXTEEN_BYTES 4 -#define SIZE_IN_NEXT_BYTE 5 -#define SIZE_IN_NEXT_WORD 6 -#define SIZE_IN_NEXT_LONG 7 +#define SIZE_ONE_BYTE 0 +#define SIZE_TWO_BYTES 1 +#define SIZE_FOUR_BYTES 2 +#define SIZE_EIGHT_BYTES 3 +#define SIZE_SIXTEEN_BYTES 4 +#define SIZE_IN_NEXT_BYTE 5 +#define SIZE_IN_NEXT_WORD 6 +#define SIZE_IN_NEXT_LONG 7 /* Language Encoding Constants */ -#define LANG_ID_CODE_ENGLISH ((uint16_t) 0x656e) /* "en" */ -#define LANG_ID_CHAR_ENCODE_UTF8 ((uint16_t) 0x006a) /* UTF-8 */ +#define LANG_ID_CODE_ENGLISH ((uint16_t)0x656e) /* "en" */ +#define LANG_ID_CHAR_ENCODE_UTF8 ((uint16_t)0x006a) /* UTF-8 */ /* Constants used for display purposes only. These define overlapping attribute * values */ -#define ATTR_ID_VERS_OR_GRP_OR_DRELNUM_OR_IPSUB_OR_SPECID 0x0200 -#define ATTR_ID_VEND_ID_OR_SERVICE_DB_STATE_OR_PARSE_VER 0x0201 -#define ATTR_ID_PROD_ID_OR_HID_DEV_SUBCLASS 0x0202 -#define ATTR_ID_PROD_VER_OR_HID_COUNTRY_CODE 0x0203 -#define ATTR_ID_PRIMARY_REC_OR_HID_VIRTUAL_CABLE 0x0204 -#define ATTR_ID_DI_VENDOR_ID_SOURCE_OR_HID_INIT_RECONNECT 0x0205 -#define ATTR_ID_SERV_VERS_OR_1284ID 0x0300 -#define ATTR_ID_DATA_STORES_OR_NETWORK 0x0301 -#define ATTR_ID_FAX_1_OR_AUD_VOL_OR_DEV_NAME 0x0302 -#define ATTR_ID_FORMATS_OR_FAX_2_0 0x0303 -#define ATTR_ID_FAX_CLASS_2_OR_FRIENDLY_NAME 0x0304 -#define ATTR_ID_NETADDRESS_OR_DEVLOCATION 0x0306 +#define ATTR_ID_VERS_OR_GRP_OR_DRELNUM_OR_IPSUB_OR_SPECID 0x0200 +#define ATTR_ID_VEND_ID_OR_SERVICE_DB_STATE_OR_PARSE_VER 0x0201 +#define ATTR_ID_PROD_ID_OR_HID_DEV_SUBCLASS 0x0202 +#define ATTR_ID_PROD_VER_OR_HID_COUNTRY_CODE 0x0203 +#define ATTR_ID_PRIMARY_REC_OR_HID_VIRTUAL_CABLE 0x0204 +#define ATTR_ID_DI_VENDOR_ID_SOURCE_OR_HID_INIT_RECONNECT 0x0205 +#define ATTR_ID_SERV_VERS_OR_1284ID 0x0300 +#define ATTR_ID_DATA_STORES_OR_NETWORK 0x0301 +#define ATTR_ID_FAX_1_OR_AUD_VOL_OR_DEV_NAME 0x0302 +#define ATTR_ID_FORMATS_OR_FAX_2_0 0x0303 +#define ATTR_ID_FAX_CLASS_2_OR_FRIENDLY_NAME 0x0304 +#define ATTR_ID_NETADDRESS_OR_DEVLOCATION 0x0306 #endif - - diff --git a/stack/include/smp_api.h b/stack/include/smp_api.h index e23828106..d448555e5 100644 --- a/stack/include/smp_api.h +++ b/stack/include/smp_api.h @@ -57,7 +57,7 @@ extern void SMP_Init(void); * Returns The new or current trace level * ******************************************************************************/ -extern uint8_t SMP_SetTraceLevel (uint8_t new_level); +extern uint8_t SMP_SetTraceLevel(uint8_t new_level); /******************************************************************************* * @@ -68,7 +68,7 @@ extern uint8_t SMP_SetTraceLevel (uint8_t new_level); * Returns void * ******************************************************************************/ -extern bool SMP_Register (tSMP_CALLBACK *p_cback); +extern bool SMP_Register(tSMP_CALLBACK* p_cback); /******************************************************************************* * @@ -79,7 +79,7 @@ extern bool SMP_Register (tSMP_CALLBACK *p_cback); * Returns SMP_STARTED if bond started, else otherwise exception. * ******************************************************************************/ -extern tSMP_STATUS SMP_Pair (BD_ADDR bd_addr); +extern tSMP_STATUS SMP_Pair(BD_ADDR bd_addr); /******************************************************************************* * @@ -91,7 +91,7 @@ extern tSMP_STATUS SMP_Pair (BD_ADDR bd_addr); * failure. * ******************************************************************************/ -extern tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr); +extern tSMP_STATUS SMP_BR_PairWith(BD_ADDR bd_addr); /******************************************************************************* * @@ -102,7 +102,7 @@ extern tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr); * Returns true - pairing cancelled * ******************************************************************************/ -extern bool SMP_PairCancel (BD_ADDR bd_addr); +extern bool SMP_PairCancel(BD_ADDR bd_addr); /******************************************************************************* * @@ -134,7 +134,7 @@ extern void SMP_SecurityGrant(BD_ADDR bd_addr, uint8_t res); * BTM_MAX_PASSKEY_VAL(999999(0xF423F)). * ******************************************************************************/ -extern void SMP_PasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey); +extern void SMP_PasskeyReply(BD_ADDR bd_addr, uint8_t res, uint32_t passkey); /******************************************************************************* * @@ -148,7 +148,7 @@ extern void SMP_PasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey); * res - comparison result SMP_SUCCESS if success * ******************************************************************************/ -extern void SMP_ConfirmReply (BD_ADDR bd_addr, uint8_t res); +extern void SMP_ConfirmReply(BD_ADDR bd_addr, uint8_t res); /******************************************************************************* * @@ -163,7 +163,7 @@ extern void SMP_ConfirmReply (BD_ADDR bd_addr, uint8_t res); * ******************************************************************************/ extern void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, uint8_t len, - uint8_t *p_data); + uint8_t* p_data); /******************************************************************************* * @@ -175,7 +175,7 @@ extern void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, uint8_t len, * Parameters: p_data - pointer to the data * ******************************************************************************/ -extern void SMP_SecureConnectionOobDataReply(uint8_t *p_data); +extern void SMP_SecureConnectionOobDataReply(uint8_t* p_data); /******************************************************************************* * @@ -192,9 +192,8 @@ extern void SMP_SecureConnectionOobDataReply(uint8_t *p_data); * * Returns Boolean - true: encryption is successful ******************************************************************************/ -extern bool SMP_Encrypt (uint8_t *key, uint8_t key_len, - uint8_t *plain_text, uint8_t pt_len, - tSMP_ENC *p_out); +extern bool SMP_Encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, tSMP_ENC* p_out); /******************************************************************************* * @@ -207,7 +206,7 @@ extern bool SMP_Encrypt (uint8_t *key, uint8_t key_len, * value - keypress notification parameter value * ******************************************************************************/ -extern void SMP_KeypressNotification (BD_ADDR bd_addr, uint8_t value); +extern void SMP_KeypressNotification(BD_ADDR bd_addr, uint8_t value); /******************************************************************************* * @@ -221,7 +220,8 @@ extern void SMP_KeypressNotification (BD_ADDR bd_addr, uint8_t value); * * Returns Boolean - true: creation of local SC OOB data set started. ******************************************************************************/ -extern bool SMP_CreateLocalSecureConnectionsOobData(tBLE_BD_ADDR *addr_to_send_to); +extern bool SMP_CreateLocalSecureConnectionsOobData( + tBLE_BD_ADDR* addr_to_send_to); // Called when LTK request is received from controller. extern bool smp_proc_ltk_request(BD_ADDR bda); @@ -239,8 +239,8 @@ extern void smp_link_encrypted(BD_ADDR bda, uint8_t encr_enable); // |p_signature| - data pointer to where signed data to be stored, tlen long. // Returns false if out of resources, true in other cases. // -bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t length, - uint16_t tlen, uint8_t *p_signature); +bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t* input, uint16_t length, + uint16_t tlen, uint8_t* p_signature); #ifdef __cplusplus } diff --git a/stack/include/smp_api_types.h b/stack/include/smp_api_types.h index 9813cb2b2..636da26e0 100644 --- a/stack/include/smp_api_types.h +++ b/stack/include/smp_api_types.h @@ -25,276 +25,262 @@ extern "C" { #endif -#define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN -#define SMP_PIN_CODE_LEN_MIN 6 +#define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN +#define SMP_PIN_CODE_LEN_MIN 6 /* SMP command code */ -#define SMP_OPCODE_PAIRING_REQ 0x01 -#define SMP_OPCODE_PAIRING_RSP 0x02 -#define SMP_OPCODE_CONFIRM 0x03 -#define SMP_OPCODE_RAND 0x04 -#define SMP_OPCODE_PAIRING_FAILED 0x05 -#define SMP_OPCODE_ENCRYPT_INFO 0x06 -#define SMP_OPCODE_MASTER_ID 0x07 -#define SMP_OPCODE_IDENTITY_INFO 0x08 -#define SMP_OPCODE_ID_ADDR 0x09 -#define SMP_OPCODE_SIGN_INFO 0x0A -#define SMP_OPCODE_SEC_REQ 0x0B -#define SMP_OPCODE_PAIR_PUBLIC_KEY 0x0C -#define SMP_OPCODE_PAIR_DHKEY_CHECK 0x0D -#define SMP_OPCODE_PAIR_KEYPR_NOTIF 0x0E -#define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF -#define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ -#define SMP_OPCODE_PAIR_COMMITM 0x0F +#define SMP_OPCODE_PAIRING_REQ 0x01 +#define SMP_OPCODE_PAIRING_RSP 0x02 +#define SMP_OPCODE_CONFIRM 0x03 +#define SMP_OPCODE_RAND 0x04 +#define SMP_OPCODE_PAIRING_FAILED 0x05 +#define SMP_OPCODE_ENCRYPT_INFO 0x06 +#define SMP_OPCODE_MASTER_ID 0x07 +#define SMP_OPCODE_IDENTITY_INFO 0x08 +#define SMP_OPCODE_ID_ADDR 0x09 +#define SMP_OPCODE_SIGN_INFO 0x0A +#define SMP_OPCODE_SEC_REQ 0x0B +#define SMP_OPCODE_PAIR_PUBLIC_KEY 0x0C +#define SMP_OPCODE_PAIR_DHKEY_CHECK 0x0D +#define SMP_OPCODE_PAIR_KEYPR_NOTIF 0x0E +#define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF +#define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ +#define SMP_OPCODE_PAIR_COMMITM 0x0F /* SMP event type */ -#define SMP_IO_CAP_REQ_EVT 1 /* IO capability request event */ -#define SMP_SEC_REQUEST_EVT 2 /* SMP pairing request */ -#define SMP_PASSKEY_NOTIF_EVT 3 /* passkey notification event */ -#define SMP_PASSKEY_REQ_EVT 4 /* passkey request event */ -#define SMP_OOB_REQ_EVT 5 /* OOB request event */ -#define SMP_NC_REQ_EVT 6 /* Numeric Comparison request event */ -#define SMP_COMPLT_EVT 7 /* SMP complete event */ -#define SMP_PEER_KEYPR_NOT_EVT 8 /* Peer keypress notification */ - -/* SC OOB request event (both local and peer OOB data can be expected in response) */ -#define SMP_SC_OOB_REQ_EVT 9 +#define SMP_IO_CAP_REQ_EVT 1 /* IO capability request event */ +#define SMP_SEC_REQUEST_EVT 2 /* SMP pairing request */ +#define SMP_PASSKEY_NOTIF_EVT 3 /* passkey notification event */ +#define SMP_PASSKEY_REQ_EVT 4 /* passkey request event */ +#define SMP_OOB_REQ_EVT 5 /* OOB request event */ +#define SMP_NC_REQ_EVT 6 /* Numeric Comparison request event */ +#define SMP_COMPLT_EVT 7 /* SMP complete event */ +#define SMP_PEER_KEYPR_NOT_EVT 8 /* Peer keypress notification */ + +/* SC OOB request event (both local and peer OOB data can be expected in + * response) */ +#define SMP_SC_OOB_REQ_EVT 9 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */ -#define SMP_SC_LOC_OOB_DATA_UP_EVT 10 -#define SMP_BR_KEYS_REQ_EVT 12 /* SMP over BR keys request event */ +#define SMP_SC_LOC_OOB_DATA_UP_EVT 10 +#define SMP_BR_KEYS_REQ_EVT 12 /* SMP over BR keys request event */ typedef uint8_t tSMP_EVT; - /* pairing failure reason code */ -#define SMP_PASSKEY_ENTRY_FAIL 0x01 -#define SMP_OOB_FAIL 0x02 -#define SMP_PAIR_AUTH_FAIL 0x03 -#define SMP_CONFIRM_VALUE_ERR 0x04 -#define SMP_PAIR_NOT_SUPPORT 0x05 -#define SMP_ENC_KEY_SIZE 0x06 -#define SMP_INVALID_CMD 0x07 -#define SMP_PAIR_FAIL_UNKNOWN 0x08 -#define SMP_REPEATED_ATTEMPTS 0x09 -#define SMP_INVALID_PARAMETERS 0x0A -#define SMP_DHKEY_CHK_FAIL 0x0B -#define SMP_NUMERIC_COMPAR_FAIL 0x0C -#define SMP_BR_PARING_IN_PROGR 0x0D +#define SMP_PASSKEY_ENTRY_FAIL 0x01 +#define SMP_OOB_FAIL 0x02 +#define SMP_PAIR_AUTH_FAIL 0x03 +#define SMP_CONFIRM_VALUE_ERR 0x04 +#define SMP_PAIR_NOT_SUPPORT 0x05 +#define SMP_ENC_KEY_SIZE 0x06 +#define SMP_INVALID_CMD 0x07 +#define SMP_PAIR_FAIL_UNKNOWN 0x08 +#define SMP_REPEATED_ATTEMPTS 0x09 +#define SMP_INVALID_PARAMETERS 0x0A +#define SMP_DHKEY_CHK_FAIL 0x0B +#define SMP_NUMERIC_COMPAR_FAIL 0x0C +#define SMP_BR_PARING_IN_PROGR 0x0D #define SMP_XTRANS_DERIVE_NOT_ALLOW 0x0E -#define SMP_MAX_FAIL_RSN_PER_SPEC SMP_XTRANS_DERIVE_NOT_ALLOW +#define SMP_MAX_FAIL_RSN_PER_SPEC SMP_XTRANS_DERIVE_NOT_ALLOW /* self defined error code */ -#define SMP_PAIR_INTERNAL_ERR (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01) /* 0x0F */ +#define SMP_PAIR_INTERNAL_ERR (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01) /* 0x0F */ /* Unknown IO capability, unable to decide association model */ -#define SMP_UNKNOWN_IO_CAP (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02) /* 0x10 */ +#define SMP_UNKNOWN_IO_CAP (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02) /* 0x10 */ -#define SMP_INIT_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x03) /* 0x11 */ -#define SMP_CONFIRM_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x04) /* 0x12 */ -#define SMP_BUSY (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05) /* 0x13 */ -#define SMP_ENC_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06) /* 0x14 */ -#define SMP_STARTED (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07) /* 0x15 */ -#define SMP_RSP_TIMEOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08) /* 0x16 */ -#define SMP_DIV_NOT_AVAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x09) /* 0x17 */ +#define SMP_INIT_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x03) /* 0x11 */ +#define SMP_CONFIRM_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x04) /* 0x12 */ +#define SMP_BUSY (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05) /* 0x13 */ +#define SMP_ENC_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06) /* 0x14 */ +#define SMP_STARTED (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07) /* 0x15 */ +#define SMP_RSP_TIMEOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08) /* 0x16 */ +#define SMP_DIV_NOT_AVAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x09) /* 0x17 */ /* Unspecified failure reason */ -#define SMP_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A) /* 0x18 */ +#define SMP_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A) /* 0x18 */ -#define SMP_CONN_TOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B) /* 0x19 */ -#define SMP_SUCCESS 0 +#define SMP_CONN_TOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B) /* 0x19 */ +#define SMP_SUCCESS 0 typedef uint8_t tSMP_STATUS; - /* Device IO capability */ -#define SMP_IO_CAP_OUT BTM_IO_CAP_OUT /* DisplayOnly */ -#define SMP_IO_CAP_IO BTM_IO_CAP_IO /* DisplayYesNo */ -#define SMP_IO_CAP_IN BTM_IO_CAP_IN /* KeyboardOnly */ -#define SMP_IO_CAP_NONE BTM_IO_CAP_NONE /* NoInputNoOutput */ -#define SMP_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* Keyboard Display */ -#define SMP_IO_CAP_MAX BTM_IO_CAP_MAX +#define SMP_IO_CAP_OUT BTM_IO_CAP_OUT /* DisplayOnly */ +#define SMP_IO_CAP_IO BTM_IO_CAP_IO /* DisplayYesNo */ +#define SMP_IO_CAP_IN BTM_IO_CAP_IN /* KeyboardOnly */ +#define SMP_IO_CAP_NONE BTM_IO_CAP_NONE /* NoInputNoOutput */ +#define SMP_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* Keyboard Display */ +#define SMP_IO_CAP_MAX BTM_IO_CAP_MAX typedef uint8_t tSMP_IO_CAP; #ifndef SMP_DEFAULT_IO_CAPS - #define SMP_DEFAULT_IO_CAPS SMP_IO_CAP_KBDISP +#define SMP_DEFAULT_IO_CAPS SMP_IO_CAP_KBDISP #endif /* OOB data present or not */ -enum -{ - SMP_OOB_NONE, - SMP_OOB_PRESENT, - SMP_OOB_UNKNOWN -}; +enum { SMP_OOB_NONE, SMP_OOB_PRESENT, SMP_OOB_UNKNOWN }; typedef uint8_t tSMP_OOB_FLAG; /* type of OOB data required from application */ -enum -{ - SMP_OOB_INVALID_TYPE, - SMP_OOB_PEER, - SMP_OOB_LOCAL, - SMP_OOB_BOTH -}; +enum { SMP_OOB_INVALID_TYPE, SMP_OOB_PEER, SMP_OOB_LOCAL, SMP_OOB_BOTH }; typedef uint8_t tSMP_OOB_DATA_TYPE; -#define SMP_AUTH_NO_BOND 0x00 -#define SMP_AUTH_GEN_BOND 0x01 //todo sdh change GEN_BOND to BOND +#define SMP_AUTH_NO_BOND 0x00 +#define SMP_AUTH_GEN_BOND 0x01 // todo sdh change GEN_BOND to BOND /* SMP Authentication requirement */ -#define SMP_AUTH_YN_BIT (1 << 2) -#define SMP_SC_SUPPORT_BIT (1 << 3) -#define SMP_KP_SUPPORT_BIT (1 << 4) +#define SMP_AUTH_YN_BIT (1 << 2) +#define SMP_SC_SUPPORT_BIT (1 << 3) +#define SMP_KP_SUPPORT_BIT (1 << 4) -#define SMP_AUTH_MASK (SMP_AUTH_GEN_BOND|SMP_AUTH_YN_BIT|SMP_SC_SUPPORT_BIT|SMP_KP_SUPPORT_BIT) +#define SMP_AUTH_MASK \ + (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT | SMP_SC_SUPPORT_BIT | \ + SMP_KP_SUPPORT_BIT) -#define SMP_AUTH_BOND SMP_AUTH_GEN_BOND +#define SMP_AUTH_BOND SMP_AUTH_GEN_BOND /* no MITM, No Bonding, encryption only */ -#define SMP_AUTH_NB_ENC_ONLY 0x00 //(SMP_AUTH_MASK | BTM_AUTH_SP_NO) +#define SMP_AUTH_NB_ENC_ONLY 0x00 //(SMP_AUTH_MASK | BTM_AUTH_SP_NO) /* MITM, No Bonding, Use IO Capability to determine authentication procedure */ -#define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT) +#define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT) /* No MITM, General Bonding, Encryption only */ -#define SMP_AUTH_GB_ENC_ONLY (SMP_AUTH_GEN_BOND ) +#define SMP_AUTH_GB_ENC_ONLY (SMP_AUTH_GEN_BOND) /* MITM, General Bonding, Use IO Capability to determine authentication * procedure */ -#define SMP_AUTH_GB_IOCAP (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT) +#define SMP_AUTH_GB_IOCAP (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT) /* Secure Connections, no MITM, no Bonding */ -#define SMP_AUTH_SC_ENC_ONLY (SMP_SC_SUPPORT_BIT) +#define SMP_AUTH_SC_ENC_ONLY (SMP_SC_SUPPORT_BIT) /* Secure Connections, no MITM, Bonding */ -#define SMP_AUTH_SC_GB (SMP_SC_SUPPORT_BIT | SMP_AUTH_GEN_BOND) +#define SMP_AUTH_SC_GB (SMP_SC_SUPPORT_BIT | SMP_AUTH_GEN_BOND) /* Secure Connections, MITM, no Bonding */ -#define SMP_AUTH_SC_MITM_NB (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND) +#define SMP_AUTH_SC_MITM_NB \ + (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND) /* Secure Connections, MITM, Bonding */ -#define SMP_AUTH_SC_MITM_GB (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_GEN_BOND) +#define SMP_AUTH_SC_MITM_GB \ + (SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_GEN_BOND) - /* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is not set */ -#define SMP_AUTH_ALL_RFU_SET 0xF8 +/* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is + * not set */ +#define SMP_AUTH_ALL_RFU_SET 0xF8 typedef uint8_t tSMP_AUTH_REQ; -#define SMP_SEC_NONE 0 -#define SMP_SEC_UNAUTHENTICATE (1 << 0) -#define SMP_SEC_AUTHENTICATED (1 << 2) +#define SMP_SEC_NONE 0 +#define SMP_SEC_UNAUTHENTICATE (1 << 0) +#define SMP_SEC_AUTHENTICATED (1 << 2) typedef uint8_t tSMP_SEC_LEVEL; /* Maximum Encryption Key Size range */ -#define SMP_ENCR_KEY_SIZE_MIN 7 -#define SMP_ENCR_KEY_SIZE_MAX 16 +#define SMP_ENCR_KEY_SIZE_MIN 7 +#define SMP_ENCR_KEY_SIZE_MAX 16 /* SMP key types */ -#define SMP_SEC_KEY_TYPE_ENC (1 << 0) /* encryption key */ -#define SMP_SEC_KEY_TYPE_ID (1 << 1) /* identity key */ -#define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */ -#define SMP_SEC_KEY_TYPE_LK (1 << 3) /* BR/EDR link key */ +#define SMP_SEC_KEY_TYPE_ENC (1 << 0) /* encryption key */ +#define SMP_SEC_KEY_TYPE_ID (1 << 1) /* identity key */ +#define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */ +#define SMP_SEC_KEY_TYPE_LK (1 << 3) /* BR/EDR link key */ typedef uint8_t tSMP_KEYS; -#define SMP_BR_SEC_DEFAULT_KEY (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | \ - SMP_SEC_KEY_TYPE_CSRK) +#define SMP_BR_SEC_DEFAULT_KEY \ + (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK) /* default security key distribution value */ -#define SMP_SEC_DEFAULT_KEY (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | \ - SMP_SEC_KEY_TYPE_CSRK | SMP_SEC_KEY_TYPE_LK) - -#define SMP_SC_KEY_STARTED 0 /* passkey entry started */ -#define SMP_SC_KEY_ENTERED 1 /* passkey digit entered */ -#define SMP_SC_KEY_ERASED 2 /* passkey digit erased */ -#define SMP_SC_KEY_CLEARED 3 /* passkey cleared */ -#define SMP_SC_KEY_COMPLT 4 /* passkey entry completed */ -#define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */ +#define SMP_SEC_DEFAULT_KEY \ + (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK | \ + SMP_SEC_KEY_TYPE_LK) + +#define SMP_SC_KEY_STARTED 0 /* passkey entry started */ +#define SMP_SC_KEY_ENTERED 1 /* passkey digit entered */ +#define SMP_SC_KEY_ERASED 2 /* passkey digit erased */ +#define SMP_SC_KEY_CLEARED 3 /* passkey cleared */ +#define SMP_SC_KEY_COMPLT 4 /* passkey entry completed */ +#define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */ typedef uint8_t tSMP_SC_KEY_TYPE; /* data type for BTM_SP_IO_REQ_EVT */ -typedef struct -{ - tSMP_IO_CAP io_cap; /* local IO capabilities */ - tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */ - tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */ - uint8_t max_key_size; /* max encryption key size */ - tSMP_KEYS init_keys; /* initiator keys to be distributed */ - tSMP_KEYS resp_keys; /* responder keys */ +typedef struct { + tSMP_IO_CAP io_cap; /* local IO capabilities */ + tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */ + tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */ + uint8_t max_key_size; /* max encryption key size */ + tSMP_KEYS init_keys; /* initiator keys to be distributed */ + tSMP_KEYS resp_keys; /* responder keys */ } tSMP_IO_REQ; -typedef struct -{ - tSMP_STATUS reason; - tSMP_SEC_LEVEL sec_level; - bool is_pair_cancel; - bool smp_over_br; +typedef struct { + tSMP_STATUS reason; + tSMP_SEC_LEVEL sec_level; + bool is_pair_cancel; + bool smp_over_br; } tSMP_CMPL; -typedef struct -{ - BT_OCTET32 x; - BT_OCTET32 y; +typedef struct { + BT_OCTET32 x; + BT_OCTET32 y; } tSMP_PUBLIC_KEY; /* the data associated with the info sent to the peer via OOB interface */ -typedef struct -{ - bool present; - BT_OCTET16 randomizer; - BT_OCTET16 commitment; - - tBLE_BD_ADDR addr_sent_to; - BT_OCTET32 private_key_used; /* is used to calculate: */ - /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */ - /* other side */ - /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */ - tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */ +typedef struct { + bool present; + BT_OCTET16 randomizer; + BT_OCTET16 commitment; + + tBLE_BD_ADDR addr_sent_to; + BT_OCTET32 private_key_used; /* is used to calculate: */ + /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */ + /* other side */ + /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */ + tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */ } tSMP_LOC_OOB_DATA; /* the data associated with the info received from the peer via OOB interface */ -typedef struct -{ - bool present; - BT_OCTET16 randomizer; - BT_OCTET16 commitment; - tBLE_BD_ADDR addr_rcvd_from; +typedef struct { + bool present; + BT_OCTET16 randomizer; + BT_OCTET16 commitment; + tBLE_BD_ADDR addr_rcvd_from; } tSMP_PEER_OOB_DATA; -typedef struct -{ - tSMP_LOC_OOB_DATA loc_oob_data; - tSMP_PEER_OOB_DATA peer_oob_data; +typedef struct { + tSMP_LOC_OOB_DATA loc_oob_data; + tSMP_PEER_OOB_DATA peer_oob_data; } tSMP_SC_OOB_DATA; - -typedef union -{ - uint32_t passkey; - tSMP_IO_REQ io_req; /* IO request */ - tSMP_CMPL cmplt; - tSMP_OOB_DATA_TYPE req_oob_type; - tSMP_LOC_OOB_DATA loc_oob_data; -}tSMP_EVT_DATA; - +typedef union { + uint32_t passkey; + tSMP_IO_REQ io_req; /* IO request */ + tSMP_CMPL cmplt; + tSMP_OOB_DATA_TYPE req_oob_type; + tSMP_LOC_OOB_DATA loc_oob_data; +} tSMP_EVT_DATA; /* AES Encryption output */ -typedef struct -{ - uint8_t status; - uint8_t param_len; - uint16_t opcode; - uint8_t param_buf[BT_OCTET16_LEN]; +typedef struct { + uint8_t status; + uint8_t param_len; + uint16_t opcode; + uint8_t param_buf[BT_OCTET16_LEN]; } tSMP_ENC; /* Security Manager events - Called by the stack when Security Manager related * events occur.*/ -typedef uint8_t (tSMP_CALLBACK) (tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data); +typedef uint8_t(tSMP_CALLBACK)(tSMP_EVT event, BD_ADDR bd_addr, + tSMP_EVT_DATA* p_data); /* callback function for CMAC algorithm */ -typedef void (tCMAC_CMPL_CBACK)(uint8_t *p_mac, uint16_t tlen, uint32_t sign_counter); +typedef void(tCMAC_CMPL_CBACK)(uint8_t* p_mac, uint16_t tlen, + uint32_t sign_counter); #ifdef __cplusplus } #endif -#endif // SMP_API_TYPES_H +#endif // SMP_API_TYPES_H diff --git a/stack/include/srvc_api.h b/stack/include/srvc_api.h index 0b34cae08..4a64a7c3a 100644 --- a/stack/include/srvc_api.h +++ b/stack/include/srvc_api.h @@ -27,105 +27,96 @@ extern "C" { #endif -#define DIS_SUCCESS GATT_SUCCESS -#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER -#define DIS_NO_RESOURCES GATT_NO_RESOURCES +#define DIS_SUCCESS GATT_SUCCESS +#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER +#define DIS_NO_RESOURCES GATT_NO_RESOURCES typedef uint8_t tDIS_STATUS; - /***************************************************************************** * Data structure for DIS ****************************************************************************/ -#define DIS_ATTR_SYS_ID_BIT 0x0001 -#define DIS_ATTR_MODEL_NUM_BIT 0x0002 -#define DIS_ATTR_SERIAL_NUM_BIT 0x0004 -#define DIS_ATTR_FW_NUM_BIT 0x0008 -#define DIS_ATTR_HW_NUM_BIT 0x0010 -#define DIS_ATTR_SW_NUM_BIT 0x0020 -#define DIS_ATTR_MANU_NAME_BIT 0x0040 -#define DIS_ATTR_IEEE_DATA_BIT 0x0080 -#define DIS_ATTR_PNP_ID_BIT 0x0100 +#define DIS_ATTR_SYS_ID_BIT 0x0001 +#define DIS_ATTR_MODEL_NUM_BIT 0x0002 +#define DIS_ATTR_SERIAL_NUM_BIT 0x0004 +#define DIS_ATTR_FW_NUM_BIT 0x0008 +#define DIS_ATTR_HW_NUM_BIT 0x0010 +#define DIS_ATTR_SW_NUM_BIT 0x0020 +#define DIS_ATTR_MANU_NAME_BIT 0x0040 +#define DIS_ATTR_IEEE_DATA_BIT 0x0080 +#define DIS_ATTR_PNP_ID_BIT 0x0100 typedef uint16_t tDIS_ATTR_MASK; -#define DIS_ATTR_ALL_MASK 0xffff - -typedef tDIS_ATTR_MASK tDIS_ATTR_BIT ; +#define DIS_ATTR_ALL_MASK 0xffff -typedef struct -{ - uint16_t len; - uint8_t *p_data; -}tDIS_STRING; +typedef tDIS_ATTR_MASK tDIS_ATTR_BIT; -typedef struct -{ - uint16_t vendor_id; - uint16_t product_id; - uint16_t product_version; - uint8_t vendor_id_src; +typedef struct { + uint16_t len; + uint8_t* p_data; +} tDIS_STRING; -}tDIS_PNP_ID; +typedef struct { + uint16_t vendor_id; + uint16_t product_id; + uint16_t product_version; + uint8_t vendor_id_src; -typedef union -{ - uint64_t system_id; - tDIS_PNP_ID pnp_id; - tDIS_STRING data_str; -}tDIS_ATTR; +} tDIS_PNP_ID; -#define DIS_MAX_STRING_DATA 7 +typedef union { + uint64_t system_id; + tDIS_PNP_ID pnp_id; + tDIS_STRING data_str; +} tDIS_ATTR; -typedef struct -{ - uint16_t attr_mask; - uint64_t system_id; - tDIS_PNP_ID pnp_id; - uint8_t *data_string[DIS_MAX_STRING_DATA]; -}tDIS_VALUE; +#define DIS_MAX_STRING_DATA 7 +typedef struct { + uint16_t attr_mask; + uint64_t system_id; + tDIS_PNP_ID pnp_id; + uint8_t* data_string[DIS_MAX_STRING_DATA]; +} tDIS_VALUE; -typedef void (tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE *p_dis_value); +typedef void(tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE* p_dis_value); /***************************************************************************** * Data structure used by Battery Service ****************************************************************************/ -typedef struct -{ - BD_ADDR remote_bda; - bool need_rsp; - uint16_t clt_cfg; -}tBA_WRITE_DATA; - -#define BA_READ_CLT_CFG_REQ 1 -#define BA_READ_PRE_FMT_REQ 2 -#define BA_READ_RPT_REF_REQ 3 -#define BA_READ_LEVEL_REQ 4 -#define BA_WRITE_CLT_CFG_REQ 5 - -typedef void (tBA_CBACK)(uint8_t app_id, uint8_t event, tBA_WRITE_DATA *p_data); - -#define BA_LEVEL_NOTIFY 0x01 -#define BA_LEVEL_PRE_FMT 0x02 -#define BA_LEVEL_RPT_REF 0x04 +typedef struct { + BD_ADDR remote_bda; + bool need_rsp; + uint16_t clt_cfg; +} tBA_WRITE_DATA; + +#define BA_READ_CLT_CFG_REQ 1 +#define BA_READ_PRE_FMT_REQ 2 +#define BA_READ_RPT_REF_REQ 3 +#define BA_READ_LEVEL_REQ 4 +#define BA_WRITE_CLT_CFG_REQ 5 + +typedef void(tBA_CBACK)(uint8_t app_id, uint8_t event, tBA_WRITE_DATA* p_data); + +#define BA_LEVEL_NOTIFY 0x01 +#define BA_LEVEL_PRE_FMT 0x02 +#define BA_LEVEL_RPT_REF 0x04 typedef uint8_t tBA_LEVEL_DESCR; -typedef struct -{ - bool is_pri; - tBA_LEVEL_DESCR ba_level_descr; - tGATT_TRANSPORT transport; - tBA_CBACK *p_cback; +typedef struct { + bool is_pri; + tBA_LEVEL_DESCR ba_level_descr; + tGATT_TRANSPORT transport; + tBA_CBACK* p_cback; -}tBA_REG_INFO; +} tBA_REG_INFO; -typedef union -{ - uint8_t ba_level; - uint16_t clt_cfg; - tGATT_CHAR_RPT_REF rpt_ref; - tGATT_CHAR_PRES pres_fmt; -}tBA_RSP_DATA; +typedef union { + uint8_t ba_level; + uint16_t clt_cfg; + tGATT_CHAR_RPT_REF rpt_ref; + tGATT_CHAR_PRES pres_fmt; +} tBA_RSP_DATA; /***************************************************************************** * External Function Declarations @@ -141,8 +132,7 @@ typedef union * application as for a central service management. * ******************************************************************************/ -extern tGATT_STATUS srvc_eng_init (void); - +extern tGATT_STATUS srvc_eng_init(void); /***************************************************************************** * DIS Server Function @@ -155,7 +145,7 @@ extern tGATT_STATUS srvc_eng_init (void); * Description Initializa the Device Information Service Server. * ******************************************************************************/ -extern tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask); +extern tDIS_STATUS DIS_SrInit(tDIS_ATTR_MASK dis_attr_mask); /******************************************************************************* * * Function DIS_SrUpdate @@ -163,7 +153,7 @@ extern tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask); * Description Update the DIS server attribute values * ******************************************************************************/ -extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info); +extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR* p_info); /***************************************************************************** * DIS Client Function ****************************************************************************/ @@ -176,8 +166,8 @@ extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info); * Returns void * ******************************************************************************/ -extern bool DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, - tDIS_ATTR_MASK mask); +extern bool DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK* p_cback, + tDIS_ATTR_MASK mask); /******************************************************************************* * BATTERY SERVICE API @@ -189,7 +179,7 @@ extern bool DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, * Description Instantiate a Battery service * ******************************************************************************/ -extern uint16_t Battery_Instantiate (uint8_t app_id, tBA_REG_INFO *p_reg_info); +extern uint16_t Battery_Instantiate(uint8_t app_id, tBA_REG_INFO* p_reg_info); /******************************************************************************* * @@ -198,7 +188,8 @@ extern uint16_t Battery_Instantiate (uint8_t app_id, tBA_REG_INFO *p_reg_info); * Description Respond to a battery service request * ******************************************************************************/ -extern void Battery_Rsp (uint8_t app_id, tGATT_STATUS st, uint8_t event, tBA_RSP_DATA *p_rsp); +extern void Battery_Rsp(uint8_t app_id, tGATT_STATUS st, uint8_t event, + tBA_RSP_DATA* p_rsp); /******************************************************************************* * * Function Battery_Notify @@ -206,11 +197,10 @@ extern void Battery_Rsp (uint8_t app_id, tGATT_STATUS st, uint8_t event, tBA_RSP * Description Send battery level notification * ******************************************************************************/ -extern void Battery_Notify (uint8_t app_id, BD_ADDR remote_bda, uint8_t battery_level); - +extern void Battery_Notify(uint8_t app_id, BD_ADDR remote_bda, + uint8_t battery_level); #ifdef __cplusplus - } #endif diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index cba856a84..d16e7088d 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -29,10 +29,10 @@ #include #include +#include "bt_common.h" #include "bt_types.h" #include "btm_api.h" #include "btu.h" -#include "bt_common.h" #include "hcidefs.h" #include "hcimsgs.h" #include "l2c_int.h" @@ -40,8 +40,7 @@ #include "osi/include/allocator.h" #include "osi/include/log.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -57,64 +56,56 @@ extern fixed_queue_t *btu_general_alarm_queue; * L2CA_ErtmConnectReq() and L2CA_Deregister() * ******************************************************************************/ -uint16_t L2CA_Register (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info) -{ - tL2C_RCB *p_rcb; - uint16_t vpsm = psm; - - L2CAP_TRACE_API ("L2CAP - L2CA_Register() called for PSM: 0x%04x", psm); - - /* Verify that the required callback info has been filled in - ** Note: Connection callbacks are required but not checked - ** for here because it is possible to be only a client - ** or only a server. - */ - if ((!p_cb_info->pL2CA_ConfigCfm_Cb) - || (!p_cb_info->pL2CA_ConfigInd_Cb) - || (!p_cb_info->pL2CA_DataInd_Cb) - || (!p_cb_info->pL2CA_DisconnectInd_Cb)) - { - L2CAP_TRACE_ERROR ("L2CAP - no cb registering PSM: 0x%04x", psm); - return (0); - } - - /* Verify PSM is valid */ - if (L2C_INVALID_PSM(psm)) - { - L2CAP_TRACE_ERROR ("L2CAP - invalid PSM value, PSM: 0x%04x", psm); - return (0); - } +uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info) { + tL2C_RCB* p_rcb; + uint16_t vpsm = psm; + + L2CAP_TRACE_API("L2CAP - L2CA_Register() called for PSM: 0x%04x", psm); + + /* Verify that the required callback info has been filled in + ** Note: Connection callbacks are required but not checked + ** for here because it is possible to be only a client + ** or only a server. + */ + if ((!p_cb_info->pL2CA_ConfigCfm_Cb) || (!p_cb_info->pL2CA_ConfigInd_Cb) || + (!p_cb_info->pL2CA_DataInd_Cb) || (!p_cb_info->pL2CA_DisconnectInd_Cb)) { + L2CAP_TRACE_ERROR("L2CAP - no cb registering PSM: 0x%04x", psm); + return (0); + } - /* Check if this is a registration for an outgoing-only connection to */ - /* a dynamic PSM. If so, allocate a "virtual" PSM for the app to use. */ - if ( (psm >= 0x1001) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL) ) - { - for (vpsm = 0x1002; vpsm < 0x8000; vpsm += 2) - { - p_rcb = l2cu_find_rcb_by_psm(vpsm); - if (p_rcb == NULL) - break; - } + /* Verify PSM is valid */ + if (L2C_INVALID_PSM(psm)) { + L2CAP_TRACE_ERROR("L2CAP - invalid PSM value, PSM: 0x%04x", psm); + return (0); + } - L2CAP_TRACE_API ("L2CA_Register - Real PSM: 0x%04x Virtual PSM: 0x%04x", psm, vpsm); + /* Check if this is a registration for an outgoing-only connection to */ + /* a dynamic PSM. If so, allocate a "virtual" PSM for the app to use. */ + if ((psm >= 0x1001) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL)) { + for (vpsm = 0x1002; vpsm < 0x8000; vpsm += 2) { + p_rcb = l2cu_find_rcb_by_psm(vpsm); + if (p_rcb == NULL) break; } - /* If registration block already there, just overwrite it */ - p_rcb = l2cu_find_rcb_by_psm(vpsm); - if (p_rcb == NULL) - { - p_rcb = l2cu_allocate_rcb(vpsm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no RCB available, PSM: 0x%04x vPSM: 0x%04x", psm, vpsm); - return (0); - } + L2CAP_TRACE_API("L2CA_Register - Real PSM: 0x%04x Virtual PSM: 0x%04x", + psm, vpsm); + } + + /* If registration block already there, just overwrite it */ + p_rcb = l2cu_find_rcb_by_psm(vpsm); + if (p_rcb == NULL) { + p_rcb = l2cu_allocate_rcb(vpsm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no RCB available, PSM: 0x%04x vPSM: 0x%04x", + psm, vpsm); + return (0); } + } - p_rcb->api = *p_cb_info; - p_rcb->real_psm = psm; + p_rcb->api = *p_cb_info; + p_rcb->real_psm = psm; - return (vpsm); + return (vpsm); } /******************************************************************************* @@ -127,42 +118,37 @@ uint16_t L2CA_Register (uint16_t psm, tL2CAP_APPL_INFO *p_cb_info) * Returns void * ******************************************************************************/ -void L2CA_Deregister (uint16_t psm) -{ - tL2C_RCB *p_rcb; - tL2C_CCB *p_ccb; - tL2C_LCB *p_lcb; - int ii; - - L2CAP_TRACE_API ("L2CAP - L2CA_Deregister() called for PSM: 0x%04x", psm); - - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb != NULL) - { - p_lcb = &l2cb.lcb_pool[0]; - for (ii = 0; ii < MAX_L2CAP_LINKS; ii++, p_lcb++) - { - if (p_lcb->in_use) - { - if (((p_ccb = p_lcb->ccb_queue.p_first_ccb) == NULL) - || (p_lcb->link_state == LST_DISCONNECTING)) - continue; - - if ((p_ccb->in_use) && - ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) || - (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) - continue; - - if (p_ccb->p_rcb == p_rcb) - l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); - } - } - l2cu_release_rcb (p_rcb); - } - else - { - L2CAP_TRACE_WARNING ("L2CAP - PSM: 0x%04x not found for deregistration", psm); +void L2CA_Deregister(uint16_t psm) { + tL2C_RCB* p_rcb; + tL2C_CCB* p_ccb; + tL2C_LCB* p_lcb; + int ii; + + L2CAP_TRACE_API("L2CAP - L2CA_Deregister() called for PSM: 0x%04x", psm); + + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb != NULL) { + p_lcb = &l2cb.lcb_pool[0]; + for (ii = 0; ii < MAX_L2CAP_LINKS; ii++, p_lcb++) { + if (p_lcb->in_use) { + if (((p_ccb = p_lcb->ccb_queue.p_first_ccb) == NULL) || + (p_lcb->link_state == LST_DISCONNECTING)) + continue; + + if ((p_ccb->in_use) && + ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) || + (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) + continue; + + if (p_ccb->p_rcb == p_rcb) + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); + } } + l2cu_release_rcb(p_rcb); + } else { + L2CAP_TRACE_WARNING("L2CAP - PSM: 0x%04x not found for deregistration", + psm); + } } /******************************************************************************* @@ -175,36 +161,30 @@ void L2CA_Deregister (uint16_t psm) * Returns PSM to use. * ******************************************************************************/ -uint16_t L2CA_AllocatePSM(void) -{ - bool done = false; - uint16_t psm = l2cb.dyn_psm; - - L2CAP_TRACE_API( "L2CA_AllocatePSM"); - while (!done) - { - psm += 2; - if (psm > 0xfeff) - { - psm = 0x1001; - } - else if (psm & 0x0100) - { - /* the upper byte must be even */ - psm += 0x0100; - } - - /* if psm is in range of reserved BRCM Aware features */ - if ((BRCM_RESERVED_PSM_START <= psm)&&(psm <= BRCM_RESERVED_PSM_END)) - continue; - - /* make sure the newlly allocated psm is not used right now */ - if ((l2cu_find_rcb_by_psm (psm)) == NULL) - done = true; - } - l2cb.dyn_psm = psm; +uint16_t L2CA_AllocatePSM(void) { + bool done = false; + uint16_t psm = l2cb.dyn_psm; + + L2CAP_TRACE_API("L2CA_AllocatePSM"); + while (!done) { + psm += 2; + if (psm > 0xfeff) { + psm = 0x1001; + } else if (psm & 0x0100) { + /* the upper byte must be even */ + psm += 0x0100; + } + + /* if psm is in range of reserved BRCM Aware features */ + if ((BRCM_RESERVED_PSM_START <= psm) && (psm <= BRCM_RESERVED_PSM_END)) + continue; + + /* make sure the newlly allocated psm is not used right now */ + if ((l2cu_find_rcb_by_psm(psm)) == NULL) done = true; + } + l2cb.dyn_psm = psm; - return(psm); + return (psm); } /******************************************************************************* @@ -220,9 +200,8 @@ uint16_t L2CA_AllocatePSM(void) * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -uint16_t L2CA_ConnectReq (uint16_t psm, BD_ADDR p_bd_addr) -{ - return L2CA_ErtmConnectReq (psm, p_bd_addr, NULL); +uint16_t L2CA_ConnectReq(uint16_t psm, BD_ADDR p_bd_addr) { + return L2CA_ErtmConnectReq(psm, p_bd_addr, NULL); } /******************************************************************************* @@ -242,103 +221,103 @@ uint16_t L2CA_ConnectReq (uint16_t psm, BD_ADDR p_bd_addr) * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -uint16_t L2CA_ErtmConnectReq (uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO *p_ertm_info) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - - L2CAP_TRACE_API ("L2CA_ErtmConnectReq() PSM: 0x%04x BDA: %08x%04x p_ertm_info: 0x%08x allowed:0x%x preferred:%d", psm, - (p_bd_addr[0]<<24)+(p_bd_addr[1]<<16)+(p_bd_addr[2]<<8)+p_bd_addr[3], - (p_bd_addr[4]<<8)+p_bd_addr[5], p_ertm_info, - (p_ertm_info) ? p_ertm_info->allowed_modes : 0, - (p_ertm_info) ? p_ertm_info->preferred_mode : 0); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING ("L2CAP connect req - BTU not ready"); - return (0); - } - /* Fail if the PSM is not registered */ - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_conn_req, PSM: 0x%04x", psm); - return (0); - } +uint16_t L2CA_ErtmConnectReq(uint16_t psm, BD_ADDR p_bd_addr, + tL2CAP_ERTM_INFO* p_ertm_info) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + + L2CAP_TRACE_API( + "L2CA_ErtmConnectReq() PSM: 0x%04x BDA: %08x%04x p_ertm_info: 0x%08x " + "allowed:0x%x preferred:%d", + psm, (p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + (p_bd_addr[2] << 8) + + p_bd_addr[3], + (p_bd_addr[4] << 8) + p_bd_addr[5], p_ertm_info, + (p_ertm_info) ? p_ertm_info->allowed_modes : 0, + (p_ertm_info) ? p_ertm_info->preferred_mode : 0); + + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("L2CAP connect req - BTU not ready"); + return (0); + } + /* Fail if the PSM is not registered */ + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no RCB for L2CA_conn_req, PSM: 0x%04x", psm); + return (0); + } - /* First, see if we already have a link to the remote */ - /* assume all ERTM l2cap connection is going over BR/EDR for now */ - p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - if ( ((p_lcb = l2cu_allocate_lcb (p_bd_addr, false, BT_TRANSPORT_BR_EDR)) == NULL) - /* currently use BR/EDR for ERTM mode l2cap connection */ - || (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) ) - { - L2CAP_TRACE_WARNING ("L2CAP - conn not started for PSM: 0x%04x p_lcb: 0x%08x", psm, p_lcb); - return (0); - } + /* First, see if we already have a link to the remote */ + /* assume all ERTM l2cap connection is going over BR/EDR for now */ + p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + if (((p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR)) == + NULL) + /* currently use BR/EDR for ERTM mode l2cap connection */ + || (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false)) { + L2CAP_TRACE_WARNING( + "L2CAP - conn not started for PSM: 0x%04x p_lcb: 0x%08x", psm, + p_lcb); + return (0); } + } - /* Allocate a channel control block */ - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_req, PSM: 0x%04x", psm); - return (0); - } + /* Allocate a channel control block */ + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_conn_req, PSM: 0x%04x", psm); + return (0); + } - /* Save registration info */ - p_ccb->p_rcb = p_rcb; + /* Save registration info */ + p_ccb->p_rcb = p_rcb; - if (p_ertm_info) - { - p_ccb->ertm_info = *p_ertm_info; + if (p_ertm_info) { + p_ccb->ertm_info = *p_ertm_info; - /* Replace default indicators with the actual default pool */ - if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; + /* Replace default indicators with the actual default pool */ + if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; - if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; + if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; - if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; + if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; - if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; + if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; - p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size - - (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); - } + p_ccb->max_rx_mtu = + p_ertm_info->user_rx_buf_size - + (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); + } - /* If link is up, start the L2CAP connection */ - if (p_lcb->link_state == LST_CONNECTED) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL); - } + /* If link is up, start the L2CAP connection */ + if (p_lcb->link_state == LST_CONNECTED) { + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL); + } - /* If link is disconnecting, save link info to retry after disconnect - * Possible Race condition when a reconnect occurs - * on the channel during a disconnect of link. This - * ccb will be automatically retried after link disconnect - * arrives - */ - else if (p_lcb->link_state == LST_DISCONNECTING) - { - L2CAP_TRACE_DEBUG ("L2CAP API - link disconnecting: RETRY LATER"); - - /* Save ccb so it can be started after disconnect is finished */ - p_lcb->p_pending_ccb = p_ccb; - } + /* If link is disconnecting, save link info to retry after disconnect + * Possible Race condition when a reconnect occurs + * on the channel during a disconnect of link. This + * ccb will be automatically retried after link disconnect + * arrives + */ + else if (p_lcb->link_state == LST_DISCONNECTING) { + L2CAP_TRACE_DEBUG("L2CAP API - link disconnecting: RETRY LATER"); + + /* Save ccb so it can be started after disconnect is finished */ + p_lcb->p_pending_ccb = p_ccb; + } - L2CAP_TRACE_API ("L2CAP - L2CA_conn_req(psm: 0x%04x) returned CID: 0x%04x", psm, p_ccb->local_cid); + L2CAP_TRACE_API("L2CAP - L2CA_conn_req(psm: 0x%04x) returned CID: 0x%04x", + psm, p_ccb->local_cid); - /* Return the local CID as our handle */ - return (p_ccb->local_cid); + /* Return the local CID as our handle */ + return (p_ccb->local_cid); } /******************************************************************************* @@ -355,63 +334,55 @@ uint16_t L2CA_ErtmConnectReq (uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO * and L2CA_DeregisterLECoc() * ******************************************************************************/ -uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO *p_cb_info) -{ - L2CAP_TRACE_API("%s called for LE PSM: 0x%04x", __func__, psm); - - /* Verify that the required callback info has been filled in - ** Note: Connection callbacks are required but not checked - ** for here because it is possible to be only a client - ** or only a server. - */ - if ((!p_cb_info->pL2CA_DataInd_Cb) - || (!p_cb_info->pL2CA_DisconnectInd_Cb)) - { - L2CAP_TRACE_ERROR("%s No cb registering BLE PSM: 0x%04x", __func__, psm); - return 0; - } +uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info) { + L2CAP_TRACE_API("%s called for LE PSM: 0x%04x", __func__, psm); + + /* Verify that the required callback info has been filled in + ** Note: Connection callbacks are required but not checked + ** for here because it is possible to be only a client + ** or only a server. + */ + if ((!p_cb_info->pL2CA_DataInd_Cb) || (!p_cb_info->pL2CA_DisconnectInd_Cb)) { + L2CAP_TRACE_ERROR("%s No cb registering BLE PSM: 0x%04x", __func__, psm); + return 0; + } - /* Verify PSM is valid */ - if (!L2C_IS_VALID_LE_PSM(psm)) - { - L2CAP_TRACE_ERROR("%s Invalid BLE PSM value, PSM: 0x%04x", __func__, psm); - return 0; - } + /* Verify PSM is valid */ + if (!L2C_IS_VALID_LE_PSM(psm)) { + L2CAP_TRACE_ERROR("%s Invalid BLE PSM value, PSM: 0x%04x", __func__, psm); + return 0; + } - tL2C_RCB *p_rcb; - uint16_t vpsm = psm; - - /* Check if this is a registration for an outgoing-only connection to */ - /* a dynamic PSM. If so, allocate a "virtual" PSM for the app to use. */ - if ((psm >= 0x0080) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL)) - { - for (vpsm = 0x0080; vpsm < 0x0100; vpsm++) - { - p_rcb = l2cu_find_ble_rcb_by_psm(vpsm); - if (p_rcb == NULL) - break; - } + tL2C_RCB* p_rcb; + uint16_t vpsm = psm; - L2CAP_TRACE_API("%s Real PSM: 0x%04x Virtual PSM: 0x%04x", __func__, psm, vpsm); + /* Check if this is a registration for an outgoing-only connection to */ + /* a dynamic PSM. If so, allocate a "virtual" PSM for the app to use. */ + if ((psm >= 0x0080) && (p_cb_info->pL2CA_ConnectInd_Cb == NULL)) { + for (vpsm = 0x0080; vpsm < 0x0100; vpsm++) { + p_rcb = l2cu_find_ble_rcb_by_psm(vpsm); + if (p_rcb == NULL) break; } - /* If registration block already there, just overwrite it */ - p_rcb = l2cu_find_ble_rcb_by_psm(vpsm); - if (p_rcb == NULL) - { - p_rcb = l2cu_allocate_ble_rcb(vpsm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING("%s No BLE RCB available, PSM: 0x%04x vPSM: 0x%04x", - __func__, psm, vpsm); - return 0; - } + L2CAP_TRACE_API("%s Real PSM: 0x%04x Virtual PSM: 0x%04x", __func__, psm, + vpsm); + } + + /* If registration block already there, just overwrite it */ + p_rcb = l2cu_find_ble_rcb_by_psm(vpsm); + if (p_rcb == NULL) { + p_rcb = l2cu_allocate_ble_rcb(vpsm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("%s No BLE RCB available, PSM: 0x%04x vPSM: 0x%04x", + __func__, psm, vpsm); + return 0; } + } - p_rcb->api = *p_cb_info; - p_rcb->real_psm = psm; + p_rcb->api = *p_cb_info; + p_rcb->real_psm = psm; - return vpsm; + return vpsm; } /******************************************************************************* @@ -424,37 +395,31 @@ uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO *p_cb_info) * Returns void * ******************************************************************************/ -void L2CA_DeregisterLECoc(uint16_t psm) -{ - L2CAP_TRACE_API("%s called for PSM: 0x%04x", __func__, psm); - - tL2C_RCB *p_rcb = l2cu_find_ble_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING("%s PSM: 0x%04x not found for deregistration", psm); - return; - } +void L2CA_DeregisterLECoc(uint16_t psm) { + L2CAP_TRACE_API("%s called for PSM: 0x%04x", __func__, psm); - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; - for (int i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) - { - if (!p_lcb->in_use || p_lcb->transport != BT_TRANSPORT_LE) - continue; + tL2C_RCB* p_rcb = l2cu_find_ble_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("%s PSM: 0x%04x not found for deregistration", psm); + return; + } - tL2C_CCB *p_ccb = p_lcb->ccb_queue.p_first_ccb; - if ((p_ccb == NULL) || (p_lcb->link_state == LST_DISCONNECTING)) - continue; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; + for (int i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) { + if (!p_lcb->in_use || p_lcb->transport != BT_TRANSPORT_LE) continue; - if (p_ccb->in_use && - (p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP || - p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP)) - continue; + tL2C_CCB* p_ccb = p_lcb->ccb_queue.p_first_ccb; + if ((p_ccb == NULL) || (p_lcb->link_state == LST_DISCONNECTING)) continue; - if (p_ccb->p_rcb == p_rcb) - l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); - } + if (p_ccb->in_use && (p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP || + p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP)) + continue; + + if (p_ccb->p_rcb == p_rcb) + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); + } - l2cu_release_rcb (p_rcb); + l2cu_release_rcb(p_rcb); } /******************************************************************************* @@ -474,85 +439,78 @@ void L2CA_DeregisterLECoc(uint16_t psm) * Returns the CID of the connection, or 0 if it failed to start * ******************************************************************************/ -uint16_t L2CA_ConnectLECocReq(uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_LE_CFG_INFO *p_cfg) -{ - L2CAP_TRACE_API("%s PSM: 0x%04x BDA: %02x:%02x:%02x:%02x:%02x:%02x", __func__, psm, - p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING("%s BTU not ready", __func__); - return 0; - } +uint16_t L2CA_ConnectLECocReq(uint16_t psm, BD_ADDR p_bd_addr, + tL2CAP_LE_CFG_INFO* p_cfg) { + L2CAP_TRACE_API("%s PSM: 0x%04x BDA: %02x:%02x:%02x:%02x:%02x:%02x", __func__, + psm, p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], + p_bd_addr[4], p_bd_addr[5]); + + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("%s BTU not ready", __func__); + return 0; + } - /* Fail if the PSM is not registered */ - tL2C_RCB *p_rcb = l2cu_find_ble_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING("%s No BLE RCB, PSM: 0x%04x", __func__, psm); - return 0; - } + /* Fail if the PSM is not registered */ + tL2C_RCB* p_rcb = l2cu_find_ble_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("%s No BLE RCB, PSM: 0x%04x", __func__, psm); + return 0; + } - /* First, see if we already have a le link to the remote */ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_LE); - if ((p_lcb == NULL) - /* currently use BR/EDR for ERTM mode l2cap connection */ - || (l2cu_create_conn(p_lcb, BT_TRANSPORT_LE) == false) ) - { - L2CAP_TRACE_WARNING("%s conn not started for PSM: 0x%04x p_lcb: 0x%08x", - __func__, psm, p_lcb); - return 0; - } + /* First, see if we already have a le link to the remote */ + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_LE); + if ((p_lcb == NULL) + /* currently use BR/EDR for ERTM mode l2cap connection */ + || (l2cu_create_conn(p_lcb, BT_TRANSPORT_LE) == false)) { + L2CAP_TRACE_WARNING("%s conn not started for PSM: 0x%04x p_lcb: 0x%08x", + __func__, psm, p_lcb); + return 0; } + } - /* Allocate a channel control block */ - tL2C_CCB *p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING("%s no CCB, PSM: 0x%04x", __func__, psm); - return 0; - } + /* Allocate a channel control block */ + tL2C_CCB* p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("%s no CCB, PSM: 0x%04x", __func__, psm); + return 0; + } - /* Save registration info */ - p_ccb->p_rcb = p_rcb; + /* Save registration info */ + p_ccb->p_rcb = p_rcb; - /* Save the configuration */ - if (p_cfg) - memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO)); + /* Save the configuration */ + if (p_cfg) memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO)); - /* If link is up, start the L2CAP connection */ - if (p_lcb->link_state == LST_CONNECTED) - { - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - L2CAP_TRACE_DEBUG("%s LE Link is up", __func__); - l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL); - } + /* If link is up, start the L2CAP connection */ + if (p_lcb->link_state == LST_CONNECTED) { + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + L2CAP_TRACE_DEBUG("%s LE Link is up", __func__); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL); } + } - /* If link is disconnecting, save link info to retry after disconnect - * Possible Race condition when a reconnect occurs - * on the channel during a disconnect of link. This - * ccb will be automatically retried after link disconnect - * arrives - */ - else if (p_lcb->link_state == LST_DISCONNECTING) - { - L2CAP_TRACE_DEBUG("%s link disconnecting: RETRY LATER", __func__); - - /* Save ccb so it can be started after disconnect is finished */ - p_lcb->p_pending_ccb = p_ccb; - } + /* If link is disconnecting, save link info to retry after disconnect + * Possible Race condition when a reconnect occurs + * on the channel during a disconnect of link. This + * ccb will be automatically retried after link disconnect + * arrives + */ + else if (p_lcb->link_state == LST_DISCONNECTING) { + L2CAP_TRACE_DEBUG("%s link disconnecting: RETRY LATER", __func__); + + /* Save ccb so it can be started after disconnect is finished */ + p_lcb->p_pending_ccb = p_ccb; + } - L2CAP_TRACE_API("%s(psm: 0x%04x) returned CID: 0x%04x", __func__, psm, p_ccb->local_cid); + L2CAP_TRACE_API("%s(psm: 0x%04x) returned CID: 0x%04x", __func__, psm, + p_ccb->local_cid); - /* Return the local CID as our handle */ - return p_ccb->local_cid; + /* Return the local CID as our handle */ + return p_ccb->local_cid; } /******************************************************************************* @@ -566,53 +524,49 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, BD_ADDR p_bd_addr, tL2CAP_LE_CFG_INF * Returns true for success, false for failure * ******************************************************************************/ -bool L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, uint16_t result, - uint16_t status, tL2CAP_LE_CFG_INFO *p_cfg) -{ - L2CAP_TRACE_API("%s CID: 0x%04x Result: %d Status: %d BDA: %02x:%02x:%02x:%02x:%02x:%02x", - __func__, lcid, result, status, - p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]); - - - /* First, find the link control block */ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - L2CAP_TRACE_WARNING("%s no LCB", __func__); - return false; - } +bool L2CA_ConnectLECocRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status, + tL2CAP_LE_CFG_INFO* p_cfg) { + L2CAP_TRACE_API( + "%s CID: 0x%04x Result: %d Status: %d BDA: %02x:%02x:%02x:%02x:%02x:%02x", + __func__, lcid, result, status, p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], + p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]); + + /* First, find the link control block */ + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_LE); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + L2CAP_TRACE_WARNING("%s no LCB", __func__); + return false; + } - /* Now, find the channel control block */ - tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING("%s no CCB", __func__); - return false; - } + /* Now, find the channel control block */ + tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("%s no CCB", __func__); + return false; + } - /* The IDs must match */ - if (p_ccb->remote_id != id) - { - L2CAP_TRACE_WARNING("%s bad id. Expected: %d Got: %d", __func__, p_ccb->remote_id, id); - return false; - } + /* The IDs must match */ + if (p_ccb->remote_id != id) { + L2CAP_TRACE_WARNING("%s bad id. Expected: %d Got: %d", __func__, + p_ccb->remote_id, id); + return false; + } - if (p_cfg) - memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO)); + if (p_cfg) memcpy(&p_ccb->local_conn_cfg, p_cfg, sizeof(tL2CAP_LE_CFG_INFO)); - if (result == L2CAP_CONN_OK) - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL); - else - { - tL2C_CONN_INFO conn_info; - memcpy(conn_info.bd_addr, p_bd_addr, BD_ADDR_LEN); - conn_info.l2cap_result = result; - conn_info.l2cap_status = status; - l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info); - } + if (result == L2CAP_CONN_OK) + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL); + else { + tL2C_CONN_INFO conn_info; + memcpy(conn_info.bd_addr, p_bd_addr, BD_ADDR_LEN); + conn_info.l2cap_result = result; + conn_info.l2cap_status = status; + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info); + } - return true; + return true; } /******************************************************************************* @@ -628,24 +582,23 @@ bool L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, uint * Return value: true if peer is connected * ******************************************************************************/ -bool L2CA_GetPeerLECocConfig (uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg) -{ - L2CAP_TRACE_API ("%s CID: 0x%04x", __func__, lcid); - - tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); - if (p_ccb == NULL) - { - L2CAP_TRACE_ERROR("%s No CCB for CID:0x%04x", __func__, lcid); - return false; - } +bool L2CA_GetPeerLECocConfig(uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg) { + L2CAP_TRACE_API("%s CID: 0x%04x", __func__, lcid); - if (peer_cfg != NULL) - memcpy(peer_cfg, &p_ccb->peer_conn_cfg, sizeof(tL2CAP_LE_CFG_INFO)); + tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); + if (p_ccb == NULL) { + L2CAP_TRACE_ERROR("%s No CCB for CID:0x%04x", __func__, lcid); + return false; + } - return true; + if (peer_cfg != NULL) + memcpy(peer_cfg, &p_ccb->peer_conn_cfg, sizeof(tL2CAP_LE_CFG_INFO)); + + return true; } -bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks) { +bool L2CA_SetConnectionCallbacks(uint16_t local_cid, + const tL2CAP_APPL_INFO* callbacks) { assert(callbacks != NULL); assert(callbacks->pL2CA_ConnectInd_Cb == NULL); assert(callbacks->pL2CA_ConnectCfm_Cb != NULL); @@ -657,9 +610,11 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal assert(callbacks->pL2CA_DataInd_Cb != NULL); assert(callbacks->pL2CA_TxComplete_Cb != NULL); - tL2C_CCB *channel_control_block = l2cu_find_ccb_by_cid(NULL, local_cid); + tL2C_CCB* channel_control_block = l2cu_find_ccb_by_cid(NULL, local_cid); if (!channel_control_block) { - LOG_ERROR(LOG_TAG, "%s no channel control block found for L2CAP LCID=0x%04x.", __func__, local_cid); + LOG_ERROR(LOG_TAG, + "%s no channel control block found for L2CAP LCID=0x%04x.", + __func__, local_cid); return false; } @@ -667,9 +622,9 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal // if we already have a private one allocated to us on the heap. If not, we // make a new allocation, mark it as heap-allocated, and inherit the fields // from the old control block. - tL2C_RCB *registration_control_block = channel_control_block->p_rcb; + tL2C_RCB* registration_control_block = channel_control_block->p_rcb; if (!channel_control_block->should_free_rcb) { - registration_control_block = (tL2C_RCB *)osi_calloc(sizeof(tL2C_RCB)); + registration_control_block = (tL2C_RCB*)osi_calloc(sizeof(tL2C_RCB)); *registration_control_block = *channel_control_block->p_rcb; channel_control_block->p_rcb = registration_control_block; @@ -691,10 +646,9 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal * Returns true for success, false for failure * ******************************************************************************/ -bool L2CA_ConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, - uint16_t result, uint16_t status) -{ - return L2CA_ErtmConnectRsp (p_bd_addr, id, lcid, result, status, NULL); +bool L2CA_ConnectRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status) { + return L2CA_ErtmConnectRsp(p_bd_addr, id, lcid, result, status, NULL); } /******************************************************************************* @@ -708,80 +662,77 @@ bool L2CA_ConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, * Returns true for success, false for failure * ******************************************************************************/ -bool L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, uint16_t result, - uint16_t status, tL2CAP_ERTM_INFO *p_ertm_info) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_ErtmConnectRsp() CID: 0x%04x Result: %d Status: %d BDA: %08x%04x p_ertm_info:0x%08x", - lcid, result, status, - (p_bd_addr[0]<<24)+(p_bd_addr[1]<<16)+(p_bd_addr[2]<<8)+p_bd_addr[3], - (p_bd_addr[4]<<8)+p_bd_addr[5], p_ertm_info); - - /* First, find the link control block */ - p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_conn_rsp"); - return (false); - } +bool L2CA_ErtmConnectRsp(BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, + uint16_t result, uint16_t status, + tL2CAP_ERTM_INFO* p_ertm_info) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_ErtmConnectRsp() CID: 0x%04x Result: %d Status: %d BDA: " + "%08x%04x p_ertm_info:0x%08x", + lcid, result, status, (p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + + (p_bd_addr[2] << 8) + p_bd_addr[3], + (p_bd_addr[4] << 8) + p_bd_addr[5], p_ertm_info); + + /* First, find the link control block */ + p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + L2CAP_TRACE_WARNING("L2CAP - no LCB for L2CA_conn_rsp"); + return (false); + } - /* Now, find the channel control block */ - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_rsp"); - return (false); - } + /* Now, find the channel control block */ + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_conn_rsp"); + return (false); + } - /* The IDs must match */ - if (p_ccb->remote_id != id) - { - L2CAP_TRACE_WARNING ("L2CAP - bad id in L2CA_conn_rsp. Exp: %d Got: %d", p_ccb->remote_id, id); - return (false); - } + /* The IDs must match */ + if (p_ccb->remote_id != id) { + L2CAP_TRACE_WARNING("L2CAP - bad id in L2CA_conn_rsp. Exp: %d Got: %d", + p_ccb->remote_id, id); + return (false); + } - if (p_ertm_info) - { - p_ccb->ertm_info = *p_ertm_info; + if (p_ertm_info) { + p_ccb->ertm_info = *p_ertm_info; - /* Replace default indicators with the actual default pool */ - if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; + /* Replace default indicators with the actual default pool */ + if (p_ccb->ertm_info.fcr_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; - if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; + if (p_ccb->ertm_info.fcr_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; - if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; + if (p_ccb->ertm_info.user_rx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; - if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) - p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; + if (p_ccb->ertm_info.user_tx_buf_size == L2CAP_INVALID_ERM_BUF_SIZE) + p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; - p_ccb->max_rx_mtu = p_ertm_info->user_rx_buf_size - - (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); - } + p_ccb->max_rx_mtu = + p_ertm_info->user_rx_buf_size - + (L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET + L2CAP_FCS_LEN); + } - if (result == L2CAP_CONN_OK) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL); - } - else - { - tL2C_CONN_INFO conn_info; + if (result == L2CAP_CONN_OK) { + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP, NULL); + } else { + tL2C_CONN_INFO conn_info; - conn_info.l2cap_result = result; - conn_info.l2cap_status = status; + conn_info.l2cap_result = result; + conn_info.l2cap_status = status; - if (result == L2CAP_CONN_PENDING) - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP, &conn_info); - else - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info); - } + if (result == L2CAP_CONN_PENDING) + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP, &conn_info); + else + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_RSP_NEG, &conn_info); + } - return (true); + return (true); } /******************************************************************************* @@ -795,45 +746,43 @@ bool L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, uint8_t id, uint16_t lcid, uint1 * Returns true if configuration sent, else false * ******************************************************************************/ -bool L2CA_ConfigReq (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) -{ - tL2C_CCB *p_ccb; +bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_ConfigReq() CID 0x%04x: fcr_present:%d (mode %d) mtu_present:%d " + "(%d)", + cid, p_cfg->fcr_present, p_cfg->fcr.mode, p_cfg->mtu_present, p_cfg->mtu); + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_cfg_req, CID: %d", cid); + return (false); + } - L2CAP_TRACE_API ("L2CA_ConfigReq() CID 0x%04x: fcr_present:%d (mode %d) mtu_present:%d (%d)", - cid, p_cfg->fcr_present, p_cfg->fcr.mode, p_cfg->mtu_present, p_cfg->mtu); + /* We need to have at least one mode type common with the peer */ + if (!l2c_fcr_adj_our_req_options(p_ccb, p_cfg)) return (false); - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_cfg_req, CID: %d", cid); - return (false); - } + /* Don't adjust FCR options if not used */ + if ((!p_cfg->fcr_present) || (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE)) { + /* FCR and FCS options are not used in basic mode */ + p_cfg->fcs_present = false; + p_cfg->ext_flow_spec_present = false; - /* We need to have at least one mode type common with the peer */ - if (!l2c_fcr_adj_our_req_options(p_ccb, p_cfg)) - return (false); - - /* Don't adjust FCR options if not used */ - if ((!p_cfg->fcr_present)||(p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE)) - { - /* FCR and FCS options are not used in basic mode */ - p_cfg->fcs_present = false; - p_cfg->ext_flow_spec_present = false; - - if ( (p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE) ) - { - L2CAP_TRACE_WARNING ("L2CAP - adjust MTU: %u too large", p_cfg->mtu); - p_cfg->mtu = L2CAP_MTU_SIZE; - } + if ((p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE)) { + L2CAP_TRACE_WARNING("L2CAP - adjust MTU: %u too large", p_cfg->mtu); + p_cfg->mtu = L2CAP_MTU_SIZE; } + } - /* Save the adjusted configuration in case it needs to be used for renegotiation */ - p_ccb->our_cfg = *p_cfg; + /* Save the adjusted configuration in case it needs to be used for + * renegotiation */ + p_ccb->our_cfg = *p_cfg; - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_REQ, p_cfg); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_REQ, p_cfg); - return (true); + return (true); } /******************************************************************************* @@ -846,39 +795,38 @@ bool L2CA_ConfigReq (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) * Returns true if configuration response sent, else false * ******************************************************************************/ -bool L2CA_ConfigRsp (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) -{ - tL2C_CCB *p_ccb; +bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_ConfigRsp() CID: 0x%04x Result: %d MTU present:%d Flush TO:%d " + "FCR:%d FCS:%d", + cid, p_cfg->result, p_cfg->mtu_present, p_cfg->flush_to_present, + p_cfg->fcr_present, p_cfg->fcs_present); + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_cfg_rsp, CID: %d", cid); + return (false); + } - L2CAP_TRACE_API ("L2CA_ConfigRsp() CID: 0x%04x Result: %d MTU present:%d Flush TO:%d FCR:%d FCS:%d", - cid, p_cfg->result, p_cfg->mtu_present, p_cfg->flush_to_present, p_cfg->fcr_present, p_cfg->fcs_present); + if ((p_cfg->result == L2CAP_CFG_OK) || (p_cfg->result == L2CAP_CFG_PENDING)) + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_RSP, p_cfg); + else { + p_cfg->fcr_present = + false; /* FCR options already negotiated before this point */ - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_cfg_rsp, CID: %d", cid); - return (false); - } + /* Clear out any cached options that are being returned as an error + * (excluding FCR) */ + if (p_cfg->mtu_present) p_ccb->peer_cfg.mtu_present = false; + if (p_cfg->flush_to_present) p_ccb->peer_cfg.flush_to_present = false; + if (p_cfg->qos_present) p_ccb->peer_cfg.qos_present = false; - if ( (p_cfg->result == L2CAP_CFG_OK) || (p_cfg->result == L2CAP_CFG_PENDING) ) - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_RSP, p_cfg); - else - { - p_cfg->fcr_present = false; /* FCR options already negotiated before this point */ - - /* Clear out any cached options that are being returned as an error (excluding FCR) */ - if (p_cfg->mtu_present) - p_ccb->peer_cfg.mtu_present = false; - if (p_cfg->flush_to_present) - p_ccb->peer_cfg.flush_to_present = false; - if (p_cfg->qos_present) - p_ccb->peer_cfg.qos_present = false; - - l2c_csm_execute (p_ccb, L2CEVT_L2CA_CONFIG_RSP_NEG, p_cfg); - } + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_RSP_NEG, p_cfg); + } - return (true); + return (true); } /******************************************************************************* @@ -890,23 +838,21 @@ bool L2CA_ConfigRsp (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) * Returns true if disconnect sent, else false * ******************************************************************************/ -bool L2CA_DisconnectReq (uint16_t cid) -{ - tL2C_CCB *p_ccb; +bool L2CA_DisconnectReq(uint16_t cid) { + tL2C_CCB* p_ccb; - L2CAP_TRACE_API ("L2CA_DisconnectReq() CID: 0x%04x", cid); + L2CAP_TRACE_API("L2CA_DisconnectReq() CID: 0x%04x", cid); - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_disc_req, CID: %d", cid); - return (false); - } + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_disc_req, CID: %d", cid); + return (false); + } - l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL); - return (true); + return (true); } /******************************************************************************* @@ -919,23 +865,21 @@ bool L2CA_DisconnectReq (uint16_t cid) * Returns void * ******************************************************************************/ -bool L2CA_DisconnectRsp (uint16_t cid) -{ - tL2C_CCB *p_ccb; +bool L2CA_DisconnectRsp(uint16_t cid) { + tL2C_CCB* p_ccb; - L2CAP_TRACE_API ("L2CA_DisconnectRsp() CID: 0x%04x", cid); + L2CAP_TRACE_API("L2CA_DisconnectRsp() CID: 0x%04x", cid); - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_disc_rsp, CID: %d", cid); - return (false); - } + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_disc_rsp, CID: %d", cid); + return (false); + } - l2c_csm_execute (p_ccb, L2CEVT_L2CA_DISCONNECT_RSP, NULL); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_RSP, NULL); - return (true); + return (true); } /******************************************************************************* @@ -947,66 +891,58 @@ bool L2CA_DisconnectRsp (uint16_t cid) * Returns true if echo request sent, else false. * ******************************************************************************/ -bool L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_callback) -{ - tL2C_LCB *p_lcb; - - L2CAP_TRACE_API ("L2CA_Ping() BDA: %02x-%02x-%02x-%02x-%02x-%02x", - p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], p_bd_addr[4], p_bd_addr[5]); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - return (false); - - /* First, see if we already have a link to the remote */ - p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_ping"); - return (false); - } - if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) - { - return (false); - } +bool L2CA_Ping(BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB* p_callback) { + tL2C_LCB* p_lcb; - p_lcb->p_echo_rsp_cb = p_callback; + L2CAP_TRACE_API("L2CA_Ping() BDA: %02x-%02x-%02x-%02x-%02x-%02x", + p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3], + p_bd_addr[4], p_bd_addr[5]); - return (true); - } + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) return (false); - /* We only allow 1 ping outstanding at a time */ - if (p_lcb->p_echo_rsp_cb != NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - rejected second L2CA_ping"); - return (false); + /* First, see if we already have a link to the remote */ + p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no LCB for L2CA_ping"); + return (false); } - - /* Have a link control block. If link is disconnecting, tell user to retry later */ - if (p_lcb->link_state == LST_DISCONNECTING) - { - L2CAP_TRACE_WARNING ("L2CAP - L2CA_ping rejected - link disconnecting"); - return (false); + if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) { + return (false); } - /* Save address of callback */ p_lcb->p_echo_rsp_cb = p_callback; - if (p_lcb->link_state == LST_CONNECTED) - { - l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID); /* Make sure not using Broadcom ID */ - l2cu_send_peer_echo_req (p_lcb, NULL, 0); - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_ECHO_RSP_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } - return (true); + } + + /* We only allow 1 ping outstanding at a time */ + if (p_lcb->p_echo_rsp_cb != NULL) { + L2CAP_TRACE_WARNING("L2CAP - rejected second L2CA_ping"); + return (false); + } + + /* Have a link control block. If link is disconnecting, tell user to retry + * later */ + if (p_lcb->link_state == LST_DISCONNECTING) { + L2CAP_TRACE_WARNING("L2CAP - L2CA_ping rejected - link disconnecting"); + return (false); + } + + /* Save address of callback */ + p_lcb->p_echo_rsp_cb = p_callback; + + if (p_lcb->link_state == LST_CONNECTED) { + l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID); /* Make sure not using Broadcom ID */ + l2cu_send_peer_echo_req(p_lcb, NULL, 0); + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_ECHO_RSP_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } + + return (true); } /******************************************************************************* @@ -1019,61 +955,55 @@ bool L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_callback) * Returns true if echo request sent, else false. * ******************************************************************************/ -bool L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback) -{ - tL2C_LCB *p_lcb; - uint8_t *pp; - - L2CAP_TRACE_API ("L2CA_Echo() BDA: %08X%04X", - ((p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + (p_bd_addr[2] << 8) + (p_bd_addr[3])), - ((p_bd_addr[4] << 8) + (p_bd_addr[5]))); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - return (false); - - if ((memcmp(BT_BD_ANY, p_bd_addr, BD_ADDR_LEN) == 0) && (p_data == NULL)) - { - /* Only register callback without sending message. */ - l2cb.p_echo_data_cb = p_callback; - return true; - } +bool L2CA_Echo(BD_ADDR p_bd_addr, BT_HDR* p_data, + tL2CA_ECHO_DATA_CB* p_callback) { + tL2C_LCB* p_lcb; + uint8_t* pp; - /* We assume the upper layer will call this function only when the link is established. */ - p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CA_Echo ERROR : link not established"); - return false; - } + L2CAP_TRACE_API("L2CA_Echo() BDA: %08X%04X", + ((p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + + (p_bd_addr[2] << 8) + (p_bd_addr[3])), + ((p_bd_addr[4] << 8) + (p_bd_addr[5]))); - if (p_lcb->link_state != LST_CONNECTED) - { - L2CAP_TRACE_ERROR ("L2CA_Echo ERROR : link is not connected"); - return false; - } + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) return (false); - /* Save address of callback */ + if ((memcmp(BT_BD_ANY, p_bd_addr, BD_ADDR_LEN) == 0) && (p_data == NULL)) { + /* Only register callback without sending message. */ l2cb.p_echo_data_cb = p_callback; + return true; + } - /* Set the pointer to the beginning of the data */ - pp = (uint8_t *)(p_data + 1) + p_data->offset; - l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID); /* Make sure not using Broadcom ID */ - l2cu_send_peer_echo_req (p_lcb, pp, p_data->len); + /* We assume the upper layer will call this function only when the link is + * established. */ + p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_ERROR("L2CA_Echo ERROR : link not established"); + return false; + } - return (true); + if (p_lcb->link_state != LST_CONNECTED) { + L2CAP_TRACE_ERROR("L2CA_Echo ERROR : link is not connected"); + return false; + } + /* Save address of callback */ + l2cb.p_echo_data_cb = p_callback; + + /* Set the pointer to the beginning of the data */ + pp = (uint8_t*)(p_data + 1) + p_data->offset; + l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID); /* Make sure not using Broadcom ID */ + l2cu_send_peer_echo_req(p_lcb, pp, p_data->len); + + return (true); } -bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle) { - tL2C_CCB *control_block = l2cu_find_ccb_by_cid(NULL, lcid); - if (!control_block) - return false; +bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t* rcid, uint16_t* handle) { + tL2C_CCB* control_block = l2cu_find_ccb_by_cid(NULL, lcid); + if (!control_block) return false; - if (rcid) - *rcid = control_block->remote_cid; - if (handle) - *handle = control_block->p_lcb->handle; + if (rcid) *rcid = control_block->remote_cid; + if (handle) *handle = control_block->p_lcb->handle; return true; } @@ -1097,34 +1027,30 @@ bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle) { * whan a connection is established till the first channel is * set up. ******************************************************************************/ -bool L2CA_SetIdleTimeout (uint16_t cid, uint16_t timeout, bool is_global) -{ - tL2C_CCB *p_ccb; - tL2C_LCB *p_lcb; - - if (is_global) - { - l2cb.idle_timeout = timeout; +bool L2CA_SetIdleTimeout(uint16_t cid, uint16_t timeout, bool is_global) { + tL2C_CCB* p_ccb; + tL2C_LCB* p_lcb; + + if (is_global) { + l2cb.idle_timeout = timeout; + } else { + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_SetIdleTimeout, CID: %d", + cid); + return (false); } - else - { - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetIdleTimeout, CID: %d", cid); - return (false); - } - p_lcb = p_ccb->p_lcb; + p_lcb = p_ccb->p_lcb; - if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) - p_lcb->idle_timeout = timeout; - else - return (false); - } + if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) + p_lcb->idle_timeout = timeout; + else + return (false); + } - return (true); + return (true); } /******************************************************************************* @@ -1146,41 +1072,32 @@ bool L2CA_SetIdleTimeout (uint16_t cid, uint16_t timeout, bool is_global) * NOTE This timeout applies to all logical channels active on the * ACL link. ******************************************************************************/ -bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, tBT_TRANSPORT transport) -{ - tL2C_LCB *p_lcb; - - if (memcmp (BT_BD_ANY, bd_addr, BD_ADDR_LEN)) - { - p_lcb = l2cu_find_lcb_by_bd_addr( bd_addr, transport); - if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) - { - p_lcb->idle_timeout = timeout; - - if (!p_lcb->ccb_queue.p_first_ccb) - l2cu_no_dynamic_ccbs (p_lcb); - } - else - return false; - } - else - { - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; - - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) - { - p_lcb->idle_timeout = timeout; - - if (!p_lcb->ccb_queue.p_first_ccb) - l2cu_no_dynamic_ccbs (p_lcb); - } - } +bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, + tBT_TRANSPORT transport) { + tL2C_LCB* p_lcb; + + if (memcmp(BT_BD_ANY, bd_addr, BD_ADDR_LEN)) { + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, transport); + if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) { + p_lcb->idle_timeout = timeout; + + if (!p_lcb->ccb_queue.p_first_ccb) l2cu_no_dynamic_ccbs(p_lcb); + } else + return false; + } else { + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; + + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) { + p_lcb->idle_timeout = timeout; + + if (!p_lcb->ccb_queue.p_first_ccb) l2cu_no_dynamic_ccbs(p_lcb); + } } + } - return true; + return true; } /******************************************************************************* @@ -1193,12 +1110,10 @@ bool L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, uint16_t timeout, tBT_TRANS * Returns the new (current) trace level * ******************************************************************************/ -uint8_t L2CA_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - l2cb.l2cap_trace_level = new_level; +uint8_t L2CA_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) l2cb.l2cap_trace_level = new_level; - return (l2cb.l2cap_trace_level); + return (l2cb.l2cap_trace_level); } /******************************************************************************* @@ -1218,28 +1133,24 @@ uint8_t L2CA_SetTraceLevel (uint8_t new_level) * Returns the new (current) role * ******************************************************************************/ -uint8_t L2CA_SetDesireRole (uint8_t new_role) -{ - L2CAP_TRACE_API ("L2CA_SetDesireRole() new:x%x, disallow_switch:%d", - new_role, l2cb.disallow_switch); - - if (L2CAP_ROLE_CHECK_SWITCH != (L2CAP_ROLE_CHECK_SWITCH & new_role)) - { - /* do not process the allow_switch when both bits are set */ - if (new_role & L2CAP_ROLE_ALLOW_SWITCH) - { - l2cb.disallow_switch = false; - } - if (new_role & L2CAP_ROLE_DISALLOW_SWITCH) - { - l2cb.disallow_switch = true; - } +uint8_t L2CA_SetDesireRole(uint8_t new_role) { + L2CAP_TRACE_API("L2CA_SetDesireRole() new:x%x, disallow_switch:%d", new_role, + l2cb.disallow_switch); + + if (L2CAP_ROLE_CHECK_SWITCH != (L2CAP_ROLE_CHECK_SWITCH & new_role)) { + /* do not process the allow_switch when both bits are set */ + if (new_role & L2CAP_ROLE_ALLOW_SWITCH) { + l2cb.disallow_switch = false; + } + if (new_role & L2CAP_ROLE_DISALLOW_SWITCH) { + l2cb.disallow_switch = true; } + } - if (new_role == HCI_ROLE_MASTER || new_role == HCI_ROLE_SLAVE) - l2cb.desire_role = new_role; + if (new_role == HCI_ROLE_MASTER || new_role == HCI_ROLE_SLAVE) + l2cb.desire_role = new_role; - return (l2cb.desire_role); + return (l2cb.desire_role); } /******************************************************************************* @@ -1251,55 +1162,52 @@ uint8_t L2CA_SetDesireRole (uint8_t new_role) * Returns CID of 0 if none. * ******************************************************************************/ -uint16_t L2CA_LocalLoopbackReq (uint16_t psm, uint16_t handle, BD_ADDR p_bd_addr) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - - L2CAP_TRACE_API ("L2CA_LocalLoopbackReq() PSM: %d Handle: 0x%04x", psm, handle); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING ("L2CAP loop req - BTU not ready"); - return (0); - } +uint16_t L2CA_LocalLoopbackReq(uint16_t psm, uint16_t handle, + BD_ADDR p_bd_addr) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + + L2CAP_TRACE_API("L2CA_LocalLoopbackReq() PSM: %d Handle: 0x%04x", psm, + handle); + + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("L2CAP loop req - BTU not ready"); + return (0); + } - /* Fail if the PSM is not registered */ - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_conn_req, PSM: %d", psm); - return (0); - } + /* Fail if the PSM is not registered */ + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no RCB for L2CA_conn_req, PSM: %d", psm); + return (0); + } - p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_conn_req"); - return (0); - } + p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no LCB for L2CA_conn_req"); + return (0); + } - p_lcb->link_state = LST_CONNECTED; - p_lcb->handle = handle; + p_lcb->link_state = LST_CONNECTED; + p_lcb->handle = handle; - /* Allocate a channel control block */ - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_conn_req"); - return (0); - } + /* Allocate a channel control block */ + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_conn_req"); + return (0); + } - /* Save registration info */ - p_ccb->p_rcb = p_rcb; - p_ccb->chnl_state = CST_OPEN; - p_ccb->remote_cid = p_ccb->local_cid; - p_ccb->config_done = CFG_DONE_MASK; + /* Save registration info */ + p_ccb->p_rcb = p_rcb; + p_ccb->chnl_state = CST_OPEN; + p_ccb->remote_cid = p_ccb->local_cid; + p_ccb->config_done = CFG_DONE_MASK; - /* Return the local CID as our handle */ - return (p_ccb->local_cid); + /* Return the local CID as our handle */ + return (p_ccb->local_cid); } /******************************************************************************* @@ -1313,13 +1221,13 @@ uint16_t L2CA_LocalLoopbackReq (uint16_t psm, uint16_t handle, BD_ADDR p_bd_addr * Returns true if a valid channel, else false * ******************************************************************************/ -bool L2CA_SetAclPriority (BD_ADDR bd_addr, uint8_t priority) -{ - L2CAP_TRACE_API ("L2CA_SetAclPriority() bdaddr: %02x%02x%02x%02x%04x, priority:%d", - bd_addr[0], bd_addr[1], bd_addr[2], - bd_addr[3], (bd_addr[4] << 8) + bd_addr[5], priority); +bool L2CA_SetAclPriority(BD_ADDR bd_addr, uint8_t priority) { + L2CAP_TRACE_API( + "L2CA_SetAclPriority() bdaddr: %02x%02x%02x%02x%04x, priority:%d", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], priority); - return (l2cu_set_acl_priority(bd_addr, priority, false)); + return (l2cu_set_acl_priority(bd_addr, priority, false)); } /******************************************************************************* @@ -1333,40 +1241,38 @@ bool L2CA_SetAclPriority (BD_ADDR bd_addr, uint8_t priority) * Returns true if valid channel, else false * ******************************************************************************/ -bool L2CA_FlowControl (uint16_t cid, bool data_enabled) -{ - tL2C_CCB *p_ccb; - bool on_off = !data_enabled; - - L2CAP_TRACE_API ("L2CA_FlowControl(%d) CID: 0x%04x", on_off, cid); +bool L2CA_FlowControl(uint16_t cid, bool data_enabled) { + tL2C_CCB* p_ccb; + bool on_off = !data_enabled; + + L2CAP_TRACE_API("L2CA_FlowControl(%d) CID: 0x%04x", on_off, cid); + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING( + "L2CAP - no CCB for L2CA_FlowControl, CID: 0x%04x data_enabled: %d", + cid, data_enabled); + return (false); + } - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_FlowControl, CID: 0x%04x data_enabled: %d", cid, data_enabled); - return (false); - } + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) { + L2CAP_TRACE_EVENT("L2CA_FlowControl() invalid mode:%d", + p_ccb->peer_cfg.fcr.mode); + return (false); + } + if (p_ccb->fcrb.local_busy != on_off) { + p_ccb->fcrb.local_busy = on_off; - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) - { - L2CAP_TRACE_EVENT ("L2CA_FlowControl() invalid mode:%d", p_ccb->peer_cfg.fcr.mode); - return (false); - } - if (p_ccb->fcrb.local_busy != on_off) - { - p_ccb->fcrb.local_busy = on_off; - - if ( (p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack) ) - { - if (on_off) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT); - } + if ((p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack)) { + if (on_off) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, 0); + else + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT); } + } - return (true); + return (true); } /******************************************************************************* @@ -1378,28 +1284,31 @@ bool L2CA_FlowControl (uint16_t cid, bool data_enabled) * Returns true if valid Channel, else false * ******************************************************************************/ -bool L2CA_SendTestSFrame (uint16_t cid, uint8_t sup_type, uint8_t back_track) -{ - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_SendTestSFrame() CID: 0x%04x Type: 0x%02x back_track: %u", cid, sup_type, back_track); - - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SendTestSFrame, CID: %d", cid); - return (false); - } +bool L2CA_SendTestSFrame(uint16_t cid, uint8_t sup_type, uint8_t back_track) { + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_SendTestSFrame() CID: 0x%04x Type: 0x%02x back_track: %u", cid, + sup_type, back_track); + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_SendTestSFrame, CID: %d", cid); + return (false); + } - if ( (p_ccb->chnl_state != CST_OPEN) || (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) ) - return (false); + if ((p_ccb->chnl_state != CST_OPEN) || + (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE)) + return (false); - p_ccb->fcrb.next_seq_expected -= back_track; + p_ccb->fcrb.next_seq_expected -= back_track; - l2c_fcr_send_S_frame (p_ccb, (uint16_t)(sup_type & 3), (uint16_t)(sup_type & (L2CAP_FCR_P_BIT | L2CAP_FCR_F_BIT))); + l2c_fcr_send_S_frame( + p_ccb, (uint16_t)(sup_type & 3), + (uint16_t)(sup_type & (L2CAP_FCR_P_BIT | L2CAP_FCR_F_BIT))); - return (true); + return (true); } /******************************************************************************* @@ -1411,24 +1320,24 @@ bool L2CA_SendTestSFrame (uint16_t cid, uint8_t sup_type, uint8_t back_track) * Returns true if a valid channel, else false * ******************************************************************************/ -bool L2CA_SetTxPriority (uint16_t cid, tL2CAP_CHNL_PRIORITY priority) -{ - tL2C_CCB *p_ccb; +bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) { + tL2C_CCB* p_ccb; - L2CAP_TRACE_API ("L2CA_SetTxPriority() CID: 0x%04x, priority:%d", cid, priority); + L2CAP_TRACE_API("L2CA_SetTxPriority() CID: 0x%04x, priority:%d", cid, + priority); - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetTxPriority, CID: %d", cid); - return (false); - } + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_SetTxPriority, CID: %d", cid); + return (false); + } - /* it will update the order of CCB in LCB by priority and update round robin service variables */ - l2cu_change_pri_ccb (p_ccb, priority); + /* it will update the order of CCB in LCB by priority and update round robin + * service variables */ + l2cu_change_pri_ccb(p_ccb, priority); - return (true); + return (true); } /******************************************************************************* @@ -1440,27 +1349,28 @@ bool L2CA_SetTxPriority (uint16_t cid, tL2CAP_CHNL_PRIORITY priority) * Returns true if a valid channel, else false * ******************************************************************************/ -bool L2CA_SetChnlDataRate (uint16_t cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx) -{ - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_SetChnlDataRate() CID: 0x%04x, tx:%d, rx:%d", cid, tx, rx); - - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetChnlDataRate, CID: %d", cid); - return (false); - } +bool L2CA_SetChnlDataRate(uint16_t cid, tL2CAP_CHNL_DATA_RATE tx, + tL2CAP_CHNL_DATA_RATE rx) { + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API("L2CA_SetChnlDataRate() CID: 0x%04x, tx:%d, rx:%d", cid, tx, + rx); + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_SetChnlDataRate, CID: %d", + cid); + return (false); + } - p_ccb->tx_data_rate = tx; - p_ccb->rx_data_rate = rx; + p_ccb->tx_data_rate = tx; + p_ccb->rx_data_rate = rx; - /* Adjust channel buffer allocation */ - l2c_link_adjust_chnl_allocation (); + /* Adjust channel buffer allocation */ + l2c_link_adjust_chnl_allocation(); - return(true); + return (true); } /******************************************************************************* @@ -1487,95 +1397,81 @@ bool L2CA_SetChnlDataRate (uint16_t cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHN * NOTE This flush timeout applies to all logical channels active on * the ACL link. ******************************************************************************/ -bool L2CA_SetFlushTimeout (BD_ADDR bd_addr, uint16_t flush_tout) -{ - tL2C_LCB *p_lcb; - uint16_t hci_flush_to; - uint32_t temp; - - /* no automatic flush (infinite timeout) */ - if (flush_tout == 0x0000) - { - hci_flush_to = flush_tout; - flush_tout = L2CAP_NO_AUTOMATIC_FLUSH; - } - /* no retransmission */ - else if (flush_tout == L2CAP_NO_RETRANSMISSION) - { - /* not mandatory range for controller */ - /* Packet is flushed before getting any ACK/NACK */ - /* To do this, flush timeout should be 1 baseband slot */ - hci_flush_to = flush_tout; - } - /* no automatic flush (infinite timeout) */ - else if (flush_tout == L2CAP_NO_AUTOMATIC_FLUSH) - { - hci_flush_to = 0x0000; - } - else - { - /* convert L2CAP flush_to to 0.625 ms units, with round */ - temp = (((uint32_t)flush_tout * 8) + 3) / 5; - - /* if L2CAP flush_to within range of HCI, set HCI flush timeout */ - if (temp > HCI_MAX_AUTO_FLUSH_TOUT) - { - L2CAP_TRACE_WARNING("WARNING L2CA_SetFlushTimeout timeout(0x%x) is out of range", flush_tout); - return false; - } - else - { - hci_flush_to = (uint16_t)temp; - } +bool L2CA_SetFlushTimeout(BD_ADDR bd_addr, uint16_t flush_tout) { + tL2C_LCB* p_lcb; + uint16_t hci_flush_to; + uint32_t temp; + + /* no automatic flush (infinite timeout) */ + if (flush_tout == 0x0000) { + hci_flush_to = flush_tout; + flush_tout = L2CAP_NO_AUTOMATIC_FLUSH; + } + /* no retransmission */ + else if (flush_tout == L2CAP_NO_RETRANSMISSION) { + /* not mandatory range for controller */ + /* Packet is flushed before getting any ACK/NACK */ + /* To do this, flush timeout should be 1 baseband slot */ + hci_flush_to = flush_tout; + } + /* no automatic flush (infinite timeout) */ + else if (flush_tout == L2CAP_NO_AUTOMATIC_FLUSH) { + hci_flush_to = 0x0000; + } else { + /* convert L2CAP flush_to to 0.625 ms units, with round */ + temp = (((uint32_t)flush_tout * 8) + 3) / 5; + + /* if L2CAP flush_to within range of HCI, set HCI flush timeout */ + if (temp > HCI_MAX_AUTO_FLUSH_TOUT) { + L2CAP_TRACE_WARNING( + "WARNING L2CA_SetFlushTimeout timeout(0x%x) is out of range", + flush_tout); + return false; + } else { + hci_flush_to = (uint16_t)temp; } + } - if (memcmp (BT_BD_ANY, bd_addr, BD_ADDR_LEN)) - { - p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR); - - if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) - { - if (p_lcb->link_flush_tout != flush_tout) - { - p_lcb->link_flush_tout = flush_tout; - - L2CAP_TRACE_API ("L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]", - flush_tout, bd_addr[3], bd_addr[4], bd_addr[5]); + if (memcmp(BT_BD_ANY, bd_addr, BD_ADDR_LEN)) { + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); - btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to); - } - } - else - { - L2CAP_TRACE_WARNING ("WARNING L2CA_SetFlushTimeout No lcb for bd_addr [...;%02x%02x%02x]", - bd_addr[3], bd_addr[4], bd_addr[5]); - return (false); - } - } - else - { - int xx; - p_lcb = &l2cb.lcb_pool[0]; - - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) - { - if (p_lcb->link_flush_tout != flush_tout) - { - p_lcb->link_flush_tout = flush_tout; - - L2CAP_TRACE_API ("L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]", - flush_tout, p_lcb->remote_bd_addr[3], - p_lcb->remote_bd_addr[4], p_lcb->remote_bd_addr[5]); - - btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to); - } - } + if ((p_lcb) && (p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) { + if (p_lcb->link_flush_tout != flush_tout) { + p_lcb->link_flush_tout = flush_tout; + + L2CAP_TRACE_API( + "L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]", + flush_tout, bd_addr[3], bd_addr[4], bd_addr[5]); + + btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to); + } + } else { + L2CAP_TRACE_WARNING( + "WARNING L2CA_SetFlushTimeout No lcb for bd_addr [...;%02x%02x%02x]", + bd_addr[3], bd_addr[4], bd_addr[5]); + return (false); + } + } else { + int xx; + p_lcb = &l2cb.lcb_pool[0]; + + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTED)) { + if (p_lcb->link_flush_tout != flush_tout) { + p_lcb->link_flush_tout = flush_tout; + + L2CAP_TRACE_API( + "L2CA_SetFlushTimeout 0x%04x ms for bd_addr [...;%02x%02x%02x]", + flush_tout, p_lcb->remote_bd_addr[3], p_lcb->remote_bd_addr[4], + p_lcb->remote_bd_addr[5]); + + btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to); } + } } + } - return (true); + return (true); } /******************************************************************************* @@ -1590,29 +1486,32 @@ bool L2CA_SetFlushTimeout (BD_ADDR bd_addr, uint16_t flush_tout) * Return value: true if peer is connected * ******************************************************************************/ -bool L2CA_GetPeerFeatures (BD_ADDR bd_addr, uint32_t *p_ext_feat, uint8_t *p_chnl_mask) -{ - tL2C_LCB *p_lcb; - - /* We must already have a link to the remote */ - p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CA_GetPeerFeatures() No BDA: %08x%04x", - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5]); - return (false); - } +bool L2CA_GetPeerFeatures(BD_ADDR bd_addr, uint32_t* p_ext_feat, + uint8_t* p_chnl_mask) { + tL2C_LCB* p_lcb; + + /* We must already have a link to the remote */ + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CA_GetPeerFeatures() No BDA: %08x%04x", + (bd_addr[0] << 24) + (bd_addr[1] << 16) + + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5]); + return (false); + } - L2CAP_TRACE_API ("L2CA_GetPeerFeatures() BDA: %08x%04x ExtFea: 0x%08x Chnl_Mask[0]: 0x%02x", - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], p_lcb->peer_ext_fea, p_lcb->peer_chnl_mask[0]); + L2CAP_TRACE_API( + "L2CA_GetPeerFeatures() BDA: %08x%04x ExtFea: 0x%08x Chnl_Mask[0]: " + "0x%02x", + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], p_lcb->peer_ext_fea, + p_lcb->peer_chnl_mask[0]); - *p_ext_feat = p_lcb->peer_ext_fea; + *p_ext_feat = p_lcb->peer_ext_fea; - memcpy (p_chnl_mask, p_lcb->peer_chnl_mask, L2CAP_FIXED_CHNL_ARRAY_SIZE); + memcpy(p_chnl_mask, p_lcb->peer_chnl_mask, L2CAP_FIXED_CHNL_ARRAY_SIZE); - return (true); + return (true); } /******************************************************************************* @@ -1627,19 +1526,17 @@ bool L2CA_GetPeerFeatures (BD_ADDR bd_addr, uint32_t *p_ext_feat, uint8_t *p_ * Return value: true if found lcb for the given handle, false otherwise * ******************************************************************************/ -bool L2CA_GetBDAddrbyHandle (uint16_t handle, BD_ADDR bd_addr) -{ - tL2C_LCB *p_lcb = NULL; - bool found_dev = false; - - p_lcb = l2cu_find_lcb_by_handle (handle); - if (p_lcb) - { - found_dev = true; - memcpy (bd_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); - } +bool L2CA_GetBDAddrbyHandle(uint16_t handle, BD_ADDR bd_addr) { + tL2C_LCB* p_lcb = NULL; + bool found_dev = false; + + p_lcb = l2cu_find_lcb_by_handle(handle); + if (p_lcb) { + found_dev = true; + memcpy(bd_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); + } - return found_dev; + return found_dev; } /******************************************************************************* @@ -1653,18 +1550,17 @@ bool L2CA_GetBDAddrbyHandle (uint16_t handle, BD_ADDR bd_addr) * Return value: Channel mode * ******************************************************************************/ -uint8_t L2CA_GetChnlFcrMode (uint16_t lcid) -{ - tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid (NULL, lcid); - - if (p_ccb) - { - L2CAP_TRACE_API ("L2CA_GetChnlFcrMode() returns mode %d", p_ccb->peer_cfg.fcr.mode); - return (p_ccb->peer_cfg.fcr.mode); - } +uint8_t L2CA_GetChnlFcrMode(uint16_t lcid) { + tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); - L2CAP_TRACE_API ("L2CA_GetChnlFcrMode() returns mode L2CAP_FCR_BASIC_MODE"); - return (L2CAP_FCR_BASIC_MODE); + if (p_ccb) { + L2CAP_TRACE_API("L2CA_GetChnlFcrMode() returns mode %d", + p_ccb->peer_cfg.fcr.mode); + return (p_ccb->peer_cfg.fcr.mode); + } + + L2CAP_TRACE_API("L2CA_GetChnlFcrMode() returns mode L2CAP_FCR_BASIC_MODE"); + return (L2CAP_FCR_BASIC_MODE); } #if (L2CAP_NUM_FIXED_CHNLS > 0) @@ -1680,17 +1576,18 @@ uint8_t L2CA_GetChnlFcrMode (uint16_t lcid) * Return value: - * ******************************************************************************/ -bool L2CA_RegisterFixedChannel (uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg) -{ - if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) ) - { - L2CAP_TRACE_ERROR ("L2CA_RegisterFixedChannel() Invalid CID: 0x%04x", fixed_cid); - - return (false); - } +bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, + tL2CAP_FIXED_CHNL_REG* p_freg) { + if ((fixed_cid < L2CAP_FIRST_FIXED_CHNL) || + (fixed_cid > L2CAP_LAST_FIXED_CHNL)) { + L2CAP_TRACE_ERROR("L2CA_RegisterFixedChannel() Invalid CID: 0x%04x", + fixed_cid); + + return (false); + } - l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = *p_freg; - return (true); + l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = *p_freg; + return (true); } /******************************************************************************* @@ -1705,102 +1602,102 @@ bool L2CA_RegisterFixedChannel (uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG *p * Return value: true if connection started * ******************************************************************************/ -bool L2CA_ConnectFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda) -{ - tL2C_LCB *p_lcb; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - L2CAP_TRACE_API ("%s() CID: 0x%04x BDA: %08x%04x", __func__, fixed_cid, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); - - // Check CID is valid and registered - if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) - || (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) - { - L2CAP_TRACE_ERROR ("%s() Invalid CID: 0x%04x", __func__, fixed_cid); - return (false); - } +bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, BD_ADDR rem_bda) { + tL2C_LCB* p_lcb; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + + L2CAP_TRACE_API( + "%s() CID: 0x%04x BDA: %08x%04x", __func__, fixed_cid, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + // Check CID is valid and registered + if ((fixed_cid < L2CAP_FIRST_FIXED_CHNL) || + (fixed_cid > L2CAP_LAST_FIXED_CHNL) || + (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == + NULL)) { + L2CAP_TRACE_ERROR("%s() Invalid CID: 0x%04x", __func__, fixed_cid); + return (false); + } - // Fail if BT is not yet up - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING ("%s(0x%04x) - BTU not ready", __func__, fixed_cid); - return (false); - } + // Fail if BT is not yet up + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("%s(0x%04x) - BTU not ready", __func__, fixed_cid); + return (false); + } - if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) - transport = BT_TRANSPORT_LE; - - tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask; - - // If we already have a link to the remote, check if it supports that CID - p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport); - if (p_lcb != NULL) - { - // Fixed channels are mandatory on LE transports so ignore the received - // channel mask and use the locally cached LE channel mask. - - if (transport == BT_TRANSPORT_LE) - peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask; - else - peer_channel_mask = p_lcb->peer_chnl_mask[0]; - - // Check for supported channel - if (!(peer_channel_mask & (1 << fixed_cid))) - { - L2CAP_TRACE_EVENT ("%s() CID:0x%04x BDA: %08x%04x not supported", __func__, - fixed_cid,(rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - return false; - } + if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) + transport = BT_TRANSPORT_LE; - // Get a CCB and link the lcb to it - if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid, - &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - L2CAP_TRACE_WARNING ("%s(0x%04x) - LCB but no CCB", __func__, fixed_cid); - return false; - } + tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask; - // racing with disconnecting, queue the connection request - if (p_lcb->link_state == LST_DISCONNECTING) - { - L2CAP_TRACE_DEBUG ("$s() - link disconnecting: RETRY LATER", __func__); - /* Save ccb so it can be started after disconnect is finished */ - p_lcb->p_pending_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; - return true; - } + // If we already have a link to the remote, check if it supports that CID + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport); + if (p_lcb != NULL) { + // Fixed channels are mandatory on LE transports so ignore the received + // channel mask and use the locally cached LE channel mask. - (*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb) - (fixed_cid,p_lcb->remote_bd_addr, true, 0, p_lcb->transport); - return true; - } + if (transport == BT_TRANSPORT_LE) + peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask; + else + peer_channel_mask = p_lcb->peer_chnl_mask[0]; - // No link. Get an LCB and start link establishment - p_lcb = l2cu_allocate_lcb(rem_bda, false, transport); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("%s(0x%04x) - no LCB", __func__, fixed_cid); - return false; + // Check for supported channel + if (!(peer_channel_mask & (1 << fixed_cid))) { + L2CAP_TRACE_EVENT("%s() CID:0x%04x BDA: %08x%04x not supported", + __func__, fixed_cid, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return false; } // Get a CCB and link the lcb to it - if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid, - &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - p_lcb->disc_reason = L2CAP_CONN_NO_RESOURCES; - L2CAP_TRACE_WARNING ("%s(0x%04x) - no CCB", __func__, fixed_cid); - l2cu_release_lcb (p_lcb); - return false; + if (!l2cu_initialize_fixed_ccb( + p_lcb, fixed_cid, + &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + L2CAP_TRACE_WARNING("%s(0x%04x) - LCB but no CCB", __func__, fixed_cid); + return false; } - if (!l2cu_create_conn(p_lcb, transport)) - { - L2CAP_TRACE_WARNING ("%s() - create_conn failed", __func__); - l2cu_release_lcb (p_lcb); - return false; + // racing with disconnecting, queue the connection request + if (p_lcb->link_state == LST_DISCONNECTING) { + L2CAP_TRACE_DEBUG("$s() - link disconnecting: RETRY LATER", __func__); + /* Save ccb so it can be started after disconnect is finished */ + p_lcb->p_pending_ccb = + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; + return true; } + + (*l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedConn_Cb)( + fixed_cid, p_lcb->remote_bd_addr, true, 0, p_lcb->transport); return true; + } + + // No link. Get an LCB and start link establishment + p_lcb = l2cu_allocate_lcb(rem_bda, false, transport); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("%s(0x%04x) - no LCB", __func__, fixed_cid); + return false; + } + + // Get a CCB and link the lcb to it + if (!l2cu_initialize_fixed_ccb( + p_lcb, fixed_cid, &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + p_lcb->disc_reason = L2CAP_CONN_NO_RESOURCES; + L2CAP_TRACE_WARNING("%s(0x%04x) - no CCB", __func__, fixed_cid); + l2cu_release_lcb(p_lcb); + return false; + } + + if (!l2cu_create_conn(p_lcb, transport)) { + L2CAP_TRACE_WARNING("%s() - create_conn failed", __func__); + l2cu_release_lcb(p_lcb); + return false; + } + return true; } /******************************************************************************* @@ -1817,97 +1714,107 @@ bool L2CA_ConnectFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda) * L2CAP_DW_FAILED, if error * ******************************************************************************/ -uint16_t L2CA_SendFixedChnlData (uint16_t fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf) -{ - tL2C_LCB *p_lcb; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - L2CAP_TRACE_API ("L2CA_SendFixedChnlData() CID: 0x%04x BDA: %08x%04x", fixed_cid, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); - - if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) - transport = BT_TRANSPORT_LE; - - // Check CID is valid and registered - if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) - || (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) - { - L2CAP_TRACE_ERROR ("L2CA_SendFixedChnlData() Invalid CID: 0x%04x", fixed_cid); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } +uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, BD_ADDR rem_bda, + BT_HDR* p_buf) { + tL2C_LCB* p_lcb; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + + L2CAP_TRACE_API( + "L2CA_SendFixedChnlData() CID: 0x%04x BDA: %08x%04x", fixed_cid, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) + transport = BT_TRANSPORT_LE; + + // Check CID is valid and registered + if ((fixed_cid < L2CAP_FIRST_FIXED_CHNL) || + (fixed_cid > L2CAP_LAST_FIXED_CHNL) || + (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == + NULL)) { + L2CAP_TRACE_ERROR("L2CA_SendFixedChnlData() Invalid CID: 0x%04x", + fixed_cid); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - // Fail if BT is not yet up - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - BTU not ready", fixed_cid); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + // Fail if BT is not yet up + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData(0x%04x) - BTU not ready", + fixed_cid); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - // We need to have a link up - if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport)) == NULL || - /* if link is disconnecting, also report data sending failure */ - p_lcb->link_state == LST_DISCONNECTING) - { - L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + // We need to have a link up + if ((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport)) == NULL || + /* if link is disconnecting, also report data sending failure */ + p_lcb->link_state == LST_DISCONNECTING) { + L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask; + tL2C_BLE_FIXED_CHNLS_MASK peer_channel_mask; - // Select peer channels mask to use depending on transport - if (transport == BT_TRANSPORT_LE) - peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask; - else - peer_channel_mask = p_lcb->peer_chnl_mask[0]; + // Select peer channels mask to use depending on transport + if (transport == BT_TRANSPORT_LE) + peer_channel_mask = l2cb.l2c_ble_fixed_chnls_mask; + else + peer_channel_mask = p_lcb->peer_chnl_mask[0]; - if ((peer_channel_mask & (1 << fixed_cid)) == 0) - { - L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - peer does not support fixed chnl: 0x%04x", fixed_cid); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + if ((peer_channel_mask & (1 << fixed_cid)) == 0) { + L2CAP_TRACE_WARNING( + "L2CA_SendFixedChnlData() - peer does not support fixed chnl: 0x%04x", + fixed_cid); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - p_buf->event = 0; - p_buf->layer_specific = L2CAP_FLUSHABLE_CH_BASED; + p_buf->event = 0; + p_buf->layer_specific = L2CAP_FLUSHABLE_CH_BASED; - if (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) - { - if (!l2cu_initialize_fixed_ccb (p_lcb, fixed_cid, &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - L2CAP_TRACE_WARNING ("L2CA_SendFixedChnlData() - no CCB for chnl: 0x%4x", fixed_cid); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + if (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) { + if (!l2cu_initialize_fixed_ccb( + p_lcb, fixed_cid, + &l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData() - no CCB for chnl: 0x%4x", + fixed_cid); + osi_free(p_buf); + return (L2CAP_DW_FAILED); } + } - // If already congested, do not accept any more packets - if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) - { - L2CAP_TRACE_ERROR ("L2CAP - CID: 0x%04x cannot send, already congested \ - xmit_hold_q.count: %u buff_quota: %u", fixed_cid, - fixed_queue_length(p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->xmit_hold_q), - p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + // If already congested, do not accept any more packets + if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) { + L2CAP_TRACE_ERROR( + "L2CAP - CID: 0x%04x cannot send, already congested \ + xmit_hold_q.count: %u buff_quota: %u", + fixed_cid, fixed_queue_length( + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] + ->xmit_hold_q), + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - l2c_enqueue_peer_data (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL], p_buf); + l2c_enqueue_peer_data(p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL], + p_buf); - l2c_link_check_send_pkts (p_lcb, NULL, NULL); + l2c_link_check_send_pkts(p_lcb, NULL, NULL); - // If there is no dynamic CCB on the link, restart the idle timer each time something is sent - if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && !p_lcb->ccb_queue.p_first_ccb) - { - l2cu_no_dynamic_ccbs (p_lcb); - } + // If there is no dynamic CCB on the link, restart the idle timer each time + // something is sent + if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && + !p_lcb->ccb_queue.p_first_ccb) { + l2cu_no_dynamic_ccbs(p_lcb); + } - if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) - return (L2CAP_DW_CONGESTED); + if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) + return (L2CAP_DW_CONGESTED); - return (L2CAP_DW_SUCCESS); + return (L2CAP_DW_SUCCESS); } /******************************************************************************* @@ -1923,54 +1830,60 @@ uint16_t L2CA_SendFixedChnlData (uint16_t fixed_cid, BD_ADDR rem_bda, BT_HDR *p_ * Return value: true if channel removed * ******************************************************************************/ -bool L2CA_RemoveFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - /* Check CID is valid and registered */ - if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) - || (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) - { - L2CAP_TRACE_ERROR ("L2CA_RemoveFixedChnl() Invalid CID: 0x%04x", fixed_cid); - return (false); - } +bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, BD_ADDR rem_bda) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + + /* Check CID is valid and registered */ + if ((fixed_cid < L2CAP_FIRST_FIXED_CHNL) || + (fixed_cid > L2CAP_LAST_FIXED_CHNL) || + (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == + NULL)) { + L2CAP_TRACE_ERROR("L2CA_RemoveFixedChnl() Invalid CID: 0x%04x", fixed_cid); + return (false); + } - if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) - transport = BT_TRANSPORT_LE; + if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) + transport = BT_TRANSPORT_LE; - /* Is a fixed channel connected to the remote BDA ?*/ - p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport); + /* Is a fixed channel connected to the remote BDA ?*/ + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport); - if ( ((p_lcb) == NULL) || (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) ) - { - L2CAP_TRACE_WARNING ("L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x not connected", fixed_cid, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); - return (false); - } + if (((p_lcb) == NULL) || + (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL])) { + L2CAP_TRACE_WARNING( + "L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x not connected", + fixed_cid, (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return (false); + } - L2CAP_TRACE_API ("L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x", fixed_cid, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); + L2CAP_TRACE_API( + "L2CA_RemoveFixedChnl() CID: 0x%04x BDA: %08x%04x", fixed_cid, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); - /* Release the CCB, starting an inactivity timeout on the LCB if no other CCBs exist */ - p_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; + /* Release the CCB, starting an inactivity timeout on the LCB if no other CCBs + * exist */ + p_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; - p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = NULL; - p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST; + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = NULL; + p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST; - // Retain the link for a few more seconds after SMP pairing is done, since - // the Android platform always does service discovery after pairing is - // complete. This will avoid the link down (pairing is complete) and an - // immediate re-connection for service discovery. - // Some devices do not do auto advertising when link is dropped, thus fail - // the second connection and service discovery. - if ((fixed_cid == L2CAP_ATT_CID ) && !p_lcb->ccb_queue.p_first_ccb) - p_lcb->idle_timeout = 0; + // Retain the link for a few more seconds after SMP pairing is done, since + // the Android platform always does service discovery after pairing is + // complete. This will avoid the link down (pairing is complete) and an + // immediate re-connection for service discovery. + // Some devices do not do auto advertising when link is dropped, thus fail + // the second connection and service discovery. + if ((fixed_cid == L2CAP_ATT_CID) && !p_lcb->ccb_queue.p_first_ccb) + p_lcb->idle_timeout = 0; - l2cu_release_ccb (p_ccb); + l2cu_release_ccb(p_ccb); - return (true); + return (true); } /******************************************************************************* @@ -1990,32 +1903,37 @@ bool L2CA_RemoveFixedChnl (uint16_t fixed_cid, BD_ADDR rem_bda) * Returns true if command succeeded, false if failed * ******************************************************************************/ -bool L2CA_SetFixedChannelTout (BD_ADDR rem_bda, uint16_t fixed_cid, uint16_t idle_tout) -{ - tL2C_LCB *p_lcb; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) - transport = BT_TRANSPORT_LE; - - /* Is a fixed channel connected to the remote BDA ?*/ - p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, transport); - if ( ((p_lcb) == NULL) || (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) ) - { - L2CAP_TRACE_WARNING ("L2CA_SetFixedChannelTout() CID: 0x%04x BDA: %08x%04x not connected", fixed_cid, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); - return (false); - } +bool L2CA_SetFixedChannelTout(BD_ADDR rem_bda, uint16_t fixed_cid, + uint16_t idle_tout) { + tL2C_LCB* p_lcb; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + + if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID) + transport = BT_TRANSPORT_LE; + + /* Is a fixed channel connected to the remote BDA ?*/ + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport); + if (((p_lcb) == NULL) || + (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL])) { + L2CAP_TRACE_WARNING( + "L2CA_SetFixedChannelTout() CID: 0x%04x BDA: %08x%04x not connected", + fixed_cid, (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return (false); + } - p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->fixed_chnl_idle_tout = idle_tout; + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] + ->fixed_chnl_idle_tout = idle_tout; - if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && !p_lcb->ccb_queue.p_first_ccb) - { - /* If there are no dynamic CCBs, (re)start the idle timer in case we changed it */ - l2cu_no_dynamic_ccbs (p_lcb); - } + if (p_lcb->in_use && p_lcb->link_state == LST_CONNECTED && + !p_lcb->ccb_queue.p_first_ccb) { + /* If there are no dynamic CCBs, (re)start the idle timer in case we changed + * it */ + l2cu_no_dynamic_ccbs(p_lcb); + } - return true; + return true; } #endif /* #if (L2CAP_NUM_FIXED_CHNLS > 0) */ @@ -2033,45 +1951,38 @@ bool L2CA_SetFixedChannelTout (BD_ADDR rem_bda, uint16_t fixed_cid, uint16_t * Returns true if successful * ******************************************************************************/ -bool L2CA_GetCurrentConfig (uint16_t lcid, - tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits, - tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits) -{ - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_GetCurrentConfig() CID: 0x%04x", lcid); - - p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); - - if (p_ccb) - { - *pp_our_cfg = &(p_ccb->our_cfg); - - /* convert valid config items into bitmap */ - *p_our_cfg_bits = 0; - if (p_ccb->our_cfg.mtu_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_MTU; - if (p_ccb->our_cfg.qos_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_QOS; - if (p_ccb->our_cfg.flush_to_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FLUSH_TO; - if (p_ccb->our_cfg.fcr_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCR; - if (p_ccb->our_cfg.fcs_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCS; - if (p_ccb->our_cfg.ext_flow_spec_present) - *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC; - - *pp_peer_cfg = &(p_ccb->peer_cfg); - *p_peer_cfg_bits = p_ccb->peer_cfg_bits; - - return true; - } - else - { - L2CAP_TRACE_ERROR ("No CCB for CID:0x%04x", lcid); - return false; - } +bool L2CA_GetCurrentConfig(uint16_t lcid, tL2CAP_CFG_INFO** pp_our_cfg, + tL2CAP_CH_CFG_BITS* p_our_cfg_bits, + tL2CAP_CFG_INFO** pp_peer_cfg, + tL2CAP_CH_CFG_BITS* p_peer_cfg_bits) { + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API("L2CA_GetCurrentConfig() CID: 0x%04x", lcid); + + p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); + + if (p_ccb) { + *pp_our_cfg = &(p_ccb->our_cfg); + + /* convert valid config items into bitmap */ + *p_our_cfg_bits = 0; + if (p_ccb->our_cfg.mtu_present) *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_MTU; + if (p_ccb->our_cfg.qos_present) *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_QOS; + if (p_ccb->our_cfg.flush_to_present) + *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FLUSH_TO; + if (p_ccb->our_cfg.fcr_present) *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCR; + if (p_ccb->our_cfg.fcs_present) *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_FCS; + if (p_ccb->our_cfg.ext_flow_spec_present) + *p_our_cfg_bits |= L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC; + + *pp_peer_cfg = &(p_ccb->peer_cfg); + *p_peer_cfg_bits = p_ccb->peer_cfg_bits; + + return true; + } else { + L2CAP_TRACE_ERROR("No CCB for CID:0x%04x", lcid); + return false; + } } /******************************************************************************* @@ -2084,25 +1995,24 @@ bool L2CA_GetCurrentConfig (uint16_t lcid, * Returns true if successful * ******************************************************************************/ -bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t *mtu, uint16_t *rcid, uint16_t *handle) -{ - tL2C_CCB *p_ccb = l2cu_find_ccb_by_cid(NULL, lcid);; +bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t* mtu, uint16_t* rcid, + uint16_t* handle) { + tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); + ; - L2CAP_TRACE_API ("%s CID: 0x%04x", __func__, lcid); + L2CAP_TRACE_API("%s CID: 0x%04x", __func__, lcid); - if (p_ccb) - { - *mtu = L2CAP_MTU_SIZE; - if (p_ccb->our_cfg.mtu_present) - *mtu = p_ccb->our_cfg.mtu; + if (p_ccb) { + *mtu = L2CAP_MTU_SIZE; + if (p_ccb->our_cfg.mtu_present) *mtu = p_ccb->our_cfg.mtu; - *rcid = p_ccb->remote_cid; - *handle= p_ccb->p_lcb->handle; - return true; - } + *rcid = p_ccb->remote_cid; + *handle = p_ccb->p_lcb->handle; + return true; + } - L2CAP_TRACE_ERROR ("%s No CCB for CID:0x%04x", __func__, lcid); - return false; + L2CAP_TRACE_ERROR("%s No CCB for CID:0x%04x", __func__, lcid); + return false; } /******************************************************************************* @@ -2117,20 +2027,18 @@ bool L2CA_GetConnectionConfig(uint16_t lcid, uint16_t *mtu, uint16_t *rcid, u * Returns true if registered OK, else false * ******************************************************************************/ -bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda) -{ - tL2C_LCB *p_lcb; +bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB* p_cb, BD_ADDR p_bda) { + tL2C_LCB* p_lcb; - /* Find the link that is associated with this remote bdaddr */ - p_lcb = l2cu_find_lcb_by_bd_addr (p_bda, BT_TRANSPORT_BR_EDR); + /* Find the link that is associated with this remote bdaddr */ + p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, BT_TRANSPORT_BR_EDR); - /* If no link for this handle, nothing to do. */ - if (!p_lcb) - return false; + /* If no link for this handle, nothing to do. */ + if (!p_lcb) return false; - p_lcb->p_nocp_cb = p_cb; + p_lcb->p_nocp_cb = p_cb; - return true; + return true; } /******************************************************************************* @@ -2145,10 +2053,9 @@ bool L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda) * L2CAP_DW_FAILED, if error * ******************************************************************************/ -uint8_t L2CA_DataWrite (uint16_t cid, BT_HDR *p_data) -{ - L2CAP_TRACE_API ("L2CA_DataWrite() CID: 0x%04x Len: %d", cid, p_data->len); - return l2c_data_write (cid, p_data, L2CAP_FLUSHABLE_CH_BASED); +uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) { + L2CAP_TRACE_API("L2CA_DataWrite() CID: 0x%04x Len: %d", cid, p_data->len); + return l2c_data_write(cid, p_data, L2CAP_FLUSHABLE_CH_BASED); } /******************************************************************************* @@ -2161,27 +2068,27 @@ uint8_t L2CA_DataWrite (uint16_t cid, BT_HDR *p_data) * Returns true if CID found, else false * ******************************************************************************/ -bool L2CA_SetChnlFlushability (uint16_t cid, bool is_flushable) -{ +bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable) { #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - tL2C_CCB *p_ccb; + tL2C_CCB* p_ccb; - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_SetChnlFlushability, CID: %d", cid); - return (false); - } + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_SetChnlFlushability, CID: %d", + cid); + return (false); + } - p_ccb->is_flushable = is_flushable; + p_ccb->is_flushable = is_flushable; - L2CAP_TRACE_API ("L2CA_SetChnlFlushability() CID: 0x%04x is_flushable: %d", cid, is_flushable); + L2CAP_TRACE_API("L2CA_SetChnlFlushability() CID: 0x%04x is_flushable: %d", + cid, is_flushable); #endif - return (true); + return (true); } /******************************************************************************* @@ -2200,11 +2107,10 @@ bool L2CA_SetChnlFlushability (uint16_t cid, bool is_flushable) * L2CAP_DW_FAILED, if error * ******************************************************************************/ -uint8_t L2CA_DataWriteEx (uint16_t cid, BT_HDR *p_data, uint16_t flags) -{ - L2CAP_TRACE_API ("L2CA_DataWriteEx() CID: 0x%04x Len: %d Flags:0x%04X", - cid, p_data->len, flags); - return l2c_data_write (cid, p_data, flags); +uint8_t L2CA_DataWriteEx(uint16_t cid, BT_HDR* p_data, uint16_t flags) { + L2CAP_TRACE_API("L2CA_DataWriteEx() CID: 0x%04x Len: %d Flags:0x%04X", cid, + p_data->len, flags); + return l2c_data_write(cid, p_data, flags); } /******************************************************************************* @@ -2221,103 +2127,92 @@ uint8_t L2CA_DataWriteEx (uint16_t cid, BT_HDR *p_data, uint16_t flags) * Returns Number of buffers left queued for that CID * ******************************************************************************/ -uint16_t L2CA_FlushChannel (uint16_t lcid, uint16_t num_to_flush) -{ - tL2C_CCB *p_ccb; - tL2C_LCB *p_lcb; - uint16_t num_left = 0, - num_flushed1 = 0, - num_flushed2 = 0; - - p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); - - if ( !p_ccb || ((p_lcb = p_ccb->p_lcb) == NULL) ) - { - L2CAP_TRACE_WARNING ("L2CA_FlushChannel() abnormally returning 0 CID: 0x%04x", lcid); - return (0); - } +uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush) { + tL2C_CCB* p_ccb; + tL2C_LCB* p_lcb; + uint16_t num_left = 0, num_flushed1 = 0, num_flushed2 = 0; - if (num_to_flush != L2CAP_FLUSH_CHANS_GET) - { - L2CAP_TRACE_API ("L2CA_FlushChannel (FLUSH) CID: 0x%04x NumToFlush: %d QC: %u pFirst: 0x%08x", - lcid, num_to_flush, - fixed_queue_length(p_ccb->xmit_hold_q), - fixed_queue_try_peek_first(p_ccb->xmit_hold_q)); - } - else - { - L2CAP_TRACE_API ("L2CA_FlushChannel (QUERY) CID: 0x%04x", lcid); - } + p_ccb = l2cu_find_ccb_by_cid(NULL, lcid); + + if (!p_ccb || ((p_lcb = p_ccb->p_lcb) == NULL)) { + L2CAP_TRACE_WARNING( + "L2CA_FlushChannel() abnormally returning 0 CID: 0x%04x", lcid); + return (0); + } + + if (num_to_flush != L2CAP_FLUSH_CHANS_GET) { + L2CAP_TRACE_API( + "L2CA_FlushChannel (FLUSH) CID: 0x%04x NumToFlush: %d QC: %u " + "pFirst: 0x%08x", + lcid, num_to_flush, fixed_queue_length(p_ccb->xmit_hold_q), + fixed_queue_try_peek_first(p_ccb->xmit_hold_q)); + } else { + L2CAP_TRACE_API("L2CA_FlushChannel (QUERY) CID: 0x%04x", lcid); + } - /* Cannot flush eRTM buffers once they have a sequence number */ - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) - { + /* Cannot flush eRTM buffers once they have a sequence number */ + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) { #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - if (num_to_flush != L2CAP_FLUSH_CHANS_GET) - { - /* If the controller supports enhanced flush, flush the data queued at the controller */ - if ( (HCI_NON_FLUSHABLE_PB_SUPPORTED(BTM_ReadLocalFeatures ())) - && (BTM_GetNumScoLinks() == 0) ) - { - if ( l2cb.is_flush_active == false ) - { - l2cb.is_flush_active = true; - - /* The only packet type defined - 0 - Automatically-Flushable Only */ - btsnd_hcic_enhanced_flush (p_lcb->handle, 0); - } - } + if (num_to_flush != L2CAP_FLUSH_CHANS_GET) { + /* If the controller supports enhanced flush, flush the data queued at the + * controller */ + if ((HCI_NON_FLUSHABLE_PB_SUPPORTED(BTM_ReadLocalFeatures())) && + (BTM_GetNumScoLinks() == 0)) { + if (l2cb.is_flush_active == false) { + l2cb.is_flush_active = true; + + /* The only packet type defined - 0 - Automatically-Flushable Only */ + btsnd_hcic_enhanced_flush(p_lcb->handle, 0); } + } + } #endif - // Iterate though list and flush the amount requested from - // the transmit data queue that satisfy the layer and event conditions. - for (const list_node_t *node = list_begin(p_lcb->link_xmit_data_q); - (num_to_flush > 0) && node != list_end(p_lcb->link_xmit_data_q);) { - BT_HDR *p_buf = (BT_HDR *)list_node(node); - node = list_next(node); - if ((p_buf->layer_specific == 0) && (p_buf->event == lcid)) { - num_to_flush--; - num_flushed1++; - - list_remove(p_lcb->link_xmit_data_q, p_buf); - osi_free(p_buf); - } - } - } + // Iterate though list and flush the amount requested from + // the transmit data queue that satisfy the layer and event conditions. + for (const list_node_t* node = list_begin(p_lcb->link_xmit_data_q); + (num_to_flush > 0) && node != list_end(p_lcb->link_xmit_data_q);) { + BT_HDR* p_buf = (BT_HDR*)list_node(node); + node = list_next(node); + if ((p_buf->layer_specific == 0) && (p_buf->event == lcid)) { + num_to_flush--; + num_flushed1++; - /* If needed, flush buffers in the CCB xmit hold queue */ - while ( (num_to_flush != 0) && (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) - { - BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + list_remove(p_lcb->link_xmit_data_q, p_buf); osi_free(p_buf); - num_to_flush--; - num_flushed2++; + } } + } - /* If app needs to track all packets, call him */ - if ( (p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && (num_flushed2) ) - (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, num_flushed2); + /* If needed, flush buffers in the CCB xmit hold queue */ + while ((num_to_flush != 0) && (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) { + BT_HDR* p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + osi_free(p_buf); + num_to_flush--; + num_flushed2++; + } - /* Now count how many are left */ - for (const list_node_t *node = list_begin(p_lcb->link_xmit_data_q); - node != list_end(p_lcb->link_xmit_data_q); - node = list_next(node)) { + /* If app needs to track all packets, call him */ + if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && + (num_flushed2)) + (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, num_flushed2); - BT_HDR *p_buf = (BT_HDR *)list_node(node); - if (p_buf->event == lcid) - num_left++; - } + /* Now count how many are left */ + for (const list_node_t* node = list_begin(p_lcb->link_xmit_data_q); + node != list_end(p_lcb->link_xmit_data_q); node = list_next(node)) { + BT_HDR* p_buf = (BT_HDR*)list_node(node); + if (p_buf->event == lcid) num_left++; + } - /* Add in the number in the CCB xmit queue */ - num_left += fixed_queue_length(p_ccb->xmit_hold_q); + /* Add in the number in the CCB xmit queue */ + num_left += fixed_queue_length(p_ccb->xmit_hold_q); - /* Return the local number of buffers left for the CID */ - L2CAP_TRACE_DEBUG ("L2CA_FlushChannel() flushed: %u + %u, num_left: %u", num_flushed1, num_flushed2, num_left); + /* Return the local number of buffers left for the CID */ + L2CAP_TRACE_DEBUG("L2CA_FlushChannel() flushed: %u + %u, num_left: %u", + num_flushed1, num_flushed2, num_left); - /* If we were congested, and now we are not, tell the app */ - l2cu_check_channel_congestion (p_ccb); + /* If we were congested, and now we are not, tell the app */ + l2cu_check_channel_congestion(p_ccb); - return (num_left); + return (num_left); } - diff --git a/stack/l2cap/l2c_ble.cc b/stack/l2cap/l2c_ble.cc index 50d3f6eb3..16573b28e 100644 --- a/stack/l2cap/l2c_ble.cc +++ b/stack/l2cap/l2c_ble.cc @@ -25,18 +25,18 @@ #include #include "bt_target.h" #include "bt_utils.h" -#include "l2cdefs.h" -#include "l2c_int.h" -#include "btu.h" #include "btm_int.h" -#include "hcimsgs.h" +#include "btu.h" #include "device/include/controller.h" -#include "stack_config.h" +#include "hcimsgs.h" +#include "l2c_int.h" +#include "l2cdefs.h" #include "osi/include/osi.h" +#include "stack_config.h" -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; -static void l2cble_start_conn_update (tL2C_LCB *p_lcb); +static void l2cble_start_conn_update(tL2C_LCB* p_lcb); /******************************************************************************* * @@ -49,41 +49,43 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb); * Return value: true if connection was cancelled * ******************************************************************************/ -bool L2CA_CancelBleConnectReq (BD_ADDR rem_bda) -{ - tL2C_LCB *p_lcb; - - /* There can be only one BLE connection request outstanding at a time */ - if (btm_ble_get_conn_st() == BLE_CONN_IDLE) - { - L2CAP_TRACE_WARNING ("%s - no connection pending", __func__); - return(false); - } - - if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) - { - L2CAP_TRACE_WARNING ("%s - different BDA Connecting: %08x%04x Cancel: %08x%04x", __func__, - (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], - (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); - btm_ble_dequeue_direct_conn_req(rem_bda); - return(false); - } - - btsnd_hcic_ble_create_conn_cancel(); - - p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); - /* Do not remove lcb if an LE link is already up as a peripheral */ - if (p_lcb != NULL && - !(p_lcb->link_role == HCI_ROLE_SLAVE && btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE) != NULL)) - { - p_lcb->disc_reason = L2CAP_CONN_CANCEL; - l2cu_release_lcb (p_lcb); - } - /* update state to be cancel, wait for connection cancel complete */ - btm_ble_set_conn_st (BLE_CONN_CANCEL); - - return(true); +bool L2CA_CancelBleConnectReq(BD_ADDR rem_bda) { + tL2C_LCB* p_lcb; + + /* There can be only one BLE connection request outstanding at a time */ + if (btm_ble_get_conn_st() == BLE_CONN_IDLE) { + L2CAP_TRACE_WARNING("%s - no connection pending", __func__); + return (false); + } + + if (memcmp(rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) { + L2CAP_TRACE_WARNING( + "%s - different BDA Connecting: %08x%04x Cancel: %08x%04x", __func__, + (l2cb.ble_connecting_bda[0] << 24) + + (l2cb.ble_connecting_bda[1] << 16) + + (l2cb.ble_connecting_bda[2] << 8) + l2cb.ble_connecting_bda[3], + (l2cb.ble_connecting_bda[4] << 8) + l2cb.ble_connecting_bda[5], + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + btm_ble_dequeue_direct_conn_req(rem_bda); + return (false); + } + + btsnd_hcic_ble_create_conn_cancel(); + + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); + /* Do not remove lcb if an LE link is already up as a peripheral */ + if (p_lcb != NULL && + !(p_lcb->link_role == HCI_ROLE_SLAVE && + btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE) != NULL)) { + p_lcb->disc_reason = L2CAP_CONN_CANCEL; + l2cu_release_lcb(p_lcb); + } + /* update state to be cancel, wait for connection cancel complete */ + btm_ble_set_conn_st(BLE_CONN_CANCEL); + + return (true); } /******************************************************************************* @@ -97,44 +99,43 @@ bool L2CA_CancelBleConnectReq (BD_ADDR rem_bda) * Return value: true if update started * ******************************************************************************/ -bool L2CA_UpdateBleConnParams (BD_ADDR rem_bda, uint16_t min_int, uint16_t max_int, - uint16_t latency, uint16_t timeout) -{ - tL2C_LCB *p_lcb; - tACL_CONN *p_acl_cb = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE); - - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); - - /* If we don't have one, create one and accept the connection. */ - if (!p_lcb || !p_acl_cb) - { - L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x", - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - return(false); - } - - if (p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE", - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - return(false); - } - - p_lcb->min_interval = min_int; - p_lcb->max_interval = max_int; - p_lcb->latency = latency; - p_lcb->timeout = timeout; - p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; - - l2cble_start_conn_update(p_lcb); - - return(true); +bool L2CA_UpdateBleConnParams(BD_ADDR rem_bda, uint16_t min_int, + uint16_t max_int, uint16_t latency, + uint16_t timeout) { + tL2C_LCB* p_lcb; + tACL_CONN* p_acl_cb = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE); + + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); + + /* If we don't have one, create one and accept the connection. */ + if (!p_lcb || !p_acl_cb) { + L2CAP_TRACE_WARNING("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x", + (rem_bda[0] << 24) + (rem_bda[1] << 16) + + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return (false); + } + + if (p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE", + (rem_bda[0] << 24) + (rem_bda[1] << 16) + + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return (false); + } + + p_lcb->min_interval = min_int; + p_lcb->max_interval = max_int; + p_lcb->latency = latency; + p_lcb->timeout = timeout; + p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; + + l2cble_start_conn_update(p_lcb); + + return (true); } - /******************************************************************************* * * Function L2CA_EnableUpdateBleConnParams @@ -146,47 +147,47 @@ bool L2CA_UpdateBleConnParams (BD_ADDR rem_bda, uint16_t min_int, uint16_t ma * Return value: true if update started * ******************************************************************************/ -bool L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, bool enable) -{ - if (stack_config_get_interface()->get_pts_conn_updates_disabled()) - return false; - - tL2C_LCB *p_lcb; - - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); - - if (!p_lcb) - { - L2CAP_TRACE_WARNING ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x", - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - return (false); - } - - L2CAP_TRACE_API ("%s - BD_ADDR %08x%04x enable %d current upd state 0x%02x",__func__, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5], enable, p_lcb->conn_update_mask); - - if (p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("%s - BD_ADDR %08x%04x not LE (link role %d)", __func__, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5], p_lcb->link_role); - return (false); - } - - if (enable) - p_lcb->conn_update_mask &= ~L2C_BLE_CONN_UPDATE_DISABLE; - else - p_lcb->conn_update_mask |= L2C_BLE_CONN_UPDATE_DISABLE; - - l2cble_start_conn_update(p_lcb); - - return (true); +bool L2CA_EnableUpdateBleConnParams(BD_ADDR rem_bda, bool enable) { + if (stack_config_get_interface()->get_pts_conn_updates_disabled()) + return false; + + tL2C_LCB* p_lcb; + + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); + + if (!p_lcb) { + L2CAP_TRACE_WARNING( + "L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x", + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + return (false); + } + + L2CAP_TRACE_API( + "%s - BD_ADDR %08x%04x enable %d current upd state 0x%02x", __func__, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5], enable, p_lcb->conn_update_mask); + + if (p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("%s - BD_ADDR %08x%04x not LE (link role %d)", __func__, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5], p_lcb->link_role); + return (false); + } + + if (enable) + p_lcb->conn_update_mask &= ~L2C_BLE_CONN_UPDATE_DISABLE; + else + p_lcb->conn_update_mask |= L2C_BLE_CONN_UPDATE_DISABLE; + + l2cble_start_conn_update(p_lcb); + + return (true); } - /******************************************************************************* * * Function L2CA_GetBleConnRole @@ -196,17 +197,15 @@ bool L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, bool enable) * Returns link role. * ******************************************************************************/ -uint8_t L2CA_GetBleConnRole (BD_ADDR bd_addr) -{ - uint8_t role = HCI_ROLE_UNKNOWN; +uint8_t L2CA_GetBleConnRole(BD_ADDR bd_addr) { + uint8_t role = HCI_ROLE_UNKNOWN; - tL2C_LCB *p_lcb; + tL2C_LCB* p_lcb; - p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); - if (p_lcb != NULL) - role = p_lcb->link_role; + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); + if (p_lcb != NULL) role = p_lcb->link_role; - return role; + return role; } /******************************************************************************* * @@ -217,18 +216,16 @@ uint8_t L2CA_GetBleConnRole (BD_ADDR bd_addr) * Returns disconnect reason * ******************************************************************************/ -uint16_t L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport) -{ - tL2C_LCB *p_lcb; - uint16_t reason = 0; +uint16_t L2CA_GetDisconnectReason(BD_ADDR remote_bda, tBT_TRANSPORT transport) { + tL2C_LCB* p_lcb; + uint16_t reason = 0; - p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, transport); - if (p_lcb != NULL) - reason = p_lcb->disc_reason; + p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, transport); + if (p_lcb != NULL) reason = p_lcb->disc_reason; - L2CAP_TRACE_DEBUG ("L2CA_GetDisconnectReason=%d ",reason); + L2CAP_TRACE_DEBUG("L2CA_GetDisconnectReason=%d ", reason); - return reason; + return reason; } /******************************************************************************* @@ -240,29 +237,27 @@ uint16_t L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport) * Returns none * ******************************************************************************/ -void l2cble_notify_le_connection (BD_ADDR bda) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); - tACL_CONN *p_acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE) ; - tL2C_CCB *p_ccb; - - if (p_lcb != NULL && p_acl != NULL && p_lcb->link_state != LST_CONNECTED) - { - /* update link status */ - btm_establish_continue(p_acl); - /* update l2cap link status and send callback */ - p_lcb->link_state = LST_CONNECTED; - l2cu_process_fixed_chnl_resp (p_lcb); - } - - if (p_lcb != NULL) { - /* For all channels, send the event through their FSMs */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - if (p_ccb->chnl_state == CST_CLOSED) - l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM, NULL); - } +void l2cble_notify_le_connection(BD_ADDR bda) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE); + tACL_CONN* p_acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE); + tL2C_CCB* p_ccb; + + if (p_lcb != NULL && p_acl != NULL && p_lcb->link_state != LST_CONNECTED) { + /* update link status */ + btm_establish_continue(p_acl); + /* update l2cap link status and send callback */ + p_lcb->link_state = LST_CONNECTED; + l2cu_process_fixed_chnl_resp(p_lcb); + } + + if (p_lcb != NULL) { + /* For all channels, send the event through their FSMs */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + if (p_ccb->chnl_state == CST_CLOSED) + l2c_csm_execute(p_ccb, L2CEVT_LP_CONNECT_CFM, NULL); } + } } /******************************************************************************* @@ -275,73 +270,75 @@ void l2cble_notify_le_connection (BD_ADDR bda) * Returns void * ******************************************************************************/ -void l2cble_scanner_conn_comp (uint16_t handle, BD_ADDR bda, tBLE_ADDR_TYPE type, - uint16_t conn_interval, uint16_t conn_latency, uint16_t conn_timeout) -{ - tL2C_LCB *p_lcb; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda); - - L2CAP_TRACE_DEBUG ("l2cble_scanner_conn_comp: HANDLE=%d addr_type=%d conn_interval=%d slave_latency=%d supervision_tout=%d", - handle, type, conn_interval, conn_latency, conn_timeout); - - l2cb.is_ble_connecting = false; - - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); - - /* If we don't have one, create one. this is auto connection complete. */ - if (!p_lcb) - { - p_lcb = l2cu_allocate_lcb (bda, false, BT_TRANSPORT_LE); - if (!p_lcb) - { - btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); - L2CAP_TRACE_ERROR ("l2cble_scanner_conn_comp - failed to allocate LCB"); - return; - } - else - { - if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); - L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB"); - return ; - } - } - } - else if (p_lcb->link_state != LST_CONNECTING) - { - L2CAP_TRACE_ERROR ("L2CAP got BLE scanner conn_comp in bad state: %d", p_lcb->link_state); +void l2cble_scanner_conn_comp(uint16_t handle, BD_ADDR bda, tBLE_ADDR_TYPE type, + uint16_t conn_interval, uint16_t conn_latency, + uint16_t conn_timeout) { + tL2C_LCB* p_lcb; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda); + + L2CAP_TRACE_DEBUG( + "l2cble_scanner_conn_comp: HANDLE=%d addr_type=%d conn_interval=%d " + "slave_latency=%d supervision_tout=%d", + handle, type, conn_interval, conn_latency, conn_timeout); + + l2cb.is_ble_connecting = false; + + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE); + + /* If we don't have one, create one. this is auto connection complete. */ + if (!p_lcb) { + p_lcb = l2cu_allocate_lcb(bda, false, BT_TRANSPORT_LE); + if (!p_lcb) { + btm_sec_disconnect(handle, HCI_ERR_NO_CONNECTION); + L2CAP_TRACE_ERROR("l2cble_scanner_conn_comp - failed to allocate LCB"); + return; + } else { + if (!l2cu_initialize_fixed_ccb( + p_lcb, L2CAP_ATT_CID, + &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + btm_sec_disconnect(handle, HCI_ERR_NO_CONNECTION); + L2CAP_TRACE_WARNING("l2cble_scanner_conn_comp - LCB but no CCB"); return; + } } - alarm_cancel(p_lcb->l2c_lcb_timer); + } else if (p_lcb->link_state != LST_CONNECTING) { + L2CAP_TRACE_ERROR("L2CAP got BLE scanner conn_comp in bad state: %d", + p_lcb->link_state); + return; + } + alarm_cancel(p_lcb->l2c_lcb_timer); - /* Save the handle */ - p_lcb->handle = handle; + /* Save the handle */ + p_lcb->handle = handle; - /* Connected OK. Change state to connected, we were scanning so we are master */ - p_lcb->link_role = HCI_ROLE_MASTER; - p_lcb->transport = BT_TRANSPORT_LE; + /* Connected OK. Change state to connected, we were scanning so we are master + */ + p_lcb->link_role = HCI_ROLE_MASTER; + p_lcb->transport = BT_TRANSPORT_LE; - /* update link parameter, set slave link as non-spec default upon link up */ - p_lcb->min_interval = p_lcb->max_interval = conn_interval; - p_lcb->timeout = conn_timeout; - p_lcb->latency = conn_latency; - p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; + /* update link parameter, set slave link as non-spec default upon link up */ + p_lcb->min_interval = p_lcb->max_interval = conn_interval; + p_lcb->timeout = conn_timeout; + p_lcb->latency = conn_latency; + p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; - /* Tell BTM Acl management about the link */ - btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE); + /* Tell BTM Acl management about the link */ + btm_acl_created(bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, + BT_TRANSPORT_LE); - p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; + p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | + L2CAP_FIXED_CHNL_BLE_SIG_BIT | + L2CAP_FIXED_CHNL_SMP_BIT; - btm_ble_set_conn_st(BLE_CONN_IDLE); + btm_ble_set_conn_st(BLE_CONN_IDLE); #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); + btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); #endif } - /******************************************************************************* * * Function l2cble_advertiser_conn_comp @@ -353,72 +350,75 @@ void l2cble_scanner_conn_comp (uint16_t handle, BD_ADDR bda, tBLE_ADDR_TYPE type * Returns void * ******************************************************************************/ -void l2cble_advertiser_conn_comp (uint16_t handle, BD_ADDR bda, UNUSED_ATTR tBLE_ADDR_TYPE type, - UNUSED_ATTR uint16_t conn_interval, UNUSED_ATTR uint16_t conn_latency, - UNUSED_ATTR uint16_t conn_timeout) -{ - tL2C_LCB *p_lcb; - tBTM_SEC_DEV_REC *p_dev_rec; - - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); - - /* If we don't have one, create one and accept the connection. */ - if (!p_lcb) - { - p_lcb = l2cu_allocate_lcb (bda, false, BT_TRANSPORT_LE); - if (!p_lcb) - { - btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); - L2CAP_TRACE_ERROR ("l2cble_advertiser_conn_comp - failed to allocate LCB"); - return; - } - else - { - if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); - L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB"); - return ; - } - } +void l2cble_advertiser_conn_comp(uint16_t handle, BD_ADDR bda, + UNUSED_ATTR tBLE_ADDR_TYPE type, + UNUSED_ATTR uint16_t conn_interval, + UNUSED_ATTR uint16_t conn_latency, + UNUSED_ATTR uint16_t conn_timeout) { + tL2C_LCB* p_lcb; + tBTM_SEC_DEV_REC* p_dev_rec; + + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE); + + /* If we don't have one, create one and accept the connection. */ + if (!p_lcb) { + p_lcb = l2cu_allocate_lcb(bda, false, BT_TRANSPORT_LE); + if (!p_lcb) { + btm_sec_disconnect(handle, HCI_ERR_NO_CONNECTION); + L2CAP_TRACE_ERROR("l2cble_advertiser_conn_comp - failed to allocate LCB"); + return; + } else { + if (!l2cu_initialize_fixed_ccb( + p_lcb, L2CAP_ATT_CID, + &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + btm_sec_disconnect(handle, HCI_ERR_NO_CONNECTION); + L2CAP_TRACE_WARNING("l2cble_scanner_conn_comp - LCB but no CCB"); + return; + } } + } - /* Save the handle */ - p_lcb->handle = handle; + /* Save the handle */ + p_lcb->handle = handle; - /* Connected OK. Change state to connected, we were advertising, so we are slave */ - p_lcb->link_role = HCI_ROLE_SLAVE; - p_lcb->transport = BT_TRANSPORT_LE; + /* Connected OK. Change state to connected, we were advertising, so we are + * slave */ + p_lcb->link_role = HCI_ROLE_SLAVE; + p_lcb->transport = BT_TRANSPORT_LE; - /* update link parameter, set slave link as non-spec default upon link up */ - p_lcb->min_interval = p_lcb->max_interval = conn_interval; - p_lcb->timeout = conn_timeout; - p_lcb->latency = conn_latency; - p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; + /* update link parameter, set slave link as non-spec default upon link up */ + p_lcb->min_interval = p_lcb->max_interval = conn_interval; + p_lcb->timeout = conn_timeout; + p_lcb->latency = conn_latency; + p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; - /* Tell BTM Acl management about the link */ - p_dev_rec = btm_find_or_alloc_dev (bda); + /* Tell BTM Acl management about the link */ + p_dev_rec = btm_find_or_alloc_dev(bda); - btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE); + btm_acl_created(bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, + BT_TRANSPORT_LE); #if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); #endif - p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; - - if (!HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array)) - { - p_lcb->link_state = LST_CONNECTED; - l2cu_process_fixed_chnl_resp (p_lcb); - } - - /* when adv and initiating are both active, cancel the direct connection */ - if (l2cb.is_ble_connecting && memcmp(bda, l2cb.ble_connecting_bda, BD_ADDR_LEN) == 0) - { - L2CA_CancelBleConnectReq(bda); - } + p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | + L2CAP_FIXED_CHNL_BLE_SIG_BIT | + L2CAP_FIXED_CHNL_SMP_BIT; + + if (!HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED( + controller_get_interface()->get_features_ble()->as_array)) { + p_lcb->link_state = LST_CONNECTED; + l2cu_process_fixed_chnl_resp(p_lcb); + } + + /* when adv and initiating are both active, cancel the direct connection */ + if (l2cb.is_ble_connecting && + memcmp(bda, l2cb.ble_connecting_bda, BD_ADDR_LEN) == 0) { + L2CA_CancelBleConnectReq(bda); + } } /******************************************************************************* @@ -431,19 +431,18 @@ void l2cble_advertiser_conn_comp (uint16_t handle, BD_ADDR bda, UNUSED_ATTR tBLE * Returns void * ******************************************************************************/ -void l2cble_conn_comp(uint16_t handle, uint8_t role, BD_ADDR bda, tBLE_ADDR_TYPE type, - uint16_t conn_interval, uint16_t conn_latency, uint16_t conn_timeout) -{ - btm_ble_update_link_topology_mask(role, true); - - if (role == HCI_ROLE_MASTER) - { - l2cble_scanner_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); - } - else - { - l2cble_advertiser_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); - } +void l2cble_conn_comp(uint16_t handle, uint8_t role, BD_ADDR bda, + tBLE_ADDR_TYPE type, uint16_t conn_interval, + uint16_t conn_latency, uint16_t conn_timeout) { + btm_ble_update_link_topology_mask(role, true); + + if (role == HCI_ROLE_MASTER) { + l2cble_scanner_conn_comp(handle, bda, type, conn_interval, conn_latency, + conn_timeout); + } else { + l2cble_advertiser_conn_comp(handle, bda, type, conn_interval, conn_latency, + conn_timeout); + } } /******************************************************************************* @@ -458,78 +457,72 @@ void l2cble_conn_comp(uint16_t handle, uint8_t role, BD_ADDR bda, tBLE_ADDR_TYPE * Return value: none * ******************************************************************************/ -static void l2cble_start_conn_update (tL2C_LCB *p_lcb) -{ - uint16_t min_conn_int, max_conn_int, slave_latency, supervision_tout; - tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); - - // TODO(armansito): The return value of this call wasn't being used but the - // logic of this function might be depending on its side effects. We should - // verify if this call is needed at all and remove it otherwise. - btm_find_or_alloc_dev(p_lcb->remote_bd_addr); - - if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) return; - - if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) - { - /* application requests to disable parameters update. - If parameters are already updated, lets set them - up to what has been requested during connection establishement */ - if (p_lcb->conn_update_mask & L2C_BLE_NOT_DEFAULT_PARAM && - /* current connection interval is greater than default min */ - p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) - { - /* use 7.5 ms as fast connection parameter, 0 slave latency */ - min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN; - slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; - supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF; - - /* if both side 4.1, or we are master device, send HCI command */ - if (p_lcb->link_role == HCI_ROLE_MASTER +static void l2cble_start_conn_update(tL2C_LCB* p_lcb) { + uint16_t min_conn_int, max_conn_int, slave_latency, supervision_tout; + tACL_CONN* p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); + + // TODO(armansito): The return value of this call wasn't being used but the + // logic of this function might be depending on its side effects. We should + // verify if this call is needed at all and remove it otherwise. + btm_find_or_alloc_dev(p_lcb->remote_bd_addr); + + if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) return; + + if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) { + /* application requests to disable parameters update. + If parameters are already updated, lets set them + up to what has been requested during connection establishement */ + if (p_lcb->conn_update_mask & L2C_BLE_NOT_DEFAULT_PARAM && + /* current connection interval is greater than default min */ + p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) { + /* use 7.5 ms as fast connection parameter, 0 slave latency */ + min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN; + slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; + supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF; + + /* if both side 4.1, or we are master device, send HCI command */ + if (p_lcb->link_role == HCI_ROLE_MASTER #if (BLE_LLT_INCLUDED == TRUE) - || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) && - HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) + || (HCI_LE_CONN_PARAM_REQ_SUPPORTED( + controller_get_interface()->get_features_ble()->as_array) && + HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) #endif - ) - { - btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, min_conn_int, max_conn_int, - slave_latency, supervision_tout, 0, 0); - p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; - } - else - { - l2cu_send_peer_ble_par_req (p_lcb, min_conn_int, max_conn_int, slave_latency, supervision_tout); - } - p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM; - p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; - } + ) { + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, min_conn_int, + max_conn_int, slave_latency, + supervision_tout, 0, 0); + p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; + } else { + l2cu_send_peer_ble_par_req(p_lcb, min_conn_int, max_conn_int, + slave_latency, supervision_tout); + } + p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM; + p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; } - else - { - /* application allows to do update, if we were delaying one do it now */ - if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) - { - /* if both side 4.1, or we are master device, send HCI command */ - if (p_lcb->link_role == HCI_ROLE_MASTER + } else { + /* application allows to do update, if we were delaying one do it now */ + if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) { + /* if both side 4.1, or we are master device, send HCI command */ + if (p_lcb->link_role == HCI_ROLE_MASTER #if (BLE_LLT_INCLUDED == TRUE) - || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) && - HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) + || (HCI_LE_CONN_PARAM_REQ_SUPPORTED( + controller_get_interface()->get_features_ble()->as_array) && + HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) #endif - ) - { - btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval, - p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0); - p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; - } - else - { - l2cu_send_peer_ble_par_req (p_lcb, p_lcb->min_interval, p_lcb->max_interval, - p_lcb->latency, p_lcb->timeout); - } - p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM; - p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM; - } + ) { + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval, + p_lcb->max_interval, p_lcb->latency, + p_lcb->timeout, 0, 0); + p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; + } else { + l2cu_send_peer_ble_par_req(p_lcb, p_lcb->min_interval, + p_lcb->max_interval, p_lcb->latency, + p_lcb->timeout); + } + p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM; + p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM; } + } } /******************************************************************************* @@ -543,29 +536,28 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2cble_process_conn_update_evt (uint16_t handle, uint8_t status, - uint16_t interval, uint16_t latency, uint16_t timeout) -{ - L2CAP_TRACE_DEBUG("%s", __func__); - - /* See if we have a link control block for the remote device */ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle); - if (!p_lcb) - { - L2CAP_TRACE_WARNING("%s: Invalid handle: %d", __func__, handle); - return; - } +void l2cble_process_conn_update_evt(uint16_t handle, uint8_t status, + uint16_t interval, uint16_t latency, + uint16_t timeout) { + L2CAP_TRACE_DEBUG("%s", __func__); + + /* See if we have a link control block for the remote device */ + tL2C_LCB* p_lcb = l2cu_find_lcb_by_handle(handle); + if (!p_lcb) { + L2CAP_TRACE_WARNING("%s: Invalid handle: %d", __func__, handle); + return; + } - p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING; + p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING; - if (status != HCI_SUCCESS) - { - L2CAP_TRACE_WARNING("%s: Error status: %d", __func__, status); - } + if (status != HCI_SUCCESS) { + L2CAP_TRACE_WARNING("%s: Error status: %d", __func__, status); + } - l2cble_start_conn_update(p_lcb); + l2cble_start_conn_update(p_lcb); - L2CAP_TRACE_DEBUG("%s: conn_update_mask=%d", __func__, p_lcb->conn_update_mask); + L2CAP_TRACE_DEBUG("%s: conn_update_mask=%d", __func__, + p_lcb->conn_update_mask); } /******************************************************************************* @@ -578,263 +570,254 @@ void l2cble_process_conn_update_evt (uint16_t handle, uint8_t status, * Returns void * ******************************************************************************/ -void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len) -{ - uint8_t *p_pkt_end; - uint8_t cmd_code, id; - uint16_t cmd_len; - uint16_t min_interval, max_interval, latency, timeout; - tL2C_CONN_INFO con_info; - uint16_t lcid = 0, rcid = 0, mtu = 0, mps = 0, initial_credit = 0; - tL2C_CCB *p_ccb = NULL, *temp_p_ccb = NULL; - tL2C_RCB *p_rcb; - uint16_t credit; - p_pkt_end = p + pkt_len; - - STREAM_TO_UINT8 (cmd_code, p); - STREAM_TO_UINT8 (id, p); - STREAM_TO_UINT16 (cmd_len, p); - - /* Check command length does not exceed packet length */ - if ((p + cmd_len) > p_pkt_end) - { - L2CAP_TRACE_WARNING ("L2CAP - LE - format error, pkt_len: %d cmd_len: %d code: %d", pkt_len, cmd_len, cmd_code); - return; - } +void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { + uint8_t* p_pkt_end; + uint8_t cmd_code, id; + uint16_t cmd_len; + uint16_t min_interval, max_interval, latency, timeout; + tL2C_CONN_INFO con_info; + uint16_t lcid = 0, rcid = 0, mtu = 0, mps = 0, initial_credit = 0; + tL2C_CCB *p_ccb = NULL, *temp_p_ccb = NULL; + tL2C_RCB* p_rcb; + uint16_t credit; + p_pkt_end = p + pkt_len; + + STREAM_TO_UINT8(cmd_code, p); + STREAM_TO_UINT8(id, p); + STREAM_TO_UINT16(cmd_len, p); + + /* Check command length does not exceed packet length */ + if ((p + cmd_len) > p_pkt_end) { + L2CAP_TRACE_WARNING( + "L2CAP - LE - format error, pkt_len: %d cmd_len: %d code: %d", + pkt_len, cmd_len, cmd_code); + return; + } + + switch (cmd_code) { + case L2CAP_CMD_REJECT: + p += 2; + break; + + case L2CAP_CMD_ECHO_REQ: + case L2CAP_CMD_ECHO_RSP: + case L2CAP_CMD_INFO_RSP: + case L2CAP_CMD_INFO_REQ: + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); + break; + + case L2CAP_CMD_BLE_UPDATE_REQ: + STREAM_TO_UINT16(min_interval, p); /* 0x0006 - 0x0C80 */ + STREAM_TO_UINT16(max_interval, p); /* 0x0006 - 0x0C80 */ + STREAM_TO_UINT16(latency, p); /* 0x0000 - 0x03E8 */ + STREAM_TO_UINT16(timeout, p); /* 0x000A - 0x0C80 */ + /* If we are a master, the slave wants to update the parameters */ + if (p_lcb->link_role == HCI_ROLE_MASTER) { + if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) + min_interval = BTM_BLE_CONN_INT_MIN_LIMIT; + + // While this could result in connection parameters that fall + // outside fo the range requested, this will allow the connection + // to remain established. + // In other words, this is a workaround for certain peripherals. + if (max_interval < BTM_BLE_CONN_INT_MIN_LIMIT) + max_interval = BTM_BLE_CONN_INT_MIN_LIMIT; + + if (min_interval < BTM_BLE_CONN_INT_MIN || + min_interval > BTM_BLE_CONN_INT_MAX || + max_interval < BTM_BLE_CONN_INT_MIN || + max_interval > BTM_BLE_CONN_INT_MAX || + latency > BTM_BLE_CONN_LATENCY_MAX || + /*(timeout >= max_interval && latency > (timeout * 10/(max_interval + * 1.25) - 1)) ||*/ + timeout < BTM_BLE_CONN_SUP_TOUT_MIN || + timeout > BTM_BLE_CONN_SUP_TOUT_MAX || + max_interval < min_interval) { + l2cu_send_peer_ble_par_rsp(p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); + } else { + l2cu_send_peer_ble_par_rsp(p_lcb, L2CAP_CFG_OK, id); + + p_lcb->min_interval = min_interval; + p_lcb->max_interval = max_interval; + p_lcb->latency = latency; + p_lcb->timeout = timeout; + p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; + + l2cble_start_conn_update(p_lcb); + } + } else + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, + 0); + break; + + case L2CAP_CMD_BLE_UPDATE_RSP: + p += 2; + break; + + case L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ: + STREAM_TO_UINT16(con_info.psm, p); + STREAM_TO_UINT16(rcid, p); + STREAM_TO_UINT16(mtu, p); + STREAM_TO_UINT16(mps, p); + STREAM_TO_UINT16(initial_credit, p); + + L2CAP_TRACE_DEBUG( + "Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ with " + "mtu = %d, " + "mps = %d, " + "initial credit = %d", + mtu, mps, initial_credit); + + p_rcb = l2cu_find_ble_rcb_by_psm(con_info.psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - rcvd conn req for unknown PSM: 0x%04x", + con_info.psm); + l2cu_reject_ble_connection(p_lcb, id, L2CAP_LE_NO_PSM); + break; + } else { + if (!p_rcb->api.pL2CA_ConnectInd_Cb) { + L2CAP_TRACE_WARNING( + "L2CAP - rcvd conn req for outgoing-only connection PSM: %d", + con_info.psm); + l2cu_reject_ble_connection(p_lcb, id, L2CAP_CONN_NO_PSM); + break; + } + } + + /* Allocate a ccb for this.*/ + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - unable to allocate CCB"); + l2cu_reject_ble_connection(p_lcb, id, L2CAP_CONN_NO_RESOURCES); + break; + } + + /* validate the parameters */ + if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS || + mps > L2CAP_LE_MAX_MPS) { + L2CAP_TRACE_ERROR("L2CAP don't like the params"); + l2cu_reject_ble_connection(p_lcb, id, L2CAP_CONN_NO_RESOURCES); + break; + } + + p_ccb->remote_id = id; + p_ccb->p_rcb = p_rcb; + p_ccb->remote_cid = rcid; + + p_ccb->peer_conn_cfg.mtu = mtu; + p_ccb->peer_conn_cfg.mps = mps; + p_ccb->peer_conn_cfg.credits = initial_credit; + + p_ccb->tx_mps = mps; + p_ccb->ble_sdu = NULL; + p_ccb->ble_sdu_length = 0; + p_ccb->is_first_seg = true; + p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; + + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); + break; + + case L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES: + L2CAP_TRACE_DEBUG("Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES"); + /* For all channels, see whose identifier matches this id */ + for (temp_p_ccb = p_lcb->ccb_queue.p_first_ccb; temp_p_ccb; + temp_p_ccb = temp_p_ccb->p_next_ccb) { + if (temp_p_ccb->local_id == id) { + p_ccb = temp_p_ccb; + break; + } + } + if (p_ccb) { + L2CAP_TRACE_DEBUG("I remember the connection req"); + STREAM_TO_UINT16(p_ccb->remote_cid, p); + STREAM_TO_UINT16(p_ccb->peer_conn_cfg.mtu, p); + STREAM_TO_UINT16(p_ccb->peer_conn_cfg.mps, p); + STREAM_TO_UINT16(p_ccb->peer_conn_cfg.credits, p); + STREAM_TO_UINT16(con_info.l2cap_result, p); + con_info.remote_cid = p_ccb->remote_cid; + + L2CAP_TRACE_DEBUG( + "remote_cid = %d, " + "mtu = %d, " + "mps = %d, " + "initial_credit = %d, " + "con_info.l2cap_result = %d", + p_ccb->remote_cid, p_ccb->peer_conn_cfg.mtu, + p_ccb->peer_conn_cfg.mps, p_ccb->peer_conn_cfg.credits, + con_info.l2cap_result); + + /* validate the parameters */ + if (p_ccb->peer_conn_cfg.mtu < L2CAP_LE_MIN_MTU || + p_ccb->peer_conn_cfg.mps < L2CAP_LE_MIN_MPS || + p_ccb->peer_conn_cfg.mps > L2CAP_LE_MAX_MPS) { + L2CAP_TRACE_ERROR("L2CAP don't like the params"); + con_info.l2cap_result = L2CAP_LE_NO_RESOURCES; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); + break; + } - switch (cmd_code) - { - case L2CAP_CMD_REJECT: - p += 2; - break; - - case L2CAP_CMD_ECHO_REQ: - case L2CAP_CMD_ECHO_RSP: - case L2CAP_CMD_INFO_RSP: - case L2CAP_CMD_INFO_REQ: - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); - break; - - case L2CAP_CMD_BLE_UPDATE_REQ: - STREAM_TO_UINT16 (min_interval, p); /* 0x0006 - 0x0C80 */ - STREAM_TO_UINT16 (max_interval, p); /* 0x0006 - 0x0C80 */ - STREAM_TO_UINT16 (latency, p); /* 0x0000 - 0x03E8 */ - STREAM_TO_UINT16 (timeout, p); /* 0x000A - 0x0C80 */ - /* If we are a master, the slave wants to update the parameters */ - if (p_lcb->link_role == HCI_ROLE_MASTER) - { - if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) - min_interval = BTM_BLE_CONN_INT_MIN_LIMIT; - - // While this could result in connection parameters that fall - // outside fo the range requested, this will allow the connection - // to remain established. - // In other words, this is a workaround for certain peripherals. - if (max_interval < BTM_BLE_CONN_INT_MIN_LIMIT) - max_interval = BTM_BLE_CONN_INT_MIN_LIMIT; - - if (min_interval < BTM_BLE_CONN_INT_MIN || min_interval > BTM_BLE_CONN_INT_MAX || - max_interval < BTM_BLE_CONN_INT_MIN || max_interval > BTM_BLE_CONN_INT_MAX || - latency > BTM_BLE_CONN_LATENCY_MAX || - /*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/ - timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX || - max_interval < min_interval) - { - l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); - } - else - { - - l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id); - - p_lcb->min_interval = min_interval; - p_lcb->max_interval = max_interval; - p_lcb->latency = latency; - p_lcb->timeout = timeout; - p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; - - l2cble_start_conn_update(p_lcb); - } - } - else - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); - break; - - case L2CAP_CMD_BLE_UPDATE_RSP: - p += 2; - break; - - case L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ: - STREAM_TO_UINT16 (con_info.psm, p); - STREAM_TO_UINT16 (rcid, p); - STREAM_TO_UINT16 (mtu, p); - STREAM_TO_UINT16 (mps, p); - STREAM_TO_UINT16 (initial_credit, p); - - L2CAP_TRACE_DEBUG ("Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ with " - "mtu = %d, " - "mps = %d, " - "initial credit = %d", mtu, mps, initial_credit); - - p_rcb = l2cu_find_ble_rcb_by_psm(con_info.psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for unknown PSM: 0x%04x", con_info.psm); - l2cu_reject_ble_connection (p_lcb, id, L2CAP_LE_NO_PSM); - break; - } - else - { - if (!p_rcb->api.pL2CA_ConnectInd_Cb) - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for outgoing-only connection PSM: %d", con_info.psm); - l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_PSM); - break; - } - } - - /* Allocate a ccb for this.*/ - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - unable to allocate CCB"); - l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_RESOURCES); - break; - } - - /* validate the parameters */ - if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS || mps > L2CAP_LE_MAX_MPS) - { - L2CAP_TRACE_ERROR ("L2CAP don't like the params"); - l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_RESOURCES); - break; - } - - p_ccb->remote_id = id; - p_ccb->p_rcb = p_rcb; - p_ccb->remote_cid = rcid; - - p_ccb->peer_conn_cfg.mtu = mtu; - p_ccb->peer_conn_cfg.mps = mps; - p_ccb->peer_conn_cfg.credits = initial_credit; - - p_ccb->tx_mps = mps; - p_ccb->ble_sdu = NULL; - p_ccb->ble_sdu_length = 0; - p_ccb->is_first_seg = true; - p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; - - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); - break; - - case L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES: - L2CAP_TRACE_DEBUG ("Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES"); - /* For all channels, see whose identifier matches this id */ - for (temp_p_ccb = p_lcb->ccb_queue.p_first_ccb; temp_p_ccb; temp_p_ccb = temp_p_ccb->p_next_ccb) - { - if (temp_p_ccb->local_id == id) - { - p_ccb = temp_p_ccb; - break; - } - } - if (p_ccb) - { - L2CAP_TRACE_DEBUG ("I remember the connection req"); - STREAM_TO_UINT16 (p_ccb->remote_cid, p); - STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.mtu, p); - STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.mps, p); - STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.credits, p); - STREAM_TO_UINT16 (con_info.l2cap_result, p); - con_info.remote_cid = p_ccb->remote_cid; - - L2CAP_TRACE_DEBUG ("remote_cid = %d, " - "mtu = %d, " - "mps = %d, " - "initial_credit = %d, " - "con_info.l2cap_result = %d", - p_ccb->remote_cid, p_ccb->peer_conn_cfg.mtu, p_ccb->peer_conn_cfg.mps, - p_ccb->peer_conn_cfg.credits, con_info.l2cap_result); - - /* validate the parameters */ - if (p_ccb->peer_conn_cfg.mtu < L2CAP_LE_MIN_MTU || - p_ccb->peer_conn_cfg.mps < L2CAP_LE_MIN_MPS || - p_ccb->peer_conn_cfg.mps > L2CAP_LE_MAX_MPS) - { - L2CAP_TRACE_ERROR ("L2CAP don't like the params"); - con_info.l2cap_result = L2CAP_LE_NO_RESOURCES; - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); - break; - } - - p_ccb->tx_mps = p_ccb->peer_conn_cfg.mps; - p_ccb->ble_sdu = NULL; - p_ccb->ble_sdu_length = 0; - p_ccb->is_first_seg = true; - p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; - - if (con_info.l2cap_result == L2CAP_LE_CONN_OK) - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); - else - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); - } - else - { - L2CAP_TRACE_DEBUG ("I DO NOT remember the connection req"); - con_info.l2cap_result = L2CAP_LE_INVALID_SOURCE_CID; - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); - } - break; - - case L2CAP_CMD_BLE_FLOW_CTRL_CREDIT: - STREAM_TO_UINT16(lcid, p); - p_ccb = l2cu_find_ccb_by_remote_cid(p_lcb, lcid); - if(p_ccb == NULL) - { - L2CAP_TRACE_DEBUG ("%s Credit received for unknown channel id %d", __func__, lcid); - break; - } - - STREAM_TO_UINT16(credit ,p); - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT, &credit); - L2CAP_TRACE_DEBUG ("%s Credit received", __func__); - break; - - case L2CAP_CMD_DISC_REQ: - STREAM_TO_UINT16 (lcid, p); - STREAM_TO_UINT16 (rcid, p); - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - if (p_ccb->remote_cid == rcid) - { - p_ccb->remote_id = id; - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, NULL); - } - } - else - l2cu_send_peer_disc_rsp (p_lcb, id, lcid, rcid); - - break; - - case L2CAP_CMD_DISC_RSP: - STREAM_TO_UINT16 (rcid, p); - STREAM_TO_UINT16 (lcid, p); - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, NULL); - } - break; - - default: - L2CAP_TRACE_WARNING ("L2CAP - LE - unknown cmd code: %d", cmd_code); - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); - break; - } + p_ccb->tx_mps = p_ccb->peer_conn_cfg.mps; + p_ccb->ble_sdu = NULL; + p_ccb->ble_sdu_length = 0; + p_ccb->is_first_seg = true; + p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; + + if (con_info.l2cap_result == L2CAP_LE_CONN_OK) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); + else + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); + } else { + L2CAP_TRACE_DEBUG("I DO NOT remember the connection req"); + con_info.l2cap_result = L2CAP_LE_INVALID_SOURCE_CID; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); + } + break; + + case L2CAP_CMD_BLE_FLOW_CTRL_CREDIT: + STREAM_TO_UINT16(lcid, p); + p_ccb = l2cu_find_ccb_by_remote_cid(p_lcb, lcid); + if (p_ccb == NULL) { + L2CAP_TRACE_DEBUG("%s Credit received for unknown channel id %d", + __func__, lcid); + break; + } + + STREAM_TO_UINT16(credit, p); + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT, &credit); + L2CAP_TRACE_DEBUG("%s Credit received", __func__); + break; + + case L2CAP_CMD_DISC_REQ: + STREAM_TO_UINT16(lcid, p); + STREAM_TO_UINT16(rcid, p); + + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + if (p_ccb->remote_cid == rcid) { + p_ccb->remote_id = id; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, NULL); + } + } else + l2cu_send_peer_disc_rsp(p_lcb, id, lcid, rcid); + + break; + + case L2CAP_CMD_DISC_RSP: + STREAM_TO_UINT16(rcid, p); + STREAM_TO_UINT16(lcid, p); + + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, NULL); + } + break; + + default: + L2CAP_TRACE_WARNING("L2CAP - LE - unknown cmd code: %d", cmd_code); + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); + break; + } } /******************************************************************************* @@ -846,82 +829,90 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len) * Returns true connection initiated, false otherwise. * ******************************************************************************/ -bool l2cble_init_direct_conn (tL2C_LCB *p_lcb) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - uint16_t scan_int; - uint16_t scan_win; - BD_ADDR peer_addr; - uint8_t peer_addr_type = BLE_ADDR_PUBLIC; - uint8_t own_addr_type = BLE_ADDR_PUBLIC; - - /* There can be only one BLE connection request outstanding at a time */ - if (p_dev_rec == NULL) - { - L2CAP_TRACE_WARNING ("unknown device, can not initate connection"); - return(false); - } - - scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; - scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; - - peer_addr_type = p_lcb->ble_addr_type; - memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); +bool l2cble_init_direct_conn(tL2C_LCB* p_lcb) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(p_lcb->remote_bd_addr); + tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; + uint16_t scan_int; + uint16_t scan_win; + BD_ADDR peer_addr; + uint8_t peer_addr_type = BLE_ADDR_PUBLIC; + uint8_t own_addr_type = BLE_ADDR_PUBLIC; + + /* There can be only one BLE connection request outstanding at a time */ + if (p_dev_rec == NULL) { + L2CAP_TRACE_WARNING("unknown device, can not initate connection"); + return (false); + } + + scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) + ? BTM_BLE_SCAN_FAST_INT + : p_cb->scan_int; + scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) + ? BTM_BLE_SCAN_FAST_WIN + : p_cb->scan_win; + + peer_addr_type = p_lcb->ble_addr_type; + memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); #if (BLE_PRIVACY_SPT == TRUE) - own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; - if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) - { - if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2) - own_addr_type |= BLE_ADDR_TYPE_ID_BIT; - - btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); - btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type); - } else { - btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); + own_addr_type = + btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; + if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { + if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2) + own_addr_type |= BLE_ADDR_TYPE_ID_BIT; + + btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); + btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type); + } else { + btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); - // If we have a current RPA, use that instead. - if (!bdaddr_is_empty((const bt_bdaddr_t *)p_dev_rec->ble.cur_rand_addr)) { - memcpy(peer_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); - } + // If we have a current RPA, use that instead. + if (!bdaddr_is_empty((const bt_bdaddr_t*)p_dev_rec->ble.cur_rand_addr)) { + memcpy(peer_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); } + } #endif - if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) - { - l2cu_release_lcb (p_lcb); - L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); - return false; - } - - btsnd_hcic_ble_create_ll_conn(scan_int,/* uint16_t scan_int */ - scan_win, /* uint16_t scan_win */ - false, /* uint8_t white_list */ - peer_addr_type, /* uint8_t addr_type_peer */ - peer_addr, /* BD_ADDR bda_peer */ - own_addr_type, /* uint8_t addr_type_own */ - (uint16_t) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? - p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* uint16_t conn_int_min */ - (uint16_t) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? - p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* uint16_t conn_int_max */ - (uint16_t) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? - p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* uint16_t conn_latency */ - (uint16_t) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? - p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ - 0, /* uint16_t min_len */ - 0); /* uint16_t max_len */ - - p_lcb->link_state = LST_CONNECTING; - l2cb.is_ble_connecting = true; - memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - btm_ble_set_conn_st (BLE_DIR_CONN); - - return (true); + if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) { + l2cu_release_lcb(p_lcb); + L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); + return false; + } + + btsnd_hcic_ble_create_ll_conn( + scan_int, /* uint16_t scan_int */ + scan_win, /* uint16_t scan_win */ + false, /* uint8_t white_list */ + peer_addr_type, /* uint8_t addr_type_peer */ + peer_addr, /* BD_ADDR bda_peer */ + own_addr_type, /* uint8_t addr_type_own */ + (uint16_t)( + (p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) + ? p_dev_rec->conn_params.min_conn_int + : BTM_BLE_CONN_INT_MIN_DEF), /* uint16_t conn_int_min */ + (uint16_t)( + (p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) + ? p_dev_rec->conn_params.max_conn_int + : BTM_BLE_CONN_INT_MAX_DEF), /* uint16_t conn_int_max */ + (uint16_t)( + (p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) + ? p_dev_rec->conn_params.slave_latency + : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* uint16_t conn_latency */ + (uint16_t)( + (p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) + ? p_dev_rec->conn_params.supervision_tout + : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ + 0, /* uint16_t min_len */ + 0); /* uint16_t max_len */ + + p_lcb->link_state = LST_CONNECTING; + l2cb.is_ble_connecting = true; + memcpy(l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + btm_ble_set_conn_st(BLE_DIR_CONN); + + return (true); } /******************************************************************************* @@ -933,28 +924,24 @@ bool l2cble_init_direct_conn (tL2C_LCB *p_lcb) * Returns true if successful, false if connection not started. * ******************************************************************************/ -bool l2cble_create_conn (tL2C_LCB *p_lcb) -{ - tBTM_BLE_CONN_ST conn_st = btm_ble_get_conn_st(); - bool rt = false; - - /* There can be only one BLE connection request outstanding at a time */ - if (conn_st == BLE_CONN_IDLE) - { - rt = l2cble_init_direct_conn(p_lcb); - } - else - { - L2CAP_TRACE_WARNING ("L2CAP - LE - cannot start new connection at conn st: %d", conn_st); +bool l2cble_create_conn(tL2C_LCB* p_lcb) { + tBTM_BLE_CONN_ST conn_st = btm_ble_get_conn_st(); + bool rt = false; - btm_ble_enqueue_direct_conn_req(p_lcb); + /* There can be only one BLE connection request outstanding at a time */ + if (conn_st == BLE_CONN_IDLE) { + rt = l2cble_init_direct_conn(p_lcb); + } else { + L2CAP_TRACE_WARNING( + "L2CAP - LE - cannot start new connection at conn st: %d", conn_st); - if (conn_st == BLE_BG_CONN) - btm_ble_suspend_bg_conn(); + btm_ble_enqueue_direct_conn_req(p_lcb); - rt = true; - } - return rt; + if (conn_st == BLE_BG_CONN) btm_ble_suspend_bg_conn(); + + rt = true; + } + return rt; } /******************************************************************************* @@ -968,15 +955,13 @@ bool l2cble_create_conn (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2c_link_processs_ble_num_bufs (uint16_t num_lm_ble_bufs) -{ - if (num_lm_ble_bufs == 0) - { - num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED; - l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED; - } +void l2c_link_processs_ble_num_bufs(uint16_t num_lm_ble_bufs) { + if (num_lm_ble_bufs == 0) { + num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED; + l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED; + } - l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs; + l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs; } /******************************************************************************* @@ -994,117 +979,109 @@ void l2c_link_processs_ble_num_bufs (uint16_t num_lm_ble_bufs) * Returns void * ******************************************************************************/ -void l2c_ble_link_adjust_allocation (void) -{ - uint16_t qq, yy, qq_remainder; - tL2C_LCB *p_lcb; - uint16_t hi_quota, low_quota; - uint16_t num_lowpri_links = 0; - uint16_t num_hipri_links = 0; - uint16_t controller_xmit_quota = l2cb.num_lm_ble_bufs; - uint16_t high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A; - - /* If no links active, reset buffer quotas and controller buffers */ - if (l2cb.num_ble_links_active == 0) - { - l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs; - l2cb.ble_round_robin_quota = l2cb.ble_round_robin_unacked = 0; - return; - } - - /* First, count the links */ - for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) - { - if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) - { - if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - num_hipri_links++; - else - num_lowpri_links++; - } - } - - /* now adjust high priority link quota */ - low_quota = num_lowpri_links ? 1 : 0; - while ( (num_hipri_links * high_pri_link_quota + low_quota) > controller_xmit_quota ) - high_pri_link_quota--; - - - /* Work out the xmit quota and buffer quota high and low priorities */ - hi_quota = num_hipri_links * high_pri_link_quota; - low_quota = (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1; - - /* Work out and save the HCI xmit quota for each low priority link */ - - /* If each low priority link cannot have at least one buffer */ - if (num_lowpri_links > low_quota) - { - l2cb.ble_round_robin_quota = low_quota; - qq = qq_remainder = 0; - } - /* If each low priority link can have at least one buffer */ - else if (num_lowpri_links > 0) - { - l2cb.ble_round_robin_quota = 0; - l2cb.ble_round_robin_unacked = 0; - qq = low_quota / num_lowpri_links; - qq_remainder = low_quota % num_lowpri_links; - } - /* If no low priority link */ - else - { - l2cb.ble_round_robin_quota = 0; - l2cb.ble_round_robin_unacked = 0; - qq = qq_remainder = 0; +void l2c_ble_link_adjust_allocation(void) { + uint16_t qq, yy, qq_remainder; + tL2C_LCB* p_lcb; + uint16_t hi_quota, low_quota; + uint16_t num_lowpri_links = 0; + uint16_t num_hipri_links = 0; + uint16_t controller_xmit_quota = l2cb.num_lm_ble_bufs; + uint16_t high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A; + + /* If no links active, reset buffer quotas and controller buffers */ + if (l2cb.num_ble_links_active == 0) { + l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs; + l2cb.ble_round_robin_quota = l2cb.ble_round_robin_unacked = 0; + return; + } + + /* First, count the links */ + for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) { + if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) { + if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) + num_hipri_links++; + else + num_lowpri_links++; } - L2CAP_TRACE_EVENT ("l2c_ble_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u", - num_hipri_links, num_lowpri_links, low_quota, - l2cb.ble_round_robin_quota, qq); - - /* Now, assign the quotas to each link */ - for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) - { - if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) - { - if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - { - p_lcb->link_xmit_quota = high_pri_link_quota; - } - else - { - /* Safety check in case we switched to round-robin with something outstanding */ - /* if sent_not_acked is added into round_robin_unacked then don't add it again */ - /* l2cap keeps updating sent_not_acked for exiting from round robin */ - if (( p_lcb->link_xmit_quota > 0 )&&( qq == 0 )) - l2cb.ble_round_robin_unacked += p_lcb->sent_not_acked; - - p_lcb->link_xmit_quota = qq; - if (qq_remainder > 0) - { - p_lcb->link_xmit_quota++; - qq_remainder--; - } - } - - L2CAP_TRACE_EVENT("l2c_ble_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", - yy, p_lcb->acl_priority, p_lcb->link_xmit_quota); - - L2CAP_TRACE_EVENT(" SentNotAcked: %d RRUnacked: %d", - p_lcb->sent_not_acked, l2cb.round_robin_unacked); - - /* There is a special case where we have readjusted the link quotas and */ - /* this link may have sent anything but some other link sent packets so */ - /* so we may need a timer to kick off this link's transmissions. */ - if ( (p_lcb->link_state == LST_CONNECTED) - && (!list_is_empty(p_lcb->link_xmit_data_q)) - && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } + } + + /* now adjust high priority link quota */ + low_quota = num_lowpri_links ? 1 : 0; + while ((num_hipri_links * high_pri_link_quota + low_quota) > + controller_xmit_quota) + high_pri_link_quota--; + + /* Work out the xmit quota and buffer quota high and low priorities */ + hi_quota = num_hipri_links * high_pri_link_quota; + low_quota = + (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1; + + /* Work out and save the HCI xmit quota for each low priority link */ + + /* If each low priority link cannot have at least one buffer */ + if (num_lowpri_links > low_quota) { + l2cb.ble_round_robin_quota = low_quota; + qq = qq_remainder = 0; + } + /* If each low priority link can have at least one buffer */ + else if (num_lowpri_links > 0) { + l2cb.ble_round_robin_quota = 0; + l2cb.ble_round_robin_unacked = 0; + qq = low_quota / num_lowpri_links; + qq_remainder = low_quota % num_lowpri_links; + } + /* If no low priority link */ + else { + l2cb.ble_round_robin_quota = 0; + l2cb.ble_round_robin_unacked = 0; + qq = qq_remainder = 0; + } + L2CAP_TRACE_EVENT( + "l2c_ble_link_adjust_allocation num_hipri: %u num_lowpri: %u " + "low_quota: %u round_robin_quota: %u qq: %u", + num_hipri_links, num_lowpri_links, low_quota, l2cb.ble_round_robin_quota, + qq); + + /* Now, assign the quotas to each link */ + for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) { + if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) { + if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) { + p_lcb->link_xmit_quota = high_pri_link_quota; + } else { + /* Safety check in case we switched to round-robin with something + * outstanding */ + /* if sent_not_acked is added into round_robin_unacked then don't add it + * again */ + /* l2cap keeps updating sent_not_acked for exiting from round robin */ + if ((p_lcb->link_xmit_quota > 0) && (qq == 0)) + l2cb.ble_round_robin_unacked += p_lcb->sent_not_acked; + + p_lcb->link_xmit_quota = qq; + if (qq_remainder > 0) { + p_lcb->link_xmit_quota++; + qq_remainder--; } + } + + L2CAP_TRACE_EVENT( + "l2c_ble_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", + yy, p_lcb->acl_priority, p_lcb->link_xmit_quota); + + L2CAP_TRACE_EVENT(" SentNotAcked: %d RRUnacked: %d", + p_lcb->sent_not_acked, l2cb.round_robin_unacked); + + /* There is a special case where we have readjusted the link quotas and */ + /* this link may have sent anything but some other link sent packets so */ + /* so we may need a timer to kick off this link's transmissions. */ + if ((p_lcb->link_state == LST_CONNECTED) && + (!list_is_empty(p_lcb->link_xmit_data_q)) && + (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) { + alarm_set_on_queue( + p_lcb->l2c_lcb_timer, L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } } + } } #if (BLE_LLT_INCLUDED == TRUE) @@ -1117,35 +1094,31 @@ void l2c_ble_link_adjust_allocation (void) * Returns void * ******************************************************************************/ -void l2cble_process_rc_param_request_evt(uint16_t handle, uint16_t int_min, uint16_t int_max, - uint16_t latency, uint16_t timeout) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle (handle); - - if (p_lcb != NULL) - { - p_lcb->min_interval = int_min; - p_lcb->max_interval = int_max; - p_lcb->latency = latency; - p_lcb->timeout = timeout; - - /* if update is enabled, always accept connection parameter update */ - if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) - { - btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, timeout, 0, 0); - } - else - { - L2CAP_TRACE_EVENT ("L2CAP - LE - update currently disabled"); - p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; - btsnd_hcic_ble_rc_param_req_neg_reply (handle,HCI_ERR_UNACCEPT_CONN_INTERVAL); - } +void l2cble_process_rc_param_request_evt(uint16_t handle, uint16_t int_min, + uint16_t int_max, uint16_t latency, + uint16_t timeout) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_handle(handle); + + if (p_lcb != NULL) { + p_lcb->min_interval = int_min; + p_lcb->max_interval = int_max; + p_lcb->latency = latency; + p_lcb->timeout = timeout; + /* if update is enabled, always accept connection parameter update */ + if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) { + btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, + timeout, 0, 0); + } else { + L2CAP_TRACE_EVENT("L2CAP - LE - update currently disabled"); + p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; + btsnd_hcic_ble_rc_param_req_neg_reply(handle, + HCI_ERR_UNACCEPT_CONN_INTERVAL); } - else - { - L2CAP_TRACE_WARNING("No link to update connection parameter") - } + + } else { + L2CAP_TRACE_WARNING("No link to update connection parameter") + } } #endif @@ -1158,34 +1131,28 @@ void l2cble_process_rc_param_request_evt(uint16_t handle, uint16_t int_min, uint * Returns void * ******************************************************************************/ -void l2cble_update_data_length(tL2C_LCB *p_lcb) -{ - uint16_t tx_mtu = 0; - uint16_t i = 0; +void l2cble_update_data_length(tL2C_LCB* p_lcb) { + uint16_t tx_mtu = 0; + uint16_t i = 0; - L2CAP_TRACE_DEBUG("%s", __func__); + L2CAP_TRACE_DEBUG("%s", __func__); - /* See if we have a link control block for the connection */ - if (p_lcb == NULL) - return; + /* See if we have a link control block for the connection */ + if (p_lcb == NULL) return; - for (i = 0; i < L2CAP_NUM_FIXED_CHNLS; i++) - { - if (i + L2CAP_FIRST_FIXED_CHNL != L2CAP_BLE_SIGNALLING_CID) - { - if ((p_lcb->p_fixed_ccbs[i] != NULL) && - (tx_mtu < (p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD))) - tx_mtu = p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD; - } + for (i = 0; i < L2CAP_NUM_FIXED_CHNLS; i++) { + if (i + L2CAP_FIRST_FIXED_CHNL != L2CAP_BLE_SIGNALLING_CID) { + if ((p_lcb->p_fixed_ccbs[i] != NULL) && + (tx_mtu < (p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD))) + tx_mtu = p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD; } + } - if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) - tx_mtu = BTM_BLE_DATA_SIZE_MAX; - - /* update TX data length if changed */ - if (p_lcb->tx_data_len != tx_mtu) - BTM_SetBleDataLength(p_lcb->remote_bd_addr, tx_mtu); + if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) tx_mtu = BTM_BLE_DATA_SIZE_MAX; + /* update TX data length if changed */ + if (p_lcb->tx_data_len != tx_mtu) + BTM_SetBleDataLength(p_lcb->remote_bd_addr, tx_mtu); } /******************************************************************************* @@ -1197,18 +1164,17 @@ void l2cble_update_data_length(tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2cble_process_data_length_change_event(uint16_t handle, uint16_t tx_data_len, uint16_t rx_data_len) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle); +void l2cble_process_data_length_change_event(uint16_t handle, + uint16_t tx_data_len, + uint16_t rx_data_len) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_handle(handle); - L2CAP_TRACE_DEBUG("%s TX data len = %d", __func__, tx_data_len); - if (p_lcb == NULL) - return; + L2CAP_TRACE_DEBUG("%s TX data len = %d", __func__, tx_data_len); + if (p_lcb == NULL) return; - if (tx_data_len > 0) - p_lcb->tx_data_len = tx_data_len; + if (tx_data_len > 0) p_lcb->tx_data_len = tx_data_len; - /* ignore rx_data len for now */ + /* ignore rx_data len for now */ } /******************************************************************************* @@ -1221,32 +1187,29 @@ void l2cble_process_data_length_change_event(uint16_t handle, uint16_t tx_data_l * Returns void * ******************************************************************************/ -void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, uint16_t fix_cid, uint16_t tx_mtu) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, BT_TRANSPORT_LE); - uint16_t cid = fix_cid - L2CAP_FIRST_FIXED_CHNL; +void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, + uint16_t fix_cid, + uint16_t tx_mtu) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, BT_TRANSPORT_LE); + uint16_t cid = fix_cid - L2CAP_FIRST_FIXED_CHNL; - L2CAP_TRACE_DEBUG("%s TX MTU = %d", __func__, tx_mtu); + L2CAP_TRACE_DEBUG("%s TX MTU = %d", __func__, tx_mtu); - if (!controller_get_interface()->supports_ble_packet_extension()) - { - L2CAP_TRACE_WARNING("%s, request not supported", __func__); - return; - } + if (!controller_get_interface()->supports_ble_packet_extension()) { + L2CAP_TRACE_WARNING("%s, request not supported", __func__); + return; + } - /* See if we have a link control block for the connection */ - if (p_lcb == NULL) - return; + /* See if we have a link control block for the connection */ + if (p_lcb == NULL) return; - if (p_lcb->p_fixed_ccbs[cid] != NULL) - { - if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) - tx_mtu = BTM_BLE_DATA_SIZE_MAX; + if (p_lcb->p_fixed_ccbs[cid] != NULL) { + if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) tx_mtu = BTM_BLE_DATA_SIZE_MAX; - p_lcb->p_fixed_ccbs[cid]->tx_data_len = tx_mtu; - } + p_lcb->p_fixed_ccbs[cid]->tx_data_len = tx_mtu; + } - l2cble_update_data_length(p_lcb); + l2cble_update_data_length(p_lcb); } /******************************************************************************* @@ -1259,19 +1222,16 @@ void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, uint16_t fix_ci * Returns void * ******************************************************************************/ -void l2cble_credit_based_conn_req (tL2C_CCB *p_ccb) -{ - if (!p_ccb) - return; +void l2cble_credit_based_conn_req(tL2C_CCB* p_ccb) { + if (!p_ccb) return; - if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("LE link doesn't exist"); - return; - } - - l2cu_send_peer_ble_credit_based_conn_req (p_ccb); + if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("LE link doesn't exist"); return; + } + + l2cu_send_peer_ble_credit_based_conn_req(p_ccb); + return; } /******************************************************************************* @@ -1284,19 +1244,16 @@ void l2cble_credit_based_conn_req (tL2C_CCB *p_ccb) * Returns void * ******************************************************************************/ -void l2cble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result) -{ - if (!p_ccb) - return; - - if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("LE link doesn't exist"); - return; - } +void l2cble_credit_based_conn_res(tL2C_CCB* p_ccb, uint16_t result) { + if (!p_ccb) return; - l2cu_send_peer_ble_credit_based_conn_res (p_ccb, result); + if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("LE link doesn't exist"); return; + } + + l2cu_send_peer_ble_credit_based_conn_res(p_ccb, result); + return; } /******************************************************************************* @@ -1309,20 +1266,16 @@ void l2cble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result) * Returns void * ******************************************************************************/ -void l2cble_send_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_value) -{ - if (!p_ccb) - return; - - if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("LE link doesn't exist"); - return; - } +void l2cble_send_flow_control_credit(tL2C_CCB* p_ccb, uint16_t credit_value) { + if (!p_ccb) return; - l2cu_send_peer_ble_flow_control_credit(p_ccb, credit_value); + if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("LE link doesn't exist"); return; + } + l2cu_send_peer_ble_flow_control_credit(p_ccb, credit_value); + return; } /******************************************************************************* @@ -1335,20 +1288,17 @@ void l2cble_send_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_value) * Returns void * ******************************************************************************/ -void l2cble_send_peer_disc_req(tL2C_CCB *p_ccb) -{ - L2CAP_TRACE_DEBUG ("%s",__func__); - if (!p_ccb) - return; - - if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) - { - L2CAP_TRACE_WARNING ("LE link doesn't exist"); - return; - } +void l2cble_send_peer_disc_req(tL2C_CCB* p_ccb) { + L2CAP_TRACE_DEBUG("%s", __func__); + if (!p_ccb) return; - l2cu_send_peer_ble_credit_based_disconn_req(p_ccb); + if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { + L2CAP_TRACE_WARNING("LE link doesn't exist"); return; + } + + l2cu_send_peer_ble_credit_based_disconn_req(p_ccb); + return; } /******************************************************************************* @@ -1361,78 +1311,69 @@ void l2cble_send_peer_disc_req(tL2C_CCB *p_ccb) * Returns void * ******************************************************************************/ -void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, uint8_t status) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, BT_TRANSPORT_LE); - tL2CAP_SEC_DATA *p_buf = NULL; - uint8_t sec_flag; - uint8_t sec_act; - - if (!p_lcb) - { - L2CAP_TRACE_WARNING ("%s security complete for unknown device", __func__); - return; +void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void* p_ref_data, + uint8_t status) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, BT_TRANSPORT_LE); + tL2CAP_SEC_DATA* p_buf = NULL; + uint8_t sec_flag; + uint8_t sec_act; + + if (!p_lcb) { + L2CAP_TRACE_WARNING("%s security complete for unknown device", __func__); + return; + } + + sec_act = p_lcb->sec_act; + p_lcb->sec_act = 0; + + if (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { + p_buf = (tL2CAP_SEC_DATA*)fixed_queue_dequeue(p_lcb->le_sec_pending_q); + if (!p_buf) { + L2CAP_TRACE_WARNING( + "%s Security complete for request not initiated from L2CAP", + __func__); + return; } - sec_act = p_lcb->sec_act; - p_lcb->sec_act = 0; - - if (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) - { - p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); - if (!p_buf) - { - L2CAP_TRACE_WARNING ("%s Security complete for request not initiated from L2CAP", - __func__); - return; + if (status != BTM_SUCCESS) { + (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); + } else { + if (sec_act == BTM_SEC_ENCRYPT_MITM) { + BTM_GetSecurityFlagsByTransport(p_bda, &sec_flag, transport); + if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) + (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, + status); + else { + L2CAP_TRACE_DEBUG("%s MITM Protection Not present", __func__); + (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, + BTM_FAILED_ON_SECURITY); } + } else { + L2CAP_TRACE_DEBUG("%s MITM Protection not required sec_act = %d", + __func__, p_lcb->sec_act); - if (status != BTM_SUCCESS) - { - (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); - } - else - { - if (sec_act == BTM_SEC_ENCRYPT_MITM) - { - BTM_GetSecurityFlagsByTransport(p_bda, &sec_flag, transport); - if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) - (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); - else - { - L2CAP_TRACE_DEBUG ("%s MITM Protection Not present", __func__); - (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, - BTM_FAILED_ON_SECURITY); - } - } - else - { - L2CAP_TRACE_DEBUG ("%s MITM Protection not required sec_act = %d", - __func__, p_lcb->sec_act); - - (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); - } - } - } - else - { - L2CAP_TRACE_WARNING ("%s Security complete for request not initiated from L2CAP", __func__); - return; + (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, + status); + } } - osi_free(p_buf); + } else { + L2CAP_TRACE_WARNING( + "%s Security complete for request not initiated from L2CAP", __func__); + return; + } + osi_free(p_buf); - while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) - { - p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); + while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { + p_buf = (tL2CAP_SEC_DATA*)fixed_queue_dequeue(p_lcb->le_sec_pending_q); - if (status != BTM_SUCCESS) - (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); - else - l2ble_sec_access_req(p_bda, p_buf->psm, p_buf->is_originator, - p_buf->p_callback, p_buf->p_ref_data); + if (status != BTM_SUCCESS) + (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); + else + l2ble_sec_access_req(p_bda, p_buf->psm, p_buf->is_originator, + p_buf->p_callback, p_buf->p_ref_data); - osi_free(p_buf); - } + osi_free(p_buf); + } } /******************************************************************************* @@ -1446,40 +1387,39 @@ void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, * false - failure * ******************************************************************************/ -bool l2ble_sec_access_req(BD_ADDR bd_addr, uint16_t psm, bool is_originator, tL2CAP_SEC_CBACK *p_callback, void *p_ref_data) -{ - L2CAP_TRACE_DEBUG ("%s", __func__); - bool status; - tL2C_LCB *p_lcb = NULL; - - if (!p_callback) - { - L2CAP_TRACE_ERROR("%s No callback function", __func__); - return false; - } - - p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); - - if (!p_lcb) - { - L2CAP_TRACE_ERROR ("%s Security check for unknown device", __func__); - p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_UNKNOWN_ADDR); - return false; - } - - tL2CAP_SEC_DATA *p_buf = (tL2CAP_SEC_DATA*) osi_malloc((uint16_t)sizeof(tL2CAP_SEC_DATA)); - if (!p_buf) - { - p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_NO_RESOURCES); - return false; - } - - p_buf->psm = psm; - p_buf->is_originator = is_originator; - p_buf->p_callback = p_callback; - p_buf->p_ref_data = p_ref_data; - fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); - status = btm_ble_start_sec_check(bd_addr, psm, is_originator, &l2cble_sec_comp, p_ref_data); - - return status; +bool l2ble_sec_access_req(BD_ADDR bd_addr, uint16_t psm, bool is_originator, + tL2CAP_SEC_CBACK* p_callback, void* p_ref_data) { + L2CAP_TRACE_DEBUG("%s", __func__); + bool status; + tL2C_LCB* p_lcb = NULL; + + if (!p_callback) { + L2CAP_TRACE_ERROR("%s No callback function", __func__); + return false; + } + + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); + + if (!p_lcb) { + L2CAP_TRACE_ERROR("%s Security check for unknown device", __func__); + p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_UNKNOWN_ADDR); + return false; + } + + tL2CAP_SEC_DATA* p_buf = + (tL2CAP_SEC_DATA*)osi_malloc((uint16_t)sizeof(tL2CAP_SEC_DATA)); + if (!p_buf) { + p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_NO_RESOURCES); + return false; + } + + p_buf->psm = psm; + p_buf->is_originator = is_originator; + p_buf->p_callback = p_callback; + p_buf->p_ref_data = p_ref_data; + fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); + status = btm_ble_start_sec_check(bd_addr, psm, is_originator, + &l2cble_sec_comp, p_ref_data); + + return status; } diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc index 989cf0a36..7e907a4da 100644 --- a/stack/l2cap/l2c_csm.cc +++ b/stack/l2cap/l2c_csm.cc @@ -22,37 +22,41 @@ * ******************************************************************************/ +#include #include #include -#include -#include "bt_target.h" #include "bt_common.h" -#include "hcidefs.h" -#include "hcimsgs.h" -#include "l2cdefs.h" -#include "l2c_int.h" +#include "bt_target.h" #include "btm_int.h" #include "btu.h" +#include "hcidefs.h" #include "hcimsgs.h" +#include "l2c_int.h" +#include "l2cdefs.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void l2c_csm_closed (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_orig_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_term_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_w4_l2cap_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_w4_l2ca_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_config (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_open (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_w4_l2cap_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); -static void l2c_csm_w4_l2ca_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data); - -static const char *l2c_csm_get_event_name (uint16_t event); +static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data); +static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); +static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); +static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); +static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); +static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data); +static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data); +static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); +static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data); + +static const char* l2c_csm_get_event_name(uint16_t event); /******************************************************************************* * @@ -63,55 +67,54 @@ static const char *l2c_csm_get_event_name (uint16_t event); * Returns void * ******************************************************************************/ -void l2c_csm_execute (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - if (!l2cu_is_ccb_active(p_ccb)) { - L2CAP_TRACE_WARNING("%s CCB not in use, event (%d) cannot be processed", __func__, event); - return; - } - - switch (p_ccb->chnl_state) - { +void l2c_csm_execute(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { + if (!l2cu_is_ccb_active(p_ccb)) { + L2CAP_TRACE_WARNING("%s CCB not in use, event (%d) cannot be processed", + __func__, event); + return; + } + + switch (p_ccb->chnl_state) { case CST_CLOSED: - l2c_csm_closed (p_ccb, event, p_data); - break; + l2c_csm_closed(p_ccb, event, p_data); + break; case CST_ORIG_W4_SEC_COMP: - l2c_csm_orig_w4_sec_comp (p_ccb, event, p_data); - break; + l2c_csm_orig_w4_sec_comp(p_ccb, event, p_data); + break; case CST_TERM_W4_SEC_COMP: - l2c_csm_term_w4_sec_comp (p_ccb, event, p_data); - break; + l2c_csm_term_w4_sec_comp(p_ccb, event, p_data); + break; case CST_W4_L2CAP_CONNECT_RSP: - l2c_csm_w4_l2cap_connect_rsp (p_ccb, event, p_data); - break; + l2c_csm_w4_l2cap_connect_rsp(p_ccb, event, p_data); + break; case CST_W4_L2CA_CONNECT_RSP: - l2c_csm_w4_l2ca_connect_rsp (p_ccb, event, p_data); - break; + l2c_csm_w4_l2ca_connect_rsp(p_ccb, event, p_data); + break; case CST_CONFIG: - l2c_csm_config (p_ccb, event, p_data); - break; + l2c_csm_config(p_ccb, event, p_data); + break; case CST_OPEN: - l2c_csm_open (p_ccb, event, p_data); - break; + l2c_csm_open(p_ccb, event, p_data); + break; case CST_W4_L2CAP_DISCONNECT_RSP: - l2c_csm_w4_l2cap_disconnect_rsp (p_ccb, event, p_data); - break; + l2c_csm_w4_l2cap_disconnect_rsp(p_ccb, event, p_data); + break; case CST_W4_L2CA_DISCONNECT_RSP: - l2c_csm_w4_l2ca_disconnect_rsp (p_ccb, event, p_data); - break; + l2c_csm_w4_l2ca_disconnect_rsp(p_ccb, event, p_data); + break; default: - L2CAP_TRACE_DEBUG("Unhandled event! event = %d",event); - break; - } + L2CAP_TRACE_DEBUG("Unhandled event! event = %d", event); + break; + } } /******************************************************************************* @@ -125,190 +128,204 @@ void l2c_csm_execute (tL2C_CCB *p_ccb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -static void l2c_csm_closed (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2C_CONN_INFO *p_ci = (tL2C_CONN_INFO *)p_data; - uint16_t local_cid = p_ccb->local_cid; - tL2CA_DISCONNECT_IND_CB *disconnect_ind; - tL2CA_CONNECT_CFM_CB *connect_cfm; - - if (p_ccb->p_rcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - LCID: 0x%04x st: CLOSED evt: %s p_rcb == NULL", p_ccb->local_cid, l2c_csm_get_event_name (event)); - return; - } +static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { + tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data; + uint16_t local_cid = p_ccb->local_cid; + tL2CA_DISCONNECT_IND_CB* disconnect_ind; + tL2CA_CONNECT_CFM_CB* connect_cfm; + + if (p_ccb->p_rcb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - LCID: 0x%04x st: CLOSED evt: %s p_rcb == NULL", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + return; + } #if (L2CAP_UCD_INCLUDED == TRUE) - if ( local_cid == L2CAP_CONNECTIONLESS_CID ) - { - /* check if this event can be processed by UCD */ - if ( l2c_ucd_process_event (p_ccb, event, p_data) ) - { - /* The event is processed by UCD state machine */ - return; - } + if (local_cid == L2CAP_CONNECTIONLESS_CID) { + /* check if this event can be processed by UCD */ + if (l2c_ucd_process_event(p_ccb, event, p_data)) { + /* The event is processed by UCD state machine */ + return; } + } #endif - disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: CLOSED evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - - case L2CEVT_LP_CONNECT_CFM: /* Link came up */ - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: CLOSED evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + + case L2CEVT_LP_CONNECT_CFM: /* Link came up */ + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; + l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, + true, &l2c_link_sec_comp, p_ccb); + } else { + p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; + btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, + p_ccb->p_rcb->psm, p_ccb->p_lcb->handle, true, + &l2c_link_sec_comp, p_ccb); + } + break; + + case L2CEVT_LP_CONNECT_CFM_NEG: /* Link failed */ + /* Disconnect unless ACL collision and upper layer wants to handle it */ + if (p_ci->status != HCI_ERR_CONNECTION_EXISTS || + !btm_acl_notif_conn_collision(p_ccb->p_lcb->remote_bd_addr)) { + L2CAP_TRACE_API( + "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", + p_ccb->local_cid, p_ci->status); + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, p_ci->status); + } + break; + + case L2CEVT_L2CA_CONNECT_REQ: /* API connect request */ + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; + l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, + true, &l2c_link_sec_comp, p_ccb); + } else { + /* Cancel sniff mode if needed */ { - p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; - l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, true, - &l2c_link_sec_comp, p_ccb); + tBTM_PM_PWR_MD settings; + memset((void*)&settings, 0, sizeof(settings)); + settings.mode = BTM_PM_MD_ACTIVE; + /* COVERITY + Event uninit_use_in_call: Using uninitialized value "settings" (field + "settings".timeout uninitialized) in call to function + "BTM_SetPowerMode" [details] + Event uninit_use_in_call: Using uninitialized value "settings.max" in + call to function "BTM_SetPowerMode" [details] + Event uninit_use_in_call: Using uninitialized value "settings.min" in + call to function "BTM_SetPowerMode" + // false-POSITIVE error from Coverity test-tool. Please do NOT remove + following comment. + // coverity[uninit_use_in_call] False-positive: setting the mode to + BTM_PM_MD_ACTIVE only uses settings.mode the other data members of + tBTM_PM_PWR_MD are ignored + */ + BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, + &settings); } - else - { - p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; - btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, - p_ccb->p_lcb->handle, true, &l2c_link_sec_comp, p_ccb); - } - break; - case L2CEVT_LP_CONNECT_CFM_NEG: /* Link failed */ - /* Disconnect unless ACL collision and upper layer wants to handle it */ - if (p_ci->status != HCI_ERR_CONNECTION_EXISTS - || !btm_acl_notif_conn_collision(p_ccb->p_lcb->remote_bd_addr)) - { - L2CAP_TRACE_API ("L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", p_ccb->local_cid, p_ci->status); - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, p_ci->status); - } - break; - - case L2CEVT_L2CA_CONNECT_REQ: /* API connect request */ - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; - l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, true, - &l2c_link_sec_comp, p_ccb); - } - else - { - /* Cancel sniff mode if needed */ - { - tBTM_PM_PWR_MD settings; - memset((void*)&settings, 0, sizeof(settings)); - settings.mode = BTM_PM_MD_ACTIVE; -/* COVERITY -Event uninit_use_in_call: Using uninitialized value "settings" (field "settings".timeout uninitialized) in call to function "BTM_SetPowerMode" [details] -Event uninit_use_in_call: Using uninitialized value "settings.max" in call to function "BTM_SetPowerMode" [details] -Event uninit_use_in_call: Using uninitialized value "settings.min" in call to function "BTM_SetPowerMode" -// false-POSITIVE error from Coverity test-tool. Please do NOT remove following comment. -// coverity[uninit_use_in_call] False-positive: setting the mode to BTM_PM_MD_ACTIVE only uses settings.mode the other data members of tBTM_PM_PWR_MD are ignored -*/ - BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, &settings); - } - - /* If sec access does not result in started SEC_COM or COMP_NEG are already processed */ - if (btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, - p_ccb->p_lcb->handle, true, &l2c_link_sec_comp, p_ccb) == BTM_CMD_STARTED) - p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; - } - break; + /* If sec access does not result in started SEC_COM or COMP_NEG are + * already processed */ + if (btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, + p_ccb->p_rcb->psm, p_ccb->p_lcb->handle, + true, &l2c_link_sec_comp, + p_ccb) == BTM_CMD_STARTED) + p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; + } + break; case L2CEVT_SEC_COMP: - p_ccb->chnl_state = CST_W4_L2CAP_CONNECT_RSP; + p_ccb->chnl_state = CST_W4_L2CAP_CONNECT_RSP; - /* Wait for the info resp in this state before sending connect req (if needed) */ - if (!p_ccb->p_lcb->w4_info_rsp) - { - /* Need to have at least one compatible channel to continue */ - if (!l2c_fcr_chk_chan_modes(p_ccb)) - { - l2cu_release_ccb (p_ccb); - (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, L2CAP_CONN_NO_LINK); - } - else - { - l2cu_send_peer_connect_req (p_ccb); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } + /* Wait for the info resp in this state before sending connect req (if + * needed) */ + if (!p_ccb->p_lcb->w4_info_rsp) { + /* Need to have at least one compatible channel to continue */ + if (!l2c_fcr_chk_chan_modes(p_ccb)) { + l2cu_release_ccb(p_ccb); + (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, + L2CAP_CONN_NO_LINK); + } else { + l2cu_send_peer_connect_req(p_ccb); + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); } - break; - - case L2CEVT_SEC_COMP_NEG: /* something is really bad with security */ - L2CAP_TRACE_API ("L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", p_ccb->local_cid, L2CAP_CONN_TIMEOUT); - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_SECURITY_BLOCK); - break; - - case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connect request */ - /* stop link timer to avoid race condition between A2MP, Security, and L2CAP */ - alarm_cancel(p_ccb->p_lcb->l2c_lcb_timer); - - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + } + break; + + case L2CEVT_SEC_COMP_NEG: /* something is really bad with security */ + L2CAP_TRACE_API( + "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", + p_ccb->local_cid, L2CAP_CONN_TIMEOUT); + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, L2CAP_CONN_SECURITY_BLOCK); + break; + + case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connect request */ + /* stop link timer to avoid race condition between A2MP, Security, and + * L2CAP */ + alarm_cancel(p_ccb->p_lcb->l2c_lcb_timer); + + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; + l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, + false, &l2c_link_sec_comp, p_ccb); + } else { + /* Cancel sniff mode if needed */ { - p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; - l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, false, - &l2c_link_sec_comp, p_ccb); + tBTM_PM_PWR_MD settings; + memset((void*)&settings, 0, sizeof(settings)); + settings.mode = BTM_PM_MD_ACTIVE; + /* COVERITY + Event uninit_use_in_call: Using uninitialized value "settings" (field + "settings".timeout uninitialized) in call to function + "BTM_SetPowerMode" [details] + Event uninit_use_in_call: Using uninitialized value "settings.max" in + call to function "BTM_SetPowerMode" [details] + Event uninit_use_in_call: Using uninitialized value "settings.min" in + call to function "BTM_SetPowerMode" + // false-POSITIVE error from Coverity test-tool. Please do NOT remove + following comment. + // coverity[uninit_use_in_call] False-positive: setting the mode to + BTM_PM_MD_ACTIVE only uses settings.mode the other data members of + tBTM_PM_PWR_MD are ignored + */ + BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, + &settings); } - else - { - /* Cancel sniff mode if needed */ - { - tBTM_PM_PWR_MD settings; - memset((void*)&settings, 0, sizeof(settings)); - settings.mode = BTM_PM_MD_ACTIVE; -/* COVERITY -Event uninit_use_in_call: Using uninitialized value "settings" (field "settings".timeout uninitialized) in call to function "BTM_SetPowerMode" [details] -Event uninit_use_in_call: Using uninitialized value "settings.max" in call to function "BTM_SetPowerMode" [details] -Event uninit_use_in_call: Using uninitialized value "settings.min" in call to function "BTM_SetPowerMode" -// false-POSITIVE error from Coverity test-tool. Please do NOT remove following comment. -// coverity[uninit_use_in_call] False-positive: setting the mode to BTM_PM_MD_ACTIVE only uses settings.mode the other data members of tBTM_PM_PWR_MD are ignored -*/ - BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, &settings); - } - - p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; - if (btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, - p_ccb->p_lcb->handle, false, &l2c_link_sec_comp, p_ccb) == BTM_CMD_STARTED) - { - /* started the security process, tell the peer to set a longer timer */ - l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_PENDING, 0); - } + + p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; + if (btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, + p_ccb->p_rcb->psm, p_ccb->p_lcb->handle, + false, &l2c_link_sec_comp, + p_ccb) == BTM_CMD_STARTED) { + /* started the security process, tell the peer to set a longer timer + */ + l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_PENDING, 0); } - break; + } + break; case L2CEVT_TIMEOUT: - L2CAP_TRACE_API ("L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", p_ccb->local_cid, L2CAP_CONN_TIMEOUT); - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - osi_free(p_data); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - l2cu_release_ccb (p_ccb); - break; + L2CAP_TRACE_API( + "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", + p_ccb->local_cid, L2CAP_CONN_TIMEOUT); + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + osi_free(p_data); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + l2cu_release_ccb(p_ccb); + break; case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: - osi_free(p_data); - break; - } + osi_free(p_data); + break; + } } - /******************************************************************************* * * Function l2c_csm_orig_w4_sec_comp @@ -319,110 +336,102 @@ Event uninit_use_in_call: Using uninitialized value "settings.min" in call to fu * Returns void * ******************************************************************************/ -static void l2c_csm_orig_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2CA_DISCONNECT_IND_CB *disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - tL2CA_CONNECT_CFM_CB *connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; - uint16_t local_cid = p_ccb->local_cid; +static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + tL2CA_DISCONNECT_IND_CB* disconnect_ind = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + tL2CA_CONNECT_CFM_CB* connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; + uint16_t local_cid = p_ccb->local_cid; - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: ORIG_W4_SEC_COMP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: ORIG_W4_SEC_COMP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); #if (L2CAP_UCD_INCLUDED == TRUE) - if ( local_cid == L2CAP_CONNECTIONLESS_CID ) - { - /* check if this event can be processed by UCD */ - if ( l2c_ucd_process_event (p_ccb, event, p_data) ) - { - /* The event is processed by UCD state machine */ - return; - } + if (local_cid == L2CAP_CONNECTIONLESS_CID) { + /* check if this event can be processed by UCD */ + if (l2c_ucd_process_event(p_ccb, event, p_data)) { + /* The event is processed by UCD state machine */ + return; } + } #endif - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - - case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ - case L2CEVT_LP_CONNECT_CFM: /* Link came up */ - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, false, - &l2c_link_sec_comp, p_ccb); - } - else - { - btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, - p_ccb->p_lcb->handle, true, &l2c_link_sec_comp, p_ccb); - } - break; - - case L2CEVT_SEC_COMP: /* Security completed success */ - /* Wait for the info resp in this state before sending connect req (if needed) */ - p_ccb->chnl_state = CST_W4_L2CAP_CONNECT_RSP; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - l2cble_credit_based_conn_req (p_ccb); /* Start Connection */ - } - else - { - if (!p_ccb->p_lcb->w4_info_rsp) - { - /* Need to have at least one compatible channel to continue */ - if (!l2c_fcr_chk_chan_modes(p_ccb)) - { - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); - } - else - { - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - l2cu_send_peer_connect_req (p_ccb); /* Start Connection */ - } - } + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + + case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ + case L2CEVT_LP_CONNECT_CFM: /* Link came up */ + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + l2ble_sec_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, + false, &l2c_link_sec_comp, p_ccb); + } else { + btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, + p_ccb->p_rcb->psm, p_ccb->p_lcb->handle, true, + &l2c_link_sec_comp, p_ccb); + } + break; + + case L2CEVT_SEC_COMP: /* Security completed success */ + /* Wait for the info resp in this state before sending connect req (if + * needed) */ + p_ccb->chnl_state = CST_W4_L2CAP_CONNECT_RSP; + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + l2cble_credit_based_conn_req(p_ccb); /* Start Connection */ + } else { + if (!p_ccb->p_lcb->w4_info_rsp) { + /* Need to have at least one compatible channel to continue */ + if (!l2c_fcr_chk_chan_modes(p_ccb)) { + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); + } else { + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + l2cu_send_peer_connect_req(p_ccb); /* Start Connection */ + } } - break; + } + break; case L2CEVT_SEC_COMP_NEG: - L2CAP_TRACE_API ("L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", p_ccb->local_cid, HCI_ERR_AUTH_FAILURE); - - /* If last channel immediately disconnect the ACL for better security. - Also prevents a race condition between BTM and L2CAP */ - if ( (p_ccb == p_ccb->p_lcb->ccb_queue.p_first_ccb) && (p_ccb == p_ccb->p_lcb->ccb_queue.p_last_ccb) ) - { - p_ccb->p_lcb->idle_timeout = 0; - } - - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, HCI_ERR_AUTH_FAILURE); - break; - - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - osi_free(p_data); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - /* Tell security manager to abort */ - btm_sec_abort_access_req (p_ccb->p_lcb->remote_bd_addr); - - l2cu_release_ccb (p_ccb); - break; - } + L2CAP_TRACE_API( + "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", + p_ccb->local_cid, HCI_ERR_AUTH_FAILURE); + + /* If last channel immediately disconnect the ACL for better security. + Also prevents a race condition between BTM and L2CAP */ + if ((p_ccb == p_ccb->p_lcb->ccb_queue.p_first_ccb) && + (p_ccb == p_ccb->p_lcb->ccb_queue.p_last_ccb)) { + p_ccb->p_lcb->idle_timeout = 0; + } + + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, HCI_ERR_AUTH_FAILURE); + break; + + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + osi_free(p_data); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + /* Tell security manager to abort */ + btm_sec_abort_access_req(p_ccb->p_lcb->remote_bd_addr); + + l2cu_release_ccb(p_ccb); + break; + } } - /******************************************************************************* * * Function l2c_csm_term_w4_sec_comp @@ -433,113 +442,109 @@ static void l2c_csm_orig_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_d * Returns void * ******************************************************************************/ -static void l2c_csm_term_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: TERM_W4_SEC_COMP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); +static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: TERM_W4_SEC_COMP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); #if (L2CAP_UCD_INCLUDED == TRUE) - if ( p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) - { - /* check if this event can be processed by UCD */ - if ( l2c_ucd_process_event (p_ccb, event, p_data) ) - { - /* The event is processed by UCD state machine */ - return; - } + if (p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) { + /* check if this event can be processed by UCD */ + if (l2c_ucd_process_event(p_ccb, event, p_data)) { + /* The event is processed by UCD state machine */ + return; } + } #endif - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - /* Tell security manager to abort */ - btm_sec_abort_access_req (p_ccb->p_lcb->remote_bd_addr); + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + /* Tell security manager to abort */ + btm_sec_abort_access_req(p_ccb->p_lcb->remote_bd_addr); - l2cu_release_ccb (p_ccb); - break; + l2cu_release_ccb(p_ccb); + break; case L2CEVT_SEC_COMP: - p_ccb->chnl_state = CST_W4_L2CA_CONNECT_RSP; + p_ccb->chnl_state = CST_W4_L2CA_CONNECT_RSP; - /* Wait for the info resp in next state before sending connect ind (if needed) */ - if (!p_ccb->p_lcb->w4_info_rsp) - { - /* Don't need to get info from peer or already retrieved so continue */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - L2CAP_TRACE_API ("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", p_ccb->local_cid); - - (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb) (p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, - p_ccb->p_rcb->psm, p_ccb->remote_id); - } - else - { - /* - ** L2CAP Connect Response will be sent out by 3 sec timer expiration - ** because Bluesoleil doesn't respond to L2CAP Information Request. - ** Bluesoleil seems to disconnect ACL link as failure case, because - ** it takes too long (4~7secs) to get response. - ** product version : Bluesoleil 2.1.1.0 EDR Release 060123 - ** stack version : 05.04.11.20060119 - */ - - /* Waiting for the info resp, tell the peer to set a longer timer */ - l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_PENDING, 0); - } - break; + /* Wait for the info resp in next state before sending connect ind (if + * needed) */ + if (!p_ccb->p_lcb->w4_info_rsp) { + /* Don't need to get info from peer or already retrieved so continue */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + L2CAP_TRACE_API("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", + p_ccb->local_cid); + + (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)( + p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm, + p_ccb->remote_id); + } else { + /* + ** L2CAP Connect Response will be sent out by 3 sec timer expiration + ** because Bluesoleil doesn't respond to L2CAP Information Request. + ** Bluesoleil seems to disconnect ACL link as failure case, because + ** it takes too long (4~7secs) to get response. + ** product version : Bluesoleil 2.1.1.0 EDR Release 060123 + ** stack version : 05.04.11.20060119 + */ + + /* Waiting for the info resp, tell the peer to set a longer timer */ + l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_PENDING, 0); + } + break; case L2CEVT_SEC_COMP_NEG: - if (((tL2C_CONN_INFO *)p_data)->status == BTM_DELAY_CHECK) - { - /* start a timer - encryption change not received before L2CAP connect req */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } + if (((tL2C_CONN_INFO*)p_data)->status == BTM_DELAY_CHECK) { + /* start a timer - encryption change not received before L2CAP connect + * req */ + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + } else { + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + l2cu_reject_ble_connection(p_ccb->p_lcb, p_ccb->remote_id, + L2CAP_LE_INSUFFICIENT_AUTHENTICATION); else - { - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - l2cu_reject_ble_connection(p_ccb->p_lcb, p_ccb->remote_id, L2CAP_LE_INSUFFICIENT_AUTHENTICATION); - else - l2cu_send_peer_connect_rsp (p_ccb, L2CAP_CONN_SECURITY_BLOCK, 0); - l2cu_release_ccb (p_ccb); - } - break; + l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_SECURITY_BLOCK, 0); + l2cu_release_ccb(p_ccb); + } + break; - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - osi_free(p_data); - break; + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + osi_free(p_data); + break; - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - l2cu_release_ccb (p_ccb); - break; + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + l2cu_release_ccb(p_ccb); + break; - case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ - l2cu_send_peer_disc_rsp (p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, p_ccb->remote_cid); + case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ + l2cu_send_peer_disc_rsp(p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, + p_ccb->remote_cid); - /* Tell security manager to abort */ - btm_sec_abort_access_req (p_ccb->p_lcb->remote_bd_addr); + /* Tell security manager to abort */ + btm_sec_abort_access_req(p_ccb->p_lcb->remote_bd_addr); - l2cu_release_ccb (p_ccb); - break; + l2cu_release_ccb(p_ccb); + break; case L2CEVT_TIMEOUT: - /* SM4 related. */ - btsnd_hcic_disconnect(p_ccb->p_lcb->handle, HCI_ERR_AUTH_FAILURE); - break; - - case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ - btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, - p_ccb->p_lcb->handle, false, &l2c_link_sec_comp, p_ccb); - break; - } + /* SM4 related. */ + btsnd_hcic_disconnect(p_ccb->p_lcb->handle, HCI_ERR_AUTH_FAILURE); + break; + + case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ + btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, p_ccb->p_rcb->psm, + p_ccb->p_lcb->handle, false, &l2c_link_sec_comp, + p_ccb); + break; + } } - /******************************************************************************* * * Function l2c_csm_w4_l2cap_connect_rsp @@ -550,130 +555,126 @@ static void l2c_csm_term_w4_sec_comp (tL2C_CCB *p_ccb, uint16_t event, void *p_d * Returns void * ******************************************************************************/ -static void l2c_csm_w4_l2cap_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2C_CONN_INFO *p_ci = (tL2C_CONN_INFO *)p_data; - tL2CA_DISCONNECT_IND_CB *disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - tL2CA_CONNECT_CFM_CB *connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; - uint16_t local_cid = p_ccb->local_cid; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: W4_L2CAP_CON_RSP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - /* Send disc indication unless peer to peer race condition AND normal disconnect */ - /* *((uint8_t *)p_data) != HCI_ERR_PEER_USER happens when peer device try to disconnect for normal reason */ - p_ccb->chnl_state = CST_CLOSED; - if ((p_ccb->flags & CCB_FLAG_NO_RETRY) || !p_data || (*((uint8_t *)p_data) != HCI_ERR_PEER_USER)) - { - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", - p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - } - p_ccb->flags |= CCB_FLAG_NO_RETRY; - break; - - case L2CEVT_L2CAP_CONNECT_RSP: /* Got peer connect confirm */ - p_ccb->remote_cid = p_ci->remote_cid; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - /* Connection is completed */ - alarm_cancel(p_ccb->l2c_ccb_timer); - p_ccb->chnl_state = CST_OPEN; - } - else - { - p_ccb->chnl_state = CST_CONFIG; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - L2CAP_TRACE_API ("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Success", p_ccb->local_cid); - - (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, L2CAP_CONN_OK); - break; - - case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Got peer connect pending */ - p_ccb->remote_cid = p_ci->remote_cid; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS, +static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data; + tL2CA_DISCONNECT_IND_CB* disconnect_ind = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + tL2CA_CONNECT_CFM_CB* connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; + uint16_t local_cid = p_ccb->local_cid; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: W4_L2CAP_CON_RSP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + /* Send disc indication unless peer to peer race condition AND normal + * disconnect */ + /* *((uint8_t *)p_data) != HCI_ERR_PEER_USER happens when peer device try + * to disconnect for normal reason */ + p_ccb->chnl_state = CST_CLOSED; + if ((p_ccb->flags & CCB_FLAG_NO_RETRY) || !p_data || + (*((uint8_t*)p_data) != HCI_ERR_PEER_USER)) { + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + } + p_ccb->flags |= CCB_FLAG_NO_RETRY; + break; + + case L2CEVT_L2CAP_CONNECT_RSP: /* Got peer connect confirm */ + p_ccb->remote_cid = p_ci->remote_cid; + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + /* Connection is completed */ + alarm_cancel(p_ccb->l2c_ccb_timer); + p_ccb->chnl_state = CST_OPEN; + } else { + p_ccb->chnl_state = CST_CONFIG; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); - if (p_ccb->p_rcb->api.pL2CA_ConnectPnd_Cb) - { - L2CAP_TRACE_API ("L2CAP - Calling Connect_Pnd_Cb(), CID: 0x%04x", p_ccb->local_cid); - (*p_ccb->p_rcb->api.pL2CA_ConnectPnd_Cb)(p_ccb->local_cid); - } - break; - - case L2CEVT_L2CAP_CONNECT_RSP_NEG: /* Peer rejected connection */ - L2CAP_TRACE_API ("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Failure Code: %d", p_ccb->local_cid, p_ci->l2cap_result); - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, p_ci->l2cap_result); - break; + } + L2CAP_TRACE_API("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Success", + p_ccb->local_cid); + + (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, L2CAP_CONN_OK); + break; + + case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Got peer connect pending */ + p_ccb->remote_cid = p_ci->remote_cid; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, + L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + if (p_ccb->p_rcb->api.pL2CA_ConnectPnd_Cb) { + L2CAP_TRACE_API("L2CAP - Calling Connect_Pnd_Cb(), CID: 0x%04x", + p_ccb->local_cid); + (*p_ccb->p_rcb->api.pL2CA_ConnectPnd_Cb)(p_ccb->local_cid); + } + break; + + case L2CEVT_L2CAP_CONNECT_RSP_NEG: /* Peer rejected connection */ + L2CAP_TRACE_API( + "L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Failure Code: %d", + p_ccb->local_cid, p_ci->l2cap_result); + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, p_ci->l2cap_result); + break; case L2CEVT_TIMEOUT: - L2CAP_TRACE_API ("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Timeout", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - /* If we know peer CID from connect pending, we can send disconnect */ - if (p_ccb->remote_cid != 0) - { - l2cu_send_peer_disc_req (p_ccb); - p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else - { - tL2CA_DISCONNECT_CFM_CB *disconnect_cfm = p_ccb->p_rcb->api.pL2CA_DisconnectCfm_Cb; - l2cu_release_ccb(p_ccb); - if (disconnect_cfm) - { - L2CAP_TRACE_API("%s: L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", __func__, local_cid); - (*disconnect_cfm)(local_cid, L2CAP_CONN_NO_LINK); - } + L2CAP_TRACE_API("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Timeout", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + /* If we know peer CID from connect pending, we can send disconnect */ + if (p_ccb->remote_cid != 0) { + l2cu_send_peer_disc_req(p_ccb); + p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + } else { + tL2CA_DISCONNECT_CFM_CB* disconnect_cfm = + p_ccb->p_rcb->api.pL2CA_DisconnectCfm_Cb; + l2cu_release_ccb(p_ccb); + if (disconnect_cfm) { + L2CAP_TRACE_API("%s: L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", + __func__, local_cid); + (*disconnect_cfm)(local_cid, L2CAP_CONN_NO_LINK); } - break; + } + break; - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - osi_free(p_data); - break; + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + osi_free(p_data); + break; case L2CEVT_L2CAP_INFO_RSP: - /* Need to have at least one compatible channel to continue */ - if (!l2c_fcr_chk_chan_modes(p_ccb)) - { - l2cu_release_ccb (p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); - } - else - { - /* We have feature info, so now send peer connect request */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - l2cu_send_peer_connect_req (p_ccb); /* Start Connection */ - } - break; + /* Need to have at least one compatible channel to continue */ + if (!l2c_fcr_chk_chan_modes(p_ccb)) { + l2cu_release_ccb(p_ccb); + (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); + } else { + /* We have feature info, so now send peer connect request */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + l2cu_send_peer_connect_req(p_ccb); /* Start Connection */ + } + break; case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: - osi_free(p_data); - break; - } + osi_free(p_data); + break; + } } - /******************************************************************************* * * Function l2c_csm_w4_l2ca_connect_rsp @@ -684,110 +685,101 @@ static void l2c_csm_w4_l2cap_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void * Returns void * ******************************************************************************/ -static void l2c_csm_w4_l2ca_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2C_CONN_INFO *p_ci; - tL2CA_DISCONNECT_IND_CB *disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - uint16_t local_cid = p_ccb->local_cid; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: W4_L2CA_CON_RSP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; +static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + tL2C_CONN_INFO* p_ci; + tL2CA_DISCONNECT_IND_CB* disconnect_ind = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + uint16_t local_cid = p_ccb->local_cid; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: W4_L2CA_CON_RSP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; case L2CEVT_L2CA_CONNECT_RSP: - p_ci = (tL2C_CONN_INFO *)p_data; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - /* Result should be OK or Reject */ - if ((!p_ci) || (p_ci->l2cap_result == L2CAP_CONN_OK)) - { - l2cble_credit_based_conn_res (p_ccb, L2CAP_CONN_OK); - p_ccb->chnl_state = CST_OPEN; - alarm_cancel(p_ccb->l2c_ccb_timer); - } - else - { - l2cble_credit_based_conn_res (p_ccb, p_ci->l2cap_result); - l2cu_release_ccb (p_ccb); - } + p_ci = (tL2C_CONN_INFO*)p_data; + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + /* Result should be OK or Reject */ + if ((!p_ci) || (p_ci->l2cap_result == L2CAP_CONN_OK)) { + l2cble_credit_based_conn_res(p_ccb, L2CAP_CONN_OK); + p_ccb->chnl_state = CST_OPEN; + alarm_cancel(p_ccb->l2c_ccb_timer); + } else { + l2cble_credit_based_conn_res(p_ccb, p_ci->l2cap_result); + l2cu_release_ccb(p_ccb); } - else - { - /* Result should be OK or PENDING */ - if ((!p_ci) || (p_ci->l2cap_result == L2CAP_CONN_OK)) - { - l2cu_send_peer_connect_rsp (p_ccb, L2CAP_CONN_OK, 0); - p_ccb->chnl_state = CST_CONFIG; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else - { - /* If pending, stay in same state and start extended timer */ - l2cu_send_peer_connect_rsp (p_ccb, p_ci->l2cap_result, p_ci->l2cap_status); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } + } else { + /* Result should be OK or PENDING */ + if ((!p_ci) || (p_ci->l2cap_result == L2CAP_CONN_OK)) { + l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_OK, 0); + p_ccb->chnl_state = CST_CONFIG; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + } else { + /* If pending, stay in same state and start extended timer */ + l2cu_send_peer_connect_rsp(p_ccb, p_ci->l2cap_result, + p_ci->l2cap_status); + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); } - break; + } + break; case L2CEVT_L2CA_CONNECT_RSP_NEG: - p_ci = (tL2C_CONN_INFO *)p_data; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - l2cble_credit_based_conn_res (p_ccb, p_ci->l2cap_result); - else - l2cu_send_peer_connect_rsp (p_ccb, p_ci->l2cap_result, p_ci->l2cap_status); - l2cu_release_ccb (p_ccb); - break; + p_ci = (tL2C_CONN_INFO*)p_data; + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + l2cble_credit_based_conn_res(p_ccb, p_ci->l2cap_result); + else + l2cu_send_peer_connect_rsp(p_ccb, p_ci->l2cap_result, + p_ci->l2cap_status); + l2cu_release_ccb(p_ccb); + break; case L2CEVT_TIMEOUT: - l2cu_send_peer_connect_rsp (p_ccb, L2CAP_CONN_NO_PSM, 0); - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - osi_free(p_data); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - l2cu_send_peer_disc_req (p_ccb); - p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; + l2cu_send_peer_connect_rsp(p_ccb, L2CAP_CONN_NO_PSM, 0); + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + osi_free(p_data); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + l2cu_send_peer_disc_req(p_ccb); + p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; case L2CEVT_L2CAP_INFO_RSP: - /* We have feature info, so now give the upper layer connect IND */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - L2CAP_TRACE_API ("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", p_ccb->local_cid); - - (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb) (p_ccb->p_lcb->remote_bd_addr, - p_ccb->local_cid, - p_ccb->p_rcb->psm, - p_ccb->remote_id); - break; - } + /* We have feature info, so now give the upper layer connect IND */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + L2CAP_TRACE_API("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", + p_ccb->local_cid); + + (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)( + p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm, + p_ccb->remote_id); + break; + } } - /******************************************************************************* * * Function l2c_csm_config @@ -798,243 +790,242 @@ static void l2c_csm_w4_l2ca_connect_rsp (tL2C_CCB *p_ccb, uint16_t event, void * * Returns void * ******************************************************************************/ -static void l2c_csm_config (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2CAP_CFG_INFO *p_cfg = (tL2CAP_CFG_INFO *)p_data; - tL2CA_DISCONNECT_IND_CB *disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - uint16_t local_cid = p_ccb->local_cid; - uint8_t cfg_result; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: CONFIG evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - - case L2CEVT_L2CAP_CONFIG_REQ: /* Peer config request */ - - cfg_result = l2cu_process_peer_cfg_req(p_ccb, p_cfg); - if (cfg_result == L2CAP_PEER_CFG_OK) - { - L2CAP_TRACE_EVENT ("L2CAP - Calling Config_Req_Cb(), CID: 0x%04x, C-bit %d", - p_ccb->local_cid, (p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT)); - (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); - } - else if (cfg_result == L2CAP_PEER_CFG_DISCONNECT) - { - /* Disconnect if channels are incompatible */ - L2CAP_TRACE_EVENT ("L2CAP - incompatible configurations disconnect"); - l2cu_disconnect_chnl (p_ccb); - } - else /* Return error to peer so he can renegotiate if possible */ - { - L2CAP_TRACE_EVENT ("L2CAP - incompatible configurations trying reconfig"); - l2cu_send_peer_config_rsp (p_ccb, p_cfg); - } - break; - - case L2CEVT_L2CAP_CONFIG_RSP: /* Peer config response */ - l2cu_process_peer_cfg_rsp (p_ccb, p_cfg); - - if (p_cfg->result != L2CAP_CFG_PENDING) - { - /* TBD: When config options grow beyong minimum MTU (48 bytes) - * logic needs to be added to handle responses with - * continuation bit set in flags field. - * 1. Send additional config request out until C-bit is cleared in response - */ - p_ccb->config_done |= OB_CFG_DONE; - - if (p_ccb->config_done & IB_CFG_DONE) - { - /* Verify two sides are in compatible modes before continuing */ - if (p_ccb->our_cfg.fcr.mode != p_ccb->peer_cfg.fcr.mode) - { - l2cu_send_peer_disc_req (p_ccb); - L2CAP_TRACE_WARNING ("L2CAP - Calling Disconnect_Ind_Cb(Incompatible CFG), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - } - - p_ccb->config_done |= RECONFIG_FLAG; - p_ccb->chnl_state = CST_OPEN; - l2c_link_adjust_chnl_allocation (); - alarm_cancel(p_ccb->l2c_ccb_timer); - - /* If using eRTM and waiting for an ACK, restart the ACK timer */ - if (p_ccb->fcrb.wait_ack) - l2c_fcr_start_timer(p_ccb); - - /* - ** check p_ccb->our_cfg.fcr.mon_tout and p_ccb->our_cfg.fcr.rtrans_tout - ** we may set them to zero when sending config request during renegotiation - */ - if ((p_ccb->our_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - &&((p_ccb->our_cfg.fcr.mon_tout == 0)||(p_ccb->our_cfg.fcr.rtrans_tout))) - { - l2c_fcr_adj_monitor_retran_timeout (p_ccb); - } +static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { + tL2CAP_CFG_INFO* p_cfg = (tL2CAP_CFG_INFO*)p_data; + tL2CA_DISCONNECT_IND_CB* disconnect_ind = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + uint16_t local_cid = p_ccb->local_cid; + uint8_t cfg_result; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: CONFIG evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + + case L2CEVT_L2CAP_CONFIG_REQ: /* Peer config request */ + + cfg_result = l2cu_process_peer_cfg_req(p_ccb, p_cfg); + if (cfg_result == L2CAP_PEER_CFG_OK) { + L2CAP_TRACE_EVENT( + "L2CAP - Calling Config_Req_Cb(), CID: 0x%04x, C-bit %d", + p_ccb->local_cid, (p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT)); + (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); + } else if (cfg_result == L2CAP_PEER_CFG_DISCONNECT) { + /* Disconnect if channels are incompatible */ + L2CAP_TRACE_EVENT("L2CAP - incompatible configurations disconnect"); + l2cu_disconnect_chnl(p_ccb); + } else /* Return error to peer so he can renegotiate if possible */ + { + L2CAP_TRACE_EVENT( + "L2CAP - incompatible configurations trying reconfig"); + l2cu_send_peer_config_rsp(p_ccb, p_cfg); + } + break; + + case L2CEVT_L2CAP_CONFIG_RSP: /* Peer config response */ + l2cu_process_peer_cfg_rsp(p_ccb, p_cfg); + + if (p_cfg->result != L2CAP_CFG_PENDING) { + /* TBD: When config options grow beyong minimum MTU (48 bytes) + * logic needs to be added to handle responses with + * continuation bit set in flags field. + * 1. Send additional config request out until C-bit is cleared in + * response + */ + p_ccb->config_done |= OB_CFG_DONE; + + if (p_ccb->config_done & IB_CFG_DONE) { + /* Verify two sides are in compatible modes before continuing */ + if (p_ccb->our_cfg.fcr.mode != p_ccb->peer_cfg.fcr.mode) { + l2cu_send_peer_disc_req(p_ccb); + L2CAP_TRACE_WARNING( + "L2CAP - Calling Disconnect_Ind_Cb(Incompatible CFG), CID: " + "0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + } + + p_ccb->config_done |= RECONFIG_FLAG; + p_ccb->chnl_state = CST_OPEN; + l2c_link_adjust_chnl_allocation(); + alarm_cancel(p_ccb->l2c_ccb_timer); + + /* If using eRTM and waiting for an ACK, restart the ACK timer */ + if (p_ccb->fcrb.wait_ack) l2c_fcr_start_timer(p_ccb); + + /* + ** check p_ccb->our_cfg.fcr.mon_tout and + *p_ccb->our_cfg.fcr.rtrans_tout + ** we may set them to zero when sending config request during + *renegotiation + */ + if ((p_ccb->our_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && + ((p_ccb->our_cfg.fcr.mon_tout == 0) || + (p_ccb->our_cfg.fcr.rtrans_tout))) { + l2c_fcr_adj_monitor_retran_timeout(p_ccb); + } #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms(); + p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms(); #endif - /* See if we can forward anything on the hold queue */ - if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) - { - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - } - } + /* See if we can forward anything on the hold queue */ + if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) { + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + } } - - L2CAP_TRACE_API ("L2CAP - Calling Config_Rsp_Cb(), CID: 0x%04x", p_ccb->local_cid); + } + + L2CAP_TRACE_API("L2CAP - Calling Config_Rsp_Cb(), CID: 0x%04x", + p_ccb->local_cid); + (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid, p_cfg); + break; + + case L2CEVT_L2CAP_CONFIG_RSP_NEG: /* Peer config error rsp */ + /* Disable the Timer */ + alarm_cancel(p_ccb->l2c_ccb_timer); + + /* If failure was channel mode try to renegotiate */ + if (l2c_fcr_renegotiate_chan(p_ccb, p_cfg) == false) { + L2CAP_TRACE_API( + "L2CAP - Calling Config_Rsp_Cb(), CID: 0x%04x, Failure: %d", + p_ccb->local_cid, p_cfg->result); (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid, p_cfg); - break; - - case L2CEVT_L2CAP_CONFIG_RSP_NEG: /* Peer config error rsp */ - /* Disable the Timer */ - alarm_cancel(p_ccb->l2c_ccb_timer); - - /* If failure was channel mode try to renegotiate */ - if (l2c_fcr_renegotiate_chan(p_ccb, p_cfg) == false) - { - L2CAP_TRACE_API ("L2CAP - Calling Config_Rsp_Cb(), CID: 0x%04x, Failure: %d", p_ccb->local_cid, p_cfg->result); - (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid, p_cfg); - } - break; - - case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP; - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", p_ccb->local_cid); - (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, true); - break; - - case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config req */ - l2cu_process_our_cfg_req (p_ccb, p_cfg); - l2cu_send_peer_config_req (p_ccb, p_cfg); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; - - case L2CEVT_L2CA_CONFIG_RSP: /* Upper layer config rsp */ - l2cu_process_our_cfg_rsp (p_ccb, p_cfg); - - /* Not finished if continuation flag is set */ - if ( (p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT) || (p_cfg->result == L2CAP_CFG_PENDING) ) - { - /* Send intermediate response; remain in cfg state */ - l2cu_send_peer_config_rsp (p_ccb, p_cfg); - break; + } + break; + + case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP; + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", + p_ccb->local_cid); + (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, true); + break; + + case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config req */ + l2cu_process_our_cfg_req(p_ccb, p_cfg); + l2cu_send_peer_config_req(p_ccb, p_cfg); + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; + + case L2CEVT_L2CA_CONFIG_RSP: /* Upper layer config rsp */ + l2cu_process_our_cfg_rsp(p_ccb, p_cfg); + + /* Not finished if continuation flag is set */ + if ((p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT) || + (p_cfg->result == L2CAP_CFG_PENDING)) { + /* Send intermediate response; remain in cfg state */ + l2cu_send_peer_config_rsp(p_ccb, p_cfg); + break; + } + + /* Local config done; clear cached configuration in case reconfig takes + * place later */ + p_ccb->peer_cfg.mtu_present = false; + p_ccb->peer_cfg.flush_to_present = false; + p_ccb->peer_cfg.qos_present = false; + + p_ccb->config_done |= IB_CFG_DONE; + + if (p_ccb->config_done & OB_CFG_DONE) { + /* Verify two sides are in compatible modes before continuing */ + if (p_ccb->our_cfg.fcr.mode != p_ccb->peer_cfg.fcr.mode) { + l2cu_send_peer_disc_req(p_ccb); + L2CAP_TRACE_WARNING( + "L2CAP - Calling Disconnect_Ind_Cb(Incompatible CFG), CID: " + "0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; } - /* Local config done; clear cached configuration in case reconfig takes place later */ - p_ccb->peer_cfg.mtu_present = false; - p_ccb->peer_cfg.flush_to_present = false; - p_ccb->peer_cfg.qos_present = false; + p_ccb->config_done |= RECONFIG_FLAG; + p_ccb->chnl_state = CST_OPEN; + l2c_link_adjust_chnl_allocation(); + alarm_cancel(p_ccb->l2c_ccb_timer); + } - p_ccb->config_done |= IB_CFG_DONE; + l2cu_send_peer_config_rsp(p_ccb, p_cfg); - if (p_ccb->config_done & OB_CFG_DONE) - { - /* Verify two sides are in compatible modes before continuing */ - if (p_ccb->our_cfg.fcr.mode != p_ccb->peer_cfg.fcr.mode) - { - l2cu_send_peer_disc_req (p_ccb); - L2CAP_TRACE_WARNING ("L2CAP - Calling Disconnect_Ind_Cb(Incompatible CFG), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - } - - p_ccb->config_done |= RECONFIG_FLAG; - p_ccb->chnl_state = CST_OPEN; - l2c_link_adjust_chnl_allocation (); - alarm_cancel(p_ccb->l2c_ccb_timer); - } - - l2cu_send_peer_config_rsp (p_ccb, p_cfg); - - /* If using eRTM and waiting for an ACK, restart the ACK timer */ - if (p_ccb->fcrb.wait_ack) - l2c_fcr_start_timer(p_ccb); + /* If using eRTM and waiting for an ACK, restart the ACK timer */ + if (p_ccb->fcrb.wait_ack) l2c_fcr_start_timer(p_ccb); #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms(); + p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms(); #endif - /* See if we can forward anything on the hold queue */ - if ( (p_ccb->chnl_state == CST_OPEN) && - (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) - { - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - } - break; - - case L2CEVT_L2CA_CONFIG_RSP_NEG: /* Upper layer config reject */ - l2cu_send_peer_config_rsp (p_ccb, p_cfg); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - l2cu_send_peer_disc_req (p_ccb); - p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - L2CAP_TRACE_API ("L2CAP - Calling DataInd_Cb(), CID: 0x%04x", p_ccb->local_cid); + /* See if we can forward anything on the hold queue */ + if ((p_ccb->chnl_state == CST_OPEN) && + (!fixed_queue_is_empty(p_ccb->xmit_hold_q))) { + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + } + break; + + case L2CEVT_L2CA_CONFIG_RSP_NEG: /* Upper layer config reject */ + l2cu_send_peer_config_rsp(p_ccb, p_cfg); + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + l2cu_send_peer_disc_req(p_ccb); + p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + L2CAP_TRACE_API("L2CAP - Calling DataInd_Cb(), CID: 0x%04x", + p_ccb->local_cid); #if (L2CAP_NUM_FIXED_CHNLS > 0) - if (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL && - p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL) - { - if (p_ccb->local_cid < L2CAP_BASE_APPL_CID) - { - if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb) - (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb) - (p_ccb->local_cid, p_ccb->p_lcb->remote_bd_addr,(BT_HDR *)p_data); - else - osi_free(p_data); - break; - } + if (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL && + p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL) { + if (p_ccb->local_cid < L2CAP_BASE_APPL_CID) { + if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL] + .pL2CA_FixedData_Cb) + (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL] + .pL2CA_FixedData_Cb)(p_ccb->local_cid, + p_ccb->p_lcb->remote_bd_addr, + (BT_HDR*)p_data); + else + osi_free(p_data); + break; } + } #endif - (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR *)p_data); - break; + (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR*)p_data); + break; - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - if (p_ccb->config_done & OB_CFG_DONE) - l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_data); - else - osi_free(p_data); - break; + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + if (p_ccb->config_done & OB_CFG_DONE) + l2c_enqueue_peer_data(p_ccb, (BT_HDR*)p_data); + else + osi_free(p_data); + break; case L2CEVT_TIMEOUT: - l2cu_send_peer_disc_req (p_ccb); - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", - p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - } + l2cu_send_peer_disc_req(p_ccb); + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + } } - /******************************************************************************* * * Function l2c_csm_open @@ -1045,185 +1036,172 @@ static void l2c_csm_config (tL2C_CCB *p_ccb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -static void l2c_csm_open (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - uint16_t local_cid = p_ccb->local_cid; - tL2CAP_CFG_INFO *p_cfg; - tL2C_CHNL_STATE tempstate; - uint8_t tempcfgdone; - uint8_t cfg_result; - uint16_t *credit; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: OPEN evt: %s", - p_ccb->local_cid, l2c_csm_get_event_name (event)); +static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { + uint16_t local_cid = p_ccb->local_cid; + tL2CAP_CFG_INFO* p_cfg; + tL2C_CHNL_STATE tempstate; + uint8_t tempcfgdone; + uint8_t cfg_result; + uint16_t* credit; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: OPEN evt: %s", p_ccb->local_cid, + l2c_csm_get_event_name(event)); #if (L2CAP_UCD_INCLUDED == TRUE) - if ( local_cid == L2CAP_CONNECTIONLESS_CID ) - { - /* check if this event can be processed by UCD */ - if ( l2c_ucd_process_event (p_ccb, event, p_data) ) - { - /* The event is processed by UCD state machine */ - return; - } + if (local_cid == L2CAP_CONNECTIONLESS_CID) { + /* check if this event can be processed by UCD */ + if (l2c_ucd_process_event(p_ccb, event, p_data)) { + /* The event is processed by UCD state machine */ + return; } + } #endif - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", - p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - if (p_ccb->p_rcb) - (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(local_cid, false); - break; - - case L2CEVT_LP_QOS_VIOLATION_IND: /* QOS violation */ - /* Tell upper layer. If service guaranteed, then clear the channel */ - if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) - (*p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb)(p_ccb->p_lcb->remote_bd_addr); - break; - - case L2CEVT_L2CAP_CONFIG_REQ: /* Peer config request */ - p_cfg = (tL2CAP_CFG_INFO *)p_data; - - tempstate = p_ccb->chnl_state; - tempcfgdone = p_ccb->config_done; - p_ccb->chnl_state = CST_CONFIG; - p_ccb->config_done &= ~CFG_DONE_MASK; - - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - - cfg_result = l2cu_process_peer_cfg_req(p_ccb, p_cfg); - if (cfg_result == L2CAP_PEER_CFG_OK) - { - (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); - } - - /* Error in config parameters: reset state and config flag */ - else if (cfg_result == L2CAP_PEER_CFG_UNACCEPTABLE) - { - alarm_cancel(p_ccb->l2c_ccb_timer); - p_ccb->chnl_state = tempstate; - p_ccb->config_done = tempcfgdone; - l2cu_send_peer_config_rsp (p_ccb, p_cfg); - } - else /* L2CAP_PEER_CFG_DISCONNECT */ + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + if (p_ccb->p_rcb) + (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(local_cid, false); + break; + + case L2CEVT_LP_QOS_VIOLATION_IND: /* QOS violation */ + /* Tell upper layer. If service guaranteed, then clear the channel */ + if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) + (*p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb)( + p_ccb->p_lcb->remote_bd_addr); + break; + + case L2CEVT_L2CAP_CONFIG_REQ: /* Peer config request */ + p_cfg = (tL2CAP_CFG_INFO*)p_data; + + tempstate = p_ccb->chnl_state; + tempcfgdone = p_ccb->config_done; + p_ccb->chnl_state = CST_CONFIG; + p_ccb->config_done &= ~CFG_DONE_MASK; + + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + + cfg_result = l2cu_process_peer_cfg_req(p_ccb, p_cfg); + if (cfg_result == L2CAP_PEER_CFG_OK) { + (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); + } + + /* Error in config parameters: reset state and config flag */ + else if (cfg_result == L2CAP_PEER_CFG_UNACCEPTABLE) { + alarm_cancel(p_ccb->l2c_ccb_timer); + p_ccb->chnl_state = tempstate; + p_ccb->config_done = tempcfgdone; + l2cu_send_peer_config_rsp(p_ccb, p_cfg); + } else /* L2CAP_PEER_CFG_DISCONNECT */ + { + /* Disconnect if channels are incompatible + * Note this should not occur if reconfigure + * since this should have never passed original config. + */ + l2cu_disconnect_chnl(p_ccb); + } + break; + + case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ + if (p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { + /* Make sure we are not in sniff mode */ { - /* Disconnect if channels are incompatible - * Note this should not occur if reconfigure - * since this should have never passed original config. - */ - l2cu_disconnect_chnl (p_ccb); + tBTM_PM_PWR_MD settings; + memset((void*)&settings, 0, sizeof(settings)); + settings.mode = BTM_PM_MD_ACTIVE; + BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, + &settings); } - break; - - case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */ - if (p_ccb->p_lcb->transport != BT_TRANSPORT_LE) - { + } + + p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", + p_ccb->local_cid); + (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, true); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb)) + (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, + (BT_HDR*)p_data); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ + if (p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { /* Make sure we are not in sniff mode */ - { - tBTM_PM_PWR_MD settings; - memset((void*)&settings, 0, sizeof(settings)); - settings.mode = BTM_PM_MD_ACTIVE; - BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, &settings); - } - } - - p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", p_ccb->local_cid); - (*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, true); - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_DataInd_Cb)) - (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR *)p_data); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ - if (p_ccb->p_lcb->transport != BT_TRANSPORT_LE) { - /* Make sure we are not in sniff mode */ - { - tBTM_PM_PWR_MD settings; - memset((void*)&settings, 0, sizeof(settings)); - settings.mode = BTM_PM_MD_ACTIVE; - BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, &settings); - } + tBTM_PM_PWR_MD settings; + memset((void*)&settings, 0, sizeof(settings)); + settings.mode = BTM_PM_MD_ACTIVE; + BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p_ccb->p_lcb->remote_bd_addr, + &settings); } - - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - l2cble_send_peer_disc_req (p_ccb); - else - l2cu_send_peer_disc_req (p_ccb); - - p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; - - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_data); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - break; - - case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config req */ - p_ccb->chnl_state = CST_CONFIG; - p_ccb->config_done &= ~CFG_DONE_MASK; - l2cu_process_our_cfg_req (p_ccb, (tL2CAP_CFG_INFO *)p_data); - l2cu_send_peer_config_req (p_ccb, (tL2CAP_CFG_INFO *)p_data); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - break; + } + + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + l2cble_send_peer_disc_req(p_ccb); + else + l2cu_send_peer_disc_req(p_ccb); + + p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_DISCONNECT_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; + + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + l2c_enqueue_peer_data(p_ccb, (BT_HDR*)p_data); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + break; + + case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config req */ + p_ccb->chnl_state = CST_CONFIG; + p_ccb->config_done &= ~CFG_DONE_MASK; + l2cu_process_our_cfg_req(p_ccb, (tL2CAP_CFG_INFO*)p_data); + l2cu_send_peer_config_req(p_ccb, (tL2CAP_CFG_INFO*)p_data); + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + break; case L2CEVT_TIMEOUT: - /* Process the monitor/retransmission time-outs in flow control/retrans mode */ - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - l2c_fcr_proc_tout (p_ccb); - break; + /* Process the monitor/retransmission time-outs in flow control/retrans + * mode */ + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) + l2c_fcr_proc_tout(p_ccb); + break; case L2CEVT_ACK_TIMEOUT: - l2c_fcr_proc_ack_tout (p_ccb); - break; + l2c_fcr_proc_ack_tout(p_ccb); + break; case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: - L2CAP_TRACE_DEBUG("%s Sending credit",__func__); - credit = (uint16_t*)p_data; - l2cble_send_flow_control_credit(p_ccb, *credit); - break; + L2CAP_TRACE_DEBUG("%s Sending credit", __func__); + credit = (uint16_t*)p_data; + l2cble_send_flow_control_credit(p_ccb, *credit); + break; case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: - credit = (uint16_t*)p_data; - L2CAP_TRACE_DEBUG("%s Credits received %d",__func__, *credit); - if((p_ccb->peer_conn_cfg.credits + *credit) > L2CAP_LE_MAX_CREDIT) - { - /* we have received credits more than max coc credits, - * so disconnecting the Le Coc Channel - */ - l2cble_send_peer_disc_req (p_ccb); - } - else - { - p_ccb->peer_conn_cfg.credits += *credit; - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - } - break; - } + credit = (uint16_t*)p_data; + L2CAP_TRACE_DEBUG("%s Credits received %d", __func__, *credit); + if ((p_ccb->peer_conn_cfg.credits + *credit) > L2CAP_LE_MAX_CREDIT) { + /* we have received credits more than max coc credits, + * so disconnecting the Le Coc Channel + */ + l2cble_send_peer_disc_req(p_ccb); + } else { + p_ccb->peer_conn_cfg.credits += *credit; + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + } + break; + } } - /******************************************************************************* * * Function l2c_csm_w4_l2cap_disconnect_rsp @@ -1234,57 +1212,58 @@ static void l2c_csm_open (tL2C_CCB *p_ccb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -static void l2c_csm_w4_l2cap_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2CA_DISCONNECT_CFM_CB *disconnect_cfm = p_ccb->p_rcb->api.pL2CA_DisconnectCfm_Cb; - uint16_t local_cid = p_ccb->local_cid; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: W4_L2CAP_DISC_RSP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_L2CAP_DISCONNECT_RSP: /* Peer disconnect response */ - l2cu_release_ccb (p_ccb); - if (disconnect_cfm) - { - L2CAP_TRACE_API ("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", local_cid); - (*disconnect_cfm)(local_cid, L2CAP_DISC_OK); - } - break; - - case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnect request */ - l2cu_send_peer_disc_rsp (p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, p_ccb->remote_cid); - l2cu_release_ccb (p_ccb); - if (disconnect_cfm) - { - L2CAP_TRACE_API ("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", local_cid); - (*disconnect_cfm)(local_cid, L2CAP_DISC_OK); - } - break; - - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - case L2CEVT_TIMEOUT: /* Timeout */ - l2cu_release_ccb (p_ccb); - if (disconnect_cfm) - { - L2CAP_TRACE_API ("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", local_cid); - (*disconnect_cfm)(local_cid, L2CAP_DISC_TIMEOUT); - } - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - osi_free(p_data); - break; +static void l2c_csm_w4_l2cap_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + tL2CA_DISCONNECT_CFM_CB* disconnect_cfm = + p_ccb->p_rcb->api.pL2CA_DisconnectCfm_Cb; + uint16_t local_cid = p_ccb->local_cid; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: W4_L2CAP_DISC_RSP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_L2CAP_DISCONNECT_RSP: /* Peer disconnect response */ + l2cu_release_ccb(p_ccb); + if (disconnect_cfm) { + L2CAP_TRACE_API("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", + local_cid); + (*disconnect_cfm)(local_cid, L2CAP_DISC_OK); + } + break; + + case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnect request */ + l2cu_send_peer_disc_rsp(p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, + p_ccb->remote_cid); + l2cu_release_ccb(p_ccb); + if (disconnect_cfm) { + L2CAP_TRACE_API("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", + local_cid); + (*disconnect_cfm)(local_cid, L2CAP_DISC_OK); + } + break; + + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + case L2CEVT_TIMEOUT: /* Timeout */ + l2cu_release_ccb(p_ccb); + if (disconnect_cfm) { + L2CAP_TRACE_API("L2CAP - Calling DisconnectCfm_Cb(), CID: 0x%04x", + local_cid); + (*disconnect_cfm)(local_cid, L2CAP_DISC_TIMEOUT); + } + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + osi_free(p_data); + break; case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: - osi_free(p_data); - break; - } + osi_free(p_data); + break; + } } - /******************************************************************************* * * Function l2c_csm_w4_l2ca_disconnect_rsp @@ -1295,39 +1274,46 @@ static void l2c_csm_w4_l2cap_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, vo * Returns void * ******************************************************************************/ -static void l2c_csm_w4_l2ca_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - tL2CA_DISCONNECT_IND_CB *disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - uint16_t local_cid = p_ccb->local_cid; - - L2CAP_TRACE_EVENT ("L2CAP - LCID: 0x%04x st: W4_L2CA_DISC_RSP evt: %s", p_ccb->local_cid, l2c_csm_get_event_name (event)); - - switch (event) - { - case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; +static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event, + void* p_data) { + tL2CA_DISCONNECT_IND_CB* disconnect_ind = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + uint16_t local_cid = p_ccb->local_cid; + + L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: W4_L2CA_DISC_RSP evt: %s", + p_ccb->local_cid, l2c_csm_get_event_name(event)); + + switch (event) { + case L2CEVT_LP_DISCONNECT_IND: /* Link was disconnected */ + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; case L2CEVT_TIMEOUT: - l2cu_send_peer_disc_rsp (p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, p_ccb->remote_cid); - L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", p_ccb->local_cid); - l2cu_release_ccb (p_ccb); - (*disconnect_ind)(local_cid, false); - break; - - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper disconnect request */ - case L2CEVT_L2CA_DISCONNECT_RSP: /* Upper disconnect response */ - l2cu_send_peer_disc_rsp (p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, p_ccb->remote_cid); - l2cu_release_ccb (p_ccb); - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - osi_free(p_data); - break; - } + l2cu_send_peer_disc_rsp(p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, + p_ccb->remote_cid); + L2CAP_TRACE_API( + "L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x No Conf Needed", + p_ccb->local_cid); + l2cu_release_ccb(p_ccb); + (*disconnect_ind)(local_cid, false); + break; + + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper disconnect request */ + case L2CEVT_L2CA_DISCONNECT_RSP: /* Upper disconnect response */ + l2cu_send_peer_disc_rsp(p_ccb->p_lcb, p_ccb->remote_id, p_ccb->local_cid, + p_ccb->remote_cid); + l2cu_release_ccb(p_ccb); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + osi_free(p_data); + break; + } } /******************************************************************************* @@ -1341,87 +1327,86 @@ static void l2c_csm_w4_l2ca_disconnect_rsp (tL2C_CCB *p_ccb, uint16_t event, voi * Returns pointer to the name * ******************************************************************************/ -static const char *l2c_csm_get_event_name (uint16_t event) -{ - switch (event) - { - case L2CEVT_LP_CONNECT_CFM: /* Lower layer connect confirm */ - return ("LOWER_LAYER_CONNECT_CFM"); - case L2CEVT_LP_CONNECT_CFM_NEG: /* Lower layer connect confirm (failed) */ - return ("LOWER_LAYER_CONNECT_CFM_NEG"); - case L2CEVT_LP_CONNECT_IND: /* Lower layer connect indication */ - return ("LOWER_LAYER_CONNECT_IND"); - case L2CEVT_LP_DISCONNECT_IND: /* Lower layer disconnect indication */ - return ("LOWER_LAYER_DISCONNECT_IND"); - case L2CEVT_LP_QOS_CFM: /* Lower layer QOS confirmation */ - return ("LOWER_LAYER_QOS_CFM"); - case L2CEVT_LP_QOS_CFM_NEG: /* Lower layer QOS confirmation (failed)*/ - return ("LOWER_LAYER_QOS_CFM_NEG"); - case L2CEVT_LP_QOS_VIOLATION_IND: /* Lower layer QOS violation indication */ - return ("LOWER_LAYER_QOS_VIOLATION_IND"); - - case L2CEVT_SEC_COMP: /* Security cleared successfully */ - return ("SECURITY_COMPLETE"); - case L2CEVT_SEC_COMP_NEG: /* Security procedure failed */ - return ("SECURITY_COMPLETE_NEG"); - - case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connection request */ - return ("PEER_CONNECT_REQ"); - case L2CEVT_L2CAP_CONNECT_RSP: /* Peer connection response */ - return ("PEER_CONNECT_RSP"); - case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Peer connection response pending */ - return ("PEER_CONNECT_RSP_PND"); - case L2CEVT_L2CAP_CONNECT_RSP_NEG: /* Peer connection response (failed) */ - return ("PEER_CONNECT_RSP_NEG"); - case L2CEVT_L2CAP_CONFIG_REQ: /* Peer configuration request */ - return ("PEER_CONFIG_REQ"); - case L2CEVT_L2CAP_CONFIG_RSP: /* Peer configuration response */ - return ("PEER_CONFIG_RSP"); - case L2CEVT_L2CAP_CONFIG_RSP_NEG: /* Peer configuration response (failed) */ - return ("PEER_CONFIG_RSP_NEG"); - case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnect request */ - return ("PEER_DISCONNECT_REQ"); - case L2CEVT_L2CAP_DISCONNECT_RSP: /* Peer disconnect response */ - return ("PEER_DISCONNECT_RSP"); - case L2CEVT_L2CAP_DATA: /* Peer data */ - return ("PEER_DATA"); - - case L2CEVT_L2CA_CONNECT_REQ: /* Upper layer connect request */ - return ("UPPER_LAYER_CONNECT_REQ"); - case L2CEVT_L2CA_CONNECT_RSP: /* Upper layer connect response */ - return ("UPPER_LAYER_CONNECT_RSP"); - case L2CEVT_L2CA_CONNECT_RSP_NEG: /* Upper layer connect response (failed)*/ - return ("UPPER_LAYER_CONNECT_RSP_NEG"); - case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config request */ - return ("UPPER_LAYER_CONFIG_REQ"); - case L2CEVT_L2CA_CONFIG_RSP: /* Upper layer config response */ - return ("UPPER_LAYER_CONFIG_RSP"); - case L2CEVT_L2CA_CONFIG_RSP_NEG: /* Upper layer config response (failed) */ - return ("UPPER_LAYER_CONFIG_RSP_NEG"); - case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper layer disconnect request */ - return ("UPPER_LAYER_DISCONNECT_REQ"); - case L2CEVT_L2CA_DISCONNECT_RSP: /* Upper layer disconnect response */ - return ("UPPER_LAYER_DISCONNECT_RSP"); - case L2CEVT_L2CA_DATA_READ: /* Upper layer data read */ - return ("UPPER_LAYER_DATA_READ"); - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data write */ - return ("UPPER_LAYER_DATA_WRITE"); - case L2CEVT_TIMEOUT: /* Timeout */ - return ("TIMEOUT"); +static const char* l2c_csm_get_event_name(uint16_t event) { + switch (event) { + case L2CEVT_LP_CONNECT_CFM: /* Lower layer connect confirm */ + return ("LOWER_LAYER_CONNECT_CFM"); + case L2CEVT_LP_CONNECT_CFM_NEG: /* Lower layer connect confirm (failed) */ + return ("LOWER_LAYER_CONNECT_CFM_NEG"); + case L2CEVT_LP_CONNECT_IND: /* Lower layer connect indication */ + return ("LOWER_LAYER_CONNECT_IND"); + case L2CEVT_LP_DISCONNECT_IND: /* Lower layer disconnect indication */ + return ("LOWER_LAYER_DISCONNECT_IND"); + case L2CEVT_LP_QOS_CFM: /* Lower layer QOS confirmation */ + return ("LOWER_LAYER_QOS_CFM"); + case L2CEVT_LP_QOS_CFM_NEG: /* Lower layer QOS confirmation (failed)*/ + return ("LOWER_LAYER_QOS_CFM_NEG"); + case L2CEVT_LP_QOS_VIOLATION_IND: /* Lower layer QOS violation indication */ + return ("LOWER_LAYER_QOS_VIOLATION_IND"); + + case L2CEVT_SEC_COMP: /* Security cleared successfully */ + return ("SECURITY_COMPLETE"); + case L2CEVT_SEC_COMP_NEG: /* Security procedure failed */ + return ("SECURITY_COMPLETE_NEG"); + + case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connection request */ + return ("PEER_CONNECT_REQ"); + case L2CEVT_L2CAP_CONNECT_RSP: /* Peer connection response */ + return ("PEER_CONNECT_RSP"); + case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Peer connection response pending */ + return ("PEER_CONNECT_RSP_PND"); + case L2CEVT_L2CAP_CONNECT_RSP_NEG: /* Peer connection response (failed) */ + return ("PEER_CONNECT_RSP_NEG"); + case L2CEVT_L2CAP_CONFIG_REQ: /* Peer configuration request */ + return ("PEER_CONFIG_REQ"); + case L2CEVT_L2CAP_CONFIG_RSP: /* Peer configuration response */ + return ("PEER_CONFIG_RSP"); + case L2CEVT_L2CAP_CONFIG_RSP_NEG: /* Peer configuration response (failed) */ + return ("PEER_CONFIG_RSP_NEG"); + case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnect request */ + return ("PEER_DISCONNECT_REQ"); + case L2CEVT_L2CAP_DISCONNECT_RSP: /* Peer disconnect response */ + return ("PEER_DISCONNECT_RSP"); + case L2CEVT_L2CAP_DATA: /* Peer data */ + return ("PEER_DATA"); + + case L2CEVT_L2CA_CONNECT_REQ: /* Upper layer connect request */ + return ("UPPER_LAYER_CONNECT_REQ"); + case L2CEVT_L2CA_CONNECT_RSP: /* Upper layer connect response */ + return ("UPPER_LAYER_CONNECT_RSP"); + case L2CEVT_L2CA_CONNECT_RSP_NEG: /* Upper layer connect response (failed)*/ + return ("UPPER_LAYER_CONNECT_RSP_NEG"); + case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config request */ + return ("UPPER_LAYER_CONFIG_REQ"); + case L2CEVT_L2CA_CONFIG_RSP: /* Upper layer config response */ + return ("UPPER_LAYER_CONFIG_RSP"); + case L2CEVT_L2CA_CONFIG_RSP_NEG: /* Upper layer config response (failed) */ + return ("UPPER_LAYER_CONFIG_RSP_NEG"); + case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper layer disconnect request */ + return ("UPPER_LAYER_DISCONNECT_REQ"); + case L2CEVT_L2CA_DISCONNECT_RSP: /* Upper layer disconnect response */ + return ("UPPER_LAYER_DISCONNECT_RSP"); + case L2CEVT_L2CA_DATA_READ: /* Upper layer data read */ + return ("UPPER_LAYER_DATA_READ"); + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data write */ + return ("UPPER_LAYER_DATA_WRITE"); + case L2CEVT_TIMEOUT: /* Timeout */ + return ("TIMEOUT"); case L2CEVT_SEC_RE_SEND_CMD: - return ("SEC_RE_SEND_CMD"); - case L2CEVT_L2CAP_INFO_RSP: /* Peer information response */ - return ("L2CEVT_L2CAP_INFO_RSP"); + return ("SEC_RE_SEND_CMD"); + case L2CEVT_L2CAP_INFO_RSP: /* Peer information response */ + return ("L2CEVT_L2CAP_INFO_RSP"); case L2CEVT_ACK_TIMEOUT: - return ("L2CEVT_ACK_TIMEOUT"); - case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: /* Upper layer send credit packet */ - return ("SEND_FLOW_CONTROL_CREDIT"); - case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: /* Peer send credit packet */ - return ("RECV_FLOW_CONTROL_CREDIT"); + return ("L2CEVT_ACK_TIMEOUT"); + case L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT: /* Upper layer send credit packet + */ + return ("SEND_FLOW_CONTROL_CREDIT"); + case L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT: /* Peer send credit packet */ + return ("RECV_FLOW_CONTROL_CREDIT"); default: - return ("???? UNKNOWN EVENT"); - } + return ("???? UNKNOWN EVENT"); + } } /******************************************************************************* @@ -1434,53 +1419,47 @@ static const char *l2c_csm_get_event_name (uint16_t event) * Returns void * ******************************************************************************/ -void l2c_enqueue_peer_data (tL2C_CCB *p_ccb, BT_HDR *p_buf) -{ - uint8_t *p; - - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - p_buf->event = 0; - } - else - { - /* Save the channel ID for faster counting */ - p_buf->event = p_ccb->local_cid; - - /* Step back to add the L2CAP header */ - p_buf->offset -= L2CAP_PKT_OVERHEAD; - p_buf->len += L2CAP_PKT_OVERHEAD; - - /* Set the pointer to the beginning of the data */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* Now the L2CAP header */ - UINT16_TO_STREAM (p, p_buf->len - L2CAP_PKT_OVERHEAD); - UINT16_TO_STREAM (p, p_ccb->remote_cid); - } - - if (p_ccb->xmit_hold_q == NULL) { - L2CAP_TRACE_ERROR("%s: empty queue: p_ccb = %p p_ccb->in_use = %d p_ccb->chnl_state = %d p_ccb->local_cid = %u p_ccb->remote_cid = %u", - __func__, p_ccb, p_ccb->in_use, p_ccb->chnl_state, - p_ccb->local_cid, p_ccb->remote_cid); - } - fixed_queue_enqueue(p_ccb->xmit_hold_q, p_buf); - - l2cu_check_channel_congestion (p_ccb); +void l2c_enqueue_peer_data(tL2C_CCB* p_ccb, BT_HDR* p_buf) { + uint8_t* p; + + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + p_buf->event = 0; + } else { + /* Save the channel ID for faster counting */ + p_buf->event = p_ccb->local_cid; + + /* Step back to add the L2CAP header */ + p_buf->offset -= L2CAP_PKT_OVERHEAD; + p_buf->len += L2CAP_PKT_OVERHEAD; + + /* Set the pointer to the beginning of the data */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* Now the L2CAP header */ + UINT16_TO_STREAM(p, p_buf->len - L2CAP_PKT_OVERHEAD); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + } + + if (p_ccb->xmit_hold_q == NULL) { + L2CAP_TRACE_ERROR( + "%s: empty queue: p_ccb = %p p_ccb->in_use = %d p_ccb->chnl_state = %d " + "p_ccb->local_cid = %u p_ccb->remote_cid = %u", + __func__, p_ccb, p_ccb->in_use, p_ccb->chnl_state, p_ccb->local_cid, + p_ccb->remote_cid); + } + fixed_queue_enqueue(p_ccb->xmit_hold_q, p_buf); + + l2cu_check_channel_congestion(p_ccb); #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - /* if new packet is higher priority than serving ccb and it is not overrun */ - if (( p_ccb->p_lcb->rr_pri > p_ccb->ccb_priority ) - &&( p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota > 0)) - { - /* send out higher priority packet */ - p_ccb->p_lcb->rr_pri = p_ccb->ccb_priority; - } + /* if new packet is higher priority than serving ccb and it is not overrun */ + if ((p_ccb->p_lcb->rr_pri > p_ccb->ccb_priority) && + (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota > 0)) { + /* send out higher priority packet */ + p_ccb->p_lcb->rr_pri = p_ccb->ccb_priority; + } #endif - /* if we are doing a round robin scheduling, set the flag */ - if (p_ccb->p_lcb->link_xmit_quota == 0) - l2cb.check_round_robin = true; + /* if we are doing a round robin scheduling, set the flag */ + if (p_ccb->p_lcb->link_xmit_quota == 0) l2cb.check_round_robin = true; } - - diff --git a/stack/l2cap/l2c_fcr.cc b/stack/l2cap/l2c_fcr.cc index 478b96098..3f8b05527 100644 --- a/stack/l2cap/l2c_fcr.cc +++ b/stack/l2cap/l2c_fcr.cc @@ -28,79 +28,78 @@ #include #include -#include "bt_types.h" #include "bt_common.h" +#include "bt_types.h" +#include "btm_api.h" +#include "btm_int.h" +#include "btu.h" #include "hcimsgs.h" #include "l2c_api.h" #include "l2c_int.h" #include "l2cdefs.h" -#include "btm_api.h" -#include "btm_int.h" -#include "btu.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /* Flag passed to retransmit_i_frames() when all packets should be retransmitted */ -#define L2C_FCR_RETX_ALL_PKTS 0xFF +#define L2C_FCR_RETX_ALL_PKTS 0xFF /* this is the minimal offset required by OBX to process incoming packets */ static const uint16_t OBX_BUF_MIN_OFFSET = 4; -static const char *SAR_types[] = { "Unsegmented", "Start", "End", "Continuation" }; -static const char *SUP_types[] = { "RR", "REJ", "RNR", "SREJ" }; +static const char* SAR_types[] = {"Unsegmented", "Start", "End", + "Continuation"}; +static const char* SUP_types[] = {"RR", "REJ", "RNR", "SREJ"}; /* Look-up table for the CRC calculation */ static const unsigned short crctab[256] = { - 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, - 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, - 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, - 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, - 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, - 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, - 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, - 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, - 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, - 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, - 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, - 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, - 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, - 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, - 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, - 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, - 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, - 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, - 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, - 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, - 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, - 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, - 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, - 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, - 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, - 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, - 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, - 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, - 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, - 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, - 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, - 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040, + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, + 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, + 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, + 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, + 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, + 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, + 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, + 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, + 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, + 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, + 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981, + 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, + 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, + 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, + 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, + 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, + 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, + 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, + 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80, + 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, + 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, + 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, + 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, + 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, + 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, + 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, + 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, + 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, + 0x4100, 0x81c1, 0x8081, 0x4040, }; - /******************************************************************************* * Static local functions */ -static bool process_reqseq (tL2C_CCB *p_ccb, uint16_t ctrl_word); -static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word); -static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word, bool delay_ack); -static bool retransmit_i_frames (tL2C_CCB *p_ccb, uint8_t tx_seq); -static void prepare_I_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, bool is_retransmission); -static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf); -static bool do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word); +static bool process_reqseq(tL2C_CCB* p_ccb, uint16_t ctrl_word); +static void process_s_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, uint16_t ctrl_word); +static void process_i_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, uint16_t ctrl_word, + bool delay_ack); +static bool retransmit_i_frames(tL2C_CCB* p_ccb, uint8_t tx_seq); +static void prepare_I_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, + bool is_retransmission); +static void process_stream_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf); +static bool do_sar_reassembly(tL2C_CCB* p_ccb, BT_HDR* p_buf, + uint16_t ctrl_word); #if (L2CAP_ERTM_STATS == TRUE) -static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, uint8_t num_bufs_acked); +static void l2c_fcr_collect_ack_delay(tL2C_CCB* p_ccb, uint8_t num_bufs_acked); #endif /******************************************************************************* @@ -112,21 +111,19 @@ static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, uint8_t num_bufs_acked); * Returns CRC * ******************************************************************************/ -static unsigned short l2c_fcr_updcrc(unsigned short icrc, unsigned char *icp, int icnt) -{ - unsigned short crc = icrc; - unsigned char *cp = icp; - int cnt = icnt; +static unsigned short l2c_fcr_updcrc(unsigned short icrc, unsigned char* icp, + int icnt) { + unsigned short crc = icrc; + unsigned char* cp = icp; + int cnt = icnt; - while (cnt--) - { - crc = ((crc >> 8) & 0xff) ^ crctab[(crc & 0xff) ^ *cp++]; - } + while (cnt--) { + crc = ((crc >> 8) & 0xff) ^ crctab[(crc & 0xff) ^ *cp++]; + } - return(crc); + return (crc); } - /******************************************************************************* * * Function l2c_fcr_tx_get_fcs @@ -136,11 +133,10 @@ static unsigned short l2c_fcr_updcrc(unsigned short icrc, unsigned char *icp, in * Returns CRC * ******************************************************************************/ -static uint16_t l2c_fcr_tx_get_fcs (BT_HDR *p_buf) -{ - uint8_t *p = ((uint8_t *) (p_buf + 1)) + p_buf->offset; +static uint16_t l2c_fcr_tx_get_fcs(BT_HDR* p_buf) { + uint8_t* p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; - return (l2c_fcr_updcrc (L2CAP_FCR_INIT_CRC, p, p_buf->len)); + return (l2c_fcr_updcrc(L2CAP_FCR_INIT_CRC, p, p_buf->len)); } /******************************************************************************* @@ -152,14 +148,14 @@ static uint16_t l2c_fcr_tx_get_fcs (BT_HDR *p_buf) * Returns CRC * ******************************************************************************/ -static uint16_t l2c_fcr_rx_get_fcs (BT_HDR *p_buf) -{ - uint8_t *p = ((uint8_t *) (p_buf + 1)) + p_buf->offset; +static uint16_t l2c_fcr_rx_get_fcs(BT_HDR* p_buf) { + uint8_t* p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; - /* offset points past the L2CAP header, but the CRC check includes it */ - p -= L2CAP_PKT_OVERHEAD; + /* offset points past the L2CAP header, but the CRC check includes it */ + p -= L2CAP_PKT_OVERHEAD; - return (l2c_fcr_updcrc (L2CAP_FCR_INIT_CRC, p, p_buf->len + L2CAP_PKT_OVERHEAD)); + return ( + l2c_fcr_updcrc(L2CAP_FCR_INIT_CRC, p, p_buf->len + L2CAP_PKT_OVERHEAD)); } /******************************************************************************* @@ -171,27 +167,22 @@ static uint16_t l2c_fcr_rx_get_fcs (BT_HDR *p_buf) * Returns - * ******************************************************************************/ -void l2c_fcr_start_timer (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - uint32_t tout; - - /* The timers which are in milliseconds */ - if (p_ccb->fcrb.wait_ack) - { - tout = (uint32_t)p_ccb->our_cfg.fcr.mon_tout; - } - else - { - tout = (uint32_t)p_ccb->our_cfg.fcr.rtrans_tout; - } - - /* Only start a timer that was not started */ - if (!alarm_is_scheduled(p_ccb->fcrb.mon_retrans_timer)) { - alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer, tout, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } +void l2c_fcr_start_timer(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + uint32_t tout; + + /* The timers which are in milliseconds */ + if (p_ccb->fcrb.wait_ack) { + tout = (uint32_t)p_ccb->our_cfg.fcr.mon_tout; + } else { + tout = (uint32_t)p_ccb->our_cfg.fcr.rtrans_tout; + } + + /* Only start a timer that was not started */ + if (!alarm_is_scheduled(p_ccb->fcrb.mon_retrans_timer)) { + alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer, tout, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + } } /******************************************************************************* @@ -203,10 +194,9 @@ void l2c_fcr_start_timer (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -void l2c_fcr_stop_timer (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - alarm_cancel(p_ccb->fcrb.mon_retrans_timer); +void l2c_fcr_stop_timer(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + alarm_cancel(p_ccb->fcrb.mon_retrans_timer); } /******************************************************************************* @@ -219,99 +209,124 @@ void l2c_fcr_stop_timer (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -void l2c_fcr_cleanup (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; +void l2c_fcr_cleanup(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; - alarm_free(p_fcrb->mon_retrans_timer); - p_fcrb->mon_retrans_timer = NULL; - alarm_free(p_fcrb->ack_timer); - p_fcrb->ack_timer = NULL; + alarm_free(p_fcrb->mon_retrans_timer); + p_fcrb->mon_retrans_timer = NULL; + alarm_free(p_fcrb->ack_timer); + p_fcrb->ack_timer = NULL; - osi_free_and_reset((void **)&p_fcrb->p_rx_sdu); + osi_free_and_reset((void**)&p_fcrb->p_rx_sdu); - fixed_queue_free(p_fcrb->waiting_for_ack_q, osi_free); - p_fcrb->waiting_for_ack_q = NULL; + fixed_queue_free(p_fcrb->waiting_for_ack_q, osi_free); + p_fcrb->waiting_for_ack_q = NULL; - fixed_queue_free(p_fcrb->srej_rcv_hold_q, osi_free); - p_fcrb->srej_rcv_hold_q = NULL; + fixed_queue_free(p_fcrb->srej_rcv_hold_q, osi_free); + p_fcrb->srej_rcv_hold_q = NULL; - fixed_queue_free(p_fcrb->retrans_q, osi_free); - p_fcrb->retrans_q = NULL; + fixed_queue_free(p_fcrb->retrans_q, osi_free); + p_fcrb->retrans_q = NULL; #if (L2CAP_ERTM_STATS == TRUE) - if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) ) - { - uint32_t dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count; - size_t p_str_size = 120; - char *p_str = (char *)osi_malloc(p_str_size); - uint16_t i; - uint32_t throughput_avg, ack_delay_avg, ack_q_count_avg; - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "--- L2CAP ERTM Stats for CID: 0x%04x Duration: %08ums", p_ccb->local_cid, dur); - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "Retransmissions:%08u Times Flow Controlled:%08u Retrans Touts:%08u Ack Touts:%08u", - p_ccb->fcrb.pkts_retransmitted, p_ccb->fcrb.xmit_window_closed, p_ccb->fcrb.retrans_touts, p_ccb->fcrb.xmit_ack_touts); - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "Times there is less than 2 packets in controller when flow controlled:%08u", p_ccb->fcrb.controller_idle); - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "max_held_acks:%08u, in_cfg.fcr.tx_win_sz:%08u", p_ccb->fcrb.max_held_acks, p_ccb->peer_cfg.fcr.tx_win_sz ); - - snprintf(p_str, p_str_size, "Sent Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u", - p_ccb->fcrb.ertm_pkt_counts[0], p_ccb->fcrb.ertm_byte_counts[0], - (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[0] * 100) / (dur / 10) : 0), - p_ccb->fcrb.s_frames_sent[0], p_ccb->fcrb.s_frames_sent[1], p_ccb->fcrb.s_frames_sent[2], p_ccb->fcrb.s_frames_sent[3]); - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "%s", p_str); - - snprintf(p_str, p_str_size, "Rcvd Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u", - p_ccb->fcrb.ertm_pkt_counts[1], p_ccb->fcrb.ertm_byte_counts[1], - (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[1] * 100) / (dur / 10) : 0), - p_ccb->fcrb.s_frames_rcvd[0], p_ccb->fcrb.s_frames_rcvd[1], p_ccb->fcrb.s_frames_rcvd[2], p_ccb->fcrb.s_frames_rcvd[3]); - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "%s", p_str); - - throughput_avg = 0; - ack_delay_avg = 0; - ack_q_count_avg = 0; - - for (i = 0; i < L2CAP_ERTM_STATS_NUM_AVG; i++) { - if (i == p_ccb->fcrb.ack_delay_avg_index) { - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "[%02u] collecting data ...", i ); - continue; - } - - snprintf(p_str, p_str_size, "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u", - i, p_ccb->fcrb.throughput[i], - p_ccb->fcrb.ack_delay_avg[i], p_ccb->fcrb.ack_delay_min[i], p_ccb->fcrb.ack_delay_max[i], - p_ccb->fcrb.ack_q_count_avg[i], p_ccb->fcrb.ack_q_count_min[i], p_ccb->fcrb.ack_q_count_max[i] ); - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "%s", p_str); - - throughput_avg += p_ccb->fcrb.throughput[i]; - ack_delay_avg += p_ccb->fcrb.ack_delay_avg[i]; - ack_q_count_avg += p_ccb->fcrb.ack_q_count_avg[i]; - } - - throughput_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); - ack_delay_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); - ack_q_count_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "throughput_avg: %8u (kbytes/sec), ack_delay_avg: %8u ms, ack_q_count_avg: %8u", - throughput_avg, ack_delay_avg, ack_q_count_avg ); - - osi_free(p_str); - - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, - "---"); - } + if ((p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && + (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)) { + uint32_t dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count; + size_t p_str_size = 120; + char* p_str = (char*)osi_malloc(p_str_size); + uint16_t i; + uint32_t throughput_avg, ack_delay_avg, ack_q_count_avg; + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, + "--- L2CAP ERTM Stats for CID: 0x%04x Duration: %08ums", + p_ccb->local_cid, dur); + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, + "Retransmissions:%08u Times Flow Controlled:%08u Retrans " + "Touts:%08u Ack Touts:%08u", + p_ccb->fcrb.pkts_retransmitted, p_ccb->fcrb.xmit_window_closed, + p_ccb->fcrb.retrans_touts, p_ccb->fcrb.xmit_ack_touts); + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, + "Times there is less than 2 packets in controller when flow " + "controlled:%08u", + p_ccb->fcrb.controller_idle); + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, + "max_held_acks:%08u, in_cfg.fcr.tx_win_sz:%08u", + p_ccb->fcrb.max_held_acks, p_ccb->peer_cfg.fcr.tx_win_sz); + + snprintf( + p_str, p_str_size, + "Sent Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u " + "SREJ:%08u", + p_ccb->fcrb.ertm_pkt_counts[0], p_ccb->fcrb.ertm_byte_counts[0], + (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[0] * 100) / (dur / 10) : 0), + p_ccb->fcrb.s_frames_sent[0], p_ccb->fcrb.s_frames_sent[1], + p_ccb->fcrb.s_frames_sent[2], p_ccb->fcrb.s_frames_sent[3]); + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "%s", p_str); + + snprintf( + p_str, p_str_size, + "Rcvd Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u " + "SREJ:%08u", + p_ccb->fcrb.ertm_pkt_counts[1], p_ccb->fcrb.ertm_byte_counts[1], + (dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[1] * 100) / (dur / 10) : 0), + p_ccb->fcrb.s_frames_rcvd[0], p_ccb->fcrb.s_frames_rcvd[1], + p_ccb->fcrb.s_frames_rcvd[2], p_ccb->fcrb.s_frames_rcvd[3]); + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "%s", p_str); + + throughput_avg = 0; + ack_delay_avg = 0; + ack_q_count_avg = 0; + + for (i = 0; i < L2CAP_ERTM_STATS_NUM_AVG; i++) { + if (i == p_ccb->fcrb.ack_delay_avg_index) { + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "[%02u] collecting data ...", i); + continue; + } + + snprintf(p_str, p_str_size, + "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, " + "ack_q_count avg:%3u, min:%3u, max:%3u", + i, p_ccb->fcrb.throughput[i], p_ccb->fcrb.ack_delay_avg[i], + p_ccb->fcrb.ack_delay_min[i], p_ccb->fcrb.ack_delay_max[i], + p_ccb->fcrb.ack_q_count_avg[i], p_ccb->fcrb.ack_q_count_min[i], + p_ccb->fcrb.ack_q_count_max[i]); + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "%s", p_str); + + throughput_avg += p_ccb->fcrb.throughput[i]; + ack_delay_avg += p_ccb->fcrb.ack_delay_avg[i]; + ack_q_count_avg += p_ccb->fcrb.ack_q_count_avg[i]; + } + + throughput_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); + ack_delay_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); + ack_q_count_avg /= (L2CAP_ERTM_STATS_NUM_AVG - 1); + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, + "throughput_avg: %8u (kbytes/sec), ack_delay_avg: %8u ms, " + "ack_q_count_avg: %8u", + throughput_avg, ack_delay_avg, ack_q_count_avg); + + osi_free(p_str); + + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "---"); + } #endif - memset (p_fcrb, 0, sizeof (tL2C_FCRB)); + memset(p_fcrb, 0, sizeof(tL2C_FCRB)); } /******************************************************************************* @@ -324,30 +339,29 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb) * Returns pointer to new buffer * ******************************************************************************/ -BT_HDR *l2c_fcr_clone_buf(BT_HDR *p_buf, uint16_t new_offset, uint16_t no_of_bytes) -{ - assert(p_buf != NULL); - /* - * NOTE: We allocate extra L2CAP_FCS_LEN octets, in case we need to put - * the FCS (Frame Check Sequence) at the end of the buffer. - */ - uint16_t buf_size = no_of_bytes + sizeof(BT_HDR) + new_offset + L2CAP_FCS_LEN; +BT_HDR* l2c_fcr_clone_buf(BT_HDR* p_buf, uint16_t new_offset, + uint16_t no_of_bytes) { + assert(p_buf != NULL); + /* + * NOTE: We allocate extra L2CAP_FCS_LEN octets, in case we need to put + * the FCS (Frame Check Sequence) at the end of the buffer. + */ + uint16_t buf_size = no_of_bytes + sizeof(BT_HDR) + new_offset + L2CAP_FCS_LEN; #if (L2CAP_ERTM_STATS == TRUE) - /* - * NOTE: If L2CAP_ERTM_STATS is enabled, we need 4 extra octets at the - * end for a timestamp at the end of an I-frame. - */ - buf_size += sizeof(uint32_t); + /* + * NOTE: If L2CAP_ERTM_STATS is enabled, we need 4 extra octets at the + * end for a timestamp at the end of an I-frame. + */ + buf_size += sizeof(uint32_t); #endif - BT_HDR *p_buf2 = (BT_HDR *)osi_malloc(buf_size); + BT_HDR* p_buf2 = (BT_HDR*)osi_malloc(buf_size); - p_buf2->offset = new_offset; - p_buf2->len = no_of_bytes; - memcpy(((uint8_t *)(p_buf2 + 1)) + p_buf2->offset, - ((uint8_t *)(p_buf + 1)) + p_buf->offset, - no_of_bytes); + p_buf2->offset = new_offset; + p_buf2->len = no_of_bytes; + memcpy(((uint8_t*)(p_buf2 + 1)) + p_buf2->offset, + ((uint8_t*)(p_buf + 1)) + p_buf->offset, no_of_bytes); - return (p_buf2); + return (p_buf2); } /******************************************************************************* @@ -359,28 +373,26 @@ BT_HDR *l2c_fcr_clone_buf(BT_HDR *p_buf, uint16_t new_offset, uint16_t no_of_byt * Returns The control word * ******************************************************************************/ -bool l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - { - /* Check if remote side flowed us off or the transmit window is full */ - if ( (p_ccb->fcrb.remote_busy == true) - || (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) >= p_ccb->peer_cfg.fcr.tx_win_sz) ) - { +bool l2c_fcr_is_flow_controlled(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { + /* Check if remote side flowed us off or the transmit window is full */ + if ((p_ccb->fcrb.remote_busy == true) || + (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) >= + p_ccb->peer_cfg.fcr.tx_win_sz)) { #if (L2CAP_ERTM_STATS == TRUE) - if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) - { - p_ccb->fcrb.xmit_window_closed++; + if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) { + p_ccb->fcrb.xmit_window_closed++; - if ((p_ccb->p_lcb->sent_not_acked < 2)&&(l2cb.controller_xmit_window > 0)) - p_ccb->fcrb.controller_idle++; - } + if ((p_ccb->p_lcb->sent_not_acked < 2) && + (l2cb.controller_xmit_window > 0)) + p_ccb->fcrb.controller_idle++; + } #endif - return (true); - } + return (true); } - return (false); + } + return (false); } /******************************************************************************* @@ -394,97 +406,93 @@ bool l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -static void prepare_I_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, bool is_retransmission) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; - uint8_t *p; - uint16_t fcs; - uint16_t ctrl_word; - bool set_f_bit = p_fcrb->send_f_rsp; - - p_fcrb->send_f_rsp = false; - - if (is_retransmission) - { - /* Get the old control word and clear out the old req_seq and F bits */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; +static void prepare_I_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, + bool is_retransmission) { + assert(p_ccb != NULL); + assert(p_buf != NULL); + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; + uint8_t* p; + uint16_t fcs; + uint16_t ctrl_word; + bool set_f_bit = p_fcrb->send_f_rsp; - STREAM_TO_UINT16 (ctrl_word, p); + p_fcrb->send_f_rsp = false; - ctrl_word &= ~(L2CAP_FCR_REQ_SEQ_BITS + L2CAP_FCR_F_BIT); - } - else - { - ctrl_word = p_buf->layer_specific & L2CAP_FCR_SEG_BITS; /* SAR bits */ - ctrl_word |= (p_fcrb->next_tx_seq << L2CAP_FCR_TX_SEQ_BITS_SHIFT); /* Tx Seq */ + if (is_retransmission) { + /* Get the old control word and clear out the old req_seq and F bits */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; - p_fcrb->next_tx_seq = (p_fcrb->next_tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; - } + STREAM_TO_UINT16(ctrl_word, p); - /* Set the F-bit and reqseq only if using re-transmission mode */ - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - { - if (set_f_bit) - ctrl_word |= L2CAP_FCR_F_BIT; - - ctrl_word |= (p_fcrb->next_seq_expected) << L2CAP_FCR_REQ_SEQ_BITS_SHIFT; + ctrl_word &= ~(L2CAP_FCR_REQ_SEQ_BITS + L2CAP_FCR_F_BIT); + } else { + ctrl_word = p_buf->layer_specific & L2CAP_FCR_SEG_BITS; /* SAR bits */ + ctrl_word |= + (p_fcrb->next_tx_seq << L2CAP_FCR_TX_SEQ_BITS_SHIFT); /* Tx Seq */ - p_fcrb->last_ack_sent = p_ccb->fcrb.next_seq_expected; + p_fcrb->next_tx_seq = (p_fcrb->next_tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; + } - alarm_cancel(p_ccb->fcrb.ack_timer); - } + /* Set the F-bit and reqseq only if using re-transmission mode */ + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { + if (set_f_bit) ctrl_word |= L2CAP_FCR_F_BIT; - /* Set the control word */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; + ctrl_word |= (p_fcrb->next_seq_expected) << L2CAP_FCR_REQ_SEQ_BITS_SHIFT; - UINT16_TO_STREAM (p, ctrl_word); + p_fcrb->last_ack_sent = p_ccb->fcrb.next_seq_expected; - /* Compute the FCS and add to the end of the buffer if not bypassed */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - { - /* length field in l2cap header has to include FCS length */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset; - UINT16_TO_STREAM (p, p_buf->len + L2CAP_FCS_LEN - L2CAP_PKT_OVERHEAD); + alarm_cancel(p_ccb->fcrb.ack_timer); + } - /* Calculate the FCS */ - fcs = l2c_fcr_tx_get_fcs(p_buf); + /* Set the control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; - /* Point to the end of the buffer and put the FCS there */ - /* - * NOTE: Here we assume the allocated buffer is large enough - * to include extra L2CAP_FCS_LEN octets at the end. - */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset + p_buf->len; + UINT16_TO_STREAM(p, ctrl_word); - UINT16_TO_STREAM (p, fcs); + /* Compute the FCS and add to the end of the buffer if not bypassed */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { + /* length field in l2cap header has to include FCS length */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; + UINT16_TO_STREAM(p, p_buf->len + L2CAP_FCS_LEN - L2CAP_PKT_OVERHEAD); - p_buf->len += L2CAP_FCS_LEN; - } + /* Calculate the FCS */ + fcs = l2c_fcr_tx_get_fcs(p_buf); - if (is_retransmission) - { - L2CAP_TRACE_EVENT ("L2CAP eRTM ReTx I-frame CID: 0x%04x Len: %u SAR: %s TxSeq: %u ReqSeq: %u F: %u", - p_ccb->local_cid, p_buf->len, - SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], - (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - } - else - { - L2CAP_TRACE_EVENT ("L2CAP eRTM Tx I-frame CID: 0x%04x Len: %u SAR: %-12s TxSeq: %u ReqSeq: %u F: %u", - p_ccb->local_cid, p_buf->len, - SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], - (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - } - - /* Start the retransmission timer if not already running */ - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - l2c_fcr_start_timer (p_ccb); + /* Point to the end of the buffer and put the FCS there */ + /* + * NOTE: Here we assume the allocated buffer is large enough + * to include extra L2CAP_FCS_LEN octets at the end. + */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + p_buf->len; + + UINT16_TO_STREAM(p, fcs); + + p_buf->len += L2CAP_FCS_LEN; + } + + if (is_retransmission) { + L2CAP_TRACE_EVENT( + "L2CAP eRTM ReTx I-frame CID: 0x%04x Len: %u SAR: %s TxSeq: %u " + "ReqSeq: %u F: %u", + p_ccb->local_cid, p_buf->len, + SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + } else { + L2CAP_TRACE_EVENT( + "L2CAP eRTM Tx I-frame CID: 0x%04x Len: %u SAR: %-12s TxSeq: %u " + "ReqSeq: %u F: %u", + p_ccb->local_cid, p_buf->len, + SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + } + + /* Start the retransmission timer if not already running */ + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) + l2c_fcr_start_timer(p_ccb); } /******************************************************************************* @@ -496,88 +504,89 @@ static void prepare_I_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, bool is_retransm * Returns - * ******************************************************************************/ -void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, uint16_t function_code, uint16_t pf_bit) -{ - assert(p_ccb != NULL); - uint8_t *p; - uint16_t ctrl_word; - uint16_t fcs; +void l2c_fcr_send_S_frame(tL2C_CCB* p_ccb, uint16_t function_code, + uint16_t pf_bit) { + assert(p_ccb != NULL); + uint8_t* p; + uint16_t ctrl_word; + uint16_t fcs; - if ((!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN)) - return; + if ((!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN)) return; #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.s_frames_sent[function_code]++; + p_ccb->fcrb.s_frames_sent[function_code]++; #endif - if (pf_bit == L2CAP_FCR_P_BIT) - { - p_ccb->fcrb.wait_ack = true; - - l2c_fcr_stop_timer (p_ccb); /* Restart the monitor timer */ - l2c_fcr_start_timer (p_ccb); - } - - /* Create the control word to use */ - ctrl_word = (function_code << L2CAP_FCR_SUP_SHIFT) | L2CAP_FCR_S_FRAME_BIT; - ctrl_word |= (p_ccb->fcrb.next_seq_expected << L2CAP_FCR_REQ_SEQ_BITS_SHIFT); - ctrl_word |= pf_bit; - - BT_HDR *p_buf = (BT_HDR *)osi_malloc(L2CAP_CMD_BUF_SIZE); - p_buf->offset = HCI_DATA_PREAMBLE_SIZE; - p_buf->len = L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD; - - /* Set the pointer to the beginning of the data */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* Put in the L2CAP header */ - UINT16_TO_STREAM(p, L2CAP_FCR_OVERHEAD + L2CAP_FCS_LEN); - UINT16_TO_STREAM(p, p_ccb->remote_cid); - UINT16_TO_STREAM(p, ctrl_word); - - /* Compute the FCS and add to the end of the buffer if not bypassed */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { - fcs = l2c_fcr_tx_get_fcs (p_buf); - - UINT16_TO_STREAM (p, fcs); - p_buf->len += L2CAP_FCS_LEN; - } else { - /* rewrite the length without FCS length */ - p -= 6; - UINT16_TO_STREAM (p, L2CAP_FCR_OVERHEAD); - } - - /* Now, the HCI transport header */ - p_buf->layer_specific = L2CAP_NON_FLUSHABLE_PKT; - l2cu_set_acl_hci_header (p_buf, p_ccb); - - if ((((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 1) - || (((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 3)) { - L2CAP_TRACE_WARNING("L2CAP eRTM Tx S-frame CID: 0x%04x ctrlword: 0x%04x Type: %s ReqSeq: %u P: %u F: %u", - p_ccb->local_cid, ctrl_word, - SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - L2CAP_TRACE_WARNING (" Buf Len: %u", p_buf->len); - } else { - L2CAP_TRACE_EVENT("L2CAP eRTM Tx S-frame CID: 0x%04x ctrlword: 0x%04x Type: %s ReqSeq: %u P: %u F: %u", - p_ccb->local_cid, ctrl_word, - SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - L2CAP_TRACE_EVENT(" Buf Len: %u", p_buf->len); - } - - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); - - p_ccb->fcrb.last_ack_sent = p_ccb->fcrb.next_seq_expected; - - alarm_cancel(p_ccb->fcrb.ack_timer); + if (pf_bit == L2CAP_FCR_P_BIT) { + p_ccb->fcrb.wait_ack = true; + + l2c_fcr_stop_timer(p_ccb); /* Restart the monitor timer */ + l2c_fcr_start_timer(p_ccb); + } + + /* Create the control word to use */ + ctrl_word = (function_code << L2CAP_FCR_SUP_SHIFT) | L2CAP_FCR_S_FRAME_BIT; + ctrl_word |= (p_ccb->fcrb.next_seq_expected << L2CAP_FCR_REQ_SEQ_BITS_SHIFT); + ctrl_word |= pf_bit; + + BT_HDR* p_buf = (BT_HDR*)osi_malloc(L2CAP_CMD_BUF_SIZE); + p_buf->offset = HCI_DATA_PREAMBLE_SIZE; + p_buf->len = L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD; + + /* Set the pointer to the beginning of the data */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* Put in the L2CAP header */ + UINT16_TO_STREAM(p, L2CAP_FCR_OVERHEAD + L2CAP_FCS_LEN); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, ctrl_word); + + /* Compute the FCS and add to the end of the buffer if not bypassed */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { + fcs = l2c_fcr_tx_get_fcs(p_buf); + + UINT16_TO_STREAM(p, fcs); + p_buf->len += L2CAP_FCS_LEN; + } else { + /* rewrite the length without FCS length */ + p -= 6; + UINT16_TO_STREAM(p, L2CAP_FCR_OVERHEAD); + } + + /* Now, the HCI transport header */ + p_buf->layer_specific = L2CAP_NON_FLUSHABLE_PKT; + l2cu_set_acl_hci_header(p_buf, p_ccb); + + if ((((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 1) || + (((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 3)) { + L2CAP_TRACE_WARNING( + "L2CAP eRTM Tx S-frame CID: 0x%04x ctrlword: 0x%04x Type: %s " + "ReqSeq: %u P: %u F: %u", + p_ccb->local_cid, ctrl_word, + SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + L2CAP_TRACE_WARNING(" Buf Len: %u", p_buf->len); + } else { + L2CAP_TRACE_EVENT( + "L2CAP eRTM Tx S-frame CID: 0x%04x ctrlword: 0x%04x Type: %s " + "ReqSeq: %u P: %u F: %u", + p_ccb->local_cid, ctrl_word, + SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + L2CAP_TRACE_EVENT(" Buf Len: %u", p_buf->len); + } + + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); + + p_ccb->fcrb.last_ack_sent = p_ccb->fcrb.next_seq_expected; + + alarm_cancel(p_ccb->fcrb.ack_timer); } - /******************************************************************************* * * Function l2c_fcr_proc_pdu @@ -589,220 +598,217 @@ void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, uint16_t function_code, uint16_t pf_ * Returns - * ******************************************************************************/ -void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); - uint8_t *p; - uint16_t fcs; - uint16_t min_pdu_len; - uint16_t ctrl_word; - - /* Check the length */ - min_pdu_len = (p_ccb->bypass_fcs == L2CAP_BYPASS_FCS) ? - (uint16_t)L2CAP_FCR_OVERHEAD : (uint16_t)(L2CAP_FCS_LEN + L2CAP_FCR_OVERHEAD); - - if (p_buf->len < min_pdu_len) - { - L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x Len too short: %u", p_ccb->local_cid, p_buf->len); - osi_free(p_buf); - return; - } - - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_STREAM_MODE) - { - process_stream_frame (p_ccb, p_buf); - return; - } - - /* Get the control word */ - p = ((uint8_t *)(p_buf+1)) + p_buf->offset; - STREAM_TO_UINT16 (ctrl_word, p); +void l2c_fcr_proc_pdu(tL2C_CCB* p_ccb, BT_HDR* p_buf) { + assert(p_ccb != NULL); + assert(p_buf != NULL); + uint8_t* p; + uint16_t fcs; + uint16_t min_pdu_len; + uint16_t ctrl_word; + + /* Check the length */ + min_pdu_len = (p_ccb->bypass_fcs == L2CAP_BYPASS_FCS) + ? (uint16_t)L2CAP_FCR_OVERHEAD + : (uint16_t)(L2CAP_FCS_LEN + L2CAP_FCR_OVERHEAD); + + if (p_buf->len < min_pdu_len) { + L2CAP_TRACE_WARNING("Rx L2CAP PDU: CID: 0x%04x Len too short: %u", + p_ccb->local_cid, p_buf->len); + osi_free(p_buf); + return; + } - if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) - { - if ((((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 1) - || (((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 3)) - { - /* REJ or SREJ */ - L2CAP_TRACE_WARNING ("L2CAP eRTM Rx S-frame: cid: 0x%04x Len: %u Type: %s ReqSeq: %u P: %u F: %u", - p_ccb->local_cid, p_buf->len, - SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - } + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_STREAM_MODE) { + process_stream_frame(p_ccb, p_buf); + return; + } + + /* Get the control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; + STREAM_TO_UINT16(ctrl_word, p); + + if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) { + if ((((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 1) || + (((ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT) == 3)) { + /* REJ or SREJ */ + L2CAP_TRACE_WARNING( + "L2CAP eRTM Rx S-frame: cid: 0x%04x Len: %u Type: %s ReqSeq: %u " + "P: %u F: %u", + p_ccb->local_cid, p_buf->len, + SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + } else { + L2CAP_TRACE_EVENT( + "L2CAP eRTM Rx S-frame: cid: 0x%04x Len: %u Type: %s ReqSeq: %u " + "P: %u F: %u", + p_ccb->local_cid, p_buf->len, + SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + } + } else { + L2CAP_TRACE_EVENT( + "L2CAP eRTM Rx I-frame: cid: 0x%04x Len: %u SAR: %-12s TxSeq: %u " + "ReqSeq: %u F: %u", + p_ccb->local_cid, p_buf->len, + SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + } + + L2CAP_TRACE_EVENT( + " eRTM Rx Nxt_tx_seq %u, Lst_rx_ack %u, Nxt_seq_exp %u, Lst_ack_snt " + "%u, wt_q.cnt %u, tries %u", + p_ccb->fcrb.next_tx_seq, p_ccb->fcrb.last_rx_ack, + p_ccb->fcrb.next_seq_expected, p_ccb->fcrb.last_ack_sent, + fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q), p_ccb->fcrb.num_tries); + + /* Verify FCS if using */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + p_buf->len - L2CAP_FCS_LEN; + + /* Extract and drop the FCS from the packet */ + STREAM_TO_UINT16(fcs, p); + p_buf->len -= L2CAP_FCS_LEN; + + if (l2c_fcr_rx_get_fcs(p_buf) != fcs) { + L2CAP_TRACE_WARNING("Rx L2CAP PDU: CID: 0x%04x BAD FCS", + p_ccb->local_cid); + osi_free(p_buf); + return; + } + } + + /* Get the control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; + + STREAM_TO_UINT16(ctrl_word, p); + + p_buf->len -= L2CAP_FCR_OVERHEAD; + p_buf->offset += L2CAP_FCR_OVERHEAD; + + /* If we had a poll bit outstanding, check if we got a final response */ + if (p_ccb->fcrb.wait_ack) { + /* If final bit not set, ignore the frame unless it is a polled S-frame */ + if (!(ctrl_word & L2CAP_FCR_F_BIT)) { + if ((ctrl_word & L2CAP_FCR_P_BIT) && + (ctrl_word & L2CAP_FCR_S_FRAME_BIT)) { + if (p_ccb->fcrb.srej_sent) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT); + else if (p_ccb->fcrb.local_busy) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT); else - { - L2CAP_TRACE_EVENT ("L2CAP eRTM Rx S-frame: cid: 0x%04x Len: %u Type: %s ReqSeq: %u P: %u F: %u", - p_ccb->local_cid, p_buf->len, - SUP_types[(ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT], - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_P_BIT) >> L2CAP_FCR_P_BIT_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - } - } - else - { - L2CAP_TRACE_EVENT ("L2CAP eRTM Rx I-frame: cid: 0x%04x Len: %u SAR: %-12s TxSeq: %u ReqSeq: %u F: %u", - p_ccb->local_cid, p_buf->len, - SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], - (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - } - - L2CAP_TRACE_EVENT (" eRTM Rx Nxt_tx_seq %u, Lst_rx_ack %u, Nxt_seq_exp %u, Lst_ack_snt %u, wt_q.cnt %u, tries %u", - p_ccb->fcrb.next_tx_seq, p_ccb->fcrb.last_rx_ack, - p_ccb->fcrb.next_seq_expected, - p_ccb->fcrb.last_ack_sent, - fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q), - p_ccb->fcrb.num_tries); - - /* Verify FCS if using */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - { - p = ((uint8_t *)(p_buf+1)) + p_buf->offset + p_buf->len - L2CAP_FCS_LEN; - - /* Extract and drop the FCS from the packet */ - STREAM_TO_UINT16 (fcs, p); - p_buf->len -= L2CAP_FCS_LEN; - - if (l2c_fcr_rx_get_fcs(p_buf) != fcs) - { - L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD FCS", p_ccb->local_cid); - osi_free(p_buf); - return; - } + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT); + + /* Got a poll while in wait_ack state, so re-start our timer with + * 1-second */ + /* This is a small optimization... the monitor timer is 12 secs, but we + * saw */ + /* that if the other side sends us a poll when we are waiting for a + * final, */ + /* then it speeds up recovery significantly if we poll him back soon + * after his poll. */ + alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer, BT_1SEC_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + } + osi_free(p_buf); + return; } - /* Get the control word */ - p = ((uint8_t *)(p_buf+1)) + p_buf->offset; - - STREAM_TO_UINT16 (ctrl_word, p); + p_ccb->fcrb.wait_ack = false; - p_buf->len -= L2CAP_FCR_OVERHEAD; - p_buf->offset += L2CAP_FCR_OVERHEAD; + /* P and F are mutually exclusive */ + if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) ctrl_word &= ~L2CAP_FCR_P_BIT; - /* If we had a poll bit outstanding, check if we got a final response */ - if (p_ccb->fcrb.wait_ack) - { - /* If final bit not set, ignore the frame unless it is a polled S-frame */ - if ( !(ctrl_word & L2CAP_FCR_F_BIT) ) - { - if ( (ctrl_word & L2CAP_FCR_P_BIT) && (ctrl_word & L2CAP_FCR_S_FRAME_BIT) ) - { - if (p_ccb->fcrb.srej_sent) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT); - else if (p_ccb->fcrb.local_busy) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT); - - /* Got a poll while in wait_ack state, so re-start our timer with 1-second */ - /* This is a small optimization... the monitor timer is 12 secs, but we saw */ - /* that if the other side sends us a poll when we are waiting for a final, */ - /* then it speeds up recovery significantly if we poll him back soon after his poll. */ - alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer, - BT_1SEC_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - osi_free(p_buf); - return; - } - - p_ccb->fcrb.wait_ack = false; + if (fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) + p_ccb->fcrb.num_tries = 0; - /* P and F are mutually exclusive */ - if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) - ctrl_word &= ~L2CAP_FCR_P_BIT; + l2c_fcr_stop_timer(p_ccb); + } else { + /* Otherwise, ensure the final bit is ignored */ + ctrl_word &= ~L2CAP_FCR_F_BIT; + } - if (fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) - p_ccb->fcrb.num_tries = 0; - - l2c_fcr_stop_timer (p_ccb); - } - else - { - /* Otherwise, ensure the final bit is ignored */ - ctrl_word &= ~L2CAP_FCR_F_BIT; - } - - /* Process receive sequence number */ - if (!process_reqseq (p_ccb, ctrl_word)) - { + /* Process receive sequence number */ + if (!process_reqseq(p_ccb, ctrl_word)) { + osi_free(p_buf); + return; + } + + /* Process based on whether it is an S-frame or an I-frame */ + if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) + process_s_frame(p_ccb, p_buf, ctrl_word); + else + process_i_frame(p_ccb, p_buf, ctrl_word, false); + + /* Return if the channel got disconnected by a bad packet or max + * retransmissions */ + if ((!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN)) return; + + /* If we have some buffers held while doing SREJ, and SREJ has cleared, + * process them now */ + if ((!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.srej_sent) && + (!fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q))) { + fixed_queue_t* temp_q = p_ccb->fcrb.srej_rcv_hold_q; + p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX); + + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(temp_q)) != NULL) { + if (p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) { + /* Get the control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset - L2CAP_FCR_OVERHEAD; + + STREAM_TO_UINT16(ctrl_word, p); + + L2CAP_TRACE_DEBUG( + "l2c_fcr_proc_pdu() CID: 0x%04x Process Buffer from SREJ_Hold_Q " + "TxSeq: %u Expected_Seq: %u", + p_ccb->local_cid, + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, + p_ccb->fcrb.next_seq_expected); + + /* Process the SREJ held I-frame, but do not send an RR for each + * individual frame */ + process_i_frame(p_ccb, p_buf, ctrl_word, true); + } else osi_free(p_buf); - return; - } - /* Process based on whether it is an S-frame or an I-frame */ - if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) - process_s_frame (p_ccb, p_buf, ctrl_word); - else - process_i_frame (p_ccb, p_buf, ctrl_word, false); - - /* Return if the channel got disconnected by a bad packet or max retransmissions */ - if ( (!p_ccb->in_use) || (p_ccb->chnl_state != CST_OPEN) ) - return; - - /* If we have some buffers held while doing SREJ, and SREJ has cleared, process them now */ - if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.srej_sent) && - (!fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q))) - { - fixed_queue_t *temp_q = p_ccb->fcrb.srej_rcv_hold_q; - p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX); - - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(temp_q)) != NULL) - { - if (p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) - { - /* Get the control word */ - p = ((uint8_t *)(p_buf+1)) + p_buf->offset - L2CAP_FCR_OVERHEAD; - - STREAM_TO_UINT16 (ctrl_word, p); - - L2CAP_TRACE_DEBUG ("l2c_fcr_proc_pdu() CID: 0x%04x Process Buffer from SREJ_Hold_Q TxSeq: %u Expected_Seq: %u", - p_ccb->local_cid, (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, - p_ccb->fcrb.next_seq_expected); - - /* Process the SREJ held I-frame, but do not send an RR for each individual frame */ - process_i_frame (p_ccb, p_buf, ctrl_word, true); - } - else - osi_free(p_buf); - - /* If more frames were lost during SREJ, send a REJ */ - if (p_ccb->fcrb.rej_after_srej) - { - p_ccb->fcrb.rej_after_srej = false; - p_ccb->fcrb.rej_sent = true; - - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0); - } - } - fixed_queue_free(temp_q, NULL); - - /* Now, if needed, send one RR for the whole held queue */ - if ( (!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.rej_sent) && (!p_ccb->fcrb.srej_sent) - && (p_ccb->fcrb.next_seq_expected != p_ccb->fcrb.last_ack_sent) ) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0); - else - { - L2CAP_TRACE_DEBUG ("l2c_fcr_proc_pdu() not sending RR CID: 0x%04x local_busy:%d rej_sent:%d srej_sent:%d Expected_Seq:%u Last_Ack:%u", - p_ccb->local_cid, p_ccb->fcrb.local_busy, p_ccb->fcrb.rej_sent, p_ccb->fcrb.srej_sent, p_ccb->fcrb.next_seq_expected, - p_ccb->fcrb.last_ack_sent); - } - } - - /* If a window has opened, check if we can send any more packets */ - if ( (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q) || - !fixed_queue_is_empty(p_ccb->xmit_hold_q)) - && (p_ccb->fcrb.wait_ack == false) - && (l2c_fcr_is_flow_controlled (p_ccb) == false) ) - { - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - } + /* If more frames were lost during SREJ, send a REJ */ + if (p_ccb->fcrb.rej_after_srej) { + p_ccb->fcrb.rej_after_srej = false; + p_ccb->fcrb.rej_sent = true; + + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_REJ, 0); + } + } + fixed_queue_free(temp_q, NULL); + + /* Now, if needed, send one RR for the whole held queue */ + if ((!p_ccb->fcrb.local_busy) && (!p_ccb->fcrb.rej_sent) && + (!p_ccb->fcrb.srej_sent) && + (p_ccb->fcrb.next_seq_expected != p_ccb->fcrb.last_ack_sent)) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, 0); + else { + L2CAP_TRACE_DEBUG( + "l2c_fcr_proc_pdu() not sending RR CID: 0x%04x local_busy:%d " + "rej_sent:%d srej_sent:%d Expected_Seq:%u Last_Ack:%u", + p_ccb->local_cid, p_ccb->fcrb.local_busy, p_ccb->fcrb.rej_sent, + p_ccb->fcrb.srej_sent, p_ccb->fcrb.next_seq_expected, + p_ccb->fcrb.last_ack_sent); + } + } + + /* If a window has opened, check if we can send any more packets */ + if ((!fixed_queue_is_empty(p_ccb->fcrb.retrans_q) || + !fixed_queue_is_empty(p_ccb->xmit_hold_q)) && + (p_ccb->fcrb.wait_ack == false) && + (l2c_fcr_is_flow_controlled(p_ccb) == false)) { + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + } } /******************************************************************************* @@ -815,76 +821,64 @@ void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf) * Returns - * ******************************************************************************/ -void l2c_lcc_proc_pdu(tL2C_CCB *p_ccb, BT_HDR *p_buf) -{ - - assert(p_ccb != NULL); - assert(p_buf != NULL); - uint8_t *p = (uint8_t*)(p_buf + 1) + p_buf->offset; - uint16_t sdu_length; - BT_HDR *p_data = NULL; - - /* Buffer length should not exceed local mps */ - if (p_buf->len > p_ccb->local_conn_cfg.mps) - { - /* Discard the buffer */ - osi_free(p_buf); - return; - } - - if (p_ccb->is_first_seg) - { - STREAM_TO_UINT16(sdu_length, p); - /* Check the SDU Length with local MTU size */ - if (sdu_length > p_ccb->local_conn_cfg.mtu) - { - /* Discard the buffer */ - osi_free(p_buf); - return; - } - - - p_data = (BT_HDR *)osi_malloc(L2CAP_MAX_BUF_SIZE); - if (p_data == NULL) - { - osi_free(p_buf); - return; - } - - p_ccb->ble_sdu = p_data; - p_data->len = 0; - p_ccb->ble_sdu_length = sdu_length; - L2CAP_TRACE_DEBUG ("%s SDU Length = %d",__func__,sdu_length); - p_buf->len -= sizeof(sdu_length); - p_buf->offset += sizeof(sdu_length); - p_data->offset = 0; - - } - else - p_data = p_ccb->ble_sdu; - - memcpy((uint8_t*)(p_data + 1) + p_data->offset + p_data->len, (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len); - p_data->len += p_buf->len; - p = (uint8_t*)(p_data+1) + p_data->offset; - if (p_data->len == p_ccb->ble_sdu_length) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DATA, p_data); - p_ccb->is_first_seg = true; - p_ccb->ble_sdu = NULL; - p_ccb->ble_sdu_length = 0; - } - else if (p_data->len < p_ccb->ble_sdu_length) - { - p_ccb->is_first_seg = false; - } - else - { - L2CAP_TRACE_ERROR ("%s Length in the SDU messed up",__func__); - // TODO: reset every thing may be??? - } - +void l2c_lcc_proc_pdu(tL2C_CCB* p_ccb, BT_HDR* p_buf) { + assert(p_ccb != NULL); + assert(p_buf != NULL); + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint16_t sdu_length; + BT_HDR* p_data = NULL; + + /* Buffer length should not exceed local mps */ + if (p_buf->len > p_ccb->local_conn_cfg.mps) { + /* Discard the buffer */ osi_free(p_buf); return; + } + + if (p_ccb->is_first_seg) { + STREAM_TO_UINT16(sdu_length, p); + /* Check the SDU Length with local MTU size */ + if (sdu_length > p_ccb->local_conn_cfg.mtu) { + /* Discard the buffer */ + osi_free(p_buf); + return; + } + + p_data = (BT_HDR*)osi_malloc(L2CAP_MAX_BUF_SIZE); + if (p_data == NULL) { + osi_free(p_buf); + return; + } + + p_ccb->ble_sdu = p_data; + p_data->len = 0; + p_ccb->ble_sdu_length = sdu_length; + L2CAP_TRACE_DEBUG("%s SDU Length = %d", __func__, sdu_length); + p_buf->len -= sizeof(sdu_length); + p_buf->offset += sizeof(sdu_length); + p_data->offset = 0; + + } else + p_data = p_ccb->ble_sdu; + + memcpy((uint8_t*)(p_data + 1) + p_data->offset + p_data->len, + (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len); + p_data->len += p_buf->len; + p = (uint8_t*)(p_data + 1) + p_data->offset; + if (p_data->len == p_ccb->ble_sdu_length) { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DATA, p_data); + p_ccb->is_first_seg = true; + p_ccb->ble_sdu = NULL; + p_ccb->ble_sdu_length = 0; + } else if (p_data->len < p_ccb->ble_sdu_length) { + p_ccb->is_first_seg = false; + } else { + L2CAP_TRACE_ERROR("%s Length in the SDU messed up", __func__); + // TODO: reset every thing may be??? + } + + osi_free(p_buf); + return; } /******************************************************************************* @@ -896,36 +890,31 @@ void l2c_lcc_proc_pdu(tL2C_CCB *p_ccb, BT_HDR *p_buf) * Returns - * ******************************************************************************/ -void l2c_fcr_proc_tout (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - L2CAP_TRACE_DEBUG ("l2c_fcr_proc_tout: CID: 0x%04x num_tries: %u (max: %u) wait_ack: %u ack_q_count: %u", - p_ccb->local_cid, p_ccb->fcrb.num_tries, - p_ccb->peer_cfg.fcr.max_transmit, - p_ccb->fcrb.wait_ack, - fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); +void l2c_fcr_proc_tout(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + L2CAP_TRACE_DEBUG( + "l2c_fcr_proc_tout: CID: 0x%04x num_tries: %u (max: %u) wait_ack: %u " + "ack_q_count: %u", + p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit, + p_ccb->fcrb.wait_ack, fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.retrans_touts++; + p_ccb->fcrb.retrans_touts++; #endif - if ( (p_ccb->peer_cfg.fcr.max_transmit != 0) && (++p_ccb->fcrb.num_tries > p_ccb->peer_cfg.fcr.max_transmit) ) - { - l2cu_disconnect_chnl (p_ccb); - } - else - { - if (!p_ccb->fcrb.srej_sent && !p_ccb->fcrb.rej_sent) - { - if (p_ccb->fcrb.local_busy) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_P_BIT); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT); - } - } + if ((p_ccb->peer_cfg.fcr.max_transmit != 0) && + (++p_ccb->fcrb.num_tries > p_ccb->peer_cfg.fcr.max_transmit)) { + l2cu_disconnect_chnl(p_ccb); + } else { + if (!p_ccb->fcrb.srej_sent && !p_ccb->fcrb.rej_sent) { + if (p_ccb->fcrb.local_busy) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_P_BIT); + else + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_P_BIT); + } + } } - /******************************************************************************* * * Function l2c_fcr_proc_ack_tout @@ -935,26 +924,25 @@ void l2c_fcr_proc_tout (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - L2CAP_TRACE_DEBUG ("l2c_fcr_proc_ack_tout: CID: 0x%04x State: %u Wack:%u Rq:%d Acked:%d", p_ccb->local_cid, - p_ccb->chnl_state, p_ccb->fcrb.wait_ack, p_ccb->fcrb.next_seq_expected, p_ccb->fcrb.last_ack_sent); - - if ( (p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack) - && (p_ccb->fcrb.last_ack_sent != p_ccb->fcrb.next_seq_expected) ) - { +void l2c_fcr_proc_ack_tout(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); + L2CAP_TRACE_DEBUG( + "l2c_fcr_proc_ack_tout: CID: 0x%04x State: %u Wack:%u Rq:%d Acked:%d", + p_ccb->local_cid, p_ccb->chnl_state, p_ccb->fcrb.wait_ack, + p_ccb->fcrb.next_seq_expected, p_ccb->fcrb.last_ack_sent); + + if ((p_ccb->chnl_state == CST_OPEN) && (!p_ccb->fcrb.wait_ack) && + (p_ccb->fcrb.last_ack_sent != p_ccb->fcrb.next_seq_expected)) { #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.xmit_ack_touts++; + p_ccb->fcrb.xmit_ack_touts++; #endif - if (p_ccb->fcrb.local_busy) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0); - } + if (p_ccb->fcrb.local_busy) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, 0); + else + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, 0); + } } - /******************************************************************************* * * Function process_reqseq @@ -964,90 +952,91 @@ void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -static bool process_reqseq (tL2C_CCB *p_ccb, uint16_t ctrl_word) -{ - assert(p_ccb != NULL); - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; - uint8_t req_seq, num_bufs_acked, xx; - uint16_t ls; - uint16_t full_sdus_xmitted; - - /* Receive sequence number does not ack anything for SREJ with P-bit set to zero */ - if ( (ctrl_word & L2CAP_FCR_S_FRAME_BIT) - && ((ctrl_word & L2CAP_FCR_SUP_BITS) == (L2CAP_FCR_SUP_SREJ << L2CAP_FCR_SUP_SHIFT)) - && ((ctrl_word & L2CAP_FCR_P_BIT) == 0) ) - { - /* If anything still waiting for ack, restart the timer if it was stopped */ - if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) - l2c_fcr_start_timer(p_ccb); +static bool process_reqseq(tL2C_CCB* p_ccb, uint16_t ctrl_word) { + assert(p_ccb != NULL); + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; + uint8_t req_seq, num_bufs_acked, xx; + uint16_t ls; + uint16_t full_sdus_xmitted; + + /* Receive sequence number does not ack anything for SREJ with P-bit set to + * zero */ + if ((ctrl_word & L2CAP_FCR_S_FRAME_BIT) && + ((ctrl_word & L2CAP_FCR_SUP_BITS) == + (L2CAP_FCR_SUP_SREJ << L2CAP_FCR_SUP_SHIFT)) && + ((ctrl_word & L2CAP_FCR_P_BIT) == 0)) { + /* If anything still waiting for ack, restart the timer if it was stopped */ + if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) + l2c_fcr_start_timer(p_ccb); - return (true); - } + return (true); + } - /* Extract the receive sequence number from the control word */ - req_seq = (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT; + /* Extract the receive sequence number from the control word */ + req_seq = + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT; - num_bufs_acked = (req_seq - p_fcrb->last_rx_ack) & L2CAP_FCR_SEQ_MODULO; + num_bufs_acked = (req_seq - p_fcrb->last_rx_ack) & L2CAP_FCR_SEQ_MODULO; - /* Verify the request sequence is in range before proceeding */ - if (num_bufs_acked > fixed_queue_length(p_fcrb->waiting_for_ack_q)) - { - /* The channel is closed if ReqSeq is not in range */ - L2CAP_TRACE_WARNING ("L2CAP eRTM Frame BAD Req_Seq - ctrl_word: 0x%04x req_seq 0x%02x last_rx_ack: 0x%02x QCount: %u", - ctrl_word, req_seq, p_fcrb->last_rx_ack, - fixed_queue_length(p_fcrb->waiting_for_ack_q)); + /* Verify the request sequence is in range before proceeding */ + if (num_bufs_acked > fixed_queue_length(p_fcrb->waiting_for_ack_q)) { + /* The channel is closed if ReqSeq is not in range */ + L2CAP_TRACE_WARNING( + "L2CAP eRTM Frame BAD Req_Seq - ctrl_word: 0x%04x req_seq 0x%02x " + "last_rx_ack: 0x%02x QCount: %u", + ctrl_word, req_seq, p_fcrb->last_rx_ack, + fixed_queue_length(p_fcrb->waiting_for_ack_q)); - l2cu_disconnect_chnl (p_ccb); - return (false); - } + l2cu_disconnect_chnl(p_ccb); + return (false); + } - p_fcrb->last_rx_ack = req_seq; + p_fcrb->last_rx_ack = req_seq; - /* Now we can release all acknowledged frames, and restart the retransmission timer if needed */ - if (num_bufs_acked != 0) - { - p_fcrb->num_tries = 0; - full_sdus_xmitted = 0; + /* Now we can release all acknowledged frames, and restart the retransmission + * timer if needed */ + if (num_bufs_acked != 0) { + p_fcrb->num_tries = 0; + full_sdus_xmitted = 0; #if (L2CAP_ERTM_STATS == TRUE) - l2c_fcr_collect_ack_delay (p_ccb, num_bufs_acked); + l2c_fcr_collect_ack_delay(p_ccb, num_bufs_acked); #endif - for (xx = 0; xx < num_bufs_acked; xx++) - { - BT_HDR *p_tmp = (BT_HDR *)fixed_queue_try_dequeue(p_fcrb->waiting_for_ack_q); - ls = p_tmp->layer_specific & L2CAP_FCR_SAR_BITS; + for (xx = 0; xx < num_bufs_acked; xx++) { + BT_HDR* p_tmp = + (BT_HDR*)fixed_queue_try_dequeue(p_fcrb->waiting_for_ack_q); + ls = p_tmp->layer_specific & L2CAP_FCR_SAR_BITS; - if ( (ls == L2CAP_FCR_UNSEG_SDU) || (ls == L2CAP_FCR_END_SDU) ) - full_sdus_xmitted++; + if ((ls == L2CAP_FCR_UNSEG_SDU) || (ls == L2CAP_FCR_END_SDU)) + full_sdus_xmitted++; - osi_free(p_tmp); - } + osi_free(p_tmp); + } - /* If we are still in a wait_ack state, do not mess with the timer */ - if (!p_ccb->fcrb.wait_ack) - l2c_fcr_stop_timer (p_ccb); - - /* Check if we need to call the "packet_sent" callback */ - if ( (p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && (full_sdus_xmitted) ) - { - /* Special case for eRTM, if all packets sent, send 0xFFFF */ - if (fixed_queue_is_empty(p_fcrb->waiting_for_ack_q) && - fixed_queue_is_empty(p_ccb->xmit_hold_q)) { - full_sdus_xmitted = 0xFFFF; - } + /* If we are still in a wait_ack state, do not mess with the timer */ + if (!p_ccb->fcrb.wait_ack) l2c_fcr_stop_timer(p_ccb); - (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, full_sdus_xmitted); - } + /* Check if we need to call the "packet_sent" callback */ + if ((p_ccb->p_rcb) && (p_ccb->p_rcb->api.pL2CA_TxComplete_Cb) && + (full_sdus_xmitted)) { + /* Special case for eRTM, if all packets sent, send 0xFFFF */ + if (fixed_queue_is_empty(p_fcrb->waiting_for_ack_q) && + fixed_queue_is_empty(p_ccb->xmit_hold_q)) { + full_sdus_xmitted = 0xFFFF; + } + + (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, + full_sdus_xmitted); } + } - /* If anything still waiting for ack, restart the timer if it was stopped */ - if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) - l2c_fcr_start_timer(p_ccb); - return (true); + /* If anything still waiting for ack, restart the timer if it was stopped */ + if (!fixed_queue_is_empty(p_fcrb->waiting_for_ack_q)) + l2c_fcr_start_timer(p_ccb); + return (true); } - /******************************************************************************* * * Function process_s_frame @@ -1057,83 +1046,80 @@ static bool process_reqseq (tL2C_CCB *p_ccb, uint16_t ctrl_word) * Returns - * ******************************************************************************/ -static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); +static void process_s_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, + uint16_t ctrl_word) { + assert(p_ccb != NULL); + assert(p_buf != NULL); - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; - uint16_t s_frame_type = (ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT; - bool remote_was_busy; - bool all_ok = true; + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; + uint16_t s_frame_type = + (ctrl_word & L2CAP_FCR_SUP_BITS) >> L2CAP_FCR_SUP_SHIFT; + bool remote_was_busy; + bool all_ok = true; - if (p_buf->len != 0) - { - L2CAP_TRACE_WARNING ("Incorrect S-frame Length (%d)", p_buf->len); - } + if (p_buf->len != 0) { + L2CAP_TRACE_WARNING("Incorrect S-frame Length (%d)", p_buf->len); + } - L2CAP_TRACE_DEBUG ("process_s_frame ctrl_word 0x%04x fcrb_remote_busy:%d", ctrl_word, p_fcrb->remote_busy); + L2CAP_TRACE_DEBUG("process_s_frame ctrl_word 0x%04x fcrb_remote_busy:%d", + ctrl_word, p_fcrb->remote_busy); #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.s_frames_rcvd[s_frame_type]++; + p_ccb->fcrb.s_frames_rcvd[s_frame_type]++; #endif - if (ctrl_word & L2CAP_FCR_P_BIT) - { - p_fcrb->rej_sent = false; /* After checkpoint, we can send anoher REJ */ - p_fcrb->send_f_rsp = true; /* Set a flag in case an I-frame is pending */ - } + if (ctrl_word & L2CAP_FCR_P_BIT) { + p_fcrb->rej_sent = false; /* After checkpoint, we can send anoher REJ */ + p_fcrb->send_f_rsp = true; /* Set a flag in case an I-frame is pending */ + } - switch (s_frame_type) - { + switch (s_frame_type) { case L2CAP_FCR_SUP_RR: - remote_was_busy = p_fcrb->remote_busy; - p_fcrb->remote_busy = false; + remote_was_busy = p_fcrb->remote_busy; + p_fcrb->remote_busy = false; - if ( (ctrl_word & L2CAP_FCR_F_BIT) || (remote_was_busy) ) - all_ok = retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS); - break; + if ((ctrl_word & L2CAP_FCR_F_BIT) || (remote_was_busy)) + all_ok = retransmit_i_frames(p_ccb, L2C_FCR_RETX_ALL_PKTS); + break; case L2CAP_FCR_SUP_REJ: - p_fcrb->remote_busy = false; - all_ok = retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS); - break; + p_fcrb->remote_busy = false; + all_ok = retransmit_i_frames(p_ccb, L2C_FCR_RETX_ALL_PKTS); + break; case L2CAP_FCR_SUP_RNR: - p_fcrb->remote_busy = true; - l2c_fcr_stop_timer (p_ccb); - break; + p_fcrb->remote_busy = true; + l2c_fcr_stop_timer(p_ccb); + break; case L2CAP_FCR_SUP_SREJ: - p_fcrb->remote_busy = false; - all_ok = retransmit_i_frames (p_ccb, (uint8_t)((ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT)); - break; - } - - if (all_ok) - { - /* If polled, we need to respond with F-bit. Note, we may have sent a I-frame with the F-bit */ - if (p_fcrb->send_f_rsp) - { - if (p_fcrb->srej_sent) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT); - else if (p_fcrb->local_busy) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT); - - p_fcrb->send_f_rsp = false; - } - } - else - { - L2CAP_TRACE_DEBUG ("process_s_frame hit_max_retries"); - } - - osi_free(p_buf); + p_fcrb->remote_busy = false; + all_ok = retransmit_i_frames( + p_ccb, (uint8_t)((ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> + L2CAP_FCR_REQ_SEQ_BITS_SHIFT)); + break; + } + + if (all_ok) { + /* If polled, we need to respond with F-bit. Note, we may have sent a + * I-frame with the F-bit */ + if (p_fcrb->send_f_rsp) { + if (p_fcrb->srej_sent) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_SREJ, L2CAP_FCR_F_BIT); + else if (p_fcrb->local_busy) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, L2CAP_FCR_F_BIT); + else + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, L2CAP_FCR_F_BIT); + + p_fcrb->send_f_rsp = false; + } + } else { + L2CAP_TRACE_DEBUG("process_s_frame hit_max_retries"); + } + + osi_free(p_buf); } - /******************************************************************************* * * Function process_i_frame @@ -1143,186 +1129,193 @@ static void process_s_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word) * Returns - * ******************************************************************************/ -static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word, bool delay_ack) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); +static void process_i_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf, uint16_t ctrl_word, + bool delay_ack) { + assert(p_ccb != NULL); + assert(p_buf != NULL); - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; - uint8_t tx_seq, num_lost, num_to_ack, next_srej; + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; + uint8_t tx_seq, num_lost, num_to_ack, next_srej; - /* If we were doing checkpoint recovery, first retransmit all unacked I-frames */ - if (ctrl_word & L2CAP_FCR_F_BIT) - { - if (!retransmit_i_frames (p_ccb, L2C_FCR_RETX_ALL_PKTS)) - { - osi_free(p_buf); - return; - } + /* If we were doing checkpoint recovery, first retransmit all unacked I-frames + */ + if (ctrl_word & L2CAP_FCR_F_BIT) { + if (!retransmit_i_frames(p_ccb, L2C_FCR_RETX_ALL_PKTS)) { + osi_free(p_buf); + return; } + } #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.ertm_pkt_counts[1]++; - p_ccb->fcrb.ertm_byte_counts[1] += p_buf->len; + p_ccb->fcrb.ertm_pkt_counts[1]++; + p_ccb->fcrb.ertm_byte_counts[1] += p_buf->len; #endif - /* Extract the sequence number */ - tx_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; - - /* If we have flow controlled the peer, ignore any bad I-frames from him */ - if ( (tx_seq != p_fcrb->next_seq_expected) && (p_fcrb->local_busy) ) - { - L2CAP_TRACE_WARNING ("Dropping bad I-Frame since we flowed off, tx_seq:%u", tx_seq); - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0); - osi_free(p_buf); - return; - } - - /* Check if tx-sequence is the expected one */ - if (tx_seq != p_fcrb->next_seq_expected) - { - num_lost = (tx_seq - p_fcrb->next_seq_expected) & L2CAP_FCR_SEQ_MODULO; - - /* Is the frame a duplicate ? If so, just drop it */ - if (num_lost >= p_ccb->our_cfg.fcr.tx_win_sz) - { - /* Duplicate - simply drop it */ - L2CAP_TRACE_WARNING ("process_i_frame() Dropping Duplicate Frame tx_seq:%u ExpectedTxSeq %u", tx_seq, p_fcrb->next_seq_expected); - osi_free(p_buf); - } - else - { - L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x Lost: %u tx_seq:%u ExpTxSeq %u Rej: %u SRej: %u", - p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent, p_fcrb->srej_sent); - - if (p_fcrb->srej_sent) - { - /* If SREJ sent, save the frame for later processing as long as it is in sequence */ - next_srej = (((BT_HDR *)fixed_queue_try_peek_last(p_fcrb->srej_rcv_hold_q))->layer_specific + 1) & L2CAP_FCR_SEQ_MODULO; - - if ( (tx_seq == next_srej) && (fixed_queue_length(p_fcrb->srej_rcv_hold_q) < p_ccb->our_cfg.fcr.tx_win_sz) ) - { - /* If user gave us a pool for held rx buffers, use that */ - /* TODO: Could that happen? Get rid of this code. */ - if (p_ccb->ertm_info.fcr_rx_buf_size != L2CAP_FCR_RX_BUF_SIZE) - { - BT_HDR *p_buf2; - - /* Adjust offset and len so that control word is copied */ - p_buf->offset -= L2CAP_FCR_OVERHEAD; - p_buf->len += L2CAP_FCR_OVERHEAD; - - p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); - - if (p_buf2) - { - osi_free(p_buf); - p_buf = p_buf2; - } - p_buf->offset += L2CAP_FCR_OVERHEAD; - p_buf->len -= L2CAP_FCR_OVERHEAD; - } - L2CAP_TRACE_DEBUG ("process_i_frame() Lost: %u tx_seq:%u ExpTxSeq %u Rej: %u SRej1", - num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent); - - p_buf->layer_specific = tx_seq; - fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); - } - else - { - L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x frame dropped in Srej Sent next_srej:%u hold_q.count:%u win_sz:%u", - p_ccb->local_cid, next_srej, fixed_queue_length(p_fcrb->srej_rcv_hold_q), p_ccb->our_cfg.fcr.tx_win_sz); - - p_fcrb->rej_after_srej = true; - osi_free(p_buf); - } - } - else if (p_fcrb->rej_sent) - { - L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x Lost: %u tx_seq:%u ExpTxSeq %u Rej: 1 SRej: %u", - p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->srej_sent); - - /* If REJ sent, just drop the frame */ - osi_free(p_buf); - } - else - { - L2CAP_TRACE_DEBUG ("process_i_frame() CID: 0x%04x tx_seq:%u ExpTxSeq %u Rej: %u", - p_ccb->local_cid, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent); - - /* If only one lost, we will send SREJ, otherwise we will send REJ */ - if (num_lost > 1) - { - osi_free(p_buf); - p_fcrb->rej_sent = true; - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_REJ, 0); - } - else - { - if (!fixed_queue_is_empty(p_fcrb->srej_rcv_hold_q)) - { - L2CAP_TRACE_ERROR ("process_i_frame() CID: 0x%04x sending SREJ tx_seq:%d hold_q.count:%u", - p_ccb->local_cid, tx_seq, fixed_queue_length(p_fcrb->srej_rcv_hold_q)); - } - p_buf->layer_specific = tx_seq; - fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); - p_fcrb->srej_sent = true; - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, 0); - } - alarm_cancel(p_ccb->fcrb.ack_timer); - } - } - return; - } - - /* Seq number is the next expected. Clear possible reject exception in case it occured */ - p_fcrb->rej_sent = p_fcrb->srej_sent = false; - - /* Adjust the next_seq, so that if the upper layer sends more data in the callback - context, the received frame is acked by an I-frame. */ - p_fcrb->next_seq_expected = (tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; - - /* If any SAR problem in eRTM mode, spec says disconnect. */ - if (!do_sar_reassembly (p_ccb, p_buf, ctrl_word)) - { - L2CAP_TRACE_WARNING ("process_i_frame() CID: 0x%04x reassembly failed", p_ccb->local_cid); - l2cu_disconnect_chnl (p_ccb); - return; - } - - /* RR optimization - if peer can still send us more, then start an ACK timer */ - num_to_ack = (p_fcrb->next_seq_expected - p_fcrb->last_ack_sent) & L2CAP_FCR_SEQ_MODULO; + /* Extract the sequence number */ + tx_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; - if ( (num_to_ack < p_ccb->fcrb.max_held_acks) && (!p_fcrb->local_busy) ) - delay_ack = true; - - /* We should neve never ack frame if we are not in OPEN state */ - if ((num_to_ack != 0) && p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) - { - /* If no frames are awaiting transmission or are held, send an RR or RNR S-frame for ack */ - if (delay_ack) - { - /* If it is the first I frame we did not ack, start ack timer */ - if (!alarm_is_scheduled(p_ccb->fcrb.ack_timer)) { - alarm_set_on_queue(p_ccb->fcrb.ack_timer, - L2CAP_FCR_ACK_TIMEOUT_MS, - l2c_fcrb_ack_timer_timeout, p_ccb, - btu_general_alarm_queue); + /* If we have flow controlled the peer, ignore any bad I-frames from him */ + if ((tx_seq != p_fcrb->next_seq_expected) && (p_fcrb->local_busy)) { + L2CAP_TRACE_WARNING("Dropping bad I-Frame since we flowed off, tx_seq:%u", + tx_seq); + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, 0); + osi_free(p_buf); + return; + } + + /* Check if tx-sequence is the expected one */ + if (tx_seq != p_fcrb->next_seq_expected) { + num_lost = (tx_seq - p_fcrb->next_seq_expected) & L2CAP_FCR_SEQ_MODULO; + + /* Is the frame a duplicate ? If so, just drop it */ + if (num_lost >= p_ccb->our_cfg.fcr.tx_win_sz) { + /* Duplicate - simply drop it */ + L2CAP_TRACE_WARNING( + "process_i_frame() Dropping Duplicate Frame tx_seq:%u ExpectedTxSeq " + "%u", + tx_seq, p_fcrb->next_seq_expected); + osi_free(p_buf); + } else { + L2CAP_TRACE_WARNING( + "process_i_frame() CID: 0x%04x Lost: %u tx_seq:%u ExpTxSeq %u " + "Rej: %u SRej: %u", + p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, + p_fcrb->rej_sent, p_fcrb->srej_sent); + + if (p_fcrb->srej_sent) { + /* If SREJ sent, save the frame for later processing as long as it is in + * sequence */ + next_srej = + (((BT_HDR*)fixed_queue_try_peek_last(p_fcrb->srej_rcv_hold_q)) + ->layer_specific + + 1) & + L2CAP_FCR_SEQ_MODULO; + + if ((tx_seq == next_srej) && + (fixed_queue_length(p_fcrb->srej_rcv_hold_q) < + p_ccb->our_cfg.fcr.tx_win_sz)) { + /* If user gave us a pool for held rx buffers, use that */ + /* TODO: Could that happen? Get rid of this code. */ + if (p_ccb->ertm_info.fcr_rx_buf_size != L2CAP_FCR_RX_BUF_SIZE) { + BT_HDR* p_buf2; + + /* Adjust offset and len so that control word is copied */ + p_buf->offset -= L2CAP_FCR_OVERHEAD; + p_buf->len += L2CAP_FCR_OVERHEAD; + + p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); + + if (p_buf2) { + osi_free(p_buf); + p_buf = p_buf2; } + p_buf->offset += L2CAP_FCR_OVERHEAD; + p_buf->len -= L2CAP_FCR_OVERHEAD; + } + L2CAP_TRACE_DEBUG( + "process_i_frame() Lost: %u tx_seq:%u ExpTxSeq %u Rej: %u " + "SRej1", + num_lost, tx_seq, p_fcrb->next_seq_expected, p_fcrb->rej_sent); + + p_buf->layer_specific = tx_seq; + fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); + } else { + L2CAP_TRACE_WARNING( + "process_i_frame() CID: 0x%04x frame dropped in Srej Sent " + "next_srej:%u hold_q.count:%u win_sz:%u", + p_ccb->local_cid, next_srej, + fixed_queue_length(p_fcrb->srej_rcv_hold_q), + p_ccb->our_cfg.fcr.tx_win_sz); + + p_fcrb->rej_after_srej = true; + osi_free(p_buf); } - else if ((fixed_queue_is_empty(p_ccb->xmit_hold_q) || - l2c_fcr_is_flow_controlled(p_ccb)) - && fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q)) - { - if (p_fcrb->local_busy) - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RNR, 0); - else - l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_RR, 0); + } else if (p_fcrb->rej_sent) { + L2CAP_TRACE_WARNING( + "process_i_frame() CID: 0x%04x Lost: %u tx_seq:%u ExpTxSeq %u " + "Rej: 1 SRej: %u", + p_ccb->local_cid, num_lost, tx_seq, p_fcrb->next_seq_expected, + p_fcrb->srej_sent); + + /* If REJ sent, just drop the frame */ + osi_free(p_buf); + } else { + L2CAP_TRACE_DEBUG( + "process_i_frame() CID: 0x%04x tx_seq:%u ExpTxSeq %u Rej: %u", + p_ccb->local_cid, tx_seq, p_fcrb->next_seq_expected, + p_fcrb->rej_sent); + + /* If only one lost, we will send SREJ, otherwise we will send REJ */ + if (num_lost > 1) { + osi_free(p_buf); + p_fcrb->rej_sent = true; + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_REJ, 0); + } else { + if (!fixed_queue_is_empty(p_fcrb->srej_rcv_hold_q)) { + L2CAP_TRACE_ERROR( + "process_i_frame() CID: 0x%04x sending SREJ tx_seq:%d " + "hold_q.count:%u", + p_ccb->local_cid, tx_seq, + fixed_queue_length(p_fcrb->srej_rcv_hold_q)); + } + p_buf->layer_specific = tx_seq; + fixed_queue_enqueue(p_fcrb->srej_rcv_hold_q, p_buf); + p_fcrb->srej_sent = true; + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_SREJ, 0); } + alarm_cancel(p_ccb->fcrb.ack_timer); + } } + return; + } + + /* Seq number is the next expected. Clear possible reject exception in case it + * occured */ + p_fcrb->rej_sent = p_fcrb->srej_sent = false; + + /* Adjust the next_seq, so that if the upper layer sends more data in the + callback + context, the received frame is acked by an I-frame. */ + p_fcrb->next_seq_expected = (tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; + + /* If any SAR problem in eRTM mode, spec says disconnect. */ + if (!do_sar_reassembly(p_ccb, p_buf, ctrl_word)) { + L2CAP_TRACE_WARNING("process_i_frame() CID: 0x%04x reassembly failed", + p_ccb->local_cid); + l2cu_disconnect_chnl(p_ccb); + return; + } + + /* RR optimization - if peer can still send us more, then start an ACK timer + */ + num_to_ack = (p_fcrb->next_seq_expected - p_fcrb->last_ack_sent) & + L2CAP_FCR_SEQ_MODULO; + + if ((num_to_ack < p_ccb->fcrb.max_held_acks) && (!p_fcrb->local_busy)) + delay_ack = true; + + /* We should neve never ack frame if we are not in OPEN state */ + if ((num_to_ack != 0) && p_ccb->in_use && (p_ccb->chnl_state == CST_OPEN)) { + /* If no frames are awaiting transmission or are held, send an RR or RNR + * S-frame for ack */ + if (delay_ack) { + /* If it is the first I frame we did not ack, start ack timer */ + if (!alarm_is_scheduled(p_ccb->fcrb.ack_timer)) { + alarm_set_on_queue(p_ccb->fcrb.ack_timer, L2CAP_FCR_ACK_TIMEOUT_MS, + l2c_fcrb_ack_timer_timeout, p_ccb, + btu_general_alarm_queue); + } + } else if ((fixed_queue_is_empty(p_ccb->xmit_hold_q) || + l2c_fcr_is_flow_controlled(p_ccb)) && + fixed_queue_is_empty(p_ccb->fcrb.srej_rcv_hold_q)) { + if (p_fcrb->local_busy) + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RNR, 0); + else + l2c_fcr_send_S_frame(p_ccb, L2CAP_FCR_SUP_RR, 0); + } + } } - /******************************************************************************* * * Function process_stream_frame @@ -1332,79 +1325,81 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word, * Returns - * ******************************************************************************/ -static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); - - uint16_t ctrl_word; - uint16_t fcs; - uint8_t *p; - uint8_t tx_seq; - - /* Verify FCS if using */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - { - p = ((uint8_t *)(p_buf+1)) + p_buf->offset + p_buf->len - L2CAP_FCS_LEN; - - /* Extract and drop the FCS from the packet */ - STREAM_TO_UINT16 (fcs, p); - p_buf->len -= L2CAP_FCS_LEN; - - if (l2c_fcr_rx_get_fcs(p_buf) != fcs) - { - L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD FCS", p_ccb->local_cid); - osi_free(p_buf); - return; - } - } +static void process_stream_frame(tL2C_CCB* p_ccb, BT_HDR* p_buf) { + assert(p_ccb != NULL); + assert(p_buf != NULL); - /* Get the control word */ - p = ((uint8_t *)(p_buf+1)) + p_buf->offset; + uint16_t ctrl_word; + uint16_t fcs; + uint8_t* p; + uint8_t tx_seq; - STREAM_TO_UINT16 (ctrl_word, p); + /* Verify FCS if using */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + p_buf->len - L2CAP_FCS_LEN; - p_buf->len -= L2CAP_FCR_OVERHEAD; - p_buf->offset += L2CAP_FCR_OVERHEAD; + /* Extract and drop the FCS from the packet */ + STREAM_TO_UINT16(fcs, p); + p_buf->len -= L2CAP_FCS_LEN; - /* Make sure it is an I-frame */ - if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) - { - L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x BAD S-frame in streaming mode ctrl_word: 0x%04x", p_ccb->local_cid, ctrl_word); - osi_free(p_buf); - return; + if (l2c_fcr_rx_get_fcs(p_buf) != fcs) { + L2CAP_TRACE_WARNING("Rx L2CAP PDU: CID: 0x%04x BAD FCS", + p_ccb->local_cid); + osi_free(p_buf); + return; } + } - L2CAP_TRACE_EVENT ("L2CAP eRTM Rx I-frame: cid: 0x%04x Len: %u SAR: %-12s TxSeq: %u ReqSeq: %u F: %u", - p_ccb->local_cid, p_buf->len, - SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], - (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, - (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); - - /* Extract the sequence number */ - tx_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; + /* Get the control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; - /* Check if tx-sequence is the expected one */ - if (tx_seq != p_ccb->fcrb.next_seq_expected) - { - L2CAP_TRACE_WARNING ("Rx L2CAP PDU: CID: 0x%04x Lost frames Exp: %u Got: %u p_rx_sdu: 0x%08x", - p_ccb->local_cid, p_ccb->fcrb.next_seq_expected, tx_seq, p_ccb->fcrb.p_rx_sdu); - - /* Lost one or more packets, so flush the SAR queue */ - osi_free_and_reset((void **)&p_ccb->fcrb.p_rx_sdu); - } + STREAM_TO_UINT16(ctrl_word, p); - p_ccb->fcrb.next_seq_expected = (tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; + p_buf->len -= L2CAP_FCR_OVERHEAD; + p_buf->offset += L2CAP_FCR_OVERHEAD; - if (!do_sar_reassembly (p_ccb, p_buf, ctrl_word)) - { - /* Some sort of SAR error, so flush the SAR queue */ - osi_free_and_reset((void **)&p_ccb->fcrb.p_rx_sdu); - } + /* Make sure it is an I-frame */ + if (ctrl_word & L2CAP_FCR_S_FRAME_BIT) { + L2CAP_TRACE_WARNING( + "Rx L2CAP PDU: CID: 0x%04x BAD S-frame in streaming mode ctrl_word: " + "0x%04x", + p_ccb->local_cid, ctrl_word); + osi_free(p_buf); + return; + } + + L2CAP_TRACE_EVENT( + "L2CAP eRTM Rx I-frame: cid: 0x%04x Len: %u SAR: %-12s TxSeq: %u " + "ReqSeq: %u F: %u", + p_ccb->local_cid, p_buf->len, + SAR_types[(ctrl_word & L2CAP_FCR_SAR_BITS) >> L2CAP_FCR_SAR_BITS_SHIFT], + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_REQ_SEQ_BITS) >> L2CAP_FCR_REQ_SEQ_BITS_SHIFT, + (ctrl_word & L2CAP_FCR_F_BIT) >> L2CAP_FCR_F_BIT_SHIFT); + + /* Extract the sequence number */ + tx_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; + + /* Check if tx-sequence is the expected one */ + if (tx_seq != p_ccb->fcrb.next_seq_expected) { + L2CAP_TRACE_WARNING( + "Rx L2CAP PDU: CID: 0x%04x Lost frames Exp: %u Got: %u p_rx_sdu: " + "0x%08x", + p_ccb->local_cid, p_ccb->fcrb.next_seq_expected, tx_seq, + p_ccb->fcrb.p_rx_sdu); + + /* Lost one or more packets, so flush the SAR queue */ + osi_free_and_reset((void**)&p_ccb->fcrb.p_rx_sdu); + } + + p_ccb->fcrb.next_seq_expected = (tx_seq + 1) & L2CAP_FCR_SEQ_MODULO; + + if (!do_sar_reassembly(p_ccb, p_buf, ctrl_word)) { + /* Some sort of SAR error, so flush the SAR queue */ + osi_free_and_reset((void**)&p_ccb->fcrb.p_rx_sdu); + } } - /******************************************************************************* * * Function do_sar_reassembly @@ -1414,120 +1409,110 @@ static void process_stream_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf) * Returns true if all OK, else false * ******************************************************************************/ -static bool do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_word) -{ - assert(p_ccb != NULL); - assert(p_buf != NULL); - - tL2C_FCRB *p_fcrb = &p_ccb->fcrb; - uint16_t sar_type = ctrl_word & L2CAP_FCR_SEG_BITS; - bool packet_ok = true; - uint8_t *p; - - /* Check if the SAR state is correct */ - if ((sar_type == L2CAP_FCR_UNSEG_SDU) || (sar_type == L2CAP_FCR_START_SDU)) - { - if (p_fcrb->p_rx_sdu != NULL) - { - L2CAP_TRACE_WARNING ("SAR - got unexpected unsegmented or start SDU Expected len: %u Got so far: %u", - p_fcrb->rx_sdu_len, p_fcrb->p_rx_sdu->len); - - packet_ok = false; - } - /* Check the length of the packet */ - if ( (sar_type == L2CAP_FCR_START_SDU) && (p_buf->len < L2CAP_SDU_LEN_OVERHEAD) ) - { - L2CAP_TRACE_WARNING ("SAR start packet too short: %u", p_buf->len); - packet_ok = false; - } - } - else - { - if (p_fcrb->p_rx_sdu == NULL) - { - L2CAP_TRACE_WARNING ("SAR - got unexpected cont or end SDU"); - packet_ok = false; - } - } - - if ( (packet_ok) && (sar_type != L2CAP_FCR_UNSEG_SDU) ) - { - p = ((uint8_t *)(p_buf + 1)) + p_buf->offset; - - /* For start SDU packet, extract the SDU length */ - if (sar_type == L2CAP_FCR_START_SDU) - { - /* Get the SDU length */ - STREAM_TO_UINT16 (p_fcrb->rx_sdu_len, p); - p_buf->offset += 2; - p_buf->len -= 2; - - if (p_fcrb->rx_sdu_len > p_ccb->max_rx_mtu) - { - L2CAP_TRACE_WARNING ("SAR - SDU len: %u larger than MTU: %u", p_fcrb->rx_sdu_len, p_fcrb->rx_sdu_len); - packet_ok = false; - } else { - p_fcrb->p_rx_sdu = (BT_HDR *)osi_malloc(L2CAP_MAX_BUF_SIZE); - p_fcrb->p_rx_sdu->offset = OBX_BUF_MIN_OFFSET; - p_fcrb->p_rx_sdu->len = 0; - } - } - - if (packet_ok) - { - if ((p_fcrb->p_rx_sdu->len + p_buf->len) > p_fcrb->rx_sdu_len) - { - L2CAP_TRACE_ERROR ("SAR - SDU len exceeded Type: %u Lengths: %u %u %u", - sar_type, p_fcrb->p_rx_sdu->len, p_buf->len, p_fcrb->rx_sdu_len); - packet_ok = false; - } - else if ( (sar_type == L2CAP_FCR_END_SDU) && ((p_fcrb->p_rx_sdu->len + p_buf->len) != p_fcrb->rx_sdu_len) ) - { - L2CAP_TRACE_WARNING ("SAR - SDU end rcvd but SDU incomplete: %u %u %u", - p_fcrb->p_rx_sdu->len, p_buf->len, p_fcrb->rx_sdu_len); - packet_ok = false; - } - else - { - memcpy (((uint8_t *) (p_fcrb->p_rx_sdu + 1)) + p_fcrb->p_rx_sdu->offset + p_fcrb->p_rx_sdu->len, p, p_buf->len); - - p_fcrb->p_rx_sdu->len += p_buf->len; +static bool do_sar_reassembly(tL2C_CCB* p_ccb, BT_HDR* p_buf, + uint16_t ctrl_word) { + assert(p_ccb != NULL); + assert(p_buf != NULL); + + tL2C_FCRB* p_fcrb = &p_ccb->fcrb; + uint16_t sar_type = ctrl_word & L2CAP_FCR_SEG_BITS; + bool packet_ok = true; + uint8_t* p; + + /* Check if the SAR state is correct */ + if ((sar_type == L2CAP_FCR_UNSEG_SDU) || (sar_type == L2CAP_FCR_START_SDU)) { + if (p_fcrb->p_rx_sdu != NULL) { + L2CAP_TRACE_WARNING( + "SAR - got unexpected unsegmented or start SDU Expected len: %u " + "Got so far: %u", + p_fcrb->rx_sdu_len, p_fcrb->p_rx_sdu->len); + + packet_ok = false; + } + /* Check the length of the packet */ + if ((sar_type == L2CAP_FCR_START_SDU) && + (p_buf->len < L2CAP_SDU_LEN_OVERHEAD)) { + L2CAP_TRACE_WARNING("SAR start packet too short: %u", p_buf->len); + packet_ok = false; + } + } else { + if (p_fcrb->p_rx_sdu == NULL) { + L2CAP_TRACE_WARNING("SAR - got unexpected cont or end SDU"); + packet_ok = false; + } + } + + if ((packet_ok) && (sar_type != L2CAP_FCR_UNSEG_SDU)) { + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset; + + /* For start SDU packet, extract the SDU length */ + if (sar_type == L2CAP_FCR_START_SDU) { + /* Get the SDU length */ + STREAM_TO_UINT16(p_fcrb->rx_sdu_len, p); + p_buf->offset += 2; + p_buf->len -= 2; + + if (p_fcrb->rx_sdu_len > p_ccb->max_rx_mtu) { + L2CAP_TRACE_WARNING("SAR - SDU len: %u larger than MTU: %u", + p_fcrb->rx_sdu_len, p_fcrb->rx_sdu_len); + packet_ok = false; + } else { + p_fcrb->p_rx_sdu = (BT_HDR*)osi_malloc(L2CAP_MAX_BUF_SIZE); + p_fcrb->p_rx_sdu->offset = OBX_BUF_MIN_OFFSET; + p_fcrb->p_rx_sdu->len = 0; + } + } + + if (packet_ok) { + if ((p_fcrb->p_rx_sdu->len + p_buf->len) > p_fcrb->rx_sdu_len) { + L2CAP_TRACE_ERROR( + "SAR - SDU len exceeded Type: %u Lengths: %u %u %u", sar_type, + p_fcrb->p_rx_sdu->len, p_buf->len, p_fcrb->rx_sdu_len); + packet_ok = false; + } else if ((sar_type == L2CAP_FCR_END_SDU) && + ((p_fcrb->p_rx_sdu->len + p_buf->len) != p_fcrb->rx_sdu_len)) { + L2CAP_TRACE_WARNING("SAR - SDU end rcvd but SDU incomplete: %u %u %u", + p_fcrb->p_rx_sdu->len, p_buf->len, + p_fcrb->rx_sdu_len); + packet_ok = false; + } else { + memcpy(((uint8_t*)(p_fcrb->p_rx_sdu + 1)) + p_fcrb->p_rx_sdu->offset + + p_fcrb->p_rx_sdu->len, + p, p_buf->len); + + p_fcrb->p_rx_sdu->len += p_buf->len; - osi_free(p_buf); - p_buf = NULL; + osi_free(p_buf); + p_buf = NULL; - if (sar_type == L2CAP_FCR_END_SDU) - { - p_buf = p_fcrb->p_rx_sdu; - p_fcrb->p_rx_sdu = NULL; - } - } + if (sar_type == L2CAP_FCR_END_SDU) { + p_buf = p_fcrb->p_rx_sdu; + p_fcrb->p_rx_sdu = NULL; } + } } + } - if (packet_ok == false) - { - osi_free(p_buf); - } - else if (p_buf != NULL) - { + if (packet_ok == false) { + osi_free(p_buf); + } else if (p_buf != NULL) { #if (L2CAP_NUM_FIXED_CHNLS > 0) - if (p_ccb->local_cid < L2CAP_BASE_APPL_CID && - (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL && p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL)) - { - if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb) - (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb) - (p_ccb->local_cid, p_ccb->p_lcb->remote_bd_addr, p_buf); - } - else + if (p_ccb->local_cid < L2CAP_BASE_APPL_CID && + (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL && + p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL)) { + if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL] + .pL2CA_FixedData_Cb) + (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL] + .pL2CA_FixedData_Cb)(p_ccb->local_cid, + p_ccb->p_lcb->remote_bd_addr, p_buf); + } else #endif - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DATA, p_buf); - } + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DATA, p_buf); + } - return (packet_ok); + return (packet_ok); } - /******************************************************************************* * * Function retransmit_i_frames @@ -1537,118 +1522,112 @@ static bool do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, uint16_t ctrl_ * Returns bool - true if retransmitted * ******************************************************************************/ -static bool retransmit_i_frames (tL2C_CCB *p_ccb, uint8_t tx_seq) -{ - assert(p_ccb != NULL); - - BT_HDR *p_buf = NULL; - uint8_t *p; - uint8_t buf_seq; - uint16_t ctrl_word; - - if ( (!fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) - && (p_ccb->peer_cfg.fcr.max_transmit != 0) - && (p_ccb->fcrb.num_tries >= p_ccb->peer_cfg.fcr.max_transmit) ) - { - L2CAP_TRACE_EVENT ("Max Tries Exceeded: (last_acq: %d CID: 0x%04x num_tries: %u (max: %u) ack_q_count: %u", - p_ccb->fcrb.last_rx_ack, p_ccb->local_cid, p_ccb->fcrb.num_tries, p_ccb->peer_cfg.fcr.max_transmit, - fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); +static bool retransmit_i_frames(tL2C_CCB* p_ccb, uint8_t tx_seq) { + assert(p_ccb != NULL); + + BT_HDR* p_buf = NULL; + uint8_t* p; + uint8_t buf_seq; + uint16_t ctrl_word; + + if ((!fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) && + (p_ccb->peer_cfg.fcr.max_transmit != 0) && + (p_ccb->fcrb.num_tries >= p_ccb->peer_cfg.fcr.max_transmit)) { + L2CAP_TRACE_EVENT( + "Max Tries Exceeded: (last_acq: %d CID: 0x%04x num_tries: %u (max: " + "%u) ack_q_count: %u", + p_ccb->fcrb.last_rx_ack, p_ccb->local_cid, p_ccb->fcrb.num_tries, + p_ccb->peer_cfg.fcr.max_transmit, + fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); + + l2cu_disconnect_chnl(p_ccb); + return (false); + } + + /* tx_seq indicates whether to retransmit a specific sequence or all (if == + * L2C_FCR_RETX_ALL_PKTS) */ + list_t* list_ack = NULL; + const list_node_t* node_ack = NULL; + if (!fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) { + list_ack = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q); + node_ack = list_begin(list_ack); + } + if (tx_seq != L2C_FCR_RETX_ALL_PKTS) { + /* If sending only one, the sequence number tells us which one. Look for it. + */ + if (list_ack != NULL) { + for (; node_ack != list_end(list_ack); node_ack = list_next(node_ack)) { + p_buf = (BT_HDR*)list_node(node_ack); + /* Get the old control word */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; - l2cu_disconnect_chnl (p_ccb); - return (false); - } + STREAM_TO_UINT16(ctrl_word, p); - /* tx_seq indicates whether to retransmit a specific sequence or all (if == L2C_FCR_RETX_ALL_PKTS) */ - list_t *list_ack = NULL; - const list_node_t *node_ack = NULL; - if (! fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) { - list_ack = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q); - node_ack = list_begin(list_ack); - } - if (tx_seq != L2C_FCR_RETX_ALL_PKTS) - { - /* If sending only one, the sequence number tells us which one. Look for it. - */ - if (list_ack != NULL) { - for ( ; node_ack != list_end(list_ack); node_ack = list_next(node_ack)) { - p_buf = (BT_HDR *)list_node(node_ack); - /* Get the old control word */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset + L2CAP_PKT_OVERHEAD; - - STREAM_TO_UINT16 (ctrl_word, p); + buf_seq = + (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; - buf_seq = (ctrl_word & L2CAP_FCR_TX_SEQ_BITS) >> L2CAP_FCR_TX_SEQ_BITS_SHIFT; + L2CAP_TRACE_DEBUG( + "retransmit_i_frames() cur seq: %u looking for: %u", buf_seq, + tx_seq); - L2CAP_TRACE_DEBUG ("retransmit_i_frames() cur seq: %u looking for: %u", buf_seq, tx_seq); + if (tx_seq == buf_seq) break; + } + } - if (tx_seq == buf_seq) - break; - } - } + if (!p_buf) { + L2CAP_TRACE_ERROR("retransmit_i_frames() UNKNOWN seq: %u q_count: %u", + tx_seq, + fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); + return (true); + } + } else { + // Iterate though list and flush the amount requested from + // the transmit data queue that satisfy the layer and event conditions. + for (list_node_t* node_tmp = list_begin(p_ccb->p_lcb->link_xmit_data_q); + node_tmp != list_end(p_ccb->p_lcb->link_xmit_data_q);) { + BT_HDR* p_tmp = (BT_HDR*)list_node(node_tmp); + node_tmp = list_next(node_tmp); - if (!p_buf) - { - L2CAP_TRACE_ERROR ("retransmit_i_frames() UNKNOWN seq: %u q_count: %u", - tx_seq, - fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)); - return (true); - } + /* Do not flush other CIDs or partial segments */ + if ((p_tmp->layer_specific == 0) && (p_tmp->event == p_ccb->local_cid)) { + list_remove(p_ccb->p_lcb->link_xmit_data_q, p_tmp); + osi_free(p_tmp); + } } - else - { - // Iterate though list and flush the amount requested from - // the transmit data queue that satisfy the layer and event conditions. - for (list_node_t *node_tmp = list_begin(p_ccb->p_lcb->link_xmit_data_q); - node_tmp != list_end(p_ccb->p_lcb->link_xmit_data_q);) { - BT_HDR *p_tmp = (BT_HDR *)list_node(node_tmp); - node_tmp = list_next(node_tmp); - - /* Do not flush other CIDs or partial segments */ - if ((p_tmp->layer_specific == 0) && (p_tmp->event == p_ccb->local_cid)) { - list_remove(p_ccb->p_lcb->link_xmit_data_q, p_tmp); - osi_free(p_tmp); - } - } - /* Also flush our retransmission queue */ - while (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) - osi_free(fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q)); + /* Also flush our retransmission queue */ + while (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) + osi_free(fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q)); - if (list_ack != NULL) - node_ack = list_begin(list_ack); - } + if (list_ack != NULL) node_ack = list_begin(list_ack); + } - if (list_ack != NULL) { - while (node_ack != list_end(list_ack)) - { - p_buf = (BT_HDR *)list_node(node_ack); - node_ack = list_next(node_ack); + if (list_ack != NULL) { + while (node_ack != list_end(list_ack)) { + p_buf = (BT_HDR*)list_node(node_ack); + node_ack = list_next(node_ack); - BT_HDR *p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); - if (p_buf2) - { - p_buf2->layer_specific = p_buf->layer_specific; + BT_HDR* p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); + if (p_buf2) { + p_buf2->layer_specific = p_buf->layer_specific; - fixed_queue_enqueue(p_ccb->fcrb.retrans_q, p_buf2); - } + fixed_queue_enqueue(p_ccb->fcrb.retrans_q, p_buf2); + } - if ( (tx_seq != L2C_FCR_RETX_ALL_PKTS) || (p_buf2 == NULL) ) - break; - } + if ((tx_seq != L2C_FCR_RETX_ALL_PKTS) || (p_buf2 == NULL)) break; } + } - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); - if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)) - { - p_ccb->fcrb.num_tries++; - l2c_fcr_start_timer (p_ccb); - } + if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q)) { + p_ccb->fcrb.num_tries++; + l2c_fcr_start_timer(p_ccb); + } - return (true); + return (true); } - /******************************************************************************* * * Function l2c_fcr_get_next_xmit_sdu_seg @@ -1658,174 +1637,161 @@ static bool retransmit_i_frames (tL2C_CCB *p_ccb, uint8_t tx_seq) * Returns pointer to buffer with segment or NULL * ******************************************************************************/ -BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_length) -{ - assert(p_ccb != NULL); - - bool first_seg = false, /* The segment is the first part of data */ - mid_seg = false, /* The segment is the middle part of data */ - last_seg = false; /* The segment is the last part of data */ - uint16_t sdu_len = 0; - BT_HDR *p_buf, *p_xmit; - uint8_t *p; - uint16_t max_pdu = p_ccb->tx_mps /* Needed? - L2CAP_MAX_HEADER_FCS*/; - - /* If there is anything in the retransmit queue, that goes first - */ - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q); - if (p_buf != NULL) - { - /* Update Rx Seq and FCS if we acked some packets while this one was queued */ - prepare_I_frame (p_ccb, p_buf, true); +BT_HDR* l2c_fcr_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb, + uint16_t max_packet_length) { + assert(p_ccb != NULL); + + bool first_seg = false, /* The segment is the first part of data */ + mid_seg = false, /* The segment is the middle part of data */ + last_seg = false; /* The segment is the last part of data */ + uint16_t sdu_len = 0; + BT_HDR *p_buf, *p_xmit; + uint8_t* p; + uint16_t max_pdu = p_ccb->tx_mps /* Needed? - L2CAP_MAX_HEADER_FCS*/; + + /* If there is anything in the retransmit queue, that goes first + */ + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->fcrb.retrans_q); + if (p_buf != NULL) { + /* Update Rx Seq and FCS if we acked some packets while this one was queued + */ + prepare_I_frame(p_ccb, p_buf, true); - p_buf->event = p_ccb->local_cid; + p_buf->event = p_ccb->local_cid; #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.pkts_retransmitted++; - p_ccb->fcrb.ertm_pkt_counts[0]++; - p_ccb->fcrb.ertm_byte_counts[0] += (p_buf->len - 8); + p_ccb->fcrb.pkts_retransmitted++; + p_ccb->fcrb.ertm_pkt_counts[0]++; + p_ccb->fcrb.ertm_byte_counts[0] += (p_buf->len - 8); #endif - return (p_buf); - } + return (p_buf); + } + + /* For BD/EDR controller, max_packet_length is set to 0 */ + /* For AMP controller, max_packet_length is set by available blocks */ + if ((max_packet_length > L2CAP_MAX_HEADER_FCS) && + (max_pdu + L2CAP_MAX_HEADER_FCS > max_packet_length)) { + max_pdu = max_packet_length - L2CAP_MAX_HEADER_FCS; + } + + p_buf = (BT_HDR*)fixed_queue_try_peek_first(p_ccb->xmit_hold_q); + + /* If there is more data than the MPS, it requires segmentation */ + if (p_buf->len > max_pdu) { + /* We are using the "event" field to tell is if we already started + * segmentation */ + if (p_buf->event == 0) { + first_seg = true; + sdu_len = p_buf->len; + } else + mid_seg = true; - /* For BD/EDR controller, max_packet_length is set to 0 */ - /* For AMP controller, max_packet_length is set by available blocks */ - if ( (max_packet_length > L2CAP_MAX_HEADER_FCS) - && (max_pdu + L2CAP_MAX_HEADER_FCS > max_packet_length) ) - { - max_pdu = max_packet_length - L2CAP_MAX_HEADER_FCS; - } - - p_buf = (BT_HDR *)fixed_queue_try_peek_first(p_ccb->xmit_hold_q); - - /* If there is more data than the MPS, it requires segmentation */ - if (p_buf->len > max_pdu) - { - /* We are using the "event" field to tell is if we already started segmentation */ - if (p_buf->event == 0) - { - first_seg = true; - sdu_len = p_buf->len; - } - else - mid_seg = true; - - /* Get a new buffer and copy the data that can be sent in a PDU */ - p_xmit = l2c_fcr_clone_buf(p_buf, L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET, - max_pdu); + /* Get a new buffer and copy the data that can be sent in a PDU */ + p_xmit = l2c_fcr_clone_buf(p_buf, L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET, + max_pdu); - if (p_xmit != NULL) - { - p_buf->event = p_ccb->local_cid; - p_xmit->event = p_ccb->local_cid; + if (p_xmit != NULL) { + p_buf->event = p_ccb->local_cid; + p_xmit->event = p_ccb->local_cid; - p_buf->len -= max_pdu; - p_buf->offset += max_pdu; + p_buf->len -= max_pdu; + p_buf->offset += max_pdu; - /* copy PBF setting */ - p_xmit->layer_specific = p_buf->layer_specific; - } - else /* Should never happen if the application has configured buffers correctly */ - { - L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer for segmentation, max_pdu: %u", max_pdu); - return (NULL); - } - } - else /* Use the original buffer if no segmentation, or the last segment */ + /* copy PBF setting */ + p_xmit->layer_specific = p_buf->layer_specific; + } else /* Should never happen if the application has configured buffers + correctly */ { - p_xmit = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + L2CAP_TRACE_ERROR( + "L2CAP - cannot get buffer for segmentation, max_pdu: %u", max_pdu); + return (NULL); + } + } else /* Use the original buffer if no segmentation, or the last segment */ + { + p_xmit = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); - if (p_xmit->event != 0) - last_seg = true; + if (p_xmit->event != 0) last_seg = true; - p_xmit->event = p_ccb->local_cid; - } + p_xmit->event = p_ccb->local_cid; + } - /* Step back to add the L2CAP headers */ - p_xmit->offset -= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD); - p_xmit->len += L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD; + /* Step back to add the L2CAP headers */ + p_xmit->offset -= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD); + p_xmit->len += L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD; - if (first_seg) - { - p_xmit->offset -= L2CAP_SDU_LEN_OVERHEAD; - p_xmit->len += L2CAP_SDU_LEN_OVERHEAD; - } + if (first_seg) { + p_xmit->offset -= L2CAP_SDU_LEN_OVERHEAD; + p_xmit->len += L2CAP_SDU_LEN_OVERHEAD; + } - /* Set the pointer to the beginning of the data */ - p = (uint8_t *)(p_xmit + 1) + p_xmit->offset; + /* Set the pointer to the beginning of the data */ + p = (uint8_t*)(p_xmit + 1) + p_xmit->offset; - /* Now the L2CAP header */ + /* Now the L2CAP header */ - /* Note: if FCS has to be included then the length is recalculated later */ - UINT16_TO_STREAM (p, p_xmit->len - L2CAP_PKT_OVERHEAD); + /* Note: if FCS has to be included then the length is recalculated later */ + UINT16_TO_STREAM(p, p_xmit->len - L2CAP_PKT_OVERHEAD); - UINT16_TO_STREAM (p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, p_ccb->remote_cid); - if (first_seg) - { - /* Skip control word and add SDU length */ - p += 2; - UINT16_TO_STREAM (p, sdu_len); + if (first_seg) { + /* Skip control word and add SDU length */ + p += 2; + UINT16_TO_STREAM(p, sdu_len); - /* We will store the SAR type in layer-specific */ - /* layer_specific is shared with flushable flag(bits 0-1), don't clear it */ - p_xmit->layer_specific |= L2CAP_FCR_START_SDU; + /* We will store the SAR type in layer-specific */ + /* layer_specific is shared with flushable flag(bits 0-1), don't clear it */ + p_xmit->layer_specific |= L2CAP_FCR_START_SDU; - first_seg = false; - } - else if (mid_seg) - p_xmit->layer_specific |= L2CAP_FCR_CONT_SDU; - else if (last_seg) - p_xmit->layer_specific |= L2CAP_FCR_END_SDU; - else - p_xmit->layer_specific |= L2CAP_FCR_UNSEG_SDU; + first_seg = false; + } else if (mid_seg) + p_xmit->layer_specific |= L2CAP_FCR_CONT_SDU; + else if (last_seg) + p_xmit->layer_specific |= L2CAP_FCR_END_SDU; + else + p_xmit->layer_specific |= L2CAP_FCR_UNSEG_SDU; - prepare_I_frame (p_ccb, p_xmit, false); + prepare_I_frame(p_ccb, p_xmit, false); - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - { - BT_HDR *p_wack = l2c_fcr_clone_buf(p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len); + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { + BT_HDR* p_wack = + l2c_fcr_clone_buf(p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len); - if (!p_wack) - { - L2CAP_TRACE_ERROR("L2CAP - no buffer for xmit cloning, CID: 0x%04x Length: %u", - p_ccb->local_cid, p_xmit->len); + if (!p_wack) { + L2CAP_TRACE_ERROR( + "L2CAP - no buffer for xmit cloning, CID: 0x%04x Length: %u", + p_ccb->local_cid, p_xmit->len); - /* We will not save the FCS in case we reconfigure and change options */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - p_xmit->len -= L2CAP_FCS_LEN; + /* We will not save the FCS in case we reconfigure and change options */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) p_xmit->len -= L2CAP_FCS_LEN; - /* Pretend we sent it and it got lost */ - fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_xmit); - return (NULL); - } - else - { + /* Pretend we sent it and it got lost */ + fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_xmit); + return (NULL); + } else { #if (L2CAP_ERTM_STATS == TRUE) - /* set timestamp at the end of tx I-frame to get acking delay */ - /* - * NOTE: Here we assume the allocate buffer is large enough - * to include extra 4 octets at the end. - */ - p = ((uint8_t *) (p_wack+1)) + p_wack->offset + p_wack->len; - UINT32_TO_STREAM (p, time_get_os_boottime_ms()); + /* set timestamp at the end of tx I-frame to get acking delay */ + /* + * NOTE: Here we assume the allocate buffer is large enough + * to include extra 4 octets at the end. + */ + p = ((uint8_t*)(p_wack + 1)) + p_wack->offset + p_wack->len; + UINT32_TO_STREAM(p, time_get_os_boottime_ms()); #endif - /* We will not save the FCS in case we reconfigure and change options */ - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - p_wack->len -= L2CAP_FCS_LEN; + /* We will not save the FCS in case we reconfigure and change options */ + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) p_wack->len -= L2CAP_FCS_LEN; - p_wack->layer_specific = p_xmit->layer_specific; - fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_wack); - } + p_wack->layer_specific = p_xmit->layer_specific; + fixed_queue_enqueue(p_ccb->fcrb.waiting_for_ack_q, p_wack); + } #if (L2CAP_ERTM_STATS == TRUE) - p_ccb->fcrb.ertm_pkt_counts[0]++; - p_ccb->fcrb.ertm_byte_counts[0] += (p_xmit->len - 8); + p_ccb->fcrb.ertm_pkt_counts[0]++; + p_ccb->fcrb.ertm_byte_counts[0] += (p_xmit->len - 8); #endif + } - } - - return (p_xmit); + return (p_xmit); } /******************************************************************************* @@ -1838,94 +1804,82 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_leng * Returns pointer to buffer with segment or NULL * ******************************************************************************/ -BT_HDR *l2c_lcc_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_length) -{ - bool first_seg = false; /* The segment is the first part of data */ - bool last_seg = false; /* The segment is the last part of data */ - uint16_t no_of_bytes_to_send = 0; - uint16_t sdu_len = 0; - BT_HDR *p_buf, *p_xmit; - uint8_t *p; - uint16_t max_pdu = p_ccb->peer_conn_cfg.mps; - - p_buf = (BT_HDR *)fixed_queue_try_peek_first(p_ccb->xmit_hold_q); - - /* We are using the "event" field to tell is if we already started segmentation */ - if (p_buf->event == 0) - { - first_seg = true; - sdu_len = p_buf->len; - if (p_buf->len <= (max_pdu - L2CAP_LCC_SDU_LENGTH)) - { - last_seg = true; - no_of_bytes_to_send = p_buf->len; - } - else - no_of_bytes_to_send = max_pdu - L2CAP_LCC_SDU_LENGTH; - } - else if (p_buf->len <= max_pdu) - { - last_seg = true; - no_of_bytes_to_send = p_buf->len; - } - else - { - /* Middle Packet */ - no_of_bytes_to_send = max_pdu; - } - - /* Get a new buffer and copy the data that can be sent in a PDU */ - if (first_seg == true) - p_xmit = l2c_fcr_clone_buf (p_buf, L2CAP_LCC_OFFSET, - no_of_bytes_to_send); - else - p_xmit = l2c_fcr_clone_buf (p_buf, L2CAP_MIN_OFFSET, - no_of_bytes_to_send); - - if (p_xmit != NULL) - { - p_buf->event = p_ccb->local_cid; - p_xmit->event = p_ccb->local_cid; - - if (first_seg == true) - { - p_xmit->offset -= L2CAP_LCC_SDU_LENGTH; /* for writing the SDU length. */ - p = (uint8_t *)(p_xmit + 1) + p_xmit->offset; - UINT16_TO_STREAM(p, sdu_len); - p_xmit->len += L2CAP_LCC_SDU_LENGTH; - } - - p_buf->len -= no_of_bytes_to_send; - p_buf->offset += no_of_bytes_to_send; - - /* copy PBF setting */ - p_xmit->layer_specific = p_buf->layer_specific; - - } - else /* Should never happen if the application has configured buffers correctly */ - { - L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer, for segmentation"); - return (NULL); - } - - if (last_seg == true) - { - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); - osi_free(p_buf); - } - - /* Step back to add the L2CAP headers */ - p_xmit->offset -= L2CAP_PKT_OVERHEAD; - p_xmit->len += L2CAP_PKT_OVERHEAD ; +BT_HDR* l2c_lcc_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb, + uint16_t max_packet_length) { + bool first_seg = false; /* The segment is the first part of data */ + bool last_seg = false; /* The segment is the last part of data */ + uint16_t no_of_bytes_to_send = 0; + uint16_t sdu_len = 0; + BT_HDR *p_buf, *p_xmit; + uint8_t* p; + uint16_t max_pdu = p_ccb->peer_conn_cfg.mps; + + p_buf = (BT_HDR*)fixed_queue_try_peek_first(p_ccb->xmit_hold_q); + + /* We are using the "event" field to tell is if we already started + * segmentation */ + if (p_buf->event == 0) { + first_seg = true; + sdu_len = p_buf->len; + if (p_buf->len <= (max_pdu - L2CAP_LCC_SDU_LENGTH)) { + last_seg = true; + no_of_bytes_to_send = p_buf->len; + } else + no_of_bytes_to_send = max_pdu - L2CAP_LCC_SDU_LENGTH; + } else if (p_buf->len <= max_pdu) { + last_seg = true; + no_of_bytes_to_send = p_buf->len; + } else { + /* Middle Packet */ + no_of_bytes_to_send = max_pdu; + } + + /* Get a new buffer and copy the data that can be sent in a PDU */ + if (first_seg == true) + p_xmit = l2c_fcr_clone_buf(p_buf, L2CAP_LCC_OFFSET, no_of_bytes_to_send); + else + p_xmit = l2c_fcr_clone_buf(p_buf, L2CAP_MIN_OFFSET, no_of_bytes_to_send); + + if (p_xmit != NULL) { + p_buf->event = p_ccb->local_cid; + p_xmit->event = p_ccb->local_cid; + + if (first_seg == true) { + p_xmit->offset -= L2CAP_LCC_SDU_LENGTH; /* for writing the SDU length. */ + p = (uint8_t*)(p_xmit + 1) + p_xmit->offset; + UINT16_TO_STREAM(p, sdu_len); + p_xmit->len += L2CAP_LCC_SDU_LENGTH; + } + + p_buf->len -= no_of_bytes_to_send; + p_buf->offset += no_of_bytes_to_send; + + /* copy PBF setting */ + p_xmit->layer_specific = p_buf->layer_specific; + + } else /* Should never happen if the application has configured buffers + correctly */ + { + L2CAP_TRACE_ERROR("L2CAP - cannot get buffer, for segmentation"); + return (NULL); + } + + if (last_seg == true) { + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + osi_free(p_buf); + } - /* Set the pointer to the beginning of the data */ - p = (uint8_t *)(p_xmit + 1) + p_xmit->offset; + /* Step back to add the L2CAP headers */ + p_xmit->offset -= L2CAP_PKT_OVERHEAD; + p_xmit->len += L2CAP_PKT_OVERHEAD; - /* Note: if FCS has to be included then the length is recalculated later */ - UINT16_TO_STREAM (p, p_xmit->len - L2CAP_PKT_OVERHEAD); - UINT16_TO_STREAM (p, p_ccb->remote_cid); - return (p_xmit); + /* Set the pointer to the beginning of the data */ + p = (uint8_t*)(p_xmit + 1) + p_xmit->offset; + /* Note: if FCS has to be included then the length is recalculated later */ + UINT16_TO_STREAM(p, p_xmit->len - L2CAP_PKT_OVERHEAD); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + return (p_xmit); } /******************************************************************************* @@ -1949,24 +1903,23 @@ BT_HDR *l2c_lcc_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_leng * channels * ******************************************************************************/ -uint8_t l2c_fcr_chk_chan_modes (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); +uint8_t l2c_fcr_chk_chan_modes(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); - /* Remove nonbasic options that the peer does not support */ - if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_ENH_RETRANS)) - p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_ERTM; + /* Remove nonbasic options that the peer does not support */ + if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_ENH_RETRANS)) + p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_ERTM; - if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_STREAM_MODE)) - p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_STREAM; + if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_STREAM_MODE)) + p_ccb->ertm_info.allowed_modes &= ~L2CAP_FCR_CHAN_OPT_STREAM; - /* At least one type needs to be set (Basic, ERTM, STM) to continue */ - if (!p_ccb->ertm_info.allowed_modes) - { - L2CAP_TRACE_WARNING ("L2CAP - Peer does not support our desired channel types"); - } + /* At least one type needs to be set (Basic, ERTM, STM) to continue */ + if (!p_ccb->ertm_info.allowed_modes) { + L2CAP_TRACE_WARNING( + "L2CAP - Peer does not support our desired channel types"); + } - return (p_ccb->ertm_info.allowed_modes); + return (p_ccb->ertm_info.allowed_modes); } /******************************************************************************* @@ -1979,115 +1932,117 @@ uint8_t l2c_fcr_chk_chan_modes (tL2C_CCB *p_ccb) * Returns true if no errors, Otherwise false * ******************************************************************************/ -bool l2c_fcr_adj_our_req_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - assert(p_ccb != NULL); - assert(p_cfg != NULL); - - tL2CAP_FCR_OPTS *p_fcr = &p_cfg->fcr; - - if (p_fcr->mode != p_ccb->ertm_info.preferred_mode) - { - L2CAP_TRACE_WARNING ("l2c_fcr_adj_our_req_options - preferred_mode (%d), does not match mode (%d)", - p_ccb->ertm_info.preferred_mode, p_fcr->mode); - - /* The preferred mode is passed in through tL2CAP_ERTM_INFO, so override this one */ - p_fcr->mode = p_ccb->ertm_info.preferred_mode; - } - - /* If upper layer did not request eRTM mode, BASIC must be used */ - if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) - { - if (p_cfg->fcr_present && p_fcr->mode != L2CAP_FCR_BASIC_MODE) - { - L2CAP_TRACE_WARNING ("l2c_fcr_adj_our_req_options (mode %d): ERROR: No FCR options set using BASIC mode", p_fcr->mode); - } +bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + assert(p_ccb != NULL); + assert(p_cfg != NULL); + + tL2CAP_FCR_OPTS* p_fcr = &p_cfg->fcr; + + if (p_fcr->mode != p_ccb->ertm_info.preferred_mode) { + L2CAP_TRACE_WARNING( + "l2c_fcr_adj_our_req_options - preferred_mode (%d), does not match " + "mode (%d)", + p_ccb->ertm_info.preferred_mode, p_fcr->mode); + + /* The preferred mode is passed in through tL2CAP_ERTM_INFO, so override + * this one */ + p_fcr->mode = p_ccb->ertm_info.preferred_mode; + } + + /* If upper layer did not request eRTM mode, BASIC must be used */ + if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) { + if (p_cfg->fcr_present && p_fcr->mode != L2CAP_FCR_BASIC_MODE) { + L2CAP_TRACE_WARNING( + "l2c_fcr_adj_our_req_options (mode %d): ERROR: No FCR options set " + "using BASIC mode", + p_fcr->mode); + } + p_fcr->mode = L2CAP_FCR_BASIC_MODE; + } + + /* Process the FCR options if initial channel bring-up (not a reconfig + *request) + ** Determine initial channel mode to try based on our options and remote's + *features + */ + if (p_cfg->fcr_present && !(p_ccb->config_done & RECONFIG_FLAG)) { + /* We need to have at least one mode type common with the peer */ + if (!l2c_fcr_chk_chan_modes(p_ccb)) { + /* Two channels have incompatible supported types */ + l2cu_disconnect_chnl(p_ccb); + return (false); + } + + /* Basic is the only common channel mode between the two devices */ + else if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) { + /* We only want to try Basic, so bypass sending the FCR options entirely + */ + p_cfg->fcr_present = false; + p_cfg->fcs_present = false; /* Illegal to use FCS option in basic mode */ + p_cfg->ext_flow_spec_present = + false; /* Illegal to use extended flow spec in basic mode */ + } + + /* We have at least one non-basic mode available + * Override mode from available mode options based on preference, if needed + */ + else { + /* If peer does not support STREAMING, try ERTM */ + if (p_fcr->mode == L2CAP_FCR_STREAM_MODE && + !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_STREAM)) { + L2CAP_TRACE_DEBUG( + "L2C CFG: mode is STREAM, but peer does not support; Try ERTM"); + p_fcr->mode = L2CAP_FCR_ERTM_MODE; + } + + /* If peer does not support ERTM, try BASIC (will support this if made it + * here in the code) */ + if (p_fcr->mode == L2CAP_FCR_ERTM_MODE && + !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM)) { + L2CAP_TRACE_DEBUG( + "L2C CFG: mode is ERTM, but peer does not support; Try BASIC"); p_fcr->mode = L2CAP_FCR_BASIC_MODE; + } } - /* Process the FCR options if initial channel bring-up (not a reconfig request) - ** Determine initial channel mode to try based on our options and remote's features - */ - if (p_cfg->fcr_present && !(p_ccb->config_done & RECONFIG_FLAG)) - { - /* We need to have at least one mode type common with the peer */ - if (!l2c_fcr_chk_chan_modes(p_ccb)) - { - /* Two channels have incompatible supported types */ - l2cu_disconnect_chnl (p_ccb); - return (false); - } - - /* Basic is the only common channel mode between the two devices */ - else if (p_ccb->ertm_info.allowed_modes == L2CAP_FCR_CHAN_OPT_BASIC) - { - /* We only want to try Basic, so bypass sending the FCR options entirely */ - p_cfg->fcr_present = false; - p_cfg->fcs_present = false; /* Illegal to use FCS option in basic mode */ - p_cfg->ext_flow_spec_present = false; /* Illegal to use extended flow spec in basic mode */ - } - - /* We have at least one non-basic mode available - * Override mode from available mode options based on preference, if needed - */ - else - { - /* If peer does not support STREAMING, try ERTM */ - if (p_fcr->mode == L2CAP_FCR_STREAM_MODE && !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_STREAM)) - { - L2CAP_TRACE_DEBUG ("L2C CFG: mode is STREAM, but peer does not support; Try ERTM"); - p_fcr->mode = L2CAP_FCR_ERTM_MODE; - } - - /* If peer does not support ERTM, try BASIC (will support this if made it here in the code) */ - if (p_fcr->mode == L2CAP_FCR_ERTM_MODE && !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM)) - { - L2CAP_TRACE_DEBUG ("L2C CFG: mode is ERTM, but peer does not support; Try BASIC"); - p_fcr->mode = L2CAP_FCR_BASIC_MODE; - } - } - - if (p_fcr->mode != L2CAP_FCR_BASIC_MODE) - { - /* MTU must be smaller than buffer size */ - if ( (p_cfg->mtu_present) && (p_cfg->mtu > p_ccb->max_rx_mtu) ) - { - L2CAP_TRACE_WARNING ("L2CAP - MTU: %u larger than buf size: %u", p_cfg->mtu, p_ccb->max_rx_mtu); - return (false); - } - - /* application want to use the default MPS */ - if (p_fcr->mps == L2CAP_DEFAULT_ERM_MPS) - { - p_fcr->mps = L2CAP_MPS_OVER_BR_EDR; - } - /* MPS must be less than MTU */ - else if (p_fcr->mps > p_ccb->max_rx_mtu) - { - L2CAP_TRACE_WARNING ("L2CAP - MPS %u invalid MTU: %u", p_fcr->mps, p_ccb->max_rx_mtu); - return (false); - } - - /* We always initially read into the HCI buffer pool, so make sure it fits */ - if (p_fcr->mps > (L2CAP_MTU_SIZE - L2CAP_MAX_HEADER_FCS)) - p_fcr->mps = L2CAP_MTU_SIZE - L2CAP_MAX_HEADER_FCS; - } - else - { - p_cfg->fcs_present = false; /* Illegal to use FCS option in basic mode */ - p_cfg->ext_flow_spec_present = false; /* Illegal to use extended flow spec in basic mode */ - } + if (p_fcr->mode != L2CAP_FCR_BASIC_MODE) { + /* MTU must be smaller than buffer size */ + if ((p_cfg->mtu_present) && (p_cfg->mtu > p_ccb->max_rx_mtu)) { + L2CAP_TRACE_WARNING("L2CAP - MTU: %u larger than buf size: %u", + p_cfg->mtu, p_ccb->max_rx_mtu); + return (false); + } + + /* application want to use the default MPS */ + if (p_fcr->mps == L2CAP_DEFAULT_ERM_MPS) { + p_fcr->mps = L2CAP_MPS_OVER_BR_EDR; + } + /* MPS must be less than MTU */ + else if (p_fcr->mps > p_ccb->max_rx_mtu) { + L2CAP_TRACE_WARNING("L2CAP - MPS %u invalid MTU: %u", p_fcr->mps, + p_ccb->max_rx_mtu); + return (false); + } - p_ccb->our_cfg.fcr = *p_fcr; - } - else /* Not sure how to send a reconfiguration(??) should fcr be included? */ - { - p_ccb->our_cfg.fcr_present = false; + /* We always initially read into the HCI buffer pool, so make sure it fits + */ + if (p_fcr->mps > (L2CAP_MTU_SIZE - L2CAP_MAX_HEADER_FCS)) + p_fcr->mps = L2CAP_MTU_SIZE - L2CAP_MAX_HEADER_FCS; + } else { + p_cfg->fcs_present = false; /* Illegal to use FCS option in basic mode */ + p_cfg->ext_flow_spec_present = + false; /* Illegal to use extended flow spec in basic mode */ } - return (true); -} + p_ccb->our_cfg.fcr = *p_fcr; + } else /* Not sure how to send a reconfiguration(??) should fcr be included? + */ + { + p_ccb->our_cfg.fcr_present = false; + } + return (true); +} /******************************************************************************* * @@ -2098,33 +2053,30 @@ bool l2c_fcr_adj_our_req_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns None * ******************************************************************************/ -void l2c_fcr_adj_monitor_retran_timeout (tL2C_CCB *p_ccb) -{ - assert(p_ccb != NULL); - - /* adjust our monitor/retran timeout */ - if (p_ccb->out_cfg_fcr_present) - { - /* - ** if we requestd ERTM or accepted ERTM - ** We may accept ERTM even if we didn't request ERTM, in case of requesting STREAM - */ - if ((p_ccb->our_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) - ||(p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)) - { - /* upper layer setting is ignored */ - p_ccb->our_cfg.fcr.mon_tout = L2CAP_MIN_MONITOR_TOUT; - p_ccb->our_cfg.fcr.rtrans_tout = L2CAP_MIN_RETRANS_TOUT; - } - else - { - p_ccb->our_cfg.fcr.mon_tout = 0; - p_ccb->our_cfg.fcr.rtrans_tout = 0; - } +void l2c_fcr_adj_monitor_retran_timeout(tL2C_CCB* p_ccb) { + assert(p_ccb != NULL); - L2CAP_TRACE_DEBUG ("l2c_fcr_adj_monitor_retran_timeout: mon_tout:%d, rtrans_tout:%d", - p_ccb->our_cfg.fcr.mon_tout, p_ccb->our_cfg.fcr.rtrans_tout); + /* adjust our monitor/retran timeout */ + if (p_ccb->out_cfg_fcr_present) { + /* + ** if we requestd ERTM or accepted ERTM + ** We may accept ERTM even if we didn't request ERTM, in case of requesting + *STREAM + */ + if ((p_ccb->our_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) || + (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)) { + /* upper layer setting is ignored */ + p_ccb->our_cfg.fcr.mon_tout = L2CAP_MIN_MONITOR_TOUT; + p_ccb->our_cfg.fcr.rtrans_tout = L2CAP_MIN_RETRANS_TOUT; + } else { + p_ccb->our_cfg.fcr.mon_tout = 0; + p_ccb->our_cfg.fcr.rtrans_tout = 0; } + + L2CAP_TRACE_DEBUG( + "l2c_fcr_adj_monitor_retran_timeout: mon_tout:%d, rtrans_tout:%d", + p_ccb->our_cfg.fcr.mon_tout, p_ccb->our_cfg.fcr.rtrans_tout); + } } /******************************************************************************* * @@ -2137,34 +2089,34 @@ void l2c_fcr_adj_monitor_retran_timeout (tL2C_CCB *p_ccb) * Returns None * ******************************************************************************/ -void l2c_fcr_adj_our_rsp_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - assert(p_ccb != NULL); - assert(p_cfg != NULL); - - /* adjust our monitor/retran timeout */ - l2c_fcr_adj_monitor_retran_timeout(p_ccb); - - p_cfg->fcr_present = p_ccb->out_cfg_fcr_present; - - if (p_cfg->fcr_present) - { - /* Temporary - until a better algorithm is implemented */ - /* If peer's tx_wnd_sz requires too many buffers for us to support, then adjust it. For now, respond with our own tx_wnd_sz. */ - /* Note: peer is not guaranteed to obey our adjustment */ - if (p_ccb->peer_cfg.fcr.tx_win_sz > p_ccb->our_cfg.fcr.tx_win_sz) - { - L2CAP_TRACE_DEBUG ("%s: adjusting requested tx_win_sz from %i to %i", __func__, p_ccb->peer_cfg.fcr.tx_win_sz, p_ccb->our_cfg.fcr.tx_win_sz); - p_ccb->peer_cfg.fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz; - } - - p_cfg->fcr.mode = p_ccb->peer_cfg.fcr.mode; - p_cfg->fcr.tx_win_sz = p_ccb->peer_cfg.fcr.tx_win_sz; - p_cfg->fcr.max_transmit = p_ccb->peer_cfg.fcr.max_transmit; - p_cfg->fcr.mps = p_ccb->peer_cfg.fcr.mps; - p_cfg->fcr.rtrans_tout = p_ccb->our_cfg.fcr.rtrans_tout; - p_cfg->fcr.mon_tout = p_ccb->our_cfg.fcr.mon_tout; - } +void l2c_fcr_adj_our_rsp_options(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + assert(p_ccb != NULL); + assert(p_cfg != NULL); + + /* adjust our monitor/retran timeout */ + l2c_fcr_adj_monitor_retran_timeout(p_ccb); + + p_cfg->fcr_present = p_ccb->out_cfg_fcr_present; + + if (p_cfg->fcr_present) { + /* Temporary - until a better algorithm is implemented */ + /* If peer's tx_wnd_sz requires too many buffers for us to support, then + * adjust it. For now, respond with our own tx_wnd_sz. */ + /* Note: peer is not guaranteed to obey our adjustment */ + if (p_ccb->peer_cfg.fcr.tx_win_sz > p_ccb->our_cfg.fcr.tx_win_sz) { + L2CAP_TRACE_DEBUG("%s: adjusting requested tx_win_sz from %i to %i", + __func__, p_ccb->peer_cfg.fcr.tx_win_sz, + p_ccb->our_cfg.fcr.tx_win_sz); + p_ccb->peer_cfg.fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz; + } + + p_cfg->fcr.mode = p_ccb->peer_cfg.fcr.mode; + p_cfg->fcr.tx_win_sz = p_ccb->peer_cfg.fcr.tx_win_sz; + p_cfg->fcr.max_transmit = p_ccb->peer_cfg.fcr.max_transmit; + p_cfg->fcr.mps = p_ccb->peer_cfg.fcr.mps; + p_cfg->fcr.rtrans_tout = p_ccb->our_cfg.fcr.rtrans_tout; + p_cfg->fcr.mon_tout = p_ccb->our_cfg.fcr.mon_tout; + } } /******************************************************************************* @@ -2179,104 +2131,90 @@ void l2c_fcr_adj_our_rsp_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * cannot match. * ******************************************************************************/ -bool l2c_fcr_renegotiate_chan(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - assert(p_ccb != NULL); - assert(p_cfg != NULL); +bool l2c_fcr_renegotiate_chan(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + assert(p_ccb != NULL); + assert(p_cfg != NULL); - uint8_t peer_mode = p_ccb->our_cfg.fcr.mode; - bool can_renegotiate; + uint8_t peer_mode = p_ccb->our_cfg.fcr.mode; + bool can_renegotiate; - /* Skip if this is a reconfiguration from OPEN STATE or if FCR is not returned */ - if (!p_cfg->fcr_present || (p_ccb->config_done & RECONFIG_FLAG)) - return (false); + /* Skip if this is a reconfiguration from OPEN STATE or if FCR is not returned + */ + if (!p_cfg->fcr_present || (p_ccb->config_done & RECONFIG_FLAG)) + return (false); - /* Only retry if there are more channel options to try */ - if (p_cfg->result == L2CAP_CFG_UNACCEPTABLE_PARAMS) - { - peer_mode = (p_cfg->fcr_present) ? p_cfg->fcr.mode : L2CAP_FCR_BASIC_MODE; + /* Only retry if there are more channel options to try */ + if (p_cfg->result == L2CAP_CFG_UNACCEPTABLE_PARAMS) { + peer_mode = (p_cfg->fcr_present) ? p_cfg->fcr.mode : L2CAP_FCR_BASIC_MODE; + + if (p_ccb->our_cfg.fcr.mode != peer_mode) { + if ((--p_ccb->fcr_cfg_tries) == 0) { + p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; + L2CAP_TRACE_WARNING("l2c_fcr_renegotiate_chan (Max retries exceeded)"); + } + + can_renegotiate = false; + + /* Try another supported mode if available based on our last attempted + * channel */ + switch (p_ccb->our_cfg.fcr.mode) { + /* Our Streaming mode request was unnacceptable; try ERTM or Basic */ + case L2CAP_FCR_STREAM_MODE: + /* Peer wants ERTM and we support it */ + if ((peer_mode == L2CAP_FCR_ERTM_MODE) && + (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM)) { + L2CAP_TRACE_DEBUG("l2c_fcr_renegotiate_chan(Trying ERTM)"); + p_ccb->our_cfg.fcr.mode = L2CAP_FCR_ERTM_MODE; + can_renegotiate = true; + } else /* Falls through */ + + case L2CAP_FCR_ERTM_MODE: { + /* We can try basic for any other peer mode if we support it */ + if (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC) { + L2CAP_TRACE_DEBUG("l2c_fcr_renegotiate_chan(Trying Basic)"); + can_renegotiate = true; + p_ccb->our_cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; + } + } break; - if (p_ccb->our_cfg.fcr.mode != peer_mode) - { + default: + /* All other scenarios cannot be renegotiated */ + break; + } - if ((--p_ccb->fcr_cfg_tries) == 0) - { - p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; - L2CAP_TRACE_WARNING ("l2c_fcr_renegotiate_chan (Max retries exceeded)"); - } + if (can_renegotiate) { + p_ccb->our_cfg.fcr_present = true; - can_renegotiate = false; - - /* Try another supported mode if available based on our last attempted channel */ - switch (p_ccb->our_cfg.fcr.mode) - { - /* Our Streaming mode request was unnacceptable; try ERTM or Basic */ - case L2CAP_FCR_STREAM_MODE: - /* Peer wants ERTM and we support it */ - if ( (peer_mode == L2CAP_FCR_ERTM_MODE) && (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM) ) - { - L2CAP_TRACE_DEBUG ("l2c_fcr_renegotiate_chan(Trying ERTM)"); - p_ccb->our_cfg.fcr.mode = L2CAP_FCR_ERTM_MODE; - can_renegotiate = true; - } - else /* Falls through */ - - case L2CAP_FCR_ERTM_MODE: - { - /* We can try basic for any other peer mode if we support it */ - if (p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC) - { - L2CAP_TRACE_DEBUG ("l2c_fcr_renegotiate_chan(Trying Basic)"); - can_renegotiate = true; - p_ccb->our_cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; - } - } - break; - - default: - /* All other scenarios cannot be renegotiated */ - break; - } + if (p_ccb->our_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) { + p_ccb->our_cfg.fcs_present = false; + p_ccb->our_cfg.ext_flow_spec_present = false; - if (can_renegotiate) - { - p_ccb->our_cfg.fcr_present = true; - - if (p_ccb->our_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) - { - p_ccb->our_cfg.fcs_present = false; - p_ccb->our_cfg.ext_flow_spec_present = false; - - /* Basic Mode uses ACL Data Pool, make sure the MTU fits */ - if ( (p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE) ) - { - L2CAP_TRACE_WARNING ("L2CAP - adjust MTU: %u too large", p_cfg->mtu); - p_cfg->mtu = L2CAP_MTU_SIZE; - } - } - - l2cu_process_our_cfg_req (p_ccb, &p_ccb->our_cfg); - l2cu_send_peer_config_req (p_ccb, &p_ccb->our_cfg); - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_CHNL_CFG_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - return (true); - } + /* Basic Mode uses ACL Data Pool, make sure the MTU fits */ + if ((p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE)) { + L2CAP_TRACE_WARNING("L2CAP - adjust MTU: %u too large", p_cfg->mtu); + p_cfg->mtu = L2CAP_MTU_SIZE; + } } - } - /* Disconnect if the channels do not match */ - if (p_ccb->our_cfg.fcr.mode != peer_mode) - { - L2CAP_TRACE_WARNING ("L2C CFG: Channels incompatible (local %d, peer %d)", - p_ccb->our_cfg.fcr.mode, peer_mode); - l2cu_disconnect_chnl (p_ccb); + l2cu_process_our_cfg_req(p_ccb, &p_ccb->our_cfg); + l2cu_send_peer_config_req(p_ccb, &p_ccb->our_cfg); + alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + return (true); + } } + } - return (false); -} + /* Disconnect if the channels do not match */ + if (p_ccb->our_cfg.fcr.mode != peer_mode) { + L2CAP_TRACE_WARNING("L2C CFG: Channels incompatible (local %d, peer %d)", + p_ccb->our_cfg.fcr.mode, peer_mode); + l2cu_disconnect_chnl(p_ccb); + } + return (false); +} /******************************************************************************* * @@ -2289,124 +2227,120 @@ bool l2c_fcr_renegotiate_chan(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * or L2CAP_PEER_CFG_DISCONNECT. * ******************************************************************************/ -uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - assert(p_ccb != NULL); - assert(p_cfg != NULL); - - uint16_t max_retrans_size; - uint8_t fcr_ok = L2CAP_PEER_CFG_OK; - - p_ccb->p_lcb->w4_info_rsp = false; /* Handles T61x SonyEricsson Bug in Info Request */ - - L2CAP_TRACE_EVENT ("l2c_fcr_process_peer_cfg_req() CFG fcr_present:%d fcr.mode:%d CCB FCR mode:%d preferred: %u allowed:%u", - p_cfg->fcr_present, p_cfg->fcr.mode, p_ccb->our_cfg.fcr.mode, p_ccb->ertm_info.preferred_mode, - p_ccb->ertm_info.allowed_modes); - - /* If Peer wants basic, we are done (accept it or disconnect) */ - if (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE) - { - /* If we do not allow basic, disconnect */ - if ( !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC) ) - fcr_ok = L2CAP_PEER_CFG_DISCONNECT; - } - - /* Need to negotiate if our modes are not the same */ - else if (p_cfg->fcr.mode != p_ccb->ertm_info.preferred_mode) - { - /* If peer wants a mode that we don't support then retry our mode (ex. rtx/flc), OR - ** If we want ERTM and they wanted streaming retry our mode. - ** Note: If we have already determined they support our mode previously - ** from their EXF mask. - */ - if ( (((1 << p_cfg->fcr.mode) & L2CAP_FCR_CHAN_OPT_ALL_MASK) == 0) - || (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE) ) - { - p_cfg->fcr.mode = p_ccb->our_cfg.fcr.mode; - p_cfg->fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz; - p_cfg->fcr.max_transmit = p_ccb->our_cfg.fcr.max_transmit; - fcr_ok = L2CAP_PEER_CFG_UNACCEPTABLE; - } - - /* If we wanted basic, then try to renegotiate it */ - else if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) - { - p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; - p_cfg->fcr.max_transmit = p_cfg->fcr.tx_win_sz = 0; - p_cfg->fcr.rtrans_tout = p_cfg->fcr.mon_tout = p_cfg->fcr.mps = 0; - p_ccb->our_cfg.fcr.rtrans_tout = p_ccb->our_cfg.fcr.mon_tout = p_ccb->our_cfg.fcr.mps = 0; - fcr_ok = L2CAP_PEER_CFG_UNACCEPTABLE; - } - - /* Only other valid case is if they want ERTM and we wanted STM which should be - accepted if we support it; otherwise the channel should be disconnected */ - else if ( (p_cfg->fcr.mode != L2CAP_FCR_ERTM_MODE) - || !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM) ) - { - fcr_ok = L2CAP_PEER_CFG_DISCONNECT; - } - } - - /* Configuration for FCR channels so make any adjustments and fwd to upper layer */ - if (fcr_ok == L2CAP_PEER_CFG_OK) - { - /* by default don't need to send params in the response */ - p_ccb->out_cfg_fcr_present = false; - - /* Make any needed adjustments for the response to the peer */ - if (p_cfg->fcr_present && p_cfg->fcr.mode != L2CAP_FCR_BASIC_MODE) - { - /* Peer desires to bypass FCS check, and streaming or ERTM mode */ - if (p_cfg->fcs_present) - { - p_ccb->peer_cfg.fcs = p_cfg->fcs; - p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCS; - if( p_cfg->fcs == L2CAP_CFG_FCS_BYPASS) - p_ccb->bypass_fcs |= L2CAP_CFG_FCS_PEER; - } - - max_retrans_size = p_ccb->ertm_info.fcr_tx_buf_size - sizeof(BT_HDR) - - L2CAP_MIN_OFFSET - L2CAP_SDU_LEN_OFFSET - L2CAP_FCS_LEN; - - /* Ensure the MPS is not bigger than the MTU */ - if ( (p_cfg->fcr.mps == 0) || (p_cfg->fcr.mps > p_ccb->peer_cfg.mtu) ) - { - p_cfg->fcr.mps = p_ccb->peer_cfg.mtu; - p_ccb->out_cfg_fcr_present = true; - } - - /* Ensure the MPS is not bigger than our retransmission buffer */ - if (p_cfg->fcr.mps > max_retrans_size) - { - L2CAP_TRACE_DEBUG("CFG: Overriding MPS to %d (orig %d)", max_retrans_size, p_cfg->fcr.mps); - - p_cfg->fcr.mps = max_retrans_size; - p_ccb->out_cfg_fcr_present = true; - } - - if (p_cfg->fcr.mode == L2CAP_FCR_ERTM_MODE || p_cfg->fcr.mode == L2CAP_FCR_STREAM_MODE) - { - /* Always respond with FCR ERTM parameters */ - p_ccb->out_cfg_fcr_present = true; - } - } - - /* Everything ok, so save the peer's adjusted fcr options */ - p_ccb->peer_cfg.fcr = p_cfg->fcr; - - if (p_cfg->fcr_present) - p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCR; - } - else if (fcr_ok == L2CAP_PEER_CFG_UNACCEPTABLE) - { - /* Allow peer only one retry for mode */ - if (p_ccb->peer_cfg_already_rejected) - fcr_ok = L2CAP_PEER_CFG_DISCONNECT; - else - p_ccb->peer_cfg_already_rejected = true; - } +uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + assert(p_ccb != NULL); + assert(p_cfg != NULL); + + uint16_t max_retrans_size; + uint8_t fcr_ok = L2CAP_PEER_CFG_OK; + + p_ccb->p_lcb->w4_info_rsp = + false; /* Handles T61x SonyEricsson Bug in Info Request */ + + L2CAP_TRACE_EVENT( + "l2c_fcr_process_peer_cfg_req() CFG fcr_present:%d fcr.mode:%d CCB FCR " + "mode:%d preferred: %u allowed:%u", + p_cfg->fcr_present, p_cfg->fcr.mode, p_ccb->our_cfg.fcr.mode, + p_ccb->ertm_info.preferred_mode, p_ccb->ertm_info.allowed_modes); + + /* If Peer wants basic, we are done (accept it or disconnect) */ + if (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE) { + /* If we do not allow basic, disconnect */ + if (!(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_BASIC)) + fcr_ok = L2CAP_PEER_CFG_DISCONNECT; + } + + /* Need to negotiate if our modes are not the same */ + else if (p_cfg->fcr.mode != p_ccb->ertm_info.preferred_mode) { + /* If peer wants a mode that we don't support then retry our mode (ex. + *rtx/flc), OR + ** If we want ERTM and they wanted streaming retry our mode. + ** Note: If we have already determined they support our mode previously + ** from their EXF mask. + */ + if ((((1 << p_cfg->fcr.mode) & L2CAP_FCR_CHAN_OPT_ALL_MASK) == 0) || + (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_ERTM_MODE)) { + p_cfg->fcr.mode = p_ccb->our_cfg.fcr.mode; + p_cfg->fcr.tx_win_sz = p_ccb->our_cfg.fcr.tx_win_sz; + p_cfg->fcr.max_transmit = p_ccb->our_cfg.fcr.max_transmit; + fcr_ok = L2CAP_PEER_CFG_UNACCEPTABLE; + } + + /* If we wanted basic, then try to renegotiate it */ + else if (p_ccb->ertm_info.preferred_mode == L2CAP_FCR_BASIC_MODE) { + p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; + p_cfg->fcr.max_transmit = p_cfg->fcr.tx_win_sz = 0; + p_cfg->fcr.rtrans_tout = p_cfg->fcr.mon_tout = p_cfg->fcr.mps = 0; + p_ccb->our_cfg.fcr.rtrans_tout = p_ccb->our_cfg.fcr.mon_tout = + p_ccb->our_cfg.fcr.mps = 0; + fcr_ok = L2CAP_PEER_CFG_UNACCEPTABLE; + } + + /* Only other valid case is if they want ERTM and we wanted STM which should + be + accepted if we support it; otherwise the channel should be disconnected + */ + else if ((p_cfg->fcr.mode != L2CAP_FCR_ERTM_MODE) || + !(p_ccb->ertm_info.allowed_modes & L2CAP_FCR_CHAN_OPT_ERTM)) { + fcr_ok = L2CAP_PEER_CFG_DISCONNECT; + } + } + + /* Configuration for FCR channels so make any adjustments and fwd to upper + * layer */ + if (fcr_ok == L2CAP_PEER_CFG_OK) { + /* by default don't need to send params in the response */ + p_ccb->out_cfg_fcr_present = false; + + /* Make any needed adjustments for the response to the peer */ + if (p_cfg->fcr_present && p_cfg->fcr.mode != L2CAP_FCR_BASIC_MODE) { + /* Peer desires to bypass FCS check, and streaming or ERTM mode */ + if (p_cfg->fcs_present) { + p_ccb->peer_cfg.fcs = p_cfg->fcs; + p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCS; + if (p_cfg->fcs == L2CAP_CFG_FCS_BYPASS) + p_ccb->bypass_fcs |= L2CAP_CFG_FCS_PEER; + } + + max_retrans_size = p_ccb->ertm_info.fcr_tx_buf_size - sizeof(BT_HDR) - + L2CAP_MIN_OFFSET - L2CAP_SDU_LEN_OFFSET - + L2CAP_FCS_LEN; + + /* Ensure the MPS is not bigger than the MTU */ + if ((p_cfg->fcr.mps == 0) || (p_cfg->fcr.mps > p_ccb->peer_cfg.mtu)) { + p_cfg->fcr.mps = p_ccb->peer_cfg.mtu; + p_ccb->out_cfg_fcr_present = true; + } + + /* Ensure the MPS is not bigger than our retransmission buffer */ + if (p_cfg->fcr.mps > max_retrans_size) { + L2CAP_TRACE_DEBUG("CFG: Overriding MPS to %d (orig %d)", + max_retrans_size, p_cfg->fcr.mps); + + p_cfg->fcr.mps = max_retrans_size; + p_ccb->out_cfg_fcr_present = true; + } + + if (p_cfg->fcr.mode == L2CAP_FCR_ERTM_MODE || + p_cfg->fcr.mode == L2CAP_FCR_STREAM_MODE) { + /* Always respond with FCR ERTM parameters */ + p_ccb->out_cfg_fcr_present = true; + } + } + + /* Everything ok, so save the peer's adjusted fcr options */ + p_ccb->peer_cfg.fcr = p_cfg->fcr; + + if (p_cfg->fcr_present) p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FCR; + } else if (fcr_ok == L2CAP_PEER_CFG_UNACCEPTABLE) { + /* Allow peer only one retry for mode */ + if (p_ccb->peer_cfg_already_rejected) + fcr_ok = L2CAP_PEER_CFG_DISCONNECT; + else + p_ccb->peer_cfg_already_rejected = true; + } - return (fcr_ok); + return (fcr_ok); } #if (L2CAP_ERTM_STATS == TRUE) @@ -2422,97 +2356,102 @@ uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void l2c_fcr_collect_ack_delay (tL2C_CCB *p_ccb, uint8_t num_bufs_acked) -{ - uint32_t index; - BT_HDR *p_buf; - uint8_t *p; - uint32_t timestamp, delay; - uint8_t xx; - uint8_t str[120]; - - index = p_ccb->fcrb.ack_delay_avg_index; - - /* update sum, max and min of waiting for ack queue size */ - p_ccb->fcrb.ack_q_count_avg[index] += +static void l2c_fcr_collect_ack_delay(tL2C_CCB* p_ccb, uint8_t num_bufs_acked) { + uint32_t index; + BT_HDR* p_buf; + uint8_t* p; + uint32_t timestamp, delay; + uint8_t xx; + uint8_t str[120]; + + index = p_ccb->fcrb.ack_delay_avg_index; + + /* update sum, max and min of waiting for ack queue size */ + p_ccb->fcrb.ack_q_count_avg[index] += + fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q); + + if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) > + p_ccb->fcrb.ack_q_count_max[index]) + p_ccb->fcrb.ack_q_count_max[index] = fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q); - if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) > p_ccb->fcrb.ack_q_count_max[index]) - p_ccb->fcrb.ack_q_count_max[index] = fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q); - - if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) < p_ccb->fcrb.ack_q_count_min[index]) - p_ccb->fcrb.ack_q_count_min[index] = fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q); - - /* update sum, max and min of round trip delay of acking */ - list_t *list = NULL; - if (! fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) - list = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q); - if (list != NULL) { - for (const list_node_t *node = list_begin(list), xx = 0; - (node != list_end(list)) && (xx < num_bufs_acked); - node = list_next(node), xx++) { - p_buf = list_node(node); - /* adding up length of acked I-frames to get throughput */ - p_ccb->fcrb.throughput[index] += p_buf->len - 8; - - if ( xx == num_bufs_acked - 1 ) - { - /* get timestamp from tx I-frame that receiver is acking */ - p = ((uint8_t *) (p_buf+1)) + p_buf->offset + p_buf->len; - if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) - { - p += L2CAP_FCS_LEN; - } - - STREAM_TO_UINT32(timestamp, p); - delay = time_get_os_boottime_ms() - timestamp; - - p_ccb->fcrb.ack_delay_avg[index] += delay; - if ( delay > p_ccb->fcrb.ack_delay_max[index] ) - p_ccb->fcrb.ack_delay_max[index] = delay; - if ( delay < p_ccb->fcrb.ack_delay_min[index] ) - p_ccb->fcrb.ack_delay_min[index] = delay; - } + if (fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q) < + p_ccb->fcrb.ack_q_count_min[index]) + p_ccb->fcrb.ack_q_count_min[index] = + fixed_queue_length(p_ccb->fcrb.waiting_for_ack_q); + + /* update sum, max and min of round trip delay of acking */ + list_t* list = NULL; + if (!fixed_queue_is_empty(p_ccb->fcrb.waiting_for_ack_q)) + list = fixed_queue_get_list(p_ccb->fcrb.waiting_for_ack_q); + if (list != NULL) { + for (const list_node_t *node = list_begin(list), xx = 0; + (node != list_end(list)) && (xx < num_bufs_acked); + node = list_next(node), xx++) { + p_buf = list_node(node); + /* adding up length of acked I-frames to get throughput */ + p_ccb->fcrb.throughput[index] += p_buf->len - 8; + + if (xx == num_bufs_acked - 1) { + /* get timestamp from tx I-frame that receiver is acking */ + p = ((uint8_t*)(p_buf + 1)) + p_buf->offset + p_buf->len; + if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) { + p += L2CAP_FCS_LEN; } - } - p_ccb->fcrb.ack_delay_avg_count++; + STREAM_TO_UINT32(timestamp, p); + delay = time_get_os_boottime_ms() - timestamp; - /* calculate average and initialize next avg, min and max */ - if (p_ccb->fcrb.ack_delay_avg_count > L2CAP_ERTM_STATS_AVG_NUM_SAMPLES) - { - p_ccb->fcrb.ack_delay_avg_count = 0; + p_ccb->fcrb.ack_delay_avg[index] += delay; + if (delay > p_ccb->fcrb.ack_delay_max[index]) + p_ccb->fcrb.ack_delay_max[index] = delay; + if (delay < p_ccb->fcrb.ack_delay_min[index]) + p_ccb->fcrb.ack_delay_min[index] = delay; + } + } + } - p_ccb->fcrb.ack_q_count_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES; - p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES; + p_ccb->fcrb.ack_delay_avg_count++; - /* calculate throughput */ - timestamp = time_get_os_boottime_ms(); - if (timestamp - p_ccb->fcrb.throughput_start > 0) - p_ccb->fcrb.throughput[index] /= (timestamp - p_ccb->fcrb.throughput_start); + /* calculate average and initialize next avg, min and max */ + if (p_ccb->fcrb.ack_delay_avg_count > L2CAP_ERTM_STATS_AVG_NUM_SAMPLES) { + p_ccb->fcrb.ack_delay_avg_count = 0; - p_ccb->fcrb.throughput_start = timestamp; + p_ccb->fcrb.ack_q_count_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES; + p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES; - snprintf(str, sizeof(str), "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u", - index, p_ccb->fcrb.throughput[index], - p_ccb->fcrb.ack_delay_avg[index], p_ccb->fcrb.ack_delay_min[index], p_ccb->fcrb.ack_delay_max[index], - p_ccb->fcrb.ack_q_count_avg[index], p_ccb->fcrb.ack_q_count_min[index], p_ccb->fcrb.ack_q_count_max[index] ); + /* calculate throughput */ + timestamp = time_get_os_boottime_ms(); + if (timestamp - p_ccb->fcrb.throughput_start > 0) + p_ccb->fcrb.throughput[index] /= + (timestamp - p_ccb->fcrb.throughput_start); - BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "%s", str); + p_ccb->fcrb.throughput_start = timestamp; - index = (index + 1) % L2CAP_ERTM_STATS_NUM_AVG; - p_ccb->fcrb.ack_delay_avg_index = index; + snprintf( + str, sizeof(str), + "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, " + "ack_q_count avg:%3u, min:%3u, max:%3u", + index, p_ccb->fcrb.throughput[index], p_ccb->fcrb.ack_delay_avg[index], + p_ccb->fcrb.ack_delay_min[index], p_ccb->fcrb.ack_delay_max[index], + p_ccb->fcrb.ack_q_count_avg[index], p_ccb->fcrb.ack_q_count_min[index], + p_ccb->fcrb.ack_q_count_max[index]); - p_ccb->fcrb.ack_q_count_max[index] = 0; - p_ccb->fcrb.ack_q_count_min[index] = 0xFFFFFFFF; - p_ccb->fcrb.ack_q_count_avg[index] = 0; + BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI, + TRACE_TYPE_GENERIC, "%s", str); + index = (index + 1) % L2CAP_ERTM_STATS_NUM_AVG; + p_ccb->fcrb.ack_delay_avg_index = index; - p_ccb->fcrb.ack_delay_max[index] = 0; - p_ccb->fcrb.ack_delay_min[index] = 0xFFFFFFFF; - p_ccb->fcrb.ack_delay_avg[index] = 0; + p_ccb->fcrb.ack_q_count_max[index] = 0; + p_ccb->fcrb.ack_q_count_min[index] = 0xFFFFFFFF; + p_ccb->fcrb.ack_q_count_avg[index] = 0; - p_ccb->fcrb.throughput[index] = 0; - } + p_ccb->fcrb.ack_delay_max[index] = 0; + p_ccb->fcrb.ack_delay_min[index] = 0xFFFFFFFF; + p_ccb->fcrb.ack_delay_avg[index] = 0; + + p_ccb->fcrb.throughput[index] = 0; + } } #endif diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h index 47ff36d0c..c9793009b 100644 --- a/stack/l2cap/l2c_int.h +++ b/stack/l2cap/l2c_int.h @@ -26,348 +26,346 @@ #include -#include "osi/include/alarm.h" -#include "osi/include/fixed_queue.h" -#include "osi/include/list.h" -#include "btm_api.h" #include "bt_common.h" +#include "btm_api.h" #include "l2c_api.h" #include "l2cdefs.h" +#include "osi/include/alarm.h" +#include "osi/include/fixed_queue.h" +#include "osi/include/list.h" #ifdef __cplusplus extern "C" { #endif -#define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */ +#define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */ /* LE credit based L2CAP connection parameters */ -#define L2CAP_LE_MIN_MTU 23 -#define L2CAP_LE_MIN_MPS 23 -#define L2CAP_LE_MAX_MPS 65533 -#define L2CAP_LE_MIN_CREDIT 0 -#define L2CAP_LE_MAX_CREDIT 65535 -#define L2CAP_LE_DEFAULT_MTU 512 -#define L2CAP_LE_DEFAULT_MPS 23 -#define L2CAP_LE_DEFAULT_CREDIT 1 +#define L2CAP_LE_MIN_MTU 23 +#define L2CAP_LE_MIN_MPS 23 +#define L2CAP_LE_MAX_MPS 65533 +#define L2CAP_LE_MIN_CREDIT 0 +#define L2CAP_LE_MAX_CREDIT 65535 +#define L2CAP_LE_DEFAULT_MTU 512 +#define L2CAP_LE_DEFAULT_MPS 23 +#define L2CAP_LE_DEFAULT_CREDIT 1 /* * Timeout values (in milliseconds). */ -#define L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS (10 * 1000) /* 10 seconds */ -#define L2CAP_LINK_CONNECT_TIMEOUT_MS (60 * 1000) /* 30 seconds */ -#define L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */ -#define L2CAP_ECHO_RSP_TIMEOUT_MS (30 * 1000) /* 30 seconds */ -#define L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS (2 * 1000) /* 2 seconds */ -#define L2CAP_LINK_DISCONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */ -#define L2CAP_CHNL_CONNECT_TIMEOUT_MS (60 * 1000) /* 60 seconds */ -#define L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */ -#define L2CAP_CHNL_CFG_TIMEOUT_MS (30 * 1000) /* 30 seconds */ -#define L2CAP_CHNL_DISCONNECT_TIMEOUT_MS (10 * 1000) /* 10 seconds */ -#define L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS (2 * 1000) /* 2 seconds */ -#define L2CAP_WAIT_INFO_RSP_TIMEOUT_MS (3 * 1000) /* 3 seconds */ -#define L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */ -#define L2CAP_FCR_ACK_TIMEOUT_MS 200 /* 200 milliseconds */ +#define L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS (10 * 1000) /* 10 seconds */ +#define L2CAP_LINK_CONNECT_TIMEOUT_MS (60 * 1000) /* 30 seconds */ +#define L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */ +#define L2CAP_ECHO_RSP_TIMEOUT_MS (30 * 1000) /* 30 seconds */ +#define L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS (2 * 1000) /* 2 seconds */ +#define L2CAP_LINK_DISCONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */ +#define L2CAP_CHNL_CONNECT_TIMEOUT_MS (60 * 1000) /* 60 seconds */ +#define L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */ +#define L2CAP_CHNL_CFG_TIMEOUT_MS (30 * 1000) /* 30 seconds */ +#define L2CAP_CHNL_DISCONNECT_TIMEOUT_MS (10 * 1000) /* 10 seconds */ +#define L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS (2 * 1000) /* 2 seconds */ +#define L2CAP_WAIT_INFO_RSP_TIMEOUT_MS (3 * 1000) /* 3 seconds */ +#define L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */ +#define L2CAP_FCR_ACK_TIMEOUT_MS 200 /* 200 milliseconds */ /* Define the possible L2CAP channel states. The names of * the states may seem a bit strange, but they are taken from * the Bluetooth specification. */ -typedef enum -{ - CST_CLOSED, /* Channel is in closed state */ - CST_ORIG_W4_SEC_COMP, /* Originator waits security clearence */ - CST_TERM_W4_SEC_COMP, /* Acceptor waits security clearence */ - CST_W4_L2CAP_CONNECT_RSP, /* Waiting for peer conenct response */ - CST_W4_L2CA_CONNECT_RSP, /* Waiting for upper layer connect rsp */ - CST_CONFIG, /* Negotiating configuration */ - CST_OPEN, /* Data transfer state */ - CST_W4_L2CAP_DISCONNECT_RSP, /* Waiting for peer disconnect rsp */ - CST_W4_L2CA_DISCONNECT_RSP /* Waiting for upper layer disc rsp */ +typedef enum { + CST_CLOSED, /* Channel is in closed state */ + CST_ORIG_W4_SEC_COMP, /* Originator waits security clearence */ + CST_TERM_W4_SEC_COMP, /* Acceptor waits security clearence */ + CST_W4_L2CAP_CONNECT_RSP, /* Waiting for peer conenct response */ + CST_W4_L2CA_CONNECT_RSP, /* Waiting for upper layer connect rsp */ + CST_CONFIG, /* Negotiating configuration */ + CST_OPEN, /* Data transfer state */ + CST_W4_L2CAP_DISCONNECT_RSP, /* Waiting for peer disconnect rsp */ + CST_W4_L2CA_DISCONNECT_RSP /* Waiting for upper layer disc rsp */ } tL2C_CHNL_STATE; /* Define the possible L2CAP link states */ -typedef enum -{ - LST_DISCONNECTED, - LST_CONNECT_HOLDING, - LST_CONNECTING_WAIT_SWITCH, - LST_CONNECTING, - LST_CONNECTED, - LST_DISCONNECTING +typedef enum { + LST_DISCONNECTED, + LST_CONNECT_HOLDING, + LST_CONNECTING_WAIT_SWITCH, + LST_CONNECTING, + LST_CONNECTED, + LST_DISCONNECTING } tL2C_LINK_STATE; - - /* Define input events to the L2CAP link and channel state machines. The names * of the events may seem a bit strange, but they are taken from * the Bluetooth specification. */ /* Lower layer */ -#define L2CEVT_LP_CONNECT_CFM 0 /* connect confirm */ -#define L2CEVT_LP_CONNECT_CFM_NEG 1 /* connect confirm (failed) */ -#define L2CEVT_LP_CONNECT_IND 2 /* connect indication */ -#define L2CEVT_LP_DISCONNECT_IND 3 /* disconnect indication */ -#define L2CEVT_LP_QOS_CFM 4 /* QOS confirmation */ -#define L2CEVT_LP_QOS_CFM_NEG 5 /* QOS confirmation (failed)*/ -#define L2CEVT_LP_QOS_VIOLATION_IND 6 /* QOS violation indication */ +#define L2CEVT_LP_CONNECT_CFM 0 /* connect confirm */ +#define L2CEVT_LP_CONNECT_CFM_NEG 1 /* connect confirm (failed) */ +#define L2CEVT_LP_CONNECT_IND 2 /* connect indication */ +#define L2CEVT_LP_DISCONNECT_IND 3 /* disconnect indication */ +#define L2CEVT_LP_QOS_CFM 4 /* QOS confirmation */ +#define L2CEVT_LP_QOS_CFM_NEG 5 /* QOS confirmation (failed)*/ +#define L2CEVT_LP_QOS_VIOLATION_IND 6 /* QOS violation indication */ /* Security */ -#define L2CEVT_SEC_COMP 7 /* cleared successfully */ -#define L2CEVT_SEC_COMP_NEG 8 /* procedure failed */ +#define L2CEVT_SEC_COMP 7 /* cleared successfully */ +#define L2CEVT_SEC_COMP_NEG 8 /* procedure failed */ /* Peer connection */ -#define L2CEVT_L2CAP_CONNECT_REQ 10 /* request */ -#define L2CEVT_L2CAP_CONNECT_RSP 11 /* response */ -#define L2CEVT_L2CAP_CONNECT_RSP_PND 12 /* response pending */ -#define L2CEVT_L2CAP_CONNECT_RSP_NEG 13 /* response (failed) */ +#define L2CEVT_L2CAP_CONNECT_REQ 10 /* request */ +#define L2CEVT_L2CAP_CONNECT_RSP 11 /* response */ +#define L2CEVT_L2CAP_CONNECT_RSP_PND 12 /* response pending */ +#define L2CEVT_L2CAP_CONNECT_RSP_NEG 13 /* response (failed) */ /* Peer configuration */ -#define L2CEVT_L2CAP_CONFIG_REQ 14 /* request */ -#define L2CEVT_L2CAP_CONFIG_RSP 15 /* response */ -#define L2CEVT_L2CAP_CONFIG_RSP_NEG 16 /* response (failed) */ +#define L2CEVT_L2CAP_CONFIG_REQ 14 /* request */ +#define L2CEVT_L2CAP_CONFIG_RSP 15 /* response */ +#define L2CEVT_L2CAP_CONFIG_RSP_NEG 16 /* response (failed) */ -#define L2CEVT_L2CAP_DISCONNECT_REQ 17 /* Peer disconnect request */ -#define L2CEVT_L2CAP_DISCONNECT_RSP 18 /* Peer disconnect response */ -#define L2CEVT_L2CAP_INFO_RSP 19 /* Peer information response */ -#define L2CEVT_L2CAP_DATA 20 /* Peer data */ +#define L2CEVT_L2CAP_DISCONNECT_REQ 17 /* Peer disconnect request */ +#define L2CEVT_L2CAP_DISCONNECT_RSP 18 /* Peer disconnect response */ +#define L2CEVT_L2CAP_INFO_RSP 19 /* Peer information response */ +#define L2CEVT_L2CAP_DATA 20 /* Peer data */ /* Upper layer */ -#define L2CEVT_L2CA_CONNECT_REQ 21 /* connect request */ -#define L2CEVT_L2CA_CONNECT_RSP 22 /* connect response */ -#define L2CEVT_L2CA_CONNECT_RSP_NEG 23 /* connect response (failed)*/ -#define L2CEVT_L2CA_CONFIG_REQ 24 /* config request */ -#define L2CEVT_L2CA_CONFIG_RSP 25 /* config response */ -#define L2CEVT_L2CA_CONFIG_RSP_NEG 26 /* config response (failed) */ -#define L2CEVT_L2CA_DISCONNECT_REQ 27 /* disconnect request */ -#define L2CEVT_L2CA_DISCONNECT_RSP 28 /* disconnect response */ -#define L2CEVT_L2CA_DATA_READ 29 /* data read */ -#define L2CEVT_L2CA_DATA_WRITE 30 /* data write */ -#define L2CEVT_L2CA_FLUSH_REQ 31 /* flush */ - -#define L2CEVT_TIMEOUT 32 /* Timeout */ -#define L2CEVT_SEC_RE_SEND_CMD 33 /* btm_sec has enough info to proceed */ - -#define L2CEVT_ACK_TIMEOUT 34 /* RR delay timeout */ - -#define L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT 35 /* Upper layer credit packet */ -#define L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT 36 /* Peer credit packet */ +#define L2CEVT_L2CA_CONNECT_REQ 21 /* connect request */ +#define L2CEVT_L2CA_CONNECT_RSP 22 /* connect response */ +#define L2CEVT_L2CA_CONNECT_RSP_NEG 23 /* connect response (failed)*/ +#define L2CEVT_L2CA_CONFIG_REQ 24 /* config request */ +#define L2CEVT_L2CA_CONFIG_RSP 25 /* config response */ +#define L2CEVT_L2CA_CONFIG_RSP_NEG 26 /* config response (failed) */ +#define L2CEVT_L2CA_DISCONNECT_REQ 27 /* disconnect request */ +#define L2CEVT_L2CA_DISCONNECT_RSP 28 /* disconnect response */ +#define L2CEVT_L2CA_DATA_READ 29 /* data read */ +#define L2CEVT_L2CA_DATA_WRITE 30 /* data write */ +#define L2CEVT_L2CA_FLUSH_REQ 31 /* flush */ + +#define L2CEVT_TIMEOUT 32 /* Timeout */ +#define L2CEVT_SEC_RE_SEND_CMD 33 /* btm_sec has enough info to proceed */ + +#define L2CEVT_ACK_TIMEOUT 34 /* RR delay timeout */ + +#define L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT \ + 35 /* Upper layer credit packet \ + */ +#define L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT 36 /* Peer credit packet */ /* Bitmask to skip over Broadcom feature reserved (ID) to avoid sending two successive ID values, '0' id only or both */ -#define L2CAP_ADJ_BRCM_ID 0x1 -#define L2CAP_ADJ_ZERO_ID 0x2 -#define L2CAP_ADJ_ID 0x3 +#define L2CAP_ADJ_BRCM_ID 0x1 +#define L2CAP_ADJ_ZERO_ID 0x2 +#define L2CAP_ADJ_ID 0x3 /* Return values for l2cu_process_peer_cfg_req() */ -#define L2CAP_PEER_CFG_UNACCEPTABLE 0 -#define L2CAP_PEER_CFG_OK 1 -#define L2CAP_PEER_CFG_DISCONNECT 2 +#define L2CAP_PEER_CFG_UNACCEPTABLE 0 +#define L2CAP_PEER_CFG_OK 1 +#define L2CAP_PEER_CFG_DISCONNECT 2 /* eL2CAP option constants */ /* Min retransmission timeout if no flush timeout or PBF */ -#define L2CAP_MIN_RETRANS_TOUT 2000 +#define L2CAP_MIN_RETRANS_TOUT 2000 /* Min monitor timeout if no flush timeout or PBF */ -#define L2CAP_MIN_MONITOR_TOUT 12000 +#define L2CAP_MIN_MONITOR_TOUT 12000 -#define L2CAP_MAX_FCR_CFG_TRIES 2 /* Config attempts before disconnecting */ +#define L2CAP_MAX_FCR_CFG_TRIES 2 /* Config attempts before disconnecting */ typedef uint8_t tL2C_BLE_FIXED_CHNLS_MASK; -typedef struct -{ - uint8_t next_tx_seq; /* Next sequence number to be Tx'ed */ - uint8_t last_rx_ack; /* Last sequence number ack'ed by the peer */ - uint8_t next_seq_expected; /* Next peer sequence number expected */ - uint8_t last_ack_sent; /* Last peer sequence number ack'ed */ - uint8_t num_tries; /* Number of retries to send a packet */ - uint8_t max_held_acks; /* Max acks we can hold before sending */ +typedef struct { + uint8_t next_tx_seq; /* Next sequence number to be Tx'ed */ + uint8_t last_rx_ack; /* Last sequence number ack'ed by the peer */ + uint8_t next_seq_expected; /* Next peer sequence number expected */ + uint8_t last_ack_sent; /* Last peer sequence number ack'ed */ + uint8_t num_tries; /* Number of retries to send a packet */ + uint8_t max_held_acks; /* Max acks we can hold before sending */ - bool remote_busy; /* true if peer has flowed us off */ - bool local_busy; /* true if we have flowed off the peer */ + bool remote_busy; /* true if peer has flowed us off */ + bool local_busy; /* true if we have flowed off the peer */ - bool rej_sent; /* Reject was sent */ - bool srej_sent; /* Selective Reject was sent */ - bool wait_ack; /* Transmitter is waiting ack (poll sent) */ - bool rej_after_srej; /* Send a REJ when SREJ clears */ + bool rej_sent; /* Reject was sent */ + bool srej_sent; /* Selective Reject was sent */ + bool wait_ack; /* Transmitter is waiting ack (poll sent) */ + bool rej_after_srej; /* Send a REJ when SREJ clears */ - bool send_f_rsp; /* We need to send an F-bit response */ + bool send_f_rsp; /* We need to send an F-bit response */ - uint16_t rx_sdu_len; /* Length of the SDU being received */ - BT_HDR *p_rx_sdu; /* Buffer holding the SDU being received */ - fixed_queue_t *waiting_for_ack_q; /* Buffers sent and waiting for peer to ack */ - fixed_queue_t *srej_rcv_hold_q; /* Buffers rcvd but held pending SREJ rsp */ - fixed_queue_t *retrans_q; /* Buffers being retransmitted */ + uint16_t rx_sdu_len; /* Length of the SDU being received */ + BT_HDR* p_rx_sdu; /* Buffer holding the SDU being received */ + fixed_queue_t* + waiting_for_ack_q; /* Buffers sent and waiting for peer to ack */ + fixed_queue_t* srej_rcv_hold_q; /* Buffers rcvd but held pending SREJ rsp */ + fixed_queue_t* retrans_q; /* Buffers being retransmitted */ - alarm_t *ack_timer; /* Timer delaying RR */ - alarm_t *mon_retrans_timer; /* Timer Monitor or Retransmission */ + alarm_t* ack_timer; /* Timer delaying RR */ + alarm_t* mon_retrans_timer; /* Timer Monitor or Retransmission */ #if (L2CAP_ERTM_STATS == TRUE) - uint32_t connect_tick_count; /* Time channel was established */ - uint32_t ertm_pkt_counts[2]; /* Packets sent and received */ - uint32_t ertm_byte_counts[2]; /* Bytes sent and received */ - uint32_t s_frames_sent[4]; /* S-frames sent (RR, REJ, RNR, SREJ) */ - uint32_t s_frames_rcvd[4]; /* S-frames rcvd (RR, REJ, RNR, SREJ) */ - uint32_t xmit_window_closed; /* # of times the xmit window was closed */ - uint32_t controller_idle; /* # of times less than 2 packets in controller */ - /* when the xmit window was closed */ - uint32_t pkts_retransmitted; /* # of packets that were retransmitted */ - uint32_t retrans_touts; /* # of retransmission timouts */ - uint32_t xmit_ack_touts; /* # of xmit ack timouts */ + uint32_t connect_tick_count; /* Time channel was established */ + uint32_t ertm_pkt_counts[2]; /* Packets sent and received */ + uint32_t ertm_byte_counts[2]; /* Bytes sent and received */ + uint32_t s_frames_sent[4]; /* S-frames sent (RR, REJ, RNR, SREJ) */ + uint32_t s_frames_rcvd[4]; /* S-frames rcvd (RR, REJ, RNR, SREJ) */ + uint32_t xmit_window_closed; /* # of times the xmit window was closed */ + uint32_t controller_idle; /* # of times less than 2 packets in controller */ + /* when the xmit window was closed */ + uint32_t pkts_retransmitted; /* # of packets that were retransmitted */ + uint32_t retrans_touts; /* # of retransmission timouts */ + uint32_t xmit_ack_touts; /* # of xmit ack timouts */ #define L2CAP_ERTM_STATS_NUM_AVG 10 #define L2CAP_ERTM_STATS_AVG_NUM_SAMPLES 100 - uint32_t ack_delay_avg_count; - uint32_t ack_delay_avg_index; - uint32_t throughput_start; - uint32_t throughput[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_delay_avg[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_delay_min[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_delay_max[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_q_count_avg[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_q_count_min[L2CAP_ERTM_STATS_NUM_AVG]; - uint32_t ack_q_count_max[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_delay_avg_count; + uint32_t ack_delay_avg_index; + uint32_t throughput_start; + uint32_t throughput[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_delay_avg[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_delay_min[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_delay_max[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_q_count_avg[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_q_count_min[L2CAP_ERTM_STATS_NUM_AVG]; + uint32_t ack_q_count_max[L2CAP_ERTM_STATS_NUM_AVG]; #endif } tL2C_FCRB; - /* Define a registration control block. Every application (e.g. RFCOMM, SDP, * TCS etc) that registers with L2CAP is assigned one of these. */ #if (L2CAP_UCD_INCLUDED == TRUE) -#define L2C_UCD_RCB_ID 0x00 -#define L2C_UCD_STATE_UNUSED 0x00 -#define L2C_UCD_STATE_W4_DATA 0x01 -#define L2C_UCD_STATE_W4_RECEPTION 0x02 -#define L2C_UCD_STATE_W4_MTU 0x04 - -typedef struct -{ - uint8_t state; - tL2CAP_UCD_CB_INFO cb_info; +#define L2C_UCD_RCB_ID 0x00 +#define L2C_UCD_STATE_UNUSED 0x00 +#define L2C_UCD_STATE_W4_DATA 0x01 +#define L2C_UCD_STATE_W4_RECEPTION 0x02 +#define L2C_UCD_STATE_W4_MTU 0x04 + +typedef struct { + uint8_t state; + tL2CAP_UCD_CB_INFO cb_info; } tL2C_UCD_REG; #endif -typedef struct -{ - bool in_use; - uint16_t psm; - uint16_t real_psm; /* This may be a dummy RCB for an o/b connection but */ - /* this is the real PSM that we need to connect to */ +typedef struct { + bool in_use; + uint16_t psm; + uint16_t real_psm; /* This may be a dummy RCB for an o/b connection but */ + /* this is the real PSM that we need to connect to */ #if (L2CAP_UCD_INCLUDED == TRUE) - tL2C_UCD_REG ucd; + tL2C_UCD_REG ucd; #endif - tL2CAP_APPL_INFO api; + tL2CAP_APPL_INFO api; } tL2C_RCB; - #ifndef L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA #define L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA 100 #endif -typedef void (tL2CAP_SEC_CBACK) (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, - void *p_ref_data, tBTM_STATUS result); +typedef void(tL2CAP_SEC_CBACK)(BD_ADDR bd_addr, tBT_TRANSPORT trasnport, + void* p_ref_data, tBTM_STATUS result); -typedef struct -{ - uint16_t psm; - tBT_TRANSPORT transport; - bool is_originator; - tL2CAP_SEC_CBACK *p_callback; - void *p_ref_data; -}tL2CAP_SEC_DATA; +typedef struct { + uint16_t psm; + tBT_TRANSPORT transport; + bool is_originator; + tL2CAP_SEC_CBACK* p_callback; + void* p_ref_data; +} tL2CAP_SEC_DATA; /* Define a channel control block (CCB). There may be many channel control * blocks between the same two Bluetooth devices (i.e. on the same link). * Each CCB has unique local and remote CIDs. All channel control blocks on * the same physical link and are chained together. */ -typedef struct t_l2c_ccb -{ - bool in_use; /* true when in use, false when not */ - tL2C_CHNL_STATE chnl_state; /* Channel state */ - tL2CAP_LE_CFG_INFO local_conn_cfg; /* Our config for ble conn oriented channel */ - tL2CAP_LE_CFG_INFO peer_conn_cfg; /* Peer device config ble conn oriented channel */ - bool is_first_seg; /* Dtermine whether the received packet is the first segment or not */ - BT_HDR* ble_sdu; /* Buffer for storing unassembled sdu*/ - uint16_t ble_sdu_length; /* Length of unassembled sdu length*/ - struct t_l2c_ccb *p_next_ccb; /* Next CCB in the chain */ - struct t_l2c_ccb *p_prev_ccb; /* Previous CCB in the chain */ - struct t_l2c_linkcb *p_lcb; /* Link this CCB is assigned to */ - - uint16_t local_cid; /* Local CID */ - uint16_t remote_cid; /* Remote CID */ - - alarm_t *l2c_ccb_timer; /* CCB Timer Entry */ - - tL2C_RCB *p_rcb; /* Registration CB for this Channel */ - bool should_free_rcb; /* True if RCB was allocated on the heap */ - -#define IB_CFG_DONE 0x01 -#define OB_CFG_DONE 0x02 -#define RECONFIG_FLAG 0x04 /* True after initial configuration */ -#define CFG_DONE_MASK (IB_CFG_DONE | OB_CFG_DONE) - - uint8_t config_done; /* Configuration flag word */ - uint8_t local_id; /* Transaction ID for local trans */ - uint8_t remote_id; /* Transaction ID for local */ - -#define CCB_FLAG_NO_RETRY 0x01 /* no more retry */ -#define CCB_FLAG_SENT_PENDING 0x02 /* already sent pending response */ - uint8_t flags; - - tL2CAP_CFG_INFO our_cfg; /* Our saved configuration options */ - tL2CAP_CH_CFG_BITS peer_cfg_bits; /* Store what peer wants to configure */ - tL2CAP_CFG_INFO peer_cfg; /* Peer's saved configuration options */ - - fixed_queue_t *xmit_hold_q; /* Transmit data hold queue */ - bool cong_sent; /* Set when congested status sent */ - uint16_t buff_quota; /* Buffer quota before sending congestion */ - - tL2CAP_CHNL_PRIORITY ccb_priority; /* Channel priority */ - tL2CAP_CHNL_DATA_RATE tx_data_rate; /* Channel Tx data rate */ - tL2CAP_CHNL_DATA_RATE rx_data_rate; /* Channel Rx data rate */ - - /* Fields used for eL2CAP */ - tL2CAP_ERTM_INFO ertm_info; - tL2C_FCRB fcrb; - uint16_t tx_mps; /* TX MPS adjusted based on current controller */ - uint16_t max_rx_mtu; - uint8_t fcr_cfg_tries; /* Max number of negotiation attempts */ - bool peer_cfg_already_rejected; /* If mode rejected once, set to true */ - bool out_cfg_fcr_present; /* true if cfg response shoulkd include fcr options */ - -#define L2CAP_CFG_FCS_OUR 0x01 /* Our desired config FCS option */ -#define L2CAP_CFG_FCS_PEER 0x02 /* Peer's desired config FCS option */ -#define L2CAP_BYPASS_FCS (L2CAP_CFG_FCS_OUR | L2CAP_CFG_FCS_PEER) - uint8_t bypass_fcs; +typedef struct t_l2c_ccb { + bool in_use; /* true when in use, false when not */ + tL2C_CHNL_STATE chnl_state; /* Channel state */ + tL2CAP_LE_CFG_INFO + local_conn_cfg; /* Our config for ble conn oriented channel */ + tL2CAP_LE_CFG_INFO + peer_conn_cfg; /* Peer device config ble conn oriented channel */ + bool is_first_seg; /* Dtermine whether the received packet is the first + segment or not */ + BT_HDR* ble_sdu; /* Buffer for storing unassembled sdu*/ + uint16_t ble_sdu_length; /* Length of unassembled sdu length*/ + struct t_l2c_ccb* p_next_ccb; /* Next CCB in the chain */ + struct t_l2c_ccb* p_prev_ccb; /* Previous CCB in the chain */ + struct t_l2c_linkcb* p_lcb; /* Link this CCB is assigned to */ + + uint16_t local_cid; /* Local CID */ + uint16_t remote_cid; /* Remote CID */ + + alarm_t* l2c_ccb_timer; /* CCB Timer Entry */ + + tL2C_RCB* p_rcb; /* Registration CB for this Channel */ + bool should_free_rcb; /* True if RCB was allocated on the heap */ + +#define IB_CFG_DONE 0x01 +#define OB_CFG_DONE 0x02 +#define RECONFIG_FLAG 0x04 /* True after initial configuration */ +#define CFG_DONE_MASK (IB_CFG_DONE | OB_CFG_DONE) + + uint8_t config_done; /* Configuration flag word */ + uint8_t local_id; /* Transaction ID for local trans */ + uint8_t remote_id; /* Transaction ID for local */ + +#define CCB_FLAG_NO_RETRY 0x01 /* no more retry */ +#define CCB_FLAG_SENT_PENDING 0x02 /* already sent pending response */ + uint8_t flags; + + tL2CAP_CFG_INFO our_cfg; /* Our saved configuration options */ + tL2CAP_CH_CFG_BITS peer_cfg_bits; /* Store what peer wants to configure */ + tL2CAP_CFG_INFO peer_cfg; /* Peer's saved configuration options */ + + fixed_queue_t* xmit_hold_q; /* Transmit data hold queue */ + bool cong_sent; /* Set when congested status sent */ + uint16_t buff_quota; /* Buffer quota before sending congestion */ + + tL2CAP_CHNL_PRIORITY ccb_priority; /* Channel priority */ + tL2CAP_CHNL_DATA_RATE tx_data_rate; /* Channel Tx data rate */ + tL2CAP_CHNL_DATA_RATE rx_data_rate; /* Channel Rx data rate */ + + /* Fields used for eL2CAP */ + tL2CAP_ERTM_INFO ertm_info; + tL2C_FCRB fcrb; + uint16_t tx_mps; /* TX MPS adjusted based on current controller */ + uint16_t max_rx_mtu; + uint8_t fcr_cfg_tries; /* Max number of negotiation attempts */ + bool peer_cfg_already_rejected; /* If mode rejected once, set to true */ + bool out_cfg_fcr_present; /* true if cfg response shoulkd include fcr options + */ + +#define L2CAP_CFG_FCS_OUR 0x01 /* Our desired config FCS option */ +#define L2CAP_CFG_FCS_PEER 0x02 /* Peer's desired config FCS option */ +#define L2CAP_BYPASS_FCS (L2CAP_CFG_FCS_OUR | L2CAP_CFG_FCS_PEER) + uint8_t bypass_fcs; #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - bool is_flushable; /* true if channel is flushable */ + bool is_flushable; /* true if channel is flushable */ #endif #if (L2CAP_NUM_FIXED_CHNLS > 0 || L2CAP_UCD_INCLUDED == TRUE) - uint16_t fixed_chnl_idle_tout; /* Idle timeout to use for the fixed channel */ + uint16_t fixed_chnl_idle_tout; /* Idle timeout to use for the fixed channel */ #endif - uint16_t tx_data_len; + uint16_t tx_data_len; } tL2C_CCB; /*********************************************************************** * Define a queue of linked CCBs. */ -typedef struct -{ - tL2C_CCB *p_first_ccb; /* The first channel in this queue */ - tL2C_CCB *p_last_ccb; /* The last channel in this queue */ +typedef struct { + tL2C_CCB* p_first_ccb; /* The first channel in this queue */ + tL2C_CCB* p_last_ccb; /* The last channel in this queue */ } tL2C_CCB_Q; #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) /* Round-Robin service for the same priority channels */ -#define L2CAP_NUM_CHNL_PRIORITY 3 /* Total number of priority group (high, medium, low)*/ -#define L2CAP_CHNL_PRIORITY_WEIGHT 5 /* weight per priority for burst transmission quota */ -#define L2CAP_GET_PRIORITY_QUOTA(pri) ((L2CAP_NUM_CHNL_PRIORITY - (pri)) * L2CAP_CHNL_PRIORITY_WEIGHT) +#define L2CAP_NUM_CHNL_PRIORITY \ + 3 /* Total number of priority group (high, medium, low)*/ +#define L2CAP_CHNL_PRIORITY_WEIGHT \ + 5 /* weight per priority for burst transmission quota */ +#define L2CAP_GET_PRIORITY_QUOTA(pri) \ + ((L2CAP_NUM_CHNL_PRIORITY - (pri)) * L2CAP_CHNL_PRIORITY_WEIGHT) /* CCBs within the same LCB are served in round robin with priority It will make * sure that low priority channel (for example, HF signaling on RFCOMM) can be @@ -375,12 +373,11 @@ typedef struct * channel) is congested. */ -typedef struct -{ - tL2C_CCB *p_serve_ccb; /* current serving ccb within priority group */ - tL2C_CCB *p_first_ccb; /* first ccb of priority group */ - uint8_t num_ccb; /* number of channels in priority group */ - uint8_t quota; /* burst transmission quota */ +typedef struct { + tL2C_CCB* p_serve_ccb; /* current serving ccb within priority group */ + tL2C_CCB* p_first_ccb; /* first ccb of priority group */ + uint8_t num_ccb; /* number of channels in priority group */ + uint8_t quota; /* burst transmission quota */ } tL2C_RR_SERV; #endif /* (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) */ @@ -388,183 +385,186 @@ typedef struct /* Define a link control block. There is one link control block between * this device and any other device (i.e. BD ADDR). */ -typedef struct t_l2c_linkcb -{ - bool in_use; /* true when in use, false when not */ - tL2C_LINK_STATE link_state; +typedef struct t_l2c_linkcb { + bool in_use; /* true when in use, false when not */ + tL2C_LINK_STATE link_state; - alarm_t *l2c_lcb_timer; /* Timer entry for timeout evt */ - uint16_t handle; /* The handle used with LM */ + alarm_t* l2c_lcb_timer; /* Timer entry for timeout evt */ + uint16_t handle; /* The handle used with LM */ - tL2C_CCB_Q ccb_queue; /* Queue of CCBs on this LCB */ + tL2C_CCB_Q ccb_queue; /* Queue of CCBs on this LCB */ - tL2C_CCB *p_pending_ccb; /* ccb of waiting channel during link disconnect */ - alarm_t *info_resp_timer; /* Timer entry for info resp timeout evt */ - BD_ADDR remote_bd_addr; /* The BD address of the remote */ + tL2C_CCB* p_pending_ccb; /* ccb of waiting channel during link disconnect */ + alarm_t* info_resp_timer; /* Timer entry for info resp timeout evt */ + BD_ADDR remote_bd_addr; /* The BD address of the remote */ - uint8_t link_role; /* Master or slave */ - uint8_t id; - uint8_t cur_echo_id; /* Current id value for echo request */ - tL2CA_ECHO_RSP_CB *p_echo_rsp_cb; /* Echo response callback */ - uint16_t idle_timeout; /* Idle timeout */ - bool is_bonding; /* True - link active only for bonding */ + uint8_t link_role; /* Master or slave */ + uint8_t id; + uint8_t cur_echo_id; /* Current id value for echo request */ + tL2CA_ECHO_RSP_CB* p_echo_rsp_cb; /* Echo response callback */ + uint16_t idle_timeout; /* Idle timeout */ + bool is_bonding; /* True - link active only for bonding */ - uint16_t link_flush_tout; /* Flush timeout used */ + uint16_t link_flush_tout; /* Flush timeout used */ - uint16_t link_xmit_quota; /* Num outstanding pkts allowed */ - uint16_t sent_not_acked; /* Num packets sent but not acked */ + uint16_t link_xmit_quota; /* Num outstanding pkts allowed */ + uint16_t sent_not_acked; /* Num packets sent but not acked */ - bool partial_segment_being_sent; /* Set true when a partial segment */ - /* is being sent. */ - bool w4_info_rsp; /* true when info request is active */ - uint8_t info_rx_bits; /* set 1 if received info type */ - uint32_t peer_ext_fea; /* Peer's extended features mask */ - list_t *link_xmit_data_q; /* Link transmit data buffer queue */ + bool partial_segment_being_sent; /* Set true when a partial segment */ + /* is being sent. */ + bool w4_info_rsp; /* true when info request is active */ + uint8_t info_rx_bits; /* set 1 if received info type */ + uint32_t peer_ext_fea; /* Peer's extended features mask */ + list_t* link_xmit_data_q; /* Link transmit data buffer queue */ - uint8_t peer_chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; + uint8_t peer_chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; #if (L2CAP_UCD_INCLUDED == TRUE) - uint16_t ucd_mtu; /* peer MTU on UCD */ - fixed_queue_t *ucd_out_sec_pending_q; /* Security pending outgoing UCD packet */ - fixed_queue_t *ucd_in_sec_pending_q; /* Security pending incoming UCD packet */ + uint16_t ucd_mtu; /* peer MTU on UCD */ + fixed_queue_t* + ucd_out_sec_pending_q; /* Security pending outgoing UCD packet */ + fixed_queue_t* + ucd_in_sec_pending_q; /* Security pending incoming UCD packet */ #endif - BT_HDR *p_hcit_rcv_acl; /* Current HCIT ACL buf being rcvd */ - uint16_t idle_timeout_sv; /* Save current Idle timeout */ - uint8_t acl_priority; /* L2C_PRIORITY_NORMAL or L2C_PRIORITY_HIGH */ - tL2CA_NOCP_CB *p_nocp_cb; /* Num Cmpl pkts callback */ + BT_HDR* p_hcit_rcv_acl; /* Current HCIT ACL buf being rcvd */ + uint16_t idle_timeout_sv; /* Save current Idle timeout */ + uint8_t acl_priority; /* L2C_PRIORITY_NORMAL or L2C_PRIORITY_HIGH */ + tL2CA_NOCP_CB* p_nocp_cb; /* Num Cmpl pkts callback */ #if (L2CAP_NUM_FIXED_CHNLS > 0) - tL2C_CCB *p_fixed_ccbs[L2CAP_NUM_FIXED_CHNLS]; - uint16_t disc_reason; + tL2C_CCB* p_fixed_ccbs[L2CAP_NUM_FIXED_CHNLS]; + uint16_t disc_reason; #endif - tBT_TRANSPORT transport; - tBLE_ADDR_TYPE ble_addr_type; - uint16_t tx_data_len; /* tx data length used in data length extension */ - fixed_queue_t *le_sec_pending_q; /* LE coc channels waiting for security check completion */ - uint8_t sec_act; -#define L2C_BLE_CONN_UPDATE_DISABLE 0x1 /* disable update connection parameters */ -#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ -#define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */ -#define L2C_BLE_NOT_DEFAULT_PARAM 0x8 /* not using default connection parameters */ - uint8_t conn_update_mask; - - uint16_t min_interval; /* parameters as requested by peripheral */ - uint16_t max_interval; - uint16_t latency; - uint16_t timeout; + tBT_TRANSPORT transport; + tBLE_ADDR_TYPE ble_addr_type; + uint16_t tx_data_len; /* tx data length used in data length extension */ + fixed_queue_t* le_sec_pending_q; /* LE coc channels waiting for security check + completion */ + uint8_t sec_act; +#define L2C_BLE_CONN_UPDATE_DISABLE \ + 0x1 /* disable update connection parameters */ +#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ +#define L2C_BLE_UPDATE_PENDING \ + 0x4 /* waiting for connection update finished \ + */ +#define L2C_BLE_NOT_DEFAULT_PARAM \ + 0x8 /* not using default connection parameters */ + uint8_t conn_update_mask; + + uint16_t min_interval; /* parameters as requested by peripheral */ + uint16_t max_interval; + uint16_t latency; + uint16_t timeout; #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - /* each priority group is limited burst transmission */ - /* round robin service for the same priority channels */ - tL2C_RR_SERV rr_serv[L2CAP_NUM_CHNL_PRIORITY]; - uint8_t rr_pri; /* current serving priority group */ + /* each priority group is limited burst transmission */ + /* round robin service for the same priority channels */ + tL2C_RR_SERV rr_serv[L2CAP_NUM_CHNL_PRIORITY]; + uint8_t rr_pri; /* current serving priority group */ #endif } tL2C_LCB; /* Define the L2CAP control structure */ -typedef struct -{ - uint8_t l2cap_trace_level; - uint16_t controller_xmit_window; /* Total ACL window for all links */ +typedef struct { + uint8_t l2cap_trace_level; + uint16_t controller_xmit_window; /* Total ACL window for all links */ - uint16_t round_robin_quota; /* Round-robin link quota */ - uint16_t round_robin_unacked; /* Round-robin unacked */ - bool check_round_robin; /* Do a round robin check */ + uint16_t round_robin_quota; /* Round-robin link quota */ + uint16_t round_robin_unacked; /* Round-robin unacked */ + bool check_round_robin; /* Do a round robin check */ - bool is_cong_cback_context; + bool is_cong_cback_context; - tL2C_LCB lcb_pool[MAX_L2CAP_LINKS]; /* Link Control Block pool */ - tL2C_CCB ccb_pool[MAX_L2CAP_CHANNELS]; /* Channel Control Block pool */ - tL2C_RCB rcb_pool[MAX_L2CAP_CLIENTS]; /* Registration info pool */ + tL2C_LCB lcb_pool[MAX_L2CAP_LINKS]; /* Link Control Block pool */ + tL2C_CCB ccb_pool[MAX_L2CAP_CHANNELS]; /* Channel Control Block pool */ + tL2C_RCB rcb_pool[MAX_L2CAP_CLIENTS]; /* Registration info pool */ - tL2C_CCB *p_free_ccb_first; /* Pointer to first free CCB */ - tL2C_CCB *p_free_ccb_last; /* Pointer to last free CCB */ + tL2C_CCB* p_free_ccb_first; /* Pointer to first free CCB */ + tL2C_CCB* p_free_ccb_last; /* Pointer to last free CCB */ - uint8_t desire_role; /* desire to be master/slave when accepting a connection */ - bool disallow_switch; /* false, to allow switch at create conn */ - uint16_t num_lm_acl_bufs; /* # of ACL buffers on controller */ - uint16_t idle_timeout; /* Idle timeout */ + uint8_t + desire_role; /* desire to be master/slave when accepting a connection */ + bool disallow_switch; /* false, to allow switch at create conn */ + uint16_t num_lm_acl_bufs; /* # of ACL buffers on controller */ + uint16_t idle_timeout; /* Idle timeout */ - list_t *rcv_pending_q; /* Recv pending queue */ - alarm_t *receive_hold_timer; /* Timer entry for rcv hold */ + list_t* rcv_pending_q; /* Recv pending queue */ + alarm_t* receive_hold_timer; /* Timer entry for rcv hold */ - tL2C_LCB *p_cur_hcit_lcb; /* Current HCI Transport buffer */ - uint16_t num_links_active; /* Number of links active */ + tL2C_LCB* p_cur_hcit_lcb; /* Current HCI Transport buffer */ + uint16_t num_links_active; /* Number of links active */ #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - uint16_t non_flushable_pbf; /* L2CAP_PKT_START_NON_FLUSHABLE if controller supports */ - /* Otherwise, L2CAP_PKT_START */ - bool is_flush_active; /* true if an HCI_Enhanced_Flush has been sent */ + uint16_t non_flushable_pbf; /* L2CAP_PKT_START_NON_FLUSHABLE if controller + supports */ + /* Otherwise, L2CAP_PKT_START */ + bool is_flush_active; /* true if an HCI_Enhanced_Flush has been sent */ #endif #if (L2CAP_CONFORMANCE_TESTING == TRUE) - uint32_t test_info_resp; /* Conformance testing needs a dynamic response */ + uint32_t test_info_resp; /* Conformance testing needs a dynamic response */ #endif #if (L2CAP_NUM_FIXED_CHNLS > 0) - tL2CAP_FIXED_CHNL_REG fixed_reg[L2CAP_NUM_FIXED_CHNLS]; /* Reg info for fixed channels */ + tL2CAP_FIXED_CHNL_REG + fixed_reg[L2CAP_NUM_FIXED_CHNLS]; /* Reg info for fixed channels */ #endif - uint16_t num_ble_links_active; /* Number of LE links active */ - bool is_ble_connecting; - BD_ADDR ble_connecting_bda; - uint16_t controller_le_xmit_window; /* Total ACL window for all links */ - tL2C_BLE_FIXED_CHNLS_MASK l2c_ble_fixed_chnls_mask; // LE fixed channels mask - uint16_t num_lm_ble_bufs; /* # of ACL buffers on controller */ - uint16_t ble_round_robin_quota; /* Round-robin link quota */ - uint16_t ble_round_robin_unacked; /* Round-robin unacked */ - bool ble_check_round_robin; /* Do a round robin check */ - tL2C_RCB ble_rcb_pool[BLE_MAX_L2CAP_CLIENTS]; /* Registration info pool */ + uint16_t num_ble_links_active; /* Number of LE links active */ + bool is_ble_connecting; + BD_ADDR ble_connecting_bda; + uint16_t controller_le_xmit_window; /* Total ACL window for all links */ + tL2C_BLE_FIXED_CHNLS_MASK l2c_ble_fixed_chnls_mask; // LE fixed channels mask + uint16_t num_lm_ble_bufs; /* # of ACL buffers on controller */ + uint16_t ble_round_robin_quota; /* Round-robin link quota */ + uint16_t ble_round_robin_unacked; /* Round-robin unacked */ + bool ble_check_round_robin; /* Do a round robin check */ + tL2C_RCB ble_rcb_pool[BLE_MAX_L2CAP_CLIENTS]; /* Registration info pool */ - tL2CA_ECHO_DATA_CB *p_echo_data_cb; /* Echo data callback */ + tL2CA_ECHO_DATA_CB* p_echo_data_cb; /* Echo data callback */ #if (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == TRUE) - uint16_t high_pri_min_xmit_quota; /* Minimum number of ACL credit for high priority link */ + uint16_t high_pri_min_xmit_quota; /* Minimum number of ACL credit for high + priority link */ #endif /* (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == TRUE) */ - uint16_t dyn_psm; + uint16_t dyn_psm; } tL2C_CB; - - /* Define a structure that contains the information about a connection. * This structure is used to pass between functions, and not all the * fields will always be filled in. */ -typedef struct -{ - BD_ADDR bd_addr; /* Remote BD address */ - uint8_t status; /* Connection status */ - uint16_t psm; /* PSM of the connection */ - uint16_t l2cap_result; /* L2CAP result */ - uint16_t l2cap_status; /* L2CAP status */ - uint16_t remote_cid; /* Remote CID */ +typedef struct { + BD_ADDR bd_addr; /* Remote BD address */ + uint8_t status; /* Connection status */ + uint16_t psm; /* PSM of the connection */ + uint16_t l2cap_result; /* L2CAP result */ + uint16_t l2cap_status; /* L2CAP status */ + uint16_t remote_cid; /* Remote CID */ } tL2C_CONN_INFO; - -typedef void (tL2C_FCR_MGMT_EVT_HDLR) (uint8_t, tL2C_CCB *); +typedef void(tL2C_FCR_MGMT_EVT_HDLR)(uint8_t, tL2C_CCB*); /* The offset in a buffer that L2CAP will use when building commands. */ -#define L2CAP_SEND_CMD_OFFSET 0 - +#define L2CAP_SEND_CMD_OFFSET 0 /* Number of ACL buffers to use for high priority channel */ #if (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == FALSE) -#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (L2CAP_HIGH_PRI_MIN_XMIT_QUOTA) +#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (L2CAP_HIGH_PRI_MIN_XMIT_QUOTA) #else -#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (l2cb.high_pri_min_xmit_quota) +#define L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A (l2cb.high_pri_min_xmit_quota) #endif /* L2CAP global data *********************************** */ -extern tL2C_CB l2cb; - +extern tL2C_CB l2cb; /* Functions provided by l2c_main.cc *********************************** @@ -572,217 +572,261 @@ extern tL2C_CB l2cb; void l2c_init(void); void l2c_free(void); -extern void l2c_receive_hold_timer_timeout(void *data); -extern void l2c_ccb_timer_timeout(void *data); -extern void l2c_lcb_timer_timeout(void *data); -extern void l2c_fcrb_ack_timer_timeout(void *data); -extern uint8_t l2c_data_write (uint16_t cid, BT_HDR *p_data, uint16_t flag); -extern void l2c_rcv_acl_data (BT_HDR *p_msg); -extern void l2c_process_held_packets (bool timed_out); +extern void l2c_receive_hold_timer_timeout(void* data); +extern void l2c_ccb_timer_timeout(void* data); +extern void l2c_lcb_timer_timeout(void* data); +extern void l2c_fcrb_ack_timer_timeout(void* data); +extern uint8_t l2c_data_write(uint16_t cid, BT_HDR* p_data, uint16_t flag); +extern void l2c_rcv_acl_data(BT_HDR* p_msg); +extern void l2c_process_held_packets(bool timed_out); /* Functions provided by l2c_utils.cc *********************************** */ -extern tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, bool is_bonding, tBT_TRANSPORT transport); -extern bool l2cu_start_post_bond_timer (uint16_t handle); -extern void l2cu_release_lcb (tL2C_LCB *p_lcb); -extern tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport); -extern tL2C_LCB *l2cu_find_lcb_by_handle (uint16_t handle); -extern void l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, bool is_bonding); - -extern uint8_t l2cu_get_conn_role (tL2C_LCB *p_this_lcb); -extern bool l2cu_set_acl_priority (BD_ADDR bd_addr, uint8_t priority, bool reset_after_rs); - -extern void l2cu_enqueue_ccb (tL2C_CCB *p_ccb); -extern void l2cu_dequeue_ccb (tL2C_CCB *p_ccb); -extern void l2cu_change_pri_ccb (tL2C_CCB *p_ccb, tL2CAP_CHNL_PRIORITY priority); - -extern tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, uint16_t cid); -extern void l2cu_release_ccb (tL2C_CCB *p_ccb); -extern tL2C_CCB *l2cu_find_ccb_by_cid (tL2C_LCB *p_lcb, uint16_t local_cid); -extern tL2C_CCB *l2cu_find_ccb_by_remote_cid (tL2C_LCB *p_lcb, uint16_t remote_cid); -extern void l2cu_adj_id (tL2C_LCB *p_lcb, uint8_t adj_mask); -extern bool l2c_is_cmd_rejected (uint8_t cmd_code, uint8_t id, tL2C_LCB *p_lcb); - -extern void l2cu_send_peer_cmd_reject (tL2C_LCB *p_lcb, uint16_t reason, - uint8_t rem_id,uint16_t p1, uint16_t p2); -extern void l2cu_send_peer_connect_req (tL2C_CCB *p_ccb); -extern void l2cu_send_peer_connect_rsp (tL2C_CCB *p_ccb, uint16_t result, uint16_t status); -extern void l2cu_send_peer_config_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2cu_send_peer_config_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2cu_send_peer_config_rej (tL2C_CCB *p_ccb, uint8_t *p_data, uint16_t data_len, uint16_t rej_len); -extern void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb); -extern void l2cu_send_peer_disc_rsp (tL2C_LCB *p_lcb, uint8_t remote_id, uint16_t local_cid, uint16_t remote_cid); -extern void l2cu_send_peer_echo_req (tL2C_LCB *p_lcb, uint8_t *p_data, uint16_t data_len); -extern void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, uint8_t id, uint8_t *p_data, uint16_t data_len); -extern void l2cu_send_peer_info_rsp (tL2C_LCB *p_lcb, uint8_t id, uint16_t info_type); -extern void l2cu_reject_connection (tL2C_LCB *p_lcb, uint16_t remote_cid, uint8_t rem_id, uint16_t result); -extern void l2cu_send_peer_info_req (tL2C_LCB *p_lcb, uint16_t info_type); -extern void l2cu_set_acl_hci_header (BT_HDR *p_buf, tL2C_CCB *p_ccb); -extern void l2cu_check_channel_congestion (tL2C_CCB *p_ccb); -extern void l2cu_disconnect_chnl (tL2C_CCB *p_ccb); +extern tL2C_LCB* l2cu_allocate_lcb(BD_ADDR p_bd_addr, bool is_bonding, + tBT_TRANSPORT transport); +extern bool l2cu_start_post_bond_timer(uint16_t handle); +extern void l2cu_release_lcb(tL2C_LCB* p_lcb); +extern tL2C_LCB* l2cu_find_lcb_by_bd_addr(BD_ADDR p_bd_addr, + tBT_TRANSPORT transport); +extern tL2C_LCB* l2cu_find_lcb_by_handle(uint16_t handle); +extern void l2cu_update_lcb_4_bonding(BD_ADDR p_bd_addr, bool is_bonding); + +extern uint8_t l2cu_get_conn_role(tL2C_LCB* p_this_lcb); +extern bool l2cu_set_acl_priority(BD_ADDR bd_addr, uint8_t priority, + bool reset_after_rs); + +extern void l2cu_enqueue_ccb(tL2C_CCB* p_ccb); +extern void l2cu_dequeue_ccb(tL2C_CCB* p_ccb); +extern void l2cu_change_pri_ccb(tL2C_CCB* p_ccb, tL2CAP_CHNL_PRIORITY priority); + +extern tL2C_CCB* l2cu_allocate_ccb(tL2C_LCB* p_lcb, uint16_t cid); +extern void l2cu_release_ccb(tL2C_CCB* p_ccb); +extern tL2C_CCB* l2cu_find_ccb_by_cid(tL2C_LCB* p_lcb, uint16_t local_cid); +extern tL2C_CCB* l2cu_find_ccb_by_remote_cid(tL2C_LCB* p_lcb, + uint16_t remote_cid); +extern void l2cu_adj_id(tL2C_LCB* p_lcb, uint8_t adj_mask); +extern bool l2c_is_cmd_rejected(uint8_t cmd_code, uint8_t id, tL2C_LCB* p_lcb); + +extern void l2cu_send_peer_cmd_reject(tL2C_LCB* p_lcb, uint16_t reason, + uint8_t rem_id, uint16_t p1, uint16_t p2); +extern void l2cu_send_peer_connect_req(tL2C_CCB* p_ccb); +extern void l2cu_send_peer_connect_rsp(tL2C_CCB* p_ccb, uint16_t result, + uint16_t status); +extern void l2cu_send_peer_config_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); +extern void l2cu_send_peer_config_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); +extern void l2cu_send_peer_config_rej(tL2C_CCB* p_ccb, uint8_t* p_data, + uint16_t data_len, uint16_t rej_len); +extern void l2cu_send_peer_disc_req(tL2C_CCB* p_ccb); +extern void l2cu_send_peer_disc_rsp(tL2C_LCB* p_lcb, uint8_t remote_id, + uint16_t local_cid, uint16_t remote_cid); +extern void l2cu_send_peer_echo_req(tL2C_LCB* p_lcb, uint8_t* p_data, + uint16_t data_len); +extern void l2cu_send_peer_echo_rsp(tL2C_LCB* p_lcb, uint8_t id, + uint8_t* p_data, uint16_t data_len); +extern void l2cu_send_peer_info_rsp(tL2C_LCB* p_lcb, uint8_t id, + uint16_t info_type); +extern void l2cu_reject_connection(tL2C_LCB* p_lcb, uint16_t remote_cid, + uint8_t rem_id, uint16_t result); +extern void l2cu_send_peer_info_req(tL2C_LCB* p_lcb, uint16_t info_type); +extern void l2cu_set_acl_hci_header(BT_HDR* p_buf, tL2C_CCB* p_ccb); +extern void l2cu_check_channel_congestion(tL2C_CCB* p_ccb); +extern void l2cu_disconnect_chnl(tL2C_CCB* p_ccb); #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) -extern void l2cu_set_non_flushable_pbf(bool ); +extern void l2cu_set_non_flushable_pbf(bool); #endif -extern void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, uint16_t min_int, uint16_t max_int, uint16_t latency, uint16_t timeout); -extern void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, uint16_t reason, uint8_t rem_id); -extern void l2cu_reject_ble_connection (tL2C_LCB *p_lcb, uint8_t rem_id, uint16_t result); -extern void l2cu_send_peer_ble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result); -extern void l2cu_send_peer_ble_credit_based_conn_req (tL2C_CCB *p_ccb); -extern void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_value); -extern void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB *p_ccb); - -extern bool l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, uint16_t fixed_cid, tL2CAP_FCR_OPTS *p_fcr); -extern void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb); -extern void l2cu_process_fixed_chnl_resp (tL2C_LCB *p_lcb); -extern bool l2cu_is_ccb_active (tL2C_CCB *p_ccb); +extern void l2cu_send_peer_ble_par_req(tL2C_LCB* p_lcb, uint16_t min_int, + uint16_t max_int, uint16_t latency, + uint16_t timeout); +extern void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, uint16_t reason, + uint8_t rem_id); +extern void l2cu_reject_ble_connection(tL2C_LCB* p_lcb, uint8_t rem_id, + uint16_t result); +extern void l2cu_send_peer_ble_credit_based_conn_res(tL2C_CCB* p_ccb, + uint16_t result); +extern void l2cu_send_peer_ble_credit_based_conn_req(tL2C_CCB* p_ccb); +extern void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB* p_ccb, + uint16_t credit_value); +extern void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB* p_ccb); + +extern bool l2cu_initialize_fixed_ccb(tL2C_LCB* p_lcb, uint16_t fixed_cid, + tL2CAP_FCR_OPTS* p_fcr); +extern void l2cu_no_dynamic_ccbs(tL2C_LCB* p_lcb); +extern void l2cu_process_fixed_chnl_resp(tL2C_LCB* p_lcb); +extern bool l2cu_is_ccb_active(tL2C_CCB* p_ccb); /* Functions provided by l2c_ucd.cc *********************************** */ #if (L2CAP_UCD_INCLUDED == TRUE) -void l2c_ucd_delete_sec_pending_q(tL2C_LCB *p_lcb); -void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB *p_ccb, void *p_data); -bool l2c_ucd_check_pending_info_req(tL2C_CCB *p_ccb); -bool l2c_ucd_check_pending_out_sec_q(tL2C_CCB *p_ccb); -void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb); -void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb); -bool l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb); -void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb); -void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB *p_ccb); -bool l2c_ucd_check_rx_pkts(tL2C_LCB *p_lcb, BT_HDR *p_msg); -bool l2c_ucd_process_event(tL2C_CCB *p_ccb, uint16_t event, void *p_data); +void l2c_ucd_delete_sec_pending_q(tL2C_LCB* p_lcb); +void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB* p_ccb, void* p_data); +bool l2c_ucd_check_pending_info_req(tL2C_CCB* p_ccb); +bool l2c_ucd_check_pending_out_sec_q(tL2C_CCB* p_ccb); +void l2c_ucd_send_pending_out_sec_q(tL2C_CCB* p_ccb); +void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB* p_ccb); +bool l2c_ucd_check_pending_in_sec_q(tL2C_CCB* p_ccb); +void l2c_ucd_send_pending_in_sec_q(tL2C_CCB* p_ccb); +void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB* p_ccb); +bool l2c_ucd_check_rx_pkts(tL2C_LCB* p_lcb, BT_HDR* p_msg); +bool l2c_ucd_process_event(tL2C_CCB* p_ccb, uint16_t event, void* p_data); #endif /* Functions provided for Broadcom Aware *************************************** */ -extern bool l2cu_check_feature_req (tL2C_LCB *p_lcb, uint8_t id, uint8_t *p_data, uint16_t data_len); -extern void l2cu_check_feature_rsp (tL2C_LCB *p_lcb, uint8_t id, uint8_t *p_data, uint16_t data_len); -extern void l2cu_send_feature_req (tL2C_CCB *p_ccb); - -extern tL2C_RCB *l2cu_allocate_rcb (uint16_t psm); -extern tL2C_RCB *l2cu_find_rcb_by_psm (uint16_t psm); -extern void l2cu_release_rcb (tL2C_RCB *p_rcb); -extern tL2C_RCB *l2cu_allocate_ble_rcb (uint16_t psm); -extern tL2C_RCB *l2cu_find_ble_rcb_by_psm (uint16_t psm); - -extern uint8_t l2cu_process_peer_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2cu_process_peer_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2cu_process_our_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2cu_process_our_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); - -extern void l2cu_device_reset (void); -extern tL2C_LCB *l2cu_find_lcb_by_state (tL2C_LINK_STATE state); -extern bool l2cu_lcb_disconnecting (void); - -extern bool l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport); -extern bool l2cu_create_conn_after_switch (tL2C_LCB *p_lcb); -extern BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb); -extern void l2cu_resubmit_pending_sec_req (BD_ADDR p_bda); -extern void l2cu_initialize_amp_ccb (tL2C_LCB *p_lcb); -extern void l2cu_adjust_out_mps (tL2C_CCB *p_ccb); +extern bool l2cu_check_feature_req(tL2C_LCB* p_lcb, uint8_t id, uint8_t* p_data, + uint16_t data_len); +extern void l2cu_check_feature_rsp(tL2C_LCB* p_lcb, uint8_t id, uint8_t* p_data, + uint16_t data_len); +extern void l2cu_send_feature_req(tL2C_CCB* p_ccb); + +extern tL2C_RCB* l2cu_allocate_rcb(uint16_t psm); +extern tL2C_RCB* l2cu_find_rcb_by_psm(uint16_t psm); +extern void l2cu_release_rcb(tL2C_RCB* p_rcb); +extern tL2C_RCB* l2cu_allocate_ble_rcb(uint16_t psm); +extern tL2C_RCB* l2cu_find_ble_rcb_by_psm(uint16_t psm); + +extern uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, + tL2CAP_CFG_INFO* p_cfg); +extern void l2cu_process_peer_cfg_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); +extern void l2cu_process_our_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); +extern void l2cu_process_our_cfg_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); + +extern void l2cu_device_reset(void); +extern tL2C_LCB* l2cu_find_lcb_by_state(tL2C_LINK_STATE state); +extern bool l2cu_lcb_disconnecting(void); + +extern bool l2cu_create_conn(tL2C_LCB* p_lcb, tBT_TRANSPORT transport); +extern bool l2cu_create_conn_after_switch(tL2C_LCB* p_lcb); +extern BT_HDR* l2cu_get_next_buffer_to_send(tL2C_LCB* p_lcb); +extern void l2cu_resubmit_pending_sec_req(BD_ADDR p_bda); +extern void l2cu_initialize_amp_ccb(tL2C_LCB* p_lcb); +extern void l2cu_adjust_out_mps(tL2C_CCB* p_ccb); /* Functions provided by l2c_link.cc *********************************** */ -extern bool l2c_link_hci_conn_req (BD_ADDR bd_addr); -extern bool l2c_link_hci_conn_comp (uint8_t status, uint16_t handle, BD_ADDR p_bda); -extern bool l2c_link_hci_disc_comp (uint16_t handle, uint8_t reason); -extern bool l2c_link_hci_qos_violation (uint16_t handle); -extern void l2c_link_timeout (tL2C_LCB *p_lcb); -extern void l2c_info_resp_timer_timeout(void *data); -extern void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf); -extern void l2c_link_adjust_allocation (void); -extern void l2c_link_process_num_completed_pkts (uint8_t *p); -extern void l2c_link_process_num_completed_blocks (uint8_t controller_id, uint8_t *p, uint16_t evt_len); -extern void l2c_link_processs_num_bufs (uint16_t num_lm_acl_bufs); -extern uint8_t l2c_link_pkts_rcvd (uint16_t *num_pkts, uint16_t *handles); -extern void l2c_link_role_changed (BD_ADDR bd_addr, uint8_t new_role, uint8_t hci_status); -extern void l2c_link_sec_comp (BD_ADDR p_bda, tBT_TRANSPORT trasnport, void *p_ref_data, uint8_t status); -extern void l2c_link_segments_xmitted (BT_HDR *p_msg); -extern void l2c_pin_code_request (BD_ADDR bd_addr); -extern void l2c_link_adjust_chnl_allocation (void); - -extern void l2c_link_processs_ble_num_bufs (uint16_t num_lm_acl_bufs); +extern bool l2c_link_hci_conn_req(BD_ADDR bd_addr); +extern bool l2c_link_hci_conn_comp(uint8_t status, uint16_t handle, + BD_ADDR p_bda); +extern bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason); +extern bool l2c_link_hci_qos_violation(uint16_t handle); +extern void l2c_link_timeout(tL2C_LCB* p_lcb); +extern void l2c_info_resp_timer_timeout(void* data); +extern void l2c_link_check_send_pkts(tL2C_LCB* p_lcb, tL2C_CCB* p_ccb, + BT_HDR* p_buf); +extern void l2c_link_adjust_allocation(void); +extern void l2c_link_process_num_completed_pkts(uint8_t* p); +extern void l2c_link_process_num_completed_blocks(uint8_t controller_id, + uint8_t* p, uint16_t evt_len); +extern void l2c_link_processs_num_bufs(uint16_t num_lm_acl_bufs); +extern uint8_t l2c_link_pkts_rcvd(uint16_t* num_pkts, uint16_t* handles); +extern void l2c_link_role_changed(BD_ADDR bd_addr, uint8_t new_role, + uint8_t hci_status); +extern void l2c_link_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT trasnport, + void* p_ref_data, uint8_t status); +extern void l2c_link_segments_xmitted(BT_HDR* p_msg); +extern void l2c_pin_code_request(BD_ADDR bd_addr); +extern void l2c_link_adjust_chnl_allocation(void); + +extern void l2c_link_processs_ble_num_bufs(uint16_t num_lm_acl_bufs); #if (L2CAP_WAKE_PARKED_LINK == TRUE) -extern bool l2c_link_check_power_mode ( tL2C_LCB *p_lcb ); -#define L2C_LINK_CHECK_POWER_MODE(x) l2c_link_check_power_mode ((x)) +extern bool l2c_link_check_power_mode(tL2C_LCB* p_lcb); +#define L2C_LINK_CHECK_POWER_MODE(x) l2c_link_check_power_mode((x)) #else // L2CAP_WAKE_PARKED_LINK #define L2C_LINK_CHECK_POWER_MODE(x) (false) #endif // L2CAP_WAKE_PARKED_LINK #if (L2CAP_CONFORMANCE_TESTING == TRUE) /* Used only for conformance testing */ -extern void l2cu_set_info_rsp_mask (uint32_t mask); +extern void l2cu_set_info_rsp_mask(uint32_t mask); #endif /* Functions provided by l2c_csm.cc *********************************** */ -extern void l2c_csm_execute (tL2C_CCB *p_ccb, uint16_t event, void *p_data); - -extern void l2c_enqueue_peer_data (tL2C_CCB *p_ccb, BT_HDR *p_buf); +extern void l2c_csm_execute(tL2C_CCB* p_ccb, uint16_t event, void* p_data); +extern void l2c_enqueue_peer_data(tL2C_CCB* p_ccb, BT_HDR* p_buf); /* Functions provided by l2c_fcr.cc *********************************** */ -extern void l2c_fcr_cleanup (tL2C_CCB *p_ccb); -extern void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf); -extern void l2c_fcr_proc_tout (tL2C_CCB *p_ccb); -extern void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb); -extern void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, uint16_t function_code, uint16_t pf_bit); -extern BT_HDR *l2c_fcr_clone_buf(BT_HDR *p_buf, uint16_t new_offset, uint16_t no_of_bytes); -extern bool l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb); -extern BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_length); -extern void l2c_fcr_start_timer (tL2C_CCB *p_ccb); -extern void l2c_lcc_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf); -extern BT_HDR *l2c_lcc_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, uint16_t max_packet_length); +extern void l2c_fcr_cleanup(tL2C_CCB* p_ccb); +extern void l2c_fcr_proc_pdu(tL2C_CCB* p_ccb, BT_HDR* p_buf); +extern void l2c_fcr_proc_tout(tL2C_CCB* p_ccb); +extern void l2c_fcr_proc_ack_tout(tL2C_CCB* p_ccb); +extern void l2c_fcr_send_S_frame(tL2C_CCB* p_ccb, uint16_t function_code, + uint16_t pf_bit); +extern BT_HDR* l2c_fcr_clone_buf(BT_HDR* p_buf, uint16_t new_offset, + uint16_t no_of_bytes); +extern bool l2c_fcr_is_flow_controlled(tL2C_CCB* p_ccb); +extern BT_HDR* l2c_fcr_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb, + uint16_t max_packet_length); +extern void l2c_fcr_start_timer(tL2C_CCB* p_ccb); +extern void l2c_lcc_proc_pdu(tL2C_CCB* p_ccb, BT_HDR* p_buf); +extern BT_HDR* l2c_lcc_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb, + uint16_t max_packet_length); /* Configuration negotiation */ -extern uint8_t l2c_fcr_chk_chan_modes (tL2C_CCB *p_ccb); -extern bool l2c_fcr_adj_our_req_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2c_fcr_adj_our_rsp_options (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_peer_cfg); -extern bool l2c_fcr_renegotiate_chan(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); -extern void l2c_fcr_adj_monitor_retran_timeout (tL2C_CCB *p_ccb); -extern void l2c_fcr_stop_timer (tL2C_CCB *p_ccb); +extern uint8_t l2c_fcr_chk_chan_modes(tL2C_CCB* p_ccb); +extern bool l2c_fcr_adj_our_req_options(tL2C_CCB* p_ccb, + tL2CAP_CFG_INFO* p_cfg); +extern void l2c_fcr_adj_our_rsp_options(tL2C_CCB* p_ccb, + tL2CAP_CFG_INFO* p_peer_cfg); +extern bool l2c_fcr_renegotiate_chan(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg); +extern uint8_t l2c_fcr_process_peer_cfg_req(tL2C_CCB* p_ccb, + tL2CAP_CFG_INFO* p_cfg); +extern void l2c_fcr_adj_monitor_retran_timeout(tL2C_CCB* p_ccb); +extern void l2c_fcr_stop_timer(tL2C_CCB* p_ccb); /* Functions provided by l2c_ble.cc *********************************** */ -extern bool l2cble_create_conn (tL2C_LCB *p_lcb); -extern void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len); -extern void l2cble_conn_comp (uint16_t handle, uint8_t role, BD_ADDR bda, tBLE_ADDR_TYPE type, - uint16_t conn_interval, uint16_t conn_latency, uint16_t conn_timeout); -extern bool l2cble_init_direct_conn (tL2C_LCB *p_lcb); -extern void l2cble_notify_le_connection (BD_ADDR bda); -extern void l2c_ble_link_adjust_allocation (void); -extern void l2cble_process_conn_update_evt (uint16_t handle, uint8_t status, - uint16_t interval, uint16_t latency, uint16_t timeout); - -extern void l2cble_credit_based_conn_req (tL2C_CCB *p_ccb); -extern void l2cble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result); -extern void l2cble_send_peer_disc_req(tL2C_CCB *p_ccb); -extern void l2cble_send_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_value); -extern bool l2ble_sec_access_req(BD_ADDR bd_addr, uint16_t psm, bool is_originator, tL2CAP_SEC_CBACK *p_callback, void *p_ref_data); +extern bool l2cble_create_conn(tL2C_LCB* p_lcb); +extern void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, + uint16_t pkt_len); +extern void l2cble_conn_comp(uint16_t handle, uint8_t role, BD_ADDR bda, + tBLE_ADDR_TYPE type, uint16_t conn_interval, + uint16_t conn_latency, uint16_t conn_timeout); +extern bool l2cble_init_direct_conn(tL2C_LCB* p_lcb); +extern void l2cble_notify_le_connection(BD_ADDR bda); +extern void l2c_ble_link_adjust_allocation(void); +extern void l2cble_process_conn_update_evt(uint16_t handle, uint8_t status, + uint16_t interval, uint16_t latency, + uint16_t timeout); + +extern void l2cble_credit_based_conn_req(tL2C_CCB* p_ccb); +extern void l2cble_credit_based_conn_res(tL2C_CCB* p_ccb, uint16_t result); +extern void l2cble_send_peer_disc_req(tL2C_CCB* p_ccb); +extern void l2cble_send_flow_control_credit(tL2C_CCB* p_ccb, + uint16_t credit_value); +extern bool l2ble_sec_access_req(BD_ADDR bd_addr, uint16_t psm, + bool is_originator, + tL2CAP_SEC_CBACK* p_callback, + void* p_ref_data); #if (BLE_LLT_INCLUDED == TRUE) -extern void l2cble_process_rc_param_request_evt(uint16_t handle, uint16_t int_min, uint16_t int_max, - uint16_t latency, uint16_t timeout); +extern void l2cble_process_rc_param_request_evt(uint16_t handle, + uint16_t int_min, + uint16_t int_max, + uint16_t latency, + uint16_t timeout); #endif -extern void l2cble_update_data_length(tL2C_LCB *p_lcb); -extern void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, uint16_t fix_cid, - uint16_t tx_mtu); -extern void l2cble_process_data_length_change_event(uint16_t handle, uint16_t tx_data_len, - uint16_t rx_data_len); +extern void l2cble_update_data_length(tL2C_LCB* p_lcb); +extern void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, + uint16_t fix_cid, + uint16_t tx_mtu); +extern void l2cble_process_data_length_change_event(uint16_t handle, + uint16_t tx_data_len, + uint16_t rx_data_len); -extern void l2cu_process_fixed_disc_cback (tL2C_LCB *p_lcb); +extern void l2cu_process_fixed_disc_cback(tL2C_LCB* p_lcb); #ifdef __cplusplus } diff --git a/stack/l2cap/l2c_link.cc b/stack/l2cap/l2c_link.cc index 1194c5a11..e590b5142 100644 --- a/stack/l2cap/l2c_link.cc +++ b/stack/l2cap/l2c_link.cc @@ -25,28 +25,27 @@ ******************************************************************************/ #include +#include #include #include -#include -#include "device/include/controller.h" #include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" -#include "hcimsgs.h" -#include "l2cdefs.h" -#include "l2c_int.h" -#include "l2c_api.h" -#include "btu.h" +#include "btcore/include/bdaddr.h" #include "btm_api.h" #include "btm_int.h" -#include "btcore/include/bdaddr.h" +#include "btu.h" +#include "device/include/controller.h" +#include "hcimsgs.h" +#include "l2c_api.h" +#include "l2c_int.h" +#include "l2cdefs.h" #include "osi/include/osi.h" +extern fixed_queue_t* btu_general_alarm_queue; -extern fixed_queue_t *btu_general_alarm_queue; - -static bool l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf); +static bool l2c_link_send_to_lower(tL2C_LCB* p_lcb, BT_HDR* p_buf); /******************************************************************************* * @@ -58,92 +57,82 @@ static bool l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf); * Returns true, if accept conn * ******************************************************************************/ -bool l2c_link_hci_conn_req (BD_ADDR bd_addr) -{ - tL2C_LCB *p_lcb; - tL2C_LCB *p_lcb_cur; - int xx; - bool no_links; - - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR); - - /* If we don't have one, create one and accept the connection. */ - if (!p_lcb) - { - p_lcb = l2cu_allocate_lcb (bd_addr, false, BT_TRANSPORT_BR_EDR); - if (!p_lcb) - { - btsnd_hcic_reject_conn (bd_addr, HCI_ERR_HOST_REJECT_RESOURCES); - L2CAP_TRACE_ERROR ("L2CAP failed to allocate LCB"); - return false; - } - - no_links = true; +bool l2c_link_hci_conn_req(BD_ADDR bd_addr) { + tL2C_LCB* p_lcb; + tL2C_LCB* p_lcb_cur; + int xx; + bool no_links; + + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); + + /* If we don't have one, create one and accept the connection. */ + if (!p_lcb) { + p_lcb = l2cu_allocate_lcb(bd_addr, false, BT_TRANSPORT_BR_EDR); + if (!p_lcb) { + btsnd_hcic_reject_conn(bd_addr, HCI_ERR_HOST_REJECT_RESOURCES); + L2CAP_TRACE_ERROR("L2CAP failed to allocate LCB"); + return false; + } - /* If we already have connection, accept as a master */ - for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb_cur++) - { - if (p_lcb_cur == p_lcb) - continue; + no_links = true; - if (p_lcb_cur->in_use) - { - no_links = false; - p_lcb->link_role = HCI_ROLE_MASTER; - break; - } - } + /* If we already have connection, accept as a master */ + for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; + xx++, p_lcb_cur++) { + if (p_lcb_cur == p_lcb) continue; - if (no_links) - { - if (!btm_dev_support_switch (bd_addr)) - p_lcb->link_role = HCI_ROLE_SLAVE; - else - p_lcb->link_role = l2cu_get_conn_role(p_lcb); - } + if (p_lcb_cur->in_use) { + no_links = false; + p_lcb->link_role = HCI_ROLE_MASTER; + break; + } + } + if (no_links) { + if (!btm_dev_support_switch(bd_addr)) + p_lcb->link_role = HCI_ROLE_SLAVE; + else + p_lcb->link_role = l2cu_get_conn_role(p_lcb); + } - /* Tell the other side we accept the connection */ - btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role); + /* Tell the other side we accept the connection */ + btsnd_hcic_accept_conn(bd_addr, p_lcb->link_role); - p_lcb->link_state = LST_CONNECTING; + p_lcb->link_state = LST_CONNECTING; - /* Start a timer waiting for connect complete */ - alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_LINK_CONNECT_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - return (true); - } + /* Start a timer waiting for connect complete */ + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_LINK_CONNECT_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + return (true); + } - /* We already had a link control block to the guy. Check what state it is in */ - if ((p_lcb->link_state == LST_CONNECTING) || (p_lcb->link_state == LST_CONNECT_HOLDING)) - { - /* Connection collision. Accept the connection anyways. */ + /* We already had a link control block to the guy. Check what state it is in + */ + if ((p_lcb->link_state == LST_CONNECTING) || + (p_lcb->link_state == LST_CONNECT_HOLDING)) { + /* Connection collision. Accept the connection anyways. */ - if (!btm_dev_support_switch (bd_addr)) - p_lcb->link_role = HCI_ROLE_SLAVE; - else - p_lcb->link_role = l2cu_get_conn_role(p_lcb); + if (!btm_dev_support_switch(bd_addr)) + p_lcb->link_role = HCI_ROLE_SLAVE; + else + p_lcb->link_role = l2cu_get_conn_role(p_lcb); - btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role); + btsnd_hcic_accept_conn(bd_addr, p_lcb->link_role); - p_lcb->link_state = LST_CONNECTING; - return (true); - } - else if (p_lcb->link_state == LST_DISCONNECTING) - { - /* In disconnecting state, reject the connection. */ - btsnd_hcic_reject_conn (bd_addr, HCI_ERR_HOST_REJECT_DEVICE); - } - else - { - L2CAP_TRACE_ERROR("L2CAP got conn_req while connected (state:%d). Reject it", - p_lcb->link_state); - /* Reject the connection with ACL Connection Already exist reason */ - btsnd_hcic_reject_conn (bd_addr, HCI_ERR_CONNECTION_EXISTS); - } - return (false); + p_lcb->link_state = LST_CONNECTING; + return (true); + } else if (p_lcb->link_state == LST_DISCONNECTING) { + /* In disconnecting state, reject the connection. */ + btsnd_hcic_reject_conn(bd_addr, HCI_ERR_HOST_REJECT_DEVICE); + } else { + L2CAP_TRACE_ERROR( + "L2CAP got conn_req while connected (state:%d). Reject it", + p_lcb->link_state); + /* Reject the connection with ACL Connection Already exist reason */ + btsnd_hcic_reject_conn(bd_addr, HCI_ERR_CONNECTION_EXISTS); + } + return (false); } /******************************************************************************* @@ -156,138 +145,121 @@ bool l2c_link_hci_conn_req (BD_ADDR bd_addr) * Returns void * ******************************************************************************/ -bool l2c_link_hci_conn_comp (uint8_t status, uint16_t handle, BD_ADDR p_bda) -{ - tL2C_CONN_INFO ci; - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tBTM_SEC_DEV_REC *p_dev_info = NULL; +bool l2c_link_hci_conn_comp(uint8_t status, uint16_t handle, BD_ADDR p_bda) { + tL2C_CONN_INFO ci; + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tBTM_SEC_DEV_REC* p_dev_info = NULL; - btm_acl_update_busy_level (BTM_BLI_PAGE_DONE_EVT); + btm_acl_update_busy_level(BTM_BLI_PAGE_DONE_EVT); - /* Save the parameters */ - ci.status = status; - memcpy (ci.bd_addr, p_bda, BD_ADDR_LEN); + /* Save the parameters */ + ci.status = status; + memcpy(ci.bd_addr, p_bda, BD_ADDR_LEN); - /* See if we have a link control block for the remote device */ - p_lcb = l2cu_find_lcb_by_bd_addr (ci.bd_addr, BT_TRANSPORT_BR_EDR); + /* See if we have a link control block for the remote device */ + p_lcb = l2cu_find_lcb_by_bd_addr(ci.bd_addr, BT_TRANSPORT_BR_EDR); - /* If we don't have one, this is an error */ - if (!p_lcb) - { - L2CAP_TRACE_WARNING ("L2CAP got conn_comp for unknown BD_ADDR"); - return (false); - } + /* If we don't have one, this is an error */ + if (!p_lcb) { + L2CAP_TRACE_WARNING("L2CAP got conn_comp for unknown BD_ADDR"); + return (false); + } - if (p_lcb->link_state != LST_CONNECTING) - { - L2CAP_TRACE_ERROR ("L2CAP got conn_comp in bad state: %d status: 0x%d", p_lcb->link_state, status); + if (p_lcb->link_state != LST_CONNECTING) { + L2CAP_TRACE_ERROR("L2CAP got conn_comp in bad state: %d status: 0x%d", + p_lcb->link_state, status); - if (status != HCI_SUCCESS) - l2c_link_hci_disc_comp (p_lcb->handle, status); + if (status != HCI_SUCCESS) l2c_link_hci_disc_comp(p_lcb->handle, status); - return (false); - } + return (false); + } - /* Save the handle */ - p_lcb->handle = handle; + /* Save the handle */ + p_lcb->handle = handle; - if (ci.status == HCI_SUCCESS) - { - /* Connected OK. Change state to connected */ - p_lcb->link_state = LST_CONNECTED; - - /* Get the peer information if the l2cap flow-control/rtrans is supported */ - l2cu_send_peer_info_req (p_lcb, L2CAP_EXTENDED_FEATURES_INFO_TYPE); - - /* Tell BTM Acl management about the link */ - p_dev_info = btm_find_dev(p_bda); - if (p_dev_info != NULL) - btm_acl_created (ci.bd_addr, p_dev_info->dev_class, - p_dev_info->sec_bd_name, handle, - p_lcb->link_role, BT_TRANSPORT_BR_EDR); - else - btm_acl_created (ci.bd_addr, NULL, NULL, handle, p_lcb->link_role, BT_TRANSPORT_BR_EDR); - - BTM_SetLinkSuperTout (ci.bd_addr, btm_cb.btm_def_link_super_tout); - - /* If dedicated bonding do not process any further */ - if (p_lcb->is_bonding) - { - if (l2cu_start_post_bond_timer(handle)) - return (true); - } + if (ci.status == HCI_SUCCESS) { + /* Connected OK. Change state to connected */ + p_lcb->link_state = LST_CONNECTED; - /* Update the timeouts in the hold queue */ - l2c_process_held_packets(false); + /* Get the peer information if the l2cap flow-control/rtrans is supported */ + l2cu_send_peer_info_req(p_lcb, L2CAP_EXTENDED_FEATURES_INFO_TYPE); - alarm_cancel(p_lcb->l2c_lcb_timer); + /* Tell BTM Acl management about the link */ + p_dev_info = btm_find_dev(p_bda); + if (p_dev_info != NULL) + btm_acl_created(ci.bd_addr, p_dev_info->dev_class, + p_dev_info->sec_bd_name, handle, p_lcb->link_role, + BT_TRANSPORT_BR_EDR); + else + btm_acl_created(ci.bd_addr, NULL, NULL, handle, p_lcb->link_role, + BT_TRANSPORT_BR_EDR); - /* For all channels, send the event through their FSMs */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM, &ci); - } + BTM_SetLinkSuperTout(ci.bd_addr, btm_cb.btm_def_link_super_tout); - if (p_lcb->p_echo_rsp_cb) - { - l2cu_send_peer_echo_req (p_lcb, NULL, 0); - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_ECHO_RSP_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } - else if (!p_lcb->ccb_queue.p_first_ccb) - { - period_ms_t timeout_ms = L2CAP_LINK_STARTUP_TOUT * 1000; - alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } - } - /* Max number of acl connections. */ - /* If there's an lcb disconnecting set this one to holding */ - else if ((ci.status == HCI_ERR_MAX_NUM_OF_CONNECTIONS) && l2cu_lcb_disconnecting()) - { - p_lcb->link_state = LST_CONNECT_HOLDING; - p_lcb->handle = HCI_INVALID_HANDLE; + /* If dedicated bonding do not process any further */ + if (p_lcb->is_bonding) { + if (l2cu_start_post_bond_timer(handle)) return (true); } - else - { - /* Just in case app decides to try again in the callback context */ - p_lcb->link_state = LST_DISCONNECTING; - /* Connection failed. For all channels, send the event through */ - /* their FSMs. The CCBs should remove themselves from the LCB */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; ) - { - tL2C_CCB *pn = p_ccb->p_next_ccb; + /* Update the timeouts in the hold queue */ + l2c_process_held_packets(false); - l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM_NEG, &ci); + alarm_cancel(p_lcb->l2c_lcb_timer); - p_ccb = pn; - } + /* For all channels, send the event through their FSMs */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + l2c_csm_execute(p_ccb, L2CEVT_LP_CONNECT_CFM, &ci); + } - p_lcb->disc_reason = status; - /* Release the LCB */ - if (p_lcb->ccb_queue.p_first_ccb == NULL) - l2cu_release_lcb (p_lcb); - else /* there are any CCBs remaining */ - { - if (ci.status == HCI_ERR_CONNECTION_EXISTS) - { - /* we are in collision situation, wait for connecttion request from controller */ - p_lcb->link_state = LST_CONNECTING; - } - else - { - l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR); - } - } + if (p_lcb->p_echo_rsp_cb) { + l2cu_send_peer_echo_req(p_lcb, NULL, 0); + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_ECHO_RSP_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } else if (!p_lcb->ccb_queue.p_first_ccb) { + period_ms_t timeout_ms = L2CAP_LINK_STARTUP_TOUT * 1000; + alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } + } + /* Max number of acl connections. */ + /* If there's an lcb disconnecting set this one to holding */ + else if ((ci.status == HCI_ERR_MAX_NUM_OF_CONNECTIONS) && + l2cu_lcb_disconnecting()) { + p_lcb->link_state = LST_CONNECT_HOLDING; + p_lcb->handle = HCI_INVALID_HANDLE; + } else { + /* Just in case app decides to try again in the callback context */ + p_lcb->link_state = LST_DISCONNECTING; + + /* Connection failed. For all channels, send the event through */ + /* their FSMs. The CCBs should remove themselves from the LCB */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;) { + tL2C_CCB* pn = p_ccb->p_next_ccb; + + l2c_csm_execute(p_ccb, L2CEVT_LP_CONNECT_CFM_NEG, &ci); + + p_ccb = pn; } - return (true); -} + p_lcb->disc_reason = status; + /* Release the LCB */ + if (p_lcb->ccb_queue.p_first_ccb == NULL) + l2cu_release_lcb(p_lcb); + else /* there are any CCBs remaining */ + { + if (ci.status == HCI_ERR_CONNECTION_EXISTS) { + /* we are in collision situation, wait for connecttion request from + * controller */ + p_lcb->link_state = LST_CONNECTING; + } else { + l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR); + } + } + } + return (true); +} /******************************************************************************* * @@ -299,65 +271,57 @@ bool l2c_link_hci_conn_comp (uint8_t status, uint16_t handle, BD_ADDR p_bda) * Returns void * ******************************************************************************/ -void l2c_link_sec_comp (BD_ADDR p_bda, - UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t status) -{ - tL2C_CONN_INFO ci; - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_CCB *p_next_ccb; - uint8_t event; - - L2CAP_TRACE_DEBUG ("l2c_link_sec_comp: %d, 0x%x", status, p_ref_data); - - if (status == BTM_SUCCESS_NO_SECURITY) - status = BTM_SUCCESS; - - /* Save the parameters */ - ci.status = status; - memcpy (ci.bd_addr, p_bda, BD_ADDR_LEN); - - p_lcb = l2cu_find_lcb_by_bd_addr (p_bda, transport); - - /* If we don't have one, this is an error */ - if (!p_lcb) - { - L2CAP_TRACE_WARNING ("L2CAP got sec_comp for unknown BD_ADDR"); - return; - } - - /* Match p_ccb with p_ref_data returned by sec manager */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) - { - p_next_ccb = p_ccb->p_next_ccb; - - if (p_ccb == p_ref_data) - { - switch(status) - { - case BTM_SUCCESS: - event = L2CEVT_SEC_COMP; - break; - - case BTM_DELAY_CHECK: - /* start a timer - encryption change not received before L2CAP connect req */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, - L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - return; - - default: - event = L2CEVT_SEC_COMP_NEG; - } - l2c_csm_execute (p_ccb, event, &ci); - break; - } +void l2c_link_sec_comp(BD_ADDR p_bda, UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t status) { + tL2C_CONN_INFO ci; + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_CCB* p_next_ccb; + uint8_t event; + + L2CAP_TRACE_DEBUG("l2c_link_sec_comp: %d, 0x%x", status, p_ref_data); + + if (status == BTM_SUCCESS_NO_SECURITY) status = BTM_SUCCESS; + + /* Save the parameters */ + ci.status = status; + memcpy(ci.bd_addr, p_bda, BD_ADDR_LEN); + + p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, transport); + + /* If we don't have one, this is an error */ + if (!p_lcb) { + L2CAP_TRACE_WARNING("L2CAP got sec_comp for unknown BD_ADDR"); + return; + } + + /* Match p_ccb with p_ref_data returned by sec manager */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) { + p_next_ccb = p_ccb->p_next_ccb; + + if (p_ccb == p_ref_data) { + switch (status) { + case BTM_SUCCESS: + event = L2CEVT_SEC_COMP; + break; + + case BTM_DELAY_CHECK: + /* start a timer - encryption change not received before L2CAP connect + * req */ + alarm_set_on_queue( + p_ccb->l2c_ccb_timer, L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS, + l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); + return; + + default: + event = L2CEVT_SEC_COMP_NEG; + } + l2c_csm_execute(p_ccb, event, &ci); + break; } + } } - /******************************************************************************* * * Function l2c_link_hci_disc_comp @@ -368,138 +332,131 @@ void l2c_link_sec_comp (BD_ADDR p_bda, * Returns true if the link is known about, else false * ******************************************************************************/ -bool l2c_link_hci_disc_comp (uint16_t handle, uint8_t reason) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - bool status = true; - bool lcb_is_free = true; - tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; - - /* See if we have a link control block for the connection */ - p_lcb = l2cu_find_lcb_by_handle (handle); - - /* If we don't have one, maybe an SCO link. Send to MM */ - if (!p_lcb) - { - status = false; +bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + bool status = true; + bool lcb_is_free = true; + tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; + + /* See if we have a link control block for the connection */ + p_lcb = l2cu_find_lcb_by_handle(handle); + + /* If we don't have one, maybe an SCO link. Send to MM */ + if (!p_lcb) { + status = false; + } else { + /* There can be a case when we rejected PIN code authentication */ + /* otherwise save a new reason */ + if (btm_cb.acl_disc_reason != HCI_ERR_HOST_REJECT_SECURITY) + btm_cb.acl_disc_reason = reason; + + p_lcb->disc_reason = btm_cb.acl_disc_reason; + + /* Just in case app decides to try again in the callback context */ + p_lcb->link_state = LST_DISCONNECTING; + + /* Check for BLE and handle that differently */ + if (p_lcb->transport == BT_TRANSPORT_LE) + btm_ble_update_link_topology_mask(p_lcb->link_role, false); + /* Link is disconnected. For all channels, send the event through */ + /* their FSMs. The CCBs should remove themselves from the LCB */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;) { + tL2C_CCB* pn = p_ccb->p_next_ccb; + + /* Keep connect pending control block (if exists) + * Possible Race condition when a reconnect occurs + * on the channel during a disconnect of link. This + * ccb will be automatically retried after link disconnect + * arrives + */ + if (p_ccb != p_lcb->p_pending_ccb) { + l2c_csm_execute(p_ccb, L2CEVT_LP_DISCONNECT_IND, &reason); + } + p_ccb = pn; } - else - { - /* There can be a case when we rejected PIN code authentication */ - /* otherwise save a new reason */ - if (btm_cb.acl_disc_reason != HCI_ERR_HOST_REJECT_SECURITY) - btm_cb.acl_disc_reason = reason; - - p_lcb->disc_reason = btm_cb.acl_disc_reason; - - /* Just in case app decides to try again in the callback context */ - p_lcb->link_state = LST_DISCONNECTING; - - /* Check for BLE and handle that differently */ - if (p_lcb->transport == BT_TRANSPORT_LE) - btm_ble_update_link_topology_mask(p_lcb->link_role, false); - /* Link is disconnected. For all channels, send the event through */ - /* their FSMs. The CCBs should remove themselves from the LCB */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; ) - { - tL2C_CCB *pn = p_ccb->p_next_ccb; - - /* Keep connect pending control block (if exists) - * Possible Race condition when a reconnect occurs - * on the channel during a disconnect of link. This - * ccb will be automatically retried after link disconnect - * arrives - */ - if (p_ccb != p_lcb->p_pending_ccb) - { - l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, &reason); - } - p_ccb = pn; - } #if (BTM_SCO_INCLUDED == TRUE) - if (p_lcb->transport == BT_TRANSPORT_BR_EDR) - /* Tell SCO management to drop any SCOs on this ACL */ - btm_sco_acl_removed (p_lcb->remote_bd_addr); + if (p_lcb->transport == BT_TRANSPORT_BR_EDR) + /* Tell SCO management to drop any SCOs on this ACL */ + btm_sco_acl_removed(p_lcb->remote_bd_addr); #endif - /* If waiting for disconnect and reconnect is pending start the reconnect now - race condition where layer above issued connect request on link that was - disconnecting - */ - if (p_lcb->ccb_queue.p_first_ccb != NULL || p_lcb->p_pending_ccb) - { - L2CAP_TRACE_DEBUG("l2c_link_hci_disc_comp: Restarting pending ACL request"); - transport = p_lcb->transport; - /* for LE link, always drop and re-open to ensure to get LE remote feature */ - if (p_lcb->transport == BT_TRANSPORT_LE) - { - l2cb.is_ble_connecting = false; - btm_acl_removed (p_lcb->remote_bd_addr, p_lcb->transport); - /* Release any held buffers */ - BT_HDR *p_buf; - while (!list_is_empty(p_lcb->link_xmit_data_q)) - { - p_buf = static_cast(list_front(p_lcb->link_xmit_data_q)); - list_remove(p_lcb->link_xmit_data_q, p_buf); - osi_free(p_buf); - } - } - else - { + /* If waiting for disconnect and reconnect is pending start the reconnect + now + race condition where layer above issued connect request on link that was + disconnecting + */ + if (p_lcb->ccb_queue.p_first_ccb != NULL || p_lcb->p_pending_ccb) { + L2CAP_TRACE_DEBUG( + "l2c_link_hci_disc_comp: Restarting pending ACL request"); + transport = p_lcb->transport; + /* for LE link, always drop and re-open to ensure to get LE remote feature + */ + if (p_lcb->transport == BT_TRANSPORT_LE) { + l2cb.is_ble_connecting = false; + btm_acl_removed(p_lcb->remote_bd_addr, p_lcb->transport); + /* Release any held buffers */ + BT_HDR* p_buf; + while (!list_is_empty(p_lcb->link_xmit_data_q)) { + p_buf = static_cast(list_front(p_lcb->link_xmit_data_q)); + list_remove(p_lcb->link_xmit_data_q, p_buf); + osi_free(p_buf); + } + } else { #if (L2CAP_NUM_FIXED_CHNLS > 0) - /* If we are going to re-use the LCB without dropping it, release all fixed channels - here */ - int xx; - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - if (p_lcb->p_fixed_ccbs[xx] && p_lcb->p_fixed_ccbs[xx] != p_lcb->p_pending_ccb) - { - (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, - p_lcb->remote_bd_addr, false, p_lcb->disc_reason, p_lcb->transport); - if (p_lcb->p_fixed_ccbs[xx] == NULL) { - bdstr_t bd_addr_str = {0}; - L2CAP_TRACE_ERROR("%s: unexpected p_fixed_ccbs[%d] is NULL remote_bd_addr = %s p_lcb = %p in_use = %d link_state = %d handle = %d link_role = %d is_bonding = %d disc_reason = %d transport = %d", - __func__, xx, - bdaddr_to_string((bt_bdaddr_t *)&p_lcb->remote_bd_addr, - bd_addr_str, - sizeof(bd_addr_str)), - p_lcb, p_lcb->in_use, - p_lcb->link_state, p_lcb->handle, - p_lcb->link_role, p_lcb->is_bonding, - p_lcb->disc_reason, p_lcb->transport); - } - assert(p_lcb->p_fixed_ccbs[xx] != NULL); - l2cu_release_ccb (p_lcb->p_fixed_ccbs[xx]); - - p_lcb->p_fixed_ccbs[xx] = NULL; - } + /* If we are going to re-use the LCB without dropping it, release all + fixed channels + here */ + int xx; + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + if (p_lcb->p_fixed_ccbs[xx] && + p_lcb->p_fixed_ccbs[xx] != p_lcb->p_pending_ccb) { + (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)( + xx + L2CAP_FIRST_FIXED_CHNL, p_lcb->remote_bd_addr, false, + p_lcb->disc_reason, p_lcb->transport); + if (p_lcb->p_fixed_ccbs[xx] == NULL) { + bdstr_t bd_addr_str = {0}; + L2CAP_TRACE_ERROR( + "%s: unexpected p_fixed_ccbs[%d] is NULL remote_bd_addr = %s " + "p_lcb = %p in_use = %d link_state = %d handle = %d " + "link_role = %d is_bonding = %d disc_reason = %d transport = " + "%d", + __func__, xx, + bdaddr_to_string((bt_bdaddr_t*)&p_lcb->remote_bd_addr, + bd_addr_str, sizeof(bd_addr_str)), + p_lcb, p_lcb->in_use, p_lcb->link_state, p_lcb->handle, + p_lcb->link_role, p_lcb->is_bonding, p_lcb->disc_reason, + p_lcb->transport); + } + assert(p_lcb->p_fixed_ccbs[xx] != NULL); + l2cu_release_ccb(p_lcb->p_fixed_ccbs[xx]); + + p_lcb->p_fixed_ccbs[xx] = NULL; } -#endif - } - if (l2cu_create_conn(p_lcb, transport)) - lcb_is_free = false; /* still using this lcb */ } +#endif + } + if (l2cu_create_conn(p_lcb, transport)) + lcb_is_free = false; /* still using this lcb */ + } - p_lcb->p_pending_ccb = NULL; + p_lcb->p_pending_ccb = NULL; - /* Release the LCB */ - if (lcb_is_free) - l2cu_release_lcb (p_lcb); - } + /* Release the LCB */ + if (lcb_is_free) l2cu_release_lcb(p_lcb); + } - /* Now that we have a free acl connection, see if any lcbs are pending */ - if (lcb_is_free && ((p_lcb = l2cu_find_lcb_by_state(LST_CONNECT_HOLDING)) != NULL)) - { - /* we found one-- create a connection */ - l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR); - } + /* Now that we have a free acl connection, see if any lcbs are pending */ + if (lcb_is_free && + ((p_lcb = l2cu_find_lcb_by_state(LST_CONNECT_HOLDING)) != NULL)) { + /* we found one-- create a connection */ + l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR); + } - return status; + return status; } - /******************************************************************************* * * Function l2c_link_hci_qos_violation @@ -510,30 +467,25 @@ bool l2c_link_hci_disc_comp (uint16_t handle, uint8_t reason) * Returns true if the link is known about, else false * ******************************************************************************/ -bool l2c_link_hci_qos_violation (uint16_t handle) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; +bool l2c_link_hci_qos_violation(uint16_t handle) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; - /* See if we have a link control block for the connection */ - p_lcb = l2cu_find_lcb_by_handle (handle); + /* See if we have a link control block for the connection */ + p_lcb = l2cu_find_lcb_by_handle(handle); - /* If we don't have one, maybe an SCO link. */ - if (!p_lcb) - return (false); + /* If we don't have one, maybe an SCO link. */ + if (!p_lcb) return (false); - /* For all channels, tell the upper layer about it */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) - l2c_csm_execute (p_ccb, L2CEVT_LP_QOS_VIOLATION_IND, NULL); - } + /* For all channels, tell the upper layer about it */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) { + if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) + l2c_csm_execute(p_ccb, L2CEVT_LP_QOS_VIOLATION_IND, NULL); + } - return (true); + return (true); } - - /******************************************************************************* * * Function l2c_link_timeout @@ -543,123 +495,105 @@ bool l2c_link_hci_qos_violation (uint16_t handle) * Returns void * ******************************************************************************/ -void l2c_link_timeout (tL2C_LCB *p_lcb) -{ - tL2C_CCB *p_ccb; - tBTM_STATUS rc; - - L2CAP_TRACE_EVENT ("L2CAP - l2c_link_timeout() link state %d first CCB %p is_bonding:%d", - p_lcb->link_state, p_lcb->ccb_queue.p_first_ccb, p_lcb->is_bonding); - - /* If link was connecting or disconnecting, clear all channels and drop the LCB */ - if ((p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH) || - (p_lcb->link_state == LST_CONNECTING) || - (p_lcb->link_state == LST_CONNECT_HOLDING) || - (p_lcb->link_state == LST_DISCONNECTING)) - { - p_lcb->p_pending_ccb = NULL; - - /* For all channels, send a disconnect indication event through */ - /* their FSMs. The CCBs should remove themselves from the LCB */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; ) - { - tL2C_CCB *pn = p_ccb->p_next_ccb; - - l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); - - p_ccb = pn; - } - if (p_lcb->link_state == LST_CONNECTING && - l2cb.is_ble_connecting == true) - { - L2CA_CancelBleConnectReq(l2cb.ble_connecting_bda); - } - /* Release the LCB */ - l2cu_release_lcb (p_lcb); +void l2c_link_timeout(tL2C_LCB* p_lcb) { + tL2C_CCB* p_ccb; + tBTM_STATUS rc; + + L2CAP_TRACE_EVENT( + "L2CAP - l2c_link_timeout() link state %d first CCB %p is_bonding:%d", + p_lcb->link_state, p_lcb->ccb_queue.p_first_ccb, p_lcb->is_bonding); + + /* If link was connecting or disconnecting, clear all channels and drop the + * LCB */ + if ((p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH) || + (p_lcb->link_state == LST_CONNECTING) || + (p_lcb->link_state == LST_CONNECT_HOLDING) || + (p_lcb->link_state == LST_DISCONNECTING)) { + p_lcb->p_pending_ccb = NULL; + + /* For all channels, send a disconnect indication event through */ + /* their FSMs. The CCBs should remove themselves from the LCB */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;) { + tL2C_CCB* pn = p_ccb->p_next_ccb; + + l2c_csm_execute(p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); + + p_ccb = pn; } + if (p_lcb->link_state == LST_CONNECTING && l2cb.is_ble_connecting == true) { + L2CA_CancelBleConnectReq(l2cb.ble_connecting_bda); + } + /* Release the LCB */ + l2cu_release_lcb(p_lcb); + } - /* If link is connected, check for inactivity timeout */ - if (p_lcb->link_state == LST_CONNECTED) - { - /* Check for ping outstanding */ - if (p_lcb->p_echo_rsp_cb) - { - tL2CA_ECHO_RSP_CB *p_cb = p_lcb->p_echo_rsp_cb; - - /* Zero out the callback in case app immediately calls us again */ - p_lcb->p_echo_rsp_cb = NULL; + /* If link is connected, check for inactivity timeout */ + if (p_lcb->link_state == LST_CONNECTED) { + /* Check for ping outstanding */ + if (p_lcb->p_echo_rsp_cb) { + tL2CA_ECHO_RSP_CB* p_cb = p_lcb->p_echo_rsp_cb; - (*p_cb) (L2CAP_PING_RESULT_NO_RESP); + /* Zero out the callback in case app immediately calls us again */ + p_lcb->p_echo_rsp_cb = NULL; - L2CAP_TRACE_WARNING ("L2CAP - ping timeout"); + (*p_cb)(L2CAP_PING_RESULT_NO_RESP); - /* For all channels, send a disconnect indication event through */ - /* their FSMs. The CCBs should remove themselves from the LCB */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; ) - { - tL2C_CCB *pn = p_ccb->p_next_ccb; + L2CAP_TRACE_WARNING("L2CAP - ping timeout"); - l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); + /* For all channels, send a disconnect indication event through */ + /* their FSMs. The CCBs should remove themselves from the LCB */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;) { + tL2C_CCB* pn = p_ccb->p_next_ccb; - p_ccb = pn; - } - } + l2c_csm_execute(p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); - /* If no channels in use, drop the link. */ - if (!p_lcb->ccb_queue.p_first_ccb) - { - period_ms_t timeout_ms; - bool start_timeout = true; + p_ccb = pn; + } + } - rc = btm_sec_disconnect (p_lcb->handle, HCI_ERR_PEER_USER); + /* If no channels in use, drop the link. */ + if (!p_lcb->ccb_queue.p_first_ccb) { + period_ms_t timeout_ms; + bool start_timeout = true; - if (rc == BTM_CMD_STORED) - { - /* Security Manager will take care of disconnecting, state will be updated at that time */ - start_timeout = false; - } - else if (rc == BTM_CMD_STARTED) - { - p_lcb->link_state = LST_DISCONNECTING; - timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; - } - else if (rc == BTM_SUCCESS) - { - l2cu_process_fixed_disc_cback(p_lcb); - /* BTM SEC will make sure that link is release (probably after pairing is done) */ - p_lcb->link_state = LST_DISCONNECTING; - start_timeout = false; - } - else if (rc == BTM_BUSY) - { - /* BTM is still executing security process. Let lcb stay as connected */ - start_timeout = false; - } - else if (p_lcb->is_bonding) - { - btsnd_hcic_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); - l2cu_process_fixed_disc_cback(p_lcb); - p_lcb->link_state = LST_DISCONNECTING; - timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; - } - else - { - /* probably no buffer to send disconnect */ - timeout_ms = BT_1SEC_TIMEOUT_MS; - } + rc = btm_sec_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); - if (start_timeout) { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } - } - else - { - /* Check in case we were flow controlled */ - l2c_link_check_send_pkts (p_lcb, NULL, NULL); - } + if (rc == BTM_CMD_STORED) { + /* Security Manager will take care of disconnecting, state will be + * updated at that time */ + start_timeout = false; + } else if (rc == BTM_CMD_STARTED) { + p_lcb->link_state = LST_DISCONNECTING; + timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; + } else if (rc == BTM_SUCCESS) { + l2cu_process_fixed_disc_cback(p_lcb); + /* BTM SEC will make sure that link is release (probably after pairing + * is done) */ + p_lcb->link_state = LST_DISCONNECTING; + start_timeout = false; + } else if (rc == BTM_BUSY) { + /* BTM is still executing security process. Let lcb stay as connected */ + start_timeout = false; + } else if (p_lcb->is_bonding) { + btsnd_hcic_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); + l2cu_process_fixed_disc_cback(p_lcb); + p_lcb->link_state = LST_DISCONNECTING; + timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; + } else { + /* probably no buffer to send disconnect */ + timeout_ms = BT_1SEC_TIMEOUT_MS; + } + + if (start_timeout) { + alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, + l2c_lcb_timer_timeout, p_lcb, + btu_general_alarm_queue); + } + } else { + /* Check in case we were flow controlled */ + l2c_link_check_send_pkts(p_lcb, NULL, NULL); } + } } /******************************************************************************* @@ -671,47 +605,43 @@ void l2c_link_timeout (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2c_info_resp_timer_timeout(void *data) -{ - tL2C_LCB *p_lcb = (tL2C_LCB *)data; - tL2C_CCB *p_ccb; - tL2C_CONN_INFO ci; - - /* If we timed out waiting for info response, just continue using basic if allowed */ - if (p_lcb->w4_info_rsp) - { - /* If waiting for security complete, restart the info response timer */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - if ( (p_ccb->chnl_state == CST_ORIG_W4_SEC_COMP) || (p_ccb->chnl_state == CST_TERM_W4_SEC_COMP) ) - { - alarm_set_on_queue(p_lcb->info_resp_timer, - L2CAP_WAIT_INFO_RSP_TIMEOUT_MS, - l2c_info_resp_timer_timeout, p_lcb, - btu_general_alarm_queue); - return; - } - } +void l2c_info_resp_timer_timeout(void* data) { + tL2C_LCB* p_lcb = (tL2C_LCB*)data; + tL2C_CCB* p_ccb; + tL2C_CONN_INFO ci; + + /* If we timed out waiting for info response, just continue using basic if + * allowed */ + if (p_lcb->w4_info_rsp) { + /* If waiting for security complete, restart the info response timer */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + if ((p_ccb->chnl_state == CST_ORIG_W4_SEC_COMP) || + (p_ccb->chnl_state == CST_TERM_W4_SEC_COMP)) { + alarm_set_on_queue( + p_lcb->info_resp_timer, L2CAP_WAIT_INFO_RSP_TIMEOUT_MS, + l2c_info_resp_timer_timeout, p_lcb, btu_general_alarm_queue); + return; + } + } - p_lcb->w4_info_rsp = false; - - /* If link is in process of being brought up */ - if ((p_lcb->link_state != LST_DISCONNECTED) && - (p_lcb->link_state != LST_DISCONNECTING)) - { - /* Notify active channels that peer info is finished */ - if (p_lcb->ccb_queue.p_first_ccb) - { - ci.status = HCI_SUCCESS; - memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); - - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); - } - } + p_lcb->w4_info_rsp = false; + + /* If link is in process of being brought up */ + if ((p_lcb->link_state != LST_DISCONNECTED) && + (p_lcb->link_state != LST_DISCONNECTING)) { + /* Notify active channels that peer info is finished */ + if (p_lcb->ccb_queue.p_first_ccb) { + ci.status = HCI_SUCCESS; + memcpy(ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); + + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); } + } } + } } /******************************************************************************* @@ -729,117 +659,109 @@ void l2c_info_resp_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void l2c_link_adjust_allocation (void) -{ - uint16_t qq, yy, qq_remainder; - tL2C_LCB *p_lcb; - uint16_t hi_quota, low_quota; - uint16_t num_lowpri_links = 0; - uint16_t num_hipri_links = 0; - uint16_t controller_xmit_quota = l2cb.num_lm_acl_bufs; - uint16_t high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A; - - /* If no links active, reset buffer quotas and controller buffers */ - if (l2cb.num_links_active == 0) - { - l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs; - l2cb.round_robin_quota = l2cb.round_robin_unacked = 0; - return; +void l2c_link_adjust_allocation(void) { + uint16_t qq, yy, qq_remainder; + tL2C_LCB* p_lcb; + uint16_t hi_quota, low_quota; + uint16_t num_lowpri_links = 0; + uint16_t num_hipri_links = 0; + uint16_t controller_xmit_quota = l2cb.num_lm_acl_bufs; + uint16_t high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A; + + /* If no links active, reset buffer quotas and controller buffers */ + if (l2cb.num_links_active == 0) { + l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs; + l2cb.round_robin_quota = l2cb.round_robin_unacked = 0; + return; + } + + /* First, count the links */ + for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) { + if (p_lcb->in_use) { + if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) + num_hipri_links++; + else + num_lowpri_links++; } - - /* First, count the links */ - for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) - { - if (p_lcb->in_use) - { - if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - num_hipri_links++; - else - num_lowpri_links++; - } - } - - /* now adjust high priority link quota */ - low_quota = num_lowpri_links ? 1 : 0; - while ( (num_hipri_links * high_pri_link_quota + low_quota) > controller_xmit_quota ) - high_pri_link_quota--; - - /* Work out the xmit quota and buffer quota high and low priorities */ - hi_quota = num_hipri_links * high_pri_link_quota; - low_quota = (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1; - - /* Work out and save the HCI xmit quota for each low priority link */ - - /* If each low priority link cannot have at least one buffer */ - if (num_lowpri_links > low_quota) - { - l2cb.round_robin_quota = low_quota; - qq = qq_remainder = 1; - } - /* If each low priority link can have at least one buffer */ - else if (num_lowpri_links > 0) - { - l2cb.round_robin_quota = 0; - l2cb.round_robin_unacked = 0; - qq = low_quota / num_lowpri_links; - qq_remainder = low_quota % num_lowpri_links; - } - /* If no low priority link */ - else - { - l2cb.round_robin_quota = 0; - l2cb.round_robin_unacked = 0; - qq = qq_remainder = 1; - } - - L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u", - num_hipri_links, num_lowpri_links, low_quota, - l2cb.round_robin_quota, qq); - - /* Now, assign the quotas to each link */ - for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) - { - if (p_lcb->in_use) - { - if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - { - p_lcb->link_xmit_quota = high_pri_link_quota; - } - else - { - /* Safety check in case we switched to round-robin with something outstanding */ - /* if sent_not_acked is added into round_robin_unacked then don't add it again */ - /* l2cap keeps updating sent_not_acked for exiting from round robin */ - if (( p_lcb->link_xmit_quota > 0 )&&( qq == 0 )) - l2cb.round_robin_unacked += p_lcb->sent_not_acked; - - p_lcb->link_xmit_quota = qq; - if (qq_remainder > 0) - { - p_lcb->link_xmit_quota++; - qq_remainder--; - } - } - - L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", - yy, p_lcb->acl_priority, p_lcb->link_xmit_quota); - - L2CAP_TRACE_EVENT (" SentNotAcked: %d RRUnacked: %d", - p_lcb->sent_not_acked, l2cb.round_robin_unacked); - - /* There is a special case where we have readjusted the link quotas and */ - /* this link may have sent anything but some other link sent packets so */ - /* so we may need a timer to kick off this link's transmissions. */ - if ( (p_lcb->link_state == LST_CONNECTED) - && (!list_is_empty(p_lcb->link_xmit_data_q)) - && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } + } + + /* now adjust high priority link quota */ + low_quota = num_lowpri_links ? 1 : 0; + while ((num_hipri_links * high_pri_link_quota + low_quota) > + controller_xmit_quota) + high_pri_link_quota--; + + /* Work out the xmit quota and buffer quota high and low priorities */ + hi_quota = num_hipri_links * high_pri_link_quota; + low_quota = + (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1; + + /* Work out and save the HCI xmit quota for each low priority link */ + + /* If each low priority link cannot have at least one buffer */ + if (num_lowpri_links > low_quota) { + l2cb.round_robin_quota = low_quota; + qq = qq_remainder = 1; + } + /* If each low priority link can have at least one buffer */ + else if (num_lowpri_links > 0) { + l2cb.round_robin_quota = 0; + l2cb.round_robin_unacked = 0; + qq = low_quota / num_lowpri_links; + qq_remainder = low_quota % num_lowpri_links; + } + /* If no low priority link */ + else { + l2cb.round_robin_quota = 0; + l2cb.round_robin_unacked = 0; + qq = qq_remainder = 1; + } + + L2CAP_TRACE_EVENT( + "l2c_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: " + "%u round_robin_quota: %u qq: %u", + num_hipri_links, num_lowpri_links, low_quota, l2cb.round_robin_quota, qq); + + /* Now, assign the quotas to each link */ + for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) { + if (p_lcb->in_use) { + if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) { + p_lcb->link_xmit_quota = high_pri_link_quota; + } else { + /* Safety check in case we switched to round-robin with something + * outstanding */ + /* if sent_not_acked is added into round_robin_unacked then don't add it + * again */ + /* l2cap keeps updating sent_not_acked for exiting from round robin */ + if ((p_lcb->link_xmit_quota > 0) && (qq == 0)) + l2cb.round_robin_unacked += p_lcb->sent_not_acked; + + p_lcb->link_xmit_quota = qq; + if (qq_remainder > 0) { + p_lcb->link_xmit_quota++; + qq_remainder--; } + } + + L2CAP_TRACE_EVENT( + "l2c_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", yy, + p_lcb->acl_priority, p_lcb->link_xmit_quota); + + L2CAP_TRACE_EVENT(" SentNotAcked: %d RRUnacked: %d", + p_lcb->sent_not_acked, l2cb.round_robin_unacked); + + /* There is a special case where we have readjusted the link quotas and */ + /* this link may have sent anything but some other link sent packets so */ + /* so we may need a timer to kick off this link's transmissions. */ + if ((p_lcb->link_state == LST_CONNECTED) && + (!list_is_empty(p_lcb->link_xmit_data_q)) && + (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) { + alarm_set_on_queue( + p_lcb->l2c_lcb_timer, L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } } + } } /******************************************************************************* @@ -856,30 +778,28 @@ void l2c_link_adjust_allocation (void) * Returns void * ******************************************************************************/ -void l2c_link_adjust_chnl_allocation (void) -{ - uint8_t xx; +void l2c_link_adjust_chnl_allocation(void) { + uint8_t xx; - L2CAP_TRACE_DEBUG("%s", __func__); + L2CAP_TRACE_DEBUG("%s", __func__); - /* assign buffer quota to each channel based on its data rate requirement */ - for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) - { - tL2C_CCB *p_ccb = l2cb.ccb_pool + xx; + /* assign buffer quota to each channel based on its data rate requirement */ + for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) { + tL2C_CCB* p_ccb = l2cb.ccb_pool + xx; - if (!p_ccb->in_use) - continue; + if (!p_ccb->in_use) continue; - tL2CAP_CHNL_DATA_RATE data_rate = p_ccb->tx_data_rate + p_ccb->rx_data_rate; - p_ccb->buff_quota = L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA * data_rate; - L2CAP_TRACE_EVENT("CID:0x%04x FCR Mode:%u Priority:%u TxDataRate:%u RxDataRate:%u Quota:%u", - p_ccb->local_cid, p_ccb->peer_cfg.fcr.mode, - p_ccb->ccb_priority, p_ccb->tx_data_rate, - p_ccb->rx_data_rate, p_ccb->buff_quota); + tL2CAP_CHNL_DATA_RATE data_rate = p_ccb->tx_data_rate + p_ccb->rx_data_rate; + p_ccb->buff_quota = L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA * data_rate; + L2CAP_TRACE_EVENT( + "CID:0x%04x FCR Mode:%u Priority:%u TxDataRate:%u RxDataRate:%u " + "Quota:%u", + p_ccb->local_cid, p_ccb->peer_cfg.fcr.mode, p_ccb->ccb_priority, + p_ccb->tx_data_rate, p_ccb->rx_data_rate, p_ccb->buff_quota); - /* quota may be change so check congestion */ - l2cu_check_channel_congestion(p_ccb); - } + /* quota may be change so check congestion */ + l2cu_check_channel_congestion(p_ccb); + } } /******************************************************************************* @@ -893,10 +813,8 @@ void l2c_link_adjust_chnl_allocation (void) * Returns void * ******************************************************************************/ -void l2c_link_processs_num_bufs (uint16_t num_lm_acl_bufs) -{ - l2cb.num_lm_acl_bufs = l2cb.controller_xmit_window = num_lm_acl_bufs; - +void l2c_link_processs_num_bufs(uint16_t num_lm_acl_bufs) { + l2cb.num_lm_acl_bufs = l2cb.controller_xmit_window = num_lm_acl_bufs; } /******************************************************************************* @@ -911,12 +829,11 @@ void l2c_link_processs_num_bufs (uint16_t num_lm_acl_bufs) * Returns count of number of entries filled in * ******************************************************************************/ -uint8_t l2c_link_pkts_rcvd (UNUSED_ATTR uint16_t *num_pkts, - UNUSED_ATTR uint16_t *handles) -{ - uint8_t num_found = 0; +uint8_t l2c_link_pkts_rcvd(UNUSED_ATTR uint16_t* num_pkts, + UNUSED_ATTR uint16_t* handles) { + uint8_t num_found = 0; - return (num_found); + return (num_found); } /******************************************************************************* @@ -930,34 +847,31 @@ uint8_t l2c_link_pkts_rcvd (UNUSED_ATTR uint16_t *num_pkts, * Returns void * ******************************************************************************/ -void l2c_link_role_changed (BD_ADDR bd_addr, uint8_t new_role, uint8_t hci_status) -{ - tL2C_LCB *p_lcb; - int xx; - - /* Make sure not called from HCI Command Status (bd_addr and new_role are invalid) */ - if (bd_addr) - { - /* If here came form hci role change event */ - p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb) - { - p_lcb->link_role = new_role; - - /* Reset high priority link if needed */ - if (hci_status == HCI_SUCCESS) - l2cu_set_acl_priority(bd_addr, p_lcb->acl_priority, true); - } +void l2c_link_role_changed(BD_ADDR bd_addr, uint8_t new_role, + uint8_t hci_status) { + tL2C_LCB* p_lcb; + int xx; + + /* Make sure not called from HCI Command Status (bd_addr and new_role are + * invalid) */ + if (bd_addr) { + /* If here came form hci role change event */ + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb) { + p_lcb->link_role = new_role; + + /* Reset high priority link if needed */ + if (hci_status == HCI_SUCCESS) + l2cu_set_acl_priority(bd_addr, p_lcb->acl_priority, true); } + } - /* Check if any LCB was waiting for switch to be completed */ - for (xx = 0, p_lcb = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH)) - { - l2cu_create_conn_after_switch (p_lcb); - } + /* Check if any LCB was waiting for switch to be completed */ + for (xx = 0, p_lcb = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH)) { + l2cu_create_conn_after_switch(p_lcb); } + } } /******************************************************************************* @@ -973,17 +887,13 @@ void l2c_link_role_changed (BD_ADDR bd_addr, uint8_t new_role, uint8_t hci_statu * Returns void * ******************************************************************************/ -void l2c_pin_code_request (BD_ADDR bd_addr) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR); +void l2c_pin_code_request(BD_ADDR bd_addr) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); - if ( (p_lcb) && (!p_lcb->ccb_queue.p_first_ccb) ) - { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } + if ((p_lcb) && (!p_lcb->ccb_queue.p_first_ccb)) { + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + } } #if (L2CAP_WAKE_PARKED_LINK == TRUE) @@ -997,44 +907,37 @@ void l2c_pin_code_request (BD_ADDR bd_addr) * false if nothing to send or not in park mode * ******************************************************************************/ -bool l2c_link_check_power_mode (tL2C_LCB *p_lcb) -{ - tBTM_PM_MODE mode; - tL2C_CCB *p_ccb; - bool need_to_active = false; - - /* - * We only switch park to active only if we have unsent packets - */ - if (list_is_empty(p_lcb->link_xmit_data_q)) - { - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) - { - need_to_active = true; - break; - } - } - } - else +bool l2c_link_check_power_mode(tL2C_LCB* p_lcb) { + tBTM_PM_MODE mode; + tL2C_CCB* p_ccb; + bool need_to_active = false; + + /* + * We only switch park to active only if we have unsent packets + */ + if (list_is_empty(p_lcb->link_xmit_data_q)) { + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) { need_to_active = true; - - /* if we have packets to send */ - if ( need_to_active ) - { - /* check power mode */ - if (BTM_ReadPowerMode(p_lcb->remote_bd_addr, &mode) == BTM_SUCCESS) - { - if ( mode == BTM_PM_STS_PENDING ) - { - L2CAP_TRACE_DEBUG ("LCB(0x%x) is in PM pending state", p_lcb->handle); - - return true; - } - } + break; + } + } + } else + need_to_active = true; + + /* if we have packets to send */ + if (need_to_active) { + /* check power mode */ + if (BTM_ReadPowerMode(p_lcb->remote_bd_addr, &mode) == BTM_SUCCESS) { + if (mode == BTM_PM_STS_PENDING) { + L2CAP_TRACE_DEBUG("LCB(0x%x) is in PM pending state", p_lcb->handle); + + return true; + } } - return false; + } + return false; } #endif /* L2CAP_WAKE_PARKED_LINK == TRUE) */ @@ -1049,155 +952,136 @@ bool l2c_link_check_power_mode (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf) -{ - int xx; - bool single_write = false; - - /* Save the channel ID for faster counting */ - if (p_buf) - { - if (p_ccb != NULL) - { - p_buf->event = p_ccb->local_cid; - single_write = true; - } - else - p_buf->event = 0; - - p_buf->layer_specific = 0; - list_append(p_lcb->link_xmit_data_q, p_buf); - - if (p_lcb->link_xmit_quota == 0) - { - if (p_lcb->transport == BT_TRANSPORT_LE) - l2cb.ble_check_round_robin = true; - else - l2cb.check_round_robin = true; - } +void l2c_link_check_send_pkts(tL2C_LCB* p_lcb, tL2C_CCB* p_ccb, BT_HDR* p_buf) { + int xx; + bool single_write = false; + + /* Save the channel ID for faster counting */ + if (p_buf) { + if (p_ccb != NULL) { + p_buf->event = p_ccb->local_cid; + single_write = true; + } else + p_buf->event = 0; + + p_buf->layer_specific = 0; + list_append(p_lcb->link_xmit_data_q, p_buf); + + if (p_lcb->link_xmit_quota == 0) { + if (p_lcb->transport == BT_TRANSPORT_LE) + l2cb.ble_check_round_robin = true; + else + l2cb.check_round_robin = true; } - - /* If this is called from uncongested callback context break recursive calling. - ** This LCB will be served when receiving number of completed packet event. - */ - if (l2cb.is_cong_cback_context) - return; - - /* If we are in a scenario where there are not enough buffers for each link to - ** have at least 1, then do a round-robin for all the LCBs - */ - if ( (p_lcb == NULL) || (p_lcb->link_xmit_quota == 0) ) - { - if (p_lcb == NULL) - p_lcb = l2cb.lcb_pool; - else if (!single_write) - p_lcb++; - - /* Loop through, starting at the next */ - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - /* If controller window is full, nothing to do */ - if (((l2cb.controller_xmit_window == 0 || - (l2cb.round_robin_unacked >= l2cb.round_robin_quota)) - && (p_lcb->transport == BT_TRANSPORT_BR_EDR) - ) - || (p_lcb->transport == BT_TRANSPORT_LE && - (l2cb.ble_round_robin_unacked >= l2cb.ble_round_robin_quota || - l2cb.controller_le_xmit_window == 0 ))) - break; - - - /* Check for wraparound */ - if (p_lcb == &l2cb.lcb_pool[MAX_L2CAP_LINKS]) - p_lcb = &l2cb.lcb_pool[0]; - - if ( (!p_lcb->in_use) - || (p_lcb->partial_segment_being_sent) - || (p_lcb->link_state != LST_CONNECTED) - || (p_lcb->link_xmit_quota != 0) - || (L2C_LINK_CHECK_POWER_MODE (p_lcb)) ) - continue; - - /* See if we can send anything from the Link Queue */ - if (!list_is_empty(p_lcb->link_xmit_data_q)) { - p_buf = (BT_HDR *)list_front(p_lcb->link_xmit_data_q); - list_remove(p_lcb->link_xmit_data_q, p_buf); - l2c_link_send_to_lower (p_lcb, p_buf); - } - else if (single_write) - { - /* If only doing one write, break out */ - break; - } - /* If nothing on the link queue, check the channel queue */ - else { - p_buf = l2cu_get_next_buffer_to_send(p_lcb); - if (p_buf != NULL) - { - l2c_link_send_to_lower (p_lcb, p_buf); - } - } + } + + /* If this is called from uncongested callback context break recursive + *calling. + ** This LCB will be served when receiving number of completed packet event. + */ + if (l2cb.is_cong_cback_context) return; + + /* If we are in a scenario where there are not enough buffers for each link to + ** have at least 1, then do a round-robin for all the LCBs + */ + if ((p_lcb == NULL) || (p_lcb->link_xmit_quota == 0)) { + if (p_lcb == NULL) + p_lcb = l2cb.lcb_pool; + else if (!single_write) + p_lcb++; + + /* Loop through, starting at the next */ + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + /* If controller window is full, nothing to do */ + if (((l2cb.controller_xmit_window == 0 || + (l2cb.round_robin_unacked >= l2cb.round_robin_quota)) && + (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || + (p_lcb->transport == BT_TRANSPORT_LE && + (l2cb.ble_round_robin_unacked >= l2cb.ble_round_robin_quota || + l2cb.controller_le_xmit_window == 0))) + break; + + /* Check for wraparound */ + if (p_lcb == &l2cb.lcb_pool[MAX_L2CAP_LINKS]) p_lcb = &l2cb.lcb_pool[0]; + + if ((!p_lcb->in_use) || (p_lcb->partial_segment_being_sent) || + (p_lcb->link_state != LST_CONNECTED) || + (p_lcb->link_xmit_quota != 0) || (L2C_LINK_CHECK_POWER_MODE(p_lcb))) + continue; + + /* See if we can send anything from the Link Queue */ + if (!list_is_empty(p_lcb->link_xmit_data_q)) { + p_buf = (BT_HDR*)list_front(p_lcb->link_xmit_data_q); + list_remove(p_lcb->link_xmit_data_q, p_buf); + l2c_link_send_to_lower(p_lcb, p_buf); + } else if (single_write) { + /* If only doing one write, break out */ + break; + } + /* If nothing on the link queue, check the channel queue */ + else { + p_buf = l2cu_get_next_buffer_to_send(p_lcb); + if (p_buf != NULL) { + l2c_link_send_to_lower(p_lcb, p_buf); } + } + } - /* If we finished without using up our quota, no need for a safety check */ - if ((l2cb.controller_xmit_window > 0) && - (l2cb.round_robin_unacked < l2cb.round_robin_quota) && - (p_lcb->transport == BT_TRANSPORT_BR_EDR)) - l2cb.check_round_robin = false; - - if ((l2cb.controller_le_xmit_window > 0) && - (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota) && - (p_lcb->transport == BT_TRANSPORT_LE)) - l2cb.ble_check_round_robin = false; + /* If we finished without using up our quota, no need for a safety check */ + if ((l2cb.controller_xmit_window > 0) && + (l2cb.round_robin_unacked < l2cb.round_robin_quota) && + (p_lcb->transport == BT_TRANSPORT_BR_EDR)) + l2cb.check_round_robin = false; + + if ((l2cb.controller_le_xmit_window > 0) && + (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota) && + (p_lcb->transport == BT_TRANSPORT_LE)) + l2cb.ble_check_round_robin = false; + } else /* if this is not round-robin service */ + { + /* If a partial segment is being sent, can't send anything else */ + if ((p_lcb->partial_segment_being_sent) || + (p_lcb->link_state != LST_CONNECTED) || + (L2C_LINK_CHECK_POWER_MODE(p_lcb))) + return; + + /* See if we can send anything from the link queue */ + while (((l2cb.controller_xmit_window != 0 && + (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || + (l2cb.controller_le_xmit_window != 0 && + (p_lcb->transport == BT_TRANSPORT_LE))) && + (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) { + if (list_is_empty(p_lcb->link_xmit_data_q)) break; + + p_buf = (BT_HDR*)list_front(p_lcb->link_xmit_data_q); + list_remove(p_lcb->link_xmit_data_q, p_buf); + if (!l2c_link_send_to_lower(p_lcb, p_buf)) break; } - else /* if this is not round-robin service */ - { - /* If a partial segment is being sent, can't send anything else */ - if ( (p_lcb->partial_segment_being_sent) - || (p_lcb->link_state != LST_CONNECTED) - || (L2C_LINK_CHECK_POWER_MODE (p_lcb)) ) - return; - - /* See if we can send anything from the link queue */ - while ( ((l2cb.controller_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || - (l2cb.controller_le_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_LE))) - && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) - { - if (list_is_empty(p_lcb->link_xmit_data_q)) - break; - - p_buf = (BT_HDR *)list_front(p_lcb->link_xmit_data_q); - list_remove(p_lcb->link_xmit_data_q, p_buf); - if (!l2c_link_send_to_lower (p_lcb, p_buf)) - break; - } - if (!single_write) - { - /* See if we can send anything for any channel */ - while ( ((l2cb.controller_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || - (l2cb.controller_le_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_LE))) - && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) - { - p_buf = l2cu_get_next_buffer_to_send(p_lcb); - if (p_buf == NULL) - break; - - if (!l2c_link_send_to_lower (p_lcb, p_buf)) - break; - } - } + if (!single_write) { + /* See if we can send anything for any channel */ + while (((l2cb.controller_xmit_window != 0 && + (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || + (l2cb.controller_le_xmit_window != 0 && + (p_lcb->transport == BT_TRANSPORT_LE))) && + (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) { + p_buf = l2cu_get_next_buffer_to_send(p_lcb); + if (p_buf == NULL) break; + + if (!l2c_link_send_to_lower(p_lcb, p_buf)) break; + } + } - /* There is a special case where we have readjusted the link quotas and */ - /* this link may have sent anything but some other link sent packets so */ - /* so we may need a timer to kick off this link's transmissions. */ - if ( (!list_is_empty(p_lcb->link_xmit_data_q)) && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - } + /* There is a special case where we have readjusted the link quotas and */ + /* this link may have sent anything but some other link sent packets so */ + /* so we may need a timer to kick off this link's transmissions. */ + if ((!list_is_empty(p_lcb->link_xmit_data_q)) && + (p_lcb->sent_not_acked < p_lcb->link_xmit_quota)) { + alarm_set_on_queue(p_lcb->l2c_lcb_timer, + L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); } + } } /******************************************************************************* @@ -1209,121 +1093,97 @@ void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf) * Returns true for success, false for fail * ******************************************************************************/ -static bool l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf) -{ - uint16_t num_segs; - uint16_t xmit_window, acl_data_size; - const controller_t *controller = controller_get_interface(); - - if ((p_buf->len <= controller->get_acl_packet_size_classic() - && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || - ((p_lcb->transport == BT_TRANSPORT_LE) && (p_buf->len <= controller->get_acl_packet_size_ble()))) - { - if (p_lcb->link_xmit_quota == 0) - { - if (p_lcb->transport == BT_TRANSPORT_LE) - l2cb.ble_round_robin_unacked++; - else - l2cb.round_robin_unacked++; - } - p_lcb->sent_not_acked++; - p_buf->layer_specific = 0; - - if (p_lcb->transport == BT_TRANSPORT_LE) - { - l2cb.controller_le_xmit_window--; - bte_main_hci_send(p_buf, (uint16_t)(BT_EVT_TO_LM_HCI_ACL|LOCAL_BLE_CONTROLLER_ID)); - } - else - { - l2cb.controller_xmit_window--; - bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL); - } +static bool l2c_link_send_to_lower(tL2C_LCB* p_lcb, BT_HDR* p_buf) { + uint16_t num_segs; + uint16_t xmit_window, acl_data_size; + const controller_t* controller = controller_get_interface(); + + if ((p_buf->len <= controller->get_acl_packet_size_classic() && + (p_lcb->transport == BT_TRANSPORT_BR_EDR)) || + ((p_lcb->transport == BT_TRANSPORT_LE) && + (p_buf->len <= controller->get_acl_packet_size_ble()))) { + if (p_lcb->link_xmit_quota == 0) { + if (p_lcb->transport == BT_TRANSPORT_LE) + l2cb.ble_round_robin_unacked++; + else + l2cb.round_robin_unacked++; + } + p_lcb->sent_not_acked++; + p_buf->layer_specific = 0; + + if (p_lcb->transport == BT_TRANSPORT_LE) { + l2cb.controller_le_xmit_window--; + bte_main_hci_send( + p_buf, (uint16_t)(BT_EVT_TO_LM_HCI_ACL | LOCAL_BLE_CONTROLLER_ID)); + } else { + l2cb.controller_xmit_window--; + bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL); + } + } else { + if (p_lcb->transport == BT_TRANSPORT_LE) { + acl_data_size = controller->get_acl_data_size_ble(); + xmit_window = l2cb.controller_le_xmit_window; + + } else { + acl_data_size = controller->get_acl_data_size_classic(); + xmit_window = l2cb.controller_xmit_window; + } + num_segs = (p_buf->len - HCI_DATA_PREAMBLE_SIZE + acl_data_size - 1) / + acl_data_size; + + /* If doing round-robin, then only 1 segment each time */ + if (p_lcb->link_xmit_quota == 0) { + num_segs = 1; + p_lcb->partial_segment_being_sent = true; + } else { + /* Multi-segment packet. Make sure it can fit */ + if (num_segs > xmit_window) { + num_segs = xmit_window; + p_lcb->partial_segment_being_sent = true; + } + + if (num_segs > (p_lcb->link_xmit_quota - p_lcb->sent_not_acked)) { + num_segs = (p_lcb->link_xmit_quota - p_lcb->sent_not_acked); + p_lcb->partial_segment_being_sent = true; + } } - else - { - if (p_lcb->transport == BT_TRANSPORT_LE) - { - acl_data_size = controller->get_acl_data_size_ble(); - xmit_window = l2cb.controller_le_xmit_window; - - } - else - { - acl_data_size = controller->get_acl_data_size_classic(); - xmit_window = l2cb.controller_xmit_window; - } - num_segs = (p_buf->len - HCI_DATA_PREAMBLE_SIZE + acl_data_size - 1) / acl_data_size; - - - /* If doing round-robin, then only 1 segment each time */ - if (p_lcb->link_xmit_quota == 0) - { - num_segs = 1; - p_lcb->partial_segment_being_sent = true; - } - else - { - /* Multi-segment packet. Make sure it can fit */ - if (num_segs > xmit_window) - { - num_segs = xmit_window; - p_lcb->partial_segment_being_sent = true; - } - - if (num_segs > (p_lcb->link_xmit_quota - p_lcb->sent_not_acked)) - { - num_segs = (p_lcb->link_xmit_quota - p_lcb->sent_not_acked); - p_lcb->partial_segment_being_sent = true; - } - } - p_buf->layer_specific = num_segs; - if (p_lcb->transport == BT_TRANSPORT_LE) - { - l2cb.controller_le_xmit_window -= num_segs; - if (p_lcb->link_xmit_quota == 0) - l2cb.ble_round_robin_unacked += num_segs; - } - else - { - l2cb.controller_xmit_window -= num_segs; + p_buf->layer_specific = num_segs; + if (p_lcb->transport == BT_TRANSPORT_LE) { + l2cb.controller_le_xmit_window -= num_segs; + if (p_lcb->link_xmit_quota == 0) l2cb.ble_round_robin_unacked += num_segs; + } else { + l2cb.controller_xmit_window -= num_segs; - if (p_lcb->link_xmit_quota == 0) - l2cb.round_robin_unacked += num_segs; - } + if (p_lcb->link_xmit_quota == 0) l2cb.round_robin_unacked += num_segs; + } - p_lcb->sent_not_acked += num_segs; - if (p_lcb->transport == BT_TRANSPORT_LE) - { - bte_main_hci_send(p_buf, (uint16_t)(BT_EVT_TO_LM_HCI_ACL|LOCAL_BLE_CONTROLLER_ID)); - } - else - { - bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL); - } + p_lcb->sent_not_acked += num_segs; + if (p_lcb->transport == BT_TRANSPORT_LE) { + bte_main_hci_send( + p_buf, (uint16_t)(BT_EVT_TO_LM_HCI_ACL | LOCAL_BLE_CONTROLLER_ID)); + } else { + bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL); } + } #if (L2CAP_HCI_FLOW_CONTROL_DEBUG == TRUE) - if (p_lcb->transport == BT_TRANSPORT_LE) - { - L2CAP_TRACE_DEBUG ("TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d", - l2cb.controller_le_xmit_window, - p_lcb->handle, - p_lcb->link_xmit_quota, p_lcb->sent_not_acked, - l2cb.ble_round_robin_quota, l2cb.ble_round_robin_unacked); - } - else - { - L2CAP_TRACE_DEBUG ("TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d", - l2cb.controller_xmit_window, - p_lcb->handle, - p_lcb->link_xmit_quota, p_lcb->sent_not_acked, - l2cb.round_robin_quota, l2cb.round_robin_unacked); - } + if (p_lcb->transport == BT_TRANSPORT_LE) { + L2CAP_TRACE_DEBUG( + "TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d", + l2cb.controller_le_xmit_window, p_lcb->handle, p_lcb->link_xmit_quota, + p_lcb->sent_not_acked, l2cb.ble_round_robin_quota, + l2cb.ble_round_robin_unacked); + } else { + L2CAP_TRACE_DEBUG( + "TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d", + l2cb.controller_xmit_window, p_lcb->handle, p_lcb->link_xmit_quota, + p_lcb->sent_not_acked, l2cb.round_robin_quota, + l2cb.round_robin_unacked); + } #endif - return true; + return true; } /******************************************************************************* @@ -1337,117 +1197,99 @@ static bool l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -void l2c_link_process_num_completed_pkts (uint8_t *p) -{ - uint8_t num_handles, xx; - uint16_t handle; - uint16_t num_sent; - tL2C_LCB *p_lcb; - - STREAM_TO_UINT8 (num_handles, p); - - for (xx = 0; xx < num_handles; xx++) - { - STREAM_TO_UINT16 (handle, p); - STREAM_TO_UINT16 (num_sent, p); +void l2c_link_process_num_completed_pkts(uint8_t* p) { + uint8_t num_handles, xx; + uint16_t handle; + uint16_t num_sent; + tL2C_LCB* p_lcb; - p_lcb = l2cu_find_lcb_by_handle (handle); + STREAM_TO_UINT8(num_handles, p); - /* Callback for number of completed packet event */ - /* Originally designed for [3DSG] */ - if((p_lcb != NULL) && (p_lcb->p_nocp_cb)) - { - L2CAP_TRACE_DEBUG ("L2CAP - calling NoCP callback"); - (*p_lcb->p_nocp_cb)(p_lcb->remote_bd_addr); - } - - if (p_lcb) - { - if (p_lcb && (p_lcb->transport == BT_TRANSPORT_LE)) - l2cb.controller_le_xmit_window += num_sent; - else - { - /* Maintain the total window to the controller */ - l2cb.controller_xmit_window += num_sent; - } - /* If doing round-robin, adjust communal counts */ - if (p_lcb->link_xmit_quota == 0) - { - if (p_lcb->transport == BT_TRANSPORT_LE) - { - /* Don't go negative */ - if (l2cb.ble_round_robin_unacked > num_sent) - l2cb.ble_round_robin_unacked -= num_sent; - else - l2cb.ble_round_robin_unacked = 0; - } - else - { - /* Don't go negative */ - if (l2cb.round_robin_unacked > num_sent) - l2cb.round_robin_unacked -= num_sent; - else - l2cb.round_robin_unacked = 0; - } - } + for (xx = 0; xx < num_handles; xx++) { + STREAM_TO_UINT16(handle, p); + STREAM_TO_UINT16(num_sent, p); - /* Don't go negative */ - if (p_lcb->sent_not_acked > num_sent) - p_lcb->sent_not_acked -= num_sent; - else - p_lcb->sent_not_acked = 0; + p_lcb = l2cu_find_lcb_by_handle(handle); - l2c_link_check_send_pkts (p_lcb, NULL, NULL); + /* Callback for number of completed packet event */ + /* Originally designed for [3DSG] */ + if ((p_lcb != NULL) && (p_lcb->p_nocp_cb)) { + L2CAP_TRACE_DEBUG("L2CAP - calling NoCP callback"); + (*p_lcb->p_nocp_cb)(p_lcb->remote_bd_addr); + } - /* If we were doing round-robin for low priority links, check 'em */ - if ( (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - && (l2cb.check_round_robin) - && (l2cb.round_robin_unacked < l2cb.round_robin_quota) ) - { - l2c_link_check_send_pkts (NULL, NULL, NULL); - } - if ((p_lcb->transport == BT_TRANSPORT_LE) - && (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) - && ((l2cb.ble_check_round_robin) - && (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota))) - { - l2c_link_check_send_pkts (NULL, NULL, NULL); - } + if (p_lcb) { + if (p_lcb && (p_lcb->transport == BT_TRANSPORT_LE)) + l2cb.controller_le_xmit_window += num_sent; + else { + /* Maintain the total window to the controller */ + l2cb.controller_xmit_window += num_sent; + } + /* If doing round-robin, adjust communal counts */ + if (p_lcb->link_xmit_quota == 0) { + if (p_lcb->transport == BT_TRANSPORT_LE) { + /* Don't go negative */ + if (l2cb.ble_round_robin_unacked > num_sent) + l2cb.ble_round_robin_unacked -= num_sent; + else + l2cb.ble_round_robin_unacked = 0; + } else { + /* Don't go negative */ + if (l2cb.round_robin_unacked > num_sent) + l2cb.round_robin_unacked -= num_sent; + else + l2cb.round_robin_unacked = 0; } + } + + /* Don't go negative */ + if (p_lcb->sent_not_acked > num_sent) + p_lcb->sent_not_acked -= num_sent; + else + p_lcb->sent_not_acked = 0; + + l2c_link_check_send_pkts(p_lcb, NULL, NULL); + + /* If we were doing round-robin for low priority links, check 'em */ + if ((p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) && + (l2cb.check_round_robin) && + (l2cb.round_robin_unacked < l2cb.round_robin_quota)) { + l2c_link_check_send_pkts(NULL, NULL, NULL); + } + if ((p_lcb->transport == BT_TRANSPORT_LE) && + (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) && + ((l2cb.ble_check_round_robin) && + (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota))) { + l2c_link_check_send_pkts(NULL, NULL, NULL); + } + } #if (L2CAP_HCI_FLOW_CONTROL_DEBUG == TRUE) - if (p_lcb) - { - if (p_lcb->transport == BT_TRANSPORT_LE) - { - L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", - l2cb.controller_le_xmit_window, - p_lcb->handle, p_lcb->sent_not_acked, - l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked); - } - else - { - L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", - l2cb.controller_xmit_window, - p_lcb->handle, p_lcb->sent_not_acked, - l2cb.check_round_robin, l2cb.round_robin_unacked); - - } - } - else - { - L2CAP_TRACE_DEBUG ("TotalWin=%d LE_Win: %d, Handle=0x%x, RRCheck=%d, RRUnack=%d", - l2cb.controller_xmit_window, - l2cb.controller_le_xmit_window, - handle, - l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked); - } -#endif + if (p_lcb) { + if (p_lcb->transport == BT_TRANSPORT_LE) { + L2CAP_TRACE_DEBUG( + "TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", + l2cb.controller_le_xmit_window, p_lcb->handle, + p_lcb->sent_not_acked, l2cb.ble_check_round_robin, + l2cb.ble_round_robin_unacked); + } else { + L2CAP_TRACE_DEBUG( + "TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", + l2cb.controller_xmit_window, p_lcb->handle, p_lcb->sent_not_acked, + l2cb.check_round_robin, l2cb.round_robin_unacked); + } + } else { + L2CAP_TRACE_DEBUG( + "TotalWin=%d LE_Win: %d, Handle=0x%x, RRCheck=%d, RRUnack=%d", + l2cb.controller_xmit_window, l2cb.controller_le_xmit_window, handle, + l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked); } +#endif + } #if (HCILP_INCLUDED == TRUE) - /* only full stack can enable sleep mode */ - btu_check_bt_sleep (); + /* only full stack can enable sleep mode */ + btu_check_bt_sleep(); #endif } @@ -1461,35 +1303,32 @@ void l2c_link_process_num_completed_pkts (uint8_t *p) * Returns void * ******************************************************************************/ -void l2c_link_segments_xmitted (BT_HDR *p_msg) -{ - uint8_t *p = (uint8_t *)(p_msg + 1) + p_msg->offset; - uint16_t handle; - tL2C_LCB *p_lcb; - - /* Extract the handle */ - STREAM_TO_UINT16 (handle, p); - handle = HCID_GET_HANDLE (handle); - - /* Find the LCB based on the handle */ - p_lcb = l2cu_find_lcb_by_handle(handle); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd segment complete, unknown handle: %d", handle); - osi_free(p_msg); - return; - } - - if (p_lcb->link_state == LST_CONNECTED) - { - /* Enqueue the buffer to the head of the transmit queue, and see */ - /* if we can transmit anything more. */ - list_prepend(p_lcb->link_xmit_data_q, p_msg); - - p_lcb->partial_segment_being_sent = false; - - l2c_link_check_send_pkts (p_lcb, NULL, NULL); - } - else - osi_free(p_msg); +void l2c_link_segments_xmitted(BT_HDR* p_msg) { + uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint16_t handle; + tL2C_LCB* p_lcb; + + /* Extract the handle */ + STREAM_TO_UINT16(handle, p); + handle = HCID_GET_HANDLE(handle); + + /* Find the LCB based on the handle */ + p_lcb = l2cu_find_lcb_by_handle(handle); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - rcvd segment complete, unknown handle: %d", + handle); + osi_free(p_msg); + return; + } + + if (p_lcb->link_state == LST_CONNECTED) { + /* Enqueue the buffer to the head of the transmit queue, and see */ + /* if we can transmit anything more. */ + list_prepend(p_lcb->link_xmit_data_q, p_msg); + + p_lcb->partial_segment_being_sent = false; + + l2c_link_check_send_pkts(p_lcb, NULL, NULL); + } else + osi_free(p_msg); } diff --git a/stack/l2cap/l2c_main.cc b/stack/l2cap/l2c_main.cc index a921aa01f..4d69eac6f 100644 --- a/stack/l2cap/l2c_main.cc +++ b/stack/l2cap/l2c_main.cc @@ -28,11 +28,11 @@ #include #include +#include "bt_common.h" #include "bt_target.h" #include "btm_int.h" #include "btu.h" #include "device/include/controller.h" -#include "bt_common.h" #include "hcimsgs.h" #include "l2c_api.h" #include "l2c_int.h" @@ -40,13 +40,12 @@ #include "osi/include/log.h" #include "osi/include/osi.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void process_l2cap_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len); +static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len); /******************************************************************************/ /* G L O B A L L 2 C A P D A T A */ @@ -63,196 +62,184 @@ tL2C_CB l2cb; * Returns void * ******************************************************************************/ -void l2c_rcv_acl_data (BT_HDR *p_msg) -{ - uint8_t *p = (uint8_t *)(p_msg + 1) + p_msg->offset; - uint16_t handle, hci_len; - uint8_t pkt_type; - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb = NULL; - uint16_t l2cap_len, rcv_cid, psm; - uint16_t credit; - - /* Extract the handle */ - STREAM_TO_UINT16 (handle, p); - pkt_type = HCID_GET_EVENT (handle); - handle = HCID_GET_HANDLE (handle); - - /* Since the HCI Transport is putting segmented packets back together, we */ - /* should never get a valid packet with the type set to "continuation" */ - if (pkt_type != L2CAP_PKT_CONTINUE) - { - /* Find the LCB based on the handle */ - p_lcb = l2cu_find_lcb_by_handle(handle); - if (p_lcb == NULL) - { - uint8_t cmd_code; - - /* There is a slight possibility (specifically with USB) that we get an */ - /* L2CAP connection request before we get the HCI connection complete. */ - /* So for these types of messages, hold them for up to 2 seconds. */ - STREAM_TO_UINT16 (hci_len, p); - STREAM_TO_UINT16 (l2cap_len, p); - STREAM_TO_UINT16 (rcv_cid, p); - STREAM_TO_UINT8 (cmd_code, p); - - if ((p_msg->layer_specific == 0) && (rcv_cid == L2CAP_SIGNALLING_CID) - && (cmd_code == L2CAP_CMD_INFO_REQ || cmd_code == L2CAP_CMD_CONN_REQ)) { - L2CAP_TRACE_WARNING ("L2CAP - holding ACL for unknown handle:%d ls:%d" - " cid:%d opcode:%d cur count:%d", handle, p_msg->layer_specific, - rcv_cid, cmd_code, list_length(l2cb.rcv_pending_q)); - p_msg->layer_specific = 2; - list_append(l2cb.rcv_pending_q, p_msg); - - if (list_length(l2cb.rcv_pending_q) == 1) { - alarm_set_on_queue(l2cb.receive_hold_timer, - BT_1SEC_TIMEOUT_MS, - l2c_receive_hold_timer_timeout, NULL, - btu_general_alarm_queue); - } - - return; - } else { - L2CAP_TRACE_ERROR ("L2CAP - rcvd ACL for unknown handle:%d ls:%d cid:%d" - " opcode:%d cur count:%d", handle, p_msg->layer_specific, rcv_cid, - cmd_code, list_length(l2cb.rcv_pending_q)); - } - osi_free(p_msg); - return; - } - } - else - { - L2CAP_TRACE_WARNING ("L2CAP - expected pkt start or complete, got: %d", pkt_type); - osi_free(p_msg); - return; - } - - /* Extract the length and update the buffer header */ - STREAM_TO_UINT16 (hci_len, p); - p_msg->offset += 4; - - /* Extract the length and CID */ - STREAM_TO_UINT16 (l2cap_len, p); - STREAM_TO_UINT16 (rcv_cid, p); - - /* for BLE channel, always notify connection when ACL data received on the link */ - if (p_lcb && p_lcb->transport == BT_TRANSPORT_LE && p_lcb->link_state != LST_DISCONNECTING) - /* only process fixed channel data as channel open indication when link is not in disconnecting mode */ - l2cble_notify_le_connection(p_lcb->remote_bd_addr); - - /* Find the CCB for this CID */ - if (rcv_cid >= L2CAP_BASE_APPL_CID) - { - p_ccb = l2cu_find_ccb_by_cid(p_lcb, rcv_cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - unknown CID: 0x%04x", rcv_cid); - osi_free(p_msg); - return; +void l2c_rcv_acl_data(BT_HDR* p_msg) { + uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint16_t handle, hci_len; + uint8_t pkt_type; + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb = NULL; + uint16_t l2cap_len, rcv_cid, psm; + uint16_t credit; + + /* Extract the handle */ + STREAM_TO_UINT16(handle, p); + pkt_type = HCID_GET_EVENT(handle); + handle = HCID_GET_HANDLE(handle); + + /* Since the HCI Transport is putting segmented packets back together, we */ + /* should never get a valid packet with the type set to "continuation" */ + if (pkt_type != L2CAP_PKT_CONTINUE) { + /* Find the LCB based on the handle */ + p_lcb = l2cu_find_lcb_by_handle(handle); + if (p_lcb == NULL) { + uint8_t cmd_code; + + /* There is a slight possibility (specifically with USB) that we get an */ + /* L2CAP connection request before we get the HCI connection complete. */ + /* So for these types of messages, hold them for up to 2 seconds. */ + STREAM_TO_UINT16(hci_len, p); + STREAM_TO_UINT16(l2cap_len, p); + STREAM_TO_UINT16(rcv_cid, p); + STREAM_TO_UINT8(cmd_code, p); + + if ((p_msg->layer_specific == 0) && (rcv_cid == L2CAP_SIGNALLING_CID) && + (cmd_code == L2CAP_CMD_INFO_REQ || cmd_code == L2CAP_CMD_CONN_REQ)) { + L2CAP_TRACE_WARNING( + "L2CAP - holding ACL for unknown handle:%d ls:%d" + " cid:%d opcode:%d cur count:%d", + handle, p_msg->layer_specific, rcv_cid, cmd_code, + list_length(l2cb.rcv_pending_q)); + p_msg->layer_specific = 2; + list_append(l2cb.rcv_pending_q, p_msg); + + if (list_length(l2cb.rcv_pending_q) == 1) { + alarm_set_on_queue(l2cb.receive_hold_timer, BT_1SEC_TIMEOUT_MS, + l2c_receive_hold_timer_timeout, NULL, + btu_general_alarm_queue); } - } - - if (hci_len >= L2CAP_PKT_OVERHEAD) /* Must receive at least the L2CAP length and CID.*/ - { - p_msg->len = hci_len - L2CAP_PKT_OVERHEAD; - p_msg->offset += L2CAP_PKT_OVERHEAD; - } - else - { - L2CAP_TRACE_WARNING ("L2CAP - got incorrect hci header" ); - osi_free(p_msg); - return; - } - - if (l2cap_len != p_msg->len) - { - L2CAP_TRACE_WARNING ("L2CAP - bad length in pkt. Exp: %d Act: %d", - l2cap_len, p_msg->len); - osi_free(p_msg); return; + } else { + L2CAP_TRACE_ERROR( + "L2CAP - rcvd ACL for unknown handle:%d ls:%d cid:%d" + " opcode:%d cur count:%d", + handle, p_msg->layer_specific, rcv_cid, cmd_code, + list_length(l2cb.rcv_pending_q)); + } + osi_free(p_msg); + return; } - - /* Send the data through the channel state machine */ - if (rcv_cid == L2CAP_SIGNALLING_CID) - { - process_l2cap_cmd (p_lcb, p, l2cap_len); - osi_free(p_msg); + } else { + L2CAP_TRACE_WARNING("L2CAP - expected pkt start or complete, got: %d", + pkt_type); + osi_free(p_msg); + return; + } + + /* Extract the length and update the buffer header */ + STREAM_TO_UINT16(hci_len, p); + p_msg->offset += 4; + + /* Extract the length and CID */ + STREAM_TO_UINT16(l2cap_len, p); + STREAM_TO_UINT16(rcv_cid, p); + + /* for BLE channel, always notify connection when ACL data received on the + * link */ + if (p_lcb && p_lcb->transport == BT_TRANSPORT_LE && + p_lcb->link_state != LST_DISCONNECTING) + /* only process fixed channel data as channel open indication when link is + * not in disconnecting mode */ + l2cble_notify_le_connection(p_lcb->remote_bd_addr); + + /* Find the CCB for this CID */ + if (rcv_cid >= L2CAP_BASE_APPL_CID) { + p_ccb = l2cu_find_ccb_by_cid(p_lcb, rcv_cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - unknown CID: 0x%04x", rcv_cid); + osi_free(p_msg); + return; } - else if (rcv_cid == L2CAP_CONNECTIONLESS_CID) - { - /* process_connectionless_data (p_lcb); */ - STREAM_TO_UINT16 (psm, p); - L2CAP_TRACE_DEBUG( "GOT CONNECTIONLESS DATA PSM:%d", psm ) ; + } + + if (hci_len >= + L2CAP_PKT_OVERHEAD) /* Must receive at least the L2CAP length and CID.*/ + { + p_msg->len = hci_len - L2CAP_PKT_OVERHEAD; + p_msg->offset += L2CAP_PKT_OVERHEAD; + } else { + L2CAP_TRACE_WARNING("L2CAP - got incorrect hci header"); + osi_free(p_msg); + return; + } + + if (l2cap_len != p_msg->len) { + L2CAP_TRACE_WARNING("L2CAP - bad length in pkt. Exp: %d Act: %d", + l2cap_len, p_msg->len); + + osi_free(p_msg); + return; + } + + /* Send the data through the channel state machine */ + if (rcv_cid == L2CAP_SIGNALLING_CID) { + process_l2cap_cmd(p_lcb, p, l2cap_len); + osi_free(p_msg); + } else if (rcv_cid == L2CAP_CONNECTIONLESS_CID) { + /* process_connectionless_data (p_lcb); */ + STREAM_TO_UINT16(psm, p); + L2CAP_TRACE_DEBUG("GOT CONNECTIONLESS DATA PSM:%d", psm); #if (L2CAP_UCD_INCLUDED == TRUE) - /* if it is not broadcast, check UCD registration */ - if ( l2c_ucd_check_rx_pkts( p_lcb, p_msg ) ) - { - /* nothing to do */ - } - else + /* if it is not broadcast, check UCD registration */ + if (l2c_ucd_check_rx_pkts(p_lcb, p_msg)) { + /* nothing to do */ + } else #endif - osi_free(p_msg); - } - else if (rcv_cid == L2CAP_BLE_SIGNALLING_CID) - { - l2cble_process_sig_cmd (p_lcb, p, l2cap_len); - osi_free(p_msg); - } + osi_free(p_msg); + } else if (rcv_cid == L2CAP_BLE_SIGNALLING_CID) { + l2cble_process_sig_cmd(p_lcb, p, l2cap_len); + osi_free(p_msg); + } #if (L2CAP_NUM_FIXED_CHNLS > 0) - else if ((rcv_cid >= L2CAP_FIRST_FIXED_CHNL) && (rcv_cid <= L2CAP_LAST_FIXED_CHNL) && - (l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb != NULL) ) - { - /* If no CCB for this channel, allocate one */ - if (p_lcb && - /* only process fixed channel data when link is open or wait for data indication */ - (p_lcb->link_state != LST_DISCONNECTING) && - l2cu_initialize_fixed_ccb (p_lcb, rcv_cid, &l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) - { - p_ccb = p_lcb->p_fixed_ccbs[rcv_cid - L2CAP_FIRST_FIXED_CHNL]; - - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - l2c_fcr_proc_pdu (p_ccb, p_msg); - else - (*l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb) - (rcv_cid, p_lcb->remote_bd_addr, p_msg); - } - else - osi_free(p_msg); - } + else if ((rcv_cid >= L2CAP_FIRST_FIXED_CHNL) && + (rcv_cid <= L2CAP_LAST_FIXED_CHNL) && + (l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL] + .pL2CA_FixedData_Cb != NULL)) { + /* If no CCB for this channel, allocate one */ + if (p_lcb && + /* only process fixed channel data when link is open or wait for data + indication */ + (p_lcb->link_state != LST_DISCONNECTING) && + l2cu_initialize_fixed_ccb( + p_lcb, rcv_cid, &l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL] + .fixed_chnl_opts)) { + p_ccb = p_lcb->p_fixed_ccbs[rcv_cid - L2CAP_FIRST_FIXED_CHNL]; + + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) + l2c_fcr_proc_pdu(p_ccb, p_msg); + else + (*l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)( + rcv_cid, p_lcb->remote_bd_addr, p_msg); + } else + osi_free(p_msg); + } #endif - else - { - if (p_ccb == NULL) + else { + if (p_ccb == NULL) + osi_free(p_msg); + else { + if (p_lcb->transport == BT_TRANSPORT_LE) { + l2c_lcc_proc_pdu(p_ccb, p_msg); + // Got a pkt, valid send out credits to the peer device + credit = L2CAP_LE_DEFAULT_CREDIT; + l2c_csm_execute(p_ccb, L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT, &credit); + } else { + /* Basic mode packets go straight to the state machine */ + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DATA, p_msg); + else { + /* eRTM or streaming mode, so we need to validate states first */ + if ((p_ccb->chnl_state == CST_OPEN) || + (p_ccb->chnl_state == CST_CONFIG)) + l2c_fcr_proc_pdu(p_ccb, p_msg); + else osi_free(p_msg); - else - { - if (p_lcb->transport == BT_TRANSPORT_LE) - { - l2c_lcc_proc_pdu(p_ccb,p_msg); - // Got a pkt, valid send out credits to the peer device - credit = L2CAP_LE_DEFAULT_CREDIT; - l2c_csm_execute(p_ccb, L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT, &credit); - } - else - { - /* Basic mode packets go straight to the state machine */ - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DATA, p_msg); - else - { - /* eRTM or streaming mode, so we need to validate states first */ - if ((p_ccb->chnl_state == CST_OPEN) || (p_ccb->chnl_state == CST_CONFIG)) - l2c_fcr_proc_pdu (p_ccb, p_msg); - else - osi_free (p_msg); - } - } } + } } + } } /******************************************************************************* @@ -265,488 +252,457 @@ void l2c_rcv_acl_data (BT_HDR *p_msg) * Returns void * ******************************************************************************/ -static void process_l2cap_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len) -{ - uint8_t *p_pkt_end, *p_next_cmd, *p_cfg_end, *p_cfg_start; - uint8_t cmd_code, cfg_code, cfg_len, id; - tL2C_CONN_INFO con_info; - tL2CAP_CFG_INFO cfg_info; - uint16_t rej_reason, rej_mtu, lcid, rcid, info_type; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - bool cfg_rej, pkt_size_rej = false; - uint16_t cfg_rej_len, cmd_len; - uint16_t result; - tL2C_CONN_INFO ci; - - /* if l2cap command received in CID 1 on top of an LE link, ignore this command */ - if (p_lcb->transport == BT_TRANSPORT_LE) - return; - - /* Reject the packet if it exceeds the default Signalling Channel MTU */ - if (pkt_len > L2CAP_DEFAULT_MTU) - { - /* Core Spec requires a single response to the first command found in a multi-command - ** L2cap packet. If only responses in the packet, then it will be ignored. - ** Here we simply mark the bad packet and decide which cmd ID to reject later - */ - pkt_size_rej = true; - L2CAP_TRACE_ERROR ("L2CAP SIG MTU Pkt Len Exceeded (672) -> pkt_len: %d", pkt_len); +static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { + uint8_t *p_pkt_end, *p_next_cmd, *p_cfg_end, *p_cfg_start; + uint8_t cmd_code, cfg_code, cfg_len, id; + tL2C_CONN_INFO con_info; + tL2CAP_CFG_INFO cfg_info; + uint16_t rej_reason, rej_mtu, lcid, rcid, info_type; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + bool cfg_rej, pkt_size_rej = false; + uint16_t cfg_rej_len, cmd_len; + uint16_t result; + tL2C_CONN_INFO ci; + + /* if l2cap command received in CID 1 on top of an LE link, ignore this + * command */ + if (p_lcb->transport == BT_TRANSPORT_LE) return; + + /* Reject the packet if it exceeds the default Signalling Channel MTU */ + if (pkt_len > L2CAP_DEFAULT_MTU) { + /* Core Spec requires a single response to the first command found in a + *multi-command + ** L2cap packet. If only responses in the packet, then it will be ignored. + ** Here we simply mark the bad packet and decide which cmd ID to reject + *later + */ + pkt_size_rej = true; + L2CAP_TRACE_ERROR("L2CAP SIG MTU Pkt Len Exceeded (672) -> pkt_len: %d", + pkt_len); + } + + p_next_cmd = p; + p_pkt_end = p + pkt_len; + + memset(&cfg_info, 0, sizeof(cfg_info)); + + /* An L2CAP packet may contain multiple commands */ + while (true) { + /* Smallest command is 4 bytes */ + if ((p = p_next_cmd) > (p_pkt_end - 4)) break; + + STREAM_TO_UINT8(cmd_code, p); + STREAM_TO_UINT8(id, p); + STREAM_TO_UINT16(cmd_len, p); + + /* Check command length does not exceed packet length */ + if ((p_next_cmd = p + cmd_len) > p_pkt_end) { + L2CAP_TRACE_WARNING("Command len bad pkt_len: %d cmd_len: %d code: %d", + pkt_len, cmd_len, cmd_code); + break; } - p_next_cmd = p; - p_pkt_end = p + pkt_len; - - memset (&cfg_info, 0, sizeof(cfg_info)); - - /* An L2CAP packet may contain multiple commands */ - while (true) - { - /* Smallest command is 4 bytes */ - if ((p = p_next_cmd) > (p_pkt_end - 4)) - break; + L2CAP_TRACE_DEBUG("cmd_code: %d, id:%d, cmd_len:%d", cmd_code, id, cmd_len); - STREAM_TO_UINT8 (cmd_code, p); - STREAM_TO_UINT8 (id, p); - STREAM_TO_UINT16 (cmd_len, p); + /* Bad L2CAP packet length, look or cmd to reject */ + if (pkt_size_rej) { + /* If command found rejected it and we're done, otherwise keep looking */ + if (l2c_is_cmd_rejected(cmd_code, id, p_lcb)) + return; + else + continue; /* Look for next cmd/response in current packet */ + } - /* Check command length does not exceed packet length */ - if ((p_next_cmd = p + cmd_len) > p_pkt_end) - { - L2CAP_TRACE_WARNING ("Command len bad pkt_len: %d cmd_len: %d code: %d", - pkt_len, cmd_len, cmd_code); - break; + switch (cmd_code) { + case L2CAP_CMD_REJECT: + STREAM_TO_UINT16(rej_reason, p); + if (rej_reason == L2CAP_CMD_REJ_MTU_EXCEEDED) { + STREAM_TO_UINT16(rej_mtu, p); + /* What to do with the MTU reject ? We have negotiated an MTU. For now + */ + /* we will ignore it and let a higher protocol timeout take care of it + */ + + L2CAP_TRACE_WARNING("L2CAP - MTU rej Handle: %d MTU: %d", + p_lcb->handle, rej_mtu); } - - L2CAP_TRACE_DEBUG ("cmd_code: %d, id:%d, cmd_len:%d", cmd_code, id, cmd_len); - - /* Bad L2CAP packet length, look or cmd to reject */ - if (pkt_size_rej) - { - /* If command found rejected it and we're done, otherwise keep looking */ - if (l2c_is_cmd_rejected(cmd_code, id, p_lcb)) - return; - else - continue; /* Look for next cmd/response in current packet */ + if (rej_reason == L2CAP_CMD_REJ_INVALID_CID) { + STREAM_TO_UINT16(rcid, p); + STREAM_TO_UINT16(lcid, p); + + L2CAP_TRACE_WARNING( + "L2CAP - rej with CID invalid, LCID: 0x%04x RCID: 0x%04x", lcid, + rcid); + + /* Remote CID invalid. Treat as a disconnect */ + if (((p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid)) != NULL) && + (p_ccb->remote_cid == rcid)) { + /* Fake link disconnect - no reply is generated */ + l2c_csm_execute(p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); + } } - switch (cmd_code) - { - case L2CAP_CMD_REJECT: - STREAM_TO_UINT16 (rej_reason, p); - if (rej_reason == L2CAP_CMD_REJ_MTU_EXCEEDED) - { - STREAM_TO_UINT16 (rej_mtu, p); - /* What to do with the MTU reject ? We have negotiated an MTU. For now */ - /* we will ignore it and let a higher protocol timeout take care of it */ - - L2CAP_TRACE_WARNING ("L2CAP - MTU rej Handle: %d MTU: %d", p_lcb->handle, rej_mtu); - } - if (rej_reason == L2CAP_CMD_REJ_INVALID_CID) - { - STREAM_TO_UINT16 (rcid, p); - STREAM_TO_UINT16 (lcid, p); - - L2CAP_TRACE_WARNING ("L2CAP - rej with CID invalid, LCID: 0x%04x RCID: 0x%04x", lcid, rcid); - - /* Remote CID invalid. Treat as a disconnect */ - if (((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) - && (p_ccb->remote_cid == rcid)) - { - /* Fake link disconnect - no reply is generated */ - l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL); - } - } - - /* SonyEricsson Info request Bug workaround (Continue connection) */ - else if (rej_reason == L2CAP_CMD_REJ_NOT_UNDERSTOOD && p_lcb->w4_info_rsp) - { - alarm_cancel(p_lcb->info_resp_timer); - - p_lcb->w4_info_rsp = false; - ci.status = HCI_SUCCESS; - memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); - - /* For all channels, send the event through their FSMs */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); - } - } - break; - - case L2CAP_CMD_CONN_REQ: - STREAM_TO_UINT16 (con_info.psm, p); - STREAM_TO_UINT16 (rcid, p); - p_rcb = l2cu_find_rcb_by_psm(con_info.psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for unknown PSM: %d", con_info.psm); - l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_PSM); - break; - } - else - { - if (!p_rcb->api.pL2CA_ConnectInd_Cb) - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for outgoing-only connection PSM: %d", con_info.psm); - l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_PSM); - break; - } - } - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - unable to allocate CCB"); - l2cu_reject_connection (p_lcb, rcid, id, L2CAP_CONN_NO_RESOURCES); - break; - } - p_ccb->remote_id = id; - p_ccb->p_rcb = p_rcb; - p_ccb->remote_cid = rcid; - - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); - break; + /* SonyEricsson Info request Bug workaround (Continue connection) */ + else if (rej_reason == L2CAP_CMD_REJ_NOT_UNDERSTOOD && + p_lcb->w4_info_rsp) { + alarm_cancel(p_lcb->info_resp_timer); - case L2CAP_CMD_CONN_RSP: - STREAM_TO_UINT16 (con_info.remote_cid, p); - STREAM_TO_UINT16 (lcid, p); - STREAM_TO_UINT16 (con_info.l2cap_result, p); - STREAM_TO_UINT16 (con_info.l2cap_status, p); - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for conn rsp, LCID: %d RCID: %d", - lcid, con_info.remote_cid); - break; - } - if (p_ccb->local_id != id) - { - L2CAP_TRACE_WARNING ("L2CAP - con rsp - bad ID. Exp: %d Got: %d", - p_ccb->local_id, id); - break; - } - - if (con_info.l2cap_result == L2CAP_CONN_OK) - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); - else if (con_info.l2cap_result == L2CAP_CONN_PENDING) - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_PND, &con_info); - else - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); + p_lcb->w4_info_rsp = false; + ci.status = HCI_SUCCESS; + memcpy(ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); + /* For all channels, send the event through their FSMs */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); + } + } + break; + + case L2CAP_CMD_CONN_REQ: + STREAM_TO_UINT16(con_info.psm, p); + STREAM_TO_UINT16(rcid, p); + p_rcb = l2cu_find_rcb_by_psm(con_info.psm); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - rcvd conn req for unknown PSM: %d", + con_info.psm); + l2cu_reject_connection(p_lcb, rcid, id, L2CAP_CONN_NO_PSM); + break; + } else { + if (!p_rcb->api.pL2CA_ConnectInd_Cb) { + L2CAP_TRACE_WARNING( + "L2CAP - rcvd conn req for outgoing-only connection PSM: %d", + con_info.psm); + l2cu_reject_connection(p_lcb, rcid, id, L2CAP_CONN_NO_PSM); break; + } + } + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - unable to allocate CCB"); + l2cu_reject_connection(p_lcb, rcid, id, L2CAP_CONN_NO_RESOURCES); + break; + } + p_ccb->remote_id = id; + p_ccb->p_rcb = p_rcb; + p_ccb->remote_cid = rcid; + + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); + break; + + case L2CAP_CMD_CONN_RSP: + STREAM_TO_UINT16(con_info.remote_cid, p); + STREAM_TO_UINT16(lcid, p); + STREAM_TO_UINT16(con_info.l2cap_result, p); + STREAM_TO_UINT16(con_info.l2cap_status, p); + + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for conn rsp, LCID: %d RCID: %d", + lcid, con_info.remote_cid); + break; + } + if (p_ccb->local_id != id) { + L2CAP_TRACE_WARNING("L2CAP - con rsp - bad ID. Exp: %d Got: %d", + p_ccb->local_id, id); + break; + } - case L2CAP_CMD_CONFIG_REQ: - p_cfg_end = p + cmd_len; - cfg_rej = false; - cfg_rej_len = 0; - - STREAM_TO_UINT16 (lcid, p); - STREAM_TO_UINT16 (cfg_info.flags, p); - - p_cfg_start = p; - - cfg_info.flush_to_present = cfg_info.mtu_present = cfg_info.qos_present = - cfg_info.fcr_present = cfg_info.fcs_present = false; - - while (p < p_cfg_end) - { - STREAM_TO_UINT8 (cfg_code, p); - STREAM_TO_UINT8 (cfg_len, p); - - switch (cfg_code & 0x7F) - { - case L2CAP_CFG_TYPE_MTU: - cfg_info.mtu_present = true; - STREAM_TO_UINT16 (cfg_info.mtu, p); - break; - - case L2CAP_CFG_TYPE_FLUSH_TOUT: - cfg_info.flush_to_present = true; - STREAM_TO_UINT16 (cfg_info.flush_to, p); - break; - - case L2CAP_CFG_TYPE_QOS: - cfg_info.qos_present = true; - STREAM_TO_UINT8 (cfg_info.qos.qos_flags, p); - STREAM_TO_UINT8 (cfg_info.qos.service_type, p); - STREAM_TO_UINT32 (cfg_info.qos.token_rate, p); - STREAM_TO_UINT32 (cfg_info.qos.token_bucket_size, p); - STREAM_TO_UINT32 (cfg_info.qos.peak_bandwidth, p); - STREAM_TO_UINT32 (cfg_info.qos.latency, p); - STREAM_TO_UINT32 (cfg_info.qos.delay_variation, p); - break; - - case L2CAP_CFG_TYPE_FCR: - cfg_info.fcr_present = true; - STREAM_TO_UINT8 (cfg_info.fcr.mode, p); - STREAM_TO_UINT8 (cfg_info.fcr.tx_win_sz, p); - STREAM_TO_UINT8 (cfg_info.fcr.max_transmit, p); - STREAM_TO_UINT16 (cfg_info.fcr.rtrans_tout, p); - STREAM_TO_UINT16 (cfg_info.fcr.mon_tout, p); - STREAM_TO_UINT16 (cfg_info.fcr.mps, p); - break; - - case L2CAP_CFG_TYPE_FCS: - cfg_info.fcs_present = true; - STREAM_TO_UINT8 (cfg_info.fcs, p); - break; - - case L2CAP_CFG_TYPE_EXT_FLOW: - cfg_info.ext_flow_spec_present = true; - STREAM_TO_UINT8 (cfg_info.ext_flow_spec.id, p); - STREAM_TO_UINT8 (cfg_info.ext_flow_spec.stype, p); - STREAM_TO_UINT16 (cfg_info.ext_flow_spec.max_sdu_size, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.sdu_inter_time, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.access_latency, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.flush_timeout, p); - break; - - default: - /* sanity check option length */ - if ((cfg_len + L2CAP_CFG_OPTION_OVERHEAD) <= cmd_len) - { - p += cfg_len; - if ((cfg_code & 0x80) == 0) - { - cfg_rej_len += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; - cfg_rej = true; - } - } - /* bad length; force loop exit */ - else - { - p = p_cfg_end; - cfg_rej = true; - } - break; - } - } - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - p_ccb->remote_id = id; - if (cfg_rej) - { - l2cu_send_peer_config_rej (p_ccb, p_cfg_start, (uint16_t) (cmd_len - L2CAP_CONFIG_REQ_LEN), cfg_rej_len); - } - else - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_REQ, &cfg_info); - } - } - else - { - /* updated spec says send command reject on invalid cid */ - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_INVALID_CID, id, 0, 0); - } - break; - - case L2CAP_CMD_CONFIG_RSP: - p_cfg_end = p + cmd_len; - STREAM_TO_UINT16 (lcid, p); - STREAM_TO_UINT16 (cfg_info.flags, p); - STREAM_TO_UINT16 (cfg_info.result, p); - - cfg_info.flush_to_present = cfg_info.mtu_present = cfg_info.qos_present = - cfg_info.fcr_present = cfg_info.fcs_present = false; - - while (p < p_cfg_end) - { - STREAM_TO_UINT8 (cfg_code, p); - STREAM_TO_UINT8 (cfg_len, p); - - switch (cfg_code & 0x7F) - { - case L2CAP_CFG_TYPE_MTU: - cfg_info.mtu_present = true; - STREAM_TO_UINT16 (cfg_info.mtu, p); - break; - - case L2CAP_CFG_TYPE_FLUSH_TOUT: - cfg_info.flush_to_present = true; - STREAM_TO_UINT16 (cfg_info.flush_to, p); - break; - - case L2CAP_CFG_TYPE_QOS: - cfg_info.qos_present = true; - STREAM_TO_UINT8 (cfg_info.qos.qos_flags, p); - STREAM_TO_UINT8 (cfg_info.qos.service_type, p); - STREAM_TO_UINT32 (cfg_info.qos.token_rate, p); - STREAM_TO_UINT32 (cfg_info.qos.token_bucket_size, p); - STREAM_TO_UINT32 (cfg_info.qos.peak_bandwidth, p); - STREAM_TO_UINT32 (cfg_info.qos.latency, p); - STREAM_TO_UINT32 (cfg_info.qos.delay_variation, p); - break; - - case L2CAP_CFG_TYPE_FCR: - cfg_info.fcr_present = true; - STREAM_TO_UINT8 (cfg_info.fcr.mode, p); - STREAM_TO_UINT8 (cfg_info.fcr.tx_win_sz, p); - STREAM_TO_UINT8 (cfg_info.fcr.max_transmit, p); - STREAM_TO_UINT16 (cfg_info.fcr.rtrans_tout, p); - STREAM_TO_UINT16 (cfg_info.fcr.mon_tout, p); - STREAM_TO_UINT16 (cfg_info.fcr.mps, p); - break; - - case L2CAP_CFG_TYPE_FCS: - cfg_info.fcs_present = true; - STREAM_TO_UINT8 (cfg_info.fcs, p); - break; - - case L2CAP_CFG_TYPE_EXT_FLOW: - cfg_info.ext_flow_spec_present = true; - STREAM_TO_UINT8 (cfg_info.ext_flow_spec.id, p); - STREAM_TO_UINT8 (cfg_info.ext_flow_spec.stype, p); - STREAM_TO_UINT16 (cfg_info.ext_flow_spec.max_sdu_size, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.sdu_inter_time, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.access_latency, p); - STREAM_TO_UINT32 (cfg_info.ext_flow_spec.flush_timeout, p); - break; - } - } - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - if (p_ccb->local_id != id) - { - L2CAP_TRACE_WARNING ("L2CAP - cfg rsp - bad ID. Exp: %d Got: %d", - p_ccb->local_id, id); - break; - } - if ( (cfg_info.result == L2CAP_CFG_OK) || (cfg_info.result == L2CAP_CFG_PENDING) ) - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_RSP, &cfg_info); - else - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_CONFIG_RSP_NEG, &cfg_info); - } - else - { - L2CAP_TRACE_WARNING ("L2CAP - rcvd cfg rsp for unknown CID: 0x%04x", lcid); - } - break; - - case L2CAP_CMD_DISC_REQ: - STREAM_TO_UINT16 (lcid, p); - STREAM_TO_UINT16 (rcid, p); - - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - if (p_ccb->remote_cid == rcid) - { - p_ccb->remote_id = id; - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, &con_info); + if (con_info.l2cap_result == L2CAP_CONN_OK) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); + else if (con_info.l2cap_result == L2CAP_CONN_PENDING) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_PND, &con_info); + else + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); + + break; + + case L2CAP_CMD_CONFIG_REQ: + p_cfg_end = p + cmd_len; + cfg_rej = false; + cfg_rej_len = 0; + + STREAM_TO_UINT16(lcid, p); + STREAM_TO_UINT16(cfg_info.flags, p); + + p_cfg_start = p; + + cfg_info.flush_to_present = cfg_info.mtu_present = + cfg_info.qos_present = cfg_info.fcr_present = cfg_info.fcs_present = + false; + + while (p < p_cfg_end) { + STREAM_TO_UINT8(cfg_code, p); + STREAM_TO_UINT8(cfg_len, p); + + switch (cfg_code & 0x7F) { + case L2CAP_CFG_TYPE_MTU: + cfg_info.mtu_present = true; + STREAM_TO_UINT16(cfg_info.mtu, p); + break; + + case L2CAP_CFG_TYPE_FLUSH_TOUT: + cfg_info.flush_to_present = true; + STREAM_TO_UINT16(cfg_info.flush_to, p); + break; + + case L2CAP_CFG_TYPE_QOS: + cfg_info.qos_present = true; + STREAM_TO_UINT8(cfg_info.qos.qos_flags, p); + STREAM_TO_UINT8(cfg_info.qos.service_type, p); + STREAM_TO_UINT32(cfg_info.qos.token_rate, p); + STREAM_TO_UINT32(cfg_info.qos.token_bucket_size, p); + STREAM_TO_UINT32(cfg_info.qos.peak_bandwidth, p); + STREAM_TO_UINT32(cfg_info.qos.latency, p); + STREAM_TO_UINT32(cfg_info.qos.delay_variation, p); + break; + + case L2CAP_CFG_TYPE_FCR: + cfg_info.fcr_present = true; + STREAM_TO_UINT8(cfg_info.fcr.mode, p); + STREAM_TO_UINT8(cfg_info.fcr.tx_win_sz, p); + STREAM_TO_UINT8(cfg_info.fcr.max_transmit, p); + STREAM_TO_UINT16(cfg_info.fcr.rtrans_tout, p); + STREAM_TO_UINT16(cfg_info.fcr.mon_tout, p); + STREAM_TO_UINT16(cfg_info.fcr.mps, p); + break; + + case L2CAP_CFG_TYPE_FCS: + cfg_info.fcs_present = true; + STREAM_TO_UINT8(cfg_info.fcs, p); + break; + + case L2CAP_CFG_TYPE_EXT_FLOW: + cfg_info.ext_flow_spec_present = true; + STREAM_TO_UINT8(cfg_info.ext_flow_spec.id, p); + STREAM_TO_UINT8(cfg_info.ext_flow_spec.stype, p); + STREAM_TO_UINT16(cfg_info.ext_flow_spec.max_sdu_size, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.sdu_inter_time, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.access_latency, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.flush_timeout, p); + break; + + default: + /* sanity check option length */ + if ((cfg_len + L2CAP_CFG_OPTION_OVERHEAD) <= cmd_len) { + p += cfg_len; + if ((cfg_code & 0x80) == 0) { + cfg_rej_len += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; + cfg_rej = true; } - } - else - l2cu_send_peer_disc_rsp (p_lcb, id, lcid, rcid); - - break; + } + /* bad length; force loop exit */ + else { + p = p_cfg_end; + cfg_rej = true; + } + break; + } + } - case L2CAP_CMD_DISC_RSP: - STREAM_TO_UINT16 (rcid, p); - STREAM_TO_UINT16 (lcid, p); + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + p_ccb->remote_id = id; + if (cfg_rej) { + l2cu_send_peer_config_rej( + p_ccb, p_cfg_start, (uint16_t)(cmd_len - L2CAP_CONFIG_REQ_LEN), + cfg_rej_len); + } else { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONFIG_REQ, &cfg_info); + } + } else { + /* updated spec says send command reject on invalid cid */ + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_INVALID_CID, id, 0, 0); + } + break; + + case L2CAP_CMD_CONFIG_RSP: + p_cfg_end = p + cmd_len; + STREAM_TO_UINT16(lcid, p); + STREAM_TO_UINT16(cfg_info.flags, p); + STREAM_TO_UINT16(cfg_info.result, p); + + cfg_info.flush_to_present = cfg_info.mtu_present = + cfg_info.qos_present = cfg_info.fcr_present = cfg_info.fcs_present = + false; + + while (p < p_cfg_end) { + STREAM_TO_UINT8(cfg_code, p); + STREAM_TO_UINT8(cfg_len, p); + + switch (cfg_code & 0x7F) { + case L2CAP_CFG_TYPE_MTU: + cfg_info.mtu_present = true; + STREAM_TO_UINT16(cfg_info.mtu, p); + break; + + case L2CAP_CFG_TYPE_FLUSH_TOUT: + cfg_info.flush_to_present = true; + STREAM_TO_UINT16(cfg_info.flush_to, p); + break; + + case L2CAP_CFG_TYPE_QOS: + cfg_info.qos_present = true; + STREAM_TO_UINT8(cfg_info.qos.qos_flags, p); + STREAM_TO_UINT8(cfg_info.qos.service_type, p); + STREAM_TO_UINT32(cfg_info.qos.token_rate, p); + STREAM_TO_UINT32(cfg_info.qos.token_bucket_size, p); + STREAM_TO_UINT32(cfg_info.qos.peak_bandwidth, p); + STREAM_TO_UINT32(cfg_info.qos.latency, p); + STREAM_TO_UINT32(cfg_info.qos.delay_variation, p); + break; + + case L2CAP_CFG_TYPE_FCR: + cfg_info.fcr_present = true; + STREAM_TO_UINT8(cfg_info.fcr.mode, p); + STREAM_TO_UINT8(cfg_info.fcr.tx_win_sz, p); + STREAM_TO_UINT8(cfg_info.fcr.max_transmit, p); + STREAM_TO_UINT16(cfg_info.fcr.rtrans_tout, p); + STREAM_TO_UINT16(cfg_info.fcr.mon_tout, p); + STREAM_TO_UINT16(cfg_info.fcr.mps, p); + break; + + case L2CAP_CFG_TYPE_FCS: + cfg_info.fcs_present = true; + STREAM_TO_UINT8(cfg_info.fcs, p); + break; + + case L2CAP_CFG_TYPE_EXT_FLOW: + cfg_info.ext_flow_spec_present = true; + STREAM_TO_UINT8(cfg_info.ext_flow_spec.id, p); + STREAM_TO_UINT8(cfg_info.ext_flow_spec.stype, p); + STREAM_TO_UINT16(cfg_info.ext_flow_spec.max_sdu_size, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.sdu_inter_time, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.access_latency, p); + STREAM_TO_UINT32(cfg_info.ext_flow_spec.flush_timeout, p); + break; + } + } - p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); - if (p_ccb != NULL) - { - if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, &con_info); - } - } + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + if (p_ccb->local_id != id) { + L2CAP_TRACE_WARNING("L2CAP - cfg rsp - bad ID. Exp: %d Got: %d", + p_ccb->local_id, id); break; + } + if ((cfg_info.result == L2CAP_CFG_OK) || + (cfg_info.result == L2CAP_CFG_PENDING)) + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONFIG_RSP, &cfg_info); + else + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONFIG_RSP_NEG, &cfg_info); + } else { + L2CAP_TRACE_WARNING("L2CAP - rcvd cfg rsp for unknown CID: 0x%04x", + lcid); + } + break; - case L2CAP_CMD_ECHO_REQ: - l2cu_send_peer_echo_rsp (p_lcb, id, NULL, 0); - break; + case L2CAP_CMD_DISC_REQ: + STREAM_TO_UINT16(lcid, p); + STREAM_TO_UINT16(rcid, p); - case L2CAP_CMD_ECHO_RSP: - if (p_lcb->p_echo_rsp_cb) - { - tL2CA_ECHO_RSP_CB *p_cb = p_lcb->p_echo_rsp_cb; + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + if (p_ccb->remote_cid == rcid) { + p_ccb->remote_id = id; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, &con_info); + } + } else + l2cu_send_peer_disc_rsp(p_lcb, id, lcid, rcid); + + break; + + case L2CAP_CMD_DISC_RSP: + STREAM_TO_UINT16(rcid, p); + STREAM_TO_UINT16(lcid, p); + + p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid); + if (p_ccb != NULL) { + if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, &con_info); + } + } + break; - /* Zero out the callback in case app immediately calls us again */ - p_lcb->p_echo_rsp_cb = NULL; + case L2CAP_CMD_ECHO_REQ: + l2cu_send_peer_echo_rsp(p_lcb, id, NULL, 0); + break; - (*p_cb) (L2CAP_PING_RESULT_OK); - } - break; + case L2CAP_CMD_ECHO_RSP: + if (p_lcb->p_echo_rsp_cb) { + tL2CA_ECHO_RSP_CB* p_cb = p_lcb->p_echo_rsp_cb; - case L2CAP_CMD_INFO_REQ: - STREAM_TO_UINT16 (info_type, p); - l2cu_send_peer_info_rsp (p_lcb, id, info_type); - break; + /* Zero out the callback in case app immediately calls us again */ + p_lcb->p_echo_rsp_cb = NULL; - case L2CAP_CMD_INFO_RSP: - /* Stop the link connect timer if sent before L2CAP connection is up */ - if (p_lcb->w4_info_rsp) - { - alarm_cancel(p_lcb->info_resp_timer); - p_lcb->w4_info_rsp = false; - } + (*p_cb)(L2CAP_PING_RESULT_OK); + } + break; + + case L2CAP_CMD_INFO_REQ: + STREAM_TO_UINT16(info_type, p); + l2cu_send_peer_info_rsp(p_lcb, id, info_type); + break; + + case L2CAP_CMD_INFO_RSP: + /* Stop the link connect timer if sent before L2CAP connection is up */ + if (p_lcb->w4_info_rsp) { + alarm_cancel(p_lcb->info_resp_timer); + p_lcb->w4_info_rsp = false; + } - STREAM_TO_UINT16 (info_type, p); - STREAM_TO_UINT16 (result, p); + STREAM_TO_UINT16(info_type, p); + STREAM_TO_UINT16(result, p); - p_lcb->info_rx_bits |= (1 << info_type); + p_lcb->info_rx_bits |= (1 << info_type); - if ( (info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) - && (result == L2CAP_INFO_RESP_RESULT_SUCCESS) ) - { - STREAM_TO_UINT32( p_lcb->peer_ext_fea, p ); + if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && + (result == L2CAP_INFO_RESP_RESULT_SUCCESS)) { + STREAM_TO_UINT32(p_lcb->peer_ext_fea, p); #if (L2CAP_NUM_FIXED_CHNLS > 0) - if (p_lcb->peer_ext_fea & L2CAP_EXTFEA_FIXED_CHNLS) - { - l2cu_send_peer_info_req (p_lcb, L2CAP_FIXED_CHANNELS_INFO_TYPE); - break; - } - else - { - l2cu_process_fixed_chnl_resp (p_lcb); - } + if (p_lcb->peer_ext_fea & L2CAP_EXTFEA_FIXED_CHNLS) { + l2cu_send_peer_info_req(p_lcb, L2CAP_FIXED_CHANNELS_INFO_TYPE); + break; + } else { + l2cu_process_fixed_chnl_resp(p_lcb); + } #endif - } + } #if (L2CAP_NUM_FIXED_CHNLS > 0) - if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) - { - if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) - { - memcpy (p_lcb->peer_chnl_mask, p, L2CAP_FIXED_CHNL_ARRAY_SIZE); - } + if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) { + if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) { + memcpy(p_lcb->peer_chnl_mask, p, L2CAP_FIXED_CHNL_ARRAY_SIZE); + } - l2cu_process_fixed_chnl_resp (p_lcb); - } + l2cu_process_fixed_chnl_resp(p_lcb); + } #endif #if (L2CAP_UCD_INCLUDED == TRUE) - else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) - { - if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) - { - STREAM_TO_UINT16 (p_lcb->ucd_mtu, p); - } - } + else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) { + if (result == L2CAP_INFO_RESP_RESULT_SUCCESS) { + STREAM_TO_UINT16(p_lcb->ucd_mtu, p); + } + } #endif - ci.status = HCI_SUCCESS; - memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); - } - break; - - default: - L2CAP_TRACE_WARNING ("L2CAP - bad cmd code: %d", cmd_code); - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); - return; + ci.status = HCI_SUCCESS; + memcpy(ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR)); + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_ccb->p_next_ccb) { + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci); } + break; + + default: + L2CAP_TRACE_WARNING("L2CAP - bad cmd code: %d", cmd_code); + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, + 0); + return; } + } } /******************************************************************************* @@ -760,34 +716,34 @@ static void process_l2cap_cmd (tL2C_LCB *p_lcb, uint8_t *p, uint16_t pkt_len) * Returns void * ******************************************************************************/ -void l2c_process_held_packets(bool timed_out) { - if (list_is_empty(l2cb.rcv_pending_q)) - return; - - if (!timed_out) { - alarm_cancel(l2cb.receive_hold_timer); - L2CAP_TRACE_WARNING("L2CAP HOLD CONTINUE"); - } else { - L2CAP_TRACE_WARNING("L2CAP HOLD TIMEOUT"); - } - - for (const list_node_t *node = list_begin(l2cb.rcv_pending_q); - node != list_end(l2cb.rcv_pending_q);) { - BT_HDR *p_buf = static_cast(list_node(node)); - node = list_next(node); - if (!timed_out || (!p_buf->layer_specific) || (--p_buf->layer_specific == 0)) { - list_remove(l2cb.rcv_pending_q, p_buf); - p_buf->layer_specific = 0xFFFF; - l2c_rcv_acl_data(p_buf); - } - } - - /* If anyone still in the queue, restart the timeout */ - if (!list_is_empty(l2cb.rcv_pending_q)) { - alarm_set_on_queue(l2cb.receive_hold_timer, BT_1SEC_TIMEOUT_MS, - l2c_receive_hold_timer_timeout, NULL, - btu_general_alarm_queue); +void l2c_process_held_packets(bool timed_out) { + if (list_is_empty(l2cb.rcv_pending_q)) return; + + if (!timed_out) { + alarm_cancel(l2cb.receive_hold_timer); + L2CAP_TRACE_WARNING("L2CAP HOLD CONTINUE"); + } else { + L2CAP_TRACE_WARNING("L2CAP HOLD TIMEOUT"); + } + + for (const list_node_t* node = list_begin(l2cb.rcv_pending_q); + node != list_end(l2cb.rcv_pending_q);) { + BT_HDR* p_buf = static_cast(list_node(node)); + node = list_next(node); + if (!timed_out || (!p_buf->layer_specific) || + (--p_buf->layer_specific == 0)) { + list_remove(l2cb.rcv_pending_q, p_buf); + p_buf->layer_specific = 0xFFFF; + l2c_rcv_acl_data(p_buf); } + } + + /* If anyone still in the queue, restart the timeout */ + if (!list_is_empty(l2cb.rcv_pending_q)) { + alarm_set_on_queue(l2cb.receive_hold_timer, BT_1SEC_TIMEOUT_MS, + l2c_receive_hold_timer_timeout, NULL, + btu_general_alarm_queue); + } } /******************************************************************************* @@ -800,92 +756,89 @@ void l2c_process_held_packets(bool timed_out) { * Returns void * ******************************************************************************/ -void l2c_init (void) -{ - int16_t xx; - - memset (&l2cb, 0, sizeof (tL2C_CB)); - /* the psm is increased by 2 before being used */ - l2cb.dyn_psm = 0xFFF; - - /* Put all the channel control blocks on the free queue */ - for (xx = 0; xx < MAX_L2CAP_CHANNELS - 1; xx++) - { - l2cb.ccb_pool[xx].p_next_ccb = &l2cb.ccb_pool[xx + 1]; - } +void l2c_init(void) { + int16_t xx; + + memset(&l2cb, 0, sizeof(tL2C_CB)); + /* the psm is increased by 2 before being used */ + l2cb.dyn_psm = 0xFFF; + + /* Put all the channel control blocks on the free queue */ + for (xx = 0; xx < MAX_L2CAP_CHANNELS - 1; xx++) { + l2cb.ccb_pool[xx].p_next_ccb = &l2cb.ccb_pool[xx + 1]; + } #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - /* it will be set to L2CAP_PKT_START_NON_FLUSHABLE if controller supports */ - l2cb.non_flushable_pbf = L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT; + /* it will be set to L2CAP_PKT_START_NON_FLUSHABLE if controller supports */ + l2cb.non_flushable_pbf = L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT; #endif - l2cb.p_free_ccb_first = &l2cb.ccb_pool[0]; - l2cb.p_free_ccb_last = &l2cb.ccb_pool[MAX_L2CAP_CHANNELS - 1]; + l2cb.p_free_ccb_first = &l2cb.ccb_pool[0]; + l2cb.p_free_ccb_last = &l2cb.ccb_pool[MAX_L2CAP_CHANNELS - 1]; #ifdef L2CAP_DESIRED_LINK_ROLE - l2cb.desire_role = L2CAP_DESIRED_LINK_ROLE; + l2cb.desire_role = L2CAP_DESIRED_LINK_ROLE; #else - l2cb.desire_role = HCI_ROLE_SLAVE; + l2cb.desire_role = HCI_ROLE_SLAVE; #endif - /* Set the default idle timeout */ - l2cb.idle_timeout = L2CAP_LINK_INACTIVITY_TOUT; + /* Set the default idle timeout */ + l2cb.idle_timeout = L2CAP_LINK_INACTIVITY_TOUT; #if defined(L2CAP_INITIAL_TRACE_LEVEL) - l2cb.l2cap_trace_level = L2CAP_INITIAL_TRACE_LEVEL; + l2cb.l2cap_trace_level = L2CAP_INITIAL_TRACE_LEVEL; #else - l2cb.l2cap_trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + l2cb.l2cap_trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif #if (L2CAP_CONFORMANCE_TESTING == TRUE) - /* Conformance testing needs a dynamic response */ - l2cb.test_info_resp = L2CAP_EXTFEA_SUPPORTED_MASK; + /* Conformance testing needs a dynamic response */ + l2cb.test_info_resp = L2CAP_EXTFEA_SUPPORTED_MASK; #endif - /* Number of ACL buffers to use for high priority channel */ +/* Number of ACL buffers to use for high priority channel */ #if (L2CAP_HIGH_PRI_CHAN_QUOTA_IS_CONFIGURABLE == TRUE) - l2cb.high_pri_min_xmit_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA; + l2cb.high_pri_min_xmit_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA; #endif - l2cb.l2c_ble_fixed_chnls_mask = - L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; + l2cb.l2c_ble_fixed_chnls_mask = L2CAP_FIXED_CHNL_ATT_BIT | + L2CAP_FIXED_CHNL_BLE_SIG_BIT | + L2CAP_FIXED_CHNL_SMP_BIT; - l2cb.rcv_pending_q = list_new(NULL); - if (l2cb.rcv_pending_q == NULL) - LOG_ERROR(LOG_TAG, "%s unable to allocate memory for link layer control block", __func__); - l2cb.receive_hold_timer = alarm_new("l2c.receive_hold_timer"); + l2cb.rcv_pending_q = list_new(NULL); + if (l2cb.rcv_pending_q == NULL) + LOG_ERROR(LOG_TAG, + "%s unable to allocate memory for link layer control block", + __func__); + l2cb.receive_hold_timer = alarm_new("l2c.receive_hold_timer"); } void l2c_free(void) { - list_free(l2cb.rcv_pending_q); - l2cb.rcv_pending_q = NULL; + list_free(l2cb.rcv_pending_q); + l2cb.rcv_pending_q = NULL; } -void l2c_receive_hold_timer_timeout(UNUSED_ATTR void *data) -{ - /* Update the timeouts in the hold queue */ - l2c_process_held_packets(true); +void l2c_receive_hold_timer_timeout(UNUSED_ATTR void* data) { + /* Update the timeouts in the hold queue */ + l2c_process_held_packets(true); } -void l2c_ccb_timer_timeout(void *data) -{ - tL2C_CCB *p_ccb = (tL2C_CCB *)data; +void l2c_ccb_timer_timeout(void* data) { + tL2C_CCB* p_ccb = (tL2C_CCB*)data; - l2c_csm_execute(p_ccb, L2CEVT_TIMEOUT, NULL); + l2c_csm_execute(p_ccb, L2CEVT_TIMEOUT, NULL); } -void l2c_fcrb_ack_timer_timeout(void *data) -{ - tL2C_CCB *p_ccb = (tL2C_CCB *)data; +void l2c_fcrb_ack_timer_timeout(void* data) { + tL2C_CCB* p_ccb = (tL2C_CCB*)data; - l2c_csm_execute(p_ccb, L2CEVT_ACK_TIMEOUT, NULL); + l2c_csm_execute(p_ccb, L2CEVT_ACK_TIMEOUT, NULL); } -void l2c_lcb_timer_timeout(void *data) -{ - tL2C_LCB *p_lcb = (tL2C_LCB *)data; +void l2c_lcb_timer_timeout(void* data) { + tL2C_LCB* p_lcb = (tL2C_LCB*)data; - l2c_link_timeout(p_lcb); + l2c_link_timeout(p_lcb); } /******************************************************************************* @@ -900,57 +853,54 @@ void l2c_lcb_timer_timeout(void *data) * L2CAP_DW_FAILED, if error * ******************************************************************************/ -uint8_t l2c_data_write (uint16_t cid, BT_HDR *p_data, uint16_t flags) -{ - tL2C_CCB *p_ccb; - - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_DataWrite, CID: %d", cid); - osi_free(p_data); - return (L2CAP_DW_FAILED); - } - -#ifndef TESTER /* Tester may send any amount of data. otherwise sending message +uint8_t l2c_data_write(uint16_t cid, BT_HDR* p_data, uint16_t flags) { + tL2C_CCB* p_ccb; + + /* Find the channel control block. We don't know the link it is on. */ + p_ccb = l2cu_find_ccb_by_cid(NULL, cid); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_DataWrite, CID: %d", cid); + osi_free(p_data); + return (L2CAP_DW_FAILED); + } + +#ifndef TESTER /* Tester may send any amount of data. otherwise sending \ + message \ bigger than mtu size of peer is a violation of protocol */ - uint16_t mtu; - - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - mtu = p_ccb->peer_conn_cfg.mtu; - else - mtu = p_ccb->peer_cfg.mtu; - - if (p_data->len > mtu) - { - L2CAP_TRACE_WARNING ("L2CAP - CID: 0x%04x cannot send message bigger than peer's mtu size", cid); - osi_free(p_data); - return (L2CAP_DW_FAILED); - } + uint16_t mtu; + + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) + mtu = p_ccb->peer_conn_cfg.mtu; + else + mtu = p_ccb->peer_cfg.mtu; + + if (p_data->len > mtu) { + L2CAP_TRACE_WARNING( + "L2CAP - CID: 0x%04x cannot send message bigger than peer's mtu size", + cid); + osi_free(p_data); + return (L2CAP_DW_FAILED); + } #endif - /* channel based, packet based flushable or non-flushable */ - p_data->layer_specific = flags; + /* channel based, packet based flushable or non-flushable */ + p_data->layer_specific = flags; - /* If already congested, do not accept any more packets */ - if (p_ccb->cong_sent) - { - L2CAP_TRACE_ERROR ("L2CAP - CID: 0x%04x cannot send, already congested xmit_hold_q.count: %u buff_quota: %u", - p_ccb->local_cid, - fixed_queue_length(p_ccb->xmit_hold_q), - p_ccb->buff_quota); - - osi_free(p_data); - return (L2CAP_DW_FAILED); - } + /* If already congested, do not accept any more packets */ + if (p_ccb->cong_sent) { + L2CAP_TRACE_ERROR( + "L2CAP - CID: 0x%04x cannot send, already congested " + "xmit_hold_q.count: %u buff_quota: %u", + p_ccb->local_cid, fixed_queue_length(p_ccb->xmit_hold_q), + p_ccb->buff_quota); + osi_free(p_data); + return (L2CAP_DW_FAILED); + } - l2c_csm_execute (p_ccb, L2CEVT_L2CA_DATA_WRITE, p_data); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DATA_WRITE, p_data); - if (p_ccb->cong_sent) - return (L2CAP_DW_CONGESTED); + if (p_ccb->cong_sent) return (L2CAP_DW_CONGESTED); - return (L2CAP_DW_SUCCESS); + return (L2CAP_DW_SUCCESS); } - diff --git a/stack/l2cap/l2c_ucd.cc b/stack/l2cap/l2c_ucd.cc index 90d8e86e2..7648cfe13 100644 --- a/stack/l2cap/l2c_ucd.cc +++ b/stack/l2cap/l2c_ucd.cc @@ -22,25 +22,25 @@ * ******************************************************************************/ +#include #include #include -#include #include "bt_common.h" #include "bt_types.h" +#include "btm_api.h" +#include "btm_int.h" +#include "btu.h" #include "hcidefs.h" #include "hcimsgs.h" -#include "l2cdefs.h" #include "l2c_int.h" -#include "btu.h" -#include "btm_api.h" -#include "btm_int.h" +#include "l2cdefs.h" #if (L2CAP_UCD_INCLUDED == TRUE) -extern fixed_queue_t *btu_bta_alarm_queue; +extern fixed_queue_t* btu_bta_alarm_queue; -static bool l2c_ucd_connect ( BD_ADDR rem_bda ); +static bool l2c_ucd_connect(BD_ADDR rem_bda); /******************************************************************************* * @@ -51,34 +51,30 @@ static bool l2c_ucd_connect ( BD_ADDR rem_bda ); * Returns void * ******************************************************************************/ -static void l2c_ucd_discover_cback (BD_ADDR rem_bda, uint8_t info_type, uint32_t data) -{ - tL2C_RCB *p_rcb = &l2cb.rcb_pool[0]; - uint16_t xx; - - L2CAP_TRACE_DEBUG ("L2CAP - l2c_ucd_discover_cback"); - - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if (p_rcb->in_use) - { - /* if this application is waiting UCD reception info */ - if (( info_type == L2CAP_UCD_INFO_TYPE_RECEPTION ) - && ( p_rcb->ucd.state & L2C_UCD_STATE_W4_RECEPTION )) - { - p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb (rem_bda, info_type, data); - p_rcb->ucd.state &= ~(L2C_UCD_STATE_W4_RECEPTION); - } - - /* if this application is waiting UCD MTU info */ - if (( info_type == L2CAP_UCD_INFO_TYPE_MTU ) - && ( p_rcb->ucd.state & L2C_UCD_STATE_W4_MTU )) - { - p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb (rem_bda, info_type, data); - p_rcb->ucd.state &= ~(L2C_UCD_STATE_W4_MTU); - } - } +static void l2c_ucd_discover_cback(BD_ADDR rem_bda, uint8_t info_type, + uint32_t data) { + tL2C_RCB* p_rcb = &l2cb.rcb_pool[0]; + uint16_t xx; + + L2CAP_TRACE_DEBUG("L2CAP - l2c_ucd_discover_cback"); + + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if (p_rcb->in_use) { + /* if this application is waiting UCD reception info */ + if ((info_type == L2CAP_UCD_INFO_TYPE_RECEPTION) && + (p_rcb->ucd.state & L2C_UCD_STATE_W4_RECEPTION)) { + p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb(rem_bda, info_type, data); + p_rcb->ucd.state &= ~(L2C_UCD_STATE_W4_RECEPTION); + } + + /* if this application is waiting UCD MTU info */ + if ((info_type == L2CAP_UCD_INFO_TYPE_MTU) && + (p_rcb->ucd.state & L2C_UCD_STATE_W4_MTU)) { + p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb(rem_bda, info_type, data); + p_rcb->ucd.state &= ~(L2C_UCD_STATE_W4_MTU); + } } + } } /******************************************************************************* @@ -90,30 +86,27 @@ static void l2c_ucd_discover_cback (BD_ADDR rem_bda, uint8_t info_type, uint32_t * Returns void * ******************************************************************************/ -static void l2c_ucd_data_ind_cback (BD_ADDR rem_bda, BT_HDR *p_buf) -{ - uint8_t *p; - uint16_t psm; - tL2C_RCB *p_rcb; +static void l2c_ucd_data_ind_cback(BD_ADDR rem_bda, BT_HDR* p_buf) { + uint8_t* p; + uint16_t psm; + tL2C_RCB* p_rcb; - L2CAP_TRACE_DEBUG ("L2CAP - l2c_ucd_data_ind_cback"); + L2CAP_TRACE_DEBUG("L2CAP - l2c_ucd_data_ind_cback"); - p = (uint8_t *)(p_buf + 1) + p_buf->offset; - STREAM_TO_UINT16(psm, p) + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + STREAM_TO_UINT16(psm, p) - p_buf->offset += L2CAP_UCD_OVERHEAD; - p_buf->len -= L2CAP_UCD_OVERHEAD; + p_buf->offset += L2CAP_UCD_OVERHEAD; + p_buf->len -= L2CAP_UCD_OVERHEAD; - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - no RCB for l2c_ucd_data_ind_cback, PSM: 0x%04x", psm); - osi_free(p_buf); - } - else - { - p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(rem_bda, p_buf); - } + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - no RCB for l2c_ucd_data_ind_cback, PSM: 0x%04x", + psm); + osi_free(p_buf); + } else { + p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(rem_bda, p_buf); + } } /******************************************************************************* @@ -125,29 +118,28 @@ static void l2c_ucd_data_ind_cback (BD_ADDR rem_bda, BT_HDR *p_buf) * Returns void * ******************************************************************************/ -static void l2c_ucd_congestion_status_cback (BD_ADDR rem_bda, bool is_congested) -{ - tL2C_RCB *p_rcb = &l2cb.rcb_pool[0]; - uint16_t xx; - - L2CAP_TRACE_DEBUG ("L2CAP - l2c_ucd_congestion_status_cback"); - - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if (( p_rcb->in_use ) - &&( p_rcb->ucd.state != L2C_UCD_STATE_UNUSED )) - { - if ( p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ) - { - L2CAP_TRACE_DEBUG ("L2CAP - Calling UCDCongestionStatus_Cb (%d), PSM=0x%04x, BDA: %08x%04x,", - is_congested, p_rcb->psm, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - - p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ( rem_bda, is_congested ); - } - } +static void l2c_ucd_congestion_status_cback(BD_ADDR rem_bda, + bool is_congested) { + tL2C_RCB* p_rcb = &l2cb.rcb_pool[0]; + uint16_t xx; + + L2CAP_TRACE_DEBUG("L2CAP - l2c_ucd_congestion_status_cback"); + + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if ((p_rcb->in_use) && (p_rcb->ucd.state != L2C_UCD_STATE_UNUSED)) { + if (p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb) { + L2CAP_TRACE_DEBUG( + "L2CAP - Calling UCDCongestionStatus_Cb (%d), PSM=0x%04x, BDA: " + "%08x%04x,", + is_congested, p_rcb->psm, (rem_bda[0] << 24) + (rem_bda[1] << 16) + + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb(rem_bda, + is_congested); + } } + } } /******************************************************************************* @@ -159,9 +151,8 @@ static void l2c_ucd_congestion_status_cback (BD_ADDR rem_bda, bool is_congest * Returns void * ******************************************************************************/ -static void l2c_ucd_disconnect_ind_cback (uint16_t cid, bool result) -{ - /* do nothing */ +static void l2c_ucd_disconnect_ind_cback(uint16_t cid, bool result) { + /* do nothing */ } /******************************************************************************* @@ -173,9 +164,8 @@ static void l2c_ucd_disconnect_ind_cback (uint16_t cid, bool result) * Returns void * ******************************************************************************/ -static void l2c_ucd_config_ind_cback (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) -{ - /* do nothing */ +static void l2c_ucd_config_ind_cback(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { + /* do nothing */ } /******************************************************************************* @@ -187,9 +177,8 @@ static void l2c_ucd_config_ind_cback (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void l2c_ucd_config_cfm_cback (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) -{ - /* do nothing */ +static void l2c_ucd_config_cfm_cback(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { + /* do nothing */ } /******************************************************************************* @@ -203,59 +192,53 @@ static void l2c_ucd_config_cfm_cback (uint16_t cid, tL2CAP_CFG_INFO *p_cfg) * Return value: true if successs * ******************************************************************************/ -bool L2CA_UcdRegister ( uint16_t psm, tL2CAP_UCD_CB_INFO *p_cb_info ) -{ - tL2C_RCB *p_rcb; +bool L2CA_UcdRegister(uint16_t psm, tL2CAP_UCD_CB_INFO* p_cb_info) { + tL2C_RCB* p_rcb; - L2CAP_TRACE_API ("L2CA_UcdRegister() PSM: 0x%04x", psm); + L2CAP_TRACE_API("L2CA_UcdRegister() PSM: 0x%04x", psm); - if ((!p_cb_info->pL2CA_UCD_Discover_Cb) - || (!p_cb_info->pL2CA_UCD_Data_Cb)) - { - L2CAP_TRACE_ERROR ("L2CAP - no callback registering PSM(0x%04x) on UCD", psm); - return (false); - } - - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - no RCB for L2CA_UcdRegister, PSM: 0x%04x", psm); - return (false); - } + if ((!p_cb_info->pL2CA_UCD_Discover_Cb) || (!p_cb_info->pL2CA_UCD_Data_Cb)) { + L2CAP_TRACE_ERROR("L2CAP - no callback registering PSM(0x%04x) on UCD", + psm); + return (false); + } - p_rcb->ucd.state = L2C_UCD_STATE_W4_DATA; - p_rcb->ucd.cb_info = *p_cb_info; - - /* check if master rcb is created for UCD */ - p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); - if (p_rcb == NULL) - { - p_rcb = l2cu_allocate_rcb(L2C_UCD_RCB_ID); - if (p_rcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - no RCB available for L2CA_UcdRegister"); - return (false); - } - else - { - /* these callback functions will forward data to each UCD application */ - p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb = l2c_ucd_discover_cback; - p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb = l2c_ucd_data_ind_cback; - p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb = l2c_ucd_congestion_status_cback; - - memset (&p_rcb->api, 0, sizeof(tL2CAP_APPL_INFO)); - p_rcb->api.pL2CA_DisconnectInd_Cb = l2c_ucd_disconnect_ind_cback; - - /* This will make L2CAP check UCD congestion callback */ - p_rcb->api.pL2CA_CongestionStatus_Cb = NULL; - - /* do nothing but prevent crash */ - p_rcb->api.pL2CA_ConfigInd_Cb = l2c_ucd_config_ind_cback; - p_rcb->api.pL2CA_ConfigCfm_Cb = l2c_ucd_config_cfm_cback; - } + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - no RCB for L2CA_UcdRegister, PSM: 0x%04x", psm); + return (false); + } + + p_rcb->ucd.state = L2C_UCD_STATE_W4_DATA; + p_rcb->ucd.cb_info = *p_cb_info; + + /* check if master rcb is created for UCD */ + p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); + if (p_rcb == NULL) { + p_rcb = l2cu_allocate_rcb(L2C_UCD_RCB_ID); + if (p_rcb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - no RCB available for L2CA_UcdRegister"); + return (false); + } else { + /* these callback functions will forward data to each UCD application */ + p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb = l2c_ucd_discover_cback; + p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb = l2c_ucd_data_ind_cback; + p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb = + l2c_ucd_congestion_status_cback; + + memset(&p_rcb->api, 0, sizeof(tL2CAP_APPL_INFO)); + p_rcb->api.pL2CA_DisconnectInd_Cb = l2c_ucd_disconnect_ind_cback; + + /* This will make L2CAP check UCD congestion callback */ + p_rcb->api.pL2CA_CongestionStatus_Cb = NULL; + + /* do nothing but prevent crash */ + p_rcb->api.pL2CA_ConfigInd_Cb = l2c_ucd_config_ind_cback; + p_rcb->api.pL2CA_ConfigCfm_Cb = l2c_ucd_config_cfm_cback; } + } - return (true); + return (true); } /******************************************************************************* @@ -269,52 +252,46 @@ bool L2CA_UcdRegister ( uint16_t psm, tL2CAP_UCD_CB_INFO *p_cb_info ) * Return value: true if successs * ******************************************************************************/ -bool L2CA_UcdDeregister ( uint16_t psm ) -{ - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - uint16_t xx; - - L2CAP_TRACE_API ("L2CA_UcdDeregister() PSM: 0x%04x", psm); - - p_rcb = l2cu_find_rcb_by_psm(psm); - if (p_rcb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - no RCB for L2CA_UcdDeregister, PSM: 0x%04x", psm); - return (false); - } +bool L2CA_UcdDeregister(uint16_t psm) { + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + uint16_t xx; - p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; + L2CAP_TRACE_API("L2CA_UcdDeregister() PSM: 0x%04x", psm); - /* check this was the last UCD registration */ - p_rcb = &l2cb.rcb_pool[0]; + p_rcb = l2cu_find_rcb_by_psm(psm); + if (p_rcb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - no RCB for L2CA_UcdDeregister, PSM: 0x%04x", + psm); + return (false); + } - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if ((p_rcb->in_use) && (p_rcb->ucd.state != L2C_UCD_STATE_UNUSED)) - return (true); - } + p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; - /* delete master rcb for UCD */ - p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); - if (p_rcb != NULL) - { - l2cu_release_rcb (p_rcb); - } + /* check this was the last UCD registration */ + p_rcb = &l2cb.rcb_pool[0]; - /* delete CCB for UCD */ - p_ccb = l2cb.ccb_pool; - for ( xx = 0; xx < MAX_L2CAP_CHANNELS; xx++ ) - { - if (( p_ccb->in_use ) - &&( p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID )) - { - l2cu_release_ccb (p_ccb); - } - p_ccb++; + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if ((p_rcb->in_use) && (p_rcb->ucd.state != L2C_UCD_STATE_UNUSED)) + return (true); + } + + /* delete master rcb for UCD */ + p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); + if (p_rcb != NULL) { + l2cu_release_rcb(p_rcb); + } + + /* delete CCB for UCD */ + p_ccb = l2cb.ccb_pool; + for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) { + if ((p_ccb->in_use) && (p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID)) { + l2cu_release_ccb(p_ccb); } + p_ccb++; + } - return (true); + return (true); } /******************************************************************************* @@ -332,53 +309,51 @@ bool L2CA_UcdDeregister ( uint16_t psm ) * Return value: true if successs * ******************************************************************************/ -bool L2CA_UcdDiscover ( uint16_t psm, BD_ADDR rem_bda, uint8_t info_type ) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - - L2CAP_TRACE_API ("L2CA_UcdDiscover() PSM: 0x%04x BDA: %08x%04x, InfoType=0x%02x", psm, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5], info_type); - - /* Fail if the PSM is not registered */ - if (((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) - ||( p_rcb->ucd.state == L2C_UCD_STATE_UNUSED )) - { - L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_UcdDiscover, PSM: 0x%04x", psm); - return (false); - } - - /* First, see if we already have a link to the remote */ - /* then find the channel control block for UCD. */ - if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) - ||((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) - { - if ( l2c_ucd_connect (rem_bda) == false ) - { - return (false); - } +bool L2CA_UcdDiscover(uint16_t psm, BD_ADDR rem_bda, uint8_t info_type) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + + L2CAP_TRACE_API( + "L2CA_UcdDiscover() PSM: 0x%04x BDA: %08x%04x, InfoType=0x%02x", psm, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5], info_type); + + /* Fail if the PSM is not registered */ + if (((p_rcb = l2cu_find_rcb_by_psm(psm)) == NULL) || + (p_rcb->ucd.state == L2C_UCD_STATE_UNUSED)) { + L2CAP_TRACE_WARNING("L2CAP - no RCB for L2CA_UcdDiscover, PSM: 0x%04x", + psm); + return (false); + } + + /* First, see if we already have a link to the remote */ + /* then find the channel control block for UCD. */ + if (((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR)) == + NULL) || + ((p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID)) == + NULL)) { + if (l2c_ucd_connect(rem_bda) == false) { + return (false); } + } - /* set waiting flags in rcb */ + /* set waiting flags in rcb */ - if ( info_type & L2CAP_UCD_INFO_TYPE_RECEPTION ) - p_rcb->ucd.state |= L2C_UCD_STATE_W4_RECEPTION; + if (info_type & L2CAP_UCD_INFO_TYPE_RECEPTION) + p_rcb->ucd.state |= L2C_UCD_STATE_W4_RECEPTION; - if ( info_type & L2CAP_UCD_INFO_TYPE_MTU ) - p_rcb->ucd.state |= L2C_UCD_STATE_W4_MTU; + if (info_type & L2CAP_UCD_INFO_TYPE_MTU) + p_rcb->ucd.state |= L2C_UCD_STATE_W4_MTU; - /* if link is already established */ - if ((p_lcb)&&(p_lcb->link_state == LST_CONNECTED)) - { - if (!p_ccb) - { - p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID); - } - l2c_ucd_check_pending_info_req(p_ccb); + /* if link is already established */ + if ((p_lcb) && (p_lcb->link_state == LST_CONNECTED)) { + if (!p_ccb) { + p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID); } - return (true); + l2c_ucd_check_pending_info_req(p_ccb); + } + return (true); } /******************************************************************************* @@ -398,83 +373,88 @@ bool L2CA_UcdDiscover ( uint16_t psm, BD_ADDR rem_bda, uint8_t info_type ) * L2CAP_DW_FAILED, if error * ******************************************************************************/ -uint16_t L2CA_UcdDataWrite (uint16_t psm, BD_ADDR rem_bda, BT_HDR *p_buf, uint16_t flags) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - uint8_t *p; - - L2CAP_TRACE_API ("L2CA_UcdDataWrite() PSM: 0x%04x BDA: %08x%04x", psm, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - - /* Fail if the PSM is not registered */ - if (((p_rcb = l2cu_find_rcb_by_psm (psm)) == NULL) - ||( p_rcb->ucd.state == L2C_UCD_STATE_UNUSED )) - { - L2CAP_TRACE_WARNING ("L2CAP - no RCB for L2CA_UcdDataWrite, PSM: 0x%04x", psm); - osi_free(p_buf); - return (L2CAP_DW_FAILED); +uint16_t L2CA_UcdDataWrite(uint16_t psm, BD_ADDR rem_bda, BT_HDR* p_buf, + uint16_t flags) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + uint8_t* p; + + L2CAP_TRACE_API( + "L2CA_UcdDataWrite() PSM: 0x%04x BDA: %08x%04x", psm, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + /* Fail if the PSM is not registered */ + if (((p_rcb = l2cu_find_rcb_by_psm(psm)) == NULL) || + (p_rcb->ucd.state == L2C_UCD_STATE_UNUSED)) { + L2CAP_TRACE_WARNING("L2CAP - no RCB for L2CA_UcdDataWrite, PSM: 0x%04x", + psm); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } + + /* First, see if we already have a link to the remote */ + /* then find the channel control block for UCD */ + if (((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR)) == + NULL) || + ((p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID)) == + NULL)) { + if (l2c_ucd_connect(rem_bda) == false) { + osi_free(p_buf); + return (L2CAP_DW_FAILED); } - /* First, see if we already have a link to the remote */ - /* then find the channel control block for UCD */ - if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) - ||((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) - { - if ( l2c_ucd_connect (rem_bda) == false ) - { - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } - - /* If we still don't have lcb and ccb after connect attempt, then can't proceed */ - if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) - || ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) - { - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + /* If we still don't have lcb and ccb after connect attempt, then can't + * proceed */ + if (((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR)) == + NULL) || + ((p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID)) == + NULL)) { + osi_free(p_buf); + return (L2CAP_DW_FAILED); } + } - /* write PSM */ - p_buf->offset -= L2CAP_UCD_OVERHEAD; - p_buf->len += L2CAP_UCD_OVERHEAD; - p = (uint8_t *)(p_buf + 1) + p_buf->offset; + /* write PSM */ + p_buf->offset -= L2CAP_UCD_OVERHEAD; + p_buf->len += L2CAP_UCD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + p_buf->offset; - UINT16_TO_STREAM (p, psm); + UINT16_TO_STREAM(p, psm); - /* UCD MTU check */ - if ((p_lcb->ucd_mtu) && (p_buf->len > p_lcb->ucd_mtu)) - { - L2CAP_TRACE_WARNING ("L2CAP - Handle: 0x%04x UCD bigger than peer's UCD mtu size cannot be sent", p_lcb->handle); - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + /* UCD MTU check */ + if ((p_lcb->ucd_mtu) && (p_buf->len > p_lcb->ucd_mtu)) { + L2CAP_TRACE_WARNING( + "L2CAP - Handle: 0x%04x UCD bigger than peer's UCD mtu size cannot be " + "sent", + p_lcb->handle); + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } + + /* If already congested, do not accept any more packets */ + if (p_ccb->cong_sent) { + L2CAP_TRACE_ERROR( + "L2CAP - Handle: 0x%04x UCD cannot be sent, already congested count: " + "%u buff_quota: %u", + p_lcb->handle, (fixed_queue_length(p_ccb->xmit_hold_q) + + fixed_queue_length(p_lcb->ucd_out_sec_pending_q)), + p_ccb->buff_quota); - /* If already congested, do not accept any more packets */ - if (p_ccb->cong_sent) - { - L2CAP_TRACE_ERROR ("L2CAP - Handle: 0x%04x UCD cannot be sent, already congested count: %u buff_quota: %u", - p_lcb->handle, - (fixed_queue_length(p_ccb->xmit_hold_q) + - fixed_queue_length(p_lcb->ucd_out_sec_pending_q)), - p_ccb->buff_quota); - - osi_free(p_buf); - return (L2CAP_DW_FAILED); - } + osi_free(p_buf); + return (L2CAP_DW_FAILED); + } - /* channel based, packet based flushable or non-flushable */ - p_buf->layer_specific = flags; + /* channel based, packet based flushable or non-flushable */ + p_buf->layer_specific = flags; - l2c_csm_execute (p_ccb, L2CEVT_L2CA_DATA_WRITE, p_buf); + l2c_csm_execute(p_ccb, L2CEVT_L2CA_DATA_WRITE, p_buf); - if (p_ccb->cong_sent) - return (L2CAP_DW_CONGESTED); - else - return (L2CAP_DW_SUCCESS); + if (p_ccb->cong_sent) + return (L2CAP_DW_CONGESTED); + else + return (L2CAP_DW_SUCCESS); } /******************************************************************************* @@ -489,28 +469,27 @@ uint16_t L2CA_UcdDataWrite (uint16_t psm, BD_ADDR rem_bda, BT_HDR *p_buf, uint16 * Return value: true if successs * ******************************************************************************/ -bool L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, uint16_t timeout ) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_UcdSetIdleTimeout() Timeout: 0x%04x BDA: %08x%04x", timeout, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - - /* First, see if we already have a link to the remote */ - /* then find the channel control block. */ - if (((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_BR_EDR)) == NULL) - ||((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) == NULL)) - { - L2CAP_TRACE_WARNING ("L2CAP - no UCD channel"); - return (false); - } - else - { - p_ccb->fixed_chnl_idle_tout = timeout; - return (true); - } +bool L2CA_UcdSetIdleTimeout(BD_ADDR rem_bda, uint16_t timeout) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_UcdSetIdleTimeout() Timeout: 0x%04x BDA: %08x%04x", timeout, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + /* First, see if we already have a link to the remote */ + /* then find the channel control block. */ + if (((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR)) == + NULL) || + ((p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID)) == + NULL)) { + L2CAP_TRACE_WARNING("L2CAP - no UCD channel"); + return (false); + } else { + p_ccb->fixed_chnl_idle_tout = timeout; + return (true); + } } /******************************************************************************* @@ -522,34 +501,33 @@ bool L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, uint16_t timeout ) * Returns true if a valid channel, else false * ******************************************************************************/ -bool L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority ) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - - L2CAP_TRACE_API ("L2CA_UCDSetTxPriority() priority: 0x%02x BDA: %08x%04x", priority, - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - - p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_UCDSetTxPriority"); - return (false); - } +bool L2CA_UCDSetTxPriority(BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + + L2CAP_TRACE_API( + "L2CA_UCDSetTxPriority() priority: 0x%02x BDA: %08x%04x", priority, + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no LCB for L2CA_UCDSetTxPriority"); + return (false); + } - /* Find the channel control block */ - p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for L2CA_UCDSetTxPriority"); - return (false); - } + /* Find the channel control block */ + p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_UCDSetTxPriority"); + return (false); + } - /* it will update the order of CCB in LCB by priority and update round robin service variables */ - l2cu_change_pri_ccb (p_ccb, priority); + /* it will update the order of CCB in LCB by priority and update round robin + * service variables */ + l2cu_change_pri_ccb(p_ccb, priority); - return (true); + return (true); } /******************************************************************************* @@ -563,85 +541,75 @@ bool L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority ) * Return value: true if successs * ******************************************************************************/ -static bool l2c_ucd_connect ( BD_ADDR rem_bda ) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - - L2CAP_TRACE_DEBUG ("l2c_ucd_connect() BDA: %08x%04x", - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], - (rem_bda[4]<<8)+rem_bda[5]); - - /* Fail if we have not established communications with the controller */ - if (!BTM_IsDeviceUp()) - { - L2CAP_TRACE_WARNING ("l2c_ucd_connect - BTU not ready"); - return (false); - } - - /* First, see if we already have a link to the remote */ - p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - /* No link. Get an LCB and start link establishment */ - if ( ((p_lcb = l2cu_allocate_lcb (rem_bda, false, BT_TRANSPORT_BR_EDR)) == NULL) - || (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false) ) - { - L2CAP_TRACE_WARNING ("L2CAP - conn not started l2c_ucd_connect"); - return (false); - } +static bool l2c_ucd_connect(BD_ADDR rem_bda) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + + L2CAP_TRACE_DEBUG( + "l2c_ucd_connect() BDA: %08x%04x", + (rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], + (rem_bda[4] << 8) + rem_bda[5]); + + /* Fail if we have not established communications with the controller */ + if (!BTM_IsDeviceUp()) { + L2CAP_TRACE_WARNING("l2c_ucd_connect - BTU not ready"); + return (false); + } + + /* First, see if we already have a link to the remote */ + p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + /* No link. Get an LCB and start link establishment */ + if (((p_lcb = l2cu_allocate_lcb(rem_bda, false, BT_TRANSPORT_BR_EDR)) == + NULL) || + (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false)) { + L2CAP_TRACE_WARNING("L2CAP - conn not started l2c_ucd_connect"); + return (false); } - else if ( p_lcb->info_rx_bits & (1 << L2CAP_EXTENDED_FEATURES_INFO_TYPE) ) - { - if (!(p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION)) - { - L2CAP_TRACE_WARNING ("L2CAP - UCD is not supported by peer, l2c_ucd_connect"); - return (false); - } + } else if (p_lcb->info_rx_bits & (1 << L2CAP_EXTENDED_FEATURES_INFO_TYPE)) { + if (!(p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION)) { + L2CAP_TRACE_WARNING( + "L2CAP - UCD is not supported by peer, l2c_ucd_connect"); + return (false); } - - /* Find the channel control block. */ - p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID); - if (p_ccb == NULL) - { - /* Allocate a channel control block */ - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for l2c_ucd_connect"); - return (false); - } - else - { - /* Set CID for the connection */ - p_ccb->local_cid = L2CAP_CONNECTIONLESS_CID; - p_ccb->remote_cid = L2CAP_CONNECTIONLESS_CID; - - /* Set the default idle timeout value to use */ - p_ccb->fixed_chnl_idle_tout = L2CAP_UCD_IDLE_TIMEOUT; - - /* Set the default channel priority value to use */ - l2cu_change_pri_ccb (p_ccb, L2CAP_UCD_CH_PRIORITY); - - p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); - if (p_rcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no UCD registered, l2c_ucd_connect"); - return (false); - } - /* Save UCD registration info */ - p_ccb->p_rcb = p_rcb; - - /* There is no configuration, so if the link is up, the channel is up */ - if (p_lcb->link_state == LST_CONNECTED) - { - p_ccb->chnl_state = CST_OPEN; - } - } + } + + /* Find the channel control block. */ + p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID); + if (p_ccb == NULL) { + /* Allocate a channel control block */ + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for l2c_ucd_connect"); + return (false); + } else { + /* Set CID for the connection */ + p_ccb->local_cid = L2CAP_CONNECTIONLESS_CID; + p_ccb->remote_cid = L2CAP_CONNECTIONLESS_CID; + + /* Set the default idle timeout value to use */ + p_ccb->fixed_chnl_idle_tout = L2CAP_UCD_IDLE_TIMEOUT; + + /* Set the default channel priority value to use */ + l2cu_change_pri_ccb(p_ccb, L2CAP_UCD_CH_PRIORITY); + + p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID); + if (p_rcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no UCD registered, l2c_ucd_connect"); + return (false); + } + /* Save UCD registration info */ + p_ccb->p_rcb = p_rcb; + + /* There is no configuration, so if the link is up, the channel is up */ + if (p_lcb->link_state == LST_CONNECTED) { + p_ccb->chnl_state = CST_OPEN; + } } + } - return (true); + return (true); } /******************************************************************************* @@ -653,18 +621,17 @@ static bool l2c_ucd_connect ( BD_ADDR rem_bda ) * Returns None * ******************************************************************************/ -void l2c_ucd_delete_sec_pending_q(tL2C_LCB *p_lcb) -{ - /* clean up any security pending UCD */ - while (! fixed_queue_is_empty(p_lcb->ucd_out_sec_pending_q)) - osi_free(fixed_queue_try_dequeue(p_lcb->ucd_out_sec_pending_q)); - fixed_queue_free(p_lcb->ucd_out_sec_pending_q, NULL); - p_lcb->ucd_out_sec_pending_q = NULL; - - while (! fixed_queue_is_empty(p_lcb->ucd_in_sec_pending_q)) - osi_free(fixed_queue_try_dequeue(p_lcb->ucd_in_sec_pending_q)); - fixed_queue_free(p_lcb->ucd_in_sec_pending_q); - p_lcb->ucd_in_sec_pending_q = NULL; +void l2c_ucd_delete_sec_pending_q(tL2C_LCB* p_lcb) { + /* clean up any security pending UCD */ + while (!fixed_queue_is_empty(p_lcb->ucd_out_sec_pending_q)) + osi_free(fixed_queue_try_dequeue(p_lcb->ucd_out_sec_pending_q)); + fixed_queue_free(p_lcb->ucd_out_sec_pending_q, NULL); + p_lcb->ucd_out_sec_pending_q = NULL; + + while (!fixed_queue_is_empty(p_lcb->ucd_in_sec_pending_q)) + osi_free(fixed_queue_try_dequeue(p_lcb->ucd_in_sec_pending_q)); + fixed_queue_free(p_lcb->ucd_in_sec_pending_q); + p_lcb->ucd_in_sec_pending_q = NULL; } /******************************************************************************* @@ -676,72 +643,61 @@ void l2c_ucd_delete_sec_pending_q(tL2C_LCB *p_lcb) * Return true if any pending UCD info request * ******************************************************************************/ -bool l2c_ucd_check_pending_info_req(tL2C_CCB *p_ccb) -{ - tL2C_RCB *p_rcb = &l2cb.rcb_pool[0]; - uint16_t xx; - bool pending = false; - - if (p_ccb == NULL) - { - L2CAP_TRACE_ERROR ("L2CAP - NULL p_ccb in l2c_ucd_check_pending_info_req"); - return (false); - } - - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if (p_rcb->in_use) - { - /* if application is waiting UCD reception info */ - if (p_rcb->ucd.state & L2C_UCD_STATE_W4_RECEPTION) - { - /* if this information is available */ - if ( p_ccb->p_lcb->info_rx_bits & (1 << L2CAP_EXTENDED_FEATURES_INFO_TYPE) ) - { - if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION)) - { - L2CAP_TRACE_WARNING ("L2CAP - UCD is not supported by peer, l2c_ucd_check_pending_info_req"); - - l2c_ucd_delete_sec_pending_q(p_ccb->p_lcb); - l2cu_release_ccb (p_ccb); - } - - p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb (p_ccb->p_lcb->remote_bd_addr, - L2CAP_UCD_INFO_TYPE_RECEPTION, - p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION); - } - else - { - pending = true; - if (p_ccb->p_lcb->w4_info_rsp == false) - { - l2cu_send_peer_info_req (p_ccb->p_lcb, L2CAP_EXTENDED_FEATURES_INFO_TYPE); - } - } - } +bool l2c_ucd_check_pending_info_req(tL2C_CCB* p_ccb) { + tL2C_RCB* p_rcb = &l2cb.rcb_pool[0]; + uint16_t xx; + bool pending = false; - /* if application is waiting for UCD MTU */ - if (p_rcb->ucd.state & L2C_UCD_STATE_W4_MTU) - { - /* if this information is available */ - if ( p_ccb->p_lcb->info_rx_bits & (1 << L2CAP_CONNLESS_MTU_INFO_TYPE)) - { - p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb (p_ccb->p_lcb->remote_bd_addr, - L2CAP_UCD_INFO_TYPE_MTU, - p_ccb->p_lcb->ucd_mtu); - } - else - { - pending = true; - if (p_ccb->p_lcb->w4_info_rsp == false) - { - l2cu_send_peer_info_req (p_ccb->p_lcb, L2CAP_CONNLESS_MTU_INFO_TYPE); - } - } - } + if (p_ccb == NULL) { + L2CAP_TRACE_ERROR("L2CAP - NULL p_ccb in l2c_ucd_check_pending_info_req"); + return (false); + } + + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if (p_rcb->in_use) { + /* if application is waiting UCD reception info */ + if (p_rcb->ucd.state & L2C_UCD_STATE_W4_RECEPTION) { + /* if this information is available */ + if (p_ccb->p_lcb->info_rx_bits & + (1 << L2CAP_EXTENDED_FEATURES_INFO_TYPE)) { + if (!(p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION)) { + L2CAP_TRACE_WARNING( + "L2CAP - UCD is not supported by peer, " + "l2c_ucd_check_pending_info_req"); + + l2c_ucd_delete_sec_pending_q(p_ccb->p_lcb); + l2cu_release_ccb(p_ccb); + } + + p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb( + p_ccb->p_lcb->remote_bd_addr, L2CAP_UCD_INFO_TYPE_RECEPTION, + p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_UCD_RECEPTION); + } else { + pending = true; + if (p_ccb->p_lcb->w4_info_rsp == false) { + l2cu_send_peer_info_req(p_ccb->p_lcb, + L2CAP_EXTENDED_FEATURES_INFO_TYPE); + } + } + } + + /* if application is waiting for UCD MTU */ + if (p_rcb->ucd.state & L2C_UCD_STATE_W4_MTU) { + /* if this information is available */ + if (p_ccb->p_lcb->info_rx_bits & (1 << L2CAP_CONNLESS_MTU_INFO_TYPE)) { + p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Discover_Cb( + p_ccb->p_lcb->remote_bd_addr, L2CAP_UCD_INFO_TYPE_MTU, + p_ccb->p_lcb->ucd_mtu); + } else { + pending = true; + if (p_ccb->p_lcb->w4_info_rsp == false) { + l2cu_send_peer_info_req(p_ccb->p_lcb, L2CAP_CONNLESS_MTU_INFO_TYPE); + } } + } } - return (pending); + } + return (pending); } /******************************************************************************* @@ -754,10 +710,9 @@ bool l2c_ucd_check_pending_info_req(tL2C_CCB *p_ccb) * Return None * ******************************************************************************/ -void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB *p_ccb, void *p_data) -{ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_out_sec_pending_q, p_data); - l2cu_check_channel_congestion (p_ccb); +void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB* p_ccb, void* p_data) { + fixed_queue_enqueue(p_ccb->p_lcb->ucd_out_sec_pending_q, p_data); + l2cu_check_channel_congestion(p_ccb); } /******************************************************************************* @@ -769,24 +724,24 @@ void l2c_ucd_enqueue_pending_out_sec_q(tL2C_CCB *p_ccb, void *p_data) * Return true if any UCD packet for security * ******************************************************************************/ -bool l2c_ucd_check_pending_out_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_peek_first(p_ccb->p_lcb->ucd_out_sec_pending_q); +bool l2c_ucd_check_pending_out_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_peek_first(p_ccb->p_lcb->ucd_out_sec_pending_q); - if (p_buf != NULL) - { - uint16_t psm; - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; + if (p_buf != NULL) { + uint16_t psm; + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; - STREAM_TO_UINT16(psm, p) + STREAM_TO_UINT16(psm, p) - p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; - btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, psm, - p_ccb->p_lcb->handle, CONNLESS_ORIG, &l2c_link_sec_comp, p_ccb); + p_ccb->chnl_state = CST_ORIG_W4_SEC_COMP; + btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, psm, + p_ccb->p_lcb->handle, CONNLESS_ORIG, + &l2c_link_sec_comp, p_ccb); - return (true); - } - return (false); + return (true); + } + return (false); } /******************************************************************************* @@ -799,15 +754,14 @@ bool l2c_ucd_check_pending_out_sec_q(tL2C_CCB *p_ccb) * Return None * ******************************************************************************/ -void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); - - if (p_buf != NULL) - { - l2c_enqueue_peer_data (p_ccb, (BT_HDR *)p_buf); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, NULL); - } +void l2c_ucd_send_pending_out_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); + + if (p_buf != NULL) { + l2c_enqueue_peer_data(p_ccb, (BT_HDR*)p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, NULL); + } } /******************************************************************************* @@ -820,12 +774,12 @@ void l2c_ucd_send_pending_out_sec_q(tL2C_CCB *p_ccb) * Return None * ******************************************************************************/ -void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); +void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_out_sec_pending_q); - /* we may need to report to application */ - osi_free(p_buf); + /* we may need to report to application */ + osi_free(p_buf); } /******************************************************************************* @@ -837,23 +791,23 @@ void l2c_ucd_discard_pending_out_sec_q(tL2C_CCB *p_ccb) * Return true if any UCD packet for security * ******************************************************************************/ -bool l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); +bool l2c_ucd_check_pending_in_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); - if (p_buf != NULL) - { - uint16_t psm; - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - STREAM_TO_UINT16(psm, p) + if (p_buf != NULL) { + uint16_t psm; + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + STREAM_TO_UINT16(psm, p) - p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; - btm_sec_l2cap_access_req (p_ccb->p_lcb->remote_bd_addr, psm, - p_ccb->p_lcb->handle, CONNLESS_TERM, &l2c_link_sec_comp, p_ccb); + p_ccb->chnl_state = CST_TERM_W4_SEC_COMP; + btm_sec_l2cap_access_req(p_ccb->p_lcb->remote_bd_addr, psm, + p_ccb->p_lcb->handle, CONNLESS_TERM, + &l2c_link_sec_comp, p_ccb); - return (true); - } - return (false); + return (true); + } + return (false); } /******************************************************************************* @@ -866,14 +820,14 @@ bool l2c_ucd_check_pending_in_sec_q(tL2C_CCB *p_ccb) * Return None * ******************************************************************************/ -void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q) - - if (p_buf != NULL) - { - p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(p_ccb->p_lcb->remote_bd_addr, (BT_HDR *)p_buf); - } +void l2c_ucd_send_pending_in_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q) + + if (p_buf != NULL) { + p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Data_Cb(p_ccb->p_lcb->remote_bd_addr, + (BT_HDR*)p_buf); + } } /******************************************************************************* @@ -886,10 +840,10 @@ void l2c_ucd_send_pending_in_sec_q(tL2C_CCB *p_ccb) * Return None * ******************************************************************************/ -void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); - osi_free(p_buf); +void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB* p_ccb) { + BT_HDR* p_buf = + (BT_HDR*)fixed_queue_try_dequeue(p_ccb->p_lcb->ucd_in_sec_pending_q); + osi_free(p_buf); } /******************************************************************************* @@ -902,47 +856,41 @@ void l2c_ucd_discard_pending_in_sec_q(tL2C_CCB *p_ccb) * Return true if UCD reception is registered * ******************************************************************************/ -bool l2c_ucd_check_rx_pkts(tL2C_LCB *p_lcb, BT_HDR *p_msg) -{ - tL2C_CCB *p_ccb; - tL2C_RCB *p_rcb; - - if (((p_ccb = l2cu_find_ccb_by_cid (p_lcb, L2CAP_CONNECTIONLESS_CID)) != NULL) - ||((p_rcb = l2cu_find_rcb_by_psm (L2C_UCD_RCB_ID)) != NULL)) - { - if (p_ccb == NULL) - { - /* Allocate a channel control block */ - p_ccb = l2cu_allocate_ccb(p_lcb, 0); - if (p_ccb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no CCB for UCD reception"); - osi_free(p_msg); - return true; - } - else - { - /* Set CID for the connection */ - p_ccb->local_cid = L2CAP_CONNECTIONLESS_CID; - p_ccb->remote_cid = L2CAP_CONNECTIONLESS_CID; +bool l2c_ucd_check_rx_pkts(tL2C_LCB* p_lcb, BT_HDR* p_msg) { + tL2C_CCB* p_ccb; + tL2C_RCB* p_rcb; + + if (((p_ccb = l2cu_find_ccb_by_cid(p_lcb, L2CAP_CONNECTIONLESS_CID)) != + NULL) || + ((p_rcb = l2cu_find_rcb_by_psm(L2C_UCD_RCB_ID)) != NULL)) { + if (p_ccb == NULL) { + /* Allocate a channel control block */ + p_ccb = l2cu_allocate_ccb(p_lcb, 0); + if (p_ccb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no CCB for UCD reception"); + osi_free(p_msg); + return true; + } else { + /* Set CID for the connection */ + p_ccb->local_cid = L2CAP_CONNECTIONLESS_CID; + p_ccb->remote_cid = L2CAP_CONNECTIONLESS_CID; - /* Set the default idle timeout value to use */ - p_ccb->fixed_chnl_idle_tout = L2CAP_UCD_IDLE_TIMEOUT; + /* Set the default idle timeout value to use */ + p_ccb->fixed_chnl_idle_tout = L2CAP_UCD_IDLE_TIMEOUT; - /* Set the default channel priority value to use */ - l2cu_change_pri_ccb (p_ccb, L2CAP_UCD_CH_PRIORITY); + /* Set the default channel priority value to use */ + l2cu_change_pri_ccb(p_ccb, L2CAP_UCD_CH_PRIORITY); - /* Save registration info */ - p_ccb->p_rcb = p_rcb; + /* Save registration info */ + p_ccb->p_rcb = p_rcb; - p_ccb->chnl_state = CST_OPEN; - } - } - l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DATA, p_msg); - return true; + p_ccb->chnl_state = CST_OPEN; + } } - else - return false; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_DATA, p_msg); + return true; + } else + return false; } /******************************************************************************* @@ -957,233 +905,211 @@ bool l2c_ucd_check_rx_pkts(tL2C_LCB *p_lcb, BT_HDR *p_msg) * machine * ******************************************************************************/ -bool l2c_ucd_process_event(tL2C_CCB *p_ccb, uint16_t event, void *p_data) -{ - /* if the event is not processed by this function, this variable will be set to false */ - bool done = true; +bool l2c_ucd_process_event(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { + /* if the event is not processed by this function, this variable will be set + * to false */ + bool done = true; - switch (p_ccb->chnl_state) - { + switch (p_ccb->chnl_state) { case CST_CLOSED: - switch (event) - { - case L2CEVT_LP_CONNECT_CFM: /* Link came up */ - /* check if waiting for UCD info */ - if (!l2c_ucd_check_pending_info_req (p_ccb)) - { - /* check if any outgoing UCD packet is waiting security check */ - if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) - { - p_ccb->chnl_state = CST_OPEN; - } + switch (event) { + case L2CEVT_LP_CONNECT_CFM: /* Link came up */ + /* check if waiting for UCD info */ + if (!l2c_ucd_check_pending_info_req(p_ccb)) { + /* check if any outgoing UCD packet is waiting security check */ + if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) { + p_ccb->chnl_state = CST_OPEN; } - break; + } + break; - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); - break; + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + break; - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); - break; + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); + break; case L2CEVT_L2CAP_INFO_RSP: - /* check if waiting for UCD info */ - if (!l2c_ucd_check_pending_info_req (p_ccb)) - { - /* check if any outgoing UCD packet is waiting security check */ - if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) - { - p_ccb->chnl_state = CST_OPEN; - } + /* check if waiting for UCD info */ + if (!l2c_ucd_check_pending_info_req(p_ccb)) { + /* check if any outgoing UCD packet is waiting security check */ + if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) { + p_ccb->chnl_state = CST_OPEN; } - break; + } + break; default: - done = false; /* main state machine continues to process event */ - break; - } - break; + done = false; /* main state machine continues to process event */ + break; + } + break; case CST_ORIG_W4_SEC_COMP: - switch (event) - { - case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ - /* check if any outgoing UCD packet is waiting security check */ - if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) - { - p_ccb->chnl_state = CST_OPEN; - } - break; - - case L2CEVT_SEC_COMP: /* Security completed success */ - p_ccb->chnl_state = CST_OPEN; - l2c_ucd_send_pending_out_sec_q(p_ccb); - - if (! fixed_queue_is_empty(p_ccb->p_lcb->ucd_out_sec_pending_q)) - { - /* start a timer to send next UCD packet in OPEN state */ - /* it will prevent stack overflow */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else - { - /* start a timer for idle timeout of UCD */ - period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - break; - - case L2CEVT_SEC_COMP_NEG: + switch (event) { + case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ + /* check if any outgoing UCD packet is waiting security check */ + if (!l2c_ucd_check_pending_out_sec_q(p_ccb)) { p_ccb->chnl_state = CST_OPEN; - l2c_ucd_discard_pending_out_sec_q(p_ccb); - + } + break; + + case L2CEVT_SEC_COMP: /* Security completed success */ + p_ccb->chnl_state = CST_OPEN; + l2c_ucd_send_pending_out_sec_q(p_ccb); + + if (!fixed_queue_is_empty(p_ccb->p_lcb->ucd_out_sec_pending_q)) { + /* start a timer to send next UCD packet in OPEN state */ + /* it will prevent stack overflow */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0, l2c_ccb_timer_timeout, + p_ccb, btu_general_alarm_queue); + } else { /* start a timer for idle timeout of UCD */ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); - break; + } + break; - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); - break; + case L2CEVT_SEC_COMP_NEG: + p_ccb->chnl_state = CST_OPEN; + l2c_ucd_discard_pending_out_sec_q(p_ccb); - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); - break; + /* start a timer for idle timeout of UCD */ + period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + break; + + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + break; case L2CEVT_L2CAP_INFO_RSP: - /* check if waiting for UCD info */ - l2c_ucd_check_pending_info_req (p_ccb); - break; + /* check if waiting for UCD info */ + l2c_ucd_check_pending_info_req(p_ccb); + break; default: - done = false; /* main state machine continues to process event */ - break; - } - break; - + done = false; /* main state machine continues to process event */ + break; + } + break; case CST_TERM_W4_SEC_COMP: - switch (event) - { + switch (event) { case L2CEVT_SEC_COMP: - p_ccb->chnl_state = CST_OPEN; - l2c_ucd_send_pending_in_sec_q (p_ccb); - - if (! fixed_queue_is_empty(p_ccb->p_lcb->ucd_in_sec_pending_q)) - { - /* start a timer to check next UCD packet in OPEN state */ - /* it will prevent stack overflow */ - alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else - { - /* start a timer for idle timeout of UCD */ - period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; - alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, - l2c_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - break; - - case L2CEVT_SEC_COMP_NEG: - if (((tL2C_CONN_INFO *)p_data)->status == BTM_DELAY_CHECK) - { - done = false; - break; - } - p_ccb->chnl_state = CST_OPEN; - l2c_ucd_discard_pending_in_sec_q (p_ccb); - + p_ccb->chnl_state = CST_OPEN; + l2c_ucd_send_pending_in_sec_q(p_ccb); + + if (!fixed_queue_is_empty(p_ccb->p_lcb->ucd_in_sec_pending_q)) { + /* start a timer to check next UCD packet in OPEN state */ + /* it will prevent stack overflow */ + alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0, l2c_ccb_timer_timeout, + p_ccb, btu_general_alarm_queue); + } else { /* start a timer for idle timeout of UCD */ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, l2c_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); - break; - - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); - break; - - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); - break; + } + break; - case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ - /* check if any incoming UCD packet is waiting security check */ - if (!l2c_ucd_check_pending_in_sec_q(p_ccb)) - { - p_ccb->chnl_state = CST_OPEN; - } + case L2CEVT_SEC_COMP_NEG: + if (((tL2C_CONN_INFO*)p_data)->status == BTM_DELAY_CHECK) { + done = false; break; + } + p_ccb->chnl_state = CST_OPEN; + l2c_ucd_discard_pending_in_sec_q(p_ccb); + + /* start a timer for idle timeout of UCD */ + period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000; + alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms, + l2c_ccb_timer_timeout, p_ccb, + btu_general_alarm_queue); + break; + + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); + break; + + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + break; + + case L2CEVT_SEC_RE_SEND_CMD: /* BTM has enough info to proceed */ + /* check if any incoming UCD packet is waiting security check */ + if (!l2c_ucd_check_pending_in_sec_q(p_ccb)) { + p_ccb->chnl_state = CST_OPEN; + } + break; case L2CEVT_L2CAP_INFO_RSP: - /* check if waiting for UCD info */ - l2c_ucd_check_pending_info_req (p_ccb); - break; + /* check if waiting for UCD info */ + l2c_ucd_check_pending_info_req(p_ccb); + break; default: - done = false; /* main state machine continues to process event */ - break; - } - break; + done = false; /* main state machine continues to process event */ + break; + } + break; case CST_OPEN: - switch (event) - { - case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ - /* stop idle timer of UCD */ - alarm_cancel(p_ccb->l2c_ccb_timer); - - fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); - l2c_ucd_check_pending_in_sec_q (p_ccb); - break; + switch (event) { + case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ + /* stop idle timer of UCD */ + alarm_cancel(p_ccb->l2c_ccb_timer); - case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ - /* stop idle timer of UCD */ - alarm_cancel(p_ccb->l2c_ccb_timer); + fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data); + l2c_ucd_check_pending_in_sec_q(p_ccb); + break; - l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); + case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ + /* stop idle timer of UCD */ + alarm_cancel(p_ccb->l2c_ccb_timer); - /* coverity[check_return] */ /* coverity[unchecked_value] */ - /* success changes state, failure stays in current state */ - l2c_ucd_check_pending_out_sec_q (p_ccb); - break; + l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data); + + /* coverity[check_return] */ /* coverity[unchecked_value] */ + /* success changes state, failure stays in current state */ + l2c_ucd_check_pending_out_sec_q(p_ccb); + break; case L2CEVT_TIMEOUT: - /* check if any UCD packet is waiting security check */ - if ((!l2c_ucd_check_pending_in_sec_q(p_ccb)) - &&(!l2c_ucd_check_pending_out_sec_q(p_ccb))) - { - l2cu_release_ccb (p_ccb); - } - break; + /* check if any UCD packet is waiting security check */ + if ((!l2c_ucd_check_pending_in_sec_q(p_ccb)) && + (!l2c_ucd_check_pending_out_sec_q(p_ccb))) { + l2cu_release_ccb(p_ccb); + } + break; case L2CEVT_L2CAP_INFO_RSP: - /* check if waiting for UCD info */ - l2c_ucd_check_pending_info_req (p_ccb); - break; + /* check if waiting for UCD info */ + l2c_ucd_check_pending_info_req(p_ccb); + break; default: - done = false; /* main state machine continues to process event */ - break; - } - break; + done = false; /* main state machine continues to process event */ + break; + } + break; default: - done = false; /* main state machine continues to process event */ - break; - } + done = false; /* main state machine continues to process event */ + break; + } - return done; + return done; } #endif /* (L2CAP_UCD_INCLUDED == TRUE) */ diff --git a/stack/l2cap/l2c_utils.cc b/stack/l2cap/l2c_utils.cc index 0c65fc7da..dd323f57a 100644 --- a/stack/l2cap/l2c_utils.cc +++ b/stack/l2cap/l2c_utils.cc @@ -22,25 +22,24 @@ * ******************************************************************************/ +#include #include #include -#include -#include "device/include/controller.h" #include "bt_common.h" #include "bt_types.h" -#include "hcimsgs.h" -#include "l2cdefs.h" -#include "l2c_int.h" -#include "hcidefs.h" -#include "btu.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" +#include "btu.h" +#include "device/include/controller.h" #include "hcidefs.h" -#include "bt_utils.h" +#include "hcimsgs.h" +#include "l2c_int.h" +#include "l2cdefs.h" #include "osi/include/allocator.h" -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -51,55 +50,51 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns LCB address or NULL if none found * ******************************************************************************/ -tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, bool is_bonding, tBT_TRANSPORT transport) -{ - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; - - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if (!p_lcb->in_use) - { - alarm_free(p_lcb->l2c_lcb_timer); - alarm_free(p_lcb->info_resp_timer); - memset (p_lcb, 0, sizeof (tL2C_LCB)); - - memcpy (p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN); - - p_lcb->in_use = true; - p_lcb->link_state = LST_DISCONNECTED; - p_lcb->handle = HCI_INVALID_HANDLE; - p_lcb->link_flush_tout = 0xFFFF; - p_lcb->l2c_lcb_timer = alarm_new("l2c_lcb.l2c_lcb_timer"); - p_lcb->info_resp_timer = alarm_new("l2c_lcb.info_resp_timer"); - p_lcb->idle_timeout = l2cb.idle_timeout; - p_lcb->id = 1; /* spec does not allow '0' */ - p_lcb->is_bonding = is_bonding; - p_lcb->transport = transport; - p_lcb->tx_data_len = controller_get_interface()->get_ble_default_data_packet_length(); - p_lcb->le_sec_pending_q = fixed_queue_new(SIZE_MAX); - - if (transport == BT_TRANSPORT_LE) - { - l2cb.num_ble_links_active++; - l2c_ble_link_adjust_allocation(); - } - else - { - l2cb.num_links_active++; - l2c_link_adjust_allocation(); - } +tL2C_LCB* l2cu_allocate_lcb(BD_ADDR p_bd_addr, bool is_bonding, + tBT_TRANSPORT transport) { + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; + + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if (!p_lcb->in_use) { + alarm_free(p_lcb->l2c_lcb_timer); + alarm_free(p_lcb->info_resp_timer); + memset(p_lcb, 0, sizeof(tL2C_LCB)); + + memcpy(p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN); + + p_lcb->in_use = true; + p_lcb->link_state = LST_DISCONNECTED; + p_lcb->handle = HCI_INVALID_HANDLE; + p_lcb->link_flush_tout = 0xFFFF; + p_lcb->l2c_lcb_timer = alarm_new("l2c_lcb.l2c_lcb_timer"); + p_lcb->info_resp_timer = alarm_new("l2c_lcb.info_resp_timer"); + p_lcb->idle_timeout = l2cb.idle_timeout; + p_lcb->id = 1; /* spec does not allow '0' */ + p_lcb->is_bonding = is_bonding; + p_lcb->transport = transport; + p_lcb->tx_data_len = + controller_get_interface()->get_ble_default_data_packet_length(); + p_lcb->le_sec_pending_q = fixed_queue_new(SIZE_MAX); + + if (transport == BT_TRANSPORT_LE) { + l2cb.num_ble_links_active++; + l2c_ble_link_adjust_allocation(); + } else { + l2cb.num_links_active++; + l2c_link_adjust_allocation(); + } #if (L2CAP_UCD_INCLUDED == TRUE) - p_lcb->ucd_out_sec_pending_q = fixed_queue_new(SIZE_MAX); - p_lcb->ucd_in_sec_pending_q = fixed_queue_new(SIZE_MAX); + p_lcb->ucd_out_sec_pending_q = fixed_queue_new(SIZE_MAX); + p_lcb->ucd_in_sec_pending_q = fixed_queue_new(SIZE_MAX); #endif - p_lcb->link_xmit_data_q = list_new(NULL); - return (p_lcb); - } + p_lcb->link_xmit_data_q = list_new(NULL); + return (p_lcb); } + } - /* If here, no free LCB found */ - return (NULL); + /* If here, no free LCB found */ + return (NULL); } /******************************************************************************* @@ -112,17 +107,16 @@ tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, bool is_bonding, tBT_TRANSPOR * Returns Nothing * ******************************************************************************/ -void l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, bool is_bonding) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (p_bd_addr, BT_TRANSPORT_BR_EDR); +void l2cu_update_lcb_4_bonding(BD_ADDR p_bd_addr, bool is_bonding) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb) - { - L2CAP_TRACE_DEBUG ("l2cu_update_lcb_4_bonding BDA: %08x%04x is_bonding: %d", - (p_bd_addr[0]<<24)+(p_bd_addr[1]<<16)+(p_bd_addr[2]<<8)+p_bd_addr[3], - (p_bd_addr[4]<<8)+p_bd_addr[5], is_bonding); - p_lcb->is_bonding = is_bonding; - } + if (p_lcb) { + L2CAP_TRACE_DEBUG("l2cu_update_lcb_4_bonding BDA: %08x%04x is_bonding: %d", + (p_bd_addr[0] << 24) + (p_bd_addr[1] << 16) + + (p_bd_addr[2] << 8) + p_bd_addr[3], + (p_bd_addr[4] << 8) + p_bd_addr[5], is_bonding); + p_lcb->is_bonding = is_bonding; + } } /******************************************************************************* @@ -135,127 +129,111 @@ void l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, bool is_bonding) * Returns void * ******************************************************************************/ -void l2cu_release_lcb (tL2C_LCB *p_lcb) -{ - tL2C_CCB *p_ccb; +void l2cu_release_lcb(tL2C_LCB* p_lcb) { + tL2C_CCB* p_ccb; - p_lcb->in_use = false; - p_lcb->is_bonding = false; + p_lcb->in_use = false; + p_lcb->is_bonding = false; - /* Stop and free timers */ - alarm_free(p_lcb->l2c_lcb_timer); - p_lcb->l2c_lcb_timer = NULL; - alarm_free(p_lcb->info_resp_timer); - p_lcb->info_resp_timer = NULL; + /* Stop and free timers */ + alarm_free(p_lcb->l2c_lcb_timer); + p_lcb->l2c_lcb_timer = NULL; + alarm_free(p_lcb->info_resp_timer); + p_lcb->info_resp_timer = NULL; - /* Release any unfinished L2CAP packet on this link */ - osi_free_and_reset((void **)&p_lcb->p_hcit_rcv_acl); + /* Release any unfinished L2CAP packet on this link */ + osi_free_and_reset((void**)&p_lcb->p_hcit_rcv_acl); #if (BTM_SCO_INCLUDED == TRUE) - if (p_lcb->transport == BT_TRANSPORT_BR_EDR) - /* Release all SCO links */ - btm_remove_sco_links(p_lcb->remote_bd_addr); + if (p_lcb->transport == BT_TRANSPORT_BR_EDR) /* Release all SCO links */ + btm_remove_sco_links(p_lcb->remote_bd_addr); #endif - if (p_lcb->sent_not_acked > 0) - { - if (p_lcb->transport == BT_TRANSPORT_LE) - { - l2cb.controller_le_xmit_window += p_lcb->sent_not_acked; - if (l2cb.controller_le_xmit_window > l2cb.num_lm_ble_bufs) - { - l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs; - } - } - else - { - l2cb.controller_xmit_window += p_lcb->sent_not_acked; - if (l2cb.controller_xmit_window > l2cb.num_lm_acl_bufs) - { - l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs; - } - } + if (p_lcb->sent_not_acked > 0) { + if (p_lcb->transport == BT_TRANSPORT_LE) { + l2cb.controller_le_xmit_window += p_lcb->sent_not_acked; + if (l2cb.controller_le_xmit_window > l2cb.num_lm_ble_bufs) { + l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs; + } + } else { + l2cb.controller_xmit_window += p_lcb->sent_not_acked; + if (l2cb.controller_xmit_window > l2cb.num_lm_acl_bufs) { + l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs; + } } + } - // Reset BLE connecting flag only if the address matches - if (!memcmp(l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) - l2cb.is_ble_connecting = false; + // Reset BLE connecting flag only if the address matches + if (!memcmp(l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) + l2cb.is_ble_connecting = false; #if (L2CAP_NUM_FIXED_CHNLS > 0) - l2cu_process_fixed_disc_cback(p_lcb); + l2cu_process_fixed_disc_cback(p_lcb); #endif - /* Ensure no CCBs left on this LCB */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_lcb->ccb_queue.p_first_ccb) - { - l2cu_release_ccb (p_ccb); - } + /* Ensure no CCBs left on this LCB */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; + p_ccb = p_lcb->ccb_queue.p_first_ccb) { + l2cu_release_ccb(p_ccb); + } - /* Tell BTM Acl management the link was removed */ - if ((p_lcb->link_state == LST_CONNECTED) || (p_lcb->link_state == LST_DISCONNECTING)) - btm_acl_removed (p_lcb->remote_bd_addr, p_lcb->transport); + /* Tell BTM Acl management the link was removed */ + if ((p_lcb->link_state == LST_CONNECTED) || + (p_lcb->link_state == LST_DISCONNECTING)) + btm_acl_removed(p_lcb->remote_bd_addr, p_lcb->transport); - /* Release any held buffers */ - if (p_lcb->link_xmit_data_q) - { - while (!list_is_empty(p_lcb->link_xmit_data_q)) { - BT_HDR *p_buf = - static_cast(list_front(p_lcb->link_xmit_data_q)); - list_remove(p_lcb->link_xmit_data_q, p_buf); - osi_free(p_buf); - } - list_free(p_lcb->link_xmit_data_q); - p_lcb->link_xmit_data_q = NULL; + /* Release any held buffers */ + if (p_lcb->link_xmit_data_q) { + while (!list_is_empty(p_lcb->link_xmit_data_q)) { + BT_HDR* p_buf = static_cast(list_front(p_lcb->link_xmit_data_q)); + list_remove(p_lcb->link_xmit_data_q, p_buf); + osi_free(p_buf); } + list_free(p_lcb->link_xmit_data_q); + p_lcb->link_xmit_data_q = NULL; + } #if (L2CAP_UCD_INCLUDED == TRUE) - /* clean up any security pending UCD */ - l2c_ucd_delete_sec_pending_q(p_lcb); + /* clean up any security pending UCD */ + l2c_ucd_delete_sec_pending_q(p_lcb); #endif - /* Re-adjust flow control windows make sure it does not go negative */ - if (p_lcb->transport == BT_TRANSPORT_LE) - { - if (l2cb.num_ble_links_active >= 1) - l2cb.num_ble_links_active--; + /* Re-adjust flow control windows make sure it does not go negative */ + if (p_lcb->transport == BT_TRANSPORT_LE) { + if (l2cb.num_ble_links_active >= 1) l2cb.num_ble_links_active--; - l2c_ble_link_adjust_allocation(); - } - else - { - if (l2cb.num_links_active >= 1) - l2cb.num_links_active--; + l2c_ble_link_adjust_allocation(); + } else { + if (l2cb.num_links_active >= 1) l2cb.num_links_active--; - l2c_link_adjust_allocation(); - } + l2c_link_adjust_allocation(); + } - /* Check for ping outstanding */ - if (p_lcb->p_echo_rsp_cb) - { - tL2CA_ECHO_RSP_CB *p_cb = p_lcb->p_echo_rsp_cb; + /* Check for ping outstanding */ + if (p_lcb->p_echo_rsp_cb) { + tL2CA_ECHO_RSP_CB* p_cb = p_lcb->p_echo_rsp_cb; - /* Zero out the callback in case app immediately calls us again */ - p_lcb->p_echo_rsp_cb = NULL; + /* Zero out the callback in case app immediately calls us again */ + p_lcb->p_echo_rsp_cb = NULL; - (*p_cb) (L2CAP_PING_RESULT_NO_LINK); - } + (*p_cb)(L2CAP_PING_RESULT_NO_LINK); + } - /* Check and release all the LE COC connections waiting for security */ - if (p_lcb->le_sec_pending_q) - { - while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) - { - tL2CAP_SEC_DATA *p_buf = (tL2CAP_SEC_DATA*) fixed_queue_try_dequeue(p_lcb->le_sec_pending_q); - if (p_buf->p_callback) - p_buf->p_callback(p_lcb->remote_bd_addr, p_lcb->transport, p_buf->p_ref_data, BTM_DEV_RESET); - osi_free(p_buf); - } - fixed_queue_free(p_lcb->le_sec_pending_q, NULL); - p_lcb->le_sec_pending_q = NULL; + /* Check and release all the LE COC connections waiting for security */ + if (p_lcb->le_sec_pending_q) { + while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) { + tL2CAP_SEC_DATA* p_buf = + (tL2CAP_SEC_DATA*)fixed_queue_try_dequeue(p_lcb->le_sec_pending_q); + if (p_buf->p_callback) + p_buf->p_callback(p_lcb->remote_bd_addr, p_lcb->transport, + p_buf->p_ref_data, BTM_DEV_RESET); + osi_free(p_buf); } + fixed_queue_free(p_lcb->le_sec_pending_q, NULL); + p_lcb->le_sec_pending_q = NULL; + } } - /******************************************************************************* * * Function l2cu_find_lcb_by_bd_addr @@ -266,23 +244,19 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb) * Returns pointer to matched LCB, or NULL if no match * ******************************************************************************/ -tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport) -{ - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; +tL2C_LCB* l2cu_find_lcb_by_bd_addr(BD_ADDR p_bd_addr, tBT_TRANSPORT transport) { + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && - p_lcb->transport == transport && - (!memcmp (p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN))) - { - return (p_lcb); - } + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && p_lcb->transport == transport && + (!memcmp(p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN))) { + return (p_lcb); } + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } /******************************************************************************* @@ -297,10 +271,7 @@ tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport) * Returns HCI_ROLE_MASTER or HCI_ROLE_SLAVE * ******************************************************************************/ -uint8_t l2cu_get_conn_role (tL2C_LCB *p_this_lcb) -{ - return l2cb.desire_role; -} +uint8_t l2cu_get_conn_role(tL2C_LCB* p_this_lcb) { return l2cb.desire_role; } /******************************************************************************* * @@ -315,10 +286,8 @@ uint8_t l2cu_get_conn_role (tL2C_LCB *p_this_lcb) * false if response code. (command not rejected) * ******************************************************************************/ -bool l2c_is_cmd_rejected (uint8_t cmd_code, uint8_t id, tL2C_LCB *p_lcb) -{ - switch(cmd_code) - { +bool l2c_is_cmd_rejected(uint8_t cmd_code, uint8_t id, tL2C_LCB* p_lcb) { + switch (cmd_code) { case L2CAP_CMD_CONN_REQ: case L2CAP_CMD_CONFIG_REQ: case L2CAP_CMD_DISC_REQ: @@ -327,13 +296,14 @@ bool l2c_is_cmd_rejected (uint8_t cmd_code, uint8_t id, tL2C_LCB *p_lcb) case L2CAP_CMD_AMP_CONN_REQ: case L2CAP_CMD_AMP_MOVE_REQ: case L2CAP_CMD_BLE_UPDATE_REQ: - l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_MTU_EXCEEDED, id, L2CAP_DEFAULT_MTU, 0); - L2CAP_TRACE_WARNING ("Dumping first Command (%d)", cmd_code); - return true; + l2cu_send_peer_cmd_reject(p_lcb, L2CAP_CMD_REJ_MTU_EXCEEDED, id, + L2CAP_DEFAULT_MTU, 0); + L2CAP_TRACE_WARNING("Dumping first Command (%d)", cmd_code); + return true; - default: /* Otherwise a response */ - return false; - } + default: /* Otherwise a response */ + return false; + } } /******************************************************************************* @@ -345,48 +315,44 @@ bool l2c_is_cmd_rejected (uint8_t cmd_code, uint8_t id, tL2C_LCB *p_lcb) * Returns Pointer to allocated packet or NULL if no resources * ******************************************************************************/ -BT_HDR *l2cu_build_header (tL2C_LCB *p_lcb, uint16_t len, uint8_t cmd, uint8_t id) -{ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(L2CAP_CMD_BUF_SIZE); - uint8_t *p; +BT_HDR* l2cu_build_header(tL2C_LCB* p_lcb, uint16_t len, uint8_t cmd, + uint8_t id) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(L2CAP_CMD_BUF_SIZE); + uint8_t* p; - p_buf->offset = L2CAP_SEND_CMD_OFFSET; - p_buf->len = len + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET; + p_buf->offset = L2CAP_SEND_CMD_OFFSET; + p_buf->len = + len + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET; - /* Put in HCI header - handle + pkt boundary */ - if (p_lcb->transport == BT_TRANSPORT_LE) - { - UINT16_TO_STREAM (p, (p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT))); - } - else - { + /* Put in HCI header - handle + pkt boundary */ + if (p_lcb->transport == BT_TRANSPORT_LE) { + UINT16_TO_STREAM(p, (p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE + << L2CAP_PKT_TYPE_SHIFT))); + } else { #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - UINT16_TO_STREAM (p, p_lcb->handle | l2cb.non_flushable_pbf); + UINT16_TO_STREAM(p, p_lcb->handle | l2cb.non_flushable_pbf); #else - UINT16_TO_STREAM (p, (p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT))); + UINT16_TO_STREAM( + p, (p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT))); #endif - } + } - UINT16_TO_STREAM (p, len + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD); - UINT16_TO_STREAM (p, len + L2CAP_CMD_OVERHEAD); - - if (p_lcb->transport == BT_TRANSPORT_LE) - { + UINT16_TO_STREAM(p, len + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD); + UINT16_TO_STREAM(p, len + L2CAP_CMD_OVERHEAD); - UINT16_TO_STREAM (p, L2CAP_BLE_SIGNALLING_CID); - } - else - { - UINT16_TO_STREAM (p, L2CAP_SIGNALLING_CID); - } + if (p_lcb->transport == BT_TRANSPORT_LE) { + UINT16_TO_STREAM(p, L2CAP_BLE_SIGNALLING_CID); + } else { + UINT16_TO_STREAM(p, L2CAP_SIGNALLING_CID); + } - /* Put in L2CAP command header */ - UINT8_TO_STREAM (p, cmd); - UINT8_TO_STREAM (p, id); - UINT16_TO_STREAM (p, len); + /* Put in L2CAP command header */ + UINT8_TO_STREAM(p, cmd); + UINT8_TO_STREAM(p, id); + UINT16_TO_STREAM(p, len); - return (p_buf); + return (p_buf); } /******************************************************************************* @@ -399,12 +365,10 @@ BT_HDR *l2cu_build_header (tL2C_LCB *p_lcb, uint16_t len, uint8_t cmd, uint8_t i * Returns void * ******************************************************************************/ -void l2cu_adj_id (tL2C_LCB *p_lcb, uint8_t adj_mask) -{ - if ((adj_mask & L2CAP_ADJ_ZERO_ID) && !p_lcb->id) - { - p_lcb->id++; - } +void l2cu_adj_id(tL2C_LCB* p_lcb, uint8_t adj_mask) { + if ((adj_mask & L2CAP_ADJ_ZERO_ID) && !p_lcb->id) { + p_lcb->id++; + } } /******************************************************************************* @@ -417,43 +381,39 @@ void l2cu_adj_id (tL2C_LCB *p_lcb, uint8_t adj_mask) * Returns void * ******************************************************************************/ -void l2cu_send_peer_cmd_reject (tL2C_LCB *p_lcb, uint16_t reason, uint8_t rem_id, - uint16_t p1, uint16_t p2) -{ - uint16_t param_len; - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_cmd_reject(tL2C_LCB* p_lcb, uint16_t reason, uint8_t rem_id, + uint16_t p1, uint16_t p2) { + uint16_t param_len; + BT_HDR* p_buf; + uint8_t* p; - /* Put in L2CAP packet header */ - if (reason == L2CAP_CMD_REJ_MTU_EXCEEDED) - param_len = 2; - else if (reason == L2CAP_CMD_REJ_INVALID_CID) - param_len = 4; - else - param_len = 0; + /* Put in L2CAP packet header */ + if (reason == L2CAP_CMD_REJ_MTU_EXCEEDED) + param_len = 2; + else if (reason == L2CAP_CMD_REJ_INVALID_CID) + param_len = 4; + else + param_len = 0; - p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_CMD_REJECT_LEN + param_len), L2CAP_CMD_REJECT, rem_id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer cmd_rej"); - return; - } + p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_CMD_REJECT_LEN + param_len), + L2CAP_CMD_REJECT, rem_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer cmd_rej"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, reason); + UINT16_TO_STREAM(p, reason); - if (param_len >= 2) - UINT16_TO_STREAM (p, p1); + if (param_len >= 2) UINT16_TO_STREAM(p, p1); - if (param_len >= 4) - UINT16_TO_STREAM (p, p2); + if (param_len >= 4) UINT16_TO_STREAM(p, p2); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_connect_req @@ -464,35 +424,32 @@ void l2cu_send_peer_cmd_reject (tL2C_LCB *p_lcb, uint16_t reason, uint8_t rem_id * Returns void * ******************************************************************************/ -void l2cu_send_peer_connect_req (tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_connect_req(tL2C_CCB* p_ccb) { + BT_HDR* p_buf; + uint8_t* p; - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - p_ccb->local_id = p_ccb->p_lcb->id; + p_ccb->local_id = p_ccb->p_lcb->id; - p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_CONN_REQ_LEN, - L2CAP_CMD_CONN_REQ, p_ccb->local_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for conn_req"); - return; - } + p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_CONN_REQ_LEN, + L2CAP_CMD_CONN_REQ, p_ccb->local_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for conn_req"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET+HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->p_rcb->real_psm); - UINT16_TO_STREAM (p, p_ccb->local_cid); + UINT16_TO_STREAM(p, p_ccb->p_rcb->real_psm); + UINT16_TO_STREAM(p, p_ccb->local_cid); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_connect_rsp @@ -503,39 +460,37 @@ void l2cu_send_peer_connect_req (tL2C_CCB *p_ccb) * Returns void * ******************************************************************************/ -void l2cu_send_peer_connect_rsp (tL2C_CCB *p_ccb, uint16_t result, uint16_t status) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_connect_rsp(tL2C_CCB* p_ccb, uint16_t result, + uint16_t status) { + BT_HDR* p_buf; + uint8_t* p; - if (result == L2CAP_CONN_PENDING) - { - /* if we already sent pending response */ - if (p_ccb->flags & CCB_FLAG_SENT_PENDING) - return; - else - p_ccb->flags |= CCB_FLAG_SENT_PENDING; - } + if (result == L2CAP_CONN_PENDING) { + /* if we already sent pending response */ + if (p_ccb->flags & CCB_FLAG_SENT_PENDING) + return; + else + p_ccb->flags |= CCB_FLAG_SENT_PENDING; + } - p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_CONN_RSP_LEN, L2CAP_CMD_CONN_RSP, p_ccb->remote_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for conn_rsp"); - return; - } + p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_CONN_RSP_LEN, + L2CAP_CMD_CONN_RSP, p_ccb->remote_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for conn_rsp"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET+HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->local_cid); - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p, result); - UINT16_TO_STREAM (p, status); + UINT16_TO_STREAM(p, p_ccb->local_cid); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, result); + UINT16_TO_STREAM(p, status); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_reject_connection @@ -547,26 +502,27 @@ void l2cu_send_peer_connect_rsp (tL2C_CCB *p_ccb, uint16_t result, uint16_t stat * Returns void * ******************************************************************************/ -void l2cu_reject_connection (tL2C_LCB *p_lcb, uint16_t remote_cid, uint8_t rem_id, uint16_t result) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_reject_connection(tL2C_LCB* p_lcb, uint16_t remote_cid, + uint8_t rem_id, uint16_t result) { + BT_HDR* p_buf; + uint8_t* p; - p_buf = l2cu_build_header(p_lcb, L2CAP_CONN_RSP_LEN, L2CAP_CMD_CONN_RSP, rem_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for conn_req"); - return; - } + p_buf = + l2cu_build_header(p_lcb, L2CAP_CONN_RSP_LEN, L2CAP_CMD_CONN_RSP, rem_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for conn_req"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET+HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, 0); /* Local CID of 0 */ - UINT16_TO_STREAM (p, remote_cid); - UINT16_TO_STREAM (p, result); - UINT16_TO_STREAM (p, 0); /* Status of 0 */ + UINT16_TO_STREAM(p, 0); /* Local CID of 0 */ + UINT16_TO_STREAM(p, remote_cid); + UINT16_TO_STREAM(p, result); + UINT16_TO_STREAM(p, 0); /* Status of 0 */ - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -579,101 +535,95 @@ void l2cu_reject_connection (tL2C_LCB *p_lcb, uint16_t remote_cid, uint8_t rem_i * Returns void * ******************************************************************************/ -void l2cu_send_peer_config_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - BT_HDR *p_buf; - uint16_t cfg_len=0; - uint8_t *p; - - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - - p_ccb->local_id = p_ccb->p_lcb->id; - - if (p_cfg->mtu_present) - cfg_len += L2CAP_CFG_MTU_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->flush_to_present) - cfg_len += L2CAP_CFG_FLUSH_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->qos_present) - cfg_len += L2CAP_CFG_QOS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->fcr_present) - cfg_len += L2CAP_CFG_FCR_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->fcs_present) - cfg_len += L2CAP_CFG_FCS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->ext_flow_spec_present) - cfg_len += L2CAP_CFG_EXT_FLOW_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - - p_buf = l2cu_build_header(p_ccb->p_lcb, (uint16_t)(L2CAP_CONFIG_REQ_LEN + cfg_len), L2CAP_CMD_CONFIG_REQ, p_ccb->local_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for conn_req"); - return; - } - - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p, p_cfg->flags); /* Flags (continuation) */ - - /* Now, put the options */ - if (p_cfg->mtu_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_MTU); - UINT8_TO_STREAM (p, L2CAP_CFG_MTU_OPTION_LEN); - UINT16_TO_STREAM (p, p_cfg->mtu); - } - if (p_cfg->flush_to_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_FLUSH_TOUT); - UINT8_TO_STREAM (p, L2CAP_CFG_FLUSH_OPTION_LEN); - UINT16_TO_STREAM (p, p_cfg->flush_to); - } - if (p_cfg->qos_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_QOS); - UINT8_TO_STREAM (p, L2CAP_CFG_QOS_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->qos.qos_flags); - UINT8_TO_STREAM (p, p_cfg->qos.service_type); - UINT32_TO_STREAM (p, p_cfg->qos.token_rate); - UINT32_TO_STREAM (p, p_cfg->qos.token_bucket_size); - UINT32_TO_STREAM (p, p_cfg->qos.peak_bandwidth); - UINT32_TO_STREAM (p, p_cfg->qos.latency); - UINT32_TO_STREAM (p, p_cfg->qos.delay_variation); - } - if (p_cfg->fcr_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_FCR); - UINT8_TO_STREAM (p, L2CAP_CFG_FCR_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->fcr.mode); - UINT8_TO_STREAM (p, p_cfg->fcr.tx_win_sz); - UINT8_TO_STREAM (p, p_cfg->fcr.max_transmit); - UINT16_TO_STREAM (p, p_cfg->fcr.rtrans_tout); - UINT16_TO_STREAM (p, p_cfg->fcr.mon_tout); - UINT16_TO_STREAM (p, p_cfg->fcr.mps); - } - - if (p_cfg->fcs_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_FCS); - UINT8_TO_STREAM (p, L2CAP_CFG_FCS_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->fcs); - } - - if (p_cfg->ext_flow_spec_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_EXT_FLOW); - UINT8_TO_STREAM (p, L2CAP_CFG_EXT_FLOW_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->ext_flow_spec.id); - UINT8_TO_STREAM (p, p_cfg->ext_flow_spec.stype); - UINT16_TO_STREAM (p, p_cfg->ext_flow_spec.max_sdu_size); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.sdu_inter_time); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.access_latency); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.flush_timeout); - } - - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); +void l2cu_send_peer_config_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + BT_HDR* p_buf; + uint16_t cfg_len = 0; + uint8_t* p; + + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + + p_ccb->local_id = p_ccb->p_lcb->id; + + if (p_cfg->mtu_present) + cfg_len += L2CAP_CFG_MTU_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->flush_to_present) + cfg_len += L2CAP_CFG_FLUSH_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->qos_present) + cfg_len += L2CAP_CFG_QOS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->fcr_present) + cfg_len += L2CAP_CFG_FCR_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->fcs_present) + cfg_len += L2CAP_CFG_FCS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->ext_flow_spec_present) + cfg_len += L2CAP_CFG_EXT_FLOW_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + + p_buf = l2cu_build_header(p_ccb->p_lcb, + (uint16_t)(L2CAP_CONFIG_REQ_LEN + cfg_len), + L2CAP_CMD_CONFIG_REQ, p_ccb->local_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for conn_req"); + return; + } + + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, p_cfg->flags); /* Flags (continuation) */ + + /* Now, put the options */ + if (p_cfg->mtu_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_MTU); + UINT8_TO_STREAM(p, L2CAP_CFG_MTU_OPTION_LEN); + UINT16_TO_STREAM(p, p_cfg->mtu); + } + if (p_cfg->flush_to_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_FLUSH_TOUT); + UINT8_TO_STREAM(p, L2CAP_CFG_FLUSH_OPTION_LEN); + UINT16_TO_STREAM(p, p_cfg->flush_to); + } + if (p_cfg->qos_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_QOS); + UINT8_TO_STREAM(p, L2CAP_CFG_QOS_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->qos.qos_flags); + UINT8_TO_STREAM(p, p_cfg->qos.service_type); + UINT32_TO_STREAM(p, p_cfg->qos.token_rate); + UINT32_TO_STREAM(p, p_cfg->qos.token_bucket_size); + UINT32_TO_STREAM(p, p_cfg->qos.peak_bandwidth); + UINT32_TO_STREAM(p, p_cfg->qos.latency); + UINT32_TO_STREAM(p, p_cfg->qos.delay_variation); + } + if (p_cfg->fcr_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_FCR); + UINT8_TO_STREAM(p, L2CAP_CFG_FCR_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->fcr.mode); + UINT8_TO_STREAM(p, p_cfg->fcr.tx_win_sz); + UINT8_TO_STREAM(p, p_cfg->fcr.max_transmit); + UINT16_TO_STREAM(p, p_cfg->fcr.rtrans_tout); + UINT16_TO_STREAM(p, p_cfg->fcr.mon_tout); + UINT16_TO_STREAM(p, p_cfg->fcr.mps); + } + + if (p_cfg->fcs_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_FCS); + UINT8_TO_STREAM(p, L2CAP_CFG_FCS_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->fcs); + } + + if (p_cfg->ext_flow_spec_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_EXT_FLOW); + UINT8_TO_STREAM(p, L2CAP_CFG_EXT_FLOW_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->ext_flow_spec.id); + UINT8_TO_STREAM(p, p_cfg->ext_flow_spec.stype); + UINT16_TO_STREAM(p, p_cfg->ext_flow_spec.max_sdu_size); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.sdu_inter_time); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.access_latency); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.flush_timeout); + } + + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } /******************************************************************************* @@ -686,87 +636,84 @@ void l2cu_send_peer_config_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_send_peer_config_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - BT_HDR *p_buf; - uint16_t cfg_len = 0; - uint8_t *p; - - /* Create an identifier for this packet */ - if (p_cfg->mtu_present) - cfg_len += L2CAP_CFG_MTU_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->flush_to_present) - cfg_len += L2CAP_CFG_FLUSH_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->qos_present) - cfg_len += L2CAP_CFG_QOS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->fcr_present) - cfg_len += L2CAP_CFG_FCR_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - if (p_cfg->ext_flow_spec_present) - cfg_len += L2CAP_CFG_EXT_FLOW_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; - - p_buf = l2cu_build_header(p_ccb->p_lcb, (uint16_t)(L2CAP_CONFIG_RSP_LEN + cfg_len), L2CAP_CMD_CONFIG_RSP, p_ccb->remote_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for conn_req"); - return; - } - - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET+HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p, p_cfg->flags); /* Flags (continuation) Must match request */ - UINT16_TO_STREAM (p, p_cfg->result); - - /* Now, put the options */ - if (p_cfg->mtu_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_MTU); - UINT8_TO_STREAM (p, L2CAP_CFG_MTU_OPTION_LEN); - UINT16_TO_STREAM (p, p_cfg->mtu); - } - if (p_cfg->flush_to_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_FLUSH_TOUT); - UINT8_TO_STREAM (p, L2CAP_CFG_FLUSH_OPTION_LEN); - UINT16_TO_STREAM (p, p_cfg->flush_to); - } - if (p_cfg->qos_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_QOS); - UINT8_TO_STREAM (p, L2CAP_CFG_QOS_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->qos.qos_flags); - UINT8_TO_STREAM (p, p_cfg->qos.service_type); - UINT32_TO_STREAM (p, p_cfg->qos.token_rate); - UINT32_TO_STREAM (p, p_cfg->qos.token_bucket_size); - UINT32_TO_STREAM (p, p_cfg->qos.peak_bandwidth); - UINT32_TO_STREAM (p, p_cfg->qos.latency); - UINT32_TO_STREAM (p, p_cfg->qos.delay_variation); - } - if (p_cfg->fcr_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_FCR); - UINT8_TO_STREAM (p, L2CAP_CFG_FCR_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->fcr.mode); - UINT8_TO_STREAM (p, p_cfg->fcr.tx_win_sz); - UINT8_TO_STREAM (p, p_cfg->fcr.max_transmit); - UINT16_TO_STREAM (p, p_ccb->our_cfg.fcr.rtrans_tout); - UINT16_TO_STREAM (p, p_ccb->our_cfg.fcr.mon_tout); - UINT16_TO_STREAM (p, p_cfg->fcr.mps); - } - - if (p_cfg->ext_flow_spec_present) - { - UINT8_TO_STREAM (p, L2CAP_CFG_TYPE_EXT_FLOW); - UINT8_TO_STREAM (p, L2CAP_CFG_EXT_FLOW_OPTION_LEN); - UINT8_TO_STREAM (p, p_cfg->ext_flow_spec.id); - UINT8_TO_STREAM (p, p_cfg->ext_flow_spec.stype); - UINT16_TO_STREAM (p, p_cfg->ext_flow_spec.max_sdu_size); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.sdu_inter_time); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.access_latency); - UINT32_TO_STREAM (p, p_cfg->ext_flow_spec.flush_timeout); - } - - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); +void l2cu_send_peer_config_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + BT_HDR* p_buf; + uint16_t cfg_len = 0; + uint8_t* p; + + /* Create an identifier for this packet */ + if (p_cfg->mtu_present) + cfg_len += L2CAP_CFG_MTU_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->flush_to_present) + cfg_len += L2CAP_CFG_FLUSH_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->qos_present) + cfg_len += L2CAP_CFG_QOS_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->fcr_present) + cfg_len += L2CAP_CFG_FCR_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + if (p_cfg->ext_flow_spec_present) + cfg_len += L2CAP_CFG_EXT_FLOW_OPTION_LEN + L2CAP_CFG_OPTION_OVERHEAD; + + p_buf = l2cu_build_header(p_ccb->p_lcb, + (uint16_t)(L2CAP_CONFIG_RSP_LEN + cfg_len), + L2CAP_CMD_CONFIG_RSP, p_ccb->remote_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for conn_req"); + return; + } + + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, + p_cfg->flags); /* Flags (continuation) Must match request */ + UINT16_TO_STREAM(p, p_cfg->result); + + /* Now, put the options */ + if (p_cfg->mtu_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_MTU); + UINT8_TO_STREAM(p, L2CAP_CFG_MTU_OPTION_LEN); + UINT16_TO_STREAM(p, p_cfg->mtu); + } + if (p_cfg->flush_to_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_FLUSH_TOUT); + UINT8_TO_STREAM(p, L2CAP_CFG_FLUSH_OPTION_LEN); + UINT16_TO_STREAM(p, p_cfg->flush_to); + } + if (p_cfg->qos_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_QOS); + UINT8_TO_STREAM(p, L2CAP_CFG_QOS_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->qos.qos_flags); + UINT8_TO_STREAM(p, p_cfg->qos.service_type); + UINT32_TO_STREAM(p, p_cfg->qos.token_rate); + UINT32_TO_STREAM(p, p_cfg->qos.token_bucket_size); + UINT32_TO_STREAM(p, p_cfg->qos.peak_bandwidth); + UINT32_TO_STREAM(p, p_cfg->qos.latency); + UINT32_TO_STREAM(p, p_cfg->qos.delay_variation); + } + if (p_cfg->fcr_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_FCR); + UINT8_TO_STREAM(p, L2CAP_CFG_FCR_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->fcr.mode); + UINT8_TO_STREAM(p, p_cfg->fcr.tx_win_sz); + UINT8_TO_STREAM(p, p_cfg->fcr.max_transmit); + UINT16_TO_STREAM(p, p_ccb->our_cfg.fcr.rtrans_tout); + UINT16_TO_STREAM(p, p_ccb->our_cfg.fcr.mon_tout); + UINT16_TO_STREAM(p, p_cfg->fcr.mps); + } + + if (p_cfg->ext_flow_spec_present) { + UINT8_TO_STREAM(p, L2CAP_CFG_TYPE_EXT_FLOW); + UINT8_TO_STREAM(p, L2CAP_CFG_EXT_FLOW_OPTION_LEN); + UINT8_TO_STREAM(p, p_cfg->ext_flow_spec.id); + UINT8_TO_STREAM(p, p_cfg->ext_flow_spec.stype); + UINT16_TO_STREAM(p, p_cfg->ext_flow_spec.max_sdu_size); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.sdu_inter_time); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.access_latency); + UINT32_TO_STREAM(p, p_cfg->ext_flow_spec.flush_timeout); + } + + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } /******************************************************************************* @@ -779,115 +726,108 @@ void l2cu_send_peer_config_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_send_peer_config_rej (tL2C_CCB *p_ccb, uint8_t *p_data, uint16_t data_len, uint16_t rej_len) -{ - uint16_t len, cfg_len, buf_space, len1; - uint8_t *p, *p_hci_len, *p_data_end; - uint8_t cfg_code; +void l2cu_send_peer_config_rej(tL2C_CCB* p_ccb, uint8_t* p_data, + uint16_t data_len, uint16_t rej_len) { + uint16_t len, cfg_len, buf_space, len1; + uint8_t *p, *p_hci_len, *p_data_end; + uint8_t cfg_code; - L2CAP_TRACE_DEBUG("l2cu_send_peer_config_rej: data_len=%d, rej_len=%d", data_len, rej_len); + L2CAP_TRACE_DEBUG("l2cu_send_peer_config_rej: data_len=%d, rej_len=%d", + data_len, rej_len); + len = BT_HDR_SIZE + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + + L2CAP_CMD_OVERHEAD + L2CAP_CONFIG_RSP_LEN; + len1 = 0xFFFF - len; + if (rej_len > len1) { + L2CAP_TRACE_ERROR( + "L2CAP - cfg_rej pkt size exceeds buffer design max limit."); + return; + } - len = BT_HDR_SIZE + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD + L2CAP_CONFIG_RSP_LEN; - len1 = 0xFFFF - len; - if (rej_len > len1) - { - L2CAP_TRACE_ERROR ("L2CAP - cfg_rej pkt size exceeds buffer design max limit."); - return; - } - - BT_HDR *p_buf = (BT_HDR *)osi_malloc(len + rej_len); - p_buf->offset = L2CAP_SEND_CMD_OFFSET; - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(len + rej_len); + p_buf->offset = L2CAP_SEND_CMD_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET; - /* Put in HCI header - handle + pkt boundary */ +/* Put in HCI header - handle + pkt boundary */ #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - if (HCI_NON_FLUSHABLE_PB_SUPPORTED(BTM_ReadLocalFeatures ())) - { - UINT16_TO_STREAM (p, (p_ccb->p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT))); - } - else + if (HCI_NON_FLUSHABLE_PB_SUPPORTED(BTM_ReadLocalFeatures())) { + UINT16_TO_STREAM(p, (p_ccb->p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE + << L2CAP_PKT_TYPE_SHIFT))); + } else #endif - { - UINT16_TO_STREAM (p, (p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT))); - } - - /* Remember the HCI header length position, and save space for it */ - p_hci_len = p; - p += 2; - - /* Put in L2CAP packet header */ - UINT16_TO_STREAM (p, L2CAP_CMD_OVERHEAD + L2CAP_CONFIG_RSP_LEN + rej_len); - UINT16_TO_STREAM (p, L2CAP_SIGNALLING_CID); - - /* Put in L2CAP command header */ - UINT8_TO_STREAM (p, L2CAP_CMD_CONFIG_RSP); - UINT8_TO_STREAM (p, p_ccb->remote_id); - - UINT16_TO_STREAM (p, L2CAP_CONFIG_RSP_LEN + rej_len); - - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p, 0); /* Flags = 0 (no continuation) */ - UINT16_TO_STREAM (p, L2CAP_CFG_UNKNOWN_OPTIONS); - - buf_space = rej_len; - - /* Now, put the rejected options */ - p_data_end = p_data + data_len; - while (p_data < p_data_end) - { - cfg_code = *p_data; - cfg_len = *(p_data + 1); - - switch (cfg_code & 0x7F) - { - /* skip known options */ - case L2CAP_CFG_TYPE_MTU: - case L2CAP_CFG_TYPE_FLUSH_TOUT: - case L2CAP_CFG_TYPE_QOS: - p_data += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; - break; - - /* unknown options; copy into rsp if not hints */ - default: - /* sanity check option length */ - if ((cfg_len + L2CAP_CFG_OPTION_OVERHEAD) <= data_len) - { - if ((cfg_code & 0x80) == 0) - { - if (buf_space >= (cfg_len + L2CAP_CFG_OPTION_OVERHEAD)) - { - memcpy(p, p_data, cfg_len + L2CAP_CFG_OPTION_OVERHEAD); - p += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; - buf_space -= (cfg_len + L2CAP_CFG_OPTION_OVERHEAD); - } - else - { - L2CAP_TRACE_WARNING("L2CAP - cfg_rej exceeds allocated buffer"); - p_data = p_data_end; /* force loop exit */ - break; - } - } - p_data += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; - } - /* bad length; force loop exit */ - else - { - p_data = p_data_end; - } - break; + { + UINT16_TO_STREAM( + p, (p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT))); + } + + /* Remember the HCI header length position, and save space for it */ + p_hci_len = p; + p += 2; + + /* Put in L2CAP packet header */ + UINT16_TO_STREAM(p, L2CAP_CMD_OVERHEAD + L2CAP_CONFIG_RSP_LEN + rej_len); + UINT16_TO_STREAM(p, L2CAP_SIGNALLING_CID); + + /* Put in L2CAP command header */ + UINT8_TO_STREAM(p, L2CAP_CMD_CONFIG_RSP); + UINT8_TO_STREAM(p, p_ccb->remote_id); + + UINT16_TO_STREAM(p, L2CAP_CONFIG_RSP_LEN + rej_len); + + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, 0); /* Flags = 0 (no continuation) */ + UINT16_TO_STREAM(p, L2CAP_CFG_UNKNOWN_OPTIONS); + + buf_space = rej_len; + + /* Now, put the rejected options */ + p_data_end = p_data + data_len; + while (p_data < p_data_end) { + cfg_code = *p_data; + cfg_len = *(p_data + 1); + + switch (cfg_code & 0x7F) { + /* skip known options */ + case L2CAP_CFG_TYPE_MTU: + case L2CAP_CFG_TYPE_FLUSH_TOUT: + case L2CAP_CFG_TYPE_QOS: + p_data += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; + break; + + /* unknown options; copy into rsp if not hints */ + default: + /* sanity check option length */ + if ((cfg_len + L2CAP_CFG_OPTION_OVERHEAD) <= data_len) { + if ((cfg_code & 0x80) == 0) { + if (buf_space >= (cfg_len + L2CAP_CFG_OPTION_OVERHEAD)) { + memcpy(p, p_data, cfg_len + L2CAP_CFG_OPTION_OVERHEAD); + p += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; + buf_space -= (cfg_len + L2CAP_CFG_OPTION_OVERHEAD); + } else { + L2CAP_TRACE_WARNING("L2CAP - cfg_rej exceeds allocated buffer"); + p_data = p_data_end; /* force loop exit */ + break; + } + } + p_data += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; + } + /* bad length; force loop exit */ + else { + p_data = p_data_end; } + break; } + } - len = (uint16_t) (p - p_hci_len - 2); - UINT16_TO_STREAM (p_hci_len, len); + len = (uint16_t)(p - p_hci_len - 2); + UINT16_TO_STREAM(p_hci_len, len); - p_buf->len = len + 4; + p_buf->len = len + 4; - L2CAP_TRACE_DEBUG ("L2CAP - cfg_rej pkt hci_len=%d, l2cap_len=%d", - len, (L2CAP_CMD_OVERHEAD+L2CAP_CONFIG_RSP_LEN+rej_len)); + L2CAP_TRACE_DEBUG("L2CAP - cfg_rej pkt hci_len=%d, l2cap_len=%d", len, + (L2CAP_CMD_OVERHEAD + L2CAP_CONFIG_RSP_LEN + rej_len)); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } /******************************************************************************* @@ -900,51 +840,48 @@ void l2cu_send_peer_config_rej (tL2C_CCB *p_ccb, uint8_t *p_data, uint16_t data_ * Returns void * ******************************************************************************/ -void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf, *p_buf2; - uint8_t *p; +void l2cu_send_peer_disc_req(tL2C_CCB* p_ccb) { + BT_HDR *p_buf, *p_buf2; + uint8_t* p; - if ((!p_ccb) || (p_ccb->p_lcb == NULL)) - { - L2CAP_TRACE_ERROR ("%s L2CAP - ccb or lcb invalid", __func__); - return; - } + if ((!p_ccb) || (p_ccb->p_lcb == NULL)) { + L2CAP_TRACE_ERROR("%s L2CAP - ccb or lcb invalid", __func__); + return; + } - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - p_ccb->local_id = p_ccb->p_lcb->id; + p_ccb->local_id = p_ccb->p_lcb->id; - p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_DISC_REQ_LEN, L2CAP_CMD_DISC_REQ, p_ccb->local_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for disc_req"); - return; - } + p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_DISC_REQ_LEN, + L2CAP_CMD_DISC_REQ, p_ccb->local_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for disc_req"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p, p_ccb->local_cid); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, p_ccb->local_cid); - /* Move all queued data packets to the LCB. In FCR mode, assume the higher - layer checks that all buffers are sent before disconnecting. - */ - if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) - { - while ((p_buf2 = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q)) != NULL) - { - l2cu_set_acl_hci_header (p_buf2, p_ccb); - l2c_link_check_send_pkts (p_ccb->p_lcb, p_ccb, p_buf2); - } + /* Move all queued data packets to the LCB. In FCR mode, assume the higher + layer checks that all buffers are sent before disconnecting. + */ + if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) { + while ((p_buf2 = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q)) != + NULL) { + l2cu_set_acl_hci_header(p_buf2, p_ccb); + l2c_link_check_send_pkts(p_ccb->p_lcb, p_ccb, p_buf2); } + } - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_disc_rsp @@ -959,28 +896,27 @@ void l2cu_send_peer_disc_req (tL2C_CCB *p_ccb) * Returns void * ******************************************************************************/ -void l2cu_send_peer_disc_rsp (tL2C_LCB *p_lcb, uint8_t remote_id, uint16_t local_cid, - uint16_t remote_cid) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_disc_rsp(tL2C_LCB* p_lcb, uint8_t remote_id, + uint16_t local_cid, uint16_t remote_cid) { + BT_HDR* p_buf; + uint8_t* p; - p_buf = l2cu_build_header(p_lcb, L2CAP_DISC_RSP_LEN, L2CAP_CMD_DISC_RSP, remote_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for disc_rsp"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_DISC_RSP_LEN, L2CAP_CMD_DISC_RSP, + remote_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for disc_rsp"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, local_cid); - UINT16_TO_STREAM (p, remote_cid); + UINT16_TO_STREAM(p, local_cid); + UINT16_TO_STREAM(p, remote_cid); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_echo_req @@ -992,32 +928,31 @@ void l2cu_send_peer_disc_rsp (tL2C_LCB *p_lcb, uint8_t remote_id, uint16_t local * Returns void * ******************************************************************************/ -void l2cu_send_peer_echo_req (tL2C_LCB *p_lcb, uint8_t *p_data, uint16_t data_len) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_echo_req(tL2C_LCB* p_lcb, uint8_t* p_data, + uint16_t data_len) { + BT_HDR* p_buf; + uint8_t* p; - p_lcb->id++; - l2cu_adj_id(p_lcb, L2CAP_ADJ_ZERO_ID); /* check for wrap to '0' */ + p_lcb->id++; + l2cu_adj_id(p_lcb, L2CAP_ADJ_ZERO_ID); /* check for wrap to '0' */ - p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_ECHO_REQ_LEN + data_len), L2CAP_CMD_ECHO_REQ, p_lcb->id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for echo_req"); - return; - } + p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_ECHO_REQ_LEN + data_len), + L2CAP_CMD_ECHO_REQ, p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for echo_req"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - if (data_len) - { - ARRAY_TO_STREAM (p, p_data, data_len); - } + if (data_len) { + ARRAY_TO_STREAM(p, p_data, data_len); + } - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_echo_rsp @@ -1028,48 +963,49 @@ void l2cu_send_peer_echo_req (tL2C_LCB *p_lcb, uint8_t *p_data, uint16_t data_le * Returns void * ******************************************************************************/ -void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, uint8_t id, uint8_t *p_data, uint16_t data_len) -{ - BT_HDR *p_buf; - uint8_t *p; - uint16_t maxlen; - /* Filter out duplicate IDs or if available buffers are low (intruder checking) */ - if (!id || id == p_lcb->cur_echo_id) - { - /* Dump this request since it is illegal */ - L2CAP_TRACE_WARNING ("L2CAP ignoring duplicate echo request (%d)", id); - return; - } - else - p_lcb->cur_echo_id = id; - - uint16_t acl_data_size = controller_get_interface()->get_acl_data_size_classic(); - uint16_t acl_packet_size = controller_get_interface()->get_acl_packet_size_classic(); - /* Don't return data if it does not fit in ACL and L2CAP MTU */ - maxlen = (L2CAP_CMD_BUF_SIZE > acl_packet_size) ? - acl_data_size : (uint16_t)L2CAP_CMD_BUF_SIZE; - maxlen -= (uint16_t)(BT_HDR_SIZE + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + - L2CAP_CMD_OVERHEAD + L2CAP_ECHO_RSP_LEN); - - if (data_len > maxlen) - data_len = 0; - - p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_ECHO_RSP_LEN + data_len), L2CAP_CMD_ECHO_RSP, id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for echo_rsp"); - return; - } - - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - - if (data_len) - { - ARRAY_TO_STREAM (p, p_data, data_len); - } - - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); +void l2cu_send_peer_echo_rsp(tL2C_LCB* p_lcb, uint8_t id, uint8_t* p_data, + uint16_t data_len) { + BT_HDR* p_buf; + uint8_t* p; + uint16_t maxlen; + /* Filter out duplicate IDs or if available buffers are low (intruder + * checking) */ + if (!id || id == p_lcb->cur_echo_id) { + /* Dump this request since it is illegal */ + L2CAP_TRACE_WARNING("L2CAP ignoring duplicate echo request (%d)", id); + return; + } else + p_lcb->cur_echo_id = id; + + uint16_t acl_data_size = + controller_get_interface()->get_acl_data_size_classic(); + uint16_t acl_packet_size = + controller_get_interface()->get_acl_packet_size_classic(); + /* Don't return data if it does not fit in ACL and L2CAP MTU */ + maxlen = (L2CAP_CMD_BUF_SIZE > acl_packet_size) + ? acl_data_size + : (uint16_t)L2CAP_CMD_BUF_SIZE; + maxlen -= + (uint16_t)(BT_HDR_SIZE + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + + L2CAP_CMD_OVERHEAD + L2CAP_ECHO_RSP_LEN); + + if (data_len > maxlen) data_len = 0; + + p_buf = l2cu_build_header(p_lcb, (uint16_t)(L2CAP_ECHO_RSP_LEN + data_len), + L2CAP_CMD_ECHO_RSP, id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for echo_rsp"); + return; + } + + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + + if (data_len) { + ARRAY_TO_STREAM(p, p_data, data_len); + } + + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -1081,38 +1017,35 @@ void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, uint8_t id, uint8_t *p_data, uint * Returns void * ******************************************************************************/ -void l2cu_send_peer_info_req (tL2C_LCB *p_lcb, uint16_t info_type) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_info_req(tL2C_LCB* p_lcb, uint16_t info_type) { + BT_HDR* p_buf; + uint8_t* p; - /* check for wrap and/or BRCM ID */ - p_lcb->id++; - l2cu_adj_id(p_lcb, L2CAP_ADJ_ID); + /* check for wrap and/or BRCM ID */ + p_lcb->id++; + l2cu_adj_id(p_lcb, L2CAP_ADJ_ID); - p_buf = l2cu_build_header(p_lcb, 2, L2CAP_CMD_INFO_REQ, p_lcb->id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for info_req"); - return; - } + p_buf = l2cu_build_header(p_lcb, 2, L2CAP_CMD_INFO_REQ, p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for info_req"); + return; + } - L2CAP_TRACE_EVENT ("l2cu_send_peer_info_req: type 0x%04x", info_type); + L2CAP_TRACE_EVENT("l2cu_send_peer_info_req: type 0x%04x", info_type); - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET+HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, info_type); + UINT16_TO_STREAM(p, info_type); - p_lcb->w4_info_rsp = true; - alarm_set_on_queue(p_lcb->info_resp_timer, L2CAP_WAIT_INFO_RSP_TIMEOUT_MS, - l2c_info_resp_timer_timeout, p_lcb, - btu_general_alarm_queue); + p_lcb->w4_info_rsp = true; + alarm_set_on_queue(p_lcb->info_resp_timer, L2CAP_WAIT_INFO_RSP_TIMEOUT_MS, + l2c_info_resp_timer_timeout, p_lcb, + btu_general_alarm_queue); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } - /******************************************************************************* * * Function l2cu_send_peer_info_rsp @@ -1123,115 +1056,107 @@ void l2cu_send_peer_info_req (tL2C_LCB *p_lcb, uint16_t info_type) * Returns void * ******************************************************************************/ -void l2cu_send_peer_info_rsp (tL2C_LCB *p_lcb, uint8_t remote_id, uint16_t info_type) -{ - BT_HDR *p_buf; - uint8_t *p; - uint16_t len = L2CAP_INFO_RSP_LEN; +void l2cu_send_peer_info_rsp(tL2C_LCB* p_lcb, uint8_t remote_id, + uint16_t info_type) { + BT_HDR* p_buf; + uint8_t* p; + uint16_t len = L2CAP_INFO_RSP_LEN; #if (L2CAP_CONFORMANCE_TESTING == TRUE) - if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) - && (l2cb.test_info_resp & (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | - L2CAP_EXTFEA_NO_CRC | L2CAP_EXTFEA_EXT_FLOW_SPEC | - L2CAP_EXTFEA_FIXED_CHNLS | L2CAP_EXTFEA_EXT_WINDOW | - L2CAP_EXTFEA_UCD_RECEPTION )) ) + if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && + (l2cb.test_info_resp & + (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | + L2CAP_EXTFEA_NO_CRC | L2CAP_EXTFEA_EXT_FLOW_SPEC | + L2CAP_EXTFEA_FIXED_CHNLS | L2CAP_EXTFEA_EXT_WINDOW | + L2CAP_EXTFEA_UCD_RECEPTION))) #else - if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) - && (L2CAP_EXTFEA_SUPPORTED_MASK & (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | - L2CAP_EXTFEA_NO_CRC |L2CAP_EXTFEA_FIXED_CHNLS | - L2CAP_EXTFEA_UCD_RECEPTION )) != 0 ) + if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && + (L2CAP_EXTFEA_SUPPORTED_MASK & + (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | + L2CAP_EXTFEA_NO_CRC | L2CAP_EXTFEA_FIXED_CHNLS | + L2CAP_EXTFEA_UCD_RECEPTION)) != 0) #endif - { - len += L2CAP_EXTENDED_FEATURES_ARRAY_SIZE; - } - else if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) - { - len += L2CAP_FIXED_CHNL_ARRAY_SIZE; - } - else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) - { - len += L2CAP_CONNLESS_MTU_INFO_SIZE; - } + { + len += L2CAP_EXTENDED_FEATURES_ARRAY_SIZE; + } else if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) { + len += L2CAP_FIXED_CHNL_ARRAY_SIZE; + } else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) { + len += L2CAP_CONNLESS_MTU_INFO_SIZE; + } - p_buf = l2cu_build_header(p_lcb, len, L2CAP_CMD_INFO_RSP, remote_id); - if (p_buf == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no buffer for info_rsp"); - return; - } + p_buf = l2cu_build_header(p_lcb, len, L2CAP_CMD_INFO_RSP, remote_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no buffer for info_rsp"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, info_type); + UINT16_TO_STREAM(p, info_type); #if (L2CAP_CONFORMANCE_TESTING == TRUE) - if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) - && (l2cb.test_info_resp & ( L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE - | L2CAP_EXTFEA_UCD_RECEPTION )) ) + if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && + (l2cb.test_info_resp & + (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | + L2CAP_EXTFEA_UCD_RECEPTION))) #else - if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) - && (L2CAP_EXTFEA_SUPPORTED_MASK & ( L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE - | L2CAP_EXTFEA_UCD_RECEPTION )) != 0 ) + if ((info_type == L2CAP_EXTENDED_FEATURES_INFO_TYPE) && + (L2CAP_EXTFEA_SUPPORTED_MASK & + (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | + L2CAP_EXTFEA_UCD_RECEPTION)) != 0) #endif - { - UINT16_TO_STREAM (p, L2CAP_INFO_RESP_RESULT_SUCCESS); - if (p_lcb->transport == BT_TRANSPORT_LE) - { - /* optional data are not added for now */ - UINT32_TO_STREAM (p, L2CAP_BLE_EXTFEA_MASK); - } - else - { + { + UINT16_TO_STREAM(p, L2CAP_INFO_RESP_RESULT_SUCCESS); + if (p_lcb->transport == BT_TRANSPORT_LE) { + /* optional data are not added for now */ + UINT32_TO_STREAM(p, L2CAP_BLE_EXTFEA_MASK); + } else { #if (L2CAP_CONFORMANCE_TESTING == TRUE) - UINT32_TO_STREAM (p, l2cb.test_info_resp); + UINT32_TO_STREAM(p, l2cb.test_info_resp); #else #if (L2CAP_NUM_FIXED_CHNLS > 0) - UINT32_TO_STREAM (p, L2CAP_EXTFEA_SUPPORTED_MASK | L2CAP_EXTFEA_FIXED_CHNLS); + UINT32_TO_STREAM(p, + L2CAP_EXTFEA_SUPPORTED_MASK | L2CAP_EXTFEA_FIXED_CHNLS); #else - UINT32_TO_STREAM (p, L2CAP_EXTFEA_SUPPORTED_MASK); + UINT32_TO_STREAM(p, L2CAP_EXTFEA_SUPPORTED_MASK); #endif #endif - } } - else if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) - { - UINT16_TO_STREAM (p, L2CAP_INFO_RESP_RESULT_SUCCESS); - memset (p, 0, L2CAP_FIXED_CHNL_ARRAY_SIZE); + } else if (info_type == L2CAP_FIXED_CHANNELS_INFO_TYPE) { + UINT16_TO_STREAM(p, L2CAP_INFO_RESP_RESULT_SUCCESS); + memset(p, 0, L2CAP_FIXED_CHNL_ARRAY_SIZE); - p[0] = L2CAP_FIXED_CHNL_SIG_BIT; + p[0] = L2CAP_FIXED_CHNL_SIG_BIT; - if ( L2CAP_EXTFEA_SUPPORTED_MASK & L2CAP_EXTFEA_UCD_RECEPTION ) - p[0] |= L2CAP_FIXED_CHNL_CNCTLESS_BIT; + if (L2CAP_EXTFEA_SUPPORTED_MASK & L2CAP_EXTFEA_UCD_RECEPTION) + p[0] |= L2CAP_FIXED_CHNL_CNCTLESS_BIT; #if (L2CAP_NUM_FIXED_CHNLS > 0) - { - int xx; - - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - /* Skip fixed channels not used on BR/EDR-ACL link */ - if((xx >= L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL) && - (xx <= L2CAP_SMP_CID - L2CAP_FIRST_FIXED_CHNL)) - continue; - - if (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL) - p[(xx + L2CAP_FIRST_FIXED_CHNL) / 8] |= 1 << ((xx + L2CAP_FIRST_FIXED_CHNL) % 8); - } - } -#endif - } - else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) { - UINT16_TO_STREAM (p, L2CAP_INFO_RESP_RESULT_SUCCESS); - UINT16_TO_STREAM (p, L2CAP_UCD_MTU); - } - else - { - UINT16_TO_STREAM (p, L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED); /* 'not supported' */ + int xx; + + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + /* Skip fixed channels not used on BR/EDR-ACL link */ + if ((xx >= L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL) && + (xx <= L2CAP_SMP_CID - L2CAP_FIRST_FIXED_CHNL)) + continue; + + if (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL) + p[(xx + L2CAP_FIRST_FIXED_CHNL) / 8] |= + 1 << ((xx + L2CAP_FIRST_FIXED_CHNL) % 8); + } } +#endif + } else if (info_type == L2CAP_CONNLESS_MTU_INFO_TYPE) { + UINT16_TO_STREAM(p, L2CAP_INFO_RESP_RESULT_SUCCESS); + UINT16_TO_STREAM(p, L2CAP_UCD_MTU); + } else { + UINT16_TO_STREAM( + p, L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED); /* 'not supported' */ + } - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /****************************************************************************** @@ -1244,87 +1169,78 @@ void l2cu_send_peer_info_rsp (tL2C_LCB *p_lcb, uint8_t remote_id, uint16_t info_ * Returns None * ******************************************************************************/ -void l2cu_enqueue_ccb (tL2C_CCB *p_ccb) -{ - tL2C_CCB *p_ccb1; - tL2C_CCB_Q *p_q = NULL; +void l2cu_enqueue_ccb(tL2C_CCB* p_ccb) { + tL2C_CCB* p_ccb1; + tL2C_CCB_Q* p_q = NULL; - /* Find out which queue the channel is on - */ - if (p_ccb->p_lcb != NULL) - p_q = &p_ccb->p_lcb->ccb_queue; + /* Find out which queue the channel is on + */ + if (p_ccb->p_lcb != NULL) p_q = &p_ccb->p_lcb->ccb_queue; - if ( (!p_ccb->in_use) || (p_q == NULL) ) - { - L2CAP_TRACE_ERROR ("l2cu_enqueue_ccb CID: 0x%04x ERROR in_use: %u p_lcb: 0x%08x", - p_ccb->local_cid, p_ccb->in_use, p_ccb->p_lcb); - return; - } + if ((!p_ccb->in_use) || (p_q == NULL)) { + L2CAP_TRACE_ERROR( + "l2cu_enqueue_ccb CID: 0x%04x ERROR in_use: %u p_lcb: 0x%08x", + p_ccb->local_cid, p_ccb->in_use, p_ccb->p_lcb); + return; + } - L2CAP_TRACE_DEBUG ("l2cu_enqueue_ccb CID: 0x%04x priority: %d", - p_ccb->local_cid, p_ccb->ccb_priority); + L2CAP_TRACE_DEBUG("l2cu_enqueue_ccb CID: 0x%04x priority: %d", + p_ccb->local_cid, p_ccb->ccb_priority); - /* If the queue is empty, we go at the front */ - if (!p_q->p_first_ccb) - { - p_q->p_first_ccb = p_q->p_last_ccb = p_ccb; - p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; - } - else - { - p_ccb1 = p_q->p_first_ccb; - - while (p_ccb1 != NULL) - { - /* Insert new ccb at the end of the same priority. Lower number, higher priority */ - if (p_ccb->ccb_priority < p_ccb1->ccb_priority) - { - /* Are we at the head of the queue ? */ - if (p_ccb1 == p_q->p_first_ccb) - p_q->p_first_ccb = p_ccb; - else - p_ccb1->p_prev_ccb->p_next_ccb = p_ccb; - - p_ccb->p_next_ccb = p_ccb1; - p_ccb->p_prev_ccb = p_ccb1->p_prev_ccb; - p_ccb1->p_prev_ccb = p_ccb; - break; - } + /* If the queue is empty, we go at the front */ + if (!p_q->p_first_ccb) { + p_q->p_first_ccb = p_q->p_last_ccb = p_ccb; + p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; + } else { + p_ccb1 = p_q->p_first_ccb; + + while (p_ccb1 != NULL) { + /* Insert new ccb at the end of the same priority. Lower number, higher + * priority */ + if (p_ccb->ccb_priority < p_ccb1->ccb_priority) { + /* Are we at the head of the queue ? */ + if (p_ccb1 == p_q->p_first_ccb) + p_q->p_first_ccb = p_ccb; + else + p_ccb1->p_prev_ccb->p_next_ccb = p_ccb; - p_ccb1 = p_ccb1->p_next_ccb; - } + p_ccb->p_next_ccb = p_ccb1; + p_ccb->p_prev_ccb = p_ccb1->p_prev_ccb; + p_ccb1->p_prev_ccb = p_ccb; + break; + } + + p_ccb1 = p_ccb1->p_next_ccb; + } - /* If we are lower then anyone in the list, we go at the end */ - if (!p_ccb1) - { - /* add new ccb at the end of the list */ - p_q->p_last_ccb->p_next_ccb = p_ccb; + /* If we are lower then anyone in the list, we go at the end */ + if (!p_ccb1) { + /* add new ccb at the end of the list */ + p_q->p_last_ccb->p_next_ccb = p_ccb; - p_ccb->p_next_ccb = NULL; - p_ccb->p_prev_ccb = p_q->p_last_ccb; - p_q->p_last_ccb = p_ccb; - } + p_ccb->p_next_ccb = NULL; + p_ccb->p_prev_ccb = p_q->p_last_ccb; + p_q->p_last_ccb = p_ccb; } + } #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - /* Adding CCB into round robin service table of its LCB */ - if (p_ccb->p_lcb != NULL) - { - /* if this is the first channel in this priority group */ - if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb == 0 ) - { - /* Set the first channel to this CCB */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = p_ccb; - /* Set the next serving channel in this group to this CCB */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = p_ccb; - /* Initialize quota of this priority group based on its priority */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota = L2CAP_GET_PRIORITY_QUOTA(p_ccb->ccb_priority); - } - /* increase number of channels in this group */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb++; - } + /* Adding CCB into round robin service table of its LCB */ + if (p_ccb->p_lcb != NULL) { + /* if this is the first channel in this priority group */ + if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb == 0) { + /* Set the first channel to this CCB */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = p_ccb; + /* Set the next serving channel in this group to this CCB */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = p_ccb; + /* Initialize quota of this priority group based on its priority */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota = + L2CAP_GET_PRIORITY_QUOTA(p_ccb->ccb_priority); + } + /* increase number of channels in this group */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb++; + } #endif - } /****************************************************************************** @@ -1336,79 +1252,69 @@ void l2cu_enqueue_ccb (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -void l2cu_dequeue_ccb (tL2C_CCB *p_ccb) -{ - tL2C_CCB_Q *p_q = NULL; +void l2cu_dequeue_ccb(tL2C_CCB* p_ccb) { + tL2C_CCB_Q* p_q = NULL; - L2CAP_TRACE_DEBUG ("l2cu_dequeue_ccb CID: 0x%04x", p_ccb->local_cid); + L2CAP_TRACE_DEBUG("l2cu_dequeue_ccb CID: 0x%04x", p_ccb->local_cid); - /* Find out which queue the channel is on - */ - if (p_ccb->p_lcb != NULL) - p_q = &p_ccb->p_lcb->ccb_queue; + /* Find out which queue the channel is on + */ + if (p_ccb->p_lcb != NULL) p_q = &p_ccb->p_lcb->ccb_queue; - if ( (!p_ccb->in_use) || (p_q == NULL) || (p_q->p_first_ccb == NULL) ) - { - L2CAP_TRACE_ERROR ("l2cu_dequeue_ccb CID: 0x%04x ERROR in_use: %u p_lcb: 0x%08x p_q: 0x%08x p_q->p_first_ccb: 0x%08x", - p_ccb->local_cid, p_ccb->in_use, p_ccb->p_lcb, p_q, p_q ? p_q->p_first_ccb : 0); - return; - } + if ((!p_ccb->in_use) || (p_q == NULL) || (p_q->p_first_ccb == NULL)) { + L2CAP_TRACE_ERROR( + "l2cu_dequeue_ccb CID: 0x%04x ERROR in_use: %u p_lcb: 0x%08x p_q: " + "0x%08x p_q->p_first_ccb: 0x%08x", + p_ccb->local_cid, p_ccb->in_use, p_ccb->p_lcb, p_q, + p_q ? p_q->p_first_ccb : 0); + return; + } #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - /* Removing CCB from round robin service table of its LCB */ - if (p_ccb->p_lcb != NULL) - { - /* decrease number of channels in this priority group */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb--; - - /* if it was the last channel in the priority group */ - if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb == 0 ) - { - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = NULL; - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = NULL; - } - else - { - /* if it is the first channel of this group */ - if ( p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb == p_ccb ) - { - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = p_ccb->p_next_ccb; - } - /* if it is the next serving channel of this group */ - if ( p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb == p_ccb ) - { - /* simply, start serving from the first channel */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb - = p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb; - } - } - } + /* Removing CCB from round robin service table of its LCB */ + if (p_ccb->p_lcb != NULL) { + /* decrease number of channels in this priority group */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb--; + + /* if it was the last channel in the priority group */ + if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb == 0) { + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = NULL; + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = NULL; + } else { + /* if it is the first channel of this group */ + if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb == p_ccb) { + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = + p_ccb->p_next_ccb; + } + /* if it is the next serving channel of this group */ + if (p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb == p_ccb) { + /* simply, start serving from the first channel */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb; + } + } + } #endif - if (p_ccb == p_q->p_first_ccb) - { - /* We are removing the first in a queue */ - p_q->p_first_ccb = p_ccb->p_next_ccb; + if (p_ccb == p_q->p_first_ccb) { + /* We are removing the first in a queue */ + p_q->p_first_ccb = p_ccb->p_next_ccb; - if (p_q->p_first_ccb) - p_q->p_first_ccb->p_prev_ccb = NULL; - else - p_q->p_last_ccb = NULL; - } - else if (p_ccb == p_q->p_last_ccb) - { - /* We are removing the last in a queue */ - p_q->p_last_ccb = p_ccb->p_prev_ccb; - p_q->p_last_ccb->p_next_ccb = NULL; - } + if (p_q->p_first_ccb) + p_q->p_first_ccb->p_prev_ccb = NULL; else - { - /* In the middle of a chain. */ - p_ccb->p_prev_ccb->p_next_ccb = p_ccb->p_next_ccb; - p_ccb->p_next_ccb->p_prev_ccb = p_ccb->p_prev_ccb; - } + p_q->p_last_ccb = NULL; + } else if (p_ccb == p_q->p_last_ccb) { + /* We are removing the last in a queue */ + p_q->p_last_ccb = p_ccb->p_prev_ccb; + p_q->p_last_ccb->p_next_ccb = NULL; + } else { + /* In the middle of a chain. */ + p_ccb->p_prev_ccb->p_next_ccb = p_ccb->p_next_ccb; + p_ccb->p_next_ccb->p_prev_ccb = p_ccb->p_prev_ccb; + } - p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; + p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; } /****************************************************************************** @@ -1420,39 +1326,36 @@ void l2cu_dequeue_ccb (tL2C_CCB *p_ccb) * Returns - * ******************************************************************************/ -void l2cu_change_pri_ccb (tL2C_CCB *p_ccb, tL2CAP_CHNL_PRIORITY priority) -{ - if (p_ccb->ccb_priority != priority) - { - /* If CCB is not the only guy on the queue */ - if ( (p_ccb->p_next_ccb != NULL) || (p_ccb->p_prev_ccb != NULL) ) - { - L2CAP_TRACE_DEBUG ("Update CCB list in logical link"); +void l2cu_change_pri_ccb(tL2C_CCB* p_ccb, tL2CAP_CHNL_PRIORITY priority) { + if (p_ccb->ccb_priority != priority) { + /* If CCB is not the only guy on the queue */ + if ((p_ccb->p_next_ccb != NULL) || (p_ccb->p_prev_ccb != NULL)) { + L2CAP_TRACE_DEBUG("Update CCB list in logical link"); - /* Remove CCB from queue and re-queue it at new priority */ - l2cu_dequeue_ccb (p_ccb); + /* Remove CCB from queue and re-queue it at new priority */ + l2cu_dequeue_ccb(p_ccb); - p_ccb->ccb_priority = priority; - l2cu_enqueue_ccb (p_ccb); - } + p_ccb->ccb_priority = priority; + l2cu_enqueue_ccb(p_ccb); + } #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - else - { - /* If CCB is the only guy on the queue, no need to re-enqueue */ - /* update only round robin service data */ - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb = 0; - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = NULL; - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = NULL; - - p_ccb->ccb_priority = priority; - - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = p_ccb; - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = p_ccb; - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota = L2CAP_GET_PRIORITY_QUOTA(p_ccb->ccb_priority); - p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb = 1; - } -#endif + else { + /* If CCB is the only guy on the queue, no need to re-enqueue */ + /* update only round robin service data */ + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb = 0; + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = NULL; + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = NULL; + + p_ccb->ccb_priority = priority; + + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_first_ccb = p_ccb; + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].p_serve_ccb = p_ccb; + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].quota = + L2CAP_GET_PRIORITY_QUOTA(p_ccb->ccb_priority); + p_ccb->p_lcb->rr_serv[p_ccb->ccb_priority].num_ccb = 1; } +#endif + } } /******************************************************************************* @@ -1466,140 +1369,142 @@ void l2cu_change_pri_ccb (tL2C_CCB *p_ccb, tL2CAP_CHNL_PRIORITY priority) * Returns pointer to CCB, or NULL if none * ******************************************************************************/ -tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, uint16_t cid) -{ - tL2C_CCB *p_ccb; - tL2C_CCB *p_prev; - - L2CAP_TRACE_DEBUG ("l2cu_allocate_ccb: cid 0x%04x", cid); - - if (!l2cb.p_free_ccb_first) - return (NULL); - - /* If a CID was passed in, use that, else take the first free one */ - if (cid == 0) - { - p_ccb = l2cb.p_free_ccb_first; - l2cb.p_free_ccb_first = p_ccb->p_next_ccb; - } - else - { - p_prev = NULL; - - p_ccb = &l2cb.ccb_pool[cid - L2CAP_BASE_APPL_CID]; - - if (p_ccb == l2cb.p_free_ccb_first) - l2cb.p_free_ccb_first = p_ccb->p_next_ccb; - else - { - for (p_prev = l2cb.p_free_ccb_first; p_prev != NULL; p_prev = p_prev->p_next_ccb) - { - if (p_prev->p_next_ccb == p_ccb) - { - p_prev->p_next_ccb = p_ccb->p_next_ccb; - - if (p_ccb == l2cb.p_free_ccb_last) - l2cb.p_free_ccb_last = p_prev; - - break; - } - } - if (p_prev == NULL) - { - L2CAP_TRACE_ERROR ("l2cu_allocate_ccb: could not find CCB for CID 0x%04x in the free list", cid); - return NULL; - } - } - } +tL2C_CCB* l2cu_allocate_ccb(tL2C_LCB* p_lcb, uint16_t cid) { + tL2C_CCB* p_ccb; + tL2C_CCB* p_prev; - p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; - - p_ccb->in_use = true; - - /* Get a CID for the connection */ - p_ccb->local_cid = L2CAP_BASE_APPL_CID + (uint16_t)(p_ccb - l2cb.ccb_pool); + L2CAP_TRACE_DEBUG("l2cu_allocate_ccb: cid 0x%04x", cid); - p_ccb->p_lcb = p_lcb; - p_ccb->p_rcb = NULL; - p_ccb->should_free_rcb = false; + if (!l2cb.p_free_ccb_first) return (NULL); - /* Set priority then insert ccb into LCB queue (if we have an LCB) */ - p_ccb->ccb_priority = L2CAP_CHNL_PRIORITY_LOW; - - if (p_lcb) - l2cu_enqueue_ccb (p_ccb); - - /* clear what peer wants to configure */ - p_ccb->peer_cfg_bits = 0; - - /* Put in default values for configuration */ - memset (&p_ccb->our_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - memset (&p_ccb->peer_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - - /* Put in default values for local/peer configurations */ - p_ccb->our_cfg.flush_to = p_ccb->peer_cfg.flush_to = L2CAP_DEFAULT_FLUSH_TO; - p_ccb->our_cfg.mtu = p_ccb->peer_cfg.mtu = L2CAP_DEFAULT_MTU; - p_ccb->our_cfg.qos.service_type = p_ccb->peer_cfg.qos.service_type = L2CAP_DEFAULT_SERV_TYPE; - p_ccb->our_cfg.qos.token_rate = p_ccb->peer_cfg.qos.token_rate = L2CAP_DEFAULT_TOKEN_RATE; - p_ccb->our_cfg.qos.token_bucket_size = p_ccb->peer_cfg.qos.token_bucket_size = L2CAP_DEFAULT_BUCKET_SIZE; - p_ccb->our_cfg.qos.peak_bandwidth = p_ccb->peer_cfg.qos.peak_bandwidth = L2CAP_DEFAULT_PEAK_BANDWIDTH; - p_ccb->our_cfg.qos.latency = p_ccb->peer_cfg.qos.latency = L2CAP_DEFAULT_LATENCY; - p_ccb->our_cfg.qos.delay_variation = p_ccb->peer_cfg.qos.delay_variation = L2CAP_DEFAULT_DELAY; - - p_ccb->bypass_fcs = 0; - memset (&p_ccb->ertm_info, 0, sizeof(tL2CAP_ERTM_INFO)); - p_ccb->peer_cfg_already_rejected = false; - p_ccb->fcr_cfg_tries = L2CAP_MAX_FCR_CFG_TRIES; - - alarm_free(p_ccb->fcrb.ack_timer); - p_ccb->fcrb.ack_timer = alarm_new("l2c_fcrb.ack_timer"); - - /* CSP408639 Fix: When L2CAP send amp move channel request or receive - * L2CEVT_AMP_MOVE_REQ do following sequence. Send channel move - * request -> Stop retrans/monitor timer -> Change channel state to CST_AMP_MOVING. */ - alarm_free(p_ccb->fcrb.mon_retrans_timer); - p_ccb->fcrb.mon_retrans_timer = alarm_new("l2c_fcrb.mon_retrans_timer"); - - p_ccb->ertm_info.preferred_mode = L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */ - p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_BASIC; /* Default mode for channel is basic mode */ - p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; - p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; - p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; - p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; - p_ccb->max_rx_mtu = L2CAP_MTU_SIZE; - p_ccb->tx_mps = L2CAP_FCR_TX_BUF_SIZE - 32; + /* If a CID was passed in, use that, else take the first free one */ + if (cid == 0) { + p_ccb = l2cb.p_free_ccb_first; + l2cb.p_free_ccb_first = p_ccb->p_next_ccb; + } else { + p_prev = NULL; - p_ccb->xmit_hold_q = fixed_queue_new(SIZE_MAX); - p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX); - p_ccb->fcrb.retrans_q = fixed_queue_new(SIZE_MAX); - p_ccb->fcrb.waiting_for_ack_q = fixed_queue_new(SIZE_MAX); + p_ccb = &l2cb.ccb_pool[cid - L2CAP_BASE_APPL_CID]; - p_ccb->cong_sent = false; - p_ccb->buff_quota = 2; /* This gets set after config */ + if (p_ccb == l2cb.p_free_ccb_first) + l2cb.p_free_ccb_first = p_ccb->p_next_ccb; + else { + for (p_prev = l2cb.p_free_ccb_first; p_prev != NULL; + p_prev = p_prev->p_next_ccb) { + if (p_prev->p_next_ccb == p_ccb) { + p_prev->p_next_ccb = p_ccb->p_next_ccb; - /* If CCB was reserved Config_Done can already have some value */ - if (cid == 0) - p_ccb->config_done = 0; - else - { - L2CAP_TRACE_DEBUG ("l2cu_allocate_ccb: cid 0x%04x config_done:0x%x", cid, p_ccb->config_done); - } + if (p_ccb == l2cb.p_free_ccb_last) l2cb.p_free_ccb_last = p_prev; - p_ccb->chnl_state = CST_CLOSED; - p_ccb->flags = 0; - p_ccb->tx_data_rate = L2CAP_CHNL_DATA_RATE_LOW; - p_ccb->rx_data_rate = L2CAP_CHNL_DATA_RATE_LOW; + break; + } + } + if (p_prev == NULL) { + L2CAP_TRACE_ERROR( + "l2cu_allocate_ccb: could not find CCB for CID 0x%04x in the free " + "list", + cid); + return NULL; + } + } + } + + p_ccb->p_next_ccb = p_ccb->p_prev_ccb = NULL; + + p_ccb->in_use = true; + + /* Get a CID for the connection */ + p_ccb->local_cid = L2CAP_BASE_APPL_CID + (uint16_t)(p_ccb - l2cb.ccb_pool); + + p_ccb->p_lcb = p_lcb; + p_ccb->p_rcb = NULL; + p_ccb->should_free_rcb = false; + + /* Set priority then insert ccb into LCB queue (if we have an LCB) */ + p_ccb->ccb_priority = L2CAP_CHNL_PRIORITY_LOW; + + if (p_lcb) l2cu_enqueue_ccb(p_ccb); + + /* clear what peer wants to configure */ + p_ccb->peer_cfg_bits = 0; + + /* Put in default values for configuration */ + memset(&p_ccb->our_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + memset(&p_ccb->peer_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + + /* Put in default values for local/peer configurations */ + p_ccb->our_cfg.flush_to = p_ccb->peer_cfg.flush_to = L2CAP_DEFAULT_FLUSH_TO; + p_ccb->our_cfg.mtu = p_ccb->peer_cfg.mtu = L2CAP_DEFAULT_MTU; + p_ccb->our_cfg.qos.service_type = p_ccb->peer_cfg.qos.service_type = + L2CAP_DEFAULT_SERV_TYPE; + p_ccb->our_cfg.qos.token_rate = p_ccb->peer_cfg.qos.token_rate = + L2CAP_DEFAULT_TOKEN_RATE; + p_ccb->our_cfg.qos.token_bucket_size = p_ccb->peer_cfg.qos.token_bucket_size = + L2CAP_DEFAULT_BUCKET_SIZE; + p_ccb->our_cfg.qos.peak_bandwidth = p_ccb->peer_cfg.qos.peak_bandwidth = + L2CAP_DEFAULT_PEAK_BANDWIDTH; + p_ccb->our_cfg.qos.latency = p_ccb->peer_cfg.qos.latency = + L2CAP_DEFAULT_LATENCY; + p_ccb->our_cfg.qos.delay_variation = p_ccb->peer_cfg.qos.delay_variation = + L2CAP_DEFAULT_DELAY; + + p_ccb->bypass_fcs = 0; + memset(&p_ccb->ertm_info, 0, sizeof(tL2CAP_ERTM_INFO)); + p_ccb->peer_cfg_already_rejected = false; + p_ccb->fcr_cfg_tries = L2CAP_MAX_FCR_CFG_TRIES; + + alarm_free(p_ccb->fcrb.ack_timer); + p_ccb->fcrb.ack_timer = alarm_new("l2c_fcrb.ack_timer"); + + /* CSP408639 Fix: When L2CAP send amp move channel request or receive + * L2CEVT_AMP_MOVE_REQ do following sequence. Send channel move + * request -> Stop retrans/monitor timer -> Change channel state to + * CST_AMP_MOVING. */ + alarm_free(p_ccb->fcrb.mon_retrans_timer); + p_ccb->fcrb.mon_retrans_timer = alarm_new("l2c_fcrb.mon_retrans_timer"); + + p_ccb->ertm_info.preferred_mode = + L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */ + p_ccb->ertm_info.allowed_modes = + L2CAP_FCR_CHAN_OPT_BASIC; /* Default mode for channel is basic mode */ + p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; + p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; + p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; + p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; + p_ccb->max_rx_mtu = L2CAP_MTU_SIZE; + p_ccb->tx_mps = L2CAP_FCR_TX_BUF_SIZE - 32; + + p_ccb->xmit_hold_q = fixed_queue_new(SIZE_MAX); + p_ccb->fcrb.srej_rcv_hold_q = fixed_queue_new(SIZE_MAX); + p_ccb->fcrb.retrans_q = fixed_queue_new(SIZE_MAX); + p_ccb->fcrb.waiting_for_ack_q = fixed_queue_new(SIZE_MAX); + + p_ccb->cong_sent = false; + p_ccb->buff_quota = 2; /* This gets set after config */ + + /* If CCB was reserved Config_Done can already have some value */ + if (cid == 0) + p_ccb->config_done = 0; + else { + L2CAP_TRACE_DEBUG("l2cu_allocate_ccb: cid 0x%04x config_done:0x%x", cid, + p_ccb->config_done); + } + + p_ccb->chnl_state = CST_CLOSED; + p_ccb->flags = 0; + p_ccb->tx_data_rate = L2CAP_CHNL_DATA_RATE_LOW; + p_ccb->rx_data_rate = L2CAP_CHNL_DATA_RATE_LOW; #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - p_ccb->is_flushable = false; + p_ccb->is_flushable = false; #endif - alarm_free(p_ccb->l2c_ccb_timer); - p_ccb->l2c_ccb_timer = alarm_new("l2c.l2c_ccb_timer"); + alarm_free(p_ccb->l2c_ccb_timer); + p_ccb->l2c_ccb_timer = alarm_new("l2c.l2c_ccb_timer"); - l2c_link_adjust_chnl_allocation (); + l2c_link_adjust_chnl_allocation(); - return (p_ccb); + return (p_ccb); } /******************************************************************************* @@ -1615,37 +1520,33 @@ tL2C_CCB *l2cu_allocate_ccb (tL2C_LCB *p_lcb, uint16_t cid) * false if there's one or more pending CCB's exist * ******************************************************************************/ -bool l2cu_start_post_bond_timer (uint16_t handle) -{ - tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle); +bool l2cu_start_post_bond_timer(uint16_t handle) { + tL2C_LCB* p_lcb = l2cu_find_lcb_by_handle(handle); - if (!p_lcb) - return (true); + if (!p_lcb) return (true); - p_lcb->is_bonding = false; + p_lcb->is_bonding = false; - /* Only start timer if no control blocks allocated */ - if (p_lcb->ccb_queue.p_first_ccb != NULL) - return (false); + /* Only start timer if no control blocks allocated */ + if (p_lcb->ccb_queue.p_first_ccb != NULL) return (false); - /* If no channels on the connection, start idle timeout */ - if ((p_lcb->link_state == LST_CONNECTED) || - (p_lcb->link_state == LST_CONNECTING) || - (p_lcb->link_state == LST_DISCONNECTING)) { - period_ms_t timeout_ms = L2CAP_BONDING_TIMEOUT * 1000; + /* If no channels on the connection, start idle timeout */ + if ((p_lcb->link_state == LST_CONNECTED) || + (p_lcb->link_state == LST_CONNECTING) || + (p_lcb->link_state == LST_DISCONNECTING)) { + period_ms_t timeout_ms = L2CAP_BONDING_TIMEOUT * 1000; - if (p_lcb->idle_timeout == 0) { - btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER); - p_lcb->link_state = LST_DISCONNECTING; - timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; - } - alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - return (true); + if (p_lcb->idle_timeout == 0) { + btsnd_hcic_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); + p_lcb->link_state = LST_DISCONNECTING; + timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; } + alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, l2c_lcb_timer_timeout, + p_lcb, btu_general_alarm_queue); + return (true); + } - return (false); + return (false); } /******************************************************************************* @@ -1659,87 +1560,74 @@ bool l2cu_start_post_bond_timer (uint16_t handle) * Returns void * ******************************************************************************/ -void l2cu_release_ccb (tL2C_CCB *p_ccb) -{ - tL2C_LCB *p_lcb = p_ccb->p_lcb; - tL2C_RCB *p_rcb = p_ccb->p_rcb; +void l2cu_release_ccb(tL2C_CCB* p_ccb) { + tL2C_LCB* p_lcb = p_ccb->p_lcb; + tL2C_RCB* p_rcb = p_ccb->p_rcb; - L2CAP_TRACE_DEBUG ("l2cu_release_ccb: cid 0x%04x in_use: %u", p_ccb->local_cid, p_ccb->in_use); + L2CAP_TRACE_DEBUG("l2cu_release_ccb: cid 0x%04x in_use: %u", + p_ccb->local_cid, p_ccb->in_use); - /* If already released, could be race condition */ - if (!p_ccb->in_use) - return; + /* If already released, could be race condition */ + if (!p_ccb->in_use) return; - if (p_rcb && (p_rcb->psm != p_rcb->real_psm)) - { - btm_sec_clr_service_by_psm(p_rcb->psm); - } + if (p_rcb && (p_rcb->psm != p_rcb->real_psm)) { + btm_sec_clr_service_by_psm(p_rcb->psm); + } - if (p_ccb->should_free_rcb) - { - osi_free(p_rcb); - p_ccb->p_rcb = NULL; - p_ccb->should_free_rcb = false; - } + if (p_ccb->should_free_rcb) { + osi_free(p_rcb); + p_ccb->p_rcb = NULL; + p_ccb->should_free_rcb = false; + } - btm_sec_clr_temp_auth_service (p_lcb->remote_bd_addr); + btm_sec_clr_temp_auth_service(p_lcb->remote_bd_addr); - /* Free the timer */ - alarm_free(p_ccb->l2c_ccb_timer); - p_ccb->l2c_ccb_timer = NULL; + /* Free the timer */ + alarm_free(p_ccb->l2c_ccb_timer); + p_ccb->l2c_ccb_timer = NULL; - fixed_queue_free(p_ccb->xmit_hold_q, osi_free); - p_ccb->xmit_hold_q = NULL; + fixed_queue_free(p_ccb->xmit_hold_q, osi_free); + p_ccb->xmit_hold_q = NULL; - l2c_fcr_cleanup (p_ccb); + l2c_fcr_cleanup(p_ccb); - /* Channel may not be assigned to any LCB if it was just pre-reserved */ - if ( (p_lcb) && - ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) + /* Channel may not be assigned to any LCB if it was just pre-reserved */ + if ((p_lcb) && ((p_ccb->local_cid >= L2CAP_BASE_APPL_CID) #if (L2CAP_UCD_INCLUDED == TRUE) - ||(p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) + || (p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) #endif - ) - ) - { - l2cu_dequeue_ccb (p_ccb); - - /* Delink the CCB from the LCB */ - p_ccb->p_lcb = NULL; - } - - /* Put the CCB back on the free pool */ - if (!l2cb.p_free_ccb_first) - { - l2cb.p_free_ccb_first = p_ccb; - l2cb.p_free_ccb_last = p_ccb; - p_ccb->p_next_ccb = NULL; - p_ccb->p_prev_ccb = NULL; - } - else - { - p_ccb->p_next_ccb = NULL; - p_ccb->p_prev_ccb = l2cb.p_free_ccb_last; - l2cb.p_free_ccb_last->p_next_ccb = p_ccb; - l2cb.p_free_ccb_last = p_ccb; - } - - /* Flag as not in use */ - p_ccb->in_use = false; - - /* If no channels on the connection, start idle timeout */ - if ((p_lcb) && p_lcb->in_use && (p_lcb->link_state == LST_CONNECTED)) - { - if (!p_lcb->ccb_queue.p_first_ccb) - { - l2cu_no_dynamic_ccbs (p_lcb); - } - else - { - /* Link is still active, adjust channel quotas. */ - l2c_link_adjust_chnl_allocation (); - } + )) { + l2cu_dequeue_ccb(p_ccb); + + /* Delink the CCB from the LCB */ + p_ccb->p_lcb = NULL; + } + + /* Put the CCB back on the free pool */ + if (!l2cb.p_free_ccb_first) { + l2cb.p_free_ccb_first = p_ccb; + l2cb.p_free_ccb_last = p_ccb; + p_ccb->p_next_ccb = NULL; + p_ccb->p_prev_ccb = NULL; + } else { + p_ccb->p_next_ccb = NULL; + p_ccb->p_prev_ccb = l2cb.p_free_ccb_last; + l2cb.p_free_ccb_last->p_next_ccb = p_ccb; + l2cb.p_free_ccb_last = p_ccb; + } + + /* Flag as not in use */ + p_ccb->in_use = false; + + /* If no channels on the connection, start idle timeout */ + if ((p_lcb) && p_lcb->in_use && (p_lcb->link_state == LST_CONNECTED)) { + if (!p_lcb->ccb_queue.p_first_ccb) { + l2cu_no_dynamic_ccbs(p_lcb); + } else { + /* Link is still active, adjust channel quotas. */ + l2c_link_adjust_chnl_allocation(); } + } } /******************************************************************************* @@ -1752,24 +1640,19 @@ void l2cu_release_ccb (tL2C_CCB *p_ccb) * Returns pointer to matched CCB, or NULL if no match * ******************************************************************************/ -tL2C_CCB *l2cu_find_ccb_by_remote_cid (tL2C_LCB *p_lcb, uint16_t remote_cid) -{ - tL2C_CCB *p_ccb; +tL2C_CCB* l2cu_find_ccb_by_remote_cid(tL2C_LCB* p_lcb, uint16_t remote_cid) { + tL2C_CCB* p_ccb; - /* If LCB is NULL, look through all active links */ - if (!p_lcb) - { - return NULL; - } - else - { - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - if ((p_ccb->in_use) && (p_ccb->remote_cid == remote_cid)) - return (p_ccb); - } + /* If LCB is NULL, look through all active links */ + if (!p_lcb) { + return NULL; + } else { + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) + if ((p_ccb->in_use) && (p_ccb->remote_cid == remote_cid)) return (p_ccb); + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } /******************************************************************************* @@ -1782,26 +1665,23 @@ tL2C_CCB *l2cu_find_ccb_by_remote_cid (tL2C_LCB *p_lcb, uint16_t remote_cid) * Returns Pointer to the RCB or NULL if not found * ******************************************************************************/ -tL2C_RCB *l2cu_allocate_rcb (uint16_t psm) -{ - tL2C_RCB *p_rcb = &l2cb.rcb_pool[0]; - uint16_t xx; +tL2C_RCB* l2cu_allocate_rcb(uint16_t psm) { + tL2C_RCB* p_rcb = &l2cb.rcb_pool[0]; + uint16_t xx; - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if (!p_rcb->in_use) - { - p_rcb->in_use = true; - p_rcb->psm = psm; + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if (!p_rcb->in_use) { + p_rcb->in_use = true; + p_rcb->psm = psm; #if (L2CAP_UCD_INCLUDED == TRUE) - p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; + p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; #endif - return (p_rcb); - } + return (p_rcb); } + } - /* If here, no free RCB found */ - return (NULL); + /* If here, no free RCB found */ + return (NULL); } /******************************************************************************* @@ -1814,26 +1694,23 @@ tL2C_RCB *l2cu_allocate_rcb (uint16_t psm) * Returns Pointer to the BLE RCB or NULL if not found * ******************************************************************************/ -tL2C_RCB *l2cu_allocate_ble_rcb (uint16_t psm) -{ - tL2C_RCB *p_rcb = &l2cb.ble_rcb_pool[0]; - uint16_t xx; +tL2C_RCB* l2cu_allocate_ble_rcb(uint16_t psm) { + tL2C_RCB* p_rcb = &l2cb.ble_rcb_pool[0]; + uint16_t xx; - for (xx = 0; xx < BLE_MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if (!p_rcb->in_use) - { - p_rcb->in_use = true; - p_rcb->psm = psm; + for (xx = 0; xx < BLE_MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if (!p_rcb->in_use) { + p_rcb->in_use = true; + p_rcb->psm = psm; #if (L2CAP_UCD_INCLUDED == TRUE) - p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; + p_rcb->ucd.state = L2C_UCD_STATE_UNUSED; #endif - return (p_rcb); - } + return (p_rcb); } + } - /* If here, no free RCB found */ - return (NULL); + /* If here, no free RCB found */ + return (NULL); } /******************************************************************************* @@ -1845,13 +1722,11 @@ tL2C_RCB *l2cu_allocate_ble_rcb (uint16_t psm) * Returns void * ******************************************************************************/ -void l2cu_release_rcb (tL2C_RCB *p_rcb) -{ - p_rcb->in_use = false; - p_rcb->psm = 0; +void l2cu_release_rcb(tL2C_RCB* p_rcb) { + p_rcb->in_use = false; + p_rcb->psm = 0; } - /******************************************************************************* * * Function l2cu_disconnect_chnl @@ -1861,29 +1736,25 @@ void l2cu_release_rcb (tL2C_RCB *p_rcb) * expiring. * ******************************************************************************/ -void l2cu_disconnect_chnl (tL2C_CCB *p_ccb) -{ - uint16_t local_cid = p_ccb->local_cid; +void l2cu_disconnect_chnl(tL2C_CCB* p_ccb) { + uint16_t local_cid = p_ccb->local_cid; - if (local_cid >= L2CAP_BASE_APPL_CID) - { - tL2CA_DISCONNECT_IND_CB *p_disc_cb = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; + if (local_cid >= L2CAP_BASE_APPL_CID) { + tL2CA_DISCONNECT_IND_CB* p_disc_cb = + p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - L2CAP_TRACE_WARNING ("L2CAP - disconnect_chnl CID: 0x%04x", local_cid); + L2CAP_TRACE_WARNING("L2CAP - disconnect_chnl CID: 0x%04x", local_cid); - l2cu_send_peer_disc_req (p_ccb); + l2cu_send_peer_disc_req(p_ccb); - l2cu_release_ccb (p_ccb); - - (*p_disc_cb)(local_cid, false); - } - else - { - /* failure on the AMP channel, probably need to disconnect ACL */ - L2CAP_TRACE_ERROR ("L2CAP - disconnect_chnl CID: 0x%04x Ignored", local_cid); - } -} + l2cu_release_ccb(p_ccb); + (*p_disc_cb)(local_cid, false); + } else { + /* failure on the AMP channel, probably need to disconnect ACL */ + L2CAP_TRACE_ERROR("L2CAP - disconnect_chnl CID: 0x%04x Ignored", local_cid); + } +} /******************************************************************************* * @@ -1895,19 +1766,16 @@ void l2cu_disconnect_chnl (tL2C_CCB *p_ccb) * Returns Pointer to the RCB or NULL if not found * ******************************************************************************/ -tL2C_RCB *l2cu_find_rcb_by_psm (uint16_t psm) -{ - tL2C_RCB *p_rcb = &l2cb.rcb_pool[0]; - uint16_t xx; +tL2C_RCB* l2cu_find_rcb_by_psm(uint16_t psm) { + tL2C_RCB* p_rcb = &l2cb.rcb_pool[0]; + uint16_t xx; - for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if ((p_rcb->in_use) && (p_rcb->psm == psm)) - return (p_rcb); - } + for (xx = 0; xx < MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if ((p_rcb->in_use) && (p_rcb->psm == psm)) return (p_rcb); + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } /******************************************************************************* @@ -1920,19 +1788,16 @@ tL2C_RCB *l2cu_find_rcb_by_psm (uint16_t psm) * Returns Pointer to the BLE RCB or NULL if not found * ******************************************************************************/ -tL2C_RCB *l2cu_find_ble_rcb_by_psm (uint16_t psm) -{ - tL2C_RCB *p_rcb = &l2cb.ble_rcb_pool[0]; - uint16_t xx; +tL2C_RCB* l2cu_find_ble_rcb_by_psm(uint16_t psm) { + tL2C_RCB* p_rcb = &l2cb.ble_rcb_pool[0]; + uint16_t xx; - for (xx = 0; xx < BLE_MAX_L2CAP_CLIENTS; xx++, p_rcb++) - { - if ((p_rcb->in_use) && (p_rcb->psm == psm)) - return (p_rcb); - } + for (xx = 0; xx < BLE_MAX_L2CAP_CLIENTS; xx++, p_rcb++) { + if ((p_rcb->in_use) && (p_rcb->psm == psm)) return (p_rcb); + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } /******************************************************************************* @@ -1956,129 +1821,106 @@ tL2C_RCB *l2cu_find_ble_rcb_by_psm (uint16_t psm) * be closed. * ******************************************************************************/ -uint8_t l2cu_process_peer_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - bool mtu_ok = true; - bool qos_type_ok = true; - bool flush_to_ok = true; - bool fcr_ok = true; - uint8_t fcr_status; - - /* Ignore FCR parameters for basic mode */ - if (!p_cfg->fcr_present) - p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; - - /* Save the MTU that our peer can receive */ - if (p_cfg->mtu_present) - { - /* Make sure MTU is at least the minimum */ - if (p_cfg->mtu >= L2CAP_MIN_MTU) - { - /* In basic mode, limit the MTU to our buffer size */ - if ( (p_cfg->fcr_present == false) && (p_cfg->mtu > L2CAP_MTU_SIZE) ) - p_cfg->mtu = L2CAP_MTU_SIZE; - - /* Save the accepted value in case of renegotiation */ - p_ccb->peer_cfg.mtu = p_cfg->mtu; - p_ccb->peer_cfg.mtu_present = true; - p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_MTU; - } - else /* Illegal MTU value */ - { - p_cfg->mtu = L2CAP_MIN_MTU; - mtu_ok = false; - } - } - /* Reload mtu from a previously accepted config request */ - else if (p_ccb->peer_cfg.mtu_present) +uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + bool mtu_ok = true; + bool qos_type_ok = true; + bool flush_to_ok = true; + bool fcr_ok = true; + uint8_t fcr_status; + + /* Ignore FCR parameters for basic mode */ + if (!p_cfg->fcr_present) p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; + + /* Save the MTU that our peer can receive */ + if (p_cfg->mtu_present) { + /* Make sure MTU is at least the minimum */ + if (p_cfg->mtu >= L2CAP_MIN_MTU) { + /* In basic mode, limit the MTU to our buffer size */ + if ((p_cfg->fcr_present == false) && (p_cfg->mtu > L2CAP_MTU_SIZE)) + p_cfg->mtu = L2CAP_MTU_SIZE; + + /* Save the accepted value in case of renegotiation */ + p_ccb->peer_cfg.mtu = p_cfg->mtu; + p_ccb->peer_cfg.mtu_present = true; + p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_MTU; + } else /* Illegal MTU value */ + { + p_cfg->mtu = L2CAP_MIN_MTU; + mtu_ok = false; + } + } + /* Reload mtu from a previously accepted config request */ + else if (p_ccb->peer_cfg.mtu_present) { + p_cfg->mtu_present = true; + p_cfg->mtu = p_ccb->peer_cfg.mtu; + } + + /* Verify that the flush timeout is a valid value (0 is illegal) */ + if (p_cfg->flush_to_present) { + if (!p_cfg->flush_to) { + p_cfg->flush_to = 0xFFFF; /* Infinite retransmissions (spec default) */ + flush_to_ok = false; + } else /* Save the accepted value in case of renegotiation */ + { + p_ccb->peer_cfg.flush_to_present = true; + p_ccb->peer_cfg.flush_to = p_cfg->flush_to; + p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FLUSH_TO; + } + } + /* Reload flush_to from a previously accepted config request */ + else if (p_ccb->peer_cfg.flush_to_present) { + p_cfg->flush_to_present = true; + p_cfg->flush_to = p_ccb->peer_cfg.flush_to; + } + + /* Save the QOS settings the the peer is using */ + if (p_cfg->qos_present) { + /* Make sure service type is not a reserved value; otherwise let upper + layer decide if acceptable + */ + if (p_cfg->qos.service_type <= GUARANTEED) { + p_ccb->peer_cfg.qos = p_cfg->qos; + p_ccb->peer_cfg.qos_present = true; + p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_QOS; + } else /* Illegal service type value */ { - p_cfg->mtu_present = true; - p_cfg->mtu = p_ccb->peer_cfg.mtu; + p_cfg->qos.service_type = BEST_EFFORT; + qos_type_ok = false; } + } + /* Reload QOS from a previously accepted config request */ + else if (p_ccb->peer_cfg.qos_present) { + p_cfg->qos_present = true; + p_cfg->qos = p_ccb->peer_cfg.qos; + } - /* Verify that the flush timeout is a valid value (0 is illegal) */ - if (p_cfg->flush_to_present) - { - if (!p_cfg->flush_to) - { - p_cfg->flush_to = 0xFFFF; /* Infinite retransmissions (spec default) */ - flush_to_ok = false; - } - else /* Save the accepted value in case of renegotiation */ - { - p_ccb->peer_cfg.flush_to_present = true; - p_ccb->peer_cfg.flush_to = p_cfg->flush_to; - p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_FLUSH_TO; - } - } - /* Reload flush_to from a previously accepted config request */ - else if (p_ccb->peer_cfg.flush_to_present) - { - p_cfg->flush_to_present = true; - p_cfg->flush_to = p_ccb->peer_cfg.flush_to; - } + fcr_status = l2c_fcr_process_peer_cfg_req(p_ccb, p_cfg); + if (fcr_status == L2CAP_PEER_CFG_DISCONNECT) { + /* Notify caller to disconnect the channel (incompatible modes) */ + p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; + p_cfg->mtu_present = p_cfg->qos_present = p_cfg->flush_to_present = 0; - /* Save the QOS settings the the peer is using */ - if (p_cfg->qos_present) - { - /* Make sure service type is not a reserved value; otherwise let upper - layer decide if acceptable - */ - if (p_cfg->qos.service_type <= GUARANTEED) - { - p_ccb->peer_cfg.qos = p_cfg->qos; - p_ccb->peer_cfg.qos_present = true; - p_ccb->peer_cfg_bits |= L2CAP_CH_CFG_MASK_QOS; - } - else /* Illegal service type value */ - { - p_cfg->qos.service_type = BEST_EFFORT; - qos_type_ok = false; - } - } - /* Reload QOS from a previously accepted config request */ - else if (p_ccb->peer_cfg.qos_present) - { - p_cfg->qos_present = true; - p_cfg->qos = p_ccb->peer_cfg.qos; - } + return (L2CAP_PEER_CFG_DISCONNECT); + } - fcr_status = l2c_fcr_process_peer_cfg_req(p_ccb, p_cfg); - if (fcr_status == L2CAP_PEER_CFG_DISCONNECT) - { - /* Notify caller to disconnect the channel (incompatible modes) */ - p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; - p_cfg->mtu_present = p_cfg->qos_present = p_cfg->flush_to_present = 0; + fcr_ok = (fcr_status == L2CAP_PEER_CFG_OK); - return (L2CAP_PEER_CFG_DISCONNECT); - } + /* Return any unacceptable parameters */ + if (mtu_ok && flush_to_ok && qos_type_ok && fcr_ok) { + l2cu_adjust_out_mps(p_ccb); + return (L2CAP_PEER_CFG_OK); + } else { + p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - fcr_ok = (fcr_status == L2CAP_PEER_CFG_OK); + if (mtu_ok) p_cfg->mtu_present = false; + if (flush_to_ok) p_cfg->flush_to_present = false; + if (qos_type_ok) p_cfg->qos_present = false; + if (fcr_ok) p_cfg->fcr_present = false; - /* Return any unacceptable parameters */ - if (mtu_ok && flush_to_ok && qos_type_ok && fcr_ok) - { - l2cu_adjust_out_mps (p_ccb); - return (L2CAP_PEER_CFG_OK); - } - else - { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - - if (mtu_ok) - p_cfg->mtu_present = false; - if (flush_to_ok) - p_cfg->flush_to_present = false; - if (qos_type_ok) - p_cfg->qos_present = false; - if (fcr_ok) - p_cfg->fcr_present = false; - - return (L2CAP_PEER_CFG_UNACCEPTABLE); - } + return (L2CAP_PEER_CFG_UNACCEPTABLE); + } } - /******************************************************************************* * * Function l2cu_process_peer_cfg_rsp @@ -2090,30 +1932,32 @@ uint8_t l2cu_process_peer_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_process_peer_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - /* If we wanted QoS and the peer sends us a positive response with QoS, use his values */ - if ( (p_cfg->qos_present) && (p_ccb->our_cfg.qos_present) ) - p_ccb->our_cfg.qos = p_cfg->qos; +void l2cu_process_peer_cfg_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + /* If we wanted QoS and the peer sends us a positive response with QoS, use + * his values */ + if ((p_cfg->qos_present) && (p_ccb->our_cfg.qos_present)) + p_ccb->our_cfg.qos = p_cfg->qos; - if (p_cfg->fcr_present) - { - /* Save the retransmission and monitor timeout values */ - if (p_cfg->fcr.mode == L2CAP_FCR_ERTM_MODE) - { - p_ccb->peer_cfg.fcr.rtrans_tout = p_cfg->fcr.rtrans_tout; - p_ccb->peer_cfg.fcr.mon_tout = p_cfg->fcr.mon_tout; - } + if (p_cfg->fcr_present) { + /* Save the retransmission and monitor timeout values */ + if (p_cfg->fcr.mode == L2CAP_FCR_ERTM_MODE) { + p_ccb->peer_cfg.fcr.rtrans_tout = p_cfg->fcr.rtrans_tout; + p_ccb->peer_cfg.fcr.mon_tout = p_cfg->fcr.mon_tout; + } - /* Calculate the max number of packets for which we can delay sending an ack */ - if (p_cfg->fcr.tx_win_sz < p_ccb->our_cfg.fcr.tx_win_sz) - p_ccb->fcrb.max_held_acks = p_cfg->fcr.tx_win_sz / 3; - else - p_ccb->fcrb.max_held_acks = p_ccb->our_cfg.fcr.tx_win_sz / 3; + /* Calculate the max number of packets for which we can delay sending an ack + */ + if (p_cfg->fcr.tx_win_sz < p_ccb->our_cfg.fcr.tx_win_sz) + p_ccb->fcrb.max_held_acks = p_cfg->fcr.tx_win_sz / 3; + else + p_ccb->fcrb.max_held_acks = p_ccb->our_cfg.fcr.tx_win_sz / 3; - L2CAP_TRACE_DEBUG ("l2cu_process_peer_cfg_rsp(): peer tx_win_sz: %d, our tx_win_sz: %d, max_held_acks: %d", - p_cfg->fcr.tx_win_sz, p_ccb->our_cfg.fcr.tx_win_sz, p_ccb->fcrb.max_held_acks); - } + L2CAP_TRACE_DEBUG( + "l2cu_process_peer_cfg_rsp(): peer tx_win_sz: %d, our tx_win_sz: %d, " + "max_held_acks: %d", + p_cfg->fcr.tx_win_sz, p_ccb->our_cfg.fcr.tx_win_sz, + p_ccb->fcrb.max_held_acks); + } } /******************************************************************************* @@ -2127,88 +1971,77 @@ void l2cu_process_peer_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_process_our_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - tL2C_LCB *p_lcb; - uint16_t hci_flush_to; - - /* Save the QOS settings we are using for transmit */ - if (p_cfg->qos_present) - { - p_ccb->our_cfg.qos_present = true; - p_ccb->our_cfg.qos = p_cfg->qos; - } - - if (p_cfg->fcr_present) - { - /* Override FCR options if attempting streaming or basic */ - if (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE) - memset(&p_cfg->fcr, 0, sizeof(tL2CAP_FCR_OPTS)); - else - { - /* On BR/EDR, timer values are zero in config request */ - /* On class 2 AMP, timer value in config request shall be non-0 processing time */ - /* timer value in config response shall be greater than received processing time */ - p_cfg->fcr.mon_tout = p_cfg->fcr.rtrans_tout = 0; - - if (p_cfg->fcr.mode == L2CAP_FCR_STREAM_MODE) - p_cfg->fcr.max_transmit = p_cfg->fcr.tx_win_sz = 0; - } - - /* Set the threshold to send acks (may be updated in the cfg response) */ - p_ccb->fcrb.max_held_acks = p_cfg->fcr.tx_win_sz / 3; - - /* Include FCS option only if peer can handle it */ - if (p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_NO_CRC) - { - /* FCS check can be bypassed if peer also desires to bypass */ - if (p_cfg->fcs_present && p_cfg->fcs == L2CAP_CFG_FCS_BYPASS) - p_ccb->bypass_fcs |= L2CAP_CFG_FCS_OUR; - } - else - p_cfg->fcs_present = false; - } - else - { - p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; - } +void l2cu_process_our_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + tL2C_LCB* p_lcb; + uint16_t hci_flush_to; + + /* Save the QOS settings we are using for transmit */ + if (p_cfg->qos_present) { + p_ccb->our_cfg.qos_present = true; + p_ccb->our_cfg.qos = p_cfg->qos; + } + + if (p_cfg->fcr_present) { + /* Override FCR options if attempting streaming or basic */ + if (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE) + memset(&p_cfg->fcr, 0, sizeof(tL2CAP_FCR_OPTS)); + else { + /* On BR/EDR, timer values are zero in config request */ + /* On class 2 AMP, timer value in config request shall be non-0 processing + * time */ + /* timer value in config response shall be greater than + * received processing time */ + p_cfg->fcr.mon_tout = p_cfg->fcr.rtrans_tout = 0; + + if (p_cfg->fcr.mode == L2CAP_FCR_STREAM_MODE) + p_cfg->fcr.max_transmit = p_cfg->fcr.tx_win_sz = 0; + } + + /* Set the threshold to send acks (may be updated in the cfg response) */ + p_ccb->fcrb.max_held_acks = p_cfg->fcr.tx_win_sz / 3; + + /* Include FCS option only if peer can handle it */ + if (p_ccb->p_lcb->peer_ext_fea & L2CAP_EXTFEA_NO_CRC) { + /* FCS check can be bypassed if peer also desires to bypass */ + if (p_cfg->fcs_present && p_cfg->fcs == L2CAP_CFG_FCS_BYPASS) + p_ccb->bypass_fcs |= L2CAP_CFG_FCS_OUR; + } else + p_cfg->fcs_present = false; + } else { + p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; + } + + p_ccb->our_cfg.fcr.mode = p_cfg->fcr.mode; + p_ccb->our_cfg.fcr_present = p_cfg->fcr_present; + + /* Check the flush timeout. If it is lower than the current one used */ + /* then we need to adjust the flush timeout sent to the controller */ + if (p_cfg->flush_to_present) { + if ((p_cfg->flush_to == 0) || + (p_cfg->flush_to == L2CAP_NO_AUTOMATIC_FLUSH)) { + /* don't send invalid flush timeout */ + /* SPEC: The sender of the Request shall specify its flush timeout value + */ + /* if it differs from the default value of 0xFFFF */ + p_cfg->flush_to_present = false; + } else { + p_ccb->our_cfg.flush_to = p_cfg->flush_to; + p_lcb = p_ccb->p_lcb; - p_ccb->our_cfg.fcr.mode = p_cfg->fcr.mode; - p_ccb->our_cfg.fcr_present = p_cfg->fcr_present; + if (p_cfg->flush_to < p_lcb->link_flush_tout) { + p_lcb->link_flush_tout = p_cfg->flush_to; - /* Check the flush timeout. If it is lower than the current one used */ - /* then we need to adjust the flush timeout sent to the controller */ - if (p_cfg->flush_to_present) - { - if ((p_cfg->flush_to == 0)||(p_cfg->flush_to == L2CAP_NO_AUTOMATIC_FLUSH)) - { - /* don't send invalid flush timeout */ - /* SPEC: The sender of the Request shall specify its flush timeout value */ - /* if it differs from the default value of 0xFFFF */ - p_cfg->flush_to_present = false; - } - else - { - p_ccb->our_cfg.flush_to = p_cfg->flush_to; - p_lcb = p_ccb->p_lcb; - - if (p_cfg->flush_to < p_lcb->link_flush_tout) - { - p_lcb->link_flush_tout = p_cfg->flush_to; - - /* If the timeout is within range of HCI, set the flush timeout */ - if (p_cfg->flush_to <= ((HCI_MAX_AUTO_FLUSH_TOUT * 5) / 8)) - { - /* Convert flush timeout to 0.625 ms units, with round */ - hci_flush_to = ((p_cfg->flush_to * 8) + 3) / 5; - btsnd_hcic_write_auto_flush_tout (p_lcb->handle, hci_flush_to); - } - } + /* If the timeout is within range of HCI, set the flush timeout */ + if (p_cfg->flush_to <= ((HCI_MAX_AUTO_FLUSH_TOUT * 5) / 8)) { + /* Convert flush timeout to 0.625 ms units, with round */ + hci_flush_to = ((p_cfg->flush_to * 8) + 3) / 5; + btsnd_hcic_write_auto_flush_tout(p_lcb->handle, hci_flush_to); } + } } + } } - /******************************************************************************* * * Function l2cu_process_our_cfg_rsp @@ -2220,18 +2053,17 @@ void l2cu_process_our_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_process_our_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) -{ - /* If peer wants QoS, we are allowed to change the values in a positive response */ - if ( (p_cfg->qos_present) && (p_ccb->peer_cfg.qos_present) ) - p_ccb->peer_cfg.qos = p_cfg->qos; - else - p_cfg->qos_present = false; +void l2cu_process_our_cfg_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { + /* If peer wants QoS, we are allowed to change the values in a positive + * response */ + if ((p_cfg->qos_present) && (p_ccb->peer_cfg.qos_present)) + p_ccb->peer_cfg.qos = p_cfg->qos; + else + p_cfg->qos_present = false; - l2c_fcr_adj_our_rsp_options (p_ccb, p_cfg); + l2c_fcr_adj_our_rsp_options(p_ccb, p_cfg); } - /******************************************************************************* * * Function l2cu_device_reset @@ -2242,19 +2074,16 @@ void l2cu_process_our_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void l2cu_device_reset (void) -{ - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; +void l2cu_device_reset(void) { + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->handle != HCI_INVALID_HANDLE)) - { - l2c_link_hci_disc_comp (p_lcb->handle, (uint8_t) -1); - } + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->handle != HCI_INVALID_HANDLE)) { + l2c_link_hci_disc_comp(p_lcb->handle, (uint8_t)-1); } - l2cb.is_ble_connecting = false; + } + l2cb.is_ble_connecting = false; } /******************************************************************************* @@ -2266,78 +2095,70 @@ void l2cu_device_reset (void) * Returns true if successful, false if get buffer fails. * ******************************************************************************/ -bool l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport) -{ - int xx; - tL2C_LCB *p_lcb_cur = &l2cb.lcb_pool[0]; +bool l2cu_create_conn(tL2C_LCB* p_lcb, tBT_TRANSPORT transport) { + int xx; + tL2C_LCB* p_lcb_cur = &l2cb.lcb_pool[0]; #if (BTM_SCO_INCLUDED == TRUE) - bool is_sco_active; + bool is_sco_active; #endif - tBT_DEVICE_TYPE dev_type; - tBLE_ADDR_TYPE addr_type; + tBT_DEVICE_TYPE dev_type; + tBLE_ADDR_TYPE addr_type; + BTM_ReadDevInfo(p_lcb->remote_bd_addr, &dev_type, &addr_type); - BTM_ReadDevInfo(p_lcb->remote_bd_addr, &dev_type, &addr_type); + if (transport == BT_TRANSPORT_LE) { + if (!controller_get_interface()->supports_ble()) return false; - if (transport == BT_TRANSPORT_LE) - { - if (!controller_get_interface()->supports_ble()) - return false; - - p_lcb->ble_addr_type = addr_type; - p_lcb->transport = BT_TRANSPORT_LE; - - return (l2cble_create_conn(p_lcb)); - } + p_lcb->ble_addr_type = addr_type; + p_lcb->transport = BT_TRANSPORT_LE; - /* If there is a connection where we perform as a slave, try to switch roles - for this connection */ - for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb_cur++) - { - if (p_lcb_cur == p_lcb) - continue; + return (l2cble_create_conn(p_lcb)); + } - if ((p_lcb_cur->in_use) && (p_lcb_cur->link_role == HCI_ROLE_SLAVE)) - { + /* If there is a connection where we perform as a slave, try to switch roles + for this connection */ + for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; + xx++, p_lcb_cur++) { + if (p_lcb_cur == p_lcb) continue; + if ((p_lcb_cur->in_use) && (p_lcb_cur->link_role == HCI_ROLE_SLAVE)) { #if (BTM_SCO_INCLUDED == TRUE) - /* The LMP_switch_req shall be sent only if the ACL logical transport - is in active mode, when encryption is disabled, and all synchronous - logical transports on the same physical link are disabled." */ + /* The LMP_switch_req shall be sent only if the ACL logical transport + is in active mode, when encryption is disabled, and all synchronous + logical transports on the same physical link are disabled." */ - /* Check if there is any SCO Active on this BD Address */ - is_sco_active = btm_is_sco_active_by_bdaddr(p_lcb_cur->remote_bd_addr); + /* Check if there is any SCO Active on this BD Address */ + is_sco_active = btm_is_sco_active_by_bdaddr(p_lcb_cur->remote_bd_addr); - L2CAP_TRACE_API ("l2cu_create_conn - btm_is_sco_active_by_bdaddr() is_sco_active = %s", \ - (is_sco_active == true) ? "true":"false"); + L2CAP_TRACE_API( + "l2cu_create_conn - btm_is_sco_active_by_bdaddr() is_sco_active = %s", + (is_sco_active == true) ? "true" : "false"); - if (is_sco_active == true) - continue; /* No Master Slave switch not allowed when SCO Active */ + if (is_sco_active == true) + continue; /* No Master Slave switch not allowed when SCO Active */ #endif - /*4_1_TODO check if btm_cb.devcb.local_features to be used instead */ - if (HCI_SWITCH_SUPPORTED(BTM_ReadLocalFeatures())) - { - /* mark this lcb waiting for switch to be completed and - start switch on the other one */ - p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH; - p_lcb->link_role = HCI_ROLE_MASTER; - - if (BTM_SwitchRole (p_lcb_cur->remote_bd_addr, HCI_ROLE_MASTER, NULL) == BTM_CMD_STARTED) - { - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); - return (true); - } - } + /*4_1_TODO check if btm_cb.devcb.local_features to be used instead */ + if (HCI_SWITCH_SUPPORTED(BTM_ReadLocalFeatures())) { + /* mark this lcb waiting for switch to be completed and + start switch on the other one */ + p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH; + p_lcb->link_role = HCI_ROLE_MASTER; + + if (BTM_SwitchRole(p_lcb_cur->remote_bd_addr, HCI_ROLE_MASTER, NULL) == + BTM_CMD_STARTED) { + alarm_set_on_queue( + p_lcb->l2c_lcb_timer, L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + return (true); } + } } + } - p_lcb->link_state = LST_CONNECTING; + p_lcb->link_state = LST_CONNECTING; - return (l2cu_create_conn_after_switch (p_lcb)); + return (l2cu_create_conn_after_switch(p_lcb)); } /******************************************************************************* @@ -2349,23 +2170,19 @@ bool l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport) * Returns * ******************************************************************************/ -uint8_t l2cu_get_num_hi_priority (void) -{ - uint8_t no_hi = 0; - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; +uint8_t l2cu_get_num_hi_priority(void) { + uint8_t no_hi = 0; + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)) - { - no_hi++; - } + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)) { + no_hi++; } - return no_hi; + } + return no_hi; } - /******************************************************************************* * * Function l2cu_create_conn_after_switch @@ -2377,69 +2194,61 @@ uint8_t l2cu_get_num_hi_priority (void) * ******************************************************************************/ -bool l2cu_create_conn_after_switch (tL2C_LCB *p_lcb) -{ - uint8_t allow_switch = HCI_CR_CONN_ALLOW_SWITCH; - tBTM_INQ_INFO *p_inq_info; - uint8_t page_scan_rep_mode; - uint8_t page_scan_mode; - uint16_t clock_offset; - uint8_t *p_features; - uint16_t num_acl = BTM_GetNumAclLinks(); - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_lcb->remote_bd_addr); - uint8_t no_hi_prio_chs = l2cu_get_num_hi_priority(); - - p_features = BTM_ReadLocalFeatures(); - - L2CAP_TRACE_DEBUG ("l2cu_create_conn_after_switch :%d num_acl:%d no_hi: %d is_bonding:%d", - l2cb.disallow_switch, num_acl, no_hi_prio_chs, p_lcb->is_bonding); - /* FW team says that we can participant in 4 piconets - * typically 3 piconet + 1 for scanning. - * We can enhance the code to count the number of piconets later. */ - if ( ((!l2cb.disallow_switch && (num_acl < 3)) || (p_lcb->is_bonding && (no_hi_prio_chs==0))) - && HCI_SWITCH_SUPPORTED(p_features)) - allow_switch = HCI_CR_CONN_ALLOW_SWITCH; - else - allow_switch = HCI_CR_CONN_NOT_ALLOW_SWITCH; +bool l2cu_create_conn_after_switch(tL2C_LCB* p_lcb) { + uint8_t allow_switch = HCI_CR_CONN_ALLOW_SWITCH; + tBTM_INQ_INFO* p_inq_info; + uint8_t page_scan_rep_mode; + uint8_t page_scan_mode; + uint16_t clock_offset; + uint8_t* p_features; + uint16_t num_acl = BTM_GetNumAclLinks(); + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_lcb->remote_bd_addr); + uint8_t no_hi_prio_chs = l2cu_get_num_hi_priority(); - p_lcb->link_state = LST_CONNECTING; + p_features = BTM_ReadLocalFeatures(); - /* Check with the BT manager if details about remote device are known */ - p_inq_info = BTM_InqDbRead(p_lcb->remote_bd_addr); - if (p_inq_info != NULL) - { - page_scan_rep_mode = p_inq_info->results.page_scan_rep_mode; - page_scan_mode = p_inq_info->results.page_scan_mode; - clock_offset = (uint16_t)(p_inq_info->results.clock_offset); - } - else - { - /* No info known. Use default settings */ - page_scan_rep_mode = HCI_PAGE_SCAN_REP_MODE_R1; - page_scan_mode = HCI_MANDATARY_PAGE_SCAN_MODE; + L2CAP_TRACE_DEBUG( + "l2cu_create_conn_after_switch :%d num_acl:%d no_hi: %d is_bonding:%d", + l2cb.disallow_switch, num_acl, no_hi_prio_chs, p_lcb->is_bonding); + /* FW team says that we can participant in 4 piconets + * typically 3 piconet + 1 for scanning. + * We can enhance the code to count the number of piconets later. */ + if (((!l2cb.disallow_switch && (num_acl < 3)) || + (p_lcb->is_bonding && (no_hi_prio_chs == 0))) && + HCI_SWITCH_SUPPORTED(p_features)) + allow_switch = HCI_CR_CONN_ALLOW_SWITCH; + else + allow_switch = HCI_CR_CONN_NOT_ALLOW_SWITCH; - clock_offset = (p_dev_rec) ? p_dev_rec->clock_offset : 0; - } + p_lcb->link_state = LST_CONNECTING; - btsnd_hcic_create_conn(p_lcb->remote_bd_addr, - ( HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 - | HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 - | HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5 ), - page_scan_rep_mode, - page_scan_mode, - clock_offset, - allow_switch); + /* Check with the BT manager if details about remote device are known */ + p_inq_info = BTM_InqDbRead(p_lcb->remote_bd_addr); + if (p_inq_info != NULL) { + page_scan_rep_mode = p_inq_info->results.page_scan_rep_mode; + page_scan_mode = p_inq_info->results.page_scan_mode; + clock_offset = (uint16_t)(p_inq_info->results.clock_offset); + } else { + /* No info known. Use default settings */ + page_scan_rep_mode = HCI_PAGE_SCAN_REP_MODE_R1; + page_scan_mode = HCI_MANDATARY_PAGE_SCAN_MODE; - btm_acl_update_busy_level (BTM_BLI_PAGE_EVT); + clock_offset = (p_dev_rec) ? p_dev_rec->clock_offset : 0; + } - alarm_set_on_queue(p_lcb->l2c_lcb_timer, - L2CAP_LINK_CONNECT_TIMEOUT_MS, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); + btsnd_hcic_create_conn( + p_lcb->remote_bd_addr, (HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | + HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 | + HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5), + page_scan_rep_mode, page_scan_mode, clock_offset, allow_switch); - return (true); -} + btm_acl_update_busy_level(BTM_BLI_PAGE_EVT); + alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_LINK_CONNECT_TIMEOUT_MS, + l2c_lcb_timer_timeout, p_lcb, btu_general_alarm_queue); + + return (true); +} /******************************************************************************* * @@ -2451,24 +2260,20 @@ bool l2cu_create_conn_after_switch (tL2C_LCB *p_lcb) * Returns pointer to first matched LCB, or NULL if no match * ******************************************************************************/ -tL2C_LCB *l2cu_find_lcb_by_state (tL2C_LINK_STATE state) -{ - uint16_t i; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; +tL2C_LCB* l2cu_find_lcb_by_state(tL2C_LINK_STATE state) { + uint16_t i; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; - for (i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->link_state == state)) - { - return (p_lcb); - } + for (i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->link_state == state)) { + return (p_lcb); } + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } - /******************************************************************************* * * Function l2cu_lcb_disconnecting @@ -2481,44 +2286,38 @@ tL2C_LCB *l2cu_find_lcb_by_state (tL2C_LINK_STATE state) * Returns true if any of above conditions met, false otherwise * ******************************************************************************/ -bool l2cu_lcb_disconnecting (void) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - uint16_t i; - bool status = false; +bool l2cu_lcb_disconnecting(void) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + uint16_t i; + bool status = false; - p_lcb = &l2cb.lcb_pool[0]; + p_lcb = &l2cb.lcb_pool[0]; - for (i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) - { - if (p_lcb->in_use) - { - /* no ccbs on lcb, or lcb is in disconnecting state */ - if ((!p_lcb->ccb_queue.p_first_ccb) || (p_lcb->link_state == LST_DISCONNECTING)) - { - status = true; - break; - } - /* only one ccb left on lcb */ - else if (p_lcb->ccb_queue.p_first_ccb == p_lcb->ccb_queue.p_last_ccb) - { - p_ccb = p_lcb->ccb_queue.p_first_ccb; - - if ((p_ccb->in_use) && - ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) || - (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) - { - status = true; - break; - } - } + for (i = 0; i < MAX_L2CAP_LINKS; i++, p_lcb++) { + if (p_lcb->in_use) { + /* no ccbs on lcb, or lcb is in disconnecting state */ + if ((!p_lcb->ccb_queue.p_first_ccb) || + (p_lcb->link_state == LST_DISCONNECTING)) { + status = true; + break; + } + /* only one ccb left on lcb */ + else if (p_lcb->ccb_queue.p_first_ccb == p_lcb->ccb_queue.p_last_ccb) { + p_ccb = p_lcb->ccb_queue.p_first_ccb; + + if ((p_ccb->in_use) && + ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) || + (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) { + status = true; + break; } + } } - return status; + } + return status; } - /******************************************************************************* * * Function l2cu_set_acl_priority @@ -2531,48 +2330,47 @@ bool l2cu_lcb_disconnecting (void) * ******************************************************************************/ -bool l2cu_set_acl_priority (BD_ADDR bd_addr, uint8_t priority, bool reset_after_rs) -{ - tL2C_LCB *p_lcb; - uint8_t *pp; - uint8_t command[HCI_BRCM_ACL_PRIORITY_PARAM_SIZE]; - uint8_t vs_param; +bool l2cu_set_acl_priority(BD_ADDR bd_addr, uint8_t priority, + bool reset_after_rs) { + tL2C_LCB* p_lcb; + uint8_t* pp; + uint8_t command[HCI_BRCM_ACL_PRIORITY_PARAM_SIZE]; + uint8_t vs_param; - APPL_TRACE_EVENT("SET ACL PRIORITY %d", priority); + APPL_TRACE_EVENT("SET ACL PRIORITY %d", priority); - /* Find the link control block for the acl channel */ - p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); - if (p_lcb == NULL) - { - L2CAP_TRACE_WARNING ("L2CAP - no LCB for L2CA_SetAclPriority"); - return (false); - } + /* Find the link control block for the acl channel */ + p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR); + if (p_lcb == NULL) { + L2CAP_TRACE_WARNING("L2CAP - no LCB for L2CA_SetAclPriority"); + return (false); + } - if (BTM_IS_BRCM_CONTROLLER()) - { - /* Called from above L2CAP through API; send VSC if changed */ - if ((!reset_after_rs && (priority != p_lcb->acl_priority)) || - /* Called because of a master/slave role switch; if high resend VSC */ - ( reset_after_rs && p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)) - { - pp = command; + if (BTM_IS_BRCM_CONTROLLER()) { + /* Called from above L2CAP through API; send VSC if changed */ + if ((!reset_after_rs && (priority != p_lcb->acl_priority)) || + /* Called because of a master/slave role switch; if high resend VSC */ + (reset_after_rs && p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)) { + pp = command; - vs_param = (priority == L2CAP_PRIORITY_HIGH) ? HCI_BRCM_ACL_PRIORITY_HIGH : HCI_BRCM_ACL_PRIORITY_LOW; + vs_param = (priority == L2CAP_PRIORITY_HIGH) ? HCI_BRCM_ACL_PRIORITY_HIGH + : HCI_BRCM_ACL_PRIORITY_LOW; - UINT16_TO_STREAM (pp, p_lcb->handle); - UINT8_TO_STREAM (pp, vs_param); + UINT16_TO_STREAM(pp, p_lcb->handle); + UINT8_TO_STREAM(pp, vs_param); - BTM_VendorSpecificCommand (HCI_BRCM_SET_ACL_PRIORITY, HCI_BRCM_ACL_PRIORITY_PARAM_SIZE, command, NULL); + BTM_VendorSpecificCommand(HCI_BRCM_SET_ACL_PRIORITY, + HCI_BRCM_ACL_PRIORITY_PARAM_SIZE, command, + NULL); - /* Adjust lmp buffer allocation for this channel if priority changed */ - if (p_lcb->acl_priority != priority) - { - p_lcb->acl_priority = priority; - l2c_link_adjust_allocation(); - } - } + /* Adjust lmp buffer allocation for this channel if priority changed */ + if (p_lcb->acl_priority != priority) { + p_lcb->acl_priority = priority; + l2c_link_adjust_allocation(); + } } - return(true); + } + return (true); } #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) @@ -2585,12 +2383,12 @@ bool l2cu_set_acl_priority (BD_ADDR bd_addr, uint8_t priority, bool reset_ * Returns void * ******************************************************************************/ -void l2cu_set_non_flushable_pbf (bool is_supported) -{ - if (is_supported) - l2cb.non_flushable_pbf = (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT); - else - l2cb.non_flushable_pbf = (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT); +void l2cu_set_non_flushable_pbf(bool is_supported) { + if (is_supported) + l2cb.non_flushable_pbf = + (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT); + else + l2cb.non_flushable_pbf = (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT); } #endif @@ -2604,51 +2402,41 @@ void l2cu_set_non_flushable_pbf (bool is_supported) * Returns void * ******************************************************************************/ -void l2cu_resubmit_pending_sec_req (BD_ADDR p_bda) -{ - tL2C_LCB *p_lcb; - tL2C_CCB *p_ccb; - tL2C_CCB *p_next_ccb; - int xx; +void l2cu_resubmit_pending_sec_req(BD_ADDR p_bda) { + tL2C_LCB* p_lcb; + tL2C_CCB* p_ccb; + tL2C_CCB* p_next_ccb; + int xx; - L2CAP_TRACE_DEBUG ("l2cu_resubmit_pending_sec_req p_bda: 0x%08x", p_bda); + L2CAP_TRACE_DEBUG("l2cu_resubmit_pending_sec_req p_bda: 0x%08x", p_bda); - /* If we are called with a BDA, only resubmit for that BDA */ - if (p_bda) - { - p_lcb = l2cu_find_lcb_by_bd_addr (p_bda, BT_TRANSPORT_BR_EDR); - - /* If we don't have one, this is an error */ - if (p_lcb) - { - /* For all channels, send the event through their FSMs */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) - { - p_next_ccb = p_ccb->p_next_ccb; - l2c_csm_execute (p_ccb, L2CEVT_SEC_RE_SEND_CMD, NULL); - } - } - else - { - L2CAP_TRACE_WARNING ("l2cu_resubmit_pending_sec_req - unknown BD_ADDR"); - } + /* If we are called with a BDA, only resubmit for that BDA */ + if (p_bda) { + p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, BT_TRANSPORT_BR_EDR); + + /* If we don't have one, this is an error */ + if (p_lcb) { + /* For all channels, send the event through their FSMs */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) { + p_next_ccb = p_ccb->p_next_ccb; + l2c_csm_execute(p_ccb, L2CEVT_SEC_RE_SEND_CMD, NULL); + } + } else { + L2CAP_TRACE_WARNING("l2cu_resubmit_pending_sec_req - unknown BD_ADDR"); } - else - { - /* No BDA pasesed in, so check all links */ - for (xx = 0, p_lcb = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if (p_lcb->in_use) - { - /* For all channels, send the event through their FSMs */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) - { - p_next_ccb = p_ccb->p_next_ccb; - l2c_csm_execute (p_ccb, L2CEVT_SEC_RE_SEND_CMD, NULL); - } - } + } else { + /* No BDA pasesed in, so check all links */ + for (xx = 0, p_lcb = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; + xx++, p_lcb++) { + if (p_lcb->in_use) { + /* For all channels, send the event through their FSMs */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) { + p_next_ccb = p_ccb->p_next_ccb; + l2c_csm_execute(p_ccb, L2CEVT_SEC_RE_SEND_CMD, NULL); } + } } + } } #if (L2CAP_CONFORMANCE_TESTING == TRUE) @@ -2662,11 +2450,8 @@ void l2cu_resubmit_pending_sec_req (BD_ADDR p_bda) * Returns pointer to CCB, or NULL if none * ******************************************************************************/ -void l2cu_set_info_rsp_mask (uint32_t mask) -{ - l2cb.test_info_resp = mask; -} -#endif /* L2CAP_CONFORMANCE_TESTING */ +void l2cu_set_info_rsp_mask(uint32_t mask) { l2cb.test_info_resp = mask; } +#endif /* L2CAP_CONFORMANCE_TESTING */ /******************************************************************************* * @@ -2677,42 +2462,46 @@ void l2cu_set_info_rsp_mask (uint32_t mask) * Returns void * ******************************************************************************/ -void l2cu_adjust_out_mps (tL2C_CCB *p_ccb) -{ - uint16_t packet_size; - - /* on the tx side MTU is selected based on packet size of the controller */ - packet_size = btm_get_max_packet_size (p_ccb->p_lcb->remote_bd_addr); - - if (packet_size <= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN)) - { - /* something is very wrong */ - L2CAP_TRACE_ERROR ("l2cu_adjust_out_mps bad packet size: %u will use MPS: %u", packet_size, p_ccb->peer_cfg.fcr.mps); - p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps; - } +void l2cu_adjust_out_mps(tL2C_CCB* p_ccb) { + uint16_t packet_size; + + /* on the tx side MTU is selected based on packet size of the controller */ + packet_size = btm_get_max_packet_size(p_ccb->p_lcb->remote_bd_addr); + + if (packet_size <= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD + + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN)) { + /* something is very wrong */ + L2CAP_TRACE_ERROR( + "l2cu_adjust_out_mps bad packet size: %u will use MPS: %u", + packet_size, p_ccb->peer_cfg.fcr.mps); + p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps; + } else { + packet_size -= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD + + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN); + + /* We try to negotiate MTU that each packet can be split into whole + number of max packets. For example if link is 1.2 max packet size is 339 + bytes. + At first calculate how many whole packets it is. MAX L2CAP is 1691 + 4 + overhead. + 1695, that will be 5 Dh5 packets. Now maximum L2CAP packet is + 5 * 339 = 1695. Minus 4 bytes L2CAP header 1691. + + For EDR 2.0 packet size is 1027. So we better send RFCOMM packet as 1 3DH5 + packet + 1 * 1027 = 1027. Minus 4 bytes L2CAP header 1023. */ + if (p_ccb->peer_cfg.fcr.mps >= packet_size) + p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps / packet_size * packet_size; else - { - packet_size -= (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN); - - /* We try to negotiate MTU that each packet can be split into whole - number of max packets. For example if link is 1.2 max packet size is 339 bytes. - At first calculate how many whole packets it is. MAX L2CAP is 1691 + 4 overhead. - 1695, that will be 5 Dh5 packets. Now maximum L2CAP packet is - 5 * 339 = 1695. Minus 4 bytes L2CAP header 1691. - - For EDR 2.0 packet size is 1027. So we better send RFCOMM packet as 1 3DH5 packet - 1 * 1027 = 1027. Minus 4 bytes L2CAP header 1023. */ - if (p_ccb->peer_cfg.fcr.mps >= packet_size) - p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps / packet_size * packet_size; - else - p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps; + p_ccb->tx_mps = p_ccb->peer_cfg.fcr.mps; - L2CAP_TRACE_DEBUG ("l2cu_adjust_out_mps use %d Based on peer_cfg.fcr.mps: %u packet_size: %u", - p_ccb->tx_mps, p_ccb->peer_cfg.fcr.mps, packet_size); - } + L2CAP_TRACE_DEBUG( + "l2cu_adjust_out_mps use %d Based on peer_cfg.fcr.mps: %u " + "packet_size: %u", + p_ccb->tx_mps, p_ccb->peer_cfg.fcr.mps, packet_size); + } } - /******************************************************************************* * * Function l2cu_initialize_fixed_ccb @@ -2722,58 +2511,56 @@ void l2cu_adjust_out_mps (tL2C_CCB *p_ccb) * Returns true or false * ******************************************************************************/ -bool l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, uint16_t fixed_cid, tL2CAP_FCR_OPTS *p_fcr) -{ +bool l2cu_initialize_fixed_ccb(tL2C_LCB* p_lcb, uint16_t fixed_cid, + tL2CAP_FCR_OPTS* p_fcr) { #if (L2CAP_NUM_FIXED_CHNLS > 0) - tL2C_CCB *p_ccb; - - /* If we already have a CCB, then simply return */ - p_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; - if ((p_ccb != NULL) && p_ccb->in_use) { - /* - * NOTE: The "in_use" check is needed to ignore leftover entries - * that have been already released by l2cu_release_ccb(). - */ - return (true); - } + tL2C_CCB* p_ccb; + + /* If we already have a CCB, then simply return */ + p_ccb = p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]; + if ((p_ccb != NULL) && p_ccb->in_use) { + /* + * NOTE: The "in_use" check is needed to ignore leftover entries + * that have been already released by l2cu_release_ccb(). + */ + return (true); + } - p_ccb = l2cu_allocate_ccb(NULL, 0); - if (p_ccb == NULL) - return (false); + p_ccb = l2cu_allocate_ccb(NULL, 0); + if (p_ccb == NULL) return (false); - alarm_cancel(p_lcb->l2c_lcb_timer); + alarm_cancel(p_lcb->l2c_lcb_timer); - /* Set CID for the connection */ - p_ccb->local_cid = fixed_cid; - p_ccb->remote_cid = fixed_cid; + /* Set CID for the connection */ + p_ccb->local_cid = fixed_cid; + p_ccb->remote_cid = fixed_cid; - p_ccb->is_flushable = false; + p_ccb->is_flushable = false; - if (p_fcr) - { - /* Set the FCR parameters. For now, we will use default pools */ - p_ccb->our_cfg.fcr = p_ccb->peer_cfg.fcr = *p_fcr; + if (p_fcr) { + /* Set the FCR parameters. For now, we will use default pools */ + p_ccb->our_cfg.fcr = p_ccb->peer_cfg.fcr = *p_fcr; - p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; - p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; - p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; - p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; + p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE; + p_ccb->ertm_info.fcr_tx_buf_size = L2CAP_FCR_TX_BUF_SIZE; + p_ccb->ertm_info.user_rx_buf_size = L2CAP_USER_RX_BUF_SIZE; + p_ccb->ertm_info.user_tx_buf_size = L2CAP_USER_TX_BUF_SIZE; - p_ccb->fcrb.max_held_acks = p_fcr->tx_win_sz / 3; - } + p_ccb->fcrb.max_held_acks = p_fcr->tx_win_sz / 3; + } - /* Link ccb to lcb and lcb to ccb */ - p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = p_ccb; - p_ccb->p_lcb = p_lcb; + /* Link ccb to lcb and lcb to ccb */ + p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = p_ccb; + p_ccb->p_lcb = p_lcb; - /* There is no configuration, so if the link is up, the channel is up */ - if (p_lcb->link_state == LST_CONNECTED) - p_ccb->chnl_state = CST_OPEN; + /* There is no configuration, so if the link is up, the channel is up */ + if (p_lcb->link_state == LST_CONNECTED) p_ccb->chnl_state = CST_OPEN; - /* Set the default idle timeout value to use */ - p_ccb->fixed_chnl_idle_tout = l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].default_idle_tout; + /* Set the default idle timeout value to use */ + p_ccb->fixed_chnl_idle_tout = + l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].default_idle_tout; #endif - return (true); + return (true); } /******************************************************************************* @@ -2788,69 +2575,58 @@ bool l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, uint16_t fixed_cid, tL2CAP_F * Returns void * ******************************************************************************/ -void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb) -{ - tBTM_STATUS rc; - period_ms_t timeout_ms = p_lcb->idle_timeout * 1000; - bool start_timeout = true; +void l2cu_no_dynamic_ccbs(tL2C_LCB* p_lcb) { + tBTM_STATUS rc; + period_ms_t timeout_ms = p_lcb->idle_timeout * 1000; + bool start_timeout = true; #if (L2CAP_NUM_FIXED_CHNLS > 0) - int xx; + int xx; - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - if ((p_lcb->p_fixed_ccbs[xx] != NULL) && - (p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000 > timeout_ms)) { - timeout_ms = p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000; - } + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + if ((p_lcb->p_fixed_ccbs[xx] != NULL) && + (p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000 > timeout_ms)) { + timeout_ms = p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000; } + } #endif - /* If the link is pairing, do not mess with the timeouts */ - if (p_lcb->is_bonding) - return; - - if (timeout_ms == 0) - { - L2CAP_TRACE_DEBUG ("l2cu_no_dynamic_ccbs() IDLE timer 0, disconnecting link"); - - rc = btm_sec_disconnect (p_lcb->handle, HCI_ERR_PEER_USER); - if (rc == BTM_CMD_STARTED) - { - l2cu_process_fixed_disc_cback(p_lcb); - p_lcb->link_state = LST_DISCONNECTING; - timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; - } - else if (rc == BTM_SUCCESS) - { - l2cu_process_fixed_disc_cback(p_lcb); - /* BTM SEC will make sure that link is release (probably after pairing is done) */ - p_lcb->link_state = LST_DISCONNECTING; - start_timeout = false; - } - else if (p_lcb->is_bonding) - { - btsnd_hcic_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); - l2cu_process_fixed_disc_cback(p_lcb); - p_lcb->link_state = LST_DISCONNECTING; - timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; - } - else - { - /* probably no buffer to send disconnect */ - timeout_ms = BT_1SEC_TIMEOUT_MS; - } - } - - if (start_timeout) { - L2CAP_TRACE_DEBUG("%s starting IDLE timeout: %d ms", __func__, - timeout_ms); - alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, - l2c_lcb_timer_timeout, p_lcb, - btu_general_alarm_queue); + /* If the link is pairing, do not mess with the timeouts */ + if (p_lcb->is_bonding) return; + + if (timeout_ms == 0) { + L2CAP_TRACE_DEBUG( + "l2cu_no_dynamic_ccbs() IDLE timer 0, disconnecting link"); + + rc = btm_sec_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); + if (rc == BTM_CMD_STARTED) { + l2cu_process_fixed_disc_cback(p_lcb); + p_lcb->link_state = LST_DISCONNECTING; + timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; + } else if (rc == BTM_SUCCESS) { + l2cu_process_fixed_disc_cback(p_lcb); + /* BTM SEC will make sure that link is release (probably after pairing is + * done) */ + p_lcb->link_state = LST_DISCONNECTING; + start_timeout = false; + } else if (p_lcb->is_bonding) { + btsnd_hcic_disconnect(p_lcb->handle, HCI_ERR_PEER_USER); + l2cu_process_fixed_disc_cback(p_lcb); + p_lcb->link_state = LST_DISCONNECTING; + timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS; } else { - alarm_cancel(p_lcb->l2c_lcb_timer); + /* probably no buffer to send disconnect */ + timeout_ms = BT_1SEC_TIMEOUT_MS; } + } + + if (start_timeout) { + L2CAP_TRACE_DEBUG("%s starting IDLE timeout: %d ms", __func__, timeout_ms); + alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms, l2c_lcb_timer_timeout, + p_lcb, btu_general_alarm_queue); + } else { + alarm_cancel(p_lcb->l2c_lcb_timer); + } } #if (L2CAP_NUM_FIXED_CHNLS > 0) @@ -2863,53 +2639,45 @@ void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb) * not received, the bitfield is all zeros. * ******************************************************************************/ -void l2cu_process_fixed_chnl_resp (tL2C_LCB *p_lcb) -{ - if (p_lcb->transport == BT_TRANSPORT_BR_EDR) - { - /* ignore all not assigned BR/EDR channels */ - p_lcb->peer_chnl_mask[0] &= (L2CAP_FIXED_CHNL_SIG_BIT| \ - L2CAP_FIXED_CHNL_CNCTLESS_BIT| \ - L2CAP_FIXED_CHNL_SMP_BR_BIT); - } - else - p_lcb->peer_chnl_mask[0] = l2cb.l2c_ble_fixed_chnls_mask; - - /* Tell all registered fixed channels about the connection */ - for (int xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - /* skip sending LE fix channel callbacks on BR/EDR links */ - if (p_lcb->transport == BT_TRANSPORT_BR_EDR && - xx + L2CAP_FIRST_FIXED_CHNL >= L2CAP_ATT_CID && - xx + L2CAP_FIRST_FIXED_CHNL <= L2CAP_SMP_CID) - continue; - if (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL) - { - if (p_lcb->peer_chnl_mask[(xx + L2CAP_FIRST_FIXED_CHNL) / 8] - & (1 << ((xx + L2CAP_FIRST_FIXED_CHNL) % 8))) - { - if (p_lcb->p_fixed_ccbs[xx]) - p_lcb->p_fixed_ccbs[xx]->chnl_state = CST_OPEN; - (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, - p_lcb->remote_bd_addr, true, 0, p_lcb->transport); - } - else - { - (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, - p_lcb->remote_bd_addr, false, p_lcb->disc_reason, p_lcb->transport); - - if (p_lcb->p_fixed_ccbs[xx]) - { - l2cu_release_ccb (p_lcb->p_fixed_ccbs[xx]); - p_lcb->p_fixed_ccbs[xx] = NULL; - } - } +void l2cu_process_fixed_chnl_resp(tL2C_LCB* p_lcb) { + if (p_lcb->transport == BT_TRANSPORT_BR_EDR) { + /* ignore all not assigned BR/EDR channels */ + p_lcb->peer_chnl_mask[0] &= + (L2CAP_FIXED_CHNL_SIG_BIT | L2CAP_FIXED_CHNL_CNCTLESS_BIT | + L2CAP_FIXED_CHNL_SMP_BR_BIT); + } else + p_lcb->peer_chnl_mask[0] = l2cb.l2c_ble_fixed_chnls_mask; + + /* Tell all registered fixed channels about the connection */ + for (int xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + /* skip sending LE fix channel callbacks on BR/EDR links */ + if (p_lcb->transport == BT_TRANSPORT_BR_EDR && + xx + L2CAP_FIRST_FIXED_CHNL >= L2CAP_ATT_CID && + xx + L2CAP_FIRST_FIXED_CHNL <= L2CAP_SMP_CID) + continue; + if (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL) { + if (p_lcb->peer_chnl_mask[(xx + L2CAP_FIRST_FIXED_CHNL) / 8] & + (1 << ((xx + L2CAP_FIRST_FIXED_CHNL) % 8))) { + if (p_lcb->p_fixed_ccbs[xx]) + p_lcb->p_fixed_ccbs[xx]->chnl_state = CST_OPEN; + (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, + p_lcb->remote_bd_addr, true, 0, + p_lcb->transport); + } else { + (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)( + xx + L2CAP_FIRST_FIXED_CHNL, p_lcb->remote_bd_addr, false, + p_lcb->disc_reason, p_lcb->transport); + + if (p_lcb->p_fixed_ccbs[xx]) { + l2cu_release_ccb(p_lcb->p_fixed_ccbs[xx]); + p_lcb->p_fixed_ccbs[xx] = NULL; } + } } + } } #endif - /******************************************************************************* * * Function l2cu_process_fixed_disc_cback @@ -2920,36 +2688,32 @@ void l2cu_process_fixed_chnl_resp (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2cu_process_fixed_disc_cback (tL2C_LCB *p_lcb) -{ +void l2cu_process_fixed_disc_cback(tL2C_LCB* p_lcb) { #if (L2CAP_NUM_FIXED_CHNLS > 0) - /* Select peer channels mask to use depending on transport */ - uint8_t peer_channel_mask = p_lcb->peer_chnl_mask[0]; - - // For LE, reset the stored peer channel mask - if (p_lcb->transport == BT_TRANSPORT_LE) - p_lcb->peer_chnl_mask[0] = 0; - - for (int xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - if (p_lcb->p_fixed_ccbs[xx]) - { - if (p_lcb->p_fixed_ccbs[xx] != p_lcb->p_pending_ccb) - { - tL2C_CCB *p_l2c_chnl_ctrl_block; - p_l2c_chnl_ctrl_block = p_lcb->p_fixed_ccbs[xx]; - p_lcb->p_fixed_ccbs[xx] = NULL; - l2cu_release_ccb(p_l2c_chnl_ctrl_block); - (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, - p_lcb->remote_bd_addr, false, p_lcb->disc_reason, p_lcb->transport); - } - } - else if ( (peer_channel_mask & (1 << (xx + L2CAP_FIRST_FIXED_CHNL))) - && (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL) ) - (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(xx + L2CAP_FIRST_FIXED_CHNL, - p_lcb->remote_bd_addr, false, p_lcb->disc_reason, p_lcb->transport); - } + /* Select peer channels mask to use depending on transport */ + uint8_t peer_channel_mask = p_lcb->peer_chnl_mask[0]; + + // For LE, reset the stored peer channel mask + if (p_lcb->transport == BT_TRANSPORT_LE) p_lcb->peer_chnl_mask[0] = 0; + + for (int xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + if (p_lcb->p_fixed_ccbs[xx]) { + if (p_lcb->p_fixed_ccbs[xx] != p_lcb->p_pending_ccb) { + tL2C_CCB* p_l2c_chnl_ctrl_block; + p_l2c_chnl_ctrl_block = p_lcb->p_fixed_ccbs[xx]; + p_lcb->p_fixed_ccbs[xx] = NULL; + l2cu_release_ccb(p_l2c_chnl_ctrl_block); + (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)( + xx + L2CAP_FIRST_FIXED_CHNL, p_lcb->remote_bd_addr, false, + p_lcb->disc_reason, p_lcb->transport); + } + } else if ((peer_channel_mask & (1 << (xx + L2CAP_FIRST_FIXED_CHNL))) && + (l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb != NULL)) + (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)( + xx + L2CAP_FIRST_FIXED_CHNL, p_lcb->remote_bd_addr, false, + p_lcb->disc_reason, p_lcb->transport); + } #endif } @@ -2963,32 +2727,32 @@ void l2cu_process_fixed_disc_cback (tL2C_LCB *p_lcb) * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, uint16_t min_int, uint16_t max_int, - uint16_t latency, uint16_t timeout) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_ble_par_req(tL2C_LCB* p_lcb, uint16_t min_int, + uint16_t max_int, uint16_t latency, + uint16_t timeout) { + BT_HDR* p_buf; + uint8_t* p; - /* Create an identifier for this packet */ - p_lcb->id++; - l2cu_adj_id (p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_lcb->id++; + l2cu_adj_id(p_lcb, L2CAP_ADJ_ID); - p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_UPD_REQ_LEN, L2CAP_CMD_BLE_UPDATE_REQ, p_lcb->id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_par_req - no buffer"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_UPD_REQ_LEN, + L2CAP_CMD_BLE_UPDATE_REQ, p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_send_peer_ble_par_req - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, min_int); - UINT16_TO_STREAM (p, max_int); - UINT16_TO_STREAM (p, latency); - UINT16_TO_STREAM (p, timeout); + UINT16_TO_STREAM(p, min_int); + UINT16_TO_STREAM(p, max_int); + UINT16_TO_STREAM(p, latency); + UINT16_TO_STREAM(p, timeout); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3001,24 +2765,24 @@ void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, uint16_t min_int, uint16_t max * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, uint16_t reason, uint8_t rem_id) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, uint16_t reason, + uint8_t rem_id) { + BT_HDR* p_buf; + uint8_t* p; - p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_UPD_RSP_LEN, L2CAP_CMD_BLE_UPDATE_RSP, rem_id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_par_rsp - no buffer"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_UPD_RSP_LEN, + L2CAP_CMD_BLE_UPDATE_RSP, rem_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_send_peer_ble_par_rsp - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, reason); + UINT16_TO_STREAM(p, reason); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3031,50 +2795,49 @@ void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, uint16_t reason, uint8_t rem_i * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_credit_based_conn_req (tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf; - uint8_t *p; - tL2C_LCB *p_lcb = NULL; - uint16_t mtu; - uint16_t mps; - uint16_t initial_credit; +void l2cu_send_peer_ble_credit_based_conn_req(tL2C_CCB* p_ccb) { + BT_HDR* p_buf; + uint8_t* p; + tL2C_LCB* p_lcb = NULL; + uint16_t mtu; + uint16_t mps; + uint16_t initial_credit; - if (!p_ccb) - return; - p_lcb = p_ccb->p_lcb; + if (!p_ccb) return; + p_lcb = p_ccb->p_lcb; - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - p_ccb->local_id = p_ccb->p_lcb->id; + p_ccb->local_id = p_ccb->p_lcb->id; - p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN, L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ, p_lcb->id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_credit_based_conn_req - no buffer"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN, + L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ, p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_send_peer_ble_credit_based_conn_req - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - mtu = p_ccb->local_conn_cfg.mtu; - mps = p_ccb->local_conn_cfg.mps; - initial_credit = p_ccb->local_conn_cfg.credits; + mtu = p_ccb->local_conn_cfg.mtu; + mps = p_ccb->local_conn_cfg.mps; + initial_credit = p_ccb->local_conn_cfg.credits; - L2CAP_TRACE_DEBUG ("l2cu_send_peer_ble_credit_based_conn_req PSM:0x%04x local_cid:%d\ - mtu:%d mps:%d initial_credit:%d", p_ccb->p_rcb->real_psm,\ - p_ccb->local_cid, mtu, mps, initial_credit); + L2CAP_TRACE_DEBUG( + "l2cu_send_peer_ble_credit_based_conn_req PSM:0x%04x local_cid:%d\ + mtu:%d mps:%d initial_credit:%d", + p_ccb->p_rcb->real_psm, p_ccb->local_cid, mtu, mps, initial_credit); - UINT16_TO_STREAM (p, p_ccb->p_rcb->real_psm); - UINT16_TO_STREAM (p, p_ccb->local_cid); - UINT16_TO_STREAM (p, mtu); - UINT16_TO_STREAM (p, mps); - UINT16_TO_STREAM (p, initial_credit); + UINT16_TO_STREAM(p, p_ccb->p_rcb->real_psm); + UINT16_TO_STREAM(p, p_ccb->local_cid); + UINT16_TO_STREAM(p, mtu); + UINT16_TO_STREAM(p, mps); + UINT16_TO_STREAM(p, initial_credit); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3088,28 +2851,28 @@ void l2cu_send_peer_ble_credit_based_conn_req (tL2C_CCB *p_ccb) * Returns void * ******************************************************************************/ -void l2cu_reject_ble_connection (tL2C_LCB *p_lcb, uint8_t rem_id, uint16_t result) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_reject_ble_connection(tL2C_LCB* p_lcb, uint8_t rem_id, + uint16_t result) { + BT_HDR* p_buf; + uint8_t* p; - p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES, rem_id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_reject_ble_connection - no buffer"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN, + L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES, rem_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_reject_ble_connection - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, 0); /* Local CID of 0 */ - UINT16_TO_STREAM (p, 0); /* MTU */ - UINT16_TO_STREAM (p, 0); /* MPS */ - UINT16_TO_STREAM (p, 0); /* initial credit */ - UINT16_TO_STREAM (p, result); + UINT16_TO_STREAM(p, 0); /* Local CID of 0 */ + UINT16_TO_STREAM(p, 0); /* MTU */ + UINT16_TO_STREAM(p, 0); /* MPS */ + UINT16_TO_STREAM(p, 0); /* initial credit */ + UINT16_TO_STREAM(p, result); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3123,29 +2886,30 @@ void l2cu_reject_ble_connection (tL2C_LCB *p_lcb, uint8_t rem_id, uint16_t resul * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result) -{ - BT_HDR *p_buf; - uint8_t *p; +void l2cu_send_peer_ble_credit_based_conn_res(tL2C_CCB* p_ccb, + uint16_t result) { + BT_HDR* p_buf; + uint8_t* p; - L2CAP_TRACE_DEBUG ("l2cu_send_peer_ble_credit_based_conn_res"); - p_buf = l2cu_build_header(p_ccb->p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES, p_ccb->remote_id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_credit_based_conn_res - no buffer"); - return; - } + L2CAP_TRACE_DEBUG("l2cu_send_peer_ble_credit_based_conn_res"); + p_buf = + l2cu_build_header(p_ccb->p_lcb, L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN, + L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES, p_ccb->remote_id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_send_peer_ble_credit_based_conn_res - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->local_cid); /* Local CID */ - UINT16_TO_STREAM (p, p_ccb->local_conn_cfg.mtu); /* MTU */ - UINT16_TO_STREAM (p, p_ccb->local_conn_cfg.mps); /* MPS */ - UINT16_TO_STREAM (p, p_ccb->local_conn_cfg.credits); /* initial credit */ - UINT16_TO_STREAM (p, result); + UINT16_TO_STREAM(p, p_ccb->local_cid); /* Local CID */ + UINT16_TO_STREAM(p, p_ccb->local_conn_cfg.mtu); /* MTU */ + UINT16_TO_STREAM(p, p_ccb->local_conn_cfg.mps); /* MPS */ + UINT16_TO_STREAM(p, p_ccb->local_conn_cfg.credits); /* initial credit */ + UINT16_TO_STREAM(p, result); - l2c_link_check_send_pkts (p_ccb->p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_ccb->p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3158,36 +2922,35 @@ void l2cu_send_peer_ble_credit_based_conn_res (tL2C_CCB *p_ccb, uint16_t result) * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_value) -{ - BT_HDR *p_buf; - uint8_t *p; - tL2C_LCB *p_lcb = NULL; +void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB* p_ccb, + uint16_t credit_value) { + BT_HDR* p_buf; + uint8_t* p; + tL2C_LCB* p_lcb = NULL; - if (!p_ccb) - return; - p_lcb = p_ccb->p_lcb; + if (!p_ccb) return; + p_lcb = p_ccb->p_lcb; - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - p_ccb->local_id = p_ccb->p_lcb->id; + p_ccb->local_id = p_ccb->p_lcb->id; - p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN, L2CAP_CMD_BLE_FLOW_CTRL_CREDIT, p_lcb->id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_credit_based_conn_req - no buffer"); - return; - } + p_buf = l2cu_build_header(p_lcb, L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN, + L2CAP_CMD_BLE_FLOW_CTRL_CREDIT, p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING("l2cu_send_peer_ble_credit_based_conn_req - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->local_cid); - UINT16_TO_STREAM (p, credit_value); + UINT16_TO_STREAM(p, p_ccb->local_cid); + UINT16_TO_STREAM(p, credit_value); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } /******************************************************************************* @@ -3200,39 +2963,37 @@ void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB *p_ccb, uint16_t credit_val * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB *p_ccb) -{ - BT_HDR *p_buf; - uint8_t *p; - tL2C_LCB *p_lcb = NULL; - L2CAP_TRACE_DEBUG ("%s",__func__); +void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB* p_ccb) { + BT_HDR* p_buf; + uint8_t* p; + tL2C_LCB* p_lcb = NULL; + L2CAP_TRACE_DEBUG("%s", __func__); - if (!p_ccb) - return; - p_lcb = p_ccb->p_lcb; + if (!p_ccb) return; + p_lcb = p_ccb->p_lcb; - /* Create an identifier for this packet */ - p_ccb->p_lcb->id++; - l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); + /* Create an identifier for this packet */ + p_ccb->p_lcb->id++; + l2cu_adj_id(p_ccb->p_lcb, L2CAP_ADJ_ID); - p_ccb->local_id = p_ccb->p_lcb->id; - p_buf = l2cu_build_header(p_lcb, L2CAP_DISC_REQ_LEN, L2CAP_CMD_DISC_REQ, p_lcb->id); - if (p_buf == NULL ) - { - L2CAP_TRACE_WARNING ("l2cu_send_peer_ble_credit_based_disconn_req - no buffer"); - return; - } + p_ccb->local_id = p_ccb->p_lcb->id; + p_buf = l2cu_build_header(p_lcb, L2CAP_DISC_REQ_LEN, L2CAP_CMD_DISC_REQ, + p_lcb->id); + if (p_buf == NULL) { + L2CAP_TRACE_WARNING( + "l2cu_send_peer_ble_credit_based_disconn_req - no buffer"); + return; + } - p = (uint8_t *)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + - L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; + p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM (p, p_ccb->remote_cid); - UINT16_TO_STREAM (p,p_ccb->local_cid); + UINT16_TO_STREAM(p, p_ccb->remote_cid); + UINT16_TO_STREAM(p, p_ccb->local_cid); - l2c_link_check_send_pkts (p_lcb, NULL, p_buf); + l2c_link_check_send_pkts(p_lcb, NULL, p_buf); } - /******************************************************************************* * Functions used by both Full and Light Stack ******************************************************************************/ @@ -3247,21 +3008,18 @@ void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB *p_ccb) * Returns pointer to matched LCB, or NULL if no match * ******************************************************************************/ -tL2C_LCB *l2cu_find_lcb_by_handle (uint16_t handle) -{ - int xx; - tL2C_LCB *p_lcb = &l2cb.lcb_pool[0]; +tL2C_LCB* l2cu_find_lcb_by_handle(uint16_t handle) { + int xx; + tL2C_LCB* p_lcb = &l2cb.lcb_pool[0]; - for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) - { - if ((p_lcb->in_use) && (p_lcb->handle == handle)) - { - return (p_lcb); - } + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) { + if ((p_lcb->in_use) && (p_lcb->handle == handle)) { + return (p_lcb); } + } - /* If here, no match found */ - return (NULL); + /* If here, no match found */ + return (NULL); } /******************************************************************************* @@ -3275,54 +3033,45 @@ tL2C_LCB *l2cu_find_lcb_by_handle (uint16_t handle) * Returns pointer to matched CCB, or NULL if no match * ******************************************************************************/ -tL2C_CCB *l2cu_find_ccb_by_cid (tL2C_LCB *p_lcb, uint16_t local_cid) -{ - tL2C_CCB *p_ccb = NULL; +tL2C_CCB* l2cu_find_ccb_by_cid(tL2C_LCB* p_lcb, uint16_t local_cid) { + tL2C_CCB* p_ccb = NULL; #if (L2CAP_UCD_INCLUDED == TRUE) - uint8_t xx; + uint8_t xx; #endif - if (local_cid >= L2CAP_BASE_APPL_CID) - { - /* find the associated CCB by "index" */ - local_cid -= L2CAP_BASE_APPL_CID; + if (local_cid >= L2CAP_BASE_APPL_CID) { + /* find the associated CCB by "index" */ + local_cid -= L2CAP_BASE_APPL_CID; - if (local_cid >= MAX_L2CAP_CHANNELS) - return NULL; + if (local_cid >= MAX_L2CAP_CHANNELS) return NULL; - p_ccb = l2cb.ccb_pool + local_cid; + p_ccb = l2cb.ccb_pool + local_cid; - /* make sure the CCB is in use */ - if (!p_ccb->in_use) - { - p_ccb = NULL; - } - /* make sure it's for the same LCB */ - else if (p_lcb && p_lcb != p_ccb->p_lcb) - { - p_ccb = NULL; - } + /* make sure the CCB is in use */ + if (!p_ccb->in_use) { + p_ccb = NULL; } -#if (L2CAP_UCD_INCLUDED == TRUE) - else - { - /* searching fixed channel */ - p_ccb = l2cb.ccb_pool; - for ( xx = 0; xx < MAX_L2CAP_CHANNELS; xx++ ) - { - if ((p_ccb->local_cid == local_cid) - &&(p_ccb->in_use) - &&(p_lcb == p_ccb->p_lcb)) - break; - else - p_ccb++; - } - if ( xx >= MAX_L2CAP_CHANNELS ) - return NULL; + /* make sure it's for the same LCB */ + else if (p_lcb && p_lcb != p_ccb->p_lcb) { + p_ccb = NULL; } + } +#if (L2CAP_UCD_INCLUDED == TRUE) + else { + /* searching fixed channel */ + p_ccb = l2cb.ccb_pool; + for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++) { + if ((p_ccb->local_cid == local_cid) && (p_ccb->in_use) && + (p_lcb == p_ccb->p_lcb)) + break; + else + p_ccb++; + } + if (xx >= MAX_L2CAP_CHANNELS) return NULL; + } #endif - return (p_ccb); + return (p_ccb); } #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) @@ -3337,109 +3086,94 @@ tL2C_CCB *l2cu_find_ccb_by_cid (tL2C_LCB *p_lcb, uint16_t local_cid) * Returns pointer to CCB or NULL * ******************************************************************************/ -static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb) -{ - tL2C_CCB *p_serve_ccb = NULL; - tL2C_CCB *p_ccb; - - int i, j; - - /* scan all of priority until finding a channel to serve */ - for ( i = 0; (i < L2CAP_NUM_CHNL_PRIORITY)&&(!p_serve_ccb); i++ ) - { - /* scan all channel within serving priority group until finding a channel to serve */ - for ( j = 0; (j < p_lcb->rr_serv[p_lcb->rr_pri].num_ccb)&&(!p_serve_ccb); j++) - { - /* scaning from next serving channel */ - p_ccb = p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb; - - if (!p_ccb) - { - L2CAP_TRACE_ERROR("p_serve_ccb is NULL, rr_pri=%d", p_lcb->rr_pri); - return NULL; - } +static tL2C_CCB* l2cu_get_next_channel_in_rr(tL2C_LCB* p_lcb) { + tL2C_CCB* p_serve_ccb = NULL; + tL2C_CCB* p_ccb; - L2CAP_TRACE_DEBUG("RR scan pri=%d, lcid=0x%04x, q_cout=%d", - p_ccb->ccb_priority, p_ccb->local_cid, - fixed_queue_length(p_ccb->xmit_hold_q)); - - /* store the next serving channel */ - /* this channel is the last channel of its priority group */ - if (( p_ccb->p_next_ccb == NULL ) - ||( p_ccb->p_next_ccb->ccb_priority != p_ccb->ccb_priority )) - { - /* next serving channel is set to the first channel in the group */ - p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb = p_lcb->rr_serv[p_lcb->rr_pri].p_first_ccb; - } - else - { - /* next serving channel is set to the next channel in the group */ - p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb = p_ccb->p_next_ccb; - } + int i, j; - if (p_ccb->chnl_state != CST_OPEN) - continue; + /* scan all of priority until finding a channel to serve */ + for (i = 0; (i < L2CAP_NUM_CHNL_PRIORITY) && (!p_serve_ccb); i++) { + /* scan all channel within serving priority group until finding a channel to + * serve */ + for (j = 0; (j < p_lcb->rr_serv[p_lcb->rr_pri].num_ccb) && (!p_serve_ccb); + j++) { + /* scaning from next serving channel */ + p_ccb = p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - L2CAP_TRACE_DEBUG("%s : Connection oriented channel",__func__); - if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) - continue; + if (!p_ccb) { + L2CAP_TRACE_ERROR("p_serve_ccb is NULL, rr_pri=%d", p_lcb->rr_pri); + return NULL; + } + + L2CAP_TRACE_DEBUG("RR scan pri=%d, lcid=0x%04x, q_cout=%d", + p_ccb->ccb_priority, p_ccb->local_cid, + fixed_queue_length(p_ccb->xmit_hold_q)); + + /* store the next serving channel */ + /* this channel is the last channel of its priority group */ + if ((p_ccb->p_next_ccb == NULL) || + (p_ccb->p_next_ccb->ccb_priority != p_ccb->ccb_priority)) { + /* next serving channel is set to the first channel in the group */ + p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb = + p_lcb->rr_serv[p_lcb->rr_pri].p_first_ccb; + } else { + /* next serving channel is set to the next channel in the group */ + p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb = p_ccb->p_next_ccb; + } + + if (p_ccb->chnl_state != CST_OPEN) continue; + + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + L2CAP_TRACE_DEBUG("%s : Connection oriented channel", __func__); + if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) continue; + + } else { + /* eL2CAP option in use */ + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) continue; - } - else - { - /* eL2CAP option in use */ - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) - continue; - - if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) - { - if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) - continue; - - /* If in eRTM mode, check for window closure */ - if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) - continue; - } - } - else - { - if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) - continue; - } - } + if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) { + if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) continue; - /* found a channel to serve */ - p_serve_ccb = p_ccb; - /* decrease quota of its priority group */ - p_lcb->rr_serv[p_lcb->rr_pri].quota--; + /* If in eRTM mode, check for window closure */ + if ((p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && + (l2c_fcr_is_flow_controlled(p_ccb))) + continue; + } + } else { + if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) continue; } + } - /* if there is no more quota of the priority group or no channel to have data to send */ - if ((p_lcb->rr_serv[p_lcb->rr_pri].quota == 0)||(!p_serve_ccb)) - { - /* serve next priority group */ - p_lcb->rr_pri = (p_lcb->rr_pri + 1) % L2CAP_NUM_CHNL_PRIORITY; - /* initialize its quota */ - p_lcb->rr_serv[p_lcb->rr_pri].quota = L2CAP_GET_PRIORITY_QUOTA(p_lcb->rr_pri); - } + /* found a channel to serve */ + p_serve_ccb = p_ccb; + /* decrease quota of its priority group */ + p_lcb->rr_serv[p_lcb->rr_pri].quota--; } - if (p_serve_ccb) - { - L2CAP_TRACE_DEBUG("RR service pri=%d, quota=%d, lcid=0x%04x", - p_serve_ccb->ccb_priority, - p_lcb->rr_serv[p_serve_ccb->ccb_priority].quota, - p_serve_ccb->local_cid ); + /* if there is no more quota of the priority group or no channel to have + * data to send */ + if ((p_lcb->rr_serv[p_lcb->rr_pri].quota == 0) || (!p_serve_ccb)) { + /* serve next priority group */ + p_lcb->rr_pri = (p_lcb->rr_pri + 1) % L2CAP_NUM_CHNL_PRIORITY; + /* initialize its quota */ + p_lcb->rr_serv[p_lcb->rr_pri].quota = + L2CAP_GET_PRIORITY_QUOTA(p_lcb->rr_pri); } + } + + if (p_serve_ccb) { + L2CAP_TRACE_DEBUG("RR service pri=%d, quota=%d, lcid=0x%04x", + p_serve_ccb->ccb_priority, + p_lcb->rr_serv[p_serve_ccb->ccb_priority].quota, + p_serve_ccb->local_cid); + } - return p_serve_ccb; + return p_serve_ccb; } -#else /* (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) */ +#else /* (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) */ /****************************************************************************** * @@ -3451,35 +3185,30 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb) * Returns pointer to CCB or NULL * ******************************************************************************/ -static tL2C_CCB *l2cu_get_next_channel(tL2C_LCB *p_lcb) -{ - tL2C_CCB *p_ccb; +static tL2C_CCB* l2cu_get_next_channel(tL2C_LCB* p_lcb) { + tL2C_CCB* p_ccb; - /* Get the first CCB with data to send. - */ - for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) - { - if (p_ccb->chnl_state != CST_OPEN) - continue; + /* Get the first CCB with data to send. + */ + for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) { + if (p_ccb->chnl_state != CST_OPEN) continue; - if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) - continue; + if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) continue; - if (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) - return p_ccb; + if (!fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) return p_ccb; - if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) - continue; + if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) continue; - /* If in eRTM mode, check for window closure */ - if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) - continue; + /* If in eRTM mode, check for window closure */ + if ((p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && + (l2c_fcr_is_flow_controlled(p_ccb))) + continue; - /* If here, we found someone */ - return p_ccb; - } + /* If here, we found someone */ + return p_ccb; + } - return NULL; + return NULL; } #endif /* (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) */ @@ -3493,121 +3222,99 @@ static tL2C_CCB *l2cu_get_next_channel(tL2C_LCB *p_lcb) * Returns pointer to buffer or NULL * ******************************************************************************/ -BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb) -{ - tL2C_CCB *p_ccb; - BT_HDR *p_buf; +BT_HDR* l2cu_get_next_buffer_to_send(tL2C_LCB* p_lcb) { + tL2C_CCB* p_ccb; + BT_HDR* p_buf; - /* Highest priority are fixed channels */ +/* Highest priority are fixed channels */ #if (L2CAP_NUM_FIXED_CHNLS > 0) - int xx; + int xx; - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) - { - p_ccb = p_lcb->p_fixed_ccbs[xx]; - if (p_ccb == NULL) - continue; + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + p_ccb = p_lcb->p_fixed_ccbs[xx]; + if (p_ccb == NULL) continue; - /* eL2CAP option in use */ - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) - continue; - - /* No more checks needed if sending from the reatransmit queue */ - if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) - { - if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) - continue; - - /* If in eRTM mode, check for window closure */ - if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) - continue; - } + /* eL2CAP option in use */ + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + if (p_ccb->fcrb.wait_ack || p_ccb->fcrb.remote_busy) continue; - p_buf = l2c_fcr_get_next_xmit_sdu_seg(p_ccb, 0); - if (p_buf != NULL) - { - l2cu_check_channel_congestion (p_ccb); - l2cu_set_acl_hci_header (p_buf, p_ccb); - return (p_buf); - } - } - else - { - if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) - { - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); - if(NULL == p_buf) - { - L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send: No data to be sent"); - return (NULL); - } - /* send tx complete */ - if (l2cb.fixed_reg[xx].pL2CA_FixedTxComplete_Cb) - (*l2cb.fixed_reg[xx].pL2CA_FixedTxComplete_Cb)(p_ccb->local_cid, 1); - - l2cu_check_channel_congestion (p_ccb); - l2cu_set_acl_hci_header (p_buf, p_ccb); - return (p_buf); - } - } - } + /* No more checks needed if sending from the reatransmit queue */ + if (fixed_queue_is_empty(p_ccb->fcrb.retrans_q)) { + if (fixed_queue_is_empty(p_ccb->xmit_hold_q)) continue; + + /* If in eRTM mode, check for window closure */ + if ((p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && + (l2c_fcr_is_flow_controlled(p_ccb))) + continue; + } + + p_buf = l2c_fcr_get_next_xmit_sdu_seg(p_ccb, 0); + if (p_buf != NULL) { + l2cu_check_channel_congestion(p_ccb); + l2cu_set_acl_hci_header(p_buf, p_ccb); + return (p_buf); + } + } else { + if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) { + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + if (NULL == p_buf) { + L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send: No data to be sent"); + return (NULL); + } + /* send tx complete */ + if (l2cb.fixed_reg[xx].pL2CA_FixedTxComplete_Cb) + (*l2cb.fixed_reg[xx].pL2CA_FixedTxComplete_Cb)(p_ccb->local_cid, 1); + + l2cu_check_channel_congestion(p_ccb); + l2cu_set_acl_hci_header(p_buf, p_ccb); + return (p_buf); + } + } + } #endif #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE) - /* get next serving channel in round-robin */ - p_ccb = l2cu_get_next_channel_in_rr( p_lcb ); + /* get next serving channel in round-robin */ + p_ccb = l2cu_get_next_channel_in_rr(p_lcb); #else - p_ccb = l2cu_get_next_channel( p_lcb ); + p_ccb = l2cu_get_next_channel(p_lcb); #endif - /* Return if no buffer */ - if (p_ccb == NULL) - return (NULL); - - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - /* Check credits */ - if(p_ccb->peer_conn_cfg.credits == 0) - { - L2CAP_TRACE_DEBUG("%s No credits to send packets",__func__); - return NULL; - } - p_buf = l2c_lcc_get_next_xmit_sdu_seg(p_ccb, 0); - if (p_buf == NULL) - return (NULL); + /* Return if no buffer */ + if (p_ccb == NULL) return (NULL); - p_ccb->peer_conn_cfg.credits--; - } - else - { - if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - p_buf = l2c_fcr_get_next_xmit_sdu_seg(p_ccb, 0); - if (p_buf == NULL) - return (NULL); - } - else - { - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); - if(NULL == p_buf) - { - L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send() #2: No data to be sent"); - return (NULL); - } - } + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + /* Check credits */ + if (p_ccb->peer_conn_cfg.credits == 0) { + L2CAP_TRACE_DEBUG("%s No credits to send packets", __func__); + return NULL; } + p_buf = l2c_lcc_get_next_xmit_sdu_seg(p_ccb, 0); + if (p_buf == NULL) return (NULL); - if ( p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_TxComplete_Cb && (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE) ) - (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, 1); + p_ccb->peer_conn_cfg.credits--; + } else { + if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + p_buf = l2c_fcr_get_next_xmit_sdu_seg(p_ccb, 0); + if (p_buf == NULL) return (NULL); + } else { + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); + if (NULL == p_buf) { + L2CAP_TRACE_ERROR("l2cu_get_buffer_to_send() #2: No data to be sent"); + return (NULL); + } + } + } + if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_TxComplete_Cb && + (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_ERTM_MODE)) + (*p_ccb->p_rcb->api.pL2CA_TxComplete_Cb)(p_ccb->local_cid, 1); - l2cu_check_channel_congestion (p_ccb); + l2cu_check_channel_congestion(p_ccb); - l2cu_set_acl_hci_header (p_buf, p_ccb); + l2cu_set_acl_hci_header(p_buf, p_ccb); - return (p_buf); + return (p_buf); } /****************************************************************************** @@ -3619,57 +3326,53 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb) * Returns None * ******************************************************************************/ -void l2cu_set_acl_hci_header (BT_HDR *p_buf, tL2C_CCB *p_ccb) -{ - uint8_t *p; +void l2cu_set_acl_hci_header(BT_HDR* p_buf, tL2C_CCB* p_ccb) { + uint8_t* p; - /* Set the pointer to the beginning of the data minus 4 bytes for the packet header */ - p = (uint8_t *)(p_buf + 1) + p_buf->offset - HCI_DATA_PREAMBLE_SIZE; + /* Set the pointer to the beginning of the data minus 4 bytes for the packet + * header */ + p = (uint8_t*)(p_buf + 1) + p_buf->offset - HCI_DATA_PREAMBLE_SIZE; - if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) - { - UINT16_TO_STREAM (p, p_ccb->p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT)); + if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) { + UINT16_TO_STREAM(p, p_ccb->p_lcb->handle | (L2CAP_PKT_START_NON_FLUSHABLE + << L2CAP_PKT_TYPE_SHIFT)); - uint16_t acl_data_size = controller_get_interface()->get_acl_data_size_ble(); - /* The HCI transport will segment the buffers. */ - if (p_buf->len > acl_data_size) - { - UINT16_TO_STREAM (p, acl_data_size); - } - else - { - UINT16_TO_STREAM (p, p_buf->len); - } + uint16_t acl_data_size = + controller_get_interface()->get_acl_data_size_ble(); + /* The HCI transport will segment the buffers. */ + if (p_buf->len > acl_data_size) { + UINT16_TO_STREAM(p, acl_data_size); + } else { + UINT16_TO_STREAM(p, p_buf->len); } - else - { + } else { #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) - if ( (((p_buf->layer_specific & L2CAP_FLUSHABLE_MASK) == L2CAP_FLUSHABLE_CH_BASED) && (p_ccb->is_flushable)) - || ((p_buf->layer_specific & L2CAP_FLUSHABLE_MASK) == L2CAP_FLUSHABLE_PKT) ) - { - UINT16_TO_STREAM (p, p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT)); - } - else - { - UINT16_TO_STREAM (p, p_ccb->p_lcb->handle | l2cb.non_flushable_pbf); - } + if ((((p_buf->layer_specific & L2CAP_FLUSHABLE_MASK) == + L2CAP_FLUSHABLE_CH_BASED) && + (p_ccb->is_flushable)) || + ((p_buf->layer_specific & L2CAP_FLUSHABLE_MASK) == + L2CAP_FLUSHABLE_PKT)) { + UINT16_TO_STREAM( + p, p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT)); + } else { + UINT16_TO_STREAM(p, p_ccb->p_lcb->handle | l2cb.non_flushable_pbf); + } #else - UINT16_TO_STREAM (p, p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT)); + UINT16_TO_STREAM( + p, p_ccb->p_lcb->handle | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT)); #endif - uint16_t acl_data_size = controller_get_interface()->get_acl_data_size_classic(); - /* The HCI transport will segment the buffers. */ - if (p_buf->len > acl_data_size) - { - UINT16_TO_STREAM (p, acl_data_size); - } - else - { - UINT16_TO_STREAM (p, p_buf->len); - } + uint16_t acl_data_size = + controller_get_interface()->get_acl_data_size_classic(); + /* The HCI transport will segment the buffers. */ + if (p_buf->len > acl_data_size) { + UINT16_TO_STREAM(p, acl_data_size); + } else { + UINT16_TO_STREAM(p, p_buf->len); } - p_buf->offset -= HCI_DATA_PREAMBLE_SIZE; - p_buf->len += HCI_DATA_PREAMBLE_SIZE; + } + p_buf->offset -= HCI_DATA_PREAMBLE_SIZE; + p_buf->len += HCI_DATA_PREAMBLE_SIZE; } /****************************************************************************** @@ -3681,111 +3384,104 @@ void l2cu_set_acl_hci_header (BT_HDR *p_buf, tL2C_CCB *p_ccb) * Returns None * ******************************************************************************/ -void l2cu_check_channel_congestion (tL2C_CCB *p_ccb) -{ - size_t q_count = fixed_queue_length(p_ccb->xmit_hold_q); +void l2cu_check_channel_congestion(tL2C_CCB* p_ccb) { + size_t q_count = fixed_queue_length(p_ccb->xmit_hold_q); #if (L2CAP_UCD_INCLUDED == TRUE) - if ( p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) - { - q_count += fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q); - } + if (p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) { + q_count += fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q); + } #endif - /* If the CCB queue limit is subject to a quota, check for congestion */ - /* if this channel has outgoing traffic */ - if (p_ccb->buff_quota != 0) - { - /* If this channel was congested */ - if ( p_ccb->cong_sent ) - { - /* If the channel is not congested now, tell the app */ - if (q_count <= (p_ccb->buff_quota / 2)) - { - p_ccb->cong_sent = false; - if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb) - { - L2CAP_TRACE_DEBUG ("L2CAP - Calling CongestionStatus_Cb (false), CID: 0x%04x xmit_hold_q.count: %u buff_quota: %u", - p_ccb->local_cid, q_count, p_ccb->buff_quota); - - /* Prevent recursive calling */ - l2cb.is_cong_cback_context = true; - (*p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb)(p_ccb->local_cid, false); - l2cb.is_cong_cback_context = false; - } + /* If the CCB queue limit is subject to a quota, check for congestion */ + /* if this channel has outgoing traffic */ + if (p_ccb->buff_quota != 0) { + /* If this channel was congested */ + if (p_ccb->cong_sent) { + /* If the channel is not congested now, tell the app */ + if (q_count <= (p_ccb->buff_quota / 2)) { + p_ccb->cong_sent = false; + if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb) { + L2CAP_TRACE_DEBUG( + "L2CAP - Calling CongestionStatus_Cb (false), CID: 0x%04x " + "xmit_hold_q.count: %u buff_quota: %u", + p_ccb->local_cid, q_count, p_ccb->buff_quota); + + /* Prevent recursive calling */ + l2cb.is_cong_cback_context = true; + (*p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb)(p_ccb->local_cid, + false); + l2cb.is_cong_cback_context = false; + } #if (L2CAP_UCD_INCLUDED == TRUE) - else if ( p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) - { - if ( p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ) - { - L2CAP_TRACE_DEBUG ("L2CAP - Calling UCD CongestionStatus_Cb (false), SecPendingQ:%u,XmitQ:%u,Quota:%u", - fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q), - fixed_queue_length(p_ccb->xmit_hold_q), - p_ccb->buff_quota); - p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( p_ccb->p_lcb->remote_bd_addr, false ); - } - } + else if (p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) { + if (p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb) { + L2CAP_TRACE_DEBUG( + "L2CAP - Calling UCD CongestionStatus_Cb (false), " + "SecPendingQ:%u,XmitQ:%u,Quota:%u", + fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q), + fixed_queue_length(p_ccb->xmit_hold_q), p_ccb->buff_quota); + p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( + p_ccb->p_lcb->remote_bd_addr, false); + } + } #endif #if (L2CAP_NUM_FIXED_CHNLS > 0) - else - { - uint8_t xx; - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx ++) - { - if (p_ccb->p_lcb->p_fixed_ccbs[xx] == p_ccb) - { - if (l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb != NULL) - (* l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb)(p_ccb->p_lcb->remote_bd_addr, false); - break; - } - } - } -#endif + else { + uint8_t xx; + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + if (p_ccb->p_lcb->p_fixed_ccbs[xx] == p_ccb) { + if (l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb != NULL) + (*l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb)( + p_ccb->p_lcb->remote_bd_addr, false); + break; } + } + } +#endif + } + } else { + /* If this channel was not congested but it is congested now, tell the app + */ + if (q_count > p_ccb->buff_quota) { + p_ccb->cong_sent = true; + if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb) { + L2CAP_TRACE_DEBUG( + "L2CAP - Calling CongestionStatus_Cb " + "(true),CID:0x%04x,XmitQ:%u,Quota:%u", + p_ccb->local_cid, q_count, p_ccb->buff_quota); + + (*p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb)(p_ccb->local_cid, + true); } - else - { - /* If this channel was not congested but it is congested now, tell the app */ - if (q_count > p_ccb->buff_quota) - { - p_ccb->cong_sent = true; - if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb) - { - L2CAP_TRACE_DEBUG ("L2CAP - Calling CongestionStatus_Cb (true),CID:0x%04x,XmitQ:%u,Quota:%u", - p_ccb->local_cid, q_count, p_ccb->buff_quota); - - (*p_ccb->p_rcb->api.pL2CA_CongestionStatus_Cb)(p_ccb->local_cid, true); - } #if (L2CAP_UCD_INCLUDED == TRUE) - else if ( p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID ) - { - if ( p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb ) - { - L2CAP_TRACE_DEBUG("L2CAP - Calling UCD CongestionStatus_Cb (true), SecPendingQ:%u,XmitQ:%u,Quota:%u", - fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q), - fixed_queue_length(p_ccb->xmit_hold_q), - p_ccb->buff_quota); - p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( p_ccb->p_lcb->remote_bd_addr, true ); - } - } + else if (p_ccb->p_rcb && p_ccb->local_cid == L2CAP_CONNECTIONLESS_CID) { + if (p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb) { + L2CAP_TRACE_DEBUG( + "L2CAP - Calling UCD CongestionStatus_Cb (true), " + "SecPendingQ:%u,XmitQ:%u,Quota:%u", + fixed_queue_length(p_ccb->p_lcb->ucd_out_sec_pending_q), + fixed_queue_length(p_ccb->xmit_hold_q), p_ccb->buff_quota); + p_ccb->p_rcb->ucd.cb_info.pL2CA_UCD_Congestion_Status_Cb( + p_ccb->p_lcb->remote_bd_addr, true); + } + } #endif #if (L2CAP_NUM_FIXED_CHNLS > 0) - else - { - uint8_t xx; - for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx ++) - { - if (p_ccb->p_lcb->p_fixed_ccbs[xx] == p_ccb) - { - if (l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb != NULL) - (* l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb)(p_ccb->p_lcb->remote_bd_addr, true); - break; - } - } - } -#endif + else { + uint8_t xx; + for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++) { + if (p_ccb->p_lcb->p_fixed_ccbs[xx] == p_ccb) { + if (l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb != NULL) + (*l2cb.fixed_reg[xx].pL2CA_FixedCong_Cb)( + p_ccb->p_lcb->remote_bd_addr, true); + break; } + } } +#endif + } } + } } /******************************************************************************* @@ -3798,7 +3494,4 @@ void l2cu_check_channel_congestion (tL2C_CCB *p_ccb) * false if p_ccb is null or is released. * ******************************************************************************/ -bool l2cu_is_ccb_active (tL2C_CCB *p_ccb) -{ - return (p_ccb && p_ccb->in_use); -} +bool l2cu_is_ccb_active(tL2C_CCB* p_ccb) { return (p_ccb && p_ccb->in_use); } diff --git a/stack/l2cap/l2cap_client.cc b/stack/l2cap/l2cap_client.cc old mode 100755 new mode 100644 index 639e63c18..ef19235e3 --- a/stack/l2cap/l2cap_client.cc +++ b/stack/l2cap/l2cap_client.cc @@ -33,56 +33,62 @@ struct l2cap_client_t { l2cap_client_callbacks_t callbacks; - void *context; + void* context; uint16_t local_channel_id; uint16_t remote_mtu; bool configured_self; bool configured_peer; bool is_congested; - list_t *outbound_fragments; + list_t* outbound_fragments; }; -static void connect_completed_cb(uint16_t local_channel_id, uint16_t error_code); -static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *requested_parameters); -static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *negotiated_parameters); +static void connect_completed_cb(uint16_t local_channel_id, + uint16_t error_code); +static void config_request_cb(uint16_t local_channel_id, + tL2CAP_CFG_INFO* requested_parameters); +static void config_completed_cb(uint16_t local_channel_id, + tL2CAP_CFG_INFO* negotiated_parameters); static void disconnect_request_cb(uint16_t local_channel_id, bool ack_required); -static void disconnect_completed_cb(uint16_t local_channel_id, uint16_t error_code); +static void disconnect_completed_cb(uint16_t local_channel_id, + uint16_t error_code); static void congestion_cb(uint16_t local_channel_id, bool is_congested); -static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet); -static void write_completed_cb(uint16_t local_channel_id, uint16_t packets_completed); +static void read_ready_cb(uint16_t local_channel_id, BT_HDR* packet); +static void write_completed_cb(uint16_t local_channel_id, + uint16_t packets_completed); -static void fragment_packet(l2cap_client_t *client, buffer_t *packet); -static void dispatch_fragments(l2cap_client_t *client); -static l2cap_client_t *find(uint16_t local_channel_id); +static void fragment_packet(l2cap_client_t* client, buffer_t* packet); +static void dispatch_fragments(l2cap_client_t* client); +static l2cap_client_t* find(uint16_t local_channel_id); // From the Bluetooth Core specification. static const uint16_t L2CAP_MTU_DEFAULT = 672; static const uint16_t L2CAP_MTU_MINIMUM = 48; static const tL2CAP_APPL_INFO l2cap_callbacks = { - .pL2CA_ConnectCfm_Cb = connect_completed_cb, - .pL2CA_ConfigInd_Cb = config_request_cb, - .pL2CA_ConfigCfm_Cb = config_completed_cb, - .pL2CA_DisconnectInd_Cb = disconnect_request_cb, - .pL2CA_DisconnectCfm_Cb = disconnect_completed_cb, - .pL2CA_CongestionStatus_Cb = congestion_cb, - .pL2CA_DataInd_Cb = read_ready_cb, - .pL2CA_TxComplete_Cb = write_completed_cb, + .pL2CA_ConnectCfm_Cb = connect_completed_cb, + .pL2CA_ConfigInd_Cb = config_request_cb, + .pL2CA_ConfigCfm_Cb = config_completed_cb, + .pL2CA_DisconnectInd_Cb = disconnect_request_cb, + .pL2CA_DisconnectCfm_Cb = disconnect_completed_cb, + .pL2CA_CongestionStatus_Cb = congestion_cb, + .pL2CA_DataInd_Cb = read_ready_cb, + .pL2CA_TxComplete_Cb = write_completed_cb, }; -static list_t *l2cap_clients; // A list of l2cap_client_t. Container does not own objects. +static list_t* + l2cap_clients; // A list of l2cap_client_t. Container does not own objects. -buffer_t *l2cap_buffer_new(size_t size) { - buffer_t *buf = buffer_new(size + L2CAP_MIN_OFFSET); - buffer_t *slice = NULL; - if (buf) - slice = buffer_new_slice(buf, size); +buffer_t* l2cap_buffer_new(size_t size) { + buffer_t* buf = buffer_new(size + L2CAP_MIN_OFFSET); + buffer_t* slice = NULL; + if (buf) slice = buffer_new_slice(buf, size); buffer_free(buf); return slice; } -l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void *context) { +l2cap_client_t* l2cap_client_new(const l2cap_client_callbacks_t* callbacks, + void* context) { assert(callbacks != NULL); assert(callbacks->connected != NULL); assert(callbacks->disconnected != NULL); @@ -92,12 +98,13 @@ l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void if (!l2cap_clients) { l2cap_clients = list_new(NULL); if (!l2cap_clients) { - LOG_ERROR(LOG_TAG, "%s unable to allocate space for L2CAP client list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate space for L2CAP client list.", + __func__); return NULL; } } - l2cap_client_t *ret = (l2cap_client_t *)osi_calloc(sizeof(l2cap_client_t)); + l2cap_client_t* ret = (l2cap_client_t*)osi_calloc(sizeof(l2cap_client_t)); ret->callbacks = *callbacks; ret->context = context; @@ -110,9 +117,8 @@ l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void return ret; } -void l2cap_client_free(l2cap_client_t *client) { - if (!client) - return; +void l2cap_client_free(l2cap_client_t* client) { + if (!client) return; list_remove(l2cap_clients, client); l2cap_client_disconnect(client); @@ -120,7 +126,8 @@ void l2cap_client_free(l2cap_client_t *client) { osi_free(client); } -bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdaddr, uint16_t psm) { +bool l2cap_client_connect(l2cap_client_t* client, + const bt_bdaddr_t* remote_bdaddr, uint16_t psm) { assert(client != NULL); assert(remote_bdaddr != NULL); assert(psm != 0); @@ -130,7 +137,7 @@ bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdad assert(!client->configured_peer); assert(!L2C_INVALID_PSM(psm)); - client->local_channel_id = L2CA_ConnectReq(psm, (uint8_t *)remote_bdaddr); + client->local_channel_id = L2CA_ConnectReq(psm, (uint8_t*)remote_bdaddr); if (!client->local_channel_id) { LOG_ERROR(LOG_TAG, "%s unable to create L2CAP connection.", __func__); return false; @@ -140,11 +147,12 @@ bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdad return true; } -void l2cap_client_disconnect(l2cap_client_t *client) { +void l2cap_client_disconnect(l2cap_client_t* client) { assert(client != NULL); if (client->local_channel_id && !L2CA_DisconnectReq(client->local_channel_id)) - LOG_ERROR(LOG_TAG, "%s unable to send disconnect message for LCID 0x%04x.", __func__, client->local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to send disconnect message for LCID 0x%04x.", + __func__, client->local_channel_id); client->local_channel_id = 0; client->remote_mtu = L2CAP_MTU_DEFAULT; @@ -152,42 +160,46 @@ void l2cap_client_disconnect(l2cap_client_t *client) { client->configured_peer = false; client->is_congested = false; - for (const list_node_t *node = list_begin(client->outbound_fragments); node != list_end(client->outbound_fragments); node = list_next(node)) + for (const list_node_t* node = list_begin(client->outbound_fragments); + node != list_end(client->outbound_fragments); node = list_next(node)) osi_free(list_node(node)); list_clear(client->outbound_fragments); } -bool l2cap_client_is_connected(const l2cap_client_t *client) { +bool l2cap_client_is_connected(const l2cap_client_t* client) { assert(client != NULL); - return client->local_channel_id != 0 && client->configured_self && client->configured_peer; + return client->local_channel_id != 0 && client->configured_self && + client->configured_peer; } -bool l2cap_client_write(l2cap_client_t *client, buffer_t *packet) { +bool l2cap_client_write(l2cap_client_t* client, buffer_t* packet) { assert(client != NULL); assert(packet != NULL); assert(l2cap_client_is_connected(client)); - if (client->is_congested) - return false; + if (client->is_congested) return false; fragment_packet(client, packet); dispatch_fragments(client); return true; } -static void connect_completed_cb(uint16_t local_channel_id, uint16_t error_code) { +static void connect_completed_cb(uint16_t local_channel_id, + uint16_t error_code) { assert(local_channel_id != 0); - l2cap_client_t *client = find(local_channel_id); + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client for LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client for LCID 0x%04x.", + __func__, local_channel_id); return; } if (error_code != L2CAP_CONN_OK) { - LOG_ERROR(LOG_TAG, "%s error connecting L2CAP channel: %d.", __func__, error_code); + LOG_ERROR(LOG_TAG, "%s error connecting L2CAP channel: %d.", __func__, + error_code); client->callbacks.disconnected(client, client->context); return; } @@ -201,12 +213,14 @@ static void connect_completed_cb(uint16_t local_channel_id, uint16_t error_code) } } -static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *requested_parameters) { +static void config_request_cb(uint16_t local_channel_id, + tL2CAP_CFG_INFO* requested_parameters) { tL2CAP_CFG_INFO response; - l2cap_client_t *client = find(local_channel_id); + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", + __func__, local_channel_id); return; } @@ -235,7 +249,8 @@ static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *reques } if (!L2CA_ConfigRsp(local_channel_id, &response)) { - LOG_ERROR(LOG_TAG, "%s unable to send config response for LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to send config response for LCID 0x%04x.", + __func__, local_channel_id); l2cap_client_disconnect(client); return; } @@ -246,11 +261,13 @@ static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *reques client->callbacks.connected(client, client->context); } -static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *negotiated_parameters) { - l2cap_client_t *client = find(local_channel_id); +static void config_completed_cb(uint16_t local_channel_id, + tL2CAP_CFG_INFO* negotiated_parameters) { + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", + __func__, local_channel_id); return; } @@ -260,13 +277,18 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego break; case L2CAP_CFG_UNACCEPTABLE_PARAMS: - // TODO: see if we can renegotiate parameters instead of dropping the connection. - LOG_WARN(LOG_TAG, "%s dropping L2CAP connection due to unacceptable config parameters.", __func__); + // TODO: see if we can renegotiate parameters instead of dropping the + // connection. + LOG_WARN( + LOG_TAG, + "%s dropping L2CAP connection due to unacceptable config parameters.", + __func__); l2cap_client_disconnect(client); break; case L2CAP_CFG_OK: - // If we've configured both endpoints, let the listener know we've connected. + // If we've configured both endpoints, let the listener know we've + // connected. client->configured_self = true; if (l2cap_client_is_connected(client)) client->callbacks.connected(client, client->context); @@ -274,21 +296,24 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego // Failure, no further parameter negotiation possible. default: - LOG_WARN(LOG_TAG, "%s L2CAP parameter negotiation failed with error code %d.", __func__, negotiated_parameters->result); + LOG_WARN(LOG_TAG, + "%s L2CAP parameter negotiation failed with error code %d.", + __func__, negotiated_parameters->result); l2cap_client_disconnect(client); break; } } -static void disconnect_request_cb(uint16_t local_channel_id, bool ack_required) { - l2cap_client_t *client = find(local_channel_id); +static void disconnect_request_cb(uint16_t local_channel_id, + bool ack_required) { + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", + __func__, local_channel_id); return; } - if (ack_required) - L2CA_DisconnectRsp(local_channel_id); + if (ack_required) L2CA_DisconnectRsp(local_channel_id); // We already sent a disconnect response so this LCID is now invalid. client->local_channel_id = 0; @@ -297,12 +322,14 @@ static void disconnect_request_cb(uint16_t local_channel_id, bool ack_required) client->callbacks.disconnected(client, client->context); } -static void disconnect_completed_cb(uint16_t local_channel_id, UNUSED_ATTR uint16_t error_code) { +static void disconnect_completed_cb(uint16_t local_channel_id, + UNUSED_ATTR uint16_t error_code) { assert(local_channel_id != 0); - l2cap_client_t *client = find(local_channel_id); + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", + __func__, local_channel_id); return; } @@ -315,9 +342,10 @@ static void disconnect_completed_cb(uint16_t local_channel_id, UNUSED_ATTR uint1 static void congestion_cb(uint16_t local_channel_id, bool is_congested) { assert(local_channel_id != 0); - l2cap_client_t *client = find(local_channel_id); + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", + __func__, local_channel_id); return; } @@ -333,17 +361,18 @@ static void congestion_cb(uint16_t local_channel_id, bool is_congested) { } } -static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet) { +static void read_ready_cb(uint16_t local_channel_id, BT_HDR* packet) { assert(local_channel_id != 0); - l2cap_client_t *client = find(local_channel_id); + l2cap_client_t* client = find(local_channel_id); if (!client) { - LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", + __func__, local_channel_id); return; } // TODO(sharvil): eliminate copy from BT_HDR. - buffer_t *buffer = buffer_new(packet->len); + buffer_t* buffer = buffer_new(packet->len); memcpy(buffer_ptr(buffer), packet->data + packet->offset, packet->len); osi_free(packet); @@ -351,22 +380,24 @@ static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet) { buffer_free(buffer); } -static void write_completed_cb(UNUSED_ATTR uint16_t local_channel_id, UNUSED_ATTR uint16_t packets_completed) { +static void write_completed_cb(UNUSED_ATTR uint16_t local_channel_id, + UNUSED_ATTR uint16_t packets_completed) { // Do nothing. We update congestion state based on the congestion callback // and we've already removed items from outbound_fragments list so we don't // really care how many packets were successfully dispatched. } -static void fragment_packet(l2cap_client_t *client, buffer_t *packet) { +static void fragment_packet(l2cap_client_t* client, buffer_t* packet) { assert(client != NULL); assert(packet != NULL); // TODO(sharvil): eliminate copy into BT_HDR. - BT_HDR *bt_packet = - static_cast(osi_malloc(buffer_length(packet) + L2CAP_MIN_OFFSET)); + BT_HDR* bt_packet = static_cast( + osi_malloc(buffer_length(packet) + L2CAP_MIN_OFFSET)); bt_packet->offset = L2CAP_MIN_OFFSET; bt_packet->len = buffer_length(packet); - memcpy(bt_packet->data + bt_packet->offset, buffer_ptr(packet), buffer_length(packet)); + memcpy(bt_packet->data + bt_packet->offset, buffer_ptr(packet), + buffer_length(packet)); for (;;) { if (bt_packet->len <= client->remote_mtu) { @@ -377,11 +408,12 @@ static void fragment_packet(l2cap_client_t *client, buffer_t *packet) { break; } - BT_HDR *fragment = - static_cast(osi_malloc(client->remote_mtu + L2CAP_MIN_OFFSET)); + BT_HDR* fragment = + static_cast(osi_malloc(client->remote_mtu + L2CAP_MIN_OFFSET)); fragment->offset = L2CAP_MIN_OFFSET; fragment->len = client->remote_mtu; - memcpy(fragment->data + fragment->offset, bt_packet->data + bt_packet->offset, client->remote_mtu); + memcpy(fragment->data + fragment->offset, + bt_packet->data + bt_packet->offset, client->remote_mtu); list_append(client->outbound_fragments, fragment); @@ -390,12 +422,12 @@ static void fragment_packet(l2cap_client_t *client, buffer_t *packet) { } } -static void dispatch_fragments(l2cap_client_t *client) { +static void dispatch_fragments(l2cap_client_t* client) { assert(client != NULL); assert(!client->is_congested); while (!list_is_empty(client->outbound_fragments)) { - BT_HDR *packet = (BT_HDR *)list_front(client->outbound_fragments); + BT_HDR* packet = (BT_HDR*)list_front(client->outbound_fragments); list_remove(client->outbound_fragments, packet); switch (L2CA_DataWrite(client->local_channel_id, packet)) { @@ -404,7 +436,10 @@ static void dispatch_fragments(l2cap_client_t *client) { return; case L2CAP_DW_FAILED: - LOG_ERROR(LOG_TAG, "%s error writing data to L2CAP connection LCID 0x%04x; disconnecting.", __func__, client->local_channel_id); + LOG_ERROR(LOG_TAG, + "%s error writing data to L2CAP connection LCID 0x%04x; " + "disconnecting.", + __func__, client->local_channel_id); l2cap_client_disconnect(client); return; @@ -414,13 +449,13 @@ static void dispatch_fragments(l2cap_client_t *client) { } } -static l2cap_client_t *find(uint16_t local_channel_id) { +static l2cap_client_t* find(uint16_t local_channel_id) { assert(local_channel_id != 0); - for (const list_node_t *node = list_begin(l2cap_clients); node != list_end(l2cap_clients); node = list_next(node)) { - l2cap_client_t *client = (l2cap_client_t *)list_node(node); - if (client->local_channel_id == local_channel_id) - return client; + for (const list_node_t* node = list_begin(l2cap_clients); + node != list_end(l2cap_clients); node = list_next(node)) { + l2cap_client_t* client = (l2cap_client_t*)list_node(node); + if (client->local_channel_id == local_channel_id) return client; } return NULL; diff --git a/stack/mcap/mca_api.cc b/stack/mcap/mca_api.cc index 937d8f496..27af2b81b 100644 --- a/stack/mcap/mca_api.cc +++ b/stack/mcap/mca_api.cc @@ -34,7 +34,6 @@ #include "btu.h" - /******************************************************************************* * * Function mca_process_timeout @@ -47,11 +46,10 @@ * Returns void * ******************************************************************************/ -void mca_ccb_timer_timeout(void *data) -{ - tMCA_CCB *p_ccb = (tMCA_CCB *)data; +void mca_ccb_timer_timeout(void* data) { + tMCA_CCB* p_ccb = (tMCA_CCB*)data; - mca_ccb_event(p_ccb, MCA_CCB_RSP_TOUT_EVT, NULL); + mca_ccb_event(p_ccb, MCA_CCB_RSP_TOUT_EVT, NULL); } /******************************************************************************* @@ -64,14 +62,13 @@ void mca_ccb_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void MCA_Init(void) -{ - memset(&mca_cb, 0, sizeof(tMCA_CB)); +void MCA_Init(void) { + memset(&mca_cb, 0, sizeof(tMCA_CB)); #if defined(MCA_INITIAL_TRACE_LEVEL) - mca_cb.trace_level = MCA_INITIAL_TRACE_LEVEL; + mca_cb.trace_level = MCA_INITIAL_TRACE_LEVEL; #else - mca_cb.trace_level = BT_TRACE_LEVEL_NONE; + mca_cb.trace_level = BT_TRACE_LEVEL_NONE; #endif } @@ -96,12 +93,10 @@ void MCA_Init(void) * the input parameter is 0xff. * ******************************************************************************/ -uint8_t MCA_SetTraceLevel (uint8_t level) -{ - if (level != 0xFF) - mca_cb.trace_level = level; +uint8_t MCA_SetTraceLevel(uint8_t level) { + if (level != 0xFF) mca_cb.trace_level = level; - return (mca_cb.trace_level); + return (mca_cb.trace_level); } /******************************************************************************* @@ -116,64 +111,60 @@ uint8_t MCA_SetTraceLevel (uint8_t level) * Returns 0, if failed. Otherwise, the MCA handle. * ******************************************************************************/ -tMCA_HANDLE MCA_Register(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback) -{ - tMCA_RCB *p_rcb; - tMCA_HANDLE handle = 0; - tL2CAP_APPL_INFO l2c_cacp_appl; - tL2CAP_APPL_INFO l2c_dacp_appl; - - assert(p_reg != NULL ); - assert(p_cback != NULL ); - - MCA_TRACE_API ("MCA_Register: ctrl_psm:0x%x, data_psm:0x%x", p_reg->ctrl_psm, p_reg->data_psm); - - p_rcb = mca_rcb_alloc(p_reg); - if (p_rcb != NULL) - { - if (p_reg->ctrl_psm) - { - if (L2C_INVALID_PSM(p_reg->ctrl_psm) || L2C_INVALID_PSM(p_reg->data_psm)) - { - MCA_TRACE_ERROR ("INVALID_PSM"); - return 0; - } - - l2c_cacp_appl = *(tL2CAP_APPL_INFO *)&mca_l2c_int_appl; - l2c_cacp_appl.pL2CA_ConnectCfm_Cb = NULL; - l2c_dacp_appl = *(tL2CAP_APPL_INFO *)&l2c_cacp_appl; - l2c_cacp_appl.pL2CA_ConnectInd_Cb = mca_l2c_cconn_ind_cback; - l2c_dacp_appl.pL2CA_ConnectInd_Cb = mca_l2c_dconn_ind_cback; - if (L2CA_Register(p_reg->ctrl_psm, (tL2CAP_APPL_INFO *) &l2c_cacp_appl) && - L2CA_Register(p_reg->data_psm, (tL2CAP_APPL_INFO *) &l2c_dacp_appl)) - { - /* set security level */ - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_CTRL, p_reg->sec_mask, - p_reg->ctrl_psm, BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); - - /* in theory, we do not need this one for data_psm - * If we don't, L2CAP rejects with security block (3), - * which is different reject code from what MCAP spec suggests. - * we set this one, so mca_l2c_dconn_ind_cback can reject /w no resources (4) */ - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, p_reg->sec_mask, - p_reg->data_psm, BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); - } - else - { - MCA_TRACE_ERROR ("Failed to register to L2CAP"); - return 0; - } - } - else - p_rcb->reg.data_psm = 0; - handle = mca_rcb_to_handle (p_rcb); - p_rcb->p_cback = p_cback; - p_rcb->reg.rsp_tout = p_reg->rsp_tout; - } - return handle; +tMCA_HANDLE MCA_Register(tMCA_REG* p_reg, tMCA_CTRL_CBACK* p_cback) { + tMCA_RCB* p_rcb; + tMCA_HANDLE handle = 0; + tL2CAP_APPL_INFO l2c_cacp_appl; + tL2CAP_APPL_INFO l2c_dacp_appl; + + assert(p_reg != NULL); + assert(p_cback != NULL); + + MCA_TRACE_API("MCA_Register: ctrl_psm:0x%x, data_psm:0x%x", p_reg->ctrl_psm, + p_reg->data_psm); + + p_rcb = mca_rcb_alloc(p_reg); + if (p_rcb != NULL) { + if (p_reg->ctrl_psm) { + if (L2C_INVALID_PSM(p_reg->ctrl_psm) || + L2C_INVALID_PSM(p_reg->data_psm)) { + MCA_TRACE_ERROR("INVALID_PSM"); + return 0; + } + + l2c_cacp_appl = *(tL2CAP_APPL_INFO*)&mca_l2c_int_appl; + l2c_cacp_appl.pL2CA_ConnectCfm_Cb = NULL; + l2c_dacp_appl = *(tL2CAP_APPL_INFO*)&l2c_cacp_appl; + l2c_cacp_appl.pL2CA_ConnectInd_Cb = mca_l2c_cconn_ind_cback; + l2c_dacp_appl.pL2CA_ConnectInd_Cb = mca_l2c_dconn_ind_cback; + if (L2CA_Register(p_reg->ctrl_psm, (tL2CAP_APPL_INFO*)&l2c_cacp_appl) && + L2CA_Register(p_reg->data_psm, (tL2CAP_APPL_INFO*)&l2c_dacp_appl)) { + /* set security level */ + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_CTRL, + p_reg->sec_mask, p_reg->ctrl_psm, + BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); + + /* in theory, we do not need this one for data_psm + * If we don't, L2CAP rejects with security block (3), + * which is different reject code from what MCAP spec suggests. + * we set this one, so mca_l2c_dconn_ind_cback can reject /w no + * resources (4) */ + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, + p_reg->sec_mask, p_reg->data_psm, + BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); + } else { + MCA_TRACE_ERROR("Failed to register to L2CAP"); + return 0; + } + } else + p_rcb->reg.data_psm = 0; + handle = mca_rcb_to_handle(p_rcb); + p_rcb->p_cback = p_cback; + p_rcb->reg.rsp_tout = p_reg->rsp_tout; + } + return handle; } - /******************************************************************************* * * Function MCA_Deregister @@ -185,22 +176,19 @@ tMCA_HANDLE MCA_Register(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback) * Returns void * ******************************************************************************/ -void MCA_Deregister(tMCA_HANDLE handle) -{ - tMCA_RCB *p_rcb = mca_rcb_by_handle(handle); - - MCA_TRACE_API ("MCA_Deregister: %d", handle); - if (p_rcb && p_rcb->reg.ctrl_psm) - { - L2CA_Deregister(p_rcb->reg.ctrl_psm); - L2CA_Deregister(p_rcb->reg.data_psm); - btm_sec_clr_service_by_psm (p_rcb->reg.ctrl_psm); - btm_sec_clr_service_by_psm (p_rcb->reg.data_psm); - } - mca_rcb_dealloc(handle); +void MCA_Deregister(tMCA_HANDLE handle) { + tMCA_RCB* p_rcb = mca_rcb_by_handle(handle); + + MCA_TRACE_API("MCA_Deregister: %d", handle); + if (p_rcb && p_rcb->reg.ctrl_psm) { + L2CA_Deregister(p_rcb->reg.ctrl_psm); + L2CA_Deregister(p_rcb->reg.data_psm); + btm_sec_clr_service_by_psm(p_rcb->reg.ctrl_psm); + btm_sec_clr_service_by_psm(p_rcb->reg.data_psm); + } + mca_rcb_dealloc(handle); } - /******************************************************************************* * * Function MCA_CreateDep @@ -213,63 +201,51 @@ void MCA_Deregister(tMCA_HANDLE handle) * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_CreateDep(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - int i; - tMCA_RCB *p_rcb = mca_rcb_by_handle(handle); - tMCA_CS *p_depcs; - - assert(p_dep != NULL ); - assert(p_cs != NULL ); - assert(p_cs->p_data_cback != NULL ); - - MCA_TRACE_API ("MCA_CreateDep: %d", handle); - if (p_rcb) - { - if (p_cs->max_mdl > MCA_NUM_MDLS) - { - MCA_TRACE_ERROR ("max_mdl: %d is too big", p_cs->max_mdl ); - result = MCA_BAD_PARAMS; +tMCA_RESULT MCA_CreateDep(tMCA_HANDLE handle, tMCA_DEP* p_dep, tMCA_CS* p_cs) { + tMCA_RESULT result = MCA_BAD_HANDLE; + int i; + tMCA_RCB* p_rcb = mca_rcb_by_handle(handle); + tMCA_CS* p_depcs; + + assert(p_dep != NULL); + assert(p_cs != NULL); + assert(p_cs->p_data_cback != NULL); + + MCA_TRACE_API("MCA_CreateDep: %d", handle); + if (p_rcb) { + if (p_cs->max_mdl > MCA_NUM_MDLS) { + MCA_TRACE_ERROR("max_mdl: %d is too big", p_cs->max_mdl); + result = MCA_BAD_PARAMS; + } else { + p_depcs = p_rcb->dep; + if (p_cs->type == MCA_TDEP_ECHO) { + if (p_depcs->p_data_cback) { + MCA_TRACE_ERROR("Already has ECHO MDEP"); + return MCA_NO_RESOURCES; } - else - { - p_depcs = p_rcb->dep; - if (p_cs->type == MCA_TDEP_ECHO) - { - if (p_depcs->p_data_cback) - { - MCA_TRACE_ERROR ("Already has ECHO MDEP"); - return MCA_NO_RESOURCES; - } - memcpy (p_depcs, p_cs, sizeof (tMCA_CS)); - *p_dep = 0; - result = MCA_SUCCESS; - } - else - { - result = MCA_NO_RESOURCES; - /* non-echo MDEP starts from 1 */ - p_depcs++; - for (i=1; ip_data_cback == NULL) - { - memcpy (p_depcs, p_cs, sizeof (tMCA_CS)); - /* internally use type as the mdep id */ - p_depcs->type = i; - *p_dep = i; - result = MCA_SUCCESS; - break; - } - } - } + memcpy(p_depcs, p_cs, sizeof(tMCA_CS)); + *p_dep = 0; + result = MCA_SUCCESS; + } else { + result = MCA_NO_RESOURCES; + /* non-echo MDEP starts from 1 */ + p_depcs++; + for (i = 1; i < MCA_NUM_DEPS; i++, p_depcs++) { + if (p_depcs->p_data_cback == NULL) { + memcpy(p_depcs, p_cs, sizeof(tMCA_CS)); + /* internally use type as the mdep id */ + p_depcs->type = i; + *p_dep = i; + result = MCA_SUCCESS; + break; + } } + } } - return result; + } + return result; } - /******************************************************************************* * * Function MCA_DeleteDep @@ -283,36 +259,31 @@ tMCA_RESULT MCA_CreateDep(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs) * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_DeleteDep(tMCA_HANDLE handle, tMCA_DEP dep) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_RCB *p_rcb = mca_rcb_by_handle(handle); - tMCA_DCB *p_dcb; - int i, max; - tMCA_CS *p_depcs; - - MCA_TRACE_API ("MCA_DeleteDep: %d dep:%d", handle, dep); - if (p_rcb) - { - if (dep < MCA_NUM_DEPS && p_rcb->dep[dep].p_data_cback) - { - result = MCA_SUCCESS; - p_rcb->dep[dep].p_data_cback = NULL; - p_depcs = &(p_rcb->dep[dep]); - i = handle - 1; - max = MCA_NUM_MDLS*MCA_NUM_LINKS; - p_dcb = &mca_cb.dcb[i*max]; - /* make sure no MDL exists for this MDEP */ - for (i=0; istate && p_dcb->p_cs == p_depcs) - { - mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); - } - } +tMCA_RESULT MCA_DeleteDep(tMCA_HANDLE handle, tMCA_DEP dep) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_RCB* p_rcb = mca_rcb_by_handle(handle); + tMCA_DCB* p_dcb; + int i, max; + tMCA_CS* p_depcs; + + MCA_TRACE_API("MCA_DeleteDep: %d dep:%d", handle, dep); + if (p_rcb) { + if (dep < MCA_NUM_DEPS && p_rcb->dep[dep].p_data_cback) { + result = MCA_SUCCESS; + p_rcb->dep[dep].p_data_cback = NULL; + p_depcs = &(p_rcb->dep[dep]); + i = handle - 1; + max = MCA_NUM_MDLS * MCA_NUM_LINKS; + p_dcb = &mca_cb.dcb[i * max]; + /* make sure no MDL exists for this MDEP */ + for (i = 0; i < max; i++, p_dcb++) { + if (p_dcb->state && p_dcb->p_cs == p_depcs) { + mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); } + } } - return result; + } + return result; } /******************************************************************************* @@ -332,49 +303,42 @@ tMCA_RESULT MCA_DeleteDep(tMCA_HANDLE handle, tMCA_DEP dep) * ******************************************************************************/ tMCA_RESULT MCA_ConnectReq(tMCA_HANDLE handle, BD_ADDR bd_addr, - uint16_t ctrl_psm, uint16_t sec_mask) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb; - tMCA_TC_TBL *p_tbl; - - MCA_TRACE_API ("MCA_ConnectReq: %d psm:0x%x", handle, ctrl_psm); - p_ccb = mca_ccb_by_bd(handle, bd_addr); - if (p_ccb == NULL) - p_ccb = mca_ccb_alloc(handle, bd_addr); - else - { - MCA_TRACE_ERROR ("control channel already exists"); - return MCA_BUSY; - } - - if (p_ccb) - { - p_ccb->ctrl_vpsm = L2CA_Register (ctrl_psm, (tL2CAP_APPL_INFO *)&mca_l2c_int_appl); - result = MCA_NO_RESOURCES; - if (p_ccb->ctrl_vpsm) - { - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_CTRL, sec_mask, - p_ccb->ctrl_vpsm, BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); - p_ccb->lcid = mca_l2c_open_req(bd_addr, p_ccb->ctrl_vpsm, NULL); - if (p_ccb->lcid) - { - p_tbl = mca_tc_tbl_calloc(p_ccb); - if (p_tbl) - { - p_tbl->state = MCA_TC_ST_CONN; - p_ccb->sec_mask = sec_mask; - result = MCA_SUCCESS; - } - } + uint16_t ctrl_psm, uint16_t sec_mask) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb; + tMCA_TC_TBL* p_tbl; + + MCA_TRACE_API("MCA_ConnectReq: %d psm:0x%x", handle, ctrl_psm); + p_ccb = mca_ccb_by_bd(handle, bd_addr); + if (p_ccb == NULL) + p_ccb = mca_ccb_alloc(handle, bd_addr); + else { + MCA_TRACE_ERROR("control channel already exists"); + return MCA_BUSY; + } + + if (p_ccb) { + p_ccb->ctrl_vpsm = + L2CA_Register(ctrl_psm, (tL2CAP_APPL_INFO*)&mca_l2c_int_appl); + result = MCA_NO_RESOURCES; + if (p_ccb->ctrl_vpsm) { + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_CTRL, sec_mask, + p_ccb->ctrl_vpsm, BTM_SEC_PROTO_MCA, MCA_CTRL_TCID); + p_ccb->lcid = mca_l2c_open_req(bd_addr, p_ccb->ctrl_vpsm, NULL); + if (p_ccb->lcid) { + p_tbl = mca_tc_tbl_calloc(p_ccb); + if (p_tbl) { + p_tbl->state = MCA_TC_ST_CONN; + p_ccb->sec_mask = sec_mask; + result = MCA_SUCCESS; } - if (result != MCA_SUCCESS) - mca_ccb_dealloc (p_ccb, NULL); + } } - return result; + if (result != MCA_SUCCESS) mca_ccb_dealloc(p_ccb, NULL); + } + return result; } - /******************************************************************************* * * Function MCA_DisconnectReq @@ -389,21 +353,18 @@ tMCA_RESULT MCA_ConnectReq(tMCA_HANDLE handle, BD_ADDR bd_addr, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_DisconnectReq(tMCA_CL mcl) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - - MCA_TRACE_API ("MCA_DisconnectReq: %d ", mcl); - if (p_ccb) - { - result = MCA_SUCCESS; - mca_ccb_event (p_ccb, MCA_CCB_API_DISCONNECT_EVT, NULL); - } - return result; +tMCA_RESULT MCA_DisconnectReq(tMCA_CL mcl) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + + MCA_TRACE_API("MCA_DisconnectReq: %d ", mcl); + if (p_ccb) { + result = MCA_SUCCESS; + mca_ccb_event(p_ccb, MCA_CCB_API_DISCONNECT_EVT, NULL); + } + return result; } - /******************************************************************************* * * Function MCA_CreateMdl @@ -423,66 +384,62 @@ tMCA_RESULT MCA_DisconnectReq(tMCA_CL mcl) * ******************************************************************************/ tMCA_RESULT MCA_CreateMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, - uint16_t mdl_id, uint8_t peer_dep_id, - uint8_t cfg, const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_DCB *p_dcb; - - MCA_TRACE_API ("MCA_CreateMdl: %d dep=%d mdl_id=%d peer_dep_id=%d", mcl, dep, mdl_id, peer_dep_id); - if (p_ccb) - { - if (p_ccb->p_tx_req || p_ccb->p_rx_msg || p_ccb->cong) - { - MCA_TRACE_ERROR ("pending req"); - return MCA_BUSY; - } + uint16_t mdl_id, uint8_t peer_dep_id, uint8_t cfg, + const tMCA_CHNL_CFG* p_chnl_cfg) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_DCB* p_dcb; + + MCA_TRACE_API("MCA_CreateMdl: %d dep=%d mdl_id=%d peer_dep_id=%d", mcl, dep, + mdl_id, peer_dep_id); + if (p_ccb) { + if (p_ccb->p_tx_req || p_ccb->p_rx_msg || p_ccb->cong) { + MCA_TRACE_ERROR("pending req"); + return MCA_BUSY; + } - if ((peer_dep_id > MCA_MAX_MDEP_ID) || (!MCA_IS_VALID_MDL_ID(mdl_id))) - { - MCA_TRACE_ERROR ("bad peer dep id:%d or bad mdl id: %d ", peer_dep_id, mdl_id); - return MCA_BAD_PARAMS; - } + if ((peer_dep_id > MCA_MAX_MDEP_ID) || (!MCA_IS_VALID_MDL_ID(mdl_id))) { + MCA_TRACE_ERROR("bad peer dep id:%d or bad mdl id: %d ", peer_dep_id, + mdl_id); + return MCA_BAD_PARAMS; + } - if (mca_ccb_uses_mdl_id(p_ccb, mdl_id)) - { - MCA_TRACE_ERROR ("mdl id: %d is used in the control link", mdl_id); - return MCA_BAD_MDL_ID; - } + if (mca_ccb_uses_mdl_id(p_ccb, mdl_id)) { + MCA_TRACE_ERROR("mdl id: %d is used in the control link", mdl_id); + return MCA_BAD_MDL_ID; + } - p_dcb = mca_dcb_alloc(p_ccb, dep); - result = MCA_NO_RESOURCES; - if (p_dcb) - { - /* save the info required by dcb connection */ - p_dcb->p_chnl_cfg = p_chnl_cfg; - p_dcb->mdl_id = mdl_id; - tMCA_CCB_MSG *p_evt_data = - (tMCA_CCB_MSG *)osi_malloc(sizeof(tMCA_CCB_MSG)); - if (!p_ccb->data_vpsm) - p_ccb->data_vpsm = L2CA_Register (data_psm, (tL2CAP_APPL_INFO *)&mca_l2c_int_appl); - if (p_ccb->data_vpsm) { - p_evt_data->dcb_idx = mca_dcb_to_hdl (p_dcb); - p_evt_data->mdep_id = peer_dep_id; - p_evt_data->mdl_id = mdl_id; - p_evt_data->param = cfg; - p_evt_data->op_code = MCA_OP_MDL_CREATE_REQ; - p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; - p_evt_data->hdr.layer_specific = false; - mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT *)p_evt_data); - return MCA_SUCCESS; - } else { - osi_free(p_evt_data); - } - - mca_dcb_dealloc(p_dcb, NULL); - } + p_dcb = mca_dcb_alloc(p_ccb, dep); + result = MCA_NO_RESOURCES; + if (p_dcb) { + /* save the info required by dcb connection */ + p_dcb->p_chnl_cfg = p_chnl_cfg; + p_dcb->mdl_id = mdl_id; + tMCA_CCB_MSG* p_evt_data = + (tMCA_CCB_MSG*)osi_malloc(sizeof(tMCA_CCB_MSG)); + if (!p_ccb->data_vpsm) + p_ccb->data_vpsm = + L2CA_Register(data_psm, (tL2CAP_APPL_INFO*)&mca_l2c_int_appl); + if (p_ccb->data_vpsm) { + p_evt_data->dcb_idx = mca_dcb_to_hdl(p_dcb); + p_evt_data->mdep_id = peer_dep_id; + p_evt_data->mdl_id = mdl_id; + p_evt_data->param = cfg; + p_evt_data->op_code = MCA_OP_MDL_CREATE_REQ; + p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; + p_evt_data->hdr.layer_specific = false; + mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT*)p_evt_data); + return MCA_SUCCESS; + } else { + osi_free(p_evt_data); + } + + mca_dcb_dealloc(p_dcb, NULL); } - return result; + } + return result; } - /******************************************************************************* * * Function MCA_CreateMdlRsp @@ -498,61 +455,54 @@ tMCA_RESULT MCA_CreateMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, - uint16_t mdl_id, uint8_t cfg, uint8_t rsp_code, - const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_CCB_MSG evt_data; - tMCA_DCB *p_dcb; - - MCA_TRACE_API ("MCA_CreateMdlRsp: %d dep=%d mdl_id=%d cfg=%d rsp_code=%d", mcl, dep, mdl_id, cfg, rsp_code); - assert(p_chnl_cfg != NULL ); - if (p_ccb) - { - if (p_ccb->cong) - { - MCA_TRACE_ERROR ("congested"); - return MCA_BUSY; - } - if (p_ccb->p_rx_msg && (p_ccb->p_rx_msg->mdep_id == dep ) - && (p_ccb->p_rx_msg->mdl_id == mdl_id) && (p_ccb->p_rx_msg->op_code == MCA_OP_MDL_CREATE_REQ)) - { - result = MCA_SUCCESS; - evt_data.dcb_idx = 0; - if (rsp_code == MCA_RSP_SUCCESS) - { - p_dcb = mca_dcb_alloc(p_ccb, dep); - if (p_dcb) - { - evt_data.dcb_idx = mca_dcb_to_hdl(p_dcb); - p_dcb->p_chnl_cfg = p_chnl_cfg; - p_dcb->mdl_id = mdl_id; - } - else - { - rsp_code = MCA_RSP_MDEP_BUSY; - result = MCA_NO_RESOURCES; - } - } - - if (result == MCA_SUCCESS) - { - evt_data.mdl_id = mdl_id; - evt_data.param = cfg; - evt_data.rsp_code = rsp_code; - evt_data.op_code = MCA_OP_MDL_CREATE_RSP; - mca_ccb_event(p_ccb, MCA_CCB_API_RSP_EVT, (tMCA_CCB_EVT *)&evt_data); - } - } - else - { - MCA_TRACE_ERROR ("The given MCL is not expecting a MCA_CreateMdlRsp with the given parameters" ); - result = MCA_BAD_PARAMS; +tMCA_RESULT MCA_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, uint16_t mdl_id, + uint8_t cfg, uint8_t rsp_code, + const tMCA_CHNL_CFG* p_chnl_cfg) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_CCB_MSG evt_data; + tMCA_DCB* p_dcb; + + MCA_TRACE_API("MCA_CreateMdlRsp: %d dep=%d mdl_id=%d cfg=%d rsp_code=%d", mcl, + dep, mdl_id, cfg, rsp_code); + assert(p_chnl_cfg != NULL); + if (p_ccb) { + if (p_ccb->cong) { + MCA_TRACE_ERROR("congested"); + return MCA_BUSY; + } + if (p_ccb->p_rx_msg && (p_ccb->p_rx_msg->mdep_id == dep) && + (p_ccb->p_rx_msg->mdl_id == mdl_id) && + (p_ccb->p_rx_msg->op_code == MCA_OP_MDL_CREATE_REQ)) { + result = MCA_SUCCESS; + evt_data.dcb_idx = 0; + if (rsp_code == MCA_RSP_SUCCESS) { + p_dcb = mca_dcb_alloc(p_ccb, dep); + if (p_dcb) { + evt_data.dcb_idx = mca_dcb_to_hdl(p_dcb); + p_dcb->p_chnl_cfg = p_chnl_cfg; + p_dcb->mdl_id = mdl_id; + } else { + rsp_code = MCA_RSP_MDEP_BUSY; + result = MCA_NO_RESOURCES; } + } + + if (result == MCA_SUCCESS) { + evt_data.mdl_id = mdl_id; + evt_data.param = cfg; + evt_data.rsp_code = rsp_code; + evt_data.op_code = MCA_OP_MDL_CREATE_RSP; + mca_ccb_event(p_ccb, MCA_CCB_API_RSP_EVT, (tMCA_CCB_EVT*)&evt_data); + } + } else { + MCA_TRACE_ERROR( + "The given MCL is not expecting a MCA_CreateMdlRsp with the given " + "parameters"); + result = MCA_BAD_PARAMS; } - return result; + } + return result; } /******************************************************************************* @@ -566,21 +516,18 @@ tMCA_RESULT MCA_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_CloseReq(tMCA_DL mdl) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_DCB *p_dcb = mca_dcb_by_hdl(mdl); - - MCA_TRACE_API ("MCA_CloseReq: %d ", mdl); - if (p_dcb) - { - result = MCA_SUCCESS; - mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); - } - return result; +tMCA_RESULT MCA_CloseReq(tMCA_DL mdl) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_DCB* p_dcb = mca_dcb_by_hdl(mdl); + + MCA_TRACE_API("MCA_CloseReq: %d ", mdl); + if (p_dcb) { + result = MCA_SUCCESS; + mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); + } + return result; } - /******************************************************************************* * * Function MCA_ReconnectMdl @@ -597,56 +544,51 @@ tMCA_RESULT MCA_CloseReq(tMCA_DL mdl) * ******************************************************************************/ tMCA_RESULT MCA_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, - uint16_t mdl_id, const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_DCB *p_dcb; - - MCA_TRACE_API ("MCA_ReconnectMdl: %d ", mcl); - assert(p_chnl_cfg != NULL ); - if (p_ccb) - { - if (p_ccb->p_tx_req || p_ccb->p_rx_msg || p_ccb->cong) - { - MCA_TRACE_ERROR ("pending req"); - return MCA_BUSY; - } + uint16_t mdl_id, const tMCA_CHNL_CFG* p_chnl_cfg) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_DCB* p_dcb; + + MCA_TRACE_API("MCA_ReconnectMdl: %d ", mcl); + assert(p_chnl_cfg != NULL); + if (p_ccb) { + if (p_ccb->p_tx_req || p_ccb->p_rx_msg || p_ccb->cong) { + MCA_TRACE_ERROR("pending req"); + return MCA_BUSY; + } - if (!MCA_IS_VALID_MDL_ID(mdl_id)) - { - MCA_TRACE_ERROR ("bad mdl id: %d ", mdl_id); - return MCA_BAD_PARAMS; - } + if (!MCA_IS_VALID_MDL_ID(mdl_id)) { + MCA_TRACE_ERROR("bad mdl id: %d ", mdl_id); + return MCA_BAD_PARAMS; + } - if (mca_ccb_uses_mdl_id(p_ccb, mdl_id)) - { - MCA_TRACE_ERROR ("mdl id: %d is used in the control link", mdl_id); - return MCA_BAD_MDL_ID; - } + if (mca_ccb_uses_mdl_id(p_ccb, mdl_id)) { + MCA_TRACE_ERROR("mdl id: %d is used in the control link", mdl_id); + return MCA_BAD_MDL_ID; + } - p_dcb = mca_dcb_alloc(p_ccb, dep); - result = MCA_NO_RESOURCES; - if (p_dcb) { - tMCA_CCB_MSG *p_evt_data = - (tMCA_CCB_MSG *)osi_malloc(sizeof(tMCA_CCB_MSG)); - - p_dcb->p_chnl_cfg = p_chnl_cfg; - p_dcb->mdl_id = mdl_id; - if (!p_ccb->data_vpsm) - p_ccb->data_vpsm = L2CA_Register (data_psm, (tL2CAP_APPL_INFO *)&mca_l2c_int_appl); - p_evt_data->dcb_idx = mca_dcb_to_hdl(p_dcb); - p_evt_data->mdl_id = mdl_id; - p_evt_data->op_code = MCA_OP_MDL_RECONNECT_REQ; - p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; - mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT *)p_evt_data); - return MCA_SUCCESS; - } + p_dcb = mca_dcb_alloc(p_ccb, dep); + result = MCA_NO_RESOURCES; + if (p_dcb) { + tMCA_CCB_MSG* p_evt_data = + (tMCA_CCB_MSG*)osi_malloc(sizeof(tMCA_CCB_MSG)); + + p_dcb->p_chnl_cfg = p_chnl_cfg; + p_dcb->mdl_id = mdl_id; + if (!p_ccb->data_vpsm) + p_ccb->data_vpsm = + L2CA_Register(data_psm, (tL2CAP_APPL_INFO*)&mca_l2c_int_appl); + p_evt_data->dcb_idx = mca_dcb_to_hdl(p_dcb); + p_evt_data->mdl_id = mdl_id; + p_evt_data->op_code = MCA_OP_MDL_RECONNECT_REQ; + p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; + mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT*)p_evt_data); + return MCA_SUCCESS; } - return result; + } + return result; } - /******************************************************************************* * * Function MCA_ReconnectMdlRsp @@ -660,61 +602,52 @@ tMCA_RESULT MCA_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, uint16_t data_psm, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, - uint16_t mdl_id, uint8_t rsp_code, - const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_CCB_MSG evt_data; - tMCA_DCB *p_dcb; - - MCA_TRACE_API ("MCA_ReconnectMdlRsp: %d ", mcl); - assert(p_chnl_cfg != NULL ); - if (p_ccb) - { - if (p_ccb->cong) - { - MCA_TRACE_ERROR ("congested"); - return MCA_BUSY; - } - if (p_ccb->p_rx_msg && (p_ccb->p_rx_msg->mdl_id == mdl_id) && - (p_ccb->p_rx_msg->op_code == MCA_OP_MDL_RECONNECT_REQ)) - { - result = MCA_SUCCESS; - evt_data.dcb_idx = 0; - if (rsp_code == MCA_RSP_SUCCESS) - { - p_dcb = mca_dcb_alloc(p_ccb, dep); - if (p_dcb) - { - evt_data.dcb_idx = mca_dcb_to_hdl(p_dcb); - p_dcb->p_chnl_cfg = p_chnl_cfg; - p_dcb->mdl_id = mdl_id; - } - else - { - MCA_TRACE_ERROR ("Out of MDL for this MDEP"); - rsp_code = MCA_RSP_MDEP_BUSY; - result = MCA_NO_RESOURCES; - } - } - - evt_data.mdl_id = mdl_id; - evt_data.rsp_code = rsp_code; - evt_data.op_code = MCA_OP_MDL_RECONNECT_RSP; - mca_ccb_event(p_ccb, MCA_CCB_API_RSP_EVT, (tMCA_CCB_EVT *)&evt_data); - } - else - { - MCA_TRACE_ERROR ("The given MCL is not expecting a MCA_ReconnectMdlRsp with the given parameters" ); - result = MCA_BAD_PARAMS; +tMCA_RESULT MCA_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, uint16_t mdl_id, + uint8_t rsp_code, + const tMCA_CHNL_CFG* p_chnl_cfg) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_CCB_MSG evt_data; + tMCA_DCB* p_dcb; + + MCA_TRACE_API("MCA_ReconnectMdlRsp: %d ", mcl); + assert(p_chnl_cfg != NULL); + if (p_ccb) { + if (p_ccb->cong) { + MCA_TRACE_ERROR("congested"); + return MCA_BUSY; + } + if (p_ccb->p_rx_msg && (p_ccb->p_rx_msg->mdl_id == mdl_id) && + (p_ccb->p_rx_msg->op_code == MCA_OP_MDL_RECONNECT_REQ)) { + result = MCA_SUCCESS; + evt_data.dcb_idx = 0; + if (rsp_code == MCA_RSP_SUCCESS) { + p_dcb = mca_dcb_alloc(p_ccb, dep); + if (p_dcb) { + evt_data.dcb_idx = mca_dcb_to_hdl(p_dcb); + p_dcb->p_chnl_cfg = p_chnl_cfg; + p_dcb->mdl_id = mdl_id; + } else { + MCA_TRACE_ERROR("Out of MDL for this MDEP"); + rsp_code = MCA_RSP_MDEP_BUSY; + result = MCA_NO_RESOURCES; } + } + + evt_data.mdl_id = mdl_id; + evt_data.rsp_code = rsp_code; + evt_data.op_code = MCA_OP_MDL_RECONNECT_RSP; + mca_ccb_event(p_ccb, MCA_CCB_API_RSP_EVT, (tMCA_CCB_EVT*)&evt_data); + } else { + MCA_TRACE_ERROR( + "The given MCL is not expecting a MCA_ReconnectMdlRsp with the given " + "parameters"); + result = MCA_BAD_PARAMS; } - return result; + } + return result; } - /******************************************************************************* * * Function MCA_DataChnlCfg @@ -728,43 +661,40 @@ tMCA_RESULT MCA_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_DataChnlCfg(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_DCB *p_dcb; - tMCA_TC_TBL *p_tbl; - - MCA_TRACE_API ("MCA_DataChnlCfg: %d ", mcl); - assert(p_chnl_cfg != NULL ); - if (p_ccb) - { - result = MCA_NO_RESOURCES; - if ((p_ccb->p_tx_req == NULL) || (p_ccb->status != MCA_CCB_STAT_PENDING) || - ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) == NULL)) - { - MCA_TRACE_ERROR ("The given MCL is not expecting this API:%d", p_ccb->status); - return result; - } +tMCA_RESULT MCA_DataChnlCfg(tMCA_CL mcl, const tMCA_CHNL_CFG* p_chnl_cfg) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_DCB* p_dcb; + tMCA_TC_TBL* p_tbl; + + MCA_TRACE_API("MCA_DataChnlCfg: %d ", mcl); + assert(p_chnl_cfg != NULL); + if (p_ccb) { + result = MCA_NO_RESOURCES; + if ((p_ccb->p_tx_req == NULL) || (p_ccb->status != MCA_CCB_STAT_PENDING) || + ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) == NULL)) { + MCA_TRACE_ERROR("The given MCL is not expecting this API:%d", + p_ccb->status); + return result; + } - p_dcb->p_chnl_cfg = p_chnl_cfg; - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_DATA, p_ccb->sec_mask, - p_ccb->data_vpsm, BTM_SEC_PROTO_MCA, p_ccb->p_tx_req->dcb_idx); - p_dcb->lcid = mca_l2c_open_req(p_ccb->peer_addr, p_ccb->data_vpsm, p_dcb->p_chnl_cfg); - if (p_dcb->lcid) - { - p_tbl = mca_tc_tbl_dalloc(p_dcb); - if (p_tbl) - { - p_tbl->state = MCA_TC_ST_CONN; - result = MCA_SUCCESS; - } - } + p_dcb->p_chnl_cfg = p_chnl_cfg; + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_DATA, p_ccb->sec_mask, + p_ccb->data_vpsm, BTM_SEC_PROTO_MCA, + p_ccb->p_tx_req->dcb_idx); + p_dcb->lcid = + mca_l2c_open_req(p_ccb->peer_addr, p_ccb->data_vpsm, p_dcb->p_chnl_cfg); + if (p_dcb->lcid) { + p_tbl = mca_tc_tbl_dalloc(p_dcb); + if (p_tbl) { + p_tbl->state = MCA_TC_ST_CONN; + result = MCA_SUCCESS; + } } - return result; + } + return result; } - /******************************************************************************* * * Function MCA_Abort @@ -776,40 +706,36 @@ tMCA_RESULT MCA_DataChnlCfg(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg) * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_Abort(tMCA_CL mcl) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - tMCA_DCB *p_dcb; - - MCA_TRACE_API ("MCA_Abort: %d", mcl); - if (p_ccb) - { - result = MCA_NO_RESOURCES; - /* verify that we are waiting for data channel to come up with the given mdl */ - if ((p_ccb->p_tx_req == NULL) || (p_ccb->status != MCA_CCB_STAT_PENDING) || - ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) == NULL)) - { - MCA_TRACE_ERROR ("The given MCL is not expecting this API:%d", p_ccb->status); - return result; - } - - if (p_ccb->cong) - { - MCA_TRACE_ERROR ("congested"); - return MCA_BUSY; - } +tMCA_RESULT MCA_Abort(tMCA_CL mcl) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + tMCA_DCB* p_dcb; + + MCA_TRACE_API("MCA_Abort: %d", mcl); + if (p_ccb) { + result = MCA_NO_RESOURCES; + /* verify that we are waiting for data channel to come up with the given mdl + */ + if ((p_ccb->p_tx_req == NULL) || (p_ccb->status != MCA_CCB_STAT_PENDING) || + ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) == NULL)) { + MCA_TRACE_ERROR("The given MCL is not expecting this API:%d", + p_ccb->status); + return result; + } - tMCA_CCB_MSG *p_evt_data = - (tMCA_CCB_MSG *)osi_malloc(sizeof(tMCA_CCB_MSG)); - result = MCA_SUCCESS; - p_evt_data->op_code = MCA_OP_MDL_ABORT_REQ; - p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; - mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT *)p_evt_data); + if (p_ccb->cong) { + MCA_TRACE_ERROR("congested"); + return MCA_BUSY; } - return result; -} + tMCA_CCB_MSG* p_evt_data = (tMCA_CCB_MSG*)osi_malloc(sizeof(tMCA_CCB_MSG)); + result = MCA_SUCCESS; + p_evt_data->op_code = MCA_OP_MDL_ABORT_REQ; + p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; + mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT*)p_evt_data); + } + return result; +} /******************************************************************************* * @@ -822,33 +748,29 @@ tMCA_RESULT MCA_Abort(tMCA_CL mcl) * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_Delete(tMCA_CL mcl, uint16_t mdl_id) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_CCB *p_ccb = mca_ccb_by_hdl(mcl); - - MCA_TRACE_API ("MCA_Delete: %d ", mcl); - if (p_ccb) - { - if (p_ccb->cong) - { - MCA_TRACE_ERROR ("congested"); - return MCA_BUSY; - } - if (!MCA_IS_VALID_MDL_ID(mdl_id) && (mdl_id != MCA_ALL_MDL_ID)) - { - MCA_TRACE_ERROR ("bad mdl id: %d ", mdl_id); - return MCA_BAD_PARAMS; - } - - tMCA_CCB_MSG *p_evt_data = (tMCA_CCB_MSG *)osi_malloc(sizeof(tMCA_CCB_MSG)); - result = MCA_SUCCESS; - p_evt_data->mdl_id = mdl_id; - p_evt_data->op_code = MCA_OP_MDL_DELETE_REQ; - p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; - mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT *)p_evt_data); +tMCA_RESULT MCA_Delete(tMCA_CL mcl, uint16_t mdl_id) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_CCB* p_ccb = mca_ccb_by_hdl(mcl); + + MCA_TRACE_API("MCA_Delete: %d ", mcl); + if (p_ccb) { + if (p_ccb->cong) { + MCA_TRACE_ERROR("congested"); + return MCA_BUSY; } - return result; + if (!MCA_IS_VALID_MDL_ID(mdl_id) && (mdl_id != MCA_ALL_MDL_ID)) { + MCA_TRACE_ERROR("bad mdl id: %d ", mdl_id); + return MCA_BAD_PARAMS; + } + + tMCA_CCB_MSG* p_evt_data = (tMCA_CCB_MSG*)osi_malloc(sizeof(tMCA_CCB_MSG)); + result = MCA_SUCCESS; + p_evt_data->mdl_id = mdl_id; + p_evt_data->op_code = MCA_OP_MDL_DELETE_REQ; + p_evt_data->hdr.event = MCA_CCB_API_REQ_EVT; + mca_ccb_event(p_ccb, MCA_CCB_API_REQ_EVT, (tMCA_CCB_EVT*)p_evt_data); + } + return result; } /******************************************************************************* @@ -870,27 +792,22 @@ tMCA_RESULT MCA_Delete(tMCA_CL mcl, uint16_t mdl_id) * Returns MCA_SUCCESS if successful, otherwise error. * ******************************************************************************/ -tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR *p_pkt) -{ - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_DCB *p_dcb = mca_dcb_by_hdl(mdl); - tMCA_DCB_EVT evt_data; - - MCA_TRACE_API ("MCA_WriteReq: %d ", mdl); - if (p_dcb) - { - if (p_dcb->cong) - { - result = MCA_BUSY; - } - else - { - evt_data.p_pkt = p_pkt; - result = MCA_SUCCESS; - mca_dcb_event(p_dcb, MCA_DCB_API_WRITE_EVT, &evt_data); - } +tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR* p_pkt) { + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_DCB* p_dcb = mca_dcb_by_hdl(mdl); + tMCA_DCB_EVT evt_data; + + MCA_TRACE_API("MCA_WriteReq: %d ", mdl); + if (p_dcb) { + if (p_dcb->cong) { + result = MCA_BUSY; + } else { + evt_data.p_pkt = p_pkt; + result = MCA_SUCCESS; + mca_dcb_event(p_dcb, MCA_DCB_API_WRITE_EVT, &evt_data); } - return result; + } + return result; } /******************************************************************************* @@ -902,14 +819,11 @@ tMCA_RESULT MCA_WriteReq(tMCA_DL mdl, BT_HDR *p_pkt) * Returns L2CAP channel ID if successful, otherwise 0. * ******************************************************************************/ -uint16_t MCA_GetL2CapChannel (tMCA_DL mdl) -{ - uint16_t lcid = 0; - tMCA_DCB *p_dcb = mca_dcb_by_hdl(mdl); - - MCA_TRACE_API ("MCA_GetL2CapChannel: %d ", mdl); - if (p_dcb) - lcid = p_dcb->lcid; - return lcid; -} +uint16_t MCA_GetL2CapChannel(tMCA_DL mdl) { + uint16_t lcid = 0; + tMCA_DCB* p_dcb = mca_dcb_by_hdl(mdl); + MCA_TRACE_API("MCA_GetL2CapChannel: %d ", mdl); + if (p_dcb) lcid = p_dcb->lcid; + return lcid; +} diff --git a/stack/mcap/mca_cact.cc b/stack/mcap/mca_cact.cc index 0df370e5e..2540554a2 100644 --- a/stack/mcap/mca_cact.cc +++ b/stack/mcap/mca_cact.cc @@ -23,19 +23,18 @@ * ******************************************************************************/ #include +#include "bt_common.h" #include "bt_target.h" #include "bt_utils.h" -#include "bt_common.h" #include "btm_api.h" #include "mca_api.h" #include "mca_defs.h" #include "mca_int.h" #include "osi/include/osi.h" +#include "btu.h" -#include "btu.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /***************************************************************************** * constants @@ -49,12 +48,10 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns void. * ******************************************************************************/ -void mca_ccb_rsp_tout(tMCA_CCB *p_ccb, - UNUSED_ATTR tMCA_CCB_EVT *p_data) -{ - tMCA_CTRL evt_data; +void mca_ccb_rsp_tout(tMCA_CCB* p_ccb, UNUSED_ATTR tMCA_CCB_EVT* p_data) { + tMCA_CTRL evt_data; - mca_ccb_report_event(p_ccb, MCA_RSP_TOUT_IND_EVT, &evt_data); + mca_ccb_report_event(p_ccb, MCA_RSP_TOUT_IND_EVT, &evt_data); } /******************************************************************************* @@ -66,10 +63,10 @@ void mca_ccb_rsp_tout(tMCA_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void mca_ccb_report_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CTRL *p_data) -{ - if (p_ccb && p_ccb->p_rcb && p_ccb->p_rcb->p_cback) - (*p_ccb->p_rcb->p_cback)(mca_rcb_to_handle(p_ccb->p_rcb), mca_ccb_to_hdl(p_ccb), event, p_data); +void mca_ccb_report_event(tMCA_CCB* p_ccb, uint8_t event, tMCA_CTRL* p_data) { + if (p_ccb && p_ccb->p_rcb && p_ccb->p_rcb->p_cback) + (*p_ccb->p_rcb->p_cback)(mca_rcb_to_handle(p_ccb->p_rcb), + mca_ccb_to_hdl(p_ccb), event, p_data); } /******************************************************************************* @@ -81,9 +78,8 @@ void mca_ccb_report_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CTRL *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_free_msg(UNUSED_ATTR tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - osi_free(p_data); +void mca_ccb_free_msg(UNUSED_ATTR tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + osi_free(p_data); } /******************************************************************************* @@ -95,58 +91,54 @@ void mca_ccb_free_msg(UNUSED_ATTR tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_snd_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - tMCA_CCB_MSG *p_msg = (tMCA_CCB_MSG *)p_data; - uint8_t *p, *p_start; - bool is_abort = false; - tMCA_DCB *p_dcb; - - MCA_TRACE_DEBUG ("mca_ccb_snd_req cong=%d req=%d", p_ccb->cong, p_msg->op_code); - /* check for abort request */ - if ((p_ccb->status == MCA_CCB_STAT_PENDING) && (p_msg->op_code == MCA_OP_MDL_ABORT_REQ)) - { - p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx); - /* the Abort API does not have the associated mdl_id. - * Get the mdl_id in dcb to compose the request */ - p_msg->mdl_id = p_dcb->mdl_id; - mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); - osi_free_and_reset((void **)&p_ccb->p_tx_req); - p_ccb->status = MCA_CCB_STAT_NORM; - is_abort = true; - } - - /* no pending outgoing messages or it's an abort request for a pending data channel */ - if ((!p_ccb->p_tx_req) || is_abort) - { - p_ccb->p_tx_req = p_msg; - if (!p_ccb->cong) - { - BT_HDR *p_pkt = (BT_HDR *)osi_malloc(MCA_CTRL_MTU); - - p_pkt->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t*)(p_pkt + 1) + L2CAP_MIN_OFFSET; - *p++ = p_msg->op_code; - UINT16_TO_BE_STREAM (p, p_msg->mdl_id); - if (p_msg->op_code == MCA_OP_MDL_CREATE_REQ) { - *p++ = p_msg->mdep_id; - *p++ = p_msg->param; - } - p_msg->hdr.layer_specific = true; /* mark this message as sent */ - p_pkt->len = p - p_start; - L2CA_DataWrite (p_ccb->lcid, p_pkt); - period_ms_t interval_ms = p_ccb->p_rcb->reg.rsp_tout * 1000; - alarm_set_on_queue(p_ccb->mca_ccb_timer, interval_ms, - mca_ccb_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - /* else the L2CAP channel is congested. keep the message to be sent later */ - } - else - { - MCA_TRACE_WARNING ("dropping api req"); - osi_free(p_data); +void mca_ccb_snd_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + tMCA_CCB_MSG* p_msg = (tMCA_CCB_MSG*)p_data; + uint8_t *p, *p_start; + bool is_abort = false; + tMCA_DCB* p_dcb; + + MCA_TRACE_DEBUG("mca_ccb_snd_req cong=%d req=%d", p_ccb->cong, + p_msg->op_code); + /* check for abort request */ + if ((p_ccb->status == MCA_CCB_STAT_PENDING) && + (p_msg->op_code == MCA_OP_MDL_ABORT_REQ)) { + p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx); + /* the Abort API does not have the associated mdl_id. + * Get the mdl_id in dcb to compose the request */ + p_msg->mdl_id = p_dcb->mdl_id; + mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); + osi_free_and_reset((void**)&p_ccb->p_tx_req); + p_ccb->status = MCA_CCB_STAT_NORM; + is_abort = true; + } + + /* no pending outgoing messages or it's an abort request for a pending data + * channel */ + if ((!p_ccb->p_tx_req) || is_abort) { + p_ccb->p_tx_req = p_msg; + if (!p_ccb->cong) { + BT_HDR* p_pkt = (BT_HDR*)osi_malloc(MCA_CTRL_MTU); + + p_pkt->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_pkt + 1) + L2CAP_MIN_OFFSET; + *p++ = p_msg->op_code; + UINT16_TO_BE_STREAM(p, p_msg->mdl_id); + if (p_msg->op_code == MCA_OP_MDL_CREATE_REQ) { + *p++ = p_msg->mdep_id; + *p++ = p_msg->param; + } + p_msg->hdr.layer_specific = true; /* mark this message as sent */ + p_pkt->len = p - p_start; + L2CA_DataWrite(p_ccb->lcid, p_pkt); + period_ms_t interval_ms = p_ccb->p_rcb->reg.rsp_tout * 1000; + alarm_set_on_queue(p_ccb->mca_ccb_timer, interval_ms, + mca_ccb_timer_timeout, p_ccb, btu_general_alarm_queue); } + /* else the L2CAP channel is congested. keep the message to be sent later */ + } else { + MCA_TRACE_WARNING("dropping api req"); + osi_free(p_data); + } } /******************************************************************************* @@ -159,45 +151,42 @@ void mca_ccb_snd_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_snd_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - tMCA_CCB_MSG *p_msg = (tMCA_CCB_MSG *)p_data; - uint8_t *p, *p_start; - bool chk_mdl = false; - BT_HDR *p_pkt = (BT_HDR *)osi_malloc(MCA_CTRL_MTU); - - MCA_TRACE_DEBUG("%s cong=%d req=%d", __func__, p_ccb->cong, p_msg->op_code); - /* assume that API functions verified the parameters */ - - p_pkt->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t*)(p_pkt + 1) + L2CAP_MIN_OFFSET; - *p++ = p_msg->op_code; - *p++ = p_msg->rsp_code; - UINT16_TO_BE_STREAM (p, p_msg->mdl_id); - if (p_msg->op_code == MCA_OP_MDL_CREATE_RSP) { - *p++ = p_msg->param; - chk_mdl = true; - } - else if (p_msg->op_code == MCA_OP_MDL_RECONNECT_RSP) { - chk_mdl = true; - } - - if (chk_mdl && p_msg->rsp_code == MCA_RSP_SUCCESS) { - mca_dcb_by_hdl(p_msg->dcb_idx); - BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, - p_ccb->sec_mask, - p_ccb->p_rcb->reg.data_psm, BTM_SEC_PROTO_MCA, - p_msg->dcb_idx); - p_ccb->status = MCA_CCB_STAT_PENDING; - /* set p_tx_req to block API_REQ/API_RSP before DL is up */ - osi_free_and_reset((void **)&p_ccb->p_tx_req); - p_ccb->p_tx_req = p_ccb->p_rx_msg; - p_ccb->p_rx_msg = NULL; - p_ccb->p_tx_req->dcb_idx = p_msg->dcb_idx; - } - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - p_pkt->len = p - p_start; - L2CA_DataWrite(p_ccb->lcid, p_pkt); +void mca_ccb_snd_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + tMCA_CCB_MSG* p_msg = (tMCA_CCB_MSG*)p_data; + uint8_t *p, *p_start; + bool chk_mdl = false; + BT_HDR* p_pkt = (BT_HDR*)osi_malloc(MCA_CTRL_MTU); + + MCA_TRACE_DEBUG("%s cong=%d req=%d", __func__, p_ccb->cong, p_msg->op_code); + /* assume that API functions verified the parameters */ + + p_pkt->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_pkt + 1) + L2CAP_MIN_OFFSET; + *p++ = p_msg->op_code; + *p++ = p_msg->rsp_code; + UINT16_TO_BE_STREAM(p, p_msg->mdl_id); + if (p_msg->op_code == MCA_OP_MDL_CREATE_RSP) { + *p++ = p_msg->param; + chk_mdl = true; + } else if (p_msg->op_code == MCA_OP_MDL_RECONNECT_RSP) { + chk_mdl = true; + } + + if (chk_mdl && p_msg->rsp_code == MCA_RSP_SUCCESS) { + mca_dcb_by_hdl(p_msg->dcb_idx); + BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_MCAP_DATA, p_ccb->sec_mask, + p_ccb->p_rcb->reg.data_psm, BTM_SEC_PROTO_MCA, + p_msg->dcb_idx); + p_ccb->status = MCA_CCB_STAT_PENDING; + /* set p_tx_req to block API_REQ/API_RSP before DL is up */ + osi_free_and_reset((void**)&p_ccb->p_tx_req); + p_ccb->p_tx_req = p_ccb->p_rx_msg; + p_ccb->p_rx_msg = NULL; + p_ccb->p_tx_req->dcb_idx = p_msg->dcb_idx; + } + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + p_pkt->len = p - p_start; + L2CA_DataWrite(p_ccb->lcid, p_pkt); } /******************************************************************************* @@ -209,11 +198,9 @@ void mca_ccb_snd_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_do_disconn (tMCA_CCB *p_ccb, - UNUSED_ATTR tMCA_CCB_EVT *p_data) -{ - mca_dcb_close_by_mdl_id (p_ccb, MCA_ALL_MDL_ID); - L2CA_DisconnectReq(p_ccb->lcid); +void mca_ccb_do_disconn(tMCA_CCB* p_ccb, UNUSED_ATTR tMCA_CCB_EVT* p_data) { + mca_dcb_close_by_mdl_id(p_ccb, MCA_ALL_MDL_ID); + L2CA_DisconnectReq(p_ccb->lcid); } /******************************************************************************* @@ -225,20 +212,17 @@ void mca_ccb_do_disconn (tMCA_CCB *p_ccb, * Returns void. * ******************************************************************************/ -void mca_ccb_cong(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - MCA_TRACE_DEBUG ("mca_ccb_cong cong=%d/%d", p_ccb->cong, p_data->llcong); - p_ccb->cong = p_data->llcong; - if (!p_ccb->cong) - { - /* if there's a held packet, send it now */ - if (p_ccb->p_tx_req && !p_ccb->p_tx_req->hdr.layer_specific) - { - p_data = (tMCA_CCB_EVT *)p_ccb->p_tx_req; - p_ccb->p_tx_req = NULL; - mca_ccb_snd_req (p_ccb, p_data); - } +void mca_ccb_cong(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + MCA_TRACE_DEBUG("mca_ccb_cong cong=%d/%d", p_ccb->cong, p_data->llcong); + p_ccb->cong = p_data->llcong; + if (!p_ccb->cong) { + /* if there's a held packet, send it now */ + if (p_ccb->p_tx_req && !p_ccb->p_tx_req->hdr.layer_specific) { + p_data = (tMCA_CCB_EVT*)p_ccb->p_tx_req; + p_ccb->p_tx_req = NULL; + mca_ccb_snd_req(p_ccb, p_data); } + } } /******************************************************************************* @@ -252,189 +236,163 @@ void mca_ccb_cong(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_hdl_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - BT_HDR *p_pkt = &p_data->hdr; - uint8_t *p, *p_start; - tMCA_DCB *p_dcb; - tMCA_CTRL evt_data; - tMCA_CCB_MSG *p_rx_msg = NULL; - uint8_t reject_code = MCA_RSP_NO_RESOURCE; - bool send_rsp = false; - bool check_req = false; - uint8_t reject_opcode; - - MCA_TRACE_DEBUG ("mca_ccb_hdl_req status:%d", p_ccb->status); - p_rx_msg = (tMCA_CCB_MSG *)p_pkt; - p = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - evt_data.hdr.op_code = *p++; - BE_STREAM_TO_UINT16 (evt_data.hdr.mdl_id, p); - reject_opcode = evt_data.hdr.op_code+1; - - MCA_TRACE_DEBUG ("received mdl id: %d ", evt_data.hdr.mdl_id); - if (p_ccb->status == MCA_CCB_STAT_PENDING) - { - MCA_TRACE_DEBUG ("received req inpending state"); - /* allow abort in pending state */ - if ((p_ccb->status == MCA_CCB_STAT_PENDING) && (evt_data.hdr.op_code == MCA_OP_MDL_ABORT_REQ)) - { - reject_code = MCA_RSP_SUCCESS; - send_rsp = true; - /* clear the pending status */ - p_ccb->status = MCA_CCB_STAT_NORM; - if (p_ccb->p_tx_req && ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx))!= NULL)) - { - mca_dcb_dealloc(p_dcb, NULL); - osi_free_and_reset((void **)&p_ccb->p_tx_req); - } - } - else - reject_code = MCA_RSP_BAD_OP; +void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + BT_HDR* p_pkt = &p_data->hdr; + uint8_t *p, *p_start; + tMCA_DCB* p_dcb; + tMCA_CTRL evt_data; + tMCA_CCB_MSG* p_rx_msg = NULL; + uint8_t reject_code = MCA_RSP_NO_RESOURCE; + bool send_rsp = false; + bool check_req = false; + uint8_t reject_opcode; + + MCA_TRACE_DEBUG("mca_ccb_hdl_req status:%d", p_ccb->status); + p_rx_msg = (tMCA_CCB_MSG*)p_pkt; + p = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + evt_data.hdr.op_code = *p++; + BE_STREAM_TO_UINT16(evt_data.hdr.mdl_id, p); + reject_opcode = evt_data.hdr.op_code + 1; + + MCA_TRACE_DEBUG("received mdl id: %d ", evt_data.hdr.mdl_id); + if (p_ccb->status == MCA_CCB_STAT_PENDING) { + MCA_TRACE_DEBUG("received req inpending state"); + /* allow abort in pending state */ + if ((p_ccb->status == MCA_CCB_STAT_PENDING) && + (evt_data.hdr.op_code == MCA_OP_MDL_ABORT_REQ)) { + reject_code = MCA_RSP_SUCCESS; + send_rsp = true; + /* clear the pending status */ + p_ccb->status = MCA_CCB_STAT_NORM; + if (p_ccb->p_tx_req && + ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) != NULL)) { + mca_dcb_dealloc(p_dcb, NULL); + osi_free_and_reset((void**)&p_ccb->p_tx_req); + } + } else + reject_code = MCA_RSP_BAD_OP; + } else if (p_ccb->p_rx_msg) { + MCA_TRACE_DEBUG("still handling prev req"); + /* still holding previous message, reject this new one ?? */ + + } else if (p_ccb->p_tx_req) { + MCA_TRACE_DEBUG("still waiting for a response ctrl_vpsm:0x%x", + p_ccb->ctrl_vpsm); + /* sent a request; waiting for response */ + if (p_ccb->ctrl_vpsm == 0) { + MCA_TRACE_DEBUG("local is ACP. accept the cmd from INT"); + /* local is acceptor, need to handle the request */ + check_req = true; + reject_code = MCA_RSP_SUCCESS; + /* drop the previous request */ + if ((p_ccb->p_tx_req->op_code == MCA_OP_MDL_CREATE_REQ) && + ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) != NULL)) { + mca_dcb_dealloc(p_dcb, NULL); + } + osi_free_and_reset((void**)&p_ccb->p_tx_req); + mca_stop_timer(p_ccb); + } else { + /* local is initiator, ignore the req */ + osi_free(p_pkt); + return; } - else if (p_ccb->p_rx_msg) - { - MCA_TRACE_DEBUG ("still handling prev req"); - /* still holding previous message, reject this new one ?? */ - + } else if (p_pkt->layer_specific != MCA_RSP_SUCCESS) { + reject_code = (uint8_t)p_pkt->layer_specific; + if (((evt_data.hdr.op_code >= MCA_NUM_STANDARD_OPCODE) && + (evt_data.hdr.op_code < MCA_FIRST_SYNC_OP)) || + (evt_data.hdr.op_code > MCA_LAST_SYNC_OP)) { + /* invalid op code */ + reject_opcode = MCA_OP_ERROR_RSP; + evt_data.hdr.mdl_id = 0; } - else if (p_ccb->p_tx_req) - { - MCA_TRACE_DEBUG ("still waiting for a response ctrl_vpsm:0x%x", p_ccb->ctrl_vpsm); - /* sent a request; waiting for response */ - if (p_ccb->ctrl_vpsm == 0) - { - MCA_TRACE_DEBUG ("local is ACP. accept the cmd from INT"); - /* local is acceptor, need to handle the request */ - check_req = true; - reject_code = MCA_RSP_SUCCESS; - /* drop the previous request */ - if ((p_ccb->p_tx_req->op_code == MCA_OP_MDL_CREATE_REQ) && - ((p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) != NULL)) - { - mca_dcb_dealloc(p_dcb, NULL); - } - osi_free_and_reset((void **)&p_ccb->p_tx_req); - mca_stop_timer(p_ccb); - } - else - { - /* local is initiator, ignore the req */ - osi_free(p_pkt); - return; - } - } - else if (p_pkt->layer_specific != MCA_RSP_SUCCESS) - { - - reject_code = (uint8_t)p_pkt->layer_specific; - if (((evt_data.hdr.op_code >= MCA_NUM_STANDARD_OPCODE) && - (evt_data.hdr.op_code < MCA_FIRST_SYNC_OP)) || - (evt_data.hdr.op_code > MCA_LAST_SYNC_OP)) - { - /* invalid op code */ - reject_opcode = MCA_OP_ERROR_RSP; - evt_data.hdr.mdl_id = 0; - } - } - else - { - check_req = true; + } else { + check_req = true; + reject_code = MCA_RSP_SUCCESS; + } + + if (check_req) { + if (reject_code == MCA_RSP_SUCCESS) { + reject_code = MCA_RSP_BAD_MDL; + if (MCA_IS_VALID_MDL_ID(evt_data.hdr.mdl_id) || + ((evt_data.hdr.mdl_id == MCA_ALL_MDL_ID) && + (evt_data.hdr.op_code == MCA_OP_MDL_DELETE_REQ))) { reject_code = MCA_RSP_SUCCESS; - } - - if (check_req) - { - if (reject_code == MCA_RSP_SUCCESS) - { - reject_code = MCA_RSP_BAD_MDL; - if (MCA_IS_VALID_MDL_ID(evt_data.hdr.mdl_id) || - ((evt_data.hdr.mdl_id == MCA_ALL_MDL_ID) && (evt_data.hdr.op_code == MCA_OP_MDL_DELETE_REQ))) - { - reject_code = MCA_RSP_SUCCESS; - /* mdl_id is valid according to the spec */ - switch (evt_data.hdr.op_code) - { - case MCA_OP_MDL_CREATE_REQ: - evt_data.create_ind.dep_id = *p++; - evt_data.create_ind.cfg = *p++; - p_rx_msg->mdep_id = evt_data.create_ind.dep_id; - if (!mca_is_valid_dep_id(p_ccb->p_rcb, p_rx_msg->mdep_id)) - { - MCA_TRACE_ERROR ("not a valid local mdep id"); - reject_code = MCA_RSP_BAD_MDEP; - } - else if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) - { - MCA_TRACE_DEBUG ("the mdl_id is currently used in the CL(create)"); - mca_dcb_close_by_mdl_id(p_ccb, evt_data.hdr.mdl_id); - } - else - { - /* check if this dep still have MDL available */ - if (mca_dep_free_mdl(p_ccb, evt_data.create_ind.dep_id) == 0) - { - MCA_TRACE_ERROR ("the mdep is currently using max_mdl"); - reject_code = MCA_RSP_MDEP_BUSY; - } - } - break; - - case MCA_OP_MDL_RECONNECT_REQ: - if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) - { - MCA_TRACE_ERROR ("the mdl_id is currently used in the CL(reconn)"); - reject_code = MCA_RSP_MDL_BUSY; - } - break; - - case MCA_OP_MDL_ABORT_REQ: - reject_code = MCA_RSP_BAD_OP; - break; - - case MCA_OP_MDL_DELETE_REQ: - /* delete the associated mdl */ - mca_dcb_close_by_mdl_id(p_ccb, evt_data.hdr.mdl_id); - send_rsp = true; - break; - } + /* mdl_id is valid according to the spec */ + switch (evt_data.hdr.op_code) { + case MCA_OP_MDL_CREATE_REQ: + evt_data.create_ind.dep_id = *p++; + evt_data.create_ind.cfg = *p++; + p_rx_msg->mdep_id = evt_data.create_ind.dep_id; + if (!mca_is_valid_dep_id(p_ccb->p_rcb, p_rx_msg->mdep_id)) { + MCA_TRACE_ERROR("not a valid local mdep id"); + reject_code = MCA_RSP_BAD_MDEP; + } else if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) { + MCA_TRACE_DEBUG("the mdl_id is currently used in the CL(create)"); + mca_dcb_close_by_mdl_id(p_ccb, evt_data.hdr.mdl_id); + } else { + /* check if this dep still have MDL available */ + if (mca_dep_free_mdl(p_ccb, evt_data.create_ind.dep_id) == 0) { + MCA_TRACE_ERROR("the mdep is currently using max_mdl"); + reject_code = MCA_RSP_MDEP_BUSY; + } } - } - } + break; - if (((reject_code != MCA_RSP_SUCCESS) && (evt_data.hdr.op_code != MCA_OP_SYNC_INFO_IND)) - || send_rsp) { - BT_HDR *p_buf = (BT_HDR *)osi_malloc(MCA_CTRL_MTU); - p_buf->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - *p++ = reject_opcode; - *p++ = reject_code; - UINT16_TO_BE_STREAM(p, evt_data.hdr.mdl_id); - /* - if (((*p_start) == MCA_OP_MDL_CREATE_RSP) && (reject_code == MCA_RSP_SUCCESS)) - { - *p++ = evt_data.create_ind.cfg; - } - */ + case MCA_OP_MDL_RECONNECT_REQ: + if (mca_ccb_uses_mdl_id(p_ccb, evt_data.hdr.mdl_id)) { + MCA_TRACE_ERROR("the mdl_id is currently used in the CL(reconn)"); + reject_code = MCA_RSP_MDL_BUSY; + } + break; - p_buf->len = p - p_start; - L2CA_DataWrite (p_ccb->lcid, p_buf); - } + case MCA_OP_MDL_ABORT_REQ: + reject_code = MCA_RSP_BAD_OP; + break; - if (reject_code == MCA_RSP_SUCCESS) - { - /* use the received GKI buffer to store information to double check response API */ - p_rx_msg->op_code = evt_data.hdr.op_code; - p_rx_msg->mdl_id = evt_data.hdr.mdl_id; - p_ccb->p_rx_msg = p_rx_msg; - if (send_rsp) - { - osi_free(p_pkt); - p_ccb->p_rx_msg = NULL; + case MCA_OP_MDL_DELETE_REQ: + /* delete the associated mdl */ + mca_dcb_close_by_mdl_id(p_ccb, evt_data.hdr.mdl_id); + send_rsp = true; + break; } - mca_ccb_report_event(p_ccb, evt_data.hdr.op_code, &evt_data); + } + } + } + + if (((reject_code != MCA_RSP_SUCCESS) && + (evt_data.hdr.op_code != MCA_OP_SYNC_INFO_IND)) || + send_rsp) { + BT_HDR* p_buf = (BT_HDR*)osi_malloc(MCA_CTRL_MTU); + p_buf->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + *p++ = reject_opcode; + *p++ = reject_code; + UINT16_TO_BE_STREAM(p, evt_data.hdr.mdl_id); + /* + if (((*p_start) == MCA_OP_MDL_CREATE_RSP) && (reject_code == + MCA_RSP_SUCCESS)) + { + *p++ = evt_data.create_ind.cfg; + } + */ + + p_buf->len = p - p_start; + L2CA_DataWrite(p_ccb->lcid, p_buf); + } + + if (reject_code == MCA_RSP_SUCCESS) { + /* use the received GKI buffer to store information to double check response + * API */ + p_rx_msg->op_code = evt_data.hdr.op_code; + p_rx_msg->mdl_id = evt_data.hdr.mdl_id; + p_ccb->p_rx_msg = p_rx_msg; + if (send_rsp) { + osi_free(p_pkt); + p_ccb->p_rx_msg = NULL; } - else - osi_free(p_pkt); + mca_ccb_report_event(p_ccb, evt_data.hdr.op_code, &evt_data); + } else + osi_free(p_pkt); } /******************************************************************************* @@ -448,95 +406,81 @@ void mca_ccb_hdl_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_hdl_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - BT_HDR *p_pkt = &p_data->hdr; - uint8_t *p; - tMCA_CTRL evt_data; - bool chk_mdl = false; - tMCA_DCB *p_dcb; - tMCA_RESULT result = MCA_BAD_HANDLE; - tMCA_TC_TBL *p_tbl; - - if (p_ccb->p_tx_req) - { - /* verify that the received response matches the sent request */ - p = (uint8_t *)(p_pkt + 1) + p_pkt->offset; - evt_data.hdr.op_code = *p++; - if ((evt_data.hdr.op_code == 0) || - ((p_ccb->p_tx_req->op_code + 1) == evt_data.hdr.op_code)) - { - evt_data.rsp.rsp_code = *p++; - mca_stop_timer(p_ccb); - BE_STREAM_TO_UINT16 (evt_data.hdr.mdl_id, p); - if (evt_data.hdr.op_code == MCA_OP_MDL_CREATE_RSP) - { - evt_data.create_cfm.cfg = *p++; - chk_mdl = true; +void mca_ccb_hdl_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + BT_HDR* p_pkt = &p_data->hdr; + uint8_t* p; + tMCA_CTRL evt_data; + bool chk_mdl = false; + tMCA_DCB* p_dcb; + tMCA_RESULT result = MCA_BAD_HANDLE; + tMCA_TC_TBL* p_tbl; + + if (p_ccb->p_tx_req) { + /* verify that the received response matches the sent request */ + p = (uint8_t*)(p_pkt + 1) + p_pkt->offset; + evt_data.hdr.op_code = *p++; + if ((evt_data.hdr.op_code == 0) || + ((p_ccb->p_tx_req->op_code + 1) == evt_data.hdr.op_code)) { + evt_data.rsp.rsp_code = *p++; + mca_stop_timer(p_ccb); + BE_STREAM_TO_UINT16(evt_data.hdr.mdl_id, p); + if (evt_data.hdr.op_code == MCA_OP_MDL_CREATE_RSP) { + evt_data.create_cfm.cfg = *p++; + chk_mdl = true; + } else if (evt_data.hdr.op_code == MCA_OP_MDL_RECONNECT_RSP) + chk_mdl = true; + + if (chk_mdl) { + p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx); + if (evt_data.rsp.rsp_code == MCA_RSP_SUCCESS) { + if (evt_data.hdr.mdl_id != p_dcb->mdl_id) { + MCA_TRACE_ERROR("peer's mdl_id=%d != our mdl_id=%d", + evt_data.hdr.mdl_id, p_dcb->mdl_id); + /* change the response code to be an error */ + if (evt_data.rsp.rsp_code == MCA_RSP_SUCCESS) { + evt_data.rsp.rsp_code = MCA_RSP_BAD_MDL; + /* send Abort */ + p_ccb->status = MCA_CCB_STAT_PENDING; + MCA_Abort(mca_ccb_to_hdl(p_ccb)); + } + } else if (p_dcb->p_chnl_cfg) { + /* the data channel configuration is known. Proceed with data + * channel initiation */ + BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_DATA, + p_ccb->sec_mask, p_ccb->data_vpsm, + BTM_SEC_PROTO_MCA, p_ccb->p_tx_req->dcb_idx); + p_dcb->lcid = mca_l2c_open_req(p_ccb->peer_addr, p_ccb->data_vpsm, + p_dcb->p_chnl_cfg); + if (p_dcb->lcid) { + p_tbl = mca_tc_tbl_dalloc(p_dcb); + if (p_tbl) { + p_tbl->state = MCA_TC_ST_CONN; + p_ccb->status = MCA_CCB_STAT_PENDING; + result = MCA_SUCCESS; + } } - else if (evt_data.hdr.op_code == MCA_OP_MDL_RECONNECT_RSP) - chk_mdl = true; - - if (chk_mdl) - { - p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx); - if (evt_data.rsp.rsp_code == MCA_RSP_SUCCESS) - { - if (evt_data.hdr.mdl_id != p_dcb->mdl_id) - { - MCA_TRACE_ERROR ("peer's mdl_id=%d != our mdl_id=%d", evt_data.hdr.mdl_id, p_dcb->mdl_id); - /* change the response code to be an error */ - if (evt_data.rsp.rsp_code == MCA_RSP_SUCCESS) - { - evt_data.rsp.rsp_code = MCA_RSP_BAD_MDL; - /* send Abort */ - p_ccb->status = MCA_CCB_STAT_PENDING; - MCA_Abort(mca_ccb_to_hdl(p_ccb)); - } - } - else if (p_dcb->p_chnl_cfg) - { - /* the data channel configuration is known. Proceed with data channel initiation */ - BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_MCAP_DATA, p_ccb->sec_mask, - p_ccb->data_vpsm, BTM_SEC_PROTO_MCA, p_ccb->p_tx_req->dcb_idx); - p_dcb->lcid = mca_l2c_open_req(p_ccb->peer_addr, p_ccb->data_vpsm, p_dcb->p_chnl_cfg); - if (p_dcb->lcid) - { - p_tbl = mca_tc_tbl_dalloc(p_dcb); - if (p_tbl) - { - p_tbl->state = MCA_TC_ST_CONN; - p_ccb->status = MCA_CCB_STAT_PENDING; - result = MCA_SUCCESS; - } - } - } - else - { - /* mark this MCL as pending and wait for MCA_DataChnlCfg */ - p_ccb->status = MCA_CCB_STAT_PENDING; - result = MCA_SUCCESS; - } - } - - if (result != MCA_SUCCESS && p_dcb) - { - mca_dcb_dealloc(p_dcb, NULL); - } - } /* end of chk_mdl */ - - if (p_ccb->status != MCA_CCB_STAT_PENDING) - osi_free_and_reset((void **)&p_ccb->p_tx_req); - mca_ccb_report_event(p_ccb, evt_data.hdr.op_code, &evt_data); + } else { + /* mark this MCL as pending and wait for MCA_DataChnlCfg */ + p_ccb->status = MCA_CCB_STAT_PENDING; + result = MCA_SUCCESS; + } } - /* else a bad response is received */ - } - else - { - /* not expecting any response. drop it */ - MCA_TRACE_WARNING ("dropping received rsp (not expecting a response)"); + + if (result != MCA_SUCCESS && p_dcb) { + mca_dcb_dealloc(p_dcb, NULL); + } + } /* end of chk_mdl */ + + if (p_ccb->status != MCA_CCB_STAT_PENDING) + osi_free_and_reset((void**)&p_ccb->p_tx_req); + mca_ccb_report_event(p_ccb, evt_data.hdr.op_code, &evt_data); } - osi_free(p_data); + /* else a bad response is received */ + } else { + /* not expecting any response. drop it */ + MCA_TRACE_WARNING("dropping received rsp (not expecting a response)"); + } + osi_free(p_data); } /******************************************************************************* @@ -549,13 +493,12 @@ void mca_ccb_hdl_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_ll_open (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - tMCA_CTRL evt_data; - p_ccb->cong = false; - evt_data.connect_ind.mtu = p_data->open.peer_mtu; - memcpy (evt_data.connect_ind.bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); - mca_ccb_report_event (p_ccb, MCA_CONNECT_IND_EVT, &evt_data); +void mca_ccb_ll_open(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + tMCA_CTRL evt_data; + p_ccb->cong = false; + evt_data.connect_ind.mtu = p_data->open.peer_mtu; + memcpy(evt_data.connect_ind.bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); + mca_ccb_report_event(p_ccb, MCA_CONNECT_IND_EVT, &evt_data); } /******************************************************************************* @@ -568,11 +511,8 @@ void mca_ccb_ll_open (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_ccb_dl_open (tMCA_CCB *p_ccb, - UNUSED_ATTR tMCA_CCB_EVT *p_data) -{ - osi_free_and_reset((void **)&p_ccb->p_tx_req); - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - p_ccb->status = MCA_CCB_STAT_NORM; +void mca_ccb_dl_open(tMCA_CCB* p_ccb, UNUSED_ATTR tMCA_CCB_EVT* p_data) { + osi_free_and_reset((void**)&p_ccb->p_tx_req); + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + p_ccb->status = MCA_CCB_STAT_NORM; } - diff --git a/stack/mcap/mca_csm.cc b/stack/mcap/mca_csm.cc index c879465f5..3c437f670 100644 --- a/stack/mcap/mca_csm.cc +++ b/stack/mcap/mca_csm.cc @@ -25,131 +25,103 @@ #include #include "bt_target.h" +#include "btu.h" #include "mca_api.h" #include "mca_defs.h" #include "mca_int.h" -#include "btu.h" /***************************************************************************** * data channel state machine constants and types ****************************************************************************/ -enum -{ - MCA_CCB_FREE_MSG, - MCA_CCB_SND_REQ, - MCA_CCB_SND_RSP, - MCA_CCB_DO_DISCONN, - MCA_CCB_CONG, - MCA_CCB_HDL_REQ, - MCA_CCB_HDL_RSP, - MCA_CCB_LL_OPEN, - MCA_CCB_DL_OPEN, - MCA_CCB_DEALLOC, - MCA_CCB_RSP_TOUT, - MCA_CCB_NUM_ACTIONS +enum { + MCA_CCB_FREE_MSG, + MCA_CCB_SND_REQ, + MCA_CCB_SND_RSP, + MCA_CCB_DO_DISCONN, + MCA_CCB_CONG, + MCA_CCB_HDL_REQ, + MCA_CCB_HDL_RSP, + MCA_CCB_LL_OPEN, + MCA_CCB_DL_OPEN, + MCA_CCB_DEALLOC, + MCA_CCB_RSP_TOUT, + MCA_CCB_NUM_ACTIONS }; -#define MCA_CCB_IGNORE MCA_CCB_NUM_ACTIONS +#define MCA_CCB_IGNORE MCA_CCB_NUM_ACTIONS /* action function list */ const tMCA_CCB_ACTION mca_ccb_action[] = { - mca_ccb_free_msg, - mca_ccb_snd_req, - mca_ccb_snd_rsp, - mca_ccb_do_disconn, - mca_ccb_cong, - mca_ccb_hdl_req, - mca_ccb_hdl_rsp, - mca_ccb_ll_open, - mca_ccb_dl_open, - mca_ccb_dealloc, - mca_ccb_rsp_tout, + mca_ccb_free_msg, mca_ccb_snd_req, mca_ccb_snd_rsp, mca_ccb_do_disconn, + mca_ccb_cong, mca_ccb_hdl_req, mca_ccb_hdl_rsp, mca_ccb_ll_open, + mca_ccb_dl_open, mca_ccb_dealloc, mca_ccb_rsp_tout, }; /* state table information */ -#define MCA_CCB_ACTIONS 1 /* number of actions */ -#define MCA_CCB_ACT_COL 0 /* position of action function */ -#define MCA_CCB_NEXT_STATE 1 /* position of next state */ -#define MCA_CCB_NUM_COLS 2 /* number of columns in state tables */ +#define MCA_CCB_ACTIONS 1 /* number of actions */ +#define MCA_CCB_ACT_COL 0 /* position of action function */ +#define MCA_CCB_NEXT_STATE 1 /* position of next state */ +#define MCA_CCB_NUM_COLS 2 /* number of columns in state tables */ /* state table for opening state */ const uint8_t mca_ccb_st_opening[][MCA_CCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, -/* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_DO_DISCONN, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_API_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, -/* MCA_CCB_API_RSP_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, -/* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, -/* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, -/* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, -/* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_LL_OPEN, MCA_CCB_OPEN_ST}, -/* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, -/* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_CONG, MCA_CCB_OPENING_ST}, -/* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST} -}; + /* Event Action Next State */ + /* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, + /* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_DO_DISCONN, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_API_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, + /* MCA_CCB_API_RSP_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, + /* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, + /* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_OPENING_ST}, + /* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}, + /* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_LL_OPEN, MCA_CCB_OPEN_ST}, + /* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, + /* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_CONG, MCA_CCB_OPENING_ST}, + /* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPENING_ST}}; /* state table for open state */ const uint8_t mca_ccb_st_open[][MCA_CCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPEN_ST}, -/* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_DO_DISCONN, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_API_REQ_EVT */ {MCA_CCB_SND_REQ, MCA_CCB_OPEN_ST}, -/* MCA_CCB_API_RSP_EVT */ {MCA_CCB_SND_RSP, MCA_CCB_OPEN_ST}, -/* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_HDL_REQ, MCA_CCB_OPEN_ST}, -/* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_HDL_RSP, MCA_CCB_OPEN_ST}, -/* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_DL_OPEN, MCA_CCB_OPEN_ST}, -/* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPEN_ST}, -/* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, -/* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_CONG, MCA_CCB_OPEN_ST}, -/* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_RSP_TOUT, MCA_CCB_OPEN_ST} -}; + /* Event Action Next State */ + /* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPEN_ST}, + /* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_DO_DISCONN, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_API_REQ_EVT */ {MCA_CCB_SND_REQ, MCA_CCB_OPEN_ST}, + /* MCA_CCB_API_RSP_EVT */ {MCA_CCB_SND_RSP, MCA_CCB_OPEN_ST}, + /* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_HDL_REQ, MCA_CCB_OPEN_ST}, + /* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_HDL_RSP, MCA_CCB_OPEN_ST}, + /* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_DL_OPEN, MCA_CCB_OPEN_ST}, + /* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_OPEN_ST}, + /* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, + /* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_CONG, MCA_CCB_OPEN_ST}, + /* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_RSP_TOUT, MCA_CCB_OPEN_ST}}; /* state table for closing state */ const uint8_t mca_ccb_st_closing[][MCA_CCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_API_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_API_RSP_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, -/* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, -/* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST} -}; + /* Event Action Next State */ + /* MCA_CCB_API_CONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_API_DISCONNECT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_API_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_API_RSP_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_MSG_REQ_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_MSG_RSP_EVT */ {MCA_CCB_FREE_MSG, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_DL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_LL_OPEN_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_LL_CLOSE_EVT */ {MCA_CCB_DEALLOC, MCA_CCB_NULL_ST}, + /* MCA_CCB_LL_CONG_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}, + /* MCA_CCB_RSP_TOUT_EVT */ {MCA_CCB_IGNORE, MCA_CCB_CLOSING_ST}}; /* type for state table */ typedef const uint8_t (*tMCA_CCB_ST_TBL)[MCA_CCB_NUM_COLS]; /* state table */ -const tMCA_CCB_ST_TBL mca_ccb_st_tbl[] = { - mca_ccb_st_opening, - mca_ccb_st_open, - mca_ccb_st_closing -}; +const tMCA_CCB_ST_TBL mca_ccb_st_tbl[] = {mca_ccb_st_opening, mca_ccb_st_open, + mca_ccb_st_closing}; /* verbose event strings for trace */ -static const char * const mca_ccb_evt_str[] = { - "API_CONNECT_EVT", - "API_DISCONNECT_EVT", - "API_REQ_EVT", - "API_RSP_EVT", - "MSG_REQ_EVT", - "MSG_RSP_EVT", - "DL_OPEN_EVT", - "LL_OPEN_EVT", - "LL_CLOSE_EVT", - "LL_CONG_EVT", - "RSP_TOUT_EVT" -}; +static const char* const mca_ccb_evt_str[] = { + "API_CONNECT_EVT", "API_DISCONNECT_EVT", "API_REQ_EVT", "API_RSP_EVT", + "MSG_REQ_EVT", "MSG_RSP_EVT", "DL_OPEN_EVT", "LL_OPEN_EVT", + "LL_CLOSE_EVT", "LL_CONG_EVT", "RSP_TOUT_EVT"}; /* verbose state strings for trace */ -static const char * const mca_ccb_st_str[] = { - "NULL_ST", - "OPENING_ST", - "OPEN_ST", - "CLOSING_ST" -}; +static const char* const mca_ccb_st_str[] = {"NULL_ST", "OPENING_ST", "OPEN_ST", + "CLOSING_ST"}; /******************************************************************************* * @@ -162,10 +134,7 @@ static const char * const mca_ccb_st_str[] = { * Returns void * ******************************************************************************/ -void mca_stop_timer(tMCA_CCB *p_ccb) -{ - alarm_cancel(p_ccb->mca_ccb_timer); -} +void mca_stop_timer(tMCA_CCB* p_ccb) { alarm_cancel(p_ccb->mca_ccb_timer); } /******************************************************************************* * @@ -178,25 +147,24 @@ void mca_stop_timer(tMCA_CCB *p_ccb) * Returns void. * ******************************************************************************/ -void mca_ccb_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CCB_EVT *p_data) -{ - tMCA_CCB_ST_TBL state_table; - uint8_t action; +void mca_ccb_event(tMCA_CCB* p_ccb, uint8_t event, tMCA_CCB_EVT* p_data) { + tMCA_CCB_ST_TBL state_table; + uint8_t action; - MCA_TRACE_EVENT("CCB ccb=%d event=%s state=%s", mca_ccb_to_hdl(p_ccb), mca_ccb_evt_str[event], mca_ccb_st_str[p_ccb->state]); + MCA_TRACE_EVENT("CCB ccb=%d event=%s state=%s", mca_ccb_to_hdl(p_ccb), + mca_ccb_evt_str[event], mca_ccb_st_str[p_ccb->state]); - /* look up the state table for the current state */ - state_table = mca_ccb_st_tbl[p_ccb->state - 1]; + /* look up the state table for the current state */ + state_table = mca_ccb_st_tbl[p_ccb->state - 1]; - /* set next state */ - p_ccb->state = state_table[event][MCA_CCB_NEXT_STATE]; + /* set next state */ + p_ccb->state = state_table[event][MCA_CCB_NEXT_STATE]; - /* execute action functions */ - action = state_table[event][MCA_CCB_ACT_COL]; - if (action != MCA_CCB_IGNORE) - { - (*mca_ccb_action[action])(p_ccb, p_data); - } + /* execute action functions */ + action = state_table[event][MCA_CCB_ACT_COL]; + if (action != MCA_CCB_IGNORE) { + (*mca_ccb_action[action])(p_ccb, p_data); + } } /******************************************************************************* @@ -210,27 +178,24 @@ void mca_ccb_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -tMCA_CCB *mca_ccb_by_bd(tMCA_HANDLE handle, BD_ADDR bd_addr) -{ - tMCA_CCB *p_ccb = NULL; - tMCA_RCB *p_rcb = mca_rcb_by_handle(handle); - tMCA_CCB *p_ccb_tmp; - int i; +tMCA_CCB* mca_ccb_by_bd(tMCA_HANDLE handle, BD_ADDR bd_addr) { + tMCA_CCB* p_ccb = NULL; + tMCA_RCB* p_rcb = mca_rcb_by_handle(handle); + tMCA_CCB* p_ccb_tmp; + int i; - if (p_rcb) - { - i = handle-1; - p_ccb_tmp = &mca_cb.ccb[i*MCA_NUM_LINKS]; - for (i=0; istate != MCA_CCB_NULL_ST && memcmp(p_ccb_tmp->peer_addr, bd_addr, BD_ADDR_LEN) == 0) - { - p_ccb = p_ccb_tmp; - break; - } - } + if (p_rcb) { + i = handle - 1; + p_ccb_tmp = &mca_cb.ccb[i * MCA_NUM_LINKS]; + for (i = 0; i < MCA_NUM_LINKS; i++, p_ccb_tmp++) { + if (p_ccb_tmp->state != MCA_CCB_NULL_ST && + memcmp(p_ccb_tmp->peer_addr, bd_addr, BD_ADDR_LEN) == 0) { + p_ccb = p_ccb_tmp; + break; + } } - return p_ccb; + } + return p_ccb; } /******************************************************************************* @@ -244,36 +209,31 @@ tMCA_CCB *mca_ccb_by_bd(tMCA_HANDLE handle, BD_ADDR bd_addr) * Returns void. * ******************************************************************************/ -tMCA_CCB *mca_ccb_alloc(tMCA_HANDLE handle, BD_ADDR bd_addr) -{ - tMCA_CCB *p_ccb = NULL; - tMCA_RCB *p_rcb = mca_rcb_by_handle(handle); - tMCA_CCB *p_ccb_tmp; - int i; +tMCA_CCB* mca_ccb_alloc(tMCA_HANDLE handle, BD_ADDR bd_addr) { + tMCA_CCB* p_ccb = NULL; + tMCA_RCB* p_rcb = mca_rcb_by_handle(handle); + tMCA_CCB* p_ccb_tmp; + int i; - MCA_TRACE_DEBUG("mca_ccb_alloc handle:0x%x", handle); - if (p_rcb) - { - i = handle-1; - p_ccb_tmp = &mca_cb.ccb[i*MCA_NUM_LINKS]; - for (i=0; istate == MCA_CCB_NULL_ST) - { - p_ccb_tmp->p_rcb = p_rcb; - p_ccb_tmp->mca_ccb_timer = alarm_new("mca.mca_ccb_timer"); - p_ccb_tmp->state = MCA_CCB_OPENING_ST; - p_ccb_tmp->cong = true; - memcpy(p_ccb_tmp->peer_addr, bd_addr, BD_ADDR_LEN); - p_ccb = p_ccb_tmp; - break; - } - } + MCA_TRACE_DEBUG("mca_ccb_alloc handle:0x%x", handle); + if (p_rcb) { + i = handle - 1; + p_ccb_tmp = &mca_cb.ccb[i * MCA_NUM_LINKS]; + for (i = 0; i < MCA_NUM_LINKS; i++, p_ccb_tmp++) { + if (p_ccb_tmp->state == MCA_CCB_NULL_ST) { + p_ccb_tmp->p_rcb = p_rcb; + p_ccb_tmp->mca_ccb_timer = alarm_new("mca.mca_ccb_timer"); + p_ccb_tmp->state = MCA_CCB_OPENING_ST; + p_ccb_tmp->cong = true; + memcpy(p_ccb_tmp->peer_addr, bd_addr, BD_ADDR_LEN); + p_ccb = p_ccb_tmp; + break; + } } - return p_ccb; + } + return p_ccb; } - /******************************************************************************* * * Function mca_ccb_dealloc @@ -283,34 +243,30 @@ tMCA_CCB *mca_ccb_alloc(tMCA_HANDLE handle, BD_ADDR bd_addr) * Returns void. * ******************************************************************************/ -void mca_ccb_dealloc(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) -{ - tMCA_CTRL evt_data; +void mca_ccb_dealloc(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data) { + tMCA_CTRL evt_data; - MCA_TRACE_DEBUG("mca_ccb_dealloc ctrl_vpsm:0x%x", p_ccb->ctrl_vpsm); - mca_dcb_close_by_mdl_id (p_ccb, MCA_ALL_MDL_ID); - if (p_ccb->ctrl_vpsm) - { - L2CA_Deregister (p_ccb->ctrl_vpsm); - } - if (p_ccb->data_vpsm) - { - L2CA_Deregister (p_ccb->data_vpsm); - } - osi_free_and_reset((void **)&p_ccb->p_rx_msg); - osi_free_and_reset((void **)&p_ccb->p_tx_req); - mca_stop_timer(p_ccb); + MCA_TRACE_DEBUG("mca_ccb_dealloc ctrl_vpsm:0x%x", p_ccb->ctrl_vpsm); + mca_dcb_close_by_mdl_id(p_ccb, MCA_ALL_MDL_ID); + if (p_ccb->ctrl_vpsm) { + L2CA_Deregister(p_ccb->ctrl_vpsm); + } + if (p_ccb->data_vpsm) { + L2CA_Deregister(p_ccb->data_vpsm); + } + osi_free_and_reset((void**)&p_ccb->p_rx_msg); + osi_free_and_reset((void**)&p_ccb->p_tx_req); + mca_stop_timer(p_ccb); - if (p_data) - { - /* non-NULL -> an action function -> report disconnect event */ - memcpy (evt_data.disconnect_ind.bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); - evt_data.disconnect_ind.reason = p_data->close.reason; - mca_ccb_report_event(p_ccb, MCA_DISCONNECT_IND_EVT, &evt_data); - } - mca_free_tc_tbl_by_lcid (p_ccb->lcid); - alarm_free(p_ccb->mca_ccb_timer); - memset(p_ccb, 0, sizeof(tMCA_CCB)); + if (p_data) { + /* non-NULL -> an action function -> report disconnect event */ + memcpy(evt_data.disconnect_ind.bd_addr, p_ccb->peer_addr, BD_ADDR_LEN); + evt_data.disconnect_ind.reason = p_data->close.reason; + mca_ccb_report_event(p_ccb, MCA_DISCONNECT_IND_EVT, &evt_data); + } + mca_free_tc_tbl_by_lcid(p_ccb->lcid); + alarm_free(p_ccb->mca_ccb_timer); + memset(p_ccb, 0, sizeof(tMCA_CCB)); } /******************************************************************************* @@ -323,9 +279,8 @@ void mca_ccb_dealloc(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data) * Returns void. * ******************************************************************************/ -tMCA_CL mca_ccb_to_hdl(tMCA_CCB *p_ccb) -{ - return (uint8_t) (p_ccb - mca_cb.ccb + 1); +tMCA_CL mca_ccb_to_hdl(tMCA_CCB* p_ccb) { + return (uint8_t)(p_ccb - mca_cb.ccb + 1); } /******************************************************************************* @@ -339,15 +294,13 @@ tMCA_CL mca_ccb_to_hdl(tMCA_CCB *p_ccb) * Returns void. * ******************************************************************************/ -tMCA_CCB *mca_ccb_by_hdl(tMCA_CL mcl) -{ - tMCA_CCB * p_ccb = NULL; - if (mcl && mcl <= MCA_NUM_CCBS && mca_cb.ccb[mcl-1].state) - p_ccb = &mca_cb.ccb[mcl-1]; - return p_ccb; +tMCA_CCB* mca_ccb_by_hdl(tMCA_CL mcl) { + tMCA_CCB* p_ccb = NULL; + if (mcl && mcl <= MCA_NUM_CCBS && mca_cb.ccb[mcl - 1].state) + p_ccb = &mca_cb.ccb[mcl - 1]; + return p_ccb; } - /******************************************************************************* * * Function mca_ccb_uses_mdl_id @@ -357,22 +310,19 @@ tMCA_CCB *mca_ccb_by_hdl(tMCA_CL mcl) * Returns true, if the given mdl_id is currently used in the MCL. * ******************************************************************************/ -bool mca_ccb_uses_mdl_id(tMCA_CCB *p_ccb, uint16_t mdl_id) -{ - bool uses = false; - tMCA_DCB *p_dcb; - int i; +bool mca_ccb_uses_mdl_id(tMCA_CCB* p_ccb, uint16_t mdl_id) { + bool uses = false; + tMCA_DCB* p_dcb; + int i; - i = mca_ccb_to_hdl(p_ccb)-1; - p_dcb = &mca_cb.dcb[i*MCA_NUM_MDLS]; - for (i=0; istate != MCA_DCB_NULL_ST && p_dcb->mdl_id == mdl_id) - { - uses = true; - break; - } + i = mca_ccb_to_hdl(p_ccb) - 1; + p_dcb = &mca_cb.dcb[i * MCA_NUM_MDLS]; + for (i = 0; i < MCA_NUM_MDLS; i++, p_dcb++) { + if (p_dcb->state != MCA_DCB_NULL_ST && p_dcb->mdl_id == mdl_id) { + uses = true; + break; } + } - return uses; + return uses; } diff --git a/stack/mcap/mca_dact.cc b/stack/mcap/mca_dact.cc index d93974b90..a99d47c38 100644 --- a/stack/mcap/mca_dact.cc +++ b/stack/mcap/mca_dact.cc @@ -24,9 +24,9 @@ ******************************************************************************/ #include +#include "bt_common.h" #include "bt_target.h" #include "bt_utils.h" -#include "bt_common.h" #include "mca_api.h" #include "mca_int.h" #include "osi/include/osi.h" @@ -40,14 +40,13 @@ * Returns void. * ******************************************************************************/ -void mca_dcb_report_cong (tMCA_DCB *p_dcb) -{ - tMCA_CTRL evt_data; +void mca_dcb_report_cong(tMCA_DCB* p_dcb) { + tMCA_CTRL evt_data; - evt_data.cong_chg.cong = p_dcb->cong; - evt_data.cong_chg.mdl = mca_dcb_to_hdl(p_dcb); - evt_data.cong_chg.mdl_id = p_dcb->mdl_id; - mca_ccb_report_event (p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data); + evt_data.cong_chg.cong = p_dcb->cong; + evt_data.cong_chg.mdl = mca_dcb_to_hdl(p_dcb); + evt_data.cong_chg.mdl_id = p_dcb->mdl_id; + mca_ccb_report_event(p_dcb->p_ccb, MCA_CONG_CHG_EVT, &evt_data); } /******************************************************************************* @@ -61,20 +60,18 @@ void mca_dcb_report_cong (tMCA_DCB *p_dcb) * Returns void. * ******************************************************************************/ -void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - tMCA_CTRL evt_data; - tMCA_CCB *p_ccb = p_dcb->p_ccb; - uint8_t event = MCA_OPEN_IND_EVT; +void mca_dcb_tc_open(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + tMCA_CTRL evt_data; + tMCA_CCB* p_ccb = p_dcb->p_ccb; + uint8_t event = MCA_OPEN_IND_EVT; - if (p_data->open.param == MCA_INT) - event = MCA_OPEN_CFM_EVT; - p_dcb->cong = false; - evt_data.open_cfm.mtu = p_data->open.peer_mtu; - evt_data.open_cfm.mdl_id = p_dcb->mdl_id; - evt_data.open_cfm.mdl = mca_dcb_to_hdl(p_dcb); - mca_ccb_event (p_ccb, MCA_CCB_DL_OPEN_EVT, NULL); - mca_ccb_report_event (p_ccb, event, &evt_data); + if (p_data->open.param == MCA_INT) event = MCA_OPEN_CFM_EVT; + p_dcb->cong = false; + evt_data.open_cfm.mtu = p_data->open.peer_mtu; + evt_data.open_cfm.mdl_id = p_dcb->mdl_id; + evt_data.open_cfm.mdl = mca_dcb_to_hdl(p_dcb); + mca_ccb_event(p_ccb, MCA_CCB_DL_OPEN_EVT, NULL); + mca_ccb_report_event(p_ccb, event, &evt_data); } /******************************************************************************* @@ -86,10 +83,9 @@ void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - p_dcb->cong = p_data->llcong; - mca_dcb_report_cong(p_dcb); +void mca_dcb_cong(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + p_dcb->cong = p_data->llcong; + mca_dcb_report_cong(p_dcb); } /******************************************************************************* @@ -101,9 +97,8 @@ void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_dcb_free_data(UNUSED_ATTR tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - osi_free(p_data); +void mca_dcb_free_data(UNUSED_ATTR tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + osi_free(p_data); } /******************************************************************************* @@ -115,18 +110,15 @@ void mca_dcb_free_data(UNUSED_ATTR tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_dcb_do_disconn (tMCA_DCB *p_dcb, - UNUSED_ATTR tMCA_DCB_EVT *p_data) -{ - tMCA_CLOSE close; +void mca_dcb_do_disconn(tMCA_DCB* p_dcb, UNUSED_ATTR tMCA_DCB_EVT* p_data) { + tMCA_CLOSE close; - if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == false)) - { - close.param = MCA_INT; - close.reason = L2CAP_DISC_OK; - close.lcid = 0; - mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT *) &close); - } + if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == false)) { + close.param = MCA_INT; + close.reason = L2CAP_DISC_OK; + close.lcid = 0; + mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT*)&close); + } } /******************************************************************************* @@ -138,17 +130,15 @@ void mca_dcb_do_disconn (tMCA_DCB *p_dcb, * Returns void. * ******************************************************************************/ -void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - uint8_t status; +void mca_dcb_snd_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + uint8_t status; - /* do not need to check cong, because API already checked the status */ - status = L2CA_DataWrite (p_dcb->lcid, p_data->p_pkt); - if (status == L2CAP_DW_CONGESTED) - { - p_dcb->cong = true; - mca_dcb_report_cong(p_dcb); - } + /* do not need to check cong, because API already checked the status */ + status = L2CA_DataWrite(p_dcb->lcid, p_data->p_pkt); + if (status == L2CAP_DW_CONGESTED) { + p_dcb->cong = true; + mca_dcb_report_cong(p_dcb); + } } /******************************************************************************* @@ -161,8 +151,6 @@ void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) * Returns void. * ******************************************************************************/ -void mca_dcb_hdl_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - (*p_dcb->p_cs->p_data_cback) (mca_dcb_to_hdl(p_dcb), (BT_HDR *)p_data); +void mca_dcb_hdl_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + (*p_dcb->p_cs->p_data_cback)(mca_dcb_to_hdl(p_dcb), (BT_HDR*)p_data); } - diff --git a/stack/mcap/mca_dsm.cc b/stack/mcap/mca_dsm.cc index 9a308a06b..349444844 100644 --- a/stack/mcap/mca_dsm.cc +++ b/stack/mcap/mca_dsm.cc @@ -31,95 +31,73 @@ /***************************************************************************** * data channel state machine constants and types ****************************************************************************/ -enum -{ - MCA_DCB_TC_OPEN, - MCA_DCB_CONG, - MCA_DCB_FREE_DATA, - MCA_DCB_DEALLOC, - MCA_DCB_DO_DISCONN, - MCA_DCB_SND_DATA, - MCA_DCB_HDL_DATA, - MCA_DCB_NUM_ACTIONS +enum { + MCA_DCB_TC_OPEN, + MCA_DCB_CONG, + MCA_DCB_FREE_DATA, + MCA_DCB_DEALLOC, + MCA_DCB_DO_DISCONN, + MCA_DCB_SND_DATA, + MCA_DCB_HDL_DATA, + MCA_DCB_NUM_ACTIONS }; -#define MCA_DCB_IGNORE MCA_DCB_NUM_ACTIONS +#define MCA_DCB_IGNORE MCA_DCB_NUM_ACTIONS /* action function list */ const tMCA_DCB_ACTION mca_dcb_action[] = { - mca_dcb_tc_open, - mca_dcb_cong, - mca_dcb_free_data, - mca_dcb_dealloc, - mca_dcb_do_disconn, - mca_dcb_snd_data, - mca_dcb_hdl_data -}; + mca_dcb_tc_open, mca_dcb_cong, mca_dcb_free_data, mca_dcb_dealloc, + mca_dcb_do_disconn, mca_dcb_snd_data, mca_dcb_hdl_data}; /* state table information */ -#define MCA_DCB_ACTIONS 1 /* number of actions */ -#define MCA_DCB_ACT_COL 0 /* position of action function */ -#define MCA_DCB_NEXT_STATE 1 /* position of next state */ -#define MCA_DCB_NUM_COLS 2 /* number of columns in state tables */ +#define MCA_DCB_ACTIONS 1 /* number of actions */ +#define MCA_DCB_ACT_COL 0 /* position of action function */ +#define MCA_DCB_NEXT_STATE 1 /* position of next state */ +#define MCA_DCB_NUM_COLS 2 /* number of columns in state tables */ /* state table for opening state */ const uint8_t mca_dcb_st_opening[][MCA_DCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST}, -/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPENING_ST}, -/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST}, -/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, -/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPENING_ST}, -/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_OPENING_ST} -}; + /* Event Action Next State */ + /* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST}, + /* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPENING_ST}, + /* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST}, + /* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, + /* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPENING_ST}, + /* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_OPENING_ST}}; /* state table for open state */ const uint8_t mca_dcb_st_open[][MCA_DCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST}, -/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_SND_DATA, MCA_DCB_OPEN_ST}, -/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPEN_ST}, -/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, -/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPEN_ST}, -/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_HDL_DATA, MCA_DCB_OPEN_ST} -}; + /* Event Action Next State */ + /* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_DO_DISCONN, MCA_DCB_CLOSING_ST}, + /* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_SND_DATA, MCA_DCB_OPEN_ST}, + /* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_IGNORE, MCA_DCB_OPEN_ST}, + /* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, + /* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_CONG, MCA_DCB_OPEN_ST}, + /* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_HDL_DATA, MCA_DCB_OPEN_ST}}; /* state table for closing state */ const uint8_t mca_dcb_st_closing[][MCA_DCB_NUM_COLS] = { -/* Event Action Next State */ -/* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, -/* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, -/* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST}, -/* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, -/* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, -/* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_CLOSING_ST} -}; + /* Event Action Next State */ + /* MCA_DCB_API_CLOSE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, + /* MCA_DCB_API_WRITE_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, + /* MCA_DCB_TC_OPEN_EVT */ {MCA_DCB_TC_OPEN, MCA_DCB_OPEN_ST}, + /* MCA_DCB_TC_CLOSE_EVT */ {MCA_DCB_DEALLOC, MCA_DCB_NULL_ST}, + /* MCA_DCB_TC_CONG_EVT */ {MCA_DCB_IGNORE, MCA_DCB_CLOSING_ST}, + /* MCA_DCB_TC_DATA_EVT */ {MCA_DCB_FREE_DATA, MCA_DCB_CLOSING_ST}}; /* type for state table */ typedef const uint8_t (*tMCA_DCB_ST_TBL)[MCA_DCB_NUM_COLS]; /* state table */ -const tMCA_DCB_ST_TBL mca_dcb_st_tbl[] = { - mca_dcb_st_opening, - mca_dcb_st_open, - mca_dcb_st_closing -}; +const tMCA_DCB_ST_TBL mca_dcb_st_tbl[] = {mca_dcb_st_opening, mca_dcb_st_open, + mca_dcb_st_closing}; /* verbose event strings for trace */ -const char * const mca_dcb_evt_str[] = { - "API_CLOSE_EVT", - "API_WRITE_EVT", - "TC_OPEN_EVT", - "TC_CLOSE_EVT", - "TC_CONG_EVT", - "TC_DATA_EVT" -}; +const char* const mca_dcb_evt_str[] = {"API_CLOSE_EVT", "API_WRITE_EVT", + "TC_OPEN_EVT", "TC_CLOSE_EVT", + "TC_CONG_EVT", "TC_DATA_EVT"}; /* verbose state strings for trace */ -const char * const mca_dcb_st_str[] = { - "NULL_ST", - "OPENING_ST", - "OPEN_ST", - "CLOSING_ST" -}; +const char* const mca_dcb_st_str[] = {"NULL_ST", "OPENING_ST", "OPEN_ST", + "CLOSING_ST"}; /******************************************************************************* * @@ -132,27 +110,25 @@ const char * const mca_dcb_st_str[] = { * Returns void. * ******************************************************************************/ -void mca_dcb_event(tMCA_DCB *p_dcb, uint8_t event, tMCA_DCB_EVT *p_data) -{ - tMCA_DCB_ST_TBL state_table; - uint8_t action; +void mca_dcb_event(tMCA_DCB* p_dcb, uint8_t event, tMCA_DCB_EVT* p_data) { + tMCA_DCB_ST_TBL state_table; + uint8_t action; - if (p_dcb == NULL) - return; - MCA_TRACE_EVENT("DCB dcb=%d event=%s state=%s", mca_dcb_to_hdl(p_dcb), mca_dcb_evt_str[event], mca_dcb_st_str[p_dcb->state]); + if (p_dcb == NULL) return; + MCA_TRACE_EVENT("DCB dcb=%d event=%s state=%s", mca_dcb_to_hdl(p_dcb), + mca_dcb_evt_str[event], mca_dcb_st_str[p_dcb->state]); - /* look up the state table for the current state */ - state_table = mca_dcb_st_tbl[p_dcb->state - 1]; + /* look up the state table for the current state */ + state_table = mca_dcb_st_tbl[p_dcb->state - 1]; - /* set next state */ - p_dcb->state = state_table[event][MCA_DCB_NEXT_STATE]; + /* set next state */ + p_dcb->state = state_table[event][MCA_DCB_NEXT_STATE]; - /* execute action functions */ - action = state_table[event][MCA_DCB_ACT_COL]; - if (action != MCA_DCB_IGNORE) - { - (*mca_dcb_action[action])(p_dcb, p_data); - } + /* execute action functions */ + action = state_table[event][MCA_DCB_ACT_COL]; + if (action != MCA_DCB_IGNORE) { + (*mca_dcb_action[action])(p_dcb, p_data); + } } /******************************************************************************* @@ -165,34 +141,30 @@ void mca_dcb_event(tMCA_DCB *p_dcb, uint8_t event, tMCA_DCB_EVT *p_data) * Returns tMCA_DCB * * ******************************************************************************/ -tMCA_DCB *mca_dcb_alloc(tMCA_CCB*p_ccb, tMCA_DEP dep) -{ - tMCA_DCB *p_dcb = NULL, *p_dcb_tmp; - tMCA_RCB *p_rcb = p_ccb->p_rcb; - tMCA_CS *p_cs; - int i, max; +tMCA_DCB* mca_dcb_alloc(tMCA_CCB* p_ccb, tMCA_DEP dep) { + tMCA_DCB *p_dcb = NULL, *p_dcb_tmp; + tMCA_RCB* p_rcb = p_ccb->p_rcb; + tMCA_CS* p_cs; + int i, max; - if (dep < MCA_NUM_DEPS) - { - p_cs = &p_rcb->dep[dep]; - i = mca_ccb_to_hdl(p_ccb)-1; - p_dcb_tmp = &mca_cb.dcb[i*MCA_NUM_MDLS]; - /* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */ - max = p_cs->max_mdl; - for (i=0; istate == MCA_DCB_NULL_ST) - { - p_dcb_tmp->p_ccb = p_ccb; - p_dcb_tmp->state = MCA_DCB_OPENING_ST; - p_dcb_tmp->cong = true; - p_dcb_tmp->p_cs = p_cs; - p_dcb = p_dcb_tmp; - break; - } - } + if (dep < MCA_NUM_DEPS) { + p_cs = &p_rcb->dep[dep]; + i = mca_ccb_to_hdl(p_ccb) - 1; + p_dcb_tmp = &mca_cb.dcb[i * MCA_NUM_MDLS]; + /* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */ + max = p_cs->max_mdl; + for (i = 0; i < max; i++, p_dcb_tmp++) { + if (p_dcb_tmp->state == MCA_DCB_NULL_ST) { + p_dcb_tmp->p_ccb = p_ccb; + p_dcb_tmp->state = MCA_DCB_OPENING_ST; + p_dcb_tmp->cong = true; + p_dcb_tmp->p_cs = p_cs; + p_dcb = p_dcb_tmp; + break; + } } - return p_dcb; + } + return p_dcb; } /******************************************************************************* @@ -205,38 +177,32 @@ tMCA_DCB *mca_dcb_alloc(tMCA_CCB*p_ccb, tMCA_DEP dep) * Returns the number of free mdl for the given dep * ******************************************************************************/ -uint8_t mca_dep_free_mdl(tMCA_CCB *p_ccb, tMCA_DEP dep) -{ - tMCA_DCB *p_dcb; - tMCA_RCB *p_rcb = p_ccb->p_rcb; - tMCA_CS *p_cs; - int i, max; - uint8_t count = 0; - uint8_t left; +uint8_t mca_dep_free_mdl(tMCA_CCB* p_ccb, tMCA_DEP dep) { + tMCA_DCB* p_dcb; + tMCA_RCB* p_rcb = p_ccb->p_rcb; + tMCA_CS* p_cs; + int i, max; + uint8_t count = 0; + uint8_t left; - if (dep < MCA_NUM_DEPS) - { - p_cs = &p_rcb->dep[dep]; - i = mca_ccb_to_hdl(p_ccb)-1; - p_dcb = &mca_cb.dcb[i * MCA_NUM_MDLS]; - /* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */ - max = p_cs->max_mdl; - for (i=0; istate != MCA_DCB_NULL_ST) && (p_dcb->p_cs == p_cs)) - { - count++; - break; - } - } + if (dep < MCA_NUM_DEPS) { + p_cs = &p_rcb->dep[dep]; + i = mca_ccb_to_hdl(p_ccb) - 1; + p_dcb = &mca_cb.dcb[i * MCA_NUM_MDLS]; + /* make sure p_cs->max_mdl is smaller than MCA_NUM_MDLS at MCA_CreateDep */ + max = p_cs->max_mdl; + for (i = 0; i < max; i++, p_dcb++) { + if ((p_dcb->state != MCA_DCB_NULL_ST) && (p_dcb->p_cs == p_cs)) { + count++; + break; + } } - else - { - max = 0; - MCA_TRACE_WARNING("Invalid Dep ID"); - } - left = max - count; - return left; + } else { + max = 0; + MCA_TRACE_WARNING("Invalid Dep ID"); + } + left = max - count; + return left; } /******************************************************************************* @@ -248,27 +214,23 @@ uint8_t mca_dep_free_mdl(tMCA_CCB *p_ccb, tMCA_DEP dep) * Returns void. * ******************************************************************************/ -void mca_dcb_dealloc(tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) -{ - tMCA_CCB *p_ccb = p_dcb->p_ccb; - uint8_t event = MCA_CLOSE_IND_EVT; - tMCA_CTRL evt_data; +void mca_dcb_dealloc(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data) { + tMCA_CCB* p_ccb = p_dcb->p_ccb; + uint8_t event = MCA_CLOSE_IND_EVT; + tMCA_CTRL evt_data; - MCA_TRACE_DEBUG("mca_dcb_dealloc"); - osi_free_and_reset((void **)&p_dcb->p_data); - if (p_data) - { - /* non-NULL -> an action function -> report disconnect event */ - evt_data.close_cfm.mdl = mca_dcb_to_hdl(p_dcb); - evt_data.close_cfm.reason = p_data->close.reason; - evt_data.close_cfm.mdl_id = p_dcb->mdl_id; - if (p_data->close.param == MCA_INT) - event = MCA_CLOSE_CFM_EVT; - if (p_data->close.lcid) - mca_ccb_report_event(p_ccb, event, &evt_data); - } - mca_free_tc_tbl_by_lcid (p_dcb->lcid); - memset (p_dcb, 0, sizeof (tMCA_DCB)); + MCA_TRACE_DEBUG("mca_dcb_dealloc"); + osi_free_and_reset((void**)&p_dcb->p_data); + if (p_data) { + /* non-NULL -> an action function -> report disconnect event */ + evt_data.close_cfm.mdl = mca_dcb_to_hdl(p_dcb); + evt_data.close_cfm.reason = p_data->close.reason; + evt_data.close_cfm.mdl_id = p_dcb->mdl_id; + if (p_data->close.param == MCA_INT) event = MCA_CLOSE_CFM_EVT; + if (p_data->close.lcid) mca_ccb_report_event(p_ccb, event, &evt_data); + } + mca_free_tc_tbl_by_lcid(p_dcb->lcid); + memset(p_dcb, 0, sizeof(tMCA_DCB)); } /******************************************************************************* @@ -281,9 +243,8 @@ void mca_dcb_dealloc(tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data) * Returns tMCA_DL. * ******************************************************************************/ -tMCA_DL mca_dcb_to_hdl(tMCA_DCB *p_dcb) -{ - return (uint8_t) (p_dcb - mca_cb.dcb + 1); +tMCA_DL mca_dcb_to_hdl(tMCA_DCB* p_dcb) { + return (uint8_t)(p_dcb - mca_cb.dcb + 1); } /******************************************************************************* @@ -297,12 +258,11 @@ tMCA_DL mca_dcb_to_hdl(tMCA_DCB *p_dcb) * Returns tMCA_DCB * * ******************************************************************************/ -tMCA_DCB *mca_dcb_by_hdl(tMCA_DL hdl) -{ - tMCA_DCB * p_dcb = NULL; - if (hdl && hdl <= MCA_NUM_DCBS && mca_cb.dcb[hdl-1].state) - p_dcb = &mca_cb.dcb[hdl-1]; - return p_dcb; +tMCA_DCB* mca_dcb_by_hdl(tMCA_DL hdl) { + tMCA_DCB* p_dcb = NULL; + if (hdl && hdl <= MCA_NUM_DCBS && mca_cb.dcb[hdl - 1].state) + p_dcb = &mca_cb.dcb[hdl - 1]; + return p_dcb; } /******************************************************************************* @@ -315,27 +275,21 @@ tMCA_DCB *mca_dcb_by_hdl(tMCA_DL hdl) * Returns void * ******************************************************************************/ -void mca_dcb_close_by_mdl_id(tMCA_CCB*p_ccb, uint16_t mdl_id) -{ - tMCA_DCB *p_dcb; - int i; +void mca_dcb_close_by_mdl_id(tMCA_CCB* p_ccb, uint16_t mdl_id) { + tMCA_DCB* p_dcb; + int i; - MCA_TRACE_DEBUG("mca_dcb_close_by_mdl_id mdl_id=%d", mdl_id); - i = mca_ccb_to_hdl(p_ccb)-1; - p_dcb = &mca_cb.dcb[i*MCA_NUM_MDLS]; - for (i=0; istate) - { - if (p_dcb->mdl_id == mdl_id) - { - mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); - break; - } - else if (mdl_id == MCA_ALL_MDL_ID) - { - mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); - } - } + MCA_TRACE_DEBUG("mca_dcb_close_by_mdl_id mdl_id=%d", mdl_id); + i = mca_ccb_to_hdl(p_ccb) - 1; + p_dcb = &mca_cb.dcb[i * MCA_NUM_MDLS]; + for (i = 0; i < MCA_NUM_MDLS; i++, p_dcb++) { + if (p_dcb->state) { + if (p_dcb->mdl_id == mdl_id) { + mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); + break; + } else if (mdl_id == MCA_ALL_MDL_ID) { + mca_dcb_event(p_dcb, MCA_DCB_API_CLOSE_EVT, NULL); + } } + } } diff --git a/stack/mcap/mca_int.h b/stack/mcap/mca_int.h index 7673ee10d..ff1366f41 100644 --- a/stack/mcap/mca_int.h +++ b/stack/mcap/mca_int.h @@ -24,8 +24,8 @@ #ifndef MCA_INT_H #define MCA_INT_H #include "bt_common.h" -#include "osi/include/alarm.h" #include "mca_api.h" +#include "osi/include/alarm.h" #ifdef __cplusplus extern "C" { @@ -36,8 +36,8 @@ extern "C" { ****************************************************************************/ /* INT initiates the L2CAP channel */ -#define MCA_ACP 0 -#define MCA_INT 1 +#define MCA_ACP 0 +#define MCA_INT 1 /***************************************************************************** * Type Definitions @@ -45,160 +45,169 @@ extern "C" { /* Header structure for api/received request/response. */ typedef struct { - BT_HDR hdr; /* layer specific information */ - uint8_t op_code; /* the request/response opcode */ - uint8_t rsp_code; /* valid only if op_code is a response */ - uint16_t mdl_id; /* the MDL ID associated with this request/response */ - uint8_t param; /* other parameter */ - uint8_t mdep_id; /* the MDEP ID associated with this request/response */ - /* tMCA_HANDLE rcb_idx; For internal use only */ - /* tMCA_CL ccb_idx; For internal use only */ - tMCA_DL dcb_idx; /* For internal use only */ + BT_HDR hdr; /* layer specific information */ + uint8_t op_code; /* the request/response opcode */ + uint8_t rsp_code; /* valid only if op_code is a response */ + uint16_t mdl_id; /* the MDL ID associated with this request/response */ + uint8_t param; /* other parameter */ + uint8_t mdep_id; /* the MDEP ID associated with this request/response */ + /* tMCA_HANDLE rcb_idx; For internal use only */ + /* tMCA_CL ccb_idx; For internal use only */ + tMCA_DL dcb_idx; /* For internal use only */ } tMCA_CCB_MSG; /* This data structure is for AVDT_OPEN_IND_EVT and AVDT_OPEN_CFM_EVT. */ typedef struct { - BT_HDR hdr; /* Event header */ - uint16_t peer_mtu; /* Transport channel L2CAP MTU of the peer */ - uint16_t lcid; /* L2CAP LCID */ - uint8_t param; + BT_HDR hdr; /* Event header */ + uint16_t peer_mtu; /* Transport channel L2CAP MTU of the peer */ + uint16_t lcid; /* L2CAP LCID */ + uint8_t param; } tMCA_OPEN; typedef struct { - uint16_t reason; /* disconnect reason from L2CAP */ - uint8_t param; /* MCA_INT or MCA_ACP */ - uint16_t lcid; /* L2CAP LCID */ + uint16_t reason; /* disconnect reason from L2CAP */ + uint8_t param; /* MCA_INT or MCA_ACP */ + uint16_t lcid; /* L2CAP LCID */ } tMCA_CLOSE; /* Header structure for state machine event parameters. */ typedef union { - BT_HDR hdr; /* layer specific information */ - tMCA_CCB_MSG api; - bool llcong; - uint8_t param; - tMCA_OPEN open; - tMCA_CLOSE close; + BT_HDR hdr; /* layer specific information */ + tMCA_CCB_MSG api; + bool llcong; + uint8_t param; + tMCA_OPEN open; + tMCA_CLOSE close; } tMCA_CCB_EVT; /* control channel states */ -enum -{ - MCA_CCB_NULL_ST, /* not allocated */ - MCA_CCB_OPENING_ST, - MCA_CCB_OPEN_ST, /* open */ - MCA_CCB_CLOSING_ST, /* disconnecting */ - MCA_CCB_MAX_ST +enum { + MCA_CCB_NULL_ST, /* not allocated */ + MCA_CCB_OPENING_ST, + MCA_CCB_OPEN_ST, /* open */ + MCA_CCB_CLOSING_ST, /* disconnecting */ + MCA_CCB_MAX_ST }; typedef uint8_t tMCA_CCB_STATE; /* control channel events */ -enum -{ - MCA_CCB_API_CONNECT_EVT, /* application initiates a connect request. */ - MCA_CCB_API_DISCONNECT_EVT, /* application initiates a disconnect request. */ - MCA_CCB_API_REQ_EVT, /* application initiates a request. The request may be create_mdl, delete_mdl, reconnect_mdl or abort_mdl. */ - MCA_CCB_API_RSP_EVT, /* application initiates a create_mdl or reconnect_mdl response. */ - MCA_CCB_MSG_REQ_EVT, /* a create_mdl, delete_mdl, reconnect_mdl or abort_mdl request message is received from the peer. */ - MCA_CCB_MSG_RSP_EVT, /* Response received event. This event is sent whenever a response message is received for an outstanding request message. */ - MCA_CCB_DL_OPEN_EVT, /* data channel open. */ - MCA_CCB_LL_OPEN_EVT, /* Lower layer open. This event is sent when the lower layer channel is open. */ - MCA_CCB_LL_CLOSE_EVT, /* Lower layer close. This event is sent when the lower layer channel is closed. */ - MCA_CCB_LL_CONG_EVT, /* Lower layer congestion. This event is sent when the lower layer is congested. */ - MCA_CCB_RSP_TOUT_EVT /* time out for waiting the message response on the control channel */ +enum { + MCA_CCB_API_CONNECT_EVT, /* application initiates a connect request. */ + MCA_CCB_API_DISCONNECT_EVT, /* application initiates a disconnect request. */ + MCA_CCB_API_REQ_EVT, /* application initiates a request. The request may be + create_mdl, delete_mdl, reconnect_mdl or abort_mdl. */ + MCA_CCB_API_RSP_EVT, /* application initiates a create_mdl or reconnect_mdl + response. */ + MCA_CCB_MSG_REQ_EVT, /* a create_mdl, delete_mdl, reconnect_mdl or abort_mdl + request message is received from the peer. */ + MCA_CCB_MSG_RSP_EVT, /* Response received event. This event is sent whenever + a response message is received for an outstanding + request message. */ + MCA_CCB_DL_OPEN_EVT, /* data channel open. */ + MCA_CCB_LL_OPEN_EVT, /* Lower layer open. This event is sent when the lower + layer channel is open. */ + MCA_CCB_LL_CLOSE_EVT, /* Lower layer close. This event is sent when the lower + layer channel is closed. */ + MCA_CCB_LL_CONG_EVT, /* Lower layer congestion. This event is sent when the + lower layer is congested. */ + MCA_CCB_RSP_TOUT_EVT /* time out for waiting the message response on the + control channel */ }; /* Header structure for callback event parameters. */ typedef union { - tMCA_OPEN open; - tMCA_CLOSE close; - BT_HDR hdr; /* layer specific information */ - BT_HDR *p_pkt; - bool llcong; - uint16_t mdl_id; /* the MDL ID associated with this request/response */ - - /* tMCA_HANDLE rcb_idx; For internal use only */ - /* tMCA_CL ccb_idx; For internal use only */ - /* tMCA_DL dcb_idx; For internal use only */ + tMCA_OPEN open; + tMCA_CLOSE close; + BT_HDR hdr; /* layer specific information */ + BT_HDR* p_pkt; + bool llcong; + uint16_t mdl_id; /* the MDL ID associated with this request/response */ + + /* tMCA_HANDLE rcb_idx; For internal use only */ + /* tMCA_CL ccb_idx; For internal use only */ + /* tMCA_DL dcb_idx; For internal use only */ } tMCA_DCB_EVT; /* data channel states */ -enum -{ - MCA_DCB_NULL_ST, /* not allocated */ - MCA_DCB_OPENING_ST, /* create/reconnect sequence is successful, waiting for data channel connection */ - MCA_DCB_OPEN_ST, /* open */ - MCA_DCB_CLOSING_ST, /* disconnecting */ - MCA_DCB_MAX_ST +enum { + MCA_DCB_NULL_ST, /* not allocated */ + MCA_DCB_OPENING_ST, /* create/reconnect sequence is successful, waiting for + data channel connection */ + MCA_DCB_OPEN_ST, /* open */ + MCA_DCB_CLOSING_ST, /* disconnecting */ + MCA_DCB_MAX_ST }; typedef uint8_t tMCA_DCB_STATE; /* data channel events */ -enum -{ - MCA_DCB_API_CLOSE_EVT, /* This event is sent when the application wants to disconnect the data channel.*/ - MCA_DCB_API_WRITE_EVT, /* This event is sent when the application wants to send a data packet to the peer.*/ - MCA_DCB_TC_OPEN_EVT, /* Transport Channel open. This event is sent when the channel is open.*/ - MCA_DCB_TC_CLOSE_EVT, /* Transport Channel close.*/ - MCA_DCB_TC_CONG_EVT, /* Transport Channel congestion status.*/ - MCA_DCB_TC_DATA_EVT /* This event is sent when a data packet is received from the peer.*/ +enum { + MCA_DCB_API_CLOSE_EVT, /* This event is sent when the application wants to + disconnect the data channel.*/ + MCA_DCB_API_WRITE_EVT, /* This event is sent when the application wants to + send a data packet to the peer.*/ + MCA_DCB_TC_OPEN_EVT, /* Transport Channel open. This event is sent when the + channel is open.*/ + MCA_DCB_TC_CLOSE_EVT, /* Transport Channel close.*/ + MCA_DCB_TC_CONG_EVT, /* Transport Channel congestion status.*/ + MCA_DCB_TC_DATA_EVT /* This event is sent when a data packet is received from + the peer.*/ }; - - - /* "states" used in transport channel table */ -#define MCA_TC_ST_UNUSED 0 /* Unused - unallocated */ -#define MCA_TC_ST_IDLE 1 /* No connection */ -#define MCA_TC_ST_ACP 2 /* Waiting to accept a connection */ -#define MCA_TC_ST_INT 3 /* Initiating a connection */ -#define MCA_TC_ST_CONN 4 /* Waiting for connection confirm */ -#define MCA_TC_ST_CFG 5 /* Waiting for configuration complete */ -#define MCA_TC_ST_OPEN 6 /* Channel opened */ -#define MCA_TC_ST_SEC_INT 7 /* Security process as INT */ -#define MCA_TC_ST_SEC_ACP 8 /* Security process as ACP */ +#define MCA_TC_ST_UNUSED 0 /* Unused - unallocated */ +#define MCA_TC_ST_IDLE 1 /* No connection */ +#define MCA_TC_ST_ACP 2 /* Waiting to accept a connection */ +#define MCA_TC_ST_INT 3 /* Initiating a connection */ +#define MCA_TC_ST_CONN 4 /* Waiting for connection confirm */ +#define MCA_TC_ST_CFG 5 /* Waiting for configuration complete */ +#define MCA_TC_ST_OPEN 6 /* Channel opened */ +#define MCA_TC_ST_SEC_INT 7 /* Security process as INT */ +#define MCA_TC_ST_SEC_ACP 8 /* Security process as ACP */ /* Configuration flags. tMCA_TC_TBL.cfg_flags */ -#define MCA_L2C_CFG_IND_DONE (1<<0) -#define MCA_L2C_CFG_CFM_DONE (1<<1) -#define MCA_L2C_CFG_CONN_INT (1<<2) -#define MCA_L2C_CFG_CONN_ACP (1<<3) -#define MCA_L2C_CFG_DISCN_INT (1<<4) -#define MCA_L2C_CFG_DISCN_ACP (1<<5) - +#define MCA_L2C_CFG_IND_DONE (1 << 0) +#define MCA_L2C_CFG_CFM_DONE (1 << 1) +#define MCA_L2C_CFG_CONN_INT (1 << 2) +#define MCA_L2C_CFG_CONN_ACP (1 << 3) +#define MCA_L2C_CFG_DISCN_INT (1 << 4) +#define MCA_L2C_CFG_DISCN_ACP (1 << 5) -#define MCA_CTRL_TCID 0 /* to identify control channel by tMCA_TC_TBL.tcid */ +#define MCA_CTRL_TCID 0 /* to identify control channel by tMCA_TC_TBL.tcid */ /* transport channel table */ typedef struct { - uint16_t peer_mtu; /* L2CAP mtu of the peer device */ - uint16_t my_mtu; /* Our MTU for this channel */ - uint16_t lcid; /* L2CAP LCID */ - uint8_t tcid; /* transport channel id (0, for control channel. (MDEP ID + 1) for data channel) */ - tMCA_DL cb_idx; /* 1-based index to ccb or dcb */ - uint8_t state; /* transport channel state */ - uint8_t cfg_flags; /* L2CAP configuration flags */ - uint8_t id; /* L2CAP id sent by peer device (need this to handle security pending) */ + uint16_t peer_mtu; /* L2CAP mtu of the peer device */ + uint16_t my_mtu; /* Our MTU for this channel */ + uint16_t lcid; /* L2CAP LCID */ + uint8_t tcid; /* transport channel id (0, for control channel. (MDEP ID + 1) + for data channel) */ + tMCA_DL cb_idx; /* 1-based index to ccb or dcb */ + uint8_t state; /* transport channel state */ + uint8_t cfg_flags; /* L2CAP configuration flags */ + uint8_t id; /* L2CAP id sent by peer device (need this to handle security + pending) */ } tMCA_TC_TBL; /* transport control block */ typedef struct { - tMCA_TC_TBL tc_tbl[MCA_NUM_TC_TBL]; - uint8_t lcid_tbl[MAX_L2CAP_CHANNELS]; /* map LCID to tc_tbl index */ + tMCA_TC_TBL tc_tbl[MCA_NUM_TC_TBL]; + uint8_t lcid_tbl[MAX_L2CAP_CHANNELS]; /* map LCID to tc_tbl index */ } tMCA_TC; /* registration control block */ typedef struct { - tMCA_REG reg; /* the parameter at register */ - tMCA_CS dep[MCA_NUM_DEPS]; /* the registration info for each MDEP */ - tMCA_CTRL_CBACK *p_cback; /* control callback function */ + tMCA_REG reg; /* the parameter at register */ + tMCA_CS dep[MCA_NUM_DEPS]; /* the registration info for each MDEP */ + tMCA_CTRL_CBACK* p_cback; /* control callback function */ } tMCA_RCB; -enum -{ - MCA_CCB_STAT_NORM, /* normal operation (based on ccb state) */ - MCA_CCB_STAT_PENDING, /* waiting for data channel */ - MCA_CCB_STAT_RECONN, /* reinitiate connection after transitioning from CLOSING to IDLE state */ - MCA_CCB_STAT_DISC /* MCA_DisconnectReq or MCA_Deregister is called. waiting for all associated CL and DL to detach */ +enum { + MCA_CCB_STAT_NORM, /* normal operation (based on ccb state) */ + MCA_CCB_STAT_PENDING, /* waiting for data channel */ + MCA_CCB_STAT_RECONN, /* reinitiate connection after transitioning from CLOSING + to IDLE state */ + MCA_CCB_STAT_DISC /* MCA_DisconnectReq or MCA_Deregister is called. waiting + for all associated CL and DL to detach */ }; typedef uint8_t tMCA_CCB_STAT; @@ -209,26 +218,27 @@ typedef uint8_t tMCA_CCB_STAT; * ccb[MCA_NUM_LINKS*2]...ccb[MCA_NUM_LINKS*3-1] -> rcb[2] */ typedef struct { - tMCA_RCB *p_rcb; /* the associated registration control block */ - alarm_t *mca_ccb_timer; /* MCA CCB timer entry */ - tMCA_CCB_MSG *p_tx_req; /* Current request being sent/awaiting response */ - tMCA_CCB_MSG *p_rx_msg; /* Current message received/being processed */ - BD_ADDR peer_addr; /* BD address of peer */ - uint16_t sec_mask; /* Security mask for connections as initiator */ - uint16_t ctrl_vpsm; /* The virtual PSM that peer is listening for control channel */ - uint16_t data_vpsm; /* The virtual PSM that peer is listening for data channel. */ - uint16_t lcid; /* L2CAP lcid for this control channel */ - uint8_t state; /* The CCB state machine state */ - bool cong; /* Whether control channel is congested */ - tMCA_CCB_STAT status; /* see tMCA_CCB_STAT */ + tMCA_RCB* p_rcb; /* the associated registration control block */ + alarm_t* mca_ccb_timer; /* MCA CCB timer entry */ + tMCA_CCB_MSG* p_tx_req; /* Current request being sent/awaiting response */ + tMCA_CCB_MSG* p_rx_msg; /* Current message received/being processed */ + BD_ADDR peer_addr; /* BD address of peer */ + uint16_t sec_mask; /* Security mask for connections as initiator */ + uint16_t ctrl_vpsm; /* The virtual PSM that peer is listening for control + channel */ + uint16_t + data_vpsm; /* The virtual PSM that peer is listening for data channel. */ + uint16_t lcid; /* L2CAP lcid for this control channel */ + uint8_t state; /* The CCB state machine state */ + bool cong; /* Whether control channel is congested */ + tMCA_CCB_STAT status; /* see tMCA_CCB_STAT */ } tMCA_CCB; -typedef void (*tMCA_CCB_ACTION)(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); +typedef void (*tMCA_CCB_ACTION)(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); -enum -{ - MCA_DCB_STAT_NORM, /* normal operation (based on dcb state) */ - MCA_DCB_STAT_DEL, /* MCA_Delete is called. waiting for the DL to detach */ - MCA_DCB_STAT_DISC /* MCA_CloseReq is called. waiting for the DL to detach */ +enum { + MCA_DCB_STAT_NORM, /* normal operation (based on dcb state) */ + MCA_DCB_STAT_DEL, /* MCA_Delete is called. waiting for the DL to detach */ + MCA_DCB_STAT_DISC /* MCA_CloseReq is called. waiting for the DL to detach */ }; typedef uint8_t tMCA_DCB_STAT; @@ -247,101 +257,105 @@ typedef uint8_t tMCA_DCB_STAT; * ...dcb[MCA_NUM_MDLS*3*MCA_NUM_LINKS*3-1] -> rcb[2] */ typedef struct { - tMCA_CCB *p_ccb; /* the associated control control block */ - BT_HDR *p_data; /* data packet held due to L2CAP channel congestion */ - tMCA_CS *p_cs; /* the associated MDEP info. p_cs->type is the mdep id(internal use) */ - const tMCA_CHNL_CFG *p_chnl_cfg; /* cfg params for L2CAP channel */ - uint16_t mdl_id; /* the MDL ID for this data channel */ - uint16_t lcid; /* L2CAP lcid */ - uint8_t state; /* The DCB state machine state */ - bool cong; /* Whether data channel is congested */ - tMCA_DCB_STAT status; /* see tMCA_DCB_STAT */ + tMCA_CCB* p_ccb; /* the associated control control block */ + BT_HDR* p_data; /* data packet held due to L2CAP channel congestion */ + tMCA_CS* p_cs; /* the associated MDEP info. p_cs->type is the mdep id(internal + use) */ + const tMCA_CHNL_CFG* p_chnl_cfg; /* cfg params for L2CAP channel */ + uint16_t mdl_id; /* the MDL ID for this data channel */ + uint16_t lcid; /* L2CAP lcid */ + uint8_t state; /* The DCB state machine state */ + bool cong; /* Whether data channel is congested */ + tMCA_DCB_STAT status; /* see tMCA_DCB_STAT */ } tMCA_DCB; -typedef void (*tMCA_DCB_ACTION)(tMCA_DCB *p_ccb, tMCA_DCB_EVT *p_data); +typedef void (*tMCA_DCB_ACTION)(tMCA_DCB* p_ccb, tMCA_DCB_EVT* p_data); /* Control block for MCA */ typedef struct { - tMCA_RCB rcb[MCA_NUM_REGS]; /* registration control block */ - tMCA_CCB ccb[MCA_NUM_CCBS]; /* control channel control blocks */ - tMCA_DCB dcb[MCA_NUM_DCBS]; /* data channel control blocks */ - tMCA_TC tc; /* transport control block */ - uint8_t trace_level; /* trace level */ + tMCA_RCB rcb[MCA_NUM_REGS]; /* registration control block */ + tMCA_CCB ccb[MCA_NUM_CCBS]; /* control channel control blocks */ + tMCA_DCB dcb[MCA_NUM_DCBS]; /* data channel control blocks */ + tMCA_TC tc; /* transport control block */ + uint8_t trace_level; /* trace level */ } tMCA_CB; /* csm functions */ -extern void mca_ccb_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CCB_EVT *p_data); -extern tMCA_CCB *mca_ccb_by_bd(tMCA_HANDLE handle, BD_ADDR bd_addr); -extern tMCA_CCB *mca_ccb_alloc(tMCA_HANDLE handle, BD_ADDR bd_addr); -extern void mca_ccb_rsp_tout(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_dealloc(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern tMCA_CL mca_ccb_to_hdl(tMCA_CCB *p_ccb); -extern tMCA_CCB *mca_ccb_by_hdl(tMCA_CL mcl); -extern bool mca_ccb_uses_mdl_id(tMCA_CCB *p_ccb, uint16_t mdl_id); +extern void mca_ccb_event(tMCA_CCB* p_ccb, uint8_t event, tMCA_CCB_EVT* p_data); +extern tMCA_CCB* mca_ccb_by_bd(tMCA_HANDLE handle, BD_ADDR bd_addr); +extern tMCA_CCB* mca_ccb_alloc(tMCA_HANDLE handle, BD_ADDR bd_addr); +extern void mca_ccb_rsp_tout(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_dealloc(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern tMCA_CL mca_ccb_to_hdl(tMCA_CCB* p_ccb); +extern tMCA_CCB* mca_ccb_by_hdl(tMCA_CL mcl); +extern bool mca_ccb_uses_mdl_id(tMCA_CCB* p_ccb, uint16_t mdl_id); /* cact functions */ -extern void mca_ccb_report_event(tMCA_CCB *p_ccb, uint8_t event, tMCA_CTRL *p_data); -extern void mca_ccb_free_msg(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_snd_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_snd_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_do_disconn (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_cong(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_hdl_req(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_hdl_rsp(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_ll_open (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); -extern void mca_ccb_dl_open (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data); +extern void mca_ccb_report_event(tMCA_CCB* p_ccb, uint8_t event, + tMCA_CTRL* p_data); +extern void mca_ccb_free_msg(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_snd_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_snd_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_do_disconn(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_cong(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_hdl_req(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_hdl_rsp(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_ll_open(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); +extern void mca_ccb_dl_open(tMCA_CCB* p_ccb, tMCA_CCB_EVT* p_data); /* dsm functions */ -extern void mca_dcb_event(tMCA_DCB *p_dcb, uint8_t event, tMCA_DCB_EVT *p_data); -extern tMCA_DCB *mca_dcb_alloc(tMCA_CCB*p_ccb, tMCA_DEP dep); -extern uint8_t mca_dep_free_mdl(tMCA_CCB*p_ccb, tMCA_DEP dep); -extern void mca_dcb_dealloc(tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern tMCA_DL mca_dcb_to_hdl(tMCA_DCB *p_dcb); -extern tMCA_DCB *mca_dcb_by_hdl(tMCA_DL hdl); -extern void mca_dcb_close_by_mdl_id(tMCA_CCB*p_ccb, uint16_t mdl_id); +extern void mca_dcb_event(tMCA_DCB* p_dcb, uint8_t event, tMCA_DCB_EVT* p_data); +extern tMCA_DCB* mca_dcb_alloc(tMCA_CCB* p_ccb, tMCA_DEP dep); +extern uint8_t mca_dep_free_mdl(tMCA_CCB* p_ccb, tMCA_DEP dep); +extern void mca_dcb_dealloc(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern tMCA_DL mca_dcb_to_hdl(tMCA_DCB* p_dcb); +extern tMCA_DCB* mca_dcb_by_hdl(tMCA_DL hdl); +extern void mca_dcb_close_by_mdl_id(tMCA_CCB* p_ccb, uint16_t mdl_id); /* dact functions */ -extern void mca_dcb_tc_open (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern void mca_dcb_cong (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern void mca_dcb_free_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern void mca_dcb_do_disconn (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern void mca_dcb_snd_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); -extern void mca_dcb_hdl_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data); - +extern void mca_dcb_tc_open(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern void mca_dcb_cong(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern void mca_dcb_free_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern void mca_dcb_do_disconn(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern void mca_dcb_snd_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); +extern void mca_dcb_hdl_data(tMCA_DCB* p_dcb, tMCA_DCB_EVT* p_data); /* main/utils functions */ extern tMCA_HANDLE mca_handle_by_cpsm(uint16_t psm); extern tMCA_HANDLE mca_handle_by_dpsm(uint16_t psm); -extern tMCA_TC_TBL * mca_tc_tbl_calloc(tMCA_CCB *p_ccb); -extern tMCA_TC_TBL * mca_tc_tbl_dalloc(tMCA_DCB *p_dcb); -extern tMCA_TC_TBL * mca_tc_tbl_by_lcid(uint16_t lcid); +extern tMCA_TC_TBL* mca_tc_tbl_calloc(tMCA_CCB* p_ccb); +extern tMCA_TC_TBL* mca_tc_tbl_dalloc(tMCA_DCB* p_dcb); +extern tMCA_TC_TBL* mca_tc_tbl_by_lcid(uint16_t lcid); extern void mca_free_tc_tbl_by_lcid(uint16_t lcid); -extern void mca_set_cfg_by_tbl(tL2CAP_CFG_INFO *p_cfg, tMCA_TC_TBL *p_tbl); -extern void mca_tc_close_ind(tMCA_TC_TBL *p_tbl, uint16_t reason); -extern void mca_tc_open_ind(tMCA_TC_TBL *p_tbl); -extern void mca_tc_cong_ind(tMCA_TC_TBL *p_tbl, bool is_congested); -extern void mca_tc_data_ind(tMCA_TC_TBL *p_tbl, BT_HDR *p_buf); -extern tMCA_RCB * mca_rcb_alloc(tMCA_REG *p_reg); +extern void mca_set_cfg_by_tbl(tL2CAP_CFG_INFO* p_cfg, tMCA_TC_TBL* p_tbl); +extern void mca_tc_close_ind(tMCA_TC_TBL* p_tbl, uint16_t reason); +extern void mca_tc_open_ind(tMCA_TC_TBL* p_tbl); +extern void mca_tc_cong_ind(tMCA_TC_TBL* p_tbl, bool is_congested); +extern void mca_tc_data_ind(tMCA_TC_TBL* p_tbl, BT_HDR* p_buf); +extern tMCA_RCB* mca_rcb_alloc(tMCA_REG* p_reg); extern void mca_rcb_dealloc(tMCA_HANDLE handle); -extern tMCA_HANDLE mca_rcb_to_handle(tMCA_RCB *p_rcb); -extern tMCA_RCB *mca_rcb_by_handle(tMCA_HANDLE handle); -extern bool mca_is_valid_dep_id(tMCA_RCB *p_rcb, tMCA_DEP dep); -extern void mca_ccb_timer_timeout(void *data); -extern void mca_stop_timer(tMCA_CCB *p_ccb); +extern tMCA_HANDLE mca_rcb_to_handle(tMCA_RCB* p_rcb); +extern tMCA_RCB* mca_rcb_by_handle(tMCA_HANDLE handle); +extern bool mca_is_valid_dep_id(tMCA_RCB* p_rcb, tMCA_DEP dep); +extern void mca_ccb_timer_timeout(void* data); +extern void mca_stop_timer(tMCA_CCB* p_ccb); /* l2c functions */ -extern uint16_t mca_l2c_open_req(BD_ADDR bd_addr, uint16_t PSM, const tMCA_CHNL_CFG *p_chnl_cfg); +extern uint16_t mca_l2c_open_req(BD_ADDR bd_addr, uint16_t PSM, + const tMCA_CHNL_CFG* p_chnl_cfg); /* callback function declarations */ -extern void mca_l2c_cconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); -extern void mca_l2c_dconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); +extern void mca_l2c_cconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, + uint16_t psm, uint8_t id); +extern void mca_l2c_dconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, + uint16_t psm, uint8_t id); extern void mca_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result); -extern void mca_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -extern void mca_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -extern void mca_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); +extern void mca_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +extern void mca_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +extern void mca_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); extern void mca_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result); -extern void mca_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); -extern void mca_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf); +extern void mca_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); +extern void mca_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); /***************************************************************************** * global data diff --git a/stack/mcap/mca_l2c.cc b/stack/mcap/mca_l2c.cc index c9f81af5d..fc08776c7 100644 --- a/stack/mcap/mca_l2c.cc +++ b/stack/mcap/mca_l2c.cc @@ -32,35 +32,30 @@ #include "mca_int.h" #include "osi/include/osi.h" - /* L2CAP callback function structure */ -const tL2CAP_APPL_INFO mca_l2c_int_appl = -{ - NULL, - mca_l2c_connect_cfm_cback, - NULL, - mca_l2c_config_ind_cback, - mca_l2c_config_cfm_cback, - mca_l2c_disconnect_ind_cback, - mca_l2c_disconnect_cfm_cback, - NULL, - mca_l2c_data_ind_cback, - mca_l2c_congestion_ind_cback, - NULL -}; +const tL2CAP_APPL_INFO mca_l2c_int_appl = {NULL, + mca_l2c_connect_cfm_cback, + NULL, + mca_l2c_config_ind_cback, + mca_l2c_config_cfm_cback, + mca_l2c_disconnect_ind_cback, + mca_l2c_disconnect_cfm_cback, + NULL, + mca_l2c_data_ind_cback, + mca_l2c_congestion_ind_cback, + NULL}; /* Control channel eL2CAP default options */ -const tL2CAP_FCR_OPTS mca_l2c_fcr_opts_def = -{ - L2CAP_FCR_ERTM_MODE, /* Mandatory for MCAP */ - MCA_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ - MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ - MCA_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ - MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ - MCA_FCR_OPT_MPS_SIZE /* MPS segment size */ +const tL2CAP_FCR_OPTS mca_l2c_fcr_opts_def = { + L2CAP_FCR_ERTM_MODE, /* Mandatory for MCAP */ + MCA_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ + MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before + disconnecting */ + MCA_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ + MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ + MCA_FCR_OPT_MPS_SIZE /* MPS segment size */ }; - /******************************************************************************* * * Function mca_sec_check_complete_term @@ -71,41 +66,39 @@ const tL2CAP_FCR_OPTS mca_l2c_fcr_opts_def = * Returns void * ******************************************************************************/ -static void mca_sec_check_complete_term (BD_ADDR bd_addr, - UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tMCA_TC_TBL *p_tbl = (tMCA_TC_TBL *)p_ref_data; - tL2CAP_CFG_INFO cfg; - tL2CAP_ERTM_INFO ertm_info; - - MCA_TRACE_DEBUG("mca_sec_check_complete_term res: %d", res); - - if ( res == BTM_SUCCESS ) - { - MCA_TRACE_DEBUG ("lcid:x%x id:x%x", p_tbl->lcid, p_tbl->id); - /* Set the FCR options: control channel mandates ERTM */ - ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; - ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; - ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; - ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; - /* Send response to the L2CAP layer. */ - L2CA_ErtmConnectRsp (bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK, L2CAP_CONN_OK, &ertm_info); - - /* transition to configuration state */ - p_tbl->state = MCA_TC_ST_CFG; - - /* Send L2CAP config req */ - mca_set_cfg_by_tbl (&cfg, p_tbl); - L2CA_ConfigReq(p_tbl->lcid, &cfg); - } - else - { - L2CA_ConnectRsp (bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK); - mca_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); - } +static void mca_sec_check_complete_term(BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tMCA_TC_TBL* p_tbl = (tMCA_TC_TBL*)p_ref_data; + tL2CAP_CFG_INFO cfg; + tL2CAP_ERTM_INFO ertm_info; + + MCA_TRACE_DEBUG("mca_sec_check_complete_term res: %d", res); + + if (res == BTM_SUCCESS) { + MCA_TRACE_DEBUG("lcid:x%x id:x%x", p_tbl->lcid, p_tbl->id); + /* Set the FCR options: control channel mandates ERTM */ + ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; + ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; + ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; + ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; + ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; + ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; + /* Send response to the L2CAP layer. */ + L2CA_ErtmConnectRsp(bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK, + L2CAP_CONN_OK, &ertm_info); + + /* transition to configuration state */ + p_tbl->state = MCA_TC_ST_CFG; + + /* Send L2CAP config req */ + mca_set_cfg_by_tbl(&cfg, p_tbl); + L2CA_ConfigReq(p_tbl->lcid, &cfg); + } else { + L2CA_ConnectRsp(bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_SECURITY_BLOCK, + L2CAP_CONN_OK); + mca_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); + } } /******************************************************************************* @@ -118,28 +111,25 @@ static void mca_sec_check_complete_term (BD_ADDR bd_addr, * Returns void * ******************************************************************************/ -static void mca_sec_check_complete_orig (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tMCA_TC_TBL *p_tbl = (tMCA_TC_TBL *)p_ref_data; - tL2CAP_CFG_INFO cfg; - - MCA_TRACE_DEBUG("mca_sec_check_complete_orig res: %d", res); - - if ( res == BTM_SUCCESS ) - { - /* set channel state */ - p_tbl->state = MCA_TC_ST_CFG; - - /* Send L2CAP config req */ - mca_set_cfg_by_tbl (&cfg, p_tbl); - L2CA_ConfigReq(p_tbl->lcid, &cfg); - } - else - { - L2CA_DisconnectReq (p_tbl->lcid); - mca_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); - } +static void mca_sec_check_complete_orig(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tMCA_TC_TBL* p_tbl = (tMCA_TC_TBL*)p_ref_data; + tL2CAP_CFG_INFO cfg; + + MCA_TRACE_DEBUG("mca_sec_check_complete_orig res: %d", res); + + if (res == BTM_SUCCESS) { + /* set channel state */ + p_tbl->state = MCA_TC_ST_CFG; + + /* Send L2CAP config req */ + mca_set_cfg_by_tbl(&cfg, p_tbl); + L2CA_ConfigReq(p_tbl->lcid, &cfg); + } else { + L2CA_DisconnectReq(p_tbl->lcid); + mca_tc_close_ind(p_tbl, L2CAP_CONN_SECURITY_BLOCK); + } } /******************************************************************************* * @@ -150,72 +140,67 @@ static void mca_sec_check_complete_orig (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATT * Returns void * ******************************************************************************/ -void mca_l2c_cconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id) -{ - tMCA_HANDLE handle = mca_handle_by_cpsm(psm); - tMCA_CCB *p_ccb; - tMCA_TC_TBL *p_tbl = NULL; - uint16_t result = L2CAP_CONN_NO_RESOURCES; - tBTM_STATUS rc; - tL2CAP_ERTM_INFO ertm_info, *p_ertm_info = NULL; - tL2CAP_CFG_INFO cfg; - - MCA_TRACE_EVENT ("mca_l2c_cconn_ind_cback: lcid:x%x psm:x%x id:x%x", lcid, psm, id); - - /* do we already have a control channel for this peer? */ - p_ccb = mca_ccb_by_bd(handle, bd_addr); - if (p_ccb == NULL) - { - /* no, allocate ccb */ - p_ccb = mca_ccb_alloc(handle, bd_addr); - if (p_ccb != NULL) - { - /* allocate and set up entry */ - p_ccb->lcid = lcid; - p_tbl = mca_tc_tbl_calloc(p_ccb); - p_tbl->id = id; - p_tbl->cfg_flags= MCA_L2C_CFG_CONN_ACP; - /* proceed with connection */ - /* Check the security */ - rc = btm_sec_mx_access_request (bd_addr, psm, false, BTM_SEC_PROTO_MCA, 0, - &mca_sec_check_complete_term, p_tbl); - if (rc == BTM_CMD_STARTED) - { - /* Set the FCR options: control channel mandates ERTM */ - ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; - ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; - ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; - ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; - p_ertm_info = &ertm_info; - result = L2CAP_CONN_PENDING; - } - else - result = L2CAP_CONN_OK; - } - - /* deal with simultaneous control channel connect case */ +void mca_l2c_cconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id) { + tMCA_HANDLE handle = mca_handle_by_cpsm(psm); + tMCA_CCB* p_ccb; + tMCA_TC_TBL* p_tbl = NULL; + uint16_t result = L2CAP_CONN_NO_RESOURCES; + tBTM_STATUS rc; + tL2CAP_ERTM_INFO ertm_info, *p_ertm_info = NULL; + tL2CAP_CFG_INFO cfg; + + MCA_TRACE_EVENT("mca_l2c_cconn_ind_cback: lcid:x%x psm:x%x id:x%x", lcid, psm, + id); + + /* do we already have a control channel for this peer? */ + p_ccb = mca_ccb_by_bd(handle, bd_addr); + if (p_ccb == NULL) { + /* no, allocate ccb */ + p_ccb = mca_ccb_alloc(handle, bd_addr); + if (p_ccb != NULL) { + /* allocate and set up entry */ + p_ccb->lcid = lcid; + p_tbl = mca_tc_tbl_calloc(p_ccb); + p_tbl->id = id; + p_tbl->cfg_flags = MCA_L2C_CFG_CONN_ACP; + /* proceed with connection */ + /* Check the security */ + rc = btm_sec_mx_access_request(bd_addr, psm, false, BTM_SEC_PROTO_MCA, 0, + &mca_sec_check_complete_term, p_tbl); + if (rc == BTM_CMD_STARTED) { + /* Set the FCR options: control channel mandates ERTM */ + ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; + ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; + ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; + ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; + ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; + ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; + p_ertm_info = &ertm_info; + result = L2CAP_CONN_PENDING; + } else + result = L2CAP_CONN_OK; } - /* else reject their connection */ - if (!p_tbl || (p_tbl->state != MCA_TC_ST_CFG)) - { - /* Send L2CAP connect rsp */ - L2CA_ErtmConnectRsp (bd_addr, id, lcid, result, L2CAP_CONN_OK, p_ertm_info); + /* deal with simultaneous control channel connect case */ + } + /* else reject their connection */ - /* if result ok, proceed with connection and send L2CAP - config req */ - if (result == L2CAP_CONN_OK) - { - /* set channel state */ - p_tbl->state = MCA_TC_ST_CFG; + if (!p_tbl || (p_tbl->state != MCA_TC_ST_CFG)) { + /* Send L2CAP connect rsp */ + L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, L2CAP_CONN_OK, p_ertm_info); - /* Send L2CAP config req */ - mca_set_cfg_by_tbl (&cfg, p_tbl); - L2CA_ConfigReq(p_tbl->lcid, &cfg); - } + /* if result ok, proceed with connection and send L2CAP + config req */ + if (result == L2CAP_CONN_OK) { + /* set channel state */ + p_tbl->state = MCA_TC_ST_CFG; + + /* Send L2CAP config req */ + mca_set_cfg_by_tbl(&cfg, p_tbl); + L2CA_ConfigReq(p_tbl->lcid, &cfg); } + } } /******************************************************************************* @@ -228,61 +213,59 @@ void mca_l2c_cconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8 * Returns void * ******************************************************************************/ -void mca_l2c_dconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id) -{ - tMCA_HANDLE handle = mca_handle_by_dpsm(psm); - tMCA_CCB *p_ccb; - tMCA_DCB *p_dcb; - tMCA_TC_TBL *p_tbl = NULL; - uint16_t result; - tL2CAP_CFG_INFO cfg; - tL2CAP_ERTM_INFO *p_ertm_info = NULL, ertm_info; - const tMCA_CHNL_CFG *p_chnl_cfg; - - MCA_TRACE_EVENT ("mca_l2c_dconn_ind_cback: lcid:x%x psm:x%x ", lcid, psm); - - if (((p_ccb = mca_ccb_by_bd(handle, bd_addr)) != NULL) && /* find the CCB */ - (p_ccb->status == MCA_CCB_STAT_PENDING) && /* this CCB is expecting a MDL */ - (p_ccb->p_tx_req && (p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) != NULL)) - { - /* found the associated dcb in listening mode */ - /* proceed with connection */ - p_dcb->lcid = lcid; - p_tbl = mca_tc_tbl_dalloc(p_dcb); - p_tbl->id = id; - p_tbl->cfg_flags= MCA_L2C_CFG_CONN_ACP; - p_chnl_cfg = p_dcb->p_chnl_cfg; - /* assume that control channel has verified the security requirement */ - /* Set the FCR options: control channel mandates ERTM */ - ertm_info.preferred_mode = p_chnl_cfg->fcr_opt.mode; - ertm_info.allowed_modes = (1 << p_chnl_cfg->fcr_opt.mode); - ertm_info.user_rx_buf_size = p_chnl_cfg->user_rx_buf_size; - ertm_info.user_tx_buf_size = p_chnl_cfg->user_tx_buf_size; - ertm_info.fcr_rx_buf_size = p_chnl_cfg->fcr_rx_buf_size; - ertm_info.fcr_tx_buf_size = p_chnl_cfg->fcr_tx_buf_size; - p_ertm_info = &ertm_info; - result = L2CAP_CONN_OK; - } - else - { - /* else we're not listening for traffic channel; reject - * (this error code is specified by MCAP spec) */ - result = L2CAP_CONN_NO_RESOURCES; - } - - /* Send L2CAP connect rsp */ - L2CA_ErtmConnectRsp (bd_addr, id, lcid, result, result, p_ertm_info); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* transition to configuration state */ - p_tbl->state = MCA_TC_ST_CFG; - - /* Send L2CAP config req */ - mca_set_cfg_by_tbl (&cfg, p_tbl); - L2CA_ConfigReq(lcid, &cfg); - } +void mca_l2c_dconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id) { + tMCA_HANDLE handle = mca_handle_by_dpsm(psm); + tMCA_CCB* p_ccb; + tMCA_DCB* p_dcb; + tMCA_TC_TBL* p_tbl = NULL; + uint16_t result; + tL2CAP_CFG_INFO cfg; + tL2CAP_ERTM_INFO *p_ertm_info = NULL, ertm_info; + const tMCA_CHNL_CFG* p_chnl_cfg; + + MCA_TRACE_EVENT("mca_l2c_dconn_ind_cback: lcid:x%x psm:x%x ", lcid, psm); + + if (((p_ccb = mca_ccb_by_bd(handle, bd_addr)) != NULL) && /* find the CCB */ + (p_ccb->status == + MCA_CCB_STAT_PENDING) && /* this CCB is expecting a MDL */ + (p_ccb->p_tx_req && + (p_dcb = mca_dcb_by_hdl(p_ccb->p_tx_req->dcb_idx)) != NULL)) { + /* found the associated dcb in listening mode */ + /* proceed with connection */ + p_dcb->lcid = lcid; + p_tbl = mca_tc_tbl_dalloc(p_dcb); + p_tbl->id = id; + p_tbl->cfg_flags = MCA_L2C_CFG_CONN_ACP; + p_chnl_cfg = p_dcb->p_chnl_cfg; + /* assume that control channel has verified the security requirement */ + /* Set the FCR options: control channel mandates ERTM */ + ertm_info.preferred_mode = p_chnl_cfg->fcr_opt.mode; + ertm_info.allowed_modes = (1 << p_chnl_cfg->fcr_opt.mode); + ertm_info.user_rx_buf_size = p_chnl_cfg->user_rx_buf_size; + ertm_info.user_tx_buf_size = p_chnl_cfg->user_tx_buf_size; + ertm_info.fcr_rx_buf_size = p_chnl_cfg->fcr_rx_buf_size; + ertm_info.fcr_tx_buf_size = p_chnl_cfg->fcr_tx_buf_size; + p_ertm_info = &ertm_info; + result = L2CAP_CONN_OK; + } else { + /* else we're not listening for traffic channel; reject + * (this error code is specified by MCAP spec) */ + result = L2CAP_CONN_NO_RESOURCES; + } + + /* Send L2CAP connect rsp */ + L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, result, p_ertm_info); + + /* if result ok, proceed with connection */ + if (result == L2CAP_CONN_OK) { + /* transition to configuration state */ + p_tbl->state = MCA_TC_ST_CFG; + + /* Send L2CAP config req */ + mca_set_cfg_by_tbl(&cfg, p_tbl); + L2CA_ConfigReq(lcid, &cfg); + } } /******************************************************************************* @@ -295,65 +278,53 @@ void mca_l2c_dconn_ind_cback(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8 * Returns void * ******************************************************************************/ -void mca_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tMCA_TC_TBL *p_tbl; - tL2CAP_CFG_INFO cfg; - tMCA_CCB *p_ccb; - - MCA_TRACE_DEBUG("mca_l2c_connect_cfm_cback lcid: x%x, result: %d", - lcid, result); - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - MCA_TRACE_DEBUG("p_tbl state: %d, tcid: %d", p_tbl->state, p_tbl->tcid); - /* if in correct state */ - if (p_tbl->state == MCA_TC_ST_CONN) - { - /* if result successful */ - if (result == L2CAP_CONN_OK) - { - if (p_tbl->tcid != 0) - { - /* set channel state */ - p_tbl->state = MCA_TC_ST_CFG; - - /* Send L2CAP config req */ - mca_set_cfg_by_tbl (&cfg, p_tbl); - L2CA_ConfigReq(lcid, &cfg); - } - else - { - p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); - if (p_ccb == NULL) - { - result = L2CAP_CONN_NO_RESOURCES; - } - else - { - /* set channel state */ - p_tbl->state = MCA_TC_ST_SEC_INT; - p_tbl->lcid = lcid; - p_tbl->cfg_flags= MCA_L2C_CFG_CONN_INT; - - /* Check the security */ - btm_sec_mx_access_request (p_ccb->peer_addr, p_ccb->ctrl_vpsm, - true, BTM_SEC_PROTO_MCA, - p_tbl->tcid, - &mca_sec_check_complete_orig, p_tbl); - } - } - } - - /* failure; notify adaption that channel closed */ - if (result != L2CAP_CONN_OK) - { - p_tbl->cfg_flags |= MCA_L2C_CFG_DISCN_INT; - mca_tc_close_ind(p_tbl, result); - } +void mca_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { + tMCA_TC_TBL* p_tbl; + tL2CAP_CFG_INFO cfg; + tMCA_CCB* p_ccb; + + MCA_TRACE_DEBUG("mca_l2c_connect_cfm_cback lcid: x%x, result: %d", lcid, + result); + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + MCA_TRACE_DEBUG("p_tbl state: %d, tcid: %d", p_tbl->state, p_tbl->tcid); + /* if in correct state */ + if (p_tbl->state == MCA_TC_ST_CONN) { + /* if result successful */ + if (result == L2CAP_CONN_OK) { + if (p_tbl->tcid != 0) { + /* set channel state */ + p_tbl->state = MCA_TC_ST_CFG; + + /* Send L2CAP config req */ + mca_set_cfg_by_tbl(&cfg, p_tbl); + L2CA_ConfigReq(lcid, &cfg); + } else { + p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); + if (p_ccb == NULL) { + result = L2CAP_CONN_NO_RESOURCES; + } else { + /* set channel state */ + p_tbl->state = MCA_TC_ST_SEC_INT; + p_tbl->lcid = lcid; + p_tbl->cfg_flags = MCA_L2C_CFG_CONN_INT; + + /* Check the security */ + btm_sec_mx_access_request(p_ccb->peer_addr, p_ccb->ctrl_vpsm, true, + BTM_SEC_PROTO_MCA, p_tbl->tcid, + &mca_sec_check_complete_orig, p_tbl); + } } + } + + /* failure; notify adaption that channel closed */ + if (result != L2CAP_CONN_OK) { + p_tbl->cfg_flags |= MCA_L2C_CFG_DISCN_INT; + mca_tc_close_ind(p_tbl, result); + } } + } } /******************************************************************************* @@ -366,37 +337,31 @@ void mca_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void mca_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tMCA_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - /* if in correct state */ - if (p_tbl->state == MCA_TC_ST_CFG) - { - /* if result successful */ - if (p_cfg->result == L2CAP_CONN_OK) - { - /* update cfg_flags */ - p_tbl->cfg_flags |= MCA_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_tbl->cfg_flags & MCA_L2C_CFG_IND_DONE) - { - mca_tc_open_ind(p_tbl); - } - } - /* else failure */ - else - { - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } +void mca_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tMCA_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + /* if in correct state */ + if (p_tbl->state == MCA_TC_ST_CFG) { + /* if result successful */ + if (p_cfg->result == L2CAP_CONN_OK) { + /* update cfg_flags */ + p_tbl->cfg_flags |= MCA_L2C_CFG_CFM_DONE; + + /* if configuration complete */ + if (p_tbl->cfg_flags & MCA_L2C_CFG_IND_DONE) { + mca_tc_open_ind(p_tbl); } + } + /* else failure */ + else { + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } } + } } /******************************************************************************* @@ -409,48 +374,41 @@ void mca_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void mca_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tMCA_TC_TBL *p_tbl; - uint16_t result = L2CAP_CFG_OK; - - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_tbl->peer_mtu = p_cfg->mtu; - if (p_tbl->peer_mtu < MCA_MIN_MTU) - { - result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - } - } - else - { - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - } - MCA_TRACE_DEBUG("peer_mtu: %d, lcid: x%x mtu_present:%d",p_tbl->peer_mtu, lcid, p_cfg->mtu_present); - - /* send L2CAP configure response */ - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->result = result; - L2CA_ConfigRsp(lcid, p_cfg); - - /* if first config ind */ - if ((p_tbl->cfg_flags & MCA_L2C_CFG_IND_DONE) == 0) - { - /* update cfg_flags */ - p_tbl->cfg_flags |= MCA_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_tbl->cfg_flags & MCA_L2C_CFG_CFM_DONE) - { - mca_tc_open_ind(p_tbl); - } - } +void mca_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tMCA_TC_TBL* p_tbl; + uint16_t result = L2CAP_CFG_OK; + + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + /* store the mtu in tbl */ + if (p_cfg->mtu_present) { + p_tbl->peer_mtu = p_cfg->mtu; + if (p_tbl->peer_mtu < MCA_MIN_MTU) { + result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + } + } else { + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + } + MCA_TRACE_DEBUG("peer_mtu: %d, lcid: x%x mtu_present:%d", p_tbl->peer_mtu, + lcid, p_cfg->mtu_present); + + /* send L2CAP configure response */ + memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + p_cfg->result = result; + L2CA_ConfigRsp(lcid, p_cfg); + + /* if first config ind */ + if ((p_tbl->cfg_flags & MCA_L2C_CFG_IND_DONE) == 0) { + /* update cfg_flags */ + p_tbl->cfg_flags |= MCA_L2C_CFG_IND_DONE; + + /* if configuration complete */ + if (p_tbl->cfg_flags & MCA_L2C_CFG_CFM_DONE) { + mca_tc_open_ind(p_tbl); + } } + } } /******************************************************************************* @@ -463,28 +421,24 @@ void mca_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -void mca_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) -{ - tMCA_TC_TBL *p_tbl; - uint16_t reason = L2CAP_DISC_TIMEOUT; - - MCA_TRACE_DEBUG("mca_l2c_disconnect_ind_cback lcid: %d, ack_needed: %d", - lcid, ack_needed); - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - - p_tbl->cfg_flags = MCA_L2C_CFG_DISCN_ACP; - if (ack_needed) - reason = L2CAP_DISC_OK; - mca_tc_close_ind(p_tbl, reason); +void mca_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { + tMCA_TC_TBL* p_tbl; + uint16_t reason = L2CAP_DISC_TIMEOUT; + + MCA_TRACE_DEBUG("mca_l2c_disconnect_ind_cback lcid: %d, ack_needed: %d", lcid, + ack_needed); + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + if (ack_needed) { + /* send L2CAP disconnect response */ + L2CA_DisconnectRsp(lcid); } + + p_tbl->cfg_flags = MCA_L2C_CFG_DISCN_ACP; + if (ack_needed) reason = L2CAP_DISC_OK; + mca_tc_close_ind(p_tbl, reason); + } } /******************************************************************************* @@ -497,22 +451,19 @@ void mca_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) * Returns void * ******************************************************************************/ -void mca_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) -{ - tMCA_TC_TBL *p_tbl; - - MCA_TRACE_DEBUG("mca_l2c_disconnect_cfm_cback lcid: x%x, result: %d", - lcid, result); - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - p_tbl->cfg_flags = MCA_L2C_CFG_DISCN_INT; - mca_tc_close_ind(p_tbl, result); - } +void mca_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) { + tMCA_TC_TBL* p_tbl; + + MCA_TRACE_DEBUG("mca_l2c_disconnect_cfm_cback lcid: x%x, result: %d", lcid, + result); + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + p_tbl->cfg_flags = MCA_L2C_CFG_DISCN_INT; + mca_tc_close_ind(p_tbl, result); + } } - /******************************************************************************* * * Function mca_l2c_congestion_ind_cback @@ -523,16 +474,14 @@ void mca_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) * Returns void * ******************************************************************************/ -void mca_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) -{ - tMCA_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - mca_tc_cong_ind(p_tbl, is_congested); - } +void mca_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) { + tMCA_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + mca_tc_cong_ind(p_tbl, is_congested); + } } /******************************************************************************* @@ -545,21 +494,17 @@ void mca_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested) * Returns void * ******************************************************************************/ -void mca_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) -{ - tMCA_TC_TBL *p_tbl; - - /* look up info for this channel */ - p_tbl = mca_tc_tbl_by_lcid(lcid); - if (p_tbl != NULL) - { - mca_tc_data_ind(p_tbl, p_buf); - } - else /* prevent buffer leak */ - osi_free(p_buf); +void mca_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf) { + tMCA_TC_TBL* p_tbl; + + /* look up info for this channel */ + p_tbl = mca_tc_tbl_by_lcid(lcid); + if (p_tbl != NULL) { + mca_tc_data_ind(p_tbl, p_buf); + } else /* prevent buffer leak */ + osi_free(p_buf); } - /******************************************************************************* * * Function mca_l2c_open_req @@ -570,28 +515,24 @@ void mca_l2c_data_ind_cback(uint16_t lcid, BT_HDR *p_buf) * Returns void. * ******************************************************************************/ -uint16_t mca_l2c_open_req(BD_ADDR bd_addr, uint16_t psm, const tMCA_CHNL_CFG *p_chnl_cfg) -{ - tL2CAP_ERTM_INFO ertm_info; - - if (p_chnl_cfg) - { - ertm_info.preferred_mode = p_chnl_cfg->fcr_opt.mode; - ertm_info.allowed_modes = (1 << p_chnl_cfg->fcr_opt.mode); - ertm_info.user_rx_buf_size = p_chnl_cfg->user_rx_buf_size; - ertm_info.user_tx_buf_size = p_chnl_cfg->user_tx_buf_size; - ertm_info.fcr_rx_buf_size = p_chnl_cfg->fcr_rx_buf_size; - ertm_info.fcr_tx_buf_size = p_chnl_cfg->fcr_tx_buf_size; - } - else - { - ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; - ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; - ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; - ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; - } - return L2CA_ErtmConnectReq (psm, bd_addr, &ertm_info); +uint16_t mca_l2c_open_req(BD_ADDR bd_addr, uint16_t psm, + const tMCA_CHNL_CFG* p_chnl_cfg) { + tL2CAP_ERTM_INFO ertm_info; + + if (p_chnl_cfg) { + ertm_info.preferred_mode = p_chnl_cfg->fcr_opt.mode; + ertm_info.allowed_modes = (1 << p_chnl_cfg->fcr_opt.mode); + ertm_info.user_rx_buf_size = p_chnl_cfg->user_rx_buf_size; + ertm_info.user_tx_buf_size = p_chnl_cfg->user_tx_buf_size; + ertm_info.fcr_rx_buf_size = p_chnl_cfg->fcr_rx_buf_size; + ertm_info.fcr_tx_buf_size = p_chnl_cfg->fcr_tx_buf_size; + } else { + ertm_info.preferred_mode = mca_l2c_fcr_opts_def.mode; + ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; + ertm_info.user_rx_buf_size = MCA_USER_RX_BUF_SIZE; + ertm_info.user_tx_buf_size = MCA_USER_TX_BUF_SIZE; + ertm_info.fcr_rx_buf_size = MCA_FCR_RX_BUF_SIZE; + ertm_info.fcr_tx_buf_size = MCA_FCR_TX_BUF_SIZE; + } + return L2CA_ErtmConnectReq(psm, bd_addr, &ertm_info); } - diff --git a/stack/mcap/mca_main.cc b/stack/mcap/mca_main.cc index 3d04ba524..a292c9af3 100644 --- a/stack/mcap/mca_main.cc +++ b/stack/mcap/mca_main.cc @@ -25,12 +25,12 @@ #include #include -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" +#include "l2c_api.h" #include "mca_api.h" #include "mca_defs.h" #include "mca_int.h" -#include "l2c_api.h" /* Main Control block for MCA */ tMCA_CB mca_cb; @@ -41,18 +41,17 @@ tMCA_CB mca_cb; /* table of standard opcode message size */ const uint8_t mca_std_msg_len[MCA_NUM_STANDARD_OPCODE] = { - 4, /* MCA_OP_ERROR_RSP */ - 5, /* MCA_OP_MDL_CREATE_REQ */ - 5, /* MCA_OP_MDL_CREATE_RSP */ - 3, /* MCA_OP_MDL_RECONNECT_REQ */ - 4, /* MCA_OP_MDL_RECONNECT_RSP */ - 3, /* MCA_OP_MDL_ABORT_REQ */ - 4, /* MCA_OP_MDL_ABORT_RSP */ - 3, /* MCA_OP_MDL_DELETE_REQ */ - 4 /* MCA_OP_MDL_DELETE_RSP */ + 4, /* MCA_OP_ERROR_RSP */ + 5, /* MCA_OP_MDL_CREATE_REQ */ + 5, /* MCA_OP_MDL_CREATE_RSP */ + 3, /* MCA_OP_MDL_RECONNECT_REQ */ + 4, /* MCA_OP_MDL_RECONNECT_RSP */ + 3, /* MCA_OP_MDL_ABORT_REQ */ + 4, /* MCA_OP_MDL_ABORT_RSP */ + 3, /* MCA_OP_MDL_DELETE_REQ */ + 4 /* MCA_OP_MDL_DELETE_RSP */ }; - /******************************************************************************* * * Function mca_handle_by_cpsm @@ -63,21 +62,18 @@ const uint8_t mca_std_msg_len[MCA_NUM_STANDARD_OPCODE] = { * Returns the MCA handle. * ******************************************************************************/ -tMCA_HANDLE mca_handle_by_cpsm(uint16_t psm) -{ - int i; - tMCA_HANDLE handle = 0; - tMCA_RCB *p_rcb = &mca_cb.rcb[0]; - - for (i=0; ip_cback && p_rcb->reg.ctrl_psm == psm) - { - handle = i+1; - break; - } +tMCA_HANDLE mca_handle_by_cpsm(uint16_t psm) { + int i; + tMCA_HANDLE handle = 0; + tMCA_RCB* p_rcb = &mca_cb.rcb[0]; + + for (i = 0; i < MCA_NUM_REGS; i++, p_rcb++) { + if (p_rcb->p_cback && p_rcb->reg.ctrl_psm == psm) { + handle = i + 1; + break; } - return handle; + } + return handle; } /******************************************************************************* @@ -90,21 +86,18 @@ tMCA_HANDLE mca_handle_by_cpsm(uint16_t psm) * Returns the MCA handle. * ******************************************************************************/ -tMCA_HANDLE mca_handle_by_dpsm(uint16_t psm) -{ - int i; - tMCA_HANDLE handle = 0; - tMCA_RCB *p_rcb = &mca_cb.rcb[0]; - - for (i=0; ip_cback && p_rcb->reg.data_psm == psm) - { - handle = i+1; - break; - } +tMCA_HANDLE mca_handle_by_dpsm(uint16_t psm) { + int i; + tMCA_HANDLE handle = 0; + tMCA_RCB* p_rcb = &mca_cb.rcb[0]; + + for (i = 0; i < MCA_NUM_REGS; i++, p_rcb++) { + if (p_rcb->p_cback && p_rcb->reg.data_psm == psm) { + handle = i + 1; + break; } - return handle; + } + return handle; } /******************************************************************************* @@ -117,35 +110,32 @@ tMCA_HANDLE mca_handle_by_dpsm(uint16_t psm) * Returns The tranport table. * ******************************************************************************/ -tMCA_TC_TBL * mca_tc_tbl_calloc(tMCA_CCB *p_ccb) -{ - tMCA_TC_TBL *p_tbl = mca_cb.tc.tc_tbl; - int i; - - /* find next free entry in tc table */ - for (i = 0; i < MCA_NUM_TC_TBL; i++, p_tbl++) - { - if (p_tbl->state == MCA_TC_ST_UNUSED) - { - break; - } +tMCA_TC_TBL* mca_tc_tbl_calloc(tMCA_CCB* p_ccb) { + tMCA_TC_TBL* p_tbl = mca_cb.tc.tc_tbl; + int i; + + /* find next free entry in tc table */ + for (i = 0; i < MCA_NUM_TC_TBL; i++, p_tbl++) { + if (p_tbl->state == MCA_TC_ST_UNUSED) { + break; } - - /* sanity check */ - assert(i != MCA_NUM_TC_TBL); - - /* initialize entry */ - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - p_tbl->cfg_flags= 0; - p_tbl->cb_idx = mca_ccb_to_hdl(p_ccb); - p_tbl->tcid = MCA_CTRL_TCID; - p_tbl->my_mtu = MCA_CTRL_MTU; - p_tbl->state = MCA_TC_ST_IDLE; - p_tbl->lcid = p_ccb->lcid; - mca_cb.tc.lcid_tbl[p_ccb->lcid - L2CAP_BASE_APPL_CID] = i; - - MCA_TRACE_DEBUG("%s() - cb_idx: %d", __func__, p_tbl->cb_idx); - return p_tbl; + } + + /* sanity check */ + assert(i != MCA_NUM_TC_TBL); + + /* initialize entry */ + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + p_tbl->cfg_flags = 0; + p_tbl->cb_idx = mca_ccb_to_hdl(p_ccb); + p_tbl->tcid = MCA_CTRL_TCID; + p_tbl->my_mtu = MCA_CTRL_MTU; + p_tbl->state = MCA_TC_ST_IDLE; + p_tbl->lcid = p_ccb->lcid; + mca_cb.tc.lcid_tbl[p_ccb->lcid - L2CAP_BASE_APPL_CID] = i; + + MCA_TRACE_DEBUG("%s() - cb_idx: %d", __func__, p_tbl->cb_idx); + return p_tbl; } /******************************************************************************* @@ -158,35 +148,33 @@ tMCA_TC_TBL * mca_tc_tbl_calloc(tMCA_CCB *p_ccb) * Returns The tranport table. * ******************************************************************************/ -tMCA_TC_TBL * mca_tc_tbl_dalloc(tMCA_DCB *p_dcb) -{ - tMCA_TC_TBL *p_tbl = mca_cb.tc.tc_tbl; - int i; - - /* find next free entry in tc table */ - for (i = 0; i < MCA_NUM_TC_TBL; i++, p_tbl++) - { - if (p_tbl->state == MCA_TC_ST_UNUSED) - { - break; - } +tMCA_TC_TBL* mca_tc_tbl_dalloc(tMCA_DCB* p_dcb) { + tMCA_TC_TBL* p_tbl = mca_cb.tc.tc_tbl; + int i; + + /* find next free entry in tc table */ + for (i = 0; i < MCA_NUM_TC_TBL; i++, p_tbl++) { + if (p_tbl->state == MCA_TC_ST_UNUSED) { + break; } - - /* sanity check */ - assert(i != MCA_NUM_TC_TBL); - - /* initialize entry */ - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - p_tbl->cfg_flags= 0; - p_tbl->cb_idx = mca_dcb_to_hdl(p_dcb); - p_tbl->tcid = p_dcb->p_cs->type + 1; - p_tbl->my_mtu = p_dcb->p_chnl_cfg->data_mtu; - p_tbl->state = MCA_TC_ST_IDLE; - p_tbl->lcid = p_dcb->lcid; - mca_cb.tc.lcid_tbl[p_dcb->lcid - L2CAP_BASE_APPL_CID] = i; - - MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, p_tbl->cb_idx); - return p_tbl; + } + + /* sanity check */ + assert(i != MCA_NUM_TC_TBL); + + /* initialize entry */ + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + p_tbl->cfg_flags = 0; + p_tbl->cb_idx = mca_dcb_to_hdl(p_dcb); + p_tbl->tcid = p_dcb->p_cs->type + 1; + p_tbl->my_mtu = p_dcb->p_chnl_cfg->data_mtu; + p_tbl->state = MCA_TC_ST_IDLE; + p_tbl->lcid = p_dcb->lcid; + mca_cb.tc.lcid_tbl[p_dcb->lcid - L2CAP_BASE_APPL_CID] = i; + + MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, + p_tbl->cb_idx); + return p_tbl; } /******************************************************************************* @@ -199,20 +187,17 @@ tMCA_TC_TBL * mca_tc_tbl_dalloc(tMCA_DCB *p_dcb) * Returns The tranport table. * ******************************************************************************/ -tMCA_TC_TBL *mca_tc_tbl_by_lcid(uint16_t lcid) -{ - uint8_t idx; +tMCA_TC_TBL* mca_tc_tbl_by_lcid(uint16_t lcid) { + uint8_t idx; - if (lcid) - { - idx = mca_cb.tc.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; + if (lcid) { + idx = mca_cb.tc.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; - if (idx < MCA_NUM_TC_TBL) - { - return &mca_cb.tc.tc_tbl[idx]; - } + if (idx < MCA_NUM_TC_TBL) { + return &mca_cb.tc.tc_tbl[idx]; } - return NULL; + } + return NULL; } /******************************************************************************* @@ -225,22 +210,18 @@ tMCA_TC_TBL *mca_tc_tbl_by_lcid(uint16_t lcid) * Returns void. * ******************************************************************************/ -void mca_free_tc_tbl_by_lcid(uint16_t lcid) -{ - uint8_t idx; +void mca_free_tc_tbl_by_lcid(uint16_t lcid) { + uint8_t idx; - if (lcid) - { - idx = mca_cb.tc.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; + if (lcid) { + idx = mca_cb.tc.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; - if (idx < MCA_NUM_TC_TBL) - { - mca_cb.tc.tc_tbl[idx].state = MCA_TC_ST_UNUSED; - } + if (idx < MCA_NUM_TC_TBL) { + mca_cb.tc.tc_tbl[idx].state = MCA_TC_ST_UNUSED; } + } } - /******************************************************************************* * * Function mca_set_cfg_by_tbl @@ -250,35 +231,29 @@ void mca_free_tc_tbl_by_lcid(uint16_t lcid) * Returns none. * ******************************************************************************/ -void mca_set_cfg_by_tbl(tL2CAP_CFG_INFO *p_cfg, tMCA_TC_TBL *p_tbl) -{ - tMCA_DCB *p_dcb; - const tL2CAP_FCR_OPTS *p_opt; - tMCA_FCS_OPT fcs = MCA_FCS_NONE; - - if (p_tbl->tcid == MCA_CTRL_TCID) - { - p_opt = &mca_l2c_fcr_opts_def; - } - else - { - p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); - if (p_dcb) - { - p_opt = &p_dcb->p_chnl_cfg->fcr_opt; - fcs = p_dcb->p_chnl_cfg->fcs; - } - } - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->mtu_present = true; - p_cfg->mtu = p_tbl->my_mtu; - p_cfg->fcr_present = true; - memcpy(&p_cfg->fcr, p_opt, sizeof (tL2CAP_FCR_OPTS)); - if (fcs & MCA_FCS_PRESNT_MASK) - { - p_cfg->fcs_present = true; - p_cfg->fcs = (fcs & MCA_FCS_USE_MASK); +void mca_set_cfg_by_tbl(tL2CAP_CFG_INFO* p_cfg, tMCA_TC_TBL* p_tbl) { + tMCA_DCB* p_dcb; + const tL2CAP_FCR_OPTS* p_opt; + tMCA_FCS_OPT fcs = MCA_FCS_NONE; + + if (p_tbl->tcid == MCA_CTRL_TCID) { + p_opt = &mca_l2c_fcr_opts_def; + } else { + p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); + if (p_dcb) { + p_opt = &p_dcb->p_chnl_cfg->fcr_opt; + fcs = p_dcb->p_chnl_cfg->fcs; } + } + memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); + p_cfg->mtu_present = true; + p_cfg->mtu = p_tbl->my_mtu; + p_cfg->fcr_present = true; + memcpy(&p_cfg->fcr, p_opt, sizeof(tL2CAP_FCR_OPTS)); + if (fcs & MCA_FCS_PRESNT_MASK) { + p_cfg->fcs_present = true; + p_cfg->fcs = (fcs & MCA_FCS_USE_MASK); + } } /******************************************************************************* @@ -294,46 +269,40 @@ void mca_set_cfg_by_tbl(tL2CAP_CFG_INFO *p_cfg, tMCA_TC_TBL *p_tbl) * Returns Nothing. * ******************************************************************************/ -void mca_tc_close_ind(tMCA_TC_TBL *p_tbl, uint16_t reason) -{ - tMCA_CCB *p_ccb; - tMCA_DCB *p_dcb; - tMCA_CLOSE close; - - close.param = MCA_ACP; - close.reason = reason; - close.lcid = p_tbl->lcid; - - MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx:%d, old: %d", __func__, - p_tbl->tcid, p_tbl->cb_idx, p_tbl->state); - - /* Check if the transport channel is in use */ - if (p_tbl->state == MCA_TC_ST_UNUSED) - return; - - /* clear mca_tc_tbl entry */ - if (p_tbl->cfg_flags&MCA_L2C_CFG_DISCN_INT) - close.param = MCA_INT; - p_tbl->cfg_flags = 0; - p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; - - /* if control channel, notify ccb that channel close */ - if (p_tbl->tcid == MCA_CTRL_TCID) - { - p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); - mca_ccb_event(p_ccb, MCA_CCB_LL_CLOSE_EVT, (tMCA_CCB_EVT *)&close); - } - /* notify dcb that channel close */ - else - { - /* look up dcb */ - p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); - if (p_dcb != NULL) - { - mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT *) &close); - } +void mca_tc_close_ind(tMCA_TC_TBL* p_tbl, uint16_t reason) { + tMCA_CCB* p_ccb; + tMCA_DCB* p_dcb; + tMCA_CLOSE close; + + close.param = MCA_ACP; + close.reason = reason; + close.lcid = p_tbl->lcid; + + MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx:%d, old: %d", __func__, p_tbl->tcid, + p_tbl->cb_idx, p_tbl->state); + + /* Check if the transport channel is in use */ + if (p_tbl->state == MCA_TC_ST_UNUSED) return; + + /* clear mca_tc_tbl entry */ + if (p_tbl->cfg_flags & MCA_L2C_CFG_DISCN_INT) close.param = MCA_INT; + p_tbl->cfg_flags = 0; + p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; + + /* if control channel, notify ccb that channel close */ + if (p_tbl->tcid == MCA_CTRL_TCID) { + p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); + mca_ccb_event(p_ccb, MCA_CCB_LL_CLOSE_EVT, (tMCA_CCB_EVT*)&close); + } + /* notify dcb that channel close */ + else { + /* look up dcb */ + p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); + if (p_dcb != NULL) { + mca_dcb_event(p_dcb, MCA_DCB_TC_CLOSE_EVT, (tMCA_DCB_EVT*)&close); } - p_tbl->state = MCA_TC_ST_UNUSED; + } + p_tbl->state = MCA_TC_ST_UNUSED; } /******************************************************************************* @@ -347,47 +316,42 @@ void mca_tc_close_ind(tMCA_TC_TBL *p_tbl, uint16_t reason) * Returns Nothing. * ******************************************************************************/ -void mca_tc_open_ind(tMCA_TC_TBL *p_tbl) -{ - tMCA_CCB *p_ccb; - tMCA_DCB *p_dcb; - tMCA_OPEN open; - - MCA_TRACE_DEBUG("mca_tc_open_ind tcid: %d, cb_idx: %d", p_tbl->tcid, p_tbl->cb_idx); - p_tbl->state = MCA_TC_ST_OPEN; - - open.peer_mtu = p_tbl->peer_mtu; - open.lcid = p_tbl->lcid; - /* use param to indicate the role of connection. - * MCA_ACP, if ACP */ - open.param = MCA_INT; - if (p_tbl->cfg_flags & MCA_L2C_CFG_CONN_ACP) - { - open.param = MCA_ACP; - } - - /* if control channel, notify ccb that channel open */ - if (p_tbl->tcid == MCA_CTRL_TCID) - { - p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); - - mca_ccb_event(p_ccb, MCA_CCB_LL_OPEN_EVT, (tMCA_CCB_EVT *)&open); - } - /* must be data channel, notify dcb that channel open */ - else - { - /* look up dcb */ - p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); - - /* put lcid in event data */ - if (p_dcb != NULL) - { - mca_dcb_event(p_dcb, MCA_DCB_TC_OPEN_EVT, (tMCA_DCB_EVT *) &open); - } +void mca_tc_open_ind(tMCA_TC_TBL* p_tbl) { + tMCA_CCB* p_ccb; + tMCA_DCB* p_dcb; + tMCA_OPEN open; + + MCA_TRACE_DEBUG("mca_tc_open_ind tcid: %d, cb_idx: %d", p_tbl->tcid, + p_tbl->cb_idx); + p_tbl->state = MCA_TC_ST_OPEN; + + open.peer_mtu = p_tbl->peer_mtu; + open.lcid = p_tbl->lcid; + /* use param to indicate the role of connection. + * MCA_ACP, if ACP */ + open.param = MCA_INT; + if (p_tbl->cfg_flags & MCA_L2C_CFG_CONN_ACP) { + open.param = MCA_ACP; + } + + /* if control channel, notify ccb that channel open */ + if (p_tbl->tcid == MCA_CTRL_TCID) { + p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); + + mca_ccb_event(p_ccb, MCA_CCB_LL_OPEN_EVT, (tMCA_CCB_EVT*)&open); + } + /* must be data channel, notify dcb that channel open */ + else { + /* look up dcb */ + p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); + + /* put lcid in event data */ + if (p_dcb != NULL) { + mca_dcb_event(p_dcb, MCA_DCB_TC_OPEN_EVT, (tMCA_DCB_EVT*)&open); } + } } - /******************************************************************************* * * Function mca_tc_cong_ind @@ -402,32 +366,28 @@ void mca_tc_open_ind(tMCA_TC_TBL *p_tbl) * Returns Nothing. * ******************************************************************************/ -void mca_tc_cong_ind(tMCA_TC_TBL *p_tbl, bool is_congested) -{ - tMCA_CCB *p_ccb; - tMCA_DCB *p_dcb; - - MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, p_tbl->cb_idx); - - /* if control channel, notify ccb of congestion */ - if (p_tbl->tcid == MCA_CTRL_TCID) - { - p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); - mca_ccb_event(p_ccb, MCA_CCB_LL_CONG_EVT, (tMCA_CCB_EVT *) &is_congested); - } - /* notify dcb that channel open */ - else - { - /* look up dcb by cb_idx */ - p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); - if (p_dcb != NULL) - { - mca_dcb_event(p_dcb, MCA_DCB_TC_CONG_EVT, (tMCA_DCB_EVT *) &is_congested); - } +void mca_tc_cong_ind(tMCA_TC_TBL* p_tbl, bool is_congested) { + tMCA_CCB* p_ccb; + tMCA_DCB* p_dcb; + + MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, + p_tbl->cb_idx); + + /* if control channel, notify ccb of congestion */ + if (p_tbl->tcid == MCA_CTRL_TCID) { + p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); + mca_ccb_event(p_ccb, MCA_CCB_LL_CONG_EVT, (tMCA_CCB_EVT*)&is_congested); + } + /* notify dcb that channel open */ + else { + /* look up dcb by cb_idx */ + p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); + if (p_dcb != NULL) { + mca_dcb_event(p_dcb, MCA_DCB_TC_CONG_EVT, (tMCA_DCB_EVT*)&is_congested); } + } } - /******************************************************************************* * * Function mca_tc_data_ind @@ -439,68 +399,57 @@ void mca_tc_cong_ind(tMCA_TC_TBL *p_tbl, bool is_congested) * Returns Nothing. * ******************************************************************************/ -void mca_tc_data_ind(tMCA_TC_TBL *p_tbl, BT_HDR *p_buf) -{ - tMCA_CCB *p_ccb; - tMCA_DCB *p_dcb; - uint8_t event = MCA_CCB_MSG_RSP_EVT; - uint8_t *p; - uint8_t rej_rsp_code = MCA_RSP_SUCCESS; - - MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, p_tbl->cb_idx); - - /* if control channel, handle control message */ - if (p_tbl->tcid == MCA_CTRL_TCID) - { - p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); - if (p_ccb) - { - p = (uint8_t*)(p_buf+1) + p_buf->offset; - /* all the request opcode has bit 0 set. response code has bit 0 clear */ - if ((*p) & 0x01) - event = MCA_CCB_MSG_REQ_EVT; - - if (*p < MCA_NUM_STANDARD_OPCODE) - { - if (p_buf->len != mca_std_msg_len[*p]) - { - MCA_TRACE_ERROR ("$s() - opcode: %d required len: %d, got len: %d" - , __func__, *p, mca_std_msg_len[*p], p_buf->len); - rej_rsp_code = MCA_RSP_BAD_PARAM; - } - } - else if ((*p >= MCA_FIRST_SYNC_OP) && (*p <= MCA_LAST_SYNC_OP)) - { - MCA_TRACE_ERROR ("%s() - unsupported SYNC opcode: %d len:%d" - , __func__, *p, p_buf->len); - /* reject unsupported request */ - rej_rsp_code = MCA_RSP_NO_SUPPORT; - } - else - { - MCA_TRACE_ERROR ("%s() - bad opcode: %d len:%d", __func__, *p, p_buf->len); - /* reject unsupported request */ - rej_rsp_code = MCA_RSP_BAD_OPCODE; - } - - p_buf->layer_specific = rej_rsp_code; - /* forward the request/response to state machine */ - mca_ccb_event(p_ccb, event, (tMCA_CCB_EVT *) p_buf); - } /* got a valid ccb */ - else - osi_free(p_buf); - } - /* else send event to dcb */ - else - { - p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); - if (p_dcb != NULL) - { - mca_dcb_event(p_dcb, MCA_DCB_TC_DATA_EVT, (tMCA_DCB_EVT *) p_buf); +void mca_tc_data_ind(tMCA_TC_TBL* p_tbl, BT_HDR* p_buf) { + tMCA_CCB* p_ccb; + tMCA_DCB* p_dcb; + uint8_t event = MCA_CCB_MSG_RSP_EVT; + uint8_t* p; + uint8_t rej_rsp_code = MCA_RSP_SUCCESS; + + MCA_TRACE_DEBUG("%s() - tcid: %d, cb_idx: %d", __func__, p_tbl->tcid, + p_tbl->cb_idx); + + /* if control channel, handle control message */ + if (p_tbl->tcid == MCA_CTRL_TCID) { + p_ccb = mca_ccb_by_hdl((tMCA_CL)p_tbl->cb_idx); + if (p_ccb) { + p = (uint8_t*)(p_buf + 1) + p_buf->offset; + /* all the request opcode has bit 0 set. response code has bit 0 clear */ + if ((*p) & 0x01) event = MCA_CCB_MSG_REQ_EVT; + + if (*p < MCA_NUM_STANDARD_OPCODE) { + if (p_buf->len != mca_std_msg_len[*p]) { + MCA_TRACE_ERROR("$s() - opcode: %d required len: %d, got len: %d", + __func__, *p, mca_std_msg_len[*p], p_buf->len); + rej_rsp_code = MCA_RSP_BAD_PARAM; } - else - osi_free(p_buf); - } + } else if ((*p >= MCA_FIRST_SYNC_OP) && (*p <= MCA_LAST_SYNC_OP)) { + MCA_TRACE_ERROR("%s() - unsupported SYNC opcode: %d len:%d", __func__, + *p, p_buf->len); + /* reject unsupported request */ + rej_rsp_code = MCA_RSP_NO_SUPPORT; + } else { + MCA_TRACE_ERROR("%s() - bad opcode: %d len:%d", __func__, *p, + p_buf->len); + /* reject unsupported request */ + rej_rsp_code = MCA_RSP_BAD_OPCODE; + } + + p_buf->layer_specific = rej_rsp_code; + /* forward the request/response to state machine */ + mca_ccb_event(p_ccb, event, (tMCA_CCB_EVT*)p_buf); + } /* got a valid ccb */ + else + osi_free(p_buf); + } + /* else send event to dcb */ + else { + p_dcb = mca_dcb_by_hdl(p_tbl->cb_idx); + if (p_dcb != NULL) { + mca_dcb_event(p_dcb, MCA_DCB_TC_DATA_EVT, (tMCA_DCB_EVT*)p_buf); + } else + osi_free(p_buf); + } } /******************************************************************************* @@ -513,21 +462,18 @@ void mca_tc_data_ind(tMCA_TC_TBL *p_tbl, BT_HDR *p_buf) * Returns tMCA_RCB * * ******************************************************************************/ -tMCA_RCB * mca_rcb_alloc(tMCA_REG *p_reg) -{ - int i; - tMCA_RCB *p_rcb = NULL; - - for (i=0; ireg, p_reg, sizeof(tMCA_REG)); - break; - } +tMCA_RCB* mca_rcb_alloc(tMCA_REG* p_reg) { + int i; + tMCA_RCB* p_rcb = NULL; + + for (i = 0; i < MCA_NUM_REGS; i++) { + if (mca_cb.rcb[i].p_cback == NULL) { + p_rcb = &mca_cb.rcb[i]; + memcpy(&p_rcb->reg, p_reg, sizeof(tMCA_REG)); + break; } - return p_rcb; + } + return p_rcb; } /******************************************************************************* @@ -539,37 +485,31 @@ tMCA_RCB * mca_rcb_alloc(tMCA_REG *p_reg) * Returns void. * ******************************************************************************/ -void mca_rcb_dealloc(tMCA_HANDLE handle) -{ - int i; - bool done = true; - tMCA_RCB *p_rcb; - tMCA_CCB *p_ccb; - - if (handle && (handle<=MCA_NUM_REGS)) - { - handle--; - p_rcb = &mca_cb.rcb[handle]; - if (p_rcb->p_cback) - { - p_ccb = &mca_cb.ccb[handle*MCA_NUM_LINKS]; - /* check if all associated CCB are disconnected */ - for (i=0; ip_rcb) - { - done = false; - mca_ccb_event (p_ccb, MCA_CCB_API_DISCONNECT_EVT, NULL); - } - } - - if (done) - { - memset (p_rcb, 0, sizeof(tMCA_RCB)); - MCA_TRACE_DEBUG("%s() - reset MCA_RCB index=%d", __func__, handle); - } +void mca_rcb_dealloc(tMCA_HANDLE handle) { + int i; + bool done = true; + tMCA_RCB* p_rcb; + tMCA_CCB* p_ccb; + + if (handle && (handle <= MCA_NUM_REGS)) { + handle--; + p_rcb = &mca_cb.rcb[handle]; + if (p_rcb->p_cback) { + p_ccb = &mca_cb.ccb[handle * MCA_NUM_LINKS]; + /* check if all associated CCB are disconnected */ + for (i = 0; i < MCA_NUM_LINKS; i++, p_ccb++) { + if (p_ccb->p_rcb) { + done = false; + mca_ccb_event(p_ccb, MCA_CCB_API_DISCONNECT_EVT, NULL); } + } + + if (done) { + memset(p_rcb, 0, sizeof(tMCA_RCB)); + MCA_TRACE_DEBUG("%s() - reset MCA_RCB index=%d", __func__, handle); + } } + } } /******************************************************************************* @@ -582,9 +522,8 @@ void mca_rcb_dealloc(tMCA_HANDLE handle) * Returns void. * ******************************************************************************/ -tMCA_HANDLE mca_rcb_to_handle(tMCA_RCB *p_rcb) -{ - return(uint8_t) (p_rcb - mca_cb.rcb + 1); +tMCA_HANDLE mca_rcb_to_handle(tMCA_RCB* p_rcb) { + return (uint8_t)(p_rcb - mca_cb.rcb + 1); } /******************************************************************************* @@ -598,15 +537,13 @@ tMCA_HANDLE mca_rcb_to_handle(tMCA_RCB *p_rcb) * Returns tMCA_RCB * * ******************************************************************************/ -tMCA_RCB *mca_rcb_by_handle(tMCA_HANDLE handle) -{ - tMCA_RCB *p_rcb = NULL; +tMCA_RCB* mca_rcb_by_handle(tMCA_HANDLE handle) { + tMCA_RCB* p_rcb = NULL; - if (handle && (handle<=MCA_NUM_REGS) && mca_cb.rcb[handle-1].p_cback) - { - p_rcb = &mca_cb.rcb[handle-1]; - } - return p_rcb; + if (handle && (handle <= MCA_NUM_REGS) && mca_cb.rcb[handle - 1].p_cback) { + p_rcb = &mca_cb.rcb[handle - 1]; + } + return p_rcb; } /******************************************************************************* @@ -618,12 +555,10 @@ tMCA_RCB *mca_rcb_by_handle(tMCA_HANDLE handle) * Returns true, if this is a valid local dep_id * ******************************************************************************/ -bool mca_is_valid_dep_id(tMCA_RCB *p_rcb, tMCA_DEP dep) -{ - bool valid = false; - if (dep < MCA_NUM_DEPS && p_rcb->dep[dep].p_data_cback) - { - valid = true; - } - return valid; +bool mca_is_valid_dep_id(tMCA_RCB* p_rcb, tMCA_DEP dep) { + bool valid = false; + if (dep < MCA_NUM_DEPS && p_rcb->dep[dep].p_data_cback) { + valid = true; + } + return valid; } diff --git a/stack/pan/pan_api.cc b/stack/pan/pan_api.cc index a340c3a8d..997d7c907 100644 --- a/stack/pan/pan_api.cc +++ b/stack/pan/pan_api.cc @@ -23,19 +23,18 @@ * *****************************************************************************/ +#include "pan_api.h" #include +#include "bnep_api.h" #include "bt_common.h" #include "bt_types.h" -#include "bnep_api.h" -#include "pan_api.h" +#include "bta_sys.h" +#include "btm_api.h" +#include "hcidefs.h" +#include "l2c_api.h" #include "pan_int.h" #include "sdp_api.h" #include "sdpdefs.h" -#include "l2c_api.h" -#include "hcidefs.h" -#include "btm_api.h" -#include "bta_sys.h" - /******************************************************************************* * @@ -51,29 +50,25 @@ * Returns none * ******************************************************************************/ -void PAN_Register (tPAN_REGISTER *p_register) -{ - BTM_SetDiscoverability (BTM_GENERAL_DISCOVERABLE, 0, 0); - BTM_SetConnectability (BTM_CONNECTABLE, 0, 0); +void PAN_Register(tPAN_REGISTER* p_register) { + BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, 0, 0); + BTM_SetConnectability(BTM_CONNECTABLE, 0, 0); - pan_register_with_bnep (); + pan_register_with_bnep(); - if (!p_register) - return; + if (!p_register) return; - pan_cb.pan_conn_state_cb = p_register->pan_conn_state_cb; - pan_cb.pan_bridge_req_cb = p_register->pan_bridge_req_cb; - pan_cb.pan_data_buf_ind_cb = p_register->pan_data_buf_ind_cb; - pan_cb.pan_data_ind_cb = p_register->pan_data_ind_cb; - pan_cb.pan_pfilt_ind_cb = p_register->pan_pfilt_ind_cb; - pan_cb.pan_mfilt_ind_cb = p_register->pan_mfilt_ind_cb; - pan_cb.pan_tx_data_flow_cb = p_register->pan_tx_data_flow_cb; + pan_cb.pan_conn_state_cb = p_register->pan_conn_state_cb; + pan_cb.pan_bridge_req_cb = p_register->pan_bridge_req_cb; + pan_cb.pan_data_buf_ind_cb = p_register->pan_data_buf_ind_cb; + pan_cb.pan_data_ind_cb = p_register->pan_data_ind_cb; + pan_cb.pan_pfilt_ind_cb = p_register->pan_pfilt_ind_cb; + pan_cb.pan_mfilt_ind_cb = p_register->pan_mfilt_ind_cb; + pan_cb.pan_tx_data_flow_cb = p_register->pan_tx_data_flow_cb; - return; + return; } - - /******************************************************************************* * * Function PAN_Deregister @@ -89,24 +84,20 @@ void PAN_Register (tPAN_REGISTER *p_register) * Returns none * ******************************************************************************/ -void PAN_Deregister (void) -{ - pan_cb.pan_bridge_req_cb = NULL; - pan_cb.pan_data_buf_ind_cb = NULL; - pan_cb.pan_data_ind_cb = NULL; - pan_cb.pan_conn_state_cb = NULL; - pan_cb.pan_pfilt_ind_cb = NULL; - pan_cb.pan_mfilt_ind_cb = NULL; - - PAN_SetRole (PAN_ROLE_INACTIVE, NULL, NULL, NULL, NULL); - BNEP_Deregister (); - - return; +void PAN_Deregister(void) { + pan_cb.pan_bridge_req_cb = NULL; + pan_cb.pan_data_buf_ind_cb = NULL; + pan_cb.pan_data_ind_cb = NULL; + pan_cb.pan_conn_state_cb = NULL; + pan_cb.pan_pfilt_ind_cb = NULL; + pan_cb.pan_mfilt_ind_cb = NULL; + + PAN_SetRole(PAN_ROLE_INACTIVE, NULL, NULL, NULL, NULL); + BNEP_Deregister(); + + return; } - - - /******************************************************************************* * * Function PAN_SetRole @@ -132,134 +123,122 @@ void PAN_Deregister (void) * PAN_FAILURE - if the role is not valid * ******************************************************************************/ -tPAN_RESULT PAN_SetRole (uint8_t role, - uint8_t *sec_mask, - const char *p_user_name, - const char *p_gn_name, - const char *p_nap_name) -{ - const char *p_desc; - uint8_t security[3] = {PAN_PANU_SECURITY_LEVEL, - PAN_GN_SECURITY_LEVEL, - PAN_NAP_SECURITY_LEVEL}; - uint8_t *p_sec; - - /* If the role is not a valid combination reject it */ - if ((!(role & (PAN_ROLE_CLIENT | PAN_ROLE_GN_SERVER | PAN_ROLE_NAP_SERVER))) && - role != PAN_ROLE_INACTIVE) - { - PAN_TRACE_ERROR ("PAN role %d is invalid", role); - return PAN_FAILURE; - } - - /* If the current active role is same as the role being set do nothing */ - if (pan_cb.role == role) - { - PAN_TRACE_EVENT ("PAN role already was set to: %d", role); - return PAN_SUCCESS; - } +tPAN_RESULT PAN_SetRole(uint8_t role, uint8_t* sec_mask, + const char* p_user_name, const char* p_gn_name, + const char* p_nap_name) { + const char* p_desc; + uint8_t security[3] = {PAN_PANU_SECURITY_LEVEL, PAN_GN_SECURITY_LEVEL, + PAN_NAP_SECURITY_LEVEL}; + uint8_t* p_sec; + + /* If the role is not a valid combination reject it */ + if ((!(role & + (PAN_ROLE_CLIENT | PAN_ROLE_GN_SERVER | PAN_ROLE_NAP_SERVER))) && + role != PAN_ROLE_INACTIVE) { + PAN_TRACE_ERROR("PAN role %d is invalid", role); + return PAN_FAILURE; + } + + /* If the current active role is same as the role being set do nothing */ + if (pan_cb.role == role) { + PAN_TRACE_EVENT("PAN role already was set to: %d", role); + return PAN_SUCCESS; + } - if (!sec_mask) - p_sec = security; - else - p_sec = sec_mask; + if (!sec_mask) + p_sec = security; + else + p_sec = sec_mask; - /* Register all the roles with SDP */ - PAN_TRACE_API ("PAN_SetRole() called with role 0x%x", role); + /* Register all the roles with SDP */ + PAN_TRACE_API("PAN_SetRole() called with role 0x%x", role); #if (PAN_SUPPORTS_ROLE_NAP == TRUE) - if (role & PAN_ROLE_NAP_SERVER) - { - /* Check the service name */ - if ((p_nap_name == NULL) || (*p_nap_name == 0)) - p_nap_name = PAN_NAP_DEFAULT_SERVICE_NAME; - - /* Registering for NAP service with SDP */ - p_desc = PAN_NAP_DEFAULT_DESCRIPTION; - - if (pan_cb.pan_nap_sdp_handle != 0) - SDP_DeleteRecord (pan_cb.pan_nap_sdp_handle); - - pan_cb.pan_nap_sdp_handle = pan_register_with_sdp (UUID_SERVCLASS_NAP, p_sec[2], p_nap_name, p_desc); - bta_sys_add_uuid(UUID_SERVCLASS_NAP); - } - /* If the NAP role is already active and now being cleared delete the record */ - else if (pan_cb.role & PAN_ROLE_NAP_SERVER) - { - if (pan_cb.pan_nap_sdp_handle != 0) - { - SDP_DeleteRecord (pan_cb.pan_nap_sdp_handle); - pan_cb.pan_nap_sdp_handle = 0; - bta_sys_remove_uuid(UUID_SERVCLASS_NAP); - } - } + if (role & PAN_ROLE_NAP_SERVER) { + /* Check the service name */ + if ((p_nap_name == NULL) || (*p_nap_name == 0)) + p_nap_name = PAN_NAP_DEFAULT_SERVICE_NAME; + + /* Registering for NAP service with SDP */ + p_desc = PAN_NAP_DEFAULT_DESCRIPTION; + + if (pan_cb.pan_nap_sdp_handle != 0) + SDP_DeleteRecord(pan_cb.pan_nap_sdp_handle); + + pan_cb.pan_nap_sdp_handle = + pan_register_with_sdp(UUID_SERVCLASS_NAP, p_sec[2], p_nap_name, p_desc); + bta_sys_add_uuid(UUID_SERVCLASS_NAP); + } + /* If the NAP role is already active and now being cleared delete the record + */ + else if (pan_cb.role & PAN_ROLE_NAP_SERVER) { + if (pan_cb.pan_nap_sdp_handle != 0) { + SDP_DeleteRecord(pan_cb.pan_nap_sdp_handle); + pan_cb.pan_nap_sdp_handle = 0; + bta_sys_remove_uuid(UUID_SERVCLASS_NAP); + } + } #endif #if (PAN_SUPPORTS_ROLE_GN == TRUE) - if (role & PAN_ROLE_GN_SERVER) - { - /* Check the service name */ - if ((p_gn_name == NULL) || (*p_gn_name == 0)) - p_gn_name = PAN_GN_DEFAULT_SERVICE_NAME; - - /* Registering for GN service with SDP */ - p_desc = PAN_GN_DEFAULT_DESCRIPTION; - - if (pan_cb.pan_gn_sdp_handle != 0) - SDP_DeleteRecord (pan_cb.pan_gn_sdp_handle); - - pan_cb.pan_gn_sdp_handle = pan_register_with_sdp (UUID_SERVCLASS_GN, p_sec[1], p_gn_name, p_desc); - bta_sys_add_uuid(UUID_SERVCLASS_GN); - } - /* If the GN role is already active and now being cleared delete the record */ - else if (pan_cb.role & PAN_ROLE_GN_SERVER) - { - if (pan_cb.pan_gn_sdp_handle != 0) - { - SDP_DeleteRecord (pan_cb.pan_gn_sdp_handle); - pan_cb.pan_gn_sdp_handle = 0; - bta_sys_remove_uuid(UUID_SERVCLASS_GN); - } - } + if (role & PAN_ROLE_GN_SERVER) { + /* Check the service name */ + if ((p_gn_name == NULL) || (*p_gn_name == 0)) + p_gn_name = PAN_GN_DEFAULT_SERVICE_NAME; + + /* Registering for GN service with SDP */ + p_desc = PAN_GN_DEFAULT_DESCRIPTION; + + if (pan_cb.pan_gn_sdp_handle != 0) + SDP_DeleteRecord(pan_cb.pan_gn_sdp_handle); + + pan_cb.pan_gn_sdp_handle = + pan_register_with_sdp(UUID_SERVCLASS_GN, p_sec[1], p_gn_name, p_desc); + bta_sys_add_uuid(UUID_SERVCLASS_GN); + } + /* If the GN role is already active and now being cleared delete the record */ + else if (pan_cb.role & PAN_ROLE_GN_SERVER) { + if (pan_cb.pan_gn_sdp_handle != 0) { + SDP_DeleteRecord(pan_cb.pan_gn_sdp_handle); + pan_cb.pan_gn_sdp_handle = 0; + bta_sys_remove_uuid(UUID_SERVCLASS_GN); + } + } #endif #if (PAN_SUPPORTS_ROLE_PANU == TRUE) - if (role & PAN_ROLE_CLIENT) - { - /* Check the service name */ - if ((p_user_name == NULL) || (*p_user_name == 0)) - p_user_name = PAN_PANU_DEFAULT_SERVICE_NAME; - - /* Registering for PANU service with SDP */ - p_desc = PAN_PANU_DEFAULT_DESCRIPTION; - if (pan_cb.pan_user_sdp_handle != 0) - SDP_DeleteRecord (pan_cb.pan_user_sdp_handle); - - pan_cb.pan_user_sdp_handle = pan_register_with_sdp (UUID_SERVCLASS_PANU, p_sec[0], p_user_name, p_desc); - bta_sys_add_uuid(UUID_SERVCLASS_PANU); - } - /* If the PANU role is already active and now being cleared delete the record */ - else if (pan_cb.role & PAN_ROLE_CLIENT) - { - if (pan_cb.pan_user_sdp_handle != 0) - { - SDP_DeleteRecord (pan_cb.pan_user_sdp_handle); - pan_cb.pan_user_sdp_handle = 0; - bta_sys_remove_uuid(UUID_SERVCLASS_PANU); - } - } + if (role & PAN_ROLE_CLIENT) { + /* Check the service name */ + if ((p_user_name == NULL) || (*p_user_name == 0)) + p_user_name = PAN_PANU_DEFAULT_SERVICE_NAME; + + /* Registering for PANU service with SDP */ + p_desc = PAN_PANU_DEFAULT_DESCRIPTION; + if (pan_cb.pan_user_sdp_handle != 0) + SDP_DeleteRecord(pan_cb.pan_user_sdp_handle); + + pan_cb.pan_user_sdp_handle = pan_register_with_sdp( + UUID_SERVCLASS_PANU, p_sec[0], p_user_name, p_desc); + bta_sys_add_uuid(UUID_SERVCLASS_PANU); + } + /* If the PANU role is already active and now being cleared delete the record + */ + else if (pan_cb.role & PAN_ROLE_CLIENT) { + if (pan_cb.pan_user_sdp_handle != 0) { + SDP_DeleteRecord(pan_cb.pan_user_sdp_handle); + pan_cb.pan_user_sdp_handle = 0; + bta_sys_remove_uuid(UUID_SERVCLASS_PANU); + } + } #endif - /* Check if it is a shutdown request */ - if (role == PAN_ROLE_INACTIVE) - pan_close_all_connections (); + /* Check if it is a shutdown request */ + if (role == PAN_ROLE_INACTIVE) pan_close_all_connections(); - pan_cb.role = role; - PAN_TRACE_EVENT ("PAN role set to: %d", role); - return PAN_SUCCESS; + pan_cb.role = role; + PAN_TRACE_EVENT("PAN role set to: %d", role); + return PAN_SUCCESS; } - - /******************************************************************************* * * Function PAN_Connect @@ -284,145 +263,126 @@ tPAN_RESULT PAN_SetRole (uint8_t role, * allowed at that point of time * ******************************************************************************/ -tPAN_RESULT PAN_Connect (BD_ADDR rem_bda, uint8_t src_role, uint8_t dst_role, uint16_t *handle) -{ - tPAN_CONN *pcb; - tBNEP_RESULT result; - tBT_UUID src_uuid, dst_uuid; - uint32_t mx_chan_id; - - /* - ** Initialize the handle so that in case of failure return values - ** the profile will not get confused - */ - *handle = BNEP_INVALID_HANDLE; - - /* Check if PAN is active or not */ - if (!(pan_cb.role & src_role)) - { - PAN_TRACE_ERROR ("PAN is not active for the role %d", src_role); - return PAN_FAILURE; - } - - /* Validate the parameters before proceeding */ - if ((src_role != PAN_ROLE_CLIENT && src_role != PAN_ROLE_GN_SERVER && src_role != PAN_ROLE_NAP_SERVER) || - (dst_role != PAN_ROLE_CLIENT && dst_role != PAN_ROLE_GN_SERVER && dst_role != PAN_ROLE_NAP_SERVER)) - { - PAN_TRACE_ERROR ("Either source %d or destination role %d is invalid", src_role, dst_role); - return PAN_FAILURE; - } - - /* Check if connection exists for this remote device */ - pcb = pan_get_pcb_by_addr (rem_bda); - - /* If we are PANU for this role validate destination role */ - if (src_role == PAN_ROLE_CLIENT) - { - if ((pan_cb.num_conns > 1) || (pan_cb.num_conns && (!pcb))) - { - /* - ** If the request is not for existing connection reject it - ** because if there is already a connection we cannot accept - ** another connection in PANU role - */ - PAN_TRACE_ERROR ("Cannot make PANU connections when there are more than one connection"); - return PAN_INVALID_SRC_ROLE; - } - - src_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; - if (dst_role == PAN_ROLE_CLIENT) - { - dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; - } - else if (dst_role == PAN_ROLE_GN_SERVER) - { - dst_uuid.uu.uuid16 = UUID_SERVCLASS_GN; - } - else - { - dst_uuid.uu.uuid16 = UUID_SERVCLASS_NAP; - } - mx_chan_id = dst_uuid.uu.uuid16; - } - /* If destination is PANU role validate source role */ - else if (dst_role == PAN_ROLE_CLIENT) - { - if (pan_cb.num_conns && pan_cb.active_role == PAN_ROLE_CLIENT && !pcb) - { - PAN_TRACE_ERROR ("Device already have a connection in PANU role"); - return PAN_INVALID_SRC_ROLE; - } - - dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; - if (src_role == PAN_ROLE_GN_SERVER) - { - src_uuid.uu.uuid16 = UUID_SERVCLASS_GN; - } - else - { - src_uuid.uu.uuid16 = UUID_SERVCLASS_NAP; - } - mx_chan_id = src_uuid.uu.uuid16; - } - /* The role combination is not valid */ - else - { - PAN_TRACE_ERROR ("Source %d and Destination roles %d are not valid combination", - src_role, dst_role); - return PAN_FAILURE; - } - - /* Allocate control block and initiate connection */ - if (!pcb) - pcb = pan_allocate_pcb (rem_bda, BNEP_INVALID_HANDLE); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN Connection failed because of no resources"); - return PAN_NO_RESOURCES; - } - BTM_SetOutService(rem_bda, BTM_SEC_SERVICE_BNEP_PANU, mx_chan_id); - - PAN_TRACE_API ("PAN_Connect() for BD Addr %x.%x.%x.%x.%x.%x", - rem_bda[0], rem_bda[1], rem_bda[2], rem_bda[3], rem_bda[4], rem_bda[5]); - if (pcb->con_state == PAN_STATE_IDLE) - { - pan_cb.num_conns++; - } - else if (pcb->con_state == PAN_STATE_CONNECTED) - { - pcb->con_flags |= PAN_FLAGS_CONN_COMPLETED; - } - else - /* PAN connection is still in progress */ - return PAN_WRONG_STATE; - - pcb->con_state = PAN_STATE_CONN_START; - pcb->prv_src_uuid = pcb->src_uuid; - pcb->prv_dst_uuid = pcb->dst_uuid; - - pcb->src_uuid = src_uuid.uu.uuid16; - pcb->dst_uuid = dst_uuid.uu.uuid16; - - src_uuid.len = 2; - dst_uuid.len = 2; - - result = BNEP_Connect (rem_bda, &src_uuid, &dst_uuid, &(pcb->handle)); - if (result != BNEP_SUCCESS) - { - pan_release_pcb (pcb); - return result; - } - - PAN_TRACE_DEBUG ("PAN_Connect() current active role set to %d", src_role); - pan_cb.prv_active_role = pan_cb.active_role; - pan_cb.active_role = src_role; - *handle = pcb->handle; - return PAN_SUCCESS; +tPAN_RESULT PAN_Connect(BD_ADDR rem_bda, uint8_t src_role, uint8_t dst_role, + uint16_t* handle) { + tPAN_CONN* pcb; + tBNEP_RESULT result; + tBT_UUID src_uuid, dst_uuid; + uint32_t mx_chan_id; + + /* + ** Initialize the handle so that in case of failure return values + ** the profile will not get confused + */ + *handle = BNEP_INVALID_HANDLE; + + /* Check if PAN is active or not */ + if (!(pan_cb.role & src_role)) { + PAN_TRACE_ERROR("PAN is not active for the role %d", src_role); + return PAN_FAILURE; + } + + /* Validate the parameters before proceeding */ + if ((src_role != PAN_ROLE_CLIENT && src_role != PAN_ROLE_GN_SERVER && + src_role != PAN_ROLE_NAP_SERVER) || + (dst_role != PAN_ROLE_CLIENT && dst_role != PAN_ROLE_GN_SERVER && + dst_role != PAN_ROLE_NAP_SERVER)) { + PAN_TRACE_ERROR("Either source %d or destination role %d is invalid", + src_role, dst_role); + return PAN_FAILURE; + } + + /* Check if connection exists for this remote device */ + pcb = pan_get_pcb_by_addr(rem_bda); + + /* If we are PANU for this role validate destination role */ + if (src_role == PAN_ROLE_CLIENT) { + if ((pan_cb.num_conns > 1) || (pan_cb.num_conns && (!pcb))) { + /* + ** If the request is not for existing connection reject it + ** because if there is already a connection we cannot accept + ** another connection in PANU role + */ + PAN_TRACE_ERROR( + "Cannot make PANU connections when there are more than one " + "connection"); + return PAN_INVALID_SRC_ROLE; + } + + src_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; + if (dst_role == PAN_ROLE_CLIENT) { + dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; + } else if (dst_role == PAN_ROLE_GN_SERVER) { + dst_uuid.uu.uuid16 = UUID_SERVCLASS_GN; + } else { + dst_uuid.uu.uuid16 = UUID_SERVCLASS_NAP; + } + mx_chan_id = dst_uuid.uu.uuid16; + } + /* If destination is PANU role validate source role */ + else if (dst_role == PAN_ROLE_CLIENT) { + if (pan_cb.num_conns && pan_cb.active_role == PAN_ROLE_CLIENT && !pcb) { + PAN_TRACE_ERROR("Device already have a connection in PANU role"); + return PAN_INVALID_SRC_ROLE; + } + + dst_uuid.uu.uuid16 = UUID_SERVCLASS_PANU; + if (src_role == PAN_ROLE_GN_SERVER) { + src_uuid.uu.uuid16 = UUID_SERVCLASS_GN; + } else { + src_uuid.uu.uuid16 = UUID_SERVCLASS_NAP; + } + mx_chan_id = src_uuid.uu.uuid16; + } + /* The role combination is not valid */ + else { + PAN_TRACE_ERROR( + "Source %d and Destination roles %d are not valid combination", + src_role, dst_role); + return PAN_FAILURE; + } + + /* Allocate control block and initiate connection */ + if (!pcb) pcb = pan_allocate_pcb(rem_bda, BNEP_INVALID_HANDLE); + if (!pcb) { + PAN_TRACE_ERROR("PAN Connection failed because of no resources"); + return PAN_NO_RESOURCES; + } + BTM_SetOutService(rem_bda, BTM_SEC_SERVICE_BNEP_PANU, mx_chan_id); + + PAN_TRACE_API("PAN_Connect() for BD Addr %x.%x.%x.%x.%x.%x", rem_bda[0], + rem_bda[1], rem_bda[2], rem_bda[3], rem_bda[4], rem_bda[5]); + if (pcb->con_state == PAN_STATE_IDLE) { + pan_cb.num_conns++; + } else if (pcb->con_state == PAN_STATE_CONNECTED) { + pcb->con_flags |= PAN_FLAGS_CONN_COMPLETED; + } else + /* PAN connection is still in progress */ + return PAN_WRONG_STATE; + + pcb->con_state = PAN_STATE_CONN_START; + pcb->prv_src_uuid = pcb->src_uuid; + pcb->prv_dst_uuid = pcb->dst_uuid; + + pcb->src_uuid = src_uuid.uu.uuid16; + pcb->dst_uuid = dst_uuid.uu.uuid16; + + src_uuid.len = 2; + dst_uuid.len = 2; + + result = BNEP_Connect(rem_bda, &src_uuid, &dst_uuid, &(pcb->handle)); + if (result != BNEP_SUCCESS) { + pan_release_pcb(pcb); + return result; + } + + PAN_TRACE_DEBUG("PAN_Connect() current active role set to %d", src_role); + pan_cb.prv_active_role = pan_cb.active_role; + pan_cb.active_role = src_role; + *handle = pcb->handle; + return PAN_SUCCESS; } - - - /******************************************************************************* * * Function PAN_Disconnect @@ -436,38 +396,33 @@ tPAN_RESULT PAN_Connect (BD_ADDR rem_bda, uint8_t src_role, uint8_t dst_role, ui * there is an error in disconnecting * ******************************************************************************/ -tPAN_RESULT PAN_Disconnect (uint16_t handle) -{ - tPAN_CONN *pcb; - tBNEP_RESULT result; - - /* Check if the connection exists */ - pcb = pan_get_pcb_by_handle (handle); - if(!pcb) - { - PAN_TRACE_ERROR ("PAN connection not found for the handle %d", handle); - return PAN_FAILURE; - } +tPAN_RESULT PAN_Disconnect(uint16_t handle) { + tPAN_CONN* pcb; + tBNEP_RESULT result; - result = BNEP_Disconnect (pcb->handle); - if (pcb->con_state != PAN_STATE_IDLE) - pan_cb.num_conns--; + /* Check if the connection exists */ + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN connection not found for the handle %d", handle); + return PAN_FAILURE; + } - if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP) - (*pan_cb.pan_bridge_req_cb) (pcb->rem_bda, false); + result = BNEP_Disconnect(pcb->handle); + if (pcb->con_state != PAN_STATE_IDLE) pan_cb.num_conns--; - pan_release_pcb (pcb); + if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP) + (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false); - if (result != BNEP_SUCCESS) - { - PAN_TRACE_EVENT ("Error in closing PAN connection"); - return PAN_FAILURE; - } + pan_release_pcb(pcb); - PAN_TRACE_EVENT ("PAN connection closed"); - return PAN_SUCCESS; -} + if (result != BNEP_SUCCESS) { + PAN_TRACE_EVENT("Error in closing PAN connection"); + return PAN_FAILURE; + } + PAN_TRACE_EVENT("PAN connection closed"); + return PAN_SUCCESS; +} /******************************************************************************* * @@ -492,35 +447,36 @@ tPAN_RESULT PAN_Disconnect (uint16_t handle) * there is an error in sending data * ******************************************************************************/ -tPAN_RESULT PAN_Write(uint16_t handle, BD_ADDR dst, BD_ADDR src, uint16_t protocol, uint8_t *p_data, uint16_t len, bool ext) -{ - if (pan_cb.role == PAN_ROLE_INACTIVE || !pan_cb.num_conns) { - PAN_TRACE_ERROR("%s PAN is not active, data write failed.", __func__); - return PAN_FAILURE; - } - - // If the packet is broadcast or multicast, we're going to have to create - // a copy of the packet for each connection. We can save one extra copy - // by fast-pathing here and calling BNEP_Write instead of placing the packet - // in a BT_HDR buffer, calling BNEP_Write, and then freeing the buffer. - if (dst[0] & 0x01) { - int i; - for (i = 0; i < MAX_PAN_CONNS; ++i) { - if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED) - BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); - } - return PAN_SUCCESS; +tPAN_RESULT PAN_Write(uint16_t handle, BD_ADDR dst, BD_ADDR src, + uint16_t protocol, uint8_t* p_data, uint16_t len, + bool ext) { + if (pan_cb.role == PAN_ROLE_INACTIVE || !pan_cb.num_conns) { + PAN_TRACE_ERROR("%s PAN is not active, data write failed.", __func__); + return PAN_FAILURE; + } + + // If the packet is broadcast or multicast, we're going to have to create + // a copy of the packet for each connection. We can save one extra copy + // by fast-pathing here and calling BNEP_Write instead of placing the packet + // in a BT_HDR buffer, calling BNEP_Write, and then freeing the buffer. + if (dst[0] & 0x01) { + int i; + for (i = 0; i < MAX_PAN_CONNS; ++i) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED) + BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); } + return PAN_SUCCESS; + } - BT_HDR *buffer = (BT_HDR *)osi_malloc(PAN_BUF_SIZE); - buffer->len = len; - buffer->offset = PAN_MINIMUM_OFFSET; - memcpy((uint8_t *)buffer + sizeof(BT_HDR) + buffer->offset, p_data, buffer->len); + BT_HDR* buffer = (BT_HDR*)osi_malloc(PAN_BUF_SIZE); + buffer->len = len; + buffer->offset = PAN_MINIMUM_OFFSET; + memcpy((uint8_t*)buffer + sizeof(BT_HDR) + buffer->offset, p_data, + buffer->len); - return PAN_WriteBuf(handle, dst, src, protocol, buffer, ext); + return PAN_WriteBuf(handle, dst, src, protocol, buffer, ext); } - /******************************************************************************* * * Function PAN_WriteBuf @@ -544,98 +500,86 @@ tPAN_RESULT PAN_Write(uint16_t handle, BD_ADDR dst, BD_ADDR src, uint16_t protoc * there is an error in sending data * ******************************************************************************/ -tPAN_RESULT PAN_WriteBuf (uint16_t handle, BD_ADDR dst, BD_ADDR src, uint16_t protocol, BT_HDR *p_buf, bool ext) -{ - tPAN_CONN *pcb; - uint16_t i; - tBNEP_RESULT result; - - if (pan_cb.role == PAN_ROLE_INACTIVE || (!(pan_cb.num_conns))) - { - PAN_TRACE_ERROR ("PAN is not active Data write failed"); - osi_free(p_buf); - return PAN_FAILURE; - } - - /* Check if it is broadcast or multicast packet */ - if (dst[0] & 0x01) - { - uint8_t *data = (uint8_t *)p_buf + sizeof(BT_HDR) + p_buf->offset; - for (i = 0; i < MAX_PAN_CONNS; ++i) { - if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED) - BNEP_Write(pan_cb.pcb[i].handle, dst, data, p_buf->len, protocol, src, ext); - } - osi_free(p_buf); - return PAN_SUCCESS; - } - - /* Check if the data write is on PANU side */ - if (pan_cb.active_role == PAN_ROLE_CLIENT) - { - /* Data write is on PANU connection */ - for (i=0; ioffset; + for (i = 0; i < MAX_PAN_CONNS; ++i) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED) + BNEP_Write(pan_cb.pcb[i].handle, dst, data, p_buf->len, protocol, src, + ext); + } + osi_free(p_buf); + return PAN_SUCCESS; + } - /* findout to which connection the data is meant for */ - pcb = pan_get_pcb_by_handle (handle); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN Buf write for wrong handle"); - osi_free(p_buf); - return PAN_FAILURE; + /* Check if the data write is on PANU side */ + if (pan_cb.active_role == PAN_ROLE_CLIENT) { + /* Data write is on PANU connection */ + for (i = 0; i < MAX_PAN_CONNS; i++) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED && + pan_cb.pcb[i].src_uuid == UUID_SERVCLASS_PANU) + break; } - if (pcb->con_state != PAN_STATE_CONNECTED) - { - PAN_TRACE_ERROR ("PAN Buf write when conn is not active"); - osi_free(p_buf); - return PAN_FAILURE; + if (i == MAX_PAN_CONNS) { + PAN_TRACE_ERROR("PAN Don't have any user connections"); + osi_free(p_buf); + return PAN_FAILURE; } - result = BNEP_WriteBuf (pcb->handle, dst, p_buf, protocol, src, ext); - if (result == BNEP_IGNORE_CMD) - { - PAN_TRACE_DEBUG ("PAN ignored data buf write to PANU"); - return result; - } - else if (result != BNEP_SUCCESS) - { - PAN_TRACE_ERROR ("PAN failed to send data buf to the PANU"); - return result; + result = + BNEP_WriteBuf(pan_cb.pcb[i].handle, dst, p_buf, protocol, src, ext); + if (result == BNEP_IGNORE_CMD) { + PAN_TRACE_DEBUG("PAN ignored data write for PANU connection"); + return result; + } else if (result != BNEP_SUCCESS) { + PAN_TRACE_ERROR("PAN failed to write data for the PANU connection"); + return result; } - PAN_TRACE_DEBUG ("PAN successfully sent data buf to the PANU"); + PAN_TRACE_DEBUG("PAN successfully wrote data for the PANU connection"); return PAN_SUCCESS; + } + + /* findout to which connection the data is meant for */ + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN Buf write for wrong handle"); + osi_free(p_buf); + return PAN_FAILURE; + } + + if (pcb->con_state != PAN_STATE_CONNECTED) { + PAN_TRACE_ERROR("PAN Buf write when conn is not active"); + osi_free(p_buf); + return PAN_FAILURE; + } + + result = BNEP_WriteBuf(pcb->handle, dst, p_buf, protocol, src, ext); + if (result == BNEP_IGNORE_CMD) { + PAN_TRACE_DEBUG("PAN ignored data buf write to PANU"); + return result; + } else if (result != BNEP_SUCCESS) { + PAN_TRACE_ERROR("PAN failed to send data buf to the PANU"); + return result; + } + + PAN_TRACE_DEBUG("PAN successfully sent data buf to the PANU"); + return PAN_SUCCESS; } - /******************************************************************************* * * Function PAN_SetProtocolFilters @@ -652,35 +596,30 @@ tPAN_RESULT PAN_WriteBuf (uint16_t handle, BD_ADDR dst, BD_ADDR src, uint16_t pr * PAN_FAILURE if connection not found or error in setting * ******************************************************************************/ -tPAN_RESULT PAN_SetProtocolFilters (uint16_t handle, - uint16_t num_filters, - uint16_t *p_start_array, - uint16_t *p_end_array) -{ - tPAN_CONN *pcb; - tPAN_RESULT result; - - /* Check if the connection exists */ - pcb = pan_get_pcb_by_handle (handle); - if(!pcb) - { - PAN_TRACE_ERROR ("PAN connection not found for the handle %d", handle); - return PAN_FAILURE; - } - - result = BNEP_SetProtocolFilters (pcb->handle, num_filters, p_start_array, p_end_array); - if (result != BNEP_SUCCESS) - { - PAN_TRACE_ERROR ("PAN failed to set protocol filters for handle %d", handle); - return result; - } - - PAN_TRACE_API ("PAN successfully sent protocol filters for handle %d", handle); - return PAN_SUCCESS; +tPAN_RESULT PAN_SetProtocolFilters(uint16_t handle, uint16_t num_filters, + uint16_t* p_start_array, + uint16_t* p_end_array) { + tPAN_CONN* pcb; + tPAN_RESULT result; + + /* Check if the connection exists */ + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN connection not found for the handle %d", handle); + return PAN_FAILURE; + } + + result = BNEP_SetProtocolFilters(pcb->handle, num_filters, p_start_array, + p_end_array); + if (result != BNEP_SUCCESS) { + PAN_TRACE_ERROR("PAN failed to set protocol filters for handle %d", handle); + return result; + } + + PAN_TRACE_API("PAN successfully sent protocol filters for handle %d", handle); + return PAN_SUCCESS; } - - /******************************************************************************* * * Function PAN_SetMulticastFilters @@ -697,35 +636,33 @@ tPAN_RESULT PAN_SetProtocolFilters (uint16_t handle, * PAN_FAILURE if connection not found or error in setting * ******************************************************************************/ -tBNEP_RESULT PAN_SetMulticastFilters (uint16_t handle, - uint16_t num_mcast_filters, - uint8_t *p_start_array, - uint8_t *p_end_array) -{ - tPAN_CONN *pcb; - tPAN_RESULT result; - - /* Check if the connection exists */ - pcb = pan_get_pcb_by_handle (handle); - if(!pcb) - { - PAN_TRACE_ERROR ("PAN connection not found for the handle %d", handle); - return PAN_FAILURE; - } - - result = BNEP_SetMulticastFilters (pcb->handle, - num_mcast_filters, p_start_array, p_end_array); - if (result != BNEP_SUCCESS) - { - PAN_TRACE_ERROR ("PAN failed to set multicast filters for handle %d", handle); - return result; - } - - PAN_TRACE_API ("PAN successfully sent multicast filters for handle %d", handle); - return PAN_SUCCESS; +tBNEP_RESULT PAN_SetMulticastFilters(uint16_t handle, + uint16_t num_mcast_filters, + uint8_t* p_start_array, + uint8_t* p_end_array) { + tPAN_CONN* pcb; + tPAN_RESULT result; + + /* Check if the connection exists */ + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN connection not found for the handle %d", handle); + return PAN_FAILURE; + } + + result = BNEP_SetMulticastFilters(pcb->handle, num_mcast_filters, + p_start_array, p_end_array); + if (result != BNEP_SUCCESS) { + PAN_TRACE_ERROR("PAN failed to set multicast filters for handle %d", + handle); + return result; + } + + PAN_TRACE_API("PAN successfully sent multicast filters for handle %d", + handle); + return PAN_SUCCESS; } - /******************************************************************************* * * Function PAN_SetTraceLevel @@ -736,14 +673,13 @@ tBNEP_RESULT PAN_SetMulticastFilters (uint16_t handle, * Returns the new (current) trace level * ******************************************************************************/ -uint8_t PAN_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - pan_cb.trace_level = new_level; - else - pan_dump_status (); - - return (pan_cb.trace_level); +uint8_t PAN_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) + pan_cb.trace_level = new_level; + else + pan_dump_status(); + + return (pan_cb.trace_level); } /******************************************************************************* @@ -757,15 +693,12 @@ uint8_t PAN_SetTraceLevel (uint8_t new_level) * Returns none * ******************************************************************************/ -void PAN_Init (void) -{ - memset (&pan_cb, 0, sizeof (tPAN_CB)); +void PAN_Init(void) { + memset(&pan_cb, 0, sizeof(tPAN_CB)); #if defined(PAN_INITIAL_TRACE_LEVEL) - pan_cb.trace_level = PAN_INITIAL_TRACE_LEVEL; + pan_cb.trace_level = PAN_INITIAL_TRACE_LEVEL; #else - pan_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + pan_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif } - - diff --git a/stack/pan/pan_int.h b/stack/pan/pan_int.h index 6622774c1..75e17e68a 100644 --- a/stack/pan/pan_int.h +++ b/stack/pan/pan_int.h @@ -22,8 +22,8 @@ * ******************************************************************************/ -#ifndef PAN_INT_H -#define PAN_INT_H +#ifndef PAN_INT_H +#define PAN_INT_H #include "pan_api.h" @@ -35,65 +35,64 @@ extern "C" { * This role is used to shutdown the profile. Used internally * Applications should call PAN_Deregister to shutdown the profile */ -#define PAN_ROLE_INACTIVE 0 +#define PAN_ROLE_INACTIVE 0 /* Protocols supported by the host internal stack, are registered with SDP */ -#define PAN_PROTOCOL_IP 0x0800 -#define PAN_PROTOCOL_ARP 0x0806 +#define PAN_PROTOCOL_IP 0x0800 +#define PAN_PROTOCOL_ARP 0x0806 -#define PAN_PROFILE_VERSION 0x0100 /* Version 1.00 */ +#define PAN_PROFILE_VERSION 0x0100 /* Version 1.00 */ /* Define the PAN Connection Control Block */ -typedef struct -{ -#define PAN_STATE_IDLE 0 -#define PAN_STATE_CONN_START 1 -#define PAN_STATE_CONNECTED 2 - uint8_t con_state; - -#define PAN_FLAGS_CONN_COMPLETED 0x01 - uint8_t con_flags; - - uint16_t handle; - BD_ADDR rem_bda; - - uint16_t bad_pkts_rcvd; - uint16_t src_uuid; - uint16_t dst_uuid; - uint16_t prv_src_uuid; - uint16_t prv_dst_uuid; - uint16_t ip_addr_known; - uint32_t ip_addr; +typedef struct { +#define PAN_STATE_IDLE 0 +#define PAN_STATE_CONN_START 1 +#define PAN_STATE_CONNECTED 2 + uint8_t con_state; + +#define PAN_FLAGS_CONN_COMPLETED 0x01 + uint8_t con_flags; + + uint16_t handle; + BD_ADDR rem_bda; + + uint16_t bad_pkts_rcvd; + uint16_t src_uuid; + uint16_t dst_uuid; + uint16_t prv_src_uuid; + uint16_t prv_dst_uuid; + uint16_t ip_addr_known; + uint32_t ip_addr; } tPAN_CONN; - /* The main PAN control block */ -typedef struct -{ - uint8_t role; - uint8_t active_role; - uint8_t prv_active_role; - tPAN_CONN pcb[MAX_PAN_CONNS]; - - tPAN_CONN_STATE_CB *pan_conn_state_cb; /* Connection state callback */ - tPAN_BRIDGE_REQ_CB *pan_bridge_req_cb; - tPAN_DATA_IND_CB *pan_data_ind_cb; - tPAN_DATA_BUF_IND_CB *pan_data_buf_ind_cb; - tPAN_FILTER_IND_CB *pan_pfilt_ind_cb; /* protocol filter indication callback */ - tPAN_MFILTER_IND_CB *pan_mfilt_ind_cb; /* multicast filter indication callback */ - tPAN_TX_DATA_FLOW_CB *pan_tx_data_flow_cb; - - char *user_service_name; - char *gn_service_name; - char *nap_service_name; - uint32_t pan_user_sdp_handle; - uint32_t pan_gn_sdp_handle; - uint32_t pan_nap_sdp_handle; - uint8_t num_conns; - uint8_t trace_level; +typedef struct { + uint8_t role; + uint8_t active_role; + uint8_t prv_active_role; + tPAN_CONN pcb[MAX_PAN_CONNS]; + + tPAN_CONN_STATE_CB* pan_conn_state_cb; /* Connection state callback */ + tPAN_BRIDGE_REQ_CB* pan_bridge_req_cb; + tPAN_DATA_IND_CB* pan_data_ind_cb; + tPAN_DATA_BUF_IND_CB* pan_data_buf_ind_cb; + tPAN_FILTER_IND_CB* + pan_pfilt_ind_cb; /* protocol filter indication callback */ + tPAN_MFILTER_IND_CB* + pan_mfilt_ind_cb; /* multicast filter indication callback */ + tPAN_TX_DATA_FLOW_CB* pan_tx_data_flow_cb; + + char* user_service_name; + char* gn_service_name; + char* nap_service_name; + uint32_t pan_user_sdp_handle; + uint32_t pan_gn_sdp_handle; + uint32_t pan_nap_sdp_handle; + uint8_t num_conns; + uint8_t trace_level; } tPAN_CB; /* Global PAN data @@ -101,46 +100,32 @@ typedef struct extern tPAN_CB pan_cb; /******************************************************************************/ -extern void pan_register_with_bnep (void); -extern void pan_conn_ind_cb (uint16_t handle, - BD_ADDR p_bda, - tBT_UUID *remote_uuid, - tBT_UUID *local_uuid, - bool is_role_change); -extern void pan_connect_state_cb (uint16_t handle, BD_ADDR rem_bda, tBNEP_RESULT result, bool is_role_change); -extern void pan_data_ind_cb (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - uint8_t *p_data, - uint16_t len, - bool fw_ext_present); -extern void pan_data_buf_ind_cb (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - BT_HDR *p_buf, - bool ext); -extern void pan_tx_data_flow_cb (uint16_t handle, - tBNEP_RESULT event); -void pan_proto_filt_ind_cb (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters); -void pan_mcast_filt_ind_cb (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters); -extern uint32_t pan_register_with_sdp (uint16_t uuid, uint8_t sec_mask, - const char *p_name, const char *p_desc); -extern tPAN_CONN *pan_allocate_pcb (BD_ADDR p_bda, uint16_t handle); -extern tPAN_CONN *pan_get_pcb_by_handle (uint16_t handle); -extern tPAN_CONN *pan_get_pcb_by_addr (BD_ADDR p_bda); -extern void pan_close_all_connections (void); -extern void pan_release_pcb (tPAN_CONN *p_pcb); -extern void pan_dump_status (void); +extern void pan_register_with_bnep(void); +extern void pan_conn_ind_cb(uint16_t handle, BD_ADDR p_bda, + tBT_UUID* remote_uuid, tBT_UUID* local_uuid, + bool is_role_change); +extern void pan_connect_state_cb(uint16_t handle, BD_ADDR rem_bda, + tBNEP_RESULT result, bool is_role_change); +extern void pan_data_ind_cb(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, uint8_t* p_data, uint16_t len, + bool fw_ext_present); +extern void pan_data_buf_ind_cb(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, BT_HDR* p_buf, bool ext); +extern void pan_tx_data_flow_cb(uint16_t handle, tBNEP_RESULT event); +void pan_proto_filt_ind_cb(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters); +void pan_mcast_filt_ind_cb(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters); +extern uint32_t pan_register_with_sdp(uint16_t uuid, uint8_t sec_mask, + const char* p_name, const char* p_desc); +extern tPAN_CONN* pan_allocate_pcb(BD_ADDR p_bda, uint16_t handle); +extern tPAN_CONN* pan_get_pcb_by_handle(uint16_t handle); +extern tPAN_CONN* pan_get_pcb_by_addr(BD_ADDR p_bda); +extern void pan_close_all_connections(void); +extern void pan_release_pcb(tPAN_CONN* p_pcb); +extern void pan_dump_status(void); /******************************************************************************/ diff --git a/stack/pan/pan_main.cc b/stack/pan/pan_main.cc index 72777fa07..d89096bb1 100644 --- a/stack/pan/pan_main.cc +++ b/stack/pan/pan_main.cc @@ -24,24 +24,23 @@ ******************************************************************************/ #include +#include "bnep_api.h" #include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" -#include "bnep_api.h" +#include "hcidefs.h" +#include "l2c_api.h" +#include "osi/include/osi.h" #include "pan_api.h" #include "pan_int.h" #include "sdp_api.h" #include "sdpdefs.h" -#include "l2c_api.h" -#include "hcidefs.h" -#include "osi/include/osi.h" - tPAN_CB pan_cb; -#define UUID_CONSTANT_PART 12 -uint8_t constant_pan_uuid[UUID_CONSTANT_PART] = {0, 0, 0x10, 0, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; - +#define UUID_CONSTANT_PART 12 +uint8_t constant_pan_uuid[UUID_CONSTANT_PART] = { + 0, 0, 0x10, 0, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; /******************************************************************************* * @@ -54,24 +53,22 @@ uint8_t constant_pan_uuid[UUID_CONSTANT_PART] = {0, 0, 0x10, 0, 0x80, 0x00, 0x00 * Returns none * ******************************************************************************/ -void pan_register_with_bnep (void) -{ - tBNEP_REGISTER reg_info; +void pan_register_with_bnep(void) { + tBNEP_REGISTER reg_info; - memset (®_info, 0, sizeof (tBNEP_REGISTER)); + memset(®_info, 0, sizeof(tBNEP_REGISTER)); - reg_info.p_conn_ind_cb = pan_conn_ind_cb; - reg_info.p_conn_state_cb = pan_connect_state_cb; - reg_info.p_data_buf_cb = pan_data_buf_ind_cb; - reg_info.p_data_ind_cb = NULL; - reg_info.p_tx_data_flow_cb = pan_tx_data_flow_cb; - reg_info.p_filter_ind_cb = pan_proto_filt_ind_cb; - reg_info.p_mfilter_ind_cb = pan_mcast_filt_ind_cb; + reg_info.p_conn_ind_cb = pan_conn_ind_cb; + reg_info.p_conn_state_cb = pan_connect_state_cb; + reg_info.p_data_buf_cb = pan_data_buf_ind_cb; + reg_info.p_data_ind_cb = NULL; + reg_info.p_tx_data_flow_cb = pan_tx_data_flow_cb; + reg_info.p_filter_ind_cb = pan_proto_filt_ind_cb; + reg_info.p_mfilter_ind_cb = pan_mcast_filt_ind_cb; - BNEP_Register (®_info); + BNEP_Register(®_info); } - /******************************************************************************* * * Function pan_conn_ind_cb @@ -92,224 +89,211 @@ void pan_register_with_bnep (void) * Returns none * ******************************************************************************/ -void pan_conn_ind_cb (uint16_t handle, - BD_ADDR p_bda, - tBT_UUID *remote_uuid, - tBT_UUID *local_uuid, - bool is_role_change) -{ - tPAN_CONN *pcb; - uint8_t req_role; - bool wrong_uuid; - +void pan_conn_ind_cb(uint16_t handle, BD_ADDR p_bda, tBT_UUID* remote_uuid, + tBT_UUID* local_uuid, bool is_role_change) { + tPAN_CONN* pcb; + uint8_t req_role; + bool wrong_uuid; + + /* + ** If we are in GN or NAP role and have one or more + ** active connections and the received connection is + ** for user role reject it. + ** If we are in user role with one connection active + ** reject the connection. + ** Allocate PCB and store the parameters + ** Make bridge request to the host system if connection + ** is for NAP + */ + wrong_uuid = false; + if (remote_uuid->len == 16) { /* - ** If we are in GN or NAP role and have one or more - ** active connections and the received connection is - ** for user role reject it. - ** If we are in user role with one connection active - ** reject the connection. - ** Allocate PCB and store the parameters - ** Make bridge request to the host system if connection - ** is for NAP + ** If the UUID is 16 bytes forst two bytes should be zeros + ** and last 12 bytes should match the spec defined constant value */ - wrong_uuid = false; - if (remote_uuid->len == 16) - { - /* - ** If the UUID is 16 bytes forst two bytes should be zeros - ** and last 12 bytes should match the spec defined constant value - */ - if (memcmp (constant_pan_uuid, remote_uuid->uu.uuid128 + 4, UUID_CONSTANT_PART)) - wrong_uuid = true; - - if (remote_uuid->uu.uuid128[0] || remote_uuid->uu.uuid128[1]) - wrong_uuid = true; - - /* Extract the 16 bit equivalent of the UUID */ - remote_uuid->uu.uuid16 = (uint16_t)((remote_uuid->uu.uuid128[2] << 8) | remote_uuid->uu.uuid128[3]); - remote_uuid->len = 2; - } - if (remote_uuid->len == 4) - { - /* First two bytes should be zeros */ - if (remote_uuid->uu.uuid32 & 0xFFFF0000) - wrong_uuid = true; - - remote_uuid->uu.uuid16 = (uint16_t)remote_uuid->uu.uuid32; - remote_uuid->len = 2; - } - - if (wrong_uuid) - { - PAN_TRACE_ERROR ("PAN Connection failed because of wrong remote UUID "); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_SRC_UUID); - return; - } - - wrong_uuid = false; - if (local_uuid->len == 16) - { - /* - ** If the UUID is 16 bytes forst two bytes should be zeros - ** and last 12 bytes should match the spec defined constant value - */ - if (memcmp (constant_pan_uuid, local_uuid->uu.uuid128 + 4, UUID_CONSTANT_PART)) - wrong_uuid = true; - - if (local_uuid->uu.uuid128[0] || local_uuid->uu.uuid128[1]) - wrong_uuid = true; - - /* Extract the 16 bit equivalent of the UUID */ - local_uuid->uu.uuid16 = (uint16_t)((local_uuid->uu.uuid128[2] << 8) | local_uuid->uu.uuid128[3]); - local_uuid->len = 2; - } - if (local_uuid->len == 4) - { - /* First two bytes should be zeros */ - if (local_uuid->uu.uuid32 & 0xFFFF0000) - wrong_uuid = true; - - local_uuid->uu.uuid16 = (uint16_t)local_uuid->uu.uuid32; - local_uuid->len = 2; - } - - if (wrong_uuid) - { - PAN_TRACE_ERROR ("PAN Connection failed because of wrong local UUID "); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_DST_UUID); - return; - } - - PAN_TRACE_EVENT ("pan_conn_ind_cb - for handle %d, current role %d, dst uuid 0x%x, src uuid 0x%x, role change %s", - handle, pan_cb.role, local_uuid->uu.uuid16, remote_uuid->uu.uuid16, is_role_change?"YES":"NO"); - /* The acceptable UUID size is only 2 */ - if (remote_uuid->len != 2) - { - PAN_TRACE_ERROR ("PAN Connection failed because of wrong UUID size %d", remote_uuid->len); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_UUID_SIZE); - return; - } - - /* Check if the source UUID is a valid one */ - if (remote_uuid->uu.uuid16 != UUID_SERVCLASS_PANU && - remote_uuid->uu.uuid16 != UUID_SERVCLASS_NAP && - remote_uuid->uu.uuid16 != UUID_SERVCLASS_GN) - { - PAN_TRACE_ERROR ("Src UUID 0x%x is not valid", remote_uuid->uu.uuid16); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_SRC_UUID); - return; - } - - /* Check if the destination UUID is a valid one */ - if (local_uuid->uu.uuid16 != UUID_SERVCLASS_PANU && - local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP && - local_uuid->uu.uuid16 != UUID_SERVCLASS_GN) - { - PAN_TRACE_ERROR ("Dst UUID 0x%x is not valid", remote_uuid->uu.uuid16); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_DST_UUID); - return; - } + if (memcmp(constant_pan_uuid, remote_uuid->uu.uuid128 + 4, + UUID_CONSTANT_PART)) + wrong_uuid = true; + + if (remote_uuid->uu.uuid128[0] || remote_uuid->uu.uuid128[1]) + wrong_uuid = true; + + /* Extract the 16 bit equivalent of the UUID */ + remote_uuid->uu.uuid16 = (uint16_t)((remote_uuid->uu.uuid128[2] << 8) | + remote_uuid->uu.uuid128[3]); + remote_uuid->len = 2; + } + if (remote_uuid->len == 4) { + /* First two bytes should be zeros */ + if (remote_uuid->uu.uuid32 & 0xFFFF0000) wrong_uuid = true; + + remote_uuid->uu.uuid16 = (uint16_t)remote_uuid->uu.uuid32; + remote_uuid->len = 2; + } + + if (wrong_uuid) { + PAN_TRACE_ERROR("PAN Connection failed because of wrong remote UUID "); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID); + return; + } - /* Check if currently we support the destination role requested */ - if (((!(pan_cb.role & UUID_SERVCLASS_PANU)) - && local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) || - ((!(pan_cb.role & UUID_SERVCLASS_GN)) - && local_uuid->uu.uuid16 == UUID_SERVCLASS_GN) || - ((!(pan_cb.role & UUID_SERVCLASS_NAP)) - && local_uuid->uu.uuid16 == UUID_SERVCLASS_NAP)) - { - PAN_TRACE_ERROR ("PAN Connection failed because of unsupported destination UUID 0x%x", local_uuid->uu.uuid16); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_DST_UUID); - return; + wrong_uuid = false; + if (local_uuid->len == 16) { + /* + ** If the UUID is 16 bytes forst two bytes should be zeros + ** and last 12 bytes should match the spec defined constant value + */ + if (memcmp(constant_pan_uuid, local_uuid->uu.uuid128 + 4, + UUID_CONSTANT_PART)) + wrong_uuid = true; + + if (local_uuid->uu.uuid128[0] || local_uuid->uu.uuid128[1]) + wrong_uuid = true; + + /* Extract the 16 bit equivalent of the UUID */ + local_uuid->uu.uuid16 = (uint16_t)((local_uuid->uu.uuid128[2] << 8) | + local_uuid->uu.uuid128[3]); + local_uuid->len = 2; + } + if (local_uuid->len == 4) { + /* First two bytes should be zeros */ + if (local_uuid->uu.uuid32 & 0xFFFF0000) wrong_uuid = true; + + local_uuid->uu.uuid16 = (uint16_t)local_uuid->uu.uuid32; + local_uuid->len = 2; + } + + if (wrong_uuid) { + PAN_TRACE_ERROR("PAN Connection failed because of wrong local UUID "); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID); + return; + } + + PAN_TRACE_EVENT( + "pan_conn_ind_cb - for handle %d, current role %d, dst uuid 0x%x, src " + "uuid 0x%x, role change %s", + handle, pan_cb.role, local_uuid->uu.uuid16, remote_uuid->uu.uuid16, + is_role_change ? "YES" : "NO"); + /* The acceptable UUID size is only 2 */ + if (remote_uuid->len != 2) { + PAN_TRACE_ERROR("PAN Connection failed because of wrong UUID size %d", + remote_uuid->len); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_UUID_SIZE); + return; + } + + /* Check if the source UUID is a valid one */ + if (remote_uuid->uu.uuid16 != UUID_SERVCLASS_PANU && + remote_uuid->uu.uuid16 != UUID_SERVCLASS_NAP && + remote_uuid->uu.uuid16 != UUID_SERVCLASS_GN) { + PAN_TRACE_ERROR("Src UUID 0x%x is not valid", remote_uuid->uu.uuid16); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID); + return; + } + + /* Check if the destination UUID is a valid one */ + if (local_uuid->uu.uuid16 != UUID_SERVCLASS_PANU && + local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP && + local_uuid->uu.uuid16 != UUID_SERVCLASS_GN) { + PAN_TRACE_ERROR("Dst UUID 0x%x is not valid", remote_uuid->uu.uuid16); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID); + return; + } + + /* Check if currently we support the destination role requested */ + if (((!(pan_cb.role & UUID_SERVCLASS_PANU)) && + local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) || + ((!(pan_cb.role & UUID_SERVCLASS_GN)) && + local_uuid->uu.uuid16 == UUID_SERVCLASS_GN) || + ((!(pan_cb.role & UUID_SERVCLASS_NAP)) && + local_uuid->uu.uuid16 == UUID_SERVCLASS_NAP)) { + PAN_TRACE_ERROR( + "PAN Connection failed because of unsupported destination UUID 0x%x", + local_uuid->uu.uuid16); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID); + return; + } + + /* Requested destination role is */ + if (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) + req_role = PAN_ROLE_CLIENT; + else if (local_uuid->uu.uuid16 == UUID_SERVCLASS_GN) + req_role = PAN_ROLE_GN_SERVER; + else + req_role = PAN_ROLE_NAP_SERVER; + + /* If the connection indication is for the existing connection + ** Check if the new destination role is acceptable + */ + pcb = pan_get_pcb_by_handle(handle); + if (pcb) { + if (pan_cb.num_conns > 1 && local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) { + /* There are connections other than this one + ** so we cann't accept PANU role. Reject + */ + PAN_TRACE_ERROR( + "Dst UUID should be either GN or NAP only because there are other " + "connections"); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID); + return; } - /* Requested destination role is */ - if (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) - req_role = PAN_ROLE_CLIENT; - else if (local_uuid->uu.uuid16 == UUID_SERVCLASS_GN) - req_role = PAN_ROLE_GN_SERVER; - else - req_role = PAN_ROLE_NAP_SERVER; - - /* If the connection indication is for the existing connection - ** Check if the new destination role is acceptable - */ - pcb = pan_get_pcb_by_handle (handle); - if (pcb) - { - if (pan_cb.num_conns > 1 && local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU) - { - /* There are connections other than this one - ** so we cann't accept PANU role. Reject - */ - PAN_TRACE_ERROR ("Dst UUID should be either GN or NAP only because there are other connections"); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_DST_UUID); - return; - } + /* If it is already in connected state check for bridging status */ + if (pcb->con_state == PAN_STATE_CONNECTED) { + PAN_TRACE_EVENT("PAN Role changing New Src 0x%x Dst 0x%x", + remote_uuid->uu.uuid16, local_uuid->uu.uuid16); - /* If it is already in connected state check for bridging status */ - if (pcb->con_state == PAN_STATE_CONNECTED) - { - PAN_TRACE_EVENT ("PAN Role changing New Src 0x%x Dst 0x%x", - remote_uuid->uu.uuid16, local_uuid->uu.uuid16); - - pcb->prv_src_uuid = pcb->src_uuid; - pcb->prv_dst_uuid = pcb->dst_uuid; - - if (pcb->src_uuid == UUID_SERVCLASS_NAP && - local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP) - { - /* Remove bridging */ - if (pan_cb.pan_bridge_req_cb) - (*pan_cb.pan_bridge_req_cb) (pcb->rem_bda, false); - } - } - /* Set the latest active PAN role */ - pan_cb.active_role = req_role; - pcb->src_uuid = local_uuid->uu.uuid16; - pcb->dst_uuid = remote_uuid->uu.uuid16; - BNEP_ConnectResp (handle, BNEP_SUCCESS); - return; - } - else - { - /* If this a new connection and destination is PANU role and - ** we already have a connection then reject the request. - ** If we have a connection in PANU role then reject it - */ - if (pan_cb.num_conns && - (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU || - pan_cb.active_role == PAN_ROLE_CLIENT)) - { - PAN_TRACE_ERROR ("PAN already have a connection and can't be user"); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED_DST_UUID); - return; - } - } + pcb->prv_src_uuid = pcb->src_uuid; + pcb->prv_dst_uuid = pcb->dst_uuid; - /* This is a new connection */ - PAN_TRACE_DEBUG ("New connection indication for handle %d", handle); - pcb = pan_allocate_pcb (p_bda, handle); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN no control block for new connection"); - BNEP_ConnectResp (handle, BNEP_CONN_FAILED); - return; + if (pcb->src_uuid == UUID_SERVCLASS_NAP && + local_uuid->uu.uuid16 != UUID_SERVCLASS_NAP) { + /* Remove bridging */ + if (pan_cb.pan_bridge_req_cb) + (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false); + } } - - PAN_TRACE_EVENT ("PAN connection destination UUID is 0x%x", local_uuid->uu.uuid16); /* Set the latest active PAN role */ pan_cb.active_role = req_role; pcb->src_uuid = local_uuid->uu.uuid16; pcb->dst_uuid = remote_uuid->uu.uuid16; - pcb->con_state = PAN_STATE_CONN_START; - pan_cb.num_conns++; - - BNEP_ConnectResp (handle, BNEP_SUCCESS); + BNEP_ConnectResp(handle, BNEP_SUCCESS); return; + } else { + /* If this a new connection and destination is PANU role and + ** we already have a connection then reject the request. + ** If we have a connection in PANU role then reject it + */ + if (pan_cb.num_conns && (local_uuid->uu.uuid16 == UUID_SERVCLASS_PANU || + pan_cb.active_role == PAN_ROLE_CLIENT)) { + PAN_TRACE_ERROR("PAN already have a connection and can't be user"); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID); + return; + } + } + + /* This is a new connection */ + PAN_TRACE_DEBUG("New connection indication for handle %d", handle); + pcb = pan_allocate_pcb(p_bda, handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN no control block for new connection"); + BNEP_ConnectResp(handle, BNEP_CONN_FAILED); + return; + } + + PAN_TRACE_EVENT("PAN connection destination UUID is 0x%x", + local_uuid->uu.uuid16); + /* Set the latest active PAN role */ + pan_cb.active_role = req_role; + pcb->src_uuid = local_uuid->uu.uuid16; + pcb->dst_uuid = remote_uuid->uu.uuid16; + pcb->con_state = PAN_STATE_CONN_START; + pan_cb.num_conns++; + + BNEP_ConnectResp(handle, BNEP_SUCCESS); + return; } - /******************************************************************************* * * Function pan_connect_state_cb @@ -329,88 +313,84 @@ void pan_conn_ind_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_connect_state_cb (uint16_t handle, - UNUSED_ATTR BD_ADDR rem_bda, tBNEP_RESULT result, - bool is_role_change) -{ - tPAN_CONN *pcb; - uint8_t peer_role; - - PAN_TRACE_EVENT ("pan_connect_state_cb - for handle %d, result %d", handle, result); - pcb = pan_get_pcb_by_handle (handle); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN State change indication for wrong handle %d", handle); - return; - } - - /* If the connection is getting terminated remove bridging */ - if (result != BNEP_SUCCESS) - { - /* Inform the application that connection is down */ - if (pan_cb.pan_conn_state_cb) - (*pan_cb.pan_conn_state_cb) (pcb->handle, pcb->rem_bda, result, is_role_change, PAN_ROLE_INACTIVE, PAN_ROLE_INACTIVE); - - /* Check if this failure is for role change only */ - if (pcb->con_state != PAN_STATE_CONNECTED && - (pcb->con_flags & PAN_FLAGS_CONN_COMPLETED)) - { - /* restore the original values */ - PAN_TRACE_EVENT ("restoring the connection state to active"); - pcb->con_state = PAN_STATE_CONNECTED; - pcb->con_flags &= (~PAN_FLAGS_CONN_COMPLETED); - - pcb->src_uuid = pcb->prv_src_uuid; - pcb->dst_uuid = pcb->prv_dst_uuid; - pan_cb.active_role = pan_cb.prv_active_role; - - if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb) - (*pan_cb.pan_bridge_req_cb) (pcb->rem_bda, true); - - return; - } - - if (pcb->con_state == PAN_STATE_CONNECTED) - { - /* If the connections destination role is NAP remove bridging */ - if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb) - (*pan_cb.pan_bridge_req_cb) (pcb->rem_bda, false); - } - - pan_cb.num_conns--; - pan_release_pcb (pcb); - return; - } - - /* Requested destination role is */ - if (pcb->src_uuid == UUID_SERVCLASS_PANU) - pan_cb.active_role = PAN_ROLE_CLIENT; - else if (pcb->src_uuid == UUID_SERVCLASS_GN) - pan_cb.active_role = PAN_ROLE_GN_SERVER; - else - pan_cb.active_role = PAN_ROLE_NAP_SERVER; - - if (pcb->dst_uuid == UUID_SERVCLASS_PANU) - peer_role = PAN_ROLE_CLIENT; - else if (pcb->dst_uuid == UUID_SERVCLASS_GN) - peer_role = PAN_ROLE_GN_SERVER; - else - peer_role = PAN_ROLE_NAP_SERVER; - - pcb->con_state = PAN_STATE_CONNECTED; +void pan_connect_state_cb(uint16_t handle, UNUSED_ATTR BD_ADDR rem_bda, + tBNEP_RESULT result, bool is_role_change) { + tPAN_CONN* pcb; + uint8_t peer_role; + + PAN_TRACE_EVENT("pan_connect_state_cb - for handle %d, result %d", handle, + result); + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN State change indication for wrong handle %d", handle); + return; + } + /* If the connection is getting terminated remove bridging */ + if (result != BNEP_SUCCESS) { /* Inform the application that connection is down */ if (pan_cb.pan_conn_state_cb) - (*pan_cb.pan_conn_state_cb) (pcb->handle, pcb->rem_bda, PAN_SUCCESS, is_role_change, pan_cb.active_role, peer_role); + (*pan_cb.pan_conn_state_cb)(pcb->handle, pcb->rem_bda, result, + is_role_change, PAN_ROLE_INACTIVE, + PAN_ROLE_INACTIVE); + + /* Check if this failure is for role change only */ + if (pcb->con_state != PAN_STATE_CONNECTED && + (pcb->con_flags & PAN_FLAGS_CONN_COMPLETED)) { + /* restore the original values */ + PAN_TRACE_EVENT("restoring the connection state to active"); + pcb->con_state = PAN_STATE_CONNECTED; + pcb->con_flags &= (~PAN_FLAGS_CONN_COMPLETED); + + pcb->src_uuid = pcb->prv_src_uuid; + pcb->dst_uuid = pcb->prv_dst_uuid; + pan_cb.active_role = pan_cb.prv_active_role; + + if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb) + (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, true); + + return; + } - /* Create bridge if the destination role is NAP */ - if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP) - { - PAN_TRACE_EVENT ("PAN requesting for bridge"); - (*pan_cb.pan_bridge_req_cb) (pcb->rem_bda, true); + if (pcb->con_state == PAN_STATE_CONNECTED) { + /* If the connections destination role is NAP remove bridging */ + if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb) + (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false); } -} + pan_cb.num_conns--; + pan_release_pcb(pcb); + return; + } + + /* Requested destination role is */ + if (pcb->src_uuid == UUID_SERVCLASS_PANU) + pan_cb.active_role = PAN_ROLE_CLIENT; + else if (pcb->src_uuid == UUID_SERVCLASS_GN) + pan_cb.active_role = PAN_ROLE_GN_SERVER; + else + pan_cb.active_role = PAN_ROLE_NAP_SERVER; + + if (pcb->dst_uuid == UUID_SERVCLASS_PANU) + peer_role = PAN_ROLE_CLIENT; + else if (pcb->dst_uuid == UUID_SERVCLASS_GN) + peer_role = PAN_ROLE_GN_SERVER; + else + peer_role = PAN_ROLE_NAP_SERVER; + + pcb->con_state = PAN_STATE_CONNECTED; + + /* Inform the application that connection is down */ + if (pan_cb.pan_conn_state_cb) + (*pan_cb.pan_conn_state_cb)(pcb->handle, pcb->rem_bda, PAN_SUCCESS, + is_role_change, pan_cb.active_role, peer_role); + + /* Create bridge if the destination role is NAP */ + if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP) { + PAN_TRACE_EVENT("PAN requesting for bridge"); + (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, true); + } +} /******************************************************************************* * @@ -432,92 +412,80 @@ void pan_connect_state_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_data_ind_cb (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - uint8_t *p_data, - uint16_t len, - bool ext) -{ - tPAN_CONN *pcb; - uint16_t i; - bool forward; - - /* - ** Check the connection status - ** If the destination address is MAC broadcast send on all links - ** except on the one received - ** If the destination uuid is for NAP send to host system also - ** If the destination address is one of the devices connected - ** send the packet to over that link - ** If the destination address is unknown and destination uuid is NAP - ** send it to the host system - */ - - PAN_TRACE_EVENT ("pan_data_ind_cb - for handle %d", handle); - pcb = pan_get_pcb_by_handle (handle); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN Data indication for wrong handle %d", handle); - return; - } +void pan_data_ind_cb(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, uint8_t* p_data, uint16_t len, + bool ext) { + tPAN_CONN* pcb; + uint16_t i; + bool forward; + + /* + ** Check the connection status + ** If the destination address is MAC broadcast send on all links + ** except on the one received + ** If the destination uuid is for NAP send to host system also + ** If the destination address is one of the devices connected + ** send the packet to over that link + ** If the destination address is unknown and destination uuid is NAP + ** send it to the host system + */ + + PAN_TRACE_EVENT("pan_data_ind_cb - for handle %d", handle); + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN Data indication for wrong handle %d", handle); + return; + } - if (pcb->con_state != PAN_STATE_CONNECTED) - { - PAN_TRACE_ERROR ("PAN Data indication in wrong state %d for handle %d", - pcb->con_state, handle); - return; + if (pcb->con_state != PAN_STATE_CONNECTED) { + PAN_TRACE_ERROR("PAN Data indication in wrong state %d for handle %d", + pcb->con_state, handle); + return; + } + + /* Check if it is broadcast packet */ + if (dst[0] & 0x01) { + PAN_TRACE_DEBUG("PAN received broadcast packet on handle %d, src uuid 0x%x", + handle, pcb->src_uuid); + for (i = 0; i < MAX_PAN_CONNS; i++) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED && + pan_cb.pcb[i].handle != handle && + pcb->src_uuid == pan_cb.pcb[i].src_uuid) { + BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); + } } - /* Check if it is broadcast packet */ - if (dst[0] & 0x01) - { - PAN_TRACE_DEBUG ("PAN received broadcast packet on handle %d, src uuid 0x%x", - handle, pcb->src_uuid); - for (i=0; isrc_uuid == pan_cb.pcb[i].src_uuid) - { - BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); - } - } - - if (pan_cb.pan_data_ind_cb) - (*pan_cb.pan_data_ind_cb) (pcb->handle, src, dst, protocol, p_data, len, ext, true); + if (pan_cb.pan_data_ind_cb) + (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, + ext, true); + return; + } + + /* Check if it is for any other PAN connection */ + for (i = 0; i < MAX_PAN_CONNS; i++) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED && + pcb->src_uuid == pan_cb.pcb[i].src_uuid) { + if (memcmp(pan_cb.pcb[i].rem_bda, dst, BD_ADDR_LEN) == 0) { + BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); return; + } } + } - /* Check if it is for any other PAN connection */ - for (i=0; isrc_uuid == pan_cb.pcb[i].src_uuid) - { - if (memcmp (pan_cb.pcb[i].rem_bda, dst, BD_ADDR_LEN) == 0) - { - BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); - return; - } - } - } + if (pcb->src_uuid == UUID_SERVCLASS_NAP) + forward = true; + else + forward = false; - if (pcb->src_uuid == UUID_SERVCLASS_NAP) - forward = true; - else - forward = false; + /* Send it over the LAN or give it to host software */ + if (pan_cb.pan_data_ind_cb) + (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, ext, + forward); - /* Send it over the LAN or give it to host software */ - if (pan_cb.pan_data_ind_cb) - (*pan_cb.pan_data_ind_cb) (pcb->handle, src, dst, protocol, p_data, len, ext, forward); - - return; + return; } - /******************************************************************************* * * Function pan_data_buf_ind_cb @@ -538,102 +506,97 @@ void pan_data_ind_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_data_buf_ind_cb (uint16_t handle, - uint8_t *src, - uint8_t *dst, - uint16_t protocol, - BT_HDR *p_buf, - bool ext) -{ - tPAN_CONN *pcb, *dst_pcb; - tBNEP_RESULT result; - uint16_t i, len; - uint8_t *p_data; - bool forward = false; - - /* Check if the connection is in right state */ - pcb = pan_get_pcb_by_handle (handle); - if (!pcb) - { - PAN_TRACE_ERROR ("PAN Data buffer indication for wrong handle %d", handle); - osi_free(p_buf); - return; - } - - if (pcb->con_state != PAN_STATE_CONNECTED) - { - PAN_TRACE_ERROR ("PAN Data indication in wrong state %d for handle %d", - pcb->con_state, handle); - osi_free(p_buf); - return; - } +void pan_data_buf_ind_cb(uint16_t handle, uint8_t* src, uint8_t* dst, + uint16_t protocol, BT_HDR* p_buf, bool ext) { + tPAN_CONN *pcb, *dst_pcb; + tBNEP_RESULT result; + uint16_t i, len; + uint8_t* p_data; + bool forward = false; + + /* Check if the connection is in right state */ + pcb = pan_get_pcb_by_handle(handle); + if (!pcb) { + PAN_TRACE_ERROR("PAN Data buffer indication for wrong handle %d", handle); + osi_free(p_buf); + return; + } - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - len = p_buf->len; - - PAN_TRACE_EVENT ("pan_data_buf_ind_cb - for handle %d, protocol 0x%x, length %d, ext %d", - handle, protocol, len, ext); - - if (pcb->src_uuid == UUID_SERVCLASS_NAP) - forward = true; - else - forward = false; - - /* Check if it is broadcast or multicast packet */ - if (pcb->src_uuid != UUID_SERVCLASS_PANU) - { - if (dst[0] & 0x01) - { - PAN_TRACE_DEBUG ("PAN received broadcast packet on handle %d, src uuid 0x%x", - handle, pcb->src_uuid); - for (i=0; isrc_uuid == pan_cb.pcb[i].src_uuid) - { - BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext); - } - } - - if (pan_cb.pan_data_buf_ind_cb) - (*pan_cb.pan_data_buf_ind_cb) (pcb->handle, src, dst, protocol, p_buf, ext, forward); - else if (pan_cb.pan_data_ind_cb) - { - (*pan_cb.pan_data_ind_cb) (pcb->handle, src, dst, protocol, p_data, len, ext, forward); - osi_free(p_buf); - } - - return; + if (pcb->con_state != PAN_STATE_CONNECTED) { + PAN_TRACE_ERROR("PAN Data indication in wrong state %d for handle %d", + pcb->con_state, handle); + osi_free(p_buf); + return; + } + + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + len = p_buf->len; + + PAN_TRACE_EVENT( + "pan_data_buf_ind_cb - for handle %d, protocol 0x%x, length %d, ext %d", + handle, protocol, len, ext); + + if (pcb->src_uuid == UUID_SERVCLASS_NAP) + forward = true; + else + forward = false; + + /* Check if it is broadcast or multicast packet */ + if (pcb->src_uuid != UUID_SERVCLASS_PANU) { + if (dst[0] & 0x01) { + PAN_TRACE_DEBUG( + "PAN received broadcast packet on handle %d, src uuid 0x%x", handle, + pcb->src_uuid); + for (i = 0; i < MAX_PAN_CONNS; i++) { + if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED && + pan_cb.pcb[i].handle != handle && + pcb->src_uuid == pan_cb.pcb[i].src_uuid) { + BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, + ext); } + } + + if (pan_cb.pan_data_buf_ind_cb) + (*pan_cb.pan_data_buf_ind_cb)(pcb->handle, src, dst, protocol, p_buf, + ext, forward); + else if (pan_cb.pan_data_ind_cb) { + (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, + ext, forward); + osi_free(p_buf); + } - /* Check if it is for any other PAN connection */ - dst_pcb = pan_get_pcb_by_addr (dst); - if (dst_pcb) - { - PAN_TRACE_EVENT ("%s - destination PANU found on handle %d and sending data, len: %d", - __func__, dst_pcb->handle, len); - - result = BNEP_Write (dst_pcb->handle, dst, p_data, len, protocol, src, ext); - if (result != BNEP_SUCCESS && result != BNEP_IGNORE_CMD) - PAN_TRACE_ERROR ("Failed to write data for PAN connection handle %d", dst_pcb->handle); - osi_free(p_buf); - return; - } + return; } - /* Send it over the LAN or give it to host software */ - if (pan_cb.pan_data_buf_ind_cb) - (*pan_cb.pan_data_buf_ind_cb) (pcb->handle, src, dst, protocol, p_buf, ext, forward); - else if (pan_cb.pan_data_ind_cb) - { - (*pan_cb.pan_data_ind_cb) (pcb->handle, src, dst, protocol, p_data, len, ext, forward); - osi_free(p_buf); + /* Check if it is for any other PAN connection */ + dst_pcb = pan_get_pcb_by_addr(dst); + if (dst_pcb) { + PAN_TRACE_EVENT( + "%s - destination PANU found on handle %d and sending data, len: %d", + __func__, dst_pcb->handle, len); + + result = + BNEP_Write(dst_pcb->handle, dst, p_data, len, protocol, src, ext); + if (result != BNEP_SUCCESS && result != BNEP_IGNORE_CMD) + PAN_TRACE_ERROR("Failed to write data for PAN connection handle %d", + dst_pcb->handle); + osi_free(p_buf); + return; } - else - osi_free(p_buf); - - return; + } + + /* Send it over the LAN or give it to host software */ + if (pan_cb.pan_data_buf_ind_cb) + (*pan_cb.pan_data_buf_ind_cb)(pcb->handle, src, dst, protocol, p_buf, ext, + forward); + else if (pan_cb.pan_data_ind_cb) { + (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, ext, + forward); + osi_free(p_buf); + } else + osi_free(p_buf); + + return; } /******************************************************************************* @@ -649,14 +612,10 @@ void pan_data_buf_ind_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_tx_data_flow_cb (uint16_t handle, - tBNEP_RESULT event) -{ +void pan_tx_data_flow_cb(uint16_t handle, tBNEP_RESULT event) { + if (pan_cb.pan_tx_data_flow_cb) (*pan_cb.pan_tx_data_flow_cb)(handle, event); - if (pan_cb.pan_tx_data_flow_cb) - (*pan_cb.pan_tx_data_flow_cb) (handle, event); - - return; + return; } /******************************************************************************* @@ -680,20 +639,19 @@ void pan_tx_data_flow_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_proto_filt_ind_cb (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters) -{ - PAN_TRACE_EVENT ("pan_proto_filt_ind_cb - called for handle %d with ind %d, result %d, num %d", - handle, indication, result, num_filters); - - if (pan_cb.pan_pfilt_ind_cb) - (*pan_cb.pan_pfilt_ind_cb) (handle, indication, result, num_filters, p_filters); +void pan_proto_filt_ind_cb(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters) { + PAN_TRACE_EVENT( + "pan_proto_filt_ind_cb - called for handle %d with ind %d, result %d, " + "num %d", + handle, indication, result, num_filters); + + if (pan_cb.pan_pfilt_ind_cb) + (*pan_cb.pan_pfilt_ind_cb)(handle, indication, result, num_filters, + p_filters); } - /******************************************************************************* * * Function pan_mcast_filt_ind_cb @@ -715,15 +673,15 @@ void pan_proto_filt_ind_cb (uint16_t handle, * Returns none * ******************************************************************************/ -void pan_mcast_filt_ind_cb (uint16_t handle, - bool indication, - tBNEP_RESULT result, - uint16_t num_filters, - uint8_t *p_filters) -{ - PAN_TRACE_EVENT ("pan_mcast_filt_ind_cb - called for handle %d with ind %d, result %d, num %d", - handle, indication, result, num_filters); - - if (pan_cb.pan_mfilt_ind_cb) - (*pan_cb.pan_mfilt_ind_cb) (handle, indication, result, num_filters, p_filters); +void pan_mcast_filt_ind_cb(uint16_t handle, bool indication, + tBNEP_RESULT result, uint16_t num_filters, + uint8_t* p_filters) { + PAN_TRACE_EVENT( + "pan_mcast_filt_ind_cb - called for handle %d with ind %d, result %d, " + "num %d", + handle, indication, result, num_filters); + + if (pan_cb.pan_mfilt_ind_cb) + (*pan_cb.pan_mfilt_ind_cb)(handle, indication, result, num_filters, + p_filters); } diff --git a/stack/pan/pan_utils.cc b/stack/pan/pan_utils.cc index ccf34e96b..7f7513512 100644 --- a/stack/pan/pan_utils.cc +++ b/stack/pan/pan_utils.cc @@ -23,30 +23,32 @@ * *****************************************************************************/ -#include #include -#include "bt_common.h" +#include #include "bnep_api.h" +#include "bt_common.h" +#include "btm_api.h" +#include "hcidefs.h" +#include "l2c_api.h" #include "pan_api.h" #include "pan_int.h" #include "sdp_api.h" #include "sdpdefs.h" -#include "l2c_api.h" -#include "hcidefs.h" -#include "btm_api.h" - -static const uint8_t pan_proto_elem_data[] = { - 0x35, 0x18, /* data element sequence of length 0x18 bytes */ - 0x35, 0x06, /* data element sequence for L2CAP descriptor */ - 0x19, 0x01, 0x00, /* UUID for L2CAP - 0x0100 */ - 0x09, 0x00, 0x0F, /* PSM for BNEP - 0x000F */ - 0x35, 0x0E, /* data element seqence for BNEP descriptor */ - 0x19, 0x00, 0x0F, /* UUID for BNEP - 0x000F */ - 0x09, 0x01, 0x00, /* BNEP specific parameter 0 -- Version of BNEP = version 1 = 0x0001 */ - 0x35, 0x06, /* BNEP specific parameter 1 -- Supported network packet type list */ - 0x09, 0x08, 0x00, /* network packet type IPv4 = 0x0800 */ - 0x09, 0x08, 0x06 /* network packet type ARP = 0x0806 */ +static const uint8_t pan_proto_elem_data[] = { + 0x35, 0x18, /* data element sequence of length 0x18 bytes */ + 0x35, 0x06, /* data element sequence for L2CAP descriptor */ + 0x19, 0x01, 0x00, /* UUID for L2CAP - 0x0100 */ + 0x09, 0x00, 0x0F, /* PSM for BNEP - 0x000F */ + 0x35, 0x0E, /* data element seqence for BNEP descriptor */ + 0x19, 0x00, 0x0F, /* UUID for BNEP - 0x000F */ + 0x09, 0x01, + 0x00, /* BNEP specific parameter 0 -- Version of BNEP = version 1 = 0x0001 + */ + 0x35, + 0x06, /* BNEP specific parameter 1 -- Supported network packet type list */ + 0x09, 0x08, 0x00, /* network packet type IPv4 = 0x0800 */ + 0x09, 0x08, 0x06 /* network packet type ARP = 0x0806 */ }; /******************************************************************************* @@ -58,112 +60,111 @@ static const uint8_t pan_proto_elem_data[] = { * Returns * ******************************************************************************/ -uint32_t pan_register_with_sdp (uint16_t uuid, uint8_t sec_mask, - const char *p_name, const char *p_desc) -{ - uint32_t sdp_handle; - uint16_t browse_list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; - uint16_t security = 0; - uint32_t proto_len = (uint32_t )pan_proto_elem_data[1]; - - /* Create a record */ - sdp_handle = SDP_CreateRecord (); - - if (sdp_handle == 0) - { - PAN_TRACE_ERROR ("PAN_SetRole - could not create SDP record"); - return 0; - } - - /* Service Class ID List */ - SDP_AddServiceClassIdList (sdp_handle, 1, &uuid); - - /* Add protocol element sequence from the constant string */ - SDP_AddAttribute (sdp_handle, ATTR_ID_PROTOCOL_DESC_LIST, DATA_ELE_SEQ_DESC_TYPE, - proto_len, (uint8_t *)(pan_proto_elem_data+2)); - - /* Language base */ - SDP_AddLanguageBaseAttrIDList (sdp_handle, LANG_ID_CODE_ENGLISH, LANG_ID_CHAR_ENCODE_UTF8, LANGUAGE_BASE_ID); - - /* Profile descriptor list */ - SDP_AddProfileDescriptorList (sdp_handle, uuid, PAN_PROFILE_VERSION); - - /* Service Name */ - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, - (uint8_t) (strlen(p_name) + 1), (uint8_t *)p_name); - - /* Service description */ - SDP_AddAttribute (sdp_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE, - (uint8_t) (strlen(p_desc) + 1), (uint8_t *)p_desc); - - /* Security description */ - if (sec_mask) - { - UINT16_TO_BE_FIELD(&security, 0x0001); - } - SDP_AddAttribute (sdp_handle, ATTR_ID_SECURITY_DESCRIPTION, UINT_DESC_TYPE, 2, (uint8_t *)&security); +uint32_t pan_register_with_sdp(uint16_t uuid, uint8_t sec_mask, + const char* p_name, const char* p_desc) { + uint32_t sdp_handle; + uint16_t browse_list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP; + uint16_t security = 0; + uint32_t proto_len = (uint32_t)pan_proto_elem_data[1]; + + /* Create a record */ + sdp_handle = SDP_CreateRecord(); + + if (sdp_handle == 0) { + PAN_TRACE_ERROR("PAN_SetRole - could not create SDP record"); + return 0; + } + + /* Service Class ID List */ + SDP_AddServiceClassIdList(sdp_handle, 1, &uuid); + + /* Add protocol element sequence from the constant string */ + SDP_AddAttribute(sdp_handle, ATTR_ID_PROTOCOL_DESC_LIST, + DATA_ELE_SEQ_DESC_TYPE, proto_len, + (uint8_t*)(pan_proto_elem_data + 2)); + + /* Language base */ + SDP_AddLanguageBaseAttrIDList(sdp_handle, LANG_ID_CODE_ENGLISH, + LANG_ID_CHAR_ENCODE_UTF8, LANGUAGE_BASE_ID); + + /* Profile descriptor list */ + SDP_AddProfileDescriptorList(sdp_handle, uuid, PAN_PROFILE_VERSION); + + /* Service Name */ + SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE, + (uint8_t)(strlen(p_name) + 1), (uint8_t*)p_name); + + /* Service description */ + SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE, + (uint8_t)(strlen(p_desc) + 1), (uint8_t*)p_desc); + + /* Security description */ + if (sec_mask) { + UINT16_TO_BE_FIELD(&security, 0x0001); + } + SDP_AddAttribute(sdp_handle, ATTR_ID_SECURITY_DESCRIPTION, UINT_DESC_TYPE, 2, + (uint8_t*)&security); #if (PAN_SUPPORTS_ROLE_NAP == TRUE) - if (uuid == UUID_SERVCLASS_NAP) - { - uint16_t NetAccessType = 0x0005; /* Ethernet */ - uint32_t NetAccessRate = 0x0001312D0; /* 10Mb/sec */ - uint8_t array[10], *p; - - /* Net access type. */ - p = array; - UINT16_TO_BE_STREAM (p, NetAccessType); - SDP_AddAttribute (sdp_handle, ATTR_ID_NET_ACCESS_TYPE, UINT_DESC_TYPE, 2, array); - - /* Net access rate. */ - p = array; - UINT32_TO_BE_STREAM (p, NetAccessRate); - SDP_AddAttribute (sdp_handle, ATTR_ID_MAX_NET_ACCESS_RATE, UINT_DESC_TYPE, 4, array); - - /* Register with Security Manager for the specific security level */ - if ((!BTM_SetSecurityLevel (true, p_name, BTM_SEC_SERVICE_BNEP_NAP, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_NAP)) - || (!BTM_SetSecurityLevel (false, p_name, BTM_SEC_SERVICE_BNEP_NAP, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_NAP))) - { - PAN_TRACE_ERROR ("PAN Security Registration failed for PANU"); - } + if (uuid == UUID_SERVCLASS_NAP) { + uint16_t NetAccessType = 0x0005; /* Ethernet */ + uint32_t NetAccessRate = 0x0001312D0; /* 10Mb/sec */ + uint8_t array[10], *p; + + /* Net access type. */ + p = array; + UINT16_TO_BE_STREAM(p, NetAccessType); + SDP_AddAttribute(sdp_handle, ATTR_ID_NET_ACCESS_TYPE, UINT_DESC_TYPE, 2, + array); + + /* Net access rate. */ + p = array; + UINT32_TO_BE_STREAM(p, NetAccessRate); + SDP_AddAttribute(sdp_handle, ATTR_ID_MAX_NET_ACCESS_RATE, UINT_DESC_TYPE, 4, + array); + + /* Register with Security Manager for the specific security level */ + if ((!BTM_SetSecurityLevel(true, p_name, BTM_SEC_SERVICE_BNEP_NAP, sec_mask, + BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_NAP)) || + (!BTM_SetSecurityLevel(false, p_name, BTM_SEC_SERVICE_BNEP_NAP, + sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_NAP))) { + PAN_TRACE_ERROR("PAN Security Registration failed for PANU"); } + } #endif #if (PAN_SUPPORTS_ROLE_GN == TRUE) - if (uuid == UUID_SERVCLASS_GN) - { - if ((!BTM_SetSecurityLevel (true, p_name, BTM_SEC_SERVICE_BNEP_GN, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_GN)) - || (!BTM_SetSecurityLevel (false, p_name, BTM_SEC_SERVICE_BNEP_GN, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_GN))) - { - PAN_TRACE_ERROR ("PAN Security Registration failed for GN"); - } + if (uuid == UUID_SERVCLASS_GN) { + if ((!BTM_SetSecurityLevel(true, p_name, BTM_SEC_SERVICE_BNEP_GN, sec_mask, + BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_GN)) || + (!BTM_SetSecurityLevel(false, p_name, BTM_SEC_SERVICE_BNEP_GN, sec_mask, + BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_GN))) { + PAN_TRACE_ERROR("PAN Security Registration failed for GN"); } + } #endif #if (PAN_SUPPORTS_ROLE_PANU == TRUE) - if (uuid == UUID_SERVCLASS_PANU) - { - if ((!BTM_SetSecurityLevel (true, p_name, BTM_SEC_SERVICE_BNEP_PANU, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_PANU)) - || (!BTM_SetSecurityLevel (false, p_name, BTM_SEC_SERVICE_BNEP_PANU, - sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, UUID_SERVCLASS_PANU))) - { - PAN_TRACE_ERROR ("PAN Security Registration failed for PANU"); - } + if (uuid == UUID_SERVCLASS_PANU) { + if ((!BTM_SetSecurityLevel(true, p_name, BTM_SEC_SERVICE_BNEP_PANU, + sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_PANU)) || + (!BTM_SetSecurityLevel(false, p_name, BTM_SEC_SERVICE_BNEP_PANU, + sec_mask, BT_PSM_BNEP, BTM_SEC_PROTO_BNEP, + UUID_SERVCLASS_PANU))) { + PAN_TRACE_ERROR("PAN Security Registration failed for PANU"); } + } #endif - /* Make the service browsable */ - SDP_AddUuidSequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse_list); - + /* Make the service browsable */ + SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse_list); - return sdp_handle; + return sdp_handle; } - - /******************************************************************************* * * Function pan_allocate_pcb @@ -173,38 +174,32 @@ uint32_t pan_register_with_sdp (uint16_t uuid, uint8_t sec_mask, * Returns * ******************************************************************************/ -tPAN_CONN *pan_allocate_pcb (BD_ADDR p_bda, uint16_t handle) -{ - uint16_t i; - - for (i=0; icon_state = PAN_STATE_IDLE; +void pan_release_pcb(tPAN_CONN* p_pcb) { + /* Drop any response pointer we may be holding */ + memset(p_pcb, 0, sizeof(tPAN_CONN)); + p_pcb->con_state = PAN_STATE_IDLE; } - /******************************************************************************* * * Function pan_dump_status @@ -318,28 +298,24 @@ void pan_release_pcb (tPAN_CONN *p_pcb) * Returns none * ******************************************************************************/ -void pan_dump_status (void) -{ +void pan_dump_status(void) { #if (PAN_SUPPORTS_DEBUG_DUMP == TRUE) - uint16_t i; - char buff[200]; - tPAN_CONN *p_pcb; - - PAN_TRACE_DEBUG ("PAN role %x, active role %d, num_conns %d", - pan_cb.role, pan_cb.active_role, pan_cb.num_conns); - - for (i = 0, p_pcb = pan_cb.pcb; i < MAX_PAN_CONNS; i++, p_pcb++) - { - snprintf (buff, sizeof(buff), - "%d state %d, handle %d, src 0x%x, dst 0x%x, BD %x.%x.%x.%x.%x.%x", - i, p_pcb->con_state, p_pcb->handle, p_pcb->src_uuid, p_pcb->dst_uuid, - p_pcb->rem_bda[0], p_pcb->rem_bda[1], p_pcb->rem_bda[2], - p_pcb->rem_bda[3], p_pcb->rem_bda[4], p_pcb->rem_bda[5]); - - PAN_TRACE_DEBUG (buff); - } + uint16_t i; + char buff[200]; + tPAN_CONN* p_pcb; + + PAN_TRACE_DEBUG("PAN role %x, active role %d, num_conns %d", pan_cb.role, + pan_cb.active_role, pan_cb.num_conns); + + for (i = 0, p_pcb = pan_cb.pcb; i < MAX_PAN_CONNS; i++, p_pcb++) { + snprintf(buff, sizeof(buff), + "%d state %d, handle %d, src 0x%x, dst 0x%x, BD %x.%x.%x.%x.%x.%x", + i, p_pcb->con_state, p_pcb->handle, p_pcb->src_uuid, + p_pcb->dst_uuid, p_pcb->rem_bda[0], p_pcb->rem_bda[1], + p_pcb->rem_bda[2], p_pcb->rem_bda[3], p_pcb->rem_bda[4], + p_pcb->rem_bda[5]); + + PAN_TRACE_DEBUG(buff); + } #endif } - - - diff --git a/stack/rfcomm/port_api.cc b/stack/rfcomm/port_api.cc index bba94ce02..196fb424d 100644 --- a/stack/rfcomm/port_api.cc +++ b/stack/rfcomm/port_api.cc @@ -29,9 +29,9 @@ #include "osi/include/log.h" #include "osi/include/mutex.h" +#include "bt_common.h" #include "btm_api.h" #include "btm_int.h" -#include "bt_common.h" #include "l2c_api.h" #include "port_api.h" #include "port_int.h" @@ -40,43 +40,45 @@ #include "sdp_api.h" /* duration of break in 200ms units */ -#define PORT_BREAK_DURATION 1 +#define PORT_BREAK_DURATION 1 -#define info(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) -#define debug(fmt, ...) LOG_DEBUG(LOG_TAG, "%s: " fmt,__func__, ## __VA_ARGS__) -#define error(fmt, ...) LOG_ERROR(LOG_TAG, "## ERROR : %s: " fmt "##",__func__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) LOG_ERROR(LOG_TAG, "## %s assert %s failed at line:%d ##",__func__, #s, __LINE__) +#define info(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) +#define debug(fmt, ...) LOG_DEBUG(LOG_TAG, "%s: " fmt, __func__, ##__VA_ARGS__) +#define error(fmt, ...) \ + LOG_ERROR(LOG_TAG, "## ERROR : %s: " fmt "##", __func__, ##__VA_ARGS__) +#define asrt(s) \ + if (!(s)) \ + LOG_ERROR(LOG_TAG, "## %s assert %s failed at line:%d ##", __func__, #s, \ + __LINE__) /* Mapping from PORT_* result codes to human readable strings. */ -static const char *result_code_strings[] = { - "Success", - "Unknown error", - "Already opened", - "Command pending", - "App not registered", - "No memory", - "No resources", - "Bad BD address", - "Unspecified error", - "Bad handle", - "Not opened", - "Line error", - "Start failed", - "Parameter negotiation failed", - "Port negotiation failed", - "Sec failed", - "Peer connection failed", - "Peer failed", - "Peer timeout", - "Closed", - "TX full", - "Local closed", - "Local timeout", - "TX queue disabled", - "Page timeout", - "Invalid SCN", - "Unknown result code" -}; +static const char* result_code_strings[] = {"Success", + "Unknown error", + "Already opened", + "Command pending", + "App not registered", + "No memory", + "No resources", + "Bad BD address", + "Unspecified error", + "Bad handle", + "Not opened", + "Line error", + "Start failed", + "Parameter negotiation failed", + "Port negotiation failed", + "Sec failed", + "Peer connection failed", + "Peer failed", + "Peer timeout", + "Closed", + "TX full", + "Local closed", + "Local timeout", + "TX queue disabled", + "Page timeout", + "Invalid SCN", + "Unknown result code"}; /******************************************************************************* * @@ -109,128 +111,129 @@ static const char *result_code_strings[] = { * (scn * 2 + 1) dlci. * ******************************************************************************/ -int RFCOMM_CreateConnection (uint16_t uuid, uint8_t scn, bool is_server, - uint16_t mtu, BD_ADDR bd_addr, uint16_t *p_handle, - tPORT_CALLBACK *p_mgmt_cb) -{ - tPORT *p_port; - int i; - uint8_t dlci; - tRFC_MCB *p_mcb = port_find_mcb (bd_addr); - uint16_t rfcomm_mtu; - - - RFCOMM_TRACE_API ("RFCOMM_CreateConnection() BDA: %02x-%02x-%02x-%02x-%02x-%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - - *p_handle = 0; - - if (( scn == 0 )||(scn >= PORT_MAX_RFC_PORTS )) - { - /* Server Channel Number(SCN) should be in range 1...30 */ - RFCOMM_TRACE_ERROR ("RFCOMM_CreateConnection - invalid SCN"); - return (PORT_INVALID_SCN); - } +int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server, + uint16_t mtu, BD_ADDR bd_addr, uint16_t* p_handle, + tPORT_CALLBACK* p_mgmt_cb) { + tPORT* p_port; + int i; + uint8_t dlci; + tRFC_MCB* p_mcb = port_find_mcb(bd_addr); + uint16_t rfcomm_mtu; + + RFCOMM_TRACE_API( + "RFCOMM_CreateConnection() BDA: %02x-%02x-%02x-%02x-%02x-%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + + *p_handle = 0; + + if ((scn == 0) || (scn >= PORT_MAX_RFC_PORTS)) { + /* Server Channel Number(SCN) should be in range 1...30 */ + RFCOMM_TRACE_ERROR("RFCOMM_CreateConnection - invalid SCN"); + return (PORT_INVALID_SCN); + } - /* For client that originate connection on the existing none initiator */ - /* multiplexer channel DLCI should be odd */ - if (p_mcb && !p_mcb->is_initiator && !is_server) - dlci = (scn << 1) + 1; - else - dlci = (scn << 1); - RFCOMM_TRACE_API("RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, p_mcb:%p", - scn, dlci, is_server, mtu, p_mcb); - - /* For the server side always allocate a new port. On the client side */ - /* do not allow the same (dlci, bd_addr) to be opened twice by application */ - if (!is_server && ((p_port = port_find_port (dlci, bd_addr)) != NULL)) - { - /* if existing port is also a client port */ - if (p_port->is_server == false) - { - RFCOMM_TRACE_ERROR ("RFCOMM_CreateConnection - already opened state:%d, RFC state:%d, MCB state:%d", - p_port->state, p_port->rfc.state, p_port->rfc.p_mcb ? p_port->rfc.p_mcb->state : 0); - *p_handle = p_port->inx; - return (PORT_ALREADY_OPENED); - } + /* For client that originate connection on the existing none initiator */ + /* multiplexer channel DLCI should be odd */ + if (p_mcb && !p_mcb->is_initiator && !is_server) + dlci = (scn << 1) + 1; + else + dlci = (scn << 1); + RFCOMM_TRACE_API( + "RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, " + "p_mcb:%p", + scn, dlci, is_server, mtu, p_mcb); + + /* For the server side always allocate a new port. On the client side */ + /* do not allow the same (dlci, bd_addr) to be opened twice by application */ + if (!is_server && ((p_port = port_find_port(dlci, bd_addr)) != NULL)) { + /* if existing port is also a client port */ + if (p_port->is_server == false) { + RFCOMM_TRACE_ERROR( + "RFCOMM_CreateConnection - already opened state:%d, RFC state:%d, " + "MCB state:%d", + p_port->state, p_port->rfc.state, + p_port->rfc.p_mcb ? p_port->rfc.p_mcb->state : 0); + *p_handle = p_port->inx; + return (PORT_ALREADY_OPENED); } + } - p_port = port_allocate_port(dlci, bd_addr); - if (p_port == NULL) - { - RFCOMM_TRACE_WARNING ("RFCOMM_CreateConnection - no resources"); - return (PORT_NO_RESOURCES); - } - RFCOMM_TRACE_API("RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, p_mcb:%p, p_port:%p", - scn, dlci, is_server, mtu, p_mcb, p_port); + p_port = port_allocate_port(dlci, bd_addr); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("RFCOMM_CreateConnection - no resources"); + return (PORT_NO_RESOURCES); + } + RFCOMM_TRACE_API( + "RFCOMM_CreateConnection(): scn:%d, dlci:%d, is_server:%d mtu:%d, " + "p_mcb:%p, p_port:%p", + scn, dlci, is_server, mtu, p_mcb, p_port); - p_port->default_signal_state = (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); + p_port->default_signal_state = + (PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); - switch (uuid) - { + switch (uuid) { case UUID_PROTOCOL_OBEX: - p_port->default_signal_state = PORT_OBEX_DEFAULT_SIGNAL_STATE; - break; + p_port->default_signal_state = PORT_OBEX_DEFAULT_SIGNAL_STATE; + break; case UUID_SERVCLASS_SERIAL_PORT: - p_port->default_signal_state = PORT_SPP_DEFAULT_SIGNAL_STATE; - break; + p_port->default_signal_state = PORT_SPP_DEFAULT_SIGNAL_STATE; + break; case UUID_SERVCLASS_LAN_ACCESS_USING_PPP: - p_port->default_signal_state = PORT_PPP_DEFAULT_SIGNAL_STATE; - break; + p_port->default_signal_state = PORT_PPP_DEFAULT_SIGNAL_STATE; + break; case UUID_SERVCLASS_DIALUP_NETWORKING: case UUID_SERVCLASS_FAX: - p_port->default_signal_state = PORT_DUN_DEFAULT_SIGNAL_STATE; - break; - } + p_port->default_signal_state = PORT_DUN_DEFAULT_SIGNAL_STATE; + break; + } - RFCOMM_TRACE_EVENT ("RFCOMM_CreateConnection dlci:%d signal state:0x%x", dlci, p_port->default_signal_state); + RFCOMM_TRACE_EVENT("RFCOMM_CreateConnection dlci:%d signal state:0x%x", dlci, + p_port->default_signal_state); - *p_handle = p_port->inx; + *p_handle = p_port->inx; - p_port->state = PORT_STATE_OPENING; - p_port->uuid = uuid; - p_port->is_server = is_server; - p_port->scn = scn; - p_port->ev_mask = 0; + p_port->state = PORT_STATE_OPENING; + p_port->uuid = uuid; + p_port->is_server = is_server; + p_port->scn = scn; + p_port->ev_mask = 0; - /* If the MTU is not specified (0), keep MTU decision until the - * PN frame has to be send - * at that time connection should be established and we - * will know for sure our prefered MTU - */ + /* If the MTU is not specified (0), keep MTU decision until the + * PN frame has to be send + * at that time connection should be established and we + * will know for sure our prefered MTU + */ - rfcomm_mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD; + rfcomm_mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD; - if (mtu) - p_port->mtu = (mtu < rfcomm_mtu) ? mtu : rfcomm_mtu; - else - p_port->mtu = rfcomm_mtu; + if (mtu) + p_port->mtu = (mtu < rfcomm_mtu) ? mtu : rfcomm_mtu; + else + p_port->mtu = rfcomm_mtu; - /* server doesn't need to release port when closing */ - if( is_server ) - { - p_port->keep_port_handle = true; + /* server doesn't need to release port when closing */ + if (is_server) { + p_port->keep_port_handle = true; - /* keep mtu that user asked, p_port->mtu could be updated during param negotiation */ - p_port->keep_mtu = p_port->mtu; - } + /* keep mtu that user asked, p_port->mtu could be updated during param + * negotiation */ + p_port->keep_mtu = p_port->mtu; + } - p_port->local_ctrl.modem_signal = p_port->default_signal_state; - p_port->local_ctrl.fc = false; + p_port->local_ctrl.modem_signal = p_port->default_signal_state; + p_port->local_ctrl.fc = false; - p_port->p_mgmt_callback = p_mgmt_cb; + p_port->p_mgmt_callback = p_mgmt_cb; - for (i = 0; i < BD_ADDR_LEN; i++) - p_port->bd_addr[i] = bd_addr[i]; + for (i = 0; i < BD_ADDR_LEN; i++) p_port->bd_addr[i] = bd_addr[i]; - /* If this is not initiator of the connection need to just wait */ - if (p_port->is_server) - { - return (PORT_SUCCESS); - } + /* If this is not initiator of the connection need to just wait */ + if (p_port->is_server) { + return (PORT_SUCCESS); + } - /* Open will be continued after security checks are passed */ - return port_open_continue (p_port); + /* Open will be continued after security checks are passed */ + return port_open_continue(p_port); } /******************************************************************************* @@ -242,32 +245,28 @@ int RFCOMM_CreateConnection (uint16_t uuid, uint8_t scn, bool is_server, * Parameters: handle - Handle returned in the RFCOMM_CreateConnection * ******************************************************************************/ -int RFCOMM_RemoveConnection (uint16_t handle) -{ - tPORT *p_port; - +int RFCOMM_RemoveConnection(uint16_t handle) { + tPORT* p_port; - RFCOMM_TRACE_API ("RFCOMM_RemoveConnection() handle:%d", handle); + RFCOMM_TRACE_API("RFCOMM_RemoveConnection() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - RFCOMM_TRACE_ERROR ("RFCOMM_RemoveConnection() BAD handle:%d", handle); - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + RFCOMM_TRACE_ERROR("RFCOMM_RemoveConnection() BAD handle:%d", handle); + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - RFCOMM_TRACE_EVENT ("RFCOMM_RemoveConnection() Not opened:%d", handle); - return (PORT_SUCCESS); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + RFCOMM_TRACE_EVENT("RFCOMM_RemoveConnection() Not opened:%d", handle); + return (PORT_SUCCESS); + } - p_port->state = PORT_STATE_CLOSING; + p_port->state = PORT_STATE_CLOSING; - port_start_close (p_port); + port_start_close(p_port); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -279,36 +278,33 @@ int RFCOMM_RemoveConnection (uint16_t handle) * Parameters: handle - Handle returned in the RFCOMM_CreateConnection * ******************************************************************************/ -int RFCOMM_RemoveServer (uint16_t handle) -{ - tPORT *p_port; +int RFCOMM_RemoveServer(uint16_t handle) { + tPORT* p_port; - RFCOMM_TRACE_API ("RFCOMM_RemoveServer() handle:%d", handle); + RFCOMM_TRACE_API("RFCOMM_RemoveServer() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - RFCOMM_TRACE_ERROR ("RFCOMM_RemoveServer() BAD handle:%d", handle); - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + RFCOMM_TRACE_ERROR("RFCOMM_RemoveServer() BAD handle:%d", handle); + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - /* Do not report any events to the client any more. */ - p_port->p_mgmt_callback = NULL; + /* Do not report any events to the client any more. */ + p_port->p_mgmt_callback = NULL; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - RFCOMM_TRACE_EVENT ("RFCOMM_RemoveServer() Not opened:%d", handle); - return (PORT_SUCCESS); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + RFCOMM_TRACE_EVENT("RFCOMM_RemoveServer() Not opened:%d", handle); + return (PORT_SUCCESS); + } - /* this port will be deallocated after closing */ - p_port->keep_port_handle = false; - p_port->state = PORT_STATE_CLOSING; + /* this port will be deallocated after closing */ + p_port->keep_port_handle = false; + p_port->state = PORT_STATE_CLOSING; - port_start_close (p_port); + port_start_close(p_port); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -326,28 +322,25 @@ int RFCOMM_RemoveServer (uint16_t handle) * * ******************************************************************************/ -int PORT_SetEventCallback (uint16_t port_handle, tPORT_CALLBACK *p_port_cb) -{ - tPORT *p_port; +int PORT_SetEventCallback(uint16_t port_handle, tPORT_CALLBACK* p_port_cb) { + tPORT* p_port; - /* Check if handle is valid to avoid crashing */ - if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[port_handle - 1]; + p_port = &rfc_cb.port.port[port_handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - RFCOMM_TRACE_API ("PORT_SetEventCallback() handle:%d", port_handle); + RFCOMM_TRACE_API("PORT_SetEventCallback() handle:%d", port_handle); - p_port->p_callback = p_port_cb; + p_port->p_callback = p_port_cb; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* * @@ -359,19 +352,17 @@ int PORT_SetEventCallback (uint16_t port_handle, tPORT_CALLBACK *p_port_cb) * ******************************************************************************/ -int PORT_ClearKeepHandleFlag (uint16_t port_handle) -{ - tPORT *p_port; +int PORT_ClearKeepHandleFlag(uint16_t port_handle) { + tPORT* p_port; - /* Check if handle is valid to avoid crashing */ - if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[port_handle - 1]; - p_port->keep_port_handle = 0; - return (PORT_SUCCESS); + p_port = &rfc_cb.port.port[port_handle - 1]; + p_port->keep_port_handle = 0; + return (PORT_SUCCESS); } /******************************************************************************* @@ -387,28 +378,26 @@ int PORT_ClearKeepHandleFlag (uint16_t port_handle) * * ******************************************************************************/ -int PORT_SetDataCallback (uint16_t port_handle, tPORT_DATA_CALLBACK *p_port_cb) -{ - tPORT *p_port; +int PORT_SetDataCallback(uint16_t port_handle, tPORT_DATA_CALLBACK* p_port_cb) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_SetDataCallback() handle:%d cb 0x%x", port_handle, p_port_cb); + RFCOMM_TRACE_API("PORT_SetDataCallback() handle:%d cb 0x%x", port_handle, + p_port_cb); - /* Check if handle is valid to avoid crashing */ - if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[port_handle - 1]; + p_port = &rfc_cb.port.port[port_handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - p_port->p_data_callback = p_port_cb; + p_port->p_data_callback = p_port_cb; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* * @@ -423,28 +412,27 @@ int PORT_SetDataCallback (uint16_t port_handle, tPORT_DATA_CALLBACK *p_port_cb) * * ******************************************************************************/ -int PORT_SetDataCOCallback (uint16_t port_handle, tPORT_DATA_CO_CALLBACK *p_port_cb) -{ - tPORT *p_port; +int PORT_SetDataCOCallback(uint16_t port_handle, + tPORT_DATA_CO_CALLBACK* p_port_cb) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_SetDataCOCallback() handle:%d cb 0x%x", port_handle, p_port_cb); + RFCOMM_TRACE_API("PORT_SetDataCOCallback() handle:%d cb 0x%x", port_handle, + p_port_cb); - /* Check if handle is valid to avoid crashing */ - if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[port_handle - 1]; + p_port = &rfc_cb.port.port[port_handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - p_port->p_data_co_callback = p_port_cb; + p_port->p_data_co_callback = p_port_cb; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -457,28 +445,26 @@ int PORT_SetDataCOCallback (uint16_t port_handle, tPORT_DATA_CO_CALLBACK *p_port * mask - Bitmask of the events the host is interested in * ******************************************************************************/ -int PORT_SetEventMask (uint16_t port_handle, uint32_t mask) -{ - tPORT *p_port; +int PORT_SetEventMask(uint16_t port_handle, uint32_t mask) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_SetEventMask() handle:%d mask:0x%x", port_handle, mask); + RFCOMM_TRACE_API("PORT_SetEventMask() handle:%d mask:0x%x", port_handle, + mask); - /* Check if handle is valid to avoid crashing */ - if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[port_handle - 1]; + p_port = &rfc_cb.port.port[port_handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - p_port->ev_mask = mask; + p_port->ev_mask = mask; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -493,37 +479,31 @@ int PORT_SetEventMask (uint16_t port_handle, uint32_t mask) * p_lcid - OUT L2CAP's LCID * ******************************************************************************/ -int PORT_CheckConnection (uint16_t handle, BD_ADDR bd_addr, uint16_t *p_lcid) -{ - tPORT *p_port; +int PORT_CheckConnection(uint16_t handle, BD_ADDR bd_addr, uint16_t* p_lcid) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_CheckConnection() handle:%d", handle); + RFCOMM_TRACE_API("PORT_CheckConnection() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (!p_port->rfc.p_mcb - || !p_port->rfc.p_mcb->peer_ready - || (p_port->rfc.state != RFC_STATE_OPENED)) - { - return (PORT_LINE_ERR); - } + if (!p_port->rfc.p_mcb || !p_port->rfc.p_mcb->peer_ready || + (p_port->rfc.state != RFC_STATE_OPENED)) { + return (PORT_LINE_ERR); + } - memcpy (bd_addr, p_port->rfc.p_mcb->bd_addr, BD_ADDR_LEN); - if (p_lcid) - *p_lcid = p_port->rfc.p_mcb->lcid; + memcpy(bd_addr, p_port->rfc.p_mcb->bd_addr, BD_ADDR_LEN); + if (p_lcid) *p_lcid = p_port->rfc.p_mcb->lcid; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -537,49 +517,42 @@ int PORT_CheckConnection (uint16_t handle, BD_ADDR bd_addr, uint16_t *p_lcid) * bd_addr - bd_addr of the peer * ******************************************************************************/ -bool PORT_IsOpening (BD_ADDR bd_addr) -{ - uint8_t xx, yy; - tRFC_MCB *p_mcb = NULL; - tPORT *p_port; - bool found_port; - - /* Check for any rfc_mcb which is in the middle of opening. */ - for (xx = 0; xx < MAX_BD_CONNECTIONS; xx++) - { - if ((rfc_cb.port.rfc_mcb[xx].state > RFC_MX_STATE_IDLE) && - (rfc_cb.port.rfc_mcb[xx].state < RFC_MX_STATE_CONNECTED)) - { - memcpy (bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); - return true; +bool PORT_IsOpening(BD_ADDR bd_addr) { + uint8_t xx, yy; + tRFC_MCB* p_mcb = NULL; + tPORT* p_port; + bool found_port; + + /* Check for any rfc_mcb which is in the middle of opening. */ + for (xx = 0; xx < MAX_BD_CONNECTIONS; xx++) { + if ((rfc_cb.port.rfc_mcb[xx].state > RFC_MX_STATE_IDLE) && + (rfc_cb.port.rfc_mcb[xx].state < RFC_MX_STATE_CONNECTED)) { + memcpy(bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); + return true; + } + + if (rfc_cb.port.rfc_mcb[xx].state == RFC_MX_STATE_CONNECTED) { + found_port = false; + p_mcb = &rfc_cb.port.rfc_mcb[xx]; + p_port = &rfc_cb.port.port[0]; + + for (yy = 0; yy < MAX_RFC_PORTS; yy++, p_port++) { + if (p_port->rfc.p_mcb == p_mcb) { + found_port = true; + break; } + } - if (rfc_cb.port.rfc_mcb[xx].state == RFC_MX_STATE_CONNECTED) - { - found_port = false; - p_mcb = &rfc_cb.port.rfc_mcb[xx]; - p_port = &rfc_cb.port.port[0]; - - for (yy = 0; yy < MAX_RFC_PORTS; yy++, p_port++) - { - if (p_port->rfc.p_mcb == p_mcb) - { - found_port = true; - break; - } - } - - if ((!found_port) || - (found_port && (p_port->rfc.state < RFC_STATE_OPENED))) - { - /* Port is not established yet. */ - memcpy (bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); - return true; - } - } + if ((!found_port) || + (found_port && (p_port->rfc.state < RFC_STATE_OPENED))) { + /* Port is not established yet. */ + memcpy(bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN); + return true; + } } + } - return false; + return false; } /******************************************************************************* @@ -595,43 +568,38 @@ bool PORT_IsOpening (BD_ADDR bd_addr) * * ******************************************************************************/ -int PORT_SetState (uint16_t handle, tPORT_STATE *p_settings) -{ - tPORT *p_port; - uint8_t baud_rate; +int PORT_SetState(uint16_t handle, tPORT_STATE* p_settings) { + tPORT* p_port; + uint8_t baud_rate; - RFCOMM_TRACE_API ("PORT_SetState() handle:%d", handle); + RFCOMM_TRACE_API("PORT_SetState() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + return (PORT_LINE_ERR); + } - RFCOMM_TRACE_API ("PORT_SetState() handle:%d FC_TYPE:0x%x", handle, - p_settings->fc_type); + RFCOMM_TRACE_API("PORT_SetState() handle:%d FC_TYPE:0x%x", handle, + p_settings->fc_type); - baud_rate = p_port->user_port_pars.baud_rate; - p_port->user_port_pars = *p_settings; + baud_rate = p_port->user_port_pars.baud_rate; + p_port->user_port_pars = *p_settings; - /* for now we've been asked to pass only baud rate */ - if (baud_rate != p_settings->baud_rate) - { - port_start_par_neg (p_port); - } - return (PORT_SUCCESS); + /* for now we've been asked to pass only baud rate */ + if (baud_rate != p_settings->baud_rate) { + port_start_par_neg(p_port); + } + return (PORT_SUCCESS); } /******************************************************************************* @@ -644,36 +612,33 @@ int PORT_SetState (uint16_t handle, tPORT_STATE *p_settings) * p_rx_queue_count - Pointer to return queue count in. * ******************************************************************************/ -int PORT_GetRxQueueCnt (uint16_t handle, uint16_t *p_rx_queue_count) -{ - tPORT *p_port; +int PORT_GetRxQueueCnt(uint16_t handle, uint16_t* p_rx_queue_count) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_GetRxQueueCnt() handle:%d", handle); + RFCOMM_TRACE_API("PORT_GetRxQueueCnt() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + return (PORT_LINE_ERR); + } - *p_rx_queue_count = p_port->rx.queue_size; + *p_rx_queue_count = p_port->rx.queue_size; - RFCOMM_TRACE_API ("PORT_GetRxQueueCnt() p_rx_queue_count:%d, p_port->rx.queue.count = %d", - *p_rx_queue_count, p_port->rx.queue_size); + RFCOMM_TRACE_API( + "PORT_GetRxQueueCnt() p_rx_queue_count:%d, p_port->rx.queue.count = %d", + *p_rx_queue_count, p_port->rx.queue_size); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -688,32 +653,28 @@ int PORT_GetRxQueueCnt (uint16_t handle, uint16_t *p_rx_queue_count) * configuration information is returned. * ******************************************************************************/ -int PORT_GetState (uint16_t handle, tPORT_STATE *p_settings) -{ - tPORT *p_port; +int PORT_GetState(uint16_t handle, tPORT_STATE* p_settings) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_GetState() handle:%d", handle); + RFCOMM_TRACE_API("PORT_GetState() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + return (PORT_LINE_ERR); + } - *p_settings = p_port->user_port_pars; - return (PORT_SUCCESS); + *p_settings = p_port->user_port_pars; + return (PORT_SUCCESS); } /******************************************************************************* @@ -727,78 +688,75 @@ int PORT_GetState (uint16_t handle, tPORT_STATE *p_settings) * signal = specify the function to be passed * ******************************************************************************/ -int PORT_Control (uint16_t handle, uint8_t signal) -{ - tPORT *p_port; - uint8_t old_modem_signal; +int PORT_Control(uint16_t handle, uint8_t signal) { + tPORT* p_port; + uint8_t old_modem_signal; - RFCOMM_TRACE_API ("PORT_Control() handle:%d signal:0x%x", handle, signal); + RFCOMM_TRACE_API("PORT_Control() handle:%d signal:0x%x", handle, signal); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - old_modem_signal = p_port->local_ctrl.modem_signal; - p_port->local_ctrl.break_signal = 0; + old_modem_signal = p_port->local_ctrl.modem_signal; + p_port->local_ctrl.break_signal = 0; - switch (signal) - { + switch (signal) { case PORT_SET_CTSRTS: - p_port->local_ctrl.modem_signal |= PORT_CTSRTS_ON; - break; + p_port->local_ctrl.modem_signal |= PORT_CTSRTS_ON; + break; case PORT_CLR_CTSRTS: - p_port->local_ctrl.modem_signal &= ~PORT_CTSRTS_ON; - break; + p_port->local_ctrl.modem_signal &= ~PORT_CTSRTS_ON; + break; case PORT_SET_DTRDSR: - p_port->local_ctrl.modem_signal |= PORT_DTRDSR_ON; - break; + p_port->local_ctrl.modem_signal |= PORT_DTRDSR_ON; + break; case PORT_CLR_DTRDSR: - p_port->local_ctrl.modem_signal &= ~PORT_DTRDSR_ON; - break; + p_port->local_ctrl.modem_signal &= ~PORT_DTRDSR_ON; + break; case PORT_SET_RI: - p_port->local_ctrl.modem_signal |= PORT_RING_ON; - break; + p_port->local_ctrl.modem_signal |= PORT_RING_ON; + break; case PORT_CLR_RI: - p_port->local_ctrl.modem_signal &= ~PORT_RING_ON; - break; + p_port->local_ctrl.modem_signal &= ~PORT_RING_ON; + break; case PORT_SET_DCD: - p_port->local_ctrl.modem_signal |= PORT_DCD_ON; - break; + p_port->local_ctrl.modem_signal |= PORT_DCD_ON; + break; case PORT_CLR_DCD: - p_port->local_ctrl.modem_signal &= ~PORT_DCD_ON; - break; - } + p_port->local_ctrl.modem_signal &= ~PORT_DCD_ON; + break; + } - if (signal == PORT_BREAK) - p_port->local_ctrl.break_signal = PORT_BREAK_DURATION; - else if (p_port->local_ctrl.modem_signal == old_modem_signal) - return (PORT_SUCCESS); + if (signal == PORT_BREAK) + p_port->local_ctrl.break_signal = PORT_BREAK_DURATION; + else if (p_port->local_ctrl.modem_signal == old_modem_signal) + return (PORT_SUCCESS); - port_start_control (p_port); + port_start_control(p_port); - RFCOMM_TRACE_EVENT ("PORT_Control DTR_DSR : %d, RTS_CTS : %d, RI : %d, DCD : %d", - ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_DTRDSR) ? 1 : 0), - ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_RTSCTS) ? 1 : 0), - ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_RI) ? 1 : 0), - ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_DCD) ? 1 : 0)); + RFCOMM_TRACE_EVENT( + "PORT_Control DTR_DSR : %d, RTS_CTS : %d, RI : %d, DCD : %d", + ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_DTRDSR) ? 1 : 0), + ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_RTSCTS) ? 1 : 0), + ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_RI) ? 1 : 0), + ((p_port->local_ctrl.modem_signal & MODEM_SIGNAL_DCD) ? 1 : 0)); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -813,70 +771,58 @@ int PORT_Control (uint16_t handle, uint8_t signal) * enable - enables data flow * ******************************************************************************/ -int PORT_FlowControl (uint16_t handle, bool enable) -{ - tPORT *p_port; - bool old_fc; - uint32_t events; +int PORT_FlowControl(uint16_t handle, bool enable) { + tPORT* p_port; + bool old_fc; + uint32_t events; - RFCOMM_TRACE_API ("PORT_FlowControl() handle:%d enable: %d", handle, enable); + RFCOMM_TRACE_API("PORT_FlowControl() handle:%d enable: %d", handle, enable); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (!p_port->rfc.p_mcb) - { - return (PORT_NOT_OPENED); - } + if (!p_port->rfc.p_mcb) { + return (PORT_NOT_OPENED); + } - p_port->rx.user_fc = !enable; + p_port->rx.user_fc = !enable; - if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - { - if (!p_port->rx.user_fc) - { - port_flow_control_peer(p_port, true, 0); - } + if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { + if (!p_port->rx.user_fc) { + port_flow_control_peer(p_port, true, 0); } - else - { - old_fc = p_port->local_ctrl.fc; + } else { + old_fc = p_port->local_ctrl.fc; - /* FC is set if user is set or peer is set */ - p_port->local_ctrl.fc = (p_port->rx.user_fc | p_port->rx.peer_fc); + /* FC is set if user is set or peer is set */ + p_port->local_ctrl.fc = (p_port->rx.user_fc | p_port->rx.peer_fc); - if (p_port->local_ctrl.fc != old_fc) - port_start_control (p_port); - } + if (p_port->local_ctrl.fc != old_fc) port_start_control(p_port); + } - /* Need to take care of the case when we could not deliver events */ - /* to the application because we were flow controlled */ - if (enable && (p_port->rx.queue_size != 0)) - { - events = PORT_EV_RXCHAR; - if (p_port->rx_flag_ev_pending) - { - p_port->rx_flag_ev_pending = false; - events |= PORT_EV_RXFLAG; - } + /* Need to take care of the case when we could not deliver events */ + /* to the application because we were flow controlled */ + if (enable && (p_port->rx.queue_size != 0)) { + events = PORT_EV_RXCHAR; + if (p_port->rx_flag_ev_pending) { + p_port->rx_flag_ev_pending = false; + events |= PORT_EV_RXFLAG; + } - events &= p_port->ev_mask; - if (p_port->p_callback && events) - { - p_port->p_callback (events, p_port->inx); - } + events &= p_port->ev_mask; + if (p_port->p_callback && events) { + p_port->p_callback(events, p_port->inx); } - return (PORT_SUCCESS); + } + return (PORT_SUCCESS); } /******************************************************************************* * @@ -892,70 +838,58 @@ int PORT_FlowControl (uint16_t handle, bool enable) * ******************************************************************************/ -int PORT_FlowControl_MaxCredit (uint16_t handle, bool enable) -{ - tPORT *p_port; - bool old_fc; - uint32_t events; +int PORT_FlowControl_MaxCredit(uint16_t handle, bool enable) { + tPORT* p_port; + bool old_fc; + uint32_t events; - RFCOMM_TRACE_API ("PORT_FlowControl() handle:%d enable: %d", handle, enable); + RFCOMM_TRACE_API("PORT_FlowControl() handle:%d enable: %d", handle, enable); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (!p_port->rfc.p_mcb) - { - return (PORT_NOT_OPENED); - } + if (!p_port->rfc.p_mcb) { + return (PORT_NOT_OPENED); + } - p_port->rx.user_fc = !enable; + p_port->rx.user_fc = !enable; - if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - { - if (!p_port->rx.user_fc) - { - port_flow_control_peer(p_port, true, p_port->credit_rx); - } + if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { + if (!p_port->rx.user_fc) { + port_flow_control_peer(p_port, true, p_port->credit_rx); } - else - { - old_fc = p_port->local_ctrl.fc; + } else { + old_fc = p_port->local_ctrl.fc; - /* FC is set if user is set or peer is set */ - p_port->local_ctrl.fc = (p_port->rx.user_fc | p_port->rx.peer_fc); + /* FC is set if user is set or peer is set */ + p_port->local_ctrl.fc = (p_port->rx.user_fc | p_port->rx.peer_fc); - if (p_port->local_ctrl.fc != old_fc) - port_start_control (p_port); - } + if (p_port->local_ctrl.fc != old_fc) port_start_control(p_port); + } - /* Need to take care of the case when we could not deliver events */ - /* to the application because we were flow controlled */ - if (enable && (p_port->rx.queue_size != 0)) - { - events = PORT_EV_RXCHAR; - if (p_port->rx_flag_ev_pending) - { - p_port->rx_flag_ev_pending = false; - events |= PORT_EV_RXFLAG; - } + /* Need to take care of the case when we could not deliver events */ + /* to the application because we were flow controlled */ + if (enable && (p_port->rx.queue_size != 0)) { + events = PORT_EV_RXCHAR; + if (p_port->rx_flag_ev_pending) { + p_port->rx_flag_ev_pending = false; + events |= PORT_EV_RXFLAG; + } - events &= p_port->ev_mask; - if (p_port->p_callback && events) - { - p_port->p_callback (events, p_port->inx); - } + events &= p_port->ev_mask; + if (p_port->p_callback && events) { + p_port->p_callback(events, p_port->inx); } - return (PORT_SUCCESS); + } + return (PORT_SUCCESS); } /******************************************************************************* @@ -971,27 +905,25 @@ int PORT_FlowControl_MaxCredit (uint16_t handle, bool enable) * p_signal - specify the pointer to control signals info * ******************************************************************************/ -int PORT_GetModemStatus (uint16_t handle, uint8_t *p_signal) -{ - tPORT *p_port; +int PORT_GetModemStatus(uint16_t handle, uint8_t* p_signal) { + tPORT* p_port; - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - *p_signal = p_port->peer_ctrl.modem_signal; + *p_signal = p_port->peer_ctrl.modem_signal; - RFCOMM_TRACE_API ("PORT_GetModemStatus() handle:%d signal:%x", handle, *p_signal); + RFCOMM_TRACE_API("PORT_GetModemStatus() handle:%d signal:%x", handle, + *p_signal); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1010,32 +942,31 @@ int PORT_GetModemStatus (uint16_t handle, uint8_t *p_signal) * connection status * ******************************************************************************/ -int PORT_ClearError (uint16_t handle, uint16_t *p_errors, tPORT_STATUS *p_status) -{ - tPORT *p_port; +int PORT_ClearError(uint16_t handle, uint16_t* p_errors, + tPORT_STATUS* p_status) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_ClearError() handle:%d", handle); + RFCOMM_TRACE_API("PORT_ClearError() handle:%d", handle); - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - *p_errors = p_port->line_status; + *p_errors = p_port->line_status; - /* This is the only call to clear error status. We can not clear */ - /* connection failed status. To clean it port should be closed and reopened */ - p_port->line_status = (p_port->line_status & LINE_STATUS_FAILED); + /* This is the only call to clear error status. We can not clear */ + /* connection failed status. To clean it port should be closed and reopened + */ + p_port->line_status = (p_port->line_status & LINE_STATUS_FAILED); - PORT_GetQueueStatus (handle, p_status); - return (PORT_SUCCESS); + PORT_GetQueueStatus(handle, p_status); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1048,31 +979,27 @@ int PORT_ClearError (uint16_t handle, uint16_t *p_errors, tPORT_STATUS *p_status * errors - receive error codes * ******************************************************************************/ -int PORT_SendError (uint16_t handle, uint8_t errors) -{ - tPORT *p_port; +int PORT_SendError(uint16_t handle, uint8_t errors) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_SendError() handle:%d errors:0x%x", handle, errors); + RFCOMM_TRACE_API("PORT_SendError() handle:%d errors:0x%x", handle, errors); - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (!p_port->rfc.p_mcb) - { - return (PORT_NOT_OPENED); - } + if (!p_port->rfc.p_mcb) { + return (PORT_NOT_OPENED); + } - RFCOMM_LineStatusReq (p_port->rfc.p_mcb, p_port->dlci, errors); - return (PORT_SUCCESS); + RFCOMM_LineStatusReq(p_port->rfc.p_mcb, p_port->dlci, errors); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1086,41 +1013,38 @@ int PORT_SendError (uint16_t handle, uint8_t errors) * connection status * ******************************************************************************/ -int PORT_GetQueueStatus (uint16_t handle, tPORT_STATUS *p_status) -{ - tPORT *p_port; +int PORT_GetQueueStatus(uint16_t handle, tPORT_STATUS* p_status) { + tPORT* p_port; - /* RFCOMM_TRACE_API ("PORT_GetQueueStatus() handle:%d", handle); */ + /* RFCOMM_TRACE_API ("PORT_GetQueueStatus() handle:%d", handle); */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - p_status->in_queue_size = (uint16_t) p_port->rx.queue_size; - p_status->out_queue_size = (uint16_t) p_port->tx.queue_size; + p_status->in_queue_size = (uint16_t)p_port->rx.queue_size; + p_status->out_queue_size = (uint16_t)p_port->tx.queue_size; - p_status->mtu_size = (uint16_t) p_port->peer_mtu; + p_status->mtu_size = (uint16_t)p_port->peer_mtu; - p_status->flags = 0; + p_status->flags = 0; - if (!(p_port->peer_ctrl.modem_signal & PORT_CTSRTS_ON)) - p_status->flags |= PORT_FLAG_CTS_HOLD; + if (!(p_port->peer_ctrl.modem_signal & PORT_CTSRTS_ON)) + p_status->flags |= PORT_FLAG_CTS_HOLD; - if (!(p_port->peer_ctrl.modem_signal & PORT_DTRDSR_ON)) - p_status->flags |= PORT_FLAG_DSR_HOLD; + if (!(p_port->peer_ctrl.modem_signal & PORT_DTRDSR_ON)) + p_status->flags |= PORT_FLAG_DSR_HOLD; - if (!(p_port->peer_ctrl.modem_signal & PORT_DCD_ON)) - p_status->flags |= PORT_FLAG_RLSD_HOLD; + if (!(p_port->peer_ctrl.modem_signal & PORT_DCD_ON)) + p_status->flags |= PORT_FLAG_RLSD_HOLD; - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1134,68 +1058,62 @@ int PORT_GetQueueStatus (uint16_t handle, tPORT_STATUS *p_status) * purge_flags - specify the action to take. * ******************************************************************************/ -int PORT_Purge (uint16_t handle, uint8_t purge_flags) -{ - tPORT *p_port; - BT_HDR *p_buf; - uint16_t count; - uint32_t events; +int PORT_Purge(uint16_t handle, uint8_t purge_flags) { + tPORT* p_port; + BT_HDR* p_buf; + uint16_t count; + uint32_t events; - RFCOMM_TRACE_API ("PORT_Purge() handle:%d flags:0x%x", handle, purge_flags); + RFCOMM_TRACE_API("PORT_Purge() handle:%d flags:0x%x", handle, purge_flags); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (purge_flags & PORT_PURGE_RXCLEAR) - { - mutex_global_lock(); /* to prevent missing credit */ + if (purge_flags & PORT_PURGE_RXCLEAR) { + mutex_global_lock(); /* to prevent missing credit */ - count = fixed_queue_length(p_port->rx.queue); + count = fixed_queue_length(p_port->rx.queue); - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) - osi_free(p_buf); + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) + osi_free(p_buf); - p_port->rx.queue_size = 0; + p_port->rx.queue_size = 0; - mutex_global_unlock(); + mutex_global_unlock(); - /* If we flowed controlled peer based on rx_queue size enable data again */ - if (count) - port_flow_control_peer (p_port, true, count); - } + /* If we flowed controlled peer based on rx_queue size enable data again */ + if (count) port_flow_control_peer(p_port, true, count); + } - if (purge_flags & PORT_PURGE_TXCLEAR) - { - mutex_global_lock(); /* to prevent tx.queue_size from being negative */ + if (purge_flags & PORT_PURGE_TXCLEAR) { + mutex_global_lock(); /* to prevent tx.queue_size from being negative */ - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) - osi_free(p_buf); + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) + osi_free(p_buf); - p_port->tx.queue_size = 0; + p_port->tx.queue_size = 0; - mutex_global_unlock(); + mutex_global_unlock(); - events = PORT_EV_TXEMPTY; + events = PORT_EV_TXEMPTY; - events |= port_flow_control_user (p_port); + events |= port_flow_control_user(p_port); - events &= p_port->ev_mask; + events &= p_port->ev_mask; - if ((p_port->p_callback != NULL) && events) - (p_port->p_callback)(events, p_port->inx); - } + if ((p_port->p_callback != NULL) && events) + (p_port->p_callback)(events, p_port->inx); + } - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1211,100 +1129,89 @@ int PORT_Purge (uint16_t handle, uint8_t purge_flags) * p_len - Byte count received * ******************************************************************************/ -int PORT_ReadData (uint16_t handle, char *p_data, uint16_t max_len, uint16_t *p_len) -{ - tPORT *p_port; - BT_HDR *p_buf; - uint16_t count; +int PORT_ReadData(uint16_t handle, char* p_data, uint16_t max_len, + uint16_t* p_len) { + tPORT* p_port; + BT_HDR* p_buf; + uint16_t count; - RFCOMM_TRACE_API ("PORT_ReadData() handle:%d max_len:%d", handle, max_len); + RFCOMM_TRACE_API("PORT_ReadData() handle:%d max_len:%d", handle, max_len); - /* Initialize this in case of an error */ - *p_len = 0; + /* Initialize this in case of an error */ + *p_len = 0; - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + return (PORT_LINE_ERR); + } - if (fixed_queue_is_empty(p_port->rx.queue)) - return (PORT_SUCCESS); + if (fixed_queue_is_empty(p_port->rx.queue)) return (PORT_SUCCESS); - count = 0; + count = 0; - while (max_len) - { - p_buf = (BT_HDR *)fixed_queue_try_peek_first(p_port->rx.queue); - if (p_buf == NULL) - break; + while (max_len) { + p_buf = (BT_HDR*)fixed_queue_try_peek_first(p_port->rx.queue); + if (p_buf == NULL) break; - if (p_buf->len > max_len) - { - memcpy (p_data, (uint8_t *)(p_buf + 1) + p_buf->offset, max_len); - p_buf->offset += max_len; - p_buf->len -= max_len; + if (p_buf->len > max_len) { + memcpy(p_data, (uint8_t*)(p_buf + 1) + p_buf->offset, max_len); + p_buf->offset += max_len; + p_buf->len -= max_len; - *p_len += max_len; + *p_len += max_len; - mutex_global_lock(); + mutex_global_lock(); - p_port->rx.queue_size -= max_len; + p_port->rx.queue_size -= max_len; - mutex_global_unlock(); + mutex_global_unlock(); - break; - } - else - { - memcpy (p_data, (uint8_t *)(p_buf + 1) + p_buf->offset, p_buf->len); + break; + } else { + memcpy(p_data, (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len); - *p_len += p_buf->len; - max_len -= p_buf->len; + *p_len += p_buf->len; + max_len -= p_buf->len; - mutex_global_lock(); + mutex_global_lock(); - p_port->rx.queue_size -= p_buf->len; + p_port->rx.queue_size -= p_buf->len; - if (max_len) - { - p_data += p_buf->len; - } + if (max_len) { + p_data += p_buf->len; + } - osi_free(fixed_queue_try_dequeue(p_port->rx.queue)); + osi_free(fixed_queue_try_dequeue(p_port->rx.queue)); - mutex_global_unlock(); + mutex_global_unlock(); - count++; - } + count++; } + } - if (*p_len == 1) - { - RFCOMM_TRACE_EVENT ("PORT_ReadData queue:%d returned:%d %x", p_port->rx.queue_size, *p_len, (p_data[0])); - } - else - { - RFCOMM_TRACE_EVENT ("PORT_ReadData queue:%d returned:%d", p_port->rx.queue_size, *p_len); - } + if (*p_len == 1) { + RFCOMM_TRACE_EVENT("PORT_ReadData queue:%d returned:%d %x", + p_port->rx.queue_size, *p_len, (p_data[0])); + } else { + RFCOMM_TRACE_EVENT("PORT_ReadData queue:%d returned:%d", + p_port->rx.queue_size, *p_len); + } - /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ - /* check if it can be resumed now */ - port_flow_control_peer (p_port, true, count); + /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ + /* check if it can be resumed now */ + port_flow_control_peer(p_port, true, count); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1318,50 +1225,43 @@ int PORT_ReadData (uint16_t handle, char *p_data, uint16_t max_len, uint16_t *p_ * pp_buf - pointer to address of buffer with data, * ******************************************************************************/ -int PORT_Read (uint16_t handle, BT_HDR **pp_buf) -{ - tPORT *p_port; - BT_HDR *p_buf; +int PORT_Read(uint16_t handle, BT_HDR** pp_buf) { + tPORT* p_port; + BT_HDR* p_buf; - RFCOMM_TRACE_API ("PORT_Read() handle:%d", handle); + RFCOMM_TRACE_API("PORT_Read() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + return (PORT_LINE_ERR); + } - mutex_global_lock(); + mutex_global_lock(); - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue); - if (p_buf) - { - p_port->rx.queue_size -= p_buf->len; + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->rx.queue); + if (p_buf) { + p_port->rx.queue_size -= p_buf->len; - mutex_global_unlock(); + mutex_global_unlock(); - /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ - /* check if it can be resumed now */ - port_flow_control_peer (p_port, true, 1); - } - else - { - mutex_global_unlock(); - } + /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ + /* check if it can be resumed now */ + port_flow_control_peer(p_port, true, 1); + } else { + mutex_global_unlock(); + } - *pp_buf = p_buf; - return (PORT_SUCCESS); + *pp_buf = p_buf; + return (PORT_SUCCESS); } /******************************************************************************* @@ -1375,57 +1275,51 @@ int PORT_Read (uint16_t handle, BT_HDR **pp_buf) * p_buf - pointer to address of buffer with data, * ******************************************************************************/ -static int port_write (tPORT *p_port, BT_HDR *p_buf) -{ - /* We should not allow to write data in to server port when connection is not opened */ - if (p_port->is_server && (p_port->rfc.state != RFC_STATE_OPENED)) - { - osi_free(p_buf); - return (PORT_CLOSED); - } +static int port_write(tPORT* p_port, BT_HDR* p_buf) { + /* We should not allow to write data in to server port when connection is not + * opened */ + if (p_port->is_server && (p_port->rfc.state != RFC_STATE_OPENED)) { + osi_free(p_buf); + return (PORT_CLOSED); + } - /* Keep the data in pending queue if peer does not allow data, or */ - /* Peer is not ready or Port is not yet opened or initial port control */ - /* command has not been sent */ - if (p_port->tx.peer_fc - || !p_port->rfc.p_mcb - || !p_port->rfc.p_mcb->peer_ready - || (p_port->rfc.state != RFC_STATE_OPENED) - || ((p_port->port_ctrl & (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED)) != - (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED))) - { - if ((p_port->tx.queue_size > PORT_TX_CRITICAL_WM) - || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM)) - { - RFCOMM_TRACE_WARNING ("PORT_Write: Queue size: %d", - p_port->tx.queue_size); + /* Keep the data in pending queue if peer does not allow data, or */ + /* Peer is not ready or Port is not yet opened or initial port control */ + /* command has not been sent */ + if (p_port->tx.peer_fc || !p_port->rfc.p_mcb || + !p_port->rfc.p_mcb->peer_ready || + (p_port->rfc.state != RFC_STATE_OPENED) || + ((p_port->port_ctrl & (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED)) != + (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED))) { + if ((p_port->tx.queue_size > PORT_TX_CRITICAL_WM) || + (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM)) { + RFCOMM_TRACE_WARNING("PORT_Write: Queue size: %d", p_port->tx.queue_size); - osi_free(p_buf); + osi_free(p_buf); - if ((p_port->p_callback != NULL) && (p_port->ev_mask & PORT_EV_ERR)) - p_port->p_callback (PORT_EV_ERR, p_port->inx); + if ((p_port->p_callback != NULL) && (p_port->ev_mask & PORT_EV_ERR)) + p_port->p_callback(PORT_EV_ERR, p_port->inx); - return (PORT_TX_FULL); - } + return (PORT_TX_FULL); + } - RFCOMM_TRACE_EVENT ("PORT_Write : Data is enqued. flow disabled %d peer_ready %d state %d ctrl_state %x", - p_port->tx.peer_fc, - (p_port->rfc.p_mcb && p_port->rfc.p_mcb->peer_ready), - p_port->rfc.state, - p_port->port_ctrl); + RFCOMM_TRACE_EVENT( + "PORT_Write : Data is enqued. flow disabled %d peer_ready %d state %d " + "ctrl_state %x", + p_port->tx.peer_fc, + (p_port->rfc.p_mcb && p_port->rfc.p_mcb->peer_ready), p_port->rfc.state, + p_port->port_ctrl); - fixed_queue_enqueue(p_port->tx.queue, p_buf); - p_port->tx.queue_size += p_buf->len; + fixed_queue_enqueue(p_port->tx.queue, p_buf); + p_port->tx.queue_size += p_buf->len; - return (PORT_CMD_PENDING); - } - else - { - RFCOMM_TRACE_EVENT ("PORT_Write : Data is being sent"); + return (PORT_CMD_PENDING); + } else { + RFCOMM_TRACE_EVENT("PORT_Write : Data is being sent"); - RFCOMM_DataReq (p_port->rfc.p_mcb, p_port->dlci, p_buf); - return (PORT_SUCCESS); - } + RFCOMM_DataReq(p_port->rfc.p_mcb, p_port->dlci, p_buf); + return (PORT_SUCCESS); + } } /******************************************************************************* @@ -1439,58 +1333,52 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf) * pp_buf - pointer to address of buffer with data, * ******************************************************************************/ -int PORT_Write (uint16_t handle, BT_HDR *p_buf) -{ - tPORT *p_port; - uint32_t event = 0; - int rc; +int PORT_Write(uint16_t handle, BT_HDR* p_buf) { + tPORT* p_port; + uint32_t event = 0; + int rc; - RFCOMM_TRACE_API ("PORT_Write() handle:%d", handle); + RFCOMM_TRACE_API("PORT_Write() handle:%d", handle); - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - osi_free(p_buf); - return (PORT_BAD_HANDLE); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + osi_free(p_buf); + return (PORT_BAD_HANDLE); + } - p_port = &rfc_cb.port.port[handle - 1]; + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - osi_free(p_buf); - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + osi_free(p_buf); + return (PORT_NOT_OPENED); + } - if (p_port->line_status) - { - RFCOMM_TRACE_WARNING ("PORT_Write: Data dropped line_status:0x%x", - p_port->line_status); - osi_free(p_buf); - return (PORT_LINE_ERR); - } + if (p_port->line_status) { + RFCOMM_TRACE_WARNING("PORT_Write: Data dropped line_status:0x%x", + p_port->line_status); + osi_free(p_buf); + return (PORT_LINE_ERR); + } - rc = port_write (p_port, p_buf); - event |= port_flow_control_user (p_port); + rc = port_write(p_port, p_buf); + event |= port_flow_control_user(p_port); - switch (rc) - { + switch (rc) { case PORT_TX_FULL: - event |= PORT_EV_ERR; - break; + event |= PORT_EV_ERR; + break; case PORT_SUCCESS: - event |= (PORT_EV_TXCHAR | PORT_EV_TXEMPTY); - break; - } - /* Mask out all events that are not of interest to user */ - event &= p_port->ev_mask; + event |= (PORT_EV_TXCHAR | PORT_EV_TXEMPTY); + break; + } + /* Mask out all events that are not of interest to user */ + event &= p_port->ev_mask; - /* Send event to the application */ - if (p_port->p_callback && event) - (p_port->p_callback)(event, p_port->inx); + /* Send event to the application */ + if (p_port->p_callback && event) (p_port->p_callback)(event, p_port->inx); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* * @@ -1504,145 +1392,148 @@ int PORT_Write (uint16_t handle, BT_HDR *p_buf) * p_len - Byte count returned * ******************************************************************************/ -int PORT_WriteDataCO (uint16_t handle, int* p_len) -{ +int PORT_WriteDataCO(uint16_t handle, int* p_len) { + tPORT* p_port; + BT_HDR* p_buf; + uint32_t event = 0; + int rc = 0; + uint16_t length; + + RFCOMM_TRACE_API("PORT_WriteDataCO() handle:%d", handle); + *p_len = 0; + + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - tPORT *p_port; - BT_HDR *p_buf; - uint32_t event = 0; - int rc = 0; - uint16_t length; + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + RFCOMM_TRACE_WARNING("PORT_WriteDataByFd() no port state:%d", + p_port->state); + return (PORT_NOT_OPENED); + } - RFCOMM_TRACE_API ("PORT_WriteDataCO() handle:%d", handle); - *p_len = 0; + if (!p_port->peer_mtu) { + RFCOMM_TRACE_ERROR("PORT_WriteDataByFd() peer_mtu:%d", p_port->peer_mtu); + return (PORT_UNKNOWN_ERROR); + } + int available = 0; + // if(ioctl(fd, FIONREAD, &available) < 0) + if (p_port->p_data_co_callback( + handle, (uint8_t*)&available, sizeof(available), + DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE) == false) { + RFCOMM_TRACE_ERROR( + "p_data_co_callback DATA_CO_CALLBACK_TYPE_INCOMING_SIZE failed, " + "available:%d", + available); + return (PORT_UNKNOWN_ERROR); + } + if (available == 0) return PORT_SUCCESS; + /* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len + */ + length = RFCOMM_DATA_BUF_SIZE - + (uint16_t)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD); + + /* If there are buffers scheduled for transmission check if requested */ + /* data fits into the end of the queue */ + mutex_global_lock(); + + if (((p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue)) != + NULL) && + (((int)p_buf->len + available) <= (int)p_port->peer_mtu) && + (((int)p_buf->len + available) <= (int)length)) { + // if(recv(fd, (uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, + // available, 0) != available) + if (p_port->p_data_co_callback( + handle, (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len, + available, DATA_CO_CALLBACK_TYPE_OUTGOING) == false) + + { + error( + "p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, " + "available:%d", + available); + mutex_global_unlock(); + return (PORT_UNKNOWN_ERROR); + } + // memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, + // max_len); + p_port->tx.queue_size += (uint16_t)available; + + *p_len = available; + p_buf->len += (uint16_t)available; - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + mutex_global_unlock(); - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - RFCOMM_TRACE_WARNING ("PORT_WriteDataByFd() no port state:%d", p_port->state); - return (PORT_NOT_OPENED); - } + return (PORT_SUCCESS); + } - if (!p_port->peer_mtu) - { - RFCOMM_TRACE_ERROR ("PORT_WriteDataByFd() peer_mtu:%d", p_port->peer_mtu); - return (PORT_UNKNOWN_ERROR); - } - int available = 0; - //if(ioctl(fd, FIONREAD, &available) < 0) - if(p_port->p_data_co_callback(handle, (uint8_t*)&available, sizeof(available), - DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE) == false) - { - RFCOMM_TRACE_ERROR("p_data_co_callback DATA_CO_CALLBACK_TYPE_INCOMING_SIZE failed, available:%d", available); - return (PORT_UNKNOWN_ERROR); - } - if(available == 0) - return PORT_SUCCESS; - /* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len */ - length = RFCOMM_DATA_BUF_SIZE - - (uint16_t)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD); - - /* If there are buffers scheduled for transmission check if requested */ - /* data fits into the end of the queue */ - mutex_global_lock(); - - if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL) - && (((int)p_buf->len + available) <= (int)p_port->peer_mtu) - && (((int)p_buf->len + available) <= (int)length)) - { - //if(recv(fd, (uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, available, 0) != available) - if(p_port->p_data_co_callback(handle, (uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, - available, DATA_CO_CALLBACK_TYPE_OUTGOING) == false) - - { - error("p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, available:%d", available); - mutex_global_unlock(); - return (PORT_UNKNOWN_ERROR); - } - //memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len); - p_port->tx.queue_size += (uint16_t)available; + mutex_global_unlock(); - *p_len = available; - p_buf->len += (uint16_t)available; + // int max_read = length < p_port->peer_mtu ? length : p_port->peer_mtu; - mutex_global_unlock(); + // max_read = available < max_read ? available : max_read; - return (PORT_SUCCESS); + while (available) { + /* if we're over buffer high water mark, we're done */ + if ((p_port->tx.queue_size > PORT_TX_HIGH_WM) || + (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) { + port_flow_control_user(p_port); + event |= PORT_EV_FC; + RFCOMM_TRACE_EVENT( + "tx queue is full,tx.queue_size:%d,tx.queue.count:%d,available:%d", + p_port->tx.queue_size, fixed_queue_length(p_port->tx.queue), + available); + break; } - mutex_global_unlock(); - - //int max_read = length < p_port->peer_mtu ? length : p_port->peer_mtu; + /* continue with rfcomm data write */ + p_buf = (BT_HDR*)osi_malloc(RFCOMM_DATA_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET; + p_buf->layer_specific = handle; - //max_read = available < max_read ? available : max_read; + if (p_port->peer_mtu < length) length = p_port->peer_mtu; + if (available < (int)length) length = (uint16_t)available; + p_buf->len = length; + p_buf->event = BT_EVT_TO_BTU_SP_DATA; - while (available) - { - /* if we're over buffer high water mark, we're done */ - if ((p_port->tx.queue_size > PORT_TX_HIGH_WM) - || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) - { - port_flow_control_user(p_port); - event |= PORT_EV_FC; - RFCOMM_TRACE_EVENT ("tx queue is full,tx.queue_size:%d,tx.queue.count:%d,available:%d", - p_port->tx.queue_size, fixed_queue_length(p_port->tx.queue), available); - break; - } - - /* continue with rfcomm data write */ - p_buf = (BT_HDR *)osi_malloc(RFCOMM_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET; - p_buf->layer_specific = handle; - - if (p_port->peer_mtu < length) - length = p_port->peer_mtu; - if (available < (int)length) - length = (uint16_t)available; - p_buf->len = length; - p_buf->event = BT_EVT_TO_BTU_SP_DATA; - - //memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset, p_data, length); - //if(recv(fd, (uint8_t *)(p_buf + 1) + p_buf->offset, (int)length, 0) != (int)length) - if(p_port->p_data_co_callback(handle, (uint8_t *)(p_buf + 1) + p_buf->offset, length, - DATA_CO_CALLBACK_TYPE_OUTGOING) == false) - { - error("p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, length:%d", length); - return (PORT_UNKNOWN_ERROR); - } + // memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset, p_data, length); + // if(recv(fd, (uint8_t *)(p_buf + 1) + p_buf->offset, (int)length, 0) != + // (int)length) + if (p_port->p_data_co_callback( + handle, (uint8_t*)(p_buf + 1) + p_buf->offset, length, + DATA_CO_CALLBACK_TYPE_OUTGOING) == false) { + error( + "p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, length:%d", + length); + return (PORT_UNKNOWN_ERROR); + } - RFCOMM_TRACE_EVENT ("PORT_WriteData %d bytes", length); + RFCOMM_TRACE_EVENT("PORT_WriteData %d bytes", length); - rc = port_write (p_port, p_buf); + rc = port_write(p_port, p_buf); - /* If queue went below the threashold need to send flow control */ - event |= port_flow_control_user (p_port); + /* If queue went below the threashold need to send flow control */ + event |= port_flow_control_user(p_port); - if (rc == PORT_SUCCESS) - event |= PORT_EV_TXCHAR; + if (rc == PORT_SUCCESS) event |= PORT_EV_TXCHAR; - if ((rc != PORT_SUCCESS) && (rc != PORT_CMD_PENDING)) - break; + if ((rc != PORT_SUCCESS) && (rc != PORT_CMD_PENDING)) break; - *p_len += length; - available -= (int)length; - } - if (!available && (rc != PORT_CMD_PENDING) && (rc != PORT_TX_QUEUE_DISABLED)) - event |= PORT_EV_TXEMPTY; + *p_len += length; + available -= (int)length; + } + if (!available && (rc != PORT_CMD_PENDING) && (rc != PORT_TX_QUEUE_DISABLED)) + event |= PORT_EV_TXEMPTY; - /* Mask out all events that are not of interest to user */ - event &= p_port->ev_mask; + /* Mask out all events that are not of interest to user */ + event &= p_port->ev_mask; - /* Send event to the application */ - if (p_port->p_callback && event) - (p_port->p_callback)(event, p_port->inx); + /* Send event to the application */ + if (p_port->p_callback && event) (p_port->p_callback)(event, p_port->inx); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1658,113 +1549,103 @@ int PORT_WriteDataCO (uint16_t handle, int* p_len) * p_len - Byte count received * ******************************************************************************/ -int PORT_WriteData (uint16_t handle, const char *p_data, uint16_t max_len, - uint16_t *p_len) -{ - tPORT *p_port; - BT_HDR *p_buf; - uint32_t event = 0; - int rc = 0; - uint16_t length; - - RFCOMM_TRACE_API ("PORT_WriteData() max_len:%d", max_len); - - *p_len = 0; +int PORT_WriteData(uint16_t handle, const char* p_data, uint16_t max_len, + uint16_t* p_len) { + tPORT* p_port; + BT_HDR* p_buf; + uint32_t event = 0; + int rc = 0; + uint16_t length; - /* Check if handle is valid to avoid crashing */ - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + RFCOMM_TRACE_API("PORT_WriteData() max_len:%d", max_len); - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - RFCOMM_TRACE_WARNING ("PORT_WriteData() no port state:%d", p_port->state); - return (PORT_NOT_OPENED); - } + *p_len = 0; - if (!max_len || !p_port->peer_mtu) - { - RFCOMM_TRACE_ERROR ("PORT_WriteData() peer_mtu:%d", p_port->peer_mtu); - return (PORT_UNKNOWN_ERROR); - } + /* Check if handle is valid to avoid crashing */ + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - /* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len */ - length = RFCOMM_DATA_BUF_SIZE - - (uint16_t)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD); + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + RFCOMM_TRACE_WARNING("PORT_WriteData() no port state:%d", p_port->state); + return (PORT_NOT_OPENED); + } - /* If there are buffers scheduled for transmission check if requested */ - /* data fits into the end of the queue */ - mutex_global_lock(); + if (!max_len || !p_port->peer_mtu) { + RFCOMM_TRACE_ERROR("PORT_WriteData() peer_mtu:%d", p_port->peer_mtu); + return (PORT_UNKNOWN_ERROR); + } - if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL) - && ((p_buf->len + max_len) <= p_port->peer_mtu) - && ((p_buf->len + max_len) <= length)) - { - memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len); - p_port->tx.queue_size += max_len; + /* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len + */ + length = RFCOMM_DATA_BUF_SIZE - + (uint16_t)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD); - *p_len = max_len; - p_buf->len += max_len; + /* If there are buffers scheduled for transmission check if requested */ + /* data fits into the end of the queue */ + mutex_global_lock(); - mutex_global_unlock(); + if (((p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue)) != + NULL) && + ((p_buf->len + max_len) <= p_port->peer_mtu) && + ((p_buf->len + max_len) <= length)) { + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len); + p_port->tx.queue_size += max_len; - return (PORT_SUCCESS); - } + *p_len = max_len; + p_buf->len += max_len; mutex_global_unlock(); - while (max_len) - { - /* if we're over buffer high water mark, we're done */ - if ((p_port->tx.queue_size > PORT_TX_HIGH_WM) - || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) - break; + return (PORT_SUCCESS); + } - /* continue with rfcomm data write */ - p_buf = (BT_HDR *)osi_malloc(RFCOMM_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET; - p_buf->layer_specific = handle; + mutex_global_unlock(); - if (p_port->peer_mtu < length) - length = p_port->peer_mtu; - if (max_len < length) - length = max_len; - p_buf->len = length; - p_buf->event = BT_EVT_TO_BTU_SP_DATA; + while (max_len) { + /* if we're over buffer high water mark, we're done */ + if ((p_port->tx.queue_size > PORT_TX_HIGH_WM) || + (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM)) + break; - memcpy ((uint8_t *)(p_buf + 1) + p_buf->offset, p_data, length); + /* continue with rfcomm data write */ + p_buf = (BT_HDR*)osi_malloc(RFCOMM_DATA_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET; + p_buf->layer_specific = handle; - RFCOMM_TRACE_EVENT ("PORT_WriteData %d bytes", length); + if (p_port->peer_mtu < length) length = p_port->peer_mtu; + if (max_len < length) length = max_len; + p_buf->len = length; + p_buf->event = BT_EVT_TO_BTU_SP_DATA; - rc = port_write (p_port, p_buf); + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, length); - /* If queue went below the threashold need to send flow control */ - event |= port_flow_control_user (p_port); + RFCOMM_TRACE_EVENT("PORT_WriteData %d bytes", length); - if (rc == PORT_SUCCESS) - event |= PORT_EV_TXCHAR; + rc = port_write(p_port, p_buf); - if ((rc != PORT_SUCCESS) && (rc != PORT_CMD_PENDING)) - break; + /* If queue went below the threashold need to send flow control */ + event |= port_flow_control_user(p_port); - *p_len += length; - max_len -= length; - p_data += length; + if (rc == PORT_SUCCESS) event |= PORT_EV_TXCHAR; - } - if (!max_len && (rc != PORT_CMD_PENDING) && (rc != PORT_TX_QUEUE_DISABLED)) - event |= PORT_EV_TXEMPTY; + if ((rc != PORT_SUCCESS) && (rc != PORT_CMD_PENDING)) break; - /* Mask out all events that are not of interest to user */ - event &= p_port->ev_mask; + *p_len += length; + max_len -= length; + p_data += length; + } + if (!max_len && (rc != PORT_CMD_PENDING) && (rc != PORT_TX_QUEUE_DISABLED)) + event |= PORT_EV_TXEMPTY; - /* Send event to the application */ - if (p_port->p_callback && event) - (p_port->p_callback)(event, p_port->inx); + /* Mask out all events that are not of interest to user */ + event &= p_port->ev_mask; - return (PORT_SUCCESS); + /* Send event to the application */ + if (p_port->p_callback && event) (p_port->p_callback)(event, p_port->inx); + + return (PORT_SUCCESS); } /******************************************************************************* @@ -1778,37 +1659,33 @@ int PORT_WriteData (uint16_t handle, const char *p_data, uint16_t max_len, * max_len - Byte count requested * ******************************************************************************/ -int PORT_Test (uint16_t handle, uint8_t *p_data, uint16_t len) -{ - tPORT *p_port; +int PORT_Test(uint16_t handle, uint8_t* p_data, uint16_t len) { + tPORT* p_port; - RFCOMM_TRACE_API ("PORT_Test() len:%d", len); + RFCOMM_TRACE_API("PORT_Test() len:%d", len); - if ((handle == 0) || (handle > MAX_RFC_PORTS)) - { - return (PORT_BAD_HANDLE); - } - p_port = &rfc_cb.port.port[handle - 1]; + if ((handle == 0) || (handle > MAX_RFC_PORTS)) { + return (PORT_BAD_HANDLE); + } + p_port = &rfc_cb.port.port[handle - 1]; - if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) - { - return (PORT_NOT_OPENED); - } + if (!p_port->in_use || (p_port->state == PORT_STATE_CLOSED)) { + return (PORT_NOT_OPENED); + } - if (len > ((p_port->mtu == 0) ? RFCOMM_DEFAULT_MTU : p_port->mtu)) - { - return (PORT_UNKNOWN_ERROR); - } + if (len > ((p_port->mtu == 0) ? RFCOMM_DEFAULT_MTU : p_port->mtu)) { + return (PORT_UNKNOWN_ERROR); + } - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2; - p_buf->len = len; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2; + p_buf->len = len; - memcpy((uint8_t *)(p_buf + 1) + p_buf->offset, p_data, p_buf->len); + memcpy((uint8_t*)(p_buf + 1) + p_buf->offset, p_data, p_buf->len); - rfc_send_test(p_port->rfc.p_mcb, true, p_buf); + rfc_send_test(p_port->rfc.p_mcb, true, p_buf); - return (PORT_SUCCESS); + return (PORT_SUCCESS); } /******************************************************************************* @@ -1818,19 +1695,18 @@ int PORT_Test (uint16_t handle, uint8_t *p_data, uint16_t len) * Description This function is called to initialize RFCOMM layer * ******************************************************************************/ -void RFCOMM_Init (void) -{ - memset (&rfc_cb, 0, sizeof (tRFC_CB)); /* Init RFCOMM control block */ +void RFCOMM_Init(void) { + memset(&rfc_cb, 0, sizeof(tRFC_CB)); /* Init RFCOMM control block */ - rfc_cb.rfc.last_mux = MAX_BD_CONNECTIONS; + rfc_cb.rfc.last_mux = MAX_BD_CONNECTIONS; #if defined(RFCOMM_INITIAL_TRACE_LEVEL) - rfc_cb.trace_level = RFCOMM_INITIAL_TRACE_LEVEL; + rfc_cb.trace_level = RFCOMM_INITIAL_TRACE_LEVEL; #else - rfc_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + rfc_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif - rfcomm_l2cap_if_init (); + rfcomm_l2cap_if_init(); } /******************************************************************************* @@ -1843,12 +1719,10 @@ void RFCOMM_Init (void) * Returns the new (current) trace level * ******************************************************************************/ -uint8_t PORT_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - rfc_cb.trace_level = new_level; +uint8_t PORT_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) rfc_cb.trace_level = new_level; - return (rfc_cb.trace_level); + return (rfc_cb.trace_level); } /******************************************************************************* @@ -1861,7 +1735,7 @@ uint8_t PORT_SetTraceLevel (uint8_t new_level) * Returns a pointer to the human-readable string for the given result. * ******************************************************************************/ -const char *PORT_GetResultString (const uint8_t result_code) { +const char* PORT_GetResultString(const uint8_t result_code) { if (result_code > PORT_ERR_MAX) { return result_code_strings[PORT_ERR_MAX]; } diff --git a/stack/rfcomm/port_int.h b/stack/rfcomm/port_int.h index 58b0e1536..bfb793d5b 100644 --- a/stack/rfcomm/port_int.h +++ b/stack/rfcomm/port_int.h @@ -25,12 +25,12 @@ #ifndef PORT_INT_H #define PORT_INT_H +#include "bt_common.h" #include "bt_target.h" #include "osi/include/alarm.h" #include "osi/include/fixed_queue.h" -#include "bt_common.h" -#include "rfcdefs.h" #include "port_api.h" +#include "rfcdefs.h" #ifdef __cplusplus extern "C" { @@ -38,211 +38,209 @@ extern "C" { /* Local events passed when application event is sent from the api to PORT */ /* ???*/ -#define PORT_EVENT_OPEN (1 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_CONTROL (2 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_SET_STATE (3 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_SET_CALLBACK (5 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_WRITE (6 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_PURGE (7 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_SEND_ERROR (8 | BT_EVT_TO_BTU_SP_EVT) -#define PORT_EVENT_FLOW_CONTROL (9 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_OPEN (1 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_CONTROL (2 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_SET_STATE (3 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_SET_CALLBACK (5 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_WRITE (6 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_PURGE (7 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_SEND_ERROR (8 | BT_EVT_TO_BTU_SP_EVT) +#define PORT_EVENT_FLOW_CONTROL (9 | BT_EVT_TO_BTU_SP_EVT) /* * Flow control configuration values for the mux */ -#define PORT_FC_UNDEFINED 0 /* mux flow control mechanism not defined yet */ -#define PORT_FC_TS710 1 /* use TS 07.10 flow control */ -#define PORT_FC_CREDIT 2 /* use RFCOMM credit based flow control */ +#define PORT_FC_UNDEFINED 0 /* mux flow control mechanism not defined yet */ +#define PORT_FC_TS710 1 /* use TS 07.10 flow control */ +#define PORT_FC_CREDIT 2 /* use RFCOMM credit based flow control */ /* * Define Port Data Transfere control block */ -typedef struct -{ - fixed_queue_t *queue; /* Queue of buffers waiting to be sent */ - bool peer_fc; /* true if flow control is set based on peer's request */ - bool user_fc; /* true if flow control is set based on user's request */ - uint32_t queue_size; /* Number of data bytes in the queue */ - tPORT_CALLBACK *p_callback; /* Address of the callback function */ +typedef struct { + fixed_queue_t* queue; /* Queue of buffers waiting to be sent */ + bool peer_fc; /* true if flow control is set based on peer's request */ + bool user_fc; /* true if flow control is set based on user's request */ + uint32_t queue_size; /* Number of data bytes in the queue */ + tPORT_CALLBACK* p_callback; /* Address of the callback function */ } tPORT_DATA; /* * Port control structure used to pass modem info */ -typedef struct -{ -#define MODEM_SIGNAL_DTRDSR 0x01 -#define MODEM_SIGNAL_RTSCTS 0x02 -#define MODEM_SIGNAL_RI 0x04 -#define MODEM_SIGNAL_DCD 0x08 +typedef struct { +#define MODEM_SIGNAL_DTRDSR 0x01 +#define MODEM_SIGNAL_RTSCTS 0x02 +#define MODEM_SIGNAL_RI 0x04 +#define MODEM_SIGNAL_DCD 0x08 - uint8_t modem_signal; /* [DTR/DSR | RTS/CTS | RI | DCD ] */ + uint8_t modem_signal; /* [DTR/DSR | RTS/CTS | RI | DCD ] */ - uint8_t break_signal; /* 0-3 s in steps of 200 ms */ + uint8_t break_signal; /* 0-3 s in steps of 200 ms */ - uint8_t discard_buffers; /* 0 - do not discard, 1 - discard */ + uint8_t discard_buffers; /* 0 - do not discard, 1 - discard */ -#define RFCOMM_CTRL_BREAK_ASAP 0 -#define RFCOMM_CTRL_BREAK_IN_SEQ 1 +#define RFCOMM_CTRL_BREAK_ASAP 0 +#define RFCOMM_CTRL_BREAK_IN_SEQ 1 - uint8_t break_signal_seq; /* as soon as possible | in sequence (default) */ + uint8_t break_signal_seq; /* as soon as possible | in sequence (default) */ - bool fc; /* true when the device is unable to accept frames */ + bool fc; /* true when the device is unable to accept frames */ } tPORT_CTRL; - /* * RFCOMM multiplexer Control Block */ -typedef struct -{ - alarm_t *mcb_timer; /* MCB timer */ - fixed_queue_t *cmd_q; /* Queue for command messages on this mux */ - uint8_t port_inx[RFCOMM_MAX_DLCI + 1]; /* Array for quick access to */ - /* tPORT based on dlci */ - BD_ADDR bd_addr; /* BD ADDR of the peer if initiator */ - uint16_t lcid; /* Local cid used for this channel */ - uint16_t peer_l2cap_mtu; /* Max frame that can be sent to peer L2CAP */ - uint8_t state; /* Current multiplexer channel state */ - uint8_t is_initiator; /* true if this side sends SABME (dlci=0) */ - bool local_cfg_sent; - bool peer_cfg_rcvd; - bool restart_required; /* true if has to restart channel after disc */ - bool peer_ready; /* True if other side can accept frames */ - uint8_t flow; /* flow control mechanism for this mux */ - bool l2cap_congested; /* true if L2CAP is congested */ - bool is_disc_initiator; /* true if initiated disc of port */ - uint16_t pending_lcid; /* store LCID for incoming connection while connecting */ - uint8_t pending_id; /* store l2cap ID for incoming connection while connecting */ +typedef struct { + alarm_t* mcb_timer; /* MCB timer */ + fixed_queue_t* cmd_q; /* Queue for command messages on this mux */ + uint8_t port_inx[RFCOMM_MAX_DLCI + 1]; /* Array for quick access to */ + /* tPORT based on dlci */ + BD_ADDR bd_addr; /* BD ADDR of the peer if initiator */ + uint16_t lcid; /* Local cid used for this channel */ + uint16_t peer_l2cap_mtu; /* Max frame that can be sent to peer L2CAP */ + uint8_t state; /* Current multiplexer channel state */ + uint8_t is_initiator; /* true if this side sends SABME (dlci=0) */ + bool local_cfg_sent; + bool peer_cfg_rcvd; + bool restart_required; /* true if has to restart channel after disc */ + bool peer_ready; /* True if other side can accept frames */ + uint8_t flow; /* flow control mechanism for this mux */ + bool l2cap_congested; /* true if L2CAP is congested */ + bool is_disc_initiator; /* true if initiated disc of port */ + uint16_t + pending_lcid; /* store LCID for incoming connection while connecting */ + uint8_t + pending_id; /* store l2cap ID for incoming connection while connecting */ } tRFC_MCB; - /* * RFCOMM Port Connection Control Block */ typedef struct { -#define RFC_PORT_STATE_IDLE 0 -#define RFC_PORT_STATE_WAIT_START 1 -#define RFC_PORT_STATE_OPENING 2 -#define RFC_PORT_STATE_OPENED 3 -#define RFC_PORT_STATE_CLOSING 4 +#define RFC_PORT_STATE_IDLE 0 +#define RFC_PORT_STATE_WAIT_START 1 +#define RFC_PORT_STATE_OPENING 2 +#define RFC_PORT_STATE_OPENED 3 +#define RFC_PORT_STATE_CLOSING 4 - uint8_t state; /* Current state of the connection */ + uint8_t state; /* Current state of the connection */ -#define RFC_RSP_PN 0x01 -#define RFC_RSP_RPN_REPLY 0x02 -#define RFC_RSP_RPN 0x04 -#define RFC_RSP_MSC 0x08 -#define RFC_RSP_RLS 0x10 +#define RFC_RSP_PN 0x01 +#define RFC_RSP_RPN_REPLY 0x02 +#define RFC_RSP_RPN 0x04 +#define RFC_RSP_MSC 0x08 +#define RFC_RSP_RLS 0x10 - uint8_t expected_rsp; + uint8_t expected_rsp; - tRFC_MCB *p_mcb; + tRFC_MCB* p_mcb; - alarm_t *port_timer; + alarm_t* port_timer; } tRFC_PORT; - /* * Define control block containing information about PORT connection */ -typedef struct -{ - uint8_t inx; /* Index of this control block in the port_info array */ - bool in_use; /* True when structure is allocated */ +typedef struct { + uint8_t inx; /* Index of this control block in the port_info array */ + bool in_use; /* True when structure is allocated */ -#define PORT_STATE_CLOSED 0 -#define PORT_STATE_OPENING 1 -#define PORT_STATE_OPENED 2 -#define PORT_STATE_CLOSING 3 +#define PORT_STATE_CLOSED 0 +#define PORT_STATE_OPENING 1 +#define PORT_STATE_OPENED 2 +#define PORT_STATE_CLOSING 3 - uint8_t state; /* State of the application */ + uint8_t state; /* State of the application */ - uint8_t scn; /* Service channel number */ - uint16_t uuid; /* Service UUID */ + uint8_t scn; /* Service channel number */ + uint16_t uuid; /* Service UUID */ - BD_ADDR bd_addr; /* BD ADDR of the device for the multiplexer channel */ - bool is_server; /* true if the server application */ - uint8_t dlci; /* DLCI of the connection */ + BD_ADDR bd_addr; /* BD ADDR of the device for the multiplexer channel */ + bool is_server; /* true if the server application */ + uint8_t dlci; /* DLCI of the connection */ - uint8_t error; /* Last error detected */ + uint8_t error; /* Last error detected */ - uint8_t line_status; /* Line status as reported by peer */ + uint8_t line_status; /* Line status as reported by peer */ - uint8_t default_signal_state; /* Initial signal state depending on uuid */ + uint8_t default_signal_state; /* Initial signal state depending on uuid */ - uint16_t mtu; /* Max MTU that port can receive */ - uint16_t peer_mtu; /* Max MTU that port can send */ + uint16_t mtu; /* Max MTU that port can receive */ + uint16_t peer_mtu; /* Max MTU that port can send */ - tPORT_DATA tx; /* Control block for data from app to peer */ - tPORT_DATA rx; /* Control block for data from peer to app */ + tPORT_DATA tx; /* Control block for data from app to peer */ + tPORT_DATA rx; /* Control block for data from peer to app */ - tPORT_STATE user_port_pars; /* Port parameters for user connection */ - tPORT_STATE peer_port_pars; /* Port parameters for user connection */ + tPORT_STATE user_port_pars; /* Port parameters for user connection */ + tPORT_STATE peer_port_pars; /* Port parameters for user connection */ - tPORT_CTRL local_ctrl; - tPORT_CTRL peer_ctrl; + tPORT_CTRL local_ctrl; + tPORT_CTRL peer_ctrl; -#define PORT_CTRL_REQ_SENT 0x01 -#define PORT_CTRL_REQ_CONFIRMED 0x02 -#define PORT_CTRL_IND_RECEIVED 0x04 -#define PORT_CTRL_IND_RESPONDED 0x08 +#define PORT_CTRL_REQ_SENT 0x01 +#define PORT_CTRL_REQ_CONFIRMED 0x02 +#define PORT_CTRL_IND_RECEIVED 0x04 +#define PORT_CTRL_IND_RESPONDED 0x08 - uint8_t port_ctrl; /* Modem Status Command */ + uint8_t port_ctrl; /* Modem Status Command */ - bool rx_flag_ev_pending; /* RXFLAG Character is received */ + bool rx_flag_ev_pending; /* RXFLAG Character is received */ - tRFC_PORT rfc; /* RFCOMM port control block */ + tRFC_PORT rfc; /* RFCOMM port control block */ - uint32_t ev_mask; /* Event mask for the callback */ - tPORT_CALLBACK *p_callback; /* Pointer to users callback function */ - tPORT_CALLBACK *p_mgmt_callback; /* Callback function to receive connection up/down */ - tPORT_DATA_CALLBACK *p_data_callback; /* Callback function to receive data indications */ - tPORT_DATA_CO_CALLBACK *p_data_co_callback; /* Callback function with callouts and flowctrl */ - uint16_t credit_tx; /* Flow control credits for tx path */ - uint16_t credit_rx; /* Flow control credits for rx path, this is */ - /* number of buffers peer is allowed to sent */ - uint16_t credit_rx_max; /* Max number of credits we will allow this guy to sent */ - uint16_t credit_rx_low; /* Number of credits when we send credit update */ - uint16_t rx_buf_critical; /* port receive queue critical watermark level */ - bool keep_port_handle; /* true if port is not deallocated when closing */ - /* it is set to true for server when allocating port */ - uint16_t keep_mtu; /* Max MTU that port can receive by server */ + uint32_t ev_mask; /* Event mask for the callback */ + tPORT_CALLBACK* p_callback; /* Pointer to users callback function */ + tPORT_CALLBACK* + p_mgmt_callback; /* Callback function to receive connection up/down */ + tPORT_DATA_CALLBACK* + p_data_callback; /* Callback function to receive data indications */ + tPORT_DATA_CO_CALLBACK* + p_data_co_callback; /* Callback function with callouts and flowctrl */ + uint16_t credit_tx; /* Flow control credits for tx path */ + uint16_t credit_rx; /* Flow control credits for rx path, this is */ + /* number of buffers peer is allowed to sent */ + uint16_t + credit_rx_max; /* Max number of credits we will allow this guy to sent */ + uint16_t credit_rx_low; /* Number of credits when we send credit update */ + uint16_t rx_buf_critical; /* port receive queue critical watermark level */ + bool keep_port_handle; /* true if port is not deallocated when closing */ + /* it is set to true for server when allocating port */ + uint16_t keep_mtu; /* Max MTU that port can receive by server */ } tPORT; - /* Define the PORT/RFCOMM control structure */ -typedef struct -{ - tPORT port[MAX_RFC_PORTS]; /* Port info pool */ - tRFC_MCB rfc_mcb[MAX_BD_CONNECTIONS]; /* RFCOMM bd_connections pool */ +typedef struct { + tPORT port[MAX_RFC_PORTS]; /* Port info pool */ + tRFC_MCB rfc_mcb[MAX_BD_CONNECTIONS]; /* RFCOMM bd_connections pool */ } tPORT_CB; /* * Functions provided by the port_utils.cc */ -extern tPORT *port_allocate_port (uint8_t dlci, BD_ADDR bd_addr); -extern void port_set_defaults (tPORT *p_port); -extern void port_select_mtu (tPORT *p_port); -extern void port_release_port (tPORT *p_port); -extern tPORT *port_find_mcb_dlci_port (tRFC_MCB *p_mcb, uint8_t dlci); -extern tRFC_MCB *port_find_mcb (BD_ADDR bd_addr); -extern tPORT *port_find_dlci_port (uint8_t dlci); -extern tPORT *port_find_port (uint8_t dlci, BD_ADDR bd_addr); -extern uint32_t port_get_signal_changes (tPORT *p_port, uint8_t old_signals, uint8_t signal); -extern uint32_t port_flow_control_user (tPORT *p_port); -extern void port_flow_control_peer(tPORT *p_port, bool enable, uint16_t count); +extern tPORT* port_allocate_port(uint8_t dlci, BD_ADDR bd_addr); +extern void port_set_defaults(tPORT* p_port); +extern void port_select_mtu(tPORT* p_port); +extern void port_release_port(tPORT* p_port); +extern tPORT* port_find_mcb_dlci_port(tRFC_MCB* p_mcb, uint8_t dlci); +extern tRFC_MCB* port_find_mcb(BD_ADDR bd_addr); +extern tPORT* port_find_dlci_port(uint8_t dlci); +extern tPORT* port_find_port(uint8_t dlci, BD_ADDR bd_addr); +extern uint32_t port_get_signal_changes(tPORT* p_port, uint8_t old_signals, + uint8_t signal); +extern uint32_t port_flow_control_user(tPORT* p_port); +extern void port_flow_control_peer(tPORT* p_port, bool enable, uint16_t count); /* * Functions provided by the port_rfc.cc */ -extern int port_open_continue (tPORT *p_port); -extern void port_start_port_open (tPORT *p_port); -extern void port_start_par_neg (tPORT *p_port); -extern void port_start_control (tPORT *p_port); -extern void port_start_close (tPORT *p_port); -extern void port_rfc_closed (tPORT *p_port, uint8_t res); +extern int port_open_continue(tPORT* p_port); +extern void port_start_port_open(tPORT* p_port); +extern void port_start_par_neg(tPORT* p_port); +extern void port_start_control(tPORT* p_port); +extern void port_start_close(tPORT* p_port); +extern void port_rfc_closed(tPORT* p_port, uint8_t res); #ifdef __cplusplus } diff --git a/stack/rfcomm/port_rfc.cc b/stack/rfcomm/port_rfc.cc index a10914ea1..ec30f0344 100644 --- a/stack/rfcomm/port_rfc.cc +++ b/stack/rfcomm/port_rfc.cc @@ -40,10 +40,9 @@ /* * Local function definitions */ -uint32_t port_rfc_send_tx_data (tPORT *p_port); -void port_rfc_closed (tPORT *p_port, uint8_t res); -void port_get_credits (tPORT *p_port, uint8_t k); - +uint32_t port_rfc_send_tx_data(tPORT* p_port); +void port_rfc_closed(tPORT* p_port, uint8_t res); +void port_get_credits(tPORT* p_port, uint8_t k); /******************************************************************************* * @@ -55,50 +54,46 @@ void port_get_credits (tPORT *p_port, uint8_t k); * Returns void * ******************************************************************************/ -int port_open_continue (tPORT *p_port) -{ - tRFC_MCB *p_mcb; - - RFCOMM_TRACE_EVENT ("port_open_continue, p_port:%p", p_port); - - /* Check if multiplexer channel has already been established */ - p_mcb = rfc_alloc_multiplexer_channel(p_port->bd_addr, true); - if (p_mcb == NULL) - { - RFCOMM_TRACE_WARNING ("port_open_continue no mx channel"); - port_release_port (p_port); - return (PORT_NO_RESOURCES); - } - - p_port->rfc.p_mcb = p_mcb; - - p_mcb->port_inx[p_port->dlci] = p_port->inx; - - /* Connection is up and we know local and remote features, select MTU */ - port_select_mtu (p_port); - - if (p_mcb->state == RFC_MX_STATE_CONNECTED) - { - RFCOMM_ParNegReq (p_mcb, p_port->dlci, p_port->mtu); - } - else if ((p_mcb->state == RFC_MX_STATE_IDLE) - ||(p_mcb->state == RFC_MX_STATE_DISC_WAIT_UA)) - { - /* In RFC_MX_STATE_IDLE state, MX state machine will create connection */ - /* In RFC_MX_STATE_DISC_WAIT_UA state, MX state machine will recreate connection */ - /* after disconnecting is completed */ - RFCOMM_StartReq (p_mcb); - } - else - { - /* MX state machine ignores RFC_MX_EVENT_START_REQ in these states */ - /* When it enters RFC_MX_STATE_CONNECTED, it will check any openning ports */ - RFCOMM_TRACE_DEBUG ("port_open_continue: mx state(%d) mx channel is openning", p_mcb->state); - } - return (PORT_SUCCESS); +int port_open_continue(tPORT* p_port) { + tRFC_MCB* p_mcb; + + RFCOMM_TRACE_EVENT("port_open_continue, p_port:%p", p_port); + + /* Check if multiplexer channel has already been established */ + p_mcb = rfc_alloc_multiplexer_channel(p_port->bd_addr, true); + if (p_mcb == NULL) { + RFCOMM_TRACE_WARNING("port_open_continue no mx channel"); + port_release_port(p_port); + return (PORT_NO_RESOURCES); + } + + p_port->rfc.p_mcb = p_mcb; + + p_mcb->port_inx[p_port->dlci] = p_port->inx; + + /* Connection is up and we know local and remote features, select MTU */ + port_select_mtu(p_port); + + if (p_mcb->state == RFC_MX_STATE_CONNECTED) { + RFCOMM_ParNegReq(p_mcb, p_port->dlci, p_port->mtu); + } else if ((p_mcb->state == RFC_MX_STATE_IDLE) || + (p_mcb->state == RFC_MX_STATE_DISC_WAIT_UA)) { + /* In RFC_MX_STATE_IDLE state, MX state machine will create connection */ + /* In RFC_MX_STATE_DISC_WAIT_UA state, MX state machine will recreate + * connection */ + /* after disconnecting is completed */ + RFCOMM_StartReq(p_mcb); + } else { + /* MX state machine ignores RFC_MX_EVENT_START_REQ in these states */ + /* When it enters RFC_MX_STATE_CONNECTED, it will check any openning ports + */ + RFCOMM_TRACE_DEBUG( + "port_open_continue: mx state(%d) mx channel is openning", + p_mcb->state); + } + return (PORT_SUCCESS); } - /******************************************************************************* * * Function port_start_control @@ -109,17 +104,14 @@ int port_open_continue (tPORT *p_port) * Returns void * ******************************************************************************/ -void port_start_control (tPORT *p_port) -{ - tRFC_MCB *p_mcb = p_port->rfc.p_mcb; +void port_start_control(tPORT* p_port) { + tRFC_MCB* p_mcb = p_port->rfc.p_mcb; - if (p_mcb == NULL) - return; + if (p_mcb == NULL) return; - RFCOMM_ControlReq (p_mcb, p_port->dlci, &p_port->local_ctrl); + RFCOMM_ControlReq(p_mcb, p_port->dlci, &p_port->local_ctrl); } - /******************************************************************************* * * Function port_start_par_neg @@ -130,17 +122,14 @@ void port_start_control (tPORT *p_port) * Returns void * ******************************************************************************/ -void port_start_par_neg (tPORT *p_port) -{ - tRFC_MCB *p_mcb = p_port->rfc.p_mcb; +void port_start_par_neg(tPORT* p_port) { + tRFC_MCB* p_mcb = p_port->rfc.p_mcb; - if (p_mcb == NULL) - return; + if (p_mcb == NULL) return; - RFCOMM_PortNegReq (p_mcb, p_port->dlci, &p_port->user_port_pars); + RFCOMM_PortNegReq(p_mcb, p_port->dlci, &p_port->user_port_pars); } - /******************************************************************************* * * Function port_start_close @@ -151,46 +140,42 @@ void port_start_par_neg (tPORT *p_port) * Returns void * ******************************************************************************/ -void port_start_close (tPORT *p_port) -{ - tRFC_MCB *p_mcb = p_port->rfc.p_mcb; - uint8_t old_signals; - uint32_t events = 0; +void port_start_close(tPORT* p_port) { + tRFC_MCB* p_mcb = p_port->rfc.p_mcb; + uint8_t old_signals; + uint32_t events = 0; - /* At first indicate to the user that signals on the connection were dropped */ - p_port->line_status |= LINE_STATUS_FAILED; - old_signals = p_port->peer_ctrl.modem_signal; - - p_port->peer_ctrl.modem_signal &= ~(PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); + /* At first indicate to the user that signals on the connection were dropped + */ + p_port->line_status |= LINE_STATUS_FAILED; + old_signals = p_port->peer_ctrl.modem_signal; - events |= port_get_signal_changes (p_port, old_signals, p_port->peer_ctrl.modem_signal); + p_port->peer_ctrl.modem_signal &= + ~(PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); - if(p_port->ev_mask & PORT_EV_CONNECT_ERR) - events |= PORT_EV_CONNECT_ERR; + events |= port_get_signal_changes(p_port, old_signals, + p_port->peer_ctrl.modem_signal); - if(p_port->ev_mask & PORT_EV_ERR) - events |= PORT_EV_ERR; + if (p_port->ev_mask & PORT_EV_CONNECT_ERR) events |= PORT_EV_CONNECT_ERR; - if ((p_port->p_callback != NULL) && events) - p_port->p_callback (events, p_port->inx); + if (p_port->ev_mask & PORT_EV_ERR) events |= PORT_EV_ERR; + if ((p_port->p_callback != NULL) && events) + p_port->p_callback(events, p_port->inx); - /* Check if RFCOMM side has been closed while the message was queued */ - if ((p_mcb == NULL) || (p_port->rfc.state == RFC_STATE_CLOSED)) - { - /* Call management callback function before calling port_release_port() to clear tPort */ - if (p_port->p_mgmt_callback) - p_port->p_mgmt_callback (PORT_CLOSED, p_port->inx); + /* Check if RFCOMM side has been closed while the message was queued */ + if ((p_mcb == NULL) || (p_port->rfc.state == RFC_STATE_CLOSED)) { + /* Call management callback function before calling port_release_port() to + * clear tPort */ + if (p_port->p_mgmt_callback) + p_port->p_mgmt_callback(PORT_CLOSED, p_port->inx); - port_release_port (p_port); - } - else - { - RFCOMM_DlcReleaseReq (p_mcb, p_port->dlci); - } + port_release_port(p_port); + } else { + RFCOMM_DlcReleaseReq(p_mcb, p_port->dlci); + } } - /******************************************************************************* * * Function PORT_StartCnf @@ -201,56 +186,50 @@ void port_start_close (tPORT *p_port) * are in the OPENING state * ******************************************************************************/ -void PORT_StartCnf (tRFC_MCB *p_mcb, uint16_t result) -{ - tPORT *p_port; - int i; - bool no_ports_up = true; - - RFCOMM_TRACE_EVENT ("PORT_StartCnf result:%d", result); - - p_port = &rfc_cb.port.port[0]; - for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) - { - if (p_port->rfc.p_mcb == p_mcb) - { - no_ports_up = false; - - if (result == RFCOMM_SUCCESS) - RFCOMM_ParNegReq (p_mcb, p_port->dlci, p_port->mtu); - else - { - RFCOMM_TRACE_WARNING ("PORT_StartCnf failed result:%d", result); - - /* Warning: result is also set to 4 when l2cap connection - fails due to l2cap connect cnf (no_resources) */ - if( result == HCI_ERR_PAGE_TIMEOUT ) - p_port->error = PORT_PAGE_TIMEOUT; - else - p_port->error = PORT_START_FAILED; - - rfc_release_multiplexer_channel (p_mcb); - - /* Send event to the application */ - if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECT_ERR)) - (p_port->p_callback)(PORT_EV_CONNECT_ERR, p_port->inx); - - if (p_port->p_mgmt_callback) - p_port->p_mgmt_callback (PORT_START_FAILED, p_port->inx); - - port_release_port (p_port); - } - } - } +void PORT_StartCnf(tRFC_MCB* p_mcb, uint16_t result) { + tPORT* p_port; + int i; + bool no_ports_up = true; + + RFCOMM_TRACE_EVENT("PORT_StartCnf result:%d", result); + + p_port = &rfc_cb.port.port[0]; + for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) { + if (p_port->rfc.p_mcb == p_mcb) { + no_ports_up = false; + + if (result == RFCOMM_SUCCESS) + RFCOMM_ParNegReq(p_mcb, p_port->dlci, p_port->mtu); + else { + RFCOMM_TRACE_WARNING("PORT_StartCnf failed result:%d", result); + + /* Warning: result is also set to 4 when l2cap connection + fails due to l2cap connect cnf (no_resources) */ + if (result == HCI_ERR_PAGE_TIMEOUT) + p_port->error = PORT_PAGE_TIMEOUT; + else + p_port->error = PORT_START_FAILED; + + rfc_release_multiplexer_channel(p_mcb); + + /* Send event to the application */ + if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECT_ERR)) + (p_port->p_callback)(PORT_EV_CONNECT_ERR, p_port->inx); + + if (p_port->p_mgmt_callback) + p_port->p_mgmt_callback(PORT_START_FAILED, p_port->inx); - /* There can be a situation when after starting connection, user closes the */ - /* port, we can catch it here to close multiplexor channel */ - if (no_ports_up) - { - rfc_check_mcb_active (p_mcb); + port_release_port(p_port); + } } -} + } + /* There can be a situation when after starting connection, user closes the */ + /* port, we can catch it here to close multiplexor channel */ + if (no_ports_up) { + rfc_check_mcb_active(p_mcb); + } +} /******************************************************************************* * @@ -262,28 +241,24 @@ void PORT_StartCnf (tRFC_MCB *p_mcb, uint16_t result) * or not assigned multiplexer. * ******************************************************************************/ -void PORT_StartInd (tRFC_MCB *p_mcb) -{ - tPORT *p_port; - int i; - - RFCOMM_TRACE_EVENT ("PORT_StartInd"); - - p_port = &rfc_cb.port.port[0]; - for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) - { - if ((p_port->rfc.p_mcb == NULL) - || (p_port->rfc.p_mcb == p_mcb)) - { - RFCOMM_TRACE_DEBUG("PORT_StartInd, RFCOMM_StartRsp RFCOMM_SUCCESS: p_mcb:%p", p_mcb); - RFCOMM_StartRsp (p_mcb, RFCOMM_SUCCESS); - return; - } +void PORT_StartInd(tRFC_MCB* p_mcb) { + tPORT* p_port; + int i; + + RFCOMM_TRACE_EVENT("PORT_StartInd"); + + p_port = &rfc_cb.port.port[0]; + for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) { + if ((p_port->rfc.p_mcb == NULL) || (p_port->rfc.p_mcb == p_mcb)) { + RFCOMM_TRACE_DEBUG( + "PORT_StartInd, RFCOMM_StartRsp RFCOMM_SUCCESS: p_mcb:%p", p_mcb); + RFCOMM_StartRsp(p_mcb, RFCOMM_SUCCESS); + return; } - RFCOMM_StartRsp (p_mcb, RFCOMM_ERROR); + } + RFCOMM_StartRsp(p_mcb, RFCOMM_ERROR); } - /******************************************************************************* * * Function PORT_ParNegInd @@ -294,86 +269,81 @@ void PORT_StartInd (tRFC_MCB *p_mcb) * Otherwise save the MTU size supported by the peer. * ******************************************************************************/ -void PORT_ParNegInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - uint8_t our_cl; - uint8_t our_k; - - RFCOMM_TRACE_EVENT ("PORT_ParNegInd dlci:%d mtu:%d", dlci, mtu); - - if (!p_port) - { - /* This can be a first request for this port */ - p_port = port_find_dlci_port (dlci); - if (!p_port) - { - /* If the port cannot be opened, send a DM. Per Errata 1205 */ - rfc_send_dm(p_mcb, dlci, false); - /* check if this is the last port open, some headsets have - problem, they don't disconnect if we send DM */ - rfc_check_mcb_active( p_mcb ); - RFCOMM_TRACE_EVENT( "PORT_ParNegInd: port not found" ); - return; - } - p_mcb->port_inx[dlci] = p_port->inx; +void PORT_ParNegInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, + uint8_t k) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + uint8_t our_cl; + uint8_t our_k; + + RFCOMM_TRACE_EVENT("PORT_ParNegInd dlci:%d mtu:%d", dlci, mtu); + + if (!p_port) { + /* This can be a first request for this port */ + p_port = port_find_dlci_port(dlci); + if (!p_port) { + /* If the port cannot be opened, send a DM. Per Errata 1205 */ + rfc_send_dm(p_mcb, dlci, false); + /* check if this is the last port open, some headsets have + problem, they don't disconnect if we send DM */ + rfc_check_mcb_active(p_mcb); + RFCOMM_TRACE_EVENT("PORT_ParNegInd: port not found"); + return; } - - memcpy (p_port->bd_addr, p_mcb->bd_addr, BD_ADDR_LEN); - - /* Connection is up and we know local and remote features, select MTU */ - port_select_mtu (p_port); - - p_port->rfc.p_mcb = p_mcb; - p_port->mtu = (p_port->mtu < mtu) ? p_port->mtu : mtu; - p_port->peer_mtu = p_port->mtu; - - /* Negotiate the flow control mechanism. If flow control mechanism for */ - /* mux has not been set yet, set it now. If either we or peer wants TS 07.10, */ - /* use that. Otherwise both must want credit based, so use that. If flow is */ - /* already defined for this mux, we respond with that value. */ - if (p_mcb->flow == PORT_FC_UNDEFINED) - { - if ((PORT_FC_DEFAULT == PORT_FC_TS710) || (cl == RFCOMM_PN_CONV_LAYER_TYPE_1)) - { - p_mcb->flow = PORT_FC_TS710; - } - else - { - p_mcb->flow = PORT_FC_CREDIT; - } - } - - /* Regardless of our flow control mechanism, if the PN cl is zero, we must */ - /* respond with zero. "A responding implementation must set this field to 14 */ - /* if (and only if) the PN request was 15." This could happen if a PN is sent */ - /* after the DLCI is already established-- the PN in that case must have cl = 0. */ - /* See RFCOMM spec 5.5.3 */ - if (cl == RFCOMM_PN_CONV_LAYER_TYPE_1) - { - our_cl = RFCOMM_PN_CONV_LAYER_TYPE_1; - our_k = 0; - } - else if (p_mcb->flow == PORT_FC_CREDIT) - { - /* get credits */ - port_get_credits (p_port, k); - - /* Set convergence layer and number of credits (k) */ - our_cl = RFCOMM_PN_CONV_LAYER_CBFC_R; - our_k = (p_port->credit_rx_max < RFCOMM_K_MAX) ? p_port->credit_rx_max : RFCOMM_K_MAX; - p_port->credit_rx = our_k; + p_mcb->port_inx[dlci] = p_port->inx; + } + + memcpy(p_port->bd_addr, p_mcb->bd_addr, BD_ADDR_LEN); + + /* Connection is up and we know local and remote features, select MTU */ + port_select_mtu(p_port); + + p_port->rfc.p_mcb = p_mcb; + p_port->mtu = (p_port->mtu < mtu) ? p_port->mtu : mtu; + p_port->peer_mtu = p_port->mtu; + + /* Negotiate the flow control mechanism. If flow control mechanism for */ + /* mux has not been set yet, set it now. If either we or peer wants TS 07.10, + */ + /* use that. Otherwise both must want credit based, so use that. If flow is + */ + /* already defined for this mux, we respond with that value. */ + if (p_mcb->flow == PORT_FC_UNDEFINED) { + if ((PORT_FC_DEFAULT == PORT_FC_TS710) || + (cl == RFCOMM_PN_CONV_LAYER_TYPE_1)) { + p_mcb->flow = PORT_FC_TS710; + } else { + p_mcb->flow = PORT_FC_CREDIT; } - else - { - /* must not be using credit based flow control; use TS 7.10 */ - our_cl = RFCOMM_PN_CONV_LAYER_TYPE_1; - our_k = 0; - } - RFCOMM_ParNegRsp (p_mcb, dlci, p_port->mtu, our_cl, our_k); + } + + /* Regardless of our flow control mechanism, if the PN cl is zero, we must */ + /* respond with zero. "A responding implementation must set this field to 14 + */ + /* if (and only if) the PN request was 15." This could happen if a PN is sent + */ + /* after the DLCI is already established-- the PN in that case must have cl = + * 0. */ + /* See RFCOMM spec 5.5.3 */ + if (cl == RFCOMM_PN_CONV_LAYER_TYPE_1) { + our_cl = RFCOMM_PN_CONV_LAYER_TYPE_1; + our_k = 0; + } else if (p_mcb->flow == PORT_FC_CREDIT) { + /* get credits */ + port_get_credits(p_port, k); + + /* Set convergence layer and number of credits (k) */ + our_cl = RFCOMM_PN_CONV_LAYER_CBFC_R; + our_k = (p_port->credit_rx_max < RFCOMM_K_MAX) ? p_port->credit_rx_max + : RFCOMM_K_MAX; + p_port->credit_rx = our_k; + } else { + /* must not be using credit based flow control; use TS 7.10 */ + our_cl = RFCOMM_PN_CONV_LAYER_TYPE_1; + our_k = 0; + } + RFCOMM_ParNegRsp(p_mcb, dlci, p_port->mtu, our_cl, our_k); } - /******************************************************************************* * * Function PORT_ParNegCnf @@ -385,54 +355,52 @@ void PORT_ParNegInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, ui * procedure send EstablishRequest to continue. * ******************************************************************************/ -void PORT_ParNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - - RFCOMM_TRACE_EVENT ("PORT_ParNegCnf dlci:%d mtu:%d cl: %d k: %d", dlci, mtu, cl, k); - - if (!p_port) - return; - - /* Flow control mechanism not set yet. Negotiate flow control mechanism. */ - if (p_mcb->flow == PORT_FC_UNDEFINED) - { - /* Our stack is configured for TS07.10 and they responded with credit-based. */ - /* This is illegal-- negotiation fails. */ - if ((PORT_FC_DEFAULT == PORT_FC_TS710) && (cl == RFCOMM_PN_CONV_LAYER_CBFC_R)) - { - rfc_send_disc (p_mcb, p_port->dlci); - rfc_port_closed (p_port); - return; - } - /* Our stack is configured for credit-based and they responded with credit-based. */ - else if (cl == RFCOMM_PN_CONV_LAYER_CBFC_R) - { - p_mcb->flow = PORT_FC_CREDIT; - } - /* They responded with any other value. Treat this as negotiation to TS07.10. */ - else - { - p_mcb->flow = PORT_FC_TS710; - } +void PORT_ParNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, + uint8_t k) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + + RFCOMM_TRACE_EVENT("PORT_ParNegCnf dlci:%d mtu:%d cl: %d k: %d", dlci, mtu, + cl, k); + + if (!p_port) return; + + /* Flow control mechanism not set yet. Negotiate flow control mechanism. */ + if (p_mcb->flow == PORT_FC_UNDEFINED) { + /* Our stack is configured for TS07.10 and they responded with credit-based. + */ + /* This is illegal-- negotiation fails. */ + if ((PORT_FC_DEFAULT == PORT_FC_TS710) && + (cl == RFCOMM_PN_CONV_LAYER_CBFC_R)) { + rfc_send_disc(p_mcb, p_port->dlci); + rfc_port_closed(p_port); + return; + } + /* Our stack is configured for credit-based and they responded with + credit-based. */ + else if (cl == RFCOMM_PN_CONV_LAYER_CBFC_R) { + p_mcb->flow = PORT_FC_CREDIT; + } + /* They responded with any other value. Treat this as negotiation to + TS07.10. */ + else { + p_mcb->flow = PORT_FC_TS710; } - /* If mux flow control mechanism set, we honor that setting regardless of */ - /* the CL value in their response. This allows us to gracefully accept any */ - /* illegal PN negotiation scenarios. */ + } + /* If mux flow control mechanism set, we honor that setting regardless of */ + /* the CL value in their response. This allows us to gracefully accept any */ + /* illegal PN negotiation scenarios. */ - p_port->mtu = (p_port->mtu < mtu) ? p_port->mtu : mtu; - p_port->peer_mtu = p_port->mtu; + p_port->mtu = (p_port->mtu < mtu) ? p_port->mtu : mtu; + p_port->peer_mtu = p_port->mtu; - if (p_mcb->flow == PORT_FC_CREDIT) - { - port_get_credits (p_port, k); - } + if (p_mcb->flow == PORT_FC_CREDIT) { + port_get_credits(p_port, k); + } - if (p_port->state == PORT_STATE_OPENING) - RFCOMM_DlcEstablishReq (p_mcb, p_port->dlci, p_port->mtu); + if (p_port->state == PORT_STATE_OPENING) + RFCOMM_DlcEstablishReq(p_mcb, p_port->dlci, p_port->mtu); } - /******************************************************************************* * * Function PORT_DlcEstablishInd @@ -446,48 +414,46 @@ void PORT_ParNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, ui * meaning that application already made open. * ******************************************************************************/ -void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - - RFCOMM_TRACE_DEBUG ("PORT_DlcEstablishInd p_mcb:%p, dlci:%d mtu:%di, p_port:%p", p_mcb, dlci, mtu, p_port); - RFCOMM_TRACE_DEBUG ("PORT_DlcEstablishInd p_mcb addr:%02x:%02x:%02x:%02x:%02x:%02x", - p_mcb->bd_addr[0], p_mcb->bd_addr[1], p_mcb->bd_addr[2], - p_mcb->bd_addr[3], p_mcb->bd_addr[4], p_mcb->bd_addr[5]); - - if (!p_port) - { - /* This can be a first request for this port */ - p_port = port_find_dlci_port (dlci); - if (!p_port) - { - RFCOMM_DlcEstablishRsp (p_mcb, dlci, 0, RFCOMM_ERROR); - return; - } - p_mcb->port_inx[dlci] = p_port->inx; +void PORT_DlcEstablishInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + + RFCOMM_TRACE_DEBUG( + "PORT_DlcEstablishInd p_mcb:%p, dlci:%d mtu:%di, p_port:%p", p_mcb, dlci, + mtu, p_port); + RFCOMM_TRACE_DEBUG( + "PORT_DlcEstablishInd p_mcb addr:%02x:%02x:%02x:%02x:%02x:%02x", + p_mcb->bd_addr[0], p_mcb->bd_addr[1], p_mcb->bd_addr[2], + p_mcb->bd_addr[3], p_mcb->bd_addr[4], p_mcb->bd_addr[5]); + + if (!p_port) { + /* This can be a first request for this port */ + p_port = port_find_dlci_port(dlci); + if (!p_port) { + RFCOMM_DlcEstablishRsp(p_mcb, dlci, 0, RFCOMM_ERROR); + return; } + p_mcb->port_inx[dlci] = p_port->inx; + } - /* If L2CAP's mtu less then RFCOMM's take it */ - if (mtu && (mtu < p_port->peer_mtu)) - p_port->peer_mtu = mtu; + /* If L2CAP's mtu less then RFCOMM's take it */ + if (mtu && (mtu < p_port->peer_mtu)) p_port->peer_mtu = mtu; - /* If there was an inactivity timer running for MCB stop it */ - rfc_timer_stop (p_mcb); + /* If there was an inactivity timer running for MCB stop it */ + rfc_timer_stop(p_mcb); - RFCOMM_DlcEstablishRsp (p_mcb, dlci, p_port->mtu, RFCOMM_SUCCESS); + RFCOMM_DlcEstablishRsp(p_mcb, dlci, p_port->mtu, RFCOMM_SUCCESS); - /* This is the server side. If application wants to know when connection */ - /* is established, thats the place */ - if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED)) - (p_port->p_callback)(PORT_EV_CONNECTED, p_port->inx); + /* This is the server side. If application wants to know when connection */ + /* is established, thats the place */ + if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED)) + (p_port->p_callback)(PORT_EV_CONNECTED, p_port->inx); - if (p_port->p_mgmt_callback) - p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx); + if (p_port->p_mgmt_callback) + p_port->p_mgmt_callback(PORT_SUCCESS, p_port->inx); - p_port->state = PORT_STATE_OPENED; + p_port->state = PORT_STATE_OPENED; } - /******************************************************************************* * * Function PORT_DlcEstablishCnf @@ -498,46 +464,44 @@ void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu) * successfull. * ******************************************************************************/ -void PORT_DlcEstablishCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint16_t result) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); +void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint16_t result) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); - RFCOMM_TRACE_EVENT ("PORT_DlcEstablishCnf dlci:%d mtu:%d result:%d", dlci, mtu, result); + RFCOMM_TRACE_EVENT("PORT_DlcEstablishCnf dlci:%d mtu:%d result:%d", dlci, mtu, + result); - if (!p_port) - return; + if (!p_port) return; - if (result != RFCOMM_SUCCESS) - { - p_port->error = PORT_START_FAILED; - port_rfc_closed (p_port, PORT_START_FAILED); - return; - } + if (result != RFCOMM_SUCCESS) { + p_port->error = PORT_START_FAILED; + port_rfc_closed(p_port, PORT_START_FAILED); + return; + } - /* If L2CAP's mtu less then RFCOMM's take it */ - if (mtu && (mtu < p_port->peer_mtu)) - p_port->peer_mtu = mtu; + /* If L2CAP's mtu less then RFCOMM's take it */ + if (mtu && (mtu < p_port->peer_mtu)) p_port->peer_mtu = mtu; - /* If there was an inactivity timer running for MCB stop it */ - rfc_timer_stop (p_mcb); + /* If there was an inactivity timer running for MCB stop it */ + rfc_timer_stop(p_mcb); - if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED)) - (p_port->p_callback)(PORT_EV_CONNECTED, p_port->inx); + if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED)) + (p_port->p_callback)(PORT_EV_CONNECTED, p_port->inx); - if (p_port->p_mgmt_callback) - p_port->p_mgmt_callback (PORT_SUCCESS, p_port->inx); + if (p_port->p_mgmt_callback) + p_port->p_mgmt_callback(PORT_SUCCESS, p_port->inx); - p_port->state = PORT_STATE_OPENED; + p_port->state = PORT_STATE_OPENED; - /* RPN is required only if we want to tell DTE how the port should be opened */ - if ((p_port->uuid == UUID_SERVCLASS_DIALUP_NETWORKING) - || (p_port->uuid == UUID_SERVCLASS_FAX)) - RFCOMM_PortNegReq (p_port->rfc.p_mcb, p_port->dlci, NULL); - else - RFCOMM_ControlReq (p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); + /* RPN is required only if we want to tell DTE how the port should be opened + */ + if ((p_port->uuid == UUID_SERVCLASS_DIALUP_NETWORKING) || + (p_port->uuid == UUID_SERVCLASS_FAX)) + RFCOMM_PortNegReq(p_port->rfc.p_mcb, p_port->dlci, NULL); + else + RFCOMM_ControlReq(p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); } - /******************************************************************************* * * Function PORT_PortNegInd @@ -549,31 +513,27 @@ void PORT_DlcEstablishCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint16_t * allocated before meaning that application already made open. * ******************************************************************************/ -void PORT_PortNegInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, - uint16_t param_mask) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - - RFCOMM_TRACE_EVENT ("PORT_PortNegInd"); - - if (!p_port) - { - /* This can be a first request for this port */ - p_port = port_find_dlci_port (dlci); - if (!p_port) - { - RFCOMM_PortNegRsp (p_mcb, dlci, p_pars, 0); - return; - } - p_mcb->port_inx[dlci] = p_port->inx; +void PORT_PortNegInd(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_STATE* p_pars, + uint16_t param_mask) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + + RFCOMM_TRACE_EVENT("PORT_PortNegInd"); + + if (!p_port) { + /* This can be a first request for this port */ + p_port = port_find_dlci_port(dlci); + if (!p_port) { + RFCOMM_PortNegRsp(p_mcb, dlci, p_pars, 0); + return; } + p_mcb->port_inx[dlci] = p_port->inx; + } - /* Check if the flow control is acceptable on local side */ - p_port->peer_port_pars = *p_pars; - RFCOMM_PortNegRsp (p_mcb, dlci, p_pars, param_mask); + /* Check if the flow control is acceptable on local side */ + p_port->peer_port_pars = *p_pars; + RFCOMM_PortNegRsp(p_mcb, dlci, p_pars, param_mask); } - /******************************************************************************* * * Function PORT_PortNegCnf @@ -582,40 +542,33 @@ void PORT_PortNegInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, * state for the port. Propagate change to the user. * ******************************************************************************/ -void PORT_PortNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, - UNUSED_ATTR tPORT_STATE *p_pars, uint16_t result) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - - RFCOMM_TRACE_EVENT ("PORT_PortNegCnf"); - - if (!p_port) - { - RFCOMM_TRACE_WARNING ("PORT_PortNegCnf no port"); - return; - } - /* Port negotiation failed. Drop the connection */ - if (result != RFCOMM_SUCCESS) - { - p_port->error = PORT_PORT_NEG_FAILED; - - RFCOMM_DlcReleaseReq (p_mcb, p_port->dlci); - - port_rfc_closed (p_port, PORT_PORT_NEG_FAILED); - return; - } - - if (!(p_port->port_ctrl & PORT_CTRL_REQ_SENT)) - { - RFCOMM_ControlReq (p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); - } - else - { - RFCOMM_TRACE_WARNING ("PORT_PortNegCnf Control Already sent"); - } +void PORT_PortNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, + UNUSED_ATTR tPORT_STATE* p_pars, uint16_t result) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + + RFCOMM_TRACE_EVENT("PORT_PortNegCnf"); + + if (!p_port) { + RFCOMM_TRACE_WARNING("PORT_PortNegCnf no port"); + return; + } + /* Port negotiation failed. Drop the connection */ + if (result != RFCOMM_SUCCESS) { + p_port->error = PORT_PORT_NEG_FAILED; + + RFCOMM_DlcReleaseReq(p_mcb, p_port->dlci); + + port_rfc_closed(p_port, PORT_PORT_NEG_FAILED); + return; + } + + if (!(p_port->port_ctrl & PORT_CTRL_REQ_SENT)) { + RFCOMM_ControlReq(p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); + } else { + RFCOMM_TRACE_WARNING("PORT_PortNegCnf Control Already sent"); + } } - /******************************************************************************* * * Function PORT_ControlInd @@ -624,57 +577,50 @@ void PORT_PortNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, * signal change. Propagate change to the user. * ******************************************************************************/ -void PORT_ControlInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - uint32_t event; - uint8_t old_signals; +void PORT_ControlInd(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* p_pars) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + uint32_t event; + uint8_t old_signals; - RFCOMM_TRACE_EVENT ("PORT_ControlInd"); + RFCOMM_TRACE_EVENT("PORT_ControlInd"); - if (!p_port) - return; + if (!p_port) return; - old_signals = p_port->peer_ctrl.modem_signal; - - event = port_get_signal_changes (p_port, old_signals, p_pars->modem_signal); + old_signals = p_port->peer_ctrl.modem_signal; - p_port->peer_ctrl = *p_pars; + event = port_get_signal_changes(p_port, old_signals, p_pars->modem_signal); - if (!(p_port->port_ctrl & PORT_CTRL_REQ_SENT)) - RFCOMM_ControlReq (p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); - else - { - /* If this is the first time we received control RFCOMM is connected */ - if (!(p_port->port_ctrl & PORT_CTRL_IND_RECEIVED)) - { - event |= (PORT_EV_CONNECTED & p_port->ev_mask); - } + p_port->peer_ctrl = *p_pars; - if (p_port->port_ctrl & PORT_CTRL_REQ_CONFIRMED) - { - event |= port_rfc_send_tx_data(p_port); - } + if (!(p_port->port_ctrl & PORT_CTRL_REQ_SENT)) + RFCOMM_ControlReq(p_port->rfc.p_mcb, p_port->dlci, &p_port->local_ctrl); + else { + /* If this is the first time we received control RFCOMM is connected */ + if (!(p_port->port_ctrl & PORT_CTRL_IND_RECEIVED)) { + event |= (PORT_EV_CONNECTED & p_port->ev_mask); } - p_port->port_ctrl |= (PORT_CTRL_IND_RECEIVED | PORT_CTRL_IND_RESPONDED); + if (p_port->port_ctrl & PORT_CTRL_REQ_CONFIRMED) { + event |= port_rfc_send_tx_data(p_port); + } + } - if (p_pars->break_signal) - event |= (PORT_EV_BREAK & p_port->ev_mask); + p_port->port_ctrl |= (PORT_CTRL_IND_RECEIVED | PORT_CTRL_IND_RESPONDED); - /* execute call back function only if the application is registered for events */ - if (event && p_port->p_callback) - (p_port->p_callback)(event, p_port->inx); + if (p_pars->break_signal) event |= (PORT_EV_BREAK & p_port->ev_mask); - RFCOMM_TRACE_EVENT ("PORT_ControlInd DTR_DSR : %d, RTS_CTS : %d, RI : %d, DCD : %d", - ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_DTRDSR) ? 1 : 0), - ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_RTSCTS) ? 1 : 0), - ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_RI) ? 1 : 0), - ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_DCD) ? 1 : 0)); + /* execute call back function only if the application is registered for events + */ + if (event && p_port->p_callback) (p_port->p_callback)(event, p_port->inx); + RFCOMM_TRACE_EVENT( + "PORT_ControlInd DTR_DSR : %d, RTS_CTS : %d, RI : %d, DCD : %d", + ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_DTRDSR) ? 1 : 0), + ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_RTSCTS) ? 1 : 0), + ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_RI) ? 1 : 0), + ((p_port->peer_ctrl.modem_signal & MODEM_SIGNAL_DCD) ? 1 : 0)); } - /******************************************************************************* * * Function PORT_ControlCnf @@ -683,35 +629,30 @@ void PORT_ControlInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars) * peer acknowleges change of the modem signals. * ******************************************************************************/ -void PORT_ControlCnf (tRFC_MCB *p_mcb, uint8_t dlci, - UNUSED_ATTR tPORT_CTRL *p_pars) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - uint32_t event = 0; +void PORT_ControlCnf(tRFC_MCB* p_mcb, uint8_t dlci, + UNUSED_ATTR tPORT_CTRL* p_pars) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + uint32_t event = 0; - RFCOMM_TRACE_EVENT ("PORT_ControlCnf"); + RFCOMM_TRACE_EVENT("PORT_ControlCnf"); - if (!p_port) - return; + if (!p_port) return; - if (!(p_port->port_ctrl & PORT_CTRL_REQ_CONFIRMED)) - { - p_port->port_ctrl |= PORT_CTRL_REQ_CONFIRMED; - - if (p_port->port_ctrl & PORT_CTRL_IND_RECEIVED) - event = (p_port->ev_mask & PORT_EV_CONNECTED); - } + if (!(p_port->port_ctrl & PORT_CTRL_REQ_CONFIRMED)) { + p_port->port_ctrl |= PORT_CTRL_REQ_CONFIRMED; if (p_port->port_ctrl & PORT_CTRL_IND_RECEIVED) - { - event |= port_rfc_send_tx_data(p_port); - } + event = (p_port->ev_mask & PORT_EV_CONNECTED); + } - /* execute call back function only if the application is registered for events */ - if (event && p_port->p_callback) - (p_port->p_callback)(event, p_port->inx); -} + if (p_port->port_ctrl & PORT_CTRL_IND_RECEIVED) { + event |= port_rfc_send_tx_data(p_port); + } + /* execute call back function only if the application is registered for events + */ + if (event && p_port->p_callback) (p_port->p_callback)(event, p_port->inx); +} /******************************************************************************* * @@ -721,32 +662,26 @@ void PORT_ControlCnf (tRFC_MCB *p_mcb, uint8_t dlci, * peer indicates change in the line status * ******************************************************************************/ -void PORT_LineStatusInd (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t line_status) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - uint32_t event = 0; +void PORT_LineStatusInd(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t line_status) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + uint32_t event = 0; - RFCOMM_TRACE_EVENT ("PORT_LineStatusInd"); + RFCOMM_TRACE_EVENT("PORT_LineStatusInd"); - if (!p_port) - return; + if (!p_port) return; - p_port->line_status |= line_status; + p_port->line_status |= line_status; - if (line_status & PORT_ERR_OVERRUN) - event |= PORT_EV_OVERRUN; + if (line_status & PORT_ERR_OVERRUN) event |= PORT_EV_OVERRUN; - if (line_status & PORT_ERR_BREAK) - event |= PORT_EV_BREAK; + if (line_status & PORT_ERR_BREAK) event |= PORT_EV_BREAK; - if (line_status & ~(PORT_ERR_OVERRUN | PORT_ERR_BREAK)) - event |= PORT_EV_ERR; + if (line_status & ~(PORT_ERR_OVERRUN | PORT_ERR_BREAK)) event |= PORT_EV_ERR; - if ((p_port->p_callback != NULL) && (p_port->ev_mask & event)) - p_port->p_callback ((p_port->ev_mask & event), p_port->inx); + if ((p_port->p_callback != NULL) && (p_port->ev_mask & event)) + p_port->p_callback((p_port->ev_mask & event), p_port->inx); } - /******************************************************************************* * * Function PORT_DlcReleaseInd @@ -755,19 +690,16 @@ void PORT_LineStatusInd (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t line_status) * DLC connection is released. * ******************************************************************************/ -void PORT_DlcReleaseInd (tRFC_MCB *p_mcb, uint8_t dlci) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); +void PORT_DlcReleaseInd(tRFC_MCB* p_mcb, uint8_t dlci) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); - RFCOMM_TRACE_EVENT ("PORT_DlcReleaseInd"); + RFCOMM_TRACE_EVENT("PORT_DlcReleaseInd"); - if (!p_port) - return; + if (!p_port) return; - port_rfc_closed (p_port, PORT_CLOSED); + port_rfc_closed(p_port, PORT_CLOSED); } - /******************************************************************************* * * Function PORT_CloseInd @@ -776,22 +708,19 @@ void PORT_DlcReleaseInd (tRFC_MCB *p_mcb, uint8_t dlci) * multiplexer connection is released. * ******************************************************************************/ -void PORT_CloseInd (tRFC_MCB *p_mcb) -{ - tPORT *p_port; - int i; - - RFCOMM_TRACE_EVENT ("PORT_CloseInd"); - - p_port = &rfc_cb.port.port[0]; - for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) - { - if (p_port->rfc.p_mcb == p_mcb) - { - port_rfc_closed (p_port, PORT_PEER_CONNECTION_FAILED); - } +void PORT_CloseInd(tRFC_MCB* p_mcb) { + tPORT* p_port; + int i; + + RFCOMM_TRACE_EVENT("PORT_CloseInd"); + + p_port = &rfc_cb.port.port[0]; + for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) { + if (p_port->rfc.p_mcb == p_mcb) { + port_rfc_closed(p_port, PORT_PEER_CONNECTION_FAILED); } - rfc_release_multiplexer_channel (p_mcb); + } + rfc_release_multiplexer_channel(p_mcb); } /******************************************************************************* @@ -802,24 +731,20 @@ void PORT_CloseInd (tRFC_MCB *p_mcb) * as a result multiplexer connection is closed. * ******************************************************************************/ -void Port_TimeOutCloseMux (tRFC_MCB *p_mcb) -{ - tPORT *p_port; - int i; - - RFCOMM_TRACE_EVENT ("Port_TimeOutCloseMux"); - - p_port = &rfc_cb.port.port[0]; - for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) - { - if (p_port->rfc.p_mcb == p_mcb) - { - port_rfc_closed (p_port, PORT_PEER_TIMEOUT); - } +void Port_TimeOutCloseMux(tRFC_MCB* p_mcb) { + tPORT* p_port; + int i; + + RFCOMM_TRACE_EVENT("Port_TimeOutCloseMux"); + + p_port = &rfc_cb.port.port[0]; + for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) { + if (p_port->rfc.p_mcb == p_mcb) { + port_rfc_closed(p_port, PORT_PEER_TIMEOUT); } + } } - /******************************************************************************* * * Function PORT_DataInd @@ -828,99 +753,94 @@ void Port_TimeOutCloseMux (tRFC_MCB *p_mcb) * buffer is received from the peer. * ******************************************************************************/ -void PORT_DataInd (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf) -{ - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - uint8_t rx_char1; - uint32_t events = 0; - uint8_t *p; - int i; - - RFCOMM_TRACE_EVENT("PORT_DataInd with data length %d, p_mcb:%p,p_port:%p,dlci:%d", - p_buf->len, p_mcb, p_port, dlci); - if (!p_port) - { - osi_free(p_buf); - return; - } - /* If client registered callout callback with flow control we can just deliver receive data */ - if (p_port->p_data_co_callback) - { - /* Another packet is delivered to user. Send credits to peer if required */ - - if(p_port->p_data_co_callback(p_port->inx, (uint8_t*)p_buf, -1, DATA_CO_CALLBACK_TYPE_INCOMING)) - port_flow_control_peer(p_port, true, 1); - else port_flow_control_peer(p_port, false, 0); - //osi_free(p_buf); - return; - } - else RFCOMM_TRACE_ERROR("PORT_DataInd, p_port:%p, p_data_co_callback is null", p_port); - /* If client registered callback we can just deliver receive data */ - if (p_port->p_data_callback) - { - /* Another packet is delivered to user. Send credits to peer if required */ - port_flow_control_peer(p_port, true, 1); - - p_port->p_data_callback (p_port->inx, (uint8_t *)(p_buf + 1) + p_buf->offset, p_buf->len); - osi_free(p_buf); - return; +void PORT_DataInd(tRFC_MCB* p_mcb, uint8_t dlci, BT_HDR* p_buf) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + uint8_t rx_char1; + uint32_t events = 0; + uint8_t* p; + int i; + + RFCOMM_TRACE_EVENT( + "PORT_DataInd with data length %d, p_mcb:%p,p_port:%p,dlci:%d", + p_buf->len, p_mcb, p_port, dlci); + if (!p_port) { + osi_free(p_buf); + return; + } + /* If client registered callout callback with flow control we can just deliver + * receive data */ + if (p_port->p_data_co_callback) { + /* Another packet is delivered to user. Send credits to peer if required */ + + if (p_port->p_data_co_callback(p_port->inx, (uint8_t*)p_buf, -1, + DATA_CO_CALLBACK_TYPE_INCOMING)) + port_flow_control_peer(p_port, true, 1); + else + port_flow_control_peer(p_port, false, 0); + // osi_free(p_buf); + return; + } else + RFCOMM_TRACE_ERROR("PORT_DataInd, p_port:%p, p_data_co_callback is null", + p_port); + /* If client registered callback we can just deliver receive data */ + if (p_port->p_data_callback) { + /* Another packet is delivered to user. Send credits to peer if required */ + port_flow_control_peer(p_port, true, 1); + + p_port->p_data_callback(p_port->inx, (uint8_t*)(p_buf + 1) + p_buf->offset, + p_buf->len); + osi_free(p_buf); + return; + } + + /* Check if rx queue exceeds the limit */ + if ((p_port->rx.queue_size + p_buf->len > PORT_RX_CRITICAL_WM) || + (fixed_queue_length(p_port->rx.queue) + 1 > p_port->rx_buf_critical)) { + RFCOMM_TRACE_EVENT("PORT_DataInd. Buffer over run. Dropping the buffer"); + osi_free(p_buf); + + RFCOMM_LineStatusReq(p_mcb, dlci, LINE_STATUS_OVERRUN); + return; + } + + /* If user registered to receive notification when a particular byte is */ + /* received we mast check all received bytes */ + if (((rx_char1 = p_port->user_port_pars.rx_char1) != 0) && + (p_port->ev_mask & PORT_EV_RXFLAG)) { + for (i = 0, p = (uint8_t*)(p_buf + 1) + p_buf->offset; i < p_buf->len; + i++) { + if (*p++ == rx_char1) { + events |= PORT_EV_RXFLAG; + break; + } } + } - /* Check if rx queue exceeds the limit */ - if ((p_port->rx.queue_size + p_buf->len > PORT_RX_CRITICAL_WM) - || (fixed_queue_length(p_port->rx.queue) + 1 > p_port->rx_buf_critical)) - { - RFCOMM_TRACE_EVENT ("PORT_DataInd. Buffer over run. Dropping the buffer"); - osi_free(p_buf); + mutex_global_lock(); - RFCOMM_LineStatusReq (p_mcb, dlci, LINE_STATUS_OVERRUN); - return; - } + fixed_queue_enqueue(p_port->rx.queue, p_buf); + p_port->rx.queue_size += p_buf->len; - /* If user registered to receive notification when a particular byte is */ - /* received we mast check all received bytes */ - if (((rx_char1 = p_port->user_port_pars.rx_char1) != 0) - && (p_port->ev_mask & PORT_EV_RXFLAG)) - { - for (i = 0, p = (uint8_t *)(p_buf + 1) + p_buf->offset; i < p_buf->len; i++) - { - if (*p++ == rx_char1) - { - events |= PORT_EV_RXFLAG; - break; - } - } - } + mutex_global_unlock(); - mutex_global_lock(); + /* perform flow control procedures if necessary */ + port_flow_control_peer(p_port, false, 0); - fixed_queue_enqueue(p_port->rx.queue, p_buf); - p_port->rx.queue_size += p_buf->len; + /* If user indicated flow control can not deliver any notifications to him */ + if (p_port->rx.user_fc) { + if (events & PORT_EV_RXFLAG) p_port->rx_flag_ev_pending = true; - mutex_global_unlock(); + return; + } - /* perform flow control procedures if necessary */ - port_flow_control_peer(p_port, false, 0); + events |= PORT_EV_RXCHAR; - /* If user indicated flow control can not deliver any notifications to him */ - if (p_port->rx.user_fc) - { - if (events & PORT_EV_RXFLAG) - p_port->rx_flag_ev_pending = true; + /* Mask out all events that are not of interest to user */ + events &= p_port->ev_mask; - return; - } - - events |= PORT_EV_RXCHAR; - - /* Mask out all events that are not of interest to user */ - events &= p_port->ev_mask; - - if (p_port->p_callback && events) - p_port->p_callback (events, p_port->inx); + if (p_port->p_callback && events) p_port->p_callback(events, p_port->inx); } - /******************************************************************************* * * Function PORT_FlowInd @@ -929,60 +849,49 @@ void PORT_DataInd (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf) * control signal change. Propagate change to the user. * ******************************************************************************/ -void PORT_FlowInd (tRFC_MCB *p_mcb, uint8_t dlci, bool enable_data) -{ - tPORT *p_port = (tPORT *)NULL; - uint32_t events = 0; - int i; - - RFCOMM_TRACE_EVENT ("PORT_FlowInd fc:%d", enable_data); - - if (dlci == 0) - { - p_mcb->peer_ready = enable_data; +void PORT_FlowInd(tRFC_MCB* p_mcb, uint8_t dlci, bool enable_data) { + tPORT* p_port = (tPORT*)NULL; + uint32_t events = 0; + int i; + + RFCOMM_TRACE_EVENT("PORT_FlowInd fc:%d", enable_data); + + if (dlci == 0) { + p_mcb->peer_ready = enable_data; + } else { + p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) return; + + p_port->tx.peer_fc = !enable_data; + } + + for (i = 0; i < MAX_RFC_PORTS; i++) { + /* If DLCI is 0 event applies to all ports */ + if (dlci == 0) { + p_port = &rfc_cb.port.port[i]; + if (!p_port->in_use || (p_port->rfc.p_mcb != p_mcb) || + (p_port->rfc.state != RFC_STATE_OPENED)) + continue; } - else - { - p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) - return; - - p_port->tx.peer_fc = !enable_data; - } - - for (i = 0; i < MAX_RFC_PORTS; i++) - { - /* If DLCI is 0 event applies to all ports */ - if (dlci == 0) - { - p_port = &rfc_cb.port.port[i]; - if (!p_port->in_use - || (p_port->rfc.p_mcb != p_mcb) - || (p_port->rfc.state != RFC_STATE_OPENED)) - continue; - } - events = 0; + events = 0; - /* Check if flow of data is still enabled */ - events |= port_flow_control_user (p_port); + /* Check if flow of data is still enabled */ + events |= port_flow_control_user(p_port); - /* Check if data can be sent and send it */ - events |= port_rfc_send_tx_data (p_port); + /* Check if data can be sent and send it */ + events |= port_rfc_send_tx_data(p_port); - /* Mask out all events that are not of interest to user */ - events &= p_port->ev_mask; + /* Mask out all events that are not of interest to user */ + events &= p_port->ev_mask; - /* Send event to the application */ - if (p_port->p_callback && events) - (p_port->p_callback)(events, p_port->inx); + /* Send event to the application */ + if (p_port->p_callback && events) (p_port->p_callback)(events, p_port->inx); - /* If DLCI is not 0 event applies to one port only */ - if (dlci != 0) - break; - } + /* If DLCI is not 0 event applies to one port only */ + if (dlci != 0) break; + } } - /******************************************************************************* * * Function port_rfc_send_tx_data @@ -990,55 +899,50 @@ void PORT_FlowInd (tRFC_MCB *p_mcb, uint8_t dlci, bool enable_data) * Description This function is when forward data can be sent to the peer * ******************************************************************************/ -uint32_t port_rfc_send_tx_data (tPORT *p_port) -{ - uint32_t events = 0; - BT_HDR *p_buf; - - /* if there is data to be sent */ - if (p_port->tx.queue_size > 0) - { - /* while the rfcomm peer is not flow controlling us, and peer is ready */ - while (!p_port->tx.peer_fc && p_port->rfc.p_mcb && p_port->rfc.p_mcb->peer_ready) - { - /* get data from tx queue and send it */ - mutex_global_lock(); - - p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue); - if (p_buf != NULL) - { - p_port->tx.queue_size -= p_buf->len; - - mutex_global_unlock(); - - RFCOMM_TRACE_DEBUG ("Sending RFCOMM_DataReq tx.queue_size=%d", p_port->tx.queue_size); - - RFCOMM_DataReq (p_port->rfc.p_mcb, p_port->dlci, p_buf); - - events |= PORT_EV_TXCHAR; - - if (p_port->tx.queue_size == 0) - { - events |= PORT_EV_TXEMPTY; - break; - } - } - /* queue is empty-- all data sent */ - else - { - mutex_global_unlock(); - - events |= PORT_EV_TXEMPTY; - break; - } +uint32_t port_rfc_send_tx_data(tPORT* p_port) { + uint32_t events = 0; + BT_HDR* p_buf; + + /* if there is data to be sent */ + if (p_port->tx.queue_size > 0) { + /* while the rfcomm peer is not flow controlling us, and peer is ready */ + while (!p_port->tx.peer_fc && p_port->rfc.p_mcb && + p_port->rfc.p_mcb->peer_ready) { + /* get data from tx queue and send it */ + mutex_global_lock(); + + p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->tx.queue); + if (p_buf != NULL) { + p_port->tx.queue_size -= p_buf->len; + + mutex_global_unlock(); + + RFCOMM_TRACE_DEBUG("Sending RFCOMM_DataReq tx.queue_size=%d", + p_port->tx.queue_size); + + RFCOMM_DataReq(p_port->rfc.p_mcb, p_port->dlci, p_buf); + + events |= PORT_EV_TXCHAR; + + if (p_port->tx.queue_size == 0) { + events |= PORT_EV_TXEMPTY; + break; } - /* If we flow controlled user based on the queue size enable data again */ - events |= port_flow_control_user (p_port); + } + /* queue is empty-- all data sent */ + else { + mutex_global_unlock(); + + events |= PORT_EV_TXEMPTY; + break; + } } - return (events & p_port->ev_mask); + /* If we flow controlled user based on the queue size enable data again */ + events |= port_flow_control_user(p_port); + } + return (events & p_port->ev_mask); } - /******************************************************************************* * * Function port_rfc_closed @@ -1046,66 +950,63 @@ uint32_t port_rfc_send_tx_data (tPORT *p_port) * Description This function when RFCOMM side of port is closed * ******************************************************************************/ -void port_rfc_closed (tPORT *p_port, uint8_t res) -{ - uint8_t old_signals; - uint32_t events = 0; - tRFC_MCB *p_mcb = p_port->rfc.p_mcb; - - if ((p_port->state == PORT_STATE_OPENING) && (p_port->is_server)) - { - /* The servr side has not been informed that connection is up, ignore */ - RFCOMM_TRACE_EVENT ("port_rfc_closed in OPENING state ignored"); - - rfc_port_timer_stop (p_port); - p_port->rfc.state = RFC_STATE_CLOSED; - - if (p_mcb) - { - p_mcb->port_inx[p_port->dlci] = 0; - - /* If there are no more ports opened on this MCB release it */ - rfc_check_mcb_active (p_mcb); - p_port->rfc.p_mcb = NULL; - } +void port_rfc_closed(tPORT* p_port, uint8_t res) { + uint8_t old_signals; + uint32_t events = 0; + tRFC_MCB* p_mcb = p_port->rfc.p_mcb; + + if ((p_port->state == PORT_STATE_OPENING) && (p_port->is_server)) { + /* The servr side has not been informed that connection is up, ignore */ + RFCOMM_TRACE_EVENT("port_rfc_closed in OPENING state ignored"); + + rfc_port_timer_stop(p_port); + p_port->rfc.state = RFC_STATE_CLOSED; - /* Need to restore DLCI to listening state - * if the server was on the initiating RFC - */ - p_port->dlci &= 0xfe; + if (p_mcb) { + p_mcb->port_inx[p_port->dlci] = 0; - return; + /* If there are no more ports opened on this MCB release it */ + rfc_check_mcb_active(p_mcb); + p_port->rfc.p_mcb = NULL; } - if ((p_port->state != PORT_STATE_CLOSING) && (p_port->state != PORT_STATE_CLOSED)) - { - p_port->line_status |= LINE_STATUS_FAILED; + /* Need to restore DLCI to listening state + * if the server was on the initiating RFC + */ + p_port->dlci &= 0xfe; - old_signals = p_port->peer_ctrl.modem_signal; + return; + } - p_port->peer_ctrl.modem_signal &= ~(PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); + if ((p_port->state != PORT_STATE_CLOSING) && + (p_port->state != PORT_STATE_CLOSED)) { + p_port->line_status |= LINE_STATUS_FAILED; - events |= port_get_signal_changes (p_port, old_signals, p_port->peer_ctrl.modem_signal); + old_signals = p_port->peer_ctrl.modem_signal; - if(p_port->ev_mask & PORT_EV_CONNECT_ERR) - events |= PORT_EV_CONNECT_ERR; - } - RFCOMM_TRACE_EVENT ("port_rfc_closed state:%d sending events:%x", p_port->state, events); + p_port->peer_ctrl.modem_signal &= + ~(PORT_DTRDSR_ON | PORT_CTSRTS_ON | PORT_DCD_ON); - if ((p_port->p_callback != NULL) && events) - p_port->p_callback (events, p_port->inx); + events |= port_get_signal_changes(p_port, old_signals, + p_port->peer_ctrl.modem_signal); - if (p_port->p_mgmt_callback) - p_port->p_mgmt_callback (res, p_port->inx); + if (p_port->ev_mask & PORT_EV_CONNECT_ERR) events |= PORT_EV_CONNECT_ERR; + } + RFCOMM_TRACE_EVENT("port_rfc_closed state:%d sending events:%x", + p_port->state, events); - p_port->rfc.state = RFC_STATE_CLOSED; + if ((p_port->p_callback != NULL) && events) + p_port->p_callback(events, p_port->inx); - RFCOMM_TRACE_WARNING ("%s RFCOMM connection in state %d closed: %s (res: %d)", - __func__, p_port->state, PORT_GetResultString(res), res); + if (p_port->p_mgmt_callback) p_port->p_mgmt_callback(res, p_port->inx); - port_release_port (p_port); -} + p_port->rfc.state = RFC_STATE_CLOSED; + RFCOMM_TRACE_WARNING("%s RFCOMM connection in state %d closed: %s (res: %d)", + __func__, p_port->state, PORT_GetResultString(res), res); + + port_release_port(p_port); +} /******************************************************************************* * @@ -1117,9 +1018,7 @@ void port_rfc_closed (tPORT *p_port, uint8_t res) * should be less then 255 * ******************************************************************************/ -void port_get_credits (tPORT *p_port, uint8_t k) -{ - p_port->credit_tx = k; - if (p_port->credit_tx == 0) - p_port->tx.peer_fc = true; +void port_get_credits(tPORT* p_port, uint8_t k) { + p_port->credit_tx = k; + if (p_port->credit_tx == 0) p_port->tx.peer_fc = true; } diff --git a/stack/rfcomm/port_utils.cc b/stack/rfcomm/port_utils.cc index 7f5f5a8bd..20e6a88ae 100644 --- a/stack/rfcomm/port_utils.cc +++ b/stack/rfcomm/port_utils.cc @@ -25,8 +25,8 @@ #include "osi/include/mutex.h" -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" #include "btm_int.h" #include "btu.h" #include "l2cdefs.h" @@ -35,21 +35,18 @@ #include "rfc_int.h" #include "rfcdefs.h" -static const tPORT_STATE default_port_pars = -{ +static const tPORT_STATE default_port_pars = { PORT_BAUD_RATE_9600, PORT_8_BITS, PORT_ONESTOPBIT, PORT_PARITY_NO, PORT_ODD_PARITY, PORT_FC_OFF, - 0, /* No rx_char */ + 0, /* No rx_char */ PORT_XON_DC1, PORT_XOFF_DC3, }; - - /******************************************************************************* * * Function port_allocate_port @@ -62,45 +59,43 @@ static const tPORT_STATE default_port_pars = * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT *port_allocate_port (uint8_t dlci, BD_ADDR bd_addr) -{ - tPORT *p_port = &rfc_cb.port.port[0]; - uint8_t xx, yy; - - for (xx = 0, yy = rfc_cb.rfc.last_port + 1; xx < MAX_RFC_PORTS; xx++, yy++) - { - if (yy >= MAX_RFC_PORTS) - yy = 0; - - p_port = &rfc_cb.port.port[yy]; - if (!p_port->in_use) - { - memset(p_port, 0, sizeof (tPORT)); - - p_port->in_use = true; - p_port->inx = yy + 1; - - /* During the open set default state for the port connection */ - port_set_defaults (p_port); - - p_port->rfc.port_timer = alarm_new("rfcomm_port.port_timer"); - rfc_cb.rfc.last_port = yy; - - p_port->dlci = dlci; - memcpy (p_port->bd_addr, bd_addr, BD_ADDR_LEN); - - RFCOMM_TRACE_DEBUG("rfc_cb.port.port[%d]:%p allocated, last_port:%d", yy, p_port, rfc_cb.rfc.last_port); - RFCOMM_TRACE_DEBUG("port_allocate_port:bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - return (p_port); - } +tPORT* port_allocate_port(uint8_t dlci, BD_ADDR bd_addr) { + tPORT* p_port = &rfc_cb.port.port[0]; + uint8_t xx, yy; + + for (xx = 0, yy = rfc_cb.rfc.last_port + 1; xx < MAX_RFC_PORTS; xx++, yy++) { + if (yy >= MAX_RFC_PORTS) yy = 0; + + p_port = &rfc_cb.port.port[yy]; + if (!p_port->in_use) { + memset(p_port, 0, sizeof(tPORT)); + + p_port->in_use = true; + p_port->inx = yy + 1; + + /* During the open set default state for the port connection */ + port_set_defaults(p_port); + + p_port->rfc.port_timer = alarm_new("rfcomm_port.port_timer"); + rfc_cb.rfc.last_port = yy; + + p_port->dlci = dlci; + memcpy(p_port->bd_addr, bd_addr, BD_ADDR_LEN); + + RFCOMM_TRACE_DEBUG("rfc_cb.port.port[%d]:%p allocated, last_port:%d", yy, + p_port, rfc_cb.rfc.last_port); + RFCOMM_TRACE_DEBUG( + "port_allocate_port:bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + return (p_port); } + } - /* If here, no free PORT found */ - return (NULL); + /* If here, no free PORT found */ + return (NULL); } - /******************************************************************************* * * Function port_set_defaults @@ -109,29 +104,28 @@ tPORT *port_allocate_port (uint8_t dlci, BD_ADDR bd_addr) * * ******************************************************************************/ -void port_set_defaults (tPORT *p_port) -{ - p_port->ev_mask = 0; - p_port->p_callback = NULL; - p_port->port_ctrl = 0; - p_port->error = 0; - p_port->line_status = 0; - p_port->rx_flag_ev_pending = false; - p_port->peer_mtu = RFCOMM_DEFAULT_MTU; - - p_port->user_port_pars = default_port_pars; - p_port->peer_port_pars = default_port_pars; - - p_port->credit_tx = 0; - p_port->credit_rx = 0; - - memset (&p_port->local_ctrl, 0, sizeof (p_port->local_ctrl)); - memset (&p_port->peer_ctrl, 0, sizeof (p_port->peer_ctrl)); - memset (&p_port->rx, 0, sizeof (p_port->rx)); - memset (&p_port->tx, 0, sizeof (p_port->tx)); - - p_port->tx.queue = fixed_queue_new(SIZE_MAX); - p_port->rx.queue = fixed_queue_new(SIZE_MAX); +void port_set_defaults(tPORT* p_port) { + p_port->ev_mask = 0; + p_port->p_callback = NULL; + p_port->port_ctrl = 0; + p_port->error = 0; + p_port->line_status = 0; + p_port->rx_flag_ev_pending = false; + p_port->peer_mtu = RFCOMM_DEFAULT_MTU; + + p_port->user_port_pars = default_port_pars; + p_port->peer_port_pars = default_port_pars; + + p_port->credit_tx = 0; + p_port->credit_rx = 0; + + memset(&p_port->local_ctrl, 0, sizeof(p_port->local_ctrl)); + memset(&p_port->peer_ctrl, 0, sizeof(p_port->peer_ctrl)); + memset(&p_port->rx, 0, sizeof(p_port->rx)); + memset(&p_port->tx, 0, sizeof(p_port->tx)); + + p_port->tx.queue = fixed_queue_new(SIZE_MAX); + p_port->rx.queue = fixed_queue_new(SIZE_MAX); } /******************************************************************************* @@ -145,58 +139,59 @@ void port_set_defaults (tPORT *p_port) * * ******************************************************************************/ -void port_select_mtu (tPORT *p_port) -{ - uint16_t packet_size; - - /* Will select MTU only if application did not setup something */ - if (p_port->mtu == 0) - { - /* find packet size which connection supports */ - packet_size = btm_get_max_packet_size (p_port->bd_addr); - if (packet_size == 0) - { - /* something is very wrong */ - RFCOMM_TRACE_WARNING ("port_select_mtu bad packet size"); - p_port->mtu = RFCOMM_DEFAULT_MTU; - } - else - { - /* We try to negotiate MTU that each packet can be split into whole - number of max packets. For example if link is 1.2 max packet size is 339 bytes. - At first calculate how many whole packets it is. MAX L2CAP is 1691 + 4 overhead. - 1695, that will be 5 Dh5 packets. Now maximum RFCOMM packet is - 5 * 339 = 1695. Minus 4 bytes L2CAP header 1691. Minus RFCOMM 6 bytes header overhead 1685 - - For EDR 2.0 packet size is 1027. So we better send RFCOMM packet as 1 3DH5 packet - 1 * 1027 = 1027. Minus 4 bytes L2CAP header 1023. Minus RFCOMM 6 bytes header overhead 1017 */ - if ((L2CAP_MTU_SIZE + L2CAP_PKT_OVERHEAD) >= packet_size) - { - p_port->mtu = ((L2CAP_MTU_SIZE + L2CAP_PKT_OVERHEAD) / packet_size * packet_size) - RFCOMM_DATA_OVERHEAD - L2CAP_PKT_OVERHEAD; - RFCOMM_TRACE_DEBUG ("port_select_mtu selected %d based on connection speed", p_port->mtu); - } - else - { - p_port->mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD; - RFCOMM_TRACE_DEBUG ("port_select_mtu selected %d based on l2cap PDU size", p_port->mtu); - } - } - } - else - { - RFCOMM_TRACE_DEBUG ("port_select_mtu application selected %d", p_port->mtu); +void port_select_mtu(tPORT* p_port) { + uint16_t packet_size; + + /* Will select MTU only if application did not setup something */ + if (p_port->mtu == 0) { + /* find packet size which connection supports */ + packet_size = btm_get_max_packet_size(p_port->bd_addr); + if (packet_size == 0) { + /* something is very wrong */ + RFCOMM_TRACE_WARNING("port_select_mtu bad packet size"); + p_port->mtu = RFCOMM_DEFAULT_MTU; + } else { + /* We try to negotiate MTU that each packet can be split into whole + number of max packets. For example if link is 1.2 max packet size is 339 + bytes. + At first calculate how many whole packets it is. MAX L2CAP is 1691 + 4 + overhead. + 1695, that will be 5 Dh5 packets. Now maximum RFCOMM packet is + 5 * 339 = 1695. Minus 4 bytes L2CAP header 1691. Minus RFCOMM 6 bytes + header overhead 1685 + + For EDR 2.0 packet size is 1027. So we better send RFCOMM packet as 1 + 3DH5 packet + 1 * 1027 = 1027. Minus 4 bytes L2CAP header 1023. Minus RFCOMM 6 bytes + header overhead 1017 */ + if ((L2CAP_MTU_SIZE + L2CAP_PKT_OVERHEAD) >= packet_size) { + p_port->mtu = ((L2CAP_MTU_SIZE + L2CAP_PKT_OVERHEAD) / packet_size * + packet_size) - + RFCOMM_DATA_OVERHEAD - L2CAP_PKT_OVERHEAD; + RFCOMM_TRACE_DEBUG( + "port_select_mtu selected %d based on connection speed", + p_port->mtu); + } else { + p_port->mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD; + RFCOMM_TRACE_DEBUG( + "port_select_mtu selected %d based on l2cap PDU size", p_port->mtu); + } } - p_port->credit_rx_max = (PORT_RX_HIGH_WM / p_port->mtu); - if( p_port->credit_rx_max > PORT_RX_BUF_HIGH_WM ) - p_port->credit_rx_max = PORT_RX_BUF_HIGH_WM; - p_port->credit_rx_low = (PORT_RX_LOW_WM / p_port->mtu); - if( p_port->credit_rx_low > PORT_RX_BUF_LOW_WM ) - p_port->credit_rx_low = PORT_RX_BUF_LOW_WM; - p_port->rx_buf_critical = (PORT_RX_CRITICAL_WM / p_port->mtu); - if( p_port->rx_buf_critical > PORT_RX_BUF_CRITICAL_WM ) - p_port->rx_buf_critical = PORT_RX_BUF_CRITICAL_WM; - RFCOMM_TRACE_DEBUG ("port_select_mtu credit_rx_max %d, credit_rx_low %d, rx_buf_critical %d", - p_port->credit_rx_max, p_port->credit_rx_low, p_port->rx_buf_critical); + } else { + RFCOMM_TRACE_DEBUG("port_select_mtu application selected %d", p_port->mtu); + } + p_port->credit_rx_max = (PORT_RX_HIGH_WM / p_port->mtu); + if (p_port->credit_rx_max > PORT_RX_BUF_HIGH_WM) + p_port->credit_rx_max = PORT_RX_BUF_HIGH_WM; + p_port->credit_rx_low = (PORT_RX_LOW_WM / p_port->mtu); + if (p_port->credit_rx_low > PORT_RX_BUF_LOW_WM) + p_port->credit_rx_low = PORT_RX_BUF_LOW_WM; + p_port->rx_buf_critical = (PORT_RX_CRITICAL_WM / p_port->mtu); + if (p_port->rx_buf_critical > PORT_RX_BUF_CRITICAL_WM) + p_port->rx_buf_critical = PORT_RX_BUF_CRITICAL_WM; + RFCOMM_TRACE_DEBUG( + "port_select_mtu credit_rx_max %d, credit_rx_low %d, rx_buf_critical %d", + p_port->credit_rx_max, p_port->credit_rx_low, p_port->rx_buf_critical); } /******************************************************************************* @@ -208,72 +203,67 @@ void port_select_mtu (tPORT *p_port) * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -void port_release_port(tPORT *p_port) -{ - RFCOMM_TRACE_DEBUG("%s p_port: %p state: %d keep_handle: %d", __func__, - p_port, p_port->rfc.state, p_port->keep_port_handle); - - mutex_global_lock(); - BT_HDR *p_buf; - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) - osi_free(p_buf); - p_port->rx.queue_size = 0; - - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) - osi_free(p_buf); - p_port->tx.queue_size = 0; - mutex_global_unlock(); - - alarm_cancel(p_port->rfc.port_timer); - - p_port->state = PORT_STATE_CLOSED; - - if (p_port->rfc.state == RFC_STATE_CLOSED) - { - if (p_port->rfc.p_mcb) - { - p_port->rfc.p_mcb->port_inx[p_port->dlci] = 0; - - /* If there are no more ports opened on this MCB release it */ - rfc_check_mcb_active(p_port->rfc.p_mcb); - } - - rfc_port_timer_stop (p_port); - fixed_queue_free(p_port->tx.queue, NULL); - p_port->tx.queue = NULL; - fixed_queue_free(p_port->rx.queue, NULL); - p_port->rx.queue = NULL; - - if (p_port->keep_port_handle) - { - RFCOMM_TRACE_DEBUG("%s Re-initialize handle: %d", __func__, p_port->inx); - - /* save event mask and callback */ - uint32_t mask = p_port->ev_mask; - tPORT_CALLBACK *p_port_cb = p_port->p_callback; - tPORT_STATE user_port_pars = p_port->user_port_pars; - - port_set_defaults(p_port); - - /* restore */ - p_port->ev_mask = mask; - p_port->p_callback = p_port_cb; - p_port->user_port_pars = user_port_pars; - p_port->mtu = p_port->keep_mtu; - - p_port->state = PORT_STATE_OPENING; - p_port->rfc.p_mcb = NULL; - if (p_port->is_server) - p_port->dlci &= 0xfe; - - p_port->local_ctrl.modem_signal = p_port->default_signal_state; - memcpy (p_port->bd_addr, BT_BD_ANY, BD_ADDR_LEN); - } else { - RFCOMM_TRACE_DEBUG("%s Clean-up handle: %d", __func__, p_port->inx); - alarm_free(p_port->rfc.port_timer); - memset (p_port, 0, sizeof (tPORT)); - } +void port_release_port(tPORT* p_port) { + RFCOMM_TRACE_DEBUG("%s p_port: %p state: %d keep_handle: %d", __func__, + p_port, p_port->rfc.state, p_port->keep_port_handle); + + mutex_global_lock(); + BT_HDR* p_buf; + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) + osi_free(p_buf); + p_port->rx.queue_size = 0; + + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) + osi_free(p_buf); + p_port->tx.queue_size = 0; + mutex_global_unlock(); + + alarm_cancel(p_port->rfc.port_timer); + + p_port->state = PORT_STATE_CLOSED; + + if (p_port->rfc.state == RFC_STATE_CLOSED) { + if (p_port->rfc.p_mcb) { + p_port->rfc.p_mcb->port_inx[p_port->dlci] = 0; + + /* If there are no more ports opened on this MCB release it */ + rfc_check_mcb_active(p_port->rfc.p_mcb); + } + + rfc_port_timer_stop(p_port); + fixed_queue_free(p_port->tx.queue, NULL); + p_port->tx.queue = NULL; + fixed_queue_free(p_port->rx.queue, NULL); + p_port->rx.queue = NULL; + + if (p_port->keep_port_handle) { + RFCOMM_TRACE_DEBUG("%s Re-initialize handle: %d", __func__, p_port->inx); + + /* save event mask and callback */ + uint32_t mask = p_port->ev_mask; + tPORT_CALLBACK* p_port_cb = p_port->p_callback; + tPORT_STATE user_port_pars = p_port->user_port_pars; + + port_set_defaults(p_port); + + /* restore */ + p_port->ev_mask = mask; + p_port->p_callback = p_port_cb; + p_port->user_port_pars = user_port_pars; + p_port->mtu = p_port->keep_mtu; + + p_port->state = PORT_STATE_OPENING; + p_port->rfc.p_mcb = NULL; + if (p_port->is_server) p_port->dlci &= 0xfe; + + p_port->local_ctrl.modem_signal = p_port->default_signal_state; + memcpy(p_port->bd_addr, BT_BD_ANY, BD_ADDR_LEN); + } else { + RFCOMM_TRACE_DEBUG("%s Clean-up handle: %d", __func__, p_port->inx); + alarm_free(p_port->rfc.port_timer); + memset(p_port, 0, sizeof(tPORT)); } + } } /******************************************************************************* @@ -284,29 +274,29 @@ void port_release_port(tPORT *p_port) * the BD_ADDR. * ******************************************************************************/ -tRFC_MCB *port_find_mcb (BD_ADDR bd_addr) -{ - int i; - - for (i = 0; i < MAX_BD_CONNECTIONS; i++) - { - if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) - && !memcmp (rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN)) - { - /* Multiplexer channel found do not change anything */ - RFCOMM_TRACE_DEBUG("port_find_mcb: found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - RFCOMM_TRACE_DEBUG("port_find_mcb: rfc_cb.port.rfc_mcb:index:%d, %p, lcid:%d", - i, &rfc_cb.port.rfc_mcb[i], rfc_cb.port.rfc_mcb[i].lcid); - return (&rfc_cb.port.rfc_mcb[i]); - } +tRFC_MCB* port_find_mcb(BD_ADDR bd_addr) { + int i; + + for (i = 0; i < MAX_BD_CONNECTIONS; i++) { + if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) && + !memcmp(rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN)) { + /* Multiplexer channel found do not change anything */ + RFCOMM_TRACE_DEBUG( + "port_find_mcb: found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], + bd_addr[5]); + RFCOMM_TRACE_DEBUG( + "port_find_mcb: rfc_cb.port.rfc_mcb:index:%d, %p, lcid:%d", i, + &rfc_cb.port.rfc_mcb[i], rfc_cb.port.rfc_mcb[i].lcid); + return (&rfc_cb.port.rfc_mcb[i]); } - RFCOMM_TRACE_DEBUG("port_find_mcb: not found, bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - return (NULL); + } + RFCOMM_TRACE_DEBUG( + "port_find_mcb: not found, bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + return (NULL); } - /******************************************************************************* * * Function port_find_mcb_dlci_port @@ -319,27 +309,23 @@ tRFC_MCB *port_find_mcb (BD_ADDR bd_addr) * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT *port_find_mcb_dlci_port (tRFC_MCB *p_mcb, uint8_t dlci) -{ - uint8_t inx; +tPORT* port_find_mcb_dlci_port(tRFC_MCB* p_mcb, uint8_t dlci) { + uint8_t inx; - if (!p_mcb) - return (NULL); + if (!p_mcb) return (NULL); - if (dlci > RFCOMM_MAX_DLCI) - return (NULL); + if (dlci > RFCOMM_MAX_DLCI) return (NULL); - inx = p_mcb->port_inx[dlci]; - if (inx == 0) - { - RFCOMM_TRACE_DEBUG("port_find_mcb_dlci_port: p_mcb:%p, port_inx[dlci:%d] is 0", p_mcb, dlci); - return (NULL); - } - else - return (&rfc_cb.port.port[inx - 1]); + inx = p_mcb->port_inx[dlci]; + if (inx == 0) { + RFCOMM_TRACE_DEBUG( + "port_find_mcb_dlci_port: p_mcb:%p, port_inx[dlci:%d] is 0", p_mcb, + dlci); + return (NULL); + } else + return (&rfc_cb.port.port[inx - 1]); } - /******************************************************************************* * * Function port_find_dlci_port @@ -349,32 +335,25 @@ tPORT *port_find_mcb_dlci_port (tRFC_MCB *p_mcb, uint8_t dlci) * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT *port_find_dlci_port (uint8_t dlci) -{ - uint16_t i; - tPORT *p_port; - - for (i = 0; i < MAX_RFC_PORTS; i++) - { - p_port = &rfc_cb.port.port[i]; - - if (p_port->in_use && (p_port->rfc.p_mcb == NULL)) - { - if (p_port->dlci == dlci) - { - return (p_port); - } - else if ((dlci & 0x01) && (p_port->dlci == (dlci - 1))) - { - p_port->dlci++; - return (p_port); - } - } +tPORT* port_find_dlci_port(uint8_t dlci) { + uint16_t i; + tPORT* p_port; + + for (i = 0; i < MAX_RFC_PORTS; i++) { + p_port = &rfc_cb.port.port[i]; + + if (p_port->in_use && (p_port->rfc.p_mcb == NULL)) { + if (p_port->dlci == dlci) { + return (p_port); + } else if ((dlci & 0x01) && (p_port->dlci == (dlci - 1))) { + p_port->dlci++; + return (p_port); + } } - return (NULL); + } + return (NULL); } - /******************************************************************************* * * Function port_find_port @@ -384,25 +363,20 @@ tPORT *port_find_dlci_port (uint8_t dlci) * Returns Pointer to the PORT or NULL if not found * ******************************************************************************/ -tPORT *port_find_port (uint8_t dlci, BD_ADDR bd_addr) -{ - uint16_t i; - tPORT *p_port; - - for (i = 0; i < MAX_RFC_PORTS; i++) - { - p_port = &rfc_cb.port.port[i]; - if (p_port->in_use - && (p_port->dlci == dlci) - && !memcmp (p_port->bd_addr, bd_addr, BD_ADDR_LEN)) - { - return (p_port); - } +tPORT* port_find_port(uint8_t dlci, BD_ADDR bd_addr) { + uint16_t i; + tPORT* p_port; + + for (i = 0; i < MAX_RFC_PORTS; i++) { + p_port = &rfc_cb.port.port[i]; + if (p_port->in_use && (p_port->dlci == dlci) && + !memcmp(p_port->bd_addr, bd_addr, BD_ADDR_LEN)) { + return (p_port); } - return (NULL); + } + return (NULL); } - /******************************************************************************* * * Function port_flow_control_user @@ -414,32 +388,28 @@ tPORT *port_find_port (uint8_t dlci, BD_ADDR bd_addr) * Returns event mask to be returned to the application * ******************************************************************************/ -uint32_t port_flow_control_user (tPORT *p_port) -{ - uint32_t event = 0; - - /* Flow control to the user can be caused by flow controlling by the peer */ - /* (FlowInd, or flow control by the peer RFCOMM (Fcon) or internally if */ - /* tx_queue is full */ - bool fc = p_port->tx.peer_fc - || !p_port->rfc.p_mcb - || !p_port->rfc.p_mcb->peer_ready - || (p_port->tx.queue_size > PORT_TX_HIGH_WM) - || (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM); - - if (p_port->tx.user_fc == fc) - return (0); - - p_port->tx.user_fc = fc; - - if (fc) - event = PORT_EV_FC; - else - event = PORT_EV_FC | PORT_EV_FCS; - - return (event); -} +uint32_t port_flow_control_user(tPORT* p_port) { + uint32_t event = 0; + + /* Flow control to the user can be caused by flow controlling by the peer */ + /* (FlowInd, or flow control by the peer RFCOMM (Fcon) or internally if */ + /* tx_queue is full */ + bool fc = p_port->tx.peer_fc || !p_port->rfc.p_mcb || + !p_port->rfc.p_mcb->peer_ready || + (p_port->tx.queue_size > PORT_TX_HIGH_WM) || + (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_HIGH_WM); + if (p_port->tx.user_fc == fc) return (0); + + p_port->tx.user_fc = fc; + + if (fc) + event = PORT_EV_FC; + else + event = PORT_EV_FC | PORT_EV_FCS; + + return (event); +} /******************************************************************************* * @@ -450,39 +420,32 @@ uint32_t port_flow_control_user (tPORT *p_port) * Returns event mask to be returned to the application * ******************************************************************************/ -uint32_t port_get_signal_changes (tPORT *p_port, uint8_t old_signals, uint8_t signal) -{ - uint8_t changed_signals = (signal ^ old_signals); - uint32_t events = 0; +uint32_t port_get_signal_changes(tPORT* p_port, uint8_t old_signals, + uint8_t signal) { + uint8_t changed_signals = (signal ^ old_signals); + uint32_t events = 0; - if (changed_signals & PORT_DTRDSR_ON) - { - events |= PORT_EV_DSR; + if (changed_signals & PORT_DTRDSR_ON) { + events |= PORT_EV_DSR; - if (signal & PORT_DTRDSR_ON) - events |= PORT_EV_DSRS; - } + if (signal & PORT_DTRDSR_ON) events |= PORT_EV_DSRS; + } - if (changed_signals & PORT_CTSRTS_ON) - { - events |= PORT_EV_CTS; + if (changed_signals & PORT_CTSRTS_ON) { + events |= PORT_EV_CTS; - if (signal & PORT_CTSRTS_ON) - events |= PORT_EV_CTSS; - } + if (signal & PORT_CTSRTS_ON) events |= PORT_EV_CTSS; + } - if (changed_signals & PORT_RING_ON) - events |= PORT_EV_RING; + if (changed_signals & PORT_RING_ON) events |= PORT_EV_RING; - if (changed_signals & PORT_DCD_ON) - { - events |= PORT_EV_RLSD; + if (changed_signals & PORT_DCD_ON) { + events |= PORT_EV_RLSD; - if (signal & PORT_DCD_ON) - events |= PORT_EV_RLSDS; - } + if (signal & PORT_DCD_ON) events |= PORT_EV_RLSDS; + } - return (p_port->ev_mask & events); + return (p_port->ev_mask & events); } /******************************************************************************* @@ -496,97 +459,77 @@ uint32_t port_get_signal_changes (tPORT *p_port, uint8_t old_signals, uint8_t si * Returns nothing * ******************************************************************************/ -void port_flow_control_peer(tPORT *p_port, bool enable, uint16_t count) -{ - if (!p_port->rfc.p_mcb) - return; - - /* If using credit based flow control */ - if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - { - /* if want to enable flow from peer */ - if (enable) - { - /* update rx credits */ - if (count > p_port->credit_rx) - { - p_port->credit_rx = 0; - } - else - { - p_port->credit_rx -= count; - } - - /* If credit count is less than low credit watermark, and user */ - /* did not force flow control, send a credit update */ - /* There might be a special case when we just adjusted rx_max */ - if ((p_port->credit_rx <= p_port->credit_rx_low) - && !p_port->rx.user_fc - && (p_port->credit_rx_max > p_port->credit_rx)) - { - rfc_send_credit(p_port->rfc.p_mcb, p_port->dlci, - (uint8_t) (p_port->credit_rx_max - p_port->credit_rx)); - - p_port->credit_rx = p_port->credit_rx_max; - - p_port->rx.peer_fc = false; - } - } - /* else want to disable flow from peer */ - else - { - /* if client registered data callback, just do what they want */ - if (p_port->p_data_callback || p_port->p_data_co_callback) - { - p_port->rx.peer_fc = true; - } - /* if queue count reached credit rx max, set peer fc */ - else if (fixed_queue_length(p_port->rx.queue) >= p_port->credit_rx_max) - { - p_port->rx.peer_fc = true; - } - } +void port_flow_control_peer(tPORT* p_port, bool enable, uint16_t count) { + if (!p_port->rfc.p_mcb) return; + + /* If using credit based flow control */ + if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { + /* if want to enable flow from peer */ + if (enable) { + /* update rx credits */ + if (count > p_port->credit_rx) { + p_port->credit_rx = 0; + } else { + p_port->credit_rx -= count; + } + + /* If credit count is less than low credit watermark, and user */ + /* did not force flow control, send a credit update */ + /* There might be a special case when we just adjusted rx_max */ + if ((p_port->credit_rx <= p_port->credit_rx_low) && !p_port->rx.user_fc && + (p_port->credit_rx_max > p_port->credit_rx)) { + rfc_send_credit(p_port->rfc.p_mcb, p_port->dlci, + (uint8_t)(p_port->credit_rx_max - p_port->credit_rx)); + + p_port->credit_rx = p_port->credit_rx_max; + + p_port->rx.peer_fc = false; + } + } + /* else want to disable flow from peer */ + else { + /* if client registered data callback, just do what they want */ + if (p_port->p_data_callback || p_port->p_data_co_callback) { + p_port->rx.peer_fc = true; + } + /* if queue count reached credit rx max, set peer fc */ + else if (fixed_queue_length(p_port->rx.queue) >= p_port->credit_rx_max) { + p_port->rx.peer_fc = true; + } } - /* else using TS 07.10 flow control */ - else - { - /* if want to enable flow from peer */ - if (enable) - { - /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ - /* check if it can be resumed now */ - if (p_port->rx.peer_fc - && (p_port->rx.queue_size < PORT_RX_LOW_WM) - && (fixed_queue_length(p_port->rx.queue) < PORT_RX_BUF_LOW_WM)) - { - p_port->rx.peer_fc = false; - - /* If user did not force flow control allow traffic now */ - if (!p_port->rx.user_fc) - RFCOMM_FlowReq (p_port->rfc.p_mcb, p_port->dlci, true); - } - } - /* else want to disable flow from peer */ - else - { - /* if client registered data callback, just do what they want */ - if (p_port->p_data_callback || p_port->p_data_co_callback) - { - p_port->rx.peer_fc = true; - RFCOMM_FlowReq (p_port->rfc.p_mcb, p_port->dlci, false); - } - /* Check the size of the rx queue. If it exceeds certain */ - /* level and flow control has not been sent to the peer do it now */ - else if ( ((p_port->rx.queue_size > PORT_RX_HIGH_WM) - || (fixed_queue_length(p_port->rx.queue) > PORT_RX_BUF_HIGH_WM)) - && !p_port->rx.peer_fc) - { - RFCOMM_TRACE_EVENT ("PORT_DataInd Data reached HW. Sending FC set."); - - p_port->rx.peer_fc = true; - RFCOMM_FlowReq (p_port->rfc.p_mcb, p_port->dlci, false); - } - } + } + /* else using TS 07.10 flow control */ + else { + /* if want to enable flow from peer */ + if (enable) { + /* If rfcomm suspended traffic from the peer based on the rx_queue_size */ + /* check if it can be resumed now */ + if (p_port->rx.peer_fc && (p_port->rx.queue_size < PORT_RX_LOW_WM) && + (fixed_queue_length(p_port->rx.queue) < PORT_RX_BUF_LOW_WM)) { + p_port->rx.peer_fc = false; + + /* If user did not force flow control allow traffic now */ + if (!p_port->rx.user_fc) + RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, true); + } } + /* else want to disable flow from peer */ + else { + /* if client registered data callback, just do what they want */ + if (p_port->p_data_callback || p_port->p_data_co_callback) { + p_port->rx.peer_fc = true; + RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, false); + } + /* Check the size of the rx queue. If it exceeds certain */ + /* level and flow control has not been sent to the peer do it now */ + else if (((p_port->rx.queue_size > PORT_RX_HIGH_WM) || + (fixed_queue_length(p_port->rx.queue) > PORT_RX_BUF_HIGH_WM)) && + !p_port->rx.peer_fc) { + RFCOMM_TRACE_EVENT("PORT_DataInd Data reached HW. Sending FC set."); + + p_port->rx.peer_fc = true; + RFCOMM_FlowReq(p_port->rfc.p_mcb, p_port->dlci, false); + } + } + } } - diff --git a/stack/rfcomm/rfc_int.h b/stack/rfcomm/rfc_int.h index 9826557d8..36a505a40 100644 --- a/stack/rfcomm/rfc_int.h +++ b/stack/rfcomm/rfc_int.h @@ -35,342 +35,349 @@ extern "C" { /* * Define RFCOMM result codes */ -#define RFCOMM_SUCCESS 0 -#define RFCOMM_ERROR 1 -#define RFCOMM_LOW_RESOURCES 2 -#define RFCOMM_TRY_LATER 3 +#define RFCOMM_SUCCESS 0 +#define RFCOMM_ERROR 1 +#define RFCOMM_LOW_RESOURCES 2 +#define RFCOMM_TRY_LATER 3 -#define RFCOMM_USER_ERR 111 -#define RFCOMM_SECURITY_ERR 112 +#define RFCOMM_USER_ERR 111 +#define RFCOMM_SECURITY_ERR 112 /* * Define max and min RFCOMM MTU (N1) */ -#define RFCOMM_MIN_MTU 23 -#define RFCOMM_MAX_MTU 32767 +#define RFCOMM_MIN_MTU 23 +#define RFCOMM_MAX_MTU 32767 -extern void RFCOMM_StartReq (tRFC_MCB *p_mcb); -extern void RFCOMM_StartRsp (tRFC_MCB *p_mcb, uint16_t result); +extern void RFCOMM_StartReq(tRFC_MCB* p_mcb); +extern void RFCOMM_StartRsp(tRFC_MCB* p_mcb, uint16_t result); -extern void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu); -extern void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint16_t result); +extern void RFCOMM_DlcEstablishReq(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu); +extern void RFCOMM_DlcEstablishRsp(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint16_t result); -extern void RFCOMM_DataReq (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf); +extern void RFCOMM_DataReq(tRFC_MCB* p_mcb, uint8_t dlci, BT_HDR* p_buf); -extern void RFCOMM_DlcReleaseReq (tRFC_MCB *p_mcb, uint8_t dlci); +extern void RFCOMM_DlcReleaseReq(tRFC_MCB* p_mcb, uint8_t dlci); -extern void RFCOMM_ParNegReq (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu); -extern void RFCOMM_ParNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k); +extern void RFCOMM_ParNegReq(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu); +extern void RFCOMM_ParNegRsp(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint8_t cl, uint8_t k); -extern void RFCOMM_TestReq (uint8_t *p_data, uint16_t len); +extern void RFCOMM_TestReq(uint8_t* p_data, uint16_t len); -#define RFCOMM_FLOW_STATE_DISABLE 0 -#define RFCOMM_FLOW_STATE_ENABLE 1 +#define RFCOMM_FLOW_STATE_DISABLE 0 +#define RFCOMM_FLOW_STATE_ENABLE 1 -extern void RFCOMM_FlowReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t state); +extern void RFCOMM_FlowReq(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t state); -extern void RFCOMM_PortNegReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars); -extern void RFCOMM_PortNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, uint16_t param_mask); +extern void RFCOMM_PortNegReq(tRFC_MCB* p_mcb, uint8_t dlci, + tPORT_STATE* p_pars); +extern void RFCOMM_PortNegRsp(tRFC_MCB* p_mcb, uint8_t dlci, + tPORT_STATE* p_pars, uint16_t param_mask); -extern void RFCOMM_ControlReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars); -extern void RFCOMM_ControlRsp (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars); +extern void RFCOMM_ControlReq(tRFC_MCB* p_mcb, uint8_t dlci, + tPORT_CTRL* p_pars); +extern void RFCOMM_ControlRsp(tRFC_MCB* p_mcb, uint8_t dlci, + tPORT_CTRL* p_pars); -extern void RFCOMM_LineStatusReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t line_status); +extern void RFCOMM_LineStatusReq(tRFC_MCB* p_mcb, uint8_t dlci, + uint8_t line_status); /* * Define logical struct used for sending and decoding MX frames */ -typedef struct -{ - uint8_t dlci; - uint8_t type; - uint8_t cr; - uint8_t ea; - uint8_t pf; - uint8_t credit; - - union - { - struct - { - uint8_t dlci; - uint8_t frame_type; - uint8_t conv_layer; - uint8_t priority; - uint8_t t1; - uint16_t mtu; - uint8_t n2; - uint8_t k; - } pn; - struct - { - uint8_t *p_data; - uint16_t data_len; - } test; - struct - { - uint8_t dlci; - uint8_t signals; - uint8_t break_present; - uint8_t break_duration; - } msc; - struct - { - uint8_t ea; - uint8_t cr; - uint8_t type; - } nsc; - struct - { - uint8_t dlci; - uint8_t is_request; - uint8_t baud_rate; - uint8_t byte_size; - uint8_t stop_bits; - uint8_t parity; - uint8_t parity_type; - uint8_t fc_type; - uint8_t xon_char; - uint8_t xoff_char; - uint16_t param_mask; - } rpn; - struct - { - uint8_t dlci; - uint8_t line_status; - } rls; - } u; +typedef struct { + uint8_t dlci; + uint8_t type; + uint8_t cr; + uint8_t ea; + uint8_t pf; + uint8_t credit; + + union { + struct { + uint8_t dlci; + uint8_t frame_type; + uint8_t conv_layer; + uint8_t priority; + uint8_t t1; + uint16_t mtu; + uint8_t n2; + uint8_t k; + } pn; + struct { + uint8_t* p_data; + uint16_t data_len; + } test; + struct { + uint8_t dlci; + uint8_t signals; + uint8_t break_present; + uint8_t break_duration; + } msc; + struct { + uint8_t ea; + uint8_t cr; + uint8_t type; + } nsc; + struct { + uint8_t dlci; + uint8_t is_request; + uint8_t baud_rate; + uint8_t byte_size; + uint8_t stop_bits; + uint8_t parity; + uint8_t parity_type; + uint8_t fc_type; + uint8_t xon_char; + uint8_t xoff_char; + uint16_t param_mask; + } rpn; + struct { + uint8_t dlci; + uint8_t line_status; + } rls; + } u; } MX_FRAME; -#define LINE_STATUS_NO_ERROR 0x00 -#define LINE_STATUS_OVERRUN 0x02 /* Receive Overrun Error */ -#define LINE_STATUS_RXPARITY 0x04 /* Receive Parity Error */ -#define LINE_STATUS_FRAME 0x08 /* Receive Framing error */ -#define LINE_STATUS_FAILED 0x10 /* Connection Failed */ +#define LINE_STATUS_NO_ERROR 0x00 +#define LINE_STATUS_OVERRUN 0x02 /* Receive Overrun Error */ +#define LINE_STATUS_RXPARITY 0x04 /* Receive Parity Error */ +#define LINE_STATUS_FRAME 0x08 /* Receive Framing error */ +#define LINE_STATUS_FAILED 0x10 /* Connection Failed */ /* * Define states and events for the RFC multiplexer state machine */ -#define RFC_MX_STATE_IDLE 0 -#define RFC_MX_STATE_WAIT_CONN_CNF 1 -#define RFC_MX_STATE_CONFIGURE 2 -#define RFC_MX_STATE_SABME_WAIT_UA 3 -#define RFC_MX_STATE_WAIT_SABME 4 -#define RFC_MX_STATE_CONNECTED 5 -#define RFC_MX_STATE_DISC_WAIT_UA 6 +#define RFC_MX_STATE_IDLE 0 +#define RFC_MX_STATE_WAIT_CONN_CNF 1 +#define RFC_MX_STATE_CONFIGURE 2 +#define RFC_MX_STATE_SABME_WAIT_UA 3 +#define RFC_MX_STATE_WAIT_SABME 4 +#define RFC_MX_STATE_CONNECTED 5 +#define RFC_MX_STATE_DISC_WAIT_UA 6 /* * Define port states */ -#define RFC_STATE_CLOSED 0 -#define RFC_STATE_SABME_WAIT_UA 1 -#define RFC_STATE_ORIG_WAIT_SEC_CHECK 2 -#define RFC_STATE_TERM_WAIT_SEC_CHECK 3 -#define RFC_STATE_OPENED 4 -#define RFC_STATE_DISC_WAIT_UA 5 +#define RFC_STATE_CLOSED 0 +#define RFC_STATE_SABME_WAIT_UA 1 +#define RFC_STATE_ORIG_WAIT_SEC_CHECK 2 +#define RFC_STATE_TERM_WAIT_SEC_CHECK 3 +#define RFC_STATE_OPENED 4 +#define RFC_STATE_DISC_WAIT_UA 5 /* * Events that can be received by multiplexer as well as port state machines */ -#define RFC_EVENT_SABME 0 -#define RFC_EVENT_UA 1 -#define RFC_EVENT_DM 2 -#define RFC_EVENT_DISC 3 -#define RFC_EVENT_UIH 4 -#define RFC_EVENT_TIMEOUT 5 -#define RFC_EVENT_BAD_FRAME 50 +#define RFC_EVENT_SABME 0 +#define RFC_EVENT_UA 1 +#define RFC_EVENT_DM 2 +#define RFC_EVENT_DISC 3 +#define RFC_EVENT_UIH 4 +#define RFC_EVENT_TIMEOUT 5 +#define RFC_EVENT_BAD_FRAME 50 /* * Multiplexer events */ -#define RFC_MX_EVENT_START_REQ 6 -#define RFC_MX_EVENT_START_RSP 7 -#define RFC_MX_EVENT_CLOSE_REQ 8 -#define RFC_MX_EVENT_CONN_CNF 9 -#define RFC_MX_EVENT_CONN_IND 10 -#define RFC_MX_EVENT_CONF_CNF 11 -#define RFC_MX_EVENT_CONF_IND 12 -#define RFC_MX_EVENT_QOS_VIOLATION_IND 13 -#define RFC_MX_EVENT_DISC_IND 14 -#define RFC_MX_EVENT_TEST_CMD 15 -#define RFC_MX_EVENT_TEST_RSP 16 -#define RFC_MX_EVENT_FCON_CMD 17 -#define RFC_MX_EVENT_FCOFF_CMD 18 -#define RFC_MX_EVENT_NSC 19 -#define RFC_MX_EVENT_NSC_RSP 20 +#define RFC_MX_EVENT_START_REQ 6 +#define RFC_MX_EVENT_START_RSP 7 +#define RFC_MX_EVENT_CLOSE_REQ 8 +#define RFC_MX_EVENT_CONN_CNF 9 +#define RFC_MX_EVENT_CONN_IND 10 +#define RFC_MX_EVENT_CONF_CNF 11 +#define RFC_MX_EVENT_CONF_IND 12 +#define RFC_MX_EVENT_QOS_VIOLATION_IND 13 +#define RFC_MX_EVENT_DISC_IND 14 +#define RFC_MX_EVENT_TEST_CMD 15 +#define RFC_MX_EVENT_TEST_RSP 16 +#define RFC_MX_EVENT_FCON_CMD 17 +#define RFC_MX_EVENT_FCOFF_CMD 18 +#define RFC_MX_EVENT_NSC 19 +#define RFC_MX_EVENT_NSC_RSP 20 /* * Port events */ -#define RFC_EVENT_OPEN 9 -#define RFC_EVENT_ESTABLISH_RSP 11 -#define RFC_EVENT_CLOSE 12 -#define RFC_EVENT_CLEAR 13 -#define RFC_EVENT_DATA 14 -#define RFC_EVENT_SEC_COMPLETE 15 +#define RFC_EVENT_OPEN 9 +#define RFC_EVENT_ESTABLISH_RSP 11 +#define RFC_EVENT_CLOSE 12 +#define RFC_EVENT_CLEAR 13 +#define RFC_EVENT_DATA 14 +#define RFC_EVENT_SEC_COMPLETE 15 /* seconds to wait for reply with Poll bit */ -#define RFC_T1_TIMEOUT 20 +#define RFC_T1_TIMEOUT 20 /* seconds to wait for reply with Poll bit other than MX */ -#define RFC_PORT_T1_TIMEOUT 60 +#define RFC_PORT_T1_TIMEOUT 60 /* timeout to wait for Mx UIH */ -#define RFC_T2_TIMEOUT 20 +#define RFC_T2_TIMEOUT 20 /* If something goes wrong and we send DISC we should not wait for min */ -#define RFC_DISC_TIMEOUT 3 -#define RFC_CLOSE_TIMEOUT 10 +#define RFC_DISC_TIMEOUT 3 +#define RFC_CLOSE_TIMEOUT 10 /* first connection to be established on Mx */ -#define RFCOMM_CONN_TIMEOUT 120 - +#define RFCOMM_CONN_TIMEOUT 120 /* Define RFComm control block */ -typedef struct -{ - MX_FRAME rx_frame; - tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ - - /* MCB based on the L2CAP's lcid */ - tRFC_MCB *p_rfc_lcid_mcb[MAX_L2CAP_CHANNELS]; - bool peer_rx_disabled; /* If true peer sent FCOFF */ - uint8_t last_mux; /* Last mux allocated */ - uint8_t last_port; /* Last port allocated */ +typedef struct { + MX_FRAME rx_frame; + tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ + + /* MCB based on the L2CAP's lcid */ + tRFC_MCB* p_rfc_lcid_mcb[MAX_L2CAP_CHANNELS]; + bool peer_rx_disabled; /* If true peer sent FCOFF */ + uint8_t last_mux; /* Last mux allocated */ + uint8_t last_port; /* Last port allocated */ } tRFCOMM_CB; /* Main Control Block for the RFCOMM Layer (PORT and RFC) */ -typedef struct -{ - tRFCOMM_CB rfc; - tPORT_CB port; - uint8_t trace_level; +typedef struct { + tRFCOMM_CB rfc; + tPORT_CB port; + uint8_t trace_level; } tRFC_CB; - extern tRFC_CB rfc_cb; /* Timer running on the multiplexor channel while no DLCI connection is open */ -#define RFC_MCB_INIT_INACT_TIMER 60 /* in seconds */ +#define RFC_MCB_INIT_INACT_TIMER 60 /* in seconds */ /* Timer running on the multiplexor channel after last DLCI is released */ -#define RFC_MCB_RELEASE_INACT_TIMER 2 /* in seconds */ +#define RFC_MCB_RELEASE_INACT_TIMER 2 /* in seconds */ /* * Define RFCOMM frame processing errors */ -#define RFCOMM_ERR_BAD_SABME 1 -#define RFCOMM_ERR_BAD_UA 2 -#define RFCOMM_ERR_BAD_DM 3 -#define RFCOMM_ERR_BAD_DISC 4 -#define RFCOMM_ERR_BAD_UIH 5 +#define RFCOMM_ERR_BAD_SABME 1 +#define RFCOMM_ERR_BAD_UA 2 +#define RFCOMM_ERR_BAD_DM 3 +#define RFCOMM_ERR_BAD_DISC 4 +#define RFCOMM_ERR_BAD_UIH 5 #ifdef RFCOMM_PRECALC_FCS #define RFCOMM_SABME_FCS(p_data, cr, dlci) rfc_sabme_fcs[cr][dlci] -#define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_ua_fcs[cr][dlci] -#define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_dm_fcs[cr][dlci] -#define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_disc_fcs[cr][dlci] -#define RFCOMM_UIH_FCS(p_data, dlci) rfc_uih_fcs[dlci] +#define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_ua_fcs[cr][dlci] +#define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_dm_fcs[cr][dlci] +#define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_disc_fcs[cr][dlci] +#define RFCOMM_UIH_FCS(p_data, dlci) rfc_uih_fcs[dlci] #else -extern uint8_t rfc_calc_fcs (uint16_t len, uint8_t *p); +extern uint8_t rfc_calc_fcs(uint16_t len, uint8_t* p); #define RFCOMM_SABME_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) -#define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) -#define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) -#define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) -#define RFCOMM_UIH_FCS(p_data, dlci) rfc_calc_fcs(2, p_data) +#define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) +#define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) +#define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data) +#define RFCOMM_UIH_FCS(p_data, dlci) rfc_calc_fcs(2, p_data) #endif -extern void rfc_mx_sm_execute (tRFC_MCB *p_mcb, uint16_t event, void *p_data); +extern void rfc_mx_sm_execute(tRFC_MCB* p_mcb, uint16_t event, void* p_data); /* * Functions provided by the rfc_port_fsm.cc */ -extern void rfc_port_sm_execute (tPORT *p_port, uint16_t event, void *p_data); - - -extern void rfc_process_pn (tRFC_MCB *p_rfc_mcb, bool is_command, MX_FRAME *p_frame); -extern void rfc_process_msc (tRFC_MCB *p_rfc_mcb, bool is_command, MX_FRAME *p_frame); -extern void rfc_process_rpn (tRFC_MCB *p_rfc_mcb, bool is_command, bool is_request, MX_FRAME *p_frame); -extern void rfc_process_rls (tRFC_MCB *p_rfc_mcb, bool is_command, MX_FRAME *p_frame); -extern void rfc_process_nsc (tRFC_MCB *p_rfc_mcb, MX_FRAME *p_frame); -extern void rfc_process_test_rsp (tRFC_MCB *p_rfc_mcb, BT_HDR *p_buf); -extern void rfc_process_fcon (tRFC_MCB *p_rfc_mcb, bool is_command); -extern void rfc_process_fcoff (tRFC_MCB *p_rfc_mcb, bool is_command); -extern void rfc_process_l2cap_congestion (tRFC_MCB *p_mcb, bool is_congested); +extern void rfc_port_sm_execute(tPORT* p_port, uint16_t event, void* p_data); + +extern void rfc_process_pn(tRFC_MCB* p_rfc_mcb, bool is_command, + MX_FRAME* p_frame); +extern void rfc_process_msc(tRFC_MCB* p_rfc_mcb, bool is_command, + MX_FRAME* p_frame); +extern void rfc_process_rpn(tRFC_MCB* p_rfc_mcb, bool is_command, + bool is_request, MX_FRAME* p_frame); +extern void rfc_process_rls(tRFC_MCB* p_rfc_mcb, bool is_command, + MX_FRAME* p_frame); +extern void rfc_process_nsc(tRFC_MCB* p_rfc_mcb, MX_FRAME* p_frame); +extern void rfc_process_test_rsp(tRFC_MCB* p_rfc_mcb, BT_HDR* p_buf); +extern void rfc_process_fcon(tRFC_MCB* p_rfc_mcb, bool is_command); +extern void rfc_process_fcoff(tRFC_MCB* p_rfc_mcb, bool is_command); +extern void rfc_process_l2cap_congestion(tRFC_MCB* p_mcb, bool is_congested); /* * Functions provided by the rfc_utils.cc */ -tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, bool is_initiator); -extern void rfc_release_multiplexer_channel (tRFC_MCB *p_rfc_mcb); -extern void rfc_timer_start (tRFC_MCB *p_rfc_mcb, uint16_t timeout); -extern void rfc_timer_stop (tRFC_MCB *p_rfc_mcb); -extern void rfc_port_timer_start (tPORT *p_port, uint16_t tout); -extern void rfc_port_timer_stop (tPORT *p_port); - -bool rfc_check_uih_fcs (uint8_t dlci, uint8_t received_fcs); -bool rfc_check_fcs (uint16_t len, uint8_t *p, uint8_t received_fcs); -tRFC_MCB *rfc_find_lcid_mcb (uint16_t lcid); -extern void rfc_save_lcid_mcb (tRFC_MCB *p_rfc_mcb, uint16_t lcid); -extern void rfc_check_mcb_active (tRFC_MCB *p_mcb); -extern void rfc_port_closed (tPORT *p_port); -extern void rfc_sec_check_complete (BD_ADDR bd_addr, tBT_TRANSPORT transport,void *p_ref_data, uint8_t res); -extern void rfc_inc_credit (tPORT *p_port, uint8_t credit); -extern void rfc_dec_credit (tPORT *p_port); -extern void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf); +tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator); +extern void rfc_release_multiplexer_channel(tRFC_MCB* p_rfc_mcb); +extern void rfc_timer_start(tRFC_MCB* p_rfc_mcb, uint16_t timeout); +extern void rfc_timer_stop(tRFC_MCB* p_rfc_mcb); +extern void rfc_port_timer_start(tPORT* p_port, uint16_t tout); +extern void rfc_port_timer_stop(tPORT* p_port); + +bool rfc_check_uih_fcs(uint8_t dlci, uint8_t received_fcs); +bool rfc_check_fcs(uint16_t len, uint8_t* p, uint8_t received_fcs); +tRFC_MCB* rfc_find_lcid_mcb(uint16_t lcid); +extern void rfc_save_lcid_mcb(tRFC_MCB* p_rfc_mcb, uint16_t lcid); +extern void rfc_check_mcb_active(tRFC_MCB* p_mcb); +extern void rfc_port_closed(tPORT* p_port); +extern void rfc_sec_check_complete(BD_ADDR bd_addr, tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res); +extern void rfc_inc_credit(tPORT* p_port, uint8_t credit); +extern void rfc_dec_credit(tPORT* p_port); +extern void rfc_check_send_cmd(tRFC_MCB* p_mcb, BT_HDR* p_buf); /* * Functions provided by the rfc_ts_frames.cc */ -extern void rfc_send_sabme (tRFC_MCB *p_rfc_mcb, uint8_t dlci); -extern void rfc_send_ua (tRFC_MCB *p_rfc_mcb, uint8_t dlci); -extern void rfc_send_dm (tRFC_MCB *p_rfc_mcb, uint8_t dlci, bool pf); -extern void rfc_send_disc (tRFC_MCB *p_rfc_mcb, uint8_t dlci); -extern void rfc_send_pn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint16_t mtu, - uint8_t cl, uint8_t k); -extern void rfc_send_test (tRFC_MCB *p_rfc_mcb, bool is_command, BT_HDR *p_buf); -extern void rfc_send_msc (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, - tPORT_CTRL *p_pars); -extern void rfc_send_rls (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint8_t status); -extern void rfc_send_rpn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, - tPORT_STATE *p_pars, uint16_t mask); -extern void rfc_send_fcon (tRFC_MCB *p_mcb, bool is_command); -extern void rfc_send_fcoff (tRFC_MCB *p_mcb, bool is_command); -extern void rfc_send_buf_uih (tRFC_MCB *p_rfc_mcb, uint8_t dlci, BT_HDR *p_buf); -extern void rfc_send_credit(tRFC_MCB *p_mcb, uint8_t dlci, uint8_t credit); -extern void rfc_process_mx_message (tRFC_MCB *p_rfc_mcb, BT_HDR *p_buf); -extern uint8_t rfc_parse_data (tRFC_MCB *p_rfc_mcb, MX_FRAME *p_frame, BT_HDR *p_buf); +extern void rfc_send_sabme(tRFC_MCB* p_rfc_mcb, uint8_t dlci); +extern void rfc_send_ua(tRFC_MCB* p_rfc_mcb, uint8_t dlci); +extern void rfc_send_dm(tRFC_MCB* p_rfc_mcb, uint8_t dlci, bool pf); +extern void rfc_send_disc(tRFC_MCB* p_rfc_mcb, uint8_t dlci); +extern void rfc_send_pn(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + uint16_t mtu, uint8_t cl, uint8_t k); +extern void rfc_send_test(tRFC_MCB* p_rfc_mcb, bool is_command, BT_HDR* p_buf); +extern void rfc_send_msc(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + tPORT_CTRL* p_pars); +extern void rfc_send_rls(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + uint8_t status); +extern void rfc_send_rpn(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + tPORT_STATE* p_pars, uint16_t mask); +extern void rfc_send_fcon(tRFC_MCB* p_mcb, bool is_command); +extern void rfc_send_fcoff(tRFC_MCB* p_mcb, bool is_command); +extern void rfc_send_buf_uih(tRFC_MCB* p_rfc_mcb, uint8_t dlci, BT_HDR* p_buf); +extern void rfc_send_credit(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t credit); +extern void rfc_process_mx_message(tRFC_MCB* p_rfc_mcb, BT_HDR* p_buf); +extern uint8_t rfc_parse_data(tRFC_MCB* p_rfc_mcb, MX_FRAME* p_frame, + BT_HDR* p_buf); /* Call back functions from RFCOMM */ -extern void rfcomm_l2cap_if_init (void); +extern void rfcomm_l2cap_if_init(void); -extern void PORT_StartInd (tRFC_MCB *p_mcb); -extern void PORT_StartCnf (tRFC_MCB *p_mcb, uint16_t result); +extern void PORT_StartInd(tRFC_MCB* p_mcb); +extern void PORT_StartCnf(tRFC_MCB* p_mcb, uint16_t result); -extern void PORT_CloseInd (tRFC_MCB *p_mcb); -extern void Port_TimeOutCloseMux (tRFC_MCB *p_mcb); +extern void PORT_CloseInd(tRFC_MCB* p_mcb); +extern void Port_TimeOutCloseMux(tRFC_MCB* p_mcb); -extern void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu); -extern void PORT_DlcEstablishCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint16_t result); +extern void PORT_DlcEstablishInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu); +extern void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint16_t result); -extern void PORT_DataInd (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf); +extern void PORT_DataInd(tRFC_MCB* p_mcb, uint8_t dlci, BT_HDR* p_buf); -extern void PORT_DlcReleaseInd (tRFC_MCB *p_mcb, uint8_t dlci); +extern void PORT_DlcReleaseInd(tRFC_MCB* p_mcb, uint8_t dlci); -extern void PORT_ParNegInd (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k); -extern void PORT_ParNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k); +extern void PORT_ParNegInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint8_t cl, uint8_t k); +extern void PORT_ParNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, + uint8_t cl, uint8_t k); -extern void PORT_TestCnf (tRFC_MCB *p_mcb, uint8_t *p_data, uint16_t len); +extern void PORT_TestCnf(tRFC_MCB* p_mcb, uint8_t* p_data, uint16_t len); -extern void PORT_FlowInd (tRFC_MCB *p_mcb, uint8_t dlci, bool fc); +extern void PORT_FlowInd(tRFC_MCB* p_mcb, uint8_t dlci, bool fc); -extern void PORT_PortNegInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, uint16_t param_mask); -extern void PORT_PortNegCnf (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, uint16_t result); +extern void PORT_PortNegInd(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_STATE* p_pars, + uint16_t param_mask); +extern void PORT_PortNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_STATE* p_pars, + uint16_t result); -extern void PORT_ControlInd (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars); -extern void PORT_ControlCnf (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars); +extern void PORT_ControlInd(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* p_pars); +extern void PORT_ControlCnf(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* p_pars); -extern void PORT_LineStatusInd (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t line_status); +extern void PORT_LineStatusInd(tRFC_MCB* p_mcb, uint8_t dlci, + uint8_t line_status); #ifdef __cplusplus } diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index 614cc96ad..85be99bdf 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -25,31 +25,30 @@ #include #include "bt_target.h" +#include "bt_common.h" #include "osi/include/osi.h" #include "osi/include/time.h" -#include "bt_common.h" -#include "rfcdefs.h" -#include "port_api.h" -#include "port_int.h" +#include "bt_utils.h" #include "l2c_api.h" #include "l2cdefs.h" +#include "port_api.h" +#include "port_int.h" #include "rfc_int.h" -#include "bt_utils.h" - +#include "rfcdefs.h" /* * Define Callback functions to be called by L2CAP */ -static void RFCOMM_ConnectInd (BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); -static void RFCOMM_ConnectCnf (uint16_t lcid, uint16_t err); -static void RFCOMM_ConfigInd (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -static void RFCOMM_ConfigCnf (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg); -static void RFCOMM_DisconnectInd (uint16_t lcid, bool is_clear); -static void RFCOMM_QoSViolationInd (UNUSED_ATTR BD_ADDR bd_addr); -static void RFCOMM_BufDataInd (uint16_t lcid, BT_HDR *p_buf); -static void RFCOMM_CongestionStatusInd (uint16_t lcid, bool is_congested); - +static void RFCOMM_ConnectInd(BD_ADDR bd_addr, uint16_t lcid, uint16_t psm, + uint8_t id); +static void RFCOMM_ConnectCnf(uint16_t lcid, uint16_t err); +static void RFCOMM_ConfigInd(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +static void RFCOMM_ConfigCnf(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +static void RFCOMM_DisconnectInd(uint16_t lcid, bool is_clear); +static void RFCOMM_QoSViolationInd(UNUSED_ATTR BD_ADDR bd_addr); +static void RFCOMM_BufDataInd(uint16_t lcid, BT_HDR* p_buf); +static void RFCOMM_CongestionStatusInd(uint16_t lcid, bool is_congested); /******************************************************************************* * @@ -59,27 +58,24 @@ static void RFCOMM_CongestionStatusInd (uint16_t lcid, bool is_congested); * to register interface functions with L2CAP. * ******************************************************************************/ -void rfcomm_l2cap_if_init (void) -{ - tL2CAP_APPL_INFO *p_l2c = &rfc_cb.rfc.reg_info; - - p_l2c->pL2CA_ConnectInd_Cb = RFCOMM_ConnectInd; - p_l2c->pL2CA_ConnectCfm_Cb = RFCOMM_ConnectCnf; - p_l2c->pL2CA_ConnectPnd_Cb = NULL; - p_l2c->pL2CA_ConfigInd_Cb = RFCOMM_ConfigInd; - p_l2c->pL2CA_ConfigCfm_Cb = RFCOMM_ConfigCnf; - p_l2c->pL2CA_DisconnectInd_Cb = RFCOMM_DisconnectInd; - p_l2c->pL2CA_DisconnectCfm_Cb = NULL; - p_l2c->pL2CA_QoSViolationInd_Cb = RFCOMM_QoSViolationInd; - p_l2c->pL2CA_DataInd_Cb = RFCOMM_BufDataInd; - p_l2c->pL2CA_CongestionStatus_Cb = RFCOMM_CongestionStatusInd; - p_l2c->pL2CA_TxComplete_Cb = NULL; - - - L2CA_Register (BT_PSM_RFCOMM, p_l2c); +void rfcomm_l2cap_if_init(void) { + tL2CAP_APPL_INFO* p_l2c = &rfc_cb.rfc.reg_info; + + p_l2c->pL2CA_ConnectInd_Cb = RFCOMM_ConnectInd; + p_l2c->pL2CA_ConnectCfm_Cb = RFCOMM_ConnectCnf; + p_l2c->pL2CA_ConnectPnd_Cb = NULL; + p_l2c->pL2CA_ConfigInd_Cb = RFCOMM_ConfigInd; + p_l2c->pL2CA_ConfigCfm_Cb = RFCOMM_ConfigCnf; + p_l2c->pL2CA_DisconnectInd_Cb = RFCOMM_DisconnectInd; + p_l2c->pL2CA_DisconnectCfm_Cb = NULL; + p_l2c->pL2CA_QoSViolationInd_Cb = RFCOMM_QoSViolationInd; + p_l2c->pL2CA_DataInd_Cb = RFCOMM_BufDataInd; + p_l2c->pL2CA_CongestionStatus_Cb = RFCOMM_CongestionStatusInd; + p_l2c->pL2CA_TxComplete_Cb = NULL; + + L2CA_Register(BT_PSM_RFCOMM, p_l2c); } - /******************************************************************************* * * Function RFCOMM_ConnectInd @@ -89,52 +85,47 @@ void rfcomm_l2cap_if_init (void) * block and dispatch the event to it. * ******************************************************************************/ -void RFCOMM_ConnectInd (BD_ADDR bd_addr, uint16_t lcid, - UNUSED_ATTR uint16_t psm, uint8_t id) -{ - tRFC_MCB *p_mcb = rfc_alloc_multiplexer_channel(bd_addr, false); - - if ((p_mcb)&&(p_mcb->state != RFC_MX_STATE_IDLE)) - { - /* if this is collision case */ - if ((p_mcb->is_initiator)&&(p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF)) - { - p_mcb->pending_lcid = lcid; - p_mcb->pending_id = id; - - /* wait random timeout (2 - 12) to resolve collision */ - /* if peer gives up then local device rejects incoming connection and continues as initiator */ - /* if timeout, local device disconnects outgoing connection and continues as acceptor */ - RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)", - p_mcb->lcid, p_mcb->pending_lcid); - - rfc_timer_start(p_mcb, (uint16_t)(time_get_os_boottime_ms() % 10 + 2)); - return; - } - else - { - /* we cannot accept connection request from peer at this state */ - /* don't update lcid */ - p_mcb = NULL; - } +void RFCOMM_ConnectInd(BD_ADDR bd_addr, uint16_t lcid, UNUSED_ATTR uint16_t psm, + uint8_t id) { + tRFC_MCB* p_mcb = rfc_alloc_multiplexer_channel(bd_addr, false); + + if ((p_mcb) && (p_mcb->state != RFC_MX_STATE_IDLE)) { + /* if this is collision case */ + if ((p_mcb->is_initiator) && (p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF)) { + p_mcb->pending_lcid = lcid; + p_mcb->pending_id = id; + + /* wait random timeout (2 - 12) to resolve collision */ + /* if peer gives up then local device rejects incoming connection and + * continues as initiator */ + /* if timeout, local device disconnects outgoing connection and continues + * as acceptor */ + RFCOMM_TRACE_DEBUG( + "RFCOMM_ConnectInd start timer for collision, initiator's " + "LCID(0x%x), acceptor's LCID(0x%x)", + p_mcb->lcid, p_mcb->pending_lcid); + + rfc_timer_start(p_mcb, (uint16_t)(time_get_os_boottime_ms() % 10 + 2)); + return; + } else { + /* we cannot accept connection request from peer at this state */ + /* don't update lcid */ + p_mcb = NULL; } - else - { - /* store mcb even if null */ - rfc_save_lcid_mcb (p_mcb, lcid); - } - - if (p_mcb == NULL) - { - L2CA_ConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0); - return; - } - p_mcb->lcid = lcid; - - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &id); + } else { + /* store mcb even if null */ + rfc_save_lcid_mcb(p_mcb, lcid); + } + + if (p_mcb == NULL) { + L2CA_ConnectRsp(bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0); + return; + } + p_mcb->lcid = lcid; + + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONN_IND, &id); } - /******************************************************************************* * * Function RFCOMM_ConnectCnf @@ -144,70 +135,68 @@ void RFCOMM_ConnectInd (BD_ADDR bd_addr, uint16_t lcid, * event to the FSM. * ******************************************************************************/ -void RFCOMM_ConnectCnf (uint16_t lcid, uint16_t result) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); - - if (!p_mcb) - { - RFCOMM_TRACE_ERROR ("RFCOMM_ConnectCnf LCID:0x%x", lcid); - return; - } - - if (p_mcb->pending_lcid) - { - /* if peer rejects our connect request but peer's connect request is pending */ - if (result != L2CAP_CONN_OK ) - { - uint16_t i; - uint8_t idx; - - RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectCnf retry as acceptor on pending LCID(0x%x)", p_mcb->pending_lcid); - - /* remove mcb from mapping table */ - rfc_save_lcid_mcb (NULL, p_mcb->lcid); - - p_mcb->lcid = p_mcb->pending_lcid; - p_mcb->is_initiator = false; - p_mcb->state = RFC_MX_STATE_IDLE; - - /* store mcb into mapping table */ - rfc_save_lcid_mcb (p_mcb, p_mcb->lcid); - - /* update direction bit */ - for (i = 0; i < RFCOMM_MAX_DLCI; i += 2) - { - idx = p_mcb->port_inx[i]; - if (idx != 0) - { - p_mcb->port_inx[i] = 0; - p_mcb->port_inx[i+1] = idx; - rfc_cb.port.port[idx - 1].dlci += 1; - RFCOMM_TRACE_DEBUG ("RFCOMM MX - DLCI:%d -> %d", i, rfc_cb.port.port[idx - 1].dlci); - } - } - - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id)); - return; +void RFCOMM_ConnectCnf(uint16_t lcid, uint16_t result) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); + + if (!p_mcb) { + RFCOMM_TRACE_ERROR("RFCOMM_ConnectCnf LCID:0x%x", lcid); + return; + } + + if (p_mcb->pending_lcid) { + /* if peer rejects our connect request but peer's connect request is pending + */ + if (result != L2CAP_CONN_OK) { + uint16_t i; + uint8_t idx; + + RFCOMM_TRACE_DEBUG( + "RFCOMM_ConnectCnf retry as acceptor on pending LCID(0x%x)", + p_mcb->pending_lcid); + + /* remove mcb from mapping table */ + rfc_save_lcid_mcb(NULL, p_mcb->lcid); + + p_mcb->lcid = p_mcb->pending_lcid; + p_mcb->is_initiator = false; + p_mcb->state = RFC_MX_STATE_IDLE; + + /* store mcb into mapping table */ + rfc_save_lcid_mcb(p_mcb, p_mcb->lcid); + + /* update direction bit */ + for (i = 0; i < RFCOMM_MAX_DLCI; i += 2) { + idx = p_mcb->port_inx[i]; + if (idx != 0) { + p_mcb->port_inx[i] = 0; + p_mcb->port_inx[i + 1] = idx; + rfc_cb.port.port[idx - 1].dlci += 1; + RFCOMM_TRACE_DEBUG("RFCOMM MX - DLCI:%d -> %d", i, + rfc_cb.port.port[idx - 1].dlci); } - else - { - RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectCnf peer gave up pending LCID(0x%x)", p_mcb->pending_lcid); + } - /* Peer gave up his connection request, make sure cleaning up L2CAP channel */ - L2CA_ConnectRsp (p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, L2CAP_CONN_NO_RESOURCES, 0); + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id)); + return; + } else { + RFCOMM_TRACE_DEBUG("RFCOMM_ConnectCnf peer gave up pending LCID(0x%x)", + p_mcb->pending_lcid); - p_mcb->pending_lcid = 0; - } + /* Peer gave up his connection request, make sure cleaning up L2CAP + * channel */ + L2CA_ConnectRsp(p_mcb->bd_addr, p_mcb->pending_id, p_mcb->pending_lcid, + L2CAP_CONN_NO_RESOURCES, 0); + + p_mcb->pending_lcid = 0; } + } - /* Save LCID to be used in all consecutive calls to L2CAP */ - p_mcb->lcid = lcid; + /* Save LCID to be used in all consecutive calls to L2CAP */ + p_mcb->lcid = lcid; - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_CNF, &result); + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONN_CNF, &result); } - /******************************************************************************* * * Function RFCOMM_ConfigInd @@ -217,19 +206,16 @@ void RFCOMM_ConnectCnf (uint16_t lcid, uint16_t result) * block and dispatch event to the FSM. * ******************************************************************************/ -void RFCOMM_ConfigInd (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); - - if (!p_mcb) - { - RFCOMM_TRACE_ERROR ("RFCOMM_ConfigInd LCID:0x%x", lcid); - return; - } +void RFCOMM_ConfigInd(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONF_IND, (void *)p_cfg); -} + if (!p_mcb) { + RFCOMM_TRACE_ERROR("RFCOMM_ConfigInd LCID:0x%x", lcid); + return; + } + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_IND, (void*)p_cfg); +} /******************************************************************************* * @@ -240,19 +226,16 @@ void RFCOMM_ConfigInd (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * event to the FSM. * ******************************************************************************/ -void RFCOMM_ConfigCnf (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); - - if (!p_mcb) - { - RFCOMM_TRACE_ERROR ("RFCOMM_ConfigCnf no MCB LCID:0x%x", lcid); - return; - } +void RFCOMM_ConfigCnf(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONF_CNF, (void *)p_cfg); -} + if (!p_mcb) { + RFCOMM_TRACE_ERROR("RFCOMM_ConfigCnf no MCB LCID:0x%x", lcid); + return; + } + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_CNF, (void*)p_cfg); +} /******************************************************************************* * @@ -263,10 +246,7 @@ void RFCOMM_ConfigCnf (uint16_t lcid, tL2CAP_CFG_INFO *p_cfg) * FSM. * ******************************************************************************/ -void RFCOMM_QoSViolationInd (UNUSED_ATTR BD_ADDR bd_addr) -{ -} - +void RFCOMM_QoSViolationInd(UNUSED_ATTR BD_ADDR bd_addr) {} /******************************************************************************* * @@ -276,25 +256,21 @@ void RFCOMM_QoSViolationInd (UNUSED_ATTR BD_ADDR bd_addr) * L2CA_DisconnectInd received. Dispatch event to the FSM. * ******************************************************************************/ -void RFCOMM_DisconnectInd (uint16_t lcid, bool is_conf_needed) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); +void RFCOMM_DisconnectInd(uint16_t lcid, bool is_conf_needed) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); - if (is_conf_needed) - { - L2CA_DisconnectRsp (lcid); - } + if (is_conf_needed) { + L2CA_DisconnectRsp(lcid); + } - if (!p_mcb) - { - RFCOMM_TRACE_WARNING ("RFCOMM_DisconnectInd LCID:0x%x", lcid); - return; - } + if (!p_mcb) { + RFCOMM_TRACE_WARNING("RFCOMM_DisconnectInd LCID:0x%x", lcid); + return; + } - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_DISC_IND, NULL); + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_DISC_IND, NULL); } - /******************************************************************************* * * Function RFCOMM_BufDataInd @@ -305,84 +281,75 @@ void RFCOMM_DisconnectInd (uint16_t lcid, bool is_conf_needed) * state machine depending on the frame destination. * ******************************************************************************/ -void RFCOMM_BufDataInd (uint16_t lcid, BT_HDR *p_buf) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); - tPORT *p_port; - uint8_t event; - - - if (!p_mcb) - { - RFCOMM_TRACE_WARNING ("RFCOMM_BufDataInd LCID:0x%x", lcid); - osi_free(p_buf); - return; - } +void RFCOMM_BufDataInd(uint16_t lcid, BT_HDR* p_buf) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); + tPORT* p_port; + uint8_t event; - event = rfc_parse_data (p_mcb, &rfc_cb.rfc.rx_frame, p_buf); - - /* If the frame did not pass validation just ignore it */ - if (event == RFC_EVENT_BAD_FRAME) - { - osi_free(p_buf); - return; - } + if (!p_mcb) { + RFCOMM_TRACE_WARNING("RFCOMM_BufDataInd LCID:0x%x", lcid); + osi_free(p_buf); + return; + } - if (rfc_cb.rfc.rx_frame.dlci == RFCOMM_MX_DLCI) - { - /* Take special care of the Multiplexer Control Messages */ - if (event == RFC_EVENT_UIH) - { - rfc_process_mx_message (p_mcb, p_buf); - return; - } + event = rfc_parse_data(p_mcb, &rfc_cb.rfc.rx_frame, p_buf); - /* Other multiplexer events go to state machine */ - rfc_mx_sm_execute (p_mcb, event, NULL); - osi_free(p_buf); - return; + /* If the frame did not pass validation just ignore it */ + if (event == RFC_EVENT_BAD_FRAME) { + osi_free(p_buf); + return; + } + + if (rfc_cb.rfc.rx_frame.dlci == RFCOMM_MX_DLCI) { + /* Take special care of the Multiplexer Control Messages */ + if (event == RFC_EVENT_UIH) { + rfc_process_mx_message(p_mcb, p_buf); + return; } - /* The frame was received on the data channel DLCI, verify that DLC exists */ - if (((p_port = port_find_mcb_dlci_port (p_mcb, rfc_cb.rfc.rx_frame.dlci)) == NULL) - || (!p_port->rfc.p_mcb)) - { - /* If this is a SABME on the new port, check if any appl is waiting for it */ - if (event != RFC_EVENT_SABME) - { - if (( p_mcb->is_initiator && !rfc_cb.rfc.rx_frame.cr) - || (!p_mcb->is_initiator && rfc_cb.rfc.rx_frame.cr)) - rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, rfc_cb.rfc.rx_frame.pf); - osi_free(p_buf); - return; - } - - p_port = port_find_dlci_port(rfc_cb.rfc.rx_frame.dlci); - if (p_port == NULL) - { - rfc_send_dm (p_mcb, rfc_cb.rfc.rx_frame.dlci, true); - osi_free(p_buf); - return; - } - p_mcb->port_inx[rfc_cb.rfc.rx_frame.dlci] = p_port->inx; - p_port->rfc.p_mcb = p_mcb; + /* Other multiplexer events go to state machine */ + rfc_mx_sm_execute(p_mcb, event, NULL); + osi_free(p_buf); + return; + } + + /* The frame was received on the data channel DLCI, verify that DLC exists */ + if (((p_port = port_find_mcb_dlci_port(p_mcb, rfc_cb.rfc.rx_frame.dlci)) == + NULL) || + (!p_port->rfc.p_mcb)) { + /* If this is a SABME on the new port, check if any appl is waiting for it + */ + if (event != RFC_EVENT_SABME) { + if ((p_mcb->is_initiator && !rfc_cb.rfc.rx_frame.cr) || + (!p_mcb->is_initiator && rfc_cb.rfc.rx_frame.cr)) + rfc_send_dm(p_mcb, rfc_cb.rfc.rx_frame.dlci, rfc_cb.rfc.rx_frame.pf); + osi_free(p_buf); + return; } - if (event == RFC_EVENT_UIH) - { + p_port = port_find_dlci_port(rfc_cb.rfc.rx_frame.dlci); + if (p_port == NULL) { + rfc_send_dm(p_mcb, rfc_cb.rfc.rx_frame.dlci, true); + osi_free(p_buf); + return; + } + p_mcb->port_inx[rfc_cb.rfc.rx_frame.dlci] = p_port->inx; + p_port->rfc.p_mcb = p_mcb; + } - if (p_buf->len > 0) - rfc_port_sm_execute (p_port, event, p_buf); - else - osi_free(p_buf); + if (event == RFC_EVENT_UIH) { + if (p_buf->len > 0) + rfc_port_sm_execute(p_port, event, p_buf); + else + osi_free(p_buf); - if (rfc_cb.rfc.rx_frame.credit != 0) - rfc_inc_credit (p_port, rfc_cb.rfc.rx_frame.credit); + if (rfc_cb.rfc.rx_frame.credit != 0) + rfc_inc_credit(p_port, rfc_cb.rfc.rx_frame.credit); - return; - } - rfc_port_sm_execute (p_port, event, NULL); - osi_free(p_buf); + return; + } + rfc_port_sm_execute(p_port, event, NULL); + osi_free(p_buf); } /******************************************************************************* @@ -393,20 +360,16 @@ void RFCOMM_BufDataInd (uint16_t lcid, BT_HDR *p_buf) * data RFCOMM L2CAP congestion status changes * ******************************************************************************/ -void RFCOMM_CongestionStatusInd (uint16_t lcid, bool is_congested) -{ - tRFC_MCB *p_mcb = rfc_find_lcid_mcb (lcid); - - if (!p_mcb) - { - RFCOMM_TRACE_ERROR ("RFCOMM_CongestionStatusInd dropped LCID:0x%x", lcid); - return; - } - else - { - RFCOMM_TRACE_EVENT ("RFCOMM_CongestionStatusInd LCID:0x%x", lcid); - } - rfc_process_l2cap_congestion (p_mcb, is_congested); +void RFCOMM_CongestionStatusInd(uint16_t lcid, bool is_congested) { + tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); + + if (!p_mcb) { + RFCOMM_TRACE_ERROR("RFCOMM_CongestionStatusInd dropped LCID:0x%x", lcid); + return; + } else { + RFCOMM_TRACE_EVENT("RFCOMM_CongestionStatusInd LCID:0x%x", lcid); + } + rfc_process_l2cap_congestion(p_mcb, is_congested); } /******************************************************************************* @@ -416,31 +379,26 @@ void RFCOMM_CongestionStatusInd (uint16_t lcid, bool is_congested) * Description This function returns MCB block supporting local cid * ******************************************************************************/ -tRFC_MCB *rfc_find_lcid_mcb (uint16_t lcid) -{ - tRFC_MCB *p_mcb; - - if (lcid - L2CAP_BASE_APPL_CID >= MAX_L2CAP_CHANNELS) - { - RFCOMM_TRACE_ERROR ("rfc_find_lcid_mcb LCID:0x%x", lcid); +tRFC_MCB* rfc_find_lcid_mcb(uint16_t lcid) { + tRFC_MCB* p_mcb; + + if (lcid - L2CAP_BASE_APPL_CID >= MAX_L2CAP_CHANNELS) { + RFCOMM_TRACE_ERROR("rfc_find_lcid_mcb LCID:0x%x", lcid); + return (NULL); + } else { + p_mcb = rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID]; + if (p_mcb != NULL) { + if (p_mcb->lcid != lcid) { + RFCOMM_TRACE_WARNING( + "rfc_find_lcid_mcb LCID reused LCID:0x%x current:0x%x", lcid, + p_mcb->lcid); return (NULL); + } } - else - { - p_mcb = rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID]; - if (p_mcb != NULL) - { - if (p_mcb->lcid != lcid) - { - RFCOMM_TRACE_WARNING ("rfc_find_lcid_mcb LCID reused LCID:0x%x current:0x%x", lcid, p_mcb->lcid); - return (NULL); - } - } - } - return (p_mcb); + } + return (p_mcb); } - /******************************************************************************* * * Function rfc_save_lcid_mcb @@ -448,9 +406,7 @@ tRFC_MCB *rfc_find_lcid_mcb (uint16_t lcid) * Description This function returns MCB block supporting local cid * ******************************************************************************/ -void rfc_save_lcid_mcb(tRFC_MCB *p_mcb, uint16_t lcid) -{ - if (lcid < L2CAP_BASE_APPL_CID) - return; - rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID] = p_mcb; +void rfc_save_lcid_mcb(tRFC_MCB* p_mcb, uint16_t lcid) { + if (lcid < L2CAP_BASE_APPL_CID) return; + rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID] = p_mcb; } diff --git a/stack/rfcomm/rfc_mx_fsm.cc b/stack/rfcomm/rfc_mx_fsm.cc index 808b1272c..4f2785e94 100644 --- a/stack/rfcomm/rfc_mx_fsm.cc +++ b/stack/rfcomm/rfc_mx_fsm.cc @@ -25,36 +25,38 @@ #include #include "bt_common.h" #include "bt_types.h" -#include "rfcdefs.h" +#include "bt_utils.h" +#include "l2c_api.h" #include "l2cdefs.h" +#include "osi/include/osi.h" #include "port_api.h" #include "port_int.h" -#include "l2c_api.h" #include "rfc_int.h" -#include "bt_utils.h" -#include "osi/include/osi.h" - -#define L2CAP_SUCCESS 0 -#define L2CAP_ERROR 1 +#include "rfcdefs.h" +#define L2CAP_SUCCESS 0 +#define L2CAP_ERROR 1 /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, uint16_t event, void *p_data); -static void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, uint16_t event, void *p_data); -static void rfc_mx_sm_state_configure (tRFC_MCB *p_mcb, uint16_t event, void *p_data); -static void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, uint16_t event, void *p_data); -static void rfc_mx_sm_state_wait_sabme (tRFC_MCB *p_mcb, uint16_t event, void *p_data); -static void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, uint16_t event, - UNUSED_ATTR void *p_data); -static void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, uint16_t event, void *p_data); - -static void rfc_mx_send_config_req (tRFC_MCB *p_mcb); -static void rfc_mx_conf_ind (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg); -static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg); - - +static void rfc_mx_sm_state_idle(tRFC_MCB* p_mcb, uint16_t event, void* p_data); +static void rfc_mx_sm_state_wait_conn_cnf(tRFC_MCB* p_mcb, uint16_t event, + void* p_data); +static void rfc_mx_sm_state_configure(tRFC_MCB* p_mcb, uint16_t event, + void* p_data); +static void rfc_mx_sm_sabme_wait_ua(tRFC_MCB* p_mcb, uint16_t event, + void* p_data); +static void rfc_mx_sm_state_wait_sabme(tRFC_MCB* p_mcb, uint16_t event, + void* p_data); +static void rfc_mx_sm_state_connected(tRFC_MCB* p_mcb, uint16_t event, + UNUSED_ATTR void* p_data); +static void rfc_mx_sm_state_disc_wait_ua(tRFC_MCB* p_mcb, uint16_t event, + void* p_data); + +static void rfc_mx_send_config_req(tRFC_MCB* p_mcb); +static void rfc_mx_conf_ind(tRFC_MCB* p_mcb, tL2CAP_CFG_INFO* p_cfg); +static void rfc_mx_conf_cnf(tRFC_MCB* p_mcb, tL2CAP_CFG_INFO* p_cfg); /******************************************************************************* * @@ -66,42 +68,38 @@ static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg); * Returns void * ******************************************************************************/ -void rfc_mx_sm_execute (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - switch (p_mcb->state) - { +void rfc_mx_sm_execute(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { + switch (p_mcb->state) { case RFC_MX_STATE_IDLE: - rfc_mx_sm_state_idle (p_mcb, event, p_data); - break; + rfc_mx_sm_state_idle(p_mcb, event, p_data); + break; case RFC_MX_STATE_WAIT_CONN_CNF: - rfc_mx_sm_state_wait_conn_cnf (p_mcb, event, p_data); - break; + rfc_mx_sm_state_wait_conn_cnf(p_mcb, event, p_data); + break; case RFC_MX_STATE_CONFIGURE: - rfc_mx_sm_state_configure (p_mcb, event, p_data); - break; + rfc_mx_sm_state_configure(p_mcb, event, p_data); + break; case RFC_MX_STATE_SABME_WAIT_UA: - rfc_mx_sm_sabme_wait_ua (p_mcb, event, p_data); - break; + rfc_mx_sm_sabme_wait_ua(p_mcb, event, p_data); + break; case RFC_MX_STATE_WAIT_SABME: - rfc_mx_sm_state_wait_sabme (p_mcb, event, p_data); - break; + rfc_mx_sm_state_wait_sabme(p_mcb, event, p_data); + break; case RFC_MX_STATE_CONNECTED: - rfc_mx_sm_state_connected (p_mcb, event, p_data); - break; + rfc_mx_sm_state_connected(p_mcb, event, p_data); + break; case RFC_MX_STATE_DISC_WAIT_UA: - rfc_mx_sm_state_disc_wait_ua (p_mcb, event, p_data); - break; - - } + rfc_mx_sm_state_disc_wait_ua(p_mcb, event, p_data); + break; + } } - /******************************************************************************* * * Function rfc_mx_sm_state_idle @@ -113,67 +111,65 @@ void rfc_mx_sm_execute (tRFC_MCB *p_mcb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_idle - evt:%d", event); - switch (event) - { - case RFC_MX_EVENT_START_REQ: - { - /* Initialize L2CAP MTU */ - p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; - - uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); - if (lcid == 0) { - rfc_save_lcid_mcb(NULL, p_mcb->lcid); - p_mcb->lcid = 0; - PORT_StartCnf(p_mcb, RFCOMM_ERROR); - return; - } - p_mcb->lcid = lcid; - /* Save entry for quicker access to mcb based on the LCID */ - rfc_save_lcid_mcb (p_mcb, p_mcb->lcid); - - p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF; - return; +void rfc_mx_sm_state_idle(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_idle - evt:%d", event); + switch (event) { + case RFC_MX_EVENT_START_REQ: { + /* Initialize L2CAP MTU */ + p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; + + uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); + if (lcid == 0) { + rfc_save_lcid_mcb(NULL, p_mcb->lcid); + p_mcb->lcid = 0; + PORT_StartCnf(p_mcb, RFCOMM_ERROR); + return; + } + p_mcb->lcid = lcid; + /* Save entry for quicker access to mcb based on the LCID */ + rfc_save_lcid_mcb(p_mcb, p_mcb->lcid); + + p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF; + return; } case RFC_MX_EVENT_START_RSP: case RFC_MX_EVENT_CONN_CNF: case RFC_MX_EVENT_CONF_IND: case RFC_MX_EVENT_CONF_CNF: - RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event); - return; + RFCOMM_TRACE_ERROR("Mx error state %d event %d", p_mcb->state, event); + return; case RFC_MX_EVENT_CONN_IND: - rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); - L2CA_ConnectRsp (p_mcb->bd_addr, *((uint8_t *)p_data), p_mcb->lcid, L2CAP_CONN_OK, 0); + rfc_timer_start(p_mcb, RFCOMM_CONN_TIMEOUT); + L2CA_ConnectRsp(p_mcb->bd_addr, *((uint8_t*)p_data), p_mcb->lcid, + L2CAP_CONN_OK, 0); - rfc_mx_send_config_req (p_mcb); + rfc_mx_send_config_req(p_mcb); - p_mcb->state = RFC_MX_STATE_CONFIGURE; - return; + p_mcb->state = RFC_MX_STATE_CONFIGURE; + return; case RFC_EVENT_SABME: - break; + break; case RFC_EVENT_UA: case RFC_EVENT_DM: - return; + return; case RFC_EVENT_DISC: - rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, true); - return; + rfc_send_dm(p_mcb, RFCOMM_MX_DLCI, true); + return; case RFC_EVENT_UIH: - rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, false); - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + rfc_send_dm(p_mcb, RFCOMM_MX_DLCI, false); + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } - /******************************************************************************* * * Function rfc_mx_sm_state_wait_conn_cnf @@ -184,80 +180,78 @@ void rfc_mx_sm_state_idle (tRFC_MCB *p_mcb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_wait_conn_cnf - evt:%d", event); - switch (event) - { +void rfc_mx_sm_state_wait_conn_cnf(tRFC_MCB* p_mcb, uint16_t event, + void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_wait_conn_cnf - evt:%d", event); + switch (event) { case RFC_MX_EVENT_START_REQ: - RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event); - return; + RFCOMM_TRACE_ERROR("Mx error state %d event %d", p_mcb->state, event); + return; - /* There is some new timing so that Config Ind comes before security is completed + /* There is some new timing so that Config Ind comes before security is + completed so we are still waiting fo the confirmation. */ case RFC_MX_EVENT_CONF_IND: - rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data); - return; + rfc_mx_conf_ind(p_mcb, (tL2CAP_CFG_INFO*)p_data); + return; case RFC_MX_EVENT_CONN_CNF: - if (*((uint16_t *)p_data) != L2CAP_SUCCESS) - { - p_mcb->state = RFC_MX_STATE_IDLE; + if (*((uint16_t*)p_data) != L2CAP_SUCCESS) { + p_mcb->state = RFC_MX_STATE_IDLE; - PORT_StartCnf (p_mcb, *((uint16_t *)p_data)); - return; - } - p_mcb->state = RFC_MX_STATE_CONFIGURE; - rfc_mx_send_config_req (p_mcb); + PORT_StartCnf(p_mcb, *((uint16_t*)p_data)); return; + } + p_mcb->state = RFC_MX_STATE_CONFIGURE; + rfc_mx_send_config_req(p_mcb); + return; case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_EVENT_TIMEOUT: - p_mcb->state = RFC_MX_STATE_IDLE; - L2CA_DisconnectReq (p_mcb->lcid); - - /* we gave up outgoing connection request then try peer's request */ - if (p_mcb->pending_lcid) - { - uint16_t i; - uint8_t idx; - - RFCOMM_TRACE_DEBUG ("RFCOMM MX retry as acceptor in collision case - evt:%d in state:%d", event, p_mcb->state); - - rfc_save_lcid_mcb (NULL, p_mcb->lcid); - p_mcb->lcid = p_mcb->pending_lcid; - rfc_save_lcid_mcb (p_mcb, p_mcb->lcid); - - p_mcb->is_initiator = false; - - /* update direction bit */ - for (i = 0; i < RFCOMM_MAX_DLCI; i += 2) - { - idx = p_mcb->port_inx[i]; - if (idx != 0) - { - p_mcb->port_inx[i] = 0; - p_mcb->port_inx[i+1] = idx; - rfc_cb.port.port[idx - 1].dlci += 1; - RFCOMM_TRACE_DEBUG ("RFCOMM MX - DLCI:%d -> %d", i, rfc_cb.port.port[idx - 1].dlci); - } - } - - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id)); + p_mcb->state = RFC_MX_STATE_IDLE; + L2CA_DisconnectReq(p_mcb->lcid); + + /* we gave up outgoing connection request then try peer's request */ + if (p_mcb->pending_lcid) { + uint16_t i; + uint8_t idx; + + RFCOMM_TRACE_DEBUG( + "RFCOMM MX retry as acceptor in collision case - evt:%d in " + "state:%d", + event, p_mcb->state); + + rfc_save_lcid_mcb(NULL, p_mcb->lcid); + p_mcb->lcid = p_mcb->pending_lcid; + rfc_save_lcid_mcb(p_mcb, p_mcb->lcid); + + p_mcb->is_initiator = false; + + /* update direction bit */ + for (i = 0; i < RFCOMM_MAX_DLCI; i += 2) { + idx = p_mcb->port_inx[i]; + if (idx != 0) { + p_mcb->port_inx[i] = 0; + p_mcb->port_inx[i + 1] = idx; + rfc_cb.port.port[idx - 1].dlci += 1; + RFCOMM_TRACE_DEBUG("RFCOMM MX - DLCI:%d -> %d", i, + rfc_cb.port.port[idx - 1].dlci); + } } - else - { - PORT_CloseInd (p_mcb); - } - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); -} + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONN_IND, &(p_mcb->pending_id)); + } else { + PORT_CloseInd(p_mcb); + } + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); +} /******************************************************************************* * @@ -269,41 +263,39 @@ void rfc_mx_sm_state_wait_conn_cnf (tRFC_MCB *p_mcb, uint16_t event, void *p_dat * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_configure (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_configure - evt:%d", event); - switch (event) - { +void rfc_mx_sm_state_configure(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_configure - evt:%d", event); + switch (event) { case RFC_MX_EVENT_START_REQ: case RFC_MX_EVENT_CONN_CNF: - RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event); - return; + RFCOMM_TRACE_ERROR("Mx error state %d event %d", p_mcb->state, event); + return; case RFC_MX_EVENT_CONF_IND: - rfc_mx_conf_ind (p_mcb, (tL2CAP_CFG_INFO *)p_data); - return; + rfc_mx_conf_ind(p_mcb, (tL2CAP_CFG_INFO*)p_data); + return; case RFC_MX_EVENT_CONF_CNF: - rfc_mx_conf_cnf (p_mcb, (tL2CAP_CFG_INFO *)p_data); - return; + rfc_mx_conf_cnf(p_mcb, (tL2CAP_CFG_INFO*)p_data); + return; case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_EVENT_TIMEOUT: - p_mcb->state = RFC_MX_STATE_IDLE; - L2CA_DisconnectReq (p_mcb->lcid); - - PORT_StartCnf (p_mcb, RFCOMM_ERROR); - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + p_mcb->state = RFC_MX_STATE_IDLE; + L2CA_DisconnectReq(p_mcb->lcid); + + PORT_StartCnf(p_mcb, RFCOMM_ERROR); + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } - /******************************************************************************* * * Function rfc_mx_sm_sabme_wait_ua @@ -314,16 +306,14 @@ void rfc_mx_sm_state_configure (tRFC_MCB *p_mcb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, uint16_t event, - UNUSED_ATTR void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_sabme_wait_ua - evt:%d", event); - switch (event) - { +void rfc_mx_sm_sabme_wait_ua(tRFC_MCB* p_mcb, uint16_t event, + UNUSED_ATTR void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_sabme_wait_ua - evt:%d", event); + switch (event) { case RFC_MX_EVENT_START_REQ: case RFC_MX_EVENT_CONN_CNF: - RFCOMM_TRACE_ERROR ("Mx error state %d event %d", p_mcb->state, event); - return; + RFCOMM_TRACE_ERROR("Mx error state %d event %d", p_mcb->state, event); + return; /* workaround: we don't support reconfig */ /* commented out until we support reconfig @@ -337,33 +327,34 @@ void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, uint16_t event, */ case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_EVENT_UA: - rfc_timer_stop (p_mcb); + rfc_timer_stop(p_mcb); - p_mcb->state = RFC_MX_STATE_CONNECTED; - p_mcb->peer_ready = true; + p_mcb->state = RFC_MX_STATE_CONNECTED; + p_mcb->peer_ready = true; - PORT_StartCnf (p_mcb, RFCOMM_SUCCESS); - return; + PORT_StartCnf(p_mcb, RFCOMM_SUCCESS); + return; case RFC_EVENT_DM: - rfc_timer_stop (p_mcb); - /* Case falls through */ + rfc_timer_stop(p_mcb); + /* Case falls through */ case RFC_MX_EVENT_CONF_IND: /* workaround: we don't support reconfig */ case RFC_MX_EVENT_CONF_CNF: /* workaround: we don't support reconfig */ case RFC_EVENT_TIMEOUT: - p_mcb->state = RFC_MX_STATE_IDLE; - L2CA_DisconnectReq (p_mcb->lcid); - - PORT_StartCnf (p_mcb, RFCOMM_ERROR); - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + p_mcb->state = RFC_MX_STATE_IDLE; + L2CA_DisconnectReq(p_mcb->lcid); + + PORT_StartCnf(p_mcb, RFCOMM_ERROR); + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } /******************************************************************************* @@ -376,64 +367,58 @@ void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, uint16_t event, * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_wait_sabme (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_wait_sabme - evt:%d", event); - switch (event) - { +void rfc_mx_sm_state_wait_sabme(tRFC_MCB* p_mcb, uint16_t event, void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_wait_sabme - evt:%d", event); + switch (event) { case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_EVENT_SABME: - /* if we gave up outgoing connection request */ - if (p_mcb->pending_lcid) - { - p_mcb->pending_lcid = 0; + /* if we gave up outgoing connection request */ + if (p_mcb->pending_lcid) { + p_mcb->pending_lcid = 0; - rfc_send_ua (p_mcb, RFCOMM_MX_DLCI); + rfc_send_ua(p_mcb, RFCOMM_MX_DLCI); - rfc_timer_stop (p_mcb); - p_mcb->state = RFC_MX_STATE_CONNECTED; - p_mcb->peer_ready = true; + rfc_timer_stop(p_mcb); + p_mcb->state = RFC_MX_STATE_CONNECTED; + p_mcb->peer_ready = true; - /* MX channel collision has been resolved, continue to open ports */ - PORT_StartCnf (p_mcb, RFCOMM_SUCCESS); - } - else - { - rfc_timer_stop (p_mcb); - PORT_StartInd (p_mcb); - } - return; + /* MX channel collision has been resolved, continue to open ports */ + PORT_StartCnf(p_mcb, RFCOMM_SUCCESS); + } else { + rfc_timer_stop(p_mcb); + PORT_StartInd(p_mcb); + } + return; case RFC_MX_EVENT_START_RSP: - if (*((uint16_t *)p_data) != RFCOMM_SUCCESS) - rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, true); - else - { - rfc_send_ua (p_mcb, RFCOMM_MX_DLCI); - - p_mcb->state = RFC_MX_STATE_CONNECTED; - p_mcb->peer_ready = true; - PORT_StartCnf (p_mcb, RFCOMM_SUCCESS); - } - return; + if (*((uint16_t*)p_data) != RFCOMM_SUCCESS) + rfc_send_dm(p_mcb, RFCOMM_MX_DLCI, true); + else { + rfc_send_ua(p_mcb, RFCOMM_MX_DLCI); + + p_mcb->state = RFC_MX_STATE_CONNECTED; + p_mcb->peer_ready = true; + PORT_StartCnf(p_mcb, RFCOMM_SUCCESS); + } + return; case RFC_MX_EVENT_CONF_IND: /* workaround: we don't support reconfig */ case RFC_MX_EVENT_CONF_CNF: /* workaround: we don't support reconfig */ case RFC_EVENT_TIMEOUT: - p_mcb->state = RFC_MX_STATE_IDLE; - L2CA_DisconnectReq (p_mcb->lcid); - - PORT_CloseInd (p_mcb); - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + p_mcb->state = RFC_MX_STATE_IDLE; + L2CA_DisconnectReq(p_mcb->lcid); + + PORT_CloseInd(p_mcb); + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } - /******************************************************************************* * * Function rfc_mx_sm_state_connected @@ -444,41 +429,38 @@ void rfc_mx_sm_state_wait_sabme (tRFC_MCB *p_mcb, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, uint16_t event, - UNUSED_ATTR void *p_data) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_connected - evt:%d", event); +void rfc_mx_sm_state_connected(tRFC_MCB* p_mcb, uint16_t event, + UNUSED_ATTR void* p_data) { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_connected - evt:%d", event); - switch (event) - { + switch (event) { case RFC_EVENT_TIMEOUT: case RFC_MX_EVENT_CLOSE_REQ: - rfc_timer_start (p_mcb, RFC_DISC_TIMEOUT); - p_mcb->state = RFC_MX_STATE_DISC_WAIT_UA; - rfc_send_disc (p_mcb, RFCOMM_MX_DLCI); - return; + rfc_timer_start(p_mcb, RFC_DISC_TIMEOUT); + p_mcb->state = RFC_MX_STATE_DISC_WAIT_UA; + rfc_send_disc(p_mcb, RFCOMM_MX_DLCI); + return; case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_EVENT_DISC: - /* Reply with UA. If initiator bring down L2CAP connection */ - /* If server wait for some time if client decide to reinitiate channel */ - rfc_send_ua (p_mcb, RFCOMM_MX_DLCI); - if (p_mcb->is_initiator) - { - L2CA_DisconnectReq (p_mcb->lcid); - } - /* notify all ports that connection is gone */ - PORT_CloseInd (p_mcb); - return; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + /* Reply with UA. If initiator bring down L2CAP connection */ + /* If server wait for some time if client decide to reinitiate channel */ + rfc_send_ua(p_mcb, RFCOMM_MX_DLCI); + if (p_mcb->is_initiator) { + L2CA_DisconnectReq(p_mcb->lcid); + } + /* notify all ports that connection is gone */ + PORT_CloseInd(p_mcb); + return; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } - /******************************************************************************* * * Function rfc_mx_sm_state_disc_wait_ua @@ -489,77 +471,75 @@ void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, uint16_t event, * Returns void * ******************************************************************************/ -void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, uint16_t event, void *p_data) -{ - BT_HDR *p_buf; +void rfc_mx_sm_state_disc_wait_ua(tRFC_MCB* p_mcb, uint16_t event, + void* p_data) { + BT_HDR* p_buf; - RFCOMM_TRACE_EVENT ("rfc_mx_sm_state_disc_wait_ua - evt:%d", event); - switch (event) - { + RFCOMM_TRACE_EVENT("rfc_mx_sm_state_disc_wait_ua - evt:%d", event); + switch (event) { case RFC_EVENT_UA: case RFC_EVENT_DM: case RFC_EVENT_TIMEOUT: - L2CA_DisconnectReq (p_mcb->lcid); - - if (p_mcb->restart_required) - { - /* Start Request was received while disconnecting. Execute it again */ - uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); - if (lcid == 0) { - rfc_save_lcid_mcb(NULL, p_mcb->lcid); - p_mcb->lcid = 0; - PORT_StartCnf(p_mcb, RFCOMM_ERROR); - return; - } - p_mcb->lcid = lcid; - /* Save entry for quicker access to mcb based on the LCID */ - rfc_save_lcid_mcb (p_mcb, p_mcb->lcid); - - /* clean up before reuse it */ - while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q)) != NULL) - osi_free(p_buf); - - rfc_timer_start (p_mcb, RFC_MCB_INIT_INACT_TIMER); - - p_mcb->is_initiator = true; - p_mcb->restart_required = false; - p_mcb->local_cfg_sent = false; - p_mcb->peer_cfg_rcvd = false; - - p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF; - return; + L2CA_DisconnectReq(p_mcb->lcid); + + if (p_mcb->restart_required) { + /* Start Request was received while disconnecting. Execute it again */ + uint16_t lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr); + if (lcid == 0) { + rfc_save_lcid_mcb(NULL, p_mcb->lcid); + p_mcb->lcid = 0; + PORT_StartCnf(p_mcb, RFCOMM_ERROR); + return; } - rfc_release_multiplexer_channel (p_mcb); + p_mcb->lcid = lcid; + /* Save entry for quicker access to mcb based on the LCID */ + rfc_save_lcid_mcb(p_mcb, p_mcb->lcid); + + /* clean up before reuse it */ + while ((p_buf = (BT_HDR*)fixed_queue_try_dequeue(p_mcb->cmd_q)) != NULL) + osi_free(p_buf); + + rfc_timer_start(p_mcb, RFC_MCB_INIT_INACT_TIMER); + + p_mcb->is_initiator = true; + p_mcb->restart_required = false; + p_mcb->local_cfg_sent = false; + p_mcb->peer_cfg_rcvd = false; + + p_mcb->state = RFC_MX_STATE_WAIT_CONN_CNF; return; + } + rfc_release_multiplexer_channel(p_mcb); + return; case RFC_EVENT_DISC: - rfc_send_ua (p_mcb, RFCOMM_MX_DLCI); - return; + rfc_send_ua(p_mcb, RFCOMM_MX_DLCI); + return; case RFC_EVENT_UIH: - osi_free(p_data); - rfc_send_dm (p_mcb, RFCOMM_MX_DLCI, false); - return; + osi_free(p_data); + rfc_send_dm(p_mcb, RFCOMM_MX_DLCI, false); + return; case RFC_MX_EVENT_START_REQ: - p_mcb->restart_required = true; - return; + p_mcb->restart_required = true; + return; case RFC_MX_EVENT_DISC_IND: - p_mcb->state = RFC_MX_STATE_IDLE; - PORT_CloseInd (p_mcb); - return; + p_mcb->state = RFC_MX_STATE_IDLE; + PORT_CloseInd(p_mcb); + return; case RFC_MX_EVENT_CLOSE_REQ: - return; + return; case RFC_MX_EVENT_QOS_VIOLATION_IND: - break; - } - RFCOMM_TRACE_EVENT ("RFCOMM MX ignored - evt:%d in state:%d", event, p_mcb->state); + break; + } + RFCOMM_TRACE_EVENT("RFCOMM MX ignored - evt:%d in state:%d", event, + p_mcb->state); } - /******************************************************************************* * * Function rfc_mx_send_config_req @@ -568,28 +548,26 @@ void rfc_mx_sm_state_disc_wait_ua (tRFC_MCB *p_mcb, uint16_t event, void *p_data * L2CAP. Accept connection. * ******************************************************************************/ -static void rfc_mx_send_config_req (tRFC_MCB *p_mcb) -{ - tL2CAP_CFG_INFO cfg; - - RFCOMM_TRACE_EVENT ("rfc_mx_send_config_req"); - - memset (&cfg, 0, sizeof (tL2CAP_CFG_INFO)); - - cfg.mtu_present = true; - cfg.mtu = L2CAP_MTU_SIZE; - -/* Defaults set by memset - cfg.flush_to_present = false; - cfg.qos_present = false; - cfg.fcr_present = false; - cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; - cfg.fcs_present = false; - cfg.fcs = N/A when fcs_present is false; -*/ - L2CA_ConfigReq (p_mcb->lcid, &cfg); -} +static void rfc_mx_send_config_req(tRFC_MCB* p_mcb) { + tL2CAP_CFG_INFO cfg; + + RFCOMM_TRACE_EVENT("rfc_mx_send_config_req"); + + memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); + cfg.mtu_present = true; + cfg.mtu = L2CAP_MTU_SIZE; + + /* Defaults set by memset + cfg.flush_to_present = false; + cfg.qos_present = false; + cfg.fcr_present = false; + cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; + cfg.fcs_present = false; + cfg.fcs = N/A when fcs_present is false; + */ + L2CA_ConfigReq(p_mcb->lcid, &cfg); +} /******************************************************************************* * @@ -601,41 +579,35 @@ static void rfc_mx_send_config_req (tRFC_MCB *p_mcb) * on DLCI 0. T1 is still running. * ******************************************************************************/ -static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg) -{ - RFCOMM_TRACE_EVENT ("rfc_mx_conf_cnf p_cfg:%08x res:%d ", p_cfg, (p_cfg) ? p_cfg->result : 0); - - if (p_cfg->result != L2CAP_CFG_OK) - { - if (p_mcb->is_initiator) - { - PORT_StartCnf (p_mcb, p_cfg->result); - L2CA_DisconnectReq (p_mcb->lcid); - } - rfc_release_multiplexer_channel (p_mcb); - return; +static void rfc_mx_conf_cnf(tRFC_MCB* p_mcb, tL2CAP_CFG_INFO* p_cfg) { + RFCOMM_TRACE_EVENT("rfc_mx_conf_cnf p_cfg:%08x res:%d ", p_cfg, + (p_cfg) ? p_cfg->result : 0); + + if (p_cfg->result != L2CAP_CFG_OK) { + if (p_mcb->is_initiator) { + PORT_StartCnf(p_mcb, p_cfg->result); + L2CA_DisconnectReq(p_mcb->lcid); } - - p_mcb->local_cfg_sent = true; - if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->peer_cfg_rcvd) - { - if (p_mcb->is_initiator) - { - p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA; - rfc_send_sabme (p_mcb, RFCOMM_MX_DLCI); - rfc_timer_start (p_mcb, RFC_T1_TIMEOUT); - } - else - { - p_mcb->state = RFC_MX_STATE_WAIT_SABME; - rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120 - to allow the user more than 10 sec to type in the - pin which can be e.g. 16 digits */ - } + rfc_release_multiplexer_channel(p_mcb); + return; + } + + p_mcb->local_cfg_sent = true; + if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->peer_cfg_rcvd) { + if (p_mcb->is_initiator) { + p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA; + rfc_send_sabme(p_mcb, RFCOMM_MX_DLCI); + rfc_timer_start(p_mcb, RFC_T1_TIMEOUT); + } else { + p_mcb->state = RFC_MX_STATE_WAIT_SABME; + rfc_timer_start( + p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120 + to allow the user more than 10 sec to type in the + pin which can be e.g. 16 digits */ } + } } - /******************************************************************************* * * Function rfc_mx_conf_ind @@ -644,38 +616,34 @@ static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg) * L2CAP. Send the L2CA_ConfigRsp message. * ******************************************************************************/ -static void rfc_mx_conf_ind (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg) -{ - /* Save peer L2CAP MTU if present */ - /* RFCOMM adds 3-4 bytes in the beginning and 1 bytes FCS */ - if (p_cfg->mtu_present) - p_mcb->peer_l2cap_mtu = p_cfg->mtu - RFCOMM_MIN_OFFSET - 1; - else - p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; - - p_cfg->mtu_present = false; - p_cfg->flush_to_present = false; - p_cfg->qos_present = false; - - p_cfg->result = L2CAP_CFG_OK; - - L2CA_ConfigRsp (p_mcb->lcid, p_cfg); - - p_mcb->peer_cfg_rcvd = true; - if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->local_cfg_sent) - { - if (p_mcb->is_initiator) - { - p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA; - rfc_send_sabme (p_mcb, RFCOMM_MX_DLCI); - rfc_timer_start (p_mcb, RFC_T1_TIMEOUT); - } - else - { - p_mcb->state = RFC_MX_STATE_WAIT_SABME; - rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120 - to allow the user more than 10 sec to type in the - pin which can be e.g. 16 digits */ - } +static void rfc_mx_conf_ind(tRFC_MCB* p_mcb, tL2CAP_CFG_INFO* p_cfg) { + /* Save peer L2CAP MTU if present */ + /* RFCOMM adds 3-4 bytes in the beginning and 1 bytes FCS */ + if (p_cfg->mtu_present) + p_mcb->peer_l2cap_mtu = p_cfg->mtu - RFCOMM_MIN_OFFSET - 1; + else + p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1; + + p_cfg->mtu_present = false; + p_cfg->flush_to_present = false; + p_cfg->qos_present = false; + + p_cfg->result = L2CAP_CFG_OK; + + L2CA_ConfigRsp(p_mcb->lcid, p_cfg); + + p_mcb->peer_cfg_rcvd = true; + if ((p_mcb->state == RFC_MX_STATE_CONFIGURE) && p_mcb->local_cfg_sent) { + if (p_mcb->is_initiator) { + p_mcb->state = RFC_MX_STATE_SABME_WAIT_UA; + rfc_send_sabme(p_mcb, RFCOMM_MX_DLCI); + rfc_timer_start(p_mcb, RFC_T1_TIMEOUT); + } else { + p_mcb->state = RFC_MX_STATE_WAIT_SABME; + rfc_timer_start( + p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120 + to allow the user more than 10 sec to type in the + pin which can be e.g. 16 digits */ } + } } diff --git a/stack/rfcomm/rfc_port_fsm.cc b/stack/rfcomm/rfc_port_fsm.cc index d048989f2..dfe4b04c1 100644 --- a/stack/rfcomm/rfc_port_fsm.cc +++ b/stack/rfcomm/rfc_port_fsm.cc @@ -23,31 +23,35 @@ * ******************************************************************************/ #include -#include "bt_target.h" #include "bt_common.h" -#include "rfcdefs.h" +#include "bt_target.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" +#include "osi/include/osi.h" #include "port_api.h" #include "port_int.h" #include "rfc_int.h" -#include "bt_utils.h" -#include "osi/include/osi.h" +#include "rfcdefs.h" /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void rfc_port_sm_state_closed (tPORT *p_port, uint16_t event, void *p_data); -static void rfc_port_sm_sabme_wait_ua (tPORT *p_port, uint16_t event, void *p_data); -static void rfc_port_sm_opened (tPORT *p_port, uint16_t event, void *p_data); -static void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, uint16_t event, void *p_data); -static void rfc_port_sm_term_wait_sec_check (tPORT *p_port, uint16_t event, void *p_data); -static void rfc_port_sm_disc_wait_ua (tPORT *p_port, uint16_t event, void *p_data); - -static void rfc_port_uplink_data (tPORT *p_port, BT_HDR *p_buf); - -static void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame); - +static void rfc_port_sm_state_closed(tPORT* p_port, uint16_t event, + void* p_data); +static void rfc_port_sm_sabme_wait_ua(tPORT* p_port, uint16_t event, + void* p_data); +static void rfc_port_sm_opened(tPORT* p_port, uint16_t event, void* p_data); +static void rfc_port_sm_orig_wait_sec_check(tPORT* p_port, uint16_t event, + void* p_data); +static void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event, + void* p_data); +static void rfc_port_sm_disc_wait_ua(tPORT* p_port, uint16_t event, + void* p_data); + +static void rfc_port_uplink_data(tPORT* p_port, BT_HDR* p_buf); + +static void rfc_set_port_state(tPORT_STATE* port_pars, MX_FRAME* p_frame); /******************************************************************************* * @@ -59,43 +63,39 @@ static void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame); * Returns void * ******************************************************************************/ -void rfc_port_sm_execute (tPORT *p_port, uint16_t event, void *p_data) -{ - if (!p_port) - { - RFCOMM_TRACE_WARNING ("NULL port event %d", event); - return; - } +void rfc_port_sm_execute(tPORT* p_port, uint16_t event, void* p_data) { + if (!p_port) { + RFCOMM_TRACE_WARNING("NULL port event %d", event); + return; + } - switch (p_port->rfc.state) - { + switch (p_port->rfc.state) { case RFC_STATE_CLOSED: - rfc_port_sm_state_closed (p_port, event, p_data); - break; + rfc_port_sm_state_closed(p_port, event, p_data); + break; case RFC_STATE_SABME_WAIT_UA: - rfc_port_sm_sabme_wait_ua (p_port, event, p_data); - break; + rfc_port_sm_sabme_wait_ua(p_port, event, p_data); + break; case RFC_STATE_ORIG_WAIT_SEC_CHECK: - rfc_port_sm_orig_wait_sec_check (p_port, event, p_data); - break; + rfc_port_sm_orig_wait_sec_check(p_port, event, p_data); + break; case RFC_STATE_TERM_WAIT_SEC_CHECK: - rfc_port_sm_term_wait_sec_check (p_port, event, p_data); - break; + rfc_port_sm_term_wait_sec_check(p_port, event, p_data); + break; case RFC_STATE_OPENED: - rfc_port_sm_opened (p_port, event, p_data); - break; + rfc_port_sm_opened(p_port, event, p_data); + break; case RFC_STATE_DISC_WAIT_UA: - rfc_port_sm_disc_wait_ua (p_port, event, p_data); - break; - } + rfc_port_sm_disc_wait_ua(p_port, event, p_data); + break; + } } - /******************************************************************************* * * Function rfc_port_sm_state_closed @@ -107,62 +107,63 @@ void rfc_port_sm_execute (tPORT *p_port, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_port_sm_state_closed (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_state_closed(tPORT* p_port, uint16_t event, void* p_data) { + switch (event) { case RFC_EVENT_OPEN: - p_port->rfc.state = RFC_STATE_ORIG_WAIT_SEC_CHECK; - btm_sec_mx_access_request (p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, true, - BTM_SEC_PROTO_RFCOMM, (uint32_t)(p_port->dlci / 2), - &rfc_sec_check_complete, p_port); - return; + p_port->rfc.state = RFC_STATE_ORIG_WAIT_SEC_CHECK; + btm_sec_mx_access_request( + p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, true, BTM_SEC_PROTO_RFCOMM, + (uint32_t)(p_port->dlci / 2), &rfc_sec_check_complete, p_port); + return; case RFC_EVENT_CLOSE: - break; + break; case RFC_EVENT_CLEAR: - return; + return; case RFC_EVENT_DATA: - osi_free(p_data); - break; + osi_free(p_data); + break; case RFC_EVENT_SABME: - /* make sure the multiplexer disconnect timer is not running (reconnect case) */ - rfc_timer_stop(p_port->rfc.p_mcb ); - - /* Open will be continued after security checks are passed */ - p_port->rfc.state = RFC_STATE_TERM_WAIT_SEC_CHECK; - btm_sec_mx_access_request (p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, false, - BTM_SEC_PROTO_RFCOMM, (uint32_t)(p_port->dlci / 2), - &rfc_sec_check_complete, p_port); - return; + /* make sure the multiplexer disconnect timer is not running (reconnect + * case) */ + rfc_timer_stop(p_port->rfc.p_mcb); + + /* Open will be continued after security checks are passed */ + p_port->rfc.state = RFC_STATE_TERM_WAIT_SEC_CHECK; + btm_sec_mx_access_request(p_port->rfc.p_mcb->bd_addr, BT_PSM_RFCOMM, + false, BTM_SEC_PROTO_RFCOMM, + (uint32_t)(p_port->dlci / 2), + &rfc_sec_check_complete, p_port); + return; case RFC_EVENT_UA: - return; + return; case RFC_EVENT_DM: - rfc_port_closed (p_port); - return; + rfc_port_closed(p_port); + return; case RFC_EVENT_UIH: - osi_free(p_data); - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, false); - return; + osi_free(p_data); + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false); + return; case RFC_EVENT_DISC: - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, false); - return; + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false); + return; case RFC_EVENT_TIMEOUT: - Port_TimeOutCloseMux( p_port->rfc.p_mcb ) ; - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; - } - - RFCOMM_TRACE_WARNING ("Port state closed Event ignored %d", event); - return; + Port_TimeOutCloseMux(p_port->rfc.p_mcb); + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; + } + + RFCOMM_TRACE_WARNING("Port state closed Event ignored %d", event); + return; } /******************************************************************************* @@ -175,66 +176,68 @@ void rfc_port_sm_state_closed (tPORT *p_port, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_port_sm_sabme_wait_ua (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_sabme_wait_ua(tPORT* p_port, uint16_t event, void* p_data) { + switch (event) { case RFC_EVENT_OPEN: case RFC_EVENT_ESTABLISH_RSP: - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; case RFC_EVENT_CLOSE: - rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT); - rfc_send_disc (p_port->rfc.p_mcb, p_port->dlci); - p_port->rfc.expected_rsp = 0; - p_port->rfc.state = RFC_STATE_DISC_WAIT_UA; - return; + rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT); + rfc_send_disc(p_port->rfc.p_mcb, p_port->dlci); + p_port->rfc.expected_rsp = 0; + p_port->rfc.state = RFC_STATE_DISC_WAIT_UA; + return; case RFC_EVENT_CLEAR: - rfc_port_closed (p_port); - return; + rfc_port_closed(p_port); + return; case RFC_EVENT_DATA: - osi_free(p_data); - break; + osi_free(p_data); + break; case RFC_EVENT_UA: - rfc_port_timer_stop (p_port); - p_port->rfc.state = RFC_STATE_OPENED; - PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_SUCCESS); - return; + rfc_port_timer_stop(p_port); + p_port->rfc.state = RFC_STATE_OPENED; + PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, + p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_SUCCESS); + return; case RFC_EVENT_DM: - p_port->rfc.p_mcb->is_disc_initiator = true; - PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); - rfc_port_closed (p_port); - return; + p_port->rfc.p_mcb->is_disc_initiator = true; + PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, + p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); + rfc_port_closed(p_port); + return; case RFC_EVENT_DISC: - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); - PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); - rfc_port_closed (p_port); - return; + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); + PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, + p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); + rfc_port_closed(p_port); + return; case RFC_EVENT_SABME: - /* Continue to wait for the UA the SABME this side sent */ - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); - return; + /* Continue to wait for the UA the SABME this side sent */ + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); + return; case RFC_EVENT_UIH: - osi_free(p_data); - return; + osi_free(p_data); + return; case RFC_EVENT_TIMEOUT: - p_port->rfc.state = RFC_STATE_CLOSED; - PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); - return; - } - RFCOMM_TRACE_WARNING ("Port state sabme_wait_ua Event ignored %d", event); + p_port->rfc.state = RFC_STATE_CLOSED; + PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, + p_port->rfc.p_mcb->peer_l2cap_mtu, RFCOMM_ERROR); + return; + } + RFCOMM_TRACE_WARNING("Port state sabme_wait_ua Event ignored %d", event); } - /******************************************************************************* * * Function rfc_port_sm_term_wait_sec_check @@ -247,76 +250,70 @@ void rfc_port_sm_sabme_wait_ua (tPORT *p_port, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_port_sm_term_wait_sec_check (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_term_wait_sec_check(tPORT* p_port, uint16_t event, + void* p_data) { + switch (event) { case RFC_EVENT_SEC_COMPLETE: - if (*((uint8_t *)p_data) != BTM_SUCCESS) - { - /* Authentication/authorization failed. If link is still */ - /* up send DM and check if we need to start inactive timer */ - if (p_port->rfc.p_mcb) - { - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, true); - p_port->rfc.p_mcb->is_disc_initiator = true; - port_rfc_closed (p_port, PORT_SEC_FAILED); - } - } - else - { - PORT_DlcEstablishInd (p_port->rfc.p_mcb, p_port->dlci, p_port->rfc.p_mcb->peer_l2cap_mtu); + if (*((uint8_t*)p_data) != BTM_SUCCESS) { + /* Authentication/authorization failed. If link is still */ + /* up send DM and check if we need to start inactive timer */ + if (p_port->rfc.p_mcb) { + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true); + p_port->rfc.p_mcb->is_disc_initiator = true; + port_rfc_closed(p_port, PORT_SEC_FAILED); } - return; + } else { + PORT_DlcEstablishInd(p_port->rfc.p_mcb, p_port->dlci, + p_port->rfc.p_mcb->peer_l2cap_mtu); + } + return; case RFC_EVENT_OPEN: case RFC_EVENT_CLOSE: - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; case RFC_EVENT_CLEAR: - btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr); - rfc_port_closed (p_port); - return; + btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr); + rfc_port_closed(p_port); + return; case RFC_EVENT_DATA: - RFCOMM_TRACE_ERROR ("Port error state Term Wait Sec event Data"); - osi_free(p_data); - return; + RFCOMM_TRACE_ERROR("Port error state Term Wait Sec event Data"); + osi_free(p_data); + return; case RFC_EVENT_SABME: - /* Ignore SABME retransmission if client dares to do so */ - return; + /* Ignore SABME retransmission if client dares to do so */ + return; case RFC_EVENT_DISC: - btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr); - p_port->rfc.state = RFC_STATE_CLOSED; - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); + btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr); + p_port->rfc.state = RFC_STATE_CLOSED; + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); - PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci); - return; + PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci); + return; case RFC_EVENT_UIH: - osi_free(p_data); - return; + osi_free(p_data); + return; case RFC_EVENT_ESTABLISH_RSP: - if (*((uint8_t *)p_data) != RFCOMM_SUCCESS) - { - if (p_port->rfc.p_mcb) - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, true); - } - else - { - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); - p_port->rfc.state = RFC_STATE_OPENED; - } - return; - } - RFCOMM_TRACE_WARNING ("Port state term_wait_sec_check Event ignored %d", event); + if (*((uint8_t*)p_data) != RFCOMM_SUCCESS) { + if (p_port->rfc.p_mcb) + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true); + } else { + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); + p_port->rfc.state = RFC_STATE_OPENED; + } + return; + } + RFCOMM_TRACE_WARNING("Port state term_wait_sec_check Event ignored %d", + event); } - /******************************************************************************* * * Function rfc_port_sm_orig_wait_sec_check @@ -328,46 +325,46 @@ void rfc_port_sm_term_wait_sec_check (tPORT *p_port, uint16_t event, void *p_dat * Returns void * ******************************************************************************/ -void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_orig_wait_sec_check(tPORT* p_port, uint16_t event, + void* p_data) { + switch (event) { case RFC_EVENT_SEC_COMPLETE: - if (*((uint8_t *)p_data) != BTM_SUCCESS) - { - p_port->rfc.p_mcb->is_disc_initiator = true; - PORT_DlcEstablishCnf (p_port->rfc.p_mcb, p_port->dlci, 0, RFCOMM_SECURITY_ERR); - rfc_port_closed (p_port); - return; - } - rfc_send_sabme (p_port->rfc.p_mcb, p_port->dlci); - rfc_port_timer_start (p_port, RFC_PORT_T1_TIMEOUT); - p_port->rfc.state = RFC_STATE_SABME_WAIT_UA; + if (*((uint8_t*)p_data) != BTM_SUCCESS) { + p_port->rfc.p_mcb->is_disc_initiator = true; + PORT_DlcEstablishCnf(p_port->rfc.p_mcb, p_port->dlci, 0, + RFCOMM_SECURITY_ERR); + rfc_port_closed(p_port); return; + } + rfc_send_sabme(p_port->rfc.p_mcb, p_port->dlci); + rfc_port_timer_start(p_port, RFC_PORT_T1_TIMEOUT); + p_port->rfc.state = RFC_STATE_SABME_WAIT_UA; + return; case RFC_EVENT_OPEN: - case RFC_EVENT_SABME: /* Peer should not use the same dlci */ - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; + case RFC_EVENT_SABME: /* Peer should not use the same dlci */ + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; case RFC_EVENT_CLOSE: - btm_sec_abort_access_req (p_port->rfc.p_mcb->bd_addr); - rfc_port_closed (p_port); - return; + btm_sec_abort_access_req(p_port->rfc.p_mcb->bd_addr); + rfc_port_closed(p_port); + return; case RFC_EVENT_DATA: - RFCOMM_TRACE_ERROR ("Port error state Orig Wait Sec event Data"); - osi_free(p_data); - return; + RFCOMM_TRACE_ERROR("Port error state Orig Wait Sec event Data"); + osi_free(p_data); + return; case RFC_EVENT_UIH: - osi_free(p_data); - return; - } - RFCOMM_TRACE_WARNING ("Port state orig_wait_sec_check Event ignored %d", event); + osi_free(p_data); + return; + } + RFCOMM_TRACE_WARNING("Port state orig_wait_sec_check Event ignored %d", + event); } - /******************************************************************************* * * Function rfc_port_sm_opened @@ -378,83 +375,80 @@ void rfc_port_sm_orig_wait_sec_check (tPORT *p_port, uint16_t event, void *p_dat * Returns void * ******************************************************************************/ -void rfc_port_sm_opened (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_opened(tPORT* p_port, uint16_t event, void* p_data) { + switch (event) { case RFC_EVENT_OPEN: - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; case RFC_EVENT_CLOSE: - rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT); - rfc_send_disc (p_port->rfc.p_mcb, p_port->dlci); - p_port->rfc.expected_rsp = 0; - p_port->rfc.state = RFC_STATE_DISC_WAIT_UA; - return; + rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT); + rfc_send_disc(p_port->rfc.p_mcb, p_port->dlci); + p_port->rfc.expected_rsp = 0; + p_port->rfc.state = RFC_STATE_DISC_WAIT_UA; + return; case RFC_EVENT_CLEAR: - rfc_port_closed (p_port); - return; + rfc_port_closed(p_port); + return; case RFC_EVENT_DATA: - /* Send credits in the frame. Pass them in the layer specific member of the hdr. */ - /* There might be an initial case when we reduced rx_max and credit_rx is still */ - /* bigger. Make sure that we do not send 255 */ - if ((p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - && (((BT_HDR *)p_data)->len < p_port->peer_mtu) - && (!p_port->rx.user_fc) - && (p_port->credit_rx_max > p_port->credit_rx)) - { - ((BT_HDR *)p_data)->layer_specific = (uint8_t) (p_port->credit_rx_max - p_port->credit_rx); - p_port->credit_rx = p_port->credit_rx_max; - } - else - { - ((BT_HDR *)p_data)->layer_specific = 0; - } - rfc_send_buf_uih (p_port->rfc.p_mcb, p_port->dlci, (BT_HDR *)p_data); - rfc_dec_credit (p_port); - return; + /* Send credits in the frame. Pass them in the layer specific member of + * the hdr. */ + /* There might be an initial case when we reduced rx_max and credit_rx is + * still */ + /* bigger. Make sure that we do not send 255 */ + if ((p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) && + (((BT_HDR*)p_data)->len < p_port->peer_mtu) && + (!p_port->rx.user_fc) && + (p_port->credit_rx_max > p_port->credit_rx)) { + ((BT_HDR*)p_data)->layer_specific = + (uint8_t)(p_port->credit_rx_max - p_port->credit_rx); + p_port->credit_rx = p_port->credit_rx_max; + } else { + ((BT_HDR*)p_data)->layer_specific = 0; + } + rfc_send_buf_uih(p_port->rfc.p_mcb, p_port->dlci, (BT_HDR*)p_data); + rfc_dec_credit(p_port); + return; case RFC_EVENT_UA: - return; + return; case RFC_EVENT_SABME: - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); - return; + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); + return; case RFC_EVENT_DM: - PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci); - rfc_port_closed (p_port); - return; + PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci); + rfc_port_closed(p_port); + return; case RFC_EVENT_DISC: - p_port->rfc.state = RFC_STATE_CLOSED; - rfc_send_ua (p_port->rfc.p_mcb, p_port->dlci); - if(! fixed_queue_is_empty(p_port->rx.queue)) - { - /* give a chance to upper stack to close port properly */ - RFCOMM_TRACE_DEBUG("port queue is not empty"); - rfc_port_timer_start (p_port, RFC_DISC_TIMEOUT); - } - else - PORT_DlcReleaseInd (p_port->rfc.p_mcb, p_port->dlci); - return; + p_port->rfc.state = RFC_STATE_CLOSED; + rfc_send_ua(p_port->rfc.p_mcb, p_port->dlci); + if (!fixed_queue_is_empty(p_port->rx.queue)) { + /* give a chance to upper stack to close port properly */ + RFCOMM_TRACE_DEBUG("port queue is not empty"); + rfc_port_timer_start(p_port, RFC_DISC_TIMEOUT); + } else + PORT_DlcReleaseInd(p_port->rfc.p_mcb, p_port->dlci); + return; case RFC_EVENT_UIH: - rfc_port_uplink_data (p_port, (BT_HDR *)p_data); - return; + rfc_port_uplink_data(p_port, (BT_HDR*)p_data); + return; case RFC_EVENT_TIMEOUT: - Port_TimeOutCloseMux( p_port->rfc.p_mcb ) ; - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; - } - RFCOMM_TRACE_WARNING ("Port state opened Event ignored %d", event); + Port_TimeOutCloseMux(p_port->rfc.p_mcb); + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; + } + RFCOMM_TRACE_WARNING("Port state opened Event ignored %d", event); } - /******************************************************************************* * * Function rfc_port_sm_disc_wait_ua @@ -465,53 +459,51 @@ void rfc_port_sm_opened (tPORT *p_port, uint16_t event, void *p_data) * Returns void * ******************************************************************************/ -void rfc_port_sm_disc_wait_ua (tPORT *p_port, uint16_t event, void *p_data) -{ - switch (event) - { +void rfc_port_sm_disc_wait_ua(tPORT* p_port, uint16_t event, void* p_data) { + switch (event) { case RFC_EVENT_OPEN: case RFC_EVENT_ESTABLISH_RSP: - RFCOMM_TRACE_ERROR ("Port error state %d event %d", p_port->rfc.state, event); - return; + RFCOMM_TRACE_ERROR("Port error state %d event %d", p_port->rfc.state, + event); + return; case RFC_EVENT_CLEAR: - rfc_port_closed (p_port); - return; + rfc_port_closed(p_port); + return; case RFC_EVENT_DATA: - osi_free(p_data); - return; + osi_free(p_data); + return; case RFC_EVENT_UA: - p_port->rfc.p_mcb->is_disc_initiator = true; - /* Case falls through */ + p_port->rfc.p_mcb->is_disc_initiator = true; + /* Case falls through */ - case RFC_EVENT_DM: - rfc_port_closed (p_port); - return; + case RFC_EVENT_DM: + rfc_port_closed(p_port); + return; case RFC_EVENT_SABME: - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, true); - return; + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true); + return; case RFC_EVENT_DISC: - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, true); - return; + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, true); + return; case RFC_EVENT_UIH: - osi_free(p_data); - rfc_send_dm (p_port->rfc.p_mcb, p_port->dlci, false); - return; + osi_free(p_data); + rfc_send_dm(p_port->rfc.p_mcb, p_port->dlci, false); + return; case RFC_EVENT_TIMEOUT: - rfc_port_closed (p_port); - return; - } + rfc_port_closed(p_port); + return; + } - RFCOMM_TRACE_WARNING ("Port state disc_wait_ua Event ignored %d", event); + RFCOMM_TRACE_WARNING("Port state disc_wait_ua Event ignored %d", event); } - /******************************************************************************* * * Function rfc_port_uplink_data @@ -519,12 +511,10 @@ void rfc_port_sm_disc_wait_ua (tPORT *p_port, uint16_t event, void *p_data) * Description This function handles uplink information data frame. * ******************************************************************************/ -void rfc_port_uplink_data (tPORT *p_port, BT_HDR *p_buf) -{ - PORT_DataInd (p_port->rfc.p_mcb, p_port->dlci, p_buf); +void rfc_port_uplink_data(tPORT* p_port, BT_HDR* p_buf) { + PORT_DataInd(p_port->rfc.p_mcb, p_port->dlci, p_buf); } - /******************************************************************************* * * Function rfc_process_pn @@ -533,40 +523,33 @@ void rfc_port_uplink_data (tPORT *p_port, BT_HDR *p_buf) * Record MTU and pass indication to the upper layer. * ******************************************************************************/ -void rfc_process_pn (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) -{ - tPORT *p_port; - uint8_t dlci = p_frame->dlci; - - if (is_command) - { - /* Ignore if Multiplexer is being shut down */ - if (p_mcb->state != RFC_MX_STATE_DISC_WAIT_UA) - { - PORT_ParNegInd (p_mcb, dlci, p_frame->u.pn.mtu, - p_frame->u.pn.conv_layer, p_frame->u.pn.k); - } - else - { - rfc_send_dm(p_mcb, dlci, false); - RFCOMM_TRACE_WARNING("***** MX PN while disconnecting *****"); - } - - return; +void rfc_process_pn(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) { + tPORT* p_port; + uint8_t dlci = p_frame->dlci; + + if (is_command) { + /* Ignore if Multiplexer is being shut down */ + if (p_mcb->state != RFC_MX_STATE_DISC_WAIT_UA) { + PORT_ParNegInd(p_mcb, dlci, p_frame->u.pn.mtu, p_frame->u.pn.conv_layer, + p_frame->u.pn.k); + } else { + rfc_send_dm(p_mcb, dlci, false); + RFCOMM_TRACE_WARNING("***** MX PN while disconnecting *****"); } - /* If we are not awaiting response just ignore it */ - p_port = port_find_mcb_dlci_port (p_mcb, dlci); - if ((p_port == NULL) || !(p_port->rfc.expected_rsp & RFC_RSP_PN)) - return; - p_port->rfc.expected_rsp &= ~RFC_RSP_PN; + return; + } + /* If we are not awaiting response just ignore it */ + p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if ((p_port == NULL) || !(p_port->rfc.expected_rsp & RFC_RSP_PN)) return; - rfc_port_timer_stop (p_port); + p_port->rfc.expected_rsp &= ~RFC_RSP_PN; - PORT_ParNegCnf (p_mcb, dlci, p_frame->u.pn.mtu, - p_frame->u.pn.conv_layer, p_frame->u.pn.k); -} + rfc_port_timer_stop(p_port); + PORT_ParNegCnf(p_mcb, dlci, p_frame->u.pn.mtu, p_frame->u.pn.conv_layer, + p_frame->u.pn.k); +} /******************************************************************************* * @@ -576,116 +559,112 @@ void rfc_process_pn (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) * command/response. Pass command to the user. * ******************************************************************************/ -void rfc_process_rpn (tRFC_MCB *p_mcb, bool is_command, - bool is_request, MX_FRAME *p_frame) -{ - tPORT_STATE port_pars; - tPORT *p_port; - - p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci); - if (p_port == NULL) - { - /* This is the first command on the port */ - if (is_command) - { - - memset(&port_pars, 0, sizeof(tPORT_STATE)); - rfc_set_port_state(&port_pars, p_frame); - - PORT_PortNegInd(p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask); - } - return; - } - - if (is_command && is_request) - { - /* This is the special situation when peer just request local pars */ - port_pars = p_port->peer_port_pars; - rfc_send_rpn (p_mcb, p_frame->dlci, false, &p_port->peer_port_pars, 0); - return; +void rfc_process_rpn(tRFC_MCB* p_mcb, bool is_command, bool is_request, + MX_FRAME* p_frame) { + tPORT_STATE port_pars; + tPORT* p_port; + + p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci); + if (p_port == NULL) { + /* This is the first command on the port */ + if (is_command) { + memset(&port_pars, 0, sizeof(tPORT_STATE)); + rfc_set_port_state(&port_pars, p_frame); + + PORT_PortNegInd(p_mcb, p_frame->dlci, &port_pars, + p_frame->u.rpn.param_mask); } + return; + } + if (is_command && is_request) { + /* This is the special situation when peer just request local pars */ port_pars = p_port->peer_port_pars; + rfc_send_rpn(p_mcb, p_frame->dlci, false, &p_port->peer_port_pars, 0); + return; + } - rfc_set_port_state(&port_pars, p_frame); - - if (is_command) - { - PORT_PortNegInd (p_mcb, p_frame->dlci, &port_pars, p_frame->u.rpn.param_mask); - return; - } - - /* If we are not awaiting response just ignore it */ - p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci); - if ((p_port == NULL) || !(p_port->rfc.expected_rsp & (RFC_RSP_RPN | RFC_RSP_RPN_REPLY))) - return; - - /* If we sent a request for port parameters to the peer he is replying with */ - /* mask 0. */ - rfc_port_timer_stop (p_port); - - if (p_port->rfc.expected_rsp & RFC_RSP_RPN_REPLY) - { - p_port->rfc.expected_rsp &= ~RFC_RSP_RPN_REPLY; - - p_port->peer_port_pars = port_pars; - - if ((port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) - || (port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT))) - { - /* This is satisfactory port parameters. Set mask as it was Ok */ - p_frame->u.rpn.param_mask = RFCOMM_RPN_PM_MASK; - } - else - { - /* Current peer parameters are not good, try to fix them */ - p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT); - - p_port->rfc.expected_rsp |= RFC_RSP_RPN; - rfc_send_rpn (p_mcb, p_frame->dlci, true, &p_port->peer_port_pars, - RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; - return; - } - } - else - p_port->rfc.expected_rsp &= ~RFC_RSP_RPN; - - /* Check if all suggested parameters were accepted */ - if (((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) == - (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) - || ((p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT)) == - (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT))) - { - PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); - return; - } + port_pars = p_port->peer_port_pars; - /* If we were proposing RTR flow control try RTC flow control */ - /* If we were proposing RTC flow control try no flow control */ - /* otherwise drop the connection */ - if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) - { - /* Current peer parameters are not good, try to fix them */ - p_port->peer_port_pars.fc_type = (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT); + rfc_set_port_state(&port_pars, p_frame); - p_port->rfc.expected_rsp |= RFC_RSP_RPN; + if (is_command) { + PORT_PortNegInd(p_mcb, p_frame->dlci, &port_pars, + p_frame->u.rpn.param_mask); + return; + } - rfc_send_rpn (p_mcb, p_frame->dlci, true, &p_port->peer_port_pars, - RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; - return; - } + /* If we are not awaiting response just ignore it */ + p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci); + if ((p_port == NULL) || + !(p_port->rfc.expected_rsp & (RFC_RSP_RPN | RFC_RSP_RPN_REPLY))) + return; - /* Other side does not support flow control */ - if (p_port->peer_port_pars.fc_type == (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT)) - { - p_port->peer_port_pars.fc_type = RFCOMM_FC_OFF; - PORT_PortNegCnf (p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); + /* If we sent a request for port parameters to the peer he is replying with */ + /* mask 0. */ + rfc_port_timer_stop(p_port); + + if (p_port->rfc.expected_rsp & RFC_RSP_RPN_REPLY) { + p_port->rfc.expected_rsp &= ~RFC_RSP_RPN_REPLY; + + p_port->peer_port_pars = port_pars; + + if ((port_pars.fc_type == + (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) || + (port_pars.fc_type == + (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT))) { + /* This is satisfactory port parameters. Set mask as it was Ok */ + p_frame->u.rpn.param_mask = RFCOMM_RPN_PM_MASK; + } else { + /* Current peer parameters are not good, try to fix them */ + p_port->peer_port_pars.fc_type = + (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT); + + p_port->rfc.expected_rsp |= RFC_RSP_RPN; + rfc_send_rpn(p_mcb, p_frame->dlci, true, &p_port->peer_port_pars, + RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); + return; } + } else + p_port->rfc.expected_rsp &= ~RFC_RSP_RPN; + + /* Check if all suggested parameters were accepted */ + if (((p_frame->u.rpn.param_mask & + (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) == + (RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT)) || + ((p_frame->u.rpn.param_mask & + (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT)) == + (RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT))) { + PORT_PortNegCnf(p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); + return; + } + + /* If we were proposing RTR flow control try RTC flow control */ + /* If we were proposing RTC flow control try no flow control */ + /* otherwise drop the connection */ + if (p_port->peer_port_pars.fc_type == + (RFCOMM_FC_RTR_ON_INPUT | RFCOMM_FC_RTR_ON_OUTPUT)) { + /* Current peer parameters are not good, try to fix them */ + p_port->peer_port_pars.fc_type = + (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT); + + p_port->rfc.expected_rsp |= RFC_RSP_RPN; + + rfc_send_rpn(p_mcb, p_frame->dlci, true, &p_port->peer_port_pars, + RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); + return; + } + + /* Other side does not support flow control */ + if (p_port->peer_port_pars.fc_type == + (RFCOMM_FC_RTC_ON_INPUT | RFCOMM_FC_RTC_ON_OUTPUT)) { + p_port->peer_port_pars.fc_type = RFCOMM_FC_OFF; + PORT_PortNegCnf(p_mcb, p_port->dlci, &port_pars, RFCOMM_SUCCESS); + } } - /******************************************************************************* * * Function rfc_process_msc @@ -694,68 +673,58 @@ void rfc_process_rpn (tRFC_MCB *p_mcb, bool is_command, * Pass command to the user. * ******************************************************************************/ -void rfc_process_msc (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) -{ - tPORT_CTRL pars; - tPORT *p_port; - uint8_t modem_signals = p_frame->u.msc.signals; - bool new_peer_fc = false; - - p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci); - if (p_port == NULL) - return; +void rfc_process_msc(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) { + tPORT_CTRL pars; + tPORT* p_port; + uint8_t modem_signals = p_frame->u.msc.signals; + bool new_peer_fc = false; - pars.modem_signal = 0; + p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci); + if (p_port == NULL) return; - if (modem_signals & RFCOMM_MSC_RTC) - pars.modem_signal |= MODEM_SIGNAL_DTRDSR; + pars.modem_signal = 0; - if (modem_signals & RFCOMM_MSC_RTR) - pars.modem_signal |= MODEM_SIGNAL_RTSCTS; + if (modem_signals & RFCOMM_MSC_RTC) pars.modem_signal |= MODEM_SIGNAL_DTRDSR; - if (modem_signals & RFCOMM_MSC_IC) - pars.modem_signal |= MODEM_SIGNAL_RI; + if (modem_signals & RFCOMM_MSC_RTR) pars.modem_signal |= MODEM_SIGNAL_RTSCTS; - if (modem_signals & RFCOMM_MSC_DV) - pars.modem_signal |= MODEM_SIGNAL_DCD; + if (modem_signals & RFCOMM_MSC_IC) pars.modem_signal |= MODEM_SIGNAL_RI; - pars.fc = ((modem_signals & RFCOMM_MSC_FC) == RFCOMM_MSC_FC); + if (modem_signals & RFCOMM_MSC_DV) pars.modem_signal |= MODEM_SIGNAL_DCD; - pars.break_signal = (p_frame->u.msc.break_present) ? - p_frame->u.msc.break_duration : 0; - pars.discard_buffers = 0; - pars.break_signal_seq = RFCOMM_CTRL_BREAK_IN_SEQ; /* this is default */ + pars.fc = ((modem_signals & RFCOMM_MSC_FC) == RFCOMM_MSC_FC); - /* Check if this command is passed only to indicate flow control */ - if (is_command) - { - rfc_send_msc (p_mcb, p_frame->dlci, false, &pars); + pars.break_signal = + (p_frame->u.msc.break_present) ? p_frame->u.msc.break_duration : 0; + pars.discard_buffers = 0; + pars.break_signal_seq = RFCOMM_CTRL_BREAK_IN_SEQ; /* this is default */ - if (p_port->rfc.p_mcb->flow != PORT_FC_CREDIT) - { - /* Spec 1.1 indicates that only FC bit is used for flow control */ - p_port->peer_ctrl.fc = new_peer_fc = pars.fc; - - if (new_peer_fc != p_port->tx.peer_fc) - PORT_FlowInd (p_mcb, p_frame->dlci, (bool )!new_peer_fc); - } + /* Check if this command is passed only to indicate flow control */ + if (is_command) { + rfc_send_msc(p_mcb, p_frame->dlci, false, &pars); - PORT_ControlInd (p_mcb, p_frame->dlci, &pars); + if (p_port->rfc.p_mcb->flow != PORT_FC_CREDIT) { + /* Spec 1.1 indicates that only FC bit is used for flow control */ + p_port->peer_ctrl.fc = new_peer_fc = pars.fc; - return; + if (new_peer_fc != p_port->tx.peer_fc) + PORT_FlowInd(p_mcb, p_frame->dlci, (bool)!new_peer_fc); } - /* If we are not awaiting response just ignore it */ - if (!(p_port->rfc.expected_rsp & RFC_RSP_MSC)) - return; + PORT_ControlInd(p_mcb, p_frame->dlci, &pars); - p_port->rfc.expected_rsp &= ~RFC_RSP_MSC; + return; + } - rfc_port_timer_stop (p_port); + /* If we are not awaiting response just ignore it */ + if (!(p_port->rfc.expected_rsp & RFC_RSP_MSC)) return; - PORT_ControlCnf (p_port->rfc.p_mcb, p_port->dlci, &pars); -} + p_port->rfc.expected_rsp &= ~RFC_RSP_MSC; + rfc_port_timer_stop(p_port); + + PORT_ControlCnf(p_port->rfc.p_mcb, p_port->dlci, &pars); +} /******************************************************************************* * @@ -765,30 +734,24 @@ void rfc_process_msc (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) * Pass command to the user. * ******************************************************************************/ -void rfc_process_rls (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) -{ - tPORT *p_port; - - if (is_command) - { - PORT_LineStatusInd (p_mcb, p_frame->dlci, p_frame->u.rls.line_status); - rfc_send_rls (p_mcb, p_frame->dlci, false, p_frame->u.rls.line_status); - } - else - { - p_port = port_find_mcb_dlci_port (p_mcb, p_frame->dlci); +void rfc_process_rls(tRFC_MCB* p_mcb, bool is_command, MX_FRAME* p_frame) { + tPORT* p_port; + + if (is_command) { + PORT_LineStatusInd(p_mcb, p_frame->dlci, p_frame->u.rls.line_status); + rfc_send_rls(p_mcb, p_frame->dlci, false, p_frame->u.rls.line_status); + } else { + p_port = port_find_mcb_dlci_port(p_mcb, p_frame->dlci); - /* If we are not awaiting response just ignore it */ - if (!p_port || !(p_port->rfc.expected_rsp & RFC_RSP_RLS)) - return; + /* If we are not awaiting response just ignore it */ + if (!p_port || !(p_port->rfc.expected_rsp & RFC_RSP_RLS)) return; - p_port->rfc.expected_rsp &= ~RFC_RSP_RLS; + p_port->rfc.expected_rsp &= ~RFC_RSP_RLS; - rfc_port_timer_stop (p_port); - } + rfc_port_timer_stop(p_port); + } } - /******************************************************************************* * * Function rfc_process_nsc @@ -796,11 +759,8 @@ void rfc_process_rls (tRFC_MCB *p_mcb, bool is_command, MX_FRAME *p_frame) * Description This function handles None Supported Command frame. * ******************************************************************************/ -void rfc_process_nsc (UNUSED_ATTR tRFC_MCB *p_mcb, - UNUSED_ATTR MX_FRAME *p_frame) -{ -} - +void rfc_process_nsc(UNUSED_ATTR tRFC_MCB* p_mcb, + UNUSED_ATTR MX_FRAME* p_frame) {} /******************************************************************************* * @@ -810,9 +770,8 @@ void rfc_process_nsc (UNUSED_ATTR tRFC_MCB *p_mcb, * reply to it. Otherwise pass response to the user. * ******************************************************************************/ -void rfc_process_test_rsp(UNUSED_ATTR tRFC_MCB *p_mcb, BT_HDR *p_buf) -{ - osi_free(p_buf); +void rfc_process_test_rsp(UNUSED_ATTR tRFC_MCB* p_mcb, BT_HDR* p_buf) { + osi_free(p_buf); } /******************************************************************************* @@ -823,17 +782,14 @@ void rfc_process_test_rsp(UNUSED_ATTR tRFC_MCB *p_mcb, BT_HDR *p_buf) * to receive new information * ******************************************************************************/ -void rfc_process_fcon (tRFC_MCB *p_mcb, bool is_command) -{ - if (is_command) - { - rfc_cb.rfc.peer_rx_disabled = false; +void rfc_process_fcon(tRFC_MCB* p_mcb, bool is_command) { + if (is_command) { + rfc_cb.rfc.peer_rx_disabled = false; - rfc_send_fcon (p_mcb, false); + rfc_send_fcon(p_mcb, false); - if (!p_mcb->l2cap_congested) - PORT_FlowInd (p_mcb, 0, true); - } + if (!p_mcb->l2cap_congested) PORT_FlowInd(p_mcb, 0, true); + } } /******************************************************************************* @@ -844,20 +800,16 @@ void rfc_process_fcon (tRFC_MCB *p_mcb, bool is_command) * unable to receive new information * ******************************************************************************/ -void rfc_process_fcoff (tRFC_MCB *p_mcb, bool is_command) -{ - if (is_command) - { - rfc_cb.rfc.peer_rx_disabled = true; +void rfc_process_fcoff(tRFC_MCB* p_mcb, bool is_command) { + if (is_command) { + rfc_cb.rfc.peer_rx_disabled = true; - if (!p_mcb->l2cap_congested) - PORT_FlowInd (p_mcb, 0, false); + if (!p_mcb->l2cap_congested) PORT_FlowInd(p_mcb, 0, false); - rfc_send_fcoff (p_mcb, false); - } + rfc_send_fcoff(p_mcb, false); + } } - /******************************************************************************* * * Function rfc_process_l2cap_congestion @@ -865,22 +817,19 @@ void rfc_process_fcoff (tRFC_MCB *p_mcb, bool is_command) * Description This function handles L2CAP congestion messages * ******************************************************************************/ -void rfc_process_l2cap_congestion (tRFC_MCB *p_mcb, bool is_congested) -{ - p_mcb->l2cap_congested = is_congested; +void rfc_process_l2cap_congestion(tRFC_MCB* p_mcb, bool is_congested) { + p_mcb->l2cap_congested = is_congested; - if (!is_congested) - { - rfc_check_send_cmd(p_mcb, NULL); - } + if (!is_congested) { + rfc_check_send_cmd(p_mcb, NULL); + } - if (!rfc_cb.rfc.peer_rx_disabled) - { - if (!is_congested) - PORT_FlowInd (p_mcb, 0, true); - else - PORT_FlowInd (p_mcb, 0, false); - } + if (!rfc_cb.rfc.peer_rx_disabled) { + if (!is_congested) + PORT_FlowInd(p_mcb, 0, true); + else + PORT_FlowInd(p_mcb, 0, false); + } } /******************************************************************************* @@ -892,28 +841,24 @@ void rfc_process_l2cap_congestion (tRFC_MCB *p_mcb, bool is_congested) * ******************************************************************************/ -void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame) -{ - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_BIT_RATE) - port_pars->baud_rate = p_frame->u.rpn.baud_rate; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_DATA_BITS) - port_pars->byte_size = p_frame->u.rpn.byte_size; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_STOP_BITS) - port_pars->stop_bits = p_frame->u.rpn.stop_bits; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY) - port_pars->parity = p_frame->u.rpn.parity; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY_TYPE) - port_pars->parity_type = p_frame->u.rpn.parity_type; - if (p_frame->u.rpn.param_mask & (RFCOMM_RPN_PM_XONXOFF_ON_INPUT | - RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT | - RFCOMM_RPN_PM_RTR_ON_INPUT | - RFCOMM_RPN_PM_RTR_ON_OUTPUT | - RFCOMM_RPN_PM_RTC_ON_INPUT | - RFCOMM_RPN_PM_RTC_ON_OUTPUT)) - port_pars->fc_type = p_frame->u.rpn.fc_type; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XON_CHAR) - port_pars->xon_char = p_frame->u.rpn.xon_char; - if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XOFF_CHAR) - port_pars->xoff_char = p_frame->u.rpn.xoff_char; +void rfc_set_port_state(tPORT_STATE* port_pars, MX_FRAME* p_frame) { + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_BIT_RATE) + port_pars->baud_rate = p_frame->u.rpn.baud_rate; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_DATA_BITS) + port_pars->byte_size = p_frame->u.rpn.byte_size; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_STOP_BITS) + port_pars->stop_bits = p_frame->u.rpn.stop_bits; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY) + port_pars->parity = p_frame->u.rpn.parity; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_PARITY_TYPE) + port_pars->parity_type = p_frame->u.rpn.parity_type; + if (p_frame->u.rpn.param_mask & + (RFCOMM_RPN_PM_XONXOFF_ON_INPUT | RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT | + RFCOMM_RPN_PM_RTR_ON_INPUT | RFCOMM_RPN_PM_RTR_ON_OUTPUT | + RFCOMM_RPN_PM_RTC_ON_INPUT | RFCOMM_RPN_PM_RTC_ON_OUTPUT)) + port_pars->fc_type = p_frame->u.rpn.fc_type; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XON_CHAR) + port_pars->xon_char = p_frame->u.rpn.xon_char; + if (p_frame->u.rpn.param_mask & RFCOMM_RPN_PM_XOFF_CHAR) + port_pars->xoff_char = p_frame->u.rpn.xoff_char; } - diff --git a/stack/rfcomm/rfc_port_if.cc b/stack/rfcomm/rfc_port_if.cc index 6f8251f41..4f8f38a17 100644 --- a/stack/rfcomm/rfc_port_if.cc +++ b/stack/rfcomm/rfc_port_if.cc @@ -24,15 +24,15 @@ *****************************************************************************/ #include -#include "bt_target.h" #include "bt_common.h" -#include "rfcdefs.h" -#include "port_api.h" +#include "bt_target.h" +#include "bt_utils.h" #include "l2c_api.h" +#include "osi/include/osi.h" +#include "port_api.h" #include "port_int.h" #include "rfc_int.h" -#include "bt_utils.h" -#include "osi/include/osi.h" +#include "rfcdefs.h" tRFC_CB rfc_cb; @@ -46,12 +46,10 @@ tRFC_CB rfc_cb; * start event to the state machine. * ******************************************************************************/ -void RFCOMM_StartReq (tRFC_MCB *p_mcb) -{ - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_REQ, NULL); +void RFCOMM_StartReq(tRFC_MCB* p_mcb) { + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_START_REQ, NULL); } - /******************************************************************************* * * Function RFCOMM_StartRsp @@ -61,12 +59,10 @@ void RFCOMM_StartReq (tRFC_MCB *p_mcb) * in the control block and dispatch event to the FSM. * ******************************************************************************/ -void RFCOMM_StartRsp (tRFC_MCB *p_mcb, uint16_t result) -{ - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_START_RSP, &result); +void RFCOMM_StartRsp(tRFC_MCB* p_mcb, uint16_t result) { + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_START_RSP, &result); } - /******************************************************************************* * * Function RFCOMM_DlcEstablishReq @@ -78,26 +74,22 @@ void RFCOMM_StartRsp (tRFC_MCB *p_mcb, uint16_t result) * machine. * ******************************************************************************/ -void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, uint8_t dlci, - UNUSED_ATTR uint16_t mtu) -{ - if (p_mcb->state != RFC_MX_STATE_CONNECTED) - { - PORT_DlcEstablishCnf (p_mcb, dlci, 0, RFCOMM_ERROR); - return; - } - - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } - - rfc_port_sm_execute(p_port, RFC_EVENT_OPEN, NULL); +void RFCOMM_DlcEstablishReq(tRFC_MCB* p_mcb, uint8_t dlci, + UNUSED_ATTR uint16_t mtu) { + if (p_mcb->state != RFC_MX_STATE_CONNECTED) { + PORT_DlcEstablishCnf(p_mcb, dlci, 0, RFCOMM_ERROR); + return; + } + + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } + + rfc_port_sm_execute(p_port, RFC_EVENT_OPEN, NULL); } - /******************************************************************************* * * Function RFCOMM_DlcEstablishRsp @@ -106,25 +98,21 @@ void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, uint8_t dlci, * acks Establish Indication. * ******************************************************************************/ -void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, uint8_t dlci, - UNUSED_ATTR uint16_t mtu, uint16_t result) -{ - if ((p_mcb->state != RFC_MX_STATE_CONNECTED) && (result == RFCOMM_SUCCESS)) - { - PORT_DlcReleaseInd (p_mcb, dlci); - return; - } - - tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } - rfc_port_sm_execute(p_port, RFC_EVENT_ESTABLISH_RSP, &result); +void RFCOMM_DlcEstablishRsp(tRFC_MCB* p_mcb, uint8_t dlci, + UNUSED_ATTR uint16_t mtu, uint16_t result) { + if ((p_mcb->state != RFC_MX_STATE_CONNECTED) && (result == RFCOMM_SUCCESS)) { + PORT_DlcReleaseInd(p_mcb, dlci); + return; + } + + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } + rfc_port_sm_execute(p_port, RFC_EVENT_ESTABLISH_RSP, &result); } - /******************************************************************************* * * Function RFCOMM_ParNegReq @@ -136,52 +124,46 @@ void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, uint8_t dlci, * block. * ******************************************************************************/ -void RFCOMM_ParNegReq (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu) -{ - uint8_t flow; - uint8_t cl; - uint8_t k; - - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } - - if (p_mcb->state != RFC_MX_STATE_CONNECTED) - { - p_port->error = PORT_PAR_NEG_FAILED; - return; - } - - /* Negotiate the flow control mechanism. If flow control mechanism for */ - /* mux has not been set yet, use our default value. If it has been set, */ - /* use that value. */ - flow = (p_mcb->flow == PORT_FC_UNDEFINED) ? PORT_FC_DEFAULT : p_mcb->flow; - - /* Set convergence layer and number of credits (k) */ - if (flow == PORT_FC_CREDIT) - { - cl = RFCOMM_PN_CONV_LAYER_CBFC_I; - k = (p_port->credit_rx_max < RFCOMM_K_MAX) ? p_port->credit_rx_max : RFCOMM_K_MAX; - p_port->credit_rx = k; - } - else - { - cl = RFCOMM_PN_CONV_LAYER_TYPE_1; - k = 0; - } - - /* Send Parameter Negotiation Command UIH frame */ - p_port->rfc.expected_rsp |= RFC_RSP_PN; - - rfc_send_pn (p_mcb, dlci, true, mtu, cl, k); - - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; +void RFCOMM_ParNegReq(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu) { + uint8_t flow; + uint8_t cl; + uint8_t k; + + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } + + if (p_mcb->state != RFC_MX_STATE_CONNECTED) { + p_port->error = PORT_PAR_NEG_FAILED; + return; + } + + /* Negotiate the flow control mechanism. If flow control mechanism for */ + /* mux has not been set yet, use our default value. If it has been set, */ + /* use that value. */ + flow = (p_mcb->flow == PORT_FC_UNDEFINED) ? PORT_FC_DEFAULT : p_mcb->flow; + + /* Set convergence layer and number of credits (k) */ + if (flow == PORT_FC_CREDIT) { + cl = RFCOMM_PN_CONV_LAYER_CBFC_I; + k = (p_port->credit_rx_max < RFCOMM_K_MAX) ? p_port->credit_rx_max + : RFCOMM_K_MAX; + p_port->credit_rx = k; + } else { + cl = RFCOMM_PN_CONV_LAYER_TYPE_1; + k = 0; + } + + /* Send Parameter Negotiation Command UIH frame */ + p_port->rfc.expected_rsp |= RFC_RSP_PN; + + rfc_send_pn(p_mcb, dlci, true, mtu, cl, k); + + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); } - /******************************************************************************* * * Function RFCOMM_ParNegRsp @@ -190,16 +172,14 @@ void RFCOMM_ParNegReq (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu) * DLC parameter negotiation. * ******************************************************************************/ -void RFCOMM_ParNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uint8_t k) -{ - if (p_mcb->state != RFC_MX_STATE_CONNECTED) - return; +void RFCOMM_ParNegRsp(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, + uint8_t k) { + if (p_mcb->state != RFC_MX_STATE_CONNECTED) return; - /* Send Parameter Negotiation Response UIH frame */ - rfc_send_pn (p_mcb, dlci, false, mtu, cl, k); + /* Send Parameter Negotiation Response UIH frame */ + rfc_send_pn(p_mcb, dlci, false, mtu, cl, k); } - /******************************************************************************* * * Function RFCOMM_PortNegReq @@ -211,33 +191,28 @@ void RFCOMM_ParNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, * control block. * ******************************************************************************/ -void RFCOMM_PortNegReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars) -{ - if (p_mcb->state != RFC_MX_STATE_CONNECTED) - { - PORT_PortNegCnf (p_mcb, dlci, NULL, RFCOMM_ERROR); - return; - } - - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } - - /* Send Parameter Negotiation Command UIH frame */ - if (!p_pars) - p_port->rfc.expected_rsp |= RFC_RSP_RPN_REPLY; - else - p_port->rfc.expected_rsp |= RFC_RSP_RPN; - - rfc_send_rpn (p_mcb, dlci, true, p_pars, RFCOMM_RPN_PM_MASK); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; - +void RFCOMM_PortNegReq(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_STATE* p_pars) { + if (p_mcb->state != RFC_MX_STATE_CONNECTED) { + PORT_PortNegCnf(p_mcb, dlci, NULL, RFCOMM_ERROR); + return; + } + + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } + + /* Send Parameter Negotiation Command UIH frame */ + if (!p_pars) + p_port->rfc.expected_rsp |= RFC_RSP_RPN_REPLY; + else + p_port->rfc.expected_rsp |= RFC_RSP_RPN; + + rfc_send_rpn(p_mcb, dlci, true, p_pars, RFCOMM_RPN_PM_MASK); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); } - /******************************************************************************* * * Function RFCOMM_PortNegRsp @@ -246,16 +221,13 @@ void RFCOMM_PortNegReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars) * Port parameters negotiation. * ******************************************************************************/ -void RFCOMM_PortNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, - uint16_t param_mask) -{ - if (p_mcb->state != RFC_MX_STATE_CONNECTED) - return; +void RFCOMM_PortNegRsp(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_STATE* p_pars, + uint16_t param_mask) { + if (p_mcb->state != RFC_MX_STATE_CONNECTED) return; - rfc_send_rpn (p_mcb, dlci, false, p_pars, param_mask); + rfc_send_rpn(p_mcb, dlci, false, p_pars, param_mask); } - /******************************************************************************* * * Function RFCOMM_ControlReq @@ -264,29 +236,25 @@ void RFCOMM_PortNegRsp (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_STATE *p_pars, * parameters to remote port emulation entity. * ******************************************************************************/ -void RFCOMM_ControlReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars) -{ - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } +void RFCOMM_ControlReq(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* p_pars) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } - if ((p_port->state != PORT_STATE_OPENED) - || (p_port->rfc.state != RFC_STATE_OPENED)) - return; + if ((p_port->state != PORT_STATE_OPENED) || + (p_port->rfc.state != RFC_STATE_OPENED)) + return; - p_port->port_ctrl |= PORT_CTRL_REQ_SENT; + p_port->port_ctrl |= PORT_CTRL_REQ_SENT; - p_port->rfc.expected_rsp |= RFC_RSP_MSC; - - rfc_send_msc (p_mcb, dlci, true, p_pars); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; + p_port->rfc.expected_rsp |= RFC_RSP_MSC; + rfc_send_msc(p_mcb, dlci, true, p_pars); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); } - /******************************************************************************* * * Function RFCOMM_FlowReq @@ -296,29 +264,25 @@ void RFCOMM_ControlReq (tRFC_MCB *p_mcb, uint8_t dlci, tPORT_CTRL *p_pars) * port can accept more data. * ******************************************************************************/ -void RFCOMM_FlowReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t enable) -{ - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } +void RFCOMM_FlowReq(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t enable) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } - if ((p_port->state != PORT_STATE_OPENED) - || (p_port->rfc.state != RFC_STATE_OPENED)) - return; + if ((p_port->state != PORT_STATE_OPENED) || + (p_port->rfc.state != RFC_STATE_OPENED)) + return; - p_port->local_ctrl.fc = !enable; + p_port->local_ctrl.fc = !enable; - p_port->rfc.expected_rsp |= RFC_RSP_MSC; - - rfc_send_msc (p_mcb, dlci, true, &p_port->local_ctrl); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT) ; + p_port->rfc.expected_rsp |= RFC_RSP_MSC; + rfc_send_msc(p_mcb, dlci, true, &p_port->local_ctrl); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); } - /******************************************************************************* * * Function RFCOMM_LineStatusReq @@ -327,25 +291,22 @@ void RFCOMM_FlowReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t enable) * status should be delivered to the peer. * ******************************************************************************/ -void RFCOMM_LineStatusReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t status) -{ - tPORT *p_port = port_find_mcb_dlci_port(p_mcb, dlci); - if (p_port == NULL) { - RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, - dlci); - return; - } - - if ((p_port->state != PORT_STATE_OPENED) - || (p_port->rfc.state != RFC_STATE_OPENED)) - return; - - p_port->rfc.expected_rsp |= RFC_RSP_RLS; - - rfc_send_rls (p_mcb, dlci, true, status); - rfc_port_timer_start (p_port, RFC_T2_TIMEOUT); -} +void RFCOMM_LineStatusReq(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t status) { + tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci); + if (p_port == NULL) { + RFCOMM_TRACE_WARNING("%s Unable to find DLCI port dlci:%d", __func__, dlci); + return; + } + + if ((p_port->state != PORT_STATE_OPENED) || + (p_port->rfc.state != RFC_STATE_OPENED)) + return; + p_port->rfc.expected_rsp |= RFC_RSP_RLS; + + rfc_send_rls(p_mcb, dlci, true, status); + rfc_port_timer_start(p_port, RFC_T2_TIMEOUT); +} /******************************************************************************* * @@ -354,12 +315,10 @@ void RFCOMM_LineStatusReq (tRFC_MCB *p_mcb, uint8_t dlci, uint8_t status) * Description This function is called by the PORT unit to close DLC * ******************************************************************************/ -void RFCOMM_DlcReleaseReq (tRFC_MCB *p_mcb, uint8_t dlci) -{ - rfc_port_sm_execute(port_find_mcb_dlci_port (p_mcb, dlci), RFC_EVENT_CLOSE, 0); +void RFCOMM_DlcReleaseReq(tRFC_MCB* p_mcb, uint8_t dlci) { + rfc_port_sm_execute(port_find_mcb_dlci_port(p_mcb, dlci), RFC_EVENT_CLOSE, 0); } - /******************************************************************************* * * Function RFCOMM_DataReq @@ -367,9 +326,7 @@ void RFCOMM_DlcReleaseReq (tRFC_MCB *p_mcb, uint8_t dlci) * Description This function is called by the user app to send data buffer * ******************************************************************************/ -void RFCOMM_DataReq (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf) -{ - rfc_port_sm_execute(port_find_mcb_dlci_port (p_mcb, dlci), RFC_EVENT_DATA, p_buf); +void RFCOMM_DataReq(tRFC_MCB* p_mcb, uint8_t dlci, BT_HDR* p_buf) { + rfc_port_sm_execute(port_find_mcb_dlci_port(p_mcb, dlci), RFC_EVENT_DATA, + p_buf); } - - diff --git a/stack/rfcomm/rfc_ts_frames.cc b/stack/rfcomm/rfc_ts_frames.cc index 3cf9816ce..aa4138fa5 100644 --- a/stack/rfcomm/rfc_ts_frames.cc +++ b/stack/rfcomm/rfc_ts_frames.cc @@ -23,13 +23,13 @@ ******************************************************************************/ #include -#include "bt_target.h" #include "bt_common.h" -#include "rfcdefs.h" -#include "port_api.h" +#include "bt_target.h" #include "l2c_api.h" +#include "port_api.h" #include "port_int.h" #include "rfc_int.h" +#include "rfcdefs.h" /******************************************************************************* * @@ -38,28 +38,27 @@ * Description This function sends SABME frame. * ******************************************************************************/ -void rfc_send_sabme (tRFC_MCB *p_mcb, uint8_t dlci) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_sabme(tRFC_MCB* p_mcb, uint8_t dlci) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_data = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_data = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* SABME frame, command, PF = 1, dlci */ - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_SABME | RFCOMM_PF; - *p_data++ = RFCOMM_EA | 0; + /* SABME frame, command, PF = 1, dlci */ + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_SABME | RFCOMM_PF; + *p_data++ = RFCOMM_EA | 0; - *p_data = RFCOMM_SABME_FCS ((uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); + *p_data = + RFCOMM_SABME_FCS((uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); - p_buf->len = 4; + p_buf->len = 4; - rfc_check_send_cmd(p_mcb, p_buf); + rfc_check_send_cmd(p_mcb, p_buf); } - /******************************************************************************* * * Function rfc_send_ua @@ -67,28 +66,26 @@ void rfc_send_sabme (tRFC_MCB *p_mcb, uint8_t dlci) * Description This function sends UA frame. * ******************************************************************************/ -void rfc_send_ua (tRFC_MCB *p_mcb, uint8_t dlci) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, false); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_ua(tRFC_MCB* p_mcb, uint8_t dlci) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, false); + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_data = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_data = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* ua frame, response, PF = 1, dlci */ - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_UA | RFCOMM_PF; - *p_data++ = RFCOMM_EA | 0; + /* ua frame, response, PF = 1, dlci */ + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_UA | RFCOMM_PF; + *p_data++ = RFCOMM_EA | 0; - *p_data = RFCOMM_UA_FCS ((uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); + *p_data = RFCOMM_UA_FCS((uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); - p_buf->len = 4; + p_buf->len = 4; - rfc_check_send_cmd(p_mcb, p_buf); + rfc_check_send_cmd(p_mcb, p_buf); } - /******************************************************************************* * * Function rfc_send_dm @@ -96,28 +93,26 @@ void rfc_send_ua (tRFC_MCB *p_mcb, uint8_t dlci) * Description This function sends DM frame. * ******************************************************************************/ -void rfc_send_dm (tRFC_MCB *p_mcb, uint8_t dlci, bool pf) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, false); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_dm(tRFC_MCB* p_mcb, uint8_t dlci, bool pf) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, false); + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_data = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_data = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* DM frame, response, PF = 1, dlci */ - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_DM | ((pf) ? RFCOMM_PF : 0); - *p_data++ = RFCOMM_EA | 0; + /* DM frame, response, PF = 1, dlci */ + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_DM | ((pf) ? RFCOMM_PF : 0); + *p_data++ = RFCOMM_EA | 0; - *p_data = RFCOMM_DM_FCS ((uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); + *p_data = RFCOMM_DM_FCS((uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); - p_buf->len = 4; + p_buf->len = 4; - rfc_check_send_cmd(p_mcb, p_buf); + rfc_check_send_cmd(p_mcb, p_buf); } - /******************************************************************************* * * Function rfc_send_disc @@ -125,28 +120,26 @@ void rfc_send_dm (tRFC_MCB *p_mcb, uint8_t dlci, bool pf) * Description This function sends DISC frame. * ******************************************************************************/ -void rfc_send_disc (tRFC_MCB *p_mcb, uint8_t dlci) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_disc(tRFC_MCB* p_mcb, uint8_t dlci) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_data = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p_buf->offset = L2CAP_MIN_OFFSET; + p_data = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* DISC frame, command, PF = 1, dlci */ - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_DISC | RFCOMM_PF; - *p_data++ = RFCOMM_EA | 0; + /* DISC frame, command, PF = 1, dlci */ + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_DISC | RFCOMM_PF; + *p_data++ = RFCOMM_EA | 0; - *p_data = RFCOMM_DISC_FCS ((uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); + *p_data = RFCOMM_DISC_FCS((uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET, cr, dlci); - p_buf->len = 4; + p_buf->len = 4; - rfc_check_send_cmd(p_mcb, p_buf); + rfc_check_send_cmd(p_mcb, p_buf); } - /******************************************************************************* * * Function rfc_send_buf_uih @@ -154,61 +147,50 @@ void rfc_send_disc (tRFC_MCB *p_mcb, uint8_t dlci) * Description This function sends UIH frame. * ******************************************************************************/ -void rfc_send_buf_uih (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); - uint8_t credits; - - p_buf->offset -= RFCOMM_CTRL_FRAME_LEN; - if (p_buf->len > 127) - p_buf->offset--; - - if (dlci) - credits = (uint8_t)p_buf->layer_specific; - else - credits = 0; - - if (credits) - p_buf->offset--; - - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - - /* UIH frame, command, PF = 0, dlci */ - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_UIH | ((credits) ? RFCOMM_PF : 0); - if (p_buf->len <= 127) - { - *p_data++ = RFCOMM_EA | (p_buf->len << 1); - p_buf->len += 3; - } - else - { - *p_data++ = (p_buf->len & 0x7f) << 1; - *p_data++ = p_buf->len >> RFCOMM_SHIFT_LENGTH2; - p_buf->len += 4; - } - - if (credits) - { - *p_data++ = credits; - p_buf->len++; - } - - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len++; - - *p_data = RFCOMM_UIH_FCS ((uint8_t *)(p_buf + 1) + p_buf->offset, dlci); - - if (dlci == RFCOMM_MX_DLCI) - { - rfc_check_send_cmd(p_mcb, p_buf); - } - else - { - L2CA_DataWrite (p_mcb->lcid, p_buf); - } -} +void rfc_send_buf_uih(tRFC_MCB* p_mcb, uint8_t dlci, BT_HDR* p_buf) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); + uint8_t credits; + p_buf->offset -= RFCOMM_CTRL_FRAME_LEN; + if (p_buf->len > 127) p_buf->offset--; + + if (dlci) + credits = (uint8_t)p_buf->layer_specific; + else + credits = 0; + + if (credits) p_buf->offset--; + + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + + /* UIH frame, command, PF = 0, dlci */ + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_UIH | ((credits) ? RFCOMM_PF : 0); + if (p_buf->len <= 127) { + *p_data++ = RFCOMM_EA | (p_buf->len << 1); + p_buf->len += 3; + } else { + *p_data++ = (p_buf->len & 0x7f) << 1; + *p_data++ = p_buf->len >> RFCOMM_SHIFT_LENGTH2; + p_buf->len += 4; + } + + if (credits) { + *p_data++ = credits; + p_buf->len++; + } + + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len++; + + *p_data = RFCOMM_UIH_FCS((uint8_t*)(p_buf + 1) + p_buf->offset, dlci); + + if (dlci == RFCOMM_MX_DLCI) { + rfc_check_send_cmd(p_mcb, p_buf); + } else { + L2CA_DataWrite(p_mcb->lcid, p_buf); + } +} /******************************************************************************* * @@ -217,41 +199,42 @@ void rfc_send_buf_uih (tRFC_MCB *p_mcb, uint8_t dlci, BT_HDR *p_buf) * Description This function sends DLC Parameters Negotiation Frame. * ******************************************************************************/ -void rfc_send_pn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint16_t mtu, uint8_t cl, uint8_t k) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); - - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_PN; - *p_data++ = RFCOMM_EA | (RFCOMM_MX_PN_LEN << 1); - - *p_data++ = dlci; - *p_data++ = RFCOMM_PN_FRAM_TYPE_UIH | cl; - - /* It appeared that we need to reply with the same priority bits as we received. - ** We will use the fact that we reply in the same context so rx_frame can still be used. - */ - if (is_command) - *p_data++ = RFCOMM_PN_PRIORITY_0; - else - *p_data++ = rfc_cb.rfc.rx_frame.u.pn.priority; - - *p_data++ = RFCOMM_T1_DSEC; - *p_data++ = mtu & 0xFF; - *p_data++ = mtu >> 8; - *p_data++ = RFCOMM_N2; - *p_data = k; - - /* Total length is sizeof PN data + mx header 2 */ - p_buf->len = RFCOMM_MX_PN_LEN + 2; - - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); +void rfc_send_pn(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, uint16_t mtu, + uint8_t cl, uint8_t k) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); + + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_PN; + *p_data++ = RFCOMM_EA | (RFCOMM_MX_PN_LEN << 1); + + *p_data++ = dlci; + *p_data++ = RFCOMM_PN_FRAM_TYPE_UIH | cl; + + /* It appeared that we need to reply with the same priority bits as we + *received. + ** We will use the fact that we reply in the same context so rx_frame can + *still be used. + */ + if (is_command) + *p_data++ = RFCOMM_PN_PRIORITY_0; + else + *p_data++ = rfc_cb.rfc.rx_frame.u.pn.priority; + + *p_data++ = RFCOMM_T1_DSEC; + *p_data++ = mtu & 0xFF; + *p_data++ = mtu >> 8; + *p_data++ = RFCOMM_N2; + *p_data = k; + + /* Total length is sizeof PN data + mx header 2 */ + p_buf->len = RFCOMM_MX_PN_LEN + 2; + + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_fcon @@ -259,24 +242,22 @@ void rfc_send_pn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint16_t mt * Description This function sends Flow Control On Command. * ******************************************************************************/ -void rfc_send_fcon (tRFC_MCB *p_mcb, bool is_command) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_fcon(tRFC_MCB* p_mcb, bool is_command) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCON; - *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCON_LEN << 1); + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCON; + *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCON_LEN << 1); - /* Total length is sizeof FCON data + mx header 2 */ - p_buf->len = RFCOMM_MX_FCON_LEN + 2; + /* Total length is sizeof FCON data + mx header 2 */ + p_buf->len = RFCOMM_MX_FCON_LEN + 2; - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_fcoff @@ -284,24 +265,22 @@ void rfc_send_fcon (tRFC_MCB *p_mcb, bool is_command) * Description This function sends Flow Control Off Command. * ******************************************************************************/ -void rfc_send_fcoff (tRFC_MCB *p_mcb, bool is_command) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_fcoff(tRFC_MCB* p_mcb, bool is_command) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCOFF; - *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCOFF_LEN << 1); + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_FCOFF; + *p_data++ = RFCOMM_EA | (RFCOMM_MX_FCOFF_LEN << 1); - /* Total length is sizeof FCOFF data + mx header 2 */ - p_buf->len = RFCOMM_MX_FCOFF_LEN + 2; + /* Total length is sizeof FCOFF data + mx header 2 */ + p_buf->len = RFCOMM_MX_FCOFF_LEN + 2; - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_msc @@ -309,50 +288,46 @@ void rfc_send_fcoff (tRFC_MCB *p_mcb, bool is_command) * Description This function sends Modem Status Command Frame. * ******************************************************************************/ -void rfc_send_msc (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, - tPORT_CTRL *p_pars) -{ - uint8_t *p_data; - uint8_t signals; - uint8_t break_duration; - uint8_t len; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); - - signals = p_pars->modem_signal; - break_duration = p_pars->break_signal; - - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - - if (break_duration) - len = RFCOMM_MX_MSC_LEN_WITH_BREAK; - else - len = RFCOMM_MX_MSC_LEN_NO_BREAK; - - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_MSC; - *p_data++ = RFCOMM_EA | (len << 1); - - *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_EA | - ((p_pars->fc) ? RFCOMM_MSC_FC : 0) | - ((signals & MODEM_SIGNAL_DTRDSR) ? RFCOMM_MSC_RTC : 0) | - ((signals & MODEM_SIGNAL_RTSCTS) ? RFCOMM_MSC_RTR : 0) | - ((signals & MODEM_SIGNAL_RI) ? RFCOMM_MSC_IC : 0) | - ((signals & MODEM_SIGNAL_DCD) ? RFCOMM_MSC_DV : 0); - - if (break_duration) - { - *p_data++ = RFCOMM_EA | RFCOMM_MSC_BREAK_PRESENT_MASK | - (break_duration << RFCOMM_MSC_SHIFT_BREAK); - } - - /* Total length is sizeof MSC data + mx header 2 */ - p_buf->len = len + 2; - - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); +void rfc_send_msc(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + tPORT_CTRL* p_pars) { + uint8_t* p_data; + uint8_t signals; + uint8_t break_duration; + uint8_t len; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); + + signals = p_pars->modem_signal; + break_duration = p_pars->break_signal; + + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + + if (break_duration) + len = RFCOMM_MX_MSC_LEN_WITH_BREAK; + else + len = RFCOMM_MX_MSC_LEN_NO_BREAK; + + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_MSC; + *p_data++ = RFCOMM_EA | (len << 1); + + *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_EA | ((p_pars->fc) ? RFCOMM_MSC_FC : 0) | + ((signals & MODEM_SIGNAL_DTRDSR) ? RFCOMM_MSC_RTC : 0) | + ((signals & MODEM_SIGNAL_RTSCTS) ? RFCOMM_MSC_RTR : 0) | + ((signals & MODEM_SIGNAL_RI) ? RFCOMM_MSC_IC : 0) | + ((signals & MODEM_SIGNAL_DCD) ? RFCOMM_MSC_DV : 0); + + if (break_duration) { + *p_data++ = RFCOMM_EA | RFCOMM_MSC_BREAK_PRESENT_MASK | + (break_duration << RFCOMM_MSC_SHIFT_BREAK); + } + + /* Total length is sizeof MSC data + mx header 2 */ + p_buf->len = len + 2; + + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_rls @@ -360,27 +335,26 @@ void rfc_send_msc (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, * Description This function sends Remote Line Status Command Frame. * ******************************************************************************/ -void rfc_send_rls (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint8_t status) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_rls(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + uint8_t status) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RLS; - *p_data++ = RFCOMM_EA | (RFCOMM_MX_RLS_LEN << 1); + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RLS; + *p_data++ = RFCOMM_EA | (RFCOMM_MX_RLS_LEN << 1); - *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_RLS_ERROR | status; + *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_RLS_ERROR | status; - /* Total length is sizeof RLS data + mx header 2 */ - p_buf->len = RFCOMM_MX_RLS_LEN + 2; + /* Total length is sizeof RLS data + mx header 2 */ + p_buf->len = RFCOMM_MX_RLS_LEN + 2; - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_nsc @@ -388,28 +362,26 @@ void rfc_send_rls (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, uint8_t st * Description This function sends Non Supported Command Response. * ******************************************************************************/ -void rfc_send_nsc (tRFC_MCB *p_mcb) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_nsc(tRFC_MCB* p_mcb) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(false) | RFCOMM_MX_NSC; - *p_data++ = RFCOMM_EA | (RFCOMM_MX_NSC_LEN << 1); + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(false) | RFCOMM_MX_NSC; + *p_data++ = RFCOMM_EA | (RFCOMM_MX_NSC_LEN << 1); - *p_data++ = rfc_cb.rfc.rx_frame.ea | - (rfc_cb.rfc.rx_frame.cr << RFCOMM_SHIFT_CR) | - rfc_cb.rfc.rx_frame.type; + *p_data++ = rfc_cb.rfc.rx_frame.ea | + (rfc_cb.rfc.rx_frame.cr << RFCOMM_SHIFT_CR) | + rfc_cb.rfc.rx_frame.type; - /* Total length is sizeof NSC data + mx header 2 */ - p_buf->len = RFCOMM_MX_NSC_LEN + 2; + /* Total length is sizeof NSC data + mx header 2 */ + p_buf->len = RFCOMM_MX_NSC_LEN + 2; - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } - /******************************************************************************* * * Function rfc_send_rpn @@ -417,48 +389,43 @@ void rfc_send_nsc (tRFC_MCB *p_mcb) * Description This function sends Remote Port Negotiation Command * ******************************************************************************/ -void rfc_send_rpn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, - tPORT_STATE *p_pars, uint16_t mask) -{ - uint8_t *p_data; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); - - p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RPN; - - if (!p_pars) - { - *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_REQ_LEN << 1); - - *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); - - p_buf->len = RFCOMM_MX_RPN_REQ_LEN + 2; - } - else - { - *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_LEN << 1); - - *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = p_pars->baud_rate; - *p_data++ = (p_pars->byte_size << RFCOMM_RPN_BITS_SHIFT) - | (p_pars->stop_bits << RFCOMM_RPN_STOP_BITS_SHIFT) - | (p_pars->parity << RFCOMM_RPN_PARITY_SHIFT) - | (p_pars->parity_type << RFCOMM_RPN_PARITY_TYPE_SHIFT); - *p_data++ = p_pars->fc_type; - *p_data++ = p_pars->xon_char; - *p_data++ = p_pars->xoff_char; - *p_data++ = (mask & 0xFF); - *p_data++ = (mask >> 8); - - /* Total length is sizeof RPN data + mx header 2 */ - p_buf->len = RFCOMM_MX_RPN_LEN + 2; - } - - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); -} +void rfc_send_rpn(tRFC_MCB* p_mcb, uint8_t dlci, bool is_command, + tPORT_STATE* p_pars, uint16_t mask) { + uint8_t* p_data; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); + + p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_RPN; + + if (!p_pars) { + *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_REQ_LEN << 1); + + *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); + p_buf->len = RFCOMM_MX_RPN_REQ_LEN + 2; + } else { + *p_data++ = RFCOMM_EA | (RFCOMM_MX_RPN_LEN << 1); + + *p_data++ = RFCOMM_EA | RFCOMM_CR_MASK | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = p_pars->baud_rate; + *p_data++ = (p_pars->byte_size << RFCOMM_RPN_BITS_SHIFT) | + (p_pars->stop_bits << RFCOMM_RPN_STOP_BITS_SHIFT) | + (p_pars->parity << RFCOMM_RPN_PARITY_SHIFT) | + (p_pars->parity_type << RFCOMM_RPN_PARITY_TYPE_SHIFT); + *p_data++ = p_pars->fc_type; + *p_data++ = p_pars->xon_char; + *p_data++ = p_pars->xoff_char; + *p_data++ = (mask & 0xFF); + *p_data++ = (mask >> 8); + + /* Total length is sizeof RPN data + mx header 2 */ + p_buf->len = RFCOMM_MX_RPN_LEN + 2; + } + + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); +} /******************************************************************************* * @@ -467,37 +434,36 @@ void rfc_send_rpn (tRFC_MCB *p_mcb, uint8_t dlci, bool is_command, * Description This function sends Test frame. * ******************************************************************************/ -void rfc_send_test (tRFC_MCB *p_mcb, bool is_command, BT_HDR *p_buf) -{ - /* Shift buffer to give space for header */ - if (p_buf->offset < (L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2)) - { - uint8_t *p_src = (uint8_t *) (p_buf + 1) + p_buf->offset + p_buf->len - 1; - BT_HDR *p_new_buf = (BT_HDR *) osi_malloc(p_buf->len + (L2CAP_MIN_OFFSET + - RFCOMM_MIN_OFFSET + 2 + sizeof(BT_HDR) + 1)); +void rfc_send_test(tRFC_MCB* p_mcb, bool is_command, BT_HDR* p_buf) { + /* Shift buffer to give space for header */ + if (p_buf->offset < (L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2)) { + uint8_t* p_src = (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len - 1; + BT_HDR* p_new_buf = + (BT_HDR*)osi_malloc(p_buf->len + (L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + + 2 + sizeof(BT_HDR) + 1)); - p_new_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2; - p_new_buf->len = p_buf->len; + p_new_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2; + p_new_buf->len = p_buf->len; - uint8_t *p_dest = (uint8_t *) (p_new_buf + 1) + p_new_buf->offset + p_new_buf->len - 1; + uint8_t* p_dest = + (uint8_t*)(p_new_buf + 1) + p_new_buf->offset + p_new_buf->len - 1; - for (uint16_t xx = 0; xx < p_buf->len; xx++) - *p_dest-- = *p_src--; + for (uint16_t xx = 0; xx < p_buf->len; xx++) *p_dest-- = *p_src--; - osi_free(p_buf); - p_buf = p_new_buf; - } + osi_free(p_buf); + p_buf = p_new_buf; + } - /* Adjust offset by number of bytes we are going to fill */ - p_buf->offset -= 2; - uint8_t *p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + /* Adjust offset by number of bytes we are going to fill */ + p_buf->offset -= 2; + uint8_t* p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_TEST; - *p_data++ = RFCOMM_EA | (p_buf->len << 1); + *p_data++ = RFCOMM_EA | RFCOMM_I_CR(is_command) | RFCOMM_MX_TEST; + *p_data++ = RFCOMM_EA | (p_buf->len << 1); - p_buf->len += 2; + p_buf->len += 2; - rfc_send_buf_uih (p_mcb, RFCOMM_MX_DLCI, p_buf); + rfc_send_buf_uih(p_mcb, RFCOMM_MX_DLCI, p_buf); } /******************************************************************************* @@ -507,27 +473,25 @@ void rfc_send_test (tRFC_MCB *p_mcb, bool is_command, BT_HDR *p_buf) * Description This function sends a flow control credit in UIH frame. * ******************************************************************************/ -void rfc_send_credit(tRFC_MCB *p_mcb, uint8_t dlci, uint8_t credit) -{ - uint8_t *p_data; - uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); - BT_HDR *p_buf = (BT_HDR *)osi_malloc(RFCOMM_CMD_BUF_SIZE); +void rfc_send_credit(tRFC_MCB* p_mcb, uint8_t dlci, uint8_t credit) { + uint8_t* p_data; + uint8_t cr = RFCOMM_CR(p_mcb->is_initiator, true); + BT_HDR* p_buf = (BT_HDR*)osi_malloc(RFCOMM_CMD_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; + p_buf->offset = L2CAP_MIN_OFFSET; + p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; - *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); - *p_data++ = RFCOMM_UIH | RFCOMM_PF; - *p_data++ = RFCOMM_EA | 0; - *p_data++ = credit; - *p_data = RFCOMM_UIH_FCS ((uint8_t *)(p_buf + 1) + p_buf->offset, dlci); + *p_data++ = RFCOMM_EA | cr | (dlci << RFCOMM_SHIFT_DLCI); + *p_data++ = RFCOMM_UIH | RFCOMM_PF; + *p_data++ = RFCOMM_EA | 0; + *p_data++ = credit; + *p_data = RFCOMM_UIH_FCS((uint8_t*)(p_buf + 1) + p_buf->offset, dlci); - p_buf->len = 5; + p_buf->len = 5; - rfc_check_send_cmd(p_mcb, p_buf); + rfc_check_send_cmd(p_mcb, p_buf); } - /******************************************************************************* * * Function rfc_parse_data @@ -535,125 +499,103 @@ void rfc_send_credit(tRFC_MCB *p_mcb, uint8_t dlci, uint8_t credit) * Description This function processes data packet received from L2CAP * ******************************************************************************/ -uint8_t rfc_parse_data (tRFC_MCB *p_mcb, MX_FRAME *p_frame, BT_HDR *p_buf) -{ - uint8_t ead, eal, fcs; - uint8_t *p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint8_t *p_start = p_data; - uint16_t len; - - if (p_buf->len < RFCOMM_CTRL_FRAME_LEN) - { - RFCOMM_TRACE_ERROR ("Bad Length1: %d", p_buf->len); - return (RFC_EVENT_BAD_FRAME); - } +uint8_t rfc_parse_data(tRFC_MCB* p_mcb, MX_FRAME* p_frame, BT_HDR* p_buf) { + uint8_t ead, eal, fcs; + uint8_t* p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint8_t* p_start = p_data; + uint16_t len; + + if (p_buf->len < RFCOMM_CTRL_FRAME_LEN) { + RFCOMM_TRACE_ERROR("Bad Length1: %d", p_buf->len); + return (RFC_EVENT_BAD_FRAME); + } - RFCOMM_PARSE_CTRL_FIELD (ead, p_frame->cr, p_frame->dlci, p_data); - if( !ead ) - { - RFCOMM_TRACE_ERROR ("Bad Address(EA must be 1)"); - return (RFC_EVENT_BAD_FRAME); - } - RFCOMM_PARSE_TYPE_FIELD (p_frame->type, p_frame->pf, p_data); - RFCOMM_PARSE_LEN_FIELD (eal, len, p_data); - - p_buf->len -= (3 + !ead + !eal + 1); /* Additional 1 for FCS */ - p_buf->offset += (3 + !ead + !eal); - - /* handle credit if credit based flow control */ - if ((p_mcb->flow == PORT_FC_CREDIT) && (p_frame->type == RFCOMM_UIH) && - (p_frame->dlci != RFCOMM_MX_DLCI) && (p_frame->pf == 1)) - { - p_frame->credit = *p_data++; - p_buf->len--; - p_buf->offset++; - } - else - p_frame->credit = 0; - - if (p_buf->len != len) - { - RFCOMM_TRACE_ERROR ("Bad Length2 %d %d", p_buf->len, len); - return (RFC_EVENT_BAD_FRAME); - } + RFCOMM_PARSE_CTRL_FIELD(ead, p_frame->cr, p_frame->dlci, p_data); + if (!ead) { + RFCOMM_TRACE_ERROR("Bad Address(EA must be 1)"); + return (RFC_EVENT_BAD_FRAME); + } + RFCOMM_PARSE_TYPE_FIELD(p_frame->type, p_frame->pf, p_data); + RFCOMM_PARSE_LEN_FIELD(eal, len, p_data); + + p_buf->len -= (3 + !ead + !eal + 1); /* Additional 1 for FCS */ + p_buf->offset += (3 + !ead + !eal); + + /* handle credit if credit based flow control */ + if ((p_mcb->flow == PORT_FC_CREDIT) && (p_frame->type == RFCOMM_UIH) && + (p_frame->dlci != RFCOMM_MX_DLCI) && (p_frame->pf == 1)) { + p_frame->credit = *p_data++; + p_buf->len--; + p_buf->offset++; + } else + p_frame->credit = 0; + + if (p_buf->len != len) { + RFCOMM_TRACE_ERROR("Bad Length2 %d %d", p_buf->len, len); + return (RFC_EVENT_BAD_FRAME); + } - fcs = *(p_data + len); + fcs = *(p_data + len); - /* All control frames that we are sending are sent with P=1, expect */ - /* reply with F=1 */ - /* According to TS 07.10 spec ivalid frames are discarded without */ - /* notification to the sender */ - switch (p_frame->type) - { + /* All control frames that we are sending are sent with P=1, expect */ + /* reply with F=1 */ + /* According to TS 07.10 spec ivalid frames are discarded without */ + /* notification to the sender */ + switch (p_frame->type) { case RFCOMM_SABME: - if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr) - || !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci) - || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) - { - RFCOMM_TRACE_ERROR ("Bad SABME"); - return (RFC_EVENT_BAD_FRAME); - } - else - return (RFC_EVENT_SABME); + if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr) || + !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci) || + !rfc_check_fcs(RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) { + RFCOMM_TRACE_ERROR("Bad SABME"); + return (RFC_EVENT_BAD_FRAME); + } else + return (RFC_EVENT_SABME); case RFCOMM_UA: - if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr) - || !p_frame->pf || len || !RFCOMM_VALID_DLCI (p_frame->dlci) - || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) - { - RFCOMM_TRACE_ERROR ("Bad UA"); - return (RFC_EVENT_BAD_FRAME); - } - else - return (RFC_EVENT_UA); + if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr) || + !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci) || + !rfc_check_fcs(RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) { + RFCOMM_TRACE_ERROR("Bad UA"); + return (RFC_EVENT_BAD_FRAME); + } else + return (RFC_EVENT_UA); case RFCOMM_DM: - if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr) - || len || !RFCOMM_VALID_DLCI(p_frame->dlci) - || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) - { - RFCOMM_TRACE_ERROR ("Bad DM"); - return (RFC_EVENT_BAD_FRAME); - } - else - return (RFC_EVENT_DM); + if (RFCOMM_FRAME_IS_CMD(p_mcb->is_initiator, p_frame->cr) || len || + !RFCOMM_VALID_DLCI(p_frame->dlci) || + !rfc_check_fcs(RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) { + RFCOMM_TRACE_ERROR("Bad DM"); + return (RFC_EVENT_BAD_FRAME); + } else + return (RFC_EVENT_DM); case RFCOMM_DISC: - if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr) - || !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci) - || !rfc_check_fcs (RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) - { - RFCOMM_TRACE_ERROR ("Bad DISC"); - return (RFC_EVENT_BAD_FRAME); - } - else - return (RFC_EVENT_DISC); + if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr) || + !p_frame->pf || len || !RFCOMM_VALID_DLCI(p_frame->dlci) || + !rfc_check_fcs(RFCOMM_CTRL_FRAME_LEN, p_start, fcs)) { + RFCOMM_TRACE_ERROR("Bad DISC"); + return (RFC_EVENT_BAD_FRAME); + } else + return (RFC_EVENT_DISC); case RFCOMM_UIH: - if (!RFCOMM_VALID_DLCI(p_frame->dlci)) - { - RFCOMM_TRACE_ERROR ("Bad UIH - invalid DLCI"); - return (RFC_EVENT_BAD_FRAME); - } - else if (!rfc_check_fcs (2, p_start, fcs)) - { - RFCOMM_TRACE_ERROR ("Bad UIH - FCS"); - return (RFC_EVENT_BAD_FRAME); - } - else if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)) - { - /* we assume that this is ok to allow bad implementations to work */ - RFCOMM_TRACE_ERROR ("Bad UIH - response"); - return (RFC_EVENT_UIH); - } - else - return (RFC_EVENT_UIH); - } - - return (RFC_EVENT_BAD_FRAME); + if (!RFCOMM_VALID_DLCI(p_frame->dlci)) { + RFCOMM_TRACE_ERROR("Bad UIH - invalid DLCI"); + return (RFC_EVENT_BAD_FRAME); + } else if (!rfc_check_fcs(2, p_start, fcs)) { + RFCOMM_TRACE_ERROR("Bad UIH - FCS"); + return (RFC_EVENT_BAD_FRAME); + } else if (RFCOMM_FRAME_IS_RSP(p_mcb->is_initiator, p_frame->cr)) { + /* we assume that this is ok to allow bad implementations to work */ + RFCOMM_TRACE_ERROR("Bad UIH - response"); + return (RFC_EVENT_UIH); + } else + return (RFC_EVENT_UIH); + } + + return (RFC_EVENT_BAD_FRAME); } - /******************************************************************************* * * Function rfc_process_mx_message @@ -662,215 +604,202 @@ uint8_t rfc_parse_data (tRFC_MCB *p_mcb, MX_FRAME *p_frame, BT_HDR *p_buf) * multiplexer control channel. * ******************************************************************************/ -void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf) -{ - uint8_t *p_data = (uint8_t *)(p_buf + 1) + p_buf->offset; - MX_FRAME *p_rx_frame = &rfc_cb.rfc.rx_frame; - uint16_t length = p_buf->len; - uint8_t ea, cr, mx_len; - bool is_command; - - p_rx_frame->ea = *p_data & RFCOMM_EA; - p_rx_frame->cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; - p_rx_frame->type = *p_data++ & ~(RFCOMM_CR_MASK | RFCOMM_EA_MASK); - - if (!p_rx_frame->ea || !length) - { - RFCOMM_TRACE_ERROR ("Illegal MX Frame ea:%d len:%d", p_rx_frame->ea, length); - osi_free(p_buf); - return; - } +void rfc_process_mx_message(tRFC_MCB* p_mcb, BT_HDR* p_buf) { + uint8_t* p_data = (uint8_t*)(p_buf + 1) + p_buf->offset; + MX_FRAME* p_rx_frame = &rfc_cb.rfc.rx_frame; + uint16_t length = p_buf->len; + uint8_t ea, cr, mx_len; + bool is_command; + + p_rx_frame->ea = *p_data & RFCOMM_EA; + p_rx_frame->cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; + p_rx_frame->type = *p_data++ & ~(RFCOMM_CR_MASK | RFCOMM_EA_MASK); + + if (!p_rx_frame->ea || !length) { + RFCOMM_TRACE_ERROR("Illegal MX Frame ea:%d len:%d", p_rx_frame->ea, length); + osi_free(p_buf); + return; + } - length--; + length--; - is_command = p_rx_frame->cr; + is_command = p_rx_frame->cr; - ea = *p_data & RFCOMM_EA; + ea = *p_data & RFCOMM_EA; - mx_len = *p_data++ >> RFCOMM_SHIFT_LENGTH1; + mx_len = *p_data++ >> RFCOMM_SHIFT_LENGTH1; + length--; + + if (!ea) { + mx_len += *p_data++ << RFCOMM_SHIFT_LENGTH2; length--; + } + + if (mx_len != length) { + RFCOMM_TRACE_ERROR("Bad MX frame"); + osi_free(p_buf); + return; + } - if (!ea) - { - mx_len += *p_data++ << RFCOMM_SHIFT_LENGTH2; - length --; - } - - if (mx_len != length) - { - RFCOMM_TRACE_ERROR ("Bad MX frame"); - osi_free(p_buf); - return; - } - - switch (p_rx_frame->type) - { + switch (p_rx_frame->type) { case RFCOMM_MX_PN: - if (length != RFCOMM_MX_PN_LEN) - break; - - p_rx_frame->dlci = *p_data++ & RFCOMM_PN_DLCI_MASK; - p_rx_frame->u.pn.frame_type = *p_data & RFCOMM_PN_FRAME_TYPE_MASK; - p_rx_frame->u.pn.conv_layer = *p_data++ & RFCOMM_PN_CONV_LAYER_MASK; - p_rx_frame->u.pn.priority = *p_data++ & RFCOMM_PN_PRIORITY_MASK; - p_rx_frame->u.pn.t1 = *p_data++; - p_rx_frame->u.pn.mtu = *p_data + (*(p_data + 1) << 8); - p_data += 2; - p_rx_frame->u.pn.n2 = *p_data++; - p_rx_frame->u.pn.k = *p_data++ & RFCOMM_PN_K_MASK; - - if (!p_rx_frame->dlci - || !RFCOMM_VALID_DLCI (p_rx_frame->dlci) - || (p_rx_frame->u.pn.mtu < RFCOMM_MIN_MTU) - || (p_rx_frame->u.pn.mtu > RFCOMM_MAX_MTU)) - { - RFCOMM_TRACE_ERROR ("Bad PN frame"); - break; - } - - osi_free(p_buf); - - rfc_process_pn (p_mcb, is_command, p_rx_frame); - return; + if (length != RFCOMM_MX_PN_LEN) break; + + p_rx_frame->dlci = *p_data++ & RFCOMM_PN_DLCI_MASK; + p_rx_frame->u.pn.frame_type = *p_data & RFCOMM_PN_FRAME_TYPE_MASK; + p_rx_frame->u.pn.conv_layer = *p_data++ & RFCOMM_PN_CONV_LAYER_MASK; + p_rx_frame->u.pn.priority = *p_data++ & RFCOMM_PN_PRIORITY_MASK; + p_rx_frame->u.pn.t1 = *p_data++; + p_rx_frame->u.pn.mtu = *p_data + (*(p_data + 1) << 8); + p_data += 2; + p_rx_frame->u.pn.n2 = *p_data++; + p_rx_frame->u.pn.k = *p_data++ & RFCOMM_PN_K_MASK; + + if (!p_rx_frame->dlci || !RFCOMM_VALID_DLCI(p_rx_frame->dlci) || + (p_rx_frame->u.pn.mtu < RFCOMM_MIN_MTU) || + (p_rx_frame->u.pn.mtu > RFCOMM_MAX_MTU)) { + RFCOMM_TRACE_ERROR("Bad PN frame"); + break; + } + + osi_free(p_buf); + + rfc_process_pn(p_mcb, is_command, p_rx_frame); + return; case RFCOMM_MX_TEST: - if (!length) - break; + if (!length) break; - p_rx_frame->u.test.p_data = p_data; - p_rx_frame->u.test.data_len = length; + p_rx_frame->u.test.p_data = p_data; + p_rx_frame->u.test.data_len = length; - p_buf->offset += 2; - p_buf->len -= 2; + p_buf->offset += 2; + p_buf->len -= 2; - if (is_command) - rfc_send_test (p_mcb, false, p_buf); - else - rfc_process_test_rsp (p_mcb, p_buf); - return; + if (is_command) + rfc_send_test(p_mcb, false, p_buf); + else + rfc_process_test_rsp(p_mcb, p_buf); + return; case RFCOMM_MX_FCON: - if (length != RFCOMM_MX_FCON_LEN) - break; + if (length != RFCOMM_MX_FCON_LEN) break; - osi_free(p_buf); + osi_free(p_buf); - rfc_process_fcon (p_mcb, is_command); - return; + rfc_process_fcon(p_mcb, is_command); + return; case RFCOMM_MX_FCOFF: - if (length != RFCOMM_MX_FCOFF_LEN) - break; + if (length != RFCOMM_MX_FCOFF_LEN) break; - osi_free(p_buf); + osi_free(p_buf); - rfc_process_fcoff (p_mcb, is_command); - return; + rfc_process_fcoff(p_mcb, is_command); + return; case RFCOMM_MX_MSC: - ea = *p_data & RFCOMM_EA; - cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; - p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; - - if (!ea || !cr || !p_rx_frame->dlci - || !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) - { - RFCOMM_TRACE_ERROR ("Bad MSC frame"); - break; - } - - p_rx_frame->u.msc.signals = *p_data++; - - if (mx_len == RFCOMM_MX_MSC_LEN_WITH_BREAK) - { - p_rx_frame->u.msc.break_present = *p_data & RFCOMM_MSC_BREAK_PRESENT_MASK; - p_rx_frame->u.msc.break_duration = (*p_data & RFCOMM_MSC_BREAK_MASK) >> RFCOMM_MSC_SHIFT_BREAK; - } - else - { - p_rx_frame->u.msc.break_present = false; - p_rx_frame->u.msc.break_duration = 0; - } - osi_free(p_buf); - - rfc_process_msc (p_mcb, is_command, p_rx_frame); - return; + ea = *p_data & RFCOMM_EA; + cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; + p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; + + if (!ea || !cr || !p_rx_frame->dlci || + !RFCOMM_VALID_DLCI(p_rx_frame->dlci)) { + RFCOMM_TRACE_ERROR("Bad MSC frame"); + break; + } + + p_rx_frame->u.msc.signals = *p_data++; + + if (mx_len == RFCOMM_MX_MSC_LEN_WITH_BREAK) { + p_rx_frame->u.msc.break_present = + *p_data & RFCOMM_MSC_BREAK_PRESENT_MASK; + p_rx_frame->u.msc.break_duration = + (*p_data & RFCOMM_MSC_BREAK_MASK) >> RFCOMM_MSC_SHIFT_BREAK; + } else { + p_rx_frame->u.msc.break_present = false; + p_rx_frame->u.msc.break_duration = 0; + } + osi_free(p_buf); + + rfc_process_msc(p_mcb, is_command, p_rx_frame); + return; case RFCOMM_MX_NSC: - if ((length != RFCOMM_MX_NSC_LEN) || !is_command) - break; + if ((length != RFCOMM_MX_NSC_LEN) || !is_command) break; - p_rx_frame->u.nsc.ea = *p_data & RFCOMM_EA; - p_rx_frame->u.nsc.cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; - p_rx_frame->u.nsc.type = *p_data++ >> RFCOMM_SHIFT_DLCI; + p_rx_frame->u.nsc.ea = *p_data & RFCOMM_EA; + p_rx_frame->u.nsc.cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; + p_rx_frame->u.nsc.type = *p_data++ >> RFCOMM_SHIFT_DLCI; - osi_free(p_buf); + osi_free(p_buf); - rfc_process_nsc (p_mcb, p_rx_frame); - return; + rfc_process_nsc(p_mcb, p_rx_frame); + return; case RFCOMM_MX_RPN: - if ((length != RFCOMM_MX_RPN_REQ_LEN) && (length != RFCOMM_MX_RPN_LEN)) - break; - - ea = *p_data & RFCOMM_EA; - cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; - p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; - - if (!ea || !cr || !p_rx_frame->dlci - || !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) - { - RFCOMM_TRACE_ERROR ("Bad RPN frame"); - break; - } - - p_rx_frame->u.rpn.is_request = (length == RFCOMM_MX_RPN_REQ_LEN); - - if (!p_rx_frame->u.rpn.is_request) - { - p_rx_frame->u.rpn.baud_rate = *p_data++; - p_rx_frame->u.rpn.byte_size = (*p_data >> RFCOMM_RPN_BITS_SHIFT) & RFCOMM_RPN_BITS_MASK; - p_rx_frame->u.rpn.stop_bits = (*p_data >> RFCOMM_RPN_STOP_BITS_SHIFT) & RFCOMM_RPN_STOP_BITS_MASK; - p_rx_frame->u.rpn.parity = (*p_data >> RFCOMM_RPN_PARITY_SHIFT) & RFCOMM_RPN_PARITY_MASK; - p_rx_frame->u.rpn.parity_type = (*p_data++ >> RFCOMM_RPN_PARITY_TYPE_SHIFT) & RFCOMM_RPN_PARITY_TYPE_MASK; - - p_rx_frame->u.rpn.fc_type = *p_data++ & RFCOMM_FC_MASK; - p_rx_frame->u.rpn.xon_char = *p_data++; - p_rx_frame->u.rpn.xoff_char = *p_data++; - p_rx_frame->u.rpn.param_mask = (*p_data + (*(p_data + 1) << 8)) & RFCOMM_RPN_PM_MASK; - } - osi_free(p_buf); - - rfc_process_rpn (p_mcb, is_command, p_rx_frame->u.rpn.is_request, p_rx_frame); - return; + if ((length != RFCOMM_MX_RPN_REQ_LEN) && (length != RFCOMM_MX_RPN_LEN)) + break; + + ea = *p_data & RFCOMM_EA; + cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; + p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; + + if (!ea || !cr || !p_rx_frame->dlci || + !RFCOMM_VALID_DLCI(p_rx_frame->dlci)) { + RFCOMM_TRACE_ERROR("Bad RPN frame"); + break; + } + + p_rx_frame->u.rpn.is_request = (length == RFCOMM_MX_RPN_REQ_LEN); + + if (!p_rx_frame->u.rpn.is_request) { + p_rx_frame->u.rpn.baud_rate = *p_data++; + p_rx_frame->u.rpn.byte_size = + (*p_data >> RFCOMM_RPN_BITS_SHIFT) & RFCOMM_RPN_BITS_MASK; + p_rx_frame->u.rpn.stop_bits = + (*p_data >> RFCOMM_RPN_STOP_BITS_SHIFT) & RFCOMM_RPN_STOP_BITS_MASK; + p_rx_frame->u.rpn.parity = + (*p_data >> RFCOMM_RPN_PARITY_SHIFT) & RFCOMM_RPN_PARITY_MASK; + p_rx_frame->u.rpn.parity_type = + (*p_data++ >> RFCOMM_RPN_PARITY_TYPE_SHIFT) & + RFCOMM_RPN_PARITY_TYPE_MASK; + + p_rx_frame->u.rpn.fc_type = *p_data++ & RFCOMM_FC_MASK; + p_rx_frame->u.rpn.xon_char = *p_data++; + p_rx_frame->u.rpn.xoff_char = *p_data++; + p_rx_frame->u.rpn.param_mask = + (*p_data + (*(p_data + 1) << 8)) & RFCOMM_RPN_PM_MASK; + } + osi_free(p_buf); + + rfc_process_rpn(p_mcb, is_command, p_rx_frame->u.rpn.is_request, + p_rx_frame); + return; case RFCOMM_MX_RLS: - if (length != RFCOMM_MX_RLS_LEN) - break; + if (length != RFCOMM_MX_RLS_LEN) break; - ea = *p_data & RFCOMM_EA; - cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; + ea = *p_data & RFCOMM_EA; + cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; - p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; - p_rx_frame->u.rls.line_status = (*p_data & ~0x01); + p_rx_frame->dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; + p_rx_frame->u.rls.line_status = (*p_data & ~0x01); - if (!ea || !cr || !p_rx_frame->dlci - || !RFCOMM_VALID_DLCI (p_rx_frame->dlci)) - { - RFCOMM_TRACE_ERROR ("Bad RPN frame"); - break; - } + if (!ea || !cr || !p_rx_frame->dlci || + !RFCOMM_VALID_DLCI(p_rx_frame->dlci)) { + RFCOMM_TRACE_ERROR("Bad RPN frame"); + break; + } - osi_free(p_buf); + osi_free(p_buf); - rfc_process_rls (p_mcb, is_command, p_rx_frame); - return; - } + rfc_process_rls(p_mcb, is_command, p_rx_frame); + return; + } - osi_free(p_buf); + osi_free(p_buf); - if (is_command) - rfc_send_nsc (p_mcb); + if (is_command) rfc_send_nsc(p_mcb); } - diff --git a/stack/rfcomm/rfc_utils.cc b/stack/rfcomm/rfc_utils.cc index d989ebacc..bad58f313 100644 --- a/stack/rfcomm/rfc_utils.cc +++ b/stack/rfcomm/rfc_utils.cc @@ -22,23 +22,23 @@ * *****************************************************************************/ -#include "bt_target.h" #include "bt_common.h" +#include "bt_target.h" +#include "bt_utils.h" #include "btm_api.h" #include "btm_int.h" -#include "rfcdefs.h" +#include "btu.h" +#include "osi/include/osi.h" #include "port_api.h" #include "port_ext.h" #include "port_int.h" #include "rfc_int.h" -#include "btu.h" -#include "bt_utils.h" -#include "osi/include/osi.h" +#include "rfcdefs.h" #include -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -47,29 +47,34 @@ extern fixed_queue_t *btu_general_alarm_queue; * Description Reversed CRC Table , 8-bit, poly=0x07 * (GSM 07.10 TS 101 369 V6.3.0) ******************************************************************************/ -static const uint8_t rfc_crctable[] = -{ - 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B, - 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67, - 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43, - 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F, - - 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B, - 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, - 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33, - 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21, 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, - - 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B, - 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, - 0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3, - 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, - - 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB, - 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, - 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, - 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF -}; - +static const uint8_t rfc_crctable[] = { + 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, + 0x7C, 0x09, 0x98, 0xEA, 0x7B, 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, + 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67, 0x38, + 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, + 0x31, 0xA0, 0xD2, 0x43, 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, + 0x51, 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F, + + 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D, + 0x0C, 0x79, 0xE8, 0x9A, 0x0B, 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, + 0x88, 0x19, 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, 0x48, + 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46, 0xD7, 0xA5, 0x34, + 0x41, 0xD0, 0xA2, 0x33, 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, + 0x21, 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, + + 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, 0xEE, 0x7F, 0x0D, + 0x9C, 0xE9, 0x78, 0x0A, 0x9B, 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, + 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, 0xD8, + 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, + 0xD1, 0x40, 0x32, 0xA3, 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, + 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, + + 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, + 0xEC, 0x99, 0x08, 0x7A, 0xEB, 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, + 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, 0xA8, + 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, + 0xA1, 0x30, 0x42, 0xD3, 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, + 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF}; /******************************************************************************* * @@ -82,20 +87,17 @@ static const uint8_t rfc_crctable[] = * p - points to message * ******************************************************************************/ -uint8_t rfc_calc_fcs (uint16_t len, uint8_t *p) -{ - uint8_t fcs = 0xFF; +uint8_t rfc_calc_fcs(uint16_t len, uint8_t* p) { + uint8_t fcs = 0xFF; - while (len--) - { - fcs = rfc_crctable[fcs ^ *p++]; - } + while (len--) { + fcs = rfc_crctable[fcs ^ *p++]; + } - /* Ones compliment */ - return (0xFF - fcs); + /* Ones compliment */ + return (0xFF - fcs); } - /******************************************************************************* * * Function rfc_check_fcs @@ -108,23 +110,20 @@ uint8_t rfc_calc_fcs (uint16_t len, uint8_t *p) * received_fcs - received FCS * ******************************************************************************/ -bool rfc_check_fcs (uint16_t len, uint8_t *p, uint8_t received_fcs) -{ - uint8_t fcs = 0xFF; +bool rfc_check_fcs(uint16_t len, uint8_t* p, uint8_t received_fcs) { + uint8_t fcs = 0xFF; - while (len--) - { - fcs = rfc_crctable[fcs ^ *p++]; - } + while (len--) { + fcs = rfc_crctable[fcs ^ *p++]; + } - /* Ones compliment */ - fcs = rfc_crctable[fcs ^ received_fcs]; + /* Ones compliment */ + fcs = rfc_crctable[fcs ^ received_fcs]; - /*0xCF is the reversed order of 11110011.*/ - return (fcs == 0xCF); + /*0xCF is the reversed order of 11110011.*/ + return (fcs == 0xCF); } - /******************************************************************************* * * Function rfc_alloc_multiplexer_channel @@ -133,68 +132,69 @@ bool rfc_check_fcs (uint16_t len, uint8_t *p, uint8_t received_fcs) * the BD_ADDR. * ******************************************************************************/ -tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, bool is_initiator) -{ - int i, j; - tRFC_MCB *p_mcb = NULL; - RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel: bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); - RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d", is_initiator); - - for (i = 0; i < MAX_BD_CONNECTIONS; i++) - { - RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel rfc_cb.port.rfc_mcb[%d].state:%d", - i, rfc_cb.port.rfc_mcb[i].state); - RFCOMM_TRACE_DEBUG("(rfc_cb.port.rfc_mcb[i].bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", - rfc_cb.port.rfc_mcb[i].bd_addr[0], rfc_cb.port.rfc_mcb[i].bd_addr[1], - rfc_cb.port.rfc_mcb[i].bd_addr[2], rfc_cb.port.rfc_mcb[i].bd_addr[3], - rfc_cb.port.rfc_mcb[i].bd_addr[4], rfc_cb.port.rfc_mcb[i].bd_addr[5]); - - if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) - && (!memcmp (rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN))) - { - /* Multiplexer channel found do not change anything */ - /* If there was an inactivity timer running stop it now */ - if (rfc_cb.port.rfc_mcb[i].state == RFC_MX_STATE_CONNECTED) - rfc_timer_stop (&rfc_cb.port.rfc_mcb[i]); - RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d, found, state:%d, p_mcb:%p", - is_initiator, rfc_cb.port.rfc_mcb[i].state, &rfc_cb.port.rfc_mcb[i]); - return (&rfc_cb.port.rfc_mcb[i]); - } +tRFC_MCB* rfc_alloc_multiplexer_channel(BD_ADDR bd_addr, bool is_initiator) { + int i, j; + tRFC_MCB* p_mcb = NULL; + RFCOMM_TRACE_DEBUG( + "rfc_alloc_multiplexer_channel: bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", + bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); + RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d", + is_initiator); + + for (i = 0; i < MAX_BD_CONNECTIONS; i++) { + RFCOMM_TRACE_DEBUG( + "rfc_alloc_multiplexer_channel rfc_cb.port.rfc_mcb[%d].state:%d", i, + rfc_cb.port.rfc_mcb[i].state); + RFCOMM_TRACE_DEBUG( + "(rfc_cb.port.rfc_mcb[i].bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", + rfc_cb.port.rfc_mcb[i].bd_addr[0], rfc_cb.port.rfc_mcb[i].bd_addr[1], + rfc_cb.port.rfc_mcb[i].bd_addr[2], rfc_cb.port.rfc_mcb[i].bd_addr[3], + rfc_cb.port.rfc_mcb[i].bd_addr[4], rfc_cb.port.rfc_mcb[i].bd_addr[5]); + + if ((rfc_cb.port.rfc_mcb[i].state != RFC_MX_STATE_IDLE) && + (!memcmp(rfc_cb.port.rfc_mcb[i].bd_addr, bd_addr, BD_ADDR_LEN))) { + /* Multiplexer channel found do not change anything */ + /* If there was an inactivity timer running stop it now */ + if (rfc_cb.port.rfc_mcb[i].state == RFC_MX_STATE_CONNECTED) + rfc_timer_stop(&rfc_cb.port.rfc_mcb[i]); + RFCOMM_TRACE_DEBUG( + "rfc_alloc_multiplexer_channel:is_initiator:%d, found, state:%d, " + "p_mcb:%p", + is_initiator, rfc_cb.port.rfc_mcb[i].state, &rfc_cb.port.rfc_mcb[i]); + return (&rfc_cb.port.rfc_mcb[i]); } + } + + /* connection with bd_addr does not exist */ + for (i = 0, j = rfc_cb.rfc.last_mux + 1; i < MAX_BD_CONNECTIONS; i++, j++) { + if (j >= MAX_BD_CONNECTIONS) j = 0; + + p_mcb = &rfc_cb.port.rfc_mcb[j]; + if (rfc_cb.port.rfc_mcb[j].state == RFC_MX_STATE_IDLE) { + /* New multiplexer control block */ + alarm_free(p_mcb->mcb_timer); + fixed_queue_free(p_mcb->cmd_q, NULL); + memset(p_mcb, 0, sizeof(tRFC_MCB)); + memcpy(p_mcb->bd_addr, bd_addr, BD_ADDR_LEN); + RFCOMM_TRACE_DEBUG( + "rfc_alloc_multiplexer_channel:is_initiator:%d, create new p_mcb:%p, " + "index:%d", + is_initiator, &rfc_cb.port.rfc_mcb[j], j); + + p_mcb->mcb_timer = alarm_new("rfcomm_mcb.mcb_timer"); + p_mcb->cmd_q = fixed_queue_new(SIZE_MAX); + + p_mcb->is_initiator = is_initiator; + + rfc_timer_start(p_mcb, RFC_MCB_INIT_INACT_TIMER); - /* connection with bd_addr does not exist */ - for (i = 0, j = rfc_cb.rfc.last_mux + 1; i < MAX_BD_CONNECTIONS; i++, j++) - { - if (j >= MAX_BD_CONNECTIONS) - j = 0; - - p_mcb = &rfc_cb.port.rfc_mcb[j]; - if (rfc_cb.port.rfc_mcb[j].state == RFC_MX_STATE_IDLE) - { - /* New multiplexer control block */ - alarm_free(p_mcb->mcb_timer); - fixed_queue_free(p_mcb->cmd_q, NULL); - memset (p_mcb, 0, sizeof (tRFC_MCB)); - memcpy (p_mcb->bd_addr, bd_addr, BD_ADDR_LEN); - RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d, create new p_mcb:%p, index:%d", - is_initiator, &rfc_cb.port.rfc_mcb[j], j); - - p_mcb->mcb_timer = alarm_new("rfcomm_mcb.mcb_timer"); - p_mcb->cmd_q = fixed_queue_new(SIZE_MAX); - - p_mcb->is_initiator = is_initiator; - - rfc_timer_start (p_mcb, RFC_MCB_INIT_INACT_TIMER); - - rfc_cb.rfc.last_mux = (uint8_t) j; - return (p_mcb); - } + rfc_cb.rfc.last_mux = (uint8_t)j; + return (p_mcb); } - return (NULL); + } + return (NULL); } - /******************************************************************************* * * Function rfc_release_multiplexer_channel @@ -202,26 +202,24 @@ tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, bool is_initiator) * Description Release a multiplexer control block * ******************************************************************************/ -void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb) -{ - /* Remove the MCB from the mapping table */ - rfc_save_lcid_mcb(NULL, p_mcb->lcid); - - /* Remove the MCB from the ports */ - for (int i = 0; i < MAX_RFC_PORTS; i++) { - if (rfc_cb.port.port[i].rfc.p_mcb == p_mcb) - rfc_cb.port.port[i].rfc.p_mcb = NULL; - } +void rfc_release_multiplexer_channel(tRFC_MCB* p_mcb) { + /* Remove the MCB from the mapping table */ + rfc_save_lcid_mcb(NULL, p_mcb->lcid); - rfc_timer_stop (p_mcb); - alarm_free(p_mcb->mcb_timer); + /* Remove the MCB from the ports */ + for (int i = 0; i < MAX_RFC_PORTS; i++) { + if (rfc_cb.port.port[i].rfc.p_mcb == p_mcb) + rfc_cb.port.port[i].rfc.p_mcb = NULL; + } - fixed_queue_free(p_mcb->cmd_q, osi_free); + rfc_timer_stop(p_mcb); + alarm_free(p_mcb->mcb_timer); - memset (p_mcb, 0, sizeof (tRFC_MCB)); - p_mcb->state = RFC_MX_STATE_IDLE; -} + fixed_queue_free(p_mcb->cmd_q, osi_free); + memset(p_mcb, 0, sizeof(tRFC_MCB)); + p_mcb->state = RFC_MX_STATE_IDLE; +} /******************************************************************************* * @@ -230,16 +228,13 @@ void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb) * Description Start RFC Timer * ******************************************************************************/ -void rfc_timer_start(tRFC_MCB *p_mcb, uint16_t timeout) -{ - RFCOMM_TRACE_EVENT ("%s - timeout:%d seconds", __func__, timeout); - - period_ms_t interval_ms = timeout * 1000; - alarm_set_on_queue(p_mcb->mcb_timer, interval_ms, - rfcomm_mcb_timer_timeout, p_mcb, - btu_general_alarm_queue); -} +void rfc_timer_start(tRFC_MCB* p_mcb, uint16_t timeout) { + RFCOMM_TRACE_EVENT("%s - timeout:%d seconds", __func__, timeout); + period_ms_t interval_ms = timeout * 1000; + alarm_set_on_queue(p_mcb->mcb_timer, interval_ms, rfcomm_mcb_timer_timeout, + p_mcb, btu_general_alarm_queue); +} /******************************************************************************* * @@ -248,14 +243,12 @@ void rfc_timer_start(tRFC_MCB *p_mcb, uint16_t timeout) * Description Stop RFC Timer * ******************************************************************************/ -void rfc_timer_stop(tRFC_MCB *p_mcb) -{ - RFCOMM_TRACE_EVENT("%s", __func__); +void rfc_timer_stop(tRFC_MCB* p_mcb) { + RFCOMM_TRACE_EVENT("%s", __func__); - alarm_cancel(p_mcb->mcb_timer); + alarm_cancel(p_mcb->mcb_timer); } - /******************************************************************************* * * Function rfc_port_timer_start @@ -263,14 +256,13 @@ void rfc_timer_stop(tRFC_MCB *p_mcb) * Description Start RFC Timer * ******************************************************************************/ -void rfc_port_timer_start(tPORT *p_port, uint16_t timeout) -{ - RFCOMM_TRACE_EVENT("%s - timeout:%d seconds", __func__, timeout); - - period_ms_t interval_ms = timeout * 1000; - alarm_set_on_queue(p_port->rfc.port_timer, interval_ms, - rfcomm_port_timer_timeout, p_port, - btu_general_alarm_queue); +void rfc_port_timer_start(tPORT* p_port, uint16_t timeout) { + RFCOMM_TRACE_EVENT("%s - timeout:%d seconds", __func__, timeout); + + period_ms_t interval_ms = timeout * 1000; + alarm_set_on_queue(p_port->rfc.port_timer, interval_ms, + rfcomm_port_timer_timeout, p_port, + btu_general_alarm_queue); } /******************************************************************************* @@ -280,14 +272,12 @@ void rfc_port_timer_start(tPORT *p_port, uint16_t timeout) * Description Stop RFC Timer * ******************************************************************************/ -void rfc_port_timer_stop(tPORT *p_port) -{ - RFCOMM_TRACE_EVENT ("%s", __func__); +void rfc_port_timer_stop(tPORT* p_port) { + RFCOMM_TRACE_EVENT("%s", __func__); - alarm_cancel(p_port->rfc.port_timer); + alarm_cancel(p_port->rfc.port_timer); } - /******************************************************************************* * * Function rfc_check_mcb_active @@ -298,41 +288,34 @@ void rfc_port_timer_stop(tPORT *p_port) * Returns void * ******************************************************************************/ -void rfc_check_mcb_active (tRFC_MCB *p_mcb) -{ - uint16_t i; - - for (i = 0; i < RFCOMM_MAX_DLCI; i++) - { - if (p_mcb->port_inx[i] != 0) - { - p_mcb->is_disc_initiator = false; - return; - } - } - /* The last port was DISCed. On the client side start disconnecting Mx */ - /* On the server side start inactivity timer */ - if (p_mcb->is_disc_initiator) - { - p_mcb->is_disc_initiator = false; - rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CLOSE_REQ, NULL); +void rfc_check_mcb_active(tRFC_MCB* p_mcb) { + uint16_t i; + + for (i = 0; i < RFCOMM_MAX_DLCI; i++) { + if (p_mcb->port_inx[i] != 0) { + p_mcb->is_disc_initiator = false; + return; } - else - rfc_timer_start (p_mcb, RFC_MCB_RELEASE_INACT_TIMER); + } + /* The last port was DISCed. On the client side start disconnecting Mx */ + /* On the server side start inactivity timer */ + if (p_mcb->is_disc_initiator) { + p_mcb->is_disc_initiator = false; + rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CLOSE_REQ, NULL); + } else + rfc_timer_start(p_mcb, RFC_MCB_RELEASE_INACT_TIMER); } -void rfcomm_port_timer_timeout(void *data) -{ - tPORT *p_port = (tPORT *)data; +void rfcomm_port_timer_timeout(void* data) { + tPORT* p_port = (tPORT*)data; - rfc_port_sm_execute(p_port, RFC_EVENT_TIMEOUT, NULL); + rfc_port_sm_execute(p_port, RFC_EVENT_TIMEOUT, NULL); } -void rfcomm_mcb_timer_timeout(void *data) -{ - tRFC_MCB *p_mcb = (tRFC_MCB *)data; +void rfcomm_mcb_timer_timeout(void* data) { + tRFC_MCB* p_mcb = (tRFC_MCB*)data; - rfc_mx_sm_execute(p_mcb, RFC_EVENT_TIMEOUT, NULL); + rfc_mx_sm_execute(p_mcb, RFC_EVENT_TIMEOUT, NULL); } /******************************************************************************* @@ -345,21 +328,20 @@ void rfcomm_mcb_timer_timeout(void *data) * Returns void * ******************************************************************************/ -void rfc_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSPORT transport, void *p_ref_data, - uint8_t res) -{ - tPORT *p_port = (tPORT *)p_ref_data; - - /* Verify that PORT is still waiting for Security to complete */ - if (!p_port->in_use - || ((p_port->rfc.state != RFC_STATE_ORIG_WAIT_SEC_CHECK) - && (p_port->rfc.state != RFC_STATE_TERM_WAIT_SEC_CHECK))) - return; - - rfc_port_sm_execute ((tPORT *)p_ref_data, RFC_EVENT_SEC_COMPLETE, &res); +void rfc_sec_check_complete(UNUSED_ATTR BD_ADDR bd_addr, + UNUSED_ATTR tBT_TRANSPORT transport, + void* p_ref_data, uint8_t res) { + tPORT* p_port = (tPORT*)p_ref_data; + + /* Verify that PORT is still waiting for Security to complete */ + if (!p_port->in_use || + ((p_port->rfc.state != RFC_STATE_ORIG_WAIT_SEC_CHECK) && + (p_port->rfc.state != RFC_STATE_TERM_WAIT_SEC_CHECK))) + return; + + rfc_port_sm_execute((tPORT*)p_ref_data, RFC_EVENT_SEC_COMPLETE, &res); } - /******************************************************************************* * * Function rfc_port_closed @@ -371,27 +353,25 @@ void rfc_sec_check_complete (UNUSED_ATTR BD_ADDR bd_addr, UNUSED_ATTR tBT_TRANSP * Returns void * ******************************************************************************/ -void rfc_port_closed (tPORT *p_port) -{ - tRFC_MCB *p_mcb = p_port->rfc.p_mcb; +void rfc_port_closed(tPORT* p_port) { + tRFC_MCB* p_mcb = p_port->rfc.p_mcb; - RFCOMM_TRACE_DEBUG ("rfc_port_closed"); + RFCOMM_TRACE_DEBUG("rfc_port_closed"); - rfc_port_timer_stop (p_port); + rfc_port_timer_stop(p_port); - p_port->rfc.state = RFC_STATE_CLOSED; + p_port->rfc.state = RFC_STATE_CLOSED; - /* If multiplexer channel was up mark it as down */ - if (p_mcb) - { - p_mcb->port_inx[p_port->dlci] = 0; + /* If multiplexer channel was up mark it as down */ + if (p_mcb) { + p_mcb->port_inx[p_port->dlci] = 0; - /* If there are no more ports opened on this MCB release it */ - rfc_check_mcb_active (p_mcb); - } + /* If there are no more ports opened on this MCB release it */ + rfc_check_mcb_active(p_mcb); + } - /* Notify port that RFC connection is gone */ - port_rfc_closed (p_port, PORT_CLOSED); + /* Notify port that RFC connection is gone */ + port_rfc_closed(p_port, PORT_CLOSED); } /******************************************************************************* @@ -405,17 +385,15 @@ void rfc_port_closed (tPORT *p_port) * Returns void * ******************************************************************************/ -void rfc_inc_credit (tPORT *p_port, uint8_t credit) -{ - if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - { - p_port->credit_tx += credit; +void rfc_inc_credit(tPORT* p_port, uint8_t credit) { + if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { + p_port->credit_tx += credit; - RFCOMM_TRACE_EVENT ("rfc_inc_credit:%d", p_port->credit_tx); + RFCOMM_TRACE_EVENT("rfc_inc_credit:%d", p_port->credit_tx); - if (p_port->tx.peer_fc == true) - PORT_FlowInd(p_port->rfc.p_mcb, p_port->dlci, true); - } + if (p_port->tx.peer_fc == true) + PORT_FlowInd(p_port->rfc.p_mcb, p_port->dlci, true); + } } /******************************************************************************* @@ -429,18 +407,13 @@ void rfc_inc_credit (tPORT *p_port, uint8_t credit) * Returns void * ******************************************************************************/ -void rfc_dec_credit (tPORT *p_port) -{ - if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) - { - if (p_port->credit_tx > 0) - p_port->credit_tx--; - - if (p_port->credit_tx == 0) - p_port->tx.peer_fc = true; - } -} +void rfc_dec_credit(tPORT* p_port) { + if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) { + if (p_port->credit_tx > 0) p_port->credit_tx--; + if (p_port->credit_tx == 0) p_port->tx.peer_fc = true; + } +} /******************************************************************************* * @@ -452,23 +425,21 @@ void rfc_dec_credit (tPORT *p_port) * Returns void * ******************************************************************************/ -void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf) -{ - /* if passed a buffer queue it */ - if (p_buf != NULL) { - if (p_mcb->cmd_q == NULL) { - RFCOMM_TRACE_ERROR("%s: empty queue: p_mcb = %p p_mcb->lcid = %u cached p_mcb = %p", - __func__, p_mcb, p_mcb->lcid, - rfc_find_lcid_mcb(p_mcb->lcid)); - } - fixed_queue_enqueue(p_mcb->cmd_q, p_buf); - } - - /* handle queue if L2CAP not congested */ - while (p_mcb->l2cap_congested == false) { - BT_HDR *p = (BT_HDR *)fixed_queue_try_dequeue(p_mcb->cmd_q); - if (p == NULL) - break; - L2CA_DataWrite(p_mcb->lcid, p); +void rfc_check_send_cmd(tRFC_MCB* p_mcb, BT_HDR* p_buf) { + /* if passed a buffer queue it */ + if (p_buf != NULL) { + if (p_mcb->cmd_q == NULL) { + RFCOMM_TRACE_ERROR( + "%s: empty queue: p_mcb = %p p_mcb->lcid = %u cached p_mcb = %p", + __func__, p_mcb, p_mcb->lcid, rfc_find_lcid_mcb(p_mcb->lcid)); } + fixed_queue_enqueue(p_mcb->cmd_q, p_buf); + } + + /* handle queue if L2CAP not congested */ + while (p_mcb->l2cap_congested == false) { + BT_HDR* p = (BT_HDR*)fixed_queue_try_dequeue(p_mcb->cmd_q); + if (p == NULL) break; + L2CA_DataWrite(p_mcb->lcid, p); + } } diff --git a/stack/sdp/sdp_api.cc b/stack/sdp/sdp_api.cc index 35addb648..f11d71a75 100644 --- a/stack/sdp/sdp_api.cc +++ b/stack/sdp/sdp_api.cc @@ -22,20 +22,20 @@ * ******************************************************************************/ +#include #include #include -#include +#include "bt_common.h" #include "bt_target.h" #include "bt_utils.h" -#include "bt_common.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" +#include "btu.h" #include "sdp_api.h" #include "sdpint.h" -#include "btu.h" #include "osi/include/osi.h" @@ -65,47 +65,44 @@ * false if one or more parameters are bad * ******************************************************************************/ -bool SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, uint32_t len, uint16_t num_uuid, - tSDP_UUID *p_uuid_list, uint16_t num_attr, uint16_t *p_attr_list) -{ +bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len, + uint16_t num_uuid, tSDP_UUID* p_uuid_list, + uint16_t num_attr, uint16_t* p_attr_list) { #if (SDP_CLIENT_ENABLED == TRUE) - uint16_t xx; + uint16_t xx; - /* verify the parameters */ - if (p_db == NULL || (sizeof (tSDP_DISCOVERY_DB) > len) || - num_attr > SDP_MAX_ATTR_FILTERS || num_uuid > SDP_MAX_UUID_FILTERS) - { - SDP_TRACE_ERROR("SDP_InitDiscoveryDb Illegal param: p_db 0x%x, len %d, num_uuid %d, num_attr %d", - PTR_TO_UINT(p_db), len, num_uuid, num_attr); + /* verify the parameters */ + if (p_db == NULL || (sizeof(tSDP_DISCOVERY_DB) > len) || + num_attr > SDP_MAX_ATTR_FILTERS || num_uuid > SDP_MAX_UUID_FILTERS) { + SDP_TRACE_ERROR( + "SDP_InitDiscoveryDb Illegal param: p_db 0x%x, len %d, num_uuid %d, " + "num_attr %d", + PTR_TO_UINT(p_db), len, num_uuid, num_attr); - return(false); - } + return (false); + } - memset (p_db, 0, (size_t)len); + memset(p_db, 0, (size_t)len); - p_db->mem_size = len - sizeof (tSDP_DISCOVERY_DB); - p_db->mem_free = p_db->mem_size; - p_db->p_first_rec = NULL; - p_db->p_free_mem = (uint8_t *)(p_db + 1); + p_db->mem_size = len - sizeof(tSDP_DISCOVERY_DB); + p_db->mem_free = p_db->mem_size; + p_db->p_first_rec = NULL; + p_db->p_free_mem = (uint8_t*)(p_db + 1); - for (xx = 0; xx < num_uuid; xx++) - p_db->uuid_filters[xx] = *p_uuid_list++; + for (xx = 0; xx < num_uuid; xx++) p_db->uuid_filters[xx] = *p_uuid_list++; - p_db->num_uuid_filters = num_uuid; + p_db->num_uuid_filters = num_uuid; - for (xx = 0; xx < num_attr; xx++) - p_db->attr_filters[xx] = *p_attr_list++; + for (xx = 0; xx < num_attr; xx++) p_db->attr_filters[xx] = *p_attr_list++; - /* sort attributes */ - sdpu_sort_attr_list( num_attr, p_db ); + /* sort attributes */ + sdpu_sort_attr_list(num_attr, p_db); - p_db->num_attr_filters = num_attr; + p_db->num_attr_filters = num_attr; #endif - return(true); + return (true); } - - /******************************************************************************* * * Function SDP_CancelServiceSearch @@ -116,21 +113,17 @@ bool SDP_InitDiscoveryDb (tSDP_DISCOVERY_DB *p_db, uint32_t len, uint16_t num * not found. * ******************************************************************************/ -bool SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db) -{ +bool SDP_CancelServiceSearch(tSDP_DISCOVERY_DB* p_db) { #if (SDP_CLIENT_ENABLED == TRUE) - tCONN_CB *p_ccb = sdpu_find_ccb_by_db (p_db); - if (!p_ccb) - return(false); + tCONN_CB* p_ccb = sdpu_find_ccb_by_db(p_db); + if (!p_ccb) return (false); - sdp_disconnect (p_ccb, SDP_CANCEL); - p_ccb->disc_state = SDP_DISC_WAIT_CANCEL; + sdp_disconnect(p_ccb, SDP_CANCEL); + p_ccb->disc_state = SDP_DISC_WAIT_CANCEL; #endif - return(true); + return (true); } - - /******************************************************************************* * * Function SDP_ServiceSearchRequest @@ -140,29 +133,26 @@ bool SDP_CancelServiceSearch (tSDP_DISCOVERY_DB *p_db) * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchRequest (uint8_t *p_bd_addr, tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB *p_cb) -{ +bool SDP_ServiceSearchRequest(uint8_t* p_bd_addr, tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB* p_cb) { #if (SDP_CLIENT_ENABLED == TRUE) - tCONN_CB *p_ccb; + tCONN_CB* p_ccb; - /* Specific BD address */ - p_ccb = sdp_conn_originate (p_bd_addr); + /* Specific BD address */ + p_ccb = sdp_conn_originate(p_bd_addr); - if (!p_ccb) - return(false); + if (!p_ccb) return (false); - p_ccb->disc_state = SDP_DISC_WAIT_CONN; - p_ccb->p_db = p_db; - p_ccb->p_cb = p_cb; + p_ccb->disc_state = SDP_DISC_WAIT_CONN; + p_ccb->p_db = p_db; + p_ccb->p_cb = p_cb; - return(true); + return (true); #else - return(false); + return (false); #endif } - /******************************************************************************* * * Function SDP_ServiceSearchAttributeRequest @@ -177,27 +167,26 @@ bool SDP_ServiceSearchRequest (uint8_t *p_bd_addr, tSDP_DISCOVERY_DB *p_db, * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchAttributeRequest (uint8_t *p_bd_addr, tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB *p_cb) -{ +bool SDP_ServiceSearchAttributeRequest(uint8_t* p_bd_addr, + tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB* p_cb) { #if (SDP_CLIENT_ENABLED == TRUE) - tCONN_CB *p_ccb; + tCONN_CB* p_ccb; - /* Specific BD address */ - p_ccb = sdp_conn_originate (p_bd_addr); + /* Specific BD address */ + p_ccb = sdp_conn_originate(p_bd_addr); - if (!p_ccb) - return(false); + if (!p_ccb) return (false); - p_ccb->disc_state = SDP_DISC_WAIT_CONN; - p_ccb->p_db = p_db; - p_ccb->p_cb = p_cb; + p_ccb->disc_state = SDP_DISC_WAIT_CONN; + p_ccb->p_db = p_db; + p_ccb->p_cb = p_cb; - p_ccb->is_attr_search = true; + p_ccb->is_attr_search = true; - return(true); + return (true); #else - return(false); + return (false); #endif } /******************************************************************************* @@ -214,36 +203,34 @@ bool SDP_ServiceSearchAttributeRequest (uint8_t *p_bd_addr, tSDP_DISCOVERY_DB * Returns true if discovery started, false if failed. * ******************************************************************************/ -bool SDP_ServiceSearchAttributeRequest2 (uint8_t *p_bd_addr, tSDP_DISCOVERY_DB *p_db, - tSDP_DISC_CMPL_CB2 *p_cb2, void * user_data) -{ +bool SDP_ServiceSearchAttributeRequest2(uint8_t* p_bd_addr, + tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_CMPL_CB2* p_cb2, + void* user_data) { #if (SDP_CLIENT_ENABLED == TRUE) - tCONN_CB *p_ccb; + tCONN_CB* p_ccb; - /* Specific BD address */ - p_ccb = sdp_conn_originate (p_bd_addr); + /* Specific BD address */ + p_ccb = sdp_conn_originate(p_bd_addr); - if (!p_ccb) - return(false); + if (!p_ccb) return (false); - p_ccb->disc_state = SDP_DISC_WAIT_CONN; - p_ccb->p_db = p_db; - p_ccb->p_cb2 = p_cb2; + p_ccb->disc_state = SDP_DISC_WAIT_CONN; + p_ccb->p_db = p_db; + p_ccb->p_cb2 = p_cb2; - p_ccb->is_attr_search = true; - p_ccb->user_data = user_data; + p_ccb->is_attr_search = true; + p_ccb->user_data = user_data; - return(true); + return (true); #else - return(false); + return (false); #endif } #if (SDP_CLIENT_ENABLED == TRUE) -void SDP_SetIdleTimeout (UNUSED_ATTR BD_ADDR addr, - UNUSED_ATTR uint16_t timeout) -{ -} +void SDP_SetIdleTimeout(UNUSED_ATTR BD_ADDR addr, + UNUSED_ATTR uint16_t timeout) {} #endif /******************************************************************************* @@ -258,41 +245,35 @@ void SDP_SetIdleTimeout (UNUSED_ATTR BD_ADDR addr, * Returns Pointer to matching record, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, uint16_t attr_id, - tSDP_DISC_REC *p_start_rec) -{ +tSDP_DISC_REC* SDP_FindAttributeInDb(tSDP_DISCOVERY_DB* p_db, uint16_t attr_id, + tSDP_DISC_REC* p_start_rec) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_REC *p_rec; - tSDP_DISC_ATTR *p_attr; + tSDP_DISC_REC* p_rec; + tSDP_DISC_ATTR* p_attr; - /* Must have a valid database */ - if (p_db == NULL) - return(NULL); - - if (!p_start_rec) - p_rec = p_db->p_first_rec; - else - p_rec = p_start_rec->p_next_rec; + /* Must have a valid database */ + if (p_db == NULL) return (NULL); - while (p_rec) - { - p_attr = p_rec->p_first_attr; - while (p_attr) - { - if (p_attr->attr_id == attr_id) - return(p_rec); + if (!p_start_rec) + p_rec = p_db->p_first_rec; + else + p_rec = p_start_rec->p_next_rec; - p_attr = p_attr->p_next_attr; - } + while (p_rec) { + p_attr = p_rec->p_first_attr; + while (p_attr) { + if (p_attr->attr_id == attr_id) return (p_rec); - p_rec = p_rec->p_next_rec; + p_attr = p_attr->p_next_attr; } + + p_rec = p_rec->p_next_rec; + } #endif - /* If here, no matching attribute found */ - return(NULL); + /* If here, no matching attribute found */ + return (NULL); } - /******************************************************************************* * * Function SDP_FindAttributeInRec @@ -303,22 +284,19 @@ tSDP_DISC_REC *SDP_FindAttributeInDb (tSDP_DISCOVERY_DB *p_db, uint16_t attr_id, * Returns Pointer to matching attribute entry, or NULL * ******************************************************************************/ -tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, uint16_t attr_id) -{ +tSDP_DISC_ATTR* SDP_FindAttributeInRec(tSDP_DISC_REC* p_rec, uint16_t attr_id) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr; + tSDP_DISC_ATTR* p_attr; - p_attr = p_rec->p_first_attr; - while (p_attr) - { - if (p_attr->attr_id == attr_id) - return(p_attr); + p_attr = p_rec->p_first_attr; + while (p_attr) { + if (p_attr->attr_id == attr_id) return (p_attr); - p_attr = p_attr->p_next_attr; - } + p_attr = p_attr->p_next_attr; + } #endif - /* If here, no matching attribute found */ - return(NULL); + /* If here, no matching attribute found */ + return (NULL); } /******************************************************************************* @@ -334,82 +312,71 @@ tSDP_DISC_ATTR *SDP_FindAttributeInRec (tSDP_DISC_REC *p_rec, uint16_t attr_id) * Returns true if found, otherwise false. * ******************************************************************************/ -bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) -{ +bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr, *p_sattr, *p_extra_sattr; - - p_attr = p_rec->p_first_attr; - - while (p_attr) - { - if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - { - if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_16) - { - p_uuid->len = LEN_UUID_16; - p_uuid->uu.uuid16 = p_sattr->attr_value.v.u16; - } - else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_128) - { - p_uuid->len = LEN_UUID_128; - for (uint8_t i = 0; i != LEN_UUID_128; ++i) - p_uuid->uu.uuid128[i] = p_sattr->attr_value.v.array[LEN_UUID_128-i-1]; - } - else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_32) - { - p_uuid->len = LEN_UUID_32; - p_uuid->uu.uuid32 = p_sattr->attr_value.v.u32; - } - - return(true); - } - - /* Checking for Toyota G Block Car Kit: - ** This car kit puts an extra data element sequence - ** where the UUID is suppose to be!!! - */ - else - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE) - { - /* Look through data element sequence until no more UUIDs */ - for (p_extra_sattr = p_sattr->attr_value.v.p_sub_attr; p_extra_sattr; p_extra_sattr = p_extra_sattr->p_next_attr) - { - /* Increment past this to see if the next attribut is UUID */ - if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == UUID_DESC_TYPE) - /* only support 16 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2)) - { - p_uuid->len = 2; - p_uuid->uu.uuid16 = p_extra_sattr->attr_value.v.u16; - return(true); - } - } - } - } - } - break; + tSDP_DISC_ATTR *p_attr, *p_sattr, *p_extra_sattr; + + p_attr = p_rec->p_first_attr; + + while (p_attr) { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) { + if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_16) { + p_uuid->len = LEN_UUID_16; + p_uuid->uu.uuid16 = p_sattr->attr_value.v.u16; + } else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == + LEN_UUID_128) { + p_uuid->len = LEN_UUID_128; + for (uint8_t i = 0; i != LEN_UUID_128; ++i) + p_uuid->uu.uuid128[i] = + p_sattr->attr_value.v.array[LEN_UUID_128 - i - 1]; + } else if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == LEN_UUID_32) { + p_uuid->len = LEN_UUID_32; + p_uuid->uu.uuid32 = p_sattr->attr_value.v.u32; + } + + return (true); } - else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) - { - if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - /* only support 16 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) - { + + /* Checking for Toyota G Block Car Kit: + ** This car kit puts an extra data element sequence + ** where the UUID is suppose to be!!! + */ + else { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE) { + /* Look through data element sequence until no more UUIDs */ + for (p_extra_sattr = p_sattr->attr_value.v.p_sub_attr; + p_extra_sattr; p_extra_sattr = p_extra_sattr->p_next_attr) { + /* Increment past this to see if the next attribut is UUID */ + if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == + UUID_DESC_TYPE) + /* only support 16 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2)) { p_uuid->len = 2; - p_uuid->uu.uuid16 = p_attr->attr_value.v.u16; - return(true); + p_uuid->uu.uuid16 = p_extra_sattr->attr_value.v.u16; + return (true); + } } + } } - p_attr = p_attr->p_next_attr; + } + break; + } else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { + if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) + /* only support 16 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2)) { + p_uuid->len = 2; + p_uuid->uu.uuid16 = p_attr->attr_value.v.u16; + return (true); + } } - return false; + p_attr = p_attr->p_next_attr; + } + return false; #endif } @@ -426,49 +393,42 @@ bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) * Returns true if found, otherwise false. * ******************************************************************************/ -bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) -{ +bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr = p_rec->p_first_attr; - while (p_attr) - { - if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - tSDP_DISC_ATTR *p_sattr = p_attr->attr_value.v.p_sub_attr; - while (p_sattr) - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - { - /* only support 128 bits UUID for now */ - if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16) - { - p_uuid->len = LEN_UUID_128; - for (uint8_t i = 0; i != LEN_UUID_128; ++i) - p_uuid->uu.uuid128[i] = p_sattr->attr_value.v.array[LEN_UUID_128-i-1]; - } - return(true); - } - - p_sattr = p_sattr->p_next_attr; - } - break; - } - else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) - { - if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - /* only support 128 bits UUID for now */ - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) - { - p_uuid->len = LEN_UUID_128; - for (uint8_t i = 0; i != LEN_UUID_128; ++i) - p_uuid->uu.uuid128[i] = p_attr->attr_value.v.array[LEN_UUID_128-i-1]; - return(true); - } + tSDP_DISC_ATTR* p_attr = p_rec->p_first_attr; + while (p_attr) { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { + tSDP_DISC_ATTR* p_sattr = p_attr->attr_value.v.p_sub_attr; + while (p_sattr) { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) { + /* only support 128 bits UUID for now */ + if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16) { + p_uuid->len = LEN_UUID_128; + for (uint8_t i = 0; i != LEN_UUID_128; ++i) + p_uuid->uu.uuid128[i] = + p_sattr->attr_value.v.array[LEN_UUID_128 - i - 1]; + } + return (true); } - p_attr = p_attr->p_next_attr; + + p_sattr = p_sattr->p_next_attr; + } + break; + } else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { + if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) + /* only support 128 bits UUID for now */ + && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) { + p_uuid->len = LEN_UUID_128; + for (uint8_t i = 0; i != LEN_UUID_128; ++i) + p_uuid->uu.uuid128[i] = + p_attr->attr_value.v.array[LEN_UUID_128 - i - 1]; + return (true); + } } - return false; + p_attr = p_attr->p_next_attr; + } + return false; #endif } @@ -484,97 +444,94 @@ bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid) * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, uint16_t service_uuid, tSDP_DISC_REC *p_start_rec) -{ +tSDP_DISC_REC* SDP_FindServiceInDb(tSDP_DISCOVERY_DB* p_db, + uint16_t service_uuid, + tSDP_DISC_REC* p_start_rec) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_REC *p_rec; - tSDP_DISC_ATTR *p_attr, *p_sattr, *p_extra_sattr; + tSDP_DISC_REC* p_rec; + tSDP_DISC_ATTR *p_attr, *p_sattr, *p_extra_sattr; - /* Must have a valid database */ - if (p_db == NULL) - return(NULL); + /* Must have a valid database */ + if (p_db == NULL) return (NULL); - if (!p_start_rec) - p_rec = p_db->p_first_rec; - else - p_rec = p_start_rec->p_next_rec; - - while (p_rec) - { - p_attr = p_rec->p_first_attr; - while (p_attr) - { - if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - - if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) ) { - SDP_TRACE_DEBUG("SDP_FindServiceInDb - p_sattr value = 0x%x serviceuuid = 0x%x", - p_sattr->attr_value.v.u16, service_uuid); - if(service_uuid == UUID_SERVCLASS_HDP_PROFILE) - { - if( (p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE) || ( p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SINK)) - { - SDP_TRACE_DEBUG("SDP_FindServiceInDb found HDP source or sink\n" ); - return (p_rec); - } - } - - } - - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE && (service_uuid == 0 - || (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2 - && p_sattr->attr_value.v.u16 == service_uuid))) - /* for a specific uuid, or any one */ - { - return(p_rec); - } - - /* Checking for Toyota G Block Car Kit: - ** This car kit puts an extra data element sequence - ** where the UUID is suppose to be!!! - */ - else - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE) - { - /* Look through data element sequence until no more UUIDs */ - for (p_extra_sattr = p_sattr->attr_value.v.p_sub_attr; p_extra_sattr; p_extra_sattr = p_extra_sattr->p_next_attr) - { - /* Increment past this to see if the next attribut is UUID */ - if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2) - /* for a specific uuid, or any one */ - && ((p_extra_sattr->attr_value.v.u16 == service_uuid) || (service_uuid == 0))) - { - return(p_rec); - } - } - } - } - } - break; + if (!p_start_rec) + p_rec = p_db->p_first_rec; + else + p_rec = p_start_rec->p_next_rec; + + while (p_rec) { + p_attr = p_rec->p_first_attr; + while (p_attr) { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE)) { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2)) { + SDP_TRACE_DEBUG( + "SDP_FindServiceInDb - p_sattr value = 0x%x serviceuuid = 0x%x", + p_sattr->attr_value.v.u16, service_uuid); + if (service_uuid == UUID_SERVCLASS_HDP_PROFILE) { + if ((p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SOURCE) || + (p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SINK)) { + SDP_TRACE_DEBUG( + "SDP_FindServiceInDb found HDP source or sink\n"); + return (p_rec); + } } - else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) - { - if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2) - /* find a specific UUID or anyone */ - && ((p_attr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) - return(p_rec); + } + + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE && + (service_uuid == 0 || + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2 && + p_sattr->attr_value.v.u16 == service_uuid))) + /* for a specific uuid, or any one */ + { + return (p_rec); + } + + /* Checking for Toyota G Block Car Kit: + ** This car kit puts an extra data element sequence + ** where the UUID is suppose to be!!! + */ + else { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE) { + /* Look through data element sequence until no more UUIDs */ + for (p_extra_sattr = p_sattr->attr_value.v.p_sub_attr; + p_extra_sattr; p_extra_sattr = p_extra_sattr->p_next_attr) { + /* Increment past this to see if the next attribut is UUID */ + if ((SDP_DISC_ATTR_TYPE(p_extra_sattr->attr_len_type) == + UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_extra_sattr->attr_len_type) == 2) + /* for a specific uuid, or any one */ + && ((p_extra_sattr->attr_value.v.u16 == service_uuid) || + (service_uuid == 0))) { + return (p_rec); + } + } } - - p_attr = p_attr->p_next_attr; + } } - - p_rec = p_rec->p_next_rec; + break; + } else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { + if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 2) + /* find a specific UUID or anyone */ + && + ((p_attr->attr_value.v.u16 == service_uuid) || service_uuid == 0)) + return (p_rec); + } + + p_attr = p_attr->p_next_attr; } + + p_rec = p_rec->p_next_rec; + } #endif - /* If here, no matching UUID found */ - return(NULL); + /* If here, no matching UUID found */ + return (NULL); } /******************************************************************************* @@ -592,57 +549,50 @@ tSDP_DISC_REC *SDP_FindServiceInDb (tSDP_DISCOVERY_DB *p_db, uint16_t service_uu * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_start_rec) -{ +tSDP_DISC_REC* SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_REC* p_start_rec) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_REC *p_rec; - tSDP_DISC_ATTR *p_attr, *p_sattr; + tSDP_DISC_REC* p_rec; + tSDP_DISC_ATTR *p_attr, *p_sattr; - /* Must have a valid database */ - if (p_db == NULL) - return(NULL); + /* Must have a valid database */ + if (p_db == NULL) return (NULL); - if (!p_start_rec) - p_rec = p_db->p_first_rec; - else - p_rec = p_start_rec->p_next_rec; - - while (p_rec) - { - p_attr = p_rec->p_first_attr; - while (p_attr) - { - if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16)) - { - return(p_rec); - } - } - break; - } - else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) - { - if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) - return(p_rec); - } + if (!p_start_rec) + p_rec = p_db->p_first_rec; + else + p_rec = p_start_rec->p_next_rec; - p_attr = p_attr->p_next_attr; + while (p_rec) { + p_attr = p_rec->p_first_attr; + while (p_attr) { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE)) { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 16)) { + return (p_rec); + } } - - p_rec = p_rec->p_next_rec; + break; + } else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { + if ((SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_attr->attr_len_type) == 16)) + return (p_rec); + } + + p_attr = p_attr->p_next_attr; } + + p_rec = p_rec->p_next_rec; + } #endif - /* If here, no matching UUID found */ - return(NULL); + /* If here, no matching UUID found */ + return (NULL); } - /******************************************************************************* * * Function SDP_FindServiceUUIDInDb @@ -659,56 +609,48 @@ tSDP_DISC_REC *SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC * Returns Pointer to record containing service class, or NULL * ******************************************************************************/ -tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uuid, tSDP_DISC_REC *p_start_rec) -{ +tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db, + tBT_UUID* p_uuid, + tSDP_DISC_REC* p_start_rec) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_REC *p_rec; - tSDP_DISC_ATTR *p_attr, *p_sattr; + tSDP_DISC_REC* p_rec; + tSDP_DISC_ATTR *p_attr, *p_sattr; - /* Must have a valid database */ - if (p_db == NULL) - return(NULL); + /* Must have a valid database */ + if (p_db == NULL) return (NULL); - if (!p_start_rec) - p_rec = p_db->p_first_rec; - else - p_rec = p_start_rec->p_next_rec; - - while (p_rec) - { - p_attr = p_rec->p_first_attr; - while (p_attr) - { - if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - { - if (sdpu_compare_uuid_with_attr (p_uuid, p_sattr)) - return(p_rec); - } - } - break; - } - else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) - { - if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE ) - { - if (sdpu_compare_uuid_with_attr (p_uuid, p_attr)) - return(p_rec); - } - } + if (!p_start_rec) + p_rec = p_db->p_first_rec; + else + p_rec = p_start_rec->p_next_rec; - p_attr = p_attr->p_next_attr; + while (p_rec) { + p_attr = p_rec->p_first_attr; + while (p_attr) { + if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE)) { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) { + if (sdpu_compare_uuid_with_attr(p_uuid, p_sattr)) return (p_rec); + } + } + break; + } else if (p_attr->attr_id == ATTR_ID_SERVICE_ID) { + if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == UUID_DESC_TYPE) { + if (sdpu_compare_uuid_with_attr(p_uuid, p_attr)) return (p_rec); } + } - p_rec = p_rec->p_next_rec; + p_attr = p_attr->p_next_attr; } -#endif /* CLIENT_ENABLED == TRUE */ - /* If here, no matching UUID found */ - return(NULL); + + p_rec = p_rec->p_next_rec; + } +#endif /* CLIENT_ENABLED == TRUE */ + /* If here, no matching UUID found */ + return (NULL); } #if (SDP_CLIENT_ENABLED == TRUE) @@ -722,54 +664,51 @@ tSDP_DISC_REC *SDP_FindServiceUUIDInDb (tSDP_DISCOVERY_DB *p_db, tBT_UUID *p_uui * If found, the passed protocol list element is filled in. * ******************************************************************************/ -static bool sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, uint16_t layer_uuid, - tSDP_PROTOCOL_ELEM *p_elem) -{ - tSDP_DISC_ATTR *p_sattr; - - /* Walk through the protocol descriptor list */ - for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; p_attr = p_attr->p_next_attr) - { - /* Safety check - each entry should itself be a sequence */ - if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - return(false); - - /* Now, see if the entry contains the layer we are interested in */ - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - /* SDP_TRACE_DEBUG ("SDP - p_sattr 0x%x, layer_uuid:0x%x, u16:0x%x####", - p_sattr, layer_uuid, p_sattr->attr_value.v.u16); */ - - if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) - && (p_sattr->attr_value.v.u16 == layer_uuid)) - { - /* Bingo. Now fill in the passed element */ - p_elem->protocol_uuid = layer_uuid; - p_elem->num_params = 0; - - /* Store the parameters, if any */ - for (p_sattr = p_sattr->p_next_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) != UINT_DESC_TYPE) - break; - - if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) - p_elem->params[p_elem->num_params++] = p_sattr->attr_value.v.u16; - else - p_elem->params[p_elem->num_params++] = p_sattr->attr_value.v.u8; - - if (p_elem->num_params >= SDP_MAX_PROTOCOL_PARAMS) - break; - } - return(true); - } +static bool sdp_fill_proto_elem(tSDP_DISC_ATTR* p_attr, uint16_t layer_uuid, + tSDP_PROTOCOL_ELEM* p_elem) { + tSDP_DISC_ATTR* p_sattr; + + /* Walk through the protocol descriptor list */ + for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; + p_attr = p_attr->p_next_attr) { + /* Safety check - each entry should itself be a sequence */ + if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) + return (false); + + /* Now, see if the entry contains the layer we are interested in */ + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + /* SDP_TRACE_DEBUG ("SDP - p_sattr 0x%x, layer_uuid:0x%x, u16:0x%x####", + p_sattr, layer_uuid, p_sattr->attr_value.v.u16); */ + + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) && + (p_sattr->attr_value.v.u16 == layer_uuid)) { + /* Bingo. Now fill in the passed element */ + p_elem->protocol_uuid = layer_uuid; + p_elem->num_params = 0; + + /* Store the parameters, if any */ + for (p_sattr = p_sattr->p_next_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) != UINT_DESC_TYPE) + break; + + if (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) + p_elem->params[p_elem->num_params++] = p_sattr->attr_value.v.u16; + else + p_elem->params[p_elem->num_params++] = p_sattr->attr_value.v.u8; + + if (p_elem->num_params >= SDP_MAX_PROTOCOL_PARAMS) break; } + return (true); + } } + } - return(false); + return (false); } -#endif /* CLIENT_ENABLED == TRUE */ +#endif /* CLIENT_ENABLED == TRUE */ /******************************************************************************* * @@ -782,28 +721,25 @@ static bool sdp_fill_proto_elem( tSDP_DISC_ATTR *p_attr, uint16_t layer_uuid * If found, the passed protocol list element is filled in. * ******************************************************************************/ -bool SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, uint16_t layer_uuid, tSDP_PROTOCOL_ELEM *p_elem) -{ +bool SDP_FindProtocolListElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, + tSDP_PROTOCOL_ELEM* p_elem) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr; - - p_attr = p_rec->p_first_attr; - while (p_attr) - { - /* Find the protocol descriptor list */ - if ((p_attr->attr_id == ATTR_ID_PROTOCOL_DESC_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - return sdp_fill_proto_elem(p_attr, layer_uuid, p_elem); - } - p_attr = p_attr->p_next_attr; + tSDP_DISC_ATTR* p_attr; + + p_attr = p_rec->p_first_attr; + while (p_attr) { + /* Find the protocol descriptor list */ + if ((p_attr->attr_id == ATTR_ID_PROTOCOL_DESC_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { + return sdp_fill_proto_elem(p_attr, layer_uuid, p_elem); } + p_attr = p_attr->p_next_attr; + } #endif - /* If here, no match found */ - return(false); + /* If here, no match found */ + return (false); } - /******************************************************************************* * * Function SDP_FindAddProtoListsElemInRec @@ -815,39 +751,35 @@ bool SDP_FindProtocolListElemInRec (tSDP_DISC_REC *p_rec, uint16_t layer_uuid * If found, the passed protocol list element is filled in. * ******************************************************************************/ -bool SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, uint16_t layer_uuid, tSDP_PROTOCOL_ELEM *p_elem) -{ +bool SDP_FindAddProtoListsElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, + tSDP_PROTOCOL_ELEM* p_elem) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr, *p_sattr; - bool ret = false; - - p_attr = p_rec->p_first_attr; - while (p_attr) - { - /* Find the additional protocol descriptor list attribute */ - if ((p_attr->attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - /* Safety check - each entry should itself be a sequence */ - if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE) - { - ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem); - if (ret == true) - break; - } - } - return ret; + tSDP_DISC_ATTR *p_attr, *p_sattr; + bool ret = false; + + p_attr = p_rec->p_first_attr; + while (p_attr) { + /* Find the additional protocol descriptor list attribute */ + if ((p_attr->attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + /* Safety check - each entry should itself be a sequence */ + if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == + DATA_ELE_SEQ_DESC_TYPE) { + ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem); + if (ret == true) break; } - p_attr = p_attr->p_next_attr; + } + return ret; } + p_attr = p_attr->p_next_attr; + } #endif - /* If here, no match found */ - return(false); + /* If here, no match found */ + return (false); } - /******************************************************************************* * * Function SDP_FindProfileVersionInRec @@ -862,58 +794,59 @@ bool SDP_FindAddProtoListsElemInRec (tSDP_DISC_REC *p_rec, uint16_t layer_uui * passed in are filled in. * ******************************************************************************/ -bool SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, uint16_t profile_uuid, uint16_t *p_version) -{ +bool SDP_FindProfileVersionInRec(tSDP_DISC_REC* p_rec, uint16_t profile_uuid, + uint16_t* p_version) { #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISC_ATTR *p_attr, *p_sattr; - - p_attr = p_rec->p_first_attr; - while (p_attr) - { - /* Find the profile descriptor list */ - if ((p_attr->attr_id == ATTR_ID_BT_PROFILE_DESC_LIST) - && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) - { - /* Walk through the protocol descriptor list */ - for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; p_attr = p_attr->p_next_attr) - { - /* Safety check - each entry should itself be a sequence */ - if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) - return(false); - - /* Now, see if the entry contains the profile UUID we are interested in */ - for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr) - { - if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) - && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) /* <- This is bytes, not size code! */ - && (p_sattr->attr_value.v.u16 == profile_uuid)) - { - /* Now fill in the major and minor numbers */ - /* if the attribute matches the description for version (type UINT, size 2 bytes) */ - p_sattr = p_sattr->p_next_attr; - - if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UINT_DESC_TYPE) && - (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2)) - { - /* The high order 8 bits is the major number, low order is the minor number (big endian) */ - *p_version = p_sattr->attr_value.v.u16; - - return(true); - } - else - return(false); /* The type and/or size was not valid for the profile list version */ - } - } - } - - return(false); + tSDP_DISC_ATTR *p_attr, *p_sattr; + + p_attr = p_rec->p_first_attr; + while (p_attr) { + /* Find the profile descriptor list */ + if ((p_attr->attr_id == ATTR_ID_BT_PROFILE_DESC_LIST) && + (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE)) { + /* Walk through the protocol descriptor list */ + for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; + p_attr = p_attr->p_next_attr) { + /* Safety check - each entry should itself be a sequence */ + if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) + return (false); + + /* Now, see if the entry contains the profile UUID we are interested in + */ + for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; + p_sattr = p_sattr->p_next_attr) { + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == + 2) /* <- This is bytes, not size code! */ + && (p_sattr->attr_value.v.u16 == profile_uuid)) { + /* Now fill in the major and minor numbers */ + /* if the attribute matches the description for version (type UINT, + * size 2 bytes) */ + p_sattr = p_sattr->p_next_attr; + + if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == + UINT_DESC_TYPE) && + (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2)) { + /* The high order 8 bits is the major number, low order is the + * minor number (big endian) */ + *p_version = p_sattr->attr_value.v.u16; + + return (true); + } else + return (false); /* The type and/or size was not valid for the + profile list version */ + } } - p_attr = p_attr->p_next_attr; + } + + return (false); } -#endif /* CLIENT_ENABLED == TRUE */ + p_attr = p_attr->p_next_attr; + } +#endif /* CLIENT_ENABLED == TRUE */ - /* If here, no match found */ - return(false); + /* If here, no match found */ + return (false); } /******************************************************************************* @@ -929,26 +862,25 @@ bool SDP_FindProfileVersionInRec (tSDP_DISC_REC *p_rec, uint16_t profile_uuid * Returns SDP_SUCCESS if query started successfully, else error * ******************************************************************************/ -uint16_t SDP_DiDiscover( BD_ADDR remote_device, tSDP_DISCOVERY_DB *p_db, - uint32_t len, tSDP_DISC_CMPL_CB *p_cb ) -{ +uint16_t SDP_DiDiscover(BD_ADDR remote_device, tSDP_DISCOVERY_DB* p_db, + uint32_t len, tSDP_DISC_CMPL_CB* p_cb) { #if (SDP_CLIENT_ENABLED == TRUE) - uint16_t result = SDP_DI_DISC_FAILED; - uint16_t num_uuids = 1; - uint16_t di_uuid = UUID_SERVCLASS_PNP_INFORMATION; + uint16_t result = SDP_DI_DISC_FAILED; + uint16_t num_uuids = 1; + uint16_t di_uuid = UUID_SERVCLASS_PNP_INFORMATION; - /* build uuid for db init */ - tSDP_UUID init_uuid; - init_uuid.len = 2; - init_uuid.uu.uuid16 = di_uuid; + /* build uuid for db init */ + tSDP_UUID init_uuid; + init_uuid.len = 2; + init_uuid.uu.uuid16 = di_uuid; - if ( SDP_InitDiscoveryDb(p_db, len, num_uuids, &init_uuid, 0, NULL) ) - if ( SDP_ServiceSearchRequest(remote_device, p_db, p_cb) ) - result = SDP_SUCCESS; + if (SDP_InitDiscoveryDb(p_db, len, num_uuids, &init_uuid, 0, NULL)) + if (SDP_ServiceSearchRequest(remote_device, p_db, p_cb)) + result = SDP_SUCCESS; - return result; + return result; #else - return SDP_DI_DISC_FAILED; + return SDP_DI_DISC_FAILED; #endif } @@ -961,23 +893,20 @@ uint16_t SDP_DiDiscover( BD_ADDR remote_device, tSDP_DISCOVERY_DB *p_db, * Returns number of DI records found * ******************************************************************************/ -uint8_t SDP_GetNumDiRecords( tSDP_DISCOVERY_DB *p_db ) -{ +uint8_t SDP_GetNumDiRecords(tSDP_DISCOVERY_DB* p_db) { #if (SDP_CLIENT_ENABLED == TRUE) - uint8_t num_records = 0; - tSDP_DISC_REC *p_curr_record = NULL; - - do - { - p_curr_record = SDP_FindServiceInDb( p_db, UUID_SERVCLASS_PNP_INFORMATION, - p_curr_record ); - if ( p_curr_record ) - num_records++; - }while ( p_curr_record ); - - return num_records; + uint8_t num_records = 0; + tSDP_DISC_REC* p_curr_record = NULL; + + do { + p_curr_record = SDP_FindServiceInDb(p_db, UUID_SERVCLASS_PNP_INFORMATION, + p_curr_record); + if (p_curr_record) num_records++; + } while (p_curr_record); + + return num_records; #else - return 0; + return 0; #endif } @@ -991,23 +920,19 @@ uint8_t SDP_GetNumDiRecords( tSDP_DISCOVERY_DB *p_db ) * Returns none * ******************************************************************************/ -static void SDP_AttrStringCopy(char *dst, tSDP_DISC_ATTR *p_attr, uint16_t dst_size) -{ - if ( dst == NULL ) return; - if ( p_attr ) - { - uint16_t len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); - if ( len > dst_size - 1 ) - { - len = dst_size - 1; - } - memcpy(dst, (char *)p_attr->attr_value.v.array, len); - dst[len] = '\0'; - } - else - { - dst[0] = '\0'; +static void SDP_AttrStringCopy(char* dst, tSDP_DISC_ATTR* p_attr, + uint16_t dst_size) { + if (dst == NULL) return; + if (p_attr) { + uint16_t len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + if (len > dst_size - 1) { + len = dst_size - 1; } + memcpy(dst, (char*)p_attr->attr_value.v.array, len); + dst[len] = '\0'; + } else { + dst[0] = '\0'; + } } /******************************************************************************* @@ -1020,88 +945,91 @@ static void SDP_AttrStringCopy(char *dst, tSDP_DISC_ATTR *p_attr, uint16_t dst_s * Returns SDP_SUCCESS if record retrieved, else error * ******************************************************************************/ -uint16_t SDP_GetDiRecord( uint8_t get_record_index, tSDP_DI_GET_RECORD *p_device_info, - tSDP_DISCOVERY_DB *p_db ) -{ +uint16_t SDP_GetDiRecord(uint8_t get_record_index, + tSDP_DI_GET_RECORD* p_device_info, + tSDP_DISCOVERY_DB* p_db) { #if (SDP_CLIENT_ENABLED == TRUE) - uint16_t result = SDP_NO_DI_RECORD_FOUND; - uint8_t curr_record_index = 1; - - tSDP_DISC_REC *p_curr_record = NULL; - - /* find the requested SDP record in the discovery database */ - do - { - p_curr_record = SDP_FindServiceInDb( p_db, UUID_SERVCLASS_PNP_INFORMATION, - p_curr_record ); - if ( p_curr_record ) - { - if ( curr_record_index++ == get_record_index ) - { - result = SDP_SUCCESS; - break; - } - } - }while ( p_curr_record ); - - if ( result == SDP_SUCCESS ) - { - /* copy the information from the SDP record to the DI record */ - tSDP_DISC_ATTR *p_curr_attr = NULL; - - /* ClientExecutableURL is optional */ - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_CLIENT_EXE_URL ); - SDP_AttrStringCopy( p_device_info->rec.client_executable_url, p_curr_attr, - SDP_MAX_ATTR_LEN ); - - /* Service Description is optional */ - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SERVICE_DESCRIPTION ); - SDP_AttrStringCopy( p_device_info->rec.service_description, p_curr_attr, SDP_MAX_ATTR_LEN ); - - /* DocumentationURL is optional */ - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_DOCUMENTATION_URL ); - SDP_AttrStringCopy( p_device_info->rec.documentation_url, p_curr_attr, SDP_MAX_ATTR_LEN ); - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SPECIFICATION_ID ); - if ( p_curr_attr ) - p_device_info->spec_id = p_curr_attr->attr_value.v.u16; - else - result = SDP_ERR_ATTR_NOT_PRESENT; - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_VENDOR_ID ); - if ( p_curr_attr ) - p_device_info->rec.vendor = p_curr_attr->attr_value.v.u16; - else - result = SDP_ERR_ATTR_NOT_PRESENT; - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_VENDOR_ID_SOURCE ); - if ( p_curr_attr ) - p_device_info->rec.vendor_id_source = p_curr_attr->attr_value.v.u16; - else - result = SDP_ERR_ATTR_NOT_PRESENT; - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRODUCT_ID ); - if ( p_curr_attr ) - p_device_info->rec.product = p_curr_attr->attr_value.v.u16; - else - result = SDP_ERR_ATTR_NOT_PRESENT; - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRODUCT_VERSION ); - if ( p_curr_attr ) - p_device_info->rec.version = p_curr_attr->attr_value.v.u16; - else - result = SDP_ERR_ATTR_NOT_PRESENT; - - p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_PRIMARY_RECORD ); - if ( p_curr_attr ) - p_device_info->rec.primary_record = (bool )p_curr_attr->attr_value.v.u8; - else - result = SDP_ERR_ATTR_NOT_PRESENT; + uint16_t result = SDP_NO_DI_RECORD_FOUND; + uint8_t curr_record_index = 1; + + tSDP_DISC_REC* p_curr_record = NULL; + + /* find the requested SDP record in the discovery database */ + do { + p_curr_record = SDP_FindServiceInDb(p_db, UUID_SERVCLASS_PNP_INFORMATION, + p_curr_record); + if (p_curr_record) { + if (curr_record_index++ == get_record_index) { + result = SDP_SUCCESS; + break; + } } + } while (p_curr_record); + + if (result == SDP_SUCCESS) { + /* copy the information from the SDP record to the DI record */ + tSDP_DISC_ATTR* p_curr_attr = NULL; + + /* ClientExecutableURL is optional */ + p_curr_attr = SDP_FindAttributeInRec(p_curr_record, ATTR_ID_CLIENT_EXE_URL); + SDP_AttrStringCopy(p_device_info->rec.client_executable_url, p_curr_attr, + SDP_MAX_ATTR_LEN); + + /* Service Description is optional */ + p_curr_attr = + SDP_FindAttributeInRec(p_curr_record, ATTR_ID_SERVICE_DESCRIPTION); + SDP_AttrStringCopy(p_device_info->rec.service_description, p_curr_attr, + SDP_MAX_ATTR_LEN); + + /* DocumentationURL is optional */ + p_curr_attr = + SDP_FindAttributeInRec(p_curr_record, ATTR_ID_DOCUMENTATION_URL); + SDP_AttrStringCopy(p_device_info->rec.documentation_url, p_curr_attr, + SDP_MAX_ATTR_LEN); + + p_curr_attr = + SDP_FindAttributeInRec(p_curr_record, ATTR_ID_SPECIFICATION_ID); + if (p_curr_attr) + p_device_info->spec_id = p_curr_attr->attr_value.v.u16; + else + result = SDP_ERR_ATTR_NOT_PRESENT; + + p_curr_attr = SDP_FindAttributeInRec(p_curr_record, ATTR_ID_VENDOR_ID); + if (p_curr_attr) + p_device_info->rec.vendor = p_curr_attr->attr_value.v.u16; + else + result = SDP_ERR_ATTR_NOT_PRESENT; + + p_curr_attr = + SDP_FindAttributeInRec(p_curr_record, ATTR_ID_VENDOR_ID_SOURCE); + if (p_curr_attr) + p_device_info->rec.vendor_id_source = p_curr_attr->attr_value.v.u16; + else + result = SDP_ERR_ATTR_NOT_PRESENT; + + p_curr_attr = SDP_FindAttributeInRec(p_curr_record, ATTR_ID_PRODUCT_ID); + if (p_curr_attr) + p_device_info->rec.product = p_curr_attr->attr_value.v.u16; + else + result = SDP_ERR_ATTR_NOT_PRESENT; + + p_curr_attr = + SDP_FindAttributeInRec(p_curr_record, ATTR_ID_PRODUCT_VERSION); + if (p_curr_attr) + p_device_info->rec.version = p_curr_attr->attr_value.v.u16; + else + result = SDP_ERR_ATTR_NOT_PRESENT; - return result; -#else /* SDP_CLIENT_ENABLED is FALSE */ - return SDP_NO_DI_RECORD_FOUND; + p_curr_attr = SDP_FindAttributeInRec(p_curr_record, ATTR_ID_PRIMARY_RECORD); + if (p_curr_attr) + p_device_info->rec.primary_record = (bool)p_curr_attr->attr_value.v.u8; + else + result = SDP_ERR_ATTR_NOT_PRESENT; + } + + return result; +#else /* SDP_CLIENT_ENABLED is FALSE */ + return SDP_NO_DI_RECORD_FOUND; #endif } @@ -1120,147 +1048,137 @@ uint16_t SDP_GetDiRecord( uint8_t get_record_index, tSDP_DI_GET_RECORD *p_device * Returns Returns SDP_SUCCESS if record added successfully, else error * ******************************************************************************/ -uint16_t SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, uint32_t *p_handle ) -{ +uint16_t SDP_SetLocalDiRecord(tSDP_DI_RECORD* p_device_info, + uint32_t* p_handle) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t result = SDP_SUCCESS; - uint32_t handle; - uint16_t di_uuid = UUID_SERVCLASS_PNP_INFORMATION; - uint16_t di_specid = BLUETOOTH_DI_SPECIFICATION; - uint8_t temp_u16[2]; - uint8_t *p_temp; - uint8_t u8; - - *p_handle = 0; - if ( p_device_info == NULL ) - return SDP_ILLEGAL_PARAMETER; - - /* if record is to be primary record, get handle to replace old primary */ - if ( p_device_info->primary_record == true && sdp_cb.server_db.di_primary_handle ) - handle = sdp_cb.server_db.di_primary_handle; - else - { - handle = SDP_CreateRecord(); - if (handle == 0) - return SDP_NO_RESOURCES; - } - - *p_handle = handle; - - /* build the SDP entry */ - /* Add the UUID to the Service Class ID List */ - if ((SDP_AddServiceClassIdList(handle, 1, &di_uuid)) == false) + uint16_t result = SDP_SUCCESS; + uint32_t handle; + uint16_t di_uuid = UUID_SERVCLASS_PNP_INFORMATION; + uint16_t di_specid = BLUETOOTH_DI_SPECIFICATION; + uint8_t temp_u16[2]; + uint8_t* p_temp; + uint8_t u8; + + *p_handle = 0; + if (p_device_info == NULL) return SDP_ILLEGAL_PARAMETER; + + /* if record is to be primary record, get handle to replace old primary */ + if (p_device_info->primary_record == true && + sdp_cb.server_db.di_primary_handle) + handle = sdp_cb.server_db.di_primary_handle; + else { + handle = SDP_CreateRecord(); + if (handle == 0) return SDP_NO_RESOURCES; + } + + *p_handle = handle; + + /* build the SDP entry */ + /* Add the UUID to the Service Class ID List */ + if ((SDP_AddServiceClassIdList(handle, 1, &di_uuid)) == false) + result = SDP_DI_REG_FAILED; + + /* mandatory */ + if (result == SDP_SUCCESS) { + p_temp = temp_u16; + UINT16_TO_BE_STREAM(p_temp, di_specid); + if (!(SDP_AddAttribute(handle, ATTR_ID_SPECIFICATION_ID, UINT_DESC_TYPE, + sizeof(di_specid), temp_u16))) + result = SDP_DI_REG_FAILED; + } + + /* optional - if string is null, do not add attribute */ + if (result == SDP_SUCCESS) { + if (p_device_info->client_executable_url[0] != '\0') { + if (!((strlen(p_device_info->client_executable_url) + 1 <= + SDP_MAX_ATTR_LEN) && + SDP_AddAttribute( + handle, ATTR_ID_CLIENT_EXE_URL, URL_DESC_TYPE, + (uint32_t)(strlen(p_device_info->client_executable_url) + 1), + (uint8_t*)p_device_info->client_executable_url))) result = SDP_DI_REG_FAILED; - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - p_temp = temp_u16; - UINT16_TO_BE_STREAM(p_temp, di_specid); - if ( !(SDP_AddAttribute(handle, ATTR_ID_SPECIFICATION_ID, - UINT_DESC_TYPE, sizeof(di_specid), - temp_u16)) ) - result = SDP_DI_REG_FAILED; - } - - /* optional - if string is null, do not add attribute */ - if ( result == SDP_SUCCESS ) - { - if ( p_device_info->client_executable_url[0] != '\0' ) - { - if ( !((strlen(p_device_info->client_executable_url)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_CLIENT_EXE_URL, URL_DESC_TYPE, - (uint32_t)(strlen(p_device_info->client_executable_url)+1), - (uint8_t *)p_device_info->client_executable_url)) ) - result = SDP_DI_REG_FAILED; - } } - - /* optional - if string is null, do not add attribute */ - if ( result == SDP_SUCCESS ) - { - if ( p_device_info->service_description[0] != '\0' ) - { - if ( !((strlen(p_device_info->service_description)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_SERVICE_DESCRIPTION, - TEXT_STR_DESC_TYPE, - (uint32_t)(strlen(p_device_info->service_description)+1), - (uint8_t *)p_device_info->service_description)) ) - result = SDP_DI_REG_FAILED; - } - } - - /* optional - if string is null, do not add attribute */ - if ( result == SDP_SUCCESS ) - { - if ( p_device_info->documentation_url[0] != '\0' ) - { - if ( !((strlen(p_device_info->documentation_url)+1 <= SDP_MAX_ATTR_LEN) && - SDP_AddAttribute(handle, ATTR_ID_DOCUMENTATION_URL, URL_DESC_TYPE, - (uint32_t)(strlen(p_device_info->documentation_url)+1), - (uint8_t *)p_device_info->documentation_url)) ) - result = SDP_DI_REG_FAILED; - } - } - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - p_temp = temp_u16; - UINT16_TO_BE_STREAM(p_temp, p_device_info->vendor); - if ( !(SDP_AddAttribute(handle, ATTR_ID_VENDOR_ID, UINT_DESC_TYPE, - sizeof(p_device_info->vendor), temp_u16)) ) - result = SDP_DI_REG_FAILED; - } - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - p_temp = temp_u16; - UINT16_TO_BE_STREAM (p_temp, p_device_info->product); - if ( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_ID, - UINT_DESC_TYPE, sizeof(p_device_info->product), temp_u16)) ) - result = SDP_DI_REG_FAILED; - } - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - p_temp = temp_u16; - UINT16_TO_BE_STREAM (p_temp, p_device_info->version); - if ( !(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_VERSION, UINT_DESC_TYPE, - sizeof(p_device_info->version), temp_u16)) ) - result = SDP_DI_REG_FAILED; - } - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - u8 = (uint8_t)p_device_info->primary_record; - if ( !(SDP_AddAttribute(handle, ATTR_ID_PRIMARY_RECORD, - BOOLEAN_DESC_TYPE, 1, &u8)) ) - result = SDP_DI_REG_FAILED; + } + + /* optional - if string is null, do not add attribute */ + if (result == SDP_SUCCESS) { + if (p_device_info->service_description[0] != '\0') { + if (!((strlen(p_device_info->service_description) + 1 <= + SDP_MAX_ATTR_LEN) && + SDP_AddAttribute( + handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE, + (uint32_t)(strlen(p_device_info->service_description) + 1), + (uint8_t*)p_device_info->service_description))) + result = SDP_DI_REG_FAILED; } - - /* mandatory */ - if ( result == SDP_SUCCESS) - { - p_temp = temp_u16; - UINT16_TO_BE_STREAM(p_temp, p_device_info->vendor_id_source); - if ( !(SDP_AddAttribute(handle, ATTR_ID_VENDOR_ID_SOURCE, UINT_DESC_TYPE, - sizeof(p_device_info->vendor_id_source), temp_u16)) ) - result = SDP_DI_REG_FAILED; + } + + /* optional - if string is null, do not add attribute */ + if (result == SDP_SUCCESS) { + if (p_device_info->documentation_url[0] != '\0') { + if (!((strlen(p_device_info->documentation_url) + 1 <= + SDP_MAX_ATTR_LEN) && + SDP_AddAttribute( + handle, ATTR_ID_DOCUMENTATION_URL, URL_DESC_TYPE, + (uint32_t)(strlen(p_device_info->documentation_url) + 1), + (uint8_t*)p_device_info->documentation_url))) + result = SDP_DI_REG_FAILED; } - - if ( result != SDP_SUCCESS ) - SDP_DeleteRecord( handle ); - else if (p_device_info->primary_record == true) - sdp_cb.server_db.di_primary_handle = handle; - - return result; -#else /* SDP_SERVER_ENABLED is FALSE */ - return SDP_DI_REG_FAILED; -#endif /* if SDP_SERVER_ENABLED */ + } + + /* mandatory */ + if (result == SDP_SUCCESS) { + p_temp = temp_u16; + UINT16_TO_BE_STREAM(p_temp, p_device_info->vendor); + if (!(SDP_AddAttribute(handle, ATTR_ID_VENDOR_ID, UINT_DESC_TYPE, + sizeof(p_device_info->vendor), temp_u16))) + result = SDP_DI_REG_FAILED; + } + + /* mandatory */ + if (result == SDP_SUCCESS) { + p_temp = temp_u16; + UINT16_TO_BE_STREAM(p_temp, p_device_info->product); + if (!(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_ID, UINT_DESC_TYPE, + sizeof(p_device_info->product), temp_u16))) + result = SDP_DI_REG_FAILED; + } + + /* mandatory */ + if (result == SDP_SUCCESS) { + p_temp = temp_u16; + UINT16_TO_BE_STREAM(p_temp, p_device_info->version); + if (!(SDP_AddAttribute(handle, ATTR_ID_PRODUCT_VERSION, UINT_DESC_TYPE, + sizeof(p_device_info->version), temp_u16))) + result = SDP_DI_REG_FAILED; + } + + /* mandatory */ + if (result == SDP_SUCCESS) { + u8 = (uint8_t)p_device_info->primary_record; + if (!(SDP_AddAttribute(handle, ATTR_ID_PRIMARY_RECORD, BOOLEAN_DESC_TYPE, 1, + &u8))) + result = SDP_DI_REG_FAILED; + } + + /* mandatory */ + if (result == SDP_SUCCESS) { + p_temp = temp_u16; + UINT16_TO_BE_STREAM(p_temp, p_device_info->vendor_id_source); + if (!(SDP_AddAttribute(handle, ATTR_ID_VENDOR_ID_SOURCE, UINT_DESC_TYPE, + sizeof(p_device_info->vendor_id_source), temp_u16))) + result = SDP_DI_REG_FAILED; + } + + if (result != SDP_SUCCESS) + SDP_DeleteRecord(handle); + else if (p_device_info->primary_record == true) + sdp_cb.server_db.di_primary_handle = handle; + + return result; +#else /* SDP_SERVER_ENABLED is FALSE */ + return SDP_DI_REG_FAILED; +#endif /* if SDP_SERVER_ENABLED */ } /******************************************************************************* @@ -1273,10 +1191,8 @@ uint16_t SDP_SetLocalDiRecord( tSDP_DI_RECORD *p_device_info, uint32_t *p_handle * Returns the new (current) trace level * ******************************************************************************/ -uint8_t SDP_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - sdp_cb.trace_level = new_level; +uint8_t SDP_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) sdp_cb.trace_level = new_level; - return(sdp_cb.trace_level); + return (sdp_cb.trace_level); } diff --git a/stack/sdp/sdp_db.cc b/stack/sdp/sdp_db.cc index d74df529e..cc846aedf 100644 --- a/stack/sdp/sdp_db.cc +++ b/stack/sdp/sdp_db.cc @@ -22,17 +22,17 @@ * ******************************************************************************/ +#include #include #include -#include #include "bt_target.h" #include "bt_common.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "sdp_api.h" #include "sdpint.h" @@ -41,9 +41,8 @@ /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static bool find_uuid_in_seq (uint8_t *p , uint32_t seq_len, uint8_t *p_his_uuid, - uint16_t his_len, int nest_level); - +static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_his_uuid, + uint16_t his_len, int nest_level); /******************************************************************************* * @@ -56,54 +55,46 @@ static bool find_uuid_in_seq (uint8_t *p , uint32_t seq_len, uint8_t *p_his_u * Returns Pointer to the record, or NULL if not found. * ******************************************************************************/ -tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq) -{ - uint16_t xx, yy; - tSDP_ATTRIBUTE *p_attr; - tSDP_RECORD *p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records]; - - /* If NULL, start at the beginning, else start at the first specified record */ - if (!p_rec) - p_rec = &sdp_cb.server_db.record[0]; - else - p_rec++; - - /* Look through the records. The spec says that a match occurs if */ - /* the record contains all the passed UUIDs in it. */ - for ( ; p_rec < p_end; p_rec++) - { - for (yy = 0; yy < p_seq->num_uids; yy++) - { - p_attr = &p_rec->attribute[0]; - for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) - { - if (p_attr->type == UUID_DESC_TYPE) - { - if (sdpu_compare_uuid_arrays (p_attr->value_ptr, p_attr->len, - &p_seq->uuid_entry[yy].value[0], - p_seq->uuid_entry[yy].len)) - break; - } - else if (p_attr->type == DATA_ELE_SEQ_DESC_TYPE) - { - if (find_uuid_in_seq (p_attr->value_ptr, p_attr->len, - &p_seq->uuid_entry[yy].value[0], - p_seq->uuid_entry[yy].len, 0)) - break; - } - } - /* If any UUID was not found, on to the next record */ - if (xx == p_rec->num_attributes) - break; +tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec, tSDP_UUID_SEQ* p_seq) { + uint16_t xx, yy; + tSDP_ATTRIBUTE* p_attr; + tSDP_RECORD* p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records]; + + /* If NULL, start at the beginning, else start at the first specified record + */ + if (!p_rec) + p_rec = &sdp_cb.server_db.record[0]; + else + p_rec++; + + /* Look through the records. The spec says that a match occurs if */ + /* the record contains all the passed UUIDs in it. */ + for (; p_rec < p_end; p_rec++) { + for (yy = 0; yy < p_seq->num_uids; yy++) { + p_attr = &p_rec->attribute[0]; + for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) { + if (p_attr->type == UUID_DESC_TYPE) { + if (sdpu_compare_uuid_arrays(p_attr->value_ptr, p_attr->len, + &p_seq->uuid_entry[yy].value[0], + p_seq->uuid_entry[yy].len)) + break; + } else if (p_attr->type == DATA_ELE_SEQ_DESC_TYPE) { + if (find_uuid_in_seq(p_attr->value_ptr, p_attr->len, + &p_seq->uuid_entry[yy].value[0], + p_seq->uuid_entry[yy].len, 0)) + break; } - - /* If every UUID was found in the record, return the record */ - if (yy == p_seq->num_uids) - return (p_rec); + } + /* If any UUID was not found, on to the next record */ + if (xx == p_rec->num_attributes) break; } - /* If here, no more records found */ - return (NULL); + /* If every UUID was found in the record, return the record */ + if (yy == p_seq->num_uids) return (p_rec); + } + + /* If here, no more records found */ + return (NULL); } /******************************************************************************* @@ -115,37 +106,30 @@ tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq) * Returns true if found, else false * ******************************************************************************/ -static bool find_uuid_in_seq (uint8_t *p , uint32_t seq_len, uint8_t *p_uuid, - uint16_t uuid_len, int nest_level) -{ - uint8_t *p_end = p + seq_len; - uint8_t type; - uint32_t len; - - /* A little safety check to avoid excessive recursion */ - if (nest_level > 3) - return (false); - - while (p < p_end) - { - type = *p++; - p = sdpu_get_len_from_type (p, type, &len); - type = type >> 3; - if (type == UUID_DESC_TYPE) - { - if (sdpu_compare_uuid_arrays (p, len, p_uuid, uuid_len)) - return (true); - } - else if (type == DATA_ELE_SEQ_DESC_TYPE) - { - if (find_uuid_in_seq (p, len, p_uuid, uuid_len, nest_level + 1)) - return (true); - } - p = p + len; +static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_uuid, + uint16_t uuid_len, int nest_level) { + uint8_t* p_end = p + seq_len; + uint8_t type; + uint32_t len; + + /* A little safety check to avoid excessive recursion */ + if (nest_level > 3) return (false); + + while (p < p_end) { + type = *p++; + p = sdpu_get_len_from_type(p, type, &len); + type = type >> 3; + if (type == UUID_DESC_TYPE) { + if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true); + } else if (type == DATA_ELE_SEQ_DESC_TYPE) { + if (find_uuid_in_seq(p, len, p_uuid, uuid_len, nest_level + 1)) + return (true); } + p = p + len; + } - /* If here, failed to match */ - return (false); + /* If here, failed to match */ + return (false); } /******************************************************************************* @@ -158,20 +142,17 @@ static bool find_uuid_in_seq (uint8_t *p , uint32_t seq_len, uint8_t *p_uuid, * Returns Pointer to the record, or NULL if not found. * ******************************************************************************/ -tSDP_RECORD *sdp_db_find_record (uint32_t handle) -{ - tSDP_RECORD *p_rec; - tSDP_RECORD *p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records]; - - /* Look through the records for the caller's handle */ - for (p_rec = &sdp_cb.server_db.record[0]; p_rec < p_end; p_rec++) - { - if (p_rec->record_handle == handle) - return (p_rec); - } +tSDP_RECORD* sdp_db_find_record(uint32_t handle) { + tSDP_RECORD* p_rec; + tSDP_RECORD* p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records]; + + /* Look through the records for the caller's handle */ + for (p_rec = &sdp_cb.server_db.record[0]; p_rec < p_end; p_rec++) { + if (p_rec->record_handle == handle) return (p_rec); + } - /* Record with that handle not found. */ - return (NULL); + /* Record with that handle not found. */ + return (NULL); } /******************************************************************************* @@ -186,25 +167,21 @@ tSDP_RECORD *sdp_db_find_record (uint32_t handle) * Returns Pointer to the attribute, or NULL if not found. * ******************************************************************************/ -tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, uint16_t start_attr, - uint16_t end_attr) -{ - tSDP_ATTRIBUTE *p_at; - uint16_t xx; - - /* Note that the attributes in a record are assumed to be in sorted order */ - for (xx = 0, p_at = &p_rec->attribute[0]; xx < p_rec->num_attributes; - xx++, p_at++) - { - if ((p_at->id >= start_attr) && (p_at->id <= end_attr)) - return (p_at); - } - - /* No matching attribute found */ - return (NULL); +tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(tSDP_RECORD* p_rec, uint16_t start_attr, + uint16_t end_attr) { + tSDP_ATTRIBUTE* p_at; + uint16_t xx; + + /* Note that the attributes in a record are assumed to be in sorted order */ + for (xx = 0, p_at = &p_rec->attribute[0]; xx < p_rec->num_attributes; + xx++, p_at++) { + if ((p_at->id >= start_attr) && (p_at->id <= end_attr)) return (p_at); + } + + /* No matching attribute found */ + return (NULL); } - /******************************************************************************* * * Function sdp_compose_proto_list @@ -215,54 +192,48 @@ tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, uint16_t start_attr * Returns the length of the data sequence * ******************************************************************************/ -static int sdp_compose_proto_list( uint8_t *p, uint16_t num_elem, - tSDP_PROTOCOL_ELEM *p_elem_list) -{ - uint16_t xx, yy, len; - bool is_rfcomm_scn; - uint8_t *p_head = p; - uint8_t *p_len; - - /* First, build the protocol list. This consists of a set of data element - ** sequences, one for each layer. Each layer sequence consists of layer's - ** UUID and optional parameters - */ - for (xx = 0; xx < num_elem; xx++, p_elem_list++) - { - len = 3 + (p_elem_list->num_params * 3); - UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - - p_len = p; - *p++ = (uint8_t) len; - - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, p_elem_list->protocol_uuid); - - if (p_elem_list->protocol_uuid == UUID_PROTOCOL_RFCOMM) - is_rfcomm_scn = true; - else - is_rfcomm_scn = false; - - for (yy = 0; yy < p_elem_list->num_params; yy++) - { - if (is_rfcomm_scn) - { - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE); - UINT8_TO_BE_STREAM (p, p_elem_list->params[yy]); - - *p_len -= 1; - } - else - { - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, p_elem_list->params[yy]); - } - } +static int sdp_compose_proto_list(uint8_t* p, uint16_t num_elem, + tSDP_PROTOCOL_ELEM* p_elem_list) { + uint16_t xx, yy, len; + bool is_rfcomm_scn; + uint8_t* p_head = p; + uint8_t* p_len; + + /* First, build the protocol list. This consists of a set of data element + ** sequences, one for each layer. Each layer sequence consists of layer's + ** UUID and optional parameters + */ + for (xx = 0; xx < num_elem; xx++, p_elem_list++) { + len = 3 + (p_elem_list->num_params * 3); + UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + + p_len = p; + *p++ = (uint8_t)len; + + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, p_elem_list->protocol_uuid); + + if (p_elem_list->protocol_uuid == UUID_PROTOCOL_RFCOMM) + is_rfcomm_scn = true; + else + is_rfcomm_scn = false; + + for (yy = 0; yy < p_elem_list->num_params; yy++) { + if (is_rfcomm_scn) { + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE); + UINT8_TO_BE_STREAM(p, p_elem_list->params[yy]); + + *p_len -= 1; + } else { + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, p_elem_list->params[yy]); + } } - return (p - p_head); + } + return (p - p_head); } -#endif /* SDP_SERVER_ENABLED == TRUE */ +#endif /* SDP_SERVER_ENABLED == TRUE */ /******************************************************************************* * @@ -276,43 +247,40 @@ static int sdp_compose_proto_list( uint8_t *p, uint16_t num_elem, * Returns Record handle if OK, else 0. * ******************************************************************************/ -uint32_t SDP_CreateRecord (void) -{ +uint32_t SDP_CreateRecord(void) { #if (SDP_SERVER_ENABLED == TRUE) - uint32_t handle; - uint8_t buf[4]; - tSDP_DB *p_db = &sdp_cb.server_db; - - /* First, check if there is a free record */ - if (p_db->num_records < SDP_MAX_RECORDS) - { - memset (&p_db->record[p_db->num_records], 0, - sizeof (tSDP_RECORD)); - - /* We will use a handle of the first unreserved handle plus last record - ** number + 1 */ - if (p_db->num_records) - handle = p_db->record[p_db->num_records - 1].record_handle + 1; - else - handle = 0x10000; - - p_db->record[p_db->num_records].record_handle = handle; - - p_db->num_records++; - SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d", p_db->num_records); - /* Add the first attribute (the handle) automatically */ - UINT32_TO_BE_FIELD (buf, handle); - SDP_AddAttribute (handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE, - 4, buf); - - return (p_db->record[p_db->num_records - 1].record_handle); - } - else SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d", SDP_MAX_RECORDS); + uint32_t handle; + uint8_t buf[4]; + tSDP_DB* p_db = &sdp_cb.server_db; + + /* First, check if there is a free record */ + if (p_db->num_records < SDP_MAX_RECORDS) { + memset(&p_db->record[p_db->num_records], 0, sizeof(tSDP_RECORD)); + + /* We will use a handle of the first unreserved handle plus last record + ** number + 1 */ + if (p_db->num_records) + handle = p_db->record[p_db->num_records - 1].record_handle + 1; + else + handle = 0x10000; + + p_db->record[p_db->num_records].record_handle = handle; + + p_db->num_records++; + SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d", p_db->num_records); + /* Add the first attribute (the handle) automatically */ + UINT32_TO_BE_FIELD(buf, handle); + SDP_AddAttribute(handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE, 4, + buf); + + return (p_db->record[p_db->num_records - 1].record_handle); + } else + SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d", + SDP_MAX_RECORDS); #endif - return (0); + return (0); } - /******************************************************************************* * * Function SDP_DeleteRecord @@ -326,58 +294,50 @@ uint32_t SDP_CreateRecord (void) * Returns true if succeeded, else false * ******************************************************************************/ -bool SDP_DeleteRecord (uint32_t handle) -{ +bool SDP_DeleteRecord(uint32_t handle) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx, yy, zz; - tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0]; + uint16_t xx, yy, zz; + tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0]; - if (handle == 0 || sdp_cb.server_db.num_records == 0) - { - /* Delete all records in the database */ - sdp_cb.server_db.num_records = 0; + if (handle == 0 || sdp_cb.server_db.num_records == 0) { + /* Delete all records in the database */ + sdp_cb.server_db.num_records = 0; - /* require new DI record to be created in SDP_SetLocalDiRecord */ - sdp_cb.server_db.di_primary_handle = 0; + /* require new DI record to be created in SDP_SetLocalDiRecord */ + sdp_cb.server_db.di_primary_handle = 0; - return (true); - } - else - { - /* Find the record in the database */ - for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) - { - if (p_rec->record_handle == handle) - { - /* Found it. Shift everything up one */ - for (yy = xx; yy < sdp_cb.server_db.num_records; yy++, p_rec++) - { - *p_rec = *(p_rec + 1); - - /* Adjust the attribute value pointer for each attribute */ - for (zz = 0; zz < p_rec->num_attributes; zz++) - p_rec->attribute[zz].value_ptr -= sizeof(tSDP_RECORD); - } - - sdp_cb.server_db.num_records--; - - SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d", sdp_cb.server_db.num_records); - /* if we're deleting the primary DI record, clear the */ - /* value in the control block */ - if( sdp_cb.server_db.di_primary_handle == handle ) - { - sdp_cb.server_db.di_primary_handle = 0; - } - - return (true); - } + return (true); + } else { + /* Find the record in the database */ + for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) { + if (p_rec->record_handle == handle) { + /* Found it. Shift everything up one */ + for (yy = xx; yy < sdp_cb.server_db.num_records; yy++, p_rec++) { + *p_rec = *(p_rec + 1); + + /* Adjust the attribute value pointer for each attribute */ + for (zz = 0; zz < p_rec->num_attributes; zz++) + p_rec->attribute[zz].value_ptr -= sizeof(tSDP_RECORD); } + + sdp_cb.server_db.num_records--; + + SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d", + sdp_cb.server_db.num_records); + /* if we're deleting the primary DI record, clear the */ + /* value in the control block */ + if (sdp_cb.server_db.di_primary_handle == handle) { + sdp_cb.server_db.di_primary_handle = 0; + } + + return (true); + } } + } #endif - return (false); + return (false); } - /******************************************************************************* * * Function SDP_AddAttribute @@ -392,122 +352,110 @@ bool SDP_DeleteRecord (uint32_t handle) * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddAttribute (uint32_t handle, uint16_t attr_id, uint8_t attr_type, - uint32_t attr_len, uint8_t *p_val) -{ +bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type, + uint32_t attr_len, uint8_t* p_val) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx, yy, zz; - tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0]; - - if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) - { - if ((attr_type == UINT_DESC_TYPE) || - (attr_type == TWO_COMP_INT_DESC_TYPE) || - (attr_type == UUID_DESC_TYPE) || - (attr_type == DATA_ELE_SEQ_DESC_TYPE) || - (attr_type == DATA_ELE_ALT_DESC_TYPE)) - { - uint8_t num_array[400]; - uint32_t len = (attr_len > 200) ? 200 : attr_len; - - num_array[0] ='\0'; - for (uint32_t i = 0; i < len; i++) - { - snprintf((char *)&num_array[i*2], sizeof(num_array) - i*2, - "%02X",(uint8_t)(p_val[i])); - } - SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s", - handle,attr_id,attr_type,attr_len,p_val,num_array); - } - else if (attr_type == BOOLEAN_DESC_TYPE) - { - SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%d", - handle,attr_id,attr_type,attr_len,p_val,*p_val); - } - else - { - SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s", - handle,attr_id,attr_type,attr_len,p_val,p_val); - } + uint16_t xx, yy, zz; + tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0]; + + if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) { + if ((attr_type == UINT_DESC_TYPE) || + (attr_type == TWO_COMP_INT_DESC_TYPE) || + (attr_type == UUID_DESC_TYPE) || + (attr_type == DATA_ELE_SEQ_DESC_TYPE) || + (attr_type == DATA_ELE_ALT_DESC_TYPE)) { + uint8_t num_array[400]; + uint32_t len = (attr_len > 200) ? 200 : attr_len; + + num_array[0] = '\0'; + for (uint32_t i = 0; i < len; i++) { + snprintf((char*)&num_array[i * 2], sizeof(num_array) - i * 2, "%02X", + (uint8_t)(p_val[i])); + } + SDP_TRACE_DEBUG( + "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, " + "*p_val:%s", + handle, attr_id, attr_type, attr_len, p_val, num_array); + } else if (attr_type == BOOLEAN_DESC_TYPE) { + SDP_TRACE_DEBUG( + "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, " + "*p_val:%d", + handle, attr_id, attr_type, attr_len, p_val, *p_val); + } else { + SDP_TRACE_DEBUG( + "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, " + "*p_val:%s", + handle, attr_id, attr_type, attr_len, p_val, p_val); } - - /* Find the record in the database */ - for (zz = 0; zz < sdp_cb.server_db.num_records; zz++, p_rec++) - { - if (p_rec->record_handle == handle) - { - tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0]; - - /* Found the record. Now, see if the attribute already exists */ - for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) - { - /* The attribute exists. replace it */ - if (p_attr->id == attr_id) - { - SDP_DeleteAttribute (handle, attr_id); - break; - } - if (p_attr->id > attr_id) - break; - } - - if (p_rec->num_attributes == SDP_MAX_REC_ATTR) - return (false); - - /* If not found, see if we can allocate a new entry */ - if (xx == p_rec->num_attributes) - p_attr = &p_rec->attribute[p_rec->num_attributes]; - else - { - /* Since the attributes are kept in sorted order, insert ours here */ - for (yy = p_rec->num_attributes; yy > xx; yy--) - p_rec->attribute[yy] = p_rec->attribute[yy - 1]; - } - - p_attr->id = attr_id; - p_attr->type = attr_type; - p_attr->len = attr_len; - - if (p_rec->free_pad_ptr + attr_len >= SDP_MAX_PAD_LEN) - { - /* do truncate only for text string type descriptor */ - if (attr_type == TEXT_STR_DESC_TYPE) - { - SDP_TRACE_WARNING("SDP_AddAttribute: attr_len:%d too long. truncate to (%d)", - attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr ); - - attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr; - p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr] = '\0'; - p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr+1] = '\0'; - } - else - attr_len = 0; - } - - if ((attr_len > 0) && (p_val != 0)) - { - p_attr->len = attr_len; - memcpy (&p_rec->attr_pad[p_rec->free_pad_ptr], p_val, (size_t)attr_len); - p_attr->value_ptr = &p_rec->attr_pad[p_rec->free_pad_ptr]; - p_rec->free_pad_ptr += attr_len; - } - else if ((attr_len == 0 && p_attr->len != 0) || /* if truncate to 0 length, simply don't add */ - p_val == 0) - { - SDP_TRACE_ERROR("SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d ", - attr_id, attr_len ); - p_attr->id = p_attr->type = p_attr->len = 0; - return (false); - } - p_rec->num_attributes++; - return (true); + } + + /* Find the record in the database */ + for (zz = 0; zz < sdp_cb.server_db.num_records; zz++, p_rec++) { + if (p_rec->record_handle == handle) { + tSDP_ATTRIBUTE* p_attr = &p_rec->attribute[0]; + + /* Found the record. Now, see if the attribute already exists */ + for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) { + /* The attribute exists. replace it */ + if (p_attr->id == attr_id) { + SDP_DeleteAttribute(handle, attr_id); + break; } + if (p_attr->id > attr_id) break; + } + + if (p_rec->num_attributes == SDP_MAX_REC_ATTR) return (false); + + /* If not found, see if we can allocate a new entry */ + if (xx == p_rec->num_attributes) + p_attr = &p_rec->attribute[p_rec->num_attributes]; + else { + /* Since the attributes are kept in sorted order, insert ours here */ + for (yy = p_rec->num_attributes; yy > xx; yy--) + p_rec->attribute[yy] = p_rec->attribute[yy - 1]; + } + + p_attr->id = attr_id; + p_attr->type = attr_type; + p_attr->len = attr_len; + + if (p_rec->free_pad_ptr + attr_len >= SDP_MAX_PAD_LEN) { + /* do truncate only for text string type descriptor */ + if (attr_type == TEXT_STR_DESC_TYPE) { + SDP_TRACE_WARNING( + "SDP_AddAttribute: attr_len:%d too long. truncate to (%d)", + attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr); + + attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr; + p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr] = '\0'; + p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr + 1] = '\0'; + } else + attr_len = 0; + } + + if ((attr_len > 0) && (p_val != 0)) { + p_attr->len = attr_len; + memcpy(&p_rec->attr_pad[p_rec->free_pad_ptr], p_val, (size_t)attr_len); + p_attr->value_ptr = &p_rec->attr_pad[p_rec->free_pad_ptr]; + p_rec->free_pad_ptr += attr_len; + } else if ((attr_len == 0 && + p_attr->len != + 0) || /* if truncate to 0 length, simply don't add */ + p_val == 0) { + SDP_TRACE_ERROR( + "SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d ", + attr_id, attr_len); + p_attr->id = p_attr->type = p_attr->len = 0; + return (false); + } + p_rec->num_attributes++; + return (true); } + } #endif - return (false); + return (false); } - /******************************************************************************* * * Function SDP_AddSequence @@ -522,72 +470,68 @@ bool SDP_AddAttribute (uint32_t handle, uint16_t attr_id, uint8_t attr_type, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddSequence (uint32_t handle, uint16_t attr_id, uint16_t num_elem, - uint8_t type[], uint8_t len[], uint8_t *p_val[]) -{ +bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem, + uint8_t type[], uint8_t len[], uint8_t* p_val[]) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx; - uint8_t *p; - uint8_t *p_head; - bool result; - uint8_t *p_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); - - p = p_buff; - - /* First, build the sequence */ - for (xx = 0; xx < num_elem; xx++) - { - p_head = p; - switch (len[xx]) - { - case 1: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_ONE_BYTE); - break; - case 2: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_TWO_BYTES); - break; - case 4: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_FOUR_BYTES); - break; - case 8: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_EIGHT_BYTES); - break; - case 16: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_SIXTEEN_BYTES); - break; - default: - UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_IN_NEXT_BYTE); - UINT8_TO_BE_STREAM (p, len[xx]); - break; - } + uint16_t xx; + uint8_t* p; + uint8_t* p_head; + bool result; + uint8_t* p_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); + + p = p_buff; + + /* First, build the sequence */ + for (xx = 0; xx < num_elem; xx++) { + p_head = p; + switch (len[xx]) { + case 1: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_ONE_BYTE); + break; + case 2: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_TWO_BYTES); + break; + case 4: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_FOUR_BYTES); + break; + case 8: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_EIGHT_BYTES); + break; + case 16: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_SIXTEEN_BYTES); + break; + default: + UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_IN_NEXT_BYTE); + UINT8_TO_BE_STREAM(p, len[xx]); + break; + } - ARRAY_TO_BE_STREAM (p, p_val[xx], len[xx]); - - if (p - p_buff > SDP_MAX_ATTR_LEN) - { - /* go back to before we add this element */ - p = p_head; - if(p_head == p_buff) - { - /* the first element exceed the max length */ - SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!"); - osi_free(p_buff); - return false; - } - else - SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d", xx, num_elem); - break; - } + ARRAY_TO_BE_STREAM(p, p_val[xx], len[xx]); + + if (p - p_buff > SDP_MAX_ATTR_LEN) { + /* go back to before we add this element */ + p = p_head; + if (p_head == p_buff) { + /* the first element exceed the max length */ + SDP_TRACE_ERROR("SDP_AddSequence - too long(attribute is not added)!!"); + osi_free(p_buff); + return false; + } else + SDP_TRACE_ERROR("SDP_AddSequence - too long, add %d elements of %d", xx, + num_elem); + break; } - result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,(uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + } + result = SDP_AddAttribute(handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, + (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } - /******************************************************************************* * * Function SDP_AddUuidSequence @@ -600,36 +544,36 @@ bool SDP_AddSequence (uint32_t handle, uint16_t attr_id, uint16_t num_elem, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddUuidSequence (uint32_t handle, uint16_t attr_id, uint16_t num_uuids, - uint16_t *p_uuids) -{ +bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids, + uint16_t* p_uuids) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx; - uint8_t *p; - int32_t max_len = SDP_MAX_ATTR_LEN -3; - bool result; - uint8_t *p_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); - - p = p_buff; - - /* First, build the sequence */ - for (xx = 0; xx < num_uuids ; xx++, p_uuids++) - { - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, *p_uuids); - - if((p - p_buff) > max_len) - { - SDP_TRACE_WARNING ("SDP_AddUuidSequence - too long, add %d uuids of %d", xx, num_uuids); - break; - } + uint16_t xx; + uint8_t* p; + int32_t max_len = SDP_MAX_ATTR_LEN - 3; + bool result; + uint8_t* p_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); + + p = p_buff; + + /* First, build the sequence */ + for (xx = 0; xx < num_uuids; xx++, p_uuids++) { + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, *p_uuids); + + if ((p - p_buff) > max_len) { + SDP_TRACE_WARNING("SDP_AddUuidSequence - too long, add %d uuids of %d", + xx, num_uuids); + break; } - - result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,(uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + } + + result = SDP_AddAttribute(handle, attr_id, DATA_ELE_SEQ_DESC_TYPE, + (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } @@ -645,24 +589,24 @@ bool SDP_AddUuidSequence (uint32_t handle, uint16_t attr_id, uint16_t num_uu * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddProtocolList (uint32_t handle, uint16_t num_elem, - tSDP_PROTOCOL_ELEM *p_elem_list) -{ +bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem, + tSDP_PROTOCOL_ELEM* p_elem_list) { #if (SDP_SERVER_ENABLED == TRUE) - int offset; - bool result; - uint8_t *p_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); - - offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list); - result = SDP_AddAttribute (handle, ATTR_ID_PROTOCOL_DESC_LIST,DATA_ELE_SEQ_DESC_TYPE, (uint32_t) offset, p_buff); - osi_free(p_buff); - return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + int offset; + bool result; + uint8_t* p_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); + + offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list); + result = SDP_AddAttribute(handle, ATTR_ID_PROTOCOL_DESC_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)offset, p_buff); + osi_free(p_buff); + return result; +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } - /******************************************************************************* * * Function SDP_AddAdditionProtoLists @@ -675,38 +619,38 @@ bool SDP_AddProtocolList (uint32_t handle, uint16_t num_elem, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddAdditionProtoLists (uint32_t handle, uint16_t num_elem, - tSDP_PROTO_LIST_ELEM *p_proto_list) -{ +bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem, + tSDP_PROTO_LIST_ELEM* p_proto_list) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx; - uint8_t *p; - uint8_t *p_len; - int offset; - bool result; - uint8_t *p_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); - - p = p_buff; - - /* for each ProtocolDescriptorList */ - for (xx = 0; xx < num_elem; xx++, p_proto_list++) - { - UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - p_len = p++; - - offset = sdp_compose_proto_list(p, p_proto_list->num_elems, - p_proto_list->list_elem); - p += offset; - - *p_len = (uint8_t)(p - p_len - 1); - } - result = SDP_AddAttribute (handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS,DATA_ELE_SEQ_DESC_TYPE, - (uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; - -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + uint16_t xx; + uint8_t* p; + uint8_t* p_len; + int offset; + bool result; + uint8_t* p_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); + + p = p_buff; + + /* for each ProtocolDescriptorList */ + for (xx = 0; xx < num_elem; xx++, p_proto_list++) { + UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + p_len = p++; + + offset = sdp_compose_proto_list(p, p_proto_list->num_elems, + p_proto_list->list_elem); + p += offset; + + *p_len = (uint8_t)(p - p_len - 1); + } + result = + SDP_AddAttribute(handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; + +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } @@ -722,38 +666,39 @@ bool SDP_AddAdditionProtoLists (uint32_t handle, uint16_t num_elem, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddProfileDescriptorList (uint32_t handle, uint16_t profile_uuid, - uint16_t version) -{ +bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid, + uint16_t version) { #if (SDP_SERVER_ENABLED == TRUE) - uint8_t *p; - bool result; - uint8_t *p_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); + uint8_t* p; + bool result; + uint8_t* p_buff = (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); - p = p_buff + 2; + p = p_buff + 2; - /* First, build the profile descriptor list. This consists of a data element sequence. */ - /* The sequence consists of profile's UUID and version number */ - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, profile_uuid); + /* First, build the profile descriptor list. This consists of a data element + * sequence. */ + /* The sequence consists of profile's UUID and version number */ + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, profile_uuid); - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, version); + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, version); - /* Add in type and length fields */ - *p_buff = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - *(p_buff+1) = (uint8_t) (p - (p_buff+2)); + /* Add in type and length fields */ + *p_buff = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + *(p_buff + 1) = (uint8_t)(p - (p_buff + 2)); - result = SDP_AddAttribute (handle, ATTR_ID_BT_PROFILE_DESC_LIST,DATA_ELE_SEQ_DESC_TYPE, (uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; + result = + SDP_AddAttribute(handle, ATTR_ID_BT_PROFILE_DESC_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } - /******************************************************************************* * * Function SDP_AddLanguageBaseAttrIDList @@ -766,37 +711,36 @@ bool SDP_AddProfileDescriptorList (uint32_t handle, uint16_t profile_uuid, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddLanguageBaseAttrIDList (uint32_t handle, uint16_t lang, - uint16_t char_enc, uint16_t base_id) -{ +bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang, + uint16_t char_enc, uint16_t base_id) { #if (SDP_SERVER_ENABLED == TRUE) - uint8_t *p; - bool result; - uint8_t *p_buff = (uint8_t *) osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); - - p = p_buff; - - /* First, build the language base descriptor list. This consists of a data */ - /* element sequence. The sequence consists of 9 bytes (3 UINt16 fields) */ - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, lang); - - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, char_enc); - - UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, base_id); - - result = SDP_AddAttribute (handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST,DATA_ELE_SEQ_DESC_TYPE, - (uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + uint8_t* p; + bool result; + uint8_t* p_buff = (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); + + p = p_buff; + + /* First, build the language base descriptor list. This consists of a data */ + /* element sequence. The sequence consists of 9 bytes (3 UINt16 fields) */ + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, lang); + + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, char_enc); + + UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, base_id); + + result = + SDP_AddAttribute(handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } - /******************************************************************************* * * Function SDP_AddServiceClassIdList @@ -809,33 +753,32 @@ bool SDP_AddLanguageBaseAttrIDList (uint32_t handle, uint16_t lang, * Returns true if added OK, else false * ******************************************************************************/ -bool SDP_AddServiceClassIdList (uint32_t handle, uint16_t num_services, - uint16_t *p_service_uuids) -{ +bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services, + uint16_t* p_service_uuids) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx; - uint8_t *p; - bool result; - uint8_t *p_buff = (uint8_t *) osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); - - p = p_buff; - - for (xx = 0; xx < num_services; xx++, p_service_uuids++) - { - UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p, *p_service_uuids); - } - - result = SDP_AddAttribute (handle, ATTR_ID_SERVICE_CLASS_ID_LIST,DATA_ELE_SEQ_DESC_TYPE, - (uint32_t) (p - p_buff), p_buff); - osi_free(p_buff); - return result; -#else /* SDP_SERVER_ENABLED == FALSE */ - return (false); + uint16_t xx; + uint8_t* p; + bool result; + uint8_t* p_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2); + + p = p_buff; + + for (xx = 0; xx < num_services; xx++, p_service_uuids++) { + UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p, *p_service_uuids); + } + + result = + SDP_AddAttribute(handle, ATTR_ID_SERVICE_CLASS_ID_LIST, + DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff); + osi_free(p_buff); + return result; +#else /* SDP_SERVER_ENABLED == FALSE */ + return (false); #endif } - /******************************************************************************* * * Function SDP_DeleteAttribute @@ -847,64 +790,54 @@ bool SDP_AddServiceClassIdList (uint32_t handle, uint16_t num_services, * Returns true if deleted OK, else false if not found * ******************************************************************************/ -bool SDP_DeleteAttribute (uint32_t handle, uint16_t attr_id) -{ +bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id) { #if (SDP_SERVER_ENABLED == TRUE) - uint16_t xx, yy; - tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0]; - uint8_t *pad_ptr; - uint32_t len; /* Number of bytes in the entry */ - - /* Find the record in the database */ - for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) - { - if (p_rec->record_handle == handle) - { - tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0]; - - SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle); - /* Found it. Now, find the attribute */ - for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) - { - if (p_attr->id == attr_id) - { - pad_ptr = p_attr->value_ptr; - len = p_attr->len; - - if (len) - { - for (yy = 0; yy < p_rec->num_attributes; yy++) - { - if( p_rec->attribute[yy].value_ptr > pad_ptr ) - p_rec->attribute[yy].value_ptr -= len; - } - } - - /* Found it. Shift everything up one */ - p_rec->num_attributes--; - - for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++) - { - *p_attr = *(p_attr + 1); - } - - /* adjust attribute values if needed */ - if (len) - { - xx = (p_rec->free_pad_ptr - ((pad_ptr+len) - - &p_rec->attr_pad[0])); - for( yy=0; yyfree_pad_ptr -= len; - } - return (true); - } + uint16_t xx, yy; + tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0]; + uint8_t* pad_ptr; + uint32_t len; /* Number of bytes in the entry */ + + /* Find the record in the database */ + for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) { + if (p_rec->record_handle == handle) { + tSDP_ATTRIBUTE* p_attr = &p_rec->attribute[0]; + + SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle); + /* Found it. Now, find the attribute */ + for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) { + if (p_attr->id == attr_id) { + pad_ptr = p_attr->value_ptr; + len = p_attr->len; + + if (len) { + for (yy = 0; yy < p_rec->num_attributes; yy++) { + if (p_rec->attribute[yy].value_ptr > pad_ptr) + p_rec->attribute[yy].value_ptr -= len; } + } + + /* Found it. Shift everything up one */ + p_rec->num_attributes--; + + for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++) { + *p_attr = *(p_attr + 1); + } + + /* adjust attribute values if needed */ + if (len) { + xx = + (p_rec->free_pad_ptr - ((pad_ptr + len) - &p_rec->attr_pad[0])); + for (yy = 0; yy < xx; yy++, pad_ptr++) *pad_ptr = *(pad_ptr + len); + p_rec->free_pad_ptr -= len; + } + return (true); } + } } + } #endif - /* If here, not found */ - return (false); + /* If here, not found */ + return (false); } /******************************************************************************* @@ -921,59 +854,52 @@ bool SDP_DeleteAttribute (uint32_t handle, uint16_t attr_id) * ******************************************************************************/ #if (SDP_RAW_DATA_INCLUDED == TRUE) -int32_t SDP_ReadRecord(uint32_t handle, uint8_t *p_data, int32_t *p_data_len) -{ - int32_t len = 0; /* Number of bytes in the entry */ - int32_t offset = -1; /* default to not found */ +int32_t SDP_ReadRecord(uint32_t handle, uint8_t* p_data, int32_t* p_data_len) { + int32_t len = 0; /* Number of bytes in the entry */ + int32_t offset = -1; /* default to not found */ #if (SDP_SERVER_ENABLED == TRUE) - tSDP_RECORD *p_rec; - uint16_t start = 0; - uint16_t end = 0xffff; - tSDP_ATTRIBUTE *p_attr; - uint16_t rem_len; - uint8_t *p_rsp; + tSDP_RECORD* p_rec; + uint16_t start = 0; + uint16_t end = 0xffff; + tSDP_ATTRIBUTE* p_attr; + uint16_t rem_len; + uint8_t* p_rsp; + + /* Find the record in the database */ + p_rec = sdp_db_find_record(handle); + if (p_rec && p_data && p_data_len) { + p_rsp = &p_data[3]; + while ((p_attr = sdp_db_find_attr_in_rec(p_rec, start, end)) != NULL) { + /* Check if attribute fits. Assume 3-byte value type/length */ + rem_len = *p_data_len - (uint16_t)(p_rsp - p_data); + + if (p_attr->len > (uint32_t)(rem_len - 6)) break; + + p_rsp = sdpu_build_attrib_entry(p_rsp, p_attr); + + /* next attr id */ + start = p_attr->id + 1; + } + len = (int32_t)(p_rsp - p_data); - /* Find the record in the database */ - p_rec = sdp_db_find_record(handle); - if(p_rec && p_data && p_data_len) - { - p_rsp = &p_data[3]; - while ( (p_attr = sdp_db_find_attr_in_rec (p_rec, start, end)) != NULL) - { - /* Check if attribute fits. Assume 3-byte value type/length */ - rem_len = *p_data_len - (uint16_t) (p_rsp - p_data); - - if (p_attr->len > (uint32_t)(rem_len - 6)) - break; - - p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr); - - /* next attr id */ - start = p_attr->id + 1; - } - len = (int32_t) (p_rsp - p_data); - - /* Put in the sequence header (2 or 3 bytes) */ - if (len > 255) - { - offset = 0; - p_data[0] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); - p_data[1] = (uint8_t) ((len - 3) >> 8); - p_data[2] = (uint8_t) (len - 3); - } - else - { - offset = 1; + /* Put in the sequence header (2 or 3 bytes) */ + if (len > 255) { + offset = 0; + p_data[0] = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); + p_data[1] = (uint8_t)((len - 3) >> 8); + p_data[2] = (uint8_t)(len - 3); + } else { + offset = 1; - p_data[1] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - p_data[2] = (uint8_t) (len - 3); + p_data[1] = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + p_data[2] = (uint8_t)(len - 3); - len--; - } - *p_data_len = len; + len--; } + *p_data_len = len; + } #endif - /* If here, not found */ - return (offset); + /* If here, not found */ + return (offset); } #endif diff --git a/stack/sdp/sdp_discovery.cc b/stack/sdp/sdp_discovery.cc index cbffd8d95..698b9aa99 100644 --- a/stack/sdp/sdp_discovery.cc +++ b/stack/sdp/sdp_discovery.cc @@ -22,41 +22,41 @@ * ******************************************************************************/ +#include #include #include -#include -#include "bt_target.h" #include "bt_common.h" -#include "l2cdefs.h" +#include "bt_target.h" +#include "btm_api.h" +#include "btu.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "sdp_api.h" #include "sdpint.h" -#include "btu.h" -#include "btm_api.h" - #ifndef SDP_DEBUG_RAW -#define SDP_DEBUG_RAW false +#define SDP_DEBUG_RAW false #endif /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ #if (SDP_CLIENT_ENABLED == TRUE) -static void process_service_search_rsp (tCONN_CB *p_ccb, uint8_t *p_reply); -static void process_service_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply); -static void process_service_search_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply); -static uint8_t *save_attr_seq (tCONN_CB *p_ccb, uint8_t *p, uint8_t *p_msg_end); -static tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda); -static uint8_t *add_attr (uint8_t *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec, - uint16_t attr_id, tSDP_DISC_ATTR *p_parent_attr, uint8_t nest_level); +static void process_service_search_rsp(tCONN_CB* p_ccb, uint8_t* p_reply); +static void process_service_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply); +static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply); +static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end); +static tSDP_DISC_REC* add_record(tSDP_DISCOVERY_DB* p_db, BD_ADDR p_bda); +static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_REC* p_rec, uint16_t attr_id, + tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level); /* Safety check in case we go crazy */ -#define MAX_NEST_LEVELS 5 +#define MAX_NEST_LEVELS 5 -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************* * @@ -69,43 +69,37 @@ extern fixed_queue_t *btu_general_alarm_queue; * Returns Pointer to next byte in the output buffer. * ******************************************************************************/ -static uint8_t *sdpu_build_uuid_seq (uint8_t *p_out, uint16_t num_uuids, tSDP_UUID *p_uuid_list) -{ - uint16_t xx; - uint8_t *p_len; - - /* First thing is the data element header */ - UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - - /* Remember where the length goes. Leave space for it. */ - p_len = p_out; - p_out += 1; - - /* Now, loop through and put in all the UUID(s) */ - for (xx = 0; xx < num_uuids; xx++, p_uuid_list++) - { - if (p_uuid_list->len == 2) - { - UINT8_TO_BE_STREAM (p_out, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p_out, p_uuid_list->uu.uuid16); - } - else if (p_uuid_list->len == 4) - { - UINT8_TO_BE_STREAM (p_out, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES); - UINT32_TO_BE_STREAM (p_out, p_uuid_list->uu.uuid32); - } - else - { - UINT8_TO_BE_STREAM (p_out, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES); - ARRAY_TO_BE_STREAM (p_out, p_uuid_list->uu.uuid128, p_uuid_list->len); - } +static uint8_t* sdpu_build_uuid_seq(uint8_t* p_out, uint16_t num_uuids, + tSDP_UUID* p_uuid_list) { + uint16_t xx; + uint8_t* p_len; + + /* First thing is the data element header */ + UINT8_TO_BE_STREAM(p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + + /* Remember where the length goes. Leave space for it. */ + p_len = p_out; + p_out += 1; + + /* Now, loop through and put in all the UUID(s) */ + for (xx = 0; xx < num_uuids; xx++, p_uuid_list++) { + if (p_uuid_list->len == 2) { + UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid16); + } else if (p_uuid_list->len == 4) { + UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_FOUR_BYTES); + UINT32_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid32); + } else { + UINT8_TO_BE_STREAM(p_out, (UUID_DESC_TYPE << 3) | SIZE_SIXTEEN_BYTES); + ARRAY_TO_BE_STREAM(p_out, p_uuid_list->uu.uuid128, p_uuid_list->len); } + } - /* Now, put in the length */ - xx = (uint16_t)(p_out - p_len - 1); - UINT8_TO_BE_STREAM (p_len, xx); + /* Now, put in the length */ + xx = (uint16_t)(p_out - p_len - 1); + UINT8_TO_BE_STREAM(p_len, xx); - return (p_out); + return (p_out); } /******************************************************************************* @@ -117,64 +111,65 @@ static uint8_t *sdpu_build_uuid_seq (uint8_t *p_out, uint16_t num_uuids, tSDP_UU * Returns void * ******************************************************************************/ -static void sdp_snd_service_search_req(tCONN_CB *p_ccb, uint8_t cont_len, uint8_t * p_cont) -{ - uint8_t *p, *p_start, *p_param_len; - BT_HDR *p_cmd = (BT_HDR *) osi_malloc(SDP_DATA_BUF_SIZE); - uint16_t param_len; - - /* Prepare the buffer for sending the packet to L2CAP */ - p_cmd->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t *)(p_cmd + 1) + L2CAP_MIN_OFFSET; - - /* Build a service search request packet */ - UINT8_TO_BE_STREAM (p, SDP_PDU_SERVICE_SEARCH_REQ); - UINT16_TO_BE_STREAM (p, p_ccb->transaction_id); - p_ccb->transaction_id++; - - /* Skip the length, we need to add it at the end */ - p_param_len = p; - p += 2; - - /* Build the UID sequence. */ +static void sdp_snd_service_search_req(tCONN_CB* p_ccb, uint8_t cont_len, + uint8_t* p_cont) { + uint8_t *p, *p_start, *p_param_len; + BT_HDR* p_cmd = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + uint16_t param_len; + + /* Prepare the buffer for sending the packet to L2CAP */ + p_cmd->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_cmd + 1) + L2CAP_MIN_OFFSET; + + /* Build a service search request packet */ + UINT8_TO_BE_STREAM(p, SDP_PDU_SERVICE_SEARCH_REQ); + UINT16_TO_BE_STREAM(p, p_ccb->transaction_id); + p_ccb->transaction_id++; + + /* Skip the length, we need to add it at the end */ + p_param_len = p; + p += 2; + +/* Build the UID sequence. */ #if (SDP_BROWSE_PLUS == TRUE) - p = sdpu_build_uuid_seq (p, 1, &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx]); + p = sdpu_build_uuid_seq(p, 1, + &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx]); #else - p = sdpu_build_uuid_seq (p, p_ccb->p_db->num_uuid_filters, p_ccb->p_db->uuid_filters); + p = sdpu_build_uuid_seq(p, p_ccb->p_db->num_uuid_filters, + p_ccb->p_db->uuid_filters); #endif - /* Set max service record count */ - UINT16_TO_BE_STREAM (p, sdp_cb.max_recs_per_search); + /* Set max service record count */ + UINT16_TO_BE_STREAM(p, sdp_cb.max_recs_per_search); - /* Set continuation state */ - UINT8_TO_BE_STREAM (p, cont_len); + /* Set continuation state */ + UINT8_TO_BE_STREAM(p, cont_len); - /* if this is not the first request */ - if(cont_len && p_cont) - { - memcpy(p, p_cont, cont_len); - p += cont_len; - } + /* if this is not the first request */ + if (cont_len && p_cont) { + memcpy(p, p_cont, cont_len); + p += cont_len; + } - /* Go back and put the parameter length into the buffer */ - param_len = (uint16_t)(p - p_param_len - 2); - UINT16_TO_BE_STREAM (p_param_len, param_len); + /* Go back and put the parameter length into the buffer */ + param_len = (uint16_t)(p - p_param_len - 2); + UINT16_TO_BE_STREAM(p_param_len, param_len); - p_ccb->disc_state = SDP_DISC_WAIT_HANDLES; + p_ccb->disc_state = SDP_DISC_WAIT_HANDLES; - /* Set the length of the SDP data in the buffer */ - p_cmd->len = (uint16_t)(p - p_start); + /* Set the length of the SDP data in the buffer */ + p_cmd->len = (uint16_t)(p - p_start); #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("sdp_snd_service_search_req cont_len :%d disc_state:%d",cont_len, p_ccb->disc_state); + SDP_TRACE_WARNING("sdp_snd_service_search_req cont_len :%d disc_state:%d", + cont_len, p_ccb->disc_state); #endif + L2CA_DataWrite(p_ccb->connection_id, p_cmd); - L2CA_DataWrite (p_ccb->connection_id, p_cmd); - - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); } /******************************************************************************* @@ -187,24 +182,19 @@ static void sdp_snd_service_search_req(tCONN_CB *p_ccb, uint8_t cont_len, uint8_ * Returns void * ******************************************************************************/ -void sdp_disc_connected (tCONN_CB *p_ccb) -{ - if (p_ccb->is_attr_search) - { - p_ccb->disc_state = SDP_DISC_WAIT_SEARCH_ATTR; - - process_service_search_attr_rsp (p_ccb, NULL); - } - else - { - /* First step is to get a list of the handles from the server. */ - /* We are not searching for a specific attribute, so we will */ - /* first search for the service, then get all attributes of it */ - - p_ccb->num_handles = 0; - sdp_snd_service_search_req(p_ccb, 0, NULL); - } - +void sdp_disc_connected(tCONN_CB* p_ccb) { + if (p_ccb->is_attr_search) { + p_ccb->disc_state = SDP_DISC_WAIT_SEARCH_ATTR; + + process_service_search_attr_rsp(p_ccb, NULL); + } else { + /* First step is to get a list of the handles from the server. */ + /* We are not searching for a specific attribute, so we will */ + /* first search for the service, then get all attributes of it */ + + p_ccb->num_handles = 0; + sdp_snd_service_search_req(p_ccb, 0, NULL); + } } /******************************************************************************* @@ -217,57 +207,52 @@ void sdp_disc_connected (tCONN_CB *p_ccb) * Returns void * ******************************************************************************/ -void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg) -{ - uint8_t *p, rsp_pdu; - bool invalid_pdu = true; +void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg) { + uint8_t *p, rsp_pdu; + bool invalid_pdu = true; #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("sdp_disc_server_rsp disc_state:%d", p_ccb->disc_state); + SDP_TRACE_WARNING("sdp_disc_server_rsp disc_state:%d", p_ccb->disc_state); #endif - /* stop inactivity timer when we receive a response */ - alarm_cancel(p_ccb->sdp_conn_timer); + /* stop inactivity timer when we receive a response */ + alarm_cancel(p_ccb->sdp_conn_timer); - /* Got a reply!! Check what we got back */ - p = (uint8_t *)(p_msg + 1) + p_msg->offset; + /* Got a reply!! Check what we got back */ + p = (uint8_t*)(p_msg + 1) + p_msg->offset; - BE_STREAM_TO_UINT8 (rsp_pdu, p); + BE_STREAM_TO_UINT8(rsp_pdu, p); - p_msg->len--; + p_msg->len--; - switch (rsp_pdu) - { + switch (rsp_pdu) { case SDP_PDU_SERVICE_SEARCH_RSP: - if (p_ccb->disc_state == SDP_DISC_WAIT_HANDLES) - { - process_service_search_rsp (p_ccb, p); - invalid_pdu = false; - } - break; + if (p_ccb->disc_state == SDP_DISC_WAIT_HANDLES) { + process_service_search_rsp(p_ccb, p); + invalid_pdu = false; + } + break; case SDP_PDU_SERVICE_ATTR_RSP: - if (p_ccb->disc_state == SDP_DISC_WAIT_ATTR) - { - process_service_attr_rsp (p_ccb, p); - invalid_pdu = false; - } - break; + if (p_ccb->disc_state == SDP_DISC_WAIT_ATTR) { + process_service_attr_rsp(p_ccb, p); + invalid_pdu = false; + } + break; case SDP_PDU_SERVICE_SEARCH_ATTR_RSP: - if (p_ccb->disc_state == SDP_DISC_WAIT_SEARCH_ATTR) - { - process_service_search_attr_rsp (p_ccb, p); - invalid_pdu = false; - } - break; - } - - if (invalid_pdu) - { - SDP_TRACE_WARNING ("SDP - Unexp. PDU: %d in state: %d", rsp_pdu, p_ccb->disc_state); - sdp_disconnect (p_ccb, SDP_GENERIC_ERROR); - } + if (p_ccb->disc_state == SDP_DISC_WAIT_SEARCH_ATTR) { + process_service_search_attr_rsp(p_ccb, p); + invalid_pdu = false; + } + break; + } + + if (invalid_pdu) { + SDP_TRACE_WARNING("SDP - Unexp. PDU: %d in state: %d", rsp_pdu, + p_ccb->disc_state); + sdp_disconnect(p_ccb, SDP_GENERIC_ERROR); + } } /****************************************************************************** @@ -280,54 +265,47 @@ void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg) * Returns void * ******************************************************************************/ -static void process_service_search_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) -{ - uint16_t xx; - uint16_t total, cur_handles, orig; - uint8_t cont_len; - - /* Skip transaction, and param len */ - p_reply += 4; - BE_STREAM_TO_UINT16 (total, p_reply); - BE_STREAM_TO_UINT16 (cur_handles, p_reply); - - orig = p_ccb->num_handles; - p_ccb->num_handles += cur_handles; - if (p_ccb->num_handles == 0) - { - SDP_TRACE_WARNING ("SDP - Rcvd ServiceSearchRsp, no matches"); - sdp_disconnect (p_ccb, SDP_NO_RECS_MATCH); - return; - } - - /* Save the handles that match. We will can only process a certain number. */ - if (total > sdp_cb.max_recs_per_search) - total = sdp_cb.max_recs_per_search; - if (p_ccb->num_handles > sdp_cb.max_recs_per_search) - p_ccb->num_handles = sdp_cb.max_recs_per_search; - - for (xx = orig; xx < p_ccb->num_handles; xx++) - BE_STREAM_TO_UINT32 (p_ccb->handles[xx], p_reply); - - BE_STREAM_TO_UINT8 (cont_len, p_reply); - if(cont_len != 0) - { - if(cont_len > SDP_MAX_CONTINUATION_LEN) - { - sdp_disconnect (p_ccb, SDP_INVALID_CONT_STATE); - return; - } - /* stay in the same state */ - sdp_snd_service_search_req(p_ccb, cont_len, p_reply); - } - else - { - /* change state */ - p_ccb->disc_state = SDP_DISC_WAIT_ATTR; - - /* Kick off the first attribute request */ - process_service_attr_rsp (p_ccb, NULL); +static void process_service_search_rsp(tCONN_CB* p_ccb, uint8_t* p_reply) { + uint16_t xx; + uint16_t total, cur_handles, orig; + uint8_t cont_len; + + /* Skip transaction, and param len */ + p_reply += 4; + BE_STREAM_TO_UINT16(total, p_reply); + BE_STREAM_TO_UINT16(cur_handles, p_reply); + + orig = p_ccb->num_handles; + p_ccb->num_handles += cur_handles; + if (p_ccb->num_handles == 0) { + SDP_TRACE_WARNING("SDP - Rcvd ServiceSearchRsp, no matches"); + sdp_disconnect(p_ccb, SDP_NO_RECS_MATCH); + return; + } + + /* Save the handles that match. We will can only process a certain number. */ + if (total > sdp_cb.max_recs_per_search) total = sdp_cb.max_recs_per_search; + if (p_ccb->num_handles > sdp_cb.max_recs_per_search) + p_ccb->num_handles = sdp_cb.max_recs_per_search; + + for (xx = orig; xx < p_ccb->num_handles; xx++) + BE_STREAM_TO_UINT32(p_ccb->handles[xx], p_reply); + + BE_STREAM_TO_UINT8(cont_len, p_reply); + if (cont_len != 0) { + if (cont_len > SDP_MAX_CONTINUATION_LEN) { + sdp_disconnect(p_ccb, SDP_INVALID_CONT_STATE); + return; } + /* stay in the same state */ + sdp_snd_service_search_req(p_ccb, cont_len, p_reply); + } else { + /* change state */ + p_ccb->disc_state = SDP_DISC_WAIT_ATTR; + + /* Kick off the first attribute request */ + process_service_attr_rsp(p_ccb, NULL); + } } /******************************************************************************* @@ -341,47 +319,43 @@ static void process_service_search_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) * ******************************************************************************/ #if (SDP_RAW_DATA_INCLUDED == TRUE) -static void sdp_copy_raw_data (tCONN_CB *p_ccb, bool offset) -{ - unsigned int cpy_len; - uint32_t list_len; - uint8_t *p; - uint8_t type; +static void sdp_copy_raw_data(tCONN_CB* p_ccb, bool offset) { + unsigned int cpy_len; + uint32_t list_len; + uint8_t* p; + uint8_t type; #if (SDP_DEBUG_RAW == TRUE) - uint8_t num_array[SDP_MAX_LIST_BYTE_COUNT]; - uint32_t i; - - for (i = 0; i < p_ccb->list_len; i++) - { - snprintf((char *)&num_array[i*2], sizeof(num_array) - i*2, - "%02X",(uint8_t)(p_ccb->rsp_list[i])); - } - SDP_TRACE_WARNING("result :%s",num_array); + uint8_t num_array[SDP_MAX_LIST_BYTE_COUNT]; + uint32_t i; + + for (i = 0; i < p_ccb->list_len; i++) { + snprintf((char*)&num_array[i * 2], sizeof(num_array) - i * 2, "%02X", + (uint8_t)(p_ccb->rsp_list[i])); + } + SDP_TRACE_WARNING("result :%s", num_array); #endif - if(p_ccb->p_db->raw_data) - { - cpy_len = p_ccb->p_db->raw_size - p_ccb->p_db->raw_used; - list_len = p_ccb->list_len; - p = &p_ccb->rsp_list[0]; + if (p_ccb->p_db->raw_data) { + cpy_len = p_ccb->p_db->raw_size - p_ccb->p_db->raw_used; + list_len = p_ccb->list_len; + p = &p_ccb->rsp_list[0]; - if(offset) - { - type = *p++; - p = sdpu_get_len_from_type (p, type, &list_len); - } - if(list_len && list_len < cpy_len ) - { - cpy_len = list_len; - } + if (offset) { + type = *p++; + p = sdpu_get_len_from_type(p, type, &list_len); + } + if (list_len && list_len < cpy_len) { + cpy_len = list_len; + } #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_len :%d cpy_len:%d raw_size:%d raw_used:%d", - list_len, cpy_len, p_ccb->p_db->raw_size, p_ccb->p_db->raw_used); + SDP_TRACE_WARNING("list_len :%d cpy_len:%d raw_size:%d raw_used:%d", + list_len, cpy_len, p_ccb->p_db->raw_size, + p_ccb->p_db->raw_used); #endif - memcpy (&p_ccb->p_db->raw_data[p_ccb->p_db->raw_used], p, cpy_len); - p_ccb->p_db->raw_used += cpy_len; - } + memcpy(&p_ccb->p_db->raw_data[p_ccb->p_db->raw_used], p, cpy_len); + p_ccb->p_db->raw_used += cpy_len; + } } #endif @@ -395,142 +369,128 @@ static void sdp_copy_raw_data (tCONN_CB *p_ccb, bool offset) * Returns void * ******************************************************************************/ -static void process_service_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) -{ - uint8_t *p_start, *p_param_len; - uint16_t param_len, list_byte_count; - bool cont_request_needed = false; +static void process_service_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply) { + uint8_t *p_start, *p_param_len; + uint16_t param_len, list_byte_count; + bool cont_request_needed = false; #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("process_service_attr_rsp raw inc:%d", - SDP_RAW_DATA_INCLUDED); + SDP_TRACE_WARNING("process_service_attr_rsp raw inc:%d", + SDP_RAW_DATA_INCLUDED); #endif - /* If p_reply is NULL, we were called after the records handles were read */ - if (p_reply) - { + /* If p_reply is NULL, we were called after the records handles were read */ + if (p_reply) { #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x", - p_reply[0], p_reply[1], p_reply[2], p_reply[3]); + SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x", p_reply[0], p_reply[1], + p_reply[2], p_reply[3]); #endif - /* Skip transaction ID and length */ - p_reply += 4; + /* Skip transaction ID and length */ + p_reply += 4; - BE_STREAM_TO_UINT16 (list_byte_count, p_reply); + BE_STREAM_TO_UINT16(list_byte_count, p_reply); #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_byte_count:%d", list_byte_count); + SDP_TRACE_WARNING("list_byte_count:%d", list_byte_count); #endif - /* Copy the response to the scratchpad. First, a safety check on the length */ - if ((p_ccb->list_len + list_byte_count) > SDP_MAX_LIST_BYTE_COUNT) - { - sdp_disconnect (p_ccb, SDP_INVALID_PDU_SIZE); - return; - } + /* Copy the response to the scratchpad. First, a safety check on the length + */ + if ((p_ccb->list_len + list_byte_count) > SDP_MAX_LIST_BYTE_COUNT) { + sdp_disconnect(p_ccb, SDP_INVALID_PDU_SIZE); + return; + } #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d", - p_ccb->list_len, list_byte_count); + SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d", p_ccb->list_len, + list_byte_count); #endif - if (p_ccb->rsp_list == NULL) - p_ccb->rsp_list = (uint8_t *)osi_malloc(SDP_MAX_LIST_BYTE_COUNT); - memcpy(&p_ccb->rsp_list[p_ccb->list_len], p_reply, list_byte_count); - p_ccb->list_len += list_byte_count; - p_reply += list_byte_count; + if (p_ccb->rsp_list == NULL) + p_ccb->rsp_list = (uint8_t*)osi_malloc(SDP_MAX_LIST_BYTE_COUNT); + memcpy(&p_ccb->rsp_list[p_ccb->list_len], p_reply, list_byte_count); + p_ccb->list_len += list_byte_count; + p_reply += list_byte_count; #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_len: %d(attr_rsp)", p_ccb->list_len); + SDP_TRACE_WARNING("list_len: %d(attr_rsp)", p_ccb->list_len); - /* Check if we need to request a continuation */ - SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN); + /* Check if we need to request a continuation */ + SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN); #endif - if (*p_reply) - { - if (*p_reply > SDP_MAX_CONTINUATION_LEN) - { - sdp_disconnect (p_ccb, SDP_INVALID_CONT_STATE); - return; - } - cont_request_needed = true; - } - else - { - + if (*p_reply) { + if (*p_reply > SDP_MAX_CONTINUATION_LEN) { + sdp_disconnect(p_ccb, SDP_INVALID_CONT_STATE); + return; + } + cont_request_needed = true; + } else { #if (SDP_RAW_DATA_INCLUDED == TRUE) - SDP_TRACE_WARNING("process_service_attr_rsp"); - sdp_copy_raw_data (p_ccb, false); + SDP_TRACE_WARNING("process_service_attr_rsp"); + sdp_copy_raw_data(p_ccb, false); #endif - /* Save the response in the database. Stop on any error */ - if (!save_attr_seq (p_ccb, &p_ccb->rsp_list[0], &p_ccb->rsp_list[p_ccb->list_len])) - { - sdp_disconnect (p_ccb, SDP_DB_FULL); - return; - } - p_ccb->list_len = 0; - p_ccb->cur_handle++; - } + /* Save the response in the database. Stop on any error */ + if (!save_attr_seq(p_ccb, &p_ccb->rsp_list[0], + &p_ccb->rsp_list[p_ccb->list_len])) { + sdp_disconnect(p_ccb, SDP_DB_FULL); + return; + } + p_ccb->list_len = 0; + p_ccb->cur_handle++; } + } - /* Now, ask for the next handle. Re-use the buffer we just got. */ - if (p_ccb->cur_handle < p_ccb->num_handles) - { - BT_HDR *p_msg = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); - uint8_t *p; + /* Now, ask for the next handle. Re-use the buffer we just got. */ + if (p_ccb->cur_handle < p_ccb->num_handles) { + BT_HDR* p_msg = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + uint8_t* p; - p_msg->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; + p_msg->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; - /* Get all the attributes from the server */ - UINT8_TO_BE_STREAM (p, SDP_PDU_SERVICE_ATTR_REQ); - UINT16_TO_BE_STREAM (p, p_ccb->transaction_id); - p_ccb->transaction_id++; - - /* Skip the length, we need to add it at the end */ - p_param_len = p; - p += 2; + /* Get all the attributes from the server */ + UINT8_TO_BE_STREAM(p, SDP_PDU_SERVICE_ATTR_REQ); + UINT16_TO_BE_STREAM(p, p_ccb->transaction_id); + p_ccb->transaction_id++; - UINT32_TO_BE_STREAM (p, p_ccb->handles[p_ccb->cur_handle]); + /* Skip the length, we need to add it at the end */ + p_param_len = p; + p += 2; - /* Max attribute byte count */ - UINT16_TO_BE_STREAM (p, sdp_cb.max_attr_list_size); + UINT32_TO_BE_STREAM(p, p_ccb->handles[p_ccb->cur_handle]); - /* If no attribute filters, build a wildcard attribute sequence */ - if (p_ccb->p_db->num_attr_filters) - p = sdpu_build_attrib_seq (p, p_ccb->p_db->attr_filters, p_ccb->p_db->num_attr_filters); - else - p = sdpu_build_attrib_seq (p, NULL, 0); + /* Max attribute byte count */ + UINT16_TO_BE_STREAM(p, sdp_cb.max_attr_list_size); - /* Was this a continuation request ? */ - if (cont_request_needed) - { - memcpy (p, p_reply, *p_reply + 1); - p += *p_reply + 1; - } - else - UINT8_TO_BE_STREAM (p, 0); + /* If no attribute filters, build a wildcard attribute sequence */ + if (p_ccb->p_db->num_attr_filters) + p = sdpu_build_attrib_seq(p, p_ccb->p_db->attr_filters, + p_ccb->p_db->num_attr_filters); + else + p = sdpu_build_attrib_seq(p, NULL, 0); - /* Go back and put the parameter length into the buffer */ - param_len = (uint16_t)(p - p_param_len - 2); - UINT16_TO_BE_STREAM (p_param_len, param_len); + /* Was this a continuation request ? */ + if (cont_request_needed) { + memcpy(p, p_reply, *p_reply + 1); + p += *p_reply + 1; + } else + UINT8_TO_BE_STREAM(p, 0); - /* Set the length of the SDP data in the buffer */ - p_msg->len = (uint16_t)(p - p_start); + /* Go back and put the parameter length into the buffer */ + param_len = (uint16_t)(p - p_param_len - 2); + UINT16_TO_BE_STREAM(p_param_len, param_len); + /* Set the length of the SDP data in the buffer */ + p_msg->len = (uint16_t)(p - p_start); - L2CA_DataWrite (p_ccb->connection_id, p_msg); + L2CA_DataWrite(p_ccb->connection_id, p_msg); - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - else - { - sdp_disconnect (p_ccb, SDP_SUCCESS); - return; - } + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); + } else { + sdp_disconnect(p_ccb, SDP_SUCCESS); + return; + } } - /******************************************************************************* * * Function process_service_search_attr_rsp @@ -541,172 +501,161 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) * Returns void * ******************************************************************************/ -static void process_service_search_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) -{ - uint8_t *p, *p_start, *p_end, *p_param_len; - uint8_t type; - uint32_t seq_len; - uint16_t param_len, lists_byte_count = 0; - bool cont_request_needed = false; +static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply) { + uint8_t *p, *p_start, *p_end, *p_param_len; + uint8_t type; + uint32_t seq_len; + uint16_t param_len, lists_byte_count = 0; + bool cont_request_needed = false; #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("process_service_search_attr_rsp"); + SDP_TRACE_WARNING("process_service_search_attr_rsp"); #endif - /* If p_reply is NULL, we were called for the initial read */ - if (p_reply) - { + /* If p_reply is NULL, we were called for the initial read */ + if (p_reply) { #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x", - p_reply[0], p_reply[1], p_reply[2], p_reply[3]); + SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x", p_reply[0], p_reply[1], + p_reply[2], p_reply[3]); #endif - /* Skip transaction ID and length */ - p_reply += 4; + /* Skip transaction ID and length */ + p_reply += 4; - BE_STREAM_TO_UINT16 (lists_byte_count, p_reply); + BE_STREAM_TO_UINT16(lists_byte_count, p_reply); #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("lists_byte_count:%d", lists_byte_count); + SDP_TRACE_WARNING("lists_byte_count:%d", lists_byte_count); #endif - /* Copy the response to the scratchpad. First, a safety check on the length */ - if ((p_ccb->list_len + lists_byte_count) > SDP_MAX_LIST_BYTE_COUNT) - { - sdp_disconnect (p_ccb, SDP_INVALID_PDU_SIZE); - return; - } + /* Copy the response to the scratchpad. First, a safety check on the length + */ + if ((p_ccb->list_len + lists_byte_count) > SDP_MAX_LIST_BYTE_COUNT) { + sdp_disconnect(p_ccb, SDP_INVALID_PDU_SIZE); + return; + } #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d", - p_ccb->list_len, lists_byte_count); + SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d", p_ccb->list_len, + lists_byte_count); #endif - if (p_ccb->rsp_list == NULL) - p_ccb->rsp_list = (uint8_t *)osi_malloc(SDP_MAX_LIST_BYTE_COUNT); - memcpy (&p_ccb->rsp_list[p_ccb->list_len], p_reply, lists_byte_count); - p_ccb->list_len += lists_byte_count; - p_reply += lists_byte_count; + if (p_ccb->rsp_list == NULL) + p_ccb->rsp_list = (uint8_t*)osi_malloc(SDP_MAX_LIST_BYTE_COUNT); + memcpy(&p_ccb->rsp_list[p_ccb->list_len], p_reply, lists_byte_count); + p_ccb->list_len += lists_byte_count; + p_reply += lists_byte_count; #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("list_len: %d(search_attr_rsp)", p_ccb->list_len); + SDP_TRACE_WARNING("list_len: %d(search_attr_rsp)", p_ccb->list_len); - /* Check if we need to request a continuation */ - SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN); + /* Check if we need to request a continuation */ + SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN); #endif - if (*p_reply) - { - if (*p_reply > SDP_MAX_CONTINUATION_LEN) - { - sdp_disconnect (p_ccb, SDP_INVALID_CONT_STATE); - return; - } + if (*p_reply) { + if (*p_reply > SDP_MAX_CONTINUATION_LEN) { + sdp_disconnect(p_ccb, SDP_INVALID_CONT_STATE); + return; + } - cont_request_needed = true; - } + cont_request_needed = true; } + } #if (SDP_DEBUG_RAW == TRUE) - SDP_TRACE_WARNING("cont_request_needed:%d", cont_request_needed); + SDP_TRACE_WARNING("cont_request_needed:%d", cont_request_needed); #endif - /* If continuation request (or first time request) */ - if ((cont_request_needed) || (!p_reply)) - { - BT_HDR *p_msg = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); - uint8_t *p; + /* If continuation request (or first time request) */ + if ((cont_request_needed) || (!p_reply)) { + BT_HDR* p_msg = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + uint8_t* p; - p_msg->offset = L2CAP_MIN_OFFSET; - p = p_start = (uint8_t *)(p_msg + 1) + L2CAP_MIN_OFFSET; + p_msg->offset = L2CAP_MIN_OFFSET; + p = p_start = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; - /* Build a service search request packet */ - UINT8_TO_BE_STREAM (p, SDP_PDU_SERVICE_SEARCH_ATTR_REQ); - UINT16_TO_BE_STREAM (p, p_ccb->transaction_id); - p_ccb->transaction_id++; + /* Build a service search request packet */ + UINT8_TO_BE_STREAM(p, SDP_PDU_SERVICE_SEARCH_ATTR_REQ); + UINT16_TO_BE_STREAM(p, p_ccb->transaction_id); + p_ccb->transaction_id++; - /* Skip the length, we need to add it at the end */ - p_param_len = p; - p += 2; + /* Skip the length, we need to add it at the end */ + p_param_len = p; + p += 2; - /* Build the UID sequence. */ +/* Build the UID sequence. */ #if (SDP_BROWSE_PLUS == TRUE) - p = sdpu_build_uuid_seq (p, 1, &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx]); + p = sdpu_build_uuid_seq(p, 1, + &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx]); #else - p = sdpu_build_uuid_seq (p, p_ccb->p_db->num_uuid_filters, p_ccb->p_db->uuid_filters); + p = sdpu_build_uuid_seq(p, p_ccb->p_db->num_uuid_filters, + p_ccb->p_db->uuid_filters); #endif - /* Max attribute byte count */ - UINT16_TO_BE_STREAM (p, sdp_cb.max_attr_list_size); + /* Max attribute byte count */ + UINT16_TO_BE_STREAM(p, sdp_cb.max_attr_list_size); - /* If no attribute filters, build a wildcard attribute sequence */ - if (p_ccb->p_db->num_attr_filters) - p = sdpu_build_attrib_seq (p, p_ccb->p_db->attr_filters, p_ccb->p_db->num_attr_filters); - else - p = sdpu_build_attrib_seq (p, NULL, 0); - - /* No continuation for first request */ - if (p_reply) - { - memcpy (p, p_reply, *p_reply + 1); - p += *p_reply + 1; - } - else - UINT8_TO_BE_STREAM (p, 0); - - /* Go back and put the parameter length into the buffer */ - param_len = p - p_param_len - 2; - UINT16_TO_BE_STREAM (p_param_len, param_len); + /* If no attribute filters, build a wildcard attribute sequence */ + if (p_ccb->p_db->num_attr_filters) + p = sdpu_build_attrib_seq(p, p_ccb->p_db->attr_filters, + p_ccb->p_db->num_attr_filters); + else + p = sdpu_build_attrib_seq(p, NULL, 0); - /* Set the length of the SDP data in the buffer */ - p_msg->len = p - p_start; + /* No continuation for first request */ + if (p_reply) { + memcpy(p, p_reply, *p_reply + 1); + p += *p_reply + 1; + } else + UINT8_TO_BE_STREAM(p, 0); + /* Go back and put the parameter length into the buffer */ + param_len = p - p_param_len - 2; + UINT16_TO_BE_STREAM(p_param_len, param_len); - L2CA_DataWrite (p_ccb->connection_id, p_msg); + /* Set the length of the SDP data in the buffer */ + p_msg->len = p - p_start; - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, - btu_general_alarm_queue); + L2CA_DataWrite(p_ccb->connection_id, p_msg); - return; - } + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); + return; + } - /*******************************************************************/ - /* We now have the full response, which is a sequence of sequences */ - /*******************************************************************/ +/*******************************************************************/ +/* We now have the full response, which is a sequence of sequences */ +/*******************************************************************/ #if (SDP_RAW_DATA_INCLUDED == TRUE) - SDP_TRACE_WARNING("process_service_search_attr_rsp"); - sdp_copy_raw_data (p_ccb, true); + SDP_TRACE_WARNING("process_service_search_attr_rsp"); + sdp_copy_raw_data(p_ccb, true); #endif - p = &p_ccb->rsp_list[0]; + p = &p_ccb->rsp_list[0]; - /* The contents is a sequence of attribute sequences */ - type = *p++; + /* The contents is a sequence of attribute sequences */ + type = *p++; - if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE) - { - SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp", type); - return; - } - p = sdpu_get_len_from_type (p, type, &seq_len); + if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE) { + SDP_TRACE_WARNING("SDP - Wrong type: 0x%02x in attr_rsp", type); + return; + } + p = sdpu_get_len_from_type(p, type, &seq_len); - p_end = &p_ccb->rsp_list[p_ccb->list_len]; + p_end = &p_ccb->rsp_list[p_ccb->list_len]; - if ((p + seq_len) != p_end) - { - sdp_disconnect (p_ccb, SDP_INVALID_CONT_STATE); - return; - } + if ((p + seq_len) != p_end) { + sdp_disconnect(p_ccb, SDP_INVALID_CONT_STATE); + return; + } - while (p < p_end) - { - p = save_attr_seq (p_ccb, p, &p_ccb->rsp_list[p_ccb->list_len]); - if (!p) - { - sdp_disconnect (p_ccb, SDP_DB_FULL); - return; - } + while (p < p_end) { + p = save_attr_seq(p_ccb, p, &p_ccb->rsp_list[p_ccb->list_len]); + if (!p) { + sdp_disconnect(p_ccb, SDP_DB_FULL); + return; } + } - /* Since we got everything we need, disconnect the call */ - sdp_disconnect (p_ccb, SDP_SUCCESS); + /* Since we got everything we need, disconnect the call */ + sdp_disconnect(p_ccb, SDP_SUCCESS); } /******************************************************************************* @@ -719,64 +668,57 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, uint8_t *p_reply) * Returns pointer to next byte or NULL if error * ******************************************************************************/ -static uint8_t *save_attr_seq (tCONN_CB *p_ccb, uint8_t *p, uint8_t *p_msg_end) -{ - uint32_t seq_len, attr_len; - uint16_t attr_id; - uint8_t type, *p_seq_end; - tSDP_DISC_REC *p_rec; - +static uint8_t* save_attr_seq(tCONN_CB* p_ccb, uint8_t* p, uint8_t* p_msg_end) { + uint32_t seq_len, attr_len; + uint16_t attr_id; + uint8_t type, *p_seq_end; + tSDP_DISC_REC* p_rec; + + type = *p++; + + if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE) { + SDP_TRACE_WARNING("SDP - Wrong type: 0x%02x in attr_rsp", type); + return (NULL); + } + + p = sdpu_get_len_from_type(p, type, &seq_len); + if ((p + seq_len) > p_msg_end) { + SDP_TRACE_WARNING("SDP - Bad len in attr_rsp %d", seq_len); + return (NULL); + } + + /* Create a record */ + p_rec = add_record(p_ccb->p_db, p_ccb->device_address); + if (!p_rec) { + SDP_TRACE_WARNING("SDP - DB full add_record"); + return (NULL); + } + + p_seq_end = p + seq_len; + + while (p < p_seq_end) { + /* First get the attribute ID */ type = *p++; - - if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE) - { - SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp", type); - return (NULL); + p = sdpu_get_len_from_type(p, type, &attr_len); + if (((type >> 3) != UINT_DESC_TYPE) || (attr_len != 2)) { + SDP_TRACE_WARNING("SDP - Bad type: 0x%02x or len: %d in attr_rsp", type, + attr_len); + return (NULL); } + BE_STREAM_TO_UINT16(attr_id, p); - p = sdpu_get_len_from_type (p, type, &seq_len); - if ((p + seq_len) > p_msg_end) - { - SDP_TRACE_WARNING ("SDP - Bad len in attr_rsp %d", seq_len); - return (NULL); - } - - /* Create a record */ - p_rec = add_record (p_ccb->p_db, p_ccb->device_address); - if (!p_rec) - { - SDP_TRACE_WARNING ("SDP - DB full add_record"); - return (NULL); - } - - p_seq_end = p + seq_len; - - while (p < p_seq_end) - { - /* First get the attribute ID */ - type = *p++; - p = sdpu_get_len_from_type (p, type, &attr_len); - if (((type >> 3) != UINT_DESC_TYPE) || (attr_len != 2)) - { - SDP_TRACE_WARNING ("SDP - Bad type: 0x%02x or len: %d in attr_rsp", type, attr_len); - return (NULL); - } - BE_STREAM_TO_UINT16 (attr_id, p); + /* Now, add the attribute value */ + p = add_attr(p, p_ccb->p_db, p_rec, attr_id, NULL, 0); - /* Now, add the attribute value */ - p = add_attr (p, p_ccb->p_db, p_rec, attr_id, NULL, 0); - - if (!p) - { - SDP_TRACE_WARNING ("SDP - DB full add_attr"); - return (NULL); - } + if (!p) { + SDP_TRACE_WARNING("SDP - DB full add_attr"); + return (NULL); } + } - return (p); + return (p); } - /******************************************************************************* * * Function add_record @@ -786,40 +728,36 @@ static uint8_t *save_attr_seq (tCONN_CB *p_ccb, uint8_t *p, uint8_t *p_msg_end) * Returns pointer to next byte in data stream * ******************************************************************************/ -tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda) -{ - tSDP_DISC_REC *p_rec; +tSDP_DISC_REC* add_record(tSDP_DISCOVERY_DB* p_db, BD_ADDR p_bda) { + tSDP_DISC_REC* p_rec; - /* See if there is enough space in the database */ - if (p_db->mem_free < sizeof (tSDP_DISC_REC)) - return (NULL); + /* See if there is enough space in the database */ + if (p_db->mem_free < sizeof(tSDP_DISC_REC)) return (NULL); - p_rec = (tSDP_DISC_REC *) p_db->p_free_mem; - p_db->p_free_mem += sizeof (tSDP_DISC_REC); - p_db->mem_free -= sizeof (tSDP_DISC_REC); + p_rec = (tSDP_DISC_REC*)p_db->p_free_mem; + p_db->p_free_mem += sizeof(tSDP_DISC_REC); + p_db->mem_free -= sizeof(tSDP_DISC_REC); - p_rec->p_first_attr = NULL; - p_rec->p_next_rec = NULL; + p_rec->p_first_attr = NULL; + p_rec->p_next_rec = NULL; - memcpy (p_rec->remote_bd_addr, p_bda, BD_ADDR_LEN); + memcpy(p_rec->remote_bd_addr, p_bda, BD_ADDR_LEN); - /* Add the record to the end of chain */ - if (!p_db->p_first_rec) - p_db->p_first_rec = p_rec; - else - { - tSDP_DISC_REC *p_rec1 = p_db->p_first_rec; + /* Add the record to the end of chain */ + if (!p_db->p_first_rec) + p_db->p_first_rec = p_rec; + else { + tSDP_DISC_REC* p_rec1 = p_db->p_first_rec; - while (p_rec1->p_next_rec) - p_rec1 = p_rec1->p_next_rec; + while (p_rec1->p_next_rec) p_rec1 = p_rec1->p_next_rec; - p_rec1->p_next_rec = p_rec; - } + p_rec1->p_next_rec = p_rec; + } - return (p_rec); + return (p_rec); } -#define SDP_ADDITIONAL_LIST_MASK 0x80 +#define SDP_ADDITIONAL_LIST_MASK 0x80 /******************************************************************************* * * Function add_attr @@ -830,236 +768,219 @@ tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda) * Returns pointer to next byte in data stream * ******************************************************************************/ -static uint8_t *add_attr (uint8_t *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec, - uint16_t attr_id, tSDP_DISC_ATTR *p_parent_attr, uint8_t nest_level) -{ - tSDP_DISC_ATTR *p_attr; - uint32_t attr_len; - uint32_t total_len; - uint16_t attr_type; - uint16_t id; - uint8_t type; - uint8_t *p_end; - uint8_t is_additional_list = nest_level & SDP_ADDITIONAL_LIST_MASK; - - nest_level &= ~(SDP_ADDITIONAL_LIST_MASK); - - type = *p++; - p = sdpu_get_len_from_type (p, type, &attr_len); - - attr_len &= SDP_DISC_ATTR_LEN_MASK; - attr_type = (type >> 3) & 0x0f; - - /* See if there is enough space in the database */ - if (attr_len > 4) - total_len = attr_len - 4 + (uint16_t)sizeof (tSDP_DISC_ATTR); - else - total_len = sizeof (tSDP_DISC_ATTR); - - /* Ensure it is a multiple of 4 */ - total_len = (total_len + 3) & ~3; - - /* See if there is enough space in the database */ - if (p_db->mem_free < total_len) - return (NULL); +static uint8_t* add_attr(uint8_t* p, tSDP_DISCOVERY_DB* p_db, + tSDP_DISC_REC* p_rec, uint16_t attr_id, + tSDP_DISC_ATTR* p_parent_attr, uint8_t nest_level) { + tSDP_DISC_ATTR* p_attr; + uint32_t attr_len; + uint32_t total_len; + uint16_t attr_type; + uint16_t id; + uint8_t type; + uint8_t* p_end; + uint8_t is_additional_list = nest_level & SDP_ADDITIONAL_LIST_MASK; + + nest_level &= ~(SDP_ADDITIONAL_LIST_MASK); + + type = *p++; + p = sdpu_get_len_from_type(p, type, &attr_len); + + attr_len &= SDP_DISC_ATTR_LEN_MASK; + attr_type = (type >> 3) & 0x0f; + + /* See if there is enough space in the database */ + if (attr_len > 4) + total_len = attr_len - 4 + (uint16_t)sizeof(tSDP_DISC_ATTR); + else + total_len = sizeof(tSDP_DISC_ATTR); + + /* Ensure it is a multiple of 4 */ + total_len = (total_len + 3) & ~3; + + /* See if there is enough space in the database */ + if (p_db->mem_free < total_len) return (NULL); + + p_attr = (tSDP_DISC_ATTR*)p_db->p_free_mem; + p_attr->attr_id = attr_id; + p_attr->attr_len_type = (uint16_t)attr_len | (attr_type << 12); + p_attr->p_next_attr = NULL; + + /* Store the attribute value */ + switch (attr_type) { + case UINT_DESC_TYPE: + if ((is_additional_list != 0) && (attr_len == 2)) { + BE_STREAM_TO_UINT16(id, p); + if (id != ATTR_ID_PROTOCOL_DESC_LIST) + p -= 2; + else { + /* Reserve the memory for the attribute now, as we need to add + * sub-attributes */ + p_db->p_free_mem += sizeof(tSDP_DISC_ATTR); + p_db->mem_free -= sizeof(tSDP_DISC_ATTR); + p_end = p + attr_len; + total_len = 0; + + /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */ + if (nest_level >= MAX_NEST_LEVELS) { + SDP_TRACE_ERROR("SDP - attr nesting too deep"); + return (p_end); + } - p_attr = (tSDP_DISC_ATTR *) p_db->p_free_mem; - p_attr->attr_id = attr_id; - p_attr->attr_len_type = (uint16_t)attr_len | (attr_type << 12); - p_attr->p_next_attr = NULL; + /* Now, add the list entry */ + p = add_attr(p, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST, p_attr, + (uint8_t)(nest_level + 1)); - /* Store the attribute value */ - switch (attr_type) - { - case UINT_DESC_TYPE: - if( (is_additional_list != 0) && (attr_len == 2) ) - { - BE_STREAM_TO_UINT16 (id, p); - if(id != ATTR_ID_PROTOCOL_DESC_LIST) - p -= 2; - else - { - /* Reserve the memory for the attribute now, as we need to add sub-attributes */ - p_db->p_free_mem += sizeof (tSDP_DISC_ATTR); - p_db->mem_free -= sizeof (tSDP_DISC_ATTR); - p_end = p + attr_len; - total_len = 0; - - /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */ - if (nest_level >= MAX_NEST_LEVELS) - { - SDP_TRACE_ERROR ("SDP - attr nesting too deep"); - return (p_end); - } - - /* Now, add the list entry */ - p = add_attr (p, p_db, p_rec, ATTR_ID_PROTOCOL_DESC_LIST, p_attr, (uint8_t)(nest_level + 1)); - - break; - } + break; } - /* Case falls through */ + } + /* Case falls through */ case TWO_COMP_INT_DESC_TYPE: - switch (attr_len) - { + switch (attr_len) { case 1: - p_attr->attr_value.v.u8 = *p++; - break; + p_attr->attr_value.v.u8 = *p++; + break; case 2: - BE_STREAM_TO_UINT16 (p_attr->attr_value.v.u16, p); - break; + BE_STREAM_TO_UINT16(p_attr->attr_value.v.u16, p); + break; case 4: - BE_STREAM_TO_UINT32 (p_attr->attr_value.v.u32, p); - break; + BE_STREAM_TO_UINT32(p_attr->attr_value.v.u32, p); + break; default: - BE_STREAM_TO_ARRAY (p, p_attr->attr_value.v.array, (int32_t)attr_len); - break; - } - break; + BE_STREAM_TO_ARRAY(p, p_attr->attr_value.v.array, (int32_t)attr_len); + break; + } + break; case UUID_DESC_TYPE: - switch (attr_len) - { + switch (attr_len) { case 2: - BE_STREAM_TO_UINT16 (p_attr->attr_value.v.u16, p); - break; + BE_STREAM_TO_UINT16(p_attr->attr_value.v.u16, p); + break; case 4: - BE_STREAM_TO_UINT32 (p_attr->attr_value.v.u32, p); - if (p_attr->attr_value.v.u32 < 0x10000) - { - attr_len = 2; - p_attr->attr_len_type = (uint16_t)attr_len | (attr_type << 12); - p_attr->attr_value.v.u16 = (uint16_t) p_attr->attr_value.v.u32; - - } - break; + BE_STREAM_TO_UINT32(p_attr->attr_value.v.u32, p); + if (p_attr->attr_value.v.u32 < 0x10000) { + attr_len = 2; + p_attr->attr_len_type = (uint16_t)attr_len | (attr_type << 12); + p_attr->attr_value.v.u16 = (uint16_t)p_attr->attr_value.v.u32; + } + break; case 16: - /* See if we can compress his UUID down to 16 or 32bit UUIDs */ - if (sdpu_is_base_uuid (p)) - { - if ((p[0] == 0) && (p[1] == 0)) - { - p_attr->attr_len_type = (p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 2; - p += 2; - BE_STREAM_TO_UINT16 (p_attr->attr_value.v.u16, p); - p += MAX_UUID_SIZE - 4; - } - else - { - p_attr->attr_len_type = (p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 4; - BE_STREAM_TO_UINT32 (p_attr->attr_value.v.u32, p); - p += MAX_UUID_SIZE - 4; - } - } - else - { - /* coverity[overrun-local] */ - /* - Event overrun-local: Overrun of static array "p_attr->attr_value.v.array" of size 4 at position 15 with index variable "ijk" - False-positive: SDP uses scratch buffer to hold the attribute value. - The actual size of tSDP_DISC_ATVAL does not matter. - If the array size in tSDP_DISC_ATVAL is increase, we would increase the system RAM usage unnecessarily - */ - BE_STREAM_TO_ARRAY (p, p_attr->attr_value.v.array, (int32_t)attr_len); + /* See if we can compress his UUID down to 16 or 32bit UUIDs */ + if (sdpu_is_base_uuid(p)) { + if ((p[0] == 0) && (p[1] == 0)) { + p_attr->attr_len_type = + (p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 2; + p += 2; + BE_STREAM_TO_UINT16(p_attr->attr_value.v.u16, p); + p += MAX_UUID_SIZE - 4; + } else { + p_attr->attr_len_type = + (p_attr->attr_len_type & ~SDP_DISC_ATTR_LEN_MASK) | 4; + BE_STREAM_TO_UINT32(p_attr->attr_value.v.u32, p); + p += MAX_UUID_SIZE - 4; } - break; + } else { + /* coverity[overrun-local] */ + /* + Event overrun-local: Overrun of static array + "p_attr->attr_value.v.array" of size 4 at position 15 with index + variable "ijk" + False-positive: SDP uses scratch buffer to hold the attribute + value. + The actual size of tSDP_DISC_ATVAL does not matter. + If the array size in tSDP_DISC_ATVAL is increase, we would + increase the system RAM usage unnecessarily + */ + BE_STREAM_TO_ARRAY(p, p_attr->attr_value.v.array, + (int32_t)attr_len); + } + break; default: - SDP_TRACE_WARNING ("SDP - bad len in UUID attr: %d", attr_len); - return (p + attr_len); - } - break; + SDP_TRACE_WARNING("SDP - bad len in UUID attr: %d", attr_len); + return (p + attr_len); + } + break; case DATA_ELE_SEQ_DESC_TYPE: case DATA_ELE_ALT_DESC_TYPE: - /* Reserve the memory for the attribute now, as we need to add sub-attributes */ - p_db->p_free_mem += sizeof (tSDP_DISC_ATTR); - p_db->mem_free -= sizeof (tSDP_DISC_ATTR); - p_end = p + attr_len; - total_len = 0; - - /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */ - if (nest_level >= MAX_NEST_LEVELS) - { - SDP_TRACE_ERROR ("SDP - attr nesting too deep"); - return (p_end); - } - if(is_additional_list != 0 || attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS) - nest_level |= SDP_ADDITIONAL_LIST_MASK; - /* SDP_TRACE_DEBUG ("SDP - attr nest level:0x%x(finish)", nest_level); */ - - while (p < p_end) - { - /* Now, add the list entry */ - p = add_attr (p, p_db, p_rec, 0, p_attr, (uint8_t)(nest_level + 1)); - - if (!p) - return (NULL); - } - break; + /* Reserve the memory for the attribute now, as we need to add + * sub-attributes */ + p_db->p_free_mem += sizeof(tSDP_DISC_ATTR); + p_db->mem_free -= sizeof(tSDP_DISC_ATTR); + p_end = p + attr_len; + total_len = 0; + + /* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */ + if (nest_level >= MAX_NEST_LEVELS) { + SDP_TRACE_ERROR("SDP - attr nesting too deep"); + return (p_end); + } + if (is_additional_list != 0 || + attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS) + nest_level |= SDP_ADDITIONAL_LIST_MASK; + /* SDP_TRACE_DEBUG ("SDP - attr nest level:0x%x(finish)", nest_level); */ + + while (p < p_end) { + /* Now, add the list entry */ + p = add_attr(p, p_db, p_rec, 0, p_attr, (uint8_t)(nest_level + 1)); + + if (!p) return (NULL); + } + break; case TEXT_STR_DESC_TYPE: case URL_DESC_TYPE: - BE_STREAM_TO_ARRAY (p, p_attr->attr_value.v.array, (int32_t)attr_len); - break; + BE_STREAM_TO_ARRAY(p, p_attr->attr_value.v.array, (int32_t)attr_len); + break; case BOOLEAN_DESC_TYPE: - switch (attr_len) - { + switch (attr_len) { case 1: - p_attr->attr_value.v.u8 = *p++; - break; + p_attr->attr_value.v.u8 = *p++; + break; default: - SDP_TRACE_WARNING ("SDP - bad len in boolean attr: %d", attr_len); - return (p + attr_len); - } - break; + SDP_TRACE_WARNING("SDP - bad len in boolean attr: %d", attr_len); + return (p + attr_len); + } + break; - default: /* switch (attr_type) */ - break; - } + default: /* switch (attr_type) */ + break; + } - p_db->p_free_mem += total_len; - p_db->mem_free -= total_len; + p_db->p_free_mem += total_len; + p_db->mem_free -= total_len; - /* Add the attribute to the end of the chain */ - if (!p_parent_attr) - { - if (!p_rec->p_first_attr) - p_rec->p_first_attr = p_attr; - else - { - tSDP_DISC_ATTR *p_attr1 = p_rec->p_first_attr; + /* Add the attribute to the end of the chain */ + if (!p_parent_attr) { + if (!p_rec->p_first_attr) + p_rec->p_first_attr = p_attr; + else { + tSDP_DISC_ATTR* p_attr1 = p_rec->p_first_attr; - while (p_attr1->p_next_attr) - p_attr1 = p_attr1->p_next_attr; + while (p_attr1->p_next_attr) p_attr1 = p_attr1->p_next_attr; - p_attr1->p_next_attr = p_attr; - } + p_attr1->p_next_attr = p_attr; } - else - { - if (!p_parent_attr->attr_value.v.p_sub_attr) - { - p_parent_attr->attr_value.v.p_sub_attr = p_attr; - /* SDP_TRACE_DEBUG ("parent:0x%x(id:%d), ch:0x%x(id:%d)", - p_parent_attr, p_parent_attr->attr_id, p_attr, p_attr->attr_id); */ - } - else - { - tSDP_DISC_ATTR *p_attr1 = p_parent_attr->attr_value.v.p_sub_attr; - /* SDP_TRACE_DEBUG ("parent:0x%x(id:%d), ch1:0x%x(id:%d)", - p_parent_attr, p_parent_attr->attr_id, p_attr1, p_attr1->attr_id); */ - - while (p_attr1->p_next_attr) - p_attr1 = p_attr1->p_next_attr; - - p_attr1->p_next_attr = p_attr; - /* SDP_TRACE_DEBUG ("new ch:0x%x(id:%d)", p_attr, p_attr->attr_id); */ - } + } else { + if (!p_parent_attr->attr_value.v.p_sub_attr) { + p_parent_attr->attr_value.v.p_sub_attr = p_attr; + /* SDP_TRACE_DEBUG ("parent:0x%x(id:%d), ch:0x%x(id:%d)", + p_parent_attr, p_parent_attr->attr_id, p_attr, p_attr->attr_id); */ + } else { + tSDP_DISC_ATTR* p_attr1 = p_parent_attr->attr_value.v.p_sub_attr; + /* SDP_TRACE_DEBUG ("parent:0x%x(id:%d), ch1:0x%x(id:%d)", + p_parent_attr, p_parent_attr->attr_id, p_attr1, p_attr1->attr_id); */ + + while (p_attr1->p_next_attr) p_attr1 = p_attr1->p_next_attr; + + p_attr1->p_next_attr = p_attr; + /* SDP_TRACE_DEBUG ("new ch:0x%x(id:%d)", p_attr, p_attr->attr_id); */ } + } - return (p); + return (p); } -#endif /* CLIENT_ENABLED == TRUE */ +#endif /* CLIENT_ENABLED == TRUE */ diff --git a/stack/sdp/sdp_main.cc b/stack/sdp/sdp_main.cc index 2a0d5cf6c..29287334a 100644 --- a/stack/sdp/sdp_main.cc +++ b/stack/sdp/sdp_main.cc @@ -22,54 +22,52 @@ * ******************************************************************************/ +#include #include #include -#include +#include "bt_common.h" #include "bt_target.h" #include "bt_utils.h" -#include "bt_common.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "l2c_api.h" #include "l2cdefs.h" #include "osi/include/osi.h" -#include "btu.h" #include "btm_api.h" +#include "btu.h" #include "sdp_api.h" #include "sdpint.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /******************************************************************************/ /* G L O B A L S D P D A T A */ /******************************************************************************/ -tSDP_CB sdp_cb; +tSDP_CB sdp_cb; /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void sdp_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, UNUSED_ATTR uint16_t psm, - uint8_t l2cap_id); -static void sdp_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void sdp_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg); -static void sdp_disconnect_ind (uint16_t l2cap_cid, bool ack_needed); -static void sdp_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg); +static void sdp_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, + UNUSED_ATTR uint16_t psm, uint8_t l2cap_id); +static void sdp_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void sdp_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg); +static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); +static void sdp_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); #if (SDP_CLIENT_ENABLED == TRUE) -static void sdp_connect_cfm (uint16_t l2cap_cid, uint16_t result); -static void sdp_disconnect_cfm (uint16_t l2cap_cid, uint16_t result); +static void sdp_connect_cfm(uint16_t l2cap_cid, uint16_t result); +static void sdp_disconnect_cfm(uint16_t l2cap_cid, uint16_t result); #else -#define sdp_connect_cfm NULL -#define sdp_disconnect_cfm NULL +#define sdp_connect_cfm NULL +#define sdp_disconnect_cfm NULL #endif - /******************************************************************************* * * Function sdp_init @@ -79,63 +77,59 @@ static void sdp_disconnect_cfm (uint16_t l2cap_cid, uint16_t result); * Returns void * ******************************************************************************/ -void sdp_init (void) -{ - /* Clears all structures and local SDP database (if Server is enabled) */ - memset (&sdp_cb, 0, sizeof (tSDP_CB)); +void sdp_init(void) { + /* Clears all structures and local SDP database (if Server is enabled) */ + memset(&sdp_cb, 0, sizeof(tSDP_CB)); - /* Initialize the L2CAP configuration. We only care about MTU and flush */ - sdp_cb.l2cap_my_cfg.mtu_present = true; - sdp_cb.l2cap_my_cfg.mtu = SDP_MTU_SIZE; - sdp_cb.l2cap_my_cfg.flush_to_present = true; - sdp_cb.l2cap_my_cfg.flush_to = SDP_FLUSH_TO; + /* Initialize the L2CAP configuration. We only care about MTU and flush */ + sdp_cb.l2cap_my_cfg.mtu_present = true; + sdp_cb.l2cap_my_cfg.mtu = SDP_MTU_SIZE; + sdp_cb.l2cap_my_cfg.flush_to_present = true; + sdp_cb.l2cap_my_cfg.flush_to = SDP_FLUSH_TO; - sdp_cb.max_attr_list_size = SDP_MTU_SIZE - 16; - sdp_cb.max_recs_per_search = SDP_MAX_DISC_SERVER_RECS; + sdp_cb.max_attr_list_size = SDP_MTU_SIZE - 16; + sdp_cb.max_recs_per_search = SDP_MAX_DISC_SERVER_RECS; #if (SDP_SERVER_ENABLED == TRUE) - /* Register with Security Manager for the specific security level */ - if (!BTM_SetSecurityLevel (false, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, - SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) - { - SDP_TRACE_ERROR ("Security Registration Server failed"); - return; - } + /* Register with Security Manager for the specific security level */ + if (!BTM_SetSecurityLevel(false, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, + SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) { + SDP_TRACE_ERROR("Security Registration Server failed"); + return; + } #endif #if (SDP_CLIENT_ENABLED == TRUE) - /* Register with Security Manager for the specific security level */ - if (!BTM_SetSecurityLevel (true, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, - SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) - { - SDP_TRACE_ERROR ("Security Registration for Client failed"); - return; - } + /* Register with Security Manager for the specific security level */ + if (!BTM_SetSecurityLevel(true, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER, + SDP_SECURITY_LEVEL, SDP_PSM, 0, 0)) { + SDP_TRACE_ERROR("Security Registration for Client failed"); + return; + } #endif #if defined(SDP_INITIAL_TRACE_LEVEL) - sdp_cb.trace_level = SDP_INITIAL_TRACE_LEVEL; + sdp_cb.trace_level = SDP_INITIAL_TRACE_LEVEL; #else - sdp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + sdp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif - sdp_cb.reg_info.pL2CA_ConnectInd_Cb = sdp_connect_ind; - sdp_cb.reg_info.pL2CA_ConnectCfm_Cb = sdp_connect_cfm; - sdp_cb.reg_info.pL2CA_ConnectPnd_Cb = NULL; - sdp_cb.reg_info.pL2CA_ConfigInd_Cb = sdp_config_ind; - sdp_cb.reg_info.pL2CA_ConfigCfm_Cb = sdp_config_cfm; - sdp_cb.reg_info.pL2CA_DisconnectInd_Cb = sdp_disconnect_ind; - sdp_cb.reg_info.pL2CA_DisconnectCfm_Cb = sdp_disconnect_cfm; - sdp_cb.reg_info.pL2CA_QoSViolationInd_Cb = NULL; - sdp_cb.reg_info.pL2CA_DataInd_Cb = sdp_data_ind; - sdp_cb.reg_info.pL2CA_CongestionStatus_Cb = NULL; - sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL; - - /* Now, register with L2CAP */ - if (!L2CA_Register (SDP_PSM, &sdp_cb.reg_info)) - { - SDP_TRACE_ERROR ("SDP Registration failed"); - } + sdp_cb.reg_info.pL2CA_ConnectInd_Cb = sdp_connect_ind; + sdp_cb.reg_info.pL2CA_ConnectCfm_Cb = sdp_connect_cfm; + sdp_cb.reg_info.pL2CA_ConnectPnd_Cb = NULL; + sdp_cb.reg_info.pL2CA_ConfigInd_Cb = sdp_config_ind; + sdp_cb.reg_info.pL2CA_ConfigCfm_Cb = sdp_config_cfm; + sdp_cb.reg_info.pL2CA_DisconnectInd_Cb = sdp_disconnect_ind; + sdp_cb.reg_info.pL2CA_DisconnectCfm_Cb = sdp_disconnect_cfm; + sdp_cb.reg_info.pL2CA_QoSViolationInd_Cb = NULL; + sdp_cb.reg_info.pL2CA_DataInd_Cb = sdp_data_ind; + sdp_cb.reg_info.pL2CA_CongestionStatus_Cb = NULL; + sdp_cb.reg_info.pL2CA_TxComplete_Cb = NULL; + + /* Now, register with L2CAP */ + if (!L2CA_Register(SDP_PSM, &sdp_cb.reg_info)) { + SDP_TRACE_ERROR("SDP Registration failed"); + } } #if (SDP_DEBUG == TRUE) @@ -148,14 +142,13 @@ void sdp_init (void) * Returns void * ******************************************************************************/ -uint16_t sdp_set_max_attr_list_size (uint16_t max_size) -{ - if (max_size > (sdp_cb.l2cap_my_cfg.mtu - 16) ) - max_size = sdp_cb.l2cap_my_cfg.mtu - 16; +uint16_t sdp_set_max_attr_list_size(uint16_t max_size) { + if (max_size > (sdp_cb.l2cap_my_cfg.mtu - 16)) + max_size = sdp_cb.l2cap_my_cfg.mtu - 16; - sdp_cb.max_attr_list_size = max_size; + sdp_cb.max_attr_list_size = max_size; - return sdp_cb.max_attr_list_size; + return sdp_cb.max_attr_list_size; } #endif @@ -170,50 +163,49 @@ uint16_t sdp_set_max_attr_list_size (uint16_t max_size) * Returns void * ******************************************************************************/ -static void sdp_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, - UNUSED_ATTR uint16_t psm, uint8_t l2cap_id) -{ +static void sdp_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, + UNUSED_ATTR uint16_t psm, uint8_t l2cap_id) { #if (SDP_SERVER_ENABLED == TRUE) - tCONN_CB *p_ccb; - - /* Allocate a new CCB. Return if none available. */ - p_ccb = sdpu_allocate_ccb(); - if (p_ccb == NULL) - return; - - /* Transition to the next appropriate state, waiting for config setup. */ - p_ccb->con_state = SDP_STATE_CFG_SETUP; + tCONN_CB* p_ccb; + + /* Allocate a new CCB. Return if none available. */ + p_ccb = sdpu_allocate_ccb(); + if (p_ccb == NULL) return; + + /* Transition to the next appropriate state, waiting for config setup. */ + p_ccb->con_state = SDP_STATE_CFG_SETUP; + + /* Save the BD Address and Channel ID. */ + memcpy(&p_ccb->device_address[0], bd_addr, sizeof(BD_ADDR)); + p_ccb->connection_id = l2cap_cid; + + /* Send response to the L2CAP layer. */ + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); + { + tL2CAP_CFG_INFO cfg = sdp_cb.l2cap_my_cfg; + + if (cfg.fcr_present) { + SDP_TRACE_DEBUG( + "sdp_connect_ind: mode %u, txwinsz %u, max_trans %u, rtrans_tout " + "%u, mon_tout %u, mps %u", + cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit, + cfg.fcr.rtrans_tout, cfg.fcr.mon_tout, cfg.fcr.mps); + } - /* Save the BD Address and Channel ID. */ - memcpy (&p_ccb->device_address[0], bd_addr, sizeof (BD_ADDR)); - p_ccb->connection_id = l2cap_cid; - - /* Send response to the L2CAP layer. */ - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK); - { - tL2CAP_CFG_INFO cfg = sdp_cb.l2cap_my_cfg; - - if (cfg.fcr_present) - { - SDP_TRACE_DEBUG("sdp_connect_ind: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u", - cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit, - cfg.fcr.rtrans_tout,cfg.fcr.mon_tout, cfg.fcr.mps); - } - - if ((!L2CA_ConfigReq (l2cap_cid, &cfg)) && cfg.fcr_present - && cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - /* FCR not desired; try again in basic mode */ - cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; - cfg.fcr_present = false; - L2CA_ConfigReq (l2cap_cid, &cfg); - } + if ((!L2CA_ConfigReq(l2cap_cid, &cfg)) && cfg.fcr_present && + cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + /* FCR not desired; try again in basic mode */ + cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; + cfg.fcr_present = false; + L2CA_ConfigReq(l2cap_cid, &cfg); } + } - SDP_TRACE_EVENT ("SDP - Rcvd L2CAP conn ind, sent config req, CID 0x%x", p_ccb->connection_id); -#else /* No server */ - /* Reject the connection */ - L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0); + SDP_TRACE_EVENT("SDP - Rcvd L2CAP conn ind, sent config req, CID 0x%x", + p_ccb->connection_id); +#else /* No server */ + /* Reject the connection */ + L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0); #endif } @@ -229,74 +221,68 @@ static void sdp_connect_ind (BD_ADDR bd_addr, uint16_t l2cap_cid, * Returns void * ******************************************************************************/ -static void sdp_connect_cfm (uint16_t l2cap_cid, uint16_t result) -{ - tCONN_CB *p_ccb; - tL2CAP_CFG_INFO cfg; - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid); - return; +static void sdp_connect_cfm(uint16_t l2cap_cid, uint16_t result) { + tCONN_CB* p_ccb; + tL2CAP_CFG_INFO cfg; + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid); + return; + } + + /* If the connection response contains success status, then */ + /* Transition to the next state and startup the timer. */ + if ((result == L2CAP_CONN_OK) && (p_ccb->con_state == SDP_STATE_CONN_SETUP)) { + p_ccb->con_state = SDP_STATE_CFG_SETUP; + + cfg = sdp_cb.l2cap_my_cfg; + + if (cfg.fcr_present) { + SDP_TRACE_DEBUG( + "sdp_connect_cfm: mode %u, txwinsz %u, max_trans %u, rtrans_tout " + "%u, mon_tout %u, mps %u", + cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit, + cfg.fcr.rtrans_tout, cfg.fcr.mon_tout, cfg.fcr.mps); } - /* If the connection response contains success status, then */ - /* Transition to the next state and startup the timer. */ - if ((result == L2CAP_CONN_OK) && (p_ccb->con_state == SDP_STATE_CONN_SETUP)) - { - p_ccb->con_state = SDP_STATE_CFG_SETUP; - - cfg = sdp_cb.l2cap_my_cfg; - - if (cfg.fcr_present) - { - SDP_TRACE_DEBUG("sdp_connect_cfm: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u", - cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit, - cfg.fcr.rtrans_tout,cfg.fcr.mon_tout, cfg.fcr.mps); - } - - if ((!L2CA_ConfigReq (l2cap_cid, &cfg)) && cfg.fcr_present - && cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) - { - /* FCR not desired; try again in basic mode */ - cfg.fcr_present = false; - cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; - L2CA_ConfigReq (l2cap_cid, &cfg); - } - - SDP_TRACE_EVENT ("SDP - got conn cnf, sent cfg req, CID: 0x%x", p_ccb->connection_id); + if ((!L2CA_ConfigReq(l2cap_cid, &cfg)) && cfg.fcr_present && + cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { + /* FCR not desired; try again in basic mode */ + cfg.fcr_present = false; + cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; + L2CA_ConfigReq(l2cap_cid, &cfg); } - else - { - SDP_TRACE_WARNING ("SDP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, p_ccb->connection_id); - - /* Tell the user if he has a callback */ - if (p_ccb->p_cb || p_ccb->p_cb2) - { - uint16_t err = -1; - if ((result == HCI_ERR_HOST_REJECT_SECURITY) - || (result == HCI_ERR_AUTH_FAILURE) - || (result == HCI_ERR_PAIRING_NOT_ALLOWED) - || (result == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) - || (result == HCI_ERR_KEY_MISSING)) - err = SDP_SECURITY_ERR; - else if (result == HCI_ERR_HOST_REJECT_DEVICE) - err = SDP_CONN_REJECTED; - else - err = SDP_CONN_FAILED; - if(p_ccb->p_cb) - (*p_ccb->p_cb)(err); - else if(p_ccb->p_cb2) - (*p_ccb->p_cb2)(err, p_ccb->user_data); - - } - sdpu_release_ccb (p_ccb); + + SDP_TRACE_EVENT("SDP - got conn cnf, sent cfg req, CID: 0x%x", + p_ccb->connection_id); + } else { + SDP_TRACE_WARNING("SDP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, + p_ccb->connection_id); + + /* Tell the user if he has a callback */ + if (p_ccb->p_cb || p_ccb->p_cb2) { + uint16_t err = -1; + if ((result == HCI_ERR_HOST_REJECT_SECURITY) || + (result == HCI_ERR_AUTH_FAILURE) || + (result == HCI_ERR_PAIRING_NOT_ALLOWED) || + (result == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) || + (result == HCI_ERR_KEY_MISSING)) + err = SDP_SECURITY_ERR; + else if (result == HCI_ERR_HOST_REJECT_DEVICE) + err = SDP_CONN_REJECTED; + else + err = SDP_CONN_FAILED; + if (p_ccb->p_cb) + (*p_ccb->p_cb)(err); + else if (p_ccb->p_cb2) + (*p_ccb->p_cb2)(err, p_ccb->user_data); } + sdpu_release_ccb(p_ccb); + } } -#endif /* SDP_CLIENT_ENABLED == TRUE */ - +#endif /* SDP_CLIENT_ENABLED == TRUE */ /******************************************************************************* * @@ -308,90 +294,86 @@ static void sdp_connect_cfm (uint16_t l2cap_cid, uint16_t result) * Returns void * ******************************************************************************/ -static void sdp_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tCONN_CB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; - } - - /* Remember the remote MTU size */ - if (!p_cfg->mtu_present) - { - /* use min(L2CAP_DEFAULT_MTU,SDP_MTU_SIZE) for GKI buffer size reasons */ - p_ccb->rem_mtu_size = (L2CAP_DEFAULT_MTU > SDP_MTU_SIZE)?SDP_MTU_SIZE:L2CAP_DEFAULT_MTU; - } +static void sdp_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tCONN_CB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); + return; + } + + /* Remember the remote MTU size */ + if (!p_cfg->mtu_present) { + /* use min(L2CAP_DEFAULT_MTU,SDP_MTU_SIZE) for GKI buffer size reasons */ + p_ccb->rem_mtu_size = + (L2CAP_DEFAULT_MTU > SDP_MTU_SIZE) ? SDP_MTU_SIZE : L2CAP_DEFAULT_MTU; + } else { + if (p_cfg->mtu > SDP_MTU_SIZE) + p_ccb->rem_mtu_size = SDP_MTU_SIZE; else - { - if (p_cfg->mtu > SDP_MTU_SIZE) - p_ccb->rem_mtu_size = SDP_MTU_SIZE; - else - p_ccb->rem_mtu_size = p_cfg->mtu; - } - - /* For now, always accept configuration from the other side */ - p_cfg->flush_to_present = false; - p_cfg->mtu_present = false; - p_cfg->result = L2CAP_CFG_OK; - - /* Check peer config request against our rfcomm configuration */ - if (p_cfg->fcr_present) - { - /* Reject the window size if it is bigger than we want it to be */ - if (p_cfg->fcr.mode != L2CAP_FCR_BASIC_MODE) - { - if (sdp_cb.l2cap_my_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE - && p_cfg->fcr.tx_win_sz > sdp_cb.l2cap_my_cfg.fcr.tx_win_sz) - { - p_cfg->fcr.tx_win_sz = sdp_cb.l2cap_my_cfg.fcr.tx_win_sz; - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with SMALLER TX WINDOW"); - } - - /* Reject if locally we want basic and they don't */ - if (sdp_cb.l2cap_my_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) - { - /* Ask for a new setup */ - p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with BASIC mode"); - } - /* Remain in configure state and give the peer our desired configuration */ - if (p_cfg->result != L2CAP_CFG_OK) - { - SDP_TRACE_WARNING ("SDP - Rcvd cfg ind, Unacceptable Parameters sent cfg cfm, CID: 0x%x", l2cap_cid); - L2CA_ConfigRsp (l2cap_cid, p_cfg); - return; - } - } - else /* We agree with peer's request */ - p_cfg->fcr_present = false; - } + p_ccb->rem_mtu_size = p_cfg->mtu; + } + + /* For now, always accept configuration from the other side */ + p_cfg->flush_to_present = false; + p_cfg->mtu_present = false; + p_cfg->result = L2CAP_CFG_OK; + + /* Check peer config request against our rfcomm configuration */ + if (p_cfg->fcr_present) { + /* Reject the window size if it is bigger than we want it to be */ + if (p_cfg->fcr.mode != L2CAP_FCR_BASIC_MODE) { + if (sdp_cb.l2cap_my_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE && + p_cfg->fcr.tx_win_sz > sdp_cb.l2cap_my_cfg.fcr.tx_win_sz) { + p_cfg->fcr.tx_win_sz = sdp_cb.l2cap_my_cfg.fcr.tx_win_sz; + p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + SDP_TRACE_DEBUG( + "sdp_config_ind(CONFIG) -> Please try again with SMALLER TX " + "WINDOW"); + } + + /* Reject if locally we want basic and they don't */ + if (sdp_cb.l2cap_my_cfg.fcr.mode == L2CAP_FCR_BASIC_MODE) { + /* Ask for a new setup */ + p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE; + p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + SDP_TRACE_DEBUG( + "sdp_config_ind(CONFIG) -> Please try again with BASIC mode"); + } + /* Remain in configure state and give the peer our desired configuration + */ + if (p_cfg->result != L2CAP_CFG_OK) { + SDP_TRACE_WARNING( + "SDP - Rcvd cfg ind, Unacceptable Parameters sent cfg cfm, CID: " + "0x%x", + l2cap_cid); + L2CA_ConfigRsp(l2cap_cid, p_cfg); + return; + } + } else /* We agree with peer's request */ + p_cfg->fcr_present = false; + } - L2CA_ConfigRsp (l2cap_cid, p_cfg); + L2CA_ConfigRsp(l2cap_cid, p_cfg); - SDP_TRACE_EVENT ("SDP - Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid); + SDP_TRACE_EVENT("SDP - Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid); - p_ccb->con_flags |= SDP_FLAGS_HIS_CFG_DONE; + p_ccb->con_flags |= SDP_FLAGS_HIS_CFG_DONE; - if (p_ccb->con_flags & SDP_FLAGS_MY_CFG_DONE) - { - p_ccb->con_state = SDP_STATE_CONNECTED; + if (p_ccb->con_flags & SDP_FLAGS_MY_CFG_DONE) { + p_ccb->con_state = SDP_STATE_CONNECTED; - if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) { - sdp_disc_connected (p_ccb); - } else { - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, - btu_general_alarm_queue); - } + if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) { + sdp_disc_connected(p_ccb); + } else { + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, + btu_general_alarm_queue); } + } } /******************************************************************************* @@ -404,56 +386,50 @@ static void sdp_config_ind (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void sdp_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) -{ - tCONN_CB *p_ccb; - - SDP_TRACE_EVENT ("SDP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result); - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); - return; +static void sdp_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { + tCONN_CB* p_ccb; + + SDP_TRACE_EVENT("SDP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, + p_cfg->result); + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid); + return; + } + + /* For now, always accept configuration from the other side */ + if (p_cfg->result == L2CAP_CFG_OK) { + p_ccb->con_flags |= SDP_FLAGS_MY_CFG_DONE; + + if (p_ccb->con_flags & SDP_FLAGS_HIS_CFG_DONE) { + p_ccb->con_state = SDP_STATE_CONNECTED; + + if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) { + sdp_disc_connected(p_ccb); + } else { + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, + btu_general_alarm_queue); + } } - - /* For now, always accept configuration from the other side */ - if (p_cfg->result == L2CAP_CFG_OK) - { - p_ccb->con_flags |= SDP_FLAGS_MY_CFG_DONE; - - if (p_ccb->con_flags & SDP_FLAGS_HIS_CFG_DONE) - { - p_ccb->con_state = SDP_STATE_CONNECTED; - - if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) { - sdp_disc_connected (p_ccb); - } else { - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, - btu_general_alarm_queue); - } - } + } else { + /* If peer has rejected FCR and suggested basic then try basic */ + if (p_cfg->fcr_present) { + tL2CAP_CFG_INFO cfg = sdp_cb.l2cap_my_cfg; + cfg.fcr_present = false; + L2CA_ConfigReq(l2cap_cid, &cfg); + + /* Remain in configure state */ + return; } - else - { - /* If peer has rejected FCR and suggested basic then try basic */ - if (p_cfg->fcr_present) - { - tL2CAP_CFG_INFO cfg = sdp_cb.l2cap_my_cfg; - cfg.fcr_present = false; - L2CA_ConfigReq (l2cap_cid, &cfg); - - /* Remain in configure state */ - return; - } #if (SDP_CLIENT_ENABLED == TRUE) - sdp_disconnect(p_ccb, SDP_CFG_FAILED); + sdp_disconnect(p_ccb, SDP_CFG_FAILED); #endif - } + } } /******************************************************************************* @@ -466,33 +442,33 @@ static void sdp_config_cfm (uint16_t l2cap_cid, tL2CAP_CFG_INFO *p_cfg) * Returns void * ******************************************************************************/ -static void sdp_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) -{ - tCONN_CB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); - return; - } +static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) { + tCONN_CB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid); + return; + } - if (ack_needed) - L2CA_DisconnectRsp (l2cap_cid); + if (ack_needed) L2CA_DisconnectRsp(l2cap_cid); - SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); + SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid); #if (SDP_CLIENT_ENABLED == TRUE) - /* Tell the user if he has a callback */ - if (p_ccb->p_cb) - (*p_ccb->p_cb) ((uint16_t) ((p_ccb->con_state == SDP_STATE_CONNECTED) ? - SDP_SUCCESS : SDP_CONN_FAILED)); - else if (p_ccb->p_cb2) - (*p_ccb->p_cb2) ((uint16_t) ((p_ccb->con_state == SDP_STATE_CONNECTED) ? - SDP_SUCCESS : SDP_CONN_FAILED), p_ccb->user_data); + /* Tell the user if he has a callback */ + if (p_ccb->p_cb) + (*p_ccb->p_cb)((uint16_t)((p_ccb->con_state == SDP_STATE_CONNECTED) + ? SDP_SUCCESS + : SDP_CONN_FAILED)); + else if (p_ccb->p_cb2) + (*p_ccb->p_cb2)( + (uint16_t)((p_ccb->con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS + : SDP_CONN_FAILED), + p_ccb->user_data); #endif - sdpu_release_ccb (p_ccb); + sdpu_release_ccb(p_ccb); } /******************************************************************************* @@ -510,36 +486,29 @@ static void sdp_disconnect_ind (uint16_t l2cap_cid, bool ack_needed) * Returns void * ******************************************************************************/ -static void sdp_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) -{ - tCONN_CB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb != NULL) - { - if (p_ccb->con_state == SDP_STATE_CONNECTED) - { - if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) - sdp_disc_server_rsp (p_ccb, p_msg); - else - sdp_server_handle_client_req (p_ccb, p_msg); - } - else - { - SDP_TRACE_WARNING ("SDP - Ignored L2CAP data while in state: %d, CID: 0x%x", - p_ccb->con_state, l2cap_cid); - } - } - else - { - SDP_TRACE_WARNING ("SDP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); +static void sdp_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) { + tCONN_CB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb != NULL) { + if (p_ccb->con_state == SDP_STATE_CONNECTED) { + if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) + sdp_disc_server_rsp(p_ccb, p_msg); + else + sdp_server_handle_client_req(p_ccb, p_msg); + } else { + SDP_TRACE_WARNING( + "SDP - Ignored L2CAP data while in state: %d, CID: 0x%x", + p_ccb->con_state, l2cap_cid); } + } else { + SDP_TRACE_WARNING("SDP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid); + } - osi_free(p_msg); + osi_free(p_msg); } - #if (SDP_CLIENT_ENABLED == TRUE) /******************************************************************************* * @@ -551,45 +520,41 @@ static void sdp_data_ind (uint16_t l2cap_cid, BT_HDR *p_msg) * Returns void * ******************************************************************************/ -tCONN_CB* sdp_conn_originate (uint8_t *p_bd_addr) -{ - tCONN_CB *p_ccb; - uint16_t cid; - - /* Allocate a new CCB. Return if none available. */ - p_ccb = sdpu_allocate_ccb(); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - no spare CCB for orig"); - return (NULL); - } +tCONN_CB* sdp_conn_originate(uint8_t* p_bd_addr) { + tCONN_CB* p_ccb; + uint16_t cid; - SDP_TRACE_EVENT ("SDP - Originate started"); + /* Allocate a new CCB. Return if none available. */ + p_ccb = sdpu_allocate_ccb(); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - no spare CCB for orig"); + return (NULL); + } - /* We are the originator of this connection */ - p_ccb->con_flags |= SDP_FLAGS_IS_ORIG; + SDP_TRACE_EVENT("SDP - Originate started"); - /* Save the BD Address and Channel ID. */ - memcpy (&p_ccb->device_address[0], p_bd_addr, sizeof (BD_ADDR)); + /* We are the originator of this connection */ + p_ccb->con_flags |= SDP_FLAGS_IS_ORIG; - /* Transition to the next appropriate state, waiting for connection confirm. */ - p_ccb->con_state = SDP_STATE_CONN_SETUP; + /* Save the BD Address and Channel ID. */ + memcpy(&p_ccb->device_address[0], p_bd_addr, sizeof(BD_ADDR)); - cid = L2CA_ConnectReq (SDP_PSM, p_bd_addr); + /* Transition to the next appropriate state, waiting for connection confirm. + */ + p_ccb->con_state = SDP_STATE_CONN_SETUP; - /* Check if L2CAP started the connection process */ - if (cid != 0) - { - p_ccb->connection_id = cid; + cid = L2CA_ConnectReq(SDP_PSM, p_bd_addr); - return (p_ccb); - } - else - { - SDP_TRACE_WARNING ("SDP - Originate failed"); - sdpu_release_ccb (p_ccb); - return (NULL); - } + /* Check if L2CAP started the connection process */ + if (cid != 0) { + p_ccb->connection_id = cid; + + return (p_ccb); + } else { + SDP_TRACE_WARNING("SDP - Originate failed"); + sdpu_release_ccb(p_ccb); + return (NULL); + } } /******************************************************************************* @@ -601,70 +566,65 @@ tCONN_CB* sdp_conn_originate (uint8_t *p_bd_addr) * Returns void * ******************************************************************************/ -void sdp_disconnect (tCONN_CB*p_ccb, uint16_t reason) -{ +void sdp_disconnect(tCONN_CB* p_ccb, uint16_t reason) { #if (SDP_BROWSE_PLUS == TRUE) - /* If we are browsing for multiple UUIDs ... */ - if ((p_ccb->con_state == SDP_STATE_CONNECTED) - && (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) - && ((reason == SDP_SUCCESS) || (reason == SDP_NO_RECS_MATCH))) - { - /* If the browse found something, do no more searching */ - if ((p_ccb->cur_uuid_idx == 0) && (p_ccb->p_db->p_first_rec)) - p_ccb->cur_uuid_idx = p_ccb->p_db->num_uuid_filters; - - while (++p_ccb->cur_uuid_idx < p_ccb->p_db->num_uuid_filters) - { - /* Check we have not already found the UUID (maybe through browse) */ - if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len == 2) - && (SDP_FindServiceInDb (p_ccb->p_db, - p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].uu.uuid16, - NULL))) - continue; - - if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len > 2) - && (SDP_FindServiceUUIDInDb (p_ccb->p_db, - &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx], NULL))) - continue; - - p_ccb->cur_handle = 0; - - SDP_TRACE_EVENT ("SDP - looking for for more, CID: 0x%x", - p_ccb->connection_id); - - sdp_disc_connected (p_ccb); - return; - } + /* If we are browsing for multiple UUIDs ... */ + if ((p_ccb->con_state == SDP_STATE_CONNECTED) && + (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) && + ((reason == SDP_SUCCESS) || (reason == SDP_NO_RECS_MATCH))) { + /* If the browse found something, do no more searching */ + if ((p_ccb->cur_uuid_idx == 0) && (p_ccb->p_db->p_first_rec)) + p_ccb->cur_uuid_idx = p_ccb->p_db->num_uuid_filters; + + while (++p_ccb->cur_uuid_idx < p_ccb->p_db->num_uuid_filters) { + /* Check we have not already found the UUID (maybe through browse) */ + if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len == 2) && + (SDP_FindServiceInDb( + p_ccb->p_db, + p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].uu.uuid16, NULL))) + continue; + + if ((p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx].len > 2) && + (SDP_FindServiceUUIDInDb( + p_ccb->p_db, &p_ccb->p_db->uuid_filters[p_ccb->cur_uuid_idx], + NULL))) + continue; + + p_ccb->cur_handle = 0; + + SDP_TRACE_EVENT("SDP - looking for for more, CID: 0x%x", + p_ccb->connection_id); + + sdp_disc_connected(p_ccb); + return; } + } - if ((reason == SDP_NO_RECS_MATCH) && (p_ccb->p_db->p_first_rec)) - reason = SDP_SUCCESS; + if ((reason == SDP_NO_RECS_MATCH) && (p_ccb->p_db->p_first_rec)) + reason = SDP_SUCCESS; #endif - SDP_TRACE_EVENT ("SDP - disconnect CID: 0x%x", p_ccb->connection_id); + SDP_TRACE_EVENT("SDP - disconnect CID: 0x%x", p_ccb->connection_id); - /* Check if we have a connection ID */ - if (p_ccb->connection_id != 0) - { - L2CA_DisconnectReq (p_ccb->connection_id); - p_ccb->disconnect_reason = reason; - } + /* Check if we have a connection ID */ + if (p_ccb->connection_id != 0) { + L2CA_DisconnectReq(p_ccb->connection_id); + p_ccb->disconnect_reason = reason; + } - /* If at setup state, we may not get callback ind from L2CAP */ - /* Call user callback immediately */ - if (p_ccb->con_state == SDP_STATE_CONN_SETUP) - { - /* Tell the user if he has a callback */ - if (p_ccb->p_cb) - (*p_ccb->p_cb) (reason); - else if (p_ccb->p_cb2) - (*p_ccb->p_cb2) (reason, p_ccb->user_data); - - sdpu_release_ccb (p_ccb); - } + /* If at setup state, we may not get callback ind from L2CAP */ + /* Call user callback immediately */ + if (p_ccb->con_state == SDP_STATE_CONN_SETUP) { + /* Tell the user if he has a callback */ + if (p_ccb->p_cb) + (*p_ccb->p_cb)(reason); + else if (p_ccb->p_cb2) + (*p_ccb->p_cb2)(reason, p_ccb->user_data); + sdpu_release_ccb(p_ccb); + } } /******************************************************************************* @@ -676,32 +636,30 @@ void sdp_disconnect (tCONN_CB*p_ccb, uint16_t reason) * Returns void * ******************************************************************************/ -static void sdp_disconnect_cfm (uint16_t l2cap_cid, - UNUSED_ATTR uint16_t result) -{ - tCONN_CB *p_ccb; - - /* Find CCB based on CID */ - p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); - if (p_ccb == NULL) - { - SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid); - return; - } - - SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); - - /* Tell the user if he has a callback */ - if (p_ccb->p_cb) - (*p_ccb->p_cb) (p_ccb->disconnect_reason); - else if (p_ccb->p_cb2) - (*p_ccb->p_cb2) (p_ccb->disconnect_reason, p_ccb->user_data); - - - sdpu_release_ccb (p_ccb); +static void sdp_disconnect_cfm(uint16_t l2cap_cid, + UNUSED_ATTR uint16_t result) { + tCONN_CB* p_ccb; + + /* Find CCB based on CID */ + p_ccb = sdpu_find_ccb_by_cid(l2cap_cid); + if (p_ccb == NULL) { + SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x%x", + l2cap_cid); + return; + } + + SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid); + + /* Tell the user if he has a callback */ + if (p_ccb->p_cb) + (*p_ccb->p_cb)(p_ccb->disconnect_reason); + else if (p_ccb->p_cb2) + (*p_ccb->p_cb2)(p_ccb->disconnect_reason, p_ccb->user_data); + + sdpu_release_ccb(p_ccb); } -#endif /* SDP_CLIENT_ENABLED == TRUE */ +#endif /* SDP_CLIENT_ENABLED == TRUE */ /******************************************************************************* * @@ -713,24 +671,19 @@ static void sdp_disconnect_cfm (uint16_t l2cap_cid, * Returns void * ******************************************************************************/ -void sdp_conn_timer_timeout(void *data) -{ - tCONN_CB *p_ccb = (tCONN_CB *)data; +void sdp_conn_timer_timeout(void* data) { + tCONN_CB* p_ccb = (tCONN_CB*)data; - SDP_TRACE_EVENT ("SDP - CCB timeout in state: %d CID: 0x%x", - p_ccb->con_state, p_ccb->connection_id); + SDP_TRACE_EVENT("SDP - CCB timeout in state: %d CID: 0x%x", p_ccb->con_state, + p_ccb->connection_id); - L2CA_DisconnectReq (p_ccb->connection_id); + L2CA_DisconnectReq(p_ccb->connection_id); #if (SDP_CLIENT_ENABLED == TRUE) - /* Tell the user if he has a callback */ - if (p_ccb->p_cb) - (*p_ccb->p_cb) (SDP_CONN_FAILED); - else if (p_ccb->p_cb2) - (*p_ccb->p_cb2) (SDP_CONN_FAILED, p_ccb->user_data); + /* Tell the user if he has a callback */ + if (p_ccb->p_cb) + (*p_ccb->p_cb)(SDP_CONN_FAILED); + else if (p_ccb->p_cb2) + (*p_ccb->p_cb2)(SDP_CONN_FAILED, p_ccb->user_data); #endif - sdpu_release_ccb (p_ccb); + sdpu_release_ccb(p_ccb); } - - - - diff --git a/stack/sdp/sdp_server.cc b/stack/sdp/sdp_server.cc index ae500037e..fe67be19b 100644 --- a/stack/sdp/sdp_server.cc +++ b/stack/sdp/sdp_server.cc @@ -23,48 +23,46 @@ * ******************************************************************************/ +#include #include #include -#include #include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" #include "btu.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "osi/include/osi.h" #include "sdp_api.h" #include "sdpint.h" - #if (SDP_SERVER_ENABLED == TRUE) -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; /* Maximum number of bytes to reserve out of SDP MTU for response data */ -#define SDP_MAX_SERVICE_RSPHDR_LEN 12 -#define SDP_MAX_SERVATTR_RSPHDR_LEN 10 -#define SDP_MAX_ATTR_RSPHDR_LEN 10 +#define SDP_MAX_SERVICE_RSPHDR_LEN 12 +#define SDP_MAX_SERVATTR_RSPHDR_LEN 10 +#define SDP_MAX_ATTR_RSPHDR_LEN 10 /******************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /******************************************************************************/ -static void process_service_search (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - UNUSED_ATTR uint8_t *p_req_end); - -static void process_service_attr_req (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - uint8_t *p_req_end); +static void process_service_search(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + UNUSED_ATTR uint8_t* p_req_end); -static void process_service_search_attr_req (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - UNUSED_ATTR uint8_t *p_req_end); +static void process_service_attr_req(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + uint8_t* p_req_end); +static void process_service_search_attr_req(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + UNUSED_ATTR uint8_t* p_req_end); /******************************************************************************/ /* E R R O R T E X T S T R I N G S */ @@ -73,35 +71,35 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, uint16_t trans_num /* configured in target.h if people want them. */ /******************************************************************************/ #ifndef SDP_TEXT_BAD_HEADER -#define SDP_TEXT_BAD_HEADER NULL +#define SDP_TEXT_BAD_HEADER NULL #endif #ifndef SDP_TEXT_BAD_PDU -#define SDP_TEXT_BAD_PDU NULL +#define SDP_TEXT_BAD_PDU NULL #endif #ifndef SDP_TEXT_BAD_UUID_LIST -#define SDP_TEXT_BAD_UUID_LIST NULL +#define SDP_TEXT_BAD_UUID_LIST NULL #endif #ifndef SDP_TEXT_BAD_HANDLE -#define SDP_TEXT_BAD_HANDLE NULL +#define SDP_TEXT_BAD_HANDLE NULL #endif #ifndef SDP_TEXT_BAD_ATTR_LIST -#define SDP_TEXT_BAD_ATTR_LIST NULL +#define SDP_TEXT_BAD_ATTR_LIST NULL #endif #ifndef SDP_TEXT_BAD_CONT_LEN -#define SDP_TEXT_BAD_CONT_LEN NULL +#define SDP_TEXT_BAD_CONT_LEN NULL #endif #ifndef SDP_TEXT_BAD_CONT_INX -#define SDP_TEXT_BAD_CONT_INX NULL +#define SDP_TEXT_BAD_CONT_INX NULL #endif #ifndef SDP_TEXT_BAD_MAX_RECORDS_LIST -#define SDP_TEXT_BAD_MAX_RECORDS_LIST NULL +#define SDP_TEXT_BAD_MAX_RECORDS_LIST NULL #endif /******************************************************************************* @@ -115,54 +113,51 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, uint16_t trans_num * Returns void * ******************************************************************************/ -void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg) -{ - uint8_t *p_req = (uint8_t *) (p_msg + 1) + p_msg->offset; - uint8_t *p_req_end = p_req + p_msg->len; - uint8_t pdu_id; - uint16_t trans_num, param_len; - - - /* Start inactivity timer */ - alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, - sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); - - /* The first byte in the message is the pdu type */ - pdu_id = *p_req++; - - /* Extract the transaction number and parameter length */ - BE_STREAM_TO_UINT16 (trans_num, p_req); - BE_STREAM_TO_UINT16 (param_len, p_req); - - if ((p_req + param_len) != p_req_end) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_PDU_SIZE, SDP_TEXT_BAD_HEADER); - return; - } - - switch (pdu_id) - { +void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg) { + uint8_t* p_req = (uint8_t*)(p_msg + 1) + p_msg->offset; + uint8_t* p_req_end = p_req + p_msg->len; + uint8_t pdu_id; + uint16_t trans_num, param_len; + + /* Start inactivity timer */ + alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS, + sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue); + + /* The first byte in the message is the pdu type */ + pdu_id = *p_req++; + + /* Extract the transaction number and parameter length */ + BE_STREAM_TO_UINT16(trans_num, p_req); + BE_STREAM_TO_UINT16(param_len, p_req); + + if ((p_req + param_len) != p_req_end) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_PDU_SIZE, + SDP_TEXT_BAD_HEADER); + return; + } + + switch (pdu_id) { case SDP_PDU_SERVICE_SEARCH_REQ: - process_service_search (p_ccb, trans_num, param_len, p_req, p_req_end); - break; + process_service_search(p_ccb, trans_num, param_len, p_req, p_req_end); + break; case SDP_PDU_SERVICE_ATTR_REQ: - process_service_attr_req (p_ccb, trans_num, param_len, p_req, p_req_end); - break; + process_service_attr_req(p_ccb, trans_num, param_len, p_req, p_req_end); + break; case SDP_PDU_SERVICE_SEARCH_ATTR_REQ: - process_service_search_attr_req (p_ccb, trans_num, param_len, p_req, p_req_end); - break; + process_service_search_attr_req(p_ccb, trans_num, param_len, p_req, + p_req_end); + break; default: - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_PDU); - SDP_TRACE_WARNING ("SDP - server got unknown PDU: 0x%x", pdu_id); - break; - } + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_PDU); + SDP_TRACE_WARNING("SDP - server got unknown PDU: 0x%x", pdu_id); + break; + } } - - /******************************************************************************* * * Function process_service_search @@ -174,133 +169,122 @@ void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg) * Returns void * ******************************************************************************/ -static void process_service_search (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - UNUSED_ATTR uint8_t *p_req_end) -{ - uint16_t max_replies, cur_handles, rem_handles, cont_offset; - tSDP_UUID_SEQ uid_seq; - uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; - uint16_t rsp_param_len, num_rsp_handles, xx; - uint32_t rsp_handles[SDP_MAX_RECORDS] = {0}; - tSDP_RECORD *p_rec = NULL; - bool is_cont = false; - - p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq); - - if ((!p_req) || (!uid_seq.num_uids)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_UUID_LIST); - return; - } - - /* Get the max replies we can send. Cap it at our max anyways. */ - BE_STREAM_TO_UINT16 (max_replies, p_req); - - if (max_replies > SDP_MAX_RECORDS) - max_replies = SDP_MAX_RECORDS; - - - if ((!p_req) || (p_req > p_req_end)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_MAX_RECORDS_LIST); - return; - } - - - /* Get a list of handles that match the UUIDs given to us */ - for (num_rsp_handles = 0; num_rsp_handles < max_replies; ) - { - p_rec = sdp_db_service_search (p_rec, &uid_seq); - - if (p_rec) - rsp_handles[num_rsp_handles++] = p_rec->record_handle; - else - break; - } - - /* Check if this is a continuation request */ - if (*p_req) - { - if (*p_req++ != SDP_CONTINUATION_LEN || (p_req >= p_req_end)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_LEN); - return; - } - BE_STREAM_TO_UINT16 (cont_offset, p_req); - - if (cont_offset != p_ccb->cont_offset) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_INX); - return; - } - - rem_handles = num_rsp_handles - cont_offset; /* extract the remaining handles */ - } +static void process_service_search(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + UNUSED_ATTR uint8_t* p_req_end) { + uint16_t max_replies, cur_handles, rem_handles, cont_offset; + tSDP_UUID_SEQ uid_seq; + uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; + uint16_t rsp_param_len, num_rsp_handles, xx; + uint32_t rsp_handles[SDP_MAX_RECORDS] = {0}; + tSDP_RECORD* p_rec = NULL; + bool is_cont = false; + + p_req = sdpu_extract_uid_seq(p_req, param_len, &uid_seq); + + if ((!p_req) || (!uid_seq.num_uids)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_UUID_LIST); + return; + } + + /* Get the max replies we can send. Cap it at our max anyways. */ + BE_STREAM_TO_UINT16(max_replies, p_req); + + if (max_replies > SDP_MAX_RECORDS) max_replies = SDP_MAX_RECORDS; + + if ((!p_req) || (p_req > p_req_end)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_MAX_RECORDS_LIST); + return; + } + + /* Get a list of handles that match the UUIDs given to us */ + for (num_rsp_handles = 0; num_rsp_handles < max_replies;) { + p_rec = sdp_db_service_search(p_rec, &uid_seq); + + if (p_rec) + rsp_handles[num_rsp_handles++] = p_rec->record_handle; else - { - rem_handles = num_rsp_handles; - cont_offset = 0; - p_ccb->cont_offset = 0; - } - - /* Calculate how many handles will fit in one PDU */ - cur_handles = (uint16_t)((p_ccb->rem_mtu_size - SDP_MAX_SERVICE_RSPHDR_LEN) / 4); - - if (rem_handles <= cur_handles) - cur_handles = rem_handles; - else /* Continuation is set */ - { - p_ccb->cont_offset += cur_handles; - is_cont = true; + break; + } + + /* Check if this is a continuation request */ + if (*p_req) { + if (*p_req++ != SDP_CONTINUATION_LEN || (p_req >= p_req_end)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_LEN); + return; } + BE_STREAM_TO_UINT16(cont_offset, p_req); - /* Get a buffer to use to build the response */ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_rsp = p_rsp_start = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - - /* Start building a rsponse */ - UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_SEARCH_RSP); - UINT16_TO_BE_STREAM (p_rsp, trans_num); - - /* Skip the length, we need to add it at the end */ - p_rsp_param_len = p_rsp; - p_rsp += 2; - - /* Put in total and current number of handles, and handles themselves */ - UINT16_TO_BE_STREAM (p_rsp, num_rsp_handles); - UINT16_TO_BE_STREAM (p_rsp, cur_handles); - -/* SDP_TRACE_DEBUG("SDP Service Rsp: tothdl %d, curhdlr %d, start %d, end %d, cont %d", - num_rsp_handles, cur_handles, cont_offset, - cont_offset + cur_handles-1, is_cont); */ - for (xx = cont_offset; xx < cont_offset + cur_handles; xx++) - UINT32_TO_BE_STREAM (p_rsp, rsp_handles[xx]); - - if (is_cont) - { - UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN); - UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset); + if (cont_offset != p_ccb->cont_offset) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_INX); + return; } - else - UINT8_TO_BE_STREAM (p_rsp, 0); - /* Go back and put the parameter length into the buffer */ - rsp_param_len = p_rsp - p_rsp_param_len - 2; - UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len); - - /* Set the length of the SDP data in the buffer */ - p_buf->len = p_rsp - p_rsp_start; - - - /* Send the buffer through L2CAP */ - L2CA_DataWrite (p_ccb->connection_id, p_buf); + rem_handles = + num_rsp_handles - cont_offset; /* extract the remaining handles */ + } else { + rem_handles = num_rsp_handles; + cont_offset = 0; + p_ccb->cont_offset = 0; + } + + /* Calculate how many handles will fit in one PDU */ + cur_handles = + (uint16_t)((p_ccb->rem_mtu_size - SDP_MAX_SERVICE_RSPHDR_LEN) / 4); + + if (rem_handles <= cur_handles) + cur_handles = rem_handles; + else /* Continuation is set */ + { + p_ccb->cont_offset += cur_handles; + is_cont = true; + } + + /* Get a buffer to use to build the response */ + BT_HDR* p_buf = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET; + p_rsp = p_rsp_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + + /* Start building a rsponse */ + UINT8_TO_BE_STREAM(p_rsp, SDP_PDU_SERVICE_SEARCH_RSP); + UINT16_TO_BE_STREAM(p_rsp, trans_num); + + /* Skip the length, we need to add it at the end */ + p_rsp_param_len = p_rsp; + p_rsp += 2; + + /* Put in total and current number of handles, and handles themselves */ + UINT16_TO_BE_STREAM(p_rsp, num_rsp_handles); + UINT16_TO_BE_STREAM(p_rsp, cur_handles); + + /* SDP_TRACE_DEBUG("SDP Service Rsp: tothdl %d, curhdlr %d, start %d, end %d, + cont %d", + num_rsp_handles, cur_handles, cont_offset, + cont_offset + cur_handles-1, is_cont); */ + for (xx = cont_offset; xx < cont_offset + cur_handles; xx++) + UINT32_TO_BE_STREAM(p_rsp, rsp_handles[xx]); + + if (is_cont) { + UINT8_TO_BE_STREAM(p_rsp, SDP_CONTINUATION_LEN); + UINT16_TO_BE_STREAM(p_rsp, p_ccb->cont_offset); + } else + UINT8_TO_BE_STREAM(p_rsp, 0); + + /* Go back and put the parameter length into the buffer */ + rsp_param_len = p_rsp - p_rsp_param_len - 2; + UINT16_TO_BE_STREAM(p_rsp_param_len, rsp_param_len); + + /* Set the length of the SDP data in the buffer */ + p_buf->len = p_rsp - p_rsp_start; + + /* Send the buffer through L2CAP */ + L2CA_DataWrite(p_ccb->connection_id, p_buf); } - /******************************************************************************* * * Function process_service_attr_req @@ -312,224 +296,210 @@ static void process_service_search (tCONN_CB *p_ccb, uint16_t trans_num, * Returns void * ******************************************************************************/ -static void process_service_attr_req (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - uint8_t *p_req_end) -{ - uint16_t max_list_len, len_to_send, cont_offset; - int16_t rem_len; - tSDP_ATTR_SEQ attr_seq, attr_seq_sav; - uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; - uint16_t rsp_param_len, xx; - uint32_t rec_handle; - tSDP_RECORD *p_rec; - tSDP_ATTRIBUTE *p_attr; - bool is_cont = false; - uint16_t attr_len; - - /* Extract the record handle */ - BE_STREAM_TO_UINT32 (rec_handle, p_req); - - if (p_req > p_req_end) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, SDP_TEXT_BAD_HANDLE); - return; - } - - /* Get the max list length we can send. Cap it at MTU size minus overhead */ - BE_STREAM_TO_UINT16 (max_list_len, p_req); - - if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN)) - max_list_len = p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN; - - p_req = sdpu_extract_attr_seq (p_req, param_len, &attr_seq); - - if ((!p_req) || (!attr_seq.num_attr) || (p_req > p_req_end)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_ATTR_LIST); - return; +static void process_service_attr_req(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + uint8_t* p_req_end) { + uint16_t max_list_len, len_to_send, cont_offset; + int16_t rem_len; + tSDP_ATTR_SEQ attr_seq, attr_seq_sav; + uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; + uint16_t rsp_param_len, xx; + uint32_t rec_handle; + tSDP_RECORD* p_rec; + tSDP_ATTRIBUTE* p_attr; + bool is_cont = false; + uint16_t attr_len; + + /* Extract the record handle */ + BE_STREAM_TO_UINT32(rec_handle, p_req); + + if (p_req > p_req_end) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, + SDP_TEXT_BAD_HANDLE); + return; + } + + /* Get the max list length we can send. Cap it at MTU size minus overhead */ + BE_STREAM_TO_UINT16(max_list_len, p_req); + + if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN)) + max_list_len = p_ccb->rem_mtu_size - SDP_MAX_ATTR_RSPHDR_LEN; + + p_req = sdpu_extract_attr_seq(p_req, param_len, &attr_seq); + + if ((!p_req) || (!attr_seq.num_attr) || (p_req > p_req_end)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_ATTR_LIST); + return; + } + + memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)); + + /* Find a record with the record handle */ + p_rec = sdp_db_find_record(rec_handle); + if (!p_rec) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, + SDP_TEXT_BAD_HANDLE); + return; + } + + /* Free and reallocate buffer */ + osi_free(p_ccb->rsp_list); + p_ccb->rsp_list = (uint8_t*)osi_malloc(max_list_len); + + /* Check if this is a continuation request */ + if (*p_req) { + if (*p_req++ != SDP_CONTINUATION_LEN) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_LEN); + return; } + BE_STREAM_TO_UINT16(cont_offset, p_req); - memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)) ; - - /* Find a record with the record handle */ - p_rec = sdp_db_find_record (rec_handle); - if (!p_rec) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_SERV_REC_HDL, SDP_TEXT_BAD_HANDLE); - return; + if (cont_offset != p_ccb->cont_offset) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_INX); + return; } - - /* Free and reallocate buffer */ - osi_free(p_ccb->rsp_list); - p_ccb->rsp_list = (uint8_t *)osi_malloc(max_list_len); - - /* Check if this is a continuation request */ - if (*p_req) { - if (*p_req++ != SDP_CONTINUATION_LEN) { - sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_LEN); - return; - } - BE_STREAM_TO_UINT16(cont_offset, p_req); - - if (cont_offset != p_ccb->cont_offset) { - sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_INX); - return; + is_cont = true; + + /* Initialise for continuation response */ + p_rsp = &p_ccb->rsp_list[0]; + attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = + p_ccb->cont_info.next_attr_start_id; + } else { + p_ccb->cont_offset = 0; + p_rsp = &p_ccb->rsp_list[3]; /* Leave space for data elem descr */ + + /* Reset continuation parameters in p_ccb */ + p_ccb->cont_info.prev_sdp_rec = NULL; + p_ccb->cont_info.next_attr_index = 0; + p_ccb->cont_info.attr_offset = 0; + } + + /* Search for attributes that match the list given to us */ + for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) { + p_attr = sdp_db_find_attr_in_rec(p_rec, attr_seq.attr_entry[xx].start, + attr_seq.attr_entry[xx].end); + + if (p_attr) { + /* Check if attribute fits. Assume 3-byte value type/length */ + rem_len = max_list_len - (int16_t)(p_rsp - &p_ccb->rsp_list[0]); + + /* just in case */ + if (rem_len <= 0) { + p_ccb->cont_info.next_attr_index = xx; + p_ccb->cont_info.next_attr_start_id = p_attr->id; + break; + } + + attr_len = sdpu_get_attrib_entry_len(p_attr); + /* if there is a partial attribute pending to be sent */ + if (p_ccb->cont_info.attr_offset) { + p_rsp = sdpu_build_partial_attrib_entry(p_rsp, p_attr, rem_len, + &p_ccb->cont_info.attr_offset); + + /* If the partial attrib could not been fully added yet */ + if (p_ccb->cont_info.attr_offset != attr_len) + break; + else /* If the partial attrib has been added in full by now */ + p_ccb->cont_info.attr_offset = 0; /* reset attr_offset */ + } else if (rem_len < + attr_len) /* Not enough space for attr... so add partially */ + { + if (attr_len >= SDP_MAX_ATTR_LEN) { + SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", + max_list_len, attr_len); + sdpu_build_n_send_error(p_ccb, trans_num, SDP_NO_RESOURCES, NULL); + return; } - is_cont = true; - /* Initialise for continuation response */ - p_rsp = &p_ccb->rsp_list[0]; - attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = - p_ccb->cont_info.next_attr_start_id; - } else { - p_ccb->cont_offset = 0; - p_rsp = &p_ccb->rsp_list[3]; /* Leave space for data elem descr */ + /* add the partial attribute if possible */ + p_rsp = sdpu_build_partial_attrib_entry( + p_rsp, p_attr, (uint16_t)rem_len, &p_ccb->cont_info.attr_offset); - /* Reset continuation parameters in p_ccb */ - p_ccb->cont_info.prev_sdp_rec = NULL; - p_ccb->cont_info.next_attr_index = 0; - p_ccb->cont_info.attr_offset = 0; - } + p_ccb->cont_info.next_attr_index = xx; + p_ccb->cont_info.next_attr_start_id = p_attr->id; + break; + } else /* build the whole attribute */ + p_rsp = sdpu_build_attrib_entry(p_rsp, p_attr); - /* Search for attributes that match the list given to us */ - for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) - { - p_attr = sdp_db_find_attr_in_rec (p_rec, attr_seq.attr_entry[xx].start, attr_seq.attr_entry[xx].end); + /* If doing a range, stick with this one till no more attributes found */ + if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) { + /* Update for next time through */ + attr_seq.attr_entry[xx].start = p_attr->id + 1; - if (p_attr) - { - /* Check if attribute fits. Assume 3-byte value type/length */ - rem_len = max_list_len - (int16_t) (p_rsp - &p_ccb->rsp_list[0]); - - /* just in case */ - if (rem_len <= 0) - { - p_ccb->cont_info.next_attr_index = xx; - p_ccb->cont_info.next_attr_start_id = p_attr->id; - break; - } - - attr_len = sdpu_get_attrib_entry_len(p_attr); - /* if there is a partial attribute pending to be sent */ - if (p_ccb->cont_info.attr_offset) - { - p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, rem_len, - &p_ccb->cont_info.attr_offset); - - /* If the partial attrib could not been fully added yet */ - if (p_ccb->cont_info.attr_offset != attr_len) - break; - else /* If the partial attrib has been added in full by now */ - p_ccb->cont_info.attr_offset = 0; /* reset attr_offset */ - } - else if (rem_len < attr_len) /* Not enough space for attr... so add partially */ - { - if (attr_len >= SDP_MAX_ATTR_LEN) - { - SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", max_list_len, attr_len); - sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL); - return; - } - - /* add the partial attribute if possible */ - p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, (uint16_t)rem_len, - &p_ccb->cont_info.attr_offset); - - p_ccb->cont_info.next_attr_index = xx; - p_ccb->cont_info.next_attr_start_id = p_attr->id; - break; - } - else /* build the whole attribute */ - p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr); - - /* If doing a range, stick with this one till no more attributes found */ - if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) - { - /* Update for next time through */ - attr_seq.attr_entry[xx].start = p_attr->id + 1; - - xx--; - } - } + xx--; + } } - /* If all the attributes have been accomodated in p_rsp, - reset next_attr_index */ - if (xx == attr_seq.num_attr) - p_ccb->cont_info.next_attr_index = 0; - - len_to_send = (uint16_t) (p_rsp - &p_ccb->rsp_list[0]); - cont_offset = 0; - - if (!is_cont) - { - p_ccb->list_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav) + 3; - /* Put in the sequence header (2 or 3 bytes) */ - if (p_ccb->list_len > 255) - { - p_ccb->rsp_list[0] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); - p_ccb->rsp_list[1] = (uint8_t) ((p_ccb->list_len - 3) >> 8); - p_ccb->rsp_list[2] = (uint8_t) (p_ccb->list_len - 3); - } - else - { - cont_offset = 1; + } + /* If all the attributes have been accomodated in p_rsp, + reset next_attr_index */ + if (xx == attr_seq.num_attr) p_ccb->cont_info.next_attr_index = 0; + + len_to_send = (uint16_t)(p_rsp - &p_ccb->rsp_list[0]); + cont_offset = 0; + + if (!is_cont) { + p_ccb->list_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav) + 3; + /* Put in the sequence header (2 or 3 bytes) */ + if (p_ccb->list_len > 255) { + p_ccb->rsp_list[0] = + (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); + p_ccb->rsp_list[1] = (uint8_t)((p_ccb->list_len - 3) >> 8); + p_ccb->rsp_list[2] = (uint8_t)(p_ccb->list_len - 3); + } else { + cont_offset = 1; - p_ccb->rsp_list[1] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - p_ccb->rsp_list[2] = (uint8_t) (p_ccb->list_len - 3); + p_ccb->rsp_list[1] = + (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + p_ccb->rsp_list[2] = (uint8_t)(p_ccb->list_len - 3); - p_ccb->list_len--; - len_to_send--; - } + p_ccb->list_len--; + len_to_send--; } + } - /* Get a buffer to use to build the response */ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_rsp = p_rsp_start = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + /* Get a buffer to use to build the response */ + BT_HDR* p_buf = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET; + p_rsp = p_rsp_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Start building a rsponse */ - UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_ATTR_RSP); - UINT16_TO_BE_STREAM (p_rsp, trans_num); + /* Start building a rsponse */ + UINT8_TO_BE_STREAM(p_rsp, SDP_PDU_SERVICE_ATTR_RSP); + UINT16_TO_BE_STREAM(p_rsp, trans_num); - /* Skip the parameter length, add it when we know the length */ - p_rsp_param_len = p_rsp; - p_rsp += 2; + /* Skip the parameter length, add it when we know the length */ + p_rsp_param_len = p_rsp; + p_rsp += 2; - UINT16_TO_BE_STREAM (p_rsp, len_to_send); + UINT16_TO_BE_STREAM(p_rsp, len_to_send); - memcpy (p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send); - p_rsp += len_to_send; + memcpy(p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send); + p_rsp += len_to_send; - p_ccb->cont_offset += len_to_send; + p_ccb->cont_offset += len_to_send; - /* If anything left to send, continuation needed */ - if (p_ccb->cont_offset < p_ccb->list_len) - { - is_cont = true; + /* If anything left to send, continuation needed */ + if (p_ccb->cont_offset < p_ccb->list_len) { + is_cont = true; - UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN); - UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset); - } - else - UINT8_TO_BE_STREAM (p_rsp, 0); + UINT8_TO_BE_STREAM(p_rsp, SDP_CONTINUATION_LEN); + UINT16_TO_BE_STREAM(p_rsp, p_ccb->cont_offset); + } else + UINT8_TO_BE_STREAM(p_rsp, 0); - /* Go back and put the parameter length into the buffer */ - rsp_param_len = p_rsp - p_rsp_param_len - 2; - UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len); + /* Go back and put the parameter length into the buffer */ + rsp_param_len = p_rsp - p_rsp_param_len - 2; + UINT16_TO_BE_STREAM(p_rsp_param_len, rsp_param_len); - /* Set the length of the SDP data in the buffer */ - p_buf->len = p_rsp - p_rsp_start; + /* Set the length of the SDP data in the buffer */ + p_buf->len = p_rsp - p_rsp_start; - - /* Send the buffer through L2CAP */ - L2CA_DataWrite (p_ccb->connection_id, p_buf); + /* Send the buffer through L2CAP */ + L2CA_DataWrite(p_ccb->connection_id, p_buf); } - - /******************************************************************************* * * Function process_service_search_attr_req @@ -542,294 +512,277 @@ static void process_service_attr_req (tCONN_CB *p_ccb, uint16_t trans_num, * Returns void * ******************************************************************************/ -static void process_service_search_attr_req (tCONN_CB *p_ccb, uint16_t trans_num, - uint16_t param_len, uint8_t *p_req, - UNUSED_ATTR uint8_t *p_req_end) -{ - uint16_t max_list_len; - int16_t rem_len; - uint16_t len_to_send, cont_offset; - tSDP_UUID_SEQ uid_seq; - uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; - uint16_t rsp_param_len, xx; - tSDP_RECORD *p_rec; - tSDP_ATTR_SEQ attr_seq, attr_seq_sav; - tSDP_ATTRIBUTE *p_attr; - bool maxxed_out = false, is_cont = false; - uint8_t *p_seq_start; - uint16_t seq_len, attr_len; - - /* Extract the UUID sequence to search for */ - p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq); - - if ((!p_req) || (!uid_seq.num_uids)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_UUID_LIST); - return; +static void process_service_search_attr_req(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t param_len, uint8_t* p_req, + UNUSED_ATTR uint8_t* p_req_end) { + uint16_t max_list_len; + int16_t rem_len; + uint16_t len_to_send, cont_offset; + tSDP_UUID_SEQ uid_seq; + uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; + uint16_t rsp_param_len, xx; + tSDP_RECORD* p_rec; + tSDP_ATTR_SEQ attr_seq, attr_seq_sav; + tSDP_ATTRIBUTE* p_attr; + bool maxxed_out = false, is_cont = false; + uint8_t* p_seq_start; + uint16_t seq_len, attr_len; + + /* Extract the UUID sequence to search for */ + p_req = sdpu_extract_uid_seq(p_req, param_len, &uid_seq); + + if ((!p_req) || (!uid_seq.num_uids)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_UUID_LIST); + return; + } + + /* Get the max list length we can send. Cap it at our max list length. */ + BE_STREAM_TO_UINT16(max_list_len, p_req); + + if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN)) + max_list_len = p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN; + + p_req = sdpu_extract_attr_seq(p_req, param_len, &attr_seq); + + if ((!p_req) || (!attr_seq.num_attr)) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, + SDP_TEXT_BAD_ATTR_LIST); + return; + } + + memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)); + + /* Free and reallocate buffer */ + osi_free(p_ccb->rsp_list); + p_ccb->rsp_list = (uint8_t*)osi_malloc(max_list_len); + + /* Check if this is a continuation request */ + if (*p_req) { + if (*p_req++ != SDP_CONTINUATION_LEN) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_LEN); + return; } + BE_STREAM_TO_UINT16(cont_offset, p_req); - /* Get the max list length we can send. Cap it at our max list length. */ - BE_STREAM_TO_UINT16 (max_list_len, p_req); - - if (max_list_len > (p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN)) - max_list_len = p_ccb->rem_mtu_size - SDP_MAX_SERVATTR_RSPHDR_LEN; - - p_req = sdpu_extract_attr_seq (p_req, param_len, &attr_seq); - - if ((!p_req) || (!attr_seq.num_attr)) - { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_ATTR_LIST); - return; + if (cont_offset != p_ccb->cont_offset) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, + SDP_TEXT_BAD_CONT_INX); + return; } - - memcpy(&attr_seq_sav, &attr_seq, sizeof(tSDP_ATTR_SEQ)) ; - - /* Free and reallocate buffer */ - osi_free(p_ccb->rsp_list); - p_ccb->rsp_list = (uint8_t *)osi_malloc(max_list_len); - - /* Check if this is a continuation request */ - if (*p_req) { - if (*p_req++ != SDP_CONTINUATION_LEN) { - sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_LEN); - return; - } - BE_STREAM_TO_UINT16(cont_offset, p_req); - - if (cont_offset != p_ccb->cont_offset) { - sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_CONT_STATE, - SDP_TEXT_BAD_CONT_INX); - return; - } - is_cont = true; - - /* Initialise for continuation response */ - p_rsp = &p_ccb->rsp_list[0]; - attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = - p_ccb->cont_info.next_attr_start_id; - } else { - p_ccb->cont_offset = 0; - p_rsp = &p_ccb->rsp_list[3]; /* Leave space for data elem descr */ - - /* Reset continuation parameters in p_ccb */ - p_ccb->cont_info.prev_sdp_rec = NULL; + is_cont = true; + + /* Initialise for continuation response */ + p_rsp = &p_ccb->rsp_list[0]; + attr_seq.attr_entry[p_ccb->cont_info.next_attr_index].start = + p_ccb->cont_info.next_attr_start_id; + } else { + p_ccb->cont_offset = 0; + p_rsp = &p_ccb->rsp_list[3]; /* Leave space for data elem descr */ + + /* Reset continuation parameters in p_ccb */ + p_ccb->cont_info.prev_sdp_rec = NULL; + p_ccb->cont_info.next_attr_index = 0; + p_ccb->cont_info.last_attr_seq_desc_sent = false; + p_ccb->cont_info.attr_offset = 0; + } + + /* Get a list of handles that match the UUIDs given to us */ + for (p_rec = sdp_db_service_search(p_ccb->cont_info.prev_sdp_rec, &uid_seq); + p_rec; p_rec = sdp_db_service_search(p_rec, &uid_seq)) { + /* Allow space for attribute sequence type and length */ + p_seq_start = p_rsp; + if (p_ccb->cont_info.last_attr_seq_desc_sent == false) { + /* See if there is enough room to include a new service in the current + * response */ + rem_len = max_list_len - (int16_t)(p_rsp - &p_ccb->rsp_list[0]); + if (rem_len < 3) { + /* Not enough room. Update continuation info for next response */ p_ccb->cont_info.next_attr_index = 0; - p_ccb->cont_info.last_attr_seq_desc_sent = false; - p_ccb->cont_info.attr_offset = 0; + p_ccb->cont_info.next_attr_start_id = attr_seq.attr_entry[0].start; + break; + } + p_rsp += 3; } /* Get a list of handles that match the UUIDs given to us */ - for (p_rec = sdp_db_service_search (p_ccb->cont_info.prev_sdp_rec, &uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, &uid_seq)) - { - /* Allow space for attribute sequence type and length */ - p_seq_start = p_rsp; - if (p_ccb->cont_info.last_attr_seq_desc_sent == false) - { - /* See if there is enough room to include a new service in the current response */ - rem_len = max_list_len - (int16_t) (p_rsp - &p_ccb->rsp_list[0]); - if (rem_len < 3) - { - /* Not enough room. Update continuation info for next response */ - p_ccb->cont_info.next_attr_index = 0; - p_ccb->cont_info.next_attr_start_id = attr_seq.attr_entry[0].start; - break; - } - p_rsp += 3; + for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) { + p_attr = sdp_db_find_attr_in_rec(p_rec, attr_seq.attr_entry[xx].start, + attr_seq.attr_entry[xx].end); + + if (p_attr) { + /* Check if attribute fits. Assume 3-byte value type/length */ + rem_len = max_list_len - (int16_t)(p_rsp - &p_ccb->rsp_list[0]); + + /* just in case */ + if (rem_len <= 0) { + p_ccb->cont_info.next_attr_index = xx; + p_ccb->cont_info.next_attr_start_id = p_attr->id; + maxxed_out = true; + break; } - /* Get a list of handles that match the UUIDs given to us */ - for (xx = p_ccb->cont_info.next_attr_index; xx < attr_seq.num_attr; xx++) - { - p_attr = sdp_db_find_attr_in_rec (p_rec, attr_seq.attr_entry[xx].start, attr_seq.attr_entry[xx].end); - - if (p_attr) - { - /* Check if attribute fits. Assume 3-byte value type/length */ - rem_len = max_list_len - (int16_t) (p_rsp - &p_ccb->rsp_list[0]); - - /* just in case */ - if (rem_len <= 0) - { - p_ccb->cont_info.next_attr_index = xx; - p_ccb->cont_info.next_attr_start_id = p_attr->id; - maxxed_out = true; - break; - } - - attr_len = sdpu_get_attrib_entry_len(p_attr); - /* if there is a partial attribute pending to be sent */ - if (p_ccb->cont_info.attr_offset) - { - p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, rem_len, - &p_ccb->cont_info.attr_offset); - - /* If the partial attrib could not been fully added yet */ - if (p_ccb->cont_info.attr_offset != attr_len) - { - maxxed_out = true; - break; - } - else /* If the partial attrib has been added in full by now */ - p_ccb->cont_info.attr_offset = 0; /* reset attr_offset */ - } - else if (rem_len < attr_len) /* Not enough space for attr... so add partially */ - { - if (attr_len >= SDP_MAX_ATTR_LEN) - { - SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", max_list_len, attr_len); - sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL); - return; - } - - /* add the partial attribute if possible */ - p_rsp = sdpu_build_partial_attrib_entry (p_rsp, p_attr, (uint16_t)rem_len, - &p_ccb->cont_info.attr_offset); - - p_ccb->cont_info.next_attr_index = xx; - p_ccb->cont_info.next_attr_start_id = p_attr->id; - maxxed_out = true; - break; - } - else /* build the whole attribute */ - p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr); - - /* If doing a range, stick with this one till no more attributes found */ - if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) - { - /* Update for next time through */ - attr_seq.attr_entry[xx].start = p_attr->id + 1; - - xx--; - } - } - } + attr_len = sdpu_get_attrib_entry_len(p_attr); + /* if there is a partial attribute pending to be sent */ + if (p_ccb->cont_info.attr_offset) { + p_rsp = sdpu_build_partial_attrib_entry( + p_rsp, p_attr, rem_len, &p_ccb->cont_info.attr_offset); - /* Go back and put the type and length into the buffer */ - if (p_ccb->cont_info.last_attr_seq_desc_sent == false) + /* If the partial attrib could not been fully added yet */ + if (p_ccb->cont_info.attr_offset != attr_len) { + maxxed_out = true; + break; + } else /* If the partial attrib has been added in full by now */ + p_ccb->cont_info.attr_offset = 0; /* reset attr_offset */ + } else if (rem_len < + attr_len) /* Not enough space for attr... so add partially */ { - seq_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav); - if (seq_len != 0) - { - UINT8_TO_BE_STREAM (p_seq_start, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); - UINT16_TO_BE_STREAM (p_seq_start, seq_len); - - if (maxxed_out) - p_ccb->cont_info.last_attr_seq_desc_sent = true; - } - else - p_rsp = p_seq_start; + if (attr_len >= SDP_MAX_ATTR_LEN) { + SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", + max_list_len, attr_len); + sdpu_build_n_send_error(p_ccb, trans_num, SDP_NO_RESOURCES, NULL); + return; + } + + /* add the partial attribute if possible */ + p_rsp = sdpu_build_partial_attrib_entry( + p_rsp, p_attr, (uint16_t)rem_len, &p_ccb->cont_info.attr_offset); + + p_ccb->cont_info.next_attr_index = xx; + p_ccb->cont_info.next_attr_start_id = p_attr->id; + maxxed_out = true; + break; + } else /* build the whole attribute */ + p_rsp = sdpu_build_attrib_entry(p_rsp, p_attr); + + /* If doing a range, stick with this one till no more attributes found + */ + if (attr_seq.attr_entry[xx].start != attr_seq.attr_entry[xx].end) { + /* Update for next time through */ + attr_seq.attr_entry[xx].start = p_attr->id + 1; + + xx--; } - - if (maxxed_out) - break; - - /* Restore the attr_seq to look for in the next sdp record */ - memcpy(&attr_seq, &attr_seq_sav, sizeof(tSDP_ATTR_SEQ)) ; - - /* Reset the next attr index */ - p_ccb->cont_info.next_attr_index = 0; - p_ccb->cont_info.prev_sdp_rec = p_rec; - p_ccb->cont_info.last_attr_seq_desc_sent = false; + } } - /* response length */ - len_to_send = (uint16_t) (p_rsp - &p_ccb->rsp_list[0]); - cont_offset = 0; - - // The current SDP server design has a critical flaw where it can run into - // an infinite request/response loop with the client. Here's the scenario: - // - client makes SDP request - // - server returns the first fragment of the response with a continuation - // token - // - an SDP record is deleted from the server - // - client issues another request with previous continuation token - // - server has nothing to send back because the record is unavailable but - // in the first fragment, it had specified more response bytes than are - // now available - // - server sends back no additional response bytes and returns the same - // continuation token - // - client issues another request with the continuation token, and the - // process repeats - // - // We work around this design flaw here by checking if we will make forward - // progress (i.e. we will send > 0 response bytes) on a continued request. - // If not, we must have run into the above situation and we tell the peer an - // error occurred. - // - // TODO(sharvil): rewrite SDP server. - if (is_cont && len_to_send == 0) { - sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, NULL); - return; + /* Go back and put the type and length into the buffer */ + if (p_ccb->cont_info.last_attr_seq_desc_sent == false) { + seq_len = sdpu_get_attrib_seq_len(p_rec, &attr_seq_sav); + if (seq_len != 0) { + UINT8_TO_BE_STREAM(p_seq_start, + (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); + UINT16_TO_BE_STREAM(p_seq_start, seq_len); + + if (maxxed_out) p_ccb->cont_info.last_attr_seq_desc_sent = true; + } else + p_rsp = p_seq_start; } - /* If first response, insert sequence header */ - if (!is_cont) - { - /* Get the total list length for requested uid and attribute sequence */ - p_ccb->list_len = sdpu_get_list_len(&uid_seq, &attr_seq_sav) + 3; - /* Put in the sequence header (2 or 3 bytes) */ - if (p_ccb->list_len > 255) - { - p_ccb->rsp_list[0] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); - p_ccb->rsp_list[1] = (uint8_t) ((p_ccb->list_len - 3) >> 8); - p_ccb->rsp_list[2] = (uint8_t) (p_ccb->list_len - 3); - } - else - { - cont_offset = 1; + if (maxxed_out) break; + + /* Restore the attr_seq to look for in the next sdp record */ + memcpy(&attr_seq, &attr_seq_sav, sizeof(tSDP_ATTR_SEQ)); + + /* Reset the next attr index */ + p_ccb->cont_info.next_attr_index = 0; + p_ccb->cont_info.prev_sdp_rec = p_rec; + p_ccb->cont_info.last_attr_seq_desc_sent = false; + } + + /* response length */ + len_to_send = (uint16_t)(p_rsp - &p_ccb->rsp_list[0]); + cont_offset = 0; + + // The current SDP server design has a critical flaw where it can run into + // an infinite request/response loop with the client. Here's the scenario: + // - client makes SDP request + // - server returns the first fragment of the response with a continuation + // token + // - an SDP record is deleted from the server + // - client issues another request with previous continuation token + // - server has nothing to send back because the record is unavailable but + // in the first fragment, it had specified more response bytes than are + // now available + // - server sends back no additional response bytes and returns the same + // continuation token + // - client issues another request with the continuation token, and the + // process repeats + // + // We work around this design flaw here by checking if we will make forward + // progress (i.e. we will send > 0 response bytes) on a continued request. + // If not, we must have run into the above situation and we tell the peer an + // error occurred. + // + // TODO(sharvil): rewrite SDP server. + if (is_cont && len_to_send == 0) { + sdpu_build_n_send_error(p_ccb, trans_num, SDP_INVALID_CONT_STATE, NULL); + return; + } + + /* If first response, insert sequence header */ + if (!is_cont) { + /* Get the total list length for requested uid and attribute sequence */ + p_ccb->list_len = sdpu_get_list_len(&uid_seq, &attr_seq_sav) + 3; + /* Put in the sequence header (2 or 3 bytes) */ + if (p_ccb->list_len > 255) { + p_ccb->rsp_list[0] = + (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); + p_ccb->rsp_list[1] = (uint8_t)((p_ccb->list_len - 3) >> 8); + p_ccb->rsp_list[2] = (uint8_t)(p_ccb->list_len - 3); + } else { + cont_offset = 1; - p_ccb->rsp_list[1] = (uint8_t) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - p_ccb->rsp_list[2] = (uint8_t) (p_ccb->list_len - 3); + p_ccb->rsp_list[1] = + (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + p_ccb->rsp_list[2] = (uint8_t)(p_ccb->list_len - 3); - p_ccb->list_len--; - len_to_send--; - } + p_ccb->list_len--; + len_to_send--; } + } - /* Get a buffer to use to build the response */ - BT_HDR *p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); - p_buf->offset = L2CAP_MIN_OFFSET; - p_rsp = p_rsp_start = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + /* Get a buffer to use to build the response */ + BT_HDR* p_buf = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + p_buf->offset = L2CAP_MIN_OFFSET; + p_rsp = p_rsp_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Start building a rsponse */ - UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_SERVICE_SEARCH_ATTR_RSP); - UINT16_TO_BE_STREAM (p_rsp, trans_num); + /* Start building a rsponse */ + UINT8_TO_BE_STREAM(p_rsp, SDP_PDU_SERVICE_SEARCH_ATTR_RSP); + UINT16_TO_BE_STREAM(p_rsp, trans_num); - /* Skip the parameter length, add it when we know the length */ - p_rsp_param_len = p_rsp; - p_rsp += 2; + /* Skip the parameter length, add it when we know the length */ + p_rsp_param_len = p_rsp; + p_rsp += 2; - /* Stream the list length to send */ - UINT16_TO_BE_STREAM (p_rsp, len_to_send); + /* Stream the list length to send */ + UINT16_TO_BE_STREAM(p_rsp, len_to_send); - /* copy from rsp_list to the actual buffer to be sent */ - memcpy (p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send); - p_rsp += len_to_send; + /* copy from rsp_list to the actual buffer to be sent */ + memcpy(p_rsp, &p_ccb->rsp_list[cont_offset], len_to_send); + p_rsp += len_to_send; - p_ccb->cont_offset += len_to_send; + p_ccb->cont_offset += len_to_send; - /* If anything left to send, continuation needed */ - if (p_ccb->cont_offset < p_ccb->list_len) - { - is_cont = true; - - UINT8_TO_BE_STREAM (p_rsp, SDP_CONTINUATION_LEN); - UINT16_TO_BE_STREAM (p_rsp, p_ccb->cont_offset); - } - else - UINT8_TO_BE_STREAM (p_rsp, 0); + /* If anything left to send, continuation needed */ + if (p_ccb->cont_offset < p_ccb->list_len) { + is_cont = true; - /* Go back and put the parameter length into the buffer */ - rsp_param_len = p_rsp - p_rsp_param_len - 2; - UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len); + UINT8_TO_BE_STREAM(p_rsp, SDP_CONTINUATION_LEN); + UINT16_TO_BE_STREAM(p_rsp, p_ccb->cont_offset); + } else + UINT8_TO_BE_STREAM(p_rsp, 0); - /* Set the length of the SDP data in the buffer */ - p_buf->len = p_rsp - p_rsp_start; + /* Go back and put the parameter length into the buffer */ + rsp_param_len = p_rsp - p_rsp_param_len - 2; + UINT16_TO_BE_STREAM(p_rsp_param_len, rsp_param_len); + /* Set the length of the SDP data in the buffer */ + p_buf->len = p_rsp - p_rsp_start; - /* Send the buffer through L2CAP */ - L2CA_DataWrite (p_ccb->connection_id, p_buf); + /* Send the buffer through L2CAP */ + L2CA_DataWrite(p_ccb->connection_id, p_buf); } -#endif /* SDP_SERVER_ENABLED == TRUE */ +#endif /* SDP_SERVER_ENABLED == TRUE */ diff --git a/stack/sdp/sdp_utils.cc b/stack/sdp/sdp_utils.cc index c92bd496f..7e490d3d2 100644 --- a/stack/sdp/sdp_utils.cc +++ b/stack/sdp/sdp_utils.cc @@ -22,26 +22,26 @@ * ******************************************************************************/ -#include -#include #include #include +#include +#include #include "bt_common.h" #include "bt_types.h" -#include "l2cdefs.h" #include "hcidefs.h" #include "hcimsgs.h" +#include "l2cdefs.h" #include "sdp_api.h" #include "sdpint.h" #include "btu.h" - -static const uint8_t sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}; +static const uint8_t sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, + 0x5F, 0x9B, 0x34, 0xFB}; /******************************************************************************* * @@ -53,23 +53,20 @@ static const uint8_t sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 * Returns the CCB address, or NULL if not found. * ******************************************************************************/ -tCONN_CB *sdpu_find_ccb_by_cid (uint16_t cid) -{ - uint16_t xx; - tCONN_CB *p_ccb; - - /* Look through each connection control block */ - for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->connection_id == cid)) - return (p_ccb); - } - - /* If here, not found */ - return (NULL); +tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid) { + uint16_t xx; + tCONN_CB* p_ccb; + + /* Look through each connection control block */ + for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) { + if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->connection_id == cid)) + return (p_ccb); + } + + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function sdpu_find_ccb_by_db @@ -80,27 +77,23 @@ tCONN_CB *sdpu_find_ccb_by_cid (uint16_t cid) * Returns the CCB address, or NULL if not found. * ******************************************************************************/ -tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db) -{ +tCONN_CB* sdpu_find_ccb_by_db(tSDP_DISCOVERY_DB* p_db) { #if (SDP_CLIENT_ENABLED == TRUE) - uint16_t xx; - tCONN_CB *p_ccb; - - if (p_db) - { - /* Look through each connection control block */ - for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->p_db == p_db)) - return (p_ccb); - } + uint16_t xx; + tCONN_CB* p_ccb; + + if (p_db) { + /* Look through each connection control block */ + for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) { + if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->p_db == p_db)) + return (p_ccb); } + } #endif - /* If here, not found */ - return (NULL); + /* If here, not found */ + return (NULL); } - /******************************************************************************* * * Function sdpu_allocate_ccb @@ -110,27 +103,23 @@ tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db) * Returns CCB address, or NULL if none available. * ******************************************************************************/ -tCONN_CB *sdpu_allocate_ccb (void) -{ - uint16_t xx; - tCONN_CB *p_ccb; - - /* Look through each connection control block for a free one */ - for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) - { - if (p_ccb->con_state == SDP_STATE_IDLE) - { - memset(p_ccb, 0, sizeof(tCONN_CB)); - p_ccb->sdp_conn_timer = alarm_new("sdp.sdp_conn_timer"); - return (p_ccb); - } +tCONN_CB* sdpu_allocate_ccb(void) { + uint16_t xx; + tCONN_CB* p_ccb; + + /* Look through each connection control block for a free one */ + for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) { + if (p_ccb->con_state == SDP_STATE_IDLE) { + memset(p_ccb, 0, sizeof(tCONN_CB)); + p_ccb->sdp_conn_timer = alarm_new("sdp.sdp_conn_timer"); + return (p_ccb); } + } - /* If here, no free CCB found */ - return (NULL); + /* If here, no free CCB found */ + return (NULL); } - /******************************************************************************* * * Function sdpu_release_ccb @@ -140,25 +129,22 @@ tCONN_CB *sdpu_allocate_ccb (void) * Returns void * ******************************************************************************/ -void sdpu_release_ccb (tCONN_CB *p_ccb) -{ - /* Ensure timer is stopped */ - alarm_free(p_ccb->sdp_conn_timer); - p_ccb->sdp_conn_timer = NULL; - - /* Drop any response pointer we may be holding */ - p_ccb->con_state = SDP_STATE_IDLE; +void sdpu_release_ccb(tCONN_CB* p_ccb) { + /* Ensure timer is stopped */ + alarm_free(p_ccb->sdp_conn_timer); + p_ccb->sdp_conn_timer = NULL; + + /* Drop any response pointer we may be holding */ + p_ccb->con_state = SDP_STATE_IDLE; #if (SDP_CLIENT_ENABLED == TRUE) - p_ccb->is_attr_search = false; + p_ccb->is_attr_search = false; #endif - /* Free the response buffer */ - if (p_ccb->rsp_list) - SDP_TRACE_DEBUG("releasing SDP rsp_list"); - osi_free_and_reset((void **)&p_ccb->rsp_list); + /* Free the response buffer */ + if (p_ccb->rsp_list) SDP_TRACE_DEBUG("releasing SDP rsp_list"); + osi_free_and_reset((void**)&p_ccb->rsp_list); } - /******************************************************************************* * * Function sdpu_build_attrib_seq @@ -170,49 +156,43 @@ void sdpu_release_ccb (tCONN_CB *p_ccb) * Returns Pointer to next byte in the output buffer. * ******************************************************************************/ -uint8_t *sdpu_build_attrib_seq (uint8_t *p_out, uint16_t *p_attr, uint16_t num_attrs) -{ - uint16_t xx; - - /* First thing is the data element header. See if the length fits 1 byte */ - /* If no attributes, assume a 4-byte wildcard */ - if (!p_attr) - xx = 5; - else - xx = num_attrs * 3; - - if (xx > 255) - { - UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); - UINT16_TO_BE_STREAM (p_out, xx); - } - else - { - UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); - UINT8_TO_BE_STREAM (p_out, xx); - } - - /* If there are no attributes specified, assume caller wants wildcard */ - if (!p_attr) - { - UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_FOUR_BYTES); - UINT16_TO_BE_STREAM (p_out, 0); - UINT16_TO_BE_STREAM (p_out, 0xFFFF); - } - else - { - /* Loop through and put in all the attributes(s) */ - for (xx = 0; xx < num_attrs; xx++, p_attr++) - { - UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p_out, *p_attr); - } +uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr, + uint16_t num_attrs) { + uint16_t xx; + + /* First thing is the data element header. See if the length fits 1 byte */ + /* If no attributes, assume a 4-byte wildcard */ + if (!p_attr) + xx = 5; + else + xx = num_attrs * 3; + + if (xx > 255) { + UINT8_TO_BE_STREAM(p_out, + (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD); + UINT16_TO_BE_STREAM(p_out, xx); + } else { + UINT8_TO_BE_STREAM(p_out, + (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE); + UINT8_TO_BE_STREAM(p_out, xx); + } + + /* If there are no attributes specified, assume caller wants wildcard */ + if (!p_attr) { + UINT8_TO_BE_STREAM(p_out, (UINT_DESC_TYPE << 3) | SIZE_FOUR_BYTES); + UINT16_TO_BE_STREAM(p_out, 0); + UINT16_TO_BE_STREAM(p_out, 0xFFFF); + } else { + /* Loop through and put in all the attributes(s) */ + for (xx = 0; xx < num_attrs; xx++, p_attr++) { + UINT8_TO_BE_STREAM(p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p_out, *p_attr); } + } - return (p_out); + return (p_out); } - /******************************************************************************* * * Function sdpu_build_attrib_entry @@ -224,82 +204,72 @@ uint8_t *sdpu_build_attrib_seq (uint8_t *p_out, uint16_t *p_attr, uint16_t num_a * Returns Pointer to next byte in the output buffer. * ******************************************************************************/ -uint8_t *sdpu_build_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr) -{ - /* First, store the attribute ID. Goes as a UINT */ - UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); - UINT16_TO_BE_STREAM (p_out, p_attr->id); - - /* the attribute is in the db record. - * assuming the attribute len is less than SDP_MAX_ATTR_LEN */ - switch(p_attr->type) - { - case TEXT_STR_DESC_TYPE: /* 4 */ - case DATA_ELE_SEQ_DESC_TYPE:/* 6 */ - case DATA_ELE_ALT_DESC_TYPE:/* 7 */ - case URL_DESC_TYPE: /* 8 */ +uint8_t* sdpu_build_attrib_entry(uint8_t* p_out, tSDP_ATTRIBUTE* p_attr) { + /* First, store the attribute ID. Goes as a UINT */ + UINT8_TO_BE_STREAM(p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES); + UINT16_TO_BE_STREAM(p_out, p_attr->id); + + /* the attribute is in the db record. + * assuming the attribute len is less than SDP_MAX_ATTR_LEN */ + switch (p_attr->type) { + case TEXT_STR_DESC_TYPE: /* 4 */ + case DATA_ELE_SEQ_DESC_TYPE: /* 6 */ + case DATA_ELE_ALT_DESC_TYPE: /* 7 */ + case URL_DESC_TYPE: /* 8 */ #if (SDP_MAX_ATTR_LEN > 0xFFFF) - if(p_attr->len > 0xFFFF) - { - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_LONG); - UINT32_TO_BE_STREAM (p_out, p_attr->len); - } - else - + if (p_attr->len > 0xFFFF) { + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_IN_NEXT_LONG); + UINT32_TO_BE_STREAM(p_out, p_attr->len); + } else #endif /* 0xFFFF - 0xFF */ #if (SDP_MAX_ATTR_LEN > 0xFF) - if(p_attr->len > 0xFF) - { - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_WORD); - UINT16_TO_BE_STREAM (p_out, p_attr->len); - } - else - + if (p_attr->len > 0xFF) { + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_IN_NEXT_WORD); + UINT16_TO_BE_STREAM(p_out, p_attr->len); + } else #endif /* 0xFF and less*/ - { - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE); - UINT8_TO_BE_STREAM (p_out, p_attr->len); - } + { + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE); + UINT8_TO_BE_STREAM(p_out, p_attr->len); + } - if (p_attr->value_ptr != NULL) { - ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len); - } + if (p_attr->value_ptr != NULL) { + ARRAY_TO_BE_STREAM(p_out, p_attr->value_ptr, (int)p_attr->len); + } - return (p_out); - } + return (p_out); + } - /* Now, store the attribute value */ - switch (p_attr->len) - { + /* Now, store the attribute value */ + switch (p_attr->len) { case 1: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_ONE_BYTE); - break; + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_ONE_BYTE); + break; case 2: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_TWO_BYTES); - break; + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_TWO_BYTES); + break; case 4: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_FOUR_BYTES); - break; + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_FOUR_BYTES); + break; case 8: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_EIGHT_BYTES); - break; + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_EIGHT_BYTES); + break; case 16: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_SIXTEEN_BYTES); - break; + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_SIXTEEN_BYTES); + break; default: - UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE); - UINT8_TO_BE_STREAM (p_out, p_attr->len); - break; - } + UINT8_TO_BE_STREAM(p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE); + UINT8_TO_BE_STREAM(p_out, p_attr->len); + break; + } - if (p_attr->value_ptr != NULL) { - ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len); - } + if (p_attr->value_ptr != NULL) { + ARRAY_TO_BE_STREAM(p_out, p_attr->value_ptr, (int)p_attr->len); + } - return (p_out); + return (p_out); } - /******************************************************************************* * * Function sdpu_build_n_send_error @@ -309,46 +279,43 @@ uint8_t *sdpu_build_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr) * Returns void * ******************************************************************************/ -void sdpu_build_n_send_error (tCONN_CB *p_ccb, uint16_t trans_num, uint16_t error_code, char *p_error_text) -{ - uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; - uint16_t rsp_param_len; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE); +void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t error_code, char* p_error_text) { + uint8_t *p_rsp, *p_rsp_start, *p_rsp_param_len; + uint16_t rsp_param_len; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(SDP_DATA_BUF_SIZE); + SDP_TRACE_WARNING("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x", + error_code, p_ccb->connection_id); - SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x", - error_code, p_ccb->connection_id); + /* Send the packet to L2CAP */ + p_buf->offset = L2CAP_MIN_OFFSET; + p_rsp = p_rsp_start = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - /* Send the packet to L2CAP */ - p_buf->offset = L2CAP_MIN_OFFSET; - p_rsp = p_rsp_start = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_BE_STREAM(p_rsp, SDP_PDU_ERROR_RESPONSE); + UINT16_TO_BE_STREAM(p_rsp, trans_num); - UINT8_TO_BE_STREAM(p_rsp, SDP_PDU_ERROR_RESPONSE); - UINT16_TO_BE_STREAM(p_rsp, trans_num); + /* Skip the parameter length, we need to add it at the end */ + p_rsp_param_len = p_rsp; + p_rsp += 2; - /* Skip the parameter length, we need to add it at the end */ - p_rsp_param_len = p_rsp; - p_rsp += 2; + UINT16_TO_BE_STREAM(p_rsp, error_code); - UINT16_TO_BE_STREAM (p_rsp, error_code); + /* Unplugfest example traces do not have any error text */ + if (p_error_text) + ARRAY_TO_BE_STREAM(p_rsp, p_error_text, (int)strlen(p_error_text)); - /* Unplugfest example traces do not have any error text */ - if (p_error_text) - ARRAY_TO_BE_STREAM(p_rsp, p_error_text, (int)strlen(p_error_text)); + /* Go back and put the parameter length into the buffer */ + rsp_param_len = p_rsp - p_rsp_param_len - 2; + UINT16_TO_BE_STREAM(p_rsp_param_len, rsp_param_len); - /* Go back and put the parameter length into the buffer */ - rsp_param_len = p_rsp - p_rsp_param_len - 2; - UINT16_TO_BE_STREAM(p_rsp_param_len, rsp_param_len); + /* Set the length of the SDP data in the buffer */ + p_buf->len = p_rsp - p_rsp_start; - /* Set the length of the SDP data in the buffer */ - p_buf->len = p_rsp - p_rsp_start; - - /* Send the buffer through L2CAP */ - L2CA_DataWrite(p_ccb->connection_id, p_buf); + /* Send the buffer through L2CAP */ + L2CA_DataWrite(p_ccb->connection_id, p_buf); } - - /******************************************************************************* * * Function sdpu_extract_uid_seq @@ -359,110 +326,99 @@ void sdpu_build_n_send_error (tCONN_CB *p_ccb, uint16_t trans_num, uint16_t erro * Returns Pointer to next byte in the input buffer after the sequence. * ******************************************************************************/ -uint8_t *sdpu_extract_uid_seq (uint8_t *p, uint16_t param_len, tSDP_UUID_SEQ *p_seq) -{ - uint8_t *p_seq_end; - uint8_t descr, type, size; - uint32_t seq_len, uuid_len; +uint8_t* sdpu_extract_uid_seq(uint8_t* p, uint16_t param_len, + tSDP_UUID_SEQ* p_seq) { + uint8_t* p_seq_end; + uint8_t descr, type, size; + uint32_t seq_len, uuid_len; + + /* Assume none found */ + p_seq->num_uids = 0; - /* Assume none found */ - p_seq->num_uids = 0; + /* A UID sequence is composed of a bunch of UIDs. */ - /* A UID sequence is composed of a bunch of UIDs. */ + BE_STREAM_TO_UINT8(descr, p); + type = descr >> 3; + size = descr & 7; - BE_STREAM_TO_UINT8 (descr, p); + if (type != DATA_ELE_SEQ_DESC_TYPE) return (NULL); + + switch (size) { + case SIZE_TWO_BYTES: + seq_len = 2; + break; + case SIZE_FOUR_BYTES: + seq_len = 4; + break; + case SIZE_SIXTEEN_BYTES: + seq_len = 16; + break; + case SIZE_IN_NEXT_BYTE: + BE_STREAM_TO_UINT8(seq_len, p); + break; + case SIZE_IN_NEXT_WORD: + BE_STREAM_TO_UINT16(seq_len, p); + break; + case SIZE_IN_NEXT_LONG: + BE_STREAM_TO_UINT32(seq_len, p); + break; + default: + return (NULL); + } + + if (seq_len >= param_len) return (NULL); + + p_seq_end = p + seq_len; + + /* Loop through, extracting the UIDs */ + for (; p < p_seq_end;) { + BE_STREAM_TO_UINT8(descr, p); type = descr >> 3; size = descr & 7; - if (type != DATA_ELE_SEQ_DESC_TYPE) - return (NULL); + if (type != UUID_DESC_TYPE) return (NULL); - switch (size) - { - case SIZE_TWO_BYTES: - seq_len = 2; + switch (size) { + case SIZE_TWO_BYTES: + uuid_len = 2; break; - case SIZE_FOUR_BYTES: - seq_len = 4; + case SIZE_FOUR_BYTES: + uuid_len = 4; break; - case SIZE_SIXTEEN_BYTES: - seq_len = 16; + case SIZE_SIXTEEN_BYTES: + uuid_len = 16; break; - case SIZE_IN_NEXT_BYTE: - BE_STREAM_TO_UINT8 (seq_len, p); + case SIZE_IN_NEXT_BYTE: + BE_STREAM_TO_UINT8(uuid_len, p); break; - case SIZE_IN_NEXT_WORD: - BE_STREAM_TO_UINT16 (seq_len, p); + case SIZE_IN_NEXT_WORD: + BE_STREAM_TO_UINT16(uuid_len, p); break; - case SIZE_IN_NEXT_LONG: - BE_STREAM_TO_UINT32 (seq_len, p); + case SIZE_IN_NEXT_LONG: + BE_STREAM_TO_UINT32(uuid_len, p); break; - default: + default: return (NULL); } - if (seq_len >= param_len) - return (NULL); + /* If UUID length is valid, copy it across */ + if ((uuid_len == 2) || (uuid_len == 4) || (uuid_len == 16)) { + p_seq->uuid_entry[p_seq->num_uids].len = (uint16_t)uuid_len; + BE_STREAM_TO_ARRAY(p, p_seq->uuid_entry[p_seq->num_uids].value, + (int)uuid_len); + p_seq->num_uids++; + } else + return (NULL); - p_seq_end = p + seq_len; - - /* Loop through, extracting the UIDs */ - for ( ; p < p_seq_end ; ) - { - BE_STREAM_TO_UINT8 (descr, p); - type = descr >> 3; - size = descr & 7; - - if (type != UUID_DESC_TYPE) - return (NULL); - - switch (size) - { - case SIZE_TWO_BYTES: - uuid_len = 2; - break; - case SIZE_FOUR_BYTES: - uuid_len = 4; - break; - case SIZE_SIXTEEN_BYTES: - uuid_len = 16; - break; - case SIZE_IN_NEXT_BYTE: - BE_STREAM_TO_UINT8 (uuid_len, p); - break; - case SIZE_IN_NEXT_WORD: - BE_STREAM_TO_UINT16 (uuid_len, p); - break; - case SIZE_IN_NEXT_LONG: - BE_STREAM_TO_UINT32 (uuid_len, p); - break; - default: - return (NULL); - } - - /* If UUID length is valid, copy it across */ - if ((uuid_len == 2) || (uuid_len == 4) || (uuid_len == 16)) - { - p_seq->uuid_entry[p_seq->num_uids].len = (uint16_t) uuid_len; - BE_STREAM_TO_ARRAY (p, p_seq->uuid_entry[p_seq->num_uids].value, (int)uuid_len); - p_seq->num_uids++; - } - else - return (NULL); - - /* We can only do so many */ - if (p_seq->num_uids >= MAX_UUIDS_PER_SEQ) - return (NULL); - } + /* We can only do so many */ + if (p_seq->num_uids >= MAX_UUIDS_PER_SEQ) return (NULL); + } - if (p != p_seq_end) - return (NULL); + if (p != p_seq_end) return (NULL); - return (p); + return (p); } - - /******************************************************************************* * * Function sdpu_extract_attr_seq @@ -473,101 +429,90 @@ uint8_t *sdpu_extract_uid_seq (uint8_t *p, uint16_t param_len, tSDP_UUID_SEQ *p_ * Returns Pointer to next byte in the input buffer after the sequence. * ******************************************************************************/ -uint8_t *sdpu_extract_attr_seq (uint8_t *p, uint16_t param_len, tSDP_ATTR_SEQ *p_seq) -{ - uint8_t *p_end_list; - uint8_t descr, type, size; - uint32_t list_len, attr_len; +uint8_t* sdpu_extract_attr_seq(uint8_t* p, uint16_t param_len, + tSDP_ATTR_SEQ* p_seq) { + uint8_t* p_end_list; + uint8_t descr, type, size; + uint32_t list_len, attr_len; - /* Assume none found */ - p_seq->num_attr = 0; + /* Assume none found */ + p_seq->num_attr = 0; - /* Get attribute sequence info */ - BE_STREAM_TO_UINT8 (descr, p); - type = descr >> 3; - size = descr & 7; + /* Get attribute sequence info */ + BE_STREAM_TO_UINT8(descr, p); + type = descr >> 3; + size = descr & 7; - if (type != DATA_ELE_SEQ_DESC_TYPE) - return (p); + if (type != DATA_ELE_SEQ_DESC_TYPE) return (p); - switch (size) - { + switch (size) { case SIZE_IN_NEXT_BYTE: - BE_STREAM_TO_UINT8 (list_len, p); - break; + BE_STREAM_TO_UINT8(list_len, p); + break; case SIZE_IN_NEXT_WORD: - BE_STREAM_TO_UINT16 (list_len, p); - break; + BE_STREAM_TO_UINT16(list_len, p); + break; case SIZE_IN_NEXT_LONG: - BE_STREAM_TO_UINT32 (list_len, p); - break; + BE_STREAM_TO_UINT32(list_len, p); + break; default: - return (p); - } + return (p); + } + + if (list_len > param_len) return (p); - if (list_len > param_len) - return (p); - - p_end_list = p + list_len; - - /* Loop through, extracting the attribute IDs */ - for ( ; p < p_end_list ; ) - { - BE_STREAM_TO_UINT8 (descr, p); - type = descr >> 3; - size = descr & 7; - - if (type != UINT_DESC_TYPE) - return (p); - - switch (size) - { - case SIZE_TWO_BYTES: - attr_len = 2; - break; - case SIZE_FOUR_BYTES: - attr_len = 4; - break; - case SIZE_IN_NEXT_BYTE: - BE_STREAM_TO_UINT8 (attr_len, p); - break; - case SIZE_IN_NEXT_WORD: - BE_STREAM_TO_UINT16 (attr_len, p); - break; - case SIZE_IN_NEXT_LONG: - BE_STREAM_TO_UINT32 (attr_len, p); - break; - default: - return (NULL); - break; - } - - /* Attribute length must be 2-bytes or 4-bytes for a paired entry. */ - if (attr_len == 2) - { - BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p); - p_seq->attr_entry[p_seq->num_attr].end = p_seq->attr_entry[p_seq->num_attr].start; - } - else if (attr_len == 4) - { - BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p); - BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].end, p); - } - else - return (NULL); - - /* We can only do so many */ - if (++p_seq->num_attr >= MAX_ATTR_PER_SEQ) - return (NULL); + p_end_list = p + list_len; + + /* Loop through, extracting the attribute IDs */ + for (; p < p_end_list;) { + BE_STREAM_TO_UINT8(descr, p); + type = descr >> 3; + size = descr & 7; + + if (type != UINT_DESC_TYPE) return (p); + + switch (size) { + case SIZE_TWO_BYTES: + attr_len = 2; + break; + case SIZE_FOUR_BYTES: + attr_len = 4; + break; + case SIZE_IN_NEXT_BYTE: + BE_STREAM_TO_UINT8(attr_len, p); + break; + case SIZE_IN_NEXT_WORD: + BE_STREAM_TO_UINT16(attr_len, p); + break; + case SIZE_IN_NEXT_LONG: + BE_STREAM_TO_UINT32(attr_len, p); + break; + default: + return (NULL); + break; } - return (p); + /* Attribute length must be 2-bytes or 4-bytes for a paired entry. */ + if (attr_len == 2) { + BE_STREAM_TO_UINT16(p_seq->attr_entry[p_seq->num_attr].start, p); + p_seq->attr_entry[p_seq->num_attr].end = + p_seq->attr_entry[p_seq->num_attr].start; + } else if (attr_len == 4) { + BE_STREAM_TO_UINT16(p_seq->attr_entry[p_seq->num_attr].start, p); + BE_STREAM_TO_UINT16(p_seq->attr_entry[p_seq->num_attr].end, p); + } else + return (NULL); + + /* We can only do so many */ + if (++p_seq->num_attr >= MAX_ATTR_PER_SEQ) return (NULL); + } + + return (p); } - /******************************************************************************* * * Function sdpu_get_len_from_type @@ -577,47 +522,44 @@ uint8_t *sdpu_extract_attr_seq (uint8_t *p, uint16_t param_len, tSDP_ATTR_SEQ *p * Returns void * ******************************************************************************/ -uint8_t *sdpu_get_len_from_type (uint8_t *p, uint8_t type, uint32_t *p_len) -{ - uint8_t u8; - uint16_t u16; - uint32_t u32; - - switch (type & 7) - { +uint8_t* sdpu_get_len_from_type(uint8_t* p, uint8_t type, uint32_t* p_len) { + uint8_t u8; + uint16_t u16; + uint32_t u32; + + switch (type & 7) { case SIZE_ONE_BYTE: - *p_len = 1; - break; + *p_len = 1; + break; case SIZE_TWO_BYTES: - *p_len = 2; - break; + *p_len = 2; + break; case SIZE_FOUR_BYTES: - *p_len = 4; - break; + *p_len = 4; + break; case SIZE_EIGHT_BYTES: - *p_len = 8; - break; + *p_len = 8; + break; case SIZE_SIXTEEN_BYTES: - *p_len = 16; - break; + *p_len = 16; + break; case SIZE_IN_NEXT_BYTE: - BE_STREAM_TO_UINT8 (u8, p); - *p_len = u8; - break; + BE_STREAM_TO_UINT8(u8, p); + *p_len = u8; + break; case SIZE_IN_NEXT_WORD: - BE_STREAM_TO_UINT16 (u16, p); - *p_len = u16; - break; + BE_STREAM_TO_UINT16(u16, p); + *p_len = u16; + break; case SIZE_IN_NEXT_LONG: - BE_STREAM_TO_UINT32 (u32, p); - *p_len = (uint16_t) u32; - break; - } + BE_STREAM_TO_UINT32(u32, p); + *p_len = (uint16_t)u32; + break; + } - return (p); + return (p); } - /******************************************************************************* * * Function sdpu_is_base_uuid @@ -628,19 +570,16 @@ uint8_t *sdpu_get_len_from_type (uint8_t *p, uint8_t type, uint32_t *p_len) * Returns true if matched, else false * ******************************************************************************/ -bool sdpu_is_base_uuid (uint8_t *p_uuid) -{ - uint16_t xx; +bool sdpu_is_base_uuid(uint8_t* p_uuid) { + uint16_t xx; - for (xx = 4; xx < MAX_UUID_SIZE; xx++) - if (p_uuid[xx] != sdp_base_uuid[xx]) - return (false); + for (xx = 4; xx < MAX_UUID_SIZE; xx++) + if (p_uuid[xx] != sdp_base_uuid[xx]) return (false); - /* If here, matched */ - return (true); + /* If here, matched */ + return (true); } - /******************************************************************************* * * Function sdpu_compare_uuid_arrays @@ -653,77 +592,64 @@ bool sdpu_is_base_uuid (uint8_t *p_uuid) * Returns true if matched, else false * ******************************************************************************/ -bool sdpu_compare_uuid_arrays (uint8_t *p_uuid1, uint32_t len1, uint8_t *p_uuid2, uint16_t len2) -{ - uint8_t nu1[MAX_UUID_SIZE]; - uint8_t nu2[MAX_UUID_SIZE]; - - if( ((len1 != 2) && (len1 != 4) && (len1 != 16)) || - ((len2 != 2) && (len2 != 4) && (len2 != 16)) ) - { - SDP_TRACE_ERROR("%s: invalid length", __func__); - return false; - } - - /* If lengths match, do a straight compare */ - if (len1 == len2) - { - if (len1 == 2) - return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1])); - if (len1 == 4) - return ( (p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1]) - && (p_uuid1[2] == p_uuid2[2]) && (p_uuid1[3] == p_uuid2[3]) ); - else - return (memcmp (p_uuid1, p_uuid2, (size_t)len1) == 0); - } - else if (len1 > len2) - { - /* If the len1 was 4-byte, (so len2 is 2-byte), compare on the fly */ - if (len1 == 4) - { - return ( (p_uuid1[0] == 0) && (p_uuid1[1] == 0) - && (p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1]) ); - } - else - { - /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */ - memcpy (nu1, p_uuid1, MAX_UUID_SIZE); - memcpy (nu2, sdp_base_uuid, MAX_UUID_SIZE); - - if (len2 == 4) - memcpy (nu2, p_uuid2, len2); - else if (len2 == 2) - memcpy (nu2 + 2, p_uuid2, len2); - - return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0); - } - } +bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1, uint8_t* p_uuid2, + uint16_t len2) { + uint8_t nu1[MAX_UUID_SIZE]; + uint8_t nu2[MAX_UUID_SIZE]; + + if (((len1 != 2) && (len1 != 4) && (len1 != 16)) || + ((len2 != 2) && (len2 != 4) && (len2 != 16))) { + SDP_TRACE_ERROR("%s: invalid length", __func__); + return false; + } + + /* If lengths match, do a straight compare */ + if (len1 == len2) { + if (len1 == 2) + return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1])); + if (len1 == 4) + return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1]) && + (p_uuid1[2] == p_uuid2[2]) && (p_uuid1[3] == p_uuid2[3])); else - { - /* len2 is greater than len1 */ - /* If the len2 was 4-byte, (so len1 is 2-byte), compare on the fly */ - if (len2 == 4) - { - return ( (p_uuid2[0] == 0) && (p_uuid2[1] == 0) - && (p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1]) ); - } - else - { - /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */ - memcpy (nu2, p_uuid2, MAX_UUID_SIZE); - memcpy (nu1, sdp_base_uuid, MAX_UUID_SIZE); - - if (len1 == 4) - memcpy (nu1, p_uuid1, (size_t)len1); - else if (len1 == 2) - memcpy (nu1 + 2, p_uuid1, (size_t)len1); - - return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0); - } + return (memcmp(p_uuid1, p_uuid2, (size_t)len1) == 0); + } else if (len1 > len2) { + /* If the len1 was 4-byte, (so len2 is 2-byte), compare on the fly */ + if (len1 == 4) { + return ((p_uuid1[0] == 0) && (p_uuid1[1] == 0) && + (p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1])); + } else { + /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */ + memcpy(nu1, p_uuid1, MAX_UUID_SIZE); + memcpy(nu2, sdp_base_uuid, MAX_UUID_SIZE); + + if (len2 == 4) + memcpy(nu2, p_uuid2, len2); + else if (len2 == 2) + memcpy(nu2 + 2, p_uuid2, len2); + + return (memcmp(nu1, nu2, MAX_UUID_SIZE) == 0); + } + } else { + /* len2 is greater than len1 */ + /* If the len2 was 4-byte, (so len1 is 2-byte), compare on the fly */ + if (len2 == 4) { + return ((p_uuid2[0] == 0) && (p_uuid2[1] == 0) && + (p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1])); + } else { + /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */ + memcpy(nu2, p_uuid2, MAX_UUID_SIZE); + memcpy(nu1, sdp_base_uuid, MAX_UUID_SIZE); + + if (len1 == 4) + memcpy(nu1, p_uuid1, (size_t)len1); + else if (len1 == 2) + memcpy(nu1 + 2, p_uuid1, (size_t)len1); + + return (memcmp(nu1, nu2, MAX_UUID_SIZE) == 0); } + } } - /******************************************************************************* * * Function sdpu_compare_bt_uuids @@ -736,23 +662,20 @@ bool sdpu_compare_uuid_arrays (uint8_t *p_uuid1, uint32_t len1, uint8_t *p_uu * Returns true if matched, else false * ******************************************************************************/ -bool sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2) -{ - /* Lengths must match for BT UUIDs to match */ - if (p_uuid1->len == p_uuid2->len) - { - if (p_uuid1->len == 2) - return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16); - else if (p_uuid1->len == 4) - return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32); - else if (!memcmp (p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16)) - return (true); - } - - return (false); +bool sdpu_compare_bt_uuids(tBT_UUID* p_uuid1, tBT_UUID* p_uuid2) { + /* Lengths must match for BT UUIDs to match */ + if (p_uuid1->len == p_uuid2->len) { + if (p_uuid1->len == 2) + return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16); + else if (p_uuid1->len == 4) + return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32); + else if (!memcmp(p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16)) + return (true); + } + + return (false); } - /******************************************************************************* * * Function sdpu_compare_uuid_with_attr @@ -769,30 +692,33 @@ bool sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2) * Returns true if matched, else false * ******************************************************************************/ -bool sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr) -{ - uint16_t attr_len = SDP_DISC_ATTR_LEN (p_attr->attr_len_type); - - /* Since both UUIDs are compressed, lengths must match */ - if (p_btuuid->len != attr_len) - return (false); - - if (p_btuuid->len == 2) - return (bool )(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16); - else if (p_btuuid->len == 4) - return (bool )(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32); - /* coverity[overrun-buffer-arg] */ - /* - Event overrun-buffer-arg: Overrun of static array "&p_attr->attr_value.v.array" of size 4 bytes by passing it to a function which indexes it with argument "16U" at byte position 15 - false-POSITIVE error from Coverity test tool. Please do NOT remove following comment. - False-positive: SDP uses scratch buffer to hold the attribute value. - The actual size of tSDP_DISC_ATVAL does not matter. - If the array size in tSDP_DISC_ATVAL is increase, we would increase the system RAM usage unnecessarily - */ - else if (!memcmp (p_btuuid->uu.uuid128,(void*) p_attr->attr_value.v.array, MAX_UUID_SIZE)) - return (true); - - return (false); +bool sdpu_compare_uuid_with_attr(tBT_UUID* p_btuuid, tSDP_DISC_ATTR* p_attr) { + uint16_t attr_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); + + /* Since both UUIDs are compressed, lengths must match */ + if (p_btuuid->len != attr_len) return (false); + + if (p_btuuid->len == 2) + return (bool)(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16); + else if (p_btuuid->len == 4) + return (bool)(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32); + /* coverity[overrun-buffer-arg] */ + /* + Event overrun-buffer-arg: Overrun of static array + "&p_attr->attr_value.v.array" of size 4 bytes by passing it to a function + which indexes it with argument "16U" at byte position 15 + false-POSITIVE error from Coverity test tool. Please do NOT remove + following comment. + False-positive: SDP uses scratch buffer to hold the attribute value. + The actual size of tSDP_DISC_ATVAL does not matter. + If the array size in tSDP_DISC_ATVAL is increase, we would increase the + system RAM usage unnecessarily + */ + else if (!memcmp(p_btuuid->uu.uuid128, (void*)p_attr->attr_value.v.array, + MAX_UUID_SIZE)) + return (true); + + return (false); } /******************************************************************************* @@ -805,39 +731,31 @@ bool sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr) * Returns void * ******************************************************************************/ -void sdpu_sort_attr_list( uint16_t num_attr, tSDP_DISCOVERY_DB *p_db ) -{ - uint16_t i; - uint16_t x; - - /* Done if no attributes to sort */ - if (num_attr <= 1) - { - return; - } - else if (num_attr > SDP_MAX_ATTR_FILTERS) - { - num_attr = SDP_MAX_ATTR_FILTERS; - } - - num_attr--; /* for the for-loop */ - for( i = 0; i < num_attr; ) - { - if( p_db->attr_filters[i] > p_db->attr_filters[i+1] ) - { - /* swap the attribute IDs and start from the beginning */ - x = p_db->attr_filters[i]; - p_db->attr_filters[i] = p_db->attr_filters[i+1]; - p_db->attr_filters[i+1] = x; - - i = 0; - } - else - i++; - } +void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db) { + uint16_t i; + uint16_t x; + + /* Done if no attributes to sort */ + if (num_attr <= 1) { + return; + } else if (num_attr > SDP_MAX_ATTR_FILTERS) { + num_attr = SDP_MAX_ATTR_FILTERS; + } + + num_attr--; /* for the for-loop */ + for (i = 0; i < num_attr;) { + if (p_db->attr_filters[i] > p_db->attr_filters[i + 1]) { + /* swap the attribute IDs and start from the beginning */ + x = p_db->attr_filters[i]; + p_db->attr_filters[i] = p_db->attr_filters[i + 1]; + p_db->attr_filters[i + 1] = x; + + i = 0; + } else + i++; + } } - /******************************************************************************* * * Function sdpu_get_list_len @@ -848,24 +766,23 @@ void sdpu_sort_attr_list( uint16_t num_attr, tSDP_DISCOVERY_DB *p_db ) * Returns void * ******************************************************************************/ -uint16_t sdpu_get_list_len(tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq) -{ - tSDP_RECORD *p_rec; - uint16_t len = 0; - uint16_t len1; - - for (p_rec = sdp_db_service_search (NULL, uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, uid_seq)) - { - len += 3; +uint16_t sdpu_get_list_len(tSDP_UUID_SEQ* uid_seq, tSDP_ATTR_SEQ* attr_seq) { + tSDP_RECORD* p_rec; + uint16_t len = 0; + uint16_t len1; - len1 = sdpu_get_attrib_seq_len(p_rec, attr_seq ); + for (p_rec = sdp_db_service_search(NULL, uid_seq); p_rec; + p_rec = sdp_db_service_search(p_rec, uid_seq)) { + len += 3; - if (len1 != 0) - len += len1; - else - len -= 3; - } - return len; + len1 = sdpu_get_attrib_seq_len(p_rec, attr_seq); + + if (len1 != 0) + len += len1; + else + len -= 3; + } + return len; } /******************************************************************************* @@ -878,43 +795,34 @@ uint16_t sdpu_get_list_len(tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq) * Returns void * ******************************************************************************/ -uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq) -{ - tSDP_ATTRIBUTE *p_attr; - uint16_t len1 = 0; - uint16_t xx; - bool is_range = false; - uint16_t start_id=0, end_id=0; - - for (xx = 0; xx < attr_seq->num_attr; xx++) - { - if (is_range == false) - { - start_id = attr_seq->attr_entry[xx].start; - end_id = attr_seq->attr_entry[xx].end; - } - p_attr = sdp_db_find_attr_in_rec (p_rec, - start_id, - end_id); - if (p_attr) - { - len1 += sdpu_get_attrib_entry_len (p_attr); - - /* If doing a range, stick with this one till no more attributes found */ - if (start_id != end_id) - { - /* Update for next time through */ - start_id = p_attr->id + 1; - xx--; - is_range = true; - } - else - is_range = false; - } - else - is_range = false; +uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD* p_rec, tSDP_ATTR_SEQ* attr_seq) { + tSDP_ATTRIBUTE* p_attr; + uint16_t len1 = 0; + uint16_t xx; + bool is_range = false; + uint16_t start_id = 0, end_id = 0; + + for (xx = 0; xx < attr_seq->num_attr; xx++) { + if (is_range == false) { + start_id = attr_seq->attr_entry[xx].start; + end_id = attr_seq->attr_entry[xx].end; } - return len1; + p_attr = sdp_db_find_attr_in_rec(p_rec, start_id, end_id); + if (p_attr) { + len1 += sdpu_get_attrib_entry_len(p_attr); + + /* If doing a range, stick with this one till no more attributes found */ + if (start_id != end_id) { + /* Update for next time through */ + start_id = p_attr->id + 1; + xx--; + is_range = true; + } else + is_range = false; + } else + is_range = false; + } + return len1; } /******************************************************************************* @@ -926,61 +834,51 @@ uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq) * Returns void * ******************************************************************************/ -uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr) -{ - uint16_t len = 3; - - /* the attribute is in the db record. - * assuming the attribute len is less than SDP_MAX_ATTR_LEN */ - switch(p_attr->type) - { - case TEXT_STR_DESC_TYPE: /* 4 */ - case DATA_ELE_SEQ_DESC_TYPE:/* 6 */ - case DATA_ELE_ALT_DESC_TYPE:/* 7 */ - case URL_DESC_TYPE: /* 8 */ +uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE* p_attr) { + uint16_t len = 3; + + /* the attribute is in the db record. + * assuming the attribute len is less than SDP_MAX_ATTR_LEN */ + switch (p_attr->type) { + case TEXT_STR_DESC_TYPE: /* 4 */ + case DATA_ELE_SEQ_DESC_TYPE: /* 6 */ + case DATA_ELE_ALT_DESC_TYPE: /* 7 */ + case URL_DESC_TYPE: /* 8 */ #if (SDP_MAX_ATTR_LEN > 0xFFFF) - if(p_attr->len > 0xFFFF) - { - len += 5; - } - else - -#endif/* 0xFFFF - 0xFF */ + if (p_attr->len > 0xFFFF) { + len += 5; + } else +#endif /* 0xFFFF - 0xFF */ #if (SDP_MAX_ATTR_LEN > 0xFF) - if(p_attr->len > 0xFF) - { - len += 3; - } - else - + if (p_attr->len > 0xFF) { + len += 3; + } else #endif /* 0xFF and less*/ - { - len += 2; - } - len += p_attr->len; - return len; - } - - /* Now, the attribute value */ - switch (p_attr->len) - { + { + len += 2; + } + len += p_attr->len; + return len; + } + + /* Now, the attribute value */ + switch (p_attr->len) { case 1: case 2: case 4: case 8: case 16: - len += 1; - break; + len += 1; + break; default: - len += 2; - break; - } + len += 2; + break; + } - len += p_attr->len; - return len; + len += p_attr->len; + return len; } - /******************************************************************************* * * Function sdpu_build_partial_attrib_entry @@ -998,27 +896,28 @@ uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr) * offset is also updated * ******************************************************************************/ -uint8_t *sdpu_build_partial_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr, uint16_t len, uint16_t *offset) -{ - uint8_t *p_attr_buff = (uint8_t *)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); - sdpu_build_attrib_entry(p_attr_buff, p_attr); +uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out, tSDP_ATTRIBUTE* p_attr, + uint16_t len, uint16_t* offset) { + uint8_t* p_attr_buff = + (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN); + sdpu_build_attrib_entry(p_attr_buff, p_attr); - uint16_t attr_len = sdpu_get_attrib_entry_len(p_attr); + uint16_t attr_len = sdpu_get_attrib_entry_len(p_attr); - if (len > SDP_MAX_ATTR_LEN) - { - SDP_TRACE_ERROR("%s len %d exceeds SDP_MAX_ATTR_LEN", __func__, len); - len = SDP_MAX_ATTR_LEN; - } + if (len > SDP_MAX_ATTR_LEN) { + SDP_TRACE_ERROR("%s len %d exceeds SDP_MAX_ATTR_LEN", __func__, len); + len = SDP_MAX_ATTR_LEN; + } - size_t len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset) : len; - memcpy(p_out, &p_attr_buff[*offset], len_to_copy); + size_t len_to_copy = + ((attr_len - *offset) < len) ? (attr_len - *offset) : len; + memcpy(p_out, &p_attr_buff[*offset], len_to_copy); - p_out = &p_out[len_to_copy]; - *offset += len_to_copy; + p_out = &p_out[len_to_copy]; + *offset += len_to_copy; - osi_free(p_attr_buff); - return p_out; + osi_free(p_attr_buff); + return p_out; } /******************************************************************************* @@ -1034,12 +933,11 @@ uint8_t *sdpu_build_partial_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr * Returns None * ******************************************************************************/ -void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128) -{ - uint16_t uuid16_bo; - memset(p_uuid128, 0, 16); - - memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE); - uuid16_bo = ntohs(uuid16); - memcpy(p_uuid128+ 2, &uuid16_bo, sizeof(uint16_t)); +void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128) { + uint16_t uuid16_bo; + memset(p_uuid128, 0, 16); + + memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE); + uuid16_bo = ntohs(uuid16); + memcpy(p_uuid128 + 2, &uuid16_bo, sizeof(uint16_t)); } diff --git a/stack/sdp/sdpint.h b/stack/sdp/sdpint.h index 4a9f726fa..7eb7e80dd 100644 --- a/stack/sdp/sdpint.h +++ b/stack/sdp/sdpint.h @@ -22,279 +22,283 @@ * ******************************************************************************/ -#ifndef SDP_INT_H -#define SDP_INT_H +#ifndef SDP_INT_H +#define SDP_INT_H #include "bt_target.h" +#include "l2c_api.h" #include "osi/include/alarm.h" #include "sdp_api.h" -#include "l2c_api.h" #ifdef __cplusplus extern "C" { #endif /* Continuation length - we use a 2-byte offset */ -#define SDP_CONTINUATION_LEN 2 -#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */ +#define SDP_CONTINUATION_LEN 2 +#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */ /* Timeout definitions. */ -#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */ - +#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */ /* Define the Out-Flow default values. */ -#define SDP_OFLOW_QOS_FLAG 0 -#define SDP_OFLOW_SERV_TYPE 0 -#define SDP_OFLOW_TOKEN_RATE 0 -#define SDP_OFLOW_TOKEN_BUCKET_SIZE 0 -#define SDP_OFLOW_PEAK_BANDWIDTH 0 -#define SDP_OFLOW_LATENCY 0 -#define SDP_OFLOW_DELAY_VARIATION 0 +#define SDP_OFLOW_QOS_FLAG 0 +#define SDP_OFLOW_SERV_TYPE 0 +#define SDP_OFLOW_TOKEN_RATE 0 +#define SDP_OFLOW_TOKEN_BUCKET_SIZE 0 +#define SDP_OFLOW_PEAK_BANDWIDTH 0 +#define SDP_OFLOW_LATENCY 0 +#define SDP_OFLOW_DELAY_VARIATION 0 /* Define the In-Flow default values. */ -#define SDP_IFLOW_QOS_FLAG 0 -#define SDP_IFLOW_SERV_TYPE 0 -#define SDP_IFLOW_TOKEN_RATE 0 -#define SDP_IFLOW_TOKEN_BUCKET_SIZE 0 -#define SDP_IFLOW_PEAK_BANDWIDTH 0 -#define SDP_IFLOW_LATENCY 0 -#define SDP_IFLOW_DELAY_VARIATION 0 +#define SDP_IFLOW_QOS_FLAG 0 +#define SDP_IFLOW_SERV_TYPE 0 +#define SDP_IFLOW_TOKEN_RATE 0 +#define SDP_IFLOW_TOKEN_BUCKET_SIZE 0 +#define SDP_IFLOW_PEAK_BANDWIDTH 0 +#define SDP_IFLOW_LATENCY 0 +#define SDP_IFLOW_DELAY_VARIATION 0 -#define SDP_LINK_TO 0 +#define SDP_LINK_TO 0 /* Define the type of device notification. */ /* (Inquiry Scan and Page Scan) */ -#define SDP_DEVICE_NOTI_LEN (sizeof (BT_HDR) + \ - HCIC_PREAMBLE_SIZE + \ - HCIC_PARAM_SIZE_WRITE_PARAM1) +#define SDP_DEVICE_NOTI_LEN \ + (sizeof(BT_HDR) + HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1) -#define SDP_DEVICE_NOTI_FLAG 0x03 +#define SDP_DEVICE_NOTI_FLAG 0x03 /* Define the Protocol Data Unit (PDU) types. */ -#define SDP_PDU_ERROR_RESPONSE 0x01 -#define SDP_PDU_SERVICE_SEARCH_REQ 0x02 -#define SDP_PDU_SERVICE_SEARCH_RSP 0x03 -#define SDP_PDU_SERVICE_ATTR_REQ 0x04 -#define SDP_PDU_SERVICE_ATTR_RSP 0x05 -#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06 -#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07 +#define SDP_PDU_ERROR_RESPONSE 0x01 +#define SDP_PDU_SERVICE_SEARCH_REQ 0x02 +#define SDP_PDU_SERVICE_SEARCH_RSP 0x03 +#define SDP_PDU_SERVICE_ATTR_REQ 0x04 +#define SDP_PDU_SERVICE_ATTR_RSP 0x05 +#define SDP_PDU_SERVICE_SEARCH_ATTR_REQ 0x06 +#define SDP_PDU_SERVICE_SEARCH_ATTR_RSP 0x07 /* Max UUIDs and attributes we support per sequence */ -#define MAX_UUIDS_PER_SEQ 16 -#define MAX_ATTR_PER_SEQ 16 +#define MAX_UUIDS_PER_SEQ 16 +#define MAX_ATTR_PER_SEQ 16 /* Max length we support for any attribute */ #ifdef SDP_MAX_ATTR_LEN #define MAX_ATTR_LEN SDP_MAX_ATTR_LEN #else -#define MAX_ATTR_LEN 256 +#define MAX_ATTR_LEN 256 #endif /* Internal UUID sequence representation */ -typedef struct -{ - uint16_t len; - uint8_t value[MAX_UUID_SIZE]; +typedef struct { + uint16_t len; + uint8_t value[MAX_UUID_SIZE]; } tUID_ENT; -typedef struct -{ - uint16_t num_uids; - tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ]; +typedef struct { + uint16_t num_uids; + tUID_ENT uuid_entry[MAX_UUIDS_PER_SEQ]; } tSDP_UUID_SEQ; - /* Internal attribute sequence definitions */ -typedef struct -{ - uint16_t start; - uint16_t end; +typedef struct { + uint16_t start; + uint16_t end; } tATT_ENT; -typedef struct -{ - uint16_t num_attr; - tATT_ENT attr_entry[MAX_ATTR_PER_SEQ]; +typedef struct { + uint16_t num_attr; + tATT_ENT attr_entry[MAX_ATTR_PER_SEQ]; } tSDP_ATTR_SEQ; - /* Define the attribute element of the SDP database record */ -typedef struct -{ - uint32_t len; /* Number of bytes in the entry */ - uint8_t *value_ptr; /* Points to attr_pad */ - uint16_t id; - uint8_t type; +typedef struct { + uint32_t len; /* Number of bytes in the entry */ + uint8_t* value_ptr; /* Points to attr_pad */ + uint16_t id; + uint8_t type; } tSDP_ATTRIBUTE; /* An SDP record consists of a handle, and 1 or more attributes */ -typedef struct -{ - uint32_t record_handle; - uint32_t free_pad_ptr; - uint16_t num_attributes; - tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR]; - uint8_t attr_pad[SDP_MAX_PAD_LEN]; +typedef struct { + uint32_t record_handle; + uint32_t free_pad_ptr; + uint16_t num_attributes; + tSDP_ATTRIBUTE attribute[SDP_MAX_REC_ATTR]; + uint8_t attr_pad[SDP_MAX_PAD_LEN]; } tSDP_RECORD; - /* Define the SDP database */ -typedef struct -{ - uint32_t di_primary_handle; /* Device ID Primary record or NULL if nonexistent */ - uint16_t num_records; - tSDP_RECORD record[SDP_MAX_RECORDS]; +typedef struct { + uint32_t + di_primary_handle; /* Device ID Primary record or NULL if nonexistent */ + uint16_t num_records; + tSDP_RECORD record[SDP_MAX_RECORDS]; } tSDP_DB; -enum -{ - SDP_IS_SEARCH, - SDP_IS_ATTR_SEARCH, +enum { + SDP_IS_SEARCH, + SDP_IS_ATTR_SEARCH, }; #if (SDP_SERVER_ENABLED == TRUE) /* Continuation information for the SDP server response */ -typedef struct -{ - uint16_t next_attr_index; /* attr index for next continuation response */ - uint16_t next_attr_start_id; /* attr id to start with for the attr index in next cont. response */ - tSDP_RECORD *prev_sdp_rec; /* last sdp record that was completely sent in the response */ - bool last_attr_seq_desc_sent; /* whether attr seq length has been sent previously */ - uint16_t attr_offset; /* offset within the attr to keep trak of partial attributes in the responses */ +typedef struct { + uint16_t next_attr_index; /* attr index for next continuation response */ + uint16_t next_attr_start_id; /* attr id to start with for the attr index in + next cont. response */ + tSDP_RECORD* prev_sdp_rec; /* last sdp record that was completely sent in the + response */ + bool last_attr_seq_desc_sent; /* whether attr seq length has been sent + previously */ + uint16_t attr_offset; /* offset within the attr to keep trak of partial + attributes in the responses */ } tSDP_CONT_INFO; -#endif /* SDP_SERVER_ENABLED == TRUE */ +#endif /* SDP_SERVER_ENABLED == TRUE */ /* Define the SDP Connection Control Block */ -typedef struct -{ -#define SDP_STATE_IDLE 0 -#define SDP_STATE_CONN_SETUP 1 -#define SDP_STATE_CFG_SETUP 2 -#define SDP_STATE_CONNECTED 3 - uint8_t con_state; - -#define SDP_FLAGS_IS_ORIG 0x01 -#define SDP_FLAGS_HIS_CFG_DONE 0x02 -#define SDP_FLAGS_MY_CFG_DONE 0x04 - uint8_t con_flags; - - BD_ADDR device_address; - alarm_t *sdp_conn_timer; - uint16_t rem_mtu_size; - uint16_t connection_id; - uint16_t list_len; /* length of the response in the GKI buffer */ - uint8_t *rsp_list; /* pointer to GKI buffer holding response */ +typedef struct { +#define SDP_STATE_IDLE 0 +#define SDP_STATE_CONN_SETUP 1 +#define SDP_STATE_CFG_SETUP 2 +#define SDP_STATE_CONNECTED 3 + uint8_t con_state; + +#define SDP_FLAGS_IS_ORIG 0x01 +#define SDP_FLAGS_HIS_CFG_DONE 0x02 +#define SDP_FLAGS_MY_CFG_DONE 0x04 + uint8_t con_flags; + + BD_ADDR device_address; + alarm_t* sdp_conn_timer; + uint16_t rem_mtu_size; + uint16_t connection_id; + uint16_t list_len; /* length of the response in the GKI buffer */ + uint8_t* rsp_list; /* pointer to GKI buffer holding response */ #if (SDP_CLIENT_ENABLED == TRUE) - tSDP_DISCOVERY_DB *p_db; /* Database to save info into */ - tSDP_DISC_CMPL_CB *p_cb; /* Callback for discovery done */ - tSDP_DISC_CMPL_CB2 *p_cb2; /* Callback for discovery done piggy back with the user data */ - void *user_data; /* piggy back user data */ - uint32_t handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */ - uint16_t num_handles; /* Number of server handles */ - uint16_t cur_handle; /* Current handle being processed */ - uint16_t transaction_id; - uint16_t disconnect_reason; /* Disconnect reason */ + tSDP_DISCOVERY_DB* p_db; /* Database to save info into */ + tSDP_DISC_CMPL_CB* p_cb; /* Callback for discovery done */ + tSDP_DISC_CMPL_CB2* + p_cb2; /* Callback for discovery done piggy back with the user data */ + void* user_data; /* piggy back user data */ + uint32_t + handles[SDP_MAX_DISC_SERVER_RECS]; /* Discovered server record handles */ + uint16_t num_handles; /* Number of server handles */ + uint16_t cur_handle; /* Current handle being processed */ + uint16_t transaction_id; + uint16_t disconnect_reason; /* Disconnect reason */ #if (SDP_BROWSE_PLUS == TRUE) - uint16_t cur_uuid_idx; + uint16_t cur_uuid_idx; #endif -#define SDP_DISC_WAIT_CONN 0 -#define SDP_DISC_WAIT_HANDLES 1 -#define SDP_DISC_WAIT_ATTR 2 -#define SDP_DISC_WAIT_SEARCH_ATTR 3 -#define SDP_DISC_WAIT_CANCEL 5 +#define SDP_DISC_WAIT_CONN 0 +#define SDP_DISC_WAIT_HANDLES 1 +#define SDP_DISC_WAIT_ATTR 2 +#define SDP_DISC_WAIT_SEARCH_ATTR 3 +#define SDP_DISC_WAIT_CANCEL 5 - uint8_t disc_state; - uint8_t is_attr_search; -#endif /* SDP_CLIENT_ENABLED == TRUE */ + uint8_t disc_state; + uint8_t is_attr_search; +#endif /* SDP_CLIENT_ENABLED == TRUE */ #if (SDP_SERVER_ENABLED == TRUE) - uint16_t cont_offset; /* Continuation state data in the server response */ - tSDP_CONT_INFO cont_info; /* structure to hold continuation information for the server response */ -#endif /* SDP_SERVER_ENABLED == TRUE */ + uint16_t cont_offset; /* Continuation state data in the server response */ + tSDP_CONT_INFO cont_info; /* structure to hold continuation information for + the server response */ +#endif /* SDP_SERVER_ENABLED == TRUE */ } tCONN_CB; - /* The main SDP control block */ -typedef struct -{ - tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ - tCONN_CB ccb[SDP_MAX_CONNECTIONS]; +typedef struct { + tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ + tCONN_CB ccb[SDP_MAX_CONNECTIONS]; #if (SDP_SERVER_ENABLED == TRUE) - tSDP_DB server_db; + tSDP_DB server_db; #endif - tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ - uint16_t max_attr_list_size; /* Max attribute list size to use */ - uint16_t max_recs_per_search; /* Max records we want per seaarch */ - uint8_t trace_level; + tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */ + uint16_t max_attr_list_size; /* Max attribute list size to use */ + uint16_t max_recs_per_search; /* Max records we want per seaarch */ + uint8_t trace_level; } tSDP_CB; /* Global SDP data */ -extern tSDP_CB sdp_cb; +extern tSDP_CB sdp_cb; /* Functions provided by sdp_main.cc */ -extern void sdp_init (void); -extern void sdp_disconnect (tCONN_CB*p_ccb, uint16_t reason); +extern void sdp_init(void); +extern void sdp_disconnect(tCONN_CB* p_ccb, uint16_t reason); #if (SDP_DEBUG == TRUE) -extern uint16_t sdp_set_max_attr_list_size (uint16_t max_size); +extern uint16_t sdp_set_max_attr_list_size(uint16_t max_size); #endif /* Functions provided by sdp_conn.cc */ -extern void sdp_conn_rcv_l2e_conn_ind (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_conn_cfm (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_disc (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_config_ind (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_config_cfm (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_connected (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg); -extern void sdp_conn_rcv_l2e_data (BT_HDR *p_msg); -extern void sdp_conn_timer_timeout(void *data); - -extern tCONN_CB *sdp_conn_originate (uint8_t *p_bd_addr); +extern void sdp_conn_rcv_l2e_conn_ind(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_conn_cfm(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_disc(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_config_ind(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_config_cfm(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_conn_failed(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_connected(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_conn_failed(BT_HDR* p_msg); +extern void sdp_conn_rcv_l2e_data(BT_HDR* p_msg); +extern void sdp_conn_timer_timeout(void* data); + +extern tCONN_CB* sdp_conn_originate(uint8_t* p_bd_addr); /* Functions provided by sdp_utils.cc */ -extern tCONN_CB *sdpu_find_ccb_by_cid (uint16_t cid); -extern tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db); -extern tCONN_CB *sdpu_allocate_ccb (void); -extern void sdpu_release_ccb (tCONN_CB *p_ccb); - -extern uint8_t *sdpu_build_attrib_seq (uint8_t *p_out, uint16_t *p_attr, uint16_t num_attrs); -extern uint8_t *sdpu_build_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr); -extern void sdpu_build_n_send_error (tCONN_CB *p_ccb, uint16_t trans_num, uint16_t error_code, char *p_error_text); - -extern uint8_t *sdpu_extract_attr_seq (uint8_t *p, uint16_t param_len, tSDP_ATTR_SEQ *p_seq); -extern uint8_t *sdpu_extract_uid_seq (uint8_t *p, uint16_t param_len, tSDP_UUID_SEQ *p_seq); - -extern uint8_t *sdpu_get_len_from_type (uint8_t *p, uint8_t type, uint32_t *p_len); -extern bool sdpu_is_base_uuid (uint8_t *p_uuid); -extern bool sdpu_compare_uuid_arrays (uint8_t *p_uuid1, uint32_t len1, uint8_t *p_uuid2, uint16_t len2); -extern bool sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2); -extern bool sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr); - -extern void sdpu_sort_attr_list( uint16_t num_attr, tSDP_DISCOVERY_DB *p_db ); -extern uint16_t sdpu_get_list_len( tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq ); -extern uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq); -extern uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr); -extern uint8_t *sdpu_build_partial_attrib_entry (uint8_t *p_out, tSDP_ATTRIBUTE *p_attr, uint16_t len, uint16_t *offset); +extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid); +extern tCONN_CB* sdpu_find_ccb_by_db(tSDP_DISCOVERY_DB* p_db); +extern tCONN_CB* sdpu_allocate_ccb(void); +extern void sdpu_release_ccb(tCONN_CB* p_ccb); + +extern uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr, + uint16_t num_attrs); +extern uint8_t* sdpu_build_attrib_entry(uint8_t* p_out, tSDP_ATTRIBUTE* p_attr); +extern void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num, + uint16_t error_code, char* p_error_text); + +extern uint8_t* sdpu_extract_attr_seq(uint8_t* p, uint16_t param_len, + tSDP_ATTR_SEQ* p_seq); +extern uint8_t* sdpu_extract_uid_seq(uint8_t* p, uint16_t param_len, + tSDP_UUID_SEQ* p_seq); + +extern uint8_t* sdpu_get_len_from_type(uint8_t* p, uint8_t type, + uint32_t* p_len); +extern bool sdpu_is_base_uuid(uint8_t* p_uuid); +extern bool sdpu_compare_uuid_arrays(uint8_t* p_uuid1, uint32_t len1, + uint8_t* p_uuid2, uint16_t len2); +extern bool sdpu_compare_bt_uuids(tBT_UUID* p_uuid1, tBT_UUID* p_uuid2); +extern bool sdpu_compare_uuid_with_attr(tBT_UUID* p_btuuid, + tSDP_DISC_ATTR* p_attr); + +extern void sdpu_sort_attr_list(uint16_t num_attr, tSDP_DISCOVERY_DB* p_db); +extern uint16_t sdpu_get_list_len(tSDP_UUID_SEQ* uid_seq, + tSDP_ATTR_SEQ* attr_seq); +extern uint16_t sdpu_get_attrib_seq_len(tSDP_RECORD* p_rec, + tSDP_ATTR_SEQ* attr_seq); +extern uint16_t sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE* p_attr); +extern uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out, + tSDP_ATTRIBUTE* p_attr, + uint16_t len, uint16_t* offset); /* Functions provided by sdp_db.cc */ -extern tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq); -extern tSDP_RECORD *sdp_db_find_record (uint32_t handle); -extern tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, uint16_t start_attr, uint16_t end_attr); - +extern tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec, + tSDP_UUID_SEQ* p_seq); +extern tSDP_RECORD* sdp_db_find_record(uint32_t handle); +extern tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(tSDP_RECORD* p_rec, + uint16_t start_attr, + uint16_t end_attr); /* Functions provided by sdp_server.cc */ #if (SDP_SERVER_ENABLED == TRUE) -extern void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg); +extern void sdp_server_handle_client_req(tCONN_CB* p_ccb, BT_HDR* p_msg); #else #define sdp_server_handle_client_req(p_ccb, p_msg) #endif @@ -302,8 +306,8 @@ extern void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg); /* Functions provided by sdp_discovery.cc */ #if (SDP_CLIENT_ENABLED == TRUE) -extern void sdp_disc_connected (tCONN_CB *p_ccb); -extern void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg); +extern void sdp_disc_connected(tCONN_CB* p_ccb); +extern void sdp_disc_server_rsp(tCONN_CB* p_ccb, BT_HDR* p_msg); #else #define sdp_disc_connected(p_ccb) #define sdp_disc_server_rsp(p_ccb, p_msg) diff --git a/stack/smp/aes.cc b/stack/smp/aes.cc index c9e52831e..362a4eeaa 100644 --- a/stack/smp/aes.cc +++ b/stack/smp/aes.cc @@ -33,13 +33,13 @@ /* define if you have a fast memcpy function on your system */ #if 1 -# define HAVE_MEMCPY -# include +#define HAVE_MEMCPY +#include #if 0 -# if defined( _MSC_VER ) -# include -# pragma intrinsic( memcpy ) -# endif +#if defined(_MSC_VER) +#include +#pragma intrinsic(memcpy) +#endif #endif #endif @@ -51,151 +51,174 @@ /* define if you have fast 32-bit types on your system */ #if 1 -# define HAVE_UINT_32T +#define HAVE_UINT_32T #endif /* define if you don't want any tables */ #if 1 -# define USE_TABLES +#define USE_TABLES #endif /* On Intel Core 2 duo VERSION_1 is faster */ /* alternative versions (test for performance on your system) */ #if 1 -# define VERSION_1 +#define VERSION_1 #endif #include "aes.h" -#if defined( HAVE_UINT_32T ) - typedef uint32_t uint_32t; +#if defined(HAVE_UINT_32T) +typedef uint32_t uint_32t; #endif /* functions for finite field multiplication in the AES Galois field */ -#define WPOLY 0x011b -#define BPOLY 0x1b -#define DPOLY 0x008d - -#define f1(x) (x) -#define f2(x) (((x) << 1) ^ ((((x) >> 7) & 1) * WPOLY)) -#define f4(x) (((x) << 2) ^ ((((x) >> 6) & 1) * WPOLY) ^ ((((x) >> 6) & 2) * WPOLY)) -#define f8(x) (((x) << 3) ^ ((((x) >> 5) & 1) * WPOLY) ^ ((((x) >> 5) & 2) * WPOLY) \ - ^ ((((x) >> 5) & 4) * WPOLY)) -#define d2(x) (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0)) - -#define f3(x) (f2(x) ^ (x)) -#define f9(x) (f8(x) ^ (x)) -#define fb(x) (f8(x) ^ f2(x) ^ (x)) -#define fd(x) (f8(x) ^ f4(x) ^ (x)) -#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) - -#if defined( USE_TABLES ) - -#define sb_data(w) { /* S Box data values */ \ - w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ - w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ - w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ - w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ - w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ - w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ - w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ - w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ - w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ - w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ - w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ - w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ - w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ - w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ - w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ - w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ - w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ - w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ - w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ - w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ - w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ - w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ - w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ - w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ - w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ - w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ - w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ - w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ - w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ - w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ - w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ - w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } - -#define isb_data(w) { /* inverse S Box data values */ \ - w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ - w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ - w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ - w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ - w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ - w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ - w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ - w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ - w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ - w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ - w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ - w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ - w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ - w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ - w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ - w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ - w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ - w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ - w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ - w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ - w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ - w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ - w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ - w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ - w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ - w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ - w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ - w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ - w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ - w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ - w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ - w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) } - -#define mm_data(w) { /* basic data for forming finite field tables */ \ - w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ - w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ - w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ - w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ - w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ - w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ - w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ - w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ - w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ - w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ - w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ - w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ - w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ - w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ - w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ - w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ - w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ - w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ - w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ - w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ - w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ - w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ - w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ - w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ - w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ - w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ - w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ - w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ - w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ - w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ - w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ - w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) } - -static const uint_8t sbox[256] = sb_data(f1); +#define WPOLY 0x011b +#define BPOLY 0x1b +#define DPOLY 0x008d + +#define f1(x) (x) +#define f2(x) (((x) << 1) ^ ((((x) >> 7) & 1) * WPOLY)) +#define f4(x) \ + (((x) << 2) ^ ((((x) >> 6) & 1) * WPOLY) ^ ((((x) >> 6) & 2) * WPOLY)) +#define f8(x) \ + (((x) << 3) ^ ((((x) >> 5) & 1) * WPOLY) ^ ((((x) >> 5) & 2) * WPOLY) ^ \ + ((((x) >> 5) & 4) * WPOLY)) +#define d2(x) (((x) >> 1) ^ ((x)&1 ? DPOLY : 0)) + +#define f3(x) (f2(x) ^ (x)) +#define f9(x) (f8(x) ^ (x)) +#define fb(x) (f8(x) ^ f2(x) ^ (x)) +#define fd(x) (f8(x) ^ f4(x) ^ (x)) +#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) + +#if defined(USE_TABLES) + +#define sb_data(w) \ + { /* S Box data values */ \ + w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5), \ + w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), \ + w(0x76), w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), \ + w(0x47), w(0xf0), w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), \ + w(0xa4), w(0x72), w(0xc0), w(0xb7), w(0xfd), w(0x93), w(0x26), \ + w(0x36), w(0x3f), w(0xf7), w(0xcc), w(0x34), w(0xa5), w(0xe5), \ + w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15), w(0x04), w(0xc7), \ + w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a), w(0x07), \ + w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75), \ + w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), \ + w(0xa0), w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), \ + w(0x2f), w(0x84), w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), \ + w(0xfc), w(0xb1), w(0x5b), w(0x6a), w(0xcb), w(0xbe), w(0x39), \ + w(0x4a), w(0x4c), w(0x58), w(0xcf), w(0xd0), w(0xef), w(0xaa), \ + w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85), w(0x45), w(0xf9), \ + w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8), w(0x51), \ + w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5), \ + w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), \ + w(0xd2), w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), \ + w(0x44), w(0x17), w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), \ + w(0x5d), w(0x19), w(0x73), w(0x60), w(0x81), w(0x4f), w(0xdc), \ + w(0x22), w(0x2a), w(0x90), w(0x88), w(0x46), w(0xee), w(0xb8), \ + w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb), w(0xe0), w(0x32), \ + w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c), w(0xc2), \ + w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79), \ + w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), \ + w(0xa9), w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), \ + w(0xae), w(0x08), w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), \ + w(0xa6), w(0xb4), w(0xc6), w(0xe8), w(0xdd), w(0x74), w(0x1f), \ + w(0x4b), w(0xbd), w(0x8b), w(0x8a), w(0x70), w(0x3e), w(0xb5), \ + w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e), w(0x61), w(0x35), \ + w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e), w(0xe1), \ + w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94), \ + w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), \ + w(0xdf), w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), \ + w(0x42), w(0x68), w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), \ + w(0x54), w(0xbb), w(0x16) \ + } + +#define isb_data(w) \ + { /* inverse S Box data values */ \ + w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38), \ + w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), \ + w(0xfb), w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), \ + w(0xff), w(0x87), w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), \ + w(0xde), w(0xe9), w(0xcb), w(0x54), w(0x7b), w(0x94), w(0x32), \ + w(0xa6), w(0xc2), w(0x23), w(0x3d), w(0xee), w(0x4c), w(0x95), \ + w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e), w(0x08), w(0x2e), \ + w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2), w(0x76), \ + w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25), \ + w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), \ + w(0x16), w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), \ + w(0xb6), w(0x92), w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), \ + w(0xed), w(0xb9), w(0xda), w(0x5e), w(0x15), w(0x46), w(0x57), \ + w(0xa7), w(0x8d), w(0x9d), w(0x84), w(0x90), w(0xd8), w(0xab), \ + w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a), w(0xf7), w(0xe4), \ + w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06), w(0xd0), \ + w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02), \ + w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), \ + w(0x6b), w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), \ + w(0xdc), w(0xea), w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), \ + w(0xb4), w(0xe6), w(0x73), w(0x96), w(0xac), w(0x74), w(0x22), \ + w(0xe7), w(0xad), w(0x35), w(0x85), w(0xe2), w(0xf9), w(0x37), \ + w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e), w(0x47), w(0xf1), \ + w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89), w(0x6f), \ + w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b), \ + w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), \ + w(0x20), w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), \ + w(0x5a), w(0xf4), w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), \ + w(0x07), w(0xc7), w(0x31), w(0xb1), w(0x12), w(0x10), w(0x59), \ + w(0x27), w(0x80), w(0xec), w(0x5f), w(0x60), w(0x51), w(0x7f), \ + w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d), w(0x2d), w(0xe5), \ + w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef), w(0xa0), \ + w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0), \ + w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), \ + w(0x61), w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), \ + w(0xd6), w(0x26), w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), \ + w(0x21), w(0x0c), w(0x7d) \ + } + +#define mm_data(w) \ + { /* basic data for forming finite field tables */ \ + w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07), \ + w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), \ + w(0x0f), w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), \ + w(0x16), w(0x17), w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), \ + w(0x1d), w(0x1e), w(0x1f), w(0x20), w(0x21), w(0x22), w(0x23), \ + w(0x24), w(0x25), w(0x26), w(0x27), w(0x28), w(0x29), w(0x2a), \ + w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f), w(0x30), w(0x31), \ + w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37), w(0x38), \ + w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f), \ + w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), \ + w(0x47), w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), \ + w(0x4e), w(0x4f), w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), \ + w(0x55), w(0x56), w(0x57), w(0x58), w(0x59), w(0x5a), w(0x5b), \ + w(0x5c), w(0x5d), w(0x5e), w(0x5f), w(0x60), w(0x61), w(0x62), \ + w(0x63), w(0x64), w(0x65), w(0x66), w(0x67), w(0x68), w(0x69), \ + w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f), w(0x70), \ + w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77), \ + w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), \ + w(0x7f), w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), \ + w(0x86), w(0x87), w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), \ + w(0x8d), w(0x8e), w(0x8f), w(0x90), w(0x91), w(0x92), w(0x93), \ + w(0x94), w(0x95), w(0x96), w(0x97), w(0x98), w(0x99), w(0x9a), \ + w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f), w(0xa0), w(0xa1), \ + w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7), w(0xa8), \ + w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf), \ + w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), \ + w(0xb7), w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), \ + w(0xbe), w(0xbf), w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), \ + w(0xc5), w(0xc6), w(0xc7), w(0xc8), w(0xc9), w(0xca), w(0xcb), \ + w(0xcc), w(0xcd), w(0xce), w(0xcf), w(0xd0), w(0xd1), w(0xd2), \ + w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7), w(0xd8), w(0xd9), \ + w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf), w(0xe0), \ + w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7), \ + w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), \ + w(0xef), w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), \ + w(0xf6), w(0xf7), w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), \ + w(0xfd), w(0xfe), w(0xff) \ + } + +static const uint_8t sbox[256] = sb_data(f1); static const uint_8t isbox[256] = isb_data(f1); static const uint_8t gfm2_sbox[256] = sb_data(f2); @@ -206,14 +229,14 @@ static const uint_8t gfmul_b[256] = mm_data(fb); static const uint_8t gfmul_d[256] = mm_data(fd); static const uint_8t gfmul_e[256] = mm_data(fe); -#define s_box(x) sbox[(x)] -#define is_box(x) isbox[(x)] -#define gfm2_sb(x) gfm2_sbox[(x)] -#define gfm3_sb(x) gfm3_sbox[(x)] -#define gfm_9(x) gfmul_9[(x)] -#define gfm_b(x) gfmul_b[(x)] -#define gfm_d(x) gfmul_d[(x)] -#define gfm_e(x) gfmul_e[(x)] +#define s_box(x) sbox[(x)] +#define is_box(x) isbox[(x)] +#define gfm2_sb(x) gfm2_sbox[(x)] +#define gfm3_sb(x) gfm3_sbox[(x)] +#define gfm_9(x) gfmul_9[(x)] +#define gfm_b(x) gfmul_b[(x)] +#define gfm_d(x) gfmul_d[(x)] +#define gfm_e(x) gfmul_e[(x)] #else @@ -222,280 +245,292 @@ static const uint_8t gfmul_e[256] = mm_data(fe); /* 9 bits (0x11b), this right shift keeps the */ /* values of all top bits within a byte */ -static uint_8t hibit(const uint_8t x) -{ uint_8t r = (uint_8t)((x >> 1) | (x >> 2)); +static uint_8t hibit(const uint_8t x) { + uint_8t r = (uint_8t)((x >> 1) | (x >> 2)); - r |= (r >> 2); - r |= (r >> 4); - return (r + 1) >> 1; + r |= (r >> 2); + r |= (r >> 4); + return (r + 1) >> 1; } /* return the inverse of the finite field element x */ -static uint_8t gf_inv(const uint_8t x) -{ uint_8t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; +static uint_8t gf_inv(const uint_8t x) { + uint_8t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; - if(x < 2) - return x; + if (x < 2) return x; - for( ; ; ) - { - if(n1) - while(n2 >= n1) /* divide polynomial p2 by p1 */ - { - n2 /= n1; /* shift smaller polynomial left */ - p2 ^= (p1 * n2) & 0xff; /* and remove from larger one */ - v2 ^= (v1 * n2); /* shift accumulated value and */ - n2 = hibit(p2); /* add into result */ - } - else - return v1; - - if(n2) /* repeat with values swapped */ - while(n1 >= n2) - { - n1 /= n2; - p1 ^= p2 * n1; - v1 ^= v2 * n1; - n1 = hibit(p1); - } - else - return v2; - } + for (;;) { + if (n1) + while (n2 >= n1) /* divide polynomial p2 by p1 */ + { + n2 /= n1; /* shift smaller polynomial left */ + p2 ^= (p1 * n2) & 0xff; /* and remove from larger one */ + v2 ^= (v1 * n2); /* shift accumulated value and */ + n2 = hibit(p2); /* add into result */ + } + else + return v1; + + if (n2) /* repeat with values swapped */ + while (n1 >= n2) { + n1 /= n2; + p1 ^= p2 * n1; + v1 ^= v2 * n1; + n1 = hibit(p1); + } + else + return v2; + } } /* The forward and inverse affine transformations used in the S-box */ -uint_8t fwd_affine(const uint_8t x) -{ -#if defined( HAVE_UINT_32T ) - uint_32t w = x; - w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4); - return 0x63 ^ ((w ^ (w >> 8)) & 0xff); +uint_8t fwd_affine(const uint_8t x) { +#if defined(HAVE_UINT_32T) + uint_32t w = x; + w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4); + return 0x63 ^ ((w ^ (w >> 8)) & 0xff); #else - return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4) - ^ (x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4); + return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4) ^ (x >> 7) ^ + (x >> 6) ^ (x >> 5) ^ (x >> 4); #endif } -uint_8t inv_affine(const uint_8t x) -{ -#if defined( HAVE_UINT_32T ) - uint_32t w = x; - w = (w << 1) ^ (w << 3) ^ (w << 6); - return 0x05 ^ ((w ^ (w >> 8)) & 0xff); +uint_8t inv_affine(const uint_8t x) { +#if defined(HAVE_UINT_32T) + uint_32t w = x; + w = (w << 1) ^ (w << 3) ^ (w << 6); + return 0x05 ^ ((w ^ (w >> 8)) & 0xff); #else - return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6) - ^ (x >> 7) ^ (x >> 5) ^ (x >> 2); + return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6) ^ (x >> 7) ^ (x >> 5) ^ (x >> 2); #endif } -#define s_box(x) fwd_affine(gf_inv(x)) -#define is_box(x) gf_inv(inv_affine(x)) +#define s_box(x) fwd_affine(gf_inv(x)) +#define is_box(x) gf_inv(inv_affine(x)) #define gfm2_sb(x) f2(s_box(x)) #define gfm3_sb(x) f3(s_box(x)) -#define gfm_9(x) f9(x) -#define gfm_b(x) fb(x) -#define gfm_d(x) fd(x) -#define gfm_e(x) fe(x) +#define gfm_9(x) f9(x) +#define gfm_b(x) fb(x) +#define gfm_d(x) fd(x) +#define gfm_e(x) fe(x) #endif -#if defined( HAVE_MEMCPY ) -# define block_copy_nn(d, s, l) memcpy(d, s, l) -# define block_copy(d, s) memcpy(d, s, N_BLOCK) +#if defined(HAVE_MEMCPY) +#define block_copy_nn(d, s, l) memcpy(d, s, l) +#define block_copy(d, s) memcpy(d, s, N_BLOCK) #else -# define block_copy_nn(d, s, l) copy_block_nn(d, s, l) -# define block_copy(d, s) copy_block(d, s) +#define block_copy_nn(d, s, l) copy_block_nn(d, s, l) +#define block_copy(d, s) copy_block(d, s) #endif -#if !defined( HAVE_MEMCPY ) -static void copy_block( void *d, const void *s ) -{ -#if defined( HAVE_UINT_32T ) - ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0]; - ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1]; - ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2]; - ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3]; +#if !defined(HAVE_MEMCPY) +static void copy_block(void* d, const void* s) { +#if defined(HAVE_UINT_32T) + ((uint_32t*)d)[0] = ((uint_32t*)s)[0]; + ((uint_32t*)d)[1] = ((uint_32t*)s)[1]; + ((uint_32t*)d)[2] = ((uint_32t*)s)[2]; + ((uint_32t*)d)[3] = ((uint_32t*)s)[3]; #else - ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0]; - ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1]; - ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2]; - ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3]; - ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4]; - ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5]; - ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6]; - ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7]; - ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8]; - ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9]; - ((uint_8t*)d)[10] = ((uint_8t*)s)[10]; - ((uint_8t*)d)[11] = ((uint_8t*)s)[11]; - ((uint_8t*)d)[12] = ((uint_8t*)s)[12]; - ((uint_8t*)d)[13] = ((uint_8t*)s)[13]; - ((uint_8t*)d)[14] = ((uint_8t*)s)[14]; - ((uint_8t*)d)[15] = ((uint_8t*)s)[15]; + ((uint_8t*)d)[0] = ((uint_8t*)s)[0]; + ((uint_8t*)d)[1] = ((uint_8t*)s)[1]; + ((uint_8t*)d)[2] = ((uint_8t*)s)[2]; + ((uint_8t*)d)[3] = ((uint_8t*)s)[3]; + ((uint_8t*)d)[4] = ((uint_8t*)s)[4]; + ((uint_8t*)d)[5] = ((uint_8t*)s)[5]; + ((uint_8t*)d)[6] = ((uint_8t*)s)[6]; + ((uint_8t*)d)[7] = ((uint_8t*)s)[7]; + ((uint_8t*)d)[8] = ((uint_8t*)s)[8]; + ((uint_8t*)d)[9] = ((uint_8t*)s)[9]; + ((uint_8t*)d)[10] = ((uint_8t*)s)[10]; + ((uint_8t*)d)[11] = ((uint_8t*)s)[11]; + ((uint_8t*)d)[12] = ((uint_8t*)s)[12]; + ((uint_8t*)d)[13] = ((uint_8t*)s)[13]; + ((uint_8t*)d)[14] = ((uint_8t*)s)[14]; + ((uint_8t*)d)[15] = ((uint_8t*)s)[15]; #endif } -static void copy_block_nn( void * d, const void *s, uint_8t nn ) -{ - while( nn-- ) - *((uint_8t*)d)++ = *((uint_8t*)s)++; +static void copy_block_nn(void* d, const void* s, uint_8t nn) { + while (nn--) *((uint_8t*)d)++ = *((uint_8t*)s)++; } #endif -static void xor_block( void *d, const void *s ) -{ -#if defined( HAVE_UINT_32T ) - ((uint_32t*)d)[ 0] ^= ((uint_32t*)s)[ 0]; - ((uint_32t*)d)[ 1] ^= ((uint_32t*)s)[ 1]; - ((uint_32t*)d)[ 2] ^= ((uint_32t*)s)[ 2]; - ((uint_32t*)d)[ 3] ^= ((uint_32t*)s)[ 3]; +static void xor_block(void* d, const void* s) { +#if defined(HAVE_UINT_32T) + ((uint_32t*)d)[0] ^= ((uint_32t*)s)[0]; + ((uint_32t*)d)[1] ^= ((uint_32t*)s)[1]; + ((uint_32t*)d)[2] ^= ((uint_32t*)s)[2]; + ((uint_32t*)d)[3] ^= ((uint_32t*)s)[3]; #else - ((uint_8t*)d)[ 0] ^= ((uint_8t*)s)[ 0]; - ((uint_8t*)d)[ 1] ^= ((uint_8t*)s)[ 1]; - ((uint_8t*)d)[ 2] ^= ((uint_8t*)s)[ 2]; - ((uint_8t*)d)[ 3] ^= ((uint_8t*)s)[ 3]; - ((uint_8t*)d)[ 4] ^= ((uint_8t*)s)[ 4]; - ((uint_8t*)d)[ 5] ^= ((uint_8t*)s)[ 5]; - ((uint_8t*)d)[ 6] ^= ((uint_8t*)s)[ 6]; - ((uint_8t*)d)[ 7] ^= ((uint_8t*)s)[ 7]; - ((uint_8t*)d)[ 8] ^= ((uint_8t*)s)[ 8]; - ((uint_8t*)d)[ 9] ^= ((uint_8t*)s)[ 9]; - ((uint_8t*)d)[10] ^= ((uint_8t*)s)[10]; - ((uint_8t*)d)[11] ^= ((uint_8t*)s)[11]; - ((uint_8t*)d)[12] ^= ((uint_8t*)s)[12]; - ((uint_8t*)d)[13] ^= ((uint_8t*)s)[13]; - ((uint_8t*)d)[14] ^= ((uint_8t*)s)[14]; - ((uint_8t*)d)[15] ^= ((uint_8t*)s)[15]; + ((uint_8t*)d)[0] ^= ((uint_8t*)s)[0]; + ((uint_8t*)d)[1] ^= ((uint_8t*)s)[1]; + ((uint_8t*)d)[2] ^= ((uint_8t*)s)[2]; + ((uint_8t*)d)[3] ^= ((uint_8t*)s)[3]; + ((uint_8t*)d)[4] ^= ((uint_8t*)s)[4]; + ((uint_8t*)d)[5] ^= ((uint_8t*)s)[5]; + ((uint_8t*)d)[6] ^= ((uint_8t*)s)[6]; + ((uint_8t*)d)[7] ^= ((uint_8t*)s)[7]; + ((uint_8t*)d)[8] ^= ((uint_8t*)s)[8]; + ((uint_8t*)d)[9] ^= ((uint_8t*)s)[9]; + ((uint_8t*)d)[10] ^= ((uint_8t*)s)[10]; + ((uint_8t*)d)[11] ^= ((uint_8t*)s)[11]; + ((uint_8t*)d)[12] ^= ((uint_8t*)s)[12]; + ((uint_8t*)d)[13] ^= ((uint_8t*)s)[13]; + ((uint_8t*)d)[14] ^= ((uint_8t*)s)[14]; + ((uint_8t*)d)[15] ^= ((uint_8t*)s)[15]; #endif } -static void copy_and_key( void *d, const void *s, const void *k ) -{ -#if defined( HAVE_UINT_32T ) - ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0] ^ ((uint_32t*)k)[ 0]; - ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1] ^ ((uint_32t*)k)[ 1]; - ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2] ^ ((uint_32t*)k)[ 2]; - ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3] ^ ((uint_32t*)k)[ 3]; +static void copy_and_key(void* d, const void* s, const void* k) { +#if defined(HAVE_UINT_32T) + ((uint_32t*)d)[0] = ((uint_32t*)s)[0] ^ ((uint_32t*)k)[0]; + ((uint_32t*)d)[1] = ((uint_32t*)s)[1] ^ ((uint_32t*)k)[1]; + ((uint_32t*)d)[2] = ((uint_32t*)s)[2] ^ ((uint_32t*)k)[2]; + ((uint_32t*)d)[3] = ((uint_32t*)s)[3] ^ ((uint_32t*)k)[3]; #elif 1 - ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0] ^ ((uint_8t*)k)[ 0]; - ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1] ^ ((uint_8t*)k)[ 1]; - ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2] ^ ((uint_8t*)k)[ 2]; - ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3] ^ ((uint_8t*)k)[ 3]; - ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4] ^ ((uint_8t*)k)[ 4]; - ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5] ^ ((uint_8t*)k)[ 5]; - ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6] ^ ((uint_8t*)k)[ 6]; - ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7] ^ ((uint_8t*)k)[ 7]; - ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8] ^ ((uint_8t*)k)[ 8]; - ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9] ^ ((uint_8t*)k)[ 9]; - ((uint_8t*)d)[10] = ((uint_8t*)s)[10] ^ ((uint_8t*)k)[10]; - ((uint_8t*)d)[11] = ((uint_8t*)s)[11] ^ ((uint_8t*)k)[11]; - ((uint_8t*)d)[12] = ((uint_8t*)s)[12] ^ ((uint_8t*)k)[12]; - ((uint_8t*)d)[13] = ((uint_8t*)s)[13] ^ ((uint_8t*)k)[13]; - ((uint_8t*)d)[14] = ((uint_8t*)s)[14] ^ ((uint_8t*)k)[14]; - ((uint_8t*)d)[15] = ((uint_8t*)s)[15] ^ ((uint_8t*)k)[15]; + ((uint_8t*)d)[0] = ((uint_8t*)s)[0] ^ ((uint_8t*)k)[0]; + ((uint_8t*)d)[1] = ((uint_8t*)s)[1] ^ ((uint_8t*)k)[1]; + ((uint_8t*)d)[2] = ((uint_8t*)s)[2] ^ ((uint_8t*)k)[2]; + ((uint_8t*)d)[3] = ((uint_8t*)s)[3] ^ ((uint_8t*)k)[3]; + ((uint_8t*)d)[4] = ((uint_8t*)s)[4] ^ ((uint_8t*)k)[4]; + ((uint_8t*)d)[5] = ((uint_8t*)s)[5] ^ ((uint_8t*)k)[5]; + ((uint_8t*)d)[6] = ((uint_8t*)s)[6] ^ ((uint_8t*)k)[6]; + ((uint_8t*)d)[7] = ((uint_8t*)s)[7] ^ ((uint_8t*)k)[7]; + ((uint_8t*)d)[8] = ((uint_8t*)s)[8] ^ ((uint_8t*)k)[8]; + ((uint_8t*)d)[9] = ((uint_8t*)s)[9] ^ ((uint_8t*)k)[9]; + ((uint_8t*)d)[10] = ((uint_8t*)s)[10] ^ ((uint_8t*)k)[10]; + ((uint_8t*)d)[11] = ((uint_8t*)s)[11] ^ ((uint_8t*)k)[11]; + ((uint_8t*)d)[12] = ((uint_8t*)s)[12] ^ ((uint_8t*)k)[12]; + ((uint_8t*)d)[13] = ((uint_8t*)s)[13] ^ ((uint_8t*)k)[13]; + ((uint_8t*)d)[14] = ((uint_8t*)s)[14] ^ ((uint_8t*)k)[14]; + ((uint_8t*)d)[15] = ((uint_8t*)s)[15] ^ ((uint_8t*)k)[15]; #else - block_copy(d, s); - xor_block(d, k); + block_copy(d, s); + xor_block(d, k); #endif } -static void add_round_key( uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK] ) -{ - xor_block(d, k); +static void add_round_key(uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK]) { + xor_block(d, k); } -static void shift_sub_rows( uint_8t st[N_BLOCK] ) -{ uint_8t tt; - - st[ 0] = s_box(st[ 0]); st[ 4] = s_box(st[ 4]); - st[ 8] = s_box(st[ 8]); st[12] = s_box(st[12]); - - tt = st[1]; st[ 1] = s_box(st[ 5]); st[ 5] = s_box(st[ 9]); - st[ 9] = s_box(st[13]); st[13] = s_box( tt ); - - tt = st[2]; st[ 2] = s_box(st[10]); st[10] = s_box( tt ); - tt = st[6]; st[ 6] = s_box(st[14]); st[14] = s_box( tt ); - - tt = st[15]; st[15] = s_box(st[11]); st[11] = s_box(st[ 7]); - st[ 7] = s_box(st[ 3]); st[ 3] = s_box( tt ); +static void shift_sub_rows(uint_8t st[N_BLOCK]) { + uint_8t tt; + + st[0] = s_box(st[0]); + st[4] = s_box(st[4]); + st[8] = s_box(st[8]); + st[12] = s_box(st[12]); + + tt = st[1]; + st[1] = s_box(st[5]); + st[5] = s_box(st[9]); + st[9] = s_box(st[13]); + st[13] = s_box(tt); + + tt = st[2]; + st[2] = s_box(st[10]); + st[10] = s_box(tt); + tt = st[6]; + st[6] = s_box(st[14]); + st[14] = s_box(tt); + + tt = st[15]; + st[15] = s_box(st[11]); + st[11] = s_box(st[7]); + st[7] = s_box(st[3]); + st[3] = s_box(tt); } -static void inv_shift_sub_rows( uint_8t st[N_BLOCK] ) -{ uint_8t tt; - - st[ 0] = is_box(st[ 0]); st[ 4] = is_box(st[ 4]); - st[ 8] = is_box(st[ 8]); st[12] = is_box(st[12]); - - tt = st[13]; st[13] = is_box(st[9]); st[ 9] = is_box(st[5]); - st[ 5] = is_box(st[1]); st[ 1] = is_box( tt ); - - tt = st[2]; st[ 2] = is_box(st[10]); st[10] = is_box( tt ); - tt = st[6]; st[ 6] = is_box(st[14]); st[14] = is_box( tt ); - - tt = st[3]; st[ 3] = is_box(st[ 7]); st[ 7] = is_box(st[11]); - st[11] = is_box(st[15]); st[15] = is_box( tt ); +static void inv_shift_sub_rows(uint_8t st[N_BLOCK]) { + uint_8t tt; + + st[0] = is_box(st[0]); + st[4] = is_box(st[4]); + st[8] = is_box(st[8]); + st[12] = is_box(st[12]); + + tt = st[13]; + st[13] = is_box(st[9]); + st[9] = is_box(st[5]); + st[5] = is_box(st[1]); + st[1] = is_box(tt); + + tt = st[2]; + st[2] = is_box(st[10]); + st[10] = is_box(tt); + tt = st[6]; + st[6] = is_box(st[14]); + st[14] = is_box(tt); + + tt = st[3]; + st[3] = is_box(st[7]); + st[7] = is_box(st[11]); + st[11] = is_box(st[15]); + st[15] = is_box(tt); } -#if defined( VERSION_1 ) - static void mix_sub_columns( uint_8t dt[N_BLOCK] ) - { uint_8t st[N_BLOCK]; - block_copy(st, dt); +#if defined(VERSION_1) +static void mix_sub_columns(uint_8t dt[N_BLOCK]) { + uint_8t st[N_BLOCK]; + block_copy(st, dt); #else - static void mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] ) - { +static void mix_sub_columns(uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK]) { #endif - dt[ 0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]); - dt[ 1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]); - dt[ 2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]); - dt[ 3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]); - - dt[ 4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]); - dt[ 5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]); - dt[ 6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]); - dt[ 7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]); - - dt[ 8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]); - dt[ 9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]); - dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]); - dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]); - - dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]); - dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]); - dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]); - dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]); - } + dt[0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]); + dt[1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]); + dt[2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]); + dt[3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]); + + dt[4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]); + dt[5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]); + dt[6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]); + dt[7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]); + + dt[8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]); + dt[9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]); + dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]); + dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]); + + dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]); + dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]); + dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]); + dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]); +} -#if defined( VERSION_1 ) - static void inv_mix_sub_columns( uint_8t dt[N_BLOCK] ) - { uint_8t st[N_BLOCK]; - block_copy(st, dt); +#if defined(VERSION_1) +static void inv_mix_sub_columns(uint_8t dt[N_BLOCK]) { + uint_8t st[N_BLOCK]; + block_copy(st, dt); #else - static void inv_mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] ) - { +static void inv_mix_sub_columns(uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK]) { #endif - dt[ 0] = is_box(gfm_e(st[ 0]) ^ gfm_b(st[ 1]) ^ gfm_d(st[ 2]) ^ gfm_9(st[ 3])); - dt[ 5] = is_box(gfm_9(st[ 0]) ^ gfm_e(st[ 1]) ^ gfm_b(st[ 2]) ^ gfm_d(st[ 3])); - dt[10] = is_box(gfm_d(st[ 0]) ^ gfm_9(st[ 1]) ^ gfm_e(st[ 2]) ^ gfm_b(st[ 3])); - dt[15] = is_box(gfm_b(st[ 0]) ^ gfm_d(st[ 1]) ^ gfm_9(st[ 2]) ^ gfm_e(st[ 3])); - - dt[ 4] = is_box(gfm_e(st[ 4]) ^ gfm_b(st[ 5]) ^ gfm_d(st[ 6]) ^ gfm_9(st[ 7])); - dt[ 9] = is_box(gfm_9(st[ 4]) ^ gfm_e(st[ 5]) ^ gfm_b(st[ 6]) ^ gfm_d(st[ 7])); - dt[14] = is_box(gfm_d(st[ 4]) ^ gfm_9(st[ 5]) ^ gfm_e(st[ 6]) ^ gfm_b(st[ 7])); - dt[ 3] = is_box(gfm_b(st[ 4]) ^ gfm_d(st[ 5]) ^ gfm_9(st[ 6]) ^ gfm_e(st[ 7])); - - dt[ 8] = is_box(gfm_e(st[ 8]) ^ gfm_b(st[ 9]) ^ gfm_d(st[10]) ^ gfm_9(st[11])); - dt[13] = is_box(gfm_9(st[ 8]) ^ gfm_e(st[ 9]) ^ gfm_b(st[10]) ^ gfm_d(st[11])); - dt[ 2] = is_box(gfm_d(st[ 8]) ^ gfm_9(st[ 9]) ^ gfm_e(st[10]) ^ gfm_b(st[11])); - dt[ 7] = is_box(gfm_b(st[ 8]) ^ gfm_d(st[ 9]) ^ gfm_9(st[10]) ^ gfm_e(st[11])); - - dt[12] = is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15])); - dt[ 1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15])); - dt[ 6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15])); - dt[11] = is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15])); - } + dt[0] = is_box(gfm_e(st[0]) ^ gfm_b(st[1]) ^ gfm_d(st[2]) ^ gfm_9(st[3])); + dt[5] = is_box(gfm_9(st[0]) ^ gfm_e(st[1]) ^ gfm_b(st[2]) ^ gfm_d(st[3])); + dt[10] = is_box(gfm_d(st[0]) ^ gfm_9(st[1]) ^ gfm_e(st[2]) ^ gfm_b(st[3])); + dt[15] = is_box(gfm_b(st[0]) ^ gfm_d(st[1]) ^ gfm_9(st[2]) ^ gfm_e(st[3])); + + dt[4] = is_box(gfm_e(st[4]) ^ gfm_b(st[5]) ^ gfm_d(st[6]) ^ gfm_9(st[7])); + dt[9] = is_box(gfm_9(st[4]) ^ gfm_e(st[5]) ^ gfm_b(st[6]) ^ gfm_d(st[7])); + dt[14] = is_box(gfm_d(st[4]) ^ gfm_9(st[5]) ^ gfm_e(st[6]) ^ gfm_b(st[7])); + dt[3] = is_box(gfm_b(st[4]) ^ gfm_d(st[5]) ^ gfm_9(st[6]) ^ gfm_e(st[7])); + + dt[8] = is_box(gfm_e(st[8]) ^ gfm_b(st[9]) ^ gfm_d(st[10]) ^ gfm_9(st[11])); + dt[13] = is_box(gfm_9(st[8]) ^ gfm_e(st[9]) ^ gfm_b(st[10]) ^ gfm_d(st[11])); + dt[2] = is_box(gfm_d(st[8]) ^ gfm_9(st[9]) ^ gfm_e(st[10]) ^ gfm_b(st[11])); + dt[7] = is_box(gfm_b(st[8]) ^ gfm_d(st[9]) ^ gfm_9(st[10]) ^ gfm_e(st[11])); + + dt[12] = + is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15])); + dt[1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15])); + dt[6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15])); + dt[11] = + is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15])); +} -#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED ) +#if defined(AES_ENC_PREKEYED) || defined(AES_DEC_PREKEYED) /* Set the cipher key for the pre-keyed version */ /* NOTE: If the length_type used for the key length is an @@ -504,432 +539,415 @@ static void inv_shift_sub_rows( uint_8t st[N_BLOCK] ) 128, 192, 16, 24 and 32). */ -return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] ) -{ - uint_8t cc, rc, hi; +return_type aes_set_key(const unsigned char key[], length_type keylen, + aes_context ctx[1]) { + uint_8t cc, rc, hi; - switch( keylen ) - { + switch (keylen) { case 16: - case 128: /* length in bits (128 = 8*16) */ - keylen = 16; - break; + case 128: /* length in bits (128 = 8*16) */ + keylen = 16; + break; case 24: - case 192: /* length in bits (192 = 8*24) */ - keylen = 24; - break; + case 192: /* length in bits (192 = 8*24) */ + keylen = 24; + break; case 32: -/* case 256: length in bits (256 = 8*32) */ - keylen = 32; - break; + /* case 256: length in bits (256 = 8*32) */ + keylen = 32; + break; default: - ctx->rnd = 0; - return (return_type)-1; - } - block_copy_nn(ctx->ksch, key, keylen); - hi = (keylen + 28) << 2; - ctx->rnd = (hi >> 4) - 1; - for( cc = keylen, rc = 1; cc < hi; cc += 4 ) - { uint_8t tt, t0, t1, t2, t3; - - t0 = ctx->ksch[cc - 4]; - t1 = ctx->ksch[cc - 3]; - t2 = ctx->ksch[cc - 2]; - t3 = ctx->ksch[cc - 1]; - if( cc % keylen == 0 ) - { - tt = t0; - t0 = s_box(t1) ^ rc; - t1 = s_box(t2); - t2 = s_box(t3); - t3 = s_box(tt); - rc = f2(rc); - } - else if( keylen > 24 && cc % keylen == 16 ) - { - t0 = s_box(t0); - t1 = s_box(t1); - t2 = s_box(t2); - t3 = s_box(t3); - } - tt = cc - keylen; - ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0; - ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1; - ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2; - ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3; + ctx->rnd = 0; + return (return_type)-1; + } + block_copy_nn(ctx->ksch, key, keylen); + hi = (keylen + 28) << 2; + ctx->rnd = (hi >> 4) - 1; + for (cc = keylen, rc = 1; cc < hi; cc += 4) { + uint_8t tt, t0, t1, t2, t3; + + t0 = ctx->ksch[cc - 4]; + t1 = ctx->ksch[cc - 3]; + t2 = ctx->ksch[cc - 2]; + t3 = ctx->ksch[cc - 1]; + if (cc % keylen == 0) { + tt = t0; + t0 = s_box(t1) ^ rc; + t1 = s_box(t2); + t2 = s_box(t3); + t3 = s_box(tt); + rc = f2(rc); + } else if (keylen > 24 && cc % keylen == 16) { + t0 = s_box(t0); + t1 = s_box(t1); + t2 = s_box(t2); + t3 = s_box(t3); } - return 0; + tt = cc - keylen; + ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0; + ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1; + ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2; + ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3; + } + return 0; } #endif -#if defined( AES_ENC_PREKEYED ) +#if defined(AES_ENC_PREKEYED) /* Encrypt a single block of 16 bytes */ -return_type aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] ) -{ - if( ctx->rnd ) +return_type aes_encrypt(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], const aes_context ctx[1]) { + if (ctx->rnd) { + uint_8t s1[N_BLOCK], r; + copy_and_key(s1, in, ctx->ksch); + + for (r = 1; r < ctx->rnd; ++r) +#if defined(VERSION_1) { - uint_8t s1[N_BLOCK], r; - copy_and_key( s1, in, ctx->ksch ); - - for( r = 1 ; r < ctx->rnd ; ++r ) -#if defined( VERSION_1 ) - { - mix_sub_columns( s1 ); - add_round_key( s1, ctx->ksch + r * N_BLOCK); - } + mix_sub_columns(s1); + add_round_key(s1, ctx->ksch + r * N_BLOCK); + } #else - { uint_8t s2[N_BLOCK]; - mix_sub_columns( s2, s1 ); - copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK); - } -#endif - shift_sub_rows( s1 ); - copy_and_key( out, s1, ctx->ksch + r * N_BLOCK ); + { + uint_8t s2[N_BLOCK]; + mix_sub_columns(s2, s1); + copy_and_key(s1, s2, ctx->ksch + r * N_BLOCK); } - else - return (return_type)-1; - return 0; +#endif + shift_sub_rows(s1); + copy_and_key(out, s1, ctx->ksch + r * N_BLOCK); + } else + return (return_type)-1; + return 0; } /* CBC encrypt a number of blocks (input and return an IV) */ -return_type aes_cbc_encrypt( const unsigned char *in, unsigned char *out, - int n_block, unsigned char iv[N_BLOCK], const aes_context ctx[1] ) -{ - - while(n_block--) - { - xor_block(iv, in); - if(aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS) - return EXIT_FAILURE; - memcpy(out, iv, N_BLOCK); - in += N_BLOCK; - out += N_BLOCK; - } - return EXIT_SUCCESS; +return_type aes_cbc_encrypt(const unsigned char* in, unsigned char* out, + int n_block, unsigned char iv[N_BLOCK], + const aes_context ctx[1]) { + while (n_block--) { + xor_block(iv, in); + if (aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS) return EXIT_FAILURE; + memcpy(out, iv, N_BLOCK); + in += N_BLOCK; + out += N_BLOCK; + } + return EXIT_SUCCESS; } #endif -#if defined( AES_DEC_PREKEYED ) +#if defined(AES_DEC_PREKEYED) /* Decrypt a single block of 16 bytes */ -return_type aes_decrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] ) -{ - if( ctx->rnd ) +return_type aes_decrypt(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], const aes_context ctx[1]) { + if (ctx->rnd) { + uint_8t s1[N_BLOCK], r; + copy_and_key(s1, in, ctx->ksch + ctx->rnd * N_BLOCK); + inv_shift_sub_rows(s1); + + for (r = ctx->rnd; --r;) +#if defined(VERSION_1) { - uint_8t s1[N_BLOCK], r; - copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK ); - inv_shift_sub_rows( s1 ); - - for( r = ctx->rnd ; --r ; ) -#if defined( VERSION_1 ) - { - add_round_key( s1, ctx->ksch + r * N_BLOCK ); - inv_mix_sub_columns( s1 ); - } + add_round_key(s1, ctx->ksch + r * N_BLOCK); + inv_mix_sub_columns(s1); + } #else - { uint_8t s2[N_BLOCK]; - copy_and_key( s2, s1, ctx->ksch + r * N_BLOCK ); - inv_mix_sub_columns( s1, s2 ); - } -#endif - copy_and_key( out, s1, ctx->ksch ); + { + uint_8t s2[N_BLOCK]; + copy_and_key(s2, s1, ctx->ksch + r * N_BLOCK); + inv_mix_sub_columns(s1, s2); } - else - return (return_type)-1; - return 0; +#endif + copy_and_key(out, s1, ctx->ksch); + } else + return (return_type)-1; + return 0; } /* CBC decrypt a number of blocks (input and return an IV) */ -return_type aes_cbc_decrypt( const unsigned char *in, unsigned char *out, - int n_block, unsigned char iv[N_BLOCK], const aes_context ctx[1] ) -{ - while(n_block--) - { uint_8t tmp[N_BLOCK]; - - memcpy(tmp, in, N_BLOCK); - if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS) - return EXIT_FAILURE; - xor_block(out, iv); - memcpy(iv, tmp, N_BLOCK); - in += N_BLOCK; - out += N_BLOCK; - } - return EXIT_SUCCESS; +return_type aes_cbc_decrypt(const unsigned char* in, unsigned char* out, + int n_block, unsigned char iv[N_BLOCK], + const aes_context ctx[1]) { + while (n_block--) { + uint_8t tmp[N_BLOCK]; + + memcpy(tmp, in, N_BLOCK); + if (aes_decrypt(in, out, ctx) != EXIT_SUCCESS) return EXIT_FAILURE; + xor_block(out, iv); + memcpy(iv, tmp, N_BLOCK); + in += N_BLOCK; + out += N_BLOCK; + } + return EXIT_SUCCESS; } #endif -#if defined( AES_ENC_128_OTFK ) +#if defined(AES_ENC_128_OTFK) /* The 'on the fly' encryption key update for for 128 bit keys */ -static void update_encrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc ) -{ uint_8t cc; +static void update_encrypt_key_128(uint_8t k[N_BLOCK], uint_8t* rc) { + uint_8t cc; - k[0] ^= s_box(k[13]) ^ *rc; - k[1] ^= s_box(k[14]); - k[2] ^= s_box(k[15]); - k[3] ^= s_box(k[12]); - *rc = f2( *rc ); + k[0] ^= s_box(k[13]) ^ *rc; + k[1] ^= s_box(k[14]); + k[2] ^= s_box(k[15]); + k[3] ^= s_box(k[12]); + *rc = f2(*rc); - for(cc = 4; cc < 16; cc += 4 ) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } + for (cc = 4; cc < 16; cc += 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } } /* Encrypt a single block of 16 bytes with 'on the fly' 128 bit keying */ -void aes_encrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], - const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] ) -{ uint_8t s1[N_BLOCK], r, rc = 1; +void aes_encrypt_128(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[N_BLOCK], + unsigned char o_key[N_BLOCK]) { + uint_8t s1[N_BLOCK], r, rc = 1; - if(o_key != key) - block_copy( o_key, key ); - copy_and_key( s1, in, o_key ); + if (o_key != key) block_copy(o_key, key); + copy_and_key(s1, in, o_key); - for( r = 1 ; r < 10 ; ++r ) -#if defined( VERSION_1 ) - { - mix_sub_columns( s1 ); - update_encrypt_key_128( o_key, &rc ); - add_round_key( s1, o_key ); - } + for (r = 1; r < 10; ++r) +#if defined(VERSION_1) + { + mix_sub_columns(s1); + update_encrypt_key_128(o_key, &rc); + add_round_key(s1, o_key); + } #else - { uint_8t s2[N_BLOCK]; - mix_sub_columns( s2, s1 ); - update_encrypt_key_128( o_key, &rc ); - copy_and_key( s1, s2, o_key ); - } + { + uint_8t s2[N_BLOCK]; + mix_sub_columns(s2, s1); + update_encrypt_key_128(o_key, &rc); + copy_and_key(s1, s2, o_key); + } #endif - shift_sub_rows( s1 ); - update_encrypt_key_128( o_key, &rc ); - copy_and_key( out, s1, o_key ); + shift_sub_rows(s1); + update_encrypt_key_128(o_key, &rc); + copy_and_key(out, s1, o_key); } #endif -#if defined( AES_DEC_128_OTFK ) +#if defined(AES_DEC_128_OTFK) /* The 'on the fly' decryption key update for for 128 bit keys */ -static void update_decrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc ) -{ uint_8t cc; +static void update_decrypt_key_128(uint_8t k[N_BLOCK], uint_8t* rc) { + uint_8t cc; - for( cc = 12; cc > 0; cc -= 4 ) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } - *rc = d2(*rc); - k[0] ^= s_box(k[13]) ^ *rc; - k[1] ^= s_box(k[14]); - k[2] ^= s_box(k[15]); - k[3] ^= s_box(k[12]); + for (cc = 12; cc > 0; cc -= 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } + *rc = d2(*rc); + k[0] ^= s_box(k[13]) ^ *rc; + k[1] ^= s_box(k[14]); + k[2] ^= s_box(k[15]); + k[3] ^= s_box(k[12]); } /* Decrypt a single block of 16 bytes with 'on the fly' 128 bit keying */ -void aes_decrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], - const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] ) -{ - uint_8t s1[N_BLOCK], r, rc = 0x6c; - if(o_key != key) - block_copy( o_key, key ); +void aes_decrypt_128(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[N_BLOCK], + unsigned char o_key[N_BLOCK]) { + uint_8t s1[N_BLOCK], r, rc = 0x6c; + if (o_key != key) block_copy(o_key, key); - copy_and_key( s1, in, o_key ); - inv_shift_sub_rows( s1 ); + copy_and_key(s1, in, o_key); + inv_shift_sub_rows(s1); - for( r = 10 ; --r ; ) -#if defined( VERSION_1 ) - { - update_decrypt_key_128( o_key, &rc ); - add_round_key( s1, o_key ); - inv_mix_sub_columns( s1 ); - } + for (r = 10; --r;) +#if defined(VERSION_1) + { + update_decrypt_key_128(o_key, &rc); + add_round_key(s1, o_key); + inv_mix_sub_columns(s1); + } #else - { uint_8t s2[N_BLOCK]; - update_decrypt_key_128( o_key, &rc ); - copy_and_key( s2, s1, o_key ); - inv_mix_sub_columns( s1, s2 ); - } + { + uint_8t s2[N_BLOCK]; + update_decrypt_key_128(o_key, &rc); + copy_and_key(s2, s1, o_key); + inv_mix_sub_columns(s1, s2); + } #endif - update_decrypt_key_128( o_key, &rc ); - copy_and_key( out, s1, o_key ); + update_decrypt_key_128(o_key, &rc); + copy_and_key(out, s1, o_key); } #endif -#if defined( AES_ENC_256_OTFK ) +#if defined(AES_ENC_256_OTFK) /* The 'on the fly' encryption key update for for 256 bit keys */ -static void update_encrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc ) -{ uint_8t cc; +static void update_encrypt_key_256(uint_8t k[2 * N_BLOCK], uint_8t* rc) { + uint_8t cc; - k[0] ^= s_box(k[29]) ^ *rc; - k[1] ^= s_box(k[30]); - k[2] ^= s_box(k[31]); - k[3] ^= s_box(k[28]); - *rc = f2( *rc ); + k[0] ^= s_box(k[29]) ^ *rc; + k[1] ^= s_box(k[30]); + k[2] ^= s_box(k[31]); + k[3] ^= s_box(k[28]); + *rc = f2(*rc); - for(cc = 4; cc < 16; cc += 4) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } + for (cc = 4; cc < 16; cc += 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } - k[16] ^= s_box(k[12]); - k[17] ^= s_box(k[13]); - k[18] ^= s_box(k[14]); - k[19] ^= s_box(k[15]); + k[16] ^= s_box(k[12]); + k[17] ^= s_box(k[13]); + k[18] ^= s_box(k[14]); + k[19] ^= s_box(k[15]); - for( cc = 20; cc < 32; cc += 4 ) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } + for (cc = 20; cc < 32; cc += 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } } /* Encrypt a single block of 16 bytes with 'on the fly' 256 bit keying */ -void aes_encrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], - const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] ) -{ - uint_8t s1[N_BLOCK], r, rc = 1; - if(o_key != key) - { - block_copy( o_key, key ); - block_copy( o_key + 16, key + 16 ); - } - copy_and_key( s1, in, o_key ); +void aes_encrypt_256(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[2 * N_BLOCK], + unsigned char o_key[2 * N_BLOCK]) { + uint_8t s1[N_BLOCK], r, rc = 1; + if (o_key != key) { + block_copy(o_key, key); + block_copy(o_key + 16, key + 16); + } + copy_and_key(s1, in, o_key); - for( r = 1 ; r < 14 ; ++r ) -#if defined( VERSION_1 ) - { - mix_sub_columns(s1); - if( r & 1 ) - add_round_key( s1, o_key + 16 ); - else - { - update_encrypt_key_256( o_key, &rc ); - add_round_key( s1, o_key ); - } + for (r = 1; r < 14; ++r) +#if defined(VERSION_1) + { + mix_sub_columns(s1); + if (r & 1) + add_round_key(s1, o_key + 16); + else { + update_encrypt_key_256(o_key, &rc); + add_round_key(s1, o_key); } + } #else - { uint_8t s2[N_BLOCK]; - mix_sub_columns( s2, s1 ); - if( r & 1 ) - copy_and_key( s1, s2, o_key + 16 ); - else - { - update_encrypt_key_256( o_key, &rc ); - copy_and_key( s1, s2, o_key ); - } + { + uint_8t s2[N_BLOCK]; + mix_sub_columns(s2, s1); + if (r & 1) + copy_and_key(s1, s2, o_key + 16); + else { + update_encrypt_key_256(o_key, &rc); + copy_and_key(s1, s2, o_key); } + } #endif - shift_sub_rows( s1 ); - update_encrypt_key_256( o_key, &rc ); - copy_and_key( out, s1, o_key ); + shift_sub_rows(s1); + update_encrypt_key_256(o_key, &rc); + copy_and_key(out, s1, o_key); } #endif -#if defined( AES_DEC_256_OTFK ) +#if defined(AES_DEC_256_OTFK) /* The 'on the fly' encryption key update for for 256 bit keys */ -static void update_decrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc ) -{ uint_8t cc; +static void update_decrypt_key_256(uint_8t k[2 * N_BLOCK], uint_8t* rc) { + uint_8t cc; - for(cc = 28; cc > 16; cc -= 4) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } + for (cc = 28; cc > 16; cc -= 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } - k[16] ^= s_box(k[12]); - k[17] ^= s_box(k[13]); - k[18] ^= s_box(k[14]); - k[19] ^= s_box(k[15]); + k[16] ^= s_box(k[12]); + k[17] ^= s_box(k[13]); + k[18] ^= s_box(k[14]); + k[19] ^= s_box(k[15]); - for(cc = 12; cc > 0; cc -= 4) - { - k[cc + 0] ^= k[cc - 4]; - k[cc + 1] ^= k[cc - 3]; - k[cc + 2] ^= k[cc - 2]; - k[cc + 3] ^= k[cc - 1]; - } + for (cc = 12; cc > 0; cc -= 4) { + k[cc + 0] ^= k[cc - 4]; + k[cc + 1] ^= k[cc - 3]; + k[cc + 2] ^= k[cc - 2]; + k[cc + 3] ^= k[cc - 1]; + } - *rc = d2(*rc); - k[0] ^= s_box(k[29]) ^ *rc; - k[1] ^= s_box(k[30]); - k[2] ^= s_box(k[31]); - k[3] ^= s_box(k[28]); + *rc = d2(*rc); + k[0] ^= s_box(k[29]) ^ *rc; + k[1] ^= s_box(k[30]); + k[2] ^= s_box(k[31]); + k[3] ^= s_box(k[28]); } /* Decrypt a single block of 16 bytes with 'on the fly' 256 bit keying */ -void aes_decrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], - const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] ) -{ - uint_8t s1[N_BLOCK], r, rc = 0x80; - - if(o_key != key) - { - block_copy( o_key, key ); - block_copy( o_key + 16, key + 16 ); - } +void aes_decrypt_256(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[2 * N_BLOCK], + unsigned char o_key[2 * N_BLOCK]) { + uint_8t s1[N_BLOCK], r, rc = 0x80; + + if (o_key != key) { + block_copy(o_key, key); + block_copy(o_key + 16, key + 16); + } - copy_and_key( s1, in, o_key ); - inv_shift_sub_rows( s1 ); + copy_and_key(s1, in, o_key); + inv_shift_sub_rows(s1); - for( r = 14 ; --r ; ) -#if defined( VERSION_1 ) - { - if( ( r & 1 ) ) - { - update_decrypt_key_256( o_key, &rc ); - add_round_key( s1, o_key + 16 ); - } - else - add_round_key( s1, o_key ); - inv_mix_sub_columns( s1 ); - } + for (r = 14; --r;) +#if defined(VERSION_1) + { + if ((r & 1)) { + update_decrypt_key_256(o_key, &rc); + add_round_key(s1, o_key + 16); + } else + add_round_key(s1, o_key); + inv_mix_sub_columns(s1); + } #else - { uint_8t s2[N_BLOCK]; - if( ( r & 1 ) ) - { - update_decrypt_key_256( o_key, &rc ); - copy_and_key( s2, s1, o_key + 16 ); - } - else - copy_and_key( s2, s1, o_key ); - inv_mix_sub_columns( s1, s2 ); - } + { + uint_8t s2[N_BLOCK]; + if ((r & 1)) { + update_decrypt_key_256(o_key, &rc); + copy_and_key(s2, s1, o_key + 16); + } else + copy_and_key(s2, s1, o_key); + inv_mix_sub_columns(s1, s2); + } #endif - copy_and_key( out, s1, o_key ); + copy_and_key(out, s1, o_key); } #endif diff --git a/stack/smp/aes.h b/stack/smp/aes.h index dcfde93c0..2ff6fbde0 100644 --- a/stack/smp/aes.h +++ b/stack/smp/aes.h @@ -32,28 +32,28 @@ #define AES_H #if 1 -# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */ +#define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */ #endif #if 1 -# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */ +#define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */ #endif #if 1 -# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */ +#define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */ #endif #if 1 -# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */ +#define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */ #endif #if 1 -# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */ +#define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */ #endif #if 1 -# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */ +#define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */ #endif -#define N_ROW 4 -#define N_COL 4 -#define N_BLOCK (N_ROW * N_COL) -#define N_MAX_ROUNDS 14 +#define N_ROW 4 +#define N_COL 4 +#define N_BLOCK (N_ROW * N_COL) +#define N_MAX_ROUNDS 14 typedef unsigned char uint_8t; @@ -65,9 +65,9 @@ typedef uint_8t return_type; typedef uint_8t length_type; -typedef struct -{ uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK]; - uint_8t rnd; +typedef struct { + uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK]; + uint_8t rnd; } aes_context; /* The following calls are for a precomputed key schedule @@ -78,37 +78,30 @@ typedef struct 128, 192, 16, 24 and 32). */ -#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED ) +#if defined(AES_ENC_PREKEYED) || defined(AES_DEC_PREKEYED) -return_type aes_set_key( const unsigned char key[], - length_type keylen, - aes_context ctx[1] ); +return_type aes_set_key(const unsigned char key[], length_type keylen, + aes_context ctx[1]); #endif -#if defined( AES_ENC_PREKEYED ) +#if defined(AES_ENC_PREKEYED) -return_type aes_encrypt( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const aes_context ctx[1] ); +return_type aes_encrypt(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], const aes_context ctx[1]); -return_type aes_cbc_encrypt( const unsigned char *in, - unsigned char *out, - int n_block, - unsigned char iv[N_BLOCK], - const aes_context ctx[1] ); +return_type aes_cbc_encrypt(const unsigned char* in, unsigned char* out, + int n_block, unsigned char iv[N_BLOCK], + const aes_context ctx[1]); #endif -#if defined( AES_DEC_PREKEYED ) +#if defined(AES_DEC_PREKEYED) -return_type aes_decrypt( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const aes_context ctx[1] ); +return_type aes_decrypt(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], const aes_context ctx[1]); -return_type aes_cbc_decrypt( const unsigned char *in, - unsigned char *out, - int n_block, - unsigned char iv[N_BLOCK], - const aes_context ctx[1] ); +return_type aes_cbc_decrypt(const unsigned char* in, unsigned char* out, + int n_block, unsigned char iv[N_BLOCK], + const aes_context ctx[1]); #endif /* The following calls are for 'on the fly' keying. In this case the @@ -131,32 +124,31 @@ return_type aes_cbc_decrypt( const unsigned char *in, modes. */ -#if defined( AES_ENC_128_OTFK ) -void aes_encrypt_128( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const unsigned char key[N_BLOCK], - uint_8t o_key[N_BLOCK] ); +#if defined(AES_ENC_128_OTFK) +void aes_encrypt_128(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[N_BLOCK], uint_8t o_key[N_BLOCK]); #endif -#if defined( AES_DEC_128_OTFK ) -void aes_decrypt_128( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const unsigned char key[N_BLOCK], - unsigned char o_key[N_BLOCK] ); +#if defined(AES_DEC_128_OTFK) +void aes_decrypt_128(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[N_BLOCK], + unsigned char o_key[N_BLOCK]); #endif -#if defined( AES_ENC_256_OTFK ) -void aes_encrypt_256( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const unsigned char key[2 * N_BLOCK], - unsigned char o_key[2 * N_BLOCK] ); +#if defined(AES_ENC_256_OTFK) +void aes_encrypt_256(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[2 * N_BLOCK], + unsigned char o_key[2 * N_BLOCK]); #endif -#if defined( AES_DEC_256_OTFK ) -void aes_decrypt_256( const unsigned char in[N_BLOCK], - unsigned char out[N_BLOCK], - const unsigned char key[2 * N_BLOCK], - unsigned char o_key[2 * N_BLOCK] ); +#if defined(AES_DEC_256_OTFK) +void aes_decrypt_256(const unsigned char in[N_BLOCK], + unsigned char out[N_BLOCK], + const unsigned char key[2 * N_BLOCK], + unsigned char o_key[2 * N_BLOCK]); #endif #endif diff --git a/stack/smp/p_256_curvepara.cc b/stack/smp/p_256_curvepara.cc index 3a8ef30d9..d9bee31d1 100644 --- a/stack/smp/p_256_curvepara.cc +++ b/stack/smp/p_256_curvepara.cc @@ -25,56 +25,53 @@ #include #include "p_256_ecc_pp.h" -void p_256_init_curve(uint32_t keyLength) -{ - elliptic_curve_t *ec; +void p_256_init_curve(uint32_t keyLength) { + elliptic_curve_t* ec; - if(keyLength == KEY_LENGTH_DWORDS_P256) - { - ec = &curve_p256; + if (keyLength == KEY_LENGTH_DWORDS_P256) { + ec = &curve_p256; - ec->p[7] = 0xFFFFFFFF; - ec->p[6] = 0x00000001; - ec->p[5] = 0x0; - ec->p[4] = 0x0; - ec->p[3] = 0x0; - ec->p[2] = 0xFFFFFFFF; - ec->p[1] = 0xFFFFFFFF; - ec->p[0] = 0xFFFFFFFF; + ec->p[7] = 0xFFFFFFFF; + ec->p[6] = 0x00000001; + ec->p[5] = 0x0; + ec->p[4] = 0x0; + ec->p[3] = 0x0; + ec->p[2] = 0xFFFFFFFF; + ec->p[1] = 0xFFFFFFFF; + ec->p[0] = 0xFFFFFFFF; - memset(ec->omega, 0, KEY_LENGTH_DWORDS_P256); - memset(ec->a, 0, KEY_LENGTH_DWORDS_P256); + memset(ec->omega, 0, KEY_LENGTH_DWORDS_P256); + memset(ec->a, 0, KEY_LENGTH_DWORDS_P256); - ec->a_minus3 = true; + ec->a_minus3 = true; - //b - ec->b[7] = 0x5ac635d8; - ec->b[6] = 0xaa3a93e7; - ec->b[5] = 0xb3ebbd55; - ec->b[4] = 0x769886bc; - ec->b[3] = 0x651d06b0; - ec->b[2] = 0xcc53b0f6; - ec->b[1] = 0x3bce3c3e; - ec->b[0] = 0x27d2604b; + // b + ec->b[7] = 0x5ac635d8; + ec->b[6] = 0xaa3a93e7; + ec->b[5] = 0xb3ebbd55; + ec->b[4] = 0x769886bc; + ec->b[3] = 0x651d06b0; + ec->b[2] = 0xcc53b0f6; + ec->b[1] = 0x3bce3c3e; + ec->b[0] = 0x27d2604b; - //base point - ec->G.x[7] = 0x6b17d1f2; - ec->G.x[6] = 0xe12c4247; - ec->G.x[5] = 0xf8bce6e5; - ec->G.x[4] = 0x63a440f2; - ec->G.x[3] = 0x77037d81; - ec->G.x[2] = 0x2deb33a0; - ec->G.x[1] = 0xf4a13945; - ec->G.x[0] = 0xd898c296; + // base point + ec->G.x[7] = 0x6b17d1f2; + ec->G.x[6] = 0xe12c4247; + ec->G.x[5] = 0xf8bce6e5; + ec->G.x[4] = 0x63a440f2; + ec->G.x[3] = 0x77037d81; + ec->G.x[2] = 0x2deb33a0; + ec->G.x[1] = 0xf4a13945; + ec->G.x[0] = 0xd898c296; - ec->G.y[7] = 0x4fe342e2; - ec->G.y[6] = 0xfe1a7f9b; - ec->G.y[5] = 0x8ee7eb4a; - ec->G.y[4] = 0x7c0f9e16; - ec->G.y[3] = 0x2bce3357; - ec->G.y[2] = 0x6b315ece; - ec->G.y[1] = 0xcbb64068; - ec->G.y[0] = 0x37bf51f5; - } + ec->G.y[7] = 0x4fe342e2; + ec->G.y[6] = 0xfe1a7f9b; + ec->G.y[5] = 0x8ee7eb4a; + ec->G.y[4] = 0x7c0f9e16; + ec->G.y[3] = 0x2bce3357; + ec->G.y[2] = 0x6b315ece; + ec->G.y[1] = 0xcbb64068; + ec->G.y[0] = 0x37bf51f5; + } } - diff --git a/stack/smp/p_256_ecc_pp.cc b/stack/smp/p_256_ecc_pp.cc index 3fc1a5b60..b416e1d3f 100644 --- a/stack/smp/p_256_ecc_pp.cc +++ b/stack/smp/p_256_ecc_pp.cc @@ -22,242 +22,226 @@ * Cryptography for private public key * ******************************************************************************/ +#include "p_256_ecc_pp.h" #include #include #include -#include "p_256_ecc_pp.h" #include "p_256_multprecision.h" elliptic_curve_t curve; elliptic_curve_t curve_p256; -static void p_256_init_point(Point *q) -{ - memset(q, 0, sizeof(Point)); -} +static void p_256_init_point(Point* q) { memset(q, 0, sizeof(Point)); } -static void p_256_copy_point(Point *q, Point *p) -{ - memcpy(q, p, sizeof(Point)); +static void p_256_copy_point(Point* q, Point* p) { + memcpy(q, p, sizeof(Point)); } // q=2q -static void ECC_Double(Point *q, Point *p, uint32_t keyLength) -{ - uint32_t t1[KEY_LENGTH_DWORDS_P256]; - uint32_t t2[KEY_LENGTH_DWORDS_P256]; - uint32_t t3[KEY_LENGTH_DWORDS_P256]; - uint32_t *x1; - uint32_t *x3; - uint32_t *y1; - uint32_t *y3; - uint32_t *z1; - uint32_t *z3; - - if (multiprecision_iszero(p->z, keyLength)) - { - multiprecision_init(q->z, keyLength); - return; // return infinity - } - - x1=p->x; y1=p->y; z1=p->z; - x3=q->x; y3=q->y; z3=q->z; - - multiprecision_mersenns_squa_mod(t1, z1, keyLength); // t1=z1^2 - multiprecision_sub_mod(t2, x1, t1, keyLength); // t2=x1-t1 - multiprecision_add_mod(t1, x1, t1, keyLength); // t1=x1+t1 - multiprecision_mersenns_mult_mod(t2, t1, t2, keyLength); // t2=t2*t1 - multiprecision_lshift_mod(t3, t2, keyLength); - multiprecision_add_mod(t2, t3, t2, keyLength); // t2=3t2 - - multiprecision_mersenns_mult_mod(z3, y1, z1, keyLength); // z3=y1*z1 - multiprecision_lshift_mod(z3, z3, keyLength); - - multiprecision_mersenns_squa_mod(y3, y1, keyLength); // y3=y1^2 - multiprecision_lshift_mod(y3, y3, keyLength); - multiprecision_mersenns_mult_mod(t3, y3, x1, keyLength); // t3=y3*x1=x1*y1^2 - multiprecision_lshift_mod(t3, t3, keyLength); - multiprecision_mersenns_squa_mod(y3, y3, keyLength); // y3=y3^2=y1^4 - multiprecision_lshift_mod(y3, y3, keyLength); - - multiprecision_mersenns_squa_mod(x3, t2, keyLength); // x3=t2^2 - multiprecision_lshift_mod(t1, t3, keyLength); // t1=2t3 - multiprecision_sub_mod(x3, x3, t1, keyLength); // x3=x3-t1 - multiprecision_sub_mod(t1, t3, x3, keyLength); // t1=t3-x3 - multiprecision_mersenns_mult_mod(t1, t1, t2, keyLength); // t1=t1*t2 - multiprecision_sub_mod(y3, t1, y3, keyLength); // y3=t1-y3 +static void ECC_Double(Point* q, Point* p, uint32_t keyLength) { + uint32_t t1[KEY_LENGTH_DWORDS_P256]; + uint32_t t2[KEY_LENGTH_DWORDS_P256]; + uint32_t t3[KEY_LENGTH_DWORDS_P256]; + uint32_t* x1; + uint32_t* x3; + uint32_t* y1; + uint32_t* y3; + uint32_t* z1; + uint32_t* z3; + + if (multiprecision_iszero(p->z, keyLength)) { + multiprecision_init(q->z, keyLength); + return; // return infinity + } + + x1 = p->x; + y1 = p->y; + z1 = p->z; + x3 = q->x; + y3 = q->y; + z3 = q->z; + + multiprecision_mersenns_squa_mod(t1, z1, keyLength); // t1=z1^2 + multiprecision_sub_mod(t2, x1, t1, keyLength); // t2=x1-t1 + multiprecision_add_mod(t1, x1, t1, keyLength); // t1=x1+t1 + multiprecision_mersenns_mult_mod(t2, t1, t2, keyLength); // t2=t2*t1 + multiprecision_lshift_mod(t3, t2, keyLength); + multiprecision_add_mod(t2, t3, t2, keyLength); // t2=3t2 + + multiprecision_mersenns_mult_mod(z3, y1, z1, keyLength); // z3=y1*z1 + multiprecision_lshift_mod(z3, z3, keyLength); + + multiprecision_mersenns_squa_mod(y3, y1, keyLength); // y3=y1^2 + multiprecision_lshift_mod(y3, y3, keyLength); + multiprecision_mersenns_mult_mod(t3, y3, x1, keyLength); // t3=y3*x1=x1*y1^2 + multiprecision_lshift_mod(t3, t3, keyLength); + multiprecision_mersenns_squa_mod(y3, y3, keyLength); // y3=y3^2=y1^4 + multiprecision_lshift_mod(y3, y3, keyLength); + + multiprecision_mersenns_squa_mod(x3, t2, keyLength); // x3=t2^2 + multiprecision_lshift_mod(t1, t3, keyLength); // t1=2t3 + multiprecision_sub_mod(x3, x3, t1, keyLength); // x3=x3-t1 + multiprecision_sub_mod(t1, t3, x3, keyLength); // t1=t3-x3 + multiprecision_mersenns_mult_mod(t1, t1, t2, keyLength); // t1=t1*t2 + multiprecision_sub_mod(y3, t1, y3, keyLength); // y3=t1-y3 } // q=q+p, zp must be 1 -static void ECC_Add(Point *r, Point *p, Point *q, uint32_t keyLength) -{ - uint32_t t1[KEY_LENGTH_DWORDS_P256]; - uint32_t t2[KEY_LENGTH_DWORDS_P256]; - uint32_t *x1; - uint32_t *x2; - uint32_t *x3; - uint32_t *y1; - uint32_t *y2; - uint32_t *y3; - uint32_t *z1; - uint32_t *z2; - uint32_t *z3; - - x1=p->x; y1=p->y; z1=p->z; - x2=q->x; y2=q->y; z2=q->z; - x3=r->x; y3=r->y; z3=r->z; - - // if Q=infinity, return p - if (multiprecision_iszero(z2, keyLength)) - { - p_256_copy_point(r, p); - return; - } - - // if P=infinity, return q - if (multiprecision_iszero(z1, keyLength)) - { - p_256_copy_point(r, q); - return; +static void ECC_Add(Point* r, Point* p, Point* q, uint32_t keyLength) { + uint32_t t1[KEY_LENGTH_DWORDS_P256]; + uint32_t t2[KEY_LENGTH_DWORDS_P256]; + uint32_t* x1; + uint32_t* x2; + uint32_t* x3; + uint32_t* y1; + uint32_t* y2; + uint32_t* y3; + uint32_t* z1; + uint32_t* z2; + uint32_t* z3; + + x1 = p->x; + y1 = p->y; + z1 = p->z; + x2 = q->x; + y2 = q->y; + z2 = q->z; + x3 = r->x; + y3 = r->y; + z3 = r->z; + + // if Q=infinity, return p + if (multiprecision_iszero(z2, keyLength)) { + p_256_copy_point(r, p); + return; + } + + // if P=infinity, return q + if (multiprecision_iszero(z1, keyLength)) { + p_256_copy_point(r, q); + return; + } + + multiprecision_mersenns_squa_mod(t1, z1, keyLength); // t1=z1^2 + multiprecision_mersenns_mult_mod(t2, z1, t1, keyLength); // t2=t1*z1 + multiprecision_mersenns_mult_mod(t1, x2, t1, keyLength); // t1=t1*x2 + multiprecision_mersenns_mult_mod(t2, y2, t2, keyLength); // t2=t2*y2 + + multiprecision_sub_mod(t1, t1, x1, keyLength); // t1=t1-x1 + multiprecision_sub_mod(t2, t2, y1, keyLength); // t2=t2-y1 + + if (multiprecision_iszero(t1, keyLength)) { + if (multiprecision_iszero(t2, keyLength)) { + ECC_Double(r, q, keyLength); + return; + } else { + multiprecision_init(z3, keyLength); + return; // return infinity } - - multiprecision_mersenns_squa_mod(t1, z1, keyLength); // t1=z1^2 - multiprecision_mersenns_mult_mod(t2, z1, t1, keyLength); // t2=t1*z1 - multiprecision_mersenns_mult_mod(t1, x2, t1, keyLength); // t1=t1*x2 - multiprecision_mersenns_mult_mod(t2, y2, t2, keyLength); // t2=t2*y2 - - multiprecision_sub_mod(t1, t1, x1, keyLength); // t1=t1-x1 - multiprecision_sub_mod(t2, t2, y1, keyLength); // t2=t2-y1 - - if (multiprecision_iszero(t1, keyLength)) - { - if (multiprecision_iszero(t2, keyLength)) - { - ECC_Double(r, q, keyLength) ; - return; - } - else - { - multiprecision_init(z3, keyLength); - return; // return infinity - } - } - - multiprecision_mersenns_mult_mod(z3, z1, t1, keyLength); // z3=z1*t1 - multiprecision_mersenns_squa_mod(y3, t1, keyLength); // t3=t1^2 - multiprecision_mersenns_mult_mod(z1, y3, t1, keyLength); // t4=t3*t1 - multiprecision_mersenns_mult_mod(y3, y3, x1, keyLength); // t3=t3*x1 - multiprecision_lshift_mod(t1, y3, keyLength); // t1=2*t3 - multiprecision_mersenns_squa_mod(x3, t2, keyLength); // x3=t2^2 - multiprecision_sub_mod(x3, x3, t1, keyLength); // x3=x3-t1 - multiprecision_sub_mod(x3, x3, z1, keyLength); // x3=x3-t4 - multiprecision_sub_mod(y3, y3, x3, keyLength); // t3=t3-x3 - multiprecision_mersenns_mult_mod(y3, y3, t2, keyLength); // t3=t3*t2 - multiprecision_mersenns_mult_mod(z1, z1, y1, keyLength); // t4=t4*t1 - multiprecision_sub_mod(y3, y3, z1, keyLength); + } + + multiprecision_mersenns_mult_mod(z3, z1, t1, keyLength); // z3=z1*t1 + multiprecision_mersenns_squa_mod(y3, t1, keyLength); // t3=t1^2 + multiprecision_mersenns_mult_mod(z1, y3, t1, keyLength); // t4=t3*t1 + multiprecision_mersenns_mult_mod(y3, y3, x1, keyLength); // t3=t3*x1 + multiprecision_lshift_mod(t1, y3, keyLength); // t1=2*t3 + multiprecision_mersenns_squa_mod(x3, t2, keyLength); // x3=t2^2 + multiprecision_sub_mod(x3, x3, t1, keyLength); // x3=x3-t1 + multiprecision_sub_mod(x3, x3, z1, keyLength); // x3=x3-t4 + multiprecision_sub_mod(y3, y3, x3, keyLength); // t3=t3-x3 + multiprecision_mersenns_mult_mod(y3, y3, t2, keyLength); // t3=t3*t2 + multiprecision_mersenns_mult_mod(z1, z1, y1, keyLength); // t4=t4*t1 + multiprecision_sub_mod(y3, y3, z1, keyLength); } // Computing the Non-Adjacent Form of a positive integer -static void ECC_NAF(uint8_t *naf, uint32_t *NumNAF, uint32_t *k, uint32_t keyLength) -{ - uint32_t sign; - int i=0; - int j; - uint32_t var; - - while ((var = multiprecision_most_signbits(k, keyLength))>=1) +static void ECC_NAF(uint8_t* naf, uint32_t* NumNAF, uint32_t* k, + uint32_t keyLength) { + uint32_t sign; + int i = 0; + int j; + uint32_t var; + + while ((var = multiprecision_most_signbits(k, keyLength)) >= 1) { + if (k[0] & 0x01) // k is odd { - if (k[0] & 0x01) // k is odd + sign = (k[0] & 0x03); // 1 or 3 + + // k = k-naf[i] + if (sign == 1) + k[0] = k[0] & 0xFFFFFFFE; + else { + k[0] = k[0] + 1; + if (k[0] == 0) // overflow { - sign = (k[0] & 0x03); // 1 or 3 - - // k = k-naf[i] - if (sign == 1) - k[0] = k[0] & 0xFFFFFFFE; - else - { - k[0] = k[0] + 1; - if (k[0] == 0) //overflow - { - j = 1; - do - { - k[j]++; - } while (k[j++]==0); //overflow - } - } + j = 1; + do { + k[j]++; + } while (k[j++] == 0); // overflow } - else - sign = 0; + } + } else + sign = 0; - multiprecision_rshift(k, k, keyLength); - naf[i / 4] |= (sign) << ((i % 4) * 2); - i++; - } + multiprecision_rshift(k, k, keyLength); + naf[i / 4] |= (sign) << ((i % 4) * 2); + i++; + } - *NumNAF=i; + *NumNAF = i; } // Binary Non-Adjacent Form for point multiplication -void ECC_PointMult_Bin_NAF(Point *q, Point *p, uint32_t *n, uint32_t keyLength) -{ - uint32_t sign; - uint8_t naf[256 / 4 +1]; - uint32_t NumNaf; - Point minus_p; - Point r; - uint32_t *modp; - - if (keyLength == KEY_LENGTH_DWORDS_P256) - { - modp = curve_p256.p; +void ECC_PointMult_Bin_NAF(Point* q, Point* p, uint32_t* n, + uint32_t keyLength) { + uint32_t sign; + uint8_t naf[256 / 4 + 1]; + uint32_t NumNaf; + Point minus_p; + Point r; + uint32_t* modp; + + if (keyLength == KEY_LENGTH_DWORDS_P256) { + modp = curve_p256.p; + } else { + modp = curve.p; + } + + p_256_init_point(&r); + multiprecision_init(p->z, keyLength); + p->z[0] = 1; + + // initialization + p_256_init_point(q); + + // -p + multiprecision_copy(minus_p.x, p->x, keyLength); + multiprecision_sub(minus_p.y, modp, p->y, keyLength); + + multiprecision_init(minus_p.z, keyLength); + minus_p.z[0] = 1; + + // NAF + memset(naf, 0, sizeof(naf)); + ECC_NAF(naf, &NumNaf, n, keyLength); + + for (int i = NumNaf - 1; i >= 0; i--) { + p_256_copy_point(&r, q); + ECC_Double(q, &r, keyLength); + sign = (naf[i / 4] >> ((i % 4) * 2)) & 0x03; + + if (sign == 1) { + p_256_copy_point(&r, q); + ECC_Add(q, &r, p, keyLength); + } else if (sign == 3) { + p_256_copy_point(&r, q); + ECC_Add(q, &r, &minus_p, keyLength); } - else - { - modp = curve.p; - } - - p_256_init_point(&r); - multiprecision_init(p->z, keyLength); - p->z[0] = 1; + } - // initialization - p_256_init_point(q); - - // -p - multiprecision_copy(minus_p.x, p->x, keyLength); - multiprecision_sub(minus_p.y, modp, p->y, keyLength); - - multiprecision_init(minus_p.z, keyLength); - minus_p.z[0]=1; - - // NAF - memset(naf, 0, sizeof(naf)); - ECC_NAF(naf, &NumNaf, n, keyLength); - - for (int i = NumNaf - 1; i >= 0; i--) - { - p_256_copy_point(&r, q); - ECC_Double(q, &r, keyLength); - sign = (naf[i / 4] >> ((i % 4) * 2)) & 0x03; - - if (sign == 1) - { - p_256_copy_point(&r, q); - ECC_Add(q, &r, p, keyLength); - } - else if (sign == 3) - { - p_256_copy_point(&r, q); - ECC_Add(q, &r, &minus_p, keyLength); - } - } - - multiprecision_inv_mod(minus_p.x, q->z, keyLength); - multiprecision_mersenns_squa_mod(q->z, minus_p.x, keyLength); - multiprecision_mersenns_mult_mod(q->x, q->x, q->z, keyLength); - multiprecision_mersenns_mult_mod(q->z, q->z, minus_p.x, keyLength); - multiprecision_mersenns_mult_mod(q->y, q->y, q->z, keyLength); + multiprecision_inv_mod(minus_p.x, q->z, keyLength); + multiprecision_mersenns_squa_mod(q->z, minus_p.x, keyLength); + multiprecision_mersenns_mult_mod(q->x, q->x, q->z, keyLength); + multiprecision_mersenns_mult_mod(q->z, q->z, minus_p.x, keyLength); + multiprecision_mersenns_mult_mod(q->y, q->y, q->z, keyLength); } - - diff --git a/stack/smp/p_256_ecc_pp.h b/stack/smp/p_256_ecc_pp.h index 186dd2991..dcc4211dc 100644 --- a/stack/smp/p_256_ecc_pp.h +++ b/stack/smp/p_256_ecc_pp.h @@ -18,7 +18,8 @@ /****************************************************************************** * - * This file contains simple pairing algorithms using Elliptic Curve Cryptography for private public key + * This file contains simple pairing algorithms using Elliptic Curve + *Cryptography for private public key * ******************************************************************************/ @@ -27,37 +28,36 @@ #include "p_256_multprecision.h" typedef struct { - uint32_t x[KEY_LENGTH_DWORDS_P256]; - uint32_t y[KEY_LENGTH_DWORDS_P256]; - uint32_t z[KEY_LENGTH_DWORDS_P256]; + uint32_t x[KEY_LENGTH_DWORDS_P256]; + uint32_t y[KEY_LENGTH_DWORDS_P256]; + uint32_t z[KEY_LENGTH_DWORDS_P256]; } Point; typedef struct { - // curve's coefficients - uint32_t a[KEY_LENGTH_DWORDS_P256]; - uint32_t b[KEY_LENGTH_DWORDS_P256]; + // curve's coefficients + uint32_t a[KEY_LENGTH_DWORDS_P256]; + uint32_t b[KEY_LENGTH_DWORDS_P256]; - //whether a is -3 - int a_minus3; + // whether a is -3 + int a_minus3; - // prime modulus - uint32_t p[KEY_LENGTH_DWORDS_P256]; + // prime modulus + uint32_t p[KEY_LENGTH_DWORDS_P256]; - // Omega, p = 2^m -omega - uint32_t omega[KEY_LENGTH_DWORDS_P256]; + // Omega, p = 2^m -omega + uint32_t omega[KEY_LENGTH_DWORDS_P256]; - // base point, a point on E of order r - Point G; + // base point, a point on E of order r + Point G; } elliptic_curve_t; extern elliptic_curve_t curve; extern elliptic_curve_t curve_p256; -void ECC_PointMult_Bin_NAF(Point *q, Point *p, uint32_t *n, uint32_t keyLength); +void ECC_PointMult_Bin_NAF(Point* q, Point* p, uint32_t* n, uint32_t keyLength); -#define ECC_PointMult(q, p, n, keyLength) ECC_PointMult_Bin_NAF(q, p, n, keyLength) +#define ECC_PointMult(q, p, n, keyLength) \ + ECC_PointMult_Bin_NAF(q, p, n, keyLength) void p_256_init_curve(uint32_t keyLength); - - diff --git a/stack/smp/p_256_multprecision.cc b/stack/smp/p_256_multprecision.cc index 2ad1a88d0..a44ea0c54 100644 --- a/stack/smp/p_256_multprecision.cc +++ b/stack/smp/p_256_multprecision.cc @@ -22,683 +22,593 @@ * ******************************************************************************/ +#include "p_256_multprecision.h" #include #include "bt_target.h" #include "p_256_ecc_pp.h" -#include "p_256_multprecision.h" -void multiprecision_init(uint32_t *c, uint32_t keyLength) -{ - for (uint32_t i = 0; i < keyLength; i++) - c[i] = 0; +void multiprecision_init(uint32_t* c, uint32_t keyLength) { + for (uint32_t i = 0; i < keyLength; i++) c[i] = 0; } -void multiprecision_copy(uint32_t *c, uint32_t *a, uint32_t keyLength) -{ - for (uint32_t i = 0; i < keyLength; i++) - c[i] = a[i]; +void multiprecision_copy(uint32_t* c, uint32_t* a, uint32_t keyLength) { + for (uint32_t i = 0; i < keyLength; i++) c[i] = a[i]; } -int multiprecision_compare(uint32_t *a, uint32_t *b, uint32_t keyLength) -{ - for (int i = keyLength - 1; i >= 0; i--) - { - if (a[i] > b[i]) - return 1; - if (a[i] < b[i]) - return -1; - } - return 0; +int multiprecision_compare(uint32_t* a, uint32_t* b, uint32_t keyLength) { + for (int i = keyLength - 1; i >= 0; i--) { + if (a[i] > b[i]) return 1; + if (a[i] < b[i]) return -1; + } + return 0; } -int multiprecision_iszero(uint32_t *a, uint32_t keyLength) -{ - for (uint32_t i = 0; i < keyLength; i++) - if (a[i]) - return 0; +int multiprecision_iszero(uint32_t* a, uint32_t keyLength) { + for (uint32_t i = 0; i < keyLength; i++) + if (a[i]) return 0; - return 1; + return 1; } -uint32_t multiprecision_dword_bits(uint32_t a) -{ - uint32_t i; - for (i = 0; i < DWORD_BITS; i++, a >>= 1) - if (a == 0) - break; +uint32_t multiprecision_dword_bits(uint32_t a) { + uint32_t i; + for (i = 0; i < DWORD_BITS; i++, a >>= 1) + if (a == 0) break; - return i; + return i; } -uint32_t multiprecision_most_signdwords(uint32_t *a, uint32_t keyLength) -{ - int i; - for (i = keyLength - 1; i >= 0; i--) - if (a[i]) - break; - return (i + 1); +uint32_t multiprecision_most_signdwords(uint32_t* a, uint32_t keyLength) { + int i; + for (i = keyLength - 1; i >= 0; i--) + if (a[i]) break; + return (i + 1); } -uint32_t multiprecision_most_signbits(uint32_t *a, uint32_t keyLength) -{ - int aMostSignDWORDs; +uint32_t multiprecision_most_signbits(uint32_t* a, uint32_t keyLength) { + int aMostSignDWORDs; - aMostSignDWORDs = multiprecision_most_signdwords(a, keyLength); - if (aMostSignDWORDs == 0) - return 0; + aMostSignDWORDs = multiprecision_most_signdwords(a, keyLength); + if (aMostSignDWORDs == 0) return 0; - return (((aMostSignDWORDs-1) << DWORD_BITS_SHIFT) + - multiprecision_dword_bits(a[aMostSignDWORDs-1]) ); + return (((aMostSignDWORDs - 1) << DWORD_BITS_SHIFT) + + multiprecision_dword_bits(a[aMostSignDWORDs - 1])); } -uint32_t multiprecision_add(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength) -{ - uint32_t carrier; - uint32_t temp; - - carrier=0; - for (uint32_t i = 0; i < keyLength; i++) - { - temp = a[i] + carrier; - carrier = (temp < carrier); - temp += b[i]; - carrier |= (temp < b[i]); - c[i]=temp; - } - - return carrier; +uint32_t multiprecision_add(uint32_t* c, uint32_t* a, uint32_t* b, + uint32_t keyLength) { + uint32_t carrier; + uint32_t temp; + + carrier = 0; + for (uint32_t i = 0; i < keyLength; i++) { + temp = a[i] + carrier; + carrier = (temp < carrier); + temp += b[i]; + carrier |= (temp < b[i]); + c[i] = temp; + } + + return carrier; } -//c=a-b -uint32_t multiprecision_sub(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength) -{ - uint32_t borrow; - uint32_t temp; - - borrow=0; - for (uint32_t i=0; i < keyLength; i++) - { - temp = a[i] - borrow; - borrow = (temp > a[i]); - c[i] = temp - b[i]; - borrow |= (c[i] > temp); - } - - return borrow; +// c=a-b +uint32_t multiprecision_sub(uint32_t* c, uint32_t* a, uint32_t* b, + uint32_t keyLength) { + uint32_t borrow; + uint32_t temp; + + borrow = 0; + for (uint32_t i = 0; i < keyLength; i++) { + temp = a[i] - borrow; + borrow = (temp > a[i]); + c[i] = temp - b[i]; + borrow |= (c[i] > temp); + } + + return borrow; } // c = a << 1 -void multiprecision_lshift_mod(uint32_t * c, uint32_t * a, uint32_t keyLength) -{ - uint32_t carrier; - uint32_t *modp; - - if (keyLength == KEY_LENGTH_DWORDS_P192) - { - modp = curve.p; - } - else if (keyLength == KEY_LENGTH_DWORDS_P256) - { - modp = curve_p256.p; - } - else - return; - - carrier = multiprecision_lshift(c, a, keyLength); - if (carrier) - { - multiprecision_sub(c, c, modp, keyLength); - } - else if (multiprecision_compare(c, modp, keyLength)>=0) - { - multiprecision_sub(c, c, modp, keyLength); - } +void multiprecision_lshift_mod(uint32_t* c, uint32_t* a, uint32_t keyLength) { + uint32_t carrier; + uint32_t* modp; + + if (keyLength == KEY_LENGTH_DWORDS_P192) { + modp = curve.p; + } else if (keyLength == KEY_LENGTH_DWORDS_P256) { + modp = curve_p256.p; + } else + return; + + carrier = multiprecision_lshift(c, a, keyLength); + if (carrier) { + multiprecision_sub(c, c, modp, keyLength); + } else if (multiprecision_compare(c, modp, keyLength) >= 0) { + multiprecision_sub(c, c, modp, keyLength); + } } // c=a>>1 -void multiprecision_rshift(uint32_t * c, uint32_t * a, uint32_t keyLength) -{ - int j; - uint32_t b = 1; - - j = DWORD_BITS - b; - - uint32_t carrier = 0; - uint32_t temp; - for (int i = keyLength-1; i >= 0; i--) - { - temp = a[i]; // in case of c==a - c[i] = (temp >> b) | carrier; - carrier = temp << j; - } +void multiprecision_rshift(uint32_t* c, uint32_t* a, uint32_t keyLength) { + int j; + uint32_t b = 1; + + j = DWORD_BITS - b; + + uint32_t carrier = 0; + uint32_t temp; + for (int i = keyLength - 1; i >= 0; i--) { + temp = a[i]; // in case of c==a + c[i] = (temp >> b) | carrier; + carrier = temp << j; + } } -// Curve specific optimization when p is a pseudo-Mersenns prime, p=2^(KEY_LENGTH_BITS)-omega -void multiprecision_mersenns_mult_mod(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength) -{ - uint32_t cc[2*KEY_LENGTH_DWORDS_P256]; - - multiprecision_mult(cc, a, b, keyLength); - if (keyLength == 6) - { - multiprecision_fast_mod(c, cc); - } - else if (keyLength == 8) - { - multiprecision_fast_mod_P256(c, cc); - } +// Curve specific optimization when p is a pseudo-Mersenns prime, +// p=2^(KEY_LENGTH_BITS)-omega +void multiprecision_mersenns_mult_mod(uint32_t* c, uint32_t* a, uint32_t* b, + uint32_t keyLength) { + uint32_t cc[2 * KEY_LENGTH_DWORDS_P256]; + + multiprecision_mult(cc, a, b, keyLength); + if (keyLength == 6) { + multiprecision_fast_mod(c, cc); + } else if (keyLength == 8) { + multiprecision_fast_mod_P256(c, cc); + } } // Curve specific optimization when p is a pseudo-Mersenns prime -void multiprecision_mersenns_squa_mod(uint32_t *c, uint32_t *a, uint32_t keyLength) -{ - multiprecision_mersenns_mult_mod(c, a, a, keyLength); +void multiprecision_mersenns_squa_mod(uint32_t* c, uint32_t* a, + uint32_t keyLength) { + multiprecision_mersenns_mult_mod(c, a, a, keyLength); } // c=(a+b) mod p, b= 0) - { - multiprecision_sub(c, c, modp, keyLength); - } +void multiprecision_add_mod(uint32_t* c, uint32_t* a, uint32_t* b, + uint32_t keyLength) { + uint32_t carrier; + uint32_t* modp; + + if (keyLength == KEY_LENGTH_DWORDS_P192) { + modp = curve.p; + } else if (keyLength == KEY_LENGTH_DWORDS_P256) { + modp = curve_p256.p; + } else + return; + + carrier = multiprecision_add(c, a, b, keyLength); + if (carrier) { + multiprecision_sub(c, c, modp, keyLength); + } else if (multiprecision_compare(c, modp, keyLength) >= 0) { + multiprecision_sub(c, c, modp, keyLength); + } } // c=(a-b) mod p, a> j; - } + for (uint32_t i = 0; i < keyLength; i++) { + temp = a[i]; // in case c==a + c[i] = (temp << b) | carrier; + carrier = temp >> j; + } - return carrier; + return carrier; } // c=a*b; c must have a buffer of 2*Key_LENGTH_uint32_tS, c != a != b -void multiprecision_mult(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength) -{ - uint32_t W; - uint32_t U; - uint32_t V; - - U = V = W = 0; - multiprecision_init(c, keyLength); - - //assume little endian right now - for (uint32_t i = 0; i < keyLength; i++) - { - U = 0; - for (uint32_t j = 0; j < keyLength; j++) - { - uint64_t result; - result = ((uint64_t)a[i]) * ((uint64_t) b[j]); - W = result >> 32; - V = a[i] * b[j]; - V = V + U; - U = (V < U); - U += W; - V = V + c[i+j]; - U += (V < c[i+j]); - c[i+j] = V; - } - c[i+keyLength] = U; - } +void multiprecision_mult(uint32_t* c, uint32_t* a, uint32_t* b, + uint32_t keyLength) { + uint32_t W; + uint32_t U; + uint32_t V; + + U = V = W = 0; + multiprecision_init(c, keyLength); + + // assume little endian right now + for (uint32_t i = 0; i < keyLength; i++) { + U = 0; + for (uint32_t j = 0; j < keyLength; j++) { + uint64_t result; + result = ((uint64_t)a[i]) * ((uint64_t)b[j]); + W = result >> 32; + V = a[i] * b[j]; + V = V + U; + U = (V < U); + U += W; + V = V + c[i + j]; + U += (V < c[i + j]); + c[i + j] = V; + } + c[i + keyLength] = U; + } } -void multiprecision_fast_mod(uint32_t *c, uint32_t *a) -{ - uint32_t U; - uint32_t V; - uint32_t *modp = curve.p; - - c[0] = a[0] + a[6]; - U=c[0] < a[0]; - c[0] += a[10]; - U += c[0] < a[10]; +void multiprecision_fast_mod(uint32_t* c, uint32_t* a) { + uint32_t U; + uint32_t V; + uint32_t* modp = curve.p; + + c[0] = a[0] + a[6]; + U = c[0] < a[0]; + c[0] += a[10]; + U += c[0] < a[10]; + + c[1] = a[1] + U; + U = c[1] < a[1]; + c[1] += a[7]; + U += c[1] < a[7]; + c[1] += a[11]; + U += c[1] < a[11]; + + c[2] = a[2] + U; + U = c[2] < a[2]; + c[2] += a[6]; + U += c[2] < a[6]; + c[2] += a[8]; + U += c[2] < a[8]; + c[2] += a[10]; + U += c[2] < a[10]; + + c[3] = a[3] + U; + U = c[3] < a[3]; + c[3] += a[7]; + U += c[3] < a[7]; + c[3] += a[9]; + U += c[3] < a[9]; + c[3] += a[11]; + U += c[3] < a[11]; + + c[4] = a[4] + U; + U = c[4] < a[4]; + c[4] += a[8]; + U += c[4] < a[8]; + c[4] += a[10]; + U += c[4] < a[10]; + + c[5] = a[5] + U; + U = c[5] < a[5]; + c[5] += a[9]; + U += c[5] < a[9]; + c[5] += a[11]; + U += c[5] < a[11]; + + c[0] += U; + V = c[0] < U; + c[1] += V; + V = c[1] < V; + c[2] += V; + V = c[2] < V; + c[2] += U; + V = c[2] < U; + c[3] += V; + V = c[3] < V; + c[4] += V; + V = c[4] < V; + c[5] += V; + V = c[5] < V; + + if (V) { + multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P192); + } else if (multiprecision_compare(c, modp, KEY_LENGTH_DWORDS_P192) >= 0) { + multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P192); + } +} +void multiprecision_fast_mod_P256(uint32_t* c, uint32_t* a) { + uint32_t A; + uint32_t B; + uint32_t C; + uint32_t D; + uint32_t E; + uint32_t F; + uint32_t G; + uint8_t UA; + uint8_t UB; + uint8_t UC; + uint8_t UD; + uint8_t UE; + uint8_t UF; + uint8_t UG; + uint32_t U; + uint32_t* modp = curve_p256.p; + + // C = a[13] + a[14] + a[15]; + C = a[13]; + C += a[14]; + UC = (C < a[14]); + C += a[15]; + UC += (C < a[15]); + + // E = a[8] + a[9]; + E = a[8]; + E += a[9]; + UE = (E < a[9]); + + // F = a[9] + a[10]; + F = a[9]; + F += a[10]; + UF = (F < a[10]); + + // G = a[10] + a[11] + G = a[10]; + G += a[11]; + UG = (G < a[11]); + + // B = a[12] + a[13] + a[14] + a[15] == C + a[12] + B = C; + UB = UC; + B += a[12]; + UB += (B < a[12]); + + // A = a[11] + a[12] + a[13] + a[14] == B + a[11] - a[15] + A = B; + UA = UB; + A += a[11]; + UA += (A < a[11]); + UA -= (A < a[15]); + A -= a[15]; + + // D = a[10] + a[11] + a[12] + a[13] == A + a[10] - a[14] + D = A; + UD = UA; + D += a[10]; + UD += (D < a[10]); + UD -= (D < a[14]); + D -= a[14]; + + c[0] = a[0]; + c[0] += E; + U = (c[0] < E); + U += UE; + U -= (c[0] < A); + U -= UA; + c[0] -= A; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[1] < UU); + c[1] = a[1] - UU; + } else { c[1] = a[1] + U; - U = c[1] < a[1]; - c[1] += a[7]; - U += c[1] < a[7]; - c[1] += a[11]; - U += c[1]< a[11]; - + U = (c[1] < a[1]); + } + + c[1] += F; + U += (c[1] < F); + U += UF; + U -= (c[1] < B); + U -= UB; + c[1] -= B; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[2] < UU); + c[2] = a[2] - UU; + } else { c[2] = a[2] + U; - U = c[2] < a[2]; - c[2] += a[6]; - U += c[2] < a[6]; - c[2] += a[8]; - U += c[2] < a[8]; - c[2] += a[10]; - U += c[2] < a[10]; - - c[3] = a[3]+U; - U = c[3] < a[3]; - c[3] += a[7]; - U += c[3] < a[7]; - c[3] += a[9]; - U += c[3] < a[9]; - c[3] += a[11]; - U += c[3] < a[11]; - - c[4] = a[4]+U; - U = c[4] < a[4]; - c[4] += a[8]; - U += c[4] < a[8]; - c[4] += a[10]; - U += c[4] < a[10]; - - c[5] = a[5]+U; - U = c[5] < a[5]; - c[5] += a[9]; - U += c[5] < a[9]; - c[5] += a[11]; - U += c[5] < a[11]; - - c[0] += U; - V = c[0] < U; - c[1] += V; - V = c[1] < V; - c[2] += V; - V = c[2] < V; - c[2] += U; - V = c[2] < U; - c[3] += V; - V = c[3] < V; - c[4] += V; - V = c[4] < V; - c[5] += V; - V = c[5] < V; - - if (V) - { - multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P192); - } - else if(multiprecision_compare(c, modp, KEY_LENGTH_DWORDS_P192) >= 0) - { - multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P192); - } -} - -void multiprecision_fast_mod_P256(uint32_t *c, uint32_t *a) -{ - uint32_t A; - uint32_t B; - uint32_t C; - uint32_t D; - uint32_t E; - uint32_t F; - uint32_t G; - uint8_t UA; - uint8_t UB; - uint8_t UC; - uint8_t UD; - uint8_t UE; - uint8_t UF; - uint8_t UG; - uint32_t U; - uint32_t *modp = curve_p256.p; - - // C = a[13] + a[14] + a[15]; - C = a[13]; - C += a[14]; - UC = (C < a[14]); - C += a[15]; - UC += (C < a[15]); - - // E = a[8] + a[9]; - E = a[8]; - E += a[9]; - UE = (E < a[9]); - - // F = a[9] + a[10]; - F = a[9]; - F += a[10]; - UF = (F < a[10]); - - // G = a[10] + a[11] - G = a[10]; - G += a[11]; - UG = (G < a[11]); - - // B = a[12] + a[13] + a[14] + a[15] == C + a[12] - B = C; - UB = UC; - B += a[12]; - UB += (B < a[12]); - - // A = a[11] + a[12] + a[13] + a[14] == B + a[11] - a[15] - A = B; - UA = UB; - A += a[11]; - UA += (A < a[11]); - UA -= (A < a[15]); - A -= a[15]; - - // D = a[10] + a[11] + a[12] + a[13] == A + a[10] - a[14] - D = A; - UD = UA; - D += a[10]; - UD += (D < a[10]); - UD -= (D < a[14]); - D -= a[14]; - - c[0] = a[0]; - c[0] += E; - U = (c[0] < E); - U += UE; - U -= (c[0] < A); - U -= UA; - c[0] -= A; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[1] < UU); - c[1] = a[1] - UU; - } - else - { - c[1] = a[1] + U; - U = (c[1] < a[1]); - } - - c[1] += F; - U += (c[1] < F); - U += UF; - U -= (c[1] < B); - U -= UB; - c[1] -= B; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[2] < UU); - c[2] = a[2] - UU; - } - else - { - c[2] = a[2] + U; - U = (c[2] < a[2]); - } - - c[2] += G; - U += (c[2] < G); - U += UG; - U -= (c[2] < C); - U -= UC; - c[2] -= C; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[3] < UU); - c[3] = a[3] - UU; - } - else - { - c[3] = a[3] + U; - U = (c[3] < a[3]); - } - - c[3] += A; - U += (c[3] < A); - U += UA; - c[3] += a[11]; - U += (c[3] < a[11]); - c[3] += a[12]; - U += (c[3] < a[12]); - U -= (c[3] < a[14]); - c[3] -= a[14]; - U -= (c[3] < a[15]); - c[3] -= a[15]; - U -= (c[3] < E); - U -= UE; - c[3] -= E; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[4] < UU); - c[4] = a[4] - UU; - } - else - { - c[4] = a[4] + U; - U = (c[4] < a[4]); - } - - c[4] += B; - U += (c[4] < B); - U += UB; - U -= (c[4] < a[15]); - c[4] -= a[15]; - c[4] += a[12]; - U += (c[4] < a[12]); - c[4] += a[13]; - U += (c[4] < a[13]); - U -= (c[4] < F); - U -= UF; - c[4] -= F; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[5] < UU); - c[5] = a[5] - UU; - } - else - { - c[5] = a[5] + U; - U = (c[5] < a[5]); - } - - c[5] += C; - U += (c[5] < C); - U += UC; - c[5] += a[13]; - U += (c[5] < a[13]); - c[5] += a[14]; - U += (c[5] < a[14]); - U -= (c[5] < G); - U -= UG; - c[5] -= G; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[6] < UU); - c[6] = a[6] - UU; - } - else - { - c[6] = a[6] + U; - U = (c[6] < a[6]); - } - - c[6] += C; - U += (c[6] < C); - U += UC; - c[6] += a[14]; - U += (c[6] < a[14]); - c[6] += a[14]; - U += (c[6] < a[14]); - c[6] += a[15]; - U += (c[6] < a[15]); - U -= (c[6] < E); - U -= UE; - c[6] -= E; - - if (U & 0x80000000) - { - uint32_t UU; - UU = 0 - U; - U = (a[7] < UU); - c[7] = a[7] - UU; - } - else - { - c[7] = a[7] + U; - U = (c[7] < a[7]); - } - - c[7] += a[15]; - U += (c[7] < a[15]); - c[7] += a[15]; - U += (c[7] < a[15]); - c[7] += a[15]; - U += (c[7] < a[15]); - c[7] += a[8]; - U += (c[7] < a[8]); - U -= (c[7] < D); - U -= UD; - c[7] -= D; - - if (U & 0x80000000) - { - while (U) - { - multiprecision_add(c, c, modp, KEY_LENGTH_DWORDS_P256); - U++; - } - } - else if (U) - { - while (U) - { - multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P256); - U--; - } - } - - if (multiprecision_compare(c, modp, KEY_LENGTH_DWORDS_P256)>=0) - multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P256); - + U = (c[2] < a[2]); + } + + c[2] += G; + U += (c[2] < G); + U += UG; + U -= (c[2] < C); + U -= UC; + c[2] -= C; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[3] < UU); + c[3] = a[3] - UU; + } else { + c[3] = a[3] + U; + U = (c[3] < a[3]); + } + + c[3] += A; + U += (c[3] < A); + U += UA; + c[3] += a[11]; + U += (c[3] < a[11]); + c[3] += a[12]; + U += (c[3] < a[12]); + U -= (c[3] < a[14]); + c[3] -= a[14]; + U -= (c[3] < a[15]); + c[3] -= a[15]; + U -= (c[3] < E); + U -= UE; + c[3] -= E; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[4] < UU); + c[4] = a[4] - UU; + } else { + c[4] = a[4] + U; + U = (c[4] < a[4]); + } + + c[4] += B; + U += (c[4] < B); + U += UB; + U -= (c[4] < a[15]); + c[4] -= a[15]; + c[4] += a[12]; + U += (c[4] < a[12]); + c[4] += a[13]; + U += (c[4] < a[13]); + U -= (c[4] < F); + U -= UF; + c[4] -= F; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[5] < UU); + c[5] = a[5] - UU; + } else { + c[5] = a[5] + U; + U = (c[5] < a[5]); + } + + c[5] += C; + U += (c[5] < C); + U += UC; + c[5] += a[13]; + U += (c[5] < a[13]); + c[5] += a[14]; + U += (c[5] < a[14]); + U -= (c[5] < G); + U -= UG; + c[5] -= G; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[6] < UU); + c[6] = a[6] - UU; + } else { + c[6] = a[6] + U; + U = (c[6] < a[6]); + } + + c[6] += C; + U += (c[6] < C); + U += UC; + c[6] += a[14]; + U += (c[6] < a[14]); + c[6] += a[14]; + U += (c[6] < a[14]); + c[6] += a[15]; + U += (c[6] < a[15]); + U -= (c[6] < E); + U -= UE; + c[6] -= E; + + if (U & 0x80000000) { + uint32_t UU; + UU = 0 - U; + U = (a[7] < UU); + c[7] = a[7] - UU; + } else { + c[7] = a[7] + U; + U = (c[7] < a[7]); + } + + c[7] += a[15]; + U += (c[7] < a[15]); + c[7] += a[15]; + U += (c[7] < a[15]); + c[7] += a[15]; + U += (c[7] < a[15]); + c[7] += a[8]; + U += (c[7] < a[8]); + U -= (c[7] < D); + U -= UD; + c[7] -= D; + + if (U & 0x80000000) { + while (U) { + multiprecision_add(c, c, modp, KEY_LENGTH_DWORDS_P256); + U++; + } + } else if (U) { + while (U) { + multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P256); + U--; + } + } + + if (multiprecision_compare(c, modp, KEY_LENGTH_DWORDS_P256) >= 0) + multiprecision_sub(c, c, modp, KEY_LENGTH_DWORDS_P256); } -void multiprecision_inv_mod(uint32_t *aminus, uint32_t *u, uint32_t keyLength) -{ - uint32_t v[KEY_LENGTH_DWORDS_P256]; - uint32_t A[KEY_LENGTH_DWORDS_P256+1]; - uint32_t C[KEY_LENGTH_DWORDS_P256+1]; - uint32_t *modp; - - if(keyLength == KEY_LENGTH_DWORDS_P256) - { - modp = curve_p256.p; - } - else - { - modp = curve.p; - } - - multiprecision_copy(v, modp, keyLength); - multiprecision_init(A, keyLength); - multiprecision_init(C, keyLength); - A[0] = 1; - - while (!multiprecision_iszero(u, keyLength)) - { - while (!(u[0] & 0x01)) // u is even - { - multiprecision_rshift(u, u, keyLength); - if(!(A[0] & 0x01)) // A is even - multiprecision_rshift(A, A, keyLength); - else - { - A[keyLength]=multiprecision_add(A, A, modp, keyLength); // A =A+p - multiprecision_rshift(A, A, keyLength); - A[keyLength-1] |= (A[keyLength]<<31); - } - } - - while (!(v[0] & 0x01)) // v is even - { - multiprecision_rshift(v, v, keyLength); - if (!(C[0] & 0x01)) // C is even - { - multiprecision_rshift(C, C, keyLength); - } - else - { - C[keyLength] = multiprecision_add(C, C, modp, keyLength); // C =C+p - multiprecision_rshift(C, C, keyLength); - C[keyLength-1] |= (C[keyLength] << 31); - } - } - - if (multiprecision_compare(u, v, keyLength) >= 0) - { - multiprecision_sub(u, u, v, keyLength); - multiprecision_sub_mod(A, A, C, keyLength); - } - else - { - multiprecision_sub(v, v, u, keyLength); - multiprecision_sub_mod(C, C, A, keyLength); - } - } - - if (multiprecision_compare(C, modp, keyLength) >= 0) - multiprecision_sub(aminus, C, modp, keyLength); - else - multiprecision_copy(aminus, C, keyLength); +void multiprecision_inv_mod(uint32_t* aminus, uint32_t* u, uint32_t keyLength) { + uint32_t v[KEY_LENGTH_DWORDS_P256]; + uint32_t A[KEY_LENGTH_DWORDS_P256 + 1]; + uint32_t C[KEY_LENGTH_DWORDS_P256 + 1]; + uint32_t* modp; + + if (keyLength == KEY_LENGTH_DWORDS_P256) { + modp = curve_p256.p; + } else { + modp = curve.p; + } + + multiprecision_copy(v, modp, keyLength); + multiprecision_init(A, keyLength); + multiprecision_init(C, keyLength); + A[0] = 1; + + while (!multiprecision_iszero(u, keyLength)) { + while (!(u[0] & 0x01)) // u is even + { + multiprecision_rshift(u, u, keyLength); + if (!(A[0] & 0x01)) // A is even + multiprecision_rshift(A, A, keyLength); + else { + A[keyLength] = multiprecision_add(A, A, modp, keyLength); // A =A+p + multiprecision_rshift(A, A, keyLength); + A[keyLength - 1] |= (A[keyLength] << 31); + } + } + + while (!(v[0] & 0x01)) // v is even + { + multiprecision_rshift(v, v, keyLength); + if (!(C[0] & 0x01)) // C is even + { + multiprecision_rshift(C, C, keyLength); + } else { + C[keyLength] = multiprecision_add(C, C, modp, keyLength); // C =C+p + multiprecision_rshift(C, C, keyLength); + C[keyLength - 1] |= (C[keyLength] << 31); + } + } + + if (multiprecision_compare(u, v, keyLength) >= 0) { + multiprecision_sub(u, u, v, keyLength); + multiprecision_sub_mod(A, A, C, keyLength); + } else { + multiprecision_sub(v, v, u, keyLength); + multiprecision_sub_mod(C, C, A, keyLength); + } + } + + if (multiprecision_compare(C, modp, keyLength) >= 0) + multiprecision_sub(aminus, C, modp, keyLength); + else + multiprecision_copy(aminus, C, keyLength); } - diff --git a/stack/smp/p_256_multprecision.h b/stack/smp/p_256_multprecision.h index 009f6f0bd..ca5311b24 100644 --- a/stack/smp/p_256_multprecision.h +++ b/stack/smp/p_256_multprecision.h @@ -25,35 +25,44 @@ #include "bt_types.h" -#define DWORD_BITS 32 -#define DWORD_BYTES 4 +#define DWORD_BITS 32 +#define DWORD_BYTES 4 #define DWORD_BITS_SHIFT 5 #define KEY_LENGTH_DWORDS_P192 6 #define KEY_LENGTH_DWORDS_P256 8 /* Arithmetic Operations */ -int multiprecision_compare(uint32_t *a, uint32_t *b, uint32_t keyLength); -int multiprecision_iszero(uint32_t *a, uint32_t keyLength); -void multiprecision_init(uint32_t *c, uint32_t keyLength); -void multiprecision_copy(uint32_t *c, uint32_t *a, uint32_t keyLength); -uint32_t multiprecision_dword_bits (uint32_t a); -uint32_t multiprecision_most_signdwords(uint32_t *a, uint32_t keyLength); -uint32_t multiprecision_most_signbits(uint32_t *a, uint32_t keyLength); -void multiprecision_inv_mod(uint32_t *aminus, uint32_t *a, uint32_t keyLength); -uint32_t multiprecision_add(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength); // c=a+b -void multiprecision_add_mod(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength); -uint32_t multiprecision_sub(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength); // c=a-b -void multiprecision_sub_mod(uint32_t *c, uint32_t *a, uint32_t *b, uint32_t keyLength); -void multiprecision_rshift(uint32_t * c, uint32_t * a, uint32_t keyLength); // c=a>>1, return carrier -void multiprecision_lshift_mod(uint32_t * c, uint32_t * a, uint32_t keyLength); // c=a<>1, return carrier +void multiprecision_lshift_mod(uint32_t* c, uint32_t* a, + uint32_t keyLength); // c=a<lmp_version == 0) - { - SMP_TRACE_WARNING("%s cannot retrieve LMP version...", __func__); - return false; - } - SMP_TRACE_WARNING("%s LMP version %d < %d", __func__, acl->lmp_version, version); - return acl->lmp_version < version; -} - -static bool pts_test_send_authentication_complete_failure(tSMP_CB *p_cb) -{ - uint8_t reason = 0; - - if (p_cb->cert_failure < 2 || p_cb->cert_failure > 6) - return false; +extern fixed_queue_t* btu_general_alarm_queue; - SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); +#define SMP_KEY_DIST_TYPE_MAX 4 +const tSMP_ACT smp_distribute_act[] = {smp_generate_ltk, smp_send_id_info, + smp_generate_csrk, + smp_set_derive_link_key}; - switch (p_cb->cert_failure) - { - case 2: - reason = SMP_PAIR_AUTH_FAIL; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - case 3: - reason = SMP_PAIR_FAIL_UNKNOWN; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - case 4: - reason = SMP_PAIR_NOT_SUPPORT; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - case 5: - reason = SMP_PASSKEY_ENTRY_FAIL; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - case 6: - reason = SMP_REPEATED_ATTEMPTS; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - } - - return true;; +static bool lmp_version_below(BD_ADDR bda, uint8_t version) { + tACL_CONN* acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE); + if (acl == NULL || acl->lmp_version == 0) { + SMP_TRACE_WARNING("%s cannot retrieve LMP version...", __func__); + return false; + } + SMP_TRACE_WARNING("%s LMP version %d < %d", __func__, acl->lmp_version, + version); + return acl->lmp_version < version; +} + +static bool pts_test_send_authentication_complete_failure(tSMP_CB* p_cb) { + uint8_t reason = 0; + + if (p_cb->cert_failure < 2 || p_cb->cert_failure > 6) return false; + + SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); + + switch (p_cb->cert_failure) { + case 2: + reason = SMP_PAIR_AUTH_FAIL; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + case 3: + reason = SMP_PAIR_FAIL_UNKNOWN; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + case 4: + reason = SMP_PAIR_NOT_SUPPORT; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + case 5: + reason = SMP_PASSKEY_ENTRY_FAIL; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + case 6: + reason = SMP_REPEATED_ATTEMPTS; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + } + + return true; + ; } /******************************************************************************* * Function smp_update_key_mask * Description This function updates the key mask for sending or receiving. ******************************************************************************/ -static void smp_update_key_mask (tSMP_CB *p_cb, uint8_t key_type, bool recv) -{ - SMP_TRACE_DEBUG("%s before update role=%d recv=%d local_i_key = %02x, local_r_key = %02x", - __func__, p_cb->role, recv, p_cb->local_i_key, p_cb->local_r_key); - - if (((p_cb->le_secure_connections_mode_is_used) || - (p_cb->smp_over_br)) && - ((key_type == SMP_SEC_KEY_TYPE_ENC) || (key_type == SMP_SEC_KEY_TYPE_LK))) - { - /* in LE SC mode LTK, CSRK and BR/EDR LK are derived locally instead of - ** being exchanged with the peer */ - p_cb->local_i_key &= ~key_type; - p_cb->local_r_key &= ~key_type; - } +static void smp_update_key_mask(tSMP_CB* p_cb, uint8_t key_type, bool recv) { + SMP_TRACE_DEBUG( + "%s before update role=%d recv=%d local_i_key = %02x, local_r_key = %02x", + __func__, p_cb->role, recv, p_cb->local_i_key, p_cb->local_r_key); + + if (((p_cb->le_secure_connections_mode_is_used) || (p_cb->smp_over_br)) && + ((key_type == SMP_SEC_KEY_TYPE_ENC) || + (key_type == SMP_SEC_KEY_TYPE_LK))) { + /* in LE SC mode LTK, CSRK and BR/EDR LK are derived locally instead of + ** being exchanged with the peer */ + p_cb->local_i_key &= ~key_type; + p_cb->local_r_key &= ~key_type; + } else if (p_cb->role == HCI_ROLE_SLAVE) { + if (recv) + p_cb->local_i_key &= ~key_type; else - if (p_cb->role == HCI_ROLE_SLAVE) - { - if (recv) - p_cb->local_i_key &= ~key_type; - else - p_cb->local_r_key &= ~key_type; - } + p_cb->local_r_key &= ~key_type; + } else { + if (recv) + p_cb->local_r_key &= ~key_type; else - { - if (recv) - p_cb->local_r_key &= ~key_type; - else - p_cb->local_i_key &= ~key_type; - } + p_cb->local_i_key &= ~key_type; + } - SMP_TRACE_DEBUG("updated local_i_key = %02x, local_r_key = %02x", p_cb->local_i_key, - p_cb->local_r_key); + SMP_TRACE_DEBUG("updated local_i_key = %02x, local_r_key = %02x", + p_cb->local_i_key, p_cb->local_r_key); } /******************************************************************************* @@ -126,588 +113,542 @@ static void smp_update_key_mask (tSMP_CB *p_cb, uint8_t key_type, bool recv) * Description notifies application about the events the application is * interested in ******************************************************************************/ -void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tSMP_EVT_DATA cb_data; - tSMP_STATUS callback_rc; - SMP_TRACE_DEBUG("%s p_cb->cb_evt=%d", __func__, p_cb->cb_evt); - if (p_cb->p_callback && p_cb->cb_evt != 0) - { - switch (p_cb->cb_evt) - { - case SMP_IO_CAP_REQ_EVT: - cb_data.io_req.auth_req = p_cb->peer_auth_req; - cb_data.io_req.oob_data = SMP_OOB_NONE; - cb_data.io_req.io_cap = SMP_DEFAULT_IO_CAPS; - cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE; - cb_data.io_req.init_keys = p_cb->local_i_key ; - cb_data.io_req.resp_keys = p_cb->local_r_key ; - SMP_TRACE_WARNING ( "io_cap = %d",cb_data.io_req.io_cap); - break; - - case SMP_NC_REQ_EVT: - cb_data.passkey = p_data->passkey; - break; - case SMP_SC_OOB_REQ_EVT: - cb_data.req_oob_type = p_data->req_oob_type; - break; - case SMP_SC_LOC_OOB_DATA_UP_EVT: - cb_data.loc_oob_data = p_cb->sc_oob_data.loc_oob_data; - break; - - case SMP_BR_KEYS_REQ_EVT: - cb_data.io_req.auth_req = 0; - cb_data.io_req.oob_data = SMP_OOB_NONE; - cb_data.io_req.io_cap = 0; - cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE; - cb_data.io_req.init_keys = SMP_BR_SEC_DEFAULT_KEY; - cb_data.io_req.resp_keys = SMP_BR_SEC_DEFAULT_KEY; - break; - - default: - break; - } - - callback_rc = (*p_cb->p_callback)(p_cb->cb_evt, p_cb->pairing_bda, &cb_data); - - SMP_TRACE_DEBUG("%s: callback_rc=%d p_cb->cb_evt=%d", __func__, callback_rc, p_cb->cb_evt ); - - if (callback_rc == SMP_SUCCESS) - { - switch (p_cb->cb_evt) - { - case SMP_IO_CAP_REQ_EVT: - p_cb->loc_auth_req = cb_data.io_req.auth_req; - p_cb->local_io_capability = cb_data.io_req.io_cap; - p_cb->loc_oob_flag = cb_data.io_req.oob_data; - p_cb->loc_enc_size = cb_data.io_req.max_key_size; - p_cb->local_i_key = cb_data.io_req.init_keys; - p_cb->local_r_key = cb_data.io_req.resp_keys; - - if (!(p_cb->loc_auth_req & SMP_AUTH_BOND)) - { - SMP_TRACE_WARNING ("Non bonding: No keys will be exchanged"); - p_cb->local_i_key = 0; - p_cb->local_r_key = 0; - } - - SMP_TRACE_WARNING ( "rcvd auth_req: 0x%02x, io_cap: %d \ +void smp_send_app_cback(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tSMP_EVT_DATA cb_data; + tSMP_STATUS callback_rc; + SMP_TRACE_DEBUG("%s p_cb->cb_evt=%d", __func__, p_cb->cb_evt); + if (p_cb->p_callback && p_cb->cb_evt != 0) { + switch (p_cb->cb_evt) { + case SMP_IO_CAP_REQ_EVT: + cb_data.io_req.auth_req = p_cb->peer_auth_req; + cb_data.io_req.oob_data = SMP_OOB_NONE; + cb_data.io_req.io_cap = SMP_DEFAULT_IO_CAPS; + cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE; + cb_data.io_req.init_keys = p_cb->local_i_key; + cb_data.io_req.resp_keys = p_cb->local_r_key; + SMP_TRACE_WARNING("io_cap = %d", cb_data.io_req.io_cap); + break; + + case SMP_NC_REQ_EVT: + cb_data.passkey = p_data->passkey; + break; + case SMP_SC_OOB_REQ_EVT: + cb_data.req_oob_type = p_data->req_oob_type; + break; + case SMP_SC_LOC_OOB_DATA_UP_EVT: + cb_data.loc_oob_data = p_cb->sc_oob_data.loc_oob_data; + break; + + case SMP_BR_KEYS_REQ_EVT: + cb_data.io_req.auth_req = 0; + cb_data.io_req.oob_data = SMP_OOB_NONE; + cb_data.io_req.io_cap = 0; + cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE; + cb_data.io_req.init_keys = SMP_BR_SEC_DEFAULT_KEY; + cb_data.io_req.resp_keys = SMP_BR_SEC_DEFAULT_KEY; + break; + + default: + break; + } + + callback_rc = + (*p_cb->p_callback)(p_cb->cb_evt, p_cb->pairing_bda, &cb_data); + + SMP_TRACE_DEBUG("%s: callback_rc=%d p_cb->cb_evt=%d", __func__, + callback_rc, p_cb->cb_evt); + + if (callback_rc == SMP_SUCCESS) { + switch (p_cb->cb_evt) { + case SMP_IO_CAP_REQ_EVT: + p_cb->loc_auth_req = cb_data.io_req.auth_req; + p_cb->local_io_capability = cb_data.io_req.io_cap; + p_cb->loc_oob_flag = cb_data.io_req.oob_data; + p_cb->loc_enc_size = cb_data.io_req.max_key_size; + p_cb->local_i_key = cb_data.io_req.init_keys; + p_cb->local_r_key = cb_data.io_req.resp_keys; + + if (!(p_cb->loc_auth_req & SMP_AUTH_BOND)) { + SMP_TRACE_WARNING("Non bonding: No keys will be exchanged"); + p_cb->local_i_key = 0; + p_cb->local_r_key = 0; + } + + SMP_TRACE_WARNING( + "rcvd auth_req: 0x%02x, io_cap: %d \ loc_oob_flag: %d loc_enc_size: %d," - "local_i_key: 0x%02x, local_r_key: 0x%02x", - p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag, - p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key); - - p_cb->secure_connections_only_mode_required = - (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false; - - if (p_cb->secure_connections_only_mode_required) - { - p_cb->loc_auth_req |= SMP_SC_SUPPORT_BIT; - } - - if (!(p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT) - || lmp_version_below(p_cb->pairing_bda, HCI_PROTO_VERSION_4_2) - || interop_match_addr(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, - (const bt_bdaddr_t *)&p_cb->pairing_bda)) - { - p_cb->loc_auth_req &= ~SMP_KP_SUPPORT_BIT; - p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; - p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; - } - - SMP_TRACE_WARNING("set auth_req: 0x%02x, local_i_key: 0x%02x, local_r_key: 0x%02x", - p_cb->loc_auth_req, p_cb->local_i_key, p_cb->local_r_key); - - smp_sm_event(p_cb, SMP_IO_RSP_EVT, NULL); - break; - - case SMP_BR_KEYS_REQ_EVT: - p_cb->loc_enc_size = cb_data.io_req.max_key_size; - p_cb->local_i_key = cb_data.io_req.init_keys; - p_cb->local_r_key = cb_data.io_req.resp_keys; - - p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; - p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; - - SMP_TRACE_WARNING ( "for SMP over BR max_key_size: 0x%02x,\ + "local_i_key: 0x%02x, local_r_key: 0x%02x", + p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag, + p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key); + + p_cb->secure_connections_only_mode_required = + (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false; + + if (p_cb->secure_connections_only_mode_required) { + p_cb->loc_auth_req |= SMP_SC_SUPPORT_BIT; + } + + if (!(p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT) || + lmp_version_below(p_cb->pairing_bda, HCI_PROTO_VERSION_4_2) || + interop_match_addr(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, + (const bt_bdaddr_t*)&p_cb->pairing_bda)) { + p_cb->loc_auth_req &= ~SMP_KP_SUPPORT_BIT; + p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; + p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; + } + + SMP_TRACE_WARNING( + "set auth_req: 0x%02x, local_i_key: 0x%02x, local_r_key: 0x%02x", + p_cb->loc_auth_req, p_cb->local_i_key, p_cb->local_r_key); + + smp_sm_event(p_cb, SMP_IO_RSP_EVT, NULL); + break; + + case SMP_BR_KEYS_REQ_EVT: + p_cb->loc_enc_size = cb_data.io_req.max_key_size; + p_cb->local_i_key = cb_data.io_req.init_keys; + p_cb->local_r_key = cb_data.io_req.resp_keys; + + p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; + p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; + + SMP_TRACE_WARNING( + "for SMP over BR max_key_size: 0x%02x,\ local_i_key: 0x%02x, local_r_key: 0x%02x", - p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key); + p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key); - smp_br_state_machine_event(p_cb, SMP_BR_KEYS_RSP_EVT, NULL); - break; - } - } + smp_br_state_machine_event(p_cb, SMP_BR_KEYS_RSP_EVT, NULL); + break; + } } + } - if (!p_cb->cb_evt && p_cb->discard_sec_req) - { - p_cb->discard_sec_req = false; - smp_sm_event(p_cb, SMP_DISCARD_SEC_REQ_EVT, NULL); - } + if (!p_cb->cb_evt && p_cb->discard_sec_req) { + p_cb->discard_sec_req = false; + smp_sm_event(p_cb, SMP_DISCARD_SEC_REQ_EVT, NULL); + } - SMP_TRACE_DEBUG("%s return", __func__); + SMP_TRACE_DEBUG("%s return", __func__); } /******************************************************************************* * Function smp_send_pair_fail * Description pairing failure to peer device if needed. ******************************************************************************/ -void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - p_cb->status = *(uint8_t *)p_data; - p_cb->failure = *(uint8_t *)p_data; +void smp_send_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + p_cb->status = *(uint8_t*)p_data; + p_cb->failure = *(uint8_t*)p_data; - SMP_TRACE_DEBUG("%s status=%d failure=%d ", __func__, p_cb->status, p_cb->failure); + SMP_TRACE_DEBUG("%s status=%d failure=%d ", __func__, p_cb->status, + p_cb->failure); - if (p_cb->status <= SMP_MAX_FAIL_RSN_PER_SPEC && p_cb->status != SMP_SUCCESS) - { - smp_send_cmd(SMP_OPCODE_PAIRING_FAILED, p_cb); - p_cb->wait_for_authorization_complete = true; - } + if (p_cb->status <= SMP_MAX_FAIL_RSN_PER_SPEC && + p_cb->status != SMP_SUCCESS) { + smp_send_cmd(SMP_OPCODE_PAIRING_FAILED, p_cb); + p_cb->wait_for_authorization_complete = true; + } } /******************************************************************************* * Function smp_send_pair_req * Description actions related to sending pairing request ******************************************************************************/ -void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda); - SMP_TRACE_DEBUG("%s", __func__); +void smp_send_pair_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); + SMP_TRACE_DEBUG("%s", __func__); - /* erase all keys when master sends pairing req*/ - if (p_dev_rec) - btm_sec_clear_ble_keys(p_dev_rec); - /* do not manipulate the key, let app decide, - leave out to BTM to mandate key distribution for bonding case */ - smp_send_cmd(SMP_OPCODE_PAIRING_REQ, p_cb); + /* erase all keys when master sends pairing req*/ + if (p_dev_rec) btm_sec_clear_ble_keys(p_dev_rec); + /* do not manipulate the key, let app decide, + leave out to BTM to mandate key distribution for bonding case */ + smp_send_cmd(SMP_OPCODE_PAIRING_REQ, p_cb); } /******************************************************************************* * Function smp_send_pair_rsp * Description actions related to sending pairing response ******************************************************************************/ -void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_send_pair_rsp(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - p_cb->local_i_key &= p_cb->peer_i_key; - p_cb->local_r_key &= p_cb->peer_r_key; + p_cb->local_i_key &= p_cb->peer_i_key; + p_cb->local_r_key &= p_cb->peer_r_key; - if (smp_send_cmd (SMP_OPCODE_PAIRING_RSP, p_cb)) - { - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) - smp_use_oob_private_key(p_cb, NULL); - else - smp_decide_association_model(p_cb, NULL); - } + if (smp_send_cmd(SMP_OPCODE_PAIRING_RSP, p_cb)) { + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) + smp_use_oob_private_key(p_cb, NULL); + else + smp_decide_association_model(p_cb, NULL); + } } /******************************************************************************* * Function smp_send_confirm * Description send confirmation to the peer ******************************************************************************/ -void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb); +void smp_send_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb); } /******************************************************************************* * Function smp_send_init * Description process pairing initializer to slave device ******************************************************************************/ -void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_INIT, p_cb); +void smp_send_init(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_INIT, p_cb); } /******************************************************************************* * Function smp_send_rand * Description send pairing random to the peer ******************************************************************************/ -void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_RAND, p_cb); +void smp_send_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_RAND, p_cb); } /******************************************************************************* * Function smp_send_pair_public_key * Description send pairing public key command to the peer ******************************************************************************/ -void smp_send_pair_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_PAIR_PUBLIC_KEY, p_cb); +void smp_send_pair_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_PAIR_PUBLIC_KEY, p_cb); } /******************************************************************************* * Function SMP_SEND_COMMITMENT * Description send commitment command to the peer ******************************************************************************/ -void smp_send_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_PAIR_COMMITM, p_cb); +void smp_send_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_PAIR_COMMITM, p_cb); } /******************************************************************************* * Function smp_send_dhkey_check * Description send DHKey Check command to the peer ******************************************************************************/ -void smp_send_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - smp_send_cmd(SMP_OPCODE_PAIR_DHKEY_CHECK, p_cb); +void smp_send_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_send_cmd(SMP_OPCODE_PAIR_DHKEY_CHECK, p_cb); } /******************************************************************************* * Function smp_send_keypress_notification * Description send Keypress Notification command to the peer ******************************************************************************/ -void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - p_cb->local_keypress_notification = *(uint8_t *) p_data; - smp_send_cmd(SMP_OPCODE_PAIR_KEYPR_NOTIF, p_cb); +void smp_send_keypress_notification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + p_cb->local_keypress_notification = *(uint8_t*)p_data; + smp_send_cmd(SMP_OPCODE_PAIR_KEYPR_NOTIF, p_cb); } /******************************************************************************* * Function smp_send_enc_info * Description send encryption information command. ******************************************************************************/ -void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_LE_LENC_KEYS le_key; +void smp_send_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_LE_LENC_KEYS le_key; - SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d", __func__, p_cb->loc_enc_size); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, false); + SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d", __func__, p_cb->loc_enc_size); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); - smp_send_cmd(SMP_OPCODE_ENCRYPT_INFO, p_cb); - smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb); + smp_send_cmd(SMP_OPCODE_ENCRYPT_INFO, p_cb); + smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb); - /* save the DIV and key size information when acting as slave device */ - memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); - le_key.div = p_cb->div; - le_key.key_size = p_cb->loc_enc_size; - le_key.sec_level = p_cb->sec_level; + /* save the DIV and key size information when acting as slave device */ + memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); + le_key.div = p_cb->div; + le_key.key_size = p_cb->loc_enc_size; + le_key.sec_level = p_cb->sec_level; - if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, - (tBTM_LE_KEY_VALUE *)&le_key, true); + if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && + (p_cb->loc_auth_req & SMP_AUTH_BOND)) + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, + (tBTM_LE_KEY_VALUE*)&le_key, true); - SMP_TRACE_WARNING ("%s", __func__); + SMP_TRACE_WARNING("%s", __func__); - smp_key_distribution(p_cb, NULL); + smp_key_distribution(p_cb, NULL); } /******************************************************************************* * Function smp_send_id_info * Description send ID information command. ******************************************************************************/ -void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_LE_KEY_VALUE le_key; - SMP_TRACE_DEBUG("%s", __func__); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, false); +void smp_send_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_LE_KEY_VALUE le_key; + SMP_TRACE_DEBUG("%s", __func__); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ID, false); - smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb); - smp_send_cmd(SMP_OPCODE_ID_ADDR, p_cb); + smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb); + smp_send_cmd(SMP_OPCODE_ID_ADDR, p_cb); - if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LID, - &le_key, true); + if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && + (p_cb->loc_auth_req & SMP_AUTH_BOND)) + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LID, &le_key, true); - SMP_TRACE_WARNING ("%s", __func__); - smp_key_distribution_by_transport(p_cb, NULL); + SMP_TRACE_WARNING("%s", __func__); + smp_key_distribution_by_transport(p_cb, NULL); } /******************************************************************************* * Function smp_send_csrk_info * Description send CSRK command. ******************************************************************************/ -void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_LE_LCSRK_KEYS key; - SMP_TRACE_DEBUG("%s", __func__); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, false); +void smp_send_csrk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_LE_LCSRK_KEYS key; + SMP_TRACE_DEBUG("%s", __func__); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_CSRK, false); - if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) - { - key.div = p_cb->div; - key.sec_level = p_cb->sec_level; - key.counter = 0; /* initialize the local counter */ - memcpy (key.csrk, p_cb->csrk, BT_OCTET16_LEN); - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, (tBTM_LE_KEY_VALUE *)&key, true); - } + if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) { + key.div = p_cb->div; + key.sec_level = p_cb->sec_level; + key.counter = 0; /* initialize the local counter */ + memcpy(key.csrk, p_cb->csrk, BT_OCTET16_LEN); + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, + (tBTM_LE_KEY_VALUE*)&key, true); + } - smp_key_distribution_by_transport(p_cb, NULL); + smp_key_distribution_by_transport(p_cb, NULL); } /******************************************************************************* * Function smp_send_ltk_reply * Description send LTK reply ******************************************************************************/ -void smp_send_ltk_reply(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - /* send stk as LTK response */ - btm_ble_ltk_request_reply(p_cb->pairing_bda, true, p_data->key.p_data); +void smp_send_ltk_reply(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + /* send stk as LTK response */ + btm_ble_ltk_request_reply(p_cb->pairing_bda, true, p_data->key.p_data); } /******************************************************************************* * Function smp_proc_sec_req * Description process security request. ******************************************************************************/ -void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_LE_AUTH_REQ auth_req = *(tBTM_LE_AUTH_REQ *)p_data; - tBTM_BLE_SEC_REQ_ACT sec_req_act; - uint8_t reason; +void smp_proc_sec_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_LE_AUTH_REQ auth_req = *(tBTM_LE_AUTH_REQ*)p_data; + tBTM_BLE_SEC_REQ_ACT sec_req_act; + uint8_t reason; - SMP_TRACE_DEBUG("%s auth_req=0x%x", __func__, auth_req); + SMP_TRACE_DEBUG("%s auth_req=0x%x", __func__, auth_req); - p_cb->cb_evt = 0; + p_cb->cb_evt = 0; - btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act); + btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act); - SMP_TRACE_DEBUG("%s sec_req_act=0x%x", __func__, sec_req_act); + SMP_TRACE_DEBUG("%s sec_req_act=0x%x", __func__, sec_req_act); - switch (sec_req_act) - { - case BTM_BLE_SEC_REQ_ACT_ENCRYPT: - SMP_TRACE_DEBUG("%s BTM_BLE_SEC_REQ_ACT_ENCRYPT", __func__); - smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); - break; - - case BTM_BLE_SEC_REQ_ACT_PAIR: - p_cb->secure_connections_only_mode_required = - (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false; - - /* respond to non SC pairing request as failure in SC only mode */ - if (p_cb->secure_connections_only_mode_required && - (auth_req & SMP_SC_SUPPORT_BIT) == 0) - { - reason = SMP_PAIR_AUTH_FAIL; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - } - else - { - /* initialize local i/r key to be default keys */ - p_cb->peer_auth_req = auth_req; - p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY ; - p_cb->cb_evt = SMP_SEC_REQUEST_EVT; - } - break; - - case BTM_BLE_SEC_REQ_ACT_DISCARD: - p_cb->discard_sec_req = true; - break; - - default: - /* do nothing */ - break; - } + switch (sec_req_act) { + case BTM_BLE_SEC_REQ_ACT_ENCRYPT: + SMP_TRACE_DEBUG("%s BTM_BLE_SEC_REQ_ACT_ENCRYPT", __func__); + smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); + break; + + case BTM_BLE_SEC_REQ_ACT_PAIR: + p_cb->secure_connections_only_mode_required = + (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false; + + /* respond to non SC pairing request as failure in SC only mode */ + if (p_cb->secure_connections_only_mode_required && + (auth_req & SMP_SC_SUPPORT_BIT) == 0) { + reason = SMP_PAIR_AUTH_FAIL; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + } else { + /* initialize local i/r key to be default keys */ + p_cb->peer_auth_req = auth_req; + p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY; + p_cb->cb_evt = SMP_SEC_REQUEST_EVT; + } + break; + + case BTM_BLE_SEC_REQ_ACT_DISCARD: + p_cb->discard_sec_req = true; + break; + + default: + /* do nothing */ + break; + } } /******************************************************************************* * Function smp_proc_sec_grant * Description process security grant. ******************************************************************************/ -void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t res= *(uint8_t *)p_data; - SMP_TRACE_DEBUG("%s", __func__); - if (res != SMP_SUCCESS) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, p_data); - } - else /*otherwise, start pairing */ - { - /* send IO request callback */ - p_cb->cb_evt = SMP_IO_CAP_REQ_EVT; - } +void smp_proc_sec_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t res = *(uint8_t*)p_data; + SMP_TRACE_DEBUG("%s", __func__); + if (res != SMP_SUCCESS) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, p_data); + } else /*otherwise, start pairing */ + { + /* send IO request callback */ + p_cb->cb_evt = SMP_IO_CAP_REQ_EVT; + } } /******************************************************************************* * Function smp_proc_pair_fail * Description process pairing failure from peer device ******************************************************************************/ -void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - p_cb->status = *(uint8_t *)p_data; +void smp_proc_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->status = *(uint8_t*)p_data; - /* Cancel pending auth complete timer if set */ - alarm_cancel(p_cb->delayed_auth_timer_ent); + /* Cancel pending auth complete timer if set */ + alarm_cancel(p_cb->delayed_auth_timer_ent); } /******************************************************************************* * Function smp_proc_pair_cmd * Description Process the SMP pairing request/response from peer device ******************************************************************************/ -void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_ENC_KEY_SIZE; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda); +void smp_proc_pair_cmd(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_ENC_KEY_SIZE; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); - SMP_TRACE_DEBUG("%s", __func__); - /* erase all keys if it is slave proc pairing req*/ - if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) - btm_sec_clear_ble_keys(p_dev_rec); + SMP_TRACE_DEBUG("%s", __func__); + /* erase all keys if it is slave proc pairing req*/ + if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) + btm_sec_clear_ble_keys(p_dev_rec); - p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; + p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; - STREAM_TO_UINT8(p_cb->peer_io_caps, p); - STREAM_TO_UINT8(p_cb->peer_oob_flag, p); - STREAM_TO_UINT8(p_cb->peer_auth_req, p); - STREAM_TO_UINT8(p_cb->peer_enc_size, p); - STREAM_TO_UINT8(p_cb->peer_i_key, p); - STREAM_TO_UINT8(p_cb->peer_r_key, p); + STREAM_TO_UINT8(p_cb->peer_io_caps, p); + STREAM_TO_UINT8(p_cb->peer_oob_flag, p); + STREAM_TO_UINT8(p_cb->peer_auth_req, p); + STREAM_TO_UINT8(p_cb->peer_enc_size, p); + STREAM_TO_UINT8(p_cb->peer_i_key, p); + STREAM_TO_UINT8(p_cb->peer_r_key, p); - if (smp_command_has_invalid_parameters(p_cb)) - { - reason = SMP_INVALID_PARAMETERS; + if (smp_command_has_invalid_parameters(p_cb)) { + reason = SMP_INVALID_PARAMETERS; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } + + // PTS Testing failure modes + if (pts_test_send_authentication_complete_failure(p_cb)) return; + + if (p_cb->role == HCI_ROLE_SLAVE) { + if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) { + /* peer (master) started pairing sending Pairing Request */ + p_cb->local_i_key = p_cb->peer_i_key; + p_cb->local_r_key = p_cb->peer_r_key; + + p_cb->cb_evt = SMP_SEC_REQUEST_EVT; + } else /* update local i/r key according to pairing request */ + { + /* pairing started with this side (slave) sending Security Request */ + p_cb->local_i_key &= p_cb->peer_i_key; + p_cb->local_r_key &= p_cb->peer_r_key; + p_cb->selected_association_model = smp_select_association_model(p_cb); + + if (p_cb->secure_connections_only_mode_required && + (!(p_cb->le_secure_connections_mode_is_used) || + (p_cb->selected_association_model == + SMP_MODEL_SEC_CONN_JUSTWORKS))) { + SMP_TRACE_ERROR( + "%s pairing failed - slave requires secure connection only mode", + __func__); + reason = SMP_PAIR_AUTH_FAIL; smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); return; - } - - // PTS Testing failure modes - if (pts_test_send_authentication_complete_failure(p_cb)) - return; + } - if (p_cb->role == HCI_ROLE_SLAVE) - { - if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) - { - /* peer (master) started pairing sending Pairing Request */ - p_cb->local_i_key = p_cb->peer_i_key; - p_cb->local_r_key = p_cb->peer_r_key; - - p_cb->cb_evt = SMP_SEC_REQUEST_EVT; - } - else /* update local i/r key according to pairing request */ - { - /* pairing started with this side (slave) sending Security Request */ - p_cb->local_i_key &= p_cb->peer_i_key; - p_cb->local_r_key &= p_cb->peer_r_key; - p_cb->selected_association_model = smp_select_association_model(p_cb); - - if (p_cb->secure_connections_only_mode_required && - (!(p_cb->le_secure_connections_mode_is_used) || - (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) - { - SMP_TRACE_ERROR("%s pairing failed - slave requires secure connection only mode", - __func__); - reason = SMP_PAIR_AUTH_FAIL; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } - - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) - { - if (smp_request_oob_data(p_cb)) return; - } - else - { - smp_send_pair_rsp(p_cb, NULL); - } - } + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { + if (smp_request_oob_data(p_cb)) return; + } else { + smp_send_pair_rsp(p_cb, NULL); + } } - else /* Master receives pairing response */ - { - p_cb->selected_association_model = smp_select_association_model(p_cb); + } else /* Master receives pairing response */ + { + p_cb->selected_association_model = smp_select_association_model(p_cb); - if (p_cb->secure_connections_only_mode_required && - (!(p_cb->le_secure_connections_mode_is_used) || - (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) - { - SMP_TRACE_ERROR ("Master requires secure connection only mode \ + if (p_cb->secure_connections_only_mode_required && + (!(p_cb->le_secure_connections_mode_is_used) || + (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) { + SMP_TRACE_ERROR( + "Master requires secure connection only mode \ but it can't be provided -> Master fails pairing"); - reason = SMP_PAIR_AUTH_FAIL; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + reason = SMP_PAIR_AUTH_FAIL; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) - { - if (smp_request_oob_data(p_cb)) return; - } - else - { - smp_decide_association_model(p_cb, NULL); - } + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { + if (smp_request_oob_data(p_cb)) return; + } else { + smp_decide_association_model(p_cb, NULL); } + } } /******************************************************************************* * Function smp_proc_confirm * Description process pairing confirm from peer device ******************************************************************************/ -void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_proc_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - if (p != NULL) - { - /* save the SConfirm for comparison later */ - STREAM_TO_ARRAY(p_cb->rconfirm, p, BT_OCTET16_LEN); - } + if (p != NULL) { + /* save the SConfirm for comparison later */ + STREAM_TO_ARRAY(p_cb->rconfirm, p, BT_OCTET16_LEN); + } - p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM; + p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM; } /******************************************************************************* * Function smp_proc_init * Description process pairing initializer from peer device ******************************************************************************/ -void smp_proc_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_proc_init(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - /* save the SRand for comparison */ - STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN); + /* save the SRand for comparison */ + STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN); } /******************************************************************************* * Function smp_proc_rand * Description process pairing random (nonce) from peer device ******************************************************************************/ -void smp_proc_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_proc_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - /* save the SRand for comparison */ - STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN); + /* save the SRand for comparison */ + STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN); } /******************************************************************************* @@ -718,103 +659,90 @@ void smp_proc_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * - calls smp_wait_for_both_public_keys(...). * ******************************************************************************/ -void smp_process_pairing_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_process_pairing_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - STREAM_TO_ARRAY(p_cb->peer_publ_key.x, p, BT_OCTET32_LEN); - STREAM_TO_ARRAY(p_cb->peer_publ_key.y, p, BT_OCTET32_LEN); - p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY; + STREAM_TO_ARRAY(p_cb->peer_publ_key.x, p, BT_OCTET32_LEN); + STREAM_TO_ARRAY(p_cb->peer_publ_key.y, p, BT_OCTET32_LEN); + p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY; - smp_wait_for_both_public_keys(p_cb, NULL); + smp_wait_for_both_public_keys(p_cb, NULL); } /******************************************************************************* * Function smp_process_pairing_commitment * Description process pairing commitment from peer device ******************************************************************************/ -void smp_process_pairing_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_process_pairing_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_COMM; + p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_COMM; - if (p != NULL) - { - STREAM_TO_ARRAY(p_cb->remote_commitment, p, BT_OCTET16_LEN); - } + if (p != NULL) { + STREAM_TO_ARRAY(p_cb->remote_commitment, p, BT_OCTET16_LEN); + } } /******************************************************************************* * Function smp_process_dhkey_check * Description process DHKey Check from peer device ******************************************************************************/ -void smp_process_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_process_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - if (p != NULL) - { - STREAM_TO_ARRAY(p_cb->remote_dhkey_check, p, BT_OCTET16_LEN); - } + if (p != NULL) { + STREAM_TO_ARRAY(p_cb->remote_dhkey_check, p, BT_OCTET16_LEN); + } - p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK; + p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK; } /******************************************************************************* * Function smp_process_keypress_notification * Description process pairing keypress notification from peer device ******************************************************************************/ -void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_INVALID_PARAMETERS; +void smp_process_keypress_notification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_INVALID_PARAMETERS; - SMP_TRACE_DEBUG("%s", __func__); - p_cb->status = *(uint8_t *)p_data; + SMP_TRACE_DEBUG("%s", __func__); + p_cb->status = *(uint8_t*)p_data; - if (smp_command_has_invalid_parameters(p_cb)) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (smp_command_has_invalid_parameters(p_cb)) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - if (p != NULL) - { - STREAM_TO_UINT8(p_cb->peer_keypress_notification, p); - } - else - { - p_cb->peer_keypress_notification = BTM_SP_KEY_OUT_OF_RANGE; - } - p_cb->cb_evt = SMP_PEER_KEYPR_NOT_EVT; + if (p != NULL) { + STREAM_TO_UINT8(p_cb->peer_keypress_notification, p); + } else { + p_cb->peer_keypress_notification = BTM_SP_KEY_OUT_OF_RANGE; + } + p_cb->cb_evt = SMP_PEER_KEYPR_NOT_EVT; } /******************************************************************************* @@ -822,81 +750,75 @@ void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description Process the SMP pairing request/response from peer device via * BR/EDR transport. ******************************************************************************/ -void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - uint8_t reason = SMP_ENC_KEY_SIZE; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda); - - SMP_TRACE_DEBUG("%s", __func__); - /* rejecting BR pairing request over non-SC BR link */ - if (!p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) - { - reason = SMP_XTRANS_DERIVE_NOT_ALLOW; - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); - return; - } - - /* erase all keys if it is slave proc pairing req*/ - if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) - btm_sec_clear_ble_keys(p_dev_rec); - - p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; - - STREAM_TO_UINT8(p_cb->peer_io_caps, p); - STREAM_TO_UINT8(p_cb->peer_oob_flag, p); - STREAM_TO_UINT8(p_cb->peer_auth_req, p); - STREAM_TO_UINT8(p_cb->peer_enc_size, p); - STREAM_TO_UINT8(p_cb->peer_i_key, p); - STREAM_TO_UINT8(p_cb->peer_r_key, p); - - if (smp_command_has_invalid_parameters(p_cb)) - { - reason = SMP_INVALID_PARAMETERS; - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); - return; - } - - /* peer (master) started pairing sending Pairing Request */ - /* or being master device always use received i/r key as keys to distribute */ - p_cb->local_i_key = p_cb->peer_i_key; - p_cb->local_r_key = p_cb->peer_r_key; - - if (p_cb->role == HCI_ROLE_SLAVE) - { - p_dev_rec->new_encryption_key_is_p256 = false; - /* shortcut to skip Security Grant step */ - p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; - } - else /* Master receives pairing response */ - { - SMP_TRACE_DEBUG("%s master rcvs valid PAIRING RESPONSE." - " Supposed to move to key distribution phase. ", __func__); - } - - /* auth_req received via BR/EDR SM channel is set to 0, - but everything derived/exchanged has to be saved */ - p_cb->peer_auth_req |= SMP_AUTH_BOND; - p_cb->loc_auth_req |= SMP_AUTH_BOND; +void smp_br_process_pairing_command(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + uint8_t reason = SMP_ENC_KEY_SIZE; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(p_cb->pairing_bda); + + SMP_TRACE_DEBUG("%s", __func__); + /* rejecting BR pairing request over non-SC BR link */ + if (!p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) { + reason = SMP_XTRANS_DERIVE_NOT_ALLOW; + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); + return; + } + + /* erase all keys if it is slave proc pairing req*/ + if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) + btm_sec_clear_ble_keys(p_dev_rec); + + p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR; + + STREAM_TO_UINT8(p_cb->peer_io_caps, p); + STREAM_TO_UINT8(p_cb->peer_oob_flag, p); + STREAM_TO_UINT8(p_cb->peer_auth_req, p); + STREAM_TO_UINT8(p_cb->peer_enc_size, p); + STREAM_TO_UINT8(p_cb->peer_i_key, p); + STREAM_TO_UINT8(p_cb->peer_r_key, p); + + if (smp_command_has_invalid_parameters(p_cb)) { + reason = SMP_INVALID_PARAMETERS; + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); + return; + } + + /* peer (master) started pairing sending Pairing Request */ + /* or being master device always use received i/r key as keys to distribute */ + p_cb->local_i_key = p_cb->peer_i_key; + p_cb->local_r_key = p_cb->peer_r_key; + + if (p_cb->role == HCI_ROLE_SLAVE) { + p_dev_rec->new_encryption_key_is_p256 = false; + /* shortcut to skip Security Grant step */ + p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; + } else /* Master receives pairing response */ + { + SMP_TRACE_DEBUG( + "%s master rcvs valid PAIRING RESPONSE." + " Supposed to move to key distribution phase. ", + __func__); + } + + /* auth_req received via BR/EDR SM channel is set to 0, + but everything derived/exchanged has to be saved */ + p_cb->peer_auth_req |= SMP_AUTH_BOND; + p_cb->loc_auth_req |= SMP_AUTH_BOND; } /******************************************************************************* * Function smp_br_process_security_grant * Description process security grant in case of pairing over BR/EDR transport. ******************************************************************************/ -void smp_br_process_security_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t res= *(uint8_t *)p_data; - SMP_TRACE_DEBUG("%s", __func__); - if (res != SMP_SUCCESS) - { - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, p_data); - } - else /*otherwise, start pairing */ - { - /* send IO request callback */ - p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; - } +void smp_br_process_security_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t res = *(uint8_t*)p_data; + SMP_TRACE_DEBUG("%s", __func__); + if (res != SMP_SUCCESS) { + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, p_data); + } else /*otherwise, start pairing */ + { + /* send IO request callback */ + p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; + } } /******************************************************************************* @@ -904,43 +826,40 @@ void smp_br_process_security_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description sets the SMP kes to be derived/distribute over BR/EDR transport * before starting the distribution/derivation ******************************************************************************/ -void smp_br_check_authorization_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason = SMP_SUCCESS; +void smp_br_check_authorization_request(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason = SMP_SUCCESS; - SMP_TRACE_DEBUG("%s rcvs i_keys=0x%x r_keys=0x%x " - "(i-initiator r-responder)", __func__, p_cb->local_i_key, - p_cb->local_r_key); + SMP_TRACE_DEBUG( + "%s rcvs i_keys=0x%x r_keys=0x%x " + "(i-initiator r-responder)", + __func__, p_cb->local_i_key, p_cb->local_r_key); - /* In LE SC mode LK field is ignored when BR/EDR transport is used */ - p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; - p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; + /* In LE SC mode LK field is ignored when BR/EDR transport is used */ + p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; + p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; - /* In LE SC mode only IRK, IAI, CSRK are exchanged with the peer. - ** Set local_r_key on master to expect only these keys. */ - if (p_cb->role == HCI_ROLE_MASTER) - { - p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); - } + /* In LE SC mode only IRK, IAI, CSRK are exchanged with the peer. + ** Set local_r_key on master to expect only these keys. */ + if (p_cb->role == HCI_ROLE_MASTER) { + p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); + } - SMP_TRACE_DEBUG("%s rcvs upgrades: i_keys=0x%x r_keys=0x%x " - "(i-initiator r-responder)", __func__, p_cb->local_i_key, - p_cb->local_r_key); + SMP_TRACE_DEBUG( + "%s rcvs upgrades: i_keys=0x%x r_keys=0x%x " + "(i-initiator r-responder)", + __func__, p_cb->local_i_key, p_cb->local_r_key); - if (/*((p_cb->peer_auth_req & SMP_AUTH_BOND) || - (p_cb->loc_auth_req & SMP_AUTH_BOND)) &&*/ - (p_cb->local_i_key || p_cb->local_r_key)) - { - smp_br_state_machine_event(p_cb, SMP_BR_BOND_REQ_EVT, NULL); + if (/*((p_cb->peer_auth_req & SMP_AUTH_BOND) || + (p_cb->loc_auth_req & SMP_AUTH_BOND)) &&*/ + (p_cb->local_i_key || p_cb->local_r_key)) { + smp_br_state_machine_event(p_cb, SMP_BR_BOND_REQ_EVT, NULL); - /* if no peer key is expected, start master key distribution */ - if (p_cb->role == HCI_ROLE_MASTER && p_cb->local_r_key == 0) - smp_key_distribution_by_transport(p_cb, NULL); - } - else - { - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); - } + /* if no peer key is expected, start master key distribution */ + if (p_cb->role == HCI_ROLE_MASTER && p_cb->local_r_key == 0) + smp_key_distribution_by_transport(p_cb, NULL); + } else { + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); + } } /******************************************************************************* @@ -948,372 +867,336 @@ void smp_br_check_authorization_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description selects the next key to derive/send when BR/EDR transport is * used. ******************************************************************************/ -void smp_br_select_next_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason = SMP_SUCCESS; - SMP_TRACE_DEBUG("%s role=%d (0-master) r_keys=0x%x i_keys=0x%x", - __func__, p_cb->role, p_cb->local_r_key, p_cb->local_i_key); +void smp_br_select_next_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason = SMP_SUCCESS; + SMP_TRACE_DEBUG("%s role=%d (0-master) r_keys=0x%x i_keys=0x%x", __func__, + p_cb->role, p_cb->local_r_key, p_cb->local_i_key); - if (p_cb->role == HCI_ROLE_SLAVE|| - (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) - { - smp_key_pick_key(p_cb, p_data); - } + if (p_cb->role == HCI_ROLE_SLAVE || + (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) { + smp_key_pick_key(p_cb, p_data); + } - if (!p_cb->local_i_key && !p_cb->local_r_key) - { - /* state check to prevent re-entrance */ - if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) - { - if (p_cb->total_tx_unacked == 0) - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); - else - p_cb->wait_for_authorization_complete = true; - } + if (!p_cb->local_i_key && !p_cb->local_r_key) { + /* state check to prevent re-entrance */ + if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) { + if (p_cb->total_tx_unacked == 0) + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); + else + p_cb->wait_for_authorization_complete = true; } + } } /******************************************************************************* * Function smp_proc_enc_info * Description process encryption information from peer device ******************************************************************************/ -void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; +void smp_proc_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; - SMP_TRACE_DEBUG("%s", __func__); - STREAM_TO_ARRAY(p_cb->ltk, p, BT_OCTET16_LEN); + SMP_TRACE_DEBUG("%s", __func__); + STREAM_TO_ARRAY(p_cb->ltk, p, BT_OCTET16_LEN); - smp_key_distribution(p_cb, NULL); + smp_key_distribution(p_cb, NULL); } /******************************************************************************* * Function smp_proc_master_id * Description process master ID from slave device ******************************************************************************/ -void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - tBTM_LE_PENC_KEYS le_key; +void smp_proc_master_id(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + tBTM_LE_PENC_KEYS le_key; - SMP_TRACE_DEBUG("%s", __func__); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, true); + SMP_TRACE_DEBUG("%s", __func__); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, true); - STREAM_TO_UINT16(le_key.ediv, p); - STREAM_TO_ARRAY(le_key.rand, p, BT_OCTET8_LEN ); + STREAM_TO_UINT16(le_key.ediv, p); + STREAM_TO_ARRAY(le_key.rand, p, BT_OCTET8_LEN); - /* store the encryption keys from peer device */ - memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); - le_key.sec_level = p_cb->sec_level; - le_key.key_size = p_cb->loc_enc_size; + /* store the encryption keys from peer device */ + memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); + le_key.sec_level = p_cb->sec_level; + le_key.key_size = p_cb->loc_enc_size; - if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) - btm_sec_save_le_key(p_cb->pairing_bda, - BTM_LE_KEY_PENC, - (tBTM_LE_KEY_VALUE *)&le_key, true); + if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && + (p_cb->loc_auth_req & SMP_AUTH_BOND)) + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, + (tBTM_LE_KEY_VALUE*)&le_key, true); - smp_key_distribution(p_cb, NULL); + smp_key_distribution(p_cb, NULL); } /******************************************************************************* * Function smp_proc_enc_info * Description process identity information from peer device ******************************************************************************/ -void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; +void smp_proc_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; - SMP_TRACE_DEBUG("%s", __func__); - STREAM_TO_ARRAY (p_cb->tk, p, BT_OCTET16_LEN); /* reuse TK for IRK */ - smp_key_distribution_by_transport(p_cb, NULL); + SMP_TRACE_DEBUG("%s", __func__); + STREAM_TO_ARRAY(p_cb->tk, p, BT_OCTET16_LEN); /* reuse TK for IRK */ + smp_key_distribution_by_transport(p_cb, NULL); } /******************************************************************************* * Function smp_proc_id_addr * Description process identity address from peer device ******************************************************************************/ -void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = (uint8_t *)p_data; - tBTM_LE_PID_KEYS pid_key; +void smp_proc_id_addr(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = (uint8_t*)p_data; + tBTM_LE_PID_KEYS pid_key; - SMP_TRACE_DEBUG("%s", __func__); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, true); + SMP_TRACE_DEBUG("%s", __func__); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ID, true); - STREAM_TO_UINT8(pid_key.addr_type, p); - STREAM_TO_BDADDR(pid_key.static_addr, p); - memcpy(pid_key.irk, p_cb->tk, BT_OCTET16_LEN); + STREAM_TO_UINT8(pid_key.addr_type, p); + STREAM_TO_BDADDR(pid_key.static_addr, p); + memcpy(pid_key.irk, p_cb->tk, BT_OCTET16_LEN); - /* to use as BD_ADDR for lk derived from ltk */ - p_cb->id_addr_rcvd = true; - p_cb->id_addr_type = pid_key.addr_type; - memcpy(p_cb->id_addr, pid_key.static_addr, BD_ADDR_LEN); + /* to use as BD_ADDR for lk derived from ltk */ + p_cb->id_addr_rcvd = true; + p_cb->id_addr_type = pid_key.addr_type; + memcpy(p_cb->id_addr, pid_key.static_addr, BD_ADDR_LEN); - /* store the ID key from peer device */ - if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, - (tBTM_LE_KEY_VALUE *)&pid_key, true); - smp_key_distribution_by_transport(p_cb, NULL); + /* store the ID key from peer device */ + if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && + (p_cb->loc_auth_req & SMP_AUTH_BOND)) + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, + (tBTM_LE_KEY_VALUE*)&pid_key, true); + smp_key_distribution_by_transport(p_cb, NULL); } /******************************************************************************* * Function smp_proc_srk_info * Description process security information from peer device ******************************************************************************/ -void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_LE_PCSRK_KEYS le_key; +void smp_proc_srk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_LE_PCSRK_KEYS le_key; - SMP_TRACE_DEBUG("%s", __func__); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, true); + SMP_TRACE_DEBUG("%s", __func__); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_CSRK, true); - /* save CSRK to security record */ - le_key.sec_level = p_cb->sec_level; - memcpy (le_key.csrk, p_data, BT_OCTET16_LEN); /* get peer CSRK */ - le_key.counter = 0; /* initialize the peer counter */ + /* save CSRK to security record */ + le_key.sec_level = p_cb->sec_level; + memcpy(le_key.csrk, p_data, BT_OCTET16_LEN); /* get peer CSRK */ + le_key.counter = 0; /* initialize the peer counter */ - if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) - btm_sec_save_le_key(p_cb->pairing_bda, - BTM_LE_KEY_PCSRK, - (tBTM_LE_KEY_VALUE *)&le_key, true); - smp_key_distribution_by_transport(p_cb, NULL); + if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && + (p_cb->loc_auth_req & SMP_AUTH_BOND)) + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PCSRK, + (tBTM_LE_KEY_VALUE*)&le_key, true); + smp_key_distribution_by_transport(p_cb, NULL); } /******************************************************************************* * Function smp_proc_compare * Description process compare value ******************************************************************************/ -void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason; +void smp_proc_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason; - SMP_TRACE_DEBUG("%s", __func__); - if (!memcmp(p_cb->rconfirm, p_data->key.p_data, BT_OCTET16_LEN)) - { - /* compare the max encryption key size, and save the smaller one for the link */ - if ( p_cb->peer_enc_size < p_cb->loc_enc_size) - p_cb->loc_enc_size = p_cb->peer_enc_size; - - if (p_cb->role == HCI_ROLE_SLAVE) - smp_sm_event(p_cb, SMP_RAND_EVT, NULL); - else - { - /* master device always use received i/r key as keys to distribute */ - p_cb->local_i_key = p_cb->peer_i_key; - p_cb->local_r_key = p_cb->peer_r_key; - - smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); - } + SMP_TRACE_DEBUG("%s", __func__); + if (!memcmp(p_cb->rconfirm, p_data->key.p_data, BT_OCTET16_LEN)) { + /* compare the max encryption key size, and save the smaller one for the + * link */ + if (p_cb->peer_enc_size < p_cb->loc_enc_size) + p_cb->loc_enc_size = p_cb->peer_enc_size; + if (p_cb->role == HCI_ROLE_SLAVE) + smp_sm_event(p_cb, SMP_RAND_EVT, NULL); + else { + /* master device always use received i/r key as keys to distribute */ + p_cb->local_i_key = p_cb->peer_i_key; + p_cb->local_r_key = p_cb->peer_r_key; + + smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); } - else - { - reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - } + + } else { + reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + } } /******************************************************************************* * Function smp_proc_sl_key * Description process key ready events. ******************************************************************************/ -void smp_proc_sl_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t key_type = p_data->key.key_type; +void smp_proc_sl_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t key_type = p_data->key.key_type; - SMP_TRACE_DEBUG("%s", __func__); - if (key_type == SMP_KEY_TYPE_TK) - { - smp_generate_srand_mrand_confirm(p_cb, NULL); - } - else if (key_type == SMP_KEY_TYPE_CFM) - { - smp_set_state(SMP_STATE_WAIT_CONFIRM); + SMP_TRACE_DEBUG("%s", __func__); + if (key_type == SMP_KEY_TYPE_TK) { + smp_generate_srand_mrand_confirm(p_cb, NULL); + } else if (key_type == SMP_KEY_TYPE_CFM) { + smp_set_state(SMP_STATE_WAIT_CONFIRM); - if (p_cb->flags & SMP_PAIR_FLAGS_CMD_CONFIRM) - smp_sm_event(p_cb, SMP_CONFIRM_EVT, NULL); - } + if (p_cb->flags & SMP_PAIR_FLAGS_CMD_CONFIRM) + smp_sm_event(p_cb, SMP_CONFIRM_EVT, NULL); + } } /******************************************************************************* * Function smp_start_enc * Description start encryption ******************************************************************************/ -void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tBTM_STATUS cmd; - uint8_t reason = SMP_ENC_FAIL; +void smp_start_enc(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tBTM_STATUS cmd; + uint8_t reason = SMP_ENC_FAIL; - SMP_TRACE_DEBUG("%s", __func__); - if (p_data != NULL) - cmd = btm_ble_start_encrypt(p_cb->pairing_bda, true, p_data->key.p_data); - else - cmd = btm_ble_start_encrypt(p_cb->pairing_bda, false, NULL); + SMP_TRACE_DEBUG("%s", __func__); + if (p_data != NULL) + cmd = btm_ble_start_encrypt(p_cb->pairing_bda, true, p_data->key.p_data); + else + cmd = btm_ble_start_encrypt(p_cb->pairing_bda, false, NULL); - if (cmd != BTM_CMD_STARTED && cmd != BTM_BUSY) - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + if (cmd != BTM_CMD_STARTED && cmd != BTM_BUSY) + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); } /******************************************************************************* * Function smp_proc_discard * Description processing for discard security request ******************************************************************************/ -void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) - smp_reset_control_value(p_cb); +void smp_proc_discard(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) + smp_reset_control_value(p_cb); } /******************************************************************************* * Function smp_enc_cmpl * Description encryption success ******************************************************************************/ -void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t enc_enable = *(uint8_t *)p_data; - uint8_t reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL; +void smp_enc_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t enc_enable = *(uint8_t*)p_data; + uint8_t reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL; - SMP_TRACE_DEBUG("%s", __func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + SMP_TRACE_DEBUG("%s", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); } /******************************************************************************* * Function smp_check_auth_req * Description check authentication request ******************************************************************************/ -void smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t enc_enable = *(uint8_t *)p_data; - uint8_t reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL; - - SMP_TRACE_DEBUG("%s rcvs enc_enable=%d i_keys=0x%x r_keys=0x%x " - "(i-initiator r-responder)", - __func__, enc_enable, p_cb->local_i_key, p_cb->local_r_key); - if (enc_enable == 1) - { - if (p_cb->le_secure_connections_mode_is_used) - { - /* In LE SC mode LTK is used instead of STK and has to be always saved */ - p_cb->local_i_key |= SMP_SEC_KEY_TYPE_ENC; - p_cb->local_r_key |= SMP_SEC_KEY_TYPE_ENC; - - /* In LE SC mode LK is derived from LTK only if both sides request it */ - if (!(p_cb->local_i_key & SMP_SEC_KEY_TYPE_LK) || - !(p_cb->local_r_key & SMP_SEC_KEY_TYPE_LK)) - { - p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; - p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; - } - - /* In LE SC mode only IRK, IAI, CSRK are exchanged with the peer. - ** Set local_r_key on master to expect only these keys. - */ - if (p_cb->role == HCI_ROLE_MASTER) - { - p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); - } - } - else - { - /* in legacy mode derivation of BR/EDR LK is not supported */ - p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; - p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; - } - SMP_TRACE_DEBUG("%s rcvs upgrades: i_keys=0x%x r_keys=0x%x " - "(i-initiator r-responder)", - __func__, p_cb->local_i_key, p_cb->local_r_key); - - if (/*((p_cb->peer_auth_req & SMP_AUTH_BOND) || - (p_cb->loc_auth_req & SMP_AUTH_BOND)) &&*/ - (p_cb->local_i_key || p_cb->local_r_key)) - { - smp_sm_event(p_cb, SMP_BOND_REQ_EVT, NULL); - } - else - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); +void smp_check_auth_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t enc_enable = *(uint8_t*)p_data; + uint8_t reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL; + + SMP_TRACE_DEBUG( + "%s rcvs enc_enable=%d i_keys=0x%x r_keys=0x%x " + "(i-initiator r-responder)", + __func__, enc_enable, p_cb->local_i_key, p_cb->local_r_key); + if (enc_enable == 1) { + if (p_cb->le_secure_connections_mode_is_used) { + /* In LE SC mode LTK is used instead of STK and has to be always saved */ + p_cb->local_i_key |= SMP_SEC_KEY_TYPE_ENC; + p_cb->local_r_key |= SMP_SEC_KEY_TYPE_ENC; + + /* In LE SC mode LK is derived from LTK only if both sides request it */ + if (!(p_cb->local_i_key & SMP_SEC_KEY_TYPE_LK) || + !(p_cb->local_r_key & SMP_SEC_KEY_TYPE_LK)) { + p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; + p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; + } + + /* In LE SC mode only IRK, IAI, CSRK are exchanged with the peer. + ** Set local_r_key on master to expect only these keys. + */ + if (p_cb->role == HCI_ROLE_MASTER) { + p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK); + } + } else { + /* in legacy mode derivation of BR/EDR LK is not supported */ + p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK; + p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK; } - else if (enc_enable == 0) - { - /* if failed for encryption after pairing, send callback */ - if (p_cb->flags & SMP_PAIR_FLAG_ENC_AFTER_PAIR) - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - /* if enc failed for old security information */ - /* if master device, clean up and abck to idle; slave device do nothing */ - else if (p_cb->role == HCI_ROLE_MASTER) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - } + SMP_TRACE_DEBUG( + "%s rcvs upgrades: i_keys=0x%x r_keys=0x%x " + "(i-initiator r-responder)", + __func__, p_cb->local_i_key, p_cb->local_r_key); + + if (/*((p_cb->peer_auth_req & SMP_AUTH_BOND) || + (p_cb->loc_auth_req & SMP_AUTH_BOND)) &&*/ + (p_cb->local_i_key || p_cb->local_r_key)) { + smp_sm_event(p_cb, SMP_BOND_REQ_EVT, NULL); + } else + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + } else if (enc_enable == 0) { + /* if failed for encryption after pairing, send callback */ + if (p_cb->flags & SMP_PAIR_FLAG_ENC_AFTER_PAIR) + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + /* if enc failed for old security information */ + /* if master device, clean up and abck to idle; slave device do nothing */ + else if (p_cb->role == HCI_ROLE_MASTER) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); } + } } /******************************************************************************* * Function smp_key_pick_key * Description Pick a key distribution function based on the key mask. ******************************************************************************/ -void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t key_to_dist = (p_cb->role == HCI_ROLE_SLAVE) ? p_cb->local_r_key : p_cb->local_i_key; - uint8_t i = 0; +void smp_key_pick_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t key_to_dist = + (p_cb->role == HCI_ROLE_SLAVE) ? p_cb->local_r_key : p_cb->local_i_key; + uint8_t i = 0; - SMP_TRACE_DEBUG("%s key_to_dist=0x%x", __func__, key_to_dist); - while (i < SMP_KEY_DIST_TYPE_MAX) - { - SMP_TRACE_DEBUG("key to send = %02x, i = %d", key_to_dist, i); + SMP_TRACE_DEBUG("%s key_to_dist=0x%x", __func__, key_to_dist); + while (i < SMP_KEY_DIST_TYPE_MAX) { + SMP_TRACE_DEBUG("key to send = %02x, i = %d", key_to_dist, i); - if (key_to_dist & (1 << i)) - { - SMP_TRACE_DEBUG("smp_distribute_act[%d]", i); - (* smp_distribute_act[i])(p_cb, p_data); - break; - } - i ++; + if (key_to_dist & (1 << i)) { + SMP_TRACE_DEBUG("smp_distribute_act[%d]", i); + (*smp_distribute_act[i])(p_cb, p_data); + break; } + i++; + } } /******************************************************************************* * Function smp_key_distribution * Description start key distribution if required. ******************************************************************************/ -void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s role=%d (0-master) r_keys=0x%x i_keys=0x%x", - __func__, p_cb->role, p_cb->local_r_key, p_cb->local_i_key); - - if (p_cb->role == HCI_ROLE_SLAVE || - (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) - { - smp_key_pick_key(p_cb, p_data); - } - - if (!p_cb->local_i_key && !p_cb->local_r_key) - { - /* state check to prevent re-entrant */ - if (smp_get_state() == SMP_STATE_BOND_PENDING) - { - if (p_cb->derive_lk) - { - smp_derive_link_key_from_long_term_key(p_cb, NULL); - p_cb->derive_lk = false; - } - - if (p_cb->total_tx_unacked == 0) - { - /* - * Instead of declaring authorization complete immediately, - * delay the event from being sent by SMP_DELAYED_AUTH_TIMEOUT_MS. - * This allows the slave to send over Pairing Failed if the - * last key is rejected. During this waiting window, the - * state should remain in SMP_STATE_BOND_PENDING. - */ - if (!alarm_is_scheduled(p_cb->delayed_auth_timer_ent)) { - SMP_TRACE_DEBUG("%s delaying auth complete.", __func__); - alarm_set_on_queue(p_cb->delayed_auth_timer_ent, SMP_DELAYED_AUTH_TIMEOUT_MS, - smp_delayed_auth_complete_timeout, NULL, btu_general_alarm_queue); - } - } else { - p_cb->wait_for_authorization_complete = true; - } +void smp_key_distribution(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s role=%d (0-master) r_keys=0x%x i_keys=0x%x", __func__, + p_cb->role, p_cb->local_r_key, p_cb->local_i_key); + + if (p_cb->role == HCI_ROLE_SLAVE || + (!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) { + smp_key_pick_key(p_cb, p_data); + } + + if (!p_cb->local_i_key && !p_cb->local_r_key) { + /* state check to prevent re-entrant */ + if (smp_get_state() == SMP_STATE_BOND_PENDING) { + if (p_cb->derive_lk) { + smp_derive_link_key_from_long_term_key(p_cb, NULL); + p_cb->derive_lk = false; + } + + if (p_cb->total_tx_unacked == 0) { + /* + * Instead of declaring authorization complete immediately, + * delay the event from being sent by SMP_DELAYED_AUTH_TIMEOUT_MS. + * This allows the slave to send over Pairing Failed if the + * last key is rejected. During this waiting window, the + * state should remain in SMP_STATE_BOND_PENDING. + */ + if (!alarm_is_scheduled(p_cb->delayed_auth_timer_ent)) { + SMP_TRACE_DEBUG("%s delaying auth complete.", __func__); + alarm_set_on_queue( + p_cb->delayed_auth_timer_ent, SMP_DELAYED_AUTH_TIMEOUT_MS, + smp_delayed_auth_complete_timeout, NULL, btu_general_alarm_queue); } + } else { + p_cb->wait_for_authorization_complete = true; + } } + } } /******************************************************************************* @@ -1322,134 +1205,129 @@ void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * STK generation and to start STK generation process. * ******************************************************************************/ -void smp_decide_association_model(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t failure = SMP_UNKNOWN_IO_CAP; - uint8_t int_evt = 0; - tSMP_KEY key; - tSMP_INT_DATA *p = NULL; - - SMP_TRACE_DEBUG("%s Association Model = %d", __func__, p_cb->selected_association_model); - - switch (p_cb->selected_association_model) - { - case SMP_MODEL_ENCRYPTION_ONLY: /* TK = 0, go calculate Confirm */ - if (p_cb->role == HCI_ROLE_MASTER && - ((p_cb->peer_auth_req & SMP_AUTH_YN_BIT) != 0) && - ((p_cb->loc_auth_req & SMP_AUTH_YN_BIT) == 0)) - { - SMP_TRACE_ERROR ("IO capability does not meet authentication requirement"); - failure = SMP_PAIR_AUTH_FAIL; - p = (tSMP_INT_DATA *)&failure; - int_evt = SMP_AUTH_CMPL_EVT; - } - else - { - p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; - SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE) ", p_cb->sec_level ); - - key.key_type = SMP_KEY_TYPE_TK; - key.p_data = p_cb->tk; - p = (tSMP_INT_DATA *)&key; - - memset(p_cb->tk, 0, BT_OCTET16_LEN); - /* TK, ready */ - int_evt = SMP_KEY_READY_EVT; - } - break; - - case SMP_MODEL_PASSKEY: - p_cb->sec_level = SMP_SEC_AUTHENTICATED; - SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", p_cb->sec_level ); - - p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; - int_evt = SMP_TK_REQ_EVT; - break; - - case SMP_MODEL_OOB: - SMP_TRACE_ERROR ("Association Model = SMP_MODEL_OOB"); - p_cb->sec_level = SMP_SEC_AUTHENTICATED; - SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", p_cb->sec_level ); - - p_cb->cb_evt = SMP_OOB_REQ_EVT; - int_evt = SMP_TK_REQ_EVT; - break; - - case SMP_MODEL_KEY_NOTIF: - p_cb->sec_level = SMP_SEC_AUTHENTICATED; - SMP_TRACE_DEBUG("Need to generate Passkey"); - - /* generate passkey and notify application */ - smp_generate_passkey(p_cb, NULL); - break; - - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - case SMP_MODEL_SEC_CONN_OOB: - int_evt = SMP_PUBL_KEY_EXCH_REQ_EVT; - break; - - case SMP_MODEL_OUT_OF_RANGE: - SMP_TRACE_ERROR("Association Model = SMP_MODEL_OUT_OF_RANGE (failed)"); - p = (tSMP_INT_DATA *)&failure; - int_evt = SMP_AUTH_CMPL_EVT; - break; - - default: - SMP_TRACE_ERROR("Association Model = %d (SOMETHING IS WRONG WITH THE CODE)", - p_cb->selected_association_model); - p = (tSMP_INT_DATA *)&failure; - int_evt = SMP_AUTH_CMPL_EVT; - } - - SMP_TRACE_EVENT ("sec_level=%d ", p_cb->sec_level ); - if (int_evt) - smp_sm_event(p_cb, int_evt, p); +void smp_decide_association_model(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t failure = SMP_UNKNOWN_IO_CAP; + uint8_t int_evt = 0; + tSMP_KEY key; + tSMP_INT_DATA* p = NULL; + + SMP_TRACE_DEBUG("%s Association Model = %d", __func__, + p_cb->selected_association_model); + + switch (p_cb->selected_association_model) { + case SMP_MODEL_ENCRYPTION_ONLY: /* TK = 0, go calculate Confirm */ + if (p_cb->role == HCI_ROLE_MASTER && + ((p_cb->peer_auth_req & SMP_AUTH_YN_BIT) != 0) && + ((p_cb->loc_auth_req & SMP_AUTH_YN_BIT) == 0)) { + SMP_TRACE_ERROR( + "IO capability does not meet authentication requirement"); + failure = SMP_PAIR_AUTH_FAIL; + p = (tSMP_INT_DATA*)&failure; + int_evt = SMP_AUTH_CMPL_EVT; + } else { + p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; + SMP_TRACE_EVENT("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE) ", + p_cb->sec_level); + + key.key_type = SMP_KEY_TYPE_TK; + key.p_data = p_cb->tk; + p = (tSMP_INT_DATA*)&key; + + memset(p_cb->tk, 0, BT_OCTET16_LEN); + /* TK, ready */ + int_evt = SMP_KEY_READY_EVT; + } + break; + + case SMP_MODEL_PASSKEY: + p_cb->sec_level = SMP_SEC_AUTHENTICATED; + SMP_TRACE_EVENT("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", + p_cb->sec_level); + + p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; + int_evt = SMP_TK_REQ_EVT; + break; + + case SMP_MODEL_OOB: + SMP_TRACE_ERROR("Association Model = SMP_MODEL_OOB"); + p_cb->sec_level = SMP_SEC_AUTHENTICATED; + SMP_TRACE_EVENT("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", + p_cb->sec_level); + + p_cb->cb_evt = SMP_OOB_REQ_EVT; + int_evt = SMP_TK_REQ_EVT; + break; + + case SMP_MODEL_KEY_NOTIF: + p_cb->sec_level = SMP_SEC_AUTHENTICATED; + SMP_TRACE_DEBUG("Need to generate Passkey"); + + /* generate passkey and notify application */ + smp_generate_passkey(p_cb, NULL); + break; + + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + case SMP_MODEL_SEC_CONN_OOB: + int_evt = SMP_PUBL_KEY_EXCH_REQ_EVT; + break; + + case SMP_MODEL_OUT_OF_RANGE: + SMP_TRACE_ERROR("Association Model = SMP_MODEL_OUT_OF_RANGE (failed)"); + p = (tSMP_INT_DATA*)&failure; + int_evt = SMP_AUTH_CMPL_EVT; + break; + + default: + SMP_TRACE_ERROR( + "Association Model = %d (SOMETHING IS WRONG WITH THE CODE)", + p_cb->selected_association_model); + p = (tSMP_INT_DATA*)&failure; + int_evt = SMP_AUTH_CMPL_EVT; + } + + SMP_TRACE_EVENT("sec_level=%d ", p_cb->sec_level); + if (int_evt) smp_sm_event(p_cb, int_evt, p); } /******************************************************************************* * Function smp_process_io_response * Description process IO response for a slave device. ******************************************************************************/ -void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason = SMP_PAIR_AUTH_FAIL; - - SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) - { - /* pairing started by local (slave) Security Request */ - smp_set_state(SMP_STATE_SEC_REQ_PENDING); - smp_send_cmd(SMP_OPCODE_SEC_REQ, p_cb); - } - else /* plan to send pairing respond */ - { - /* pairing started by peer (master) Pairing Request */ - p_cb->selected_association_model = smp_select_association_model(p_cb); - - if (p_cb->secure_connections_only_mode_required && - (!(p_cb->le_secure_connections_mode_is_used) || - (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) - { - SMP_TRACE_ERROR ("Slave requires secure connection only mode \ +void smp_process_io_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason = SMP_PAIR_AUTH_FAIL; + + SMP_TRACE_DEBUG("%s", __func__); + if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) { + /* pairing started by local (slave) Security Request */ + smp_set_state(SMP_STATE_SEC_REQ_PENDING); + smp_send_cmd(SMP_OPCODE_SEC_REQ, p_cb); + } else /* plan to send pairing respond */ + { + /* pairing started by peer (master) Pairing Request */ + p_cb->selected_association_model = smp_select_association_model(p_cb); + + if (p_cb->secure_connections_only_mode_required && + (!(p_cb->le_secure_connections_mode_is_used) || + (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) { + SMP_TRACE_ERROR( + "Slave requires secure connection only mode \ but it can't be provided -> Slave fails pairing"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) - { - if (smp_request_oob_data(p_cb)) return; - } + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) { + if (smp_request_oob_data(p_cb)) return; + } - // PTS Testing failure modes - if (pts_test_send_authentication_complete_failure(p_cb)) - return; + // PTS Testing failure modes + if (pts_test_send_authentication_complete_failure(p_cb)) return; - smp_send_pair_rsp(p_cb, NULL); - } + smp_send_pair_rsp(p_cb, NULL); + } } /******************************************************************************* @@ -1457,9 +1335,8 @@ void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description process application keys response for a slave device * (BR/EDR transport). ******************************************************************************/ -void smp_br_process_slave_keys_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - smp_br_send_pair_response(p_cb, NULL); +void smp_br_process_slave_keys_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + smp_br_send_pair_response(p_cb, NULL); } /******************************************************************************* @@ -1467,14 +1344,13 @@ void smp_br_process_slave_keys_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description actions related to sending pairing response over BR/EDR * transport. ******************************************************************************/ -void smp_br_send_pair_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_br_send_pair_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - p_cb->local_i_key &= p_cb->peer_i_key; - p_cb->local_r_key &= p_cb->peer_r_key; + p_cb->local_i_key &= p_cb->peer_i_key; + p_cb->local_r_key &= p_cb->peer_r_key; - smp_send_cmd (SMP_OPCODE_PAIRING_RSP, p_cb); + smp_send_cmd(SMP_OPCODE_PAIRING_RSP, p_cb); } /******************************************************************************* @@ -1482,13 +1358,11 @@ void smp_br_send_pair_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description This function is called to send the pairing complete * callback and remove the connection if needed. ******************************************************************************/ -void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - if (p_cb->total_tx_unacked == 0) - { - /* process the pairing complete */ - smp_proc_pairing_cmpl(p_cb); - } +void smp_pairing_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + if (p_cb->total_tx_unacked == 0) { + /* process the pairing complete */ + smp_proc_pairing_cmpl(p_cb); + } } /******************************************************************************* @@ -1496,11 +1370,10 @@ void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description This function is called to send the pairing complete * callback and remove the connection if needed. ******************************************************************************/ -void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - p_cb->status = SMP_CONN_TOUT; - smp_proc_pairing_cmpl(p_cb); +void smp_pair_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->status = SMP_CONN_TOUT; + smp_proc_pairing_cmpl(p_cb); } /******************************************************************************* @@ -1508,27 +1381,24 @@ void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description This function calledin idle state to determine to send * authentication complete or not. ******************************************************************************/ -void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) - { - SMP_TRACE_DEBUG("Pairing terminated at IDLE state."); - p_cb->status = SMP_FAIL; - smp_proc_pairing_cmpl(p_cb); - } +void smp_idle_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) { + SMP_TRACE_DEBUG("Pairing terminated at IDLE state."); + p_cb->status = SMP_FAIL; + smp_proc_pairing_cmpl(p_cb); + } } /******************************************************************************* * Function smp_fast_conn_param * Description apply default connection parameter for pairing process ******************************************************************************/ -void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - /* Disable L2CAP connection parameter updates while bonding since - some peripherals are not able to revert to fast connection parameters - during the start of service discovery. Connection paramter updates - get enabled again once service discovery completes. */ - L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, false); +void smp_fast_conn_param(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + /* Disable L2CAP connection parameter updates while bonding since + some peripherals are not able to revert to fast connection parameters + during the start of service discovery. Connection paramter updates + get enabled again once service discovery completes. */ + L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, false); } /******************************************************************************* @@ -1540,18 +1410,16 @@ void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * - on slave side invokes sending local public key to the peer. * - invokes SC phase 1 process. ******************************************************************************/ -void smp_both_have_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s",__func__); +void smp_both_have_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - /* invokes DHKey computation */ - smp_compute_dhkey(p_cb); + /* invokes DHKey computation */ + smp_compute_dhkey(p_cb); - /* on slave side invokes sending local public key to the peer */ - if (p_cb->role == HCI_ROLE_SLAVE) - smp_send_pair_public_key(p_cb, NULL); + /* on slave side invokes sending local public key to the peer */ + if (p_cb->role == HCI_ROLE_SLAVE) smp_send_pair_public_key(p_cb, NULL); - smp_sm_event(p_cb, SMP_SC_DHKEY_CMPLT_EVT, NULL); + smp_sm_event(p_cb, SMP_SC_DHKEY_CMPLT_EVT, NULL); } /******************************************************************************* @@ -1561,47 +1429,44 @@ void smp_both_have_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * to the peer messages appropriate for the role and association * model. ******************************************************************************/ -void smp_start_secure_connection_phase1(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) - { - p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; - SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE) ", p_cb->sec_level ); - } - else - { - p_cb->sec_level = SMP_SEC_AUTHENTICATED; - SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", p_cb->sec_level ); - } - - switch(p_cb->selected_association_model) - { - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - memset(p_cb->local_random, 0, BT_OCTET16_LEN); - smp_start_nonce_generation(p_cb); - break; - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - /* user has to provide passkey */ - p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; - smp_sm_event(p_cb, SMP_TK_REQ_EVT, NULL); - break; - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - /* passkey has to be provided to user */ - SMP_TRACE_DEBUG("Need to generate SC Passkey"); - smp_generate_passkey(p_cb, NULL); - break; - case SMP_MODEL_SEC_CONN_OOB: - /* use the available OOB information */ - smp_process_secure_connection_oob_data(p_cb, NULL); - break; - default: - SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC", - p_cb->selected_association_model); - break; - } +void smp_start_secure_connection_phase1(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) { + p_cb->sec_level = SMP_SEC_UNAUTHENTICATE; + SMP_TRACE_EVENT("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE) ", + p_cb->sec_level); + } else { + p_cb->sec_level = SMP_SEC_AUTHENTICATED; + SMP_TRACE_EVENT("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) ", + p_cb->sec_level); + } + + switch (p_cb->selected_association_model) { + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + memset(p_cb->local_random, 0, BT_OCTET16_LEN); + smp_start_nonce_generation(p_cb); + break; + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + /* user has to provide passkey */ + p_cb->cb_evt = SMP_PASSKEY_REQ_EVT; + smp_sm_event(p_cb, SMP_TK_REQ_EVT, NULL); + break; + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + /* passkey has to be provided to user */ + SMP_TRACE_DEBUG("Need to generate SC Passkey"); + smp_generate_passkey(p_cb, NULL); + break; + case SMP_MODEL_SEC_CONN_OOB: + /* use the available OOB information */ + smp_process_secure_connection_oob_data(p_cb, NULL); + break; + default: + SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", + p_cb->selected_association_model); + break; + } } /******************************************************************************* @@ -1610,67 +1475,60 @@ void smp_start_secure_connection_phase1(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * * Note It is supposed to be called in SC phase1. ******************************************************************************/ -void smp_process_local_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - - switch(p_cb->selected_association_model) - { - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - if (p_cb->role == HCI_ROLE_SLAVE) - { - /* slave calculates and sends local commitment */ - smp_calculate_local_commitment(p_cb); - smp_send_commitment(p_cb, NULL); - /* slave has to wait for peer nonce */ - smp_set_state(SMP_STATE_WAIT_NONCE); - } - else /* i.e. master */ - { - if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) - { - /* slave commitment is already received, send local nonce, wait for remote nonce*/ - SMP_TRACE_DEBUG("master in assoc mode = %d \ +void smp_process_local_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + + switch (p_cb->selected_association_model) { + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + if (p_cb->role == HCI_ROLE_SLAVE) { + /* slave calculates and sends local commitment */ + smp_calculate_local_commitment(p_cb); + smp_send_commitment(p_cb, NULL); + /* slave has to wait for peer nonce */ + smp_set_state(SMP_STATE_WAIT_NONCE); + } else /* i.e. master */ + { + if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) { + /* slave commitment is already received, send local nonce, wait for + * remote nonce*/ + SMP_TRACE_DEBUG( + "master in assoc mode = %d \ already rcvd slave commitment - race condition", - p_cb->selected_association_model); - p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; - smp_send_rand(p_cb, NULL); - smp_set_state(SMP_STATE_WAIT_NONCE); - } - } - break; - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - smp_calculate_local_commitment(p_cb); - - if (p_cb->role == HCI_ROLE_MASTER) - { - smp_send_commitment(p_cb, NULL); - } - else /* slave */ - { - if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) - { - /* master commitment is already received */ - smp_send_commitment(p_cb, NULL); - smp_set_state(SMP_STATE_WAIT_NONCE); - } - } - break; - case SMP_MODEL_SEC_CONN_OOB: - if (p_cb->role == HCI_ROLE_MASTER) - { - smp_send_rand(p_cb, NULL); - } - - smp_set_state(SMP_STATE_WAIT_NONCE); - break; - default: - SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC", - p_cb->selected_association_model); - break; - } + p_cb->selected_association_model); + p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; + smp_send_rand(p_cb, NULL); + smp_set_state(SMP_STATE_WAIT_NONCE); + } + } + break; + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + smp_calculate_local_commitment(p_cb); + + if (p_cb->role == HCI_ROLE_MASTER) { + smp_send_commitment(p_cb, NULL); + } else /* slave */ + { + if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) { + /* master commitment is already received */ + smp_send_commitment(p_cb, NULL); + smp_set_state(SMP_STATE_WAIT_NONCE); + } + } + break; + case SMP_MODEL_SEC_CONN_OOB: + if (p_cb->role == HCI_ROLE_MASTER) { + smp_send_rand(p_cb, NULL); + } + + smp_set_state(SMP_STATE_WAIT_NONCE); + break; + default: + SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", + p_cb->selected_association_model); + break; + } } /******************************************************************************* @@ -1681,90 +1539,78 @@ void smp_process_local_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * * Note It is supposed to be called in SC phase1. ******************************************************************************/ -void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason; +void smp_process_peer_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason; - SMP_TRACE_DEBUG("%s start ", __func__); + SMP_TRACE_DEBUG("%s start ", __func__); - // PTS Testing failure modes - if (p_cb->cert_failure == 1) { - SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); + // PTS Testing failure modes + if (p_cb->cert_failure == 1) { + SMP_TRACE_ERROR("%s failure case = %d", __func__, p_cb->cert_failure); + reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } + + switch (p_cb->selected_association_model) { + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + /* in these models only master receives commitment */ + if (p_cb->role == HCI_ROLE_MASTER) { + if (!smp_check_commitment(p_cb)) { + reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + break; + } + } else { + /* slave sends local nonce */ + smp_send_rand(p_cb, NULL); + } + + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) { + /* go directly to phase 2 */ + smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); + } else /* numeric comparison */ + { + smp_set_state(SMP_STATE_WAIT_NONCE); + smp_sm_event(p_cb, SMP_SC_CALC_NC_EVT, NULL); + } + break; + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + if (!smp_check_commitment(p_cb) && p_cb->cert_failure != 9) { reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + break; + } - switch(p_cb->selected_association_model) - { - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - /* in these models only master receives commitment */ - if (p_cb->role == HCI_ROLE_MASTER) - { - if (!smp_check_commitment(p_cb)) - { - reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - } - } - else - { - /* slave sends local nonce */ - smp_send_rand(p_cb, NULL); - } - - if(p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) - { - /* go directly to phase 2 */ - smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); - } - else /* numeric comparison */ - { - smp_set_state(SMP_STATE_WAIT_NONCE); - smp_sm_event(p_cb, SMP_SC_CALC_NC_EVT, NULL); - } - break; - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - if (!smp_check_commitment(p_cb) && p_cb->cert_failure != 9) - { - reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - break; - } - - if (p_cb->role == HCI_ROLE_SLAVE) - { - smp_send_rand(p_cb, NULL); - } - - if (++p_cb->round < 20) - { - smp_set_state(SMP_STATE_SEC_CONN_PHS1_START); - p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; - smp_start_nonce_generation(p_cb); - break; - } - - smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); - break; - case SMP_MODEL_SEC_CONN_OOB: - if (p_cb->role == HCI_ROLE_SLAVE) - { - smp_send_rand(p_cb, NULL); - } - - smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); - break; - default: - SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC", - p_cb->selected_association_model); - break; - } + if (p_cb->role == HCI_ROLE_SLAVE) { + smp_send_rand(p_cb, NULL); + } + + if (++p_cb->round < 20) { + smp_set_state(SMP_STATE_SEC_CONN_PHS1_START); + p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM; + smp_start_nonce_generation(p_cb); + break; + } + + smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); + break; + case SMP_MODEL_SEC_CONN_OOB: + if (p_cb->role == HCI_ROLE_SLAVE) { + smp_send_rand(p_cb, NULL); + } - SMP_TRACE_DEBUG("%s end ",__func__); + smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); + break; + default: + SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", + p_cb->selected_association_model); + break; + } + + SMP_TRACE_DEBUG("%s end ", __func__); } /******************************************************************************* @@ -1772,37 +1618,33 @@ void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description checks if the calculated peer DHKey Check value is the same as * received from the peer DHKey check value. ******************************************************************************/ -void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t reason = SMP_DHKEY_CHK_FAIL; +void smp_match_dhkey_checks(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t reason = SMP_DHKEY_CHK_FAIL; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (memcmp(p_data->key.p_data, p_cb->remote_dhkey_check, BT_OCTET16_LEN)) - { - SMP_TRACE_WARNING ("dhkey chcks do no match"); - p_cb->failure = reason; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } + if (memcmp(p_data->key.p_data, p_cb->remote_dhkey_check, BT_OCTET16_LEN)) { + SMP_TRACE_WARNING("dhkey chcks do no match"); + p_cb->failure = reason; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; + } - SMP_TRACE_EVENT ("dhkey chcks match"); + SMP_TRACE_EVENT("dhkey chcks match"); - /* compare the max encryption key size, and save the smaller one for the link */ - if (p_cb->peer_enc_size < p_cb->loc_enc_size) - p_cb->loc_enc_size = p_cb->peer_enc_size; + /* compare the max encryption key size, and save the smaller one for the link + */ + if (p_cb->peer_enc_size < p_cb->loc_enc_size) + p_cb->loc_enc_size = p_cb->peer_enc_size; - if (p_cb->role == HCI_ROLE_SLAVE) - { - smp_sm_event(p_cb, SMP_PAIR_DHKEY_CHCK_EVT, NULL); - } - else - { - /* master device always use received i/r key as keys to distribute */ - p_cb->local_i_key = p_cb->peer_i_key; - p_cb->local_r_key = p_cb->peer_r_key; - smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); - } + if (p_cb->role == HCI_ROLE_SLAVE) { + smp_sm_event(p_cb, SMP_PAIR_DHKEY_CHCK_EVT, NULL); + } else { + /* master device always use received i/r key as keys to distribute */ + p_cb->local_i_key = p_cb->peer_i_key; + p_cb->local_r_key = p_cb->peer_r_key; + smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL); + } } /******************************************************************************* @@ -1812,10 +1654,10 @@ void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * * Note SM is supposed to be in the state SMP_STATE_SEC_CONN_PHS2_START. ******************************************************************************/ -void smp_move_to_secure_connections_phase2(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s",__func__); - smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); +void smp_move_to_secure_connections_phase2(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL); } /******************************************************************************* @@ -1827,12 +1669,12 @@ void smp_move_to_secure_connections_phase2(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * It is supposed to be called after slave dhkey check is * calculated. ******************************************************************************/ -void smp_phase_2_dhkey_checks_are_present(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s",__func__); +void smp_phase_2_dhkey_checks_are_present(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK) - smp_sm_event(p_cb, SMP_SC_2_DHCK_CHKS_PRES_EVT, NULL); + if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK) + smp_sm_event(p_cb, SMP_SC_2_DHCK_CHKS_PRES_EVT, NULL); } /******************************************************************************* @@ -1843,94 +1685,84 @@ void smp_phase_2_dhkey_checks_are_present(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Note on the slave it is used to prevent race condition. * ******************************************************************************/ -void smp_wait_for_both_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s",__func__); +void smp_wait_for_both_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - if ((p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY) && - (p_cb->flags & SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY)) - { - if ((p_cb->role == HCI_ROLE_SLAVE) && - ((p_cb->req_oob_type == SMP_OOB_LOCAL) || (p_cb->req_oob_type == SMP_OOB_BOTH))) - { - smp_set_state(SMP_STATE_PUBLIC_KEY_EXCH); - } - smp_sm_event(p_cb, SMP_BOTH_PUBL_KEYS_RCVD_EVT, NULL); + if ((p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY) && + (p_cb->flags & SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY)) { + if ((p_cb->role == HCI_ROLE_SLAVE) && + ((p_cb->req_oob_type == SMP_OOB_LOCAL) || + (p_cb->req_oob_type == SMP_OOB_BOTH))) { + smp_set_state(SMP_STATE_PUBLIC_KEY_EXCH); } + smp_sm_event(p_cb, SMP_BOTH_PUBL_KEYS_RCVD_EVT, NULL); + } } /******************************************************************************* * Function smp_start_passkey_verification * Description Starts SC passkey entry verification. ******************************************************************************/ -void smp_start_passkey_verification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t *p = NULL; +void smp_start_passkey_verification(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t* p = NULL; - SMP_TRACE_DEBUG("%s", __func__); - p = p_cb->local_random; - UINT32_TO_STREAM(p, p_data->passkey); + SMP_TRACE_DEBUG("%s", __func__); + p = p_cb->local_random; + UINT32_TO_STREAM(p, p_data->passkey); - p = p_cb->peer_random; - UINT32_TO_STREAM(p, p_data->passkey); + p = p_cb->peer_random; + UINT32_TO_STREAM(p, p_data->passkey); - p_cb->round = 0; - smp_start_nonce_generation(p_cb); + p_cb->round = 0; + smp_start_nonce_generation(p_cb); } /******************************************************************************* * Function smp_process_secure_connection_oob_data * Description Processes local/peer SC OOB data received from somewhere. ******************************************************************************/ -void smp_process_secure_connection_oob_data(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_process_secure_connection_oob_data(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - tSMP_SC_OOB_DATA *p_sc_oob_data = &p_cb->sc_oob_data; - if (p_sc_oob_data->loc_oob_data.present) - { - memcpy(p_cb->local_random, p_sc_oob_data->loc_oob_data.randomizer, - sizeof(p_cb->local_random)); - } - else - { - SMP_TRACE_EVENT ("%s: local OOB randomizer is absent", __func__); - memset(p_cb->local_random, 0, sizeof (p_cb->local_random)); - } + tSMP_SC_OOB_DATA* p_sc_oob_data = &p_cb->sc_oob_data; + if (p_sc_oob_data->loc_oob_data.present) { + memcpy(p_cb->local_random, p_sc_oob_data->loc_oob_data.randomizer, + sizeof(p_cb->local_random)); + } else { + SMP_TRACE_EVENT("%s: local OOB randomizer is absent", __func__); + memset(p_cb->local_random, 0, sizeof(p_cb->local_random)); + } - if (!p_sc_oob_data->peer_oob_data.present) - { - SMP_TRACE_EVENT ("%s: peer OOB data is absent", __func__); - memset(p_cb->peer_random, 0, sizeof (p_cb->peer_random)); + if (!p_sc_oob_data->peer_oob_data.present) { + SMP_TRACE_EVENT("%s: peer OOB data is absent", __func__); + memset(p_cb->peer_random, 0, sizeof(p_cb->peer_random)); + } else { + memcpy(p_cb->peer_random, p_sc_oob_data->peer_oob_data.randomizer, + sizeof(p_cb->peer_random)); + memcpy(p_cb->remote_commitment, p_sc_oob_data->peer_oob_data.commitment, + sizeof(p_cb->remote_commitment)); + + uint8_t reason = SMP_CONFIRM_VALUE_ERR; + /* check commitment */ + if (!smp_check_commitment(p_cb)) { + p_cb->failure = reason; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); + return; } - else - { - memcpy(p_cb->peer_random, p_sc_oob_data->peer_oob_data.randomizer, - sizeof(p_cb->peer_random)); - memcpy(p_cb->remote_commitment, p_sc_oob_data->peer_oob_data.commitment, - sizeof(p_cb->remote_commitment)); - - uint8_t reason = SMP_CONFIRM_VALUE_ERR; - /* check commitment */ - if (!smp_check_commitment(p_cb)) - { - p_cb->failure = reason; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } - if (p_cb->peer_oob_flag != SMP_OOB_PRESENT) - { - /* the peer doesn't have local randomiser */ - SMP_TRACE_EVENT ("%s: peer didn't receive local OOB data, set local randomizer to 0", - __func__); - memset(p_cb->local_random, 0, sizeof (p_cb->local_random)); - } + if (p_cb->peer_oob_flag != SMP_OOB_PRESENT) { + /* the peer doesn't have local randomiser */ + SMP_TRACE_EVENT( + "%s: peer didn't receive local OOB data, set local randomizer to 0", + __func__); + memset(p_cb->local_random, 0, sizeof(p_cb->local_random)); } + } - print128(p_cb->local_random, (const uint8_t *)"local OOB randomizer"); - print128(p_cb->peer_random, (const uint8_t *)"peer OOB randomizer"); - smp_start_nonce_generation(p_cb); + print128(p_cb->local_random, (const uint8_t*)"local OOB randomizer"); + print128(p_cb->peer_random, (const uint8_t*)"peer OOB randomizer"); + smp_start_nonce_generation(p_cb); } /******************************************************************************* @@ -1939,14 +1771,13 @@ void smp_process_secure_connection_oob_data(tSMP_CB *p_cb, tSMP_INT_DATA *p_data * sc_oob_data.loc_oob_data, starts nonce generation * (to be saved in sc_oob_data.loc_oob_data.randomizer). ******************************************************************************/ -void smp_set_local_oob_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_set_local_oob_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - memcpy(p_cb->sc_oob_data.loc_oob_data.private_key_used, p_cb->private_key, - BT_OCTET32_LEN); - p_cb->sc_oob_data.loc_oob_data.publ_key_used = p_cb->loc_publ_key; - smp_start_nonce_generation(p_cb); + memcpy(p_cb->sc_oob_data.loc_oob_data.private_key_used, p_cb->private_key, + BT_OCTET32_LEN); + p_cb->sc_oob_data.loc_oob_data.publ_key_used = p_cb->loc_publ_key; + smp_start_nonce_generation(p_cb); } /******************************************************************************* @@ -1955,46 +1786,44 @@ void smp_set_local_oob_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * sc_oob_data.loc_oob_data, passes sc_oob_data.loc_oob_data up * for safekeeping. ******************************************************************************/ -void smp_set_local_oob_random_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - memcpy(p_cb->sc_oob_data.loc_oob_data.randomizer, p_cb->rand, - BT_OCTET16_LEN); +void smp_set_local_oob_random_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + memcpy(p_cb->sc_oob_data.loc_oob_data.randomizer, p_cb->rand, BT_OCTET16_LEN); - smp_calculate_f4(p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, - p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, - p_cb->sc_oob_data.loc_oob_data.randomizer, 0, - p_cb->sc_oob_data.loc_oob_data.commitment); + smp_calculate_f4(p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, + p_cb->sc_oob_data.loc_oob_data.publ_key_used.x, + p_cb->sc_oob_data.loc_oob_data.randomizer, 0, + p_cb->sc_oob_data.loc_oob_data.commitment); #if (SMP_DEBUG == TRUE) - uint8_t *p_print = NULL; - SMP_TRACE_DEBUG("local SC OOB data set:"); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.addr_sent_to; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"addr_sent_to", - sizeof(tBLE_BD_ADDR)); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.private_key_used; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"private_key_used", - BT_OCTET32_LEN); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.publ_key_used.x; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"publ_key_used.x", - BT_OCTET32_LEN); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.publ_key_used.y; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"publ_key_used.y", - BT_OCTET32_LEN); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.randomizer; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"randomizer", - BT_OCTET16_LEN); - p_print = (uint8_t*) &p_cb->sc_oob_data.loc_oob_data.commitment; - smp_debug_print_nbyte_little_endian (p_print,(const uint8_t *) "commitment", - BT_OCTET16_LEN); - SMP_TRACE_DEBUG(""); + uint8_t* p_print = NULL; + SMP_TRACE_DEBUG("local SC OOB data set:"); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.addr_sent_to; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"addr_sent_to", + sizeof(tBLE_BD_ADDR)); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.private_key_used; + smp_debug_print_nbyte_little_endian( + p_print, (const uint8_t*)"private_key_used", BT_OCTET32_LEN); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.publ_key_used.x; + smp_debug_print_nbyte_little_endian( + p_print, (const uint8_t*)"publ_key_used.x", BT_OCTET32_LEN); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.publ_key_used.y; + smp_debug_print_nbyte_little_endian( + p_print, (const uint8_t*)"publ_key_used.y", BT_OCTET32_LEN); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.randomizer; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"randomizer", + BT_OCTET16_LEN); + p_print = (uint8_t*)&p_cb->sc_oob_data.loc_oob_data.commitment; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"commitment", + BT_OCTET16_LEN); + SMP_TRACE_DEBUG(""); #endif - /* pass created OOB data up */ - p_cb->cb_evt = SMP_SC_LOC_OOB_DATA_UP_EVT; - smp_send_app_cback(p_cb, NULL); + /* pass created OOB data up */ + p_cb->cb_evt = SMP_SC_LOC_OOB_DATA_UP_EVT; + smp_send_app_cback(p_cb, NULL); - smp_cb_cleanup(p_cb); + smp_cb_cleanup(p_cb); } /******************************************************************************* @@ -2009,24 +1838,22 @@ void smp_set_local_oob_random_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Returns void * ******************************************************************************/ -void smp_link_encrypted(BD_ADDR bda, uint8_t encr_enable) -{ - tSMP_CB *p_cb = &smp_cb; +void smp_link_encrypted(BD_ADDR bda, uint8_t encr_enable) { + tSMP_CB* p_cb = &smp_cb; - SMP_TRACE_DEBUG("%s encr_enable=%d", __func__, encr_enable); + SMP_TRACE_DEBUG("%s encr_enable=%d", __func__, encr_enable); - if (memcmp(&smp_cb.pairing_bda[0], bda, BD_ADDR_LEN) == 0) - { - /* encryption completed with STK, remmeber the key size now, could be overwite - * when key exchange happens */ - if (p_cb->loc_enc_size != 0 && encr_enable) - { - /* update the link encryption key size if a SMP pairing just performed */ - btm_ble_update_sec_key_size(bda, p_cb->loc_enc_size); - } - - smp_sm_event(&smp_cb, SMP_ENCRYPTED_EVT, &encr_enable); + if (memcmp(&smp_cb.pairing_bda[0], bda, BD_ADDR_LEN) == 0) { + /* encryption completed with STK, remmeber the key size now, could be + * overwite + * when key exchange happens */ + if (p_cb->loc_enc_size != 0 && encr_enable) { + /* update the link encryption key size if a SMP pairing just performed */ + btm_ble_update_sec_key_size(bda, p_cb->loc_enc_size); } + + smp_sm_event(&smp_cb, SMP_ENCRYPTED_EVT, &encr_enable); + } } /******************************************************************************* @@ -2039,32 +1866,29 @@ void smp_link_encrypted(BD_ADDR bda, uint8_t encr_enable) * Returns void * ******************************************************************************/ -bool smp_proc_ltk_request(BD_ADDR bda) -{ - SMP_TRACE_DEBUG("%s state = %d", __func__, smp_cb.state); - bool match = false; +bool smp_proc_ltk_request(BD_ADDR bda) { + SMP_TRACE_DEBUG("%s state = %d", __func__, smp_cb.state); + bool match = false; - if (!memcmp(bda, smp_cb.pairing_bda, BD_ADDR_LEN)) - { - match = true; - } else { - BD_ADDR dummy_bda = {0}; - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bda); - if (p_dev_rec != NULL && - 0 == memcmp(p_dev_rec->ble.pseudo_addr, smp_cb.pairing_bda, BD_ADDR_LEN) && - 0 != memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN)) - { - match = true; - } + if (!memcmp(bda, smp_cb.pairing_bda, BD_ADDR_LEN)) { + match = true; + } else { + BD_ADDR dummy_bda = {0}; + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + if (p_dev_rec != NULL && + 0 == memcmp(p_dev_rec->ble.pseudo_addr, smp_cb.pairing_bda, + BD_ADDR_LEN) && + 0 != memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN)) { + match = true; } + } - if (match && smp_cb.state == SMP_STATE_ENCRYPTION_PENDING) - { - smp_sm_event(&smp_cb, SMP_ENC_REQ_EVT, NULL); - return true; - } + if (match && smp_cb.state == SMP_STATE_ENCRYPTION_PENDING) { + smp_sm_event(&smp_cb, SMP_ENC_REQ_EVT, NULL); + return true; + } - return false; + return false; } /******************************************************************************* @@ -2078,15 +1902,14 @@ bool smp_proc_ltk_request(BD_ADDR bda) * Returns void * ******************************************************************************/ -void smp_process_secure_connection_long_term_key(void) -{ - tSMP_CB *p_cb = &smp_cb; +void smp_process_secure_connection_long_term_key(void) { + tSMP_CB* p_cb = &smp_cb; - SMP_TRACE_DEBUG("%s", __func__); - smp_save_secure_connections_long_term_key(p_cb); + SMP_TRACE_DEBUG("%s", __func__); + smp_save_secure_connections_long_term_key(p_cb); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, false); - smp_key_distribution(p_cb, NULL); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); + smp_key_distribution(p_cb, NULL); } /******************************************************************************* @@ -2100,12 +1923,11 @@ void smp_process_secure_connection_long_term_key(void) * Returns void * ******************************************************************************/ -void smp_set_derive_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - p_cb->derive_lk = true; - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_LK, false); - smp_key_distribution(p_cb, NULL); +void smp_set_derive_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->derive_lk = true; + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_LK, false); + smp_key_distribution(p_cb, NULL); } /******************************************************************************* @@ -2117,17 +1939,16 @@ void smp_set_derive_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Returns void * ******************************************************************************/ -void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; +void smp_derive_link_key_from_long_term_key(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data) { + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - SMP_TRACE_DEBUG("%s", __func__); - if (!smp_calculate_link_key_from_long_term_key(p_cb)) - { - SMP_TRACE_ERROR("%s failed", __func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - return; - } + SMP_TRACE_DEBUG("%s", __func__); + if (!smp_calculate_link_key_from_long_term_key(p_cb)) { + SMP_TRACE_ERROR("%s failed", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + return; + } } /******************************************************************************* @@ -2141,22 +1962,21 @@ void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data * Returns void * ******************************************************************************/ -void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; +void smp_br_process_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - SMP_TRACE_DEBUG("%s", __func__); - if (!smp_calculate_long_term_key_from_link_key(p_cb)) - { - SMP_TRACE_ERROR ("%s failed",__func__); - smp_sm_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); - return; - } + SMP_TRACE_DEBUG("%s", __func__); + if (!smp_calculate_long_term_key_from_link_key(p_cb)) { + SMP_TRACE_ERROR("%s failed", __func__); + smp_sm_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); + return; + } - SMP_TRACE_DEBUG("%s: LTK derivation from LK successfully completed", __func__); - smp_save_secure_connections_long_term_key(p_cb); - smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, false); - smp_br_select_next_key(p_cb, NULL); + SMP_TRACE_DEBUG("%s: LTK derivation from LK successfully completed", + __func__); + smp_save_secure_connections_long_term_key(p_cb); + smp_update_key_mask(p_cb, SMP_SEC_KEY_TYPE_ENC, false); + smp_br_select_next_key(p_cb, NULL); } /******************************************************************************* @@ -2164,17 +1984,13 @@ void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description depending on the transport used at the moment calls either * smp_key_distribution(...) or smp_br_key_distribution(...). ******************************************************************************/ -void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->smp_over_br) - { - smp_br_select_next_key(p_cb, NULL); - } - else - { - smp_key_distribution(p_cb, NULL); - } +void smp_key_distribution_by_transport(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + if (p_cb->smp_over_br) { + smp_br_select_next_key(p_cb, NULL); + } else { + smp_key_distribution(p_cb, NULL); + } } /******************************************************************************* @@ -2182,13 +1998,11 @@ void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Description This function is called to send the pairing complete * callback and remove the connection if needed. ******************************************************************************/ -void smp_br_pairing_complete(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_br_pairing_complete(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->total_tx_unacked == 0) - { - /* process the pairing complete */ - smp_proc_pairing_cmpl(p_cb); - } + if (p_cb->total_tx_unacked == 0) { + /* process the pairing complete */ + smp_proc_pairing_cmpl(p_cb); + } } diff --git a/stack/smp/smp_api.cc b/stack/smp/smp_api.cc index 8c5516196..ebd300b09 100644 --- a/stack/smp/smp_api.cc +++ b/stack/smp/smp_api.cc @@ -28,12 +28,12 @@ #include "bt_utils.h" #include "stack_config.h" -#include "smp_int.h" -#include "smp_api.h" -#include "l2cdefs.h" -#include "l2c_int.h" #include "btm_int.h" #include "hcimsgs.h" +#include "l2c_int.h" +#include "l2cdefs.h" +#include "smp_api.h" +#include "smp_int.h" #include "btu.h" #include "p_256_ecc_pp.h" @@ -47,30 +47,30 @@ * Returns void * ******************************************************************************/ -void SMP_Init(void) -{ - memset(&smp_cb, 0, sizeof(tSMP_CB)); - smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent"); - smp_cb.delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent"); +void SMP_Init(void) { + memset(&smp_cb, 0, sizeof(tSMP_CB)); + smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent"); + smp_cb.delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent"); #if defined(SMP_INITIAL_TRACE_LEVEL) - smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL; + smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL; #else - smp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ + smp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */ #endif - SMP_TRACE_EVENT ("%s", __func__); - - smp_l2cap_if_init(); - /* initialization of P-256 parameters */ - p_256_init_curve(KEY_LENGTH_DWORDS_P256); - - /* Initialize failure case for certification */ - smp_cb.cert_failure = stack_config_get_interface()->get_pts_smp_failure_case(); - if (smp_cb.cert_failure) - SMP_TRACE_ERROR ("%s PTS FAILURE MODE IN EFFECT (CASE %d)", __func__, smp_cb.cert_failure); + SMP_TRACE_EVENT("%s", __func__); + + smp_l2cap_if_init(); + /* initialization of P-256 parameters */ + p_256_init_curve(KEY_LENGTH_DWORDS_P256); + + /* Initialize failure case for certification */ + smp_cb.cert_failure = + stack_config_get_interface()->get_pts_smp_failure_case(); + if (smp_cb.cert_failure) + SMP_TRACE_ERROR("%s PTS FAILURE MODE IN EFFECT (CASE %d)", __func__, + smp_cb.cert_failure); } - /******************************************************************************* * * Function SMP_SetTraceLevel @@ -91,15 +91,12 @@ void SMP_Init(void) * Returns The new or current trace level * ******************************************************************************/ -extern uint8_t SMP_SetTraceLevel (uint8_t new_level) -{ - if (new_level != 0xFF) - smp_cb.trace_level = new_level; +extern uint8_t SMP_SetTraceLevel(uint8_t new_level) { + if (new_level != 0xFF) smp_cb.trace_level = new_level; - return(smp_cb.trace_level); + return (smp_cb.trace_level); } - /******************************************************************************* * * Function SMP_Register @@ -109,18 +106,15 @@ extern uint8_t SMP_SetTraceLevel (uint8_t new_level) * Returns void * ******************************************************************************/ -bool SMP_Register (tSMP_CALLBACK *p_cback) -{ - SMP_TRACE_EVENT ("SMP_Register state=%d", smp_cb.state); +bool SMP_Register(tSMP_CALLBACK* p_cback) { + SMP_TRACE_EVENT("SMP_Register state=%d", smp_cb.state); - if (smp_cb.p_callback != NULL) - { - SMP_TRACE_ERROR ("SMP_Register: duplicate registration, overwrite it"); - } - smp_cb.p_callback = p_cback; - - return(true); + if (smp_cb.p_callback != NULL) { + SMP_TRACE_ERROR("SMP_Register: duplicate registration, overwrite it"); + } + smp_cb.p_callback = p_cback; + return (true); } /******************************************************************************* @@ -135,34 +129,29 @@ bool SMP_Register (tSMP_CALLBACK *p_cback) * Returns None * ******************************************************************************/ -tSMP_STATUS SMP_Pair (BD_ADDR bd_addr) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t status = SMP_PAIR_INTERNAL_ERR; - - SMP_TRACE_EVENT ("%s state=%d br_state=%d flag=0x%x ", - __func__, p_cb->state, p_cb->br_state, p_cb->flags); - if (p_cb->state != SMP_STATE_IDLE || p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD || - p_cb->smp_over_br) - { - /* pending security on going, reject this one */ - return SMP_BUSY; - } - else - { - p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD; - - memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); +tSMP_STATUS SMP_Pair(BD_ADDR bd_addr) { + tSMP_CB* p_cb = &smp_cb; + uint8_t status = SMP_PAIR_INTERNAL_ERR; + + SMP_TRACE_EVENT("%s state=%d br_state=%d flag=0x%x ", __func__, p_cb->state, + p_cb->br_state, p_cb->flags); + if (p_cb->state != SMP_STATE_IDLE || + p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD || p_cb->smp_over_br) { + /* pending security on going, reject this one */ + return SMP_BUSY; + } else { + p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD; - if (!L2CA_ConnectFixedChnl (L2CAP_SMP_CID, bd_addr)) - { - SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.", __func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - return status; - } + memcpy(p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); - return SMP_STARTED; + if (!L2CA_ConnectFixedChnl(L2CAP_SMP_CID, bd_addr)) { + SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + return status; } + + return SMP_STARTED; + } } /******************************************************************************* @@ -178,36 +167,32 @@ tSMP_STATUS SMP_Pair (BD_ADDR bd_addr) * failure. * ******************************************************************************/ -tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t status = SMP_PAIR_INTERNAL_ERR; - - SMP_TRACE_EVENT ("%s state=%d br_state=%d flag=0x%x ", - __func__, p_cb->state, p_cb->br_state, p_cb->flags); - - if (p_cb->state != SMP_STATE_IDLE || - p_cb->smp_over_br || - p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) - { - /* pending security on going, reject this one */ - return SMP_BUSY; - } +tSMP_STATUS SMP_BR_PairWith(BD_ADDR bd_addr) { + tSMP_CB* p_cb = &smp_cb; + uint8_t status = SMP_PAIR_INTERNAL_ERR; - p_cb->role = HCI_ROLE_MASTER; - p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD; - p_cb->smp_over_br = true; + SMP_TRACE_EVENT("%s state=%d br_state=%d flag=0x%x ", __func__, p_cb->state, + p_cb->br_state, p_cb->flags); - memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); + if (p_cb->state != SMP_STATE_IDLE || p_cb->smp_over_br || + p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) { + /* pending security on going, reject this one */ + return SMP_BUSY; + } - if (!L2CA_ConnectFixedChnl (L2CAP_SMP_BR_CID, bd_addr)) - { - SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.",__func__); - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); - return status; - } + p_cb->role = HCI_ROLE_MASTER; + p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD; + p_cb->smp_over_br = true; - return SMP_STARTED; + memcpy(p_cb->pairing_bda, bd_addr, BD_ADDR_LEN); + + if (!L2CA_ConnectFixedChnl(L2CAP_SMP_BR_CID, bd_addr)) { + SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.", __func__); + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); + return status; + } + + return SMP_STARTED; } /******************************************************************************* @@ -221,29 +206,28 @@ tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr) * Returns true - Pairining is cancelled * ******************************************************************************/ -bool SMP_PairCancel (BD_ADDR bd_addr) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t err_code = SMP_PAIR_FAIL_UNKNOWN; - bool status = false; - - // PTS SMP failure test cases - if (p_cb->cert_failure == 7) - err_code = SMP_PASSKEY_ENTRY_FAIL; - else if (p_cb->cert_failure == 8) - err_code = SMP_NUMERIC_COMPAR_FAIL; - - BTM_TRACE_EVENT ("SMP_CancelPair state=%d flag=0x%x ", p_cb->state, p_cb->flags); - if ( (p_cb->state != SMP_STATE_IDLE) && - (!memcmp (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN)) ) - { - p_cb->is_pair_cancel = true; - SMP_TRACE_DEBUG("Cancel Pairing: set fail reason Unknown"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &err_code); - status = true; - } - - return status; +bool SMP_PairCancel(BD_ADDR bd_addr) { + tSMP_CB* p_cb = &smp_cb; + uint8_t err_code = SMP_PAIR_FAIL_UNKNOWN; + bool status = false; + + // PTS SMP failure test cases + if (p_cb->cert_failure == 7) + err_code = SMP_PASSKEY_ENTRY_FAIL; + else if (p_cb->cert_failure == 8) + err_code = SMP_NUMERIC_COMPAR_FAIL; + + BTM_TRACE_EVENT("SMP_CancelPair state=%d flag=0x%x ", p_cb->state, + p_cb->flags); + if ((p_cb->state != SMP_STATE_IDLE) && + (!memcmp(p_cb->pairing_bda, bd_addr, BD_ADDR_LEN))) { + p_cb->is_pair_cancel = true; + SMP_TRACE_DEBUG("Cancel Pairing: set fail reason Unknown"); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &err_code); + status = true; + } + + return status; } /******************************************************************************* * @@ -259,34 +243,31 @@ bool SMP_PairCancel (BD_ADDR bd_addr) * Returns None * ******************************************************************************/ -void SMP_SecurityGrant(BD_ADDR bd_addr, uint8_t res) -{ - SMP_TRACE_EVENT ("SMP_SecurityGrant "); - - if (smp_cb.smp_over_br) - { - if (smp_cb.br_state != SMP_BR_STATE_WAIT_APP_RSP || - smp_cb.cb_evt != SMP_SEC_REQUEST_EVT || - memcmp (smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) - { - return; - } - - /* clear the SMP_SEC_REQUEST_EVT event after get grant */ - /* avoid generating duplicate pair request */ - smp_cb.cb_evt = 0; - smp_br_state_machine_event(&smp_cb, SMP_BR_API_SEC_GRANT_EVT, &res); - return; - } +void SMP_SecurityGrant(BD_ADDR bd_addr, uint8_t res) { + SMP_TRACE_EVENT("SMP_SecurityGrant "); - if (smp_cb.state != SMP_STATE_WAIT_APP_RSP || + if (smp_cb.smp_over_br) { + if (smp_cb.br_state != SMP_BR_STATE_WAIT_APP_RSP || smp_cb.cb_evt != SMP_SEC_REQUEST_EVT || - memcmp (smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) - return; + memcmp(smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) { + return; + } + /* clear the SMP_SEC_REQUEST_EVT event after get grant */ - /* avoid generate duplicate pair request */ + /* avoid generating duplicate pair request */ smp_cb.cb_evt = 0; - smp_sm_event(&smp_cb, SMP_API_SEC_GRANT_EVT, &res); + smp_br_state_machine_event(&smp_cb, SMP_BR_API_SEC_GRANT_EVT, &res); + return; + } + + if (smp_cb.state != SMP_STATE_WAIT_APP_RSP || + smp_cb.cb_evt != SMP_SEC_REQUEST_EVT || + memcmp(smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) + return; + /* clear the SMP_SEC_REQUEST_EVT event after get grant */ + /* avoid generate duplicate pair request */ + smp_cb.cb_evt = 0; + smp_sm_event(&smp_cb, SMP_API_SEC_GRANT_EVT, &res); } /******************************************************************************* @@ -304,50 +285,43 @@ void SMP_SecurityGrant(BD_ADDR bd_addr, uint8_t res) * BTM_MAX_PASSKEY_VAL(999999(0xF423F)). * ******************************************************************************/ -void SMP_PasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey) -{ - tSMP_CB *p_cb = & smp_cb; - uint8_t failure = SMP_PASSKEY_ENTRY_FAIL; - - SMP_TRACE_EVENT ("SMP_PasskeyReply: Key: %d Result:%d", - passkey, res); - - /* If timeout already expired or has been canceled, ignore the reply */ - if (p_cb->cb_evt != SMP_PASSKEY_REQ_EVT) - { - SMP_TRACE_WARNING ("SMP_PasskeyReply() - Wrong State: %d", p_cb->state); - return; - } +void SMP_PasskeyReply(BD_ADDR bd_addr, uint8_t res, uint32_t passkey) { + tSMP_CB* p_cb = &smp_cb; + uint8_t failure = SMP_PASSKEY_ENTRY_FAIL; - if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) - { - SMP_TRACE_ERROR ("SMP_PasskeyReply() - Wrong BD Addr"); - return; - } + SMP_TRACE_EVENT("SMP_PasskeyReply: Key: %d Result:%d", passkey, res); - if (btm_find_dev (bd_addr) == NULL) - { - SMP_TRACE_ERROR ("SMP_PasskeyReply() - no dev CB"); - return; - } - - if (passkey > BTM_MAX_PASSKEY_VAL || res != SMP_SUCCESS) - { - SMP_TRACE_WARNING ("SMP_PasskeyReply() - Wrong key len: %d or passkey entry fail", passkey); - /* send pairing failure */ - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + /* If timeout already expired or has been canceled, ignore the reply */ + if (p_cb->cb_evt != SMP_PASSKEY_REQ_EVT) { + SMP_TRACE_WARNING("SMP_PasskeyReply() - Wrong State: %d", p_cb->state); + return; + } - } - else if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_PASSKEY_ENT) - { - smp_sm_event(&smp_cb, SMP_SC_KEY_READY_EVT, &passkey); - } - else - { - smp_convert_string_to_tk(p_cb->tk, passkey); - } + if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) { + SMP_TRACE_ERROR("SMP_PasskeyReply() - Wrong BD Addr"); + return; + } + if (btm_find_dev(bd_addr) == NULL) { + SMP_TRACE_ERROR("SMP_PasskeyReply() - no dev CB"); return; + } + + if (passkey > BTM_MAX_PASSKEY_VAL || res != SMP_SUCCESS) { + SMP_TRACE_WARNING( + "SMP_PasskeyReply() - Wrong key len: %d or passkey entry fail", + passkey); + /* send pairing failure */ + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + + } else if (p_cb->selected_association_model == + SMP_MODEL_SEC_CONN_PASSKEY_ENT) { + smp_sm_event(&smp_cb, SMP_SC_KEY_READY_EVT, &passkey); + } else { + smp_convert_string_to_tk(p_cb->tk, passkey); + } + + return; } /******************************************************************************* @@ -362,42 +336,35 @@ void SMP_PasskeyReply (BD_ADDR bd_addr, uint8_t res, uint32_t passkey) * res - comparison result SMP_SUCCESS if success * ******************************************************************************/ -void SMP_ConfirmReply (BD_ADDR bd_addr, uint8_t res) -{ - tSMP_CB *p_cb = & smp_cb; - uint8_t failure = SMP_NUMERIC_COMPAR_FAIL; - - SMP_TRACE_EVENT ("%s: Result:%d", __func__, res); +void SMP_ConfirmReply(BD_ADDR bd_addr, uint8_t res) { + tSMP_CB* p_cb = &smp_cb; + uint8_t failure = SMP_NUMERIC_COMPAR_FAIL; - /* If timeout already expired or has been canceled, ignore the reply */ - if (p_cb->cb_evt != SMP_NC_REQ_EVT) - { - SMP_TRACE_WARNING ("%s() - Wrong State: %d", __func__,p_cb->state); - return; - } + SMP_TRACE_EVENT("%s: Result:%d", __func__, res); - if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) - { - SMP_TRACE_ERROR ("%s() - Wrong BD Addr",__func__); - return; - } + /* If timeout already expired or has been canceled, ignore the reply */ + if (p_cb->cb_evt != SMP_NC_REQ_EVT) { + SMP_TRACE_WARNING("%s() - Wrong State: %d", __func__, p_cb->state); + return; + } - if (btm_find_dev (bd_addr) == NULL) - { - SMP_TRACE_ERROR ("%s() - no dev CB",__func__); - return; - } + if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) { + SMP_TRACE_ERROR("%s() - Wrong BD Addr", __func__); + return; + } - if (res != SMP_SUCCESS) - { - SMP_TRACE_WARNING ("%s() - Numeric Comparison fails",__func__); - /* send pairing failure */ - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - } - else - { - smp_sm_event(p_cb, SMP_SC_NC_OK_EVT, NULL); - } + if (btm_find_dev(bd_addr) == NULL) { + SMP_TRACE_ERROR("%s() - no dev CB", __func__); + return; + } + + if (res != SMP_SUCCESS) { + SMP_TRACE_WARNING("%s() - Numeric Comparison fails", __func__); + /* send pairing failure */ + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + } else { + smp_sm_event(p_cb, SMP_SC_NC_OK_EVT, NULL); + } } /******************************************************************************* @@ -412,34 +379,30 @@ void SMP_ConfirmReply (BD_ADDR bd_addr, uint8_t res) * p_data - simple pairing Randomizer C. * ******************************************************************************/ -void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, uint8_t len, uint8_t *p_data) -{ - tSMP_CB *p_cb = & smp_cb; - uint8_t failure = SMP_OOB_FAIL; - tSMP_KEY key; +void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, uint8_t len, + uint8_t* p_data) { + tSMP_CB* p_cb = &smp_cb; + uint8_t failure = SMP_OOB_FAIL; + tSMP_KEY key; - SMP_TRACE_EVENT ("%s State: %d res:%d", __func__, smp_cb.state, res); + SMP_TRACE_EVENT("%s State: %d res:%d", __func__, smp_cb.state, res); - /* If timeout already expired or has been canceled, ignore the reply */ - if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_OOB_REQ_EVT) - return; + /* If timeout already expired or has been canceled, ignore the reply */ + if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_OOB_REQ_EVT) + return; - if (res != SMP_SUCCESS || len == 0 || !p_data) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - } - else - { - if (len > BT_OCTET16_LEN) - len = BT_OCTET16_LEN; + if (res != SMP_SUCCESS || len == 0 || !p_data) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + } else { + if (len > BT_OCTET16_LEN) len = BT_OCTET16_LEN; - memcpy(p_cb->tk, p_data, len); + memcpy(p_cb->tk, p_data, len); - key.key_type = SMP_KEY_TYPE_TK; - key.p_data = p_cb->tk; + key.key_type = SMP_KEY_TYPE_TK; + key.p_data = p_cb->tk; - smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &key); - } + smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &key); + } } /******************************************************************************* @@ -452,57 +415,53 @@ void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, uint8_t len, uint8_t *p_ * Parameters: p_data - pointer to the data * ******************************************************************************/ -void SMP_SecureConnectionOobDataReply(uint8_t *p_data) -{ - tSMP_CB *p_cb = &smp_cb; - - uint8_t failure = SMP_OOB_FAIL; - tSMP_SC_OOB_DATA *p_oob = (tSMP_SC_OOB_DATA *) p_data; - if (!p_oob) - { - SMP_TRACE_ERROR("%s received no data",__func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - return; - } +void SMP_SecureConnectionOobDataReply(uint8_t* p_data) { + tSMP_CB* p_cb = &smp_cb; + + uint8_t failure = SMP_OOB_FAIL; + tSMP_SC_OOB_DATA* p_oob = (tSMP_SC_OOB_DATA*)p_data; + if (!p_oob) { + SMP_TRACE_ERROR("%s received no data", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + return; + } - SMP_TRACE_EVENT ("%s req_oob_type: %d, loc_oob_data.present: %d, " - "peer_oob_data.present: %d", - __func__, p_cb->req_oob_type, p_oob->loc_oob_data.present, - p_oob->peer_oob_data.present); - - if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_SC_OOB_REQ_EVT) - return; - - bool data_missing = false; - switch (p_cb->req_oob_type) - { - case SMP_OOB_PEER: - if (!p_oob->peer_oob_data.present) - data_missing = true; - break; - case SMP_OOB_LOCAL: - if (!p_oob->loc_oob_data.present) - data_missing = true; - break; - case SMP_OOB_BOTH: - if (!p_oob->loc_oob_data.present || !p_oob->peer_oob_data.present) - data_missing = true; - break; - default: - SMP_TRACE_EVENT ("Unexpected OOB data type requested. Fail OOB"); - data_missing = true; - break; - } + SMP_TRACE_EVENT( + "%s req_oob_type: %d, loc_oob_data.present: %d, " + "peer_oob_data.present: %d", + __func__, p_cb->req_oob_type, p_oob->loc_oob_data.present, + p_oob->peer_oob_data.present); - if (data_missing) - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - return; - } + if (p_cb->state != SMP_STATE_WAIT_APP_RSP || + p_cb->cb_evt != SMP_SC_OOB_REQ_EVT) + return; + + bool data_missing = false; + switch (p_cb->req_oob_type) { + case SMP_OOB_PEER: + if (!p_oob->peer_oob_data.present) data_missing = true; + break; + case SMP_OOB_LOCAL: + if (!p_oob->loc_oob_data.present) data_missing = true; + break; + case SMP_OOB_BOTH: + if (!p_oob->loc_oob_data.present || !p_oob->peer_oob_data.present) + data_missing = true; + break; + default: + SMP_TRACE_EVENT("Unexpected OOB data type requested. Fail OOB"); + data_missing = true; + break; + } + + if (data_missing) { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + return; + } - p_cb->sc_oob_data = *p_oob; + p_cb->sc_oob_data = *p_oob; - smp_sm_event(&smp_cb, SMP_SC_OOB_DATA_EVT, p_data); + smp_sm_event(&smp_cb, SMP_SC_OOB_DATA_EVT, p_data); } /******************************************************************************* @@ -521,14 +480,13 @@ void SMP_SecureConnectionOobDataReply(uint8_t *p_data) * * Returns Boolean - request is successful ******************************************************************************/ -bool SMP_Encrypt (uint8_t *key, uint8_t key_len, - uint8_t *plain_text, uint8_t pt_len, - tSMP_ENC *p_out) +bool SMP_Encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, tSMP_ENC* p_out) { - bool status=false; - status = smp_encrypt_data(key, key_len, plain_text, pt_len, p_out); - return status; + bool status = false; + status = smp_encrypt_data(key, key_len, plain_text, pt_len, p_out); + return status; } /******************************************************************************* @@ -543,40 +501,36 @@ bool SMP_Encrypt (uint8_t *key, uint8_t key_len, * value Keypress notification parameter value * ******************************************************************************/ -void SMP_KeypressNotification (BD_ADDR bd_addr, uint8_t value) -{ - tSMP_CB *p_cb = &smp_cb; +void SMP_KeypressNotification(BD_ADDR bd_addr, uint8_t value) { + tSMP_CB* p_cb = &smp_cb; - SMP_TRACE_EVENT ("%s: Value: %d", __func__,value); + SMP_TRACE_EVENT("%s: Value: %d", __func__, value); - if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) - { - SMP_TRACE_ERROR ("%s() - Wrong BD Addr",__func__); - return; - } + if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) { + SMP_TRACE_ERROR("%s() - Wrong BD Addr", __func__); + return; + } - if (btm_find_dev (bd_addr) == NULL) - { - SMP_TRACE_ERROR ("%s() - no dev CB",__func__); - return; - } + if (btm_find_dev(bd_addr) == NULL) { + SMP_TRACE_ERROR("%s() - no dev CB", __func__); + return; + } - /* Keypress Notification is used by a device with KeyboardOnly IO capabilities during the passkey entry protocol */ - if (p_cb->local_io_capability != SMP_IO_CAP_IN) - { - SMP_TRACE_ERROR ("%s() - wrong local IO capabilities %d", - __func__, p_cb->local_io_capability); - return; - } + /* Keypress Notification is used by a device with KeyboardOnly IO capabilities + * during the passkey entry protocol */ + if (p_cb->local_io_capability != SMP_IO_CAP_IN) { + SMP_TRACE_ERROR("%s() - wrong local IO capabilities %d", __func__, + p_cb->local_io_capability); + return; + } - if (p_cb->selected_association_model != SMP_MODEL_SEC_CONN_PASSKEY_ENT) - { - SMP_TRACE_ERROR ("%s() - wrong protocol %d", __func__, - p_cb->selected_association_model); - return; - } + if (p_cb->selected_association_model != SMP_MODEL_SEC_CONN_PASSKEY_ENT) { + SMP_TRACE_ERROR("%s() - wrong protocol %d", __func__, + p_cb->selected_association_model); + return; + } - smp_sm_event(p_cb, SMP_KEYPRESS_NOTIFICATION_EVENT, &value); + smp_sm_event(p_cb, SMP_KEYPRESS_NOTIFICATION_EVENT, &value); } /******************************************************************************* @@ -590,35 +544,33 @@ void SMP_KeypressNotification (BD_ADDR bd_addr, uint8_t value) * * Returns Boolean - true: creation of local SC OOB data set started. ******************************************************************************/ -bool SMP_CreateLocalSecureConnectionsOobData (tBLE_BD_ADDR *addr_to_send_to) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t *bd_addr; - - if (addr_to_send_to == NULL) - { - SMP_TRACE_ERROR ("%s addr_to_send_to is not provided",__func__); - return false; - } - - bd_addr = addr_to_send_to->bda; - - SMP_TRACE_EVENT ("%s addr type: %u, BDA: %08x%04x, state: %u, br_state: %u", - __func__, addr_to_send_to->type, - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8) + bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], - p_cb->state, - p_cb->br_state); - - if ((p_cb->state != SMP_STATE_IDLE) || (p_cb->smp_over_br)) - { - SMP_TRACE_WARNING ("%s creation of local OOB data set "\ - "starts only in IDLE state",__func__); - return false; - } - - p_cb->sc_oob_data.loc_oob_data.addr_sent_to = *addr_to_send_to; - smp_sm_event(p_cb, SMP_CR_LOC_SC_OOB_DATA_EVT, NULL); - - return true; +bool SMP_CreateLocalSecureConnectionsOobData(tBLE_BD_ADDR* addr_to_send_to) { + tSMP_CB* p_cb = &smp_cb; + uint8_t* bd_addr; + + if (addr_to_send_to == NULL) { + SMP_TRACE_ERROR("%s addr_to_send_to is not provided", __func__); + return false; + } + + bd_addr = addr_to_send_to->bda; + + SMP_TRACE_EVENT( + "%s addr type: %u, BDA: %08x%04x, state: %u, br_state: %u", __func__, + addr_to_send_to->type, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], p_cb->state, p_cb->br_state); + + if ((p_cb->state != SMP_STATE_IDLE) || (p_cb->smp_over_br)) { + SMP_TRACE_WARNING( + "%s creation of local OOB data set " + "starts only in IDLE state", + __func__); + return false; + } + + p_cb->sc_oob_data.loc_oob_data.addr_sent_to = *addr_to_send_to; + smp_sm_event(p_cb, SMP_CR_LOC_SC_OOB_DATA_EVT, NULL); + + return true; } diff --git a/stack/smp/smp_br_main.cc b/stack/smp/smp_br_main.cc index b14e9a5e3..260b9c4fd 100644 --- a/stack/smp/smp_br_main.cc +++ b/stack/smp/smp_br_main.cc @@ -21,243 +21,206 @@ #include #include "smp_int.h" -const char *const smp_br_state_name [SMP_BR_STATE_MAX+1] = -{ - "SMP_BR_STATE_IDLE", - "SMP_BR_STATE_WAIT_APP_RSP", - "SMP_BR_STATE_PAIR_REQ_RSP", - "SMP_BR_STATE_BOND_PENDING", - "SMP_BR_STATE_OUT_OF_RANGE" -}; - -const char *const smp_br_event_name [SMP_BR_MAX_EVT] = -{ - "BR_PAIRING_REQ_EVT", - "BR_PAIRING_RSP_EVT", - "BR_CONFIRM_EVT", - "BR_RAND_EVT", - "BR_PAIRING_FAILED_EVT", - "BR_ENCRPTION_INFO_EVT", - "BR_MASTER_ID_EVT", - "BR_ID_INFO_EVT", - "BR_ID_ADDR_EVT", - "BR_SIGN_INFO_EVT", - "BR_SECURITY_REQ_EVT", - "BR_PAIR_PUBLIC_KEY_EVT", - "BR_PAIR_DHKEY_CHCK_EVT", - "BR_PAIR_KEYPR_NOTIF_EVT", - "BR_KEY_READY_EVT", - "BR_ENCRYPTED_EVT", - "BR_L2CAP_CONN_EVT", - "BR_L2CAP_DISCONN_EVT", - "BR_KEYS_RSP_EVT", - "BR_API_SEC_GRANT_EVT", - "BR_TK_REQ_EVT", - "BR_AUTH_CMPL_EVT", - "BR_ENC_REQ_EVT", - "BR_BOND_REQ_EVT", - "BR_DISCARD_SEC_REQ_EVT", - "BR_OUT_OF_RANGE_EVT" -}; - -const char *smp_get_br_event_name(tSMP_BR_EVENT event); -const char *smp_get_br_state_name(tSMP_BR_STATE state); - -#define SMP_BR_SM_IGNORE 0 -#define SMP_BR_NUM_ACTIONS 2 -#define SMP_BR_SME_NEXT_STATE 2 -#define SMP_BR_SM_NUM_COLS 3 +const char* const smp_br_state_name[SMP_BR_STATE_MAX + 1] = { + "SMP_BR_STATE_IDLE", "SMP_BR_STATE_WAIT_APP_RSP", + "SMP_BR_STATE_PAIR_REQ_RSP", "SMP_BR_STATE_BOND_PENDING", + "SMP_BR_STATE_OUT_OF_RANGE"}; + +const char* const smp_br_event_name[SMP_BR_MAX_EVT] = { + "BR_PAIRING_REQ_EVT", "BR_PAIRING_RSP_EVT", + "BR_CONFIRM_EVT", "BR_RAND_EVT", + "BR_PAIRING_FAILED_EVT", "BR_ENCRPTION_INFO_EVT", + "BR_MASTER_ID_EVT", "BR_ID_INFO_EVT", + "BR_ID_ADDR_EVT", "BR_SIGN_INFO_EVT", + "BR_SECURITY_REQ_EVT", "BR_PAIR_PUBLIC_KEY_EVT", + "BR_PAIR_DHKEY_CHCK_EVT", "BR_PAIR_KEYPR_NOTIF_EVT", + "BR_KEY_READY_EVT", "BR_ENCRYPTED_EVT", + "BR_L2CAP_CONN_EVT", "BR_L2CAP_DISCONN_EVT", + "BR_KEYS_RSP_EVT", "BR_API_SEC_GRANT_EVT", + "BR_TK_REQ_EVT", "BR_AUTH_CMPL_EVT", + "BR_ENC_REQ_EVT", "BR_BOND_REQ_EVT", + "BR_DISCARD_SEC_REQ_EVT", "BR_OUT_OF_RANGE_EVT"}; + +const char* smp_get_br_event_name(tSMP_BR_EVENT event); +const char* smp_get_br_state_name(tSMP_BR_STATE state); + +#define SMP_BR_SM_IGNORE 0 +#define SMP_BR_NUM_ACTIONS 2 +#define SMP_BR_SME_NEXT_STATE 2 +#define SMP_BR_SM_NUM_COLS 3 typedef const uint8_t (*tSMP_BR_SM_TBL)[SMP_BR_SM_NUM_COLS]; -enum -{ - SMP_SEND_PAIR_REQ, - SMP_BR_SEND_PAIR_RSP, - SMP_SEND_PAIR_FAIL, - SMP_SEND_ID_INFO, - SMP_BR_PROC_PAIR_CMD, - SMP_PROC_PAIR_FAIL, - SMP_PROC_ID_INFO, - SMP_PROC_ID_ADDR, - SMP_PROC_SRK_INFO, - SMP_BR_PROC_SEC_GRANT, - SMP_BR_PROC_SL_KEYS_RSP, - SMP_BR_KEY_DISTRIBUTION, - SMP_BR_PAIRING_COMPLETE, - SMP_SEND_APP_CBACK, - SMP_BR_CHECK_AUTH_REQ, - SMP_PAIR_TERMINATE, - SMP_IDLE_TERMINATE, - SMP_BR_SM_NO_ACTION +enum { + SMP_SEND_PAIR_REQ, + SMP_BR_SEND_PAIR_RSP, + SMP_SEND_PAIR_FAIL, + SMP_SEND_ID_INFO, + SMP_BR_PROC_PAIR_CMD, + SMP_PROC_PAIR_FAIL, + SMP_PROC_ID_INFO, + SMP_PROC_ID_ADDR, + SMP_PROC_SRK_INFO, + SMP_BR_PROC_SEC_GRANT, + SMP_BR_PROC_SL_KEYS_RSP, + SMP_BR_KEY_DISTRIBUTION, + SMP_BR_PAIRING_COMPLETE, + SMP_SEND_APP_CBACK, + SMP_BR_CHECK_AUTH_REQ, + SMP_PAIR_TERMINATE, + SMP_IDLE_TERMINATE, + SMP_BR_SM_NO_ACTION }; -static const tSMP_ACT smp_br_sm_action[] = -{ - smp_send_pair_req, - smp_br_send_pair_response, - smp_send_pair_fail, - smp_send_id_info, - smp_br_process_pairing_command, - smp_proc_pair_fail, - smp_proc_id_info, - smp_proc_id_addr, - smp_proc_srk_info, - smp_br_process_security_grant, - smp_br_process_slave_keys_response, - smp_br_select_next_key, - smp_br_pairing_complete, - smp_send_app_cback, - smp_br_check_authorization_request, - smp_pair_terminate, - smp_idle_terminate -}; - -static const uint8_t smp_br_all_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_PAIRING_FAILED */ -{SMP_PROC_PAIR_FAIL, SMP_BR_PAIRING_COMPLETE, SMP_BR_STATE_IDLE}, -/* BR_AUTH_CMPL */ -{SMP_SEND_PAIR_FAIL, SMP_BR_PAIRING_COMPLETE, SMP_BR_STATE_IDLE}, -/* BR_L2CAP_DISCONN */ -{SMP_PAIR_TERMINATE, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_IDLE} -}; +static const tSMP_ACT smp_br_sm_action[] = {smp_send_pair_req, + smp_br_send_pair_response, + smp_send_pair_fail, + smp_send_id_info, + smp_br_process_pairing_command, + smp_proc_pair_fail, + smp_proc_id_info, + smp_proc_id_addr, + smp_proc_srk_info, + smp_br_process_security_grant, + smp_br_process_slave_keys_response, + smp_br_select_next_key, + smp_br_pairing_complete, + smp_send_app_cback, + smp_br_check_authorization_request, + smp_pair_terminate, + smp_idle_terminate}; + +static const uint8_t smp_br_all_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_PAIRING_FAILED */ + {SMP_PROC_PAIR_FAIL, SMP_BR_PAIRING_COMPLETE, SMP_BR_STATE_IDLE}, + /* BR_AUTH_CMPL */ + {SMP_SEND_PAIR_FAIL, SMP_BR_PAIRING_COMPLETE, SMP_BR_STATE_IDLE}, + /* BR_L2CAP_DISCONN */ + {SMP_PAIR_TERMINATE, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_IDLE}}; /************ SMP Master FSM State/Event Indirection Table **************/ -static const uint8_t smp_br_master_entry_map[][SMP_BR_STATE_MAX] = -{ -/* br_state name: Idle WaitApp Pair Bond - Rsp ReqRsp Pend */ -/* BR_PAIRING_REQ */ { 0, 0, 0, 0 }, -/* BR_PAIRING_RSP */ { 0, 0, 1, 0 }, -/* BR_CONFIRM */ { 0, 0, 0, 0 }, -/* BR_RAND */ { 0, 0, 0, 0 }, -/* BR_PAIRING_FAILED */ { 0, 0x81, 0x81, 0 }, -/* BR_ENCRPTION_INFO */ { 0, 0, 0, 0 }, -/* BR_MASTER_ID */ { 0, 0, 0, 0 }, -/* BR_ID_INFO */ { 0, 0, 0, 1 }, -/* BR_ID_ADDR */ { 0, 0, 0, 2 }, -/* BR_SIGN_INFO */ { 0, 0, 0, 3 }, -/* BR_SECURITY_REQ */ { 0, 0, 0, 0 }, -/* BR_PAIR_PUBLIC_KEY_EVT */ { 0, 0, 0, 0 }, -/* BR_PAIR_DHKEY_CHCK_EVT */ { 0, 0, 0, 0 }, -/* BR_PAIR_KEYPR_NOTIF_EVT */ { 0, 0, 0, 0 }, -/* BR_KEY_READY */ { 0, 0, 0, 0 }, -/* BR_ENCRYPTED */ { 0, 0, 0, 0 }, -/* BR_L2CAP_CONN */ { 1, 0, 0, 0 }, -/* BR_L2CAP_DISCONN */ { 2, 0x83, 0x83, 0x83 }, -/* BR_KEYS_RSP */ { 0, 1, 0, 0 }, -/* BR_API_SEC_GRANT */ { 0, 0, 0, 0 }, -/* BR_TK_REQ */ { 0, 0, 0, 0 }, -/* BR_AUTH_CMPL */ { 0, 0x82, 0x82, 0x82 }, -/* BR_ENC_REQ */ { 0, 0, 0, 0 }, -/* BR_BOND_REQ */ { 0, 0, 2, 0 }, -/* BR_DISCARD_SEC_REQ */ { 0, 0, 0, 0 } -}; - -static const uint8_t smp_br_master_idle_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_L2CAP_CONN */ -{SMP_SEND_APP_CBACK, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_WAIT_APP_RSP}, -/* BR_L2CAP_DISCONN */ -{SMP_IDLE_TERMINATE, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_IDLE} -}; - -static const uint8_t smp_br_master_wait_appln_response_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_KEYS_RSP */ -{SMP_SEND_PAIR_REQ, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_PAIR_REQ_RSP} -}; - -static const uint8_t smp_br_master_pair_request_response_table [][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_PAIRING_RSP */ -{SMP_BR_PROC_PAIR_CMD, SMP_BR_CHECK_AUTH_REQ, SMP_BR_STATE_PAIR_REQ_RSP}, -/* BR_BOND_REQ */ -{SMP_BR_SM_NO_ACTION, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING} -}; - -static const uint8_t smp_br_master_bond_pending_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_ID_INFO */ -{SMP_PROC_ID_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, -/* BR_ID_ADDR */ -{SMP_PROC_ID_ADDR, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, -/* BR_SIGN_INFO */ -{SMP_PROC_SRK_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING} -}; - -static const uint8_t smp_br_slave_entry_map[][SMP_BR_STATE_MAX] = -{ -/* br_state name: Idle WaitApp Pair Bond - Rsp ReqRsp Pend */ -/* BR_PAIRING_REQ */ { 1, 0, 0, 0 }, -/* BR_PAIRING_RSP */ { 0, 0, 0, 0 }, -/* BR_CONFIRM */ { 0, 0, 0, 0 }, -/* BR_RAND */ { 0, 0, 0, 0 }, -/* BR_PAIRING_FAILED */ { 0, 0x81, 0x81, 0x81 }, -/* BR_ENCRPTION_INFO */ { 0, 0, 0, 0 }, -/* BR_MASTER_ID */ { 0, 0, 0, 0 }, -/* BR_ID_INFO */ { 0, 0, 0, 1 }, -/* BR_ID_ADDR */ { 0, 0, 0, 2 }, -/* BR_SIGN_INFO */ { 0, 0, 0, 3 }, -/* BR_SECURITY_REQ */ { 0, 0, 0, 0 }, -/* BR_PAIR_PUBLIC_KEY_EVT */ { 0, 0, 0, 0 }, -/* BR_PAIR_DHKEY_CHCK_EVT */ { 0, 0, 0, 0 }, -/* BR_PAIR_KEYPR_NOTIF_EVT */ { 0, 0, 0, 0 }, -/* BR_KEY_READY */ { 0, 0, 0, 0 }, -/* BR_ENCRYPTED */ { 0, 0, 0, 0 }, -/* BR_L2CAP_CONN */ { 0, 0, 0, 0 }, -/* BR_L2CAP_DISCONN */ { 0, 0x83, 0x83, 0x83 }, -/* BR_KEYS_RSP */ { 0, 2, 0, 0 }, -/* BR_API_SEC_GRANT */ { 0, 1, 0, 0 }, -/* BR_TK_REQ */ { 0, 0, 0, 0 }, -/* BR_AUTH_CMPL */ { 0, 0x82, 0x82, 0x82 }, -/* BR_ENC_REQ */ { 0, 0, 0, 0 }, -/* BR_BOND_REQ */ { 0, 3, 0, 0 }, -/* BR_DISCARD_SEC_REQ */ { 0, 0, 0, 0 } -}; - -static const uint8_t smp_br_slave_idle_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_PAIRING_REQ */ -{SMP_BR_PROC_PAIR_CMD, SMP_SEND_APP_CBACK, SMP_BR_STATE_WAIT_APP_RSP} -}; - -static const uint8_t smp_br_slave_wait_appln_response_table [][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_API_SEC_GRANT */ -{SMP_BR_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_BR_STATE_WAIT_APP_RSP}, -/* BR_KEYS_RSP */ -{SMP_BR_PROC_SL_KEYS_RSP, SMP_BR_CHECK_AUTH_REQ,SMP_BR_STATE_WAIT_APP_RSP}, -/* BR_BOND_REQ */ -{SMP_BR_KEY_DISTRIBUTION, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING} -}; - -static const uint8_t smp_br_slave_bond_pending_table[][SMP_BR_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* BR_ID_INFO */ -{SMP_PROC_ID_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, -/* BR_ID_ADDR */ -{SMP_PROC_ID_ADDR, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, -/* BR_SIGN_INFO */ -{SMP_PROC_SRK_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING} -}; - -static const tSMP_BR_SM_TBL smp_br_state_table[][2] = -{ +static const uint8_t smp_br_master_entry_map[][SMP_BR_STATE_MAX] = { + /* br_state name: Idle WaitApp Pair Bond + Rsp ReqRsp Pend */ + /* BR_PAIRING_REQ */ {0, 0, 0, 0}, + /* BR_PAIRING_RSP */ {0, 0, 1, 0}, + /* BR_CONFIRM */ {0, 0, 0, 0}, + /* BR_RAND */ {0, 0, 0, 0}, + /* BR_PAIRING_FAILED */ {0, 0x81, 0x81, 0}, + /* BR_ENCRPTION_INFO */ {0, 0, 0, 0}, + /* BR_MASTER_ID */ {0, 0, 0, 0}, + /* BR_ID_INFO */ {0, 0, 0, 1}, + /* BR_ID_ADDR */ {0, 0, 0, 2}, + /* BR_SIGN_INFO */ {0, 0, 0, 3}, + /* BR_SECURITY_REQ */ {0, 0, 0, 0}, + /* BR_PAIR_PUBLIC_KEY_EVT */ {0, 0, 0, 0}, + /* BR_PAIR_DHKEY_CHCK_EVT */ {0, 0, 0, 0}, + /* BR_PAIR_KEYPR_NOTIF_EVT */ {0, 0, 0, 0}, + /* BR_KEY_READY */ {0, 0, 0, 0}, + /* BR_ENCRYPTED */ {0, 0, 0, 0}, + /* BR_L2CAP_CONN */ {1, 0, 0, 0}, + /* BR_L2CAP_DISCONN */ {2, 0x83, 0x83, 0x83}, + /* BR_KEYS_RSP */ {0, 1, 0, 0}, + /* BR_API_SEC_GRANT */ {0, 0, 0, 0}, + /* BR_TK_REQ */ {0, 0, 0, 0}, + /* BR_AUTH_CMPL */ {0, 0x82, 0x82, 0x82}, + /* BR_ENC_REQ */ {0, 0, 0, 0}, + /* BR_BOND_REQ */ {0, 0, 2, 0}, + /* BR_DISCARD_SEC_REQ */ {0, 0, 0, 0}}; + +static const uint8_t smp_br_master_idle_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_L2CAP_CONN */ + {SMP_SEND_APP_CBACK, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_WAIT_APP_RSP}, + /* BR_L2CAP_DISCONN */ + {SMP_IDLE_TERMINATE, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_IDLE}}; + +static const uint8_t + smp_br_master_wait_appln_response_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_KEYS_RSP */ + {SMP_SEND_PAIR_REQ, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_PAIR_REQ_RSP}}; + +static const uint8_t + smp_br_master_pair_request_response_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_PAIRING_RSP */ + {SMP_BR_PROC_PAIR_CMD, SMP_BR_CHECK_AUTH_REQ, + SMP_BR_STATE_PAIR_REQ_RSP}, + /* BR_BOND_REQ */ + {SMP_BR_SM_NO_ACTION, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}}; + +static const uint8_t smp_br_master_bond_pending_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_ID_INFO */ + {SMP_PROC_ID_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, + /* BR_ID_ADDR */ + {SMP_PROC_ID_ADDR, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, + /* BR_SIGN_INFO */ + {SMP_PROC_SRK_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}}; + +static const uint8_t smp_br_slave_entry_map[][SMP_BR_STATE_MAX] = { + /* br_state name: Idle WaitApp Pair Bond + Rsp ReqRsp Pend */ + /* BR_PAIRING_REQ */ {1, 0, 0, 0}, + /* BR_PAIRING_RSP */ {0, 0, 0, 0}, + /* BR_CONFIRM */ {0, 0, 0, 0}, + /* BR_RAND */ {0, 0, 0, 0}, + /* BR_PAIRING_FAILED */ {0, 0x81, 0x81, 0x81}, + /* BR_ENCRPTION_INFO */ {0, 0, 0, 0}, + /* BR_MASTER_ID */ {0, 0, 0, 0}, + /* BR_ID_INFO */ {0, 0, 0, 1}, + /* BR_ID_ADDR */ {0, 0, 0, 2}, + /* BR_SIGN_INFO */ {0, 0, 0, 3}, + /* BR_SECURITY_REQ */ {0, 0, 0, 0}, + /* BR_PAIR_PUBLIC_KEY_EVT */ {0, 0, 0, 0}, + /* BR_PAIR_DHKEY_CHCK_EVT */ {0, 0, 0, 0}, + /* BR_PAIR_KEYPR_NOTIF_EVT */ {0, 0, 0, 0}, + /* BR_KEY_READY */ {0, 0, 0, 0}, + /* BR_ENCRYPTED */ {0, 0, 0, 0}, + /* BR_L2CAP_CONN */ {0, 0, 0, 0}, + /* BR_L2CAP_DISCONN */ {0, 0x83, 0x83, 0x83}, + /* BR_KEYS_RSP */ {0, 2, 0, 0}, + /* BR_API_SEC_GRANT */ {0, 1, 0, 0}, + /* BR_TK_REQ */ {0, 0, 0, 0}, + /* BR_AUTH_CMPL */ {0, 0x82, 0x82, 0x82}, + /* BR_ENC_REQ */ {0, 0, 0, 0}, + /* BR_BOND_REQ */ {0, 3, 0, 0}, + /* BR_DISCARD_SEC_REQ */ {0, 0, 0, 0}}; + +static const uint8_t smp_br_slave_idle_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_PAIRING_REQ */ + {SMP_BR_PROC_PAIR_CMD, SMP_SEND_APP_CBACK, SMP_BR_STATE_WAIT_APP_RSP}}; + +static const uint8_t + smp_br_slave_wait_appln_response_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_API_SEC_GRANT */ + {SMP_BR_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_BR_STATE_WAIT_APP_RSP}, + /* BR_KEYS_RSP */ + {SMP_BR_PROC_SL_KEYS_RSP, SMP_BR_CHECK_AUTH_REQ, + SMP_BR_STATE_WAIT_APP_RSP}, + /* BR_BOND_REQ */ + {SMP_BR_KEY_DISTRIBUTION, SMP_BR_SM_NO_ACTION, + SMP_BR_STATE_BOND_PENDING}}; + +static const uint8_t smp_br_slave_bond_pending_table[][SMP_BR_SM_NUM_COLS] = { + /* Event Action Next State */ + /* BR_ID_INFO */ + {SMP_PROC_ID_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, + /* BR_ID_ADDR */ + {SMP_PROC_ID_ADDR, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}, + /* BR_SIGN_INFO */ + {SMP_PROC_SRK_INFO, SMP_BR_SM_NO_ACTION, SMP_BR_STATE_BOND_PENDING}}; + +static const tSMP_BR_SM_TBL smp_br_state_table[][2] = { /* SMP_BR_STATE_IDLE */ {smp_br_master_idle_table, smp_br_slave_idle_table}, /* SMP_BR_STATE_WAIT_APP_RSP */ - {smp_br_master_wait_appln_response_table, smp_br_slave_wait_appln_response_table}, + {smp_br_master_wait_appln_response_table, + smp_br_slave_wait_appln_response_table}, /* SMP_BR_STATE_PAIR_REQ_RSP */ {smp_br_master_pair_request_response_table, NULL}, @@ -268,68 +231,54 @@ static const tSMP_BR_SM_TBL smp_br_state_table[][2] = typedef const uint8_t (*tSMP_BR_ENTRY_TBL)[SMP_BR_STATE_MAX]; -static const tSMP_BR_ENTRY_TBL smp_br_entry_table[] = -{ - smp_br_master_entry_map, - smp_br_slave_entry_map -}; +static const tSMP_BR_ENTRY_TBL smp_br_entry_table[] = {smp_br_master_entry_map, + smp_br_slave_entry_map}; -#define SMP_BR_ALL_TABLE_MASK 0x80 +#define SMP_BR_ALL_TABLE_MASK 0x80 /******************************************************************************* * Function smp_set_br_state * Returns None ******************************************************************************/ -void smp_set_br_state(tSMP_BR_STATE br_state) -{ - if (br_state < SMP_BR_STATE_MAX) - { - SMP_TRACE_DEBUG( "BR_State change: %s(%d) ==> %s(%d)", - smp_get_br_state_name(smp_cb.br_state), smp_cb.br_state, - smp_get_br_state_name(br_state), br_state ); - smp_cb.br_state = br_state; - } - else - { - SMP_TRACE_DEBUG("%s invalid br_state =%d", __func__,br_state ); - } +void smp_set_br_state(tSMP_BR_STATE br_state) { + if (br_state < SMP_BR_STATE_MAX) { + SMP_TRACE_DEBUG("BR_State change: %s(%d) ==> %s(%d)", + smp_get_br_state_name(smp_cb.br_state), smp_cb.br_state, + smp_get_br_state_name(br_state), br_state); + smp_cb.br_state = br_state; + } else { + SMP_TRACE_DEBUG("%s invalid br_state =%d", __func__, br_state); + } } /******************************************************************************* * Function smp_get_br_state * Returns The smp_br state ******************************************************************************/ -tSMP_BR_STATE smp_get_br_state(void) -{ - return smp_cb.br_state; -} +tSMP_BR_STATE smp_get_br_state(void) { return smp_cb.br_state; } /******************************************************************************* * Function smp_get_br_state_name * Returns The smp_br state name. ******************************************************************************/ -const char *smp_get_br_state_name(tSMP_BR_STATE br_state) -{ - const char *p_str = smp_br_state_name[SMP_BR_STATE_MAX]; +const char* smp_get_br_state_name(tSMP_BR_STATE br_state) { + const char* p_str = smp_br_state_name[SMP_BR_STATE_MAX]; - if (br_state < SMP_BR_STATE_MAX) - p_str = smp_br_state_name[br_state]; + if (br_state < SMP_BR_STATE_MAX) p_str = smp_br_state_name[br_state]; - return p_str; + return p_str; } /******************************************************************************* * Function smp_get_br_event_name * Returns The smp_br event name. ******************************************************************************/ -const char * smp_get_br_event_name(tSMP_BR_EVENT event) -{ - const char * p_str = smp_br_event_name[SMP_BR_MAX_EVT - 1]; +const char* smp_get_br_event_name(tSMP_BR_EVENT event) { + const char* p_str = smp_br_event_name[SMP_BR_MAX_EVT - 1]; - if (event < SMP_BR_MAX_EVT) - { - p_str = smp_br_event_name[event- 1]; - } - return p_str; + if (event < SMP_BR_MAX_EVT) { + p_str = smp_br_event_name[event - 1]; + } + return p_str; } /******************************************************************************* @@ -346,69 +295,58 @@ const char * smp_get_br_event_name(tSMP_BR_EVENT event) * Returns void. * ******************************************************************************/ -void smp_br_state_machine_event(tSMP_CB *p_cb, tSMP_BR_EVENT event, void *p_data) -{ - tSMP_BR_STATE curr_state = p_cb->br_state; - tSMP_BR_SM_TBL state_table; - uint8_t action, entry; - tSMP_BR_ENTRY_TBL entry_table = smp_br_entry_table[p_cb->role]; - - SMP_TRACE_EVENT("main %s", __func__); - if (curr_state >= SMP_BR_STATE_MAX) - { - SMP_TRACE_DEBUG( "Invalid br_state: %d", curr_state) ; - return; +void smp_br_state_machine_event(tSMP_CB* p_cb, tSMP_BR_EVENT event, + void* p_data) { + tSMP_BR_STATE curr_state = p_cb->br_state; + tSMP_BR_SM_TBL state_table; + uint8_t action, entry; + tSMP_BR_ENTRY_TBL entry_table = smp_br_entry_table[p_cb->role]; + + SMP_TRACE_EVENT("main %s", __func__); + if (curr_state >= SMP_BR_STATE_MAX) { + SMP_TRACE_DEBUG("Invalid br_state: %d", curr_state); + return; + } + + SMP_TRACE_DEBUG("SMP Role: %s State: [%s (%d)], Event: [%s (%d)]", + (p_cb->role == HCI_ROLE_SLAVE) ? "Slave" : "Master", + smp_get_br_state_name(p_cb->br_state), p_cb->br_state, + smp_get_br_event_name(event), event); + + /* look up the state table for the current state */ + /* lookup entry / w event & curr_state */ + /* If entry is ignore, return. + * Otherwise, get state table (according to curr_state or all_state) */ + if ((event <= SMP_BR_MAX_EVT) && + ((entry = entry_table[event - 1][curr_state]) != SMP_BR_SM_IGNORE)) { + if (entry & SMP_BR_ALL_TABLE_MASK) { + entry &= ~SMP_BR_ALL_TABLE_MASK; + state_table = smp_br_all_table; + } else { + state_table = smp_br_state_table[curr_state][p_cb->role]; } - - SMP_TRACE_DEBUG( "SMP Role: %s State: [%s (%d)], Event: [%s (%d)]", - (p_cb->role == HCI_ROLE_SLAVE) ? "Slave" : "Master", - smp_get_br_state_name( p_cb->br_state), - p_cb->br_state, smp_get_br_event_name(event), event) ; - - /* look up the state table for the current state */ - /* lookup entry / w event & curr_state */ - /* If entry is ignore, return. - * Otherwise, get state table (according to curr_state or all_state) */ - if ((event <= SMP_BR_MAX_EVT) && ( (entry = entry_table[event - 1][curr_state]) - != SMP_BR_SM_IGNORE )) - { - if (entry & SMP_BR_ALL_TABLE_MASK) - { - entry &= ~SMP_BR_ALL_TABLE_MASK; - state_table = smp_br_all_table; - } - else - { - state_table = smp_br_state_table[curr_state][p_cb->role]; - } - } - else - { - SMP_TRACE_DEBUG( "Ignore event [%s (%d)] in state [%s (%d)]", - smp_get_br_event_name(event), event, - smp_get_br_state_name(curr_state), curr_state); - return; - } - - /* Get possible next state from state table. */ - - smp_set_br_state(state_table[entry - 1][SMP_BR_SME_NEXT_STATE]); - - /* If action is not ignore, clear param, exec action and get next state. - * The action function may set the Param for cback. - * Depending on param, call cback or free buffer. */ - /* execute action functions */ - for (uint8_t i = 0; i < SMP_BR_NUM_ACTIONS; i++) - { - action = state_table[entry - 1][i]; - if (action != SMP_BR_SM_NO_ACTION) - { - (*smp_br_sm_action[action])(p_cb, (tSMP_INT_DATA *)p_data); - } - else - { - break; - } + } else { + SMP_TRACE_DEBUG("Ignore event [%s (%d)] in state [%s (%d)]", + smp_get_br_event_name(event), event, + smp_get_br_state_name(curr_state), curr_state); + return; + } + + /* Get possible next state from state table. */ + + smp_set_br_state(state_table[entry - 1][SMP_BR_SME_NEXT_STATE]); + + /* If action is not ignore, clear param, exec action and get next state. + * The action function may set the Param for cback. + * Depending on param, call cback or free buffer. */ + /* execute action functions */ + for (uint8_t i = 0; i < SMP_BR_NUM_ACTIONS; i++) { + action = state_table[entry - 1][i]; + if (action != SMP_BR_SM_NO_ACTION) { + (*smp_br_sm_action[action])(p_cb, (tSMP_INT_DATA*)p_data); + } else { + break; } - SMP_TRACE_DEBUG( "result state = %s", smp_get_br_state_name( p_cb->br_state ) ) ; + } + SMP_TRACE_DEBUG("result state = %s", smp_get_br_state_name(p_cb->br_state)); } diff --git a/stack/smp/smp_cmac.cc b/stack/smp/smp_cmac.cc index 2170082ce..876c42008 100644 --- a/stack/smp/smp_cmac.cc +++ b/stack/smp/smp_cmac.cc @@ -28,38 +28,34 @@ #include #include "btm_ble_api.h" -#include "smp_int.h" #include "hcimsgs.h" +#include "smp_int.h" -typedef struct -{ - uint8_t *text; - uint16_t len; - uint16_t round; -}tCMAC_CB; +typedef struct { + uint8_t* text; + uint16_t len; + uint16_t round; +} tCMAC_CB; -tCMAC_CB cmac_cb; +tCMAC_CB cmac_cb; /* Rb for AES-128 as block cipher, LSB as [0] */ -BT_OCTET16 const_Rb = { - 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; +BT_OCTET16 const_Rb = {0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -void print128(BT_OCTET16 x, const uint8_t *key_name) -{ +void print128(BT_OCTET16 x, const uint8_t* key_name) { #if (SMP_DEBUG == TRUE && SMP_DEBUG_VERBOSE == TRUE) - uint8_t *p = (uint8_t *)x; - uint8_t i; + uint8_t* p = (uint8_t*)x; + uint8_t i; - SMP_TRACE_WARNING("%s(MSB ~ LSB) = ", key_name); + SMP_TRACE_WARNING("%s(MSB ~ LSB) = ", key_name); - for (i = 0; i < 4; i ++) - { - SMP_TRACE_WARNING("%02x %02x %02x %02x", - p[BT_OCTET16_LEN - i*4 -1], p[BT_OCTET16_LEN - i*4 -2], - p[BT_OCTET16_LEN - i*4 -3], p[BT_OCTET16_LEN - i*4 -4]); - } + for (i = 0; i < 4; i++) { + SMP_TRACE_WARNING("%02x %02x %02x %02x", p[BT_OCTET16_LEN - i * 4 - 1], + p[BT_OCTET16_LEN - i * 4 - 2], + p[BT_OCTET16_LEN - i * 4 - 3], + p[BT_OCTET16_LEN - i * 4 - 4]); + } #endif } @@ -75,12 +71,11 @@ void print128(BT_OCTET16 x, const uint8_t *key_name) * Returns void * ******************************************************************************/ -static void padding ( BT_OCTET16 dest, uint8_t length ) -{ - uint8_t i, *p = dest; - /* original last block */ - for ( i = length ; i < BT_OCTET16_LEN; i++ ) - p[BT_OCTET16_LEN - i - 1] = ( i == length ) ? 0x80 : 0; +static void padding(BT_OCTET16 dest, uint8_t length) { + uint8_t i, *p = dest; + /* original last block */ + for (i = length; i < BT_OCTET16_LEN; i++) + p[BT_OCTET16_LEN - i - 1] = (i == length) ? 0x80 : 0; } /******************************************************************************* * @@ -91,18 +86,16 @@ static void padding ( BT_OCTET16 dest, uint8_t length ) * Returns void * ******************************************************************************/ -static void leftshift_onebit(uint8_t *input, uint8_t *output) -{ - uint8_t i, overflow = 0 , next_overflow = 0; - SMP_TRACE_EVENT ("leftshift_onebit "); - /* input[0] is LSB */ - for ( i = 0; i < BT_OCTET16_LEN ; i ++ ) - { - next_overflow = (input[i] & 0x80) ? 1:0; - output[i] = (input[i] << 1) | overflow; - overflow = next_overflow; - } - return; +static void leftshift_onebit(uint8_t* input, uint8_t* output) { + uint8_t i, overflow = 0, next_overflow = 0; + SMP_TRACE_EVENT("leftshift_onebit "); + /* input[0] is LSB */ + for (i = 0; i < BT_OCTET16_LEN; i++) { + next_overflow = (input[i] & 0x80) ? 1 : 0; + output[i] = (input[i] << 1) | overflow; + overflow = next_overflow; + } + return; } /******************************************************************************* * @@ -113,10 +106,9 @@ static void leftshift_onebit(uint8_t *input, uint8_t *output) * Returns void * ******************************************************************************/ -static void cmac_aes_cleanup(void) -{ - osi_free(cmac_cb.text); - memset(&cmac_cb, 0, sizeof(tCMAC_CB)); +static void cmac_aes_cleanup(void) { + osi_free(cmac_cb.text); + memset(&cmac_cb, 0, sizeof(tCMAC_CB)); } /******************************************************************************* @@ -129,45 +121,48 @@ static void cmac_aes_cleanup(void) * Returns void * ******************************************************************************/ -static bool cmac_aes_k_calculate(BT_OCTET16 key, uint8_t *p_signature, uint16_t tlen) -{ - tSMP_ENC output; - uint8_t i = 1, err = 0; - uint8_t x[16] = {0}; - uint8_t *p_mac; - - SMP_TRACE_EVENT ("cmac_aes_k_calculate "); - - while (i <= cmac_cb.round) - { - smp_xor_128(&cmac_cb.text[(cmac_cb.round - i)*BT_OCTET16_LEN], x); /* Mi' := Mi (+) X */ - - if (!SMP_Encrypt(key, BT_OCTET16_LEN, &cmac_cb.text[(cmac_cb.round - i)*BT_OCTET16_LEN], BT_OCTET16_LEN, &output)) - { - err = 1; - break; - } - - memcpy(x, output.param_buf, BT_OCTET16_LEN); - i ++; +static bool cmac_aes_k_calculate(BT_OCTET16 key, uint8_t* p_signature, + uint16_t tlen) { + tSMP_ENC output; + uint8_t i = 1, err = 0; + uint8_t x[16] = {0}; + uint8_t* p_mac; + + SMP_TRACE_EVENT("cmac_aes_k_calculate "); + + while (i <= cmac_cb.round) { + smp_xor_128(&cmac_cb.text[(cmac_cb.round - i) * BT_OCTET16_LEN], + x); /* Mi' := Mi (+) X */ + + if (!SMP_Encrypt(key, BT_OCTET16_LEN, + &cmac_cb.text[(cmac_cb.round - i) * BT_OCTET16_LEN], + BT_OCTET16_LEN, &output)) { + err = 1; + break; } - if (!err) - { - p_mac = output.param_buf + (BT_OCTET16_LEN - tlen); - memcpy(p_signature, p_mac, tlen); + memcpy(x, output.param_buf, BT_OCTET16_LEN); + i++; + } - SMP_TRACE_DEBUG("tlen = %d p_mac = %d", tlen, p_mac); - SMP_TRACE_DEBUG("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x", - *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3)); - SMP_TRACE_DEBUG("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x", - *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7)); + if (!err) { + p_mac = output.param_buf + (BT_OCTET16_LEN - tlen); + memcpy(p_signature, p_mac, tlen); - return true; + SMP_TRACE_DEBUG("tlen = %d p_mac = %d", tlen, p_mac); + SMP_TRACE_DEBUG( + "p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = " + "0x%02x", + *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3)); + SMP_TRACE_DEBUG( + "p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = " + "0x%02x", + *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7)); - } - else - return false; + return true; + + } else + return false; } /******************************************************************************* * @@ -179,27 +174,25 @@ static bool cmac_aes_k_calculate(BT_OCTET16 key, uint8_t *p_signature, uint16 * Returns void * ******************************************************************************/ -static void cmac_prepare_last_block (BT_OCTET16 k1, BT_OCTET16 k2) -{ -// uint8_t x[16] = {0}; - bool flag; +static void cmac_prepare_last_block(BT_OCTET16 k1, BT_OCTET16 k2) { + // uint8_t x[16] = {0}; + bool flag; - SMP_TRACE_EVENT ("cmac_prepare_last_block "); - /* last block is a complete block set flag to 1 */ - flag = ((cmac_cb.len % BT_OCTET16_LEN) == 0 && cmac_cb.len != 0) ? true : false; + SMP_TRACE_EVENT("cmac_prepare_last_block "); + /* last block is a complete block set flag to 1 */ + flag = + ((cmac_cb.len % BT_OCTET16_LEN) == 0 && cmac_cb.len != 0) ? true : false; - SMP_TRACE_WARNING("flag = %d round = %d", flag, cmac_cb.round); + SMP_TRACE_WARNING("flag = %d round = %d", flag, cmac_cb.round); - if ( flag ) - { /* last block is complete block */ - smp_xor_128(&cmac_cb.text[0], k1); - } - else /* padding then xor with k2 */ - { - padding(&cmac_cb.text[0], (uint8_t)(cmac_cb.len % 16)); + if (flag) { /* last block is complete block */ + smp_xor_128(&cmac_cb.text[0], k1); + } else /* padding then xor with k2 */ + { + padding(&cmac_cb.text[0], (uint8_t)(cmac_cb.len % 16)); - smp_xor_128(&cmac_cb.text[0], k2); - } + smp_xor_128(&cmac_cb.text[0], k2); + } } /******************************************************************************* * @@ -211,41 +204,34 @@ static void cmac_prepare_last_block (BT_OCTET16 k1, BT_OCTET16 k2) * Returns void * ******************************************************************************/ -static void cmac_subkey_cont(tSMP_ENC *p) -{ - uint8_t k1[BT_OCTET16_LEN], k2[BT_OCTET16_LEN]; - uint8_t *pp = p->param_buf; - SMP_TRACE_EVENT ("cmac_subkey_cont "); - print128(pp, (const uint8_t *)"K1 before shift"); - - /* If MSB(L) = 0, then K1 = L << 1 */ - if ( (pp[BT_OCTET16_LEN - 1] & 0x80) != 0 ) - { - /* Else K1 = ( L << 1 ) (+) Rb */ - leftshift_onebit(pp, k1); - smp_xor_128(k1, const_Rb); - } - else - { - leftshift_onebit(pp, k1); - } - - if ( (k1[BT_OCTET16_LEN - 1] & 0x80) != 0 ) - { - /* K2 = (K1 << 1) (+) Rb */ - leftshift_onebit(k1, k2); - smp_xor_128(k2, const_Rb); - } - else - { - /* If MSB(K1) = 0, then K2 = K1 << 1 */ - leftshift_onebit(k1, k2); - } - - print128(k1, (const uint8_t *)"K1"); - print128(k2, (const uint8_t *)"K2"); - - cmac_prepare_last_block (k1, k2); +static void cmac_subkey_cont(tSMP_ENC* p) { + uint8_t k1[BT_OCTET16_LEN], k2[BT_OCTET16_LEN]; + uint8_t* pp = p->param_buf; + SMP_TRACE_EVENT("cmac_subkey_cont "); + print128(pp, (const uint8_t*)"K1 before shift"); + + /* If MSB(L) = 0, then K1 = L << 1 */ + if ((pp[BT_OCTET16_LEN - 1] & 0x80) != 0) { + /* Else K1 = ( L << 1 ) (+) Rb */ + leftshift_onebit(pp, k1); + smp_xor_128(k1, const_Rb); + } else { + leftshift_onebit(pp, k1); + } + + if ((k1[BT_OCTET16_LEN - 1] & 0x80) != 0) { + /* K2 = (K1 << 1) (+) Rb */ + leftshift_onebit(k1, k2); + smp_xor_128(k2, const_Rb); + } else { + /* If MSB(K1) = 0, then K2 = K1 << 1 */ + leftshift_onebit(k1, k2); + } + + print128(k1, (const uint8_t*)"K1"); + print128(k2, (const uint8_t*)"K2"); + + cmac_prepare_last_block(k1, k2); } /******************************************************************************* * @@ -258,21 +244,19 @@ static void cmac_subkey_cont(tSMP_ENC *p) * Returns void * ******************************************************************************/ -static bool cmac_generate_subkey(BT_OCTET16 key) -{ - BT_OCTET16 z = {0}; - bool ret = true; - tSMP_ENC output; - SMP_TRACE_EVENT (" cmac_generate_subkey"); - - if (SMP_Encrypt(key, BT_OCTET16_LEN, z, BT_OCTET16_LEN, &output)) - { - cmac_subkey_cont(&output);; - } - else - ret = false; - - return ret; +static bool cmac_generate_subkey(BT_OCTET16 key) { + BT_OCTET16 z = {0}; + bool ret = true; + tSMP_ENC output; + SMP_TRACE_EVENT(" cmac_generate_subkey"); + + if (SMP_Encrypt(key, BT_OCTET16_LEN, z, BT_OCTET16_LEN, &output)) { + cmac_subkey_cont(&output); + ; + } else + ret = false; + + return ret; } /******************************************************************************* * @@ -292,38 +276,38 @@ static bool cmac_generate_subkey(BT_OCTET16 key) * Returns false if out of resources, true in other cases. * ******************************************************************************/ -bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t length, - uint16_t tlen, uint8_t *p_signature) -{ - uint16_t len, diff; - uint16_t n = (length + BT_OCTET16_LEN - 1) / BT_OCTET16_LEN; /* n is number of rounds */ - bool ret = false; - - SMP_TRACE_EVENT ("%s", __func__); - - if (n == 0) n = 1; - len = n * BT_OCTET16_LEN; - - SMP_TRACE_WARNING("AES128_CMAC started, allocate buffer size = %d", len); - /* allocate a memory space of multiple of 16 bytes to hold text */ - cmac_cb.text = (uint8_t *)osi_calloc(len); - cmac_cb.round = n; - diff = len - length; - - if (input != NULL && length > 0) { - memcpy(&cmac_cb.text[diff] , input, (int)length); - cmac_cb.len = length; - } else { - cmac_cb.len = 0; - } - - /* prepare calculation for subkey s and last block of data */ - if (cmac_generate_subkey(key)) { - /* start calculation */ - ret = cmac_aes_k_calculate(key, p_signature, tlen); - } - /* clean up */ - cmac_aes_cleanup(); - - return ret; +bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t* input, uint16_t length, + uint16_t tlen, uint8_t* p_signature) { + uint16_t len, diff; + uint16_t n = (length + BT_OCTET16_LEN - 1) / + BT_OCTET16_LEN; /* n is number of rounds */ + bool ret = false; + + SMP_TRACE_EVENT("%s", __func__); + + if (n == 0) n = 1; + len = n * BT_OCTET16_LEN; + + SMP_TRACE_WARNING("AES128_CMAC started, allocate buffer size = %d", len); + /* allocate a memory space of multiple of 16 bytes to hold text */ + cmac_cb.text = (uint8_t*)osi_calloc(len); + cmac_cb.round = n; + diff = len - length; + + if (input != NULL && length > 0) { + memcpy(&cmac_cb.text[diff], input, (int)length); + cmac_cb.len = length; + } else { + cmac_cb.len = 0; + } + + /* prepare calculation for subkey s and last block of data */ + if (cmac_generate_subkey(key)) { + /* start calculation */ + ret = cmac_aes_k_calculate(key, p_signature, tlen); + } + /* clean up */ + cmac_aes_cleanup(); + + return ret; } diff --git a/stack/smp/smp_int.h b/stack/smp/smp_int.h index d121af487..0fca16d0f 100644 --- a/stack/smp/smp_int.h +++ b/stack/smp/smp_int.h @@ -21,12 +21,12 @@ * This file contains internally used SMP definitions * ******************************************************************************/ -#ifndef SMP_INT_H -#define SMP_INT_H +#ifndef SMP_INT_H +#define SMP_INT_H -#include "btu.h" -#include "btm_ble_api.h" #include "btm_api.h" +#include "btm_ble_api.h" +#include "btu.h" #include "smp_api.h" #ifdef __cplusplus @@ -34,326 +34,329 @@ extern "C" { #endif /* Legacy mode */ -#define SMP_MODEL_ENCRYPTION_ONLY 0 /* Just Works model */ -#define SMP_MODEL_PASSKEY 1 /* Passkey Entry model, input the key */ -#define SMP_MODEL_OOB 2 /* OOB model */ -#define SMP_MODEL_KEY_NOTIF 3 /* Passkey Entry model, display the key */ +#define SMP_MODEL_ENCRYPTION_ONLY 0 /* Just Works model */ +#define SMP_MODEL_PASSKEY 1 /* Passkey Entry model, input the key */ +#define SMP_MODEL_OOB 2 /* OOB model */ +#define SMP_MODEL_KEY_NOTIF 3 /* Passkey Entry model, display the key */ /* Secure connections mode */ -#define SMP_MODEL_SEC_CONN_JUSTWORKS 4 /* Just Works model */ -#define SMP_MODEL_SEC_CONN_NUM_COMP 5 /* Numeric Comparison model */ -#define SMP_MODEL_SEC_CONN_PASSKEY_ENT 6 /* Passkey Entry model, */ - /* this side inputs the key */ -#define SMP_MODEL_SEC_CONN_PASSKEY_DISP 7 /* Passkey Entry model, */ - /* this side displays the key */ -#define SMP_MODEL_SEC_CONN_OOB 8 /* Secure Connections mode, OOB model */ -#define SMP_MODEL_OUT_OF_RANGE 9 +#define SMP_MODEL_SEC_CONN_JUSTWORKS 4 /* Just Works model */ +#define SMP_MODEL_SEC_CONN_NUM_COMP 5 /* Numeric Comparison model */ +#define SMP_MODEL_SEC_CONN_PASSKEY_ENT 6 /* Passkey Entry model, */ + /* this side inputs the key */ +#define SMP_MODEL_SEC_CONN_PASSKEY_DISP 7 /* Passkey Entry model, */ + /* this side displays the key */ +#define SMP_MODEL_SEC_CONN_OOB 8 /* Secure Connections mode, OOB model */ +#define SMP_MODEL_OUT_OF_RANGE 9 typedef uint8_t tSMP_ASSO_MODEL; - #ifndef SMP_MAX_CONN - #define SMP_MAX_CONN 2 +#define SMP_MAX_CONN 2 #endif -#define SMP_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000) -#define SMP_DELAYED_AUTH_TIMEOUT_MS 500 +#define SMP_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000) +#define SMP_DELAYED_AUTH_TIMEOUT_MS 500 -#define SMP_OPCODE_INIT 0x04 +#define SMP_OPCODE_INIT 0x04 /* SMP events */ -#define SMP_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ -#define SMP_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP -#define SMP_CONFIRM_EVT SMP_OPCODE_CONFIRM -#define SMP_RAND_EVT SMP_OPCODE_RAND -#define SMP_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED -#define SMP_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO -#define SMP_MASTER_ID_EVT SMP_OPCODE_MASTER_ID -#define SMP_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO -#define SMP_ID_ADDR_EVT SMP_OPCODE_ID_ADDR -#define SMP_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO -#define SMP_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ - -#define SMP_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY +#define SMP_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ +#define SMP_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP +#define SMP_CONFIRM_EVT SMP_OPCODE_CONFIRM +#define SMP_RAND_EVT SMP_OPCODE_RAND +#define SMP_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED +#define SMP_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO +#define SMP_MASTER_ID_EVT SMP_OPCODE_MASTER_ID +#define SMP_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO +#define SMP_ID_ADDR_EVT SMP_OPCODE_ID_ADDR +#define SMP_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO +#define SMP_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ + +#define SMP_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY #define SMP_PAIR_KEYPRESS_NOTIFICATION_EVT SMP_OPCODE_PAIR_KEYPR_NOTIF -#define SMP_PAIR_COMMITM_EVT SMP_OPCODE_PAIR_COMMITM +#define SMP_PAIR_COMMITM_EVT SMP_OPCODE_PAIR_COMMITM -#define SMP_SELF_DEF_EVT (SMP_PAIR_COMMITM_EVT + 1) -#define SMP_KEY_READY_EVT (SMP_SELF_DEF_EVT) -#define SMP_ENCRYPTED_EVT (SMP_SELF_DEF_EVT + 1) -#define SMP_L2CAP_CONN_EVT (SMP_SELF_DEF_EVT + 2) -#define SMP_L2CAP_DISCONN_EVT (SMP_SELF_DEF_EVT + 3) -#define SMP_IO_RSP_EVT (SMP_SELF_DEF_EVT + 4) -#define SMP_API_SEC_GRANT_EVT (SMP_SELF_DEF_EVT + 5) -#define SMP_TK_REQ_EVT (SMP_SELF_DEF_EVT + 6) -#define SMP_AUTH_CMPL_EVT (SMP_SELF_DEF_EVT + 7) -#define SMP_ENC_REQ_EVT (SMP_SELF_DEF_EVT + 8) -#define SMP_BOND_REQ_EVT (SMP_SELF_DEF_EVT + 9) -#define SMP_DISCARD_SEC_REQ_EVT (SMP_SELF_DEF_EVT + 10) +#define SMP_SELF_DEF_EVT (SMP_PAIR_COMMITM_EVT + 1) +#define SMP_KEY_READY_EVT (SMP_SELF_DEF_EVT) +#define SMP_ENCRYPTED_EVT (SMP_SELF_DEF_EVT + 1) +#define SMP_L2CAP_CONN_EVT (SMP_SELF_DEF_EVT + 2) +#define SMP_L2CAP_DISCONN_EVT (SMP_SELF_DEF_EVT + 3) +#define SMP_IO_RSP_EVT (SMP_SELF_DEF_EVT + 4) +#define SMP_API_SEC_GRANT_EVT (SMP_SELF_DEF_EVT + 5) +#define SMP_TK_REQ_EVT (SMP_SELF_DEF_EVT + 6) +#define SMP_AUTH_CMPL_EVT (SMP_SELF_DEF_EVT + 7) +#define SMP_ENC_REQ_EVT (SMP_SELF_DEF_EVT + 8) +#define SMP_BOND_REQ_EVT (SMP_SELF_DEF_EVT + 9) +#define SMP_DISCARD_SEC_REQ_EVT (SMP_SELF_DEF_EVT + 10) -#define SMP_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK +#define SMP_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK /* request to start public key exchange */ -#define SMP_PUBL_KEY_EXCH_REQ_EVT (SMP_SELF_DEF_EVT + 11) +#define SMP_PUBL_KEY_EXCH_REQ_EVT (SMP_SELF_DEF_EVT + 11) /* local public key created */ -#define SMP_LOC_PUBL_KEY_CRTD_EVT (SMP_SELF_DEF_EVT + 12) +#define SMP_LOC_PUBL_KEY_CRTD_EVT (SMP_SELF_DEF_EVT + 12) /* both local and peer public keys are saved in cb */ -#define SMP_BOTH_PUBL_KEYS_RCVD_EVT (SMP_SELF_DEF_EVT + 13) +#define SMP_BOTH_PUBL_KEYS_RCVD_EVT (SMP_SELF_DEF_EVT + 13) /* DHKey computation is completed, time to start SC phase1 */ -#define SMP_SC_DHKEY_CMPLT_EVT (SMP_SELF_DEF_EVT + 14) +#define SMP_SC_DHKEY_CMPLT_EVT (SMP_SELF_DEF_EVT + 14) /* new local nonce is generated and saved in p_cb->rand */ -#define SMP_HAVE_LOC_NONCE_EVT (SMP_SELF_DEF_EVT + 15) +#define SMP_HAVE_LOC_NONCE_EVT (SMP_SELF_DEF_EVT + 15) /* time to start SC phase2 */ -#define SMP_SC_PHASE1_CMPLT_EVT (SMP_SELF_DEF_EVT + 16) +#define SMP_SC_PHASE1_CMPLT_EVT (SMP_SELF_DEF_EVT + 16) -/* request to calculate number for user check. Used only in the numeric compare protocol */ -#define SMP_SC_CALC_NC_EVT (SMP_SELF_DEF_EVT + 17) +/* request to calculate number for user check. Used only in the numeric compare + * protocol */ +#define SMP_SC_CALC_NC_EVT (SMP_SELF_DEF_EVT + 17) /* Request to display the number for user check to the user.*/ /* Used only in the numeric compare protocol */ -#define SMP_SC_DSPL_NC_EVT (SMP_SELF_DEF_EVT + 18) +#define SMP_SC_DSPL_NC_EVT (SMP_SELF_DEF_EVT + 18) /* user confirms 'OK' numeric comparison request */ -#define SMP_SC_NC_OK_EVT (SMP_SELF_DEF_EVT + 19) +#define SMP_SC_NC_OK_EVT (SMP_SELF_DEF_EVT + 19) /* both local and peer DHKey Checks are already present - it is used on slave to * prevent a race condition */ -#define SMP_SC_2_DHCK_CHKS_PRES_EVT (SMP_SELF_DEF_EVT + 20) +#define SMP_SC_2_DHCK_CHKS_PRES_EVT (SMP_SELF_DEF_EVT + 20) /* same meaning as SMP_KEY_READY_EVT to separate between SC and legacy actions */ -#define SMP_SC_KEY_READY_EVT (SMP_SELF_DEF_EVT + 21) +#define SMP_SC_KEY_READY_EVT (SMP_SELF_DEF_EVT + 21) #define SMP_KEYPRESS_NOTIFICATION_EVENT (SMP_SELF_DEF_EVT + 22) /* SC OOB data from some repository is provided */ -#define SMP_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 23) +#define SMP_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 23) -#define SMP_CR_LOC_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 24) -#define SMP_MAX_EVT SMP_CR_LOC_SC_OOB_DATA_EVT +#define SMP_CR_LOC_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 24) +#define SMP_MAX_EVT SMP_CR_LOC_SC_OOB_DATA_EVT typedef uint8_t tSMP_EVENT; /* Assumption it's only using the low 8 bits, if bigger than that, need to * expand it to 16 bits */ -#define SMP_SEC_KEY_MASK 0x00ff +#define SMP_SEC_KEY_MASK 0x00ff /* SMP pairing state */ -enum -{ - SMP_STATE_IDLE, - SMP_STATE_WAIT_APP_RSP, - SMP_STATE_SEC_REQ_PENDING, - SMP_STATE_PAIR_REQ_RSP, - SMP_STATE_WAIT_CONFIRM, - SMP_STATE_CONFIRM, - SMP_STATE_RAND, - SMP_STATE_PUBLIC_KEY_EXCH, - SMP_STATE_SEC_CONN_PHS1_START, - SMP_STATE_WAIT_COMMITMENT, - SMP_STATE_WAIT_NONCE, - SMP_STATE_SEC_CONN_PHS2_START, - SMP_STATE_WAIT_DHK_CHECK, - SMP_STATE_DHK_CHECK, - SMP_STATE_ENCRYPTION_PENDING, - SMP_STATE_BOND_PENDING, - SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA, - SMP_STATE_MAX +enum { + SMP_STATE_IDLE, + SMP_STATE_WAIT_APP_RSP, + SMP_STATE_SEC_REQ_PENDING, + SMP_STATE_PAIR_REQ_RSP, + SMP_STATE_WAIT_CONFIRM, + SMP_STATE_CONFIRM, + SMP_STATE_RAND, + SMP_STATE_PUBLIC_KEY_EXCH, + SMP_STATE_SEC_CONN_PHS1_START, + SMP_STATE_WAIT_COMMITMENT, + SMP_STATE_WAIT_NONCE, + SMP_STATE_SEC_CONN_PHS2_START, + SMP_STATE_WAIT_DHK_CHECK, + SMP_STATE_DHK_CHECK, + SMP_STATE_ENCRYPTION_PENDING, + SMP_STATE_BOND_PENDING, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA, + SMP_STATE_MAX }; typedef uint8_t tSMP_STATE; /* SMP over BR/EDR events */ -#define SMP_BR_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ -#define SMP_BR_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP -#define SMP_BR_CONFIRM_EVT SMP_OPCODE_CONFIRM /* not over BR/EDR */ -#define SMP_BR_RAND_EVT SMP_OPCODE_RAND /* not over BR/EDR */ -#define SMP_BR_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED -#define SMP_BR_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO /* not over BR/EDR */ -#define SMP_BR_MASTER_ID_EVT SMP_OPCODE_MASTER_ID /* not over BR/EDR */ -#define SMP_BR_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO -#define SMP_BR_ID_ADDR_EVT SMP_OPCODE_ID_ADDR -#define SMP_BR_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO -#define SMP_BR_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ /* not over BR/EDR */ -#define SMP_BR_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY /* not over BR/EDR */ -#define SMP_BR_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK /* not over BR/EDR */ -#define SMP_BR_PAIR_KEYPR_NOTIF_EVT SMP_OPCODE_PAIR_KEYPR_NOTIF /* not over BR/EDR */ -#define SMP_BR_SELF_DEF_EVT SMP_BR_PAIR_KEYPR_NOTIF_EVT -#define SMP_BR_KEY_READY_EVT (SMP_BR_SELF_DEF_EVT + 1) -#define SMP_BR_ENCRYPTED_EVT (SMP_BR_SELF_DEF_EVT + 2) -#define SMP_BR_L2CAP_CONN_EVT (SMP_BR_SELF_DEF_EVT + 3) -#define SMP_BR_L2CAP_DISCONN_EVT (SMP_BR_SELF_DEF_EVT + 4) -#define SMP_BR_KEYS_RSP_EVT (SMP_BR_SELF_DEF_EVT + 5) -#define SMP_BR_API_SEC_GRANT_EVT (SMP_BR_SELF_DEF_EVT + 6) -#define SMP_BR_TK_REQ_EVT (SMP_BR_SELF_DEF_EVT + 7) -#define SMP_BR_AUTH_CMPL_EVT (SMP_BR_SELF_DEF_EVT + 8) -#define SMP_BR_ENC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 9) -#define SMP_BR_BOND_REQ_EVT (SMP_BR_SELF_DEF_EVT + 10) -#define SMP_BR_DISCARD_SEC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 11) -#define SMP_BR_MAX_EVT (SMP_BR_SELF_DEF_EVT + 12) +#define SMP_BR_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ +#define SMP_BR_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP +#define SMP_BR_CONFIRM_EVT SMP_OPCODE_CONFIRM /* not over BR/EDR */ +#define SMP_BR_RAND_EVT SMP_OPCODE_RAND /* not over BR/EDR */ +#define SMP_BR_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED +#define SMP_BR_ENCRPTION_INFO_EVT \ + SMP_OPCODE_ENCRYPT_INFO /* not over BR/EDR \ + */ +#define SMP_BR_MASTER_ID_EVT SMP_OPCODE_MASTER_ID /* not over BR/EDR */ +#define SMP_BR_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO +#define SMP_BR_ID_ADDR_EVT SMP_OPCODE_ID_ADDR +#define SMP_BR_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO +#define SMP_BR_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ /* not over BR/EDR */ +#define SMP_BR_PAIR_PUBLIC_KEY_EVT \ + SMP_OPCODE_PAIR_PUBLIC_KEY /* not over BR/EDR */ +#define SMP_BR_PAIR_DHKEY_CHCK_EVT \ + SMP_OPCODE_PAIR_DHKEY_CHECK /* not over BR/EDR */ +#define SMP_BR_PAIR_KEYPR_NOTIF_EVT \ + SMP_OPCODE_PAIR_KEYPR_NOTIF /* not over BR/EDR */ +#define SMP_BR_SELF_DEF_EVT SMP_BR_PAIR_KEYPR_NOTIF_EVT +#define SMP_BR_KEY_READY_EVT (SMP_BR_SELF_DEF_EVT + 1) +#define SMP_BR_ENCRYPTED_EVT (SMP_BR_SELF_DEF_EVT + 2) +#define SMP_BR_L2CAP_CONN_EVT (SMP_BR_SELF_DEF_EVT + 3) +#define SMP_BR_L2CAP_DISCONN_EVT (SMP_BR_SELF_DEF_EVT + 4) +#define SMP_BR_KEYS_RSP_EVT (SMP_BR_SELF_DEF_EVT + 5) +#define SMP_BR_API_SEC_GRANT_EVT (SMP_BR_SELF_DEF_EVT + 6) +#define SMP_BR_TK_REQ_EVT (SMP_BR_SELF_DEF_EVT + 7) +#define SMP_BR_AUTH_CMPL_EVT (SMP_BR_SELF_DEF_EVT + 8) +#define SMP_BR_ENC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 9) +#define SMP_BR_BOND_REQ_EVT (SMP_BR_SELF_DEF_EVT + 10) +#define SMP_BR_DISCARD_SEC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 11) +#define SMP_BR_MAX_EVT (SMP_BR_SELF_DEF_EVT + 12) typedef uint8_t tSMP_BR_EVENT; /* SMP over BR/EDR pairing states */ -enum -{ - SMP_BR_STATE_IDLE = SMP_STATE_IDLE, - SMP_BR_STATE_WAIT_APP_RSP, - SMP_BR_STATE_PAIR_REQ_RSP, - SMP_BR_STATE_BOND_PENDING, - SMP_BR_STATE_MAX +enum { + SMP_BR_STATE_IDLE = SMP_STATE_IDLE, + SMP_BR_STATE_WAIT_APP_RSP, + SMP_BR_STATE_PAIR_REQ_RSP, + SMP_BR_STATE_BOND_PENDING, + SMP_BR_STATE_MAX }; typedef uint8_t tSMP_BR_STATE; /* random and encrption activity state */ -enum -{ - SMP_GEN_COMPARE = 1, - SMP_GEN_CONFIRM, - - SMP_GEN_DIV_LTK, - SMP_GEN_DIV_CSRK, - SMP_GEN_RAND_V, - SMP_GEN_TK, - SMP_GEN_SRAND_MRAND, - SMP_GEN_SRAND_MRAND_CONT, - SMP_GENERATE_PRIVATE_KEY_0_7, - SMP_GENERATE_PRIVATE_KEY_8_15, - SMP_GENERATE_PRIVATE_KEY_16_23, - SMP_GENERATE_PRIVATE_KEY_24_31, - SMP_GEN_NONCE_0_7, - SMP_GEN_NONCE_8_15 +enum { + SMP_GEN_COMPARE = 1, + SMP_GEN_CONFIRM, + + SMP_GEN_DIV_LTK, + SMP_GEN_DIV_CSRK, + SMP_GEN_RAND_V, + SMP_GEN_TK, + SMP_GEN_SRAND_MRAND, + SMP_GEN_SRAND_MRAND_CONT, + SMP_GENERATE_PRIVATE_KEY_0_7, + SMP_GENERATE_PRIVATE_KEY_8_15, + SMP_GENERATE_PRIVATE_KEY_16_23, + SMP_GENERATE_PRIVATE_KEY_24_31, + SMP_GEN_NONCE_0_7, + SMP_GEN_NONCE_8_15 }; -enum -{ - SMP_KEY_TYPE_TK, - SMP_KEY_TYPE_CFM, - SMP_KEY_TYPE_CMP, - SMP_KEY_TYPE_PEER_DHK_CHCK, - SMP_KEY_TYPE_STK, - SMP_KEY_TYPE_LTK +enum { + SMP_KEY_TYPE_TK, + SMP_KEY_TYPE_CFM, + SMP_KEY_TYPE_CMP, + SMP_KEY_TYPE_PEER_DHK_CHCK, + SMP_KEY_TYPE_STK, + SMP_KEY_TYPE_LTK }; -typedef struct -{ - uint8_t key_type; - uint8_t* p_data; -}tSMP_KEY; - -typedef union -{ - uint8_t *p_data; /* uint8_t type data pointer */ - tSMP_KEY key; - uint16_t reason; - uint32_t passkey; - tSMP_OOB_DATA_TYPE req_oob_type; -}tSMP_INT_DATA; +typedef struct { + uint8_t key_type; + uint8_t* p_data; +} tSMP_KEY; + +typedef union { + uint8_t* p_data; /* uint8_t type data pointer */ + tSMP_KEY key; + uint16_t reason; + uint32_t passkey; + tSMP_OOB_DATA_TYPE req_oob_type; +} tSMP_INT_DATA; /* internal status mask */ -#define SMP_PAIR_FLAGS_WE_STARTED_DD (1) -#define SMP_PAIR_FLAGS_PEER_STARTED_DD (1 << 1) -#define SMP_PAIR_FLAGS_CMD_CONFIRM (1 << SMP_OPCODE_CONFIRM) /* 1 << 3 */ -#define SMP_PAIR_FLAG_ENC_AFTER_PAIR (1 << 4) -#define SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK (1 << 5) /* used on slave to resolve race condition */ -#define SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY (1 << 6) /* used on slave to resolve race condition */ -#define SMP_PAIR_FLAG_HAVE_PEER_COMM (1 << 7) /* used to resolve race condition */ -#define SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY (1 << 8) /* used on slave to resolve race condition */ +#define SMP_PAIR_FLAGS_WE_STARTED_DD (1) +#define SMP_PAIR_FLAGS_PEER_STARTED_DD (1 << 1) +#define SMP_PAIR_FLAGS_CMD_CONFIRM (1 << SMP_OPCODE_CONFIRM) /* 1 << 3 */ +#define SMP_PAIR_FLAG_ENC_AFTER_PAIR (1 << 4) +#define SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK \ + (1 << 5) /* used on slave to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY \ + (1 << 6) /* used on slave to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_PEER_COMM \ + (1 << 7) /* used to resolve race condition */ +#define SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY \ + (1 << 8) /* used on slave to resolve race condition */ /* check if authentication requirement need MITM protection */ -#define SMP_NO_MITM_REQUIRED(x) (((x) & SMP_AUTH_YN_BIT) == 0) +#define SMP_NO_MITM_REQUIRED(x) (((x)&SMP_AUTH_YN_BIT) == 0) -#define SMP_ENCRYT_KEY_SIZE 16 -#define SMP_ENCRYT_DATA_SIZE 16 -#define SMP_ECNCRPYT_STATUS HCI_SUCCESS +#define SMP_ENCRYT_KEY_SIZE 16 +#define SMP_ENCRYT_DATA_SIZE 16 +#define SMP_ECNCRPYT_STATUS HCI_SUCCESS -typedef struct -{ - BD_ADDR bd_addr; - BT_HDR* p_copy; +typedef struct { + BD_ADDR bd_addr; + BT_HDR* p_copy; } tSMP_REQ_Q_ENTRY; /* SMP control block */ -typedef struct -{ - tSMP_CALLBACK *p_callback; - alarm_t *smp_rsp_timer_ent; - uint8_t trace_level; - BD_ADDR pairing_bda; - tSMP_STATE state; - bool derive_lk; - bool id_addr_rcvd; - tBLE_ADDR_TYPE id_addr_type; - BD_ADDR id_addr; - bool smp_over_br; - tSMP_BR_STATE br_state; /* if SMP over BR/ERD has priority over SMP */ - uint8_t failure; - uint8_t status; - uint8_t role; - uint16_t flags; - uint8_t cb_evt; - tSMP_SEC_LEVEL sec_level; - bool connect_initialized; - BT_OCTET16 confirm; - BT_OCTET16 rconfirm; - BT_OCTET16 rrand; /* for SC this is peer nonce */ - BT_OCTET16 rand; /* for SC this is local nonce */ - BT_OCTET32 private_key; - BT_OCTET32 dhkey; - BT_OCTET16 commitment; - BT_OCTET16 remote_commitment; - BT_OCTET16 local_random; /* local randomizer - passkey or OOB randomizer */ - BT_OCTET16 peer_random; /* peer randomizer - passkey or OOB randomizer */ - BT_OCTET16 dhkey_check; - BT_OCTET16 remote_dhkey_check; - tSMP_PUBLIC_KEY loc_publ_key; - tSMP_PUBLIC_KEY peer_publ_key; - tSMP_OOB_DATA_TYPE req_oob_type; - tSMP_SC_OOB_DATA sc_oob_data; - tSMP_IO_CAP peer_io_caps; - tSMP_IO_CAP local_io_capability; - tSMP_OOB_FLAG peer_oob_flag; - tSMP_OOB_FLAG loc_oob_flag; - tSMP_AUTH_REQ peer_auth_req; - tSMP_AUTH_REQ loc_auth_req; - bool secure_connections_only_mode_required;/* true if locally SM is required to operate */ - /* either in Secure Connections mode or not at all */ - tSMP_ASSO_MODEL selected_association_model; - bool le_secure_connections_mode_is_used; - bool le_sc_kp_notif_is_used; - tSMP_SC_KEY_TYPE local_keypress_notification; - tSMP_SC_KEY_TYPE peer_keypress_notification; - uint8_t round; /* authentication stage 1 round for passkey association model */ - uint32_t number_to_display; - BT_OCTET16 mac_key; - uint8_t peer_enc_size; - uint8_t loc_enc_size; - uint8_t peer_i_key; - uint8_t peer_r_key; - uint8_t local_i_key; - uint8_t local_r_key; - - BT_OCTET16 tk; - BT_OCTET16 ltk; - uint16_t div; - BT_OCTET16 csrk; /* storage for local CSRK */ - uint16_t ediv; - BT_OCTET8 enc_rand; - uint8_t rand_enc_proc_state; - uint8_t addr_type; - BD_ADDR local_bda; - bool is_pair_cancel; - bool discard_sec_req; - uint8_t rcvd_cmd_code; - uint8_t rcvd_cmd_len; - uint16_t total_tx_unacked; - bool wait_for_authorization_complete; - uint8_t cert_failure; /*failure case for certification */ - alarm_t *delayed_auth_timer_ent; -}tSMP_CB; +typedef struct { + tSMP_CALLBACK* p_callback; + alarm_t* smp_rsp_timer_ent; + uint8_t trace_level; + BD_ADDR pairing_bda; + tSMP_STATE state; + bool derive_lk; + bool id_addr_rcvd; + tBLE_ADDR_TYPE id_addr_type; + BD_ADDR id_addr; + bool smp_over_br; + tSMP_BR_STATE br_state; /* if SMP over BR/ERD has priority over SMP */ + uint8_t failure; + uint8_t status; + uint8_t role; + uint16_t flags; + uint8_t cb_evt; + tSMP_SEC_LEVEL sec_level; + bool connect_initialized; + BT_OCTET16 confirm; + BT_OCTET16 rconfirm; + BT_OCTET16 rrand; /* for SC this is peer nonce */ + BT_OCTET16 rand; /* for SC this is local nonce */ + BT_OCTET32 private_key; + BT_OCTET32 dhkey; + BT_OCTET16 commitment; + BT_OCTET16 remote_commitment; + BT_OCTET16 local_random; /* local randomizer - passkey or OOB randomizer */ + BT_OCTET16 peer_random; /* peer randomizer - passkey or OOB randomizer */ + BT_OCTET16 dhkey_check; + BT_OCTET16 remote_dhkey_check; + tSMP_PUBLIC_KEY loc_publ_key; + tSMP_PUBLIC_KEY peer_publ_key; + tSMP_OOB_DATA_TYPE req_oob_type; + tSMP_SC_OOB_DATA sc_oob_data; + tSMP_IO_CAP peer_io_caps; + tSMP_IO_CAP local_io_capability; + tSMP_OOB_FLAG peer_oob_flag; + tSMP_OOB_FLAG loc_oob_flag; + tSMP_AUTH_REQ peer_auth_req; + tSMP_AUTH_REQ loc_auth_req; + bool secure_connections_only_mode_required; /* true if locally SM is required + to operate */ + /* either in Secure Connections mode or not at all */ + tSMP_ASSO_MODEL selected_association_model; + bool le_secure_connections_mode_is_used; + bool le_sc_kp_notif_is_used; + tSMP_SC_KEY_TYPE local_keypress_notification; + tSMP_SC_KEY_TYPE peer_keypress_notification; + uint8_t + round; /* authentication stage 1 round for passkey association model */ + uint32_t number_to_display; + BT_OCTET16 mac_key; + uint8_t peer_enc_size; + uint8_t loc_enc_size; + uint8_t peer_i_key; + uint8_t peer_r_key; + uint8_t local_i_key; + uint8_t local_r_key; + + BT_OCTET16 tk; + BT_OCTET16 ltk; + uint16_t div; + BT_OCTET16 csrk; /* storage for local CSRK */ + uint16_t ediv; + BT_OCTET8 enc_rand; + uint8_t rand_enc_proc_state; + uint8_t addr_type; + BD_ADDR local_bda; + bool is_pair_cancel; + bool discard_sec_req; + uint8_t rcvd_cmd_code; + uint8_t rcvd_cmd_len; + uint16_t total_tx_unacked; + bool wait_for_authorization_complete; + uint8_t cert_failure; /*failure case for certification */ + alarm_t* delayed_auth_timer_ent; +} tSMP_CB; /* Server Action functions are of this type */ -typedef void (*tSMP_ACT)(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +typedef void (*tSMP_ACT)(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); extern tSMP_CB smp_cb; @@ -362,181 +365,207 @@ extern tSMP_CB smp_cb; #endif /* Functions provided by att_main.cc */ -extern void smp_init (void); +extern void smp_init(void); /* smp main */ -extern void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data); - -extern void smp_proc_sec_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_set_fail_nc (bool enable); -extern void smp_set_fail_conf (bool enable); -extern void smp_set_passk_entry_fail(bool enable); -extern void smp_set_oob_fail(bool enable); -extern void smp_set_peer_sc_notif(bool enable); -extern void smp_aes_cmac_rfc4493_chk (uint8_t *key, uint8_t *msg, uint8_t msg_len, - uint8_t mac_len, uint8_t *mac); -extern void smp_f4_calc_chk (uint8_t *U, uint8_t *V, uint8_t *X, uint8_t *Z, uint8_t *mac); -extern void smp_g2_calc_chk (uint8_t *U, uint8_t *V, uint8_t *X, uint8_t *Y); -extern void smp_h6_calc_chk (uint8_t *key, uint8_t *key_id, uint8_t *mac); -extern void smp_f5_key_calc_chk (uint8_t *w, uint8_t *mac); -extern void smp_f5_mackey_or_ltk_calc_chk(uint8_t *t, uint8_t *counter, - uint8_t *key_id, uint8_t *n1, - uint8_t *n2, uint8_t *a1, uint8_t *a2, - uint8_t *length, uint8_t *mac); -extern void smp_f5_calc_chk (uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *a1, uint8_t *a2, - uint8_t *mac_key, uint8_t *ltk); -extern void smp_f6_calc_chk (uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r, - uint8_t *iocap, uint8_t *a1, uint8_t *a2, uint8_t *mac); +extern void smp_sm_event(tSMP_CB* p_cb, tSMP_EVENT event, void* p_data); + +extern void smp_proc_sec_request(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_set_fail_nc(bool enable); +extern void smp_set_fail_conf(bool enable); +extern void smp_set_passk_entry_fail(bool enable); +extern void smp_set_oob_fail(bool enable); +extern void smp_set_peer_sc_notif(bool enable); +extern void smp_aes_cmac_rfc4493_chk(uint8_t* key, uint8_t* msg, + uint8_t msg_len, uint8_t mac_len, + uint8_t* mac); +extern void smp_f4_calc_chk(uint8_t* U, uint8_t* V, uint8_t* X, uint8_t* Z, + uint8_t* mac); +extern void smp_g2_calc_chk(uint8_t* U, uint8_t* V, uint8_t* X, uint8_t* Y); +extern void smp_h6_calc_chk(uint8_t* key, uint8_t* key_id, uint8_t* mac); +extern void smp_f5_key_calc_chk(uint8_t* w, uint8_t* mac); +extern void smp_f5_mackey_or_ltk_calc_chk(uint8_t* t, uint8_t* counter, + uint8_t* key_id, uint8_t* n1, + uint8_t* n2, uint8_t* a1, uint8_t* a2, + uint8_t* length, uint8_t* mac); +extern void smp_f5_calc_chk(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* a1, + uint8_t* a2, uint8_t* mac_key, uint8_t* ltk); +extern void smp_f6_calc_chk(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* r, + uint8_t* iocap, uint8_t* a1, uint8_t* a2, + uint8_t* mac); /* smp_main */ -extern void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data); -extern tSMP_STATE smp_get_state(void); -extern void smp_set_state(tSMP_STATE state); +extern void smp_sm_event(tSMP_CB* p_cb, tSMP_EVENT event, void* p_data); +extern tSMP_STATE smp_get_state(void); +extern void smp_set_state(tSMP_STATE state); /* smp_br_main */ -extern void smp_br_state_machine_event(tSMP_CB *p_cb, tSMP_BR_EVENT event, void *p_data); -extern tSMP_BR_STATE smp_get_br_state(void); -extern void smp_set_br_state(tSMP_BR_STATE state); - +extern void smp_br_state_machine_event(tSMP_CB* p_cb, tSMP_BR_EVENT event, + void* p_data); +extern tSMP_BR_STATE smp_get_br_state(void); +extern void smp_set_br_state(tSMP_BR_STATE state); /* smp_act.cc */ -extern void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_pair_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_pairing_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_sl_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_decide_association_model(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_ltk_reply(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_both_have_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_start_secure_connection_phase1(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_local_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_pairing_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_move_to_secure_connections_phase2(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_phase_2_dhkey_checks_are_present(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_wait_for_both_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_start_passkey_verification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_process_secure_connection_oob_data(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_send_pair_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_pair_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_keypress_notification(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_proc_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_process_pairing_public_key(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_proc_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_master_id(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_id_addr(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_sec_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_sec_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_sl_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_start_enc(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_enc_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_discard(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_pairing_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_decide_association_model(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_app_cback(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_check_auth_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_process_io_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_csrk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_ltk_reply(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_pair_cmd(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_pair_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_idle_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_send_pair_rsp(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_key_distribution(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_proc_srk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_generate_csrk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_fast_conn_param(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_key_pick_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_both_have_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_start_secure_connection_phase1(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_process_local_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_process_pairing_commitment(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_process_peer_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_process_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_match_dhkey_checks(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_process_keypress_notification(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_move_to_secure_connections_phase2(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_phase_2_dhkey_checks_are_present(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_wait_for_both_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_start_passkey_verification(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_process_secure_connection_oob_data(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); extern void smp_process_secure_connection_long_term_key(void); -extern void smp_set_local_oob_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_set_local_oob_random_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_set_derive_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_process_security_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_process_slave_keys_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_send_pair_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_check_authorization_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_select_next_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_br_pairing_complete(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); +extern void smp_set_local_oob_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_set_local_oob_random_commitment(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_set_derive_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_derive_link_key_from_long_term_key(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_br_process_pairing_command(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_br_process_security_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_br_process_slave_keys_response(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_br_send_pair_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_br_check_authorization_request(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_br_select_next_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_br_process_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_key_distribution_by_transport(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_br_pairing_complete(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); /* smp_l2c */ -extern void smp_l2cap_if_init (void); -extern void smp_data_ind (BD_ADDR bd_addr, BT_HDR *p_buf); +extern void smp_l2cap_if_init(void); +extern void smp_data_ind(BD_ADDR bd_addr, BT_HDR* p_buf); /* smp_util.cc */ -extern bool smp_send_cmd(uint8_t cmd_code, tSMP_CB *p_cb); -extern void smp_cb_cleanup(tSMP_CB *p_cb); -extern void smp_reset_control_value(tSMP_CB *p_cb); -extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb); +extern bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb); +extern void smp_cb_cleanup(tSMP_CB* p_cb); +extern void smp_reset_control_value(tSMP_CB* p_cb); +extern void smp_proc_pairing_cmpl(tSMP_CB* p_cb); extern void smp_convert_string_to_tk(BT_OCTET16 tk, uint32_t passkey); -extern void smp_mask_enc_key(uint8_t loc_enc_size, uint8_t * p_data); -extern void smp_rsp_timeout(void *data); -extern void smp_delayed_auth_complete_timeout(void *data); +extern void smp_mask_enc_key(uint8_t loc_enc_size, uint8_t* p_data); +extern void smp_rsp_timeout(void* data); +extern void smp_delayed_auth_complete_timeout(void* data); extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b); -extern bool smp_encrypt_data (uint8_t *key, uint8_t key_len, - uint8_t *plain_text, uint8_t pt_len, - tSMP_ENC *p_out); -extern bool smp_command_has_invalid_parameters(tSMP_CB *p_cb); +extern bool smp_encrypt_data(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, tSMP_ENC* p_out); +extern bool smp_command_has_invalid_parameters(tSMP_CB* p_cb); extern void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr); -extern tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB *p_cb); -extern void smp_reverse_array(uint8_t *arr, uint8_t len); -extern uint8_t smp_calculate_random_input(uint8_t *random, uint8_t round); -extern void smp_collect_local_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb); -extern void smp_collect_peer_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb); -extern void smp_collect_local_ble_address(uint8_t *le_addr, tSMP_CB *p_cb); -extern void smp_collect_peer_ble_address(uint8_t *le_addr, tSMP_CB *p_cb); -extern bool smp_check_commitment(tSMP_CB *p_cb); -extern void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb); -extern bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB *p_cb); -extern void smp_remove_fixed_channel(tSMP_CB *p_cb); -extern bool smp_request_oob_data(tSMP_CB *p_cb); +extern tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB* p_cb); +extern void smp_reverse_array(uint8_t* arr, uint8_t len); +extern uint8_t smp_calculate_random_input(uint8_t* random, uint8_t round); +extern void smp_collect_local_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb); +extern void smp_collect_peer_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb); +extern void smp_collect_local_ble_address(uint8_t* le_addr, tSMP_CB* p_cb); +extern void smp_collect_peer_ble_address(uint8_t* le_addr, tSMP_CB* p_cb); +extern bool smp_check_commitment(tSMP_CB* p_cb); +extern void smp_save_secure_connections_long_term_key(tSMP_CB* p_cb); +extern bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB* p_cb); +extern void smp_remove_fixed_channel(tSMP_CB* p_cb); +extern bool smp_request_oob_data(tSMP_CB* p_cb); /* smp_keys.cc */ -extern void smp_generate_srand_mrand_confirm (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_compare (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_stk (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_ltk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_passkey (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_generate_rand_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_create_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_use_oob_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_compute_dhkey(tSMP_CB *p_cb); -extern void smp_calculate_local_commitment(tSMP_CB *p_cb); -extern void smp_calculate_peer_commitment(tSMP_CB *p_cb, BT_OCTET16 output_buf); -extern void smp_calculate_numeric_comparison_display_number(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_calculate_local_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_calculate_peer_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -extern void smp_start_nonce_generation(tSMP_CB *p_cb); -extern bool smp_calculate_link_key_from_long_term_key(tSMP_CB *p_cb); -extern bool smp_calculate_long_term_key_from_link_key(tSMP_CB *p_cb); -extern void smp_calculate_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z, uint8_t *c); -extern uint32_t smp_calculate_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y); -extern bool smp_calculate_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *a1, uint8_t *a2, - uint8_t *mac_key, uint8_t *ltk); -extern bool smp_calculate_f5_mackey_or_long_term_key(uint8_t *t, uint8_t *counter, - uint8_t *key_id, uint8_t *n1, uint8_t *n2, uint8_t *a1, - uint8_t *a2, uint8_t *length, uint8_t *mac); -extern bool smp_calculate_f5_key(uint8_t *w, uint8_t *t); -extern bool smp_calculate_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r, uint8_t *iocap, - uint8_t *a1, uint8_t *a2, uint8_t *f3); -extern bool smp_calculate_h6(uint8_t *w, uint8_t *keyid, uint8_t *h2); +extern void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_generate_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_generate_stk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_generate_ltk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_generate_passkey(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_generate_rand_cont(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_use_oob_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_compute_dhkey(tSMP_CB* p_cb); +extern void smp_calculate_local_commitment(tSMP_CB* p_cb); +extern void smp_calculate_peer_commitment(tSMP_CB* p_cb, BT_OCTET16 output_buf); +extern void smp_calculate_numeric_comparison_display_number( + tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +extern void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data); +extern void smp_start_nonce_generation(tSMP_CB* p_cb); +extern bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb); +extern bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb); +extern void smp_calculate_f4(uint8_t* u, uint8_t* v, uint8_t* x, uint8_t z, + uint8_t* c); +extern uint32_t smp_calculate_g2(uint8_t* u, uint8_t* v, uint8_t* x, + uint8_t* y); +extern bool smp_calculate_f5(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* a1, + uint8_t* a2, uint8_t* mac_key, uint8_t* ltk); +extern bool smp_calculate_f5_mackey_or_long_term_key( + uint8_t* t, uint8_t* counter, uint8_t* key_id, uint8_t* n1, uint8_t* n2, + uint8_t* a1, uint8_t* a2, uint8_t* length, uint8_t* mac); +extern bool smp_calculate_f5_key(uint8_t* w, uint8_t* t); +extern bool smp_calculate_f6(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* r, + uint8_t* iocap, uint8_t* a1, uint8_t* a2, + uint8_t* f3); +extern bool smp_calculate_h6(uint8_t* w, uint8_t* keyid, uint8_t* h2); #if (SMP_DEBUG == TRUE) -extern void smp_debug_print_nbyte_little_endian (uint8_t *p, const uint8_t *key_name, - uint8_t len); +extern void smp_debug_print_nbyte_little_endian(uint8_t* p, + const uint8_t* key_name, + uint8_t len); #endif /* smp_cmac.cc */ -extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t *input, uint16_t length, - uint16_t tlen, uint8_t *p_signature); -extern void print128(BT_OCTET16 x, const uint8_t *key_name); +extern bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t* input, + uint16_t length, uint16_t tlen, + uint8_t* p_signature); +extern void print128(BT_OCTET16 x, const uint8_t* key_name); #endif /* SMP_INT_H */ diff --git a/stack/smp/smp_keys.cc b/stack/smp/smp_keys.cc index 16f738327..ae1153e58 100644 --- a/stack/smp/smp_keys.cc +++ b/stack/smp/smp_keys.cc @@ -24,87 +24,86 @@ #include "bt_target.h" #if (SMP_DEBUG == TRUE) - #include +#include #endif #include +#include "aes.h" #include "bt_utils.h" #include "btm_ble_api.h" -#include "smp_int.h" -#include "btm_int.h" #include "btm_ble_int.h" -#include "hcimsgs.h" -#include "aes.h" -#include "p_256_ecc_pp.h" +#include "btm_int.h" #include "device/include/controller.h" +#include "hcimsgs.h" #include "osi/include/osi.h" +#include "p_256_ecc_pp.h" +#include "smp_int.h" #ifndef SMP_MAX_ENC_REPEAT - #define SMP_MAX_ENC_REPEAT 3 +#define SMP_MAX_ENC_REPEAT 3 #endif -static void smp_rand_back(tBTM_RAND_ENC *p); -static void smp_generate_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -static void smp_generate_ltk_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); -static void smp_generate_y(tSMP_CB *p_cb, tSMP_INT_DATA *p); -static void smp_generate_rand_vector (tSMP_CB *p_cb, tSMP_INT_DATA *p); -static void smp_process_stk(tSMP_CB *p_cb, tSMP_ENC *p); -static void smp_calculate_comfirm_cont(tSMP_CB *p_cb, tSMP_ENC *p); -static void smp_process_confirm(tSMP_CB *p_cb, tSMP_ENC *p); -static void smp_process_compare(tSMP_CB *p_cb, tSMP_ENC *p); -static void smp_process_ediv(tSMP_CB *p_cb, tSMP_ENC *p); -static bool smp_calculate_legacy_short_term_key(tSMP_CB *p_cb, tSMP_ENC *output); -static void smp_continue_private_key_creation(tSMP_CB *p_cb, tBTM_RAND_ENC *p); -static void smp_process_private_key(tSMP_CB *p_cb); -static void smp_finish_nonce_generation(tSMP_CB *p_cb); -static void smp_process_new_nonce(tSMP_CB *p_cb); - -#define SMP_PASSKEY_MASK 0xfff00000 - -void smp_debug_print_nbyte_little_endian(uint8_t *p, const uint8_t *key_name, uint8_t len) -{ +static void smp_rand_back(tBTM_RAND_ENC* p); +static void smp_generate_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +static void smp_generate_ltk_cont(tSMP_CB* p_cb, tSMP_INT_DATA* p_data); +static void smp_generate_y(tSMP_CB* p_cb, tSMP_INT_DATA* p); +static void smp_generate_rand_vector(tSMP_CB* p_cb, tSMP_INT_DATA* p); +static void smp_process_stk(tSMP_CB* p_cb, tSMP_ENC* p); +static void smp_calculate_comfirm_cont(tSMP_CB* p_cb, tSMP_ENC* p); +static void smp_process_confirm(tSMP_CB* p_cb, tSMP_ENC* p); +static void smp_process_compare(tSMP_CB* p_cb, tSMP_ENC* p); +static void smp_process_ediv(tSMP_CB* p_cb, tSMP_ENC* p); +static bool smp_calculate_legacy_short_term_key(tSMP_CB* p_cb, + tSMP_ENC* output); +static void smp_continue_private_key_creation(tSMP_CB* p_cb, tBTM_RAND_ENC* p); +static void smp_process_private_key(tSMP_CB* p_cb); +static void smp_finish_nonce_generation(tSMP_CB* p_cb); +static void smp_process_new_nonce(tSMP_CB* p_cb); + +#define SMP_PASSKEY_MASK 0xfff00000 + +void smp_debug_print_nbyte_little_endian(uint8_t* p, const uint8_t* key_name, + uint8_t len) { #if (SMP_DEBUG == TRUE) - int ind; - int col_count = 32; - int row_count; - uint8_t p_buf[512]; - - SMP_TRACE_WARNING("%s(LSB ~ MSB):", key_name); - memset(p_buf, 0, sizeof(p_buf)); - row_count = len % col_count ? len / col_count + 1: len / col_count; - - ind = 0; - for (int row = 0; row < row_count; row++) - { - for (int column = 0, x = 0; (ind < len) && (column < col_count); column++, ind++) - { - x += snprintf((char *)&p_buf[x], sizeof(p_buf) - x, "%02x ", p[ind]); - } - SMP_TRACE_WARNING(" [%03d]: %s", row * col_count, p_buf); - } + int ind; + int col_count = 32; + int row_count; + uint8_t p_buf[512]; + + SMP_TRACE_WARNING("%s(LSB ~ MSB):", key_name); + memset(p_buf, 0, sizeof(p_buf)); + row_count = len % col_count ? len / col_count + 1 : len / col_count; + + ind = 0; + for (int row = 0; row < row_count; row++) { + for (int column = 0, x = 0; (ind < len) && (column < col_count); + column++, ind++) { + x += snprintf((char*)&p_buf[x], sizeof(p_buf) - x, "%02x ", p[ind]); + } + SMP_TRACE_WARNING(" [%03d]: %s", row * col_count, p_buf); + } #endif } -void smp_debug_print_nbyte_big_endian (uint8_t *p, const uint8_t *key_name, uint8_t len) -{ +void smp_debug_print_nbyte_big_endian(uint8_t* p, const uint8_t* key_name, + uint8_t len) { #if (SMP_DEBUG == TRUE) - uint8_t p_buf[512]; - - SMP_TRACE_WARNING("%s(MSB ~ LSB):", key_name); - memset(p_buf, 0, sizeof(p_buf)); - - int ind = 0; - int ncols = 32; /* num entries in one line */ - int nrows; /* num lines */ - - nrows = len % ncols ? len / ncols + 1: len / ncols; - for (int row = 0; row < nrows; row++) - { - for (int col = 0, x = 0; (ind < len) && (col < ncols); col++, ind++) - { - x += snprintf ((char *)&p_buf[len-x-1], sizeof(p_buf) - (len-x-1), "%02x ", p[ind]); - } - SMP_TRACE_WARNING("[%03d]: %s", row * ncols, p_buf); + uint8_t p_buf[512]; + + SMP_TRACE_WARNING("%s(MSB ~ LSB):", key_name); + memset(p_buf, 0, sizeof(p_buf)); + + int ind = 0; + int ncols = 32; /* num entries in one line */ + int nrows; /* num lines */ + + nrows = len % ncols ? len / ncols + 1 : len / ncols; + for (int row = 0; row < nrows; row++) { + for (int col = 0, x = 0; (ind < len) && (col < ncols); col++, ind++) { + x += snprintf((char*)&p_buf[len - x - 1], sizeof(p_buf) - (len - x - 1), + "%02x ", p[ind]); } + SMP_TRACE_WARNING("[%03d]: %s", row * ncols, p_buf); + } #endif } @@ -119,57 +118,57 @@ void smp_debug_print_nbyte_big_endian (uint8_t *p, const uint8_t *key_name, uint * Returns void * ******************************************************************************/ -bool smp_encrypt_data (uint8_t *key, uint8_t key_len, - uint8_t *plain_text, uint8_t pt_len, - tSMP_ENC *p_out) -{ - aes_context ctx; - uint8_t *p_start = NULL; - uint8_t *p = NULL; - uint8_t *p_rev_data = NULL; /* input data in big endilan format */ - uint8_t *p_rev_key = NULL; /* input key in big endilan format */ - uint8_t *p_rev_output = NULL; /* encrypted output in big endilan format */ - - SMP_TRACE_DEBUG ("%s", __func__); - if ( (p_out == NULL ) || (key_len != SMP_ENCRYT_KEY_SIZE) ) - { - SMP_TRACE_ERROR ("%s failed", __func__); - return false; - } - - p_start = (uint8_t *)osi_calloc(SMP_ENCRYT_DATA_SIZE * 4); - - if (pt_len > SMP_ENCRYT_DATA_SIZE) - pt_len = SMP_ENCRYT_DATA_SIZE; - - p = p_start; - ARRAY_TO_STREAM (p, plain_text, pt_len); /* byte 0 to byte 15 */ - p_rev_data = p = p_start + SMP_ENCRYT_DATA_SIZE; /* start at byte 16 */ - REVERSE_ARRAY_TO_STREAM (p, p_start, SMP_ENCRYT_DATA_SIZE); /* byte 16 to byte 31 */ - p_rev_key = p; /* start at byte 32 */ - REVERSE_ARRAY_TO_STREAM (p, key, SMP_ENCRYT_KEY_SIZE); /* byte 32 to byte 47 */ +bool smp_encrypt_data(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, tSMP_ENC* p_out) { + aes_context ctx; + uint8_t* p_start = NULL; + uint8_t* p = NULL; + uint8_t* p_rev_data = NULL; /* input data in big endilan format */ + uint8_t* p_rev_key = NULL; /* input key in big endilan format */ + uint8_t* p_rev_output = NULL; /* encrypted output in big endilan format */ + + SMP_TRACE_DEBUG("%s", __func__); + if ((p_out == NULL) || (key_len != SMP_ENCRYT_KEY_SIZE)) { + SMP_TRACE_ERROR("%s failed", __func__); + return false; + } + + p_start = (uint8_t*)osi_calloc(SMP_ENCRYT_DATA_SIZE * 4); + + if (pt_len > SMP_ENCRYT_DATA_SIZE) pt_len = SMP_ENCRYT_DATA_SIZE; + + p = p_start; + ARRAY_TO_STREAM(p, plain_text, pt_len); /* byte 0 to byte 15 */ + p_rev_data = p = p_start + SMP_ENCRYT_DATA_SIZE; /* start at byte 16 */ + REVERSE_ARRAY_TO_STREAM(p, p_start, + SMP_ENCRYT_DATA_SIZE); /* byte 16 to byte 31 */ + p_rev_key = p; /* start at byte 32 */ + REVERSE_ARRAY_TO_STREAM(p, key, SMP_ENCRYT_KEY_SIZE); /* byte 32 to byte 47 */ #if (SMP_DEBUG == TRUE && SMP_DEBUG_VERBOSE == TRUE) - smp_debug_print_nbyte_little_endian(key, (const uint8_t *)"Key", SMP_ENCRYT_KEY_SIZE); - smp_debug_print_nbyte_little_endian(p_start, (const uint8_t *)"Plain text", SMP_ENCRYT_DATA_SIZE); + smp_debug_print_nbyte_little_endian(key, (const uint8_t*)"Key", + SMP_ENCRYT_KEY_SIZE); + smp_debug_print_nbyte_little_endian(p_start, (const uint8_t*)"Plain text", + SMP_ENCRYT_DATA_SIZE); #endif - p_rev_output = p; - aes_set_key(p_rev_key, SMP_ENCRYT_KEY_SIZE, &ctx); - aes_encrypt(p_rev_data, p, &ctx); /* outputs in byte 48 to byte 63 */ + p_rev_output = p; + aes_set_key(p_rev_key, SMP_ENCRYT_KEY_SIZE, &ctx); + aes_encrypt(p_rev_data, p, &ctx); /* outputs in byte 48 to byte 63 */ - p = p_out->param_buf; - REVERSE_ARRAY_TO_STREAM (p, p_rev_output, SMP_ENCRYT_DATA_SIZE); + p = p_out->param_buf; + REVERSE_ARRAY_TO_STREAM(p, p_rev_output, SMP_ENCRYT_DATA_SIZE); #if (SMP_DEBUG == TRUE && SMP_DEBUG_VERBOSE == TRUE) - smp_debug_print_nbyte_little_endian(p_out->param_buf, (const uint8_t *)"Encrypted text", SMP_ENCRYT_KEY_SIZE); + smp_debug_print_nbyte_little_endian( + p_out->param_buf, (const uint8_t*)"Encrypted text", SMP_ENCRYT_KEY_SIZE); #endif - p_out->param_len = SMP_ENCRYT_KEY_SIZE; - p_out->status = HCI_SUCCESS; - p_out->opcode = HCI_BLE_ENCRYPT; + p_out->param_len = SMP_ENCRYT_KEY_SIZE; + p_out->status = HCI_SUCCESS; + p_out->opcode = HCI_BLE_ENCRYPT; - osi_free(p_start); + osi_free(p_start); - return true; + return true; } /******************************************************************************* @@ -181,14 +180,12 @@ bool smp_encrypt_data (uint8_t *key, uint8_t key_len, * Returns void * ******************************************************************************/ -void smp_generate_passkey(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_TK; +void smp_generate_passkey(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_TK; - /* generate MRand or SRand */ - btsnd_hcic_ble_rand((void *)smp_rand_back); + /* generate MRand or SRand */ + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -200,41 +197,36 @@ void smp_generate_passkey(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_proc_passkey(tSMP_CB *p_cb , tBTM_RAND_ENC *p) -{ - uint8_t *tt = p_cb->tk; - tSMP_KEY key; - uint32_t passkey; /* 19655 test number; */ - uint8_t *pp = p->param_buf; - - SMP_TRACE_DEBUG ("%s", __func__); - STREAM_TO_UINT32(passkey, pp); - passkey &= ~SMP_PASSKEY_MASK; - - /* truncate by maximum value */ - while (passkey > BTM_MAX_PASSKEY_VAL) - passkey >>= 1; - - /* save the TK */ - memset(p_cb->tk, 0, BT_OCTET16_LEN); - UINT32_TO_STREAM(tt, passkey); - - key.key_type = SMP_KEY_TYPE_TK; - key.p_data = p_cb->tk; - - if (p_cb->p_callback) - { - (*p_cb->p_callback)(SMP_PASSKEY_NOTIF_EVT, p_cb->pairing_bda, (tSMP_EVT_DATA *)&passkey); - } - - if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_PASSKEY_DISP) - { - smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &passkey); - } - else - { - smp_sm_event(p_cb, SMP_KEY_READY_EVT, (tSMP_INT_DATA *)&key); - } +void smp_proc_passkey(tSMP_CB* p_cb, tBTM_RAND_ENC* p) { + uint8_t* tt = p_cb->tk; + tSMP_KEY key; + uint32_t passkey; /* 19655 test number; */ + uint8_t* pp = p->param_buf; + + SMP_TRACE_DEBUG("%s", __func__); + STREAM_TO_UINT32(passkey, pp); + passkey &= ~SMP_PASSKEY_MASK; + + /* truncate by maximum value */ + while (passkey > BTM_MAX_PASSKEY_VAL) passkey >>= 1; + + /* save the TK */ + memset(p_cb->tk, 0, BT_OCTET16_LEN); + UINT32_TO_STREAM(tt, passkey); + + key.key_type = SMP_KEY_TYPE_TK; + key.p_data = p_cb->tk; + + if (p_cb->p_callback) { + (*p_cb->p_callback)(SMP_PASSKEY_NOTIF_EVT, p_cb->pairing_bda, + (tSMP_EVT_DATA*)&passkey); + } + + if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_PASSKEY_DISP) { + smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &passkey); + } else { + smp_sm_event(p_cb, SMP_KEY_READY_EVT, (tSMP_INT_DATA*)&key); + } } /******************************************************************************* @@ -248,31 +240,25 @@ void smp_proc_passkey(tSMP_CB *p_cb , tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -void smp_generate_stk(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - SMP_TRACE_DEBUG ("%s", __func__); - - if (p_cb->le_secure_connections_mode_is_used) - { - SMP_TRACE_WARNING ("FOR LE SC LTK IS USED INSTEAD OF STK"); - output.param_len = SMP_ENCRYT_KEY_SIZE; - output.status = HCI_SUCCESS; - output.opcode = HCI_BLE_ENCRYPT; - memcpy(output.param_buf, p_cb->ltk, SMP_ENCRYT_DATA_SIZE); - } - else if (!smp_calculate_legacy_short_term_key(p_cb, &output)) - { - SMP_TRACE_ERROR("%s failed", __func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - return; - } +void smp_generate_stk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->le_secure_connections_mode_is_used) { + SMP_TRACE_WARNING("FOR LE SC LTK IS USED INSTEAD OF STK"); + output.param_len = SMP_ENCRYT_KEY_SIZE; + output.status = HCI_SUCCESS; + output.opcode = HCI_BLE_ENCRYPT; + memcpy(output.param_buf, p_cb->ltk, SMP_ENCRYT_DATA_SIZE); + } else if (!smp_calculate_legacy_short_term_key(p_cb, &output)) { + SMP_TRACE_ERROR("%s failed", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + return; + } - smp_process_stk(p_cb, &output); + smp_process_stk(p_cb, &output); } /******************************************************************************* @@ -286,13 +272,12 @@ void smp_generate_stk(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_generate_srand_mrand_confirm(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_SRAND_MRAND; - /* generate MRand or SRand */ - btsnd_hcic_ble_rand((void *)smp_rand_back); +void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb, + UNUSED_ATTR tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_SRAND_MRAND; + /* generate MRand or SRand */ + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -305,13 +290,11 @@ void smp_generate_srand_mrand_confirm(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_generate_rand_cont(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_SRAND_MRAND_CONT; - /* generate 64 MSB of MRand or SRand */ - btsnd_hcic_ble_rand((void *)smp_rand_back); +void smp_generate_rand_cont(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_SRAND_MRAND_CONT; + /* generate 64 MSB of MRand or SRand */ + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -329,36 +312,27 @@ void smp_generate_rand_cont(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_generate_ltk(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - - bool div_status; - SMP_TRACE_DEBUG ("%s", __func__); - if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) - { - smp_br_process_link_key(p_cb, NULL); - return; - } - else if (p_cb->le_secure_connections_mode_is_used) - { - smp_process_secure_connection_long_term_key(); - return; - } +void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + bool div_status; + SMP_TRACE_DEBUG("%s", __func__); + if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) { + smp_br_process_link_key(p_cb, NULL); + return; + } else if (p_cb->le_secure_connections_mode_is_used) { + smp_process_secure_connection_long_term_key(); + return; + } - div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div); + div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div); - if (div_status) - { - smp_generate_ltk_cont(p_cb, NULL); - } - else - { - SMP_TRACE_DEBUG ("Generate DIV for LTK"); - p_cb->rand_enc_proc_state = SMP_GEN_DIV_LTK; - /* generate MRand or SRand */ - btsnd_hcic_ble_rand((void *)smp_rand_back); - } + if (div_status) { + smp_generate_ltk_cont(p_cb, NULL); + } else { + SMP_TRACE_DEBUG("Generate DIV for LTK"); + p_cb->rand_enc_proc_state = SMP_GEN_DIV_LTK; + /* generate MRand or SRand */ + btsnd_hcic_ble_rand((void*)smp_rand_back); + } } /******************************************************************************* @@ -371,40 +345,31 @@ void smp_generate_ltk(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_compute_csrk(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - - BT_OCTET16 er; - uint8_t buffer[4]; /* for (r || DIV) r=1*/ - uint16_t r=1; - uint8_t *p=buffer; - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - SMP_TRACE_DEBUG ("smp_compute_csrk div=%x", p_cb->div); - BTM_GetDeviceEncRoot(er); - /* CSRK = d1(ER, DIV, 1) */ - UINT16_TO_STREAM(p, p_cb->div); - UINT16_TO_STREAM(p, r); - - if (!SMP_Encrypt(er, BT_OCTET16_LEN, buffer, 4, &output)) - { - SMP_TRACE_ERROR("smp_generate_csrk failed"); - if (p_cb->smp_over_br) - { - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); - } - else - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } - } - else - { - memcpy((void *)p_cb->csrk, output.param_buf, BT_OCTET16_LEN); - smp_send_csrk_info(p_cb, NULL); - } +void smp_compute_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + BT_OCTET16 er; + uint8_t buffer[4]; /* for (r || DIV) r=1*/ + uint16_t r = 1; + uint8_t* p = buffer; + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("smp_compute_csrk div=%x", p_cb->div); + BTM_GetDeviceEncRoot(er); + /* CSRK = d1(ER, DIV, 1) */ + UINT16_TO_STREAM(p, p_cb->div); + UINT16_TO_STREAM(p, r); + + if (!SMP_Encrypt(er, BT_OCTET16_LEN, buffer, 4, &output)) { + SMP_TRACE_ERROR("smp_generate_csrk failed"); + if (p_cb->smp_over_br) { + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status); + } else { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } + } else { + memcpy((void*)p_cb->csrk, output.param_buf, BT_OCTET16_LEN); + smp_send_csrk_info(p_cb, NULL); + } } /******************************************************************************* @@ -418,65 +383,57 @@ void smp_compute_csrk(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_generate_csrk(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - - bool div_status; - - SMP_TRACE_DEBUG ("smp_generate_csrk"); - - div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div); - if (div_status) - { - smp_compute_csrk(p_cb, NULL); - } - else - { - SMP_TRACE_DEBUG ("Generate DIV for CSRK"); - p_cb->rand_enc_proc_state = SMP_GEN_DIV_CSRK; - btsnd_hcic_ble_rand((void *)smp_rand_back); - } +void smp_generate_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + bool div_status; + + SMP_TRACE_DEBUG("smp_generate_csrk"); + + div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div); + if (div_status) { + smp_compute_csrk(p_cb, NULL); + } else { + SMP_TRACE_DEBUG("Generate DIV for CSRK"); + p_cb->rand_enc_proc_state = SMP_GEN_DIV_CSRK; + btsnd_hcic_ble_rand((void*)smp_rand_back); + } } /******************************************************************************* * Function smp_concatenate_peer * add pairing command sent from local device into p1. ******************************************************************************/ -void smp_concatenate_local( tSMP_CB *p_cb, uint8_t **p_data, uint8_t op_code) -{ - uint8_t *p = *p_data; - - SMP_TRACE_DEBUG ("%s", __func__); - UINT8_TO_STREAM(p, op_code); - UINT8_TO_STREAM(p, p_cb->local_io_capability); - UINT8_TO_STREAM(p, p_cb->loc_oob_flag); - UINT8_TO_STREAM(p, p_cb->loc_auth_req); - UINT8_TO_STREAM(p, p_cb->loc_enc_size); - UINT8_TO_STREAM(p, p_cb->local_i_key); - UINT8_TO_STREAM(p, p_cb->local_r_key); - - *p_data = p; +void smp_concatenate_local(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) { + uint8_t* p = *p_data; + + SMP_TRACE_DEBUG("%s", __func__); + UINT8_TO_STREAM(p, op_code); + UINT8_TO_STREAM(p, p_cb->local_io_capability); + UINT8_TO_STREAM(p, p_cb->loc_oob_flag); + UINT8_TO_STREAM(p, p_cb->loc_auth_req); + UINT8_TO_STREAM(p, p_cb->loc_enc_size); + UINT8_TO_STREAM(p, p_cb->local_i_key); + UINT8_TO_STREAM(p, p_cb->local_r_key); + + *p_data = p; } /******************************************************************************* * Function smp_concatenate_peer * add pairing command received from peer device into p1. ******************************************************************************/ -void smp_concatenate_peer( tSMP_CB *p_cb, uint8_t **p_data, uint8_t op_code) -{ - uint8_t *p = *p_data; - - SMP_TRACE_DEBUG ("smp_concatenate_peer "); - UINT8_TO_STREAM(p, op_code); - UINT8_TO_STREAM(p, p_cb->peer_io_caps); - UINT8_TO_STREAM(p, p_cb->peer_oob_flag); - UINT8_TO_STREAM(p, p_cb->peer_auth_req); - UINT8_TO_STREAM(p, p_cb->peer_enc_size); - UINT8_TO_STREAM(p, p_cb->peer_i_key); - UINT8_TO_STREAM(p, p_cb->peer_r_key); - - *p_data = p; +void smp_concatenate_peer(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) { + uint8_t* p = *p_data; + + SMP_TRACE_DEBUG("smp_concatenate_peer "); + UINT8_TO_STREAM(p, op_code); + UINT8_TO_STREAM(p, p_cb->peer_io_caps); + UINT8_TO_STREAM(p, p_cb->peer_oob_flag); + UINT8_TO_STREAM(p, p_cb->peer_auth_req); + UINT8_TO_STREAM(p, p_cb->peer_enc_size); + UINT8_TO_STREAM(p, p_cb->peer_i_key); + UINT8_TO_STREAM(p, p_cb->peer_r_key); + + *p_data = p; } /******************************************************************************* @@ -489,47 +446,43 @@ void smp_concatenate_peer( tSMP_CB *p_cb, uint8_t **p_data, uint8_t op_code) * Returns void * ******************************************************************************/ -void smp_gen_p1_4_confirm( tSMP_CB *p_cb, BT_OCTET16 p1) -{ - uint8_t *p = (uint8_t *)p1; - tBLE_ADDR_TYPE addr_type = 0; - BD_ADDR remote_bda; - - SMP_TRACE_DEBUG ("smp_gen_p1_4_confirm"); - - if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda, &addr_type)) - { - SMP_TRACE_ERROR("can not generate confirm for unknown device"); - return; - } +void smp_gen_p1_4_confirm(tSMP_CB* p_cb, BT_OCTET16 p1) { + uint8_t* p = (uint8_t*)p1; + tBLE_ADDR_TYPE addr_type = 0; + BD_ADDR remote_bda; - BTM_ReadConnectionAddr( p_cb->pairing_bda, p_cb->local_bda, &p_cb->addr_type); - - if (p_cb->role == HCI_ROLE_MASTER) - { - /* LSB : rat': initiator's(local) address type */ - UINT8_TO_STREAM(p, p_cb->addr_type); - /* LSB : iat': responder's address type */ - UINT8_TO_STREAM(p, addr_type); - /* concatinate preq */ - smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_REQ); - /* concatinate pres */ - smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_RSP); - } - else - { - /* LSB : iat': initiator's address type */ - UINT8_TO_STREAM(p, addr_type); - /* LSB : rat': responder's(local) address type */ - UINT8_TO_STREAM(p, p_cb->addr_type); - /* concatinate preq */ - smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_REQ); - /* concatinate pres */ - smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_RSP); - } + SMP_TRACE_DEBUG("smp_gen_p1_4_confirm"); + + if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda, + &addr_type)) { + SMP_TRACE_ERROR("can not generate confirm for unknown device"); + return; + } + + BTM_ReadConnectionAddr(p_cb->pairing_bda, p_cb->local_bda, &p_cb->addr_type); + + if (p_cb->role == HCI_ROLE_MASTER) { + /* LSB : rat': initiator's(local) address type */ + UINT8_TO_STREAM(p, p_cb->addr_type); + /* LSB : iat': responder's address type */ + UINT8_TO_STREAM(p, addr_type); + /* concatinate preq */ + smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_REQ); + /* concatinate pres */ + smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_RSP); + } else { + /* LSB : iat': initiator's address type */ + UINT8_TO_STREAM(p, addr_type); + /* LSB : rat': responder's(local) address type */ + UINT8_TO_STREAM(p, p_cb->addr_type); + /* concatinate preq */ + smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_REQ); + /* concatinate pres */ + smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_RSP); + } #if (SMP_DEBUG == TRUE) - SMP_TRACE_DEBUG("p1 = pres || preq || rat' || iat'"); - smp_debug_print_nbyte_little_endian ((uint8_t *)p1, (const uint8_t *)"P1", 16); + SMP_TRACE_DEBUG("p1 = pres || preq || rat' || iat'"); + smp_debug_print_nbyte_little_endian((uint8_t*)p1, (const uint8_t*)"P1", 16); #endif } @@ -543,39 +496,35 @@ void smp_gen_p1_4_confirm( tSMP_CB *p_cb, BT_OCTET16 p1) * Returns void * ******************************************************************************/ -void smp_gen_p2_4_confirm( tSMP_CB *p_cb, BT_OCTET16 p2) -{ - uint8_t *p = (uint8_t *)p2; - BD_ADDR remote_bda; - tBLE_ADDR_TYPE addr_type = 0; - - if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda, &addr_type)) - { - SMP_TRACE_ERROR("can not generate confirm p2 for unknown device"); - return; - } - - SMP_TRACE_DEBUG ("smp_gen_p2_4_confirm"); - - memset(p, 0, sizeof(BT_OCTET16)); - - if (p_cb->role == HCI_ROLE_MASTER) - { - /* LSB ra */ - BDADDR_TO_STREAM(p, remote_bda); - /* ia */ - BDADDR_TO_STREAM(p, p_cb->local_bda); - } - else - { - /* LSB ra */ - BDADDR_TO_STREAM(p, p_cb->local_bda); - /* ia */ - BDADDR_TO_STREAM(p, remote_bda); - } +void smp_gen_p2_4_confirm(tSMP_CB* p_cb, BT_OCTET16 p2) { + uint8_t* p = (uint8_t*)p2; + BD_ADDR remote_bda; + tBLE_ADDR_TYPE addr_type = 0; + + if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda, + &addr_type)) { + SMP_TRACE_ERROR("can not generate confirm p2 for unknown device"); + return; + } + + SMP_TRACE_DEBUG("smp_gen_p2_4_confirm"); + + memset(p, 0, sizeof(BT_OCTET16)); + + if (p_cb->role == HCI_ROLE_MASTER) { + /* LSB ra */ + BDADDR_TO_STREAM(p, remote_bda); + /* ia */ + BDADDR_TO_STREAM(p, p_cb->local_bda); + } else { + /* LSB ra */ + BDADDR_TO_STREAM(p, p_cb->local_bda); + /* ia */ + BDADDR_TO_STREAM(p, remote_bda); + } #if (SMP_DEBUG == TRUE) - SMP_TRACE_DEBUG("p2 = padding || ia || ra"); - smp_debug_print_nbyte_little_endian(p2, (const uint8_t *)"p2", 16); + SMP_TRACE_DEBUG("p2 = padding || ia || ra"); + smp_debug_print_nbyte_little_endian(p2, (const uint8_t*)"p2", 16); #endif } @@ -588,33 +537,29 @@ void smp_gen_p2_4_confirm( tSMP_CB *p_cb, BT_OCTET16 p2) * Returns void * ******************************************************************************/ -void smp_calculate_comfirm (tSMP_CB *p_cb, BT_OCTET16 rand, - UNUSED_ATTR BD_ADDR bda) -{ - - BT_OCTET16 p1; - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - SMP_TRACE_DEBUG ("smp_calculate_comfirm "); - /* generate p1 = pres || preq || rat' || iat' */ - smp_gen_p1_4_confirm(p_cb, p1); - - /* p1 = rand XOR p1 */ - smp_xor_128(p1, rand); - - smp_debug_print_nbyte_little_endian ((uint8_t *)p1, (const uint8_t *)"P1' = r XOR p1", 16); - - /* calculate e(k, r XOR p1), where k = TK */ - if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p1, BT_OCTET16_LEN, &output)) - { - SMP_TRACE_ERROR("smp_generate_csrk failed"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } - else - { - smp_calculate_comfirm_cont(p_cb, &output); - } +void smp_calculate_comfirm(tSMP_CB* p_cb, BT_OCTET16 rand, + UNUSED_ATTR BD_ADDR bda) { + BT_OCTET16 p1; + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("smp_calculate_comfirm "); + /* generate p1 = pres || preq || rat' || iat' */ + smp_gen_p1_4_confirm(p_cb, p1); + + /* p1 = rand XOR p1 */ + smp_xor_128(p1, rand); + + smp_debug_print_nbyte_little_endian((uint8_t*)p1, + (const uint8_t*)"P1' = r XOR p1", 16); + + /* calculate e(k, r XOR p1), where k = TK */ + if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p1, BT_OCTET16_LEN, &output)) { + SMP_TRACE_ERROR("smp_generate_csrk failed"); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } else { + smp_calculate_comfirm_cont(p_cb, &output); + } } /******************************************************************************* @@ -627,43 +572,39 @@ void smp_calculate_comfirm (tSMP_CB *p_cb, BT_OCTET16 rand, * Returns void * ******************************************************************************/ -static void smp_calculate_comfirm_cont(tSMP_CB *p_cb, tSMP_ENC *p) -{ - BT_OCTET16 p2; - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; +static void smp_calculate_comfirm_cont(tSMP_CB* p_cb, tSMP_ENC* p) { + BT_OCTET16 p2; + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - SMP_TRACE_DEBUG ("smp_calculate_comfirm_cont "); + SMP_TRACE_DEBUG("smp_calculate_comfirm_cont "); #if (SMP_DEBUG == TRUE) - SMP_TRACE_DEBUG("Confirm step 1 p1' = e(k, r XOR p1) Generated"); - smp_debug_print_nbyte_little_endian (p->param_buf, (const uint8_t *)"C1", 16); + SMP_TRACE_DEBUG("Confirm step 1 p1' = e(k, r XOR p1) Generated"); + smp_debug_print_nbyte_little_endian(p->param_buf, (const uint8_t*)"C1", 16); #endif - smp_gen_p2_4_confirm(p_cb, p2); + smp_gen_p2_4_confirm(p_cb, p2); - /* calculate p2 = (p1' XOR p2) */ - smp_xor_128(p2, p->param_buf); - smp_debug_print_nbyte_little_endian ((uint8_t *)p2, (const uint8_t *)"p2' = C1 xor p2", 16); + /* calculate p2 = (p1' XOR p2) */ + smp_xor_128(p2, p->param_buf); + smp_debug_print_nbyte_little_endian((uint8_t*)p2, + (const uint8_t*)"p2' = C1 xor p2", 16); - /* calculate: Confirm = E(k, p1' XOR p2) */ - if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p2, BT_OCTET16_LEN, &output)) - { - SMP_TRACE_ERROR("smp_calculate_comfirm_cont failed"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } - else - { - switch (p_cb->rand_enc_proc_state) - { - case SMP_GEN_CONFIRM: - smp_process_confirm(p_cb, &output); - break; - - case SMP_GEN_COMPARE: - smp_process_compare(p_cb, &output); - break; - } + /* calculate: Confirm = E(k, p1' XOR p2) */ + if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p2, BT_OCTET16_LEN, &output)) { + SMP_TRACE_ERROR("smp_calculate_comfirm_cont failed"); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } else { + switch (p_cb->rand_enc_proc_state) { + case SMP_GEN_CONFIRM: + smp_process_confirm(p_cb, &output); + break; + + case SMP_GEN_COMPARE: + smp_process_compare(p_cb, &output); + break; } + } } /******************************************************************************* @@ -677,13 +618,13 @@ static void smp_calculate_comfirm_cont(tSMP_CB *p_cb, tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void smp_generate_confirm(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_CONFIRM; - smp_debug_print_nbyte_little_endian ((uint8_t *)p_cb->rand, (const uint8_t *)"local rand", 16); - smp_calculate_comfirm(p_cb, p_cb->rand, p_cb->pairing_bda); +static void smp_generate_confirm(tSMP_CB* p_cb, + UNUSED_ATTR tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_CONFIRM; + smp_debug_print_nbyte_little_endian((uint8_t*)p_cb->rand, + (const uint8_t*)"local rand", 16); + smp_calculate_comfirm(p_cb, p_cb->rand, p_cb->pairing_bda); } /******************************************************************************* @@ -698,13 +639,12 @@ static void smp_generate_confirm(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -void smp_generate_compare (tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("smp_generate_compare "); - p_cb->rand_enc_proc_state = SMP_GEN_COMPARE; - smp_debug_print_nbyte_little_endian ((uint8_t *)p_cb->rrand, (const uint8_t *)"peer rand", 16); - smp_calculate_comfirm(p_cb, p_cb->rrand, p_cb->local_bda); +void smp_generate_compare(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("smp_generate_compare "); + p_cb->rand_enc_proc_state = SMP_GEN_COMPARE; + smp_debug_print_nbyte_little_endian((uint8_t*)p_cb->rrand, + (const uint8_t*)"peer rand", 16); + smp_calculate_comfirm(p_cb, p_cb->rrand, p_cb->local_bda); } /******************************************************************************* @@ -717,21 +657,21 @@ void smp_generate_compare (tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -static void smp_process_confirm(tSMP_CB *p_cb, tSMP_ENC *p) -{ - tSMP_KEY key; +static void smp_process_confirm(tSMP_CB* p_cb, tSMP_ENC* p) { + tSMP_KEY key; - SMP_TRACE_DEBUG ("%s", __func__); - memcpy(p_cb->confirm, p->param_buf, BT_OCTET16_LEN); + SMP_TRACE_DEBUG("%s", __func__); + memcpy(p_cb->confirm, p->param_buf, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - SMP_TRACE_DEBUG("Confirm Generated"); - smp_debug_print_nbyte_little_endian ((uint8_t *)p_cb->confirm, (const uint8_t *)"Confirm", 16); + SMP_TRACE_DEBUG("Confirm Generated"); + smp_debug_print_nbyte_little_endian((uint8_t*)p_cb->confirm, + (const uint8_t*)"Confirm", 16); #endif - key.key_type = SMP_KEY_TYPE_CFM; - key.p_data = p->param_buf; - smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); + key.key_type = SMP_KEY_TYPE_CFM; + key.p_data = p->param_buf; + smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); } /******************************************************************************* @@ -744,19 +684,19 @@ static void smp_process_confirm(tSMP_CB *p_cb, tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void smp_process_compare(tSMP_CB *p_cb, tSMP_ENC *p) -{ - tSMP_KEY key; +static void smp_process_compare(tSMP_CB* p_cb, tSMP_ENC* p) { + tSMP_KEY key; - SMP_TRACE_DEBUG ("smp_process_compare "); + SMP_TRACE_DEBUG("smp_process_compare "); #if (SMP_DEBUG == TRUE) - SMP_TRACE_DEBUG("Compare Generated"); - smp_debug_print_nbyte_little_endian (p->param_buf, (const uint8_t *)"Compare", 16); + SMP_TRACE_DEBUG("Compare Generated"); + smp_debug_print_nbyte_little_endian(p->param_buf, (const uint8_t*)"Compare", + 16); #endif - key.key_type = SMP_KEY_TYPE_CMP; - key.p_data = p->param_buf; + key.key_type = SMP_KEY_TYPE_CMP; + key.p_data = p->param_buf; - smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); + smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); } /******************************************************************************* @@ -769,20 +709,19 @@ static void smp_process_compare(tSMP_CB *p_cb, tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void smp_process_stk(tSMP_CB *p_cb, tSMP_ENC *p) -{ - tSMP_KEY key; +static void smp_process_stk(tSMP_CB* p_cb, tSMP_ENC* p) { + tSMP_KEY key; - SMP_TRACE_DEBUG ("smp_process_stk "); + SMP_TRACE_DEBUG("smp_process_stk "); #if (SMP_DEBUG == TRUE) - SMP_TRACE_ERROR("STK Generated"); + SMP_TRACE_ERROR("STK Generated"); #endif - smp_mask_enc_key(p_cb->loc_enc_size, p->param_buf); + smp_mask_enc_key(p_cb->loc_enc_size, p->param_buf); - key.key_type = SMP_KEY_TYPE_STK; - key.p_data = p->param_buf; + key.key_type = SMP_KEY_TYPE_STK; + key.p_data = p->param_buf; - smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); + smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); } /******************************************************************************* @@ -794,31 +733,26 @@ static void smp_process_stk(tSMP_CB *p_cb, tSMP_ENC *p) * Returns void * ******************************************************************************/ -static void smp_generate_ltk_cont(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p_data) -{ - - BT_OCTET16 er; - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - SMP_TRACE_DEBUG ("%s", __func__); - BTM_GetDeviceEncRoot(er); - - /* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/ - if (!SMP_Encrypt(er, BT_OCTET16_LEN, (uint8_t *)&p_cb->div, - sizeof(uint16_t), &output)) - { - SMP_TRACE_ERROR("%s failed", __func__); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } - else - { - /* mask the LTK */ - smp_mask_enc_key(p_cb->loc_enc_size, output.param_buf); - memcpy((void *)p_cb->ltk, output.param_buf, BT_OCTET16_LEN); - smp_generate_rand_vector(p_cb, NULL); - } +static void smp_generate_ltk_cont(tSMP_CB* p_cb, + UNUSED_ATTR tSMP_INT_DATA* p_data) { + BT_OCTET16 er; + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("%s", __func__); + BTM_GetDeviceEncRoot(er); + + /* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/ + if (!SMP_Encrypt(er, BT_OCTET16_LEN, (uint8_t*)&p_cb->div, sizeof(uint16_t), + &output)) { + SMP_TRACE_ERROR("%s failed", __func__); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } else { + /* mask the LTK */ + smp_mask_enc_key(p_cb->loc_enc_size, output.param_buf); + memcpy((void*)p_cb->ltk, output.param_buf, BT_OCTET16_LEN); + smp_generate_rand_vector(p_cb, NULL); + } } /******************************************************************************* @@ -830,28 +764,21 @@ static void smp_generate_ltk_cont(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -static void smp_generate_y(tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p) -{ - - BT_OCTET16 dhk; - tSMP_ENC output; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - - SMP_TRACE_DEBUG ("smp_generate_y "); - BTM_GetDeviceDHK(dhk); - - if (!SMP_Encrypt(dhk, BT_OCTET16_LEN, p_cb->enc_rand, - BT_OCTET8_LEN, &output)) - { - SMP_TRACE_ERROR("smp_generate_y failed"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } - else - { - smp_process_ediv(p_cb, &output); - } +static void smp_generate_y(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p) { + BT_OCTET16 dhk; + tSMP_ENC output; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("smp_generate_y "); + BTM_GetDeviceDHK(dhk); + + if (!SMP_Encrypt(dhk, BT_OCTET16_LEN, p_cb->enc_rand, BT_OCTET8_LEN, + &output)) { + SMP_TRACE_ERROR("smp_generate_y failed"); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } else { + smp_process_ediv(p_cb, &output); + } } /******************************************************************************* @@ -864,14 +791,13 @@ static void smp_generate_y(tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -static void smp_generate_rand_vector (tSMP_CB *p_cb, - UNUSED_ATTR tSMP_INT_DATA *p) -{ - /* generate EDIV and rand now */ - /* generate random vector */ - SMP_TRACE_DEBUG ("smp_generate_rand_vector "); - p_cb->rand_enc_proc_state = SMP_GEN_RAND_V; - btsnd_hcic_ble_rand((void *)smp_rand_back); +static void smp_generate_rand_vector(tSMP_CB* p_cb, + UNUSED_ATTR tSMP_INT_DATA* p) { + /* generate EDIV and rand now */ + /* generate random vector */ + SMP_TRACE_DEBUG("smp_generate_rand_vector "); + p_cb->rand_enc_proc_state = SMP_GEN_RAND_V; + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -883,23 +809,22 @@ static void smp_generate_rand_vector (tSMP_CB *p_cb, * Returns void * ******************************************************************************/ -static void smp_process_ediv(tSMP_CB *p_cb, tSMP_ENC *p) -{ - tSMP_KEY key; - uint8_t *pp= p->param_buf; - uint16_t y; - - SMP_TRACE_DEBUG ("smp_process_ediv "); - STREAM_TO_UINT16(y, pp); - - /* EDIV = Y xor DIV */ - p_cb->ediv = p_cb->div ^ y; - /* send LTK ready */ - SMP_TRACE_ERROR("LTK ready"); - key.key_type = SMP_KEY_TYPE_LTK; - key.p_data = p->param_buf; - - smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); +static void smp_process_ediv(tSMP_CB* p_cb, tSMP_ENC* p) { + tSMP_KEY key; + uint8_t* pp = p->param_buf; + uint16_t y; + + SMP_TRACE_DEBUG("smp_process_ediv "); + STREAM_TO_UINT16(y, pp); + + /* EDIV = Y xor DIV */ + p_cb->ediv = p_cb->div ^ y; + /* send LTK ready */ + SMP_TRACE_ERROR("LTK ready"); + key.key_type = SMP_KEY_TYPE_LTK; + key.p_data = p->param_buf; + + smp_sm_event(p_cb, SMP_KEY_READY_EVT, &key); } /******************************************************************************* @@ -911,32 +836,28 @@ static void smp_process_ediv(tSMP_CB *p_cb, tSMP_ENC *p) * Returns false if out of resources, true in other cases. * ******************************************************************************/ -bool smp_calculate_legacy_short_term_key(tSMP_CB *p_cb, tSMP_ENC *output) -{ - BT_OCTET16 ptext; - uint8_t *p = ptext; - - SMP_TRACE_DEBUG ("%s", __func__); - memset(p, 0, BT_OCTET16_LEN); - if (p_cb->role == HCI_ROLE_MASTER) - { - memcpy(p, p_cb->rand, BT_OCTET8_LEN); - memcpy(&p[BT_OCTET8_LEN], p_cb->rrand, BT_OCTET8_LEN); - } - else - { - memcpy(p, p_cb->rrand, BT_OCTET8_LEN); - memcpy(&p[BT_OCTET8_LEN], p_cb->rand, BT_OCTET8_LEN); - } - - bool encrypted; - /* generate STK = Etk(rand|rrand)*/ - encrypted = SMP_Encrypt( p_cb->tk, BT_OCTET16_LEN, ptext, BT_OCTET16_LEN, output); - if (!encrypted) - { - SMP_TRACE_ERROR("%s failed", __func__); - } - return encrypted; +bool smp_calculate_legacy_short_term_key(tSMP_CB* p_cb, tSMP_ENC* output) { + BT_OCTET16 ptext; + uint8_t* p = ptext; + + SMP_TRACE_DEBUG("%s", __func__); + memset(p, 0, BT_OCTET16_LEN); + if (p_cb->role == HCI_ROLE_MASTER) { + memcpy(p, p_cb->rand, BT_OCTET8_LEN); + memcpy(&p[BT_OCTET8_LEN], p_cb->rrand, BT_OCTET8_LEN); + } else { + memcpy(p, p_cb->rrand, BT_OCTET8_LEN); + memcpy(&p[BT_OCTET8_LEN], p_cb->rand, BT_OCTET8_LEN); + } + + bool encrypted; + /* generate STK = Etk(rand|rrand)*/ + encrypted = + SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, ptext, BT_OCTET16_LEN, output); + if (!encrypted) { + SMP_TRACE_ERROR("%s failed", __func__); + } + return encrypted; } /******************************************************************************* @@ -951,11 +872,10 @@ bool smp_calculate_legacy_short_term_key(tSMP_CB *p_cb, tSMP_ENC *output) * Returns void * ******************************************************************************/ -void smp_create_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s",__func__); - p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_0_7; - btsnd_hcic_ble_rand((void *)smp_rand_back); +void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_0_7; + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -974,25 +894,24 @@ void smp_create_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Returns void * ******************************************************************************/ -void smp_use_oob_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s req_oob_type: %d, role: %d", - __func__, p_cb->req_oob_type, p_cb->role); - - switch (p_cb->req_oob_type) - { - case SMP_OOB_BOTH: - case SMP_OOB_LOCAL: - SMP_TRACE_DEBUG("%s restore secret key", __func__) - memcpy(p_cb->private_key, p_cb->sc_oob_data.loc_oob_data.private_key_used, BT_OCTET32_LEN); - smp_process_private_key(p_cb); - break; - default: - SMP_TRACE_DEBUG("%s create secret key anew", __func__); - smp_set_state(SMP_STATE_PAIR_REQ_RSP); - smp_decide_association_model(p_cb, NULL); - break; - } +void smp_use_oob_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s req_oob_type: %d, role: %d", __func__, p_cb->req_oob_type, + p_cb->role); + + switch (p_cb->req_oob_type) { + case SMP_OOB_BOTH: + case SMP_OOB_LOCAL: + SMP_TRACE_DEBUG("%s restore secret key", __func__) + memcpy(p_cb->private_key, p_cb->sc_oob_data.loc_oob_data.private_key_used, + BT_OCTET32_LEN); + smp_process_private_key(p_cb); + break; + default: + SMP_TRACE_DEBUG("%s create secret key anew", __func__); + smp_set_state(SMP_STATE_PAIR_REQ_RSP); + smp_decide_association_model(p_cb, NULL); + break; + } } /******************************************************************************* @@ -1004,41 +923,39 @@ void smp_use_oob_private_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Returns void * ******************************************************************************/ -void smp_continue_private_key_creation (tSMP_CB *p_cb, tBTM_RAND_ENC *p) -{ - uint8_t state = p_cb->rand_enc_proc_state & ~0x80; - SMP_TRACE_DEBUG ("%s state=0x%x", __func__, state); - - switch (state) - { - case SMP_GENERATE_PRIVATE_KEY_0_7: - memcpy((void *)p_cb->private_key, p->param_buf, p->param_len); - p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_8_15; - btsnd_hcic_ble_rand((void *)smp_rand_back); - break; - - case SMP_GENERATE_PRIVATE_KEY_8_15: - memcpy((void *)&p_cb->private_key[8], p->param_buf, p->param_len); - p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_16_23; - btsnd_hcic_ble_rand((void *)smp_rand_back); - break; - - case SMP_GENERATE_PRIVATE_KEY_16_23: - memcpy((void *)&p_cb->private_key[16], p->param_buf, p->param_len); - p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_24_31; - btsnd_hcic_ble_rand((void *)smp_rand_back); - break; - - case SMP_GENERATE_PRIVATE_KEY_24_31: - memcpy((void *)&p_cb->private_key[24], p->param_buf, p->param_len); - smp_process_private_key (p_cb); - break; - - default: - break; - } - - return; +void smp_continue_private_key_creation(tSMP_CB* p_cb, tBTM_RAND_ENC* p) { + uint8_t state = p_cb->rand_enc_proc_state & ~0x80; + SMP_TRACE_DEBUG("%s state=0x%x", __func__, state); + + switch (state) { + case SMP_GENERATE_PRIVATE_KEY_0_7: + memcpy((void*)p_cb->private_key, p->param_buf, p->param_len); + p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_8_15; + btsnd_hcic_ble_rand((void*)smp_rand_back); + break; + + case SMP_GENERATE_PRIVATE_KEY_8_15: + memcpy((void*)&p_cb->private_key[8], p->param_buf, p->param_len); + p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_16_23; + btsnd_hcic_ble_rand((void*)smp_rand_back); + break; + + case SMP_GENERATE_PRIVATE_KEY_16_23: + memcpy((void*)&p_cb->private_key[16], p->param_buf, p->param_len); + p_cb->rand_enc_proc_state = SMP_GENERATE_PRIVATE_KEY_24_31; + btsnd_hcic_ble_rand((void*)smp_rand_back); + break; + + case SMP_GENERATE_PRIVATE_KEY_24_31: + memcpy((void*)&p_cb->private_key[24], p->param_buf, p->param_len); + smp_process_private_key(p_cb); + break; + + default: + break; + } + + return; } /******************************************************************************* @@ -1052,26 +969,26 @@ void smp_continue_private_key_creation (tSMP_CB *p_cb, tBTM_RAND_ENC *p) * Returns void * ******************************************************************************/ -void smp_process_private_key(tSMP_CB *p_cb) -{ - Point public_key; - BT_OCTET32 private_key; - - SMP_TRACE_DEBUG ("%s", __func__); - - memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN); - ECC_PointMult(&public_key, &(curve_p256.G), (uint32_t*) private_key, KEY_LENGTH_DWORDS_P256); - memcpy(p_cb->loc_publ_key.x, public_key.x, BT_OCTET32_LEN); - memcpy(p_cb->loc_publ_key.y, public_key.y, BT_OCTET32_LEN); - - smp_debug_print_nbyte_little_endian (p_cb->private_key, (const uint8_t *)"private", - BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->loc_publ_key.x, (const uint8_t *)"local public(x)", - BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->loc_publ_key.y, (const uint8_t *)"local public(y)", - BT_OCTET32_LEN); - p_cb->flags |= SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY; - smp_sm_event(p_cb, SMP_LOC_PUBL_KEY_CRTD_EVT, NULL); +void smp_process_private_key(tSMP_CB* p_cb) { + Point public_key; + BT_OCTET32 private_key; + + SMP_TRACE_DEBUG("%s", __func__); + + memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN); + ECC_PointMult(&public_key, &(curve_p256.G), (uint32_t*)private_key, + KEY_LENGTH_DWORDS_P256); + memcpy(p_cb->loc_publ_key.x, public_key.x, BT_OCTET32_LEN); + memcpy(p_cb->loc_publ_key.y, public_key.y, BT_OCTET32_LEN); + + smp_debug_print_nbyte_little_endian( + p_cb->private_key, (const uint8_t*)"private", BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->loc_publ_key.x, (const uint8_t*)"local public(x)", BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->loc_publ_key.y, (const uint8_t*)"local public(y)", BT_OCTET32_LEN); + p_cb->flags |= SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY; + smp_sm_event(p_cb, SMP_LOC_PUBL_KEY_CRTD_EVT, NULL); } /******************************************************************************* @@ -1086,32 +1003,32 @@ void smp_process_private_key(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_compute_dhkey (tSMP_CB *p_cb) -{ - Point peer_publ_key, new_publ_key; - BT_OCTET32 private_key; +void smp_compute_dhkey(tSMP_CB* p_cb) { + Point peer_publ_key, new_publ_key; + BT_OCTET32 private_key; - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN); - memcpy(peer_publ_key.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN); - memcpy(peer_publ_key.y, p_cb->peer_publ_key.y, BT_OCTET32_LEN); + memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN); + memcpy(peer_publ_key.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN); + memcpy(peer_publ_key.y, p_cb->peer_publ_key.y, BT_OCTET32_LEN); - ECC_PointMult(&new_publ_key, &peer_publ_key, (uint32_t*) private_key, KEY_LENGTH_DWORDS_P256); + ECC_PointMult(&new_publ_key, &peer_publ_key, (uint32_t*)private_key, + KEY_LENGTH_DWORDS_P256); - memcpy(p_cb->dhkey, new_publ_key.x, BT_OCTET32_LEN); + memcpy(p_cb->dhkey, new_publ_key.x, BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->dhkey, (const uint8_t *)"Old DHKey", - BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian(p_cb->dhkey, (const uint8_t*)"Old DHKey", + BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->private_key, (const uint8_t *)"private", - BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->peer_publ_key.x, (const uint8_t *)"rem public(x)", - BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->peer_publ_key.y, (const uint8_t *)"rem public(y)", - BT_OCTET32_LEN); - smp_debug_print_nbyte_little_endian (p_cb->dhkey, (const uint8_t *)"Reverted DHKey", - BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->private_key, (const uint8_t*)"private", BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->peer_publ_key.x, (const uint8_t*)"rem public(x)", BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->peer_publ_key.y, (const uint8_t*)"rem public(y)", BT_OCTET32_LEN); + smp_debug_print_nbyte_little_endian( + p_cb->dhkey, (const uint8_t*)"Reverted DHKey", BT_OCTET32_LEN); } /******************************************************************************* @@ -1123,40 +1040,41 @@ void smp_compute_dhkey (tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_calculate_local_commitment(tSMP_CB *p_cb) -{ - uint8_t random_input; - - SMP_TRACE_DEBUG("%s", __func__); - - switch (p_cb->selected_association_model) - { - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - if (p_cb->role == HCI_ROLE_MASTER) - SMP_TRACE_WARNING ("local commitment calc on master is not expected \ - for Just Works/Numeric Comparison models"); - smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, 0, - p_cb->commitment); - break; - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - random_input = smp_calculate_random_input(p_cb->local_random, p_cb->round); - smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, - random_input, p_cb->commitment); - break; - case SMP_MODEL_SEC_CONN_OOB: - SMP_TRACE_WARNING ("local commitment calc is expected for OOB model BEFORE pairing"); - smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->loc_publ_key.x, p_cb->local_random, 0, - p_cb->commitment); - break; - default: - SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", - p_cb->selected_association_model); - return; - } +void smp_calculate_local_commitment(tSMP_CB* p_cb) { + uint8_t random_input; + + SMP_TRACE_DEBUG("%s", __func__); - SMP_TRACE_EVENT ("local commitment calculation is completed"); + switch (p_cb->selected_association_model) { + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + if (p_cb->role == HCI_ROLE_MASTER) + SMP_TRACE_WARNING( + "local commitment calc on master is not expected \ + for Just Works/Numeric Comparison models"); + smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, + 0, p_cb->commitment); + break; + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + random_input = + smp_calculate_random_input(p_cb->local_random, p_cb->round); + smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, + random_input, p_cb->commitment); + break; + case SMP_MODEL_SEC_CONN_OOB: + SMP_TRACE_WARNING( + "local commitment calc is expected for OOB model BEFORE pairing"); + smp_calculate_f4(p_cb->loc_publ_key.x, p_cb->loc_publ_key.x, + p_cb->local_random, 0, p_cb->commitment); + break; + default: + SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", + p_cb->selected_association_model); + return; + } + + SMP_TRACE_EVENT("local commitment calculation is completed"); } /******************************************************************************* @@ -1169,39 +1087,38 @@ void smp_calculate_local_commitment(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_calculate_peer_commitment(tSMP_CB *p_cb, BT_OCTET16 output_buf) -{ - uint8_t ri; - - SMP_TRACE_DEBUG ("%s", __func__); - - switch (p_cb->selected_association_model) - { - case SMP_MODEL_SEC_CONN_JUSTWORKS: - case SMP_MODEL_SEC_CONN_NUM_COMP: - if (p_cb->role == HCI_ROLE_SLAVE) - SMP_TRACE_WARNING ("peer commitment calc on slave is not expected \ - for Just Works/Numeric Comparison models"); - smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, 0, - output_buf); - break; - case SMP_MODEL_SEC_CONN_PASSKEY_ENT: - case SMP_MODEL_SEC_CONN_PASSKEY_DISP: - ri = smp_calculate_random_input(p_cb->peer_random, p_cb->round); - smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, ri, - output_buf); - break; - case SMP_MODEL_SEC_CONN_OOB: - smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->peer_publ_key.x, p_cb->peer_random, 0, - output_buf); - break; - default: - SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", - p_cb->selected_association_model); - return; - } +void smp_calculate_peer_commitment(tSMP_CB* p_cb, BT_OCTET16 output_buf) { + uint8_t ri; - SMP_TRACE_EVENT ("peer commitment calculation is completed"); + SMP_TRACE_DEBUG("%s", __func__); + + switch (p_cb->selected_association_model) { + case SMP_MODEL_SEC_CONN_JUSTWORKS: + case SMP_MODEL_SEC_CONN_NUM_COMP: + if (p_cb->role == HCI_ROLE_SLAVE) + SMP_TRACE_WARNING( + "peer commitment calc on slave is not expected \ + for Just Works/Numeric Comparison models"); + smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, + 0, output_buf); + break; + case SMP_MODEL_SEC_CONN_PASSKEY_ENT: + case SMP_MODEL_SEC_CONN_PASSKEY_DISP: + ri = smp_calculate_random_input(p_cb->peer_random, p_cb->round); + smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, + ri, output_buf); + break; + case SMP_MODEL_SEC_CONN_OOB: + smp_calculate_f4(p_cb->peer_publ_key.x, p_cb->peer_publ_key.x, + p_cb->peer_random, 0, output_buf); + break; + default: + SMP_TRACE_ERROR("Association Model = %d is not used in LE SC", + p_cb->selected_association_model); + return; + } + + SMP_TRACE_EVENT("peer commitment calculation is completed"); } /******************************************************************************* @@ -1224,54 +1141,60 @@ void smp_calculate_peer_commitment(tSMP_CB *p_cb, BT_OCTET16 output_buf) * the AES-CMAC input/output stream. * ******************************************************************************/ -void smp_calculate_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z, uint8_t *c) -{ - uint8_t msg_len = BT_OCTET32_LEN /* U size */ + BT_OCTET32_LEN /* V size */ + 1 /* Z size */; - uint8_t msg[BT_OCTET32_LEN + BT_OCTET32_LEN + 1]; - uint8_t key[BT_OCTET16_LEN]; - uint8_t cmac[BT_OCTET16_LEN]; - uint8_t *p = NULL; +void smp_calculate_f4(uint8_t* u, uint8_t* v, uint8_t* x, uint8_t z, + uint8_t* c) { + uint8_t msg_len = BT_OCTET32_LEN /* U size */ + BT_OCTET32_LEN /* V size */ + + 1 /* Z size */; + uint8_t msg[BT_OCTET32_LEN + BT_OCTET32_LEN + 1]; + uint8_t key[BT_OCTET16_LEN]; + uint8_t cmac[BT_OCTET16_LEN]; + uint8_t* p = NULL; #if (SMP_DEBUG == TRUE) - uint8_t *p_prnt = NULL; + uint8_t* p_prnt = NULL; #endif - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_prnt = u; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"U", BT_OCTET32_LEN); - p_prnt = v; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"V", BT_OCTET32_LEN); - p_prnt = x; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"X", BT_OCTET16_LEN); - p_prnt = &z; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"Z", 1); + p_prnt = u; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"U", + BT_OCTET32_LEN); + p_prnt = v; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"V", + BT_OCTET32_LEN); + p_prnt = x; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"X", + BT_OCTET16_LEN); + p_prnt = &z; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"Z", 1); #endif - p = msg; - UINT8_TO_STREAM(p, z); - ARRAY_TO_STREAM(p, v, BT_OCTET32_LEN); - ARRAY_TO_STREAM(p, u, BT_OCTET32_LEN); + p = msg; + UINT8_TO_STREAM(p, z); + ARRAY_TO_STREAM(p, v, BT_OCTET32_LEN); + ARRAY_TO_STREAM(p, u, BT_OCTET32_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = msg; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"M", msg_len); + p_prnt = msg; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"M", msg_len); #endif - p = key; - ARRAY_TO_STREAM(p, x, BT_OCTET16_LEN); + p = key; + ARRAY_TO_STREAM(p, x, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = key; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"K", BT_OCTET16_LEN); + p_prnt = key; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"K", + BT_OCTET16_LEN); #endif - aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac); + aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac); #if (SMP_DEBUG == TRUE) - p_prnt = cmac; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"AES_CMAC", BT_OCTET16_LEN); + p_prnt = cmac; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"AES_CMAC", + BT_OCTET16_LEN); #endif - p = c; - ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); + p = c; + ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); } /******************************************************************************* @@ -1284,36 +1207,30 @@ void smp_calculate_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z, uint8_t *c) * Returns void * ******************************************************************************/ -void smp_calculate_numeric_comparison_display_number(tSMP_CB *p_cb, - tSMP_INT_DATA *p_data) -{ - SMP_TRACE_DEBUG ("%s", __func__); - - if (p_cb->role == HCI_ROLE_MASTER) - { - p_cb->number_to_display = - smp_calculate_g2(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, - p_cb->rrand); - } - else - { - p_cb->number_to_display = - smp_calculate_g2(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, - p_cb->rand); - } - - if (p_cb->number_to_display >= (BTM_MAX_PASSKEY_VAL + 1)) - { - uint8_t reason; - reason = p_cb->failure = SMP_PAIR_FAIL_UNKNOWN; - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - return; - } - - SMP_TRACE_EVENT("Number to display in numeric comparison = %d", p_cb->number_to_display); - p_cb->cb_evt = SMP_NC_REQ_EVT; - smp_sm_event(p_cb, SMP_SC_DSPL_NC_EVT, &p_cb->number_to_display); +void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb, + tSMP_INT_DATA* p_data) { + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->role == HCI_ROLE_MASTER) { + p_cb->number_to_display = smp_calculate_g2( + p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, p_cb->rrand); + } else { + p_cb->number_to_display = smp_calculate_g2( + p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, p_cb->rand); + } + + if (p_cb->number_to_display >= (BTM_MAX_PASSKEY_VAL + 1)) { + uint8_t reason; + reason = p_cb->failure = SMP_PAIR_FAIL_UNKNOWN; + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); return; + } + + SMP_TRACE_EVENT("Number to display in numeric comparison = %d", + p_cb->number_to_display); + p_cb->cb_evt = SMP_NC_REQ_EVT; + smp_sm_event(p_cb, SMP_SC_DSPL_NC_EVT, &p_cb->number_to_display); + return; } /******************************************************************************* @@ -1340,71 +1257,76 @@ void smp_calculate_numeric_comparison_display_number(tSMP_CB *p_cb, * the AES-CMAC input/output stream. * ******************************************************************************/ -uint32_t smp_calculate_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y) -{ - uint8_t msg_len = BT_OCTET32_LEN /* U size */ + BT_OCTET32_LEN /* V size */ - + BT_OCTET16_LEN /* Y size */; - uint8_t msg[BT_OCTET32_LEN + BT_OCTET32_LEN + BT_OCTET16_LEN]; - uint8_t key[BT_OCTET16_LEN]; - uint8_t cmac[BT_OCTET16_LEN]; - uint8_t *p = NULL; - uint32_t vres; +uint32_t smp_calculate_g2(uint8_t* u, uint8_t* v, uint8_t* x, uint8_t* y) { + uint8_t msg_len = BT_OCTET32_LEN /* U size */ + BT_OCTET32_LEN /* V size */ + + BT_OCTET16_LEN /* Y size */; + uint8_t msg[BT_OCTET32_LEN + BT_OCTET32_LEN + BT_OCTET16_LEN]; + uint8_t key[BT_OCTET16_LEN]; + uint8_t cmac[BT_OCTET16_LEN]; + uint8_t* p = NULL; + uint32_t vres; #if (SMP_DEBUG == TRUE) - uint8_t *p_prnt = NULL; + uint8_t* p_prnt = NULL; #endif - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - p = msg; - ARRAY_TO_STREAM(p, y, BT_OCTET16_LEN); - ARRAY_TO_STREAM(p, v, BT_OCTET32_LEN); - ARRAY_TO_STREAM(p, u, BT_OCTET32_LEN); + p = msg; + ARRAY_TO_STREAM(p, y, BT_OCTET16_LEN); + ARRAY_TO_STREAM(p, v, BT_OCTET32_LEN); + ARRAY_TO_STREAM(p, u, BT_OCTET32_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = u; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"U", BT_OCTET32_LEN); - p_prnt = v; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"V", BT_OCTET32_LEN); - p_prnt = x; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"X", BT_OCTET16_LEN); - p_prnt = y; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"Y", BT_OCTET16_LEN); + p_prnt = u; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"U", + BT_OCTET32_LEN); + p_prnt = v; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"V", + BT_OCTET32_LEN); + p_prnt = x; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"X", + BT_OCTET16_LEN); + p_prnt = y; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"Y", + BT_OCTET16_LEN); #endif - p = key; - ARRAY_TO_STREAM(p, x, BT_OCTET16_LEN); + p = key; + ARRAY_TO_STREAM(p, x, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = key; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"K", BT_OCTET16_LEN); + p_prnt = key; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"K", + BT_OCTET16_LEN); #endif - if(!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) - { - SMP_TRACE_ERROR("%s failed",__func__); - return (BTM_MAX_PASSKEY_VAL + 1); - } + if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) { + SMP_TRACE_ERROR("%s failed", __func__); + return (BTM_MAX_PASSKEY_VAL + 1); + } #if (SMP_DEBUG == TRUE) - p_prnt = cmac; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"AES-CMAC", BT_OCTET16_LEN); + p_prnt = cmac; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"AES-CMAC", + BT_OCTET16_LEN); #endif - /* vres = cmac mod 2**32 mod 10**6 */ - p = &cmac[0]; - STREAM_TO_UINT32(vres, p); + /* vres = cmac mod 2**32 mod 10**6 */ + p = &cmac[0]; + STREAM_TO_UINT32(vres, p); #if (SMP_DEBUG == TRUE) - p_prnt = (uint8_t *) &vres; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"cmac mod 2**32", 4); + p_prnt = (uint8_t*)&vres; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"cmac mod 2**32", + 4); #endif - while (vres > BTM_MAX_PASSKEY_VAL) - vres -= (BTM_MAX_PASSKEY_VAL + 1); + while (vres > BTM_MAX_PASSKEY_VAL) vres -= (BTM_MAX_PASSKEY_VAL + 1); #if (SMP_DEBUG == TRUE) - p_prnt = (uint8_t *) &vres; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"cmac mod 2**32 mod 10**6", 4); + p_prnt = (uint8_t*)&vres; + smp_debug_print_nbyte_little_endian( + p_prnt, (const uint8_t*)"cmac mod 2**32 mod 10**6", 4); #endif - SMP_TRACE_ERROR("Value for numeric comparison = %d", vres); - return vres; + SMP_TRACE_ERROR("Value for numeric comparison = %d", vres); + return vres; } /******************************************************************************* @@ -1467,78 +1389,80 @@ uint32_t smp_calculate_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y) * the AES-CMAC input/output stream. * ******************************************************************************/ -bool smp_calculate_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *a1, uint8_t *a2, - uint8_t *mac_key, uint8_t *ltk) -{ - BT_OCTET16 t; /* AES-CMAC output in smp_calculate_f5_key(...), key in */ - /* smp_calculate_f5_mackey_or_long_term_key(...) */ +bool smp_calculate_f5(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* a1, + uint8_t* a2, uint8_t* mac_key, uint8_t* ltk) { + BT_OCTET16 t; /* AES-CMAC output in smp_calculate_f5_key(...), key in */ + /* smp_calculate_f5_mackey_or_long_term_key(...) */ #if (SMP_DEBUG == TRUE) - uint8_t *p_prnt = NULL; + uint8_t* p_prnt = NULL; #endif - /* internal parameters: */ - - /* - counter is 0 for MacKey, - is 1 for LTK - */ - uint8_t counter_mac_key[1] = {0}; - uint8_t counter_ltk[1] = {1}; - /* - keyID 62746c65 - */ - uint8_t key_id[4] = {0x65, 0x6c, 0x74, 0x62}; - /* - length 0100 - */ - uint8_t length[2] = {0x00, 0x01}; - - SMP_TRACE_DEBUG ("%s", __func__); + /* internal parameters: */ + + /* + counter is 0 for MacKey, + is 1 for LTK + */ + uint8_t counter_mac_key[1] = {0}; + uint8_t counter_ltk[1] = {1}; + /* + keyID 62746c65 + */ + uint8_t key_id[4] = {0x65, 0x6c, 0x74, 0x62}; + /* + length 0100 + */ + uint8_t length[2] = {0x00, 0x01}; + + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_prnt = w; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"W", BT_OCTET32_LEN); - p_prnt = n1; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"N1", BT_OCTET16_LEN); - p_prnt = n2; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"N2", BT_OCTET16_LEN); - p_prnt = a1; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"A1", 7); - p_prnt = a2; - smp_debug_print_nbyte_little_endian (p_prnt,(const uint8_t *) "A2", 7); + p_prnt = w; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"W", + BT_OCTET32_LEN); + p_prnt = n1; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"N1", + BT_OCTET16_LEN); + p_prnt = n2; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"N2", + BT_OCTET16_LEN); + p_prnt = a1; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"A1", 7); + p_prnt = a2; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"A2", 7); #endif - if (!smp_calculate_f5_key(w, t)) - { - SMP_TRACE_ERROR("%s failed to calc T",__func__); - return false; - } + if (!smp_calculate_f5_key(w, t)) { + SMP_TRACE_ERROR("%s failed to calc T", __func__); + return false; + } #if (SMP_DEBUG == TRUE) - p_prnt = t; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"T", BT_OCTET16_LEN); + p_prnt = t; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"T", + BT_OCTET16_LEN); #endif - if (!smp_calculate_f5_mackey_or_long_term_key(t, counter_mac_key, key_id, n1, n2, a1, a2, - length, mac_key)) - { - SMP_TRACE_ERROR("%s failed to calc MacKey", __func__); - return false; - } + if (!smp_calculate_f5_mackey_or_long_term_key(t, counter_mac_key, key_id, n1, + n2, a1, a2, length, mac_key)) { + SMP_TRACE_ERROR("%s failed to calc MacKey", __func__); + return false; + } #if (SMP_DEBUG == TRUE) - p_prnt = mac_key; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"MacKey", BT_OCTET16_LEN); + p_prnt = mac_key; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"MacKey", + BT_OCTET16_LEN); #endif - if (!smp_calculate_f5_mackey_or_long_term_key(t, counter_ltk, key_id, n1, n2, a1, a2, - length, ltk)) - { - SMP_TRACE_ERROR("%s failed to calc LTK",__func__); - return false; - } + if (!smp_calculate_f5_mackey_or_long_term_key(t, counter_ltk, key_id, n1, n2, + a1, a2, length, ltk)) { + SMP_TRACE_ERROR("%s failed to calc LTK", __func__); + return false; + } #if (SMP_DEBUG == TRUE) - p_prnt = ltk; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"LTK", BT_OCTET16_LEN); + p_prnt = ltk; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"LTK", + BT_OCTET16_LEN); #endif - return true; + return true; } /******************************************************************************* @@ -1573,75 +1497,81 @@ bool smp_calculate_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *a1, uint * the AES-CMAC input/output stream. * ******************************************************************************/ -bool smp_calculate_f5_mackey_or_long_term_key(uint8_t *t, uint8_t *counter, - uint8_t *key_id, uint8_t *n1, uint8_t *n2, uint8_t *a1, uint8_t *a2, - uint8_t *length, uint8_t *mac) -{ - uint8_t *p = NULL; - uint8_t cmac[BT_OCTET16_LEN]; - uint8_t key[BT_OCTET16_LEN]; - uint8_t msg_len = 1 /* Counter size */ + 4 /* keyID size */ + - BT_OCTET16_LEN /* N1 size */ + BT_OCTET16_LEN /* N2 size */ + - 7 /* A1 size*/ + 7 /* A2 size*/ + 2 /* Length size */; - uint8_t msg[1 + 4 + BT_OCTET16_LEN + BT_OCTET16_LEN + 7 + 7 + 2]; - bool ret = true; +bool smp_calculate_f5_mackey_or_long_term_key(uint8_t* t, uint8_t* counter, + uint8_t* key_id, uint8_t* n1, + uint8_t* n2, uint8_t* a1, + uint8_t* a2, uint8_t* length, + uint8_t* mac) { + uint8_t* p = NULL; + uint8_t cmac[BT_OCTET16_LEN]; + uint8_t key[BT_OCTET16_LEN]; + uint8_t msg_len = 1 /* Counter size */ + 4 /* keyID size */ + + BT_OCTET16_LEN /* N1 size */ + + BT_OCTET16_LEN /* N2 size */ + 7 /* A1 size*/ + + 7 /* A2 size*/ + 2 /* Length size */; + uint8_t msg[1 + 4 + BT_OCTET16_LEN + BT_OCTET16_LEN + 7 + 7 + 2]; + bool ret = true; #if (SMP_DEBUG == TRUE) - uint8_t *p_prnt = NULL; + uint8_t* p_prnt = NULL; #endif - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_prnt = t; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"T", BT_OCTET16_LEN); - p_prnt = counter; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"Counter", 1); - p_prnt = key_id; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"KeyID", 4); - p_prnt = n1; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"N1", BT_OCTET16_LEN); - p_prnt = n2; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"N2", BT_OCTET16_LEN); - p_prnt = a1; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"A1", 7); - p_prnt = a2; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"A2", 7); - p_prnt = length; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"Length", 2); + p_prnt = t; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"T", + BT_OCTET16_LEN); + p_prnt = counter; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"Counter", 1); + p_prnt = key_id; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"KeyID", 4); + p_prnt = n1; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"N1", + BT_OCTET16_LEN); + p_prnt = n2; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"N2", + BT_OCTET16_LEN); + p_prnt = a1; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"A1", 7); + p_prnt = a2; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"A2", 7); + p_prnt = length; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"Length", 2); #endif - p = key; - ARRAY_TO_STREAM(p, t, BT_OCTET16_LEN); + p = key; + ARRAY_TO_STREAM(p, t, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = key; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"K", BT_OCTET16_LEN); + p_prnt = key; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"K", + BT_OCTET16_LEN); #endif - p = msg; - ARRAY_TO_STREAM(p, length, 2); - ARRAY_TO_STREAM(p, a2, 7); - ARRAY_TO_STREAM(p, a1, 7); - ARRAY_TO_STREAM(p, n2, BT_OCTET16_LEN); - ARRAY_TO_STREAM(p, n1, BT_OCTET16_LEN); - ARRAY_TO_STREAM(p, key_id, 4); - ARRAY_TO_STREAM(p, counter, 1); + p = msg; + ARRAY_TO_STREAM(p, length, 2); + ARRAY_TO_STREAM(p, a2, 7); + ARRAY_TO_STREAM(p, a1, 7); + ARRAY_TO_STREAM(p, n2, BT_OCTET16_LEN); + ARRAY_TO_STREAM(p, n1, BT_OCTET16_LEN); + ARRAY_TO_STREAM(p, key_id, 4); + ARRAY_TO_STREAM(p, counter, 1); #if (SMP_DEBUG == TRUE) - p_prnt = msg; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"M", msg_len); + p_prnt = msg; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"M", msg_len); #endif - if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) - { - SMP_TRACE_ERROR("%s failed", __func__); - ret = false; - } + if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) { + SMP_TRACE_ERROR("%s failed", __func__); + ret = false; + } #if (SMP_DEBUG == TRUE) - p_prnt = cmac; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"AES-CMAC", BT_OCTET16_LEN); + p_prnt = cmac; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"AES-CMAC", + BT_OCTET16_LEN); #endif - p = mac; - ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); - return ret; + p = mac; + ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); + return ret; } /******************************************************************************* @@ -1663,59 +1593,61 @@ bool smp_calculate_f5_mackey_or_long_term_key(uint8_t *t, uint8_t *counter, * the AES-CMAC input/output stream. * ******************************************************************************/ -bool smp_calculate_f5_key(uint8_t *w, uint8_t *t) -{ - uint8_t *p = NULL; - /* Please see 2.2.7 LE Secure Connections Key Generation Function f5 */ - /* - salt: 6C88 8391 AAF5 A538 6037 0BDB 5A60 83BE - */ - BT_OCTET16 salt = { - 0xBE, 0x83, 0x60, 0x5A, 0xDB, 0x0B, 0x37, 0x60, - 0x38, 0xA5, 0xF5, 0xAA, 0x91, 0x83, 0x88, 0x6C - }; +bool smp_calculate_f5_key(uint8_t* w, uint8_t* t) { + uint8_t* p = NULL; + /* Please see 2.2.7 LE Secure Connections Key Generation Function f5 */ + /* + salt: 6C88 8391 AAF5 A538 6037 0BDB 5A60 83BE + */ + BT_OCTET16 salt = {0xBE, 0x83, 0x60, 0x5A, 0xDB, 0x0B, 0x37, 0x60, + 0x38, 0xA5, 0xF5, 0xAA, 0x91, 0x83, 0x88, 0x6C}; #if (SMP_DEBUG == TRUE) - uint8_t *p_prnt = NULL; + uint8_t* p_prnt = NULL; #endif - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_prnt = salt; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"salt", BT_OCTET16_LEN); - p_prnt = w; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"W", BT_OCTET32_LEN); + p_prnt = salt; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"salt", + BT_OCTET16_LEN); + p_prnt = w; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"W", + BT_OCTET32_LEN); #endif - BT_OCTET16 key; - BT_OCTET32 msg; + BT_OCTET16 key; + BT_OCTET32 msg; - p = key; - ARRAY_TO_STREAM(p, salt, BT_OCTET16_LEN); - p = msg; - ARRAY_TO_STREAM(p, w, BT_OCTET32_LEN); + p = key; + ARRAY_TO_STREAM(p, salt, BT_OCTET16_LEN); + p = msg; + ARRAY_TO_STREAM(p, w, BT_OCTET32_LEN); #if (SMP_DEBUG == TRUE) - p_prnt = key; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"K", BT_OCTET16_LEN); - p_prnt = msg; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"M", BT_OCTET32_LEN); + p_prnt = key; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"K", + BT_OCTET16_LEN); + p_prnt = msg; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"M", + BT_OCTET32_LEN); #endif - BT_OCTET16 cmac; - bool ret = true; - if (!aes_cipher_msg_auth_code(key, msg, BT_OCTET32_LEN, BT_OCTET16_LEN, cmac)) - { - SMP_TRACE_ERROR("%s failed", __func__); - ret = false; - } + BT_OCTET16 cmac; + bool ret = true; + if (!aes_cipher_msg_auth_code(key, msg, BT_OCTET32_LEN, BT_OCTET16_LEN, + cmac)) { + SMP_TRACE_ERROR("%s failed", __func__); + ret = false; + } #if (SMP_DEBUG == TRUE) - p_prnt = cmac; - smp_debug_print_nbyte_little_endian (p_prnt, (const uint8_t *)"AES-CMAC", BT_OCTET16_LEN); + p_prnt = cmac; + smp_debug_print_nbyte_little_endian(p_prnt, (const uint8_t*)"AES-CMAC", + BT_OCTET16_LEN); #endif - p = t; - ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); - return ret; + p = t; + ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); + return ret; } /******************************************************************************* @@ -1732,22 +1664,21 @@ bool smp_calculate_f5_key(uint8_t *w, uint8_t *t) * Returns void * ******************************************************************************/ -void smp_calculate_local_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t iocap[3], a[7], b[7]; +void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t iocap[3], a[7], b[7]; - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - smp_calculate_f5_mackey_and_long_term_key(p_cb); + smp_calculate_f5_mackey_and_long_term_key(p_cb); - smp_collect_local_io_capabilities(iocap, p_cb); + smp_collect_local_io_capabilities(iocap, p_cb); - smp_collect_local_ble_address(a, p_cb); - smp_collect_peer_ble_address(b, p_cb); - smp_calculate_f6(p_cb->mac_key, p_cb->rand, p_cb->rrand, p_cb->peer_random, iocap, a, b, - p_cb->dhkey_check); + smp_collect_local_ble_address(a, p_cb); + smp_collect_peer_ble_address(b, p_cb); + smp_calculate_f6(p_cb->mac_key, p_cb->rand, p_cb->rrand, p_cb->peer_random, + iocap, a, b, p_cb->dhkey_check); - SMP_TRACE_EVENT ("local DHKey check calculation is completed"); + SMP_TRACE_EVENT("local DHKey check calculation is completed"); } /******************************************************************************* @@ -1759,39 +1690,35 @@ void smp_calculate_local_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * Returns void * ******************************************************************************/ -void smp_calculate_peer_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) -{ - uint8_t iocap[3], a[7], b[7]; - BT_OCTET16 param_buf; - bool ret; - tSMP_KEY key; - tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; - - SMP_TRACE_DEBUG ("%s", __func__); - - smp_collect_peer_io_capabilities(iocap, p_cb); - - smp_collect_local_ble_address(a, p_cb); - smp_collect_peer_ble_address(b, p_cb); - ret = smp_calculate_f6(p_cb->mac_key, p_cb->rrand, p_cb->rand, p_cb->local_random, iocap, - b, a, param_buf); - - if (ret) - { - SMP_TRACE_EVENT ("peer DHKey check calculation is completed"); +void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { + uint8_t iocap[3], a[7], b[7]; + BT_OCTET16 param_buf; + bool ret; + tSMP_KEY key; + tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN; + + SMP_TRACE_DEBUG("%s", __func__); + + smp_collect_peer_io_capabilities(iocap, p_cb); + + smp_collect_local_ble_address(a, p_cb); + smp_collect_peer_ble_address(b, p_cb); + ret = smp_calculate_f6(p_cb->mac_key, p_cb->rrand, p_cb->rand, + p_cb->local_random, iocap, b, a, param_buf); + + if (ret) { + SMP_TRACE_EVENT("peer DHKey check calculation is completed"); #if (SMP_DEBUG == TRUE) - smp_debug_print_nbyte_little_endian (param_buf, (const uint8_t *)"peer DHKey check", - BT_OCTET16_LEN); + smp_debug_print_nbyte_little_endian( + param_buf, (const uint8_t*)"peer DHKey check", BT_OCTET16_LEN); #endif - key.key_type = SMP_KEY_TYPE_PEER_DHK_CHCK; - key.p_data = param_buf; - smp_sm_event(p_cb, SMP_SC_KEY_READY_EVT, &key); - } - else - { - SMP_TRACE_EVENT ("peer DHKey check calculation failed"); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); - } + key.key_type = SMP_KEY_TYPE_PEER_DHK_CHCK; + key.p_data = param_buf; + smp_sm_event(p_cb, SMP_SC_KEY_READY_EVT, &key); + } else { + SMP_TRACE_EVENT("peer DHKey check calculation failed"); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status); + } } /******************************************************************************* @@ -1818,73 +1745,78 @@ void smp_calculate_peer_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) * the AES-CMAC input/output stream. * ******************************************************************************/ -bool smp_calculate_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r, uint8_t *iocap, uint8_t *a1, - uint8_t *a2, uint8_t *c) -{ - uint8_t *p = NULL; - uint8_t msg_len = BT_OCTET16_LEN /* N1 size */ + BT_OCTET16_LEN /* N2 size */ + - BT_OCTET16_LEN /* R size */ + 3 /* IOcap size */ + 7 /* A1 size*/ - + 7 /* A2 size*/; - uint8_t msg[BT_OCTET16_LEN + BT_OCTET16_LEN + BT_OCTET16_LEN + 3 + 7 + 7]; +bool smp_calculate_f6(uint8_t* w, uint8_t* n1, uint8_t* n2, uint8_t* r, + uint8_t* iocap, uint8_t* a1, uint8_t* a2, uint8_t* c) { + uint8_t* p = NULL; + uint8_t msg_len = BT_OCTET16_LEN /* N1 size */ + + BT_OCTET16_LEN /* N2 size */ + BT_OCTET16_LEN /* R size */ + + 3 /* IOcap size */ + 7 /* A1 size*/ + + 7 /* A2 size*/; + uint8_t msg[BT_OCTET16_LEN + BT_OCTET16_LEN + BT_OCTET16_LEN + 3 + 7 + 7]; #if (SMP_DEBUG == TRUE) - uint8_t *p_print = NULL; + uint8_t* p_print = NULL; #endif - SMP_TRACE_DEBUG ("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_print = w; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"W", BT_OCTET16_LEN); - p_print = n1; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"N1", BT_OCTET16_LEN); - p_print = n2; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"N2", BT_OCTET16_LEN); - p_print = r; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"R", BT_OCTET16_LEN); - p_print = iocap; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"IOcap", 3); - p_print = a1; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"A1", 7); - p_print = a2; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"A2", 7); + p_print = w; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"W", + BT_OCTET16_LEN); + p_print = n1; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"N1", + BT_OCTET16_LEN); + p_print = n2; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"N2", + BT_OCTET16_LEN); + p_print = r; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"R", + BT_OCTET16_LEN); + p_print = iocap; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"IOcap", 3); + p_print = a1; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"A1", 7); + p_print = a2; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"A2", 7); #endif - uint8_t cmac[BT_OCTET16_LEN]; - uint8_t key[BT_OCTET16_LEN]; + uint8_t cmac[BT_OCTET16_LEN]; + uint8_t key[BT_OCTET16_LEN]; - p = key; - ARRAY_TO_STREAM(p, w, BT_OCTET16_LEN); + p = key; + ARRAY_TO_STREAM(p, w, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_print = key; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"K", BT_OCTET16_LEN); + p_print = key; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"K", + BT_OCTET16_LEN); #endif - p = msg; - ARRAY_TO_STREAM(p, a2, 7); - ARRAY_TO_STREAM(p, a1, 7); - ARRAY_TO_STREAM(p, iocap, 3); - ARRAY_TO_STREAM(p, r, BT_OCTET16_LEN); - ARRAY_TO_STREAM(p, n2, BT_OCTET16_LEN); - ARRAY_TO_STREAM(p, n1, BT_OCTET16_LEN); + p = msg; + ARRAY_TO_STREAM(p, a2, 7); + ARRAY_TO_STREAM(p, a1, 7); + ARRAY_TO_STREAM(p, iocap, 3); + ARRAY_TO_STREAM(p, r, BT_OCTET16_LEN); + ARRAY_TO_STREAM(p, n2, BT_OCTET16_LEN); + ARRAY_TO_STREAM(p, n1, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_print = msg; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"M", msg_len); + p_print = msg; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"M", msg_len); #endif - bool ret = true; - if(!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) - { - SMP_TRACE_ERROR("%s failed", __func__); - ret = false; - } + bool ret = true; + if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) { + SMP_TRACE_ERROR("%s failed", __func__); + ret = false; + } #if (SMP_DEBUG == TRUE) - p_print = cmac; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"AES-CMAC", BT_OCTET16_LEN); + p_print = cmac; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"AES-CMAC", + BT_OCTET16_LEN); #endif - p = c; - ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); - return ret; + p = c; + ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); + return ret; } /******************************************************************************* @@ -1897,97 +1829,84 @@ bool smp_calculate_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r, uint8 * Returns false if out of resources, true in other cases. * ******************************************************************************/ -bool smp_calculate_link_key_from_long_term_key(tSMP_CB *p_cb) -{ - tBTM_SEC_DEV_REC *p_dev_rec; - BD_ADDR bda_for_lk; - tBLE_ADDR_TYPE conn_addr_type; - - SMP_TRACE_DEBUG ("%s", __func__); - - if (p_cb->id_addr_rcvd && p_cb->id_addr_type == BLE_ADDR_PUBLIC) - { - SMP_TRACE_DEBUG ("Use rcvd identity address as BD_ADDR of LK rcvd identity address"); - memcpy(bda_for_lk, p_cb->id_addr, BD_ADDR_LEN); - } - else if ((BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda_for_lk, &conn_addr_type)) && - conn_addr_type == BLE_ADDR_PUBLIC) - { - SMP_TRACE_DEBUG ("Use rcvd connection address as BD_ADDR of LK"); - } - else - { - SMP_TRACE_WARNING ("Don't have peer public address to associate with LK"); - return false; - } - - p_dev_rec = btm_find_dev(p_cb->pairing_bda); - if (p_dev_rec == NULL) - { - SMP_TRACE_ERROR("%s failed to find Security Record", __func__); - return false; - } - - BT_OCTET16 intermediate_link_key; - bool ret = true; - - ret = smp_calculate_h6(p_cb->ltk, (uint8_t *)"1pmt" /* reversed "tmp1" */,intermediate_link_key); - if (!ret) - { - SMP_TRACE_ERROR("%s failed to derive intermediate_link_key", __func__); - return ret; - } - - BT_OCTET16 link_key; - ret = smp_calculate_h6(intermediate_link_key, (uint8_t *) "rbel" /* reversed "lebr" */, link_key); - if (!ret) - { - SMP_TRACE_ERROR("%s failed", __func__); - } - else - { - uint8_t link_key_type; - if (btm_cb.security_mode == BTM_SEC_MODE_SC) - { - /* Secure Connections Only Mode */ - link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256; - } - else if (controller_get_interface()->supports_secure_connections()) - { - /* both transports are SC capable */ - if (p_cb->sec_level == SMP_SEC_AUTHENTICATED) - link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256; - else - link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB_P_256; - } - else if (btm_cb.security_mode == BTM_SEC_MODE_SP) - { - /* BR/EDR transport is SSP capable */ - if (p_cb->sec_level == SMP_SEC_AUTHENTICATED) - link_key_type = BTM_LKEY_TYPE_AUTH_COMB; - else - link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB; - } - else - { - SMP_TRACE_ERROR ("%s failed to update link_key. Sec Mode = %d, sm4 = 0x%02x", - __func__, btm_cb.security_mode, p_dev_rec->sm4); - return false; - } - - link_key_type += BTM_LTK_DERIVED_LKEY_OFFSET; - - uint8_t *p; - BT_OCTET16 notif_link_key; - p = notif_link_key; - ARRAY16_TO_STREAM(p, link_key); - - btm_sec_link_key_notification (bda_for_lk, notif_link_key, link_key_type); - - SMP_TRACE_EVENT ("%s is completed", __func__); - } - +bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) { + tBTM_SEC_DEV_REC* p_dev_rec; + BD_ADDR bda_for_lk; + tBLE_ADDR_TYPE conn_addr_type; + + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->id_addr_rcvd && p_cb->id_addr_type == BLE_ADDR_PUBLIC) { + SMP_TRACE_DEBUG( + "Use rcvd identity address as BD_ADDR of LK rcvd identity address"); + memcpy(bda_for_lk, p_cb->id_addr, BD_ADDR_LEN); + } else if ((BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda_for_lk, + &conn_addr_type)) && + conn_addr_type == BLE_ADDR_PUBLIC) { + SMP_TRACE_DEBUG("Use rcvd connection address as BD_ADDR of LK"); + } else { + SMP_TRACE_WARNING("Don't have peer public address to associate with LK"); + return false; + } + + p_dev_rec = btm_find_dev(p_cb->pairing_bda); + if (p_dev_rec == NULL) { + SMP_TRACE_ERROR("%s failed to find Security Record", __func__); + return false; + } + + BT_OCTET16 intermediate_link_key; + bool ret = true; + + ret = smp_calculate_h6(p_cb->ltk, (uint8_t*)"1pmt" /* reversed "tmp1" */, + intermediate_link_key); + if (!ret) { + SMP_TRACE_ERROR("%s failed to derive intermediate_link_key", __func__); return ret; + } + + BT_OCTET16 link_key; + ret = smp_calculate_h6(intermediate_link_key, + (uint8_t*)"rbel" /* reversed "lebr" */, link_key); + if (!ret) { + SMP_TRACE_ERROR("%s failed", __func__); + } else { + uint8_t link_key_type; + if (btm_cb.security_mode == BTM_SEC_MODE_SC) { + /* Secure Connections Only Mode */ + link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256; + } else if (controller_get_interface()->supports_secure_connections()) { + /* both transports are SC capable */ + if (p_cb->sec_level == SMP_SEC_AUTHENTICATED) + link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256; + else + link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB_P_256; + } else if (btm_cb.security_mode == BTM_SEC_MODE_SP) { + /* BR/EDR transport is SSP capable */ + if (p_cb->sec_level == SMP_SEC_AUTHENTICATED) + link_key_type = BTM_LKEY_TYPE_AUTH_COMB; + else + link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB; + } else { + SMP_TRACE_ERROR( + "%s failed to update link_key. Sec Mode = %d, sm4 = 0x%02x", __func__, + btm_cb.security_mode, p_dev_rec->sm4); + return false; + } + + link_key_type += BTM_LTK_DERIVED_LKEY_OFFSET; + + uint8_t* p; + BT_OCTET16 notif_link_key; + p = notif_link_key; + ARRAY16_TO_STREAM(p, link_key); + + btm_sec_link_key_notification(bda_for_lk, notif_link_key, link_key_type); + + SMP_TRACE_EVENT("%s is completed", __func__); + } + + return ret; } /******************************************************************************* @@ -2000,70 +1919,63 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB *p_cb) * Returns false if out of resources, true in other cases. * ******************************************************************************/ -bool smp_calculate_long_term_key_from_link_key(tSMP_CB *p_cb) -{ - bool ret = true; - tBTM_SEC_DEV_REC *p_dev_rec; - uint8_t rev_link_key[16]; - - SMP_TRACE_DEBUG ("%s", __func__); - - p_dev_rec = btm_find_dev(p_cb->pairing_bda); - if (p_dev_rec == NULL) - { - SMP_TRACE_ERROR("%s failed to find Security Record",__func__); - return false; - } - - uint8_t br_link_key_type; - br_link_key_type = BTM_SecGetDeviceLinkKeyType(p_cb->pairing_bda); - if (br_link_key_type == BTM_LKEY_TYPE_IGNORE) - { - SMP_TRACE_ERROR("%s failed to retrieve BR link type",__func__); - return false; - } - - if ((br_link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256) && - (br_link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) - { - SMP_TRACE_ERROR("%s LE SC LTK can't be derived from LK %d", - __func__, br_link_key_type); - return false; - } - - uint8_t *p1; - uint8_t *p2; - p1 = rev_link_key; - p2 = p_dev_rec->link_key; - REVERSE_ARRAY_TO_STREAM(p1, p2, 16); - - BT_OCTET16 intermediate_long_term_key; - /* "tmp2" obtained from the spec */ - ret = smp_calculate_h6(rev_link_key, (uint8_t *) "2pmt" /* reversed "tmp2" */, - intermediate_long_term_key); - - if (!ret) - { - SMP_TRACE_ERROR("%s failed to derive intermediate_long_term_key",__func__); - return ret; - } - - /* "brle" obtained from the spec */ - ret = smp_calculate_h6(intermediate_long_term_key, (uint8_t *) "elrb" /* reversed "brle" */, - p_cb->ltk); - - if (!ret) - { - SMP_TRACE_ERROR("%s failed",__func__); - } - else - { - p_cb->sec_level = (br_link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) - ? SMP_SEC_AUTHENTICATED : SMP_SEC_UNAUTHENTICATE; - SMP_TRACE_EVENT ("%s is completed",__func__); - } - +bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) { + bool ret = true; + tBTM_SEC_DEV_REC* p_dev_rec; + uint8_t rev_link_key[16]; + + SMP_TRACE_DEBUG("%s", __func__); + + p_dev_rec = btm_find_dev(p_cb->pairing_bda); + if (p_dev_rec == NULL) { + SMP_TRACE_ERROR("%s failed to find Security Record", __func__); + return false; + } + + uint8_t br_link_key_type; + br_link_key_type = BTM_SecGetDeviceLinkKeyType(p_cb->pairing_bda); + if (br_link_key_type == BTM_LKEY_TYPE_IGNORE) { + SMP_TRACE_ERROR("%s failed to retrieve BR link type", __func__); + return false; + } + + if ((br_link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256) && + (br_link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) { + SMP_TRACE_ERROR("%s LE SC LTK can't be derived from LK %d", __func__, + br_link_key_type); + return false; + } + + uint8_t* p1; + uint8_t* p2; + p1 = rev_link_key; + p2 = p_dev_rec->link_key; + REVERSE_ARRAY_TO_STREAM(p1, p2, 16); + + BT_OCTET16 intermediate_long_term_key; + /* "tmp2" obtained from the spec */ + ret = smp_calculate_h6(rev_link_key, (uint8_t*)"2pmt" /* reversed "tmp2" */, + intermediate_long_term_key); + + if (!ret) { + SMP_TRACE_ERROR("%s failed to derive intermediate_long_term_key", __func__); return ret; + } + + /* "brle" obtained from the spec */ + ret = smp_calculate_h6(intermediate_long_term_key, + (uint8_t*)"elrb" /* reversed "brle" */, p_cb->ltk); + + if (!ret) { + SMP_TRACE_ERROR("%s failed", __func__); + } else { + p_cb->sec_level = (br_link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256) + ? SMP_SEC_AUTHENTICATED + : SMP_SEC_UNAUTHENTICATE; + SMP_TRACE_EVENT("%s is completed", __func__); + } + + return ret; } /******************************************************************************* @@ -2084,58 +1996,59 @@ bool smp_calculate_long_term_key_from_link_key(tSMP_CB *p_cb) * the AES-CMAC input/output stream. * ******************************************************************************/ -bool smp_calculate_h6(uint8_t *w, uint8_t *keyid, uint8_t *c) -{ +bool smp_calculate_h6(uint8_t* w, uint8_t* keyid, uint8_t* c) { #if (SMP_DEBUG == TRUE) - uint8_t *p_print = NULL; + uint8_t* p_print = NULL; #endif - SMP_TRACE_DEBUG ("%s",__func__); + SMP_TRACE_DEBUG("%s", __func__); #if (SMP_DEBUG == TRUE) - p_print = w; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"W", BT_OCTET16_LEN); - p_print = keyid; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"keyID", 4); + p_print = w; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"W", + BT_OCTET16_LEN); + p_print = keyid; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"keyID", 4); #endif - uint8_t *p = NULL; - uint8_t key[BT_OCTET16_LEN]; + uint8_t* p = NULL; + uint8_t key[BT_OCTET16_LEN]; - p = key; - ARRAY_TO_STREAM(p, w, BT_OCTET16_LEN); + p = key; + ARRAY_TO_STREAM(p, w, BT_OCTET16_LEN); #if (SMP_DEBUG == TRUE) - p_print = key; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"K", BT_OCTET16_LEN); + p_print = key; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"K", + BT_OCTET16_LEN); #endif - uint8_t msg_len = 4 /* KeyID size */; - uint8_t msg[4]; + uint8_t msg_len = 4 /* KeyID size */; + uint8_t msg[4]; - p = msg; - ARRAY_TO_STREAM(p, keyid, 4); + p = msg; + ARRAY_TO_STREAM(p, keyid, 4); #if (SMP_DEBUG == TRUE) - p_print = msg; - smp_debug_print_nbyte_little_endian (p_print,(const uint8_t *) "M", msg_len); + p_print = msg; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"M", msg_len); #endif - bool ret = true; - uint8_t cmac[BT_OCTET16_LEN]; - if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) - { - SMP_TRACE_ERROR("%s failed",__func__); - ret = false; - } + bool ret = true; + uint8_t cmac[BT_OCTET16_LEN]; + if (!aes_cipher_msg_auth_code(key, msg, msg_len, BT_OCTET16_LEN, cmac)) { + SMP_TRACE_ERROR("%s failed", __func__); + ret = false; + } #if (SMP_DEBUG == TRUE) - p_print = cmac; - smp_debug_print_nbyte_little_endian (p_print, (const uint8_t *)"AES-CMAC", BT_OCTET16_LEN); + p_print = cmac; + smp_debug_print_nbyte_little_endian(p_print, (const uint8_t*)"AES-CMAC", + BT_OCTET16_LEN); #endif - p = c; - ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); - return ret; + p = c; + ARRAY_TO_STREAM(p, cmac, BT_OCTET16_LEN); + return ret; } /******************************************************************************* @@ -2147,11 +2060,10 @@ bool smp_calculate_h6(uint8_t *w, uint8_t *keyid, uint8_t *c) * Returns void * ******************************************************************************/ -void smp_start_nonce_generation(tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_NONCE_0_7; - btsnd_hcic_ble_rand((void *)smp_rand_back); +void smp_start_nonce_generation(tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_NONCE_0_7; + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -2163,11 +2075,10 @@ void smp_start_nonce_generation(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_finish_nonce_generation(tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG("%s", __func__); - p_cb->rand_enc_proc_state = SMP_GEN_NONCE_8_15; - btsnd_hcic_ble_rand((void *)smp_rand_back); +void smp_finish_nonce_generation(tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s", __func__); + p_cb->rand_enc_proc_state = SMP_GEN_NONCE_8_15; + btsnd_hcic_ble_rand((void*)smp_rand_back); } /******************************************************************************* @@ -2179,10 +2090,9 @@ void smp_finish_nonce_generation(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_process_new_nonce(tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG ("%s round %d", __func__, p_cb->round); - smp_sm_event(p_cb, SMP_HAVE_LOC_NONCE_EVT, NULL); +void smp_process_new_nonce(tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s round %d", __func__, p_cb->round); + smp_sm_event(p_cb, SMP_HAVE_LOC_NONCE_EVT, NULL); } /******************************************************************************* @@ -2195,68 +2105,66 @@ void smp_process_new_nonce(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -static void smp_rand_back(tBTM_RAND_ENC *p) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t *pp = p->param_buf; - uint8_t failure = SMP_PAIR_FAIL_UNKNOWN; - uint8_t state = p_cb->rand_enc_proc_state & ~0x80; - - SMP_TRACE_DEBUG ("%s state=0x%x", __func__, state); - if (p && p->status == HCI_SUCCESS) - { - switch (state) - { - case SMP_GEN_SRAND_MRAND: - memcpy((void *)p_cb->rand, p->param_buf, p->param_len); - smp_generate_rand_cont(p_cb, NULL); - break; - - case SMP_GEN_SRAND_MRAND_CONT: - memcpy((void *)&p_cb->rand[8], p->param_buf, p->param_len); - smp_generate_confirm(p_cb, NULL); - break; - - case SMP_GEN_DIV_LTK: - STREAM_TO_UINT16(p_cb->div, pp); - smp_generate_ltk_cont(p_cb, NULL); - break; - - case SMP_GEN_DIV_CSRK: - STREAM_TO_UINT16(p_cb->div, pp); - smp_compute_csrk(p_cb, NULL); - break; - - case SMP_GEN_TK: - smp_proc_passkey(p_cb, p); - break; - - case SMP_GEN_RAND_V: - memcpy(p_cb->enc_rand, p->param_buf, BT_OCTET8_LEN); - smp_generate_y(p_cb, NULL); - break; - - case SMP_GENERATE_PRIVATE_KEY_0_7: - case SMP_GENERATE_PRIVATE_KEY_8_15: - case SMP_GENERATE_PRIVATE_KEY_16_23: - case SMP_GENERATE_PRIVATE_KEY_24_31: - smp_continue_private_key_creation(p_cb, p); - break; - - case SMP_GEN_NONCE_0_7: - memcpy((void *)p_cb->rand, p->param_buf, p->param_len); - smp_finish_nonce_generation(p_cb); - break; - - case SMP_GEN_NONCE_8_15: - memcpy((void *)&p_cb->rand[8], p->param_buf, p->param_len); - smp_process_new_nonce(p_cb); - break; - } - - return; +static void smp_rand_back(tBTM_RAND_ENC* p) { + tSMP_CB* p_cb = &smp_cb; + uint8_t* pp = p->param_buf; + uint8_t failure = SMP_PAIR_FAIL_UNKNOWN; + uint8_t state = p_cb->rand_enc_proc_state & ~0x80; + + SMP_TRACE_DEBUG("%s state=0x%x", __func__, state); + if (p && p->status == HCI_SUCCESS) { + switch (state) { + case SMP_GEN_SRAND_MRAND: + memcpy((void*)p_cb->rand, p->param_buf, p->param_len); + smp_generate_rand_cont(p_cb, NULL); + break; + + case SMP_GEN_SRAND_MRAND_CONT: + memcpy((void*)&p_cb->rand[8], p->param_buf, p->param_len); + smp_generate_confirm(p_cb, NULL); + break; + + case SMP_GEN_DIV_LTK: + STREAM_TO_UINT16(p_cb->div, pp); + smp_generate_ltk_cont(p_cb, NULL); + break; + + case SMP_GEN_DIV_CSRK: + STREAM_TO_UINT16(p_cb->div, pp); + smp_compute_csrk(p_cb, NULL); + break; + + case SMP_GEN_TK: + smp_proc_passkey(p_cb, p); + break; + + case SMP_GEN_RAND_V: + memcpy(p_cb->enc_rand, p->param_buf, BT_OCTET8_LEN); + smp_generate_y(p_cb, NULL); + break; + + case SMP_GENERATE_PRIVATE_KEY_0_7: + case SMP_GENERATE_PRIVATE_KEY_8_15: + case SMP_GENERATE_PRIVATE_KEY_16_23: + case SMP_GENERATE_PRIVATE_KEY_24_31: + smp_continue_private_key_creation(p_cb, p); + break; + + case SMP_GEN_NONCE_0_7: + memcpy((void*)p_cb->rand, p->param_buf, p->param_len); + smp_finish_nonce_generation(p_cb); + break; + + case SMP_GEN_NONCE_8_15: + memcpy((void*)&p_cb->rand[8], p->param_buf, p->param_len); + smp_process_new_nonce(p_cb); + break; } - SMP_TRACE_ERROR("%s key generation failed: (%d)", __func__, p_cb->rand_enc_proc_state); - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + return; + } + + SMP_TRACE_ERROR("%s key generation failed: (%d)", __func__, + p_cb->rand_enc_proc_state); + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); } diff --git a/stack/smp/smp_l2c.cc b/stack/smp/smp_l2c.cc index de571b06e..98ac52d2c 100644 --- a/stack/smp/smp_l2c.cc +++ b/stack/smp/smp_l2c.cc @@ -30,18 +30,20 @@ #include "smp_int.h" - -extern fixed_queue_t *btu_general_alarm_queue; +extern fixed_queue_t* btu_general_alarm_queue; static void smp_tx_complete_callback(uint16_t cid, uint16_t num_pkt); -static void smp_connect_callback(uint16_t channel, BD_ADDR bd_addr, bool connected, uint16_t reason, - tBT_TRANSPORT transport); -static void smp_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_buf); +static void smp_connect_callback(uint16_t channel, BD_ADDR bd_addr, + bool connected, uint16_t reason, + tBT_TRANSPORT transport); +static void smp_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR* p_buf); -static void smp_br_connect_callback(uint16_t channel, BD_ADDR bd_addr, bool connected, uint16_t reason, +static void smp_br_connect_callback(uint16_t channel, BD_ADDR bd_addr, + bool connected, uint16_t reason, tBT_TRANSPORT transport); -static void smp_br_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_buf); +static void smp_br_data_received(uint16_t channel, BD_ADDR bd_addr, + BT_HDR* p_buf); /******************************************************************************* * @@ -51,30 +53,31 @@ static void smp_br_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_bu * to register interface functions with L2CAP. * ******************************************************************************/ -void smp_l2cap_if_init (void) -{ - tL2CAP_FIXED_CHNL_REG fixed_reg; - SMP_TRACE_EVENT ("SMDBG l2c %s", __func__); - fixed_reg.fixed_chnl_opts.mode = L2CAP_FCR_BASIC_MODE; - fixed_reg.fixed_chnl_opts.max_transmit = 0; - fixed_reg.fixed_chnl_opts.rtrans_tout = 0; - fixed_reg.fixed_chnl_opts.mon_tout = 0; - fixed_reg.fixed_chnl_opts.mps = 0; - fixed_reg.fixed_chnl_opts.tx_win_sz = 0; - - fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback; - fixed_reg.pL2CA_FixedData_Cb = smp_data_received; - fixed_reg.pL2CA_FixedTxComplete_Cb = smp_tx_complete_callback; - - fixed_reg.pL2CA_FixedCong_Cb = NULL; /* do not handle congestion on this channel */ - fixed_reg.default_idle_tout = 60; /* set 60 seconds timeout, 0xffff default idle timeout */ - - L2CA_RegisterFixedChannel (L2CAP_SMP_CID, &fixed_reg); - - fixed_reg.pL2CA_FixedConn_Cb = smp_br_connect_callback; - fixed_reg.pL2CA_FixedData_Cb = smp_br_data_received; - - L2CA_RegisterFixedChannel (L2CAP_SMP_BR_CID, &fixed_reg); +void smp_l2cap_if_init(void) { + tL2CAP_FIXED_CHNL_REG fixed_reg; + SMP_TRACE_EVENT("SMDBG l2c %s", __func__); + fixed_reg.fixed_chnl_opts.mode = L2CAP_FCR_BASIC_MODE; + fixed_reg.fixed_chnl_opts.max_transmit = 0; + fixed_reg.fixed_chnl_opts.rtrans_tout = 0; + fixed_reg.fixed_chnl_opts.mon_tout = 0; + fixed_reg.fixed_chnl_opts.mps = 0; + fixed_reg.fixed_chnl_opts.tx_win_sz = 0; + + fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback; + fixed_reg.pL2CA_FixedData_Cb = smp_data_received; + fixed_reg.pL2CA_FixedTxComplete_Cb = smp_tx_complete_callback; + + fixed_reg.pL2CA_FixedCong_Cb = + NULL; /* do not handle congestion on this channel */ + fixed_reg.default_idle_tout = + 60; /* set 60 seconds timeout, 0xffff default idle timeout */ + + L2CA_RegisterFixedChannel(L2CAP_SMP_CID, &fixed_reg); + + fixed_reg.pL2CA_FixedConn_Cb = smp_br_connect_callback; + fixed_reg.pL2CA_FixedData_Cb = smp_br_data_received; + + L2CA_RegisterFixedChannel(L2CAP_SMP_BR_CID, &fixed_reg); } /******************************************************************************* @@ -86,48 +89,44 @@ void smp_l2cap_if_init (void) * connected (conn = true)/disconnected (conn = false). * ******************************************************************************/ -static void smp_connect_callback (uint16_t channel, BD_ADDR bd_addr, bool connected, uint16_t reason, - tBT_TRANSPORT transport) -{ - tSMP_CB *p_cb = &smp_cb; - tSMP_INT_DATA int_data; - BD_ADDR dummy_bda = {0}; - - SMP_TRACE_EVENT ("SMDBG l2c %s", __func__); - - if (transport == BT_TRANSPORT_BR_EDR || memcmp(bd_addr, dummy_bda, BD_ADDR_LEN) == 0) - return; - - if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) == 0) - { - SMP_TRACE_EVENT ("%s() for pairing BDA: %08x%04x Event: %s", - __func__, - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8) + bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], - (connected) ? "connected" : "disconnected"); - - if (connected) - { - if(!p_cb->connect_initialized) - { - p_cb->connect_initialized = true; - /* initiating connection established */ - p_cb->role = L2CA_GetBleConnRole(bd_addr); - - /* initialize local i/r key to be default keys */ - p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY; - p_cb->loc_auth_req = p_cb->peer_auth_req = SMP_DEFAULT_AUTH_REQ; - p_cb->cb_evt = SMP_IO_CAP_REQ_EVT; - smp_sm_event(p_cb, SMP_L2CAP_CONN_EVT, NULL); - } - } - else - { - int_data.reason = reason; - /* Disconnected while doing security */ - smp_sm_event(p_cb, SMP_L2CAP_DISCONN_EVT, &int_data); - } +static void smp_connect_callback(uint16_t channel, BD_ADDR bd_addr, + bool connected, uint16_t reason, + tBT_TRANSPORT transport) { + tSMP_CB* p_cb = &smp_cb; + tSMP_INT_DATA int_data; + BD_ADDR dummy_bda = {0}; + + SMP_TRACE_EVENT("SMDBG l2c %s", __func__); + + if (transport == BT_TRANSPORT_BR_EDR || + memcmp(bd_addr, dummy_bda, BD_ADDR_LEN) == 0) + return; + + if (memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) == 0) { + SMP_TRACE_EVENT("%s() for pairing BDA: %08x%04x Event: %s", __func__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], + (connected) ? "connected" : "disconnected"); + + if (connected) { + if (!p_cb->connect_initialized) { + p_cb->connect_initialized = true; + /* initiating connection established */ + p_cb->role = L2CA_GetBleConnRole(bd_addr); + + /* initialize local i/r key to be default keys */ + p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY; + p_cb->loc_auth_req = p_cb->peer_auth_req = SMP_DEFAULT_AUTH_REQ; + p_cb->cb_evt = SMP_IO_CAP_REQ_EVT; + smp_sm_event(p_cb, SMP_L2CAP_CONN_EVT, NULL); + } + } else { + int_data.reason = reason; + /* Disconnected while doing security */ + smp_sm_event(p_cb, SMP_L2CAP_DISCONN_EVT, &int_data); } + } } /******************************************************************************* @@ -141,66 +140,60 @@ static void smp_connect_callback (uint16_t channel, BD_ADDR bd_addr, bool con * Returns void * ******************************************************************************/ -static void smp_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_buf) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint8_t cmd ; - SMP_TRACE_EVENT ("SMDBG l2c %s", __func__); - - STREAM_TO_UINT8(cmd, p); - - /* sanity check */ - if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) - { - SMP_TRACE_WARNING( "Ignore received command with RESERVED code 0x%02x", cmd); - osi_free(p_buf); - return; +static void smp_data_received(uint16_t channel, BD_ADDR bd_addr, + BT_HDR* p_buf) { + tSMP_CB* p_cb = &smp_cb; + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint8_t cmd; + SMP_TRACE_EVENT("SMDBG l2c %s", __func__); + + STREAM_TO_UINT8(cmd, p); + + /* sanity check */ + if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) { + SMP_TRACE_WARNING("Ignore received command with RESERVED code 0x%02x", cmd); + osi_free(p_buf); + return; + } + + /* reject the pairing request if there is an on-going SMP pairing */ + if (SMP_OPCODE_PAIRING_REQ == cmd || SMP_OPCODE_SEC_REQ == cmd) { + if ((p_cb->state == SMP_STATE_IDLE) && + (p_cb->br_state == SMP_BR_STATE_IDLE) && + !(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) { + p_cb->role = L2CA_GetBleConnRole(bd_addr); + memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN); + } else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) { + osi_free(p_buf); + smp_reject_unexpected_pairing_command(bd_addr); + return; } - - /* reject the pairing request if there is an on-going SMP pairing */ - if (SMP_OPCODE_PAIRING_REQ == cmd || SMP_OPCODE_SEC_REQ == cmd) - { - if ((p_cb->state == SMP_STATE_IDLE) && (p_cb->br_state == SMP_BR_STATE_IDLE) && - !(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) - { - p_cb->role = L2CA_GetBleConnRole(bd_addr); - memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN); - } - else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) - { - osi_free(p_buf); - smp_reject_unexpected_pairing_command(bd_addr); - return; - } - /* else, out of state pairing request/security request received, passed into SM */ + /* else, out of state pairing request/security request received, passed into + * SM */ + } + + if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0) { + alarm_set_on_queue(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, + smp_rsp_timeout, NULL, btu_general_alarm_queue); + + if (cmd == SMP_OPCODE_CONFIRM) { + SMP_TRACE_DEBUG( + "in %s cmd = 0x%02x, peer_auth_req = 0x%02x," + "loc_auth_req = 0x%02x", + __func__, cmd, p_cb->peer_auth_req, p_cb->loc_auth_req); + + if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) && + (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) { + cmd = SMP_OPCODE_PAIR_COMMITM; + } } - if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0) - { - alarm_set_on_queue(p_cb->smp_rsp_timer_ent, - SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL, - btu_general_alarm_queue); - - if (cmd == SMP_OPCODE_CONFIRM) - { - SMP_TRACE_DEBUG ("in %s cmd = 0x%02x, peer_auth_req = 0x%02x," - "loc_auth_req = 0x%02x", - __func__, cmd, p_cb->peer_auth_req, p_cb->loc_auth_req); - - if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) && - (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) - { - cmd = SMP_OPCODE_PAIR_COMMITM; - } - } - - p_cb->rcvd_cmd_code = cmd; - p_cb->rcvd_cmd_len = (uint8_t) p_buf->len; - smp_sm_event(p_cb, cmd, p); - } + p_cb->rcvd_cmd_code = cmd; + p_cb->rcvd_cmd_len = (uint8_t)p_buf->len; + smp_sm_event(p_cb, cmd, p); + } - osi_free(p_buf); + osi_free(p_buf); } /******************************************************************************* @@ -210,23 +203,21 @@ static void smp_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_buf) * Description SMP channel tx complete callback * ******************************************************************************/ -static void smp_tx_complete_callback (uint16_t cid, uint16_t num_pkt) -{ - tSMP_CB *p_cb = &smp_cb; - - if (p_cb->total_tx_unacked >= num_pkt) - p_cb->total_tx_unacked -= num_pkt; +static void smp_tx_complete_callback(uint16_t cid, uint16_t num_pkt) { + tSMP_CB* p_cb = &smp_cb; + + if (p_cb->total_tx_unacked >= num_pkt) + p_cb->total_tx_unacked -= num_pkt; + else + SMP_TRACE_ERROR("Unexpected %s: num_pkt = %d", __func__, num_pkt); + + uint8_t reason = SMP_SUCCESS; + if (p_cb->total_tx_unacked == 0 && p_cb->wait_for_authorization_complete) { + if (cid == L2CAP_SMP_CID) + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); else - SMP_TRACE_ERROR("Unexpected %s: num_pkt = %d", __func__,num_pkt); - - uint8_t reason = SMP_SUCCESS; - if (p_cb->total_tx_unacked == 0 && p_cb->wait_for_authorization_complete) - { - if (cid == L2CAP_SMP_CID) - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason); - else - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); - } + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason); + } } /******************************************************************************* @@ -238,48 +229,42 @@ static void smp_tx_complete_callback (uint16_t cid, uint16_t num_pkt) * connected (conn = true)/disconnected (conn = false). * ******************************************************************************/ -static void smp_br_connect_callback(uint16_t channel, BD_ADDR bd_addr, bool connected, - uint16_t reason, tBT_TRANSPORT transport) -{ - tSMP_CB *p_cb = &smp_cb; - tSMP_INT_DATA int_data; - - SMP_TRACE_EVENT ("%s", __func__); - - if (transport != BT_TRANSPORT_BR_EDR) - { - SMP_TRACE_WARNING("%s is called on unexpected transport %d", - __func__, transport); - return; - } - - if (!(memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) == 0)) - return; - - SMP_TRACE_EVENT ("%s for pairing BDA: %08x%04x Event: %s", - __func__, - (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8) + bd_addr[3], - (bd_addr[4]<<8)+bd_addr[5], - (connected) ? "connected" : "disconnected"); - - if (connected) - { - if(!p_cb->connect_initialized) - { - p_cb->connect_initialized = true; - /* initialize local i/r key to be default keys */ - p_cb->local_r_key = p_cb->local_i_key = SMP_BR_SEC_DEFAULT_KEY; - p_cb->loc_auth_req = p_cb->peer_auth_req = 0; - p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; - smp_br_state_machine_event(p_cb, SMP_BR_L2CAP_CONN_EVT, NULL); - } - } - else - { - int_data.reason = reason; - /* Disconnected while doing security */ - smp_br_state_machine_event(p_cb, SMP_BR_L2CAP_DISCONN_EVT, &int_data); +static void smp_br_connect_callback(uint16_t channel, BD_ADDR bd_addr, + bool connected, uint16_t reason, + tBT_TRANSPORT transport) { + tSMP_CB* p_cb = &smp_cb; + tSMP_INT_DATA int_data; + + SMP_TRACE_EVENT("%s", __func__); + + if (transport != BT_TRANSPORT_BR_EDR) { + SMP_TRACE_WARNING("%s is called on unexpected transport %d", __func__, + transport); + return; + } + + if (!(memcmp(bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) == 0)) return; + + SMP_TRACE_EVENT( + "%s for pairing BDA: %08x%04x Event: %s", __func__, + (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3], + (bd_addr[4] << 8) + bd_addr[5], + (connected) ? "connected" : "disconnected"); + + if (connected) { + if (!p_cb->connect_initialized) { + p_cb->connect_initialized = true; + /* initialize local i/r key to be default keys */ + p_cb->local_r_key = p_cb->local_i_key = SMP_BR_SEC_DEFAULT_KEY; + p_cb->loc_auth_req = p_cb->peer_auth_req = 0; + p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT; + smp_br_state_machine_event(p_cb, SMP_BR_L2CAP_CONN_EVT, NULL); } + } else { + int_data.reason = reason; + /* Disconnected while doing security */ + smp_br_state_machine_event(p_cb, SMP_BR_L2CAP_DISCONN_EVT, &int_data); + } } /******************************************************************************* @@ -292,51 +277,45 @@ static void smp_br_connect_callback(uint16_t channel, BD_ADDR bd_addr, bool c * Returns void * ******************************************************************************/ -static void smp_br_data_received(uint16_t channel, BD_ADDR bd_addr, BT_HDR *p_buf) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset; - uint8_t cmd ; - SMP_TRACE_EVENT ("SMDBG l2c %s", __func__); - - STREAM_TO_UINT8(cmd, p); - - /* sanity check */ - if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) - { - SMP_TRACE_WARNING( "Ignore received command with RESERVED code 0x%02x", cmd); - osi_free(p_buf); - return; - } - - /* reject the pairing request if there is an on-going SMP pairing */ - if (SMP_OPCODE_PAIRING_REQ == cmd) - { - if ((p_cb->state == SMP_STATE_IDLE) && (p_cb->br_state == SMP_BR_STATE_IDLE)) - { - p_cb->role = HCI_ROLE_SLAVE; - p_cb->smp_over_br = true; - memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN); - } - else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) - { - osi_free(p_buf); - smp_reject_unexpected_pairing_command(bd_addr); - return; - } - /* else, out of state pairing request received, passed into State Machine */ +static void smp_br_data_received(uint16_t channel, BD_ADDR bd_addr, + BT_HDR* p_buf) { + tSMP_CB* p_cb = &smp_cb; + uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset; + uint8_t cmd; + SMP_TRACE_EVENT("SMDBG l2c %s", __func__); + + STREAM_TO_UINT8(cmd, p); + + /* sanity check */ + if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) { + SMP_TRACE_WARNING("Ignore received command with RESERVED code 0x%02x", cmd); + osi_free(p_buf); + return; + } + + /* reject the pairing request if there is an on-going SMP pairing */ + if (SMP_OPCODE_PAIRING_REQ == cmd) { + if ((p_cb->state == SMP_STATE_IDLE) && + (p_cb->br_state == SMP_BR_STATE_IDLE)) { + p_cb->role = HCI_ROLE_SLAVE; + p_cb->smp_over_br = true; + memcpy(&p_cb->pairing_bda[0], bd_addr, BD_ADDR_LEN); + } else if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN)) { + osi_free(p_buf); + smp_reject_unexpected_pairing_command(bd_addr); + return; } + /* else, out of state pairing request received, passed into State Machine */ + } - if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0) - { - alarm_set_on_queue(p_cb->smp_rsp_timer_ent, - SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL, - btu_general_alarm_queue); + if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0) { + alarm_set_on_queue(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, + smp_rsp_timeout, NULL, btu_general_alarm_queue); - p_cb->rcvd_cmd_code = cmd; - p_cb->rcvd_cmd_len = (uint8_t) p_buf->len; - smp_br_state_machine_event(p_cb, cmd, p); - } + p_cb->rcvd_cmd_code = cmd; + p_cb->rcvd_cmd_len = (uint8_t)p_buf->len; + smp_br_state_machine_event(p_cb, cmd, p); + } - osi_free(p_buf); + osi_free(p_buf); } diff --git a/stack/smp/smp_main.cc b/stack/smp/smp_main.cc index 93615c17d..829a5d48f 100644 --- a/stack/smp/smp_main.cc +++ b/stack/smp/smp_main.cc @@ -21,8 +21,7 @@ #include #include "smp_int.h" -const char *const smp_state_name [] = -{ +const char* const smp_state_name[] = { "SMP_STATE_IDLE", "SMP_STATE_WAIT_APP_RSP", "SMP_STATE_SEC_REQ_PENDING", @@ -40,132 +39,126 @@ const char *const smp_state_name [] = "SMP_STATE_ENCRYPTION_PENDING", "SMP_STATE_BOND_PENDING", "SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA", - "SMP_STATE_MAX" -}; - -const char *const smp_event_name [] = -{ - "PAIRING_REQ_EVT", - "PAIRING_RSP_EVT", - "CONFIRM_EVT", - "RAND_EVT", - "PAIRING_FAILED_EVT", - "ENC_INFO_EVT", - "MASTER_ID_EVT", - "ID_INFO_EVT", - "ID_ADDR_EVT", - "SIGN_INFO_EVT", - "SECURITY_REQ_EVT", - "PAIR_PUBLIC_KEY_EVT", - "PAIR_DHKEY_CHECK_EVT", - "PAIR_KEYPRESS_NOTIFICATION_EVT", - "PAIR_COMMITMENT_EVT", - "KEY_READY_EVT", - "ENCRYPTED_EVT", - "L2CAP_CONN_EVT", - "L2CAP_DISCONN_EVT", - "API_IO_RSP_EVT", - "API_SEC_GRANT_EVT", - "TK_REQ_EVT", - "AUTH_CMPL_EVT", - "ENC_REQ_EVT", - "BOND_REQ_EVT", - "DISCARD_SEC_REQ_EVT", - "PUBLIC_KEY_EXCHANGE_REQ_EVT", - "LOCAL_PUBLIC_KEY_CRTD_EVT", - "BOTH_PUBLIC_KEYS_RCVD_EVT", - "SEC_CONN_DHKEY_COMPLETE_EVT", - "HAVE_LOCAL_NONCE_EVT", - "SEC_CONN_PHASE1_CMPLT_EVT", - "SEC_CONN_CALC_NC_EVT", - "SEC_CONN_DISPLAY_NC_EVT", - "SEC_CONN_OK_EVT", - "SEC_CONN_2_DHCK_CHECKS_PRESENT_EVT", - "SEC_CONN_KEY_READY_EVT", - "KEYPRESS_NOTIFICATION_EVT", - "SEC_CONN_OOB_DATA_EVT", - "CREATE_LOCAL_SEC_CONN_OOB_DATA_EVT", - "OUT_OF_RANGE_EVT" -}; - -const char *smp_get_event_name(tSMP_EVENT event); -const char *smp_get_state_name(tSMP_STATE state); - -#define SMP_SM_IGNORE 0 -#define SMP_NUM_ACTIONS 2 -#define SMP_SME_NEXT_STATE 2 -#define SMP_SM_NUM_COLS 3 + "SMP_STATE_MAX"}; + +const char* const smp_event_name[] = {"PAIRING_REQ_EVT", + "PAIRING_RSP_EVT", + "CONFIRM_EVT", + "RAND_EVT", + "PAIRING_FAILED_EVT", + "ENC_INFO_EVT", + "MASTER_ID_EVT", + "ID_INFO_EVT", + "ID_ADDR_EVT", + "SIGN_INFO_EVT", + "SECURITY_REQ_EVT", + "PAIR_PUBLIC_KEY_EVT", + "PAIR_DHKEY_CHECK_EVT", + "PAIR_KEYPRESS_NOTIFICATION_EVT", + "PAIR_COMMITMENT_EVT", + "KEY_READY_EVT", + "ENCRYPTED_EVT", + "L2CAP_CONN_EVT", + "L2CAP_DISCONN_EVT", + "API_IO_RSP_EVT", + "API_SEC_GRANT_EVT", + "TK_REQ_EVT", + "AUTH_CMPL_EVT", + "ENC_REQ_EVT", + "BOND_REQ_EVT", + "DISCARD_SEC_REQ_EVT", + "PUBLIC_KEY_EXCHANGE_REQ_EVT", + "LOCAL_PUBLIC_KEY_CRTD_EVT", + "BOTH_PUBLIC_KEYS_RCVD_EVT", + "SEC_CONN_DHKEY_COMPLETE_EVT", + "HAVE_LOCAL_NONCE_EVT", + "SEC_CONN_PHASE1_CMPLT_EVT", + "SEC_CONN_CALC_NC_EVT", + "SEC_CONN_DISPLAY_NC_EVT", + "SEC_CONN_OK_EVT", + "SEC_CONN_2_DHCK_CHECKS_PRESENT_EVT", + "SEC_CONN_KEY_READY_EVT", + "KEYPRESS_NOTIFICATION_EVT", + "SEC_CONN_OOB_DATA_EVT", + "CREATE_LOCAL_SEC_CONN_OOB_DATA_EVT", + "OUT_OF_RANGE_EVT"}; + +const char* smp_get_event_name(tSMP_EVENT event); +const char* smp_get_state_name(tSMP_STATE state); + +#define SMP_SM_IGNORE 0 +#define SMP_NUM_ACTIONS 2 +#define SMP_SME_NEXT_STATE 2 +#define SMP_SM_NUM_COLS 3 typedef const uint8_t (*tSMP_SM_TBL)[SMP_SM_NUM_COLS]; -enum -{ - SMP_PROC_SEC_REQ, - SMP_SEND_PAIR_REQ, - SMP_SEND_PAIR_RSP, - SMP_SEND_CONFIRM, - SMP_SEND_PAIR_FAIL, - SMP_SEND_RAND, - SMP_SEND_ENC_INFO, - SMP_SEND_ID_INFO, - SMP_SEND_LTK_REPLY, - SMP_PROC_PAIR_CMD, - SMP_PROC_PAIR_FAIL, - SMP_PROC_CONFIRM, - SMP_PROC_RAND, - SMP_PROC_ENC_INFO, - SMP_PROC_MASTER_ID, - SMP_PROC_ID_INFO, - SMP_PROC_ID_ADDR, - SMP_PROC_SRK_INFO, - SMP_PROC_SEC_GRANT, - SMP_PROC_SL_KEY, - SMP_PROC_COMPARE, - SMP_PROC_IO_RSP, - SMP_GENERATE_COMPARE, - SMP_GENERATE_CONFIRM, - SMP_GENERATE_STK, - SMP_KEY_DISTRIBUTE, - SMP_START_ENC, - SMP_PAIRING_CMPL, - SMP_DECIDE_ASSO_MODEL, - SMP_SEND_APP_CBACK, - SMP_CHECK_AUTH_REQ, - SMP_PAIR_TERMINATE, - SMP_ENC_CMPL, - SMP_PROC_DISCARD, - SMP_CREATE_PRIVATE_KEY, - SMP_USE_OOB_PRIVATE_KEY, - SMP_SEND_PAIR_PUBLIC_KEY, - SMP_PROCESS_PAIR_PUBLIC_KEY, - SMP_HAVE_BOTH_PUBLIC_KEYS, - SMP_START_SEC_CONN_PHASE1, - SMP_PROCESS_LOCAL_NONCE, - SMP_SEND_COMMITMENT, - SMP_PROCESS_PAIRING_COMMITMENT, - SMP_PROCESS_PEER_NONCE, - SMP_CALCULATE_LOCAL_DHKEY_CHECK, - SMP_SEND_DHKEY_CHECK, - SMP_PROCESS_DHKEY_CHECK, - SMP_CALCULATE_PEER_DHKEY_CHECK, - SMP_MATCH_DHKEY_CHECKS, - SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, - SMP_MOVE_TO_SEC_CONN_PHASE2, - SMP_PH2_DHKEY_CHECKS_ARE_PRESENT, - SMP_WAIT_FOR_BOTH_PUBLIC_KEYS, - SMP_START_PASSKEY_VERIFICATION, - SMP_SEND_KEYPRESS_NOTIFICATION, - SMP_PROCESS_KEYPRESS_NOTIFICATION, - SMP_PROCESS_SECURE_CONNECTION_OOB_DATA, - SMP_SET_LOCAL_OOB_KEYS, - SMP_SET_LOCAL_OOB_RAND_COMMITMENT, - SMP_IDLE_TERMINATE, - SMP_FAST_CONN_PARAM, - SMP_SM_NO_ACTION +enum { + SMP_PROC_SEC_REQ, + SMP_SEND_PAIR_REQ, + SMP_SEND_PAIR_RSP, + SMP_SEND_CONFIRM, + SMP_SEND_PAIR_FAIL, + SMP_SEND_RAND, + SMP_SEND_ENC_INFO, + SMP_SEND_ID_INFO, + SMP_SEND_LTK_REPLY, + SMP_PROC_PAIR_CMD, + SMP_PROC_PAIR_FAIL, + SMP_PROC_CONFIRM, + SMP_PROC_RAND, + SMP_PROC_ENC_INFO, + SMP_PROC_MASTER_ID, + SMP_PROC_ID_INFO, + SMP_PROC_ID_ADDR, + SMP_PROC_SRK_INFO, + SMP_PROC_SEC_GRANT, + SMP_PROC_SL_KEY, + SMP_PROC_COMPARE, + SMP_PROC_IO_RSP, + SMP_GENERATE_COMPARE, + SMP_GENERATE_CONFIRM, + SMP_GENERATE_STK, + SMP_KEY_DISTRIBUTE, + SMP_START_ENC, + SMP_PAIRING_CMPL, + SMP_DECIDE_ASSO_MODEL, + SMP_SEND_APP_CBACK, + SMP_CHECK_AUTH_REQ, + SMP_PAIR_TERMINATE, + SMP_ENC_CMPL, + SMP_PROC_DISCARD, + SMP_CREATE_PRIVATE_KEY, + SMP_USE_OOB_PRIVATE_KEY, + SMP_SEND_PAIR_PUBLIC_KEY, + SMP_PROCESS_PAIR_PUBLIC_KEY, + SMP_HAVE_BOTH_PUBLIC_KEYS, + SMP_START_SEC_CONN_PHASE1, + SMP_PROCESS_LOCAL_NONCE, + SMP_SEND_COMMITMENT, + SMP_PROCESS_PAIRING_COMMITMENT, + SMP_PROCESS_PEER_NONCE, + SMP_CALCULATE_LOCAL_DHKEY_CHECK, + SMP_SEND_DHKEY_CHECK, + SMP_PROCESS_DHKEY_CHECK, + SMP_CALCULATE_PEER_DHKEY_CHECK, + SMP_MATCH_DHKEY_CHECKS, + SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, + SMP_MOVE_TO_SEC_CONN_PHASE2, + SMP_PH2_DHKEY_CHECKS_ARE_PRESENT, + SMP_WAIT_FOR_BOTH_PUBLIC_KEYS, + SMP_START_PASSKEY_VERIFICATION, + SMP_SEND_KEYPRESS_NOTIFICATION, + SMP_PROCESS_KEYPRESS_NOTIFICATION, + SMP_PROCESS_SECURE_CONNECTION_OOB_DATA, + SMP_SET_LOCAL_OOB_KEYS, + SMP_SET_LOCAL_OOB_RAND_COMMITMENT, + SMP_IDLE_TERMINATE, + SMP_FAST_CONN_PARAM, + SMP_SM_NO_ACTION }; -static const tSMP_ACT smp_sm_action[] = -{ +static const tSMP_ACT smp_sm_action[] = { smp_proc_sec_req, smp_send_pair_req, smp_send_pair_rsp, @@ -226,650 +219,652 @@ static const tSMP_ACT smp_sm_action[] = smp_set_local_oob_keys, smp_set_local_oob_random_commitment, smp_idle_terminate, - smp_fast_conn_param -}; + smp_fast_conn_param}; /************ SMP Master FSM State/Event Indirection Table **************/ -static const uint8_t smp_master_entry_map[][SMP_STATE_MAX] = -{ -/* state name: */ -/* Idle, WaitApp Rsp, SecReq Pend, Pair ReqRsp, Wait Cfm, Confirm, Rand, PublKey Exch, SCPhs1 Strt, Wait Cmtm, Wait Nonce, SCPhs2 Strt, Wait DHKChk, DHKChk, Enc Pend, Bond Pend, CrLocSc OobData */ -/* PAIR_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_RSP */ -{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* CONFIRM */ -{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* RAND */ -{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, -/* PAIR_FAIL */ -{ 0, 0x81, 0, 0x81, 0x81,0x81, 0x81,0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0, 0x81, 0 }, -/* ENC_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, -/* MASTER_ID */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0 }, -/* ID_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0 }, -/* ID_ADDR */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0 }, -/* SIGN_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0 }, -/* SEC_REQ */ -{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_PUBLIC_KEY */ -{ 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_DHKEY_CHCK */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, -/* PAIR_KEYPR_NOTIF */ -{ 0, 8, 0, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_COMMITM */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 0, 0 }, -/* KEY_READY */ -{ 0, 3, 0, 3, 1, 0, 2, 0, 4, 0, 0, 0, 0, 0, 1, 6, 0 }, -/* ENC_CMPL */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 }, -/* L2C_CONN */ -{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* L2C_DISC */ -{ 3, 0x83, 0, 0x83, 0x83,0x83, 0x83,0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0 }, -/* IO_RSP */ -{ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SEC_GRANT */ -{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* TK_REQ */ -{ 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* AUTH_CMPL */ -{ 4, 0x82, 0, 0x82, 0x82,0x82, 0x82,0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0 }, -/* ENC_REQ */ -{ 0, 4, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0 }, -/* BOND_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }, -/* DISCARD_SEC_REQ */ -{ 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }, -/* PUBL_KEY_EXCH_REQ */ -{ 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* LOC_PUBL_KEY_CRTD */ -{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, -/* BOTH_PUBL_KEYS_RCVD */ -{ 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_DHKEY_CMPLT */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* HAVE_LOC_NONCE */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2 }, -/* SC_PHASE1_CMPLT */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, -/* SC_CALC_NC */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, -/* SC_DSPL_NC */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0 }, -/* SC_NC_OK */ -{ 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_2_DHCK_CHKS_PRES */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_KEY_READY */ -{ 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, -/* KEYPR_NOTIF */ -{ 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_OOB_DATA */ -{ 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* CR_LOC_SC_OOB_DATA */ -{ 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -}; - -static const uint8_t smp_all_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_FAIL */ -{SMP_PROC_PAIR_FAIL, SMP_PAIRING_CMPL, SMP_STATE_IDLE}, -/* AUTH_CMPL */ -{SMP_SEND_PAIR_FAIL, SMP_PAIRING_CMPL, SMP_STATE_IDLE}, -/* L2C_DISC */ -{SMP_PAIR_TERMINATE, SMP_SM_NO_ACTION, SMP_STATE_IDLE} +static const uint8_t smp_master_entry_map[][SMP_STATE_MAX] = { + /* state name: */ + /* Idle, WaitApp Rsp, SecReq Pend, Pair ReqRsp, Wait Cfm, Confirm, Rand, + PublKey Exch, SCPhs1 Strt, Wait Cmtm, Wait Nonce, SCPhs2 Strt, Wait + DHKChk, DHKChk, Enc Pend, Bond Pend, CrLocSc OobData */ + /* PAIR_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_RSP */ + {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* CONFIRM */ + {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* RAND */ + {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, + /* PAIR_FAIL */ + {0, 0x81, 0, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0, 0x81, 0}, + /* ENC_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, + /* MASTER_ID */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0}, + /* ID_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0}, + /* ID_ADDR */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0}, + /* SIGN_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0}, + /* SEC_REQ */ + {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_PUBLIC_KEY */ + {0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_DHKEY_CHCK */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, + /* PAIR_KEYPR_NOTIF */ + {0, 8, 0, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_COMMITM */ + {0, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 0, 0}, + /* KEY_READY */ + {0, 3, 0, 3, 1, 0, 2, 0, 4, 0, 0, 0, 0, 0, 1, 6, 0}, + /* ENC_CMPL */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0}, + /* L2C_CONN */ + {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* L2C_DISC */ + {3, 0x83, 0, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, + 0x83, 0x83, 0x83, 0}, + /* IO_RSP */ + {0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SEC_GRANT */ + {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* TK_REQ */ + {0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0}, + /* AUTH_CMPL */ + {4, 0x82, 0, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0x82, 0x82, 0x82, 0}, + /* ENC_REQ */ + {0, 4, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0}, + /* BOND_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0}, + /* DISCARD_SEC_REQ */ + {0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0}, + /* PUBL_KEY_EXCH_REQ */ + {0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* LOC_PUBL_KEY_CRTD */ + {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + /* BOTH_PUBL_KEYS_RCVD */ + {0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_DHKEY_CMPLT */ + {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, + /* HAVE_LOC_NONCE */ + {0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2}, + /* SC_PHASE1_CMPLT */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, + /* SC_CALC_NC */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0}, + /* SC_DSPL_NC */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0}, + /* SC_NC_OK */ + {0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_2_DHCK_CHKS_PRES */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_KEY_READY */ + {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, + /* KEYPR_NOTIF */ + {0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_OOB_DATA */ + {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* CR_LOC_SC_OOB_DATA */ + {5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }; -static const uint8_t smp_master_idle_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* L2C_CONN */ -{SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* SEC_REQ */ -{SMP_PROC_SEC_REQ, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, -/* L2C_DISC */ -{SMP_IDLE_TERMINATE, SMP_SM_NO_ACTION, SMP_STATE_IDLE}, -/* AUTH_CMPL */ -{SMP_PAIRING_CMPL, SMP_SM_NO_ACTION, SMP_STATE_IDLE}, -/* CR_LOC_SC_OOB_DATA */ -{SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA} +static const uint8_t smp_all_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_FAIL */ + {SMP_PROC_PAIR_FAIL, SMP_PAIRING_CMPL, SMP_STATE_IDLE}, + /* AUTH_CMPL */ + {SMP_SEND_PAIR_FAIL, SMP_PAIRING_CMPL, SMP_STATE_IDLE}, + /* L2C_DISC */ + {SMP_PAIR_TERMINATE, SMP_SM_NO_ACTION, SMP_STATE_IDLE}}; + +static const uint8_t smp_master_idle_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* L2C_CONN */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* SEC_REQ */ + {SMP_PROC_SEC_REQ, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, + /* L2C_DISC */ + {SMP_IDLE_TERMINATE, SMP_SM_NO_ACTION, SMP_STATE_IDLE}, + /* AUTH_CMPL */ + {SMP_PAIRING_CMPL, SMP_SM_NO_ACTION, SMP_STATE_IDLE}, + /* CR_LOC_SC_OOB_DATA */ + {SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA} }; static const uint8_t smp_master_wait_for_app_response_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* SEC_GRANT */ -{SMP_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, -/* IO_RSP */ -{SMP_SEND_PAIR_REQ, SMP_FAST_CONN_PARAM, SMP_STATE_PAIR_REQ_RSP}, - - /* TK ready */ -/* KEY_READY */ -{SMP_GENERATE_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM}, - - /* start enc mode setup */ -/* ENC_REQ */ -{ SMP_START_ENC, SMP_FAST_CONN_PARAM, SMP_STATE_ENCRYPTION_PENDING}, -/* DISCARD_SEC_REQ */ -{ SMP_PROC_DISCARD, SMP_SM_NO_ACTION, SMP_STATE_IDLE} -/* user confirms NC 'OK', i.e. phase 1 is completed */ -/* SC_NC_OK */, -{ SMP_MOVE_TO_SEC_CONN_PHASE2, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS2_START}, -/* user-provided passkey is rcvd */ -/* SC_KEY_READY */ -{ SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* PAIR_KEYPR_NOTIF */ -{ SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, -/* KEYPR_NOTIF */ -{ SMP_SEND_KEYPRESS_NOTIFICATION, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* SC_OOB_DATA */ -{ SMP_USE_OOB_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH} -}; + { + /* Event Action Next State */ + /* SEC_GRANT */ + {SMP_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, + /* IO_RSP */ + {SMP_SEND_PAIR_REQ, SMP_FAST_CONN_PARAM, SMP_STATE_PAIR_REQ_RSP}, + + /* TK ready */ + /* KEY_READY */ + {SMP_GENERATE_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM}, + + /* start enc mode setup */ + /* ENC_REQ */ + {SMP_START_ENC, SMP_FAST_CONN_PARAM, SMP_STATE_ENCRYPTION_PENDING}, + /* DISCARD_SEC_REQ */ + {SMP_PROC_DISCARD, SMP_SM_NO_ACTION, SMP_STATE_IDLE} + /* user confirms NC 'OK', i.e. phase 1 is completed */ + /* SC_NC_OK */, + {SMP_MOVE_TO_SEC_CONN_PHASE2, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS2_START}, + /* user-provided passkey is rcvd */ + /* SC_KEY_READY */ + {SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_WAIT_APP_RSP}, + /* KEYPR_NOTIF */ + {SMP_SEND_KEYPRESS_NOTIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_WAIT_APP_RSP}, + /* SC_OOB_DATA */ + {SMP_USE_OOB_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}}; static const uint8_t smp_master_pair_request_response_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_RSP */ -{ SMP_PROC_PAIR_CMD, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, -/* TK_REQ */ -{ SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, - - /* TK ready */ -/* KEY_READY */ -{ SMP_GENERATE_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM} -/* PUBL_KEY_EXCH_REQ */, -{ SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH} -}; - -static const uint8_t smp_master_wait_for_confirm_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* KEY_READY*/ -/* CONFIRM ready */ -{SMP_SEND_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM} -}; - -static const uint8_t smp_master_confirm_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* CONFIRM */ -{ SMP_PROC_CONFIRM, SMP_SEND_RAND, SMP_STATE_RAND} -}; - -static const uint8_t smp_master_rand_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* RAND */ -{ SMP_PROC_RAND, SMP_GENERATE_COMPARE, SMP_STATE_RAND}, -/* KEY_READY */ -{ SMP_PROC_COMPARE, SMP_SM_NO_ACTION, SMP_STATE_RAND}, /* Compare ready */ -/* ENC_REQ */ -{ SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING} -}; - -static const uint8_t smp_master_public_key_exchange_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* LOC_PUBL_KEY_CRTD */ -{ SMP_SEND_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, -/* PAIR_PUBLIC_KEY */ -{ SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, -/* BOTH_PUBL_KEYS_RCVD */ -{ SMP_HAVE_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -}; - -static const uint8_t smp_master_sec_conn_phs1_start_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* SC_DHKEY_CMPLT */ -{ SMP_START_SEC_CONN_PHASE1, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* HAVE_LOC_NONCE */ -{ SMP_PROCESS_LOCAL_NONCE, SMP_SM_NO_ACTION, SMP_STATE_WAIT_COMMITMENT}, -/* TK_REQ */ -{ SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* SMP_MODEL_SEC_CONN_PASSKEY_DISP model, passkey is sent up to display,*/ -/* It's time to start commitment calculation */ -/* KEY_READY */ -{ SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* PAIR_KEYPR_NOTIF */ -{ SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, SMP_STATE_SEC_CONN_PHS1_START}, -/* PAIR_COMMITM */ -{ SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, + { + /* Event Action Next State */ + /* PAIR_RSP */ + {SMP_PROC_PAIR_CMD, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, + /* TK_REQ */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + + /* TK ready */ + /* KEY_READY */ + {SMP_GENERATE_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM} + /* PUBL_KEY_EXCH_REQ */, + {SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}}; + +static const uint8_t smp_master_wait_for_confirm_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* KEY_READY*/ + /* CONFIRM ready */ + {SMP_SEND_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}}; + +static const uint8_t smp_master_confirm_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* CONFIRM */ + {SMP_PROC_CONFIRM, SMP_SEND_RAND, SMP_STATE_RAND}}; + +static const uint8_t smp_master_rand_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* RAND */ + {SMP_PROC_RAND, SMP_GENERATE_COMPARE, SMP_STATE_RAND}, + /* KEY_READY */ + {SMP_PROC_COMPARE, SMP_SM_NO_ACTION, SMP_STATE_RAND}, /* Compare ready */ + /* ENC_REQ */ + {SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}}; + +static const uint8_t smp_master_public_key_exchange_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* LOC_PUBL_KEY_CRTD */ + {SMP_SEND_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, + /* PAIR_PUBLIC_KEY */ + {SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, + /* BOTH_PUBL_KEYS_RCVD */ + {SMP_HAVE_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, }; -static const uint8_t smp_master_wait_commitment_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_COMMITM */ -{ SMP_PROCESS_PAIRING_COMMITMENT, SMP_SEND_RAND, SMP_STATE_WAIT_NONCE}, -/* PAIR_KEYPR_NOTIF */ -{ SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_COMMITMENT}, +static const uint8_t smp_master_sec_conn_phs1_start_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* SC_DHKEY_CMPLT */ + {SMP_START_SEC_CONN_PHASE1, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* HAVE_LOC_NONCE */ + {SMP_PROCESS_LOCAL_NONCE, SMP_SM_NO_ACTION, SMP_STATE_WAIT_COMMITMENT}, + /* TK_REQ */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* SMP_MODEL_SEC_CONN_PASSKEY_DISP model, passkey is sent up to display,*/ + /* It's time to start commitment calculation */ + /* KEY_READY */ + {SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_SEC_CONN_PHS1_START}, + /* PAIR_COMMITM */ + {SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, }; -static const uint8_t smp_master_wait_nonce_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* peer nonce is received */ -/* RAND */ -{SMP_PROC_RAND, SMP_PROCESS_PEER_NONCE, SMP_STATE_SEC_CONN_PHS2_START}, -/* NC model, time to calculate number for NC */ -/* SC_CALC_NC */ -{SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, SMP_SM_NO_ACTION, SMP_STATE_WAIT_NONCE}, -/* NC model, time to display calculated number for NC to the user */ -/* SC_DSPL_NC */ -{SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, +static const uint8_t smp_master_wait_commitment_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_COMMITM */ + {SMP_PROCESS_PAIRING_COMMITMENT, SMP_SEND_RAND, SMP_STATE_WAIT_NONCE}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_WAIT_COMMITMENT}, }; -static const uint8_t smp_master_sec_conn_phs2_start_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* SC_PHASE1_CMPLT */ -{SMP_CALCULATE_LOCAL_DHKEY_CHECK, SMP_SEND_DHKEY_CHECK, SMP_STATE_WAIT_DHK_CHECK}, +static const uint8_t smp_master_wait_nonce_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* peer nonce is received */ + /* RAND */ + {SMP_PROC_RAND, SMP_PROCESS_PEER_NONCE, SMP_STATE_SEC_CONN_PHS2_START}, + /* NC model, time to calculate number for NC */ + /* SC_CALC_NC */ + {SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, SMP_SM_NO_ACTION, + SMP_STATE_WAIT_NONCE}, + /* NC model, time to display calculated number for NC to the user */ + /* SC_DSPL_NC */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, }; -static const uint8_t smp_master_wait_dhk_check_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_DHKEY_CHCK */ -{SMP_PROCESS_DHKEY_CHECK, SMP_CALCULATE_PEER_DHKEY_CHECK, SMP_STATE_DHK_CHECK}, +static const uint8_t smp_master_sec_conn_phs2_start_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* SC_PHASE1_CMPLT */ + {SMP_CALCULATE_LOCAL_DHKEY_CHECK, SMP_SEND_DHKEY_CHECK, + SMP_STATE_WAIT_DHK_CHECK}, }; -static const uint8_t smp_master_dhk_check_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* locally calculated peer dhkey check is ready -> compare it withs DHKey Check - * actually received from peer */ -/* SC_KEY_READY */ -{SMP_MATCH_DHKEY_CHECKS, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, -/* locally calculated peer dhkey check is ready -> calculate STK, go to sending - */ -/* HCI LE Start Encryption command */ -/* ENC_REQ */ -{SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, +static const uint8_t smp_master_wait_dhk_check_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_DHKEY_CHCK */ + {SMP_PROCESS_DHKEY_CHECK, SMP_CALCULATE_PEER_DHKEY_CHECK, + SMP_STATE_DHK_CHECK}, }; -static const uint8_t smp_master_enc_pending_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* STK ready */ -/* KEY_READY */ -{ SMP_START_ENC, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, -/* ENCRYPTED */ -{ SMP_CHECK_AUTH_REQ, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, -/* BOND_REQ */ -{ SMP_KEY_DISTRIBUTE, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING} -}; -static const uint8_t smp_master_bond_pending_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* ENC_INFO */ -{ SMP_PROC_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* ID_INFO */ -{ SMP_PROC_ID_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* SIGN_INFO */ -{ SMP_PROC_SRK_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* MASTER_ID */ -{ SMP_PROC_MASTER_ID, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* ID_ADDR */ -{ SMP_PROC_ID_ADDR, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* KEY_READY */ -/* LTK ready */ -{SMP_SEND_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING} -}; - -static const uint8_t smp_master_create_local_sec_conn_oob_data[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* LOC_PUBL_KEY_CRTD */ -{SMP_SET_LOCAL_OOB_KEYS, SMP_SM_NO_ACTION, SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA}, -/* HAVE_LOC_NONCE */ -{SMP_SET_LOCAL_OOB_RAND_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_IDLE} +static const uint8_t smp_master_dhk_check_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* locally calculated peer dhkey check is ready -> compare it withs DHKey + * Check + * actually received from peer */ + /* SC_KEY_READY */ + {SMP_MATCH_DHKEY_CHECKS, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, + /* locally calculated peer dhkey check is ready -> calculate STK, go to + * sending + */ + /* HCI LE Start Encryption command */ + /* ENC_REQ */ + {SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, }; +static const uint8_t smp_master_enc_pending_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* STK ready */ + /* KEY_READY */ + {SMP_START_ENC, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, + /* ENCRYPTED */ + {SMP_CHECK_AUTH_REQ, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, + /* BOND_REQ */ + {SMP_KEY_DISTRIBUTE, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}}; +static const uint8_t smp_master_bond_pending_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* ENC_INFO */ + {SMP_PROC_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* ID_INFO */ + {SMP_PROC_ID_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* SIGN_INFO */ + {SMP_PROC_SRK_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* MASTER_ID */ + {SMP_PROC_MASTER_ID, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* ID_ADDR */ + {SMP_PROC_ID_ADDR, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* KEY_READY */ + /* LTK ready */ + {SMP_SEND_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}}; + +static const uint8_t + smp_master_create_local_sec_conn_oob_data[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* LOC_PUBL_KEY_CRTD */ + {SMP_SET_LOCAL_OOB_KEYS, SMP_SM_NO_ACTION, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA}, + /* HAVE_LOC_NONCE */ + {SMP_SET_LOCAL_OOB_RAND_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_IDLE}}; /************ SMP Slave FSM State/Event Indirection Table **************/ -static const uint8_t smp_slave_entry_map[][SMP_STATE_MAX] = -{ -/* state name: */ -/* Idle, WaitApp Rsp, SecReq Pend, Pair ReqRsp, Wait Cfm, Confirm, Rand, PublKey Exch, SCPhs1 Strt, Wait Cmtm, Wait Nonce, SCPhs2 Strt, Wait DHKChk, DHKChk, Enc Pend, Bond Pend, CrLocSc OobData */ -/* PAIR_REQ */ -{ 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_RSP */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* CONFIRM */ -{ 0, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* RAND */ -{ 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, -/* PAIR_FAIL */ -{ 0, 0x81, 0x81, 0x81, 0x81,0x81, 0x81,0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0, 0 }, -/* ENC_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0 }, -/* MASTER_ID */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0 }, -/* ID_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0 }, -/* ID_ADDR */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0 }, -/* SIGN_INFO */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0 }, -/* SEC_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_PUBLIC_KEY */ -{ 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_DHKEY_CHCK */ -{ 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0 }, -/* PAIR_KEYPR_NOTIF */ -{ 0, 9, 0, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 0 }, -/* PAIR_COMMITM */ -{ 0, 8, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 0, 0 }, -/* KEY_READY */ -{ 0, 3, 0, 3, 2, 2, 1, 0, 4, 0, 0, 0, 0, 0, 2, 1, 0 }, -/* ENC_CMPL */ -{ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }, -/* L2C_CONN */ -{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* L2C_DISC */ -{ 0, 0x83, 0x83, 0x83, 0x83,0x83, 0x83,0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0 }, -/* IO_RSP */ -{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SEC_GRANT */ -{ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* TK_REQ */ -{ 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* AUTH_CMPL */ -{ 0, 0x82, 0x82, 0x82, 0x82,0x82, 0x82,0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0 }, -/* ENC_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, -/* BOND_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0 }, -/* DISCARD_SEC_REQ */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* PUBL_KEY_EXCH_REQ */ -{ 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* LOC_PUBL_KEY_CRTD */ -{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, -/* BOTH_PUBL_KEYS_RCVD */ -{ 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_DHKEY_CMPLT */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* HAVE_LOC_NONCE */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2 }, -/* SC_PHASE1_CMPLT */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, -/* SC_CALC_NC */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, -/* SC_DSPL_NC */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0 }, -/* SC_NC_OK */ -{ 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_2_DHCK_CHKS_PRES */ -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0 }, -/* SC_KEY_READY */ -{ 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, -/* KEYPR_NOTIF */ -{ 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* SC_OOB_DATA */ -{ 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -/* CR_LOC_SC_OOB_DATA */ -{ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -}; - -static const uint8_t smp_slave_idle_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* L2C_CONN */ -{SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* PAIR_REQ */ -{SMP_PROC_PAIR_CMD, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, -/* CR_LOC_SC_OOB_DATA */ -{SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA} +static const uint8_t smp_slave_entry_map[][SMP_STATE_MAX] = { + /* state name: */ + /* Idle, WaitApp Rsp, SecReq Pend, Pair ReqRsp, Wait Cfm, Confirm, Rand, + PublKey Exch, SCPhs1 Strt, Wait Cmtm, Wait Nonce, SCPhs2 Strt, Wait + DHKChk, DHKChk, Enc Pend, Bond Pend, CrLocSc OobData */ + /* PAIR_REQ */ + {2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_RSP */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* CONFIRM */ + {0, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* RAND */ + {0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, + /* PAIR_FAIL */ + {0, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0x81, 0, 0}, + /* ENC_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0}, + /* MASTER_ID */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0}, + /* ID_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0}, + /* ID_ADDR */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0}, + /* SIGN_INFO */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0}, + /* SEC_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_PUBLIC_KEY */ + {0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_DHKEY_CHCK */ + {0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0}, + /* PAIR_KEYPR_NOTIF */ + {0, 9, 0, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0, 0, 0, 0, 0}, + /* PAIR_COMMITM */ + {0, 8, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 0, 0}, + /* KEY_READY */ + {0, 3, 0, 3, 2, 2, 1, 0, 4, 0, 0, 0, 0, 0, 2, 1, 0}, + /* ENC_CMPL */ + {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0}, + /* L2C_CONN */ + {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* L2C_DISC */ + {0, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, + 0x83, 0x83, 0x83, 0}, + /* IO_RSP */ + {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SEC_GRANT */ + {0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* TK_REQ */ + {0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0}, + /* AUTH_CMPL */ + {0, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0x82, 0x82, 0x82, 0}, + /* ENC_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, + /* BOND_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0}, + /* DISCARD_SEC_REQ */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* PUBL_KEY_EXCH_REQ */ + {0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* LOC_PUBL_KEY_CRTD */ + {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + /* BOTH_PUBL_KEYS_RCVD */ + {0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_DHKEY_CMPLT */ + {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, + /* HAVE_LOC_NONCE */ + {0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2}, + /* SC_PHASE1_CMPLT */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, + /* SC_CALC_NC */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0}, + /* SC_DSPL_NC */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0}, + /* SC_NC_OK */ + {0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_2_DHCK_CHKS_PRES */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0}, + /* SC_KEY_READY */ + {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, + /* KEYPR_NOTIF */ + {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* SC_OOB_DATA */ + {0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* CR_LOC_SC_OOB_DATA */ + {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }; -static const uint8_t smp_slave_wait_for_app_response_table [][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* IO_RSP */ -{SMP_PROC_IO_RSP, SMP_FAST_CONN_PARAM, SMP_STATE_PAIR_REQ_RSP}, -/* SEC_GRANT */ -{SMP_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, - - /* TK ready */ -/* KEY_READY */ -{SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* CONFIRM */ -{SMP_PROC_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}, -/* DHKey Check from master is received before phase 1 is completed - race */ -/* PAIR_DHKEY_CHCK */ -{SMP_PROCESS_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* user confirms NC 'OK', i.e. phase 1 is completed */ -/* SC_NC_OK */ -{SMP_MOVE_TO_SEC_CONN_PHASE2, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS2_START}, -/* user-provided passkey is rcvd */ -/* SC_KEY_READY */ -{SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* PAIR_COMMITM */ -{SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* PAIR_KEYPR_NOTIF */ -{SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, -/* KEYPR_NOTIF */ -{SMP_SEND_KEYPRESS_NOTIFICATION, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* SC_OOB_DATA */ -{SMP_SEND_PAIR_RSP, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, +static const uint8_t smp_slave_idle_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* L2C_CONN */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* PAIR_REQ */ + {SMP_PROC_PAIR_CMD, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, + /* CR_LOC_SC_OOB_DATA */ + {SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA}}; + +static const uint8_t smp_slave_wait_for_app_response_table[][SMP_SM_NUM_COLS] = + { + /* Event Action Next State */ + /* IO_RSP */ + {SMP_PROC_IO_RSP, SMP_FAST_CONN_PARAM, SMP_STATE_PAIR_REQ_RSP}, + /* SEC_GRANT */ + {SMP_PROC_SEC_GRANT, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_APP_RSP}, + + /* TK ready */ + /* KEY_READY */ + {SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* CONFIRM */ + {SMP_PROC_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}, + /* DHKey Check from master is received before phase 1 is completed - + race */ + /* PAIR_DHKEY_CHCK */ + {SMP_PROCESS_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* user confirms NC 'OK', i.e. phase 1 is completed */ + /* SC_NC_OK */ + {SMP_MOVE_TO_SEC_CONN_PHASE2, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS2_START}, + /* user-provided passkey is rcvd */ + /* SC_KEY_READY */ + {SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* PAIR_COMMITM */ + {SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, + SMP_STATE_WAIT_APP_RSP}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_WAIT_APP_RSP}, + /* KEYPR_NOTIF */ + {SMP_SEND_KEYPRESS_NOTIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_WAIT_APP_RSP}, + /* SC_OOB_DATA */ + {SMP_SEND_PAIR_RSP, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, }; -static const uint8_t smp_slave_sec_request_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_REQ */ -{SMP_PROC_PAIR_CMD, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, -/* ENCRYPTED*/ -{SMP_ENC_CMPL, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, +static const uint8_t smp_slave_sec_request_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_REQ */ + {SMP_PROC_PAIR_CMD, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, + /* ENCRYPTED*/ + {SMP_ENC_CMPL, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, }; static const uint8_t smp_slave_pair_request_response_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* CONFIRM */ -{SMP_PROC_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}, -/* TK_REQ */ -{SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, - - /* TK/Confirm ready */ -/* KEY_READY */ -{SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, -/* PUBL_KEY_EXCH_REQ */ -{ SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, -/* PAIR_PUBLIC_KEY */ -{ SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, -}; - -static const uint8_t smp_slave_wait_confirm_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* CONFIRM */ -{SMP_PROC_CONFIRM, SMP_SEND_CONFIRM, SMP_STATE_CONFIRM}, -/* KEY_READY*/ -{SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM} -}; - -static const uint8_t smp_slave_confirm_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* RAND */ -{SMP_PROC_RAND, SMP_GENERATE_COMPARE, SMP_STATE_RAND}, - - /* TK/Confirm ready */ -/* KEY_READY*/ -{SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM} -}; - -static const uint8_t smp_slave_rand_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* KEY_READY */ -{SMP_PROC_COMPARE, SMP_SM_NO_ACTION, SMP_STATE_RAND}, /* compare match */ -/* RAND */ -{SMP_SEND_RAND, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING} + { + /* Event Action Next State */ + /* CONFIRM */ + {SMP_PROC_CONFIRM, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}, + /* TK_REQ */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + + /* TK/Confirm ready */ + /* KEY_READY */ + {SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, + /* PUBL_KEY_EXCH_REQ */ + {SMP_CREATE_PRIVATE_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, + /* PAIR_PUBLIC_KEY */ + {SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PAIR_REQ_RSP}, }; -static const uint8_t smp_slave_public_key_exch_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* LOC_PUBL_KEY_CRTD */ -{ SMP_WAIT_FOR_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, -/* PAIR_PUBLIC_KEY */ -{ SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, -/* BOTH_PUBL_KEYS_RCVD */ -{ SMP_HAVE_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, +static const uint8_t smp_slave_wait_confirm_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* CONFIRM */ + {SMP_PROC_CONFIRM, SMP_SEND_CONFIRM, SMP_STATE_CONFIRM}, + /* KEY_READY*/ + {SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_WAIT_CONFIRM}}; + +static const uint8_t smp_slave_confirm_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* RAND */ + {SMP_PROC_RAND, SMP_GENERATE_COMPARE, SMP_STATE_RAND}, + + /* TK/Confirm ready */ + /* KEY_READY*/ + {SMP_PROC_SL_KEY, SMP_SM_NO_ACTION, SMP_STATE_CONFIRM}}; + +static const uint8_t smp_slave_rand_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* KEY_READY */ + {SMP_PROC_COMPARE, SMP_SM_NO_ACTION, SMP_STATE_RAND}, /* compare match */ + /* RAND */ + {SMP_SEND_RAND, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}}; + +static const uint8_t smp_slave_public_key_exch_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* LOC_PUBL_KEY_CRTD */ + {SMP_WAIT_FOR_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, + SMP_STATE_PUBLIC_KEY_EXCH}, + /* PAIR_PUBLIC_KEY */ + {SMP_PROCESS_PAIR_PUBLIC_KEY, SMP_SM_NO_ACTION, SMP_STATE_PUBLIC_KEY_EXCH}, + /* BOTH_PUBL_KEYS_RCVD */ + {SMP_HAVE_BOTH_PUBLIC_KEYS, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, }; -static const uint8_t smp_slave_sec_conn_phs1_start_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* SC_DHKEY_CMPLT */ -{ SMP_START_SEC_CONN_PHASE1, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* HAVE_LOC_NONCE */ -{ SMP_PROCESS_LOCAL_NONCE,SMP_SM_NO_ACTION, SMP_STATE_WAIT_COMMITMENT}, -/* TK_REQ */ -{ SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, -/* SMP_MODEL_SEC_CONN_PASSKEY_DISP model, passkey is sent up to display, it's - * time to start */ -/* commitment calculation */ -/* KEY_READY */ -{ SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, -/* PAIR_KEYPR_NOTIF */ -{ SMP_PROCESS_KEYPRESS_NOTIFICATION,SMP_SEND_APP_CBACK, SMP_STATE_SEC_CONN_PHS1_START}, -/*COMMIT*/ -{SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS1_START}, +static const uint8_t smp_slave_sec_conn_phs1_start_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* SC_DHKEY_CMPLT */ + {SMP_START_SEC_CONN_PHASE1, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* HAVE_LOC_NONCE */ + {SMP_PROCESS_LOCAL_NONCE, SMP_SM_NO_ACTION, SMP_STATE_WAIT_COMMITMENT}, + /* TK_REQ */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, + /* SMP_MODEL_SEC_CONN_PASSKEY_DISP model, passkey is sent up to display, + * it's + * time to start */ + /* commitment calculation */ + /* KEY_READY */ + {SMP_START_PASSKEY_VERIFICATION, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_SEC_CONN_PHS1_START}, + /*COMMIT*/ + {SMP_PROCESS_PAIRING_COMMITMENT, SMP_SM_NO_ACTION, + SMP_STATE_SEC_CONN_PHS1_START}, }; -static const uint8_t smp_slave_wait_commitment_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_COMMITM */ -{SMP_PROCESS_PAIRING_COMMITMENT, SMP_SEND_COMMITMENT, SMP_STATE_WAIT_NONCE}, -/* PAIR_KEYPR_NOTIF */ -{SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, SMP_STATE_WAIT_COMMITMENT}, +static const uint8_t smp_slave_wait_commitment_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_COMMITM */ + {SMP_PROCESS_PAIRING_COMMITMENT, SMP_SEND_COMMITMENT, SMP_STATE_WAIT_NONCE}, + /* PAIR_KEYPR_NOTIF */ + {SMP_PROCESS_KEYPRESS_NOTIFICATION, SMP_SEND_APP_CBACK, + SMP_STATE_WAIT_COMMITMENT}, }; -static const uint8_t smp_slave_wait_nonce_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* peer nonce is received */ -/* RAND */ -{SMP_PROC_RAND, SMP_PROCESS_PEER_NONCE, SMP_STATE_SEC_CONN_PHS2_START}, -/* NC model, time to calculate number for NC */ -/* SC_CALC_NC */ -{SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, SMP_SM_NO_ACTION, SMP_STATE_WAIT_NONCE}, -/* NC model, time to display calculated number for NC to the user */ -/* SC_DSPL_NC */ -{SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, +static const uint8_t smp_slave_wait_nonce_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* peer nonce is received */ + /* RAND */ + {SMP_PROC_RAND, SMP_PROCESS_PEER_NONCE, SMP_STATE_SEC_CONN_PHS2_START}, + /* NC model, time to calculate number for NC */ + /* SC_CALC_NC */ + {SMP_CALCULATE_NUMERIC_COMPARISON_DISPLAY_NUMBER, SMP_SM_NO_ACTION, + SMP_STATE_WAIT_NONCE}, + /* NC model, time to display calculated number for NC to the user */ + /* SC_DSPL_NC */ + {SMP_SEND_APP_CBACK, SMP_SM_NO_ACTION, SMP_STATE_WAIT_APP_RSP}, }; -static const uint8_t smp_slave_sec_conn_phs2_start_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* SC_PHASE1_CMPLT */ -{SMP_CALCULATE_LOCAL_DHKEY_CHECK, SMP_PH2_DHKEY_CHECKS_ARE_PRESENT, SMP_STATE_WAIT_DHK_CHECK}, -/* DHKey Check from master is received before slave DHKey calculation is - * completed - race */ -/* PAIR_DHKEY_CHCK */ -{SMP_PROCESS_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS2_START}, +static const uint8_t smp_slave_sec_conn_phs2_start_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* SC_PHASE1_CMPLT */ + {SMP_CALCULATE_LOCAL_DHKEY_CHECK, SMP_PH2_DHKEY_CHECKS_ARE_PRESENT, + SMP_STATE_WAIT_DHK_CHECK}, + /* DHKey Check from master is received before slave DHKey calculation is + * completed - race */ + /* PAIR_DHKEY_CHCK */ + {SMP_PROCESS_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_SEC_CONN_PHS2_START}, }; -static const uint8_t smp_slave_wait_dhk_check_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* PAIR_DHKEY_CHCK */ -{SMP_PROCESS_DHKEY_CHECK, SMP_CALCULATE_PEER_DHKEY_CHECK, SMP_STATE_DHK_CHECK}, -/* DHKey Check from master was received before slave came to this state */ -/* SC_2_DHCK_CHKS_PRES */ -{SMP_CALCULATE_PEER_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, +static const uint8_t smp_slave_wait_dhk_check_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* PAIR_DHKEY_CHCK */ + {SMP_PROCESS_DHKEY_CHECK, SMP_CALCULATE_PEER_DHKEY_CHECK, + SMP_STATE_DHK_CHECK}, + /* DHKey Check from master was received before slave came to this state */ + /* SC_2_DHCK_CHKS_PRES */ + {SMP_CALCULATE_PEER_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, }; -static const uint8_t smp_slave_dhk_check_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ - -/* locally calculated peer dhkey check is ready -> compare it withs DHKey Check - */ -/* actually received from peer */ -/* SC_KEY_READY */ -{SMP_MATCH_DHKEY_CHECKS, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, - -/* dhkey checks match -> send local dhkey check to master, go to wait for HCI LE - */ -/* Long Term Key Request Event */ -/* PAIR_DHKEY_CHCK */ -{SMP_SEND_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, +static const uint8_t smp_slave_dhk_check_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + + /* locally calculated peer dhkey check is ready -> compare it withs DHKey + * Check + */ + /* actually received from peer */ + /* SC_KEY_READY */ + {SMP_MATCH_DHKEY_CHECKS, SMP_SM_NO_ACTION, SMP_STATE_DHK_CHECK}, + + /* dhkey checks match -> send local dhkey check to master, go to wait for + * HCI LE + */ + /* Long Term Key Request Event */ + /* PAIR_DHKEY_CHCK */ + {SMP_SEND_DHKEY_CHECK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, }; -static const uint8_t smp_slave_enc_pending_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* ENC_REQ */ -{SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, - - /* STK ready */ -/* KEY_READY */ -{SMP_SEND_LTK_REPLY, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, -/* ENCRYPTED */ -{SMP_CHECK_AUTH_REQ, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, -/* BOND_REQ */ -{SMP_KEY_DISTRIBUTE, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING} -}; -static const uint8_t smp_slave_bond_pending_table[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ - - /* LTK ready */ -/* KEY_READY */ -{ SMP_SEND_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, - - /* rev SRK */ -/* SIGN_INFO */ -{ SMP_PROC_SRK_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* ENC_INFO */ -{ SMP_PROC_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* ID_INFO */ -{ SMP_PROC_ID_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* MASTER_ID*/ -{ SMP_PROC_MASTER_ID, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, -/* ID_ADDR */ -{ SMP_PROC_ID_ADDR, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING} +static const uint8_t smp_slave_enc_pending_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* ENC_REQ */ + {SMP_GENERATE_STK, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, + + /* STK ready */ + /* KEY_READY */ + {SMP_SEND_LTK_REPLY, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, + /* ENCRYPTED */ + {SMP_CHECK_AUTH_REQ, SMP_SM_NO_ACTION, SMP_STATE_ENCRYPTION_PENDING}, + /* BOND_REQ */ + {SMP_KEY_DISTRIBUTE, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}}; +static const uint8_t smp_slave_bond_pending_table[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + + /* LTK ready */ + /* KEY_READY */ + {SMP_SEND_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + + /* rev SRK */ + /* SIGN_INFO */ + {SMP_PROC_SRK_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* ENC_INFO */ + {SMP_PROC_ENC_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* ID_INFO */ + {SMP_PROC_ID_INFO, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* MASTER_ID*/ + {SMP_PROC_MASTER_ID, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING}, + /* ID_ADDR */ + {SMP_PROC_ID_ADDR, SMP_SM_NO_ACTION, SMP_STATE_BOND_PENDING} }; -static const uint8_t smp_slave_create_local_sec_conn_oob_data[][SMP_SM_NUM_COLS] = -{ -/* Event Action Next State */ -/* LOC_PUBL_KEY_CRTD */ -{SMP_SET_LOCAL_OOB_KEYS, SMP_SM_NO_ACTION, SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA}, -/* HAVE_LOC_NONCE */ -{SMP_SET_LOCAL_OOB_RAND_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_IDLE} -}; +static const uint8_t + smp_slave_create_local_sec_conn_oob_data[][SMP_SM_NUM_COLS] = { + /* Event Action Next State */ + /* LOC_PUBL_KEY_CRTD */ + {SMP_SET_LOCAL_OOB_KEYS, SMP_SM_NO_ACTION, + SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA}, + /* HAVE_LOC_NONCE */ + {SMP_SET_LOCAL_OOB_RAND_COMMITMENT, SMP_SM_NO_ACTION, SMP_STATE_IDLE}}; -static const tSMP_SM_TBL smp_state_table[][2] = -{ +static const tSMP_SM_TBL smp_state_table[][2] = { /* SMP_STATE_IDLE */ {smp_master_idle_table, smp_slave_idle_table}, /* SMP_STATE_WAIT_APP_RSP */ - {smp_master_wait_for_app_response_table, smp_slave_wait_for_app_response_table}, + {smp_master_wait_for_app_response_table, + smp_slave_wait_for_app_response_table}, /* SMP_STATE_SEC_REQ_PENDING */ {NULL, smp_slave_sec_request_table}, /* SMP_STATE_PAIR_REQ_RSP */ - {smp_master_pair_request_response_table, smp_slave_pair_request_response_table}, + {smp_master_pair_request_response_table, + smp_slave_pair_request_response_table}, /* SMP_STATE_WAIT_CONFIRM */ {smp_master_wait_for_confirm_table, smp_slave_wait_confirm_table}, @@ -881,7 +876,7 @@ static const tSMP_SM_TBL smp_state_table[][2] = {smp_master_rand_table, smp_slave_rand_table}, /* SMP_STATE_PUBLIC_KEY_EXCH */ - {smp_master_public_key_exchange_table,smp_slave_public_key_exch_table}, + {smp_master_public_key_exchange_table, smp_slave_public_key_exch_table}, /* SMP_STATE_SEC_CONN_PHS1_START */ {smp_master_sec_conn_phs1_start_table, smp_slave_sec_conn_phs1_start_table}, @@ -892,7 +887,7 @@ static const tSMP_SM_TBL smp_state_table[][2] = /* SMP_STATE_WAIT_NONCE */ {smp_master_wait_nonce_table, smp_slave_wait_nonce_table}, - /* SMP_STATE_SEC_CONN_PHS2_START */ + /* SMP_STATE_SEC_CONN_PHS2_START */ {smp_master_sec_conn_phs2_start_table, smp_slave_sec_conn_phs2_start_table}, /* SMP_STATE_WAIT_DHK_CHECK */ @@ -904,51 +899,41 @@ static const tSMP_SM_TBL smp_state_table[][2] = /* SMP_STATE_ENCRYPTION_PENDING */ {smp_master_enc_pending_table, smp_slave_enc_pending_table}, - /* SMP_STATE_BOND_PENDING */ + /* SMP_STATE_BOND_PENDING */ {smp_master_bond_pending_table, smp_slave_bond_pending_table}, /* SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA */ - {smp_master_create_local_sec_conn_oob_data, smp_slave_create_local_sec_conn_oob_data} -}; + {smp_master_create_local_sec_conn_oob_data, + smp_slave_create_local_sec_conn_oob_data}}; typedef const uint8_t (*tSMP_ENTRY_TBL)[SMP_STATE_MAX]; -static const tSMP_ENTRY_TBL smp_entry_table[] = -{ - smp_master_entry_map, - smp_slave_entry_map -}; +static const tSMP_ENTRY_TBL smp_entry_table[] = {smp_master_entry_map, + smp_slave_entry_map}; tSMP_CB smp_cb; -#define SMP_ALL_TBL_MASK 0x80 +#define SMP_ALL_TBL_MASK 0x80 /******************************************************************************* * Function smp_set_state * Returns None ******************************************************************************/ -void smp_set_state(tSMP_STATE state) -{ - if (state < SMP_STATE_MAX) - { - SMP_TRACE_DEBUG( "State change: %s(%d) ==> %s(%d)", - smp_get_state_name(smp_cb.state), smp_cb.state, - smp_get_state_name(state), state ); - smp_cb.state = state; - } - else - { - SMP_TRACE_DEBUG("smp_set_state invalid state =%d", state ); - } +void smp_set_state(tSMP_STATE state) { + if (state < SMP_STATE_MAX) { + SMP_TRACE_DEBUG("State change: %s(%d) ==> %s(%d)", + smp_get_state_name(smp_cb.state), smp_cb.state, + smp_get_state_name(state), state); + smp_cb.state = state; + } else { + SMP_TRACE_DEBUG("smp_set_state invalid state =%d", state); + } } /******************************************************************************* * Function smp_get_state * Returns The smp state ******************************************************************************/ -tSMP_STATE smp_get_state(void) -{ - return smp_cb.state; -} +tSMP_STATE smp_get_state(void) { return smp_cb.state; } /******************************************************************************* * @@ -965,96 +950,83 @@ tSMP_STATE smp_get_state(void) * Returns void. * ******************************************************************************/ -void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data) -{ - uint8_t curr_state = p_cb->state; - tSMP_SM_TBL state_table; - uint8_t action, entry, i; - tSMP_ENTRY_TBL entry_table = smp_entry_table[p_cb->role]; - - SMP_TRACE_EVENT("main smp_sm_event"); - if (curr_state >= SMP_STATE_MAX) - { - SMP_TRACE_DEBUG( "Invalid state: %d", curr_state) ; - return; +void smp_sm_event(tSMP_CB* p_cb, tSMP_EVENT event, void* p_data) { + uint8_t curr_state = p_cb->state; + tSMP_SM_TBL state_table; + uint8_t action, entry, i; + tSMP_ENTRY_TBL entry_table = smp_entry_table[p_cb->role]; + + SMP_TRACE_EVENT("main smp_sm_event"); + if (curr_state >= SMP_STATE_MAX) { + SMP_TRACE_DEBUG("Invalid state: %d", curr_state); + return; + } + + SMP_TRACE_DEBUG("SMP Role: %s State: [%s (%d)], Event: [%s (%d)]", + (p_cb->role == 0x01) ? "Slave" : "Master", + smp_get_state_name(p_cb->state), p_cb->state, + smp_get_event_name(event), event); + + /* look up the state table for the current state */ + /* lookup entry /w event & curr_state */ + /* If entry is ignore, return. + * Otherwise, get state table (according to curr_state or all_state) */ + if ((event <= SMP_MAX_EVT) && + ((entry = entry_table[event - 1][curr_state]) != SMP_SM_IGNORE)) { + if (entry & SMP_ALL_TBL_MASK) { + entry &= ~SMP_ALL_TBL_MASK; + state_table = smp_all_table; + } else + state_table = smp_state_table[curr_state][p_cb->role]; + } else { + SMP_TRACE_DEBUG("Ignore event [%s (%d)] in state [%s (%d)]", + smp_get_event_name(event), event, + smp_get_state_name(curr_state), curr_state); + return; + } + + /* Get possible next state from state table. */ + + smp_set_state(state_table[entry - 1][SMP_SME_NEXT_STATE]); + + /* If action is not ignore, clear param, exec action and get next state. + * The action function may set the Param for cback. + * Depending on param, call cback or free buffer. */ + /* execute action */ + /* execute action functions */ + for (i = 0; i < SMP_NUM_ACTIONS; i++) { + action = state_table[entry - 1][i]; + if (action != SMP_SM_NO_ACTION) { + (*smp_sm_action[action])(p_cb, (tSMP_INT_DATA*)p_data); + } else { + break; } - - SMP_TRACE_DEBUG( "SMP Role: %s State: [%s (%d)], Event: [%s (%d)]",\ - (p_cb->role == 0x01) ?"Slave" : "Master", smp_get_state_name( p_cb->state), - p_cb->state, smp_get_event_name(event), event) ; - - /* look up the state table for the current state */ - /* lookup entry /w event & curr_state */ - /* If entry is ignore, return. - * Otherwise, get state table (according to curr_state or all_state) */ - if ((event <= SMP_MAX_EVT) && ( (entry = entry_table[event - 1][curr_state]) != SMP_SM_IGNORE )) - { - if (entry & SMP_ALL_TBL_MASK) - { - entry &= ~SMP_ALL_TBL_MASK; - state_table = smp_all_table; - } - else - state_table = smp_state_table[curr_state][p_cb->role]; - } - else - { - SMP_TRACE_DEBUG( "Ignore event [%s (%d)] in state [%s (%d)]", - smp_get_event_name(event), event, smp_get_state_name(curr_state), - curr_state); - return; - } - - /* Get possible next state from state table. */ - - smp_set_state(state_table[entry-1][SMP_SME_NEXT_STATE]); - - /* If action is not ignore, clear param, exec action and get next state. - * The action function may set the Param for cback. - * Depending on param, call cback or free buffer. */ - /* execute action */ - /* execute action functions */ - for (i = 0; i < SMP_NUM_ACTIONS; i++) - { - action = state_table[entry - 1][i]; - if (action != SMP_SM_NO_ACTION) - { - (*smp_sm_action[action])(p_cb, (tSMP_INT_DATA *)p_data); - } - else - { - break; - } - } - SMP_TRACE_DEBUG( "result state = %s", smp_get_state_name( p_cb->state ) ) ; + } + SMP_TRACE_DEBUG("result state = %s", smp_get_state_name(p_cb->state)); } /******************************************************************************* * Function smp_get_state_name * Returns The smp state name. ******************************************************************************/ -const char * smp_get_state_name(tSMP_STATE state) -{ - const char *p_str = smp_state_name[SMP_STATE_MAX]; +const char* smp_get_state_name(tSMP_STATE state) { + const char* p_str = smp_state_name[SMP_STATE_MAX]; - if (state < SMP_STATE_MAX) - { - p_str = smp_state_name[state]; - } - return p_str; + if (state < SMP_STATE_MAX) { + p_str = smp_state_name[state]; + } + return p_str; } /******************************************************************************* * Function smp_get_event_name * Returns The smp event name. ******************************************************************************/ -const char * smp_get_event_name(tSMP_EVENT event) -{ - const char *p_str = smp_event_name[SMP_MAX_EVT]; +const char* smp_get_event_name(tSMP_EVENT event) { + const char* p_str = smp_event_name[SMP_MAX_EVT]; - if (event <= SMP_MAX_EVT) - { - p_str = smp_event_name[event- 1]; - } - return p_str; + if (event <= SMP_MAX_EVT) { + p_str = smp_event_name[event - 1]; + } + return p_str; } diff --git a/stack/smp/smp_utils.cc b/stack/smp/smp_utils.cc index 75c1655ea..8b0b4724f 100644 --- a/stack/smp/smp_utils.cc +++ b/stack/smp/smp_utils.cc @@ -23,69 +23,67 @@ ******************************************************************************/ #include "bt_target.h" +#include +#include #include "bt_types.h" #include "bt_utils.h" -#include -#include -#include "hcidefs.h" #include "btm_ble_api.h" +#include "btm_int.h" +#include "device/include/controller.h" +#include "hcidefs.h" #include "l2c_api.h" #include "l2c_int.h" -#include "smp_int.h" -#include "device/include/controller.h" -#include "btm_int.h" #include "osi/include/osi.h" +#include "smp_int.h" - -extern fixed_queue_t *btu_general_alarm_queue; - -#define SMP_PAIRING_REQ_SIZE 7 -#define SMP_CONFIRM_CMD_SIZE (BT_OCTET16_LEN + 1) -#define SMP_RAND_CMD_SIZE (BT_OCTET16_LEN + 1) -#define SMP_INIT_CMD_SIZE (BT_OCTET16_LEN + 1) -#define SMP_ENC_INFO_SIZE (BT_OCTET16_LEN + 1) -#define SMP_MASTER_ID_SIZE (BT_OCTET8_LEN + 2 + 1) -#define SMP_ID_INFO_SIZE (BT_OCTET16_LEN + 1) -#define SMP_ID_ADDR_SIZE (BD_ADDR_LEN + 1 + 1) -#define SMP_SIGN_INFO_SIZE (BT_OCTET16_LEN + 1) -#define SMP_PAIR_FAIL_SIZE 2 -#define SMP_SECURITY_REQUEST_SIZE 2 -#define SMP_PAIR_PUBL_KEY_SIZE (1 /* opcode */ + (2*BT_OCTET32_LEN)) -#define SMP_PAIR_COMMITM_SIZE (1 /* opcode */ + BT_OCTET16_LEN /*Commitment*/) -#define SMP_PAIR_DHKEY_CHECK_SIZE (1 /* opcode */ + BT_OCTET16_LEN /*DHKey Check*/) -#define SMP_PAIR_KEYPR_NOTIF_SIZE (1 /* opcode */ + 1 /*Notif Type*/) +extern fixed_queue_t* btu_general_alarm_queue; + +#define SMP_PAIRING_REQ_SIZE 7 +#define SMP_CONFIRM_CMD_SIZE (BT_OCTET16_LEN + 1) +#define SMP_RAND_CMD_SIZE (BT_OCTET16_LEN + 1) +#define SMP_INIT_CMD_SIZE (BT_OCTET16_LEN + 1) +#define SMP_ENC_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_MASTER_ID_SIZE (BT_OCTET8_LEN + 2 + 1) +#define SMP_ID_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_ID_ADDR_SIZE (BD_ADDR_LEN + 1 + 1) +#define SMP_SIGN_INFO_SIZE (BT_OCTET16_LEN + 1) +#define SMP_PAIR_FAIL_SIZE 2 +#define SMP_SECURITY_REQUEST_SIZE 2 +#define SMP_PAIR_PUBL_KEY_SIZE (1 /* opcode */ + (2 * BT_OCTET32_LEN)) +#define SMP_PAIR_COMMITM_SIZE (1 /* opcode */ + BT_OCTET16_LEN /*Commitment*/) +#define SMP_PAIR_DHKEY_CHECK_SIZE \ + (1 /* opcode */ + BT_OCTET16_LEN /*DHKey Check*/) +#define SMP_PAIR_KEYPR_NOTIF_SIZE (1 /* opcode */ + 1 /*Notif Type*/) /* SMP command sizes per spec */ -static const uint8_t smp_cmd_size_per_spec[] = -{ +static const uint8_t smp_cmd_size_per_spec[] = { 0, - SMP_PAIRING_REQ_SIZE, /* 0x01: pairing request */ - SMP_PAIRING_REQ_SIZE, /* 0x02: pairing response */ - SMP_CONFIRM_CMD_SIZE, /* 0x03: pairing confirm */ - SMP_RAND_CMD_SIZE, /* 0x04: pairing random */ - SMP_PAIR_FAIL_SIZE, /* 0x05: pairing failed */ - SMP_ENC_INFO_SIZE, /* 0x06: encryption information */ - SMP_MASTER_ID_SIZE, /* 0x07: master identification */ - SMP_ID_INFO_SIZE, /* 0x08: identity information */ - SMP_ID_ADDR_SIZE, /* 0x09: identity address information */ - SMP_SIGN_INFO_SIZE, /* 0x0A: signing information */ - SMP_SECURITY_REQUEST_SIZE, /* 0x0B: security request */ - SMP_PAIR_PUBL_KEY_SIZE, /* 0x0C: pairing public key */ - SMP_PAIR_DHKEY_CHECK_SIZE, /* 0x0D: pairing dhkey check */ - SMP_PAIR_KEYPR_NOTIF_SIZE, /* 0x0E: pairing keypress notification */ - SMP_PAIR_COMMITM_SIZE /* 0x0F: pairing commitment */ + SMP_PAIRING_REQ_SIZE, /* 0x01: pairing request */ + SMP_PAIRING_REQ_SIZE, /* 0x02: pairing response */ + SMP_CONFIRM_CMD_SIZE, /* 0x03: pairing confirm */ + SMP_RAND_CMD_SIZE, /* 0x04: pairing random */ + SMP_PAIR_FAIL_SIZE, /* 0x05: pairing failed */ + SMP_ENC_INFO_SIZE, /* 0x06: encryption information */ + SMP_MASTER_ID_SIZE, /* 0x07: master identification */ + SMP_ID_INFO_SIZE, /* 0x08: identity information */ + SMP_ID_ADDR_SIZE, /* 0x09: identity address information */ + SMP_SIGN_INFO_SIZE, /* 0x0A: signing information */ + SMP_SECURITY_REQUEST_SIZE, /* 0x0B: security request */ + SMP_PAIR_PUBL_KEY_SIZE, /* 0x0C: pairing public key */ + SMP_PAIR_DHKEY_CHECK_SIZE, /* 0x0D: pairing dhkey check */ + SMP_PAIR_KEYPR_NOTIF_SIZE, /* 0x0E: pairing keypress notification */ + SMP_PAIR_COMMITM_SIZE /* 0x0F: pairing commitment */ }; -static bool smp_parameter_unconditionally_valid(tSMP_CB *p_cb); -static bool smp_parameter_unconditionally_invalid(tSMP_CB *p_cb); +static bool smp_parameter_unconditionally_valid(tSMP_CB* p_cb); +static bool smp_parameter_unconditionally_invalid(tSMP_CB* p_cb); /* type for SMP command length validation functions */ -typedef bool (*tSMP_CMD_LEN_VALID)(tSMP_CB *p_cb); +typedef bool (*tSMP_CMD_LEN_VALID)(tSMP_CB* p_cb); -static bool smp_command_has_valid_fixed_length(tSMP_CB *p_cb); +static bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb); -static const tSMP_CMD_LEN_VALID smp_cmd_len_is_valid[] = -{ +static const tSMP_CMD_LEN_VALID smp_cmd_len_is_valid[] = { smp_parameter_unconditionally_invalid, smp_command_has_valid_fixed_length, /* 0x01: pairing request */ smp_command_has_valid_fixed_length, /* 0x02: pairing response */ @@ -100,58 +98,72 @@ static const tSMP_CMD_LEN_VALID smp_cmd_len_is_valid[] = smp_command_has_valid_fixed_length, /* 0x0B: security request */ smp_command_has_valid_fixed_length, /* 0x0C: pairing public key */ smp_command_has_valid_fixed_length, /* 0x0D: pairing dhkey check */ - smp_command_has_valid_fixed_length, /* 0x0E: pairing keypress notification */ + smp_command_has_valid_fixed_length, /* 0x0E: pairing keypress notification + */ smp_command_has_valid_fixed_length /* 0x0F: pairing commitment */ }; /* type for SMP command parameter ranges validation functions */ -typedef bool (*tSMP_CMD_PARAM_RANGES_VALID)(tSMP_CB *p_cb); +typedef bool (*tSMP_CMD_PARAM_RANGES_VALID)(tSMP_CB* p_cb); -static bool smp_pairing_request_response_parameters_are_valid(tSMP_CB *p_cb); -static bool smp_pairing_keypress_notification_is_valid(tSMP_CB *p_cb); +static bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb); +static bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb); -static const tSMP_CMD_PARAM_RANGES_VALID smp_cmd_param_ranges_are_valid[] = -{ +static const tSMP_CMD_PARAM_RANGES_VALID smp_cmd_param_ranges_are_valid[] = { smp_parameter_unconditionally_invalid, - smp_pairing_request_response_parameters_are_valid, /* 0x01: pairing request */ - smp_pairing_request_response_parameters_are_valid, /* 0x02: pairing response */ + smp_pairing_request_response_parameters_are_valid, /* 0x01: pairing + request */ + smp_pairing_request_response_parameters_are_valid, /* 0x02: pairing + response */ smp_parameter_unconditionally_valid, /* 0x03: pairing confirm */ smp_parameter_unconditionally_valid, /* 0x04: pairing random */ smp_parameter_unconditionally_valid, /* 0x05: pairing failed */ smp_parameter_unconditionally_valid, /* 0x06: encryption information */ smp_parameter_unconditionally_valid, /* 0x07: master identification */ smp_parameter_unconditionally_valid, /* 0x08: identity information */ - smp_parameter_unconditionally_valid, /* 0x09: identity address information */ + smp_parameter_unconditionally_valid, /* 0x09: identity address + information */ smp_parameter_unconditionally_valid, /* 0x0A: signing information */ smp_parameter_unconditionally_valid, /* 0x0B: security request */ smp_parameter_unconditionally_valid, /* 0x0C: pairing public key */ smp_parameter_unconditionally_valid, /* 0x0D: pairing dhkey check */ - smp_pairing_keypress_notification_is_valid, /* 0x0E: pairing keypress notification */ - smp_parameter_unconditionally_valid /* 0x0F: pairing commitment */ + smp_pairing_keypress_notification_is_valid, /* 0x0E: pairing keypress + notification */ + smp_parameter_unconditionally_valid /* 0x0F: pairing commitment */ }; /* type for action functions */ -typedef BT_HDR * (*tSMP_CMD_ACT)(uint8_t cmd_code, tSMP_CB *p_cb); - -static BT_HDR *smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_confirm_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_pairing_fail(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_identity_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_encrypt_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_security_request(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_signing_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_master_id_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_id_addr_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_pair_public_key_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_pairing_commitment_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_pair_dhkey_check_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); -static BT_HDR *smp_build_pairing_keypress_notification_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb); - -static const tSMP_CMD_ACT smp_cmd_build_act[] = -{ - NULL, - smp_build_pairing_cmd, /* 0x01: pairing request */ +typedef BT_HDR* (*tSMP_CMD_ACT)(uint8_t cmd_code, tSMP_CB* p_cb); + +static BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb); +static BT_HDR* smp_build_confirm_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb); +static BT_HDR* smp_build_pairing_fail(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_identity_info_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_encrypt_info_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_security_request(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_signing_info_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_master_id_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_id_addr_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_pair_public_key_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_pairing_commitment_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_pair_dhkey_check_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb); +static BT_HDR* smp_build_pairing_keypress_notification_cmd( + UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb); + +static const tSMP_CMD_ACT smp_cmd_build_act[] = { + NULL, smp_build_pairing_cmd, /* 0x01: pairing request */ smp_build_pairing_cmd, /* 0x02: pairing response */ smp_build_confirm_cmd, /* 0x03: pairing confirm */ smp_build_rand_cmd, /* 0x04: pairing random */ @@ -164,114 +176,126 @@ static const tSMP_CMD_ACT smp_cmd_build_act[] = smp_build_security_request, /* 0x0B: security request */ smp_build_pair_public_key_cmd, /* 0x0C: pairing public key */ smp_build_pair_dhkey_check_cmd, /* 0x0D: pairing DHKey check */ - smp_build_pairing_keypress_notification_cmd, /* 0x0E: pairing keypress notification */ - smp_build_pairing_commitment_cmd /* 0x0F: pairing commitment */ + smp_build_pairing_keypress_notification_cmd, /* 0x0E: pairing keypress + notification */ + smp_build_pairing_commitment_cmd /* 0x0F: pairing commitment */ }; static const uint8_t smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = -{ - /* display only */ /* Display Yes/No */ /* keyboard only */ - /* No Input/Output */ /* keyboard display */ - - /* initiator */ - /* model = tbl[peer_io_caps][loc_io_caps] */ - /* Display Only */ - {{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, - - /* Display Yes/No */ - {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, - - /* Keyboard only */ - {SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, - - /* No Input No Output */ - {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY}, - - /* keyboard display */ - {SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}}, - - /* responder */ - /* model = tbl[loc_io_caps][peer_io_caps] */ - /* Display Only */ - {{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, - - /* Display Yes/No */ - {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, - - /* keyboard only */ - {SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, - - /* No Input No Output */ - {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY}, - - /* keyboard display */ - {SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_KEY_NOTIF, - SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}} -}; - -static const uint8_t smp_association_table_sc[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = -{ - /* display only */ /* Display Yes/No */ /* keyboard only */ - /* No InputOutput */ /* keyboard display */ - - /* initiator */ - /* model = tbl[peer_io_caps][loc_io_caps] */ - - /* Display Only */ - {{SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_ENT, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_ENT}, - - /* Display Yes/No */ - {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP, SMP_MODEL_SEC_CONN_PASSKEY_ENT, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP}, - - /* keyboard only */ - {SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_PASSKEY_ENT, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_DISP}, - - /* No Input No Output */ - {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS}, - - /* keyboard display */ - {SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_NUM_COMP, SMP_MODEL_SEC_CONN_PASSKEY_ENT, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP}}, - - /* responder */ - /* model = tbl[loc_io_caps][peer_io_caps] */ - - /* Display Only */ - {{SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_DISP, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_DISP}, - - /* Display Yes/No */ - {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP, SMP_MODEL_SEC_CONN_PASSKEY_DISP, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP}, - - /* keyboard only */ - {SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_PASSKEY_ENT, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_PASSKEY_ENT}, - - /* No Input No Output */ - {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS}, - - /* keyboard display */ - {SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_NUM_COMP, SMP_MODEL_SEC_CONN_PASSKEY_DISP, - SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP}} -}; - -static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB *p_cb); -static tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB *p_cb); + { + /* display only */ /* Display Yes/No */ /* keyboard only */ + /* No Input/Output */ /* keyboard display */ + + /* initiator */ + /* model = tbl[peer_io_caps][loc_io_caps] */ + /* Display Only */ + {{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, + + /* Display Yes/No */ + {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, + + /* Keyboard only */ + {SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, + + /* No Input No Output */ + {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_ENCRYPTION_ONLY}, + + /* keyboard display */ + {SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}}, + + /* responder */ + /* model = tbl[loc_io_caps][peer_io_caps] */ + /* Display Only */ + {{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, + + /* Display Yes/No */ + {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}, + + /* keyboard only */ + {SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}, + + /* No Input No Output */ + {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, + SMP_MODEL_ENCRYPTION_ONLY}, + + /* keyboard display */ + {SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_KEY_NOTIF, + SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}}}; + +static const uint8_t + smp_association_table_sc[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = { + /* display only */ /* Display Yes/No */ /* keyboard only */ + /* No InputOutput */ /* keyboard display */ + + /* initiator */ + /* model = tbl[peer_io_caps][loc_io_caps] */ + + /* Display Only */ + {{SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_ENT}, + + /* Display Yes/No */ + {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP, + SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_NUM_COMP}, + + /* keyboard only */ + {SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_PASSKEY_DISP, + SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_DISP}, + + /* No Input No Output */ + {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_JUSTWORKS}, + + /* keyboard display */ + {SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_NUM_COMP, + SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_NUM_COMP}}, + + /* responder */ + /* model = tbl[loc_io_caps][peer_io_caps] */ + + /* Display Only */ + {{SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_DISP}, + + /* Display Yes/No */ + {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_NUM_COMP, + SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_NUM_COMP}, + + /* keyboard only */ + {SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_PASSKEY_ENT, + SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_PASSKEY_ENT}, + + /* No Input No Output */ + {SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_JUSTWORKS, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_JUSTWORKS}, + + /* keyboard display */ + {SMP_MODEL_SEC_CONN_PASSKEY_ENT, SMP_MODEL_SEC_CONN_NUM_COMP, + SMP_MODEL_SEC_CONN_PASSKEY_DISP, SMP_MODEL_SEC_CONN_JUSTWORKS, + SMP_MODEL_SEC_CONN_NUM_COMP}}}; + +static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb); +static tSMP_ASSO_MODEL smp_select_association_model_secure_connections( + tSMP_CB* p_cb); /******************************************************************************* * @@ -280,29 +304,25 @@ static tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB * * Description Send message to L2CAP. * ******************************************************************************/ -bool smp_send_msg_to_L2CAP(BD_ADDR rem_bda, BT_HDR *p_toL2CAP) -{ - uint16_t l2cap_ret; - uint16_t fixed_cid = L2CAP_SMP_CID; - - if (smp_cb.smp_over_br) - { - fixed_cid = L2CAP_SMP_BR_CID; - } - - SMP_TRACE_EVENT("%s", __func__); - smp_cb.total_tx_unacked += 1; - - l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP); - if (l2cap_ret == L2CAP_DW_FAILED) - { - smp_cb.total_tx_unacked -= 1; - SMP_TRACE_ERROR("SMP failed to pass msg:0x%0x to L2CAP", - *((uint8_t *)(p_toL2CAP + 1) + p_toL2CAP->offset)); - return false; - } - else - return true; +bool smp_send_msg_to_L2CAP(BD_ADDR rem_bda, BT_HDR* p_toL2CAP) { + uint16_t l2cap_ret; + uint16_t fixed_cid = L2CAP_SMP_CID; + + if (smp_cb.smp_over_br) { + fixed_cid = L2CAP_SMP_BR_CID; + } + + SMP_TRACE_EVENT("%s", __func__); + smp_cb.total_tx_unacked += 1; + + l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP); + if (l2cap_ret == L2CAP_DW_FAILED) { + smp_cb.total_tx_unacked -= 1; + SMP_TRACE_ERROR("SMP failed to pass msg:0x%0x to L2CAP", + *((uint8_t*)(p_toL2CAP + 1) + p_toL2CAP->offset)); + return false; + } else + return true; } /******************************************************************************* @@ -312,39 +332,30 @@ bool smp_send_msg_to_L2CAP(BD_ADDR rem_bda, BT_HDR *p_toL2CAP) * Description send a SMP command on L2CAP channel. * ******************************************************************************/ -bool smp_send_cmd(uint8_t cmd_code, tSMP_CB *p_cb) -{ - BT_HDR *p_buf; - bool sent = false; - uint8_t failure = SMP_PAIR_INTERNAL_ERR; - SMP_TRACE_EVENT("smp_send_cmd on l2cap cmd_code=0x%x", cmd_code); - if ( cmd_code <= (SMP_OPCODE_MAX + 1 /* for SMP_OPCODE_PAIR_COMMITM */) && - smp_cmd_build_act[cmd_code] != NULL) - { - p_buf = (*smp_cmd_build_act[cmd_code])(cmd_code, p_cb); - - if (p_buf != NULL && - smp_send_msg_to_L2CAP(p_cb->pairing_bda, p_buf)) - { - sent = true; - alarm_set_on_queue(p_cb->smp_rsp_timer_ent, - SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, - NULL, btu_general_alarm_queue); - } +bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb) { + BT_HDR* p_buf; + bool sent = false; + uint8_t failure = SMP_PAIR_INTERNAL_ERR; + SMP_TRACE_EVENT("smp_send_cmd on l2cap cmd_code=0x%x", cmd_code); + if (cmd_code <= (SMP_OPCODE_MAX + 1 /* for SMP_OPCODE_PAIR_COMMITM */) && + smp_cmd_build_act[cmd_code] != NULL) { + p_buf = (*smp_cmd_build_act[cmd_code])(cmd_code, p_cb); + + if (p_buf != NULL && smp_send_msg_to_L2CAP(p_cb->pairing_bda, p_buf)) { + sent = true; + alarm_set_on_queue(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, + smp_rsp_timeout, NULL, btu_general_alarm_queue); } + } - if (!sent) - { - if (p_cb->smp_over_br) - { - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); - } - else - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - } + if (!sent) { + if (p_cb->smp_over_br) { + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); + } else { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); } - return sent; + } + return sent; } /******************************************************************************* @@ -356,21 +367,18 @@ bool smp_send_cmd(uint8_t cmd_code, tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_rsp_timeout(UNUSED_ATTR void *data) -{ - tSMP_CB *p_cb = &smp_cb; - uint8_t failure = SMP_RSP_TIMEOUT; - - SMP_TRACE_EVENT("%s state:%d br_state:%d", __func__, p_cb->state, p_cb->br_state); - - if (p_cb->smp_over_br) - { - smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); - } - else - { - smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); - } +void smp_rsp_timeout(UNUSED_ATTR void* data) { + tSMP_CB* p_cb = &smp_cb; + uint8_t failure = SMP_RSP_TIMEOUT; + + SMP_TRACE_EVENT("%s state:%d br_state:%d", __func__, p_cb->state, + p_cb->br_state); + + if (p_cb->smp_over_br) { + smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure); + } else { + smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure); + } } /******************************************************************************* @@ -383,18 +391,16 @@ void smp_rsp_timeout(UNUSED_ATTR void *data) * Returns void * ******************************************************************************/ -void smp_delayed_auth_complete_timeout(UNUSED_ATTR void *data) -{ - /* - * Waited for potential pair failure. Send SMP_AUTH_CMPL_EVT if - * the state is still in bond pending. - */ - if (smp_get_state() == SMP_STATE_BOND_PENDING) - { - uint8_t reason = SMP_SUCCESS; - SMP_TRACE_EVENT("%s sending delayed auth complete.", __func__); - smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &reason); - } +void smp_delayed_auth_complete_timeout(UNUSED_ATTR void* data) { + /* + * Waited for potential pair failure. Send SMP_AUTH_CMPL_EVT if + * the state is still in bond pending. + */ + if (smp_get_state() == SMP_STATE_BOND_PENDING) { + uint8_t reason = SMP_SUCCESS; + SMP_TRACE_EVENT("%s sending delayed auth complete.", __func__); + smp_sm_event(&smp_cb, SMP_AUTH_CMPL_EVT, &reason); + } } /******************************************************************************* @@ -404,28 +410,27 @@ void smp_delayed_auth_complete_timeout(UNUSED_ATTR void *data) * Description Build pairing request command. * ******************************************************************************/ -BT_HDR * smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIRING_REQ_SIZE + L2CAP_MIN_OFFSET); - - SMP_TRACE_EVENT("%s", __func__); - - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, cmd_code); - UINT8_TO_STREAM(p, p_cb->local_io_capability); - UINT8_TO_STREAM(p, p_cb->loc_oob_flag); - UINT8_TO_STREAM(p, p_cb->loc_auth_req); - UINT8_TO_STREAM(p, p_cb->loc_enc_size); - UINT8_TO_STREAM(p, p_cb->local_i_key); - UINT8_TO_STREAM(p, p_cb->local_r_key); - - p_buf->offset = L2CAP_MIN_OFFSET; - /* 1B ERR_RSP op code + 1B cmd_op_code + 2B handle + 1B status */ - p_buf->len = SMP_PAIRING_REQ_SIZE; - - return p_buf; +BT_HDR* smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_PAIRING_REQ_SIZE + + L2CAP_MIN_OFFSET); + + SMP_TRACE_EVENT("%s", __func__); + + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, cmd_code); + UINT8_TO_STREAM(p, p_cb->local_io_capability); + UINT8_TO_STREAM(p, p_cb->loc_oob_flag); + UINT8_TO_STREAM(p, p_cb->loc_auth_req); + UINT8_TO_STREAM(p, p_cb->loc_enc_size); + UINT8_TO_STREAM(p, p_cb->local_i_key); + UINT8_TO_STREAM(p, p_cb->local_r_key); + + p_buf->offset = L2CAP_MIN_OFFSET; + /* 1B ERR_RSP op code + 1B cmd_op_code + 2B handle + 1B status */ + p_buf->len = SMP_PAIRING_REQ_SIZE; + + return p_buf; } /******************************************************************************* @@ -435,23 +440,23 @@ BT_HDR * smp_build_pairing_cmd(uint8_t cmd_code, tSMP_CB *p_cb) * Description Build confirm request command. * ******************************************************************************/ -static BT_HDR * smp_build_confirm_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_CONFIRM_CMD_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_confirm_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_CONFIRM_CMD_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_CONFIRM); - ARRAY_TO_STREAM(p, p_cb->confirm, BT_OCTET16_LEN); + UINT8_TO_STREAM(p, SMP_OPCODE_CONFIRM); + ARRAY_TO_STREAM(p, p_cb->confirm, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_CONFIRM_CMD_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_CONFIRM_CMD_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -461,22 +466,21 @@ static BT_HDR * smp_build_confirm_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_c * Description Build Random command. * ******************************************************************************/ -static BT_HDR * smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_RAND_CMD_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_RAND_CMD_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_RAND); - ARRAY_TO_STREAM(p, p_cb->rand, BT_OCTET16_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_RAND); + ARRAY_TO_STREAM(p, p_cb->rand, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_RAND_CMD_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_RAND_CMD_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -486,22 +490,22 @@ static BT_HDR * smp_build_rand_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) * Description Build security information command. * ******************************************************************************/ -static BT_HDR * smp_build_encrypt_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_ENC_INFO_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_encrypt_info_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_ENC_INFO_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_ENCRYPT_INFO); - ARRAY_TO_STREAM(p, p_cb->ltk, BT_OCTET16_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_ENCRYPT_INFO); + ARRAY_TO_STREAM(p, p_cb->ltk, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_ENC_INFO_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_ENC_INFO_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -511,23 +515,23 @@ static BT_HDR * smp_build_encrypt_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB * Description Build security information command. * ******************************************************************************/ -static BT_HDR * smp_build_master_id_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_MASTER_ID_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_master_id_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_MASTER_ID_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_MASTER_ID); - UINT16_TO_STREAM(p, p_cb->ediv); - ARRAY_TO_STREAM(p, p_cb->enc_rand, BT_OCTET8_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_MASTER_ID); + UINT16_TO_STREAM(p, p_cb->ediv); + ARRAY_TO_STREAM(p, p_cb->enc_rand, BT_OCTET8_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_MASTER_ID_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_MASTER_ID_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -537,27 +541,26 @@ static BT_HDR * smp_build_master_id_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p * Description Build identity information command. * ******************************************************************************/ -static BT_HDR * smp_build_identity_info_cmd(UNUSED_ATTR uint8_t cmd_code, - UNUSED_ATTR tSMP_CB *p_cb) -{ - uint8_t *p; - BT_OCTET16 irk; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_ID_INFO_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_identity_info_cmd(UNUSED_ATTR uint8_t cmd_code, + UNUSED_ATTR tSMP_CB* p_cb) { + uint8_t* p; + BT_OCTET16 irk; + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_ID_INFO_SIZE + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; - BTM_GetDeviceIDRoot(irk); + BTM_GetDeviceIDRoot(irk); - UINT8_TO_STREAM(p, SMP_OPCODE_IDENTITY_INFO); - ARRAY_TO_STREAM(p, irk, BT_OCTET16_LEN); + UINT8_TO_STREAM(p, SMP_OPCODE_IDENTITY_INFO); + ARRAY_TO_STREAM(p, irk, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_ID_INFO_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_ID_INFO_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -567,24 +570,23 @@ static BT_HDR * smp_build_identity_info_cmd(UNUSED_ATTR uint8_t cmd_code, * Description Build identity address information command. * ******************************************************************************/ -static BT_HDR * smp_build_id_addr_cmd(UNUSED_ATTR uint8_t cmd_code, - UNUSED_ATTR tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_ID_ADDR_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_id_addr_cmd(UNUSED_ATTR uint8_t cmd_code, + UNUSED_ATTR tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = + (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_ID_ADDR_SIZE + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_ID_ADDR); - UINT8_TO_STREAM(p, 0); - BDADDR_TO_STREAM(p, controller_get_interface()->get_address()->address); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_ID_ADDR); + UINT8_TO_STREAM(p, 0); + BDADDR_TO_STREAM(p, controller_get_interface()->get_address()->address); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_ID_ADDR_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_ID_ADDR_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -594,22 +596,22 @@ static BT_HDR * smp_build_id_addr_cmd(UNUSED_ATTR uint8_t cmd_code, * Description Build signing information command. * ******************************************************************************/ -static BT_HDR * smp_build_signing_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_SIGN_INFO_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_signing_info_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_SIGN_INFO_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_SIGN_INFO); - ARRAY_TO_STREAM(p, p_cb->csrk, BT_OCTET16_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_SIGN_INFO); + ARRAY_TO_STREAM(p, p_cb->csrk, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_SIGN_INFO_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_SIGN_INFO_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -619,22 +621,22 @@ static BT_HDR * smp_build_signing_info_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB * Description Build Pairing Fail command. * ******************************************************************************/ -static BT_HDR * smp_build_pairing_fail(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_pairing_fail(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_FAIL_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_PAIRING_FAILED); - UINT8_TO_STREAM(p, p_cb->failure); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_PAIRING_FAILED); + UINT8_TO_STREAM(p, p_cb->failure); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_FAIL_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_FAIL_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -644,24 +646,24 @@ static BT_HDR * smp_build_pairing_fail(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_ * Description Build security request command. * ******************************************************************************/ -static BT_HDR *smp_build_security_request(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - 2 + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_security_request(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + 2 + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_SEC_REQ); - UINT8_TO_STREAM(p, p_cb->loc_auth_req); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_SEC_REQ); + UINT8_TO_STREAM(p, p_cb->loc_auth_req); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_SECURITY_REQUEST_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_SECURITY_REQUEST_SIZE; - SMP_TRACE_EVENT("opcode=%d auth_req=0x%x",SMP_OPCODE_SEC_REQ, p_cb->loc_auth_req ); + SMP_TRACE_EVENT("opcode=%d auth_req=0x%x", SMP_OPCODE_SEC_REQ, + p_cb->loc_auth_req); - return p_buf; + return p_buf; } /******************************************************************************* @@ -671,27 +673,27 @@ static BT_HDR *smp_build_security_request(UNUSED_ATTR uint8_t cmd_code, tSMP_CB * Description Build pairing public key command. * ******************************************************************************/ -static BT_HDR *smp_build_pair_public_key_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - uint8_t publ_key[2*BT_OCTET32_LEN]; - uint8_t *p_publ_key = publ_key; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_PUBL_KEY_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_pair_public_key_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + uint8_t publ_key[2 * BT_OCTET32_LEN]; + uint8_t* p_publ_key = publ_key; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_PUBL_KEY_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - memcpy(p_publ_key, p_cb->loc_publ_key.x, BT_OCTET32_LEN); - memcpy(p_publ_key + BT_OCTET32_LEN, p_cb->loc_publ_key.y, BT_OCTET32_LEN); + memcpy(p_publ_key, p_cb->loc_publ_key.x, BT_OCTET32_LEN); + memcpy(p_publ_key + BT_OCTET32_LEN, p_cb->loc_publ_key.y, BT_OCTET32_LEN); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_PUBLIC_KEY); - ARRAY_TO_STREAM(p, p_publ_key, 2*BT_OCTET32_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_PUBLIC_KEY); + ARRAY_TO_STREAM(p, p_publ_key, 2 * BT_OCTET32_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_PUBL_KEY_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_PUBL_KEY_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -701,22 +703,22 @@ static BT_HDR *smp_build_pair_public_key_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_ * Description Build pairing commitment command. * ******************************************************************************/ -static BT_HDR *smp_build_pairing_commitment_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_COMMITM_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_pairing_commitment_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_COMMITM_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_CONFIRM); - ARRAY_TO_STREAM(p, p_cb->commitment, BT_OCTET16_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_CONFIRM); + ARRAY_TO_STREAM(p, p_cb->commitment, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_COMMITM_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_COMMITM_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -726,22 +728,22 @@ static BT_HDR *smp_build_pairing_commitment_cmd(UNUSED_ATTR uint8_t cmd_code, tS * Description Build pairing DHKey check command. * ******************************************************************************/ -static BT_HDR *smp_build_pair_dhkey_check_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_DHKEY_CHECK_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_pair_dhkey_check_cmd(UNUSED_ATTR uint8_t cmd_code, + tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc( + sizeof(BT_HDR) + SMP_PAIR_DHKEY_CHECK_SIZE + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_DHKEY_CHECK); - ARRAY_TO_STREAM(p, p_cb->dhkey_check, BT_OCTET16_LEN); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_DHKEY_CHECK); + ARRAY_TO_STREAM(p, p_cb->dhkey_check, BT_OCTET16_LEN); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_DHKEY_CHECK_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_DHKEY_CHECK_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -751,22 +753,22 @@ static BT_HDR *smp_build_pair_dhkey_check_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP * Description Build keypress notification command. * ******************************************************************************/ -static BT_HDR * smp_build_pairing_keypress_notification_cmd(UNUSED_ATTR uint8_t cmd_code, tSMP_CB *p_cb) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_KEYPR_NOTIF_SIZE + L2CAP_MIN_OFFSET); +static BT_HDR* smp_build_pairing_keypress_notification_cmd( + UNUSED_ATTR uint8_t cmd_code, tSMP_CB* p_cb) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc( + sizeof(BT_HDR) + SMP_PAIR_KEYPR_NOTIF_SIZE + L2CAP_MIN_OFFSET); - SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_EVENT("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_KEYPR_NOTIF); - UINT8_TO_STREAM(p, p_cb->local_keypress_notification); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_PAIR_KEYPR_NOTIF); + UINT8_TO_STREAM(p, p_cb->local_keypress_notification); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_KEYPR_NOTIF_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_KEYPR_NOTIF_SIZE; - return p_buf; + return p_buf; } /******************************************************************************* @@ -780,17 +782,16 @@ static BT_HDR * smp_build_pairing_keypress_notification_cmd(UNUSED_ATTR uint8_t * Returns void * ******************************************************************************/ -void smp_convert_string_to_tk(BT_OCTET16 tk, uint32_t passkey) -{ - uint8_t *p = tk; - tSMP_KEY key; - SMP_TRACE_EVENT("smp_convert_string_to_tk"); - UINT32_TO_STREAM(p, passkey); +void smp_convert_string_to_tk(BT_OCTET16 tk, uint32_t passkey) { + uint8_t* p = tk; + tSMP_KEY key; + SMP_TRACE_EVENT("smp_convert_string_to_tk"); + UINT32_TO_STREAM(p, passkey); - key.key_type = SMP_KEY_TYPE_TK; - key.p_data = tk; + key.key_type = SMP_KEY_TYPE_TK; + key.p_data = tk; - smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &key); + smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &key); } /******************************************************************************* @@ -804,15 +805,13 @@ void smp_convert_string_to_tk(BT_OCTET16 tk, uint32_t passkey) * Returns void * ******************************************************************************/ -void smp_mask_enc_key(uint8_t loc_enc_size, uint8_t * p_data) -{ - SMP_TRACE_EVENT("smp_mask_enc_key"); - if (loc_enc_size < BT_OCTET16_LEN) - { - for (; loc_enc_size < BT_OCTET16_LEN; loc_enc_size ++) - * (p_data + loc_enc_size) = 0; - } - return; +void smp_mask_enc_key(uint8_t loc_enc_size, uint8_t* p_data) { + SMP_TRACE_EVENT("smp_mask_enc_key"); + if (loc_enc_size < BT_OCTET16_LEN) { + for (; loc_enc_size < BT_OCTET16_LEN; loc_enc_size++) + *(p_data + loc_enc_size) = 0; + } + return; } /******************************************************************************* @@ -825,15 +824,13 @@ void smp_mask_enc_key(uint8_t loc_enc_size, uint8_t * p_data) * Returns void * ******************************************************************************/ -void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b) -{ - uint8_t i, *aa = a, *bb = b; +void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b) { + uint8_t i, *aa = a, *bb = b; - SMP_TRACE_EVENT("smp_xor_128"); - for (i = 0; i < BT_OCTET16_LEN; i++) - { - aa[i] = aa[i] ^ bb[i]; - } + SMP_TRACE_EVENT("smp_xor_128"); + for (i = 0; i < BT_OCTET16_LEN; i++) { + aa[i] = aa[i] ^ bb[i]; + } } /******************************************************************************* @@ -845,20 +842,19 @@ void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b) * Returns void * ******************************************************************************/ -void smp_cb_cleanup(tSMP_CB *p_cb) -{ - tSMP_CALLBACK *p_callback = p_cb->p_callback; - uint8_t trace_level = p_cb->trace_level; - - SMP_TRACE_EVENT("smp_cb_cleanup"); - - alarm_free(p_cb->smp_rsp_timer_ent); - alarm_free(p_cb->delayed_auth_timer_ent); - memset(p_cb, 0, sizeof(tSMP_CB)); - p_cb->p_callback = p_callback; - p_cb->trace_level = trace_level; - p_cb->smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent"); - p_cb->delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent"); +void smp_cb_cleanup(tSMP_CB* p_cb) { + tSMP_CALLBACK* p_callback = p_cb->p_callback; + uint8_t trace_level = p_cb->trace_level; + + SMP_TRACE_EVENT("smp_cb_cleanup"); + + alarm_free(p_cb->smp_rsp_timer_ent); + alarm_free(p_cb->delayed_auth_timer_ent); + memset(p_cb, 0, sizeof(tSMP_CB)); + p_cb->p_callback = p_callback; + p_cb->trace_level = trace_level; + p_cb->smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent"); + p_cb->delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent"); } /******************************************************************************* @@ -870,14 +866,13 @@ void smp_cb_cleanup(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_remove_fixed_channel(tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG("%s", __func__); - - if (p_cb->smp_over_br) - L2CA_RemoveFixedChnl (L2CAP_SMP_BR_CID, p_cb->pairing_bda); - else - L2CA_RemoveFixedChnl (L2CAP_SMP_CID, p_cb->pairing_bda); +void smp_remove_fixed_channel(tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->smp_over_br) + L2CA_RemoveFixedChnl(L2CAP_SMP_BR_CID, p_cb->pairing_bda); + else + L2CA_RemoveFixedChnl(L2CAP_SMP_CID, p_cb->pairing_bda); } /******************************************************************************* @@ -891,21 +886,21 @@ void smp_remove_fixed_channel(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_reset_control_value(tSMP_CB *p_cb) -{ - SMP_TRACE_EVENT("%s", __func__); - - alarm_cancel(p_cb->smp_rsp_timer_ent); - p_cb->flags = 0; - /* set the link idle timer to drop the link when pairing is done - usually service discovery will follow authentication complete, to avoid - racing condition for a link down/up, set link idle timer to be - SMP_LINK_TOUT_MIN to guarantee SMP key exchange */ - L2CA_SetIdleTimeoutByBdAddr(p_cb->pairing_bda, SMP_LINK_TOUT_MIN, BT_TRANSPORT_LE); - - /* We can tell L2CAP to remove the fixed channel (if it has one) */ - smp_remove_fixed_channel(p_cb); - smp_cb_cleanup(p_cb); +void smp_reset_control_value(tSMP_CB* p_cb) { + SMP_TRACE_EVENT("%s", __func__); + + alarm_cancel(p_cb->smp_rsp_timer_ent); + p_cb->flags = 0; + /* set the link idle timer to drop the link when pairing is done + usually service discovery will follow authentication complete, to avoid + racing condition for a link down/up, set link idle timer to be + SMP_LINK_TOUT_MIN to guarantee SMP key exchange */ + L2CA_SetIdleTimeoutByBdAddr(p_cb->pairing_bda, SMP_LINK_TOUT_MIN, + BT_TRANSPORT_LE); + + /* We can tell L2CAP to remove the fixed channel (if it has one) */ + smp_remove_fixed_channel(p_cb); + smp_cb_cleanup(p_cb); } /******************************************************************************* @@ -918,36 +913,30 @@ void smp_reset_control_value(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_proc_pairing_cmpl(tSMP_CB *p_cb) -{ - tSMP_EVT_DATA evt_data = {0}; - tSMP_CALLBACK *p_callback = p_cb->p_callback; - BD_ADDR pairing_bda; - - SMP_TRACE_DEBUG ("smp_proc_pairing_cmpl "); +void smp_proc_pairing_cmpl(tSMP_CB* p_cb) { + tSMP_EVT_DATA evt_data = {0}; + tSMP_CALLBACK* p_callback = p_cb->p_callback; + BD_ADDR pairing_bda; - evt_data.cmplt.reason = p_cb->status; - evt_data.cmplt.smp_over_br = p_cb->smp_over_br; + SMP_TRACE_DEBUG("smp_proc_pairing_cmpl "); - if (p_cb->status == SMP_SUCCESS) - evt_data.cmplt.sec_level = p_cb->sec_level; + evt_data.cmplt.reason = p_cb->status; + evt_data.cmplt.smp_over_br = p_cb->smp_over_br; - evt_data.cmplt.is_pair_cancel = false; + if (p_cb->status == SMP_SUCCESS) evt_data.cmplt.sec_level = p_cb->sec_level; - if (p_cb->is_pair_cancel) - evt_data.cmplt.is_pair_cancel = true; + evt_data.cmplt.is_pair_cancel = false; + if (p_cb->is_pair_cancel) evt_data.cmplt.is_pair_cancel = true; - SMP_TRACE_DEBUG ("send SMP_COMPLT_EVT reason=0x%0x sec_level=0x%0x", - evt_data.cmplt.reason, - evt_data.cmplt.sec_level ); + SMP_TRACE_DEBUG("send SMP_COMPLT_EVT reason=0x%0x sec_level=0x%0x", + evt_data.cmplt.reason, evt_data.cmplt.sec_level); - memcpy (pairing_bda, p_cb->pairing_bda, BD_ADDR_LEN); + memcpy(pairing_bda, p_cb->pairing_bda, BD_ADDR_LEN); - smp_reset_control_value(p_cb); + smp_reset_control_value(p_cb); - if (p_callback) - (*p_callback) (SMP_COMPLT_EVT, pairing_bda, &evt_data); + if (p_callback) (*p_callback)(SMP_COMPLT_EVT, pairing_bda, &evt_data); } /******************************************************************************* @@ -962,26 +951,23 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb) * Returns true if the command has invalid parameters, false otherwise. * ******************************************************************************/ -bool smp_command_has_invalid_parameters(tSMP_CB *p_cb) -{ - uint8_t cmd_code = p_cb->rcvd_cmd_code; +bool smp_command_has_invalid_parameters(tSMP_CB* p_cb) { + uint8_t cmd_code = p_cb->rcvd_cmd_code; - SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, cmd_code); + SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, cmd_code); - if ((cmd_code > (SMP_OPCODE_MAX + 1 /* for SMP_OPCODE_PAIR_COMMITM */)) || - (cmd_code < SMP_OPCODE_MIN)) - { - SMP_TRACE_WARNING("Somehow received command with the RESERVED code 0x%02x", cmd_code); - return true; - } + if ((cmd_code > (SMP_OPCODE_MAX + 1 /* for SMP_OPCODE_PAIR_COMMITM */)) || + (cmd_code < SMP_OPCODE_MIN)) { + SMP_TRACE_WARNING("Somehow received command with the RESERVED code 0x%02x", + cmd_code); + return true; + } - if (!(*smp_cmd_len_is_valid[cmd_code])(p_cb)) - return true; + if (!(*smp_cmd_len_is_valid[cmd_code])(p_cb)) return true; - if (!(*smp_cmd_param_ranges_are_valid[cmd_code])(p_cb)) - return true; + if (!(*smp_cmd_param_ranges_are_valid[cmd_code])(p_cb)) return true; - return false; + return false; } /******************************************************************************* @@ -995,21 +981,20 @@ bool smp_command_has_invalid_parameters(tSMP_CB *p_cb) * * Note The command is expected to have fixed length. ******************************************************************************/ -bool smp_command_has_valid_fixed_length(tSMP_CB *p_cb) -{ - uint8_t cmd_code = p_cb->rcvd_cmd_code; +bool smp_command_has_valid_fixed_length(tSMP_CB* p_cb) { + uint8_t cmd_code = p_cb->rcvd_cmd_code; - SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, cmd_code); + SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, cmd_code); - if (p_cb->rcvd_cmd_len != smp_cmd_size_per_spec[cmd_code]) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with invalid length\ + if (p_cb->rcvd_cmd_len != smp_cmd_size_per_spec[cmd_code]) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with invalid length\ 0x%02x (per spec the length is 0x%02x).", - cmd_code, p_cb->rcvd_cmd_len, smp_cmd_size_per_spec[cmd_code]); - return false; - } + cmd_code, p_cb->rcvd_cmd_len, smp_cmd_size_per_spec[cmd_code]); + return false; + } - return true; + return true; } /******************************************************************************* @@ -1027,48 +1012,49 @@ bool smp_command_has_valid_fixed_length(tSMP_CB *p_cb) * range. * ******************************************************************************/ -bool smp_pairing_request_response_parameters_are_valid(tSMP_CB *p_cb) -{ - uint8_t io_caps = p_cb->peer_io_caps; - uint8_t oob_flag = p_cb->peer_oob_flag; - uint8_t bond_flag = p_cb->peer_auth_req & 0x03; //0x03 is gen bond with appropriate mask - uint8_t enc_size = p_cb->peer_enc_size; - - SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); - - if (io_caps >= BTM_IO_CAP_MAX) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with IO Capabilty \ +bool smp_pairing_request_response_parameters_are_valid(tSMP_CB* p_cb) { + uint8_t io_caps = p_cb->peer_io_caps; + uint8_t oob_flag = p_cb->peer_oob_flag; + uint8_t bond_flag = + p_cb->peer_auth_req & 0x03; // 0x03 is gen bond with appropriate mask + uint8_t enc_size = p_cb->peer_enc_size; + + SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); + + if (io_caps >= BTM_IO_CAP_MAX) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with IO Capabilty \ value (0x%02x) out of range).", - p_cb->rcvd_cmd_code, io_caps); - return false; - } + p_cb->rcvd_cmd_code, io_caps); + return false; + } - if (!((oob_flag == SMP_OOB_NONE) || (oob_flag == SMP_OOB_PRESENT))) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with OOB data flag value \ + if (!((oob_flag == SMP_OOB_NONE) || (oob_flag == SMP_OOB_PRESENT))) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with OOB data flag value \ (0x%02x) out of range).", - p_cb->rcvd_cmd_code, oob_flag); - return false; - } + p_cb->rcvd_cmd_code, oob_flag); + return false; + } - if (!((bond_flag == SMP_AUTH_NO_BOND) || (bond_flag == SMP_AUTH_BOND))) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with Bonding_Flags value (0x%02x)\ + if (!((bond_flag == SMP_AUTH_NO_BOND) || (bond_flag == SMP_AUTH_BOND))) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with Bonding_Flags value (0x%02x)\ out of range).", - p_cb->rcvd_cmd_code, bond_flag); - return false; - } + p_cb->rcvd_cmd_code, bond_flag); + return false; + } - if ((enc_size < SMP_ENCR_KEY_SIZE_MIN) || (enc_size > SMP_ENCR_KEY_SIZE_MAX)) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with Maximum Encryption \ + if ((enc_size < SMP_ENCR_KEY_SIZE_MIN) || + (enc_size > SMP_ENCR_KEY_SIZE_MAX)) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with Maximum Encryption \ Key value (0x%02x) out of range).", - p_cb->rcvd_cmd_code, enc_size); - return false; - } + p_cb->rcvd_cmd_code, enc_size); + return false; + } - return true; + return true; } /******************************************************************************* @@ -1080,21 +1066,20 @@ bool smp_pairing_request_response_parameters_are_valid(tSMP_CB *p_cb) * Returns false if this parameter is out of range. * ******************************************************************************/ -bool smp_pairing_keypress_notification_is_valid(tSMP_CB *p_cb) -{ - tBTM_SP_KEY_TYPE keypress_notification = p_cb->peer_keypress_notification; +bool smp_pairing_keypress_notification_is_valid(tSMP_CB* p_cb) { + tBTM_SP_KEY_TYPE keypress_notification = p_cb->peer_keypress_notification; - SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); + SMP_TRACE_DEBUG("%s for cmd code 0x%02x", __func__, p_cb->rcvd_cmd_code); - if (keypress_notification >= BTM_SP_KEY_OUT_OF_RANGE) - { - SMP_TRACE_WARNING("Rcvd from the peer cmd 0x%02x with Pairing Keypress \ + if (keypress_notification >= BTM_SP_KEY_OUT_OF_RANGE) { + SMP_TRACE_WARNING( + "Rcvd from the peer cmd 0x%02x with Pairing Keypress \ Notification value (0x%02x) out of range).", - p_cb->rcvd_cmd_code, keypress_notification); - return false; - } + p_cb->rcvd_cmd_code, keypress_notification); + return false; + } - return true; + return true; } /******************************************************************************* @@ -1104,9 +1089,8 @@ bool smp_pairing_keypress_notification_is_valid(tSMP_CB *p_cb) * Description Always returns true. * ******************************************************************************/ -bool smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB *p_cb) -{ - return true; +bool smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB* p_cb) { + return true; } /******************************************************************************* @@ -1116,9 +1100,8 @@ bool smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB *p_cb) * Description Always returns false. * ******************************************************************************/ -bool smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB *p_cb) -{ - return false; +bool smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB* p_cb) { + return false; } /******************************************************************************* @@ -1131,22 +1114,21 @@ bool smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr) -{ - uint8_t *p; - BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + - SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET); +void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr) { + uint8_t* p; + BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR) + SMP_PAIR_FAIL_SIZE + + L2CAP_MIN_OFFSET); - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - p = (uint8_t *)(p_buf + 1) + L2CAP_MIN_OFFSET; - UINT8_TO_STREAM(p, SMP_OPCODE_PAIRING_FAILED); - UINT8_TO_STREAM(p, SMP_PAIR_NOT_SUPPORT); + p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET; + UINT8_TO_STREAM(p, SMP_OPCODE_PAIRING_FAILED); + UINT8_TO_STREAM(p, SMP_PAIR_NOT_SUPPORT); - p_buf->offset = L2CAP_MIN_OFFSET; - p_buf->len = SMP_PAIR_FAIL_SIZE; + p_buf->offset = L2CAP_MIN_OFFSET; + p_buf->len = SMP_PAIR_FAIL_SIZE; - smp_send_msg_to_L2CAP(bd_addr, p_buf); + smp_send_msg_to_L2CAP(bd_addr, p_buf); } /******************************************************************************* @@ -1166,38 +1148,35 @@ void smp_reject_unexpected_pairing_command(BD_ADDR bd_addr) * SMP_SC_SUPPORT_BIT * ******************************************************************************/ -tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB *p_cb) -{ - tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; - p_cb->le_secure_connections_mode_is_used = false; - - SMP_TRACE_EVENT("%s", __func__); - SMP_TRACE_DEBUG("%s p_cb->peer_io_caps = %d p_cb->local_io_capability = %d", - __func__, p_cb->peer_io_caps, p_cb->local_io_capability); - SMP_TRACE_DEBUG("%s p_cb->peer_oob_flag = %d p_cb->loc_oob_flag = %d", - __func__, p_cb->peer_oob_flag, p_cb->loc_oob_flag); - SMP_TRACE_DEBUG("%s p_cb->peer_auth_req = 0x%02x p_cb->loc_auth_req = 0x%02x", - __func__, p_cb->peer_auth_req, p_cb->loc_auth_req); - SMP_TRACE_DEBUG("%s p_cb->secure_connections_only_mode_required = %s", - __func__, p_cb->secure_connections_only_mode_required ? - "true" : "false"); - - if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) && (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) - { - p_cb->le_secure_connections_mode_is_used = true; - } - - SMP_TRACE_DEBUG("use_sc_process = %d", p_cb->le_secure_connections_mode_is_used); - - if (p_cb->le_secure_connections_mode_is_used) - { - model = smp_select_association_model_secure_connections(p_cb); - } - else - { - model = smp_select_legacy_association_model(p_cb); - } - return model; +tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB* p_cb) { + tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; + p_cb->le_secure_connections_mode_is_used = false; + + SMP_TRACE_EVENT("%s", __func__); + SMP_TRACE_DEBUG("%s p_cb->peer_io_caps = %d p_cb->local_io_capability = %d", + __func__, p_cb->peer_io_caps, p_cb->local_io_capability); + SMP_TRACE_DEBUG("%s p_cb->peer_oob_flag = %d p_cb->loc_oob_flag = %d", + __func__, p_cb->peer_oob_flag, p_cb->loc_oob_flag); + SMP_TRACE_DEBUG("%s p_cb->peer_auth_req = 0x%02x p_cb->loc_auth_req = 0x%02x", + __func__, p_cb->peer_auth_req, p_cb->loc_auth_req); + SMP_TRACE_DEBUG( + "%s p_cb->secure_connections_only_mode_required = %s", __func__, + p_cb->secure_connections_only_mode_required ? "true" : "false"); + + if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) && + (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) { + p_cb->le_secure_connections_mode_is_used = true; + } + + SMP_TRACE_DEBUG("use_sc_process = %d", + p_cb->le_secure_connections_mode_is_used); + + if (p_cb->le_secure_connections_mode_is_used) { + model = smp_select_association_model_secure_connections(p_cb); + } else { + model = smp_select_legacy_association_model(p_cb); + } + return model; } /******************************************************************************* @@ -1207,35 +1186,34 @@ tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB *p_cb) * least one side doesn't support secure connections. * ******************************************************************************/ -tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB *p_cb) -{ - tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; - - SMP_TRACE_DEBUG("%s", __func__); - /* if OOB data is present on both devices, then use OOB association model */ - if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && p_cb->loc_oob_flag == SMP_OOB_PRESENT) - return SMP_MODEL_OOB; - - /* else if neither device requires MITM, then use Just Works association model */ - if (SMP_NO_MITM_REQUIRED (p_cb->peer_auth_req) && SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) - return SMP_MODEL_ENCRYPTION_ONLY; - - /* otherwise use IO capability to select association model */ - if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && p_cb->local_io_capability < SMP_IO_CAP_MAX) - { - if (p_cb->role == HCI_ROLE_MASTER) - { - model = smp_association_table[p_cb->role][p_cb->peer_io_caps] - [p_cb->local_io_capability]; - } - else - { - model = smp_association_table[p_cb->role][p_cb->local_io_capability] - [p_cb->peer_io_caps]; - } +tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb) { + tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; + + SMP_TRACE_DEBUG("%s", __func__); + /* if OOB data is present on both devices, then use OOB association model */ + if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && + p_cb->loc_oob_flag == SMP_OOB_PRESENT) + return SMP_MODEL_OOB; + + /* else if neither device requires MITM, then use Just Works association model + */ + if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) && + SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) + return SMP_MODEL_ENCRYPTION_ONLY; + + /* otherwise use IO capability to select association model */ + if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && + p_cb->local_io_capability < SMP_IO_CAP_MAX) { + if (p_cb->role == HCI_ROLE_MASTER) { + model = smp_association_table[p_cb->role][p_cb->peer_io_caps] + [p_cb->local_io_capability]; + } else { + model = smp_association_table[p_cb->role][p_cb->local_io_capability] + [p_cb->peer_io_caps]; } + } - return model; + return model; } /******************************************************************************* @@ -1245,35 +1223,35 @@ tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB *p_cb) * sides support secure connections. * ******************************************************************************/ -tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB *p_cb) -{ - tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; - - SMP_TRACE_DEBUG("%s", __func__); - /* if OOB data is present on at least one device, then use OOB association model */ - if (p_cb->peer_oob_flag == SMP_OOB_PRESENT || p_cb->loc_oob_flag == SMP_OOB_PRESENT) - return SMP_MODEL_SEC_CONN_OOB; - - /* else if neither device requires MITM, then use Just Works association model */ - if (SMP_NO_MITM_REQUIRED (p_cb->peer_auth_req) && SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) - return SMP_MODEL_SEC_CONN_JUSTWORKS; - - /* otherwise use IO capability to select association model */ - if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && p_cb->local_io_capability < SMP_IO_CAP_MAX) - { - if (p_cb->role == HCI_ROLE_MASTER) - { - model = smp_association_table_sc[p_cb->role][p_cb->peer_io_caps] - [p_cb->local_io_capability]; - } - else - { - model = smp_association_table_sc[p_cb->role][p_cb->local_io_capability] - [p_cb->peer_io_caps]; - } +tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB* p_cb) { + tSMP_ASSO_MODEL model = SMP_MODEL_OUT_OF_RANGE; + + SMP_TRACE_DEBUG("%s", __func__); + /* if OOB data is present on at least one device, then use OOB association + * model */ + if (p_cb->peer_oob_flag == SMP_OOB_PRESENT || + p_cb->loc_oob_flag == SMP_OOB_PRESENT) + return SMP_MODEL_SEC_CONN_OOB; + + /* else if neither device requires MITM, then use Just Works association model + */ + if (SMP_NO_MITM_REQUIRED(p_cb->peer_auth_req) && + SMP_NO_MITM_REQUIRED(p_cb->loc_auth_req)) + return SMP_MODEL_SEC_CONN_JUSTWORKS; + + /* otherwise use IO capability to select association model */ + if (p_cb->peer_io_caps < SMP_IO_CAP_MAX && + p_cb->local_io_capability < SMP_IO_CAP_MAX) { + if (p_cb->role == HCI_ROLE_MASTER) { + model = smp_association_table_sc[p_cb->role][p_cb->peer_io_caps] + [p_cb->local_io_capability]; + } else { + model = smp_association_table_sc[p_cb->role][p_cb->local_io_capability] + [p_cb->peer_io_caps]; } + } - return model; + return model; } /******************************************************************************* @@ -1282,18 +1260,16 @@ tSMP_ASSO_MODEL smp_select_association_model_secure_connections(tSMP_CB *p_cb) * Description This function reverses array bytes * ******************************************************************************/ -void smp_reverse_array(uint8_t *arr, uint8_t len) -{ - uint8_t i =0, tmp; +void smp_reverse_array(uint8_t* arr, uint8_t len) { + uint8_t i = 0, tmp; - SMP_TRACE_DEBUG("smp_reverse_array"); + SMP_TRACE_DEBUG("smp_reverse_array"); - for (i = 0; i < len/2; i ++) - { - tmp = arr[i]; - arr[i] = arr[len -1 - i]; - arr[len -1 - i] = tmp; - } + for (i = 0; i < len / 2; i++) { + tmp = arr[i]; + arr[i] = arr[len - 1 - i]; + arr[len - 1 - i] = tmp; + } } /******************************************************************************* @@ -1307,16 +1283,16 @@ void smp_reverse_array(uint8_t *arr, uint8_t len) * Returns ri value * ******************************************************************************/ -uint8_t smp_calculate_random_input(uint8_t *random, uint8_t round) -{ - uint8_t i = round/8; - uint8_t j = round%8; - uint8_t ri; - - SMP_TRACE_DEBUG("random: 0x%02x, round: %d, i: %d, j: %d", random[i], round, i, j); - ri = ((random[i] >> j) & 1) | 0x80; - SMP_TRACE_DEBUG("%s ri=0x%02x", __func__, ri); - return ri; +uint8_t smp_calculate_random_input(uint8_t* random, uint8_t round) { + uint8_t i = round / 8; + uint8_t j = round % 8; + uint8_t ri; + + SMP_TRACE_DEBUG("random: 0x%02x, round: %d, i: %d, j: %d", random[i], round, + i, j); + ri = ((random[i] >> j) & 1) | 0x80; + SMP_TRACE_DEBUG("%s ri=0x%02x", __func__, ri); + return ri; } /******************************************************************************* @@ -1328,13 +1304,12 @@ uint8_t smp_calculate_random_input(uint8_t *random, uint8_t round) * Returns void * ******************************************************************************/ -void smp_collect_local_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_collect_local_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s", __func__); - iocap[0] = p_cb->local_io_capability; - iocap[1] = p_cb->loc_oob_flag; - iocap[2] = p_cb->loc_auth_req; + iocap[0] = p_cb->local_io_capability; + iocap[1] = p_cb->loc_oob_flag; + iocap[2] = p_cb->loc_auth_req; } /******************************************************************************* @@ -1346,13 +1321,12 @@ void smp_collect_local_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_collect_peer_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb) -{ - SMP_TRACE_DEBUG("%s", __func__); +void smp_collect_peer_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb) { + SMP_TRACE_DEBUG("%s", __func__); - iocap[0] = p_cb->peer_io_caps; - iocap[1] = p_cb->peer_oob_flag; - iocap[2] = p_cb->peer_auth_req; + iocap[0] = p_cb->peer_io_caps; + iocap[1] = p_cb->peer_oob_flag; + iocap[2] = p_cb->peer_auth_req; } /******************************************************************************* @@ -1365,17 +1339,16 @@ void smp_collect_peer_io_capabilities(uint8_t *iocap, tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_collect_local_ble_address(uint8_t *le_addr, tSMP_CB *p_cb) -{ - tBLE_ADDR_TYPE addr_type = 0; - BD_ADDR bda; - uint8_t *p = le_addr; +void smp_collect_local_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) { + tBLE_ADDR_TYPE addr_type = 0; + BD_ADDR bda; + uint8_t* p = le_addr; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - BTM_ReadConnectionAddr( p_cb->pairing_bda, bda, &addr_type); - BDADDR_TO_STREAM(p, bda); - UINT8_TO_STREAM(p, addr_type); + BTM_ReadConnectionAddr(p_cb->pairing_bda, bda, &addr_type); + BDADDR_TO_STREAM(p, bda); + UINT8_TO_STREAM(p, addr_type); } /******************************************************************************* @@ -1388,22 +1361,21 @@ void smp_collect_local_ble_address(uint8_t *le_addr, tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_collect_peer_ble_address(uint8_t *le_addr, tSMP_CB *p_cb) -{ - tBLE_ADDR_TYPE addr_type = 0; - BD_ADDR bda; - uint8_t *p = le_addr; +void smp_collect_peer_ble_address(uint8_t* le_addr, tSMP_CB* p_cb) { + tBLE_ADDR_TYPE addr_type = 0; + BD_ADDR bda; + uint8_t* p = le_addr; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda, &addr_type)) - { - SMP_TRACE_ERROR("can not collect peer le addr information for unknown device"); - return; - } + if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda, &addr_type)) { + SMP_TRACE_ERROR( + "can not collect peer le addr information for unknown device"); + return; + } - BDADDR_TO_STREAM(p, bda); - UINT8_TO_STREAM(p, addr_type); + BDADDR_TO_STREAM(p, bda); + UINT8_TO_STREAM(p, addr_type); } /******************************************************************************* @@ -1417,24 +1389,22 @@ void smp_collect_peer_ble_address(uint8_t *le_addr, tSMP_CB *p_cb) * false otherwise * ******************************************************************************/ -bool smp_check_commitment(tSMP_CB *p_cb) -{ - BT_OCTET16 expected; +bool smp_check_commitment(tSMP_CB* p_cb) { + BT_OCTET16 expected; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - smp_calculate_peer_commitment(p_cb, expected); - print128(expected, (const uint8_t *)"calculated peer commitment"); - print128(p_cb->remote_commitment, (const uint8_t *)"received peer commitment"); + smp_calculate_peer_commitment(p_cb, expected); + print128(expected, (const uint8_t*)"calculated peer commitment"); + print128(p_cb->remote_commitment, (const uint8_t*)"received peer commitment"); - if (memcmp(p_cb->remote_commitment, expected, BT_OCTET16_LEN)) - { - SMP_TRACE_WARNING("%s: Commitment check fails", __func__); - return false; - } + if (memcmp(p_cb->remote_commitment, expected, BT_OCTET16_LEN)) { + SMP_TRACE_WARNING("%s: Commitment check fails", __func__); + return false; + } - SMP_TRACE_DEBUG("%s: Commitment check succeeds", __func__); - return true; + SMP_TRACE_DEBUG("%s: Commitment check succeeds", __func__); + return true; } /******************************************************************************* @@ -1447,25 +1417,26 @@ bool smp_check_commitment(tSMP_CB *p_cb) * Returns void * ******************************************************************************/ -void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb) -{ - tBTM_LE_LENC_KEYS lle_key; - tBTM_LE_PENC_KEYS ple_key; - - SMP_TRACE_DEBUG("%s-Save LTK as local LTK key", __func__); - memcpy(lle_key.ltk, p_cb->ltk, BT_OCTET16_LEN); - lle_key.div = 0; - lle_key.key_size = p_cb->loc_enc_size; - lle_key.sec_level = p_cb->sec_level; - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, (tBTM_LE_KEY_VALUE *)&lle_key, true); - - SMP_TRACE_DEBUG("%s-Save LTK as peer LTK key", __func__); - ple_key.ediv = 0; - memset(ple_key.rand, 0, BT_OCTET8_LEN); - memcpy(ple_key.ltk, p_cb->ltk, BT_OCTET16_LEN); - ple_key.sec_level = p_cb->sec_level; - ple_key.key_size = p_cb->loc_enc_size; - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, (tBTM_LE_KEY_VALUE *)&ple_key, true); +void smp_save_secure_connections_long_term_key(tSMP_CB* p_cb) { + tBTM_LE_LENC_KEYS lle_key; + tBTM_LE_PENC_KEYS ple_key; + + SMP_TRACE_DEBUG("%s-Save LTK as local LTK key", __func__); + memcpy(lle_key.ltk, p_cb->ltk, BT_OCTET16_LEN); + lle_key.div = 0; + lle_key.key_size = p_cb->loc_enc_size; + lle_key.sec_level = p_cb->sec_level; + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, + (tBTM_LE_KEY_VALUE*)&lle_key, true); + + SMP_TRACE_DEBUG("%s-Save LTK as peer LTK key", __func__); + ple_key.ediv = 0; + memset(ple_key.rand, 0, BT_OCTET8_LEN); + memcpy(ple_key.ltk, p_cb->ltk, BT_OCTET16_LEN); + ple_key.sec_level = p_cb->sec_level; + ple_key.key_size = p_cb->loc_enc_size; + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, + (tBTM_LE_KEY_VALUE*)&ple_key, true); } /******************************************************************************* @@ -1480,38 +1451,34 @@ void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb) * Returns false if out of resources, true otherwise. * ******************************************************************************/ -bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB *p_cb) -{ - uint8_t a[7]; - uint8_t b[7]; - uint8_t *p_na; - uint8_t *p_nb; - - SMP_TRACE_DEBUG("%s", __func__); - - if (p_cb->role == HCI_ROLE_MASTER) - { - smp_collect_local_ble_address(a, p_cb); - smp_collect_peer_ble_address(b, p_cb); - p_na = p_cb->rand; - p_nb = p_cb->rrand; - } - else - { - smp_collect_local_ble_address(b, p_cb); - smp_collect_peer_ble_address(a, p_cb); - p_na = p_cb->rrand; - p_nb = p_cb->rand; - } - - if(!smp_calculate_f5(p_cb->dhkey, p_na, p_nb, a, b, p_cb->mac_key, p_cb->ltk)) - { - SMP_TRACE_ERROR("%s failed", __func__); - return false; - } +bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB* p_cb) { + uint8_t a[7]; + uint8_t b[7]; + uint8_t* p_na; + uint8_t* p_nb; + + SMP_TRACE_DEBUG("%s", __func__); + + if (p_cb->role == HCI_ROLE_MASTER) { + smp_collect_local_ble_address(a, p_cb); + smp_collect_peer_ble_address(b, p_cb); + p_na = p_cb->rand; + p_nb = p_cb->rrand; + } else { + smp_collect_local_ble_address(b, p_cb); + smp_collect_peer_ble_address(a, p_cb); + p_na = p_cb->rrand; + p_nb = p_cb->rand; + } + + if (!smp_calculate_f5(p_cb->dhkey, p_na, p_nb, a, b, p_cb->mac_key, + p_cb->ltk)) { + SMP_TRACE_ERROR("%s failed", __func__); + return false; + } - SMP_TRACE_EVENT ("%s is completed", __func__); - return true; + SMP_TRACE_EVENT("%s is completed", __func__); + return true; } /******************************************************************************* @@ -1524,35 +1491,29 @@ bool smp_calculate_f5_mackey_and_long_term_key(tSMP_CB *p_cb) * false - otherwise (unexpected) * ******************************************************************************/ -bool smp_request_oob_data(tSMP_CB *p_cb) -{ - tSMP_OOB_DATA_TYPE req_oob_type = SMP_OOB_INVALID_TYPE; +bool smp_request_oob_data(tSMP_CB* p_cb) { + tSMP_OOB_DATA_TYPE req_oob_type = SMP_OOB_INVALID_TYPE; - SMP_TRACE_DEBUG("%s", __func__); + SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && p_cb->loc_oob_flag == SMP_OOB_PRESENT) - { - /* both local and peer rcvd data OOB */ - req_oob_type = SMP_OOB_BOTH; - } - else if (p_cb->peer_oob_flag == SMP_OOB_PRESENT) - { - /* peer rcvd OOB local data, local didn't receive OOB peer data */ - req_oob_type = SMP_OOB_LOCAL; - } - else if (p_cb->loc_oob_flag == SMP_OOB_PRESENT) - { - req_oob_type = SMP_OOB_PEER; - } + if (p_cb->peer_oob_flag == SMP_OOB_PRESENT && + p_cb->loc_oob_flag == SMP_OOB_PRESENT) { + /* both local and peer rcvd data OOB */ + req_oob_type = SMP_OOB_BOTH; + } else if (p_cb->peer_oob_flag == SMP_OOB_PRESENT) { + /* peer rcvd OOB local data, local didn't receive OOB peer data */ + req_oob_type = SMP_OOB_LOCAL; + } else if (p_cb->loc_oob_flag == SMP_OOB_PRESENT) { + req_oob_type = SMP_OOB_PEER; + } - SMP_TRACE_DEBUG("req_oob_type = %d", req_oob_type); + SMP_TRACE_DEBUG("req_oob_type = %d", req_oob_type); - if (req_oob_type == SMP_OOB_INVALID_TYPE) - return false; + if (req_oob_type == SMP_OOB_INVALID_TYPE) return false; - p_cb->req_oob_type = req_oob_type; - p_cb->cb_evt = SMP_SC_OOB_REQ_EVT; - smp_sm_event(p_cb, SMP_TK_REQ_EVT, &req_oob_type); + p_cb->req_oob_type = req_oob_type; + p_cb->cb_evt = SMP_SC_OOB_REQ_EVT; + smp_sm_event(p_cb, SMP_TK_REQ_EVT, &req_oob_type); - return true; + return true; } diff --git a/stack/srvc/srvc_battery.cc b/stack/srvc/srvc_battery.cc index 06030d312..7600f9d50 100644 --- a/stack/srvc/srvc_battery.cc +++ b/stack/srvc/srvc_battery.cc @@ -18,145 +18,127 @@ #include "bt_target.h" #include "bt_utils.h" +#include "btcore/include/uuid.h" #include "gatt_api.h" #include "gatt_int.h" -#include "srvc_eng_int.h" -#include "srvc_battery_int.h" -#include "btcore/include/uuid.h" #include "osi/include/osi.h" +#include "srvc_battery_int.h" +#include "srvc_eng_int.h" -#define BA_MAX_CHAR_NUM 1 +#define BA_MAX_CHAR_NUM 1 /* max 3 descriptors, 1 desclration and 1 value */ -#define BA_MAX_ATTR_NUM (BA_MAX_CHAR_NUM * 5 + 1) +#define BA_MAX_ATTR_NUM (BA_MAX_CHAR_NUM * 5 + 1) #ifndef BATTER_LEVEL_PROP -#define BATTER_LEVEL_PROP (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_NOTIFY) +#define BATTER_LEVEL_PROP (GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_NOTIFY) #endif - #ifndef BATTER_LEVEL_PERM -#define BATTER_LEVEL_PERM (GATT_PERM_READ) +#define BATTER_LEVEL_PERM (GATT_PERM_READ) #endif tBATTERY_CB battery_cb; - /******************************************************************************* * battery_valid_handle_range * * validate a handle to be a DIS attribute handle or not. ******************************************************************************/ -bool battery_valid_handle_range(uint16_t handle) -{ - uint8_t i = 0; - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - - for (;i < BA_MAX_INT_NUM; i ++, p_inst++) - { - if (handle == p_inst->ba_level_hdl || - handle == p_inst->clt_cfg_hdl || - handle == p_inst->rpt_ref_hdl || - handle == p_inst->pres_fmt_hdl ) - { - return true; - } +bool battery_valid_handle_range(uint16_t handle) { + uint8_t i = 0; + tBA_INST* p_inst = &battery_cb.battery_inst[0]; + + for (; i < BA_MAX_INT_NUM; i++, p_inst++) { + if (handle == p_inst->ba_level_hdl || handle == p_inst->clt_cfg_hdl || + handle == p_inst->rpt_ref_hdl || handle == p_inst->pres_fmt_hdl) { + return true; } - return false; + } + return false; } /******************************************************************************* * battery_s_write_attr_value * * Process write DIS attribute request. ******************************************************************************/ -uint8_t battery_s_write_attr_value(uint8_t clcb_idx, tGATT_WRITE_REQ * p_value, - tGATT_STATUS *p_status) -{ - uint8_t *p = p_value->value, i; - uint16_t handle = p_value->handle; - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - tGATT_STATUS st = GATT_NOT_FOUND; - tBA_WRITE_DATA cfg; - uint8_t act = SRVC_ACT_RSP; - - for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++) +uint8_t battery_s_write_attr_value(uint8_t clcb_idx, tGATT_WRITE_REQ* p_value, + tGATT_STATUS* p_status) { + uint8_t *p = p_value->value, i; + uint16_t handle = p_value->handle; + tBA_INST* p_inst = &battery_cb.battery_inst[0]; + tGATT_STATUS st = GATT_NOT_FOUND; + tBA_WRITE_DATA cfg; + uint8_t act = SRVC_ACT_RSP; + + for (i = 0; i < BA_MAX_INT_NUM; i++, p_inst++) { + /* read battery level */ + if (handle == p_inst->clt_cfg_hdl) { + memcpy(cfg.remote_bda, srvc_eng_cb.clcb[clcb_idx].bda, BD_ADDR_LEN); + STREAM_TO_UINT16(cfg.clt_cfg, p); + + if (p_inst->p_cback) { + p_inst->pending_clcb_idx = clcb_idx; + p_inst->pending_evt = BA_WRITE_CLT_CFG_REQ; + p_inst->pending_handle = handle; + cfg.need_rsp = p_value->need_rsp; + act = SRVC_ACT_PENDING; + + (*p_inst->p_cback)(p_inst->app_id, BA_WRITE_CLT_CFG_REQ, &cfg); + } + } else /* all other handle is not writable */ { - /* read battery level */ - if (handle == p_inst->clt_cfg_hdl) - { - memcpy(cfg.remote_bda, srvc_eng_cb.clcb[clcb_idx].bda, BD_ADDR_LEN); - STREAM_TO_UINT16(cfg.clt_cfg, p); - - if (p_inst->p_cback) - { - p_inst->pending_clcb_idx = clcb_idx; - p_inst->pending_evt = BA_WRITE_CLT_CFG_REQ; - p_inst->pending_handle = handle; - cfg.need_rsp = p_value->need_rsp; - act = SRVC_ACT_PENDING; - - (* p_inst->p_cback)(p_inst->app_id, BA_WRITE_CLT_CFG_REQ, &cfg); - } - } - else /* all other handle is not writable */ - { - st = GATT_WRITE_NOT_PERMIT; - break; - } + st = GATT_WRITE_NOT_PERMIT; + break; } - *p_status = st; + } + *p_status = st; - return act; + return act; } /******************************************************************************* * BA Attributes Database Server Request callback ******************************************************************************/ -uint8_t battery_s_read_attr_value (uint8_t clcb_idx, uint16_t handle, - UNUSED_ATTR tGATT_VALUE *p_value, bool is_long, - tGATT_STATUS* p_status) -{ - uint8_t i; - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - tGATT_STATUS st = GATT_NOT_FOUND; - uint8_t act = SRVC_ACT_RSP; - - for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++) - { - /* read battery level */ - if (handle == p_inst->ba_level_hdl || - handle == p_inst->clt_cfg_hdl || - handle == p_inst->rpt_ref_hdl || - handle == p_inst->pres_fmt_hdl) - { - if (is_long) - st = GATT_NOT_LONG; - - if (p_inst->p_cback) - { - if (handle == p_inst->ba_level_hdl) p_inst->pending_evt = BA_READ_LEVEL_REQ; - if (handle == p_inst->clt_cfg_hdl) p_inst->pending_evt = BA_READ_CLT_CFG_REQ; - if (handle == p_inst->pres_fmt_hdl) p_inst->pending_evt = BA_READ_PRE_FMT_REQ; - if (handle == p_inst->rpt_ref_hdl) p_inst->pending_evt = BA_READ_RPT_REF_REQ ; - - p_inst->pending_clcb_idx = clcb_idx; - p_inst->pending_handle = handle; - act = SRVC_ACT_PENDING; - - (* p_inst->p_cback)(p_inst->app_id, p_inst->pending_evt, NULL); - } - else /* application is not registered */ - st = GATT_ERR_UNLIKELY; - break; - } - /* else attribute not found */ +uint8_t battery_s_read_attr_value(uint8_t clcb_idx, uint16_t handle, + UNUSED_ATTR tGATT_VALUE* p_value, + bool is_long, tGATT_STATUS* p_status) { + uint8_t i; + tBA_INST* p_inst = &battery_cb.battery_inst[0]; + tGATT_STATUS st = GATT_NOT_FOUND; + uint8_t act = SRVC_ACT_RSP; + + for (i = 0; i < BA_MAX_INT_NUM; i++, p_inst++) { + /* read battery level */ + if (handle == p_inst->ba_level_hdl || handle == p_inst->clt_cfg_hdl || + handle == p_inst->rpt_ref_hdl || handle == p_inst->pres_fmt_hdl) { + if (is_long) st = GATT_NOT_LONG; + + if (p_inst->p_cback) { + if (handle == p_inst->ba_level_hdl) + p_inst->pending_evt = BA_READ_LEVEL_REQ; + if (handle == p_inst->clt_cfg_hdl) + p_inst->pending_evt = BA_READ_CLT_CFG_REQ; + if (handle == p_inst->pres_fmt_hdl) + p_inst->pending_evt = BA_READ_PRE_FMT_REQ; + if (handle == p_inst->rpt_ref_hdl) + p_inst->pending_evt = BA_READ_RPT_REF_REQ; + + p_inst->pending_clcb_idx = clcb_idx; + p_inst->pending_handle = handle; + act = SRVC_ACT_PENDING; + + (*p_inst->p_cback)(p_inst->app_id, p_inst->pending_evt, NULL); + } else /* application is not registered */ + st = GATT_ERR_UNLIKELY; + break; } + /* else attribute not found */ + } - - *p_status = st; - return act; + *p_status = st; + return act; } - /******************************************************************************* * * Function battery_gatt_c_read_ba_req @@ -166,10 +148,7 @@ uint8_t battery_s_read_attr_value (uint8_t clcb_idx, uint16_t handle, * Returns void * ******************************************************************************/ -bool battery_gatt_c_read_ba_req(UNUSED_ATTR uint16_t conn_id) -{ - return true; -} +bool battery_gatt_c_read_ba_req(UNUSED_ATTR uint16_t conn_id) { return true; } /******************************************************************************* * @@ -180,12 +159,10 @@ bool battery_gatt_c_read_ba_req(UNUSED_ATTR uint16_t conn_id) * Returns void * ******************************************************************************/ -void battery_c_cmpl_cback (UNUSED_ATTR tSRVC_CLCB *p_clcb, UNUSED_ATTR tGATTC_OPTYPE op, - UNUSED_ATTR tGATT_STATUS status, - UNUSED_ATTR tGATT_CL_COMPLETE *p_data) -{ -} - +void battery_c_cmpl_cback(UNUSED_ATTR tSRVC_CLCB* p_clcb, + UNUSED_ATTR tGATTC_OPTYPE op, + UNUSED_ATTR tGATT_STATUS status, + UNUSED_ATTR tGATT_CL_COMPLETE* p_data) {} /******************************************************************************* * @@ -194,100 +171,98 @@ void battery_c_cmpl_cback (UNUSED_ATTR tSRVC_CLCB *p_clcb, UNUSED_ATTR tGATTC_OP * Description Instantiate a Battery service * ******************************************************************************/ -uint16_t Battery_Instantiate (uint8_t app_id, tBA_REG_INFO *p_reg_info) -{ - uint16_t srvc_hdl = 0; - tGATT_STATUS status = GATT_ERROR; - tBA_INST *p_inst; - - if (battery_cb.inst_id == BA_MAX_INT_NUM) - { - GATT_TRACE_ERROR("MAX battery service has been reached"); - return 0; - } - - p_inst = &battery_cb.battery_inst[battery_cb.inst_id]; - - btgatt_db_element_t service[BA_MAX_ATTR_NUM] = {}; - - bt_uuid_t service_uuid; - uuid_128_from_16(&service_uuid, UUID_SERVCLASS_BATTERY); - service[0].type = /* p_reg_info->is_pri */ BTGATT_DB_PRIMARY_SERVICE; - service[0].uuid = service_uuid; - - bt_uuid_t char_uuid; - uuid_128_from_16(&char_uuid, GATT_UUID_BATTERY_LEVEL); - service[1].type = BTGATT_DB_CHARACTERISTIC; - service[1].uuid = char_uuid; - service[1].properties = GATT_CHAR_PROP_BIT_READ; - if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) - service[1].properties |= GATT_CHAR_PROP_BIT_NOTIFY; - - int i=2; - if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) { - bt_uuid_t desc_uuid; - uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_CLIENT_CONFIG); - - service[i].type = BTGATT_DB_DESCRIPTOR; - service[i].uuid = desc_uuid; - service[i].permissions = (GATT_PERM_READ|GATT_PERM_WRITE); - i++; - } - - /* need presentation format descriptor? */ - if (p_reg_info->ba_level_descr & BA_LEVEL_PRE_FMT) { - bt_uuid_t desc_uuid; - uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_PRESENT_FORMAT); - - service[i].type = BTGATT_DB_DESCRIPTOR; - service[i].uuid = desc_uuid; - service[i].permissions = GATT_PERM_READ; - i++; - } - - /* need presentation format descriptor? */ - if (p_reg_info->ba_level_descr & BA_LEVEL_RPT_REF) { - bt_uuid_t desc_uuid; - uuid_128_from_16(&desc_uuid, GATT_UUID_RPT_REF_DESCR); - - service[i].type = BTGATT_DB_DESCRIPTOR; - service[i].uuid = desc_uuid; - service[i].permissions = GATT_PERM_READ; - i++; - } - - GATTS_AddService(srvc_eng_cb.gatt_if, service, i); - - if (status != GATT_SUCCESS) { - battery_cb.inst_id --; - GATT_TRACE_ERROR("%s: Failed to add battery servuce!", __func__); - } - - battery_cb.inst_id ++; - - p_inst->app_id = app_id; - p_inst->p_cback = p_reg_info->p_cback; - - srvc_hdl = service[0].attribute_handle; - p_inst->ba_level_hdl = service[1].attribute_handle; - - i=2; - if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) { - p_inst->clt_cfg_hdl = service[i].attribute_handle; - i++; - } - - if (p_reg_info->ba_level_descr & BA_LEVEL_PRE_FMT) { - p_inst->pres_fmt_hdl = service[i].attribute_handle; - i++; - } - - if (p_reg_info->ba_level_descr & BA_LEVEL_RPT_REF) { - p_inst->rpt_ref_hdl = service[i].attribute_handle; - i++; - } - - return srvc_hdl; +uint16_t Battery_Instantiate(uint8_t app_id, tBA_REG_INFO* p_reg_info) { + uint16_t srvc_hdl = 0; + tGATT_STATUS status = GATT_ERROR; + tBA_INST* p_inst; + + if (battery_cb.inst_id == BA_MAX_INT_NUM) { + GATT_TRACE_ERROR("MAX battery service has been reached"); + return 0; + } + + p_inst = &battery_cb.battery_inst[battery_cb.inst_id]; + + btgatt_db_element_t service[BA_MAX_ATTR_NUM] = {}; + + bt_uuid_t service_uuid; + uuid_128_from_16(&service_uuid, UUID_SERVCLASS_BATTERY); + service[0].type = /* p_reg_info->is_pri */ BTGATT_DB_PRIMARY_SERVICE; + service[0].uuid = service_uuid; + + bt_uuid_t char_uuid; + uuid_128_from_16(&char_uuid, GATT_UUID_BATTERY_LEVEL); + service[1].type = BTGATT_DB_CHARACTERISTIC; + service[1].uuid = char_uuid; + service[1].properties = GATT_CHAR_PROP_BIT_READ; + if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) + service[1].properties |= GATT_CHAR_PROP_BIT_NOTIFY; + + int i = 2; + if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) { + bt_uuid_t desc_uuid; + uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_CLIENT_CONFIG); + + service[i].type = BTGATT_DB_DESCRIPTOR; + service[i].uuid = desc_uuid; + service[i].permissions = (GATT_PERM_READ | GATT_PERM_WRITE); + i++; + } + + /* need presentation format descriptor? */ + if (p_reg_info->ba_level_descr & BA_LEVEL_PRE_FMT) { + bt_uuid_t desc_uuid; + uuid_128_from_16(&desc_uuid, GATT_UUID_CHAR_PRESENT_FORMAT); + + service[i].type = BTGATT_DB_DESCRIPTOR; + service[i].uuid = desc_uuid; + service[i].permissions = GATT_PERM_READ; + i++; + } + + /* need presentation format descriptor? */ + if (p_reg_info->ba_level_descr & BA_LEVEL_RPT_REF) { + bt_uuid_t desc_uuid; + uuid_128_from_16(&desc_uuid, GATT_UUID_RPT_REF_DESCR); + + service[i].type = BTGATT_DB_DESCRIPTOR; + service[i].uuid = desc_uuid; + service[i].permissions = GATT_PERM_READ; + i++; + } + + GATTS_AddService(srvc_eng_cb.gatt_if, service, i); + + if (status != GATT_SUCCESS) { + battery_cb.inst_id--; + GATT_TRACE_ERROR("%s: Failed to add battery servuce!", __func__); + } + + battery_cb.inst_id++; + + p_inst->app_id = app_id; + p_inst->p_cback = p_reg_info->p_cback; + + srvc_hdl = service[0].attribute_handle; + p_inst->ba_level_hdl = service[1].attribute_handle; + + i = 2; + if (p_reg_info->ba_level_descr & BA_LEVEL_NOTIFY) { + p_inst->clt_cfg_hdl = service[i].attribute_handle; + i++; + } + + if (p_reg_info->ba_level_descr & BA_LEVEL_PRE_FMT) { + p_inst->pres_fmt_hdl = service[i].attribute_handle; + i++; + } + + if (p_reg_info->ba_level_descr & BA_LEVEL_RPT_REF) { + p_inst->rpt_ref_hdl = service[i].attribute_handle; + i++; + } + + return srvc_hdl; } /******************************************************************************* * @@ -296,66 +271,61 @@ uint16_t Battery_Instantiate (uint8_t app_id, tBA_REG_INFO *p_reg_info) * Description Respond to a battery service request * ******************************************************************************/ -void Battery_Rsp (uint8_t app_id, tGATT_STATUS st, uint8_t event, tBA_RSP_DATA *p_rsp) -{ - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - tGATTS_RSP rsp; - uint8_t *pp; - - uint8_t i = 0; - while (i < BA_MAX_INT_NUM) - { - if (p_inst->app_id == app_id && p_inst->ba_level_hdl != 0) - break; - i ++; - } - - if (i == BA_MAX_INT_NUM) - return; - - memset(&rsp, 0, sizeof(tGATTS_RSP)); - - if (p_inst->pending_evt == event) - { - switch (event) - { - case BA_READ_CLT_CFG_REQ: - rsp.attr_value.handle = p_inst->pending_handle; - rsp.attr_value.len = 2; - pp = rsp.attr_value.value; - UINT16_TO_STREAM(pp, p_rsp->clt_cfg); - srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); - break; - - case BA_READ_LEVEL_REQ: - rsp.attr_value.handle = p_inst->pending_handle; - rsp.attr_value.len = 1; - pp = rsp.attr_value.value; - UINT8_TO_STREAM(pp, p_rsp->ba_level); - srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); - break; - - case BA_WRITE_CLT_CFG_REQ: - srvc_sr_rsp(p_inst->pending_clcb_idx, st, NULL); - break; - - case BA_READ_RPT_REF_REQ: - rsp.attr_value.handle = p_inst->pending_handle; - rsp.attr_value.len = 2; - pp = rsp.attr_value.value; - UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_id); - UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_type); - srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); - break; - - default: - break; - } - p_inst->pending_clcb_idx = 0; - p_inst->pending_evt = 0; - p_inst->pending_handle = 0; +void Battery_Rsp(uint8_t app_id, tGATT_STATUS st, uint8_t event, + tBA_RSP_DATA* p_rsp) { + tBA_INST* p_inst = &battery_cb.battery_inst[0]; + tGATTS_RSP rsp; + uint8_t* pp; + + uint8_t i = 0; + while (i < BA_MAX_INT_NUM) { + if (p_inst->app_id == app_id && p_inst->ba_level_hdl != 0) break; + i++; + } + + if (i == BA_MAX_INT_NUM) return; + + memset(&rsp, 0, sizeof(tGATTS_RSP)); + + if (p_inst->pending_evt == event) { + switch (event) { + case BA_READ_CLT_CFG_REQ: + rsp.attr_value.handle = p_inst->pending_handle; + rsp.attr_value.len = 2; + pp = rsp.attr_value.value; + UINT16_TO_STREAM(pp, p_rsp->clt_cfg); + srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); + break; + + case BA_READ_LEVEL_REQ: + rsp.attr_value.handle = p_inst->pending_handle; + rsp.attr_value.len = 1; + pp = rsp.attr_value.value; + UINT8_TO_STREAM(pp, p_rsp->ba_level); + srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); + break; + + case BA_WRITE_CLT_CFG_REQ: + srvc_sr_rsp(p_inst->pending_clcb_idx, st, NULL); + break; + + case BA_READ_RPT_REF_REQ: + rsp.attr_value.handle = p_inst->pending_handle; + rsp.attr_value.len = 2; + pp = rsp.attr_value.value; + UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_id); + UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_type); + srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); + break; + + default: + break; } - return; + p_inst->pending_clcb_idx = 0; + p_inst->pending_evt = 0; + p_inst->pending_handle = 0; + } + return; } /******************************************************************************* * @@ -364,23 +334,18 @@ void Battery_Rsp (uint8_t app_id, tGATT_STATUS st, uint8_t event, tBA_RSP_DATA * * Description Send battery level notification * ******************************************************************************/ -void Battery_Notify (uint8_t app_id, BD_ADDR remote_bda, uint8_t battery_level) -{ - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - uint8_t i = 0; - - while (i < BA_MAX_INT_NUM) - { - if (p_inst->app_id == app_id && p_inst->ba_level_hdl != 0) - break; - i ++; - } +void Battery_Notify(uint8_t app_id, BD_ADDR remote_bda, uint8_t battery_level) { + tBA_INST* p_inst = &battery_cb.battery_inst[0]; + uint8_t i = 0; - if (i == BA_MAX_INT_NUM || p_inst->clt_cfg_hdl == 0) - return; + while (i < BA_MAX_INT_NUM) { + if (p_inst->app_id == app_id && p_inst->ba_level_hdl != 0) break; + i++; + } - srvc_sr_notify(remote_bda, p_inst->ba_level_hdl, 1, &battery_level); + if (i == BA_MAX_INT_NUM || p_inst->clt_cfg_hdl == 0) return; + srvc_sr_notify(remote_bda, p_inst->ba_level_hdl, 1, &battery_level); } /******************************************************************************* * @@ -391,8 +356,7 @@ void Battery_Notify (uint8_t app_id, BD_ADDR remote_bda, uint8_t battery_level) * Returns void * ******************************************************************************/ -bool Battery_ReadBatteryLevel(UNUSED_ATTR BD_ADDR peer_bda) -{ - /* to be implemented */ - return true; +bool Battery_ReadBatteryLevel(UNUSED_ATTR BD_ADDR peer_bda) { + /* to be implemented */ + return true; } diff --git a/stack/srvc/srvc_battery_int.h b/stack/srvc/srvc_battery_int.h index 4b03e87f2..f649af0fe 100644 --- a/stack/srvc/srvc_battery_int.h +++ b/stack/srvc/srvc_battery_int.h @@ -20,55 +20,52 @@ #define SRVC_BATTERY_INT_H #include "bt_target.h" -#include "srvc_api.h" #include "gatt_api.h" +#include "srvc_api.h" #ifdef __cplusplus extern "C" { #endif #ifndef BA_MAX_INT_NUM -#define BA_MAX_INT_NUM 4 +#define BA_MAX_INT_NUM 4 #endif -#define BATTERY_LEVEL_SIZE 1 - +#define BATTERY_LEVEL_SIZE 1 -typedef struct -{ - uint8_t app_id; - uint16_t ba_level_hdl; - uint16_t clt_cfg_hdl; - uint16_t rpt_ref_hdl; - uint16_t pres_fmt_hdl; +typedef struct { + uint8_t app_id; + uint16_t ba_level_hdl; + uint16_t clt_cfg_hdl; + uint16_t rpt_ref_hdl; + uint16_t pres_fmt_hdl; - tBA_CBACK *p_cback; + tBA_CBACK* p_cback; - uint16_t pending_handle; - uint8_t pending_clcb_idx; - uint8_t pending_evt; + uint16_t pending_handle; + uint8_t pending_clcb_idx; + uint8_t pending_evt; -}tBA_INST; +} tBA_INST; -typedef struct -{ - tBA_INST battery_inst[BA_MAX_INT_NUM]; - uint8_t inst_id; - bool enabled; +typedef struct { + tBA_INST battery_inst[BA_MAX_INT_NUM]; + uint8_t inst_id; + bool enabled; -}tBATTERY_CB; +} tBATTERY_CB; /* Global GATT data */ extern tBATTERY_CB battery_cb; +extern bool battery_valid_handle_range(uint16_t handle); -extern bool battery_valid_handle_range(uint16_t handle); - -extern uint8_t battery_s_write_attr_value(uint8_t clcb_idx, tGATT_WRITE_REQ * p_value, - tGATT_STATUS *p_status); -extern uint8_t battery_s_read_attr_value (uint8_t clcb_idx, uint16_t handle, tGATT_VALUE *p_value, bool is_long, tGATT_STATUS* p_status); - - +extern uint8_t battery_s_write_attr_value(uint8_t clcb_idx, + tGATT_WRITE_REQ* p_value, + tGATT_STATUS* p_status); +extern uint8_t battery_s_read_attr_value(uint8_t clcb_idx, uint16_t handle, + tGATT_VALUE* p_value, bool is_long, + tGATT_STATUS* p_status); #ifdef __cplusplus } diff --git a/stack/srvc/srvc_dis.cc b/stack/srvc/srvc_dis.cc index addebaad3..84fd8202d 100644 --- a/stack/srvc/srvc_dis.cc +++ b/stack/srvc/srvc_dis.cc @@ -20,30 +20,48 @@ #include "bt_target.h" #include "bt_utils.h" +#include "btcore/include/uuid.h" #include "gatt_api.h" #include "gatt_int.h" #include "osi/include/log.h" #include "osi/include/osi.h" #include "srvc_dis_int.h" #include "srvc_eng_int.h" -#include "btcore/include/uuid.h" -#define DIS_MAX_NUM_INC_SVR 0 -#define DIS_MAX_CHAR_NUM 9 -#define DIS_MAX_ATTR_NUM (DIS_MAX_CHAR_NUM * 2 + DIS_MAX_NUM_INC_SVR + 1) +#define DIS_MAX_NUM_INC_SVR 0 +#define DIS_MAX_CHAR_NUM 9 +#define DIS_MAX_ATTR_NUM (DIS_MAX_CHAR_NUM * 2 + DIS_MAX_NUM_INC_SVR + 1) #ifndef DIS_ATTR_DB_SIZE -#define DIS_ATTR_DB_SIZE GATT_DB_MEM_SIZE(DIS_MAX_NUM_INC_SVR, DIS_MAX_CHAR_NUM, 0) +#define DIS_ATTR_DB_SIZE \ + GATT_DB_MEM_SIZE(DIS_MAX_NUM_INC_SVR, DIS_MAX_CHAR_NUM, 0) #endif -#define uint64_t_TO_STREAM(p, u64) {*(p)++ = (uint8_t)(u64); *(p)++ = (uint8_t)((u64) >> 8);*(p)++ = (uint8_t)((u64) >> 16); *(p)++ = (uint8_t)((u64) >> 24); \ - *(p)++ = (uint8_t)((u64) >> 32); *(p)++ = (uint8_t)((u64) >> 40);*(p)++ = (uint8_t)((u64) >> 48); *(p)++ = (uint8_t)((u64) >> 56);} - -#define STREAM_TO_UINT64(u64, p) {(u64) = (((uint64_t)(*(p))) + ((((uint64_t)(*((p) + 1)))) << 8) + ((((uint64_t)(*((p) + 2)))) << 16) + ((((uint64_t)(*((p) + 3)))) << 24) \ - + ((((uint64_t)(*((p) + 4)))) << 32) + ((((uint64_t)(*((p) + 5)))) << 40) + ((((uint64_t)(*((p) + 6)))) << 48) + ((((uint64_t)(*((p) + 7)))) << 56)); (p) += 8;} - -static const uint16_t dis_attr_uuid[DIS_MAX_CHAR_NUM] = -{ +#define uint64_t_TO_STREAM(p, u64) \ + { \ + *(p)++ = (uint8_t)(u64); \ + *(p)++ = (uint8_t)((u64) >> 8); \ + *(p)++ = (uint8_t)((u64) >> 16); \ + *(p)++ = (uint8_t)((u64) >> 24); \ + *(p)++ = (uint8_t)((u64) >> 32); \ + *(p)++ = (uint8_t)((u64) >> 40); \ + *(p)++ = (uint8_t)((u64) >> 48); \ + *(p)++ = (uint8_t)((u64) >> 56); \ + } + +#define STREAM_TO_UINT64(u64, p) \ + { \ + (u64) = (((uint64_t)(*(p))) + ((((uint64_t)(*((p) + 1)))) << 8) + \ + ((((uint64_t)(*((p) + 2)))) << 16) + \ + ((((uint64_t)(*((p) + 3)))) << 24) + \ + ((((uint64_t)(*((p) + 4)))) << 32) + \ + ((((uint64_t)(*((p) + 5)))) << 40) + \ + ((((uint64_t)(*((p) + 6)))) << 48) + \ + ((((uint64_t)(*((p) + 7)))) << 56)); \ + (p) += 8; \ + } + +static const uint16_t dis_attr_uuid[DIS_MAX_CHAR_NUM] = { GATT_UUID_SYSTEM_ID, GATT_UUID_MODEL_NUMBER_STR, GATT_UUID_SERIAL_NUMBER_STR, @@ -52,36 +70,33 @@ static const uint16_t dis_attr_uuid[DIS_MAX_CHAR_NUM] = GATT_UUID_SW_VERSION_STR, GATT_UUID_MANU_NAME, GATT_UUID_IEEE_DATA, - GATT_UUID_PNP_ID -}; + GATT_UUID_PNP_ID}; tDIS_CB dis_cb; -static tDIS_ATTR_MASK dis_uuid_to_attr(uint16_t uuid) -{ - switch (uuid) - { - case GATT_UUID_SYSTEM_ID: - return DIS_ATTR_SYS_ID_BIT; - case GATT_UUID_MODEL_NUMBER_STR: - return DIS_ATTR_MODEL_NUM_BIT; - case GATT_UUID_SERIAL_NUMBER_STR: - return DIS_ATTR_SERIAL_NUM_BIT; - case GATT_UUID_FW_VERSION_STR: - return DIS_ATTR_FW_NUM_BIT; - case GATT_UUID_HW_VERSION_STR: - return DIS_ATTR_HW_NUM_BIT; - case GATT_UUID_SW_VERSION_STR: - return DIS_ATTR_SW_NUM_BIT; - case GATT_UUID_MANU_NAME: - return DIS_ATTR_MANU_NAME_BIT; - case GATT_UUID_IEEE_DATA: - return DIS_ATTR_IEEE_DATA_BIT; - case GATT_UUID_PNP_ID: - return DIS_ATTR_PNP_ID_BIT; - default: - return 0; - }; +static tDIS_ATTR_MASK dis_uuid_to_attr(uint16_t uuid) { + switch (uuid) { + case GATT_UUID_SYSTEM_ID: + return DIS_ATTR_SYS_ID_BIT; + case GATT_UUID_MODEL_NUMBER_STR: + return DIS_ATTR_MODEL_NUM_BIT; + case GATT_UUID_SERIAL_NUMBER_STR: + return DIS_ATTR_SERIAL_NUM_BIT; + case GATT_UUID_FW_VERSION_STR: + return DIS_ATTR_FW_NUM_BIT; + case GATT_UUID_HW_VERSION_STR: + return DIS_ATTR_HW_NUM_BIT; + case GATT_UUID_SW_VERSION_STR: + return DIS_ATTR_SW_NUM_BIT; + case GATT_UUID_MANU_NAME: + return DIS_ATTR_MANU_NAME_BIT; + case GATT_UUID_IEEE_DATA: + return DIS_ATTR_IEEE_DATA_BIT; + case GATT_UUID_PNP_ID: + return DIS_ATTR_PNP_ID_BIT; + default: + return 0; + }; } /******************************************************************************* @@ -89,101 +104,91 @@ static tDIS_ATTR_MASK dis_uuid_to_attr(uint16_t uuid) * * validate a handle to be a DIS attribute handle or not. ******************************************************************************/ -bool dis_valid_handle_range(uint16_t handle) -{ - if (handle >= dis_cb.service_handle && handle <= dis_cb.max_handle) - return true; - else - return false; +bool dis_valid_handle_range(uint16_t handle) { + if (handle >= dis_cb.service_handle && handle <= dis_cb.max_handle) + return true; + else + return false; } /******************************************************************************* * dis_write_attr_value * * Process write DIS attribute request. ******************************************************************************/ -uint8_t dis_write_attr_value(UNUSED_ATTR tGATT_WRITE_REQ *p_data, tGATT_STATUS *p_status) -{ - *p_status = GATT_WRITE_NOT_PERMIT; - return SRVC_ACT_RSP; +uint8_t dis_write_attr_value(UNUSED_ATTR tGATT_WRITE_REQ* p_data, + tGATT_STATUS* p_status) { + *p_status = GATT_WRITE_NOT_PERMIT; + return SRVC_ACT_RSP; } /******************************************************************************* * DIS Attributes Database Server Request callback ******************************************************************************/ -uint8_t dis_read_attr_value (UNUSED_ATTR uint8_t clcb_idx, uint16_t handle, - tGATT_VALUE *p_value, - bool is_long, tGATT_STATUS *p_status) -{ - tDIS_DB_ENTRY *p_db_attr = dis_cb.dis_attr; - uint8_t *p = p_value->value, i, *pp; - uint16_t offset = p_value->offset; - uint8_t act = SRVC_ACT_RSP; - tGATT_STATUS st = GATT_NOT_FOUND; - - for (i = 0; i < DIS_MAX_CHAR_NUM; i ++, p_db_attr ++) - { - if (handle == p_db_attr->handle) - { - if ((p_db_attr->uuid == GATT_UUID_PNP_ID || p_db_attr->uuid == GATT_UUID_SYSTEM_ID)&& - is_long == true) - { - st = GATT_NOT_LONG; - break; - } - st = GATT_SUCCESS; - - switch (p_db_attr->uuid) - { - case GATT_UUID_MANU_NAME: - case GATT_UUID_MODEL_NUMBER_STR: - case GATT_UUID_SERIAL_NUMBER_STR: - case GATT_UUID_FW_VERSION_STR: - case GATT_UUID_HW_VERSION_STR: - case GATT_UUID_SW_VERSION_STR: - case GATT_UUID_IEEE_DATA: - pp = dis_cb.dis_value.data_string[p_db_attr->uuid - GATT_UUID_MODEL_NUMBER_STR]; - if (pp != NULL) - { - if (strlen ((char *)pp) > GATT_MAX_ATTR_LEN) - p_value->len = GATT_MAX_ATTR_LEN; - else - p_value->len = (uint16_t)strlen ((char *)pp); - } - else - p_value->len = 0; - - if (offset > p_value->len) - { - st = GATT_INVALID_OFFSET; - break; - } - else - { - p_value->len -= offset; - pp += offset; - ARRAY_TO_STREAM(p, pp, p_value->len); - GATT_TRACE_EVENT("GATT_UUID_MANU_NAME len=0x%04x", p_value->len); - } - break; - - case GATT_UUID_SYSTEM_ID: - uint64_t_TO_STREAM(p, dis_cb.dis_value.system_id); /* int_min */ - p_value->len = DIS_SYSTEM_ID_SIZE; - break; - - case GATT_UUID_PNP_ID: - UINT8_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id_src); - UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id); - UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_id); - UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_version); - p_value->len = DIS_PNP_ID_SIZE; - break; - - } +uint8_t dis_read_attr_value(UNUSED_ATTR uint8_t clcb_idx, uint16_t handle, + tGATT_VALUE* p_value, bool is_long, + tGATT_STATUS* p_status) { + tDIS_DB_ENTRY* p_db_attr = dis_cb.dis_attr; + uint8_t *p = p_value->value, i, *pp; + uint16_t offset = p_value->offset; + uint8_t act = SRVC_ACT_RSP; + tGATT_STATUS st = GATT_NOT_FOUND; + + for (i = 0; i < DIS_MAX_CHAR_NUM; i++, p_db_attr++) { + if (handle == p_db_attr->handle) { + if ((p_db_attr->uuid == GATT_UUID_PNP_ID || + p_db_attr->uuid == GATT_UUID_SYSTEM_ID) && + is_long == true) { + st = GATT_NOT_LONG; + break; + } + st = GATT_SUCCESS; + + switch (p_db_attr->uuid) { + case GATT_UUID_MANU_NAME: + case GATT_UUID_MODEL_NUMBER_STR: + case GATT_UUID_SERIAL_NUMBER_STR: + case GATT_UUID_FW_VERSION_STR: + case GATT_UUID_HW_VERSION_STR: + case GATT_UUID_SW_VERSION_STR: + case GATT_UUID_IEEE_DATA: + pp = dis_cb.dis_value + .data_string[p_db_attr->uuid - GATT_UUID_MODEL_NUMBER_STR]; + if (pp != NULL) { + if (strlen((char*)pp) > GATT_MAX_ATTR_LEN) + p_value->len = GATT_MAX_ATTR_LEN; + else + p_value->len = (uint16_t)strlen((char*)pp); + } else + p_value->len = 0; + + if (offset > p_value->len) { + st = GATT_INVALID_OFFSET; break; - } + } else { + p_value->len -= offset; + pp += offset; + ARRAY_TO_STREAM(p, pp, p_value->len); + GATT_TRACE_EVENT("GATT_UUID_MANU_NAME len=0x%04x", p_value->len); + } + break; + + case GATT_UUID_SYSTEM_ID: + uint64_t_TO_STREAM(p, dis_cb.dis_value.system_id); /* int_min */ + p_value->len = DIS_SYSTEM_ID_SIZE; + break; + + case GATT_UUID_PNP_ID: + UINT8_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id_src); + UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.vendor_id); + UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_id); + UINT16_TO_STREAM(p, dis_cb.dis_value.pnp_id.product_version); + p_value->len = DIS_PNP_ID_SIZE; + break; + } + break; } - *p_status = st; - return act; + } + *p_status = st; + return act; } /******************************************************************************* @@ -195,22 +200,20 @@ uint8_t dis_read_attr_value (UNUSED_ATTR uint8_t clcb_idx, uint16_t handle, * Returns void * ******************************************************************************/ -static void dis_gatt_c_read_dis_value_cmpl(uint16_t conn_id) -{ - tSRVC_CLCB *p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); +static void dis_gatt_c_read_dis_value_cmpl(uint16_t conn_id) { + tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); - dis_cb.dis_read_uuid_idx = 0xff; + dis_cb.dis_read_uuid_idx = 0xff; - srvc_eng_release_channel(conn_id); + srvc_eng_release_channel(conn_id); - if (dis_cb.p_read_dis_cback && p_clcb) - { - LOG_INFO(LOG_TAG, "%s conn_id:%d attr_mask = 0x%04x", __func__, conn_id, - p_clcb->dis_value.attr_mask); + if (dis_cb.p_read_dis_cback && p_clcb) { + LOG_INFO(LOG_TAG, "%s conn_id:%d attr_mask = 0x%04x", __func__, conn_id, + p_clcb->dis_value.attr_mask); - (*dis_cb.p_read_dis_cback)(p_clcb->bda, &p_clcb->dis_value); - dis_cb.p_read_dis_cback = NULL; - } + (*dis_cb.p_read_dis_cback)(p_clcb->bda, &p_clcb->dis_value); + dis_cb.p_read_dis_cback = NULL; + } } /******************************************************************************* @@ -222,36 +225,34 @@ static void dis_gatt_c_read_dis_value_cmpl(uint16_t conn_id) * Returns void * ******************************************************************************/ -bool dis_gatt_c_read_dis_req(uint16_t conn_id) -{ - tGATT_READ_PARAM param; +bool dis_gatt_c_read_dis_req(uint16_t conn_id) { + tGATT_READ_PARAM param; - memset(¶m, 0, sizeof(tGATT_READ_PARAM)); + memset(¶m, 0, sizeof(tGATT_READ_PARAM)); - param.service.uuid.len = LEN_UUID_16; - param.service.s_handle = 1; - param.service.e_handle = 0xFFFF; - param.service.auth_req = 0; + param.service.uuid.len = LEN_UUID_16; + param.service.s_handle = 1; + param.service.e_handle = 0xFFFF; + param.service.auth_req = 0; - while (dis_cb.dis_read_uuid_idx < DIS_MAX_CHAR_NUM) - { - if (dis_uuid_to_attr(dis_attr_uuid[dis_cb.dis_read_uuid_idx]) & - dis_cb.request_mask) - { - param.service.uuid.uu.uuid16 = dis_attr_uuid[dis_cb.dis_read_uuid_idx]; + while (dis_cb.dis_read_uuid_idx < DIS_MAX_CHAR_NUM) { + if (dis_uuid_to_attr(dis_attr_uuid[dis_cb.dis_read_uuid_idx]) & + dis_cb.request_mask) { + param.service.uuid.uu.uuid16 = dis_attr_uuid[dis_cb.dis_read_uuid_idx]; - if (GATTC_Read(conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS) - return true; - - GATT_TRACE_ERROR ("Read DISInfo: 0x%04x GATT_Read Failed", param.service.uuid.uu.uuid16); - } + if (GATTC_Read(conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS) + return true; - dis_cb.dis_read_uuid_idx++; + GATT_TRACE_ERROR("Read DISInfo: 0x%04x GATT_Read Failed", + param.service.uuid.uu.uuid16); } - dis_gatt_c_read_dis_value_cmpl(conn_id); + dis_cb.dis_read_uuid_idx++; + } - return(false); + dis_gatt_c_read_dis_value_cmpl(conn_id); + + return (false); } /******************************************************************************* @@ -263,72 +264,70 @@ bool dis_gatt_c_read_dis_req(uint16_t conn_id) * Returns void * ******************************************************************************/ -void dis_c_cmpl_cback (tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op, - tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) -{ - uint16_t read_type = dis_attr_uuid[dis_cb.dis_read_uuid_idx]; - uint8_t *pp = NULL, *p_str; - uint16_t conn_id = p_clcb->conn_id; - - GATT_TRACE_EVENT ("dis_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x \ - read_type: 0x%04x", op, status, read_type); - - if (op != GATTC_OPTYPE_READ) - return; - - if (p_data != NULL && status == GATT_SUCCESS) - { - pp = p_data->att_value.value; - - switch (read_type) - { - case GATT_UUID_SYSTEM_ID: - GATT_TRACE_EVENT ("DIS_ATTR_SYS_ID_BIT"); - if (p_data->att_value.len == DIS_SYSTEM_ID_SIZE) - { - p_clcb->dis_value.attr_mask |= DIS_ATTR_SYS_ID_BIT; - /* save system ID*/ - STREAM_TO_UINT64 (p_clcb->dis_value.system_id, pp); - } - break; - - case GATT_UUID_PNP_ID: - if (p_data->att_value.len == DIS_PNP_ID_SIZE) - { - p_clcb->dis_value.attr_mask |= DIS_ATTR_PNP_ID_BIT; - STREAM_TO_UINT8 (p_clcb->dis_value.pnp_id.vendor_id_src, pp); - STREAM_TO_UINT16 (p_clcb->dis_value.pnp_id.vendor_id, pp); - STREAM_TO_UINT16 (p_clcb->dis_value.pnp_id.product_id, pp); - STREAM_TO_UINT16 (p_clcb->dis_value.pnp_id.product_version, pp); - } - break; - - case GATT_UUID_MODEL_NUMBER_STR: - case GATT_UUID_SERIAL_NUMBER_STR: - case GATT_UUID_FW_VERSION_STR: - case GATT_UUID_HW_VERSION_STR: - case GATT_UUID_SW_VERSION_STR: - case GATT_UUID_MANU_NAME: - case GATT_UUID_IEEE_DATA: - p_str = p_clcb->dis_value.data_string[read_type - GATT_UUID_MODEL_NUMBER_STR]; - osi_free(p_str); - p_str = (uint8_t *)osi_malloc(p_data->att_value.len + 1); - p_clcb->dis_value.attr_mask |= dis_uuid_to_attr(read_type); - memcpy(p_str, p_data->att_value.value, p_data->att_value.len); - p_str[p_data->att_value.len] = 0; - p_clcb->dis_value.data_string[read_type - GATT_UUID_MODEL_NUMBER_STR] = p_str; - break; - - default: - break; - - break; - }/* end switch */ - }/* end if */ - - dis_cb.dis_read_uuid_idx ++; - - dis_gatt_c_read_dis_req(conn_id); +void dis_c_cmpl_cback(tSRVC_CLCB* p_clcb, tGATTC_OPTYPE op, tGATT_STATUS status, + tGATT_CL_COMPLETE* p_data) { + uint16_t read_type = dis_attr_uuid[dis_cb.dis_read_uuid_idx]; + uint8_t *pp = NULL, *p_str; + uint16_t conn_id = p_clcb->conn_id; + + GATT_TRACE_EVENT( + "dis_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x \ + read_type: 0x%04x", + op, status, read_type); + + if (op != GATTC_OPTYPE_READ) return; + + if (p_data != NULL && status == GATT_SUCCESS) { + pp = p_data->att_value.value; + + switch (read_type) { + case GATT_UUID_SYSTEM_ID: + GATT_TRACE_EVENT("DIS_ATTR_SYS_ID_BIT"); + if (p_data->att_value.len == DIS_SYSTEM_ID_SIZE) { + p_clcb->dis_value.attr_mask |= DIS_ATTR_SYS_ID_BIT; + /* save system ID*/ + STREAM_TO_UINT64(p_clcb->dis_value.system_id, pp); + } + break; + + case GATT_UUID_PNP_ID: + if (p_data->att_value.len == DIS_PNP_ID_SIZE) { + p_clcb->dis_value.attr_mask |= DIS_ATTR_PNP_ID_BIT; + STREAM_TO_UINT8(p_clcb->dis_value.pnp_id.vendor_id_src, pp); + STREAM_TO_UINT16(p_clcb->dis_value.pnp_id.vendor_id, pp); + STREAM_TO_UINT16(p_clcb->dis_value.pnp_id.product_id, pp); + STREAM_TO_UINT16(p_clcb->dis_value.pnp_id.product_version, pp); + } + break; + + case GATT_UUID_MODEL_NUMBER_STR: + case GATT_UUID_SERIAL_NUMBER_STR: + case GATT_UUID_FW_VERSION_STR: + case GATT_UUID_HW_VERSION_STR: + case GATT_UUID_SW_VERSION_STR: + case GATT_UUID_MANU_NAME: + case GATT_UUID_IEEE_DATA: + p_str = p_clcb->dis_value + .data_string[read_type - GATT_UUID_MODEL_NUMBER_STR]; + osi_free(p_str); + p_str = (uint8_t*)osi_malloc(p_data->att_value.len + 1); + p_clcb->dis_value.attr_mask |= dis_uuid_to_attr(read_type); + memcpy(p_str, p_data->att_value.value, p_data->att_value.len); + p_str[p_data->att_value.len] = 0; + p_clcb->dis_value.data_string[read_type - GATT_UUID_MODEL_NUMBER_STR] = + p_str; + break; + + default: + break; + + break; + } /* end switch */ + } /* end if */ + + dis_cb.dis_read_uuid_idx++; + + dis_gatt_c_read_dis_req(conn_id); } /******************************************************************************* @@ -338,57 +337,57 @@ void dis_c_cmpl_cback (tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op, * Description Initialize the Device Information Service Server. * ******************************************************************************/ -tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask) -{ - tGATT_STATUS status; +tDIS_STATUS DIS_SrInit(tDIS_ATTR_MASK dis_attr_mask) { + tGATT_STATUS status; - if (dis_cb.enabled) { - GATT_TRACE_ERROR("DIS already initalized"); - return DIS_SUCCESS; - } + if (dis_cb.enabled) { + GATT_TRACE_ERROR("DIS already initalized"); + return DIS_SUCCESS; + } - memset(&dis_cb, 0, sizeof(tDIS_CB)); + memset(&dis_cb, 0, sizeof(tDIS_CB)); - btgatt_db_element_t service[DIS_MAX_ATTR_NUM] = { }; + btgatt_db_element_t service[DIS_MAX_ATTR_NUM] = {}; - bt_uuid_t svc_uuid; - uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_DEVICE_INFO); - service[0].type = BTGATT_DB_PRIMARY_SERVICE; - service[0].uuid = svc_uuid; + bt_uuid_t svc_uuid; + uuid_128_from_16(&svc_uuid, UUID_SERVCLASS_DEVICE_INFO); + service[0].type = BTGATT_DB_PRIMARY_SERVICE; + service[0].uuid = svc_uuid; - for(int i=0; dis_attr_mask != 0 && i < DIS_MAX_CHAR_NUM; i++) { - dis_cb.dis_attr[i].uuid = dis_attr_uuid[i]; + for (int i = 0; dis_attr_mask != 0 && i < DIS_MAX_CHAR_NUM; i++) { + dis_cb.dis_attr[i].uuid = dis_attr_uuid[i]; - bt_uuid_t char_uuid; - uuid_128_from_16(&char_uuid, dis_cb.dis_attr[i].uuid); - /* index 0 is service, so characteristics start from 1 */ - service[i+1].type = BTGATT_DB_CHARACTERISTIC; - service[i+1].uuid = char_uuid; - service[i+1].properties = GATT_CHAR_PROP_BIT_READ; - service[i+1].permissions = GATT_PERM_READ; + bt_uuid_t char_uuid; + uuid_128_from_16(&char_uuid, dis_cb.dis_attr[i].uuid); + /* index 0 is service, so characteristics start from 1 */ + service[i + 1].type = BTGATT_DB_CHARACTERISTIC; + service[i + 1].uuid = char_uuid; + service[i + 1].properties = GATT_CHAR_PROP_BIT_READ; + service[i + 1].permissions = GATT_PERM_READ; - dis_attr_mask >>= 1; - } + dis_attr_mask >>= 1; + } - /* Add a GAP service */ - status = GATTS_AddService(srvc_eng_cb.gatt_if, service, sizeof(service)/sizeof(btgatt_db_element_t)); - if (status != GATT_SERVICE_STARTED) { - GATT_TRACE_ERROR("Can not create service, DIS_Init failed!"); - return GATT_ERROR; - } + /* Add a GAP service */ + status = GATTS_AddService(srvc_eng_cb.gatt_if, service, + sizeof(service) / sizeof(btgatt_db_element_t)); + if (status != GATT_SERVICE_STARTED) { + GATT_TRACE_ERROR("Can not create service, DIS_Init failed!"); + return GATT_ERROR; + } - dis_cb.service_handle = service[0].attribute_handle; - dis_cb.max_handle = dis_cb.service_handle + DIS_MAX_ATTR_NUM; + dis_cb.service_handle = service[0].attribute_handle; + dis_cb.max_handle = dis_cb.service_handle + DIS_MAX_ATTR_NUM; - for (int i = 0; i < DIS_MAX_CHAR_NUM; i++) { - dis_cb.dis_attr[i].handle = service[i+1].attribute_handle; + for (int i = 0; i < DIS_MAX_CHAR_NUM; i++) { + dis_cb.dis_attr[i].handle = service[i + 1].attribute_handle; - GATT_TRACE_DEBUG ("%s: handle of new attribute 0x%04 = x%d", __func__, - dis_cb.dis_attr[i].uuid, dis_cb.dis_attr[i].handle); - } + GATT_TRACE_DEBUG("%s: handle of new attribute 0x%04 = x%d", __func__, + dis_cb.dis_attr[i].uuid, dis_cb.dis_attr[i].handle); + } - dis_cb.enabled = true; - return (tDIS_STATUS) status; + dis_cb.enabled = true; + return (tDIS_STATUS)status; } /******************************************************************************* * @@ -397,49 +396,45 @@ tDIS_STATUS DIS_SrInit (tDIS_ATTR_MASK dis_attr_mask) * Description Update the DIS server attribute values * ******************************************************************************/ -tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info) -{ - uint8_t i = 1; - tDIS_STATUS st = DIS_SUCCESS; - - if (dis_attr_bit & DIS_ATTR_SYS_ID_BIT) - { - dis_cb.dis_value.system_id = p_info->system_id; +tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR* p_info) { + uint8_t i = 1; + tDIS_STATUS st = DIS_SUCCESS; + + if (dis_attr_bit & DIS_ATTR_SYS_ID_BIT) { + dis_cb.dis_value.system_id = p_info->system_id; + } else if (dis_attr_bit & DIS_ATTR_PNP_ID_BIT) { + dis_cb.dis_value.pnp_id.vendor_id = p_info->pnp_id.vendor_id; + dis_cb.dis_value.pnp_id.vendor_id_src = p_info->pnp_id.vendor_id_src; + dis_cb.dis_value.pnp_id.product_id = p_info->pnp_id.product_id; + dis_cb.dis_value.pnp_id.product_version = p_info->pnp_id.product_version; + } else { + st = DIS_ILLEGAL_PARAM; + + while (dis_attr_bit && i < (DIS_MAX_CHAR_NUM - 1)) { + if (dis_attr_bit & (uint16_t)(1 << i)) { + osi_free(dis_cb.dis_value.data_string[i - 1]); + /* coverity[OVERRUN-STATIC] False-positive : + * when i = 8, (1 << i) == DIS_ATTR_PNP_ID_BIT, + * and it will never come down here + * CID 49902: Out-of-bounds read (OVERRUN_STATIC) + * Overrunning static array "dis_cb.dis_value.data_string", with 7 + * elements, at + * position 7 with index variable "i". + */ + dis_cb.dis_value.data_string[i - 1] = + (uint8_t*)osi_malloc(p_info->data_str.len + 1); + memcpy(dis_cb.dis_value.data_string[i - 1], p_info->data_str.p_data, + p_info->data_str.len); + dis_cb.dis_value.data_string[i - 1][p_info->data_str.len] = + 0; /* make sure null terminate */ + st = DIS_SUCCESS; + + break; + } + i++; } - else if (dis_attr_bit & DIS_ATTR_PNP_ID_BIT) - { - dis_cb.dis_value.pnp_id.vendor_id = p_info->pnp_id.vendor_id; - dis_cb.dis_value.pnp_id.vendor_id_src = p_info->pnp_id.vendor_id_src; - dis_cb.dis_value.pnp_id.product_id = p_info->pnp_id.product_id; - dis_cb.dis_value.pnp_id.product_version = p_info->pnp_id.product_version; - } - else - { - st = DIS_ILLEGAL_PARAM; - - while (dis_attr_bit && i < (DIS_MAX_CHAR_NUM -1 )) - { - if (dis_attr_bit & (uint16_t)(1 << i)) - { - osi_free(dis_cb.dis_value.data_string[i - 1]); -/* coverity[OVERRUN-STATIC] False-positive : - * when i = 8, (1 << i) == DIS_ATTR_PNP_ID_BIT, - * and it will never come down here - * CID 49902: Out-of-bounds read (OVERRUN_STATIC) - * Overrunning static array "dis_cb.dis_value.data_string", with 7 elements, at - * position 7 with index variable "i". - */ - dis_cb.dis_value.data_string[i - 1] = (uint8_t *)osi_malloc(p_info->data_str.len + 1); - memcpy(dis_cb.dis_value.data_string[i - 1], p_info->data_str.p_data, p_info->data_str.len); - dis_cb.dis_value.data_string[i - 1][p_info->data_str.len] = 0; /* make sure null terminate */ - st = DIS_SUCCESS; - - break; - } - i ++; - } - } - return st; + } + return st; } /******************************************************************************* * @@ -450,40 +445,40 @@ tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info) * Returns void * ******************************************************************************/ -bool DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback, tDIS_ATTR_MASK mask) -{ - uint16_t conn_id; +bool DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK* p_cback, + tDIS_ATTR_MASK mask) { + uint16_t conn_id; - /* Initialize the DIS client if it hasn't been initialized already. */ - srvc_eng_init(); + /* Initialize the DIS client if it hasn't been initialized already. */ + srvc_eng_init(); - /* For now we only handle one at a time */ - if (dis_cb.dis_read_uuid_idx != 0xff) - return(false); + /* For now we only handle one at a time */ + if (dis_cb.dis_read_uuid_idx != 0xff) return (false); - if (p_cback == NULL) - return(false); + if (p_cback == NULL) return (false); - dis_cb.p_read_dis_cback = p_cback; - /* Mark currently active operation */ - dis_cb.dis_read_uuid_idx = 0; + dis_cb.p_read_dis_cback = p_cback; + /* Mark currently active operation */ + dis_cb.dis_read_uuid_idx = 0; - dis_cb.request_mask = mask; + dis_cb.request_mask = mask; - GATT_TRACE_EVENT ("DIS_ReadDISInfo() - BDA: %08x%04x cl_read_uuid: 0x%04x", - (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], - (peer_bda[4]<<8)+peer_bda[5], dis_attr_uuid[dis_cb.dis_read_uuid_idx]); + GATT_TRACE_EVENT("DIS_ReadDISInfo() - BDA: %08x%04x cl_read_uuid: 0x%04x", + (peer_bda[0] << 24) + (peer_bda[1] << 16) + + (peer_bda[2] << 8) + peer_bda[3], + (peer_bda[4] << 8) + peer_bda[5], + dis_attr_uuid[dis_cb.dis_read_uuid_idx]); - GATT_GetConnIdIfConnected(srvc_eng_cb.gatt_if, peer_bda, &conn_id, BT_TRANSPORT_LE); + GATT_GetConnIdIfConnected(srvc_eng_cb.gatt_if, peer_bda, &conn_id, + BT_TRANSPORT_LE); - /* need to enhance it as multiple service is needed */ - srvc_eng_request_channel(peer_bda, SRVC_ID_DIS); - - if (conn_id == GATT_INVALID_CONN_ID) - { - return GATT_Connect(srvc_eng_cb.gatt_if, peer_bda, true, BT_TRANSPORT_LE, false); - } + /* need to enhance it as multiple service is needed */ + srvc_eng_request_channel(peer_bda, SRVC_ID_DIS); - return dis_gatt_c_read_dis_req(conn_id); + if (conn_id == GATT_INVALID_CONN_ID) { + return GATT_Connect(srvc_eng_cb.gatt_if, peer_bda, true, BT_TRANSPORT_LE, + false); + } + return dis_gatt_c_read_dis_req(conn_id); } diff --git a/stack/srvc/srvc_dis_int.h b/stack/srvc/srvc_dis_int.h index d3be95efd..d690adc62 100644 --- a/stack/srvc/srvc_dis_int.h +++ b/stack/srvc/srvc_dis_int.h @@ -28,44 +28,44 @@ extern "C" { #endif -#define DIS_MAX_CHAR_NUM 9 +#define DIS_MAX_CHAR_NUM 9 -typedef struct -{ - uint16_t uuid; - uint16_t handle; -}tDIS_DB_ENTRY; +typedef struct { + uint16_t uuid; + uint16_t handle; +} tDIS_DB_ENTRY; -#define DIS_SYSTEM_ID_SIZE 8 -#define DIS_PNP_ID_SIZE 7 +#define DIS_SYSTEM_ID_SIZE 8 +#define DIS_PNP_ID_SIZE 7 -typedef struct -{ - tDIS_DB_ENTRY dis_attr[DIS_MAX_CHAR_NUM]; - tDIS_VALUE dis_value; +typedef struct { + tDIS_DB_ENTRY dis_attr[DIS_MAX_CHAR_NUM]; + tDIS_VALUE dis_value; - tDIS_READ_CBACK *p_read_dis_cback; + tDIS_READ_CBACK* p_read_dis_cback; - uint16_t service_handle; - uint16_t max_handle; + uint16_t service_handle; + uint16_t max_handle; - bool enabled; + bool enabled; - uint8_t dis_read_uuid_idx; + uint8_t dis_read_uuid_idx; - tDIS_ATTR_MASK request_mask; -}tDIS_CB; + tDIS_ATTR_MASK request_mask; +} tDIS_CB; /* Global GATT data */ extern tDIS_CB dis_cb; -extern bool dis_valid_handle_range(uint16_t handle); -extern uint8_t dis_read_attr_value (uint8_t clcb_idx, uint16_t handle, tGATT_VALUE *p_value, - bool is_long, tGATT_STATUS *p_status); -extern uint8_t dis_write_attr_value(tGATT_WRITE_REQ * p_data, tGATT_STATUS *p_status); +extern bool dis_valid_handle_range(uint16_t handle); +extern uint8_t dis_read_attr_value(uint8_t clcb_idx, uint16_t handle, + tGATT_VALUE* p_value, bool is_long, + tGATT_STATUS* p_status); +extern uint8_t dis_write_attr_value(tGATT_WRITE_REQ* p_data, + tGATT_STATUS* p_status); -extern void dis_c_cmpl_cback (tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op, - tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); +extern void dis_c_cmpl_cback(tSRVC_CLCB* p_clcb, tGATTC_OPTYPE op, + tGATT_STATUS status, tGATT_CL_COMPLETE* p_data); #ifdef __cplusplus } diff --git a/stack/srvc/srvc_eng.cc b/stack/srvc/srvc_eng.cc index ebd063a26..d9aebb933 100644 --- a/stack/srvc/srvc_eng.cc +++ b/stack/srvc/srvc_eng.cc @@ -23,31 +23,32 @@ #include "osi/include/osi.h" #include "srvc_eng_int.h" -#include "srvc_dis_int.h" #include "srvc_battery_int.h" +#include "srvc_dis_int.h" -static void srvc_eng_s_request_cback (uint16_t conn_id, uint32_t trans_id, uint8_t op_code, tGATTS_DATA *p_data); -static void srvc_eng_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, - uint16_t conn_id, bool connected, - tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport); -static void srvc_eng_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); - -static tGATT_CBACK srvc_gatt_cback = -{ - srvc_eng_connect_cback, - srvc_eng_c_cmpl_cback, - NULL, - NULL, - srvc_eng_s_request_cback, - NULL, - NULL -} ; +static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id, + uint8_t op_code, tGATTS_DATA* p_data); +static void srvc_eng_connect_cback(UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + tBT_TRANSPORT transport); +static void srvc_eng_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, + tGATT_STATUS status, + tGATT_CL_COMPLETE* p_data); + +static tGATT_CBACK srvc_gatt_cback = {srvc_eng_connect_cback, + srvc_eng_c_cmpl_cback, + NULL, + NULL, + srvc_eng_s_request_cback, + NULL, + NULL}; /* type for action functions */ -typedef void (*tSRVC_ENG_C_CMPL_ACTION)(tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op, - tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); +typedef void (*tSRVC_ENG_C_CMPL_ACTION)(tSRVC_CLCB* p_clcb, tGATTC_OPTYPE op, + tGATT_STATUS status, + tGATT_CL_COMPLETE* p_data); -const tSRVC_ENG_C_CMPL_ACTION srvc_eng_c_cmpl_act[SRVC_ID_MAX] = -{ +const tSRVC_ENG_C_CMPL_ACTION srvc_eng_c_cmpl_act[SRVC_ID_MAX] = { dis_c_cmpl_cback, }; @@ -62,20 +63,19 @@ tSRVC_ENG_CB srvc_eng_cb; * Returns total number of clcb found. * ******************************************************************************/ -uint16_t srvc_eng_find_conn_id_by_bd_addr(BD_ADDR bda) -{ - uint8_t i_clcb; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) - { - return p_clcb->conn_id; - } +uint16_t srvc_eng_find_conn_id_by_bd_addr(BD_ADDR bda) { + uint8_t i_clcb; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && + !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) { + return p_clcb->conn_id; } + } - return GATT_INVALID_CONN_ID; + return GATT_INVALID_CONN_ID; } /******************************************************************************* @@ -87,20 +87,19 @@ uint16_t srvc_eng_find_conn_id_by_bd_addr(BD_ADDR bda) * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -tSRVC_CLCB *srvc_eng_find_clcb_by_bd_addr(BD_ADDR bda) -{ - uint8_t i_clcb; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) - { - return p_clcb; - } +tSRVC_CLCB* srvc_eng_find_clcb_by_bd_addr(BD_ADDR bda) { + uint8_t i_clcb; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && + !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) { + return p_clcb; } + } - return NULL; + return NULL; } /******************************************************************************* * @@ -111,20 +110,18 @@ tSRVC_CLCB *srvc_eng_find_clcb_by_bd_addr(BD_ADDR bda) * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -tSRVC_CLCB *srvc_eng_find_clcb_by_conn_id(uint16_t conn_id) -{ - uint8_t i_clcb; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) - { - return p_clcb; - } +tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(uint16_t conn_id) { + uint8_t i_clcb; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) { + return p_clcb; } + } - return NULL; + return NULL; } /******************************************************************************* * @@ -135,20 +132,18 @@ tSRVC_CLCB *srvc_eng_find_clcb_by_conn_id(uint16_t conn_id) * Returns Pointer to the found link conenction control block. * ******************************************************************************/ -uint8_t srvc_eng_find_clcb_idx_by_conn_id(uint16_t conn_id) -{ - uint8_t i_clcb; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) - { - return i_clcb; - } +uint8_t srvc_eng_find_clcb_idx_by_conn_id(uint16_t conn_id) { + uint8_t i_clcb; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) { + return i_clcb; } + } - return SRVC_MAX_APPS; + return SRVC_MAX_APPS; } /******************************************************************************* * @@ -160,23 +155,21 @@ uint8_t srvc_eng_find_clcb_idx_by_conn_id(uint16_t conn_id) * block. * ******************************************************************************/ -tSRVC_CLCB *srvc_eng_clcb_alloc (uint16_t conn_id, BD_ADDR bda) -{ - uint8_t i_clcb = 0; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (!p_clcb->in_use) - { - p_clcb->in_use = true; - p_clcb->conn_id = conn_id; - p_clcb->connected = true; - memcpy (p_clcb->bda, bda, BD_ADDR_LEN); - break; - } +tSRVC_CLCB* srvc_eng_clcb_alloc(uint16_t conn_id, BD_ADDR bda) { + uint8_t i_clcb = 0; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (!p_clcb->in_use) { + p_clcb->in_use = true; + p_clcb->conn_id = conn_id; + p_clcb->connected = true; + memcpy(p_clcb->bda, bda, BD_ADDR_LEN); + break; } - return p_clcb; + } + return p_clcb; } /******************************************************************************* * @@ -187,68 +180,64 @@ tSRVC_CLCB *srvc_eng_clcb_alloc (uint16_t conn_id, BD_ADDR bda) * Returns True the deallocation is successful * ******************************************************************************/ -bool srvc_eng_clcb_dealloc (uint16_t conn_id) -{ - uint8_t i_clcb = 0; - tSRVC_CLCB *p_clcb = NULL; - - for (i_clcb = 0, p_clcb= srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; i_clcb++, p_clcb++) - { - if (p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id)) - { - unsigned j; - for (j = 0; j < ARRAY_SIZE(p_clcb->dis_value.data_string); j++) - osi_free(p_clcb->dis_value.data_string[j]); - - memset(p_clcb, 0, sizeof(tSRVC_CLCB)); - return true; - } +bool srvc_eng_clcb_dealloc(uint16_t conn_id) { + uint8_t i_clcb = 0; + tSRVC_CLCB* p_clcb = NULL; + + for (i_clcb = 0, p_clcb = srvc_eng_cb.clcb; i_clcb < SRVC_MAX_APPS; + i_clcb++, p_clcb++) { + if (p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id)) { + unsigned j; + for (j = 0; j < ARRAY_SIZE(p_clcb->dis_value.data_string); j++) + osi_free(p_clcb->dis_value.data_string[j]); + + memset(p_clcb, 0, sizeof(tSRVC_CLCB)); + return true; } - return false; + } + return false; } /******************************************************************************* * Service Engine Server Attributes Database Read/Read Blob Request process ******************************************************************************/ -uint8_t srvc_eng_process_read_req (uint8_t clcb_idx, tGATT_READ_REQ *p_data, tGATTS_RSP *p_rsp, tGATT_STATUS *p_status) -{ - tGATT_STATUS status = GATT_NOT_FOUND; - uint8_t act = SRVC_ACT_RSP; +uint8_t srvc_eng_process_read_req(uint8_t clcb_idx, tGATT_READ_REQ* p_data, + tGATTS_RSP* p_rsp, tGATT_STATUS* p_status) { + tGATT_STATUS status = GATT_NOT_FOUND; + uint8_t act = SRVC_ACT_RSP; - if (p_data->is_long) - p_rsp->attr_value.offset = p_data->offset; + if (p_data->is_long) p_rsp->attr_value.offset = p_data->offset; - p_rsp->attr_value.handle = p_data->handle; + p_rsp->attr_value.handle = p_data->handle; - if (dis_valid_handle_range(p_data->handle)) - act = dis_read_attr_value(clcb_idx, p_data->handle, &p_rsp->attr_value, p_data->is_long, p_status); + if (dis_valid_handle_range(p_data->handle)) + act = dis_read_attr_value(clcb_idx, p_data->handle, &p_rsp->attr_value, + p_data->is_long, p_status); - else if (battery_valid_handle_range(p_data->handle)) - act = battery_s_read_attr_value(clcb_idx, p_data->handle, &p_rsp->attr_value, p_data->is_long, p_status); + else if (battery_valid_handle_range(p_data->handle)) + act = + battery_s_read_attr_value(clcb_idx, p_data->handle, &p_rsp->attr_value, + p_data->is_long, p_status); - else - *p_status = status; - return act; + else + *p_status = status; + return act; } /******************************************************************************* * Service Engine Server Attributes Database write Request process ******************************************************************************/ -uint8_t srvc_eng_process_write_req (uint8_t clcb_idx, tGATT_WRITE_REQ *p_data, - UNUSED_ATTR tGATTS_RSP *p_rsp, tGATT_STATUS *p_status) -{ - uint8_t act = SRVC_ACT_RSP; - - if (dis_valid_handle_range(p_data->handle)) - { - act = dis_write_attr_value(p_data, p_status); - } - else if (battery_valid_handle_range(p_data->handle)) - { - act = battery_s_write_attr_value(clcb_idx, p_data, p_status); - } - else - *p_status = GATT_NOT_FOUND; - - return act; +uint8_t srvc_eng_process_write_req(uint8_t clcb_idx, tGATT_WRITE_REQ* p_data, + UNUSED_ATTR tGATTS_RSP* p_rsp, + tGATT_STATUS* p_status) { + uint8_t act = SRVC_ACT_RSP; + + if (dis_valid_handle_range(p_data->handle)) { + act = dis_write_attr_value(p_data, p_status); + } else if (battery_valid_handle_range(p_data->handle)) { + act = battery_s_write_attr_value(clcb_idx, p_data, p_status); + } else + *p_status = GATT_NOT_FOUND; + + return act; } /******************************************************************************* @@ -260,56 +249,52 @@ uint8_t srvc_eng_process_write_req (uint8_t clcb_idx, tGATT_WRITE_REQ *p_data, * Returns void. * ******************************************************************************/ -static void srvc_eng_s_request_cback (uint16_t conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type, - tGATTS_DATA *p_data) -{ - uint8_t status = GATT_INVALID_PDU; - tGATTS_RSP rsp_msg ; - uint8_t act = SRVC_ACT_IGNORE; - uint8_t clcb_idx = srvc_eng_find_clcb_idx_by_conn_id(conn_id); - - GATT_TRACE_EVENT("srvc_eng_s_request_cback : recv type (0x%02x)", type); - - memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); - - srvc_eng_cb.clcb[clcb_idx].trans_id = trans_id; - - switch (type) - { - case GATTS_REQ_TYPE_READ_CHARACTERISTIC: - case GATTS_REQ_TYPE_READ_DESCRIPTOR: - act = srvc_eng_process_read_req(clcb_idx, &p_data->read_req, &rsp_msg, &status); - break; - - case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: - case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: - act = srvc_eng_process_write_req(clcb_idx, &p_data->write_req, &rsp_msg, &status); - if (!p_data->write_req.need_rsp) - act = SRVC_ACT_IGNORE; - break; - - case GATTS_REQ_TYPE_WRITE_EXEC: - GATT_TRACE_EVENT("Ignore GATT_REQ_EXEC_WRITE/WRITE_CMD" ); - break; - - case GATTS_REQ_TYPE_MTU: - GATT_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); - break; - - default: - GATT_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); - break; - } - - srvc_eng_cb.clcb[clcb_idx].trans_id = 0; - - if (act == SRVC_ACT_RSP) - GATTS_SendRsp (conn_id, trans_id, status, &rsp_msg); - - +static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id, + tGATTS_REQ_TYPE type, + tGATTS_DATA* p_data) { + uint8_t status = GATT_INVALID_PDU; + tGATTS_RSP rsp_msg; + uint8_t act = SRVC_ACT_IGNORE; + uint8_t clcb_idx = srvc_eng_find_clcb_idx_by_conn_id(conn_id); + + GATT_TRACE_EVENT("srvc_eng_s_request_cback : recv type (0x%02x)", type); + + memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); + + srvc_eng_cb.clcb[clcb_idx].trans_id = trans_id; + + switch (type) { + case GATTS_REQ_TYPE_READ_CHARACTERISTIC: + case GATTS_REQ_TYPE_READ_DESCRIPTOR: + act = srvc_eng_process_read_req(clcb_idx, &p_data->read_req, &rsp_msg, + &status); + break; + + case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC: + case GATTS_REQ_TYPE_WRITE_DESCRIPTOR: + act = srvc_eng_process_write_req(clcb_idx, &p_data->write_req, &rsp_msg, + &status); + if (!p_data->write_req.need_rsp) act = SRVC_ACT_IGNORE; + break; + + case GATTS_REQ_TYPE_WRITE_EXEC: + GATT_TRACE_EVENT("Ignore GATT_REQ_EXEC_WRITE/WRITE_CMD"); + break; + + case GATTS_REQ_TYPE_MTU: + GATT_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); + break; + + default: + GATT_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); + break; + } + + srvc_eng_cb.clcb[clcb_idx].trans_id = 0; + + if (act == SRVC_ACT_RSP) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg); } - /******************************************************************************* * * Function srvc_eng_c_cmpl_cback @@ -319,25 +304,23 @@ static void srvc_eng_s_request_cback (uint16_t conn_id, uint32_t trans_id, tGATT * Returns void * ******************************************************************************/ -static void srvc_eng_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, - tGATT_CL_COMPLETE *p_data) -{ - tSRVC_CLCB *p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); +static void srvc_eng_c_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, + tGATT_STATUS status, + tGATT_CL_COMPLETE* p_data) { + tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); - GATT_TRACE_EVENT ("srvc_eng_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x ", op, status); + GATT_TRACE_EVENT("srvc_eng_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x ", + op, status); - if (p_clcb == NULL) - { - GATT_TRACE_ERROR("srvc_eng_c_cmpl_cback received for unknown connection"); - return; - } + if (p_clcb == NULL) { + GATT_TRACE_ERROR("srvc_eng_c_cmpl_cback received for unknown connection"); + return; + } - if (p_clcb->cur_srvc_id != SRVC_ID_NONE && - p_clcb->cur_srvc_id <= SRVC_ID_MAX) - srvc_eng_c_cmpl_act[p_clcb->cur_srvc_id - 1](p_clcb, op, status, p_data); + if (p_clcb->cur_srvc_id != SRVC_ID_NONE && p_clcb->cur_srvc_id <= SRVC_ID_MAX) + srvc_eng_c_cmpl_act[p_clcb->cur_srvc_id - 1](p_clcb, op, status, p_data); } - /******************************************************************************* * * Function srvc_eng_connect_cback @@ -347,28 +330,24 @@ static void srvc_eng_c_cmpl_cback (uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STA * Returns void * ******************************************************************************/ -static void srvc_eng_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, - uint16_t conn_id, - bool connected, tGATT_DISCONN_REASON reason, - UNUSED_ATTR tBT_TRANSPORT transport) -{ - GATT_TRACE_EVENT ("srvc_eng_connect_cback: from %08x%04x connected:%d conn_id=%d reason = 0x%04x", - (bda[0]<<24)+(bda[1]<<16)+(bda[2]<<8)+bda[3], - (bda[4]<<8)+bda[5], connected, conn_id, reason); - - if (connected) - { - if (srvc_eng_clcb_alloc(conn_id, bda) == NULL) - { - GATT_TRACE_ERROR ("srvc_eng_connect_cback: no_resource"); - return; - } - } - else - { - srvc_eng_clcb_dealloc(conn_id); +static void srvc_eng_connect_cback(UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, + uint16_t conn_id, bool connected, + tGATT_DISCONN_REASON reason, + UNUSED_ATTR tBT_TRANSPORT transport) { + GATT_TRACE_EVENT( + "srvc_eng_connect_cback: from %08x%04x connected:%d conn_id=%d reason = " + "0x%04x", + (bda[0] << 24) + (bda[1] << 16) + (bda[2] << 8) + bda[3], + (bda[4] << 8) + bda[5], connected, conn_id, reason); + + if (connected) { + if (srvc_eng_clcb_alloc(conn_id, bda) == NULL) { + GATT_TRACE_ERROR("srvc_eng_connect_cback: no_resource"); + return; } - + } else { + srvc_eng_clcb_dealloc(conn_id); + } } /******************************************************************************* * @@ -379,20 +358,18 @@ static void srvc_eng_connect_cback (UNUSED_ATTR tGATT_IF gatt_if, BD_ADDR bda, * Returns void * ******************************************************************************/ -bool srvc_eng_request_channel (BD_ADDR remote_bda, uint8_t srvc_id ) -{ - bool set = true; - tSRVC_CLCB *p_clcb = srvc_eng_find_clcb_by_bd_addr(remote_bda); +bool srvc_eng_request_channel(BD_ADDR remote_bda, uint8_t srvc_id) { + bool set = true; + tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_bd_addr(remote_bda); - if (p_clcb == NULL) - p_clcb = srvc_eng_clcb_alloc(0, remote_bda); + if (p_clcb == NULL) p_clcb = srvc_eng_clcb_alloc(0, remote_bda); - if (p_clcb && p_clcb->cur_srvc_id == SRVC_ID_NONE) - p_clcb->cur_srvc_id = srvc_id; - else - set = false; + if (p_clcb && p_clcb->cur_srvc_id == SRVC_ID_NONE) + p_clcb->cur_srvc_id = srvc_id; + else + set = false; - return set; + return set; } /******************************************************************************* * @@ -403,20 +380,18 @@ bool srvc_eng_request_channel (BD_ADDR remote_bda, uint8_t srvc_id ) * Returns void * ******************************************************************************/ -void srvc_eng_release_channel (uint16_t conn_id) -{ - tSRVC_CLCB *p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); - - if (p_clcb == NULL) - { - GATT_TRACE_ERROR("%s: invalid connection id %d", __func__, conn_id); - return; - } +void srvc_eng_release_channel(uint16_t conn_id) { + tSRVC_CLCB* p_clcb = srvc_eng_find_clcb_by_conn_id(conn_id); + + if (p_clcb == NULL) { + GATT_TRACE_ERROR("%s: invalid connection id %d", __func__, conn_id); + return; + } - p_clcb->cur_srvc_id = SRVC_ID_NONE; + p_clcb->cur_srvc_id = SRVC_ID_NONE; - /* check pending request */ - GATT_Disconnect(p_clcb->conn_id); + /* check pending request */ + GATT_Disconnect(p_clcb->conn_id); } /******************************************************************************* * @@ -425,48 +400,39 @@ void srvc_eng_release_channel (uint16_t conn_id) * Description Initializa the GATT Service engine. * ******************************************************************************/ -tGATT_STATUS srvc_eng_init (void) -{ - tBT_UUID app_uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}}; +tGATT_STATUS srvc_eng_init(void) { + tBT_UUID app_uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}}; - if (srvc_eng_cb.enabled) - { - GATT_TRACE_ERROR("DIS already initalized"); - } - else - { - memset(&srvc_eng_cb, 0, sizeof(tSRVC_ENG_CB)); + if (srvc_eng_cb.enabled) { + GATT_TRACE_ERROR("DIS already initalized"); + } else { + memset(&srvc_eng_cb, 0, sizeof(tSRVC_ENG_CB)); - /* Create a GATT profile service */ - srvc_eng_cb.gatt_if = GATT_Register(&app_uuid, &srvc_gatt_cback); - GATT_StartIf(srvc_eng_cb.gatt_if); + /* Create a GATT profile service */ + srvc_eng_cb.gatt_if = GATT_Register(&app_uuid, &srvc_gatt_cback); + GATT_StartIf(srvc_eng_cb.gatt_if); - GATT_TRACE_DEBUG ("Srvc_Init: gatt_if=%d ", srvc_eng_cb.gatt_if); + GATT_TRACE_DEBUG("Srvc_Init: gatt_if=%d ", srvc_eng_cb.gatt_if); - srvc_eng_cb.enabled = true; - dis_cb.dis_read_uuid_idx = 0xff; - } - return GATT_SUCCESS; + srvc_eng_cb.enabled = true; + dis_cb.dis_read_uuid_idx = 0xff; + } + return GATT_SUCCESS; } -void srvc_sr_rsp(uint8_t clcb_idx, tGATT_STATUS st, tGATTS_RSP *p_rsp) -{ - if (srvc_eng_cb.clcb[clcb_idx].trans_id != 0) - { - GATTS_SendRsp(srvc_eng_cb.clcb[clcb_idx].conn_id, - srvc_eng_cb.clcb[clcb_idx].trans_id, - st, - p_rsp); +void srvc_sr_rsp(uint8_t clcb_idx, tGATT_STATUS st, tGATTS_RSP* p_rsp) { + if (srvc_eng_cb.clcb[clcb_idx].trans_id != 0) { + GATTS_SendRsp(srvc_eng_cb.clcb[clcb_idx].conn_id, + srvc_eng_cb.clcb[clcb_idx].trans_id, st, p_rsp); - srvc_eng_cb.clcb[clcb_idx].trans_id = 0; - } + srvc_eng_cb.clcb[clcb_idx].trans_id = 0; + } } -void srvc_sr_notify(BD_ADDR remote_bda, uint16_t handle, uint16_t len, uint8_t *p_value) -{ - uint16_t conn_id = srvc_eng_find_conn_id_by_bd_addr(remote_bda); +void srvc_sr_notify(BD_ADDR remote_bda, uint16_t handle, uint16_t len, + uint8_t* p_value) { + uint16_t conn_id = srvc_eng_find_conn_id_by_bd_addr(remote_bda); - if (conn_id != GATT_INVALID_CONN_ID) - { - GATTS_HandleValueNotification( conn_id, handle, len, p_value); - } + if (conn_id != GATT_INVALID_CONN_ID) { + GATTS_HandleValueNotification(conn_id, handle, len, p_value); + } } diff --git a/stack/srvc/srvc_eng_int.h b/stack/srvc/srvc_eng_int.h index c5076dae9..f2b132b60 100644 --- a/stack/srvc/srvc_eng_int.h +++ b/stack/srvc/srvc_eng_int.h @@ -27,52 +27,48 @@ extern "C" { #endif -#define SRVC_MAX_APPS GATT_CL_MAX_LCB +#define SRVC_MAX_APPS GATT_CL_MAX_LCB -#define SRVC_ID_NONE 0 -#define SRVC_ID_DIS 1 -#define SRVC_ID_MAX SRVC_ID_DIS +#define SRVC_ID_NONE 0 +#define SRVC_ID_DIS 1 +#define SRVC_ID_MAX SRVC_ID_DIS -#define SRVC_ACT_IGNORE 0 -#define SRVC_ACT_RSP 1 -#define SRVC_ACT_PENDING 2 +#define SRVC_ACT_IGNORE 0 +#define SRVC_ACT_RSP 1 +#define SRVC_ACT_PENDING 2 -typedef struct -{ - bool in_use; - uint16_t conn_id; - bool connected; - BD_ADDR bda; - uint32_t trans_id; - uint8_t cur_srvc_id; +typedef struct { + bool in_use; + uint16_t conn_id; + bool connected; + BD_ADDR bda; + uint32_t trans_id; + uint8_t cur_srvc_id; - tDIS_VALUE dis_value; - -}tSRVC_CLCB; + tDIS_VALUE dis_value; +} tSRVC_CLCB; /* service engine control block */ -typedef struct -{ - tSRVC_CLCB clcb[SRVC_MAX_APPS]; /* connection link*/ - tGATT_IF gatt_if; - bool enabled; +typedef struct { + tSRVC_CLCB clcb[SRVC_MAX_APPS]; /* connection link*/ + tGATT_IF gatt_if; + bool enabled; -}tSRVC_ENG_CB; +} tSRVC_ENG_CB; /* Global GATT data */ extern tSRVC_ENG_CB srvc_eng_cb; -extern tSRVC_CLCB *srvc_eng_find_clcb_by_conn_id(uint16_t conn_id); -extern tSRVC_CLCB *srvc_eng_find_clcb_by_bd_addr(BD_ADDR bda); +extern tSRVC_CLCB* srvc_eng_find_clcb_by_conn_id(uint16_t conn_id); +extern tSRVC_CLCB* srvc_eng_find_clcb_by_bd_addr(BD_ADDR bda); extern uint16_t srvc_eng_find_conn_id_by_bd_addr(BD_ADDR bda); - -extern void srvc_eng_release_channel (uint16_t conn_id) ; -extern bool srvc_eng_request_channel (BD_ADDR remote_bda, uint8_t srvc_id ); -extern void srvc_sr_rsp(uint8_t clcb_idx, tGATT_STATUS st, tGATTS_RSP *p_rsp); -extern void srvc_sr_notify(BD_ADDR remote_bda, uint16_t handle, uint16_t len, uint8_t *p_value); - +extern void srvc_eng_release_channel(uint16_t conn_id); +extern bool srvc_eng_request_channel(BD_ADDR remote_bda, uint8_t srvc_id); +extern void srvc_sr_rsp(uint8_t clcb_idx, tGATT_STATUS st, tGATTS_RSP* p_rsp); +extern void srvc_sr_notify(BD_ADDR remote_bda, uint16_t handle, uint16_t len, + uint8_t* p_value); #ifdef __cplusplus } diff --git a/stack/test/ble_advertiser_test.cc b/stack/test/ble_advertiser_test.cc index 11537bef9..f8c46a2db 100644 --- a/stack/test/ble_advertiser_test.cc +++ b/stack/test/ble_advertiser_test.cc @@ -37,31 +37,31 @@ const int num_adv_instances = 16; * whole stack. They will be removed, or changed into mocks one by one in the * future, as the refactoring progresses */ bool BTM_BleLocalPrivacyEnabled() { return true; } -uint16_t BTM_ReadDiscoverability(uint16_t *p_window, uint16_t *p_interval) { +uint16_t BTM_ReadDiscoverability(uint16_t* p_window, uint16_t* p_interval) { return true; } -bool SMP_Encrypt(uint8_t *key, uint8_t key_len, uint8_t *plain_text, - uint8_t pt_len, tSMP_ENC *p_out) { +bool SMP_Encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text, + uint8_t pt_len, tSMP_ENC* p_out) { return true; } void BTM_GetDeviceIDRoot(BT_OCTET16 irk) {} -void btm_ble_update_dmt_flag_bits(uint8_t *flag_value, +void btm_ble_update_dmt_flag_bits(uint8_t* flag_value, const uint16_t connect_mode, const uint16_t disc_mode) {} void btm_acl_update_conn_addr(uint8_t conn_handle, BD_ADDR address) {} -void btm_gen_resolvable_private_addr(void *p_cmd_cplt_cback) { +void btm_gen_resolvable_private_addr(void* p_cmd_cplt_cback) { // TODO(jpawlowski): should call p_cmd_cplt_cback(); } -void alarm_set_on_queue(alarm_t *alarm, period_ms_t interval_ms, - alarm_callback_t cb, void *data, fixed_queue_t *queue) { +void alarm_set_on_queue(alarm_t* alarm, period_ms_t interval_ms, + alarm_callback_t cb, void* data, fixed_queue_t* queue) { } -void alarm_cancel(alarm_t *alarm) {} -alarm_t *alarm_new_periodic(const char *name) { return nullptr; } -alarm_t *alarm_new(const char *name) { return nullptr; } -void alarm_free(alarm_t *alarm) {} -const controller_t *controller_get_interface() { return nullptr; } -fixed_queue_t *btu_general_alarm_queue = nullptr; +void alarm_cancel(alarm_t* alarm) {} +alarm_t* alarm_new_periodic(const char* name) { return nullptr; } +alarm_t* alarm_new(const char* name) { return nullptr; } +void alarm_free(alarm_t* alarm) {} +const controller_t* controller_get_interface() { return nullptr; } +fixed_queue_t* btu_general_alarm_queue = nullptr; namespace { @@ -70,12 +70,13 @@ class AdvertiserHciMock : public BleAdvertiserHciInterface { AdvertiserHciMock() = default; ~AdvertiserHciMock() override = default; - MOCK_METHOD1(ReadInstanceCount, void(base::Callback)); - MOCK_METHOD1(SetAdvertisingEventObserver, void(AdvertisingEventObserver *observer)); - MOCK_METHOD4(SetAdvertisingData, - void(uint8_t, uint8_t *, uint8_t, status_cb)); + MOCK_METHOD1(ReadInstanceCount, + void(base::Callback)); + MOCK_METHOD1(SetAdvertisingEventObserver, + void(AdvertisingEventObserver* observer)); + MOCK_METHOD4(SetAdvertisingData, void(uint8_t, uint8_t*, uint8_t, status_cb)); MOCK_METHOD4(SetScanResponseData, - void(uint8_t, uint8_t *, uint8_t, status_cb)); + void(uint8_t, uint8_t*, uint8_t, status_cb)); MOCK_METHOD3(SetRandomAddress, void(BD_ADDR, uint8_t, status_cb)); MOCK_METHOD3(Enable, void(uint8_t, uint8_t, status_cb)); @@ -117,8 +118,8 @@ class BleAdvertisingManagerTest : public testing::Test { base::Callback inst_cnt_Cb; EXPECT_CALL(*hci_mock, ReadInstanceCount(_)) - .Times(Exactly(1)) - .WillOnce(SaveArg<0>(&inst_cnt_Cb)); + .Times(Exactly(1)) + .WillOnce(SaveArg<0>(&inst_cnt_Cb)); BleAdvertisingManager::Initialize(hci_mock.get()); @@ -337,10 +338,9 @@ TEST_F(BleAdvertisingManagerTest, test_reenabling) { /* Make sure that instance is not reenabled if it's already disabled */ TEST_F(BleAdvertisingManagerTest, test_reenabling_disabled_instance) { - uint8_t advertiser_id = 1; // any unregistered value + uint8_t advertiser_id = 1; // any unregistered value - EXPECT_CALL(*hci_mock, Enable(_, _, _)) - .Times(Exactly(0)); + EXPECT_CALL(*hci_mock, Enable(_, _, _)).Times(Exactly(0)); BleAdvertisingManager::Get()->OnAdvertisingStateChanged(advertiser_id, 0, 5); ::testing::Mock::VerifyAndClearExpectations(hci_mock.get()); } diff --git a/stack/test/stack_a2dp_test.cc b/stack/test/stack_a2dp_test.cc index 65e8ecd44..4274f5ee2 100644 --- a/stack/test/stack_a2dp_test.cc +++ b/stack/test/stack_a2dp_test.cc @@ -22,71 +22,71 @@ #include "stack/include/a2dp_sbc.h" #include "stack/include/a2dp_vendor.h" -//TODO(jpawlowski): remove once weird dependency in hci_layer.cc is removed +// TODO(jpawlowski): remove once weird dependency in hci_layer.cc is removed #include bt_bdaddr_t btif_local_bd_addr; namespace { const uint8_t codec_info_sbc[AVDT_CODEC_SIZE] = { - 6, // Length (A2DP_SBC_INFO_LEN) - 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO - 0, // Media Codec Type: A2DP_MEDIA_CT_SBC - 0x20 | 0x01, // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | - // Channel Mode: A2DP_SBC_IE_CH_MD_JOINT - 0x10 | 0x04 | 0x01, // Block Length: A2DP_SBC_IE_BLOCKS_16 | - // Subbands: A2DP_SBC_IE_SUBBAND_8 | - // Allocation Method: A2DP_SBC_IE_ALLOC_MD_L - 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL - 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL - 7, // Dummy - 8, // Dummy - 9 // Dummy + 6, // Length (A2DP_SBC_INFO_LEN) + 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO + 0, // Media Codec Type: A2DP_MEDIA_CT_SBC + 0x20 | 0x01, // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | + // Channel Mode: A2DP_SBC_IE_CH_MD_JOINT + 0x10 | 0x04 | 0x01, // Block Length: A2DP_SBC_IE_BLOCKS_16 | + // Subbands: A2DP_SBC_IE_SUBBAND_8 | + // Allocation Method: A2DP_SBC_IE_ALLOC_MD_L + 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL + 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL + 7, // Dummy + 8, // Dummy + 9 // Dummy }; const uint8_t codec_info_sbc_sink[AVDT_CODEC_SIZE] = { - 6, // Length (A2DP_SBC_INFO_LEN) - 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO - 0, // Media Codec Type: A2DP_MEDIA_CT_SBC - 0x20 | 0x10 | // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | - // A2DP_SBC_IE_SAMP_FREQ_48 | - 0x08 | 0x04 | 0x02 | 0x01, // Channel Mode: A2DP_SBC_IE_CH_MD_MONO | - // A2DP_SBC_IE_CH_MD_DUAL | - // A2DP_SBC_IE_CH_MD_STEREO | - // A2DP_SBC_IE_CH_MD_JOINT - 0x80 | 0x40 | 0x20 | 0x10 | // Block Length: A2DP_SBC_IE_BLOCKS_4 | - // A2DP_SBC_IE_BLOCKS_8 | - // A2DP_SBC_IE_BLOCKS_12 | - // A2DP_SBC_IE_BLOCKS_16 | - 0x08 | 0x04 | // Subbands: A2DP_SBC_IE_SUBBAND_4 | - // A2DP_SBC_IE_SUBBAND_8 | - 0x02 | 0x01, // Allocation Method: A2DP_SBC_IE_ALLOC_MD_S | - // A2DP_SBC_IE_ALLOC_MD_L - 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL - 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL - 7, // Dummy - 8, // Dummy - 9 // Dummy + 6, // Length (A2DP_SBC_INFO_LEN) + 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO + 0, // Media Codec Type: A2DP_MEDIA_CT_SBC + 0x20 | 0x10 | // Sample Frequency: A2DP_SBC_IE_SAMP_FREQ_44 | + // A2DP_SBC_IE_SAMP_FREQ_48 | + 0x08 | 0x04 | 0x02 | 0x01, // Channel Mode: A2DP_SBC_IE_CH_MD_MONO | + // A2DP_SBC_IE_CH_MD_DUAL | + // A2DP_SBC_IE_CH_MD_STEREO | + // A2DP_SBC_IE_CH_MD_JOINT + 0x80 | 0x40 | 0x20 | 0x10 | // Block Length: A2DP_SBC_IE_BLOCKS_4 | + // A2DP_SBC_IE_BLOCKS_8 | + // A2DP_SBC_IE_BLOCKS_12 | + // A2DP_SBC_IE_BLOCKS_16 | + 0x08 | 0x04 | // Subbands: A2DP_SBC_IE_SUBBAND_4 | + // A2DP_SBC_IE_SUBBAND_8 | + 0x02 | 0x01, // Allocation Method: A2DP_SBC_IE_ALLOC_MD_S | + // A2DP_SBC_IE_ALLOC_MD_L + 2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL + 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL + 7, // Dummy + 8, // Dummy + 9 // Dummy }; const uint8_t codec_info_non_a2dp[AVDT_CODEC_SIZE] = { - 8, // Length - 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO - 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP - 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 - 7, 8, // Codec ID: LSB first - 9 // Dummy + 8, // Length + 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO + 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP + 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 + 7, 8, // Codec ID: LSB first + 9 // Dummy }; const uint8_t codec_info_non_a2dp_dummy[AVDT_CODEC_SIZE] = { - 8, // Length - 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO - 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP - 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 - 7, 8, // Codec ID: LSB first - 10 // Dummy + 8, // Length + 0, // Media Type: AVDT_MEDIA_TYPE_AUDIO + 0xFF, // Media Codec Type: A2DP_MEDIA_CT_NON_A2DP + 3, 4, 0, 0, // Vendor ID: LSB first, upper two octets should be 0 + 7, 8, // Codec ID: LSB first + 10 // Dummy }; -} // namespace +} // namespace TEST(StackA2dpTest, test_a2dp_is_codec_valid) { EXPECT_TRUE(A2DP_IsSourceCodecValid(codec_info_sbc)); @@ -109,14 +109,14 @@ TEST(StackA2dpTest, test_a2dp_is_codec_valid) { EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_invalid)); memcpy(codec_info_sbc_invalid, codec_info_sbc, sizeof(codec_info_sbc)); - codec_info_sbc_invalid[0] = 0; // Corrupt the Length field + codec_info_sbc_invalid[0] = 0; // Corrupt the Length field EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_sbc_invalid)); EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_sbc_invalid)); EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_invalid)); EXPECT_FALSE(A2DP_IsPeerSinkCodecValid(codec_info_sbc_invalid)); memcpy(codec_info_sbc_invalid, codec_info_sbc, sizeof(codec_info_sbc)); - codec_info_sbc_invalid[1] = 0xff; // Corrupt the Media Type field + codec_info_sbc_invalid[1] = 0xff; // Corrupt the Media Type field EXPECT_FALSE(A2DP_IsSourceCodecValid(codec_info_sbc_invalid)); EXPECT_FALSE(A2DP_IsSinkCodecValid(codec_info_sbc_invalid)); EXPECT_FALSE(A2DP_IsPeerSourceCodecValid(codec_info_sbc_invalid)); @@ -188,10 +188,10 @@ TEST(StackA2dpTest, test_build_src2sink_config) { // Include extra (less preferred) capabilities and test again uint8_t codec_info_sbc_test1[AVDT_CODEC_SIZE]; memcpy(codec_info_sbc_test1, codec_info_sbc, sizeof(codec_info_sbc)); - codec_info_sbc_test1[3] |= (A2DP_SBC_IE_CH_MD_STEREO | A2DP_SBC_IE_CH_MD_DUAL | - A2DP_SBC_IE_CH_MD_MONO); - codec_info_sbc_test1[4] |= (A2DP_SBC_IE_BLOCKS_12 | A2DP_SBC_IE_BLOCKS_8 | - A2DP_SBC_IE_BLOCKS_4); + codec_info_sbc_test1[3] |= (A2DP_SBC_IE_CH_MD_STEREO | + A2DP_SBC_IE_CH_MD_DUAL | A2DP_SBC_IE_CH_MD_MONO); + codec_info_sbc_test1[4] |= + (A2DP_SBC_IE_BLOCKS_12 | A2DP_SBC_IE_BLOCKS_8 | A2DP_SBC_IE_BLOCKS_4); codec_info_sbc_test1[4] |= A2DP_SBC_IE_SUBBAND_4; codec_info_sbc_test1[4] |= A2DP_SBC_IE_ALLOC_MD_S; memset(codec_info_result, 0, sizeof(codec_info_result)); @@ -229,7 +229,8 @@ TEST(StackA2dpTest, test_a2dp_source_codec_sep_index) { TEST(StackA2dpTest, test_a2dp_codec_sep_index_str) { // Explicit tests for known codecs EXPECT_STREQ(A2DP_CodecSepIndexStr(A2DP_CODEC_SEP_INDEX_SOURCE_SBC), "SBC"); - EXPECT_STREQ(A2DP_CodecSepIndexStr(A2DP_CODEC_SEP_INDEX_SINK_SBC), "SBC SINK"); + EXPECT_STREQ(A2DP_CodecSepIndexStr(A2DP_CODEC_SEP_INDEX_SINK_SBC), + "SBC SINK"); // Test that the unknown codec string has not changed EXPECT_STREQ(A2DP_CodecSepIndexStr(A2DP_CODEC_SEP_INDEX_MAX), @@ -238,7 +239,7 @@ TEST(StackA2dpTest, test_a2dp_codec_sep_index_str) { // Test that each codec has a known string for (int i = 0; i < A2DP_CODEC_SEP_INDEX_MAX; i++) { tA2DP_CODEC_SEP_INDEX codec_sep_index = - static_cast(i); + static_cast(i); EXPECT_STRNE(A2DP_CodecSepIndexStr(codec_sep_index), "UNKNOWN CODEC SEP INDEX"); } @@ -256,7 +257,7 @@ TEST(StackA2dpTest, test_a2dp_init_codec_config) { for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) { EXPECT_EQ(avdt_cfg.codec_info[i], codec_info_sbc[i]); } - // Test for content protection +// Test for content protection #if (BTA_AV_CO_CP_SCMS_T == TRUE) EXPECT_EQ(avdt_cfg.protect_info[0], AVDT_CP_LOSC); EXPECT_EQ(avdt_cfg.protect_info[1], (AVDT_CP_SCMS_T_ID & 0xFF)); @@ -301,16 +302,15 @@ TEST(StackA2dpTest, test_a2dp_codec_name) { // Test all unknown codecs memcpy(codec_info_test, codec_info_sbc, sizeof(codec_info_sbc)); for (uint8_t codec_type = A2DP_MEDIA_CT_SBC + 1; - codec_type < A2DP_MEDIA_CT_NON_A2DP; - codec_type++) { - codec_info_test[2] = codec_type; // Unknown codec type + codec_type < A2DP_MEDIA_CT_NON_A2DP; codec_type++) { + codec_info_test[2] = codec_type; // Unknown codec type EXPECT_STREQ(A2DP_CodecName(codec_info_test), "UNKNOWN CODEC"); } } TEST(StackA2dpTest, test_a2dp_vendor) { EXPECT_EQ(A2DP_VendorCodecGetVendorId(codec_info_non_a2dp), - (uint32_t)0x00000403); + (uint32_t)0x00000403); EXPECT_EQ(A2DP_VendorCodecGetCodecId(codec_info_non_a2dp), (uint16_t)0x0807); EXPECT_TRUE(A2DP_VendorUsesRtpHeader(true, codec_info_non_a2dp)); EXPECT_TRUE(A2DP_VendorUsesRtpHeader(false, codec_info_non_a2dp)); @@ -318,8 +318,8 @@ TEST(StackA2dpTest, test_a2dp_vendor) { TEST(StackA2dpTest, test_a2dp_codec_type_equals) { EXPECT_TRUE(A2DP_CodecTypeEquals(codec_info_sbc, codec_info_sbc_sink)); - EXPECT_TRUE(A2DP_CodecTypeEquals(codec_info_non_a2dp, - codec_info_non_a2dp_dummy)); + EXPECT_TRUE( + A2DP_CodecTypeEquals(codec_info_non_a2dp, codec_info_non_a2dp_dummy)); EXPECT_FALSE(A2DP_CodecTypeEquals(codec_info_sbc, codec_info_non_a2dp)); } @@ -423,7 +423,7 @@ TEST(StackA2dpTest, test_a2dp_get_sink_frames_count_to_process) { TEST(StackA2dpTest, test_a2dp_get_packet_timestamp) { uint8_t a2dp_data[1000]; uint32_t timestamp; - uint32_t *p_ts = reinterpret_cast(a2dp_data); + uint32_t* p_ts = reinterpret_cast(a2dp_data); memset(a2dp_data, 0xAB, sizeof(a2dp_data)); *p_ts = 0x12345678; @@ -434,13 +434,13 @@ TEST(StackA2dpTest, test_a2dp_get_packet_timestamp) { memset(a2dp_data, 0xAB, sizeof(a2dp_data)); *p_ts = 0x12345678; timestamp = 0xFFFFFFFF; - EXPECT_FALSE(A2DP_GetPacketTimestamp(codec_info_non_a2dp, a2dp_data, - ×tamp)); + EXPECT_FALSE( + A2DP_GetPacketTimestamp(codec_info_non_a2dp, a2dp_data, ×tamp)); } TEST(StackA2dpTest, test_a2dp_build_codec_header) { uint8_t a2dp_data[1000]; - BT_HDR *p_buf = reinterpret_cast(a2dp_data); + BT_HDR* p_buf = reinterpret_cast(a2dp_data); const uint16_t BT_HDR_LEN = 500; const uint16_t BT_HDR_OFFSET = 50; const uint8_t FRAMES_PER_PACKET = 0xCD; @@ -449,17 +449,19 @@ TEST(StackA2dpTest, test_a2dp_build_codec_header) { p_buf->len = BT_HDR_LEN; p_buf->offset = BT_HDR_OFFSET; EXPECT_TRUE(A2DP_BuildCodecHeader(codec_info_sbc, p_buf, FRAMES_PER_PACKET)); - EXPECT_EQ(p_buf->offset + 1, BT_HDR_OFFSET); // Modified by A2DP_SBC_MPL_HDR_LEN - EXPECT_EQ(p_buf->len - 1, BT_HDR_LEN); // Modified by A2DP_SBC_MPL_HDR_LEN - const uint8_t *p = - reinterpret_cast(p_buf + 1) + p_buf->offset; - EXPECT_EQ(*p, static_cast(0x0D)); // 0xCD masked with A2DP_SBC_HDR_NUM_MSK + EXPECT_EQ(p_buf->offset + 1, + BT_HDR_OFFSET); // Modified by A2DP_SBC_MPL_HDR_LEN + EXPECT_EQ(p_buf->len - 1, BT_HDR_LEN); // Modified by A2DP_SBC_MPL_HDR_LEN + const uint8_t* p = + reinterpret_cast(p_buf + 1) + p_buf->offset; + EXPECT_EQ( + *p, static_cast(0x0D)); // 0xCD masked with A2DP_SBC_HDR_NUM_MSK memset(a2dp_data, 0xAB, sizeof(a2dp_data)); p_buf->len = BT_HDR_LEN; p_buf->offset = BT_HDR_OFFSET; - EXPECT_FALSE(A2DP_BuildCodecHeader(codec_info_non_a2dp, p_buf, - FRAMES_PER_PACKET)); + EXPECT_FALSE( + A2DP_BuildCodecHeader(codec_info_non_a2dp, p_buf, FRAMES_PER_PACKET)); } TEST(StackA2dpTest, test_a2dp_adjust_codec) { @@ -470,21 +472,21 @@ TEST(StackA2dpTest, test_a2dp_adjust_codec) { memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test)); - EXPECT_TRUE(memcmp(codec_info_sbc_test, codec_info_sbc, - sizeof(codec_info_sbc)) == 0); + EXPECT_TRUE( + memcmp(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)) == 0); // Test updating a valid SBC codec that needs adjustment memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); codec_info_sbc_test[6] = 54; // A2DP_SBC_MAX_BITPOOL + 1 EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test)); - EXPECT_TRUE(memcmp(codec_info_sbc_test, codec_info_sbc, - sizeof(codec_info_sbc)) == 0); + EXPECT_TRUE( + memcmp(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)) == 0); // Test updating an invalid SBC codec memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test)); memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc)); - codec_info_sbc_test[6] = 255; // Invalid MAX_BITPOOL + codec_info_sbc_test[6] = 255; // Invalid MAX_BITPOOL EXPECT_FALSE(A2DP_AdjustCodec(codec_info_sbc_test)); // Test updating a non-A2DP codec that is not recognized diff --git a/test/suite/adapter/adapter_unittest.cc b/test/suite/adapter/adapter_unittest.cc index b16dfc5f4..78c8237b1 100644 --- a/test/suite/adapter/adapter_unittest.cc +++ b/test/suite/adapter/adapter_unittest.cc @@ -32,12 +32,12 @@ const int kTestRepeatCount = 5; namespace bttest { TEST_F(BluetoothTest, AdapterEnableDisable) { - EXPECT_EQ(GetState(), BT_STATE_OFF) << - "Test should be run with Adapter disabled"; + EXPECT_EQ(GetState(), BT_STATE_OFF) + << "Test should be run with Adapter disabled"; EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); - EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; + EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); @@ -46,12 +46,12 @@ TEST_F(BluetoothTest, AdapterEnableDisable) { TEST_F(BluetoothTest, AdapterRepeatedEnableDisable) { EXPECT_EQ(GetState(), BT_STATE_OFF) - << "Test should be run with Adapter disabled"; + << "Test should be run with Adapter disabled"; for (int i = 0; i < kTestRepeatCount; ++i) { EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); - EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; + EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); @@ -60,49 +60,50 @@ TEST_F(BluetoothTest, AdapterRepeatedEnableDisable) { } TEST_F(BluetoothTest, AdapterSetGetName) { - bt_property_t *new_name = property_new_name("BluetoothTestName1"); + bt_property_t* new_name = property_new_name("BluetoothTestName1"); EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); EXPECT_EQ(GetState(), BT_STATE_ON) - << "Test should be run with Adapter enabled"; + << "Test should be run with Adapter enabled"; // Enabling the interface will call the properties callback twice before // ever reaching this point. ClearSemaphore(adapter_properties_callback_sem_); EXPECT_EQ(bt_interface()->get_adapter_property(BT_PROPERTY_BDNAME), - BT_STATUS_SUCCESS); + BT_STATUS_SUCCESS); semaphore_wait(adapter_properties_callback_sem_); EXPECT_GT(GetPropertiesChangedCount(), 0) - << "Expected at least one adapter property to change"; - bt_property_t *name_property = GetProperty(BT_PROPERTY_BDNAME); + << "Expected at least one adapter property to change"; + bt_property_t* name_property = GetProperty(BT_PROPERTY_BDNAME); EXPECT_NE(name_property, nullptr); if (property_equals(name_property, new_name)) { property_free(new_name); new_name = property_new_name("BluetoothTestName2"); } - std::string old_name((const char *)property_as_name(name_property)->name); + std::string old_name((const char*)property_as_name(name_property)->name); EXPECT_EQ(bt_interface()->set_adapter_property(new_name), BT_STATUS_SUCCESS); semaphore_wait(adapter_properties_callback_sem_); EXPECT_GT(GetPropertiesChangedCount(), 0) - << "Expected at least one adapter property to change"; + << "Expected at least one adapter property to change"; EXPECT_TRUE(GetProperty(BT_PROPERTY_BDNAME)) - << "The Bluetooth name property did not change."; + << "The Bluetooth name property did not change."; EXPECT_TRUE(property_equals(GetProperty(BT_PROPERTY_BDNAME), new_name)) - << "Bluetooth name " - << property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name - << " does not match test value " << property_as_name(new_name)->name; - + << "Bluetooth name " + << property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name + << " does not match test value " << property_as_name(new_name)->name; - bt_property_t *old_name_property = property_new_name(old_name.c_str()); - EXPECT_EQ(bt_interface()->set_adapter_property(old_name_property), BT_STATUS_SUCCESS); + bt_property_t* old_name_property = property_new_name(old_name.c_str()); + EXPECT_EQ(bt_interface()->set_adapter_property(old_name_property), + BT_STATUS_SUCCESS); semaphore_wait(adapter_properties_callback_sem_); - EXPECT_TRUE(property_equals(GetProperty(BT_PROPERTY_BDNAME), old_name_property)) - << "Bluetooth name " - << property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name - << " does not match original name" << old_name; + EXPECT_TRUE( + property_equals(GetProperty(BT_PROPERTY_BDNAME), old_name_property)) + << "Bluetooth name " + << property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name + << " does not match original name" << old_name; EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); @@ -115,12 +116,12 @@ TEST_F(BluetoothTest, AdapterStartDiscovery) { EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); EXPECT_EQ(GetState(), BT_STATE_ON) - << "Test should be run with Adapter enabled"; + << "Test should be run with Adapter enabled"; EXPECT_EQ(bt_interface()->start_discovery(), BT_STATUS_SUCCESS); semaphore_wait(discovery_state_changed_callback_sem_); EXPECT_EQ(GetDiscoveryState(), BT_DISCOVERY_STARTED) - << "Unable to start discovery."; + << "Unable to start discovery."; EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); @@ -131,7 +132,7 @@ TEST_F(BluetoothTest, AdapterCancelDiscovery) { EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); EXPECT_EQ(GetState(), BT_STATE_ON) - << "Test should be run with Adapter enabled"; + << "Test should be run with Adapter enabled"; EXPECT_EQ(bt_interface()->start_discovery(), BT_STATUS_SUCCESS); semaphore_wait(discovery_state_changed_callback_sem_); @@ -139,7 +140,7 @@ TEST_F(BluetoothTest, AdapterCancelDiscovery) { semaphore_wait(discovery_state_changed_callback_sem_); EXPECT_EQ(GetDiscoveryState(), BT_DISCOVERY_STOPPED) - << "Unable to stop discovery."; + << "Unable to stop discovery."; EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); @@ -148,14 +149,14 @@ TEST_F(BluetoothTest, AdapterCancelDiscovery) { TEST_F(BluetoothTest, AdapterDisableDuringBonding) { EXPECT_EQ(GetState(), BT_STATE_OFF) - << "Test should be run with Adapter disabled"; + << "Test should be run with Adapter disabled"; - bt_bdaddr_t bdaddr = { { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 } }; + bt_bdaddr_t bdaddr = {{0x22, 0x22, 0x22, 0x22, 0x22, 0x22}}; for (int i = 0; i < kTestRepeatCount; ++i) { EXPECT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); - EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; + EXPECT_EQ(GetState(), BT_STATE_ON) << "Adapter did not turn on."; EXPECT_EQ(bt_interface()->create_bond(&bdaddr, BT_TRANSPORT_BR_EDR), BT_STATUS_SUCCESS); diff --git a/test/suite/adapter/bluetooth_test.cc b/test/suite/adapter/bluetooth_test.cc index 0ee88da4e..eb4afd55a 100644 --- a/test/suite/adapter/bluetooth_test.cc +++ b/test/suite/adapter/bluetooth_test.cc @@ -68,16 +68,13 @@ void BluetoothTest::TearDown() { } void BluetoothTest::ClearSemaphore(semaphore_t* sem) { - while (semaphore_try_wait(sem)); + while (semaphore_try_wait(sem)) + ; } -const bt_interface_t* BluetoothTest::bt_interface() { - return bt_interface_; -} +const bt_interface_t* BluetoothTest::bt_interface() { return bt_interface_; } -bt_state_t BluetoothTest::GetState() { - return state_; -} +bt_state_t BluetoothTest::GetState() { return state_; } int BluetoothTest::GetPropertiesChangedCount() { return properties_changed_count_; @@ -94,8 +91,7 @@ bt_property_t* BluetoothTest::GetProperty(bt_property_type_t type) { bt_property_t* BluetoothTest::GetRemoteDeviceProperty(const bt_bdaddr_t* addr, bt_property_type_t type) { - if (!bdaddr_equals(&curr_remote_device_, addr)) - return nullptr; + if (!bdaddr_equals(&curr_remote_device_, addr)) return nullptr; for (int i = 0; i < remote_device_properties_changed_count_; i++) { if (remote_device_last_changed_properties_[i].type == type) { @@ -109,14 +105,10 @@ bt_discovery_state_t BluetoothTest::GetDiscoveryState() { return discovery_state_; } -bt_acl_state_t BluetoothTest::GetAclState() { - return acl_state_; -} +bt_acl_state_t BluetoothTest::GetAclState() { return acl_state_; } // Returns the device bond state. -bt_bond_state_t BluetoothTest::GetBondState() { - return bond_state_; -} +bt_bond_state_t BluetoothTest::GetBondState() { return bond_state_; } // callback void BluetoothTest::AdapterStateChangedCallback(bt_state_t new_state) { @@ -125,27 +117,26 @@ void BluetoothTest::AdapterStateChangedCallback(bt_state_t new_state) { } // callback -void BluetoothTest::AdapterPropertiesCallback( - bt_status_t status, - int num_properties, - bt_property_t* new_properties) { +void BluetoothTest::AdapterPropertiesCallback(bt_status_t status, + int num_properties, + bt_property_t* new_properties) { property_free_array(last_changed_properties_, properties_changed_count_); - last_changed_properties_ = property_copy_array(new_properties, num_properties); + last_changed_properties_ = + property_copy_array(new_properties, num_properties); properties_changed_count_ = num_properties; semaphore_post(adapter_properties_callback_sem_); } -//callback -void BluetoothTest::RemoteDevicePropertiesCallback( - bt_status_t status, - bt_bdaddr_t *remote_bd_addr, - int num_properties, - bt_property_t *properties) { +// callback +void BluetoothTest::RemoteDevicePropertiesCallback(bt_status_t status, + bt_bdaddr_t* remote_bd_addr, + int num_properties, + bt_property_t* properties) { bdaddr_copy(&curr_remote_device_, remote_bd_addr); property_free_array(remote_device_last_changed_properties_, remote_device_properties_changed_count_); - remote_device_last_changed_properties_ = property_copy_array(properties, - num_properties); + remote_device_last_changed_properties_ = + property_copy_array(properties, num_properties); remote_device_properties_changed_count_ = num_properties; semaphore_post(remote_device_properties_callback_sem_); } @@ -156,4 +147,4 @@ void BluetoothTest::DiscoveryStateChangedCallback(bt_discovery_state_t state) { semaphore_post(discovery_state_changed_callback_sem_); } -} // bttest +} // bttest diff --git a/test/suite/adapter/bluetooth_test.h b/test/suite/adapter/bluetooth_test.h index e655ab4ad..2c12aff36 100644 --- a/test/suite/adapter/bluetooth_test.h +++ b/test/suite/adapter/bluetooth_test.h @@ -78,17 +78,14 @@ class BluetoothTest : public ::testing::Test, void TearDown() override; // A callback that is called when a property changes - void AdapterPropertiesCallback( - bt_status_t status, - int num_properties, - bt_property_t *properties) override; + void AdapterPropertiesCallback(bt_status_t status, int num_properties, + bt_property_t* properties) override; // A callback that is called when the remote device's property changes - void RemoteDevicePropertiesCallback( - bt_status_t status, - bt_bdaddr_t *remote_bd_addr, - int num_properties, - bt_property_t *properties) override; + void RemoteDevicePropertiesCallback(bt_status_t status, + bt_bdaddr_t* remote_bd_addr, + int num_properties, + bt_property_t* properties) override; // A callback that is called when the adapter state changes void AdapterStateChangedCallback(bt_state_t state) override; @@ -109,10 +106,10 @@ class BluetoothTest : public ::testing::Test, bt_state_t state_; int properties_changed_count_; - bt_property_t *last_changed_properties_; + bt_property_t* last_changed_properties_; bt_bdaddr_t curr_remote_device_; int remote_device_properties_changed_count_; - bt_property_t *remote_device_last_changed_properties_; + bt_property_t* remote_device_last_changed_properties_; bt_discovery_state_t discovery_state_; bt_acl_state_t acl_state_; bt_bond_state_t bond_state_; diff --git a/test/suite/gatt/gatt_test.cc b/test/suite/gatt/gatt_test.cc index 50791f189..eec3040fb 100644 --- a/test/suite/gatt/gatt_test.cc +++ b/test/suite/gatt/gatt_test.cc @@ -91,8 +91,8 @@ const btgatt_server_interface_t* GattTest::gatt_server_interface() { } void GattTest::RegisterClientCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int clientIf, const bt_uuid_t& app_uuid) { + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int clientIf, const bt_uuid_t& app_uuid) { status_ = status; client_interface_id_ = clientIf; semaphore_post(register_client_callback_sem_); @@ -106,16 +106,16 @@ void GattTest::ScanResultCallback( // GATT server callbacks void GattTest::RegisterServerCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, const bt_uuid_t& uuid) { + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, const bt_uuid_t& uuid) { status_ = status; server_interface_id_ = server_if; semaphore_post(register_server_callback_sem_); } void GattTest::ServiceAddedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, vector service) { + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, vector service) { status_ = status; server_interface_id_ = server_if; service_handle_ = service[0].attribute_handle; @@ -123,8 +123,8 @@ void GattTest::ServiceAddedCallback( } void GattTest::ServiceStoppedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, int srvc_handle) { + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, int srvc_handle) { status_ = status; server_interface_id_ = server_if; service_handle_ = srvc_handle; @@ -132,8 +132,8 @@ void GattTest::ServiceStoppedCallback( } void GattTest::ServiceDeletedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, int srvc_handle) { + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, int srvc_handle) { status_ = status; server_interface_id_ = server_if; service_handle_ = srvc_handle; diff --git a/test/suite/gatt/gatt_test.h b/test/suite/gatt/gatt_test.h index b9bdd0862..5a1905bf8 100644 --- a/test/suite/gatt/gatt_test.h +++ b/test/suite/gatt/gatt_test.h @@ -58,25 +58,25 @@ class GattTest : public BluetoothTest, // bluetooth::hal::BluetoothGattInterface::ClientObserver overrides void RegisterClientCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int clientIf, const bt_uuid_t& app_uuid) override; - void ScanResultCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - const bt_bdaddr_t& bda, int rssi, vector adv_data) override; + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int clientIf, const bt_uuid_t& app_uuid) override; + void ScanResultCallback(bluetooth::hal::BluetoothGattInterface* /* unused */, + const bt_bdaddr_t& bda, int rssi, + vector adv_data) override; // bluetooth::hal::BluetoothGattInterface::ServerObserver overrides void RegisterServerCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, const bt_uuid_t& uuid) override; + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, const bt_uuid_t& uuid) override; void ServiceAddedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, vector service) override; + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, vector service) override; void ServiceStoppedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, int srvc_handle) override; + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, int srvc_handle) override; void ServiceDeletedCallback( - bluetooth::hal::BluetoothGattInterface* /* unused */, - int status, int server_if, int srvc_handle) override; + bluetooth::hal::BluetoothGattInterface* /* unused */, int status, + int server_if, int srvc_handle) override; // Semaphores used to wait for specific callback execution. Each callback // has its own semaphore associated with it @@ -93,7 +93,8 @@ class GattTest : public BluetoothTest, semaphore_t* service_deleted_callback_sem_; private: - // The btgatt_scanner_interface_t that all the tests use to interact with the HAL + // The btgatt_scanner_interface_t that all the tests use to interact with the + // HAL const btgatt_scanner_interface_t* gatt_scanner_interface_; // The gatt_client_interface that all the tests use to interact with the HAL diff --git a/test/suite/gatt/gatt_unittest.cc b/test/suite/gatt/gatt_unittest.cc index 64435a3c5..5de962889 100644 --- a/test/suite/gatt/gatt_unittest.cc +++ b/test/suite/gatt/gatt_unittest.cc @@ -26,10 +26,10 @@ namespace { -static void create_random_uuid(bt_uuid_t *uuid, int seed) { +static void create_random_uuid(bt_uuid_t* uuid, int seed) { srand(seed < 0 ? time(NULL) : seed); for (int i = 0; i < 16; ++i) { - uuid->uu[i] = (uint8_t) (rand() % 256); + uuid->uu[i] = (uint8_t)(rand() % 256); } } @@ -44,7 +44,7 @@ TEST_F(GattTest, GattClientRegister) { gatt_client_interface()->register_client(&gatt_client_uuid); semaphore_wait(register_client_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) - << "Error registering GATT client app callback."; + << "Error registering GATT client app callback."; // Unregisters gatt client. No callback is expected. gatt_client_interface()->unregister_client(client_interface_id()); @@ -57,7 +57,7 @@ TEST_F(GattTest, GattServerRegister) { gatt_server_interface()->register_server(&gatt_server_uuid); semaphore_wait(register_server_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) - << "Error registering GATT server app callback."; + << "Error registering GATT server app callback."; // Unregisters gatt server. No callback is expected. gatt_server_interface()->unregister_server(server_interface_id()); @@ -70,7 +70,7 @@ TEST_F(GattTest, GattServerBuild) { gatt_server_interface()->register_server(&gatt_server_uuid); semaphore_wait(register_server_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) - << "Error registering GATT server app callback."; + << "Error registering GATT server app callback."; // Service UUID. bt_uuid_t srvc_uuid; @@ -88,11 +88,12 @@ TEST_F(GattTest, GattServerBuild) { int server_if = server_interface_id(); vector service = { - {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid=srvc_uuid}, - {.type = BTGATT_DB_CHARACTERISTIC, .uuid=char_uuid, - .properties = 0x10 /* notification */, .permissions = 0x01 /* read only */}, - {.type = BTGATT_DB_DESCRIPTOR, .uuid=desc_uuid, .permissions = 0x01} - }; + {.type = BTGATT_DB_PRIMARY_SERVICE, .uuid = srvc_uuid}, + {.type = BTGATT_DB_CHARACTERISTIC, + .uuid = char_uuid, + .properties = 0x10 /* notification */, + .permissions = 0x01 /* read only */}, + {.type = BTGATT_DB_DESCRIPTOR, .uuid = desc_uuid, .permissions = 0x01}}; gatt_server_interface()->add_service(server_if, service); semaphore_wait(service_added_callback_sem_); diff --git a/test/suite/rfcomm/rfcomm_test.cc b/test/suite/rfcomm/rfcomm_test.cc index 93a23f14c..adde7cea8 100644 --- a/test/suite/rfcomm/rfcomm_test.cc +++ b/test/suite/rfcomm/rfcomm_test.cc @@ -16,52 +16,54 @@ * ******************************************************************************/ -#include "adapter/bluetooth_test.h" #include "rfcomm/rfcomm_test.h" +#include "adapter/bluetooth_test.h" #include "btcore/include/bdaddr.h" #include "btcore/include/uuid.h" namespace bttest { -const bt_uuid_t RFCommTest::HFP_UUID = {{ 0x00, 0x00, 0x11, 0x1E, - 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, - 0x5F, 0x9B, 0x34, 0xFB }}; +const bt_uuid_t RFCommTest::HFP_UUID = {{0x00, 0x00, 0x11, 0x1E, 0x00, 0x00, + 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, + 0x5F, 0x9B, 0x34, 0xFB}}; -void RFCommTest::SetUp(){ +void RFCommTest::SetUp() { BluetoothTest::SetUp(); ASSERT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS); semaphore_wait(adapter_state_changed_callback_sem_); ASSERT_TRUE(GetState() == BT_STATE_ON); - socket_interface_ = (const btsock_interface_t *)bt_interface()-> - get_profile_interface(BT_PROFILE_SOCKETS_ID); + socket_interface_ = + (const btsock_interface_t*)bt_interface()->get_profile_interface( + BT_PROFILE_SOCKETS_ID); ASSERT_NE(socket_interface_, nullptr); // Find a bonded device that supports HFP string_to_bdaddr("00:00:00:00:00:00", &bt_remote_bdaddr_); char value[1280]; - bt_property_t* bonded_devices_prop = GetProperty(BT_PROPERTY_ADAPTER_BONDED_DEVICES); + bt_property_t* bonded_devices_prop = + GetProperty(BT_PROPERTY_ADAPTER_BONDED_DEVICES); bt_bdaddr_t* devices = (bt_bdaddr_t*)bonded_devices_prop->val; int num_bonded_devices = bonded_devices_prop->len / sizeof(bt_bdaddr_t); - for (int i = 0; i < num_bonded_devices && bdaddr_is_empty(&bt_remote_bdaddr_); i++) { + for (int i = 0; i < num_bonded_devices && bdaddr_is_empty(&bt_remote_bdaddr_); + i++) { ClearSemaphore(remote_device_properties_callback_sem_); bt_interface()->get_remote_device_property(&devices[i], BT_PROPERTY_UUIDS); semaphore_wait(remote_device_properties_callback_sem_); - bt_property_t* uuid_prop = GetRemoteDeviceProperty(&devices[i], BT_PROPERTY_UUIDS); - if (uuid_prop == nullptr) - continue; - bt_uuid_t* uuids = (bt_uuid_t*) uuid_prop->val; + bt_property_t* uuid_prop = + GetRemoteDeviceProperty(&devices[i], BT_PROPERTY_UUIDS); + if (uuid_prop == nullptr) continue; + bt_uuid_t* uuids = (bt_uuid_t*)uuid_prop->val; int num_uuids = uuid_prop->len / sizeof(bt_uuid_t); for (int j = 0; j < num_uuids; j++) { uuid_to_string(&uuids[j], (uuid_string_t*)value); if (!memcmp(uuids + j, &HFP_UUID, sizeof(bt_uuid_t))) { - bdaddr_copy(&bt_remote_bdaddr_, devices+i); + bdaddr_copy(&bt_remote_bdaddr_, devices + i); break; } } diff --git a/test/suite/rfcomm/rfcomm_test.h b/test/suite/rfcomm/rfcomm_test.h index c7e5a7b43..662fdb1a2 100644 --- a/test/suite/rfcomm/rfcomm_test.h +++ b/test/suite/rfcomm/rfcomm_test.h @@ -26,8 +26,9 @@ class RFCommTest : public BluetoothTest { virtual ~RFCommTest() = default; // Getter for the RFCOMM socket - const btsock_interface_t* socket_interface() const - { return socket_interface_; } + const btsock_interface_t* socket_interface() const { + return socket_interface_; + } // SetUp initializes the Bluetooth interfaces and the RFCOMM interface virtual void SetUp(); @@ -40,7 +41,7 @@ class RFCommTest : public BluetoothTest { static const bt_uuid_t HFP_UUID; private: - const btsock_interface_t *socket_interface_; + const btsock_interface_t* socket_interface_; }; } // bttest diff --git a/test/suite/rfcomm/rfcomm_unittest.cc b/test/suite/rfcomm/rfcomm_unittest.cc index c9fd9d6e3..7655a8f57 100644 --- a/test/suite/rfcomm/rfcomm_unittest.cc +++ b/test/suite/rfcomm/rfcomm_unittest.cc @@ -36,28 +36,30 @@ TEST_F(RFCommTest, RfcommConnectPairedDevice) { size_t len = 0; error = socket_interface()->connect(&bt_remote_bdaddr_, BTSOCK_RFCOMM, - (const uint8_t *)&HFP_UUID, 0, &fd, 0, getuid()); - EXPECT_TRUE(error == BT_STATUS_SUCCESS) - << "Error creating RFCOMM socket: " << error; + (const uint8_t*)&HFP_UUID, 0, &fd, 0, + getuid()); + EXPECT_TRUE(error == BT_STATUS_SUCCESS) << "Error creating RFCOMM socket: " + << error; EXPECT_TRUE(fd != -1) << "Error creating RFCOMM socket: invalid fd"; int channel; sock_connect_signal_t signal; len = read(fd, &channel, sizeof(channel)); EXPECT_TRUE(len == sizeof(channel)) - << "Channel not read from RFCOMM socket. Bytes read: " << len; + << "Channel not read from RFCOMM socket. Bytes read: " << len; len = read(fd, &signal, sizeof(signal)); EXPECT_TRUE(len == sizeof(signal)) - << "Connection signal not read from RFCOMM socket. Bytes read: " << len; + << "Connection signal not read from RFCOMM socket. Bytes read: " << len; EXPECT_TRUE(!memcmp(&signal.bd_addr, &bt_remote_bdaddr_, sizeof(bt_bdaddr_t))) - << "Connected to a different bdaddr than expected."; - EXPECT_TRUE(channel == signal.channel) << "Inconsistent channels returned: " - << channel << " and " << signal.channel; + << "Connected to a different bdaddr than expected."; + EXPECT_TRUE(channel == signal.channel) + << "Inconsistent channels returned: " << channel << " and " + << signal.channel; len = write(fd, HANDSHAKE_COMMAND, sizeof(HANDSHAKE_COMMAND)); - EXPECT_TRUE( len == sizeof(HANDSHAKE_COMMAND)) - << "Unable to send HFP handshake. Bytes written: " << len; + EXPECT_TRUE(len == sizeof(HANDSHAKE_COMMAND)) + << "Unable to send HFP handshake. Bytes written: " << len; char response[1024]; len = read(fd, response, sizeof(response)); @@ -71,59 +73,61 @@ TEST_F(RFCommTest, RfcommRepeatedConnectPairedDevice) { int channel_fail = 0, signal_fail = 0, handshake_fail = 0, read_fail = 0; for (int i = 0; i < max_iterations; ++i) { - int fd = -1; - int error = 0; - size_t len = 0; - - error = socket_interface()->connect(&bt_remote_bdaddr_, BTSOCK_RFCOMM, - (const uint8_t *)&HFP_UUID, 0, - &fd, 0, getuid()); - ASSERT_TRUE(error == BT_STATUS_SUCCESS) - << "Error creating RFCOMM socket: " << error; - ASSERT_TRUE(fd != -1) << "Error creating RFCOMM socket: invalid fd"; - - int channel; - sock_connect_signal_t signal; - if ((len = read(fd, &channel, sizeof(channel))) != sizeof(channel)) { - ADD_FAILURE() << "Channel not read from RFCOMM socket. Bytes read: " << len - << ", Sizeof channel: " << sizeof(channel); - channel_fail++; - } - - if ((len = read(fd, &signal, sizeof(signal))) != sizeof(signal)) { - ADD_FAILURE() << "Connection signal not read from RFCOMM socket. Bytes read: " - << len; - signal_fail++; - } - - EXPECT_TRUE(!memcmp(&signal.bd_addr, &bt_remote_bdaddr_, - sizeof(bt_bdaddr_t))) + int fd = -1; + int error = 0; + size_t len = 0; + + error = socket_interface()->connect(&bt_remote_bdaddr_, BTSOCK_RFCOMM, + (const uint8_t*)&HFP_UUID, 0, &fd, 0, + getuid()); + ASSERT_TRUE(error == BT_STATUS_SUCCESS) << "Error creating RFCOMM socket: " + << error; + ASSERT_TRUE(fd != -1) << "Error creating RFCOMM socket: invalid fd"; + + int channel; + sock_connect_signal_t signal; + if ((len = read(fd, &channel, sizeof(channel))) != sizeof(channel)) { + ADD_FAILURE() << "Channel not read from RFCOMM socket. Bytes read: " + << len << ", Sizeof channel: " << sizeof(channel); + channel_fail++; + } + + if ((len = read(fd, &signal, sizeof(signal))) != sizeof(signal)) { + ADD_FAILURE() + << "Connection signal not read from RFCOMM socket. Bytes read: " + << len; + signal_fail++; + } + + EXPECT_TRUE( + !memcmp(&signal.bd_addr, &bt_remote_bdaddr_, sizeof(bt_bdaddr_t))) << "Connected to a different bdaddr than expected."; - EXPECT_TRUE(channel == signal.channel) + EXPECT_TRUE(channel == signal.channel) << "Inconsistent channels returned: " << channel << " and " << signal.channel; - if ((len = write(fd, HANDSHAKE_COMMAND, sizeof(HANDSHAKE_COMMAND))) != - sizeof(HANDSHAKE_COMMAND)) { - ADD_FAILURE() << "Unable to send HFP handshake. Bytes written: " << len; - handshake_fail++; - } + if ((len = write(fd, HANDSHAKE_COMMAND, sizeof(HANDSHAKE_COMMAND))) != + sizeof(HANDSHAKE_COMMAND)) { + ADD_FAILURE() << "Unable to send HFP handshake. Bytes written: " << len; + handshake_fail++; + } - char response[1024]; - if ((len = read(fd, response, sizeof(response))) <= 0) { - ADD_FAILURE() << "Read " << len << " bytes"; - read_fail++; - } + char response[1024]; + if ((len = read(fd, response, sizeof(response))) <= 0) { + ADD_FAILURE() << "Read " << len << " bytes"; + read_fail++; + } - close(fd); + close(fd); } - if (channel_fail > 0 || signal_fail > 0 || - handshake_fail > 0 || read_fail > 0) { - ADD_FAILURE() << "Number of channel read fails: " << channel_fail << "\n" - << "Number of signal read fails: " << signal_fail << "\n" - << "Number of handshake send fails: " << handshake_fail << "\n" - << "Number of read response fails: " << read_fail; + if (channel_fail > 0 || signal_fail > 0 || handshake_fail > 0 || + read_fail > 0) { + ADD_FAILURE() << "Number of channel read fails: " << channel_fail << "\n" + << "Number of signal read fails: " << signal_fail << "\n" + << "Number of handshake send fails: " << handshake_fail + << "\n" + << "Number of read response fails: " << read_fail; } } diff --git a/tools/bdtool/adapter.c b/tools/bdtool/adapter.c index dde8d4132..70b1b70c2 100644 --- a/tools/bdtool/adapter.c +++ b/tools/bdtool/adapter.c @@ -16,33 +16,29 @@ * ******************************************************************************/ +#include "support/adapter.h" #include "base.h" #include "btcore/include/bdaddr.h" #include "btcore/include/property.h" -#include "support/adapter.h" #include "support/callbacks.h" static bt_state_t state; static int property_count = 0; -static bt_property_t *properties = NULL; +static bt_property_t* properties = NULL; static bt_discovery_state_t discovery_state; static bt_acl_state_t acl_state; static bt_bond_state_t bond_state; -static void parse_properties(int num_properties, bt_property_t *property); +static void parse_properties(int num_properties, bt_property_t* property); // Returns the current adapter state. -bt_state_t adapter_get_state() { - return state; -} +bt_state_t adapter_get_state() { return state; } // Returns the number of adapter properties. -int adapter_get_property_count() { - return property_count; -} +int adapter_get_property_count() { return property_count; } // Returns the specified property. -bt_property_t *adapter_get_property(bt_property_type_t type) { +bt_property_t* adapter_get_property(bt_property_type_t type) { for (int i = 0; i < property_count; ++i) { if (properties[i].type == type) { return &properties[i]; @@ -53,30 +49,24 @@ bt_property_t *adapter_get_property(bt_property_type_t type) { } // Returns the device discovery state. -bt_discovery_state_t adapter_get_discovery_state() { - return discovery_state; -} +bt_discovery_state_t adapter_get_discovery_state() { return discovery_state; } // Returns the device acl state. -bt_acl_state_t adapter_get_acl_state() { - return acl_state; -} +bt_acl_state_t adapter_get_acl_state() { return acl_state; } // Returns the device bond state. -bt_bond_state_t adapter_get_bond_state() { - return bond_state; -} +bt_bond_state_t adapter_get_bond_state() { return bond_state; } // callback -void acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state) { +void acl_state_changed(bt_status_t status, bt_bdaddr_t* remote_bd_addr, + bt_acl_state_t state) { acl_state = state; CALLBACK_RET(); } // callback -void adapter_properties(bt_status_t status, - int num_properties, - bt_property_t *new_properties) { +void adapter_properties(bt_status_t status, int num_properties, + bt_property_t* new_properties) { property_free_array(properties, property_count); properties = property_copy_array(new_properties, num_properties); property_count = num_properties; @@ -91,13 +81,12 @@ void adapter_state_changed(bt_state_t new_state) { } // callback -void bond_state_changed(bt_status_t status, - bt_bdaddr_t *bdaddr, - bt_bond_state_t state) { +void bond_state_changed(bt_status_t status, bt_bdaddr_t* bdaddr, + bt_bond_state_t state) { char buf[18]; bond_state = state; - const char *state_name = "Bond state unknown"; + const char* state_name = "Bond state unknown"; switch (bond_state) { case BT_BOND_STATE_NONE: state_name = "Bond state none"; @@ -113,13 +102,14 @@ void bond_state_changed(bt_status_t status, // default none } - fprintf(stdout, "Bond state changed callback addr:%s state:%s\n", bdaddr_to_string(bdaddr, buf, sizeof(buf)), state_name); + fprintf(stdout, "Bond state changed callback addr:%s state:%s\n", + bdaddr_to_string(bdaddr, buf, sizeof(buf)), state_name); CALLBACK_RET(); } // callback -void device_found(int num_properties, bt_property_t *property) { +void device_found(int num_properties, bt_property_t* property) { fprintf(stdout, "Device found num_properties:%d\n", num_properties); parse_properties(num_properties, property); @@ -128,7 +118,7 @@ void device_found(int num_properties, bt_property_t *property) { // callback void discovery_state_changed(bt_discovery_state_t state) { - const char *state_name = "Unknown"; + const char* state_name = "Unknown"; discovery_state = state; switch (discovery_state) { @@ -148,13 +138,11 @@ void discovery_state_changed(bt_discovery_state_t state) { } // callback -void remote_device_properties(bt_status_t status, - bt_bdaddr_t *bdaddr, - int num_properties, - bt_property_t *properties) { +void remote_device_properties(bt_status_t status, bt_bdaddr_t* bdaddr, + int num_properties, bt_property_t* properties) { char buf[18]; fprintf(stdout, "Device found bdaddr:%s num_properties:%d\n", - bdaddr_to_string(bdaddr, buf, sizeof(buf)), num_properties); + bdaddr_to_string(bdaddr, buf, sizeof(buf)), num_properties); parse_properties(num_properties, properties); @@ -162,13 +150,10 @@ void remote_device_properties(bt_status_t status, } // callback -void ssp_request( - bt_bdaddr_t *remote_bd_addr, - bt_bdname_t *bd_name, - uint32_t cod, - bt_ssp_variant_t pairing_variant, - uint32_t pass_key) { - char *pairing_variant_name = "Unknown"; +void ssp_request(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, + uint32_t cod, bt_ssp_variant_t pairing_variant, + uint32_t pass_key) { + char* pairing_variant_name = "Unknown"; switch (pairing_variant) { case BT_SSP_VARIANT_PASSKEY_CONFIRMATION: @@ -187,101 +172,86 @@ void ssp_request( break; } - fprintf(stdout, "Got ssp request device_class:%u passkey:%x pairing_variant:%s\n", cod, pass_key, pairing_variant_name); + fprintf(stdout, + "Got ssp request device_class:%u passkey:%x pairing_variant:%s\n", + cod, pass_key, pairing_variant_name); char buf[18]; - fprintf(stdout, "Device found:%s %s\n", bdaddr_to_string(remote_bd_addr, buf, sizeof(buf)), bd_name->name); - + fprintf(stdout, "Device found:%s %s\n", + bdaddr_to_string(remote_bd_addr, buf, sizeof(buf)), bd_name->name); fprintf(stdout, "auto-accepting bond\n"); bool accept = true; int rc = bt_interface->ssp_reply(remote_bd_addr, pairing_variant, - (uint8_t)accept, pass_key); + (uint8_t)accept, pass_key); CALLBACK_RET(); } // callback -void thread_evt(bt_cb_thread_evt evt) { - CALLBACK_RET(); -} +void thread_evt(bt_cb_thread_evt evt) { CALLBACK_RET(); } -static void parse_properties(int num_properties, bt_property_t *property) { +static void parse_properties(int num_properties, bt_property_t* property) { while (num_properties-- > 0) { - switch(property->type) { - case BT_PROPERTY_BDNAME: - { - const bt_bdname_t *name = property_as_name(property); - if (name) - fprintf(stdout, " name:%s\n", name->name); - } - break; - - case BT_PROPERTY_BDADDR: - { - char buf[18]; - const bt_bdaddr_t *addr = property_as_addr(property); - if (addr) - fprintf(stdout, " addr:%s\n", bdaddr_to_string(addr, buf, sizeof(buf))); - } - break; - - case BT_PROPERTY_UUIDS: - { - size_t num_uuid; - const bt_uuid_t *uuid = property_as_uuids(property, &num_uuid); - if (uuid) { - for (size_t i = 0; i < num_uuid; i++) { - fprintf(stdout, " uuid:%zd: ", i); - for (size_t j = 0; j < sizeof(uuid); j++) { - fprintf(stdout, "%02x", uuid->uu[j]); - } - fprintf(stdout, "\n"); + switch (property->type) { + case BT_PROPERTY_BDNAME: { + const bt_bdname_t* name = property_as_name(property); + if (name) fprintf(stdout, " name:%s\n", name->name); + } break; + + case BT_PROPERTY_BDADDR: { + char buf[18]; + const bt_bdaddr_t* addr = property_as_addr(property); + if (addr) + fprintf(stdout, " addr:%s\n", + bdaddr_to_string(addr, buf, sizeof(buf))); + } break; + + case BT_PROPERTY_UUIDS: { + size_t num_uuid; + const bt_uuid_t* uuid = property_as_uuids(property, &num_uuid); + if (uuid) { + for (size_t i = 0; i < num_uuid; i++) { + fprintf(stdout, " uuid:%zd: ", i); + for (size_t j = 0; j < sizeof(uuid); j++) { + fprintf(stdout, "%02x", uuid->uu[j]); } + fprintf(stdout, "\n"); } } - break; - - case BT_PROPERTY_TYPE_OF_DEVICE: - { - bt_device_type_t device_type = property_as_device_type(property); - if (device_type) { - const struct { - const char * device_type; - } device_type_lookup[] = { - { "Unknown" }, - { "Classic Only" }, - { "BLE Only" }, - { "Both Classic and BLE" }, - }; - int idx = (int)device_type; - if (idx > BT_DEVICE_DEVTYPE_DUAL) - idx = 0; - fprintf(stdout, " device_type:%s\n", device_type_lookup[idx].device_type); - } + } break; + + case BT_PROPERTY_TYPE_OF_DEVICE: { + bt_device_type_t device_type = property_as_device_type(property); + if (device_type) { + const struct { + const char* device_type; + } device_type_lookup[] = { + {"Unknown"}, + {"Classic Only"}, + {"BLE Only"}, + {"Both Classic and BLE"}, + }; + int idx = (int)device_type; + if (idx > BT_DEVICE_DEVTYPE_DUAL) idx = 0; + fprintf(stdout, " device_type:%s\n", + device_type_lookup[idx].device_type); } - break; + } break; - case BT_PROPERTY_CLASS_OF_DEVICE: - { - const bt_device_class_t *dc = property_as_device_class(property); - int dc_int = device_class_to_int(dc); - fprintf(stdout, " device_class:0x%x\n", dc_int); - } - break; + case BT_PROPERTY_CLASS_OF_DEVICE: { + const bt_device_class_t* dc = property_as_device_class(property); + int dc_int = device_class_to_int(dc); + fprintf(stdout, " device_class:0x%x\n", dc_int); + } break; - case BT_PROPERTY_REMOTE_RSSI: - { - int8_t rssi = property_as_rssi(property); - fprintf(stdout, " rssi:%d\n", rssi); - } - break; + case BT_PROPERTY_REMOTE_RSSI: { + int8_t rssi = property_as_rssi(property); + fprintf(stdout, " rssi:%d\n", rssi); + } break; - case BT_PROPERTY_REMOTE_FRIENDLY_NAME: - { - const bt_bdname_t *name = property_as_name(property); - if (name) - fprintf(stdout, " remote_name:%s\n", name->name); - } - break; + case BT_PROPERTY_REMOTE_FRIENDLY_NAME: { + const bt_bdname_t* name = property_as_name(property); + if (name) fprintf(stdout, " remote_name:%s\n", name->name); + } break; case BT_PROPERTY_SERVICE_RECORD: case BT_PROPERTY_ADAPTER_SCAN_MODE: @@ -290,16 +260,15 @@ static void parse_properties(int num_properties, bt_property_t *property) { case BT_PROPERTY_REMOTE_VERSION_INFO: case BT_PROPERTY_LOCAL_LE_FEATURES: case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: - default: - { - fprintf(stderr, "Unhandled property type:%d len:%d\n", property->type, property->len); - uint8_t *p = (uint8_t *)property->val; - for (int i = 0; i < property->len; ++i, p++) { - fprintf(stderr, " %02x", *p); - } - if (property->len != 0) - fprintf(stderr, "\n"); + default: { + fprintf(stderr, "Unhandled property type:%d len:%d\n", property->type, + property->len); + uint8_t* p = (uint8_t*)property->val; + for (int i = 0; i < property->len; ++i, p++) { + fprintf(stderr, " %02x", *p); } + if (property->len != 0) fprintf(stderr, "\n"); + } } property++; } diff --git a/tools/bdtool/bdtool.c b/tools/bdtool/bdtool.c index 0f81685ad..f25cf2414 100644 --- a/tools/bdtool/bdtool.c +++ b/tools/bdtool/bdtool.c @@ -27,10 +27,14 @@ #include "test/suite/support/callbacks.h" #include "test/suite/support/hal.h" -static const bt_uuid_t HFP_UUID = {{ 0x00, 0x00, 0x11, 0x1E, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }}; -static const bt_uuid_t HFP_AG_UUID = {{ 0x00, 0x00, 0x11, 0x1F, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }}; +static const bt_uuid_t HFP_UUID = {{0x00, 0x00, 0x11, 0x1E, 0x00, 0x00, 0x10, + 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, + 0x34, 0xFB}}; +static const bt_uuid_t HFP_AG_UUID = {{0x00, 0x00, 0x11, 0x1F, 0x00, 0x00, 0x10, + 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, + 0x34, 0xFB}}; -const bt_interface_t *bt_interface; +const bt_interface_t* bt_interface; bt_bdaddr_t bt_remote_bdaddr; @@ -45,30 +49,23 @@ static bool sco_listen = false; static bool sco_connect = false; static int timeout_in_sec = 30; -static char *bd_name; +static char* bd_name; static struct option long_options[] = { - {"bdaddr", required_argument, 0, 0 }, - {"discover", no_argument, 0, 0 }, - {"discoverable", no_argument, 0, 0 }, - {"time", required_argument, 0, 0 }, - {"bond", no_argument, 0, 0 }, - {"up", no_argument, 0, 0 }, - {"verbose", no_argument, 0, 0 }, - {"get_name", no_argument, 0, 0 }, - {"set_name", required_argument, 0, 0 }, - {"sco_listen", no_argument, 0, 0 }, - {"sco_connect", no_argument, 0, 0 }, - {0, 0, 0, 0 } -}; - -static void usage(const char *name); -static bool parse_args(int argc, char **argv); + {"bdaddr", required_argument, 0, 0}, {"discover", no_argument, 0, 0}, + {"discoverable", no_argument, 0, 0}, {"time", required_argument, 0, 0}, + {"bond", no_argument, 0, 0}, {"up", no_argument, 0, 0}, + {"verbose", no_argument, 0, 0}, {"get_name", no_argument, 0, 0}, + {"set_name", required_argument, 0, 0}, {"sco_listen", no_argument, 0, 0}, + {"sco_connect", no_argument, 0, 0}, {0, 0, 0, 0}}; + +static void usage(const char* name); +static bool parse_args(int argc, char** argv); static void sig_handler(int signo); -bt_property_t *adapter_get_property(bt_property_type_t type); +bt_property_t* adapter_get_property(bt_property_type_t type); -int main(int argc, char **argv) { +int main(int argc, char** argv) { if (!parse_args(argc, argv)) { usage(argv[0]); } @@ -79,11 +76,13 @@ int main(int argc, char **argv) { } if (sco_listen && sco_connect) { - fprintf(stderr, "Can only select either sco_listen or sco_connect, not both\n"); + fprintf(stderr, + "Can only select either sco_listen or sco_connect, not both\n"); usage(argv[0]); } - if (!bond && !discover && !discoverable && !up && !get_name && !set_name && !sco_listen && !sco_connect) { + if (!bond && !discover && !discoverable && !up && !get_name && !set_name && + !sco_listen && !sco_connect) { fprintf(stderr, "Must specify one command\n"); usage(argv[0]); } @@ -117,26 +116,31 @@ int main(int argc, char **argv) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); - bt_property_t *property = property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + bt_property_t* property = + property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); int rc = bt_interface->set_adapter_property(property); - fprintf(stdout, "Set rc:%d device as discoverable for %d seconds\n", rc, timeout_in_sec); + fprintf(stdout, "Set rc:%d device as discoverable for %d seconds\n", rc, + timeout_in_sec); sleep(timeout_in_sec); property_free(property); } - if (bond) { + if (bond) { if (bdaddr_is_empty(&bt_remote_bdaddr)) { - fprintf(stderr, "Must specify a remote device address [ --bdaddr=xx:yy:zz:aa:bb:cc ]\n"); + fprintf(stderr, + "Must specify a remote device address [ " + "--bdaddr=xx:yy:zz:aa:bb:cc ]\n"); exit(1); } CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); - int rc = bt_interface->create_bond(&bt_remote_bdaddr, 0 /* UNKNOWN; Currently not documented :( */); + int rc = bt_interface->create_bond( + &bt_remote_bdaddr, 0 /* UNKNOWN; Currently not documented :( */); fprintf(stdout, "Started bonding:%d for %d seconds\n", rc, timeout_in_sec); sleep(timeout_in_sec); @@ -154,13 +158,15 @@ int main(int argc, char **argv) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); int error; - CALL_AND_WAIT(error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), adapter_properties); + CALL_AND_WAIT( + error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), + adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to get adapter property\n"); exit(1); } - bt_property_t *property = adapter_get_property(BT_PROPERTY_BDNAME); - const bt_bdname_t *name = property_as_name(property); + bt_property_t* property = adapter_get_property(BT_PROPERTY_BDNAME); + const bt_bdname_t* name = property_as_name(property); if (name) printf("Queried bluetooth device name:%s\n", name->name); else @@ -171,15 +177,18 @@ int main(int argc, char **argv) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); - bt_property_t *property = property_new_name(bd_name); + bt_property_t* property = property_new_name(bd_name); printf("Setting bluetooth device name to:%s\n", bd_name); int error; - CALL_AND_WAIT(error = bt_interface->set_adapter_property(property), adapter_properties); + CALL_AND_WAIT(error = bt_interface->set_adapter_property(property), + adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to set adapter property\n"); exit(1); } - CALL_AND_WAIT(error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), adapter_properties); + CALL_AND_WAIT( + error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), + adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to get adapter property\n"); exit(1); @@ -194,16 +203,22 @@ int main(int argc, char **argv) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); - bt_property_t *property = property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); - CALL_AND_WAIT(bt_interface->set_adapter_property(property), adapter_properties); + bt_property_t* property = + property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + CALL_AND_WAIT(bt_interface->set_adapter_property(property), + adapter_properties); property_free(property); - const btsock_interface_t *sock = bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); + const btsock_interface_t* sock = + bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); int rfcomm_fd = INVALID_FD; - int error = sock->listen(BTSOCK_RFCOMM, "meow", (const uint8_t *)&HFP_AG_UUID, 0, &rfcomm_fd, 0, app_uid); + int error = + sock->listen(BTSOCK_RFCOMM, "meow", (const uint8_t*)&HFP_AG_UUID, 0, + &rfcomm_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { - fprintf(stderr, "Unable to listen for incoming RFCOMM socket: %d\n", error); + fprintf(stderr, "Unable to listen for incoming RFCOMM socket: %d\n", + error); exit(1); } @@ -219,17 +234,22 @@ int main(int argc, char **argv) { if (sco_connect) { if (bdaddr_is_empty(&bt_remote_bdaddr)) { - fprintf(stderr, "Must specify a remote device address [ --bdaddr=xx:yy:zz:aa:bb:cc ]\n"); + fprintf(stderr, + "Must specify a remote device address [ " + "--bdaddr=xx:yy:zz:aa:bb:cc ]\n"); exit(1); } CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); - const btsock_interface_t *sock = bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); + const btsock_interface_t* sock = + bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); int rfcomm_fd = INVALID_FD; - int error = sock->connect(&bt_remote_bdaddr, BTSOCK_RFCOMM, (const uint8_t *)&HFP_AG_UUID, 0, &rfcomm_fd, 0, app_uid); + int error = + sock->connect(&bt_remote_bdaddr, BTSOCK_RFCOMM, + (const uint8_t*)&HFP_AG_UUID, 0, &rfcomm_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to connect to RFCOMM socket: %d.\n", error); exit(1); @@ -240,7 +260,8 @@ int main(int argc, char **argv) { fprintf(stdout, "Establishing SCO connection...\n"); int sock_fd = INVALID_FD; - error = sock->connect(&bt_remote_bdaddr, BTSOCK_SCO, NULL, 5, &sock_fd, 0, app_uid); + error = sock->connect(&bt_remote_bdaddr, BTSOCK_SCO, NULL, 5, &sock_fd, 0, + app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to connect to SCO socket: %d.\n", error); exit(1); @@ -261,24 +282,29 @@ static void sig_handler(int signo) { } } -static void usage(const char *name) { - fprintf(stderr, "Usage: %s [--bond|--discover|--discoverable|--up|--sco_listen|--sco_connect] [--bdaddr=] [--time=] --verbose\n", name); +static void usage(const char* name) { + fprintf(stderr, + "Usage: %s " + "[--bond|--discover|--discoverable|--up|--sco_listen|--sco_connect] " + "[--bdaddr=] [--time=] --verbose\n", + name); fprintf(stderr, " bond: Discover actively advertising devices\n"); fprintf(stderr, " discover: Discover actively advertising devices\n"); - fprintf(stderr, " discoverable: Set into a connectable and discoverable mode\n"); + fprintf(stderr, + " discoverable: Set into a connectable and discoverable mode\n"); fprintf(stderr, " up: Only bring up stack\n"); fprintf(stderr, " sco_listen: Listen for incoming SCO connections\n"); - fprintf(stderr, " sco_connect: Establish a SCO connection with another device\n"); + fprintf(stderr, + " sco_connect: Establish a SCO connection with another device\n"); fprintf(stderr, " time: Time to hold in the specified mode\n"); exit(1); } -static bool parse_args(int argc, char **argv) { +static bool parse_args(int argc, char** argv) { while (1) { int option_index = 0; int c = getopt_long_only(argc, argv, "", long_options, &option_index); - if (c != 0) - break; + if (c != 0) break; switch (c) { case 0: @@ -297,7 +323,7 @@ static bool parse_args(int argc, char **argv) { timeout_in_sec = atoi(optarg); } if (option_index == 4) { - bond = true; + bond = true; } if (option_index == 5) { up = true; @@ -309,7 +335,7 @@ static bool parse_args(int argc, char **argv) { get_name = true; } if (option_index == 8) { - bd_name = (char *)optarg; + bd_name = (char*)optarg; set_name = true; } if (option_index == 9) { @@ -327,8 +353,7 @@ static bool parse_args(int argc, char **argv) { if (optind < argc) { fprintf(stderr, "non-option ARGV-elements: "); - while (optind < argc) - fprintf(stderr, "%s ", argv[optind++]); + while (optind < argc) fprintf(stderr, "%s ", argv[optind++]); fprintf(stderr, "\n"); return false; } diff --git a/tools/hci/main.c b/tools/hci/main.c index 4fbb45739..c1678867c 100644 --- a/tools/hci/main.c +++ b/tools/hci/main.c @@ -8,46 +8,55 @@ #include "osi/include/osi.h" -typedef int (*handler_t)(int argc, char **argv); +typedef int (*handler_t)(int argc, char** argv); typedef enum { - HCI_PACKET_COMMAND = 1, + HCI_PACKET_COMMAND = 1, HCI_PACKET_ACL_DATA = 2, HCI_PACKET_SCO_DATA = 3, - HCI_PACKET_EVENT = 4, + HCI_PACKET_EVENT = 4, } hci_packet_t; typedef struct { - const char *name; - const char *help; + const char* name; + const char* help; handler_t handler; } command_t; -static int help(int argc, char **argv); -static int set_discoverable(int argc, char **argv); -static int set_name(int argc, char **argv); -static int set_pcm_loopback(int argc, char **argv); -static int set_sco_route(int argc, char **argv); +static int help(int argc, char** argv); +static int set_discoverable(int argc, char** argv); +static int set_name(int argc, char** argv); +static int set_pcm_loopback(int argc, char** argv); +static int set_sco_route(int argc, char** argv); -static bool write_hci_command(hci_packet_t type, const void *packet, size_t length); -static const command_t *find_command(const char *name); -static void usage(const char *name); +static bool write_hci_command(hci_packet_t type, const void* packet, + size_t length); +static const command_t* find_command(const char* name); +static void usage(const char* name); static const command_t commands[] = { - { "help", " - shows help text for .", help }, - { "setDiscoverable", "(true|false) - whether the controller should be discoverable.", set_discoverable }, - { "setName", " - sets the device's Bluetooth name to .", set_name }, - { "setPcmLoopback", "(true|false) - enables or disables PCM loopback on the controller.", set_pcm_loopback }, - { "setScoRoute", "(pcm|i2s|uart) - sets the SCO packet route to one of the specified buses.", set_sco_route }, + {"help", " - shows help text for .", help}, + {"setDiscoverable", + "(true|false) - whether the controller should be discoverable.", + set_discoverable}, + {"setName", " - sets the device's Bluetooth name to .", + set_name}, + {"setPcmLoopback", + "(true|false) - enables or disables PCM loopback on the controller.", + set_pcm_loopback}, + {"setScoRoute", + "(pcm|i2s|uart) - sets the SCO packet route to one of the specified " + "buses.", + set_sco_route}, }; -static int help(int argc, char **argv) { +static int help(int argc, char** argv) { if (!argc) { printf("No help command specified.\n"); return 1; } - const command_t *command = find_command(argv[0]); + const command_t* command = find_command(argv[0]); if (!command) { printf("No command named '%s'.\n", argv[0]); return 2; @@ -57,7 +66,7 @@ static int help(int argc, char **argv) { return 0; } -static int set_discoverable(int argc, char **argv) { +static int set_discoverable(int argc, char** argv) { if (argc != 1) { printf("Discoverable mode not specified.\n"); return 1; @@ -68,14 +77,13 @@ static int set_discoverable(int argc, char **argv) { return 2; } - uint8_t packet[] = { 0x1A, 0x0C, 0x01, 0x00 }; - if (argv[0][0] == 't') - packet[ARRAY_SIZE(packet) - 1] = 0x03; + uint8_t packet[] = {0x1A, 0x0C, 0x01, 0x00}; + if (argv[0][0] == 't') packet[ARRAY_SIZE(packet) - 1] = 0x03; return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet)); } -static int set_name(int argc, char **argv) { +static int set_name(int argc, char** argv) { if (argc != 1) { printf("Device name not specified.\n"); return 1; @@ -87,11 +95,10 @@ static int set_name(int argc, char **argv) { return 2; } - uint8_t packet[251] = { 0x13, 0x0C, 248 }; + uint8_t packet[251] = {0x13, 0x0C, 248}; memcpy(&packet[3], argv[0], len + 1); - if (!write_hci_command(HCI_PACKET_COMMAND, packet, sizeof(packet))) - return 1; + if (!write_hci_command(HCI_PACKET_COMMAND, packet, sizeof(packet))) return 1; memset(&packet[0], 0, sizeof(packet)); packet[0] = 0x52; @@ -104,7 +111,7 @@ static int set_name(int argc, char **argv) { return !write_hci_command(HCI_PACKET_COMMAND, packet, 0xF4); } -static int set_pcm_loopback(int argc, char **argv) { +static int set_pcm_loopback(int argc, char** argv) { if (argc != 1) { printf("PCM loopback mode not specified.\n"); return 1; @@ -115,14 +122,13 @@ static int set_pcm_loopback(int argc, char **argv) { return 2; } - uint8_t packet[] = { 0x24, 0xFC, 0x01, 0x00 }; - if (argv[0][0] == 't') - packet[ARRAY_SIZE(packet) - 1] = 0x01; + uint8_t packet[] = {0x24, 0xFC, 0x01, 0x00}; + if (argv[0][0] == 't') packet[ARRAY_SIZE(packet) - 1] = 0x01; return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet)); } -static int set_sco_route(int argc, char **argv) { +static int set_sco_route(int argc, char** argv) { if (argc != 1) { printf("SCO route parameter must be specified.\n"); return 1; @@ -141,19 +147,19 @@ static int set_sco_route(int argc, char **argv) { return 2; } - uint8_t packet[] = { 0x1C, 0xFC, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00 }; + uint8_t packet[] = {0x1C, 0xFC, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00}; packet[3] = route; return !write_hci_command(HCI_PACKET_COMMAND, packet, ARRAY_SIZE(packet)); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { if (argc < 2) { usage(argv[0]); return -1; } - const command_t *command = find_command(argv[1]); + const command_t* command = find_command(argv[1]); if (!command) { printf("Unrecognized command '%s'.\n", argv[1]); return -2; @@ -167,29 +173,24 @@ int main(int argc, char **argv) { return command->handler(argc - 2, &argv[2]); } -static bool write_hci_command(hci_packet_t type, const void *packet, size_t length) { +static bool write_hci_command(hci_packet_t type, const void* packet, + size_t length) { int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock == INVALID_FD) - goto error; + if (sock == INVALID_FD) goto error; struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(0x7F000001); addr.sin_port = htons(8873); int ret; - OSI_NO_INTR(ret = connect(sock, (const struct sockaddr *)&addr, - sizeof(addr))); - if (ret == -1) - goto error; + OSI_NO_INTR(ret = connect(sock, (const struct sockaddr*)&addr, sizeof(addr))); + if (ret == -1) goto error; - if (send(sock, &type, 1, 0) != 1) - goto error; + if (send(sock, &type, 1, 0) != 1) goto error; - if (send(sock, &length, 2, 0) != 2) - goto error; + if (send(sock, &length, 2, 0) != 2) goto error; - if (send(sock, packet, length, 0) != (ssize_t)length) - goto error; + if (send(sock, packet, length, 0) != (ssize_t)length) goto error; close(sock); return true; @@ -199,14 +200,13 @@ error:; return false; } -static const command_t *find_command(const char *name) { +static const command_t* find_command(const char* name) { for (size_t i = 0; i < ARRAY_SIZE(commands); ++i) - if (!strcmp(commands[i].name, name)) - return &commands[i]; + if (!strcmp(commands[i].name, name)) return &commands[i]; return NULL; } -static void usage(const char *name) { +static void usage(const char* name) { printf("Usage: %s [options]\n", name); printf("Commands:\n"); for (size_t i = 0; i < ARRAY_SIZE(commands); ++i) diff --git a/udrv/include/uipc.h b/udrv/include/uipc.h index e98f90d15..5d00f5410 100644 --- a/udrv/include/uipc.h +++ b/udrv/include/uipc.h @@ -22,11 +22,11 @@ extern "C" { #endif -#define UIPC_CH_ID_AV_CTRL 0 +#define UIPC_CH_ID_AV_CTRL 0 #define UIPC_CH_ID_AV_AUDIO 1 -#define UIPC_CH_NUM 2 +#define UIPC_CH_NUM 2 -#define UIPC_CH_ID_ALL 3 /* used to address all the ch id at once */ +#define UIPC_CH_ID_ALL 3 /* used to address all the ch id at once */ #define DEFAULT_READ_POLL_TMO_MS 100 @@ -34,23 +34,28 @@ typedef uint8_t tUIPC_CH_ID; /* Events generated */ typedef enum { - UIPC_OPEN_EVT = 0x0001, - UIPC_CLOSE_EVT = 0x0002, - UIPC_RX_DATA_EVT = 0x0004, - UIPC_RX_DATA_READY_EVT = 0x0008, - UIPC_TX_DATA_READY_EVT = 0x0010 + UIPC_OPEN_EVT = 0x0001, + UIPC_CLOSE_EVT = 0x0002, + UIPC_RX_DATA_EVT = 0x0004, + UIPC_RX_DATA_READY_EVT = 0x0008, + UIPC_TX_DATA_READY_EVT = 0x0010 } tUIPC_EVENT; /* * UIPC IOCTL Requests */ -#define UIPC_REQ_RX_FLUSH 1 -#define UIPC_REG_CBACK 2 -#define UIPC_REG_REMOVE_ACTIVE_READSET 3 -#define UIPC_SET_READ_POLL_TMO 4 +#define UIPC_REQ_RX_FLUSH 1 +#define UIPC_REG_CBACK 2 +#define UIPC_REG_REMOVE_ACTIVE_READSET 3 +#define UIPC_SET_READ_POLL_TMO 4 -typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */ +typedef void(tUIPC_RCV_CBACK)( + tUIPC_CH_ID ch_id, + tUIPC_EVENT event); /* points to BT_HDR which describes event type and + length of data; len contains the number of bytes of + entire message (sizeof(BT_HDR) + offset + size of + data) */ const char* dump_uipc_event(tUIPC_EVENT event); @@ -63,7 +68,7 @@ const char* dump_uipc_event(tUIPC_EVENT event); * Returns void * ******************************************************************************/ -void UIPC_Init(void *); +void UIPC_Init(void*); /******************************************************************************* * @@ -74,7 +79,7 @@ void UIPC_Init(void *); * Returns void * ******************************************************************************/ -bool UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback); +bool UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback); /******************************************************************************* * @@ -96,7 +101,8 @@ void UIPC_Close(tUIPC_CH_ID ch_id); * Returns void * ******************************************************************************/ -bool UIPC_Send(tUIPC_CH_ID ch_id, uint16_t msg_evt, uint8_t *p_buf, uint16_t msglen); +bool UIPC_Send(tUIPC_CH_ID ch_id, uint16_t msg_evt, uint8_t* p_buf, + uint16_t msglen); /******************************************************************************* * @@ -107,7 +113,8 @@ bool UIPC_Send(tUIPC_CH_ID ch_id, uint16_t msg_evt, uint8_t *p_buf, uint16_t * Returns void * ******************************************************************************/ -uint32_t UIPC_Read(tUIPC_CH_ID ch_id, uint16_t *p_msg_evt, uint8_t *p_buf, uint32_t len); +uint32_t UIPC_Read(tUIPC_CH_ID ch_id, uint16_t* p_msg_evt, uint8_t* p_buf, + uint32_t len); /******************************************************************************* * @@ -118,10 +125,10 @@ uint32_t UIPC_Read(tUIPC_CH_ID ch_id, uint16_t *p_msg_evt, uint8_t *p_buf, uint3 * Returns void * ******************************************************************************/ -bool UIPC_Ioctl(tUIPC_CH_ID ch_id, uint32_t request, void *param); +bool UIPC_Ioctl(tUIPC_CH_ID ch_id, uint32_t request, void* param); #ifdef __cplusplus } #endif -#endif /* UIPC_H */ +#endif /* UIPC_H */ diff --git a/udrv/ulinux/uipc.cc b/udrv/ulinux/uipc.cc index 235f388db..4d394c2ff 100644 --- a/udrv/ulinux/uipc.cc +++ b/udrv/ulinux/uipc.cc @@ -41,9 +41,9 @@ #include #include "audio_a2dp_hw.h" +#include "bt_common.h" #include "bt_types.h" #include "bt_utils.h" -#include "bt_common.h" #include "osi/include/osi.h" #include "osi/include/socket_utils/sockets.h" #include "uipc.h" @@ -54,14 +54,18 @@ #define PCM_FILENAME "/data/test.pcm" -#define MAX(a,b) ((a)>(b)?(a):(b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define CASE_RETURN_STR(const) case const: return #const; +#define CASE_RETURN_STR(const) \ + case const: \ + return #const; #define UIPC_DISCONNECTED (-1) -#define UIPC_LOCK() /*BTIF_TRACE_EVENT(" %s lock", __func__);*/ pthread_mutex_lock(&uipc_main.mutex); -#define UIPC_UNLOCK() /*BTIF_TRACE_EVENT("%s unlock", __func__);*/ pthread_mutex_unlock(&uipc_main.mutex); +#define UIPC_LOCK() /*BTIF_TRACE_EVENT(" %s lock", __func__);*/ \ + pthread_mutex_lock(&uipc_main.mutex); +#define UIPC_UNLOCK() /*BTIF_TRACE_EVENT("%s unlock", __func__);*/ \ + pthread_mutex_unlock(&uipc_main.mutex); #define SAFE_FD_ISSET(fd, set) (((fd) == -1) ? false : FD_ISSET((fd), (set))) @@ -72,41 +76,39 @@ *****************************************************************************/ typedef enum { - UIPC_TASK_FLAG_DISCONNECT_CHAN = 0x1, + UIPC_TASK_FLAG_DISCONNECT_CHAN = 0x1, } tUIPC_TASK_FLAGS; typedef struct { - int srvfd; - int fd; - int read_poll_tmo_ms; - int task_evt_flags; /* event flags pending to be processed in read task */ - tUIPC_EVENT cond_flags; - pthread_mutex_t cond_mutex; - pthread_cond_t cond; - tUIPC_RCV_CBACK *cback; + int srvfd; + int fd; + int read_poll_tmo_ms; + int task_evt_flags; /* event flags pending to be processed in read task */ + tUIPC_EVENT cond_flags; + pthread_mutex_t cond_mutex; + pthread_cond_t cond; + tUIPC_RCV_CBACK* cback; } tUIPC_CHAN; typedef struct { - pthread_t tid; /* main thread id */ - int running; - pthread_mutex_t mutex; + pthread_t tid; /* main thread id */ + int running; + pthread_mutex_t mutex; - fd_set active_set; - fd_set read_set; - int max_fd; - int signal_fds[2]; + fd_set active_set; + fd_set read_set; + int max_fd; + int signal_fds[2]; - tUIPC_CHAN ch[UIPC_CH_NUM]; + tUIPC_CHAN ch[UIPC_CH_NUM]; } tUIPC_MAIN; - /***************************************************************************** * Static variables *****************************************************************************/ static tUIPC_MAIN uipc_main; - /***************************************************************************** * Static functions *****************************************************************************/ @@ -117,101 +119,92 @@ static int uipc_close_ch_locked(tUIPC_CH_ID ch_id); * Externs *****************************************************************************/ - /***************************************************************************** * Helper functions *****************************************************************************/ - -const char* dump_uipc_event(tUIPC_EVENT event) -{ - switch(event) - { - CASE_RETURN_STR(UIPC_OPEN_EVT) - CASE_RETURN_STR(UIPC_CLOSE_EVT) - CASE_RETURN_STR(UIPC_RX_DATA_EVT) - CASE_RETURN_STR(UIPC_RX_DATA_READY_EVT) - CASE_RETURN_STR(UIPC_TX_DATA_READY_EVT) - default: - return "UNKNOWN MSG ID"; - } +const char* dump_uipc_event(tUIPC_EVENT event) { + switch (event) { + CASE_RETURN_STR(UIPC_OPEN_EVT) + CASE_RETURN_STR(UIPC_CLOSE_EVT) + CASE_RETURN_STR(UIPC_RX_DATA_EVT) + CASE_RETURN_STR(UIPC_RX_DATA_READY_EVT) + CASE_RETURN_STR(UIPC_TX_DATA_READY_EVT) + default: + return "UNKNOWN MSG ID"; + } } /***************************************************************************** * socket helper functions ****************************************************************************/ -static inline int create_server_socket(const char* name) -{ - int s = socket(AF_LOCAL, SOCK_STREAM, 0); - if (s < 0) - return -1; +static inline int create_server_socket(const char* name) { + int s = socket(AF_LOCAL, SOCK_STREAM, 0); + if (s < 0) return -1; - BTIF_TRACE_EVENT("create_server_socket %s", name); + BTIF_TRACE_EVENT("create_server_socket %s", name); - if(osi_socket_local_server_bind(s, name, + if (osi_socket_local_server_bind(s, name, #if defined(OS_GENERIC) - ANDROID_SOCKET_NAMESPACE_FILESYSTEM -#else // !defined(OS_GENERIC) - ANDROID_SOCKET_NAMESPACE_ABSTRACT + ANDROID_SOCKET_NAMESPACE_FILESYSTEM +#else // !defined(OS_GENERIC) + ANDROID_SOCKET_NAMESPACE_ABSTRACT #endif // defined(OS_GENERIC) - ) < 0) - { - BTIF_TRACE_EVENT("socket failed to create (%s)", strerror(errno)); - close(s); - return -1; - } - - if(listen(s, 5) < 0) - { - BTIF_TRACE_EVENT("listen failed", strerror(errno)); - close(s); - return -1; - } - - BTIF_TRACE_EVENT("created socket fd %d", s); - return s; + ) < 0) { + BTIF_TRACE_EVENT("socket failed to create (%s)", strerror(errno)); + close(s); + return -1; + } + + if (listen(s, 5) < 0) { + BTIF_TRACE_EVENT("listen failed", strerror(errno)); + close(s); + return -1; + } + + BTIF_TRACE_EVENT("created socket fd %d", s); + return s; } -static int accept_server_socket(int sfd) -{ - struct sockaddr_un remote; - struct pollfd pfd; - int fd; - socklen_t len = sizeof(struct sockaddr_un); +static int accept_server_socket(int sfd) { + struct sockaddr_un remote; + struct pollfd pfd; + int fd; + socklen_t len = sizeof(struct sockaddr_un); - BTIF_TRACE_EVENT("accept fd %d", sfd); + BTIF_TRACE_EVENT("accept fd %d", sfd); - /* make sure there is data to process */ - pfd.fd = sfd; - pfd.events = POLLIN; + /* make sure there is data to process */ + pfd.fd = sfd; + pfd.events = POLLIN; - int poll_ret; - OSI_NO_INTR(poll_ret = poll(&pfd, 1, 0)); - if (poll_ret == 0) - { - BTIF_TRACE_WARNING("accept poll timeout"); - return -1; - } + int poll_ret; + OSI_NO_INTR(poll_ret = poll(&pfd, 1, 0)); + if (poll_ret == 0) { + BTIF_TRACE_WARNING("accept poll timeout"); + return -1; + } - //BTIF_TRACE_EVENT("poll revents 0x%x", pfd.revents); + // BTIF_TRACE_EVENT("poll revents 0x%x", pfd.revents); - OSI_NO_INTR(fd = accept(sfd, (struct sockaddr *)&remote, &len)); - if (fd == -1) { - BTIF_TRACE_ERROR("sock accept failed (%s)", strerror(errno)); - return -1; - } + OSI_NO_INTR(fd = accept(sfd, (struct sockaddr*)&remote, &len)); + if (fd == -1) { + BTIF_TRACE_ERROR("sock accept failed (%s)", strerror(errno)); + return -1; + } - // match socket buffer size option with client - const int size = AUDIO_STREAM_OUTPUT_BUFFER_SZ; - int ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&size, (int)sizeof(size)); - if (ret < 0) { - BTIF_TRACE_ERROR("setsockopt failed (%s)", strerror(errno)); - } + // match socket buffer size option with client + const int size = AUDIO_STREAM_OUTPUT_BUFFER_SZ; + int ret = + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&size, (int)sizeof(size)); + if (ret < 0) { + BTIF_TRACE_ERROR("setsockopt failed (%s)", strerror(errno)); + } - //BTIF_TRACE_EVENT("new fd %d", fd); + // BTIF_TRACE_EVENT("new fd %d", fd); - return fd; + return fd; } /***************************************************************************** @@ -220,377 +213,329 @@ static int accept_server_socket(int sfd) * ****************************************************************************/ -static int uipc_main_init(void) -{ - int i; - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&uipc_main.mutex, &attr); - - BTIF_TRACE_EVENT("### uipc_main_init ###"); - - /* setup interrupt socket pair */ - if (socketpair(AF_UNIX, SOCK_STREAM, 0, uipc_main.signal_fds) < 0) - { - return -1; - } - - FD_SET(uipc_main.signal_fds[0], &uipc_main.active_set); - uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.signal_fds[0]); - - for (i=0; i< UIPC_CH_NUM; i++) - { - tUIPC_CHAN *p = &uipc_main.ch[i]; - p->srvfd = UIPC_DISCONNECTED; - p->fd = UIPC_DISCONNECTED; - p->task_evt_flags = 0; - pthread_cond_init(&p->cond, NULL); - pthread_mutex_init(&p->cond_mutex, NULL); - p->cback = NULL; - } - - return 0; +static int uipc_main_init(void) { + int i; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&uipc_main.mutex, &attr); + + BTIF_TRACE_EVENT("### uipc_main_init ###"); + + /* setup interrupt socket pair */ + if (socketpair(AF_UNIX, SOCK_STREAM, 0, uipc_main.signal_fds) < 0) { + return -1; + } + + FD_SET(uipc_main.signal_fds[0], &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.signal_fds[0]); + + for (i = 0; i < UIPC_CH_NUM; i++) { + tUIPC_CHAN* p = &uipc_main.ch[i]; + p->srvfd = UIPC_DISCONNECTED; + p->fd = UIPC_DISCONNECTED; + p->task_evt_flags = 0; + pthread_cond_init(&p->cond, NULL); + pthread_mutex_init(&p->cond_mutex, NULL); + p->cback = NULL; + } + + return 0; } -void uipc_main_cleanup(void) -{ - int i; +void uipc_main_cleanup(void) { + int i; - BTIF_TRACE_EVENT("uipc_main_cleanup"); + BTIF_TRACE_EVENT("uipc_main_cleanup"); - close(uipc_main.signal_fds[0]); - close(uipc_main.signal_fds[1]); + close(uipc_main.signal_fds[0]); + close(uipc_main.signal_fds[1]); - /* close any open channels */ - for (i=0; i= UIPC_CH_NUM) - return -1; + /* add here */ + } +} - //BTIF_TRACE_EVENT("CHECK SRVFD %d (ch %d)", uipc_main.ch[ch_id].srvfd, ch_id); +static int uipc_check_fd_locked(tUIPC_CH_ID ch_id) { + if (ch_id >= UIPC_CH_NUM) return -1; - if (SAFE_FD_ISSET(uipc_main.ch[ch_id].srvfd, &uipc_main.read_set)) - { - BTIF_TRACE_EVENT("INCOMING CONNECTION ON CH %d", ch_id); + // BTIF_TRACE_EVENT("CHECK SRVFD %d (ch %d)", uipc_main.ch[ch_id].srvfd, + // ch_id); - uipc_main.ch[ch_id].fd = accept_server_socket(uipc_main.ch[ch_id].srvfd); + if (SAFE_FD_ISSET(uipc_main.ch[ch_id].srvfd, &uipc_main.read_set)) { + BTIF_TRACE_EVENT("INCOMING CONNECTION ON CH %d", ch_id); - BTIF_TRACE_EVENT("NEW FD %d", uipc_main.ch[ch_id].fd); + uipc_main.ch[ch_id].fd = accept_server_socket(uipc_main.ch[ch_id].srvfd); - if ((uipc_main.ch[ch_id].fd > 0) && uipc_main.ch[ch_id].cback) - { - /* if we have a callback we should add this fd to the active set - and notify user with callback event */ - BTIF_TRACE_EVENT("ADD FD %d TO ACTIVE SET", uipc_main.ch[ch_id].fd); - FD_SET(uipc_main.ch[ch_id].fd, &uipc_main.active_set); - uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.ch[ch_id].fd); - } + BTIF_TRACE_EVENT("NEW FD %d", uipc_main.ch[ch_id].fd); - if (uipc_main.ch[ch_id].fd < 0) - { - BTIF_TRACE_ERROR("FAILED TO ACCEPT CH %d (%s)", ch_id, strerror(errno)); - return -1; - } + if ((uipc_main.ch[ch_id].fd > 0) && uipc_main.ch[ch_id].cback) { + /* if we have a callback we should add this fd to the active set + and notify user with callback event */ + BTIF_TRACE_EVENT("ADD FD %d TO ACTIVE SET", uipc_main.ch[ch_id].fd); + FD_SET(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, uipc_main.ch[ch_id].fd); + } - if (uipc_main.ch[ch_id].cback) - uipc_main.ch[ch_id].cback(ch_id, UIPC_OPEN_EVT); + if (uipc_main.ch[ch_id].fd < 0) { + BTIF_TRACE_ERROR("FAILED TO ACCEPT CH %d (%s)", ch_id, strerror(errno)); + return -1; } - //BTIF_TRACE_EVENT("CHECK FD %d (ch %d)", uipc_main.ch[ch_id].fd, ch_id); + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_OPEN_EVT); + } - if (SAFE_FD_ISSET(uipc_main.ch[ch_id].fd, &uipc_main.read_set)) - { - //BTIF_TRACE_EVENT("INCOMING DATA ON CH %d", ch_id); + // BTIF_TRACE_EVENT("CHECK FD %d (ch %d)", uipc_main.ch[ch_id].fd, ch_id); - if (uipc_main.ch[ch_id].cback) - uipc_main.ch[ch_id].cback(ch_id, UIPC_RX_DATA_READY_EVT); - } - return 0; + if (SAFE_FD_ISSET(uipc_main.ch[ch_id].fd, &uipc_main.read_set)) { + // BTIF_TRACE_EVENT("INCOMING DATA ON CH %d", ch_id); + + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_RX_DATA_READY_EVT); + } + return 0; } -static void uipc_check_interrupt_locked(void) -{ - if (SAFE_FD_ISSET(uipc_main.signal_fds[0], &uipc_main.read_set)) - { - char sig_recv = 0; - OSI_NO_INTR(recv(uipc_main.signal_fds[0], &sig_recv, sizeof(sig_recv), - MSG_WAITALL)); - } +static void uipc_check_interrupt_locked(void) { + if (SAFE_FD_ISSET(uipc_main.signal_fds[0], &uipc_main.read_set)) { + char sig_recv = 0; + OSI_NO_INTR(recv(uipc_main.signal_fds[0], &sig_recv, sizeof(sig_recv), + MSG_WAITALL)); + } } -static inline void uipc_wakeup_locked(void) -{ - char sig_on = 1; - BTIF_TRACE_EVENT("UIPC SEND WAKE UP"); +static inline void uipc_wakeup_locked(void) { + char sig_on = 1; + BTIF_TRACE_EVENT("UIPC SEND WAKE UP"); - OSI_NO_INTR(send(uipc_main.signal_fds[1], &sig_on, sizeof(sig_on), 0)); + OSI_NO_INTR(send(uipc_main.signal_fds[1], &sig_on, sizeof(sig_on), 0)); } -static int uipc_setup_server_locked(tUIPC_CH_ID ch_id, const char *name, - tUIPC_RCV_CBACK *cback) -{ - int fd; +static int uipc_setup_server_locked(tUIPC_CH_ID ch_id, const char* name, + tUIPC_RCV_CBACK* cback) { + int fd; - BTIF_TRACE_EVENT("SETUP CHANNEL SERVER %d", ch_id); + BTIF_TRACE_EVENT("SETUP CHANNEL SERVER %d", ch_id); - if (ch_id >= UIPC_CH_NUM) - return -1; + if (ch_id >= UIPC_CH_NUM) return -1; - UIPC_LOCK(); + UIPC_LOCK(); - fd = create_server_socket(name); + fd = create_server_socket(name); - if (fd < 0) - { - BTIF_TRACE_ERROR("failed to setup %s", name, strerror(errno)); - UIPC_UNLOCK(); - return -1; - } + if (fd < 0) { + BTIF_TRACE_ERROR("failed to setup %s", name, strerror(errno)); + UIPC_UNLOCK(); + return -1; + } - BTIF_TRACE_EVENT("ADD SERVER FD TO ACTIVE SET %d", fd); - FD_SET(fd, &uipc_main.active_set); - uipc_main.max_fd = MAX(uipc_main.max_fd, fd); + BTIF_TRACE_EVENT("ADD SERVER FD TO ACTIVE SET %d", fd); + FD_SET(fd, &uipc_main.active_set); + uipc_main.max_fd = MAX(uipc_main.max_fd, fd); - uipc_main.ch[ch_id].srvfd = fd; - uipc_main.ch[ch_id].cback = cback; - uipc_main.ch[ch_id].read_poll_tmo_ms = DEFAULT_READ_POLL_TMO_MS; + uipc_main.ch[ch_id].srvfd = fd; + uipc_main.ch[ch_id].cback = cback; + uipc_main.ch[ch_id].read_poll_tmo_ms = DEFAULT_READ_POLL_TMO_MS; - /* trigger main thread to update read set */ - uipc_wakeup_locked(); + /* trigger main thread to update read set */ + uipc_wakeup_locked(); - UIPC_UNLOCK(); + UIPC_UNLOCK(); - return 0; + return 0; } -static void uipc_flush_ch_locked(tUIPC_CH_ID ch_id) -{ - char buf[UIPC_FLUSH_BUFFER_SIZE]; - struct pollfd pfd; - - pfd.events = POLLIN; - pfd.fd = uipc_main.ch[ch_id].fd; - - if (uipc_main.ch[ch_id].fd == UIPC_DISCONNECTED) - { - BTIF_TRACE_EVENT("%s() - fd disconnected. Exiting", __func__); - return; +static void uipc_flush_ch_locked(tUIPC_CH_ID ch_id) { + char buf[UIPC_FLUSH_BUFFER_SIZE]; + struct pollfd pfd; + + pfd.events = POLLIN; + pfd.fd = uipc_main.ch[ch_id].fd; + + if (uipc_main.ch[ch_id].fd == UIPC_DISCONNECTED) { + BTIF_TRACE_EVENT("%s() - fd disconnected. Exiting", __func__); + return; + } + + while (1) { + int ret; + OSI_NO_INTR(ret = poll(&pfd, 1, 1)); + if (ret == 0) { + BTIF_TRACE_VERBOSE("%s(): poll() timeout - nothing to do. Exiting", + __func__); + return; } - - while (1) - { - int ret; - OSI_NO_INTR(ret = poll(&pfd, 1, 1)); - if (ret == 0) { - BTIF_TRACE_VERBOSE("%s(): poll() timeout - nothing to do. Exiting", - __func__); - return; - } - if (ret < 0) { - BTIF_TRACE_WARNING("%s() - poll() failed: return %d errno %d (%s). Exiting", - __func__, ret, errno, strerror(errno)); - return; - } - BTIF_TRACE_VERBOSE("%s() - polling fd %d, revents: 0x%x, ret %d", - __func__, pfd.fd, pfd.revents, ret); - if (pfd.revents & (POLLERR|POLLHUP)) - { - BTIF_TRACE_WARNING("%s() - POLLERR or POLLHUP. Exiting", __func__); - return; - } - - /* read sufficiently large buffer to ensure flush empties socket faster than - it is getting refilled */ - read(pfd.fd, &buf, UIPC_FLUSH_BUFFER_SIZE); + if (ret < 0) { + BTIF_TRACE_WARNING( + "%s() - poll() failed: return %d errno %d (%s). Exiting", __func__, + ret, errno, strerror(errno)); + return; + } + BTIF_TRACE_VERBOSE("%s() - polling fd %d, revents: 0x%x, ret %d", __func__, + pfd.fd, pfd.revents, ret); + if (pfd.revents & (POLLERR | POLLHUP)) { + BTIF_TRACE_WARNING("%s() - POLLERR or POLLHUP. Exiting", __func__); + return; } -} + /* read sufficiently large buffer to ensure flush empties socket faster than + it is getting refilled */ + read(pfd.fd, &buf, UIPC_FLUSH_BUFFER_SIZE); + } +} -static void uipc_flush_locked(tUIPC_CH_ID ch_id) -{ - if (ch_id >= UIPC_CH_NUM) - return; +static void uipc_flush_locked(tUIPC_CH_ID ch_id) { + if (ch_id >= UIPC_CH_NUM) return; - switch(ch_id) - { - case UIPC_CH_ID_AV_CTRL: - uipc_flush_ch_locked(UIPC_CH_ID_AV_CTRL); - break; + switch (ch_id) { + case UIPC_CH_ID_AV_CTRL: + uipc_flush_ch_locked(UIPC_CH_ID_AV_CTRL); + break; - case UIPC_CH_ID_AV_AUDIO: - uipc_flush_ch_locked(UIPC_CH_ID_AV_AUDIO); - break; - } + case UIPC_CH_ID_AV_AUDIO: + uipc_flush_ch_locked(UIPC_CH_ID_AV_AUDIO); + break; + } } +static int uipc_close_ch_locked(tUIPC_CH_ID ch_id) { + int wakeup = 0; -static int uipc_close_ch_locked(tUIPC_CH_ID ch_id) -{ - int wakeup = 0; + BTIF_TRACE_EVENT("CLOSE CHANNEL %d", ch_id); - BTIF_TRACE_EVENT("CLOSE CHANNEL %d", ch_id); + if (ch_id >= UIPC_CH_NUM) return -1; - if (ch_id >= UIPC_CH_NUM) - return -1; + if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) { + BTIF_TRACE_EVENT("CLOSE SERVER (FD %d)", uipc_main.ch[ch_id].srvfd); + close(uipc_main.ch[ch_id].srvfd); + FD_CLR(uipc_main.ch[ch_id].srvfd, &uipc_main.active_set); + uipc_main.ch[ch_id].srvfd = UIPC_DISCONNECTED; + wakeup = 1; + } - if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) - { - BTIF_TRACE_EVENT("CLOSE SERVER (FD %d)", uipc_main.ch[ch_id].srvfd); - close(uipc_main.ch[ch_id].srvfd); - FD_CLR(uipc_main.ch[ch_id].srvfd, &uipc_main.active_set); - uipc_main.ch[ch_id].srvfd = UIPC_DISCONNECTED; - wakeup = 1; - } + if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) { + BTIF_TRACE_EVENT("CLOSE CONNECTION (FD %d)", uipc_main.ch[ch_id].fd); + close(uipc_main.ch[ch_id].fd); + FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + uipc_main.ch[ch_id].fd = UIPC_DISCONNECTED; + wakeup = 1; + } - if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) - { - BTIF_TRACE_EVENT("CLOSE CONNECTION (FD %d)", uipc_main.ch[ch_id].fd); - close(uipc_main.ch[ch_id].fd); - FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); - uipc_main.ch[ch_id].fd = UIPC_DISCONNECTED; - wakeup = 1; - } - - /* notify this connection is closed */ - if (uipc_main.ch[ch_id].cback) - uipc_main.ch[ch_id].cback(ch_id, UIPC_CLOSE_EVT); + /* notify this connection is closed */ + if (uipc_main.ch[ch_id].cback) + uipc_main.ch[ch_id].cback(ch_id, UIPC_CLOSE_EVT); - /* trigger main thread update if something was updated */ - if (wakeup) - uipc_wakeup_locked(); + /* trigger main thread update if something was updated */ + if (wakeup) uipc_wakeup_locked(); - return 0; + return 0; } +void uipc_close_locked(tUIPC_CH_ID ch_id) { + if (uipc_main.ch[ch_id].srvfd == UIPC_DISCONNECTED) { + BTIF_TRACE_EVENT("CHANNEL %d ALREADY CLOSED", ch_id); + return; + } -void uipc_close_locked(tUIPC_CH_ID ch_id) -{ - if (uipc_main.ch[ch_id].srvfd == UIPC_DISCONNECTED) - { - BTIF_TRACE_EVENT("CHANNEL %d ALREADY CLOSED", ch_id); - return; - } - - /* schedule close on this channel */ - uipc_main.ch[ch_id].task_evt_flags |= UIPC_TASK_FLAG_DISCONNECT_CHAN; - uipc_wakeup_locked(); + /* schedule close on this channel */ + uipc_main.ch[ch_id].task_evt_flags |= UIPC_TASK_FLAG_DISCONNECT_CHAN; + uipc_wakeup_locked(); } +static void* uipc_read_task(UNUSED_ATTR void* arg) { + int ch_id; + int result; -static void *uipc_read_task(UNUSED_ATTR void *arg) -{ - int ch_id; - int result; + prctl(PR_SET_NAME, (unsigned long)"uipc-main", 0, 0, 0); - prctl(PR_SET_NAME, (unsigned long)"uipc-main", 0, 0, 0); + raise_priority_a2dp(TASK_UIPC_READ); - raise_priority_a2dp(TASK_UIPC_READ); + while (uipc_main.running) { + uipc_main.read_set = uipc_main.active_set; - while (uipc_main.running) - { - uipc_main.read_set = uipc_main.active_set; + result = + select(uipc_main.max_fd + 1, &uipc_main.read_set, NULL, NULL, NULL); - result = select(uipc_main.max_fd+1, &uipc_main.read_set, NULL, NULL, NULL); - - if (result == 0) { - BTIF_TRACE_EVENT("select timeout"); - continue; - } - if (result < 0) { - if (errno != EINTR) - BTIF_TRACE_EVENT("select failed %s", strerror(errno)); - continue; - } - - UIPC_LOCK(); + if (result == 0) { + BTIF_TRACE_EVENT("select timeout"); + continue; + } + if (result < 0) { + if (errno != EINTR) BTIF_TRACE_EVENT("select failed %s", strerror(errno)); + continue; + } - /* clear any wakeup interrupt */ - uipc_check_interrupt_locked(); + UIPC_LOCK(); - /* check pending task events */ - uipc_check_task_flags_locked(); + /* clear any wakeup interrupt */ + uipc_check_interrupt_locked(); - /* make sure we service audio channel first */ - uipc_check_fd_locked(UIPC_CH_ID_AV_AUDIO); + /* check pending task events */ + uipc_check_task_flags_locked(); - /* check for other connections */ - for (ch_id = 0; ch_id < UIPC_CH_NUM; ch_id++) - { - if (ch_id != UIPC_CH_ID_AV_AUDIO) - uipc_check_fd_locked(ch_id); - } + /* make sure we service audio channel first */ + uipc_check_fd_locked(UIPC_CH_ID_AV_AUDIO); - UIPC_UNLOCK(); + /* check for other connections */ + for (ch_id = 0; ch_id < UIPC_CH_NUM; ch_id++) { + if (ch_id != UIPC_CH_ID_AV_AUDIO) uipc_check_fd_locked(ch_id); } - BTIF_TRACE_EVENT("UIPC READ THREAD EXITING"); + UIPC_UNLOCK(); + } + + BTIF_TRACE_EVENT("UIPC READ THREAD EXITING"); - uipc_main_cleanup(); + uipc_main_cleanup(); - uipc_main.tid = 0; + uipc_main.tid = 0; - BTIF_TRACE_EVENT("UIPC READ THREAD DONE"); + BTIF_TRACE_EVENT("UIPC READ THREAD DONE"); - return nullptr; + return nullptr; } +int uipc_start_main_server_thread(void) { + uipc_main.running = 1; -int uipc_start_main_server_thread(void) -{ - uipc_main.running = 1; + if (pthread_create(&uipc_main.tid, (const pthread_attr_t*)NULL, + uipc_read_task, nullptr) < 0) { + BTIF_TRACE_ERROR("uipc_thread_create pthread_create failed:%d", errno); + return -1; + } - if (pthread_create(&uipc_main.tid, (const pthread_attr_t *) NULL, - uipc_read_task, nullptr) < 0) - { - BTIF_TRACE_ERROR("uipc_thread_create pthread_create failed:%d", errno); - return -1; - } - - return 0; + return 0; } /* blocking call */ -void uipc_stop_main_server_thread(void) -{ - /* request shutdown of read thread */ - UIPC_LOCK(); - uipc_main.running = 0; - uipc_wakeup_locked(); - UIPC_UNLOCK(); - - /* wait until read thread is fully terminated */ - /* tid might hold pointer value where it's value - is negative vaule with singed bit is set, so - corrected the logic to check zero or non zero */ - if (uipc_main.tid) - pthread_join(uipc_main.tid, NULL); +void uipc_stop_main_server_thread(void) { + /* request shutdown of read thread */ + UIPC_LOCK(); + uipc_main.running = 0; + uipc_wakeup_locked(); + UIPC_UNLOCK(); + + /* wait until read thread is fully terminated */ + /* tid might hold pointer value where it's value + is negative vaule with singed bit is set, so + corrected the logic to check zero or non zero */ + if (uipc_main.tid) pthread_join(uipc_main.tid, NULL); } /******************************************************************************* @@ -603,15 +548,14 @@ void uipc_stop_main_server_thread(void) ** ******************************************************************************/ -void UIPC_Init(UNUSED_ATTR void *p_data) -{ - BTIF_TRACE_DEBUG("UIPC_Init"); +void UIPC_Init(UNUSED_ATTR void* p_data) { + BTIF_TRACE_DEBUG("UIPC_Init"); - memset(&uipc_main, 0, sizeof(tUIPC_MAIN)); + memset(&uipc_main, 0, sizeof(tUIPC_MAIN)); - uipc_main_init(); + uipc_main_init(); - uipc_start_main_server_thread(); + uipc_start_main_server_thread(); } /******************************************************************************* @@ -623,39 +567,35 @@ void UIPC_Init(UNUSED_ATTR void *p_data) ** Returns true in case of success, false in case of failure. ** ******************************************************************************/ -bool UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback) -{ - BTIF_TRACE_DEBUG("UIPC_Open : ch_id %d, p_cback %x", ch_id, p_cback); +bool UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback) { + BTIF_TRACE_DEBUG("UIPC_Open : ch_id %d, p_cback %x", ch_id, p_cback); - UIPC_LOCK(); + UIPC_LOCK(); - if (ch_id >= UIPC_CH_NUM) - { - UIPC_UNLOCK(); - return false; - } + if (ch_id >= UIPC_CH_NUM) { + UIPC_UNLOCK(); + return false; + } - if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) - { - BTIF_TRACE_EVENT("CHANNEL %d ALREADY OPEN", ch_id); - UIPC_UNLOCK(); - return 0; - } + if (uipc_main.ch[ch_id].srvfd != UIPC_DISCONNECTED) { + BTIF_TRACE_EVENT("CHANNEL %d ALREADY OPEN", ch_id); + UIPC_UNLOCK(); + return 0; + } - switch(ch_id) - { - case UIPC_CH_ID_AV_CTRL: - uipc_setup_server_locked(ch_id, A2DP_CTRL_PATH, p_cback); - break; + switch (ch_id) { + case UIPC_CH_ID_AV_CTRL: + uipc_setup_server_locked(ch_id, A2DP_CTRL_PATH, p_cback); + break; - case UIPC_CH_ID_AV_AUDIO: - uipc_setup_server_locked(ch_id, A2DP_DATA_PATH, p_cback); - break; - } + case UIPC_CH_ID_AV_AUDIO: + uipc_setup_server_locked(ch_id, A2DP_DATA_PATH, p_cback); + break; + } - UIPC_UNLOCK(); + UIPC_UNLOCK(); - return true; + return true; } /******************************************************************************* @@ -668,23 +608,19 @@ bool UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback) ** ******************************************************************************/ -void UIPC_Close(tUIPC_CH_ID ch_id) -{ - BTIF_TRACE_DEBUG("UIPC_Close : ch_id %d", ch_id); +void UIPC_Close(tUIPC_CH_ID ch_id) { + BTIF_TRACE_DEBUG("UIPC_Close : ch_id %d", ch_id); - /* special case handling uipc shutdown */ - if (ch_id != UIPC_CH_ID_ALL) - { - UIPC_LOCK(); - uipc_close_locked(ch_id); - UIPC_UNLOCK(); - } - else - { - BTIF_TRACE_DEBUG("UIPC_Close : waiting for shutdown to complete"); - uipc_stop_main_server_thread(); - BTIF_TRACE_DEBUG("UIPC_Close : shutdown complete"); - } + /* special case handling uipc shutdown */ + if (ch_id != UIPC_CH_ID_ALL) { + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); + } else { + BTIF_TRACE_DEBUG("UIPC_Close : waiting for shutdown to complete"); + uipc_stop_main_server_thread(); + BTIF_TRACE_DEBUG("UIPC_Close : shutdown complete"); + } } /******************************************************************************* @@ -696,23 +632,21 @@ void UIPC_Close(tUIPC_CH_ID ch_id) ** Returns true in case of success, false in case of failure. ** ******************************************************************************/ -bool UIPC_Send(tUIPC_CH_ID ch_id, - UNUSED_ATTR uint16_t msg_evt, uint8_t *p_buf, - uint16_t msglen) -{ - BTIF_TRACE_DEBUG("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen); +bool UIPC_Send(tUIPC_CH_ID ch_id, UNUSED_ATTR uint16_t msg_evt, uint8_t* p_buf, + uint16_t msglen) { + BTIF_TRACE_DEBUG("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen); - UIPC_LOCK(); + UIPC_LOCK(); - ssize_t ret; - OSI_NO_INTR(ret = write(uipc_main.ch[ch_id].fd, p_buf, msglen)); - if (ret < 0) { - BTIF_TRACE_ERROR("failed to write (%s)", strerror(errno)); - } + ssize_t ret; + OSI_NO_INTR(ret = write(uipc_main.ch[ch_id].fd, p_buf, msglen)); + if (ret < 0) { + BTIF_TRACE_ERROR("failed to write (%s)", strerror(errno)); + } - UIPC_UNLOCK(); + UIPC_UNLOCK(); - return false; + return false; } /******************************************************************************* @@ -725,87 +659,77 @@ bool UIPC_Send(tUIPC_CH_ID ch_id, ** ******************************************************************************/ -uint32_t UIPC_Read(tUIPC_CH_ID ch_id, - UNUSED_ATTR uint16_t *p_msg_evt, uint8_t *p_buf, - uint32_t len) -{ - int n_read = 0; - int fd = uipc_main.ch[ch_id].fd; - struct pollfd pfd; - - if (ch_id >= UIPC_CH_NUM) - { - BTIF_TRACE_ERROR("UIPC_Read : invalid ch id %d", ch_id); - return 0; +uint32_t UIPC_Read(tUIPC_CH_ID ch_id, UNUSED_ATTR uint16_t* p_msg_evt, + uint8_t* p_buf, uint32_t len) { + int n_read = 0; + int fd = uipc_main.ch[ch_id].fd; + struct pollfd pfd; + + if (ch_id >= UIPC_CH_NUM) { + BTIF_TRACE_ERROR("UIPC_Read : invalid ch id %d", ch_id); + return 0; + } + + if (fd == UIPC_DISCONNECTED) { + BTIF_TRACE_ERROR("UIPC_Read : channel %d closed", ch_id); + return 0; + } + + // BTIF_TRACE_DEBUG("UIPC_Read : ch_id %d, len %d, fd %d, polltmo %d", + // ch_id, len, fd, uipc_main.ch[ch_id].read_poll_tmo_ms); + + while (n_read < (int)len) { + pfd.fd = fd; + pfd.events = POLLIN | POLLHUP; + + /* make sure there is data prior to attempting read to avoid blocking + a read for more than poll timeout */ + + int poll_ret; + OSI_NO_INTR(poll_ret = poll(&pfd, 1, uipc_main.ch[ch_id].read_poll_tmo_ms)); + if (poll_ret == 0) { + BTIF_TRACE_WARNING("poll timeout (%d ms)", + uipc_main.ch[ch_id].read_poll_tmo_ms); + break; } + if (poll_ret < 0) { + BTIF_TRACE_ERROR("%s(): poll() failed: return %d errno %d (%s)", __func__, + poll_ret, errno, strerror(errno)); + break; + } + + // BTIF_TRACE_EVENT("poll revents %x", pfd.revents); - if (fd == UIPC_DISCONNECTED) - { - BTIF_TRACE_ERROR("UIPC_Read : channel %d closed", ch_id); - return 0; + if (pfd.revents & (POLLHUP | POLLNVAL)) { + BTIF_TRACE_WARNING("poll : channel detached remotely"); + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); + return 0; } - //BTIF_TRACE_DEBUG("UIPC_Read : ch_id %d, len %d, fd %d, polltmo %d", - // ch_id, len, fd, uipc_main.ch[ch_id].read_poll_tmo_ms); - - while (n_read < (int)len) - { - pfd.fd = fd; - pfd.events = POLLIN|POLLHUP; - - /* make sure there is data prior to attempting read to avoid blocking - a read for more than poll timeout */ - - int poll_ret; - OSI_NO_INTR(poll_ret = poll(&pfd, 1, - uipc_main.ch[ch_id].read_poll_tmo_ms)); - if (poll_ret == 0) - { - BTIF_TRACE_WARNING("poll timeout (%d ms)", uipc_main.ch[ch_id].read_poll_tmo_ms); - break; - } - if (poll_ret < 0) { - BTIF_TRACE_ERROR("%s(): poll() failed: return %d errno %d (%s)", - __func__, poll_ret, errno, strerror(errno)); - break; - } - - //BTIF_TRACE_EVENT("poll revents %x", pfd.revents); - - if (pfd.revents & (POLLHUP|POLLNVAL) ) - { - BTIF_TRACE_WARNING("poll : channel detached remotely"); - UIPC_LOCK(); - uipc_close_locked(ch_id); - UIPC_UNLOCK(); - return 0; - } - - ssize_t n; - OSI_NO_INTR(n = recv(fd, p_buf+n_read, len-n_read, 0)); - - //BTIF_TRACE_EVENT("read %d bytes", n); - - if (n == 0) - { - BTIF_TRACE_WARNING("UIPC_Read : channel detached remotely"); - UIPC_LOCK(); - uipc_close_locked(ch_id); - UIPC_UNLOCK(); - return 0; - } - - if (n < 0) - { - BTIF_TRACE_WARNING("UIPC_Read : read failed (%s)", strerror(errno)); - return 0; - } - - n_read+=n; + ssize_t n; + OSI_NO_INTR(n = recv(fd, p_buf + n_read, len - n_read, 0)); + + // BTIF_TRACE_EVENT("read %d bytes", n); + + if (n == 0) { + BTIF_TRACE_WARNING("UIPC_Read : channel detached remotely"); + UIPC_LOCK(); + uipc_close_locked(ch_id); + UIPC_UNLOCK(); + return 0; + } + if (n < 0) { + BTIF_TRACE_WARNING("UIPC_Read : read failed (%s)", strerror(errno)); + return 0; } - return n_read; + n_read += n; + } + + return n_read; } /******************************************************************************* @@ -818,48 +742,47 @@ uint32_t UIPC_Read(tUIPC_CH_ID ch_id, * ******************************************************************************/ -extern bool UIPC_Ioctl(tUIPC_CH_ID ch_id, uint32_t request, void *param) -{ - BTIF_TRACE_DEBUG("#### UIPC_Ioctl : ch_id %d, request %d ####", ch_id, request); +extern bool UIPC_Ioctl(tUIPC_CH_ID ch_id, uint32_t request, void* param) { + BTIF_TRACE_DEBUG("#### UIPC_Ioctl : ch_id %d, request %d ####", ch_id, + request); - UIPC_LOCK(); + UIPC_LOCK(); - switch(request) - { - case UIPC_REQ_RX_FLUSH: - uipc_flush_locked(ch_id); - break; - - case UIPC_REG_CBACK: - //BTIF_TRACE_EVENT("register callback ch %d srvfd %d, fd %d", ch_id, uipc_main.ch[ch_id].srvfd, uipc_main.ch[ch_id].fd); - uipc_main.ch[ch_id].cback = (tUIPC_RCV_CBACK*)param; - break; - - case UIPC_REG_REMOVE_ACTIVE_READSET: - - /* user will read data directly and not use select loop */ - if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) - { - /* remove this channel from active set */ - FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); - - /* refresh active set */ - uipc_wakeup_locked(); - } - break; - - case UIPC_SET_READ_POLL_TMO: - uipc_main.ch[ch_id].read_poll_tmo_ms = (intptr_t)param; - BTIF_TRACE_EVENT("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id, uipc_main.ch[ch_id].read_poll_tmo_ms ); - break; - - default: - BTIF_TRACE_EVENT("UIPC_Ioctl : request not handled (%d)", request); - break; - } + switch (request) { + case UIPC_REQ_RX_FLUSH: + uipc_flush_locked(ch_id); + break; - UIPC_UNLOCK(); + case UIPC_REG_CBACK: + // BTIF_TRACE_EVENT("register callback ch %d srvfd %d, fd %d", ch_id, + // uipc_main.ch[ch_id].srvfd, uipc_main.ch[ch_id].fd); + uipc_main.ch[ch_id].cback = (tUIPC_RCV_CBACK*)param; + break; - return false; -} + case UIPC_REG_REMOVE_ACTIVE_READSET: + + /* user will read data directly and not use select loop */ + if (uipc_main.ch[ch_id].fd != UIPC_DISCONNECTED) { + /* remove this channel from active set */ + FD_CLR(uipc_main.ch[ch_id].fd, &uipc_main.active_set); + + /* refresh active set */ + uipc_wakeup_locked(); + } + break; + + case UIPC_SET_READ_POLL_TMO: + uipc_main.ch[ch_id].read_poll_tmo_ms = (intptr_t)param; + BTIF_TRACE_EVENT("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id, + uipc_main.ch[ch_id].read_poll_tmo_ms); + break; + default: + BTIF_TRACE_EVENT("UIPC_Ioctl : request not handled (%d)", request); + break; + } + + UIPC_UNLOCK(); + + return false; +} diff --git a/udrv/ulinux/uipc_linux.h b/udrv/ulinux/uipc_linux.h index 45cfc3141..98d085cca 100644 --- a/udrv/ulinux/uipc_linux.h +++ b/udrv/ulinux/uipc_linux.h @@ -23,14 +23,14 @@ extern "C" { #endif typedef int SOCKET; -#define INVALID_SOCKET (SOCKET)(-1) -#define SOCKET_ERROR (-1) +#define INVALID_SOCKET (SOCKET)(-1) +#define SOCKET_ERROR (-1) /* tcp/ip socket configuration */ typedef struct { - char *p_address; - unsigned int port; -} tUIPC_LINUX_CFG_TCP ; + char* p_address; + unsigned int port; +} tUIPC_LINUX_CFG_TCP; /* Socket configuration for GLGPS interface */ extern tUIPC_LINUX_CFG_TCP uipc_linux_cfg_glgps; diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h index 4264a4bd6..b648d65e4 100644 --- a/utils/include/bt_utils.h +++ b/utils/include/bt_utils.h @@ -30,9 +30,9 @@ static const char BT_UTILS_MODULE[] = "bt_utils_module"; ******************************************************************************/ typedef enum { - TASK_HIGH_MEDIA = 0, - TASK_UIPC_READ, - TASK_HIGH_MAX + TASK_HIGH_MEDIA = 0, + TASK_UIPC_READ, + TASK_HIGH_MAX } tHIGH_PRIORITY_TASK; /******************************************************************************* diff --git a/utils/src/bt_utils.cc b/utils/src/bt_utils.cc index 399b452cd..a8cb8243b 100644 --- a/utils/src/bt_utils.cc +++ b/utils/src/bt_utils.cc @@ -40,8 +40,8 @@ #define ANDROID_PRIORITY_AUDIO -16 #define ANDROID_PRIORITY_URGENT_AUDIO -19 #else -#include #include +#include #endif #include "bt_types.h" @@ -54,17 +54,17 @@ * Type definitions for callback functions ******************************************************************************/ static pthread_once_t g_DoSchedulingGroupOnce[TASK_HIGH_MAX]; -static bool g_DoSchedulingGroup[TASK_HIGH_MAX]; -static pthread_mutex_t gIdxLock; +static bool g_DoSchedulingGroup[TASK_HIGH_MAX]; +static pthread_mutex_t gIdxLock; static int g_TaskIdx; static int g_TaskIDs[TASK_HIGH_MAX]; -#define INVALID_TASK_ID (-1) +#define INVALID_TASK_ID (-1) -static future_t *init(void) { +static future_t* init(void) { int i; pthread_mutexattr_t lock_attr; - for(i = 0; i < TASK_HIGH_MAX; i++) { + for (i = 0; i < TASK_HIGH_MAX; i++) { g_DoSchedulingGroupOnce[i] = PTHREAD_ONCE_INIT; g_DoSchedulingGroup[i] = true; g_TaskIDs[i] = INVALID_TASK_ID; @@ -75,21 +75,17 @@ static future_t *init(void) { return NULL; } -static future_t *clean_up(void) { +static future_t* clean_up(void) { pthread_mutex_destroy(&gIdxLock); return NULL; } -EXPORT_SYMBOL extern const module_t bt_utils_module = { - .name = BT_UTILS_MODULE, - .init = init, - .start_up = NULL, - .shut_down = NULL, - .clean_up = clean_up, - .dependencies = { - NULL - } -}; +EXPORT_SYMBOL extern const module_t bt_utils_module = {.name = BT_UTILS_MODULE, + .init = init, + .start_up = NULL, + .shut_down = NULL, + .clean_up = clean_up, + .dependencies = {NULL}}; /***************************************************************************** * @@ -101,14 +97,14 @@ EXPORT_SYMBOL extern const module_t bt_utils_module = { * ******************************************************************************/ static void check_do_scheduling_group(void) { - char buf[PROPERTY_VALUE_MAX]; - int len = osi_property_get("debug.sys.noschedgroups", buf, ""); - if (len > 0) { - int temp; - if (sscanf(buf, "%d", &temp) == 1) { - g_DoSchedulingGroup[g_TaskIdx] = temp == 0; - } + char buf[PROPERTY_VALUE_MAX]; + int len = osi_property_get("debug.sys.noschedgroups", buf, ""); + if (len > 0) { + int temp; + if (sscanf(buf, "%d", &temp) == 1) { + g_DoSchedulingGroup[g_TaskIdx] = temp == 0; } + } } /***************************************************************************** @@ -121,41 +117,42 @@ static void check_do_scheduling_group(void) { * ******************************************************************************/ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) { - int rc = 0; - int tid = gettid(); - int priority = ANDROID_PRIORITY_AUDIO; + int rc = 0; + int tid = gettid(); + int priority = ANDROID_PRIORITY_AUDIO; - pthread_mutex_lock(&gIdxLock); - g_TaskIdx = high_task; + pthread_mutex_lock(&gIdxLock); + g_TaskIdx = high_task; - // TODO(armansito): Remove this conditional check once we find a solution - // for system/core on non-Android platforms. +// TODO(armansito): Remove this conditional check once we find a solution +// for system/core on non-Android platforms. #if defined(OS_GENERIC) - rc = -1; -#else // !defined(OS_GENERIC) - pthread_once(&g_DoSchedulingGroupOnce[g_TaskIdx], check_do_scheduling_group); - if (g_DoSchedulingGroup[g_TaskIdx]) { - // set_sched_policy does not support tid == 0 - rc = set_sched_policy(tid, SP_AUDIO_SYS); - } + rc = -1; +#else // !defined(OS_GENERIC) + pthread_once(&g_DoSchedulingGroupOnce[g_TaskIdx], check_do_scheduling_group); + if (g_DoSchedulingGroup[g_TaskIdx]) { + // set_sched_policy does not support tid == 0 + rc = set_sched_policy(tid, SP_AUDIO_SYS); + } #endif // defined(OS_GENERIC) - g_TaskIDs[high_task] = tid; - pthread_mutex_unlock(&gIdxLock); + g_TaskIDs[high_task] = tid; + pthread_mutex_unlock(&gIdxLock); - if (rc) { - LOG_WARN(LOG_TAG, "failed to change sched policy, tid %d, err: %d", tid, errno); - } + if (rc) { + LOG_WARN(LOG_TAG, "failed to change sched policy, tid %d, err: %d", tid, + errno); + } - // always use urgent priority for HCI worker thread until we can adjust - // its prio individually. All other threads can be dynamically adjusted voa - // adjust_priority_a2dp() + // always use urgent priority for HCI worker thread until we can adjust + // its prio individually. All other threads can be dynamically adjusted voa + // adjust_priority_a2dp() - priority = ANDROID_PRIORITY_URGENT_AUDIO; + priority = ANDROID_PRIORITY_URGENT_AUDIO; - if (setpriority(PRIO_PROCESS, tid, priority) < 0) { - LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority); - } + if (setpriority(PRIO_PROCESS, tid, priority) < 0) { + LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority); + } } /***************************************************************************** @@ -171,19 +168,17 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) { * ******************************************************************************/ void adjust_priority_a2dp(int start) { - int priority = start ? ANDROID_PRIORITY_URGENT_AUDIO : ANDROID_PRIORITY_AUDIO; - int tid; - int i; - - for (i = 0; i < TASK_HIGH_MAX; i++) - { - tid = g_TaskIDs[i]; - if (tid != INVALID_TASK_ID) - { - if (setpriority(PRIO_PROCESS, tid, priority) < 0) - { - LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority); - } - } + int priority = start ? ANDROID_PRIORITY_URGENT_AUDIO : ANDROID_PRIORITY_AUDIO; + int tid; + int i; + + for (i = 0; i < TASK_HIGH_MAX; i++) { + tid = g_TaskIDs[i]; + if (tid != INVALID_TASK_ID) { + if (setpriority(PRIO_PROCESS, tid, priority) < 0) { + LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, + priority); + } } + } } diff --git a/vendor_libs/test_vendor_lib/include/bt_address.h b/vendor_libs/test_vendor_lib/include/bt_address.h index e6eef5921..c37624fab 100644 --- a/vendor_libs/test_vendor_lib/include/bt_address.h +++ b/vendor_libs/test_vendor_lib/include/bt_address.h @@ -17,8 +17,8 @@ #pragma once #include -#include #include +#include namespace test_vendor_lib { diff --git a/vendor_libs/test_vendor_lib/test/hci_transport_unittest.cc b/vendor_libs/test_vendor_lib/test/hci_transport_unittest.cc index 63890346b..a98690e2b 100644 --- a/vendor_libs/test_vendor_lib/test/hci_transport_unittest.cc +++ b/vendor_libs/test_vendor_lib/test/hci_transport_unittest.cc @@ -19,8 +19,8 @@ #include "async_manager.h" -#include #include +#include #include #include #include diff --git a/vnd/ble/vendor_hcidefs.h b/vnd/ble/vendor_hcidefs.h index b1fae40e8..d0bbaf30f 100644 --- a/vnd/ble/vendor_hcidefs.h +++ b/vnd/ble/vendor_hcidefs.h @@ -33,22 +33,20 @@ *****************************************************************************/ /* VSC */ -#define HCI_VENDOR_BLE_RPA_VSC (0x0155 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_VENDOR_BLE_RPA_VSC (0x0155 | HCI_GRP_VENDOR_SPECIFIC) /* Sub codes */ -#define HCI_VENDOR_BLE_RPA_ENABLE 0x01 -#define HCI_VENDOR_BLE_RPA_ADD_IRK 0x02 -#define HCI_VENDOR_BLE_RPA_REMOVE_IRK 0x03 -#define HCI_VENDOR_BLE_RPA_CLEAR_IRK 0x04 -#define HCI_VENDOR_BLE_RPA_READ_IRK 0x05 - +#define HCI_VENDOR_BLE_RPA_ENABLE 0x01 +#define HCI_VENDOR_BLE_RPA_ADD_IRK 0x02 +#define HCI_VENDOR_BLE_RPA_REMOVE_IRK 0x03 +#define HCI_VENDOR_BLE_RPA_CLEAR_IRK 0x04 +#define HCI_VENDOR_BLE_RPA_READ_IRK 0x05 /***************************************************************************** * Advertising data payload filter VSC *****************************************************************************/ /* VSC */ -#define HCI_VENDOR_BLE_PCF_VSC (0x0157 | HCI_GRP_VENDOR_SPECIFIC) +#define HCI_VENDOR_BLE_PCF_VSC (0x0157 | HCI_GRP_VENDOR_SPECIFIC) #endif - diff --git a/vnd/include/vendor_api.h b/vnd/include/vendor_api.h index 5c1ab16ac..5740e891b 100644 --- a/vnd/include/vendor_api.h +++ b/vnd/include/vendor_api.h @@ -22,18 +22,12 @@ extern "C" { * Resolvable private address offload VSC specific definitions *****************************************************************************/ -enum -{ - BTM_BLE_PRIVACY_ENABLE, - BTM_BLE_PRIVACY_DISABLE -}; - +enum { BTM_BLE_PRIVACY_ENABLE, BTM_BLE_PRIVACY_DISABLE }; /**************************************************************************** * Advertising packet filter VSC specific definitions *****************************************************************************/ - /***************************************************************************** * VENDOR SPECIFIC BLE FEATURE FUNCTIONS *****************************************************************************/ -- 2.11.0