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 | { |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 42 | struct cardstate *cs = gigaset_get_cs_by_id(driverID); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 43 | struct bc_state *bcs; |
Tilman Schmidt | 4dd8230 | 2009-10-25 09:29:57 +0000 | [diff] [blame] | 44 | unsigned char *ack_header; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 45 | unsigned len; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 46 | |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 47 | if (!cs) { |
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 | |
Tilman Schmidt | 4dd8230 | 2009-10-25 09:29:57 +0000 | [diff] [blame] | 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]); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 98 | |
| 99 | /* pass to device-specific module */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 100 | return cs->ops->send_skb(bcs, skb); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Tilman Schmidt | 1cec972 | 2009-10-06 12:19:01 +0000 | [diff] [blame] | 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 | */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 111 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) |
| 112 | { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 113 | isdn_if *iif = bcs->cs->iif; |
Tilman Schmidt | 4dd8230 | 2009-10-25 09:29:57 +0000 | [diff] [blame] | 114 | unsigned char *ack_header = skb_mac_header(skb); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 115 | unsigned len; |
| 116 | isdn_ctrl response; |
| 117 | |
| 118 | ++bcs->trans_up; |
| 119 | |
| 120 | if (skb->len) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 121 | dev_warn(bcs->cs->dev, "%s: skb->len==%d\n", |
| 122 | __func__, skb->len); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 123 | |
Tilman Schmidt | 4dd8230 | 2009-10-25 09:29:57 +0000 | [diff] [blame] | 124 | len = ack_header[0] + ((unsigned) ack_header[1] << 8); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 125 | if (len) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 126 | gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)", |
| 127 | bcs->cs->myid, bcs->channel, len); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 128 | |
| 129 | response.driver = bcs->cs->myid; |
| 130 | response.command = ISDN_STAT_BSENT; |
| 131 | response.arg = bcs->channel; |
| 132 | response.parm.length = len; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 133 | iif->statcallb(&response); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | EXPORT_SYMBOL_GPL(gigaset_skb_sent); |
| 137 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 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 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 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 | { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 193 | struct cardstate *cs; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 194 | struct bc_state *bcs; |
| 195 | int retval = 0; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 196 | char **commands; |
| 197 | int ch; |
| 198 | int i; |
| 199 | size_t l; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 200 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 201 | gigaset_debugdrivers(); |
| 202 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 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) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 208 | pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 209 | return -ENODEV; |
| 210 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 211 | ch = cntrl->arg & 0xff; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 212 | |
| 213 | switch (cntrl->command) { |
| 214 | case ISDN_CMD_IOCTL: |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 215 | dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | |
| 218 | case ISDN_CMD_DIAL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 219 | gig_dbg(DEBUG_ANY, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 220 | "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 221 | cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, |
| 222 | cntrl->parm.setup.si1, cntrl->parm.setup.si2); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 223 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 224 | if (ch >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 225 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 226 | "ISDN_CMD_DIAL: invalid channel (%d)\n", ch); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 227 | return -EINVAL; |
| 228 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 229 | bcs = cs->bcs + ch; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 230 | if (!gigaset_get_channel(bcs)) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 231 | dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 232 | return -EBUSY; |
| 233 | } |
| 234 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 235 | commands = kzalloc(AT_NUM*(sizeof *commands), GFP_ATOMIC); |
| 236 | if (!commands) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 237 | gigaset_free_channel(bcs); |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 238 | dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 239 | return -ENOMEM; |
| 240 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 241 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 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, |
Tilman Schmidt | 4d1ff58 | 2007-10-16 01:27:50 -0700 | [diff] [blame] | 300 | bcs->at_state.seq_index, NULL)) { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 301 | for (i = 0; i < AT_NUM; ++i) |
| 302 | kfree(commands[i]); |
| 303 | kfree(commands); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 304 | gigaset_free_channel(bcs); |
| 305 | return -ENOMEM; |
| 306 | } |
| 307 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 308 | gig_dbg(DEBUG_CMD, "scheduling DIAL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 309 | gigaset_schedule_event(cs); |
| 310 | break; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 311 | case ISDN_CMD_ACCEPTD: |
| 312 | if (ch >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 313 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 314 | "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 315 | return -EINVAL; |
| 316 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 317 | bcs = cs->bcs + ch; |
| 318 | if (!gigaset_add_event(cs, &bcs->at_state, |
| 319 | EV_ACCEPT, NULL, 0, NULL)) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 320 | return -ENOMEM; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 321 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 322 | gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 323 | gigaset_schedule_event(cs); |
| 324 | |
| 325 | break; |
| 326 | case ISDN_CMD_ACCEPTB: |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 327 | break; |
| 328 | case ISDN_CMD_HANGUP: |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 329 | if (ch >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 330 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 331 | "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 332 | return -EINVAL; |
| 333 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 334 | bcs = cs->bcs + ch; |
| 335 | if (!gigaset_add_event(cs, &bcs->at_state, |
| 336 | EV_HUP, NULL, 0, NULL)) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 337 | return -ENOMEM; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 338 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 339 | gig_dbg(DEBUG_CMD, "scheduling HUP"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 340 | gigaset_schedule_event(cs); |
| 341 | |
| 342 | break; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 343 | case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ |
| 344 | dev_info(cs->dev, "ignoring ISDN_CMD_CLREAZ\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 345 | break; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 346 | case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ |
| 347 | dev_info(cs->dev, "ignoring ISDN_CMD_SETEAZ (%s)\n", |
| 348 | cntrl->parm.num); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 349 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 350 | case ISDN_CMD_SETL2: /* Set L2 to given protocol */ |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 351 | if (ch >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 352 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 353 | "ISDN_CMD_SETL2: invalid channel (%d)\n", ch); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 354 | return -EINVAL; |
| 355 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 356 | bcs = cs->bcs + ch; |
| 357 | if (bcs->chstate & CHS_D_UP) { |
| 358 | dev_err(cs->dev, |
| 359 | "ISDN_CMD_SETL2: channel active (%d)\n", ch); |
| 360 | return -EINVAL; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 361 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 362 | switch (cntrl->arg >> 8) { |
| 363 | case ISDN_PROTO_L2_HDLC: |
| 364 | gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_HDLC"); |
| 365 | bcs->proto2 = L2_HDLC; |
| 366 | break; |
| 367 | case ISDN_PROTO_L2_TRANS: |
| 368 | gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_VOICE"); |
| 369 | bcs->proto2 = L2_VOICE; |
| 370 | break; |
| 371 | default: |
| 372 | dev_err(cs->dev, |
| 373 | "ISDN_CMD_SETL2: unsupported protocol (%lu)\n", |
| 374 | cntrl->arg >> 8); |
| 375 | return -EINVAL; |
| 376 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 377 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 378 | case ISDN_CMD_SETL3: /* Set L3 to given protocol */ |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 379 | if (ch >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 380 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 381 | "ISDN_CMD_SETL3: invalid channel (%d)\n", ch); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 382 | return -EINVAL; |
| 383 | } |
| 384 | |
| 385 | if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 386 | dev_err(cs->dev, |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 387 | "ISDN_CMD_SETL3: unsupported protocol (%lu)\n", |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 388 | cntrl->arg >> 8); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 389 | return -EINVAL; |
| 390 | } |
| 391 | |
| 392 | break; |
| 393 | case ISDN_CMD_PROCEED: |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 394 | gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 395 | break; |
| 396 | case ISDN_CMD_ALERT: |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 397 | gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 398 | if (cntrl->arg >= cs->channels) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 399 | dev_err(cs->dev, |
| 400 | "ISDN_CMD_ALERT: invalid channel (%d)\n", |
| 401 | (int) cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 404 | break; |
| 405 | case ISDN_CMD_REDIR: |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 406 | gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 407 | break; |
| 408 | case ISDN_CMD_PROT_IO: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 409 | gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 410 | break; |
| 411 | case ISDN_CMD_FAXCMD: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 412 | gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 413 | break; |
| 414 | case ISDN_CMD_GETL2: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 415 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 416 | break; |
| 417 | case ISDN_CMD_GETL3: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 418 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 419 | break; |
| 420 | case ISDN_CMD_GETEAZ: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 421 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 422 | break; |
| 423 | case ISDN_CMD_SETSIL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 424 | gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 425 | break; |
| 426 | case ISDN_CMD_GETSIL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 427 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 428 | break; |
| 429 | default: |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 430 | dev_err(cs->dev, "unknown command %d from LL\n", |
| 431 | cntrl->command); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 432 | return -EINVAL; |
| 433 | } |
| 434 | |
| 435 | return retval; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 436 | |
| 437 | oom: |
| 438 | dev_err(bcs->cs->dev, "out of memory\n"); |
| 439 | for (i = 0; i < AT_NUM; ++i) |
| 440 | kfree(commands[i]); |
| 441 | return -ENOMEM; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 444 | static void gigaset_i4l_cmd(struct cardstate *cs, int cmd) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 445 | { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 446 | isdn_if *iif = cs->iif; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 447 | isdn_ctrl command; |
| 448 | |
| 449 | command.driver = cs->myid; |
| 450 | command.command = cmd; |
| 451 | command.arg = 0; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 452 | iif->statcallb(&command); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 455 | static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 456 | { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 457 | isdn_if *iif = bcs->cs->iif; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 458 | isdn_ctrl command; |
| 459 | |
| 460 | command.driver = bcs->cs->myid; |
| 461 | command.command = cmd; |
| 462 | command.arg = bcs->channel; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 463 | iif->statcallb(&command); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Tilman Schmidt | 1cec972 | 2009-10-06 12:19:01 +0000 | [diff] [blame] | 466 | /** |
| 467 | * gigaset_isdn_icall() - signal incoming call |
| 468 | * @at_state: connection state structure. |
| 469 | * |
| 470 | * Called by main module to notify the LL that an incoming call has been |
| 471 | * received. @at_state contains the parameters of the call. |
| 472 | * |
| 473 | * Return value: call disposition (ICALL_*) |
| 474 | */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 475 | int gigaset_isdn_icall(struct at_state_t *at_state) |
| 476 | { |
| 477 | struct cardstate *cs = at_state->cs; |
| 478 | struct bc_state *bcs = at_state->bcs; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 479 | isdn_if *iif = cs->iif; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 480 | isdn_ctrl response; |
| 481 | int retval; |
| 482 | |
| 483 | /* fill ICALL structure */ |
| 484 | response.parm.setup.si1 = 0; /* default: unknown */ |
| 485 | response.parm.setup.si2 = 0; |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 486 | response.parm.setup.screen = 0; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 487 | response.parm.setup.plan = 0; |
| 488 | if (!at_state->str_var[STR_ZBC]) { |
| 489 | /* no BC (internal call): assume speech, A-law */ |
| 490 | response.parm.setup.si1 = 1; |
| 491 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) { |
| 492 | /* unrestricted digital information */ |
| 493 | response.parm.setup.si1 = 7; |
| 494 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) { |
| 495 | /* speech, A-law */ |
| 496 | response.parm.setup.si1 = 1; |
| 497 | } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) { |
| 498 | /* 3,1 kHz audio, A-law */ |
| 499 | response.parm.setup.si1 = 1; |
| 500 | response.parm.setup.si2 = 2; |
| 501 | } else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 502 | dev_warn(cs->dev, "RING ignored - unsupported BC %s\n", |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 503 | at_state->str_var[STR_ZBC]); |
| 504 | return ICALL_IGNORE; |
| 505 | } |
| 506 | if (at_state->str_var[STR_NMBR]) { |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 507 | strlcpy(response.parm.setup.phone, at_state->str_var[STR_NMBR], |
| 508 | sizeof response.parm.setup.phone); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 509 | } else |
| 510 | response.parm.setup.phone[0] = 0; |
| 511 | if (at_state->str_var[STR_ZCPN]) { |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 512 | strlcpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN], |
| 513 | sizeof response.parm.setup.eazmsn); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 514 | } else |
| 515 | response.parm.setup.eazmsn[0] = 0; |
| 516 | |
| 517 | if (!bcs) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 518 | dev_notice(cs->dev, "no channel for incoming call\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 519 | response.command = ISDN_STAT_ICALLW; |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 520 | response.arg = 0; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 521 | } else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 522 | gig_dbg(DEBUG_CMD, "Sending ICALL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 523 | response.command = ISDN_STAT_ICALL; |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame^] | 524 | response.arg = bcs->channel; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 525 | } |
| 526 | response.driver = cs->myid; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 527 | retval = iif->statcallb(&response); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 528 | gig_dbg(DEBUG_CMD, "Response: %d", retval); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 529 | switch (retval) { |
| 530 | case 0: /* no takers */ |
| 531 | return ICALL_IGNORE; |
| 532 | case 1: /* alerting */ |
| 533 | bcs->chstate |= CHS_NOTIFY_LL; |
| 534 | return ICALL_ACCEPT; |
| 535 | case 2: /* reject */ |
| 536 | return ICALL_REJECT; |
| 537 | case 3: /* incomplete */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 538 | dev_warn(cs->dev, |
| 539 | "LL requested unsupported feature: Incomplete Number\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 540 | return ICALL_IGNORE; |
| 541 | case 4: /* proceeding */ |
| 542 | /* Gigaset will send ALERTING anyway. |
| 543 | * There doesn't seem to be a way to avoid this. |
| 544 | */ |
| 545 | return ICALL_ACCEPT; |
| 546 | case 5: /* deflect */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 547 | dev_warn(cs->dev, |
| 548 | "LL requested unsupported feature: Call Deflection\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 549 | return ICALL_IGNORE; |
| 550 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 551 | dev_err(cs->dev, "LL error %d on ICALL\n", retval); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 552 | return ICALL_IGNORE; |
| 553 | } |
| 554 | } |
| 555 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 556 | /** |
| 557 | * gigaset_isdn_connD() - signal D channel connect |
| 558 | * @bcs: B channel descriptor structure. |
| 559 | * |
| 560 | * Called by main module to notify the LL that the D channel connection has |
| 561 | * been established. |
| 562 | */ |
| 563 | void gigaset_isdn_connD(struct bc_state *bcs) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 564 | { |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 565 | gig_dbg(DEBUG_CMD, "sending DCONN"); |
| 566 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); |
| 567 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 568 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 569 | /** |
| 570 | * gigaset_isdn_hupD() - signal D channel hangup |
| 571 | * @bcs: B channel descriptor structure. |
| 572 | * |
| 573 | * Called by main module to notify the LL that the D channel connection has |
| 574 | * been shut down. |
| 575 | */ |
| 576 | void gigaset_isdn_hupD(struct bc_state *bcs) |
| 577 | { |
| 578 | gig_dbg(DEBUG_CMD, "sending DHUP"); |
| 579 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * gigaset_isdn_connB() - signal B channel connect |
| 584 | * @bcs: B channel descriptor structure. |
| 585 | * |
| 586 | * Called by main module to notify the LL that the B channel connection has |
| 587 | * been established. |
| 588 | */ |
| 589 | void gigaset_isdn_connB(struct bc_state *bcs) |
| 590 | { |
| 591 | gig_dbg(DEBUG_CMD, "sending BCONN"); |
| 592 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * gigaset_isdn_hupB() - signal B channel hangup |
| 597 | * @bcs: B channel descriptor structure. |
| 598 | * |
| 599 | * Called by main module to notify the LL that the B channel connection has |
| 600 | * been shut down. |
| 601 | */ |
| 602 | void gigaset_isdn_hupB(struct bc_state *bcs) |
| 603 | { |
| 604 | gig_dbg(DEBUG_CMD, "sending BHUP"); |
| 605 | gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * gigaset_isdn_start() - signal device availability |
| 610 | * @cs: device descriptor structure. |
| 611 | * |
| 612 | * Called by main module to notify the LL that the device is available for |
| 613 | * use. |
| 614 | */ |
| 615 | void gigaset_isdn_start(struct cardstate *cs) |
| 616 | { |
| 617 | gig_dbg(DEBUG_CMD, "sending RUN"); |
| 618 | gigaset_i4l_cmd(cs, ISDN_STAT_RUN); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * gigaset_isdn_stop() - signal device unavailability |
| 623 | * @cs: device descriptor structure. |
| 624 | * |
| 625 | * Called by main module to notify the LL that the device is no longer |
| 626 | * available for use. |
| 627 | */ |
| 628 | void gigaset_isdn_stop(struct cardstate *cs) |
| 629 | { |
| 630 | gig_dbg(DEBUG_CMD, "sending STOP"); |
| 631 | gigaset_i4l_cmd(cs, ISDN_STAT_STOP); |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * gigaset_isdn_register() - register to LL |
| 636 | * @cs: device descriptor structure. |
| 637 | * @isdnid: device name. |
| 638 | * |
| 639 | * Called by main module to register the device with the LL. |
| 640 | * |
| 641 | * Return value: 1 for success, 0 for failure |
| 642 | */ |
| 643 | int gigaset_isdn_register(struct cardstate *cs, const char *isdnid) |
| 644 | { |
| 645 | isdn_if *iif; |
| 646 | |
| 647 | pr_info("ISDN4Linux interface\n"); |
| 648 | |
| 649 | iif = kmalloc(sizeof *iif, GFP_KERNEL); |
| 650 | if (!iif) { |
| 651 | pr_err("out of memory\n"); |
| 652 | return 0; |
| 653 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 654 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 655 | 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] | 656 | >= sizeof iif->id) { |
| 657 | pr_err("ID too long: %s\n", isdnid); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 658 | kfree(iif); |
Tilman Schmidt | 7226d7c | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 659 | return 0; |
| 660 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 661 | |
| 662 | iif->owner = THIS_MODULE; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 663 | iif->channels = cs->channels; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 664 | iif->maxbufsize = MAX_BUF_SIZE; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 665 | iif->features = ISDN_FEATURE_L2_TRANS | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 666 | ISDN_FEATURE_L2_HDLC | |
| 667 | #ifdef GIG_X75 |
| 668 | ISDN_FEATURE_L2_X75I | |
| 669 | #endif |
| 670 | ISDN_FEATURE_L3_TRANS | |
| 671 | ISDN_FEATURE_P_EURO; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 672 | iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 673 | iif->command = command_from_LL; |
| 674 | iif->writebuf_skb = writebuf_from_LL; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 675 | iif->writecmd = NULL; /* Don't support isdnctrl */ |
| 676 | iif->readstat = NULL; /* Don't support isdnctrl */ |
| 677 | iif->rcvcallb_skb = NULL; /* Will be set by LL */ |
| 678 | iif->statcallb = NULL; /* Will be set by LL */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 679 | |
Tilman Schmidt | 7226d7c | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 680 | if (!register_isdn(iif)) { |
| 681 | pr_err("register_isdn failed\n"); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 682 | kfree(iif); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 683 | return 0; |
Tilman Schmidt | 7226d7c | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 684 | } |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 685 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 686 | cs->iif = iif; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 687 | cs->myid = iif->channels; /* Set my device id */ |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 688 | cs->hw_hdr_len = HW_HDR_LEN; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 689 | return 1; |
| 690 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 691 | |
| 692 | /** |
| 693 | * gigaset_isdn_unregister() - unregister from LL |
| 694 | * @cs: device descriptor structure. |
| 695 | * |
| 696 | * Called by main module to unregister the device from the LL. |
| 697 | */ |
| 698 | void gigaset_isdn_unregister(struct cardstate *cs) |
| 699 | { |
| 700 | gig_dbg(DEBUG_CMD, "sending UNLOAD"); |
| 701 | gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); |
| 702 | kfree(cs->iif); |
| 703 | cs->iif = NULL; |
| 704 | } |