Release 4.11 drivers/isdn/i4l/isdn_x25iface.c
/* $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.
* This module supports a network interface which 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 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 <linux/slab.h>
#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*/
#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); */
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 *);
static struct concap_proto_ops ix25_pops = {
.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
};
/* error message helper function */
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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 23 | 95.83% | 1 | 50.00% |
Andrew Morton | 1 | 4.17% | 1 | 50.00% |
Total | 24 | 100.00% | 2 | 100.00% |
/* 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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 31 | 96.88% | 1 | 50.00% |
Andrew Morton | 1 | 3.12% | 1 | 50.00% |
Total | 32 | 100.00% | 2 | 100.00% |
/* create a new x25 interface protocol instance
*/
struct concap_proto *isdn_x25iface_proto_new(void)
{
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 */
spin_lock_init(&tmp->priv.lock);
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;
}Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 98 | 88.29% | 1 | 33.33% |
Andrew Morton | 10 | 9.01% | 1 | 33.33% |
Al Viro | 3 | 2.70% | 1 | 33.33% |
Total | 111 | 100.00% | 3 | 100.00% |
;
/* close the x25iface encapsulation protocol
*/
static 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));
spin_lock_irqsave(&cprot->lock, flags);
cprot->dops = NULL;
cprot->net_dev = NULL;
tmp = cprot->proto_data;
if (pdata_is_bad(tmp)) {
ret = -1;
} else {
tmp->state = WAN_UNCONFIGURED;
}
spin_unlock_irqrestore(&cprot->lock, flags);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 104 | 88.89% | 1 | 33.33% |
Andrew Morton | 12 | 10.26% | 1 | 33.33% |
Adrian Bunk | 1 | 0.85% | 1 | 33.33% |
Total | 117 | 100.00% | 3 | 100.00% |
/* Delete the x25iface encapsulation protocol instance
*/
static 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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 87 | 98.86% | 1 | 50.00% |
Adrian Bunk | 1 | 1.14% | 1 | 50.00% |
Total | 88 | 100.00% | 2 | 100.00% |
/* (re-)initialize the data structures for x25iface encapsulation
*/
static int isdn_x25iface_proto_restart(struct concap_proto *cprot,
struct net_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;
}
spin_lock_irqsave(&cprot->lock, flags);
cprot->net_dev = ndev;
cprot->pops = &ix25_pops;
cprot->dops = dops;
pda->state = WAN_DISCONNECTED;
spin_unlock_irqrestore(&cprot->lock, flags);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 125 | 90.58% | 2 | 50.00% |
Andrew Morton | 12 | 8.70% | 1 | 25.00% |
Adrian Bunk | 1 | 0.72% | 1 | 25.00% |
Total | 138 | 100.00% | 4 | 100.00% |
/* deliver a dl_data frame received from i4l HL driver to the network layer
*/
static 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) {
if (skb_push(skb, 1)) {
skb->data[0] = X25_IFACE_DATA;
skb->protocol = x25_type_trans(skb, cprot->net_dev);
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);
return -1;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 102 | 91.89% | 1 | 25.00% |
Arnaldo Carvalho de Melo | 7 | 6.31% | 1 | 25.00% |
Andrew Hendry | 1 | 0.90% | 1 | 25.00% |
Adrian Bunk | 1 | 0.90% | 1 | 25.00% |
Total | 111 | 100.00% | 4 | 100.00% |
/* a connection set up is indicated by lower layer
*/
static int isdn_x25iface_connect_ind(struct concap_proto *cprot)
{
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
"isdn_x25iface_connect_ind while unconfigured %s\n"
, MY_DEVNAME(cprot->net_dev));
return -1;
}
*state_p = WAN_CONNECTED;
skb = dev_alloc_skb(1);
if (skb) {
*(skb_put(skb, 1)) = X25_IFACE_CONNECT;
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");
cprot->dops->disconn_req(cprot);
return -1;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 137 | 91.33% | 1 | 20.00% |
Eric Sesterhenn / Snakebyte | 7 | 4.67% | 1 | 20.00% |
Arnaldo Carvalho de Melo | 4 | 2.67% | 1 | 20.00% |
Andrew Hendry | 1 | 0.67% | 1 | 20.00% |
Adrian Bunk | 1 | 0.67% | 1 | 20.00% |
Total | 150 | 100.00% | 5 | 100.00% |
/* a disconnect is indicated by lower layer
*/
static 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)) = X25_IFACE_DISCONNECT;
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;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 139 | 95.86% | 1 | 25.00% |
Arnaldo Carvalho de Melo | 4 | 2.76% | 1 | 25.00% |
Adrian Bunk | 1 | 0.69% | 1 | 25.00% |
Andrew Hendry | 1 | 0.69% | 1 | 25.00% |
Total | 145 | 100.00% | 4 | 100.00% |
/* process a frame handed over to us from linux network layer. First byte
semantics as defined in Documentation/networking/x25-iface.txt
*/
static int isdn_x25iface_xmit(struct concap_proto *cprot, struct sk_buff *skb)
{
unsigned char firstbyte = skb->data[0];
enum wan_states *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 X25_IFACE_DATA:
if (*state == WAN_CONNECTED) {
skb_pull(skb, 1);
netif_trans_update(cprot->net_dev);
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 X25_IFACE_CONNECT:
if (*state == WAN_DISCONNECTED) {
*state = WAN_CONNECTING;
ret = cprot->dops->connect_req(cprot);
if (ret) {
/* reset state and notify upper layer about
* immidiatly failed attempts */
isdn_x25iface_disconn_ind(cprot);
}
} else {
illegal_state_warn(*state, firstbyte);
}
break;
case X25_IFACE_DISCONNECT:
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 X25_IFACE_PARAMS:
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 266 | 95.68% | 2 | 28.57% |
Andrew Hendry | 5 | 1.80% | 1 | 14.29% |
Florian Westphal | 3 | 1.08% | 1 | 14.29% |
Al Viro | 2 | 0.72% | 1 | 14.29% |
Adrian Bunk | 1 | 0.36% | 1 | 14.29% |
Andrew Morton | 1 | 0.36% | 1 | 14.29% |
Total | 278 | 100.00% | 7 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 1260 | 90.84% | 4 | 26.67% |
Andrew Morton | 38 | 2.74% | 1 | 6.67% |
Kees Cook | 24 | 1.73% | 1 | 6.67% |
Arnaldo Carvalho de Melo | 18 | 1.30% | 1 | 6.67% |
Adrian Bunk | 14 | 1.01% | 1 | 6.67% |
Andrew Hendry | 8 | 0.58% | 1 | 6.67% |
Eric Sesterhenn / Snakebyte | 7 | 0.50% | 1 | 6.67% |
Joe Perches | 6 | 0.43% | 1 | 6.67% |
Al Viro | 5 | 0.36% | 1 | 6.67% |
Tejun Heo | 3 | 0.22% | 1 | 6.67% |
Florian Westphal | 3 | 0.22% | 1 | 6.67% |
Uwe Zeisberger (is this really Uwe?) | 1 | 0.07% | 1 | 6.67% |
Total | 1387 | 100.00% | 15 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.