2005-04-17 05:20:36 +07:00
|
|
|
/* $Id: isdn_x25iface.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
|
|
|
|
*
|
|
|
|
* Linux ISDN subsystem, X.25 related functions
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
* stuff needed to support the Linux X.25 PLP code on top of devices that
|
|
|
|
* can provide a lab_b service using the concap_proto mechanism.
|
2006-03-25 00:23:14 +07:00
|
|
|
* This module supports a network interface which provides lapb_sematics
|
2005-04-17 05:20:36 +07:00
|
|
|
* -- as defined in Documentation/networking/x25-iface.txt -- to
|
|
|
|
* the upper layer and assumes that the lower layer provides a reliable
|
|
|
|
* data link service by means of the concap_device_ops callbacks.
|
|
|
|
*
|
|
|
|
* Only protocol specific stuff goes here. Device specific stuff
|
|
|
|
* goes to another -- device related -- concap_proto support source file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #include <linux/isdn.h> */
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/concap.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/wanrouter.h>
|
|
|
|
#include <net/x25device.h>
|
|
|
|
#include "isdn_x25iface.h"
|
|
|
|
|
|
|
|
/* for debugging messages not to cause an oops when device pointer is NULL*/
|
2012-02-20 10:52:38 +07:00
|
|
|
#define MY_DEVNAME(dev) ((dev) ? (dev)->name : "DEVICE UNSPECIFIED")
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct isdn_x25iface_proto_data {
|
|
|
|
int magic;
|
|
|
|
enum wan_states state;
|
|
|
|
/* Private stuff, not to be accessed via proto_data. We provide the
|
|
|
|
other storage for the concap_proto instance here as well,
|
2012-02-20 10:52:38 +07:00
|
|
|
enabling us to allocate both with just one kmalloc(): */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct concap_proto priv;
|
|
|
|
} ix25_pdata_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* is now in header file (extern): struct concap_proto * isdn_x25iface_proto_new(void); */
|
2012-02-20 10:52:38 +07:00
|
|
|
static void isdn_x25iface_proto_del(struct concap_proto *);
|
|
|
|
static int isdn_x25iface_proto_close(struct concap_proto *);
|
|
|
|
static int isdn_x25iface_proto_restart(struct concap_proto *,
|
|
|
|
struct net_device *,
|
|
|
|
struct concap_device_ops *);
|
|
|
|
static int isdn_x25iface_xmit(struct concap_proto *, struct sk_buff *);
|
|
|
|
static int isdn_x25iface_receive(struct concap_proto *, struct sk_buff *);
|
|
|
|
static int isdn_x25iface_connect_ind(struct concap_proto *);
|
|
|
|
static int isdn_x25iface_disconn_ind(struct concap_proto *);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
|
|
|
static struct concap_proto_ops ix25_pops = {
|
2016-12-17 08:01:42 +07:00
|
|
|
.proto_new = &isdn_x25iface_proto_new,
|
|
|
|
.proto_del = &isdn_x25iface_proto_del,
|
|
|
|
.restart = &isdn_x25iface_proto_restart,
|
|
|
|
.close = &isdn_x25iface_proto_close,
|
|
|
|
.encap_and_xmit = &isdn_x25iface_xmit,
|
|
|
|
.data_ind = &isdn_x25iface_receive,
|
|
|
|
.connect_ind = &isdn_x25iface_connect_ind,
|
|
|
|
.disconn_ind = &isdn_x25iface_disconn_ind
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* error message helper function */
|
2012-02-20 10:52:38 +07:00
|
|
|
static void illegal_state_warn(unsigned state, unsigned char firstbyte)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-02-20 10:52:38 +07:00
|
|
|
printk(KERN_WARNING "isdn_x25iface: firstbyte %x illegal in"
|
|
|
|
"current state %d\n", firstbyte, state);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check protocol data field for consistency */
|
2012-02-20 10:52:38 +07:00
|
|
|
static int pdata_is_bad(ix25_pdata_t *pda) {
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
if (pda && pda->magic == ISDN_X25IFACE_MAGIC) return 0;
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"isdn_x25iface_xxx: illegal pointer to proto data\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new x25 interface protocol instance
|
|
|
|
*/
|
2012-02-20 10:52:38 +07:00
|
|
|
struct concap_proto *isdn_x25iface_proto_new(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-02-20 10:52:38 +07:00
|
|
|
ix25_pdata_t *tmp = kmalloc(sizeof(ix25_pdata_t), GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_proto_new\n");
|
2012-02-20 10:52:38 +07:00
|
|
|
if (tmp) {
|
|
|
|
tmp->magic = ISDN_X25IFACE_MAGIC;
|
|
|
|
tmp->state = WAN_UNCONFIGURED;
|
2005-04-17 05:20:36 +07:00
|
|
|
/* private data space used to hold the concap_proto data.
|
|
|
|
Only to be accessed via the returned pointer */
|
|
|
|
spin_lock_init(&tmp->priv.lock);
|
2012-02-20 10:52:38 +07:00
|
|
|
tmp->priv.dops = NULL;
|
|
|
|
tmp->priv.net_dev = NULL;
|
|
|
|
tmp->priv.pops = &ix25_pops;
|
|
|
|
tmp->priv.flags = 0;
|
|
|
|
tmp->priv.proto_data = tmp;
|
|
|
|
return (&(tmp->priv));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
/* close the x25iface encapsulation protocol
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2012-02-20 10:52:38 +07:00
|
|
|
static int isdn_x25iface_proto_close(struct concap_proto *cprot) {
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
ix25_pdata_t *tmp;
|
2012-02-20 10:52:38 +07:00
|
|
|
int ret = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
ulong flags;
|
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
if (!cprot) {
|
|
|
|
printk(KERN_ERR "isdn_x25iface_proto_close: "
|
|
|
|
"invalid concap_proto pointer\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_proto_close %s \n", MY_DEVNAME(cprot->net_dev));
|
2005-04-17 05:20:36 +07:00
|
|
|
spin_lock_irqsave(&cprot->lock, flags);
|
2012-02-20 10:52:38 +07:00
|
|
|
cprot->dops = NULL;
|
|
|
|
cprot->net_dev = NULL;
|
|
|
|
tmp = cprot->proto_data;
|
|
|
|
if (pdata_is_bad(tmp)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
ret = -1;
|
|
|
|
} else {
|
2012-02-20 10:52:38 +07:00
|
|
|
tmp->state = WAN_UNCONFIGURED;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cprot->lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the x25iface encapsulation protocol instance
|
|
|
|
*/
|
2012-02-20 10:52:38 +07:00
|
|
|
static void isdn_x25iface_proto_del(struct concap_proto *cprot) {
|
|
|
|
|
|
|
|
ix25_pdata_t *tmp;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_proto_del \n");
|
|
|
|
if (!cprot) {
|
|
|
|
printk(KERN_ERR "isdn_x25iface_proto_del: "
|
|
|
|
"concap_proto pointer is NULL\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
tmp = cprot->proto_data;
|
|
|
|
if (tmp == NULL) {
|
|
|
|
printk(KERN_ERR "isdn_x25iface_proto_del: inconsistent "
|
|
|
|
"proto_data pointer (maybe already deleted?)\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* close if the protocol is still open */
|
2012-02-20 10:52:38 +07:00
|
|
|
if (cprot->dops) isdn_x25iface_proto_close(cprot);
|
2005-04-17 05:20:36 +07:00
|
|
|
/* freeing the storage should be sufficient now. But some additional
|
|
|
|
settings might help to catch wild pointer bugs */
|
2012-02-20 10:52:38 +07:00
|
|
|
tmp->magic = 0;
|
|
|
|
cprot->proto_data = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
kfree(tmp);
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (re-)initialize the data structures for x25iface encapsulation
|
|
|
|
*/
|
2005-06-26 04:58:35 +07:00
|
|
|
static int isdn_x25iface_proto_restart(struct concap_proto *cprot,
|
2012-02-20 10:52:38 +07:00
|
|
|
struct net_device *ndev,
|
|
|
|
struct concap_device_ops *dops)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-02-20 10:52:38 +07:00
|
|
|
ix25_pdata_t *pda = cprot->proto_data;
|
2005-04-17 05:20:36 +07:00
|
|
|
ulong flags;
|
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_proto_restart %s \n", MY_DEVNAME(ndev));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
if (pdata_is_bad(pda)) return -1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
if (!(dops && dops->data_req && dops->connect_req
|
|
|
|
&& dops->disconn_req)) {
|
|
|
|
printk(KERN_WARNING "isdn_x25iface_restart: required dops"
|
|
|
|
" missing\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
isdn_x25iface_proto_close(cprot);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&cprot->lock, flags);
|
2012-02-20 10:52:38 +07:00
|
|
|
cprot->net_dev = ndev;
|
|
|
|
cprot->pops = &ix25_pops;
|
|
|
|
cprot->dops = dops;
|
|
|
|
pda->state = WAN_DISCONNECTED;
|
2005-04-17 05:20:36 +07:00
|
|
|
spin_unlock_irqrestore(&cprot->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
/* deliver a dl_data frame received from i4l HL driver to the network layer
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-06-26 04:58:35 +07:00
|
|
|
static int isdn_x25iface_receive(struct concap_proto *cprot, struct sk_buff *skb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-02-20 10:52:38 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_receive %s \n", MY_DEVNAME(cprot->net_dev));
|
|
|
|
if (((ix25_pdata_t *)(cprot->proto_data))
|
|
|
|
->state == WAN_CONNECTED) {
|
|
|
|
if (skb_push(skb, 1)) {
|
2010-04-19 20:29:06 +07:00
|
|
|
skb->data[0] = X25_IFACE_DATA;
|
2005-04-17 05:20:36 +07:00
|
|
|
skb->protocol = x25_type_trans(skb, cprot->net_dev);
|
|
|
|
netif_rx(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
printk(KERN_WARNING "isdn_x25iface_receive %s: not connected, skb dropped\n", MY_DEVNAME(cprot->net_dev));
|
2005-04-17 05:20:36 +07:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-20 10:52:38 +07:00
|
|
|
/* a connection set up is indicated by lower layer
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-06-26 04:58:35 +07:00
|
|
|
static int isdn_x25iface_connect_ind(struct concap_proto *cprot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-02-20 10:52:38 +07:00
|
|
|
struct sk_buff *skb;
|
|
|
|
enum wan_states *state_p
|
|
|
|
= &(((ix25_pdata_t *)(cprot->proto_data))->state);
|
|
|
|
IX25DEBUG("isdn_x25iface_connect_ind %s \n"
|
|
|
|
, MY_DEVNAME(cprot->net_dev));
|
|
|
|
if (*state_p == WAN_UNCONFIGURED) {
|
|
|
|
printk(KERN_WARNING
|
2005-04-17 05:20:36 +07:00
|
|
|
"isdn_x25iface_connect_ind while unconfigured %s\n"
|
2012-02-20 10:52:38 +07:00
|
|
|
, MY_DEVNAME(cprot->net_dev));
|
2005-04-17 05:20:36 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*state_p = WAN_CONNECTED;
|
2006-06-29 16:24:34 +07:00
|
|
|
|
|
|
|
skb = dev_alloc_skb(1);
|
2012-02-20 10:52:38 +07:00
|
|
|
if (skb) {
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:24 +07:00
|
|
|
skb_put_u8(skb, X25_IFACE_CONNECT);
|
2005-04-17 05:20:36 +07:00
|
|
|
skb->protocol = x25_type_trans(skb, cprot->net_dev);
|
|
|
|
netif_rx(skb);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "isdn_x25iface_connect_ind: "
|
|
|
|
" out of memory -- disconnecting\n");
|
2012-02-20 10:52:38 +07:00
|
|
|
cprot->dops->disconn_req(cprot);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
|
|
|
|
/* a disconnect is indicated by lower layer
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-06-26 04:58:35 +07:00
|
|
|
static int isdn_x25iface_disconn_ind(struct concap_proto *cprot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
2012-02-20 10:52:38 +07:00
|
|
|
enum wan_states *state_p
|
|
|
|
= &(((ix25_pdata_t *)(cprot->proto_data))->state);
|
|
|
|
IX25DEBUG("isdn_x25iface_disconn_ind %s \n", MY_DEVNAME(cprot->net_dev));
|
|
|
|
if (*state_p == WAN_UNCONFIGURED) {
|
|
|
|
printk(KERN_WARNING
|
2005-04-17 05:20:36 +07:00
|
|
|
"isdn_x25iface_disconn_ind while unconfigured\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
if (!cprot->net_dev) return -1;
|
2005-04-17 05:20:36 +07:00
|
|
|
*state_p = WAN_DISCONNECTED;
|
|
|
|
skb = dev_alloc_skb(1);
|
2012-02-20 10:52:38 +07:00
|
|
|
if (skb) {
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:24 +07:00
|
|
|
skb_put_u8(skb, X25_IFACE_DISCONNECT);
|
2005-04-17 05:20:36 +07:00
|
|
|
skb->protocol = x25_type_trans(skb, cprot->net_dev);
|
|
|
|
netif_rx(skb);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "isdn_x25iface_disconn_ind:"
|
|
|
|
" out of memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process a frame handed over to us from linux network layer. First byte
|
|
|
|
semantics as defined in Documentation/networking/x25-iface.txt
|
2012-02-20 10:52:38 +07:00
|
|
|
*/
|
2005-06-26 04:58:35 +07:00
|
|
|
static int isdn_x25iface_xmit(struct concap_proto *cprot, struct sk_buff *skb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned char firstbyte = skb->data[0];
|
2012-02-20 10:52:38 +07:00
|
|
|
enum wan_states *state = &((ix25_pdata_t *)cprot->proto_data)->state;
|
2005-04-17 05:20:36 +07:00
|
|
|
int ret = 0;
|
2010-04-19 20:29:06 +07:00
|
|
|
IX25DEBUG("isdn_x25iface_xmit: %s first=%x state=%d\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
MY_DEVNAME(cprot->net_dev), firstbyte, *state);
|
|
|
|
switch (firstbyte) {
|
2010-04-19 20:29:06 +07:00
|
|
|
case X25_IFACE_DATA:
|
2012-02-20 10:52:38 +07:00
|
|
|
if (*state == WAN_CONNECTED) {
|
2005-04-17 05:20:36 +07:00
|
|
|
skb_pull(skb, 1);
|
2016-05-03 21:33:13 +07:00
|
|
|
netif_trans_update(cprot->net_dev);
|
2012-02-20 10:52:38 +07:00
|
|
|
ret = (cprot->dops->data_req(cprot, skb));
|
2005-04-17 05:20:36 +07:00
|
|
|
/* prepare for future retransmissions */
|
2012-02-20 10:52:38 +07:00
|
|
|
if (ret) skb_push(skb, 1);
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret;
|
|
|
|
}
|
2012-02-20 10:52:38 +07:00
|
|
|
illegal_state_warn(*state, firstbyte);
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
2010-04-19 20:29:06 +07:00
|
|
|
case X25_IFACE_CONNECT:
|
2012-02-20 10:52:38 +07:00
|
|
|
if (*state == WAN_DISCONNECTED) {
|
2005-04-17 05:20:36 +07:00
|
|
|
*state = WAN_CONNECTING;
|
2012-02-20 10:52:38 +07:00
|
|
|
ret = cprot->dops->connect_req(cprot);
|
|
|
|
if (ret) {
|
2005-04-17 05:20:36 +07:00
|
|
|
/* reset state and notify upper layer about
|
|
|
|
* immidiatly failed attempts */
|
|
|
|
isdn_x25iface_disconn_ind(cprot);
|
|
|
|
}
|
|
|
|
} else {
|
2012-02-20 10:52:38 +07:00
|
|
|
illegal_state_warn(*state, firstbyte);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
break;
|
2010-04-19 20:29:06 +07:00
|
|
|
case X25_IFACE_DISCONNECT:
|
2012-02-20 10:52:38 +07:00
|
|
|
switch (*state) {
|
|
|
|
case WAN_DISCONNECTED:
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Should not happen. However, give upper layer a
|
|
|
|
chance to recover from inconstistency but don't
|
|
|
|
trust the lower layer sending the disconn_confirm
|
|
|
|
when already disconnected */
|
|
|
|
printk(KERN_WARNING "isdn_x25iface_xmit: disconnect "
|
2012-02-20 10:52:38 +07:00
|
|
|
" requested while disconnected\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
isdn_x25iface_disconn_ind(cprot);
|
|
|
|
break; /* prevent infinite loops */
|
|
|
|
case WAN_CONNECTING:
|
|
|
|
case WAN_CONNECTED:
|
|
|
|
*state = WAN_DISCONNECTED;
|
2012-02-20 10:52:38 +07:00
|
|
|
cprot->dops->disconn_req(cprot);
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
default:
|
2012-02-20 10:52:38 +07:00
|
|
|
illegal_state_warn(*state, firstbyte);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
break;
|
2010-04-19 20:29:06 +07:00
|
|
|
case X25_IFACE_PARAMS:
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_WARNING "isdn_x25iface_xmit: setting of lapb"
|
|
|
|
" options not yet supported\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "isdn_x25iface_xmit: frame with illegal"
|
|
|
|
" first byte %x ignored:\n", firstbyte);
|
|
|
|
}
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|