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