alistair23-linux/include/linux/can/dev.h
Wolfgang Grandegger 7b6856a029 can: provide library functions for skb allocation
This patch makes the private functions alloc_can_skb() and
alloc_can_err_skb() of the at91_can driver public and adapts all
drivers to use these. While making the patch I realized, that
the skb's are *not* setup consistently. It's now done as shown
below:

  skb->protocol = htons(ETH_P_CAN);
  skb->pkt_type = PACKET_BROADCAST;
  skb->ip_summed = CHECKSUM_UNNECESSARY;
  *cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  memset(*cf, 0, sizeof(struct can_frame));

The frame is zeroed out to avoid uninitialized data to be passed to
user space. Some drivers or library code did not set "pkt_type" or
"ip_summed". Also,  "__constant_htons()" should not be used for
runtime invocations, as pointed out by David Miller.

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-10-20 00:08:01 -07:00

76 lines
1.8 KiB
C

/*
* linux/can/dev.h
*
* Definitions for the CAN network device driver interface
*
* Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
* Varma Electronics Oy
*
* Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
*
* Send feedback to <socketcan-users@lists.berlios.de>
*/
#ifndef CAN_DEV_H
#define CAN_DEV_H
#include <linux/can/netlink.h>
#include <linux/can/error.h>
/*
* CAN mode
*/
enum can_mode {
CAN_MODE_STOP = 0,
CAN_MODE_START,
CAN_MODE_SLEEP
};
/*
* CAN common private data
*/
struct can_priv {
struct can_device_stats can_stats;
struct can_bittiming bittiming;
struct can_bittiming_const *bittiming_const;
struct can_clock clock;
enum can_state state;
u32 ctrlmode;
int restart_ms;
struct timer_list restart_timer;
int (*do_set_bittiming)(struct net_device *dev);
int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
int (*do_get_state)(const struct net_device *dev,
enum can_state *state);
unsigned int echo_skb_max;
struct sk_buff **echo_skb;
};
struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
void free_candev(struct net_device *dev);
int open_candev(struct net_device *dev);
void close_candev(struct net_device *dev);
int register_candev(struct net_device *dev);
void unregister_candev(struct net_device *dev);
int can_restart_now(struct net_device *dev);
void can_bus_off(struct net_device *dev);
void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
unsigned int idx);
void can_get_echo_skb(struct net_device *dev, unsigned int idx);
void can_free_echo_skb(struct net_device *dev, unsigned int idx);
struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf);
struct sk_buff *alloc_can_err_skb(struct net_device *dev,
struct can_frame **cf);
#endif /* CAN_DEV_H */