OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [ax25/] [ax25_in.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/*
/*
 *      AX.25 release 037
 *      AX.25 release 037
 *
 *
 *      This code REQUIRES 2.1.15 or higher/ NET3.038
 *      This code REQUIRES 2.1.15 or higher/ NET3.038
 *
 *
 *      This module:
 *      This module:
 *              This module is free software; you can redistribute it and/or
 *              This module is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 *              2 of the License, or (at your option) any later version.
 *
 *
 *      Most of this code is based on the SDL diagrams published in the 7th
 *      Most of this code is based on the SDL diagrams published in the 7th
 *      ARRL Computer Networking Conference papers. The diagrams have mistakes
 *      ARRL Computer Networking Conference papers. The diagrams have mistakes
 *      in them, but are mostly correct. Before you modify the code could you
 *      in them, but are mostly correct. Before you modify the code could you
 *      read the SDL diagrams as the code is not obvious and probably very
 *      read the SDL diagrams as the code is not obvious and probably very
 *      easy to break;
 *      easy to break;
 *
 *
 *      History
 *      History
 *      AX.25 028a      Jonathan(G4KLX) New state machine based on SDL diagrams.
 *      AX.25 028a      Jonathan(G4KLX) New state machine based on SDL diagrams.
 *      AX.25 028b      Jonathan(G4KLX) Extracted AX25 control block from
 *      AX.25 028b      Jonathan(G4KLX) Extracted AX25 control block from
 *                                      the sock structure.
 *                                      the sock structure.
 *      AX.25 029       Alan(GW4PTS)    Switched to KA9Q constant names.
 *      AX.25 029       Alan(GW4PTS)    Switched to KA9Q constant names.
 *                      Jonathan(G4KLX) Added IP mode registration.
 *                      Jonathan(G4KLX) Added IP mode registration.
 *      AX.25 030       Jonathan(G4KLX) Added AX.25 fragment reception.
 *      AX.25 030       Jonathan(G4KLX) Added AX.25 fragment reception.
 *                                      Upgraded state machine for SABME.
 *                                      Upgraded state machine for SABME.
 *                                      Added arbitrary protocol id support.
 *                                      Added arbitrary protocol id support.
 *      AX.25 031       Joerg(DL1BKE)   Added DAMA support
 *      AX.25 031       Joerg(DL1BKE)   Added DAMA support
 *                      HaJo(DD8NE)     Added Idle Disc Timer T5
 *                      HaJo(DD8NE)     Added Idle Disc Timer T5
 *                      Joerg(DL1BKE)   Renamed it to "IDLE" with a slightly
 *                      Joerg(DL1BKE)   Renamed it to "IDLE" with a slightly
 *                                      different behaviour. Fixed defrag
 *                                      different behaviour. Fixed defrag
 *                                      routine (I hope)
 *                                      routine (I hope)
 *      AX.25 032       Darryl(G7LED)   AX.25 segmentation fixed.
 *      AX.25 032       Darryl(G7LED)   AX.25 segmentation fixed.
 *      AX.25 033       Jonathan(G4KLX) Remove auto-router.
 *      AX.25 033       Jonathan(G4KLX) Remove auto-router.
 *                                      Modularisation changes.
 *                                      Modularisation changes.
 *      AX.25 035       Hans(PE1AYX)    Fixed interface to IP layer.
 *      AX.25 035       Hans(PE1AYX)    Fixed interface to IP layer.
 *      AX.25 036       Jonathan(G4KLX) Move DAMA code into own file.
 *      AX.25 036       Jonathan(G4KLX) Move DAMA code into own file.
 *                      Joerg(DL1BKE)   Fixed DAMA Slave.
 *                      Joerg(DL1BKE)   Fixed DAMA Slave.
 *      AX.25 037       Jonathan(G4KLX) New timer architecture.
 *      AX.25 037       Jonathan(G4KLX) New timer architecture.
 *                      Thomas(DL9SAU)  Fixed missing initialization of skb->protocol.
 *                      Thomas(DL9SAU)  Fixed missing initialization of skb->protocol.
 */
 */
 
 
#include <linux/config.h>
#include <linux/config.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/net.h>
#include <net/ax25.h>
#include <net/ax25.h>
#include <linux/inet.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/netfilter.h>
#include <linux/netfilter.h>
#include <net/sock.h>
#include <net/sock.h>
#include <net/ip.h>                     /* For ip_rcv */
#include <net/ip.h>                     /* For ip_rcv */
#include <net/arp.h>                    /* For arp_rcv */
#include <net/arp.h>                    /* For arp_rcv */
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/system.h>
#include <linux/fcntl.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/interrupt.h>
 
 
/*
/*
 *      Given a fragment, queue it on the fragment queue and if the fragment
 *      Given a fragment, queue it on the fragment queue and if the fragment
 *      is complete, send it back to ax25_rx_iframe.
 *      is complete, send it back to ax25_rx_iframe.
 */
 */
static int ax25_rx_fragment(ax25_cb *ax25, struct sk_buff *skb)
static int ax25_rx_fragment(ax25_cb *ax25, struct sk_buff *skb)
{
{
        struct sk_buff *skbn, *skbo;
        struct sk_buff *skbn, *skbo;
 
 
        if (ax25->fragno != 0) {
        if (ax25->fragno != 0) {
                if (!(*skb->data & AX25_SEG_FIRST)) {
                if (!(*skb->data & AX25_SEG_FIRST)) {
                        if ((ax25->fragno - 1) == (*skb->data & AX25_SEG_REM)) {
                        if ((ax25->fragno - 1) == (*skb->data & AX25_SEG_REM)) {
                                /* Enqueue fragment */
                                /* Enqueue fragment */
                                ax25->fragno = *skb->data & AX25_SEG_REM;
                                ax25->fragno = *skb->data & AX25_SEG_REM;
                                skb_pull(skb, 1);       /* skip fragno */
                                skb_pull(skb, 1);       /* skip fragno */
                                ax25->fraglen += skb->len;
                                ax25->fraglen += skb->len;
                                skb_queue_tail(&ax25->frag_queue, skb);
                                skb_queue_tail(&ax25->frag_queue, skb);
 
 
                                /* Last fragment received ? */
                                /* Last fragment received ? */
                                if (ax25->fragno == 0) {
                                if (ax25->fragno == 0) {
                                        skbn = alloc_skb(AX25_MAX_HEADER_LEN +
                                        skbn = alloc_skb(AX25_MAX_HEADER_LEN +
                                                         ax25->fraglen,
                                                         ax25->fraglen,
                                                         GFP_ATOMIC);
                                                         GFP_ATOMIC);
                                        if (!skbn) {
                                        if (!skbn) {
                                                skb_queue_purge(&ax25->frag_queue);
                                                skb_queue_purge(&ax25->frag_queue);
                                                return 1;
                                                return 1;
                                        }
                                        }
 
 
                                        skb_reserve(skbn, AX25_MAX_HEADER_LEN);
                                        skb_reserve(skbn, AX25_MAX_HEADER_LEN);
 
 
                                        skbn->dev   = ax25->ax25_dev->dev;
                                        skbn->dev   = ax25->ax25_dev->dev;
                                        skbn->h.raw = skbn->data;
                                        skbn->h.raw = skbn->data;
                                        skbn->nh.raw = skbn->data;
                                        skbn->nh.raw = skbn->data;
 
 
                                        /* Copy data from the fragments */
                                        /* Copy data from the fragments */
                                        while ((skbo = skb_dequeue(&ax25->frag_queue)) != NULL) {
                                        while ((skbo = skb_dequeue(&ax25->frag_queue)) != NULL) {
                                                memcpy(skb_put(skbn, skbo->len), skbo->data, skbo->len);
                                                memcpy(skb_put(skbn, skbo->len), skbo->data, skbo->len);
                                                kfree_skb(skbo);
                                                kfree_skb(skbo);
                                        }
                                        }
 
 
                                        ax25->fraglen = 0;
                                        ax25->fraglen = 0;
 
 
                                        if (ax25_rx_iframe(ax25, skbn) == 0)
                                        if (ax25_rx_iframe(ax25, skbn) == 0)
                                                kfree_skb(skbn);
                                                kfree_skb(skbn);
                                }
                                }
 
 
                                return 1;
                                return 1;
                        }
                        }
                }
                }
        } else {
        } else {
                /* First fragment received */
                /* First fragment received */
                if (*skb->data & AX25_SEG_FIRST) {
                if (*skb->data & AX25_SEG_FIRST) {
                        skb_queue_purge(&ax25->frag_queue);
                        skb_queue_purge(&ax25->frag_queue);
                        ax25->fragno = *skb->data & AX25_SEG_REM;
                        ax25->fragno = *skb->data & AX25_SEG_REM;
                        skb_pull(skb, 1);               /* skip fragno */
                        skb_pull(skb, 1);               /* skip fragno */
                        ax25->fraglen = skb->len;
                        ax25->fraglen = skb->len;
                        skb_queue_tail(&ax25->frag_queue, skb);
                        skb_queue_tail(&ax25->frag_queue, skb);
                        return 1;
                        return 1;
                }
                }
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 *      This is where all valid I frames are sent to, to be dispatched to
 *      This is where all valid I frames are sent to, to be dispatched to
 *      whichever protocol requires them.
 *      whichever protocol requires them.
 */
 */
int ax25_rx_iframe(ax25_cb *ax25, struct sk_buff *skb)
int ax25_rx_iframe(ax25_cb *ax25, struct sk_buff *skb)
{
{
        int (*func)(struct sk_buff *, ax25_cb *);
        int (*func)(struct sk_buff *, ax25_cb *);
        volatile int queued = 0;
        volatile int queued = 0;
        unsigned char pid;
        unsigned char pid;
 
 
        if (skb == NULL) return 0;
        if (skb == NULL) return 0;
 
 
        ax25_start_idletimer(ax25);
        ax25_start_idletimer(ax25);
 
 
        pid = *skb->data;
        pid = *skb->data;
 
 
#ifdef CONFIG_INET
#ifdef CONFIG_INET
        if (pid == AX25_P_IP) {
        if (pid == AX25_P_IP) {
                /* working around a TCP bug to keep additional listeners
                /* working around a TCP bug to keep additional listeners
                 * happy. TCP re-uses the buffer and destroys the original
                 * happy. TCP re-uses the buffer and destroys the original
                 * content.
                 * content.
                 */
                 */
                struct sk_buff *skbn = skb_copy(skb, GFP_ATOMIC);
                struct sk_buff *skbn = skb_copy(skb, GFP_ATOMIC);
                if (skbn != NULL) {
                if (skbn != NULL) {
                        kfree_skb(skb);
                        kfree_skb(skb);
                        skb = skbn;
                        skb = skbn;
                }
                }
 
 
                skb_pull(skb, 1);       /* Remove PID */
                skb_pull(skb, 1);       /* Remove PID */
                skb->h.raw    = skb->data;
                skb->h.raw    = skb->data;
                skb->nh.raw   = skb->data;
                skb->nh.raw   = skb->data;
                skb->dev      = ax25->ax25_dev->dev;
                skb->dev      = ax25->ax25_dev->dev;
                skb->pkt_type = PACKET_HOST;
                skb->pkt_type = PACKET_HOST;
                skb->protocol = htons(ETH_P_IP);
                skb->protocol = htons(ETH_P_IP);
                ip_rcv(skb, skb->dev, NULL);    /* Wrong ptype */
                ip_rcv(skb, skb->dev, NULL);    /* Wrong ptype */
                return 1;
                return 1;
        }
        }
#endif
#endif
        if (pid == AX25_P_SEGMENT) {
        if (pid == AX25_P_SEGMENT) {
                skb_pull(skb, 1);       /* Remove PID */
                skb_pull(skb, 1);       /* Remove PID */
                return ax25_rx_fragment(ax25, skb);
                return ax25_rx_fragment(ax25, skb);
        }
        }
 
 
        if ((func = ax25_protocol_function(pid)) != NULL) {
        if ((func = ax25_protocol_function(pid)) != NULL) {
                skb_pull(skb, 1);       /* Remove PID */
                skb_pull(skb, 1);       /* Remove PID */
                return (*func)(skb, ax25);
                return (*func)(skb, ax25);
        }
        }
 
 
        if (ax25->sk != NULL && ax25->ax25_dev->values[AX25_VALUES_CONMODE] == 2) {
        if (ax25->sk != NULL && ax25->ax25_dev->values[AX25_VALUES_CONMODE] == 2) {
                if ((!ax25->pidincl && ax25->sk->protocol == pid) || ax25->pidincl) {
                if ((!ax25->pidincl && ax25->sk->protocol == pid) || ax25->pidincl) {
                        if (sock_queue_rcv_skb(ax25->sk, skb) == 0)
                        if (sock_queue_rcv_skb(ax25->sk, skb) == 0)
                                queued = 1;
                                queued = 1;
                        else
                        else
                                ax25->condition |= AX25_COND_OWN_RX_BUSY;
                                ax25->condition |= AX25_COND_OWN_RX_BUSY;
                }
                }
        }
        }
 
 
        return queued;
        return queued;
}
}
 
 
/*
/*
 *      Higher level upcall for a LAPB frame
 *      Higher level upcall for a LAPB frame
 */
 */
static int ax25_process_rx_frame(ax25_cb *ax25, struct sk_buff *skb, int type, int dama)
static int ax25_process_rx_frame(ax25_cb *ax25, struct sk_buff *skb, int type, int dama)
{
{
        int queued = 0;
        int queued = 0;
 
 
        if (ax25->state == AX25_STATE_0)
        if (ax25->state == AX25_STATE_0)
                return 0;
                return 0;
 
 
        switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
        switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
                case AX25_PROTO_STD_SIMPLEX:
                case AX25_PROTO_STD_SIMPLEX:
                case AX25_PROTO_STD_DUPLEX:
                case AX25_PROTO_STD_DUPLEX:
                        queued = ax25_std_frame_in(ax25, skb, type);
                        queued = ax25_std_frame_in(ax25, skb, type);
                        break;
                        break;
 
 
#ifdef CONFIG_AX25_DAMA_SLAVE
#ifdef CONFIG_AX25_DAMA_SLAVE
                case AX25_PROTO_DAMA_SLAVE:
                case AX25_PROTO_DAMA_SLAVE:
                        if (dama || ax25->ax25_dev->dama.slave)
                        if (dama || ax25->ax25_dev->dama.slave)
                                queued = ax25_ds_frame_in(ax25, skb, type);
                                queued = ax25_ds_frame_in(ax25, skb, type);
                        else
                        else
                                queued = ax25_std_frame_in(ax25, skb, type);
                                queued = ax25_std_frame_in(ax25, skb, type);
                        break;
                        break;
#endif
#endif
        }
        }
 
 
        return queued;
        return queued;
}
}
 
 
static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ax25_address *dev_addr, struct packet_type *ptype)
static int ax25_rcv(struct sk_buff *skb, struct net_device *dev, ax25_address *dev_addr, struct packet_type *ptype)
{
{
        struct sock *make;
        struct sock *make;
        struct sock *sk;
        struct sock *sk;
        int type = 0;
        int type = 0;
        ax25_digi dp, reverse_dp;
        ax25_digi dp, reverse_dp;
        ax25_cb *ax25;
        ax25_cb *ax25;
        ax25_address src, dest;
        ax25_address src, dest;
        ax25_address *next_digi = NULL;
        ax25_address *next_digi = NULL;
        ax25_dev *ax25_dev;
        ax25_dev *ax25_dev;
        struct sock *raw;
        struct sock *raw;
        int mine = 0;
        int mine = 0;
        int dama;
        int dama;
 
 
        /*
        /*
         *      Process the AX.25/LAPB frame.
         *      Process the AX.25/LAPB frame.
         */
         */
 
 
        skb->h.raw = skb->data;
        skb->h.raw = skb->data;
 
 
        if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) {
        if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) {
                kfree_skb(skb);
                kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        /*
        /*
         *      Parse the address header.
         *      Parse the address header.
         */
         */
 
 
        if (ax25_addr_parse(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL) {
        if (ax25_addr_parse(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL) {
                kfree_skb(skb);
                kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        /*
        /*
         *      Ours perhaps ?
         *      Ours perhaps ?
         */
         */
        if (dp.lastrepeat + 1 < dp.ndigi)               /* Not yet digipeated completely */
        if (dp.lastrepeat + 1 < dp.ndigi)               /* Not yet digipeated completely */
                next_digi = &dp.calls[dp.lastrepeat + 1];
                next_digi = &dp.calls[dp.lastrepeat + 1];
 
 
        /*
        /*
         *      Pull of the AX.25 headers leaving the CTRL/PID bytes
         *      Pull of the AX.25 headers leaving the CTRL/PID bytes
         */
         */
        skb_pull(skb, ax25_addr_size(&dp));
        skb_pull(skb, ax25_addr_size(&dp));
 
 
        /* For our port addresses ? */
        /* For our port addresses ? */
        if (ax25cmp(&dest, dev_addr) == 0 && dp.lastrepeat + 1 == dp.ndigi)
        if (ax25cmp(&dest, dev_addr) == 0 && dp.lastrepeat + 1 == dp.ndigi)
                mine = 1;
                mine = 1;
 
 
        /* Also match on any registered callsign from L3/4 */
        /* Also match on any registered callsign from L3/4 */
        if (!mine && ax25_listen_mine(&dest, dev) && dp.lastrepeat + 1 == dp.ndigi)
        if (!mine && ax25_listen_mine(&dest, dev) && dp.lastrepeat + 1 == dp.ndigi)
                mine = 1;
                mine = 1;
 
 
        /* UI frame - bypass LAPB processing */
        /* UI frame - bypass LAPB processing */
        if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) {
        if ((*skb->data & ~0x10) == AX25_UI && dp.lastrepeat + 1 == dp.ndigi) {
                skb->h.raw = skb->data + 2;             /* skip control and pid */
                skb->h.raw = skb->data + 2;             /* skip control and pid */
 
 
                if ((raw = ax25_addr_match(&dest)) != NULL)
                if ((raw = ax25_addr_match(&dest)) != NULL)
                        ax25_send_to_raw(raw, skb, skb->data[1]);
                        ax25_send_to_raw(raw, skb, skb->data[1]);
 
 
                if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) {
                if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) {
                        kfree_skb(skb);
                        kfree_skb(skb);
                        return 0;
                        return 0;
                }
                }
 
 
                /* Now we are pointing at the pid byte */
                /* Now we are pointing at the pid byte */
                switch (skb->data[1]) {
                switch (skb->data[1]) {
#ifdef CONFIG_INET
#ifdef CONFIG_INET
                        case AX25_P_IP:
                        case AX25_P_IP:
                                skb_pull(skb,2);                /* drop PID/CTRL */
                                skb_pull(skb,2);                /* drop PID/CTRL */
                                skb->h.raw    = skb->data;
                                skb->h.raw    = skb->data;
                                skb->nh.raw   = skb->data;
                                skb->nh.raw   = skb->data;
                                skb->dev      = dev;
                                skb->dev      = dev;
                                skb->pkt_type = PACKET_HOST;
                                skb->pkt_type = PACKET_HOST;
                                skb->protocol = htons(ETH_P_IP);
                                skb->protocol = htons(ETH_P_IP);
                                ip_rcv(skb, dev, ptype);        /* Note ptype here is the wrong one, fix me later */
                                ip_rcv(skb, dev, ptype);        /* Note ptype here is the wrong one, fix me later */
                                break;
                                break;
 
 
                        case AX25_P_ARP:
                        case AX25_P_ARP:
                                skb_pull(skb,2);
                                skb_pull(skb,2);
                                skb->h.raw    = skb->data;
                                skb->h.raw    = skb->data;
                                skb->nh.raw   = skb->data;
                                skb->nh.raw   = skb->data;
                                skb->dev      = dev;
                                skb->dev      = dev;
                                skb->pkt_type = PACKET_HOST;
                                skb->pkt_type = PACKET_HOST;
                                skb->protocol = htons(ETH_P_ARP);
                                skb->protocol = htons(ETH_P_ARP);
                                arp_rcv(skb, dev, ptype);       /* Note ptype here is wrong... */
                                arp_rcv(skb, dev, ptype);       /* Note ptype here is wrong... */
                                break;
                                break;
#endif
#endif
                        case AX25_P_TEXT:
                        case AX25_P_TEXT:
                                /* Now find a suitable dgram socket */
                                /* Now find a suitable dgram socket */
                                if ((sk = ax25_find_socket(&dest, &src, SOCK_DGRAM)) != NULL) {
                                if ((sk = ax25_find_socket(&dest, &src, SOCK_DGRAM)) != NULL) {
                                        if (atomic_read(&sk->rmem_alloc) >= sk->rcvbuf) {
                                        if (atomic_read(&sk->rmem_alloc) >= sk->rcvbuf) {
                                                kfree_skb(skb);
                                                kfree_skb(skb);
                                        } else {
                                        } else {
                                                /*
                                                /*
                                                 *      Remove the control and PID.
                                                 *      Remove the control and PID.
                                                 */
                                                 */
                                                skb_pull(skb, 2);
                                                skb_pull(skb, 2);
                                                if (sock_queue_rcv_skb(sk, skb) != 0)
                                                if (sock_queue_rcv_skb(sk, skb) != 0)
                                                        kfree_skb(skb);
                                                        kfree_skb(skb);
                                        }
                                        }
                                } else {
                                } else {
                                        kfree_skb(skb);
                                        kfree_skb(skb);
                                }
                                }
                                break;
                                break;
 
 
                        default:
                        default:
                                kfree_skb(skb); /* Will scan SOCK_AX25 RAW sockets */
                                kfree_skb(skb); /* Will scan SOCK_AX25 RAW sockets */
                                break;
                                break;
                }
                }
 
 
                return 0;
                return 0;
        }
        }
 
 
        /*
        /*
         *      Is connected mode supported on this device ?
         *      Is connected mode supported on this device ?
         *      If not, should we DM the incoming frame (except DMs) or
         *      If not, should we DM the incoming frame (except DMs) or
         *      silently ignore them. For now we stay quiet.
         *      silently ignore them. For now we stay quiet.
         */
         */
        if (ax25_dev->values[AX25_VALUES_CONMODE] == 0) {
        if (ax25_dev->values[AX25_VALUES_CONMODE] == 0) {
                kfree_skb(skb);
                kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        /* LAPB */
        /* LAPB */
 
 
        /* AX.25 state 1-4 */
        /* AX.25 state 1-4 */
 
 
        ax25_digi_invert(&dp, &reverse_dp);
        ax25_digi_invert(&dp, &reverse_dp);
 
 
        if ((ax25 = ax25_find_cb(&dest, &src, &reverse_dp, dev)) != NULL) {
        if ((ax25 = ax25_find_cb(&dest, &src, &reverse_dp, dev)) != NULL) {
                /*
                /*
                 *      Process the frame. If it is queued up internally it returns one otherwise we
                 *      Process the frame. If it is queued up internally it returns one otherwise we
                 *      free it immediately. This routine itself wakes the user context layers so we
                 *      free it immediately. This routine itself wakes the user context layers so we
                 *      do no further work
                 *      do no further work
                 */
                 */
                if (ax25_process_rx_frame(ax25, skb, type, dama) == 0)
                if (ax25_process_rx_frame(ax25, skb, type, dama) == 0)
                        kfree_skb(skb);
                        kfree_skb(skb);
 
 
                return 0;
                return 0;
        }
        }
 
 
        /* AX.25 state 0 (disconnected) */
        /* AX.25 state 0 (disconnected) */
 
 
        /* a) received not a SABM(E) */
        /* a) received not a SABM(E) */
 
 
        if ((*skb->data & ~AX25_PF) != AX25_SABM && (*skb->data & ~AX25_PF) != AX25_SABME) {
        if ((*skb->data & ~AX25_PF) != AX25_SABM && (*skb->data & ~AX25_PF) != AX25_SABME) {
                /*
                /*
                 *      Never reply to a DM. Also ignore any connects for
                 *      Never reply to a DM. Also ignore any connects for
                 *      addresses that are not our interfaces and not a socket.
                 *      addresses that are not our interfaces and not a socket.
                 */
                 */
                if ((*skb->data & ~AX25_PF) != AX25_DM && mine)
                if ((*skb->data & ~AX25_PF) != AX25_DM && mine)
                        ax25_return_dm(dev, &src, &dest, &dp);
                        ax25_return_dm(dev, &src, &dest, &dp);
 
 
                kfree_skb(skb);
                kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        /* b) received SABM(E) */
        /* b) received SABM(E) */
 
 
        if (dp.lastrepeat + 1 == dp.ndigi)
        if (dp.lastrepeat + 1 == dp.ndigi)
                sk = ax25_find_listener(&dest, 0, dev, SOCK_SEQPACKET);
                sk = ax25_find_listener(&dest, 0, dev, SOCK_SEQPACKET);
        else
        else
                sk = ax25_find_listener(next_digi, 1, dev, SOCK_SEQPACKET);
                sk = ax25_find_listener(next_digi, 1, dev, SOCK_SEQPACKET);
 
 
        if (sk != NULL) {
        if (sk != NULL) {
                if (sk->ack_backlog == sk->max_ack_backlog || (make = ax25_make_new(sk, ax25_dev)) == NULL) {
                if (sk->ack_backlog == sk->max_ack_backlog || (make = ax25_make_new(sk, ax25_dev)) == NULL) {
                        if (mine) ax25_return_dm(dev, &src, &dest, &dp);
                        if (mine) ax25_return_dm(dev, &src, &dest, &dp);
                        kfree_skb(skb);
                        kfree_skb(skb);
                        return 0;
                        return 0;
                }
                }
 
 
                ax25 = make->protinfo.ax25;
                ax25 = make->protinfo.ax25;
                skb_set_owner_r(skb, make);
                skb_set_owner_r(skb, make);
                skb_queue_head(&sk->receive_queue, skb);
                skb_queue_head(&sk->receive_queue, skb);
 
 
                make->state = TCP_ESTABLISHED;
                make->state = TCP_ESTABLISHED;
                make->pair  = sk;
                make->pair  = sk;
 
 
                sk->ack_backlog++;
                sk->ack_backlog++;
        } else {
        } else {
                if (!mine) {
                if (!mine) {
                        kfree_skb(skb);
                        kfree_skb(skb);
                        return 0;
                        return 0;
                }
                }
 
 
                if ((ax25 = ax25_create_cb()) == NULL) {
                if ((ax25 = ax25_create_cb()) == NULL) {
                        ax25_return_dm(dev, &src, &dest, &dp);
                        ax25_return_dm(dev, &src, &dest, &dp);
                        kfree_skb(skb);
                        kfree_skb(skb);
                        return 0;
                        return 0;
                }
                }
 
 
                ax25_fillin_cb(ax25, ax25_dev);
                ax25_fillin_cb(ax25, ax25_dev);
        }
        }
 
 
        ax25->source_addr = dest;
        ax25->source_addr = dest;
        ax25->dest_addr   = src;
        ax25->dest_addr   = src;
 
 
        /*
        /*
         *      Sort out any digipeated paths.
         *      Sort out any digipeated paths.
         */
         */
        if (dp.ndigi && !ax25->digipeat &&
        if (dp.ndigi && !ax25->digipeat &&
            (ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
            (ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
                kfree_skb(skb);
                kfree_skb(skb);
                ax25_destroy_socket(ax25);
                ax25_destroy_socket(ax25);
                return 0;
                return 0;
        }
        }
 
 
        if (dp.ndigi == 0) {
        if (dp.ndigi == 0) {
                if (ax25->digipeat != NULL) {
                if (ax25->digipeat != NULL) {
                        kfree(ax25->digipeat);
                        kfree(ax25->digipeat);
                        ax25->digipeat = NULL;
                        ax25->digipeat = NULL;
                }
                }
        } else {
        } else {
                /* Reverse the source SABM's path */
                /* Reverse the source SABM's path */
                memcpy(ax25->digipeat, &reverse_dp, sizeof(ax25_digi));
                memcpy(ax25->digipeat, &reverse_dp, sizeof(ax25_digi));
        }
        }
 
 
        if ((*skb->data & ~AX25_PF) == AX25_SABME) {
        if ((*skb->data & ~AX25_PF) == AX25_SABME) {
                ax25->modulus = AX25_EMODULUS;
                ax25->modulus = AX25_EMODULUS;
                ax25->window  = ax25_dev->values[AX25_VALUES_EWINDOW];
                ax25->window  = ax25_dev->values[AX25_VALUES_EWINDOW];
        } else {
        } else {
                ax25->modulus = AX25_MODULUS;
                ax25->modulus = AX25_MODULUS;
                ax25->window  = ax25_dev->values[AX25_VALUES_WINDOW];
                ax25->window  = ax25_dev->values[AX25_VALUES_WINDOW];
        }
        }
 
 
        ax25_send_control(ax25, AX25_UA, AX25_POLLON, AX25_RESPONSE);
        ax25_send_control(ax25, AX25_UA, AX25_POLLON, AX25_RESPONSE);
 
 
#ifdef CONFIG_AX25_DAMA_SLAVE
#ifdef CONFIG_AX25_DAMA_SLAVE
        if (dama && ax25->ax25_dev->values[AX25_VALUES_PROTOCOL] == AX25_PROTO_DAMA_SLAVE)
        if (dama && ax25->ax25_dev->values[AX25_VALUES_PROTOCOL] == AX25_PROTO_DAMA_SLAVE)
                ax25_dama_on(ax25);
                ax25_dama_on(ax25);
#endif
#endif
 
 
        ax25->state = AX25_STATE_3;
        ax25->state = AX25_STATE_3;
 
 
        ax25_insert_socket(ax25);
        ax25_insert_socket(ax25);
 
 
        ax25_start_heartbeat(ax25);
        ax25_start_heartbeat(ax25);
        ax25_start_t3timer(ax25);
        ax25_start_t3timer(ax25);
        ax25_start_idletimer(ax25);
        ax25_start_idletimer(ax25);
 
 
        if (sk != NULL) {
        if (sk != NULL) {
                if (!sk->dead)
                if (!sk->dead)
                        sk->data_ready(sk, skb->len);
                        sk->data_ready(sk, skb->len);
        } else {
        } else {
                kfree_skb(skb);
                kfree_skb(skb);
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 *      Receive an AX.25 frame via a SLIP interface.
 *      Receive an AX.25 frame via a SLIP interface.
 */
 */
int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
                  struct packet_type *ptype)
                  struct packet_type *ptype)
{
{
        skb->sk = NULL;         /* Initially we don't know who it's for */
        skb->sk = NULL;         /* Initially we don't know who it's for */
        skb->destructor = NULL; /* Who initializes this, dammit?! */
        skb->destructor = NULL; /* Who initializes this, dammit?! */
 
 
        if ((*skb->data & 0x0F) != 0) {
        if ((*skb->data & 0x0F) != 0) {
                kfree_skb(skb); /* Not a KISS data frame */
                kfree_skb(skb); /* Not a KISS data frame */
                return 0;
                return 0;
        }
        }
 
 
        skb_pull(skb, AX25_KISS_HEADER_LEN);    /* Remove the KISS byte */
        skb_pull(skb, AX25_KISS_HEADER_LEN);    /* Remove the KISS byte */
 
 
        return ax25_rcv(skb, dev, (ax25_address *)dev->dev_addr, ptype);
        return ax25_rcv(skb, dev, (ax25_address *)dev->dev_addr, ptype);
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.