2 * Kernel CAPI interface for the Gigaset driver
4 * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
6 * =====================================================================
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 * =====================================================================
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
17 #include <linux/isdn/capilli.h>
18 #include <linux/isdn/capicmd.h>
19 #include <linux/isdn/capiutil.h>
21 /* missing from kernelcapi.h */
22 #define CapiNcpiNotSupportedByProtocol 0x0001
23 #define CapiFlagsNotSupportedByProtocol 0x0002
24 #define CapiAlertAlreadySent 0x0003
25 #define CapiFacilitySpecificFunctionNotSupported 0x3011
27 /* missing from capicmd.h */
28 #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
29 #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
30 #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
31 #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
32 #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
33 #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
34 #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
35 #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
36 #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
37 /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
38 #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
40 #define CAPI_FACILITY_HANDSET 0x0000
41 #define CAPI_FACILITY_DTMF 0x0001
42 #define CAPI_FACILITY_V42BIS 0x0002
43 #define CAPI_FACILITY_SUPPSVC 0x0003
44 #define CAPI_FACILITY_WAKEUP 0x0004
45 #define CAPI_FACILITY_LI 0x0005
47 #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
49 /* missing from capiutil.h */
50 #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
51 #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
52 #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
53 #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
54 #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
55 #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
56 #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
57 #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
59 /* parameters with differing location in DATA_B3_CONF/_RESP: */
60 #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
61 #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
63 /* Flags (DATA_B3_REQ/_IND) */
64 #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
65 #define CAPI_FLAGS_RESERVED (~0x1f)
68 #define MAX_BC_OCTETS 11
69 #define MAX_HLC_OCTETS 3
70 #define MAX_NUMBER_DIGITS 20
71 #define MAX_FMT_IE_LEN 20
73 /* values for gigaset_capi_appl.connected */
74 #define APCONN_NONE 0 /* inactive/listening */
75 #define APCONN_SETUP 1 /* connecting */
76 #define APCONN_ACTIVE 2 /* B channel up */
78 /* registered application data structure */
79 struct gigaset_capi_appl
{
80 struct list_head ctrlist
;
81 struct gigaset_capi_appl
*bcnext
;
83 struct capi_register_params rp
;
84 u16 nextMessageNumber
;
90 /* CAPI specific controller data structure */
91 struct gigaset_capi_ctr
{
93 struct list_head appls
;
94 struct sk_buff_head sendqueue
;
96 /* two _cmsg structures possibly used concurrently: */
97 _cmsg hcmsg
; /* for message composition triggered from hardware */
98 _cmsg acmsg
; /* for dissection of messages sent from application */
99 u8 bc_buf
[MAX_BC_OCTETS
+1];
100 u8 hlc_buf
[MAX_HLC_OCTETS
+1];
101 u8 cgpty_buf
[MAX_NUMBER_DIGITS
+3];
102 u8 cdpty_buf
[MAX_NUMBER_DIGITS
+2];
105 /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
110 [1] = { "8090A3", NULL
},
112 [2] = { "8890", NULL
},
113 /* Unrestricted digital information */
114 [3] = { "8990", NULL
},
115 /* Restricted digital information */
116 [4] = { "9090A3", NULL
},
117 /* 3,1 kHz audio (A-law) */
118 [5] = { "9190", NULL
},
120 [6] = { "9890", NULL
},
122 [7] = { "88C0C6E6", NULL
},
124 [8] = { "8890218F", NULL
},
125 /* 56 kbit/s rate adaptation */
126 [9] = { "9190A5", NULL
},
127 /* Unrestricted digital information with tones/announcements */
128 [16] = { "8090A3", "9181" },
130 [17] = { "9090A3", "9184" },
131 /* Group 2/3 facsimile */
132 [18] = { "8890", "91A1" },
133 /* Group 4 facsimile Class 1 */
134 [19] = { "8890", "91A4" },
135 /* Teletex service basic and mixed mode
136 and Group 4 facsimile service Classes II and III */
137 [20] = { "8890", "91A8" },
138 /* Teletex service basic and processable mode */
139 [21] = { "8890", "91B1" },
140 /* Teletex service basic mode */
141 [22] = { "8890", "91B2" },
142 /* International interworking for Videotex */
143 [23] = { "8890", "91B5" },
145 [24] = { "8890", "91B8" },
146 /* Message Handling Systems in accordance with X.400 */
147 [25] = { "8890", "91C1" },
148 /* OSI application in accordance with X.200 */
149 [26] = { "9190A5", "9181" },
150 /* 7 kHz telephony */
151 [27] = { "9190A5", "916001" },
152 /* Video telephony, first connection */
153 [28] = { "8890", "916002" },
154 /* Video telephony, second connection */
163 * emit unsupported parameter warning
165 static inline void ignore_cstruct_param(struct cardstate
*cs
, _cstruct param
,
166 char *msgname
, char *paramname
)
169 dev_warn(cs
->dev
, "%s: ignoring unsupported parameter: %s\n",
174 * convert hex to binary
176 static inline u8
hex2bin(char c
)
178 int result
= c
& 0x0f;
185 * convert an IE from Gigaset hex string to ETSI binary representation
186 * including length byte
187 * return value: result length, -1 on error
189 static int encode_ie(char *in
, u8
*out
, int maxlen
)
193 if (!isxdigit(in
[0]) || !isxdigit(in
[1]) || l
>= maxlen
)
195 out
[++l
] = (hex2bin(in
[0]) << 4) + hex2bin(in
[1]);
203 * convert an IE from ETSI binary representation including length byte
204 * to Gigaset hex string
206 static void decode_ie(u8
*in
, char *out
)
210 /* ToDo: conversion to upper case necessary? */
211 *out
++ = toupper(hex_asc_hi(*++in
));
212 *out
++ = toupper(hex_asc_lo(*in
));
217 * retrieve application data structure for an application ID
219 static inline struct gigaset_capi_appl
*
220 get_appl(struct gigaset_capi_ctr
*iif
, u16 appl
)
222 struct gigaset_capi_appl
*ap
;
224 list_for_each_entry(ap
, &iif
->appls
, ctrlist
)
231 * dump CAPI message to kernel messages for debugging
233 static inline void dump_cmsg(enum debuglevel level
, const char *tag
, _cmsg
*p
)
235 #ifdef CONFIG_GIGASET_DEBUG
238 if (!(gigaset_debuglevel
& level
))
241 cdb
= capi_cmsg2str(p
);
243 gig_dbg(level
, "%s: [%d] %s", tag
, p
->ApplId
, cdb
->buf
);
246 gig_dbg(level
, "%s: [%d] %s", tag
, p
->ApplId
,
247 capi_cmd2str(p
->Command
, p
->Subcommand
));
252 static inline void dump_rawmsg(enum debuglevel level
, const char *tag
,
255 #ifdef CONFIG_GIGASET_DEBUG
259 if (!(gigaset_debuglevel
& level
))
262 l
= CAPIMSG_LEN(data
);
264 gig_dbg(level
, "%s: ??? LEN=%04d", tag
, l
);
267 gig_dbg(level
, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
268 tag
, CAPIMSG_COMMAND(data
), CAPIMSG_SUBCOMMAND(data
),
269 CAPIMSG_APPID(data
), CAPIMSG_MSGID(data
), l
,
270 CAPIMSG_CONTROL(data
));
272 dbgline
= kmalloc(3*l
, GFP_ATOMIC
);
275 for (i
= 0; i
< l
; i
++) {
276 dbgline
[3*i
] = hex_asc_hi(data
[12+i
]);
277 dbgline
[3*i
+1] = hex_asc_lo(data
[12+i
]);
278 dbgline
[3*i
+2] = ' ';
280 dbgline
[3*l
-1] = '\0';
281 gig_dbg(level
, " %s", dbgline
);
283 if (CAPIMSG_COMMAND(data
) == CAPI_DATA_B3
&&
284 (CAPIMSG_SUBCOMMAND(data
) == CAPI_REQ
||
285 CAPIMSG_SUBCOMMAND(data
) == CAPI_IND
) &&
286 CAPIMSG_DATALEN(data
) > 0) {
287 l
= CAPIMSG_DATALEN(data
);
288 dbgline
= kmalloc(3*l
, GFP_ATOMIC
);
291 data
+= CAPIMSG_LEN(data
);
292 for (i
= 0; i
< l
; i
++) {
293 dbgline
[3*i
] = hex_asc_hi(data
[i
]);
294 dbgline
[3*i
+1] = hex_asc_lo(data
[i
]);
295 dbgline
[3*i
+2] = ' ';
297 dbgline
[3*l
-1] = '\0';
298 gig_dbg(level
, " %s", dbgline
);
305 * format CAPI IE as string
308 static const char *format_ie(const char *ie
)
310 static char result
[3*MAX_FMT_IE_LEN
];
318 if (count
> MAX_FMT_IE_LEN
)
319 count
= MAX_FMT_IE_LEN
-1;
321 *pout
++ = hex_asc_hi(*++ie
);
322 *pout
++ = hex_asc_lo(*ie
);
325 if (len
> MAX_FMT_IE_LEN
) {
336 * driver interface functions
337 * ==========================
341 * gigaset_skb_sent() - acknowledge transmission of outgoing skb
342 * @bcs: B channel descriptor structure.
345 * Called by hardware module {bas,ser,usb}_gigaset when the data in a
346 * skb has been successfully sent, for signalling completion to the LL.
348 void gigaset_skb_sent(struct bc_state
*bcs
, struct sk_buff
*dskb
)
350 struct cardstate
*cs
= bcs
->cs
;
351 struct gigaset_capi_ctr
*iif
= cs
->iif
;
352 struct gigaset_capi_appl
*ap
= bcs
->ap
;
353 unsigned char *req
= skb_mac_header(dskb
);
354 struct sk_buff
*cskb
;
357 /* update statistics */
361 dev_err(cs
->dev
, "%s: no application\n", __func__
);
365 /* don't send further B3 messages if disconnected */
366 if (ap
->connected
< APCONN_ACTIVE
) {
367 gig_dbg(DEBUG_LLDATA
, "disconnected, discarding ack");
371 /* ToDo: honor unset "delivery confirmation" bit */
372 flags
= CAPIMSG_FLAGS(req
);
374 /* build DATA_B3_CONF message */
375 cskb
= alloc_skb(CAPI_DATA_B3_CONF_LEN
, GFP_ATOMIC
);
377 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
380 /* frequent message, avoid _cmsg overhead */
381 CAPIMSG_SETLEN(cskb
->data
, CAPI_DATA_B3_CONF_LEN
);
382 CAPIMSG_SETAPPID(cskb
->data
, ap
->id
);
383 CAPIMSG_SETCOMMAND(cskb
->data
, CAPI_DATA_B3
);
384 CAPIMSG_SETSUBCOMMAND(cskb
->data
, CAPI_CONF
);
385 CAPIMSG_SETMSGID(cskb
->data
, CAPIMSG_MSGID(req
));
386 CAPIMSG_SETCONTROLLER(cskb
->data
, iif
->ctr
.cnr
);
387 CAPIMSG_SETPLCI_PART(cskb
->data
, bcs
->channel
+ 1);
388 CAPIMSG_SETNCCI_PART(cskb
->data
, 1);
389 CAPIMSG_SETHANDLE_CONF(cskb
->data
, CAPIMSG_HANDLE_REQ(req
));
390 if (flags
& ~CAPI_FLAGS_DELIVERY_CONFIRMATION
)
391 CAPIMSG_SETINFO_CONF(cskb
->data
,
392 CapiFlagsNotSupportedByProtocol
);
394 CAPIMSG_SETINFO_CONF(cskb
->data
, CAPI_NOERROR
);
397 dump_rawmsg(DEBUG_LLDATA
, "DATA_B3_CONF", cskb
->data
);
398 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, cskb
);
400 EXPORT_SYMBOL_GPL(gigaset_skb_sent
);
403 * gigaset_skb_rcvd() - pass received skb to LL
404 * @bcs: B channel descriptor structure.
405 * @skb: received data.
407 * Called by hardware module {bas,ser,usb}_gigaset when user data has
408 * been successfully received, for passing to the LL.
409 * Warning: skb must not be accessed anymore!
411 void gigaset_skb_rcvd(struct bc_state
*bcs
, struct sk_buff
*skb
)
413 struct cardstate
*cs
= bcs
->cs
;
414 struct gigaset_capi_ctr
*iif
= cs
->iif
;
415 struct gigaset_capi_appl
*ap
= bcs
->ap
;
418 /* update statistics */
422 dev_err(cs
->dev
, "%s: no application\n", __func__
);
426 /* don't send further B3 messages if disconnected */
427 if (ap
->connected
< APCONN_ACTIVE
) {
428 gig_dbg(DEBUG_LLDATA
, "disconnected, discarding data");
429 dev_kfree_skb_any(skb
);
434 * prepend DATA_B3_IND message to payload
435 * Parameters: NCCI = 1, all others 0/unused
436 * frequent message, avoid _cmsg overhead
438 skb_push(skb
, CAPI_DATA_B3_REQ_LEN
);
439 CAPIMSG_SETLEN(skb
->data
, CAPI_DATA_B3_REQ_LEN
);
440 CAPIMSG_SETAPPID(skb
->data
, ap
->id
);
441 CAPIMSG_SETCOMMAND(skb
->data
, CAPI_DATA_B3
);
442 CAPIMSG_SETSUBCOMMAND(skb
->data
, CAPI_IND
);
443 CAPIMSG_SETMSGID(skb
->data
, ap
->nextMessageNumber
++);
444 CAPIMSG_SETCONTROLLER(skb
->data
, iif
->ctr
.cnr
);
445 CAPIMSG_SETPLCI_PART(skb
->data
, bcs
->channel
+ 1);
446 CAPIMSG_SETNCCI_PART(skb
->data
, 1);
447 /* Data parameter not used */
448 CAPIMSG_SETDATALEN(skb
->data
, len
);
449 /* Data handle parameter not used */
450 CAPIMSG_SETFLAGS(skb
->data
, 0);
451 /* Data64 parameter not present */
454 dump_rawmsg(DEBUG_LLDATA
, "DATA_B3_IND", skb
->data
);
455 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
457 EXPORT_SYMBOL_GPL(gigaset_skb_rcvd
);
460 * gigaset_isdn_rcv_err() - signal receive error
461 * @bcs: B channel descriptor structure.
463 * Called by hardware module {bas,ser,usb}_gigaset when a receive error
464 * has occurred, for signalling to the LL.
466 void gigaset_isdn_rcv_err(struct bc_state
*bcs
)
468 /* if currently ignoring packets, just count down */
474 /* update statistics */
477 /* ToDo: signal error -> LL */
479 EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err
);
482 * gigaset_isdn_icall() - signal incoming call
483 * @at_state: connection state structure.
485 * Called by main module at tasklet level to notify the LL that an incoming
486 * call has been received. @at_state contains the parameters of the call.
488 * Return value: call disposition (ICALL_*)
490 int gigaset_isdn_icall(struct at_state_t
*at_state
)
492 struct cardstate
*cs
= at_state
->cs
;
493 struct bc_state
*bcs
= at_state
->bcs
;
494 struct gigaset_capi_ctr
*iif
= cs
->iif
;
495 struct gigaset_capi_appl
*ap
;
498 unsigned int msgsize
;
502 * ToDo: signal calls without a free B channel, too
503 * (requires a u8 handle for the at_state structure that can
504 * be stored in the PLCI and used in the CONNECT_RESP message
505 * handler to retrieve it)
510 /* prepare CONNECT_IND message, using B channel number as PLCI */
511 capi_cmsg_header(&iif
->hcmsg
, 0, CAPI_CONNECT
, CAPI_IND
, 0,
512 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
514 /* minimum size, all structs empty */
515 msgsize
= CAPI_CONNECT_IND_BASELEN
;
517 /* Bearer Capability (mandatory) */
518 if (at_state
->str_var
[STR_ZBC
]) {
519 /* pass on BC from Gigaset */
520 if (encode_ie(at_state
->str_var
[STR_ZBC
], iif
->bc_buf
,
521 MAX_BC_OCTETS
) < 0) {
522 dev_warn(cs
->dev
, "RING ignored - bad BC %s\n",
523 at_state
->str_var
[STR_ZBC
]);
527 /* look up corresponding CIP value */
528 iif
->hcmsg
.CIPValue
= 0; /* default if nothing found */
529 for (i
= 0; i
< ARRAY_SIZE(cip2bchlc
); i
++)
530 if (cip2bchlc
[i
].bc
!= NULL
&&
531 cip2bchlc
[i
].hlc
== NULL
&&
532 !strcmp(cip2bchlc
[i
].bc
,
533 at_state
->str_var
[STR_ZBC
])) {
534 iif
->hcmsg
.CIPValue
= i
;
538 /* no BC (internal call): assume CIP 1 (speech, A-law) */
539 iif
->hcmsg
.CIPValue
= 1;
540 encode_ie(cip2bchlc
[1].bc
, iif
->bc_buf
, MAX_BC_OCTETS
);
542 iif
->hcmsg
.BC
= iif
->bc_buf
;
543 msgsize
+= iif
->hcmsg
.BC
[0];
545 /* High Layer Compatibility (optional) */
546 if (at_state
->str_var
[STR_ZHLC
]) {
547 /* pass on HLC from Gigaset */
548 if (encode_ie(at_state
->str_var
[STR_ZHLC
], iif
->hlc_buf
,
549 MAX_HLC_OCTETS
) < 0) {
550 dev_warn(cs
->dev
, "RING ignored - bad HLC %s\n",
551 at_state
->str_var
[STR_ZHLC
]);
554 iif
->hcmsg
.HLC
= iif
->hlc_buf
;
555 msgsize
+= iif
->hcmsg
.HLC
[0];
557 /* look up corresponding CIP value */
558 /* keep BC based CIP value if none found */
559 if (at_state
->str_var
[STR_ZBC
])
560 for (i
= 0; i
< ARRAY_SIZE(cip2bchlc
); i
++)
561 if (cip2bchlc
[i
].hlc
!= NULL
&&
562 !strcmp(cip2bchlc
[i
].hlc
,
563 at_state
->str_var
[STR_ZHLC
]) &&
564 !strcmp(cip2bchlc
[i
].bc
,
565 at_state
->str_var
[STR_ZBC
])) {
566 iif
->hcmsg
.CIPValue
= i
;
571 /* Called Party Number (optional) */
572 if (at_state
->str_var
[STR_ZCPN
]) {
573 i
= strlen(at_state
->str_var
[STR_ZCPN
]);
574 if (i
> MAX_NUMBER_DIGITS
) {
575 dev_warn(cs
->dev
, "RING ignored - bad number %s\n",
576 at_state
->str_var
[STR_ZBC
]);
579 iif
->cdpty_buf
[0] = i
+ 1;
580 iif
->cdpty_buf
[1] = 0x80; /* type / numbering plan unknown */
581 memcpy(iif
->cdpty_buf
+2, at_state
->str_var
[STR_ZCPN
], i
);
582 iif
->hcmsg
.CalledPartyNumber
= iif
->cdpty_buf
;
583 msgsize
+= iif
->hcmsg
.CalledPartyNumber
[0];
586 /* Calling Party Number (optional) */
587 if (at_state
->str_var
[STR_NMBR
]) {
588 i
= strlen(at_state
->str_var
[STR_NMBR
]);
589 if (i
> MAX_NUMBER_DIGITS
) {
590 dev_warn(cs
->dev
, "RING ignored - bad number %s\n",
591 at_state
->str_var
[STR_ZBC
]);
594 iif
->cgpty_buf
[0] = i
+ 2;
595 iif
->cgpty_buf
[1] = 0x00; /* type / numbering plan unknown */
596 iif
->cgpty_buf
[2] = 0x80; /* pres. allowed, not screened */
597 memcpy(iif
->cgpty_buf
+3, at_state
->str_var
[STR_NMBR
], i
);
598 iif
->hcmsg
.CallingPartyNumber
= iif
->cgpty_buf
;
599 msgsize
+= iif
->hcmsg
.CallingPartyNumber
[0];
602 /* remaining parameters (not supported, always left NULL):
603 * - CalledPartySubaddress
604 * - CallingPartySubaddress
606 * - BChannelinformation
609 * - Facilitydataarray
612 gig_dbg(DEBUG_CMD
, "icall: PLCI %x CIP %d BC %s",
613 iif
->hcmsg
.adr
.adrPLCI
, iif
->hcmsg
.CIPValue
,
614 format_ie(iif
->hcmsg
.BC
));
615 gig_dbg(DEBUG_CMD
, "icall: HLC %s",
616 format_ie(iif
->hcmsg
.HLC
));
617 gig_dbg(DEBUG_CMD
, "icall: CgPty %s",
618 format_ie(iif
->hcmsg
.CallingPartyNumber
));
619 gig_dbg(DEBUG_CMD
, "icall: CdPty %s",
620 format_ie(iif
->hcmsg
.CalledPartyNumber
));
622 /* scan application list for matching listeners */
624 actCIPmask
= 1 | (1 << iif
->hcmsg
.CIPValue
);
625 list_for_each_entry(ap
, &iif
->appls
, ctrlist
)
626 if (actCIPmask
& ap
->listenCIPmask
) {
627 /* build CONNECT_IND message for this application */
628 iif
->hcmsg
.ApplId
= ap
->id
;
629 iif
->hcmsg
.Messagenumber
= ap
->nextMessageNumber
++;
631 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
633 dev_err(cs
->dev
, "%s: out of memory\n",
637 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
638 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
640 /* add to listeners on this B channel, update state */
641 ap
->bcnext
= bcs
->ap
;
643 bcs
->chstate
|= CHS_NOTIFY_LL
;
644 ap
->connected
= APCONN_SETUP
;
647 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
651 * Return "accept" if any listeners.
652 * Gigaset will send ALERTING.
653 * There doesn't seem to be a way to avoid this.
655 return bcs
->ap
? ICALL_ACCEPT
: ICALL_IGNORE
;
659 * send a DISCONNECT_IND message to an application
660 * does not sleep, clobbers the controller's hcmsg structure
662 static void send_disconnect_ind(struct bc_state
*bcs
,
663 struct gigaset_capi_appl
*ap
, u16 reason
)
665 struct cardstate
*cs
= bcs
->cs
;
666 struct gigaset_capi_ctr
*iif
= cs
->iif
;
669 if (ap
->connected
== APCONN_NONE
)
672 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_DISCONNECT
, CAPI_IND
,
673 ap
->nextMessageNumber
++,
674 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
675 iif
->hcmsg
.Reason
= reason
;
676 skb
= alloc_skb(CAPI_DISCONNECT_IND_LEN
, GFP_ATOMIC
);
678 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
681 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, CAPI_DISCONNECT_IND_LEN
));
682 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
683 ap
->connected
= APCONN_NONE
;
684 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
688 * send a DISCONNECT_B3_IND message to an application
689 * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
690 * does not sleep, clobbers the controller's hcmsg structure
692 static void send_disconnect_b3_ind(struct bc_state
*bcs
,
693 struct gigaset_capi_appl
*ap
)
695 struct cardstate
*cs
= bcs
->cs
;
696 struct gigaset_capi_ctr
*iif
= cs
->iif
;
699 /* nothing to do if no logical connection active */
700 if (ap
->connected
< APCONN_ACTIVE
)
702 ap
->connected
= APCONN_SETUP
;
704 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_DISCONNECT_B3
, CAPI_IND
,
705 ap
->nextMessageNumber
++,
706 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8) | (1 << 16));
707 skb
= alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN
, GFP_ATOMIC
);
709 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
712 capi_cmsg2message(&iif
->hcmsg
,
713 __skb_put(skb
, CAPI_DISCONNECT_B3_IND_BASELEN
));
714 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
715 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
719 * gigaset_isdn_connD() - signal D channel connect
720 * @bcs: B channel descriptor structure.
722 * Called by main module at tasklet level to notify the LL that the D channel
723 * connection has been established.
725 void gigaset_isdn_connD(struct bc_state
*bcs
)
727 struct cardstate
*cs
= bcs
->cs
;
728 struct gigaset_capi_ctr
*iif
= cs
->iif
;
729 struct gigaset_capi_appl
*ap
= bcs
->ap
;
731 unsigned int msgsize
;
734 dev_err(cs
->dev
, "%s: no application\n", __func__
);
738 /* this should never happen */
739 dev_warn(cs
->dev
, "%s: dropping extra application %u\n",
740 __func__
, ap
->bcnext
->id
);
741 send_disconnect_ind(bcs
, ap
->bcnext
,
742 CapiCallGivenToOtherApplication
);
743 ap
->bcnext
= ap
->bcnext
->bcnext
;
745 if (ap
->connected
== APCONN_NONE
) {
746 dev_warn(cs
->dev
, "%s: application %u not connected\n",
751 /* prepare CONNECT_ACTIVE_IND message
752 * Note: LLC not supported by device
754 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, CAPI_CONNECT_ACTIVE
, CAPI_IND
,
755 ap
->nextMessageNumber
++,
756 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8));
758 /* minimum size, all structs empty */
759 msgsize
= CAPI_CONNECT_ACTIVE_IND_BASELEN
;
761 /* ToDo: set parameter: Connected number
762 * (requires ev-layer state machine extension to collect
766 /* build and emit CONNECT_ACTIVE_IND message */
767 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
769 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
772 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
773 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
774 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
778 * gigaset_isdn_hupD() - signal D channel hangup
779 * @bcs: B channel descriptor structure.
781 * Called by main module at tasklet level to notify the LL that the D channel
782 * connection has been shut down.
784 void gigaset_isdn_hupD(struct bc_state
*bcs
)
786 struct gigaset_capi_appl
*ap
;
789 * ToDo: pass on reason code reported by device
790 * (requires ev-layer state machine extension to collect
793 for (ap
= bcs
->ap
; ap
!= NULL
; ap
= ap
->bcnext
) {
794 send_disconnect_b3_ind(bcs
, ap
);
795 send_disconnect_ind(bcs
, ap
, 0);
801 * gigaset_isdn_connB() - signal B channel connect
802 * @bcs: B channel descriptor structure.
804 * Called by main module at tasklet level to notify the LL that the B channel
805 * connection has been established.
807 void gigaset_isdn_connB(struct bc_state
*bcs
)
809 struct cardstate
*cs
= bcs
->cs
;
810 struct gigaset_capi_ctr
*iif
= cs
->iif
;
811 struct gigaset_capi_appl
*ap
= bcs
->ap
;
813 unsigned int msgsize
;
817 dev_err(cs
->dev
, "%s: no application\n", __func__
);
821 /* this should never happen */
822 dev_warn(cs
->dev
, "%s: dropping extra application %u\n",
823 __func__
, ap
->bcnext
->id
);
824 send_disconnect_ind(bcs
, ap
->bcnext
,
825 CapiCallGivenToOtherApplication
);
826 ap
->bcnext
= ap
->bcnext
->bcnext
;
828 if (!ap
->connected
) {
829 dev_warn(cs
->dev
, "%s: application %u not connected\n",
835 * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
836 * otherwise we have to emit CONNECT_B3_IND first, and follow up with
837 * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
838 * Parameters in both cases always: NCCI = 1, NCPI empty
840 if (ap
->connected
>= APCONN_ACTIVE
) {
841 command
= CAPI_CONNECT_B3_ACTIVE
;
842 msgsize
= CAPI_CONNECT_B3_ACTIVE_IND_BASELEN
;
844 command
= CAPI_CONNECT_B3
;
845 msgsize
= CAPI_CONNECT_B3_IND_BASELEN
;
847 capi_cmsg_header(&iif
->hcmsg
, ap
->id
, command
, CAPI_IND
,
848 ap
->nextMessageNumber
++,
849 iif
->ctr
.cnr
| ((bcs
->channel
+ 1) << 8) | (1 << 16));
850 skb
= alloc_skb(msgsize
, GFP_ATOMIC
);
852 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
855 capi_cmsg2message(&iif
->hcmsg
, __skb_put(skb
, msgsize
));
856 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->hcmsg
);
857 ap
->connected
= APCONN_ACTIVE
;
858 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
862 * gigaset_isdn_hupB() - signal B channel hangup
863 * @bcs: B channel descriptor structure.
865 * Called by main module to notify the LL that the B channel connection has
868 void gigaset_isdn_hupB(struct bc_state
*bcs
)
870 struct cardstate
*cs
= bcs
->cs
;
871 struct gigaset_capi_appl
*ap
= bcs
->ap
;
873 /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
876 dev_err(cs
->dev
, "%s: no application\n", __func__
);
880 send_disconnect_b3_ind(bcs
, ap
);
884 * gigaset_isdn_start() - signal device availability
885 * @cs: device descriptor structure.
887 * Called by main module to notify the LL that the device is available for
890 void gigaset_isdn_start(struct cardstate
*cs
)
892 struct gigaset_capi_ctr
*iif
= cs
->iif
;
894 /* fill profile data: manufacturer name */
895 strcpy(iif
->ctr
.manu
, "Siemens");
896 /* CAPI and device version */
897 iif
->ctr
.version
.majorversion
= 2; /* CAPI 2.0 */
898 iif
->ctr
.version
.minorversion
= 0;
899 /* ToDo: check/assert cs->gotfwver? */
900 iif
->ctr
.version
.majormanuversion
= cs
->fwver
[0];
901 iif
->ctr
.version
.minormanuversion
= cs
->fwver
[1];
902 /* number of B channels supported */
903 iif
->ctr
.profile
.nbchannel
= cs
->channels
;
904 /* global options: internal controller, supplementary services */
905 iif
->ctr
.profile
.goptions
= 0x11;
906 /* B1 protocols: 64 kbit/s HDLC or transparent */
907 iif
->ctr
.profile
.support1
= 0x03;
908 /* B2 protocols: transparent only */
909 /* ToDo: X.75 SLP ? */
910 iif
->ctr
.profile
.support2
= 0x02;
911 /* B3 protocols: transparent only */
912 iif
->ctr
.profile
.support3
= 0x01;
913 /* no serial number */
914 strcpy(iif
->ctr
.serial
, "0");
915 capi_ctr_ready(&iif
->ctr
);
919 * gigaset_isdn_stop() - signal device unavailability
920 * @cs: device descriptor structure.
922 * Called by main module to notify the LL that the device is no longer
925 void gigaset_isdn_stop(struct cardstate
*cs
)
927 struct gigaset_capi_ctr
*iif
= cs
->iif
;
928 capi_ctr_down(&iif
->ctr
);
932 * kernel CAPI callback methods
933 * ============================
937 * register CAPI application
939 static void gigaset_register_appl(struct capi_ctr
*ctr
, u16 appl
,
940 capi_register_params
*rp
)
942 struct gigaset_capi_ctr
*iif
943 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
944 struct cardstate
*cs
= ctr
->driverdata
;
945 struct gigaset_capi_appl
*ap
;
947 list_for_each_entry(ap
, &iif
->appls
, ctrlist
)
948 if (ap
->id
== appl
) {
950 "application %u already registered\n", appl
);
954 ap
= kzalloc(sizeof(*ap
), GFP_KERNEL
);
956 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
962 list_add(&ap
->ctrlist
, &iif
->appls
);
966 * release CAPI application
968 static void gigaset_release_appl(struct capi_ctr
*ctr
, u16 appl
)
970 struct gigaset_capi_ctr
*iif
971 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
972 struct cardstate
*cs
= iif
->ctr
.driverdata
;
973 struct gigaset_capi_appl
*ap
, *tmp
;
975 list_for_each_entry_safe(ap
, tmp
, &iif
->appls
, ctrlist
)
976 if (ap
->id
== appl
) {
977 if (ap
->connected
!= APCONN_NONE
) {
979 "%s: application %u still connected\n",
981 /* ToDo: clear active connection */
983 list_del(&ap
->ctrlist
);
990 * =====================================================================
991 * outgoing CAPI message handler
992 * =====================================================================
996 * helper function: emit reply message with given Info value
998 static void send_conf(struct gigaset_capi_ctr
*iif
,
999 struct gigaset_capi_appl
*ap
,
1000 struct sk_buff
*skb
,
1004 * _CONF replies always only have NCCI and Info parameters
1005 * so they'll fit into the _REQ message skb
1007 capi_cmsg_answer(&iif
->acmsg
);
1008 iif
->acmsg
.Info
= info
;
1009 capi_cmsg2message(&iif
->acmsg
, skb
->data
);
1010 __skb_trim(skb
, CAPI_STDCONF_LEN
);
1011 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1012 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1016 * process FACILITY_REQ message
1018 static void do_facility_req(struct gigaset_capi_ctr
*iif
,
1019 struct gigaset_capi_appl
*ap
,
1020 struct sk_buff
*skb
)
1022 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1023 _cmsg
*cmsg
= &iif
->acmsg
;
1024 struct sk_buff
*cskb
;
1026 unsigned int msgsize
= CAPI_FACILITY_CONF_BASELEN
;
1028 static u8 confparam
[10]; /* max. 9 octets + length byte */
1030 /* decode message */
1031 capi_message2cmsg(cmsg
, skb
->data
);
1032 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1035 * Facility Request Parameter is not decoded by capi_message2cmsg()
1036 * encoding depends on Facility Selector
1038 switch (cmsg
->FacilitySelector
) {
1039 case CAPI_FACILITY_DTMF
: /* ToDo */
1040 info
= CapiFacilityNotSupported
;
1041 confparam
[0] = 2; /* length */
1042 /* DTMF information: Unknown DTMF request */
1043 capimsg_setu16(confparam
, 1, 2);
1046 case CAPI_FACILITY_V42BIS
: /* not supported */
1047 info
= CapiFacilityNotSupported
;
1048 confparam
[0] = 2; /* length */
1049 /* V.42 bis information: not available */
1050 capimsg_setu16(confparam
, 1, 1);
1053 case CAPI_FACILITY_SUPPSVC
:
1054 /* decode Function parameter */
1055 pparam
= cmsg
->FacilityRequestParameter
;
1056 if (pparam
== NULL
|| *pparam
< 2) {
1057 dev_notice(cs
->dev
, "%s: %s missing\n", "FACILITY_REQ",
1058 "Facility Request Parameter");
1059 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
1062 function
= CAPIMSG_U16(pparam
, 1);
1064 case CAPI_SUPPSVC_GETSUPPORTED
:
1066 /* Supplementary Service specific parameter */
1067 confparam
[3] = 6; /* length */
1068 /* Supplementary services info: Success */
1069 capimsg_setu16(confparam
, 4, CapiSuccess
);
1070 /* Supported Services: none */
1071 capimsg_setu32(confparam
, 6, 0);
1073 /* ToDo: add supported services */
1075 info
= CapiFacilitySpecificFunctionNotSupported
;
1076 /* Supplementary Service specific parameter */
1077 confparam
[3] = 2; /* length */
1078 /* Supplementary services info: not supported */
1079 capimsg_setu16(confparam
, 4,
1080 CapiSupplementaryServiceNotSupported
);
1083 /* Facility confirmation parameter */
1084 confparam
[0] = confparam
[3] + 3; /* total length */
1085 /* Function: copy from _REQ message */
1086 capimsg_setu16(confparam
, 1, function
);
1087 /* Supplementary Service specific parameter already set above */
1090 case CAPI_FACILITY_WAKEUP
: /* ToDo */
1091 info
= CapiFacilityNotSupported
;
1092 confparam
[0] = 2; /* length */
1093 /* Number of accepted awake request parameters: 0 */
1094 capimsg_setu16(confparam
, 1, 0);
1098 info
= CapiFacilityNotSupported
;
1099 confparam
[0] = 0; /* empty struct */
1102 /* send FACILITY_CONF with given Info and confirmation parameter */
1103 capi_cmsg_answer(cmsg
);
1105 cmsg
->FacilityConfirmationParameter
= confparam
;
1106 msgsize
+= confparam
[0]; /* length */
1107 cskb
= alloc_skb(msgsize
, GFP_ATOMIC
);
1109 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1112 capi_cmsg2message(cmsg
, __skb_put(cskb
, msgsize
));
1113 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1114 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, cskb
);
1119 * process LISTEN_REQ message
1120 * just store the masks in the application data structure
1122 static void do_listen_req(struct gigaset_capi_ctr
*iif
,
1123 struct gigaset_capi_appl
*ap
,
1124 struct sk_buff
*skb
)
1126 /* decode message */
1127 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1128 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1130 /* store listening parameters */
1131 ap
->listenInfoMask
= iif
->acmsg
.InfoMask
;
1132 ap
->listenCIPmask
= iif
->acmsg
.CIPmask
;
1133 send_conf(iif
, ap
, skb
, CapiSuccess
);
1137 * process ALERT_REQ message
1138 * nothing to do, Gigaset always alerts anyway
1140 static void do_alert_req(struct gigaset_capi_ctr
*iif
,
1141 struct gigaset_capi_appl
*ap
,
1142 struct sk_buff
*skb
)
1144 /* decode message */
1145 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1146 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1147 send_conf(iif
, ap
, skb
, CapiAlertAlreadySent
);
1151 * process CONNECT_REQ message
1152 * allocate a B channel, prepare dial commands, queue a DIAL event,
1153 * emit CONNECT_CONF reply
1155 static void do_connect_req(struct gigaset_capi_ctr
*iif
,
1156 struct gigaset_capi_appl
*ap
,
1157 struct sk_buff
*skb
)
1159 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1160 _cmsg
*cmsg
= &iif
->acmsg
;
1161 struct bc_state
*bcs
;
1168 /* decode message */
1169 capi_message2cmsg(cmsg
, skb
->data
);
1170 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1172 /* get free B channel & construct PLCI */
1173 bcs
= gigaset_get_free_channel(cs
);
1175 dev_notice(cs
->dev
, "%s: no B channel available\n",
1177 send_conf(iif
, ap
, skb
, CapiNoPlciAvailable
);
1182 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1183 dev_kfree_skb(bcs
->rx_skb
);
1184 gigaset_new_rx_skb(bcs
);
1185 cmsg
->adr
.adrPLCI
|= (bcs
->channel
+ 1) << 8;
1187 /* build command table */
1188 commands
= kzalloc(AT_NUM
*(sizeof *commands
), GFP_KERNEL
);
1192 /* encode parameter: Called party number */
1193 pp
= cmsg
->CalledPartyNumber
;
1194 if (pp
== NULL
|| *pp
== 0) {
1195 dev_notice(cs
->dev
, "%s: %s missing\n",
1196 "CONNECT_REQ", "Called party number");
1197 info
= CapiIllMessageParmCoding
;
1201 /* check type of number/numbering plan byte */
1203 case 0x80: /* unknown type / unknown numbering plan */
1204 case 0x81: /* unknown type / ISDN/Telephony numbering plan */
1206 default: /* others: warn about potential misinterpretation */
1207 dev_notice(cs
->dev
, "%s: %s type/plan 0x%02x unsupported\n",
1208 "CONNECT_REQ", "Called party number", *pp
);
1212 /* translate "**" internal call prefix to CTP value */
1213 if (l
>= 2 && pp
[0] == '*' && pp
[1] == '*') {
1220 commands
[AT_TYPE
] = kstrdup(s
, GFP_KERNEL
);
1221 if (!commands
[AT_TYPE
])
1223 commands
[AT_DIAL
] = kmalloc(l
+3, GFP_KERNEL
);
1224 if (!commands
[AT_DIAL
])
1226 snprintf(commands
[AT_DIAL
], l
+3, "D%.*s\r", l
, pp
);
1228 /* encode parameter: Calling party number */
1229 pp
= cmsg
->CallingPartyNumber
;
1230 if (pp
!= NULL
&& *pp
> 0) {
1233 /* check type of number/numbering plan byte */
1234 /* ToDo: allow for/handle Ext=1? */
1236 case 0x00: /* unknown type / unknown numbering plan */
1237 case 0x01: /* unknown type / ISDN/Telephony num. plan */
1241 "%s: %s type/plan 0x%02x unsupported\n",
1242 "CONNECT_REQ", "Calling party number", *pp
);
1247 /* check presentation indicator */
1249 dev_notice(cs
->dev
, "%s: %s IE truncated\n",
1250 "CONNECT_REQ", "Calling party number");
1251 info
= CapiIllMessageParmCoding
;
1254 switch (*pp
& 0xfc) { /* ignore Screening indicator */
1255 case 0x80: /* Presentation allowed */
1258 case 0xa0: /* Presentation restricted */
1262 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1264 "Presentation/Screening indicator",
1268 commands
[AT_CLIP
] = kstrdup(s
, GFP_KERNEL
);
1269 if (!commands
[AT_CLIP
])
1276 commands
[AT_MSN
] = kmalloc(l
+8, GFP_KERNEL
);
1277 if (!commands
[AT_MSN
])
1279 snprintf(commands
[AT_MSN
], l
+8, "^SMSN=%*s\r", l
, pp
);
1283 /* check parameter: CIP Value */
1284 if (cmsg
->CIPValue
>= ARRAY_SIZE(cip2bchlc
) ||
1285 (cmsg
->CIPValue
> 0 && cip2bchlc
[cmsg
->CIPValue
].bc
== NULL
)) {
1286 dev_notice(cs
->dev
, "%s: unknown CIP value %d\n",
1287 "CONNECT_REQ", cmsg
->CIPValue
);
1288 info
= CapiCipValueUnknown
;
1292 /* check/encode parameter: BC */
1293 if (cmsg
->BC
&& cmsg
->BC
[0]) {
1294 /* explicit BC overrides CIP */
1295 l
= 2*cmsg
->BC
[0] + 7;
1296 commands
[AT_BC
] = kmalloc(l
, GFP_KERNEL
);
1297 if (!commands
[AT_BC
])
1299 strcpy(commands
[AT_BC
], "^SBC=");
1300 decode_ie(cmsg
->BC
, commands
[AT_BC
]+5);
1301 strcpy(commands
[AT_BC
] + l
- 2, "\r");
1302 } else if (cip2bchlc
[cmsg
->CIPValue
].bc
) {
1303 l
= strlen(cip2bchlc
[cmsg
->CIPValue
].bc
) + 7;
1304 commands
[AT_BC
] = kmalloc(l
, GFP_KERNEL
);
1305 if (!commands
[AT_BC
])
1307 snprintf(commands
[AT_BC
], l
, "^SBC=%s\r",
1308 cip2bchlc
[cmsg
->CIPValue
].bc
);
1311 /* check/encode parameter: HLC */
1312 if (cmsg
->HLC
&& cmsg
->HLC
[0]) {
1313 /* explicit HLC overrides CIP */
1314 l
= 2*cmsg
->HLC
[0] + 7;
1315 commands
[AT_HLC
] = kmalloc(l
, GFP_KERNEL
);
1316 if (!commands
[AT_HLC
])
1318 strcpy(commands
[AT_HLC
], "^SHLC=");
1319 decode_ie(cmsg
->HLC
, commands
[AT_HLC
]+5);
1320 strcpy(commands
[AT_HLC
] + l
- 2, "\r");
1321 } else if (cip2bchlc
[cmsg
->CIPValue
].hlc
) {
1322 l
= strlen(cip2bchlc
[cmsg
->CIPValue
].hlc
) + 7;
1323 commands
[AT_HLC
] = kmalloc(l
, GFP_KERNEL
);
1324 if (!commands
[AT_HLC
])
1326 snprintf(commands
[AT_HLC
], l
, "^SHLC=%s\r",
1327 cip2bchlc
[cmsg
->CIPValue
].hlc
);
1330 /* check/encode parameter: B Protocol */
1331 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1332 bcs
->proto2
= L2_HDLC
;
1334 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1336 switch (cmsg
->B1protocol
) {
1338 bcs
->proto2
= L2_HDLC
;
1341 bcs
->proto2
= L2_BITSYNC
;
1345 "B1 Protocol %u unsupported, using Transparent\n",
1347 bcs
->proto2
= L2_BITSYNC
;
1349 if (cmsg
->B2protocol
!= 1)
1351 "B2 Protocol %u unsupported, using Transparent\n",
1353 if (cmsg
->B3protocol
!= 0)
1355 "B3 Protocol %u unsupported, using Transparent\n",
1357 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1358 "CONNECT_REQ", "B1 Configuration");
1359 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1360 "CONNECT_REQ", "B2 Configuration");
1361 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1362 "CONNECT_REQ", "B3 Configuration");
1364 commands
[AT_PROTO
] = kmalloc(9, GFP_KERNEL
);
1365 if (!commands
[AT_PROTO
])
1367 snprintf(commands
[AT_PROTO
], 9, "^SBPR=%u\r", bcs
->proto2
);
1369 /* ToDo: check/encode remaining parameters */
1370 ignore_cstruct_param(cs
, cmsg
->CalledPartySubaddress
,
1371 "CONNECT_REQ", "Called pty subaddr");
1372 ignore_cstruct_param(cs
, cmsg
->CallingPartySubaddress
,
1373 "CONNECT_REQ", "Calling pty subaddr");
1374 ignore_cstruct_param(cs
, cmsg
->LLC
,
1375 "CONNECT_REQ", "LLC");
1376 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1377 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1378 "CONNECT_REQ", "B Channel Information");
1379 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1380 "CONNECT_REQ", "Keypad Facility");
1381 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1382 "CONNECT_REQ", "User-User Data");
1383 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1384 "CONNECT_REQ", "Facility Data Array");
1387 /* encode parameter: B channel to use */
1388 commands
[AT_ISO
] = kmalloc(9, GFP_KERNEL
);
1389 if (!commands
[AT_ISO
])
1391 snprintf(commands
[AT_ISO
], 9, "^SISO=%u\r",
1392 (unsigned) bcs
->channel
+ 1);
1394 /* queue & schedule EV_DIAL event */
1395 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_DIAL
, commands
,
1396 bcs
->at_state
.seq_index
, NULL
)) {
1397 info
= CAPI_MSGOSRESOURCEERR
;
1400 gigaset_schedule_event(cs
);
1401 ap
->connected
= APCONN_SETUP
;
1402 send_conf(iif
, ap
, skb
, CapiSuccess
);
1406 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1407 info
= CAPI_MSGOSRESOURCEERR
;
1410 for (i
= 0; i
< AT_NUM
; i
++)
1413 gigaset_free_channel(bcs
);
1414 send_conf(iif
, ap
, skb
, info
);
1418 * process CONNECT_RESP message
1419 * checks protocol parameters and queues an ACCEPT or HUP event
1421 static void do_connect_resp(struct gigaset_capi_ctr
*iif
,
1422 struct gigaset_capi_appl
*ap
,
1423 struct sk_buff
*skb
)
1425 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1426 _cmsg
*cmsg
= &iif
->acmsg
;
1427 struct bc_state
*bcs
;
1428 struct gigaset_capi_appl
*oap
;
1431 /* decode message */
1432 capi_message2cmsg(cmsg
, skb
->data
);
1433 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1434 dev_kfree_skb_any(skb
);
1436 /* extract and check channel number from PLCI */
1437 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1438 if (!channel
|| channel
> cs
->channels
) {
1439 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1440 "CONNECT_RESP", "PLCI", cmsg
->adr
.adrPLCI
);
1443 bcs
= cs
->bcs
+ channel
- 1;
1445 switch (cmsg
->Reject
) {
1446 case 0: /* Accept */
1447 /* drop all competing applications, keep only this one */
1448 for (oap
= bcs
->ap
; oap
!= NULL
; oap
= oap
->bcnext
)
1450 send_disconnect_ind(bcs
, oap
,
1451 CapiCallGivenToOtherApplication
);
1454 bcs
->rx_bufsize
= ap
->rp
.datablklen
;
1455 dev_kfree_skb(bcs
->rx_skb
);
1456 gigaset_new_rx_skb(bcs
);
1457 bcs
->chstate
|= CHS_NOTIFY_LL
;
1459 /* check/encode B channel protocol */
1460 if (cmsg
->BProtocol
== CAPI_DEFAULT
) {
1461 bcs
->proto2
= L2_HDLC
;
1463 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1465 switch (cmsg
->B1protocol
) {
1467 bcs
->proto2
= L2_HDLC
;
1470 bcs
->proto2
= L2_BITSYNC
;
1474 "B1 Protocol %u unsupported, using Transparent\n",
1476 bcs
->proto2
= L2_BITSYNC
;
1478 if (cmsg
->B2protocol
!= 1)
1480 "B2 Protocol %u unsupported, using Transparent\n",
1482 if (cmsg
->B3protocol
!= 0)
1484 "B3 Protocol %u unsupported, using Transparent\n",
1486 ignore_cstruct_param(cs
, cmsg
->B1configuration
,
1487 "CONNECT_RESP", "B1 Configuration");
1488 ignore_cstruct_param(cs
, cmsg
->B2configuration
,
1489 "CONNECT_RESP", "B2 Configuration");
1490 ignore_cstruct_param(cs
, cmsg
->B3configuration
,
1491 "CONNECT_RESP", "B3 Configuration");
1494 /* ToDo: check/encode remaining parameters */
1495 ignore_cstruct_param(cs
, cmsg
->ConnectedNumber
,
1496 "CONNECT_RESP", "Connected Number");
1497 ignore_cstruct_param(cs
, cmsg
->ConnectedSubaddress
,
1498 "CONNECT_RESP", "Connected Subaddress");
1499 ignore_cstruct_param(cs
, cmsg
->LLC
,
1500 "CONNECT_RESP", "LLC");
1501 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1502 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1503 "CONNECT_RESP", "BChannel Information");
1504 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1505 "CONNECT_RESP", "Keypad Facility");
1506 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1507 "CONNECT_RESP", "User-User Data");
1508 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1509 "CONNECT_RESP", "Facility Data Array");
1513 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1514 EV_ACCEPT
, NULL
, 0, NULL
))
1516 gigaset_schedule_event(cs
);
1519 case 1: /* Ignore */
1520 /* send DISCONNECT_IND to this application */
1521 send_disconnect_ind(bcs
, ap
, 0);
1523 /* remove it from the list of listening apps */
1524 if (bcs
->ap
== ap
) {
1525 bcs
->ap
= ap
->bcnext
;
1526 if (bcs
->ap
== NULL
)
1527 /* last one: stop ev-layer hupD notifications */
1528 bcs
->chstate
&= ~CHS_NOTIFY_LL
;
1531 for (oap
= bcs
->ap
; oap
!= NULL
; oap
= oap
->bcnext
) {
1532 if (oap
->bcnext
== ap
) {
1533 oap
->bcnext
= oap
->bcnext
->bcnext
;
1537 dev_err(cs
->dev
, "%s: application %u not found\n",
1541 default: /* Reject */
1542 /* drop all competing applications, keep only this one */
1543 for (oap
= bcs
->ap
; oap
!= NULL
; oap
= oap
->bcnext
)
1545 send_disconnect_ind(bcs
, oap
,
1546 CapiCallGivenToOtherApplication
);
1550 /* reject call - will trigger DISCONNECT_IND for this app */
1551 dev_info(cs
->dev
, "%s: Reject=%x\n",
1552 "CONNECT_RESP", cmsg
->Reject
);
1553 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1554 EV_HUP
, NULL
, 0, NULL
))
1556 gigaset_schedule_event(cs
);
1562 * process CONNECT_B3_REQ message
1563 * build NCCI and emit CONNECT_B3_CONF reply
1565 static void do_connect_b3_req(struct gigaset_capi_ctr
*iif
,
1566 struct gigaset_capi_appl
*ap
,
1567 struct sk_buff
*skb
)
1569 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1570 _cmsg
*cmsg
= &iif
->acmsg
;
1573 /* decode message */
1574 capi_message2cmsg(cmsg
, skb
->data
);
1575 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1577 /* extract and check channel number from PLCI */
1578 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1579 if (!channel
|| channel
> cs
->channels
) {
1580 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1581 "CONNECT_B3_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1582 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1586 /* mark logical connection active */
1587 ap
->connected
= APCONN_ACTIVE
;
1589 /* build NCCI: always 1 (one B3 connection only) */
1590 cmsg
->adr
.adrNCCI
|= 1 << 16;
1592 /* NCPI parameter: not applicable for B3 Transparent */
1593 ignore_cstruct_param(cs
, cmsg
->NCPI
, "CONNECT_B3_REQ", "NCPI");
1594 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1595 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1599 * process CONNECT_B3_RESP message
1600 * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
1601 * or queue EV_HUP and emit DISCONNECT_B3_IND.
1602 * The emitted message is always shorter than the received one,
1603 * allowing to reuse the skb.
1605 static void do_connect_b3_resp(struct gigaset_capi_ctr
*iif
,
1606 struct gigaset_capi_appl
*ap
,
1607 struct sk_buff
*skb
)
1609 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1610 _cmsg
*cmsg
= &iif
->acmsg
;
1611 struct bc_state
*bcs
;
1613 unsigned int msgsize
;
1616 /* decode message */
1617 capi_message2cmsg(cmsg
, skb
->data
);
1618 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1620 /* extract and check channel number and NCCI */
1621 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1622 if (!channel
|| channel
> cs
->channels
||
1623 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1624 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1625 "CONNECT_B3_RESP", "NCCI", cmsg
->adr
.adrNCCI
);
1626 dev_kfree_skb_any(skb
);
1629 bcs
= &cs
->bcs
[channel
-1];
1632 /* Reject: clear B3 connect received flag */
1633 ap
->connected
= APCONN_SETUP
;
1635 /* trigger hangup, causing eventual DISCONNECT_IND */
1636 if (!gigaset_add_event(cs
, &bcs
->at_state
,
1637 EV_HUP
, NULL
, 0, NULL
)) {
1638 dev_kfree_skb_any(skb
);
1641 gigaset_schedule_event(cs
);
1643 /* emit DISCONNECT_B3_IND */
1644 command
= CAPI_DISCONNECT_B3
;
1645 msgsize
= CAPI_DISCONNECT_B3_IND_BASELEN
;
1648 * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
1649 * we only send CONNECT_B3_IND if the B channel is up
1651 command
= CAPI_CONNECT_B3_ACTIVE
;
1652 msgsize
= CAPI_CONNECT_B3_ACTIVE_IND_BASELEN
;
1654 capi_cmsg_header(cmsg
, ap
->id
, command
, CAPI_IND
,
1655 ap
->nextMessageNumber
++, cmsg
->adr
.adrNCCI
);
1656 __skb_trim(skb
, msgsize
);
1657 capi_cmsg2message(cmsg
, skb
->data
);
1658 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1659 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, skb
);
1663 * process DISCONNECT_REQ message
1664 * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
1665 * emit DISCONNECT_CONF reply
1667 static void do_disconnect_req(struct gigaset_capi_ctr
*iif
,
1668 struct gigaset_capi_appl
*ap
,
1669 struct sk_buff
*skb
)
1671 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1672 _cmsg
*cmsg
= &iif
->acmsg
;
1673 struct bc_state
*bcs
;
1675 struct sk_buff
*b3skb
;
1678 /* decode message */
1679 capi_message2cmsg(cmsg
, skb
->data
);
1680 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1682 /* extract and check channel number from PLCI */
1683 channel
= (cmsg
->adr
.adrPLCI
>> 8) & 0xff;
1684 if (!channel
|| channel
> cs
->channels
) {
1685 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1686 "DISCONNECT_REQ", "PLCI", cmsg
->adr
.adrPLCI
);
1687 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1690 bcs
= cs
->bcs
+ channel
- 1;
1692 /* ToDo: process parameter: Additional info */
1693 if (cmsg
->AdditionalInfo
!= CAPI_DEFAULT
) {
1694 ignore_cstruct_param(cs
, cmsg
->BChannelinformation
,
1695 "DISCONNECT_REQ", "B Channel Information");
1696 ignore_cstruct_param(cs
, cmsg
->Keypadfacility
,
1697 "DISCONNECT_REQ", "Keypad Facility");
1698 ignore_cstruct_param(cs
, cmsg
->Useruserdata
,
1699 "DISCONNECT_REQ", "User-User Data");
1700 ignore_cstruct_param(cs
, cmsg
->Facilitydataarray
,
1701 "DISCONNECT_REQ", "Facility Data Array");
1704 /* skip if DISCONNECT_IND already sent */
1708 /* check for active logical connection */
1709 if (ap
->connected
>= APCONN_ACTIVE
) {
1711 * emit DISCONNECT_B3_IND with cause 0x3301
1712 * use separate cmsg structure, as the content of iif->acmsg
1713 * is still needed for creating the _CONF message
1715 b3cmsg
= kmalloc(sizeof(*b3cmsg
), GFP_KERNEL
);
1717 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1718 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1721 capi_cmsg_header(b3cmsg
, ap
->id
, CAPI_DISCONNECT_B3
, CAPI_IND
,
1722 ap
->nextMessageNumber
++,
1723 cmsg
->adr
.adrPLCI
| (1 << 16));
1724 b3cmsg
->Reason_B3
= CapiProtocolErrorLayer1
;
1725 b3skb
= alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN
, GFP_KERNEL
);
1726 if (b3skb
== NULL
) {
1727 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
1728 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1731 capi_cmsg2message(b3cmsg
,
1732 __skb_put(b3skb
, CAPI_DISCONNECT_B3_IND_BASELEN
));
1734 capi_ctr_handle_message(&iif
->ctr
, ap
->id
, b3skb
);
1737 /* trigger hangup, causing eventual DISCONNECT_IND */
1738 if (!gigaset_add_event(cs
, &bcs
->at_state
, EV_HUP
, NULL
, 0, NULL
)) {
1739 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1742 gigaset_schedule_event(cs
);
1745 send_conf(iif
, ap
, skb
, CapiSuccess
);
1749 * process DISCONNECT_B3_REQ message
1750 * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
1752 static void do_disconnect_b3_req(struct gigaset_capi_ctr
*iif
,
1753 struct gigaset_capi_appl
*ap
,
1754 struct sk_buff
*skb
)
1756 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1757 _cmsg
*cmsg
= &iif
->acmsg
;
1760 /* decode message */
1761 capi_message2cmsg(cmsg
, skb
->data
);
1762 dump_cmsg(DEBUG_CMD
, __func__
, cmsg
);
1764 /* extract and check channel number and NCCI */
1765 channel
= (cmsg
->adr
.adrNCCI
>> 8) & 0xff;
1766 if (!channel
|| channel
> cs
->channels
||
1767 ((cmsg
->adr
.adrNCCI
>> 16) & 0xffff) != 1) {
1768 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1769 "DISCONNECT_B3_REQ", "NCCI", cmsg
->adr
.adrNCCI
);
1770 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1774 /* reject if logical connection not active */
1775 if (ap
->connected
< APCONN_ACTIVE
) {
1776 send_conf(iif
, ap
, skb
,
1777 CapiMessageNotSupportedInCurrentState
);
1781 /* trigger hangup, causing eventual DISCONNECT_B3_IND */
1782 if (!gigaset_add_event(cs
, &cs
->bcs
[channel
-1].at_state
,
1783 EV_HUP
, NULL
, 0, NULL
)) {
1784 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1787 gigaset_schedule_event(cs
);
1789 /* NCPI parameter: not applicable for B3 Transparent */
1790 ignore_cstruct_param(cs
, cmsg
->NCPI
,
1791 "DISCONNECT_B3_REQ", "NCPI");
1792 send_conf(iif
, ap
, skb
, (cmsg
->NCPI
&& cmsg
->NCPI
[0]) ?
1793 CapiNcpiNotSupportedByProtocol
: CapiSuccess
);
1797 * process DATA_B3_REQ message
1799 static void do_data_b3_req(struct gigaset_capi_ctr
*iif
,
1800 struct gigaset_capi_appl
*ap
,
1801 struct sk_buff
*skb
)
1803 struct cardstate
*cs
= iif
->ctr
.driverdata
;
1804 int channel
= CAPIMSG_PLCI_PART(skb
->data
);
1805 u16 ncci
= CAPIMSG_NCCI_PART(skb
->data
);
1806 u16 msglen
= CAPIMSG_LEN(skb
->data
);
1807 u16 datalen
= CAPIMSG_DATALEN(skb
->data
);
1808 u16 flags
= CAPIMSG_FLAGS(skb
->data
);
1810 /* frequent message, avoid _cmsg overhead */
1811 dump_rawmsg(DEBUG_LLDATA
, "DATA_B3_REQ", skb
->data
);
1813 gig_dbg(DEBUG_LLDATA
,
1814 "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
1815 channel
, flags
, msglen
, datalen
);
1817 /* check parameters */
1818 if (channel
== 0 || channel
> cs
->channels
|| ncci
!= 1) {
1819 dev_notice(cs
->dev
, "%s: invalid %s 0x%02x\n",
1820 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb
->data
));
1821 send_conf(iif
, ap
, skb
, CapiIllContrPlciNcci
);
1824 if (msglen
!= CAPI_DATA_B3_REQ_LEN
&& msglen
!= CAPI_DATA_B3_REQ_LEN64
)
1825 dev_notice(cs
->dev
, "%s: unexpected length %d\n",
1826 "DATA_B3_REQ", msglen
);
1827 if (msglen
+ datalen
!= skb
->len
)
1828 dev_notice(cs
->dev
, "%s: length mismatch (%d+%d!=%d)\n",
1829 "DATA_B3_REQ", msglen
, datalen
, skb
->len
);
1830 if (msglen
+ datalen
> skb
->len
) {
1831 /* message too short for announced data length */
1832 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
); /* ? */
1835 if (flags
& CAPI_FLAGS_RESERVED
) {
1836 dev_notice(cs
->dev
, "%s: reserved flags set (%x)\n",
1837 "DATA_B3_REQ", flags
);
1838 send_conf(iif
, ap
, skb
, CapiIllMessageParmCoding
);
1842 /* reject if logical connection not active */
1843 if (ap
->connected
< APCONN_ACTIVE
) {
1844 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
1848 /* pull CAPI message into link layer header */
1849 skb_reset_mac_header(skb
);
1850 skb
->mac_len
= msglen
;
1851 skb_pull(skb
, msglen
);
1853 /* pass to device-specific module */
1854 if (cs
->ops
->send_skb(&cs
->bcs
[channel
-1], skb
) < 0) {
1855 send_conf(iif
, ap
, skb
, CAPI_MSGOSRESOURCEERR
);
1859 /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
1862 * ToDo: honor unset "delivery confirmation" bit
1863 * (send DATA_B3_CONF immediately?)
1868 * process RESET_B3_REQ message
1869 * just always reply "not supported by current protocol"
1871 static void do_reset_b3_req(struct gigaset_capi_ctr
*iif
,
1872 struct gigaset_capi_appl
*ap
,
1873 struct sk_buff
*skb
)
1875 /* decode message */
1876 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1877 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1878 send_conf(iif
, ap
, skb
,
1879 CapiResetProcedureNotSupportedByCurrentProtocol
);
1883 * dump unsupported/ignored messages at most twice per minute,
1884 * some apps send those very frequently
1886 static unsigned long ignored_msg_dump_time
;
1889 * unsupported CAPI message handler
1891 static void do_unsupported(struct gigaset_capi_ctr
*iif
,
1892 struct gigaset_capi_appl
*ap
,
1893 struct sk_buff
*skb
)
1895 /* decode message */
1896 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1897 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000))
1898 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1899 send_conf(iif
, ap
, skb
, CapiMessageNotSupportedInCurrentState
);
1903 * CAPI message handler: no-op
1905 static void do_nothing(struct gigaset_capi_ctr
*iif
,
1906 struct gigaset_capi_appl
*ap
,
1907 struct sk_buff
*skb
)
1909 if (printk_timed_ratelimit(&ignored_msg_dump_time
, 30 * 1000)) {
1910 /* decode message */
1911 capi_message2cmsg(&iif
->acmsg
, skb
->data
);
1912 dump_cmsg(DEBUG_CMD
, __func__
, &iif
->acmsg
);
1914 dev_kfree_skb_any(skb
);
1917 static void do_data_b3_resp(struct gigaset_capi_ctr
*iif
,
1918 struct gigaset_capi_appl
*ap
,
1919 struct sk_buff
*skb
)
1921 dump_rawmsg(DEBUG_LLDATA
, __func__
, skb
->data
);
1922 dev_kfree_skb_any(skb
);
1925 /* table of outgoing CAPI message handlers with lookup function */
1926 typedef void (*capi_send_handler_t
)(struct gigaset_capi_ctr
*,
1927 struct gigaset_capi_appl
*,
1932 capi_send_handler_t handler
;
1933 } capi_send_handler_table
[] = {
1934 /* most frequent messages first for faster lookup */
1935 { CAPI_DATA_B3_REQ
, do_data_b3_req
},
1936 { CAPI_DATA_B3_RESP
, do_data_b3_resp
},
1938 { CAPI_ALERT_REQ
, do_alert_req
},
1939 { CAPI_CONNECT_ACTIVE_RESP
, do_nothing
},
1940 { CAPI_CONNECT_B3_ACTIVE_RESP
, do_nothing
},
1941 { CAPI_CONNECT_B3_REQ
, do_connect_b3_req
},
1942 { CAPI_CONNECT_B3_RESP
, do_connect_b3_resp
},
1943 { CAPI_CONNECT_B3_T90_ACTIVE_RESP
, do_nothing
},
1944 { CAPI_CONNECT_REQ
, do_connect_req
},
1945 { CAPI_CONNECT_RESP
, do_connect_resp
},
1946 { CAPI_DISCONNECT_B3_REQ
, do_disconnect_b3_req
},
1947 { CAPI_DISCONNECT_B3_RESP
, do_nothing
},
1948 { CAPI_DISCONNECT_REQ
, do_disconnect_req
},
1949 { CAPI_DISCONNECT_RESP
, do_nothing
},
1950 { CAPI_FACILITY_REQ
, do_facility_req
},
1951 { CAPI_FACILITY_RESP
, do_nothing
},
1952 { CAPI_LISTEN_REQ
, do_listen_req
},
1953 { CAPI_SELECT_B_PROTOCOL_REQ
, do_unsupported
},
1954 { CAPI_RESET_B3_REQ
, do_reset_b3_req
},
1955 { CAPI_RESET_B3_RESP
, do_nothing
},
1958 * ToDo: support overlap sending (requires ev-layer state
1959 * machine extension to generate additional ATD commands)
1961 { CAPI_INFO_REQ
, do_unsupported
},
1962 { CAPI_INFO_RESP
, do_nothing
},
1965 * ToDo: what's the proper response for these?
1967 { CAPI_MANUFACTURER_REQ
, do_nothing
},
1968 { CAPI_MANUFACTURER_RESP
, do_nothing
},
1971 /* look up handler */
1972 static inline capi_send_handler_t
lookup_capi_send_handler(const u16 cmd
)
1976 for (i
= 0; i
< ARRAY_SIZE(capi_send_handler_table
); i
++)
1977 if (capi_send_handler_table
[i
].cmd
== cmd
)
1978 return capi_send_handler_table
[i
].handler
;
1984 * gigaset_send_message() - accept a CAPI message from an application
1985 * @ctr: controller descriptor structure.
1986 * @skb: CAPI message.
1988 * Return value: CAPI error code
1989 * Note: capidrv (and probably others, too) only uses the return value to
1990 * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
1992 static u16
gigaset_send_message(struct capi_ctr
*ctr
, struct sk_buff
*skb
)
1994 struct gigaset_capi_ctr
*iif
1995 = container_of(ctr
, struct gigaset_capi_ctr
, ctr
);
1996 struct cardstate
*cs
= ctr
->driverdata
;
1997 struct gigaset_capi_appl
*ap
;
1998 capi_send_handler_t handler
;
2000 /* can only handle linear sk_buffs */
2001 if (skb_linearize(skb
) < 0) {
2002 dev_warn(cs
->dev
, "%s: skb_linearize failed\n", __func__
);
2003 return CAPI_MSGOSRESOURCEERR
;
2006 /* retrieve application data structure */
2007 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2009 dev_notice(cs
->dev
, "%s: application %u not registered\n",
2010 __func__
, CAPIMSG_APPID(skb
->data
));
2011 return CAPI_ILLAPPNR
;
2014 /* look up command */
2015 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2017 /* unknown/unsupported message type */
2018 if (printk_ratelimit())
2019 dev_notice(cs
->dev
, "%s: unsupported message %u\n",
2020 __func__
, CAPIMSG_CMD(skb
->data
));
2021 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL
;
2025 if (atomic_add_return(1, &iif
->sendqlen
) > 1) {
2026 /* queue behind other messages */
2027 skb_queue_tail(&iif
->sendqueue
, skb
);
2028 return CAPI_NOERROR
;
2031 /* process message */
2032 handler(iif
, ap
, skb
);
2034 /* process other messages arrived in the meantime */
2035 while (atomic_sub_return(1, &iif
->sendqlen
) > 0) {
2036 skb
= skb_dequeue(&iif
->sendqueue
);
2038 /* should never happen */
2039 dev_err(cs
->dev
, "%s: send queue empty\n", __func__
);
2042 ap
= get_appl(iif
, CAPIMSG_APPID(skb
->data
));
2044 /* could that happen? */
2045 dev_warn(cs
->dev
, "%s: application %u vanished\n",
2046 __func__
, CAPIMSG_APPID(skb
->data
));
2049 handler
= lookup_capi_send_handler(CAPIMSG_CMD(skb
->data
));
2051 /* should never happen */
2052 dev_err(cs
->dev
, "%s: handler %x vanished\n",
2053 __func__
, CAPIMSG_CMD(skb
->data
));
2056 handler(iif
, ap
, skb
);
2059 return CAPI_NOERROR
;
2063 * gigaset_procinfo() - build single line description for controller
2064 * @ctr: controller descriptor structure.
2066 * Return value: pointer to generated string (null terminated)
2068 static char *gigaset_procinfo(struct capi_ctr
*ctr
)
2070 return ctr
->name
; /* ToDo: more? */
2073 static int gigaset_proc_show(struct seq_file
*m
, void *v
)
2075 struct capi_ctr
*ctr
= m
->private;
2076 struct cardstate
*cs
= ctr
->driverdata
;
2080 seq_printf(m
, "%-16s %s\n", "name", ctr
->name
);
2081 seq_printf(m
, "%-16s %s %s\n", "dev",
2082 dev_driver_string(cs
->dev
), dev_name(cs
->dev
));
2083 seq_printf(m
, "%-16s %d\n", "id", cs
->myid
);
2085 seq_printf(m
, "%-16s %d.%d.%d.%d\n", "firmware",
2086 cs
->fwver
[0], cs
->fwver
[1], cs
->fwver
[2], cs
->fwver
[3]);
2087 seq_printf(m
, "%-16s %d\n", "channels", cs
->channels
);
2088 seq_printf(m
, "%-16s %s\n", "onechannel", cs
->onechannel
? "yes" : "no");
2106 seq_printf(m
, "%-16s %s\n", "mode", s
);
2108 switch (cs
->mstate
) {
2109 case MS_UNINITIALIZED
:
2110 s
= "uninitialized";
2130 seq_printf(m
, "%-16s %s\n", "mstate", s
);
2132 seq_printf(m
, "%-16s %s\n", "running", cs
->running
? "yes" : "no");
2133 seq_printf(m
, "%-16s %s\n", "connected", cs
->connected
? "yes" : "no");
2134 seq_printf(m
, "%-16s %s\n", "isdn_up", cs
->isdn_up
? "yes" : "no");
2135 seq_printf(m
, "%-16s %s\n", "cidmode", cs
->cidmode
? "yes" : "no");
2137 for (i
= 0; i
< cs
->channels
; i
++) {
2138 seq_printf(m
, "[%d]%-13s %d\n", i
, "corrupted",
2139 cs
->bcs
[i
].corrupted
);
2140 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_down",
2141 cs
->bcs
[i
].trans_down
);
2142 seq_printf(m
, "[%d]%-13s %d\n", i
, "trans_up",
2143 cs
->bcs
[i
].trans_up
);
2144 seq_printf(m
, "[%d]%-13s %d\n", i
, "chstate",
2145 cs
->bcs
[i
].chstate
);
2146 switch (cs
->bcs
[i
].proto2
) {
2159 seq_printf(m
, "[%d]%-13s %s\n", i
, "proto2", s
);
2164 static int gigaset_proc_open(struct inode
*inode
, struct file
*file
)
2166 return single_open(file
, gigaset_proc_show
, PDE(inode
)->data
);
2169 static const struct file_operations gigaset_proc_fops
= {
2170 .owner
= THIS_MODULE
,
2171 .open
= gigaset_proc_open
,
2173 .llseek
= seq_lseek
,
2174 .release
= single_release
,
2178 * gigaset_isdn_regdev() - register device to LL
2179 * @cs: device descriptor structure.
2180 * @isdnid: device name.
2182 * Return value: 1 for success, 0 for failure
2184 int gigaset_isdn_regdev(struct cardstate
*cs
, const char *isdnid
)
2186 struct gigaset_capi_ctr
*iif
;
2189 iif
= kmalloc(sizeof(*iif
), GFP_KERNEL
);
2191 pr_err("%s: out of memory\n", __func__
);
2195 /* prepare controller structure */
2196 iif
->ctr
.owner
= THIS_MODULE
;
2197 iif
->ctr
.driverdata
= cs
;
2198 strncpy(iif
->ctr
.name
, isdnid
, sizeof(iif
->ctr
.name
));
2199 iif
->ctr
.driver_name
= "gigaset";
2200 iif
->ctr
.load_firmware
= NULL
;
2201 iif
->ctr
.reset_ctr
= NULL
;
2202 iif
->ctr
.register_appl
= gigaset_register_appl
;
2203 iif
->ctr
.release_appl
= gigaset_release_appl
;
2204 iif
->ctr
.send_message
= gigaset_send_message
;
2205 iif
->ctr
.procinfo
= gigaset_procinfo
;
2206 iif
->ctr
.proc_fops
= &gigaset_proc_fops
;
2207 INIT_LIST_HEAD(&iif
->appls
);
2208 skb_queue_head_init(&iif
->sendqueue
);
2209 atomic_set(&iif
->sendqlen
, 0);
2211 /* register controller with CAPI */
2212 rc
= attach_capi_ctr(&iif
->ctr
);
2214 pr_err("attach_capi_ctr failed (%d)\n", rc
);
2220 cs
->hw_hdr_len
= CAPI_DATA_B3_REQ_LEN
;
2225 * gigaset_isdn_unregdev() - unregister device from LL
2226 * @cs: device descriptor structure.
2228 void gigaset_isdn_unregdev(struct cardstate
*cs
)
2230 struct gigaset_capi_ctr
*iif
= cs
->iif
;
2232 detach_capi_ctr(&iif
->ctr
);
2237 static struct capi_driver capi_driver_gigaset
= {
2243 * gigaset_isdn_regdrv() - register driver to LL
2245 void gigaset_isdn_regdrv(void)
2247 pr_info("Kernel CAPI interface\n");
2248 register_capi_driver(&capi_driver_gigaset
);
2252 * gigaset_isdn_unregdrv() - unregister driver from LL
2254 void gigaset_isdn_unregdrv(void)
2256 unregister_capi_driver(&capi_driver_gigaset
);