3
* (C) 2009 Luotao Fu <l.fu@pengutronix.de>
5
* This library is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU Lesser General Public License as published by the Free
7
* Software Foundation; either version 2.1 of the License, or (at your option)
10
* This library is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library; if not, write to the Free Software Foundation, Inc.,
17
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
#include <linux/rtnetlink.h>
34
#include <linux/netlink.h>
36
#include <libsocketcan.h>
38
#define parse_rtattr_nested(tb, max, rta) \
39
(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
41
#define NLMSG_TAIL(nmsg) \
42
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
44
#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1)
50
#define GET_RESTART_MS 2
51
#define GET_BITTIMING 3
52
#define GET_CTRLMODE 4
54
#define GET_BITTIMING_CONST 6
55
#define GET_BERR_COUNTER 7
71
__u8 disable_autorestart;
73
struct can_ctrlmode *ctrlmode;
74
struct can_bittiming *bittiming;
78
parse_rtattr(struct rtattr **tb, int max, struct rtattr *rta, int len)
80
memset(tb, 0, sizeof(*tb) * max);
81
while (RTA_OK(rta, len)) {
82
if (rta->rta_type <= max) {
83
tb[rta->rta_type] = rta;
86
rta = RTA_NEXT(rta, len);
90
static int addattr32(struct nlmsghdr *n, size_t maxlen, int type, __u32 data)
92
int len = RTA_LENGTH(4);
95
if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
97
"addattr32: Error! max allowed bound %zu exceeded\n",
103
rta->rta_type = type;
105
memcpy(RTA_DATA(rta), &data, 4);
106
n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
111
static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type,
112
const void *data, int alen)
114
int len = RTA_LENGTH(alen);
117
if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
119
"addattr_l ERROR: message exceeded bound of %zu\n",
125
rta->rta_type = type;
127
memcpy(RTA_DATA(rta), data, alen);
128
n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
135
* @brief send_mod_request - send a linkinfo modification request
137
* @param fd decriptor to a priorly opened netlink socket
138
* @param n netlink message containing the request
140
* sends a request to setup the the linkinfo to netlink layer and awaits the
143
* @return 0 if success
144
* @return negativ if failed
146
static int send_mod_request(int fd, struct nlmsghdr *n)
149
struct sockaddr_nl nladdr;
153
.iov_base = (void *)n,
154
.iov_len = n->nlmsg_len
156
struct msghdr msg = {
158
.msg_namelen = sizeof(nladdr),
164
memset(&nladdr, 0, sizeof(nladdr));
166
nladdr.nl_family = AF_NETLINK;
168
nladdr.nl_groups = 0;
171
n->nlmsg_flags |= NLM_F_ACK;
173
status = sendmsg(fd, &msg, 0);
176
perror("Cannot talk to rtnetlink");
182
iov.iov_len = sizeof(buf);
183
status = recvmsg(fd, &msg, 0);
184
for (h = (struct nlmsghdr *)buf; (size_t) status >= sizeof(*h);) {
185
int len = h->nlmsg_len;
186
int l = len - sizeof(*h);
187
if (l < 0 || len > status) {
188
if (msg.msg_flags & MSG_TRUNC) {
189
fprintf(stderr, "Truncated message\n");
193
"!!!malformed message: len=%d\n", len);
197
if (h->nlmsg_type == NLMSG_ERROR) {
198
struct nlmsgerr *err =
199
(struct nlmsgerr *)NLMSG_DATA(h);
200
if ((size_t) l < sizeof(struct nlmsgerr)) {
201
fprintf(stderr, "ERROR truncated\n");
207
perror("RTNETLINK answers");
211
status -= NLMSG_ALIGN(len);
212
h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
221
* @brief send_dump_request - send a dump linkinfo request
223
* @param fd decriptor to a priorly opened netlink socket
224
* @param family rt_gen message family
225
* @param type netlink message header type
227
* @return 0 if success
228
* @return negativ if failed
230
static int send_dump_request(int fd, int family, int type)
234
memset(&req, 0, sizeof(req));
236
req.n.nlmsg_len = sizeof(req);
237
req.n.nlmsg_type = type;
238
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH;
242
req.g.rtgen_family = family;
244
return send(fd, (void *)&req, sizeof(req), 0);
249
* @brief open_nl_sock - open a netlink socket
251
* opens a netlink socket and returns the socket descriptor
253
* @return 0 if success
254
* @return negativ if failed
256
static int open_nl_sock()
261
unsigned int addr_len;
262
struct sockaddr_nl local;
264
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
266
perror("Cannot open netlink socket");
270
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&sndbuf, sizeof(sndbuf));
272
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *)&rcvbuf, sizeof(rcvbuf));
274
memset(&local, 0, sizeof(local));
275
local.nl_family = AF_NETLINK;
278
if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
279
perror("Cannot bind netlink socket");
283
addr_len = sizeof(local);
284
if (getsockname(fd, (struct sockaddr *)&local, &addr_len) < 0) {
285
perror("Cannot getsockname");
288
if (addr_len != sizeof(local)) {
289
fprintf(stderr, "Wrong address length %u\n", addr_len);
292
if (local.nl_family != AF_NETLINK) {
293
fprintf(stderr, "Wrong address family %d\n", local.nl_family);
301
* @brief do_get_nl_link - get linkinfo
303
* @param fd socket file descriptor to a priorly opened netlink socket
304
* @param acquire which parameter we want to get
305
* @param name name of the can device. This is the netdev name, as ifconfig -a
306
* shows in your system. usually it contains prefix "can" and the numer of the
307
* can line. e.g. "can0"
308
* @param res pointer to store the result
310
* This callback send a dump request into the netlink layer, collect the packet
311
* containing the linkinfo and fill the pointer res points to depending on the
312
* acquire mode set in param acquire.
314
* @return 0 if success
315
* @return -1 if failed
318
static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
320
struct sockaddr_nl peer;
323
char nlbuf[1024 * 8];
329
.iov_base = (void *)nlbuf,
330
.iov_len = sizeof(nlbuf),
333
struct msghdr msg = {
334
.msg_name = (void *)&peer,
335
.msg_namelen = sizeof(peer),
338
.msg_control = &cbuf,
339
.msg_controllen = sizeof(cbuf),
342
struct nlmsghdr *nl_msg;
345
struct rtattr *linkinfo[IFLA_INFO_MAX + 1];
346
struct rtattr *can_attr[IFLA_CAN_MAX + 1];
348
if (send_dump_request(fd, AF_PACKET, RTM_GETLINK) < 0) {
349
perror("Cannot send dump request");
353
while (!done && (msglen = recvmsg(fd, &msg, 0)) > 0) {
354
size_t u_msglen = (size_t) msglen;
355
/* Check to see if the buffers in msg get truncated */
356
if (msg.msg_namelen != sizeof(peer) ||
357
(msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) {
358
fprintf(stderr, "Uhoh... truncated message.\n");
362
for (nl_msg = (struct nlmsghdr *)nlbuf;
363
NLMSG_OK(nl_msg, u_msglen);
364
nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) {
365
int type = nl_msg->nlmsg_type;
368
if (type == NLMSG_DONE) {
372
if (type != RTM_NEWLINK)
375
struct ifinfomsg *ifi = NLMSG_DATA(nl_msg);
376
struct rtattr *tb[IFLA_MAX + 1];
379
nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
380
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
383
((char *)RTA_DATA(tb[IFLA_IFNAME]), name) != 0)
386
if (tb[IFLA_LINKINFO])
387
parse_rtattr_nested(linkinfo,
388
IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
392
if (acquire == GET_XSTATS) {
393
if (!linkinfo[IFLA_INFO_XSTATS])
394
fprintf(stderr, "no can statistics found\n");
396
memcpy(res, RTA_DATA(linkinfo[IFLA_INFO_XSTATS]),
397
sizeof(struct can_device_stats));
403
if (!linkinfo[IFLA_INFO_DATA]) {
404
fprintf(stderr, "no link data found\n");
408
parse_rtattr_nested(can_attr, IFLA_CAN_MAX,
409
linkinfo[IFLA_INFO_DATA]);
413
if (can_attr[IFLA_CAN_STATE]) {
414
*((int *)res) = *((__u32 *)
419
fprintf(stderr, "no state data found\n");
424
if (can_attr[IFLA_CAN_RESTART_MS]) {
425
*((__u32 *) res) = *((__u32 *)
427
[IFLA_CAN_RESTART_MS]));
430
fprintf(stderr, "no restart_ms data found\n");
434
if (can_attr[IFLA_CAN_BITTIMING]) {
436
RTA_DATA(can_attr[IFLA_CAN_BITTIMING]),
437
sizeof(struct can_bittiming));
440
fprintf(stderr, "no bittiming data found\n");
444
if (can_attr[IFLA_CAN_CTRLMODE]) {
446
RTA_DATA(can_attr[IFLA_CAN_CTRLMODE]),
447
sizeof(struct can_ctrlmode));
450
fprintf(stderr, "no ctrlmode data found\n");
454
if (can_attr[IFLA_CAN_CLOCK]) {
456
RTA_DATA(can_attr[IFLA_CAN_CLOCK]),
457
sizeof(struct can_clock));
461
"no clock parameter data found\n");
464
case GET_BITTIMING_CONST:
465
if (can_attr[IFLA_CAN_BITTIMING_CONST]) {
467
RTA_DATA(can_attr[IFLA_CAN_BITTIMING_CONST]),
468
sizeof(struct can_bittiming_const));
471
fprintf(stderr, "no bittiming_const data found\n");
474
case GET_BERR_COUNTER:
475
if (can_attr[IFLA_CAN_BERR_COUNTER]) {
477
RTA_DATA(can_attr[IFLA_CAN_BERR_COUNTER]),
478
sizeof(struct can_berr_counter));
481
fprintf(stderr, "no berr_counter data found\n");
486
fprintf(stderr, "unknown acquire mode\n");
496
* @brief get_link - get linkinfo
498
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
499
* in your system. usually it contains prefix "can" and the numer of the can
501
* @param acquire which parameter we want to get
502
* @param res pointer to store the result
504
* This is a wrapper for do_get_nl_link
506
* @return 0 if success
507
* @return -1 if failed
509
static int get_link(const char *name, __u8 acquire, void *res)
517
err = do_get_nl_link(fd, acquire, name, res);
526
* @brief do_set_nl_link - setup linkinfo
528
* @param fd socket file descriptor to a priorly opened netlink socket
529
* @param if_state state of the interface we want to put the device into. this
530
* parameter is only set if you want to use the callback to driver up/down the
532
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
533
* in your system. usually it contains prefix "can" and the numer of the can
535
* @param req_info request parameters
537
* This callback can do two different tasks:
538
* - bring up/down the interface
539
* - set up a netlink packet with request, as set up in req_info
540
* Which task this callback will do depends on which parameters are set.
542
* @return 0 if success
543
* @return -1 if failed
545
static int do_set_nl_link(int fd, __u8 if_state, const char *name,
546
struct req_info *req_info)
550
const char *type = "can";
552
memset(&req, 0, sizeof(req));
554
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
555
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
556
req.n.nlmsg_type = RTM_NEWLINK;
557
req.i.ifi_family = 0;
559
req.i.ifi_index = if_nametoindex(name);
560
if (req.i.ifi_index == 0) {
561
fprintf(stderr, "Cannot find device \"%s\"\n", name);
568
req.i.ifi_change |= IFF_UP;
569
req.i.ifi_flags &= ~IFF_UP;
572
req.i.ifi_change |= IFF_UP;
573
req.i.ifi_flags |= IFF_UP;
576
fprintf(stderr, "unknown state\n");
581
if (req_info != NULL) {
582
/* setup linkinfo section */
583
struct rtattr *linkinfo = NLMSG_TAIL(&req.n);
584
addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
585
addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type,
587
/* setup data section */
588
struct rtattr *data = NLMSG_TAIL(&req.n);
589
addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0);
591
if (req_info->restart_ms > 0 || req_info->disable_autorestart)
592
addattr32(&req.n, 1024, IFLA_CAN_RESTART_MS,
593
req_info->restart_ms);
595
if (req_info->restart)
596
addattr32(&req.n, 1024, IFLA_CAN_RESTART, 1);
598
if (req_info->bittiming != NULL) {
599
addattr_l(&req.n, 1024, IFLA_CAN_BITTIMING,
601
sizeof(struct can_bittiming));
604
if (req_info->ctrlmode != NULL) {
605
addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE,
607
sizeof(struct can_ctrlmode));
610
/* mark end of data section */
611
data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data;
613
/* mark end of link info section */
615
(void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;
618
return send_mod_request(fd, &req.n);
623
* @brief set_link - open a netlink socket and setup linkinfo
625
* @param name name of the can device. This is the netdev name, as ifconfig -a
626
* shows in your system. usually it contains prefix "can" and the numer of the
627
* can line. e.g. "can0"
628
* @param if_state state of the interface we want to put the device into. this
629
* parameter is only set if you want to use the callback to driver up/down the
631
* @param req_info request parameters
633
* This is a wrapper for do_set_nl_link. It opens a netlink socket and sends
636
* @return 0 if success
637
* @return -1 if failed
639
static int set_link(const char *name, __u8 if_state, struct req_info *req_info)
647
err = do_set_nl_link(fd, if_state, name, req_info);
655
* can_do_start - start the can interface
656
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
657
* in your system. usually it contains prefix "can" and the numer of the can
660
* This starts the can interface with the given name. It simply changes the if
661
* state of the interface to up. All initialisation works will be done in
662
* kernel. The if state can also be queried by a simple ifconfig.
664
* @return 0 if success
665
* @return -1 if failed
667
int can_do_start(const char *name)
669
return set_link(name, IF_UP, NULL);
674
* can_do_stop - stop the can interface
675
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
676
* in your system. usually it contains prefix "can" and the numer of the can
679
* This stops the can interface with the given name. It simply changes the if
680
* state of the interface to down. Any running communication would be stopped.
682
* @return 0 if success
683
* @return -1 if failed
685
int can_do_stop(const char *name)
687
return set_link(name, IF_DOWN, NULL);
692
* can_do_restart - restart the can interface
693
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
694
* in your system. usually it contains prefix "can" and the numer of the can
697
* This triggers the start mode of the can device.
700
* - restart mode can only be triggerd if the device is in BUS_OFF and the auto
701
* restart not turned on (restart_ms == 0)
703
* @return 0 if success
704
* @return -1 if failed
706
int can_do_restart(const char *name)
711
/* first we check if we can restart the device at all */
712
if ((can_get_state(name, &state)) < 0) {
713
fprintf(stderr, "cannot get bustate, "
714
"something is seriously wrong\n");
716
} else if (state != CAN_STATE_BUS_OFF) {
718
"Device is not in BUS_OFF," " no use to restart\n");
722
if ((can_get_restart_ms(name, &restart_ms)) < 0) {
723
fprintf(stderr, "cannot get restart_ms, "
724
"something is seriously wrong\n");
726
} else if (restart_ms > 0) {
728
"auto restart with %ums interval is turned on,"
729
" no use to restart\n", restart_ms);
733
struct req_info req_info = {
737
return set_link(name, 0, &req_info);
742
* can_set_restart_ms - set interval of auto restart.
744
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
745
* in your system. usually it contains prefix "can" and the numer of the can
747
* @param restart_ms interval of auto restart in milliseconds
749
* This sets how often the device shall automatically restart the interface in
750
* case that a bus_off is detected.
752
* @return 0 if success
753
* @return -1 if failed
755
int can_set_restart_ms(const char *name, __u32 restart_ms)
757
struct req_info req_info = {
758
.restart_ms = restart_ms,
762
req_info.disable_autorestart = 1;
764
return set_link(name, 0, &req_info);
769
* can_set_ctrlmode - setup the control mode.
771
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
772
* in your system. usually it contains prefix "can" and the numer of the can
775
* @param cm pointer of a can_ctrlmode struct
777
* This sets the control mode of the can device. There're currently three
778
* different control modes:
783
* You have to define the control mode struct yourself. a can_ctrlmode struct
787
* struct can_ctrlmode {
793
* You can use mask to select modes you want to control and flags to determine
794
* if you want to turn the selected mode(s) on or off. Every control mode is
795
* mapped to an own macro
798
* #define CAN_CTRLMODE_LOOPBACK 0x1
799
* #define CAN_CTRLMODE_LISTENONLY 0x2
800
* #define CAN_CTRLMODE_3_SAMPLES 0x4
803
* e.g. the following pseudocode
806
* struct can_ctrlmode cm;
807
* memset(&cm, 0, sizeof(cm));
808
* cm.mask = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY;
809
* cm.flags = CAN_CTRLMODE_LOOPBACK;
810
* can_set_ctrlmode(candev, &cm);
813
* will turn the loopback mode on and listenonly mode off.
815
* @return 0 if success
816
* @return -1 if failed
819
int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm)
821
struct req_info req_info = {
825
return set_link(name, 0, &req_info);
830
* can_set_bittiming - setup the bittiming.
832
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
833
* in your system. usually it contains prefix "can" and the numer of the can
835
* @param bt pointer to a can_bittiming struct
837
* This sets the bittiming of the can device. This is for advantage usage. In
838
* normal cases you should use can_set_bitrate to simply define the bitrate and
839
* let the driver automatically calculate the bittiming. You will only need this
840
* function if you wish to define the bittiming in expert mode with fully
841
* manually defined timing values.
842
* You have to define the bittiming struct yourself. a can_bittiming struct
846
* struct can_bittiming {
848
* __u32 sample_point;
858
* to define a customized bittiming, you have to define tq, prop_seq,
859
* phase_seg1, phase_seg2 and sjw. See http://www.can-cia.org/index.php?id=88
860
* for more information about bittiming and synchronizations on can bus.
862
* @return 0 if success
863
* @return -1 if failed
866
int can_set_bittiming(const char *name, struct can_bittiming *bt)
868
struct req_info req_info = {
872
return set_link(name, 0, &req_info);
877
* can_set_bitrate - setup the bitrate.
879
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
880
* in your system. usually it contains prefix "can" and the numer of the can
882
* @param bitrate bitrate of the can bus
884
* This is the recommended way to setup the bus bit timing. You only have to
885
* give a bitrate value here. The exact bit timing will be calculated
886
* automatically. To use this function, make sure that CONFIG_CAN_CALC_BITTIMING
887
* is set to y in your kernel configuration. bitrate can be a value between
888
* 1000(1kbit/s) and 1000000(1000kbit/s).
890
* @return 0 if success
891
* @return -1 if failed
894
int can_set_bitrate(const char *name, __u32 bitrate)
896
struct can_bittiming bt;
898
memset(&bt, 0, sizeof(bt));
899
bt.bitrate = bitrate;
901
return can_set_bittiming(name, &bt);
906
* can_set_bitrate_samplepoint - setup the bitrate.
908
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
909
* in your system. usually it contains prefix "can" and the numer of the can
911
* @param bitrate bitrate of the can bus
912
* @param sample_point sample point value
914
* This one is similar to can_set_bitrate, only you can additionally set up the
915
* time point for sampling (sample point) customly instead of using the
916
* CIA recommended value. sample_point can be a value between 0 and 999.
918
* @return 0 if success
919
* @return -1 if failed
921
int can_set_bitrate_samplepoint(const char *name, __u32 bitrate,
924
struct can_bittiming bt;
926
memset(&bt, 0, sizeof(bt));
927
bt.bitrate = bitrate;
928
bt.sample_point = sample_point;
930
return can_set_bittiming(name, &bt);
935
* can_get_state - get the current state of the device
937
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
938
* in your system. usually it contains prefix "can" and the numer of the can
940
* @param state pointer to store the state
942
* This one stores the current state of the can interface into the given
943
* pointer. Valid states are:
944
* - CAN_STATE_ERROR_ACTIVE
945
* - CAN_STATE_ERROR_WARNING
946
* - CAN_STATE_ERROR_PASSIVE
947
* - CAN_STATE_BUS_OFF
948
* - CAN_STATE_STOPPED
949
* - CAN_STATE_SLEEPING
951
* The first four states is determined by the value of RX/TX error counter.
952
* Please see relevant can specification for more information about this. A
953
* device in STATE_STOPPED is an inactive device. STATE_SLEEPING is not
954
* implemented on all devices.
956
* @return 0 if success
957
* @return -1 if failed
960
int can_get_state(const char *name, int *state)
962
return get_link(name, GET_STATE, state);
967
* can_get_restart_ms - get the current interval of auto restarting.
969
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
970
* in your system. usually it contains prefix "can" and the numer of the can
972
* @param restart_ms pointer to store the value.
974
* This one stores the current interval of auto restarting into the given
977
* The socketcan framework can automatically restart a device if it is in
978
* bus_off in a given interval. This function gets this value in milliseconds.
979
* restart_ms == 0 means that autorestarting is turned off.
981
* @return 0 if success
982
* @return -1 if failed
985
int can_get_restart_ms(const char *name, __u32 *restart_ms)
987
return get_link(name, GET_RESTART_MS, restart_ms);
992
* can_get_bittiming - get the current bittimnig configuration.
994
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
995
* in your system. usually it contains prefix "can" and the numer of the can
997
* @param bt pointer to the bittiming struct.
999
* This one stores the current bittiming configuration.
1001
* Please see can_set_bittiming for more information about bit timing.
1003
* @return 0 if success
1004
* @return -1 if failed
1006
int can_get_bittiming(const char *name, struct can_bittiming *bt)
1008
return get_link(name, GET_BITTIMING, bt);
1013
* can_get_ctrlmode - get the current control mode.
1015
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
1016
* in your system. usually it contains prefix "can" and the numer of the can
1018
* @param cm pointer to the ctrlmode struct.
1020
* This one stores the current control mode configuration.
1022
* Please see can_set_ctrlmode for more information about control modes.
1024
* @return 0 if success
1025
* @return -1 if failed
1028
int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm)
1030
return get_link(name, GET_CTRLMODE, cm);
1035
* can_get_clock - get the current clock struct.
1037
* @param name: name of the can device. This is the netdev name, as ifconfig -a shows
1038
* in your system. usually it contains prefix "can" and the numer of the can
1040
* @param clock pointer to the clock struct.
1042
* This one stores the current clock configuration. At the time of writing the
1043
* can_clock struct only contains information about the clock frequecy. This
1044
* information is e.g. essential while setting up the bit timing.
1046
* @return 0 if success
1047
* @return -1 if failed
1049
int can_get_clock(const char *name, struct can_clock *clock)
1051
return get_link(name, GET_CLOCK, clock);
1056
* can_get_bittiming_const - get the current bittimnig constant.
1058
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
1059
* in your system. usually it contains prefix "can" and the numer of the can
1061
* @param btc pointer to the bittiming constant struct.
1063
* This one stores the hardware dependent bittiming constant. The
1064
* can_bittiming_const struct consists:
1067
* struct can_bittiming_const {
1080
* The information in this struct is used to calculate the bus bit timing
1083
* @return 0 if success
1084
* @return -1 if failed
1086
int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc)
1088
return get_link(name, GET_BITTIMING_CONST, btc);
1094
* can_get_berr_counter - get the tx/rx error counter.
1096
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
1097
* in your system. usually it contains prefix "can" and the numer of the can
1099
* @param bc pointer to the error counter struct..
1101
* This one gets the current rx/tx error counter from the hardware.
1104
* struct can_berr_counter {
1110
* @return 0 if success
1111
* @return -1 if failed
1113
int can_get_berr_counter(const char *name, struct can_berr_counter *bc)
1115
return get_link(name, GET_BERR_COUNTER, bc);
1120
* can_get_device_stats - get the can_device_stats.
1122
* @param name name of the can device. This is the netdev name, as ifconfig -a shows
1123
* in your system. usually it contains prefix "can" and the numer of the can
1125
* @param bc pointer to the error counter struct..
1127
* This one gets the current can_device_stats.
1129
* Please see struct can_device_stats for more information.
1131
* @return 0 if success
1132
* @return -1 if failed
1134
int can_get_device_stats(const char *name, struct can_device_stats *cds)
1136
return get_link(name, GET_XSTATS, cds);