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