2 * Kernel CAPI interface for the Gigaset driver
4 * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
15 #include <linux/ctype.h>
16 #include <linux/isdn/capilli.h>
17 #include <linux/isdn/capicmd.h>
18 #include <linux/isdn/capiutil.h>
20 /* missing from kernelcapi.h */
21 #define CapiNcpiNotSupportedByProtocol 0x0001
22 #define CapiFlagsNotSupportedByProtocol 0x0002
23 #define CapiAlertAlreadySent 0x0003
24 #define CapiFacilitySpecificFunctionNotSupported 0x3011
26 /* missing from capicmd.h */
27 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
28 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
29 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
30 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
31 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
32 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
33 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
34 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
35 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
36 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
37 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
39 #define CAPI_FACILITY_HANDSET 0x0000
40 #define CAPI_FACILITY_DTMF 0x0001
41 #define CAPI_FACILITY_V42BIS 0x0002
42 #define CAPI_FACILITY_SUPPSVC 0x0003
43 #define CAPI_FACILITY_WAKEUP 0x0004
44 #define CAPI_FACILITY_LI 0x0005
46 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
48 /* missing from capiutil.h */
49 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
50 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
51 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
52 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
53 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
54 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
55 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
56 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
58 /* parameters with differing location in DATA_B3_CONF/_RESP: */
59 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
60 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
62 /* Flags (DATA_B3_REQ/_IND) */
63 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
64 #define CAPI_FLAGS_RESERVED (~0x1f)
67 #define MAX_BC_OCTETS 11
68 #define MAX_HLC_OCTETS 3
69 #define MAX_NUMBER_DIGITS 20
70 #define MAX_FMT_IE_LEN 20
72 /* values for gigaset_capi_appl.connected */
73 #define APCONN_NONE 0 /* inactive/listening */
74 #define APCONN_SETUP 1 /* connecting */
75 #define APCONN_ACTIVE 2 /* B channel up */
77 /* registered application data structure */
78 struct gigaset_capi_appl {
79 struct list_head ctrlist;
80 struct gigaset_capi_appl *bcnext;
82 u16 nextMessageNumber;
88 /* CAPI specific controller data structure */
89 struct gigaset_capi_ctr {
91 struct list_head appls;
92 struct sk_buff_head sendqueue;
94 /* two _cmsg structures possibly used concurrently: */
95 _cmsg hcmsg; /* for message composition triggered from hardware */
96 _cmsg acmsg; /* for dissection of messages sent from application */
97 u8 bc_buf[MAX_BC_OCTETS+1];
98 u8 hlc_buf[MAX_HLC_OCTETS+1];
99 u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
100 u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
103 /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
108 [1] = { "8090A3", NULL },
110 [2] = { "8890", NULL },
111 /* Unrestricted digital information */
112 [3] = { "8990", NULL },
113 /* Restricted digital information */
114 [4] = { "9090A3", NULL },
115 /* 3,1 kHz audio (A-law) */
116 [5] = { "9190", NULL },
118 [6] = { "9890", NULL },
120 [7] = { "88C0C6E6", NULL },
122 [8] = { "8890218F", NULL },
123 /* 56 kbit/s rate adaptation */
124 [9] = { "9190A5", NULL },
125 /* Unrestricted digital information with tones/announcements */
126 [16] = { "8090A3", "9181" },
128 [17] = { "9090A3", "9184" },
129 /* Group 2/3 facsimile */
130 [18] = { "8890", "91A1" },
131 /* Group 4 facsimile Class 1 */
132 [19] = { "8890", "91A4" },
133 /* Teletex service basic and mixed mode
134 and Group 4 facsimile service Classes II and III */
135 [20] = { "8890", "91A8" },
136 /* Teletex service basic and processable mode */
137 [21] = { "8890", "91B1" },
138 /* Teletex service basic mode */
139 [22] = { "8890", "91B2" },
140 /* International interworking for Videotex */
141 [23] = { "8890", "91B5" },
143 [24] = { "8890", "91B8" },
144 /* Message Handling Systems in accordance with X.400 */
145 [25] = { "8890", "91C1" },
146 /* OSI application in accordance with X.200 */
147 [26] = { "9190A5", "9181" },
148 /* 7 kHz telephony */
149 [27] = { "9190A5", "916001" },
150 /* Video telephony, first connection */
151 [28] = { "8890", "916002" },
152 /* Video telephony, second connection */
161 * emit unsupported parameter warning
163 static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
164 char *msgname, char *paramname)
167 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
171 static inline void ignore_cmstruct_param(struct cardstate *cs, _cmstruct param,
172 char *msgname, char *paramname)
174 if (param != CAPI_DEFAULT)
175 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
180 * check for legal hex digit
182 static inline int ishexdigit(char c)
184 if (c >= '0' && c <= '9')
186 if (c >= 'A' && c <= 'F')
188 if (c >= 'a' && c <= 'f')
194 * convert hex to binary
196 static inline u8 hex2bin(char c)
198 int result = c & 0x0f;
205 * convert an IE from Gigaset hex string to ETSI binary representation
206 * including length byte
207 * return value: result length, -1 on error
209 static int encode_ie(char *in, u8 *out, int maxlen)
213 if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
215 out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
223 * convert an IE from ETSI binary representation including length byte
224 * to Gigaset hex string
226 static void decode_ie(u8 *in, char *out)
230 /* ToDo: conversion to upper case necessary? */
231 *out++ = toupper(hex_asc_hi(*++in));
232 *out++ = toupper(hex_asc_lo(*in));
237 * retrieve application data structure for an application ID
239 static inline struct gigaset_capi_appl *
240 get_appl(struct gigaset_capi_ctr *iif, u16 appl)
242 struct gigaset_capi_appl *ap;
244 list_for_each_entry(ap, &iif->appls, ctrlist)
251 * dump CAPI message to kernel messages for debugging
253 static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
255 #ifdef CONFIG_GIGASET_DEBUG
258 if (!(gigaset_debuglevel & level))
261 cdb = capi_cmsg2str(p);
263 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
266 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
267 capi_cmd2str(p->Command, p->Subcommand));
272 static inline void dump_rawmsg(enum debuglevel level, const char *tag,
275 #ifdef CONFIG_GIGASET_DEBUG
279 if (!(gigaset_debuglevel & level))
282 l = CAPIMSG_LEN(data);
284 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
287 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
288 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
289 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
290 CAPIMSG_CONTROL(data));
292 dbgline = kmalloc(3*l, GFP_ATOMIC);
295 for (i = 0; i < l; i++) {
296 dbgline[3*i] = hex_asc_hi(data[12+i]);
297 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
298 dbgline[3*i+2] = ' ';
300 dbgline[3*l-1] = '\0';
301 gig_dbg(level, " %s", dbgline);
303 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
304 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
305 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
306 CAPIMSG_DATALEN(data) > 0) {
307 l = CAPIMSG_DATALEN(data);
308 dbgline = kmalloc(3*l, GFP_ATOMIC);
311 data += CAPIMSG_LEN(data);
312 for (i = 0; i < l; i++) {
313 dbgline[3*i] = hex_asc_hi(data[i]);
314 dbgline[3*i+1] = hex_asc_lo(data[i]);
315 dbgline[3*i+2] = ' ';
317 dbgline[3*l-1] = '\0';
318 gig_dbg(level, " %s", dbgline);
325 * format CAPI IE as string
328 static const char *format_ie(const char *ie)
330 static char result[3*MAX_FMT_IE_LEN];
338 if (count > MAX_FMT_IE_LEN)
339 count = MAX_FMT_IE_LEN-1;
341 *pout++ = hex_asc_hi(*++ie);
342 *pout++ = hex_asc_lo(*ie);
345 if (len > MAX_FMT_IE_LEN) {
356 * driver interface functions
357 * ==========================
361 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
362 * @bcs: B channel descriptor structure.
365 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
366 * skb has been successfully sent, for signalling completion to the LL.
368 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
370 struct cardstate *cs = bcs->cs;
371 struct gigaset_capi_ctr *iif = cs->iif;
372 struct gigaset_capi_appl *ap = bcs->ap;
373 struct sk_buff *cskb;
376 /* update statistics */
380 dev_err(cs->dev, "%s: no application\n", __func__);
384 /* don't send further B3 messages if disconnected */
385 if (ap->connected < APCONN_ACTIVE) {
386 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
390 /* ToDo: honor unset "delivery confirmation" bit */
391 flags = CAPIMSG_FLAGS(dskb->head);
393 /* build DATA_B3_CONF message */
394 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
396 dev_err(cs->dev, "%s: out of memory\n", __func__);
399 /* frequent message, avoid _cmsg overhead */
400 CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
401 CAPIMSG_SETAPPID(cskb->data, ap->id);
402 CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
403 CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
404 CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(dskb->head));
405 CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
406 CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
407 CAPIMSG_SETNCCI_PART(cskb->data, 1);
408 CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(dskb->head));
409 if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
410 CAPIMSG_SETINFO_CONF(cskb->data,
411 CapiFlagsNotSupportedByProtocol);
413 CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
416 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
417 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
419 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
422 * gigaset_skb_rcvd() - pass received skb to LL
423 * @bcs: B channel descriptor structure.
424 * @skb: received data.
426 * Called by hardware module {bas,ser,usb}_gigaset when user data has
427 * been successfully received, for passing to the LL.
428 * Warning: skb must not be accessed anymore!
430 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
432 struct cardstate *cs = bcs->cs;
433 struct gigaset_capi_ctr *iif = cs->iif;
434 struct gigaset_capi_appl *ap = bcs->ap;
437 /* update statistics */
441 dev_err(cs->dev, "%s: no application\n", __func__);
445 /* don't send further B3 messages if disconnected */
446 if (ap->connected < APCONN_ACTIVE) {
447 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
453 * prepend DATA_B3_IND message to payload
454 * Parameters: NCCI = 1, all others 0/unused
455 * frequent message, avoid _cmsg overhead
457 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
458 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
459 CAPIMSG_SETAPPID(skb->data, ap->id);
460 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
461 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
462 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
463 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
464 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
465 CAPIMSG_SETNCCI_PART(skb->data, 1);
466 /* Data parameter not used */
467 CAPIMSG_SETDATALEN(skb->data, len);
468 /* Data handle parameter not used */
469 CAPIMSG_SETFLAGS(skb->data, 0);
470 /* Data64 parameter not present */
473 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
474 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
476 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
479 * gigaset_isdn_rcv_err() - signal receive error
480 * @bcs: B channel descriptor structure.
482 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
483 * has occurred, for signalling to the LL.
485 void gigaset_isdn_rcv_err(struct bc_state *bcs)
487 /* if currently ignoring packets, just count down */
493 /* update statistics */
496 /* ToDo: signal error -> LL */
498 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
501 * gigaset_isdn_icall() - signal incoming call
502 * @at_state: connection state structure.
504 * Called by main module at tasklet level to notify the LL that an incoming
505 * call has been received. @at_state contains the parameters of the call.
507 * Return value: call disposition (ICALL_*)
509 int gigaset_isdn_icall(struct at_state_t *at_state)
511 struct cardstate *cs = at_state->cs;
512 struct bc_state *bcs = at_state->bcs;
513 struct gigaset_capi_ctr *iif = cs->iif;
514 struct gigaset_capi_appl *ap;
517 unsigned int msgsize;
521 * ToDo: signal calls without a free B channel, too
522 * (requires a u8 handle for the at_state structure that can
523 * be stored in the PLCI and used in the CONNECT_RESP message
524 * handler to retrieve it)
529 /* prepare CONNECT_IND message, using B channel number as PLCI */
530 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
531 iif->ctr.cnr | ((bcs->channel + 1) << 8));
533 /* minimum size, all structs empty */
534 msgsize = CAPI_CONNECT_IND_BASELEN;
536 /* Bearer Capability (mandatory) */
537 if (at_state->str_var[STR_ZBC]) {
538 /* pass on BC from Gigaset */
539 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
540 MAX_BC_OCTETS) < 0) {
541 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
542 at_state->str_var[STR_ZBC]);
546 /* look up corresponding CIP value */
547 iif->hcmsg.CIPValue = 0; /* default if nothing found */
548 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
549 if (cip2bchlc[i].bc != NULL &&
550 cip2bchlc[i].hlc == NULL &&
551 !strcmp(cip2bchlc[i].bc,
552 at_state->str_var[STR_ZBC])) {
553 iif->hcmsg.CIPValue = i;
557 /* no BC (internal call): assume CIP 1 (speech, A-law) */
558 iif->hcmsg.CIPValue = 1;
559 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
561 iif->hcmsg.BC = iif->bc_buf;
562 msgsize += iif->hcmsg.BC[0];
564 /* High Layer Compatibility (optional) */
565 if (at_state->str_var[STR_ZHLC]) {
566 /* pass on HLC from Gigaset */
567 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
568 MAX_HLC_OCTETS) < 0) {
569 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
570 at_state->str_var[STR_ZHLC]);
573 iif->hcmsg.HLC = iif->hlc_buf;
574 msgsize += iif->hcmsg.HLC[0];
576 /* look up corresponding CIP value */
577 /* keep BC based CIP value if none found */
578 if (at_state->str_var[STR_ZBC])
579 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
580 if (cip2bchlc[i].hlc != NULL &&
581 !strcmp(cip2bchlc[i].hlc,
582 at_state->str_var[STR_ZHLC]) &&
583 !strcmp(cip2bchlc[i].bc,
584 at_state->str_var[STR_ZBC])) {
585 iif->hcmsg.CIPValue = i;
590 /* Called Party Number (optional) */
591 if (at_state->str_var[STR_ZCPN]) {
592 i = strlen(at_state->str_var[STR_ZCPN]);
593 if (i > MAX_NUMBER_DIGITS) {
594 dev_warn(cs->dev, "RING ignored - bad number %s\n",
595 at_state->str_var[STR_ZBC]);
598 iif->cdpty_buf[0] = i + 1;
599 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
600 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
601 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
602 msgsize += iif->hcmsg.CalledPartyNumber[0];
605 /* Calling Party Number (optional) */
606 if (at_state->str_var[STR_NMBR]) {
607 i = strlen(at_state->str_var[STR_NMBR]);
608 if (i > MAX_NUMBER_DIGITS) {
609 dev_warn(cs->dev, "RING ignored - bad number %s\n",
610 at_state->str_var[STR_ZBC]);
613 iif->cgpty_buf[0] = i + 2;
614 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
615 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
616 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
617 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
618 msgsize += iif->hcmsg.CallingPartyNumber[0];
621 /* remaining parameters (not supported, always left NULL):
622 * - CalledPartySubaddress
623 * - CallingPartySubaddress
625 * - BChannelinformation
628 * - Facilitydataarray
631 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
632 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
633 format_ie(iif->hcmsg.BC));
634 gig_dbg(DEBUG_CMD, "icall: HLC %s",
635 format_ie(iif->hcmsg.HLC));
636 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
637 format_ie(iif->hcmsg.CallingPartyNumber));
638 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
639 format_ie(iif->hcmsg.CalledPartyNumber));
641 /* scan application list for matching listeners */
643 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
644 list_for_each_entry(ap, &iif->appls, ctrlist)
645 if (actCIPmask & ap->listenCIPmask) {
646 /* build CONNECT_IND message for this application */
647 iif->hcmsg.ApplId = ap->id;
648 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
650 skb = alloc_skb(msgsize, GFP_ATOMIC);
652 dev_err(cs->dev, "%s: out of memory\n",
656 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
657 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
659 /* add to listeners on this B channel, update state */
660 ap->bcnext = bcs->ap;
662 bcs->chstate |= CHS_NOTIFY_LL;
663 ap->connected = APCONN_SETUP;
666 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
670 * Return "accept" if any listeners.
671 * Gigaset will send ALERTING.
672 * There doesn't seem to be a way to avoid this.
674 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
678 * send a DISCONNECT_IND message to an application
679 * does not sleep, clobbers the controller's hcmsg structure
681 static void send_disconnect_ind(struct bc_state *bcs,
682 struct gigaset_capi_appl *ap, u16 reason)
684 struct cardstate *cs = bcs->cs;
685 struct gigaset_capi_ctr *iif = cs->iif;
688 if (ap->connected == APCONN_NONE)
691 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
692 ap->nextMessageNumber++,
693 iif->ctr.cnr | ((bcs->channel + 1) << 8));
694 iif->hcmsg.Reason = reason;
695 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
697 dev_err(cs->dev, "%s: out of memory\n", __func__);
700 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
701 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
702 ap->connected = APCONN_NONE;
703 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
707 * send a DISCONNECT_B3_IND message to an application
708 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
709 * does not sleep, clobbers the controller's hcmsg structure
711 static void send_disconnect_b3_ind(struct bc_state *bcs,
712 struct gigaset_capi_appl *ap)
714 struct cardstate *cs = bcs->cs;
715 struct gigaset_capi_ctr *iif = cs->iif;
718 /* nothing to do if no logical connection active */
719 if (ap->connected < APCONN_ACTIVE)
721 ap->connected = APCONN_SETUP;
723 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
724 ap->nextMessageNumber++,
725 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
726 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
728 dev_err(cs->dev, "%s: out of memory\n", __func__);
731 capi_cmsg2message(&iif->hcmsg,
732 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
733 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
734 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
738 * gigaset_isdn_connD() - signal D channel connect
739 * @bcs: B channel descriptor structure.
741 * Called by main module at tasklet level to notify the LL that the D channel
742 * connection has been established.
744 void gigaset_isdn_connD(struct bc_state *bcs)
746 struct cardstate *cs = bcs->cs;
747 struct gigaset_capi_ctr *iif = cs->iif;
748 struct gigaset_capi_appl *ap = bcs->ap;
750 unsigned int msgsize;
753 dev_err(cs->dev, "%s: no application\n", __func__);
757 /* this should never happen */
758 dev_warn(cs->dev, "%s: dropping extra application %u\n",
759 __func__, ap->bcnext->id);
760 send_disconnect_ind(bcs, ap->bcnext,
761 CapiCallGivenToOtherApplication);
762 ap->bcnext = ap->bcnext->bcnext;
764 if (ap->connected == APCONN_NONE) {
765 dev_warn(cs->dev, "%s: application %u not connected\n",
770 /* prepare CONNECT_ACTIVE_IND message
771 * Note: LLC not supported by device
773 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
774 ap->nextMessageNumber++,
775 iif->ctr.cnr | ((bcs->channel + 1) << 8));
777 /* minimum size, all structs empty */
778 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
780 /* ToDo: set parameter: Connected number
781 * (requires ev-layer state machine extension to collect
785 /* build and emit CONNECT_ACTIVE_IND message */
786 skb = alloc_skb(msgsize, GFP_ATOMIC);
788 dev_err(cs->dev, "%s: out of memory\n", __func__);
791 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
792 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
793 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
797 * gigaset_isdn_hupD() - signal D channel hangup
798 * @bcs: B channel descriptor structure.
800 * Called by main module at tasklet level to notify the LL that the D channel
801 * connection has been shut down.
803 void gigaset_isdn_hupD(struct bc_state *bcs)
805 struct gigaset_capi_appl *ap;
808 * ToDo: pass on reason code reported by device
809 * (requires ev-layer state machine extension to collect
812 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
813 send_disconnect_b3_ind(bcs, ap);
814 send_disconnect_ind(bcs, ap, 0);
820 * gigaset_isdn_connB() - signal B channel connect
821 * @bcs: B channel descriptor structure.
823 * Called by main module at tasklet level to notify the LL that the B channel
824 * connection has been established.
826 void gigaset_isdn_connB(struct bc_state *bcs)
828 struct cardstate *cs = bcs->cs;
829 struct gigaset_capi_ctr *iif = cs->iif;
830 struct gigaset_capi_appl *ap = bcs->ap;
832 unsigned int msgsize;
836 dev_err(cs->dev, "%s: no application\n", __func__);
840 /* this should never happen */
841 dev_warn(cs->dev, "%s: dropping extra application %u\n",
842 __func__, ap->bcnext->id);
843 send_disconnect_ind(bcs, ap->bcnext,
844 CapiCallGivenToOtherApplication);
845 ap->bcnext = ap->bcnext->bcnext;
847 if (!ap->connected) {
848 dev_warn(cs->dev, "%s: application %u not connected\n",
854 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
855 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
856 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
857 * Parameters in both cases always: NCCI = 1, NCPI empty
859 if (ap->connected >= APCONN_ACTIVE) {
860 command = CAPI_CONNECT_B3_ACTIVE;
861 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
863 command = CAPI_CONNECT_B3;
864 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
866 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
867 ap->nextMessageNumber++,
868 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
869 skb = alloc_skb(msgsize, GFP_ATOMIC);
871 dev_err(cs->dev, "%s: out of memory\n", __func__);
874 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
875 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
876 ap->connected = APCONN_ACTIVE;
877 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
881 * gigaset_isdn_hupB() - signal B channel hangup
882 * @bcs: B channel descriptor structure.
884 * Called by main module to notify the LL that the B channel connection has
887 void gigaset_isdn_hupB(struct bc_state *bcs)
889 struct cardstate *cs = bcs->cs;
890 struct gigaset_capi_appl *ap = bcs->ap;
892 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
895 dev_err(cs->dev, "%s: no application\n", __func__);
899 send_disconnect_b3_ind(bcs, ap);
903 * gigaset_isdn_start() - signal device availability
904 * @cs: device descriptor structure.
906 * Called by main module to notify the LL that the device is available for
909 void gigaset_isdn_start(struct cardstate *cs)
911 struct gigaset_capi_ctr *iif = cs->iif;
913 /* fill profile data: manufacturer name */
914 strcpy(iif->ctr.manu, "Siemens");
915 /* CAPI and device version */
916 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
917 iif->ctr.version.minorversion = 0;
918 /* ToDo: check/assert cs->gotfwver? */
919 iif->ctr.version.majormanuversion = cs->fwver[0];
920 iif->ctr.version.minormanuversion = cs->fwver[1];
921 /* number of B channels supported */
922 iif->ctr.profile.nbchannel = cs->channels;
923 /* global options: internal controller, supplementary services */
924 iif->ctr.profile.goptions = 0x11;
925 /* B1 protocols: 64 kbit/s HDLC or transparent */
926 iif->ctr.profile.support1 = 0x03;
927 /* B2 protocols: transparent only */
928 /* ToDo: X.75 SLP ? */
929 iif->ctr.profile.support2 = 0x02;
930 /* B3 protocols: transparent only */
931 iif->ctr.profile.support3 = 0x01;
932 /* no serial number */
933 strcpy(iif->ctr.serial, "0");
934 capi_ctr_ready(&iif->ctr);
938 * gigaset_isdn_stop() - signal device unavailability
939 * @cs: device descriptor structure.
941 * Called by main module to notify the LL that the device is no longer
944 void gigaset_isdn_stop(struct cardstate *cs)
946 struct gigaset_capi_ctr *iif = cs->iif;
947 capi_ctr_down(&iif->ctr);
951 * kernel CAPI callback methods
952 * ============================
958 static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
960 struct cardstate *cs = ctr->driverdata;
962 /* AVM specific operation, not needed for Gigaset -- ignore */
963 dev_notice(cs->dev, "load_firmware ignored\n");
969 * reset (deactivate) controller
971 static void gigaset_reset_ctr(struct capi_ctr *ctr)
973 struct cardstate *cs = ctr->driverdata;
975 /* AVM specific operation, not needed for Gigaset -- ignore */
976 dev_notice(cs->dev, "reset_ctr ignored\n");
980 * register CAPI application
982 static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
983 capi_register_params *rp)
985 struct gigaset_capi_ctr *iif
986 = container_of(ctr, struct gigaset_capi_ctr, ctr);
987 struct cardstate *cs = ctr->driverdata;
988 struct gigaset_capi_appl *ap;
990 list_for_each_entry(ap, &iif->appls, ctrlist)
991 if (ap->id == appl) {
993 "application %u already registered\n", appl);
997 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
999 dev_err(cs->dev, "%s: out of memory\n", __func__);
1004 list_add(&ap->ctrlist, &iif->appls);
1008 * release CAPI application
1010 static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
1012 struct gigaset_capi_ctr *iif
1013 = container_of(ctr, struct gigaset_capi_ctr, ctr);
1014 struct cardstate *cs = iif->ctr.driverdata;
1015 struct gigaset_capi_appl *ap, *tmp;
1017 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1018 if (ap->id == appl) {
1019 if (ap->connected != APCONN_NONE) {
1021 "%s: application %u still connected\n",
1023 /* ToDo: clear active connection */
1025 list_del(&ap->ctrlist);
1032 * =====================================================================
1033 * outgoing CAPI message handler
1034 * =====================================================================
1038 * helper function: emit reply message with given Info value
1040 static void send_conf(struct gigaset_capi_ctr *iif,
1041 struct gigaset_capi_appl *ap,
1042 struct sk_buff *skb,
1046 * _CONF replies always only have NCCI and Info parameters
1047 * so they'll fit into the _REQ message skb
1049 capi_cmsg_answer(&iif->acmsg);
1050 iif->acmsg.Info = info;
1051 capi_cmsg2message(&iif->acmsg, skb->data);
1052 __skb_trim(skb, CAPI_STDCONF_LEN);
1053 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1054 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1058 * process FACILITY_REQ message
1060 static void do_facility_req(struct gigaset_capi_ctr *iif,
1061 struct gigaset_capi_appl *ap,
1062 struct sk_buff *skb)
1064 struct cardstate *cs = iif->ctr.driverdata;
1065 struct sk_buff *cskb;
1067 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1069 static u8 confparam[10]; /* max. 9 octets + length byte */
1071 /* decode message */
1072 capi_message2cmsg(&iif->acmsg, skb->data);
1073 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1076 * Facility Request Parameter is not decoded by capi_message2cmsg()
1077 * encoding depends on Facility Selector
1079 switch (iif->acmsg.FacilitySelector) {
1080 case CAPI_FACILITY_DTMF: /* ToDo */
1081 info = CapiFacilityNotSupported;
1082 confparam[0] = 2; /* length */
1083 /* DTMF information: Unknown DTMF request */
1084 capimsg_setu16(confparam, 1, 2);
1087 case CAPI_FACILITY_V42BIS: /* not supported */
1088 info = CapiFacilityNotSupported;
1089 confparam[0] = 2; /* length */
1090 /* V.42 bis information: not available */
1091 capimsg_setu16(confparam, 1, 1);
1094 case CAPI_FACILITY_SUPPSVC:
1095 /* decode Function parameter */
1096 pparam = iif->acmsg.FacilityRequestParameter;
1097 if (pparam == NULL || *pparam < 2) {
1098 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1099 "Facility Request Parameter");
1100 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1103 function = CAPIMSG_U16(pparam, 1);
1105 case CAPI_SUPPSVC_GETSUPPORTED:
1107 /* Supplementary Service specific parameter */
1108 confparam[3] = 6; /* length */
1109 /* Supplementary services info: Success */
1110 capimsg_setu16(confparam, 4, CapiSuccess);
1111 /* Supported Services: none */
1112 capimsg_setu32(confparam, 6, 0);
1114 /* ToDo: add supported services */
1116 info = CapiFacilitySpecificFunctionNotSupported;
1117 /* Supplementary Service specific parameter */
1118 confparam[3] = 2; /* length */
1119 /* Supplementary services info: not supported */
1120 capimsg_setu16(confparam, 4,
1121 CapiSupplementaryServiceNotSupported);
1124 /* Facility confirmation parameter */
1125 confparam[0] = confparam[3] + 3; /* total length */
1126 /* Function: copy from _REQ message */
1127 capimsg_setu16(confparam, 1, function);
1128 /* Supplementary Service specific parameter already set above */
1131 case CAPI_FACILITY_WAKEUP: /* ToDo */
1132 info = CapiFacilityNotSupported;
1133 confparam[0] = 2; /* length */
1134 /* Number of accepted awake request parameters: 0 */
1135 capimsg_setu16(confparam, 1, 0);
1139 info = CapiFacilityNotSupported;
1140 confparam[0] = 0; /* empty struct */
1143 /* send FACILITY_CONF with given Info and confirmation parameter */
1144 capi_cmsg_answer(&iif->acmsg);
1145 iif->acmsg.Info = info;
1146 iif->acmsg.FacilityConfirmationParameter = confparam;
1147 msgsize += confparam[0]; /* length */
1148 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1150 dev_err(cs->dev, "%s: out of memory\n", __func__);
1153 capi_cmsg2message(&iif->acmsg, __skb_put(cskb, msgsize));
1154 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1155 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1160 * process LISTEN_REQ message
1161 * just store the masks in the application data structure
1163 static void do_listen_req(struct gigaset_capi_ctr *iif,
1164 struct gigaset_capi_appl *ap,
1165 struct sk_buff *skb)
1167 /* decode message */
1168 capi_message2cmsg(&iif->acmsg, skb->data);
1169 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1171 /* store listening parameters */
1172 ap->listenInfoMask = iif->acmsg.InfoMask;
1173 ap->listenCIPmask = iif->acmsg.CIPmask;
1174 send_conf(iif, ap, skb, CapiSuccess);
1178 * process ALERT_REQ message
1179 * nothing to do, Gigaset always alerts anyway
1181 static void do_alert_req(struct gigaset_capi_ctr *iif,
1182 struct gigaset_capi_appl *ap,
1183 struct sk_buff *skb)
1185 /* decode message */
1186 capi_message2cmsg(&iif->acmsg, skb->data);
1187 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1188 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1192 * process CONNECT_REQ message
1193 * allocate a B channel, prepare dial commands, queue a DIAL event,
1194 * emit CONNECT_CONF reply
1196 static void do_connect_req(struct gigaset_capi_ctr *iif,
1197 struct gigaset_capi_appl *ap,
1198 struct sk_buff *skb)
1200 struct cardstate *cs = iif->ctr.driverdata;
1201 _cmsg *cmsg = &iif->acmsg;
1202 struct bc_state *bcs;
1209 /* decode message */
1210 capi_message2cmsg(&iif->acmsg, skb->data);
1211 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1213 /* get free B channel & construct PLCI */
1214 bcs = gigaset_get_free_channel(cs);
1216 dev_notice(cs->dev, "%s: no B channel available\n",
1218 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1223 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1225 /* build command table */
1226 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1230 /* encode parameter: Called party number */
1231 pp = cmsg->CalledPartyNumber;
1232 if (pp == NULL || *pp == 0) {
1233 dev_notice(cs->dev, "%s: %s missing\n",
1234 "CONNECT_REQ", "Called party number");
1235 info = CapiIllMessageParmCoding;
1239 /* check type of number/numbering plan byte */
1241 case 0x80: /* unknown type / unknown numbering plan */
1242 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1244 default: /* others: warn about potential misinterpretation */
1245 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1246 "CONNECT_REQ", "Called party number", *pp);
1250 /* translate "**" internal call prefix to CTP value */
1251 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1258 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1259 if (!commands[AT_TYPE])
1261 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1262 if (!commands[AT_DIAL])
1264 snprintf(commands[AT_DIAL], l+3, "D%*s\r", l, pp);
1266 /* encode parameter: Calling party number */
1267 pp = cmsg->CallingPartyNumber;
1268 if (pp != NULL && *pp > 0) {
1271 /* check type of number/numbering plan byte */
1272 /* ToDo: allow for/handle Ext=1? */
1274 case 0x00: /* unknown type / unknown numbering plan */
1275 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1279 "%s: %s type/plan 0x%02x unsupported\n",
1280 "CONNECT_REQ", "Calling party number", *pp);
1285 /* check presentation indicator */
1287 dev_notice(cs->dev, "%s: %s IE truncated\n",
1288 "CONNECT_REQ", "Calling party number");
1289 info = CapiIllMessageParmCoding;
1292 switch (*pp & 0xfc) { /* ignore Screening indicator */
1293 case 0x80: /* Presentation allowed */
1296 case 0xa0: /* Presentation restricted */
1300 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1302 "Presentation/Screening indicator",
1306 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1307 if (!commands[AT_CLIP])
1314 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1315 if (!commands[AT_MSN])
1317 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1321 /* check parameter: CIP Value */
1322 if (cmsg->CIPValue > ARRAY_SIZE(cip2bchlc) ||
1323 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1324 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1325 "CONNECT_REQ", cmsg->CIPValue);
1326 info = CapiCipValueUnknown;
1330 /* check/encode parameter: BC */
1331 if (cmsg->BC && cmsg->BC[0]) {
1332 /* explicit BC overrides CIP */
1333 l = 2*cmsg->BC[0] + 7;
1334 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1335 if (!commands[AT_BC])
1337 strcpy(commands[AT_BC], "^SBC=");
1338 decode_ie(cmsg->BC, commands[AT_BC]+5);
1339 strcpy(commands[AT_BC] + l - 2, "\r");
1340 } else if (cip2bchlc[cmsg->CIPValue].bc) {
1341 l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
1342 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1343 if (!commands[AT_BC])
1345 snprintf(commands[AT_BC], l, "^SBC=%s\r",
1346 cip2bchlc[cmsg->CIPValue].bc);
1349 /* check/encode parameter: HLC */
1350 if (cmsg->HLC && cmsg->HLC[0]) {
1351 /* explicit HLC overrides CIP */
1352 l = 2*cmsg->HLC[0] + 7;
1353 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1354 if (!commands[AT_HLC])
1356 strcpy(commands[AT_HLC], "^SHLC=");
1357 decode_ie(cmsg->HLC, commands[AT_HLC]+5);
1358 strcpy(commands[AT_HLC] + l - 2, "\r");
1359 } else if (cip2bchlc[cmsg->CIPValue].hlc) {
1360 l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
1361 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1362 if (!commands[AT_HLC])
1364 snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
1365 cip2bchlc[cmsg->CIPValue].hlc);
1368 /* check/encode parameter: B Protocol */
1369 if (cmsg->BProtocol == CAPI_DEFAULT) {
1370 bcs->proto2 = L2_HDLC;
1372 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1374 switch (cmsg->B1protocol) {
1376 bcs->proto2 = L2_HDLC;
1379 bcs->proto2 = L2_BITSYNC;
1383 "B1 Protocol %u unsupported, using Transparent\n",
1385 bcs->proto2 = L2_BITSYNC;
1387 if (cmsg->B2protocol != 1)
1389 "B2 Protocol %u unsupported, using Transparent\n",
1391 if (cmsg->B3protocol != 0)
1393 "B3 Protocol %u unsupported, using Transparent\n",
1395 ignore_cstruct_param(cs, cmsg->B1configuration,
1396 "CONNECT_REQ", "B1 Configuration");
1397 ignore_cstruct_param(cs, cmsg->B2configuration,
1398 "CONNECT_REQ", "B2 Configuration");
1399 ignore_cstruct_param(cs, cmsg->B3configuration,
1400 "CONNECT_REQ", "B3 Configuration");
1402 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1403 if (!commands[AT_PROTO])
1405 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1407 /* ToDo: check/encode remaining parameters */
1408 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1409 "CONNECT_REQ", "Called pty subaddr");
1410 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1411 "CONNECT_REQ", "Calling pty subaddr");
1412 ignore_cstruct_param(cs, cmsg->LLC,
1413 "CONNECT_REQ", "LLC");
1414 ignore_cmstruct_param(cs, cmsg->AdditionalInfo,
1415 "CONNECT_REQ", "Additional Info");
1417 /* encode parameter: B channel to use */
1418 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1419 if (!commands[AT_ISO])
1421 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1422 (unsigned) bcs->channel + 1);
1424 /* queue & schedule EV_DIAL event */
1425 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1426 bcs->at_state.seq_index, NULL))
1428 gig_dbg(DEBUG_CMD, "scheduling DIAL");
1429 gigaset_schedule_event(cs);
1430 ap->connected = APCONN_SETUP;
1431 send_conf(iif, ap, skb, CapiSuccess);
1435 dev_err(cs->dev, "%s: out of memory\n", __func__);
1436 info = CAPI_MSGOSRESOURCEERR;
1439 for (i = 0; i < AT_NUM; i++)
1442 gigaset_free_channel(bcs);
1443 send_conf(iif, ap, skb, info);
1447 * process CONNECT_RESP message
1448 * checks protocol parameters and queues an ACCEPT or HUP event
1450 static void do_connect_resp(struct gigaset_capi_ctr *iif,
1451 struct gigaset_capi_appl *ap,
1452 struct sk_buff *skb)
1454 struct cardstate *cs = iif->ctr.driverdata;
1455 _cmsg *cmsg = &iif->acmsg;
1456 struct bc_state *bcs;
1457 struct gigaset_capi_appl *oap;
1460 /* decode message */
1461 capi_message2cmsg(&iif->acmsg, skb->data);
1462 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1465 /* extract and check channel number from PLCI */
1466 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1467 if (!channel || channel > cs->channels) {
1468 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1469 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1472 bcs = cs->bcs + channel - 1;
1474 switch (cmsg->Reject) {
1475 case 0: /* Accept */
1476 /* drop all competing applications, keep only this one */
1477 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1479 send_disconnect_ind(bcs, oap,
1480 CapiCallGivenToOtherApplication);
1483 bcs->chstate |= CHS_NOTIFY_LL;
1485 /* check/encode B channel protocol */
1486 if (cmsg->BProtocol == CAPI_DEFAULT) {
1487 bcs->proto2 = L2_HDLC;
1489 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1491 switch (cmsg->B1protocol) {
1493 bcs->proto2 = L2_HDLC;
1496 bcs->proto2 = L2_BITSYNC;
1500 "B1 Protocol %u unsupported, using Transparent\n",
1502 bcs->proto2 = L2_BITSYNC;
1504 if (cmsg->B2protocol != 1)
1506 "B2 Protocol %u unsupported, using Transparent\n",
1508 if (cmsg->B3protocol != 0)
1510 "B3 Protocol %u unsupported, using Transparent\n",
1512 ignore_cstruct_param(cs, cmsg->B1configuration,
1513 "CONNECT_RESP", "B1 Configuration");
1514 ignore_cstruct_param(cs, cmsg->B2configuration,
1515 "CONNECT_RESP", "B2 Configuration");
1516 ignore_cstruct_param(cs, cmsg->B3configuration,
1517 "CONNECT_RESP", "B3 Configuration");
1520 /* ToDo: check/encode remaining parameters */
1521 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1522 "CONNECT_RESP", "Connected Number");
1523 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1524 "CONNECT_RESP", "Connected Subaddress");
1525 ignore_cstruct_param(cs, cmsg->LLC,
1526 "CONNECT_RESP", "LLC");
1527 ignore_cmstruct_param(cs, cmsg->AdditionalInfo,
1528 "CONNECT_RESP", "Additional Info");
1531 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1532 EV_ACCEPT, NULL, 0, NULL))
1534 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
1535 gigaset_schedule_event(cs);
1538 case 1: /* Ignore */
1539 /* send DISCONNECT_IND to this application */
1540 send_disconnect_ind(bcs, ap, 0);
1542 /* remove it from the list of listening apps */
1543 if (bcs->ap == ap) {
1544 bcs->ap = ap->bcnext;
1545 if (bcs->ap == NULL)
1546 /* last one: stop ev-layer hupD notifications */
1547 bcs->chstate &= ~CHS_NOTIFY_LL;
1550 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1551 if (oap->bcnext == ap) {
1552 oap->bcnext = oap->bcnext->bcnext;
1556 dev_err(cs->dev, "%s: application %u not found\n",
1560 default: /* Reject */
1561 /* drop all competing applications, keep only this one */
1562 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1564 send_disconnect_ind(bcs, oap,
1565 CapiCallGivenToOtherApplication);
1569 /* reject call - will trigger DISCONNECT_IND for this app */
1570 dev_info(cs->dev, "%s: Reject=%x\n",
1571 "CONNECT_RESP", cmsg->Reject);
1572 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1573 EV_HUP, NULL, 0, NULL))
1575 gig_dbg(DEBUG_CMD, "scheduling HUP");
1576 gigaset_schedule_event(cs);
1582 * process CONNECT_B3_REQ message
1583 * build NCCI and emit CONNECT_B3_CONF reply
1585 static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1586 struct gigaset_capi_appl *ap,
1587 struct sk_buff *skb)
1589 struct cardstate *cs = iif->ctr.driverdata;
1592 /* decode message */
1593 capi_message2cmsg(&iif->acmsg, skb->data);
1594 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1596 /* extract and check channel number from PLCI */
1597 channel = (iif->acmsg.adr.adrPLCI >> 8) & 0xff;
1598 if (!channel || channel > cs->channels) {
1599 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1600 "CONNECT_B3_REQ", "PLCI", iif->acmsg.adr.adrPLCI);
1601 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1605 /* mark logical connection active */
1606 ap->connected = APCONN_ACTIVE;
1608 /* build NCCI: always 1 (one B3 connection only) */
1609 iif->acmsg.adr.adrNCCI |= 1 << 16;
1611 /* NCPI parameter: not applicable for B3 Transparent */
1612 ignore_cstruct_param(cs, iif->acmsg.NCPI,
1613 "CONNECT_B3_REQ", "NCPI");
1614 send_conf(iif, ap, skb,
1615 (iif->acmsg.NCPI && iif->acmsg.NCPI[0]) ?
1616 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1620 * process CONNECT_B3_RESP message
1621 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1622 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1623 * The emitted message is always shorter than the received one,
1624 * allowing to reuse the skb.
1626 static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1627 struct gigaset_capi_appl *ap,
1628 struct sk_buff *skb)
1630 struct cardstate *cs = iif->ctr.driverdata;
1631 struct bc_state *bcs = NULL;
1633 unsigned int msgsize;
1636 /* decode message */
1637 capi_message2cmsg(&iif->acmsg, skb->data);
1638 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1640 /* extract and check channel number and NCCI */
1641 channel = (iif->acmsg.adr.adrNCCI >> 8) & 0xff;
1642 if (!channel || channel > cs->channels ||
1643 ((iif->acmsg.adr.adrNCCI >> 16) & 0xffff) != 1) {
1644 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1645 "CONNECT_B3_RESP", "NCCI", iif->acmsg.adr.adrNCCI);
1649 bcs = &cs->bcs[channel-1];
1651 if (iif->acmsg.Reject) {
1652 /* Reject: clear B3 connect received flag */
1653 ap->connected = APCONN_SETUP;
1655 /* trigger hangup, causing eventual DISCONNECT_IND */
1656 if (!gigaset_add_event(cs, &bcs->at_state,
1657 EV_HUP, NULL, 0, NULL)) {
1658 dev_err(cs->dev, "%s: out of memory\n", __func__);
1662 gig_dbg(DEBUG_CMD, "scheduling HUP");
1663 gigaset_schedule_event(cs);
1665 /* emit DISCONNECT_B3_IND */
1666 command = CAPI_DISCONNECT_B3;
1667 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1670 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1671 * we only send CONNECT_B3_IND if the B channel is up
1673 command = CAPI_CONNECT_B3_ACTIVE;
1674 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1676 capi_cmsg_header(&iif->acmsg, ap->id, command, CAPI_IND,
1677 ap->nextMessageNumber++, iif->acmsg.adr.adrNCCI);
1678 __skb_trim(skb, msgsize);
1679 capi_cmsg2message(&iif->acmsg, skb->data);
1680 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1681 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1685 * process DISCONNECT_REQ message
1686 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1687 * emit DISCONNECT_CONF reply
1689 static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1690 struct gigaset_capi_appl *ap,
1691 struct sk_buff *skb)
1693 struct cardstate *cs = iif->ctr.driverdata;
1694 struct bc_state *bcs;
1696 struct sk_buff *b3skb;
1699 /* decode message */
1700 capi_message2cmsg(&iif->acmsg, skb->data);
1701 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1703 /* extract and check channel number from PLCI */
1704 channel = (iif->acmsg.adr.adrPLCI >> 8) & 0xff;
1705 if (!channel || channel > cs->channels) {
1706 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1707 "DISCONNECT_REQ", "PLCI", iif->acmsg.adr.adrPLCI);
1708 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1711 bcs = cs->bcs + channel - 1;
1713 /* ToDo: process parameter: Additional info */
1714 ignore_cmstruct_param(cs, iif->acmsg.AdditionalInfo,
1715 "DISCONNECT_REQ", "Additional Info");
1717 /* skip if DISCONNECT_IND already sent */
1721 /* check for active logical connection */
1722 if (ap->connected >= APCONN_ACTIVE) {
1724 * emit DISCONNECT_B3_IND with cause 0x3301
1725 * use separate cmsg structure, as the content of iif->acmsg
1726 * is still needed for creating the _CONF message
1728 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1730 dev_err(cs->dev, "%s: out of memory\n", __func__);
1731 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1734 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1735 ap->nextMessageNumber++,
1736 iif->acmsg.adr.adrPLCI | (1 << 16));
1737 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1738 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1739 if (b3skb == NULL) {
1740 dev_err(cs->dev, "%s: out of memory\n", __func__);
1741 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1744 capi_cmsg2message(b3cmsg,
1745 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1747 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1750 /* trigger hangup, causing eventual DISCONNECT_IND */
1751 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1752 dev_err(cs->dev, "%s: out of memory\n", __func__);
1753 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1756 gig_dbg(DEBUG_CMD, "scheduling HUP");
1757 gigaset_schedule_event(cs);
1760 send_conf(iif, ap, skb, CapiSuccess);
1764 * process DISCONNECT_B3_REQ message
1765 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1767 static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1768 struct gigaset_capi_appl *ap,
1769 struct sk_buff *skb)
1771 struct cardstate *cs = iif->ctr.driverdata;
1774 /* decode message */
1775 capi_message2cmsg(&iif->acmsg, skb->data);
1776 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1778 /* extract and check channel number and NCCI */
1779 channel = (iif->acmsg.adr.adrNCCI >> 8) & 0xff;
1780 if (!channel || channel > cs->channels ||
1781 ((iif->acmsg.adr.adrNCCI >> 16) & 0xffff) != 1) {
1782 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1783 "DISCONNECT_B3_REQ", "NCCI", iif->acmsg.adr.adrNCCI);
1784 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1788 /* reject if logical connection not active */
1789 if (ap->connected < APCONN_ACTIVE) {
1790 send_conf(iif, ap, skb,
1791 CapiMessageNotSupportedInCurrentState);
1795 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1796 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1797 EV_HUP, NULL, 0, NULL)) {
1798 dev_err(cs->dev, "%s: out of memory\n", __func__);
1799 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1802 gig_dbg(DEBUG_CMD, "scheduling HUP");
1803 gigaset_schedule_event(cs);
1805 /* NCPI parameter: not applicable for B3 Transparent */
1806 ignore_cstruct_param(cs, iif->acmsg.NCPI,
1807 "DISCONNECT_B3_REQ", "NCPI");
1808 send_conf(iif, ap, skb,
1809 (iif->acmsg.NCPI && iif->acmsg.NCPI[0]) ?
1810 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1814 * process DATA_B3_REQ message
1816 static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1817 struct gigaset_capi_appl *ap,
1818 struct sk_buff *skb)
1820 struct cardstate *cs = iif->ctr.driverdata;
1821 int channel = CAPIMSG_PLCI_PART(skb->data);
1822 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1823 u16 msglen = CAPIMSG_LEN(skb->data);
1824 u16 datalen = CAPIMSG_DATALEN(skb->data);
1825 u16 flags = CAPIMSG_FLAGS(skb->data);
1827 /* frequent message, avoid _cmsg overhead */
1828 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1830 gig_dbg(DEBUG_LLDATA,
1831 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1832 channel, flags, msglen, datalen);
1834 /* check parameters */
1835 if (channel == 0 || channel > cs->channels || ncci != 1) {
1836 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1837 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1838 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1841 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1842 dev_notice(cs->dev, "%s: unexpected length %d\n",
1843 "DATA_B3_REQ", msglen);
1844 if (msglen + datalen != skb->len)
1845 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1846 "DATA_B3_REQ", msglen, datalen, skb->len);
1847 if (msglen + datalen > skb->len) {
1848 /* message too short for announced data length */
1849 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1852 if (flags & CAPI_FLAGS_RESERVED) {
1853 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1854 "DATA_B3_REQ", flags);
1855 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1859 /* reject if logical connection not active */
1860 if (ap->connected < APCONN_ACTIVE) {
1861 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1866 * pull CAPI message from skb,
1867 * pass payload data to device-specific module
1868 * CAPI message will be preserved in headroom
1870 skb_pull(skb, msglen);
1871 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1872 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1876 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1879 * ToDo: honor unset "delivery confirmation" bit
1880 * (send DATA_B3_CONF immediately?)
1885 * process RESET_B3_REQ message
1886 * just always reply "not supported by current protocol"
1888 static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1889 struct gigaset_capi_appl *ap,
1890 struct sk_buff *skb)
1892 /* decode message */
1893 capi_message2cmsg(&iif->acmsg, skb->data);
1894 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1895 send_conf(iif, ap, skb,
1896 CapiResetProcedureNotSupportedByCurrentProtocol);
1900 * dump unsupported/ignored messages at most twice per minute,
1901 * some apps send those very frequently
1903 static unsigned long ignored_msg_dump_time;
1906 * unsupported CAPI message handler
1908 static void do_unsupported(struct gigaset_capi_ctr *iif,
1909 struct gigaset_capi_appl *ap,
1910 struct sk_buff *skb)
1912 /* decode message */
1913 capi_message2cmsg(&iif->acmsg, skb->data);
1914 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1915 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1916 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1920 * CAPI message handler: no-op
1922 static void do_nothing(struct gigaset_capi_ctr *iif,
1923 struct gigaset_capi_appl *ap,
1924 struct sk_buff *skb)
1926 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1927 /* decode message */
1928 capi_message2cmsg(&iif->acmsg, skb->data);
1929 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1934 static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1935 struct gigaset_capi_appl *ap,
1936 struct sk_buff *skb)
1938 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1942 /* table of outgoing CAPI message handlers with lookup function */
1943 typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1944 struct gigaset_capi_appl *,
1949 capi_send_handler_t handler;
1950 } capi_send_handler_table[] = {
1951 /* most frequent messages first for faster lookup */
1952 { CAPI_DATA_B3_REQ, do_data_b3_req },
1953 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1955 { CAPI_ALERT_REQ, do_alert_req },
1956 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1957 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1958 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1959 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1960 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1961 { CAPI_CONNECT_REQ, do_connect_req },
1962 { CAPI_CONNECT_RESP, do_connect_resp },
1963 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1964 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1965 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1966 { CAPI_DISCONNECT_RESP, do_nothing },
1967 { CAPI_FACILITY_REQ, do_facility_req },
1968 { CAPI_FACILITY_RESP, do_nothing },
1969 { CAPI_LISTEN_REQ, do_listen_req },
1970 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1971 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1972 { CAPI_RESET_B3_RESP, do_nothing },
1975 * ToDo: support overlap sending (requires ev-layer state
1976 * machine extension to generate additional ATD commands)
1978 { CAPI_INFO_REQ, do_unsupported },
1979 { CAPI_INFO_RESP, do_nothing },
1982 * ToDo: what's the proper response for these?
1984 { CAPI_MANUFACTURER_REQ, do_nothing },
1985 { CAPI_MANUFACTURER_RESP, do_nothing },
1988 /* look up handler */
1989 static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
1993 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
1994 if (capi_send_handler_table[i].cmd == cmd)
1995 return capi_send_handler_table[i].handler;
2001 * gigaset_send_message() - accept a CAPI message from an application
2002 * @ctr: controller descriptor structure.
2003 * @skb: CAPI message.
2005 * Return value: CAPI error code
2006 * Note: capidrv (and probably others, too) only uses the return value to
2007 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2009 static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2011 struct gigaset_capi_ctr *iif
2012 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2013 struct cardstate *cs = ctr->driverdata;
2014 struct gigaset_capi_appl *ap;
2015 capi_send_handler_t handler;
2017 /* can only handle linear sk_buffs */
2018 if (skb_linearize(skb) < 0) {
2019 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2020 return CAPI_MSGOSRESOURCEERR;
2023 /* retrieve application data structure */
2024 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2026 dev_notice(cs->dev, "%s: application %u not registered\n",
2027 __func__, CAPIMSG_APPID(skb->data));
2028 return CAPI_ILLAPPNR;
2031 /* look up command */
2032 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2034 /* unknown/unsupported message type */
2035 if (printk_ratelimit())
2036 dev_notice(cs->dev, "%s: unsupported message %u\n",
2037 __func__, CAPIMSG_CMD(skb->data));
2038 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2042 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2043 /* queue behind other messages */
2044 skb_queue_tail(&iif->sendqueue, skb);
2045 return CAPI_NOERROR;
2048 /* process message */
2049 handler(iif, ap, skb);
2051 /* process other messages arrived in the meantime */
2052 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2053 skb = skb_dequeue(&iif->sendqueue);
2055 /* should never happen */
2056 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2059 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2061 /* could that happen? */
2062 dev_warn(cs->dev, "%s: application %u vanished\n",
2063 __func__, CAPIMSG_APPID(skb->data));
2066 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2068 /* should never happen */
2069 dev_err(cs->dev, "%s: handler %x vanished\n",
2070 __func__, CAPIMSG_CMD(skb->data));
2073 handler(iif, ap, skb);
2076 return CAPI_NOERROR;
2080 * gigaset_procinfo() - build single line description for controller
2081 * @ctr: controller descriptor structure.
2083 * Return value: pointer to generated string (null terminated)
2085 static char *gigaset_procinfo(struct capi_ctr *ctr)
2087 return ctr->name; /* ToDo: more? */
2091 * gigaset_ctr_read_proc() - build controller proc file entry
2092 * @page: buffer of PAGE_SIZE bytes for receiving the entry.
2097 * @ctr: controller descriptor structure.
2099 * Return value: length of generated entry
2101 static int gigaset_ctr_read_proc(char *page, char **start, off_t off,
2102 int count, int *eof, struct capi_ctr *ctr)
2104 struct cardstate *cs = ctr->driverdata;
2108 len += sprintf(page+len, "%-16s %s\n", "name", ctr->name);
2109 len += sprintf(page+len, "%-16s %s %s\n", "dev",
2110 dev_driver_string(cs->dev), dev_name(cs->dev));
2111 len += sprintf(page+len, "%-16s %d\n", "id", cs->myid);
2113 len += sprintf(page+len, "%-16s %d.%d.%d.%d\n", "firmware",
2114 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2115 len += sprintf(page+len, "%-16s %d\n", "channels",
2117 len += sprintf(page+len, "%-16s %s\n", "onechannel",
2118 cs->onechannel ? "yes" : "no");
2136 len += sprintf(page+len, "%-16s %s\n", "mode", s);
2138 switch (cs->mstate) {
2139 case MS_UNINITIALIZED:
2140 s = "uninitialized";
2160 len += sprintf(page+len, "%-16s %s\n", "mstate", s);
2162 len += sprintf(page+len, "%-16s %s\n", "running",
2163 cs->running ? "yes" : "no");
2164 len += sprintf(page+len, "%-16s %s\n", "connected",
2165 cs->connected ? "yes" : "no");
2166 len += sprintf(page+len, "%-16s %s\n", "isdn_up",
2167 cs->isdn_up ? "yes" : "no");
2168 len += sprintf(page+len, "%-16s %s\n", "cidmode",
2169 cs->cidmode ? "yes" : "no");
2171 for (i = 0; i < cs->channels; i++) {
2172 len += sprintf(page+len, "[%d]%-13s %d\n", i, "corrupted",
2173 cs->bcs[i].corrupted);
2174 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_down",
2175 cs->bcs[i].trans_down);
2176 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_up",
2177 cs->bcs[i].trans_up);
2178 len += sprintf(page+len, "[%d]%-13s %d\n", i, "chstate",
2179 cs->bcs[i].chstate);
2180 switch (cs->bcs[i].proto2) {
2193 len += sprintf(page+len, "[%d]%-13s %s\n", i, "proto2", s);
2199 static struct capi_driver capi_driver_gigaset = {
2205 * gigaset_isdn_register() - register to LL
2206 * @cs: device descriptor structure.
2207 * @isdnid: device name.
2209 * Called by main module to register the device with the LL.
2211 * Return value: 1 for success, 0 for failure
2213 int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
2215 struct gigaset_capi_ctr *iif;
2218 pr_info("Kernel CAPI interface\n");
2220 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2222 pr_err("%s: out of memory\n", __func__);
2226 /* register driver with CAPI (ToDo: what for?) */
2227 register_capi_driver(&capi_driver_gigaset);
2229 /* prepare controller structure */
2230 iif->ctr.owner = THIS_MODULE;
2231 iif->ctr.driverdata = cs;
2232 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2233 iif->ctr.driver_name = "gigaset";
2234 iif->ctr.load_firmware = gigaset_load_firmware;
2235 iif->ctr.reset_ctr = gigaset_reset_ctr;
2236 iif->ctr.register_appl = gigaset_register_appl;
2237 iif->ctr.release_appl = gigaset_release_appl;
2238 iif->ctr.send_message = gigaset_send_message;
2239 iif->ctr.procinfo = gigaset_procinfo;
2240 iif->ctr.ctr_read_proc = gigaset_ctr_read_proc;
2241 INIT_LIST_HEAD(&iif->appls);
2242 skb_queue_head_init(&iif->sendqueue);
2243 atomic_set(&iif->sendqlen, 0);
2245 /* register controller with CAPI */
2246 rc = attach_capi_ctr(&iif->ctr);
2248 pr_err("attach_capi_ctr failed (%d)\n", rc);
2249 unregister_capi_driver(&capi_driver_gigaset);
2255 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2260 * gigaset_isdn_unregister() - unregister from LL
2261 * @cs: device descriptor structure.
2263 * Called by main module to unregister the device from the LL.
2265 void gigaset_isdn_unregister(struct cardstate *cs)
2267 struct gigaset_capi_ctr *iif = cs->iif;
2269 detach_capi_ctr(&iif->ctr);
2272 unregister_capi_driver(&capi_driver_gigaset);