sctp: Support ipv6only AF_INET6 sockets.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / isdn / pcbit / callbacks.c
blob43ecd0f5423567c0dc2026106512383126bf813a
1 /*
2 * Callbacks for the FSM
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
13 * Fix: 19981230 - Carlos Morgado <chbm@techie.com>
14 * Port of Nelson Escravana's <nelson.escravana@usa.net> fix to CalledPN
15 * NULL pointer dereference in cb_in_1 (originally fixed in 2.0)
18 #include <linux/string.h>
19 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/slab.h>
23 #include <linux/mm.h>
24 #include <linux/skbuff.h>
26 #include <asm/io.h>
28 #include <linux/isdnif.h>
30 #include "pcbit.h"
31 #include "layer2.h"
32 #include "edss1.h"
33 #include "callbacks.h"
34 #include "capi.h"
36 ushort last_ref_num = 1;
39 * send_conn_req
43 void cb_out_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
44 struct callb_data *cbdata)
46 struct sk_buff *skb;
47 int len;
48 ushort refnum;
51 #ifdef DEBUG
52 printk(KERN_DEBUG "Called Party Number: %s\n",
53 cbdata->data.setup.CalledPN);
54 #endif
56 * hdr - kmalloc in capi_conn_req
57 * - kfree when msg has been sent
60 if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb,
61 chan->proto)) < 0)
63 printk("capi_conn_req failed\n");
64 return;
68 refnum = last_ref_num++ & 0x7fffU;
70 chan->callref = 0;
71 chan->layer2link = 0;
72 chan->snum = 0;
73 chan->s_refnum = refnum;
75 pcbit_l2_write(dev, MSG_CONN_REQ, refnum, skb, len);
79 * rcv CONNECT
80 * will go into ACTIVE state
81 * send CONN_ACTIVE_RESP
82 * send Select protocol request
85 void cb_out_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
86 struct callb_data *data)
88 isdn_ctrl ictl;
89 struct sk_buff *skb;
90 int len;
91 ushort refnum;
93 if ((len=capi_conn_active_resp(chan, &skb)) < 0)
95 printk("capi_conn_active_req failed\n");
96 return;
99 refnum = last_ref_num++ & 0x7fffU;
100 chan->s_refnum = refnum;
102 pcbit_l2_write(dev, MSG_CONN_ACTV_RESP, refnum, skb, len);
105 ictl.command = ISDN_STAT_DCONN;
106 ictl.driver=dev->id;
107 ictl.arg=chan->id;
108 dev->dev_if->statcallb(&ictl);
110 /* ACTIVE D-channel */
112 /* Select protocol */
114 if ((len=capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) {
115 printk("capi_select_proto_req failed\n");
116 return;
119 refnum = last_ref_num++ & 0x7fffU;
120 chan->s_refnum = refnum;
122 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
127 * Incoming call received
128 * inform user
131 void cb_in_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
132 struct callb_data *cbdata)
134 isdn_ctrl ictl;
135 unsigned short refnum;
136 struct sk_buff *skb;
137 int len;
140 ictl.command = ISDN_STAT_ICALL;
141 ictl.driver=dev->id;
142 ictl.arg=chan->id;
145 * ictl.num >= strlen() + strlen() + 5
148 if (cbdata->data.setup.CallingPN == NULL) {
149 printk(KERN_DEBUG "NULL CallingPN to phone; using 0\n");
150 strcpy(ictl.parm.setup.phone, "0");
152 else {
153 strcpy(ictl.parm.setup.phone, cbdata->data.setup.CallingPN);
155 if (cbdata->data.setup.CalledPN == NULL) {
156 printk(KERN_DEBUG "NULL CalledPN to eazmsn; using 0\n");
157 strcpy(ictl.parm.setup.eazmsn, "0");
159 else {
160 strcpy(ictl.parm.setup.eazmsn, cbdata->data.setup.CalledPN);
162 ictl.parm.setup.si1 = 7;
163 ictl.parm.setup.si2 = 0;
164 ictl.parm.setup.plan = 0;
165 ictl.parm.setup.screen = 0;
167 #ifdef DEBUG
168 printk(KERN_DEBUG "statstr: %s\n", ictl.num);
169 #endif
171 dev->dev_if->statcallb(&ictl);
174 if ((len=capi_conn_resp(chan, &skb)) < 0) {
175 printk(KERN_DEBUG "capi_conn_resp failed\n");
176 return;
179 refnum = last_ref_num++ & 0x7fffU;
180 chan->s_refnum = refnum;
182 pcbit_l2_write(dev, MSG_CONN_RESP, refnum, skb, len);
186 * user has replied
187 * open the channel
188 * send CONNECT message CONNECT_ACTIVE_REQ in CAPI
191 void cb_in_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
192 struct callb_data *data)
194 unsigned short refnum;
195 struct sk_buff *skb;
196 int len;
198 if ((len = capi_conn_active_req(chan, &skb)) < 0) {
199 printk(KERN_DEBUG "capi_conn_active_req failed\n");
200 return;
204 refnum = last_ref_num++ & 0x7fffU;
205 chan->s_refnum = refnum;
207 printk(KERN_DEBUG "sending MSG_CONN_ACTV_REQ\n");
208 pcbit_l2_write(dev, MSG_CONN_ACTV_REQ, refnum, skb, len);
212 * CONN_ACK arrived
213 * start b-proto selection
217 void cb_in_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
218 struct callb_data *data)
220 unsigned short refnum;
221 struct sk_buff *skb;
222 int len;
224 if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
226 printk("capi_select_proto_req failed\n");
227 return;
230 refnum = last_ref_num++ & 0x7fffU;
231 chan->s_refnum = refnum;
233 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
239 * Received disconnect ind on active state
240 * send disconnect resp
241 * send msg to user
243 void cb_disc_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
244 struct callb_data *data)
246 struct sk_buff *skb;
247 int len;
248 ushort refnum;
249 isdn_ctrl ictl;
251 if ((len = capi_disc_resp(chan, &skb)) < 0) {
252 printk("capi_disc_resp failed\n");
253 return;
256 refnum = last_ref_num++ & 0x7fffU;
257 chan->s_refnum = refnum;
259 pcbit_l2_write(dev, MSG_DISC_RESP, refnum, skb, len);
261 ictl.command = ISDN_STAT_BHUP;
262 ictl.driver=dev->id;
263 ictl.arg=chan->id;
264 dev->dev_if->statcallb(&ictl);
269 * User HANGUP on active/call proceeding state
270 * send disc.req
272 void cb_disc_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
273 struct callb_data *data)
275 struct sk_buff *skb;
276 int len;
277 ushort refnum;
279 if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
281 printk("capi_disc_req failed\n");
282 return;
285 refnum = last_ref_num++ & 0x7fffU;
286 chan->s_refnum = refnum;
288 pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb, len);
292 * Disc confirm received send BHUP
293 * Problem: when the HL driver sends the disc req itself
294 * LL receives BHUP
296 void cb_disc_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
297 struct callb_data *data)
299 isdn_ctrl ictl;
301 ictl.command = ISDN_STAT_BHUP;
302 ictl.driver=dev->id;
303 ictl.arg=chan->id;
304 dev->dev_if->statcallb(&ictl);
307 void cb_notdone(struct pcbit_dev * dev, struct pcbit_chan* chan,
308 struct callb_data *data)
313 * send activate b-chan protocol
315 void cb_selp_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
316 struct callb_data *data)
318 struct sk_buff *skb;
319 int len;
320 ushort refnum;
322 if ((len = capi_activate_transp_req(chan, &skb)) < 0)
324 printk("capi_conn_activate_transp_req failed\n");
325 return;
328 refnum = last_ref_num++ & 0x7fffU;
329 chan->s_refnum = refnum;
331 pcbit_l2_write(dev, MSG_ACT_TRANSP_REQ, refnum, skb, len);
335 * Inform User that the B-channel is available
337 void cb_open(struct pcbit_dev * dev, struct pcbit_chan* chan,
338 struct callb_data *data)
340 isdn_ctrl ictl;
342 ictl.command = ISDN_STAT_BCONN;
343 ictl.driver=dev->id;
344 ictl.arg=chan->id;
345 dev->dev_if->statcallb(&ictl);