2 * Callbacks for the FSM
4 * Copyright (C) 1996 Universidade de Lisboa
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>
24 #include <linux/skbuff.h>
28 #include <linux/isdnif.h>
33 #include "callbacks.h"
36 ushort last_ref_num = 1;
43 void cb_out_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
44 struct callb_data *cbdata)
52 printk(KERN_DEBUG "Called Party Number: %s\n",
53 cbdata->data.setup.CalledPN);
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,
63 printk("capi_conn_req failed\n");
68 refnum = last_ref_num++ & 0x7fffU;
73 chan->s_refnum = refnum;
75 pcbit_l2_write(dev, MSG_CONN_REQ, refnum, skb, len);
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)
93 if ((len=capi_conn_active_resp(chan, &skb)) < 0)
95 printk("capi_conn_active_req failed\n");
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;
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");
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
131 void cb_in_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
132 struct callb_data *cbdata)
135 unsigned short refnum;
140 ictl.command = ISDN_STAT_ICALL;
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");
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");
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;
168 printk(KERN_DEBUG "statstr: %s\n", ictl.num);
171 dev->dev_if->statcallb(&ictl);
174 if ((len=capi_conn_resp(chan, &skb)) < 0) {
175 printk(KERN_DEBUG "capi_conn_resp failed\n");
179 refnum = last_ref_num++ & 0x7fffU;
180 chan->s_refnum = refnum;
182 pcbit_l2_write(dev, MSG_CONN_RESP, refnum, skb, len);
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;
198 if ((len = capi_conn_active_req(chan, &skb)) < 0) {
199 printk(KERN_DEBUG "capi_conn_active_req failed\n");
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);
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;
224 if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
226 printk("capi_select_proto_req failed\n");
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
243 void cb_disc_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
244 struct callb_data *data)
251 if ((len = capi_disc_resp(chan, &skb)) < 0) {
252 printk("capi_disc_resp failed\n");
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;
264 dev->dev_if->statcallb(&ictl);
269 * User HANGUP on active/call proceeding state
272 void cb_disc_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
273 struct callb_data *data)
279 if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
281 printk("capi_disc_req failed\n");
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
296 void cb_disc_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
297 struct callb_data *data)
301 ictl.command = ISDN_STAT_BHUP;
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)
322 if ((len = capi_activate_transp_req(chan, &skb)) < 0)
324 printk("capi_conn_activate_transp_req failed\n");
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)
342 ictl.command = ISDN_STAT_BCONN;
345 dev->dev_if->statcallb(&ictl);