Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: isdn_x25iface.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $ |
| 2 | * |
| 3 | * Linux ISDN subsystem, X.25 related functions |
| 4 | * |
| 5 | * This software may be used and distributed according to the terms |
| 6 | * of the GNU General Public License, incorporated herein by reference. |
| 7 | * |
| 8 | * stuff needed to support the Linux X.25 PLP code on top of devices that |
| 9 | * can provide a lab_b service using the concap_proto mechanism. |
Uwe Zeisberger | c30fe7f | 2006-03-24 18:23:14 +0100 | [diff] [blame] | 10 | * This module supports a network interface which provides lapb_sematics |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * -- as defined in Documentation/networking/x25-iface.txt -- to |
| 12 | * the upper layer and assumes that the lower layer provides a reliable |
| 13 | * data link service by means of the concap_device_ops callbacks. |
| 14 | * |
| 15 | * Only protocol specific stuff goes here. Device specific stuff |
| 16 | * goes to another -- device related -- concap_proto support source file. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | /* #include <linux/isdn.h> */ |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/concap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/wanrouter.h> |
| 25 | #include <net/x25device.h> |
| 26 | #include "isdn_x25iface.h" |
| 27 | |
| 28 | /* for debugging messages not to cause an oops when device pointer is NULL*/ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 29 | #define MY_DEVNAME(dev) ((dev) ? (dev)->name : "DEVICE UNSPECIFIED") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | |
| 32 | typedef struct isdn_x25iface_proto_data { |
| 33 | int magic; |
| 34 | enum wan_states state; |
| 35 | /* Private stuff, not to be accessed via proto_data. We provide the |
| 36 | other storage for the concap_proto instance here as well, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 37 | enabling us to allocate both with just one kmalloc(): */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | struct concap_proto priv; |
| 39 | } ix25_pdata_t; |
| 40 | |
| 41 | |
| 42 | |
| 43 | /* is now in header file (extern): struct concap_proto * isdn_x25iface_proto_new(void); */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 44 | static void isdn_x25iface_proto_del(struct concap_proto *); |
| 45 | static int isdn_x25iface_proto_close(struct concap_proto *); |
| 46 | static int isdn_x25iface_proto_restart(struct concap_proto *, |
| 47 | struct net_device *, |
| 48 | struct concap_device_ops *); |
| 49 | static int isdn_x25iface_xmit(struct concap_proto *, struct sk_buff *); |
| 50 | static int isdn_x25iface_receive(struct concap_proto *, struct sk_buff *); |
| 51 | static int isdn_x25iface_connect_ind(struct concap_proto *); |
| 52 | static int isdn_x25iface_disconn_ind(struct concap_proto *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | |
| 55 | static struct concap_proto_ops ix25_pops = { |
Kees Cook | ebf12f1 | 2016-12-16 17:01:42 -0800 | [diff] [blame] | 56 | .proto_new = &isdn_x25iface_proto_new, |
| 57 | .proto_del = &isdn_x25iface_proto_del, |
| 58 | .restart = &isdn_x25iface_proto_restart, |
| 59 | .close = &isdn_x25iface_proto_close, |
| 60 | .encap_and_xmit = &isdn_x25iface_xmit, |
| 61 | .data_ind = &isdn_x25iface_receive, |
| 62 | .connect_ind = &isdn_x25iface_connect_ind, |
| 63 | .disconn_ind = &isdn_x25iface_disconn_ind |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /* error message helper function */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 67 | static void illegal_state_warn(unsigned state, unsigned char firstbyte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 69 | printk(KERN_WARNING "isdn_x25iface: firstbyte %x illegal in" |
| 70 | "current state %d\n", firstbyte, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* check protocol data field for consistency */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 74 | static int pdata_is_bad(ix25_pdata_t *pda) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 76 | if (pda && pda->magic == ISDN_X25IFACE_MAGIC) return 0; |
| 77 | printk(KERN_WARNING |
| 78 | "isdn_x25iface_xxx: illegal pointer to proto data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | /* create a new x25 interface protocol instance |
| 83 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 84 | struct concap_proto *isdn_x25iface_proto_new(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 86 | ix25_pdata_t *tmp = kmalloc(sizeof(ix25_pdata_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | IX25DEBUG("isdn_x25iface_proto_new\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 88 | if (tmp) { |
| 89 | tmp->magic = ISDN_X25IFACE_MAGIC; |
| 90 | tmp->state = WAN_UNCONFIGURED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* private data space used to hold the concap_proto data. |
| 92 | Only to be accessed via the returned pointer */ |
| 93 | spin_lock_init(&tmp->priv.lock); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 94 | tmp->priv.dops = NULL; |
| 95 | tmp->priv.net_dev = NULL; |
| 96 | tmp->priv.pops = &ix25_pops; |
| 97 | tmp->priv.flags = 0; |
| 98 | tmp->priv.proto_data = tmp; |
| 99 | return (&(tmp->priv)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | return NULL; |
| 102 | }; |
| 103 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 104 | /* close the x25iface encapsulation protocol |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 106 | static int isdn_x25iface_proto_close(struct concap_proto *cprot) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | ix25_pdata_t *tmp; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 109 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | ulong flags; |
| 111 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 112 | if (!cprot) { |
| 113 | printk(KERN_ERR "isdn_x25iface_proto_close: " |
| 114 | "invalid concap_proto pointer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | return -1; |
| 116 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 117 | IX25DEBUG("isdn_x25iface_proto_close %s \n", MY_DEVNAME(cprot->net_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | spin_lock_irqsave(&cprot->lock, flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 119 | cprot->dops = NULL; |
| 120 | cprot->net_dev = NULL; |
| 121 | tmp = cprot->proto_data; |
| 122 | if (pdata_is_bad(tmp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | ret = -1; |
| 124 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 125 | tmp->state = WAN_UNCONFIGURED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | spin_unlock_irqrestore(&cprot->lock, flags); |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | /* Delete the x25iface encapsulation protocol instance |
| 132 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 133 | static void isdn_x25iface_proto_del(struct concap_proto *cprot) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 135 | ix25_pdata_t *tmp; |
| 136 | |
| 137 | IX25DEBUG("isdn_x25iface_proto_del \n"); |
| 138 | if (!cprot) { |
| 139 | printk(KERN_ERR "isdn_x25iface_proto_del: " |
| 140 | "concap_proto pointer is NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return; |
| 142 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 143 | tmp = cprot->proto_data; |
| 144 | if (tmp == NULL) { |
| 145 | printk(KERN_ERR "isdn_x25iface_proto_del: inconsistent " |
| 146 | "proto_data pointer (maybe already deleted?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | /* close if the protocol is still open */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 150 | if (cprot->dops) isdn_x25iface_proto_close(cprot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* freeing the storage should be sufficient now. But some additional |
| 152 | settings might help to catch wild pointer bugs */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 153 | tmp->magic = 0; |
| 154 | cprot->proto_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 156 | kfree(tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | /* (re-)initialize the data structures for x25iface encapsulation |
| 161 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 162 | static int isdn_x25iface_proto_restart(struct concap_proto *cprot, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 163 | struct net_device *ndev, |
| 164 | struct concap_device_ops *dops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 166 | ix25_pdata_t *pda = cprot->proto_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | ulong flags; |
| 168 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 169 | IX25DEBUG("isdn_x25iface_proto_restart %s \n", MY_DEVNAME(ndev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 171 | if (pdata_is_bad(pda)) return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 173 | if (!(dops && dops->data_req && dops->connect_req |
| 174 | && dops->disconn_req)) { |
| 175 | printk(KERN_WARNING "isdn_x25iface_restart: required dops" |
| 176 | " missing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | isdn_x25iface_proto_close(cprot); |
| 178 | return -1; |
| 179 | } |
| 180 | spin_lock_irqsave(&cprot->lock, flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 181 | cprot->net_dev = ndev; |
| 182 | cprot->pops = &ix25_pops; |
| 183 | cprot->dops = dops; |
| 184 | pda->state = WAN_DISCONNECTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | spin_unlock_irqrestore(&cprot->lock, flags); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 189 | /* deliver a dl_data frame received from i4l HL driver to the network layer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 191 | static int isdn_x25iface_receive(struct concap_proto *cprot, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 193 | IX25DEBUG("isdn_x25iface_receive %s \n", MY_DEVNAME(cprot->net_dev)); |
| 194 | if (((ix25_pdata_t *)(cprot->proto_data)) |
| 195 | ->state == WAN_CONNECTED) { |
| 196 | if (skb_push(skb, 1)) { |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 197 | skb->data[0] = X25_IFACE_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | skb->protocol = x25_type_trans(skb, cprot->net_dev); |
| 199 | netif_rx(skb); |
| 200 | return 0; |
| 201 | } |
| 202 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 203 | printk(KERN_WARNING "isdn_x25iface_receive %s: not connected, skb dropped\n", MY_DEVNAME(cprot->net_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | dev_kfree_skb(skb); |
| 205 | return -1; |
| 206 | } |
| 207 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 208 | /* a connection set up is indicated by lower layer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 210 | static int isdn_x25iface_connect_ind(struct concap_proto *cprot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 212 | struct sk_buff *skb; |
| 213 | enum wan_states *state_p |
| 214 | = &(((ix25_pdata_t *)(cprot->proto_data))->state); |
| 215 | IX25DEBUG("isdn_x25iface_connect_ind %s \n" |
| 216 | , MY_DEVNAME(cprot->net_dev)); |
| 217 | if (*state_p == WAN_UNCONFIGURED) { |
| 218 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | "isdn_x25iface_connect_ind while unconfigured %s\n" |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 220 | , MY_DEVNAME(cprot->net_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | return -1; |
| 222 | } |
| 223 | *state_p = WAN_CONNECTED; |
Eric Sesterhenn | d81931d | 2006-06-29 02:24:34 -0700 | [diff] [blame] | 224 | |
| 225 | skb = dev_alloc_skb(1); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 226 | if (skb) { |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 227 | skb_put_u8(skb, X25_IFACE_CONNECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | skb->protocol = x25_type_trans(skb, cprot->net_dev); |
| 229 | netif_rx(skb); |
| 230 | return 0; |
| 231 | } else { |
| 232 | printk(KERN_WARNING "isdn_x25iface_connect_ind: " |
| 233 | " out of memory -- disconnecting\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 234 | cprot->dops->disconn_req(cprot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return -1; |
| 236 | } |
| 237 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 238 | |
| 239 | /* a disconnect is indicated by lower layer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 241 | static int isdn_x25iface_disconn_ind(struct concap_proto *cprot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | struct sk_buff *skb; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 244 | enum wan_states *state_p |
| 245 | = &(((ix25_pdata_t *)(cprot->proto_data))->state); |
| 246 | IX25DEBUG("isdn_x25iface_disconn_ind %s \n", MY_DEVNAME(cprot->net_dev)); |
| 247 | if (*state_p == WAN_UNCONFIGURED) { |
| 248 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | "isdn_x25iface_disconn_ind while unconfigured\n"); |
| 250 | return -1; |
| 251 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 252 | if (!cprot->net_dev) return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | *state_p = WAN_DISCONNECTED; |
| 254 | skb = dev_alloc_skb(1); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 255 | if (skb) { |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 256 | skb_put_u8(skb, X25_IFACE_DISCONNECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | skb->protocol = x25_type_trans(skb, cprot->net_dev); |
| 258 | netif_rx(skb); |
| 259 | return 0; |
| 260 | } else { |
| 261 | printk(KERN_WARNING "isdn_x25iface_disconn_ind:" |
| 262 | " out of memory\n"); |
| 263 | return -1; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* process a frame handed over to us from linux network layer. First byte |
| 268 | semantics as defined in Documentation/networking/x25-iface.txt |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 269 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 270 | static int isdn_x25iface_xmit(struct concap_proto *cprot, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
| 272 | unsigned char firstbyte = skb->data[0]; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 273 | enum wan_states *state = &((ix25_pdata_t *)cprot->proto_data)->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | int ret = 0; |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 275 | IX25DEBUG("isdn_x25iface_xmit: %s first=%x state=%d\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 276 | MY_DEVNAME(cprot->net_dev), firstbyte, *state); |
| 277 | switch (firstbyte) { |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 278 | case X25_IFACE_DATA: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 279 | if (*state == WAN_CONNECTED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | skb_pull(skb, 1); |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 281 | netif_trans_update(cprot->net_dev); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 282 | ret = (cprot->dops->data_req(cprot, skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /* prepare for future retransmissions */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 284 | if (ret) skb_push(skb, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return ret; |
| 286 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 287 | illegal_state_warn(*state, firstbyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | break; |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 289 | case X25_IFACE_CONNECT: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 290 | if (*state == WAN_DISCONNECTED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | *state = WAN_CONNECTING; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 292 | ret = cprot->dops->connect_req(cprot); |
| 293 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /* reset state and notify upper layer about |
| 295 | * immidiatly failed attempts */ |
| 296 | isdn_x25iface_disconn_ind(cprot); |
| 297 | } |
| 298 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 299 | illegal_state_warn(*state, firstbyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | break; |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 302 | case X25_IFACE_DISCONNECT: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 303 | switch (*state) { |
| 304 | case WAN_DISCONNECTED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | /* Should not happen. However, give upper layer a |
| 306 | chance to recover from inconstistency but don't |
| 307 | trust the lower layer sending the disconn_confirm |
| 308 | when already disconnected */ |
| 309 | printk(KERN_WARNING "isdn_x25iface_xmit: disconnect " |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 310 | " requested while disconnected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | isdn_x25iface_disconn_ind(cprot); |
| 312 | break; /* prevent infinite loops */ |
| 313 | case WAN_CONNECTING: |
| 314 | case WAN_CONNECTED: |
| 315 | *state = WAN_DISCONNECTED; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 316 | cprot->dops->disconn_req(cprot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | break; |
| 318 | default: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 319 | illegal_state_warn(*state, firstbyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | break; |
andrew hendry | 4150bbf | 2010-04-19 13:29:06 +0000 | [diff] [blame] | 322 | case X25_IFACE_PARAMS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | printk(KERN_WARNING "isdn_x25iface_xmit: setting of lapb" |
| 324 | " options not yet supported\n"); |
| 325 | break; |
| 326 | default: |
| 327 | printk(KERN_WARNING "isdn_x25iface_xmit: frame with illegal" |
| 328 | " first byte %x ignored:\n", firstbyte); |
| 329 | } |
| 330 | dev_kfree_skb(skb); |
| 331 | return 0; |
| 332 | } |