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>
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
27 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
29 #define DPRINTK(format,args...)
33 struct atm_vcc
*sigd
= NULL
;
34 static wait_queue_head_t sigd_sleep
;
37 static void sigd_put_skb(struct sk_buff
*skb
)
40 static unsigned long silence
= 0;
45 if (time_after(jiffies
, silence
) || silence
== 0) {
46 printk(KERN_INFO
"atmsvc: waiting for signaling demon "
48 silence
= (jiffies
+30*HZ
)|1;
50 sleep_on(&sigd_sleep
);
52 printk(KERN_WARNING
"atmsvc: no signaling demon\n");
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
)
67 if ((vcc
->flags
& ATM_VF_RELEASED
) || !(vcc
->flags
& ATM_VF_READY
))
70 if (!vcc
->dev
->ops
->change_qos
) msg
->reply
= -EOPNOTSUPP
;
73 msg
->reply
= vcc
->dev
->ops
->change_qos(vcc
,&msg
->qos
,
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
)))
83 *(struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
)) = *msg
;
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
;
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
;
117 vcc
->flags
&= ~(ATM_VF_REGIS
| ATM_VF_READY
);
118 vcc
->reply
= msg
->reply
;
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
);
127 vcc
->backlog_quota
--;
128 skb_queue_tail(&vcc
->listenq
,skb
);
130 DPRINTK("waking vcc->sleep 0x%p\n",
136 vcc
->flags
|= ATM_VF_RELEASED
;
137 vcc
->flags
&= ~ATM_VF_READY
;
138 vcc
->reply
= msg
->reply
;
144 printk(KERN_ALERT
"sigd_send: bad message type %d\n",
148 if (vcc
->callback
) vcc
->callback(vcc
);
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
)
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
)))
164 msg
= (struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
));
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 */
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
;
179 if (vcc
) vcc
->flags
|= ATM_VF_REGIS
;
183 static void purge_vccs(struct atm_vcc
*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
);
197 static void sigd_close(struct atm_vcc
*vcc
)
202 DPRINTK("sigd_close\n");
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 */
215 sigd_close
, /* close */
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
= {
234 999, /* dummy device number */
235 NULL
,NULL
, /* pretend not to have any VCCs */
236 NULL
,NULL
, /* no data */
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");
248 bind_vcc(vcc
,&sigd_dev
);
249 vcc
->flags
|= ATM_VF_READY
| ATM_VF_META
;
250 wake_up(&sigd_sleep
);
255 void signaling_init(void)
257 init_waitqueue_head(&sigd_sleep
);