summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2007-09-17 13:27:12 +0000
committerMarc Kleine-Budde <mkl@pengutronix.de>2007-09-17 13:27:12 +0000
commitc59d21e737c560627fbaff57099fa1b215aa7aa7 (patch)
tree56fe341a060f7c07627c0d15430fa8b3efd1e896
parent77ab90a3713c5afc4340529899a810d0b992d735 (diff)
downloadcanutils-c59d21e737c560627fbaff57099fa1b215aa7aa7.tar.gz
git-svn-id: https://iocaste.extern.pengutronix.de/svn/canutils/trunks/canutils-1.2-trunk@69 5fd5a299-6ef2-0310-aa18-8b01d7c39d8c
-rwxr-xr-xautogen.sh38
-rw-r--r--configure.ac2
-rw-r--r--include/GNUmakefile.am2
-rw-r--r--include/socket-can/can.h246
-rw-r--r--src/GNUmakefile.am16
-rw-r--r--src/canconfig.c177
6 files changed, 43 insertions, 438 deletions
diff --git a/autogen.sh b/autogen.sh
index 76a7de0..29db9c9 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# usage:
@@ -6,7 +6,6 @@
# banner <target name>
#
banner() {
-
echo
TG=`echo $1 | sed -e "s,/.*/,,g"`
LINE=`echo $TG |sed -e "s/./-/g"`
@@ -16,39 +15,8 @@ banner() {
echo
}
+banner "autoreconf"
-ACLOCAL=${ACLOCAL:=aclocal}
-AUTOHEADER=${AUTOHEADER:=autoheader}
-AUTOMAKE=${AUTOMAKE:=automake}
-AUTOCONF=${AUTOCONF:=autoconf}
-
-$ACLOCAL --version | \
- awk -vPROG="aclocal" -vVERS=1.7\
- '{if ($1 == PROG) {gsub ("-.*","",$4); if ($4 < VERS) print PROG" < version "VERS"\nThis may result in errors\n"}}'
-
-$AUTOMAKE --version | \
- awk -vPROG="automake" -vVERS=1.7\
- '{if ($1 == PROG) {gsub ("-.*","",$4); if ($4 < VERS) print PROG" < version "VERS"\nThis may result in errors\n"}}'
-
-
-banner "running libtoolize"
-libtoolize --force
-[ $? != 0 ] && exit
-
-banner "running aclocal"
-$ACLOCAL -I config/m4
-[ $? != 0 ] && exit
-
-banner "running autoheader"
-$AUTOHEADER
-[ $? != 0 ] && exit
-
-banner "running automake"
-$AUTOMAKE --gnu --add-missing -Wall
-[ $? != 0 ] && exit
-
-banner "running autoconf"
-$AUTOCONF -Wall
-[ $? != 0 ] && exit
+autoreconf --force --install --symlink -Wall || exit $?
banner "Finished"
diff --git a/configure.ac b/configure.ac
index 403f6cb..9e3e3ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([canutils], [1.1.2], [socket-can@pengutronix.de])
+AC_INIT([canutils], [1.2.0], [socket-can@pengutronix.de])
AC_CONFIG_HEADERS([include/can_config.h])
AC_CONFIG_SRCDIR([src/canconfig.c])
AC_CONFIG_MACRO_DIR([config/m4])
diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am
index e398444..5d5b766 100644
--- a/include/GNUmakefile.am
+++ b/include/GNUmakefile.am
@@ -1,5 +1,3 @@
-nobase_include_HEADERS = socket-can/can.h
-
MAINTAINERCLEANFILES = \
can_config.h.in \
GNUmakefile.in
diff --git a/include/socket-can/can.h b/include/socket-can/can.h
deleted file mode 100644
index 507cfd7..0000000
--- a/include/socket-can/can.h
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * can.h (userspace)
- *
- * Copyright (C) 2004, 2005, 2006
- *
- * - Robert Schwebel, Benedikt Spranger, Marc Kleine-Budde, Pengutronix
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the version 2 of the GNU General Public License
- * as published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef _SOCKET_CAN_CAN_H
-#define _SOCKET_CAN_CAN_H
-
-#include <stdint.h>
-
-#define CAN_ID_EXT_MASK 0x1FFFFFFF /* contains CAN id */
-#define CAN_ID_STD_MASK 0x000007FF
-#define CAN_FLAG_ALL 0x20000000 /* filter all messages */
-#define CAN_FLAG_RTR 0x40000000 /* remote transmission flag*/
-#define CAN_FLAG_EXTENDED 0x80000000 /* extended frame */
-
-#define SIOCSCANBAUDRATE (SIOCPROTOPRIVATE + 0)
-#define SIOCGCANBAUDRATE (SIOCPROTOPRIVATE + 1)
-#define SIOCSCANMODE (SIOCPROTOPRIVATE + 2)
-#define SIOCGCANSTATE (SIOCPROTOPRIVATE + 3)
-
-
-enum CAN_BAUD {
- /*!
- ** Baudrate 10 kBit/sec
- */
- CAN_BAUD_10K = 0,
-
- /*!
- ** Baudrate 20 kBit/sec
- */
- CAN_BAUD_20K,
-
- /*!
- ** Baudrate 50 kBit/sec
- */
- CAN_BAUD_50K,
-
- /*!
- ** Baudrate 100 kBit/sec
- */
- CAN_BAUD_100K,
-
- /*!
- ** Baudrate 125 kBit/sec
- */
- CAN_BAUD_125K,
-
- /*!
- ** Baudrate 250 kBit/sec
- */
- CAN_BAUD_250K,
-
- /*!
- ** Baudrate 500 kBit/sec
- */
- CAN_BAUD_500K,
-
- /*!
- ** Baudrate 800 kBit/sec
- */
- CAN_BAUD_800K,
-
- /*!
- ** Baudrate 1 MBit/sec
- */
- CAN_BAUD_1M,
-
- /*!
- ** Max value, beside CAN_BAUD_BTR_*
- */
- CAN_BAUD_MAX,
- CAN_BAUD_UNCONFIGURED,
-
- CAN_BAUD_BTR_SJA1000 = 0x80,
- CAN_BAUD_BTR_C_CAN,
- CAN_BAUD_BTR_NIOS,
-};
-
-
-enum CAN_MODE {
- /*! Set controller in Stop mode (no reception / transmission possible)
- */
- CAN_MODE_STOP = 0,
-
- /*! Set controller into normal operation
- */
- CAN_MODE_START,
-
- /*! Start Autobaud Detection
- */
- CAN_MODE_AUTO_BAUD,
- /*! Set controller into Sleep mode
- */
- CAN_MODE_SLEEP
-};
-
-
-enum CAN_STATE {
- /*!
- ** CAN controller is active, no errors
- */
- CAN_STATE_ACTIVE = 0,
-
- /*!
- ** CAN controller is in stopped mode
- */
- CAN_STATE_STOPPED,
-
- /*!
- ** CAN controller is in Sleep mode
- */
- CAN_STATE_SLEEPING,
-
- /*!
- ** CAN controller is active, warning level is reached
- */
- CAN_STATE_BUS_WARN = 6,
-
- /*!
- ** CAN controller is error passive
- */
- CAN_STATE_BUS_PASSIVE,
-
- /*!
- ** CAN controller went into Bus Off
- */
- CAN_STATE_BUS_OFF,
-
- /*!
- ** General failure of physical layer detected (if supported by hardware)
- */
- CAN_STATE_PHY_FAULT = 10,
-
- /*!
- ** Fault on CAN-H detected (Low Speed CAN)
- */
- CAN_STATE_PHY_H,
-
- /*!
- ** Fault on CAN-L detected (Low Speed CAN)
- */
- CAN_STATE_PHY_L,
-
- CAN_STATE_ERR_BIT = 0x10,
- CAN_STATE_ERR_STUFF = 0x20,
- CAN_STATE_ERR_FORM = 0x30,
- CAN_STATE_ERR_CRC = 0x40,
- CAN_STATE_ERR_ACK = 0x50
-};
-
-struct can_baudrate_sja1000 {
- uint8_t brp;
- uint8_t sjw;
- uint8_t tseg1;
- uint8_t tseg2;
- uint8_t sam;
-};
-
-struct can_baudrate_c_can {
- uint8_t brp;
- uint8_t sjw;
- uint8_t tseg1;
- uint8_t tseg2;
-};
-
-struct can_baudrate_nios {
- uint8_t prescale;
- uint8_t timea;
- uint8_t timeb;
-};
-
-struct can_baudrate {
- enum CAN_BAUD baudrate;
- union {
- struct can_baudrate_sja1000 sja1000;
- struct can_baudrate_c_can c_can;
- struct can_baudrate_nios nios;
- } btr;
-};
-
-
-union can_settings {
- enum CAN_MODE mode;
- enum CAN_STATE state;
-};
-
-
-#define AF_CAN 29 /* CAN Bus */
-#define PF_CAN AF_CAN
-
-enum CAN_PROTO {
- CAN_PROTO_RAW,
- CAN_PROTO_MAX,
-};
-
-struct sockaddr_can {
- sa_family_t can_family;
- int can_ifindex;
- int can_id;
-};
-
-struct can_frame {
- int can_id;
- int can_dlc;
- union {
- int64_t data_64;
- int32_t data_32[2];
- int16_t data_16[4];
- int8_t data_8[8];
- uint64_t data_u64;
- uint32_t data_u32[2];
- uint16_t data_u16[4];
- uint8_t data_u8[8];
- int8_t data[8]; /* shortcut */
- } payload;
-};
-
-struct can_filter {
- uint32_t can_id;
- uint32_t can_mask;
-};
-
-#define SO_CAN_SET_FILTER 1
-#define SO_CAN_UNSET_FILTER 2
-
-#define SOL_CAN_BASE 100
-#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_PROTO_RAW)
-
-#endif /* !_SOCKET_CAN_CAN_H */
diff --git a/src/GNUmakefile.am b/src/GNUmakefile.am
index 195532c..315600d 100644
--- a/src/GNUmakefile.am
+++ b/src/GNUmakefile.am
@@ -1,15 +1,17 @@
-bin_PROGRAMS = \
- candump \
- canecho \
- cansend \
- cansequence
+# bin_PROGRAMS = \
+# candump \
+# canecho \
+# cansend \
+# cansequence
sbin_PROGRAMS = \
canconfig
AM_CPPFLAGS = \
- -I$(top_srcdir)/include
- -I$(top_builddir)/include
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/include \
+ -DPF_CAN=29 \
+ -DAF_CAN=PF_CAN
MAINTAINERCLEANFILES = \
GNUmakefile.in
diff --git a/src/canconfig.c b/src/canconfig.c
index d481ce2..3ce0fb7 100644
--- a/src/canconfig.c
+++ b/src/canconfig.c
@@ -34,7 +34,8 @@
#include <netinet/in.h>
#include <netinet/ether.h>
-#include <socket-can/can.h>
+#include <linux/can.h>
+#include <linux/can/ioctl.h>
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -43,53 +44,7 @@
int s;
struct ifreq ifr;
-struct speed_map {
- unsigned short speed;
- unsigned short value;
-};
-
-static const struct speed_map speeds[] = {
- {CAN_BAUD_10K, 10},
- {CAN_BAUD_20K, 20},
- {CAN_BAUD_50K, 50},
- {CAN_BAUD_100K, 100},
- {CAN_BAUD_125K, 125},
- {CAN_BAUD_250K, 250},
- {CAN_BAUD_500K, 500},
- {CAN_BAUD_800K, 800},
- {CAN_BAUD_1M, 1000},
-};
-
-static const int NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map));
-
-unsigned long can_baud_to_value(speed_t speed)
-{
- int i = 0;
-
- do {
- if (speed == speeds[i].speed) {
- return speeds[i].value;
- }
- } while (++i < NUM_SPEEDS);
-
- return 0;
-}
-
-speed_t can_value_to_baud(unsigned long value)
-{
- int i = 0;
-
- do {
- if (value == can_baud_to_value(speeds[i].speed)) {
- return speeds[i].speed;
- }
- } while (++i < NUM_SPEEDS);
-
- return (speed_t)-1;
-}
-
-
-void help(void)
+static void help(void)
{
fprintf(stderr, "usage:\n\t"
"canconfig <dev> baudrate { BR | BTR }\n\t\t"
@@ -106,104 +61,32 @@ void help(void)
}
-void do_show_baudrate(int argc, char* argv[])
+static void do_show_baudrate(int argc, char* argv[])
{
- struct can_baudrate *br = (struct can_baudrate *)&ifr.ifr_ifru;
- int i, value;
+ uint32_t *baudrate = (uint32_t *)&ifr.ifr_ifru;
+ int i;
i = ioctl(s, SIOCGCANBAUDRATE, &ifr);
+
if (i < 0) {
perror("ioctl");
exit(EXIT_FAILURE);
}
- switch (br->baudrate) {
- case CAN_BAUD_BTR_SJA1000:
- fprintf(stdout, "%s: sja1000 brp=%d sjw=%d tseg1=%d tseg2=%d sam=%d\n",
- ifr.ifr_name,
- br->btr.sja1000.brp,
- br->btr.sja1000.sjw,
- br->btr.sja1000.tseg1,
- br->btr.sja1000.tseg2,
- br->btr.sja1000.sam);
- break;
- case CAN_BAUD_BTR_C_CAN:
- fprintf(stdout, "%s: C-Can brp=%d sjw=%d tseg1=%d tseg2=%d\n",
- ifr.ifr_name,
- br->btr.c_can.brp,
- br->btr.c_can.sjw,
- br->btr.c_can.tseg1,
- br->btr.c_can.tseg2);
- break;
- case CAN_BAUD_BTR_NIOS:
- fprintf(stdout, "%s: nios prescale=%d timea=%d timeb=%d\n",
- ifr.ifr_name,
- br->btr.nios.prescale,
- br->btr.nios.timea,
- br->btr.nios.timeb);
- break;
- default:
- value = can_baud_to_value(br->baudrate);
- if (value != 0)
- fprintf(stdout,
- "%s: baudrate %d\n", ifr.ifr_name, value);
- else
- fprintf(stdout, "baudrate not recognized. update canconfig?\n");
- break;
- }
+ fprintf(stdout,
+ "%s: baudrate %d\n", ifr.ifr_name, *baudrate);
}
-void do_set_baudrate(int argc, char* argv[])
+static void do_set_baudrate(int argc, char* argv[])
{
- struct can_baudrate *br = (struct can_baudrate *)&ifr.ifr_ifru;
- speed_t baudrate;
- int value, i;
-
- if (!strcmp(argv[3], "btr_sja1000")) {
- struct can_baudrate_sja1000 *br_sja1000 = &br->btr.sja1000;
-
- if (argc < 9)
- help();
-
- br->baudrate = CAN_BAUD_BTR_SJA1000;
- br_sja1000->brp = strtol(argv[4], NULL, 0);
- br_sja1000->sjw = strtol(argv[5], NULL, 0);
- br_sja1000->tseg1 = strtol(argv[6], NULL, 0);
- br_sja1000->tseg2 = strtol(argv[7], NULL, 0);
- br_sja1000->sam = strtol(argv[8], NULL, 0);
-
- } else if (!strcmp(argv[3], "btr_c_can")) {
- struct can_baudrate_c_can *br_c_can = &br->btr.c_can;
-
- if (argc < 8)
- help();
-
- br->baudrate = CAN_BAUD_BTR_C_CAN;
- br_c_can->brp = strtol(argv[4], NULL, 0);
- br_c_can->sjw = strtol(argv[5], NULL, 0);
- br_c_can->tseg1 = strtol(argv[6], NULL, 0);
- br_c_can->tseg2 = strtol(argv[7], NULL, 0);
-
- } else if (!strcmp(argv[3], "btr_nios")) {
- struct can_baudrate_nios *br_nios = &br->btr.nios;
-
- if (argc < 7)
- help();
-
- br->baudrate = CAN_BAUD_BTR_NIOS;
- br_nios->prescale = strtol(argv[4], NULL, 0);
- br_nios->timea = strtol(argv[5], NULL, 0);
- br_nios->timeb = strtol(argv[6], NULL, 0);
+ uint32_t *baudrate = (uint32_t *)&ifr.ifr_ifru;
+ int i;
- } else {
- value = atoi(argv[3]);
- baudrate = can_value_to_baud(value);
- if ( baudrate == -1) {
- fprintf(stderr, "invalid baudrate\n");
- exit(EXIT_FAILURE);
- }
- br->baudrate = baudrate;
+ *baudrate = (uint32_t)strtoul(argv[3], NULL, 0);
+ if (*baudrate == 0) {
+ fprintf(stderr, "invalid baudrate\n");
+ exit(EXIT_FAILURE);
}
i = ioctl(s, SIOCSCANBAUDRATE, &ifr);
@@ -214,7 +97,7 @@ void do_set_baudrate(int argc, char* argv[])
}
-void cmd_baudrate(int argc, char *argv[])
+static void cmd_baudrate(int argc, char *argv[])
{
if (argc >= 4) {
do_set_baudrate(argc, argv);
@@ -224,17 +107,16 @@ void cmd_baudrate(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
-
-void cmd_mode(int argc, char *argv[])
+static void cmd_mode(int argc, char *argv[])
{
- union can_settings *settings = (union can_settings *)&ifr.ifr_ifru;
+ can_mode_t *mode = (can_mode_t *)&ifr.ifr_ifru;
int i;
if (argc < 4 )
help();
if (!strcmp(argv[3], "start")) {
- settings->mode = CAN_MODE_START;
+ *mode = CAN_MODE_START;
} else {
help();
}
@@ -249,7 +131,8 @@ void cmd_mode(int argc, char *argv[])
}
-void do_show_state(int argc, char *argv[])
+#if 0
+static void do_show_state(int argc, char *argv[])
{
union can_settings *settings = (union can_settings *)&ifr.ifr_ifru;
enum CAN_STATE state;
@@ -283,29 +166,29 @@ void do_show_state(int argc, char *argv[])
}
-void cmd_state(int argc, char *argv[])
+static void cmd_state(int argc, char *argv[])
{
do_show_state(argc, argv);
exit(EXIT_SUCCESS);
}
+#endif
-void cmd_show_interface(int argc, char *argv[])
+static void cmd_show_interface(int argc, char *argv[])
{
do_show_baudrate(argc, argv);
- do_show_state(argc, argv);
+/* do_show_state(argc, argv); */
exit(EXIT_SUCCESS);
}
-
int main(int argc, char *argv[])
{
if ((argc < 2) || !strcmp(argv[1], "--help"))
help();
- if ((s = socket(AF_CAN, SOCK_RAW, 0)) < 0) {
+ if ((s = socket(AF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("socket");
exit(EXIT_FAILURE);
}
@@ -319,10 +202,10 @@ int main(int argc, char *argv[])
cmd_baudrate(argc, argv);
if (!strcmp(argv[2], "mode"))
cmd_mode(argc, argv);
- if (!strcmp(argv[2], "state"))
- cmd_state(argc, argv);
+/* if (!strcmp(argv[2], "state")) */
+/* cmd_state(argc, argv); */
help();
- return 0;
+ exit(EXIT_SUCCESS);
}