blob: cc1d3093e433527999f15ce2f37b63ba148d082b [file] [log] [blame]
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -08001/*
2 * Stuff used by all variants of the driver
3 *
4 * Copyright (c) 2001 by Stefan Eilers (Eilers.Stefan@epost.de),
5 * Hansjoerg Lipp (hjlipp@web.de),
6 * Tilman Schmidt (tilman@imap.cc).
7 *
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080014 */
15
16#include "gigaset.h"
17
Tilman Schmidt784d5852006-04-10 22:55:04 -070018/* == Handling of I4L IO =====================================================*/
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080019
20/* writebuf_from_LL
21 * called by LL to transmit data on an open channel
22 * inserts the buffer data into the send queue and starts the transmission
23 * Note that this operation must not sleep!
24 * When the buffer is processed completely, gigaset_skb_sent() should be called.
25 * parameters:
26 * driverID driver ID as assigned by LL
27 * channel channel number
Tilman Schmidt917f5082006-04-10 22:55:00 -070028 * ack if != 0 LL wants to be notified on completion via
29 * statcallb(ISDN_STAT_BSENT)
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080030 * skb skb containing data to send
31 * return value:
32 * number of accepted bytes
33 * 0 if temporarily unable to accept data (out of buffer space)
34 * <0 on error (eg. -EINVAL)
35 */
Tilman Schmidt784d5852006-04-10 22:55:04 -070036static int writebuf_from_LL(int driverID, int channel, int ack,
37 struct sk_buff *skb)
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080038{
39 struct cardstate *cs;
40 struct bc_state *bcs;
41 unsigned len;
42 unsigned skblen;
43
44 if (!(cs = gigaset_get_cs_by_id(driverID))) {
45 err("%s: invalid driver ID (%d)", __func__, driverID);
46 return -ENODEV;
47 }
48 if (channel < 0 || channel >= cs->channels) {
49 err("%s: invalid channel ID (%d)", __func__, channel);
50 return -ENODEV;
51 }
52 bcs = &cs->bcs[channel];
53 len = skb->len;
54
Tilman Schmidt784d5852006-04-10 22:55:04 -070055 gig_dbg(DEBUG_LLDATA,
56 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
57 driverID, channel, ack, len);
58
59 if (!atomic_read(&cs->connected)) {
60 err("%s: disconnected", __func__);
61 return -ENODEV;
62 }
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080063
64 if (!len) {
65 if (ack)
Tilman Schmidt784d5852006-04-10 22:55:04 -070066 notice("%s: not ACKing empty packet", __func__);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080067 return 0;
68 }
69 if (len > MAX_BUF_SIZE) {
Tilman Schmidt784d5852006-04-10 22:55:04 -070070 err("%s: packet too large (%d bytes)", __func__, len);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080071 return -EINVAL;
72 }
73
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080074 skblen = ack ? len : 0;
75 skb->head[0] = skblen & 0xff;
76 skb->head[1] = skblen >> 8;
Tilman Schmidt784d5852006-04-10 22:55:04 -070077 gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x",
78 len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080079
80 /* pass to device-specific module */
81 return cs->ops->send_skb(bcs, skb);
82}
83
84void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
85{
86 unsigned len;
87 isdn_ctrl response;
88
89 ++bcs->trans_up;
90
91 if (skb->len)
Tilman Schmidt784d5852006-04-10 22:55:04 -070092 dev_warn(bcs->cs->dev, "%s: skb->len==%d\n",
93 __func__, skb->len);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -080094
95 len = (unsigned char) skb->head[0] |
96 (unsigned) (unsigned char) skb->head[1] << 8;
97 if (len) {
Tilman Schmidt784d5852006-04-10 22:55:04 -070098 gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
99 bcs->cs->myid, bcs->channel, len);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800100
101 response.driver = bcs->cs->myid;
102 response.command = ISDN_STAT_BSENT;
103 response.arg = bcs->channel;
104 response.parm.length = len;
105 bcs->cs->iif.statcallb(&response);
106 }
107}
108EXPORT_SYMBOL_GPL(gigaset_skb_sent);
109
110/* This function will be called by LL to send commands
111 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
112 * so don't put too much effort into it.
113 */
114static int command_from_LL(isdn_ctrl *cntrl)
115{
116 struct cardstate *cs = gigaset_get_cs_by_id(cntrl->driver);
117 //isdn_ctrl response;
118 //unsigned long flags;
119 struct bc_state *bcs;
120 int retval = 0;
121 struct setup_parm *sp;
122
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800123 gigaset_debugdrivers();
124
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800125 //FIXME "remove test for &connected"
126 if ((!cs || !atomic_read(&cs->connected))) {
127 warn("LL tried to access unknown device with nr. %d",
128 cntrl->driver);
129 return -ENODEV;
130 }
131
132 switch (cntrl->command) {
133 case ISDN_CMD_IOCTL:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700134 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
135 cntrl->driver, cntrl->arg);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800136
137 warn("ISDN_CMD_IOCTL is not supported.");
138 return -EINVAL;
139
140 case ISDN_CMD_DIAL:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700141 gig_dbg(DEBUG_ANY,
142 "ISDN_CMD_DIAL (driver: %d, ch: %ld, "
143 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
144 cntrl->driver, cntrl->arg,
145 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
146 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800147
148 if (cntrl->arg >= cs->channels) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700149 err("ISDN_CMD_DIAL: invalid channel (%d)",
150 (int) cntrl->arg);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800151 return -EINVAL;
152 }
153
154 bcs = cs->bcs + cntrl->arg;
155
156 if (!gigaset_get_channel(bcs)) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700157 err("ISDN_CMD_DIAL: channel not free");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800158 return -EBUSY;
159 }
160
161 sp = kmalloc(sizeof *sp, GFP_ATOMIC);
162 if (!sp) {
163 gigaset_free_channel(bcs);
164 err("ISDN_CMD_DIAL: out of memory");
165 return -ENOMEM;
166 }
167 *sp = cntrl->parm.setup;
168
169 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700170 atomic_read(&bcs->at_state.seq_index),
171 NULL)) {
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800172 //FIXME what should we do?
173 kfree(sp);
174 gigaset_free_channel(bcs);
175 return -ENOMEM;
176 }
177
Tilman Schmidt784d5852006-04-10 22:55:04 -0700178 gig_dbg(DEBUG_CMD, "scheduling DIAL");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800179 gigaset_schedule_event(cs);
180 break;
181 case ISDN_CMD_ACCEPTD: //FIXME
Tilman Schmidt784d5852006-04-10 22:55:04 -0700182 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800183
184 if (cntrl->arg >= cs->channels) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700185 err("ISDN_CMD_ACCEPTD: invalid channel (%d)",
186 (int) cntrl->arg);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800187 return -EINVAL;
188 }
189
190 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700191 EV_ACCEPT, NULL, 0, NULL)) {
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800192 //FIXME what should we do?
193 return -ENOMEM;
194 }
195
Tilman Schmidt784d5852006-04-10 22:55:04 -0700196 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800197 gigaset_schedule_event(cs);
198
199 break;
200 case ISDN_CMD_ACCEPTB:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700201 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800202 break;
203 case ISDN_CMD_HANGUP:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700204 gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)",
205 (int) cntrl->arg);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800206
207 if (cntrl->arg >= cs->channels) {
208 err("ISDN_CMD_HANGUP: invalid channel (%u)",
209 (unsigned) cntrl->arg);
210 return -EINVAL;
211 }
212
213 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700214 EV_HUP, NULL, 0, NULL)) {
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800215 //FIXME what should we do?
216 return -ENOMEM;
217 }
218
Tilman Schmidt784d5852006-04-10 22:55:04 -0700219 gig_dbg(DEBUG_CMD, "scheduling HUP");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800220 gigaset_schedule_event(cs);
221
222 break;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700223 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME
Tilman Schmidt784d5852006-04-10 22:55:04 -0700224 gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800225 break;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700226 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME
Tilman Schmidt784d5852006-04-10 22:55:04 -0700227 gig_dbg(DEBUG_ANY,
228 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)",
229 cntrl->driver, cntrl->arg, cntrl->parm.num);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800230 break;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700231 case ISDN_CMD_SETL2: /* Set L2 to given protocol */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700232 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)",
233 cntrl->arg & 0xff, (cntrl->arg >> 8));
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800234
235 if ((cntrl->arg & 0xff) >= cs->channels) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700236 err("ISDN_CMD_SETL2: invalid channel (%u)",
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800237 (unsigned) cntrl->arg & 0xff);
238 return -EINVAL;
239 }
240
241 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state,
Tilman Schmidt784d5852006-04-10 22:55:04 -0700242 EV_PROTO_L2, NULL, cntrl->arg >> 8,
243 NULL)) {
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800244 //FIXME what should we do?
245 return -ENOMEM;
246 }
247
Tilman Schmidt784d5852006-04-10 22:55:04 -0700248 gig_dbg(DEBUG_CMD, "scheduling PROTO_L2");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800249 gigaset_schedule_event(cs);
250 break;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700251 case ISDN_CMD_SETL3: /* Set L3 to given protocol */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700252 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)",
253 cntrl->arg & 0xff, (cntrl->arg >> 8));
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800254
255 if ((cntrl->arg & 0xff) >= cs->channels) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700256 err("ISDN_CMD_SETL3: invalid channel (%u)",
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800257 (unsigned) cntrl->arg & 0xff);
258 return -EINVAL;
259 }
260
261 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700262 err("ISDN_CMD_SETL3: invalid protocol %lu",
263 cntrl->arg >> 8);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800264 return -EINVAL;
265 }
266
267 break;
268 case ISDN_CMD_PROCEED:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700269 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800270 break;
271 case ISDN_CMD_ALERT:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700272 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800273 if (cntrl->arg >= cs->channels) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700274 err("ISDN_CMD_ALERT: invalid channel (%d)",
275 (int) cntrl->arg);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800276 return -EINVAL;
277 }
278 //bcs = cs->bcs + cntrl->arg;
279 //bcs->proto2 = -1;
280 // FIXME
281 break;
282 case ISDN_CMD_REDIR:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700283 gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800284 break;
285 case ISDN_CMD_PROT_IO:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700286 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800287 break;
288 case ISDN_CMD_FAXCMD:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700289 gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800290 break;
291 case ISDN_CMD_GETL2:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700292 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800293 break;
294 case ISDN_CMD_GETL3:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700295 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800296 break;
297 case ISDN_CMD_GETEAZ:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700298 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800299 break;
300 case ISDN_CMD_SETSIL:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700301 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800302 break;
303 case ISDN_CMD_GETSIL:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700304 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800305 break;
306 default:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700307 err("unknown command %d from LL", cntrl->command);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800308 return -EINVAL;
309 }
310
311 return retval;
312}
313
314void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
315{
316 isdn_ctrl command;
317
318 command.driver = cs->myid;
319 command.command = cmd;
320 command.arg = 0;
321 cs->iif.statcallb(&command);
322}
323
324void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
325{
326 isdn_ctrl command;
327
328 command.driver = bcs->cs->myid;
329 command.command = cmd;
330 command.arg = bcs->channel;
331 bcs->cs->iif.statcallb(&command);
332}
333
334int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
335{
336 struct bc_state *bcs = at_state->bcs;
337 unsigned proto;
338 const char *bc;
339 size_t length[AT_NUM];
340 size_t l;
341 int i;
342 struct setup_parm *sp = data;
343
344 switch (bcs->proto2) {
345 case ISDN_PROTO_L2_HDLC:
346 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
347 break;
348 case ISDN_PROTO_L2_TRANS:
349 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
350 break;
351 default:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700352 dev_err(bcs->cs->dev, "%s: invalid L2 protocol: %u\n",
353 __func__, bcs->proto2);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800354 return -EINVAL;
355 }
356
357 switch (sp->si1) {
358 case 1: /* audio */
359 bc = "9090A3"; /* 3.1 kHz audio, A-law */
360 break;
361 case 7: /* data */
362 default: /* hope the app knows what it is doing */
363 bc = "8890"; /* unrestricted digital information */
364 }
365 //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC
366
367 length[AT_DIAL ] = 1 + strlen(sp->phone) + 1 + 1;
368 l = strlen(sp->eazmsn);
369 length[AT_MSN ] = l ? 6 + l + 1 + 1 : 0;
370 length[AT_BC ] = 5 + strlen(bc) + 1 + 1;
371 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
372 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
373 length[AT_TYPE ] = 6 + 1 + 1 + 1; /* call type: 1 character */
374 length[AT_HLC ] = 0;
375
376 for (i = 0; i < AT_NUM; ++i) {
377 kfree(bcs->commands[i]);
378 bcs->commands[i] = NULL;
379 if (length[i] &&
380 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700381 dev_err(bcs->cs->dev, "out of memory\n");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800382 return -ENOMEM;
383 }
384 }
385
386 /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */
387 if (sp->phone[0] == '*' && sp->phone[1] == '*') {
388 /* internal call: translate ** prefix to CTP value */
389 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
390 "D%s\r", sp->phone+2);
391 strncpy(bcs->commands[AT_TYPE], "^SCTP=0\r", length[AT_TYPE]);
392 } else {
393 snprintf(bcs->commands[AT_DIAL], length[AT_DIAL],
394 "D%s\r", sp->phone);
395 strncpy(bcs->commands[AT_TYPE], "^SCTP=1\r", length[AT_TYPE]);
396 }
397
398 if (bcs->commands[AT_MSN])
Tilman Schmidt917f5082006-04-10 22:55:00 -0700399 snprintf(bcs->commands[AT_MSN], length[AT_MSN],
400 "^SMSN=%s\r", sp->eazmsn);
401 snprintf(bcs->commands[AT_BC ], length[AT_BC ],
402 "^SBC=%s\r", bc);
403 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
404 "^SBPR=%u\r", proto);
405 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
406 "^SISO=%u\r", (unsigned)bcs->channel + 1);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800407
408 return 0;
409}
410
411int gigaset_isdn_setup_accept(struct at_state_t *at_state)
412{
413 unsigned proto;
414 size_t length[AT_NUM];
415 int i;
416 struct bc_state *bcs = at_state->bcs;
417
418 switch (bcs->proto2) {
419 case ISDN_PROTO_L2_HDLC:
420 proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
421 break;
422 case ISDN_PROTO_L2_TRANS:
423 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
424 break;
425 default:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700426 dev_err(at_state->cs->dev, "%s: invalid protocol: %u\n",
427 __func__, bcs->proto2);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800428 return -EINVAL;
429 }
430
431 length[AT_DIAL ] = 0;
432 length[AT_MSN ] = 0;
433 length[AT_BC ] = 0;
434 length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */
435 length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */
436 length[AT_TYPE ] = 0;
437 length[AT_HLC ] = 0;
438
439 for (i = 0; i < AT_NUM; ++i) {
440 kfree(bcs->commands[i]);
441 bcs->commands[i] = NULL;
442 if (length[i] &&
443 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700444 dev_err(at_state->cs->dev, "out of memory\n");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800445 return -ENOMEM;
446 }
447 }
448
Tilman Schmidt917f5082006-04-10 22:55:00 -0700449 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
450 "^SBPR=%u\r", proto);
451 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
452 "^SISO=%u\r", (unsigned) bcs->channel + 1);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800453
454 return 0;
455}
456
457int gigaset_isdn_icall(struct at_state_t *at_state)
458{
459 struct cardstate *cs = at_state->cs;
460 struct bc_state *bcs = at_state->bcs;
461 isdn_ctrl response;
462 int retval;
463
464 /* fill ICALL structure */
465 response.parm.setup.si1 = 0; /* default: unknown */
466 response.parm.setup.si2 = 0;
467 response.parm.setup.screen = 0; //FIXME how to set these?
468 response.parm.setup.plan = 0;
469 if (!at_state->str_var[STR_ZBC]) {
470 /* no BC (internal call): assume speech, A-law */
471 response.parm.setup.si1 = 1;
472 } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) {
473 /* unrestricted digital information */
474 response.parm.setup.si1 = 7;
475 } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) {
476 /* speech, A-law */
477 response.parm.setup.si1 = 1;
478 } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) {
479 /* 3,1 kHz audio, A-law */
480 response.parm.setup.si1 = 1;
481 response.parm.setup.si2 = 2;
482 } else {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700483 dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800484 at_state->str_var[STR_ZBC]);
485 return ICALL_IGNORE;
486 }
487 if (at_state->str_var[STR_NMBR]) {
488 strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
489 sizeof response.parm.setup.phone - 1);
490 response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0;
491 } else
492 response.parm.setup.phone[0] = 0;
493 if (at_state->str_var[STR_ZCPN]) {
494 strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
495 sizeof response.parm.setup.eazmsn - 1);
496 response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0;
497 } else
498 response.parm.setup.eazmsn[0] = 0;
499
500 if (!bcs) {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700501 dev_notice(cs->dev, "no channel for incoming call\n");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800502 response.command = ISDN_STAT_ICALLW;
503 response.arg = 0; //FIXME
504 } else {
Tilman Schmidt784d5852006-04-10 22:55:04 -0700505 gig_dbg(DEBUG_CMD, "Sending ICALL");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800506 response.command = ISDN_STAT_ICALL;
507 response.arg = bcs->channel; //FIXME
508 }
509 response.driver = cs->myid;
510 retval = cs->iif.statcallb(&response);
Tilman Schmidt784d5852006-04-10 22:55:04 -0700511 gig_dbg(DEBUG_CMD, "Response: %d", retval);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800512 switch (retval) {
513 case 0: /* no takers */
514 return ICALL_IGNORE;
515 case 1: /* alerting */
516 bcs->chstate |= CHS_NOTIFY_LL;
517 return ICALL_ACCEPT;
518 case 2: /* reject */
519 return ICALL_REJECT;
520 case 3: /* incomplete */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700521 dev_warn(cs->dev,
522 "LL requested unsupported feature: Incomplete Number\n");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800523 return ICALL_IGNORE;
524 case 4: /* proceeding */
525 /* Gigaset will send ALERTING anyway.
526 * There doesn't seem to be a way to avoid this.
527 */
528 return ICALL_ACCEPT;
529 case 5: /* deflect */
Tilman Schmidt784d5852006-04-10 22:55:04 -0700530 dev_warn(cs->dev,
531 "LL requested unsupported feature: Call Deflection\n");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800532 return ICALL_IGNORE;
533 default:
Tilman Schmidt784d5852006-04-10 22:55:04 -0700534 dev_err(cs->dev, "LL error %d on ICALL\n", retval);
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800535 return ICALL_IGNORE;
536 }
537}
538
539/* Set Callback function pointer */
540int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
541{
542 isdn_if *iif = &cs->iif;
543
Tilman Schmidt784d5852006-04-10 22:55:04 -0700544 gig_dbg(DEBUG_ANY, "Register driver capabilities to LL");
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800545
546 //iif->id[sizeof(iif->id) - 1]=0;
547 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1);
548 if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
549 >= sizeof iif->id)
550 return -ENOMEM; //FIXME EINVAL/...??
551
552 iif->owner = THIS_MODULE;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700553 iif->channels = cs->channels;
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800554 iif->maxbufsize = MAX_BUF_SIZE;
Tilman Schmidt917f5082006-04-10 22:55:00 -0700555 iif->features = ISDN_FEATURE_L2_TRANS |
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800556 ISDN_FEATURE_L2_HDLC |
557#ifdef GIG_X75
558 ISDN_FEATURE_L2_X75I |
559#endif
560 ISDN_FEATURE_L3_TRANS |
561 ISDN_FEATURE_P_EURO;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700562 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800563 iif->command = command_from_LL;
564 iif->writebuf_skb = writebuf_from_LL;
Tilman Schmidt784d5852006-04-10 22:55:04 -0700565 iif->writecmd = NULL; /* Don't support isdnctrl */
566 iif->readstat = NULL; /* Don't support isdnctrl */
567 iif->rcvcallb_skb = NULL; /* Will be set by LL */
568 iif->statcallb = NULL; /* Will be set by LL */
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800569
570 if (!register_isdn(iif))
571 return 0;
572
Tilman Schmidt784d5852006-04-10 22:55:04 -0700573 cs->myid = iif->channels; /* Set my device id */
Hansjoerg Lipp3c66a222006-03-26 01:38:31 -0800574 return 1;
575}