22 #ifndef LELY_IO2_INTERN_LINUX_CAN_ATTR_H_ 23 #define LELY_IO2_INTERN_LINUX_CAN_ATTR_H_ 36 #if !LELY_NO_CANFD && !defined(CANFD_MTU) 37 #error CAN FD not supported. 39 #define can_state can_state_ 40 #define CAN_STATE_STOPPED CAN_STATE_STOPPED_ 41 #define CAN_STATE_SLEEPING CAN_STATE_SLEEPING_ 42 #include <linux/can/netlink.h> 43 #undef CAN_STATE_SLEEPING 44 #undef CAN_STATE_STOPPED 46 #include <linux/if_arp.h> 60 #define IO_CAN_ATTR_INIT \ 62 CAN_STATE_ACTIVE, 0, 0 \ 65 #define IO_CAN_ATTR_INIT \ 67 CAN_STATE_ACTIVE, 0, 0, 0 \ 75 static int io_can_attr_get(
struct io_can_attr *attr,
unsigned int ifindex);
76 static int io_can_attr_parse(
struct nlmsghdr *nlh,
size_t len,
void *arg);
79 io_can_attr_get(
struct io_can_attr *attr,
unsigned int ifindex)
84 if (rtnl_open(&rth) == -1) {
89 if (rtnl_send_getlink_request(&rth, AF_UNSPEC, ARPHRD_CAN, ifindex)
92 goto error_rtnl_send_getlink_request;
95 if (rtnl_recv_type(&rth, RTM_NEWLINK, &io_can_attr_parse, attr) == -1) {
97 goto error_rtnl_recv_type;
103 error_rtnl_recv_type:
104 error_rtnl_send_getlink_request:
112 io_can_attr_parse(
struct nlmsghdr *nlh,
size_t len,
void *arg)
115 assert(NLMSG_OK(nlh, len));
116 assert(nlh->nlmsg_type == RTM_NEWLINK);
121 struct ifinfomsg *ifi = NLMSG_DATA(nlh);
122 if (ifi->ifi_type != ARPHRD_CAN) {
129 rta_find(IFLA_RTA(ifi), IFLA_PAYLOAD(nlh), IFLA_MTU);
130 if (mtu && RTA_PAYLOAD(mtu) >=
sizeof(
unsigned int)) {
131 unsigned int *data = RTA_DATA(mtu);
132 if (*data == CANFD_MTU)
139 struct rtattr *linkinfo = rta_find(
140 IFLA_RTA(ifi), IFLA_PAYLOAD(nlh), IFLA_LINKINFO);
146 struct rtattr *info_data = rta_find(RTA_DATA(linkinfo),
147 RTA_PAYLOAD(linkinfo), IFLA_INFO_DATA);
151 rta = rta_find(RTA_DATA(info_data), RTA_PAYLOAD(info_data),
153 if (rta && RTA_PAYLOAD(rta) >=
sizeof(
int)) {
154 int *data = RTA_DATA(rta);
156 case CAN_STATE_ERROR_ACTIVE:
157 case CAN_STATE_ERROR_WARNING:
160 case CAN_STATE_ERROR_PASSIVE:
163 case CAN_STATE_BUS_OFF:
166 case CAN_STATE_STOPPED_:
169 case CAN_STATE_SLEEPING_:
176 rta = rta_find(RTA_DATA(info_data), RTA_PAYLOAD(info_data),
178 if (rta && RTA_PAYLOAD(rta) >=
sizeof(
struct can_ctrlmode)) {
179 struct can_ctrlmode *data = RTA_DATA(rta);
180 if (data->flags & CAN_CTRLMODE_FD)
187 rta = rta_find(RTA_DATA(info_data), RTA_PAYLOAD(info_data),
189 if (rta && RTA_PAYLOAD(rta) >=
sizeof(
struct can_bittiming)) {
190 struct can_bittiming *data = RTA_DATA(rta);
191 attr->nominal = data->bitrate;
195 rta = rta_find(RTA_DATA(info_data), RTA_PAYLOAD(info_data),
196 IFLA_CAN_DATA_BITTIMING);
197 if (rta && RTA_PAYLOAD(rta) >=
sizeof(
struct can_bittiming)) {
198 struct can_bittiming *data = RTA_DATA(rta);
199 attr->data = data->bitrate;
213 #endif // !LELY_IO2_INTERN_LINUX_CAN_ATTR_H_ This is the internal header file of the rtnetlink functions.
The device is in sleep mode.
This is the internal header file of the Linux-specific I/O declarations.
FD Format (formerly Extended Data Length) support is enabled.
Bit Rate Switch support is enabled.
This header file is part of the I/O library; it contains the CAN bus declarations for Linux...
This header file is part of the I/O library; it contains the abstract CAN bus interface.
The error passive state (TX/RX error count < 256).
The bus off state (TX/RX error count >= 256).
The error active state (TX/RX error count < 128).