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