gigaset: prepare for CAPI implementation
[safe/jmp/linux-2.6] / drivers / isdn / gigaset / i4l.c
1 /*
2  * Stuff used by all variants of the driver
3  *
4  * Copyright (c) 2001 by Stefan Eilers,
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  * =====================================================================
14  */
15
16 #include "gigaset.h"
17 #include <linux/isdnif.h>
18
19 #define HW_HDR_LEN      2       /* Header size used to store ack info */
20
21 /* == Handling of I4L IO =====================================================*/
22
23 /* writebuf_from_LL
24  * called by LL to transmit data on an open channel
25  * inserts the buffer data into the send queue and starts the transmission
26  * Note that this operation must not sleep!
27  * When the buffer is processed completely, gigaset_skb_sent() should be called.
28  * parameters:
29  *      driverID        driver ID as assigned by LL
30  *      channel         channel number
31  *      ack             if != 0 LL wants to be notified on completion via
32  *                      statcallb(ISDN_STAT_BSENT)
33  *      skb             skb containing data to send
34  * return value:
35  *      number of accepted bytes
36  *      0 if temporarily unable to accept data (out of buffer space)
37  *      <0 on error (eg. -EINVAL)
38  */
39 static int writebuf_from_LL(int driverID, int channel, int ack,
40                             struct sk_buff *skb)
41 {
42         struct cardstate *cs;
43         struct bc_state *bcs;
44         unsigned len;
45         unsigned skblen;
46
47         if (!(cs = gigaset_get_cs_by_id(driverID))) {
48                 pr_err("%s: invalid driver ID (%d)\n", __func__, driverID);
49                 return -ENODEV;
50         }
51         if (channel < 0 || channel >= cs->channels) {
52                 dev_err(cs->dev, "%s: invalid channel ID (%d)\n",
53                         __func__, channel);
54                 return -ENODEV;
55         }
56         bcs = &cs->bcs[channel];
57
58         /* can only handle linear sk_buffs */
59         if (skb_linearize(skb) < 0) {
60                 dev_err(cs->dev, "%s: skb_linearize failed\n", __func__);
61                 return -ENOMEM;
62         }
63         len = skb->len;
64
65         gig_dbg(DEBUG_LLDATA,
66                 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
67                 driverID, channel, ack, len);
68
69         if (!len) {
70                 if (ack)
71                         dev_notice(cs->dev, "%s: not ACKing empty packet\n",
72                                    __func__);
73                 return 0;
74         }
75         if (len > MAX_BUF_SIZE) {
76                 dev_err(cs->dev, "%s: packet too large (%d bytes)\n",
77                         __func__, len);
78                 return -EINVAL;
79         }
80
81         skblen = ack ? len : 0;
82         skb->head[0] = skblen & 0xff;
83         skb->head[1] = skblen >> 8;
84         gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x",
85                 len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]);
86
87         /* pass to device-specific module */
88         return cs->ops->send_skb(bcs, skb);
89 }
90
91 /**
92  * gigaset_skb_sent() - acknowledge sending an skb
93  * @bcs:        B channel descriptor structure.
94  * @skb:        sent data.
95  *
96  * Called by hardware module {bas,ser,usb}_gigaset when the data in a
97  * skb has been successfully sent, for signalling completion to the LL.
98  */
99 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
100 {
101         isdn_if *iif = bcs->cs->iif;
102         unsigned len;
103         isdn_ctrl response;
104
105         ++bcs->trans_up;
106
107         if (skb->len)
108                 dev_warn(bcs->cs->dev, "%s: skb->len==%d\n",
109                          __func__, skb->len);
110
111         len = (unsigned char) skb->head[0] |
112               (unsigned) (unsigned char) skb->head[1] << 8;
113         if (len) {
114                 gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
115                         bcs->cs->myid, bcs->channel, len);
116
117                 response.driver = bcs->cs->myid;
118                 response.command = ISDN_STAT_BSENT;
119                 response.arg = bcs->channel;
120                 response.parm.length = len;
121                 iif->statcallb(&response);
122         }
123 }
124 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
125
126 /**
127  * gigaset_skb_rcvd() - pass received skb to LL
128  * @bcs:        B channel descriptor structure.
129  * @skb:        received data.
130  *
131  * Called by hardware module {bas,ser,usb}_gigaset when user data has
132  * been successfully received, for passing to the LL.
133  * Warning: skb must not be accessed anymore!
134  */
135 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
136 {
137         isdn_if *iif = bcs->cs->iif;
138
139         iif->rcvcallb_skb(bcs->cs->myid, bcs->channel, skb);
140         bcs->trans_down++;
141 }
142 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
143
144 /**
145  * gigaset_isdn_rcv_err() - signal receive error
146  * @bcs:        B channel descriptor structure.
147  *
148  * Called by hardware module {bas,ser,usb}_gigaset when a receive error
149  * has occurred, for signalling to the LL.
150  */
151 void gigaset_isdn_rcv_err(struct bc_state *bcs)
152 {
153         isdn_if *iif = bcs->cs->iif;
154         isdn_ctrl response;
155
156         /* if currently ignoring packets, just count down */
157         if (bcs->ignore) {
158                 bcs->ignore--;
159                 return;
160         }
161
162         /* update statistics */
163         bcs->corrupted++;
164
165         /* error -> LL */
166         gig_dbg(DEBUG_CMD, "sending L1ERR");
167         response.driver = bcs->cs->myid;
168         response.command = ISDN_STAT_L1ERR;
169         response.arg = bcs->channel;
170         response.parm.errcode = ISDN_STAT_L1ERR_RECV;
171         iif->statcallb(&response);
172 }
173 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
174
175 /* This function will be called by LL to send commands
176  * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
177  * so don't put too much effort into it.
178  */
179 static int command_from_LL(isdn_ctrl *cntrl)
180 {
181         struct cardstate *cs;
182         struct bc_state *bcs;
183         int retval = 0;
184         char **commands;
185         int ch;
186         int i;
187         size_t l;
188
189         gigaset_debugdrivers();
190
191         gig_dbg(DEBUG_CMD, "driver: %d, command: %d, arg: 0x%lx",
192                 cntrl->driver, cntrl->command, cntrl->arg);
193
194         cs = gigaset_get_cs_by_id(cntrl->driver);
195         if (cs == NULL) {
196                 pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver);
197                 return -ENODEV;
198         }
199         ch = cntrl->arg & 0xff;
200
201         switch (cntrl->command) {
202         case ISDN_CMD_IOCTL:
203                 dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n");
204                 return -EINVAL;
205
206         case ISDN_CMD_DIAL:
207                 gig_dbg(DEBUG_ANY,
208                         "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)",
209                         cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
210                         cntrl->parm.setup.si1, cntrl->parm.setup.si2);
211
212                 if (ch >= cs->channels) {
213                         dev_err(cs->dev,
214                                 "ISDN_CMD_DIAL: invalid channel (%d)\n", ch);
215                         return -EINVAL;
216                 }
217                 bcs = cs->bcs + ch;
218                 if (!gigaset_get_channel(bcs)) {
219                         dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n");
220                         return -EBUSY;
221                 }
222
223                 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_ATOMIC);
224                 if (!commands) {
225                         gigaset_free_channel(bcs);
226                         dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n");
227                         return -ENOMEM;
228                 }
229
230                 l = 3 + strlen(cntrl->parm.setup.phone);
231                 commands[AT_DIAL] = kmalloc(l, GFP_ATOMIC);
232                 if (!commands[AT_DIAL])
233                         goto oom;
234                 if (cntrl->parm.setup.phone[0] == '*' &&
235                     cntrl->parm.setup.phone[1] == '*') {
236                         /* internal call: translate ** prefix to CTP value */
237                         commands[AT_TYPE] = kstrdup("^SCTP=0\r", GFP_ATOMIC);
238                         if (!commands[AT_TYPE])
239                                 goto oom;
240                         snprintf(commands[AT_DIAL], l,
241                                  "D%s\r", cntrl->parm.setup.phone+2);
242                 } else {
243                         commands[AT_TYPE] = kstrdup("^SCTP=1\r", GFP_ATOMIC);
244                         if (!commands[AT_TYPE])
245                                 goto oom;
246                         snprintf(commands[AT_DIAL], l,
247                                  "D%s\r", cntrl->parm.setup.phone);
248                 }
249
250                 l = strlen(cntrl->parm.setup.eazmsn);
251                 if (l) {
252                         l += 8;
253                         commands[AT_MSN] = kmalloc(l, GFP_ATOMIC);
254                         if (!commands[AT_MSN])
255                                 goto oom;
256                         snprintf(commands[AT_MSN], l, "^SMSN=%s\r",
257                                  cntrl->parm.setup.eazmsn);
258                 }
259
260                 switch (cntrl->parm.setup.si1) {
261                 case 1:         /* audio */
262                         /* BC = 9090A3: 3.1 kHz audio, A-law */
263                         commands[AT_BC] = kstrdup("^SBC=9090A3\r", GFP_ATOMIC);
264                         if (!commands[AT_BC])
265                                 goto oom;
266                         break;
267                 case 7:         /* data */
268                 default:        /* hope the app knows what it is doing */
269                         /* BC = 8890: unrestricted digital information */
270                         commands[AT_BC] = kstrdup("^SBC=8890\r", GFP_ATOMIC);
271                         if (!commands[AT_BC])
272                                 goto oom;
273                 }
274                 /* ToDo: other si1 values, inspect si2, set HLC/LLC */
275
276                 commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC);
277                 if (!commands[AT_PROTO])
278                         goto oom;
279                 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
280
281                 commands[AT_ISO] = kmalloc(9, GFP_ATOMIC);
282                 if (!commands[AT_ISO])
283                         goto oom;
284                 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
285                          (unsigned) bcs->channel + 1);
286
287                 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
288                                        bcs->at_state.seq_index, NULL)) {
289                         for (i = 0; i < AT_NUM; ++i)
290                                 kfree(commands[i]);
291                         kfree(commands);
292                         gigaset_free_channel(bcs);
293                         return -ENOMEM;
294                 }
295
296                 gig_dbg(DEBUG_CMD, "scheduling DIAL");
297                 gigaset_schedule_event(cs);
298                 break;
299         case ISDN_CMD_ACCEPTD:
300                 if (ch >= cs->channels) {
301                         dev_err(cs->dev,
302                                 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch);
303                         return -EINVAL;
304                 }
305                 bcs = cs->bcs + ch;
306                 if (!gigaset_add_event(cs, &bcs->at_state,
307                                        EV_ACCEPT, NULL, 0, NULL))
308                         return -ENOMEM;
309
310                 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
311                 gigaset_schedule_event(cs);
312
313                 break;
314         case ISDN_CMD_ACCEPTB:
315                 break;
316         case ISDN_CMD_HANGUP:
317                 if (ch >= cs->channels) {
318                         dev_err(cs->dev,
319                                 "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch);
320                         return -EINVAL;
321                 }
322                 bcs = cs->bcs + ch;
323                 if (!gigaset_add_event(cs, &bcs->at_state,
324                                        EV_HUP, NULL, 0, NULL))
325                         return -ENOMEM;
326
327                 gig_dbg(DEBUG_CMD, "scheduling HUP");
328                 gigaset_schedule_event(cs);
329
330                 break;
331         case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */
332                 dev_info(cs->dev, "ignoring ISDN_CMD_CLREAZ\n");
333                 break;
334         case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */
335                 dev_info(cs->dev, "ignoring ISDN_CMD_SETEAZ (%s)\n",
336                          cntrl->parm.num);
337                 break;
338         case ISDN_CMD_SETL2: /* Set L2 to given protocol */
339                 if (ch >= cs->channels) {
340                         dev_err(cs->dev,
341                                 "ISDN_CMD_SETL2: invalid channel (%d)\n", ch);
342                         return -EINVAL;
343                 }
344                 bcs = cs->bcs + ch;
345                 if (bcs->chstate & CHS_D_UP) {
346                         dev_err(cs->dev,
347                                 "ISDN_CMD_SETL2: channel active (%d)\n", ch);
348                         return -EINVAL;
349                 }
350                 switch (cntrl->arg >> 8) {
351                 case ISDN_PROTO_L2_HDLC:
352                         gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_HDLC");
353                         bcs->proto2 = L2_HDLC;
354                         break;
355                 case ISDN_PROTO_L2_TRANS:
356                         gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_VOICE");
357                         bcs->proto2 = L2_VOICE;
358                         break;
359                 default:
360                         dev_err(cs->dev,
361                                 "ISDN_CMD_SETL2: unsupported protocol (%lu)\n",
362                                 cntrl->arg >> 8);
363                         return -EINVAL;
364                 }
365                 break;
366         case ISDN_CMD_SETL3: /* Set L3 to given protocol */
367                 if (ch >= cs->channels) {
368                         dev_err(cs->dev,
369                                 "ISDN_CMD_SETL3: invalid channel (%d)\n", ch);
370                         return -EINVAL;
371                 }
372
373                 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
374                         dev_err(cs->dev,
375                                 "ISDN_CMD_SETL3: unsupported protocol (%lu)\n",
376                                 cntrl->arg >> 8);
377                         return -EINVAL;
378                 }
379
380                 break;
381         case ISDN_CMD_PROCEED:
382                 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME
383                 break;
384         case ISDN_CMD_ALERT:
385                 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
386                 if (cntrl->arg >= cs->channels) {
387                         dev_err(cs->dev,
388                                 "ISDN_CMD_ALERT: invalid channel (%d)\n",
389                                 (int) cntrl->arg);
390                         return -EINVAL;
391                 }
392                 //bcs = cs->bcs + cntrl->arg;
393                 //bcs->proto2 = -1;
394                 // FIXME
395                 break;
396         case ISDN_CMD_REDIR:
397                 gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
398                 break;
399         case ISDN_CMD_PROT_IO:
400                 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
401                 break;
402         case ISDN_CMD_FAXCMD:
403                 gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
404                 break;
405         case ISDN_CMD_GETL2:
406                 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
407                 break;
408         case ISDN_CMD_GETL3:
409                 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
410                 break;
411         case ISDN_CMD_GETEAZ:
412                 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
413                 break;
414         case ISDN_CMD_SETSIL:
415                 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
416                 break;
417         case ISDN_CMD_GETSIL:
418                 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
419                 break;
420         default:
421                 dev_err(cs->dev, "unknown command %d from LL\n",
422                         cntrl->command);
423                 return -EINVAL;
424         }
425
426         return retval;
427
428 oom:
429         dev_err(bcs->cs->dev, "out of memory\n");
430         for (i = 0; i < AT_NUM; ++i)
431                 kfree(commands[i]);
432         return -ENOMEM;
433 }
434
435 static void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
436 {
437         isdn_if *iif = cs->iif;
438         isdn_ctrl command;
439
440         command.driver = cs->myid;
441         command.command = cmd;
442         command.arg = 0;
443         iif->statcallb(&command);
444 }
445
446 static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
447 {
448         isdn_if *iif = bcs->cs->iif;
449         isdn_ctrl command;
450
451         command.driver = bcs->cs->myid;
452         command.command = cmd;
453         command.arg = bcs->channel;
454         iif->statcallb(&command);
455 }
456
457 /**
458  * gigaset_isdn_icall() - signal incoming call
459  * @at_state:   connection state structure.
460  *
461  * Called by main module to notify the LL that an incoming call has been
462  * received. @at_state contains the parameters of the call.
463  *
464  * Return value: call disposition (ICALL_*)
465  */
466 int gigaset_isdn_icall(struct at_state_t *at_state)
467 {
468         struct cardstate *cs = at_state->cs;
469         struct bc_state *bcs = at_state->bcs;
470         isdn_if *iif = cs->iif;
471         isdn_ctrl response;
472         int retval;
473
474         /* fill ICALL structure */
475         response.parm.setup.si1 = 0;    /* default: unknown */
476         response.parm.setup.si2 = 0;
477         response.parm.setup.screen = 0; //FIXME how to set these?
478         response.parm.setup.plan = 0;
479         if (!at_state->str_var[STR_ZBC]) {
480                 /* no BC (internal call): assume speech, A-law */
481                 response.parm.setup.si1 = 1;
482         } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) {
483                 /* unrestricted digital information */
484                 response.parm.setup.si1 = 7;
485         } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) {
486                 /* speech, A-law */
487                 response.parm.setup.si1 = 1;
488         } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) {
489                 /* 3,1 kHz audio, A-law */
490                 response.parm.setup.si1 = 1;
491                 response.parm.setup.si2 = 2;
492         } else {
493                 dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
494                      at_state->str_var[STR_ZBC]);
495                 return ICALL_IGNORE;
496         }
497         if (at_state->str_var[STR_NMBR]) {
498                 strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
499                         sizeof response.parm.setup.phone - 1);
500                 response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0;
501         } else
502                 response.parm.setup.phone[0] = 0;
503         if (at_state->str_var[STR_ZCPN]) {
504                 strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
505                         sizeof response.parm.setup.eazmsn - 1);
506                 response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0;
507         } else
508                 response.parm.setup.eazmsn[0] = 0;
509
510         if (!bcs) {
511                 dev_notice(cs->dev, "no channel for incoming call\n");
512                 response.command = ISDN_STAT_ICALLW;
513                 response.arg = 0; //FIXME
514         } else {
515                 gig_dbg(DEBUG_CMD, "Sending ICALL");
516                 response.command = ISDN_STAT_ICALL;
517                 response.arg = bcs->channel; //FIXME
518         }
519         response.driver = cs->myid;
520         retval = iif->statcallb(&response);
521         gig_dbg(DEBUG_CMD, "Response: %d", retval);
522         switch (retval) {
523         case 0: /* no takers */
524                 return ICALL_IGNORE;
525         case 1: /* alerting */
526                 bcs->chstate |= CHS_NOTIFY_LL;
527                 return ICALL_ACCEPT;
528         case 2: /* reject */
529                 return ICALL_REJECT;
530         case 3: /* incomplete */
531                 dev_warn(cs->dev,
532                        "LL requested unsupported feature: Incomplete Number\n");
533                 return ICALL_IGNORE;
534         case 4: /* proceeding */
535                 /* Gigaset will send ALERTING anyway.
536                  * There doesn't seem to be a way to avoid this.
537                  */
538                 return ICALL_ACCEPT;
539         case 5: /* deflect */
540                 dev_warn(cs->dev,
541                          "LL requested unsupported feature: Call Deflection\n");
542                 return ICALL_IGNORE;
543         default:
544                 dev_err(cs->dev, "LL error %d on ICALL\n", retval);
545                 return ICALL_IGNORE;
546         }
547 }
548
549 /**
550  * gigaset_isdn_connD() - signal D channel connect
551  * @bcs:        B channel descriptor structure.
552  *
553  * Called by main module to notify the LL that the D channel connection has
554  * been established.
555  */
556 void gigaset_isdn_connD(struct bc_state *bcs)
557 {
558         gig_dbg(DEBUG_CMD, "sending DCONN");
559         gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
560 }
561
562 /**
563  * gigaset_isdn_hupD() - signal D channel hangup
564  * @bcs:        B channel descriptor structure.
565  *
566  * Called by main module to notify the LL that the D channel connection has
567  * been shut down.
568  */
569 void gigaset_isdn_hupD(struct bc_state *bcs)
570 {
571         gig_dbg(DEBUG_CMD, "sending DHUP");
572         gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP);
573 }
574
575 /**
576  * gigaset_isdn_connB() - signal B channel connect
577  * @bcs:        B channel descriptor structure.
578  *
579  * Called by main module to notify the LL that the B channel connection has
580  * been established.
581  */
582 void gigaset_isdn_connB(struct bc_state *bcs)
583 {
584         gig_dbg(DEBUG_CMD, "sending BCONN");
585         gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
586 }
587
588 /**
589  * gigaset_isdn_hupB() - signal B channel hangup
590  * @bcs:        B channel descriptor structure.
591  *
592  * Called by main module to notify the LL that the B channel connection has
593  * been shut down.
594  */
595 void gigaset_isdn_hupB(struct bc_state *bcs)
596 {
597         gig_dbg(DEBUG_CMD, "sending BHUP");
598         gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
599 }
600
601 /**
602  * gigaset_isdn_start() - signal device availability
603  * @cs:         device descriptor structure.
604  *
605  * Called by main module to notify the LL that the device is available for
606  * use.
607  */
608 void gigaset_isdn_start(struct cardstate *cs)
609 {
610         gig_dbg(DEBUG_CMD, "sending RUN");
611         gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
612 }
613
614 /**
615  * gigaset_isdn_stop() - signal device unavailability
616  * @cs:         device descriptor structure.
617  *
618  * Called by main module to notify the LL that the device is no longer
619  * available for use.
620  */
621 void gigaset_isdn_stop(struct cardstate *cs)
622 {
623         gig_dbg(DEBUG_CMD, "sending STOP");
624         gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
625 }
626
627 /**
628  * gigaset_isdn_register() - register to LL
629  * @cs:         device descriptor structure.
630  * @isdnid:     device name.
631  *
632  * Called by main module to register the device with the LL.
633  *
634  * Return value: 1 for success, 0 for failure
635  */
636 int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
637 {
638         isdn_if *iif;
639
640         pr_info("ISDN4Linux interface\n");
641
642         iif = kmalloc(sizeof *iif, GFP_KERNEL);
643         if (!iif) {
644                 pr_err("out of memory\n");
645                 return 0;
646         }
647
648         if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
649             >= sizeof iif->id) {
650                 pr_err("ID too long: %s\n", isdnid);
651                 kfree(iif);
652                 return 0;
653         }
654
655         iif->owner = THIS_MODULE;
656         iif->channels = cs->channels;
657         iif->maxbufsize = MAX_BUF_SIZE;
658         iif->features = ISDN_FEATURE_L2_TRANS |
659                 ISDN_FEATURE_L2_HDLC |
660 #ifdef GIG_X75
661                 ISDN_FEATURE_L2_X75I |
662 #endif
663                 ISDN_FEATURE_L3_TRANS |
664                 ISDN_FEATURE_P_EURO;
665         iif->hl_hdrlen = HW_HDR_LEN;            /* Area for storing ack */
666         iif->command = command_from_LL;
667         iif->writebuf_skb = writebuf_from_LL;
668         iif->writecmd = NULL;                   /* Don't support isdnctrl */
669         iif->readstat = NULL;                   /* Don't support isdnctrl */
670         iif->rcvcallb_skb = NULL;               /* Will be set by LL */
671         iif->statcallb = NULL;                  /* Will be set by LL */
672
673         if (!register_isdn(iif)) {
674                 pr_err("register_isdn failed\n");
675                 kfree(iif);
676                 return 0;
677         }
678
679         cs->iif = iif;
680         cs->myid = iif->channels;               /* Set my device id */
681         cs->hw_hdr_len = HW_HDR_LEN;
682         return 1;
683 }
684
685 /**
686  * gigaset_isdn_unregister() - unregister from LL
687  * @cs:         device descriptor structure.
688  *
689  * Called by main module to unregister the device from the LL.
690  */
691 void gigaset_isdn_unregister(struct cardstate *cs)
692 {
693         gig_dbg(DEBUG_CMD, "sending UNLOAD");
694         gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
695         kfree(cs->iif);
696         cs->iif = NULL;
697 }