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/proc_fs.h>
17 #include <linux/seq_file.h>
18 #include <linux/isdn/capilli.h>
19 #include <linux/isdn/capicmd.h>
20 #include <linux/isdn/capiutil.h>
22 /* missing from kernelcapi.h */
23 #define CapiNcpiNotSupportedByProtocol 0x0001
24 #define CapiFlagsNotSupportedByProtocol 0x0002
25 #define CapiAlertAlreadySent 0x0003
26 #define CapiFacilitySpecificFunctionNotSupported 0x3011
28 /* missing from capicmd.h */
29 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
30 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
31 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
32 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
33 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
34 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
35 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
36 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
37 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
38 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
39 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
41 #define CAPI_FACILITY_HANDSET 0x0000
42 #define CAPI_FACILITY_DTMF 0x0001
43 #define CAPI_FACILITY_V42BIS 0x0002
44 #define CAPI_FACILITY_SUPPSVC 0x0003
45 #define CAPI_FACILITY_WAKEUP 0x0004
46 #define CAPI_FACILITY_LI 0x0005
48 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
50 /* missing from capiutil.h */
51 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
52 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
53 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
54 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
55 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
56 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
57 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
58 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
60 /* parameters with differing location in DATA_B3_CONF/_RESP: */
61 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
62 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
64 /* Flags (DATA_B3_REQ/_IND) */
65 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
66 #define CAPI_FLAGS_RESERVED (~0x1f)
69 #define MAX_BC_OCTETS 11
70 #define MAX_HLC_OCTETS 3
71 #define MAX_NUMBER_DIGITS 20
72 #define MAX_FMT_IE_LEN 20
74 /* values for gigaset_capi_appl.connected */
75 #define APCONN_NONE 0 /* inactive/listening */
76 #define APCONN_SETUP 1 /* connecting */
77 #define APCONN_ACTIVE 2 /* B channel up */
79 /* registered application data structure */
80 struct gigaset_capi_appl {
81 struct list_head ctrlist;
82 struct gigaset_capi_appl *bcnext;
84 u16 nextMessageNumber;
90 /* CAPI specific controller data structure */
91 struct gigaset_capi_ctr {
93 struct list_head appls;
94 struct sk_buff_head sendqueue;
96 /* two _cmsg structures possibly used concurrently: */
97 _cmsg hcmsg; /* for message composition triggered from hardware */
98 _cmsg acmsg; /* for dissection of messages sent from application */
99 u8 bc_buf[MAX_BC_OCTETS+1];
100 u8 hlc_buf[MAX_HLC_OCTETS+1];
101 u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
102 u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
105 /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
110 [1] = { "8090A3", NULL },
112 [2] = { "8890", NULL },
113 /* Unrestricted digital information */
114 [3] = { "8990", NULL },
115 /* Restricted digital information */
116 [4] = { "9090A3", NULL },
117 /* 3,1 kHz audio (A-law) */
118 [5] = { "9190", NULL },
120 [6] = { "9890", NULL },
122 [7] = { "88C0C6E6", NULL },
124 [8] = { "8890218F", NULL },
125 /* 56 kbit/s rate adaptation */
126 [9] = { "9190A5", NULL },
127 /* Unrestricted digital information with tones/announcements */
128 [16] = { "8090A3", "9181" },
130 [17] = { "9090A3", "9184" },
131 /* Group 2/3 facsimile */
132 [18] = { "8890", "91A1" },
133 /* Group 4 facsimile Class 1 */
134 [19] = { "8890", "91A4" },
135 /* Teletex service basic and mixed mode
136 and Group 4 facsimile service Classes II and III */
137 [20] = { "8890", "91A8" },
138 /* Teletex service basic and processable mode */
139 [21] = { "8890", "91B1" },
140 /* Teletex service basic mode */
141 [22] = { "8890", "91B2" },
142 /* International interworking for Videotex */
143 [23] = { "8890", "91B5" },
145 [24] = { "8890", "91B8" },
146 /* Message Handling Systems in accordance with X.400 */
147 [25] = { "8890", "91C1" },
148 /* OSI application in accordance with X.200 */
149 [26] = { "9190A5", "9181" },
150 /* 7 kHz telephony */
151 [27] = { "9190A5", "916001" },
152 /* Video telephony, first connection */
153 [28] = { "8890", "916002" },
154 /* Video telephony, second connection */
163 * emit unsupported parameter warning
165 static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
166 char *msgname, char *paramname)
169 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
174 * check for legal hex digit
176 static inline int ishexdigit(char c)
178 if (c >= '0' && c <= '9')
180 if (c >= 'A' && c <= 'F')
182 if (c >= 'a' && c <= 'f')
188 * convert hex to binary
190 static inline u8 hex2bin(char c)
192 int result = c & 0x0f;
199 * convert an IE from Gigaset hex string to ETSI binary representation
200 * including length byte
201 * return value: result length, -1 on error
203 static int encode_ie(char *in, u8 *out, int maxlen)
207 if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
209 out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
217 * convert an IE from ETSI binary representation including length byte
218 * to Gigaset hex string
220 static void decode_ie(u8 *in, char *out)
224 /* ToDo: conversion to upper case necessary? */
225 *out++ = toupper(hex_asc_hi(*++in));
226 *out++ = toupper(hex_asc_lo(*in));
231 * retrieve application data structure for an application ID
233 static inline struct gigaset_capi_appl *
234 get_appl(struct gigaset_capi_ctr *iif, u16 appl)
236 struct gigaset_capi_appl *ap;
238 list_for_each_entry(ap, &iif->appls, ctrlist)
245 * dump CAPI message to kernel messages for debugging
247 static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
249 #ifdef CONFIG_GIGASET_DEBUG
252 if (!(gigaset_debuglevel & level))
255 cdb = capi_cmsg2str(p);
257 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
260 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
261 capi_cmd2str(p->Command, p->Subcommand));
266 static inline void dump_rawmsg(enum debuglevel level, const char *tag,
269 #ifdef CONFIG_GIGASET_DEBUG
273 if (!(gigaset_debuglevel & level))
276 l = CAPIMSG_LEN(data);
278 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
281 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
282 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
283 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
284 CAPIMSG_CONTROL(data));
286 dbgline = kmalloc(3*l, GFP_ATOMIC);
289 for (i = 0; i < l; i++) {
290 dbgline[3*i] = hex_asc_hi(data[12+i]);
291 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
292 dbgline[3*i+2] = ' ';
294 dbgline[3*l-1] = '\0';
295 gig_dbg(level, " %s", dbgline);
297 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
298 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
299 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
300 CAPIMSG_DATALEN(data) > 0) {
301 l = CAPIMSG_DATALEN(data);
302 dbgline = kmalloc(3*l, GFP_ATOMIC);
305 data += CAPIMSG_LEN(data);
306 for (i = 0; i < l; i++) {
307 dbgline[3*i] = hex_asc_hi(data[i]);
308 dbgline[3*i+1] = hex_asc_lo(data[i]);
309 dbgline[3*i+2] = ' ';
311 dbgline[3*l-1] = '\0';
312 gig_dbg(level, " %s", dbgline);
319 * format CAPI IE as string
322 static const char *format_ie(const char *ie)
324 static char result[3*MAX_FMT_IE_LEN];
332 if (count > MAX_FMT_IE_LEN)
333 count = MAX_FMT_IE_LEN-1;
335 *pout++ = hex_asc_hi(*++ie);
336 *pout++ = hex_asc_lo(*ie);
339 if (len > MAX_FMT_IE_LEN) {
350 * driver interface functions
351 * ==========================
355 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
356 * @bcs: B channel descriptor structure.
359 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
360 * skb has been successfully sent, for signalling completion to the LL.
362 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
364 struct cardstate *cs = bcs->cs;
365 struct gigaset_capi_ctr *iif = cs->iif;
366 struct gigaset_capi_appl *ap = bcs->ap;
367 unsigned char *req = skb_mac_header(dskb);
368 struct sk_buff *cskb;
371 /* update statistics */
375 dev_err(cs->dev, "%s: no application\n", __func__);
379 /* don't send further B3 messages if disconnected */
380 if (ap->connected < APCONN_ACTIVE) {
381 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
385 /* ToDo: honor unset "delivery confirmation" bit */
386 flags = CAPIMSG_FLAGS(req);
388 /* build DATA_B3_CONF message */
389 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
391 dev_err(cs->dev, "%s: out of memory\n", __func__);
394 /* frequent message, avoid _cmsg overhead */
395 CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
396 CAPIMSG_SETAPPID(cskb->data, ap->id);
397 CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
398 CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
399 CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(req));
400 CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
401 CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
402 CAPIMSG_SETNCCI_PART(cskb->data, 1);
403 CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(req));
404 if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
405 CAPIMSG_SETINFO_CONF(cskb->data,
406 CapiFlagsNotSupportedByProtocol);
408 CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
411 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
412 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
414 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
417 * gigaset_skb_rcvd() - pass received skb to LL
418 * @bcs: B channel descriptor structure.
419 * @skb: received data.
421 * Called by hardware module {bas,ser,usb}_gigaset when user data has
422 * been successfully received, for passing to the LL.
423 * Warning: skb must not be accessed anymore!
425 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
427 struct cardstate *cs = bcs->cs;
428 struct gigaset_capi_ctr *iif = cs->iif;
429 struct gigaset_capi_appl *ap = bcs->ap;
432 /* update statistics */
436 dev_err(cs->dev, "%s: no application\n", __func__);
440 /* don't send further B3 messages if disconnected */
441 if (ap->connected < APCONN_ACTIVE) {
442 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
443 dev_kfree_skb_any(skb);
448 * prepend DATA_B3_IND message to payload
449 * Parameters: NCCI = 1, all others 0/unused
450 * frequent message, avoid _cmsg overhead
452 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
453 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
454 CAPIMSG_SETAPPID(skb->data, ap->id);
455 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
456 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
457 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
458 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
459 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
460 CAPIMSG_SETNCCI_PART(skb->data, 1);
461 /* Data parameter not used */
462 CAPIMSG_SETDATALEN(skb->data, len);
463 /* Data handle parameter not used */
464 CAPIMSG_SETFLAGS(skb->data, 0);
465 /* Data64 parameter not present */
468 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
469 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
471 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
474 * gigaset_isdn_rcv_err() - signal receive error
475 * @bcs: B channel descriptor structure.
477 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
478 * has occurred, for signalling to the LL.
480 void gigaset_isdn_rcv_err(struct bc_state *bcs)
482 /* if currently ignoring packets, just count down */
488 /* update statistics */
491 /* ToDo: signal error -> LL */
493 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
496 * gigaset_isdn_icall() - signal incoming call
497 * @at_state: connection state structure.
499 * Called by main module at tasklet level to notify the LL that an incoming
500 * call has been received. @at_state contains the parameters of the call.
502 * Return value: call disposition (ICALL_*)
504 int gigaset_isdn_icall(struct at_state_t *at_state)
506 struct cardstate *cs = at_state->cs;
507 struct bc_state *bcs = at_state->bcs;
508 struct gigaset_capi_ctr *iif = cs->iif;
509 struct gigaset_capi_appl *ap;
512 unsigned int msgsize;
516 * ToDo: signal calls without a free B channel, too
517 * (requires a u8 handle for the at_state structure that can
518 * be stored in the PLCI and used in the CONNECT_RESP message
519 * handler to retrieve it)
524 /* prepare CONNECT_IND message, using B channel number as PLCI */
525 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
526 iif->ctr.cnr | ((bcs->channel + 1) << 8));
528 /* minimum size, all structs empty */
529 msgsize = CAPI_CONNECT_IND_BASELEN;
531 /* Bearer Capability (mandatory) */
532 if (at_state->str_var[STR_ZBC]) {
533 /* pass on BC from Gigaset */
534 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
535 MAX_BC_OCTETS) < 0) {
536 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
537 at_state->str_var[STR_ZBC]);
541 /* look up corresponding CIP value */
542 iif->hcmsg.CIPValue = 0; /* default if nothing found */
543 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
544 if (cip2bchlc[i].bc != NULL &&
545 cip2bchlc[i].hlc == NULL &&
546 !strcmp(cip2bchlc[i].bc,
547 at_state->str_var[STR_ZBC])) {
548 iif->hcmsg.CIPValue = i;
552 /* no BC (internal call): assume CIP 1 (speech, A-law) */
553 iif->hcmsg.CIPValue = 1;
554 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
556 iif->hcmsg.BC = iif->bc_buf;
557 msgsize += iif->hcmsg.BC[0];
559 /* High Layer Compatibility (optional) */
560 if (at_state->str_var[STR_ZHLC]) {
561 /* pass on HLC from Gigaset */
562 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
563 MAX_HLC_OCTETS) < 0) {
564 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
565 at_state->str_var[STR_ZHLC]);
568 iif->hcmsg.HLC = iif->hlc_buf;
569 msgsize += iif->hcmsg.HLC[0];
571 /* look up corresponding CIP value */
572 /* keep BC based CIP value if none found */
573 if (at_state->str_var[STR_ZBC])
574 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
575 if (cip2bchlc[i].hlc != NULL &&
576 !strcmp(cip2bchlc[i].hlc,
577 at_state->str_var[STR_ZHLC]) &&
578 !strcmp(cip2bchlc[i].bc,
579 at_state->str_var[STR_ZBC])) {
580 iif->hcmsg.CIPValue = i;
585 /* Called Party Number (optional) */
586 if (at_state->str_var[STR_ZCPN]) {
587 i = strlen(at_state->str_var[STR_ZCPN]);
588 if (i > MAX_NUMBER_DIGITS) {
589 dev_warn(cs->dev, "RING ignored - bad number %s\n",
590 at_state->str_var[STR_ZBC]);
593 iif->cdpty_buf[0] = i + 1;
594 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
595 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
596 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
597 msgsize += iif->hcmsg.CalledPartyNumber[0];
600 /* Calling Party Number (optional) */
601 if (at_state->str_var[STR_NMBR]) {
602 i = strlen(at_state->str_var[STR_NMBR]);
603 if (i > MAX_NUMBER_DIGITS) {
604 dev_warn(cs->dev, "RING ignored - bad number %s\n",
605 at_state->str_var[STR_ZBC]);
608 iif->cgpty_buf[0] = i + 2;
609 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
610 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
611 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
612 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
613 msgsize += iif->hcmsg.CallingPartyNumber[0];
616 /* remaining parameters (not supported, always left NULL):
617 * - CalledPartySubaddress
618 * - CallingPartySubaddress
620 * - BChannelinformation
623 * - Facilitydataarray
626 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
627 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
628 format_ie(iif->hcmsg.BC));
629 gig_dbg(DEBUG_CMD, "icall: HLC %s",
630 format_ie(iif->hcmsg.HLC));
631 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
632 format_ie(iif->hcmsg.CallingPartyNumber));
633 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
634 format_ie(iif->hcmsg.CalledPartyNumber));
636 /* scan application list for matching listeners */
638 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
639 list_for_each_entry(ap, &iif->appls, ctrlist)
640 if (actCIPmask & ap->listenCIPmask) {
641 /* build CONNECT_IND message for this application */
642 iif->hcmsg.ApplId = ap->id;
643 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
645 skb = alloc_skb(msgsize, GFP_ATOMIC);
647 dev_err(cs->dev, "%s: out of memory\n",
651 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
652 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
654 /* add to listeners on this B channel, update state */
655 ap->bcnext = bcs->ap;
657 bcs->chstate |= CHS_NOTIFY_LL;
658 ap->connected = APCONN_SETUP;
661 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
665 * Return "accept" if any listeners.
666 * Gigaset will send ALERTING.
667 * There doesn't seem to be a way to avoid this.
669 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
673 * send a DISCONNECT_IND message to an application
674 * does not sleep, clobbers the controller's hcmsg structure
676 static void send_disconnect_ind(struct bc_state *bcs,
677 struct gigaset_capi_appl *ap, u16 reason)
679 struct cardstate *cs = bcs->cs;
680 struct gigaset_capi_ctr *iif = cs->iif;
683 if (ap->connected == APCONN_NONE)
686 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
687 ap->nextMessageNumber++,
688 iif->ctr.cnr | ((bcs->channel + 1) << 8));
689 iif->hcmsg.Reason = reason;
690 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
692 dev_err(cs->dev, "%s: out of memory\n", __func__);
695 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
696 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
697 ap->connected = APCONN_NONE;
698 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
702 * send a DISCONNECT_B3_IND message to an application
703 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
704 * does not sleep, clobbers the controller's hcmsg structure
706 static void send_disconnect_b3_ind(struct bc_state *bcs,
707 struct gigaset_capi_appl *ap)
709 struct cardstate *cs = bcs->cs;
710 struct gigaset_capi_ctr *iif = cs->iif;
713 /* nothing to do if no logical connection active */
714 if (ap->connected < APCONN_ACTIVE)
716 ap->connected = APCONN_SETUP;
718 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
719 ap->nextMessageNumber++,
720 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
721 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
723 dev_err(cs->dev, "%s: out of memory\n", __func__);
726 capi_cmsg2message(&iif->hcmsg,
727 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
728 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
729 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
733 * gigaset_isdn_connD() - signal D channel connect
734 * @bcs: B channel descriptor structure.
736 * Called by main module at tasklet level to notify the LL that the D channel
737 * connection has been established.
739 void gigaset_isdn_connD(struct bc_state *bcs)
741 struct cardstate *cs = bcs->cs;
742 struct gigaset_capi_ctr *iif = cs->iif;
743 struct gigaset_capi_appl *ap = bcs->ap;
745 unsigned int msgsize;
748 dev_err(cs->dev, "%s: no application\n", __func__);
752 /* this should never happen */
753 dev_warn(cs->dev, "%s: dropping extra application %u\n",
754 __func__, ap->bcnext->id);
755 send_disconnect_ind(bcs, ap->bcnext,
756 CapiCallGivenToOtherApplication);
757 ap->bcnext = ap->bcnext->bcnext;
759 if (ap->connected == APCONN_NONE) {
760 dev_warn(cs->dev, "%s: application %u not connected\n",
765 /* prepare CONNECT_ACTIVE_IND message
766 * Note: LLC not supported by device
768 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
769 ap->nextMessageNumber++,
770 iif->ctr.cnr | ((bcs->channel + 1) << 8));
772 /* minimum size, all structs empty */
773 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
775 /* ToDo: set parameter: Connected number
776 * (requires ev-layer state machine extension to collect
780 /* build and emit CONNECT_ACTIVE_IND message */
781 skb = alloc_skb(msgsize, GFP_ATOMIC);
783 dev_err(cs->dev, "%s: out of memory\n", __func__);
786 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
787 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
788 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
792 * gigaset_isdn_hupD() - signal D channel hangup
793 * @bcs: B channel descriptor structure.
795 * Called by main module at tasklet level to notify the LL that the D channel
796 * connection has been shut down.
798 void gigaset_isdn_hupD(struct bc_state *bcs)
800 struct gigaset_capi_appl *ap;
803 * ToDo: pass on reason code reported by device
804 * (requires ev-layer state machine extension to collect
807 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
808 send_disconnect_b3_ind(bcs, ap);
809 send_disconnect_ind(bcs, ap, 0);
815 * gigaset_isdn_connB() - signal B channel connect
816 * @bcs: B channel descriptor structure.
818 * Called by main module at tasklet level to notify the LL that the B channel
819 * connection has been established.
821 void gigaset_isdn_connB(struct bc_state *bcs)
823 struct cardstate *cs = bcs->cs;
824 struct gigaset_capi_ctr *iif = cs->iif;
825 struct gigaset_capi_appl *ap = bcs->ap;
827 unsigned int msgsize;
831 dev_err(cs->dev, "%s: no application\n", __func__);
835 /* this should never happen */
836 dev_warn(cs->dev, "%s: dropping extra application %u\n",
837 __func__, ap->bcnext->id);
838 send_disconnect_ind(bcs, ap->bcnext,
839 CapiCallGivenToOtherApplication);
840 ap->bcnext = ap->bcnext->bcnext;
842 if (!ap->connected) {
843 dev_warn(cs->dev, "%s: application %u not connected\n",
849 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
850 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
851 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
852 * Parameters in both cases always: NCCI = 1, NCPI empty
854 if (ap->connected >= APCONN_ACTIVE) {
855 command = CAPI_CONNECT_B3_ACTIVE;
856 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
858 command = CAPI_CONNECT_B3;
859 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
861 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
862 ap->nextMessageNumber++,
863 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
864 skb = alloc_skb(msgsize, GFP_ATOMIC);
866 dev_err(cs->dev, "%s: out of memory\n", __func__);
869 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
870 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
871 ap->connected = APCONN_ACTIVE;
872 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
876 * gigaset_isdn_hupB() - signal B channel hangup
877 * @bcs: B channel descriptor structure.
879 * Called by main module to notify the LL that the B channel connection has
882 void gigaset_isdn_hupB(struct bc_state *bcs)
884 struct cardstate *cs = bcs->cs;
885 struct gigaset_capi_appl *ap = bcs->ap;
887 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
890 dev_err(cs->dev, "%s: no application\n", __func__);
894 send_disconnect_b3_ind(bcs, ap);
898 * gigaset_isdn_start() - signal device availability
899 * @cs: device descriptor structure.
901 * Called by main module to notify the LL that the device is available for
904 void gigaset_isdn_start(struct cardstate *cs)
906 struct gigaset_capi_ctr *iif = cs->iif;
908 /* fill profile data: manufacturer name */
909 strcpy(iif->ctr.manu, "Siemens");
910 /* CAPI and device version */
911 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
912 iif->ctr.version.minorversion = 0;
913 /* ToDo: check/assert cs->gotfwver? */
914 iif->ctr.version.majormanuversion = cs->fwver[0];
915 iif->ctr.version.minormanuversion = cs->fwver[1];
916 /* number of B channels supported */
917 iif->ctr.profile.nbchannel = cs->channels;
918 /* global options: internal controller, supplementary services */
919 iif->ctr.profile.goptions = 0x11;
920 /* B1 protocols: 64 kbit/s HDLC or transparent */
921 iif->ctr.profile.support1 = 0x03;
922 /* B2 protocols: transparent only */
923 /* ToDo: X.75 SLP ? */
924 iif->ctr.profile.support2 = 0x02;
925 /* B3 protocols: transparent only */
926 iif->ctr.profile.support3 = 0x01;
927 /* no serial number */
928 strcpy(iif->ctr.serial, "0");
929 capi_ctr_ready(&iif->ctr);
933 * gigaset_isdn_stop() - signal device unavailability
934 * @cs: device descriptor structure.
936 * Called by main module to notify the LL that the device is no longer
939 void gigaset_isdn_stop(struct cardstate *cs)
941 struct gigaset_capi_ctr *iif = cs->iif;
942 capi_ctr_down(&iif->ctr);
946 * kernel CAPI callback methods
947 * ============================
953 static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
955 struct cardstate *cs = ctr->driverdata;
957 /* AVM specific operation, not needed for Gigaset -- ignore */
958 dev_notice(cs->dev, "load_firmware ignored\n");
964 * reset (deactivate) controller
966 static void gigaset_reset_ctr(struct capi_ctr *ctr)
968 struct cardstate *cs = ctr->driverdata;
970 /* AVM specific operation, not needed for Gigaset -- ignore */
971 dev_notice(cs->dev, "reset_ctr ignored\n");
975 * register CAPI application
977 static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
978 capi_register_params *rp)
980 struct gigaset_capi_ctr *iif
981 = container_of(ctr, struct gigaset_capi_ctr, ctr);
982 struct cardstate *cs = ctr->driverdata;
983 struct gigaset_capi_appl *ap;
985 list_for_each_entry(ap, &iif->appls, ctrlist)
986 if (ap->id == appl) {
988 "application %u already registered\n", appl);
992 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
994 dev_err(cs->dev, "%s: out of memory\n", __func__);
999 list_add(&ap->ctrlist, &iif->appls);
1003 * release CAPI application
1005 static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
1007 struct gigaset_capi_ctr *iif
1008 = container_of(ctr, struct gigaset_capi_ctr, ctr);
1009 struct cardstate *cs = iif->ctr.driverdata;
1010 struct gigaset_capi_appl *ap, *tmp;
1012 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1013 if (ap->id == appl) {
1014 if (ap->connected != APCONN_NONE) {
1016 "%s: application %u still connected\n",
1018 /* ToDo: clear active connection */
1020 list_del(&ap->ctrlist);
1027 * =====================================================================
1028 * outgoing CAPI message handler
1029 * =====================================================================
1033 * helper function: emit reply message with given Info value
1035 static void send_conf(struct gigaset_capi_ctr *iif,
1036 struct gigaset_capi_appl *ap,
1037 struct sk_buff *skb,
1041 * _CONF replies always only have NCCI and Info parameters
1042 * so they'll fit into the _REQ message skb
1044 capi_cmsg_answer(&iif->acmsg);
1045 iif->acmsg.Info = info;
1046 capi_cmsg2message(&iif->acmsg, skb->data);
1047 __skb_trim(skb, CAPI_STDCONF_LEN);
1048 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1049 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1053 * process FACILITY_REQ message
1055 static void do_facility_req(struct gigaset_capi_ctr *iif,
1056 struct gigaset_capi_appl *ap,
1057 struct sk_buff *skb)
1059 struct cardstate *cs = iif->ctr.driverdata;
1060 _cmsg *cmsg = &iif->acmsg;
1061 struct sk_buff *cskb;
1063 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1065 static u8 confparam[10]; /* max. 9 octets + length byte */
1067 /* decode message */
1068 capi_message2cmsg(cmsg, skb->data);
1069 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1072 * Facility Request Parameter is not decoded by capi_message2cmsg()
1073 * encoding depends on Facility Selector
1075 switch (cmsg->FacilitySelector) {
1076 case CAPI_FACILITY_DTMF: /* ToDo */
1077 info = CapiFacilityNotSupported;
1078 confparam[0] = 2; /* length */
1079 /* DTMF information: Unknown DTMF request */
1080 capimsg_setu16(confparam, 1, 2);
1083 case CAPI_FACILITY_V42BIS: /* not supported */
1084 info = CapiFacilityNotSupported;
1085 confparam[0] = 2; /* length */
1086 /* V.42 bis information: not available */
1087 capimsg_setu16(confparam, 1, 1);
1090 case CAPI_FACILITY_SUPPSVC:
1091 /* decode Function parameter */
1092 pparam = cmsg->FacilityRequestParameter;
1093 if (pparam == NULL || *pparam < 2) {
1094 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1095 "Facility Request Parameter");
1096 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1099 function = CAPIMSG_U16(pparam, 1);
1101 case CAPI_SUPPSVC_GETSUPPORTED:
1103 /* Supplementary Service specific parameter */
1104 confparam[3] = 6; /* length */
1105 /* Supplementary services info: Success */
1106 capimsg_setu16(confparam, 4, CapiSuccess);
1107 /* Supported Services: none */
1108 capimsg_setu32(confparam, 6, 0);
1110 /* ToDo: add supported services */
1112 info = CapiFacilitySpecificFunctionNotSupported;
1113 /* Supplementary Service specific parameter */
1114 confparam[3] = 2; /* length */
1115 /* Supplementary services info: not supported */
1116 capimsg_setu16(confparam, 4,
1117 CapiSupplementaryServiceNotSupported);
1120 /* Facility confirmation parameter */
1121 confparam[0] = confparam[3] + 3; /* total length */
1122 /* Function: copy from _REQ message */
1123 capimsg_setu16(confparam, 1, function);
1124 /* Supplementary Service specific parameter already set above */
1127 case CAPI_FACILITY_WAKEUP: /* ToDo */
1128 info = CapiFacilityNotSupported;
1129 confparam[0] = 2; /* length */
1130 /* Number of accepted awake request parameters: 0 */
1131 capimsg_setu16(confparam, 1, 0);
1135 info = CapiFacilityNotSupported;
1136 confparam[0] = 0; /* empty struct */
1139 /* send FACILITY_CONF with given Info and confirmation parameter */
1140 capi_cmsg_answer(cmsg);
1142 cmsg->FacilityConfirmationParameter = confparam;
1143 msgsize += confparam[0]; /* length */
1144 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1146 dev_err(cs->dev, "%s: out of memory\n", __func__);
1149 capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
1150 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1151 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1156 * process LISTEN_REQ message
1157 * just store the masks in the application data structure
1159 static void do_listen_req(struct gigaset_capi_ctr *iif,
1160 struct gigaset_capi_appl *ap,
1161 struct sk_buff *skb)
1163 /* decode message */
1164 capi_message2cmsg(&iif->acmsg, skb->data);
1165 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1167 /* store listening parameters */
1168 ap->listenInfoMask = iif->acmsg.InfoMask;
1169 ap->listenCIPmask = iif->acmsg.CIPmask;
1170 send_conf(iif, ap, skb, CapiSuccess);
1174 * process ALERT_REQ message
1175 * nothing to do, Gigaset always alerts anyway
1177 static void do_alert_req(struct gigaset_capi_ctr *iif,
1178 struct gigaset_capi_appl *ap,
1179 struct sk_buff *skb)
1181 /* decode message */
1182 capi_message2cmsg(&iif->acmsg, skb->data);
1183 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1184 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1188 * process CONNECT_REQ message
1189 * allocate a B channel, prepare dial commands, queue a DIAL event,
1190 * emit CONNECT_CONF reply
1192 static void do_connect_req(struct gigaset_capi_ctr *iif,
1193 struct gigaset_capi_appl *ap,
1194 struct sk_buff *skb)
1196 struct cardstate *cs = iif->ctr.driverdata;
1197 _cmsg *cmsg = &iif->acmsg;
1198 struct bc_state *bcs;
1205 /* decode message */
1206 capi_message2cmsg(cmsg, skb->data);
1207 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1209 /* get free B channel & construct PLCI */
1210 bcs = gigaset_get_free_channel(cs);
1212 dev_notice(cs->dev, "%s: no B channel available\n",
1214 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1219 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1221 /* build command table */
1222 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1226 /* encode parameter: Called party number */
1227 pp = cmsg->CalledPartyNumber;
1228 if (pp == NULL || *pp == 0) {
1229 dev_notice(cs->dev, "%s: %s missing\n",
1230 "CONNECT_REQ", "Called party number");
1231 info = CapiIllMessageParmCoding;
1235 /* check type of number/numbering plan byte */
1237 case 0x80: /* unknown type / unknown numbering plan */
1238 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1240 default: /* others: warn about potential misinterpretation */
1241 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1242 "CONNECT_REQ", "Called party number", *pp);
1246 /* translate "**" internal call prefix to CTP value */
1247 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1254 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1255 if (!commands[AT_TYPE])
1257 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1258 if (!commands[AT_DIAL])
1260 snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
1262 /* encode parameter: Calling party number */
1263 pp = cmsg->CallingPartyNumber;
1264 if (pp != NULL && *pp > 0) {
1267 /* check type of number/numbering plan byte */
1268 /* ToDo: allow for/handle Ext=1? */
1270 case 0x00: /* unknown type / unknown numbering plan */
1271 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1275 "%s: %s type/plan 0x%02x unsupported\n",
1276 "CONNECT_REQ", "Calling party number", *pp);
1281 /* check presentation indicator */
1283 dev_notice(cs->dev, "%s: %s IE truncated\n",
1284 "CONNECT_REQ", "Calling party number");
1285 info = CapiIllMessageParmCoding;
1288 switch (*pp & 0xfc) { /* ignore Screening indicator */
1289 case 0x80: /* Presentation allowed */
1292 case 0xa0: /* Presentation restricted */
1296 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1298 "Presentation/Screening indicator",
1302 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1303 if (!commands[AT_CLIP])
1310 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1311 if (!commands[AT_MSN])
1313 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1317 /* check parameter: CIP Value */
1318 if (cmsg->CIPValue > ARRAY_SIZE(cip2bchlc) ||
1319 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1320 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1321 "CONNECT_REQ", cmsg->CIPValue);
1322 info = CapiCipValueUnknown;
1326 /* check/encode parameter: BC */
1327 if (cmsg->BC && cmsg->BC[0]) {
1328 /* explicit BC overrides CIP */
1329 l = 2*cmsg->BC[0] + 7;
1330 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1331 if (!commands[AT_BC])
1333 strcpy(commands[AT_BC], "^SBC=");
1334 decode_ie(cmsg->BC, commands[AT_BC]+5);
1335 strcpy(commands[AT_BC] + l - 2, "\r");
1336 } else if (cip2bchlc[cmsg->CIPValue].bc) {
1337 l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
1338 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1339 if (!commands[AT_BC])
1341 snprintf(commands[AT_BC], l, "^SBC=%s\r",
1342 cip2bchlc[cmsg->CIPValue].bc);
1345 /* check/encode parameter: HLC */
1346 if (cmsg->HLC && cmsg->HLC[0]) {
1347 /* explicit HLC overrides CIP */
1348 l = 2*cmsg->HLC[0] + 7;
1349 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1350 if (!commands[AT_HLC])
1352 strcpy(commands[AT_HLC], "^SHLC=");
1353 decode_ie(cmsg->HLC, commands[AT_HLC]+5);
1354 strcpy(commands[AT_HLC] + l - 2, "\r");
1355 } else if (cip2bchlc[cmsg->CIPValue].hlc) {
1356 l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
1357 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1358 if (!commands[AT_HLC])
1360 snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
1361 cip2bchlc[cmsg->CIPValue].hlc);
1364 /* check/encode parameter: B Protocol */
1365 if (cmsg->BProtocol == CAPI_DEFAULT) {
1366 bcs->proto2 = L2_HDLC;
1368 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1370 switch (cmsg->B1protocol) {
1372 bcs->proto2 = L2_HDLC;
1375 bcs->proto2 = L2_BITSYNC;
1379 "B1 Protocol %u unsupported, using Transparent\n",
1381 bcs->proto2 = L2_BITSYNC;
1383 if (cmsg->B2protocol != 1)
1385 "B2 Protocol %u unsupported, using Transparent\n",
1387 if (cmsg->B3protocol != 0)
1389 "B3 Protocol %u unsupported, using Transparent\n",
1391 ignore_cstruct_param(cs, cmsg->B1configuration,
1392 "CONNECT_REQ", "B1 Configuration");
1393 ignore_cstruct_param(cs, cmsg->B2configuration,
1394 "CONNECT_REQ", "B2 Configuration");
1395 ignore_cstruct_param(cs, cmsg->B3configuration,
1396 "CONNECT_REQ", "B3 Configuration");
1398 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1399 if (!commands[AT_PROTO])
1401 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1403 /* ToDo: check/encode remaining parameters */
1404 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1405 "CONNECT_REQ", "Called pty subaddr");
1406 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1407 "CONNECT_REQ", "Calling pty subaddr");
1408 ignore_cstruct_param(cs, cmsg->LLC,
1409 "CONNECT_REQ", "LLC");
1410 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1411 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1412 "CONNECT_REQ", "B Channel Information");
1413 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1414 "CONNECT_REQ", "Keypad Facility");
1415 ignore_cstruct_param(cs, cmsg->Useruserdata,
1416 "CONNECT_REQ", "User-User Data");
1417 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1418 "CONNECT_REQ", "Facility Data Array");
1421 /* encode parameter: B channel to use */
1422 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1423 if (!commands[AT_ISO])
1425 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1426 (unsigned) bcs->channel + 1);
1428 /* queue & schedule EV_DIAL event */
1429 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1430 bcs->at_state.seq_index, NULL))
1432 gig_dbg(DEBUG_CMD, "scheduling DIAL");
1433 gigaset_schedule_event(cs);
1434 ap->connected = APCONN_SETUP;
1435 send_conf(iif, ap, skb, CapiSuccess);
1439 dev_err(cs->dev, "%s: out of memory\n", __func__);
1440 info = CAPI_MSGOSRESOURCEERR;
1443 for (i = 0; i < AT_NUM; i++)
1446 gigaset_free_channel(bcs);
1447 send_conf(iif, ap, skb, info);
1451 * process CONNECT_RESP message
1452 * checks protocol parameters and queues an ACCEPT or HUP event
1454 static void do_connect_resp(struct gigaset_capi_ctr *iif,
1455 struct gigaset_capi_appl *ap,
1456 struct sk_buff *skb)
1458 struct cardstate *cs = iif->ctr.driverdata;
1459 _cmsg *cmsg = &iif->acmsg;
1460 struct bc_state *bcs;
1461 struct gigaset_capi_appl *oap;
1464 /* decode message */
1465 capi_message2cmsg(cmsg, skb->data);
1466 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1467 dev_kfree_skb_any(skb);
1469 /* extract and check channel number from PLCI */
1470 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1471 if (!channel || channel > cs->channels) {
1472 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1473 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1476 bcs = cs->bcs + channel - 1;
1478 switch (cmsg->Reject) {
1479 case 0: /* Accept */
1480 /* drop all competing applications, keep only this one */
1481 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1483 send_disconnect_ind(bcs, oap,
1484 CapiCallGivenToOtherApplication);
1487 bcs->chstate |= CHS_NOTIFY_LL;
1489 /* check/encode B channel protocol */
1490 if (cmsg->BProtocol == CAPI_DEFAULT) {
1491 bcs->proto2 = L2_HDLC;
1493 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1495 switch (cmsg->B1protocol) {
1497 bcs->proto2 = L2_HDLC;
1500 bcs->proto2 = L2_BITSYNC;
1504 "B1 Protocol %u unsupported, using Transparent\n",
1506 bcs->proto2 = L2_BITSYNC;
1508 if (cmsg->B2protocol != 1)
1510 "B2 Protocol %u unsupported, using Transparent\n",
1512 if (cmsg->B3protocol != 0)
1514 "B3 Protocol %u unsupported, using Transparent\n",
1516 ignore_cstruct_param(cs, cmsg->B1configuration,
1517 "CONNECT_RESP", "B1 Configuration");
1518 ignore_cstruct_param(cs, cmsg->B2configuration,
1519 "CONNECT_RESP", "B2 Configuration");
1520 ignore_cstruct_param(cs, cmsg->B3configuration,
1521 "CONNECT_RESP", "B3 Configuration");
1524 /* ToDo: check/encode remaining parameters */
1525 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1526 "CONNECT_RESP", "Connected Number");
1527 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1528 "CONNECT_RESP", "Connected Subaddress");
1529 ignore_cstruct_param(cs, cmsg->LLC,
1530 "CONNECT_RESP", "LLC");
1531 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1532 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1533 "CONNECT_RESP", "BChannel Information");
1534 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1535 "CONNECT_RESP", "Keypad Facility");
1536 ignore_cstruct_param(cs, cmsg->Useruserdata,
1537 "CONNECT_RESP", "User-User Data");
1538 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1539 "CONNECT_RESP", "Facility Data Array");
1543 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1544 EV_ACCEPT, NULL, 0, NULL))
1546 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
1547 gigaset_schedule_event(cs);
1550 case 1: /* Ignore */
1551 /* send DISCONNECT_IND to this application */
1552 send_disconnect_ind(bcs, ap, 0);
1554 /* remove it from the list of listening apps */
1555 if (bcs->ap == ap) {
1556 bcs->ap = ap->bcnext;
1557 if (bcs->ap == NULL)
1558 /* last one: stop ev-layer hupD notifications */
1559 bcs->chstate &= ~CHS_NOTIFY_LL;
1562 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1563 if (oap->bcnext == ap) {
1564 oap->bcnext = oap->bcnext->bcnext;
1568 dev_err(cs->dev, "%s: application %u not found\n",
1572 default: /* Reject */
1573 /* drop all competing applications, keep only this one */
1574 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1576 send_disconnect_ind(bcs, oap,
1577 CapiCallGivenToOtherApplication);
1581 /* reject call - will trigger DISCONNECT_IND for this app */
1582 dev_info(cs->dev, "%s: Reject=%x\n",
1583 "CONNECT_RESP", cmsg->Reject);
1584 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1585 EV_HUP, NULL, 0, NULL))
1587 gig_dbg(DEBUG_CMD, "scheduling HUP");
1588 gigaset_schedule_event(cs);
1594 * process CONNECT_B3_REQ message
1595 * build NCCI and emit CONNECT_B3_CONF reply
1597 static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1598 struct gigaset_capi_appl *ap,
1599 struct sk_buff *skb)
1601 struct cardstate *cs = iif->ctr.driverdata;
1602 _cmsg *cmsg = &iif->acmsg;
1605 /* decode message */
1606 capi_message2cmsg(cmsg, skb->data);
1607 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1609 /* extract and check channel number from PLCI */
1610 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1611 if (!channel || channel > cs->channels) {
1612 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1613 "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
1614 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1618 /* mark logical connection active */
1619 ap->connected = APCONN_ACTIVE;
1621 /* build NCCI: always 1 (one B3 connection only) */
1622 cmsg->adr.adrNCCI |= 1 << 16;
1624 /* NCPI parameter: not applicable for B3 Transparent */
1625 ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
1626 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1627 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1631 * process CONNECT_B3_RESP message
1632 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1633 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1634 * The emitted message is always shorter than the received one,
1635 * allowing to reuse the skb.
1637 static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1638 struct gigaset_capi_appl *ap,
1639 struct sk_buff *skb)
1641 struct cardstate *cs = iif->ctr.driverdata;
1642 _cmsg *cmsg = &iif->acmsg;
1643 struct bc_state *bcs;
1645 unsigned int msgsize;
1648 /* decode message */
1649 capi_message2cmsg(cmsg, skb->data);
1650 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1652 /* extract and check channel number and NCCI */
1653 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1654 if (!channel || channel > cs->channels ||
1655 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1656 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1657 "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
1658 dev_kfree_skb_any(skb);
1661 bcs = &cs->bcs[channel-1];
1664 /* Reject: clear B3 connect received flag */
1665 ap->connected = APCONN_SETUP;
1667 /* trigger hangup, causing eventual DISCONNECT_IND */
1668 if (!gigaset_add_event(cs, &bcs->at_state,
1669 EV_HUP, NULL, 0, NULL)) {
1670 dev_err(cs->dev, "%s: out of memory\n", __func__);
1671 dev_kfree_skb_any(skb);
1674 gig_dbg(DEBUG_CMD, "scheduling HUP");
1675 gigaset_schedule_event(cs);
1677 /* emit DISCONNECT_B3_IND */
1678 command = CAPI_DISCONNECT_B3;
1679 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1682 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1683 * we only send CONNECT_B3_IND if the B channel is up
1685 command = CAPI_CONNECT_B3_ACTIVE;
1686 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1688 capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
1689 ap->nextMessageNumber++, cmsg->adr.adrNCCI);
1690 __skb_trim(skb, msgsize);
1691 capi_cmsg2message(cmsg, skb->data);
1692 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1693 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1697 * process DISCONNECT_REQ message
1698 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1699 * emit DISCONNECT_CONF reply
1701 static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1702 struct gigaset_capi_appl *ap,
1703 struct sk_buff *skb)
1705 struct cardstate *cs = iif->ctr.driverdata;
1706 _cmsg *cmsg = &iif->acmsg;
1707 struct bc_state *bcs;
1709 struct sk_buff *b3skb;
1712 /* decode message */
1713 capi_message2cmsg(cmsg, skb->data);
1714 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1716 /* extract and check channel number from PLCI */
1717 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1718 if (!channel || channel > cs->channels) {
1719 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1720 "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
1721 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1724 bcs = cs->bcs + channel - 1;
1726 /* ToDo: process parameter: Additional info */
1727 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1728 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1729 "DISCONNECT_REQ", "B Channel Information");
1730 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1731 "DISCONNECT_REQ", "Keypad Facility");
1732 ignore_cstruct_param(cs, cmsg->Useruserdata,
1733 "DISCONNECT_REQ", "User-User Data");
1734 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1735 "DISCONNECT_REQ", "Facility Data Array");
1738 /* skip if DISCONNECT_IND already sent */
1742 /* check for active logical connection */
1743 if (ap->connected >= APCONN_ACTIVE) {
1745 * emit DISCONNECT_B3_IND with cause 0x3301
1746 * use separate cmsg structure, as the content of iif->acmsg
1747 * is still needed for creating the _CONF message
1749 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1751 dev_err(cs->dev, "%s: out of memory\n", __func__);
1752 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1755 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1756 ap->nextMessageNumber++,
1757 cmsg->adr.adrPLCI | (1 << 16));
1758 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1759 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1760 if (b3skb == NULL) {
1761 dev_err(cs->dev, "%s: out of memory\n", __func__);
1762 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1765 capi_cmsg2message(b3cmsg,
1766 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1768 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1771 /* trigger hangup, causing eventual DISCONNECT_IND */
1772 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1773 dev_err(cs->dev, "%s: out of memory\n", __func__);
1774 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1777 gig_dbg(DEBUG_CMD, "scheduling HUP");
1778 gigaset_schedule_event(cs);
1781 send_conf(iif, ap, skb, CapiSuccess);
1785 * process DISCONNECT_B3_REQ message
1786 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1788 static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1789 struct gigaset_capi_appl *ap,
1790 struct sk_buff *skb)
1792 struct cardstate *cs = iif->ctr.driverdata;
1793 _cmsg *cmsg = &iif->acmsg;
1796 /* decode message */
1797 capi_message2cmsg(cmsg, skb->data);
1798 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1800 /* extract and check channel number and NCCI */
1801 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1802 if (!channel || channel > cs->channels ||
1803 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1804 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1805 "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
1806 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1810 /* reject if logical connection not active */
1811 if (ap->connected < APCONN_ACTIVE) {
1812 send_conf(iif, ap, skb,
1813 CapiMessageNotSupportedInCurrentState);
1817 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1818 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1819 EV_HUP, NULL, 0, NULL)) {
1820 dev_err(cs->dev, "%s: out of memory\n", __func__);
1821 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1824 gig_dbg(DEBUG_CMD, "scheduling HUP");
1825 gigaset_schedule_event(cs);
1827 /* NCPI parameter: not applicable for B3 Transparent */
1828 ignore_cstruct_param(cs, cmsg->NCPI,
1829 "DISCONNECT_B3_REQ", "NCPI");
1830 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1831 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1835 * process DATA_B3_REQ message
1837 static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1838 struct gigaset_capi_appl *ap,
1839 struct sk_buff *skb)
1841 struct cardstate *cs = iif->ctr.driverdata;
1842 int channel = CAPIMSG_PLCI_PART(skb->data);
1843 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1844 u16 msglen = CAPIMSG_LEN(skb->data);
1845 u16 datalen = CAPIMSG_DATALEN(skb->data);
1846 u16 flags = CAPIMSG_FLAGS(skb->data);
1848 /* frequent message, avoid _cmsg overhead */
1849 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1851 gig_dbg(DEBUG_LLDATA,
1852 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1853 channel, flags, msglen, datalen);
1855 /* check parameters */
1856 if (channel == 0 || channel > cs->channels || ncci != 1) {
1857 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1858 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1859 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1862 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1863 dev_notice(cs->dev, "%s: unexpected length %d\n",
1864 "DATA_B3_REQ", msglen);
1865 if (msglen + datalen != skb->len)
1866 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1867 "DATA_B3_REQ", msglen, datalen, skb->len);
1868 if (msglen + datalen > skb->len) {
1869 /* message too short for announced data length */
1870 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1873 if (flags & CAPI_FLAGS_RESERVED) {
1874 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1875 "DATA_B3_REQ", flags);
1876 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1880 /* reject if logical connection not active */
1881 if (ap->connected < APCONN_ACTIVE) {
1882 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1886 /* pull CAPI message into link layer header */
1887 skb_reset_mac_header(skb);
1888 skb->mac_len = msglen;
1889 skb_pull(skb, msglen);
1891 /* pass to device-specific module */
1892 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1893 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1897 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1900 * ToDo: honor unset "delivery confirmation" bit
1901 * (send DATA_B3_CONF immediately?)
1906 * process RESET_B3_REQ message
1907 * just always reply "not supported by current protocol"
1909 static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1910 struct gigaset_capi_appl *ap,
1911 struct sk_buff *skb)
1913 /* decode message */
1914 capi_message2cmsg(&iif->acmsg, skb->data);
1915 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1916 send_conf(iif, ap, skb,
1917 CapiResetProcedureNotSupportedByCurrentProtocol);
1921 * dump unsupported/ignored messages at most twice per minute,
1922 * some apps send those very frequently
1924 static unsigned long ignored_msg_dump_time;
1927 * unsupported CAPI message handler
1929 static void do_unsupported(struct gigaset_capi_ctr *iif,
1930 struct gigaset_capi_appl *ap,
1931 struct sk_buff *skb)
1933 /* decode message */
1934 capi_message2cmsg(&iif->acmsg, skb->data);
1935 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1936 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1937 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1941 * CAPI message handler: no-op
1943 static void do_nothing(struct gigaset_capi_ctr *iif,
1944 struct gigaset_capi_appl *ap,
1945 struct sk_buff *skb)
1947 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1948 /* decode message */
1949 capi_message2cmsg(&iif->acmsg, skb->data);
1950 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1952 dev_kfree_skb_any(skb);
1955 static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1956 struct gigaset_capi_appl *ap,
1957 struct sk_buff *skb)
1959 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1960 dev_kfree_skb_any(skb);
1963 /* table of outgoing CAPI message handlers with lookup function */
1964 typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1965 struct gigaset_capi_appl *,
1970 capi_send_handler_t handler;
1971 } capi_send_handler_table[] = {
1972 /* most frequent messages first for faster lookup */
1973 { CAPI_DATA_B3_REQ, do_data_b3_req },
1974 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1976 { CAPI_ALERT_REQ, do_alert_req },
1977 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1978 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1979 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1980 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1981 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1982 { CAPI_CONNECT_REQ, do_connect_req },
1983 { CAPI_CONNECT_RESP, do_connect_resp },
1984 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1985 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1986 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1987 { CAPI_DISCONNECT_RESP, do_nothing },
1988 { CAPI_FACILITY_REQ, do_facility_req },
1989 { CAPI_FACILITY_RESP, do_nothing },
1990 { CAPI_LISTEN_REQ, do_listen_req },
1991 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1992 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1993 { CAPI_RESET_B3_RESP, do_nothing },
1996 * ToDo: support overlap sending (requires ev-layer state
1997 * machine extension to generate additional ATD commands)
1999 { CAPI_INFO_REQ, do_unsupported },
2000 { CAPI_INFO_RESP, do_nothing },
2003 * ToDo: what's the proper response for these?
2005 { CAPI_MANUFACTURER_REQ, do_nothing },
2006 { CAPI_MANUFACTURER_RESP, do_nothing },
2009 /* look up handler */
2010 static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
2014 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
2015 if (capi_send_handler_table[i].cmd == cmd)
2016 return capi_send_handler_table[i].handler;
2022 * gigaset_send_message() - accept a CAPI message from an application
2023 * @ctr: controller descriptor structure.
2024 * @skb: CAPI message.
2026 * Return value: CAPI error code
2027 * Note: capidrv (and probably others, too) only uses the return value to
2028 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2030 static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2032 struct gigaset_capi_ctr *iif
2033 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2034 struct cardstate *cs = ctr->driverdata;
2035 struct gigaset_capi_appl *ap;
2036 capi_send_handler_t handler;
2038 /* can only handle linear sk_buffs */
2039 if (skb_linearize(skb) < 0) {
2040 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2041 return CAPI_MSGOSRESOURCEERR;
2044 /* retrieve application data structure */
2045 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2047 dev_notice(cs->dev, "%s: application %u not registered\n",
2048 __func__, CAPIMSG_APPID(skb->data));
2049 return CAPI_ILLAPPNR;
2052 /* look up command */
2053 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2055 /* unknown/unsupported message type */
2056 if (printk_ratelimit())
2057 dev_notice(cs->dev, "%s: unsupported message %u\n",
2058 __func__, CAPIMSG_CMD(skb->data));
2059 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2063 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2064 /* queue behind other messages */
2065 skb_queue_tail(&iif->sendqueue, skb);
2066 return CAPI_NOERROR;
2069 /* process message */
2070 handler(iif, ap, skb);
2072 /* process other messages arrived in the meantime */
2073 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2074 skb = skb_dequeue(&iif->sendqueue);
2076 /* should never happen */
2077 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2080 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2082 /* could that happen? */
2083 dev_warn(cs->dev, "%s: application %u vanished\n",
2084 __func__, CAPIMSG_APPID(skb->data));
2087 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2089 /* should never happen */
2090 dev_err(cs->dev, "%s: handler %x vanished\n",
2091 __func__, CAPIMSG_CMD(skb->data));
2094 handler(iif, ap, skb);
2097 return CAPI_NOERROR;
2101 * gigaset_procinfo() - build single line description for controller
2102 * @ctr: controller descriptor structure.
2104 * Return value: pointer to generated string (null terminated)
2106 static char *gigaset_procinfo(struct capi_ctr *ctr)
2108 return ctr->name; /* ToDo: more? */
2111 static int gigaset_proc_show(struct seq_file *m, void *v)
2113 struct capi_ctr *ctr = m->private;
2114 struct cardstate *cs = ctr->driverdata;
2118 seq_printf(m, "%-16s %s\n", "name", ctr->name);
2119 seq_printf(m, "%-16s %s %s\n", "dev",
2120 dev_driver_string(cs->dev), dev_name(cs->dev));
2121 seq_printf(m, "%-16s %d\n", "id", cs->myid);
2123 seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
2124 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2125 seq_printf(m, "%-16s %d\n", "channels", cs->channels);
2126 seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
2144 seq_printf(m, "%-16s %s\n", "mode", s);
2146 switch (cs->mstate) {
2147 case MS_UNINITIALIZED:
2148 s = "uninitialized";
2168 seq_printf(m, "%-16s %s\n", "mstate", s);
2170 seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
2171 seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
2172 seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
2173 seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
2175 for (i = 0; i < cs->channels; i++) {
2176 seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
2177 cs->bcs[i].corrupted);
2178 seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
2179 cs->bcs[i].trans_down);
2180 seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
2181 cs->bcs[i].trans_up);
2182 seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
2183 cs->bcs[i].chstate);
2184 switch (cs->bcs[i].proto2) {
2197 seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
2202 static int gigaset_proc_open(struct inode *inode, struct file *file)
2204 return single_open(file, gigaset_proc_show, PDE(inode)->data);
2207 static const struct file_operations gigaset_proc_fops = {
2208 .owner = THIS_MODULE,
2209 .open = gigaset_proc_open,
2211 .llseek = seq_lseek,
2212 .release = single_release,
2215 static struct capi_driver capi_driver_gigaset = {
2221 * gigaset_isdn_register() - register to LL
2222 * @cs: device descriptor structure.
2223 * @isdnid: device name.
2225 * Called by main module to register the device with the LL.
2227 * Return value: 1 for success, 0 for failure
2229 int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
2231 struct gigaset_capi_ctr *iif;
2234 pr_info("Kernel CAPI interface\n");
2236 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2238 pr_err("%s: out of memory\n", __func__);
2242 /* register driver with CAPI (ToDo: what for?) */
2243 register_capi_driver(&capi_driver_gigaset);
2245 /* prepare controller structure */
2246 iif->ctr.owner = THIS_MODULE;
2247 iif->ctr.driverdata = cs;
2248 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2249 iif->ctr.driver_name = "gigaset";
2250 iif->ctr.load_firmware = gigaset_load_firmware;
2251 iif->ctr.reset_ctr = gigaset_reset_ctr;
2252 iif->ctr.register_appl = gigaset_register_appl;
2253 iif->ctr.release_appl = gigaset_release_appl;
2254 iif->ctr.send_message = gigaset_send_message;
2255 iif->ctr.procinfo = gigaset_procinfo;
2256 iif->ctr.proc_fops = &gigaset_proc_fops;
2257 INIT_LIST_HEAD(&iif->appls);
2258 skb_queue_head_init(&iif->sendqueue);
2259 atomic_set(&iif->sendqlen, 0);
2261 /* register controller with CAPI */
2262 rc = attach_capi_ctr(&iif->ctr);
2264 pr_err("attach_capi_ctr failed (%d)\n", rc);
2265 unregister_capi_driver(&capi_driver_gigaset);
2271 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2276 * gigaset_isdn_unregister() - unregister from LL
2277 * @cs: device descriptor structure.
2279 * Called by main module to unregister the device from the LL.
2281 void gigaset_isdn_unregister(struct cardstate *cs)
2283 struct gigaset_capi_ctr *iif = cs->iif;
2285 detach_capi_ctr(&iif->ctr);
2288 unregister_capi_driver(&capi_driver_gigaset);