1
2
3
4
5
6
7
8
9
10
11
12
13
14#include "gigaset.h"
15#include <linux/proc_fs.h>
16#include <linux/seq_file.h>
17#include <linux/ratelimit.h>
18#include <linux/isdn/capilli.h>
19#include <linux/isdn/capicmd.h>
20#include <linux/isdn/capiutil.h>
21#include <linux/export.h>
22
23
24#define CapiNcpiNotSupportedByProtocol 0x0001
25#define CapiFlagsNotSupportedByProtocol 0x0002
26#define CapiAlertAlreadySent 0x0003
27#define CapiFacilitySpecificFunctionNotSupported 0x3011
28
29
30#define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN + 4 + 2 + 8 * 1)
31#define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN + 4 + 3 * 1)
32#define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN + 4 + 1)
33#define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN + 4 + 1)
34#define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN + 4 + 4 + 2 + 2 + 2 + 8)
35#define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN + 4 + 2 + 2)
36#define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN + 4 + 2)
37#define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN + 4 + 2 + 1)
38#define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN + 4 + 2 + 2 + 1)
39
40#define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN + 4 + 2)
41
42#define CAPI_FACILITY_HANDSET 0x0000
43#define CAPI_FACILITY_DTMF 0x0001
44#define CAPI_FACILITY_V42BIS 0x0002
45#define CAPI_FACILITY_SUPPSVC 0x0003
46#define CAPI_FACILITY_WAKEUP 0x0004
47#define CAPI_FACILITY_LI 0x0005
48
49#define CAPI_SUPPSVC_GETSUPPORTED 0x0000
50#define CAPI_SUPPSVC_LISTEN 0x0001
51
52
53#define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
54#define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
55#define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18)
56#define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
57#define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
58#define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
59#define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
60#define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
61
62
63#define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
64#define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
65
66
67#define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
68#define CAPI_FLAGS_RESERVED (~0x1f)
69
70
71#define MAX_BC_OCTETS 11
72#define MAX_HLC_OCTETS 3
73#define MAX_NUMBER_DIGITS 20
74#define MAX_FMT_IE_LEN 20
75
76
77#define APCONN_NONE 0
78#define APCONN_SETUP 1
79#define APCONN_ACTIVE 2
80
81
82struct gigaset_capi_appl {
83 struct list_head ctrlist;
84 struct gigaset_capi_appl *bcnext;
85 u16 id;
86 struct capi_register_params rp;
87 u16 nextMessageNumber;
88 u32 listenInfoMask;
89 u32 listenCIPmask;
90};
91
92
93struct gigaset_capi_ctr {
94 struct capi_ctr ctr;
95 struct list_head appls;
96 struct sk_buff_head sendqueue;
97 atomic_t sendqlen;
98
99 _cmsg hcmsg;
100 _cmsg acmsg;
101 u8 bc_buf[MAX_BC_OCTETS + 1];
102 u8 hlc_buf[MAX_HLC_OCTETS + 1];
103 u8 cgpty_buf[MAX_NUMBER_DIGITS + 3];
104 u8 cdpty_buf[MAX_NUMBER_DIGITS + 2];
105};
106
107
108static struct {
109 u8 *bc;
110 u8 *hlc;
111} cip2bchlc[] = {
112 [1] = { "8090A3", NULL },
113 [2] = { "8890", NULL },
114 [3] = { "8990", NULL },
115 [4] = { "9090A3", NULL },
116 [5] = { "9190", NULL },
117 [6] = { "9890", NULL },
118 [7] = { "88C0C6E6", NULL },
119 [8] = { "8890218F", NULL },
120 [9] = { "9190A5", NULL },
121
122 [16] = { "8090A3", "9181" },
123 [17] = { "9090A3", "9184" },
124 [18] = { "8890", "91A1" },
125 [19] = { "8890", "91A4" },
126
127
128 [20] = { "8890", "91A8" },
129
130 [21] = { "8890", "91B1" },
131 [22] = { "8890", "91B2" },
132
133 [23] = { "8890", "91B5" },
134 [24] = { "8890", "91B8" },
135
136 [25] = { "8890", "91C1" },
137
138 [26] = { "9190A5", "9181" },
139 [27] = { "9190A5", "916001" },
140 [28] = { "8890", "916002" },
141};
142
143
144
145
146
147
148
149
150
151static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
152 char *msgname, char *paramname)
153{
154 if (param && *param)
155 dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
156 msgname, paramname);
157}
158
159
160
161
162
163
164static int encode_ie(char *in, u8 *out, int maxlen)
165{
166 int l = 0;
167 while (*in) {
168 if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
169 return -1;
170 out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
171 in += 2;
172 }
173 out[0] = l;
174 return l;
175}
176
177
178
179
180
181static void decode_ie(u8 *in, char *out)
182{
183 int i = *in;
184 while (i-- > 0) {
185
186 *out++ = toupper(hex_asc_hi(*++in));
187 *out++ = toupper(hex_asc_lo(*in));
188 }
189}
190
191
192
193
194static inline struct gigaset_capi_appl *
195get_appl(struct gigaset_capi_ctr *iif, u16 appl)
196{
197 struct gigaset_capi_appl *ap;
198
199 list_for_each_entry(ap, &iif->appls, ctrlist)
200 if (ap->id == appl)
201 return ap;
202 return NULL;
203}
204
205
206
207
208static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
209{
210#ifdef CONFIG_GIGASET_DEBUG
211
212 static DEFINE_RATELIMIT_STATE(msg_dump_ratelimit, 20 * HZ, 20);
213 _cdebbuf *cdb;
214
215 if (!(gigaset_debuglevel & level))
216 return;
217 if (!___ratelimit(&msg_dump_ratelimit, tag))
218 return;
219
220 cdb = capi_cmsg2str(p);
221 if (cdb) {
222 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
223 cdebbuf_free(cdb);
224 } else {
225 gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
226 capi_cmd2str(p->Command, p->Subcommand));
227 }
228#endif
229}
230
231static inline void dump_rawmsg(enum debuglevel level, const char *tag,
232 unsigned char *data)
233{
234#ifdef CONFIG_GIGASET_DEBUG
235 char *dbgline;
236 int i, l;
237
238 if (!(gigaset_debuglevel & level))
239 return;
240
241 l = CAPIMSG_LEN(data);
242 if (l < 12) {
243 gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
244 return;
245 }
246 gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
247 tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
248 CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
249 CAPIMSG_CONTROL(data));
250 l -= 12;
251 if (l <= 0)
252 return;
253 dbgline = kmalloc(3 * l, GFP_ATOMIC);
254 if (!dbgline)
255 return;
256 for (i = 0; i < l; i++) {
257 dbgline[3 * i] = hex_asc_hi(data[12 + i]);
258 dbgline[3 * i + 1] = hex_asc_lo(data[12 + i]);
259 dbgline[3 * i + 2] = ' ';
260 }
261 dbgline[3 * l - 1] = '\0';
262 gig_dbg(level, " %s", dbgline);
263 kfree(dbgline);
264 if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
265 (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
266 CAPIMSG_SUBCOMMAND(data) == CAPI_IND)) {
267 l = CAPIMSG_DATALEN(data);
268 gig_dbg(level, " DataLength=%d", l);
269 if (l <= 0 || !(gigaset_debuglevel & DEBUG_LLDATA))
270 return;
271 if (l > 64)
272 l = 64;
273 dbgline = kmalloc(3 * l, GFP_ATOMIC);
274 if (!dbgline)
275 return;
276 data += CAPIMSG_LEN(data);
277 for (i = 0; i < l; i++) {
278 dbgline[3 * i] = hex_asc_hi(data[i]);
279 dbgline[3 * i + 1] = hex_asc_lo(data[i]);
280 dbgline[3 * i + 2] = ' ';
281 }
282 dbgline[3 * l - 1] = '\0';
283 gig_dbg(level, " %s", dbgline);
284 kfree(dbgline);
285 }
286#endif
287}
288
289
290
291
292
293#ifdef CONFIG_GIGASET_DEBUG
294static const char *format_ie(const char *ie)
295{
296 static char result[3 * MAX_FMT_IE_LEN];
297 int len, count;
298 char *pout = result;
299
300 if (!ie)
301 return "NULL";
302
303 count = len = ie[0];
304 if (count > MAX_FMT_IE_LEN)
305 count = MAX_FMT_IE_LEN - 1;
306 while (count--) {
307 *pout++ = hex_asc_hi(*++ie);
308 *pout++ = hex_asc_lo(*ie);
309 *pout++ = ' ';
310 }
311 if (len > MAX_FMT_IE_LEN) {
312 *pout++ = '.';
313 *pout++ = '.';
314 *pout++ = '.';
315 }
316 *--pout = 0;
317 return result;
318}
319#endif
320
321
322
323
324static void send_data_b3_conf(struct cardstate *cs, struct capi_ctr *ctr,
325 u16 appl, u16 msgid, int channel,
326 u16 handle, u16 info)
327{
328 struct sk_buff *cskb;
329 u8 *msg;
330
331 cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
332 if (!cskb) {
333 dev_err(cs->dev, "%s: out of memory\n", __func__);
334 return;
335 }
336
337 msg = __skb_put(cskb, CAPI_DATA_B3_CONF_LEN);
338 CAPIMSG_SETLEN(msg, CAPI_DATA_B3_CONF_LEN);
339 CAPIMSG_SETAPPID(msg, appl);
340 CAPIMSG_SETCOMMAND(msg, CAPI_DATA_B3);
341 CAPIMSG_SETSUBCOMMAND(msg, CAPI_CONF);
342 CAPIMSG_SETMSGID(msg, msgid);
343 CAPIMSG_SETCONTROLLER(msg, ctr->cnr);
344 CAPIMSG_SETPLCI_PART(msg, channel);
345 CAPIMSG_SETNCCI_PART(msg, 1);
346 CAPIMSG_SETHANDLE_CONF(msg, handle);
347 CAPIMSG_SETINFO_CONF(msg, info);
348
349
350 dump_rawmsg(DEBUG_MCMD, __func__, msg);
351 capi_ctr_handle_message(ctr, appl, cskb);
352}
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
369{
370 struct cardstate *cs = bcs->cs;
371 struct gigaset_capi_ctr *iif = cs->iif;
372 struct gigaset_capi_appl *ap = bcs->ap;
373 unsigned char *req = skb_mac_header(dskb);
374 u16 flags;
375
376
377 ++bcs->trans_up;
378
379 if (!ap) {
380 gig_dbg(DEBUG_MCMD, "%s: application gone", __func__);
381 return;
382 }
383
384
385 if (bcs->apconnstate < APCONN_ACTIVE) {
386 gig_dbg(DEBUG_MCMD, "%s: disconnected", __func__);
387 return;
388 }
389
390
391
392
393
394 flags = CAPIMSG_FLAGS(req);
395 if (flags & CAPI_FLAGS_DELIVERY_CONFIRMATION)
396 send_data_b3_conf(cs, &iif->ctr, ap->id, CAPIMSG_MSGID(req),
397 bcs->channel + 1, CAPIMSG_HANDLE_REQ(req),
398 (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION) ?
399 CapiFlagsNotSupportedByProtocol :
400 CAPI_NOERROR);
401}
402EXPORT_SYMBOL_GPL(gigaset_skb_sent);
403
404
405
406
407
408
409
410
411
412
413void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
414{
415 struct cardstate *cs = bcs->cs;
416 struct gigaset_capi_ctr *iif = cs->iif;
417 struct gigaset_capi_appl *ap = bcs->ap;
418 int len = skb->len;
419
420
421 bcs->trans_down++;
422
423 if (!ap) {
424 gig_dbg(DEBUG_MCMD, "%s: application gone", __func__);
425 dev_kfree_skb_any(skb);
426 return;
427 }
428
429
430 if (bcs->apconnstate < APCONN_ACTIVE) {
431 gig_dbg(DEBUG_MCMD, "%s: disconnected", __func__);
432 dev_kfree_skb_any(skb);
433 return;
434 }
435
436
437
438
439
440
441 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
442 CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
443 CAPIMSG_SETAPPID(skb->data, ap->id);
444 CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
445 CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
446 CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
447 CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
448 CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
449 CAPIMSG_SETNCCI_PART(skb->data, 1);
450
451 CAPIMSG_SETDATALEN(skb->data, len);
452
453 CAPIMSG_SETFLAGS(skb->data, 0);
454
455
456
457 dump_rawmsg(DEBUG_MCMD, __func__, skb->data);
458 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
459}
460EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
461
462
463
464
465
466
467
468
469void gigaset_isdn_rcv_err(struct bc_state *bcs)
470{
471
472 if (bcs->ignore) {
473 bcs->ignore--;
474 return;
475 }
476
477
478 bcs->corrupted++;
479
480
481}
482EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
483
484
485
486
487
488
489
490
491
492
493int gigaset_isdn_icall(struct at_state_t *at_state)
494{
495 struct cardstate *cs = at_state->cs;
496 struct bc_state *bcs = at_state->bcs;
497 struct gigaset_capi_ctr *iif = cs->iif;
498 struct gigaset_capi_appl *ap;
499 u32 actCIPmask;
500 struct sk_buff *skb;
501 unsigned int msgsize;
502 unsigned long flags;
503 int i;
504
505
506
507
508
509
510
511 if (!bcs)
512 return ICALL_IGNORE;
513
514
515 capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
516 iif->ctr.cnr | ((bcs->channel + 1) << 8));
517
518
519 msgsize = CAPI_CONNECT_IND_BASELEN;
520
521
522 if (at_state->str_var[STR_ZBC]) {
523
524 if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
525 MAX_BC_OCTETS) < 0) {
526 dev_warn(cs->dev, "RING ignored - bad BC %s\n",
527 at_state->str_var[STR_ZBC]);
528 return ICALL_IGNORE;
529 }
530
531
532 iif->hcmsg.CIPValue = 0;
533 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
534 if (cip2bchlc[i].bc != NULL &&
535 cip2bchlc[i].hlc == NULL &&
536 !strcmp(cip2bchlc[i].bc,
537 at_state->str_var[STR_ZBC])) {
538 iif->hcmsg.CIPValue = i;
539 break;
540 }
541 } else {
542
543 iif->hcmsg.CIPValue = 1;
544 encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
545 }
546 iif->hcmsg.BC = iif->bc_buf;
547 msgsize += iif->hcmsg.BC[0];
548
549
550 if (at_state->str_var[STR_ZHLC]) {
551
552 if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
553 MAX_HLC_OCTETS) < 0) {
554 dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
555 at_state->str_var[STR_ZHLC]);
556 return ICALL_IGNORE;
557 }
558 iif->hcmsg.HLC = iif->hlc_buf;
559 msgsize += iif->hcmsg.HLC[0];
560
561
562
563 if (at_state->str_var[STR_ZBC])
564 for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
565 if (cip2bchlc[i].hlc != NULL &&
566 !strcmp(cip2bchlc[i].hlc,
567 at_state->str_var[STR_ZHLC]) &&
568 !strcmp(cip2bchlc[i].bc,
569 at_state->str_var[STR_ZBC])) {
570 iif->hcmsg.CIPValue = i;
571 break;
572 }
573 }
574
575
576 if (at_state->str_var[STR_ZCPN]) {
577 i = strlen(at_state->str_var[STR_ZCPN]);
578 if (i > MAX_NUMBER_DIGITS) {
579 dev_warn(cs->dev, "RING ignored - bad number %s\n",
580 at_state->str_var[STR_ZBC]);
581 return ICALL_IGNORE;
582 }
583 iif->cdpty_buf[0] = i + 1;
584 iif->cdpty_buf[1] = 0x80;
585 memcpy(iif->cdpty_buf + 2, at_state->str_var[STR_ZCPN], i);
586 iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
587 msgsize += iif->hcmsg.CalledPartyNumber[0];
588 }
589
590
591 if (at_state->str_var[STR_NMBR]) {
592 i = strlen(at_state->str_var[STR_NMBR]);
593 if (i > MAX_NUMBER_DIGITS) {
594 dev_warn(cs->dev, "RING ignored - bad number %s\n",
595 at_state->str_var[STR_ZBC]);
596 return ICALL_IGNORE;
597 }
598 iif->cgpty_buf[0] = i + 2;
599 iif->cgpty_buf[1] = 0x00;
600 iif->cgpty_buf[2] = 0x80;
601 memcpy(iif->cgpty_buf + 3, at_state->str_var[STR_NMBR], i);
602 iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
603 msgsize += iif->hcmsg.CallingPartyNumber[0];
604 }
605
606
607
608
609
610
611
612
613
614
615
616 gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
617 iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
618 format_ie(iif->hcmsg.BC));
619 gig_dbg(DEBUG_CMD, "icall: HLC %s",
620 format_ie(iif->hcmsg.HLC));
621 gig_dbg(DEBUG_CMD, "icall: CgPty %s",
622 format_ie(iif->hcmsg.CallingPartyNumber));
623 gig_dbg(DEBUG_CMD, "icall: CdPty %s",
624 format_ie(iif->hcmsg.CalledPartyNumber));
625
626
627 spin_lock_irqsave(&bcs->aplock, flags);
628 if (bcs->ap != NULL || bcs->apconnstate != APCONN_NONE) {
629 dev_warn(cs->dev, "%s: channel not properly cleared (%p/%d)\n",
630 __func__, bcs->ap, bcs->apconnstate);
631 bcs->ap = NULL;
632 bcs->apconnstate = APCONN_NONE;
633 }
634 spin_unlock_irqrestore(&bcs->aplock, flags);
635 actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
636 list_for_each_entry(ap, &iif->appls, ctrlist)
637 if (actCIPmask & ap->listenCIPmask) {
638
639 iif->hcmsg.ApplId = ap->id;
640 iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
641
642 skb = alloc_skb(msgsize, GFP_ATOMIC);
643 if (!skb) {
644 dev_err(cs->dev, "%s: out of memory\n",
645 __func__);
646 break;
647 }
648 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
649 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
650
651
652 spin_lock_irqsave(&bcs->aplock, flags);
653 ap->bcnext = bcs->ap;
654 bcs->ap = ap;
655 bcs->chstate |= CHS_NOTIFY_LL;
656 bcs->apconnstate = APCONN_SETUP;
657 spin_unlock_irqrestore(&bcs->aplock, flags);
658
659
660 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
661 }
662
663
664
665
666
667
668 return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
669}
670
671
672
673
674
675static void send_disconnect_ind(struct bc_state *bcs,
676 struct gigaset_capi_appl *ap, u16 reason)
677{
678 struct cardstate *cs = bcs->cs;
679 struct gigaset_capi_ctr *iif = cs->iif;
680 struct sk_buff *skb;
681
682 if (bcs->apconnstate == APCONN_NONE)
683 return;
684
685 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
686 ap->nextMessageNumber++,
687 iif->ctr.cnr | ((bcs->channel + 1) << 8));
688 iif->hcmsg.Reason = reason;
689 skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
690 if (!skb) {
691 dev_err(cs->dev, "%s: out of memory\n", __func__);
692 return;
693 }
694 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
695 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
696 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
697}
698
699
700
701
702
703
704static void send_disconnect_b3_ind(struct bc_state *bcs,
705 struct gigaset_capi_appl *ap)
706{
707 struct cardstate *cs = bcs->cs;
708 struct gigaset_capi_ctr *iif = cs->iif;
709 struct sk_buff *skb;
710
711
712 if (bcs->apconnstate < APCONN_ACTIVE)
713 return;
714 bcs->apconnstate = APCONN_SETUP;
715
716 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
717 ap->nextMessageNumber++,
718 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
719 skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
720 if (!skb) {
721 dev_err(cs->dev, "%s: out of memory\n", __func__);
722 return;
723 }
724 capi_cmsg2message(&iif->hcmsg,
725 __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
726 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
727 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
728}
729
730
731
732
733
734
735
736
737void gigaset_isdn_connD(struct bc_state *bcs)
738{
739 struct cardstate *cs = bcs->cs;
740 struct gigaset_capi_ctr *iif = cs->iif;
741 struct gigaset_capi_appl *ap;
742 struct sk_buff *skb;
743 unsigned int msgsize;
744 unsigned long flags;
745
746 spin_lock_irqsave(&bcs->aplock, flags);
747 ap = bcs->ap;
748 if (!ap) {
749 spin_unlock_irqrestore(&bcs->aplock, flags);
750 gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
751 return;
752 }
753 if (bcs->apconnstate == APCONN_NONE) {
754 spin_unlock_irqrestore(&bcs->aplock, flags);
755 dev_warn(cs->dev, "%s: application %u not connected\n",
756 __func__, ap->id);
757 return;
758 }
759 spin_unlock_irqrestore(&bcs->aplock, flags);
760 while (ap->bcnext) {
761
762 dev_warn(cs->dev, "%s: dropping extra application %u\n",
763 __func__, ap->bcnext->id);
764 send_disconnect_ind(bcs, ap->bcnext,
765 CapiCallGivenToOtherApplication);
766 ap->bcnext = ap->bcnext->bcnext;
767 }
768
769
770
771
772 capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
773 ap->nextMessageNumber++,
774 iif->ctr.cnr | ((bcs->channel + 1) << 8));
775
776
777 msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
778
779
780
781
782
783
784
785 skb = alloc_skb(msgsize, GFP_ATOMIC);
786 if (!skb) {
787 dev_err(cs->dev, "%s: out of memory\n", __func__);
788 return;
789 }
790 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
791 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
792 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
793}
794
795
796
797
798
799
800
801
802void gigaset_isdn_hupD(struct bc_state *bcs)
803{
804 struct gigaset_capi_appl *ap;
805 unsigned long flags;
806
807
808
809
810
811
812 spin_lock_irqsave(&bcs->aplock, flags);
813 while (bcs->ap != NULL) {
814 ap = bcs->ap;
815 bcs->ap = ap->bcnext;
816 spin_unlock_irqrestore(&bcs->aplock, flags);
817 send_disconnect_b3_ind(bcs, ap);
818 send_disconnect_ind(bcs, ap, 0);
819 spin_lock_irqsave(&bcs->aplock, flags);
820 }
821 bcs->apconnstate = APCONN_NONE;
822 spin_unlock_irqrestore(&bcs->aplock, flags);
823}
824
825
826
827
828
829
830
831
832void gigaset_isdn_connB(struct bc_state *bcs)
833{
834 struct cardstate *cs = bcs->cs;
835 struct gigaset_capi_ctr *iif = cs->iif;
836 struct gigaset_capi_appl *ap;
837 struct sk_buff *skb;
838 unsigned long flags;
839 unsigned int msgsize;
840 u8 command;
841
842 spin_lock_irqsave(&bcs->aplock, flags);
843 ap = bcs->ap;
844 if (!ap) {
845 spin_unlock_irqrestore(&bcs->aplock, flags);
846 gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
847 return;
848 }
849 if (!bcs->apconnstate) {
850 spin_unlock_irqrestore(&bcs->aplock, flags);
851 dev_warn(cs->dev, "%s: application %u not connected\n",
852 __func__, ap->id);
853 return;
854 }
855
856
857
858
859
860
861
862 if (bcs->apconnstate >= APCONN_ACTIVE) {
863 command = CAPI_CONNECT_B3_ACTIVE;
864 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
865 } else {
866 command = CAPI_CONNECT_B3;
867 msgsize = CAPI_CONNECT_B3_IND_BASELEN;
868 }
869 bcs->apconnstate = APCONN_ACTIVE;
870
871 spin_unlock_irqrestore(&bcs->aplock, flags);
872
873 while (ap->bcnext) {
874
875 dev_warn(cs->dev, "%s: dropping extra application %u\n",
876 __func__, ap->bcnext->id);
877 send_disconnect_ind(bcs, ap->bcnext,
878 CapiCallGivenToOtherApplication);
879 ap->bcnext = ap->bcnext->bcnext;
880 }
881
882 capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
883 ap->nextMessageNumber++,
884 iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
885 skb = alloc_skb(msgsize, GFP_ATOMIC);
886 if (!skb) {
887 dev_err(cs->dev, "%s: out of memory\n", __func__);
888 return;
889 }
890 capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
891 dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
892 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
893}
894
895
896
897
898
899
900
901
902void gigaset_isdn_hupB(struct bc_state *bcs)
903{
904 struct gigaset_capi_appl *ap = bcs->ap;
905
906
907
908 if (!ap) {
909 gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
910 return;
911 }
912
913 send_disconnect_b3_ind(bcs, ap);
914}
915
916
917
918
919
920
921
922
923void gigaset_isdn_start(struct cardstate *cs)
924{
925 struct gigaset_capi_ctr *iif = cs->iif;
926
927
928 strcpy(iif->ctr.manu, "Siemens");
929
930 iif->ctr.version.majorversion = 2;
931 iif->ctr.version.minorversion = 0;
932
933 iif->ctr.version.majormanuversion = cs->fwver[0];
934 iif->ctr.version.minormanuversion = cs->fwver[1];
935
936 iif->ctr.profile.nbchannel = cs->channels;
937
938 iif->ctr.profile.goptions = 0x11;
939
940 iif->ctr.profile.support1 = 0x03;
941
942
943 iif->ctr.profile.support2 = 0x02;
944
945 iif->ctr.profile.support3 = 0x01;
946
947 strcpy(iif->ctr.serial, "0");
948 capi_ctr_ready(&iif->ctr);
949}
950
951
952
953
954
955
956
957
958void gigaset_isdn_stop(struct cardstate *cs)
959{
960 struct gigaset_capi_ctr *iif = cs->iif;
961 capi_ctr_down(&iif->ctr);
962}
963
964
965
966
967
968
969
970
971
972static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
973 capi_register_params *rp)
974{
975 struct gigaset_capi_ctr *iif
976 = container_of(ctr, struct gigaset_capi_ctr, ctr);
977 struct cardstate *cs = ctr->driverdata;
978 struct gigaset_capi_appl *ap;
979
980 gig_dbg(DEBUG_CMD, "%s [%u] l3cnt=%u blkcnt=%u blklen=%u",
981 __func__, appl, rp->level3cnt, rp->datablkcnt, rp->datablklen);
982
983 list_for_each_entry(ap, &iif->appls, ctrlist)
984 if (ap->id == appl) {
985 dev_notice(cs->dev,
986 "application %u already registered\n", appl);
987 return;
988 }
989
990 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
991 if (!ap) {
992 dev_err(cs->dev, "%s: out of memory\n", __func__);
993 return;
994 }
995 ap->id = appl;
996 ap->rp = *rp;
997
998 list_add(&ap->ctrlist, &iif->appls);
999 dev_info(cs->dev, "application %u registered\n", ap->id);
1000}
1001
1002
1003
1004
1005
1006
1007static inline void remove_appl_from_channel(struct bc_state *bcs,
1008 struct gigaset_capi_appl *ap)
1009{
1010 struct cardstate *cs = bcs->cs;
1011 struct gigaset_capi_appl *bcap;
1012 unsigned long flags;
1013 int prevconnstate;
1014
1015 spin_lock_irqsave(&bcs->aplock, flags);
1016 bcap = bcs->ap;
1017 if (bcap == NULL) {
1018 spin_unlock_irqrestore(&bcs->aplock, flags);
1019 return;
1020 }
1021
1022
1023 if (bcap == ap) {
1024 bcs->ap = ap->bcnext;
1025 if (bcs->ap != NULL) {
1026 spin_unlock_irqrestore(&bcs->aplock, flags);
1027 return;
1028 }
1029
1030
1031 prevconnstate = bcs->apconnstate;
1032 bcs->apconnstate = APCONN_NONE;
1033 spin_unlock_irqrestore(&bcs->aplock, flags);
1034
1035 if (prevconnstate == APCONN_ACTIVE) {
1036 dev_notice(cs->dev, "%s: hanging up channel %u\n",
1037 __func__, bcs->channel);
1038 gigaset_add_event(cs, &bcs->at_state,
1039 EV_HUP, NULL, 0, NULL);
1040 gigaset_schedule_event(cs);
1041 }
1042 return;
1043 }
1044
1045
1046 do {
1047 if (bcap->bcnext == ap) {
1048 bcap->bcnext = bcap->bcnext->bcnext;
1049 spin_unlock_irqrestore(&bcs->aplock, flags);
1050 return;
1051 }
1052 bcap = bcap->bcnext;
1053 } while (bcap != NULL);
1054 spin_unlock_irqrestore(&bcs->aplock, flags);
1055}
1056
1057
1058
1059
1060static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
1061{
1062 struct gigaset_capi_ctr *iif
1063 = container_of(ctr, struct gigaset_capi_ctr, ctr);
1064 struct cardstate *cs = iif->ctr.driverdata;
1065 struct gigaset_capi_appl *ap, *tmp;
1066 unsigned ch;
1067
1068 gig_dbg(DEBUG_CMD, "%s [%u]", __func__, appl);
1069
1070 list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
1071 if (ap->id == appl) {
1072
1073 for (ch = 0; ch < cs->channels; ch++)
1074 remove_appl_from_channel(&cs->bcs[ch], ap);
1075
1076
1077 list_del(&ap->ctrlist);
1078 kfree(ap);
1079 dev_info(cs->dev, "application %u released\n", appl);
1080 }
1081}
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092static void send_conf(struct gigaset_capi_ctr *iif,
1093 struct gigaset_capi_appl *ap,
1094 struct sk_buff *skb,
1095 u16 info)
1096{
1097
1098
1099
1100
1101 capi_cmsg_answer(&iif->acmsg);
1102 iif->acmsg.Info = info;
1103 capi_cmsg2message(&iif->acmsg, skb->data);
1104 __skb_trim(skb, CAPI_STDCONF_LEN);
1105 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1106 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1107}
1108
1109
1110
1111
1112static void do_facility_req(struct gigaset_capi_ctr *iif,
1113 struct gigaset_capi_appl *ap,
1114 struct sk_buff *skb)
1115{
1116 struct cardstate *cs = iif->ctr.driverdata;
1117 _cmsg *cmsg = &iif->acmsg;
1118 struct sk_buff *cskb;
1119 u8 *pparam;
1120 unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
1121 u16 function, info;
1122 static u8 confparam[10];
1123
1124
1125 capi_message2cmsg(cmsg, skb->data);
1126 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1127
1128
1129
1130
1131
1132 switch (cmsg->FacilitySelector) {
1133 case CAPI_FACILITY_DTMF:
1134 info = CapiFacilityNotSupported;
1135 confparam[0] = 2;
1136
1137 capimsg_setu16(confparam, 1, 2);
1138 break;
1139
1140 case CAPI_FACILITY_V42BIS:
1141 info = CapiFacilityNotSupported;
1142 confparam[0] = 2;
1143
1144 capimsg_setu16(confparam, 1, 1);
1145 break;
1146
1147 case CAPI_FACILITY_SUPPSVC:
1148
1149 pparam = cmsg->FacilityRequestParameter;
1150 if (pparam == NULL || pparam[0] < 2) {
1151 dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
1152 "Facility Request Parameter");
1153 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
1154 return;
1155 }
1156 function = CAPIMSG_U16(pparam, 1);
1157 switch (function) {
1158 case CAPI_SUPPSVC_GETSUPPORTED:
1159 info = CapiSuccess;
1160
1161 confparam[3] = 6;
1162
1163 capimsg_setu16(confparam, 4, CapiSuccess);
1164
1165 capimsg_setu32(confparam, 6, 0);
1166 break;
1167 case CAPI_SUPPSVC_LISTEN:
1168 if (pparam[0] < 7 || pparam[3] < 4) {
1169 dev_notice(cs->dev, "%s: %s missing\n",
1170 "FACILITY_REQ", "Notification Mask");
1171 send_conf(iif, ap, skb,
1172 CapiIllMessageParmCoding);
1173 return;
1174 }
1175 if (CAPIMSG_U32(pparam, 4) != 0) {
1176 dev_notice(cs->dev,
1177 "%s: unsupported supplementary service notification mask 0x%x\n",
1178 "FACILITY_REQ", CAPIMSG_U32(pparam, 4));
1179 info = CapiFacilitySpecificFunctionNotSupported;
1180 confparam[3] = 2;
1181 capimsg_setu16(confparam, 4,
1182 CapiSupplementaryServiceNotSupported);
1183 }
1184 info = CapiSuccess;
1185 confparam[3] = 2;
1186 capimsg_setu16(confparam, 4, CapiSuccess);
1187 break;
1188
1189
1190
1191 default:
1192 dev_notice(cs->dev,
1193 "%s: unsupported supplementary service function 0x%04x\n",
1194 "FACILITY_REQ", function);
1195 info = CapiFacilitySpecificFunctionNotSupported;
1196
1197 confparam[3] = 2;
1198
1199 capimsg_setu16(confparam, 4,
1200 CapiSupplementaryServiceNotSupported);
1201 }
1202
1203
1204 confparam[0] = confparam[3] + 3;
1205
1206 capimsg_setu16(confparam, 1, function);
1207
1208 break;
1209
1210 case CAPI_FACILITY_WAKEUP:
1211 info = CapiFacilityNotSupported;
1212 confparam[0] = 2;
1213
1214 capimsg_setu16(confparam, 1, 0);
1215 break;
1216
1217 default:
1218 info = CapiFacilityNotSupported;
1219 confparam[0] = 0;
1220 }
1221
1222
1223 capi_cmsg_answer(cmsg);
1224 cmsg->Info = info;
1225 cmsg->FacilityConfirmationParameter = confparam;
1226 msgsize += confparam[0];
1227 cskb = alloc_skb(msgsize, GFP_ATOMIC);
1228 if (!cskb) {
1229 dev_err(cs->dev, "%s: out of memory\n", __func__);
1230 return;
1231 }
1232 capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
1233 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1234 capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
1235}
1236
1237
1238
1239
1240
1241
1242static void do_listen_req(struct gigaset_capi_ctr *iif,
1243 struct gigaset_capi_appl *ap,
1244 struct sk_buff *skb)
1245{
1246
1247 capi_message2cmsg(&iif->acmsg, skb->data);
1248 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1249
1250
1251 ap->listenInfoMask = iif->acmsg.InfoMask;
1252 ap->listenCIPmask = iif->acmsg.CIPmask;
1253 send_conf(iif, ap, skb, CapiSuccess);
1254}
1255
1256
1257
1258
1259
1260static void do_alert_req(struct gigaset_capi_ctr *iif,
1261 struct gigaset_capi_appl *ap,
1262 struct sk_buff *skb)
1263{
1264
1265 capi_message2cmsg(&iif->acmsg, skb->data);
1266 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
1267 send_conf(iif, ap, skb, CapiAlertAlreadySent);
1268}
1269
1270
1271
1272
1273
1274
1275static void do_connect_req(struct gigaset_capi_ctr *iif,
1276 struct gigaset_capi_appl *ap,
1277 struct sk_buff *skb)
1278{
1279 struct cardstate *cs = iif->ctr.driverdata;
1280 _cmsg *cmsg = &iif->acmsg;
1281 struct bc_state *bcs;
1282 char **commands;
1283 char *s;
1284 u8 *pp;
1285 unsigned long flags;
1286 int i, l, lbc, lhlc;
1287 u16 info;
1288
1289
1290 capi_message2cmsg(cmsg, skb->data);
1291 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1292
1293
1294 bcs = gigaset_get_free_channel(cs);
1295 if (!bcs) {
1296 dev_notice(cs->dev, "%s: no B channel available\n",
1297 "CONNECT_REQ");
1298 send_conf(iif, ap, skb, CapiNoPlciAvailable);
1299 return;
1300 }
1301 spin_lock_irqsave(&bcs->aplock, flags);
1302 if (bcs->ap != NULL || bcs->apconnstate != APCONN_NONE)
1303 dev_warn(cs->dev, "%s: channel not properly cleared (%p/%d)\n",
1304 __func__, bcs->ap, bcs->apconnstate);
1305 ap->bcnext = NULL;
1306 bcs->ap = ap;
1307 bcs->apconnstate = APCONN_SETUP;
1308 spin_unlock_irqrestore(&bcs->aplock, flags);
1309
1310 bcs->rx_bufsize = ap->rp.datablklen;
1311 dev_kfree_skb(bcs->rx_skb);
1312 gigaset_new_rx_skb(bcs);
1313 cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
1314
1315
1316 commands = kzalloc(AT_NUM * (sizeof *commands), GFP_KERNEL);
1317 if (!commands)
1318 goto oom;
1319
1320
1321 pp = cmsg->CalledPartyNumber;
1322 if (pp == NULL || *pp == 0) {
1323 dev_notice(cs->dev, "%s: %s missing\n",
1324 "CONNECT_REQ", "Called party number");
1325 info = CapiIllMessageParmCoding;
1326 goto error;
1327 }
1328 l = *pp++;
1329
1330 switch (*pp) {
1331 case 0x80:
1332 case 0x81:
1333 break;
1334 default:
1335 dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
1336 "CONNECT_REQ", "Called party number", *pp);
1337 }
1338 pp++;
1339 l--;
1340
1341 if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
1342 s = "^SCTP=0\r";
1343 pp += 2;
1344 l -= 2;
1345 } else {
1346 s = "^SCTP=1\r";
1347 }
1348 commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
1349 if (!commands[AT_TYPE])
1350 goto oom;
1351 commands[AT_DIAL] = kmalloc(l + 3, GFP_KERNEL);
1352 if (!commands[AT_DIAL])
1353 goto oom;
1354 snprintf(commands[AT_DIAL], l + 3, "D%.*s\r", l, pp);
1355
1356
1357 pp = cmsg->CallingPartyNumber;
1358 if (pp != NULL && *pp > 0) {
1359 l = *pp++;
1360
1361
1362
1363 switch (*pp) {
1364 case 0x00:
1365 case 0x01:
1366 break;
1367 default:
1368 dev_notice(cs->dev,
1369 "%s: %s type/plan 0x%02x unsupported\n",
1370 "CONNECT_REQ", "Calling party number", *pp);
1371 }
1372 pp++;
1373 l--;
1374
1375
1376 if (!l) {
1377 dev_notice(cs->dev, "%s: %s IE truncated\n",
1378 "CONNECT_REQ", "Calling party number");
1379 info = CapiIllMessageParmCoding;
1380 goto error;
1381 }
1382 switch (*pp & 0xfc) {
1383 case 0x80:
1384 s = "^SCLIP=1\r";
1385 break;
1386 case 0xa0:
1387 s = "^SCLIP=0\r";
1388 break;
1389 default:
1390 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1391 "CONNECT_REQ",
1392 "Presentation/Screening indicator",
1393 *pp);
1394 s = "^SCLIP=1\r";
1395 }
1396 commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
1397 if (!commands[AT_CLIP])
1398 goto oom;
1399 pp++;
1400 l--;
1401
1402 if (l) {
1403
1404 commands[AT_MSN] = kmalloc(l + 8, GFP_KERNEL);
1405 if (!commands[AT_MSN])
1406 goto oom;
1407 snprintf(commands[AT_MSN], l + 8, "^SMSN=%*s\r", l, pp);
1408 }
1409 }
1410
1411
1412 if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
1413 (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
1414 dev_notice(cs->dev, "%s: unknown CIP value %d\n",
1415 "CONNECT_REQ", cmsg->CIPValue);
1416 info = CapiCipValueUnknown;
1417 goto error;
1418 }
1419
1420
1421
1422
1423
1424
1425
1426
1427 if (cmsg->BC && cmsg->BC[0])
1428 lbc = 2 * cmsg->BC[0];
1429 else if (cip2bchlc[cmsg->CIPValue].bc)
1430 lbc = strlen(cip2bchlc[cmsg->CIPValue].bc);
1431 else
1432 lbc = 0;
1433 if (cmsg->HLC && cmsg->HLC[0])
1434 lhlc = 2 * cmsg->HLC[0];
1435 else if (cip2bchlc[cmsg->CIPValue].hlc)
1436 lhlc = strlen(cip2bchlc[cmsg->CIPValue].hlc);
1437 else
1438 lhlc = 0;
1439
1440 if (lbc) {
1441
1442 l = lbc + 7;
1443 if (lhlc)
1444 l += lhlc + 7;
1445 commands[AT_BC] = kmalloc(l, GFP_KERNEL);
1446 if (!commands[AT_BC])
1447 goto oom;
1448 strcpy(commands[AT_BC], "^SBC=");
1449 if (cmsg->BC && cmsg->BC[0])
1450 decode_ie(cmsg->BC, commands[AT_BC] + 5);
1451 else
1452 strcpy(commands[AT_BC] + 5,
1453 cip2bchlc[cmsg->CIPValue].bc);
1454 if (lhlc) {
1455 strcpy(commands[AT_BC] + lbc + 5, ";^SHLC=");
1456 if (cmsg->HLC && cmsg->HLC[0])
1457
1458 decode_ie(cmsg->HLC,
1459 commands[AT_BC] + lbc + 12);
1460 else
1461 strcpy(commands[AT_BC] + lbc + 12,
1462 cip2bchlc[cmsg->CIPValue].hlc);
1463 }
1464 strcpy(commands[AT_BC] + l - 2, "\r");
1465 } else {
1466
1467 if (lhlc) {
1468 dev_notice(cs->dev, "%s: cannot set HLC without BC\n",
1469 "CONNECT_REQ");
1470 info = CapiIllMessageParmCoding;
1471 goto error;
1472 }
1473 }
1474
1475
1476 if (cmsg->BProtocol == CAPI_DEFAULT) {
1477 bcs->proto2 = L2_HDLC;
1478 dev_warn(cs->dev,
1479 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1480 } else {
1481 switch (cmsg->B1protocol) {
1482 case 0:
1483 bcs->proto2 = L2_HDLC;
1484 break;
1485 case 1:
1486 bcs->proto2 = L2_VOICE;
1487 break;
1488 default:
1489 dev_warn(cs->dev,
1490 "B1 Protocol %u unsupported, using Transparent\n",
1491 cmsg->B1protocol);
1492 bcs->proto2 = L2_VOICE;
1493 }
1494 if (cmsg->B2protocol != 1)
1495 dev_warn(cs->dev,
1496 "B2 Protocol %u unsupported, using Transparent\n",
1497 cmsg->B2protocol);
1498 if (cmsg->B3protocol != 0)
1499 dev_warn(cs->dev,
1500 "B3 Protocol %u unsupported, using Transparent\n",
1501 cmsg->B3protocol);
1502 ignore_cstruct_param(cs, cmsg->B1configuration,
1503 "CONNECT_REQ", "B1 Configuration");
1504 ignore_cstruct_param(cs, cmsg->B2configuration,
1505 "CONNECT_REQ", "B2 Configuration");
1506 ignore_cstruct_param(cs, cmsg->B3configuration,
1507 "CONNECT_REQ", "B3 Configuration");
1508 }
1509 commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
1510 if (!commands[AT_PROTO])
1511 goto oom;
1512 snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
1513
1514
1515 ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
1516 "CONNECT_REQ", "Called pty subaddr");
1517 ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
1518 "CONNECT_REQ", "Calling pty subaddr");
1519 ignore_cstruct_param(cs, cmsg->LLC,
1520 "CONNECT_REQ", "LLC");
1521 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1522 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1523 "CONNECT_REQ", "B Channel Information");
1524 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1525 "CONNECT_REQ", "Keypad Facility");
1526 ignore_cstruct_param(cs, cmsg->Useruserdata,
1527 "CONNECT_REQ", "User-User Data");
1528 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1529 "CONNECT_REQ", "Facility Data Array");
1530 }
1531
1532
1533 commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
1534 if (!commands[AT_ISO])
1535 goto oom;
1536 snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
1537 (unsigned) bcs->channel + 1);
1538
1539
1540 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
1541 bcs->at_state.seq_index, NULL)) {
1542 info = CAPI_MSGOSRESOURCEERR;
1543 goto error;
1544 }
1545 gigaset_schedule_event(cs);
1546 send_conf(iif, ap, skb, CapiSuccess);
1547 return;
1548
1549oom:
1550 dev_err(cs->dev, "%s: out of memory\n", __func__);
1551 info = CAPI_MSGOSRESOURCEERR;
1552error:
1553 if (commands)
1554 for (i = 0; i < AT_NUM; i++)
1555 kfree(commands[i]);
1556 kfree(commands);
1557 gigaset_free_channel(bcs);
1558 send_conf(iif, ap, skb, info);
1559}
1560
1561
1562
1563
1564
1565static void do_connect_resp(struct gigaset_capi_ctr *iif,
1566 struct gigaset_capi_appl *ap,
1567 struct sk_buff *skb)
1568{
1569 struct cardstate *cs = iif->ctr.driverdata;
1570 _cmsg *cmsg = &iif->acmsg;
1571 struct bc_state *bcs;
1572 struct gigaset_capi_appl *oap;
1573 unsigned long flags;
1574 int channel;
1575
1576
1577 capi_message2cmsg(cmsg, skb->data);
1578 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1579 dev_kfree_skb_any(skb);
1580
1581
1582 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1583 if (!channel || channel > cs->channels) {
1584 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1585 "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
1586 return;
1587 }
1588 bcs = cs->bcs + channel - 1;
1589
1590 switch (cmsg->Reject) {
1591 case 0:
1592
1593 spin_lock_irqsave(&bcs->aplock, flags);
1594 while (bcs->ap != NULL) {
1595 oap = bcs->ap;
1596 bcs->ap = oap->bcnext;
1597 if (oap != ap) {
1598 spin_unlock_irqrestore(&bcs->aplock, flags);
1599 send_disconnect_ind(bcs, oap,
1600 CapiCallGivenToOtherApplication);
1601 spin_lock_irqsave(&bcs->aplock, flags);
1602 }
1603 }
1604 ap->bcnext = NULL;
1605 bcs->ap = ap;
1606 spin_unlock_irqrestore(&bcs->aplock, flags);
1607
1608 bcs->rx_bufsize = ap->rp.datablklen;
1609 dev_kfree_skb(bcs->rx_skb);
1610 gigaset_new_rx_skb(bcs);
1611 bcs->chstate |= CHS_NOTIFY_LL;
1612
1613
1614 if (cmsg->BProtocol == CAPI_DEFAULT) {
1615 bcs->proto2 = L2_HDLC;
1616 dev_warn(cs->dev,
1617 "B2 Protocol X.75 SLP unsupported, using Transparent\n");
1618 } else {
1619 switch (cmsg->B1protocol) {
1620 case 0:
1621 bcs->proto2 = L2_HDLC;
1622 break;
1623 case 1:
1624 bcs->proto2 = L2_VOICE;
1625 break;
1626 default:
1627 dev_warn(cs->dev,
1628 "B1 Protocol %u unsupported, using Transparent\n",
1629 cmsg->B1protocol);
1630 bcs->proto2 = L2_VOICE;
1631 }
1632 if (cmsg->B2protocol != 1)
1633 dev_warn(cs->dev,
1634 "B2 Protocol %u unsupported, using Transparent\n",
1635 cmsg->B2protocol);
1636 if (cmsg->B3protocol != 0)
1637 dev_warn(cs->dev,
1638 "B3 Protocol %u unsupported, using Transparent\n",
1639 cmsg->B3protocol);
1640 ignore_cstruct_param(cs, cmsg->B1configuration,
1641 "CONNECT_RESP", "B1 Configuration");
1642 ignore_cstruct_param(cs, cmsg->B2configuration,
1643 "CONNECT_RESP", "B2 Configuration");
1644 ignore_cstruct_param(cs, cmsg->B3configuration,
1645 "CONNECT_RESP", "B3 Configuration");
1646 }
1647
1648
1649 ignore_cstruct_param(cs, cmsg->ConnectedNumber,
1650 "CONNECT_RESP", "Connected Number");
1651 ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
1652 "CONNECT_RESP", "Connected Subaddress");
1653 ignore_cstruct_param(cs, cmsg->LLC,
1654 "CONNECT_RESP", "LLC");
1655 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1656 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1657 "CONNECT_RESP", "BChannel Information");
1658 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1659 "CONNECT_RESP", "Keypad Facility");
1660 ignore_cstruct_param(cs, cmsg->Useruserdata,
1661 "CONNECT_RESP", "User-User Data");
1662 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1663 "CONNECT_RESP", "Facility Data Array");
1664 }
1665
1666
1667 if (!gigaset_add_event(cs, &cs->bcs[channel - 1].at_state,
1668 EV_ACCEPT, NULL, 0, NULL))
1669 return;
1670 gigaset_schedule_event(cs);
1671 return;
1672
1673 case 1:
1674
1675 send_disconnect_ind(bcs, ap, 0);
1676
1677
1678 spin_lock_irqsave(&bcs->aplock, flags);
1679 if (bcs->ap == ap) {
1680 bcs->ap = ap->bcnext;
1681 if (bcs->ap == NULL) {
1682
1683 bcs->apconnstate = APCONN_NONE;
1684 bcs->chstate &= ~CHS_NOTIFY_LL;
1685 }
1686 spin_unlock_irqrestore(&bcs->aplock, flags);
1687 return;
1688 }
1689 for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
1690 if (oap->bcnext == ap) {
1691 oap->bcnext = oap->bcnext->bcnext;
1692 spin_unlock_irqrestore(&bcs->aplock, flags);
1693 return;
1694 }
1695 }
1696 spin_unlock_irqrestore(&bcs->aplock, flags);
1697 dev_err(cs->dev, "%s: application %u not found\n",
1698 __func__, ap->id);
1699 return;
1700
1701 default:
1702
1703 spin_lock_irqsave(&bcs->aplock, flags);
1704 while (bcs->ap != NULL) {
1705 oap = bcs->ap;
1706 bcs->ap = oap->bcnext;
1707 if (oap != ap) {
1708 spin_unlock_irqrestore(&bcs->aplock, flags);
1709 send_disconnect_ind(bcs, oap,
1710 CapiCallGivenToOtherApplication);
1711 spin_lock_irqsave(&bcs->aplock, flags);
1712 }
1713 }
1714 ap->bcnext = NULL;
1715 bcs->ap = ap;
1716 spin_unlock_irqrestore(&bcs->aplock, flags);
1717
1718
1719 dev_info(cs->dev, "%s: Reject=%x\n",
1720 "CONNECT_RESP", cmsg->Reject);
1721 if (!gigaset_add_event(cs, &cs->bcs[channel - 1].at_state,
1722 EV_HUP, NULL, 0, NULL))
1723 return;
1724 gigaset_schedule_event(cs);
1725 return;
1726 }
1727}
1728
1729
1730
1731
1732
1733static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
1734 struct gigaset_capi_appl *ap,
1735 struct sk_buff *skb)
1736{
1737 struct cardstate *cs = iif->ctr.driverdata;
1738 _cmsg *cmsg = &iif->acmsg;
1739 struct bc_state *bcs;
1740 int channel;
1741
1742
1743 capi_message2cmsg(cmsg, skb->data);
1744 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1745
1746
1747 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1748 if (!channel || channel > cs->channels) {
1749 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1750 "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
1751 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1752 return;
1753 }
1754 bcs = &cs->bcs[channel - 1];
1755
1756
1757 bcs->apconnstate = APCONN_ACTIVE;
1758
1759
1760 cmsg->adr.adrNCCI |= 1 << 16;
1761
1762
1763 ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
1764 send_conf(iif, ap, skb,
1765 (cmsg->NCPI && cmsg->NCPI[0]) ?
1766 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1767}
1768
1769
1770
1771
1772
1773
1774
1775
1776static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
1777 struct gigaset_capi_appl *ap,
1778 struct sk_buff *skb)
1779{
1780 struct cardstate *cs = iif->ctr.driverdata;
1781 _cmsg *cmsg = &iif->acmsg;
1782 struct bc_state *bcs;
1783 int channel;
1784 unsigned int msgsize;
1785 u8 command;
1786
1787
1788 capi_message2cmsg(cmsg, skb->data);
1789 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1790
1791
1792 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1793 if (!channel || channel > cs->channels ||
1794 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1795 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1796 "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
1797 dev_kfree_skb_any(skb);
1798 return;
1799 }
1800 bcs = &cs->bcs[channel - 1];
1801
1802 if (cmsg->Reject) {
1803
1804 bcs->apconnstate = APCONN_SETUP;
1805
1806
1807 if (!gigaset_add_event(cs, &bcs->at_state,
1808 EV_HUP, NULL, 0, NULL)) {
1809 dev_kfree_skb_any(skb);
1810 return;
1811 }
1812 gigaset_schedule_event(cs);
1813
1814
1815 command = CAPI_DISCONNECT_B3;
1816 msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
1817 } else {
1818
1819
1820
1821
1822 command = CAPI_CONNECT_B3_ACTIVE;
1823 msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
1824 }
1825 capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
1826 ap->nextMessageNumber++, cmsg->adr.adrNCCI);
1827 __skb_trim(skb, msgsize);
1828 capi_cmsg2message(cmsg, skb->data);
1829 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1830 capi_ctr_handle_message(&iif->ctr, ap->id, skb);
1831}
1832
1833
1834
1835
1836
1837
1838static void do_disconnect_req(struct gigaset_capi_ctr *iif,
1839 struct gigaset_capi_appl *ap,
1840 struct sk_buff *skb)
1841{
1842 struct cardstate *cs = iif->ctr.driverdata;
1843 _cmsg *cmsg = &iif->acmsg;
1844 struct bc_state *bcs;
1845 _cmsg *b3cmsg;
1846 struct sk_buff *b3skb;
1847 int channel;
1848
1849
1850 capi_message2cmsg(cmsg, skb->data);
1851 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1852
1853
1854 channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
1855 if (!channel || channel > cs->channels) {
1856 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1857 "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
1858 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1859 return;
1860 }
1861 bcs = cs->bcs + channel - 1;
1862
1863
1864 if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
1865 ignore_cstruct_param(cs, cmsg->BChannelinformation,
1866 "DISCONNECT_REQ", "B Channel Information");
1867 ignore_cstruct_param(cs, cmsg->Keypadfacility,
1868 "DISCONNECT_REQ", "Keypad Facility");
1869 ignore_cstruct_param(cs, cmsg->Useruserdata,
1870 "DISCONNECT_REQ", "User-User Data");
1871 ignore_cstruct_param(cs, cmsg->Facilitydataarray,
1872 "DISCONNECT_REQ", "Facility Data Array");
1873 }
1874
1875
1876 if (!bcs->apconnstate)
1877 return;
1878
1879
1880 if (bcs->apconnstate >= APCONN_ACTIVE) {
1881
1882 bcs->apconnstate = APCONN_SETUP;
1883
1884
1885
1886
1887
1888
1889 b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
1890 if (!b3cmsg) {
1891 dev_err(cs->dev, "%s: out of memory\n", __func__);
1892 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1893 return;
1894 }
1895 capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
1896 ap->nextMessageNumber++,
1897 cmsg->adr.adrPLCI | (1 << 16));
1898 b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
1899 b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
1900 if (b3skb == NULL) {
1901 dev_err(cs->dev, "%s: out of memory\n", __func__);
1902 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1903 kfree(b3cmsg);
1904 return;
1905 }
1906 capi_cmsg2message(b3cmsg,
1907 __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
1908 dump_cmsg(DEBUG_CMD, __func__, b3cmsg);
1909 kfree(b3cmsg);
1910 capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
1911 }
1912
1913
1914 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1915 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1916 return;
1917 }
1918 gigaset_schedule_event(cs);
1919
1920
1921 send_conf(iif, ap, skb, CapiSuccess);
1922}
1923
1924
1925
1926
1927
1928static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
1929 struct gigaset_capi_appl *ap,
1930 struct sk_buff *skb)
1931{
1932 struct cardstate *cs = iif->ctr.driverdata;
1933 _cmsg *cmsg = &iif->acmsg;
1934 struct bc_state *bcs;
1935 int channel;
1936
1937
1938 capi_message2cmsg(cmsg, skb->data);
1939 dump_cmsg(DEBUG_CMD, __func__, cmsg);
1940
1941
1942 channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
1943 if (!channel || channel > cs->channels ||
1944 ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
1945 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1946 "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
1947 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1948 return;
1949 }
1950 bcs = &cs->bcs[channel - 1];
1951
1952
1953 if (bcs->apconnstate < APCONN_ACTIVE) {
1954 send_conf(iif, ap, skb,
1955 CapiMessageNotSupportedInCurrentState);
1956 return;
1957 }
1958
1959
1960 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
1961 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
1962 return;
1963 }
1964 gigaset_schedule_event(cs);
1965
1966
1967 ignore_cstruct_param(cs, cmsg->NCPI,
1968 "DISCONNECT_B3_REQ", "NCPI");
1969 send_conf(iif, ap, skb,
1970 (cmsg->NCPI && cmsg->NCPI[0]) ?
1971 CapiNcpiNotSupportedByProtocol : CapiSuccess);
1972}
1973
1974
1975
1976
1977static void do_data_b3_req(struct gigaset_capi_ctr *iif,
1978 struct gigaset_capi_appl *ap,
1979 struct sk_buff *skb)
1980{
1981 struct cardstate *cs = iif->ctr.driverdata;
1982 struct bc_state *bcs;
1983 int channel = CAPIMSG_PLCI_PART(skb->data);
1984 u16 ncci = CAPIMSG_NCCI_PART(skb->data);
1985 u16 msglen = CAPIMSG_LEN(skb->data);
1986 u16 datalen = CAPIMSG_DATALEN(skb->data);
1987 u16 flags = CAPIMSG_FLAGS(skb->data);
1988 u16 msgid = CAPIMSG_MSGID(skb->data);
1989 u16 handle = CAPIMSG_HANDLE_REQ(skb->data);
1990
1991
1992 dump_rawmsg(DEBUG_MCMD, __func__, skb->data);
1993
1994
1995 if (channel == 0 || channel > cs->channels || ncci != 1) {
1996 dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
1997 "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
1998 send_conf(iif, ap, skb, CapiIllContrPlciNcci);
1999 return;
2000 }
2001 bcs = &cs->bcs[channel - 1];
2002 if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
2003 dev_notice(cs->dev, "%s: unexpected length %d\n",
2004 "DATA_B3_REQ", msglen);
2005 if (msglen + datalen != skb->len)
2006 dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
2007 "DATA_B3_REQ", msglen, datalen, skb->len);
2008 if (msglen + datalen > skb->len) {
2009
2010 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
2011 return;
2012 }
2013 if (flags & CAPI_FLAGS_RESERVED) {
2014 dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
2015 "DATA_B3_REQ", flags);
2016 send_conf(iif, ap, skb, CapiIllMessageParmCoding);
2017 return;
2018 }
2019
2020
2021 if (bcs->apconnstate < APCONN_ACTIVE) {
2022 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
2023 return;
2024 }
2025
2026
2027 skb_reset_mac_header(skb);
2028 skb->mac_len = msglen;
2029 skb_pull(skb, msglen);
2030
2031
2032 if (cs->ops->send_skb(bcs, skb) < 0) {
2033 send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
2034 return;
2035 }
2036
2037
2038
2039
2040
2041 if (!(flags & CAPI_FLAGS_DELIVERY_CONFIRMATION))
2042 send_data_b3_conf(cs, &iif->ctr, ap->id, msgid, channel, handle,
2043 flags ? CapiFlagsNotSupportedByProtocol
2044 : CAPI_NOERROR);
2045}
2046
2047
2048
2049
2050
2051static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
2052 struct gigaset_capi_appl *ap,
2053 struct sk_buff *skb)
2054{
2055
2056 capi_message2cmsg(&iif->acmsg, skb->data);
2057 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
2058 send_conf(iif, ap, skb,
2059 CapiResetProcedureNotSupportedByCurrentProtocol);
2060}
2061
2062
2063
2064
2065static void do_unsupported(struct gigaset_capi_ctr *iif,
2066 struct gigaset_capi_appl *ap,
2067 struct sk_buff *skb)
2068{
2069
2070 capi_message2cmsg(&iif->acmsg, skb->data);
2071 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
2072 send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
2073}
2074
2075
2076
2077
2078static void do_nothing(struct gigaset_capi_ctr *iif,
2079 struct gigaset_capi_appl *ap,
2080 struct sk_buff *skb)
2081{
2082
2083 capi_message2cmsg(&iif->acmsg, skb->data);
2084 dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
2085 dev_kfree_skb_any(skb);
2086}
2087
2088static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
2089 struct gigaset_capi_appl *ap,
2090 struct sk_buff *skb)
2091{
2092 dump_rawmsg(DEBUG_MCMD, __func__, skb->data);
2093 dev_kfree_skb_any(skb);
2094}
2095
2096
2097typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
2098 struct gigaset_capi_appl *,
2099 struct sk_buff *);
2100
2101static struct {
2102 u16 cmd;
2103 capi_send_handler_t handler;
2104} capi_send_handler_table[] = {
2105
2106 { CAPI_DATA_B3_REQ, do_data_b3_req },
2107 { CAPI_DATA_B3_RESP, do_data_b3_resp },
2108
2109 { CAPI_ALERT_REQ, do_alert_req },
2110 { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
2111 { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
2112 { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
2113 { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
2114 { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
2115 { CAPI_CONNECT_REQ, do_connect_req },
2116 { CAPI_CONNECT_RESP, do_connect_resp },
2117 { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
2118 { CAPI_DISCONNECT_B3_RESP, do_nothing },
2119 { CAPI_DISCONNECT_REQ, do_disconnect_req },
2120 { CAPI_DISCONNECT_RESP, do_nothing },
2121 { CAPI_FACILITY_REQ, do_facility_req },
2122 { CAPI_FACILITY_RESP, do_nothing },
2123 { CAPI_LISTEN_REQ, do_listen_req },
2124 { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
2125 { CAPI_RESET_B3_REQ, do_reset_b3_req },
2126 { CAPI_RESET_B3_RESP, do_nothing },
2127
2128
2129
2130
2131
2132 { CAPI_INFO_REQ, do_unsupported },
2133 { CAPI_INFO_RESP, do_nothing },
2134
2135
2136
2137
2138 { CAPI_MANUFACTURER_REQ, do_nothing },
2139 { CAPI_MANUFACTURER_RESP, do_nothing },
2140};
2141
2142
2143static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
2144{
2145 size_t i;
2146
2147 for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
2148 if (capi_send_handler_table[i].cmd == cmd)
2149 return capi_send_handler_table[i].handler;
2150 return NULL;
2151}
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
2164{
2165 struct gigaset_capi_ctr *iif
2166 = container_of(ctr, struct gigaset_capi_ctr, ctr);
2167 struct cardstate *cs = ctr->driverdata;
2168 struct gigaset_capi_appl *ap;
2169 capi_send_handler_t handler;
2170
2171
2172 if (skb_linearize(skb) < 0) {
2173 dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
2174 return CAPI_MSGOSRESOURCEERR;
2175 }
2176
2177
2178 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2179 if (!ap) {
2180 dev_notice(cs->dev, "%s: application %u not registered\n",
2181 __func__, CAPIMSG_APPID(skb->data));
2182 return CAPI_ILLAPPNR;
2183 }
2184
2185
2186 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2187 if (!handler) {
2188
2189 if (printk_ratelimit())
2190 dev_notice(cs->dev, "%s: unsupported message %u\n",
2191 __func__, CAPIMSG_CMD(skb->data));
2192 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
2193 }
2194
2195
2196 if (atomic_add_return(1, &iif->sendqlen) > 1) {
2197
2198 skb_queue_tail(&iif->sendqueue, skb);
2199 return CAPI_NOERROR;
2200 }
2201
2202
2203 handler(iif, ap, skb);
2204
2205
2206 while (atomic_sub_return(1, &iif->sendqlen) > 0) {
2207 skb = skb_dequeue(&iif->sendqueue);
2208 if (!skb) {
2209
2210 dev_err(cs->dev, "%s: send queue empty\n", __func__);
2211 continue;
2212 }
2213 ap = get_appl(iif, CAPIMSG_APPID(skb->data));
2214 if (!ap) {
2215
2216 dev_warn(cs->dev, "%s: application %u vanished\n",
2217 __func__, CAPIMSG_APPID(skb->data));
2218 continue;
2219 }
2220 handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
2221 if (!handler) {
2222
2223 dev_err(cs->dev, "%s: handler %x vanished\n",
2224 __func__, CAPIMSG_CMD(skb->data));
2225 continue;
2226 }
2227 handler(iif, ap, skb);
2228 }
2229
2230 return CAPI_NOERROR;
2231}
2232
2233
2234
2235
2236
2237
2238
2239static char *gigaset_procinfo(struct capi_ctr *ctr)
2240{
2241 return ctr->name;
2242}
2243
2244static int gigaset_proc_show(struct seq_file *m, void *v)
2245{
2246 struct capi_ctr *ctr = m->private;
2247 struct cardstate *cs = ctr->driverdata;
2248 char *s;
2249 int i;
2250
2251 seq_printf(m, "%-16s %s\n", "name", ctr->name);
2252 seq_printf(m, "%-16s %s %s\n", "dev",
2253 dev_driver_string(cs->dev), dev_name(cs->dev));
2254 seq_printf(m, "%-16s %d\n", "id", cs->myid);
2255 if (cs->gotfwver)
2256 seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
2257 cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
2258 seq_printf(m, "%-16s %d\n", "channels", cs->channels);
2259 seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
2260
2261 switch (cs->mode) {
2262 case M_UNKNOWN:
2263 s = "unknown";
2264 break;
2265 case M_CONFIG:
2266 s = "config";
2267 break;
2268 case M_UNIMODEM:
2269 s = "Unimodem";
2270 break;
2271 case M_CID:
2272 s = "CID";
2273 break;
2274 default:
2275 s = "??";
2276 }
2277 seq_printf(m, "%-16s %s\n", "mode", s);
2278
2279 switch (cs->mstate) {
2280 case MS_UNINITIALIZED:
2281 s = "uninitialized";
2282 break;
2283 case MS_INIT:
2284 s = "init";
2285 break;
2286 case MS_LOCKED:
2287 s = "locked";
2288 break;
2289 case MS_SHUTDOWN:
2290 s = "shutdown";
2291 break;
2292 case MS_RECOVER:
2293 s = "recover";
2294 break;
2295 case MS_READY:
2296 s = "ready";
2297 break;
2298 default:
2299 s = "??";
2300 }
2301 seq_printf(m, "%-16s %s\n", "mstate", s);
2302
2303 seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
2304 seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
2305 seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
2306 seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
2307
2308 for (i = 0; i < cs->channels; i++) {
2309 seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
2310 cs->bcs[i].corrupted);
2311 seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
2312 cs->bcs[i].trans_down);
2313 seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
2314 cs->bcs[i].trans_up);
2315 seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
2316 cs->bcs[i].chstate);
2317 switch (cs->bcs[i].proto2) {
2318 case L2_BITSYNC:
2319 s = "bitsync";
2320 break;
2321 case L2_HDLC:
2322 s = "HDLC";
2323 break;
2324 case L2_VOICE:
2325 s = "voice";
2326 break;
2327 default:
2328 s = "??";
2329 }
2330 seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
2331 }
2332 return 0;
2333}
2334
2335static int gigaset_proc_open(struct inode *inode, struct file *file)
2336{
2337 return single_open(file, gigaset_proc_show, PDE_DATA(inode));
2338}
2339
2340static const struct file_operations gigaset_proc_fops = {
2341 .owner = THIS_MODULE,
2342 .open = gigaset_proc_open,
2343 .read = seq_read,
2344 .llseek = seq_lseek,
2345 .release = single_release,
2346};
2347
2348
2349
2350
2351
2352
2353
2354
2355int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
2356{
2357 struct gigaset_capi_ctr *iif;
2358 int rc;
2359
2360 iif = kmalloc(sizeof(*iif), GFP_KERNEL);
2361 if (!iif) {
2362 pr_err("%s: out of memory\n", __func__);
2363 return -ENOMEM;
2364 }
2365
2366
2367 iif->ctr.owner = THIS_MODULE;
2368 iif->ctr.driverdata = cs;
2369 strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
2370 iif->ctr.driver_name = "gigaset";
2371 iif->ctr.load_firmware = NULL;
2372 iif->ctr.reset_ctr = NULL;
2373 iif->ctr.register_appl = gigaset_register_appl;
2374 iif->ctr.release_appl = gigaset_release_appl;
2375 iif->ctr.send_message = gigaset_send_message;
2376 iif->ctr.procinfo = gigaset_procinfo;
2377 iif->ctr.proc_fops = &gigaset_proc_fops;
2378 INIT_LIST_HEAD(&iif->appls);
2379 skb_queue_head_init(&iif->sendqueue);
2380 atomic_set(&iif->sendqlen, 0);
2381
2382
2383 rc = attach_capi_ctr(&iif->ctr);
2384 if (rc) {
2385 pr_err("attach_capi_ctr failed (%d)\n", rc);
2386 kfree(iif);
2387 return rc;
2388 }
2389
2390 cs->iif = iif;
2391 cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
2392 return 0;
2393}
2394
2395
2396
2397
2398
2399void gigaset_isdn_unregdev(struct cardstate *cs)
2400{
2401 struct gigaset_capi_ctr *iif = cs->iif;
2402
2403 detach_capi_ctr(&iif->ctr);
2404 kfree(iif);
2405 cs->iif = NULL;
2406}
2407
2408static struct capi_driver capi_driver_gigaset = {
2409 .name = "gigaset",
2410 .revision = "1.0",
2411};
2412
2413
2414
2415
2416void gigaset_isdn_regdrv(void)
2417{
2418 pr_info("Kernel CAPI interface\n");
2419 register_capi_driver(&capi_driver_gigaset);
2420}
2421
2422
2423
2424
2425void gigaset_isdn_unregdrv(void)
2426{
2427 unregister_capi_driver(&capi_driver_gigaset);
2428}
2429