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

NRF_ERROR_INVALID_PARAM when launching advertising with scan response

There was an unexpected issue configuring beacon ad packages. The task is to transfer as much data as possible in beacon mode. For this, I want to include the scan responce package. But somehow I can't do it.
Here is the code:

#define BEACON_DATA_MAX_SIZE 27
#define BEACON_RSP_DATA_MAX_SIZE 27

// ADV packed declaration
static ble_advdata_t m_beacon_advdata;
static ble_advdata_manuf_data_t m_manuf_specific_data;
static uint8_t m_beacon_data_buf[BEACON_DATA_MAX_SIZE];

// ADV scan responce packed declaration
static ble_advdata_t m_beacon_rspdata;
static ble_advdata_manuf_data_t m_manuf_specific_rsp_data;
static uint8_t m_beacon_rsp_data_buf[BEACON_DATA_MAX_SIZE];


static uint8_t    m_enc_advdata_beacon[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; 				/**< Buffer for storing an encoded advertising set. */
static uint8_t    m_enc_advdata_rsp_beacon[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; 			/**< Buffer for storing an encoded advertising set. */
static uint8_t    m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];    					/**< Buffer for storing an encoded advertising set. */
static uint8_t    m_enc_srdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];     					/**< Buffer for storing an encoded advertising set. */

static ble_gap_adv_params_t m_adv_params_beacon;                           	 		/**< Parameters to be passed to the stack when starting advertising. */
static ble_gap_adv_params_t m_adv_params;                               			/**< Parameters to be passed to the stack when starting advertising. */
static uint8_t              m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;  		/**< Advertising handle used to identify an advertising set. */


/**@brief Struct that contains pointers to the encoded advertising data. */
static ble_gap_adv_data_t m_adv_data_beacon =
{
    .adv_data =
    {
        .p_data = m_enc_advdata_beacon,
        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    },
    .scan_rsp_data =
    {
		.p_data = m_enc_advdata_rsp_beacon,
		.len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
//		.p_data = NULL,
//		.len    = 0
    }
};


static void advertising_beacon_init()
{
    uint32_t      err_code;

    m_manuf_specific_data.data.p_data = m_beacon_data_buf;
    m_manuf_specific_data.data.size   = BEACON_DATA_MAX_SIZE;
    m_manuf_specific_rsp_data.data.p_data = m_beacon_rsp_data_buf;
    m_manuf_specific_rsp_data.data.size   = BEACON_RSP_DATA_MAX_SIZE;

    // Build and set advertising data.
    memset(&m_beacon_advdata, 0, sizeof(m_beacon_advdata));
    memset(&m_beacon_rspdata, 0, sizeof(m_beacon_rspdata));

    m_beacon_advdata.name_type             = BLE_ADVDATA_NO_NAME;
    m_beacon_advdata.p_manuf_specific_data = &m_manuf_specific_data;

    m_beacon_rspdata.name_type             = BLE_ADVDATA_NO_NAME;
    m_beacon_rspdata.p_manuf_specific_data = &m_manuf_specific_rsp_data;

    // Initialize advertising parameters (used when starting advertising).
    memset(&m_adv_params_beacon, 0, sizeof(m_adv_params_beacon));

    m_adv_params_beacon.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
    m_adv_params_beacon.p_peer_addr     = NULL;    // Undirected advertisement.
    m_adv_params_beacon.filter_policy   = BLE_GAP_ADV_FP_ANY;
    m_adv_params_beacon.interval        = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params_beacon.duration        = 0;       // Never time out.

    m_adv_params_beacon.primary_phy     = BLE_GAP_PHY_1MBPS;
    m_adv_params_beacon.secondary_phy   = BLE_GAP_PHY_1MBPS;

    m_adv_params_beacon.max_adv_evts    = 3;

    err_code = ble_advdata_encode(&m_beacon_advdata, m_adv_data_beacon.adv_data.p_data, &m_adv_data_beacon.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&m_beacon_rspdata, m_adv_data_beacon.scan_rsp_data.p_data, &m_adv_data_beacon.scan_rsp_data.len);
    APP_ERROR_CHECK(err_code);
}

static void advertising_start_beacon(void)
{
    ret_code_t err_code;

    sd_ble_gap_adv_stop(m_adv_handle);

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data_beacon, &m_adv_params_beacon);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    APP_ERROR_CHECK(err_code);
}

The error occurs in the advertising_start_beacon function when calling sd_ble_gap_adv_set_configure.
sd_ble_gap_adv_set_configure returns NRF_ERROR_INVALID_PARAM.

I can't figure out what the problem is. Thanks!

Parents
  • Hi,

    You get NRF_ERROR_INVALID_PARAM because you provide a  scan response buffer while the type indicate it should not be there. To fix this you need to set the type to BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED (and not BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED).

  • those. I can't use scan response packets on non-connectable connection?

  • Hi,

    You can use scan response with both connectable and non-connectable advertising. But you need to ensure that you configure a advertising type that is scannable if you want to supply scan response data. That is the only difference between the type you used before (BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED) and the one I suggests to fix the issue (BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED ).

    You can refer to this snippet from ble_gap.h to see all possible types if that is interesting:

    /**@defgroup BLE_GAP_ADV_TYPES GAP Advertising types
     *
     * Advertising types defined in Bluetooth Core Specification v5.0, Vol 6, Part B, Section 4.4.2.
     *
     * The maximum advertising data length is defined by @ref BLE_GAP_ADV_SET_DATA_SIZE_MAX.
     * The maximum supported data length for an extended advertiser is defined by
     * @ref BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED
     * Note that some of the advertising types do not support advertising data. Non-scannable types do not support
     * scan response data.
     *
     * @{ */
    #define BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED                   0x01   /**< Connectable and scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE  0x02   /**< Connectable non-scannable directed advertising
                                                                                            events. Advertising interval is less that 3.75 ms.
                                                                                            Use this type for fast reconnections.
                                                                                            @note Advertising data is not supported. */
    #define BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED                  0x03   /**< Connectable non-scannable directed advertising
                                                                                            events.
                                                                                            @note Advertising data is not supported. */
    #define BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED                0x04   /**< Non-connectable scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED             0x05   /**< Non-connectable non-scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED       0x06   /**< Connectable non-scannable undirected advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED         0x07   /**< Connectable non-scannable directed advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_UNDIRECTED       0x08   /**< Non-connectable scannable undirected advertising
                                                                                            events using extended advertising PDUs.
                                                                                            @note Only scan response data is supported. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED         0x09   /**< Non-connectable scannable directed advertising
                                                                                            events using extended advertising PDUs.
                                                                                            @note Only scan response data is supported. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED    0x0A   /**< Non-connectable non-scannable undirected advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED      0x0B   /**< Non-connectable non-scannable directed advertising
                                                                                            events using extended advertising PDUs. */
    /**@} */
    

Reply Children
No Data
Related