can: sja1000: use common prefix for all sja1000 defines
Subsystems (2)
RFC PATCH v2 1/1 can: sja1000: use common prefix for all sja1000 defines
This is a follow up patch to:
f901b6b can: sja1000: fix define conflict on SH
That patch fixed a define conflict between the SH architecture and the sja1000 driver, by addind a prefix to one macro only. This patch consistently renames the prefix of the SJA1000 controller registers from "REG_" to "SJA1000_".
---
Hello Marc,
to not miss the current net-next window, here's a well formatted patch for my REG_ rename proposal. It renames the formerly register defines from REG_ to SJA1000_ and leaves the content definitions of the registers as-is. This is because of all content definitions would have to be changed in sja1000.h AND include/linux/can/platform/sja1000.h to have a consistent naming scheme.
Regards,
Oliver
ems_pci.c | 6 +- ems_pcmcia.c | 6 +- kvaser_pci.c | 4 - peak_pci.c | 2 peak_pcmcia.c | 8 +-- plx_pci.c | 12 ++--- sja1000.c | 126 +++++++++++++++++++++++++++++----------------------------- sja1000.h | 68 +++++++++++++++---------------- 8 files changed, 117 insertions(+), 115 deletions(-)
drivers/net/can/sja1000/ems_pci.c +3 -3
@@ -168,12 +168,12 @@ static inline int ems_pci_check_chan(const struct sja1000_priv *priv)unsigned char res;/* Make sure SJA1000 is in reset mode */ - priv->write_reg (priv,REG_MOD ,1 ); + priv->write_reg (priv,SJA1000_MOD ,1 ); - priv->write_reg (priv,REG_CDR ,CDR_PELICAN ); + priv->write_reg (priv,SJA1000_CDR ,CDR_PELICAN );/* read reset-values */ - res = priv->read_reg (priv,REG_CDR ); + res = priv->read_reg (priv,SJA1000_CDR );if (res ==CDR_PELICAN )return 1 ;
drivers/net/can/sja1000/ems_pcmcia.c +3 -3
@@ -126,11 +126,11 @@ static irqreturn_t ems_pcmcia_interrupt(int irq, void *dev_id)static inline int ems_pcmcia_check_chan (struct sja1000_priv *priv) {/* Make sure SJA1000 is in reset mode */ -ems_pcmcia_write_reg (priv,REG_MOD ,1 ); -ems_pcmcia_write_reg (priv,REG_CDR ,CDR_PELICAN ); +ems_pcmcia_write_reg (priv,SJA1000_MOD ,1 ); +ems_pcmcia_write_reg (priv,SJA1000_CDR ,CDR_PELICAN );/* read reset-values */ -if (ems_pcmcia_read_reg (priv,REG_CDR ) ==CDR_PELICAN ) +if (ems_pcmcia_read_reg (priv,SJA1000_CDR ) ==CDR_PELICAN )return 1 ;return 0 ;
drivers/net/can/sja1000/kvaser_pci.c +2 -2
@@ -159,9 +159,9 @@ static int number_of_sja1000_chip(void __iomem *base_addr)for (i =0 ; i <MAX_NO_OF_CHANNELS ; i++) {/* reset chip */ iowrite8 (MOD_RM , base_addr + - (i *KVASER_PCI_PORT_BYTES ) +REG_MOD ); + (i *KVASER_PCI_PORT_BYTES ) +SJA1000_MOD ); status =ioread8 (base_addr + - (i *KVASER_PCI_PORT_BYTES ) +REG_MOD ); + (i *KVASER_PCI_PORT_BYTES ) +SJA1000_MOD );/* check reset bit */ if (!(status &MOD_RM ))break ;
drivers/net/can/sja1000/peak_pci.c +1 -1
@@ -402,7 +402,7 @@ static void peak_pciec_write_reg(const struct sja1000_priv *priv,int c = (priv->reg_base - card->reg_base) /PEAK_PCI_CHAN_SIZE ;/* sja1000 register changes control the leds state */ -if (port ==REG_MOD ) +if (port ==SJA1000_MOD )switch (val) {case MOD_RM :/* Reset Mode: set led on */
drivers/net/can/sja1000/peak_pcmcia.c +4 -4
@@ -196,7 +196,7 @@ static void pcan_write_canreg(const struct sja1000_priv *priv, int port, u8 v)int c = (priv->reg_base - card->ioport_addr) /PCC_CHAN_SIZE ;/* sja1000 register changes control the leds state */ -if (port ==REG_MOD ) +if (port ==SJA1000_MOD )switch (v) {case MOD_RM :/* Reset Mode: set led on */
@@ -509,11 +509,11 @@ static void pcan_free_channels(struct pcan_pccard *card)static inline int pcan_channel_present (struct sja1000_priv *priv) {/* make sure SJA1000 is in reset mode */ -pcan_write_canreg (priv,REG_MOD ,1 ); -pcan_write_canreg (priv,REG_CDR ,CDR_PELICAN ); +pcan_write_canreg (priv,SJA1000_MOD ,1 ); +pcan_write_canreg (priv,SJA1000_CDR ,CDR_PELICAN );/* read reset-values */ -if (pcan_read_canreg (priv,REG_CDR ) ==CDR_PELICAN ) +if (pcan_read_canreg (priv,SJA1000_CDR ) ==CDR_PELICAN )return 1 ;return 0 ;
drivers/net/can/sja1000/plx_pci.c +6 -6
@@ -348,20 +348,20 @@ static inline int plx_pci_check_sja1000(const struct sja1000_priv *priv)*/ if ((priv->read_reg (priv,REG_CR ) ®_CR_BASICCAN_INITIAL_MASK ) ==REG_CR_BASICCAN_INITIAL && - (priv->read_reg (priv,SJA1000_REG_SR ) ==REG_SR_BASICCAN_INITIAL ) && - (priv->read_reg (priv,REG_IR ) ==REG_IR_BASICCAN_INITIAL )) + (priv->read_reg (priv,SJA1000_SR ) ==REG_SR_BASICCAN_INITIAL ) && + (priv->read_reg (priv,SJA1000_IR ) ==REG_IR_BASICCAN_INITIAL )) flag =1 ;/* Bring the SJA1000 into the PeliCAN mode*/ - priv->write_reg (priv,REG_CDR ,CDR_PELICAN ); + priv->write_reg (priv,SJA1000_CDR ,CDR_PELICAN );/* * Check registers after reset in the PeliCAN mode. * See states on p. 23 of the Datasheet. */ -if (priv->read_reg (priv,REG_MOD ) ==REG_MOD_PELICAN_INITIAL && - priv->read_reg (priv,SJA1000_REG_SR ) ==REG_SR_PELICAN_INITIAL && - priv->read_reg (priv,REG_IR ) ==REG_IR_PELICAN_INITIAL ) +if (priv->read_reg (priv,SJA1000_MOD ) ==REG_MOD_PELICAN_INITIAL && + priv->read_reg (priv,SJA1000_SR ) ==REG_SR_PELICAN_INITIAL && + priv->read_reg (priv,SJA1000_IR ) ==REG_IR_PELICAN_INITIAL )return flag;return 0 ;
drivers/net/can/sja1000/sja1000.c +64 -62
269 lines not on this page · raw message
drivers/net/can/sja1000/sja1000.h +34 -34
80 lines not on this page · raw message
Marc Kleine-Budde
maintainerQuoted 12 lines · Oliver Hartkopp
This is a follow up patch to:
f901b6b can: sja1000: fix define conflict on SH
That patch fixed a define conflict between the SH architecture and the sja1000 driver, by addind a prefix to one macro only. This patch consistently renames the prefix of the SJA1000 controller registers from "
REG_" to "SJA1000_".Signed-off-by Oliver Hartkopp <[email protected]>---
Quoted 8 lines
Hello Marc,
to not miss the current net-next window, here's a well formatted patch for my
REG_rename proposal. It renames the formerly register defines fromREG_toSJA1000_and leaves the content definitions of the registers as-is. This is because of all content definitions would have to be changed insja1000.hANDinclude/linux/can/platform/sja1000.hto have a consistent naming scheme.
Looks good, I've fixed the indention in drivers/net/can/sja1000/sja1000.h. I'll send a pull request to David soon.
Thanks, Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Is there any way of getting the CAN interfaces list, from any C program?
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program? I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor. And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)
Thanks for your help and best regards,
Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected]
Re: Is there any way of getting the CAN interfaces list, from any C program?
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
Kurt
Quoted 24 lines · Stephane Grosjean
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program?
I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor.
And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)Thanks for your help and best regards,
Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.:
DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected]
----
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534
#ifdef linux
#if linux
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include "enumif.h"
static struct {
int sock;
int seq;
} s = {
.sock = -1,
};__attribute__((destructor))
void enumif_cleanup(void)
{
if (s.sock >= 0) {
close(s.sock);
s.sock = -1;
}
}static int enumif_open(void)
{
int fd;
struct sockaddr_nl local = {
.nl_family = AF_NETLINK,
.nl_groups = 0,
};
if (s.sock >= 0)
return s.sock;
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (fd < 0) {
perror("Cannot open netlink socket");
return -1;
}
if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
perror("Cannot bind netlink socket");
return -1;
}
s.sock = fd;
s.seq = 0;
return fd;
}static inline int enumif_send_request(int sk)
{
struct {
struct nlmsghdr n;
struct rtgenmsg g;
} req = {
.n = {
.nlmsg_len = sizeof(req),
.nlmsg_type = RTM_GETLINK,
.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH,
.nlmsg_pid = 0,
.nlmsg_seq = ++s.seq,
},
.g.rtgen_family = AF_PACKET,
};
return send(sk, &req, sizeof(req), 0);
}static void parse_rtattr(struct rtattr **tb, int max,
struct rtattr *rta, int len)
{
memset(tb, 0, sizeof(*tb) * max);
while (RTA_OK(rta, len)) {
if (rta->rta_type <= max) {
tb[rta->rta_type] = rta;
}
rta = RTA_NEXT(rta, len);
}
}int enumif(void (*fn)(const char *name, int ifindex, int type, int flags, int state))
{
int ret, n_if = 0;
size_t msglen;
struct nlmsghdr *h;
struct sockaddr_nl peer;
char cbuf[128];
char buf[1024 * 16];
struct iovec iov = {
.iov_base = buf,
.iov_len = sizeof(buf),
};
struct msghdr msg = {
.msg_name = (void *)&peer,
.msg_namelen = sizeof(peer),
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = &cbuf,
.msg_controllen = sizeof(cbuf),
.msg_flags = 0,
};
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
if (enumif_open() < 0)
return -1;
if (enumif_send_request(s.sock) < 0) {
perror("Cannot send dump request");
return -1;
}
while (1) {
iov.iov_len = sizeof(buf);
ret = recvmsg(s.sock, &msg, 0);
if (ret < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
perror("netlink receive error");
return -1;
}
if (ret == 0) {
errno = 0;
perror("netlink EOF?");
return -1;
}
msglen = ret;
for (h = (void *)buf; NLMSG_OK(h, msglen);
h = NLMSG_NEXT(h, msglen)) {
if (h->nlmsg_type == NLMSG_DONE)
goto done;
if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
fprintf(stderr,
"ERROR truncated\n");
} else {
errno = -err->error;
perror("RTNETLINK answers");
}
return -1;
}
++n_if;
ifi = NLMSG_DATA(h);
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(h));
fn(RTA_DATA(tb[IFLA_IFNAME]), ifi->ifi_index, ifi->ifi_type,
ifi->ifi_flags,
*(unsigned char *)RTA_DATA(tb[IFLA_OPERSTATE]));
}
}done:
return 0; }
#endif
#endif
#ifndef _enumif_h_
#define _enumif_h_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef linux
#if linux
extern int enumif(void (*fn)(const char *name, int ifindex, int type, int flags, int state)); #endif
#endif
#ifdef __cplusplus
}
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include "enumif.h"
struct lookup {
int i;
const char *a;
};#define __PF(f,n) { ARPHRD_##f, #n },
static const struct lookup iftypes[] = {
{ 0, "generic", },__PF(ETHER,ether)__PF(EETHER,eether)__PF(AX25,ax25)__PF(PRONET,pronet)__PF(CHAOS,chaos)__PF(IEEE802,ieee802)__PF(ARCNET,arcnet)__PF(APPLETLK,atalk)__PF(DLCI,dlci)__PF(ATM,atm)__PF(METRICOM,metricom)__PF(IEEE1394,ieee1394)__PF(INFINIBAND,infiniband)__PF(SLIP,slip)__PF(CSLIP,cslip)__PF(SLIP6,slip6)__PF(CSLIP6,cslip6)__PF(RSRVD,rsrvd)__PF(ADAPT,adapt)__PF(ROSE,rose)__PF(X25,x25)__PF(HWX25,hwx25)__PF(CAN,can)__PF(PPP,ppp)__PF(HDLC,hdlc)__PF(LAPB,lapb)__PF(DDCMP,ddcmp)__PF(RAWHDLC,rawhdlc)__PF(TUNNEL,ipip)__PF(TUNNEL6,tunnel6)__PF(FRAD,frad)__PF(SKIP,skip)__PF(LOOPBACK,loopback)__PF(LOCALTLK,ltalk)__PF(FDDI,fddi)__PF(BIF,bif)__PF(SIT,sit)__PF(IPDDP,ip/ddp)__PF(IPGRE,gre)__PF(PIMREG,pimreg)__PF(HIPPI,hippi)__PF(ASH,ash)__PF(ECONET,econet)__PF(IRDA,irda)__PF(FCPP,fcpp)__PF(FCAL,fcal)__PF(FCPL,fcpl)__PF(FCFABRIC,fcfb0)__PF(FCFABRIC+1,fcfb1)__PF(FCFABRIC+2,fcfb2)__PF(FCFABRIC+3,fcfb3)__PF(FCFABRIC+4,fcfb4)__PF(FCFABRIC+5,fcfb5)__PF(FCFABRIC+6,fcfb6)__PF(FCFABRIC+7,fcfb7)__PF(FCFABRIC+8,fcfb8)__PF(FCFABRIC+9,fcfb9)__PF(FCFABRIC+10,fcfb10)__PF(FCFABRIC+11,fcfb11)__PF(FCFABRIC+12,fcfb12)__PF(IEEE802_TR,tr)__PF(IEEE80211,ieee802.11)__PF(IEEE80211_PRISM,ieee802.11/prism)__PF(IEEE80211_RADIOTAP,ieee802.11/radiotap)
#ifdef ARPHD_IEEE802154__PF(IEEE802154, ieee802.15.4)
#endif
#ifdef ARPHD_PHONET__PF(PHONET, phonet)
#endif
#ifdef ARPHD_PIPE__PF(PHONET_PIPE, phonet_pipe)
#endif
__PF(NONE, none)__PF(VOID,void)
{ },
};#define __IF(f) { IFF_##f, #f, }
static const struct lookup ifflags[] = {
__IF(LOOPBACK),
__IF(BROADCAST),
__IF(POINTOPOINT),
__IF(MULTICAST),
__IF(NOARP),
__IF(ALLMULTI),
__IF(PROMISC),
__IF(MASTER),
__IF(SLAVE),
__IF(DEBUG),
__IF(DYNAMIC),
__IF(AUTOMEDIA),
__IF(PORTSEL),
__IF(NOTRAILERS),
__IF(UP),
__IF(LOWER_UP),
__IF(DORMANT),
__IF(ECHO),
{},
};static const char *statestrs[] = {
"UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN",
"TESTING", "DORMANT", "UP"
};static void ifcallback(const char *name, int index, int type, int flags, int state)
{
const struct lookup *lp;
char typestr[16];
sprintf(typestr, "%i", type);
for (lp = iftypes; lp->a; ++lp)
if (lp->i == type)
break;
printf("%i: %s\t{%s}", index, name, lp->a ?: typestr);
printf(" <");
/* from iproute2 */
if ((flags & IFF_UP) && !(flags & IFF_RUNNING))
printf("%s%s", "NO-CARRIER", flags ? "," : "");
flags &= ~IFF_RUNNING;
for (lp = ifflags; lp->a; ++lp) {
if (flags & lp->i) {
flags &= ~lp->i;
printf("%s%s", lp->a, flags ? "," : "");
}
}
if (flags)
printf("%x", flags);
printf("> %s\n", statestrs[state]);
}int main(int argc, char *argv[])
{
enumif(ifcallback);
return 0;
}Re: Is there any way of getting the CAN interfaces list, from any C program?
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWN
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
Wolfgang.
Quoted 29 lines
Kurt
Quoted 24 lines · Stephane Grosjean
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program?
I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor.
And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)Thanks for your help and best regards,
Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.:
DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected]
----
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
maintainerRe: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 21 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWN
Quoted 3 lines
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
Good idea, Stephane, can you license the code under a permissive license like LGPL or BSD?
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Marc Kleine-Budde
maintainerRe: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 22 lines · Marc Kleine-Budde
Quoted 21 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWN
Quoted 6 lines
Quoted 3 lines
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
Good idea, Stephane, can you license the code under a permissive license like LGPL or BSD?
Errr...sorry. It's Kurt, who posted that code. Kurt, can you give the code a nice license? :)
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Re: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 27 lines · Marc Kleine-Budde
Quoted 26 lines · Marc Kleine-Budde
Quoted 24 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWNCool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
Quoted 6 lines
Quoted 2 lines
Good idea, Stephane, can you license the code under a permissive license like LGPL or BSD?
Errr...sorry. It's Kurt, who posted that code.
Kurt, can you give the code a nice license? :)
What is needed for LGPL or BSD?
Is there a short overview available?
Kurt
Marc Kleine-Budde
maintainerRe: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 28 lines · Kurt Van Dijck
Quoted 27 lines · Marc Kleine-Budde
Quoted 26 lines · Marc Kleine-Budde
Quoted 24 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWNCool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Good idea, Stephane, can you license the code under a permissive license like LGPL or BSD?
Errr...sorry. It's Kurt, who posted that code.
Kurt, can you give the code a nice license? :)
What is needed for LGPL or BSD?
Is there a short overview available?
If the code is LGPL we can include it in the libsocketcan. You are allowed to link the library against your closed source application (without to license under GPL). Any changes you make to the library have to be made available as source code.
IANAL,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Re: Is there any way of getting the CAN interfaces list, from any C program?
In reply to Wolfgang GrandeggerQuoted 21 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWN
Quoted 3 lines
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
would it make sense to maintain the split into enumif-test.c and enumif.c, so for example Stephane could just link to libenumif.a?
Kurt
Quoted 37 lines
Wolfgang.
Quoted 29 lines
Kurt
Quoted 24 lines · Stephane Grosjean
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program?
I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor.
And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)Thanks for your help and best regards,
Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.:
DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected]
----
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534
Re: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 22 lines · Kurt Van Dijck
Quoted 21 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWN
Quoted 6 lines
Quoted 3 lines
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
would it make sense to maintain the split into
enumif-test.candenumif.c, so for example Stephane could just link to libenumif.a?
Well, a better place might be libsocketcan then. In general it would be nice to host libsocketcan (maybe as liblinuxcan) at
https://gitorious.org/linux-can as well.
Wolfgang.
Re: Is there any way of getting the CAN interfaces list, from any C program?
I was just thinking that it has not that much to do with CAN altogether, and may deserve a seperate git tree.
I'm just rewriting the code a bit to work without callback, and be more like if_nameindex().
I'll post something later on...
Kurt
Quoted 39 lines · Wolfgang Grandegger
Quoted 22 lines · Kurt Van Dijck
Quoted 21 lines · Wolfgang Grandegger
Hi Kurt,
Quoted 6 lines · Kurt Van Dijck
Hi Stephane,
I have written this some time ago, not using it actually. I tried a modular approach, don't know if its usefull.
PS: I used attachments.
~/enumif$ ./enumif
1: lo {loopback} <LOOPBACK,UP,LOWER_UP> UNKNOWN
2: eth0 {ether} <BROADCAST,MULTICAST> DOWN
3: eth1 {ether} <BROADCAST,MULTICAST,UP,LOWER_UP> UNKNOWN
4: eth3 {ether} <NO-CARRIER,BROADCAST,MULTICAST,UP> DOWN
5: can0 {can} <NOARP,UP,LOWER_UP,ECHO> UNKNOWN
6: can1 {can} <NOARP,ECHO> DOWN
7: can2 {can} <NOARP,ECHO> DOWN
8: can3 {can} <NOARP,ECHO> DOWN
9: pan0 {ether} <BROADCAST,MULTICAST> DOWNQuoted 6 lines
Quoted 3 lines
Cool! We know that "ip link" does list all network interfaces but the code doing the job is not really strength-forward. I think this would be a nice enhancement of the can-utils.
would it make sense to maintain the split into
enumif-test.candenumif.c, so for example Stephane could just link to libenumif.a?Well, a better place might be libsocketcan then. In general it would be nice to host libsocketcan (maybe as liblinuxcan) at
https://gitorious.org/linux-can as well.Wolfgang.
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534
Marc Kleine-Budde
maintainerRe: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 5 lines · Kurt Van Dijck
I was just thinking that it has not that much to do with CAN altogether, and may deserve a seperate git tree.
I'm just rewriting the code a bit to work without callback, and be more like
if_nameindex().
Would be cool if the functions follows the same semantics as if_nameindex(), i.e. it could be named canif_nameindex() and just return CAN interfaces, not all.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Re: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 10 lines · Marc Kleine-Budde
Quoted 5 lines · Kurt Van Dijck
I was just thinking that it has not that much to do with CAN altogether, and may deserve a seperate git tree.
I'm just rewriting the code a bit to work without callback, and be more like
if_nameindex().Would be cool if the functions follows the same semantics as
if_nameindex(), i.e. it could be namedcanif_nameindex()and just return CAN interfaces, not all.
and such function belongs to libsocketcan, indeed. sounds like a plan.
Quoted 8 lines
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534
Re: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 5 lines · Kurt Van Dijck
Quoted 4 lines · Marc Kleine-Budde
Quoted 3 lines · Kurt Van Dijck
I was just thinking that it has not that much to do with CAN altogether, and may deserve a seperate git tree.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I'm just rewriting the code a bit to work without callback, and be more like
if_nameindex().Would be cool if the functions follows the same semantics as
if_nameindex(), i.e. it could be namedcanif_nameindex()and just return CAN interfaces, not all.and such function belongs to libsocketcan, indeed. sounds like a plan.
I realized I don't want to put much effort in making the code more dedicated to one task and struggle with the struct definition that if_nameindex uses (no status info).
So, I sanitized my version a bit, and
I just released libenumif on git://github.com/kurt-vd/enumif.git
This one allows to find:
* all can interfaces
* all active can interfaces.
* ...
Since it's LGPL'd, one can use it as is,
or use the code to build a canif_nameindex().
Kind regards,
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534
Re: Is there any way of getting the CAN interfaces list, from any C program?
In reply to Stephane GrosjeanStephane,
This is what i have done in a open source project i have started, a web can analyzer called ewecan (https://bitbucket.org/Mongo/ewecan):
It parses /sys/class/net but unfortunately, as noted in comments, it cannot make the difference between up or down interfaces.
/* Get a list of available socketcan interfaces and return them in
a string as a JS array like ["can0", "can1", "vcan"] Returned string must be freed after use
BUG : it also returns interfaces that are present but down !
*/
char *cmd_listitf(void)
{
char *buf = malloc(255);
if(!buf)
return NULL;
/* looking for socketcan interfaces in /sys */
DIR *fdir = opendir("/sys/class/net");
if(fdir == NULL){
perror("opendir");
free(buf);
return NULL;
}
struct dirent *fic;
int firstdone = 0;
buf[0] = '[';
buf[1] = '\0';
while(1){
fic = readdir(fdir);
if(fic == NULL)
break;
if(!strstr(fic->d_name, "can"))
continue;
/* if the new string does not fit in buf, stop here */
if((strlen(fic->d_name) + strlen(buf) + 4) >= 255)
break;
if(firstdone)
strcat(buf, ",");
strcat(buf, "\"");
strcat(buf, fic->d_name);
strcat(buf, "\"");
firstdone = 1;
}
strcat(buf, "]");
closedir(fdir);
return buf;
}Hope it can help !
Regards
--
François Beaulier
www.ingelibre.fr
Quoted 16 lines · Stephane Grosjean
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program? I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor. And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)Thanks for your help and best regards,
Stéphane
Signature · 5 lines
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected] ---- To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
maintainerRe: Is there any way of getting the CAN interfaces list, from any C program?
Quoted 7 lines · François
Stephane,
This is what i have done in a open source project i have started, a web can analyzer called ewecan (https://bitbucket.org/Mongo/ewecan):
It parses/sys/class/netbut unfortunately, as noted in comments, it cannot make the difference between up or down interfaces.
Quoted 5 lines
/* Get a list of available socketcan interfaces and return them in
a string as a JS array like ["can0", "can1", "vcan"] Returned string must be freed after use
BUG : it also returns interfaces that are present but down !
*/
Whan happens if I rename my ethernet interface to "can0"?
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Re: Is there any way of getting the CAN interfaces list, from any C program?
In reply to Françoisman if_nameindex
if_nameindex does a similar thing :-)
And does not return the type of interface neither.
Kurt
Quoted 87 lines · François
Stephane,
This is what i have done in a open source project i have started, a web can analyzer called ewecan (https://bitbucket.org/Mongo/ewecan):
It parses/sys/class/netbut unfortunately, as noted in comments, it cannot make the difference between up or down interfaces./* Get a list of available socketcan interfaces and return them in
a string as a JS array like ["can0", "can1", "vcan"] Returned string must be freed after use
BUG : it also returns interfaces that are present but down !
*/
char*cmd_listitf(void){ char *buf = malloc(255); if(!buf) return NULL; /* looking for socketcan interfaces in /sys */ DIR *fdir = opendir("/sys/class/net"); if(fdir == NULL){ perror("opendir"); free(buf); return NULL; } struct dirent *fic; int firstdone = 0; buf[0] = '['; buf[1] = '\0'; while(1){ fic = readdir(fdir); if(fic == NULL) break; if(!strstr(fic->d_name, "can")) continue; /* if the new string does not fit in buf, stop here */ if((strlen(fic->d_name) + strlen(buf) + 4) >= 255) break; if(firstdone) strcat(buf, ","); strcat(buf, "\""); strcat(buf, fic->d_name); strcat(buf, "\""); firstdone = 1; } strcat(buf, "]"); closedir(fdir); return buf; }Hope it can help !
Regards
--
François Beaulier
www.ingelibre.frQuoted 11 lines · Stephane Grosjean
Hi linux-can members,
I currently wonder whether it exists any way of getting the list of the installed CAN interfaces, from a C program?
I mean, getting the network interfaces list is available using ioctl(SIOCGIFCONF).
But AFAIK, this (only) returns the IP interfaces found in the system, even using a socket CAN file descriptor.
And, I would also like to avoid some pipe/fork/grep/sed in this C program too ;-)Quoted 13 lines
Thanks for your help and best regards,
Stéphane
Signature · 9 lines
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, [email protected] ---- To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Kurt Van Dijck GRAMMER EiA ELECTRONICS http://www.eia.be [email protected] +32-38708534