2 * Stuff used by all variants of the driver
4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>.
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 * =====================================================================
18 /* == Handling of I4L IO =====================================================*/
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.
26 * driverID driver ID as assigned by LL
27 * channel channel number
28 * ack if != 0 LL wants to be notified on completion via
29 * statcallb(ISDN_STAT_BSENT)
30 * skb skb containing data to send
32 * number of accepted bytes
33 * 0 if temporarily unable to accept data (out of buffer space)
34 * <0 on error (eg. -EINVAL)
36 static int writebuf_from_LL(int driverID
, int channel
, int ack
,
44 if (!(cs
= gigaset_get_cs_by_id(driverID
))) {
45 pr_err("%s: invalid driver ID (%d)\n", __func__
, driverID
);
48 if (channel
< 0 || channel
>= cs
->channels
) {
49 dev_err(cs
->dev
, "%s: invalid channel ID (%d)\n",
53 bcs
= &cs
->bcs
[channel
];
55 /* can only handle linear sk_buffs */
56 if (skb_linearize(skb
) < 0) {
57 dev_err(cs
->dev
, "%s: skb_linearize failed\n", __func__
);
63 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
64 driverID
, channel
, ack
, len
);
68 dev_notice(cs
->dev
, "%s: not ACKing empty packet\n",
72 if (len
> MAX_BUF_SIZE
) {
73 dev_err(cs
->dev
, "%s: packet too large (%d bytes)\n",
78 skblen
= ack
? len
: 0;
79 skb
->head
[0] = skblen
& 0xff;
80 skb
->head
[1] = skblen
>> 8;
81 gig_dbg(DEBUG_MCMD
, "skb: len=%u, skblen=%u: %02x %02x",
82 len
, skblen
, (unsigned) skb
->head
[0], (unsigned) skb
->head
[1]);
84 /* pass to device-specific module */
85 return cs
->ops
->send_skb(bcs
, skb
);
89 * gigaset_skb_sent() - acknowledge sending an skb
90 * @bcs: B channel descriptor structure.
93 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
94 * skb has been successfully sent, for signalling completion to the LL.
96 void gigaset_skb_sent(struct bc_state
*bcs
, struct sk_buff
*skb
)
104 dev_warn(bcs
->cs
->dev
, "%s: skb->len==%d\n",
107 len
= (unsigned char) skb
->head
[0] |
108 (unsigned) (unsigned char) skb
->head
[1] << 8;
110 gig_dbg(DEBUG_MCMD
, "ACKing to LL (id: %d, ch: %d, sz: %u)",
111 bcs
->cs
->myid
, bcs
->channel
, len
);
113 response
.driver
= bcs
->cs
->myid
;
114 response
.command
= ISDN_STAT_BSENT
;
115 response
.arg
= bcs
->channel
;
116 response
.parm
.length
= len
;
117 bcs
->cs
->iif
.statcallb(&response
);
120 EXPORT_SYMBOL_GPL(gigaset_skb_sent
);
122 /* This function will be called by LL to send commands
123 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
124 * so don't put too much effort into it.
126 static int command_from_LL(isdn_ctrl
*cntrl
)
128 struct cardstate
*cs
= gigaset_get_cs_by_id(cntrl
->driver
);
129 struct bc_state
*bcs
;
131 struct setup_parm
*sp
;
133 gigaset_debugdrivers();
136 pr_err("%s: invalid driver ID (%d)\n", __func__
, cntrl
->driver
);
140 switch (cntrl
->command
) {
142 gig_dbg(DEBUG_ANY
, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
143 cntrl
->driver
, cntrl
->arg
);
145 dev_warn(cs
->dev
, "ISDN_CMD_IOCTL not supported\n");
150 "ISDN_CMD_DIAL (driver: %d, ch: %ld, "
151 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
152 cntrl
->driver
, cntrl
->arg
,
153 cntrl
->parm
.setup
.phone
, cntrl
->parm
.setup
.eazmsn
,
154 cntrl
->parm
.setup
.si1
, cntrl
->parm
.setup
.si2
);
156 if (cntrl
->arg
>= cs
->channels
) {
158 "ISDN_CMD_DIAL: invalid channel (%d)\n",
163 bcs
= cs
->bcs
+ cntrl
->arg
;
165 if (!gigaset_get_channel(bcs
)) {
166 dev_err(cs
->dev
, "ISDN_CMD_DIAL: channel not free\n");
170 sp
= kmalloc(sizeof *sp
, GFP_ATOMIC
);
172 gigaset_free_channel(bcs
);
173 dev_err(cs
->dev
, "ISDN_CMD_DIAL: out of memory\n");
176 *sp
= cntrl
->parm
.setup
;
178 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_DIAL
, sp
,
179 bcs
->at_state
.seq_index
, NULL
)) {
180 //FIXME what should we do?
182 gigaset_free_channel(bcs
);
186 gig_dbg(DEBUG_CMD
, "scheduling DIAL");
187 gigaset_schedule_event(cs
);
189 case ISDN_CMD_ACCEPTD
: //FIXME
190 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ACCEPTD");
192 if (cntrl
->arg
>= cs
->channels
) {
194 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n",
199 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
].at_state
,
200 EV_ACCEPT
, NULL
, 0, NULL
)) {
201 //FIXME what should we do?
205 gig_dbg(DEBUG_CMD
, "scheduling ACCEPT");
206 gigaset_schedule_event(cs
);
209 case ISDN_CMD_ACCEPTB
:
210 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ACCEPTB");
212 case ISDN_CMD_HANGUP
:
213 gig_dbg(DEBUG_ANY
, "ISDN_CMD_HANGUP (ch: %d)",
216 if (cntrl
->arg
>= cs
->channels
) {
218 "ISDN_CMD_HANGUP: invalid channel (%d)\n",
223 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
].at_state
,
224 EV_HUP
, NULL
, 0, NULL
)) {
225 //FIXME what should we do?
229 gig_dbg(DEBUG_CMD
, "scheduling HUP");
230 gigaset_schedule_event(cs
);
233 case ISDN_CMD_CLREAZ
: /* Do not signal incoming signals */ //FIXME
234 gig_dbg(DEBUG_ANY
, "ISDN_CMD_CLREAZ");
236 case ISDN_CMD_SETEAZ
: /* Signal incoming calls for given MSN */ //FIXME
238 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)",
239 cntrl
->driver
, cntrl
->arg
, cntrl
->parm
.num
);
241 case ISDN_CMD_SETL2
: /* Set L2 to given protocol */
242 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)",
243 cntrl
->arg
& 0xff, (cntrl
->arg
>> 8));
245 if ((cntrl
->arg
& 0xff) >= cs
->channels
) {
247 "ISDN_CMD_SETL2: invalid channel (%d)\n",
248 (int) cntrl
->arg
& 0xff);
252 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
& 0xff].at_state
,
253 EV_PROTO_L2
, NULL
, cntrl
->arg
>> 8,
255 //FIXME what should we do?
259 gig_dbg(DEBUG_CMD
, "scheduling PROTO_L2");
260 gigaset_schedule_event(cs
);
262 case ISDN_CMD_SETL3
: /* Set L3 to given protocol */
263 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)",
264 cntrl
->arg
& 0xff, (cntrl
->arg
>> 8));
266 if ((cntrl
->arg
& 0xff) >= cs
->channels
) {
268 "ISDN_CMD_SETL3: invalid channel (%d)\n",
269 (int) cntrl
->arg
& 0xff);
273 if (cntrl
->arg
>> 8 != ISDN_PROTO_L3_TRANS
) {
275 "ISDN_CMD_SETL3: invalid protocol %lu\n",
281 case ISDN_CMD_PROCEED
:
282 gig_dbg(DEBUG_ANY
, "ISDN_CMD_PROCEED"); //FIXME
285 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ALERT"); //FIXME
286 if (cntrl
->arg
>= cs
->channels
) {
288 "ISDN_CMD_ALERT: invalid channel (%d)\n",
292 //bcs = cs->bcs + cntrl->arg;
297 gig_dbg(DEBUG_ANY
, "ISDN_CMD_REDIR"); //FIXME
299 case ISDN_CMD_PROT_IO
:
300 gig_dbg(DEBUG_ANY
, "ISDN_CMD_PROT_IO");
302 case ISDN_CMD_FAXCMD
:
303 gig_dbg(DEBUG_ANY
, "ISDN_CMD_FAXCMD");
306 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETL2");
309 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETL3");
311 case ISDN_CMD_GETEAZ
:
312 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETEAZ");
314 case ISDN_CMD_SETSIL
:
315 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETSIL");
317 case ISDN_CMD_GETSIL
:
318 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETSIL");
321 dev_err(cs
->dev
, "unknown command %d from LL\n",
329 void gigaset_i4l_cmd(struct cardstate
*cs
, int cmd
)
333 command
.driver
= cs
->myid
;
334 command
.command
= cmd
;
336 cs
->iif
.statcallb(&command
);
339 void gigaset_i4l_channel_cmd(struct bc_state
*bcs
, int cmd
)
343 command
.driver
= bcs
->cs
->myid
;
344 command
.command
= cmd
;
345 command
.arg
= bcs
->channel
;
346 bcs
->cs
->iif
.statcallb(&command
);
349 int gigaset_isdn_setup_dial(struct at_state_t
*at_state
, void *data
)
351 struct bc_state
*bcs
= at_state
->bcs
;
354 size_t length
[AT_NUM
];
357 struct setup_parm
*sp
= data
;
359 switch (bcs
->proto2
) {
360 case ISDN_PROTO_L2_HDLC
:
361 proto
= 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
363 case ISDN_PROTO_L2_TRANS
:
364 proto
= 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
367 dev_err(bcs
->cs
->dev
, "%s: invalid L2 protocol: %u\n",
368 __func__
, bcs
->proto2
);
374 bc
= "9090A3"; /* 3.1 kHz audio, A-law */
377 default: /* hope the app knows what it is doing */
378 bc
= "8890"; /* unrestricted digital information */
380 //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC
382 length
[AT_DIAL
] = 1 + strlen(sp
->phone
) + 1 + 1;
383 l
= strlen(sp
->eazmsn
);
384 length
[AT_MSN
] = l
? 6 + l
+ 1 + 1 : 0;
385 length
[AT_BC
] = 5 + strlen(bc
) + 1 + 1;
386 length
[AT_PROTO
] = 6 + 1 + 1 + 1; /* proto: 1 character */
387 length
[AT_ISO
] = 6 + 1 + 1 + 1; /* channel: 1 character */
388 length
[AT_TYPE
] = 6 + 1 + 1 + 1; /* call type: 1 character */
391 for (i
= 0; i
< AT_NUM
; ++i
) {
392 kfree(bcs
->commands
[i
]);
393 bcs
->commands
[i
] = NULL
;
395 !(bcs
->commands
[i
] = kmalloc(length
[i
], GFP_ATOMIC
))) {
396 dev_err(bcs
->cs
->dev
, "out of memory\n");
401 /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */
402 if (sp
->phone
[0] == '*' && sp
->phone
[1] == '*') {
403 /* internal call: translate ** prefix to CTP value */
404 snprintf(bcs
->commands
[AT_DIAL
], length
[AT_DIAL
],
405 "D%s\r", sp
->phone
+2);
406 strncpy(bcs
->commands
[AT_TYPE
], "^SCTP=0\r", length
[AT_TYPE
]);
408 snprintf(bcs
->commands
[AT_DIAL
], length
[AT_DIAL
],
410 strncpy(bcs
->commands
[AT_TYPE
], "^SCTP=1\r", length
[AT_TYPE
]);
413 if (bcs
->commands
[AT_MSN
])
414 snprintf(bcs
->commands
[AT_MSN
], length
[AT_MSN
],
415 "^SMSN=%s\r", sp
->eazmsn
);
416 snprintf(bcs
->commands
[AT_BC
], length
[AT_BC
],
418 snprintf(bcs
->commands
[AT_PROTO
], length
[AT_PROTO
],
419 "^SBPR=%u\r", proto
);
420 snprintf(bcs
->commands
[AT_ISO
], length
[AT_ISO
],
421 "^SISO=%u\r", (unsigned)bcs
->channel
+ 1);
426 int gigaset_isdn_setup_accept(struct at_state_t
*at_state
)
429 size_t length
[AT_NUM
];
431 struct bc_state
*bcs
= at_state
->bcs
;
433 switch (bcs
->proto2
) {
434 case ISDN_PROTO_L2_HDLC
:
435 proto
= 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
437 case ISDN_PROTO_L2_TRANS
:
438 proto
= 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
441 dev_err(at_state
->cs
->dev
, "%s: invalid protocol: %u\n",
442 __func__
, bcs
->proto2
);
446 length
[AT_DIAL
] = 0;
449 length
[AT_PROTO
] = 6 + 1 + 1 + 1; /* proto: 1 character */
450 length
[AT_ISO
] = 6 + 1 + 1 + 1; /* channel: 1 character */
451 length
[AT_TYPE
] = 0;
454 for (i
= 0; i
< AT_NUM
; ++i
) {
455 kfree(bcs
->commands
[i
]);
456 bcs
->commands
[i
] = NULL
;
458 !(bcs
->commands
[i
] = kmalloc(length
[i
], GFP_ATOMIC
))) {
459 dev_err(at_state
->cs
->dev
, "out of memory\n");
464 snprintf(bcs
->commands
[AT_PROTO
], length
[AT_PROTO
],
465 "^SBPR=%u\r", proto
);
466 snprintf(bcs
->commands
[AT_ISO
], length
[AT_ISO
],
467 "^SISO=%u\r", (unsigned) bcs
->channel
+ 1);
473 * gigaset_isdn_icall() - signal incoming call
474 * @at_state: connection state structure.
476 * Called by main module to notify the LL that an incoming call has been
477 * received. @at_state contains the parameters of the call.
479 * Return value: call disposition (ICALL_*)
481 int gigaset_isdn_icall(struct at_state_t
*at_state
)
483 struct cardstate
*cs
= at_state
->cs
;
484 struct bc_state
*bcs
= at_state
->bcs
;
488 /* fill ICALL structure */
489 response
.parm
.setup
.si1
= 0; /* default: unknown */
490 response
.parm
.setup
.si2
= 0;
491 response
.parm
.setup
.screen
= 0; //FIXME how to set these?
492 response
.parm
.setup
.plan
= 0;
493 if (!at_state
->str_var
[STR_ZBC
]) {
494 /* no BC (internal call): assume speech, A-law */
495 response
.parm
.setup
.si1
= 1;
496 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "8890")) {
497 /* unrestricted digital information */
498 response
.parm
.setup
.si1
= 7;
499 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "8090A3")) {
501 response
.parm
.setup
.si1
= 1;
502 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "9090A3")) {
503 /* 3,1 kHz audio, A-law */
504 response
.parm
.setup
.si1
= 1;
505 response
.parm
.setup
.si2
= 2;
507 dev_warn(cs
->dev
, "RING ignored - unsupported BC %s\n",
508 at_state
->str_var
[STR_ZBC
]);
511 if (at_state
->str_var
[STR_NMBR
]) {
512 strncpy(response
.parm
.setup
.phone
, at_state
->str_var
[STR_NMBR
],
513 sizeof response
.parm
.setup
.phone
- 1);
514 response
.parm
.setup
.phone
[sizeof response
.parm
.setup
.phone
- 1] = 0;
516 response
.parm
.setup
.phone
[0] = 0;
517 if (at_state
->str_var
[STR_ZCPN
]) {
518 strncpy(response
.parm
.setup
.eazmsn
, at_state
->str_var
[STR_ZCPN
],
519 sizeof response
.parm
.setup
.eazmsn
- 1);
520 response
.parm
.setup
.eazmsn
[sizeof response
.parm
.setup
.eazmsn
- 1] = 0;
522 response
.parm
.setup
.eazmsn
[0] = 0;
525 dev_notice(cs
->dev
, "no channel for incoming call\n");
526 response
.command
= ISDN_STAT_ICALLW
;
527 response
.arg
= 0; //FIXME
529 gig_dbg(DEBUG_CMD
, "Sending ICALL");
530 response
.command
= ISDN_STAT_ICALL
;
531 response
.arg
= bcs
->channel
; //FIXME
533 response
.driver
= cs
->myid
;
534 retval
= cs
->iif
.statcallb(&response
);
535 gig_dbg(DEBUG_CMD
, "Response: %d", retval
);
537 case 0: /* no takers */
539 case 1: /* alerting */
540 bcs
->chstate
|= CHS_NOTIFY_LL
;
544 case 3: /* incomplete */
546 "LL requested unsupported feature: Incomplete Number\n");
548 case 4: /* proceeding */
549 /* Gigaset will send ALERTING anyway.
550 * There doesn't seem to be a way to avoid this.
553 case 5: /* deflect */
555 "LL requested unsupported feature: Call Deflection\n");
558 dev_err(cs
->dev
, "LL error %d on ICALL\n", retval
);
563 /* Set Callback function pointer */
564 int gigaset_register_to_LL(struct cardstate
*cs
, const char *isdnid
)
566 isdn_if
*iif
= &cs
->iif
;
568 gig_dbg(DEBUG_ANY
, "Register driver capabilities to LL");
570 if (snprintf(iif
->id
, sizeof iif
->id
, "%s_%u", isdnid
, cs
->minor_index
)
572 pr_err("ID too long: %s\n", isdnid
);
576 iif
->owner
= THIS_MODULE
;
577 iif
->channels
= cs
->channels
;
578 iif
->maxbufsize
= MAX_BUF_SIZE
;
579 iif
->features
= ISDN_FEATURE_L2_TRANS
|
580 ISDN_FEATURE_L2_HDLC
|
582 ISDN_FEATURE_L2_X75I
|
584 ISDN_FEATURE_L3_TRANS
|
586 iif
->hl_hdrlen
= HW_HDR_LEN
; /* Area for storing ack */
587 iif
->command
= command_from_LL
;
588 iif
->writebuf_skb
= writebuf_from_LL
;
589 iif
->writecmd
= NULL
; /* Don't support isdnctrl */
590 iif
->readstat
= NULL
; /* Don't support isdnctrl */
591 iif
->rcvcallb_skb
= NULL
; /* Will be set by LL */
592 iif
->statcallb
= NULL
; /* Will be set by LL */
594 if (!register_isdn(iif
)) {
595 pr_err("register_isdn failed\n");
599 cs
->myid
= iif
->channels
; /* Set my device id */