^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * LAPB release 002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This code REQUIRES 2.1.15 or higher/ NET3.038
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * History
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * LAPB 001 Jonathan Naylor Started Coding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * LAPB 002 Jonathan Naylor New timer architecture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 2000-10-29 Henner Eisen lapb_data_indication() return status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/lapb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static LIST_HEAD(lapb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static DEFINE_RWLOCK(lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Free an allocated lapb control block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static void lapb_free_cb(struct lapb_cb *lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) kfree(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static __inline__ void lapb_hold(struct lapb_cb *lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) refcount_inc(&lapb->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static __inline__ void lapb_put(struct lapb_cb *lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (refcount_dec_and_test(&lapb->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) lapb_free_cb(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Socket removal during an interrupt is now safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void __lapb_remove_cb(struct lapb_cb *lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (lapb->node.next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) list_del(&lapb->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Add a socket to the bound sockets list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static void __lapb_insert_cb(struct lapb_cb *lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) list_add(&lapb->node, &lapb_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) lapb_hold(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct lapb_cb *__lapb_devtostruct(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct list_head *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct lapb_cb *lapb, *use = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) list_for_each(entry, &lapb_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) lapb = list_entry(entry, struct lapb_cb, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (lapb->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) use = lapb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (use)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) lapb_hold(use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static struct lapb_cb *lapb_devtostruct(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct lapb_cb *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) read_lock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) rc = __lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) read_unlock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Create an empty LAPB control block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static struct lapb_cb *lapb_create_cb(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct lapb_cb *lapb = kzalloc(sizeof(*lapb), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) skb_queue_head_init(&lapb->write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) skb_queue_head_init(&lapb->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) timer_setup(&lapb->t1timer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) timer_setup(&lapb->t2timer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) lapb->t1 = LAPB_DEFAULT_T1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) lapb->t2 = LAPB_DEFAULT_T2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) lapb->n2 = LAPB_DEFAULT_N2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) lapb->mode = LAPB_DEFAULT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) lapb->window = LAPB_DEFAULT_WINDOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) lapb->state = LAPB_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) refcount_set(&lapb->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return lapb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int lapb_register(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) const struct lapb_register_struct *callbacks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct lapb_cb *lapb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) write_lock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) lapb = __lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (lapb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) lapb = lapb_create_cb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) rc = LAPB_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) lapb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) lapb->callbacks = callbacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) __lapb_insert_cb(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) lapb_start_t1timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) write_unlock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) EXPORT_SYMBOL(lapb_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int lapb_unregister(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct lapb_cb *lapb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) write_lock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) lapb = __lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) lapb_stop_t1timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) lapb_stop_t2timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) lapb_clear_queues(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) __lapb_remove_cb(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) write_unlock_bh(&lapb_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) EXPORT_SYMBOL(lapb_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) parms->t1 = lapb->t1 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) parms->t2 = lapb->t2 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) parms->n2 = lapb->n2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) parms->n2count = lapb->n2count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) parms->state = lapb->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) parms->window = lapb->window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) parms->mode = lapb->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (!timer_pending(&lapb->t1timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) parms->t1timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) parms->t1timer = (lapb->t1timer.expires - jiffies) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (!timer_pending(&lapb->t2timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) parms->t2timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) parms->t2timer = (lapb->t2timer.expires - jiffies) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) EXPORT_SYMBOL(lapb_getparms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) rc = LAPB_INVALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (parms->t1 < 1 || parms->t2 < 1 || parms->n2 < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (lapb->state == LAPB_STATE_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (parms->mode & LAPB_EXTENDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (parms->window < 1 || parms->window > 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (parms->window < 1 || parms->window > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) lapb->mode = parms->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) lapb->window = parms->window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) lapb->t1 = parms->t1 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) lapb->t2 = parms->t2 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) lapb->n2 = parms->n2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) EXPORT_SYMBOL(lapb_setparms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int lapb_connect_request(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (lapb->state == LAPB_STATE_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) rc = LAPB_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (lapb->state == LAPB_STATE_3 || lapb->state == LAPB_STATE_4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) lapb_establish_data_link(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) lapb_dbg(0, "(%p) S0 -> S1\n", lapb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) lapb->state = LAPB_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) EXPORT_SYMBOL(lapb_connect_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int lapb_disconnect_request(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) switch (lapb->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) case LAPB_STATE_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) rc = LAPB_NOTCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) case LAPB_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) lapb_dbg(1, "(%p) S1 TX DISC(1)\n", lapb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) lapb->state = LAPB_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) lapb_start_t1timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) rc = LAPB_NOTCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) case LAPB_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) lapb_clear_queues(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) lapb->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) lapb_start_t1timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) lapb_stop_t2timer(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) lapb->state = LAPB_STATE_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) lapb_dbg(1, "(%p) S3 DISC(1)\n", lapb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) lapb_dbg(0, "(%p) S3 -> S2\n", lapb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) EXPORT_SYMBOL(lapb_disconnect_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int lapb_data_request(struct net_device *dev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (!lapb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) rc = LAPB_NOTCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (lapb->state != LAPB_STATE_3 && lapb->state != LAPB_STATE_4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) skb_queue_tail(&lapb->write_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) lapb_kick(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) EXPORT_SYMBOL(lapb_data_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct lapb_cb *lapb = lapb_devtostruct(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int rc = LAPB_BADTOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (lapb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) lapb_data_input(lapb, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) lapb_put(lapb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) rc = LAPB_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) EXPORT_SYMBOL(lapb_data_received);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (lapb->callbacks->connect_confirmation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) lapb->callbacks->connect_confirmation(lapb->dev, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) void lapb_connect_indication(struct lapb_cb *lapb, int reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (lapb->callbacks->connect_indication)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) lapb->callbacks->connect_indication(lapb->dev, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (lapb->callbacks->disconnect_confirmation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (lapb->callbacks->disconnect_indication)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) lapb->callbacks->disconnect_indication(lapb->dev, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (lapb->callbacks->data_indication)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return lapb->callbacks->data_indication(lapb->dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (lapb->callbacks->data_transmit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) lapb->callbacks->data_transmit(lapb->dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) used = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static int __init lapb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static void __exit lapb_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) WARN_ON(!list_empty(&lapb_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) MODULE_AUTHOR("Jonathan Naylor <g4klx@g4klx.demon.co.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) MODULE_DESCRIPTION("The X.25 Link Access Procedure B link layer protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) module_init(lapb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) module_exit(lapb_exit);