5 Replies Latest reply on May 19, 2017 10:14 AM by sajid_1694051

    hands free profile disconnects

    sajid_1694051

      using platform BCM94343WWCD1 with WICED Studio 4.1

      trying to implement a hands free profile (basically a headset).

      combined 2 demo apps :

      - bt_dualmode_server (only non-ble app I could find for BCM94343WWCD1)

      - dual_hf_a2dp (couldn't get this to compile for BCM94343WWCD1)

       

      replaced the rfcomm in bt_dualmode_server with the hf code from dual_hf_a2dp.

       

      I see the WICED board appear as a heaset in my android settings.

      It also seems to connect and pair, but about 10 seconds later it disconnects, with an error code saying host disconnected.

       

      any help would be greatly appreciated.

       

       

       

       

        • 1. Re: hands free profile disconnects
          grsr

          Can you please share the application code where you combined the 2 demo apps? Also please share the BLE sniffer air logs containing the disconnection issue.

          • 2. Re: hands free profile disconnects
            sajid_1694051

            This is the console log :

             

            bt_audio_enable_bluetooth: result: 0x0, cb = 0x80105f9

             

            .bt_audio_management_callback: Bluetooth enabled (success)

            WICED DCT BT ADDR 0x11:0x22:0x33:0xaa:0xbb:0xcc

             

            bt_audio_management_callback:wiced_bt_dev_write_local_addr result = 0x4

            bt_audio_management_callback: wiced_bt_dev_write_eir result = 0x0

            bt_audio_management_callback:Local Bluetooth Address: [11:22:33:AA:BB:CC]

            bt_audio_management_callback: wiced_bt_sdp_db_init result (bool) = 0x1

            bt_audio_management_callback: discoverability result = 0x0

            bt_audio_management_callback:connectability result = 0x0

            bt_audio_management_callback registering acl_change callback result: 0x0, cb = 0x8010555

            [BT-DM] Connection status callback is_connected:1 reason:0

            bt_audio_management_callback: Unhandled Bluetooth Management Event: 0x9

            bt_audio_management_callback: IO capabilities BR/EDR request

            bt_audio_management_callback: User confirmation request

            bt_audio_management_callback: Pairing complete 8192.

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Unhandled Bluetooth Management Event: 0xc

            bt_audio_management_callback: Unhandled Bluetooth Management Event: 0xa

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Link key update evt

            bt_audio_management_callback: Link key update evt

            [BT-DM] Connection status callback is_connected:0 reason:16 <-- this after the initial pairing

             

            <--- this sequence is when I select the Bluettoth device again on the android phone

             

            [BT-DM] Connection status callback is_connected:1 reason:0

            bt_audio_management_callback: Unhandled Bluetooth Management Event: 0xc

            [BT-DM] Connection status callback is_connected:0 reason:16

             

             

            This is the relevant part of the code

             

            #define WICED_BLUETOOTH_DEVICE_NAME    "HFP"

            #define WICED_BLUETOOTH_DEVICE_ADDRESS "\x11\x22\x33\xAA\xBB\xCC"

            #define WICED_BLUETOOTH_DEVICE_CLASS  "\x20\x04\x18"

             

            void bt_audio_enable_bluetooth( void )

            {

                wiced_result_t result;

                bt_audio_nv_init();

             

                result = wiced_bt_stack_init( bt_audio_management_callback, &wiced_bt_audio_cfg_settings, wiced_bt_audio_cfg_buf_pools );

                WPRINT_APP_INFO( ("bt_audio_enable_bluetooth: result: 0x%x, cb = 0x%x\n", result, (unsigned int) bt_audio_management_callback) );

             

                wiced_rtos_init_timer( &dm_ctxt_data.timer, DM_LINK_LOSS_RETRY_INTERVAL, (timer_handler_t)bt_audio_dm_linkloss_timer_handler, NULL );

            }

             

            void application_start( )

            {

                adi_init();

                bt_audio_enable_bluetooth();

            }

             

             

            ---> bluetooth_dm.c

            /*

            * Copyright 2017, Cypress Semiconductor Corporation or a subsidiary of

            * Cypress Semiconductor Corporation. All Rights Reserved.

            *

            * This software, associated documentation and materials ("Software"),

            * is owned by Cypress Semiconductor Corporation

            * or one of its subsidiaries ("Cypress") and is protected by and subject to

            * worldwide patent protection (United States and foreign),

            * United States copyright laws and international treaty provisions.

            * Therefore, you may use this Software only as provided in the license

            * agreement accompanying the software package from which you

            * obtained this Software ("EULA").

            * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,

            * non-transferable license to copy, modify, and compile the Software

            * source code solely for use in connection with Cypress's

            * integrated circuit products. Any reproduction, modification, translation,

            * compilation, or representation of this Software except as specified

            * above is prohibited without the express written permission of Cypress.

            *

            * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,

            * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED

            * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress

            * reserves the right to make changes to the Software without notice. Cypress

            * does not assume any liability arising out of the application or use of the

            * Software or any product or circuit described in the Software. Cypress does

            * not authorize its products for use in any products where a malfunction or

            * failure of the Cypress product may reasonably be expected to result in

            * significant property damage, injury or death ("High Risk Product"). By

            * including Cypress's product in a High Risk Product, the manufacturer

            * of such system or application assumes all risk of such use and in doing

            * so agrees to indemnify Cypress against all liability.

            */

             

             

            /*

            *@bluetooth_dm.c : Bluetooth Device Manager/ service discover/ Device discovery

            *

            */

             

             

            #include "wiced.h"

            #include "bluetooth_dm.h"

            #include "app_dct.h"

            #include "rtos.h"

            #include "wiced_bt_stack.h"

            #include "wiced_bt_dev.h"

            #include "wiced_bt_avrc.h"

            #include "bluetooth_nv.h"

            #include "wiced_bt_sdp.h"

            #include "hashtable.h"

            #include "bluetooth_hfp.h"

             

             

            /******************************************************

            *                      Macros

            ******************************************************/

                // SDP Record for Device ID

            #define HDLR_DEVICE_ID                        0x10000

                // SDP Record for A2DP Sink

            #define HDLR_A2DP_SINK                        0x10001

                // SDP Record for AVRC Controller

            #define HDLR_AVRC_CONTROLLER                  0x10002

                // SDP Record for AVRC Target

            #define HDLR_AVRC_TARGET                      0x10003

                // SDP Record for Hands-Free Unit

            #define HDLR_HANDS_FREE_UNIT                  0x10004

             

             

            #define BLUETOOTH_DEVICE_NAME           "HFP"

             

             

            #define EIR_DATA_LENGTH                 240

            #define EIR_COMPLETE_LOCAL_NAME_TYPE    0x09

            #define EIR_COMPLETE_16BITS_UUID_TYPE   0x03

             

             

            /******************************************************

            *                    Constants

            ******************************************************/

             

             

            /******************************************************

            *                   Enumerations

            ******************************************************/

             

             

            /******************************************************

            *                 Type Definitions

            ******************************************************/

             

             

            /******************************************************

            *                    Structures

            ******************************************************/

             

             

             

             

            /******************************************************

            *               Function Declarations

            ******************************************************/

             

             

            static void bt_audio_reconnect_on_link_loss(void);

             

             

            /******************************************************

            *               Variable Definitions

            ******************************************************/

            uint8_t bluetooth_device_name[249] = BLUETOOTH_DEVICE_NAME;

             

             

            uint8_t uuid_list[] =

            {

                0x08, 0x11, /* Headset */

                0x1E, 0x11, /* Handsfree */

            };

             

             

             

             

            const uint8_t sdp_database[] = // Define SDP database

            {

                SDP_ATTR_SEQUENCE_2(391),

             

             

                // SDP Record for Device ID

                SDP_ATTR_SEQUENCE_1(77),

                    SDP_ATTR_RECORD_HANDLE(HDLR_DEVICE_ID),

                    SDP_ATTR_CLASS_ID(UUID_SERVCLASS_PNP_INFORMATION),

                    SDP_ATTR_PROTOCOL_DESC_LIST(1),

                    SDP_ATTR_BROWSE_LIST,

                    SDP_ATTR_UINT2(ATTR_ID_SPECIFICATION_ID, 0x103),

                    SDP_ATTR_UINT2(ATTR_ID_VENDOR_ID, 0x000F),

                    SDP_ATTR_UINT2(ATTR_ID_PRODUCT_ID, 0x0000),

                    SDP_ATTR_UINT2(ATTR_ID_PRODUCT_VERSION, 0x0001),

                    SDP_ATTR_BOOLEAN(ATTR_ID_PRIMARY_RECORD, 0x01),

                    SDP_ATTR_UINT2(ATTR_ID_VENDOR_ID_SOURCE, DI_VENDOR_ID_SOURCE_BTSIG),

             

             

                // SDP Record for Hands-Free Unit

                SDP_ATTR_SEQUENCE_1(75),

                    SDP_ATTR_RECORD_HANDLE(HDLR_HANDS_FREE_UNIT),

                    SDP_ATTR_ID(ATTR_ID_SERVICE_CLASS_ID_LIST), SDP_ATTR_SEQUENCE_1(6),

                        SDP_ATTR_UUID16(UUID_SERVCLASS_HF_HANDSFREE),

                        SDP_ATTR_UUID16(UUID_SERVCLASS_GENERIC_AUDIO),

                    SDP_ATTR_RFCOMM_PROTOCOL_DESC_LIST(HANDS_FREE_SCN),

                    SDP_ATTR_ID(ATTR_ID_BT_PROFILE_DESC_LIST), SDP_ATTR_SEQUENCE_1(8),

                        SDP_ATTR_SEQUENCE_1(6),

                            SDP_ATTR_UUID16(UUID_SERVCLASS_HF_HANDSFREE),

                            SDP_ATTR_VALUE_UINT2(0x0106),

                    SDP_ATTR_SERVICE_NAME(15),

                        'W', 'I', 'C', 'E', 'D', ' ', 'H', 'F', ' ', 'D', 'E', 'V', 'I', 'C', 'E',

                    SDP_ATTR_UINT2(ATTR_ID_SUPPORTED_FEATURES, 0x0016),

            };

             

             

            /* Name, address and class of device shall be over-written using DCT entries if present.

            * Please use the DCT entries to configure these parameters */

            wiced_bt_cfg_settings_t wiced_bt_audio_cfg_settings =

            {

                .device_name               = (uint8_t*)BLUETOOTH_DEVICE_NAME,

                .device_class              = {0x24, 0x04, 0x18},

                .security_requirement_mask = BTM_SEC_NONE,

                .max_simultaneous_links    = 3,/*TBD*/

             

             

                /*BR/EDR scan settings */

                .br_edr_scan_cfg =

                {

                    .inquiry_scan_type     = BTM_SCAN_TYPE_INTERLACED,

                    .inquiry_scan_interval = WICED_BT_CFG_DEFAULT_INQUIRY_SCAN_INTERVAL,

                    .inquiry_scan_window   = WICED_BT_CFG_DEFAULT_INQUIRY_SCAN_WINDOW,

             

             

                    .page_scan_type        = BTM_SCAN_TYPE_INTERLACED,

                    .page_scan_interval    = WICED_BT_CFG_DEFAULT_PAGE_SCAN_INTERVAL,

                    .page_scan_window      = WICED_BT_CFG_DEFAULT_PAGE_SCAN_WINDOW,

                },

             

             

                /*BLE scan settings */

                .ble_scan_cfg =

                    {

                        .scan_mode = BTM_BLE_SCAN_MODE_NONE,

                    },

             

             

                .rfcomm_cfg =

                    {

                        .max_links = 4,

                        .max_ports = 20,

                    },

             

             

                .l2cap_application =

                 {

                     .max_links       = 6,

                     .max_psm         = 5, /*TBD*/

                     .max_channels    = 12,

                 },

             

             

                 .avdt_cfg =

                 {

                     .max_links = 4,

                 },

             

             

                 /* Audio/Video Remote Control configuration */

                 .avrc_cfg =

                 {

                     .roles     = AVRC_CONN_ACCEPTOR, /**< Mask of local roles supported (AVRC_CONN_INITIATOR|AVRC_CONN_ACCEPTOR) */

                     .max_links = 4  /**< Maximum simultaneous remote control links */

                 },

             

             

                 .max_number_of_buffer_pools = WICED_BT_CFG_NUM_BUF_POOLS,

             

             

                .addr_resolution_db_size = 3,

            };

             

             

            const wiced_bt_cfg_buf_pool_t wiced_bt_audio_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS] =

            {

            /*  { buf_size, buf_count } */

                { 268,       60   },      /* Small Buffer Pool */

                { 360,      20   },      /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */

                { 660,      40  },      /* Large Buffer Pool  (used for HCI ACL messages) */

                { 1024,     5   },      /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */

            };

             

             

            static bluetooth_dm_context_t dm_ctxt_data =

            {

                .connect_state  = WICED_FALSE,

                .num_retries    = 0,

            };

             

             

            wiced_bt_device_address_t local_address = {0x81,0x34,0x09,0xAD,0xCD,0xAC};

             

             

            /******************************************************

            *               Function Definitions

            ******************************************************/

             

             

            wiced_result_t bt_audio_write_eir( uint8_t *device_name )

            {

                uint8_t eir_cfg[EIR_DATA_LENGTH] = {0};

                uint8_t* p = eir_cfg;

                uint8_t name_len = strlen((char*)device_name);

             

             

                *p++ = (uint8_t)(name_len+1);                 /* Length */

                *p++ = (uint8_t)EIR_COMPLETE_LOCAL_NAME_TYPE; /* EIR Data Type */

                memcpy(p, device_name, name_len);   /* Name string */

                p += name_len;

             

             

                *p++ = sizeof(uuid_list)+1;

                *p++ = (uint8_t) EIR_COMPLETE_16BITS_UUID_TYPE;

                memcpy(p, uuid_list, sizeof(uuid_list));

             

             

                return wiced_bt_dev_write_eir(eir_cfg, EIR_DATA_LENGTH);

            }

             

             

            void bt_audio_init_services( void )

            {

                wiced_app_service_t *service = NULL;

             

             

                service = wiced_get_entry(SERVICE_BT_HFP);

                if(service != NULL)

                {

                    service->init_service();

                }

            }

             

             

             

             

            bluetooth_dm_context_t* wiced_bt_dm_get_context( void )

            {

               return &dm_ctxt_data;

            }

             

             

            void bt_audio_disconnect_services(void)

            {

                app_queue_element_t message;

             

             

                WPRINT_APP_INFO( ("SAJID DISCONNECT !!!\r\n") );

             

             

                wiced_rtos_lock_mutex( &app_data.lock );

             

             

                /* Order for disconnecting AVRCP, A2DP and then HFP */

             

             

                message.event = WICED_BT_DISCONNECT_HFP;

                message.function = wiced_get_entry(SERVICE_BT_HFP)->disconnect_service;

                message.wait_for_event_complete = WICED_TRUE;

                wiced_rtos_push_to_queue( &app_data.queue, &message, WICED_NO_WAIT );

             

             

                wiced_rtos_unlock_mutex( &app_data.lock );

             

             

                return;

            }

             

             

            void bt_audio_connect_services(void)

            {

                app_queue_element_t message;

             

             

                WPRINT_APP_INFO( ("SAJID CONNECT !!!\r\n") );

             

             

                wiced_rtos_lock_mutex( &app_data.lock );

             

             

             

             

                /* Order for connecting HFP and then A2DP, AVRCP */

             

             

                message.event = WICED_BT_CONNECT_HFP;

                message.function = wiced_get_entry(SERVICE_BT_HFP)->connect_service;

                message.wait_for_event_complete = WICED_TRUE;

                wiced_rtos_push_to_queue( &app_data.queue, &message, WICED_NO_WAIT );

             

             

             

             

                wiced_rtos_unlock_mutex( &app_data.lock );

             

             

                return;

            }

             

             

            static void bt_audio_connection_status_callback (wiced_bt_device_address_t bd_addr, uint8_t *p_features, wiced_bool_t is_connected, uint16_t handle, wiced_bt_transport_t transport, uint8_t reason)

            {

                dm_ctxt_data.connect_state = is_connected;

             

             

                WPRINT_APP_INFO( ("[BT-DM] Connection status callback is_connected:%d reason:%x\n", is_connected, reason ) );

                if( reason == HCI_ERR_CONNECTION_TOUT )

                {

                    WPRINT_APP_INFO( ("[BT-DM] Device disconnected(link-loss). Starting Reconnection-Timer...\n") );

                    wiced_rtos_start_timer( &dm_ctxt_data.timer );

                }

            }

             

             

             

             

            static void bt_audio_dm_linkloss_timer_handler( void )

            {

                if( dm_ctxt_data.num_retries >= DM_LINK_LOSS_NUM_RETRIES || dm_ctxt_data.connect_state == WICED_TRUE )

                {

                    WPRINT_APP_INFO( ("[BT-DM] Reconnection timer - num of connection-retry:%d is_connected:%d\n", dm_ctxt_data.num_retries, dm_ctxt_data.connect_state ) );

                    dm_ctxt_data.num_retries = 0;

                    wiced_rtos_stop_timer(&dm_ctxt_data.timer);

                    return;

                }

                else

                {

                    bt_audio_reconnect_on_link_loss();

                    dm_ctxt_data.num_retries++;

                }

            }

             

             

             

             

            static wiced_bt_dev_status_t bt_audio_management_callback( wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t *p_event_data )

            {

                wiced_bt_dev_status_t status = WICED_BT_SUCCESS;

                wiced_bt_device_address_t bda;

                wiced_result_t result = WICED_ERROR;

             

             

                switch ( event )

                {

                    case BTM_SCO_CONNECTED_EVT:

                        bt_audio_hfp_sco_connection_evt_handler(&p_event_data->sco_connected);

                    break;

             

             

                    case BTM_SCO_DISCONNECTED_EVT:

                        bt_audio_hfp_sco_disconnection_evt_handler(&p_event_data->sco_disconnected);

                    break;

             

             

                    case BTM_SCO_CONNECTION_REQUEST_EVT:

                        bt_audio_hfp_sco_connection_request_evt_handler(&p_event_data->sco_connection_request);

                    break;

             

             

                    case BTM_ENABLED_EVT:

                    {

                        /* Bluetooth controller and host stack enabled */

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Bluetooth enabled (%s)\n", ((p_event_data->enabled.status == WICED_BT_SUCCESS) ? "success":"failure")) );

             

             

                        if ( p_event_data->enabled.status == WICED_BT_SUCCESS )

                        {

            #ifdef WICED_DCT_INCLUDE_BT_CONFIG

                            /* Configure the Device Name and Class of Device from the DCT */

                            platform_dct_bt_config_t* dct_bt_config;

                             // Read config

                            wiced_dct_read_lock( (void**) &dct_bt_config, WICED_TRUE, DCT_BT_CONFIG_SECTION, 0, sizeof(platform_dct_bt_config_t) );

                            WPRINT_APP_INFO( ("WICED DCT BT ADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x \r\n",

                                              dct_bt_config->bluetooth_device_address[0], dct_bt_config->bluetooth_device_address[1],

                                              dct_bt_config->bluetooth_device_address[2], dct_bt_config->bluetooth_device_address[3],

                                              dct_bt_config->bluetooth_device_address[4], dct_bt_config->bluetooth_device_address[5]) );

                            wiced_bt_set_local_bdaddr ( dct_bt_config->bluetooth_device_address );

                            WPRINT_APP_INFO( ("bt_audio_management_callback:wiced_bt_dev_write_local_addr result = 0x%x\n", (unsigned int)result) );

                            result = bt_audio_write_eir(dct_bt_config->bluetooth_device_name);

                            wiced_dct_read_unlock( (void*) dct_bt_config, WICED_TRUE );

            #else

                            result = bt_audio_write_eir(BLUETOOTH_DEVICE_NAME);

            #endif

                            WPRINT_APP_INFO( ("bt_audio_management_callback: wiced_bt_dev_write_eir result = 0x%x\n", (unsigned int)result) );

             

             

                            wiced_bt_dev_read_local_addr( bda );

                            WPRINT_APP_INFO( ("bt_audio_management_callback:Local Bluetooth Address: [%02X:%02X:%02X:%02X:%02X:%02X]\n", bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]) );

             

             

                            /**

                             * TODO Remove this, and make changes in the embedded app to solicit this information.

                             */

            #ifdef USE_WICED_HCI

                        {

                            bt_audio_paired_device_info_t out_device;

             

             

                            //TODO: Currently pushing only the last paired device to 2070x but will need to enhance this to push all paired devices.

                            if( bt_audio_nv_get_device_info_by_index(0, &out_device) != WICED_SUCCESS )

                            {

                                WPRINT_APP_INFO( ("%s no entry saved in NVRAM\n", __func__) );

                            }

                            else

                            {

                                WPRINT_APP_INFO(("%s Bluetooth address of the paired device extracted \n", __func__));

                                WPRINT_APP_INFO(("from NVRAM: %x %x %x %x %x %x\n",out_device.device_link.bd_addr[0], out_device.device_link.bd_addr[1],

                                        out_device.device_link.bd_addr[2],out_device.device_link.bd_addr[3], out_device.device_link.bd_addr[4], out_device.device_link.bd_addr[5]));

                                wiced_bt_dev_push_nvram_data(&out_device.device_link);

                            }

                        }

            #endif

                            result = wiced_bt_sdp_db_init( ( uint8_t * )sdp_database, sizeof( sdp_database ) );

                            WPRINT_APP_INFO( ("bt_audio_management_callback: wiced_bt_sdp_db_init result (bool) = 0x%x\n", (unsigned int)result) );

             

             

                            result = wiced_bt_dev_set_discoverability(BTM_GENERAL_DISCOVERABLE, wiced_bt_audio_cfg_settings.br_edr_scan_cfg.inquiry_scan_window, wiced_bt_audio_cfg_settings.br_edr_scan_cfg.inquiry_scan_interval);

                            WPRINT_APP_INFO( ("bt_audio_management_callback: discoverability result = 0x%x\n", (unsigned int)result) );

             

             

                            result = wiced_bt_dev_set_connectability (BTM_CONNECTABLE, wiced_bt_audio_cfg_settings.br_edr_scan_cfg.page_scan_window, wiced_bt_audio_cfg_settings.br_edr_scan_cfg.page_scan_interval);

                            WPRINT_APP_INFO( ("bt_audio_management_callback:connectability result = 0x%x\n", (unsigned int)result) );

             

             

                            bt_audio_init_services();

             

             

                            result = wiced_bt_dev_register_connection_status_change( bt_audio_connection_status_callback );

                            WPRINT_APP_INFO( ("bt_audio_management_callback registering acl_change callback result: 0x%x, cb = 0x%x\n", result, (unsigned int) bt_audio_connection_status_callback) );

                        }

                    }

                        break;

             

             

                    case BTM_PAIRING_IO_CAPABILITIES_BR_EDR_REQUEST_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: IO capabilities BR/EDR request \n") );

                        p_event_data->pairing_io_capabilities_br_edr_request.local_io_cap = BTM_IO_CAPABILITIES_NONE;

                        p_event_data->pairing_io_capabilities_br_edr_request.auth_req = BTM_AUTH_SINGLE_PROFILE_GENERAL_BONDING_NO;

                        break;

             

             

                    case BTM_USER_CONFIRMATION_REQUEST_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: User confirmation request \n") );

                        wiced_bt_dev_confirm_req_reply(WICED_BT_SUCCESS, p_event_data->user_confirmation_request.bd_addr);

                        break;

             

             

                    case BTM_PAIRED_DEVICE_LINK_KEYS_UPDATE_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Link key update evt\n") );

                        bt_audio_nv_update_device_link_key( &p_event_data->paired_device_link_keys_update );

                        break;

             

             

                    case BTM_PAIRED_DEVICE_LINK_KEYS_REQUEST_EVT:

                        {

                            bt_audio_paired_device_info_t out_device;

             

             

                            WPRINT_APP_INFO( ("bt_audio_management_callback: Link key request evt\n") );

                            if(WICED_SUCCESS == bt_audio_nv_get_device_info_by_addr( &p_event_data->paired_device_link_keys_request.bd_addr, &out_device ) )

                            {

                                memcpy(&p_event_data->paired_device_link_keys_request.key_data, &out_device.device_link.key_data, sizeof( out_device.device_link.key_data ) );

                            }

                            else

                            {

                                status = WICED_BT_ERROR;

                            }

                        }

                        break;

             

             

                    case BTM_LOCAL_IDENTITY_KEYS_UPDATE_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Local ID key update evt\n") );

                        bt_audio_nv_update_local_id_keys( &p_event_data->local_identity_keys_update );

                        break;

             

             

                    case BTM_LOCAL_IDENTITY_KEYS_REQUEST_EVT:

            #ifndef USE_WICED_HCI

                        if(WICED_SUCCESS != bt_audio_nv_get_local_id_keys( &p_event_data->local_identity_keys_request ))

                            status = WICED_BT_ERROR;

            #endif

                        break;

             

             

                    case BTM_SCO_CONNECTION_CHANGE_EVT:

                        bt_audio_hfp_sco_connection_change_evt_handler(&p_event_data->sco_connection_change);

                    break;

             

             

                    case BTM_SECURITY_REQUEST_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Security reqeust\n") );

                        break;

             

             

                    case BTM_PAIRING_COMPLETE_EVT:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Pairing complete %i.\n", p_event_data->pairing_complete.pairing_complete_info.ble.status) );

                        break;

             

             

                    default:

                        WPRINT_APP_INFO( ("bt_audio_management_callback: Unhandled Bluetooth Management Event: 0x%x\n", event) );

                        break;

                }

             

             

                return ( status );

            }

             

             

             

             

            void bt_audio_enable_bluetooth( void )

            {

                wiced_result_t result;

                bt_audio_nv_init();

             

             

                result = wiced_bt_stack_init( bt_audio_management_callback, &wiced_bt_audio_cfg_settings, wiced_bt_audio_cfg_buf_pools );

                WPRINT_APP_INFO( ("bt_audio_enable_bluetooth: result: 0x%x, cb = 0x%x\n", result, (unsigned int) bt_audio_management_callback) );

             

             

                wiced_rtos_init_timer( &dm_ctxt_data.timer, DM_LINK_LOSS_RETRY_INTERVAL, (timer_handler_t)bt_audio_dm_linkloss_timer_handler, NULL );

            }

             

             

            static void bt_audio_reconnect_on_link_loss(void)

            {

                app_queue_element_t message;

             

             

                wiced_rtos_lock_mutex( &app_data.lock );

             

             

                message.event                   = WICED_BT_RECONNECT_ON_LINK_LOSS;

                message.function                = bt_audio_connect_services;

                message.wait_for_event_complete = WICED_FALSE;

             

             

                wiced_rtos_push_to_queue( &app_data.queue, &message, WICED_NO_WAIT );

             

             

                wiced_rtos_unlock_mutex(&app_data.lock);

            }

            • 3. Re: hands free profile disconnects
              sajid_1694051

              I switched to just using dual_hf_a2dp and commented out the audio portions of the code, since I plan on using a DSP and connecting the DSP I2S to the BT_PCM.

               

              This is the android log I see when I try to pair :

              I/BluetoothBondStateMachine( 9504): Bond address is:11:22:33:AA:BB:CC

              E/bt-btif ( 9504): check_cod: remote_cod = 0x20041c

              I/BluetoothBondStateMachine( 9504): Entering PendingCommandState State

              I/BluetoothBondStateMachine( 9504): bondStateChangeCallback: Status: 0 Address: 11:22:33:AA:BB:CC newState: 1

              I/BluetoothBondStateMachine( 9504): Bond State Change Intent:11:22:33:AA:BB:CC OldState: 10 NewState: 11

              D/BluetoothMap( 1164): getConnectionState(11:22:33:AA:BB:CC)

              D/SFPerfTracer(  297):        layers: (3:10) (FocusedStackFrame (0xb65a0000): 0:66)* (DimLayer (0xb6606000): 0:185)* (DimLayer (0xb6608000): 0:12)* (StatusBar (0xb6682000): 1:3521) (com.android.systemui.ImageWallpaper (0xb663c000): 0:81)* (com.android.settings/com.android.settings.SubSettings$BluetoothSubSettings (0xb663e000): 30:3630) (NavigationBar (0xb6677000): 0:38) ( (0xb6679000): 0:40)-

              W/bt-btm  ( 9504): btm_acl_created hci_handle=7 link_role=1  transport=1

              W/bt-btm  ( 9504): btm_acl_created hci_handle=7 link_role=0  transport=1

              W/bt-btm  ( 9504): btm_read_remote_version_complete: BDA: 11-22-33-aa-bb-cc

              W/bt-btm  ( 9504): btm_read_remote_version_complete lmp_version 7 manufacturer 15 lmp_subversion 8713

              W/bt-btm  ( 9504): btm_process_remote_ext_features_page 0: BDA: 11-22-33-aa-bb-cc

              W/bt-btm  ( 9504): ext_features_complt page_num:1 f[0]:x0f, sm4:11, pend:0

              W/bt-btm  ( 9504): btm_process_remote_ext_features_page 1: BDA: 11-22-33-aa-bb-cc

              W/bt-btif ( 9504): info:x10

              W/bt-l2cap( 9504): L2CA_SetDesireRole() new:x1, disallow_switch:0

              I/TrustAgent.Tracker( 2051): [BluetoothConnectionTracker] Bluetooth connect broadast for Wiced Dual HFP Audio 11:22:33:AA:BB:CC

              E/bt-btif ( 9504): services_to_search = 3fffffff

              E/bt-btif ( 9504): ****************search UUID = 1200***********

              W/bt-l2cap( 9504): L2CA_ErtmConnectReq()  PSM: 0x0001  BDA: 112233aabbcc  p_ertm_info: 0x00000000 allowed:0x0 preferred:0

              W/bt-l2cap( 9504): L2CAP - st: CLOSED evt: 21

              W/bt-l2cap( 9504): L2CAP - st: CLOSED evt: 7

              W/bt-l2cap( 9504): L2CAP - st: W4_L2CAP_CON_RSP evt: 13

              W/bt-sdp  ( 9504): SDP - Rcvd conn cnf with error: 0x4  CID 0x44

              W/bt-btif ( 9504): btif_dm_search_services_evt:SDP failed after bonding re-attempting

              E/bt-btif ( 9504): services_to_search = 3fffffff

              E/bt-btif ( 9504): ****************search UUID = 1200***********

              W/bt-l2cap( 9504): L2CA_ErtmConnectReq()  PSM: 0x0001  BDA: 112233aabbcc  p_ertm_info: 0x00000000 allowed:0x0 preferred:0

              W/bt-l2cap( 9504): L2CAP - st: CLOSED evt: 21

              W/bt-l2cap( 9504): L2CAP - st: CLOSED evt: 7

              W/bt-l2cap( 9504): L2CAP - st: W4_L2CAP_CON_RSP evt: 13

              W/bt-sdp  ( 9504): SDP - Rcvd conn cnf with error: 0x4  CID 0x45

              I/BluetoothBondStateMachine( 9504): bondStateChangeCallback: Status: 0 Address: 11:22:33:AA:BB:CC newState: 2

              E/BluetoothRemoteDevices( 9504): devicePropertyChangedCallback: bdDevice: 11:22:33:AA:BB:CC, value is empty for type: 3

              D/BluetoothAdapterProperties( 9504): Adding bonded device:11:22:33:AA:BB:CC

              I/BluetoothBondStateMachine( 9504): Bond State Change Intent:11:22:33:AA:BB:CC OldState: 11 NewState: 12

              I/BluetoothBondStateMachine( 9504): StableState(): Entering Off State

              D/BluetoothMetrics( 9504): btclass20041c

              D/CachedBluetoothDevice( 6884): No profiles. Maybe we will connect later

              D/BluetoothMap( 1164): getConnectionState(11:22:33:AA:BB:CC)

              E/bt-btm  ( 9504): btm_sec_disconnected - Clearing Pending flag

              W/bt-l2cap( 9504): L2CA_SetDesireRole() new:x1, disallow_switch:0

              D/BluetoothMapService( 9504): onReceive

              I/TrustAgent.Tracker( 2051): [BluetoothConnectionTracker] Bluetooth disconnect broadast for Wiced Dual HFP Audio 11:22:33:AA:BB:CC

              D/HeadsetStateMachine( 9504): Disconnected process message: 10, size: 0

               

              This is the corresponding console log:

               

              Platform BCM94343WWCD1 initialised

              Started ThreadX v5.6

              [App] Starting Dual A2DP-HFP App

              [App] Dual A2DP HFP thread started...

              WICED DCT BT NAME: Wiced Dual HFP Audio

              WICED DCT BT DEVICE CLASS : 20 04 1c

              WICED DCT name Wiced Dual HFP Audio

               

              sajid Starting Bluetooth...

              [BT-A2DP] Service Added

              [BT-HFP] Service Added

              00:00:00.041000 GKI_create_task func=0x801c255  id=1  name=BTU  stack=0x0  stackSize=6144

              00:00:00.050000 GKI_create_task func=0x8022d71  id=0  name=HCISU  stack=0x0  stackSize=4096

               

              bt_audio_enable_bluetooth: result: 0x0, cb = 0x80109d9

              sajid bt_audio_management_callback 21

              sajid bt_audio_management_callback 0

              bt_audio_management_callback: Bluetooth enabled (success)

              WICED DCT BT ADDR 0x11:0x22:0x33:0xaa:0xbb:0xcc

              bt_audio_management_callback:wiced_bt_dev_write_local_addr result = 0x4

              sajid bt_audio_write_eir

              bt_audio_management_callback: wiced_bt_dev_write_eir result = 0x0

              bt_audio_management_callback:Local Bluetooth Address: [11:22:33:AA:BB:CC]

              bt_audio_management_callback: wiced_bt_sdp_db_init result (bool) = 0x1

              bt_audio_management_callback: discoverability result = 0x0

              bt_audio_management_callback:connectability result = 0x0

              [bt_audio_hfp_init_service] HF Profile init result = 0

              [bt_audio_hfp_init_service] SCO data cb register result = 7

              [bt_audio_hfp_init_service] SCO setting buffer-pool result = 8034

              [BT-A2DP]: a2dp sink init result = 0

              [BT-A2DP]: Service started

              bt_audio_management_callback registering acl_change callback result: 0x0, cb = 0x8010915

               

              <<<< following log is when I select the device on the phone in the BT settings screen

               

              [BT-DM] Connection status callback is_connected:1 reason:0

              sajid bt_audio_management_callback 9

              bt_audio_management_callback: Unhandled Bluetooth Management Event: 0x9

              sajid bt_audio_management_callback 8

              bt_audio_management_callback: IO capabilities BR/EDR request

              sajid bt_audio_management_callback 4

              bt_audio_management_callback: User confirmation request

              sajid bt_audio_management_callback 11

              bt_audio_management_callback: Pairing complete 8192.

              sajid bt_audio_management_callback 18

              bt_audio_management_callback: Link key update evt

              [BT-DM] Connection status callback is_connected:0 reason:13

              • 4. Re: hands free profile disconnects
                sajid_1694051

                Problem seems to be "unauthorized" connection.

                 

                Running in BCM94343WWCD1

                Changed the code to just use the dual_hf_a2dp project and commented out calls to audio, mem_pool and nv.

                device defined as:

                 

                wiced_bt_cfg_settings_t wiced_bt_audio_cfg_settings =

                {

                    .device_name               = (uint8_t*)BLUETOOTH_DEVICE_NAME,

                    .device_class              = {0x24, 0x04, 0x18},            <-- tried changing device class to 0x04, 0x08, 0x1c, did not help

                    .security_requirement_mask = BTM_SEC_NONE,  <--- tried all possible settings here, did not help

                    .max_simultaneous_links    = 3,/*TBD*/

                 

                 

                These are the logs form the device

                00:00:40.032032 RCVD Event from HCI. Name: HCI_Simple_Pairing_Complete  (Hex Code: 0x36  Param Len: 7) Ctrl(0)

                00:00:40.042032 Parameters

                00:00:40.045032                                   Status : Success (0x00)

                00:00:40.052032                        BD_ADDR of remote : f8-e0-79-f7-71-13

                00:00:40.059032 --

                00:00:40.061032 --

                00:00:40.063032 RCVD Event from HCI. Name: HCI_Link_Key_Notification  (Hex Code: 0x18  Param Len: 23) Ctrl(0)

                00:00:40.007496 Parameters

                00:00:40.009496                        BD_ADDR of remote : f8-e0-79-f7-71-13

                00:00:40.016496 8c

                00:00:40.018496                                 Key Type : Unauthenticated Combination generated from P-192 (0x04)

                00:00:40.029496 --

                bt_audio_management_callback: Pairing complete 8192.

                 

                bt_audio_management_callback: Link key update evt

                00:00:41.009928 L2CAP SENT Command.  Name: L2C Connection Response (0x03) ID 0x04, len 8

                00:00:41.017928                               Channel ID : 01

                00:00:41.023928                          Destination CID : 0x0

                00:00:41.029928                               Source CID : 0x40

                00:00:41.034928                                   Result : 0x4 (refused - no resources available)

                00:00:41.043928                                   Status : 0x0

                00:00:41.049928 --

                 

                00:00:41.000392 L2CAP SENT Command.  Name: L2C Connection Response (0x03) ID 0x05, len 8

                00:00:41.008392                               Channel ID : 01

                00:00:41.014392                          Destination CID : 0x0

                00:00:41.019392                               Source CID : 0x41

                00:00:41.025392                                   Result : 0x4 (refused - no resources available)

                00:00:41.034392                                   Status : 0x0

                00:00:41.040392 --

                00:00:44.045640 --

                 

                The corresponding phone logs :

                D/BtGatt.GattService(23793): start scan with filters

                I/BtOppRfcommListener(23793): Accept thread started.

                D/BtGatt.ScanManager(23793): handling starting scan

                D/BtGatt.ScanManager(23793): configureRegularScanParams() - queue=1

                D/BtGatt.ScanManager(23793): configureRegularScanParams() - ScanSetting Scan mode=2 mLastConfiguredScanSetting=-2147483648

                W/bt-btm  (23793): btm_process_inq_results: BDA: 11-22-33-aa-bb-cc

                W/bt-btm  (23793): btm_process_inq_results: Dev class: 20-04-1c

                D/BtGatt.GattService(23793): stopScan() - queue size =1

                D/BtGatt.ScanManager(23793): stop scan

                :

                E/bt-btif (23793): bte_scan_filt_param_cfg_evt, 1

                E/bt-btif (23793): check_cod: remote_cod = 0x20041c

                W/bt-btm  (23793): btm_acl_created hci_handle=3 link_role=1  transport=1

                W/bt-btm  (23793): btm_acl_created hci_handle=3 link_role=0  transport=1

                W/bt-btm  (23793): btm_read_remote_version_complete: BDA: 11-22-33-aa-bb-cc

                W/bt-btm  (23793): btm_read_remote_version_complete lmp_version 7 manufacturer 15 lmp_subversion 8713

                W/bt-btm  (23793): btm_process_remote_ext_features_page 0: BDA: 11-22-33-aa-bb-cc

                W/bt-btm  (23793): ext_features_complt page_num:1 f[0]:x0f, sm4:11, pend:0

                W/bt-btm  (23793): btm_process_remote_ext_features_page 1: BDA: 11-22-33-aa-bb-cc

                W/bt-btif (23793): info:x10

                W/bt-l2cap(23793): L2CA_SetDesireRole() new:x1, disallow_switch:0

                D/btif_config(23793): btif_get_device_type: Device [11:22:33:aa:bb:cc] type 1

                D/btif_config_util(23793): btif_config_save_file(L188): in file name:/data/misc/bluedroid/bt_config.new

                E/bt-btif (23793): services_to_search = 3fffffff

                E/bt-btif (23793): ****************search UUID = 1200***********

                W/bt-l2cap(23793): L2CA_ErtmConnectReq()  PSM: 0x0001  BDA: 112233aabbcc  p_ertm_info: 0x00000000 allowed:0x0 preferred:0

                W/bt-l2cap(23793): L2CAP - st: CLOSED evt: 21

                W/bt-l2cap(23793): L2CAP - st: CLOSED evt: 7

                W/bt-l2cap(23793): L2CAP - st: W4_L2CAP_CON_RSP evt: 13

                W/bt-sdp  (23793): SDP - Rcvd conn cnf with error: 0x4  CID 0x40

                W/bt-btif (23793): btif_dm_search_services_evt:SDP failed after bonding re-attempting

                E/bt-btif (23793): services_to_search = 3fffffff

                E/bt-btif (23793): ****************search UUID = 1200***********

                W/bt-l2cap(23793): L2CA_ErtmConnectReq()  PSM: 0x0001  BDA: 112233aabbcc  p_ertm_info: 0x00000000 allowed:0x0 preferred:0

                W/bt-l2cap(23793): L2CAP - st: CLOSED evt: 21

                W/bt-l2cap(23793): L2CAP - st: CLOSED evt: 7

                W/bt-l2cap(23793): L2CAP - st: W4_L2CAP_CON_RSP evt: 13

                W/bt-sdp  (23793): SDP - Rcvd conn cnf with error: 0x4  CID 0x41

                D/BluetoothAdapterService(23793): getAdapterService() - returning com.android.bluetooth.btservice.AdapterService@3ad2de45

                D/BluetoothMetrics(23793): btclass20041c

                D/Checkin (23793): publish the event [tag = MOT_BT event name = PAIRING]

                E/bt-btm  (23793): btm_sec_disconnected - Clearing Pending flag

                W/bt-l2cap(23793): L2CA_SetDesireRole() new:x1, disallow_switch:0

                D/btif_config_util(23793): btif_config_save_file(L188): in file name:/data/misc/bluedroid/bt_config.new

                • 5. Re: hands free profile disconnects
                  sajid_1694051

                  I added the following code to my call back handler, bt_audio_management_callback :

                      case BTM_ENCRYPTION_STATUS_EVT:

                          p_status = &p_event_data->encryption_status;

                          WPRINT_BT_APP_INFO(( "Encryption Status Event: res %d", p_status->result));

                          break;

                  And I see the following log about 15 seconds after the Pairing complete message :

                  Encryption Status Event: res 0

                  [BT-DM] Connection status callback is_connected:0 reason:13

                   

                  How am I supposed to handle this event ?

                  I can't find anything in the sample demo apps that handles this.