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
48 #define CAPI_SUPPSVC_LISTEN 0x0001
50 /* missing from capiutil.h */
51 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
52 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
53 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
54 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
55 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
56 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
57 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
58 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
60 /* parameters with differing location in DATA_B3_CONF/_RESP: */
61 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
62 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
64 /* Flags (DATA_B3_REQ/_IND) */
65 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
66 #define CAPI_FLAGS_RESERVED (~0x1f)
69 #define MAX_BC_OCTETS 11
70 #define MAX_HLC_OCTETS 3
71 #define MAX_NUMBER_DIGITS 20
72 #define MAX_FMT_IE_LEN 20
74 /* values for bcs->apconnstate */
75 #define APCONN_NONE 0 /* inactive/listening */
76 #define APCONN_SETUP 1 /* connecting */
77 #define APCONN_ACTIVE 2 /* B channel up */
79 /* registered application data structure */
80 struct gigaset_capi_appl
{
81 struct list_head ctrlist
;
82 struct gigaset_capi_appl
*bcnext
;
84 struct capi_register_params rp
;
85 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 l
= CAPIMSG_DATALEN(data
);
276 gig_dbg(level
, " DataLength=%d", l
);
277 if (l
<= 0 || !(gigaset_debuglevel
& DEBUG_LLDATA
))
280 l
= 64; /* arbitrary limit */
281 dbgline
= kmalloc(3*l
, GFP_ATOMIC
);
284 data
+= CAPIMSG_LEN(data
);
285 for (i
= 0; i
< l
; i
++) {
286 dbgline
[3*i
] = hex_asc_hi(data
[i
]);
287 dbgline
[3*i
+1] = hex_asc_lo(data
[i
]);
288 dbgline
[3*i
+2] = ' ';
290 dbgline
[3*l
-1] = '\0';
291 gig_dbg(level
, " %s", dbgline
);
298 * format CAPI IE as string
301 static const char *format_ie(const char *ie
)
303 static char result
[3*MAX_FMT_IE_LEN
];
311 if (count
> MAX_FMT_IE_LEN
)
312 count
= MAX_FMT_IE_LEN
-1;
314 *pout
++ = hex_asc_hi(*++ie
);
315 *pout
++ = hex_asc_lo(*ie
);
318 if (len
> MAX_FMT_IE_LEN
) {
328 * emit DATA_B3_CONF message
330 static void send_data_b3_conf(struct cardstate
*cs
, struct capi_ctr
*ctr
,
331 u16 appl
, u16 msgid
, int channel
,
332 u16 handle
, u16 info
)
334 struct sk_buff
*cskb
;
337 cskb
= alloc_skb(CAPI_DATA_B3_CONF_LEN
, GFP_ATOMIC
);
339 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
342 /* frequent message, avoid _cmsg overhead */
343 msg
= __skb_put(cskb
, CAPI_DATA_B3_CONF_LEN
);
344 CAPIMSG_SETLEN(msg
, CAPI_DATA_B3_CONF_LEN
);
345 CAPIMSG_SETAPPID(msg
, appl
);
346 CAPIMSG_SETCOMMAND(msg
, CAPI_DATA_B3
);
347 CAPIMSG_SETSUBCOMMAND(msg
, CAPI_CONF
);
348 CAPIMSG_SETMSGID(msg
, msgid
);
349 CAPIMSG_SETCONTROLLER(msg
, ctr
->cnr
);
350 CAPIMSG_SETPLCI_PART(msg
, channel
);
351 CAPIMSG_SETNCCI_PART(msg
, 1);
352 CAPIMSG_SETHANDLE_CONF(msg
, handle
);
353 CAPIMSG_SETINFO_CONF(msg
, info
);
356 dump_rawmsg(DEBUG_MCMD
, __func__
, msg
);
357 capi_ctr_handle_message(ctr
, appl
, cskb
);
362 * driver interface functions
363 * ==========================
367 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
368 * @bcs: B channel descriptor structure.
371 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
372 * skb has been successfully sent, for signalling completion to the LL.
374 void gigaset_skb_sent(struct bc_state
*bcs
, struct sk_buff
*dskb
)
376 struct cardstate
*cs
= bcs
->cs
;
377 struct gigaset_capi_ctr
*iif
= cs
->iif
;
378 struct gigaset_capi_appl
*ap
= bcs
->ap
;
379 unsigned char *req
= skb_mac_header(dskb
);
382 /* update statistics */
386 gig_dbg(DEBUG_MCMD
, "%s: application gone", __func__
);
390 /* don't send further B3 messages if disconnected */
391 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
392 gig_dbg(DEBUG_MCMD
, "%s: disconnected", __func__
);
397 * send DATA_B3_CONF if "delivery confirmation" bit was set in request;
398 * otherwise it has already been sent by do_data_b3_req()
400 flags
= CAPIMSG_FLAGS(req
);
401 if (flags
& CAPI_FLAGS_DELIVERY_CONFIRMATION
)
402 send_data_b3_conf(cs
, &iif
->ctr
, ap
->id
, CAPIMSG_MSGID(req
),
403 bcs
->channel
+ 1, CAPIMSG_HANDLE_REQ(req
),
404 (flags
& ~CAPI_FLAGS_DELIVERY_CONFIRMATION
) ?
405 CapiFlagsNotSupportedByProtocol
:
408 EXPORT_SYMBOL_GPL(gigaset_skb_sent
);
411 * gigaset_skb_rcvd() - pass received skb to LL
412 * @bcs: B channel descriptor structure.
413 * @skb: received data.
415 * Called by hardware module {bas,ser,usb}_gigaset when user data has
416 * been successfully received, for passing to the LL.
417 * Warning: skb must not be accessed anymore!
419 void gigaset_skb_rcvd(struct bc_state
*bcs
, struct sk_buff
*skb
)
421 struct cardstate
*cs
= bcs
->cs
;
422 struct gigaset_capi_ctr
*iif
= cs
->iif
;
423 struct gigaset_capi_appl
*ap
= bcs
->ap
;
426 /* update statistics */
430 gig_dbg(DEBUG_MCMD
, "%s: application gone", __func__
);
431 dev_kfree_skb_any(skb
);
435 /* don't send further B3 messages if disconnected */
436 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
437 gig_dbg(DEBUG_MCMD
, "%s: disconnected", __func__
);
438 dev_kfree_skb_any(skb
);
443 * prepend DATA_B3_IND message to payload
444 * Parameters: NCCI = 1, all others 0/unused
445 * frequent message, avoid _cmsg overhead
447 skb_push(skb
, CAPI_DATA_B3_REQ_LEN
);
448 CAPIMSG_SETLEN(skb
->data
, CAPI_DATA_B3_REQ_LEN
);
449 CAPIMSG_SETAPPID(skb
->data
, ap
->id
);
450 CAPIMSG_SETCOMMAND(skb
->data
, CAPI_DATA_B3
);
451 CAPIMSG_SETSUBCOMMAND(skb
->data
, CAPI_IND
);
452 CAPIMSG_SETMSGID(skb
->data
, ap
->nextMessageNumber
++);
453 CAPIMSG_SETCONTROLLER(skb
->data
, iif
->ctr
.cnr
);
454 CAPIMSG_SETPLCI_PART(skb
->data
, bcs
->channel
+ 1);
455 CAPIMSG_SETNCCI_PART(skb
->data
, 1);
456 /* Data parameter not used */
457 CAPIMSG_SETDATALEN(skb
->data
, len
);
458 /* Data handle parameter not used */
459 CAPIMSG_SETFLAGS(skb
->data
, 0);
460 /* Data64 parameter not present */
463 dump_rawmsg(DEBUG_MCMD
, __func__
, skb
->data
);
464 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
466 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd
);
469 * gigaset_isdn_rcv_err() - signal receive error
470 * @bcs: B channel descriptor structure.
472 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
473 * has occurred, for signalling to the LL.
475 void gigaset_isdn_rcv_err(struct bc_state
*bcs
)
477 /* if currently ignoring packets, just count down */
483 /* update statistics */
486 /* ToDo: signal error -> LL */
488 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err
);
491 * gigaset_isdn_icall() - signal incoming call
492 * @at_state: connection state structure.
494 * Called by main module at tasklet level to notify the LL that an incoming
495 * call has been received. @at_state contains the parameters of the call.
497 * Return value: call disposition (ICALL_*)
499 int gigaset_isdn_icall(struct at_state_t
*at_state
)
501 struct cardstate
*cs
= at_state
->cs
;
502 struct bc_state
*bcs
= at_state
->bcs
;
503 struct gigaset_capi_ctr
*iif
= cs
->iif
;
504 struct gigaset_capi_appl
*ap
;
507 unsigned int msgsize
;
512 * ToDo: signal calls without a free B channel, too
513 * (requires a u8 handle for the at_state structure that can
514 * be stored in the PLCI and used in the CONNECT_RESP message
515 * handler to retrieve it)
520 /* prepare CONNECT_IND message, using B channel number as PLCI */
521 capi_cmsg_header(&iif
->hcmsg
, 0, CAPI_CONNECT
, CAPI_IND
, 0,
522 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
524 /* minimum size, all structs empty */
525 msgsize
= CAPI_CONNECT_IND_BASELEN
;
527 /* Bearer Capability (mandatory) */
528 if (at_state
->str_var
[STR_ZBC
]) {
529 /* pass on BC from Gigaset */
530 if (encode_ie(at_state
->str_var
[STR_ZBC
], iif
->bc_buf
,
531 MAX_BC_OCTETS
) < 0) {
532 dev_warn(cs
->dev
, "RING ignored - bad BC %s\n",
533 at_state
->str_var
[STR_ZBC
]);
537 /* look up corresponding CIP value */
538 iif
->hcmsg
.CIPValue
= 0; /* default if nothing found */
539 for (i
= 0; i
< ARRAY_SIZE(cip2bchlc
); i
++)
540 if (cip2bchlc
[i
].bc
!= NULL
&&
541 cip2bchlc
[i
].hlc
== NULL
&&
542 !strcmp(cip2bchlc
[i
].bc
,
543 at_state
->str_var
[STR_ZBC
])) {
544 iif
->hcmsg
.CIPValue
= i
;
548 /* no BC (internal call): assume CIP 1 (speech, A-law) */
549 iif
->hcmsg
.CIPValue
= 1;
550 encode_ie(cip2bchlc
[1].bc
, iif
->bc_buf
, MAX_BC_OCTETS
);
552 iif
->hcmsg
.BC
= iif
->bc_buf
;
553 msgsize
+= iif
->hcmsg
.BC
[0];
555 /* High Layer Compatibility (optional) */
556 if (at_state
->str_var
[STR_ZHLC
]) {
557 /* pass on HLC from Gigaset */
558 if (encode_ie(at_state
->str_var
[STR_ZHLC
], iif
->hlc_buf
,
559 MAX_HLC_OCTETS
) < 0) {
560 dev_warn(cs
->dev
, "RING ignored - bad HLC %s\n",
561 at_state
->str_var
[STR_ZHLC
]);
564 iif
->hcmsg
.HLC
= iif
->hlc_buf
;
565 msgsize
+= iif
->hcmsg
.HLC
[0];
567 /* look up corresponding CIP value */
568 /* keep BC based CIP value if none found */
569 if (at_state
->str_var
[STR_ZBC
])
570 for (i
= 0; i
< ARRAY_SIZE(cip2bchlc
); i
++)
571 if (cip2bchlc
[i
].hlc
!= NULL
&&
572 !strcmp(cip2bchlc
[i
].hlc
,
573 at_state
->str_var
[STR_ZHLC
]) &&
574 !strcmp(cip2bchlc
[i
].bc
,
575 at_state
->str_var
[STR_ZBC
])) {
576 iif
->hcmsg
.CIPValue
= i
;
581 /* Called Party Number (optional) */
582 if (at_state
->str_var
[STR_ZCPN
]) {
583 i
= strlen(at_state
->str_var
[STR_ZCPN
]);
584 if (i
> MAX_NUMBER_DIGITS
) {
585 dev_warn(cs
->dev
, "RING ignored - bad number %s\n",
586 at_state
->str_var
[STR_ZBC
]);
589 iif
->cdpty_buf
[0] = i
+ 1;
590 iif
->cdpty_buf
[1] = 0x80; /* type / numbering plan unknown */
591 memcpy(iif
->cdpty_buf
+2, at_state
->str_var
[STR_ZCPN
], i
);
592 iif
->hcmsg
.CalledPartyNumber
= iif
->cdpty_buf
;
593 msgsize
+= iif
->hcmsg
.CalledPartyNumber
[0];
596 /* Calling Party Number (optional) */
597 if (at_state
->str_var
[STR_NMBR
]) {
598 i
= strlen(at_state
->str_var
[STR_NMBR
]);
599 if (i
> MAX_NUMBER_DIGITS
) {
600 dev_warn(cs
->dev
, "RING ignored - bad number %s\n",
601 at_state
->str_var
[STR_ZBC
]);
604 iif
->cgpty_buf
[0] = i
+ 2;
605 iif
->cgpty_buf
[1] = 0x00; /* type / numbering plan unknown */
606 iif
->cgpty_buf
[2] = 0x80; /* pres. allowed, not screened */
607 memcpy(iif
->cgpty_buf
+3, at_state
->str_var
[STR_NMBR
], i
);
608 iif
->hcmsg
.CallingPartyNumber
= iif
->cgpty_buf
;
609 msgsize
+= iif
->hcmsg
.CallingPartyNumber
[0];
612 /* remaining parameters (not supported, always left NULL):
613 * - CalledPartySubaddress
614 * - CallingPartySubaddress
616 * - BChannelinformation
619 * - Facilitydataarray
622 gig_dbg(DEBUG_CMD
, "icall: PLCI %x CIP %d BC %s",
623 iif
->hcmsg
.adr
.adrPLCI
, iif
->hcmsg
.CIPValue
,
624 format_ie(iif
->hcmsg
.BC
));
625 gig_dbg(DEBUG_CMD
, "icall: HLC %s",
626 format_ie(iif
->hcmsg
.HLC
));
627 gig_dbg(DEBUG_CMD
, "icall: CgPty %s",
628 format_ie(iif
->hcmsg
.CallingPartyNumber
));
629 gig_dbg(DEBUG_CMD
, "icall: CdPty %s",
630 format_ie(iif
->hcmsg
.CalledPartyNumber
));
632 /* scan application list for matching listeners */
633 spin_lock_irqsave(&bcs
->aplock
, flags
);
634 if (bcs
->ap
!= NULL
|| bcs
->apconnstate
!= APCONN_NONE
) {
635 dev_warn(cs
->dev
, "%s: channel not properly cleared (%p/%d)\n",
636 __func__
, bcs
->ap
, bcs
->apconnstate
);
638 bcs
->apconnstate
= APCONN_NONE
;
640 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
641 actCIPmask
= 1 | (1 << iif
->hcmsg
.CIPValue
);
642 list_for_each_entry(ap
, &iif
->appls
, ctrlist
)
643 if (actCIPmask
& ap
->listenCIPmask
) {
644 /* build CONNECT_IND message for this application */
645 iif
->hcmsg
.ApplId
= ap
->id
;
646 iif
->hcmsg
.Messagenumber
= ap
->nextMessageNumber
++;
648 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
650 dev_err(cs
->dev
, "%s: out of memory\n",
654 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
655 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
657 /* add to listeners on this B channel, update state */
658 spin_lock_irqsave(&bcs
->aplock
, flags
);
659 ap
->bcnext
= bcs
->ap
;
661 bcs
->chstate
|= CHS_NOTIFY_LL
;
662 bcs
->apconnstate
= APCONN_SETUP
;
663 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
666 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
670 * Return "accept" if any listeners.
671 * Gigaset will send ALERTING.
672 * There doesn't seem to be a way to avoid this.
674 return bcs
->ap
? ICALL_ACCEPT
: ICALL_IGNORE
;
678 * send a DISCONNECT_IND message to an application
679 * does not sleep, clobbers the controller's hcmsg structure
681 static void send_disconnect_ind(struct bc_state
*bcs
,
682 struct gigaset_capi_appl
*ap
, u16 reason
)
684 struct cardstate
*cs
= bcs
->cs
;
685 struct gigaset_capi_ctr
*iif
= cs
->iif
;
688 if (bcs
->apconnstate
== APCONN_NONE
)
691 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_DISCONNECT
, CAPI_IND
,
692 ap
->nextMessageNumber
++,
693 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
694 iif
->hcmsg
.Reason
= reason
;
695 skb
= alloc_skb(CAPI_DISCONNECT_IND_LEN
, GFP_ATOMIC
);
697 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
700 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, CAPI_DISCONNECT_IND_LEN
));
701 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
702 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
706 * send a DISCONNECT_B3_IND message to an application
707 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
708 * does not sleep, clobbers the controller's hcmsg structure
710 static void send_disconnect_b3_ind(struct bc_state
*bcs
,
711 struct gigaset_capi_appl
*ap
)
713 struct cardstate
*cs
= bcs
->cs
;
714 struct gigaset_capi_ctr
*iif
= cs
->iif
;
717 /* nothing to do if no logical connection active */
718 if (bcs
->apconnstate
< APCONN_ACTIVE
)
720 bcs
->apconnstate
= APCONN_SETUP
;
722 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_DISCONNECT_B3
, CAPI_IND
,
723 ap
->nextMessageNumber
++,
724 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8) | (1 << 16));
725 skb
= alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN
, GFP_ATOMIC
);
727 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
730 capi_cmsg2message(&iif
->hcmsg
,
731 __skb_put(skb
, CAPI_DISCONNECT_B3_IND_BASELEN
));
732 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
733 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
737 * gigaset_isdn_connD() - signal D channel connect
738 * @bcs: B channel descriptor structure.
740 * Called by main module at tasklet level to notify the LL that the D channel
741 * connection has been established.
743 void gigaset_isdn_connD(struct bc_state
*bcs
)
745 struct cardstate
*cs
= bcs
->cs
;
746 struct gigaset_capi_ctr
*iif
= cs
->iif
;
747 struct gigaset_capi_appl
*ap
;
749 unsigned int msgsize
;
752 spin_lock_irqsave(&bcs
->aplock
, flags
);
755 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
756 gig_dbg(DEBUG_CMD
, "%s: application gone", __func__
);
759 if (bcs
->apconnstate
== APCONN_NONE
) {
760 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
761 dev_warn(cs
->dev
, "%s: application %u not connected\n",
765 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
767 /* this should never happen */
768 dev_warn(cs
->dev
, "%s: dropping extra application %u\n",
769 __func__
, ap
->bcnext
->id
);
770 send_disconnect_ind(bcs
, ap
->bcnext
,
771 CapiCallGivenToOtherApplication
);
772 ap
->bcnext
= ap
->bcnext
->bcnext
;
775 /* prepare CONNECT_ACTIVE_IND message
776 * Note: LLC not supported by device
778 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_CONNECT_ACTIVE
, CAPI_IND
,
779 ap
->nextMessageNumber
++,
780 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
782 /* minimum size, all structs empty */
783 msgsize
= CAPI_CONNECT_ACTIVE_IND_BASELEN
;
785 /* ToDo: set parameter: Connected number
786 * (requires ev-layer state machine extension to collect
790 /* build and emit CONNECT_ACTIVE_IND message */
791 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
793 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
796 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
797 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
798 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
802 * gigaset_isdn_hupD() - signal D channel hangup
803 * @bcs: B channel descriptor structure.
805 * Called by main module at tasklet level to notify the LL that the D channel
806 * connection has been shut down.
808 void gigaset_isdn_hupD(struct bc_state
*bcs
)
810 struct gigaset_capi_appl
*ap
;
814 * ToDo: pass on reason code reported by device
815 * (requires ev-layer state machine extension to collect
818 spin_lock_irqsave(&bcs
->aplock
, flags
);
819 while (bcs
->ap
!= NULL
) {
821 bcs
->ap
= ap
->bcnext
;
822 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
823 send_disconnect_b3_ind(bcs
, ap
);
824 send_disconnect_ind(bcs
, ap
, 0);
825 spin_lock_irqsave(&bcs
->aplock
, flags
);
827 bcs
->apconnstate
= APCONN_NONE
;
828 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
832 * gigaset_isdn_connB() - signal B channel connect
833 * @bcs: B channel descriptor structure.
835 * Called by main module at tasklet level to notify the LL that the B channel
836 * connection has been established.
838 void gigaset_isdn_connB(struct bc_state
*bcs
)
840 struct cardstate
*cs
= bcs
->cs
;
841 struct gigaset_capi_ctr
*iif
= cs
->iif
;
842 struct gigaset_capi_appl
*ap
;
845 unsigned int msgsize
;
848 spin_lock_irqsave(&bcs
->aplock
, flags
);
851 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
852 gig_dbg(DEBUG_CMD
, "%s: application gone", __func__
);
855 if (!bcs
->apconnstate
) {
856 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
857 dev_warn(cs
->dev
, "%s: application %u not connected\n",
863 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
864 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
865 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
866 * Parameters in both cases always: NCCI = 1, NCPI empty
868 if (bcs
->apconnstate
>= APCONN_ACTIVE
) {
869 command
= CAPI_CONNECT_B3_ACTIVE
;
870 msgsize
= CAPI_CONNECT_B3_ACTIVE_IND_BASELEN
;
872 command
= CAPI_CONNECT_B3
;
873 msgsize
= CAPI_CONNECT_B3_IND_BASELEN
;
875 bcs
->apconnstate
= APCONN_ACTIVE
;
877 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
880 /* this should never happen */
881 dev_warn(cs
->dev
, "%s: dropping extra application %u\n",
882 __func__
, ap
->bcnext
->id
);
883 send_disconnect_ind(bcs
, ap
->bcnext
,
884 CapiCallGivenToOtherApplication
);
885 ap
->bcnext
= ap
->bcnext
->bcnext
;
888 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, command
, CAPI_IND
,
889 ap
->nextMessageNumber
++,
890 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8) | (1 << 16));
891 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
893 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
896 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
897 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
898 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
902 * gigaset_isdn_hupB() - signal B channel hangup
903 * @bcs: B channel descriptor structure.
905 * Called by main module to notify the LL that the B channel connection has
908 void gigaset_isdn_hupB(struct bc_state
*bcs
)
910 struct gigaset_capi_appl
*ap
= bcs
->ap
;
912 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
915 gig_dbg(DEBUG_CMD
, "%s: application gone", __func__
);
919 send_disconnect_b3_ind(bcs
, ap
);
923 * gigaset_isdn_start() - signal device availability
924 * @cs: device descriptor structure.
926 * Called by main module to notify the LL that the device is available for
929 void gigaset_isdn_start(struct cardstate
*cs
)
931 struct gigaset_capi_ctr
*iif
= cs
->iif
;
933 /* fill profile data: manufacturer name */
934 strcpy(iif
->ctr
.manu
, "Siemens");
935 /* CAPI and device version */
936 iif
->ctr
.version
.majorversion
= 2; /* CAPI 2.0 */
937 iif
->ctr
.version
.minorversion
= 0;
938 /* ToDo: check/assert cs->gotfwver? */
939 iif
->ctr
.version
.majormanuversion
= cs
->fwver
[0];
940 iif
->ctr
.version
.minormanuversion
= cs
->fwver
[1];
941 /* number of B channels supported */
942 iif
->ctr
.profile
.nbchannel
= cs
->channels
;
943 /* global options: internal controller, supplementary services */
944 iif
->ctr
.profile
.goptions
= 0x11;
945 /* B1 protocols: 64 kbit/s HDLC or transparent */
946 iif
->ctr
.profile
.support1
= 0x03;
947 /* B2 protocols: transparent only */
948 /* ToDo: X.75 SLP ? */
949 iif
->ctr
.profile
.support2
= 0x02;
950 /* B3 protocols: transparent only */
951 iif
->ctr
.profile
.support3
= 0x01;
952 /* no serial number */
953 strcpy(iif
->ctr
.serial
, "0");
954 capi_ctr_ready(&iif
->ctr
);
958 * gigaset_isdn_stop() - signal device unavailability
959 * @cs: device descriptor structure.
961 * Called by main module to notify the LL that the device is no longer
964 void gigaset_isdn_stop(struct cardstate
*cs
)
966 struct gigaset_capi_ctr
*iif
= cs
->iif
;
967 capi_ctr_down(&iif
->ctr
);
971 * kernel CAPI callback methods
972 * ============================
976 * register CAPI application
978 static void gigaset_register_appl(struct capi_ctr
*ctr
, u16 appl
,
979 capi_register_params
*rp
)
981 struct gigaset_capi_ctr
*iif
982 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
983 struct cardstate
*cs
= ctr
->driverdata
;
984 struct gigaset_capi_appl
*ap
;
986 gig_dbg(DEBUG_CMD
, "%s [%u] l3cnt=%u blkcnt=%u blklen=%u",
987 __func__
, appl
, rp
->level3cnt
, rp
->datablkcnt
, rp
->datablklen
);
989 list_for_each_entry(ap
, &iif
->appls
, ctrlist
)
990 if (ap
->id
== appl
) {
992 "application %u already registered\n", appl
);
996 ap
= kzalloc(sizeof(*ap
), GFP_KERNEL
);
998 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1004 list_add(&ap
->ctrlist
, &iif
->appls
);
1005 dev_info(cs
->dev
, "application %u registered\n", ap
->id
);
1009 * remove CAPI application from channel
1010 * helper function to keep indentation levels down and stay in 80 columns
1013 static inline void remove_appl_from_channel(struct bc_state
*bcs
,
1014 struct gigaset_capi_appl
*ap
)
1016 struct cardstate
*cs
= bcs
->cs
;
1017 struct gigaset_capi_appl
*bcap
;
1018 unsigned long flags
;
1021 spin_lock_irqsave(&bcs
->aplock
, flags
);
1024 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1028 /* check first application on channel */
1030 bcs
->ap
= ap
->bcnext
;
1031 if (bcs
->ap
!= NULL
) {
1032 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1036 /* none left, clear channel state */
1037 prevconnstate
= bcs
->apconnstate
;
1038 bcs
->apconnstate
= APCONN_NONE
;
1039 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1041 if (prevconnstate
== APCONN_ACTIVE
) {
1042 dev_notice(cs
->dev
, "%s: hanging up channel %u\n",
1043 __func__
, bcs
->channel
);
1044 gigaset_add_event(cs
, &bcs
->at_state
,
1045 EV_HUP
, NULL
, 0, NULL
);
1046 gigaset_schedule_event(cs
);
1051 /* check remaining list */
1053 if (bcap
->bcnext
== ap
) {
1054 bcap
->bcnext
= bcap
->bcnext
->bcnext
;
1055 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1058 bcap
= bcap
->bcnext
;
1059 } while (bcap
!= NULL
);
1060 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1064 * release CAPI application
1066 static void gigaset_release_appl(struct capi_ctr
*ctr
, u16 appl
)
1068 struct gigaset_capi_ctr
*iif
1069 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
1070 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1071 struct gigaset_capi_appl
*ap
, *tmp
;
1074 gig_dbg(DEBUG_CMD
, "%s [%u]", __func__
, appl
);
1076 list_for_each_entry_safe(ap
, tmp
, &iif
->appls
, ctrlist
)
1077 if (ap
->id
== appl
) {
1078 /* remove from any channels */
1079 for (ch
= 0; ch
< cs
->channels
; ch
++)
1080 remove_appl_from_channel(&cs
->bcs
[ch
], ap
);
1082 /* remove from registration list */
1083 list_del(&ap
->ctrlist
);
1085 dev_info(cs
->dev
, "application %u released\n", appl
);
1090 * =====================================================================
1091 * outgoing CAPI message handler
1092 * =====================================================================
1096 * helper function: emit reply message with given Info value
1098 static void send_conf(struct gigaset_capi_ctr
*iif
,
1099 struct gigaset_capi_appl
*ap
,
1100 struct sk_buff
*skb
,
1104 * _CONF replies always only have NCCI and Info parameters
1105 * so they'll fit into the _REQ message skb
1107 capi_cmsg_answer(&iif
->acmsg
);
1108 iif
->acmsg
.Info
= info
;
1109 capi_cmsg2message(&iif
->acmsg
, skb
->data
);
1110 __skb_trim(skb
, CAPI_STDCONF_LEN
);
1111 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1112 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1116 * process FACILITY_REQ message
1118 static void do_facility_req(struct gigaset_capi_ctr
*iif
,
1119 struct gigaset_capi_appl
*ap
,
1120 struct sk_buff
*skb
)
1122 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1123 _cmsg
*cmsg
= &iif
->acmsg
;
1124 struct sk_buff
*cskb
;
1126 unsigned int msgsize
= CAPI_FACILITY_CONF_BASELEN
;
1128 static u8 confparam
[10]; /* max. 9 octets + length byte */
1130 /* decode message */
1131 capi_message2cmsg(cmsg
, skb
->data
);
1132 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1135 * Facility Request Parameter is not decoded by capi_message2cmsg()
1136 * encoding depends on Facility Selector
1138 switch (cmsg
->FacilitySelector
) {
1139 case CAPI_FACILITY_DTMF
: /* ToDo */
1140 info
= CapiFacilityNotSupported
;
1141 confparam
[0] = 2; /* length */
1142 /* DTMF information: Unknown DTMF request */
1143 capimsg_setu16(confparam
, 1, 2);
1146 case CAPI_FACILITY_V42BIS
: /* not supported */
1147 info
= CapiFacilityNotSupported
;
1148 confparam
[0] = 2; /* length */
1149 /* V.42 bis information: not available */
1150 capimsg_setu16(confparam
, 1, 1);
1153 case CAPI_FACILITY_SUPPSVC
:
1154 /* decode Function parameter */
1155 pparam
= cmsg
->FacilityRequestParameter
;
1156 if (pparam
== NULL
|| pparam
[0] < 2) {
1157 dev_notice(cs
->dev
, "%s: %s missing\n", "FACILITY_REQ",
1158 "Facility Request Parameter");
1159 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
1162 function
= CAPIMSG_U16(pparam
, 1);
1164 case CAPI_SUPPSVC_GETSUPPORTED
:
1166 /* Supplementary Service specific parameter */
1167 confparam
[3] = 6; /* length */
1168 /* Supplementary services info: Success */
1169 capimsg_setu16(confparam
, 4, CapiSuccess
);
1170 /* Supported Services: none */
1171 capimsg_setu32(confparam
, 6, 0);
1173 case CAPI_SUPPSVC_LISTEN
:
1174 if (pparam
[0] < 7 || pparam
[3] < 4) {
1175 dev_notice(cs
->dev
, "%s: %s missing\n",
1176 "FACILITY_REQ", "Notification Mask");
1177 send_conf(iif
, ap
, skb
,
1178 CapiIllMessageParmCoding
);
1181 if (CAPIMSG_U32(pparam
, 4) != 0) {
1183 "%s: unsupported supplementary service notification mask 0x%x\n",
1184 "FACILITY_REQ", CAPIMSG_U32(pparam
, 4));
1185 info
= CapiFacilitySpecificFunctionNotSupported
;
1186 confparam
[3] = 2; /* length */
1187 capimsg_setu16(confparam
, 4,
1188 CapiSupplementaryServiceNotSupported
);
1191 confparam
[3] = 2; /* length */
1192 capimsg_setu16(confparam
, 4, CapiSuccess
);
1194 /* ToDo: add supported services */
1197 "%s: unsupported supplementary service function 0x%04x\n",
1198 "FACILITY_REQ", function
);
1199 info
= CapiFacilitySpecificFunctionNotSupported
;
1200 /* Supplementary Service specific parameter */
1201 confparam
[3] = 2; /* length */
1202 /* Supplementary services info: not supported */
1203 capimsg_setu16(confparam
, 4,
1204 CapiSupplementaryServiceNotSupported
);
1207 /* Facility confirmation parameter */
1208 confparam
[0] = confparam
[3] + 3; /* total length */
1209 /* Function: copy from _REQ message */
1210 capimsg_setu16(confparam
, 1, function
);
1211 /* Supplementary Service specific parameter already set above */
1214 case CAPI_FACILITY_WAKEUP
: /* ToDo */
1215 info
= CapiFacilityNotSupported
;
1216 confparam
[0] = 2; /* length */
1217 /* Number of accepted awake request parameters: 0 */
1218 capimsg_setu16(confparam
, 1, 0);
1222 info
= CapiFacilityNotSupported
;
1223 confparam
[0] = 0; /* empty struct */
1226 /* send FACILITY_CONF with given Info and confirmation parameter */
1227 capi_cmsg_answer(cmsg
);
1229 cmsg
->FacilityConfirmationParameter
= confparam
;
1230 msgsize
+= confparam
[0]; /* length */
1231 cskb
= alloc_skb(msgsize
, GFP_ATOMIC
);
1233 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1236 capi_cmsg2message(cmsg
, __skb_put(cskb
, msgsize
));
1237 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1238 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, cskb
);
1243 * process LISTEN_REQ message
1244 * just store the masks in the application data structure
1246 static void do_listen_req(struct gigaset_capi_ctr
*iif
,
1247 struct gigaset_capi_appl
*ap
,
1248 struct sk_buff
*skb
)
1250 /* decode message */
1251 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1252 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1254 /* store listening parameters */
1255 ap
->listenInfoMask
= iif
->acmsg
.InfoMask
;
1256 ap
->listenCIPmask
= iif
->acmsg
.CIPmask
;
1257 send_conf(iif
, ap
, skb
, CapiSuccess
);
1261 * process ALERT_REQ message
1262 * nothing to do, Gigaset always alerts anyway
1264 static void do_alert_req(struct gigaset_capi_ctr
*iif
,
1265 struct gigaset_capi_appl
*ap
,
1266 struct sk_buff
*skb
)
1268 /* decode message */
1269 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1270 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1271 send_conf(iif
, ap
, skb
, CapiAlertAlreadySent
);
1275 * process CONNECT_REQ message
1276 * allocate a B channel, prepare dial commands, queue a DIAL event,
1277 * emit CONNECT_CONF reply
1279 static void do_connect_req(struct gigaset_capi_ctr
*iif
,
1280 struct gigaset_capi_appl
*ap
,
1281 struct sk_buff
*skb
)
1283 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1284 _cmsg
*cmsg
= &iif
->acmsg
;
1285 struct bc_state
*bcs
;
1289 unsigned long flags
;
1290 int i
, l
, lbc
, lhlc
;
1293 /* decode message */
1294 capi_message2cmsg(cmsg
, skb
->data
);
1295 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1297 /* get free B channel & construct PLCI */
1298 bcs
= gigaset_get_free_channel(cs
);
1300 dev_notice(cs
->dev
, "%s: no B channel available\n",
1302 send_conf(iif
, ap
, skb
, CapiNoPlciAvailable
);
1305 spin_lock_irqsave(&bcs
->aplock
, flags
);
1306 if (bcs
->ap
!= NULL
|| bcs
->apconnstate
!= APCONN_NONE
)
1307 dev_warn(cs
->dev
, "%s: channel not properly cleared (%p/%d)\n",
1308 __func__
, bcs
->ap
, bcs
->apconnstate
);
1311 bcs
->apconnstate
= APCONN_SETUP
;
1312 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1314 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1315 dev_kfree_skb(bcs
->rx_skb
);
1316 gigaset_new_rx_skb(bcs
);
1317 cmsg
->adr
.adrPLCI
|= (bcs
->channel
+ 1) << 8;
1319 /* build command table */
1320 commands
= kzalloc(AT_NUM
*(sizeof *commands
), GFP_KERNEL
);
1324 /* encode parameter: Called party number */
1325 pp
= cmsg
->CalledPartyNumber
;
1326 if (pp
== NULL
|| *pp
== 0) {
1327 dev_notice(cs
->dev
, "%s: %s missing\n",
1328 "CONNECT_REQ", "Called party number");
1329 info
= CapiIllMessageParmCoding
;
1333 /* check type of number/numbering plan byte */
1335 case 0x80: /* unknown type / unknown numbering plan */
1336 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1338 default: /* others: warn about potential misinterpretation */
1339 dev_notice(cs
->dev
, "%s: %s type/plan 0x%02x unsupported\n",
1340 "CONNECT_REQ", "Called party number", *pp
);
1344 /* translate "**" internal call prefix to CTP value */
1345 if (l
>= 2 && pp
[0] == '*' && pp
[1] == '*') {
1352 commands
[AT_TYPE
] = kstrdup(s
, GFP_KERNEL
);
1353 if (!commands
[AT_TYPE
])
1355 commands
[AT_DIAL
] = kmalloc(l
+3, GFP_KERNEL
);
1356 if (!commands
[AT_DIAL
])
1358 snprintf(commands
[AT_DIAL
], l
+3, "D%.*s\r", l
, pp
);
1360 /* encode parameter: Calling party number */
1361 pp
= cmsg
->CallingPartyNumber
;
1362 if (pp
!= NULL
&& *pp
> 0) {
1365 /* check type of number/numbering plan byte */
1366 /* ToDo: allow for/handle Ext=1? */
1368 case 0x00: /* unknown type / unknown numbering plan */
1369 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1373 "%s: %s type/plan 0x%02x unsupported\n",
1374 "CONNECT_REQ", "Calling party number", *pp
);
1379 /* check presentation indicator */
1381 dev_notice(cs
->dev
, "%s: %s IE truncated\n",
1382 "CONNECT_REQ", "Calling party number");
1383 info
= CapiIllMessageParmCoding
;
1386 switch (*pp
& 0xfc) { /* ignore Screening indicator */
1387 case 0x80: /* Presentation allowed */
1390 case 0xa0: /* Presentation restricted */
1394 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1396 "Presentation/Screening indicator",
1400 commands
[AT_CLIP
] = kstrdup(s
, GFP_KERNEL
);
1401 if (!commands
[AT_CLIP
])
1408 commands
[AT_MSN
] = kmalloc(l
+8, GFP_KERNEL
);
1409 if (!commands
[AT_MSN
])
1411 snprintf(commands
[AT_MSN
], l
+8, "^SMSN=%*s\r", l
, pp
);
1415 /* check parameter: CIP Value */
1416 if (cmsg
->CIPValue
>= ARRAY_SIZE(cip2bchlc
) ||
1417 (cmsg
->CIPValue
> 0 && cip2bchlc
[cmsg
->CIPValue
].bc
== NULL
)) {
1418 dev_notice(cs
->dev
, "%s: unknown CIP value %d\n",
1419 "CONNECT_REQ", cmsg
->CIPValue
);
1420 info
= CapiCipValueUnknown
;
1425 * check/encode parameters: BC & HLC
1426 * must be encoded together as device doesn't accept HLC separately
1427 * explicit parameters override values derived from CIP
1430 /* determine lengths */
1431 if (cmsg
->BC
&& cmsg
->BC
[0]) /* BC specified explicitly */
1432 lbc
= 2*cmsg
->BC
[0];
1433 else if (cip2bchlc
[cmsg
->CIPValue
].bc
) /* BC derived from CIP */
1434 lbc
= strlen(cip2bchlc
[cmsg
->CIPValue
].bc
);
1437 if (cmsg
->HLC
&& cmsg
->HLC
[0]) /* HLC specified explicitly */
1438 lhlc
= 2*cmsg
->HLC
[0];
1439 else if (cip2bchlc
[cmsg
->CIPValue
].hlc
) /* HLC derived from CIP */
1440 lhlc
= strlen(cip2bchlc
[cmsg
->CIPValue
].hlc
);
1445 /* have BC: allocate and assemble command string */
1446 l
= lbc
+ 7; /* "^SBC=" + value + "\r" + null byte */
1448 l
+= lhlc
+ 7; /* ";^SHLC=" + value */
1449 commands
[AT_BC
] = kmalloc(l
, GFP_KERNEL
);
1450 if (!commands
[AT_BC
])
1452 strcpy(commands
[AT_BC
], "^SBC=");
1453 if (cmsg
->BC
&& cmsg
->BC
[0]) /* BC specified explicitly */
1454 decode_ie(cmsg
->BC
, commands
[AT_BC
] + 5);
1455 else /* BC derived from CIP */
1456 strcpy(commands
[AT_BC
] + 5,
1457 cip2bchlc
[cmsg
->CIPValue
].bc
);
1459 strcpy(commands
[AT_BC
] + lbc
+ 5, ";^SHLC=");
1460 if (cmsg
->HLC
&& cmsg
->HLC
[0])
1461 /* HLC specified explicitly */
1462 decode_ie(cmsg
->HLC
,
1463 commands
[AT_BC
] + lbc
+ 12);
1464 else /* HLC derived from CIP */
1465 strcpy(commands
[AT_BC
] + lbc
+ 12,
1466 cip2bchlc
[cmsg
->CIPValue
].hlc
);
1468 strcpy(commands
[AT_BC
] + l
- 2, "\r");
1472 dev_notice(cs
->dev
, "%s: cannot set HLC without BC\n",
1474 info
= CapiIllMessageParmCoding
; /* ? */
1479 /* check/encode parameter: B Protocol */
1480 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1481 bcs
->proto2
= L2_HDLC
;
1483 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1485 switch (cmsg
->B1protocol
) {
1487 bcs
->proto2
= L2_HDLC
;
1490 bcs
->proto2
= L2_VOICE
;
1494 "B1 Protocol %u unsupported, using Transparent\n",
1496 bcs
->proto2
= L2_VOICE
;
1498 if (cmsg
->B2protocol
!= 1)
1500 "B2 Protocol %u unsupported, using Transparent\n",
1502 if (cmsg
->B3protocol
!= 0)
1504 "B3 Protocol %u unsupported, using Transparent\n",
1506 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1507 "CONNECT_REQ", "B1 Configuration");
1508 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1509 "CONNECT_REQ", "B2 Configuration");
1510 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1511 "CONNECT_REQ", "B3 Configuration");
1513 commands
[AT_PROTO
] = kmalloc(9, GFP_KERNEL
);
1514 if (!commands
[AT_PROTO
])
1516 snprintf(commands
[AT_PROTO
], 9, "^SBPR=%u\r", bcs
->proto2
);
1518 /* ToDo: check/encode remaining parameters */
1519 ignore_cstruct_param(cs
, cmsg
->CalledPartySubaddress
,
1520 "CONNECT_REQ", "Called pty subaddr");
1521 ignore_cstruct_param(cs
, cmsg
->CallingPartySubaddress
,
1522 "CONNECT_REQ", "Calling pty subaddr");
1523 ignore_cstruct_param(cs
, cmsg
->LLC
,
1524 "CONNECT_REQ", "LLC");
1525 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1526 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1527 "CONNECT_REQ", "B Channel Information");
1528 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1529 "CONNECT_REQ", "Keypad Facility");
1530 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1531 "CONNECT_REQ", "User-User Data");
1532 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1533 "CONNECT_REQ", "Facility Data Array");
1536 /* encode parameter: B channel to use */
1537 commands
[AT_ISO
] = kmalloc(9, GFP_KERNEL
);
1538 if (!commands
[AT_ISO
])
1540 snprintf(commands
[AT_ISO
], 9, "^SISO=%u\r",
1541 (unsigned) bcs
->channel
+ 1);
1543 /* queue & schedule EV_DIAL event */
1544 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_DIAL
, commands
,
1545 bcs
->at_state
.seq_index
, NULL
)) {
1546 info
= CAPI_MSGOSRESOURCEERR
;
1549 gigaset_schedule_event(cs
);
1550 send_conf(iif
, ap
, skb
, CapiSuccess
);
1554 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1555 info
= CAPI_MSGOSRESOURCEERR
;
1558 for (i
= 0; i
< AT_NUM
; i
++)
1561 gigaset_free_channel(bcs
);
1562 send_conf(iif
, ap
, skb
, info
);
1566 * process CONNECT_RESP message
1567 * checks protocol parameters and queues an ACCEPT or HUP event
1569 static void do_connect_resp(struct gigaset_capi_ctr
*iif
,
1570 struct gigaset_capi_appl
*ap
,
1571 struct sk_buff
*skb
)
1573 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1574 _cmsg
*cmsg
= &iif
->acmsg
;
1575 struct bc_state
*bcs
;
1576 struct gigaset_capi_appl
*oap
;
1577 unsigned long flags
;
1580 /* decode message */
1581 capi_message2cmsg(cmsg
, skb
->data
);
1582 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1583 dev_kfree_skb_any(skb
);
1585 /* extract and check channel number from PLCI */
1586 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1587 if (!channel
|| channel
> cs
->channels
) {
1588 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1589 "CONNECT_RESP", "PLCI", cmsg
->adr
.adrPLCI
);
1592 bcs
= cs
->bcs
+ channel
- 1;
1594 switch (cmsg
->Reject
) {
1595 case 0: /* Accept */
1596 /* drop all competing applications, keep only this one */
1597 spin_lock_irqsave(&bcs
->aplock
, flags
);
1598 while (bcs
->ap
!= NULL
) {
1600 bcs
->ap
= oap
->bcnext
;
1602 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1603 send_disconnect_ind(bcs
, oap
,
1604 CapiCallGivenToOtherApplication
);
1605 spin_lock_irqsave(&bcs
->aplock
, flags
);
1610 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1612 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1613 dev_kfree_skb(bcs
->rx_skb
);
1614 gigaset_new_rx_skb(bcs
);
1615 bcs
->chstate
|= CHS_NOTIFY_LL
;
1617 /* check/encode B channel protocol */
1618 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1619 bcs
->proto2
= L2_HDLC
;
1621 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1623 switch (cmsg
->B1protocol
) {
1625 bcs
->proto2
= L2_HDLC
;
1628 bcs
->proto2
= L2_VOICE
;
1632 "B1 Protocol %u unsupported, using Transparent\n",
1634 bcs
->proto2
= L2_VOICE
;
1636 if (cmsg
->B2protocol
!= 1)
1638 "B2 Protocol %u unsupported, using Transparent\n",
1640 if (cmsg
->B3protocol
!= 0)
1642 "B3 Protocol %u unsupported, using Transparent\n",
1644 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1645 "CONNECT_RESP", "B1 Configuration");
1646 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1647 "CONNECT_RESP", "B2 Configuration");
1648 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1649 "CONNECT_RESP", "B3 Configuration");
1652 /* ToDo: check/encode remaining parameters */
1653 ignore_cstruct_param(cs
, cmsg
->ConnectedNumber
,
1654 "CONNECT_RESP", "Connected Number");
1655 ignore_cstruct_param(cs
, cmsg
->ConnectedSubaddress
,
1656 "CONNECT_RESP", "Connected Subaddress");
1657 ignore_cstruct_param(cs
, cmsg
->LLC
,
1658 "CONNECT_RESP", "LLC");
1659 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1660 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1661 "CONNECT_RESP", "BChannel Information");
1662 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1663 "CONNECT_RESP", "Keypad Facility");
1664 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1665 "CONNECT_RESP", "User-User Data");
1666 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1667 "CONNECT_RESP", "Facility Data Array");
1671 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1672 EV_ACCEPT
, NULL
, 0, NULL
))
1674 gigaset_schedule_event(cs
);
1677 case 1: /* Ignore */
1678 /* send DISCONNECT_IND to this application */
1679 send_disconnect_ind(bcs
, ap
, 0);
1681 /* remove it from the list of listening apps */
1682 spin_lock_irqsave(&bcs
->aplock
, flags
);
1683 if (bcs
->ap
== ap
) {
1684 bcs
->ap
= ap
->bcnext
;
1685 if (bcs
->ap
== NULL
) {
1686 /* last one: stop ev-layer hupD notifications */
1687 bcs
->apconnstate
= APCONN_NONE
;
1688 bcs
->chstate
&= ~CHS_NOTIFY_LL
;
1690 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1693 for (oap
= bcs
->ap
; oap
!= NULL
; oap
= oap
->bcnext
) {
1694 if (oap
->bcnext
== ap
) {
1695 oap
->bcnext
= oap
->bcnext
->bcnext
;
1696 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1700 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1701 dev_err(cs
->dev
, "%s: application %u not found\n",
1705 default: /* Reject */
1706 /* drop all competing applications, keep only this one */
1707 spin_lock_irqsave(&bcs
->aplock
, flags
);
1708 while (bcs
->ap
!= NULL
) {
1710 bcs
->ap
= oap
->bcnext
;
1712 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1713 send_disconnect_ind(bcs
, oap
,
1714 CapiCallGivenToOtherApplication
);
1715 spin_lock_irqsave(&bcs
->aplock
, flags
);
1720 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1722 /* reject call - will trigger DISCONNECT_IND for this app */
1723 dev_info(cs
->dev
, "%s: Reject=%x\n",
1724 "CONNECT_RESP", cmsg
->Reject
);
1725 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1726 EV_HUP
, NULL
, 0, NULL
))
1728 gigaset_schedule_event(cs
);
1734 * process CONNECT_B3_REQ message
1735 * build NCCI and emit CONNECT_B3_CONF reply
1737 static void do_connect_b3_req(struct gigaset_capi_ctr
*iif
,
1738 struct gigaset_capi_appl
*ap
,
1739 struct sk_buff
*skb
)
1741 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1742 _cmsg
*cmsg
= &iif
->acmsg
;
1743 struct bc_state
*bcs
;
1746 /* decode message */
1747 capi_message2cmsg(cmsg
, skb
->data
);
1748 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1750 /* extract and check channel number from PLCI */
1751 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1752 if (!channel
|| channel
> cs
->channels
) {
1753 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1754 "CONNECT_B3_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1755 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1758 bcs
= &cs
->bcs
[channel
-1];
1760 /* mark logical connection active */
1761 bcs
->apconnstate
= APCONN_ACTIVE
;
1763 /* build NCCI: always 1 (one B3 connection only) */
1764 cmsg
->adr
.adrNCCI
|= 1 << 16;
1766 /* NCPI parameter: not applicable for B3 Transparent */
1767 ignore_cstruct_param(cs
, cmsg
->NCPI
, "CONNECT_B3_REQ", "NCPI");
1768 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1769 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1773 * process CONNECT_B3_RESP message
1774 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1775 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1776 * The emitted message is always shorter than the received one,
1777 * allowing to reuse the skb.
1779 static void do_connect_b3_resp(struct gigaset_capi_ctr
*iif
,
1780 struct gigaset_capi_appl
*ap
,
1781 struct sk_buff
*skb
)
1783 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1784 _cmsg
*cmsg
= &iif
->acmsg
;
1785 struct bc_state
*bcs
;
1787 unsigned int msgsize
;
1790 /* decode message */
1791 capi_message2cmsg(cmsg
, skb
->data
);
1792 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1794 /* extract and check channel number and NCCI */
1795 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1796 if (!channel
|| channel
> cs
->channels
||
1797 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1798 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1799 "CONNECT_B3_RESP", "NCCI", cmsg
->adr
.adrNCCI
);
1800 dev_kfree_skb_any(skb
);
1803 bcs
= &cs
->bcs
[channel
-1];
1806 /* Reject: clear B3 connect received flag */
1807 bcs
->apconnstate
= APCONN_SETUP
;
1809 /* trigger hangup, causing eventual DISCONNECT_IND */
1810 if (!gigaset_add_event(cs
, &bcs
->at_state
,
1811 EV_HUP
, NULL
, 0, NULL
)) {
1812 dev_kfree_skb_any(skb
);
1815 gigaset_schedule_event(cs
);
1817 /* emit DISCONNECT_B3_IND */
1818 command
= CAPI_DISCONNECT_B3
;
1819 msgsize
= CAPI_DISCONNECT_B3_IND_BASELEN
;
1822 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1823 * we only send CONNECT_B3_IND if the B channel is up
1825 command
= CAPI_CONNECT_B3_ACTIVE
;
1826 msgsize
= CAPI_CONNECT_B3_ACTIVE_IND_BASELEN
;
1828 capi_cmsg_header(cmsg
, ap
->id
, command
, CAPI_IND
,
1829 ap
->nextMessageNumber
++, cmsg
->adr
.adrNCCI
);
1830 __skb_trim(skb
, msgsize
);
1831 capi_cmsg2message(cmsg
, skb
->data
);
1832 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1833 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1837 * process DISCONNECT_REQ message
1838 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1839 * emit DISCONNECT_CONF reply
1841 static void do_disconnect_req(struct gigaset_capi_ctr
*iif
,
1842 struct gigaset_capi_appl
*ap
,
1843 struct sk_buff
*skb
)
1845 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1846 _cmsg
*cmsg
= &iif
->acmsg
;
1847 struct bc_state
*bcs
;
1849 struct sk_buff
*b3skb
;
1852 /* decode message */
1853 capi_message2cmsg(cmsg
, skb
->data
);
1854 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1856 /* extract and check channel number from PLCI */
1857 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1858 if (!channel
|| channel
> cs
->channels
) {
1859 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1860 "DISCONNECT_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1861 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1864 bcs
= cs
->bcs
+ channel
- 1;
1866 /* ToDo: process parameter: Additional info */
1867 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1868 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1869 "DISCONNECT_REQ", "B Channel Information");
1870 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1871 "DISCONNECT_REQ", "Keypad Facility");
1872 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1873 "DISCONNECT_REQ", "User-User Data");
1874 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1875 "DISCONNECT_REQ", "Facility Data Array");
1878 /* skip if DISCONNECT_IND already sent */
1879 if (!bcs
->apconnstate
)
1882 /* check for active logical connection */
1883 if (bcs
->apconnstate
>= APCONN_ACTIVE
) {
1885 * emit DISCONNECT_B3_IND with cause 0x3301
1886 * use separate cmsg structure, as the content of iif->acmsg
1887 * is still needed for creating the _CONF message
1889 b3cmsg
= kmalloc(sizeof(*b3cmsg
), GFP_KERNEL
);
1891 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1892 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1895 capi_cmsg_header(b3cmsg
, ap
->id
, CAPI_DISCONNECT_B3
, CAPI_IND
,
1896 ap
->nextMessageNumber
++,
1897 cmsg
->adr
.adrPLCI
| (1 << 16));
1898 b3cmsg
->Reason_B3
= CapiProtocolErrorLayer1
;
1899 b3skb
= alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN
, GFP_KERNEL
);
1900 if (b3skb
== NULL
) {
1901 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1902 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1905 capi_cmsg2message(b3cmsg
,
1906 __skb_put(b3skb
, CAPI_DISCONNECT_B3_IND_BASELEN
));
1908 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, b3skb
);
1911 /* trigger hangup, causing eventual DISCONNECT_IND */
1912 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_HUP
, NULL
, 0, NULL
)) {
1913 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1916 gigaset_schedule_event(cs
);
1919 send_conf(iif
, ap
, skb
, CapiSuccess
);
1923 * process DISCONNECT_B3_REQ message
1924 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1926 static void do_disconnect_b3_req(struct gigaset_capi_ctr
*iif
,
1927 struct gigaset_capi_appl
*ap
,
1928 struct sk_buff
*skb
)
1930 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1931 _cmsg
*cmsg
= &iif
->acmsg
;
1932 struct bc_state
*bcs
;
1935 /* decode message */
1936 capi_message2cmsg(cmsg
, skb
->data
);
1937 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1939 /* extract and check channel number and NCCI */
1940 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1941 if (!channel
|| channel
> cs
->channels
||
1942 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1943 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1944 "DISCONNECT_B3_REQ", "NCCI", cmsg
->adr
.adrNCCI
);
1945 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1948 bcs
= &cs
->bcs
[channel
-1];
1950 /* reject if logical connection not active */
1951 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
1952 send_conf(iif
, ap
, skb
,
1953 CapiMessageNotSupportedInCurrentState
);
1957 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1958 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_HUP
, NULL
, 0, NULL
)) {
1959 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1962 gigaset_schedule_event(cs
);
1964 /* NCPI parameter: not applicable for B3 Transparent */
1965 ignore_cstruct_param(cs
, cmsg
->NCPI
,
1966 "DISCONNECT_B3_REQ", "NCPI");
1967 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1968 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1972 * process DATA_B3_REQ message
1974 static void do_data_b3_req(struct gigaset_capi_ctr
*iif
,
1975 struct gigaset_capi_appl
*ap
,
1976 struct sk_buff
*skb
)
1978 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1979 struct bc_state
*bcs
;
1980 int channel
= CAPIMSG_PLCI_PART(skb
->data
);
1981 u16 ncci
= CAPIMSG_NCCI_PART(skb
->data
);
1982 u16 msglen
= CAPIMSG_LEN(skb
->data
);
1983 u16 datalen
= CAPIMSG_DATALEN(skb
->data
);
1984 u16 flags
= CAPIMSG_FLAGS(skb
->data
);
1985 u16 msgid
= CAPIMSG_MSGID(skb
->data
);
1986 u16 handle
= CAPIMSG_HANDLE_REQ(skb
->data
);
1988 /* frequent message, avoid _cmsg overhead */
1989 dump_rawmsg(DEBUG_MCMD
, __func__
, skb
->data
);
1991 /* check parameters */
1992 if (channel
== 0 || channel
> cs
->channels
|| ncci
!= 1) {
1993 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1994 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb
->data
));
1995 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1998 bcs
= &cs
->bcs
[channel
-1];
1999 if (msglen
!= CAPI_DATA_B3_REQ_LEN
&& msglen
!= CAPI_DATA_B3_REQ_LEN64
)
2000 dev_notice(cs
->dev
, "%s: unexpected length %d\n",
2001 "DATA_B3_REQ", msglen
);
2002 if (msglen
+ datalen
!= skb
->len
)
2003 dev_notice(cs
->dev
, "%s: length mismatch (%d+%d!=%d)\n",
2004 "DATA_B3_REQ", msglen
, datalen
, skb
->len
);
2005 if (msglen
+ datalen
> skb
->len
) {
2006 /* message too short for announced data length */
2007 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
); /* ? */
2010 if (flags
& CAPI_FLAGS_RESERVED
) {
2011 dev_notice(cs
->dev
, "%s: reserved flags set (%x)\n",
2012 "DATA_B3_REQ", flags
);
2013 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
2017 /* reject if logical connection not active */
2018 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
2019 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
2023 /* pull CAPI message into link layer header */
2024 skb_reset_mac_header(skb
);
2025 skb
->mac_len
= msglen
;
2026 skb_pull(skb
, msglen
);
2028 /* pass to device-specific module */
2029 if (cs
->ops
->send_skb(bcs
, skb
) < 0) {
2030 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
2035 * DATA_B3_CONF will be sent by gigaset_skb_sent() only if "delivery
2036 * confirmation" bit is set; otherwise we have to send it now
2038 if (!(flags
& CAPI_FLAGS_DELIVERY_CONFIRMATION
))
2039 send_data_b3_conf(cs
, &iif
->ctr
, ap
->id
, msgid
, channel
, handle
,
2040 flags
? CapiFlagsNotSupportedByProtocol
2045 * process RESET_B3_REQ message
2046 * just always reply "not supported by current protocol"
2048 static void do_reset_b3_req(struct gigaset_capi_ctr
*iif
,
2049 struct gigaset_capi_appl
*ap
,
2050 struct sk_buff
*skb
)
2052 /* decode message */
2053 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2054 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2055 send_conf(iif
, ap
, skb
,
2056 CapiResetProcedureNotSupportedByCurrentProtocol
);
2060 * dump unsupported/ignored messages at most twice per minute,
2061 * some apps send those very frequently
2063 static unsigned long ignored_msg_dump_time
;
2066 * unsupported CAPI message handler
2068 static void do_unsupported(struct gigaset_capi_ctr
*iif
,
2069 struct gigaset_capi_appl
*ap
,
2070 struct sk_buff
*skb
)
2072 /* decode message */
2073 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2074 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000))
2075 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2076 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
2080 * CAPI message handler: no-op
2082 static void do_nothing(struct gigaset_capi_ctr
*iif
,
2083 struct gigaset_capi_appl
*ap
,
2084 struct sk_buff
*skb
)
2086 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000)) {
2087 /* decode message */
2088 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2089 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2091 dev_kfree_skb_any(skb
);
2094 static void do_data_b3_resp(struct gigaset_capi_ctr
*iif
,
2095 struct gigaset_capi_appl
*ap
,
2096 struct sk_buff
*skb
)
2098 dump_rawmsg(DEBUG_MCMD
, __func__
, skb
->data
);
2099 dev_kfree_skb_any(skb
);
2102 /* table of outgoing CAPI message handlers with lookup function */
2103 typedef void (*capi_send_handler_t
)(struct gigaset_capi_ctr
*,
2104 struct gigaset_capi_appl
*,
2109 capi_send_handler_t handler
;
2110 } capi_send_handler_table
[] = {
2111 /* most frequent messages first for faster lookup */
2112 { CAPI_DATA_B3_REQ
, do_data_b3_req
},
2113 { CAPI_DATA_B3_RESP
, do_data_b3_resp
},
2115 { CAPI_ALERT_REQ
, do_alert_req
},
2116 { CAPI_CONNECT_ACTIVE_RESP
, do_nothing
},
2117 { CAPI_CONNECT_B3_ACTIVE_RESP
, do_nothing
},
2118 { CAPI_CONNECT_B3_REQ
, do_connect_b3_req
},
2119 { CAPI_CONNECT_B3_RESP
, do_connect_b3_resp
},
2120 { CAPI_CONNECT_B3_T90_ACTIVE_RESP
, do_nothing
},
2121 { CAPI_CONNECT_REQ
, do_connect_req
},
2122 { CAPI_CONNECT_RESP
, do_connect_resp
},
2123 { CAPI_DISCONNECT_B3_REQ
, do_disconnect_b3_req
},
2124 { CAPI_DISCONNECT_B3_RESP
, do_nothing
},
2125 { CAPI_DISCONNECT_REQ
, do_disconnect_req
},
2126 { CAPI_DISCONNECT_RESP
, do_nothing
},
2127 { CAPI_FACILITY_REQ
, do_facility_req
},
2128 { CAPI_FACILITY_RESP
, do_nothing
},
2129 { CAPI_LISTEN_REQ
, do_listen_req
},
2130 { CAPI_SELECT_B_PROTOCOL_REQ
, do_unsupported
},
2131 { CAPI_RESET_B3_REQ
, do_reset_b3_req
},
2132 { CAPI_RESET_B3_RESP
, do_nothing
},
2135 * ToDo: support overlap sending (requires ev-layer state
2136 * machine extension to generate additional ATD commands)
2138 { CAPI_INFO_REQ
, do_unsupported
},
2139 { CAPI_INFO_RESP
, do_nothing
},
2142 * ToDo: what's the proper response for these?
2144 { CAPI_MANUFACTURER_REQ
, do_nothing
},
2145 { CAPI_MANUFACTURER_RESP
, do_nothing
},
2148 /* look up handler */
2149 static inline capi_send_handler_t
lookup_capi_send_handler(const u16 cmd
)
2153 for (i
= 0; i
< ARRAY_SIZE(capi_send_handler_table
); i
++)
2154 if (capi_send_handler_table
[i
].cmd
== cmd
)
2155 return capi_send_handler_table
[i
].handler
;
2161 * gigaset_send_message() - accept a CAPI message from an application
2162 * @ctr: controller descriptor structure.
2163 * @skb: CAPI message.
2165 * Return value: CAPI error code
2166 * Note: capidrv (and probably others, too) only uses the return value to
2167 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2169 static u16
gigaset_send_message(struct capi_ctr
*ctr
, struct sk_buff
*skb
)
2171 struct gigaset_capi_ctr
*iif
2172 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
2173 struct cardstate
*cs
= ctr
->driverdata
;
2174 struct gigaset_capi_appl
*ap
;
2175 capi_send_handler_t handler
;
2177 /* can only handle linear sk_buffs */
2178 if (skb_linearize(skb
) < 0) {
2179 dev_warn(cs
->dev
, "%s: skb_linearize failed\n", __func__
);
2180 return CAPI_MSGOSRESOURCEERR
;
2183 /* retrieve application data structure */
2184 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2186 dev_notice(cs
->dev
, "%s: application %u not registered\n",
2187 __func__
, CAPIMSG_APPID(skb
->data
));
2188 return CAPI_ILLAPPNR
;
2191 /* look up command */
2192 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2194 /* unknown/unsupported message type */
2195 if (printk_ratelimit())
2196 dev_notice(cs
->dev
, "%s: unsupported message %u\n",
2197 __func__
, CAPIMSG_CMD(skb
->data
));
2198 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL
;
2202 if (atomic_add_return(1, &iif
->sendqlen
) > 1) {
2203 /* queue behind other messages */
2204 skb_queue_tail(&iif
->sendqueue
, skb
);
2205 return CAPI_NOERROR
;
2208 /* process message */
2209 handler(iif
, ap
, skb
);
2211 /* process other messages arrived in the meantime */
2212 while (atomic_sub_return(1, &iif
->sendqlen
) > 0) {
2213 skb
= skb_dequeue(&iif
->sendqueue
);
2215 /* should never happen */
2216 dev_err(cs
->dev
, "%s: send queue empty\n", __func__
);
2219 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2221 /* could that happen? */
2222 dev_warn(cs
->dev
, "%s: application %u vanished\n",
2223 __func__
, CAPIMSG_APPID(skb
->data
));
2226 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2228 /* should never happen */
2229 dev_err(cs
->dev
, "%s: handler %x vanished\n",
2230 __func__
, CAPIMSG_CMD(skb
->data
));
2233 handler(iif
, ap
, skb
);
2236 return CAPI_NOERROR
;
2240 * gigaset_procinfo() - build single line description for controller
2241 * @ctr: controller descriptor structure.
2243 * Return value: pointer to generated string (null terminated)
2245 static char *gigaset_procinfo(struct capi_ctr
*ctr
)
2247 return ctr
->name
; /* ToDo: more? */
2250 static int gigaset_proc_show(struct seq_file
*m
, void *v
)
2252 struct capi_ctr
*ctr
= m
->private;
2253 struct cardstate
*cs
= ctr
->driverdata
;
2257 seq_printf(m
, "%-16s %s\n", "name", ctr
->name
);
2258 seq_printf(m
, "%-16s %s %s\n", "dev",
2259 dev_driver_string(cs
->dev
), dev_name(cs
->dev
));
2260 seq_printf(m
, "%-16s %d\n", "id", cs
->myid
);
2262 seq_printf(m
, "%-16s %d.%d.%d.%d\n", "firmware",
2263 cs
->fwver
[0], cs
->fwver
[1], cs
->fwver
[2], cs
->fwver
[3]);
2264 seq_printf(m
, "%-16s %d\n", "channels", cs
->channels
);
2265 seq_printf(m
, "%-16s %s\n", "onechannel", cs
->onechannel
? "yes" : "no");
2283 seq_printf(m
, "%-16s %s\n", "mode", s
);
2285 switch (cs
->mstate
) {
2286 case MS_UNINITIALIZED
:
2287 s
= "uninitialized";
2307 seq_printf(m
, "%-16s %s\n", "mstate", s
);
2309 seq_printf(m
, "%-16s %s\n", "running", cs
->running
? "yes" : "no");
2310 seq_printf(m
, "%-16s %s\n", "connected", cs
->connected
? "yes" : "no");
2311 seq_printf(m
, "%-16s %s\n", "isdn_up", cs
->isdn_up
? "yes" : "no");
2312 seq_printf(m
, "%-16s %s\n", "cidmode", cs
->cidmode
? "yes" : "no");
2314 for (i
= 0; i
< cs
->channels
; i
++) {
2315 seq_printf(m
, "[%d]%-13s %d\n", i
, "corrupted",
2316 cs
->bcs
[i
].corrupted
);
2317 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_down",
2318 cs
->bcs
[i
].trans_down
);
2319 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_up",
2320 cs
->bcs
[i
].trans_up
);
2321 seq_printf(m
, "[%d]%-13s %d\n", i
, "chstate",
2322 cs
->bcs
[i
].chstate
);
2323 switch (cs
->bcs
[i
].proto2
) {
2336 seq_printf(m
, "[%d]%-13s %s\n", i
, "proto2", s
);
2341 static int gigaset_proc_open(struct inode
*inode
, struct file
*file
)
2343 return single_open(file
, gigaset_proc_show
, PDE(inode
)->data
);
2346 static const struct file_operations gigaset_proc_fops
= {
2347 .owner
= THIS_MODULE
,
2348 .open
= gigaset_proc_open
,
2350 .llseek
= seq_lseek
,
2351 .release
= single_release
,
2355 * gigaset_isdn_regdev() - register device to LL
2356 * @cs: device descriptor structure.
2357 * @isdnid: device name.
2359 * Return value: 1 for success, 0 for failure
2361 int gigaset_isdn_regdev(struct cardstate
*cs
, const char *isdnid
)
2363 struct gigaset_capi_ctr
*iif
;
2366 iif
= kmalloc(sizeof(*iif
), GFP_KERNEL
);
2368 pr_err("%s: out of memory\n", __func__
);
2372 /* prepare controller structure */
2373 iif
->ctr
.owner
= THIS_MODULE
;
2374 iif
->ctr
.driverdata
= cs
;
2375 strncpy(iif
->ctr
.name
, isdnid
, sizeof(iif
->ctr
.name
));
2376 iif
->ctr
.driver_name
= "gigaset";
2377 iif
->ctr
.load_firmware
= NULL
;
2378 iif
->ctr
.reset_ctr
= NULL
;
2379 iif
->ctr
.register_appl
= gigaset_register_appl
;
2380 iif
->ctr
.release_appl
= gigaset_release_appl
;
2381 iif
->ctr
.send_message
= gigaset_send_message
;
2382 iif
->ctr
.procinfo
= gigaset_procinfo
;
2383 iif
->ctr
.proc_fops
= &gigaset_proc_fops
;
2384 INIT_LIST_HEAD(&iif
->appls
);
2385 skb_queue_head_init(&iif
->sendqueue
);
2386 atomic_set(&iif
->sendqlen
, 0);
2388 /* register controller with CAPI */
2389 rc
= attach_capi_ctr(&iif
->ctr
);
2391 pr_err("attach_capi_ctr failed (%d)\n", rc
);
2397 cs
->hw_hdr_len
= CAPI_DATA_B3_REQ_LEN
;
2402 * gigaset_isdn_unregdev() - unregister device from LL
2403 * @cs: device descriptor structure.
2405 void gigaset_isdn_unregdev(struct cardstate
*cs
)
2407 struct gigaset_capi_ctr
*iif
= cs
->iif
;
2409 detach_capi_ctr(&iif
->ctr
);
2414 static struct capi_driver capi_driver_gigaset
= {
2420 * gigaset_isdn_regdrv() - register driver to LL
2422 void gigaset_isdn_regdrv(void)
2424 pr_info("Kernel CAPI interface\n");
2425 register_capi_driver(&capi_driver_gigaset
);
2429 * gigaset_isdn_unregdrv() - unregister driver from LL
2431 void gigaset_isdn_unregdrv(void)
2433 unregister_capi_driver(&capi_driver_gigaset
);