Commit | Line | Data |
---|---|---|
3c66a225 HL |
1 | /* |
2 | * Stuff used by all variants of the driver | |
3 | * | |
70440cf2 TS |
4 | * Copyright (c) 2001 by Stefan Eilers, |
5 | * Hansjoerg Lipp <hjlipp@web.de>, | |
6 | * Tilman Schmidt <tilman@imap.cc>. | |
3c66a225 HL |
7 | * |
8 | * ===================================================================== | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License as | |
11 | * published by the Free Software Foundation; either version 2 of | |
12 | * the License, or (at your option) any later version. | |
13 | * ===================================================================== | |
3c66a225 HL |
14 | */ |
15 | ||
16 | #include "gigaset.h" | |
088ec0cc | 17 | #include <linux/isdnif.h> |
5a0e3ad6 | 18 | #include <linux/slab.h> |
088ec0cc TS |
19 | |
20 | #define HW_HDR_LEN 2 /* Header size used to store ack info */ | |
3c66a225 | 21 | |
784d5858 | 22 | /* == Handling of I4L IO =====================================================*/ |
3c66a225 HL |
23 | |
24 | /* writebuf_from_LL | |
25 | * called by LL to transmit data on an open channel | |
26 | * inserts the buffer data into the send queue and starts the transmission | |
27 | * Note that this operation must not sleep! | |
28 | * When the buffer is processed completely, gigaset_skb_sent() should be called. | |
29 | * parameters: | |
30 | * driverID driver ID as assigned by LL | |
31 | * channel channel number | |
917f5085 TS |
32 | * ack if != 0 LL wants to be notified on completion via |
33 | * statcallb(ISDN_STAT_BSENT) | |
3c66a225 HL |
34 | * skb skb containing data to send |
35 | * return value: | |
36 | * number of accepted bytes | |
37 | * 0 if temporarily unable to accept data (out of buffer space) | |
38 | * <0 on error (eg. -EINVAL) | |
39 | */ | |
784d5858 TS |
40 | static int writebuf_from_LL(int driverID, int channel, int ack, |
41 | struct sk_buff *skb) | |
3c66a225 | 42 | { |
d9ba9c91 | 43 | struct cardstate *cs = gigaset_get_cs_by_id(driverID); |
3c66a225 | 44 | struct bc_state *bcs; |
4dd8230a | 45 | unsigned char *ack_header; |
3c66a225 | 46 | unsigned len; |
3c66a225 | 47 | |
d9ba9c91 | 48 | if (!cs) { |
c8770dca | 49 | pr_err("%s: invalid driver ID (%d)\n", __func__, driverID); |
3c66a225 HL |
50 | return -ENODEV; |
51 | } | |
52 | if (channel < 0 || channel >= cs->channels) { | |
5002779d TS |
53 | dev_err(cs->dev, "%s: invalid channel ID (%d)\n", |
54 | __func__, channel); | |
3c66a225 HL |
55 | return -ENODEV; |
56 | } | |
57 | bcs = &cs->bcs[channel]; | |
ee239d99 TS |
58 | |
59 | /* can only handle linear sk_buffs */ | |
60 | if (skb_linearize(skb) < 0) { | |
61 | dev_err(cs->dev, "%s: skb_linearize failed\n", __func__); | |
62 | return -ENOMEM; | |
63 | } | |
3c66a225 HL |
64 | len = skb->len; |
65 | ||
784d5858 TS |
66 | gig_dbg(DEBUG_LLDATA, |
67 | "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)", | |
68 | driverID, channel, ack, len); | |
69 | ||
3c66a225 HL |
70 | if (!len) { |
71 | if (ack) | |
5002779d TS |
72 | dev_notice(cs->dev, "%s: not ACKing empty packet\n", |
73 | __func__); | |
3c66a225 HL |
74 | return 0; |
75 | } | |
76 | if (len > MAX_BUF_SIZE) { | |
5002779d TS |
77 | dev_err(cs->dev, "%s: packet too large (%d bytes)\n", |
78 | __func__, len); | |
3c66a225 HL |
79 | return -EINVAL; |
80 | } | |
81 | ||
4dd8230a TS |
82 | /* set up acknowledgement header */ |
83 | if (skb_headroom(skb) < HW_HDR_LEN) { | |
84 | /* should never happen */ | |
85 | dev_err(cs->dev, "%s: insufficient skb headroom\n", __func__); | |
86 | return -ENOMEM; | |
87 | } | |
88 | skb_set_mac_header(skb, -HW_HDR_LEN); | |
89 | skb->mac_len = HW_HDR_LEN; | |
90 | ack_header = skb_mac_header(skb); | |
91 | if (ack) { | |
92 | ack_header[0] = len & 0xff; | |
93 | ack_header[1] = len >> 8; | |
94 | } else { | |
95 | ack_header[0] = ack_header[1] = 0; | |
96 | } | |
97 | gig_dbg(DEBUG_MCMD, "skb: len=%u, ack=%d: %02x %02x", | |
98 | len, ack, ack_header[0], ack_header[1]); | |
3c66a225 HL |
99 | |
100 | /* pass to device-specific module */ | |
73a88814 | 101 | return cs->ops->send_skb(bcs, skb); |
3c66a225 HL |
102 | } |
103 | ||
1cec9727 TS |
104 | /** |
105 | * gigaset_skb_sent() - acknowledge sending an skb | |
106 | * @bcs: B channel descriptor structure. | |
107 | * @skb: sent data. | |
108 | * | |
109 | * Called by hardware module {bas,ser,usb}_gigaset when the data in a | |
110 | * skb has been successfully sent, for signalling completion to the LL. | |
111 | */ | |
3c66a225 HL |
112 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) |
113 | { | |
088ec0cc | 114 | isdn_if *iif = bcs->cs->iif; |
4dd8230a | 115 | unsigned char *ack_header = skb_mac_header(skb); |
3c66a225 HL |
116 | unsigned len; |
117 | isdn_ctrl response; | |
118 | ||
119 | ++bcs->trans_up; | |
120 | ||
121 | if (skb->len) | |
784d5858 TS |
122 | dev_warn(bcs->cs->dev, "%s: skb->len==%d\n", |
123 | __func__, skb->len); | |
3c66a225 | 124 | |
4dd8230a | 125 | len = ack_header[0] + ((unsigned) ack_header[1] << 8); |
3c66a225 | 126 | if (len) { |
784d5858 TS |
127 | gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)", |
128 | bcs->cs->myid, bcs->channel, len); | |
3c66a225 HL |
129 | |
130 | response.driver = bcs->cs->myid; | |
131 | response.command = ISDN_STAT_BSENT; | |
132 | response.arg = bcs->channel; | |
133 | response.parm.length = len; | |
088ec0cc | 134 | iif->statcallb(&response); |
3c66a225 HL |
135 | } |
136 | } | |
137 | EXPORT_SYMBOL_GPL(gigaset_skb_sent); | |
138 | ||
088ec0cc TS |
139 | /** |
140 | * gigaset_skb_rcvd() - pass received skb to LL | |
141 | * @bcs: B channel descriptor structure. | |
142 | * @skb: received data. | |
143 | * | |
144 | * Called by hardware module {bas,ser,usb}_gigaset when user data has | |
145 | * been successfully received, for passing to the LL. | |
146 | * Warning: skb must not be accessed anymore! | |
147 | */ | |
148 | void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb) | |
149 | { | |
150 | isdn_if *iif = bcs->cs->iif; | |
151 | ||
152 | iif->rcvcallb_skb(bcs->cs->myid, bcs->channel, skb); | |
153 | bcs->trans_down++; | |
154 | } | |
155 | EXPORT_SYMBOL_GPL(gigaset_skb_rcvd); | |
156 | ||
157 | /** | |
158 | * gigaset_isdn_rcv_err() - signal receive error | |
159 | * @bcs: B channel descriptor structure. | |
160 | * | |
161 | * Called by hardware module {bas,ser,usb}_gigaset when a receive error | |
162 | * has occurred, for signalling to the LL. | |
163 | */ | |
164 | void gigaset_isdn_rcv_err(struct bc_state *bcs) | |
165 | { | |
166 | isdn_if *iif = bcs->cs->iif; | |
167 | isdn_ctrl response; | |
168 | ||
169 | /* if currently ignoring packets, just count down */ | |
170 | if (bcs->ignore) { | |
171 | bcs->ignore--; | |
172 | return; | |
173 | } | |
174 | ||
175 | /* update statistics */ | |
176 | bcs->corrupted++; | |
177 | ||
178 | /* error -> LL */ | |
179 | gig_dbg(DEBUG_CMD, "sending L1ERR"); | |
180 | response.driver = bcs->cs->myid; | |
181 | response.command = ISDN_STAT_L1ERR; | |
182 | response.arg = bcs->channel; | |
183 | response.parm.errcode = ISDN_STAT_L1ERR_RECV; | |
184 | iif->statcallb(&response); | |
185 | } | |
186 | EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err); | |
187 | ||
3c66a225 HL |
188 | /* This function will be called by LL to send commands |
189 | * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL, | |
190 | * so don't put too much effort into it. | |
191 | */ | |
192 | static int command_from_LL(isdn_ctrl *cntrl) | |
193 | { | |
088ec0cc | 194 | struct cardstate *cs; |
3c66a225 HL |
195 | struct bc_state *bcs; |
196 | int retval = 0; | |
088ec0cc TS |
197 | char **commands; |
198 | int ch; | |
199 | int i; | |
200 | size_t l; | |
3c66a225 | 201 | |
3c66a225 HL |
202 | gigaset_debugdrivers(); |
203 | ||
088ec0cc TS |
204 | gig_dbg(DEBUG_CMD, "driver: %d, command: %d, arg: 0x%lx", |
205 | cntrl->driver, cntrl->command, cntrl->arg); | |
206 | ||
207 | cs = gigaset_get_cs_by_id(cntrl->driver); | |
208 | if (cs == NULL) { | |
c8770dca | 209 | pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver); |
3c66a225 HL |
210 | return -ENODEV; |
211 | } | |
088ec0cc | 212 | ch = cntrl->arg & 0xff; |
3c66a225 HL |
213 | |
214 | switch (cntrl->command) { | |
215 | case ISDN_CMD_IOCTL: | |
5002779d | 216 | dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n"); |
3c66a225 HL |
217 | return -EINVAL; |
218 | ||
219 | case ISDN_CMD_DIAL: | |
1528b18f | 220 | gig_dbg(DEBUG_CMD, |
088ec0cc | 221 | "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)", |
784d5858 TS |
222 | cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, |
223 | cntrl->parm.setup.si1, cntrl->parm.setup.si2); | |
3c66a225 | 224 | |
088ec0cc | 225 | if (ch >= cs->channels) { |
5002779d | 226 | dev_err(cs->dev, |
088ec0cc | 227 | "ISDN_CMD_DIAL: invalid channel (%d)\n", ch); |
3c66a225 HL |
228 | return -EINVAL; |
229 | } | |
088ec0cc | 230 | bcs = cs->bcs + ch; |
3c66a225 | 231 | if (!gigaset_get_channel(bcs)) { |
5002779d | 232 | dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n"); |
3c66a225 HL |
233 | return -EBUSY; |
234 | } | |
235 | ||
088ec0cc TS |
236 | commands = kzalloc(AT_NUM*(sizeof *commands), GFP_ATOMIC); |
237 | if (!commands) { | |
3c66a225 | 238 | gigaset_free_channel(bcs); |
5002779d | 239 | dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n"); |
3c66a225 HL |
240 | return -ENOMEM; |
241 | } | |
3c66a225 | 242 | |
088ec0cc TS |
243 | l = 3 + strlen(cntrl->parm.setup.phone); |
244 | commands[AT_DIAL] = kmalloc(l, GFP_ATOMIC); | |
245 | if (!commands[AT_DIAL]) | |
246 | goto oom; | |
247 | if (cntrl->parm.setup.phone[0] == '*' && | |
248 | cntrl->parm.setup.phone[1] == '*') { | |
249 | /* internal call: translate ** prefix to CTP value */ | |
250 | commands[AT_TYPE] = kstrdup("^SCTP=0\r", GFP_ATOMIC); | |
251 | if (!commands[AT_TYPE]) | |
252 | goto oom; | |
253 | snprintf(commands[AT_DIAL], l, | |
254 | "D%s\r", cntrl->parm.setup.phone+2); | |
255 | } else { | |
256 | commands[AT_TYPE] = kstrdup("^SCTP=1\r", GFP_ATOMIC); | |
257 | if (!commands[AT_TYPE]) | |
258 | goto oom; | |
259 | snprintf(commands[AT_DIAL], l, | |
260 | "D%s\r", cntrl->parm.setup.phone); | |
261 | } | |
262 | ||
263 | l = strlen(cntrl->parm.setup.eazmsn); | |
264 | if (l) { | |
265 | l += 8; | |
266 | commands[AT_MSN] = kmalloc(l, GFP_ATOMIC); | |
267 | if (!commands[AT_MSN]) | |
268 | goto oom; | |
269 | snprintf(commands[AT_MSN], l, "^SMSN=%s\r", | |
270 | cntrl->parm.setup.eazmsn); | |
271 | } | |
272 | ||
273 | switch (cntrl->parm.setup.si1) { | |
274 | case 1: /* audio */ | |
275 | /* BC = 9090A3: 3.1 kHz audio, A-law */ | |
276 | commands[AT_BC] = kstrdup("^SBC=9090A3\r", GFP_ATOMIC); | |
277 | if (!commands[AT_BC]) | |
278 | goto oom; | |
279 | break; | |
280 | case 7: /* data */ | |
281 | default: /* hope the app knows what it is doing */ | |
282 | /* BC = 8890: unrestricted digital information */ | |
283 | commands[AT_BC] = kstrdup("^SBC=8890\r", GFP_ATOMIC); | |
284 | if (!commands[AT_BC]) | |
285 | goto oom; | |
286 | } | |
287 | /* ToDo: other si1 values, inspect si2, set HLC/LLC */ | |
288 | ||
289 | commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC); | |
290 | if (!commands[AT_PROTO]) | |
291 | goto oom; | |
292 | snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2); | |
293 | ||
294 | commands[AT_ISO] = kmalloc(9, GFP_ATOMIC); | |
295 | if (!commands[AT_ISO]) | |
296 | goto oom; | |
297 | snprintf(commands[AT_ISO], 9, "^SISO=%u\r", | |
298 | (unsigned) bcs->channel + 1); | |
299 | ||
300 | if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands, | |
4d1ff582 | 301 | bcs->at_state.seq_index, NULL)) { |
088ec0cc TS |
302 | for (i = 0; i < AT_NUM; ++i) |
303 | kfree(commands[i]); | |
304 | kfree(commands); | |
3c66a225 HL |
305 | gigaset_free_channel(bcs); |
306 | return -ENOMEM; | |
307 | } | |
3c66a225 HL |
308 | gigaset_schedule_event(cs); |
309 | break; | |
088ec0cc | 310 | case ISDN_CMD_ACCEPTD: |
1528b18f | 311 | gig_dbg(DEBUG_CMD, "ISDN_CMD_ACCEPTD"); |
088ec0cc | 312 | if (ch >= cs->channels) { |
5002779d | 313 | dev_err(cs->dev, |
088ec0cc | 314 | "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch); |
3c66a225 HL |
315 | return -EINVAL; |
316 | } | |
088ec0cc TS |
317 | bcs = cs->bcs + ch; |
318 | if (!gigaset_add_event(cs, &bcs->at_state, | |
319 | EV_ACCEPT, NULL, 0, NULL)) | |
3c66a225 | 320 | return -ENOMEM; |
3c66a225 HL |
321 | gigaset_schedule_event(cs); |
322 | ||
3c66a225 HL |
323 | break; |
324 | case ISDN_CMD_HANGUP: | |
1528b18f | 325 | gig_dbg(DEBUG_CMD, "ISDN_CMD_HANGUP"); |
088ec0cc | 326 | if (ch >= cs->channels) { |
5002779d | 327 | dev_err(cs->dev, |
088ec0cc | 328 | "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch); |
3c66a225 HL |
329 | return -EINVAL; |
330 | } | |
088ec0cc TS |
331 | bcs = cs->bcs + ch; |
332 | if (!gigaset_add_event(cs, &bcs->at_state, | |
333 | EV_HUP, NULL, 0, NULL)) | |
3c66a225 | 334 | return -ENOMEM; |
3c66a225 HL |
335 | gigaset_schedule_event(cs); |
336 | ||
337 | break; | |
088ec0cc TS |
338 | case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ |
339 | dev_info(cs->dev, "ignoring ISDN_CMD_CLREAZ\n"); | |
3c66a225 | 340 | break; |
088ec0cc TS |
341 | case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ |
342 | dev_info(cs->dev, "ignoring ISDN_CMD_SETEAZ (%s)\n", | |
343 | cntrl->parm.num); | |
3c66a225 | 344 | break; |
917f5085 | 345 | case ISDN_CMD_SETL2: /* Set L2 to given protocol */ |
088ec0cc | 346 | if (ch >= cs->channels) { |
5002779d | 347 | dev_err(cs->dev, |
088ec0cc | 348 | "ISDN_CMD_SETL2: invalid channel (%d)\n", ch); |
3c66a225 HL |
349 | return -EINVAL; |
350 | } | |
088ec0cc TS |
351 | bcs = cs->bcs + ch; |
352 | if (bcs->chstate & CHS_D_UP) { | |
353 | dev_err(cs->dev, | |
354 | "ISDN_CMD_SETL2: channel active (%d)\n", ch); | |
355 | return -EINVAL; | |
356 | } | |
357 | switch (cntrl->arg >> 8) { | |
358 | case ISDN_PROTO_L2_HDLC: | |
359 | gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_HDLC"); | |
360 | bcs->proto2 = L2_HDLC; | |
361 | break; | |
362 | case ISDN_PROTO_L2_TRANS: | |
363 | gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_VOICE"); | |
364 | bcs->proto2 = L2_VOICE; | |
365 | break; | |
366 | default: | |
367 | dev_err(cs->dev, | |
368 | "ISDN_CMD_SETL2: unsupported protocol (%lu)\n", | |
369 | cntrl->arg >> 8); | |
370 | return -EINVAL; | |
3c66a225 | 371 | } |
3c66a225 | 372 | break; |
917f5085 | 373 | case ISDN_CMD_SETL3: /* Set L3 to given protocol */ |
1528b18f | 374 | gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL3"); |
088ec0cc | 375 | if (ch >= cs->channels) { |
5002779d | 376 | dev_err(cs->dev, |
088ec0cc | 377 | "ISDN_CMD_SETL3: invalid channel (%d)\n", ch); |
3c66a225 HL |
378 | return -EINVAL; |
379 | } | |
380 | ||
381 | if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { | |
5002779d | 382 | dev_err(cs->dev, |
088ec0cc | 383 | "ISDN_CMD_SETL3: unsupported protocol (%lu)\n", |
5002779d | 384 | cntrl->arg >> 8); |
3c66a225 HL |
385 | return -EINVAL; |
386 | } | |
387 | ||
388 | break; | |
1528b18f | 389 | |
3c66a225 | 390 | default: |
1528b18f | 391 | gig_dbg(DEBUG_CMD, "unknown command %d from LL", |
5002779d | 392 | cntrl->command); |
3c66a225 HL |
393 | return -EINVAL; |
394 | } | |
395 | ||
396 | return retval; | |
088ec0cc TS |
397 | |
398 | oom: | |
399 | dev_err(bcs->cs->dev, "out of memory\n"); | |
400 | for (i = 0; i < AT_NUM; ++i) | |
401 | kfree(commands[i]); | |
402 | return -ENOMEM; | |
3c66a225 HL |
403 | } |
404 | ||
088ec0cc | 405 | static void gigaset_i4l_cmd(struct cardstate *cs, int cmd) |
3c66a225 | 406 | { |
088ec0cc | 407 | isdn_if *iif = cs->iif; |
3c66a225 HL |
408 | isdn_ctrl command; |
409 | ||
410 | command.driver = cs->myid; | |
411 | command.command = cmd; | |
412 | command.arg = 0; | |
088ec0cc | 413 | iif->statcallb(&command); |
3c66a225 HL |
414 | } |
415 | ||
088ec0cc | 416 | static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd) |
3c66a225 | 417 | { |
088ec0cc | 418 | isdn_if *iif = bcs->cs->iif; |
3c66a225 HL |
419 | isdn_ctrl command; |
420 | ||
421 | command.driver = bcs->cs->myid; | |
422 | command.command = cmd; | |
423 | command.arg = bcs->channel; | |
088ec0cc | 424 | iif->statcallb(&command); |
3c66a225 HL |
425 | } |
426 | ||
1cec9727 TS |
427 | /** |
428 | * gigaset_isdn_icall() - signal incoming call | |
429 | * @at_state: connection state structure. | |
430 | * | |
431 | * Called by main module to notify the LL that an incoming call has been | |
432 | * received. @at_state contains the parameters of the call. | |
433 | * | |
434 | * Return value: call disposition (ICALL_*) | |
435 | */ | |
3c66a225 HL |
436 | int gigaset_isdn_icall(struct at_state_t *at_state) |
437 | { | |
438 | struct cardstate *cs = at_state->cs; | |
439 | struct bc_state *bcs = at_state->bcs; | |
088ec0cc | 440 | isdn_if *iif = cs->iif; |
3c66a225 HL |
441 | isdn_ctrl response; |
442 | int retval; | |
443 | ||
444 | /* fill ICALL structure */ | |
445 | response.parm.setup.si1 = 0; /* default: unknown */ | |
446 | response.parm.setup.si2 = 0; | |
d9ba9c91 | 447 | response.parm.setup.screen = 0; |
3c66a225 HL |
448 | response.parm.setup.plan = 0; |
449 | if (!at_state->str_var[STR_ZBC]) { | |
450 | /* no BC (internal call): assume speech, A-law */ | |
451 | response.parm.setup.si1 = 1; | |
452 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) { | |
453 | /* unrestricted digital information */ | |
454 | response.parm.setup.si1 = 7; | |
455 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) { | |
456 | /* speech, A-law */ | |
457 | response.parm.setup.si1 = 1; | |
458 | } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) { | |
459 | /* 3,1 kHz audio, A-law */ | |
460 | response.parm.setup.si1 = 1; | |
461 | response.parm.setup.si2 = 2; | |
462 | } else { | |
784d5858 | 463 | dev_warn(cs->dev, "RING ignored - unsupported BC %s\n", |
3c66a225 HL |
464 | at_state->str_var[STR_ZBC]); |
465 | return ICALL_IGNORE; | |
466 | } | |
467 | if (at_state->str_var[STR_NMBR]) { | |
d9ba9c91 TS |
468 | strlcpy(response.parm.setup.phone, at_state->str_var[STR_NMBR], |
469 | sizeof response.parm.setup.phone); | |
3c66a225 HL |
470 | } else |
471 | response.parm.setup.phone[0] = 0; | |
472 | if (at_state->str_var[STR_ZCPN]) { | |
d9ba9c91 TS |
473 | strlcpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN], |
474 | sizeof response.parm.setup.eazmsn); | |
3c66a225 HL |
475 | } else |
476 | response.parm.setup.eazmsn[0] = 0; | |
477 | ||
478 | if (!bcs) { | |
784d5858 | 479 | dev_notice(cs->dev, "no channel for incoming call\n"); |
3c66a225 | 480 | response.command = ISDN_STAT_ICALLW; |
d9ba9c91 | 481 | response.arg = 0; |
3c66a225 | 482 | } else { |
784d5858 | 483 | gig_dbg(DEBUG_CMD, "Sending ICALL"); |
3c66a225 | 484 | response.command = ISDN_STAT_ICALL; |
d9ba9c91 | 485 | response.arg = bcs->channel; |
3c66a225 HL |
486 | } |
487 | response.driver = cs->myid; | |
088ec0cc | 488 | retval = iif->statcallb(&response); |
784d5858 | 489 | gig_dbg(DEBUG_CMD, "Response: %d", retval); |
3c66a225 HL |
490 | switch (retval) { |
491 | case 0: /* no takers */ | |
492 | return ICALL_IGNORE; | |
493 | case 1: /* alerting */ | |
494 | bcs->chstate |= CHS_NOTIFY_LL; | |
495 | return ICALL_ACCEPT; | |
496 | case 2: /* reject */ | |
497 | return ICALL_REJECT; | |
498 | case 3: /* incomplete */ | |
784d5858 TS |
499 | dev_warn(cs->dev, |
500 | "LL requested unsupported feature: Incomplete Number\n"); | |
3c66a225 HL |
501 | return ICALL_IGNORE; |
502 | case 4: /* proceeding */ | |
503 | /* Gigaset will send ALERTING anyway. | |
504 | * There doesn't seem to be a way to avoid this. | |
505 | */ | |
506 | return ICALL_ACCEPT; | |
507 | case 5: /* deflect */ | |
784d5858 TS |
508 | dev_warn(cs->dev, |
509 | "LL requested unsupported feature: Call Deflection\n"); | |
3c66a225 HL |
510 | return ICALL_IGNORE; |
511 | default: | |
784d5858 | 512 | dev_err(cs->dev, "LL error %d on ICALL\n", retval); |
3c66a225 HL |
513 | return ICALL_IGNORE; |
514 | } | |
515 | } | |
516 | ||
088ec0cc TS |
517 | /** |
518 | * gigaset_isdn_connD() - signal D channel connect | |
519 | * @bcs: B channel descriptor structure. | |
520 | * | |
521 | * Called by main module to notify the LL that the D channel connection has | |
522 | * been established. | |
523 | */ | |
524 | void gigaset_isdn_connD(struct bc_state *bcs) | |
3c66a225 | 525 | { |
088ec0cc TS |
526 | gig_dbg(DEBUG_CMD, "sending DCONN"); |
527 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); | |
528 | } | |
3c66a225 | 529 | |
088ec0cc TS |
530 | /** |
531 | * gigaset_isdn_hupD() - signal D channel hangup | |
532 | * @bcs: B channel descriptor structure. | |
533 | * | |
534 | * Called by main module to notify the LL that the D channel connection has | |
535 | * been shut down. | |
536 | */ | |
537 | void gigaset_isdn_hupD(struct bc_state *bcs) | |
538 | { | |
539 | gig_dbg(DEBUG_CMD, "sending DHUP"); | |
540 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP); | |
541 | } | |
542 | ||
543 | /** | |
544 | * gigaset_isdn_connB() - signal B channel connect | |
545 | * @bcs: B channel descriptor structure. | |
546 | * | |
547 | * Called by main module to notify the LL that the B channel connection has | |
548 | * been established. | |
549 | */ | |
550 | void gigaset_isdn_connB(struct bc_state *bcs) | |
551 | { | |
552 | gig_dbg(DEBUG_CMD, "sending BCONN"); | |
553 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN); | |
554 | } | |
555 | ||
556 | /** | |
557 | * gigaset_isdn_hupB() - signal B channel hangup | |
558 | * @bcs: B channel descriptor structure. | |
559 | * | |
560 | * Called by main module to notify the LL that the B channel connection has | |
561 | * been shut down. | |
562 | */ | |
563 | void gigaset_isdn_hupB(struct bc_state *bcs) | |
564 | { | |
565 | gig_dbg(DEBUG_CMD, "sending BHUP"); | |
566 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP); | |
567 | } | |
568 | ||
569 | /** | |
570 | * gigaset_isdn_start() - signal device availability | |
571 | * @cs: device descriptor structure. | |
572 | * | |
573 | * Called by main module to notify the LL that the device is available for | |
574 | * use. | |
575 | */ | |
576 | void gigaset_isdn_start(struct cardstate *cs) | |
577 | { | |
578 | gig_dbg(DEBUG_CMD, "sending RUN"); | |
579 | gigaset_i4l_cmd(cs, ISDN_STAT_RUN); | |
580 | } | |
581 | ||
582 | /** | |
583 | * gigaset_isdn_stop() - signal device unavailability | |
584 | * @cs: device descriptor structure. | |
585 | * | |
586 | * Called by main module to notify the LL that the device is no longer | |
587 | * available for use. | |
588 | */ | |
589 | void gigaset_isdn_stop(struct cardstate *cs) | |
590 | { | |
591 | gig_dbg(DEBUG_CMD, "sending STOP"); | |
592 | gigaset_i4l_cmd(cs, ISDN_STAT_STOP); | |
593 | } | |
594 | ||
595 | /** | |
bc35b4e3 | 596 | * gigaset_isdn_regdev() - register to LL |
088ec0cc TS |
597 | * @cs: device descriptor structure. |
598 | * @isdnid: device name. | |
599 | * | |
088ec0cc TS |
600 | * Return value: 1 for success, 0 for failure |
601 | */ | |
bc35b4e3 | 602 | int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid) |
088ec0cc TS |
603 | { |
604 | isdn_if *iif; | |
605 | ||
606 | pr_info("ISDN4Linux interface\n"); | |
607 | ||
608 | iif = kmalloc(sizeof *iif, GFP_KERNEL); | |
609 | if (!iif) { | |
610 | pr_err("out of memory\n"); | |
611 | return 0; | |
612 | } | |
3c66a225 | 613 | |
3c66a225 | 614 | if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index) |
7226d7c9 TS |
615 | >= sizeof iif->id) { |
616 | pr_err("ID too long: %s\n", isdnid); | |
088ec0cc | 617 | kfree(iif); |
7226d7c9 TS |
618 | return 0; |
619 | } | |
3c66a225 HL |
620 | |
621 | iif->owner = THIS_MODULE; | |
917f5085 | 622 | iif->channels = cs->channels; |
3c66a225 | 623 | iif->maxbufsize = MAX_BUF_SIZE; |
917f5085 | 624 | iif->features = ISDN_FEATURE_L2_TRANS | |
3c66a225 HL |
625 | ISDN_FEATURE_L2_HDLC | |
626 | #ifdef GIG_X75 | |
627 | ISDN_FEATURE_L2_X75I | | |
628 | #endif | |
629 | ISDN_FEATURE_L3_TRANS | | |
630 | ISDN_FEATURE_P_EURO; | |
784d5858 | 631 | iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */ |
3c66a225 HL |
632 | iif->command = command_from_LL; |
633 | iif->writebuf_skb = writebuf_from_LL; | |
784d5858 TS |
634 | iif->writecmd = NULL; /* Don't support isdnctrl */ |
635 | iif->readstat = NULL; /* Don't support isdnctrl */ | |
636 | iif->rcvcallb_skb = NULL; /* Will be set by LL */ | |
637 | iif->statcallb = NULL; /* Will be set by LL */ | |
3c66a225 | 638 | |
7226d7c9 TS |
639 | if (!register_isdn(iif)) { |
640 | pr_err("register_isdn failed\n"); | |
088ec0cc | 641 | kfree(iif); |
3c66a225 | 642 | return 0; |
7226d7c9 | 643 | } |
3c66a225 | 644 | |
088ec0cc | 645 | cs->iif = iif; |
784d5858 | 646 | cs->myid = iif->channels; /* Set my device id */ |
088ec0cc | 647 | cs->hw_hdr_len = HW_HDR_LEN; |
3c66a225 HL |
648 | return 1; |
649 | } | |
088ec0cc TS |
650 | |
651 | /** | |
bc35b4e3 | 652 | * gigaset_isdn_unregdev() - unregister device from LL |
088ec0cc | 653 | * @cs: device descriptor structure. |
088ec0cc | 654 | */ |
bc35b4e3 | 655 | void gigaset_isdn_unregdev(struct cardstate *cs) |
088ec0cc TS |
656 | { |
657 | gig_dbg(DEBUG_CMD, "sending UNLOAD"); | |
658 | gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); | |
659 | kfree(cs->iif); | |
660 | cs->iif = NULL; | |
661 | } | |
bc35b4e3 TS |
662 | |
663 | /** | |
664 | * gigaset_isdn_regdrv() - register driver to LL | |
665 | */ | |
666 | void gigaset_isdn_regdrv(void) | |
667 | { | |
668 | /* nothing to do */ | |
669 | } | |
670 | ||
671 | /** | |
672 | * gigaset_isdn_unregdrv() - unregister driver from LL | |
673 | */ | |
674 | void gigaset_isdn_unregdrv(void) | |
675 | { | |
676 | /* nothing to do */ | |
677 | } |