summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuotao Fu <luotao@alea.(none)>2010-02-14 18:12:01 +0100
committerLuotao Fu <luotao@alea.(none)>2010-02-14 18:12:01 +0100
commit298e6efc3e06251bd39f8a2afb7eb272c0fd9772 (patch)
treeaea1e4f94f64d6ea3f455fb2d9643872b162eee4
parent118358336eceb0ad4ab4e72751af09964eb0a6ef (diff)
downloadlibsocketcan-298e6efc3e06251bd39f8a2afb7eb272c0fd9772.tar.gz
libsocketcan-298e6efc3e06251bd39f8a2afb7eb272c0fd9772.tar.xz
add get error counter call
Signed-off-by: Luotao Fu <luotao@alea.(none)>
-rw-r--r--include/can_netlink.h17
-rw-r--r--src/libsocketcan.c38
2 files changed, 52 insertions, 3 deletions
diff --git a/include/can_netlink.h b/include/can_netlink.h
index 9ecbb78..31cfa6a 100644
--- a/include/can_netlink.h
+++ b/include/can_netlink.h
@@ -70,6 +70,14 @@ enum can_state {
};
/*
+ * CAN bus error counters
+ */
+struct can_berr_counter {
+ __u16 txerr;
+ __u16 rxerr;
+};
+
+/*
* CAN controller mode
*/
struct can_ctrlmode {
@@ -77,9 +85,11 @@ struct can_ctrlmode {
__u32 flags;
};
-#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */
-#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */
-#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */
+#define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */
+#define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */
+#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */
+#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */
+#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */
/*
* CAN device statistics
@@ -105,6 +115,7 @@ enum {
IFLA_CAN_CTRLMODE,
IFLA_CAN_RESTART_MS,
IFLA_CAN_RESTART,
+ IFLA_CAN_BERR_COUNTER,
__IFLA_CAN_MAX
};
diff --git a/src/libsocketcan.c b/src/libsocketcan.c
index 417abcc..2ac3f2a 100644
--- a/src/libsocketcan.c
+++ b/src/libsocketcan.c
@@ -52,6 +52,7 @@
#define GET_CTRLMODE 4
#define GET_CLOCK 5
#define GET_BITTIMING_CONST 6
+#define GET_BERR_COUNTER 7
struct get_req {
struct nlmsghdr n;
@@ -456,6 +457,17 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
fprintf(stderr, "no bittiming_const data found\n");
break;
+ case GET_BERR_COUNTER:
+ if (can_attr[IFLA_CAN_BERR_COUNTER]) {
+ memcpy(res,
+ RTA_DATA(can_attr[IFLA_CAN_BERR_COUNTER]),
+ sizeof(struct can_berr_counter));
+ ret = 0;
+ } else
+ fprintf(stderr, "no berr_counter data found\n");
+
+ break;
+
default:
fprintf(stderr, "unknown acquire mode\n");
}
@@ -1083,3 +1095,29 @@ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc)
return get_link(name, GET_BITTIMING_CONST, btc);
}
+
+/**
+ * @ingroup extern
+ * can_get_berr_counter - get the tx/rx error counter.
+ *
+ * @param name name of the can device. This is the netdev name, as ifconfig -a shows
+ * in your system. usually it contains prefix "can" and the numer of the can
+ * line. e.g. "can0"
+ * @param bc pointer to the error counter struct..
+ *
+ * This one gets the current rx/tx error counter from the hardware.
+ *
+ * @code
+ * struct can_berr_counter {
+ * __u16 txerr;
+ * __u16 rxerr;
+ * };
+ * @endcode
+ *
+ * @return 0 if success
+ * @return -1 if failed
+ */
+int can_get_berr_counter(const char *name, struct can_berr_counter *bc)
+{
+ return get_link(name, GET_BERR_COUNTER, bc);
+}