* better
[mascara-docs.git] / i386 / linux-2.3.21 / net / atm / signaling.c
blob6c0ef9f0f9253d66905b53506f94f029ed506114
1 /* net/atm/signaling.c - ATM signaling */
3 /* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
6 #include <linux/errno.h> /* error codes */
7 #include <linux/kernel.h> /* printk */
8 #include <linux/skbuff.h>
9 #include <linux/wait.h>
10 #include <linux/sched.h> /* jiffies and HZ */
11 #include <linux/atm.h> /* ATM stuff */
12 #include <linux/atmsap.h>
13 #include <linux/atmsvc.h>
14 #include <linux/atmdev.h>
16 #include "tunable.h"
17 #include "resources.h"
18 #include "signaling.h"
21 #undef WAIT_FOR_DEMON /* #define this if system calls on SVC sockets
22 should block until the demon runs.
23 Danger: may cause nasty hangs if the demon
24 crashes. */
26 #if 0
27 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
28 #else
29 #define DPRINTK(format,args...)
30 #endif
33 struct atm_vcc *sigd = NULL;
34 static wait_queue_head_t sigd_sleep;
37 static void sigd_put_skb(struct sk_buff *skb)
39 #ifdef WAIT_FOR_DEMON
40 static unsigned long silence = 0;
41 #endif
43 while (!sigd) {
44 #ifdef WAIT_FOR_DEMON
45 if (time_after(jiffies, silence) || silence == 0) {
46 printk(KERN_INFO "atmsvc: waiting for signaling demon "
47 "...\n");
48 silence = (jiffies+30*HZ)|1;
50 sleep_on(&sigd_sleep);
51 #else
52 printk(KERN_WARNING "atmsvc: no signaling demon\n");
53 kfree_skb(skb);
54 return;
55 #endif
57 atm_force_charge(sigd,skb->truesize);
58 skb_queue_tail(&sigd->recvq,skb);
59 wake_up(&sigd->sleep);
63 static void modify_qos(struct atm_vcc *vcc,struct atmsvc_msg *msg)
65 struct sk_buff *skb;
67 if ((vcc->flags & ATM_VF_RELEASED) || !(vcc->flags & ATM_VF_READY))
68 return;
69 msg->type = as_error;
70 if (!vcc->dev->ops->change_qos) msg->reply = -EOPNOTSUPP;
71 else {
72 /* should lock VCC */
73 msg->reply = vcc->dev->ops->change_qos(vcc,&msg->qos,
74 msg->reply);
75 if (!msg->reply) msg->type = as_okay;
78 * Should probably just turn around the old skb. But the, the buffer
79 * space accounting needs to follow the change too. Maybe later.
81 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL)))
82 schedule();
83 *(struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg)) = *msg;
84 sigd_put_skb(skb);
88 static int sigd_send(struct atm_vcc *vcc,struct sk_buff *skb)
90 struct atmsvc_msg *msg;
91 struct atm_vcc *session_vcc;
93 msg = (struct atmsvc_msg *) skb->data;
94 atomic_sub(skb->truesize+ATM_PDU_OVHD,&vcc->tx_inuse);
95 DPRINTK("sigd_send %d (0x%lx)\n",(int) msg->type,msg->vcc);
96 vcc = (struct atm_vcc *) msg->vcc;
97 switch (msg->type) {
98 case as_okay:
99 vcc->reply = msg->reply;
100 if (!*vcc->local.sas_addr.prv &&
101 !*vcc->local.sas_addr.pub) {
102 vcc->local.sas_family = AF_ATMSVC;
103 memcpy(vcc->local.sas_addr.prv,
104 msg->local.sas_addr.prv,ATM_ESA_LEN);
105 memcpy(vcc->local.sas_addr.pub,
106 msg->local.sas_addr.pub,ATM_E164_LEN+1);
108 session_vcc = vcc->session ? vcc->session : vcc;
109 if (session_vcc->vpi || session_vcc->vci) break;
110 session_vcc->itf = msg->pvc.sap_addr.itf;
111 session_vcc->vpi = msg->pvc.sap_addr.vpi;
112 session_vcc->vci = msg->pvc.sap_addr.vci;
113 if (session_vcc->vpi || session_vcc->vci)
114 session_vcc->qos = msg->qos;
115 break;
116 case as_error:
117 vcc->flags &= ~(ATM_VF_REGIS | ATM_VF_READY);
118 vcc->reply = msg->reply;
119 break;
120 case as_indicate:
121 vcc = (struct atm_vcc *) msg->listen_vcc;
122 DPRINTK("as_indicate!!!\n");
123 if (!vcc->backlog_quota) {
124 sigd_enq(0,as_reject,vcc,NULL,NULL);
125 return 0;
127 vcc->backlog_quota--;
128 skb_queue_tail(&vcc->listenq,skb);
129 if (vcc->callback) {
130 DPRINTK("waking vcc->sleep 0x%p\n",
131 &vcc->sleep);
132 vcc->callback(vcc);
134 return 0;
135 case as_close:
136 vcc->flags |= ATM_VF_RELEASED;
137 vcc->flags &= ~ATM_VF_READY;
138 vcc->reply = msg->reply;
139 break;
140 case as_modify:
141 modify_qos(vcc,msg);
142 break;
143 default:
144 printk(KERN_ALERT "sigd_send: bad message type %d\n",
145 (int) msg->type);
146 return -EINVAL;
148 if (vcc->callback) vcc->callback(vcc);
149 dev_kfree_skb(skb);
150 return 0;
154 void sigd_enq(struct atm_vcc *vcc,enum atmsvc_msg_type type,
155 const struct atm_vcc *listen_vcc,const struct sockaddr_atmpvc *pvc,
156 const struct sockaddr_atmsvc *svc)
158 struct sk_buff *skb;
159 struct atmsvc_msg *msg;
161 DPRINTK("sigd_enq %d (0x%p)\n",(int) type,vcc);
162 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL)))
163 schedule();
164 msg = (struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg));
165 msg->type = type;
166 msg->vcc = (unsigned long) vcc;
167 msg->listen_vcc = (unsigned long) listen_vcc;
168 msg->reply = 0; /* other ISP applications may use this field */
169 if (vcc) {
170 msg->qos = vcc->qos;
171 msg->sap = vcc->sap;
173 if (!svc) msg->svc.sas_family = 0;
174 else msg->svc = *svc;
175 if (vcc) msg->local = vcc->local;
176 if (!pvc) memset(&msg->pvc,0,sizeof(msg->pvc));
177 else msg->pvc = *pvc;
178 sigd_put_skb(skb);
179 if (vcc) vcc->flags |= ATM_VF_REGIS;
183 static void purge_vccs(struct atm_vcc *vcc)
185 while (vcc) {
186 if (vcc->family == PF_ATMSVC &&
187 !(vcc->flags & ATM_VF_META)) {
188 vcc->flags |= ATM_VF_RELEASED;
189 vcc->reply = -EUNATCH;
190 wake_up(&vcc->sleep);
192 vcc = vcc->next;
197 static void sigd_close(struct atm_vcc *vcc)
199 struct sk_buff *skb;
200 struct atm_dev *dev;
202 DPRINTK("sigd_close\n");
203 sigd = NULL;
204 if (skb_peek(&vcc->recvq))
205 printk(KERN_ERR "sigd_close: closing with requests pending\n");
206 while ((skb = skb_dequeue(&vcc->recvq))) kfree_skb(skb);
207 purge_vccs(nodev_vccs);
208 for (dev = atm_devs; dev; dev = dev->next) purge_vccs(dev->vccs);
212 static struct atmdev_ops sigd_dev_ops = {
213 NULL, /* no dev_close */
214 NULL, /* no open */
215 sigd_close, /* close */
216 NULL, /* no ioctl */
217 NULL, /* no getsockopt */
218 NULL, /* no setsockopt */
219 sigd_send, /* send */
220 NULL, /* no sg_send */
221 NULL, /* no send_oam */
222 NULL, /* no phy_put */
223 NULL, /* no phy_get */
224 NULL, /* no feedback */
225 NULL, /* no change_qos */
226 NULL /* no free_rx_skb */
230 static struct atm_dev sigd_dev = {
231 &sigd_dev_ops,
232 NULL, /* no PHY */
233 "sig", /* type */
234 999, /* dummy device number */
235 NULL,NULL, /* pretend not to have any VCCs */
236 NULL,NULL, /* no data */
237 0, /* no flags */
238 NULL, /* no local address */
239 { 0 } /* no ESI, no statistics */
243 int sigd_attach(struct atm_vcc *vcc)
245 if (sigd) return -EADDRINUSE;
246 DPRINTK("sigd_attach\n");
247 sigd = vcc;
248 bind_vcc(vcc,&sigd_dev);
249 vcc->flags |= ATM_VF_READY | ATM_VF_META;
250 wake_up(&sigd_sleep);
251 return 0;
255 void signaling_init(void)
257 init_waitqueue_head(&sigd_sleep);