can_eth_gw Gateway Module  0.1
A bidirectional CAN to Ethernet Gateway (Kernel Module)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
ce_gw_main.h File Reference

Control Area Network - Ethernet - Gateway - Haeder. More...

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include "ce_gw_dev.h"
#include "ce_gw_netlink.h"
#include <uapi/linux/can.h>
#include <uapi/linux/if_arp.h>
#include <linux/can/core.h>
#include <linux/can/error.h>
#include <linux/slab.h>
#include <linux/if_ether.h>
#include <linux/netdevice.h>
Include dependency graph for ce_gw_main.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ce_gw_job
 
#define CE_GW_F_CAN_FD   0x00000001
 
#define CE_GW_TYPE_MAX   (__CE_GW_TYPE_MAX - 1)
 
enum  ce_gw_type {
  CE_GW_TYPE_NONE, CE_GW_TYPE_ETH, CE_GW_TYPE_NET, CE_GW_TYPE_TCP,
  CE_GW_TYPE_UDP, __CE_GW_TYPE_MAX
}
 Type of the Gateway. More...
 
struct hlist_head * ce_gw_get_job_list (void)
 getter for HLIST_HEAD(ce_gw_job_list) More...
 
struct can_frame * ce_gw_alloc_can_frame (void)
 allocates memory for the can frame More...
 
void ce_gw_free_can_frame (struct can_frame *memory)
 frees memory allocated for can_frame More...
 
struct canfd_frame * ce_gw_alloc_canfd_frame (void)
 allocates memory for a canfd frame More...
 
void ce_gw_free_canfd_frame (struct canfd_frame *memory)
 frees memory allocated for can_frame More...
 
struct can_frame * ce_gw_get_header_can (canid_t can_id, __u8 can_dlc, __u8 *payload)
 builds a can header in SFF (standart frame format) or EFF (extended frame formate) with the given information More...
 
struct canfd_frame * ce_gw_get_header_canfd (canid_t id, __u8 len, __u8 flags, __u8 res0, __u8 res1, __u8 *data)
 
struct sk_buff * ce_gw_can_to_eth (unsigned char *dest, unsigned char *source, __be16 type, struct sk_buff *can_buffer, struct net_device *net)
 converts sk buffer including can frame into sk buffer including ethernet_frame More...
 
struct sk_buff * ce_gw_canfd_to_eth (unsigned char *dest, unsigned char *source, __be16 type, struct sk_buff *canfd_skb, struct net_device *net)
 converts sk buffer including canfd frame into sk buffer including ethernet frame More...
 
struct sk_buff * ce_gw_eth_to_can (canid_t id, struct sk_buff *eth_buff, struct net_device *net)
 converst sk_buffer including an ethernet frame to sk_buffer including a can_frame More...
 
struct sk_buff * ce_gw_eth_to_canfd (canid_t id, __u8 flags, __u8 res0, __u8 res1, struct sk_buff *eth_skb, struct net_device *net)
 converst sk buffer including an ethernet frame to sk buffer including a canfd frame More...
 
void ce_gw_can_rcv (struct sk_buff *can_skb, void *data)
 The gateway function for incoming CAN frames Receive CAN frame –> process –> send to ETH dev (skbuffer, struct receiver->data) More...
 
void ce_gw_eth_rcv (struct sk_buff *eth_skb, void *data)
 The gateway function for incoming ETH frames Receive skb from ETH dev –> process –> send to CAN bus. More...
 
int ce_gw_create_route (int src_ifindex, int dst_ifindex, enum ce_gw_type rt_type, u32 flags)
 
int ce_gw_remove_route (u32 id)
 

Detailed Description

Control Area Network - Ethernet - Gateway - Haeder.

Author
Stefan Smarzly (stefa.nosp@m.n.sm.nosp@m.arzly.nosp@m.@in..nosp@m.tum.d.nosp@m.e)
Date
May, 2013

Definition in file ce_gw_main.h.

Macro Definition Documentation

#define CE_GW_F_CAN_FD   0x00000001

ce_gw_job.flags: is Gateway CANfd compatible

Definition at line 49 of file ce_gw_main.h.

Referenced by ce_gw_dev_setup(), and ce_gw_has_min_mtu().

#define CE_GW_TYPE_MAX   (__CE_GW_TYPE_MAX - 1)

Maximum Type Number

Definition at line 65 of file ce_gw_main.h.

Enumeration Type Documentation

enum ce_gw_type

Type of the Gateway.

Enumerator
CE_GW_TYPE_NONE 

No Type. Should normally not be used.

CE_GW_TYPE_ETH 

Convert CAN header to Ethernet header Payload of CAN header must contain an IP header

CE_GW_TYPE_NET 

Copy complete CAN Frame into Ethernet payload e.g use CAN as Network Layer (Layer 3) protocol.

CE_GW_TYPE_TCP 

Convert CAN header into an IP/TCP package

CE_GW_TYPE_UDP 

Convert CAN header into an IP/UDP package

__CE_GW_TYPE_MAX 

Maximum Type Number + 1

Definition at line 55 of file ce_gw_main.h.

Function Documentation

int ce_gw_create_route ( int  src_ifindex,
int  dst_ifindex,
enum ce_gw_type  rt_type,
u32  flags 
)

Definition at line 916 of file ce_gw_main.c.

References ce_gw_job::can_rcv_filter, ce_gw_has_min_mtu(), ce_gw_is_registered_dev(), ce_gw_register_can_src(), ce_gw_register_eth_src(), ce_gw_job::dev, ce_gw_job::dropped_frames, ce_gw_job::dst, ce_gw_job::flags, ce_gw_job::handled_frames, ce_gw_job::id, job_count, ce_gw_job::list, ce_gw_job::src, and ce_gw_job::type.

Referenced by ce_gw_netlink_add().

918 {
919  int err = 0;
920 
921  struct ce_gw_job *gwj;
922  gwj = kmem_cache_alloc(ce_gw_job_cache, GFP_KERNEL);
923 
924  gwj->id = job_count++;
925  gwj->handled_frames = 0;
926  gwj->dropped_frames = 0;
927 
928  err = -ENODEV;
929  gwj->src.dev = dev_get_by_index(&init_net, src_ifindex);
930  gwj->dst.dev = dev_get_by_index(&init_net, dst_ifindex);
931  if (!gwj->src.dev || !gwj->dst.dev)
932  goto clean_exit;
933 
934  if (ce_gw_has_min_mtu(gwj->src.dev, rt_type, flags) == false ||
935  ce_gw_has_min_mtu(gwj->dst.dev, rt_type, flags) == false) {
936  err = -EOPNOTSUPP;
937  goto clean_exit;
938  }
939 
940  gwj->type = rt_type;
941  gwj->flags = flags;
942 
943  /* TEST: pre-filled values */
944  gwj->can_rcv_filter.can_id = 0x42A;
945  gwj->can_rcv_filter.can_mask = 0; /* allow all frames */
946 
947  /*
948  * Depending on routing direction: register at source device
949  */
950  if (gwj->src.dev->type == ARPHRD_CAN &&
951  ce_gw_is_registered_dev(gwj->dst.dev) == 0) {
952  /* && gwj->dst.dev->type == ARPHRD_ETHER) {*/
953  /* CAN source --> ETH destination (cegw virtual dev) */
954  err = ce_gw_register_can_src(gwj);
955  } else if (ce_gw_is_registered_dev(gwj->src.dev) == 0 &&
956  gwj->dst.dev->type == ARPHRD_CAN) {
957  /* ETH source (cegw virtual dev) --> CAN destination */
958  err = ce_gw_register_eth_src(gwj);
959  } else {
960  /* Undefined routing setup */
961  goto clean_exit;
962  }
963 
964  if (!err)
965  hlist_add_head_rcu(&gwj->list, &ce_gw_job_list);
966 
967 clean_exit:
968  if (err) {
969  printk(KERN_ERR "ce_gw: Src or dst device not found or "
970  "not compatible (CAN<->CEGW ETH), exit.\n");
971  if (gwj->src.dev)
972  dev_put(gwj->src.dev);
973  if (gwj->dst.dev)
974  dev_put(gwj->dst.dev);
975  kmem_cache_free(ce_gw_job_cache, gwj);
976  }
977 
978  return err;
979 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct canfd_frame* ce_gw_get_header_canfd ( canid_t  id,
__u8  len,
__u8  flags,
__u8  res0,
__u8  res1,
__u8 *  data 
)
read

Definition at line 201 of file ce_gw_main.c.

References ce_gw_alloc_canfd_frame().

202  {
203  struct canfd_frame *canfd = ce_gw_alloc_canfd_frame();
204  if (canfd == NULL) {
205  printk (KERN_ERR "ce_gw_main.c: kmalloc failed in function"
206  "ce_gw_get_header_canfd\n");
207  return NULL;
208  }
209 
210  canfd->can_id = id;
211  canfd->len = len;
212  canfd->flags = flags;
213  canfd->__res0 = res0;
214  canfd->__res1 = res1;
215  *(u64 *)canfd->data = *(u64 *)data;
216 
217  return canfd;
218 }

Here is the call graph for this function:

struct hlist_head* ce_gw_get_job_list ( void  )
read

getter for HLIST_HEAD(ce_gw_job_list)

Returns
Pointer to ce_gw_job_list.

Definition at line 157 of file ce_gw_main.c.

Referenced by ce_gw_netlink_list().

157  {
158  return &ce_gw_job_list;
159 }

Here is the caller graph for this function:

int ce_gw_remove_route ( u32  id)

Definition at line 982 of file ce_gw_main.c.

References ce_gw_job::can_rcv_filter, ce_gw_unregister_can_src(), ce_gw_unregister_eth_src(), ce_gw_job::dev, ce_gw_job::dst, ce_gw_job::id, ce_gw_job::list, and ce_gw_job::src.

Referenced by ce_gw_cleanup(), ce_gw_dev_unregister(), and ce_gw_netlink_del().

983 {
984  pr_info("ce_gw: unregister CAN ETH GW routes\n");
985  struct ce_gw_job *gwj = NULL;
986  struct hlist_node *n, *nx;
987 
988  hlist_for_each_entry_safe(gwj, n, nx, &ce_gw_job_list, list) {
989  if (gwj->id != id && id)
990  continue;
991 
992  pr_debug("Removing routing src device: %s, id %x, mask %x\n",
993  gwj->src.dev->name, gwj->can_rcv_filter.can_id,
994  gwj->can_rcv_filter.can_mask);
995  hlist_del(&gwj->list);
996  /* TODO: Unregister destination device (only for cegw eth) */
997  if (gwj->src.dev->type == ARPHRD_CAN)
999  else
1001  dev_put(gwj->src.dev);
1002  dev_put(gwj->dst.dev);
1003  kmem_cache_free(ce_gw_job_cache, gwj);
1004  }
1005 
1006  return 0; /* TODO: error, when no suitable entry was found */
1007 }

Here is the call graph for this function:

Here is the caller graph for this function: