20719 forgets BD/EDR pairing after reset/power cycle

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
juerc_3891021
Level 1
Level 1

At boot I disable pairing and connections from non paired devices:

             wiced_bt_set_pairable_mode(0 /*allow_pairing*/, 1 /*connect_only_paired*/);

I allow pairing from a button with:

             wiced_bt_set_pairable_mode(1 /*allow_pairing*/, 0 /*connect_only_paired*/);

After pairing from the button(I write keys and bdaddr to NVRAM),  I deny further pairings and connections from non-paired devices:

             wiced_bt_set_pairable_mode(0 /*allow_pairing*/, 1 /*connect_only_paired*/);

Now if I try to connect and re-connect (BD/EDR), it works perfectly:

     [4088185][bt_hw]: HCI EVENT (0x04) Connection Request

     [4088186][bt_hw]:     BD_ADDR: 51:dc:3b:7a:9f:cc

     [4088186][bt_hw]:     Class of device: 0c:02:5a

     [4088187][bt_hw]:     Link type: ACL Connection requested

     [4088188][bt_hw]: HCI COMMAND: (group: 0x01, cmd: 0x0009) HCI_Accept_Connection_Request

But if I power off and power on the device, then it won't let to connect anymore. NVRAM still contains the bonding data(I have checked it from a trace):

     [9275][bt_hw]: HCI EVENT (0x04) Connection Request

     [9275][bt_hw]:     BD_ADDR: 51:dc:3b:7a:9f:cc

     [9276][bt_hw]:     Class of device: 0c:02:5a

     [9277][bt_hw]:     Link type: ACL Connection requested

     [9277][bt_hw]: HCI COMMAND: (group: 0x01, cmd: 0x000a) HCI_Reject_Connection_Request

     [9278][bt_hw]:     Reason: 0x0f

     [9279][bt_hw]:     CONNECTION REJECTED DUE TO UNACCEPTABLE BD_ADDR(51:dc:3b:7a:9f:cc)

The same code works for BLE, it still allows to connect after power cycle. Am I doing something wrong here? Do I need to call some

BT-stack function at boot to inform (BD/EDR)stack about bonding data in NVRAM? After reset the stack never asks about keys, it just blocks the connection

even though the keys are in NVRAM.

Br. Juha

0 Likes
2 Replies
Murali_R
Moderator
Moderator
Moderator
250 sign-ins 250 replies posted 100 solutions authored

Hi,

Could you please elaborate on the issue faced so that we would be able to debug it.

You have mentioned that "The same code works for BLE, it still allows to connect after power cycle." Does this mean that you have the same code for both BT and BLE?

Or else could you attach your project and give some insight on the peer device that you are using, so that we could look into it if there are any issues in it.

Regards,

Murali

0 Likes

Hi,

Unfortunately I can't attach the whole project here, but here is the description and hotspots.

Our application is dual mode, it has both BLE and BR/EDR enabled. Application basicly acts like an UART bridge from Android phone to an another device on the same board as the Cypress BT-modem(20719).

[Android phone] -> [BT HW --- wiced hci uart --- another device]

On BR/EDR side we are using modified SPP-lib from the Cypress SDK. On BLE side we have a custom BLE UART GATT service with TX and RX characteristics defined. Android phone acts as a scanner and BT-device advertises.

Here is the application init function:

/*

* This function is executed in the BTM_ENABLED_EVT management callback.

*/

void ble_btc_uart_app_init(void)

{

    uart_init();

    app_write_eir();

    /* Initialize Application */

    wiced_bt_app_init();

    ble_btc_uart_set_pairable_mode(WICED_FALSE /* dont't allow pairing */, WICED_TRUE /* true = only paired can connect */);

    /* Set Advertisement Data */

    ble_btc_uart_set_advertisement_data();

    /* Register with stack to receive GATT callback */

    wiced_bt_gatt_register( ble_btc_uart_event_handler );

    /* Initialize GATT Database */

    wiced_bt_gatt_db_init( gatt_database, gatt_database_len );

    /* Initialize SDP Database */

    wiced_bt_sdp_db_init( (uint8_t*)sdp_database, sdp_database_len );

    /* Start Undirected LE Advertisements on device startup.

     * The corresponding parameters are contained in 'wiced_bt_cfg.c' */

    wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, 0, NULL);

    /* Make device connectable (enables page scan) using default connectability window/interval.

     * The corresponding parameters are contained in 'wiced_bt_cfg.c' */

    wiced_bt_dev_set_connectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW, BTM_DEFAULT_CONN_INTERVAL);

    /* Make device discoverable (enables inquiry scan) over BR/EDR using default discoverability window/interval.

     * The corresponding parameters are contained in 'wiced_bt_cfg.c' */

    wiced_bt_dev_set_discoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW, BTM_DEFAULT_DISC_INTERVAL);

    wiced_bt_spp_startup(&spp_reg);

    wiced_hal_gpio_init();

    //digictal mic clock

    wiced_hal_gpio_configure_pin(WICED_P00, GPIO_INPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

    wiced_hal_gpio_configure_pin(WICED_P26, GPIO_INPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

    wiced_result_t r = wiced_init_timer(&m_rssi_read_timer, on_rssi_read_timer_expire, 0,

            WICED_MILLI_SECONDS_TIMER);

    if(r != WICED_SUCCESS) {

        DBG("Failed to initialize rssi read timer\n");

    }

    m_rssi_read_timer_running = 0;

    /* OTA Firmware upgrade Initialization */

#ifdef OTA_SECURE_FIRMWARE_UPGRADE

    if (!wiced_ota_fw_upgrade_init(&ecdsa256_public_key, NULL))

#else

    if (!wiced_ota_fw_upgrade_init(NULL, NULL))

#endif

    {

        WICED_BT_TRACE("OTA upgrade Init failure !!! \n");

    }

}

SDP Database:

const uint8_t sdp_database[] = // Define SDP database

{

    //SDP_ATTR_SEQUENCE_1(162),

    SDP_ATTR_SEQUENCE_1(242),

    // SDP Record for GATT (Generic Attribute)

    SDP_ATTR_SEQUENCE_1(48),

        SDP_ATTR_RECORD_HANDLE(HDLR_GATT_GENERIC_ATTRIBUTE),

        SDP_ATTR_CLASS_ID(UUID_SERVICE_GATT),

        SDP_ATTR_ID(ATTR_ID_PROTOCOL_DESC_LIST), SDP_ATTR_SEQUENCE_1(19),

            SDP_ATTR_SEQUENCE_1(6),

                SDP_ATTR_UUID16(UUID_PROTOCOL_L2CAP),

                SDP_ATTR_VALUE_UINT2(BT_PSM_ATT),

            SDP_ATTR_SEQUENCE_1(9),

                SDP_ATTR_UUID16(UUID_PROTOCOL_ATT),

                SDP_ATTR_VALUE_UINT2(HDLS_GENERIC_ATTRIBUTE),

                SDP_ATTR_VALUE_UINT2(HDLS_GENERIC_ATTRIBUTE),

        SDP_ATTR_BROWSE_LIST,

    // SDP Record for GATT (Generic Access)

    SDP_ATTR_SEQUENCE_1(48),

        SDP_ATTR_RECORD_HANDLE(HDLR_GATT_GENERIC_ACCESS),

        SDP_ATTR_CLASS_ID(UUID_SERVICE_GAP),

        SDP_ATTR_ID(ATTR_ID_PROTOCOL_DESC_LIST), SDP_ATTR_SEQUENCE_1(19),

            SDP_ATTR_SEQUENCE_1(6),

                SDP_ATTR_UUID16(UUID_PROTOCOL_L2CAP),

                SDP_ATTR_VALUE_UINT2(BT_PSM_ATT),

            SDP_ATTR_SEQUENCE_1(9),

                SDP_ATTR_UUID16(UUID_PROTOCOL_ATT),

                SDP_ATTR_VALUE_UINT2(HDLS_GENERIC_ACCESS),

                SDP_ATTR_VALUE_UINT2(HDLC_GENERIC_ACCESS_APPEARANCE_VALUE),

        SDP_ATTR_BROWSE_LIST,

    // Serial port

    SDP_ATTR_SEQUENCE_1(69),                                                // 2 bytes

        SDP_ATTR_RECORD_HANDLE(HDLR_SERIAL_PORT),                           // 8 bytes

        SDP_ATTR_CLASS_ID(UUID_SERVCLASS_SERIAL_PORT),                      // 8

        SDP_ATTR_RFCOMM_PROTOCOL_DESC_LIST( SPP_RFCOMM_SCN ),               // 17 bytes

        SDP_ATTR_BROWSE_LIST,                                               // 8

        SDP_ATTR_PROFILE_DESC_LIST(UUID_SERVCLASS_SERIAL_PORT, 0x0102),     // 13 byte

        SDP_ATTR_SERVICE_NAME(10),                                          // 15

        'S', 'P', 'P', ' ', 'S', 'E', 'R', 'V', 'E', 'R',

    // Device ID service

    SDP_ATTR_SEQUENCE_1(69),                                                // 2 bytes, length of the record

        SDP_ATTR_RECORD_HANDLE(HDLR_DEVICE_ID),                             // 8 byte

        SDP_ATTR_CLASS_ID(UUID_SERVCLASS_PNP_INFORMATION),                  // 8

        SDP_ATTR_PROTOCOL_DESC_LIST(1),                                     // 18

        SDP_ATTR_UINT2(ATTR_ID_SPECIFICATION_ID, 0x103),                    // 6

        SDP_ATTR_UINT2(ATTR_ID_VENDOR_ID, 0x0f),                            // 6

        SDP_ATTR_UINT2(ATTR_ID_PRODUCT_ID, 0x0401),                         // 6

        SDP_ATTR_UINT2(ATTR_ID_PRODUCT_VERSION, 0x0001),                    // 6

        SDP_ATTR_BOOLEAN(ATTR_ID_PRIMARY_RECORD, 0x01),                     // 5

        SDP_ATTR_UINT2(ATTR_ID_VENDOR_ID_SOURCE, DI_VENDOR_ID_SOURCE_BTSIG) // 6

};

GATT database (REQUIRE PAIRING is defined):

const uint8_t gatt_database[] = // Define GATT database

{

    /* Primary Service 'Generic Attribute' */

    PRIMARY_SERVICE_UUID16 (HDLS_GENERIC_ATTRIBUTE, UUID_SERVICE_GATT),

    /* Primary Service 'Generic Access' */

    PRIMARY_SERVICE_UUID16 (HDLS_GENERIC_ACCESS, UUID_SERVICE_GAP),

        /* Characteristic 'Device Name' */

        CHARACTERISTIC_UUID16 (HDLC_GENERIC_ACCESS_DEVICE_NAME, HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE,

            UUID_CHARACTERISTIC_DEVICE_NAME, LEGATTDB_CHAR_PROP_READ,

            LEGATTDB_PERM_READABLE),

        /* Characteristic 'Appearance' */

        CHARACTERISTIC_UUID16 (HDLC_GENERIC_ACCESS_APPEARANCE, HDLC_GENERIC_ACCESS_APPEARANCE_VALUE,

            UUID_CHARACTERISTIC_APPEARANCE, LEGATTDB_CHAR_PROP_READ,

            LEGATTDB_PERM_READABLE),

    /* Primary Service 'ble_uart' */

    PRIMARY_SERVICE_UUID128 (HDLS_BLE_UART, __UUID_BLE_UART),

        /* Characteristic ble tx - phone rx */

        CHARACTERISTIC_UUID128 (HDLC_BLE_UART_RX, HDLC_BLE_UART_RX_VALUE,

               __UUID_BLE_UART_RX,

               LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY,

#ifdef REQUIRE_PAIRING

               LEGATTDB_PERM_READABLE | LEGATTDB_PERM_AUTH_READABLE), //see vol3. part f 3.2.5 Attribute Permissions

#else

               LEGATTDB_PERM_READABLE),

#endif

            /* Descriptor 'Client Characteristic Configuration' */

            CHAR_DESCRIPTOR_UUID16_WRITABLE (HDLD_BLE_UART_RX_CLIENT_CONFIGURATION,

                    UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,

#ifdef REQUIRE_PAIRING

                    LEGATTDB_PERM_AUTH_READABLE | LEGATTDB_PERM_WRITE_REQ | LEGATTDB_PERM_AUTH_WRITABLE),

#else

                    LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ),

#endif

        /* Characteristic ble rx - phone tx */

        CHARACTERISTIC_UUID128_WRITABLE (HDLC_BLE_UART_TX, HDLC_BLE_UART_TX_VALUE,

                __UUID_BLE_UART_TX,

                LEGATTDB_CHAR_PROP_WRITE,

#ifdef REQUIRE_PAIRING

                LEGATTDB_PERM_WRITE_REQ | LEGATTDB_PERM_AUTH_WRITABLE),

#else

                LEGATTDB_PERM_WRITE_REQ),

#endif

    //

    // --- FOTA ---

    //

    // Declare mandatory GATT service

    PRIMARY_SERVICE_UUID16(HANDLE_OTA_FW_UPGRADE_GATT_SERVICE, UUID_SERVICE_GATT),

    // Handle 0xff00: Broadcom vendor specific WICED Upgrade Service.

    #ifdef OTA_SECURE_FIRMWARE_UPGRADE

        PRIMARY_SERVICE_UUID128(HANDLE_OTA_FW_UPGRADE_SERVICE, UUID_OTA_SEC_FW_UPGRADE_SERVICE),

    #else

        PRIMARY_SERVICE_UUID128(HANDLE_OTA_FW_UPGRADE_SERVICE, UUID_OTA_FW_UPGRADE_SERVICE),

    #endif

                    // Handles 0xff03: characteristic WS Control Point, handle 0xff04 characteristic value.

            CHARACTERISTIC_UUID128_WRITABLE(HANDLE_OTA_FW_UPGRADE_CHARACTERISTIC_CONTROL_POINT, HANDLE_OTA_FW_UPGRADE_CONTROL_POINT,

                    UUID_OTA_FW_UPGRADE_CHARACTERISTIC_CONTROL_POINT, LEGATTDB_CHAR_PROP_WRITE | LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_INDICATE,

                    LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_WRITE_REQ /*| LEGATTDB_PERM_AUTH_WRITABLE*/),

                // Declare client characteristic configuration descriptor

                // Value of the descriptor can be modified by the client

                // Value modified shall be retained during connection and across connection

                // for bonded devices.  Setting value to 1 tells this application to send notification

                // when value of the characteristic changes.  Value 2 is to allow indications.

                CHAR_DESCRIPTOR_UUID16_WRITABLE(HANDLE_OTA_FW_UPGRADE_CLIENT_CONFIGURATION_DESCRIPTOR, UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,

                        LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ /*| LEGATTDB_PERM_AUTH_WRITABLE */),

                // Handle 0xff07: characteristic WS Data, handle 0xff08 characteristic value. This

                // characteristic is used to send next portion of the FW Similar to the control point

                CHARACTERISTIC_UUID128_WRITABLE(HANDLE_OTA_FW_UPGRADE_CHARACTERISTIC_DATA, HANDLE_OTA_FW_UPGRADE_DATA,

                        UUID_OTA_FW_UPGRADE_CHARACTERISTIC_DATA, LEGATTDB_CHAR_PROP_WRITE,

                        LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_WRITE_REQ /*| LEGATTDB_PERM_AUTH_WRITABLE */),

};

0 Likes