IrDA: IrLAP raw mode
Subsystems (2)
PATCH 3/6 IrDA: IrLAP raw mode
This patch allows us to bypass the IrDA stack down to the IrLAP level. Sending and receiving frames is done through a character device. This is useful for e.g. doing real IrDA sniffing, testing external IrDA stacks and for Lirc (once I will add the framing disabling switch).
--- include/net/irda/irlap.h | 5 + include/net/irda/irlap_raw.h | 27 +++ net/irda/Kconfig | 10 ++ net/irda/Makefile | 1 + net/irda/irlap.c | 5 + net/irda/irlap_event.c | 5 + net/irda/irlap_frame.c | 6 + net/irda/irlap_raw.c | 358 ++++++++++++++++++++++++++++++++++++++++++ net/irda/irsysctl.c | 16 ++- 9 files changed, 432 insertions(+), 1 deletions(-) create mode 100644 include/net/irda/irlap_raw.h create mode 100644 net/irda/irlap_raw.c
include/net/irda/irlap.h +5 -0
@@ -36,6 +36,7 @@#include <net/irda/qos.h> /* struct qos_info */ #include <net/irda/discovery.h> /* discovery_t */ #include <net/irda/irlap_event.h> /* IRLAP_STATE, ... */ +#include <net/irda/irlap_raw.h> /* IRLAP raw definitions */ #include <net/irda/irmod.h> /* struct notify_t */ #define CONFIG_IRDA_DYNAMIC_WINDOW 1
@@ -208,6 +209,10 @@ struct irlap_cb {int xbofs_delay;/* Nr of XBOF's used to MTT */ int bofs_count;/* Negotiated extra BOFs */ int next_bofs;/* Negotiated extra BOFs after next frame */ +#ifdef CONFIG_IRDA_RAW +int raw_mode; +struct irlap_raw * irlap_raw; +#endif };/*
include/net/irda/irlap_raw.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2007 Samuel Ortiz ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +* +*/ + +#ifndef _IRLAP_RAW_H +#define _IRLAP_RAW_H + +#ifdef CONFIG_IRDA_RAW + +int irlap_raw_recv_frame (struct sk_buff *skb,struct net_device *dev); +int irlap_raw_register_device (struct net_device * dev); +int irlap_raw_unregister_device (struct net_device * dev); + +#else + +#define irlap_raw_recv_frame (skbuff, netdev) +#define irlap_raw_register_device (netdev) +#define irlap_raw_unregister_device (netdev) + +#endif + +#endif
net/irda/Kconfig +10 -0
@@ -92,5 +92,15 @@ config IRDA_DEBUG If unsure, say Y (since it makes it easier to find the bugs). +config IRDA_RAW + bool "IrLAP raw" + depends on IRDA + help + Say Y if you want to bypass the IrDA stack, down to the IrLAP level. + This option allows you to send and receive IrLAP frames from + userspace, by writing and reading to a character device + (/dev/irdaX_raw). Note that the IrDA stack will be mostly disabled. + If unsure, say N. + source "drivers/net/irda/Kconfig"
net/irda/Makefile +1 -0
@@ -13,3 +13,4 @@ irda-y := iriap.o iriap_event.o irlmp.o irlmp_event.o irlmp_frame.o \ discovery.o parameters.o irmod.o irda-$(CONFIG_PROC_FS) += irproc.o irda-$(CONFIG_SYSCTL) += irsysctl.o +irda-$(CONFIG_IRDA_RAW) += irlap_raw.o
net/irda/irlap.c +5 -0
@@ -173,6 +173,8 @@ struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,irlmp_register_link (self, self->saddr, &self->notify); +irlap_raw_register_device (dev); +return self; }EXPORT_SYMBOL (irlap_open);
@@ -234,6 +236,9 @@ void irlap_close(struct irlap_cb *self)IRDA_DEBUG (1 ,"%s(), Didn't find myself!\n" , __FUNCTION__);return ; } + +irlap_raw_unregister_device (self->netdev); +__irlap_close (lap); }EXPORT_SYMBOL (irlap_close);
net/irda/irlap_event.c +5 -0
@@ -241,6 +241,11 @@ void irlap_do_event(struct irlap_cb *self, IRLAP_EVENT event,if (!self || self->magic !=LAP_MAGIC )return ; +#ifdef CONFIG_IRDA_RAW +if (self->raw_mode) +return ; +#endif +IRDA_DEBUG (3 ,"%s(), event = %s, state = %s\n" , __FUNCTION__, irlap_event[event], irlap_state[self->state]);
net/irda/irlap_frame.c +6 -0
@@ -1323,6 +1323,12 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,return -1 ; } +#ifdef CONFIG_IRDA_RAW +if (self->raw_mode) { +return irlap_raw_recv_frame (skb, dev); + } +#endif +/* We are no longer an "old" protocol, so we need to handle * share and non linear skbs. This should never happen, so * we don't need to be clever about it. Jean II */
net/irda/irlap_raw.c new file +358 -0
358 lines not on this page · raw message
net/irda/irsysctl.c +15 -1
@@ -35,7 +35,7 @@enum {DISCOVERY =1 ,DEVNAME ,DEBUG ,FAST_POLL ,DISCOVERY_SLOTS ,DISCOVERY_TIMEOUT ,SLOT_TIMEOUT ,MAX_BAUD_RATE ,MIN_TX_TURN_TIME ,MAX_TX_DATA_SIZE ,MAX_TX_WINDOW ,MAX_NOREPLY_TIME ,WARN_NOREPLY_TIME , -LAP_KEEPALIVE_TIME }; +LAP_KEEPALIVE_TIME ,RAW_RING_LENGTH };extern int sysctl_discovery;extern int sysctl_discovery_slots;
@@ -50,6 +50,9 @@ extern int sysctl_max_tx_window;extern int sysctl_max_noreply_time;extern int sysctl_warn_noreply_time;extern int sysctl_lap_keepalive_time; +#ifdef CONFIG_IRDA_RAW +extern unsigned int sysctl_raw_ring_length; +#endif /* this is needed for the proc_dointvec_minmax - Jean II */ static int max_discovery_slots =16 ;/* ??? */
@@ -237,6 +240,17 @@ static ctl_table irda_table[] = { .extra1 = &min_lap_keepalive_time, .extra2 = &max_lap_keepalive_time }, +#ifdef CONFIG_IRDA_RAW + { + .ctl_name = RAW_RING_LENGTH, + .procname = "raw_ring_length", + .data = &sysctl_raw_ring_length, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec + }, +#endif + { .ctl_name = 0 } };
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Hi Samuel,
Quoted 4 lines · Samuel Ortiz
This patch allows us to bypass the IrDA stack down to the IrLAP level. Sending and receiving frames is done through a character device. This is useful for e.g. doing real IrDA sniffing, testing external IrDA stacks and for Lirc (once I will add the framing disabling switch).
Nice!
Quoted 16 lines
include/net/irda/irlap_raw.h new file +13
-0@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2007 Samuel Ortiz ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +* +*/ + +#ifndef _IRLAP_RAW_H +#define _IRLAP_RAW_H + +#ifdef CONFIG_IRDA_RAW
include/net/irda/irlap_raw.h line 23
Quoted 10 lines
include/net/irda/irlap_raw.h new file +10
-0+ +int irlap_raw_recv_frame (struct sk_buff *skb,struct net_device *dev); +int irlap_raw_register_device (struct net_device * dev); +int irlap_raw_unregister_device (struct net_device * dev); + +#else + +#define irlap_raw_recv_frame (skbuff, netdev) +#define irlap_raw_register_device (netdev) +#define irlap_raw_unregister_device (netdev)
This stuff is usually done this way (functions, which just check arguments and do nothing):
static inline int irlap_raw_recv_frame(struct sk_buff *skb, struct net_device *dev)
{
if (skb == NULL)
return -EINVAL;
if (dev->atalk_ptr == NULL)
return -ENODEV;
return 0;
}static inline int irlap_raw_register_device(struct net_device * dev)
{
if (dev == NULL)
return -ENODEV;
return 0;
}statice inline int irlap_raw_unregister_device(struct net_device * dev)
{
if (dev == NULL)
return -ENODEV;
return 0;
}net/irda/irlap_event.c void irlap_do_event(struct irlap_cb *self, IRLAP_EVENT event, · line 247
Quoted 10 lines
net/irda/irlap_event.c +4
-0@@ -241,6 +241,11 @@ void irlap_do_event(struct irlap_cb *self, IRLAP_EVENT event,if (!self || self->magic !=LAP_MAGIC )return ; +if (self->raw_mode) +return ; +#endif +
I would suggest a small helper function here, which compiles into a constant, if raw_mode is not compiled in.
like
#ifdef CONFIG_IRDA_RAW
static inline int irlap_raw_mod(struct irlap_cb *self)
{
return self->raw_mode;
}
#else
static inline int irlap_raw_mod(struct irlap_cb *self)
{
return 0;
}#endif
Best Regards
Ingo Oeser
Hi Ingo,
Quoted 20 lines · Ingo Oeser
Quoted 20 lines
include/net/irda/irlap_raw.h new file +17
-0@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2007 Samuel Ortiz ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +* +*/ + +#ifndef _IRLAP_RAW_H +#define _IRLAP_RAW_H + +#ifdef CONFIG_IRDA_RAW + +int irlap_raw_recv_frame (struct sk_buff *skb,struct net_device *dev); +int irlap_raw_register_device (struct net_device * dev); +int irlap_raw_unregister_device (struct net_device * dev);
Quoted 8 lines
include/net/irda/irlap_raw.h line 23
Quoted 6 lines
include/net/irda/irlap_raw.h new file +6
-0+ +#else + +#define irlap_raw_recv_frame (skbuff, netdev) +#define irlap_raw_register_device (netdev) +#define irlap_raw_unregister_device (netdev)This stuff is usually done this way (functions, which just check arguments and do nothing):
Since those are exported symbols, I think it makes sense to do these checks.
Quoted 5 lines
I would suggest a small helper function here, which compiles into a constant, if
raw_modeis not compiled in.like
This would prevent us from adding #ifdefs in the core IrDA code: I'll go for it.
Thanks for the comments.
Cheers,
Samuel.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV