[PATCH] can: add helper function to get CAN bus state

Benedikt Spranger b.spranger at linutronix.de
Fri Jan 25 10:50:32 EST 2013


Add a helper function to get the CAN bus state.

Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
---
 include/netlink/route/link/can.h |    1 +
 lib/route/link/can.c             |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/netlink/route/link/can.h b/include/netlink/route/link/can.h
index 90296f1..61c9f47 100644
--- a/include/netlink/route/link/can.h
+++ b/include/netlink/route/link/can.h
@@ -27,6 +27,7 @@ extern int rtnl_link_can_str2ctrlmode(const char *);
 
 extern int rtnl_link_can_restart(struct rtnl_link *);
 extern int rtnl_link_can_freq(struct rtnl_link *, uint32_t *);
+extern int rtnl_link_can_state(struct rtnl_link *, uint32_t *);
 
 extern int rtnl_link_can_berr_rx(struct rtnl_link *);
 extern int rtnl_link_can_berr_tx(struct rtnl_link *);
diff --git a/lib/route/link/can.c b/lib/route/link/can.c
index 76bfa1a..307dec0 100644
--- a/lib/route/link/can.c
+++ b/lib/route/link/can.c
@@ -405,6 +405,25 @@ int rtnl_link_can_freq(struct rtnl_link *link, uint32_t *freq)
 }
 
 /**
+ * Get CAN state
+ * @arg link            Link object
+ * @arg state		CAN bus state
+ * @return 0 on success or a negative error code
+ */
+int rtnl_link_can_state(struct rtnl_link *link, uint32_t *state)
+{
+	struct can_info *ci = link->l_info;
+
+	IS_CAN_LINK_ASSERT(link);
+	if (!state)
+		return -NLE_INVAL;
+
+	*state = ci->ci_state;
+
+	return 0;
+}
+
+/**
  * Get CAN RX bus error count
  * @arg link            Link object
  *
-- 
1.7.10.4




More information about the libnl mailing list