New files from Henner Eisen for X.25 support

This commit is contained in:
Karsten Keil 1998-01-31 22:27:59 +00:00
parent f8b9a3759e
commit 86bd533dd2
4 changed files with 471 additions and 0 deletions

102
drivers/isdn/isdn_concap.c Normal file
View file

@ -0,0 +1,102 @@
/* $Id$
/* Stuff to support the concap_proto by isdn4linux. isdn4linux - specific
* stuff goes here. Stuff that depends only on the concap protocol goes to
* another -- protocol specific -- source file.
*
* $Log$
*/
#include <linux/isdn.h>
#include "isdn_x25iface.h"
#include "isdn_net.h"
#include <linux/concap.h>
#include "isdn_concap.h"
/* The declaration of this (or a plublic variant thereof) should really go
in linux/isdn.h. But we really need it here (and isdn_ppp, like us, also
refers to that private function currently owned by isdn_net.c) */
extern int isdn_net_force_dial_lp(isdn_net_local *);
/* The following set of device service operations are for encapsulation
protocols that require for reliable datalink sematics. That means:
- before any data is to be submitted the connection must explicitly
be set up.
- after the successful set up of the connection is signalled the
connection is considered to be reliably up.
Auto-dialing ist not compatible with this requirements. Thus, auto-dialing
is completely bypassed.
It might be possible to implement a (non standardized) datalink protocol
that provides a reliable data link service while using some auto dialing
mechanism. Such a protocol would need an auxiliary channel (i.e. user-user-
signaling on the D-channel) while the B-channel is down.
*/
int isdn_concap_dl_data_req(struct concap_proto *concap, struct sk_buff *skb)
{
int tmp;
struct device *ndev = concap -> net_dev;
isdn_net_local *lp = (isdn_net_local *) ndev->priv;
IX25DEBUG( "isdn_concap_dl_data_req: %s \n", concap->net_dev->name);
lp->huptimer = 0;
tmp=isdn_net_send_skb(ndev, lp, skb);
IX25DEBUG( "isdn_concap_dl_data_req: %s : isdn_net_send_skb returned %d\n", concap -> net_dev -> name, tmp);
return tmp;
}
int isdn_concap_dl_connect_req(struct concap_proto *concap)
{
struct device *ndev = concap -> net_dev;
isdn_net_local *lp = (isdn_net_local *) ndev->priv;
int ret;
IX25DEBUG( "isdn_concap_dl_connect_req: %s \n", ndev -> name);
/* dial ... */
ret = isdn_net_force_dial_lp( lp );
if ( ret ) IX25DEBUG("dialing failed\n");
return 0;
}
int isdn_concap_dl_disconn_req(struct concap_proto *concap)
{
IX25DEBUG( "isdn_concap_dl_disconn_req: %s \n", concap -> net_dev -> name);
isdn_net_hangup( concap -> net_dev );
return 0;
}
struct concap_device_ops isdn_concap_reliable_dl_dops = {
&isdn_concap_dl_data_req,
&isdn_concap_dl_connect_req,
&isdn_concap_dl_disconn_req
};
struct concap_device_ops isdn_concap_demand_dial_dops = {
NULL, /* set this first entry to something like &isdn_net_start_xmit,
but the entry part of the current isdn_net_start_xmit must be
separated first. */
/* no connection control for demand dial semantics */
NULL,
NULL,
};
/* The following should better go into a dedicated source file such that
this sourcefile does not need to include any protocol specific header
files. For now:
*/
struct concap_proto * isdn_concap_new( int encap )
{
switch ( encap ) {
case ISDN_NET_ENCAP_X25IFACE:
return isdn_x25iface_proto_new();
}
return NULL;
}

View file

@ -0,0 +1,6 @@
/* $Id$
extern struct concap_device_ops isdn_concap_reliable_dl_dops;
extern struct concap_device_ops isdn_concap_demand_dial_dops;
extern struct concap_proto * isdn_concap_new( int );

View file

@ -0,0 +1,331 @@
/* $Id$
/* 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.
* This module supports a network interface wich provides lapb_sematics
* -- 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 the concap_device_ops callbacks.
*
* Only protocol specific stuff goes here. Device specific stuff
* goes to another -- device related -- concap_proto support source file.
*
* $Log$
*/
/* #include <linux/isdn.h> */
#include <linux/netdevice.h>
#include <linux/concap.h>
#include <linux/wanrouter.h>
#include "isdn_x25iface.h"
/* for debugging messages not to cause an oops when device pointer is NULL*/
#define MY_DEVNAME(dev) ( (dev) ? (dev)->name : "DEVICE UNSPECIFIED" )
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,
enabling us to allocate both with just one kmalloc(): */
struct concap_proto priv;
} ix25_pdata_t;
/* is now in header file (extern): struct concap_proto * isdn_x25iface_proto_new(void); */
void isdn_x25iface_proto_del( struct concap_proto * );
int isdn_x25iface_proto_close( struct concap_proto * );
int isdn_x25iface_proto_restart( struct concap_proto *,
struct device *,
struct concap_device_ops *);
int isdn_x25iface_xmit( struct concap_proto *, struct sk_buff * );
int isdn_x25iface_receive( struct concap_proto *, struct sk_buff * );
int isdn_x25iface_connect_ind( struct concap_proto * );
int isdn_x25iface_disconn_ind( struct concap_proto * );
static struct concap_proto_ops ix25_pops = {
&isdn_x25iface_proto_new,
&isdn_x25iface_proto_del,
&isdn_x25iface_proto_restart,
&isdn_x25iface_proto_close,
&isdn_x25iface_xmit,
&isdn_x25iface_receive,
&isdn_x25iface_connect_ind,
&isdn_x25iface_disconn_ind
};
/* error message helper fuction */
static void illegal_state_warn( unsigned state, unsigned char firstbyte)
{
printk( KERN_WARNING "isdn_x25iface: firstbyte %x illegal in"
"current state %d\n",firstbyte, state );
}
/* check protocol data field for consistency */
static int pdata_is_bad( ix25_pdata_t * pda ){
if( pda && pda -> magic == ISDN_X25IFACE_MAGIC ) return 0;
printk( KERN_WARNING
"isdn_x25iface_xxx: illegal pointer to proto data\n" );
return 1;
}
/* create a new x25 interface protocol instance
*/
struct concap_proto * isdn_x25iface_proto_new()
{
ix25_pdata_t * tmp = kmalloc(sizeof(ix25_pdata_t),GFP_KERNEL);
IX25DEBUG("isdn_x25iface_proto_new\n");
if( tmp ){
tmp -> magic = ISDN_X25IFACE_MAGIC;
tmp -> state = WAN_UNCONFIGURED;
/* private data space used to hold the concap_proto data.
Only to be accessed via the returned pointer */
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) );
}
return NULL;
};
/* close the x25iface encapsulation protocol
*/
int isdn_x25iface_proto_close(struct concap_proto *cprot){
ix25_pdata_t *tmp;
int ret = 0;
ulong flags;
if( ! cprot ){
printk( KERN_ERR "isdn_x25iface_proto_close: "
"invalid concap_proto pointer\n" );
return -1;
}
IX25DEBUG( "isdn_x25iface_proto_close %s \n", MY_DEVNAME(cprot -> net_dev) );
save_flags(flags);
cli(); /* avoid races with incoming events calling pops methods while
cprot members are inconsistent */
cprot -> dops = NULL;
cprot -> net_dev = NULL;
tmp = cprot -> proto_data;
if( pdata_is_bad( tmp ) ){
ret = -1;
} else {
tmp -> state = WAN_UNCONFIGURED;
}
restore_flags(flags);
return ret;
}
/* Delete the x25iface encapsulation protocol instance
*/
void isdn_x25iface_proto_del(struct concap_proto *cprot){
ix25_pdata_t * tmp;
IX25DEBUG( "isdn_x25iface_proto_del \n" );
if( ! cprot ){
printk( KERN_ERR "isdn_x25iface_proto_del: "
"concap_proto pointer is NULL\n" );
return;
}
tmp = cprot -> proto_data;
if( tmp == NULL ){
printk( KERN_ERR "isdn_x25iface_proto_del: inconsistent "
"proto_data pointer (maybe already deleted?)\n");
return;
}
/* close if the protocol is still open */
if( cprot -> dops ) isdn_x25iface_proto_close(cprot);
/* freeing the storage should be sufficient now. But some additional
settings might help to catch wild pointer bugs */
tmp -> magic = 0;
cprot -> proto_data = NULL;
kfree( tmp );
return;
}
/* (re-)initialize the data structures for x25iface encapsulation
*/
int isdn_x25iface_proto_restart(struct concap_proto *cprot,
struct device *ndev,
struct concap_device_ops *dops)
{
ix25_pdata_t * pda = cprot -> proto_data ;
ulong flags;
IX25DEBUG( "isdn_x25iface_proto_restart %s \n", MY_DEVNAME(ndev) );
if ( pdata_is_bad( pda ) ) return -1;
if( !( dops && dops -> data_req && dops -> connect_req
&& dops -> disconn_req ) ){
printk( KERN_WARNING "isdn_x25iface_restart: required dops"
" missing\n" );
isdn_x25iface_proto_close(cprot);
return -1;
}
save_flags(flags);
cli(); /* avoid races with incoming events calling pops methods while
cprot members are inconsistent */
cprot -> net_dev = ndev;
cprot -> pops = &ix25_pops;
cprot -> dops = dops;
pda -> state = WAN_DISCONNECTED;
restore_flags(flags);
return 0;
}
/* deliver a dl_data frame received from i4l HL driver to the network layer
*/
int isdn_x25iface_receive(struct concap_proto *cprot, struct sk_buff *skb)
{
IX25DEBUG( "isdn_x25iface_receive %s \n", MY_DEVNAME(cprot->net_dev) );
if ( ( (ix25_pdata_t*) (cprot->proto_data) )
-> state == WAN_CONNECTED ){
skb -> dev = cprot -> net_dev;
skb -> protocol = htons(ETH_P_X25);
skb -> pkt_type = PACKET_HOST;
if( skb_push(skb, 1)){
skb -> data[0]=0x00;
skb -> mac.raw = skb -> data;
netif_rx(skb);
return 0;
}
}
printk(KERN_WARNING "isdn_x25iface_receive %s: not connected, skb dropped\n", MY_DEVNAME(cprot->net_dev) );
dev_kfree_skb(skb,FREE_READ);
return -1;
}
/* a connection set up is indicated by lower layer
*/
int isdn_x25iface_connect_ind(struct concap_proto *cprot)
{
struct sk_buff * skb = dev_alloc_skb(1);
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
"isdn_x25iface_connect_ind while unconfigured %s\n"
, MY_DEVNAME(cprot->net_dev) );
return -1;
}
*state_p = WAN_CONNECTED;
if( skb ){
*( skb_put(skb, 1) ) = 0x01;
skb -> mac.raw = skb -> data;
skb -> dev = cprot -> net_dev;
skb -> protocol = htons(ETH_P_X25);
skb -> pkt_type = PACKET_HOST;
netif_rx(skb);
return 0;
} else {
printk(KERN_WARNING "isdn_x25iface_connect_ind: "
" out of memory -- disconnecting\n");
cprot -> dops -> disconn_req(cprot);
return -1;
}
}
/* a disconnect is indicated by lower layer
*/
int isdn_x25iface_disconn_ind(struct concap_proto *cprot)
{
struct sk_buff *skb;
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
"isdn_x25iface_disconn_ind while unconfigured\n");
return -1;
}
if(! cprot -> net_dev) return -1;
*state_p = WAN_DISCONNECTED;
skb = dev_alloc_skb(1);
if( skb ){
*( skb_put(skb, 1) ) = 0x02;
skb -> mac.raw = skb -> data;
skb -> dev = cprot -> net_dev;
skb -> protocol = htons(ETH_P_X25);
skb -> pkt_type = PACKET_HOST;
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
*/
int isdn_x25iface_xmit(struct concap_proto *cprot, struct sk_buff *skb)
{
unsigned char firstbyte = skb->data[0];
unsigned *state =
&( ( (ix25_pdata_t*) (cprot -> proto_data) ) -> state );
int ret = 0;
IX25DEBUG( "isdn_x25iface_xmit: %s first=%x state=%d \n", MY_DEVNAME(cprot -> net_dev), firstbyte, *state );
switch ( firstbyte ){
case 0x00: /* dl_data request */
if( *state == WAN_CONNECTED ){
skb_pull(skb, 1);
cprot -> net_dev -> trans_start = jiffies;
ret = ( cprot -> dops -> data_req(cprot, skb) );
/* prepare for future retransmissions */
if( ret ) skb_push(skb,1);
return ret;
}
illegal_state_warn( *state, firstbyte );
break;
case 0x01: /* dl_connect request */
if( *state == WAN_DISCONNECTED ){
*state = WAN_CONNECTING;
cprot -> dops -> connect_req(cprot);
} else {
illegal_state_warn( *state, firstbyte );
}
break;
case 0x02: /* dl_disconnect request */
switch ( *state ){
case WAN_DISCONNECTED:
/* 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 "
" requested while disconnected\n" );
isdn_x25iface_disconn_ind(cprot);
break; /* prevent infinite loops */
case WAN_CONNECTING:
case WAN_CONNECTED:
*state = WAN_DISCONNECTED;
cprot -> dops -> disconn_req(cprot);
break;
default:
illegal_state_warn( *state, firstbyte );
}
break;
case 0x03: /* changing lapb parameters requested */
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,FREE_WRITE);
return 0;
}

View file

@ -0,0 +1,32 @@
/* $Id$
#ifndef _LINUX_ISDN_X25IFACE_H
#define _LINUX_ISDN_X25IFACE_H
#define ISDN_X25IFACE_MAGIC 0x1e75a2b9
/* #define DEBUG_ISDN_X25 if you want isdn_x25 debugging messages */
#ifdef DEBUG_ISDN_X25
# define IX25DEBUG(fmt,args...) printk(KERN_DEBUG fmt , ## args)
#else
# define IX25DEBUG(fmt,args...)
#endif
#include <linux/skbuff.h>
#include <linux/wanrouter.h>
#include <linux/isdn.h>
#include <linux/concap.h>
extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
extern struct concap_proto * isdn_x25iface_proto_new(void);
#endif