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/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <linux/isdn/capilli.h>
18 #include <linux/isdn/capicmd.h>
19 #include <linux/isdn/capiutil.h>
21 /* missing from kernelcapi.h */
22 #define CapiNcpiNotSupportedByProtocol 0x0001
23 #define CapiFlagsNotSupportedByProtocol 0x0002
24 #define CapiAlertAlreadySent 0x0003
25 #define CapiFacilitySpecificFunctionNotSupported 0x3011
27 /* missing from capicmd.h */
28 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
29 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
30 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
31 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
32 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
33 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
34 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
35 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
36 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
37 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
38 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
40 #define CAPI_FACILITY_HANDSET 0x0000
41 #define CAPI_FACILITY_DTMF 0x0001
42 #define CAPI_FACILITY_V42BIS 0x0002
43 #define CAPI_FACILITY_SUPPSVC 0x0003
44 #define CAPI_FACILITY_WAKEUP 0x0004
45 #define CAPI_FACILITY_LI 0x0005
47 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
49 /* missing from capiutil.h */
50 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
51 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
52 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
53 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
54 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
55 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
56 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
57 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
59 /* parameters with differing location in DATA_B3_CONF/_RESP: */
60 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
61 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
63 /* Flags (DATA_B3_REQ/_IND) */
64 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
65 #define CAPI_FLAGS_RESERVED (~0x1f)
68 #define MAX_BC_OCTETS 11
69 #define MAX_HLC_OCTETS 3
70 #define MAX_NUMBER_DIGITS 20
71 #define MAX_FMT_IE_LEN 20
73 /* values for gigaset_capi_appl.connected */
74 #define APCONN_NONE 0 /* inactive/listening */
75 #define APCONN_SETUP 1 /* connecting */
76 #define APCONN_ACTIVE 2 /* B channel up */
78 /* registered application data structure */
79 struct gigaset_capi_appl {
80 struct list_head ctrlist;
81 struct gigaset_capi_appl *bcnext;
83 struct capi_register_params rp;
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 * convert an IE from Gigaset hex string to ETSI binary representation
175 * including length byte
176 * return value: result length, -1 on error
178 static int encode_ie(char *in, u8 *out, int maxlen)
182 if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
184 out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
192 * convert an IE from ETSI binary representation including length byte
193 * to Gigaset hex string
195 static void decode_ie(u8 *in, char *out)
199 /* ToDo: conversion to upper case necessary? */
200 *out++ = toupper(hex_asc_hi(*++in));
201 *out++ = toupper(hex_asc_lo(*in));
206 * retrieve application data structure for an application ID
208 static inline struct gigaset_capi_appl *
209 get_appl(struct gigaset_capi_ctr *iif, u16 appl)
211 struct gigaset_capi_appl *ap;
213 list_for_each_entry(ap, &iif->appls, ctrlist)
220 * dump CAPI message to kernel messages for debugging
222 static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
224 #ifdef CONFIG_GIGASET_DEBUG
227 if (!(gigaset_debuglevel & level))
230 cdb = capi_cmsg2str(p);
232 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
235 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
236 capi_cmd2str(p->Command, p->Subcommand));
241 static inline void dump_rawmsg(enum debuglevel level, const char *tag,
244 #ifdef CONFIG_GIGASET_DEBUG
248 if (!(gigaset_debuglevel & level))
251 l = CAPIMSG_LEN(data);
253 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
256 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
257 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
258 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
259 CAPIMSG_CONTROL(data));
261 dbgline = kmalloc(3*l, GFP_ATOMIC);
264 for (i = 0; i < l; i++) {
265 dbgline[3*i] = hex_asc_hi(data[12+i]);
266 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
267 dbgline[3*i+2] = ' ';
269 dbgline[3*l-1] = '\0';
270 gig_dbg(level, " %s", dbgline);
272 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
273 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
274 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
275 CAPIMSG_DATALEN(data) > 0) {
276 l = CAPIMSG_DATALEN(data);
277 dbgline = kmalloc(3*l, GFP_ATOMIC);
280 data += CAPIMSG_LEN(data);
281 for (i = 0; i < l; i++) {
282 dbgline[3*i] = hex_asc_hi(data[i]);
283 dbgline[3*i+1] = hex_asc_lo(data[i]);
284 dbgline[3*i+2] = ' ';
286 dbgline[3*l-1] = '\0';
287 gig_dbg(level, " %s", dbgline);
294 * format CAPI IE as string
297 static const char *format_ie(const char *ie)
299 static char result[3*MAX_FMT_IE_LEN];
307 if (count > MAX_FMT_IE_LEN)
308 count = MAX_FMT_IE_LEN-1;
310 *pout++ = hex_asc_hi(*++ie);
311 *pout++ = hex_asc_lo(*ie);
314 if (len > MAX_FMT_IE_LEN) {
324 * emit DATA_B3_CONF message
326 static void send_data_b3_conf(struct cardstate *cs, struct capi_ctr *ctr,
327 u16 appl, u16 msgid, int channel,
328 u16 handle, u16 info)
330 struct sk_buff *cskb;
333 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
335 dev_err(cs->dev, "%s: out of memory\n", __func__);
338 /* frequent message, avoid _cmsg overhead */
339 msg = __skb_put(cskb, CAPI_DATA_B3_CONF_LEN);
340 CAPIMSG_SETLEN(msg, CAPI_DATA_B3_CONF_LEN);
341 CAPIMSG_SETAPPID(msg, appl);
342 CAPIMSG_SETCOMMAND(msg, CAPI_DATA_B3);
343 CAPIMSG_SETSUBCOMMAND(msg, CAPI_CONF);
344 CAPIMSG_SETMSGID(msg, msgid);
345 CAPIMSG_SETCONTROLLER(msg, ctr->cnr);
346 CAPIMSG_SETPLCI_PART(msg, channel);
347 CAPIMSG_SETNCCI_PART(msg, 1);
348 CAPIMSG_SETHANDLE_CONF(msg, handle);
349 CAPIMSG_SETINFO_CONF(msg, info);
352 dump_rawmsg(DEBUG_MCMD, __func__, msg);
353 capi_ctr_handle_message(ctr, appl, cskb);
358 * driver interface functions
359 * ==========================
363 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
364 * @bcs: B channel descriptor structure.
367 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
368 * skb has been successfully sent, for signalling completion to the LL.
370 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
372 struct cardstate *cs = bcs->cs;
373 struct gigaset_capi_ctr *iif = cs->iif;
374 struct gigaset_capi_appl *ap = bcs->ap;
375 unsigned char *req = skb_mac_header(dskb);
378 /* update statistics */
382 dev_err(cs->dev, "%s: no application\n", __func__);
386 /* don't send further B3 messages if disconnected */
387 if (ap->connected < APCONN_ACTIVE) {
388 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
393 * send DATA_B3_CONF if "delivery confirmation" bit was set in request;
394 * otherwise it has already been sent by do_data_b3_req()
396 flags = CAPIMSG_FLAGS(req);
397 if (flags & CAPI_FLAGS_DELIVERY_CONFIRMATION)
398 send_data_b3_conf(cs, &iif->ctr, ap->id, CAPIMSG_MSGID(req),
399 bcs->channel + 1, CAPIMSG_HANDLE_REQ(req),
400 (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION) ?
401 CapiFlagsNotSupportedByProtocol :
404 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
407 * gigaset_skb_rcvd() - pass received skb to LL
408 * @bcs: B channel descriptor structure.
409 * @skb: received data.
411 * Called by hardware module {bas,ser,usb}_gigaset when user data has
412 * been successfully received, for passing to the LL.
413 * Warning: skb must not be accessed anymore!
415 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
417 struct cardstate *cs = bcs->cs;
418 struct gigaset_capi_ctr *iif = cs->iif;
419 struct gigaset_capi_appl *ap = bcs->ap;
422 /* update statistics */
426 dev_err(cs->dev, "%s: no application\n", __func__);
430 /* don't send further B3 messages if disconnected */
431 if (ap->connected < APCONN_ACTIVE) {
432 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
433 dev_kfree_skb_any(skb);
438 * prepend DATA_B3_IND message to payload
439 * Parameters: NCCI = 1, all others 0/unused
440 * frequent message, avoid _cmsg overhead
442 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
443 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
444 CAPIMSG_SETAPPID(skb->data, ap->id);
445 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
446 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
447 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
448 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
449 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
450 CAPIMSG_SETNCCI_PART(skb->data, 1);
451 /* Data parameter not used */
452 CAPIMSG_SETDATALEN(skb->data, len);
453 /* Data handle parameter not used */
454 CAPIMSG_SETFLAGS(skb->data, 0);
455 /* Data64 parameter not present */
458 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
459 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
461 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
464 * gigaset_isdn_rcv_err() - signal receive error
465 * @bcs: B channel descriptor structure.
467 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
468 * has occurred, for signalling to the LL.
470 void gigaset_isdn_rcv_err(struct bc_state *bcs)
472 /* if currently ignoring packets, just count down */
478 /* update statistics */
481 /* ToDo: signal error -> LL */
483 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
486 * gigaset_isdn_icall() - signal incoming call
487 * @at_state: connection state structure.
489 * Called by main module at tasklet level to notify the LL that an incoming
490 * call has been received. @at_state contains the parameters of the call.
492 * Return value: call disposition (ICALL_*)
494 int gigaset_isdn_icall(struct at_state_t *at_state)
496 struct cardstate *cs = at_state->cs;
497 struct bc_state *bcs = at_state->bcs;
498 struct gigaset_capi_ctr *iif = cs->iif;
499 struct gigaset_capi_appl *ap;
502 unsigned int msgsize;
506 * ToDo: signal calls without a free B channel, too
507 * (requires a u8 handle for the at_state structure that can
508 * be stored in the PLCI and used in the CONNECT_RESP message
509 * handler to retrieve it)
514 /* prepare CONNECT_IND message, using B channel number as PLCI */
515 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
516 iif->ctr.cnr | ((bcs->channel + 1) << 8));
518 /* minimum size, all structs empty */
519 msgsize = CAPI_CONNECT_IND_BASELEN;
521 /* Bearer Capability (mandatory) */
522 if (at_state->str_var[STR_ZBC]) {
523 /* pass on BC from Gigaset */
524 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
525 MAX_BC_OCTETS) < 0) {
526 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
527 at_state->str_var[STR_ZBC]);
531 /* look up corresponding CIP value */
532 iif->hcmsg.CIPValue = 0; /* default if nothing found */
533 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
534 if (cip2bchlc[i].bc != NULL &&
535 cip2bchlc[i].hlc == NULL &&
536 !strcmp(cip2bchlc[i].bc,
537 at_state->str_var[STR_ZBC])) {
538 iif->hcmsg.CIPValue = i;
542 /* no BC (internal call): assume CIP 1 (speech, A-law) */
543 iif->hcmsg.CIPValue = 1;
544 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
546 iif->hcmsg.BC = iif->bc_buf;
547 msgsize += iif->hcmsg.BC[0];
549 /* High Layer Compatibility (optional) */
550 if (at_state->str_var[STR_ZHLC]) {
551 /* pass on HLC from Gigaset */
552 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
553 MAX_HLC_OCTETS) < 0) {
554 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
555 at_state->str_var[STR_ZHLC]);
558 iif->hcmsg.HLC = iif->hlc_buf;
559 msgsize += iif->hcmsg.HLC[0];
561 /* look up corresponding CIP value */
562 /* keep BC based CIP value if none found */
563 if (at_state->str_var[STR_ZBC])
564 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
565 if (cip2bchlc[i].hlc != NULL &&
566 !strcmp(cip2bchlc[i].hlc,
567 at_state->str_var[STR_ZHLC]) &&
568 !strcmp(cip2bchlc[i].bc,
569 at_state->str_var[STR_ZBC])) {
570 iif->hcmsg.CIPValue = i;
575 /* Called Party Number (optional) */
576 if (at_state->str_var[STR_ZCPN]) {
577 i = strlen(at_state->str_var[STR_ZCPN]);
578 if (i > MAX_NUMBER_DIGITS) {
579 dev_warn(cs->dev, "RING ignored - bad number %s\n",
580 at_state->str_var[STR_ZBC]);
583 iif->cdpty_buf[0] = i + 1;
584 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
585 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
586 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
587 msgsize += iif->hcmsg.CalledPartyNumber[0];
590 /* Calling Party Number (optional) */
591 if (at_state->str_var[STR_NMBR]) {
592 i = strlen(at_state->str_var[STR_NMBR]);
593 if (i > MAX_NUMBER_DIGITS) {
594 dev_warn(cs->dev, "RING ignored - bad number %s\n",
595 at_state->str_var[STR_ZBC]);
598 iif->cgpty_buf[0] = i + 2;
599 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
600 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
601 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
602 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
603 msgsize += iif->hcmsg.CallingPartyNumber[0];
606 /* remaining parameters (not supported, always left NULL):
607 * - CalledPartySubaddress
608 * - CallingPartySubaddress
610 * - BChannelinformation
613 * - Facilitydataarray
616 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
617 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
618 format_ie(iif->hcmsg.BC));
619 gig_dbg(DEBUG_CMD, "icall: HLC %s",
620 format_ie(iif->hcmsg.HLC));
621 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
622 format_ie(iif->hcmsg.CallingPartyNumber));
623 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
624 format_ie(iif->hcmsg.CalledPartyNumber));
626 /* scan application list for matching listeners */
628 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
629 list_for_each_entry(ap, &iif->appls, ctrlist)
630 if (actCIPmask & ap->listenCIPmask) {
631 /* build CONNECT_IND message for this application */
632 iif->hcmsg.ApplId = ap->id;
633 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
635 skb = alloc_skb(msgsize, GFP_ATOMIC);
637 dev_err(cs->dev, "%s: out of memory\n",
641 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
642 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
644 /* add to listeners on this B channel, update state */
645 ap->bcnext = bcs->ap;
647 bcs->chstate |= CHS_NOTIFY_LL;
648 ap->connected = APCONN_SETUP;
651 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
655 * Return "accept" if any listeners.
656 * Gigaset will send ALERTING.
657 * There doesn't seem to be a way to avoid this.
659 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
663 * send a DISCONNECT_IND message to an application
664 * does not sleep, clobbers the controller's hcmsg structure
666 static void send_disconnect_ind(struct bc_state *bcs,
667 struct gigaset_capi_appl *ap, u16 reason)
669 struct cardstate *cs = bcs->cs;
670 struct gigaset_capi_ctr *iif = cs->iif;
673 if (ap->connected == APCONN_NONE)
676 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
677 ap->nextMessageNumber++,
678 iif->ctr.cnr | ((bcs->channel + 1) << 8));
679 iif->hcmsg.Reason = reason;
680 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
682 dev_err(cs->dev, "%s: out of memory\n", __func__);
685 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
686 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
687 ap->connected = APCONN_NONE;
688 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
692 * send a DISCONNECT_B3_IND message to an application
693 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
694 * does not sleep, clobbers the controller's hcmsg structure
696 static void send_disconnect_b3_ind(struct bc_state *bcs,
697 struct gigaset_capi_appl *ap)
699 struct cardstate *cs = bcs->cs;
700 struct gigaset_capi_ctr *iif = cs->iif;
703 /* nothing to do if no logical connection active */
704 if (ap->connected < APCONN_ACTIVE)
706 ap->connected = APCONN_SETUP;
708 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
709 ap->nextMessageNumber++,
710 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
711 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
713 dev_err(cs->dev, "%s: out of memory\n", __func__);
716 capi_cmsg2message(&iif->hcmsg,
717 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
718 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
719 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
723 * gigaset_isdn_connD() - signal D channel connect
724 * @bcs: B channel descriptor structure.
726 * Called by main module at tasklet level to notify the LL that the D channel
727 * connection has been established.
729 void gigaset_isdn_connD(struct bc_state *bcs)
731 struct cardstate *cs = bcs->cs;
732 struct gigaset_capi_ctr *iif = cs->iif;
733 struct gigaset_capi_appl *ap = bcs->ap;
735 unsigned int msgsize;
738 dev_err(cs->dev, "%s: no application\n", __func__);
742 /* this should never happen */
743 dev_warn(cs->dev, "%s: dropping extra application %u\n",
744 __func__, ap->bcnext->id);
745 send_disconnect_ind(bcs, ap->bcnext,
746 CapiCallGivenToOtherApplication);
747 ap->bcnext = ap->bcnext->bcnext;
749 if (ap->connected == APCONN_NONE) {
750 dev_warn(cs->dev, "%s: application %u not connected\n",
755 /* prepare CONNECT_ACTIVE_IND message
756 * Note: LLC not supported by device
758 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
759 ap->nextMessageNumber++,
760 iif->ctr.cnr | ((bcs->channel + 1) << 8));
762 /* minimum size, all structs empty */
763 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
765 /* ToDo: set parameter: Connected number
766 * (requires ev-layer state machine extension to collect
770 /* build and emit CONNECT_ACTIVE_IND message */
771 skb = alloc_skb(msgsize, GFP_ATOMIC);
773 dev_err(cs->dev, "%s: out of memory\n", __func__);
776 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
777 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
778 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
782 * gigaset_isdn_hupD() - signal D channel hangup
783 * @bcs: B channel descriptor structure.
785 * Called by main module at tasklet level to notify the LL that the D channel
786 * connection has been shut down.
788 void gigaset_isdn_hupD(struct bc_state *bcs)
790 struct gigaset_capi_appl *ap;
793 * ToDo: pass on reason code reported by device
794 * (requires ev-layer state machine extension to collect
797 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
798 send_disconnect_b3_ind(bcs, ap);
799 send_disconnect_ind(bcs, ap, 0);
805 * gigaset_isdn_connB() - signal B channel connect
806 * @bcs: B channel descriptor structure.
808 * Called by main module at tasklet level to notify the LL that the B channel
809 * connection has been established.
811 void gigaset_isdn_connB(struct bc_state *bcs)
813 struct cardstate *cs = bcs->cs;
814 struct gigaset_capi_ctr *iif = cs->iif;
815 struct gigaset_capi_appl *ap = bcs->ap;
817 unsigned int msgsize;
821 dev_err(cs->dev, "%s: no application\n", __func__);
825 /* this should never happen */
826 dev_warn(cs->dev, "%s: dropping extra application %u\n",
827 __func__, ap->bcnext->id);
828 send_disconnect_ind(bcs, ap->bcnext,
829 CapiCallGivenToOtherApplication);
830 ap->bcnext = ap->bcnext->bcnext;
832 if (!ap->connected) {
833 dev_warn(cs->dev, "%s: application %u not connected\n",
839 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
840 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
841 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
842 * Parameters in both cases always: NCCI = 1, NCPI empty
844 if (ap->connected >= APCONN_ACTIVE) {
845 command = CAPI_CONNECT_B3_ACTIVE;
846 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
848 command = CAPI_CONNECT_B3;
849 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
851 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
852 ap->nextMessageNumber++,
853 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
854 skb = alloc_skb(msgsize, GFP_ATOMIC);
856 dev_err(cs->dev, "%s: out of memory\n", __func__);
859 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
860 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
861 ap->connected = APCONN_ACTIVE;
862 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
866 * gigaset_isdn_hupB() - signal B channel hangup
867 * @bcs: B channel descriptor structure.
869 * Called by main module to notify the LL that the B channel connection has
872 void gigaset_isdn_hupB(struct bc_state *bcs)
874 struct cardstate *cs = bcs->cs;
875 struct gigaset_capi_appl *ap = bcs->ap;
877 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
880 dev_err(cs->dev, "%s: no application\n", __func__);
884 send_disconnect_b3_ind(bcs, ap);
888 * gigaset_isdn_start() - signal device availability
889 * @cs: device descriptor structure.
891 * Called by main module to notify the LL that the device is available for
894 void gigaset_isdn_start(struct cardstate *cs)
896 struct gigaset_capi_ctr *iif = cs->iif;
898 /* fill profile data: manufacturer name */
899 strcpy(iif->ctr.manu, "Siemens");
900 /* CAPI and device version */
901 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
902 iif->ctr.version.minorversion = 0;
903 /* ToDo: check/assert cs->gotfwver? */
904 iif->ctr.version.majormanuversion = cs->fwver[0];
905 iif->ctr.version.minormanuversion = cs->fwver[1];
906 /* number of B channels supported */
907 iif->ctr.profile.nbchannel = cs->channels;
908 /* global options: internal controller, supplementary services */
909 iif->ctr.profile.goptions = 0x11;
910 /* B1 protocols: 64 kbit/s HDLC or transparent */
911 iif->ctr.profile.support1 = 0x03;
912 /* B2 protocols: transparent only */
913 /* ToDo: X.75 SLP ? */
914 iif->ctr.profile.support2 = 0x02;
915 /* B3 protocols: transparent only */
916 iif->ctr.profile.support3 = 0x01;
917 /* no serial number */
918 strcpy(iif->ctr.serial, "0");
919 capi_ctr_ready(&iif->ctr);
923 * gigaset_isdn_stop() - signal device unavailability
924 * @cs: device descriptor structure.
926 * Called by main module to notify the LL that the device is no longer
929 void gigaset_isdn_stop(struct cardstate *cs)
931 struct gigaset_capi_ctr *iif = cs->iif;
932 capi_ctr_down(&iif->ctr);
936 * kernel CAPI callback methods
937 * ============================
941 * register CAPI application
943 static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
944 capi_register_params *rp)
946 struct gigaset_capi_ctr *iif
947 = container_of(ctr, struct gigaset_capi_ctr, ctr);
948 struct cardstate *cs = ctr->driverdata;
949 struct gigaset_capi_appl *ap;
951 list_for_each_entry(ap, &iif->appls, ctrlist)
952 if (ap->id == appl) {
954 "application %u already registered\n", appl);
958 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
960 dev_err(cs->dev, "%s: out of memory\n", __func__);
966 list_add(&ap->ctrlist, &iif->appls);
970 * release CAPI application
972 static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
974 struct gigaset_capi_ctr *iif
975 = container_of(ctr, struct gigaset_capi_ctr, ctr);
976 struct cardstate *cs = iif->ctr.driverdata;
977 struct gigaset_capi_appl *ap, *tmp;
979 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
980 if (ap->id == appl) {
981 if (ap->connected != APCONN_NONE) {
983 "%s: application %u still connected\n",
985 /* ToDo: clear active connection */
987 list_del(&ap->ctrlist);
994 * =====================================================================
995 * outgoing CAPI message handler
996 * =====================================================================
1000 * helper function: emit reply message with given Info value
1002 static void send_conf(struct gigaset_capi_ctr *iif,
1003 struct gigaset_capi_appl *ap,
1004 struct sk_buff *skb,
1008 * _CONF replies always only have NCCI and Info parameters
1009 * so they'll fit into the _REQ message skb
1011 capi_cmsg_answer(&iif->acmsg);
1012 iif->acmsg.Info = info;
1013 capi_cmsg2message(&iif->acmsg, skb->data);
1014 __skb_trim(skb, CAPI_STDCONF_LEN);
1015 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1016 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1020 * process FACILITY_REQ message
1022 static void do_facility_req(struct gigaset_capi_ctr *iif,
1023 struct gigaset_capi_appl *ap,
1024 struct sk_buff *skb)
1026 struct cardstate *cs = iif->ctr.driverdata;
1027 _cmsg *cmsg = &iif->acmsg;
1028 struct sk_buff *cskb;
1030 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1032 static u8 confparam[10]; /* max. 9 octets + length byte */
1034 /* decode message */
1035 capi_message2cmsg(cmsg, skb->data);
1036 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1039 * Facility Request Parameter is not decoded by capi_message2cmsg()
1040 * encoding depends on Facility Selector
1042 switch (cmsg->FacilitySelector) {
1043 case CAPI_FACILITY_DTMF: /* ToDo */
1044 info = CapiFacilityNotSupported;
1045 confparam[0] = 2; /* length */
1046 /* DTMF information: Unknown DTMF request */
1047 capimsg_setu16(confparam, 1, 2);
1050 case CAPI_FACILITY_V42BIS: /* not supported */
1051 info = CapiFacilityNotSupported;
1052 confparam[0] = 2; /* length */
1053 /* V.42 bis information: not available */
1054 capimsg_setu16(confparam, 1, 1);
1057 case CAPI_FACILITY_SUPPSVC:
1058 /* decode Function parameter */
1059 pparam = cmsg->FacilityRequestParameter;
1060 if (pparam == NULL || *pparam < 2) {
1061 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1062 "Facility Request Parameter");
1063 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1066 function = CAPIMSG_U16(pparam, 1);
1068 case CAPI_SUPPSVC_GETSUPPORTED:
1070 /* Supplementary Service specific parameter */
1071 confparam[3] = 6; /* length */
1072 /* Supplementary services info: Success */
1073 capimsg_setu16(confparam, 4, CapiSuccess);
1074 /* Supported Services: none */
1075 capimsg_setu32(confparam, 6, 0);
1077 /* ToDo: add supported services */
1079 info = CapiFacilitySpecificFunctionNotSupported;
1080 /* Supplementary Service specific parameter */
1081 confparam[3] = 2; /* length */
1082 /* Supplementary services info: not supported */
1083 capimsg_setu16(confparam, 4,
1084 CapiSupplementaryServiceNotSupported);
1087 /* Facility confirmation parameter */
1088 confparam[0] = confparam[3] + 3; /* total length */
1089 /* Function: copy from _REQ message */
1090 capimsg_setu16(confparam, 1, function);
1091 /* Supplementary Service specific parameter already set above */
1094 case CAPI_FACILITY_WAKEUP: /* ToDo */
1095 info = CapiFacilityNotSupported;
1096 confparam[0] = 2; /* length */
1097 /* Number of accepted awake request parameters: 0 */
1098 capimsg_setu16(confparam, 1, 0);
1102 info = CapiFacilityNotSupported;
1103 confparam[0] = 0; /* empty struct */
1106 /* send FACILITY_CONF with given Info and confirmation parameter */
1107 capi_cmsg_answer(cmsg);
1109 cmsg->FacilityConfirmationParameter = confparam;
1110 msgsize += confparam[0]; /* length */
1111 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1113 dev_err(cs->dev, "%s: out of memory\n", __func__);
1116 capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
1117 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1118 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1123 * process LISTEN_REQ message
1124 * just store the masks in the application data structure
1126 static void do_listen_req(struct gigaset_capi_ctr *iif,
1127 struct gigaset_capi_appl *ap,
1128 struct sk_buff *skb)
1130 /* decode message */
1131 capi_message2cmsg(&iif->acmsg, skb->data);
1132 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1134 /* store listening parameters */
1135 ap->listenInfoMask = iif->acmsg.InfoMask;
1136 ap->listenCIPmask = iif->acmsg.CIPmask;
1137 send_conf(iif, ap, skb, CapiSuccess);
1141 * process ALERT_REQ message
1142 * nothing to do, Gigaset always alerts anyway
1144 static void do_alert_req(struct gigaset_capi_ctr *iif,
1145 struct gigaset_capi_appl *ap,
1146 struct sk_buff *skb)
1148 /* decode message */
1149 capi_message2cmsg(&iif->acmsg, skb->data);
1150 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1151 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1155 * process CONNECT_REQ message
1156 * allocate a B channel, prepare dial commands, queue a DIAL event,
1157 * emit CONNECT_CONF reply
1159 static void do_connect_req(struct gigaset_capi_ctr *iif,
1160 struct gigaset_capi_appl *ap,
1161 struct sk_buff *skb)
1163 struct cardstate *cs = iif->ctr.driverdata;
1164 _cmsg *cmsg = &iif->acmsg;
1165 struct bc_state *bcs;
1169 int i, l, lbc, lhlc;
1172 /* decode message */
1173 capi_message2cmsg(cmsg, skb->data);
1174 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1176 /* get free B channel & construct PLCI */
1177 bcs = gigaset_get_free_channel(cs);
1179 dev_notice(cs->dev, "%s: no B channel available\n",
1181 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1186 bcs->rx_bufsize = ap->rp.datablklen;
1187 dev_kfree_skb(bcs->rx_skb);
1188 gigaset_new_rx_skb(bcs);
1189 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1191 /* build command table */
1192 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1196 /* encode parameter: Called party number */
1197 pp = cmsg->CalledPartyNumber;
1198 if (pp == NULL || *pp == 0) {
1199 dev_notice(cs->dev, "%s: %s missing\n",
1200 "CONNECT_REQ", "Called party number");
1201 info = CapiIllMessageParmCoding;
1205 /* check type of number/numbering plan byte */
1207 case 0x80: /* unknown type / unknown numbering plan */
1208 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1210 default: /* others: warn about potential misinterpretation */
1211 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1212 "CONNECT_REQ", "Called party number", *pp);
1216 /* translate "**" internal call prefix to CTP value */
1217 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1224 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1225 if (!commands[AT_TYPE])
1227 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1228 if (!commands[AT_DIAL])
1230 snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
1232 /* encode parameter: Calling party number */
1233 pp = cmsg->CallingPartyNumber;
1234 if (pp != NULL && *pp > 0) {
1237 /* check type of number/numbering plan byte */
1238 /* ToDo: allow for/handle Ext=1? */
1240 case 0x00: /* unknown type / unknown numbering plan */
1241 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1245 "%s: %s type/plan 0x%02x unsupported\n",
1246 "CONNECT_REQ", "Calling party number", *pp);
1251 /* check presentation indicator */
1253 dev_notice(cs->dev, "%s: %s IE truncated\n",
1254 "CONNECT_REQ", "Calling party number");
1255 info = CapiIllMessageParmCoding;
1258 switch (*pp & 0xfc) { /* ignore Screening indicator */
1259 case 0x80: /* Presentation allowed */
1262 case 0xa0: /* Presentation restricted */
1266 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1268 "Presentation/Screening indicator",
1272 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1273 if (!commands[AT_CLIP])
1280 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1281 if (!commands[AT_MSN])
1283 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1287 /* check parameter: CIP Value */
1288 if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
1289 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1290 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1291 "CONNECT_REQ", cmsg->CIPValue);
1292 info = CapiCipValueUnknown;
1297 * check/encode parameters: BC & HLC
1298 * must be encoded together as device doesn't accept HLC separately
1299 * explicit parameters override values derived from CIP
1302 /* determine lengths */
1303 if (cmsg->BC && cmsg->BC[0]) /* BC specified explicitly */
1304 lbc = 2*cmsg->BC[0];
1305 else if (cip2bchlc[cmsg->CIPValue].bc) /* BC derived from CIP */
1306 lbc = strlen(cip2bchlc[cmsg->CIPValue].bc);
1309 if (cmsg->HLC && cmsg->HLC[0]) /* HLC specified explicitly */
1310 lhlc = 2*cmsg->HLC[0];
1311 else if (cip2bchlc[cmsg->CIPValue].hlc) /* HLC derived from CIP */
1312 lhlc = strlen(cip2bchlc[cmsg->CIPValue].hlc);
1317 /* have BC: allocate and assemble command string */
1318 l = lbc + 7; /* "^SBC=" + value + "\r" + null byte */
1320 l += lhlc + 7; /* ";^SHLC=" + value */
1321 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1322 if (!commands[AT_BC])
1324 strcpy(commands[AT_BC], "^SBC=");
1325 if (cmsg->BC && cmsg->BC[0]) /* BC specified explicitly */
1326 decode_ie(cmsg->BC, commands[AT_BC] + 5);
1327 else /* BC derived from CIP */
1328 strcpy(commands[AT_BC] + 5,
1329 cip2bchlc[cmsg->CIPValue].bc);
1331 strcpy(commands[AT_BC] + lbc + 5, ";^SHLC=");
1332 if (cmsg->HLC && cmsg->HLC[0])
1333 /* HLC specified explicitly */
1334 decode_ie(cmsg->HLC,
1335 commands[AT_BC] + lbc + 12);
1336 else /* HLC derived from CIP */
1337 strcpy(commands[AT_BC] + lbc + 12,
1338 cip2bchlc[cmsg->CIPValue].hlc);
1340 strcpy(commands[AT_BC] + l - 2, "\r");
1344 dev_notice(cs->dev, "%s: cannot set HLC without BC\n",
1346 info = CapiIllMessageParmCoding; /* ? */
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_VOICE;
1366 "B1 Protocol %u unsupported, using Transparent\n",
1368 bcs->proto2 = L2_VOICE;
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->rx_bufsize = ap->rp.datablklen;
1476 dev_kfree_skb(bcs->rx_skb);
1477 gigaset_new_rx_skb(bcs);
1478 bcs->chstate |= CHS_NOTIFY_LL;
1480 /* check/encode B channel protocol */
1481 if (cmsg->BProtocol == CAPI_DEFAULT) {
1482 bcs->proto2 = L2_HDLC;
1484 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1486 switch (cmsg->B1protocol) {
1488 bcs->proto2 = L2_HDLC;
1491 bcs->proto2 = L2_VOICE;
1495 "B1 Protocol %u unsupported, using Transparent\n",
1497 bcs->proto2 = L2_VOICE;
1499 if (cmsg->B2protocol != 1)
1501 "B2 Protocol %u unsupported, using Transparent\n",
1503 if (cmsg->B3protocol != 0)
1505 "B3 Protocol %u unsupported, using Transparent\n",
1507 ignore_cstruct_param(cs, cmsg->B1configuration,
1508 "CONNECT_RESP", "B1 Configuration");
1509 ignore_cstruct_param(cs, cmsg->B2configuration,
1510 "CONNECT_RESP", "B2 Configuration");
1511 ignore_cstruct_param(cs, cmsg->B3configuration,
1512 "CONNECT_RESP", "B3 Configuration");
1515 /* ToDo: check/encode remaining parameters */
1516 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1517 "CONNECT_RESP", "Connected Number");
1518 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1519 "CONNECT_RESP", "Connected Subaddress");
1520 ignore_cstruct_param(cs, cmsg->LLC,
1521 "CONNECT_RESP", "LLC");
1522 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1523 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1524 "CONNECT_RESP", "BChannel Information");
1525 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1526 "CONNECT_RESP", "Keypad Facility");
1527 ignore_cstruct_param(cs, cmsg->Useruserdata,
1528 "CONNECT_RESP", "User-User Data");
1529 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1530 "CONNECT_RESP", "Facility Data Array");
1534 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1535 EV_ACCEPT, NULL, 0, NULL))
1537 gigaset_schedule_event(cs);
1540 case 1: /* Ignore */
1541 /* send DISCONNECT_IND to this application */
1542 send_disconnect_ind(bcs, ap, 0);
1544 /* remove it from the list of listening apps */
1545 if (bcs->ap == ap) {
1546 bcs->ap = ap->bcnext;
1547 if (bcs->ap == NULL)
1548 /* last one: stop ev-layer hupD notifications */
1549 bcs->chstate &= ~CHS_NOTIFY_LL;
1552 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1553 if (oap->bcnext == ap) {
1554 oap->bcnext = oap->bcnext->bcnext;
1558 dev_err(cs->dev, "%s: application %u not found\n",
1562 default: /* Reject */
1563 /* drop all competing applications, keep only this one */
1564 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1566 send_disconnect_ind(bcs, oap,
1567 CapiCallGivenToOtherApplication);
1571 /* reject call - will trigger DISCONNECT_IND for this app */
1572 dev_info(cs->dev, "%s: Reject=%x\n",
1573 "CONNECT_RESP", cmsg->Reject);
1574 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1575 EV_HUP, NULL, 0, NULL))
1577 gigaset_schedule_event(cs);
1583 * process CONNECT_B3_REQ message
1584 * build NCCI and emit CONNECT_B3_CONF reply
1586 static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1587 struct gigaset_capi_appl *ap,
1588 struct sk_buff *skb)
1590 struct cardstate *cs = iif->ctr.driverdata;
1591 _cmsg *cmsg = &iif->acmsg;
1594 /* decode message */
1595 capi_message2cmsg(cmsg, skb->data);
1596 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1598 /* extract and check channel number from PLCI */
1599 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1600 if (!channel || channel > cs->channels) {
1601 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1602 "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
1603 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1607 /* mark logical connection active */
1608 ap->connected = APCONN_ACTIVE;
1610 /* build NCCI: always 1 (one B3 connection only) */
1611 cmsg->adr.adrNCCI |= 1 << 16;
1613 /* NCPI parameter: not applicable for B3 Transparent */
1614 ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
1615 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1616 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1620 * process CONNECT_B3_RESP message
1621 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1622 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1623 * The emitted message is always shorter than the received one,
1624 * allowing to reuse the skb.
1626 static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1627 struct gigaset_capi_appl *ap,
1628 struct sk_buff *skb)
1630 struct cardstate *cs = iif->ctr.driverdata;
1631 _cmsg *cmsg = &iif->acmsg;
1632 struct bc_state *bcs;
1634 unsigned int msgsize;
1637 /* decode message */
1638 capi_message2cmsg(cmsg, skb->data);
1639 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1641 /* extract and check channel number and NCCI */
1642 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1643 if (!channel || channel > cs->channels ||
1644 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1645 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1646 "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
1647 dev_kfree_skb_any(skb);
1650 bcs = &cs->bcs[channel-1];
1653 /* Reject: clear B3 connect received flag */
1654 ap->connected = APCONN_SETUP;
1656 /* trigger hangup, causing eventual DISCONNECT_IND */
1657 if (!gigaset_add_event(cs, &bcs->at_state,
1658 EV_HUP, NULL, 0, NULL)) {
1659 dev_kfree_skb_any(skb);
1662 gigaset_schedule_event(cs);
1664 /* emit DISCONNECT_B3_IND */
1665 command = CAPI_DISCONNECT_B3;
1666 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1669 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1670 * we only send CONNECT_B3_IND if the B channel is up
1672 command = CAPI_CONNECT_B3_ACTIVE;
1673 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1675 capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
1676 ap->nextMessageNumber++, cmsg->adr.adrNCCI);
1677 __skb_trim(skb, msgsize);
1678 capi_cmsg2message(cmsg, skb->data);
1679 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1680 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1684 * process DISCONNECT_REQ message
1685 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1686 * emit DISCONNECT_CONF reply
1688 static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1689 struct gigaset_capi_appl *ap,
1690 struct sk_buff *skb)
1692 struct cardstate *cs = iif->ctr.driverdata;
1693 _cmsg *cmsg = &iif->acmsg;
1694 struct bc_state *bcs;
1696 struct sk_buff *b3skb;
1699 /* decode message */
1700 capi_message2cmsg(cmsg, skb->data);
1701 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1703 /* extract and check channel number from PLCI */
1704 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1705 if (!channel || channel > cs->channels) {
1706 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1707 "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
1708 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1711 bcs = cs->bcs + channel - 1;
1713 /* ToDo: process parameter: Additional info */
1714 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1715 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1716 "DISCONNECT_REQ", "B Channel Information");
1717 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1718 "DISCONNECT_REQ", "Keypad Facility");
1719 ignore_cstruct_param(cs, cmsg->Useruserdata,
1720 "DISCONNECT_REQ", "User-User Data");
1721 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1722 "DISCONNECT_REQ", "Facility Data Array");
1725 /* skip if DISCONNECT_IND already sent */
1729 /* check for active logical connection */
1730 if (ap->connected >= APCONN_ACTIVE) {
1732 * emit DISCONNECT_B3_IND with cause 0x3301
1733 * use separate cmsg structure, as the content of iif->acmsg
1734 * is still needed for creating the _CONF message
1736 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1738 dev_err(cs->dev, "%s: out of memory\n", __func__);
1739 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1742 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1743 ap->nextMessageNumber++,
1744 cmsg->adr.adrPLCI | (1 << 16));
1745 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1746 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1747 if (b3skb == NULL) {
1748 dev_err(cs->dev, "%s: out of memory\n", __func__);
1749 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1752 capi_cmsg2message(b3cmsg,
1753 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1755 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1758 /* trigger hangup, causing eventual DISCONNECT_IND */
1759 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1760 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1763 gigaset_schedule_event(cs);
1766 send_conf(iif, ap, skb, CapiSuccess);
1770 * process DISCONNECT_B3_REQ message
1771 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1773 static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1774 struct gigaset_capi_appl *ap,
1775 struct sk_buff *skb)
1777 struct cardstate *cs = iif->ctr.driverdata;
1778 _cmsg *cmsg = &iif->acmsg;
1781 /* decode message */
1782 capi_message2cmsg(cmsg, skb->data);
1783 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1785 /* extract and check channel number and NCCI */
1786 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1787 if (!channel || channel > cs->channels ||
1788 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1789 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1790 "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
1791 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1795 /* reject if logical connection not active */
1796 if (ap->connected < APCONN_ACTIVE) {
1797 send_conf(iif, ap, skb,
1798 CapiMessageNotSupportedInCurrentState);
1802 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1803 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1804 EV_HUP, NULL, 0, NULL)) {
1805 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1808 gigaset_schedule_event(cs);
1810 /* NCPI parameter: not applicable for B3 Transparent */
1811 ignore_cstruct_param(cs, cmsg->NCPI,
1812 "DISCONNECT_B3_REQ", "NCPI");
1813 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1814 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1818 * process DATA_B3_REQ message
1820 static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1821 struct gigaset_capi_appl *ap,
1822 struct sk_buff *skb)
1824 struct cardstate *cs = iif->ctr.driverdata;
1825 int channel = CAPIMSG_PLCI_PART(skb->data);
1826 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1827 u16 msglen = CAPIMSG_LEN(skb->data);
1828 u16 datalen = CAPIMSG_DATALEN(skb->data);
1829 u16 flags = CAPIMSG_FLAGS(skb->data);
1830 u16 msgid = CAPIMSG_MSGID(skb->data);
1831 u16 handle = CAPIMSG_HANDLE_REQ(skb->data);
1833 /* frequent message, avoid _cmsg overhead */
1834 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1836 gig_dbg(DEBUG_LLDATA,
1837 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1838 channel, flags, msglen, datalen);
1840 /* check parameters */
1841 if (channel == 0 || channel > cs->channels || ncci != 1) {
1842 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1843 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1844 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1847 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1848 dev_notice(cs->dev, "%s: unexpected length %d\n",
1849 "DATA_B3_REQ", msglen);
1850 if (msglen + datalen != skb->len)
1851 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1852 "DATA_B3_REQ", msglen, datalen, skb->len);
1853 if (msglen + datalen > skb->len) {
1854 /* message too short for announced data length */
1855 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1858 if (flags & CAPI_FLAGS_RESERVED) {
1859 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1860 "DATA_B3_REQ", flags);
1861 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1865 /* reject if logical connection not active */
1866 if (ap->connected < APCONN_ACTIVE) {
1867 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1871 /* pull CAPI message into link layer header */
1872 skb_reset_mac_header(skb);
1873 skb->mac_len = msglen;
1874 skb_pull(skb, msglen);
1876 /* pass to device-specific module */
1877 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1878 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1883 * DATA_B3_CONF will be sent by gigaset_skb_sent() only if "delivery
1884 * confirmation" bit is set; otherwise we have to send it now
1886 if (!(flags & CAPI_FLAGS_DELIVERY_CONFIRMATION))
1887 send_data_b3_conf(cs, &iif->ctr, ap->id, msgid, channel, handle,
1888 flags ? CapiFlagsNotSupportedByProtocol
1893 * process RESET_B3_REQ message
1894 * just always reply "not supported by current protocol"
1896 static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1897 struct gigaset_capi_appl *ap,
1898 struct sk_buff *skb)
1900 /* decode message */
1901 capi_message2cmsg(&iif->acmsg, skb->data);
1902 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1903 send_conf(iif, ap, skb,
1904 CapiResetProcedureNotSupportedByCurrentProtocol);
1908 * dump unsupported/ignored messages at most twice per minute,
1909 * some apps send those very frequently
1911 static unsigned long ignored_msg_dump_time;
1914 * unsupported CAPI message handler
1916 static void do_unsupported(struct gigaset_capi_ctr *iif,
1917 struct gigaset_capi_appl *ap,
1918 struct sk_buff *skb)
1920 /* decode message */
1921 capi_message2cmsg(&iif->acmsg, skb->data);
1922 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1923 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1924 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1928 * CAPI message handler: no-op
1930 static void do_nothing(struct gigaset_capi_ctr *iif,
1931 struct gigaset_capi_appl *ap,
1932 struct sk_buff *skb)
1934 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1935 /* decode message */
1936 capi_message2cmsg(&iif->acmsg, skb->data);
1937 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1939 dev_kfree_skb_any(skb);
1942 static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1943 struct gigaset_capi_appl *ap,
1944 struct sk_buff *skb)
1946 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1947 dev_kfree_skb_any(skb);
1950 /* table of outgoing CAPI message handlers with lookup function */
1951 typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1952 struct gigaset_capi_appl *,
1957 capi_send_handler_t handler;
1958 } capi_send_handler_table[] = {
1959 /* most frequent messages first for faster lookup */
1960 { CAPI_DATA_B3_REQ, do_data_b3_req },
1961 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1963 { CAPI_ALERT_REQ, do_alert_req },
1964 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1965 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1966 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1967 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1968 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1969 { CAPI_CONNECT_REQ, do_connect_req },
1970 { CAPI_CONNECT_RESP, do_connect_resp },
1971 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1972 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1973 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1974 { CAPI_DISCONNECT_RESP, do_nothing },
1975 { CAPI_FACILITY_REQ, do_facility_req },
1976 { CAPI_FACILITY_RESP, do_nothing },
1977 { CAPI_LISTEN_REQ, do_listen_req },
1978 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1979 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1980 { CAPI_RESET_B3_RESP, do_nothing },
1983 * ToDo: support overlap sending (requires ev-layer state
1984 * machine extension to generate additional ATD commands)
1986 { CAPI_INFO_REQ, do_unsupported },
1987 { CAPI_INFO_RESP, do_nothing },
1990 * ToDo: what's the proper response for these?
1992 { CAPI_MANUFACTURER_REQ, do_nothing },
1993 { CAPI_MANUFACTURER_RESP, do_nothing },
1996 /* look up handler */
1997 static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
2001 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
2002 if (capi_send_handler_table[i].cmd == cmd)
2003 return capi_send_handler_table[i].handler;
2009 * gigaset_send_message() - accept a CAPI message from an application
2010 * @ctr: controller descriptor structure.
2011 * @skb: CAPI message.
2013 * Return value: CAPI error code
2014 * Note: capidrv (and probably others, too) only uses the return value to
2015 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2017 static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2019 struct gigaset_capi_ctr *iif
2020 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2021 struct cardstate *cs = ctr->driverdata;
2022 struct gigaset_capi_appl *ap;
2023 capi_send_handler_t handler;
2025 /* can only handle linear sk_buffs */
2026 if (skb_linearize(skb) < 0) {
2027 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2028 return CAPI_MSGOSRESOURCEERR;
2031 /* retrieve application data structure */
2032 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2034 dev_notice(cs->dev, "%s: application %u not registered\n",
2035 __func__, CAPIMSG_APPID(skb->data));
2036 return CAPI_ILLAPPNR;
2039 /* look up command */
2040 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2042 /* unknown/unsupported message type */
2043 if (printk_ratelimit())
2044 dev_notice(cs->dev, "%s: unsupported message %u\n",
2045 __func__, CAPIMSG_CMD(skb->data));
2046 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2050 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2051 /* queue behind other messages */
2052 skb_queue_tail(&iif->sendqueue, skb);
2053 return CAPI_NOERROR;
2056 /* process message */
2057 handler(iif, ap, skb);
2059 /* process other messages arrived in the meantime */
2060 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2061 skb = skb_dequeue(&iif->sendqueue);
2063 /* should never happen */
2064 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2067 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2069 /* could that happen? */
2070 dev_warn(cs->dev, "%s: application %u vanished\n",
2071 __func__, CAPIMSG_APPID(skb->data));
2074 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2076 /* should never happen */
2077 dev_err(cs->dev, "%s: handler %x vanished\n",
2078 __func__, CAPIMSG_CMD(skb->data));
2081 handler(iif, ap, skb);
2084 return CAPI_NOERROR;
2088 * gigaset_procinfo() - build single line description for controller
2089 * @ctr: controller descriptor structure.
2091 * Return value: pointer to generated string (null terminated)
2093 static char *gigaset_procinfo(struct capi_ctr *ctr)
2095 return ctr->name; /* ToDo: more? */
2098 static int gigaset_proc_show(struct seq_file *m, void *v)
2100 struct capi_ctr *ctr = m->private;
2101 struct cardstate *cs = ctr->driverdata;
2105 seq_printf(m, "%-16s %s\n", "name", ctr->name);
2106 seq_printf(m, "%-16s %s %s\n", "dev",
2107 dev_driver_string(cs->dev), dev_name(cs->dev));
2108 seq_printf(m, "%-16s %d\n", "id", cs->myid);
2110 seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
2111 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2112 seq_printf(m, "%-16s %d\n", "channels", cs->channels);
2113 seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
2131 seq_printf(m, "%-16s %s\n", "mode", s);
2133 switch (cs->mstate) {
2134 case MS_UNINITIALIZED:
2135 s = "uninitialized";
2155 seq_printf(m, "%-16s %s\n", "mstate", s);
2157 seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
2158 seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
2159 seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
2160 seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
2162 for (i = 0; i < cs->channels; i++) {
2163 seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
2164 cs->bcs[i].corrupted);
2165 seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
2166 cs->bcs[i].trans_down);
2167 seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
2168 cs->bcs[i].trans_up);
2169 seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
2170 cs->bcs[i].chstate);
2171 switch (cs->bcs[i].proto2) {
2184 seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
2189 static int gigaset_proc_open(struct inode *inode, struct file *file)
2191 return single_open(file, gigaset_proc_show, PDE(inode)->data);
2194 static const struct file_operations gigaset_proc_fops = {
2195 .owner = THIS_MODULE,
2196 .open = gigaset_proc_open,
2198 .llseek = seq_lseek,
2199 .release = single_release,
2203 * gigaset_isdn_regdev() - register device to LL
2204 * @cs: device descriptor structure.
2205 * @isdnid: device name.
2207 * Return value: 1 for success, 0 for failure
2209 int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
2211 struct gigaset_capi_ctr *iif;
2214 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2216 pr_err("%s: out of memory\n", __func__);
2220 /* prepare controller structure */
2221 iif->ctr.owner = THIS_MODULE;
2222 iif->ctr.driverdata = cs;
2223 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2224 iif->ctr.driver_name = "gigaset";
2225 iif->ctr.load_firmware = NULL;
2226 iif->ctr.reset_ctr = NULL;
2227 iif->ctr.register_appl = gigaset_register_appl;
2228 iif->ctr.release_appl = gigaset_release_appl;
2229 iif->ctr.send_message = gigaset_send_message;
2230 iif->ctr.procinfo = gigaset_procinfo;
2231 iif->ctr.proc_fops = &gigaset_proc_fops;
2232 INIT_LIST_HEAD(&iif->appls);
2233 skb_queue_head_init(&iif->sendqueue);
2234 atomic_set(&iif->sendqlen, 0);
2236 /* register controller with CAPI */
2237 rc = attach_capi_ctr(&iif->ctr);
2239 pr_err("attach_capi_ctr failed (%d)\n", rc);
2245 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2250 * gigaset_isdn_unregdev() - unregister device from LL
2251 * @cs: device descriptor structure.
2253 void gigaset_isdn_unregdev(struct cardstate *cs)
2255 struct gigaset_capi_ctr *iif = cs->iif;
2257 detach_capi_ctr(&iif->ctr);
2262 static struct capi_driver capi_driver_gigaset = {
2268 * gigaset_isdn_regdrv() - register driver to LL
2270 void gigaset_isdn_regdrv(void)
2272 pr_info("Kernel CAPI interface\n");
2273 register_capi_driver(&capi_driver_gigaset);
2277 * gigaset_isdn_unregdrv() - unregister driver from LL
2279 void gigaset_isdn_unregdrv(void)
2281 unregister_capi_driver(&capi_driver_gigaset);