2 * Kernel CAPI interface for the Gigaset driver
4 * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
15 #include <linux/ctype.h>
16 #include <linux/isdn/capilli.h>
17 #include <linux/isdn/capicmd.h>
18 #include <linux/isdn/capiutil.h>
20 /* missing from kernelcapi.h */
21 #define CapiNcpiNotSupportedByProtocol 0x0001
22 #define CapiFlagsNotSupportedByProtocol 0x0002
23 #define CapiAlertAlreadySent 0x0003
24 #define CapiFacilitySpecificFunctionNotSupported 0x3011
26 /* missing from capicmd.h */
27 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
28 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
29 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
30 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
31 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
32 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
33 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
34 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
35 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
36 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
37 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
39 #define CAPI_FACILITY_HANDSET 0x0000
40 #define CAPI_FACILITY_DTMF 0x0001
41 #define CAPI_FACILITY_V42BIS 0x0002
42 #define CAPI_FACILITY_SUPPSVC 0x0003
43 #define CAPI_FACILITY_WAKEUP 0x0004
44 #define CAPI_FACILITY_LI 0x0005
46 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
48 /* missing from capiutil.h */
49 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
50 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
51 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
52 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
53 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
54 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
55 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
56 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
58 /* parameters with differing location in DATA_B3_CONF/_RESP: */
59 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
60 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
62 /* Flags (DATA_B3_REQ/_IND) */
63 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
64 #define CAPI_FLAGS_RESERVED (~0x1f)
67 #define MAX_BC_OCTETS 11
68 #define MAX_HLC_OCTETS 3
69 #define MAX_NUMBER_DIGITS 20
70 #define MAX_FMT_IE_LEN 20
72 /* values for gigaset_capi_appl.connected */
73 #define APCONN_NONE 0 /* inactive/listening */
74 #define APCONN_SETUP 1 /* connecting */
75 #define APCONN_ACTIVE 2 /* B channel up */
77 /* registered application data structure */
78 struct gigaset_capi_appl {
79 struct list_head ctrlist;
80 struct gigaset_capi_appl *bcnext;
82 u16 nextMessageNumber;
88 /* CAPI specific controller data structure */
89 struct gigaset_capi_ctr {
91 struct list_head appls;
92 struct sk_buff_head sendqueue;
94 /* two _cmsg structures possibly used concurrently: */
95 _cmsg hcmsg; /* for message composition triggered from hardware */
96 _cmsg acmsg; /* for dissection of messages sent from application */
97 u8 bc_buf[MAX_BC_OCTETS+1];
98 u8 hlc_buf[MAX_HLC_OCTETS+1];
99 u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
100 u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
103 /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
108 [1] = { "8090A3", NULL },
110 [2] = { "8890", NULL },
111 /* Unrestricted digital information */
112 [3] = { "8990", NULL },
113 /* Restricted digital information */
114 [4] = { "9090A3", NULL },
115 /* 3,1 kHz audio (A-law) */
116 [5] = { "9190", NULL },
118 [6] = { "9890", NULL },
120 [7] = { "88C0C6E6", NULL },
122 [8] = { "8890218F", NULL },
123 /* 56 kbit/s rate adaptation */
124 [9] = { "9190A5", NULL },
125 /* Unrestricted digital information with tones/announcements */
126 [16] = { "8090A3", "9181" },
128 [17] = { "9090A3", "9184" },
129 /* Group 2/3 facsimile */
130 [18] = { "8890", "91A1" },
131 /* Group 4 facsimile Class 1 */
132 [19] = { "8890", "91A4" },
133 /* Teletex service basic and mixed mode
134 and Group 4 facsimile service Classes II and III */
135 [20] = { "8890", "91A8" },
136 /* Teletex service basic and processable mode */
137 [21] = { "8890", "91B1" },
138 /* Teletex service basic mode */
139 [22] = { "8890", "91B2" },
140 /* International interworking for Videotex */
141 [23] = { "8890", "91B5" },
143 [24] = { "8890", "91B8" },
144 /* Message Handling Systems in accordance with X.400 */
145 [25] = { "8890", "91C1" },
146 /* OSI application in accordance with X.200 */
147 [26] = { "9190A5", "9181" },
148 /* 7 kHz telephony */
149 [27] = { "9190A5", "916001" },
150 /* Video telephony, first connection */
151 [28] = { "8890", "916002" },
152 /* Video telephony, second connection */
161 * emit unsupported parameter warning
163 static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
164 char *msgname, char *paramname)
167 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
172 * check for legal hex digit
174 static inline int ishexdigit(char c)
176 if (c >= '0' && c <= '9')
178 if (c >= 'A' && c <= 'F')
180 if (c >= 'a' && c <= 'f')
186 * convert hex to binary
188 static inline u8 hex2bin(char c)
190 int result = c & 0x0f;
197 * convert an IE from Gigaset hex string to ETSI binary representation
198 * including length byte
199 * return value: result length, -1 on error
201 static int encode_ie(char *in, u8 *out, int maxlen)
205 if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
207 out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
215 * convert an IE from ETSI binary representation including length byte
216 * to Gigaset hex string
218 static void decode_ie(u8 *in, char *out)
222 /* ToDo: conversion to upper case necessary? */
223 *out++ = toupper(hex_asc_hi(*++in));
224 *out++ = toupper(hex_asc_lo(*in));
229 * retrieve application data structure for an application ID
231 static inline struct gigaset_capi_appl *
232 get_appl(struct gigaset_capi_ctr *iif, u16 appl)
234 struct gigaset_capi_appl *ap;
236 list_for_each_entry(ap, &iif->appls, ctrlist)
243 * dump CAPI message to kernel messages for debugging
245 static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
247 #ifdef CONFIG_GIGASET_DEBUG
250 if (!(gigaset_debuglevel & level))
253 cdb = capi_cmsg2str(p);
255 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
258 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
259 capi_cmd2str(p->Command, p->Subcommand));
264 static inline void dump_rawmsg(enum debuglevel level, const char *tag,
267 #ifdef CONFIG_GIGASET_DEBUG
271 if (!(gigaset_debuglevel & level))
274 l = CAPIMSG_LEN(data);
276 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
279 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
280 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
281 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
282 CAPIMSG_CONTROL(data));
284 dbgline = kmalloc(3*l, GFP_ATOMIC);
287 for (i = 0; i < l; i++) {
288 dbgline[3*i] = hex_asc_hi(data[12+i]);
289 dbgline[3*i+1] = hex_asc_lo(data[12+i]);
290 dbgline[3*i+2] = ' ';
292 dbgline[3*l-1] = '\0';
293 gig_dbg(level, " %s", dbgline);
295 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
296 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
297 CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
298 CAPIMSG_DATALEN(data) > 0) {
299 l = CAPIMSG_DATALEN(data);
300 dbgline = kmalloc(3*l, GFP_ATOMIC);
303 data += CAPIMSG_LEN(data);
304 for (i = 0; i < l; i++) {
305 dbgline[3*i] = hex_asc_hi(data[i]);
306 dbgline[3*i+1] = hex_asc_lo(data[i]);
307 dbgline[3*i+2] = ' ';
309 dbgline[3*l-1] = '\0';
310 gig_dbg(level, " %s", dbgline);
317 * format CAPI IE as string
320 static const char *format_ie(const char *ie)
322 static char result[3*MAX_FMT_IE_LEN];
330 if (count > MAX_FMT_IE_LEN)
331 count = MAX_FMT_IE_LEN-1;
333 *pout++ = hex_asc_hi(*++ie);
334 *pout++ = hex_asc_lo(*ie);
337 if (len > MAX_FMT_IE_LEN) {
348 * driver interface functions
349 * ==========================
353 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
354 * @bcs: B channel descriptor structure.
357 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
358 * skb has been successfully sent, for signalling completion to the LL.
360 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
362 struct cardstate *cs = bcs->cs;
363 struct gigaset_capi_ctr *iif = cs->iif;
364 struct gigaset_capi_appl *ap = bcs->ap;
365 struct sk_buff *cskb;
368 /* update statistics */
372 dev_err(cs->dev, "%s: no application\n", __func__);
376 /* don't send further B3 messages if disconnected */
377 if (ap->connected < APCONN_ACTIVE) {
378 gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
382 /* ToDo: honor unset "delivery confirmation" bit */
383 flags = CAPIMSG_FLAGS(dskb->head);
385 /* build DATA_B3_CONF message */
386 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
388 dev_err(cs->dev, "%s: out of memory\n", __func__);
391 /* frequent message, avoid _cmsg overhead */
392 CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
393 CAPIMSG_SETAPPID(cskb->data, ap->id);
394 CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
395 CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
396 CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(dskb->head));
397 CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
398 CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
399 CAPIMSG_SETNCCI_PART(cskb->data, 1);
400 CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(dskb->head));
401 if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
402 CAPIMSG_SETINFO_CONF(cskb->data,
403 CapiFlagsNotSupportedByProtocol);
405 CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
408 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
409 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
411 EXPORT_SYMBOL_GPL(gigaset_skb_sent);
414 * gigaset_skb_rcvd() - pass received skb to LL
415 * @bcs: B channel descriptor structure.
416 * @skb: received data.
418 * Called by hardware module {bas,ser,usb}_gigaset when user data has
419 * been successfully received, for passing to the LL.
420 * Warning: skb must not be accessed anymore!
422 void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
424 struct cardstate *cs = bcs->cs;
425 struct gigaset_capi_ctr *iif = cs->iif;
426 struct gigaset_capi_appl *ap = bcs->ap;
429 /* update statistics */
433 dev_err(cs->dev, "%s: no application\n", __func__);
437 /* don't send further B3 messages if disconnected */
438 if (ap->connected < APCONN_ACTIVE) {
439 gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
445 * prepend DATA_B3_IND message to payload
446 * Parameters: NCCI = 1, all others 0/unused
447 * frequent message, avoid _cmsg overhead
449 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
450 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
451 CAPIMSG_SETAPPID(skb->data, ap->id);
452 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
453 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
454 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
455 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
456 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
457 CAPIMSG_SETNCCI_PART(skb->data, 1);
458 /* Data parameter not used */
459 CAPIMSG_SETDATALEN(skb->data, len);
460 /* Data handle parameter not used */
461 CAPIMSG_SETFLAGS(skb->data, 0);
462 /* Data64 parameter not present */
465 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
466 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
468 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
471 * gigaset_isdn_rcv_err() - signal receive error
472 * @bcs: B channel descriptor structure.
474 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
475 * has occurred, for signalling to the LL.
477 void gigaset_isdn_rcv_err(struct bc_state *bcs)
479 /* if currently ignoring packets, just count down */
485 /* update statistics */
488 /* ToDo: signal error -> LL */
490 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
493 * gigaset_isdn_icall() - signal incoming call
494 * @at_state: connection state structure.
496 * Called by main module at tasklet level to notify the LL that an incoming
497 * call has been received. @at_state contains the parameters of the call.
499 * Return value: call disposition (ICALL_*)
501 int gigaset_isdn_icall(struct at_state_t *at_state)
503 struct cardstate *cs = at_state->cs;
504 struct bc_state *bcs = at_state->bcs;
505 struct gigaset_capi_ctr *iif = cs->iif;
506 struct gigaset_capi_appl *ap;
509 unsigned int msgsize;
513 * ToDo: signal calls without a free B channel, too
514 * (requires a u8 handle for the at_state structure that can
515 * be stored in the PLCI and used in the CONNECT_RESP message
516 * handler to retrieve it)
521 /* prepare CONNECT_IND message, using B channel number as PLCI */
522 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
523 iif->ctr.cnr | ((bcs->channel + 1) << 8));
525 /* minimum size, all structs empty */
526 msgsize = CAPI_CONNECT_IND_BASELEN;
528 /* Bearer Capability (mandatory) */
529 if (at_state->str_var[STR_ZBC]) {
530 /* pass on BC from Gigaset */
531 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
532 MAX_BC_OCTETS) < 0) {
533 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
534 at_state->str_var[STR_ZBC]);
538 /* look up corresponding CIP value */
539 iif->hcmsg.CIPValue = 0; /* default if nothing found */
540 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
541 if (cip2bchlc[i].bc != NULL &&
542 cip2bchlc[i].hlc == NULL &&
543 !strcmp(cip2bchlc[i].bc,
544 at_state->str_var[STR_ZBC])) {
545 iif->hcmsg.CIPValue = i;
549 /* no BC (internal call): assume CIP 1 (speech, A-law) */
550 iif->hcmsg.CIPValue = 1;
551 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
553 iif->hcmsg.BC = iif->bc_buf;
554 msgsize += iif->hcmsg.BC[0];
556 /* High Layer Compatibility (optional) */
557 if (at_state->str_var[STR_ZHLC]) {
558 /* pass on HLC from Gigaset */
559 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
560 MAX_HLC_OCTETS) < 0) {
561 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
562 at_state->str_var[STR_ZHLC]);
565 iif->hcmsg.HLC = iif->hlc_buf;
566 msgsize += iif->hcmsg.HLC[0];
568 /* look up corresponding CIP value */
569 /* keep BC based CIP value if none found */
570 if (at_state->str_var[STR_ZBC])
571 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
572 if (cip2bchlc[i].hlc != NULL &&
573 !strcmp(cip2bchlc[i].hlc,
574 at_state->str_var[STR_ZHLC]) &&
575 !strcmp(cip2bchlc[i].bc,
576 at_state->str_var[STR_ZBC])) {
577 iif->hcmsg.CIPValue = i;
582 /* Called Party Number (optional) */
583 if (at_state->str_var[STR_ZCPN]) {
584 i = strlen(at_state->str_var[STR_ZCPN]);
585 if (i > MAX_NUMBER_DIGITS) {
586 dev_warn(cs->dev, "RING ignored - bad number %s\n",
587 at_state->str_var[STR_ZBC]);
590 iif->cdpty_buf[0] = i + 1;
591 iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
592 memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
593 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
594 msgsize += iif->hcmsg.CalledPartyNumber[0];
597 /* Calling Party Number (optional) */
598 if (at_state->str_var[STR_NMBR]) {
599 i = strlen(at_state->str_var[STR_NMBR]);
600 if (i > MAX_NUMBER_DIGITS) {
601 dev_warn(cs->dev, "RING ignored - bad number %s\n",
602 at_state->str_var[STR_ZBC]);
605 iif->cgpty_buf[0] = i + 2;
606 iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
607 iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
608 memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
609 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
610 msgsize += iif->hcmsg.CallingPartyNumber[0];
613 /* remaining parameters (not supported, always left NULL):
614 * - CalledPartySubaddress
615 * - CallingPartySubaddress
617 * - BChannelinformation
620 * - Facilitydataarray
623 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
624 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
625 format_ie(iif->hcmsg.BC));
626 gig_dbg(DEBUG_CMD, "icall: HLC %s",
627 format_ie(iif->hcmsg.HLC));
628 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
629 format_ie(iif->hcmsg.CallingPartyNumber));
630 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
631 format_ie(iif->hcmsg.CalledPartyNumber));
633 /* scan application list for matching listeners */
635 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
636 list_for_each_entry(ap, &iif->appls, ctrlist)
637 if (actCIPmask & ap->listenCIPmask) {
638 /* build CONNECT_IND message for this application */
639 iif->hcmsg.ApplId = ap->id;
640 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
642 skb = alloc_skb(msgsize, GFP_ATOMIC);
644 dev_err(cs->dev, "%s: out of memory\n",
648 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
649 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
651 /* add to listeners on this B channel, update state */
652 ap->bcnext = bcs->ap;
654 bcs->chstate |= CHS_NOTIFY_LL;
655 ap->connected = APCONN_SETUP;
658 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
662 * Return "accept" if any listeners.
663 * Gigaset will send ALERTING.
664 * There doesn't seem to be a way to avoid this.
666 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
670 * send a DISCONNECT_IND message to an application
671 * does not sleep, clobbers the controller's hcmsg structure
673 static void send_disconnect_ind(struct bc_state *bcs,
674 struct gigaset_capi_appl *ap, u16 reason)
676 struct cardstate *cs = bcs->cs;
677 struct gigaset_capi_ctr *iif = cs->iif;
680 if (ap->connected == APCONN_NONE)
683 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
684 ap->nextMessageNumber++,
685 iif->ctr.cnr | ((bcs->channel + 1) << 8));
686 iif->hcmsg.Reason = reason;
687 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
689 dev_err(cs->dev, "%s: out of memory\n", __func__);
692 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
693 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
694 ap->connected = APCONN_NONE;
695 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
699 * send a DISCONNECT_B3_IND message to an application
700 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
701 * does not sleep, clobbers the controller's hcmsg structure
703 static void send_disconnect_b3_ind(struct bc_state *bcs,
704 struct gigaset_capi_appl *ap)
706 struct cardstate *cs = bcs->cs;
707 struct gigaset_capi_ctr *iif = cs->iif;
710 /* nothing to do if no logical connection active */
711 if (ap->connected < APCONN_ACTIVE)
713 ap->connected = APCONN_SETUP;
715 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
716 ap->nextMessageNumber++,
717 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
718 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
720 dev_err(cs->dev, "%s: out of memory\n", __func__);
723 capi_cmsg2message(&iif->hcmsg,
724 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
725 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
726 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
730 * gigaset_isdn_connD() - signal D channel connect
731 * @bcs: B channel descriptor structure.
733 * Called by main module at tasklet level to notify the LL that the D channel
734 * connection has been established.
736 void gigaset_isdn_connD(struct bc_state *bcs)
738 struct cardstate *cs = bcs->cs;
739 struct gigaset_capi_ctr *iif = cs->iif;
740 struct gigaset_capi_appl *ap = bcs->ap;
742 unsigned int msgsize;
745 dev_err(cs->dev, "%s: no application\n", __func__);
749 /* this should never happen */
750 dev_warn(cs->dev, "%s: dropping extra application %u\n",
751 __func__, ap->bcnext->id);
752 send_disconnect_ind(bcs, ap->bcnext,
753 CapiCallGivenToOtherApplication);
754 ap->bcnext = ap->bcnext->bcnext;
756 if (ap->connected == APCONN_NONE) {
757 dev_warn(cs->dev, "%s: application %u not connected\n",
762 /* prepare CONNECT_ACTIVE_IND message
763 * Note: LLC not supported by device
765 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
766 ap->nextMessageNumber++,
767 iif->ctr.cnr | ((bcs->channel + 1) << 8));
769 /* minimum size, all structs empty */
770 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
772 /* ToDo: set parameter: Connected number
773 * (requires ev-layer state machine extension to collect
777 /* build and emit CONNECT_ACTIVE_IND message */
778 skb = alloc_skb(msgsize, GFP_ATOMIC);
780 dev_err(cs->dev, "%s: out of memory\n", __func__);
783 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
784 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
785 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
789 * gigaset_isdn_hupD() - signal D channel hangup
790 * @bcs: B channel descriptor structure.
792 * Called by main module at tasklet level to notify the LL that the D channel
793 * connection has been shut down.
795 void gigaset_isdn_hupD(struct bc_state *bcs)
797 struct gigaset_capi_appl *ap;
800 * ToDo: pass on reason code reported by device
801 * (requires ev-layer state machine extension to collect
804 for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
805 send_disconnect_b3_ind(bcs, ap);
806 send_disconnect_ind(bcs, ap, 0);
812 * gigaset_isdn_connB() - signal B channel connect
813 * @bcs: B channel descriptor structure.
815 * Called by main module at tasklet level to notify the LL that the B channel
816 * connection has been established.
818 void gigaset_isdn_connB(struct bc_state *bcs)
820 struct cardstate *cs = bcs->cs;
821 struct gigaset_capi_ctr *iif = cs->iif;
822 struct gigaset_capi_appl *ap = bcs->ap;
824 unsigned int msgsize;
828 dev_err(cs->dev, "%s: no application\n", __func__);
832 /* this should never happen */
833 dev_warn(cs->dev, "%s: dropping extra application %u\n",
834 __func__, ap->bcnext->id);
835 send_disconnect_ind(bcs, ap->bcnext,
836 CapiCallGivenToOtherApplication);
837 ap->bcnext = ap->bcnext->bcnext;
839 if (!ap->connected) {
840 dev_warn(cs->dev, "%s: application %u not connected\n",
846 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
847 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
848 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
849 * Parameters in both cases always: NCCI = 1, NCPI empty
851 if (ap->connected >= APCONN_ACTIVE) {
852 command = CAPI_CONNECT_B3_ACTIVE;
853 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
855 command = CAPI_CONNECT_B3;
856 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
858 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
859 ap->nextMessageNumber++,
860 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
861 skb = alloc_skb(msgsize, GFP_ATOMIC);
863 dev_err(cs->dev, "%s: out of memory\n", __func__);
866 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
867 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
868 ap->connected = APCONN_ACTIVE;
869 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
873 * gigaset_isdn_hupB() - signal B channel hangup
874 * @bcs: B channel descriptor structure.
876 * Called by main module to notify the LL that the B channel connection has
879 void gigaset_isdn_hupB(struct bc_state *bcs)
881 struct cardstate *cs = bcs->cs;
882 struct gigaset_capi_appl *ap = bcs->ap;
884 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
887 dev_err(cs->dev, "%s: no application\n", __func__);
891 send_disconnect_b3_ind(bcs, ap);
895 * gigaset_isdn_start() - signal device availability
896 * @cs: device descriptor structure.
898 * Called by main module to notify the LL that the device is available for
901 void gigaset_isdn_start(struct cardstate *cs)
903 struct gigaset_capi_ctr *iif = cs->iif;
905 /* fill profile data: manufacturer name */
906 strcpy(iif->ctr.manu, "Siemens");
907 /* CAPI and device version */
908 iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
909 iif->ctr.version.minorversion = 0;
910 /* ToDo: check/assert cs->gotfwver? */
911 iif->ctr.version.majormanuversion = cs->fwver[0];
912 iif->ctr.version.minormanuversion = cs->fwver[1];
913 /* number of B channels supported */
914 iif->ctr.profile.nbchannel = cs->channels;
915 /* global options: internal controller, supplementary services */
916 iif->ctr.profile.goptions = 0x11;
917 /* B1 protocols: 64 kbit/s HDLC or transparent */
918 iif->ctr.profile.support1 = 0x03;
919 /* B2 protocols: transparent only */
920 /* ToDo: X.75 SLP ? */
921 iif->ctr.profile.support2 = 0x02;
922 /* B3 protocols: transparent only */
923 iif->ctr.profile.support3 = 0x01;
924 /* no serial number */
925 strcpy(iif->ctr.serial, "0");
926 capi_ctr_ready(&iif->ctr);
930 * gigaset_isdn_stop() - signal device unavailability
931 * @cs: device descriptor structure.
933 * Called by main module to notify the LL that the device is no longer
936 void gigaset_isdn_stop(struct cardstate *cs)
938 struct gigaset_capi_ctr *iif = cs->iif;
939 capi_ctr_down(&iif->ctr);
943 * kernel CAPI callback methods
944 * ============================
950 static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
952 struct cardstate *cs = ctr->driverdata;
954 /* AVM specific operation, not needed for Gigaset -- ignore */
955 dev_notice(cs->dev, "load_firmware ignored\n");
961 * reset (deactivate) controller
963 static void gigaset_reset_ctr(struct capi_ctr *ctr)
965 struct cardstate *cs = ctr->driverdata;
967 /* AVM specific operation, not needed for Gigaset -- ignore */
968 dev_notice(cs->dev, "reset_ctr ignored\n");
972 * register CAPI application
974 static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
975 capi_register_params *rp)
977 struct gigaset_capi_ctr *iif
978 = container_of(ctr, struct gigaset_capi_ctr, ctr);
979 struct cardstate *cs = ctr->driverdata;
980 struct gigaset_capi_appl *ap;
982 list_for_each_entry(ap, &iif->appls, ctrlist)
983 if (ap->id == appl) {
985 "application %u already registered\n", appl);
989 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
991 dev_err(cs->dev, "%s: out of memory\n", __func__);
996 list_add(&ap->ctrlist, &iif->appls);
1000 * release CAPI application
1002 static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
1004 struct gigaset_capi_ctr *iif
1005 = container_of(ctr, struct gigaset_capi_ctr, ctr);
1006 struct cardstate *cs = iif->ctr.driverdata;
1007 struct gigaset_capi_appl *ap, *tmp;
1009 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1010 if (ap->id == appl) {
1011 if (ap->connected != APCONN_NONE) {
1013 "%s: application %u still connected\n",
1015 /* ToDo: clear active connection */
1017 list_del(&ap->ctrlist);
1024 * =====================================================================
1025 * outgoing CAPI message handler
1026 * =====================================================================
1030 * helper function: emit reply message with given Info value
1032 static void send_conf(struct gigaset_capi_ctr *iif,
1033 struct gigaset_capi_appl *ap,
1034 struct sk_buff *skb,
1038 * _CONF replies always only have NCCI and Info parameters
1039 * so they'll fit into the _REQ message skb
1041 capi_cmsg_answer(&iif->acmsg);
1042 iif->acmsg.Info = info;
1043 capi_cmsg2message(&iif->acmsg, skb->data);
1044 __skb_trim(skb, CAPI_STDCONF_LEN);
1045 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1046 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1050 * process FACILITY_REQ message
1052 static void do_facility_req(struct gigaset_capi_ctr *iif,
1053 struct gigaset_capi_appl *ap,
1054 struct sk_buff *skb)
1056 struct cardstate *cs = iif->ctr.driverdata;
1057 _cmsg *cmsg = &iif->acmsg;
1058 struct sk_buff *cskb;
1060 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1062 static u8 confparam[10]; /* max. 9 octets + length byte */
1064 /* decode message */
1065 capi_message2cmsg(cmsg, skb->data);
1066 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1069 * Facility Request Parameter is not decoded by capi_message2cmsg()
1070 * encoding depends on Facility Selector
1072 switch (cmsg->FacilitySelector) {
1073 case CAPI_FACILITY_DTMF: /* ToDo */
1074 info = CapiFacilityNotSupported;
1075 confparam[0] = 2; /* length */
1076 /* DTMF information: Unknown DTMF request */
1077 capimsg_setu16(confparam, 1, 2);
1080 case CAPI_FACILITY_V42BIS: /* not supported */
1081 info = CapiFacilityNotSupported;
1082 confparam[0] = 2; /* length */
1083 /* V.42 bis information: not available */
1084 capimsg_setu16(confparam, 1, 1);
1087 case CAPI_FACILITY_SUPPSVC:
1088 /* decode Function parameter */
1089 pparam = cmsg->FacilityRequestParameter;
1090 if (pparam == NULL || *pparam < 2) {
1091 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1092 "Facility Request Parameter");
1093 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1096 function = CAPIMSG_U16(pparam, 1);
1098 case CAPI_SUPPSVC_GETSUPPORTED:
1100 /* Supplementary Service specific parameter */
1101 confparam[3] = 6; /* length */
1102 /* Supplementary services info: Success */
1103 capimsg_setu16(confparam, 4, CapiSuccess);
1104 /* Supported Services: none */
1105 capimsg_setu32(confparam, 6, 0);
1107 /* ToDo: add supported services */
1109 info = CapiFacilitySpecificFunctionNotSupported;
1110 /* Supplementary Service specific parameter */
1111 confparam[3] = 2; /* length */
1112 /* Supplementary services info: not supported */
1113 capimsg_setu16(confparam, 4,
1114 CapiSupplementaryServiceNotSupported);
1117 /* Facility confirmation parameter */
1118 confparam[0] = confparam[3] + 3; /* total length */
1119 /* Function: copy from _REQ message */
1120 capimsg_setu16(confparam, 1, function);
1121 /* Supplementary Service specific parameter already set above */
1124 case CAPI_FACILITY_WAKEUP: /* ToDo */
1125 info = CapiFacilityNotSupported;
1126 confparam[0] = 2; /* length */
1127 /* Number of accepted awake request parameters: 0 */
1128 capimsg_setu16(confparam, 1, 0);
1132 info = CapiFacilityNotSupported;
1133 confparam[0] = 0; /* empty struct */
1136 /* send FACILITY_CONF with given Info and confirmation parameter */
1137 capi_cmsg_answer(cmsg);
1139 cmsg->FacilityConfirmationParameter = confparam;
1140 msgsize += confparam[0]; /* length */
1141 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1143 dev_err(cs->dev, "%s: out of memory\n", __func__);
1146 capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
1147 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1148 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1153 * process LISTEN_REQ message
1154 * just store the masks in the application data structure
1156 static void do_listen_req(struct gigaset_capi_ctr *iif,
1157 struct gigaset_capi_appl *ap,
1158 struct sk_buff *skb)
1160 /* decode message */
1161 capi_message2cmsg(&iif->acmsg, skb->data);
1162 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1164 /* store listening parameters */
1165 ap->listenInfoMask = iif->acmsg.InfoMask;
1166 ap->listenCIPmask = iif->acmsg.CIPmask;
1167 send_conf(iif, ap, skb, CapiSuccess);
1171 * process ALERT_REQ message
1172 * nothing to do, Gigaset always alerts anyway
1174 static void do_alert_req(struct gigaset_capi_ctr *iif,
1175 struct gigaset_capi_appl *ap,
1176 struct sk_buff *skb)
1178 /* decode message */
1179 capi_message2cmsg(&iif->acmsg, skb->data);
1180 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1181 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1185 * process CONNECT_REQ message
1186 * allocate a B channel, prepare dial commands, queue a DIAL event,
1187 * emit CONNECT_CONF reply
1189 static void do_connect_req(struct gigaset_capi_ctr *iif,
1190 struct gigaset_capi_appl *ap,
1191 struct sk_buff *skb)
1193 struct cardstate *cs = iif->ctr.driverdata;
1194 _cmsg *cmsg = &iif->acmsg;
1195 struct bc_state *bcs;
1202 /* decode message */
1203 capi_message2cmsg(cmsg, skb->data);
1204 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1206 /* get free B channel & construct PLCI */
1207 bcs = gigaset_get_free_channel(cs);
1209 dev_notice(cs->dev, "%s: no B channel available\n",
1211 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1216 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1218 /* build command table */
1219 commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
1223 /* encode parameter: Called party number */
1224 pp = cmsg->CalledPartyNumber;
1225 if (pp == NULL || *pp == 0) {
1226 dev_notice(cs->dev, "%s: %s missing\n",
1227 "CONNECT_REQ", "Called party number");
1228 info = CapiIllMessageParmCoding;
1232 /* check type of number/numbering plan byte */
1234 case 0x80: /* unknown type / unknown numbering plan */
1235 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1237 default: /* others: warn about potential misinterpretation */
1238 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1239 "CONNECT_REQ", "Called party number", *pp);
1243 /* translate "**" internal call prefix to CTP value */
1244 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1251 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1252 if (!commands[AT_TYPE])
1254 commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
1255 if (!commands[AT_DIAL])
1257 snprintf(commands[AT_DIAL], l+3, "D%*s\r", l, pp);
1259 /* encode parameter: Calling party number */
1260 pp = cmsg->CallingPartyNumber;
1261 if (pp != NULL && *pp > 0) {
1264 /* check type of number/numbering plan byte */
1265 /* ToDo: allow for/handle Ext=1? */
1267 case 0x00: /* unknown type / unknown numbering plan */
1268 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1272 "%s: %s type/plan 0x%02x unsupported\n",
1273 "CONNECT_REQ", "Calling party number", *pp);
1278 /* check presentation indicator */
1280 dev_notice(cs->dev, "%s: %s IE truncated\n",
1281 "CONNECT_REQ", "Calling party number");
1282 info = CapiIllMessageParmCoding;
1285 switch (*pp & 0xfc) { /* ignore Screening indicator */
1286 case 0x80: /* Presentation allowed */
1289 case 0xa0: /* Presentation restricted */
1293 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1295 "Presentation/Screening indicator",
1299 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1300 if (!commands[AT_CLIP])
1307 commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
1308 if (!commands[AT_MSN])
1310 snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
1314 /* check parameter: CIP Value */
1315 if (cmsg->CIPValue > ARRAY_SIZE(cip2bchlc) ||
1316 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1317 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1318 "CONNECT_REQ", cmsg->CIPValue);
1319 info = CapiCipValueUnknown;
1323 /* check/encode parameter: BC */
1324 if (cmsg->BC && cmsg->BC[0]) {
1325 /* explicit BC overrides CIP */
1326 l = 2*cmsg->BC[0] + 7;
1327 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1328 if (!commands[AT_BC])
1330 strcpy(commands[AT_BC], "^SBC=");
1331 decode_ie(cmsg->BC, commands[AT_BC]+5);
1332 strcpy(commands[AT_BC] + l - 2, "\r");
1333 } else if (cip2bchlc[cmsg->CIPValue].bc) {
1334 l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
1335 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1336 if (!commands[AT_BC])
1338 snprintf(commands[AT_BC], l, "^SBC=%s\r",
1339 cip2bchlc[cmsg->CIPValue].bc);
1342 /* check/encode parameter: HLC */
1343 if (cmsg->HLC && cmsg->HLC[0]) {
1344 /* explicit HLC overrides CIP */
1345 l = 2*cmsg->HLC[0] + 7;
1346 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1347 if (!commands[AT_HLC])
1349 strcpy(commands[AT_HLC], "^SHLC=");
1350 decode_ie(cmsg->HLC, commands[AT_HLC]+5);
1351 strcpy(commands[AT_HLC] + l - 2, "\r");
1352 } else if (cip2bchlc[cmsg->CIPValue].hlc) {
1353 l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
1354 commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
1355 if (!commands[AT_HLC])
1357 snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
1358 cip2bchlc[cmsg->CIPValue].hlc);
1361 /* check/encode parameter: B Protocol */
1362 if (cmsg->BProtocol == CAPI_DEFAULT) {
1363 bcs->proto2 = L2_HDLC;
1365 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1367 switch (cmsg->B1protocol) {
1369 bcs->proto2 = L2_HDLC;
1372 bcs->proto2 = L2_BITSYNC;
1376 "B1 Protocol %u unsupported, using Transparent\n",
1378 bcs->proto2 = L2_BITSYNC;
1380 if (cmsg->B2protocol != 1)
1382 "B2 Protocol %u unsupported, using Transparent\n",
1384 if (cmsg->B3protocol != 0)
1386 "B3 Protocol %u unsupported, using Transparent\n",
1388 ignore_cstruct_param(cs, cmsg->B1configuration,
1389 "CONNECT_REQ", "B1 Configuration");
1390 ignore_cstruct_param(cs, cmsg->B2configuration,
1391 "CONNECT_REQ", "B2 Configuration");
1392 ignore_cstruct_param(cs, cmsg->B3configuration,
1393 "CONNECT_REQ", "B3 Configuration");
1395 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1396 if (!commands[AT_PROTO])
1398 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1400 /* ToDo: check/encode remaining parameters */
1401 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1402 "CONNECT_REQ", "Called pty subaddr");
1403 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1404 "CONNECT_REQ", "Calling pty subaddr");
1405 ignore_cstruct_param(cs, cmsg->LLC,
1406 "CONNECT_REQ", "LLC");
1407 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1408 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1409 "CONNECT_REQ", "B Channel Information");
1410 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1411 "CONNECT_REQ", "Keypad Facility");
1412 ignore_cstruct_param(cs, cmsg->Useruserdata,
1413 "CONNECT_REQ", "User-User Data");
1414 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1415 "CONNECT_REQ", "Facility Data Array");
1418 /* encode parameter: B channel to use */
1419 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1420 if (!commands[AT_ISO])
1422 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1423 (unsigned) bcs->channel + 1);
1425 /* queue & schedule EV_DIAL event */
1426 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1427 bcs->at_state.seq_index, NULL))
1429 gig_dbg(DEBUG_CMD, "scheduling DIAL");
1430 gigaset_schedule_event(cs);
1431 ap->connected = APCONN_SETUP;
1432 send_conf(iif, ap, skb, CapiSuccess);
1436 dev_err(cs->dev, "%s: out of memory\n", __func__);
1437 info = CAPI_MSGOSRESOURCEERR;
1440 for (i = 0; i < AT_NUM; i++)
1443 gigaset_free_channel(bcs);
1444 send_conf(iif, ap, skb, info);
1448 * process CONNECT_RESP message
1449 * checks protocol parameters and queues an ACCEPT or HUP event
1451 static void do_connect_resp(struct gigaset_capi_ctr *iif,
1452 struct gigaset_capi_appl *ap,
1453 struct sk_buff *skb)
1455 struct cardstate *cs = iif->ctr.driverdata;
1456 _cmsg *cmsg = &iif->acmsg;
1457 struct bc_state *bcs;
1458 struct gigaset_capi_appl *oap;
1461 /* decode message */
1462 capi_message2cmsg(cmsg, skb->data);
1463 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1466 /* extract and check channel number from PLCI */
1467 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1468 if (!channel || channel > cs->channels) {
1469 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1470 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1473 bcs = cs->bcs + channel - 1;
1475 switch (cmsg->Reject) {
1476 case 0: /* Accept */
1477 /* drop all competing applications, keep only this one */
1478 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1480 send_disconnect_ind(bcs, oap,
1481 CapiCallGivenToOtherApplication);
1484 bcs->chstate |= CHS_NOTIFY_LL;
1486 /* check/encode B channel protocol */
1487 if (cmsg->BProtocol == CAPI_DEFAULT) {
1488 bcs->proto2 = L2_HDLC;
1490 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1492 switch (cmsg->B1protocol) {
1494 bcs->proto2 = L2_HDLC;
1497 bcs->proto2 = L2_BITSYNC;
1501 "B1 Protocol %u unsupported, using Transparent\n",
1503 bcs->proto2 = L2_BITSYNC;
1505 if (cmsg->B2protocol != 1)
1507 "B2 Protocol %u unsupported, using Transparent\n",
1509 if (cmsg->B3protocol != 0)
1511 "B3 Protocol %u unsupported, using Transparent\n",
1513 ignore_cstruct_param(cs, cmsg->B1configuration,
1514 "CONNECT_RESP", "B1 Configuration");
1515 ignore_cstruct_param(cs, cmsg->B2configuration,
1516 "CONNECT_RESP", "B2 Configuration");
1517 ignore_cstruct_param(cs, cmsg->B3configuration,
1518 "CONNECT_RESP", "B3 Configuration");
1521 /* ToDo: check/encode remaining parameters */
1522 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1523 "CONNECT_RESP", "Connected Number");
1524 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1525 "CONNECT_RESP", "Connected Subaddress");
1526 ignore_cstruct_param(cs, cmsg->LLC,
1527 "CONNECT_RESP", "LLC");
1528 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1529 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1530 "CONNECT_RESP", "BChannel Information");
1531 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1532 "CONNECT_RESP", "Keypad Facility");
1533 ignore_cstruct_param(cs, cmsg->Useruserdata,
1534 "CONNECT_RESP", "User-User Data");
1535 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1536 "CONNECT_RESP", "Facility Data Array");
1540 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1541 EV_ACCEPT, NULL, 0, NULL))
1543 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
1544 gigaset_schedule_event(cs);
1547 case 1: /* Ignore */
1548 /* send DISCONNECT_IND to this application */
1549 send_disconnect_ind(bcs, ap, 0);
1551 /* remove it from the list of listening apps */
1552 if (bcs->ap == ap) {
1553 bcs->ap = ap->bcnext;
1554 if (bcs->ap == NULL)
1555 /* last one: stop ev-layer hupD notifications */
1556 bcs->chstate &= ~CHS_NOTIFY_LL;
1559 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1560 if (oap->bcnext == ap) {
1561 oap->bcnext = oap->bcnext->bcnext;
1565 dev_err(cs->dev, "%s: application %u not found\n",
1569 default: /* Reject */
1570 /* drop all competing applications, keep only this one */
1571 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
1573 send_disconnect_ind(bcs, oap,
1574 CapiCallGivenToOtherApplication);
1578 /* reject call - will trigger DISCONNECT_IND for this app */
1579 dev_info(cs->dev, "%s: Reject=%x\n",
1580 "CONNECT_RESP", cmsg->Reject);
1581 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1582 EV_HUP, NULL, 0, NULL))
1584 gig_dbg(DEBUG_CMD, "scheduling HUP");
1585 gigaset_schedule_event(cs);
1591 * process CONNECT_B3_REQ message
1592 * build NCCI and emit CONNECT_B3_CONF reply
1594 static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1595 struct gigaset_capi_appl *ap,
1596 struct sk_buff *skb)
1598 struct cardstate *cs = iif->ctr.driverdata;
1599 _cmsg *cmsg = &iif->acmsg;
1602 /* decode message */
1603 capi_message2cmsg(cmsg, skb->data);
1604 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1606 /* extract and check channel number from PLCI */
1607 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1608 if (!channel || channel > cs->channels) {
1609 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1610 "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
1611 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1615 /* mark logical connection active */
1616 ap->connected = APCONN_ACTIVE;
1618 /* build NCCI: always 1 (one B3 connection only) */
1619 cmsg->adr.adrNCCI |= 1 << 16;
1621 /* NCPI parameter: not applicable for B3 Transparent */
1622 ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
1623 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1624 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1628 * process CONNECT_B3_RESP message
1629 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1630 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1631 * The emitted message is always shorter than the received one,
1632 * allowing to reuse the skb.
1634 static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1635 struct gigaset_capi_appl *ap,
1636 struct sk_buff *skb)
1638 struct cardstate *cs = iif->ctr.driverdata;
1639 _cmsg *cmsg = &iif->acmsg;
1640 struct bc_state *bcs;
1642 unsigned int msgsize;
1645 /* decode message */
1646 capi_message2cmsg(cmsg, skb->data);
1647 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1649 /* extract and check channel number and NCCI */
1650 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1651 if (!channel || channel > cs->channels ||
1652 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1653 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1654 "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
1658 bcs = &cs->bcs[channel-1];
1661 /* Reject: clear B3 connect received flag */
1662 ap->connected = APCONN_SETUP;
1664 /* trigger hangup, causing eventual DISCONNECT_IND */
1665 if (!gigaset_add_event(cs, &bcs->at_state,
1666 EV_HUP, NULL, 0, NULL)) {
1667 dev_err(cs->dev, "%s: out of memory\n", __func__);
1671 gig_dbg(DEBUG_CMD, "scheduling HUP");
1672 gigaset_schedule_event(cs);
1674 /* emit DISCONNECT_B3_IND */
1675 command = CAPI_DISCONNECT_B3;
1676 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1679 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1680 * we only send CONNECT_B3_IND if the B channel is up
1682 command = CAPI_CONNECT_B3_ACTIVE;
1683 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1685 capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
1686 ap->nextMessageNumber++, cmsg->adr.adrNCCI);
1687 __skb_trim(skb, msgsize);
1688 capi_cmsg2message(cmsg, skb->data);
1689 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1690 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1694 * process DISCONNECT_REQ message
1695 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1696 * emit DISCONNECT_CONF reply
1698 static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1699 struct gigaset_capi_appl *ap,
1700 struct sk_buff *skb)
1702 struct cardstate *cs = iif->ctr.driverdata;
1703 _cmsg *cmsg = &iif->acmsg;
1704 struct bc_state *bcs;
1706 struct sk_buff *b3skb;
1709 /* decode message */
1710 capi_message2cmsg(cmsg, skb->data);
1711 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1713 /* extract and check channel number from PLCI */
1714 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1715 if (!channel || channel > cs->channels) {
1716 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1717 "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
1718 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1721 bcs = cs->bcs + channel - 1;
1723 /* ToDo: process parameter: Additional info */
1724 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1725 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1726 "DISCONNECT_REQ", "B Channel Information");
1727 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1728 "DISCONNECT_REQ", "Keypad Facility");
1729 ignore_cstruct_param(cs, cmsg->Useruserdata,
1730 "DISCONNECT_REQ", "User-User Data");
1731 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1732 "DISCONNECT_REQ", "Facility Data Array");
1735 /* skip if DISCONNECT_IND already sent */
1739 /* check for active logical connection */
1740 if (ap->connected >= APCONN_ACTIVE) {
1742 * emit DISCONNECT_B3_IND with cause 0x3301
1743 * use separate cmsg structure, as the content of iif->acmsg
1744 * is still needed for creating the _CONF message
1746 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1748 dev_err(cs->dev, "%s: out of memory\n", __func__);
1749 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1752 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1753 ap->nextMessageNumber++,
1754 cmsg->adr.adrPLCI | (1 << 16));
1755 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1756 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1757 if (b3skb == NULL) {
1758 dev_err(cs->dev, "%s: out of memory\n", __func__);
1759 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1762 capi_cmsg2message(b3cmsg,
1763 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1765 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1768 /* trigger hangup, causing eventual DISCONNECT_IND */
1769 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1770 dev_err(cs->dev, "%s: out of memory\n", __func__);
1771 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1774 gig_dbg(DEBUG_CMD, "scheduling HUP");
1775 gigaset_schedule_event(cs);
1778 send_conf(iif, ap, skb, CapiSuccess);
1782 * process DISCONNECT_B3_REQ message
1783 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1785 static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1786 struct gigaset_capi_appl *ap,
1787 struct sk_buff *skb)
1789 struct cardstate *cs = iif->ctr.driverdata;
1790 _cmsg *cmsg = &iif->acmsg;
1793 /* decode message */
1794 capi_message2cmsg(cmsg, skb->data);
1795 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1797 /* extract and check channel number and NCCI */
1798 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1799 if (!channel || channel > cs->channels ||
1800 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1801 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1802 "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
1803 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1807 /* reject if logical connection not active */
1808 if (ap->connected < APCONN_ACTIVE) {
1809 send_conf(iif, ap, skb,
1810 CapiMessageNotSupportedInCurrentState);
1814 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1815 if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
1816 EV_HUP, NULL, 0, NULL)) {
1817 dev_err(cs->dev, "%s: out of memory\n", __func__);
1818 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1821 gig_dbg(DEBUG_CMD, "scheduling HUP");
1822 gigaset_schedule_event(cs);
1824 /* NCPI parameter: not applicable for B3 Transparent */
1825 ignore_cstruct_param(cs, cmsg->NCPI,
1826 "DISCONNECT_B3_REQ", "NCPI");
1827 send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
1828 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1832 * process DATA_B3_REQ message
1834 static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1835 struct gigaset_capi_appl *ap,
1836 struct sk_buff *skb)
1838 struct cardstate *cs = iif->ctr.driverdata;
1839 int channel = CAPIMSG_PLCI_PART(skb->data);
1840 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1841 u16 msglen = CAPIMSG_LEN(skb->data);
1842 u16 datalen = CAPIMSG_DATALEN(skb->data);
1843 u16 flags = CAPIMSG_FLAGS(skb->data);
1845 /* frequent message, avoid _cmsg overhead */
1846 dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
1848 gig_dbg(DEBUG_LLDATA,
1849 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1850 channel, flags, msglen, datalen);
1852 /* check parameters */
1853 if (channel == 0 || channel > cs->channels || ncci != 1) {
1854 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1855 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1856 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1859 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
1860 dev_notice(cs->dev, "%s: unexpected length %d\n",
1861 "DATA_B3_REQ", msglen);
1862 if (msglen + datalen != skb->len)
1863 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
1864 "DATA_B3_REQ", msglen, datalen, skb->len);
1865 if (msglen + datalen > skb->len) {
1866 /* message too short for announced data length */
1867 send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
1870 if (flags & CAPI_FLAGS_RESERVED) {
1871 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
1872 "DATA_B3_REQ", flags);
1873 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1877 /* reject if logical connection not active */
1878 if (ap->connected < APCONN_ACTIVE) {
1879 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1884 * pull CAPI message from skb,
1885 * pass payload data to device-specific module
1886 * CAPI message will be preserved in headroom
1888 skb_pull(skb, msglen);
1889 if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
1890 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1894 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1897 * ToDo: honor unset "delivery confirmation" bit
1898 * (send DATA_B3_CONF immediately?)
1903 * process RESET_B3_REQ message
1904 * just always reply "not supported by current protocol"
1906 static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
1907 struct gigaset_capi_appl *ap,
1908 struct sk_buff *skb)
1910 /* decode message */
1911 capi_message2cmsg(&iif->acmsg, skb->data);
1912 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1913 send_conf(iif, ap, skb,
1914 CapiResetProcedureNotSupportedByCurrentProtocol);
1918 * dump unsupported/ignored messages at most twice per minute,
1919 * some apps send those very frequently
1921 static unsigned long ignored_msg_dump_time;
1924 * unsupported CAPI message handler
1926 static void do_unsupported(struct gigaset_capi_ctr *iif,
1927 struct gigaset_capi_appl *ap,
1928 struct sk_buff *skb)
1930 /* decode message */
1931 capi_message2cmsg(&iif->acmsg, skb->data);
1932 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
1933 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1934 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
1938 * CAPI message handler: no-op
1940 static void do_nothing(struct gigaset_capi_ctr *iif,
1941 struct gigaset_capi_appl *ap,
1942 struct sk_buff *skb)
1944 if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
1945 /* decode message */
1946 capi_message2cmsg(&iif->acmsg, skb->data);
1947 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1952 static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
1953 struct gigaset_capi_appl *ap,
1954 struct sk_buff *skb)
1956 dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
1960 /* table of outgoing CAPI message handlers with lookup function */
1961 typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
1962 struct gigaset_capi_appl *,
1967 capi_send_handler_t handler;
1968 } capi_send_handler_table[] = {
1969 /* most frequent messages first for faster lookup */
1970 { CAPI_DATA_B3_REQ, do_data_b3_req },
1971 { CAPI_DATA_B3_RESP, do_data_b3_resp },
1973 { CAPI_ALERT_REQ, do_alert_req },
1974 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
1975 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
1976 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
1977 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
1978 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
1979 { CAPI_CONNECT_REQ, do_connect_req },
1980 { CAPI_CONNECT_RESP, do_connect_resp },
1981 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
1982 { CAPI_DISCONNECT_B3_RESP, do_nothing },
1983 { CAPI_DISCONNECT_REQ, do_disconnect_req },
1984 { CAPI_DISCONNECT_RESP, do_nothing },
1985 { CAPI_FACILITY_REQ, do_facility_req },
1986 { CAPI_FACILITY_RESP, do_nothing },
1987 { CAPI_LISTEN_REQ, do_listen_req },
1988 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
1989 { CAPI_RESET_B3_REQ, do_reset_b3_req },
1990 { CAPI_RESET_B3_RESP, do_nothing },
1993 * ToDo: support overlap sending (requires ev-layer state
1994 * machine extension to generate additional ATD commands)
1996 { CAPI_INFO_REQ, do_unsupported },
1997 { CAPI_INFO_RESP, do_nothing },
2000 * ToDo: what's the proper response for these?
2002 { CAPI_MANUFACTURER_REQ, do_nothing },
2003 { CAPI_MANUFACTURER_RESP, do_nothing },
2006 /* look up handler */
2007 static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
2011 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
2012 if (capi_send_handler_table[i].cmd == cmd)
2013 return capi_send_handler_table[i].handler;
2019 * gigaset_send_message() - accept a CAPI message from an application
2020 * @ctr: controller descriptor structure.
2021 * @skb: CAPI message.
2023 * Return value: CAPI error code
2024 * Note: capidrv (and probably others, too) only uses the return value to
2025 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2027 static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2029 struct gigaset_capi_ctr *iif
2030 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2031 struct cardstate *cs = ctr->driverdata;
2032 struct gigaset_capi_appl *ap;
2033 capi_send_handler_t handler;
2035 /* can only handle linear sk_buffs */
2036 if (skb_linearize(skb) < 0) {
2037 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2038 return CAPI_MSGOSRESOURCEERR;
2041 /* retrieve application data structure */
2042 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2044 dev_notice(cs->dev, "%s: application %u not registered\n",
2045 __func__, CAPIMSG_APPID(skb->data));
2046 return CAPI_ILLAPPNR;
2049 /* look up command */
2050 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2052 /* unknown/unsupported message type */
2053 if (printk_ratelimit())
2054 dev_notice(cs->dev, "%s: unsupported message %u\n",
2055 __func__, CAPIMSG_CMD(skb->data));
2056 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2060 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2061 /* queue behind other messages */
2062 skb_queue_tail(&iif->sendqueue, skb);
2063 return CAPI_NOERROR;
2066 /* process message */
2067 handler(iif, ap, skb);
2069 /* process other messages arrived in the meantime */
2070 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2071 skb = skb_dequeue(&iif->sendqueue);
2073 /* should never happen */
2074 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2077 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2079 /* could that happen? */
2080 dev_warn(cs->dev, "%s: application %u vanished\n",
2081 __func__, CAPIMSG_APPID(skb->data));
2084 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2086 /* should never happen */
2087 dev_err(cs->dev, "%s: handler %x vanished\n",
2088 __func__, CAPIMSG_CMD(skb->data));
2091 handler(iif, ap, skb);
2094 return CAPI_NOERROR;
2098 * gigaset_procinfo() - build single line description for controller
2099 * @ctr: controller descriptor structure.
2101 * Return value: pointer to generated string (null terminated)
2103 static char *gigaset_procinfo(struct capi_ctr *ctr)
2105 return ctr->name; /* ToDo: more? */
2109 * gigaset_ctr_read_proc() - build controller proc file entry
2110 * @page: buffer of PAGE_SIZE bytes for receiving the entry.
2115 * @ctr: controller descriptor structure.
2117 * Return value: length of generated entry
2119 static int gigaset_ctr_read_proc(char *page, char **start, off_t off,
2120 int count, int *eof, struct capi_ctr *ctr)
2122 struct cardstate *cs = ctr->driverdata;
2126 len += sprintf(page+len, "%-16s %s\n", "name", ctr->name);
2127 len += sprintf(page+len, "%-16s %s %s\n", "dev",
2128 dev_driver_string(cs->dev), dev_name(cs->dev));
2129 len += sprintf(page+len, "%-16s %d\n", "id", cs->myid);
2131 len += sprintf(page+len, "%-16s %d.%d.%d.%d\n", "firmware",
2132 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2133 len += sprintf(page+len, "%-16s %d\n", "channels",
2135 len += sprintf(page+len, "%-16s %s\n", "onechannel",
2136 cs->onechannel ? "yes" : "no");
2154 len += sprintf(page+len, "%-16s %s\n", "mode", s);
2156 switch (cs->mstate) {
2157 case MS_UNINITIALIZED:
2158 s = "uninitialized";
2178 len += sprintf(page+len, "%-16s %s\n", "mstate", s);
2180 len += sprintf(page+len, "%-16s %s\n", "running",
2181 cs->running ? "yes" : "no");
2182 len += sprintf(page+len, "%-16s %s\n", "connected",
2183 cs->connected ? "yes" : "no");
2184 len += sprintf(page+len, "%-16s %s\n", "isdn_up",
2185 cs->isdn_up ? "yes" : "no");
2186 len += sprintf(page+len, "%-16s %s\n", "cidmode",
2187 cs->cidmode ? "yes" : "no");
2189 for (i = 0; i < cs->channels; i++) {
2190 len += sprintf(page+len, "[%d]%-13s %d\n", i, "corrupted",
2191 cs->bcs[i].corrupted);
2192 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_down",
2193 cs->bcs[i].trans_down);
2194 len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_up",
2195 cs->bcs[i].trans_up);
2196 len += sprintf(page+len, "[%d]%-13s %d\n", i, "chstate",
2197 cs->bcs[i].chstate);
2198 switch (cs->bcs[i].proto2) {
2211 len += sprintf(page+len, "[%d]%-13s %s\n", i, "proto2", s);
2217 static struct capi_driver capi_driver_gigaset = {
2223 * gigaset_isdn_register() - register to LL
2224 * @cs: device descriptor structure.
2225 * @isdnid: device name.
2227 * Called by main module to register the device with the LL.
2229 * Return value: 1 for success, 0 for failure
2231 int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
2233 struct gigaset_capi_ctr *iif;
2236 pr_info("Kernel CAPI interface\n");
2238 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2240 pr_err("%s: out of memory\n", __func__);
2244 /* register driver with CAPI (ToDo: what for?) */
2245 register_capi_driver(&capi_driver_gigaset);
2247 /* prepare controller structure */
2248 iif->ctr.owner = THIS_MODULE;
2249 iif->ctr.driverdata = cs;
2250 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2251 iif->ctr.driver_name = "gigaset";
2252 iif->ctr.load_firmware = gigaset_load_firmware;
2253 iif->ctr.reset_ctr = gigaset_reset_ctr;
2254 iif->ctr.register_appl = gigaset_register_appl;
2255 iif->ctr.release_appl = gigaset_release_appl;
2256 iif->ctr.send_message = gigaset_send_message;
2257 iif->ctr.procinfo = gigaset_procinfo;
2258 iif->ctr.ctr_read_proc = gigaset_ctr_read_proc;
2259 INIT_LIST_HEAD(&iif->appls);
2260 skb_queue_head_init(&iif->sendqueue);
2261 atomic_set(&iif->sendqlen, 0);
2263 /* register controller with CAPI */
2264 rc = attach_capi_ctr(&iif->ctr);
2266 pr_err("attach_capi_ctr failed (%d)\n", rc);
2267 unregister_capi_driver(&capi_driver_gigaset);
2273 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2278 * gigaset_isdn_unregister() - unregister from LL
2279 * @cs: device descriptor structure.
2281 * Called by main module to unregister the device from the LL.
2283 void gigaset_isdn_unregister(struct cardstate *cs)
2285 struct gigaset_capi_ctr *iif = cs->iif;
2287 detach_capi_ctr(&iif->ctr);
2290 unregister_capi_driver(&capi_driver_gigaset);