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
;
1057 bcap
= bcap
->bcnext
;
1058 } while (bcap
!= NULL
);
1059 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1063 * release CAPI application
1065 static void gigaset_release_appl(struct capi_ctr
*ctr
, u16 appl
)
1067 struct gigaset_capi_ctr
*iif
1068 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
1069 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1070 struct gigaset_capi_appl
*ap
, *tmp
;
1073 gig_dbg(DEBUG_CMD
, "%s [%u]", __func__
, appl
);
1075 list_for_each_entry_safe(ap
, tmp
, &iif
->appls
, ctrlist
)
1076 if (ap
->id
== appl
) {
1077 /* remove from any channels */
1078 for (ch
= 0; ch
< cs
->channels
; ch
++)
1079 remove_appl_from_channel(&cs
->bcs
[ch
], ap
);
1081 /* remove from registration list */
1082 list_del(&ap
->ctrlist
);
1084 dev_info(cs
->dev
, "application %u released\n", appl
);
1089 * =====================================================================
1090 * outgoing CAPI message handler
1091 * =====================================================================
1095 * helper function: emit reply message with given Info value
1097 static void send_conf(struct gigaset_capi_ctr
*iif
,
1098 struct gigaset_capi_appl
*ap
,
1099 struct sk_buff
*skb
,
1103 * _CONF replies always only have NCCI and Info parameters
1104 * so they'll fit into the _REQ message skb
1106 capi_cmsg_answer(&iif
->acmsg
);
1107 iif
->acmsg
.Info
= info
;
1108 capi_cmsg2message(&iif
->acmsg
, skb
->data
);
1109 __skb_trim(skb
, CAPI_STDCONF_LEN
);
1110 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1111 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1115 * process FACILITY_REQ message
1117 static void do_facility_req(struct gigaset_capi_ctr
*iif
,
1118 struct gigaset_capi_appl
*ap
,
1119 struct sk_buff
*skb
)
1121 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1122 _cmsg
*cmsg
= &iif
->acmsg
;
1123 struct sk_buff
*cskb
;
1125 unsigned int msgsize
= CAPI_FACILITY_CONF_BASELEN
;
1127 static u8 confparam
[10]; /* max. 9 octets + length byte */
1129 /* decode message */
1130 capi_message2cmsg(cmsg
, skb
->data
);
1131 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1134 * Facility Request Parameter is not decoded by capi_message2cmsg()
1135 * encoding depends on Facility Selector
1137 switch (cmsg
->FacilitySelector
) {
1138 case CAPI_FACILITY_DTMF
: /* ToDo */
1139 info
= CapiFacilityNotSupported
;
1140 confparam
[0] = 2; /* length */
1141 /* DTMF information: Unknown DTMF request */
1142 capimsg_setu16(confparam
, 1, 2);
1145 case CAPI_FACILITY_V42BIS
: /* not supported */
1146 info
= CapiFacilityNotSupported
;
1147 confparam
[0] = 2; /* length */
1148 /* V.42 bis information: not available */
1149 capimsg_setu16(confparam
, 1, 1);
1152 case CAPI_FACILITY_SUPPSVC
:
1153 /* decode Function parameter */
1154 pparam
= cmsg
->FacilityRequestParameter
;
1155 if (pparam
== NULL
|| pparam
[0] < 2) {
1156 dev_notice(cs
->dev
, "%s: %s missing\n", "FACILITY_REQ",
1157 "Facility Request Parameter");
1158 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
1161 function
= CAPIMSG_U16(pparam
, 1);
1163 case CAPI_SUPPSVC_GETSUPPORTED
:
1165 /* Supplementary Service specific parameter */
1166 confparam
[3] = 6; /* length */
1167 /* Supplementary services info: Success */
1168 capimsg_setu16(confparam
, 4, CapiSuccess
);
1169 /* Supported Services: none */
1170 capimsg_setu32(confparam
, 6, 0);
1172 case CAPI_SUPPSVC_LISTEN
:
1173 if (pparam
[0] < 7 || pparam
[3] < 4) {
1174 dev_notice(cs
->dev
, "%s: %s missing\n",
1175 "FACILITY_REQ", "Notification Mask");
1176 send_conf(iif
, ap
, skb
,
1177 CapiIllMessageParmCoding
);
1180 if (CAPIMSG_U32(pparam
, 4) != 0) {
1182 "%s: unsupported supplementary service notification mask 0x%x\n",
1183 "FACILITY_REQ", CAPIMSG_U32(pparam
, 4));
1184 info
= CapiFacilitySpecificFunctionNotSupported
;
1185 confparam
[3] = 2; /* length */
1186 capimsg_setu16(confparam
, 4,
1187 CapiSupplementaryServiceNotSupported
);
1190 confparam
[3] = 2; /* length */
1191 capimsg_setu16(confparam
, 4, CapiSuccess
);
1193 /* ToDo: add supported services */
1196 "%s: unsupported supplementary service function 0x%04x\n",
1197 "FACILITY_REQ", function
);
1198 info
= CapiFacilitySpecificFunctionNotSupported
;
1199 /* Supplementary Service specific parameter */
1200 confparam
[3] = 2; /* length */
1201 /* Supplementary services info: not supported */
1202 capimsg_setu16(confparam
, 4,
1203 CapiSupplementaryServiceNotSupported
);
1206 /* Facility confirmation parameter */
1207 confparam
[0] = confparam
[3] + 3; /* total length */
1208 /* Function: copy from _REQ message */
1209 capimsg_setu16(confparam
, 1, function
);
1210 /* Supplementary Service specific parameter already set above */
1213 case CAPI_FACILITY_WAKEUP
: /* ToDo */
1214 info
= CapiFacilityNotSupported
;
1215 confparam
[0] = 2; /* length */
1216 /* Number of accepted awake request parameters: 0 */
1217 capimsg_setu16(confparam
, 1, 0);
1221 info
= CapiFacilityNotSupported
;
1222 confparam
[0] = 0; /* empty struct */
1225 /* send FACILITY_CONF with given Info and confirmation parameter */
1226 capi_cmsg_answer(cmsg
);
1228 cmsg
->FacilityConfirmationParameter
= confparam
;
1229 msgsize
+= confparam
[0]; /* length */
1230 cskb
= alloc_skb(msgsize
, GFP_ATOMIC
);
1232 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1235 capi_cmsg2message(cmsg
, __skb_put(cskb
, msgsize
));
1236 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1237 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, cskb
);
1242 * process LISTEN_REQ message
1243 * just store the masks in the application data structure
1245 static void do_listen_req(struct gigaset_capi_ctr
*iif
,
1246 struct gigaset_capi_appl
*ap
,
1247 struct sk_buff
*skb
)
1249 /* decode message */
1250 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1251 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1253 /* store listening parameters */
1254 ap
->listenInfoMask
= iif
->acmsg
.InfoMask
;
1255 ap
->listenCIPmask
= iif
->acmsg
.CIPmask
;
1256 send_conf(iif
, ap
, skb
, CapiSuccess
);
1260 * process ALERT_REQ message
1261 * nothing to do, Gigaset always alerts anyway
1263 static void do_alert_req(struct gigaset_capi_ctr
*iif
,
1264 struct gigaset_capi_appl
*ap
,
1265 struct sk_buff
*skb
)
1267 /* decode message */
1268 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1269 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1270 send_conf(iif
, ap
, skb
, CapiAlertAlreadySent
);
1274 * process CONNECT_REQ message
1275 * allocate a B channel, prepare dial commands, queue a DIAL event,
1276 * emit CONNECT_CONF reply
1278 static void do_connect_req(struct gigaset_capi_ctr
*iif
,
1279 struct gigaset_capi_appl
*ap
,
1280 struct sk_buff
*skb
)
1282 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1283 _cmsg
*cmsg
= &iif
->acmsg
;
1284 struct bc_state
*bcs
;
1288 unsigned long flags
;
1289 int i
, l
, lbc
, lhlc
;
1292 /* decode message */
1293 capi_message2cmsg(cmsg
, skb
->data
);
1294 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1296 /* get free B channel & construct PLCI */
1297 bcs
= gigaset_get_free_channel(cs
);
1299 dev_notice(cs
->dev
, "%s: no B channel available\n",
1301 send_conf(iif
, ap
, skb
, CapiNoPlciAvailable
);
1304 spin_lock_irqsave(&bcs
->aplock
, flags
);
1305 if (bcs
->ap
!= NULL
|| bcs
->apconnstate
!= APCONN_NONE
)
1306 dev_warn(cs
->dev
, "%s: channel not properly cleared (%p/%d)\n",
1307 __func__
, bcs
->ap
, bcs
->apconnstate
);
1310 bcs
->apconnstate
= APCONN_SETUP
;
1311 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1313 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1314 dev_kfree_skb(bcs
->rx_skb
);
1315 gigaset_new_rx_skb(bcs
);
1316 cmsg
->adr
.adrPLCI
|= (bcs
->channel
+ 1) << 8;
1318 /* build command table */
1319 commands
= kzalloc(AT_NUM
*(sizeof *commands
), GFP_KERNEL
);
1323 /* encode parameter: Called party number */
1324 pp
= cmsg
->CalledPartyNumber
;
1325 if (pp
== NULL
|| *pp
== 0) {
1326 dev_notice(cs
->dev
, "%s: %s missing\n",
1327 "CONNECT_REQ", "Called party number");
1328 info
= CapiIllMessageParmCoding
;
1332 /* check type of number/numbering plan byte */
1334 case 0x80: /* unknown type / unknown numbering plan */
1335 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1337 default: /* others: warn about potential misinterpretation */
1338 dev_notice(cs
->dev
, "%s: %s type/plan 0x%02x unsupported\n",
1339 "CONNECT_REQ", "Called party number", *pp
);
1343 /* translate "**" internal call prefix to CTP value */
1344 if (l
>= 2 && pp
[0] == '*' && pp
[1] == '*') {
1351 commands
[AT_TYPE
] = kstrdup(s
, GFP_KERNEL
);
1352 if (!commands
[AT_TYPE
])
1354 commands
[AT_DIAL
] = kmalloc(l
+3, GFP_KERNEL
);
1355 if (!commands
[AT_DIAL
])
1357 snprintf(commands
[AT_DIAL
], l
+3, "D%.*s\r", l
, pp
);
1359 /* encode parameter: Calling party number */
1360 pp
= cmsg
->CallingPartyNumber
;
1361 if (pp
!= NULL
&& *pp
> 0) {
1364 /* check type of number/numbering plan byte */
1365 /* ToDo: allow for/handle Ext=1? */
1367 case 0x00: /* unknown type / unknown numbering plan */
1368 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1372 "%s: %s type/plan 0x%02x unsupported\n",
1373 "CONNECT_REQ", "Calling party number", *pp
);
1378 /* check presentation indicator */
1380 dev_notice(cs
->dev
, "%s: %s IE truncated\n",
1381 "CONNECT_REQ", "Calling party number");
1382 info
= CapiIllMessageParmCoding
;
1385 switch (*pp
& 0xfc) { /* ignore Screening indicator */
1386 case 0x80: /* Presentation allowed */
1389 case 0xa0: /* Presentation restricted */
1393 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1395 "Presentation/Screening indicator",
1399 commands
[AT_CLIP
] = kstrdup(s
, GFP_KERNEL
);
1400 if (!commands
[AT_CLIP
])
1407 commands
[AT_MSN
] = kmalloc(l
+8, GFP_KERNEL
);
1408 if (!commands
[AT_MSN
])
1410 snprintf(commands
[AT_MSN
], l
+8, "^SMSN=%*s\r", l
, pp
);
1414 /* check parameter: CIP Value */
1415 if (cmsg
->CIPValue
>= ARRAY_SIZE(cip2bchlc
) ||
1416 (cmsg
->CIPValue
> 0 && cip2bchlc
[cmsg
->CIPValue
].bc
== NULL
)) {
1417 dev_notice(cs
->dev
, "%s: unknown CIP value %d\n",
1418 "CONNECT_REQ", cmsg
->CIPValue
);
1419 info
= CapiCipValueUnknown
;
1424 * check/encode parameters: BC & HLC
1425 * must be encoded together as device doesn't accept HLC separately
1426 * explicit parameters override values derived from CIP
1429 /* determine lengths */
1430 if (cmsg
->BC
&& cmsg
->BC
[0]) /* BC specified explicitly */
1431 lbc
= 2*cmsg
->BC
[0];
1432 else if (cip2bchlc
[cmsg
->CIPValue
].bc
) /* BC derived from CIP */
1433 lbc
= strlen(cip2bchlc
[cmsg
->CIPValue
].bc
);
1436 if (cmsg
->HLC
&& cmsg
->HLC
[0]) /* HLC specified explicitly */
1437 lhlc
= 2*cmsg
->HLC
[0];
1438 else if (cip2bchlc
[cmsg
->CIPValue
].hlc
) /* HLC derived from CIP */
1439 lhlc
= strlen(cip2bchlc
[cmsg
->CIPValue
].hlc
);
1444 /* have BC: allocate and assemble command string */
1445 l
= lbc
+ 7; /* "^SBC=" + value + "\r" + null byte */
1447 l
+= lhlc
+ 7; /* ";^SHLC=" + value */
1448 commands
[AT_BC
] = kmalloc(l
, GFP_KERNEL
);
1449 if (!commands
[AT_BC
])
1451 strcpy(commands
[AT_BC
], "^SBC=");
1452 if (cmsg
->BC
&& cmsg
->BC
[0]) /* BC specified explicitly */
1453 decode_ie(cmsg
->BC
, commands
[AT_BC
] + 5);
1454 else /* BC derived from CIP */
1455 strcpy(commands
[AT_BC
] + 5,
1456 cip2bchlc
[cmsg
->CIPValue
].bc
);
1458 strcpy(commands
[AT_BC
] + lbc
+ 5, ";^SHLC=");
1459 if (cmsg
->HLC
&& cmsg
->HLC
[0])
1460 /* HLC specified explicitly */
1461 decode_ie(cmsg
->HLC
,
1462 commands
[AT_BC
] + lbc
+ 12);
1463 else /* HLC derived from CIP */
1464 strcpy(commands
[AT_BC
] + lbc
+ 12,
1465 cip2bchlc
[cmsg
->CIPValue
].hlc
);
1467 strcpy(commands
[AT_BC
] + l
- 2, "\r");
1471 dev_notice(cs
->dev
, "%s: cannot set HLC without BC\n",
1473 info
= CapiIllMessageParmCoding
; /* ? */
1478 /* check/encode parameter: B Protocol */
1479 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1480 bcs
->proto2
= L2_HDLC
;
1482 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1484 switch (cmsg
->B1protocol
) {
1486 bcs
->proto2
= L2_HDLC
;
1489 bcs
->proto2
= L2_VOICE
;
1493 "B1 Protocol %u unsupported, using Transparent\n",
1495 bcs
->proto2
= L2_VOICE
;
1497 if (cmsg
->B2protocol
!= 1)
1499 "B2 Protocol %u unsupported, using Transparent\n",
1501 if (cmsg
->B3protocol
!= 0)
1503 "B3 Protocol %u unsupported, using Transparent\n",
1505 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1506 "CONNECT_REQ", "B1 Configuration");
1507 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1508 "CONNECT_REQ", "B2 Configuration");
1509 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1510 "CONNECT_REQ", "B3 Configuration");
1512 commands
[AT_PROTO
] = kmalloc(9, GFP_KERNEL
);
1513 if (!commands
[AT_PROTO
])
1515 snprintf(commands
[AT_PROTO
], 9, "^SBPR=%u\r", bcs
->proto2
);
1517 /* ToDo: check/encode remaining parameters */
1518 ignore_cstruct_param(cs
, cmsg
->CalledPartySubaddress
,
1519 "CONNECT_REQ", "Called pty subaddr");
1520 ignore_cstruct_param(cs
, cmsg
->CallingPartySubaddress
,
1521 "CONNECT_REQ", "Calling pty subaddr");
1522 ignore_cstruct_param(cs
, cmsg
->LLC
,
1523 "CONNECT_REQ", "LLC");
1524 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1525 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1526 "CONNECT_REQ", "B Channel Information");
1527 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1528 "CONNECT_REQ", "Keypad Facility");
1529 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1530 "CONNECT_REQ", "User-User Data");
1531 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1532 "CONNECT_REQ", "Facility Data Array");
1535 /* encode parameter: B channel to use */
1536 commands
[AT_ISO
] = kmalloc(9, GFP_KERNEL
);
1537 if (!commands
[AT_ISO
])
1539 snprintf(commands
[AT_ISO
], 9, "^SISO=%u\r",
1540 (unsigned) bcs
->channel
+ 1);
1542 /* queue & schedule EV_DIAL event */
1543 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_DIAL
, commands
,
1544 bcs
->at_state
.seq_index
, NULL
)) {
1545 info
= CAPI_MSGOSRESOURCEERR
;
1548 gigaset_schedule_event(cs
);
1549 send_conf(iif
, ap
, skb
, CapiSuccess
);
1553 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1554 info
= CAPI_MSGOSRESOURCEERR
;
1557 for (i
= 0; i
< AT_NUM
; i
++)
1560 gigaset_free_channel(bcs
);
1561 send_conf(iif
, ap
, skb
, info
);
1565 * process CONNECT_RESP message
1566 * checks protocol parameters and queues an ACCEPT or HUP event
1568 static void do_connect_resp(struct gigaset_capi_ctr
*iif
,
1569 struct gigaset_capi_appl
*ap
,
1570 struct sk_buff
*skb
)
1572 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1573 _cmsg
*cmsg
= &iif
->acmsg
;
1574 struct bc_state
*bcs
;
1575 struct gigaset_capi_appl
*oap
;
1576 unsigned long flags
;
1579 /* decode message */
1580 capi_message2cmsg(cmsg
, skb
->data
);
1581 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1582 dev_kfree_skb_any(skb
);
1584 /* extract and check channel number from PLCI */
1585 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1586 if (!channel
|| channel
> cs
->channels
) {
1587 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1588 "CONNECT_RESP", "PLCI", cmsg
->adr
.adrPLCI
);
1591 bcs
= cs
->bcs
+ channel
- 1;
1593 switch (cmsg
->Reject
) {
1594 case 0: /* Accept */
1595 /* drop all competing applications, keep only this one */
1596 spin_lock_irqsave(&bcs
->aplock
, flags
);
1597 while (bcs
->ap
!= NULL
) {
1599 bcs
->ap
= oap
->bcnext
;
1601 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1602 send_disconnect_ind(bcs
, oap
,
1603 CapiCallGivenToOtherApplication
);
1604 spin_lock_irqsave(&bcs
->aplock
, flags
);
1609 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1611 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1612 dev_kfree_skb(bcs
->rx_skb
);
1613 gigaset_new_rx_skb(bcs
);
1614 bcs
->chstate
|= CHS_NOTIFY_LL
;
1616 /* check/encode B channel protocol */
1617 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1618 bcs
->proto2
= L2_HDLC
;
1620 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1622 switch (cmsg
->B1protocol
) {
1624 bcs
->proto2
= L2_HDLC
;
1627 bcs
->proto2
= L2_VOICE
;
1631 "B1 Protocol %u unsupported, using Transparent\n",
1633 bcs
->proto2
= L2_VOICE
;
1635 if (cmsg
->B2protocol
!= 1)
1637 "B2 Protocol %u unsupported, using Transparent\n",
1639 if (cmsg
->B3protocol
!= 0)
1641 "B3 Protocol %u unsupported, using Transparent\n",
1643 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1644 "CONNECT_RESP", "B1 Configuration");
1645 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1646 "CONNECT_RESP", "B2 Configuration");
1647 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1648 "CONNECT_RESP", "B3 Configuration");
1651 /* ToDo: check/encode remaining parameters */
1652 ignore_cstruct_param(cs
, cmsg
->ConnectedNumber
,
1653 "CONNECT_RESP", "Connected Number");
1654 ignore_cstruct_param(cs
, cmsg
->ConnectedSubaddress
,
1655 "CONNECT_RESP", "Connected Subaddress");
1656 ignore_cstruct_param(cs
, cmsg
->LLC
,
1657 "CONNECT_RESP", "LLC");
1658 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1659 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1660 "CONNECT_RESP", "BChannel Information");
1661 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1662 "CONNECT_RESP", "Keypad Facility");
1663 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1664 "CONNECT_RESP", "User-User Data");
1665 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1666 "CONNECT_RESP", "Facility Data Array");
1670 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1671 EV_ACCEPT
, NULL
, 0, NULL
))
1673 gigaset_schedule_event(cs
);
1676 case 1: /* Ignore */
1677 /* send DISCONNECT_IND to this application */
1678 send_disconnect_ind(bcs
, ap
, 0);
1680 /* remove it from the list of listening apps */
1681 spin_lock_irqsave(&bcs
->aplock
, flags
);
1682 if (bcs
->ap
== ap
) {
1683 bcs
->ap
= ap
->bcnext
;
1684 if (bcs
->ap
== NULL
) {
1685 /* last one: stop ev-layer hupD notifications */
1686 bcs
->apconnstate
= APCONN_NONE
;
1687 bcs
->chstate
&= ~CHS_NOTIFY_LL
;
1689 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1692 for (oap
= bcs
->ap
; oap
!= NULL
; oap
= oap
->bcnext
) {
1693 if (oap
->bcnext
== ap
) {
1694 oap
->bcnext
= oap
->bcnext
->bcnext
;
1695 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1699 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1700 dev_err(cs
->dev
, "%s: application %u not found\n",
1704 default: /* Reject */
1705 /* drop all competing applications, keep only this one */
1706 spin_lock_irqsave(&bcs
->aplock
, flags
);
1707 while (bcs
->ap
!= NULL
) {
1709 bcs
->ap
= oap
->bcnext
;
1711 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1712 send_disconnect_ind(bcs
, oap
,
1713 CapiCallGivenToOtherApplication
);
1714 spin_lock_irqsave(&bcs
->aplock
, flags
);
1719 spin_unlock_irqrestore(&bcs
->aplock
, flags
);
1721 /* reject call - will trigger DISCONNECT_IND for this app */
1722 dev_info(cs
->dev
, "%s: Reject=%x\n",
1723 "CONNECT_RESP", cmsg
->Reject
);
1724 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1725 EV_HUP
, NULL
, 0, NULL
))
1727 gigaset_schedule_event(cs
);
1733 * process CONNECT_B3_REQ message
1734 * build NCCI and emit CONNECT_B3_CONF reply
1736 static void do_connect_b3_req(struct gigaset_capi_ctr
*iif
,
1737 struct gigaset_capi_appl
*ap
,
1738 struct sk_buff
*skb
)
1740 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1741 _cmsg
*cmsg
= &iif
->acmsg
;
1742 struct bc_state
*bcs
;
1745 /* decode message */
1746 capi_message2cmsg(cmsg
, skb
->data
);
1747 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1749 /* extract and check channel number from PLCI */
1750 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1751 if (!channel
|| channel
> cs
->channels
) {
1752 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1753 "CONNECT_B3_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1754 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1757 bcs
= &cs
->bcs
[channel
-1];
1759 /* mark logical connection active */
1760 bcs
->apconnstate
= APCONN_ACTIVE
;
1762 /* build NCCI: always 1 (one B3 connection only) */
1763 cmsg
->adr
.adrNCCI
|= 1 << 16;
1765 /* NCPI parameter: not applicable for B3 Transparent */
1766 ignore_cstruct_param(cs
, cmsg
->NCPI
, "CONNECT_B3_REQ", "NCPI");
1767 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1768 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1772 * process CONNECT_B3_RESP message
1773 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1774 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1775 * The emitted message is always shorter than the received one,
1776 * allowing to reuse the skb.
1778 static void do_connect_b3_resp(struct gigaset_capi_ctr
*iif
,
1779 struct gigaset_capi_appl
*ap
,
1780 struct sk_buff
*skb
)
1782 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1783 _cmsg
*cmsg
= &iif
->acmsg
;
1784 struct bc_state
*bcs
;
1786 unsigned int msgsize
;
1789 /* decode message */
1790 capi_message2cmsg(cmsg
, skb
->data
);
1791 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1793 /* extract and check channel number and NCCI */
1794 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1795 if (!channel
|| channel
> cs
->channels
||
1796 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1797 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1798 "CONNECT_B3_RESP", "NCCI", cmsg
->adr
.adrNCCI
);
1799 dev_kfree_skb_any(skb
);
1802 bcs
= &cs
->bcs
[channel
-1];
1805 /* Reject: clear B3 connect received flag */
1806 bcs
->apconnstate
= APCONN_SETUP
;
1808 /* trigger hangup, causing eventual DISCONNECT_IND */
1809 if (!gigaset_add_event(cs
, &bcs
->at_state
,
1810 EV_HUP
, NULL
, 0, NULL
)) {
1811 dev_kfree_skb_any(skb
);
1814 gigaset_schedule_event(cs
);
1816 /* emit DISCONNECT_B3_IND */
1817 command
= CAPI_DISCONNECT_B3
;
1818 msgsize
= CAPI_DISCONNECT_B3_IND_BASELEN
;
1821 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1822 * we only send CONNECT_B3_IND if the B channel is up
1824 command
= CAPI_CONNECT_B3_ACTIVE
;
1825 msgsize
= CAPI_CONNECT_B3_ACTIVE_IND_BASELEN
;
1827 capi_cmsg_header(cmsg
, ap
->id
, command
, CAPI_IND
,
1828 ap
->nextMessageNumber
++, cmsg
->adr
.adrNCCI
);
1829 __skb_trim(skb
, msgsize
);
1830 capi_cmsg2message(cmsg
, skb
->data
);
1831 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1832 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1836 * process DISCONNECT_REQ message
1837 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1838 * emit DISCONNECT_CONF reply
1840 static void do_disconnect_req(struct gigaset_capi_ctr
*iif
,
1841 struct gigaset_capi_appl
*ap
,
1842 struct sk_buff
*skb
)
1844 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1845 _cmsg
*cmsg
= &iif
->acmsg
;
1846 struct bc_state
*bcs
;
1848 struct sk_buff
*b3skb
;
1851 /* decode message */
1852 capi_message2cmsg(cmsg
, skb
->data
);
1853 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1855 /* extract and check channel number from PLCI */
1856 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1857 if (!channel
|| channel
> cs
->channels
) {
1858 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1859 "DISCONNECT_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1860 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1863 bcs
= cs
->bcs
+ channel
- 1;
1865 /* ToDo: process parameter: Additional info */
1866 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1867 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1868 "DISCONNECT_REQ", "B Channel Information");
1869 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1870 "DISCONNECT_REQ", "Keypad Facility");
1871 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1872 "DISCONNECT_REQ", "User-User Data");
1873 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1874 "DISCONNECT_REQ", "Facility Data Array");
1877 /* skip if DISCONNECT_IND already sent */
1878 if (!bcs
->apconnstate
)
1881 /* check for active logical connection */
1882 if (bcs
->apconnstate
>= APCONN_ACTIVE
) {
1884 * emit DISCONNECT_B3_IND with cause 0x3301
1885 * use separate cmsg structure, as the content of iif->acmsg
1886 * is still needed for creating the _CONF message
1888 b3cmsg
= kmalloc(sizeof(*b3cmsg
), GFP_KERNEL
);
1890 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1891 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1894 capi_cmsg_header(b3cmsg
, ap
->id
, CAPI_DISCONNECT_B3
, CAPI_IND
,
1895 ap
->nextMessageNumber
++,
1896 cmsg
->adr
.adrPLCI
| (1 << 16));
1897 b3cmsg
->Reason_B3
= CapiProtocolErrorLayer1
;
1898 b3skb
= alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN
, GFP_KERNEL
);
1899 if (b3skb
== NULL
) {
1900 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1901 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1904 capi_cmsg2message(b3cmsg
,
1905 __skb_put(b3skb
, CAPI_DISCONNECT_B3_IND_BASELEN
));
1907 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, b3skb
);
1910 /* trigger hangup, causing eventual DISCONNECT_IND */
1911 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_HUP
, NULL
, 0, NULL
)) {
1912 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1915 gigaset_schedule_event(cs
);
1918 send_conf(iif
, ap
, skb
, CapiSuccess
);
1922 * process DISCONNECT_B3_REQ message
1923 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1925 static void do_disconnect_b3_req(struct gigaset_capi_ctr
*iif
,
1926 struct gigaset_capi_appl
*ap
,
1927 struct sk_buff
*skb
)
1929 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1930 _cmsg
*cmsg
= &iif
->acmsg
;
1931 struct bc_state
*bcs
;
1934 /* decode message */
1935 capi_message2cmsg(cmsg
, skb
->data
);
1936 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1938 /* extract and check channel number and NCCI */
1939 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1940 if (!channel
|| channel
> cs
->channels
||
1941 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1942 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1943 "DISCONNECT_B3_REQ", "NCCI", cmsg
->adr
.adrNCCI
);
1944 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1947 bcs
= &cs
->bcs
[channel
-1];
1949 /* reject if logical connection not active */
1950 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
1951 send_conf(iif
, ap
, skb
,
1952 CapiMessageNotSupportedInCurrentState
);
1956 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1957 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_HUP
, NULL
, 0, NULL
)) {
1958 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1961 gigaset_schedule_event(cs
);
1963 /* NCPI parameter: not applicable for B3 Transparent */
1964 ignore_cstruct_param(cs
, cmsg
->NCPI
,
1965 "DISCONNECT_B3_REQ", "NCPI");
1966 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1967 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1971 * process DATA_B3_REQ message
1973 static void do_data_b3_req(struct gigaset_capi_ctr
*iif
,
1974 struct gigaset_capi_appl
*ap
,
1975 struct sk_buff
*skb
)
1977 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1978 struct bc_state
*bcs
;
1979 int channel
= CAPIMSG_PLCI_PART(skb
->data
);
1980 u16 ncci
= CAPIMSG_NCCI_PART(skb
->data
);
1981 u16 msglen
= CAPIMSG_LEN(skb
->data
);
1982 u16 datalen
= CAPIMSG_DATALEN(skb
->data
);
1983 u16 flags
= CAPIMSG_FLAGS(skb
->data
);
1984 u16 msgid
= CAPIMSG_MSGID(skb
->data
);
1985 u16 handle
= CAPIMSG_HANDLE_REQ(skb
->data
);
1987 /* frequent message, avoid _cmsg overhead */
1988 dump_rawmsg(DEBUG_MCMD
, __func__
, skb
->data
);
1990 /* check parameters */
1991 if (channel
== 0 || channel
> cs
->channels
|| ncci
!= 1) {
1992 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1993 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb
->data
));
1994 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1997 bcs
= &cs
->bcs
[channel
-1];
1998 if (msglen
!= CAPI_DATA_B3_REQ_LEN
&& msglen
!= CAPI_DATA_B3_REQ_LEN64
)
1999 dev_notice(cs
->dev
, "%s: unexpected length %d\n",
2000 "DATA_B3_REQ", msglen
);
2001 if (msglen
+ datalen
!= skb
->len
)
2002 dev_notice(cs
->dev
, "%s: length mismatch (%d+%d!=%d)\n",
2003 "DATA_B3_REQ", msglen
, datalen
, skb
->len
);
2004 if (msglen
+ datalen
> skb
->len
) {
2005 /* message too short for announced data length */
2006 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
); /* ? */
2009 if (flags
& CAPI_FLAGS_RESERVED
) {
2010 dev_notice(cs
->dev
, "%s: reserved flags set (%x)\n",
2011 "DATA_B3_REQ", flags
);
2012 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
2016 /* reject if logical connection not active */
2017 if (bcs
->apconnstate
< APCONN_ACTIVE
) {
2018 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
2022 /* pull CAPI message into link layer header */
2023 skb_reset_mac_header(skb
);
2024 skb
->mac_len
= msglen
;
2025 skb_pull(skb
, msglen
);
2027 /* pass to device-specific module */
2028 if (cs
->ops
->send_skb(bcs
, skb
) < 0) {
2029 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
2034 * DATA_B3_CONF will be sent by gigaset_skb_sent() only if "delivery
2035 * confirmation" bit is set; otherwise we have to send it now
2037 if (!(flags
& CAPI_FLAGS_DELIVERY_CONFIRMATION
))
2038 send_data_b3_conf(cs
, &iif
->ctr
, ap
->id
, msgid
, channel
, handle
,
2039 flags
? CapiFlagsNotSupportedByProtocol
2044 * process RESET_B3_REQ message
2045 * just always reply "not supported by current protocol"
2047 static void do_reset_b3_req(struct gigaset_capi_ctr
*iif
,
2048 struct gigaset_capi_appl
*ap
,
2049 struct sk_buff
*skb
)
2051 /* decode message */
2052 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2053 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2054 send_conf(iif
, ap
, skb
,
2055 CapiResetProcedureNotSupportedByCurrentProtocol
);
2059 * dump unsupported/ignored messages at most twice per minute,
2060 * some apps send those very frequently
2062 static unsigned long ignored_msg_dump_time
;
2065 * unsupported CAPI message handler
2067 static void do_unsupported(struct gigaset_capi_ctr
*iif
,
2068 struct gigaset_capi_appl
*ap
,
2069 struct sk_buff
*skb
)
2071 /* decode message */
2072 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2073 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000))
2074 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2075 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
2079 * CAPI message handler: no-op
2081 static void do_nothing(struct gigaset_capi_ctr
*iif
,
2082 struct gigaset_capi_appl
*ap
,
2083 struct sk_buff
*skb
)
2085 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000)) {
2086 /* decode message */
2087 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
2088 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
2090 dev_kfree_skb_any(skb
);
2093 static void do_data_b3_resp(struct gigaset_capi_ctr
*iif
,
2094 struct gigaset_capi_appl
*ap
,
2095 struct sk_buff
*skb
)
2097 dump_rawmsg(DEBUG_MCMD
, __func__
, skb
->data
);
2098 dev_kfree_skb_any(skb
);
2101 /* table of outgoing CAPI message handlers with lookup function */
2102 typedef void (*capi_send_handler_t
)(struct gigaset_capi_ctr
*,
2103 struct gigaset_capi_appl
*,
2108 capi_send_handler_t handler
;
2109 } capi_send_handler_table
[] = {
2110 /* most frequent messages first for faster lookup */
2111 { CAPI_DATA_B3_REQ
, do_data_b3_req
},
2112 { CAPI_DATA_B3_RESP
, do_data_b3_resp
},
2114 { CAPI_ALERT_REQ
, do_alert_req
},
2115 { CAPI_CONNECT_ACTIVE_RESP
, do_nothing
},
2116 { CAPI_CONNECT_B3_ACTIVE_RESP
, do_nothing
},
2117 { CAPI_CONNECT_B3_REQ
, do_connect_b3_req
},
2118 { CAPI_CONNECT_B3_RESP
, do_connect_b3_resp
},
2119 { CAPI_CONNECT_B3_T90_ACTIVE_RESP
, do_nothing
},
2120 { CAPI_CONNECT_REQ
, do_connect_req
},
2121 { CAPI_CONNECT_RESP
, do_connect_resp
},
2122 { CAPI_DISCONNECT_B3_REQ
, do_disconnect_b3_req
},
2123 { CAPI_DISCONNECT_B3_RESP
, do_nothing
},
2124 { CAPI_DISCONNECT_REQ
, do_disconnect_req
},
2125 { CAPI_DISCONNECT_RESP
, do_nothing
},
2126 { CAPI_FACILITY_REQ
, do_facility_req
},
2127 { CAPI_FACILITY_RESP
, do_nothing
},
2128 { CAPI_LISTEN_REQ
, do_listen_req
},
2129 { CAPI_SELECT_B_PROTOCOL_REQ
, do_unsupported
},
2130 { CAPI_RESET_B3_REQ
, do_reset_b3_req
},
2131 { CAPI_RESET_B3_RESP
, do_nothing
},
2134 * ToDo: support overlap sending (requires ev-layer state
2135 * machine extension to generate additional ATD commands)
2137 { CAPI_INFO_REQ
, do_unsupported
},
2138 { CAPI_INFO_RESP
, do_nothing
},
2141 * ToDo: what's the proper response for these?
2143 { CAPI_MANUFACTURER_REQ
, do_nothing
},
2144 { CAPI_MANUFACTURER_RESP
, do_nothing
},
2147 /* look up handler */
2148 static inline capi_send_handler_t
lookup_capi_send_handler(const u16 cmd
)
2152 for (i
= 0; i
< ARRAY_SIZE(capi_send_handler_table
); i
++)
2153 if (capi_send_handler_table
[i
].cmd
== cmd
)
2154 return capi_send_handler_table
[i
].handler
;
2160 * gigaset_send_message() - accept a CAPI message from an application
2161 * @ctr: controller descriptor structure.
2162 * @skb: CAPI message.
2164 * Return value: CAPI error code
2165 * Note: capidrv (and probably others, too) only uses the return value to
2166 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
2168 static u16
gigaset_send_message(struct capi_ctr
*ctr
, struct sk_buff
*skb
)
2170 struct gigaset_capi_ctr
*iif
2171 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
2172 struct cardstate
*cs
= ctr
->driverdata
;
2173 struct gigaset_capi_appl
*ap
;
2174 capi_send_handler_t handler
;
2176 /* can only handle linear sk_buffs */
2177 if (skb_linearize(skb
) < 0) {
2178 dev_warn(cs
->dev
, "%s: skb_linearize failed\n", __func__
);
2179 return CAPI_MSGOSRESOURCEERR
;
2182 /* retrieve application data structure */
2183 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2185 dev_notice(cs
->dev
, "%s: application %u not registered\n",
2186 __func__
, CAPIMSG_APPID(skb
->data
));
2187 return CAPI_ILLAPPNR
;
2190 /* look up command */
2191 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2193 /* unknown/unsupported message type */
2194 if (printk_ratelimit())
2195 dev_notice(cs
->dev
, "%s: unsupported message %u\n",
2196 __func__
, CAPIMSG_CMD(skb
->data
));
2197 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL
;
2201 if (atomic_add_return(1, &iif
->sendqlen
) > 1) {
2202 /* queue behind other messages */
2203 skb_queue_tail(&iif
->sendqueue
, skb
);
2204 return CAPI_NOERROR
;
2207 /* process message */
2208 handler(iif
, ap
, skb
);
2210 /* process other messages arrived in the meantime */
2211 while (atomic_sub_return(1, &iif
->sendqlen
) > 0) {
2212 skb
= skb_dequeue(&iif
->sendqueue
);
2214 /* should never happen */
2215 dev_err(cs
->dev
, "%s: send queue empty\n", __func__
);
2218 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2220 /* could that happen? */
2221 dev_warn(cs
->dev
, "%s: application %u vanished\n",
2222 __func__
, CAPIMSG_APPID(skb
->data
));
2225 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2227 /* should never happen */
2228 dev_err(cs
->dev
, "%s: handler %x vanished\n",
2229 __func__
, CAPIMSG_CMD(skb
->data
));
2232 handler(iif
, ap
, skb
);
2235 return CAPI_NOERROR
;
2239 * gigaset_procinfo() - build single line description for controller
2240 * @ctr: controller descriptor structure.
2242 * Return value: pointer to generated string (null terminated)
2244 static char *gigaset_procinfo(struct capi_ctr
*ctr
)
2246 return ctr
->name
; /* ToDo: more? */
2249 static int gigaset_proc_show(struct seq_file
*m
, void *v
)
2251 struct capi_ctr
*ctr
= m
->private;
2252 struct cardstate
*cs
= ctr
->driverdata
;
2256 seq_printf(m
, "%-16s %s\n", "name", ctr
->name
);
2257 seq_printf(m
, "%-16s %s %s\n", "dev",
2258 dev_driver_string(cs
->dev
), dev_name(cs
->dev
));
2259 seq_printf(m
, "%-16s %d\n", "id", cs
->myid
);
2261 seq_printf(m
, "%-16s %d.%d.%d.%d\n", "firmware",
2262 cs
->fwver
[0], cs
->fwver
[1], cs
->fwver
[2], cs
->fwver
[3]);
2263 seq_printf(m
, "%-16s %d\n", "channels", cs
->channels
);
2264 seq_printf(m
, "%-16s %s\n", "onechannel", cs
->onechannel
? "yes" : "no");
2282 seq_printf(m
, "%-16s %s\n", "mode", s
);
2284 switch (cs
->mstate
) {
2285 case MS_UNINITIALIZED
:
2286 s
= "uninitialized";
2306 seq_printf(m
, "%-16s %s\n", "mstate", s
);
2308 seq_printf(m
, "%-16s %s\n", "running", cs
->running
? "yes" : "no");
2309 seq_printf(m
, "%-16s %s\n", "connected", cs
->connected
? "yes" : "no");
2310 seq_printf(m
, "%-16s %s\n", "isdn_up", cs
->isdn_up
? "yes" : "no");
2311 seq_printf(m
, "%-16s %s\n", "cidmode", cs
->cidmode
? "yes" : "no");
2313 for (i
= 0; i
< cs
->channels
; i
++) {
2314 seq_printf(m
, "[%d]%-13s %d\n", i
, "corrupted",
2315 cs
->bcs
[i
].corrupted
);
2316 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_down",
2317 cs
->bcs
[i
].trans_down
);
2318 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_up",
2319 cs
->bcs
[i
].trans_up
);
2320 seq_printf(m
, "[%d]%-13s %d\n", i
, "chstate",
2321 cs
->bcs
[i
].chstate
);
2322 switch (cs
->bcs
[i
].proto2
) {
2335 seq_printf(m
, "[%d]%-13s %s\n", i
, "proto2", s
);
2340 static int gigaset_proc_open(struct inode
*inode
, struct file
*file
)
2342 return single_open(file
, gigaset_proc_show
, PDE(inode
)->data
);
2345 static const struct file_operations gigaset_proc_fops
= {
2346 .owner
= THIS_MODULE
,
2347 .open
= gigaset_proc_open
,
2349 .llseek
= seq_lseek
,
2350 .release
= single_release
,
2354 * gigaset_isdn_regdev() - register device to LL
2355 * @cs: device descriptor structure.
2356 * @isdnid: device name.
2358 * Return value: 1 for success, 0 for failure
2360 int gigaset_isdn_regdev(struct cardstate
*cs
, const char *isdnid
)
2362 struct gigaset_capi_ctr
*iif
;
2365 iif
= kmalloc(sizeof(*iif
), GFP_KERNEL
);
2367 pr_err("%s: out of memory\n", __func__
);
2371 /* prepare controller structure */
2372 iif
->ctr
.owner
= THIS_MODULE
;
2373 iif
->ctr
.driverdata
= cs
;
2374 strncpy(iif
->ctr
.name
, isdnid
, sizeof(iif
->ctr
.name
));
2375 iif
->ctr
.driver_name
= "gigaset";
2376 iif
->ctr
.load_firmware
= NULL
;
2377 iif
->ctr
.reset_ctr
= NULL
;
2378 iif
->ctr
.register_appl
= gigaset_register_appl
;
2379 iif
->ctr
.release_appl
= gigaset_release_appl
;
2380 iif
->ctr
.send_message
= gigaset_send_message
;
2381 iif
->ctr
.procinfo
= gigaset_procinfo
;
2382 iif
->ctr
.proc_fops
= &gigaset_proc_fops
;
2383 INIT_LIST_HEAD(&iif
->appls
);
2384 skb_queue_head_init(&iif
->sendqueue
);
2385 atomic_set(&iif
->sendqlen
, 0);
2387 /* register controller with CAPI */
2388 rc
= attach_capi_ctr(&iif
->ctr
);
2390 pr_err("attach_capi_ctr failed (%d)\n", rc
);
2396 cs
->hw_hdr_len
= CAPI_DATA_B3_REQ_LEN
;
2401 * gigaset_isdn_unregdev() - unregister device from LL
2402 * @cs: device descriptor structure.
2404 void gigaset_isdn_unregdev(struct cardstate
*cs
)
2406 struct gigaset_capi_ctr
*iif
= cs
->iif
;
2408 detach_capi_ctr(&iif
->ctr
);
2413 static struct capi_driver capi_driver_gigaset
= {
2419 * gigaset_isdn_regdrv() - register driver to LL
2421 void gigaset_isdn_regdrv(void)
2423 pr_info("Kernel CAPI interface\n");
2424 register_capi_driver(&capi_driver_gigaset
);
2428 * gigaset_isdn_unregdrv() - unregister driver from LL
2430 void gigaset_isdn_unregdrv(void)
2432 unregister_capi_driver(&capi_driver_gigaset
);