socketcan : support error frame filter
add error mask for CAN_RAW_ERR_FILTER Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
This commit is contained in:
parent
ef3f807f89
commit
b756a7c3a9
@ -106,6 +106,9 @@ struct can_conn_s
|
||||
# endif
|
||||
struct can_filter filters[CONFIG_NET_CAN_RAW_FILTER_MAX];
|
||||
int32_t filter_count;
|
||||
# ifdef CONFIG_NET_CAN_ERRORS
|
||||
can_err_mask_t err_mask;
|
||||
# endif
|
||||
# ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
int32_t tx_deadline;
|
||||
# endif
|
||||
|
@ -141,6 +141,18 @@ int can_getsockopt(FAR struct socket *psock, int level, int option,
|
||||
break;
|
||||
|
||||
case CAN_RAW_ERR_FILTER:
|
||||
#ifdef CONFIG_NET_CAN_ERRORS
|
||||
if (*value_len < sizeof(can_err_mask_t))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
FAR can_err_mask_t *mask = (FAR can_err_mask_t *)value;
|
||||
*mask = conn->err_mask;
|
||||
*value_len = sizeof(can_err_mask_t);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CAN_RAW_LOOPBACK:
|
||||
|
@ -301,6 +301,16 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)
|
||||
static int can_recv_filter(struct can_conn_s *conn, canid_t id)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
#ifdef CONFIG_NET_CAN_ERRORS
|
||||
/* error message frame */
|
||||
|
||||
if (id & CAN_ERR_FLAG)
|
||||
{
|
||||
return id & conn->err_mask ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < conn->filter_count; i++)
|
||||
{
|
||||
if (conn->filters[i].can_id & CAN_INV_FILTER)
|
||||
|
@ -153,6 +153,14 @@ int can_setsockopt(FAR struct socket *psock, int level, int option,
|
||||
break;
|
||||
|
||||
case CAN_RAW_ERR_FILTER:
|
||||
#ifdef CONFIG_NET_CAN_ERRORS
|
||||
if (value_len != sizeof(can_err_mask_t))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
conn->err_mask = *(FAR can_err_mask_t *)value & CAN_ERR_MASK;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CAN_RAW_LOOPBACK:
|
||||
|
Loading…
Reference in New Issue
Block a user