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
];
57 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
58 driverID
, channel
, ack
, len
);
62 dev_notice(cs
->dev
, "%s: not ACKing empty packet\n",
66 if (len
> MAX_BUF_SIZE
) {
67 dev_err(cs
->dev
, "%s: packet too large (%d bytes)\n",
72 skblen
= ack
? len
: 0;
73 skb
->head
[0] = skblen
& 0xff;
74 skb
->head
[1] = skblen
>> 8;
75 gig_dbg(DEBUG_MCMD
, "skb: len=%u, skblen=%u: %02x %02x",
76 len
, skblen
, (unsigned) skb
->head
[0], (unsigned) skb
->head
[1]);
78 /* pass to device-specific module */
79 return cs
->ops
->send_skb(bcs
, skb
);
82 void gigaset_skb_sent(struct bc_state
*bcs
, struct sk_buff
*skb
)
90 dev_warn(bcs
->cs
->dev
, "%s: skb->len==%d\n",
93 len
= (unsigned char) skb
->head
[0] |
94 (unsigned) (unsigned char) skb
->head
[1] << 8;
96 gig_dbg(DEBUG_MCMD
, "ACKing to LL (id: %d, ch: %d, sz: %u)",
97 bcs
->cs
->myid
, bcs
->channel
, len
);
99 response
.driver
= bcs
->cs
->myid
;
100 response
.command
= ISDN_STAT_BSENT
;
101 response
.arg
= bcs
->channel
;
102 response
.parm
.length
= len
;
103 bcs
->cs
->iif
.statcallb(&response
);
106 EXPORT_SYMBOL_GPL(gigaset_skb_sent
);
108 /* This function will be called by LL to send commands
109 * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
110 * so don't put too much effort into it.
112 static int command_from_LL(isdn_ctrl
*cntrl
)
114 struct cardstate
*cs
= gigaset_get_cs_by_id(cntrl
->driver
);
115 struct bc_state
*bcs
;
117 struct setup_parm
*sp
;
119 gigaset_debugdrivers();
122 pr_err("%s: invalid driver ID (%d)\n", __func__
, cntrl
->driver
);
126 switch (cntrl
->command
) {
128 gig_dbg(DEBUG_ANY
, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
129 cntrl
->driver
, cntrl
->arg
);
131 dev_warn(cs
->dev
, "ISDN_CMD_IOCTL not supported\n");
136 "ISDN_CMD_DIAL (driver: %d, ch: %ld, "
137 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
138 cntrl
->driver
, cntrl
->arg
,
139 cntrl
->parm
.setup
.phone
, cntrl
->parm
.setup
.eazmsn
,
140 cntrl
->parm
.setup
.si1
, cntrl
->parm
.setup
.si2
);
142 if (cntrl
->arg
>= cs
->channels
) {
144 "ISDN_CMD_DIAL: invalid channel (%d)\n",
149 bcs
= cs
->bcs
+ cntrl
->arg
;
151 if (!gigaset_get_channel(bcs
)) {
152 dev_err(cs
->dev
, "ISDN_CMD_DIAL: channel not free\n");
156 sp
= kmalloc(sizeof *sp
, GFP_ATOMIC
);
158 gigaset_free_channel(bcs
);
159 dev_err(cs
->dev
, "ISDN_CMD_DIAL: out of memory\n");
162 *sp
= cntrl
->parm
.setup
;
164 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_DIAL
, sp
,
165 bcs
->at_state
.seq_index
, NULL
)) {
166 //FIXME what should we do?
168 gigaset_free_channel(bcs
);
172 gig_dbg(DEBUG_CMD
, "scheduling DIAL");
173 gigaset_schedule_event(cs
);
175 case ISDN_CMD_ACCEPTD
: //FIXME
176 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ACCEPTD");
178 if (cntrl
->arg
>= cs
->channels
) {
180 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n",
185 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
].at_state
,
186 EV_ACCEPT
, NULL
, 0, NULL
)) {
187 //FIXME what should we do?
191 gig_dbg(DEBUG_CMD
, "scheduling ACCEPT");
192 gigaset_schedule_event(cs
);
195 case ISDN_CMD_ACCEPTB
:
196 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ACCEPTB");
198 case ISDN_CMD_HANGUP
:
199 gig_dbg(DEBUG_ANY
, "ISDN_CMD_HANGUP (ch: %d)",
202 if (cntrl
->arg
>= cs
->channels
) {
204 "ISDN_CMD_HANGUP: invalid channel (%d)\n",
209 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
].at_state
,
210 EV_HUP
, NULL
, 0, NULL
)) {
211 //FIXME what should we do?
215 gig_dbg(DEBUG_CMD
, "scheduling HUP");
216 gigaset_schedule_event(cs
);
219 case ISDN_CMD_CLREAZ
: /* Do not signal incoming signals */ //FIXME
220 gig_dbg(DEBUG_ANY
, "ISDN_CMD_CLREAZ");
222 case ISDN_CMD_SETEAZ
: /* Signal incoming calls for given MSN */ //FIXME
224 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)",
225 cntrl
->driver
, cntrl
->arg
, cntrl
->parm
.num
);
227 case ISDN_CMD_SETL2
: /* Set L2 to given protocol */
228 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)",
229 cntrl
->arg
& 0xff, (cntrl
->arg
>> 8));
231 if ((cntrl
->arg
& 0xff) >= cs
->channels
) {
233 "ISDN_CMD_SETL2: invalid channel (%d)\n",
234 (int) cntrl
->arg
& 0xff);
238 if (!gigaset_add_event(cs
, &cs
->bcs
[cntrl
->arg
& 0xff].at_state
,
239 EV_PROTO_L2
, NULL
, cntrl
->arg
>> 8,
241 //FIXME what should we do?
245 gig_dbg(DEBUG_CMD
, "scheduling PROTO_L2");
246 gigaset_schedule_event(cs
);
248 case ISDN_CMD_SETL3
: /* Set L3 to given protocol */
249 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)",
250 cntrl
->arg
& 0xff, (cntrl
->arg
>> 8));
252 if ((cntrl
->arg
& 0xff) >= cs
->channels
) {
254 "ISDN_CMD_SETL3: invalid channel (%d)\n",
255 (int) cntrl
->arg
& 0xff);
259 if (cntrl
->arg
>> 8 != ISDN_PROTO_L3_TRANS
) {
261 "ISDN_CMD_SETL3: invalid protocol %lu\n",
267 case ISDN_CMD_PROCEED
:
268 gig_dbg(DEBUG_ANY
, "ISDN_CMD_PROCEED"); //FIXME
271 gig_dbg(DEBUG_ANY
, "ISDN_CMD_ALERT"); //FIXME
272 if (cntrl
->arg
>= cs
->channels
) {
274 "ISDN_CMD_ALERT: invalid channel (%d)\n",
278 //bcs = cs->bcs + cntrl->arg;
283 gig_dbg(DEBUG_ANY
, "ISDN_CMD_REDIR"); //FIXME
285 case ISDN_CMD_PROT_IO
:
286 gig_dbg(DEBUG_ANY
, "ISDN_CMD_PROT_IO");
288 case ISDN_CMD_FAXCMD
:
289 gig_dbg(DEBUG_ANY
, "ISDN_CMD_FAXCMD");
292 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETL2");
295 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETL3");
297 case ISDN_CMD_GETEAZ
:
298 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETEAZ");
300 case ISDN_CMD_SETSIL
:
301 gig_dbg(DEBUG_ANY
, "ISDN_CMD_SETSIL");
303 case ISDN_CMD_GETSIL
:
304 gig_dbg(DEBUG_ANY
, "ISDN_CMD_GETSIL");
307 dev_err(cs
->dev
, "unknown command %d from LL\n",
315 void gigaset_i4l_cmd(struct cardstate
*cs
, int cmd
)
319 command
.driver
= cs
->myid
;
320 command
.command
= cmd
;
322 cs
->iif
.statcallb(&command
);
325 void gigaset_i4l_channel_cmd(struct bc_state
*bcs
, int cmd
)
329 command
.driver
= bcs
->cs
->myid
;
330 command
.command
= cmd
;
331 command
.arg
= bcs
->channel
;
332 bcs
->cs
->iif
.statcallb(&command
);
335 int gigaset_isdn_setup_dial(struct at_state_t
*at_state
, void *data
)
337 struct bc_state
*bcs
= at_state
->bcs
;
340 size_t length
[AT_NUM
];
343 struct setup_parm
*sp
= data
;
345 switch (bcs
->proto2
) {
346 case ISDN_PROTO_L2_HDLC
:
347 proto
= 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
349 case ISDN_PROTO_L2_TRANS
:
350 proto
= 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
353 dev_err(bcs
->cs
->dev
, "%s: invalid L2 protocol: %u\n",
354 __func__
, bcs
->proto2
);
360 bc
= "9090A3"; /* 3.1 kHz audio, A-law */
363 default: /* hope the app knows what it is doing */
364 bc
= "8890"; /* unrestricted digital information */
366 //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC
368 length
[AT_DIAL
] = 1 + strlen(sp
->phone
) + 1 + 1;
369 l
= strlen(sp
->eazmsn
);
370 length
[AT_MSN
] = l
? 6 + l
+ 1 + 1 : 0;
371 length
[AT_BC
] = 5 + strlen(bc
) + 1 + 1;
372 length
[AT_PROTO
] = 6 + 1 + 1 + 1; /* proto: 1 character */
373 length
[AT_ISO
] = 6 + 1 + 1 + 1; /* channel: 1 character */
374 length
[AT_TYPE
] = 6 + 1 + 1 + 1; /* call type: 1 character */
377 for (i
= 0; i
< AT_NUM
; ++i
) {
378 kfree(bcs
->commands
[i
]);
379 bcs
->commands
[i
] = NULL
;
381 !(bcs
->commands
[i
] = kmalloc(length
[i
], GFP_ATOMIC
))) {
382 dev_err(bcs
->cs
->dev
, "out of memory\n");
387 /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */
388 if (sp
->phone
[0] == '*' && sp
->phone
[1] == '*') {
389 /* internal call: translate ** prefix to CTP value */
390 snprintf(bcs
->commands
[AT_DIAL
], length
[AT_DIAL
],
391 "D%s\r", sp
->phone
+2);
392 strncpy(bcs
->commands
[AT_TYPE
], "^SCTP=0\r", length
[AT_TYPE
]);
394 snprintf(bcs
->commands
[AT_DIAL
], length
[AT_DIAL
],
396 strncpy(bcs
->commands
[AT_TYPE
], "^SCTP=1\r", length
[AT_TYPE
]);
399 if (bcs
->commands
[AT_MSN
])
400 snprintf(bcs
->commands
[AT_MSN
], length
[AT_MSN
],
401 "^SMSN=%s\r", sp
->eazmsn
);
402 snprintf(bcs
->commands
[AT_BC
], length
[AT_BC
],
404 snprintf(bcs
->commands
[AT_PROTO
], length
[AT_PROTO
],
405 "^SBPR=%u\r", proto
);
406 snprintf(bcs
->commands
[AT_ISO
], length
[AT_ISO
],
407 "^SISO=%u\r", (unsigned)bcs
->channel
+ 1);
412 int gigaset_isdn_setup_accept(struct at_state_t
*at_state
)
415 size_t length
[AT_NUM
];
417 struct bc_state
*bcs
= at_state
->bcs
;
419 switch (bcs
->proto2
) {
420 case ISDN_PROTO_L2_HDLC
:
421 proto
= 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */
423 case ISDN_PROTO_L2_TRANS
:
424 proto
= 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
427 dev_err(at_state
->cs
->dev
, "%s: invalid protocol: %u\n",
428 __func__
, bcs
->proto2
);
432 length
[AT_DIAL
] = 0;
435 length
[AT_PROTO
] = 6 + 1 + 1 + 1; /* proto: 1 character */
436 length
[AT_ISO
] = 6 + 1 + 1 + 1; /* channel: 1 character */
437 length
[AT_TYPE
] = 0;
440 for (i
= 0; i
< AT_NUM
; ++i
) {
441 kfree(bcs
->commands
[i
]);
442 bcs
->commands
[i
] = NULL
;
444 !(bcs
->commands
[i
] = kmalloc(length
[i
], GFP_ATOMIC
))) {
445 dev_err(at_state
->cs
->dev
, "out of memory\n");
450 snprintf(bcs
->commands
[AT_PROTO
], length
[AT_PROTO
],
451 "^SBPR=%u\r", proto
);
452 snprintf(bcs
->commands
[AT_ISO
], length
[AT_ISO
],
453 "^SISO=%u\r", (unsigned) bcs
->channel
+ 1);
458 int gigaset_isdn_icall(struct at_state_t
*at_state
)
460 struct cardstate
*cs
= at_state
->cs
;
461 struct bc_state
*bcs
= at_state
->bcs
;
465 /* fill ICALL structure */
466 response
.parm
.setup
.si1
= 0; /* default: unknown */
467 response
.parm
.setup
.si2
= 0;
468 response
.parm
.setup
.screen
= 0; //FIXME how to set these?
469 response
.parm
.setup
.plan
= 0;
470 if (!at_state
->str_var
[STR_ZBC
]) {
471 /* no BC (internal call): assume speech, A-law */
472 response
.parm
.setup
.si1
= 1;
473 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "8890")) {
474 /* unrestricted digital information */
475 response
.parm
.setup
.si1
= 7;
476 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "8090A3")) {
478 response
.parm
.setup
.si1
= 1;
479 } else if (!strcmp(at_state
->str_var
[STR_ZBC
], "9090A3")) {
480 /* 3,1 kHz audio, A-law */
481 response
.parm
.setup
.si1
= 1;
482 response
.parm
.setup
.si2
= 2;
484 dev_warn(cs
->dev
, "RING ignored - unsupported BC %s\n",
485 at_state
->str_var
[STR_ZBC
]);
488 if (at_state
->str_var
[STR_NMBR
]) {
489 strncpy(response
.parm
.setup
.phone
, at_state
->str_var
[STR_NMBR
],
490 sizeof response
.parm
.setup
.phone
- 1);
491 response
.parm
.setup
.phone
[sizeof response
.parm
.setup
.phone
- 1] = 0;
493 response
.parm
.setup
.phone
[0] = 0;
494 if (at_state
->str_var
[STR_ZCPN
]) {
495 strncpy(response
.parm
.setup
.eazmsn
, at_state
->str_var
[STR_ZCPN
],
496 sizeof response
.parm
.setup
.eazmsn
- 1);
497 response
.parm
.setup
.eazmsn
[sizeof response
.parm
.setup
.eazmsn
- 1] = 0;
499 response
.parm
.setup
.eazmsn
[0] = 0;
502 dev_notice(cs
->dev
, "no channel for incoming call\n");
503 response
.command
= ISDN_STAT_ICALLW
;
504 response
.arg
= 0; //FIXME
506 gig_dbg(DEBUG_CMD
, "Sending ICALL");
507 response
.command
= ISDN_STAT_ICALL
;
508 response
.arg
= bcs
->channel
; //FIXME
510 response
.driver
= cs
->myid
;
511 retval
= cs
->iif
.statcallb(&response
);
512 gig_dbg(DEBUG_CMD
, "Response: %d", retval
);
514 case 0: /* no takers */
516 case 1: /* alerting */
517 bcs
->chstate
|= CHS_NOTIFY_LL
;
521 case 3: /* incomplete */
523 "LL requested unsupported feature: Incomplete Number\n");
525 case 4: /* proceeding */
526 /* Gigaset will send ALERTING anyway.
527 * There doesn't seem to be a way to avoid this.
530 case 5: /* deflect */
532 "LL requested unsupported feature: Call Deflection\n");
535 dev_err(cs
->dev
, "LL error %d on ICALL\n", retval
);
540 /* Set Callback function pointer */
541 int gigaset_register_to_LL(struct cardstate
*cs
, const char *isdnid
)
543 isdn_if
*iif
= &cs
->iif
;
545 gig_dbg(DEBUG_ANY
, "Register driver capabilities to LL");
547 if (snprintf(iif
->id
, sizeof iif
->id
, "%s_%u", isdnid
, cs
->minor_index
)
549 pr_err("ID too long: %s\n", isdnid
);
553 iif
->owner
= THIS_MODULE
;
554 iif
->channels
= cs
->channels
;
555 iif
->maxbufsize
= MAX_BUF_SIZE
;
556 iif
->features
= ISDN_FEATURE_L2_TRANS
|
557 ISDN_FEATURE_L2_HDLC
|
559 ISDN_FEATURE_L2_X75I
|
561 ISDN_FEATURE_L3_TRANS
|
563 iif
->hl_hdrlen
= HW_HDR_LEN
; /* Area for storing ack */
564 iif
->command
= command_from_LL
;
565 iif
->writebuf_skb
= writebuf_from_LL
;
566 iif
->writecmd
= NULL
; /* Don't support isdnctrl */
567 iif
->readstat
= NULL
; /* Don't support isdnctrl */
568 iif
->rcvcallb_skb
= NULL
; /* Will be set by LL */
569 iif
->statcallb
= NULL
; /* Will be set by LL */
571 if (!register_isdn(iif
)) {
572 pr_err("register_isdn failed\n");
576 cs
->myid
= iif
->channels
; /* Set my device id */