Skip to content

Fault callback is never invoked #279

@zolnierczyk

Description

@zolnierczyk

Hi PolySync,

I think that I found bug with fault handling mechanism.

Expected behavior

OSCC C api fault_report_callback should be invoked where CAN error frame is received.

Actual behavior

All error frames are ignored.

Steps to reproduce

For example brake module:

  1. Disconnect module from car system but keep CAN connection to oscc part
  2. Power it up
  3. Send enable command
  4. Module send CAN error frames (CAN sniffer show frames)
  5. OSCC C api don't receive any faults

Version info

Source from v1.2.1-niro

Analyze

SocketCAN is initialized by this code:

    struct sigaction sig;
    memset( &sig, 0, sizeof(sig) );
    sigemptyset( &sig.sa_mask );
    sig.sa_flags = SA_RESTART;
    sig.sa_handler = oscc_update_status;
    sigaction( SIGIO, &sig, NULL );

    int sock = socket( PF_CAN, SOCK_RAW, CAN_RAW );

    if ( sock < 0 )
    {
        printf( "Opening CAN socket failed: %s\n", strerror(errno) );
    }
    else
    {
        result = OSCC_OK;
    }

But from kernel documentation we can read kernel doc

Using CAN_RAW sockets is extensively comparable to the commonly
known access to CAN character devices. To meet the new possibilities
provided by the multi user SocketCAN approach, some reasonable
defaults are set at RAW socket binding time:

  • The filters are set to exactly one filter receiving everything
  • The socket only receives valid data frames (=> no error message frames)
  • The loopback of sent CAN frames is enabled (see chapter 3.2)
  • The socket does not receive its own sent frames (in loopback mode)

So current behavior that api don't get any error frames is valid one from kernel driver point of view. I modify code by adding new header include:

#include <linux/can/raw.h>
#include <linux/can/error.h>

And also after creating socket new option:

can_err_mask_t err_mask = ( CAN_ERR_MASK );
setsockopt(sock, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &err_mask, sizeof(err_mask));

And after this modification I can receive fault code and callback is invoked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions