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