/*
* tst-bcm-cycle.c
*
- * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions, the following disclaimer and
- * the referenced file 'COPYING'.
+ * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Alternatively, provided that this notice is retained in full, this
* software may be distributed under the terms of the GNU General
- * Public License ("GPL") version 2 as distributed in the 'COPYING'
- * file from the main directory of the linux kernel source.
+ * Public License ("GPL") version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
*
* The provided data structures and external interfaces from this code
* are not restricted to be used by modules with a GPL compatible license.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * Send feedback to <llcf@volkswagen.de>
+ * Send feedback to <socketcan-users@lists.berlios.de>
*
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
+#include <net/if.h>
-#include "af_can.h"
-#include "bcm.h"
+#include <linux/can.h>
+#include <linux/can/bcm.h>
#define U64_DATA(p) (*(unsigned long long*)(p)->data)
int main(int argc, char **argv)
{
- int s;
- struct sockaddr_can addr;
- struct ifreq ifr;
-
- struct {
- struct bcm_msg_head msg_head;
- struct can_frame frame[4];
- } msg;
-
- if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
- perror("socket");
- return 1;
- }
-
- addr.can_family = PF_CAN;
- strcpy(ifr.ifr_name, "vcan2");
- ioctl(s, SIOCGIFINDEX, &ifr);
- addr.can_ifindex = ifr.ifr_ifindex;
-
- if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- perror("connect");
- return 1;
- }
-
- msg.msg_head.opcode = TX_SETUP;
- msg.msg_head.can_id = 0x42;
- msg.msg_head.flags = SETTIMER|STARTTIMER;
- msg.msg_head.nframes = 1;
- msg.msg_head.count = 10;
- msg.msg_head.ival1.tv_sec = 1;
- msg.msg_head.ival1.tv_usec = 0;
- msg.msg_head.ival2.tv_sec = 0;
- msg.msg_head.ival2.tv_usec = 0;
- msg.frame[0].can_id = 0x42;
- msg.frame[0].can_dlc = 8;
- U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
-
- if (write(s, &msg, sizeof(msg)) < 0)
- perror("write");
-
- printf("Press any key to stop the cycle ...\n");
-
- getchar();
-
- msg.msg_head.opcode = TX_SETUP;
- msg.msg_head.can_id = 0x42;
- msg.msg_head.flags = SETTIMER|STARTTIMER;
- msg.msg_head.nframes = 1;
- msg.msg_head.count = 0;
- msg.msg_head.ival1.tv_sec = 0;
- msg.msg_head.ival1.tv_usec = 0;
- msg.msg_head.ival2.tv_sec = 0;
- msg.msg_head.ival2.tv_usec = 0;
- msg.frame[0].can_id = 0x42;
- msg.frame[0].can_dlc = 8;
- U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
-
- if (write(s, &msg, sizeof(msg)) < 0)
- perror("write");
-
- printf("Press any key to close the socket ...\n");
-
- getchar();
-
- close(s);
-
- printf("Press any key to end the program ...\n");
-
- getchar();
-
- return 0;
+ int s;
+ struct sockaddr_can addr;
+ struct ifreq ifr;
+
+ struct {
+ struct bcm_msg_head msg_head;
+ struct can_frame frame[4];
+ } msg;
+
+ if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
+ perror("socket");
+ return 1;
+ }
+
+ addr.can_family = PF_CAN;
+ strcpy(ifr.ifr_name, "vcan2");
+ ioctl(s, SIOCGIFINDEX, &ifr);
+ addr.can_ifindex = ifr.ifr_ifindex;
+
+ if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("connect");
+ return 1;
+ }
+
+ msg.msg_head.opcode = TX_SETUP;
+ msg.msg_head.can_id = 0x42;
+ msg.msg_head.flags = SETTIMER|STARTTIMER;
+ msg.msg_head.nframes = 1;
+ msg.msg_head.count = 10;
+ msg.msg_head.ival1.tv_sec = 1;
+ msg.msg_head.ival1.tv_usec = 0;
+ msg.msg_head.ival2.tv_sec = 0;
+ msg.msg_head.ival2.tv_usec = 0;
+ msg.frame[0].can_id = 0x42;
+ msg.frame[0].can_dlc = 8;
+ U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
+
+ if (write(s, &msg, sizeof(msg)) < 0)
+ perror("write");
+
+ printf("Press any key to stop the cycle ...\n");
+
+ getchar();
+
+ msg.msg_head.opcode = TX_SETUP;
+ msg.msg_head.can_id = 0x42;
+ msg.msg_head.flags = SETTIMER|STARTTIMER;
+ msg.msg_head.nframes = 1;
+ msg.msg_head.count = 0;
+ msg.msg_head.ival1.tv_sec = 0;
+ msg.msg_head.ival1.tv_usec = 0;
+ msg.msg_head.ival2.tv_sec = 0;
+ msg.msg_head.ival2.tv_usec = 0;
+ msg.frame[0].can_id = 0x42;
+ msg.frame[0].can_dlc = 8;
+ U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL;
+
+ if (write(s, &msg, sizeof(msg)) < 0)
+ perror("write");
+
+ printf("Press any key to close the socket ...\n");
+
+ getchar();
+
+ close(s);
+
+ printf("Press any key to end the program ...\n");
+
+ getchar();
+
+ return 0;
}