2 * Callbacks for the FSM
4 * Copyright (C) 1996 Universidade de Lisboa
6 * Written by Pedro Roque Marques (pedro_m@yahoo.com)
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/sched.h>
19 #include <linux/string.h>
20 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/slab.h>
25 #include <linux/tqueue.h>
26 #include <linux/skbuff.h>
30 #include <linux/isdnif.h>
35 #include "callbacks.h"
38 ushort last_ref_num = 1;
45 void cb_out_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
46 struct callb_data *cbdata)
54 printk(KERN_DEBUG "Called Party Number: %s\n",
55 cbdata->data.setup.CalledPN);
58 * hdr - kmalloc in capi_conn_req
59 * - kfree when msg has been sent
62 if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb,
65 printk("capi_conn_req failed\n");
70 refnum = last_ref_num++ & 0x7fffU;
75 chan->s_refnum = refnum;
77 pcbit_l2_write(dev, MSG_CONN_REQ, refnum, skb, len);
82 * will go into ACTIVE state
83 * send CONN_ACTIVE_RESP
84 * send Select protocol request
87 void cb_out_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
88 struct callb_data *data)
95 if ((len=capi_conn_active_resp(chan, &skb)) < 0)
97 printk("capi_conn_active_req failed\n");
101 refnum = last_ref_num++ & 0x7fffU;
102 chan->s_refnum = refnum;
104 pcbit_l2_write(dev, MSG_CONN_ACTV_RESP, refnum, skb, len);
107 ictl.command = ISDN_STAT_DCONN;
110 dev->dev_if->statcallb(&ictl);
112 /* ACTIVE D-channel */
114 /* Select protocol */
116 if ((len=capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) {
117 printk("capi_select_proto_req failed\n");
121 refnum = last_ref_num++ & 0x7fffU;
122 chan->s_refnum = refnum;
124 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
129 * Disconnect received (actually RELEASE COMPLETE)
130 * This means we were not able to establish connection with remote
131 * Inform the big boss above
133 void cb_out_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
134 struct callb_data *data)
138 ictl.command = ISDN_STAT_DHUP;
141 dev->dev_if->statcallb(&ictl);
146 * Incoming call received
150 void cb_in_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
151 struct callb_data *cbdata)
154 unsigned short refnum;
159 ictl.command = ISDN_STAT_ICALL;
164 * ictl.num >= strlen() + strlen() + 5
167 if (cbdata->data.setup.CallingPN == NULL) {
168 printk(KERN_DEBUG "NULL CallingPN to phone; using 0\n");
169 strcpy(ictl.parm.setup.phone, "0");
172 strcpy(ictl.parm.setup.phone, cbdata->data.setup.CallingPN);
174 if (cbdata->data.setup.CalledPN == NULL) {
175 printk(KERN_DEBUG "NULL CalledPN to eazmsn; using 0\n");
176 strcpy(ictl.parm.setup.eazmsn, "0");
179 strcpy(ictl.parm.setup.eazmsn, cbdata->data.setup.CalledPN);
181 ictl.parm.setup.si1 = 7;
182 ictl.parm.setup.si2 = 0;
183 ictl.parm.setup.plan = 0;
184 ictl.parm.setup.screen = 0;
187 printk(KERN_DEBUG "statstr: %s\n", ictl.num);
190 dev->dev_if->statcallb(&ictl);
193 if ((len=capi_conn_resp(chan, &skb)) < 0) {
194 printk(KERN_DEBUG "capi_conn_resp failed\n");
198 refnum = last_ref_num++ & 0x7fffU;
199 chan->s_refnum = refnum;
201 pcbit_l2_write(dev, MSG_CONN_RESP, refnum, skb, len);
207 * send CONNECT message CONNECT_ACTIVE_REQ in CAPI
210 void cb_in_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
211 struct callb_data *data)
213 unsigned short refnum;
217 if ((len = capi_conn_active_req(chan, &skb)) < 0) {
218 printk(KERN_DEBUG "capi_conn_active_req failed\n");
223 refnum = last_ref_num++ & 0x7fffU;
224 chan->s_refnum = refnum;
226 printk(KERN_DEBUG "sending MSG_CONN_ACTV_REQ\n");
227 pcbit_l2_write(dev, MSG_CONN_ACTV_REQ, refnum, skb, len);
232 * start b-proto selection
236 void cb_in_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
237 struct callb_data *data)
239 unsigned short refnum;
243 if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
245 printk("capi_select_proto_req failed\n");
249 refnum = last_ref_num++ & 0x7fffU;
250 chan->s_refnum = refnum;
252 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
258 * Received disconnect ind on active state
259 * send disconnect resp
262 void cb_disc_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
263 struct callb_data *data)
270 if ((len = capi_disc_resp(chan, &skb)) < 0) {
271 printk("capi_disc_resp failed\n");
275 refnum = last_ref_num++ & 0x7fffU;
276 chan->s_refnum = refnum;
278 pcbit_l2_write(dev, MSG_DISC_RESP, refnum, skb, len);
280 ictl.command = ISDN_STAT_BHUP;
283 dev->dev_if->statcallb(&ictl);
288 * User HANGUP on active/call proceeding state
291 void cb_disc_2(struct pcbit_dev * dev, struct pcbit_chan* chan,
292 struct callb_data *data)
298 if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
300 printk("capi_disc_req failed\n");
304 refnum = last_ref_num++ & 0x7fffU;
305 chan->s_refnum = refnum;
307 pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb, len);
311 * Disc confirm received send BHUP
312 * Problem: when the HL driver sends the disc req itself
315 void cb_disc_3(struct pcbit_dev * dev, struct pcbit_chan* chan,
316 struct callb_data *data)
320 ictl.command = ISDN_STAT_BHUP;
323 dev->dev_if->statcallb(&ictl);
326 void cb_notdone(struct pcbit_dev * dev, struct pcbit_chan* chan,
327 struct callb_data *data)
332 * send activate b-chan protocol
334 void cb_selp_1(struct pcbit_dev * dev, struct pcbit_chan* chan,
335 struct callb_data *data)
341 if ((len = capi_activate_transp_req(chan, &skb)) < 0)
343 printk("capi_conn_activate_transp_req failed\n");
347 refnum = last_ref_num++ & 0x7fffU;
348 chan->s_refnum = refnum;
350 pcbit_l2_write(dev, MSG_ACT_TRANSP_REQ, refnum, skb, len);
354 * Inform User that the B-channel is available
356 void cb_open(struct pcbit_dev * dev, struct pcbit_chan* chan,
357 struct callb_data *data)
361 ictl.command = ISDN_STAT_BCONN;
364 dev->dev_if->statcallb(&ictl);