MODULE_LICENSE("GPL");
-static int cegw_udp_can(void *data);
+static int cegw_udp2can(void *data);
static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
- struct in_addr ipaddr, u16 port);
-static int cegw_can_udp(void *data);
+ struct in_addr ipaddr, u16 port);
+static int cegw_can2udp(void *data);
static void cegw_can_send(struct socket *can_sock, struct can_frame *cf,
- int ifindex);
+ int ifindex);
static int cegw_thread_start(void *data);
static int cegw_thread_stop(void);
-enum __cegw_state
-{
+enum __cegw_state {
CEGW_RUN,
CEGW_STOP,
CEGW_EXIT
};
-struct cegw_rule
-{
+struct cegw_rule {
int can_ifindex;
struct in_addr eth_ip;
unsigned short eth_port;
struct hlist_node list;
};
-struct cegw_setting
-{
+struct cegw_setting {
struct in_addr eth_ip;
unsigned short eth_port;
};
+
static int cegw_state = CEGW_STOP;
static struct socket *can_sock = NULL, *udp_sock = NULL;
static struct task_struct *eth_to_can = NULL, *can_to_eth = NULL;
static DEFINE_MUTEX(cegw_mutex);
static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
- struct in_addr ipaddr, u16 port)
+ struct in_addr ipaddr, u16 port)
{
struct msghdr mh;
struct sockaddr_in addr;
vec.iov_base = cf;
vec.iov_len = sizeof(*cf);
+ /* FIXME: Convert endianing of cf->can_id */
kernel_sendmsg(udp_sock, &mh, &vec, 1, sizeof(*cf));
}
}
/**
- * cegw_udp_can - performs udp->can routing
+ * cegw_udp2can - performs udp->can routing
*
* This function is run as a thread.
*/
-static int cegw_udp_can(void *data)
+static int cegw_udp2can(void *data)
{
struct can_frame cf;
struct kvec vec;
int can_ifidx;
int recv_size;
- mh.msg_name = NULL;
- mh.msg_namelen = 0;
- mh.msg_iov = NULL;
- mh.msg_iovlen = 0;
- mh.msg_control = NULL;
- mh.msg_controllen = 0;
- mh.msg_flags = 0;
+ memset(&mh, 0, sizeof(mh));
- while (1) {
- if (cegw_state == CEGW_STOP)
- break;
+ while (cegw_state != CEGW_STOP) {
vec.iov_base = &cf;
vec.iov_len = sizeof(cf);
recv_size = kernel_recvmsg(udp_sock, &mh, &vec, 1,
else if (recv_size < 0)
return -1;
+ /* FIXME: Convert endianing of cf.can_id */
mutex_lock(&rule_eth_can_mutex);
hlist_for_each_entry(rule, pos, &rule_eth_can, list) {
can_ifidx = rule->can_ifindex;
}
/**
- * cegw_can_udp - performs can->udp routing
+ * cegw_can2udp - performs can->udp routing
+ *
+ * Runs as a thread.
*/
-static int cegw_can_udp(void* data)
+static int cegw_can2udp(void* data)
{
struct msghdr mh;
struct kvec vec;
mh.msg_controllen = 0;
mh.msg_flags = 0;
- while (1) {
- if (cegw_state == CEGW_STOP)
- break;
+ while (cegw_state != CEGW_STOP) {
vec.iov_base = &cf;
vec.iov_len = sizeof(cf);
/* start threads */
cegw_state = CEGW_RUN;
- eth_to_can = kthread_create(cegw_udp_can, NULL, "canethgw");
+ eth_to_can = kthread_create(cegw_udp2can, NULL, "canethgw");
if (IS_ERR(eth_to_can)) {
cegw_state = CEGW_STOP;
sock_release(udp_sock);
get_task_struct(eth_to_can);
wake_up_process(eth_to_can);
- can_to_eth = kthread_create(cegw_can_udp, NULL, "canethgw");
+ can_to_eth = kthread_create(cegw_can2udp, NULL, "canethgw");
if (IS_ERR(can_to_eth)) {
cegw_state = CEGW_STOP;
kernel_sock_shutdown(udp_sock, SHUT_RDWR);