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/slab.h>
16 #include <linux/ctype.h>
17 #include <linux/proc_fs.h>
18 #include <linux/seq_file.h>
19 #include <linux/isdn/capilli.h>
20 #include <linux/isdn/capicmd.h>
21 #include <linux/isdn/capiutil.h>
23 /* missing from kernelcapi.h */
24 #define CapiNcpiNotSupportedByProtocol 0x0001
25 #define CapiFlagsNotSupportedByProtocol 0x0002
26 #define CapiAlertAlreadySent 0x0003
27 #define CapiFacilitySpecificFunctionNotSupported 0x3011
29 /* missing from capicmd.h */
30 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
31 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
32 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
33 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
34 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
35 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
36 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
37 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
38 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
39 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
40 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
42 #define CAPI_FACILITY_HANDSET 0x0000
43 #define CAPI_FACILITY_DTMF 0x0001
44 #define CAPI_FACILITY_V42BIS 0x0002
45 #define CAPI_FACILITY_SUPPSVC 0x0003
46 #define CAPI_FACILITY_WAKEUP 0x0004
47 #define CAPI_FACILITY_LI 0x0005
49 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
51 /* missing from capiutil.h */
52 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
53 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
54 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
55 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
56 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
57 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
58 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
59 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
61 /* parameters with differing location in DATA_B3_CONF/_RESP: */
62 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
63 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
65 /* Flags (DATA_B3_REQ/_IND) */
66 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
67 #define CAPI_FLAGS_RESERVED (~0x1f)
70 #define MAX_BC_OCTETS 11
71 #define MAX_HLC_OCTETS 3
72 #define MAX_NUMBER_DIGITS 20
73 #define MAX_FMT_IE_LEN 20
75 /* values for gigaset_capi_appl.connected */
76 #define APCONN_NONE 0 /* inactive/listening */
77 #define APCONN_SETUP 1 /* connecting */
78 #define APCONN_ACTIVE 2 /* B channel up */
80 /* registered application data structure */
81 struct gigaset_capi_appl {
82 struct list_head ctrlist;
83 struct gigaset_capi_appl *bcnext;
85 u16 nextMessageNumber;
91 /* CAPI specific controller data structure */
92 struct gigaset_capi_ctr {
94 struct list_head appls;
95 struct sk_buff_head sendqueue;
97 /* two _cmsg structures possibly used concurrently: */
98 _cmsg hcmsg; /* for message composition triggered from hardware */
99 _cmsg acmsg; /* for dissection of messages sent from application */
100 u8 bc_buf[MAX_BC_OCTETS+1];
101 u8 hlc_buf[MAX_HLC_OCTETS+1];
102 u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
103 u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
106 /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
111 [1] = { "8090A3", NULL },
113 [2] = { "8890", NULL },
114 /* Unrestricted digital information */
115 [3] = { "8990", NULL },
116 /* Restricted digital information */
117 [4] = { "9090A3", NULL },
118 /* 3,1 kHz audio (A-law) */
119 [5] = { "9190", NULL },
121 [6] = { "9890", NULL },
123 [7] = { "88C0C6E6", NULL },
125 [8] = { "8890218F", NULL },
126 /* 56 kbit/s rate adaptation */
127 [9] = { "9190A5", NULL },
128 /* Unrestricted digital information with tones/announcements */
129 [16] = { "8090A3", "9181" },
131 [17] = { "9090A3", "9184" },
132 /* Group 2/3 facsimile */
133 [18] = { "8890", "91A1" },
134 /* Group 4 facsimile Class 1 */
135 [19] = { "8890", "91A4" },
136 /* Teletex service basic and mixed mode
137 and Group 4 facsimile service Classes II and III */
138 [20] = { "8890", "91A8" },
139 /* Teletex service basic and processable mode */
140 [21] = { "8890", "91B1" },
141 /* Teletex service basic mode */
142 [22] = { "8890", "91B2" },
143 /* International interworking for Videotex */
144 [23] = { "8890", "91B5" },
146 [24] = { "8890", "91B8" },
147 /* Message Handling Systems in accordance with X.400 */
148 [25] = { "8890", "91C1" },
149 /* OSI application in accordance with X.200 */
150 [26] = { "9190A5", "9181" },
151 /* 7 kHz telephony */
152 [27] = { "9190A5", "916001" },
153 /* Video telephony, first connection */
154 [28] = { "8890", "916002" },
155 /* Video telephony, second connection */
164 * emit unsupported parameter warning
166 static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
167 char *msgname, char *paramname)
170 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
175 * convert hex to binary
177 static inline u8 hex2bin(char c)
179 int result = c & 0x0f;
186 * convert an IE from Gigaset hex string to ETSI binary representation
187 * including length byte
188 * return value: result length, -1 on error
190 static int encode_ie(char *in, u8 *out, int maxlen)
194 if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
196 out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
204 * convert an IE from ETSI binary representation including length byte
205 * to Gigaset hex string
207 static void decode_ie(u8 *in, char *out)
211 /* ToDo: conversion to upper case necessary? */
212 *out++ = toupper(hex_asc_hi(*++in));
213 *out++ = toupper(hex_asc_lo(*in));
218 * retrieve application data structure for an application ID
220 static inline struct gigaset_capi_appl *
221 get_appl(struct gigaset_capi_ctr *iif, u16 appl)
223 struct gigaset_capi_appl *ap;
225 list_for_each_entry(ap, &iif->appls, ctrlist)
232 * dump CAPI message to kernel messages for debugging
234 static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
236 #ifdef CONFIG_GIGASET_DEBUG
239 if (!(gigaset_debuglevel & level))
242 cdb = capi_cmsg2str(p);
244 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
247 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
248 capi_cmd2str(p->Command, p->Subcommand));
253 static inline void dump_rawmsg(enum debuglevel level, const char *tag,
256 #ifdef CONFIG_GIGASET_DEBUG
260 if (!(gigaset_debuglevel & level))
263 l = CAPIMSG_LEN(data);
265 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
268 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
269 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
270 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
271 CAPIMSG_CONTROL(data));
273 dbgline = kmalloc(3*l, GFP_ATOMIC);
276 for (i = 0; i < l; i++) {
277 dbgline[3*i] = hex_asc_hi(data[12+i]);
278 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
279 dbgline[3*i+2] = ' ';
281 dbgline[3*l-1] = '\0';
282 gig_dbg(level, " %s", dbgline);
284 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
285 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
286 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
287 CAPIMSG_DATALEN(data) > 0) {
288 l = CAPIMSG_DATALEN(data);
289 dbgline = kmalloc(3*l, GFP_ATOMIC);
292 data += CAPIMSG_LEN(data);
293 for (i = 0; i < l; i++) {
294 dbgline[3*i] = hex_asc_hi(data[i]);
295 dbgline[3*i+1] = hex_asc_lo(data[i]);
296 dbgline[3*i+2] = ' ';
298 dbgline[3*l-1] = '\0';
299 gig_dbg(level, " %s", dbgline);
306 * format CAPI IE as string
309 static const char *format_ie(const char *ie)
311 static char result[3*MAX_FMT_IE_LEN];
319 if (count > MAX_FMT_IE_LEN)
320 count = MAX_FMT_IE_LEN-1;
322 *pout++ = hex_asc_hi(*++ie);
323 *pout++ = hex_asc_lo(*ie);
326 if (len > MAX_FMT_IE_LEN) {
337 * driver interface functions
338 * ==========================
342 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
343 * @bcs: B channel descriptor structure.
346 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
347 * skb has been successfully sent, for signalling completion to the LL.
349 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
351 struct cardstate *cs = bcs->cs;
352 struct gigaset_capi_ctr *iif = cs->iif;
353 struct gigaset_capi_appl *ap = bcs->ap;
354 unsigned char *req = skb_mac_header(dskb);
355 struct sk_buff *cskb;
358 /* update statistics */
362 dev_err(cs->dev, "%s: no application\n", __func__);
366 /* don't send further B3 messages if disconnected */
367 if (ap->connected < APCONN_ACTIVE) {
368 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
372 /* ToDo: honor unset "delivery confirmation" bit */
373 flags = CAPIMSG_FLAGS(req);
375 /* build DATA_B3_CONF message */
376 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
378 dev_err(cs->dev, "%s: out of memory\n", __func__);
381 /* frequent message, avoid _cmsg overhead */
382 CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
383 CAPIMSG_SETAPPID(cskb->data, ap->id);
384 CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
385 CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
386 CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(req));
387 CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
388 CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
389 CAPIMSG_SETNCCI_PART(cskb->data, 1);
390 CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(req));
391 if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
392 CAPIMSG_SETINFO_CONF(cskb->data,
393 CapiFlagsNotSupportedByProtocol);
395 CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
398 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
399 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
401 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
404 * gigaset_skb_rcvd() - pass received skb to LL
405 * @bcs: B channel descriptor structure.
406 * @skb: received data.
408 * Called by hardware module {bas,ser,usb}_gigaset when user data has
409 * been successfully received, for passing to the LL.
410 * Warning: skb must not be accessed anymore!
412 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
414 struct cardstate *cs = bcs->cs;
415 struct gigaset_capi_ctr *iif = cs->iif;
416 struct gigaset_capi_appl *ap = bcs->ap;
419 /* update statistics */
423 dev_err(cs->dev, "%s: no application\n", __func__);
427 /* don't send further B3 messages if disconnected */
428 if (ap->connected < APCONN_ACTIVE) {
429 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
430 dev_kfree_skb_any(skb);
435 * prepend DATA_B3_IND message to payload
436 * Parameters: NCCI = 1, all others 0/unused
437 * frequent message, avoid _cmsg overhead
439 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
440 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
441 CAPIMSG_SETAPPID(skb->data, ap->id);
442 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
443 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
444 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
445 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
446 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
447 CAPIMSG_SETNCCI_PART(skb->data, 1);
448 /* Data parameter not used */
449 CAPIMSG_SETDATALEN(skb->data, len);
450 /* Data handle parameter not used */
451 CAPIMSG_SETFLAGS(skb->data, 0);
452 /* Data64 parameter not present */
455 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
456 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
458 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
461 * gigaset_isdn_rcv_err() - signal receive error
462 * @bcs: B channel descriptor structure.
464 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
465 * has occurred, for signalling to the LL.
467 void gigaset_isdn_rcv_err(struct bc_state *bcs)
469 /* if currently ignoring packets, just count down */
475 /* update statistics */
478 /* ToDo: signal error -> LL */
480 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
483 * gigaset_isdn_icall() - signal incoming call
484 * @at_state: connection state structure.
486 * Called by main module at tasklet level to notify the LL that an incoming
487 * call has been received. @at_state contains the parameters of the call.
489 * Return value: call disposition (ICALL_*)
491 int gigaset_isdn_icall(struct at_state_t *at_state)
493 struct cardstate *cs = at_state->cs;
494 struct bc_state *bcs = at_state->bcs;
495 struct gigaset_capi_ctr *iif = cs->iif;
496 struct gigaset_capi_appl *ap;
499 unsigned int msgsize;
503 * ToDo: signal calls without a free B channel, too
504 * (requires a u8 handle for the at_state structure that can
505 * be stored in the PLCI and used in the CONNECT_RESP message
506 * handler to retrieve it)
511 /* prepare CONNECT_IND message, using B channel number as PLCI */
512 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
513 iif->ctr.cnr | ((bcs->channel + 1) << 8));
515 /* minimum size, all structs empty */
516 msgsize = CAPI_CONNECT_IND_BASELEN;
518 /* Bearer Capability (mandatory) */
519 if (at_state->str_var[STR_ZBC]) {
520 /* pass on BC from Gigaset */
521 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
522 MAX_BC_OCTETS) < 0) {
523 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
524 at_state->str_var[STR_ZBC]);
528 /* look up corresponding CIP value */
529 iif->hcmsg.CIPValue = 0; /* default if nothing found */
530 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
531 if (cip2bchlc[i].bc != NULL &&
532 cip2bchlc[i].hlc == NULL &&
533 !strcmp(cip2bchlc[i].bc,
534 at_state->str_var[STR_ZBC])) {
535 iif->hcmsg.CIPValue = i;
539 /* no BC (internal call): assume CIP 1 (speech, A-law) */
540 iif->hcmsg.CIPValue = 1;
541 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
543 iif->hcmsg.BC = iif->bc_buf;
544 msgsize += iif->hcmsg.BC[0];
546 /* High Layer Compatibility (optional) */
547 if (at_state->str_var[STR_ZHLC]) {
548 /* pass on HLC from Gigaset */
549 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
550 MAX_HLC_OCTETS) < 0) {
551 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
552 at_state->str_var[STR_ZHLC]);
555 iif->hcmsg.HLC = iif->hlc_buf;
556 msgsize += iif->hcmsg.HLC[0];
558 /* look up corresponding CIP value */
559 /* keep BC based CIP value if none found */
560 if (at_state->str_var[STR_ZBC])
561 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
562 if (cip2bchlc[i].hlc != NULL &&
563 !strcmp(cip2bchlc[i].hlc,
564 at_state->str_var[STR_ZHLC]) &&
565 !strcmp(cip2bchlc[i].bc,
566 at_state->str_var[STR_ZBC])) {
567 iif->hcmsg.CIPValue = i;
572 /* Called Party Number (optional) */
573 if (at_state->str_var[STR_ZCPN]) {
574 i = strlen(at_state->str_var[STR_ZCPN]);
575 if (i > MAX_NUMBER_DIGITS) {
576 dev_warn(cs->dev, "RING ignored - bad number %s\n",
577 at_state->str_var[STR_ZBC]);
580 iif->cdpty_buf[0] = i + 1;
581 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
582 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
583 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
584 msgsize += iif->hcmsg.CalledPartyNumber[0];
587 /* Calling Party Number (optional) */
588 if (at_state->str_var[STR_NMBR]) {
589 i = strlen(at_state->str_var[STR_NMBR]);
590 if (i > MAX_NUMBER_DIGITS) {
591 dev_warn(cs->dev, "RING ignored - bad number %s\n",
592 at_state->str_var[STR_ZBC]);
595 iif->cgpty_buf[0] = i + 2;
596 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
597 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
598 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
599 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
600 msgsize += iif->hcmsg.CallingPartyNumber[0];
603 /* remaining parameters (not supported, always left NULL):
604 * - CalledPartySubaddress
605 * - CallingPartySubaddress
607 * - BChannelinformation
610 * - Facilitydataarray
613 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
614 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
615 format_ie(iif->hcmsg.BC));
616 gig_dbg(DEBUG_CMD, "icall: HLC %s",
617 format_ie(iif->hcmsg.HLC));
618 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
619 format_ie(iif->hcmsg.CallingPartyNumber));
620 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
621 format_ie(iif->hcmsg.CalledPartyNumber));
623 /* scan application list for matching listeners */
625 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
626 list_for_each_entry(ap, &iif->appls, ctrlist)
627 if (actCIPmask & ap->listenCIPmask) {
628 /* build CONNECT_IND message for this application */
629 iif->hcmsg.ApplId = ap->id;
630 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
632 skb = alloc_skb(msgsize, GFP_ATOMIC);
634 dev_err(cs->dev, "%s: out of memory\n",
638 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
639 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
641 /* add to listeners on this B channel, update state */
642 ap->bcnext = bcs->ap;
644 bcs->chstate |= CHS_NOTIFY_LL;
645 ap->connected = APCONN_SETUP;
648 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
652 * Return "accept" if any listeners.
653 * Gigaset will send ALERTING.
654 * There doesn't seem to be a way to avoid this.
656 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
660 * send a DISCONNECT_IND message to an application
661 * does not sleep, clobbers the controller's hcmsg structure
663 static void send_disconnect_ind(struct bc_state *bcs,
664 struct gigaset_capi_appl *ap, u16 reason)
666 struct cardstate *cs = bcs->cs;
667 struct gigaset_capi_ctr *iif = cs->iif;
670 if (ap->connected == APCONN_NONE)
673 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
674 ap->nextMessageNumber++,
675 iif->ctr.cnr | ((bcs->channel + 1) << 8));
676 iif->hcmsg.Reason = reason;
677 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
679 dev_err(cs->dev, "%s: out of memory\n", __func__);
682 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
683 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
684 ap->connected = APCONN_NONE;
685 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
689 * send a DISCONNECT_B3_IND message to an application
690 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
691 * does not sleep, clobbers the controller's hcmsg structure
693 static void send_disconnect_b3_ind(struct bc_state *bcs,
694 struct gigaset_capi_appl *ap)
696 struct cardstate *cs = bcs->cs;
697 struct gigaset_capi_ctr *iif = cs->iif;
700 /* nothing to do if no logical connection active */
701 if (ap->connected < APCONN_ACTIVE)
703 ap->connected = APCONN_SETUP;
705 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
706 ap->nextMessageNumber++,
707 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
708 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
710 dev_err(cs->dev, "%s: out of memory\n", __func__);
713 capi_cmsg2message(&iif->hcmsg,
714 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
715 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
716 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
720 * gigaset_isdn_connD() - signal D channel connect
721 * @bcs: B channel descriptor structure.
723 * Called by main module at tasklet level to notify the LL that the D channel
724 * connection has been established.
726 void gigaset_isdn_connD(struct bc_state *bcs)
728 struct cardstate *cs = bcs->cs;
729 struct gigaset_capi_ctr *iif = cs->iif;
730 struct gigaset_capi_appl *ap = bcs->ap;
732 unsigned int msgsize;
735 dev_err(cs->dev, "%s: no application\n", __func__);
739 /* this should never happen */
740 dev_warn(cs->dev, "%s: dropping extra application %u\n",
741 __func__, ap->bcnext->id);
742 send_disconnect_ind(bcs, ap->bcnext,
743 CapiCallGivenToOtherApplication);
744 ap->bcnext = ap->bcnext->bcnext;
746 if (ap->connected == APCONN_NONE) {
747 dev_warn(cs->dev, "%s: application %u not connected\n",
752 /* prepare CONNECT_ACTIVE_IND message
753 * Note: LLC not supported by device
755 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
756 ap->nextMessageNumber++,
757 iif->ctr.cnr | ((bcs->channel + 1) << 8));
759 /* minimum size, all structs empty */
760 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
762 /* ToDo: set parameter: Connected number
763 * (requires ev-layer state machine extension to collect
767 /* build and emit CONNECT_ACTIVE_IND message */
768 skb = alloc_skb(msgsize, GFP_ATOMIC);
770 dev_err(cs->dev, "%s: out of memory\n", __func__);
773 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
774 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
775 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
779 * gigaset_isdn_hupD() - signal D channel hangup
780 * @bcs: B channel descriptor structure.
782 * Called by main module at tasklet level to notify the LL that the D channel
783 * connection has been shut down.
785 void gigaset_isdn_hupD(struct bc_state *bcs)
787 struct gigaset_capi_appl *ap;
790 * ToDo: pass on reason code reported by device
791 * (requires ev-layer state machine extension to collect
794 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
795 send_disconnect_b3_ind(bcs, ap);
796 send_disconnect_ind(bcs, ap, 0);
802 * gigaset_isdn_connB() - signal B channel connect
803 * @bcs: B channel descriptor structure.
805 * Called by main module at tasklet level to notify the LL that the B channel
806 * connection has been established.
808 void gigaset_isdn_connB(struct bc_state *bcs)
810 struct cardstate *cs = bcs->cs;
811 struct gigaset_capi_ctr *iif = cs->iif;
812 struct gigaset_capi_appl *ap = bcs->ap;
814 unsigned int msgsize;
818 dev_err(cs->dev, "%s: no application\n", __func__);
822 /* this should never happen */
823 dev_warn(cs->dev, "%s: dropping extra application %u\n",
824 __func__, ap->bcnext->id);
825 send_disconnect_ind(bcs, ap->bcnext,
826 CapiCallGivenToOtherApplication);
827 ap->bcnext = ap->bcnext->bcnext;
829 if (!ap->connected) {
830 dev_warn(cs->dev, "%s: application %u not connected\n",
836 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
837 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
838 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
839 * Parameters in both cases always: NCCI = 1, NCPI empty
841 if (ap->connected >= APCONN_ACTIVE) {
842 command = CAPI_CONNECT_B3_ACTIVE;
843 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
845 command = CAPI_CONNECT_B3;
846 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
848 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
849 ap->nextMessageNumber++,
850 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
851 skb = alloc_skb(msgsize, GFP_ATOMIC);
853 dev_err(cs->dev, "%s: out of memory\n", __func__);
856 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
857 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
858 ap->connected = APCONN_ACTIVE;
859 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
863 * gigaset_isdn_hupB() - signal B channel hangup
864 * @bcs: B channel descriptor structure.
866 * Called by main module to notify the LL that the B channel connection has
869 void gigaset_isdn_hupB(struct bc_state *bcs)
871 struct cardstate *cs = bcs->cs;
872 struct gigaset_capi_appl *ap = bcs->ap;
874 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
877 dev_err(cs->dev, "%s: no application\n", __func__);
881 send_disconnect_b3_ind(bcs, ap);
885 * gigaset_isdn_start() - signal device availability
886 * @cs: device descriptor structure.
888 * Called by main module to notify the LL that the device is available for
891 void gigaset_isdn_start(struct cardstate *cs)
893 struct gigaset_capi_ctr *iif = cs->iif;
895 /* fill profile data: manufacturer name */
896 strcpy(iif->ctr.manu, "Siemens");
897 /* CAPI and device version */
898 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
899 iif->ctr.version.minorversion = 0;
900 /* ToDo: check/assert cs->gotfwver? */
901 iif->ctr.version.majormanuversion = cs->fwver[0];
902 iif->ctr.version.minormanuversion = cs->fwver[1];
903 /* number of B channels supported */
904 iif->ctr.profile.nbchannel = cs->channels;
905 /* global options: internal controller, supplementary services */
906 iif->ctr.profile.goptions = 0x11;
907 /* B1 protocols: 64 kbit/s HDLC or transparent */
908 iif->ctr.profile.support1 = 0x03;
909 /* B2 protocols: transparent only */
910 /* ToDo: X.75 SLP ? */
911 iif->ctr.profile.support2 = 0x02;
912 /* B3 protocols: transparent only */
913 iif->ctr.profile.support3 = 0x01;
914 /* no serial number */
915 strcpy(iif->ctr.serial, "0");
916 capi_ctr_ready(&iif->ctr);
920 * gigaset_isdn_stop() - signal device unavailability
921 * @cs: device descriptor structure.
923 * Called by main module to notify the LL that the device is no longer
926 void gigaset_isdn_stop(struct cardstate *cs)
928 struct gigaset_capi_ctr *iif = cs->iif;
929 capi_ctr_down(&iif->ctr);
933 * kernel CAPI callback methods
934 * ============================
940 static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
942 struct cardstate *cs = ctr->driverdata;
944 /* AVM specific operation, not needed for Gigaset -- ignore */
945 dev_notice(cs->dev, "load_firmware ignored\n");
951 * reset (deactivate) controller
953 static void gigaset_reset_ctr(struct capi_ctr *ctr)
955 struct cardstate *cs = ctr->driverdata;
957 /* AVM specific operation, not needed for Gigaset -- ignore */
958 dev_notice(cs->dev, "reset_ctr ignored\n");
962 * register CAPI application
964 static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
965 capi_register_params *rp)
967 struct gigaset_capi_ctr *iif
968 = container_of(ctr, struct gigaset_capi_ctr, ctr);
969 struct cardstate *cs = ctr->driverdata;
970 struct gigaset_capi_appl *ap;
972 list_for_each_entry(ap, &iif->appls, ctrlist)
973 if (ap->id == appl) {
975 "application %u already registered\n", appl);
979 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
981 dev_err(cs->dev, "%s: out of memory\n", __func__);
986 list_add(&ap->ctrlist, &iif->appls);
990 * release CAPI application
992 static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
994 struct gigaset_capi_ctr *iif
995 = container_of(ctr, struct gigaset_capi_ctr, ctr);
996 struct cardstate *cs = iif->ctr.driverdata;
997 struct gigaset_capi_appl *ap, *tmp;
999 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1000 if (ap->id == appl) {
1001 if (ap->connected != APCONN_NONE) {
1003 "%s: application %u still connected\n",
1005 /* ToDo: clear active connection */
1007 list_del(&ap->ctrlist);
1014 * =====================================================================
1015 * outgoing CAPI message handler
1016 * =====================================================================
1020 * helper function: emit reply message with given Info value
1022 static void send_conf(struct gigaset_capi_ctr *iif,
1023 struct gigaset_capi_appl *ap,
1024 struct sk_buff *skb,
1028 * _CONF replies always only have NCCI and Info parameters
1029 * so they'll fit into the _REQ message skb
1031 capi_cmsg_answer(&iif->acmsg);
1032 iif->acmsg.Info = info;
1033 capi_cmsg2message(&iif->acmsg, skb->data);
1034 __skb_trim(skb, CAPI_STDCONF_LEN);
1035 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1036 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1040 * process FACILITY_REQ message
1042 static void do_facility_req(struct gigaset_capi_ctr *iif,
1043 struct gigaset_capi_appl *ap,
1044 struct sk_buff *skb)
1046 struct cardstate *cs = iif->ctr.driverdata;
1047 _cmsg *cmsg = &iif->acmsg;
1048 struct sk_buff *cskb;
1050 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1052 static u8 confparam[10]; /* max. 9 octets + length byte */
1054 /* decode message */
1055 capi_message2cmsg(cmsg, skb->data);
1056 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1059 * Facility Request Parameter is not decoded by capi_message2cmsg()
1060 * encoding depends on Facility Selector
1062 switch (cmsg->FacilitySelector) {
1063 case CAPI_FACILITY_DTMF: /* ToDo */
1064 info = CapiFacilityNotSupported;
1065 confparam[0] = 2; /* length */
1066 /* DTMF information: Unknown DTMF request */
1067 capimsg_setu16(confparam, 1, 2);
1070 case CAPI_FACILITY_V42BIS: /* not supported */
1071 info = CapiFacilityNotSupported;
1072 confparam[0] = 2; /* length */
1073 /* V.42 bis information: not available */
1074 capimsg_setu16(confparam, 1, 1);
1077 case CAPI_FACILITY_SUPPSVC:
1078 /* decode Function parameter */
1079 pparam = cmsg->FacilityRequestParameter;
1080 if (pparam == NULL || *pparam < 2) {
1081 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1082 "Facility Request Parameter");
1083 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1086 function = CAPIMSG_U16(pparam, 1);
1088 case CAPI_SUPPSVC_GETSUPPORTED:
1090 /* Supplementary Service specific parameter */
1091 confparam[3] = 6; /* length */
1092 /* Supplementary services info: Success */
1093 capimsg_setu16(confparam, 4, CapiSuccess);
1094 /* Supported Services: none */
1095 capimsg_setu32(confparam, 6, 0);
1097 /* ToDo: add supported services */
1099 info = CapiFacilitySpecificFunctionNotSupported;
1100 /* Supplementary Service specific parameter */
1101 confparam[3] = 2; /* length */
1102 /* Supplementary services info: not supported */
1103 capimsg_setu16(confparam, 4,
1104 CapiSupplementaryServiceNotSupported);
1107 /* Facility confirmation parameter */
1108 confparam[0] = confparam[3] + 3; /* total length */
1109 /* Function: copy from _REQ message */
1110 capimsg_setu16(confparam, 1, function);
1111 /* Supplementary Service specific parameter already set above */
1114 case CAPI_FACILITY_WAKEUP: /* ToDo */
1115 info = CapiFacilityNotSupported;
1116 confparam[0] = 2; /* length */
1117 /* Number of accepted awake request parameters: 0 */
1118 capimsg_setu16(confparam, 1, 0);
1122 info = CapiFacilityNotSupported;
1123 confparam[0] = 0; /* empty struct */
1126 /* send FACILITY_CONF with given Info and confirmation parameter */
1127 capi_cmsg_answer(cmsg);
1129 cmsg->FacilityConfirmationParameter = confparam;
1130 msgsize += confparam[0]; /* length */
1131 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1133 dev_err(cs->dev, "%s: out of memory\n", __func__);
1136 capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
1137 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1138 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1143 * process LISTEN_REQ message
1144 * just store the masks in the application data structure
1146 static void do_listen_req(struct gigaset_capi_ctr *iif,
1147 struct gigaset_capi_appl *ap,
1148 struct sk_buff *skb)
1150 /* decode message */
1151 capi_message2cmsg(&iif->acmsg, skb->data);
1152 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1154 /* store listening parameters */
1155 ap->listenInfoMask = iif->acmsg.InfoMask;
1156 ap->listenCIPmask = iif->acmsg.CIPmask;
1157 send_conf(iif, ap, skb, CapiSuccess);
1161 * process ALERT_REQ message
1162 * nothing to do, Gigaset always alerts anyway
1164 static void do_alert_req(struct gigaset_capi_ctr *iif,
1165 struct gigaset_capi_appl *ap,
1166 struct sk_buff *skb)
1168 /* decode message */
1169 capi_message2cmsg(&iif->acmsg, skb->data);
1170 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1171 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1175 * process CONNECT_REQ message
1176 * allocate a B channel, prepare dial commands, queue a DIAL event,
1177 * emit CONNECT_CONF reply
1179 static void do_connect_req(struct gigaset_capi_ctr *iif,
1180 struct gigaset_capi_appl *ap,
1181 struct sk_buff *skb)
1183 struct cardstate *cs = iif->ctr.driverdata;
1184 _cmsg *cmsg = &iif->acmsg;
1185 struct bc_state *bcs;
1192 /* decode message */
1193 capi_message2cmsg(cmsg, skb->data);
1194 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1196 /* get free B channel & construct PLCI */
1197 bcs = gigaset_get_free_channel(cs);
1199 dev_notice(cs->dev, "%s: no B channel available\n",
1201 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1206 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1208 /* build command table */
1209 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1213 /* encode parameter: Called party number */
1214 pp = cmsg->CalledPartyNumber;
1215 if (pp == NULL || *pp == 0) {
1216 dev_notice(cs->dev, "%s: %s missing\n",
1217 "CONNECT_REQ", "Called party number");
1218 info = CapiIllMessageParmCoding;
1222 /* check type of number/numbering plan byte */
1224 case 0x80: /* unknown type / unknown numbering plan */
1225 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1227 default: /* others: warn about potential misinterpretation */
1228 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1229 "CONNECT_REQ", "Called party number", *pp);
1233 /* translate "**" internal call prefix to CTP value */
1234 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1241 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1242 if (!commands[AT_TYPE])
1244 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1245 if (!commands[AT_DIAL])
1247 snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
1249 /* encode parameter: Calling party number */
1250 pp = cmsg->CallingPartyNumber;
1251 if (pp != NULL && *pp > 0) {
1254 /* check type of number/numbering plan byte */
1255 /* ToDo: allow for/handle Ext=1? */
1257 case 0x00: /* unknown type / unknown numbering plan */
1258 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1262 "%s: %s type/plan 0x%02x unsupported\n",
1263 "CONNECT_REQ", "Calling party number", *pp);
1268 /* check presentation indicator */
1270 dev_notice(cs->dev, "%s: %s IE truncated\n",
1271 "CONNECT_REQ", "Calling party number");
1272 info = CapiIllMessageParmCoding;
1275 switch (*pp & 0xfc) { /* ignore Screening indicator */
1276 case 0x80: /* Presentation allowed */
1279 case 0xa0: /* Presentation restricted */
1283 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1285 "Presentation/Screening indicator",
1289 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1290 if (!commands[AT_CLIP])
1297 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1298 if (!commands[AT_MSN])
1300 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1304 /* check parameter: CIP Value */
1305 if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
1306 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1307 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1308 "CONNECT_REQ", cmsg->CIPValue);
1309 info = CapiCipValueUnknown;
1313 /* check/encode parameter: BC */
1314 if (cmsg->BC && cmsg->BC[0]) {
1315 /* explicit BC overrides CIP */
1316 l = 2*cmsg->BC[0] + 7;
1317 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1318 if (!commands[AT_BC])
1320 strcpy(commands[AT_BC], "^SBC=");
1321 decode_ie(cmsg->BC, commands[AT_BC]+5);
1322 strcpy(commands[AT_BC] + l - 2, "\r");
1323 } else if (cip2bchlc[cmsg->CIPValue].bc) {
1324 l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
1325 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1326 if (!commands[AT_BC])
1328 snprintf(commands[AT_BC], l, "^SBC=%s\r",
1329 cip2bchlc[cmsg->CIPValue].bc);
1332 /* check/encode parameter: HLC */
1333 if (cmsg->HLC && cmsg->HLC[0]) {
1334 /* explicit HLC overrides CIP */
1335 l = 2*cmsg->HLC[0] + 7;
1336 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1337 if (!commands[AT_HLC])
1339 strcpy(commands[AT_HLC], "^SHLC=");
1340 decode_ie(cmsg->HLC, commands[AT_HLC]+5);
1341 strcpy(commands[AT_HLC] + l - 2, "\r");
1342 } else if (cip2bchlc[cmsg->CIPValue].hlc) {
1343 l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
1344 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1345 if (!commands[AT_HLC])
1347 snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
1348 cip2bchlc[cmsg->CIPValue].hlc);
1351 /* check/encode parameter: B Protocol */
1352 if (cmsg->BProtocol == CAPI_DEFAULT) {
1353 bcs->proto2 = L2_HDLC;
1355 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1357 switch (cmsg->B1protocol) {
1359 bcs->proto2 = L2_HDLC;
1362 bcs->proto2 = L2_BITSYNC;
1366 "B1 Protocol %u unsupported, using Transparent\n",
1368 bcs->proto2 = L2_BITSYNC;
1370 if (cmsg->B2protocol != 1)
1372 "B2 Protocol %u unsupported, using Transparent\n",
1374 if (cmsg->B3protocol != 0)
1376 "B3 Protocol %u unsupported, using Transparent\n",
1378 ignore_cstruct_param(cs, cmsg->B1configuration,
1379 "CONNECT_REQ", "B1 Configuration");
1380 ignore_cstruct_param(cs, cmsg->B2configuration,
1381 "CONNECT_REQ", "B2 Configuration");
1382 ignore_cstruct_param(cs, cmsg->B3configuration,
1383 "CONNECT_REQ", "B3 Configuration");
1385 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1386 if (!commands[AT_PROTO])
1388 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1390 /* ToDo: check/encode remaining parameters */
1391 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1392 "CONNECT_REQ", "Called pty subaddr");
1393 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1394 "CONNECT_REQ", "Calling pty subaddr");
1395 ignore_cstruct_param(cs, cmsg->LLC,
1396 "CONNECT_REQ", "LLC");
1397 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1398 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1399 "CONNECT_REQ", "B Channel Information");
1400 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1401 "CONNECT_REQ", "Keypad Facility");
1402 ignore_cstruct_param(cs, cmsg->Useruserdata,
1403 "CONNECT_REQ", "User-User Data");
1404 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1405 "CONNECT_REQ", "Facility Data Array");
1408 /* encode parameter: B channel to use */
1409 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1410 if (!commands[AT_ISO])
1412 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1413 (unsigned) bcs->channel + 1);
1415 /* queue & schedule EV_DIAL event */
1416 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1417 bcs->at_state.seq_index, NULL)) {
1418 info = CAPI_MSGOSRESOURCEERR;
1421 gigaset_schedule_event(cs);
1422 ap->connected = APCONN_SETUP;
1423 send_conf(iif, ap, skb, CapiSuccess);
1427 dev_err(cs->dev, "%s: out of memory\n", __func__);
1428 info = CAPI_MSGOSRESOURCEERR;
1431 for (i = 0; i < AT_NUM; i++)
1434 gigaset_free_channel(bcs);
1435 send_conf(iif, ap, skb, info);
1439 * process CONNECT_RESP message
1440 * checks protocol parameters and queues an ACCEPT or HUP event
1442 static void do_connect_resp(struct gigaset_capi_ctr *iif,
1443 struct gigaset_capi_appl *ap,
1444 struct sk_buff *skb)
1446 struct cardstate *cs = iif->ctr.driverdata;
1447 _cmsg *cmsg = &iif->acmsg;
1448 struct bc_state *bcs;
1449 struct gigaset_capi_appl *oap;
1452 /* decode message */
1453 capi_message2cmsg(cmsg, skb->data);
1454 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1455 dev_kfree_skb_any(skb);
1457 /* extract and check channel number from PLCI */
1458 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1459 if (!channel || channel > cs->channels) {
1460 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1461 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1464 bcs = cs->bcs + channel - 1;
1466 switch (cmsg->Reject) {
1467 case 0: /* Accept */
1468 /* drop all competing applications, keep only this one */
1469 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1471 send_disconnect_ind(bcs, oap,
1472 CapiCallGivenToOtherApplication);
1475 bcs->chstate |= CHS_NOTIFY_LL;
1477 /* check/encode B channel protocol */
1478 if (cmsg->BProtocol == CAPI_DEFAULT) {
1479 bcs->proto2 = L2_HDLC;
1481 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1483 switch (cmsg->B1protocol) {
1485 bcs->proto2 = L2_HDLC;
1488 bcs->proto2 = L2_BITSYNC;
1492 "B1 Protocol %u unsupported, using Transparent\n",
1494 bcs->proto2 = L2_BITSYNC;
1496 if (cmsg->B2protocol != 1)
1498 "B2 Protocol %u unsupported, using Transparent\n",
1500 if (cmsg->B3protocol != 0)
1502 "B3 Protocol %u unsupported, using Transparent\n",
1504 ignore_cstruct_param(cs, cmsg->B1configuration,
1505 "CONNECT_RESP", "B1 Configuration");
1506 ignore_cstruct_param(cs, cmsg->B2configuration,
1507 "CONNECT_RESP", "B2 Configuration");
1508 ignore_cstruct_param(cs, cmsg->B3configuration,
1509 "CONNECT_RESP", "B3 Configuration");
1512 /* ToDo: check/encode remaining parameters */
1513 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1514 "CONNECT_RESP", "Connected Number");
1515 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1516 "CONNECT_RESP", "Connected Subaddress");
1517 ignore_cstruct_param(cs, cmsg->LLC,
1518 "CONNECT_RESP", "LLC");
1519 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1520 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1521 "CONNECT_RESP", "BChannel Information");
1522 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1523 "CONNECT_RESP", "Keypad Facility");
1524 ignore_cstruct_param(cs, cmsg->Useruserdata,
1525 "CONNECT_RESP", "User-User Data");
1526 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1527 "CONNECT_RESP", "Facility Data Array");
1531 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1532 EV_ACCEPT, NULL, 0, NULL))
1534 gigaset_schedule_event(cs);
1537 case 1: /* Ignore */
1538 /* send DISCONNECT_IND to this application */
1539 send_disconnect_ind(bcs, ap, 0);
1541 /* remove it from the list of listening apps */
1542 if (bcs->ap == ap) {
1543 bcs->ap = ap->bcnext;
1544 if (bcs->ap == NULL)
1545 /* last one: stop ev-layer hupD notifications */
1546 bcs->chstate &= ~CHS_NOTIFY_LL;
1549 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1550 if (oap->bcnext == ap) {
1551 oap->bcnext = oap->bcnext->bcnext;
1555 dev_err(cs->dev, "%s: application %u not found\n",
1559 default: /* Reject */
1560 /* drop all competing applications, keep only this one */
1561 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1563 send_disconnect_ind(bcs, oap,
1564 CapiCallGivenToOtherApplication);
1568 /* reject call - will trigger DISCONNECT_IND for this app */
1569 dev_info(cs->dev, "%s: Reject=%x\n",
1570 "CONNECT_RESP", cmsg->Reject);
1571 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1572 EV_HUP, NULL, 0, NULL))
1574 gigaset_schedule_event(cs);
1580 * process CONNECT_B3_REQ message
1581 * build NCCI and emit CONNECT_B3_CONF reply
1583 static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1584 struct gigaset_capi_appl *ap,
1585 struct sk_buff *skb)
1587 struct cardstate *cs = iif->ctr.driverdata;
1588 _cmsg *cmsg = &iif->acmsg;
1591 /* decode message */
1592 capi_message2cmsg(cmsg, skb->data);
1593 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1595 /* extract and check channel number from PLCI */
1596 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1597 if (!channel || channel > cs->channels) {
1598 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1599 "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
1600 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1604 /* mark logical connection active */
1605 ap->connected = APCONN_ACTIVE;
1607 /* build NCCI: always 1 (one B3 connection only) */
1608 cmsg->adr.adrNCCI |= 1 << 16;
1610 /* NCPI parameter: not applicable for B3 Transparent */
1611 ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
1612 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1613 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1617 * process CONNECT_B3_RESP message
1618 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1619 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1620 * The emitted message is always shorter than the received one,
1621 * allowing to reuse the skb.
1623 static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1624 struct gigaset_capi_appl *ap,
1625 struct sk_buff *skb)
1627 struct cardstate *cs = iif->ctr.driverdata;
1628 _cmsg *cmsg = &iif->acmsg;
1629 struct bc_state *bcs;
1631 unsigned int msgsize;
1634 /* decode message */
1635 capi_message2cmsg(cmsg, skb->data);
1636 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1638 /* extract and check channel number and NCCI */
1639 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1640 if (!channel || channel > cs->channels ||
1641 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1642 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1643 "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
1644 dev_kfree_skb_any(skb);
1647 bcs = &cs->bcs[channel-1];
1650 /* Reject: clear B3 connect received flag */
1651 ap->connected = APCONN_SETUP;
1653 /* trigger hangup, causing eventual DISCONNECT_IND */
1654 if (!gigaset_add_event(cs, &bcs->at_state,
1655 EV_HUP, NULL, 0, NULL)) {
1656 dev_kfree_skb_any(skb);
1659 gigaset_schedule_event(cs);
1661 /* emit DISCONNECT_B3_IND */
1662 command = CAPI_DISCONNECT_B3;
1663 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1666 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1667 * we only send CONNECT_B3_IND if the B channel is up
1669 command = CAPI_CONNECT_B3_ACTIVE;
1670 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1672 capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
1673 ap->nextMessageNumber++, cmsg->adr.adrNCCI);
1674 __skb_trim(skb, msgsize);
1675 capi_cmsg2message(cmsg, skb->data);
1676 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1677 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1681 * process DISCONNECT_REQ message
1682 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1683 * emit DISCONNECT_CONF reply
1685 static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1686 struct gigaset_capi_appl *ap,
1687 struct sk_buff *skb)
1689 struct cardstate *cs = iif->ctr.driverdata;
1690 _cmsg *cmsg = &iif->acmsg;
1691 struct bc_state *bcs;
1693 struct sk_buff *b3skb;
1696 /* decode message */
1697 capi_message2cmsg(cmsg, skb->data);
1698 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1700 /* extract and check channel number from PLCI */
1701 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1702 if (!channel || channel > cs->channels) {
1703 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1704 "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
1705 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1708 bcs = cs->bcs + channel - 1;
1710 /* ToDo: process parameter: Additional info */
1711 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1712 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1713 "DISCONNECT_REQ", "B Channel Information");
1714 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1715 "DISCONNECT_REQ", "Keypad Facility");
1716 ignore_cstruct_param(cs, cmsg->Useruserdata,
1717 "DISCONNECT_REQ", "User-User Data");
1718 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1719 "DISCONNECT_REQ", "Facility Data Array");
1722 /* skip if DISCONNECT_IND already sent */
1726 /* check for active logical connection */
1727 if (ap->connected >= APCONN_ACTIVE) {
1729 * emit DISCONNECT_B3_IND with cause 0x3301
1730 * use separate cmsg structure, as the content of iif->acmsg
1731 * is still needed for creating the _CONF message
1733 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1735 dev_err(cs->dev, "%s: out of memory\n", __func__);
1736 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1739 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1740 ap->nextMessageNumber++,
1741 cmsg->adr.adrPLCI | (1 << 16));
1742 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1743 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1744 if (b3skb == NULL) {
1745 dev_err(cs->dev, "%s: out of memory\n", __func__);
1746 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1749 capi_cmsg2message(b3cmsg,
1750 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1752 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1755 /* trigger hangup, causing eventual DISCONNECT_IND */
1756 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1757 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1760 gigaset_schedule_event(cs);
1763 send_conf(iif, ap, skb, CapiSuccess);
1767 * process DISCONNECT_B3_REQ message
1768 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1770 static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1771 struct gigaset_capi_appl *ap,
1772 struct sk_buff *skb)
1774 struct cardstate *cs = iif->ctr.driverdata;
1775 _cmsg *cmsg = &iif->acmsg;
1778 /* decode message */
1779 capi_message2cmsg(cmsg, skb->data);
1780 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1782 /* extract and check channel number and NCCI */
1783 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1784 if (!channel || channel > cs->channels ||
1785 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1786 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1787 "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
1788 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1792 /* reject if logical connection not active */
1793 if (ap->connected < APCONN_ACTIVE) {
1794 send_conf(iif, ap, skb,
1795 CapiMessageNotSupportedInCurrentState);
1799 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1800 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1801 EV_HUP, NULL, 0, NULL)) {
1802 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1805 gigaset_schedule_event(cs);
1807 /* NCPI parameter: not applicable for B3 Transparent */
1808 ignore_cstruct_param(cs, cmsg->NCPI,
1809 "DISCONNECT_B3_REQ", "NCPI");
1810 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1811 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1815 * process DATA_B3_REQ message
1817 static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1818 struct gigaset_capi_appl *ap,
1819 struct sk_buff *skb)
1821 struct cardstate *cs = iif->ctr.driverdata;
1822 int channel = CAPIMSG_PLCI_PART(skb->data);
1823 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1824 u16 msglen = CAPIMSG_LEN(skb->data);
1825 u16 datalen = CAPIMSG_DATALEN(skb->data);
1826 u16 flags = CAPIMSG_FLAGS(skb->data);
1828 /* frequent message, avoid _cmsg overhead */
1829 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1831 gig_dbg(DEBUG_LLDATA,
1832 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1833 channel, flags, msglen, datalen);
1835 /* check parameters */
1836 if (channel == 0 || channel > cs->channels || ncci != 1) {
1837 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1838 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1839 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1842 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1843 dev_notice(cs->dev, "%s: unexpected length %d\n",
1844 "DATA_B3_REQ", msglen);
1845 if (msglen + datalen != skb->len)
1846 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1847 "DATA_B3_REQ", msglen, datalen, skb->len);
1848 if (msglen + datalen > skb->len) {
1849 /* message too short for announced data length */
1850 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1853 if (flags & CAPI_FLAGS_RESERVED) {
1854 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1855 "DATA_B3_REQ", flags);
1856 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1860 /* reject if logical connection not active */
1861 if (ap->connected < APCONN_ACTIVE) {
1862 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1866 /* pull CAPI message into link layer header */
1867 skb_reset_mac_header(skb);
1868 skb->mac_len = msglen;
1869 skb_pull(skb, msglen);
1871 /* pass to device-specific module */
1872 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1873 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1877 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1880 * ToDo: honor unset "delivery confirmation" bit
1881 * (send DATA_B3_CONF immediately?)
1886 * process RESET_B3_REQ message
1887 * just always reply "not supported by current protocol"
1889 static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1890 struct gigaset_capi_appl *ap,
1891 struct sk_buff *skb)
1893 /* decode message */
1894 capi_message2cmsg(&iif->acmsg, skb->data);
1895 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1896 send_conf(iif, ap, skb,
1897 CapiResetProcedureNotSupportedByCurrentProtocol);
1901 * dump unsupported/ignored messages at most twice per minute,
1902 * some apps send those very frequently
1904 static unsigned long ignored_msg_dump_time;
1907 * unsupported CAPI message handler
1909 static void do_unsupported(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 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1916 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1917 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1921 * CAPI message handler: no-op
1923 static void do_nothing(struct gigaset_capi_ctr *iif,
1924 struct gigaset_capi_appl *ap,
1925 struct sk_buff *skb)
1927 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1928 /* decode message */
1929 capi_message2cmsg(&iif->acmsg, skb->data);
1930 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1932 dev_kfree_skb_any(skb);
1935 static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1936 struct gigaset_capi_appl *ap,
1937 struct sk_buff *skb)
1939 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1940 dev_kfree_skb_any(skb);
1943 /* table of outgoing CAPI message handlers with lookup function */
1944 typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1945 struct gigaset_capi_appl *,
1950 capi_send_handler_t handler;
1951 } capi_send_handler_table[] = {
1952 /* most frequent messages first for faster lookup */
1953 { CAPI_DATA_B3_REQ, do_data_b3_req },
1954 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1956 { CAPI_ALERT_REQ, do_alert_req },
1957 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1958 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1959 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1960 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1961 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1962 { CAPI_CONNECT_REQ, do_connect_req },
1963 { CAPI_CONNECT_RESP, do_connect_resp },
1964 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1965 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1966 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1967 { CAPI_DISCONNECT_RESP, do_nothing },
1968 { CAPI_FACILITY_REQ, do_facility_req },
1969 { CAPI_FACILITY_RESP, do_nothing },
1970 { CAPI_LISTEN_REQ, do_listen_req },
1971 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1972 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1973 { CAPI_RESET_B3_RESP, do_nothing },
1976 * ToDo: support overlap sending (requires ev-layer state
1977 * machine extension to generate additional ATD commands)
1979 { CAPI_INFO_REQ, do_unsupported },
1980 { CAPI_INFO_RESP, do_nothing },
1983 * ToDo: what's the proper response for these?
1985 { CAPI_MANUFACTURER_REQ, do_nothing },
1986 { CAPI_MANUFACTURER_RESP, do_nothing },
1989 /* look up handler */
1990 static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
1994 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
1995 if (capi_send_handler_table[i].cmd == cmd)
1996 return capi_send_handler_table[i].handler;
2002 * gigaset_send_message() - accept a CAPI message from an application
2003 * @ctr: controller descriptor structure.
2004 * @skb: CAPI message.
2006 * Return value: CAPI error code
2007 * Note: capidrv (and probably others, too) only uses the return value to
2008 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2010 static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2012 struct gigaset_capi_ctr *iif
2013 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2014 struct cardstate *cs = ctr->driverdata;
2015 struct gigaset_capi_appl *ap;
2016 capi_send_handler_t handler;
2018 /* can only handle linear sk_buffs */
2019 if (skb_linearize(skb) < 0) {
2020 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2021 return CAPI_MSGOSRESOURCEERR;
2024 /* retrieve application data structure */
2025 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2027 dev_notice(cs->dev, "%s: application %u not registered\n",
2028 __func__, CAPIMSG_APPID(skb->data));
2029 return CAPI_ILLAPPNR;
2032 /* look up command */
2033 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2035 /* unknown/unsupported message type */
2036 if (printk_ratelimit())
2037 dev_notice(cs->dev, "%s: unsupported message %u\n",
2038 __func__, CAPIMSG_CMD(skb->data));
2039 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2043 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2044 /* queue behind other messages */
2045 skb_queue_tail(&iif->sendqueue, skb);
2046 return CAPI_NOERROR;
2049 /* process message */
2050 handler(iif, ap, skb);
2052 /* process other messages arrived in the meantime */
2053 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2054 skb = skb_dequeue(&iif->sendqueue);
2056 /* should never happen */
2057 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2060 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2062 /* could that happen? */
2063 dev_warn(cs->dev, "%s: application %u vanished\n",
2064 __func__, CAPIMSG_APPID(skb->data));
2067 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2069 /* should never happen */
2070 dev_err(cs->dev, "%s: handler %x vanished\n",
2071 __func__, CAPIMSG_CMD(skb->data));
2074 handler(iif, ap, skb);
2077 return CAPI_NOERROR;
2081 * gigaset_procinfo() - build single line description for controller
2082 * @ctr: controller descriptor structure.
2084 * Return value: pointer to generated string (null terminated)
2086 static char *gigaset_procinfo(struct capi_ctr *ctr)
2088 return ctr->name; /* ToDo: more? */
2091 static int gigaset_proc_show(struct seq_file *m, void *v)
2093 struct capi_ctr *ctr = m->private;
2094 struct cardstate *cs = ctr->driverdata;
2098 seq_printf(m, "%-16s %s\n", "name", ctr->name);
2099 seq_printf(m, "%-16s %s %s\n", "dev",
2100 dev_driver_string(cs->dev), dev_name(cs->dev));
2101 seq_printf(m, "%-16s %d\n", "id", cs->myid);
2103 seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
2104 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2105 seq_printf(m, "%-16s %d\n", "channels", cs->channels);
2106 seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
2124 seq_printf(m, "%-16s %s\n", "mode", s);
2126 switch (cs->mstate) {
2127 case MS_UNINITIALIZED:
2128 s = "uninitialized";
2148 seq_printf(m, "%-16s %s\n", "mstate", s);
2150 seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
2151 seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
2152 seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
2153 seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
2155 for (i = 0; i < cs->channels; i++) {
2156 seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
2157 cs->bcs[i].corrupted);
2158 seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
2159 cs->bcs[i].trans_down);
2160 seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
2161 cs->bcs[i].trans_up);
2162 seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
2163 cs->bcs[i].chstate);
2164 switch (cs->bcs[i].proto2) {
2177 seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
2182 static int gigaset_proc_open(struct inode *inode, struct file *file)
2184 return single_open(file, gigaset_proc_show, PDE(inode)->data);
2187 static const struct file_operations gigaset_proc_fops = {
2188 .owner = THIS_MODULE,
2189 .open = gigaset_proc_open,
2191 .llseek = seq_lseek,
2192 .release = single_release,
2196 * gigaset_isdn_regdev() - register device to LL
2197 * @cs: device descriptor structure.
2198 * @isdnid: device name.
2200 * Return value: 1 for success, 0 for failure
2202 int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
2204 struct gigaset_capi_ctr *iif;
2207 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2209 pr_err("%s: out of memory\n", __func__);
2213 /* prepare controller structure */
2214 iif->ctr.owner = THIS_MODULE;
2215 iif->ctr.driverdata = cs;
2216 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2217 iif->ctr.driver_name = "gigaset";
2218 iif->ctr.load_firmware = gigaset_load_firmware;
2219 iif->ctr.reset_ctr = gigaset_reset_ctr;
2220 iif->ctr.register_appl = gigaset_register_appl;
2221 iif->ctr.release_appl = gigaset_release_appl;
2222 iif->ctr.send_message = gigaset_send_message;
2223 iif->ctr.procinfo = gigaset_procinfo;
2224 iif->ctr.proc_fops = &gigaset_proc_fops;
2225 INIT_LIST_HEAD(&iif->appls);
2226 skb_queue_head_init(&iif->sendqueue);
2227 atomic_set(&iif->sendqlen, 0);
2229 /* register controller with CAPI */
2230 rc = attach_capi_ctr(&iif->ctr);
2232 pr_err("attach_capi_ctr failed (%d)\n", rc);
2238 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2243 * gigaset_isdn_unregdev() - unregister device from LL
2244 * @cs: device descriptor structure.
2246 void gigaset_isdn_unregdev(struct cardstate *cs)
2248 struct gigaset_capi_ctr *iif = cs->iif;
2250 detach_capi_ctr(&iif->ctr);
2255 static struct capi_driver capi_driver_gigaset = {
2261 * gigaset_isdn_regdrv() - register driver to LL
2263 void gigaset_isdn_regdrv(void)
2265 pr_info("Kernel CAPI interface\n");
2266 register_capi_driver(&capi_driver_gigaset);
2270 * gigaset_isdn_unregdrv() - unregister driver from LL
2272 void gigaset_isdn_unregdrv(void)
2274 unregister_capi_driver(&capi_driver_gigaset);