This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ANCS add to S130

I develop ANCS success in S110,but in example ble_app_hrs_rscs_relay of S130 SDK9 .I don't know how to add the ANCS.I find S110 has ble_bondmnngr.c file,but in S130 dosn't exsit,Just find device_manager_central.c file. The phone can't bond the device .Should I add the ble_bondmnngr.c to the project like in S110? TKS

  • I see.

    Adding device_manager_peripheral library to the ble_app_hrs_rscs_relay example will probably lead to conflict, but they should be fixable.

    Do you need concurrent peripheral and central operation? Since you have selected the ble_app_hrs_rscs_relay example? Do you need pairing/bonding support for the central and the peripheral?

  • Yes,Petter Myhre.My production need peripheral and central operation.Be peripheral role,it can be linked by phone,but can't be bonded now.Be central role ,it can scan other BLE device,and create link,but often arise link breaking,I haven't found where the problem is.I now add the device_manager_peripheral.c to the ble_app_hrs_rscs_relay example ,program can receive the BLE_GAP_EVT_SEC_INFO_REQUEST when I use the phone Launching parting operation,then my program restart.. The device_manager_peripheral.c file manage the master BLE( such as phone) Independently,while device_manager_central.c manage other slave BLE(such as CSC device),I think the conflict can be solute,but I don't know where to start, because I don't know the BLE encryption principle .Could you show me how to modify the device_manager_peripheral.cto able bond the phone?


  • case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
        
                 event.event_id = DM_EVT_SECURITY_SETUP;
    
                m_connection_table[index].state |= STATE_PAIRING;
                notify_app                       = true;
    
                if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID)
                {
                    //Assign a peer index as a new bond or update existing bonds.
                    err_code = device_instance_allocate((uint8_t *)&device_index,
                                                        &m_connection_table[index].peer_addr);
    
                    //Allocation successful.
                    if (err_code == NRF_SUCCESS)
                    {
                        handle.device_id                        = device_index;
                        m_connection_table[index].bonded_dev_id = device_index;
                    }
                    else
                    {
                        event_result = err_code;
                        notify_app   = true;
                    }
                }
                else
                {
                    //Bond/key refresh.
                    event.event_id = DM_EVT_SECURITY_SETUP_REFRESH;
                    memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE);
    
                    //Set the update flag for bond data.
                    m_connection_table[index].state |= STATE_BOND_INFO_UPDATE;
                }
    
                ble_gap_sec_keyset_t keys_exchanged;
    
    
                keys_exchanged.keys_central.p_enc_key  = NULL;
                keys_exchanged.keys_central.p_id_key   = &m_peer_table[m_connection_table[index].bonded_dev_id].peer_id; 
                keys_exchanged.keys_central.p_sign_key = NULL;
                keys_exchanged.keys_periph.p_enc_key   = &m_bond_table[index].peer_enc_key;
                keys_exchanged.keys_periph.p_id_key    = NULL;
                keys_exchanged.keys_periph.p_sign_key  = NULL;
    
                err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle,
                                                       BLE_GAP_SEC_STATUS_SUCCESS,
                                                       &m_application_table[0].sec_param, 
                                                       &keys_exchanged);
    
                if (err_code != NRF_SUCCESS)
                {
                    event_result = err_code;
                    notify_app   = false;
                }
                break;
    

    The program can run here,but then go to restart.

  • So I guess you get a reset because of an error returned somewhere? Please define DEBUG, turn off optimizations and put a breakpoint in app_error_handler().

  • I have tried to make an example for you. I used ble_app_hrs_rscs_relay as a starting point. SDK 9.0.0, S130 1.0.0.

    I have modified the device manager library. Now each .c file has its own .h file. And the function names are not the same, so there shouldn't be any conflicts. You can find the new libraries in the project folder.

    I have done very limited testing, but it seems to work.

    Here is the example, extract to \examples\ble_central_and_peripheral\experimental. I used Keil.

Related