Commit 9b332909 authored by Luotao Fu's avatar Luotao Fu

add get/set raw ctrlmode callbacks

Signed-off-by: 's avatarLuotao Fu <l.fu@pengutronix.de>
parent 8c25d8d4
......@@ -28,6 +28,7 @@
#define GET_STATE 1
#define GET_RESTART_MS 2
#define GET_BITTIMING 3
#define GET_CTRLMODE 4
int if_down(int fd, const char *name);
int if_up(int fd, const char *name);
......@@ -35,9 +36,11 @@ int if_up(int fd, const char *name);
int set_restart(const char *name);
int set_bitrate(const char *name, __u32 bitrate);
int set_restart_ms(const char *name, __u32 restart_ms);
int set_ctrlmode(const char *name, __u32 mode, __u32 flags);
int get_state(const char *name);
__u32 get_restart_ms(const char *name);
int get_bittiming(const char *name, struct can_bittiming *bt);
int get_ctrlmode(const char *name, struct can_ctrlmode *cm);
#endif
......@@ -54,7 +54,7 @@ struct req_info {
__u32 restart_ms;
__u32 bitrate;
__u32 ctrlmode;
__u32 flags;
__u32 ctrlflags;
};
static void
......@@ -355,6 +355,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
} else
fprintf(stderr, "no bittiming data found\n");
break;
case GET_CTRLMODE:
if (can_attr[IFLA_CAN_CTRLMODE]) {
memcpy(res,
RTA_DATA(can_attr[IFLA_CAN_CTRLMODE]),
sizeof(struct can_ctrlmode));
ret = 0;
} else
fprintf(stderr, "no ctrlmode data found\n");
break;
default:
fprintf(stderr, "unknown acquire mode\n");
......@@ -429,7 +439,7 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name,
if (req_info->ctrlmode) {
memset(&cm, 0, sizeof(cm));
cm.mask = req_info->ctrlmode;
cm.flags = req_info->flags;
cm.flags = req_info->ctrlflags;
addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm,
sizeof(cm));
}
......@@ -482,15 +492,6 @@ int if_down(int fd, const char *name)
return do_set_nl_link(fd, IF_DOWN, name, NULL);
}
int set_bitrate(const char *name, __u32 bitrate)
{
struct req_info req_info = {
.bitrate = bitrate,
};
return set_link(name, &req_info);
}
int set_restart(const char *name)
{
int fd;
......@@ -537,6 +538,16 @@ int set_restart_ms(const char *name, __u32 restart_ms)
return set_link(name, &req_info);
}
int set_ctrlmode(const char *name, __u32 mode, __u32 flags)
{
struct req_info req_info = {
.ctrlmode = mode,
.ctrlflags = flags,
};
return set_link(name, &req_info);
}
int get_state(const char *name)
{
int fd;
......@@ -589,3 +600,20 @@ int get_bittiming(const char *name, struct can_bittiming *bt)
close(fd);
return 0;
}
int get_ctrlmode(const char *name, struct can_ctrlmode *cm)
{
int fd;
int err;
fd = open_nl_sock();
if (fd < 0)
return -1;
err = do_get_nl_link(fd, GET_CTRLMODE, name, cm);
if (err < 0)
return -1;
close(fd);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment