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

Fatal error when more than 20 bytes write to a custom characteristic from nRF Connect android app.

Hi,

I know that the BLE protocol allows to write up to 20 bytes size packets, I have also set max length to 20 bytes in my custom characteristics.

But when I am trying to send more than 20 bytes packets from android app to my application(on nRF52), I am getting Fatal error.

I don't expect that my application crashed when someone  send more than 20 bytes.

Call stack shown below after Fatal error:

I am using  SDK17 and nRF52840 DK board.

Parents
  • Hi,

    The application should not crash even if the client is sending a packet that is too long. From the stack trace you posted, it appears that the error is occuring in your ble_evt_handler() (likely means an error code passed to one of the APP_ERROR_CHECK() macros). Are you able to tell which one of the functions inside this handler returned the error code?

    Do you have logging enabled in your project? In that case, please make sure the "Debug" configuration is selected as that will make the fault handler produce more detailed crash log.

  • Hi,

    Yes It is sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &auth_reply) return the error in ble_evt_handler().

    case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
    {
        ble_gatts_evt_rw_authorize_request_t req;
        ble_gatts_rw_authorize_reply_params_t auth_reply;

       req = p_ble_evt->evt.gatts_evt.params.authorize_request;

      if (req.type != BLE_GATTS_AUTHORIZE_TYPE_INVALID)
     {
       if ((req.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ) ||
       (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
       (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL))
      {
      if (req.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
      {
        auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
      }
      else
     {
       auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
     }
      auth_reply.params.write.gatt_status = APP_FEATURE_NOT_SUPPORTED;
      err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,&auth_reply);
      APP_ERROR_CHECK(err_code);
      }
    }
    } break;

    I print the log by comment out APP_ERROR_CHECK()-

    00> <info> app: req.type=2,req.request.write.op=4
    00> <info> app: err_code=0
    00> <info> app: req.type=2,req.request.write.op=5
    00> <info> app: err_code=7

Reply
  • Hi,

    Yes It is sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &auth_reply) return the error in ble_evt_handler().

    case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
    {
        ble_gatts_evt_rw_authorize_request_t req;
        ble_gatts_rw_authorize_reply_params_t auth_reply;

       req = p_ble_evt->evt.gatts_evt.params.authorize_request;

      if (req.type != BLE_GATTS_AUTHORIZE_TYPE_INVALID)
     {
       if ((req.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ) ||
       (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
       (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL))
      {
      if (req.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
      {
        auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
      }
      else
     {
       auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
     }
      auth_reply.params.write.gatt_status = APP_FEATURE_NOT_SUPPORTED;
      err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,&auth_reply);
      APP_ERROR_CHECK(err_code);
      }
    }
    } break;

    I print the log by comment out APP_ERROR_CHECK()-

    00> <info> app: req.type=2,req.request.write.op=4
    00> <info> app: err_code=0
    00> <info> app: req.type=2,req.request.write.op=5
    00> <info> app: err_code=7

Children
Related