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

NRF_ERROR_INVALID_PARAM error code

Hello,

I try to add pairing functionality to my app. Error code NRF_ERROR_INVALID_PARAM occur from the sd_ble_gap_sec_params_reply when i want to read my characteritic.

Characteristic properties: Read & Write : BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM No authentication required for read authentication required for write

on_ble_evt function (main.c)

 case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
    
       
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle,BLE_GAP_SEC_STATUS_SUCCESS,&m_sec_params);
            APP_ERROR_CHECK(err_code);
						
            break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
				{
					
					ble_gatts_rw_authorize_reply_params_t reply;
					memset(&reply, 0, sizeof(ble_gatts_rw_authorize_reply_params_t));
					reply.type = p_ble_evt->evt.gatts_evt.params.authorize_request.type;
					
					//==== Write case ====
					if ( p_ble_evt->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_READ  )
					{
							uint8_t test_buffer[20];							
							
							for(uint8_t i = 0 ; i evt.gatts_evt.params.authorize_request.request.write.len; i++)
									test_buffer[i] = p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.data[i];                                   
							
							// This is a test function. Master will get this error when first byte is not 0x12. 
							if (test_buffer[0] != 0x12)
									reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED;
							
							err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle, &reply);       
						 APP_ERROR_CHECK(err_code);
					}
					
					//====Read case====
					else if( p_ble_evt->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE  )
					{	
						
							err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle, &reply);       
							APP_ERROR_CHECK(err_code);
						
					}
				
				}
  • BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST Read case was made to start pairing process on IOS devices ( Pairing process start only on read request on ios devices and i need to trigg this process)

  • I compared with the nrf51-ble-app-lbs-require-encryption branch of ble_app example, i don't find were i forgot something.

    Problem come from sd_ble_gap_sec_params_reply's arguments. My m_sec_params are initialized as examples and i don't think that's come from m_conn_handle or BLE_GAP_SEC_STATUS_SUCCESS...

    error code : 7 NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7)

  • You don't need to have authorized read and/or write to start pairing. As you can see if you test nrf51-ble-app-lbs with LightBlue, just trying to read one of the characteristics with BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM() is sufficient for iOS to trigger bonding. However, I don't really think this is related to the problem here.

    You don't include the actual parameters you pass here, but are you absolutely certain that you haven't changed any of them?

    There are several checks being done:

    • IO caps has a legal value
    • Minimum key size less than max key size
    • Minimum key size >= 7 and max key size <= 16
    • Timeout == 30 s

    Can you please verify that these are all ok for your case? If you still have problems, can you please supply your complete project, so that I can test it here?

  • error came from sec_param init.., wrong io caps,

    #define SEC_PARAM_TIMEOUT 30 /< Timeout for Pairing Request or Security Request (in seconds). */ #define SEC_PARAM_BOND 1 /< Perform bonding. */ #define SEC_PARAM_MITM 0 /< Man In The Middle protection not required. */ #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE /< No I/O capabilities. */ #define SEC_PARAM_OOB 1 /< Out Of Band data not available. */ #define SEC_PARAM_MIN_KEY_SIZE 7 /< Minimum encryption key size. */ #define SEC_PARAM_MAX_KEY_SIZE 16

    Thanks for help

  • Thank you so much! I meet the same problem and find this :DD

Related