include upstream ip1000a driver version 2.09f
[linux-2.4.git] / net / atm / raw.c
1 /* net/atm/raw.c - Raw AAL0 and AAL5 transports */
2
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
5
6 #include <linux/module.h>
7 #include <linux/sched.h>
8 #include <linux/atmdev.h>
9 #include <linux/kernel.h>
10 #include <linux/skbuff.h>
11 #include <linux/mm.h>
12
13 #include "common.h"
14 #include "protocols.h"
15
16
17 #if 0
18 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
19 #else
20 #define DPRINTK(format,args...)
21 #endif
22
23
24 /*
25  * SKB == NULL indicates that the link is being closed
26  */
27
28 void atm_push_raw(struct atm_vcc *vcc,struct sk_buff *skb)
29 {
30         if (skb) {
31                 skb_queue_tail(&vcc->sk->receive_queue,skb);
32                 wake_up(&vcc->sleep);
33         }
34 }
35
36
37 static void atm_pop_raw(struct atm_vcc *vcc,struct sk_buff *skb)
38 {
39         DPRINTK("APopR (%d) %d -= %d\n",vcc->vci,vcc->sk->wmem_alloc,skb->truesize);
40         atomic_sub(skb->truesize, &vcc->sk->wmem_alloc);
41         dev_kfree_skb_any(skb);
42         wake_up(&vcc->sleep);
43 }
44
45
46 static int atm_send_aal0(struct atm_vcc *vcc,struct sk_buff *skb)
47 {
48         /*
49          * Note that if vpi/vci are _ANY or _UNSPEC the below will
50          * still work
51          */
52         if (!capable(CAP_NET_ADMIN) &&
53             (((u32 *) skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) !=
54             ((vcc->vpi << ATM_HDR_VPI_SHIFT) | (vcc->vci << ATM_HDR_VCI_SHIFT)))
55             {
56                 kfree_skb(skb);
57                 return -EADDRNOTAVAIL;
58         }
59         return vcc->dev->ops->send(vcc,skb);
60 }
61
62
63 int atm_init_aal0(struct atm_vcc *vcc)
64 {
65         vcc->push = atm_push_raw;
66         vcc->pop = atm_pop_raw;
67         vcc->push_oam = NULL;
68         vcc->send = atm_send_aal0;
69         return 0;
70 }
71
72
73 int atm_init_aal34(struct atm_vcc *vcc)
74 {
75         vcc->push = atm_push_raw;
76         vcc->pop = atm_pop_raw;
77         vcc->push_oam = NULL;
78         vcc->send = vcc->dev->ops->send;
79         return 0;
80 }
81
82
83 int atm_init_aal5(struct atm_vcc *vcc)
84 {
85         vcc->push = atm_push_raw;
86         vcc->pop = atm_pop_raw;
87         vcc->push_oam = NULL;
88         vcc->send = vcc->dev->ops->send;
89         return 0;
90 }
91
92
93 EXPORT_SYMBOL(atm_init_aal5);